-
Notifications
You must be signed in to change notification settings - Fork 134
Expand file tree
/
Copy pathdialog-altimate-login.tsx
More file actions
81 lines (78 loc) · 2.52 KB
/
Copy pathdialog-altimate-login.tsx
File metadata and controls
81 lines (78 loc) · 2.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import { createSignal } from "solid-js"
import { useDialog } from "@tui/ui/dialog"
import { useSDK } from "../context/sdk"
import { useSync } from "@tui/context/sync"
import { useLocal } from "@tui/context/local"
import { DialogPrompt } from "../ui/dialog-prompt"
import { useTheme } from "../context/theme"
import { AltimateApi } from "@/altimate/api/client"
import { Filesystem } from "@/util/filesystem"
export function DialogAltimateLogin() {
const dialog = useDialog()
const sdk = useSDK()
const sync = useSync()
const local = useLocal()
const { theme } = useTheme()
const [step, setStep] = createSignal<"url" | "tenant" | "key">("url")
const [url, setUrl] = createSignal("https://api.myaltimate.com")
const [tenant, setTenant] = createSignal("")
async function saveAndConnect(apiKey: string) {
const creds = {
altimateUrl: url(),
altimateInstanceName: tenant(),
altimateApiKey: apiKey,
}
await Filesystem.writeJson(AltimateApi.credentialsPath(), creds, 0o600)
// Refresh providers to pick up the new altimate-backend
await sdk.client.instance.dispose()
await sync.bootstrap()
// Auto-select the altimate model
local.model.set({ providerID: "altimate-backend", modelID: "altimate-default" }, { recent: true })
dialog.clear()
}
return (
<>
{step() === "url" && (
<DialogPrompt
title="Altimate Backend URL"
placeholder="https://api.myaltimate.com"
value="https://api.myaltimate.com"
description={() => (
<text fg={theme.textMuted}>Enter the URL of your Altimate backend server</text>
)}
onConfirm={(value) => {
if (value) setUrl(value)
setStep("tenant")
}}
/>
)}
{step() === "tenant" && (
<DialogPrompt
title="Instance Name"
placeholder="your-tenant"
description={() => (
<text fg={theme.textMuted}>Enter your Altimate instance (tenant) name</text>
)}
onConfirm={(value) => {
if (!value) return
setTenant(value)
setStep("key")
}}
/>
)}
{step() === "key" && (
<DialogPrompt
title="API Key"
placeholder="your-api-key"
description={() => (
<text fg={theme.textMuted}>Enter your Altimate API key</text>
)}
onConfirm={async (value) => {
if (!value) return
await saveAndConnect(value)
}}
/>
)}
</>
)
}