@tangle-network/sdk-provider-cli-base 0.13.17 → 0.13.19
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/dist/adapters/amp/index.d.mts +250 -0
- package/dist/adapters/amp/index.mjs +233 -0
- package/dist/adapters/factory-droids/index.d.mts +200 -0
- package/dist/adapters/factory-droids/index.mjs +356 -0
- package/dist/adapters/grok/index.d.mts +27 -0
- package/dist/adapters/grok/index.mjs +56 -0
- package/dist/adapters/hermes/index.d.mts +148 -0
- package/dist/adapters/hermes/index.mjs +244 -0
- package/dist/adapters/nanoclaw/index.d.mts +50 -0
- package/dist/adapters/nanoclaw/index.mjs +116 -0
- package/dist/adapters/openclaw/index.d.mts +68 -0
- package/dist/adapters/openclaw/index.mjs +240 -0
- package/dist/adapters/prime/index.d.mts +126 -0
- package/dist/adapters/prime/index.mjs +446 -0
- package/dist/conformance/index.d.mts +1 -1
- package/dist/index-BpO3fvbf.d.mts +1254 -0
- package/dist/index.d.mts +3 -1254
- package/dist/index.mjs +1 -4585
- package/dist/{prompt-input-BHn_1z69.d.mts → prompt-input-CD7okX8T.d.mts} +1 -1
- package/dist/src-Fn8Pu1xq.mjs +4586 -0
- package/package.json +38 -9
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
import { Mt as CliExecArgs, Pt as CliProviderConfig, Rt as ExecutionState, ht as CliProviderAdapterBase } from "../../index-BpO3fvbf.mjs";
|
|
2
|
+
import { StreamParserConfig } from "@tangle-network/sdk-cli-runner";
|
|
3
|
+
import { McpConfig, ProviderConfig, StreamEvent } from "@tangle-network/agent-interface";
|
|
4
|
+
|
|
5
|
+
//#region src/adapters/amp/types.d.ts
|
|
6
|
+
/**
|
|
7
|
+
* Text content block.
|
|
8
|
+
*/
|
|
9
|
+
interface AmpTextBlock {
|
|
10
|
+
type: "text";
|
|
11
|
+
text: string;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Tool use request block.
|
|
15
|
+
*/
|
|
16
|
+
interface AmpToolUseBlock {
|
|
17
|
+
type: "tool_use";
|
|
18
|
+
id: string;
|
|
19
|
+
name: string;
|
|
20
|
+
input: Record<string, unknown>;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Tool result block (appears in user messages).
|
|
24
|
+
*/
|
|
25
|
+
interface AmpToolResultBlock {
|
|
26
|
+
type: "tool_result";
|
|
27
|
+
tool_use_id: string;
|
|
28
|
+
content: string | unknown;
|
|
29
|
+
is_error?: boolean;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Thinking/reasoning content block.
|
|
33
|
+
* Only present when `--stream-json-thinking` is used.
|
|
34
|
+
*/
|
|
35
|
+
interface AmpThinkingBlock {
|
|
36
|
+
type: "thinking";
|
|
37
|
+
thinking: string;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Redacted thinking block.
|
|
41
|
+
*/
|
|
42
|
+
interface AmpRedactedThinkingBlock {
|
|
43
|
+
type: "redacted_thinking";
|
|
44
|
+
data: string;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Union of all content block types.
|
|
48
|
+
*/
|
|
49
|
+
type AmpContentBlock = AmpTextBlock | AmpToolUseBlock | AmpToolResultBlock | AmpThinkingBlock | AmpRedactedThinkingBlock;
|
|
50
|
+
/**
|
|
51
|
+
* Token usage statistics.
|
|
52
|
+
*/
|
|
53
|
+
interface AmpTokenUsage {
|
|
54
|
+
input_tokens: number;
|
|
55
|
+
output_tokens: number;
|
|
56
|
+
max_tokens?: number;
|
|
57
|
+
cache_creation_input_tokens?: number;
|
|
58
|
+
cache_read_input_tokens?: number;
|
|
59
|
+
service_tier?: string;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Assistant message structure.
|
|
63
|
+
*/
|
|
64
|
+
interface AmpAssistantMessage {
|
|
65
|
+
type: "message";
|
|
66
|
+
role: "assistant";
|
|
67
|
+
content: AmpContentBlock[];
|
|
68
|
+
stop_reason?: "end_turn" | "tool_use" | "max_tokens" | null;
|
|
69
|
+
usage?: AmpTokenUsage;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* User message structure (contains tool results).
|
|
73
|
+
*/
|
|
74
|
+
interface AmpUserMessage {
|
|
75
|
+
role: "user";
|
|
76
|
+
content: AmpToolResultBlock[];
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* MCP server status in init event.
|
|
80
|
+
*/
|
|
81
|
+
interface AmpMcpServerInfo {
|
|
82
|
+
name: string;
|
|
83
|
+
status: string;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* System initialization event.
|
|
87
|
+
* Emitted at the start of execution with environment details.
|
|
88
|
+
*/
|
|
89
|
+
interface AmpSystemEvent {
|
|
90
|
+
type: "system";
|
|
91
|
+
subtype: "init";
|
|
92
|
+
cwd: string;
|
|
93
|
+
session_id: string;
|
|
94
|
+
tools: string[];
|
|
95
|
+
mcp_servers: AmpMcpServerInfo[];
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* User event (contains tool results).
|
|
99
|
+
*/
|
|
100
|
+
interface AmpUserEvent {
|
|
101
|
+
type: "user";
|
|
102
|
+
message: AmpUserMessage;
|
|
103
|
+
parent_tool_use_id: string | null;
|
|
104
|
+
session_id: string;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Assistant event (model response with content blocks).
|
|
108
|
+
*/
|
|
109
|
+
interface AmpAssistantEvent {
|
|
110
|
+
type: "assistant";
|
|
111
|
+
message: AmpAssistantMessage;
|
|
112
|
+
parent_tool_use_id: string | null;
|
|
113
|
+
session_id: string;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Success result event.
|
|
117
|
+
*/
|
|
118
|
+
interface AmpSuccessResultEvent {
|
|
119
|
+
type: "result";
|
|
120
|
+
subtype: "success";
|
|
121
|
+
duration_ms: number;
|
|
122
|
+
is_error: false;
|
|
123
|
+
num_turns: number;
|
|
124
|
+
result: string;
|
|
125
|
+
session_id: string;
|
|
126
|
+
usage?: AmpTokenUsage;
|
|
127
|
+
permission_denials?: string[];
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Error result event.
|
|
131
|
+
*/
|
|
132
|
+
interface AmpErrorResultEvent {
|
|
133
|
+
type: "result";
|
|
134
|
+
subtype: "error_during_execution" | "error_max_turns";
|
|
135
|
+
duration_ms: number;
|
|
136
|
+
is_error: true;
|
|
137
|
+
num_turns: number;
|
|
138
|
+
error: string;
|
|
139
|
+
session_id: string;
|
|
140
|
+
usage?: AmpTokenUsage;
|
|
141
|
+
permission_denials?: string[];
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Union of result event types.
|
|
145
|
+
*/
|
|
146
|
+
type AmpResultEvent = AmpSuccessResultEvent | AmpErrorResultEvent;
|
|
147
|
+
/**
|
|
148
|
+
* Union of all AMP events.
|
|
149
|
+
*/
|
|
150
|
+
type AmpEvent = AmpSystemEvent | AmpUserEvent | AmpAssistantEvent | AmpResultEvent;
|
|
151
|
+
/**
|
|
152
|
+
* Configuration for the AMP provider.
|
|
153
|
+
* Extends the shared CliProviderConfig with AMP-specific options.
|
|
154
|
+
*/
|
|
155
|
+
interface AmpConfig extends CliProviderConfig {
|
|
156
|
+
/** Path to the amp CLI (default: "amp") */
|
|
157
|
+
cliPath?: string;
|
|
158
|
+
/** Default model to use (AMP uses claude-opus-4-5-20251101 by default) */
|
|
159
|
+
model?: string;
|
|
160
|
+
/** API key for AMP (can also use AMP_API_KEY env var) */
|
|
161
|
+
apiKey?: string;
|
|
162
|
+
/** Include thinking/reasoning in output (adds --stream-json-thinking) */
|
|
163
|
+
includeThinking?: boolean;
|
|
164
|
+
/**
|
|
165
|
+
* Bypass all permission checks for fully autonomous operation.
|
|
166
|
+
* Uses --dangerously-allow-all flag.
|
|
167
|
+
* Default: true (for headless/automated use)
|
|
168
|
+
*/
|
|
169
|
+
bypassPermissions?: boolean;
|
|
170
|
+
/** Extra flags to pass to the CLI */
|
|
171
|
+
extraFlags?: string[];
|
|
172
|
+
/** Workspace settings path override */
|
|
173
|
+
workspaceSettingsPath?: string;
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Type guard for AMP events.
|
|
177
|
+
*/
|
|
178
|
+
declare function isAmpEvent(value: unknown): value is AmpEvent;
|
|
179
|
+
/**
|
|
180
|
+
* Type guard for text blocks.
|
|
181
|
+
*/
|
|
182
|
+
declare function isTextBlock(block: AmpContentBlock): block is AmpTextBlock;
|
|
183
|
+
/**
|
|
184
|
+
* Type guard for tool use blocks.
|
|
185
|
+
*/
|
|
186
|
+
declare function isToolUseBlock(block: AmpContentBlock): block is AmpToolUseBlock;
|
|
187
|
+
/**
|
|
188
|
+
* Type guard for tool result blocks.
|
|
189
|
+
*/
|
|
190
|
+
declare function isToolResultBlock(block: AmpContentBlock): block is AmpToolResultBlock;
|
|
191
|
+
/**
|
|
192
|
+
* Type guard for thinking blocks.
|
|
193
|
+
*/
|
|
194
|
+
declare function isThinkingBlock(block: AmpContentBlock): block is AmpThinkingBlock;
|
|
195
|
+
//#endregion
|
|
196
|
+
//#region src/adapters/amp/adapter.d.ts
|
|
197
|
+
/**
|
|
198
|
+
* AMP (Sourcegraph) provider adapter.
|
|
199
|
+
*
|
|
200
|
+
* Implements the SdkProviderAdapter interface for the AMP CLI tool.
|
|
201
|
+
* Extends CliProviderAdapterBase with AMP-specific event parsing and CLI arguments.
|
|
202
|
+
*
|
|
203
|
+
* Key differences from other CLI providers:
|
|
204
|
+
* - Uses `-x` (execute) mode for non-interactive operation
|
|
205
|
+
* - Uses `--stream-json` and `--stream-json-input` for structured I/O
|
|
206
|
+
* - Session continuation uses `amp threads continue [thread_id]`
|
|
207
|
+
* - Events have a nested structure with `assistant.message.content[]`
|
|
208
|
+
*/
|
|
209
|
+
declare class AmpProviderAdapter extends CliProviderAdapterBase<AmpConfig, AmpEvent> {
|
|
210
|
+
readonly provider = "amp";
|
|
211
|
+
protected readonly defaultCliPath = "amp";
|
|
212
|
+
protected buildExecArgs(params: {
|
|
213
|
+
message: string;
|
|
214
|
+
config: AmpConfig;
|
|
215
|
+
model?: string;
|
|
216
|
+
sessionId?: string;
|
|
217
|
+
workspaceRoot: string;
|
|
218
|
+
systemPrompt?: string;
|
|
219
|
+
}): CliExecArgs;
|
|
220
|
+
/**
|
|
221
|
+
* Refuse a run that has no Amp credential. Without `AMP_API_KEY` or login
|
|
222
|
+
* files the amp CLI prints a device-login URL and waits for a person to
|
|
223
|
+
* confirm it in a browser, so a headless turn produces no event until its
|
|
224
|
+
* timeout. Amp is a hosted service of its own: the Tangle Router has no
|
|
225
|
+
* managed credential for it, so a managed box carries none, and the caller
|
|
226
|
+
* supplies the access token (`backend.model.apiKey`) or login files.
|
|
227
|
+
*/
|
|
228
|
+
protected afterInitialize(config: ProviderConfig): Promise<void>;
|
|
229
|
+
protected buildExecEnv(config: AmpConfig): Record<string, string | undefined>;
|
|
230
|
+
protected createEventParser(state: ExecutionState, onEvent?: (event: StreamEvent) => void): StreamParserConfig<AmpEvent>;
|
|
231
|
+
protected formatStdinMessage(message: string): string;
|
|
232
|
+
protected buildMcpAddArgs(name: string, config: McpConfig): string[];
|
|
233
|
+
protected buildMcpListArgs(): string[] | null;
|
|
234
|
+
}
|
|
235
|
+
//#endregion
|
|
236
|
+
//#region src/adapters/amp/event-mapper.d.ts
|
|
237
|
+
/**
|
|
238
|
+
* Maps an AMP event to StreamEvent(s).
|
|
239
|
+
*
|
|
240
|
+
* Uses message.part.updated as the primary event type for all content updates,
|
|
241
|
+
* matching the OpenCode provider's event format.
|
|
242
|
+
*
|
|
243
|
+
* @param event - The AMP event
|
|
244
|
+
* @param state - The execution state (mutated by this function)
|
|
245
|
+
* @returns Array of StreamEvents
|
|
246
|
+
*/
|
|
247
|
+
declare function mapAmpEvent(event: AmpEvent, state: ExecutionState): StreamEvent[];
|
|
248
|
+
//#endregion
|
|
249
|
+
export { type AmpAssistantEvent, type AmpAssistantMessage, type AmpConfig, type AmpContentBlock, type AmpErrorResultEvent, type AmpEvent, type AmpMcpServerInfo, AmpProviderAdapter, type AmpRedactedThinkingBlock, type AmpResultEvent, type AmpSuccessResultEvent, type AmpSystemEvent, type AmpTextBlock, type AmpThinkingBlock, type AmpTokenUsage, type AmpToolResultBlock, type AmpToolUseBlock, type AmpUserEvent, type AmpUserMessage, isAmpEvent, isTextBlock, isThinkingBlock, isToolResultBlock, isToolUseBlock, mapAmpEvent };
|
|
250
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
import { At as toolStartEvents, Dt as textDeltaEvents, F as jsonEventParser, H as CliProviderAdapterBase, K as localMcpArgv, Tt as sessionObservedEvents, V as recordCliTokenUsage, kt as toolResultEvents, q as localMcpEnv, wt as reasoningEvents } from "../../src-Fn8Pu1xq.mjs";
|
|
2
|
+
//#region src/adapters/amp/types.ts
|
|
3
|
+
/**
|
|
4
|
+
* Type guard for AMP events.
|
|
5
|
+
*/
|
|
6
|
+
function isAmpEvent(value) {
|
|
7
|
+
if (typeof value !== "object" || value === null) return false;
|
|
8
|
+
return typeof value.type === "string";
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Type guard for text blocks.
|
|
12
|
+
*/
|
|
13
|
+
function isTextBlock(block) {
|
|
14
|
+
return block.type === "text";
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Type guard for tool use blocks.
|
|
18
|
+
*/
|
|
19
|
+
function isToolUseBlock(block) {
|
|
20
|
+
return block.type === "tool_use";
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Type guard for tool result blocks.
|
|
24
|
+
*/
|
|
25
|
+
function isToolResultBlock(block) {
|
|
26
|
+
return block.type === "tool_result";
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Type guard for thinking blocks.
|
|
30
|
+
*/
|
|
31
|
+
function isThinkingBlock(block) {
|
|
32
|
+
return block.type === "thinking";
|
|
33
|
+
}
|
|
34
|
+
//#endregion
|
|
35
|
+
//#region src/adapters/amp/event-mapper.ts
|
|
36
|
+
/**
|
|
37
|
+
* Maps an AMP system init event to StreamEvents.
|
|
38
|
+
*/
|
|
39
|
+
function mapSystemEvent(event, state) {
|
|
40
|
+
return [...sessionObservedEvents(state, "amp", event.session_id), {
|
|
41
|
+
type: "status",
|
|
42
|
+
status: "processing",
|
|
43
|
+
detail: `Initialized in ${event.cwd} with ${event.tools.length} tools`
|
|
44
|
+
}];
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Maps an AMP user event (tool results) to StreamEvents.
|
|
48
|
+
* User events contain tool results that update the state of pending tool calls.
|
|
49
|
+
*/
|
|
50
|
+
function mapUserEvent(event, state) {
|
|
51
|
+
const events = [];
|
|
52
|
+
for (const block of event.message.content) if (isToolResultBlock(block)) events.push(...toolResultEvents(state, {
|
|
53
|
+
id: block.tool_use_id,
|
|
54
|
+
content: block.content,
|
|
55
|
+
isError: Boolean(block.is_error)
|
|
56
|
+
}));
|
|
57
|
+
return events;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Maps an AMP assistant event to StreamEvents.
|
|
61
|
+
* Assistant events contain content blocks (text, tool_use, thinking).
|
|
62
|
+
*/
|
|
63
|
+
function mapAssistantEvent(event, state) {
|
|
64
|
+
const events = [];
|
|
65
|
+
for (const block of event.message.content) events.push(...mapContentBlock(block, state));
|
|
66
|
+
recordCliTokenUsage(state, event.message);
|
|
67
|
+
return events;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Maps an individual content block to StreamEvents.
|
|
71
|
+
*/
|
|
72
|
+
function mapContentBlock(block, state) {
|
|
73
|
+
if (isTextBlock(block)) return textDeltaEvents(state, block.text);
|
|
74
|
+
if (isToolUseBlock(block)) return toolStartEvents(state, block);
|
|
75
|
+
if (isThinkingBlock(block)) return reasoningEvents(state, block.thinking, { signalPhase: true });
|
|
76
|
+
return [{
|
|
77
|
+
type: "raw",
|
|
78
|
+
backend: "amp",
|
|
79
|
+
event: block
|
|
80
|
+
}];
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Maps an AMP result event to StreamEvents.
|
|
84
|
+
*/
|
|
85
|
+
function mapResultEvent(event, state) {
|
|
86
|
+
const events = sessionObservedEvents(state, "amp", event.session_id);
|
|
87
|
+
recordCliTokenUsage(state, event);
|
|
88
|
+
if (event.is_error) events.push({
|
|
89
|
+
type: "warning",
|
|
90
|
+
code: event.subtype.toUpperCase(),
|
|
91
|
+
message: event.error
|
|
92
|
+
});
|
|
93
|
+
if (event.permission_denials && event.permission_denials.length > 0) events.push({
|
|
94
|
+
type: "warning",
|
|
95
|
+
code: "PERMISSION_DENIED",
|
|
96
|
+
message: `Permission denied for: ${event.permission_denials.join(", ")}`
|
|
97
|
+
});
|
|
98
|
+
events.push({
|
|
99
|
+
type: "status",
|
|
100
|
+
status: event.is_error ? "failed" : "completed",
|
|
101
|
+
detail: event.is_error ? event.error : void 0
|
|
102
|
+
});
|
|
103
|
+
return events;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Maps an AMP event to StreamEvent(s).
|
|
107
|
+
*
|
|
108
|
+
* Uses message.part.updated as the primary event type for all content updates,
|
|
109
|
+
* matching the OpenCode provider's event format.
|
|
110
|
+
*
|
|
111
|
+
* @param event - The AMP event
|
|
112
|
+
* @param state - The execution state (mutated by this function)
|
|
113
|
+
* @returns Array of StreamEvents
|
|
114
|
+
*/
|
|
115
|
+
function mapAmpEvent(event, state) {
|
|
116
|
+
switch (event.type) {
|
|
117
|
+
case "system": return mapSystemEvent(event, state);
|
|
118
|
+
case "user": return mapUserEvent(event, state);
|
|
119
|
+
case "assistant": return mapAssistantEvent(event, state);
|
|
120
|
+
case "result": return mapResultEvent(event, state);
|
|
121
|
+
default: return [{
|
|
122
|
+
type: "raw",
|
|
123
|
+
backend: "amp",
|
|
124
|
+
event
|
|
125
|
+
}];
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
//#endregion
|
|
129
|
+
//#region src/adapters/amp/adapter.ts
|
|
130
|
+
/**
|
|
131
|
+
* AMP (Sourcegraph) provider adapter.
|
|
132
|
+
*
|
|
133
|
+
* Implements the SdkProviderAdapter interface for the AMP CLI tool.
|
|
134
|
+
* Extends CliProviderAdapterBase with AMP-specific event parsing and CLI arguments.
|
|
135
|
+
*
|
|
136
|
+
* Key differences from other CLI providers:
|
|
137
|
+
* - Uses `-x` (execute) mode for non-interactive operation
|
|
138
|
+
* - Uses `--stream-json` and `--stream-json-input` for structured I/O
|
|
139
|
+
* - Session continuation uses `amp threads continue [thread_id]`
|
|
140
|
+
* - Events have a nested structure with `assistant.message.content[]`
|
|
141
|
+
*/
|
|
142
|
+
var AmpProviderAdapter = class extends CliProviderAdapterBase {
|
|
143
|
+
provider = "amp";
|
|
144
|
+
defaultCliPath = "amp";
|
|
145
|
+
buildExecArgs(params) {
|
|
146
|
+
const args = [];
|
|
147
|
+
if (params.config.bypassPermissions !== false) args.push("--dangerously-allow-all");
|
|
148
|
+
if (params.sessionId) args.push("threads", "continue", params.sessionId);
|
|
149
|
+
args.push(params.sessionId ? "-x" : `--execute=${params.message}`);
|
|
150
|
+
args.push("--stream-json");
|
|
151
|
+
if (params.config.includeThinking !== false) args.push("--stream-json-thinking");
|
|
152
|
+
if (params.config.extraFlags) args.push(...params.config.extraFlags);
|
|
153
|
+
if (params.sessionId) {
|
|
154
|
+
args.push("--stream-json-input");
|
|
155
|
+
return {
|
|
156
|
+
command: this.getCliPath(),
|
|
157
|
+
args,
|
|
158
|
+
useStdin: true
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
return {
|
|
162
|
+
command: this.getCliPath(),
|
|
163
|
+
args,
|
|
164
|
+
useStdin: false
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Refuse a run that has no Amp credential. Without `AMP_API_KEY` or login
|
|
169
|
+
* files the amp CLI prints a device-login URL and waits for a person to
|
|
170
|
+
* confirm it in a browser, so a headless turn produces no event until its
|
|
171
|
+
* timeout. Amp is a hosted service of its own: the Tangle Router has no
|
|
172
|
+
* managed credential for it, so a managed box carries none, and the caller
|
|
173
|
+
* supplies the access token (`backend.model.apiKey`) or login files.
|
|
174
|
+
*/
|
|
175
|
+
async afterInitialize(config) {
|
|
176
|
+
const apiKey = config.model?.apiKey ?? this.config.apiKey ?? process.env.AMP_API_KEY;
|
|
177
|
+
const authFiles = config.model?.authFiles ?? this.config.authFiles;
|
|
178
|
+
if (!apiKey && (authFiles?.length ?? 0) === 0) throw new Error("An Amp credential is required: set AMP_API_KEY, or provide backend.model.apiKey (an Amp access token) or login files. The Tangle Router does not provide Amp credentials.");
|
|
179
|
+
}
|
|
180
|
+
buildExecEnv(config) {
|
|
181
|
+
const env = this.agentEnvironmentValues();
|
|
182
|
+
const apiKey = config.apiKey ?? process.env.AMP_API_KEY;
|
|
183
|
+
if (apiKey) env.AMP_API_KEY = apiKey;
|
|
184
|
+
env.AMP_SKIP_UPDATE_CHECK = "1";
|
|
185
|
+
return env;
|
|
186
|
+
}
|
|
187
|
+
createEventParser(state, onEvent) {
|
|
188
|
+
return jsonEventParser(this.logger, onEvent, {
|
|
189
|
+
label: "AMP",
|
|
190
|
+
accept: isAmpEvent,
|
|
191
|
+
map: (event) => mapAmpEvent(event, state)
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
formatStdinMessage(message) {
|
|
195
|
+
return JSON.stringify({
|
|
196
|
+
type: "user",
|
|
197
|
+
message: {
|
|
198
|
+
role: "user",
|
|
199
|
+
content: [{
|
|
200
|
+
type: "text",
|
|
201
|
+
text: message
|
|
202
|
+
}]
|
|
203
|
+
}
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
buildMcpAddArgs(name, config) {
|
|
207
|
+
const args = [
|
|
208
|
+
"mcp",
|
|
209
|
+
"add",
|
|
210
|
+
"--workspace",
|
|
211
|
+
name
|
|
212
|
+
];
|
|
213
|
+
if (config.type === "http" || config.type === "remote") {
|
|
214
|
+
this.logger.warn("AMP may not support remote MCP servers directly", {
|
|
215
|
+
name,
|
|
216
|
+
url: config.url
|
|
217
|
+
});
|
|
218
|
+
args.push("--", "echo", `Remote MCP not supported: ${config.url}`);
|
|
219
|
+
} else {
|
|
220
|
+
const envEntries = localMcpEnv(config);
|
|
221
|
+
if (envEntries && Object.keys(envEntries).length > 0) throw new Error(`amp: MCP server "${name}" declares environment variables (${Object.keys(envEntries).sort().join(", ")}) but the amp CLI exposes no way to pass them to the server process. Use a backend whose CLI accepts MCP env vars, or drop the env from the config.`);
|
|
222
|
+
args.push("--", ...localMcpArgv(config));
|
|
223
|
+
}
|
|
224
|
+
return args;
|
|
225
|
+
}
|
|
226
|
+
buildMcpListArgs() {
|
|
227
|
+
return ["mcp", "list"];
|
|
228
|
+
}
|
|
229
|
+
};
|
|
230
|
+
//#endregion
|
|
231
|
+
export { AmpProviderAdapter, isAmpEvent, isTextBlock, isThinkingBlock, isToolResultBlock, isToolUseBlock, mapAmpEvent };
|
|
232
|
+
|
|
233
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
import { Mt as CliExecArgs, Pt as CliProviderConfig, Rt as ExecutionState, ht as CliProviderAdapterBase } from "../../index-BpO3fvbf.mjs";
|
|
2
|
+
import { StreamParserConfig } from "@tangle-network/sdk-cli-runner";
|
|
3
|
+
import { AgentExecutionInput, AgentExecutionResult, BackendCapabilities, InteractionResponse, McpConfig, ProviderConfig, SdkHostServices, StreamEvent } from "@tangle-network/agent-interface";
|
|
4
|
+
|
|
5
|
+
//#region src/adapters/factory-droids/types.d.ts
|
|
6
|
+
/**
|
|
7
|
+
* Assistant text content event.
|
|
8
|
+
*/
|
|
9
|
+
interface FactoryDroidsAssistantEvent {
|
|
10
|
+
type: "assistant";
|
|
11
|
+
content: string;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Thinking/reasoning content event.
|
|
15
|
+
*/
|
|
16
|
+
interface FactoryDroidsThinkingEvent {
|
|
17
|
+
type: "thinking";
|
|
18
|
+
content: string;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Tool use request event.
|
|
22
|
+
*/
|
|
23
|
+
interface FactoryDroidsToolUseEvent {
|
|
24
|
+
type: "tool_use";
|
|
25
|
+
id: string;
|
|
26
|
+
name: string;
|
|
27
|
+
input: unknown;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Tool result event.
|
|
31
|
+
*/
|
|
32
|
+
interface FactoryDroidsToolResultEvent {
|
|
33
|
+
type: "tool_result";
|
|
34
|
+
tool_use_id: string;
|
|
35
|
+
content: string | unknown;
|
|
36
|
+
is_error?: boolean;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* System message event.
|
|
40
|
+
*/
|
|
41
|
+
interface FactoryDroidsSystemEvent {
|
|
42
|
+
type: "system";
|
|
43
|
+
content: string;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Error event.
|
|
47
|
+
*/
|
|
48
|
+
interface FactoryDroidsErrorEvent {
|
|
49
|
+
type: "error";
|
|
50
|
+
/** droid 0.238.0 names the failure here, e.g. `{type:"error",source:"cli",message}`. */
|
|
51
|
+
message?: string;
|
|
52
|
+
content?: string;
|
|
53
|
+
source?: string;
|
|
54
|
+
code?: string;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Final result event.
|
|
58
|
+
*/
|
|
59
|
+
interface FactoryDroidsResultEvent {
|
|
60
|
+
type: "result";
|
|
61
|
+
text: string;
|
|
62
|
+
session_id?: string;
|
|
63
|
+
usage?: {
|
|
64
|
+
input_tokens?: number;
|
|
65
|
+
output_tokens?: number;
|
|
66
|
+
cache_read_input_tokens?: number;
|
|
67
|
+
cache_creation_input_tokens?: number;
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Union of all Factory Droids events.
|
|
72
|
+
*/
|
|
73
|
+
/**
|
|
74
|
+
* droid ≥0.159 stream-json schema. The earlier `assistant`/`tool_use`/`result`
|
|
75
|
+
* events were renamed: assistant text arrives as a `message` (with a `role` and
|
|
76
|
+
* `text`), tool calls as `tool_call` (`toolName`/`parameters`), and the terminal
|
|
77
|
+
* event as `completion` (`finalText`). We map both shapes so the adapter works
|
|
78
|
+
* across droid versions.
|
|
79
|
+
*/
|
|
80
|
+
interface FactoryDroidsMessageEvent {
|
|
81
|
+
type: "message";
|
|
82
|
+
role: "assistant" | "user";
|
|
83
|
+
text: string;
|
|
84
|
+
id?: string;
|
|
85
|
+
session_id?: string;
|
|
86
|
+
}
|
|
87
|
+
interface FactoryDroidsToolCallEvent {
|
|
88
|
+
type: "tool_call";
|
|
89
|
+
toolName: string;
|
|
90
|
+
parameters?: unknown;
|
|
91
|
+
toolId?: string;
|
|
92
|
+
id?: string;
|
|
93
|
+
session_id?: string;
|
|
94
|
+
}
|
|
95
|
+
interface FactoryDroidsCompletionEvent {
|
|
96
|
+
type: "completion";
|
|
97
|
+
finalText?: string;
|
|
98
|
+
numTurns?: number;
|
|
99
|
+
durationMs?: number;
|
|
100
|
+
session_id?: string;
|
|
101
|
+
usage?: {
|
|
102
|
+
input_tokens?: number;
|
|
103
|
+
output_tokens?: number;
|
|
104
|
+
cache_read_input_tokens?: number;
|
|
105
|
+
cache_creation_input_tokens?: number;
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
type FactoryDroidsEvent = FactoryDroidsAssistantEvent | FactoryDroidsThinkingEvent | FactoryDroidsToolUseEvent | FactoryDroidsToolResultEvent | FactoryDroidsSystemEvent | FactoryDroidsErrorEvent | FactoryDroidsResultEvent | FactoryDroidsMessageEvent | FactoryDroidsToolCallEvent | FactoryDroidsCompletionEvent;
|
|
109
|
+
/**
|
|
110
|
+
* Configuration for the Factory Droids provider.
|
|
111
|
+
* Extends the shared CliProviderConfig with Factory Droids-specific options.
|
|
112
|
+
*/
|
|
113
|
+
interface FactoryDroidsConfig extends CliProviderConfig {
|
|
114
|
+
/** Path to the droid CLI (default: "droid") */
|
|
115
|
+
cliPath?: string;
|
|
116
|
+
/** Default model to use */
|
|
117
|
+
model?: string;
|
|
118
|
+
/**
|
|
119
|
+
* Autonomy level passed to `droid exec --auto`. droid only accepts
|
|
120
|
+
* low|medium|high; full bypass is `bypassPermissions` (→ `--skip-permissions-unsafe`),
|
|
121
|
+
* NOT an autonomy level.
|
|
122
|
+
*/
|
|
123
|
+
autonomyLevel?: "low" | "medium" | "high";
|
|
124
|
+
/** Extra flags to pass to the CLI */
|
|
125
|
+
extraFlags?: string[];
|
|
126
|
+
/** API key for Factory Droids (can also use FACTORY_API_KEY env var) */
|
|
127
|
+
apiKey?: string;
|
|
128
|
+
/**
|
|
129
|
+
* Route clarifying questions through a per-execution loopback MCP server.
|
|
130
|
+
* Factory Droids does not advertise plan support because it cannot enforce
|
|
131
|
+
* a terminal plan-before-execute boundary. Permission remains governed by
|
|
132
|
+
* droid's autonomy flags. Default: false.
|
|
133
|
+
*/
|
|
134
|
+
interactions?: CliProviderConfig["interactions"];
|
|
135
|
+
}
|
|
136
|
+
//#endregion
|
|
137
|
+
//#region src/adapters/factory-droids/adapter.d.ts
|
|
138
|
+
/**
|
|
139
|
+
* Factory Droids provider adapter.
|
|
140
|
+
*
|
|
141
|
+
* Implements the SdkProviderAdapter interface for the Factory Droids CLI tool.
|
|
142
|
+
* Extends CliProviderAdapterBase with Factory Droids-specific event parsing and CLI arguments.
|
|
143
|
+
*/
|
|
144
|
+
declare class FactoryDroidsProviderAdapter extends CliProviderAdapterBase<FactoryDroidsConfig, FactoryDroidsEvent> {
|
|
145
|
+
readonly provider = "factory-droids";
|
|
146
|
+
protected readonly defaultCliPath = "droid";
|
|
147
|
+
/**
|
|
148
|
+
* Shared interaction round-trip for questions. droid auto-discovers
|
|
149
|
+
* MCP tools, so the agent calls `ask_user` itself; permission
|
|
150
|
+
* stays governed by droid's own `--auto` / `--skip-permissions-unsafe`.
|
|
151
|
+
*/
|
|
152
|
+
private activeInteractions?;
|
|
153
|
+
private configuredInteractionKinds;
|
|
154
|
+
getCapabilities(): BackendCapabilities;
|
|
155
|
+
/**
|
|
156
|
+
* Host a per-execution interaction MCP server when `interactions` is on and
|
|
157
|
+
* register it into the SAME `$HOME/.factory/mcp.json` that `droid exec` reads
|
|
158
|
+
* (HOME resolved exactly as the base adapter's exec env resolves it, so the
|
|
159
|
+
* write lands where droid looks). The entry is removed and every pending
|
|
160
|
+
* interaction failed-closed in `finally` when the turn unwinds.
|
|
161
|
+
*/
|
|
162
|
+
execute(input: AgentExecutionInput, services: SdkHostServices, onEvent?: (event: StreamEvent) => void): Promise<AgentExecutionResult>;
|
|
163
|
+
respondToInteraction(response: InteractionResponse): Promise<void>;
|
|
164
|
+
/**
|
|
165
|
+
* Initialize the adapter with API key validation.
|
|
166
|
+
* Factory Droids requires an API key to function.
|
|
167
|
+
*/
|
|
168
|
+
protected afterInitialize(config: ProviderConfig): Promise<void>;
|
|
169
|
+
protected buildExecArgs(params: {
|
|
170
|
+
message: string;
|
|
171
|
+
config: FactoryDroidsConfig;
|
|
172
|
+
model?: string;
|
|
173
|
+
sessionId?: string;
|
|
174
|
+
workspaceRoot: string;
|
|
175
|
+
systemPrompt?: string;
|
|
176
|
+
}): CliExecArgs;
|
|
177
|
+
protected buildExecEnv(config: FactoryDroidsConfig): Record<string, string | undefined>;
|
|
178
|
+
protected createEventParser(state: ExecutionState, onEvent?: (event: StreamEvent) => void): StreamParserConfig<FactoryDroidsEvent>;
|
|
179
|
+
protected buildMcpAddArgs(name: string, config: McpConfig): string[];
|
|
180
|
+
}
|
|
181
|
+
//#endregion
|
|
182
|
+
//#region src/adapters/factory-droids/event-mapper.d.ts
|
|
183
|
+
/**
|
|
184
|
+
* Type guard for Factory Droids events.
|
|
185
|
+
*/
|
|
186
|
+
declare function isFactoryDroidsEvent(value: unknown): value is FactoryDroidsEvent;
|
|
187
|
+
/**
|
|
188
|
+
* Maps a Factory Droids event to StreamEvent(s).
|
|
189
|
+
*
|
|
190
|
+
* Uses message.part.updated as the primary event type for all content updates,
|
|
191
|
+
* matching the OpenCode provider's event format.
|
|
192
|
+
*
|
|
193
|
+
* @param event - The Factory Droids event
|
|
194
|
+
* @param state - The execution state (mutated by this function)
|
|
195
|
+
* @returns Array of StreamEvents
|
|
196
|
+
*/
|
|
197
|
+
declare function mapFactoryDroidsEvent(event: FactoryDroidsEvent, state: ExecutionState): StreamEvent[];
|
|
198
|
+
//#endregion
|
|
199
|
+
export { type FactoryDroidsAssistantEvent, type FactoryDroidsConfig, type FactoryDroidsErrorEvent, type FactoryDroidsEvent, FactoryDroidsProviderAdapter, type FactoryDroidsResultEvent, type FactoryDroidsSystemEvent, type FactoryDroidsThinkingEvent, type FactoryDroidsToolResultEvent, type FactoryDroidsToolUseEvent, isFactoryDroidsEvent, mapFactoryDroidsEvent };
|
|
200
|
+
//# sourceMappingURL=index.d.mts.map
|