fix(sdk): share generated session identity

This commit is contained in:
Tianyi Cui
2026-07-16 00:51:12 +08:00
parent 3765abf731
commit 828d6004ba
4 changed files with 25 additions and 12 deletions

View File

@@ -4,6 +4,7 @@
* @module @deepseek-ai/dsh-helper/features/builtin/app
*/
import { JsExpression } from '../../documents/cordis-yaml-file.ts'
import { featureId } from '../../ids.ts'
import type { ProjectProfile } from '../../project/types.ts'
import {
@@ -94,11 +95,11 @@ class AppOption extends FeatureOption {
name: '@deepseek-ai/dsh-stdio',
config: {
welcome: 'agent REPL ready. Give it a coding task.',
agent: 'main',
sessionId: new JsExpression('process.env.DSH_SDK_SESSION_ID'),
},
}, ['welcome', 'agent'], config => [
}, ['welcome', 'sessionId'], config => [
...optionalString(config, 'welcome'),
...requiredString(config, 'agent'),
...config.sessionId instanceof JsExpression ? [] : requiredString(config, 'sessionId'),
]),
])
case 'embed':

View File

@@ -2,14 +2,12 @@
import { startSDK, type SdkBootContext } from '@deepseek-ai/dsh-scripts'
{{else}}
import { randomUUID } from 'node:crypto'
import { AgentId } from '@deepseek-ai/dsh-agent'
import { SessionId } from '@deepseek-ai/dsh-session'
import { startSDK, type SdkBootContext } from '@deepseek-ai/dsh-scripts'
{{/if}}
/** Boot this project's cordis.yml when invoked by dsh-scripts. */
export async function main(boot: SdkBootContext) {
const ctx = await startSDK(new URL('./cordis.yml', import.meta.url))
{{#if isStdio}}
const model = boot.args.model
if (typeof model !== 'string' || model.length === 0) throw new Error('stdio startup requires --model=<name>')
@@ -17,24 +15,26 @@ export async function main(boot: SdkBootContext) {
if (resume !== undefined && (typeof resume !== 'string' || resume.length === 0)) {
throw new Error('stdio startup requires --resume=<session-id>')
}
const sessionId = SessionId(resume ?? `main-session-${randomUUID()}`)
process.env.DSH_SDK_SESSION_ID = sessionId
{{/if}}
const ctx = await startSDK(new URL('./cordis.yml', import.meta.url))
{{#if isStdio}}
if (resume === undefined) {
await ctx.agents.create({
agentId: AgentId('main'),
sessionId: SessionId(`main-session-${randomUUID()}`),
sessionId,
meta: { cwd: boot.cwd },
agentOptions: { model },
})
} else {
await ctx.agents.resume({
agentId: AgentId('main'),
resumeSessionId: SessionId(resume),
resumeSessionId: sessionId,
agentOptions: { model },
})
}
{{else}}
{{#if isEmbed}}
await ctx.agents.create({
agentId: AgentId('main'),
sessionId: SessionId(`main-session-${randomUUID()}`),
meta: { cwd: boot.cwd },
agentOptions: { model: {{modelLiteral}} },