@yourgpt/copilot-sdk 2.1.5-alpha.7 → 2.1.6
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-UZHGMDOK.js → chunk-2JNH3T6H.js} +35 -6
- package/dist/chunk-2JNH3T6H.js.map +1 -0
- package/dist/{chunk-NPBOKT63.cjs → chunk-6ZTITCKU.cjs} +35 -6
- package/dist/chunk-6ZTITCKU.cjs.map +1 -0
- package/dist/{chunk-M66XAHSW.cjs → chunk-HIVSXIER.cjs} +16 -16
- package/dist/{chunk-M66XAHSW.cjs.map → chunk-HIVSXIER.cjs.map} +1 -1
- package/dist/{chunk-YHW6JZEF.js → chunk-SMNZHZM7.js} +3 -3
- package/dist/{chunk-YHW6JZEF.js.map → chunk-SMNZHZM7.js.map} +1 -1
- package/dist/experimental/index.cjs +2 -2
- package/dist/experimental/index.js +1 -1
- package/dist/react/index.cjs +62 -62
- package/dist/react/index.d.cts +15 -0
- package/dist/react/index.d.ts +15 -0
- package/dist/react/index.js +2 -2
- package/dist/styles.css +26 -0
- package/dist/ui/index.cjs +89 -20
- package/dist/ui/index.cjs.map +1 -1
- package/dist/ui/index.d.cts +3 -1
- package/dist/ui/index.d.ts +3 -1
- package/dist/ui/index.js +86 -17
- package/dist/ui/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-NPBOKT63.cjs.map +0 -1
- package/dist/chunk-UZHGMDOK.js.map +0 -1
|
@@ -299,8 +299,16 @@ var HttpTransport = class {
|
|
|
299
299
|
signal: this.abortController.signal
|
|
300
300
|
});
|
|
301
301
|
if (!response.ok) {
|
|
302
|
-
|
|
303
|
-
|
|
302
|
+
let errorMessage = `HTTP ${response.status}`;
|
|
303
|
+
try {
|
|
304
|
+
const errorBody = await response.json();
|
|
305
|
+
const custom = this.config.parseError?.(response.status, errorBody);
|
|
306
|
+
errorMessage = custom ?? errorBody?.message ?? errorBody?.error ?? JSON.stringify(errorBody);
|
|
307
|
+
} catch {
|
|
308
|
+
const text = await response.text();
|
|
309
|
+
if (text) errorMessage = text;
|
|
310
|
+
}
|
|
311
|
+
throw new Error(errorMessage);
|
|
304
312
|
}
|
|
305
313
|
const contentType = response.headers.get("content-type") || "";
|
|
306
314
|
if (contentType.includes("application/json")) {
|
|
@@ -1485,6 +1493,11 @@ var AbstractChat = class {
|
|
|
1485
1493
|
this.eventHandlers = /* @__PURE__ */ new Map();
|
|
1486
1494
|
// Current streaming state
|
|
1487
1495
|
this.streamState = null;
|
|
1496
|
+
// ID of the pending assistant placeholder pushed before a request.
|
|
1497
|
+
// Used by handleError() to pop (remove) the placeholder on failure so it
|
|
1498
|
+
// doesn't stay frozen. Error is surfaced via state.error only — never written
|
|
1499
|
+
// into message history.
|
|
1500
|
+
this._activePlaceholderMessageId = void 0;
|
|
1488
1501
|
/**
|
|
1489
1502
|
* Inline skills from the client (sent on every request for server to merge)
|
|
1490
1503
|
*/
|
|
@@ -1517,7 +1530,8 @@ var AbstractChat = class {
|
|
|
1517
1530
|
url: init.runtimeUrl,
|
|
1518
1531
|
headers: init.headers,
|
|
1519
1532
|
body: init.body,
|
|
1520
|
-
streaming: init.streaming ?? true
|
|
1533
|
+
streaming: init.streaming ?? true,
|
|
1534
|
+
parseError: init.parseError
|
|
1521
1535
|
});
|
|
1522
1536
|
this.callbacks = init.callbacks ?? {};
|
|
1523
1537
|
this.optimizer = new ChatContextOptimizer(init.optimization);
|
|
@@ -1597,6 +1611,7 @@ var AbstractChat = class {
|
|
|
1597
1611
|
});
|
|
1598
1612
|
this.state.pushMessage(preMsg);
|
|
1599
1613
|
preCreatedMessageId = preMsg.id;
|
|
1614
|
+
this._activePlaceholderMessageId = preMsg.id;
|
|
1600
1615
|
}
|
|
1601
1616
|
this.callbacks.onMessagesChange?.(this._allMessages());
|
|
1602
1617
|
this.callbacks.onStatusChange?.("submitted");
|
|
@@ -1730,6 +1745,7 @@ var AbstractChat = class {
|
|
|
1730
1745
|
this.state.pushMessage(userMessage);
|
|
1731
1746
|
}
|
|
1732
1747
|
this.state.status = "submitted";
|
|
1748
|
+
this.state.error = void 0;
|
|
1733
1749
|
this.callbacks.onMessagesChange?.(this._allMessages());
|
|
1734
1750
|
this.callbacks.onStatusChange?.("submitted");
|
|
1735
1751
|
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
@@ -1892,6 +1908,7 @@ var AbstractChat = class {
|
|
|
1892
1908
|
this.state.pushMessage(preMsg);
|
|
1893
1909
|
this.callbacks.onMessagesChange?.(this._allMessages());
|
|
1894
1910
|
preCreatedMessageId = preMsg.id;
|
|
1911
|
+
this._activePlaceholderMessageId = preMsg.id;
|
|
1895
1912
|
}
|
|
1896
1913
|
const response = await this.transport.send(request);
|
|
1897
1914
|
if (this.isAsyncIterable(response)) {
|
|
@@ -1908,6 +1925,7 @@ var AbstractChat = class {
|
|
|
1908
1925
|
this.state.setCurrentLeaf(intendedLeafId);
|
|
1909
1926
|
}
|
|
1910
1927
|
}
|
|
1928
|
+
this._activePlaceholderMessageId = void 0;
|
|
1911
1929
|
this.handleJsonResponse(response);
|
|
1912
1930
|
}
|
|
1913
1931
|
}
|
|
@@ -2193,7 +2211,7 @@ ${this.dynamicContext}`.trim() : this.config.systemPrompt;
|
|
|
2193
2211
|
this.handleError(error);
|
|
2194
2212
|
return;
|
|
2195
2213
|
}
|
|
2196
|
-
if (chunk.type === "message:end" && this.streamState?.
|
|
2214
|
+
if (chunk.type === "message:end" && this.streamState !== null && (this.streamState.content || (this.streamState.toolResults?.size ?? 0) > 0)) {
|
|
2197
2215
|
this.debug("message:end mid-stream", {
|
|
2198
2216
|
messageId: this.streamState.messageId,
|
|
2199
2217
|
contentLength: this.streamState.content.length,
|
|
@@ -2268,6 +2286,8 @@ ${this.dynamicContext}`.trim() : this.config.systemPrompt;
|
|
|
2268
2286
|
continue;
|
|
2269
2287
|
}
|
|
2270
2288
|
if (msg.role === "assistant" && !msg.tool_calls?.length) continue;
|
|
2289
|
+
if (msg.role === "assistant" && msg.tool_calls?.length && pendingIds.size === 0)
|
|
2290
|
+
continue;
|
|
2271
2291
|
messagesToInsert.push({
|
|
2272
2292
|
id: generateMessageId(),
|
|
2273
2293
|
role: msg.role,
|
|
@@ -2546,6 +2566,7 @@ ${this.dynamicContext}`.trim() : this.config.systemPrompt;
|
|
|
2546
2566
|
}
|
|
2547
2567
|
}
|
|
2548
2568
|
this.callbacks.onMessagesChange?.(this._allMessages());
|
|
2569
|
+
this._activePlaceholderMessageId = void 0;
|
|
2549
2570
|
this.debugGroupEnd();
|
|
2550
2571
|
this.debug("stream end", {
|
|
2551
2572
|
toolCallsEmitted,
|
|
@@ -2626,6 +2647,11 @@ ${this.dynamicContext}`.trim() : this.config.systemPrompt;
|
|
|
2626
2647
|
*/
|
|
2627
2648
|
handleError(error) {
|
|
2628
2649
|
this.debug("error", error);
|
|
2650
|
+
if (this._activePlaceholderMessageId) {
|
|
2651
|
+
this.state.popMessage();
|
|
2652
|
+
this._activePlaceholderMessageId = void 0;
|
|
2653
|
+
this.callbacks.onMessagesChange?.(this._allMessages());
|
|
2654
|
+
}
|
|
2629
2655
|
this.state.error = error;
|
|
2630
2656
|
this.state.status = "error";
|
|
2631
2657
|
this.callbacks.onError?.(error);
|
|
@@ -3499,6 +3525,7 @@ var ChatWithTools = class {
|
|
|
3499
3525
|
initialMessages: config.initialMessages,
|
|
3500
3526
|
state: config.state,
|
|
3501
3527
|
transport: config.transport,
|
|
3528
|
+
parseError: config.parseError,
|
|
3502
3529
|
callbacks: {
|
|
3503
3530
|
onMessagesChange: callbacks.onMessagesChange,
|
|
3504
3531
|
onStatusChange: callbacks.onStatusChange,
|
|
@@ -5372,6 +5399,7 @@ function CopilotProvider(props) {
|
|
|
5372
5399
|
initialMessages,
|
|
5373
5400
|
onMessagesChange,
|
|
5374
5401
|
onError,
|
|
5402
|
+
parseError,
|
|
5375
5403
|
streaming,
|
|
5376
5404
|
headers,
|
|
5377
5405
|
body,
|
|
@@ -5437,6 +5465,7 @@ function CopilotProvider(props) {
|
|
|
5437
5465
|
streaming,
|
|
5438
5466
|
headers,
|
|
5439
5467
|
body,
|
|
5468
|
+
parseError,
|
|
5440
5469
|
debug,
|
|
5441
5470
|
maxIterations,
|
|
5442
5471
|
maxIterationsMessage,
|
|
@@ -5912,5 +5941,5 @@ function useMCPTools(config) {
|
|
|
5912
5941
|
}
|
|
5913
5942
|
|
|
5914
5943
|
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 };
|
|
5915
|
-
//# sourceMappingURL=chunk-
|
|
5916
|
-
//# sourceMappingURL=chunk-
|
|
5944
|
+
//# sourceMappingURL=chunk-2JNH3T6H.js.map
|
|
5945
|
+
//# sourceMappingURL=chunk-2JNH3T6H.js.map
|