@dsh-cc/acp 0.0.0-stage → 0.9.1-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE-harness +21 -0
- package/README.i18n.yaml +6 -0
- package/README.md +4 -2
- package/README.zh.md +5 -0
- package/lib/codec.d.ts +13 -0
- package/lib/codec.d.ts.map +1 -0
- package/lib/codec.js +36 -0
- package/lib/codec.js.map +1 -0
- package/lib/content.d.ts +50 -0
- package/lib/content.d.ts.map +1 -0
- package/lib/content.js +217 -0
- package/lib/content.js.map +1 -0
- package/lib/index.d.ts +37 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +514 -0
- package/lib/index.js.map +1 -0
- package/lib/mcp.d.ts +15 -0
- package/lib/mcp.d.ts.map +1 -0
- package/lib/mcp.js +135 -0
- package/lib/mcp.js.map +1 -0
- package/lib/model-control.d.ts +62 -0
- package/lib/model-control.d.ts.map +1 -0
- package/lib/model-control.js +222 -0
- package/lib/model-control.js.map +1 -0
- package/lib/session.d.ts +135 -0
- package/lib/session.d.ts.map +1 -0
- package/lib/session.js +483 -0
- package/lib/session.js.map +1 -0
- package/lib/updates.d.ts +26 -0
- package/lib/updates.d.ts.map +1 -0
- package/lib/updates.js +100 -0
- package/lib/updates.js.map +1 -0
- package/lib/version.d.ts +13 -0
- package/lib/version.d.ts.map +1 -0
- package/lib/version.js +30 -0
- package/lib/version.js.map +1 -0
- package/package.json +71 -3
package/lib/mcp.js
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
// Vendored from @deepseek-ai/dsh-acp (packages/acp/acp/src/mcp.ts)
|
|
2
|
+
// Source ref: c1b47e41fcd54d20a0f061df28683bfc29ee24e5 (deepseek-harness, MIT — see LICENSE-harness)
|
|
3
|
+
// Copied 2026-10-09. Structural fixes flow from upstream during harness
|
|
4
|
+
// migrations; CC-specific divergences must be recorded in DIVERGENCE.md.
|
|
5
|
+
/** Standard ACP MCP-server declarations translated into Agent-scoped DSH MCP clients. */
|
|
6
|
+
import { createHash } from 'node:crypto';
|
|
7
|
+
import { validateHeaderName, validateHeaderValue } from 'node:http';
|
|
8
|
+
import { isAbsolute } from 'node:path';
|
|
9
|
+
import * as McpClient from '@deepseek-ai/dsh-mcp-client';
|
|
10
|
+
const VALID_SERVER_NAME = /^[A-Za-z0-9_-]{1,32}$/;
|
|
11
|
+
/** Caller-correctable MCP declaration failure. */
|
|
12
|
+
export class AcpMcpConfigError extends Error {
|
|
13
|
+
constructor(message) {
|
|
14
|
+
super(message);
|
|
15
|
+
this.name = 'AcpMcpConfigError';
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Validate and mount one session's complete standard MCP server list before Agent publication.
|
|
20
|
+
* @param agentCtx - unpublished Agent scope that owns the MCP clients and tools.
|
|
21
|
+
* @param servers - stable ACP stdio or HTTP server declarations.
|
|
22
|
+
* @param sessionCwd - canonical primary workspace used by stdio servers.
|
|
23
|
+
*/
|
|
24
|
+
export async function mountAcpMcpServers(agentCtx, servers, sessionCwd) {
|
|
25
|
+
const configs = resolveMcpConfigs(servers, sessionCwd);
|
|
26
|
+
for (const config of configs)
|
|
27
|
+
await agentCtx.plugin(McpClient, config);
|
|
28
|
+
}
|
|
29
|
+
/** Convert the stable stdio/HTTP ACP transports and reject every other transport. */
|
|
30
|
+
function resolveMcpConfigs(servers, sessionCwd) {
|
|
31
|
+
const names = new Set();
|
|
32
|
+
return servers.map((server, index) => {
|
|
33
|
+
const serverName = normalizeServerName(server.name);
|
|
34
|
+
if (names.has(serverName)) {
|
|
35
|
+
throw new AcpMcpConfigError(`mcpServers contains duplicate normalized name: ${serverName}`);
|
|
36
|
+
}
|
|
37
|
+
names.add(serverName);
|
|
38
|
+
if (!('type' in server)) {
|
|
39
|
+
if (!isAbsolute(server.command)) {
|
|
40
|
+
throw new AcpMcpConfigError(`mcpServers[${index}].command must be an absolute path`);
|
|
41
|
+
}
|
|
42
|
+
const env = entriesToRecord(server.env, `mcpServers[${index}].env`, 'environment');
|
|
43
|
+
const config = validateClientConfig(index, () => McpClient.Config({
|
|
44
|
+
transport: 'stdio',
|
|
45
|
+
serverName,
|
|
46
|
+
command: server.command,
|
|
47
|
+
args: server.args,
|
|
48
|
+
env,
|
|
49
|
+
cwd: sessionCwd,
|
|
50
|
+
failOnStartupError: true,
|
|
51
|
+
}));
|
|
52
|
+
return { ...config, env };
|
|
53
|
+
}
|
|
54
|
+
if (server.type === 'http') {
|
|
55
|
+
assertHttpUrl(server.url, `mcpServers[${index}].url`);
|
|
56
|
+
const headers = entriesToRecord(server.headers, `mcpServers[${index}].headers`, 'header');
|
|
57
|
+
const config = validateClientConfig(index, () => McpClient.Config({
|
|
58
|
+
transport: 'streamable-http',
|
|
59
|
+
serverName,
|
|
60
|
+
url: server.url,
|
|
61
|
+
headers,
|
|
62
|
+
failOnStartupError: true,
|
|
63
|
+
}));
|
|
64
|
+
return { ...config, headers };
|
|
65
|
+
}
|
|
66
|
+
throw new AcpMcpConfigError(`mcpServers[${index}] transport ${server.type} is not supported`);
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
/** Convert ordered ACP name/value entries without silently accepting duplicate keys. */
|
|
70
|
+
function entriesToRecord(entries, field, kind) {
|
|
71
|
+
// Valid environment and header names include "__proto__"; a null prototype
|
|
72
|
+
// keeps that entry as data instead of invoking Object.prototype's setter.
|
|
73
|
+
const result = Object.create(null);
|
|
74
|
+
const names = new Set();
|
|
75
|
+
for (const entry of entries) {
|
|
76
|
+
if (kind === 'header') {
|
|
77
|
+
try {
|
|
78
|
+
validateHeaderName(entry.name);
|
|
79
|
+
validateHeaderValue(entry.name, entry.value);
|
|
80
|
+
}
|
|
81
|
+
catch (_invalidHeader) {
|
|
82
|
+
throw new AcpMcpConfigError(`${field} contains an invalid header entry`);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
else if (entry.name.length === 0
|
|
86
|
+
|| entry.name.includes('=')
|
|
87
|
+
|| entry.name.includes('\0')
|
|
88
|
+
|| entry.value.includes('\0')) {
|
|
89
|
+
throw new AcpMcpConfigError(`${field} contains an invalid environment entry`);
|
|
90
|
+
}
|
|
91
|
+
const identity = kind === 'header' ? entry.name.toLowerCase() : entry.name;
|
|
92
|
+
if (names.has(identity))
|
|
93
|
+
throw new AcpMcpConfigError(`${field} contains duplicate name: ${entry.name}`);
|
|
94
|
+
names.add(identity);
|
|
95
|
+
result[entry.name] = entry.value;
|
|
96
|
+
}
|
|
97
|
+
return result;
|
|
98
|
+
}
|
|
99
|
+
/** Produce a stable DSH tool namespace from ACP's human-readable server name. */
|
|
100
|
+
function normalizeServerName(name) {
|
|
101
|
+
if (name.trim().length === 0 || /[\u0000-\u001f\u007f]/.test(name)) {
|
|
102
|
+
throw new AcpMcpConfigError('mcpServers contains an invalid server name');
|
|
103
|
+
}
|
|
104
|
+
if (VALID_SERVER_NAME.test(name))
|
|
105
|
+
return name;
|
|
106
|
+
const slug = name.normalize('NFKD')
|
|
107
|
+
.replace(/[^A-Za-z0-9_-]+/g, '_')
|
|
108
|
+
.replace(/^_+|_+$/g, '')
|
|
109
|
+
.slice(0, 20) || 'server';
|
|
110
|
+
const digest = createHash('sha256').update(name).digest('hex').slice(0, 8);
|
|
111
|
+
return `${slug}_${digest}`.slice(0, 32);
|
|
112
|
+
}
|
|
113
|
+
/** Require the stable Streamable HTTP transport URL schemes. */
|
|
114
|
+
function assertHttpUrl(value, field) {
|
|
115
|
+
try {
|
|
116
|
+
const url = new URL(value);
|
|
117
|
+
if (url.protocol !== 'http:' && url.protocol !== 'https:')
|
|
118
|
+
throw new Error('unsupported protocol');
|
|
119
|
+
}
|
|
120
|
+
catch (_invalidUrl) {
|
|
121
|
+
throw new AcpMcpConfigError(`${field} must be an absolute HTTP(S) URL`);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
/** Map the existing MCP provider's schema error into ACP invalid params. */
|
|
125
|
+
function validateClientConfig(index, parse) {
|
|
126
|
+
try {
|
|
127
|
+
return parse();
|
|
128
|
+
}
|
|
129
|
+
catch (error) {
|
|
130
|
+
/* v8 ignore next -- Schemastery validation rejects with Error instances. */
|
|
131
|
+
const detail = error instanceof Error ? error.message : String(error);
|
|
132
|
+
throw new AcpMcpConfigError(`mcpServers[${index}] is invalid: ${detail}`);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
//# sourceMappingURL=mcp.js.map
|
package/lib/mcp.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp.js","sourceRoot":"","sources":["../src/mcp.ts"],"names":[],"mappings":"AAAA,mEAAmE;AACnE,qGAAqG;AACrG,wEAAwE;AACxE,yEAAyE;AACzE,yFAAyF;AAGzF,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACxC,OAAO,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAA;AACnE,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAA;AAEtC,OAAO,KAAK,SAAS,MAAM,6BAA6B,CAAA;AAExD,MAAM,iBAAiB,GAAG,uBAAuB,CAAA;AAEjD,kDAAkD;AAClD,MAAM,OAAO,iBAAkB,SAAQ,KAAK;IAC1C,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,IAAI,GAAG,mBAAmB,CAAA;IACjC,CAAC;CACF;AAED;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB,CACtC,QAAiB,EACjB,OAA6B,EAC7B,UAAkB;IAElB,MAAM,OAAO,GAAG,iBAAiB,CAAC,OAAO,EAAE,UAAU,CAAC,CAAA;IACtD,KAAK,MAAM,MAAM,IAAI,OAAO;QAAE,MAAM,QAAQ,CAAC,MAAM,CAAC,SAAS,EAAE,MAAM,CAAC,CAAA;AACxE,CAAC;AAED,qFAAqF;AACrF,SAAS,iBAAiB,CAAC,OAA6B,EAAE,UAAkB;IAC1E,MAAM,KAAK,GAA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,OAAO,GAAG,IAAI,IAAI,MAAM,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAA;AACzC,CAAC;AAED,gEAAgE;AAChE,SAAS,aAAa,CAAC,KAAa,EAAE,KAAa;IACjD,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,CAAA;QAC1B,IAAI,GAAG,CAAC,QAAQ,KAAK,OAAO,IAAI,GAAG,CAAC,QAAQ,KAAK,QAAQ;YAAE,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAA;IACpG,CAAC;IAAC,OAAO,WAAW,EAAE,CAAC;QACrB,MAAM,IAAI,iBAAiB,CAAC,GAAG,KAAK,kCAAkC,CAAC,CAAA;IACzE,CAAC;AACH,CAAC;AAED,4EAA4E;AAC5E,SAAS,oBAAoB,CAAC,KAAa,EAAE,KAA6B;IACxE,IAAI,CAAC;QACH,OAAO,KAAK,EAAE,CAAA;IAChB,CAAC;IAAC,OAAO,KAAc,EAAE,CAAC;QACxB,4EAA4E;QAC5E,MAAM,MAAM,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;QACrE,MAAM,IAAI,iBAAiB,CAAC,cAAc,KAAK,iBAAiB,MAAM,EAAE,CAAC,CAAA;IAC3E,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/** Standard ACP session configuration over one Agent's model selection. */
|
|
2
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
3
|
+
import type { SessionConfigOption } from '@agentclientprotocol/sdk';
|
|
4
|
+
import { type ModelSelection, type ModelSelectionRef } from '@deepseek-ai/dsh-agent';
|
|
5
|
+
import { type LlmRuntime } from '@deepseek-ai/dsh-llm';
|
|
6
|
+
/** Caller-correctable session configuration failure. */
|
|
7
|
+
export declare class AcpModelConfigError extends Error {
|
|
8
|
+
constructor(message: string);
|
|
9
|
+
}
|
|
10
|
+
/** Project and mutate one Agent's provider/model/reasoning selection through ACP config options. */
|
|
11
|
+
export declare class AcpModelControl {
|
|
12
|
+
private readonly llm;
|
|
13
|
+
/** Scoped selection reference consumed by Agent request assembly. */
|
|
14
|
+
readonly selection: ModelSelectionRef;
|
|
15
|
+
private tail;
|
|
16
|
+
private selected;
|
|
17
|
+
private turnSelection;
|
|
18
|
+
private hasResolvedState;
|
|
19
|
+
constructor(llm: LlmRuntime, initial: ModelSelection | undefined);
|
|
20
|
+
/**
|
|
21
|
+
* Install request/prompt consistency listeners in the unpublished Agent scope.
|
|
22
|
+
* @param agentCtx - Agent scope that consumes this selection.
|
|
23
|
+
*/
|
|
24
|
+
install(agentCtx: Context): void;
|
|
25
|
+
/**
|
|
26
|
+
* Snapshot the selection attached to the next accepted ACP prompt.
|
|
27
|
+
* @returns a detached future selection, or undefined when listeners supply the route.
|
|
28
|
+
*/
|
|
29
|
+
snapshot(): ModelSelection | undefined;
|
|
30
|
+
/**
|
|
31
|
+
* Pin one admitted ACP message's selection for every step in its turn.
|
|
32
|
+
* @param turn - admitted Agent turn.
|
|
33
|
+
* @param selection - exact prompt-admission selection.
|
|
34
|
+
*/
|
|
35
|
+
pinTurn(turn: number, selection: ModelSelection): void;
|
|
36
|
+
/**
|
|
37
|
+
* Release only the exact completed turn's routing override.
|
|
38
|
+
* @param turn - completed Agent turn.
|
|
39
|
+
*/
|
|
40
|
+
releaseTurn(turn: number): void;
|
|
41
|
+
/**
|
|
42
|
+
* Return the complete standard config-option state after prior mutations settle.
|
|
43
|
+
* @param signal - optional catalog and exact-model cancellation.
|
|
44
|
+
* @returns all current standard configuration options.
|
|
45
|
+
*/
|
|
46
|
+
options(signal?: AbortSignal): Promise<SessionConfigOption[]>;
|
|
47
|
+
/**
|
|
48
|
+
* Set one advertised option and return the complete resulting option state.
|
|
49
|
+
* @param configId - standard option id.
|
|
50
|
+
* @param value - opaque selected value returned by a previous option state.
|
|
51
|
+
* @param signal - optional catalog and exact-model cancellation.
|
|
52
|
+
* @returns all standard options after the serialized mutation.
|
|
53
|
+
*/
|
|
54
|
+
set(configId: string, value: unknown, signal?: AbortSignal): Promise<SessionConfigOption[]>;
|
|
55
|
+
/** Keep concurrent client mutations in receive order without wedging after rejection. */
|
|
56
|
+
private serialize;
|
|
57
|
+
/** Build detached model choices and the dependent reasoning option. */
|
|
58
|
+
private state;
|
|
59
|
+
/** Validate an exact route and retain only Agent-owned selection fields. */
|
|
60
|
+
private resolveSelection;
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=model-control.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"model-control.d.ts","sourceRoot":"","sources":["../src/model-control.ts"],"names":[],"mappings":"AAIA,2EAA2E;AAE3E,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAClD,OAAO,KAAK,EAAE,mBAAmB,EAAwB,MAAM,0BAA0B,CAAA;AACzF,OAAO,EAAyB,KAAK,cAAc,EAAE,KAAK,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAC3G,OAAO,EAAyC,KAAK,UAAU,EAAE,MAAM,sBAAsB,CAAA;AAiB7F,wDAAwD;AACxD,qBAAa,mBAAoB,SAAQ,KAAK;gBAChC,OAAO,EAAE,MAAM;CAI5B;AAED,oGAAoG;AACpG,qBAAa,eAAe;IASxB,OAAO,CAAC,QAAQ,CAAC,GAAG;IARtB,qEAAqE;IACrE,QAAQ,CAAC,SAAS,EAAE,iBAAiB,CAAA;IACrC,OAAO,CAAC,IAAI,CAAoB;IAChC,OAAO,CAAC,QAAQ,CAA4B;IAC5C,OAAO,CAAC,aAAa,CAAyD;IAC9E,OAAO,CAAC,gBAAgB,CAAQ;gBAGb,GAAG,EAAE,UAAU,EAChC,OAAO,EAAE,cAAc,GAAG,SAAS;IAYrC;;;OAGG;IACH,OAAO,CAAC,QAAQ,EAAE,OAAO,GAAG,IAAI;IAIhC;;;OAGG;IACH,QAAQ,IAAI,cAAc,GAAG,SAAS;IAItC;;;;OAIG;IACH,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,cAAc,GAAG,IAAI;IAItD;;;OAGG;IACH,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAI/B;;;;OAIG;IACH,OAAO,CAAC,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,mBAAmB,EAAE,CAAC;IAI7D;;;;;;OAMG;IACH,GAAG,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,mBAAmB,EAAE,CAAC;IAiC3F,yFAAyF;IACzF,OAAO,CAAC,SAAS;IAMjB,uEAAuE;YACzD,KAAK;IA+EnB,4EAA4E;YAC9D,gBAAgB;CAQ/B"}
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
// Vendored from @deepseek-ai/dsh-acp (packages/acp/acp/src/model-control.ts)
|
|
2
|
+
// Source ref: c1b47e41fcd54d20a0f061df28683bfc29ee24e5 (deepseek-harness, MIT — see LICENSE-harness)
|
|
3
|
+
// Copied 2026-10-09. Structural fixes flow from upstream during harness
|
|
4
|
+
// migrations; CC-specific divergences must be recorded in DIVERGENCE.md.
|
|
5
|
+
/** Standard ACP session configuration over one Agent's model selection. */
|
|
6
|
+
import { installModelSelection } from '@deepseek-ai/dsh-agent';
|
|
7
|
+
import { ReasoningEffortId } from '@deepseek-ai/dsh-llm';
|
|
8
|
+
const MODEL_CONFIG_ID = 'model';
|
|
9
|
+
const REASONING_CONFIG_ID = 'reasoning_effort';
|
|
10
|
+
// DSH reasoning effort ids are non-empty, so the empty opaque ACP value is a disjoint provider-default choice.
|
|
11
|
+
const PROVIDER_DEFAULT_REASONING_VALUE = '';
|
|
12
|
+
/** Caller-correctable session configuration failure. */
|
|
13
|
+
export class AcpModelConfigError extends Error {
|
|
14
|
+
constructor(message) {
|
|
15
|
+
super(message);
|
|
16
|
+
this.name = 'AcpModelConfigError';
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
/** Project and mutate one Agent's provider/model/reasoning selection through ACP config options. */
|
|
20
|
+
export class AcpModelControl {
|
|
21
|
+
llm;
|
|
22
|
+
/** Scoped selection reference consumed by Agent request assembly. */
|
|
23
|
+
selection;
|
|
24
|
+
tail = Promise.resolve();
|
|
25
|
+
selected;
|
|
26
|
+
turnSelection;
|
|
27
|
+
hasResolvedState = false;
|
|
28
|
+
constructor(llm, initial) {
|
|
29
|
+
this.llm = llm;
|
|
30
|
+
this.selected = initial;
|
|
31
|
+
const getCurrent = () => this.turnSelection?.selection ?? this.selected;
|
|
32
|
+
const setCurrent = (value) => { this.selected = value; };
|
|
33
|
+
this.selection = {
|
|
34
|
+
get current() { return getCurrent(); },
|
|
35
|
+
set current(value) { setCurrent(value); },
|
|
36
|
+
assembled: undefined,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Install request/prompt consistency listeners in the unpublished Agent scope.
|
|
41
|
+
* @param agentCtx - Agent scope that consumes this selection.
|
|
42
|
+
*/
|
|
43
|
+
install(agentCtx) {
|
|
44
|
+
installModelSelection(agentCtx, this.selection);
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Snapshot the selection attached to the next accepted ACP prompt.
|
|
48
|
+
* @returns a detached future selection, or undefined when listeners supply the route.
|
|
49
|
+
*/
|
|
50
|
+
snapshot() {
|
|
51
|
+
return this.selected === undefined ? undefined : { ...this.selected };
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Pin one admitted ACP message's selection for every step in its turn.
|
|
55
|
+
* @param turn - admitted Agent turn.
|
|
56
|
+
* @param selection - exact prompt-admission selection.
|
|
57
|
+
*/
|
|
58
|
+
pinTurn(turn, selection) {
|
|
59
|
+
this.turnSelection = { turn, selection: { ...selection } };
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Release only the exact completed turn's routing override.
|
|
63
|
+
* @param turn - completed Agent turn.
|
|
64
|
+
*/
|
|
65
|
+
releaseTurn(turn) {
|
|
66
|
+
if (this.turnSelection?.turn === turn)
|
|
67
|
+
this.turnSelection = undefined;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Return the complete standard config-option state after prior mutations settle.
|
|
71
|
+
* @param signal - optional catalog and exact-model cancellation.
|
|
72
|
+
* @returns all current standard configuration options.
|
|
73
|
+
*/
|
|
74
|
+
options(signal) {
|
|
75
|
+
return this.serialize(async () => (await this.state(signal)).options);
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Set one advertised option and return the complete resulting option state.
|
|
79
|
+
* @param configId - standard option id.
|
|
80
|
+
* @param value - opaque selected value returned by a previous option state.
|
|
81
|
+
* @param signal - optional catalog and exact-model cancellation.
|
|
82
|
+
* @returns all standard options after the serialized mutation.
|
|
83
|
+
*/
|
|
84
|
+
set(configId, value, signal) {
|
|
85
|
+
return this.serialize(async () => {
|
|
86
|
+
if (typeof value !== 'string')
|
|
87
|
+
throw new AcpModelConfigError(`${configId} requires a select value`);
|
|
88
|
+
const current = this.selected;
|
|
89
|
+
if (current === undefined)
|
|
90
|
+
throw new AcpModelConfigError('this session has no model selection');
|
|
91
|
+
if (configId === MODEL_CONFIG_ID) {
|
|
92
|
+
const state = await this.state(signal);
|
|
93
|
+
const selected = state.choices.get(value);
|
|
94
|
+
if (selected === undefined)
|
|
95
|
+
throw new AcpModelConfigError(`unknown model option: ${value}`);
|
|
96
|
+
await this.resolveSelection(selected, signal);
|
|
97
|
+
this.selected = selected;
|
|
98
|
+
}
|
|
99
|
+
else if (configId === REASONING_CONFIG_ID) {
|
|
100
|
+
const info = await this.llm.resolveModelInfo(current.provider, current.model, signal);
|
|
101
|
+
const providerDefault = value === PROVIDER_DEFAULT_REASONING_VALUE
|
|
102
|
+
&& info.reasoning?.defaultEffort === undefined;
|
|
103
|
+
if (info.reasoning === undefined
|
|
104
|
+
|| (!providerDefault && !info.reasoning.efforts.some(effort => effort.id === value))) {
|
|
105
|
+
throw new AcpModelConfigError(`unknown reasoning effort for ${current.provider}/${current.model}: ${value}`);
|
|
106
|
+
}
|
|
107
|
+
this.selected = await this.resolveSelection({
|
|
108
|
+
provider: current.provider,
|
|
109
|
+
model: current.model,
|
|
110
|
+
...providerDefault ? {} : { reasoningEffort: ReasoningEffortId(value) },
|
|
111
|
+
}, signal);
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
throw new AcpModelConfigError(`unknown session config option: ${configId}`);
|
|
115
|
+
}
|
|
116
|
+
return (await this.state(signal)).options;
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
/** Keep concurrent client mutations in receive order without wedging after rejection. */
|
|
120
|
+
serialize(operation) {
|
|
121
|
+
const result = this.tail.then(operation);
|
|
122
|
+
this.tail = result.then(() => undefined, () => undefined);
|
|
123
|
+
return result;
|
|
124
|
+
}
|
|
125
|
+
/** Build detached model choices and the dependent reasoning option. */
|
|
126
|
+
async state(signal) {
|
|
127
|
+
const selected = this.selected;
|
|
128
|
+
if (selected === undefined)
|
|
129
|
+
return { choices: new Map(), options: [] };
|
|
130
|
+
let resolved;
|
|
131
|
+
let routeAvailable = true;
|
|
132
|
+
try {
|
|
133
|
+
resolved = await this.resolveSelection(selected, signal);
|
|
134
|
+
this.hasResolvedState = true;
|
|
135
|
+
}
|
|
136
|
+
catch (error) {
|
|
137
|
+
if (!this.hasResolvedState)
|
|
138
|
+
throw error;
|
|
139
|
+
resolved = selected;
|
|
140
|
+
routeAvailable = false;
|
|
141
|
+
}
|
|
142
|
+
const choices = new Map();
|
|
143
|
+
const groups = await Promise.all(this.llm.listProviders().map(async (provider) => {
|
|
144
|
+
try {
|
|
145
|
+
const models = await this.llm.listModels(provider.id);
|
|
146
|
+
const entries = models.map((model) => {
|
|
147
|
+
const choice = {
|
|
148
|
+
value: modelValue(provider.id, model.id),
|
|
149
|
+
selection: { provider: provider.id, model: model.id },
|
|
150
|
+
};
|
|
151
|
+
choices.set(choice.value, choice.selection);
|
|
152
|
+
return {
|
|
153
|
+
value: choice.value,
|
|
154
|
+
name: model.name,
|
|
155
|
+
...model.description === undefined ? {} : { description: model.description },
|
|
156
|
+
};
|
|
157
|
+
});
|
|
158
|
+
return { group: provider.id, name: provider.name, options: entries };
|
|
159
|
+
}
|
|
160
|
+
catch (_providerCatalogUnavailable) {
|
|
161
|
+
return { group: provider.id, name: provider.name, options: [] };
|
|
162
|
+
}
|
|
163
|
+
}));
|
|
164
|
+
const currentValue = modelValue(resolved.provider, resolved.model);
|
|
165
|
+
if (!choices.has(currentValue)) {
|
|
166
|
+
choices.set(currentValue, { provider: resolved.provider, model: resolved.model });
|
|
167
|
+
let group = groups.find(item => item.group === resolved.provider);
|
|
168
|
+
if (group === undefined) {
|
|
169
|
+
group = { group: resolved.provider, name: resolved.provider, options: [] };
|
|
170
|
+
groups.push(group);
|
|
171
|
+
}
|
|
172
|
+
group.options.unshift({ value: currentValue, name: resolved.model });
|
|
173
|
+
}
|
|
174
|
+
const options = [{
|
|
175
|
+
id: MODEL_CONFIG_ID,
|
|
176
|
+
name: 'Model',
|
|
177
|
+
category: 'model',
|
|
178
|
+
type: 'select',
|
|
179
|
+
currentValue,
|
|
180
|
+
options: groups.filter(group => group.options.length > 0),
|
|
181
|
+
}];
|
|
182
|
+
const info = routeAvailable
|
|
183
|
+
? await this.llm.resolveModelInfo(resolved.provider, resolved.model, signal)
|
|
184
|
+
: undefined;
|
|
185
|
+
if (info?.reasoning !== undefined) {
|
|
186
|
+
options.push({
|
|
187
|
+
id: REASONING_CONFIG_ID,
|
|
188
|
+
name: 'Reasoning effort',
|
|
189
|
+
category: 'thought_level',
|
|
190
|
+
type: 'select',
|
|
191
|
+
currentValue: resolved.reasoningEffort === undefined
|
|
192
|
+
? PROVIDER_DEFAULT_REASONING_VALUE
|
|
193
|
+
: String(resolved.reasoningEffort),
|
|
194
|
+
options: [
|
|
195
|
+
...info.reasoning.defaultEffort === undefined
|
|
196
|
+
? [{ value: PROVIDER_DEFAULT_REASONING_VALUE, name: 'Provider default' }]
|
|
197
|
+
: [],
|
|
198
|
+
...info.reasoning.efforts.map(effort => ({
|
|
199
|
+
value: String(effort.id),
|
|
200
|
+
name: effort.name,
|
|
201
|
+
...effort.description === undefined ? {} : { description: effort.description },
|
|
202
|
+
})),
|
|
203
|
+
],
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
return { choices, options };
|
|
207
|
+
}
|
|
208
|
+
/** Validate an exact route and retain only Agent-owned selection fields. */
|
|
209
|
+
async resolveSelection(selection, signal) {
|
|
210
|
+
const resolved = await this.llm.resolveCallConfig(selection, signal);
|
|
211
|
+
return {
|
|
212
|
+
provider: resolved.provider,
|
|
213
|
+
model: resolved.model,
|
|
214
|
+
...resolved.reasoningEffort === undefined ? {} : { reasoningEffort: resolved.reasoningEffort },
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
/** Opaque ACP selector value carrying the full route identity. */
|
|
219
|
+
function modelValue(provider, model) {
|
|
220
|
+
return JSON.stringify([provider, model]);
|
|
221
|
+
}
|
|
222
|
+
//# sourceMappingURL=model-control.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"model-control.js","sourceRoot":"","sources":["../src/model-control.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,qGAAqG;AACrG,wEAAwE;AACxE,yEAAyE;AACzE,2EAA2E;AAI3E,OAAO,EAAE,qBAAqB,EAA+C,MAAM,wBAAwB,CAAA;AAC3G,OAAO,EAAE,iBAAiB,EAAuC,MAAM,sBAAsB,CAAA;AAE7F,MAAM,eAAe,GAAG,OAAO,CAAA;AAC/B,MAAM,mBAAmB,GAAG,kBAAkB,CAAA;AAC9C,+GAA+G;AAC/G,MAAM,gCAAgC,GAAG,EAAE,CAAA;AAY3C,wDAAwD;AACxD,MAAM,OAAO,mBAAoB,SAAQ,KAAK;IAC5C,Y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E,gCAAgC,EAAE,IAAI,EAAE,kBAAkB,EAAE,CAAC;wBACzE,CAAC,CAAC,EAAE;oBACN,GAAG,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;wBACvC,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC;wBACxB,IAAI,EAAE,MAAM,CAAC,IAAI;wBACjB,GAAG,MAAM,CAAC,WAAW,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,MAAM,CAAC,WAAW,EAAE;qBAC/E,CAAC,CAAC;iBACJ;aACF,CAAC,CAAA;QACJ,CAAC;QACD,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,CAAA;IAC7B,CAAC;IAED,4EAA4E;IACpE,KAAK,CAAC,gBAAgB,CAAC,SAAyB,EAAE,MAAoB;QAC5E,MAAM,QAAQ,GAAkB,MAAM,IAAI,CAAC,GAAG,CAAC,iBAAiB,CAAC,SAAS,EAAE,MAAM,CAAC,CAAA;QACnF,OAAO;YACL,QAAQ,EAAE,QAAQ,CAAC,QAAQ;YAC3B,KAAK,EAAE,QAAQ,CAAC,KAAK;YACrB,GAAG,QAAQ,CAAC,eAAe,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,eAAe,EAAE,QAAQ,CAAC,eAAe,EAAE;SAC/F,CAAA;IACH,CAAC;CACF;AAED,kEAAkE;AAClE,SAAS,UAAU,CAAC,QAAgB,EAAE,KAAa;IACjD,OAAO,IAAI,CAAC,SAAS,CAAC,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC,CAAA;AAC1C,CAAC"}
|
package/lib/session.d.ts
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
/** One standard ACP session's Agent, configuration, prompt, update, and teardown lifecycle. */
|
|
2
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
3
|
+
import { type McpServer, type PromptRequest, type PromptResponse, type SessionConfigOption, type SessionNotification } from '@agentclientprotocol/sdk';
|
|
4
|
+
import type { Agent, AgentOptions, ModelSelection } from '@deepseek-ai/dsh-agent';
|
|
5
|
+
import { type UserMessage } from '@deepseek-ai/dsh-llm';
|
|
6
|
+
import { type Session, type SessionEvent, type SessionId } from '@deepseek-ai/dsh-session';
|
|
7
|
+
/** The preset-registry seam composed into every ACP session (§5.2). */
|
|
8
|
+
export interface AcpPresetsService {
|
|
9
|
+
mount(agentCtx: Context, presetId?: string): Promise<unknown>;
|
|
10
|
+
/** Compose a preset into a published agent, appending `agent-preset/selected`. */
|
|
11
|
+
select(agent: Agent, presetId: string): Promise<string>;
|
|
12
|
+
/** The preset a live agent already uses, if bound. */
|
|
13
|
+
composedPreset(ctx: Context): string | undefined;
|
|
14
|
+
}
|
|
15
|
+
/** Inputs shared by fresh and resumed ACP session construction. */
|
|
16
|
+
interface AcpSessionBuildOptions {
|
|
17
|
+
cwd: string;
|
|
18
|
+
mcpServers: readonly McpServer[];
|
|
19
|
+
agentOptions: AgentOptions;
|
|
20
|
+
fallbackSelection: ModelSelection | undefined;
|
|
21
|
+
presets: AcpPresetsService;
|
|
22
|
+
signal: AbortSignal;
|
|
23
|
+
notify: (notification: SessionNotification) => Promise<void>;
|
|
24
|
+
}
|
|
25
|
+
/** Fresh ACP session construction inputs. */
|
|
26
|
+
export interface CreateAcpSessionOptions extends AcpSessionBuildOptions {
|
|
27
|
+
sessionId: SessionId;
|
|
28
|
+
/** Agent preset composed into this session and stamped into its header. */
|
|
29
|
+
presetId: string;
|
|
30
|
+
}
|
|
31
|
+
/** Persisted ACP session construction inputs. */
|
|
32
|
+
export interface ResumeAcpSessionOptions extends AcpSessionBuildOptions {
|
|
33
|
+
sessionId: SessionId;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Per-session ACP module. It owns the unpublished Agent composition, selected
|
|
37
|
+
* route, one-prompt admission slot, ordered standard updates, and memoized
|
|
38
|
+
* quiescent teardown.
|
|
39
|
+
*/
|
|
40
|
+
export declare class AcpSession {
|
|
41
|
+
private readonly ctx;
|
|
42
|
+
private readonly notify;
|
|
43
|
+
/** The exact top-level Agent owned by this ACP session. */
|
|
44
|
+
readonly agent: Agent;
|
|
45
|
+
private readonly modelControl;
|
|
46
|
+
private outputTail;
|
|
47
|
+
private inflight;
|
|
48
|
+
private closing;
|
|
49
|
+
private readonly pendingSelections;
|
|
50
|
+
private constructor();
|
|
51
|
+
private readonly disposeAgent;
|
|
52
|
+
/**
|
|
53
|
+
* Compose a fresh Agent and all requested MCP clients before publication.
|
|
54
|
+
* @param ctx - ACP plugin context with Agent, LLM, and persistence services.
|
|
55
|
+
* @param options - fresh session identity, workspace, route, MCP, and notifier.
|
|
56
|
+
* @returns the fully composed per-session module.
|
|
57
|
+
*/
|
|
58
|
+
static create(ctx: Context, options: CreateAcpSessionOptions): Promise<AcpSession>;
|
|
59
|
+
/**
|
|
60
|
+
* Restore a persisted Agent and compose the request's fresh MCP connections.
|
|
61
|
+
* @param ctx - ACP plugin context with Agent, LLM, and persistence services.
|
|
62
|
+
* @param options - persisted identity, workspace, fallback route, MCP, and notifier.
|
|
63
|
+
* @returns the restored per-session module.
|
|
64
|
+
*/
|
|
65
|
+
static resume(ctx: Context, options: ResumeAcpSessionOptions): Promise<AcpSession>;
|
|
66
|
+
/**
|
|
67
|
+
* Whether this module owns an exact Agent reference.
|
|
68
|
+
* @param agent - Agent observed on a scoped runtime event.
|
|
69
|
+
* @returns true only for this session's owned Agent.
|
|
70
|
+
*/
|
|
71
|
+
owns(agent: Agent): boolean;
|
|
72
|
+
/**
|
|
73
|
+
* Whether this module owns an exact Session reference.
|
|
74
|
+
* @param session - Session observed on a durable event.
|
|
75
|
+
* @returns true only for this session's owned Session.
|
|
76
|
+
*/
|
|
77
|
+
ownsSession(session: Session): boolean;
|
|
78
|
+
/**
|
|
79
|
+
* Return the complete standard model configuration state.
|
|
80
|
+
* @param signal - optional request cancellation.
|
|
81
|
+
* @returns provider-grouped model and exact-model reasoning options.
|
|
82
|
+
*/
|
|
83
|
+
configOptions(signal?: AbortSignal): Promise<SessionConfigOption[]>;
|
|
84
|
+
/**
|
|
85
|
+
* Apply one standard configuration option to later ACP turns.
|
|
86
|
+
* @param configId - advertised standard option id.
|
|
87
|
+
* @param value - selected standard option value.
|
|
88
|
+
* @param signal - optional request cancellation.
|
|
89
|
+
* @returns the complete resulting option state.
|
|
90
|
+
*/
|
|
91
|
+
setConfig(configId: string, value: unknown, signal?: AbortSignal): Promise<SessionConfigOption[]>;
|
|
92
|
+
/** Resolve topology state off-chain, then serialize its notification without blocking execution updates. */
|
|
93
|
+
topologyChanged(): void;
|
|
94
|
+
/**
|
|
95
|
+
* Admit, enqueue, and settle one prompt at whole-Agent quiescence.
|
|
96
|
+
* @param params - standard ACP prompt request for this session.
|
|
97
|
+
* @param imageEnabled - connection capability advertised at initialization.
|
|
98
|
+
* @param requestSignal - JSON-RPC request cancellation signal.
|
|
99
|
+
* @returns the correlated standard stop reason after ordered updates drain.
|
|
100
|
+
*/
|
|
101
|
+
prompt(params: PromptRequest, imageEnabled: boolean, requestSignal?: AbortSignal): Promise<PromptResponse>;
|
|
102
|
+
/** Cancel the active prompt, or autonomous work when no ACP prompt exists. */
|
|
103
|
+
cancel(): void;
|
|
104
|
+
/**
|
|
105
|
+
* Process one durable event and enqueue its standard ACP projections.
|
|
106
|
+
* @param session - exact event-owning Session.
|
|
107
|
+
* @param event - committed durable event.
|
|
108
|
+
*/
|
|
109
|
+
onSessionEvent(session: Session, event: SessionEvent): void;
|
|
110
|
+
/**
|
|
111
|
+
* Correlate an accepted user message with its Agent turn and pinned route.
|
|
112
|
+
* @param message - claimed durable inbox message.
|
|
113
|
+
* @param turn - allocated Agent turn.
|
|
114
|
+
*/
|
|
115
|
+
onInboxClaimed(message: UserMessage, turn: number): void;
|
|
116
|
+
/**
|
|
117
|
+
* Correlate an Agent interval failure with the active ACP prompt.
|
|
118
|
+
* @param turn - failed turn number.
|
|
119
|
+
* @param error - original same-process failure.
|
|
120
|
+
*/
|
|
121
|
+
onAgentError(turn: number, error: unknown): void;
|
|
122
|
+
/** Await every update queued before this call. */
|
|
123
|
+
drainUpdates(): Promise<void>;
|
|
124
|
+
/**
|
|
125
|
+
* Cancel, drain, flush, and dispose this session once.
|
|
126
|
+
* @param detail - cancellation detail for any prompt still in admission.
|
|
127
|
+
* @returns the shared quiescent teardown promise.
|
|
128
|
+
*/
|
|
129
|
+
close(detail: string): Promise<void>;
|
|
130
|
+
private assertActive;
|
|
131
|
+
private cancelPrompt;
|
|
132
|
+
private settleAfterQuiescence;
|
|
133
|
+
}
|
|
134
|
+
export {};
|
|
135
|
+
//# sourceMappingURL=session.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../src/session.ts"],"names":[],"mappings":"AAIA,+FAA+F;AAE/F,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAClD,OAAO,EAEL,KAAK,SAAS,EACd,KAAK,aAAa,EAClB,KAAK,cAAc,EACnB,KAAK,mBAAmB,EACxB,KAAK,mBAAmB,EAEzB,MAAM,0BAA0B,CAAA;AACjC,OAAO,KAAK,EAAE,KAAK,EAAe,YAAY,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAA;AAC9F,OAAO,EAAiC,KAAK,WAAW,EAAE,MAAM,sBAAsB,CAAA;AACtF,OAAO,EAAE,KAAK,OAAO,EAAE,KAAK,YAAY,EAAE,KAAK,SAAS,EAAsB,MAAM,0BAA0B,CAAA;AAa9G,uEAAuE;AACvE,MAAM,WAAW,iBAAiB;IAChC,KAAK,CAAC,QAAQ,EAAE,OAAO,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAA;IAC7D,kFAAkF;IAClF,MAAM,CAAC,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CA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