Compare commits
7 Commits
dev
...
kit/consol
| Author | SHA1 | Date |
|---|---|---|
|
|
3506081f40 | |
|
|
fa92f0590c | |
|
|
d0ef2b2ade | |
|
|
8922a77e93 | |
|
|
e972353d59 | |
|
|
f5b30cdf39 | |
|
|
8675f51751 |
|
|
@ -52,6 +52,11 @@ export type AccountOrgs = {
|
||||||
orgs: readonly Org[]
|
orgs: readonly Org[]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type ActiveOrg = {
|
||||||
|
account: Info
|
||||||
|
org: Org
|
||||||
|
}
|
||||||
|
|
||||||
class RemoteConfig extends Schema.Class<RemoteConfig>("RemoteConfig")({
|
class RemoteConfig extends Schema.Class<RemoteConfig>("RemoteConfig")({
|
||||||
config: Schema.Record(Schema.String, Schema.Json),
|
config: Schema.Record(Schema.String, Schema.Json),
|
||||||
}) {}
|
}) {}
|
||||||
|
|
@ -137,6 +142,7 @@ const mapAccountServiceError =
|
||||||
export namespace Account {
|
export namespace Account {
|
||||||
export interface Interface {
|
export interface Interface {
|
||||||
readonly active: () => Effect.Effect<Option.Option<Info>, AccountError>
|
readonly active: () => Effect.Effect<Option.Option<Info>, AccountError>
|
||||||
|
readonly activeOrg: () => Effect.Effect<Option.Option<ActiveOrg>, AccountError>
|
||||||
readonly list: () => Effect.Effect<Info[], AccountError>
|
readonly list: () => Effect.Effect<Info[], AccountError>
|
||||||
readonly orgsByAccount: () => Effect.Effect<readonly AccountOrgs[], AccountError>
|
readonly orgsByAccount: () => Effect.Effect<readonly AccountOrgs[], AccountError>
|
||||||
readonly remove: (accountID: AccountID) => Effect.Effect<void, AccountError>
|
readonly remove: (accountID: AccountID) => Effect.Effect<void, AccountError>
|
||||||
|
|
@ -279,19 +285,31 @@ export namespace Account {
|
||||||
resolveAccess(accountID).pipe(Effect.map(Option.map((r) => r.accessToken))),
|
resolveAccess(accountID).pipe(Effect.map(Option.map((r) => r.accessToken))),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const activeOrg = Effect.fn("Account.activeOrg")(function* () {
|
||||||
|
const activeAccount = yield* repo.active()
|
||||||
|
if (Option.isNone(activeAccount)) return Option.none<ActiveOrg>()
|
||||||
|
|
||||||
|
const account = activeAccount.value
|
||||||
|
if (!account.active_org_id) return Option.none<ActiveOrg>()
|
||||||
|
|
||||||
|
const accountOrgs = yield* orgs(account.id)
|
||||||
|
const org = accountOrgs.find((item) => item.id === account.active_org_id)
|
||||||
|
if (!org) return Option.none<ActiveOrg>()
|
||||||
|
|
||||||
|
return Option.some({ account, org })
|
||||||
|
})
|
||||||
|
|
||||||
const orgsByAccount = Effect.fn("Account.orgsByAccount")(function* () {
|
const orgsByAccount = Effect.fn("Account.orgsByAccount")(function* () {
|
||||||
const accounts = yield* repo.list()
|
const accounts = yield* repo.list()
|
||||||
const [errors, results] = yield* Effect.partition(
|
return yield* Effect.forEach(
|
||||||
accounts,
|
accounts,
|
||||||
(account) => orgs(account.id).pipe(Effect.map((orgs) => ({ account, orgs }))),
|
(account) =>
|
||||||
|
orgs(account.id).pipe(
|
||||||
|
Effect.catch(() => Effect.succeed([] as readonly Org[])),
|
||||||
|
Effect.map((orgs) => ({ account, orgs })),
|
||||||
|
),
|
||||||
{ concurrency: 3 },
|
{ concurrency: 3 },
|
||||||
)
|
)
|
||||||
for (const error of errors) {
|
|
||||||
yield* Effect.logWarning("failed to fetch orgs for account").pipe(
|
|
||||||
Effect.annotateLogs({ error: String(error) }),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
return results
|
|
||||||
})
|
})
|
||||||
|
|
||||||
const orgs = Effect.fn("Account.orgs")(function* (accountID: AccountID) {
|
const orgs = Effect.fn("Account.orgs")(function* (accountID: AccountID) {
|
||||||
|
|
@ -396,6 +414,7 @@ export namespace Account {
|
||||||
|
|
||||||
return Service.of({
|
return Service.of({
|
||||||
active: repo.active,
|
active: repo.active,
|
||||||
|
activeOrg,
|
||||||
list: repo.list,
|
list: repo.list,
|
||||||
orgsByAccount,
|
orgsByAccount,
|
||||||
remove: repo.remove,
|
remove: repo.remove,
|
||||||
|
|
@ -417,6 +436,26 @@ export namespace Account {
|
||||||
return Option.getOrUndefined(await runPromise((service) => service.active()))
|
return Option.getOrUndefined(await runPromise((service) => service.active()))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function list(): Promise<Info[]> {
|
||||||
|
return runPromise((service) => service.list())
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function activeOrg(): Promise<ActiveOrg | undefined> {
|
||||||
|
return Option.getOrUndefined(await runPromise((service) => service.activeOrg()))
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function orgsByAccount(): Promise<readonly AccountOrgs[]> {
|
||||||
|
return runPromise((service) => service.orgsByAccount())
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function orgs(accountID: AccountID): Promise<readonly Org[]> {
|
||||||
|
return runPromise((service) => service.orgs(accountID))
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function switchOrg(accountID: AccountID, orgID: OrgID) {
|
||||||
|
return runPromise((service) => service.use(accountID, Option.some(orgID)))
|
||||||
|
}
|
||||||
|
|
||||||
export async function token(accountID: AccountID): Promise<AccessToken | undefined> {
|
export async function token(accountID: AccountID): Promise<AccessToken | undefined> {
|
||||||
const t = await runPromise((service) => service.token(accountID))
|
const t = await runPromise((service) => service.token(accountID))
|
||||||
return Option.getOrUndefined(t)
|
return Option.getOrUndefined(t)
|
||||||
|
|
|
||||||
|
|
@ -36,6 +36,7 @@ import { CommandProvider, useCommandDialog } from "@tui/component/dialog-command
|
||||||
import { DialogAgent } from "@tui/component/dialog-agent"
|
import { DialogAgent } from "@tui/component/dialog-agent"
|
||||||
import { DialogSessionList } from "@tui/component/dialog-session-list"
|
import { DialogSessionList } from "@tui/component/dialog-session-list"
|
||||||
import { DialogWorkspaceList } from "@tui/component/dialog-workspace-list"
|
import { DialogWorkspaceList } from "@tui/component/dialog-workspace-list"
|
||||||
|
import { DialogConsoleOrg } from "@tui/component/dialog-console-org"
|
||||||
import { KeybindProvider, useKeybind } from "@tui/context/keybind"
|
import { KeybindProvider, useKeybind } from "@tui/context/keybind"
|
||||||
import { ThemeProvider, useTheme } from "@tui/context/theme"
|
import { ThemeProvider, useTheme } from "@tui/context/theme"
|
||||||
import { Home } from "@tui/routes/home"
|
import { Home } from "@tui/routes/home"
|
||||||
|
|
@ -629,6 +630,19 @@ function App(props: { onSnapshot?: () => Promise<string[]> }) {
|
||||||
},
|
},
|
||||||
category: "Provider",
|
category: "Provider",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
title: "Switch org",
|
||||||
|
value: "console.org.switch",
|
||||||
|
suggested: Boolean(sync.data.console_state.activeOrgName),
|
||||||
|
slash: {
|
||||||
|
name: "org",
|
||||||
|
aliases: ["orgs", "switch-org"],
|
||||||
|
},
|
||||||
|
onSelect: () => {
|
||||||
|
dialog.replace(() => <DialogConsoleOrg />)
|
||||||
|
},
|
||||||
|
category: "Provider",
|
||||||
|
},
|
||||||
{
|
{
|
||||||
title: "View status",
|
title: "View status",
|
||||||
keybind: "status_view",
|
keybind: "status_view",
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,109 @@
|
||||||
|
import { createResource, createMemo } from "solid-js"
|
||||||
|
import { DialogSelect } from "@tui/ui/dialog-select"
|
||||||
|
import { useSDK } from "@tui/context/sdk"
|
||||||
|
import { useDialog } from "@tui/ui/dialog"
|
||||||
|
import { useToast } from "@tui/ui/toast"
|
||||||
|
import { useTheme } from "@tui/context/theme"
|
||||||
|
|
||||||
|
type OrgOption = {
|
||||||
|
accountID: string
|
||||||
|
accountEmail: string
|
||||||
|
accountUrl: string
|
||||||
|
orgID: string
|
||||||
|
orgName: string
|
||||||
|
active: boolean
|
||||||
|
}
|
||||||
|
|
||||||
|
const accountHost = (url: string) => {
|
||||||
|
try {
|
||||||
|
return new URL(url).host
|
||||||
|
} catch {
|
||||||
|
return url
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const accountLabel = (item: Pick<OrgOption, "accountEmail" | "accountUrl">) =>
|
||||||
|
`${item.accountEmail} ${accountHost(item.accountUrl)}`
|
||||||
|
|
||||||
|
export function DialogConsoleOrg() {
|
||||||
|
const sdk = useSDK()
|
||||||
|
const dialog = useDialog()
|
||||||
|
const toast = useToast()
|
||||||
|
const { theme } = useTheme()
|
||||||
|
|
||||||
|
const [orgs] = createResource(async () => {
|
||||||
|
const result = await sdk.client.experimental.console.listOrgs({}, { throwOnError: true })
|
||||||
|
return result.data?.orgs ?? []
|
||||||
|
})
|
||||||
|
|
||||||
|
const current = createMemo(() => orgs()?.find((item) => item.active))
|
||||||
|
|
||||||
|
const options = createMemo(() => {
|
||||||
|
const listed = orgs()
|
||||||
|
if (listed === undefined) {
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
title: "Loading orgs...",
|
||||||
|
value: "loading",
|
||||||
|
onSelect: () => {},
|
||||||
|
},
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
if (listed.length === 0) {
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
title: "No orgs found",
|
||||||
|
value: "empty",
|
||||||
|
onSelect: () => {},
|
||||||
|
},
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
return listed
|
||||||
|
.toSorted((a, b) => {
|
||||||
|
const activeAccountA = a.active ? 0 : 1
|
||||||
|
const activeAccountB = b.active ? 0 : 1
|
||||||
|
if (activeAccountA !== activeAccountB) return activeAccountA - activeAccountB
|
||||||
|
|
||||||
|
const accountCompare = accountLabel(a).localeCompare(accountLabel(b))
|
||||||
|
if (accountCompare !== 0) return accountCompare
|
||||||
|
|
||||||
|
return a.orgName.localeCompare(b.orgName)
|
||||||
|
})
|
||||||
|
.map((item) => ({
|
||||||
|
title: item.orgName,
|
||||||
|
value: item,
|
||||||
|
category: accountLabel(item),
|
||||||
|
categoryView: (
|
||||||
|
<box flexDirection="row" gap={2}>
|
||||||
|
<text fg={theme.accent}>{item.accountEmail}</text>
|
||||||
|
<text fg={theme.textMuted}>{accountHost(item.accountUrl)}</text>
|
||||||
|
</box>
|
||||||
|
),
|
||||||
|
onSelect: async () => {
|
||||||
|
if (item.active) {
|
||||||
|
dialog.clear()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
await sdk.client.experimental.console.switchOrg(
|
||||||
|
{
|
||||||
|
accountID: item.accountID,
|
||||||
|
orgID: item.orgID,
|
||||||
|
},
|
||||||
|
{ throwOnError: true },
|
||||||
|
)
|
||||||
|
|
||||||
|
await sdk.client.instance.dispose()
|
||||||
|
toast.show({
|
||||||
|
message: `Switched to ${item.orgName}`,
|
||||||
|
variant: "info",
|
||||||
|
})
|
||||||
|
dialog.clear()
|
||||||
|
},
|
||||||
|
}))
|
||||||
|
})
|
||||||
|
|
||||||
|
return <DialogSelect<string | OrgOption> title="Switch org" options={options()} current={current()} />
|
||||||
|
}
|
||||||
|
|
@ -8,6 +8,7 @@ import { createDialogProviderOptions, DialogProvider } from "./dialog-provider"
|
||||||
import { DialogVariant } from "./dialog-variant"
|
import { DialogVariant } from "./dialog-variant"
|
||||||
import { useKeybind } from "../context/keybind"
|
import { useKeybind } from "../context/keybind"
|
||||||
import * as fuzzysort from "fuzzysort"
|
import * as fuzzysort from "fuzzysort"
|
||||||
|
import { consoleManagedProviderLabel } from "@tui/util/provider-origin"
|
||||||
|
|
||||||
export function useConnected() {
|
export function useConnected() {
|
||||||
const sync = useSync()
|
const sync = useSync()
|
||||||
|
|
@ -33,6 +34,7 @@ export function DialogModel(props: { providerID?: string }) {
|
||||||
const showSections = showExtra() && needle.length === 0
|
const showSections = showExtra() && needle.length === 0
|
||||||
const favorites = connected() ? local.model.favorite() : []
|
const favorites = connected() ? local.model.favorite() : []
|
||||||
const recents = local.model.recent()
|
const recents = local.model.recent()
|
||||||
|
const consoleManagedProviders = new Set(sync.data.console_state.consoleManagedProviders)
|
||||||
|
|
||||||
function toOptions(items: typeof favorites, category: string) {
|
function toOptions(items: typeof favorites, category: string) {
|
||||||
if (!showSections) return []
|
if (!showSections) return []
|
||||||
|
|
@ -46,7 +48,7 @@ export function DialogModel(props: { providerID?: string }) {
|
||||||
key: item,
|
key: item,
|
||||||
value: { providerID: provider.id, modelID: model.id },
|
value: { providerID: provider.id, modelID: model.id },
|
||||||
title: model.name ?? item.modelID,
|
title: model.name ?? item.modelID,
|
||||||
description: provider.name,
|
description: consoleManagedProviderLabel(consoleManagedProviders, provider.id, provider.name),
|
||||||
category,
|
category,
|
||||||
disabled: provider.id === "opencode" && model.id.includes("-nano"),
|
disabled: provider.id === "opencode" && model.id.includes("-nano"),
|
||||||
footer: model.cost?.input === 0 && provider.id === "opencode" ? "Free" : undefined,
|
footer: model.cost?.input === 0 && provider.id === "opencode" ? "Free" : undefined,
|
||||||
|
|
@ -84,7 +86,9 @@ export function DialogModel(props: { providerID?: string }) {
|
||||||
description: favorites.some((item) => item.providerID === provider.id && item.modelID === model)
|
description: favorites.some((item) => item.providerID === provider.id && item.modelID === model)
|
||||||
? "(Favorite)"
|
? "(Favorite)"
|
||||||
: undefined,
|
: undefined,
|
||||||
category: connected() ? provider.name : undefined,
|
category: connected()
|
||||||
|
? consoleManagedProviderLabel(consoleManagedProviders, provider.id, provider.name)
|
||||||
|
: undefined,
|
||||||
disabled: provider.id === "opencode" && model.includes("-nano"),
|
disabled: provider.id === "opencode" && model.includes("-nano"),
|
||||||
footer: info.cost?.input === 0 && provider.id === "opencode" ? "Free" : undefined,
|
footer: info.cost?.input === 0 && provider.id === "opencode" ? "Free" : undefined,
|
||||||
onSelect() {
|
onSelect() {
|
||||||
|
|
@ -132,7 +136,11 @@ export function DialogModel(props: { providerID?: string }) {
|
||||||
props.providerID ? sync.data.provider.find((x) => x.id === props.providerID) : null,
|
props.providerID ? sync.data.provider.find((x) => x.id === props.providerID) : null,
|
||||||
)
|
)
|
||||||
|
|
||||||
const title = createMemo(() => provider()?.name ?? "Select model")
|
const title = createMemo(() => {
|
||||||
|
const value = provider()
|
||||||
|
if (!value) return "Select model"
|
||||||
|
return consoleManagedProviderLabel(sync.data.console_state.consoleManagedProviders, value.id, value.name)
|
||||||
|
})
|
||||||
|
|
||||||
function onSelect(providerID: string, modelID: string) {
|
function onSelect(providerID: string, modelID: string) {
|
||||||
local.model.set({ providerID, modelID }, { recent: true })
|
local.model.set({ providerID, modelID }, { recent: true })
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@ import { DialogModel } from "./dialog-model"
|
||||||
import { useKeyboard } from "@opentui/solid"
|
import { useKeyboard } from "@opentui/solid"
|
||||||
import { Clipboard } from "@tui/util/clipboard"
|
import { Clipboard } from "@tui/util/clipboard"
|
||||||
import { useToast } from "../ui/toast"
|
import { useToast } from "../ui/toast"
|
||||||
|
import { CONSOLE_MANAGED_ICON, isConsoleManagedProvider } from "@tui/util/provider-origin"
|
||||||
|
|
||||||
const PROVIDER_PRIORITY: Record<string, number> = {
|
const PROVIDER_PRIORITY: Record<string, number> = {
|
||||||
opencode: 0,
|
opencode: 0,
|
||||||
|
|
@ -28,11 +29,18 @@ export function createDialogProviderOptions() {
|
||||||
const dialog = useDialog()
|
const dialog = useDialog()
|
||||||
const sdk = useSDK()
|
const sdk = useSDK()
|
||||||
const toast = useToast()
|
const toast = useToast()
|
||||||
|
const { theme } = useTheme()
|
||||||
const options = createMemo(() => {
|
const options = createMemo(() => {
|
||||||
|
const consoleManagedProviders = new Set(sync.data.console_state.consoleManagedProviders)
|
||||||
|
|
||||||
return pipe(
|
return pipe(
|
||||||
sync.data.provider_next.all,
|
sync.data.provider_next.all,
|
||||||
sortBy((x) => PROVIDER_PRIORITY[x.id] ?? 99),
|
sortBy((x) => PROVIDER_PRIORITY[x.id] ?? 99),
|
||||||
map((provider) => ({
|
map((provider) => {
|
||||||
|
const consoleManaged = isConsoleManagedProvider(consoleManagedProviders, provider.id)
|
||||||
|
const connected = sync.data.provider_next.connected.includes(provider.id)
|
||||||
|
|
||||||
|
return {
|
||||||
title: provider.name,
|
title: provider.name,
|
||||||
value: provider.id,
|
value: provider.id,
|
||||||
description: {
|
description: {
|
||||||
|
|
@ -41,8 +49,16 @@ export function createDialogProviderOptions() {
|
||||||
openai: "(ChatGPT Plus/Pro or API key)",
|
openai: "(ChatGPT Plus/Pro or API key)",
|
||||||
"opencode-go": "Low cost subscription for everyone",
|
"opencode-go": "Low cost subscription for everyone",
|
||||||
}[provider.id],
|
}[provider.id],
|
||||||
|
footer: consoleManaged ? sync.data.console_state.activeOrgName : undefined,
|
||||||
category: provider.id in PROVIDER_PRIORITY ? "Popular" : "Other",
|
category: provider.id in PROVIDER_PRIORITY ? "Popular" : "Other",
|
||||||
|
gutter: consoleManaged ? (
|
||||||
|
<text fg={theme.textMuted}>{CONSOLE_MANAGED_ICON}</text>
|
||||||
|
) : connected ? (
|
||||||
|
<text fg={theme.success}>✓</text>
|
||||||
|
) : undefined,
|
||||||
async onSelect() {
|
async onSelect() {
|
||||||
|
if (consoleManaged) return
|
||||||
|
|
||||||
const methods = sync.data.provider_auth[provider.id] ?? [
|
const methods = sync.data.provider_auth[provider.id] ?? [
|
||||||
{
|
{
|
||||||
type: "api",
|
type: "api",
|
||||||
|
|
@ -95,12 +111,22 @@ export function createDialogProviderOptions() {
|
||||||
}
|
}
|
||||||
if (result.data?.method === "code") {
|
if (result.data?.method === "code") {
|
||||||
dialog.replace(() => (
|
dialog.replace(() => (
|
||||||
<CodeMethod providerID={provider.id} title={method.label} index={index} authorization={result.data!} />
|
<CodeMethod
|
||||||
|
providerID={provider.id}
|
||||||
|
title={method.label}
|
||||||
|
index={index}
|
||||||
|
authorization={result.data!}
|
||||||
|
/>
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
if (result.data?.method === "auto") {
|
if (result.data?.method === "auto") {
|
||||||
dialog.replace(() => (
|
dialog.replace(() => (
|
||||||
<AutoMethod providerID={provider.id} title={method.label} index={index} authorization={result.data!} />
|
<AutoMethod
|
||||||
|
providerID={provider.id}
|
||||||
|
title={method.label}
|
||||||
|
index={index}
|
||||||
|
authorization={result.data!}
|
||||||
|
/>
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -108,7 +134,8 @@ export function createDialogProviderOptions() {
|
||||||
return dialog.replace(() => <ApiMethod providerID={provider.id} title={method.label} />)
|
return dialog.replace(() => <ApiMethod providerID={provider.id} title={method.label} />)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
})),
|
}
|
||||||
|
}),
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
return options
|
return options
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,7 @@ import { useToast } from "../../ui/toast"
|
||||||
import { useKV } from "../../context/kv"
|
import { useKV } from "../../context/kv"
|
||||||
import { useTextareaKeybindings } from "../textarea-keybindings"
|
import { useTextareaKeybindings } from "../textarea-keybindings"
|
||||||
import { DialogSkill } from "../dialog-skill"
|
import { DialogSkill } from "../dialog-skill"
|
||||||
|
import { CONSOLE_MANAGED_ICON, consoleManagedProviderLabel } from "@tui/util/provider-origin"
|
||||||
|
|
||||||
export type PromptProps = {
|
export type PromptProps = {
|
||||||
sessionID?: string
|
sessionID?: string
|
||||||
|
|
@ -94,6 +95,14 @@ export function Prompt(props: PromptProps) {
|
||||||
const list = createMemo(() => props.placeholders?.normal ?? [])
|
const list = createMemo(() => props.placeholders?.normal ?? [])
|
||||||
const shell = createMemo(() => props.placeholders?.shell ?? [])
|
const shell = createMemo(() => props.placeholders?.shell ?? [])
|
||||||
const [auto, setAuto] = createSignal<AutocompleteRef>()
|
const [auto, setAuto] = createSignal<AutocompleteRef>()
|
||||||
|
const activeOrgName = createMemo(() => sync.data.console_state.activeOrgName)
|
||||||
|
const currentProviderLabel = createMemo(() => {
|
||||||
|
const current = local.model.current()
|
||||||
|
const provider = local.model.parsed().provider
|
||||||
|
if (!current) return provider
|
||||||
|
return consoleManagedProviderLabel(sync.data.console_state.consoleManagedProviders, current.providerID, provider)
|
||||||
|
})
|
||||||
|
const hasRightContent = createMemo(() => Boolean(props.right || activeOrgName()))
|
||||||
|
|
||||||
function promptModelWarning() {
|
function promptModelWarning() {
|
||||||
toast.show({
|
toast.show({
|
||||||
|
|
@ -1095,7 +1104,7 @@ export function Prompt(props: PromptProps) {
|
||||||
<text flexShrink={0} fg={keybind.leader ? theme.textMuted : theme.text}>
|
<text flexShrink={0} fg={keybind.leader ? theme.textMuted : theme.text}>
|
||||||
{local.model.parsed().model}
|
{local.model.parsed().model}
|
||||||
</text>
|
</text>
|
||||||
<text fg={theme.textMuted}>{local.model.parsed().provider}</text>
|
<text fg={theme.textMuted}>{currentProviderLabel()}</text>
|
||||||
<Show when={showVariant()}>
|
<Show when={showVariant()}>
|
||||||
<text fg={theme.textMuted}>·</text>
|
<text fg={theme.textMuted}>·</text>
|
||||||
<text>
|
<text>
|
||||||
|
|
@ -1105,7 +1114,16 @@ export function Prompt(props: PromptProps) {
|
||||||
</box>
|
</box>
|
||||||
</Show>
|
</Show>
|
||||||
</box>
|
</box>
|
||||||
|
<Show when={hasRightContent()}>
|
||||||
|
<box flexDirection="row" gap={1} alignItems="center">
|
||||||
{props.right}
|
{props.right}
|
||||||
|
<Show when={activeOrgName()}>
|
||||||
|
<text fg={theme.textMuted} onMouseUp={() => command.trigger("console.org.switch")}>
|
||||||
|
{`${CONSOLE_MANAGED_ICON} ${activeOrgName()}`}
|
||||||
|
</text>
|
||||||
|
</Show>
|
||||||
|
</box>
|
||||||
|
</Show>
|
||||||
</box>
|
</box>
|
||||||
</box>
|
</box>
|
||||||
</box>
|
</box>
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,7 @@ import { batch, onMount } from "solid-js"
|
||||||
import { Log } from "@/util/log"
|
import { Log } from "@/util/log"
|
||||||
import type { Path } from "@opencode-ai/sdk"
|
import type { Path } from "@opencode-ai/sdk"
|
||||||
import type { Workspace } from "@opencode-ai/sdk/v2"
|
import type { Workspace } from "@opencode-ai/sdk/v2"
|
||||||
|
import { ConsoleState, emptyConsoleState, type ConsoleState as ConsoleStateType } from "@/config/console-state"
|
||||||
|
|
||||||
export const { use: useSync, provider: SyncProvider } = createSimpleContext({
|
export const { use: useSync, provider: SyncProvider } = createSimpleContext({
|
||||||
name: "Sync",
|
name: "Sync",
|
||||||
|
|
@ -38,6 +39,7 @@ export const { use: useSync, provider: SyncProvider } = createSimpleContext({
|
||||||
provider: Provider[]
|
provider: Provider[]
|
||||||
provider_default: Record<string, string>
|
provider_default: Record<string, string>
|
||||||
provider_next: ProviderListResponse
|
provider_next: ProviderListResponse
|
||||||
|
console_state: ConsoleStateType
|
||||||
provider_auth: Record<string, ProviderAuthMethod[]>
|
provider_auth: Record<string, ProviderAuthMethod[]>
|
||||||
agent: Agent[]
|
agent: Agent[]
|
||||||
command: Command[]
|
command: Command[]
|
||||||
|
|
@ -81,6 +83,7 @@ export const { use: useSync, provider: SyncProvider } = createSimpleContext({
|
||||||
default: {},
|
default: {},
|
||||||
connected: [],
|
connected: [],
|
||||||
},
|
},
|
||||||
|
console_state: emptyConsoleState,
|
||||||
provider_auth: {},
|
provider_auth: {},
|
||||||
config: {},
|
config: {},
|
||||||
status: "loading",
|
status: "loading",
|
||||||
|
|
@ -365,11 +368,16 @@ export const { use: useSync, provider: SyncProvider } = createSimpleContext({
|
||||||
// blocking - include session.list when continuing a session
|
// blocking - include session.list when continuing a session
|
||||||
const providersPromise = sdk.client.config.providers({}, { throwOnError: true })
|
const providersPromise = sdk.client.config.providers({}, { throwOnError: true })
|
||||||
const providerListPromise = sdk.client.provider.list({}, { throwOnError: true })
|
const providerListPromise = sdk.client.provider.list({}, { throwOnError: true })
|
||||||
|
const consoleStatePromise = sdk.client.experimental.console
|
||||||
|
.get({}, { throwOnError: true })
|
||||||
|
.then((x) => ConsoleState.parse(x.data))
|
||||||
|
.catch(() => emptyConsoleState)
|
||||||
const agentsPromise = sdk.client.app.agents({}, { throwOnError: true })
|
const agentsPromise = sdk.client.app.agents({}, { throwOnError: true })
|
||||||
const configPromise = sdk.client.config.get({}, { throwOnError: true })
|
const configPromise = sdk.client.config.get({}, { throwOnError: true })
|
||||||
const blockingRequests: Promise<unknown>[] = [
|
const blockingRequests: Promise<unknown>[] = [
|
||||||
providersPromise,
|
providersPromise,
|
||||||
providerListPromise,
|
providerListPromise,
|
||||||
|
consoleStatePromise,
|
||||||
agentsPromise,
|
agentsPromise,
|
||||||
configPromise,
|
configPromise,
|
||||||
...(args.continue ? [sessionListPromise] : []),
|
...(args.continue ? [sessionListPromise] : []),
|
||||||
|
|
@ -379,6 +387,7 @@ export const { use: useSync, provider: SyncProvider } = createSimpleContext({
|
||||||
.then(() => {
|
.then(() => {
|
||||||
const providersResponse = providersPromise.then((x) => x.data!)
|
const providersResponse = providersPromise.then((x) => x.data!)
|
||||||
const providerListResponse = providerListPromise.then((x) => x.data!)
|
const providerListResponse = providerListPromise.then((x) => x.data!)
|
||||||
|
const consoleStateResponse = consoleStatePromise
|
||||||
const agentsResponse = agentsPromise.then((x) => x.data ?? [])
|
const agentsResponse = agentsPromise.then((x) => x.data ?? [])
|
||||||
const configResponse = configPromise.then((x) => x.data!)
|
const configResponse = configPromise.then((x) => x.data!)
|
||||||
const sessionListResponse = args.continue ? sessionListPromise : undefined
|
const sessionListResponse = args.continue ? sessionListPromise : undefined
|
||||||
|
|
@ -386,20 +395,23 @@ export const { use: useSync, provider: SyncProvider } = createSimpleContext({
|
||||||
return Promise.all([
|
return Promise.all([
|
||||||
providersResponse,
|
providersResponse,
|
||||||
providerListResponse,
|
providerListResponse,
|
||||||
|
consoleStateResponse,
|
||||||
agentsResponse,
|
agentsResponse,
|
||||||
configResponse,
|
configResponse,
|
||||||
...(sessionListResponse ? [sessionListResponse] : []),
|
...(sessionListResponse ? [sessionListResponse] : []),
|
||||||
]).then((responses) => {
|
]).then((responses) => {
|
||||||
const providers = responses[0]
|
const providers = responses[0]
|
||||||
const providerList = responses[1]
|
const providerList = responses[1]
|
||||||
const agents = responses[2]
|
const consoleState = responses[2]
|
||||||
const config = responses[3]
|
const agents = responses[3]
|
||||||
const sessions = responses[4]
|
const config = responses[4]
|
||||||
|
const sessions = responses[5]
|
||||||
|
|
||||||
batch(() => {
|
batch(() => {
|
||||||
setStore("provider", reconcile(providers.providers))
|
setStore("provider", reconcile(providers.providers))
|
||||||
setStore("provider_default", reconcile(providers.default))
|
setStore("provider_default", reconcile(providers.default))
|
||||||
setStore("provider_next", reconcile(providerList))
|
setStore("provider_next", reconcile(providerList))
|
||||||
|
setStore("console_state", reconcile(consoleState))
|
||||||
setStore("agent", reconcile(agents))
|
setStore("agent", reconcile(agents))
|
||||||
setStore("config", reconcile(config))
|
setStore("config", reconcile(config))
|
||||||
if (sessions !== undefined) setStore("session", reconcile(sessions))
|
if (sessions !== undefined) setStore("session", reconcile(sessions))
|
||||||
|
|
|
||||||
|
|
@ -38,6 +38,7 @@ export interface DialogSelectOption<T = any> {
|
||||||
description?: string
|
description?: string
|
||||||
footer?: JSX.Element | string
|
footer?: JSX.Element | string
|
||||||
category?: string
|
category?: string
|
||||||
|
categoryView?: JSX.Element
|
||||||
disabled?: boolean
|
disabled?: boolean
|
||||||
bg?: RGBA
|
bg?: RGBA
|
||||||
gutter?: JSX.Element
|
gutter?: JSX.Element
|
||||||
|
|
@ -291,9 +292,16 @@ export function DialogSelect<T>(props: DialogSelectProps<T>) {
|
||||||
<>
|
<>
|
||||||
<Show when={category}>
|
<Show when={category}>
|
||||||
<box paddingTop={index() > 0 ? 1 : 0} paddingLeft={3}>
|
<box paddingTop={index() > 0 ? 1 : 0} paddingLeft={3}>
|
||||||
|
<Show
|
||||||
|
when={options[0]?.categoryView}
|
||||||
|
fallback={
|
||||||
<text fg={theme.accent} attributes={TextAttributes.BOLD}>
|
<text fg={theme.accent} attributes={TextAttributes.BOLD}>
|
||||||
{category}
|
{category}
|
||||||
</text>
|
</text>
|
||||||
|
}
|
||||||
|
>
|
||||||
|
{options[0]?.categoryView}
|
||||||
|
</Show>
|
||||||
</box>
|
</box>
|
||||||
</Show>
|
</Show>
|
||||||
<For each={options}>
|
<For each={options}>
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,20 @@
|
||||||
|
export const CONSOLE_MANAGED_ICON = "⌂"
|
||||||
|
|
||||||
|
const contains = (consoleManagedProviders: string[] | ReadonlySet<string>, providerID: string) =>
|
||||||
|
Array.isArray(consoleManagedProviders)
|
||||||
|
? consoleManagedProviders.includes(providerID)
|
||||||
|
: consoleManagedProviders.has(providerID)
|
||||||
|
|
||||||
|
export const isConsoleManagedProvider = (consoleManagedProviders: string[] | ReadonlySet<string>, providerID: string) =>
|
||||||
|
contains(consoleManagedProviders, providerID)
|
||||||
|
|
||||||
|
export const consoleManagedProviderSuffix = (
|
||||||
|
consoleManagedProviders: string[] | ReadonlySet<string>,
|
||||||
|
providerID: string,
|
||||||
|
) => (contains(consoleManagedProviders, providerID) ? ` ${CONSOLE_MANAGED_ICON}` : "")
|
||||||
|
|
||||||
|
export const consoleManagedProviderLabel = (
|
||||||
|
consoleManagedProviders: string[] | ReadonlySet<string>,
|
||||||
|
providerID: string,
|
||||||
|
providerName: string,
|
||||||
|
) => `${providerName}${consoleManagedProviderSuffix(consoleManagedProviders, providerID)}`
|
||||||
|
|
@ -33,6 +33,7 @@ import { Account } from "@/account"
|
||||||
import { isRecord } from "@/util/record"
|
import { isRecord } from "@/util/record"
|
||||||
import { ConfigPaths } from "./paths"
|
import { ConfigPaths } from "./paths"
|
||||||
import { Filesystem } from "@/util/filesystem"
|
import { Filesystem } from "@/util/filesystem"
|
||||||
|
import type { ConsoleState } from "./console-state"
|
||||||
import { AppFileSystem } from "@/filesystem"
|
import { AppFileSystem } from "@/filesystem"
|
||||||
import { InstanceState } from "@/effect/instance-state"
|
import { InstanceState } from "@/effect/instance-state"
|
||||||
import { makeRuntime } from "@/effect/run-service"
|
import { makeRuntime } from "@/effect/run-service"
|
||||||
|
|
@ -1050,11 +1051,14 @@ export namespace Config {
|
||||||
config: Info
|
config: Info
|
||||||
directories: string[]
|
directories: string[]
|
||||||
deps: Promise<void>[]
|
deps: Promise<void>[]
|
||||||
|
consoleManagedProviders: string[]
|
||||||
|
activeOrgName?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Interface {
|
export interface Interface {
|
||||||
readonly get: () => Effect.Effect<Info>
|
readonly get: () => Effect.Effect<Info>
|
||||||
readonly getGlobal: () => Effect.Effect<Info>
|
readonly getGlobal: () => Effect.Effect<Info>
|
||||||
|
readonly getConsoleState: () => Effect.Effect<ConsoleState>
|
||||||
readonly update: (config: Info) => Effect.Effect<void>
|
readonly update: (config: Info) => Effect.Effect<void>
|
||||||
readonly updateGlobal: (config: Info) => Effect.Effect<Info>
|
readonly updateGlobal: (config: Info) => Effect.Effect<Info>
|
||||||
readonly invalidate: (wait?: boolean) => Effect.Effect<void>
|
readonly invalidate: (wait?: boolean) => Effect.Effect<void>
|
||||||
|
|
@ -1260,6 +1264,8 @@ export namespace Config {
|
||||||
const auth = yield* authSvc.all().pipe(Effect.orDie)
|
const auth = yield* authSvc.all().pipe(Effect.orDie)
|
||||||
|
|
||||||
let result: Info = {}
|
let result: Info = {}
|
||||||
|
const consoleManagedProviders = new Set<string>()
|
||||||
|
let activeOrgName: string | undefined
|
||||||
|
|
||||||
const scope = (source: string): PluginScope => {
|
const scope = (source: string): PluginScope => {
|
||||||
if (source.startsWith("http://") || source.startsWith("https://")) return "global"
|
if (source.startsWith("http://") || source.startsWith("https://")) return "global"
|
||||||
|
|
@ -1371,26 +1377,31 @@ export namespace Config {
|
||||||
log.debug("loaded custom config from OPENCODE_CONFIG_CONTENT")
|
log.debug("loaded custom config from OPENCODE_CONFIG_CONTENT")
|
||||||
}
|
}
|
||||||
|
|
||||||
const active = Option.getOrUndefined(yield* accountSvc.active().pipe(Effect.orDie))
|
const activeOrg = Option.getOrUndefined(
|
||||||
if (active?.active_org_id) {
|
yield* accountSvc.activeOrg().pipe(Effect.catch(() => Effect.succeed(Option.none()))),
|
||||||
|
)
|
||||||
|
if (activeOrg) {
|
||||||
yield* Effect.gen(function* () {
|
yield* Effect.gen(function* () {
|
||||||
const [configOpt, tokenOpt] = yield* Effect.all(
|
const [configOpt, tokenOpt] = yield* Effect.all(
|
||||||
[accountSvc.config(active.id, active.active_org_id!), accountSvc.token(active.id)],
|
[accountSvc.config(activeOrg.account.id, activeOrg.org.id), accountSvc.token(activeOrg.account.id)],
|
||||||
{ concurrency: 2 },
|
{ concurrency: 2 },
|
||||||
)
|
)
|
||||||
const token = Option.getOrUndefined(tokenOpt)
|
if (Option.isSome(tokenOpt)) {
|
||||||
if (token) {
|
process.env["OPENCODE_CONSOLE_TOKEN"] = tokenOpt.value
|
||||||
process.env["OPENCODE_CONSOLE_TOKEN"] = token
|
Env.set("OPENCODE_CONSOLE_TOKEN", tokenOpt.value)
|
||||||
Env.set("OPENCODE_CONSOLE_TOKEN", token)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const config = Option.getOrUndefined(configOpt)
|
activeOrgName = activeOrg.org.name
|
||||||
if (config) {
|
|
||||||
const source = `${active.url}/api/config`
|
if (Option.isSome(configOpt)) {
|
||||||
const next = yield* loadConfig(JSON.stringify(config), {
|
const source = `${activeOrg.account.url}/api/config`
|
||||||
|
const next = yield* loadConfig(JSON.stringify(configOpt.value), {
|
||||||
dir: path.dirname(source),
|
dir: path.dirname(source),
|
||||||
source,
|
source,
|
||||||
})
|
})
|
||||||
|
for (const providerID of Object.keys(next.provider ?? {})) {
|
||||||
|
consoleManagedProviders.add(providerID)
|
||||||
|
}
|
||||||
merge(source, next, "global")
|
merge(source, next, "global")
|
||||||
}
|
}
|
||||||
}).pipe(
|
}).pipe(
|
||||||
|
|
@ -1456,6 +1467,8 @@ export namespace Config {
|
||||||
config: result,
|
config: result,
|
||||||
directories,
|
directories,
|
||||||
deps,
|
deps,
|
||||||
|
consoleManagedProviders: Array.from(consoleManagedProviders),
|
||||||
|
activeOrgName,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
@ -1473,6 +1486,13 @@ export namespace Config {
|
||||||
return yield* InstanceState.use(state, (s) => s.directories)
|
return yield* InstanceState.use(state, (s) => s.directories)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const getConsoleState = Effect.fn("Config.getConsoleState")(function* () {
|
||||||
|
return yield* InstanceState.use(state, (s) => ({
|
||||||
|
consoleManagedProviders: s.consoleManagedProviders,
|
||||||
|
activeOrgName: s.activeOrgName,
|
||||||
|
}))
|
||||||
|
})
|
||||||
|
|
||||||
const waitForDependencies = Effect.fn("Config.waitForDependencies")(function* () {
|
const waitForDependencies = Effect.fn("Config.waitForDependencies")(function* () {
|
||||||
yield* InstanceState.useEffect(state, (s) => Effect.promise(() => Promise.all(s.deps).then(() => undefined)))
|
yield* InstanceState.useEffect(state, (s) => Effect.promise(() => Promise.all(s.deps).then(() => undefined)))
|
||||||
})
|
})
|
||||||
|
|
@ -1528,6 +1548,7 @@ export namespace Config {
|
||||||
return Service.of({
|
return Service.of({
|
||||||
get,
|
get,
|
||||||
getGlobal,
|
getGlobal,
|
||||||
|
getConsoleState,
|
||||||
update,
|
update,
|
||||||
updateGlobal,
|
updateGlobal,
|
||||||
invalidate,
|
invalidate,
|
||||||
|
|
@ -1553,6 +1574,10 @@ export namespace Config {
|
||||||
return runPromise((svc) => svc.getGlobal())
|
return runPromise((svc) => svc.getGlobal())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function getConsoleState() {
|
||||||
|
return runPromise((svc) => svc.getConsoleState())
|
||||||
|
}
|
||||||
|
|
||||||
export async function update(config: Info) {
|
export async function update(config: Info) {
|
||||||
return runPromise((svc) => svc.update(config))
|
return runPromise((svc) => svc.update(config))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,13 @@
|
||||||
|
import z from "zod"
|
||||||
|
|
||||||
|
export const ConsoleState = z.object({
|
||||||
|
consoleManagedProviders: z.array(z.string()),
|
||||||
|
activeOrgName: z.string().optional(),
|
||||||
|
})
|
||||||
|
|
||||||
|
export type ConsoleState = z.infer<typeof ConsoleState>
|
||||||
|
|
||||||
|
export const emptyConsoleState: ConsoleState = {
|
||||||
|
consoleManagedProviders: [],
|
||||||
|
activeOrgName: undefined,
|
||||||
|
}
|
||||||
|
|
@ -8,13 +8,112 @@ import { Instance } from "../../project/instance"
|
||||||
import { Project } from "../../project/project"
|
import { Project } from "../../project/project"
|
||||||
import { MCP } from "../../mcp"
|
import { MCP } from "../../mcp"
|
||||||
import { Session } from "../../session"
|
import { Session } from "../../session"
|
||||||
|
import { Config } from "../../config/config"
|
||||||
|
import { ConsoleState } from "../../config/console-state"
|
||||||
|
import { Account, AccountID, OrgID } from "../../account"
|
||||||
import { zodToJsonSchema } from "zod-to-json-schema"
|
import { zodToJsonSchema } from "zod-to-json-schema"
|
||||||
import { errors } from "../error"
|
import { errors } from "../error"
|
||||||
import { lazy } from "../../util/lazy"
|
import { lazy } from "../../util/lazy"
|
||||||
import { WorkspaceRoutes } from "./workspace"
|
import { WorkspaceRoutes } from "./workspace"
|
||||||
|
|
||||||
|
const ConsoleOrgOption = z.object({
|
||||||
|
accountID: z.string(),
|
||||||
|
accountEmail: z.string(),
|
||||||
|
accountUrl: z.string(),
|
||||||
|
orgID: z.string(),
|
||||||
|
orgName: z.string(),
|
||||||
|
active: z.boolean(),
|
||||||
|
})
|
||||||
|
|
||||||
|
const ConsoleOrgList = z.object({
|
||||||
|
orgs: z.array(ConsoleOrgOption),
|
||||||
|
})
|
||||||
|
|
||||||
|
const ConsoleSwitchBody = z.object({
|
||||||
|
accountID: z.string(),
|
||||||
|
orgID: z.string(),
|
||||||
|
})
|
||||||
|
|
||||||
export const ExperimentalRoutes = lazy(() =>
|
export const ExperimentalRoutes = lazy(() =>
|
||||||
new Hono()
|
new Hono()
|
||||||
|
.get(
|
||||||
|
"/console",
|
||||||
|
describeRoute({
|
||||||
|
summary: "Get active Console provider metadata",
|
||||||
|
description: "Get the active Console org name and the set of provider IDs managed by that Console org.",
|
||||||
|
operationId: "experimental.console.get",
|
||||||
|
responses: {
|
||||||
|
200: {
|
||||||
|
description: "Active Console provider metadata",
|
||||||
|
content: {
|
||||||
|
"application/json": {
|
||||||
|
schema: resolver(ConsoleState),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
async (c) => {
|
||||||
|
return c.json(await Config.getConsoleState())
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.get(
|
||||||
|
"/console/orgs",
|
||||||
|
describeRoute({
|
||||||
|
summary: "List switchable Console orgs",
|
||||||
|
description: "Get the available Console orgs across logged-in accounts, including the current active org.",
|
||||||
|
operationId: "experimental.console.listOrgs",
|
||||||
|
responses: {
|
||||||
|
200: {
|
||||||
|
description: "Switchable Console orgs",
|
||||||
|
content: {
|
||||||
|
"application/json": {
|
||||||
|
schema: resolver(ConsoleOrgList),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
async (c) => {
|
||||||
|
const [groups, active] = await Promise.all([Account.orgsByAccount(), Account.active()])
|
||||||
|
|
||||||
|
const orgs = groups.flatMap((group) =>
|
||||||
|
group.orgs.map((org) => ({
|
||||||
|
accountID: group.account.id,
|
||||||
|
accountEmail: group.account.email,
|
||||||
|
accountUrl: group.account.url,
|
||||||
|
orgID: org.id,
|
||||||
|
orgName: org.name,
|
||||||
|
active: !!active && active.id === group.account.id && active.active_org_id === org.id,
|
||||||
|
})),
|
||||||
|
)
|
||||||
|
return c.json({ orgs })
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.post(
|
||||||
|
"/console/switch",
|
||||||
|
describeRoute({
|
||||||
|
summary: "Switch active Console org",
|
||||||
|
description: "Persist a new active Console account/org selection for the current local OpenCode state.",
|
||||||
|
operationId: "experimental.console.switchOrg",
|
||||||
|
responses: {
|
||||||
|
200: {
|
||||||
|
description: "Switch success",
|
||||||
|
content: {
|
||||||
|
"application/json": {
|
||||||
|
schema: resolver(z.boolean()),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
validator("json", ConsoleSwitchBody),
|
||||||
|
async (c) => {
|
||||||
|
const body = c.req.valid("json")
|
||||||
|
await Account.switchOrg(AccountID.make(body.accountID), OrgID.make(body.orgID))
|
||||||
|
return c.json(true)
|
||||||
|
},
|
||||||
|
)
|
||||||
.get(
|
.get(
|
||||||
"/tool/ids",
|
"/tool/ids",
|
||||||
describeRoute({
|
describeRoute({
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,7 @@ import { Npm } from "../../src/npm"
|
||||||
|
|
||||||
const emptyAccount = Layer.mock(Account.Service)({
|
const emptyAccount = Layer.mock(Account.Service)({
|
||||||
active: () => Effect.succeed(Option.none()),
|
active: () => Effect.succeed(Option.none()),
|
||||||
|
activeOrg: () => Effect.succeed(Option.none()),
|
||||||
})
|
})
|
||||||
|
|
||||||
const emptyAuth = Layer.mock(Auth.Service)({
|
const emptyAuth = Layer.mock(Auth.Service)({
|
||||||
|
|
@ -282,6 +283,21 @@ test("resolves env templates in account config with account token", async () =>
|
||||||
active_org_id: OrgID.make("org-1"),
|
active_org_id: OrgID.make("org-1"),
|
||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
|
activeOrg: () =>
|
||||||
|
Effect.succeed(
|
||||||
|
Option.some({
|
||||||
|
account: {
|
||||||
|
id: AccountID.make("account-1"),
|
||||||
|
email: "user@example.com",
|
||||||
|
url: "https://control.example.com",
|
||||||
|
active_org_id: OrgID.make("org-1"),
|
||||||
|
},
|
||||||
|
org: {
|
||||||
|
id: OrgID.make("org-1"),
|
||||||
|
name: "Example Org",
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
),
|
||||||
config: () =>
|
config: () =>
|
||||||
Effect.succeed(
|
Effect.succeed(
|
||||||
Option.some({
|
Option.some({
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,9 @@ import type {
|
||||||
EventTuiPromptAppend,
|
EventTuiPromptAppend,
|
||||||
EventTuiSessionSelect,
|
EventTuiSessionSelect,
|
||||||
EventTuiToastShow,
|
EventTuiToastShow,
|
||||||
|
ExperimentalConsoleGetResponses,
|
||||||
|
ExperimentalConsoleListOrgsResponses,
|
||||||
|
ExperimentalConsoleSwitchOrgResponses,
|
||||||
ExperimentalResourceListResponses,
|
ExperimentalResourceListResponses,
|
||||||
ExperimentalSessionListResponses,
|
ExperimentalSessionListResponses,
|
||||||
ExperimentalWorkspaceCreateErrors,
|
ExperimentalWorkspaceCreateErrors,
|
||||||
|
|
@ -981,13 +984,13 @@ export class Config2 extends HeyApiClient {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Tool extends HeyApiClient {
|
export class Console extends HeyApiClient {
|
||||||
/**
|
/**
|
||||||
* List tool IDs
|
* Get active Console provider metadata
|
||||||
*
|
*
|
||||||
* Get a list of all available tool IDs, including both built-in tools and dynamically registered tools.
|
* Get the active Console org name and the set of provider IDs managed by that Console org.
|
||||||
*/
|
*/
|
||||||
public ids<ThrowOnError extends boolean = false>(
|
public get<ThrowOnError extends boolean = false>(
|
||||||
parameters?: {
|
parameters?: {
|
||||||
directory?: string
|
directory?: string
|
||||||
workspace?: string
|
workspace?: string
|
||||||
|
|
@ -1005,24 +1008,22 @@ export class Tool extends HeyApiClient {
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
return (options?.client ?? this.client).get<ToolIdsResponses, ToolIdsErrors, ThrowOnError>({
|
return (options?.client ?? this.client).get<ExperimentalConsoleGetResponses, unknown, ThrowOnError>({
|
||||||
url: "/experimental/tool/ids",
|
url: "/experimental/console",
|
||||||
...options,
|
...options,
|
||||||
...params,
|
...params,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* List tools
|
* List switchable Console orgs
|
||||||
*
|
*
|
||||||
* Get a list of available tools with their JSON schema parameters for a specific provider and model combination.
|
* Get the available Console orgs across logged-in accounts, including the current active org.
|
||||||
*/
|
*/
|
||||||
public list<ThrowOnError extends boolean = false>(
|
public listOrgs<ThrowOnError extends boolean = false>(
|
||||||
parameters: {
|
parameters?: {
|
||||||
directory?: string
|
directory?: string
|
||||||
workspace?: string
|
workspace?: string
|
||||||
provider: string
|
|
||||||
model: string
|
|
||||||
},
|
},
|
||||||
options?: Options<never, ThrowOnError>,
|
options?: Options<never, ThrowOnError>,
|
||||||
) {
|
) {
|
||||||
|
|
@ -1033,18 +1034,55 @@ export class Tool extends HeyApiClient {
|
||||||
args: [
|
args: [
|
||||||
{ in: "query", key: "directory" },
|
{ in: "query", key: "directory" },
|
||||||
{ in: "query", key: "workspace" },
|
{ in: "query", key: "workspace" },
|
||||||
{ in: "query", key: "provider" },
|
|
||||||
{ in: "query", key: "model" },
|
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
return (options?.client ?? this.client).get<ToolListResponses, ToolListErrors, ThrowOnError>({
|
return (options?.client ?? this.client).get<ExperimentalConsoleListOrgsResponses, unknown, ThrowOnError>({
|
||||||
url: "/experimental/tool",
|
url: "/experimental/console/orgs",
|
||||||
...options,
|
...options,
|
||||||
...params,
|
...params,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Switch active Console org
|
||||||
|
*
|
||||||
|
* Persist a new active Console account/org selection for the current local OpenCode state.
|
||||||
|
*/
|
||||||
|
public switchOrg<ThrowOnError extends boolean = false>(
|
||||||
|
parameters?: {
|
||||||
|
directory?: string
|
||||||
|
workspace?: string
|
||||||
|
accountID?: string
|
||||||
|
orgID?: string
|
||||||
|
},
|
||||||
|
options?: Options<never, ThrowOnError>,
|
||||||
|
) {
|
||||||
|
const params = buildClientParams(
|
||||||
|
[parameters],
|
||||||
|
[
|
||||||
|
{
|
||||||
|
args: [
|
||||||
|
{ in: "query", key: "directory" },
|
||||||
|
{ in: "query", key: "workspace" },
|
||||||
|
{ in: "body", key: "accountID" },
|
||||||
|
{ in: "body", key: "orgID" },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
)
|
||||||
|
return (options?.client ?? this.client).post<ExperimentalConsoleSwitchOrgResponses, unknown, ThrowOnError>({
|
||||||
|
url: "/experimental/console/switch",
|
||||||
|
...options,
|
||||||
|
...params,
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
...options?.headers,
|
||||||
|
...params.headers,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Workspace extends HeyApiClient {
|
export class Workspace extends HeyApiClient {
|
||||||
|
|
@ -1239,6 +1277,11 @@ export class Resource extends HeyApiClient {
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Experimental extends HeyApiClient {
|
export class Experimental extends HeyApiClient {
|
||||||
|
private _console?: Console
|
||||||
|
get console(): Console {
|
||||||
|
return (this._console ??= new Console({ client: this.client }))
|
||||||
|
}
|
||||||
|
|
||||||
private _workspace?: Workspace
|
private _workspace?: Workspace
|
||||||
get workspace(): Workspace {
|
get workspace(): Workspace {
|
||||||
return (this._workspace ??= new Workspace({ client: this.client }))
|
return (this._workspace ??= new Workspace({ client: this.client }))
|
||||||
|
|
@ -1255,6 +1298,72 @@ export class Experimental extends HeyApiClient {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export class Tool extends HeyApiClient {
|
||||||
|
/**
|
||||||
|
* List tool IDs
|
||||||
|
*
|
||||||
|
* Get a list of all available tool IDs, including both built-in tools and dynamically registered tools.
|
||||||
|
*/
|
||||||
|
public ids<ThrowOnError extends boolean = false>(
|
||||||
|
parameters?: {
|
||||||
|
directory?: string
|
||||||
|
workspace?: string
|
||||||
|
},
|
||||||
|
options?: Options<never, ThrowOnError>,
|
||||||
|
) {
|
||||||
|
const params = buildClientParams(
|
||||||
|
[parameters],
|
||||||
|
[
|
||||||
|
{
|
||||||
|
args: [
|
||||||
|
{ in: "query", key: "directory" },
|
||||||
|
{ in: "query", key: "workspace" },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
)
|
||||||
|
return (options?.client ?? this.client).get<ToolIdsResponses, ToolIdsErrors, ThrowOnError>({
|
||||||
|
url: "/experimental/tool/ids",
|
||||||
|
...options,
|
||||||
|
...params,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* List tools
|
||||||
|
*
|
||||||
|
* Get a list of available tools with their JSON schema parameters for a specific provider and model combination.
|
||||||
|
*/
|
||||||
|
public list<ThrowOnError extends boolean = false>(
|
||||||
|
parameters: {
|
||||||
|
directory?: string
|
||||||
|
workspace?: string
|
||||||
|
provider: string
|
||||||
|
model: string
|
||||||
|
},
|
||||||
|
options?: Options<never, ThrowOnError>,
|
||||||
|
) {
|
||||||
|
const params = buildClientParams(
|
||||||
|
[parameters],
|
||||||
|
[
|
||||||
|
{
|
||||||
|
args: [
|
||||||
|
{ in: "query", key: "directory" },
|
||||||
|
{ in: "query", key: "workspace" },
|
||||||
|
{ in: "query", key: "provider" },
|
||||||
|
{ in: "query", key: "model" },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
)
|
||||||
|
return (options?.client ?? this.client).get<ToolListResponses, ToolListErrors, ThrowOnError>({
|
||||||
|
url: "/experimental/tool",
|
||||||
|
...options,
|
||||||
|
...params,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export class Worktree extends HeyApiClient {
|
export class Worktree extends HeyApiClient {
|
||||||
/**
|
/**
|
||||||
* Remove worktree
|
* Remove worktree
|
||||||
|
|
@ -4017,16 +4126,16 @@ export class OpencodeClient extends HeyApiClient {
|
||||||
return (this._config ??= new Config2({ client: this.client }))
|
return (this._config ??= new Config2({ client: this.client }))
|
||||||
}
|
}
|
||||||
|
|
||||||
private _tool?: Tool
|
|
||||||
get tool(): Tool {
|
|
||||||
return (this._tool ??= new Tool({ client: this.client }))
|
|
||||||
}
|
|
||||||
|
|
||||||
private _experimental?: Experimental
|
private _experimental?: Experimental
|
||||||
get experimental(): Experimental {
|
get experimental(): Experimental {
|
||||||
return (this._experimental ??= new Experimental({ client: this.client }))
|
return (this._experimental ??= new Experimental({ client: this.client }))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _tool?: Tool
|
||||||
|
get tool(): Tool {
|
||||||
|
return (this._tool ??= new Tool({ client: this.client }))
|
||||||
|
}
|
||||||
|
|
||||||
private _worktree?: Worktree
|
private _worktree?: Worktree
|
||||||
get worktree(): Worktree {
|
get worktree(): Worktree {
|
||||||
return (this._worktree ??= new Worktree({ client: this.client }))
|
return (this._worktree ??= new Worktree({ client: this.client }))
|
||||||
|
|
|
||||||
|
|
@ -2653,6 +2653,80 @@ export type ConfigProvidersResponses = {
|
||||||
|
|
||||||
export type ConfigProvidersResponse = ConfigProvidersResponses[keyof ConfigProvidersResponses]
|
export type ConfigProvidersResponse = ConfigProvidersResponses[keyof ConfigProvidersResponses]
|
||||||
|
|
||||||
|
export type ExperimentalConsoleGetData = {
|
||||||
|
body?: never
|
||||||
|
path?: never
|
||||||
|
query?: {
|
||||||
|
directory?: string
|
||||||
|
workspace?: string
|
||||||
|
}
|
||||||
|
url: "/experimental/console"
|
||||||
|
}
|
||||||
|
|
||||||
|
export type ExperimentalConsoleGetResponses = {
|
||||||
|
/**
|
||||||
|
* Active Console provider metadata
|
||||||
|
*/
|
||||||
|
200: {
|
||||||
|
consoleManagedProviders: Array<string>
|
||||||
|
activeOrgName?: string
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export type ExperimentalConsoleGetResponse = ExperimentalConsoleGetResponses[keyof ExperimentalConsoleGetResponses]
|
||||||
|
|
||||||
|
export type ExperimentalConsoleListOrgsData = {
|
||||||
|
body?: never
|
||||||
|
path?: never
|
||||||
|
query?: {
|
||||||
|
directory?: string
|
||||||
|
workspace?: string
|
||||||
|
}
|
||||||
|
url: "/experimental/console/orgs"
|
||||||
|
}
|
||||||
|
|
||||||
|
export type ExperimentalConsoleListOrgsResponses = {
|
||||||
|
/**
|
||||||
|
* Switchable Console orgs
|
||||||
|
*/
|
||||||
|
200: {
|
||||||
|
orgs: Array<{
|
||||||
|
accountID: string
|
||||||
|
accountEmail: string
|
||||||
|
accountUrl: string
|
||||||
|
orgID: string
|
||||||
|
orgName: string
|
||||||
|
active: boolean
|
||||||
|
}>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export type ExperimentalConsoleListOrgsResponse =
|
||||||
|
ExperimentalConsoleListOrgsResponses[keyof ExperimentalConsoleListOrgsResponses]
|
||||||
|
|
||||||
|
export type ExperimentalConsoleSwitchOrgData = {
|
||||||
|
body?: {
|
||||||
|
accountID: string
|
||||||
|
orgID: string
|
||||||
|
}
|
||||||
|
path?: never
|
||||||
|
query?: {
|
||||||
|
directory?: string
|
||||||
|
workspace?: string
|
||||||
|
}
|
||||||
|
url: "/experimental/console/switch"
|
||||||
|
}
|
||||||
|
|
||||||
|
export type ExperimentalConsoleSwitchOrgResponses = {
|
||||||
|
/**
|
||||||
|
* Switch success
|
||||||
|
*/
|
||||||
|
200: boolean
|
||||||
|
}
|
||||||
|
|
||||||
|
export type ExperimentalConsoleSwitchOrgResponse =
|
||||||
|
ExperimentalConsoleSwitchOrgResponses[keyof ExperimentalConsoleSwitchOrgResponses]
|
||||||
|
|
||||||
export type ToolIdsData = {
|
export type ToolIdsData = {
|
||||||
body?: never
|
body?: never
|
||||||
path?: never
|
path?: never
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue