@anureo/adapter-acp 0.2.0 → 0.3.0
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/README.md +60 -14
- package/package.json +15 -16
- package/src/adapter.d.ts +214 -0
- package/src/adapter.js +944 -0
- package/src/diagnostics.d.ts +36 -0
- package/src/diagnostics.js +91 -0
- package/src/dsh.d.ts +32 -0
- package/src/dsh.js +31 -0
- package/src/extensions.d.ts +25 -0
- package/src/extensions.js +30 -0
- package/src/file-changes.d.ts +9 -0
- package/src/file-changes.js +29 -0
- package/src/index.d.ts +3 -0
- package/src/index.js +3 -0
- package/src/mapping.d.ts +119 -0
- package/src/mapping.js +504 -0
- package/src/options.d.ts +103 -0
- package/src/options.js +0 -0
- package/src/request-error.d.ts +6 -0
- package/src/request-error.js +22 -0
- package/src/stdio.d.ts +9 -0
- package/src/stdio.js +108 -0
- package/src/stop.d.ts +18 -0
- package/src/stop.js +30 -0
- package/dist/file-changes.d.ts +0 -3
- package/dist/index.d.ts +0 -98
- package/dist/index.js +0 -852
- package/dist/mapping.d.ts +0 -30
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Prepare one stderr line for StderrTail.push. Truncate to 8,192 UTF-16 code units plus an
|
|
3
|
+
* ellipsis when needed, then redact recognized credential patterns.
|
|
4
|
+
*/
|
|
5
|
+
export declare function redactLine(line: string): string;
|
|
6
|
+
/**
|
|
7
|
+
* Buffer decoded stderr for captureStderr. The tail keeps at most 32,768 UTF-16 code units
|
|
8
|
+
* of redacted text, counting each retained line's length plus one for its separator.
|
|
9
|
+
*/
|
|
10
|
+
export declare class StderrTail {
|
|
11
|
+
private readonly maxLines;
|
|
12
|
+
private readonly onLine?;
|
|
13
|
+
/**
|
|
14
|
+
* Set the retained line limit. A nonpositive limit disables capture and the optional synchronous
|
|
15
|
+
* onLine callback. Callback throws are ignored so captureStderr can keep draining.
|
|
16
|
+
*/
|
|
17
|
+
constructor(maxLines: number, onLine?: ((line: string) => void) | undefined);
|
|
18
|
+
/** Redact one line and notify onLine before updating the tail. Evict oldest entries to enforce both bounds. */
|
|
19
|
+
push(line: string): void;
|
|
20
|
+
/**
|
|
21
|
+
* Buffer decoded stderr across chunks and publish each LF-delimited line.
|
|
22
|
+
* Publish an unterminated fragment once it exceeds 8,192 code units to bound retained partial text.
|
|
23
|
+
*/
|
|
24
|
+
write(chunk: string): void;
|
|
25
|
+
/** Publish and clear any buffered fragment. captureStderr calls this when draining ends. */
|
|
26
|
+
flush(): void;
|
|
27
|
+
/** Rendered tail, oldest first. Empty when capture is disabled or nothing arrived. */
|
|
28
|
+
text(): string;
|
|
29
|
+
/** Number of retained lines, excluding a buffered partial line. */
|
|
30
|
+
get size(): number;
|
|
31
|
+
private readonly lines;
|
|
32
|
+
private retainedCodeUnits;
|
|
33
|
+
private partial;
|
|
34
|
+
/** Treat a fragment emitted by write or flush as one entry so both paths use the same redaction and bounds. */
|
|
35
|
+
private publishPartial;
|
|
36
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
// Bounds the stderr tail included in ACP failure diagnostics and filters recognized credentials.
|
|
2
|
+
/**
|
|
3
|
+
* Prepare one stderr line for StderrTail.push. Truncate to 8,192 UTF-16 code units plus an
|
|
4
|
+
* ellipsis when needed, then redact recognized credential patterns.
|
|
5
|
+
*/
|
|
6
|
+
export function redactLine(line) {
|
|
7
|
+
let value = line.length > LINE_CODE_UNIT_LIMIT ? `${line.slice(0, LINE_CODE_UNIT_LIMIT)}…` : line;
|
|
8
|
+
for (const [pattern, replacement] of REDACTIONS)
|
|
9
|
+
value = value.replace(pattern, replacement);
|
|
10
|
+
return value;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Buffer decoded stderr for captureStderr. The tail keeps at most 32,768 UTF-16 code units
|
|
14
|
+
* of redacted text, counting each retained line's length plus one for its separator.
|
|
15
|
+
*/
|
|
16
|
+
export class StderrTail {
|
|
17
|
+
maxLines;
|
|
18
|
+
onLine;
|
|
19
|
+
/**
|
|
20
|
+
* Set the retained line limit. A nonpositive limit disables capture and the optional synchronous
|
|
21
|
+
* onLine callback. Callback throws are ignored so captureStderr can keep draining.
|
|
22
|
+
*/
|
|
23
|
+
constructor(maxLines, onLine) {
|
|
24
|
+
this.maxLines = maxLines;
|
|
25
|
+
this.onLine = onLine;
|
|
26
|
+
}
|
|
27
|
+
/** Redact one line and notify onLine before updating the tail. Evict oldest entries to enforce both bounds. */
|
|
28
|
+
push(line) {
|
|
29
|
+
if (this.maxLines <= 0)
|
|
30
|
+
return;
|
|
31
|
+
const redacted = redactLine(line);
|
|
32
|
+
try {
|
|
33
|
+
this.onLine?.(redacted);
|
|
34
|
+
}
|
|
35
|
+
catch { /* a consumer callback must not break draining */ }
|
|
36
|
+
this.retainedCodeUnits += redacted.length + 1;
|
|
37
|
+
this.lines.push(redacted);
|
|
38
|
+
while (this.lines.length > this.maxLines || this.retainedCodeUnits > TOTAL_CODE_UNIT_LIMIT) {
|
|
39
|
+
const dropped = this.lines.shift();
|
|
40
|
+
if (dropped === undefined)
|
|
41
|
+
break;
|
|
42
|
+
this.retainedCodeUnits -= dropped.length + 1;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Buffer decoded stderr across chunks and publish each LF-delimited line.
|
|
47
|
+
* Publish an unterminated fragment once it exceeds 8,192 code units to bound retained partial text.
|
|
48
|
+
*/
|
|
49
|
+
write(chunk) {
|
|
50
|
+
if (this.maxLines <= 0)
|
|
51
|
+
return;
|
|
52
|
+
this.partial += chunk;
|
|
53
|
+
for (let index = this.partial.indexOf('\n'); index >= 0; index = this.partial.indexOf('\n')) {
|
|
54
|
+
this.push(this.partial.slice(0, index));
|
|
55
|
+
this.partial = this.partial.slice(index + 1);
|
|
56
|
+
}
|
|
57
|
+
// A child that never emits a newline must not grow the buffer without bound.
|
|
58
|
+
if (this.partial.length > LINE_CODE_UNIT_LIMIT)
|
|
59
|
+
this.publishPartial();
|
|
60
|
+
}
|
|
61
|
+
/** Publish and clear any buffered fragment. captureStderr calls this when draining ends. */
|
|
62
|
+
flush() {
|
|
63
|
+
if (!this.partial)
|
|
64
|
+
return;
|
|
65
|
+
this.publishPartial();
|
|
66
|
+
}
|
|
67
|
+
/** Rendered tail, oldest first. Empty when capture is disabled or nothing arrived. */
|
|
68
|
+
text() {
|
|
69
|
+
return this.lines.join('\n');
|
|
70
|
+
}
|
|
71
|
+
/** Number of retained lines, excluding a buffered partial line. */
|
|
72
|
+
get size() {
|
|
73
|
+
return this.lines.length;
|
|
74
|
+
}
|
|
75
|
+
lines = [];
|
|
76
|
+
retainedCodeUnits = 0;
|
|
77
|
+
partial = '';
|
|
78
|
+
/** Treat a fragment emitted by write or flush as one entry so both paths use the same redaction and bounds. */
|
|
79
|
+
publishPartial() {
|
|
80
|
+
this.push(this.partial);
|
|
81
|
+
this.partial = '';
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
const LINE_CODE_UNIT_LIMIT = 8 * 1024;
|
|
85
|
+
const TOTAL_CODE_UNIT_LIMIT = 32 * 1024;
|
|
86
|
+
const REDACTIONS = [
|
|
87
|
+
[/\b(sk-[A-Za-z0-9_-]{8,})/g, 'sk-[redacted]'],
|
|
88
|
+
[/\b(Bearer\s+)[A-Za-z0-9._~+/=-]{8,}/gi, '$1[redacted]'],
|
|
89
|
+
[/\b((?:api[_-]?key|token|secret|password|authorization)\s*[:=]\s*)\S+/gi, '$1[redacted]'],
|
|
90
|
+
[/\b(https?:\/\/)[^\s/@]+:[^\s/@]+@/gi, '$1[redacted]@'],
|
|
91
|
+
];
|
package/src/dsh.d.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { type AcpAdapter } from "./adapter.js";
|
|
2
|
+
import type { AcpAdapterOptions } from "./options.js";
|
|
3
|
+
/** Configure the DSH command and approval policy alongside ACP's host ports and transport options. */
|
|
4
|
+
export interface DshAcpOptions extends Omit<AcpAdapterOptions, 'command' | 'args'> {
|
|
5
|
+
/** `dsh` executable; defaults to `dsh` on PATH. */
|
|
6
|
+
command?: string;
|
|
7
|
+
/** Value passed to `--profile`; defaults to `acp`. */
|
|
8
|
+
profile?: string;
|
|
9
|
+
/**
|
|
10
|
+
* Set the child's DSH home. An explicit env.DSH_HOME entry takes precedence, including undefined.
|
|
11
|
+
* Otherwise the preset uses this value, the host's DSH_HOME, or `~/.dsh`, in that order.
|
|
12
|
+
*/
|
|
13
|
+
dshHome?: string;
|
|
14
|
+
/**
|
|
15
|
+
* Opt into the allow-once policy for unattended hosts, overriding autoRespondPermission.
|
|
16
|
+
* Requests without a matching option still fall back to interactive handling. Defaults to false.
|
|
17
|
+
*/
|
|
18
|
+
autoApprove?: boolean;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Create an ACP adapter for DeepSeek Harness, launching `dsh --profile acp` by default.
|
|
22
|
+
* Pass it to createClient to start the transport and negotiate ACP, then await client disposal
|
|
23
|
+
* when finished. Construction only configures the adapter. A supplied connect factory takes
|
|
24
|
+
* precedence over the command during initialization.
|
|
25
|
+
*
|
|
26
|
+
* DSH needs Node.js >= 24.9 and provider credentials in DSH_HOME. Startup failures during the
|
|
27
|
+
* handshake include the redacted stderr tail when available. The preset sets a 120,000 ms
|
|
28
|
+
* native request wait (excluding session/prompt) when requestTimeoutMs is omitted. Passing it
|
|
29
|
+
* explicitly as undefined uses ACP's 30,000 ms fallback. Stdio retains up to 200 stderr lines by default.
|
|
30
|
+
* Child environment overrides are merged over the host environment and preset DSH_HOME.
|
|
31
|
+
*/
|
|
32
|
+
export declare function createDshAcpAdapter(options?: DshAcpOptions): AcpAdapter;
|
package/src/dsh.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { homedir } from 'node:os';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { createAcpAdapter } from "./adapter.js";
|
|
4
|
+
/**
|
|
5
|
+
* Create an ACP adapter for DeepSeek Harness, launching `dsh --profile acp` by default.
|
|
6
|
+
* Pass it to createClient to start the transport and negotiate ACP, then await client disposal
|
|
7
|
+
* when finished. Construction only configures the adapter. A supplied connect factory takes
|
|
8
|
+
* precedence over the command during initialization.
|
|
9
|
+
*
|
|
10
|
+
* DSH needs Node.js >= 24.9 and provider credentials in DSH_HOME. Startup failures during the
|
|
11
|
+
* handshake include the redacted stderr tail when available. The preset sets a 120,000 ms
|
|
12
|
+
* native request wait (excluding session/prompt) when requestTimeoutMs is omitted. Passing it
|
|
13
|
+
* explicitly as undefined uses ACP's 30,000 ms fallback. Stdio retains up to 200 stderr lines by default.
|
|
14
|
+
* Child environment overrides are merged over the host environment and preset DSH_HOME.
|
|
15
|
+
*/
|
|
16
|
+
export function createDshAcpAdapter(options = {}) {
|
|
17
|
+
const { dshHome, profile = 'acp', autoApprove = false, ...rest } = options;
|
|
18
|
+
return createAcpAdapter({
|
|
19
|
+
stderrTailLines: 200,
|
|
20
|
+
requestTimeoutMs: 120_000,
|
|
21
|
+
...rest,
|
|
22
|
+
command: rest.command ?? 'dsh',
|
|
23
|
+
args: ['--profile', profile],
|
|
24
|
+
env: {
|
|
25
|
+
...process.env,
|
|
26
|
+
DSH_HOME: dshHome ?? process.env.DSH_HOME ?? join(homedir(), '.dsh'),
|
|
27
|
+
...rest.env,
|
|
28
|
+
},
|
|
29
|
+
...(autoApprove ? { autoRespondPermission: 'allow-once' } : {}),
|
|
30
|
+
});
|
|
31
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/** Operations that can be advertised as private ACP methods. */
|
|
2
|
+
export type ExtensionKey = 'fork' | 'revert' | 'steer' | 'history' | 'goalSet' | 'goalClear' | 'compact' | 'review';
|
|
3
|
+
/** Negotiated features shared by AcpAdapter and its backend sessions. */
|
|
4
|
+
export interface Extensions {
|
|
5
|
+
/** Accepted private method names, which the adapter can withdraw after a native rejection. */
|
|
6
|
+
methods: Partial<Record<ExtensionKey, string>>;
|
|
7
|
+
/** Supported fork boundaries when a private fork method is present. */
|
|
8
|
+
fork: Array<'before' | 'through'>;
|
|
9
|
+
/** Supported revert scopes when a private revert method is present. */
|
|
10
|
+
revert: Array<'conversation' | 'files' | 'both'>;
|
|
11
|
+
/** Whether peer updates can describe nested subagent activity. */
|
|
12
|
+
subagents: boolean;
|
|
13
|
+
/** Whether session open can send custom instructions in AHP metadata. */
|
|
14
|
+
instructions: boolean;
|
|
15
|
+
/** Whether the adapter accepts the negotiated _ahp/user_input request. */
|
|
16
|
+
userInput: boolean;
|
|
17
|
+
/** Whether the adapter accepts the negotiated _ahp/dynamic_tool request. */
|
|
18
|
+
dynamicTool: boolean;
|
|
19
|
+
/** Whether v2 turn-correlation notifications and prompt receipts govern execution. */
|
|
20
|
+
nativeLifecycle?: boolean;
|
|
21
|
+
}
|
|
22
|
+
/** Read AHP v1 metadata or v2 metadata with explicit turn correlation. AcpAdapter.configureCapabilities
|
|
23
|
+
* stores the parsed methods and flags and uses them to advertise supported operations.
|
|
24
|
+
* Missing or incompatible metadata yields no capabilities from this extension. */
|
|
25
|
+
export declare function extensions(response: unknown): Extensions;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// Parses optional AHP capabilities advertised in native ACP metadata.
|
|
2
|
+
import { record } from "./mapping.js";
|
|
3
|
+
/** Read AHP v1 metadata or v2 metadata with explicit turn correlation. AcpAdapter.configureCapabilities
|
|
4
|
+
* stores the parsed methods and flags and uses them to advertise supported operations.
|
|
5
|
+
* Missing or incompatible metadata yields no capabilities from this extension. */
|
|
6
|
+
export function extensions(response) {
|
|
7
|
+
const extension = record(record(record(response)._meta).ahp);
|
|
8
|
+
const methods = {};
|
|
9
|
+
const result = { methods, fork: [], revert: [], subagents: false, instructions: false, userInput: false, dynamicTool: false };
|
|
10
|
+
if (extension.version !== 1 && !(extension.version === 2 && extension.turnCorrelation === true))
|
|
11
|
+
return result;
|
|
12
|
+
result.nativeLifecycle = extension.version === 2 && extension.turnCorrelation === true;
|
|
13
|
+
const names = record(extension.methods);
|
|
14
|
+
for (const key of extensionKeys) {
|
|
15
|
+
const name = names[key];
|
|
16
|
+
if (typeof name === 'string' && /^_[a-zA-Z0-9/_.-]+$/.test(name))
|
|
17
|
+
methods[key] = name;
|
|
18
|
+
}
|
|
19
|
+
if (methods.fork && Array.isArray(extension.fork))
|
|
20
|
+
result.fork = extension.fork.filter((value) => value === 'before' || value === 'through');
|
|
21
|
+
if (methods.revert && Array.isArray(extension.revert))
|
|
22
|
+
result.revert = extension.revert.filter((value) => ['conversation', 'files', 'both'].includes(String(value)));
|
|
23
|
+
result.subagents = extension.subagents === true;
|
|
24
|
+
result.instructions = extension.instructions === true;
|
|
25
|
+
const requests = record(extension.clientRequests);
|
|
26
|
+
result.userInput = requests.userInput === '_ahp/user_input';
|
|
27
|
+
result.dynamicTool = requests.dynamicTool === '_ahp/dynamic_tool';
|
|
28
|
+
return result;
|
|
29
|
+
}
|
|
30
|
+
const extensionKeys = ['fork', 'revert', 'steer', 'history', 'goalSet', 'goalClear', 'compact', 'review'];
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { FileChange } from '@anureo/protocol';
|
|
2
|
+
/**
|
|
3
|
+
* Convert valid ACP diff blocks to complete file-text materials without reading or writing files.
|
|
4
|
+
* The mapper includes them in live tool snapshots. AcpBackendSession.extension uses them
|
|
5
|
+
* to fill absent fileChanges in history before validating the page. Retain valid diff blocks
|
|
6
|
+
* in input order and ignore other content, including text that resembles a patch.
|
|
7
|
+
* Missing or null oldText means a new file. Empty strings are valid file contents.
|
|
8
|
+
*/
|
|
9
|
+
export declare function acpFileChanges(content: unknown): FileChange[];
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Convert valid ACP diff blocks to complete file-text materials without reading or writing files.
|
|
3
|
+
* The mapper includes them in live tool snapshots. AcpBackendSession.extension uses them
|
|
4
|
+
* to fill absent fileChanges in history before validating the page. Retain valid diff blocks
|
|
5
|
+
* in input order and ignore other content, including text that resembles a patch.
|
|
6
|
+
* Missing or null oldText means a new file. Empty strings are valid file contents.
|
|
7
|
+
*/
|
|
8
|
+
export function acpFileChanges(content) {
|
|
9
|
+
if (!Array.isArray(content))
|
|
10
|
+
return [];
|
|
11
|
+
return content.flatMap(value => {
|
|
12
|
+
if (!value || typeof value !== 'object')
|
|
13
|
+
return [];
|
|
14
|
+
const part = value;
|
|
15
|
+
if (part.type !== 'diff' || typeof part.path !== 'string')
|
|
16
|
+
return [];
|
|
17
|
+
if (part.oldText !== undefined && part.oldText !== null && typeof part.oldText !== 'string')
|
|
18
|
+
return [];
|
|
19
|
+
if (typeof part.newText !== 'string')
|
|
20
|
+
return [];
|
|
21
|
+
const oldText = part.oldText ?? null;
|
|
22
|
+
return [{
|
|
23
|
+
path: part.path,
|
|
24
|
+
operation: oldText === null ? 'add' : 'modify',
|
|
25
|
+
materials: [{ format: 'text', scope: 'file', oldText, newText: part.newText }],
|
|
26
|
+
completeness: 'complete',
|
|
27
|
+
}];
|
|
28
|
+
});
|
|
29
|
+
}
|
package/src/index.d.ts
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { AcpAdapter, AcpBackendSession, createAcpAdapter } from "./adapter.js";
|
|
2
|
+
export { createDshAcpAdapter, type DshAcpOptions } from "./dsh.js";
|
|
3
|
+
export type { AcpAdapterOptions, AcpChannel, AcpFileSystemPort, AcpPermissionContext, AcpPermissionDecision, AcpPermissionPolicy, AcpTerminalPort, } from "./options.js";
|
package/src/index.js
ADDED
package/src/mapping.d.ts
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import type { Capabilities, ConfigOption, InputBlock, JsonObject, JsonValue, McpServer as SessionMcpServer, SessionState } from '@anureo/protocol';
|
|
2
|
+
import { type SessionEventSink } from '@anureo/sdk';
|
|
3
|
+
import type { ContentBlock, McpServer } from '@agentclientprotocol/sdk';
|
|
4
|
+
/** Read a native object by reference. Arrays, null and primitives become a fresh empty record. */
|
|
5
|
+
export declare function record(value: unknown): Record<string, unknown>;
|
|
6
|
+
/**
|
|
7
|
+
* Make a detached JSON copy and apply publicValue redaction before retaining native payloads.
|
|
8
|
+
* Nullish values become null. JSON serialization and parsing errors propagate synchronously.
|
|
9
|
+
* Callers still own removal of secrets embedded in arbitrary text.
|
|
10
|
+
*/
|
|
11
|
+
export declare function safe(value: unknown): JsonValue;
|
|
12
|
+
/**
|
|
13
|
+
* Flatten native content for message, plan and compaction text. Arrays join block text with
|
|
14
|
+
* newlines, diffs join old and new text with a newline, and unrecognized blocks yield empty text.
|
|
15
|
+
*/
|
|
16
|
+
export declare function text(value: unknown): string;
|
|
17
|
+
/**
|
|
18
|
+
* Translate prompt blocks in order for AcpBackendSession.submitStandardInput and
|
|
19
|
+
* submitCorrelatedInput to send in session/prompt. File links use the URI as the name when
|
|
20
|
+
* omitted. Throws INVALID_PARAMS before dispatch if an image's data or MIME type is empty or missing.
|
|
21
|
+
*/
|
|
22
|
+
export declare function input(blocks: InputBlock[]): ContentBlock[];
|
|
23
|
+
/**
|
|
24
|
+
* Build native MCP server entries in input order for the session request sent by AcpAdapter.openSession.
|
|
25
|
+
* Omitted servers, stdio arguments, HTTP headers and environment variables become empty arrays.
|
|
26
|
+
*/
|
|
27
|
+
export declare function mcp(servers?: SessionMcpServer[]): McpServer[];
|
|
28
|
+
/**
|
|
29
|
+
* Project native booleans, select lists and modes for AcpBackendSession.configure to advertise in
|
|
30
|
+
* capabilities and merge into current state. Missing current values supply no patch.
|
|
31
|
+
* setConfiguration uses keys to address the native option or mode, so the model alias points
|
|
32
|
+
* to its original native descriptor.
|
|
33
|
+
*/
|
|
34
|
+
export declare function configuration(data: Record<string, unknown>): {
|
|
35
|
+
options: ConfigOption[];
|
|
36
|
+
values: JsonObject;
|
|
37
|
+
keys: Map<string, Record<string, unknown>>;
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Project one execution's native updates into ordered item events and session patches.
|
|
41
|
+
* AcpBackendSession keeps a standard mapper and creates a separate mapper for each correlated
|
|
42
|
+
* turn that receives an update. The session controls reset, completion and resource cleanup.
|
|
43
|
+
* Await each update in source order. Sink and callback failures reject after any prior mutations.
|
|
44
|
+
*/
|
|
45
|
+
export declare class AcpUpdateMapper {
|
|
46
|
+
private readonly sink;
|
|
47
|
+
private readonly getTurn;
|
|
48
|
+
private readonly state;
|
|
49
|
+
private readonly setState;
|
|
50
|
+
private readonly subagents;
|
|
51
|
+
/**
|
|
52
|
+
* AcpBackendSession supplies the event sink, a turn ID reader that can return undefined while
|
|
53
|
+
* idle, and callbacks backed by snapshot and configure. The mapper applies state patches
|
|
54
|
+
* synchronously before reading or publishing state. Enable subagents only after negotiation.
|
|
55
|
+
*/
|
|
56
|
+
constructor(sink: SessionEventSink, getTurn: () => string | undefined, state: () => SessionState, setState: (data: Record<string, unknown>) => void, subagents: boolean);
|
|
57
|
+
/**
|
|
58
|
+
* Forget cached items, completions, summaries and generated plan IDs without publishing.
|
|
59
|
+
* AcpBackendSession.beginStandardSubmission calls this before reusing the standard mapper.
|
|
60
|
+
*/
|
|
61
|
+
reset(): void;
|
|
62
|
+
/**
|
|
63
|
+
* Flush unended cached items in insertion order, promoting running status to completed.
|
|
64
|
+
* AcpBackendSession.submitStandardInput and nativeEvent await this before publishing
|
|
65
|
+
* turn/completed. Publication failures reject and leave prior mutations and events in place.
|
|
66
|
+
* With no current turn, no items are published.
|
|
67
|
+
*/
|
|
68
|
+
complete(): Promise<void>;
|
|
69
|
+
/**
|
|
70
|
+
* Await projection/publication of one native update forwarded by AcpBackendSession.update.
|
|
71
|
+
* Configuration, metadata and usage can be published while idle. Other idle updates and unmapped
|
|
72
|
+
* turn updates produce notices. A failed publication leaves state and cache mutations in place.
|
|
73
|
+
* AcpAdapter's notification routing observes rejection and ends the stream.
|
|
74
|
+
*/
|
|
75
|
+
update(update: Record<string, unknown>): Promise<void>;
|
|
76
|
+
private readonly items;
|
|
77
|
+
private readonly ended;
|
|
78
|
+
private serial;
|
|
79
|
+
private readonly compaction;
|
|
80
|
+
/**
|
|
81
|
+
* Cache a turn's item before publishing it. An unseen ID starts even in completion mode.
|
|
82
|
+
* Later snapshots emit full patches until the ID is marked ended. Mark it ended before
|
|
83
|
+
* awaiting completion publication so subsequent writes stay silent even if the sink rejects.
|
|
84
|
+
* With no current turn, discard the snapshot without touching the cache.
|
|
85
|
+
*/
|
|
86
|
+
private upsert;
|
|
87
|
+
/**
|
|
88
|
+
* Apply a changed title before publishing session/metadata, including while idle.
|
|
89
|
+
* Omitted, invalid and unchanged titles leave state and publication alone. Null clears the title.
|
|
90
|
+
*/
|
|
91
|
+
private updateMetadata;
|
|
92
|
+
/**
|
|
93
|
+
* Accumulate message chunks by kind and message ID, falling back to one item per kind.
|
|
94
|
+
* Publish a start before the first delta. User items emit full patches and agent/reasoning
|
|
95
|
+
* items emit text deltas. Unsupported content is retained in notices. complete flushes the items.
|
|
96
|
+
*/
|
|
97
|
+
private updateMessage;
|
|
98
|
+
/** Publish the merged tool snapshot, closing the item when its mapped status is terminal. */
|
|
99
|
+
private updateToolCall;
|
|
100
|
+
/**
|
|
101
|
+
* Publish standard steps under one stable ID and extension plans under their supplied or
|
|
102
|
+
* generated IDs. Extension removal publishes an empty terminal plan.
|
|
103
|
+
*/
|
|
104
|
+
private updatePlan;
|
|
105
|
+
/** Accumulate summary chunks, replace explicit summaries, and close only on native terminal status. */
|
|
106
|
+
private updateCompaction;
|
|
107
|
+
/** Merge negotiated subagent fields and publish a terminal snapshot when its native state ends. */
|
|
108
|
+
private updateSubagent;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Resolve a host value against the agent's advertised session configuration.
|
|
112
|
+
* AcpAdapter.openSession passes the model override here before calling setConfiguration.
|
|
113
|
+
* Returns the requested value when no nonempty string enum constrains it, otherwise accepts
|
|
114
|
+
* an exact match or a unique provider-qualified suffix. Throws CAPABILITY_UNSUPPORTED for
|
|
115
|
+
* a missing session option and INVALID_PARAMS for an unknown or ambiguous enum value.
|
|
116
|
+
*
|
|
117
|
+
* This lets hosts use a bare model name when a peer advertises `provider/model`.
|
|
118
|
+
*/
|
|
119
|
+
export declare function resolveConfigValue(capabilities: Capabilities, key: string, wanted: string): string;
|