@agentskit/adapters 0.16.0 → 0.17.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 +129 -2
- package/dist/cli/index.cjs +220 -59
- package/dist/cli/index.cjs.map +1 -1
- package/dist/cli/index.d.cts +146 -11
- package/dist/cli/index.d.ts +146 -11
- package/dist/cli/index.js +214 -59
- package/dist/cli/index.js.map +1 -1
- package/dist/langchain-bridge.cjs +232 -0
- package/dist/langchain-bridge.cjs.map +1 -0
- package/dist/langchain-bridge.d.cts +77 -0
- package/dist/langchain-bridge.d.ts +77 -0
- package/dist/langchain-bridge.js +229 -0
- package/dist/langchain-bridge.js.map +1 -0
- package/package.json +18 -6
package/dist/cli/index.d.cts
CHANGED
|
@@ -1,7 +1,109 @@
|
|
|
1
|
-
import { AdapterRequest, AdapterCapabilities,
|
|
1
|
+
import { StreamChunk, AdapterRequest, AdapterCapabilities, TokenUsage, AdapterFactory } from '@agentskit/core';
|
|
2
|
+
|
|
3
|
+
declare function parseCliJsonResponse(value: unknown): readonly StreamChunk[];
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Serializes an `AdapterRequest` as clearly labelled prompt blocks for
|
|
7
|
+
* agentic CLIs (Claude Code, Codex, ...) that read a natural-language prompt
|
|
8
|
+
* from stdin.
|
|
9
|
+
*
|
|
10
|
+
* The generic `createCliAdapter` default writes the raw `AdapterRequest` JSON
|
|
11
|
+
* to stdin, which is the right contract for a purpose-built CLI but is
|
|
12
|
+
* hostile to agentic CLIs: Claude Code, for example, treats a raw JSON blob
|
|
13
|
+
* containing `systemPrompt` as a prompt-injection attempt and refuses it.
|
|
14
|
+
* First-party manifests for those CLIs use this serializer instead; the
|
|
15
|
+
* Claude Code manifests go further and pass system instructions through
|
|
16
|
+
* `--append-system-prompt` (`claudeCodeRequestArgs`) with `serializeCliMessages`
|
|
17
|
+
* on stdin, because Claude Code also flags labelled `[system]`/`[tools]`
|
|
18
|
+
* blocks inside the user prompt.
|
|
19
|
+
*
|
|
20
|
+
* Output shape:
|
|
21
|
+
*
|
|
22
|
+
* ```text
|
|
23
|
+
* [system]
|
|
24
|
+
* ...system prompt...
|
|
25
|
+
*
|
|
26
|
+
* [tools]
|
|
27
|
+
* ...JSON list of tool definitions + response contract...
|
|
28
|
+
*
|
|
29
|
+
* [user]
|
|
30
|
+
* ...
|
|
31
|
+
*
|
|
32
|
+
* [assistant]
|
|
33
|
+
* ...
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
declare function serializeCliPrompt(request: AdapterRequest, options?: SerializeCliPromptOptions): string;
|
|
37
|
+
interface SerializeCliPromptOptions {
|
|
38
|
+
/** Include the `[system]` block and `system` messages. Default `true`. */
|
|
39
|
+
system?: boolean;
|
|
40
|
+
/** Include the `[tools]` block. Default `true`. */
|
|
41
|
+
tools?: boolean;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Conversation-only serializer for CLIs that take the system prompt through
|
|
45
|
+
* argv (see `buildCliSystemPrompt`). A single user message is written bare;
|
|
46
|
+
* multi-turn conversations use `[user]`/`[assistant]`/`[tool]` blocks.
|
|
47
|
+
*/
|
|
48
|
+
declare function serializeCliMessages(request: AdapterRequest): string;
|
|
49
|
+
/**
|
|
50
|
+
* System instructions for a request: the system prompt plus, when tools are
|
|
51
|
+
* present, the tool list and the JSON tool-call contract. Returns `undefined`
|
|
52
|
+
* when the request carries neither. Intended for CLIs with a system-prompt
|
|
53
|
+
* flag; Claude Code treats the same text inside the user prompt as an
|
|
54
|
+
* injection attempt.
|
|
55
|
+
*/
|
|
56
|
+
declare function buildCliSystemPrompt(request: AdapterRequest): string | undefined;
|
|
57
|
+
/** Extra `claude -p` argv: `--append-system-prompt` when the request has system instructions or tools. */
|
|
58
|
+
declare function claudeCodeRequestArgs(request: AdapterRequest): readonly string[];
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Maps one `claude -p --output-format json` envelope to normalized stream
|
|
62
|
+
* chunks. Used by the `claude-code-json` manifest with `createJsonCliAdapter`.
|
|
63
|
+
*
|
|
64
|
+
* - `result` becomes a `text` chunk. When the result is itself a JSON object
|
|
65
|
+
* following the `CliJsonResponse` shape (`text`, `reasoning`, `toolCalls`),
|
|
66
|
+
* for instance because the prompt carried a `[tools]` block, it is parsed
|
|
67
|
+
* with `parseCliJsonResponse` so tool calls surface as `tool_call` chunks.
|
|
68
|
+
* - `structured_output` (from `--json-schema`) is preferred over `result`
|
|
69
|
+
* when it follows the same shape; otherwise it is emitted as JSON text.
|
|
70
|
+
* - `usage.input_tokens` (+ cache tokens) and `usage.output_tokens` become a
|
|
71
|
+
* `usage` chunk; `session_id`, `total_cost_usd`, `duration_ms`, and
|
|
72
|
+
* `num_turns` are attached as metadata on the last chunk.
|
|
73
|
+
* - `is_error: true` or a non-`success` subtype fails closed.
|
|
74
|
+
*/
|
|
75
|
+
declare function parseClaudeCodeJsonResponse(value: unknown): readonly StreamChunk[];
|
|
76
|
+
/**
|
|
77
|
+
* Decodes Claude Code stdout before `parseClaudeCodeJsonResponse`. Claude
|
|
78
|
+
* Code prints a single JSON object, but a leading warning line or trailing
|
|
79
|
+
* whitespace is tolerated by taking the last complete JSON object.
|
|
80
|
+
*/
|
|
81
|
+
declare function parseClaudeCodeJsonOutput(stdout: string): unknown;
|
|
2
82
|
|
|
3
83
|
type CliSecurityMode = 'review-safe' | 'trusted-local' | 'restricted-environment';
|
|
84
|
+
/**
|
|
85
|
+
* Transport protocol of a CLI manifest. The protocol bounds what the adapter
|
|
86
|
+
* can return:
|
|
87
|
+
*
|
|
88
|
+
* | Protocol | Emits | Never emits |
|
|
89
|
+
* | ----------- | ---------------------------------------------- | -------------------------------------------- |
|
|
90
|
+
* | `exec-text` | streamed `text` | `tool_call`, `reasoning`, structured output, usage |
|
|
91
|
+
* | `exec-json` | one parsed `text`/`reasoning`/`tool_call`/`usage` | streaming |
|
|
92
|
+
* | `acp` | streamed `text`/`reasoning` | tool calls (rejected), MCP, plugins, terminal |
|
|
93
|
+
*
|
|
94
|
+
* `CliCapabilitiesFor<P>` encodes the same table at the type level so that a
|
|
95
|
+
* manifest, or a `requiredCapabilities` request against it, cannot claim a
|
|
96
|
+
* capability its protocol cannot deliver.
|
|
97
|
+
*/
|
|
4
98
|
type CliProtocol = 'exec-text' | 'exec-json' | 'acp';
|
|
99
|
+
/** Capability keys each protocol can legitimately declare or be asked for. */
|
|
100
|
+
interface CliProtocolCapabilityKeys {
|
|
101
|
+
'exec-text': 'streaming' | 'nativeAuth';
|
|
102
|
+
'exec-json': 'structuredOutput' | 'reasoning' | 'nativeAuth';
|
|
103
|
+
acp: 'streaming' | 'structuredOutput' | 'reasoning' | 'nativeAuth';
|
|
104
|
+
}
|
|
105
|
+
/** The subset of `CliCapabilityRequirements` that protocol `P` supports. */
|
|
106
|
+
type CliCapabilitiesFor<P extends CliProtocol> = Pick<CliCapabilityRequirements, CliProtocolCapabilityKeys[P]>;
|
|
5
107
|
type CliTerminationReason = 'aborted' | 'timeout' | 'output-limit';
|
|
6
108
|
interface CliCapabilityRequirements {
|
|
7
109
|
streaming?: boolean;
|
|
@@ -93,21 +195,53 @@ interface AcpCliAdapterOptions extends CliProcessOptions {
|
|
|
93
195
|
toPrompt?: (request: AdapterRequest) => string;
|
|
94
196
|
}
|
|
95
197
|
|
|
96
|
-
|
|
198
|
+
/**
|
|
199
|
+
* A CLI provider manifest for protocol `P`. `capabilities` is restricted to
|
|
200
|
+
* `CliCapabilitiesFor<P>`, so an `exec-text` manifest cannot declare
|
|
201
|
+
* `structuredOutput` and a consumer cannot request `tools` from it: both are
|
|
202
|
+
* compile-time errors, mirroring the runtime `validateCliProviderManifest`.
|
|
203
|
+
*/
|
|
204
|
+
interface CliProviderManifestFor<P extends CliProtocol = CliProtocol> {
|
|
97
205
|
id: string;
|
|
98
206
|
name: string;
|
|
99
207
|
command: string;
|
|
100
208
|
args: readonly string[];
|
|
101
209
|
diagnosticArgs: readonly string[];
|
|
102
|
-
protocol:
|
|
210
|
+
protocol: P;
|
|
103
211
|
protocolVersion?: 1;
|
|
104
|
-
capabilities:
|
|
212
|
+
capabilities: CliCapabilitiesFor<P>;
|
|
105
213
|
supportedModes: readonly CliSecurityMode[];
|
|
106
214
|
credentialEnv?: readonly string[];
|
|
107
215
|
docsUrl?: string;
|
|
108
216
|
versionPattern?: string;
|
|
217
|
+
/**
|
|
218
|
+
* Serializes the request written to the CLI's stdin. Agentic CLIs that read
|
|
219
|
+
* a natural-language prompt use `serializeCliPrompt`; omit it to write the
|
|
220
|
+
* raw `AdapterRequest` JSON.
|
|
221
|
+
*/
|
|
222
|
+
serializeRequest?: CliAdapterOptions['serializeRequest'];
|
|
223
|
+
/**
|
|
224
|
+
* Extra per-request argv appended after `args` and `CliManifestOptions.args`,
|
|
225
|
+
* e.g. `--append-system-prompt` for Claude Code. Still spawned without a shell.
|
|
226
|
+
*/
|
|
227
|
+
requestArgs?: (request: AdapterRequest) => readonly string[];
|
|
228
|
+
/** `exec-json` only: decodes raw stdout before `parse`. */
|
|
229
|
+
parseOutput?: CliJsonAdapterOptions['parseOutput'];
|
|
230
|
+
/** `exec-json` only: maps the decoded JSON value to stream chunks. */
|
|
231
|
+
parse?: CliJsonAdapterOptions['parse'];
|
|
109
232
|
}
|
|
110
|
-
|
|
233
|
+
/** Discriminated by `protocol`; see `CliProviderManifestFor`. */
|
|
234
|
+
type CliProviderManifest = CliProviderManifestFor<'exec-text'> | CliProviderManifestFor<'exec-json'> | CliProviderManifestFor<'acp'>;
|
|
235
|
+
/** Protocol of each built-in manifest id, used to type `getCliProviderManifest`. */
|
|
236
|
+
interface BuiltInCliManifestProtocols {
|
|
237
|
+
codex: 'exec-text';
|
|
238
|
+
'claude-code': 'exec-text';
|
|
239
|
+
'claude-code-json': 'exec-json';
|
|
240
|
+
grok: 'acp';
|
|
241
|
+
opencode: 'acp';
|
|
242
|
+
}
|
|
243
|
+
type BuiltInCliManifestId = keyof BuiltInCliManifestProtocols;
|
|
244
|
+
interface CliManifestOptions<P extends CliProtocol = CliProtocol> {
|
|
111
245
|
args?: readonly string[];
|
|
112
246
|
mode?: CliSecurityMode;
|
|
113
247
|
cwd?: string;
|
|
@@ -116,22 +250,23 @@ interface CliManifestOptions {
|
|
|
116
250
|
maxOutputBytes?: number;
|
|
117
251
|
killGraceMs?: number;
|
|
118
252
|
onDiagnostic?: CliProcessOptions['onDiagnostic'];
|
|
119
|
-
|
|
253
|
+
/** Only capabilities the manifest's protocol can deliver are accepted. */
|
|
254
|
+
requiredCapabilities?: CliCapabilitiesFor<P>;
|
|
120
255
|
}
|
|
121
256
|
declare function validateCliProviderManifest(manifest: unknown): asserts manifest is CliProviderManifest;
|
|
122
257
|
declare function listCliProviderManifests(): CliProviderManifest[];
|
|
123
|
-
|
|
124
|
-
declare function
|
|
125
|
-
declare function
|
|
258
|
+
/** Built-in ids resolve to their protocol-specific manifest type; unknown ids to the union. */
|
|
259
|
+
declare function getCliProviderManifest<Id extends string>(id: Id): (Id extends BuiltInCliManifestId ? CliProviderManifestFor<BuiltInCliManifestProtocols[Id]> : CliProviderManifest) | undefined;
|
|
260
|
+
declare function resolveCliManifest<M extends CliProviderManifest>(manifest: M, options?: CliManifestOptions<M['protocol']>): CliJsonAdapterOptions;
|
|
261
|
+
declare function diagnoseCliProviderManifest<M extends CliProviderManifest>(manifest: M, options?: Omit<CliManifestOptions<M['protocol']>, 'args'>): Promise<CliDiagnostic>;
|
|
126
262
|
declare function manifestCapabilities(manifest: CliProviderManifest): AdapterCapabilities;
|
|
127
263
|
|
|
128
264
|
declare function diagnoseCliProvider(options: CliProcessOptions & {
|
|
129
265
|
diagnosticArgs?: readonly string[];
|
|
130
266
|
}): Promise<CliDiagnostic>;
|
|
131
267
|
|
|
132
|
-
declare function standardJsonParser(value: unknown): readonly StreamChunk[];
|
|
133
268
|
declare function createCliAdapter(options: CliAdapterOptions): AdapterFactory;
|
|
134
269
|
declare function createJsonCliAdapter(options: CliJsonAdapterOptions): AdapterFactory;
|
|
135
270
|
declare function createAcpCliAdapter(options: AcpCliAdapterOptions): AdapterFactory;
|
|
136
271
|
|
|
137
|
-
export { type AcpCliAdapterOptions, type AcpClientInfo, type CliAdapterOptions, type CliCapabilityRequirements, type CliDiagnostic, type CliJsonAdapterOptions, type CliJsonParser, type CliJsonResponse, type CliManifestOptions, type CliProcessOptions, type CliProtocol, type CliProviderManifest, type CliSecurityMode, type CliTerminationReason, type CliToolCall, createAcpCliAdapter, createCliAdapter, createJsonCliAdapter, diagnoseCliProvider, diagnoseCliProviderManifest, getCliProviderManifest, listCliProviderManifests, manifestCapabilities,
|
|
272
|
+
export { type AcpCliAdapterOptions, type AcpClientInfo, type BuiltInCliManifestId, type BuiltInCliManifestProtocols, type CliAdapterOptions, type CliCapabilitiesFor, type CliCapabilityRequirements, type CliDiagnostic, type CliJsonAdapterOptions, type CliJsonParser, type CliJsonResponse, type CliManifestOptions, type CliProcessOptions, type CliProtocol, type CliProtocolCapabilityKeys, type CliProviderManifest, type CliProviderManifestFor, type CliSecurityMode, type CliTerminationReason, type CliToolCall, type SerializeCliPromptOptions, buildCliSystemPrompt, claudeCodeRequestArgs, createAcpCliAdapter, createCliAdapter, createJsonCliAdapter, diagnoseCliProvider, diagnoseCliProviderManifest, getCliProviderManifest, listCliProviderManifests, manifestCapabilities, parseClaudeCodeJsonOutput, parseClaudeCodeJsonResponse, parseCliJsonResponse, resolveCliManifest, serializeCliMessages, serializeCliPrompt, validateCliProviderManifest };
|
package/dist/cli/index.d.ts
CHANGED
|
@@ -1,7 +1,109 @@
|
|
|
1
|
-
import { AdapterRequest, AdapterCapabilities,
|
|
1
|
+
import { StreamChunk, AdapterRequest, AdapterCapabilities, TokenUsage, AdapterFactory } from '@agentskit/core';
|
|
2
|
+
|
|
3
|
+
declare function parseCliJsonResponse(value: unknown): readonly StreamChunk[];
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Serializes an `AdapterRequest` as clearly labelled prompt blocks for
|
|
7
|
+
* agentic CLIs (Claude Code, Codex, ...) that read a natural-language prompt
|
|
8
|
+
* from stdin.
|
|
9
|
+
*
|
|
10
|
+
* The generic `createCliAdapter` default writes the raw `AdapterRequest` JSON
|
|
11
|
+
* to stdin, which is the right contract for a purpose-built CLI but is
|
|
12
|
+
* hostile to agentic CLIs: Claude Code, for example, treats a raw JSON blob
|
|
13
|
+
* containing `systemPrompt` as a prompt-injection attempt and refuses it.
|
|
14
|
+
* First-party manifests for those CLIs use this serializer instead; the
|
|
15
|
+
* Claude Code manifests go further and pass system instructions through
|
|
16
|
+
* `--append-system-prompt` (`claudeCodeRequestArgs`) with `serializeCliMessages`
|
|
17
|
+
* on stdin, because Claude Code also flags labelled `[system]`/`[tools]`
|
|
18
|
+
* blocks inside the user prompt.
|
|
19
|
+
*
|
|
20
|
+
* Output shape:
|
|
21
|
+
*
|
|
22
|
+
* ```text
|
|
23
|
+
* [system]
|
|
24
|
+
* ...system prompt...
|
|
25
|
+
*
|
|
26
|
+
* [tools]
|
|
27
|
+
* ...JSON list of tool definitions + response contract...
|
|
28
|
+
*
|
|
29
|
+
* [user]
|
|
30
|
+
* ...
|
|
31
|
+
*
|
|
32
|
+
* [assistant]
|
|
33
|
+
* ...
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
declare function serializeCliPrompt(request: AdapterRequest, options?: SerializeCliPromptOptions): string;
|
|
37
|
+
interface SerializeCliPromptOptions {
|
|
38
|
+
/** Include the `[system]` block and `system` messages. Default `true`. */
|
|
39
|
+
system?: boolean;
|
|
40
|
+
/** Include the `[tools]` block. Default `true`. */
|
|
41
|
+
tools?: boolean;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Conversation-only serializer for CLIs that take the system prompt through
|
|
45
|
+
* argv (see `buildCliSystemPrompt`). A single user message is written bare;
|
|
46
|
+
* multi-turn conversations use `[user]`/`[assistant]`/`[tool]` blocks.
|
|
47
|
+
*/
|
|
48
|
+
declare function serializeCliMessages(request: AdapterRequest): string;
|
|
49
|
+
/**
|
|
50
|
+
* System instructions for a request: the system prompt plus, when tools are
|
|
51
|
+
* present, the tool list and the JSON tool-call contract. Returns `undefined`
|
|
52
|
+
* when the request carries neither. Intended for CLIs with a system-prompt
|
|
53
|
+
* flag; Claude Code treats the same text inside the user prompt as an
|
|
54
|
+
* injection attempt.
|
|
55
|
+
*/
|
|
56
|
+
declare function buildCliSystemPrompt(request: AdapterRequest): string | undefined;
|
|
57
|
+
/** Extra `claude -p` argv: `--append-system-prompt` when the request has system instructions or tools. */
|
|
58
|
+
declare function claudeCodeRequestArgs(request: AdapterRequest): readonly string[];
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Maps one `claude -p --output-format json` envelope to normalized stream
|
|
62
|
+
* chunks. Used by the `claude-code-json` manifest with `createJsonCliAdapter`.
|
|
63
|
+
*
|
|
64
|
+
* - `result` becomes a `text` chunk. When the result is itself a JSON object
|
|
65
|
+
* following the `CliJsonResponse` shape (`text`, `reasoning`, `toolCalls`),
|
|
66
|
+
* for instance because the prompt carried a `[tools]` block, it is parsed
|
|
67
|
+
* with `parseCliJsonResponse` so tool calls surface as `tool_call` chunks.
|
|
68
|
+
* - `structured_output` (from `--json-schema`) is preferred over `result`
|
|
69
|
+
* when it follows the same shape; otherwise it is emitted as JSON text.
|
|
70
|
+
* - `usage.input_tokens` (+ cache tokens) and `usage.output_tokens` become a
|
|
71
|
+
* `usage` chunk; `session_id`, `total_cost_usd`, `duration_ms`, and
|
|
72
|
+
* `num_turns` are attached as metadata on the last chunk.
|
|
73
|
+
* - `is_error: true` or a non-`success` subtype fails closed.
|
|
74
|
+
*/
|
|
75
|
+
declare function parseClaudeCodeJsonResponse(value: unknown): readonly StreamChunk[];
|
|
76
|
+
/**
|
|
77
|
+
* Decodes Claude Code stdout before `parseClaudeCodeJsonResponse`. Claude
|
|
78
|
+
* Code prints a single JSON object, but a leading warning line or trailing
|
|
79
|
+
* whitespace is tolerated by taking the last complete JSON object.
|
|
80
|
+
*/
|
|
81
|
+
declare function parseClaudeCodeJsonOutput(stdout: string): unknown;
|
|
2
82
|
|
|
3
83
|
type CliSecurityMode = 'review-safe' | 'trusted-local' | 'restricted-environment';
|
|
84
|
+
/**
|
|
85
|
+
* Transport protocol of a CLI manifest. The protocol bounds what the adapter
|
|
86
|
+
* can return:
|
|
87
|
+
*
|
|
88
|
+
* | Protocol | Emits | Never emits |
|
|
89
|
+
* | ----------- | ---------------------------------------------- | -------------------------------------------- |
|
|
90
|
+
* | `exec-text` | streamed `text` | `tool_call`, `reasoning`, structured output, usage |
|
|
91
|
+
* | `exec-json` | one parsed `text`/`reasoning`/`tool_call`/`usage` | streaming |
|
|
92
|
+
* | `acp` | streamed `text`/`reasoning` | tool calls (rejected), MCP, plugins, terminal |
|
|
93
|
+
*
|
|
94
|
+
* `CliCapabilitiesFor<P>` encodes the same table at the type level so that a
|
|
95
|
+
* manifest, or a `requiredCapabilities` request against it, cannot claim a
|
|
96
|
+
* capability its protocol cannot deliver.
|
|
97
|
+
*/
|
|
4
98
|
type CliProtocol = 'exec-text' | 'exec-json' | 'acp';
|
|
99
|
+
/** Capability keys each protocol can legitimately declare or be asked for. */
|
|
100
|
+
interface CliProtocolCapabilityKeys {
|
|
101
|
+
'exec-text': 'streaming' | 'nativeAuth';
|
|
102
|
+
'exec-json': 'structuredOutput' | 'reasoning' | 'nativeAuth';
|
|
103
|
+
acp: 'streaming' | 'structuredOutput' | 'reasoning' | 'nativeAuth';
|
|
104
|
+
}
|
|
105
|
+
/** The subset of `CliCapabilityRequirements` that protocol `P` supports. */
|
|
106
|
+
type CliCapabilitiesFor<P extends CliProtocol> = Pick<CliCapabilityRequirements, CliProtocolCapabilityKeys[P]>;
|
|
5
107
|
type CliTerminationReason = 'aborted' | 'timeout' | 'output-limit';
|
|
6
108
|
interface CliCapabilityRequirements {
|
|
7
109
|
streaming?: boolean;
|
|
@@ -93,21 +195,53 @@ interface AcpCliAdapterOptions extends CliProcessOptions {
|
|
|
93
195
|
toPrompt?: (request: AdapterRequest) => string;
|
|
94
196
|
}
|
|
95
197
|
|
|
96
|
-
|
|
198
|
+
/**
|
|
199
|
+
* A CLI provider manifest for protocol `P`. `capabilities` is restricted to
|
|
200
|
+
* `CliCapabilitiesFor<P>`, so an `exec-text` manifest cannot declare
|
|
201
|
+
* `structuredOutput` and a consumer cannot request `tools` from it: both are
|
|
202
|
+
* compile-time errors, mirroring the runtime `validateCliProviderManifest`.
|
|
203
|
+
*/
|
|
204
|
+
interface CliProviderManifestFor<P extends CliProtocol = CliProtocol> {
|
|
97
205
|
id: string;
|
|
98
206
|
name: string;
|
|
99
207
|
command: string;
|
|
100
208
|
args: readonly string[];
|
|
101
209
|
diagnosticArgs: readonly string[];
|
|
102
|
-
protocol:
|
|
210
|
+
protocol: P;
|
|
103
211
|
protocolVersion?: 1;
|
|
104
|
-
capabilities:
|
|
212
|
+
capabilities: CliCapabilitiesFor<P>;
|
|
105
213
|
supportedModes: readonly CliSecurityMode[];
|
|
106
214
|
credentialEnv?: readonly string[];
|
|
107
215
|
docsUrl?: string;
|
|
108
216
|
versionPattern?: string;
|
|
217
|
+
/**
|
|
218
|
+
* Serializes the request written to the CLI's stdin. Agentic CLIs that read
|
|
219
|
+
* a natural-language prompt use `serializeCliPrompt`; omit it to write the
|
|
220
|
+
* raw `AdapterRequest` JSON.
|
|
221
|
+
*/
|
|
222
|
+
serializeRequest?: CliAdapterOptions['serializeRequest'];
|
|
223
|
+
/**
|
|
224
|
+
* Extra per-request argv appended after `args` and `CliManifestOptions.args`,
|
|
225
|
+
* e.g. `--append-system-prompt` for Claude Code. Still spawned without a shell.
|
|
226
|
+
*/
|
|
227
|
+
requestArgs?: (request: AdapterRequest) => readonly string[];
|
|
228
|
+
/** `exec-json` only: decodes raw stdout before `parse`. */
|
|
229
|
+
parseOutput?: CliJsonAdapterOptions['parseOutput'];
|
|
230
|
+
/** `exec-json` only: maps the decoded JSON value to stream chunks. */
|
|
231
|
+
parse?: CliJsonAdapterOptions['parse'];
|
|
109
232
|
}
|
|
110
|
-
|
|
233
|
+
/** Discriminated by `protocol`; see `CliProviderManifestFor`. */
|
|
234
|
+
type CliProviderManifest = CliProviderManifestFor<'exec-text'> | CliProviderManifestFor<'exec-json'> | CliProviderManifestFor<'acp'>;
|
|
235
|
+
/** Protocol of each built-in manifest id, used to type `getCliProviderManifest`. */
|
|
236
|
+
interface BuiltInCliManifestProtocols {
|
|
237
|
+
codex: 'exec-text';
|
|
238
|
+
'claude-code': 'exec-text';
|
|
239
|
+
'claude-code-json': 'exec-json';
|
|
240
|
+
grok: 'acp';
|
|
241
|
+
opencode: 'acp';
|
|
242
|
+
}
|
|
243
|
+
type BuiltInCliManifestId = keyof BuiltInCliManifestProtocols;
|
|
244
|
+
interface CliManifestOptions<P extends CliProtocol = CliProtocol> {
|
|
111
245
|
args?: readonly string[];
|
|
112
246
|
mode?: CliSecurityMode;
|
|
113
247
|
cwd?: string;
|
|
@@ -116,22 +250,23 @@ interface CliManifestOptions {
|
|
|
116
250
|
maxOutputBytes?: number;
|
|
117
251
|
killGraceMs?: number;
|
|
118
252
|
onDiagnostic?: CliProcessOptions['onDiagnostic'];
|
|
119
|
-
|
|
253
|
+
/** Only capabilities the manifest's protocol can deliver are accepted. */
|
|
254
|
+
requiredCapabilities?: CliCapabilitiesFor<P>;
|
|
120
255
|
}
|
|
121
256
|
declare function validateCliProviderManifest(manifest: unknown): asserts manifest is CliProviderManifest;
|
|
122
257
|
declare function listCliProviderManifests(): CliProviderManifest[];
|
|
123
|
-
|
|
124
|
-
declare function
|
|
125
|
-
declare function
|
|
258
|
+
/** Built-in ids resolve to their protocol-specific manifest type; unknown ids to the union. */
|
|
259
|
+
declare function getCliProviderManifest<Id extends string>(id: Id): (Id extends BuiltInCliManifestId ? CliProviderManifestFor<BuiltInCliManifestProtocols[Id]> : CliProviderManifest) | undefined;
|
|
260
|
+
declare function resolveCliManifest<M extends CliProviderManifest>(manifest: M, options?: CliManifestOptions<M['protocol']>): CliJsonAdapterOptions;
|
|
261
|
+
declare function diagnoseCliProviderManifest<M extends CliProviderManifest>(manifest: M, options?: Omit<CliManifestOptions<M['protocol']>, 'args'>): Promise<CliDiagnostic>;
|
|
126
262
|
declare function manifestCapabilities(manifest: CliProviderManifest): AdapterCapabilities;
|
|
127
263
|
|
|
128
264
|
declare function diagnoseCliProvider(options: CliProcessOptions & {
|
|
129
265
|
diagnosticArgs?: readonly string[];
|
|
130
266
|
}): Promise<CliDiagnostic>;
|
|
131
267
|
|
|
132
|
-
declare function standardJsonParser(value: unknown): readonly StreamChunk[];
|
|
133
268
|
declare function createCliAdapter(options: CliAdapterOptions): AdapterFactory;
|
|
134
269
|
declare function createJsonCliAdapter(options: CliJsonAdapterOptions): AdapterFactory;
|
|
135
270
|
declare function createAcpCliAdapter(options: AcpCliAdapterOptions): AdapterFactory;
|
|
136
271
|
|
|
137
|
-
export { type AcpCliAdapterOptions, type AcpClientInfo, type CliAdapterOptions, type CliCapabilityRequirements, type CliDiagnostic, type CliJsonAdapterOptions, type CliJsonParser, type CliJsonResponse, type CliManifestOptions, type CliProcessOptions, type CliProtocol, type CliProviderManifest, type CliSecurityMode, type CliTerminationReason, type CliToolCall, createAcpCliAdapter, createCliAdapter, createJsonCliAdapter, diagnoseCliProvider, diagnoseCliProviderManifest, getCliProviderManifest, listCliProviderManifests, manifestCapabilities,
|
|
272
|
+
export { type AcpCliAdapterOptions, type AcpClientInfo, type BuiltInCliManifestId, type BuiltInCliManifestProtocols, type CliAdapterOptions, type CliCapabilitiesFor, type CliCapabilityRequirements, type CliDiagnostic, type CliJsonAdapterOptions, type CliJsonParser, type CliJsonResponse, type CliManifestOptions, type CliProcessOptions, type CliProtocol, type CliProtocolCapabilityKeys, type CliProviderManifest, type CliProviderManifestFor, type CliSecurityMode, type CliTerminationReason, type CliToolCall, type SerializeCliPromptOptions, buildCliSystemPrompt, claudeCodeRequestArgs, createAcpCliAdapter, createCliAdapter, createJsonCliAdapter, diagnoseCliProvider, diagnoseCliProviderManifest, getCliProviderManifest, listCliProviderManifests, manifestCapabilities, parseClaudeCodeJsonOutput, parseClaudeCodeJsonResponse, parseCliJsonResponse, resolveCliManifest, serializeCliMessages, serializeCliPrompt, validateCliProviderManifest };
|