Files
dify/cli/src/workspace/resolver.ts
L1nSn0w 6e1e0d9439 feat(openapi,cli): workspace switch + member management (#36651)
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2026-05-27 03:05:47 +00:00

35 lines
1.0 KiB
TypeScript

import type { HostsBundle } from '../auth/hosts.js'
import { BaseError } from '../errors/base.js'
import { ErrorCode } from '../errors/codes.js'
export type WorkspaceResolveInputs = {
readonly flag?: string
readonly env?: string
readonly bundle?: HostsBundle
}
export function resolveWorkspaceId(inputs: WorkspaceResolveInputs): string {
if (truthy(inputs.flag))
return inputs.flag
if (truthy(inputs.env))
return inputs.env
const b = inputs.bundle
if (b !== undefined) {
if (truthy(b.workspace?.id))
return b.workspace.id
if (b.available_workspaces !== undefined && b.available_workspaces.length > 0
&& truthy(b.available_workspaces[0]?.id)) {
return b.available_workspaces[0].id
}
}
throw new BaseError({
code: ErrorCode.UsageMissingArg,
message: 'no workspace selected',
hint: 'pass --workspace, set DIFY_WORKSPACE_ID, or run \'difyctl use workspace <id>\'',
})
}
function truthy(v: string | undefined): v is string {
return v !== undefined && v !== ''
}