@yourgpt/copilot-sdk 2.1.7 → 2.1.9-alpha.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/{chunk-ISOMZAYN.js → chunk-RBULQ6EJ.js} +207 -62
- package/dist/chunk-RBULQ6EJ.js.map +1 -0
- package/dist/chunk-RPR5GMWF.js +52 -0
- package/dist/chunk-RPR5GMWF.js.map +1 -0
- package/dist/{chunk-IDAQU3FP.cjs → chunk-TD7NF6OE.cjs} +207 -62
- package/dist/chunk-TD7NF6OE.cjs.map +1 -0
- package/dist/{chunk-JFVTY757.cjs → chunk-WYFJZNFT.cjs} +16 -16
- package/dist/{chunk-JFVTY757.cjs.map → chunk-WYFJZNFT.cjs.map} +1 -1
- package/dist/{chunk-H3LX6FTP.js → chunk-XVKKLLKW.js} +3 -3
- package/dist/{chunk-H3LX6FTP.js.map → chunk-XVKKLLKW.js.map} +1 -1
- package/dist/chunk-YBLAHX2Z.cjs +55 -0
- package/dist/chunk-YBLAHX2Z.cjs.map +1 -0
- package/dist/experimental/index.cjs +416 -536
- package/dist/experimental/index.cjs.map +1 -1
- package/dist/experimental/index.d.cts +189 -853
- package/dist/experimental/index.d.ts +189 -853
- package/dist/experimental/index.js +415 -530
- package/dist/experimental/index.js.map +1 -1
- package/dist/react/index.cjs +62 -62
- package/dist/react/index.d.cts +18 -0
- package/dist/react/index.d.ts +18 -0
- package/dist/react/index.js +2 -2
- package/dist/ui/index.cjs +521 -263
- package/dist/ui/index.cjs.map +1 -1
- package/dist/ui/index.js +352 -94
- package/dist/ui/index.js.map +1 -1
- package/package.json +2 -1
- package/dist/chunk-5EGBIQYS.cjs +0 -292
- package/dist/chunk-5EGBIQYS.cjs.map +0 -1
- package/dist/chunk-IDAQU3FP.cjs.map +0 -1
- package/dist/chunk-ISOMZAYN.js.map +0 -1
- package/dist/chunk-TXQ37MAO.js +0 -287
- package/dist/chunk-TXQ37MAO.js.map +0 -1
|
@@ -39,6 +39,19 @@ function isStreamDone(chunk) {
|
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
// src/chat/functions/stream/processChunk.ts
|
|
42
|
+
function parsePartialJson(partial) {
|
|
43
|
+
if (!partial || !partial.startsWith("{")) return null;
|
|
44
|
+
const result = {};
|
|
45
|
+
const stringPairs = partial.matchAll(/"(\w+)"\s*:\s*"((?:[^"\\]|\\.)*)"/g);
|
|
46
|
+
for (const m of stringPairs) {
|
|
47
|
+
result[m[1]] = m[2];
|
|
48
|
+
}
|
|
49
|
+
const openString = partial.match(/"(\w+)"\s*:\s*"((?:[^"\\]|\\.)*)$/);
|
|
50
|
+
if (openString) {
|
|
51
|
+
result[openString[1]] = openString[2];
|
|
52
|
+
}
|
|
53
|
+
return Object.keys(result).length > 0 ? result : null;
|
|
54
|
+
}
|
|
42
55
|
function processStreamChunk(chunk, state) {
|
|
43
56
|
switch (chunk.type) {
|
|
44
57
|
case "message:start":
|
|
@@ -79,12 +92,17 @@ function processStreamChunk(chunk, state) {
|
|
|
79
92
|
const existing = state.toolResults.get(chunk.id);
|
|
80
93
|
if (existing) {
|
|
81
94
|
const newResults = new Map(state.toolResults);
|
|
95
|
+
let parsed = null;
|
|
82
96
|
try {
|
|
97
|
+
parsed = JSON.parse(chunk.args);
|
|
98
|
+
} catch {
|
|
99
|
+
parsed = parsePartialJson(chunk.args);
|
|
100
|
+
}
|
|
101
|
+
if (parsed) {
|
|
83
102
|
newResults.set(chunk.id, {
|
|
84
103
|
...existing,
|
|
85
|
-
args:
|
|
104
|
+
args: parsed
|
|
86
105
|
});
|
|
87
|
-
} catch {
|
|
88
106
|
}
|
|
89
107
|
return { ...state, toolResults: newResults };
|
|
90
108
|
}
|
|
@@ -1523,7 +1541,8 @@ var AbstractChat = class {
|
|
|
1523
1541
|
threadId: init.threadId,
|
|
1524
1542
|
debug: init.debug,
|
|
1525
1543
|
optimization: init.optimization,
|
|
1526
|
-
yourgptConfig: init.yourgptConfig
|
|
1544
|
+
yourgptConfig: init.yourgptConfig,
|
|
1545
|
+
streamMode: init.streamMode
|
|
1527
1546
|
};
|
|
1528
1547
|
this.state = init.state ?? new SimpleChatState();
|
|
1529
1548
|
this.transport = init.transport ?? new HttpTransport({
|
|
@@ -1749,6 +1768,12 @@ var AbstractChat = class {
|
|
|
1749
1768
|
this.callbacks.onMessagesChange?.(this._allMessages());
|
|
1750
1769
|
this.callbacks.onStatusChange?.("submitted");
|
|
1751
1770
|
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
1771
|
+
if (this.status === "ready" || this.status === "error") {
|
|
1772
|
+
this.debug(
|
|
1773
|
+
"Skipping processRequest \u2014 status reset during yield (stop was called)"
|
|
1774
|
+
);
|
|
1775
|
+
return;
|
|
1776
|
+
}
|
|
1752
1777
|
await this.processRequest();
|
|
1753
1778
|
} catch (error) {
|
|
1754
1779
|
this.handleError(error);
|
|
@@ -2187,11 +2212,19 @@ ${this.dynamicContext}`.trim() : this.config.systemPrompt;
|
|
|
2187
2212
|
if (existing) {
|
|
2188
2213
|
assistantMessage = existing;
|
|
2189
2214
|
} else {
|
|
2190
|
-
|
|
2215
|
+
const visibleMessages = this.state.messages;
|
|
2216
|
+
const currentLeafId = visibleMessages.length > 0 ? visibleMessages[visibleMessages.length - 1].id : void 0;
|
|
2217
|
+
assistantMessage = createEmptyAssistantMessage(void 0, {
|
|
2218
|
+
parentId: currentLeafId
|
|
2219
|
+
});
|
|
2191
2220
|
this.state.pushMessage(assistantMessage);
|
|
2192
2221
|
}
|
|
2193
2222
|
} else {
|
|
2194
|
-
|
|
2223
|
+
const visibleMessages = this.state.messages;
|
|
2224
|
+
const currentLeafId = visibleMessages.length > 0 ? visibleMessages[visibleMessages.length - 1].id : void 0;
|
|
2225
|
+
assistantMessage = createEmptyAssistantMessage(void 0, {
|
|
2226
|
+
parentId: currentLeafId
|
|
2227
|
+
});
|
|
2195
2228
|
this.state.pushMessage(assistantMessage);
|
|
2196
2229
|
}
|
|
2197
2230
|
this.streamState = createStreamState(assistantMessage.id);
|
|
@@ -2211,37 +2244,58 @@ ${this.dynamicContext}`.trim() : this.config.systemPrompt;
|
|
|
2211
2244
|
this.handleError(error);
|
|
2212
2245
|
return;
|
|
2213
2246
|
}
|
|
2214
|
-
if (chunk.type === "message:end" && this.streamState
|
|
2215
|
-
this.
|
|
2216
|
-
|
|
2217
|
-
|
|
2218
|
-
|
|
2219
|
-
|
|
2220
|
-
|
|
2221
|
-
|
|
2222
|
-
|
|
2223
|
-
|
|
2224
|
-
|
|
2225
|
-
|
|
2247
|
+
if (chunk.type === "message:end" && this.streamState) {
|
|
2248
|
+
if (this.config.streamMode === "single-turn") {
|
|
2249
|
+
this.debug(
|
|
2250
|
+
"message:end mid-stream (single-turn: keeping streamState alive)",
|
|
2251
|
+
{
|
|
2252
|
+
messageId: this.streamState.messageId,
|
|
2253
|
+
contentLength: this.streamState.content.length,
|
|
2254
|
+
chunkCount
|
|
2255
|
+
}
|
|
2256
|
+
);
|
|
2257
|
+
continue;
|
|
2258
|
+
}
|
|
2259
|
+
if (!this.streamState.content && (this.streamState.toolResults?.size ?? 0) === 0) ; else {
|
|
2260
|
+
this.debug("message:end mid-stream", {
|
|
2261
|
+
messageId: this.streamState.messageId,
|
|
2262
|
+
contentLength: this.streamState.content.length,
|
|
2263
|
+
toolCallsInState: this.streamState.toolCalls?.length ?? 0,
|
|
2264
|
+
chunkCount
|
|
2265
|
+
});
|
|
2266
|
+
const turnMessage = streamStateToMessage(this.streamState);
|
|
2267
|
+
const toolCallsHidden = {};
|
|
2268
|
+
for (const [id, result] of this.streamState.toolResults) {
|
|
2269
|
+
if (result.hidden !== void 0) {
|
|
2270
|
+
toolCallsHidden[id] = result.hidden;
|
|
2271
|
+
}
|
|
2272
|
+
}
|
|
2273
|
+
if (turnMessage.toolCalls?.length && Object.keys(toolCallsHidden).length > 0) {
|
|
2274
|
+
turnMessage.metadata = {
|
|
2275
|
+
...turnMessage.metadata,
|
|
2276
|
+
toolCallsHidden
|
|
2277
|
+
};
|
|
2226
2278
|
}
|
|
2279
|
+
this.state.updateMessageById(
|
|
2280
|
+
this.streamState.messageId,
|
|
2281
|
+
(existing) => ({
|
|
2282
|
+
...turnMessage,
|
|
2283
|
+
...existing.parentId !== void 0 ? { parentId: existing.parentId } : {},
|
|
2284
|
+
...existing.childrenIds !== void 0 ? { childrenIds: existing.childrenIds } : {}
|
|
2285
|
+
})
|
|
2286
|
+
);
|
|
2287
|
+
this.callbacks.onMessageFinish?.(turnMessage);
|
|
2288
|
+
this.streamState = null;
|
|
2289
|
+
continue;
|
|
2227
2290
|
}
|
|
2228
|
-
|
|
2229
|
-
|
|
2230
|
-
|
|
2231
|
-
|
|
2232
|
-
|
|
2291
|
+
}
|
|
2292
|
+
if (chunk.type === "message:start" && this.streamState !== null) {
|
|
2293
|
+
if (this.config.streamMode === "single-turn") {
|
|
2294
|
+
this.debug(
|
|
2295
|
+
"message:start mid-stream (single-turn: streamState already active, skipping)"
|
|
2296
|
+
);
|
|
2297
|
+
continue;
|
|
2233
2298
|
}
|
|
2234
|
-
this.state.updateMessageById(
|
|
2235
|
-
this.streamState.messageId,
|
|
2236
|
-
(existing) => ({
|
|
2237
|
-
...turnMessage,
|
|
2238
|
-
...existing.parentId !== void 0 ? { parentId: existing.parentId } : {},
|
|
2239
|
-
...existing.childrenIds !== void 0 ? { childrenIds: existing.childrenIds } : {}
|
|
2240
|
-
})
|
|
2241
|
-
);
|
|
2242
|
-
this.callbacks.onMessageFinish?.(turnMessage);
|
|
2243
|
-
this.streamState = null;
|
|
2244
|
-
continue;
|
|
2245
2299
|
}
|
|
2246
2300
|
if (chunk.type === "message:start" && this.streamState === null) {
|
|
2247
2301
|
this.debug("message:start after mid-stream end - creating new message");
|
|
@@ -2256,6 +2310,45 @@ ${this.dynamicContext}`.trim() : this.config.systemPrompt;
|
|
|
2256
2310
|
continue;
|
|
2257
2311
|
}
|
|
2258
2312
|
if (!this.streamState) {
|
|
2313
|
+
if (chunk.type === "action:start") {
|
|
2314
|
+
this.callbacks.onServerToolStart?.({
|
|
2315
|
+
id: chunk.id,
|
|
2316
|
+
name: chunk.name,
|
|
2317
|
+
hidden: chunk.hidden
|
|
2318
|
+
});
|
|
2319
|
+
continue;
|
|
2320
|
+
}
|
|
2321
|
+
if (chunk.type === "action:args") {
|
|
2322
|
+
let args = {};
|
|
2323
|
+
try {
|
|
2324
|
+
args = JSON.parse(chunk.args);
|
|
2325
|
+
} catch {
|
|
2326
|
+
try {
|
|
2327
|
+
const partial = chunk.args;
|
|
2328
|
+
if (partial && partial.startsWith("{")) {
|
|
2329
|
+
const extracted = {};
|
|
2330
|
+
const pairs = partial.matchAll(
|
|
2331
|
+
/"(\w+)"\s*:\s*"((?:[^"\\]|\\.)*)"/g
|
|
2332
|
+
);
|
|
2333
|
+
for (const m of pairs) extracted[m[1]] = m[2];
|
|
2334
|
+
const open = partial.match(/"(\w+)"\s*:\s*"((?:[^"\\]|\\.)*)$/);
|
|
2335
|
+
if (open) extracted[open[1]] = open[2];
|
|
2336
|
+
if (Object.keys(extracted).length > 0) args = extracted;
|
|
2337
|
+
}
|
|
2338
|
+
} catch {
|
|
2339
|
+
}
|
|
2340
|
+
}
|
|
2341
|
+
const execName = chunk.id;
|
|
2342
|
+
this.callbacks.onServerToolArgs?.({
|
|
2343
|
+
id: chunk.id,
|
|
2344
|
+
name: execName,
|
|
2345
|
+
args
|
|
2346
|
+
});
|
|
2347
|
+
continue;
|
|
2348
|
+
}
|
|
2349
|
+
if (chunk.type === "action:end") {
|
|
2350
|
+
continue;
|
|
2351
|
+
}
|
|
2259
2352
|
if (chunk.type === "tool_calls") {
|
|
2260
2353
|
pendingClientToolCalls = chunk.toolCalls;
|
|
2261
2354
|
this.debug("tool_calls (post-message:end, stored as pending)", {
|
|
@@ -2278,6 +2371,8 @@ ${this.dynamicContext}`.trim() : this.config.systemPrompt;
|
|
|
2278
2371
|
);
|
|
2279
2372
|
const messagesToInsert = [];
|
|
2280
2373
|
let clientAssistantToolCalls;
|
|
2374
|
+
const lastVisibleMsgs = this.state.messages;
|
|
2375
|
+
let postEndInsertParentId = lastVisibleMsgs.length > 0 ? lastVisibleMsgs[lastVisibleMsgs.length - 1].id : void 0;
|
|
2281
2376
|
for (const msg of chunk.messages) {
|
|
2282
2377
|
if (msg.role === "assistant" && msg.tool_calls?.length && pendingIds.size > 0 && msg.tool_calls.every(
|
|
2283
2378
|
(tc) => pendingIds.has(tc?.id ?? "")
|
|
@@ -2292,14 +2387,17 @@ ${this.dynamicContext}`.trim() : this.config.systemPrompt;
|
|
|
2292
2387
|
continue;
|
|
2293
2388
|
if (msg.role === "tool" && msg.tool_call_id && pendingIds.has(msg.tool_call_id))
|
|
2294
2389
|
continue;
|
|
2295
|
-
|
|
2390
|
+
const insertedMsg = {
|
|
2296
2391
|
id: generateMessageId(),
|
|
2297
2392
|
role: msg.role,
|
|
2298
2393
|
content: msg.content ?? "",
|
|
2299
2394
|
toolCalls: msg.tool_calls,
|
|
2300
2395
|
toolCallId: msg.tool_call_id,
|
|
2301
|
-
createdAt: /* @__PURE__ */ new Date()
|
|
2302
|
-
|
|
2396
|
+
createdAt: /* @__PURE__ */ new Date(),
|
|
2397
|
+
...postEndInsertParentId ? { parentId: postEndInsertParentId } : {}
|
|
2398
|
+
};
|
|
2399
|
+
postEndInsertParentId = insertedMsg.id;
|
|
2400
|
+
messagesToInsert.push(insertedMsg);
|
|
2303
2401
|
}
|
|
2304
2402
|
if (clientAssistantToolCalls) {
|
|
2305
2403
|
const currentMessages = this.state.messages;
|
|
@@ -2317,7 +2415,7 @@ ${this.dynamicContext}`.trim() : this.config.systemPrompt;
|
|
|
2317
2415
|
}
|
|
2318
2416
|
}
|
|
2319
2417
|
if (messagesToInsert.length > 0) {
|
|
2320
|
-
const currentMessages = this.
|
|
2418
|
+
const currentMessages = this._allMessages();
|
|
2321
2419
|
let insertIdx = currentMessages.length;
|
|
2322
2420
|
for (let i = currentMessages.length - 1; i >= 0; i--) {
|
|
2323
2421
|
if (currentMessages[i].role === "assistant") {
|
|
@@ -2373,6 +2471,20 @@ ${this.dynamicContext}`.trim() : this.config.systemPrompt;
|
|
|
2373
2471
|
try {
|
|
2374
2472
|
args = JSON.parse(chunk.args);
|
|
2375
2473
|
} catch {
|
|
2474
|
+
try {
|
|
2475
|
+
const partial = chunk.args;
|
|
2476
|
+
if (partial && partial.startsWith("{")) {
|
|
2477
|
+
const extracted = {};
|
|
2478
|
+
const pairs = partial.matchAll(
|
|
2479
|
+
/"(\w+)"\s*:\s*"((?:[^"\\]|\\.)*)"/g
|
|
2480
|
+
);
|
|
2481
|
+
for (const m of pairs) extracted[m[1]] = m[2];
|
|
2482
|
+
const open = partial.match(/"(\w+)"\s*:\s*"((?:[^"\\]|\\.)*)$/);
|
|
2483
|
+
if (open) extracted[open[1]] = open[2];
|
|
2484
|
+
if (Object.keys(extracted).length > 0) args = extracted;
|
|
2485
|
+
}
|
|
2486
|
+
} catch {
|
|
2487
|
+
}
|
|
2376
2488
|
}
|
|
2377
2489
|
const existingResult = this.streamState?.toolResults.get(chunk.id);
|
|
2378
2490
|
if (existingResult) {
|
|
@@ -2443,10 +2555,21 @@ ${this.dynamicContext}`.trim() : this.config.systemPrompt;
|
|
|
2443
2555
|
(m) => `${m.role}${m.tool_calls?.length ? `[${m.tool_calls.length}tc]` : ""}`
|
|
2444
2556
|
)
|
|
2445
2557
|
});
|
|
2446
|
-
const currentStreamToolCallIds = new Set(
|
|
2447
|
-
this.streamState?.toolCalls?.map((toolCall) => toolCall.id) ?? []
|
|
2448
|
-
|
|
2558
|
+
const currentStreamToolCallIds = /* @__PURE__ */ new Set([
|
|
2559
|
+
...this.streamState?.toolCalls?.map((toolCall) => toolCall.id) ?? [],
|
|
2560
|
+
...this.config.streamMode === "single-turn" && this.streamState?.toolResults ? Array.from(this.streamState.toolResults.keys()) : []
|
|
2561
|
+
]);
|
|
2449
2562
|
const messagesToInsert = [];
|
|
2563
|
+
let insertChainParentId;
|
|
2564
|
+
if (this.config.streamMode === "single-turn" && this.streamState) {
|
|
2565
|
+
const allMsgs = this._allMessages();
|
|
2566
|
+
const streamIdx = allMsgs.findIndex(
|
|
2567
|
+
(m) => m.id === this.streamState.messageId
|
|
2568
|
+
);
|
|
2569
|
+
insertChainParentId = streamIdx > 0 ? allMsgs[streamIdx - 1].id : void 0;
|
|
2570
|
+
} else {
|
|
2571
|
+
insertChainParentId = this.streamState?.messageId;
|
|
2572
|
+
}
|
|
2450
2573
|
const toolCallsHidden = {};
|
|
2451
2574
|
if (this.streamState?.toolResults) {
|
|
2452
2575
|
for (const [id, result] of this.streamState.toolResults) {
|
|
@@ -2459,6 +2582,12 @@ ${this.dynamicContext}`.trim() : this.config.systemPrompt;
|
|
|
2459
2582
|
if (msg.role === "assistant" && !msg.tool_calls?.length) {
|
|
2460
2583
|
continue;
|
|
2461
2584
|
}
|
|
2585
|
+
if (this.config.streamMode === "single-turn" && msg.role === "assistant") {
|
|
2586
|
+
continue;
|
|
2587
|
+
}
|
|
2588
|
+
if (this.config.streamMode === "single-turn" && msg.role === "tool") {
|
|
2589
|
+
continue;
|
|
2590
|
+
}
|
|
2462
2591
|
if (msg.role === "assistant" && msg.tool_calls?.length && msg.tool_calls.every(
|
|
2463
2592
|
(toolCall) => currentStreamToolCallIds.has(toolCall.id)
|
|
2464
2593
|
)) {
|
|
@@ -2475,12 +2604,14 @@ ${this.dynamicContext}`.trim() : this.config.systemPrompt;
|
|
|
2475
2604
|
toolCalls: msg.tool_calls,
|
|
2476
2605
|
toolCallId: msg.tool_call_id,
|
|
2477
2606
|
createdAt: /* @__PURE__ */ new Date(),
|
|
2478
|
-
metadata
|
|
2607
|
+
metadata,
|
|
2608
|
+
...insertChainParentId ? { parentId: insertChainParentId } : {}
|
|
2479
2609
|
};
|
|
2610
|
+
insertChainParentId = message.id;
|
|
2480
2611
|
messagesToInsert.push(message);
|
|
2481
2612
|
}
|
|
2482
2613
|
if (messagesToInsert.length > 0) {
|
|
2483
|
-
const currentMessages = this.
|
|
2614
|
+
const currentMessages = this._allMessages();
|
|
2484
2615
|
const currentStreamIndex = this.streamState ? currentMessages.findIndex(
|
|
2485
2616
|
(message) => message.id === this.streamState.messageId
|
|
2486
2617
|
) : -1;
|
|
@@ -2897,7 +3028,6 @@ var AbstractAgentLoop = class {
|
|
|
2897
3028
|
return [];
|
|
2898
3029
|
}
|
|
2899
3030
|
this.abortController = new AbortController();
|
|
2900
|
-
this._isCancelled = false;
|
|
2901
3031
|
this._isProcessing = true;
|
|
2902
3032
|
this.setIteration(this._iteration + 1);
|
|
2903
3033
|
const results = await Promise.all(
|
|
@@ -2920,17 +3050,28 @@ var AbstractAgentLoop = class {
|
|
|
2920
3050
|
*/
|
|
2921
3051
|
async executeSingleTool(toolCall) {
|
|
2922
3052
|
const tool = this.getTool(toolCall.name);
|
|
2923
|
-
const
|
|
2924
|
-
id
|
|
2925
|
-
|
|
2926
|
-
|
|
2927
|
-
|
|
2928
|
-
|
|
2929
|
-
|
|
2930
|
-
|
|
2931
|
-
|
|
2932
|
-
}
|
|
2933
|
-
|
|
3053
|
+
const existingExecution = this._toolExecutions.find(
|
|
3054
|
+
(e) => e.id === toolCall.id
|
|
3055
|
+
);
|
|
3056
|
+
let execution;
|
|
3057
|
+
if (existingExecution) {
|
|
3058
|
+
execution = existingExecution;
|
|
3059
|
+
this.updateToolExecution(toolCall.id, {
|
|
3060
|
+
args: toolCall.args
|
|
3061
|
+
});
|
|
3062
|
+
} else {
|
|
3063
|
+
execution = {
|
|
3064
|
+
id: toolCall.id,
|
|
3065
|
+
toolCallId: toolCall.id,
|
|
3066
|
+
name: toolCall.name,
|
|
3067
|
+
args: toolCall.args,
|
|
3068
|
+
status: "pending",
|
|
3069
|
+
approvalStatus: "none",
|
|
3070
|
+
startedAt: /* @__PURE__ */ new Date(),
|
|
3071
|
+
hidden: tool?.hidden
|
|
3072
|
+
};
|
|
3073
|
+
this.addToolExecution(execution);
|
|
3074
|
+
}
|
|
2934
3075
|
this.callbacks.onToolStart?.(execution);
|
|
2935
3076
|
if (!tool) {
|
|
2936
3077
|
const errorResult = {
|
|
@@ -3535,6 +3676,7 @@ var ChatWithTools = class {
|
|
|
3535
3676
|
onCreateSession: config.onCreateSession,
|
|
3536
3677
|
yourgptConfig: config.yourgptConfig,
|
|
3537
3678
|
debug: config.debug,
|
|
3679
|
+
streamMode: config.streamMode,
|
|
3538
3680
|
initialMessages: config.initialMessages,
|
|
3539
3681
|
state: config.state,
|
|
3540
3682
|
transport: config.transport,
|
|
@@ -3575,7 +3717,8 @@ var ChatWithTools = class {
|
|
|
3575
3717
|
(t) => t.name === info.name && t.location === "client"
|
|
3576
3718
|
);
|
|
3577
3719
|
if (isClientTool) {
|
|
3578
|
-
this.debug("
|
|
3720
|
+
this.debug("Tracking client tool for streaming render:", info.name);
|
|
3721
|
+
this.agentLoop.addServerToolExecution(info);
|
|
3579
3722
|
return;
|
|
3580
3723
|
}
|
|
3581
3724
|
this.debug("Server tool started:", info.name, {
|
|
@@ -3585,10 +3728,6 @@ var ChatWithTools = class {
|
|
|
3585
3728
|
this.agentLoop.addServerToolExecution(info);
|
|
3586
3729
|
},
|
|
3587
3730
|
onServerToolArgs: (info) => {
|
|
3588
|
-
const isClientTool = this.agentLoop.tools.some(
|
|
3589
|
-
(t) => t.name === info.name && t.location === "client"
|
|
3590
|
-
);
|
|
3591
|
-
if (isClientTool) return;
|
|
3592
3731
|
this.debug("Server tool args:", info.name, info.args);
|
|
3593
3732
|
this.agentLoop.updateServerToolArgs(info.id, info.args ?? {});
|
|
3594
3733
|
},
|
|
@@ -3636,6 +3775,10 @@ var ChatWithTools = class {
|
|
|
3636
3775
|
try {
|
|
3637
3776
|
const results = await this.agentLoop.executeToolCalls(toolCallInfos);
|
|
3638
3777
|
this.debug("Tool results:", results);
|
|
3778
|
+
if (this.agentLoop.isCancelled) {
|
|
3779
|
+
this.debug("Skipping continueWithToolResults \u2014 loop was cancelled");
|
|
3780
|
+
return;
|
|
3781
|
+
}
|
|
3639
3782
|
if (results.length > 0) {
|
|
3640
3783
|
const toolResults = results.map((r) => ({
|
|
3641
3784
|
toolCallId: r.toolCallId,
|
|
@@ -5079,7 +5222,7 @@ function useTools(tools) {
|
|
|
5079
5222
|
const registeredToolsRef = useRef([]);
|
|
5080
5223
|
const toolsRef = useRef(tools);
|
|
5081
5224
|
toolsRef.current = tools;
|
|
5082
|
-
const toolsKey = Object.
|
|
5225
|
+
const toolsKey = Object.entries(tools).sort(([a], [b]) => a.localeCompare(b)).map(([name, def]) => `${name}:${def.available ?? true}`).join(",");
|
|
5083
5226
|
useEffect(() => {
|
|
5084
5227
|
const currentTools = toolsRef.current;
|
|
5085
5228
|
const toolNames = [];
|
|
@@ -5414,6 +5557,7 @@ function CopilotProvider(props) {
|
|
|
5414
5557
|
onError,
|
|
5415
5558
|
parseError,
|
|
5416
5559
|
streaming,
|
|
5560
|
+
streamMode,
|
|
5417
5561
|
headers,
|
|
5418
5562
|
body,
|
|
5419
5563
|
debug = false,
|
|
@@ -5476,6 +5620,7 @@ function CopilotProvider(props) {
|
|
|
5476
5620
|
yourgptConfig,
|
|
5477
5621
|
initialMessages: uiInitialMessages,
|
|
5478
5622
|
streaming,
|
|
5623
|
+
streamMode,
|
|
5479
5624
|
headers,
|
|
5480
5625
|
body,
|
|
5481
5626
|
parseError,
|
|
@@ -5954,5 +6099,5 @@ function useMCPTools(config) {
|
|
|
5954
6099
|
}
|
|
5955
6100
|
|
|
5956
6101
|
export { AbstractAgentLoop, AbstractChat, CopilotProvider, MessageHistoryContext, MessageTree, ReactChatState, SkillProvider, createReactChatState, defaultMessageHistoryConfig, initialAgentLoopState, isCompactionMarker, keepToolPairsAtomic, toDisplayMessage, toLLMMessage, toLLMMessages, useAIContext, useAIContexts, useCopilot, useMCPClient, useMCPTools, useMessageHistory, useMessageHistoryContext, useSkillContext, useTool, useTools };
|
|
5957
|
-
//# sourceMappingURL=chunk-
|
|
5958
|
-
//# sourceMappingURL=chunk-
|
|
6102
|
+
//# sourceMappingURL=chunk-RBULQ6EJ.js.map
|
|
6103
|
+
//# sourceMappingURL=chunk-RBULQ6EJ.js.map
|