|
|
@@ -6,7 +6,7 @@
|
|
|
import { homedir } from 'node:os'
|
|
|
import { dirname } from 'node:path'
|
|
|
import type { Context } from '@deepseek-ai/cordis'
|
|
|
-import type { Agent, ModelSelection } from '@deepseek-ai/dsh-agent'
|
|
|
+import type { ModelSelection } from '@deepseek-ai/dsh-agent'
|
|
|
import type {} from '@deepseek-ai/dsh-agent-presets/types'
|
|
|
import type { Session, SessionId } from '@deepseek-ai/dsh-session'
|
|
|
import { SubagentError } from '@deepseek-ai/dsh-subagent'
|
|
|
@@ -16,7 +16,7 @@ import {
|
|
|
PresetNotWritableError, UnknownPresetError,
|
|
|
} from '@deepseek-ai/dsh-agent-presets'
|
|
|
import type {
|
|
|
- ApiProxy, ConfigurableProviderView, CredentialView, GoalRef,
|
|
|
+ ApiProxy, ConfigurableProviderView, CredentialView,
|
|
|
SettingsNamespaceView,
|
|
|
} from './api/index.ts'
|
|
|
import type { SessionRequestId } from '@deepseek-ai/dsh-api-session-controller/types'
|
|
|
@@ -32,9 +32,6 @@ import {
|
|
|
type SessionLogCompressionLevel,
|
|
|
} from './session-export.ts'
|
|
|
import type { SessionRawArtifact } from '@deepseek-ai/dsh-session-persistence'
|
|
|
-// GoalError narrows domain rejections to their stable codes at the wire boundary.
|
|
|
-import { GoalError } from '@deepseek-ai/dsh-goal'
|
|
|
-import type { GoalRef as CoreGoalRef } from '@deepseek-ai/dsh-goal'
|
|
|
// Type-only edges: resolve the command-change stream and `ctx.get('skills')`.
|
|
|
import type {} from '@deepseek-ai/dsh-commands'
|
|
|
import type {} from '@deepseek-ai/dsh-skill'
|
|
|
@@ -270,47 +267,6 @@ export function createApiProxy(ctx: Context, defaults: ApiProxyDefaults): ApiPro
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * Resolve the goal service THIS agent runs.
|
|
|
- *
|
|
|
- * The service is per session: an agent preset mounts it behind an `isolate`
|
|
|
- * realm, which no host context resolves. Reading it from the root would
|
|
|
- * answer "absent" for a session whose composition mounts it — so the lookup
|
|
|
- * is keyed by the agent, and only a deployment composing it nowhere is
|
|
|
- * genuinely absent.
|
|
|
- */
|
|
|
- function goalServiceFor(agent: Agent): NonNullable<ReturnType<typeof ctx.get<'goals'>>> | { error: RpcError } {
|
|
|
- const presets = ctx.get('agentPresets')
|
|
|
- const goals = presets?.serviceFor(agent, 'goals') ?? ctx.get('goals')
|
|
|
- if (goals === undefined) {
|
|
|
- return { error: { code: 'internal', message: 'goal service is absent: neither this session\'s agent preset nor the host composition mounts @deepseek-ai/dsh-goal', details: {} } }
|
|
|
- }
|
|
|
- return goals
|
|
|
- }
|
|
|
-
|
|
|
- /** Map one goal-domain rejection to the wire error (stable GoalError codes ride in details). */
|
|
|
- function goalError(request: RpcRequest<unknown>, error: unknown): RpcResponse<never> {
|
|
|
- const details = error instanceof GoalError ? { goalCode: error.code } : {}
|
|
|
- return err(request, { code: 'internal', message: String(error), details })
|
|
|
- }
|
|
|
-
|
|
|
- /** Resolve a session's agent, apply one goal mutation, and acknowledge with the new CAS ref. */
|
|
|
- async function mutateGoal(
|
|
|
- request: RpcRequest<{ sessionId: SessionId }>,
|
|
|
- mutation: (goals: NonNullable<ReturnType<typeof ctx.get<'goals'>>>, agent: Agent) => CoreGoalRef,
|
|
|
- ): Promise<RpcResponse<{ ref: GoalRef }>> {
|
|
|
- const found = await agentFor(request.payload.sessionId)
|
|
|
- if ('error' in found) return err(request, found.error)
|
|
|
- const goals = goalServiceFor(found.agent)
|
|
|
- if ('error' in goals) return err(request, goals.error)
|
|
|
- try {
|
|
|
- const ref = mutation(goals, found.agent)
|
|
|
- return ok(request, { ref: { id: ref.id, revision: ref.revision } })
|
|
|
- } catch (error: unknown) {
|
|
|
- return goalError(request, error)
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
/** Missing-service report shared by the settings domain (skills-domain stance). */
|
|
|
function settingsAbsent(): RpcError {
|
|
|
return { code: 'internal', message: 'settings service is absent: this deployment does not mount a settings provider (e.g. @deepseek-ai/dsh-settings-file) in its composition', details: {} }
|
|
|
@@ -623,54 +579,6 @@ export function createApiProxy(ctx: Context, defaults: ApiProxyDefaults): ApiPro
|
|
|
},
|
|
|
},
|
|
|
|
|
|
- goals: {
|
|
|
- // Mutations only — the read side is the 'goal' session projection.
|
|
|
- // Every verb resolves the session's agent (agentFor: implicit cold
|
|
|
- // resume, the command.* precedent) and acknowledges with the new CAS
|
|
|
- // ref; the committed goal/change event carries the whole value to every
|
|
|
- // client through the projection frames.
|
|
|
- async create(request) {
|
|
|
- const { objective, maxGoalRounds } = request.payload
|
|
|
- return mutateGoal(request, (goals, agent) => goals.create(agent, {
|
|
|
- objective,
|
|
|
- ...(maxGoalRounds !== undefined ? { maxGoalRounds } : {}),
|
|
|
- }))
|
|
|
- },
|
|
|
-
|
|
|
- async edit(request) {
|
|
|
- const { ref, objective, maxGoalRounds } = request.payload
|
|
|
- return mutateGoal(request, (goals, agent) => goals.edit(agent, ref, {
|
|
|
- ...(objective !== undefined ? { objective } : {}),
|
|
|
- ...(maxGoalRounds !== undefined ? { maxGoalRounds } : {}),
|
|
|
- }))
|
|
|
- },
|
|
|
-
|
|
|
- async pause(request) {
|
|
|
- return mutateGoal(request, (goals, agent) => goals.pause(agent, request.payload.ref))
|
|
|
- },
|
|
|
-
|
|
|
- async resume(request) {
|
|
|
- return mutateGoal(request, (goals, agent) => goals.resume(agent, request.payload.ref))
|
|
|
- },
|
|
|
-
|
|
|
- async complete(request) {
|
|
|
- return mutateGoal(request, (goals, agent) => goals.complete(agent, request.payload.ref))
|
|
|
- },
|
|
|
-
|
|
|
- async clear(request) {
|
|
|
- const found = await agentFor(request.payload.sessionId)
|
|
|
- if ('error' in found) return err(request, found.error)
|
|
|
- const goals = goalServiceFor(found.agent)
|
|
|
- if ('error' in goals) return err(request, goals.error)
|
|
|
- try {
|
|
|
- goals.clear(found.agent, request.payload.ref)
|
|
|
- return ok(request, { cleared: true as const })
|
|
|
- } catch (error: unknown) {
|
|
|
- return goalError(request, error)
|
|
|
- }
|
|
|
- },
|
|
|
- },
|
|
|
-
|
|
|
agentPresets: {
|
|
|
// A deployment with no roster answers with an empty list rather than an
|
|
|
// error: composing no presets is a valid deployment, and the browser
|