@dsh-cc/acp 0.0.0-stage → 0.9.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/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/LICENSE-harness
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 DeepSeek
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.i18n.yaml
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
# Bilingual-pair consistency record (docs/i18n/README.md): the git blob hash of each
|
|
2
|
+
# side as of the last confirmed-consistent state. Both languages carry equal authority;
|
|
3
|
+
# after editing either side, bring the other along and re-record with:
|
|
4
|
+
# pnpm check:readme --write
|
|
5
|
+
README.md: eb9a693cbafc9b499fa040080e9e73494c13c603
|
|
6
|
+
README.zh.md: e5f412966c7073478896e959cb719e4b0290c759
|
package/README.md
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @dsh-cc/acp
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
English | [中文](README.zh.md)
|
|
4
|
+
|
|
5
|
+
Agent Client Protocol (ACP, v1) server that lets an ACP client (e.g. Zed) drive dsh-cc agents over JSON-RPC on stdio. This package is a verbatim vendor of `@deepseek-ai/dsh-acp` (`packages/acp/acp`, deepseek-harness, MIT — see `LICENSE-harness`), pinned at `c1b47e41fcd54d20a0f061df28683bfc29ee24e5`; every ported file carries a provenance header and CC-specific divergences must be recorded in `DIVERGENCE.md`. The vendoring and extension plan is described in `docs/plans/2026-10-09-acp-m2-own-plugin.md`.
|
package/README.zh.md
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
# @dsh-cc/acp
|
|
2
|
+
|
|
3
|
+
[English](README.md) | 中文
|
|
4
|
+
|
|
5
|
+
Agent Client Protocol(ACP,v1)服务器,让 ACP 客户端(如 Zed)通过 stdio 上的 JSON-RPC 驱动 dsh-cc agent。本包是 `@deepseek-ai/dsh-acp`(deepseek-harness 的 `packages/acp/acp`,MIT — 见 `LICENSE-harness`)的逐字 vendor,固定于 `c1b47e41fcd54d20a0f061df28683bfc29ee24e5`;每个移植文件都带出处头,CC 侧的分歧必须记录在 `DIVERGENCE.md`。vendor 与扩展计划见 `docs/plans/2026-10-09-acp-m2-own-plugin.md`。
|
package/lib/codec.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure translation between the harness lifecycle and the automation-only ACP wire.
|
|
3
|
+
* @module @deepseek-ai/dsh-acp/codec
|
|
4
|
+
*/
|
|
5
|
+
import type { StopReason } from '@agentclientprotocol/sdk';
|
|
6
|
+
import type { TurnEndReason } from '@deepseek-ai/dsh-session';
|
|
7
|
+
/**
|
|
8
|
+
* Map a harness turn ending to ACP's terminal reason vocabulary.
|
|
9
|
+
* @param reason - harness turn outcome.
|
|
10
|
+
* @returns the closest legal ACP stop reason.
|
|
11
|
+
*/
|
|
12
|
+
export declare function turnEndToStopReason(reason: TurnEndReason): StopReason;
|
|
13
|
+
//# sourceMappingURL=codec.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codec.d.ts","sourceRoot":"","sources":["../src/codec.ts"],"names":[],"mappings":"AAIA;;;GAGG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAA;AAC1D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAA;AAE7D;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,aAAa,GAAG,UAAU,CAqBrE"}
|
package/lib/codec.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// Vendored from @deepseek-ai/dsh-acp (packages/acp/acp/src/codec.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
|
+
/**
|
|
6
|
+
* Pure translation between the harness lifecycle and the automation-only ACP wire.
|
|
7
|
+
* @module @deepseek-ai/dsh-acp/codec
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Map a harness turn ending to ACP's terminal reason vocabulary.
|
|
11
|
+
* @param reason - harness turn outcome.
|
|
12
|
+
* @returns the closest legal ACP stop reason.
|
|
13
|
+
*/
|
|
14
|
+
export function turnEndToStopReason(reason) {
|
|
15
|
+
switch (reason.kind) {
|
|
16
|
+
case 'completed':
|
|
17
|
+
return 'end_turn';
|
|
18
|
+
case 'max-tokens':
|
|
19
|
+
return 'max_tokens';
|
|
20
|
+
// `cancelled` is reserved for explicit client cancellation (`session/cancel`)
|
|
21
|
+
// and disposal, both settled out of band; a turn aborted by a hook or
|
|
22
|
+
// another owner is ordinary quiescence and reports `end_turn`.
|
|
23
|
+
case 'aborted':
|
|
24
|
+
return 'end_turn';
|
|
25
|
+
case 'interrupted':
|
|
26
|
+
return 'cancelled';
|
|
27
|
+
case 'blocked':
|
|
28
|
+
case 'error':
|
|
29
|
+
return 'end_turn';
|
|
30
|
+
/* v8 ignore next 2 -- TurnEndReason is merge-extensible; every live-turn member is
|
|
31
|
+
* handled above, and seed-only variants (`forked`) never end an ACP prompt turn. */
|
|
32
|
+
default:
|
|
33
|
+
return 'end_turn';
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=codec.js.map
|
package/lib/codec.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codec.js","sourceRoot":"","sources":["../src/codec.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,qGAAqG;AACrG,wEAAwE;AACxE,yEAAyE;AACzE;;;GAGG;AAKH;;;;GAIG;AACH,MAAM,UAAU,mBAAmB,CAAC,MAAqB;IACvD,QAAQ,MAAM,CAAC,IAAI,EAAE,CAAC;QACpB,KAAK,WAAW;YACd,OAAO,UAAU,CAAA;QACnB,KAAK,YAAY;YACf,OAAO,YAAY,CAAA;QACrB,8EAA8E;QAC9E,sEAAsE;QACtE,+DAA+D;QAC/D,KAAK,SAAS;YACZ,OAAO,UAAU,CAAA;QACnB,KAAK,aAAa;YAChB,OAAO,WAAW,CAAA;QACpB,KAAK,SAAS,CAAC;QACf,KAAK,OAAO;YACV,OAAO,UAAU,CAAA;QACnB;4FACoF;QACpF;YACE,OAAO,UAAU,CAAA;IACrB,CAAC;AACH,CAAC"}
|
package/lib/content.d.ts
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/** ACP wire-content admission and projection owned by the ACP adapter. @module */
|
|
2
|
+
import type { ContentBlock as AcpContentBlock } from '@agentclientprotocol/sdk';
|
|
3
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
4
|
+
import type { ModelSelection } from '@deepseek-ai/dsh-agent';
|
|
5
|
+
import type { ContentBlock } from '@deepseek-ai/dsh-llm';
|
|
6
|
+
/** Content-admission failure category used by the protocol handler. */
|
|
7
|
+
export type AcpContentFailureKind = 'invalid' | 'internal';
|
|
8
|
+
/** Error with a stable ACP request-failure category and no raw binary payload. */
|
|
9
|
+
export declare class AcpContentError extends Error {
|
|
10
|
+
/** Whether the bridge should report invalid params or an internal failure. */
|
|
11
|
+
readonly kind: AcpContentFailureKind;
|
|
12
|
+
/**
|
|
13
|
+
* @param message - safe protocol-facing detail without inline binary data.
|
|
14
|
+
* @param kind - request-failure category.
|
|
15
|
+
* @param options - optional causal chain for diagnostics.
|
|
16
|
+
*/
|
|
17
|
+
constructor(message: string, kind: AcpContentFailureKind, options?: ErrorOptions);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Determine whether initialization may truthfully advertise inline image prompts.
|
|
21
|
+
* Unknown service, route, capability, or deployment media support is negative.
|
|
22
|
+
* @param ctx - bridge context carrying optional attachment and model services.
|
|
23
|
+
* @param provider - configured provider route used for newly created sessions.
|
|
24
|
+
* @param model - configured exact model id used for newly created sessions.
|
|
25
|
+
* @returns whether this bridge can admit images at initialization time.
|
|
26
|
+
*/
|
|
27
|
+
export declare function supportsAcpImagePrompts(ctx: Context, provider: string | undefined, model: string | undefined): Promise<boolean>;
|
|
28
|
+
/**
|
|
29
|
+
* Admit one ACP prompt into ordered durable core content.
|
|
30
|
+
* Every wire block and image is validated before the ordered image batch starts
|
|
31
|
+
* writing; cancellation after a successful content-addressed write may leave an
|
|
32
|
+
* unreachable object but never queues a late user message.
|
|
33
|
+
* @param ctx - bridge context carrying attachment and model services.
|
|
34
|
+
* @param route - selection pinned to the accepted prompt.
|
|
35
|
+
* @param prompt - untrusted ACP prompt blocks in wire order.
|
|
36
|
+
* @param imageEnabled - capability result advertised during initialization.
|
|
37
|
+
* @param signal - admission cancellation signal.
|
|
38
|
+
* @returns core content with durable image references in wire order.
|
|
39
|
+
*/
|
|
40
|
+
export declare function admitAcpPrompt(ctx: Context, route: ModelSelection | undefined, prompt: readonly AcpContentBlock[], imageEnabled: boolean, signal: AbortSignal): Promise<ContentBlock[]>;
|
|
41
|
+
/**
|
|
42
|
+
* Translate one committed assistant block to ACP wire content.
|
|
43
|
+
* Images are re-read and integrity-verified before inline base64 delivery;
|
|
44
|
+
* unsupported core output blocks stay off the automation wire.
|
|
45
|
+
* @param ctx - bridge context carrying the authoritative attachment store.
|
|
46
|
+
* @param block - committed core assistant block.
|
|
47
|
+
* @returns ACP text/image content, or undefined for non-output blocks.
|
|
48
|
+
*/
|
|
49
|
+
export declare function assistantBlockToAcp(ctx: Context, block: ContentBlock): Promise<AcpContentBlock | undefined>;
|
|
50
|
+
//# sourceMappingURL=content.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"content.d.ts","sourceRoot":"","sources":["../src/content.ts"],"names":[],"mappings":"AAIA,kFAAkF;AAElF,OAAO,KAAK,EAAE,YAAY,IAAI,eAAe,EAAE,MAAM,0BAA0B,CAAA;AAC/E,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAGlD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAA;AAC5D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAA;AAaxD,uEAAuE;AACvE,MAAM,MAAM,qBAAqB,GAAG,SAAS,GAAG,UAAU,CAAA;AAE1D,kFAAkF;AAClF,qBAAa,eAAgB,SAAQ,KAAK;IACxC,8EAA8E;IAC9E,QAAQ,CAAC,IAAI,EAAE,qBAAqB,CAAA;IAEpC;;;;OAIG;gBACS,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,qBAAqB,EAAE,OAAO,CAAC,EAAE,YAAY;CAKjF;AA0CD;;;;;;;GAOG;AACH,wBAAsB,uBAAuB,CAC3C,GAAG,EAAE,OAAO,EACZ,QAAQ,EAAE,MAAM,GAAG,SAAS,EAC5B,KAAK,EAAE,MAAM,GAAG,SAAS,GACxB,OAAO,CAAC,OAAO,CAAC,CAWlB;AAOD;;;;;;;;;;;GAWG;AACH,wBAAsB,cAAc,CAClC,GAAG,EAAE,OAAO,EACZ,KAAK,EAAE,cAAc,GAAG,SAAS,EACjC,MAAM,EAAE,SAAS,eAAe,EAAE,EAClC,YAAY,EAAE,OAAO,EACrB,MAAM,EAAE,WAAW,GAClB,OAAO,CAAC,YAAY,EAAE,CAAC,CA2EzB;AAED;;;;;;;GAOG;AACH,wBAAsB,mBAAmB,CACvC,GAAG,EAAE,OAAO,EACZ,KAAK,EAAE,YAAY,GAClB,OAAO,CAAC,eAAe,GAAG,SAAS,CAAC,CAoBtC"}
|
package/lib/content.js
ADDED
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
// Vendored from @deepseek-ai/dsh-acp (packages/acp/acp/src/content.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
|
+
/** ACP wire-content admission and projection owned by the ACP adapter. @module */
|
|
6
|
+
import { isImageAdmissionError } from '@deepseek-ai/dsh-attachment';
|
|
7
|
+
/** Raster formats shared by ACP image blocks and the core attachment vocabulary. */
|
|
8
|
+
const IMAGE_MEDIA_TYPES = [
|
|
9
|
+
'image/png',
|
|
10
|
+
'image/jpeg',
|
|
11
|
+
'image/webp',
|
|
12
|
+
'image/gif',
|
|
13
|
+
];
|
|
14
|
+
/** Canonical RFC 4648 base64, excluding whitespace and URL-safe aliases. */
|
|
15
|
+
const CANONICAL_BASE64 = /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/;
|
|
16
|
+
/** Error with a stable ACP request-failure category and no raw binary payload. */
|
|
17
|
+
export class AcpContentError extends Error {
|
|
18
|
+
/** Whether the bridge should report invalid params or an internal failure. */
|
|
19
|
+
kind;
|
|
20
|
+
/**
|
|
21
|
+
* @param message - safe protocol-facing detail without inline binary data.
|
|
22
|
+
* @param kind - request-failure category.
|
|
23
|
+
* @param options - optional causal chain for diagnostics.
|
|
24
|
+
*/
|
|
25
|
+
constructor(message, kind, options) {
|
|
26
|
+
super(message, options);
|
|
27
|
+
this.name = 'AcpContentError';
|
|
28
|
+
this.kind = kind;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
/** Narrow a wire MIME string to the durable raster vocabulary. */
|
|
32
|
+
function imageMediaType(value) {
|
|
33
|
+
return IMAGE_MEDIA_TYPES.includes(value) ? value : undefined;
|
|
34
|
+
}
|
|
35
|
+
/** Strictly decode one ACP inline image without accepting base64 aliases. */
|
|
36
|
+
function decodeImage(block) {
|
|
37
|
+
const mediaType = imageMediaType(block.mimeType);
|
|
38
|
+
if (mediaType === undefined) {
|
|
39
|
+
throw new AcpContentError('image mimeType must be image/png, image/jpeg, image/webp, or image/gif', 'invalid');
|
|
40
|
+
}
|
|
41
|
+
if (!CANONICAL_BASE64.test(block.data)) {
|
|
42
|
+
throw new AcpContentError('image data must be canonical base64', 'invalid');
|
|
43
|
+
}
|
|
44
|
+
const data = Buffer.from(block.data, 'base64');
|
|
45
|
+
if (data.toString('base64') !== block.data) {
|
|
46
|
+
throw new AcpContentError('image data must be canonical base64', 'invalid');
|
|
47
|
+
}
|
|
48
|
+
return { data, mediaType };
|
|
49
|
+
}
|
|
50
|
+
/** Resolve the exact current route and require explicit image input support. */
|
|
51
|
+
async function assertImageRoute(ctx, route, signal) {
|
|
52
|
+
const provider = route?.provider;
|
|
53
|
+
const model = route?.model;
|
|
54
|
+
const llm = ctx.get('llm');
|
|
55
|
+
if (provider === undefined || model === undefined || llm === undefined) {
|
|
56
|
+
throw new AcpContentError('the current model route could not be resolved for image input', 'invalid');
|
|
57
|
+
}
|
|
58
|
+
let info;
|
|
59
|
+
try {
|
|
60
|
+
info = await llm.resolveModelInfo(provider, model, signal);
|
|
61
|
+
}
|
|
62
|
+
catch (error) {
|
|
63
|
+
throw new AcpContentError('the current model route could not be verified for image input', 'internal', { cause: error });
|
|
64
|
+
}
|
|
65
|
+
if (info.inputModalities === undefined || !info.inputModalities.includes('image')) {
|
|
66
|
+
throw new AcpContentError(`model "${model}" does not declare image input`, 'invalid');
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Determine whether initialization may truthfully advertise inline image prompts.
|
|
71
|
+
* Unknown service, route, capability, or deployment media support is negative.
|
|
72
|
+
* @param ctx - bridge context carrying optional attachment and model services.
|
|
73
|
+
* @param provider - configured provider route used for newly created sessions.
|
|
74
|
+
* @param model - configured exact model id used for newly created sessions.
|
|
75
|
+
* @returns whether this bridge can admit images at initialization time.
|
|
76
|
+
*/
|
|
77
|
+
export async function supportsAcpImagePrompts(ctx, provider, model) {
|
|
78
|
+
const attachments = ctx.get('attachments');
|
|
79
|
+
const llm = ctx.get('llm');
|
|
80
|
+
if (attachments === undefined || llm === undefined || provider === undefined || model === undefined)
|
|
81
|
+
return false;
|
|
82
|
+
if (!attachments.imageLimits.mediaTypes.some(mediaType => IMAGE_MEDIA_TYPES.includes(mediaType)))
|
|
83
|
+
return false;
|
|
84
|
+
try {
|
|
85
|
+
const info = await llm.resolveModelInfo(provider, model);
|
|
86
|
+
return info.inputModalities?.includes('image') === true;
|
|
87
|
+
}
|
|
88
|
+
catch {
|
|
89
|
+
return false;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
/** Render one baseline resource link into the core's current text vocabulary. */
|
|
93
|
+
function resourceLinkText(block) {
|
|
94
|
+
return `\n[resource_link name=${JSON.stringify(block.name)} uri=${JSON.stringify(block.uri)}]\n`;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Admit one ACP prompt into ordered durable core content.
|
|
98
|
+
* Every wire block and image is validated before the ordered image batch starts
|
|
99
|
+
* writing; cancellation after a successful content-addressed write may leave an
|
|
100
|
+
* unreachable object but never queues a late user message.
|
|
101
|
+
* @param ctx - bridge context carrying attachment and model services.
|
|
102
|
+
* @param route - selection pinned to the accepted prompt.
|
|
103
|
+
* @param prompt - untrusted ACP prompt blocks in wire order.
|
|
104
|
+
* @param imageEnabled - capability result advertised during initialization.
|
|
105
|
+
* @param signal - admission cancellation signal.
|
|
106
|
+
* @returns core content with durable image references in wire order.
|
|
107
|
+
*/
|
|
108
|
+
export async function admitAcpPrompt(ctx, route, prompt, imageEnabled, signal) {
|
|
109
|
+
const images = [];
|
|
110
|
+
for (const block of prompt) {
|
|
111
|
+
switch (block.type) {
|
|
112
|
+
case 'text':
|
|
113
|
+
case 'resource_link':
|
|
114
|
+
break;
|
|
115
|
+
case 'image':
|
|
116
|
+
if (!imageEnabled)
|
|
117
|
+
throw new AcpContentError('inline image prompts were not advertised by this connection', 'invalid');
|
|
118
|
+
images.push(decodeImage(block));
|
|
119
|
+
break;
|
|
120
|
+
case 'audio':
|
|
121
|
+
throw new AcpContentError('audio prompt content is not supported', 'invalid');
|
|
122
|
+
case 'resource':
|
|
123
|
+
throw new AcpContentError('embedded resource prompt content is not supported', 'invalid');
|
|
124
|
+
/* v8 ignore next 2 -- ACP ContentBlock is a closed generated union. */
|
|
125
|
+
default:
|
|
126
|
+
throw new AcpContentError('unsupported ACP prompt content', 'invalid');
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
let refs = [];
|
|
130
|
+
if (images.length > 0) {
|
|
131
|
+
const attachments = ctx.get('attachments');
|
|
132
|
+
if (attachments === undefined)
|
|
133
|
+
throw new AcpContentError('no attachment store is mounted', 'invalid');
|
|
134
|
+
await assertImageRoute(ctx, route, signal);
|
|
135
|
+
signal.throwIfAborted();
|
|
136
|
+
try {
|
|
137
|
+
refs = await attachments.saveImages(images);
|
|
138
|
+
}
|
|
139
|
+
catch (error) {
|
|
140
|
+
if (isImageAdmissionError(error)) {
|
|
141
|
+
throw new AcpContentError(error.message, 'invalid', { cause: error });
|
|
142
|
+
}
|
|
143
|
+
throw new AcpContentError('unable to persist the prompt image batch', 'internal', { cause: error });
|
|
144
|
+
}
|
|
145
|
+
signal.throwIfAborted();
|
|
146
|
+
}
|
|
147
|
+
const content = [];
|
|
148
|
+
let pendingText = '';
|
|
149
|
+
let imageIndex = 0;
|
|
150
|
+
const flushText = () => {
|
|
151
|
+
if (pendingText.length === 0)
|
|
152
|
+
return;
|
|
153
|
+
content.push({ type: 'text', text: pendingText });
|
|
154
|
+
pendingText = '';
|
|
155
|
+
};
|
|
156
|
+
for (const block of prompt) {
|
|
157
|
+
switch (block.type) {
|
|
158
|
+
case 'text':
|
|
159
|
+
pendingText += block.text;
|
|
160
|
+
break;
|
|
161
|
+
case 'resource_link':
|
|
162
|
+
pendingText += resourceLinkText(block);
|
|
163
|
+
break;
|
|
164
|
+
case 'image': {
|
|
165
|
+
flushText();
|
|
166
|
+
const ref = refs[imageIndex++];
|
|
167
|
+
content.push({ type: 'image', attachment: ref });
|
|
168
|
+
break;
|
|
169
|
+
}
|
|
170
|
+
/* v8 ignore start -- the validation pass above rejects both tags before reconstruction. */
|
|
171
|
+
case 'audio':
|
|
172
|
+
case 'resource':
|
|
173
|
+
break;
|
|
174
|
+
/* v8 ignore stop */
|
|
175
|
+
/* v8 ignore next 2 -- validated by the first closed-union switch. */
|
|
176
|
+
default:
|
|
177
|
+
break;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
flushText();
|
|
181
|
+
if (!content.some(block => block.type === 'image' || (block.type === 'text' && block.text.trim().length > 0))) {
|
|
182
|
+
throw new AcpContentError('empty prompt', 'invalid');
|
|
183
|
+
}
|
|
184
|
+
return content;
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Translate one committed assistant block to ACP wire content.
|
|
188
|
+
* Images are re-read and integrity-verified before inline base64 delivery;
|
|
189
|
+
* unsupported core output blocks stay off the automation wire.
|
|
190
|
+
* @param ctx - bridge context carrying the authoritative attachment store.
|
|
191
|
+
* @param block - committed core assistant block.
|
|
192
|
+
* @returns ACP text/image content, or undefined for non-output blocks.
|
|
193
|
+
*/
|
|
194
|
+
export async function assistantBlockToAcp(ctx, block) {
|
|
195
|
+
if (block.type === 'text') {
|
|
196
|
+
return block.text.length === 0 ? undefined : { type: 'text', text: block.text };
|
|
197
|
+
}
|
|
198
|
+
if (block.type !== 'image')
|
|
199
|
+
return undefined;
|
|
200
|
+
const attachments = ctx.get('attachments');
|
|
201
|
+
if (attachments === undefined) {
|
|
202
|
+
throw new AcpContentError('cannot deliver assistant image: no attachment store is mounted', 'internal');
|
|
203
|
+
}
|
|
204
|
+
let stored;
|
|
205
|
+
try {
|
|
206
|
+
stored = await attachments.readImage(block.attachment);
|
|
207
|
+
}
|
|
208
|
+
catch (error) {
|
|
209
|
+
throw new AcpContentError('cannot deliver assistant image: the attachment is unavailable or corrupt', 'internal', { cause: error });
|
|
210
|
+
}
|
|
211
|
+
return {
|
|
212
|
+
type: 'image',
|
|
213
|
+
data: Buffer.from(stored.data).toString('base64'),
|
|
214
|
+
mimeType: stored.ref.mediaType,
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
//# sourceMappingURL=content.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"content.js","sourceRoot":"","sources":["../src/content.ts"],"names":[],"mappings":"AAAA,uEAAuE;AACvE,qGAAqG;AACrG,wEAAwE;AACxE,yEAAyE;AACzE,kFAAkF;AAIlF,OAAO,EAAE,qBAAqB,EAAE,MAAM,6BAA6B,CAAA;AAKnE,oFAAoF;AACpF,MAAM,iBAAiB,GAA8B;IACnD,WAAW;IACX,YAAY;IACZ,YAAY;IACZ,WAAW;CACZ,CAAA;AAED,4EAA4E;AAC5E,MAAM,gBAAgB,GAAG,kEAAkE,CAAA;AAK3F,kFAAkF;AAClF,MAAM,OAAO,eAAgB,SAAQ,KAAK;IACxC,8EAA8E;IACrE,IAAI,CAAuB;IAEpC;;;;OAIG;IACH,YAAY,OAAe,EAAE,IAA2B,EAAE,OAAsB;QAC9E,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;QACvB,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAA;QAC7B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;IAClB,CAAC;CACF;AAED,kEAAkE;AAClE,SAAS,cAAc,CAAC,KAAa;IACnC,OAAO,iBAAiB,CAAC,QAAQ,CAAC,KAAuB,CAAC,CAAC,CAAC,CAAC,KAAuB,CAAC,CA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M,WAAW,CAAC,SAAS,CAAC,KAAK,CAAC,UAAU,CAAC,CAAA;IACxD,CAAC;IAAC,OAAO,KAAc,EAAE,CAAC;QACxB,MAAM,IAAI,eAAe,CAAC,0EAA0E,EAAE,UAAU,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAA;IACrI,CAAC;IACD,OAAO;QACL,IAAI,EAAE,OAAO;QACb,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC;QACjD,QAAQ,EAAE,MAAM,CAAC,GAAG,CAAC,SAAS;KAC/B,CAAA;AACH,CAAC"}
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Automation-only Agent Client Protocol server over JSON-RPC stdio.
|
|
3
|
+
*
|
|
4
|
+
* The bridge exposes persistent harness sessions to trusted programmatic
|
|
5
|
+
* clients. It carries standard configuration, MCP mounts, prompt content,
|
|
6
|
+
* committed semantic updates, cancellation, and one-shot permission decisions;
|
|
7
|
+
* presentation and human-interaction features stay with the harness's UI modules.
|
|
8
|
+
*
|
|
9
|
+
* @module @deepseek-ai/dsh-acp
|
|
10
|
+
*/
|
|
11
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
12
|
+
import Schema from '@deepseek-ai/schemastery';
|
|
13
|
+
import { type Stream } from '@agentclientprotocol/sdk';
|
|
14
|
+
export declare const name = "acp-cc";
|
|
15
|
+
/** Core services required by the standard automation controls. */
|
|
16
|
+
export declare const inject: string[];
|
|
17
|
+
/** Plugin config: the provider/model selection used for each ACP-created agent. */
|
|
18
|
+
export interface AcpConfig {
|
|
19
|
+
/** Provider route for created agents. */
|
|
20
|
+
provider?: string;
|
|
21
|
+
/** Model name for created agents. */
|
|
22
|
+
model?: string;
|
|
23
|
+
/** Agent preset composed into every fresh session (§5.2). */
|
|
24
|
+
presetId?: string;
|
|
25
|
+
/** Maximum summaries returned by one session/list page. */
|
|
26
|
+
sessionListPageSize?: number;
|
|
27
|
+
/** Runtime-only transport override; production uses stdio. */
|
|
28
|
+
stream?: Stream;
|
|
29
|
+
}
|
|
30
|
+
export declare const Config: Schema<AcpConfig>;
|
|
31
|
+
/**
|
|
32
|
+
* Mount the automation-only ACP server.
|
|
33
|
+
* @param ctx - Cordis context carrying the agent factory and session events.
|
|
34
|
+
* @param config - Initial provider/model selection and optional test transport.
|
|
35
|
+
*/
|
|
36
|
+
export declare function apply(ctx: Context, config: AcpConfig): void;
|
|
37
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAMlD,OAAO,MAAM,MAAM,0BAA0B,CAAA;AAG7C,OAAO,EAyBL,KAAK,MAAM,EACZ,MAAM,0BAA0B,CAAA;AAkBjC,eAAO,MAAM,IAAI,WAAW,CAAA;AAC5B,kEAAkE;AAMlE,eAAO,MAAM,MAAM,UAAsD,CAAA;AAYzE,mFAAmF;AACnF,MAAM,WAAW,SAAS;IACxB,yCAAyC;IACzC,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,qCAAqC;IACrC,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,6DAA6D;IAC7D,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,2DAA2D;IAC3D,mBAAmB,CAAC,EAAE,MAAM,CAAA;IAC5B,8DAA8D;IAC9D,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB;AAED,eAAO,MAAM,MAAM,EAAE,MAAM,CAAC,SAAS,CAKnC,CAAA;AAEF;;;;GAIG;AACH,wBAAgB,KAAK,CAAC,GAAG,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,GAAG,IAAI,CA6X3D"}
|