diff --git a/frontend/src/api/env-vars.ts b/frontend/src/api/env-vars.ts new file mode 100644 index 00000000..5dc64c28 --- /dev/null +++ b/frontend/src/api/env-vars.ts @@ -0,0 +1,85 @@ +import { del, get, put } from '@/utils/request' + +/** + * Which value an execution would actually use for one variable. + * + * `unset` means nothing is stored anywhere, `workspace` means an admin filled + * it in for everyone, `user` means the caller filled in their own — which wins + * over the workspace one for this caller only. + */ +export type EnvVarSource = 'unset' | 'workspace' | 'user' + +/** + * One variable as its owner may see it. There is deliberately no value field: + * the endpoint reports what is missing, never what is stored. + */ +export interface EnvVarView { + name: string + description?: string + required?: boolean + source: EnvVarSource + /** Present only for the caller's own value; a workspace value has no per-variable timestamp. */ + updated_at?: string +} + +/** One skill's declared credentials. */ +export interface SkillEnvGroup { + skill_id: string + skill_name: string + vars: EnvVarView[] +} + +/** + * One sandbox config: the caller's own config-wide variables, injected into + * every execution on it, plus the credentials its skills declared. + */ +export interface ConfigEnvGroup { + sandbox_config_id: string + sandbox_config_name: string + vars: EnvVarView[] + skills: SkillEnvGroup[] +} + +export function listMyEnvVars(): Promise<{ data: ConfigEnvGroup[] }> { + return get('/api/v1/me/env-vars') as unknown as Promise<{ data: ConfigEnvGroup[] }> +} + +export function setMySkillEnv( + skillId: string, + name: string, + value: string, +): Promise<{ success: boolean }> { + return put('/api/v1/me/env-vars/skill', { skill_id: skillId, name, value }) as unknown as Promise<{ + success: boolean + }> +} + +/** + * Removes the caller's own value, after which the workspace value (if any) + * applies again. The scope and name travel in a JSON body rather than the query + * string, matching the PUT above. + */ +export function deleteMySkillEnv(skillId: string, name: string): Promise<{ success: boolean }> { + return del('/api/v1/me/env-vars/skill', { skill_id: skillId, name }) as unknown as Promise<{ + success: boolean + }> +} + +export function setMySandboxEnv( + configId: string, + name: string, + value: string, +): Promise<{ success: boolean }> { + return put('/api/v1/me/env-vars/sandbox', { + sandbox_config_id: configId, + name, + value, + }) as unknown as Promise<{ success: boolean }> +} + +export function deleteMySandboxEnv(configId: string, name: string): Promise<{ success: boolean }> { + return del('/api/v1/me/env-vars/sandbox', { + sandbox_config_id: configId, + name, + }) as unknown as Promise<{ success: boolean }> +} diff --git a/frontend/src/api/system/index.ts b/frontend/src/api/system/index.ts index 51760de1..12788104 100644 --- a/frontend/src/api/system/index.ts +++ b/frontend/src/api/system/index.ts @@ -1006,6 +1006,18 @@ export function parseSandboxConflict(err: unknown): SandboxConflict | null { export type ConfigSkillStatus = 'installing' | 'ready' | 'failed' | 'removing' | 'removed' +/** + * One environment variable the skill's installer declared. `is_set` reports + * whether a workspace-wide value exists; the value itself is never returned, + * so an editor can show that something is stored but not what. + */ +export interface ConfigSkillEnv { + name: string + description?: string + required?: boolean + is_set: boolean +} + export interface ConfigSkill { id: string name: string @@ -1023,6 +1035,9 @@ export interface ConfigSkill { install_message_id?: string created_at: string updated_at: string + // Absent for a skill whose installer declared nothing, which is how the + // panel decides whether to offer the environment variable editor at all. + envs?: ConfigSkillEnv[] } export interface ConfigSkillInstallEvent { @@ -1069,10 +1084,15 @@ export function reinstallConfigSkill( ) as unknown as Promise<{ data: { skill_id: string } }> } +/** + * Partial update: an absent field is left alone. `envs` names only the + * variables to write — an entry with an empty string clears the stored value + * while keeping the declaration, and undeclared names are ignored server-side. + */ export function patchConfigSkill( configId: string, skillId: string, - payload: { enabled: boolean }, + payload: { enabled?: boolean; envs?: Record }, ): Promise<{ data: ConfigSkill }> { return patch(`/api/v1/sandbox-configs/${configId}/skills/${skillId}`, payload) as unknown as Promise<{ data: ConfigSkill diff --git a/frontend/src/components/SandboxConfigEditorDrawer.vue b/frontend/src/components/SandboxConfigEditorDrawer.vue index 97b7ce14..35d1833e 100644 --- a/frontend/src/components/SandboxConfigEditorDrawer.vue +++ b/frontend/src/components/SandboxConfigEditorDrawer.vue @@ -472,9 +472,6 @@

{{ $t('settings.sandbox.checkPendingHint', { names: pendingCheckNames.join('、') }) }}

- diff --git a/frontend/src/components/SandboxSkillsPanel.vue b/frontend/src/components/SandboxSkillsPanel.vue index 1ccb7de6..5ee4cf11 100644 --- a/frontend/src/components/SandboxSkillsPanel.vue +++ b/frontend/src/components/SandboxSkillsPanel.vue @@ -179,6 +179,27 @@ @change="(v: any) => toggleEnabled(skill, Boolean(v))" /> + + +