@yourgpt/copilot-sdk 2.1.5-alpha.7 → 2.1.5-alpha.8

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.
@@ -299,8 +299,16 @@ var HttpTransport = class {
299
299
  signal: this.abortController.signal
300
300
  });
301
301
  if (!response.ok) {
302
- const error = await response.text();
303
- throw new Error(`HTTP ${response.status}: ${error}`);
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
  }
@@ -2546,6 +2564,7 @@ ${this.dynamicContext}`.trim() : this.config.systemPrompt;
2546
2564
  }
2547
2565
  }
2548
2566
  this.callbacks.onMessagesChange?.(this._allMessages());
2567
+ this._activePlaceholderMessageId = void 0;
2549
2568
  this.debugGroupEnd();
2550
2569
  this.debug("stream end", {
2551
2570
  toolCallsEmitted,
@@ -2626,6 +2645,11 @@ ${this.dynamicContext}`.trim() : this.config.systemPrompt;
2626
2645
  */
2627
2646
  handleError(error) {
2628
2647
  this.debug("error", error);
2648
+ if (this._activePlaceholderMessageId) {
2649
+ this.state.popMessage();
2650
+ this._activePlaceholderMessageId = void 0;
2651
+ this.callbacks.onMessagesChange?.(this._allMessages());
2652
+ }
2629
2653
  this.state.error = error;
2630
2654
  this.state.status = "error";
2631
2655
  this.callbacks.onError?.(error);
@@ -3499,6 +3523,7 @@ var ChatWithTools = class {
3499
3523
  initialMessages: config.initialMessages,
3500
3524
  state: config.state,
3501
3525
  transport: config.transport,
3526
+ parseError: config.parseError,
3502
3527
  callbacks: {
3503
3528
  onMessagesChange: callbacks.onMessagesChange,
3504
3529
  onStatusChange: callbacks.onStatusChange,
@@ -5372,6 +5397,7 @@ function CopilotProvider(props) {
5372
5397
  initialMessages,
5373
5398
  onMessagesChange,
5374
5399
  onError,
5400
+ parseError,
5375
5401
  streaming,
5376
5402
  headers,
5377
5403
  body,
@@ -5437,6 +5463,7 @@ function CopilotProvider(props) {
5437
5463
  streaming,
5438
5464
  headers,
5439
5465
  body,
5466
+ parseError,
5440
5467
  debug,
5441
5468
  maxIterations,
5442
5469
  maxIterationsMessage,
@@ -5912,5 +5939,5 @@ function useMCPTools(config) {
5912
5939
  }
5913
5940
 
5914
5941
  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-UZHGMDOK.js.map
5916
- //# sourceMappingURL=chunk-UZHGMDOK.js.map
5942
+ //# sourceMappingURL=chunk-FDZVDGNR.js.map
5943
+ //# sourceMappingURL=chunk-FDZVDGNR.js.map