@yourgpt/copilot-sdk 1.2.2 → 1.2.4
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-34LUNTCZ.js → chunk-CVZ7LT5B.js} +35 -11
- package/dist/chunk-CVZ7LT5B.js.map +1 -0
- package/dist/{chunk-DLM5KOFK.cjs → chunk-RMVUGFSK.cjs} +35 -11
- package/dist/chunk-RMVUGFSK.cjs.map +1 -0
- package/dist/react/index.cjs +37 -37
- package/dist/react/index.d.cts +14 -1
- package/dist/react/index.d.ts +14 -1
- package/dist/react/index.js +1 -1
- package/dist/ui/index.cjs +4 -4
- package/dist/ui/index.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-34LUNTCZ.js.map +0 -1
- package/dist/chunk-DLM5KOFK.cjs.map +0 -1
|
@@ -62,6 +62,12 @@ var SimpleChatState = class {
|
|
|
62
62
|
const lastIndex = this._messages.length - 1;
|
|
63
63
|
this.replaceMessage(lastIndex, updater(this._messages[lastIndex]));
|
|
64
64
|
}
|
|
65
|
+
updateMessageById(id, updater) {
|
|
66
|
+
const index = this._messages.findIndex((m) => m.id === id);
|
|
67
|
+
if (index === -1) return false;
|
|
68
|
+
this.replaceMessage(index, updater(this._messages[index]));
|
|
69
|
+
return true;
|
|
70
|
+
}
|
|
65
71
|
setMessages(messages) {
|
|
66
72
|
this._messages = messages;
|
|
67
73
|
this.notify();
|
|
@@ -126,10 +132,7 @@ function requiresToolExecution(chunk) {
|
|
|
126
132
|
function processStreamChunk(chunk, state) {
|
|
127
133
|
switch (chunk.type) {
|
|
128
134
|
case "message:start":
|
|
129
|
-
return
|
|
130
|
-
...state,
|
|
131
|
-
messageId: chunk.id
|
|
132
|
-
};
|
|
135
|
+
return state;
|
|
133
136
|
case "message:delta":
|
|
134
137
|
return {
|
|
135
138
|
...state,
|
|
@@ -768,7 +771,7 @@ ${this.dynamicContext}`.trim() : this.config.systemPrompt,
|
|
|
768
771
|
}
|
|
769
772
|
this.streamState = processStreamChunk(chunk, this.streamState);
|
|
770
773
|
const updatedMessage = streamStateToMessage(this.streamState);
|
|
771
|
-
this.state.
|
|
774
|
+
this.state.updateMessageById(this.streamState.messageId, () => updatedMessage);
|
|
772
775
|
if (chunk.type === "message:delta") {
|
|
773
776
|
this.callbacks.onMessageDelta?.(assistantMessage.id, chunk.content);
|
|
774
777
|
}
|
|
@@ -784,7 +787,7 @@ ${this.dynamicContext}`.trim() : this.config.systemPrompt,
|
|
|
784
787
|
}
|
|
785
788
|
this.debug("handleStreamResponse", `Processed ${chunkCount} chunks`);
|
|
786
789
|
const finalMessage = streamStateToMessage(this.streamState);
|
|
787
|
-
this.state.
|
|
790
|
+
this.state.updateMessageById(this.streamState.messageId, () => finalMessage);
|
|
788
791
|
this.state.status = "ready";
|
|
789
792
|
if (!finalMessage.content && (!finalMessage.toolCalls || finalMessage.toolCalls.length === 0)) {
|
|
790
793
|
this.debug("warning", "Empty response - no content and no tool calls");
|
|
@@ -1137,6 +1140,14 @@ var AbstractAgentLoop = class {
|
|
|
1137
1140
|
this.clearToolExecutions();
|
|
1138
1141
|
this.pendingApprovals.clear();
|
|
1139
1142
|
}
|
|
1143
|
+
/**
|
|
1144
|
+
* Reset iteration counter only (allows continuing after max iterations)
|
|
1145
|
+
* Called when user sends a new message
|
|
1146
|
+
*/
|
|
1147
|
+
resetIterations() {
|
|
1148
|
+
this.setIteration(0);
|
|
1149
|
+
this._maxIterationsReached = false;
|
|
1150
|
+
}
|
|
1140
1151
|
/**
|
|
1141
1152
|
* Update configuration
|
|
1142
1153
|
*/
|
|
@@ -1245,11 +1256,12 @@ var ChatWithTools = class {
|
|
|
1245
1256
|
await this.chat.continueWithToolResults(toolResults);
|
|
1246
1257
|
} else if (this.agentLoop.maxIterationsReached && toolCallInfos.length > 0) {
|
|
1247
1258
|
this.debug("Max iterations reached, adding blocked tool results");
|
|
1259
|
+
const errorMessage = this.config.maxIterationsMessage || "Tool execution paused: iteration limit reached. User can say 'continue' to resume.";
|
|
1248
1260
|
const blockedResults = toolCallInfos.map((tc) => ({
|
|
1249
1261
|
toolCallId: tc.id,
|
|
1250
1262
|
result: {
|
|
1251
1263
|
success: false,
|
|
1252
|
-
error:
|
|
1264
|
+
error: errorMessage
|
|
1253
1265
|
}
|
|
1254
1266
|
}));
|
|
1255
1267
|
await this.chat.continueWithToolResults(blockedResults);
|
|
@@ -1300,6 +1312,7 @@ var ChatWithTools = class {
|
|
|
1300
1312
|
* Send a message
|
|
1301
1313
|
*/
|
|
1302
1314
|
async sendMessage(content, attachments) {
|
|
1315
|
+
this.agentLoop.resetIterations();
|
|
1303
1316
|
await this.chat.sendMessage(content, attachments);
|
|
1304
1317
|
}
|
|
1305
1318
|
/**
|
|
@@ -1491,6 +1504,15 @@ var ReactChatState = class {
|
|
|
1491
1504
|
];
|
|
1492
1505
|
this.notify();
|
|
1493
1506
|
}
|
|
1507
|
+
updateMessageById(id, updater) {
|
|
1508
|
+
const index = this._messages.findIndex((m) => m.id === id);
|
|
1509
|
+
if (index === -1) return false;
|
|
1510
|
+
this._messages = this._messages.map(
|
|
1511
|
+
(m, i) => i === index ? updater(m) : m
|
|
1512
|
+
);
|
|
1513
|
+
this.notify();
|
|
1514
|
+
return true;
|
|
1515
|
+
}
|
|
1494
1516
|
setMessages(messages) {
|
|
1495
1517
|
this._messages = messages;
|
|
1496
1518
|
this.notify();
|
|
@@ -1628,7 +1650,8 @@ function CopilotProvider({
|
|
|
1628
1650
|
onError,
|
|
1629
1651
|
streaming,
|
|
1630
1652
|
debug = false,
|
|
1631
|
-
maxIterations
|
|
1653
|
+
maxIterations,
|
|
1654
|
+
maxIterationsMessage
|
|
1632
1655
|
}) {
|
|
1633
1656
|
const debugLog = useCallback(
|
|
1634
1657
|
(...args) => {
|
|
@@ -1665,7 +1688,8 @@ function CopilotProvider({
|
|
|
1665
1688
|
initialMessages: uiInitialMessages,
|
|
1666
1689
|
streaming,
|
|
1667
1690
|
debug,
|
|
1668
|
-
maxIterations
|
|
1691
|
+
maxIterations,
|
|
1692
|
+
maxIterationsMessage
|
|
1669
1693
|
},
|
|
1670
1694
|
{
|
|
1671
1695
|
onToolExecutionsChange: (executions) => {
|
|
@@ -3578,5 +3602,5 @@ function useChat(config) {
|
|
|
3578
3602
|
}
|
|
3579
3603
|
|
|
3580
3604
|
export { AbstractAgentLoop, AbstractChat, CopilotProvider, ReactChat, ReactChatState, ReactThreadManager, ReactThreadManagerState, createPermissionStorage, createReactChat, createReactChatState, createReactThreadManager, createReactThreadManagerState, createSessionPermissionCache, formatKnowledgeResultsForAI, initialAgentLoopState, searchKnowledgeBase, useAIAction, useAIActions, useAIContext, useAIContexts, useAITools, useAgent, useCapabilities, useChat, useCopilot, useDevLogger, useFeatureSupport, useKnowledgeBase, useSuggestions, useSupportedMediaTypes, useThreadManager, useTool, useToolExecutor, useToolWithSchema, useTools, useToolsWithSchema };
|
|
3581
|
-
//# sourceMappingURL=chunk-
|
|
3582
|
-
//# sourceMappingURL=chunk-
|
|
3605
|
+
//# sourceMappingURL=chunk-CVZ7LT5B.js.map
|
|
3606
|
+
//# sourceMappingURL=chunk-CVZ7LT5B.js.map
|