@moxxy/plugin-provider-claude-code 0.44.0 → 0.46.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/dist/account-limit.d.ts +8 -0
- package/dist/account-limit.d.ts.map +1 -0
- package/dist/account-limit.js +23 -0
- package/dist/account-limit.js.map +1 -0
- package/dist/agent-provider.d.ts +61 -0
- package/dist/agent-provider.d.ts.map +1 -0
- package/dist/agent-provider.js +195 -0
- package/dist/agent-provider.js.map +1 -0
- package/dist/agent-session.d.ts +145 -0
- package/dist/agent-session.d.ts.map +1 -0
- package/dist/agent-session.js +703 -0
- package/dist/agent-session.js.map +1 -0
- package/dist/background-work.d.ts +42 -0
- package/dist/background-work.d.ts.map +1 -0
- package/dist/background-work.js +140 -0
- package/dist/background-work.js.map +1 -0
- package/dist/constants.d.ts +2 -2
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +2 -2
- package/dist/constants.js.map +1 -1
- package/dist/executable.d.ts +15 -0
- package/dist/executable.d.ts.map +1 -0
- package/dist/executable.js +30 -0
- package/dist/executable.js.map +1 -0
- package/dist/index.d.ts +4 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +55 -16
- package/dist/index.js.map +1 -1
- package/dist/login.d.ts +3 -0
- package/dist/login.d.ts.map +1 -1
- package/dist/login.js +8 -1
- package/dist/login.js.map +1 -1
- package/dist/offered-models.d.ts +13 -0
- package/dist/offered-models.d.ts.map +1 -0
- package/dist/offered-models.js +48 -0
- package/dist/offered-models.js.map +1 -0
- package/dist/own-settings.d.ts +12 -0
- package/dist/own-settings.d.ts.map +1 -0
- package/dist/own-settings.js +31 -0
- package/dist/own-settings.js.map +1 -0
- package/dist/questions.d.ts +6 -0
- package/dist/questions.d.ts.map +1 -0
- package/dist/questions.js +38 -0
- package/dist/questions.js.map +1 -0
- package/dist/scheduled-wakeups.d.ts +10 -0
- package/dist/scheduled-wakeups.d.ts.map +1 -0
- package/dist/scheduled-wakeups.js +30 -0
- package/dist/scheduled-wakeups.js.map +1 -0
- package/dist/sdk-install.d.ts +25 -0
- package/dist/sdk-install.d.ts.map +1 -0
- package/dist/sdk-install.js +94 -0
- package/dist/sdk-install.js.map +1 -0
- package/dist/sdk-types.d.ts +312 -0
- package/dist/sdk-types.d.ts.map +1 -0
- package/dist/sdk-types.js +8 -0
- package/dist/sdk-types.js.map +1 -0
- package/dist/subagents.d.ts +39 -0
- package/dist/subagents.d.ts.map +1 -0
- package/dist/subagents.js +114 -0
- package/dist/subagents.js.map +1 -0
- package/dist/task-list.d.ts +21 -0
- package/dist/task-list.d.ts.map +1 -0
- package/dist/task-list.js +68 -0
- package/dist/task-list.js.map +1 -0
- package/dist/translate.d.ts +66 -0
- package/dist/translate.d.ts.map +1 -0
- package/dist/translate.js +302 -0
- package/dist/translate.js.map +1 -0
- package/package.json +14 -9
- package/src/account-limit.ts +26 -0
- package/src/agent-cli.test.ts +83 -0
- package/src/agent-provider.test.ts +1176 -0
- package/src/agent-provider.ts +223 -0
- package/src/agent-session.ts +793 -0
- package/src/background-work.ts +163 -0
- package/src/constants.ts +2 -3
- package/src/event-coverage.test.ts +106 -0
- package/src/executable.test.ts +60 -0
- package/src/executable.ts +34 -0
- package/src/fake-claude.testkit.ts +376 -0
- package/src/fixtures/claude-agent-sdk-0.3.296.json +43 -0
- package/src/fixtures/claude-supported-models-0.3.296.json +218 -0
- package/src/index.test.ts +49 -0
- package/src/index.ts +61 -18
- package/src/login.ts +10 -1
- package/src/offered-models.test.ts +81 -0
- package/src/offered-models.ts +60 -0
- package/src/own-settings.test.ts +68 -0
- package/src/own-settings.ts +33 -0
- package/src/questions.test.ts +68 -0
- package/src/questions.ts +45 -0
- package/src/scheduled-wakeups.test.ts +41 -0
- package/src/scheduled-wakeups.ts +34 -0
- package/src/sdk-install.test.ts +124 -0
- package/src/sdk-install.ts +107 -0
- package/src/sdk-types.ts +278 -0
- package/src/subagents.ts +123 -0
- package/src/task-list.ts +65 -0
- package/src/translate.test.ts +474 -0
- package/src/translate.ts +306 -0
- package/dist/process.d.ts +0 -34
- package/dist/process.d.ts.map +0 -1
- package/dist/process.js +0 -197
- package/dist/process.js.map +0 -1
- package/dist/protocol.d.ts +0 -30
- package/dist/protocol.d.ts.map +0 -1
- package/dist/protocol.js +0 -368
- package/dist/protocol.js.map +0 -1
- package/dist/provider.d.ts +0 -53
- package/dist/provider.d.ts.map +0 -1
- package/dist/provider.js +0 -229
- package/dist/provider.js.map +0 -1
- package/src/process.test.ts +0 -208
- package/src/process.ts +0 -224
- package/src/protocol.ts +0 -390
- package/src/provider.test.ts +0 -671
- package/src/provider.ts +0 -267
package/src/translate.ts
ADDED
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
import type { AgentAccountLimit, AgentGoalStatus, AgentStepEvent, ContentBlock, FileDiffDisplay, TokenUsage } from '@moxxy/sdk';
|
|
2
|
+
import { diffPathIn, fileDiffFromPatch, fileDiffFromText, imageToolOutput, stepListOutput, type ToolImage } from '@moxxy/sdk';
|
|
3
|
+
import type { ClaudeContentBlock, ClaudeMessage, ClaudePermissionMode, ClaudeUsage, ClaudeUserContent } from './sdk-types.js';
|
|
4
|
+
import { accountLimitFrom } from './account-limit.js';
|
|
5
|
+
import { ClaudeSubagents } from './subagents.js';
|
|
6
|
+
import { ClaudeTaskList } from './task-list.js';
|
|
7
|
+
|
|
8
|
+
/** The name Moxxy's MCP server has in Claude; its tools appear as `mcp__moxxy__<name>`. */
|
|
9
|
+
export const MOXXY_MCP_SERVER = 'moxxy';
|
|
10
|
+
export const MOXXY_TOOL_PREFIX = `mcp__${MOXXY_MCP_SERVER}__`;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Claude's messages for one turn, as Moxxy agent events. Calls to Moxxy's own
|
|
14
|
+
* tools are left out: Moxxy records those when it runs them. A subagent shows
|
|
15
|
+
* as a subagent, with its own calls under it.
|
|
16
|
+
*/
|
|
17
|
+
export class TurnTranslator {
|
|
18
|
+
private readonly announced = new Map<string, { readonly name: string; readonly input: unknown }>();
|
|
19
|
+
private readonly moxxyCalls = new Set<string>();
|
|
20
|
+
/** Calls whose answer Moxxy gave the person instead (a plan on the plan card); Claude's refusal of them is not shown. */
|
|
21
|
+
private readonly handedOver = new Set<string>();
|
|
22
|
+
/** The plan limit Claude last reported, whose reset its own limit message leaves out. */
|
|
23
|
+
private limit: AgentAccountLimit | undefined;
|
|
24
|
+
/**
|
|
25
|
+
* A sentence Claude sent on its own, not yet marked. Claude Code sends each block
|
|
26
|
+
* of a reply as a message of its own, with no stop reason yet, so a sentence and
|
|
27
|
+
* the call after it arrive apart: it is marked by what comes next.
|
|
28
|
+
*/
|
|
29
|
+
private unmarked: string | undefined;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* `cwd`: the project folder, which the paths of file diffs are shown relative to.
|
|
33
|
+
* `tasks`: Claude's task list, which outlives a turn.
|
|
34
|
+
* `subagents`: Claude's subagents, which may outlive a turn.
|
|
35
|
+
*/
|
|
36
|
+
constructor(
|
|
37
|
+
private readonly cwd = '',
|
|
38
|
+
private readonly tasks = new ClaudeTaskList(),
|
|
39
|
+
private readonly subagents = new ClaudeSubagents(),
|
|
40
|
+
) {}
|
|
41
|
+
|
|
42
|
+
/** Show a call before Moxxy decides on it, unless it is already shown. */
|
|
43
|
+
announce(callId: string, name: string, input: unknown, from: { readonly inSubagent?: boolean } = {}): AgentStepEvent[] {
|
|
44
|
+
// A subagent's call shows under its subagent, from the subagent's message.
|
|
45
|
+
if (from.inSubagent || this.announced.has(callId) || name.startsWith(MOXXY_TOOL_PREFIX)) return [];
|
|
46
|
+
if (this.subagents.ownerOf(callId) !== undefined || this.subagents.isSubagent(callId)) return [];
|
|
47
|
+
this.announced.set(callId, { name, input });
|
|
48
|
+
// The sentence before the call goes first, as part of the work.
|
|
49
|
+
const before = this.mark('tool_use');
|
|
50
|
+
if (this.subagents.isSubagentTool(name)) return [...before, ...this.subagents.started(callId, input)];
|
|
51
|
+
return [...before, { type: 'tool_call', callId, name, input }];
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** The turn ended: a sentence still unmarked is what Claude ended it with. */
|
|
55
|
+
finish(): AgentStepEvent[] {
|
|
56
|
+
return this.mark('end_turn');
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
private mark(stopReason: 'tool_use' | 'end_turn'): AgentStepEvent[] {
|
|
60
|
+
const text = this.unmarked;
|
|
61
|
+
this.unmarked = undefined;
|
|
62
|
+
return text === undefined ? [] : [{ type: 'message', text, stopReason }];
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** The call is done on Moxxy's side, whatever Claude is told: it reads as gone through, not as refused. */
|
|
66
|
+
handOver(callId: string, output: string): AgentStepEvent[] {
|
|
67
|
+
if (this.handedOver.has(callId) || !this.announced.has(callId)) return [];
|
|
68
|
+
this.handedOver.add(callId);
|
|
69
|
+
return [{ type: 'tool_result', callId, ok: true, output }];
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
translate(message: ClaudeMessage): AgentStepEvent[] {
|
|
73
|
+
switch (message.type) {
|
|
74
|
+
case 'system':
|
|
75
|
+
if (isInit(message)) return 'session_id' in message ? this.fromInit(message) : [];
|
|
76
|
+
if (message.subtype === 'task_progress' || message.subtype === 'task_notification') return this.subagents.fromTaskNote(message);
|
|
77
|
+
// Claude reports every change of mode, whoever made it, so the switch follows it at once.
|
|
78
|
+
return isModeChange(message) ? autoApproveEvents(message.permissionMode) : [];
|
|
79
|
+
case 'stream_event':
|
|
80
|
+
if (!isMainThread(message)) return [];
|
|
81
|
+
// The reply's end says how it stopped: a call comes next, or the turn is over.
|
|
82
|
+
if (message.event.type === 'message_delta' && message.event.delta?.stop_reason) {
|
|
83
|
+
return this.mark(message.event.delta.stop_reason === 'tool_use' ? 'tool_use' : 'end_turn');
|
|
84
|
+
}
|
|
85
|
+
return fromDelta(message);
|
|
86
|
+
case 'assistant':
|
|
87
|
+
if (message.error === 'rate_limit' && isMainThread(message)) return [this.limitReached()];
|
|
88
|
+
return isMainThread(message) ? [...this.fromAssistant(message), ...contextUsed(message.message.usage)] : this.fromSubagent(message);
|
|
89
|
+
case 'rate_limit_event':
|
|
90
|
+
this.limit = accountLimitFrom(message.rate_limit_info);
|
|
91
|
+
return [{ type: 'account_limit', limit: this.limit }];
|
|
92
|
+
case 'user':
|
|
93
|
+
return this.fromToolResults(message);
|
|
94
|
+
default:
|
|
95
|
+
return [];
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/** Claude Code's own "You've hit your limit" message: the limit is reached, whatever Claude last reported. */
|
|
100
|
+
private limitReached(): AgentStepEvent {
|
|
101
|
+
return { type: 'account_limit', limit: this.limit ? { ...this.limit, state: 'reached' } : { state: 'reached' } };
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
private fromInit(message: { session_id: string; permissionMode?: ClaudePermissionMode }): AgentStepEvent[] {
|
|
105
|
+
return [{ type: 'session', sessionId: message.session_id }, ...(message.permissionMode ? autoApproveEvents(message.permissionMode) : [])];
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
private fromAssistant(message: { message: { content: ReadonlyArray<ClaudeContentBlock> } }): AgentStepEvent[] {
|
|
109
|
+
const blocks = message.message.content;
|
|
110
|
+
// Claude went on after a sentence it sent on its own: that sentence was part of the work.
|
|
111
|
+
const events: AgentStepEvent[] = blocks.length > 0 ? this.mark('tool_use') : [];
|
|
112
|
+
const thinking = blocks.flatMap((b) => (isThinking(b) && b.thinking ? [b.thinking] : [])).join('\n');
|
|
113
|
+
if (thinking) events.push({ type: 'reasoning', text: thinking });
|
|
114
|
+
const text = blocks.flatMap((b) => (isText(b) ? [b.text] : [])).join('');
|
|
115
|
+
const calls = blocks.filter(isToolUse);
|
|
116
|
+
if (text && calls.length > 0) events.push({ type: 'message', text, stopReason: 'tool_use' });
|
|
117
|
+
else if (text) this.unmarked = text;
|
|
118
|
+
for (const call of calls) {
|
|
119
|
+
if (call.name.startsWith(MOXXY_TOOL_PREFIX)) this.moxxyCalls.add(call.id);
|
|
120
|
+
else events.push(...this.announce(call.id, call.name, call.input));
|
|
121
|
+
}
|
|
122
|
+
return events;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
private fromSubagent(message: { message: { content: ReadonlyArray<ClaudeContentBlock> }; parent_tool_use_id: string | null }): AgentStepEvent[] {
|
|
126
|
+
if (message.parent_tool_use_id === null) return [];
|
|
127
|
+
const blocks = message.message.content;
|
|
128
|
+
const text = blocks.flatMap((b) => (isText(b) ? [b.text] : [])).join('');
|
|
129
|
+
const calls = blocks.filter(isToolUse).filter((call) => !call.name.startsWith(MOXXY_TOOL_PREFIX));
|
|
130
|
+
return this.subagents.fromMessage(message.parent_tool_use_id, text, calls);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
private fromToolResults(message: { message: { content: string | ReadonlyArray<ClaudeContentBlock> }; tool_use_result?: unknown }): AgentStepEvent[] {
|
|
134
|
+
const { content } = message.message;
|
|
135
|
+
if (typeof content === 'string') return [];
|
|
136
|
+
const results = content.filter(isToolResult);
|
|
137
|
+
// The tool's own output object belongs to the message, so it is read only when the message carries one result.
|
|
138
|
+
const diff = results.length === 1 ? this.fileDiffOf(message.tool_use_result) : undefined;
|
|
139
|
+
const events: AgentStepEvent[] = [];
|
|
140
|
+
for (const block of results) {
|
|
141
|
+
const call = this.announced.get(block.tool_use_id);
|
|
142
|
+
if (this.moxxyCalls.has(block.tool_use_id) || this.handedOver.has(block.tool_use_id) || !call) continue;
|
|
143
|
+
const text = resultText(block.content);
|
|
144
|
+
if (this.subagents.isSubagent(block.tool_use_id)) {
|
|
145
|
+
events.push(...this.subagents.fromResult(block.tool_use_id, text, block.is_error === true, results.length === 1 ? message.tool_use_result : undefined));
|
|
146
|
+
continue;
|
|
147
|
+
}
|
|
148
|
+
if (block.is_error) {
|
|
149
|
+
events.push({ type: 'tool_result', callId: block.tool_use_id, ok: false, error: text });
|
|
150
|
+
continue;
|
|
151
|
+
}
|
|
152
|
+
const steps = this.tasks.apply(call.name, call.input, results.length === 1 ? message.tool_use_result : undefined);
|
|
153
|
+
const images = diff || steps ? [] : resultImages(block.content);
|
|
154
|
+
const output =
|
|
155
|
+
steps ? stepListOutput(text, steps)
|
|
156
|
+
: diff ? { forModel: text, display: diff }
|
|
157
|
+
: images.length > 0 ? imageToolOutput(text, images)
|
|
158
|
+
: text;
|
|
159
|
+
events.push({ type: 'tool_result', callId: block.tool_use_id, ok: true, output });
|
|
160
|
+
}
|
|
161
|
+
return events;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/** The diff of what Edit or Write reports: its patch, or for a new file its content. */
|
|
165
|
+
private fileDiffOf(result: unknown): FileDiffDisplay | undefined {
|
|
166
|
+
if (typeof result !== 'object' || result === null) return undefined;
|
|
167
|
+
const report = result as { filePath?: unknown; structuredPatch?: unknown; type?: unknown; content?: unknown };
|
|
168
|
+
if (typeof report.filePath !== 'string' || !Array.isArray(report.structuredPatch)) return undefined;
|
|
169
|
+
const path = diffPathIn(this.cwd, report.filePath);
|
|
170
|
+
const mode = report.type === 'create' ? 'create' : 'update';
|
|
171
|
+
const hunks = report.structuredPatch.filter(isPatchHunk);
|
|
172
|
+
if (hunks.length > 0) return fileDiffFromPatch({ path, mode, hunks });
|
|
173
|
+
if (mode === 'create' && typeof report.content === 'string') return fileDiffFromText({ path, mode, before: '', after: report.content });
|
|
174
|
+
return undefined;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/** Claude's permission mode as the conversation's auto-approve; `undefined` when the mode says nothing about it. */
|
|
179
|
+
export function autoApproveFor(mode: ClaudePermissionMode): boolean | undefined {
|
|
180
|
+
switch (mode) {
|
|
181
|
+
case 'bypassPermissions':
|
|
182
|
+
return true;
|
|
183
|
+
case 'default':
|
|
184
|
+
case 'acceptEdits':
|
|
185
|
+
case 'dontAsk':
|
|
186
|
+
return false;
|
|
187
|
+
default:
|
|
188
|
+
return undefined;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/** What `/goal` without arguments answers, as the state of the goal. */
|
|
193
|
+
export function goalStatusFrom(text: string): AgentGoalStatus | undefined {
|
|
194
|
+
if (/^Goal active\b/.test(text)) return 'active';
|
|
195
|
+
if (/^No goal set\b/.test(text)) return 'complete';
|
|
196
|
+
return undefined;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/** The prompt of one call of the main agent is how full its context is; a turn's result adds every call up. */
|
|
200
|
+
function contextUsed(usage: ClaudeUsage | undefined): AgentStepEvent[] {
|
|
201
|
+
if (!usage) return [];
|
|
202
|
+
const tokens = (usage.input_tokens ?? 0) + (usage.cache_read_input_tokens ?? 0) + (usage.cache_creation_input_tokens ?? 0);
|
|
203
|
+
return tokens > 0 ? [{ type: 'context_used', tokens }] : [];
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
export function toTokenUsage(usage: ClaudeUsage): TokenUsage {
|
|
207
|
+
return {
|
|
208
|
+
inputTokens: usage.input_tokens ?? 0,
|
|
209
|
+
outputTokens: usage.output_tokens ?? 0,
|
|
210
|
+
...(usage.cache_read_input_tokens ? { cacheReadTokens: usage.cache_read_input_tokens } : {}),
|
|
211
|
+
...(usage.cache_creation_input_tokens ? { cacheCreationTokens: usage.cache_creation_input_tokens } : {}),
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/** The person's message as Messages API blocks; `prefix` goes in front of the first text (`/goal `). */
|
|
216
|
+
export function toClaudeContent(prompt: ReadonlyArray<ContentBlock>, prefix = ''): ClaudeUserContent {
|
|
217
|
+
let pending = prefix;
|
|
218
|
+
const blocks: Exclude<ClaudeUserContent, string>[number][] = [];
|
|
219
|
+
for (const block of prompt) {
|
|
220
|
+
if (block.type === 'text') {
|
|
221
|
+
blocks.push({ type: 'text', text: `${pending}${block.text}` });
|
|
222
|
+
pending = '';
|
|
223
|
+
} else if (block.type === 'image' || block.type === 'document') {
|
|
224
|
+
blocks.push({ type: block.type, source: { type: 'base64', media_type: block.mediaType, data: block.data } });
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
if (pending) blocks.unshift({ type: 'text', text: pending.trimEnd() });
|
|
228
|
+
return blocks;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
function fromDelta(message: { event: { type: string; delta?: { type?: string; text?: string; thinking?: string } } }): AgentStepEvent[] {
|
|
232
|
+
const { event } = message;
|
|
233
|
+
if (event.type !== 'content_block_delta' || !event.delta) return [];
|
|
234
|
+
if (event.delta.type === 'text_delta' && event.delta.text) return [{ type: 'text_delta', delta: event.delta.text }];
|
|
235
|
+
if (event.delta.type === 'thinking_delta' && event.delta.thinking) return [{ type: 'reasoning_delta', delta: event.delta.thinking }];
|
|
236
|
+
return [];
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
function isPatchHunk(x: unknown): x is { oldStart: number; newStart: number; lines: string[] } {
|
|
240
|
+
if (typeof x !== 'object' || x === null) return false;
|
|
241
|
+
const hunk = x as { oldStart?: unknown; newStart?: unknown; lines?: unknown };
|
|
242
|
+
return (
|
|
243
|
+
typeof hunk.oldStart === 'number' &&
|
|
244
|
+
typeof hunk.newStart === 'number' &&
|
|
245
|
+
Array.isArray(hunk.lines) &&
|
|
246
|
+
hunk.lines.every((line) => typeof line === 'string')
|
|
247
|
+
);
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/** The images of a result (a screenshot, an image file Claude read), in order. */
|
|
251
|
+
function resultImages(content: string | ReadonlyArray<{ type: string }> | undefined): ToolImage[] {
|
|
252
|
+
if (typeof content === 'string' || !content) return [];
|
|
253
|
+
return content.flatMap((part) => {
|
|
254
|
+
if (part.type !== 'image') return [];
|
|
255
|
+
const source = (part as { source?: { type?: unknown; media_type?: unknown; data?: unknown } }).source;
|
|
256
|
+
if (source && source.type === 'base64' && typeof source.media_type === 'string' && typeof source.data === 'string') {
|
|
257
|
+
return [{ mediaType: source.media_type, base64: source.data }];
|
|
258
|
+
}
|
|
259
|
+
return [];
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
function resultText(content: string | ReadonlyArray<{ type: string; text?: string }> | undefined): string {
|
|
264
|
+
if (typeof content === 'string') return content;
|
|
265
|
+
if (!content) return '';
|
|
266
|
+
return content.flatMap((part) => (part.type === 'text' && part.text ? [part.text] : [])).join('\n');
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
function isInit(message: { subtype?: string }): message is { subtype: 'init'; session_id: string; permissionMode?: ClaudePermissionMode } {
|
|
270
|
+
return message.subtype === 'init';
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
/** A status message that names the mode Claude now runs in. */
|
|
274
|
+
export function isModeChange(message: ClaudeMessage): message is ClaudeMessage & { readonly subtype: 'status'; readonly permissionMode: ClaudePermissionMode } {
|
|
275
|
+
return message.type === 'system' && message.subtype === 'status' && typeof (message as { permissionMode?: unknown }).permissionMode === 'string';
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
function autoApproveEvents(mode: ClaudePermissionMode): AgentStepEvent[] {
|
|
279
|
+
const enabled = autoApproveFor(mode);
|
|
280
|
+
return enabled === undefined ? [] : [{ type: 'auto_approve', enabled }];
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
function isMainThread(message: { parent_tool_use_id?: string | null }): boolean {
|
|
284
|
+
return message.parent_tool_use_id === null || message.parent_tool_use_id === undefined;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
function isText(block: ClaudeContentBlock): block is { type: 'text'; text: string } {
|
|
288
|
+
return block.type === 'text';
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
function isThinking(block: ClaudeContentBlock): block is { type: 'thinking'; thinking: string } {
|
|
292
|
+
return block.type === 'thinking';
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
function isToolUse(block: ClaudeContentBlock): block is { type: 'tool_use'; id: string; name: string; input: unknown } {
|
|
296
|
+
return block.type === 'tool_use';
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
function isToolResult(block: ClaudeContentBlock): block is {
|
|
300
|
+
type: 'tool_result';
|
|
301
|
+
tool_use_id: string;
|
|
302
|
+
content?: string | ReadonlyArray<{ type: string; text?: string }>;
|
|
303
|
+
is_error?: boolean;
|
|
304
|
+
} {
|
|
305
|
+
return block.type === 'tool_result';
|
|
306
|
+
}
|
package/dist/process.d.ts
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { type ChildProcessWithoutNullStreams } from 'node:child_process';
|
|
2
|
-
export interface ClaudeSpawnOptions {
|
|
3
|
-
readonly env: NodeJS.ProcessEnv;
|
|
4
|
-
readonly cwd: string;
|
|
5
|
-
}
|
|
6
|
-
export type ClaudeSpawn = (executable: string, args: ReadonlyArray<string>, options: ClaudeSpawnOptions) => ChildProcessWithoutNullStreams;
|
|
7
|
-
export type ClaudeProcessFailure = 'aborted' | 'startup_timeout' | 'idle_timeout' | 'protocol';
|
|
8
|
-
export declare class ClaudeProcessError extends Error {
|
|
9
|
-
readonly failure: ClaudeProcessFailure;
|
|
10
|
-
constructor(failure: ClaudeProcessFailure, message: string);
|
|
11
|
-
}
|
|
12
|
-
export interface ClaudeProcessOptions {
|
|
13
|
-
readonly executable: string;
|
|
14
|
-
readonly model: string;
|
|
15
|
-
readonly prompt: string;
|
|
16
|
-
readonly cwd: string;
|
|
17
|
-
readonly nativeTools: boolean;
|
|
18
|
-
/** Enable only Claude Code's native WebSearch when nativeTools is false. */
|
|
19
|
-
readonly webSearch?: boolean;
|
|
20
|
-
readonly permissionMode?: string;
|
|
21
|
-
readonly allowedTools: ReadonlyArray<string>;
|
|
22
|
-
readonly signal?: AbortSignal;
|
|
23
|
-
readonly spawn?: ClaudeSpawn;
|
|
24
|
-
readonly startupTimeoutMs?: number;
|
|
25
|
-
readonly idleTimeoutMs?: number;
|
|
26
|
-
readonly maxStderrChars?: number;
|
|
27
|
-
readonly maxRecordChars?: number;
|
|
28
|
-
}
|
|
29
|
-
export interface ClaudeProcessResult {
|
|
30
|
-
readonly exitCode: number;
|
|
31
|
-
readonly stderr: string;
|
|
32
|
-
}
|
|
33
|
-
export declare function runClaudeProcess(options: ClaudeProcessOptions): AsyncGenerator<string, ClaudeProcessResult>;
|
|
34
|
-
//# sourceMappingURL=process.d.ts.map
|
package/dist/process.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"process.d.ts","sourceRoot":"","sources":["../src/process.ts"],"names":[],"mappings":"AAAA,OAAO,EAAS,KAAK,8BAA8B,EAAE,MAAM,oBAAoB,CAAC;AAEhF,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC,UAAU,CAAC;IAChC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,MAAM,WAAW,GAAG,CACxB,UAAU,EAAE,MAAM,EAClB,IAAI,EAAE,aAAa,CAAC,MAAM,CAAC,EAC3B,OAAO,EAAE,kBAAkB,KACxB,8BAA8B,CAAC;AAEpC,MAAM,MAAM,oBAAoB,GAAG,SAAS,GAAG,iBAAiB,GAAG,cAAc,GAAG,UAAU,CAAC;AAE/F,qBAAa,kBAAmB,SAAQ,KAAK;IAC/B,QAAQ,CAAC,OAAO,EAAE,oBAAoB;gBAA7B,OAAO,EAAE,oBAAoB,EAAE,OAAO,EAAE,MAAM;CAIpE;AAED,MAAM,WAAW,oBAAoB;IACnC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,WAAW,EAAE,OAAO,CAAC;IAC9B,4EAA4E;IAC5E,QAAQ,CAAC,SAAS,CAAC,EAAE,OAAO,CAAC;IAC7B,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,CAAC;IACjC,QAAQ,CAAC,YAAY,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;IAC7C,QAAQ,CAAC,MAAM,CAAC,EAAE,WAAW,CAAC;IAC9B,QAAQ,CAAC,KAAK,CAAC,EAAE,WAAW,CAAC;IAC7B,QAAQ,CAAC,gBAAgB,CAAC,EAAE,MAAM,CAAC;IACnC,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,CAAC;IACjC,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,CAAC;CAClC;AAED,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB;AAUD,wBAAuB,gBAAgB,CACrC,OAAO,EAAE,oBAAoB,GAC5B,cAAc,CAAC,MAAM,EAAE,mBAAmB,CAAC,CAsJ7C"}
|
package/dist/process.js
DELETED
|
@@ -1,197 +0,0 @@
|
|
|
1
|
-
import { spawn } from 'node:child_process';
|
|
2
|
-
export class ClaudeProcessError extends Error {
|
|
3
|
-
failure;
|
|
4
|
-
constructor(failure, message) {
|
|
5
|
-
super(message);
|
|
6
|
-
this.failure = failure;
|
|
7
|
-
this.name = 'ClaudeProcessError';
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
const DEFAULT_STARTUP_TIMEOUT_MS = 30_000;
|
|
11
|
-
const DEFAULT_IDLE_TIMEOUT_MS = 120_000;
|
|
12
|
-
const DEFAULT_MAX_STDERR_CHARS = 2048;
|
|
13
|
-
const DEFAULT_MAX_RECORD_CHARS = 64 * 1024;
|
|
14
|
-
const KILL_GRACE_MS = 1_000;
|
|
15
|
-
export async function* runClaudeProcess(options) {
|
|
16
|
-
const args = buildArgs(options);
|
|
17
|
-
const env = { ...process.env };
|
|
18
|
-
// Claude refuses nested interactive sessions. Moxxy is the parent here, not a
|
|
19
|
-
// nested Claude Code instance, even when it was launched from Claude Code.
|
|
20
|
-
delete env.CLAUDECODE;
|
|
21
|
-
delete env.CLAUDE_CODE_ENTRYPOINT;
|
|
22
|
-
const spawnImpl = options.spawn ?? ((file, childArgs, childOptions) => spawn(file, [...childArgs], {
|
|
23
|
-
stdio: ['pipe', 'pipe', 'pipe'], env: childOptions.env, cwd: childOptions.cwd,
|
|
24
|
-
}));
|
|
25
|
-
const child = spawnImpl(options.executable, args, { env, cwd: options.cwd });
|
|
26
|
-
const queue = [];
|
|
27
|
-
let wake;
|
|
28
|
-
let stdout = '';
|
|
29
|
-
let stderr = '';
|
|
30
|
-
let closed = false;
|
|
31
|
-
let failure;
|
|
32
|
-
let timer;
|
|
33
|
-
let killTimer;
|
|
34
|
-
let terminationRequested = false;
|
|
35
|
-
const startupTimeoutMs = positive(options.startupTimeoutMs, DEFAULT_STARTUP_TIMEOUT_MS);
|
|
36
|
-
const idleTimeoutMs = positive(options.idleTimeoutMs, DEFAULT_IDLE_TIMEOUT_MS);
|
|
37
|
-
const maxStderrChars = positive(options.maxStderrChars, DEFAULT_MAX_STDERR_CHARS);
|
|
38
|
-
const maxRecordChars = positive(options.maxRecordChars, DEFAULT_MAX_RECORD_CHARS);
|
|
39
|
-
const push = (item) => {
|
|
40
|
-
queue.push(item);
|
|
41
|
-
const notify = wake;
|
|
42
|
-
wake = undefined;
|
|
43
|
-
notify?.();
|
|
44
|
-
};
|
|
45
|
-
const clearWatchdog = () => {
|
|
46
|
-
if (timer)
|
|
47
|
-
clearTimeout(timer);
|
|
48
|
-
timer = undefined;
|
|
49
|
-
};
|
|
50
|
-
const terminate = () => {
|
|
51
|
-
if (closed || child.exitCode !== null || child.signalCode !== null || terminationRequested)
|
|
52
|
-
return;
|
|
53
|
-
terminationRequested = true;
|
|
54
|
-
child.kill('SIGTERM');
|
|
55
|
-
killTimer = setTimeout(() => {
|
|
56
|
-
killTimer = undefined;
|
|
57
|
-
if (!closed && child.exitCode === null && child.signalCode === null)
|
|
58
|
-
child.kill('SIGKILL');
|
|
59
|
-
}, KILL_GRACE_MS);
|
|
60
|
-
killTimer.unref?.();
|
|
61
|
-
};
|
|
62
|
-
const fail = (error) => {
|
|
63
|
-
if (failure)
|
|
64
|
-
return;
|
|
65
|
-
failure = error;
|
|
66
|
-
clearWatchdog();
|
|
67
|
-
terminate();
|
|
68
|
-
// Cancellation/failure is terminal: discard records received but not yet
|
|
69
|
-
// consumed so no text can be emitted after the single error event.
|
|
70
|
-
queue.length = 0;
|
|
71
|
-
push({ error });
|
|
72
|
-
};
|
|
73
|
-
const arm = (kind) => {
|
|
74
|
-
clearWatchdog();
|
|
75
|
-
const delay = kind === 'startup' ? startupTimeoutMs : idleTimeoutMs;
|
|
76
|
-
timer = setTimeout(() => fail(new ClaudeProcessError(kind === 'startup' ? 'startup_timeout' : 'idle_timeout', kind === 'startup'
|
|
77
|
-
? `Claude CLI did not produce a stream record within ${delay}ms`
|
|
78
|
-
: `Claude CLI stream was idle for ${delay}ms`)), delay);
|
|
79
|
-
timer.unref?.();
|
|
80
|
-
};
|
|
81
|
-
const onAbort = () => fail(new ClaudeProcessError('aborted', 'Claude CLI request aborted'));
|
|
82
|
-
child.stdin.on('error', (error) => {
|
|
83
|
-
// EPIPE commonly follows cancellation; the abort error is the useful one.
|
|
84
|
-
if (!failure)
|
|
85
|
-
fail(error);
|
|
86
|
-
});
|
|
87
|
-
child.stderr.setEncoding('utf8');
|
|
88
|
-
child.stderr.on('data', (chunk) => {
|
|
89
|
-
if (stderr.length < maxStderrChars)
|
|
90
|
-
stderr += chunk.slice(0, maxStderrChars - stderr.length);
|
|
91
|
-
});
|
|
92
|
-
child.stdout.setEncoding('utf8');
|
|
93
|
-
child.stdout.on('data', (chunk) => {
|
|
94
|
-
if (failure)
|
|
95
|
-
return;
|
|
96
|
-
stdout += chunk;
|
|
97
|
-
if (stdout.length > maxRecordChars && !stdout.includes('\n')) {
|
|
98
|
-
fail(new ClaudeProcessError('protocol', `Claude CLI emitted a stream record larger than ${maxRecordChars} characters`));
|
|
99
|
-
return;
|
|
100
|
-
}
|
|
101
|
-
let newline = stdout.indexOf('\n');
|
|
102
|
-
while (newline >= 0 && !failure) {
|
|
103
|
-
const line = stdout.slice(0, newline).replace(/\r$/, '');
|
|
104
|
-
stdout = stdout.slice(newline + 1);
|
|
105
|
-
if (line.length > maxRecordChars) {
|
|
106
|
-
fail(new ClaudeProcessError('protocol', `Claude CLI emitted a stream record larger than ${maxRecordChars} characters`));
|
|
107
|
-
return;
|
|
108
|
-
}
|
|
109
|
-
if (line.trim()) {
|
|
110
|
-
arm('idle');
|
|
111
|
-
push({ line });
|
|
112
|
-
}
|
|
113
|
-
newline = stdout.indexOf('\n');
|
|
114
|
-
}
|
|
115
|
-
if (stdout.length > maxRecordChars) {
|
|
116
|
-
fail(new ClaudeProcessError('protocol', `Claude CLI emitted a stream record larger than ${maxRecordChars} characters`));
|
|
117
|
-
}
|
|
118
|
-
});
|
|
119
|
-
const completion = new Promise((resolve) => {
|
|
120
|
-
child.once('error', (error) => {
|
|
121
|
-
fail(error);
|
|
122
|
-
});
|
|
123
|
-
child.once('close', (code) => {
|
|
124
|
-
closed = true;
|
|
125
|
-
clearWatchdog();
|
|
126
|
-
if (killTimer)
|
|
127
|
-
clearTimeout(killTimer);
|
|
128
|
-
killTimer = undefined;
|
|
129
|
-
if (!failure && stdout.trim()) {
|
|
130
|
-
if (stdout.length > maxRecordChars) {
|
|
131
|
-
fail(new ClaudeProcessError('protocol', `Claude CLI emitted a stream record larger than ${maxRecordChars} characters`));
|
|
132
|
-
}
|
|
133
|
-
else {
|
|
134
|
-
// A final JSON record need not end in a newline.
|
|
135
|
-
push({ line: stdout.replace(/\r$/, '') });
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
push({ done: true });
|
|
139
|
-
resolve(code ?? 1);
|
|
140
|
-
});
|
|
141
|
-
});
|
|
142
|
-
options.signal?.addEventListener('abort', onAbort, { once: true });
|
|
143
|
-
if (options.signal?.aborted)
|
|
144
|
-
onAbort();
|
|
145
|
-
else
|
|
146
|
-
arm('startup');
|
|
147
|
-
if (!failure)
|
|
148
|
-
child.stdin.end(options.prompt, 'utf8');
|
|
149
|
-
try {
|
|
150
|
-
while (true) {
|
|
151
|
-
if (queue.length === 0)
|
|
152
|
-
await new Promise((resolve) => { wake = resolve; });
|
|
153
|
-
const item = queue.shift();
|
|
154
|
-
if (!item)
|
|
155
|
-
continue;
|
|
156
|
-
if ('error' in item)
|
|
157
|
-
throw item.error;
|
|
158
|
-
if ('done' in item)
|
|
159
|
-
break;
|
|
160
|
-
yield item.line;
|
|
161
|
-
}
|
|
162
|
-
const exitCode = await completion;
|
|
163
|
-
return { exitCode, stderr: stderr.trim() };
|
|
164
|
-
}
|
|
165
|
-
finally {
|
|
166
|
-
clearWatchdog();
|
|
167
|
-
options.signal?.removeEventListener('abort', onAbort);
|
|
168
|
-
terminate();
|
|
169
|
-
try {
|
|
170
|
-
await completion;
|
|
171
|
-
}
|
|
172
|
-
catch { /* surfaced through the queue */ }
|
|
173
|
-
if (killTimer)
|
|
174
|
-
clearTimeout(killTimer);
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
function buildArgs(options) {
|
|
178
|
-
const args = ['--print', '--verbose', '--output-format', 'stream-json', '--include-partial-messages', '--model', options.model];
|
|
179
|
-
if (options.nativeTools) {
|
|
180
|
-
args.push('--tools', ...(options.allowedTools.length > 0 ? options.allowedTools : ['']));
|
|
181
|
-
if (options.permissionMode)
|
|
182
|
-
args.push('--permission-mode', options.permissionMode);
|
|
183
|
-
if (options.allowedTools.length > 0)
|
|
184
|
-
args.push('--allowedTools', ...options.allowedTools);
|
|
185
|
-
}
|
|
186
|
-
else if (options.webSearch) {
|
|
187
|
-
args.splice(args.length - 2, 0, '--tools', 'WebSearch', '--allowedTools', 'WebSearch');
|
|
188
|
-
}
|
|
189
|
-
else {
|
|
190
|
-
args.splice(args.length - 2, 0, '--tools', '');
|
|
191
|
-
}
|
|
192
|
-
return args;
|
|
193
|
-
}
|
|
194
|
-
function positive(value, fallback) {
|
|
195
|
-
return value !== undefined && value > 0 ? value : fallback;
|
|
196
|
-
}
|
|
197
|
-
//# sourceMappingURL=process.js.map
|
package/dist/process.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"process.js","sourceRoot":"","sources":["../src/process.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAuC,MAAM,oBAAoB,CAAC;AAehF,MAAM,OAAO,kBAAmB,SAAQ,KAAK;IACtB;IAArB,YAAqB,OAA6B,EAAE,OAAe;QACjE,KAAK,CAAC,OAAO,CAAC,CAAC;QADI,YAAO,GAAP,OAAO,CAAsB;QAEhD,IAAI,CAAC,IAAI,GAAG,oBAAoB,CAAC;IACnC,CAAC;CACF;AAyBD,MAAM,0BAA0B,GAAG,MAAM,CAAC;AAC1C,MAAM,uBAAuB,GAAG,OAAO,CAAC;AACxC,MAAM,wBAAwB,GAAG,IAAI,CAAC;AACtC,MAAM,wBAAwB,GAAG,EAAE,GAAG,IAAI,CAAC;AAC3C,MAAM,aAAa,GAAG,KAAK,CAAC;AAI5B,MAAM,CAAC,KAAK,SAAS,CAAC,CAAC,gBAAgB,CACrC,OAA6B;IAE7B,MAAM,IAAI,GAAG,SAAS,CAAC,OAAO,CAAC,CAAC;IAChC,MAAM,GAAG,GAAG,EAAE,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC;IAC/B,8EAA8E;IAC9E,2EAA2E;IAC3E,OAAO,GAAG,CAAC,UAAU,CAAC;IACtB,OAAO,GAAG,CAAC,sBAAsB,CAAC;IAClC,MAAM,SAAS,GAAG,OAAO,CAAC,KAAK,IAAI,CAAC,CAAC,IAAI,EAAE,SAAS,EAAE,YAAY,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,GAAG,SAAS,CAAC,EAAE;QACjG,KAAK,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,GAAG,EAAE,YAAY,CAAC,GAAG,EAAE,GAAG,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C;IACzF,CAAC;SAAM,CAAC;QACN,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,EAAE,SAAS,EAAE,EAAE,CAAC,CAAC;IACjD,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED,SAAS,QAAQ,CAAC,KAAyB,EAAE,QAAgB;IAC3D,OAAO,KAAK,KAAK,SAAS,IAAI,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,QAAQ,CAAC;AAC7D,CAAC"}
|
package/dist/protocol.d.ts
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import type { ProviderEvent, ProviderRequest } from '@moxxy/sdk';
|
|
2
|
-
interface ProtocolState {
|
|
3
|
-
started: boolean;
|
|
4
|
-
ended: boolean;
|
|
5
|
-
/** Current streamed block. Native tool records are consumed by Claude itself. */
|
|
6
|
-
blockType?: 'text' | 'thinking' | 'tool_use' | 'tool_result';
|
|
7
|
-
stopReason: 'end_turn' | 'max_tokens' | 'stop_sequence' | 'error';
|
|
8
|
-
inputTokens?: number;
|
|
9
|
-
outputTokens?: number;
|
|
10
|
-
/** Present when moxxy tools were offered; streamed text is scanned for a call block. */
|
|
11
|
-
toolCalls?: ToolCallScan;
|
|
12
|
-
}
|
|
13
|
-
interface ToolCallScan {
|
|
14
|
-
/** Trailing text withheld because it may be the start of TOOL_CALLS_OPEN. */
|
|
15
|
-
held: string;
|
|
16
|
-
/** Text after TOOL_CALLS_OPEN once a block has started. */
|
|
17
|
-
block?: string;
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Projects the complete provider-neutral conversation into one stateless CLI
|
|
21
|
-
* prompt. Historical tool records are deliberately textual: the CLI can use
|
|
22
|
-
* their information, but cannot mistake them for a new native tool request.
|
|
23
|
-
*/
|
|
24
|
-
export declare function serializeClaudePrompt(req: ProviderRequest): string;
|
|
25
|
-
export declare function createProtocolState(opts?: {
|
|
26
|
-
readonly toolCalls?: boolean;
|
|
27
|
-
}): ProtocolState;
|
|
28
|
-
export declare function parseClaudeRecord(line: string, state: ProtocolState): ProviderEvent[];
|
|
29
|
-
export {};
|
|
30
|
-
//# sourceMappingURL=protocol.d.ts.map
|
package/dist/protocol.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"protocol.d.ts","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAgB,aAAa,EAAE,eAAe,EAAW,MAAM,YAAY,CAAC;AAIxF,UAAU,aAAa;IACrB,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,EAAE,OAAO,CAAC;IACf,iFAAiF;IACjF,SAAS,CAAC,EAAE,MAAM,GAAG,UAAU,GAAG,UAAU,GAAG,aAAa,CAAC;IAC7D,UAAU,EAAE,UAAU,GAAG,YAAY,GAAG,eAAe,GAAG,OAAO,CAAC;IAClE,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,wFAAwF;IACxF,SAAS,CAAC,EAAE,YAAY,CAAC;CAC1B;AAED,UAAU,YAAY;IACpB,6EAA6E;IAC7E,IAAI,EAAE,MAAM,CAAC;IACb,2DAA2D;IAC3D,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAcD;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,eAAe,GAAG,MAAM,CAyBlE;AAwGD,wBAAgB,mBAAmB,CAAC,IAAI,GAAE;IAAE,QAAQ,CAAC,SAAS,CAAC,EAAE,OAAO,CAAA;CAAO,GAAG,aAAa,CAO9F;AAkFD,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,aAAa,GAAG,aAAa,EAAE,CAkBrF"}
|