@ank1015/providers 0.0.36 → 0.0.37
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/debug-conversation.d.ts +2 -0
- package/dist/debug-conversation.d.ts.map +1 -0
- package/dist/debug-conversation.js +98 -0
- package/dist/debug-conversation.js.map +1 -0
- package/dist/debug-minimal-test.d.ts +2 -0
- package/dist/debug-minimal-test.d.ts.map +1 -0
- package/dist/debug-minimal-test.js +47 -0
- package/dist/debug-minimal-test.js.map +1 -0
- package/dist/debug-sdk-tool.d.ts +2 -0
- package/dist/debug-sdk-tool.d.ts.map +1 -0
- package/dist/debug-sdk-tool.js +99 -0
- package/dist/debug-sdk-tool.js.map +1 -0
- package/dist/debug-sdk.d.ts +2 -0
- package/dist/debug-sdk.d.ts.map +1 -0
- package/dist/debug-sdk.js +59 -0
- package/dist/debug-sdk.js.map +1 -0
- package/dist/debug-session-flow.d.ts +2 -0
- package/dist/debug-session-flow.d.ts.map +1 -0
- package/dist/debug-session-flow.js +134 -0
- package/dist/debug-session-flow.js.map +1 -0
- package/dist/debug-session-hack.d.ts +2 -0
- package/dist/debug-session-hack.d.ts.map +1 -0
- package/dist/debug-session-hack.js +143 -0
- package/dist/debug-session-hack.js.map +1 -0
- package/dist/llm.d.ts.map +1 -1
- package/dist/llm.js +10 -1
- package/dist/llm.js.map +1 -1
- package/dist/models.generated.d.ts +19 -0
- package/dist/models.generated.d.ts.map +1 -1
- package/dist/models.generated.js +19 -0
- package/dist/models.generated.js.map +1 -1
- package/dist/providers/anthropic-agents-sdk/complete.d.ts +3 -0
- package/dist/providers/anthropic-agents-sdk/complete.d.ts.map +1 -0
- package/dist/providers/anthropic-agents-sdk/complete.js +246 -0
- package/dist/providers/anthropic-agents-sdk/complete.js.map +1 -0
- package/dist/providers/anthropic-agents-sdk/index.d.ts +4 -0
- package/dist/providers/anthropic-agents-sdk/index.d.ts.map +1 -0
- package/dist/providers/anthropic-agents-sdk/index.js +4 -0
- package/dist/providers/anthropic-agents-sdk/index.js.map +1 -0
- package/dist/providers/anthropic-agents-sdk/session.d.ts +37 -0
- package/dist/providers/anthropic-agents-sdk/session.d.ts.map +1 -0
- package/dist/providers/anthropic-agents-sdk/session.js +188 -0
- package/dist/providers/anthropic-agents-sdk/session.js.map +1 -0
- package/dist/providers/anthropic-agents-sdk/stream.d.ts +3 -0
- package/dist/providers/anthropic-agents-sdk/stream.d.ts.map +1 -0
- package/dist/providers/anthropic-agents-sdk/stream.js +402 -0
- package/dist/providers/anthropic-agents-sdk/stream.js.map +1 -0
- package/dist/providers/anthropic-agents-sdk/types.d.ts +22 -0
- package/dist/providers/anthropic-agents-sdk/types.d.ts.map +1 -0
- package/dist/providers/anthropic-agents-sdk/types.js +3 -0
- package/dist/providers/anthropic-agents-sdk/types.js.map +1 -0
- package/dist/providers/anthropic-agents-sdk/utils.d.ts +39 -0
- package/dist/providers/anthropic-agents-sdk/utils.d.ts.map +1 -0
- package/dist/providers/anthropic-agents-sdk/utils.js +251 -0
- package/dist/providers/anthropic-agents-sdk/utils.js.map +1 -0
- package/dist/providers/google/utils.d.ts.map +1 -1
- package/dist/providers/google/utils.js +2 -0
- package/dist/providers/google/utils.js.map +1 -1
- package/dist/providers/google-interactions/complete.d.ts +3 -0
- package/dist/providers/google-interactions/complete.d.ts.map +1 -0
- package/dist/providers/google-interactions/complete.js +63 -0
- package/dist/providers/google-interactions/complete.js.map +1 -0
- package/dist/providers/google-interactions/index.d.ts +5 -0
- package/dist/providers/google-interactions/index.d.ts.map +1 -0
- package/dist/providers/google-interactions/index.js +4 -0
- package/dist/providers/google-interactions/index.js.map +1 -0
- package/dist/providers/google-interactions/poll.d.ts +59 -0
- package/dist/providers/google-interactions/poll.d.ts.map +1 -0
- package/dist/providers/google-interactions/poll.js +161 -0
- package/dist/providers/google-interactions/poll.js.map +1 -0
- package/dist/providers/google-interactions/stream.d.ts +3 -0
- package/dist/providers/google-interactions/stream.d.ts.map +1 -0
- package/dist/providers/google-interactions/stream.js +242 -0
- package/dist/providers/google-interactions/stream.js.map +1 -0
- package/dist/providers/google-interactions/types.d.ts +10 -0
- package/dist/providers/google-interactions/types.d.ts.map +1 -0
- package/dist/providers/google-interactions/types.js +2 -0
- package/dist/providers/google-interactions/types.js.map +1 -0
- package/dist/providers/google-interactions/utils.d.ts +61 -0
- package/dist/providers/google-interactions/utils.d.ts.map +1 -0
- package/dist/providers/google-interactions/utils.js +252 -0
- package/dist/providers/google-interactions/utils.js.map +1 -0
- package/dist/providers/zai/complete.d.ts +3 -0
- package/dist/providers/zai/complete.d.ts.map +1 -0
- package/dist/providers/zai/complete.js +58 -0
- package/dist/providers/zai/complete.js.map +1 -0
- package/dist/providers/zai/index.d.ts +5 -0
- package/dist/providers/zai/index.d.ts.map +1 -0
- package/dist/providers/zai/index.js +4 -0
- package/dist/providers/zai/index.js.map +1 -0
- package/dist/providers/zai/stream.d.ts +3 -0
- package/dist/providers/zai/stream.d.ts.map +1 -0
- package/dist/providers/zai/stream.js +321 -0
- package/dist/providers/zai/stream.js.map +1 -0
- package/dist/providers/zai/types.d.ts +13 -0
- package/dist/providers/zai/types.d.ts.map +1 -0
- package/dist/providers/zai/types.js +2 -0
- package/dist/providers/zai/types.js.map +1 -0
- package/dist/providers/zai/utils.d.ts +19 -0
- package/dist/providers/zai/utils.d.ts.map +1 -0
- package/dist/providers/zai/utils.js +253 -0
- package/dist/providers/zai/utils.js.map +1 -0
- package/dist/test-sdk-direct.d.ts +2 -0
- package/dist/test-sdk-direct.d.ts.map +1 -0
- package/dist/test-sdk-direct.js +41 -0
- package/dist/test-sdk-direct.js.map +1 -0
- package/dist/test.d.ts +2 -0
- package/dist/test.d.ts.map +1 -0
- package/dist/test.js +213 -0
- package/dist/test.js.map +1 -0
- package/dist/types.d.ts +4 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +1 -1
- package/dist/types.js.map +1 -1
- package/dist/utils/oauth/google-antigravity.d.ts +25 -0
- package/dist/utils/oauth/google-antigravity.d.ts.map +1 -0
- package/dist/utils/oauth/google-antigravity.js +337 -0
- package/dist/utils/oauth/google-antigravity.js.map +1 -0
- package/dist/utils/oauth/pkce.d.ts +13 -0
- package/dist/utils/oauth/pkce.d.ts.map +1 -0
- package/dist/utils/oauth/pkce.js +31 -0
- package/dist/utils/oauth/pkce.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import * as fs from "fs";
|
|
2
|
+
import * as path from "path";
|
|
3
|
+
import { randomUUID } from "crypto";
|
|
4
|
+
import { SDK_SESSION_DIR } from "./types.js";
|
|
5
|
+
/**
|
|
6
|
+
* Gets the SDK's actual session directory path.
|
|
7
|
+
* The SDK stores sessions in ~/.claude/projects/{sanitized-cwd}/
|
|
8
|
+
* where sanitized-cwd replaces / with -
|
|
9
|
+
*/
|
|
10
|
+
export function getSdkSessionDir() {
|
|
11
|
+
// Resolve the cwd to handle symlinks (e.g., /tmp -> /private/tmp on macOS)
|
|
12
|
+
const resolvedCwd = fs.realpathSync(SDK_SESSION_DIR);
|
|
13
|
+
const sanitizedCwd = resolvedCwd.replace(/\//g, '-');
|
|
14
|
+
const homeDir = process.env.HOME || '~';
|
|
15
|
+
return path.join(homeDir, '.claude', 'projects', sanitizedCwd);
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Ensures the SDK session directory exists.
|
|
19
|
+
*/
|
|
20
|
+
export function ensureSessionDir() {
|
|
21
|
+
// Ensure our working directory exists (for SDK's cwd option)
|
|
22
|
+
if (!fs.existsSync(SDK_SESSION_DIR)) {
|
|
23
|
+
fs.mkdirSync(SDK_SESSION_DIR, { recursive: true });
|
|
24
|
+
}
|
|
25
|
+
// Note: SDK creates its own session dir, we don't need to create it
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Gets the JSONL file path for a session (SDK's actual location).
|
|
29
|
+
*/
|
|
30
|
+
export function getSessionFilePath(sessionId) {
|
|
31
|
+
return path.join(getSdkSessionDir(), `${sessionId}.jsonl`);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Appends a tool result to the session JSONL file.
|
|
35
|
+
* This injects the tool result into the SDK's session history so it can be resumed.
|
|
36
|
+
*/
|
|
37
|
+
export function appendToolResultToSession(sessionId, toolUseId, result, parentUuid, isError = false) {
|
|
38
|
+
ensureSessionDir();
|
|
39
|
+
const jsonlPath = getSessionFilePath(sessionId);
|
|
40
|
+
// Use the resolved cwd to match what the SDK uses
|
|
41
|
+
const resolvedCwd = fs.realpathSync(SDK_SESSION_DIR);
|
|
42
|
+
const uuid = randomUUID();
|
|
43
|
+
const entry = {
|
|
44
|
+
parentUuid,
|
|
45
|
+
isSidechain: false,
|
|
46
|
+
userType: "external",
|
|
47
|
+
cwd: resolvedCwd,
|
|
48
|
+
sessionId,
|
|
49
|
+
version: "2.1.3",
|
|
50
|
+
type: "user",
|
|
51
|
+
message: {
|
|
52
|
+
role: "user",
|
|
53
|
+
content: [{
|
|
54
|
+
tool_use_id: toolUseId,
|
|
55
|
+
type: "tool_result",
|
|
56
|
+
content: result, // Must be a string, not an array
|
|
57
|
+
is_error: isError
|
|
58
|
+
}]
|
|
59
|
+
},
|
|
60
|
+
uuid,
|
|
61
|
+
timestamp: new Date().toISOString(),
|
|
62
|
+
toolUseResult: result, // Match real session format
|
|
63
|
+
sourceToolAssistantUUID: parentUuid
|
|
64
|
+
};
|
|
65
|
+
fs.appendFileSync(jsonlPath, JSON.stringify(entry) + '\n');
|
|
66
|
+
return uuid;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Looks for SDK session metadata in the context messages.
|
|
70
|
+
* Returns the metadata from the most recent assistant message that has tool calls
|
|
71
|
+
* and corresponding tool results that need to be injected.
|
|
72
|
+
*/
|
|
73
|
+
export function findSessionToResume(context) {
|
|
74
|
+
// Find the last assistant message with sdkMetadata
|
|
75
|
+
const messages = context.messages;
|
|
76
|
+
for (let i = messages.length - 1; i >= 0; i--) {
|
|
77
|
+
const msg = messages[i];
|
|
78
|
+
if (msg.role === 'assistant') {
|
|
79
|
+
const assistantMsg = msg;
|
|
80
|
+
if (assistantMsg.sdkMetadata) {
|
|
81
|
+
// Collect all tool results that come after this assistant message
|
|
82
|
+
const toolResults = [];
|
|
83
|
+
for (let j = i + 1; j < messages.length; j++) {
|
|
84
|
+
if (messages[j].role === 'toolResult') {
|
|
85
|
+
toolResults.push(messages[j]);
|
|
86
|
+
}
|
|
87
|
+
else if (messages[j].role === 'user') {
|
|
88
|
+
// Stop at the next user message - that's a new turn
|
|
89
|
+
break;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
if (toolResults.length > 0) {
|
|
93
|
+
return {
|
|
94
|
+
metadata: assistantMsg.sdkMetadata,
|
|
95
|
+
toolResults
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Replaces the SDK's placeholder tool result content with actual results in-place.
|
|
105
|
+
* This preserves the parentUuid chain which is critical for SDK to traverse history.
|
|
106
|
+
*
|
|
107
|
+
* We modify entries in-place rather than removing them to avoid breaking the
|
|
108
|
+
* parent chain that the SDK uses to reconstruct conversation history.
|
|
109
|
+
*/
|
|
110
|
+
function replaceToolResultsInPlace(sessionId, toolResultMap) {
|
|
111
|
+
const jsonlPath = getSessionFilePath(sessionId);
|
|
112
|
+
if (!fs.existsSync(jsonlPath)) {
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
const content = fs.readFileSync(jsonlPath, 'utf-8');
|
|
116
|
+
const lines = content.trim().split('\n');
|
|
117
|
+
const modifiedLines = [];
|
|
118
|
+
for (const line of lines) {
|
|
119
|
+
try {
|
|
120
|
+
const entry = JSON.parse(line);
|
|
121
|
+
// Replace placeholder tool result content with real result
|
|
122
|
+
if (entry.type === 'user' && entry.message?.content?.[0]?.type === 'tool_result') {
|
|
123
|
+
const toolUseId = entry.message.content[0].tool_use_id;
|
|
124
|
+
const replacement = toolResultMap.get(toolUseId);
|
|
125
|
+
if (replacement) {
|
|
126
|
+
// Update the content in-place - must be a string, not an array
|
|
127
|
+
entry.message.content[0].content = replacement.text;
|
|
128
|
+
entry.message.content[0].is_error = replacement.isError;
|
|
129
|
+
// Also update the toolUseResult field if present
|
|
130
|
+
if (entry.toolUseResult) {
|
|
131
|
+
entry.toolUseResult = replacement.text;
|
|
132
|
+
}
|
|
133
|
+
modifiedLines.push(JSON.stringify(entry));
|
|
134
|
+
continue;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
// Replace "No response requested." synthetic messages with empty text
|
|
138
|
+
// These messages poison the context by telling the model not to respond
|
|
139
|
+
if (entry.type === 'assistant' &&
|
|
140
|
+
entry.message?.content?.[0]?.type === 'text' &&
|
|
141
|
+
entry.message?.content?.[0]?.text === 'No response requested.') {
|
|
142
|
+
// Replace with benign content that doesn't discourage responding
|
|
143
|
+
entry.message.content[0].text = '';
|
|
144
|
+
modifiedLines.push(JSON.stringify(entry));
|
|
145
|
+
continue;
|
|
146
|
+
}
|
|
147
|
+
// Keep all other entries as-is
|
|
148
|
+
modifiedLines.push(line);
|
|
149
|
+
}
|
|
150
|
+
catch {
|
|
151
|
+
// Keep unparseable lines as-is
|
|
152
|
+
modifiedLines.push(line);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
// Write back the modified content
|
|
156
|
+
fs.writeFileSync(jsonlPath, modifiedLines.join('\n') + '\n');
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Injects tool results into the SDK session file.
|
|
160
|
+
* Maps our tool call IDs to SDK tool_use IDs using the metadata.
|
|
161
|
+
* Replaces placeholder content in-place to preserve parent chain.
|
|
162
|
+
*/
|
|
163
|
+
export function injectToolResultsIntoSession(metadata, toolResults) {
|
|
164
|
+
// Build a map of tool_use_id -> replacement content
|
|
165
|
+
const toolResultMap = new Map();
|
|
166
|
+
for (const toolResult of toolResults) {
|
|
167
|
+
// Map our toolCallId to SDK's tool_use_id
|
|
168
|
+
const sdkToolUseId = metadata.toolUseMapping[toolResult.toolCallId];
|
|
169
|
+
if (!sdkToolUseId) {
|
|
170
|
+
console.warn(`No SDK tool_use_id mapping for toolCallId: ${toolResult.toolCallId}`);
|
|
171
|
+
continue;
|
|
172
|
+
}
|
|
173
|
+
// Get the result text
|
|
174
|
+
const resultText = toolResult.content
|
|
175
|
+
.filter(c => c.type === 'text')
|
|
176
|
+
.map(c => c.content)
|
|
177
|
+
.join('\n');
|
|
178
|
+
toolResultMap.set(sdkToolUseId, {
|
|
179
|
+
text: resultText,
|
|
180
|
+
isError: toolResult.isError
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
// Replace placeholder tool results with real results in-place
|
|
184
|
+
if (toolResultMap.size > 0) {
|
|
185
|
+
replaceToolResultsInPlace(metadata.sessionId, toolResultMap);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
//# sourceMappingURL=session.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session.js","sourceRoot":"","sources":["../../../src/providers/anthropic-agents-sdk/session.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AACpC,OAAO,EAAE,eAAe,EAAsB,MAAM,YAAY,CAAC;AAGjE;;;;GAIG;AACH,MAAM,UAAU,gBAAgB;IAC/B,2EAA2E;IAC3E,MAAM,WAAW,GAAG,EAAE,CAAC,YAAY,CAAC,eAAe,CAAC,CAAC;IACrD,MAAM,YAAY,GAAG,WAAW,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IACrD,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,IAAI,IAAI,GAAG,CAAC;IACxC,OAAO,IAAI,CAAC,IAAI,CAA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AC,YAAY,EAAE,CAAC;YACnB,OAAO,CAAC,IAAI,CAAC,8CAA8C,UAAU,CAAC,UAAU,EAAE,CAAC,CAAC;YACpF,SAAS;QACV,CAAC;QAED,sBAAsB;QACtB,MAAM,UAAU,GAAG,UAAU,CAAC,OAAO;aACnC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,MAAM,CAAC;aAC9B,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC;aACnB,IAAI,CAAC,IAAI,CAAC,CAAC;QAEb,aAAa,CAAC,GAAG,CAAC,YAAY,EAAE;YAC/B,IAAI,EAAE,UAAU;YAChB,OAAO,EAAE,UAAU,CAAC,OAAO;SAC3B,CAAC,CAAC;IACJ,CAAC;IAED,8DAA8D;IAC9D,IAAI,aAAa,CAAC,IAAI,GAAG,CAAC,EAAE,CAAC;QAC5B,yBAAyB,CAAC,QAAQ,CAAC,SAAS,EAAE,aAAa,CAAC,CAAC;IAC9D,CAAC;AACF,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stream.d.ts","sourceRoot":"","sources":["../../../src/providers/anthropic-agents-sdk/stream.ts"],"names":[],"mappings":"AASA,OAAO,EACN,cAAc,EAUd,MAAM,gBAAgB,CAAC;AAgBxB,eAAO,MAAM,wBAAwB,EAAE,cAAc,CAAC,sBAAsB,CA4T3E,CAAC"}
|
|
@@ -0,0 +1,402 @@
|
|
|
1
|
+
import { query } from "@anthropic-ai/claude-agent-sdk";
|
|
2
|
+
import { AssistantMessageEventStream } from "../../utils/event-stream.js";
|
|
3
|
+
import { SDK_SESSION_DIR } from "./types.js";
|
|
4
|
+
import { createToolsServer, mapStopReason, mapResultSubtypeToStopReason, getMockBetaMessage, getEmptyUsage, getResponseUsage, stripMcpToolPrefix } from "./utils.js";
|
|
5
|
+
import { sanitizeSurrogates } from "../../utils/sanitize-unicode.js";
|
|
6
|
+
import { parseStreamingJson } from "../../utils/json-parse.js";
|
|
7
|
+
import { findSessionToResume, injectToolResultsIntoSession, ensureSessionDir } from "./session.js";
|
|
8
|
+
export const streamAnthropicAgentsSdk = (model, context, options, id) => {
|
|
9
|
+
const stream = new AssistantMessageEventStream();
|
|
10
|
+
(async () => {
|
|
11
|
+
const startTimestamp = Date.now();
|
|
12
|
+
const output = {
|
|
13
|
+
role: "assistant",
|
|
14
|
+
api: model.api,
|
|
15
|
+
model: model,
|
|
16
|
+
id,
|
|
17
|
+
content: [],
|
|
18
|
+
usage: getEmptyUsage(),
|
|
19
|
+
stopReason: "stop",
|
|
20
|
+
timestamp: startTimestamp,
|
|
21
|
+
duration: 0
|
|
22
|
+
};
|
|
23
|
+
let finalResponse = getMockBetaMessage();
|
|
24
|
+
const blocks = output.content;
|
|
25
|
+
const accumulatedContent = [];
|
|
26
|
+
// Session tracking for multi-turn tool execution
|
|
27
|
+
let sessionId;
|
|
28
|
+
let assistantUuid;
|
|
29
|
+
const toolUseMapping = {}; // our toolCallId -> SDK tool_use_id
|
|
30
|
+
try {
|
|
31
|
+
// Ensure session directory exists
|
|
32
|
+
ensureSessionDir();
|
|
33
|
+
// Check if we need to resume a session (tool results in context)
|
|
34
|
+
const sessionToResume = findSessionToResume(context);
|
|
35
|
+
let resumeSessionId;
|
|
36
|
+
if (sessionToResume) {
|
|
37
|
+
// Inject tool results into the session file
|
|
38
|
+
injectToolResultsIntoSession(sessionToResume.metadata, sessionToResume.toolResults);
|
|
39
|
+
resumeSessionId = sessionToResume.metadata.sessionId;
|
|
40
|
+
}
|
|
41
|
+
// Build SDK options (with resume if needed)
|
|
42
|
+
const sdkOptions = buildSdkOptions(model, context, options, resumeSessionId);
|
|
43
|
+
// Build the prompt
|
|
44
|
+
const prompt = resumeSessionId
|
|
45
|
+
? "Continue with the tool result." // Non-empty prompt for resume
|
|
46
|
+
: buildPrompt(context);
|
|
47
|
+
// Create abort controller from signal if provided
|
|
48
|
+
if (options?.signal) {
|
|
49
|
+
sdkOptions.abortController = new AbortController();
|
|
50
|
+
options.signal.addEventListener('abort', () => {
|
|
51
|
+
sdkOptions.abortController?.abort();
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
// Enable partial messages for streaming
|
|
55
|
+
sdkOptions.includePartialMessages = true;
|
|
56
|
+
// Run the query
|
|
57
|
+
const queryResult = query({ prompt, options: sdkOptions });
|
|
58
|
+
stream.push({ type: "start", message: { ...output, timestamp: Date.now() } });
|
|
59
|
+
let lastAssistantMessage;
|
|
60
|
+
let resultMessage;
|
|
61
|
+
for await (const message of queryResult) {
|
|
62
|
+
// Capture session ID from system init message
|
|
63
|
+
if (message.type === 'system' && message.subtype === 'init') {
|
|
64
|
+
sessionId = message.session_id;
|
|
65
|
+
}
|
|
66
|
+
if (message.type === 'stream_event') {
|
|
67
|
+
// Handle streaming events
|
|
68
|
+
const partialMessage = message;
|
|
69
|
+
const event = partialMessage.event;
|
|
70
|
+
if (event.type === "message_start") {
|
|
71
|
+
finalResponse.id = event.message.id;
|
|
72
|
+
finalResponse.model = event.message.model;
|
|
73
|
+
finalResponse.role = event.message.role;
|
|
74
|
+
output.usage.input = event.message.usage.input_tokens || 0;
|
|
75
|
+
output.usage.output = event.message.usage.output_tokens || 0;
|
|
76
|
+
output.usage.cacheRead = event.message.usage.cache_read_input_tokens || 0;
|
|
77
|
+
output.usage.cacheWrite = event.message.usage.cache_creation_input_tokens || 0;
|
|
78
|
+
output.usage.totalTokens =
|
|
79
|
+
output.usage.input + output.usage.output + output.usage.cacheRead + output.usage.cacheWrite;
|
|
80
|
+
}
|
|
81
|
+
else if (event.type === "content_block_start") {
|
|
82
|
+
accumulatedContent.push({ index: event.index, ...event.content_block });
|
|
83
|
+
if (event.content_block.type === "text") {
|
|
84
|
+
const block = {
|
|
85
|
+
type: "response",
|
|
86
|
+
content: [{ type: 'text', content: "" }],
|
|
87
|
+
index: event.index,
|
|
88
|
+
};
|
|
89
|
+
output.content.push(block);
|
|
90
|
+
stream.push({ type: "text_start", contentIndex: output.content.length - 1, message: output });
|
|
91
|
+
}
|
|
92
|
+
else if (event.content_block.type === "thinking") {
|
|
93
|
+
const block = {
|
|
94
|
+
type: "thinking",
|
|
95
|
+
thinkingText: "",
|
|
96
|
+
index: event.index,
|
|
97
|
+
};
|
|
98
|
+
output.content.push(block);
|
|
99
|
+
stream.push({ type: "thinking_start", contentIndex: output.content.length - 1, message: output });
|
|
100
|
+
}
|
|
101
|
+
else if (event.content_block.type === "tool_use") {
|
|
102
|
+
const sdkToolUseId = event.content_block.id;
|
|
103
|
+
const block = {
|
|
104
|
+
type: "toolCall",
|
|
105
|
+
toolCallId: sdkToolUseId,
|
|
106
|
+
// Strip MCP prefix so Conversation class can find the tool
|
|
107
|
+
name: stripMcpToolPrefix(event.content_block.name),
|
|
108
|
+
arguments: event.content_block.input,
|
|
109
|
+
partialJson: "",
|
|
110
|
+
index: event.index,
|
|
111
|
+
};
|
|
112
|
+
output.content.push(block);
|
|
113
|
+
// Map our toolCallId to SDK tool_use_id (same value, but stored for session management)
|
|
114
|
+
toolUseMapping[sdkToolUseId] = sdkToolUseId;
|
|
115
|
+
stream.push({ type: "toolcall_start", contentIndex: output.content.length - 1, message: output });
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
else if (event.type === "content_block_delta") {
|
|
119
|
+
const accumBlockIndex = accumulatedContent.findIndex(a => a.index === event.index);
|
|
120
|
+
if (event.delta.type === "text_delta") {
|
|
121
|
+
const index = blocks.findIndex((b) => b.index === event.index);
|
|
122
|
+
const block = blocks[index];
|
|
123
|
+
if (block && block.type === "response") {
|
|
124
|
+
const textContentIndex = block.content.findIndex((b) => b.type === 'text');
|
|
125
|
+
block.content[textContentIndex].content += event.delta.text;
|
|
126
|
+
stream.push({
|
|
127
|
+
type: "text_delta",
|
|
128
|
+
contentIndex: index,
|
|
129
|
+
delta: event.delta.text,
|
|
130
|
+
message: output,
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
if (accumBlockIndex !== -1) {
|
|
134
|
+
accumulatedContent[accumBlockIndex].text += event.delta.text;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
else if (event.delta.type === "thinking_delta") {
|
|
138
|
+
const index = blocks.findIndex((b) => b.index === event.index);
|
|
139
|
+
const block = blocks[index];
|
|
140
|
+
if (block && block.type === "thinking") {
|
|
141
|
+
block.thinkingText += event.delta.thinking;
|
|
142
|
+
stream.push({
|
|
143
|
+
type: "thinking_delta",
|
|
144
|
+
contentIndex: index,
|
|
145
|
+
delta: event.delta.thinking,
|
|
146
|
+
message: output,
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
if (accumBlockIndex !== -1) {
|
|
150
|
+
accumulatedContent[accumBlockIndex].thinking += event.delta.thinking;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
else if (event.delta.type === "input_json_delta") {
|
|
154
|
+
const index = blocks.findIndex((b) => b.index === event.index);
|
|
155
|
+
const block = blocks[index];
|
|
156
|
+
if (block && block.type === "toolCall") {
|
|
157
|
+
block.partialJson += event.delta.partial_json;
|
|
158
|
+
block.arguments = parseStreamingJson(block.partialJson);
|
|
159
|
+
stream.push({
|
|
160
|
+
type: "toolcall_delta",
|
|
161
|
+
contentIndex: index,
|
|
162
|
+
delta: event.delta.partial_json,
|
|
163
|
+
message: output,
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
if (accumBlockIndex !== -1) {
|
|
167
|
+
accumulatedContent[accumBlockIndex].partialJson =
|
|
168
|
+
(accumulatedContent[accumBlockIndex].partialJson || '') + event.delta.partial_json;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
else if (event.delta.type === "signature_delta") {
|
|
172
|
+
if (accumBlockIndex !== -1) {
|
|
173
|
+
accumulatedContent[accumBlockIndex].signature =
|
|
174
|
+
(accumulatedContent[accumBlockIndex].signature || '') + event.delta.signature;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
else if (event.type === "content_block_stop") {
|
|
179
|
+
const index = blocks.findIndex((b) => b.index === event.index);
|
|
180
|
+
const block = blocks[index];
|
|
181
|
+
const accumBlockIndex = accumulatedContent.findIndex(a => a.index === event.index);
|
|
182
|
+
if (accumBlockIndex !== -1) {
|
|
183
|
+
if (accumulatedContent[accumBlockIndex].type === 'tool_use') {
|
|
184
|
+
const partialJson = accumulatedContent[accumBlockIndex].partialJson;
|
|
185
|
+
if (partialJson) {
|
|
186
|
+
accumulatedContent[accumBlockIndex].input = parseStreamingJson(partialJson);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
if (accumulatedContent[accumBlockIndex].index !== undefined) {
|
|
190
|
+
delete accumulatedContent[accumBlockIndex].index;
|
|
191
|
+
}
|
|
192
|
+
if (accumulatedContent[accumBlockIndex].partialJson !== undefined) {
|
|
193
|
+
delete accumulatedContent[accumBlockIndex].partialJson;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
if (block) {
|
|
197
|
+
delete block.index;
|
|
198
|
+
if (block.type === "response") {
|
|
199
|
+
stream.push({
|
|
200
|
+
type: "text_end",
|
|
201
|
+
contentIndex: index,
|
|
202
|
+
content: block.content,
|
|
203
|
+
message: output,
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
else if (block.type === "thinking") {
|
|
207
|
+
stream.push({
|
|
208
|
+
type: "thinking_end",
|
|
209
|
+
contentIndex: index,
|
|
210
|
+
content: block.thinkingText,
|
|
211
|
+
message: output,
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
else if (block.type === "toolCall") {
|
|
215
|
+
block.arguments = parseStreamingJson(block.partialJson);
|
|
216
|
+
delete block.partialJson;
|
|
217
|
+
stream.push({
|
|
218
|
+
type: "toolcall_end",
|
|
219
|
+
contentIndex: index,
|
|
220
|
+
toolCall: block,
|
|
221
|
+
message: output,
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
else if (event.type === "message_delta") {
|
|
227
|
+
if (event.delta.stop_reason) {
|
|
228
|
+
output.stopReason = mapStopReason(event.delta.stop_reason);
|
|
229
|
+
finalResponse.stop_reason = event.delta.stop_reason;
|
|
230
|
+
}
|
|
231
|
+
output.usage.output = event.usage.output_tokens || 0;
|
|
232
|
+
output.usage.totalTokens =
|
|
233
|
+
output.usage.input + output.usage.output + output.usage.cacheRead + output.usage.cacheWrite;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
else if (message.type === 'assistant') {
|
|
237
|
+
lastAssistantMessage = message;
|
|
238
|
+
// Capture assistant UUID for session management
|
|
239
|
+
assistantUuid = message.uuid;
|
|
240
|
+
}
|
|
241
|
+
else if (message.type === 'result') {
|
|
242
|
+
resultMessage = message;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
if (options?.signal?.aborted) {
|
|
246
|
+
throw new Error("Request was aborted");
|
|
247
|
+
}
|
|
248
|
+
// Update final response content
|
|
249
|
+
finalResponse.content = accumulatedContent;
|
|
250
|
+
// Update usage from result if available
|
|
251
|
+
if (resultMessage) {
|
|
252
|
+
output.usage = getResponseUsage(resultMessage.usage, resultMessage.total_cost_usd, model);
|
|
253
|
+
if (resultMessage.subtype !== 'success') {
|
|
254
|
+
output.stopReason = mapResultSubtypeToStopReason(resultMessage.subtype);
|
|
255
|
+
if ('errors' in resultMessage) {
|
|
256
|
+
output.errorMessage = resultMessage.errors.join('; ');
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
// Use the full assistant message if available
|
|
261
|
+
if (lastAssistantMessage) {
|
|
262
|
+
finalResponse = lastAssistantMessage.message;
|
|
263
|
+
}
|
|
264
|
+
stream.push({ type: "done", reason: output.stopReason, message: { ...output, timestamp: Date.now() } });
|
|
265
|
+
const baseAssistantMessage = {
|
|
266
|
+
...output,
|
|
267
|
+
message: finalResponse,
|
|
268
|
+
timestamp: Date.now(),
|
|
269
|
+
duration: Date.now() - startTimestamp,
|
|
270
|
+
// Include session metadata for multi-turn tool execution
|
|
271
|
+
sdkMetadata: sessionId && assistantUuid ? {
|
|
272
|
+
sessionId,
|
|
273
|
+
assistantUuid,
|
|
274
|
+
toolUseMapping
|
|
275
|
+
} : undefined
|
|
276
|
+
};
|
|
277
|
+
stream.end(baseAssistantMessage);
|
|
278
|
+
}
|
|
279
|
+
catch (error) {
|
|
280
|
+
for (const block of output.content)
|
|
281
|
+
delete block.index;
|
|
282
|
+
output.stopReason = options?.signal?.aborted ? "aborted" : "error";
|
|
283
|
+
output.errorMessage = error instanceof Error ? error.message : JSON.stringify(error);
|
|
284
|
+
stream.push({ type: "error", reason: output.stopReason, message: { ...output, timestamp: Date.now() } });
|
|
285
|
+
finalResponse.content = accumulatedContent;
|
|
286
|
+
const baseAssistantMessage = {
|
|
287
|
+
...output,
|
|
288
|
+
message: finalResponse,
|
|
289
|
+
timestamp: Date.now(),
|
|
290
|
+
duration: Date.now() - startTimestamp,
|
|
291
|
+
// Include session metadata even on error for debugging
|
|
292
|
+
sdkMetadata: sessionId && assistantUuid ? {
|
|
293
|
+
sessionId,
|
|
294
|
+
assistantUuid,
|
|
295
|
+
toolUseMapping
|
|
296
|
+
} : undefined
|
|
297
|
+
};
|
|
298
|
+
stream.end(baseAssistantMessage);
|
|
299
|
+
}
|
|
300
|
+
})();
|
|
301
|
+
return stream;
|
|
302
|
+
};
|
|
303
|
+
/**
|
|
304
|
+
* Builds SDK options from our context and provider options.
|
|
305
|
+
*/
|
|
306
|
+
function buildSdkOptions(model, context, options, resumeSessionId) {
|
|
307
|
+
const { signal, ...restOptions } = options;
|
|
308
|
+
const sdkOptions = {
|
|
309
|
+
...restOptions,
|
|
310
|
+
model: model.id,
|
|
311
|
+
// Always use single turn - Conversation class handles multi-turn
|
|
312
|
+
maxTurns: 1,
|
|
313
|
+
// Bypass permissions for programmatic use
|
|
314
|
+
permissionMode: options.permissionMode ?? 'bypassPermissions',
|
|
315
|
+
allowDangerouslySkipPermissions: options.allowDangerouslySkipPermissions ?? true,
|
|
316
|
+
// Use fixed session directory
|
|
317
|
+
cwd: SDK_SESSION_DIR,
|
|
318
|
+
};
|
|
319
|
+
// Resume session if we have tool results to continue from
|
|
320
|
+
if (resumeSessionId) {
|
|
321
|
+
sdkOptions.resume = resumeSessionId;
|
|
322
|
+
}
|
|
323
|
+
// Set system prompt - use provided or empty string to avoid default Claude Code prompt
|
|
324
|
+
sdkOptions.systemPrompt = context.systemPrompt
|
|
325
|
+
? sanitizeSurrogates(context.systemPrompt)
|
|
326
|
+
: '';
|
|
327
|
+
// Disable all built-in tools by explicitly disallowing them
|
|
328
|
+
// This prevents their definitions from being loaded into context
|
|
329
|
+
const builtInTools = [
|
|
330
|
+
'Task', 'TaskOutput', 'Bash', 'Glob', 'Grep', 'Read', 'Edit', 'Write',
|
|
331
|
+
'NotebookEdit', 'WebFetch', 'TodoWrite', 'WebSearch', 'KillShell',
|
|
332
|
+
'AskUserQuestion', 'Skill', 'EnterPlanMode', 'ExitPlanMode'
|
|
333
|
+
];
|
|
334
|
+
sdkOptions.disallowedTools = builtInTools;
|
|
335
|
+
// Convert tools to MCP server
|
|
336
|
+
if (context.tools && context.tools.length > 0) {
|
|
337
|
+
const toolsServer = createToolsServer(context.tools);
|
|
338
|
+
if (toolsServer) {
|
|
339
|
+
sdkOptions.mcpServers = {
|
|
340
|
+
"custom-tools": toolsServer
|
|
341
|
+
};
|
|
342
|
+
// Only allow our custom tools
|
|
343
|
+
sdkOptions.allowedTools = context.tools.map(t => `mcp__custom-tools__${t.name}`);
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
else {
|
|
347
|
+
// No tools provided
|
|
348
|
+
sdkOptions.allowedTools = [];
|
|
349
|
+
}
|
|
350
|
+
return sdkOptions;
|
|
351
|
+
}
|
|
352
|
+
/**
|
|
353
|
+
* Builds the prompt string from context messages.
|
|
354
|
+
* For the SDK, we serialize the entire conversation history into the prompt
|
|
355
|
+
* since the SDK's query function only accepts a string prompt.
|
|
356
|
+
*/
|
|
357
|
+
function buildPrompt(context) {
|
|
358
|
+
const parts = [];
|
|
359
|
+
for (const message of context.messages) {
|
|
360
|
+
if (message.role === 'user') {
|
|
361
|
+
const textContent = message.content
|
|
362
|
+
.filter(c => c.type === 'text')
|
|
363
|
+
.map(c => c.content)
|
|
364
|
+
.join('\n');
|
|
365
|
+
if (textContent) {
|
|
366
|
+
parts.push(`User: ${textContent}`);
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
else if (message.role === 'assistant') {
|
|
370
|
+
// Include assistant response text and tool calls
|
|
371
|
+
const assistantParts = [];
|
|
372
|
+
const assistantMsg = message;
|
|
373
|
+
for (const content of assistantMsg.content) {
|
|
374
|
+
if (content.type === 'response') {
|
|
375
|
+
const text = content.content
|
|
376
|
+
.filter(c => c.type === 'text')
|
|
377
|
+
.map(c => c.content)
|
|
378
|
+
.join('\n');
|
|
379
|
+
if (text)
|
|
380
|
+
assistantParts.push(text);
|
|
381
|
+
}
|
|
382
|
+
else if (content.type === 'toolCall') {
|
|
383
|
+
assistantParts.push(`[Tool Call: ${content.name} with args ${JSON.stringify(content.arguments)}]`);
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
if (assistantParts.length > 0) {
|
|
387
|
+
parts.push(`Assistant: ${assistantParts.join('\n')}`);
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
else if (message.role === 'toolResult') {
|
|
391
|
+
const toolResult = message;
|
|
392
|
+
const resultText = toolResult.content
|
|
393
|
+
.filter(c => c.type === 'text')
|
|
394
|
+
.map(c => c.content)
|
|
395
|
+
.join('\n');
|
|
396
|
+
const status = toolResult.isError ? 'Error' : 'Result';
|
|
397
|
+
parts.push(`Tool ${status} (${toolResult.toolName}): ${resultText}`);
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
return sanitizeSurrogates(parts.join('\n\n'));
|
|
401
|
+
}
|
|
402
|
+
//# sourceMappingURL=stream.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stream.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