@copilotkit/core 1.68.3-canary.1787220377 → 1.69.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/index.cjs +101 -155
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +12 -71
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +12 -71
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +102 -155
- package/dist/index.mjs.map +1 -1
- package/dist/index.umd.js +118 -165
- package/dist/index.umd.js.map +1 -1
- package/package.json +3 -3
package/dist/index.umd.js
CHANGED
|
@@ -618,6 +618,32 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
618
618
|
}
|
|
619
619
|
};
|
|
620
620
|
|
|
621
|
+
//#endregion
|
|
622
|
+
//#region src/utils/runtime-info-error.ts
|
|
623
|
+
/**
|
|
624
|
+
* Build the error for a failed runtime `/info` response, folding in whatever
|
|
625
|
+
* explanation the runtime sent back.
|
|
626
|
+
*
|
|
627
|
+
* The status alone cannot distinguish a wrong `runtimeUrl` from a transport
|
|
628
|
+
* mismatch, so the runtime answers the latter with a body naming the cause
|
|
629
|
+
* (see the handler's `single_route_envelope_against_multi_route_runtime`
|
|
630
|
+
* diagnostic). Discarding that body — as every `/info` caller used to — left
|
|
631
|
+
* the developer with a bare 404 and nothing to act on (OSS-882).
|
|
632
|
+
*
|
|
633
|
+
* A body that isn't JSON, or carries no string `message`, contributes nothing:
|
|
634
|
+
* the status is then the whole error.
|
|
635
|
+
*/
|
|
636
|
+
async function runtimeInfoError(response) {
|
|
637
|
+
const base = `Runtime info request failed with status ${response.status}`;
|
|
638
|
+
let detail;
|
|
639
|
+
try {
|
|
640
|
+
const body = await response.clone().json();
|
|
641
|
+
const message = body === null || body === void 0 ? void 0 : body.message;
|
|
642
|
+
if (typeof message === "string" && message.trim().length > 0) detail = message.trim();
|
|
643
|
+
} catch (_unused) {}
|
|
644
|
+
return new Error(detail ? `${base}: ${detail}` : base);
|
|
645
|
+
}
|
|
646
|
+
|
|
621
647
|
//#endregion
|
|
622
648
|
//#region \0@oxc-project+runtime@0.112.0/helpers/checkPrivateRedeclaration.js
|
|
623
649
|
function _checkPrivateRedeclaration(e, t) {
|
|
@@ -947,7 +973,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
947
973
|
headers,
|
|
948
974
|
...this.credentials ? { credentials: this.credentials } : {}
|
|
949
975
|
});
|
|
950
|
-
if (!response.ok) throw
|
|
976
|
+
if (!response.ok) throw await runtimeInfoError(response);
|
|
951
977
|
return await response.json();
|
|
952
978
|
}
|
|
953
979
|
async fetchRuntimeInfoAutoDetect(headers) {
|
|
@@ -969,7 +995,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
969
995
|
body: JSON.stringify({ method: "info" }),
|
|
970
996
|
...this.credentials ? { credentials: this.credentials } : {}
|
|
971
997
|
});
|
|
972
|
-
if (!response.ok) throw
|
|
998
|
+
if (!response.ok) throw await runtimeInfoError(response);
|
|
973
999
|
this.transport = "single";
|
|
974
1000
|
this.singleEndpointUrl = this.runtimeUrl;
|
|
975
1001
|
return await response.json();
|
|
@@ -1602,7 +1628,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
1602
1628
|
headers,
|
|
1603
1629
|
...credentials ? { credentials } : {}
|
|
1604
1630
|
});
|
|
1605
|
-
if (!response.ok) throw
|
|
1631
|
+
if (!response.ok) throw await runtimeInfoError(response);
|
|
1606
1632
|
return {
|
|
1607
1633
|
runtimeInfo: await response.json(),
|
|
1608
1634
|
resolvedTransport: "rest"
|
|
@@ -1615,7 +1641,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
1615
1641
|
body: JSON.stringify({ method: "info" }),
|
|
1616
1642
|
...credentials ? { credentials } : {}
|
|
1617
1643
|
});
|
|
1618
|
-
if (!response.ok) throw
|
|
1644
|
+
if (!response.ok) throw await runtimeInfoError(response);
|
|
1619
1645
|
return await response.json();
|
|
1620
1646
|
}
|
|
1621
1647
|
/**
|
|
@@ -2912,6 +2938,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
2912
2938
|
this.core = core;
|
|
2913
2939
|
_defineProperty(this, "stateByRun", /* @__PURE__ */ new Map());
|
|
2914
2940
|
_defineProperty(this, "messageToRun", /* @__PURE__ */ new Map());
|
|
2941
|
+
_defineProperty(this, "rawEventByMessage", /* @__PURE__ */ new Map());
|
|
2915
2942
|
_defineProperty(this, "activeRun", /* @__PURE__ */ new Map());
|
|
2916
2943
|
_defineProperty(this, "agentSubscriptions", /* @__PURE__ */ new Map());
|
|
2917
2944
|
_defineProperty(this, "pendingContinuations", /* @__PURE__ */ new WeakMap());
|
|
@@ -2964,16 +2991,16 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
2964
2991
|
};
|
|
2965
2992
|
};
|
|
2966
2993
|
const { unsubscribe } = agent.subscribe({
|
|
2967
|
-
onRunStartedEvent: ({ input, state }) => {
|
|
2994
|
+
onRunStartedEvent: ({ event, input, state }) => {
|
|
2968
2995
|
if (revoked) return;
|
|
2969
2996
|
const pendingForAgent = this.pendingContinuations.get(agent);
|
|
2970
2997
|
const internalContinuation = [...pendingForAgent !== null && pendingForAgent !== void 0 ? pendingForAgent : []].find((pending) => pending.expectedInput === input);
|
|
2971
2998
|
internalContinuation === null || internalContinuation === void 0 || internalContinuation.cancel();
|
|
2972
|
-
if (
|
|
2973
|
-
|
|
2974
|
-
|
|
2975
|
-
|
|
2976
|
-
|
|
2999
|
+
if (internalContinuation) {
|
|
3000
|
+
var _ref, _internalContinuation;
|
|
3001
|
+
subRunId = (_ref = (_internalContinuation = internalContinuation.expectedRunId) !== null && _internalContinuation !== void 0 ? _internalContinuation : event.runId) !== null && _ref !== void 0 ? _ref : input.runId;
|
|
3002
|
+
} else if (runFinished && input.runId === subRunId && !isContinuation(input) && (event.runId == null || event.runId === subRunId)) subRunId = (0, _ag_ui_client.randomUUID)();
|
|
3003
|
+
else subRunId = event.runId || input.runId;
|
|
2977
3004
|
runFinished = false;
|
|
2978
3005
|
this.handleRunStarted(agent, effectiveInput(input), state);
|
|
2979
3006
|
},
|
|
@@ -2995,13 +3022,22 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
2995
3022
|
if (revoked) return;
|
|
2996
3023
|
this.handleStateDelta(agent, event, effectiveInput(input), state);
|
|
2997
3024
|
},
|
|
3025
|
+
onTextMessageStartEvent: ({ event, input }) => {
|
|
3026
|
+
if (revoked) return;
|
|
3027
|
+
this.handleTextMessageStart(agent, event, effectiveInput(input));
|
|
3028
|
+
},
|
|
2998
3029
|
onMessagesSnapshotEvent: ({ event, input, messages }) => {
|
|
2999
3030
|
if (revoked) return;
|
|
3000
3031
|
this.handleMessagesSnapshot(agent, event, effectiveInput(input), messages);
|
|
3032
|
+
this.pruneRawEvents(agent.agentId, input.threadId, event.messages, effectiveInput(input));
|
|
3001
3033
|
},
|
|
3002
3034
|
onNewMessage: ({ message, input }) => {
|
|
3003
3035
|
if (revoked) return;
|
|
3004
3036
|
this.handleNewMessage(agent, message, input ? effectiveInput(input) : void 0);
|
|
3037
|
+
},
|
|
3038
|
+
onMessagesChanged: ({ messages, input }) => {
|
|
3039
|
+
if (revoked) return;
|
|
3040
|
+
if (!input) this.pruneRawEvents(agent.agentId, agent.threadId, messages);
|
|
3005
3041
|
}
|
|
3006
3042
|
});
|
|
3007
3043
|
this.agentSubscriptions.set(agentId, () => {
|
|
@@ -3019,6 +3055,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
3019
3055
|
unsubscribe();
|
|
3020
3056
|
this.agentSubscriptions.delete(agentId);
|
|
3021
3057
|
}
|
|
3058
|
+
this.rawEventByMessage.delete(agentId);
|
|
3022
3059
|
}
|
|
3023
3060
|
/**
|
|
3024
3061
|
* Get state for a specific run
|
|
@@ -3038,6 +3075,14 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
3038
3075
|
return (_this$messageToRun$ge = this.messageToRun.get(agentId)) === null || _this$messageToRun$ge === void 0 || (_this$messageToRun$ge = _this$messageToRun$ge.get(threadId)) === null || _this$messageToRun$ge === void 0 ? void 0 : _this$messageToRun$ge.get(messageId);
|
|
3039
3076
|
}
|
|
3040
3077
|
/**
|
|
3078
|
+
* Get direct text-start metadata associated with a message.
|
|
3079
|
+
*/
|
|
3080
|
+
getRawEventForMessage(agentId, threadId, messageId) {
|
|
3081
|
+
var _this$rawEventByMessa;
|
|
3082
|
+
const rawEvent = (_this$rawEventByMessa = this.rawEventByMessage.get(agentId)) === null || _this$rawEventByMessa === void 0 || (_this$rawEventByMessa = _this$rawEventByMessa.get(threadId)) === null || _this$rawEventByMessa === void 0 ? void 0 : _this$rawEventByMessa.get(messageId);
|
|
3083
|
+
return rawEvent === void 0 ? void 0 : (0, _ag_ui_client.structuredClone_)(rawEvent);
|
|
3084
|
+
}
|
|
3085
|
+
/**
|
|
3041
3086
|
* Get all states for an agent's thread
|
|
3042
3087
|
*/
|
|
3043
3088
|
getStatesForThread(agentId, threadId) {
|
|
@@ -3091,12 +3136,34 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
3091
3136
|
this.saveState(agent.agentId, threadId, runId, state);
|
|
3092
3137
|
}
|
|
3093
3138
|
/**
|
|
3139
|
+
* Capture only defined metadata from a normalized direct text-start event.
|
|
3140
|
+
*/
|
|
3141
|
+
handleTextMessageStart(agent, event, input) {
|
|
3142
|
+
if (!agent.agentId) return;
|
|
3143
|
+
const { threadId } = input;
|
|
3144
|
+
if (event.rawEvent === void 0) {
|
|
3145
|
+
var _this$rawEventByMessa2, _this$rawEventByMessa4;
|
|
3146
|
+
const threadEvents = (_this$rawEventByMessa2 = this.rawEventByMessage.get(agent.agentId)) === null || _this$rawEventByMessa2 === void 0 ? void 0 : _this$rawEventByMessa2.get(threadId);
|
|
3147
|
+
threadEvents === null || threadEvents === void 0 || threadEvents.delete(event.messageId);
|
|
3148
|
+
if ((threadEvents === null || threadEvents === void 0 ? void 0 : threadEvents.size) === 0) {
|
|
3149
|
+
var _this$rawEventByMessa3;
|
|
3150
|
+
(_this$rawEventByMessa3 = this.rawEventByMessage.get(agent.agentId)) === null || _this$rawEventByMessa3 === void 0 || _this$rawEventByMessa3.delete(threadId);
|
|
3151
|
+
}
|
|
3152
|
+
if (((_this$rawEventByMessa4 = this.rawEventByMessage.get(agent.agentId)) === null || _this$rawEventByMessa4 === void 0 ? void 0 : _this$rawEventByMessa4.size) === 0) this.rawEventByMessage.delete(agent.agentId);
|
|
3153
|
+
return;
|
|
3154
|
+
}
|
|
3155
|
+
if (!this.rawEventByMessage.has(agent.agentId)) this.rawEventByMessage.set(agent.agentId, /* @__PURE__ */ new Map());
|
|
3156
|
+
const agentEvents = this.rawEventByMessage.get(agent.agentId);
|
|
3157
|
+
if (!agentEvents.has(threadId)) agentEvents.set(threadId, /* @__PURE__ */ new Map());
|
|
3158
|
+
agentEvents.get(threadId).set(event.messageId, event.rawEvent);
|
|
3159
|
+
}
|
|
3160
|
+
/**
|
|
3094
3161
|
* Handle messages snapshot event
|
|
3095
3162
|
*/
|
|
3096
3163
|
handleMessagesSnapshot(agent, event, input, messages) {
|
|
3097
3164
|
if (!agent.agentId) return;
|
|
3098
3165
|
const { threadId, runId } = input;
|
|
3099
|
-
for (const message of event.messages) this.associateMessageWithRun(agent.agentId, threadId, message.id, runId);
|
|
3166
|
+
for (const message of event.messages) if (this.getRunIdForMessage(agent.agentId, threadId, message.id) === void 0) this.associateMessageWithRun(agent.agentId, threadId, message.id, runId);
|
|
3100
3167
|
}
|
|
3101
3168
|
/**
|
|
3102
3169
|
* Handle new message event
|
|
@@ -3131,143 +3198,36 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
3131
3198
|
if (!agentMessages.has(threadId)) agentMessages.set(threadId, /* @__PURE__ */ new Map());
|
|
3132
3199
|
agentMessages.get(threadId).set(messageId, runId);
|
|
3133
3200
|
}
|
|
3201
|
+
pruneRawEvents(agentId, fallbackThreadId, messages, input) {
|
|
3202
|
+
var _input$threadId, _this$rawEventByMessa5, _this$rawEventByMessa7;
|
|
3203
|
+
const threadId = (_input$threadId = input === null || input === void 0 ? void 0 : input.threadId) !== null && _input$threadId !== void 0 ? _input$threadId : fallbackThreadId;
|
|
3204
|
+
if (!threadId) return;
|
|
3205
|
+
const threadEvents = (_this$rawEventByMessa5 = this.rawEventByMessage.get(agentId)) === null || _this$rawEventByMessa5 === void 0 ? void 0 : _this$rawEventByMessa5.get(threadId);
|
|
3206
|
+
if (!threadEvents) return;
|
|
3207
|
+
const messageIds = new Set(messages.map((message) => message.id));
|
|
3208
|
+
for (const messageId of threadEvents.keys()) if (!messageIds.has(messageId)) threadEvents.delete(messageId);
|
|
3209
|
+
if (threadEvents.size === 0) {
|
|
3210
|
+
var _this$rawEventByMessa6;
|
|
3211
|
+
(_this$rawEventByMessa6 = this.rawEventByMessage.get(agentId)) === null || _this$rawEventByMessa6 === void 0 || _this$rawEventByMessa6.delete(threadId);
|
|
3212
|
+
}
|
|
3213
|
+
if (((_this$rawEventByMessa7 = this.rawEventByMessage.get(agentId)) === null || _this$rawEventByMessa7 === void 0 ? void 0 : _this$rawEventByMessa7.size) === 0) this.rawEventByMessage.delete(agentId);
|
|
3214
|
+
}
|
|
3134
3215
|
/**
|
|
3135
3216
|
* Clear all state for an agent
|
|
3136
3217
|
*/
|
|
3137
3218
|
clearAgentState(agentId) {
|
|
3138
3219
|
this.stateByRun.delete(agentId);
|
|
3139
3220
|
this.messageToRun.delete(agentId);
|
|
3221
|
+
this.rawEventByMessage.delete(agentId);
|
|
3140
3222
|
}
|
|
3141
3223
|
/**
|
|
3142
3224
|
* Clear all state for a thread
|
|
3143
3225
|
*/
|
|
3144
3226
|
clearThreadState(agentId, threadId) {
|
|
3145
|
-
var _this$stateByRun$get4, _this$messageToRun$ge2;
|
|
3227
|
+
var _this$stateByRun$get4, _this$messageToRun$ge2, _this$rawEventByMessa8;
|
|
3146
3228
|
(_this$stateByRun$get4 = this.stateByRun.get(agentId)) === null || _this$stateByRun$get4 === void 0 || _this$stateByRun$get4.delete(threadId);
|
|
3147
3229
|
(_this$messageToRun$ge2 = this.messageToRun.get(agentId)) === null || _this$messageToRun$ge2 === void 0 || _this$messageToRun$ge2.delete(threadId);
|
|
3148
|
-
|
|
3149
|
-
};
|
|
3150
|
-
|
|
3151
|
-
//#endregion
|
|
3152
|
-
//#region src/core/subagent-registry.ts
|
|
3153
|
-
/**
|
|
3154
|
-
* Tracks subagent lifecycle events (SUBAGENT_STARTED / FINISHED / ERROR) per
|
|
3155
|
-
* owning agent so consumers can resolve a message's `subagentRunId` to a name,
|
|
3156
|
-
* description, and running status.
|
|
3157
|
-
*
|
|
3158
|
-
* Modeled on {@link SuggestionEngine}: an in-memory `Record` keyed by (owning)
|
|
3159
|
-
* agentId, mutated from streamed AG-UI events, made reactive by calling
|
|
3160
|
-
* `notifySubscribers(onSubagentsChanged)` after every change. It owns its own
|
|
3161
|
-
* per-agent `agent.subscribe` (like {@link StateManager}) so it is fully
|
|
3162
|
-
* self-contained and adds no coupling to the state/message tracking path.
|
|
3163
|
-
*
|
|
3164
|
-
* No-op for runs without subagents (a normal LangGraph run never emits
|
|
3165
|
-
* SUBAGENT_* events), so the registry simply stays empty.
|
|
3166
|
-
*/
|
|
3167
|
-
var SubagentRegistry = class {
|
|
3168
|
-
constructor(core) {
|
|
3169
|
-
this.core = core;
|
|
3170
|
-
_defineProperty(this, "_subagents", {});
|
|
3171
|
-
_defineProperty(this, "agentSubscriptions", /* @__PURE__ */ new Map());
|
|
3172
|
-
}
|
|
3173
|
-
/**
|
|
3174
|
-
* Subscribe to an agent's subagent lifecycle events. Idempotent per agentId:
|
|
3175
|
-
* an existing subscription for the same agent is revoked and replaced.
|
|
3176
|
-
*/
|
|
3177
|
-
subscribeToAgent(agent) {
|
|
3178
|
-
if (!agent.agentId) return;
|
|
3179
|
-
const agentId = agent.agentId;
|
|
3180
|
-
const existingUnsubscribe = this.agentSubscriptions.get(agentId);
|
|
3181
|
-
if (existingUnsubscribe) {
|
|
3182
|
-
existingUnsubscribe();
|
|
3183
|
-
this.agentSubscriptions.delete(agentId);
|
|
3184
|
-
}
|
|
3185
|
-
let revoked = false;
|
|
3186
|
-
const { unsubscribe } = agent.subscribe({
|
|
3187
|
-
onSubagentStartedEvent: ({ event }) => {
|
|
3188
|
-
if (revoked) return;
|
|
3189
|
-
this.handleStarted(agentId, event);
|
|
3190
|
-
},
|
|
3191
|
-
onSubagentFinishedEvent: ({ event }) => {
|
|
3192
|
-
if (revoked) return;
|
|
3193
|
-
this.handleFinished(agentId, event);
|
|
3194
|
-
},
|
|
3195
|
-
onSubagentErrorEvent: ({ event }) => {
|
|
3196
|
-
if (revoked) return;
|
|
3197
|
-
this.handleError(agentId, event);
|
|
3198
|
-
}
|
|
3199
|
-
});
|
|
3200
|
-
this.agentSubscriptions.set(agentId, () => {
|
|
3201
|
-
revoked = true;
|
|
3202
|
-
unsubscribe();
|
|
3203
|
-
});
|
|
3204
|
-
}
|
|
3205
|
-
/**
|
|
3206
|
-
* Unsubscribe an agent's subscription (symmetric with StateManager cleanup).
|
|
3207
|
-
*/
|
|
3208
|
-
unsubscribeFromAgent(agentId) {
|
|
3209
|
-
const unsubscribe = this.agentSubscriptions.get(agentId);
|
|
3210
|
-
if (unsubscribe) {
|
|
3211
|
-
unsubscribe();
|
|
3212
|
-
this.agentSubscriptions.delete(agentId);
|
|
3213
|
-
}
|
|
3214
|
-
}
|
|
3215
|
-
/**
|
|
3216
|
-
* Get the subagents observed for an owning agent, keyed by subagentRunId.
|
|
3217
|
-
* Returns a fresh shallow copy each call so consumers (and React state) see
|
|
3218
|
-
* a new reference when anything changed.
|
|
3219
|
-
*/
|
|
3220
|
-
getSubagents(agentId) {
|
|
3221
|
-
return { ...this._subagents[agentId] };
|
|
3222
|
-
}
|
|
3223
|
-
handleStarted(agentId, event) {
|
|
3224
|
-
var _this$_subagents, _this$_subagents$agen;
|
|
3225
|
-
const bucket = (_this$_subagents$agen = (_this$_subagents = this._subagents)[agentId]) !== null && _this$_subagents$agen !== void 0 ? _this$_subagents$agen : _this$_subagents[agentId] = {};
|
|
3226
|
-
bucket[event.subagentRunId] = {
|
|
3227
|
-
subagentRunId: event.subagentRunId,
|
|
3228
|
-
name: event.name,
|
|
3229
|
-
description: event.description,
|
|
3230
|
-
parentSubagentRunId: event.parentSubagentRunId,
|
|
3231
|
-
status: "running"
|
|
3232
|
-
};
|
|
3233
|
-
this.notifySubagentsChanged(agentId);
|
|
3234
|
-
}
|
|
3235
|
-
handleFinished(agentId, event) {
|
|
3236
|
-
const bucket = this._subagents[agentId];
|
|
3237
|
-
const existing = bucket === null || bucket === void 0 ? void 0 : bucket[event.subagentRunId];
|
|
3238
|
-
if (!bucket || !existing) return;
|
|
3239
|
-
bucket[event.subagentRunId] = {
|
|
3240
|
-
...existing,
|
|
3241
|
-
status: "finished"
|
|
3242
|
-
};
|
|
3243
|
-
this.notifySubagentsChanged(agentId);
|
|
3244
|
-
}
|
|
3245
|
-
handleError(agentId, event) {
|
|
3246
|
-
var _this$_subagents2, _this$_subagents2$age;
|
|
3247
|
-
const bucket = (_this$_subagents2$age = (_this$_subagents2 = this._subagents)[agentId]) !== null && _this$_subagents2$age !== void 0 ? _this$_subagents2$age : _this$_subagents2[agentId] = {};
|
|
3248
|
-
const existing = bucket[event.subagentRunId];
|
|
3249
|
-
bucket[event.subagentRunId] = existing ? {
|
|
3250
|
-
...existing,
|
|
3251
|
-
status: "error",
|
|
3252
|
-
error: event.message
|
|
3253
|
-
} : {
|
|
3254
|
-
subagentRunId: event.subagentRunId,
|
|
3255
|
-
name: event.subagentRunId,
|
|
3256
|
-
status: "error",
|
|
3257
|
-
error: event.message
|
|
3258
|
-
};
|
|
3259
|
-
this.notifySubagentsChanged(agentId);
|
|
3260
|
-
}
|
|
3261
|
-
async notifySubagentsChanged(agentId) {
|
|
3262
|
-
const subagents = this.getSubagents(agentId);
|
|
3263
|
-
await this.core.notifySubscribers((subscriber) => {
|
|
3264
|
-
var _subscriber$onSubagen;
|
|
3265
|
-
return (_subscriber$onSubagen = subscriber.onSubagentsChanged) === null || _subscriber$onSubagen === void 0 ? void 0 : _subscriber$onSubagen.call(subscriber, {
|
|
3266
|
-
copilotkit: this.core,
|
|
3267
|
-
agentId,
|
|
3268
|
-
subagents
|
|
3269
|
-
});
|
|
3270
|
-
}, "Subscriber onSubagentsChanged error:");
|
|
3230
|
+
(_this$rawEventByMessa8 = this.rawEventByMessage.get(agentId)) === null || _this$rawEventByMessa8 === void 0 || _this$rawEventByMessa8.delete(threadId);
|
|
3271
3231
|
}
|
|
3272
3232
|
};
|
|
3273
3233
|
|
|
@@ -4471,7 +4431,6 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
4471
4431
|
_defineProperty(this, "suggestionEngine", void 0);
|
|
4472
4432
|
_defineProperty(this, "runHandler", void 0);
|
|
4473
4433
|
_defineProperty(this, "stateManager", void 0);
|
|
4474
|
-
_defineProperty(this, "subagentRegistry", void 0);
|
|
4475
4434
|
_defineProperty(this, "threadStoreRegistry", void 0);
|
|
4476
4435
|
_defineProperty(this, "_memoryStore", void 0);
|
|
4477
4436
|
_defineProperty(this, "previousAgentIds", /* @__PURE__ */ new Set());
|
|
@@ -4484,7 +4443,6 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
4484
4443
|
this.suggestionEngine = new SuggestionEngine(this);
|
|
4485
4444
|
this.runHandler = new RunHandler(this);
|
|
4486
4445
|
this.stateManager = new StateManager(this);
|
|
4487
|
-
this.subagentRegistry = new SubagentRegistry(this);
|
|
4488
4446
|
this.threadStoreRegistry = new ThreadStoreRegistry(this);
|
|
4489
4447
|
this.agentRegistry.initialize(agents__unsafe_dev_only);
|
|
4490
4448
|
this.runHandler.initialize(tools);
|
|
@@ -4499,10 +4457,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
4499
4457
|
},
|
|
4500
4458
|
onAgentsChanged: ({ agents }) => {
|
|
4501
4459
|
Object.values(agents).forEach((agent) => {
|
|
4502
|
-
if (agent.agentId)
|
|
4503
|
-
this.stateManager.subscribeToAgent(agent);
|
|
4504
|
-
this.subagentRegistry.subscribeToAgent(agent);
|
|
4505
|
-
}
|
|
4460
|
+
if (agent.agentId) this.stateManager.subscribeToAgent(agent);
|
|
4506
4461
|
});
|
|
4507
4462
|
const currentAgentIds = new Set(Object.keys(agents));
|
|
4508
4463
|
for (const agentId of Object.keys(this.threadStoreRegistry.getAll())) if (this.previousAgentIds.has(agentId) && !currentAgentIds.has(agentId)) try {
|
|
@@ -4510,17 +4465,10 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
4510
4465
|
} catch (err) {
|
|
4511
4466
|
console.error(`CopilotKitCore.onAgentsChanged: threadStoreRegistry.unregister failed for "${agentId}":`, err);
|
|
4512
4467
|
}
|
|
4513
|
-
for (const agentId of this.previousAgentIds) if (!currentAgentIds.has(agentId)) {
|
|
4514
|
-
|
|
4515
|
-
|
|
4516
|
-
}
|
|
4517
|
-
console.error(`CopilotKitCore.onAgentsChanged: stateManager.unsubscribeFromAgent failed for "${agentId}":`, err);
|
|
4518
|
-
}
|
|
4519
|
-
try {
|
|
4520
|
-
this.subagentRegistry.unsubscribeFromAgent(agentId);
|
|
4521
|
-
} catch (err) {
|
|
4522
|
-
console.error(`CopilotKitCore.onAgentsChanged: subagentRegistry.unsubscribeFromAgent failed for "${agentId}":`, err);
|
|
4523
|
-
}
|
|
4468
|
+
for (const agentId of this.previousAgentIds) if (!currentAgentIds.has(agentId)) try {
|
|
4469
|
+
this.stateManager.unsubscribeFromAgent(agentId);
|
|
4470
|
+
} catch (err) {
|
|
4471
|
+
console.error(`CopilotKitCore.onAgentsChanged: stateManager.unsubscribeFromAgent failed for "${agentId}":`, err);
|
|
4524
4472
|
}
|
|
4525
4473
|
this.previousAgentIds = currentAgentIds;
|
|
4526
4474
|
}
|
|
@@ -4900,16 +4848,6 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
4900
4848
|
return this.suggestionEngine.getSuggestions(agentId);
|
|
4901
4849
|
}
|
|
4902
4850
|
/**
|
|
4903
|
-
* Subagent registry (delegated to SubagentRegistry).
|
|
4904
|
-
*
|
|
4905
|
-
* Returns the subagents observed for an owning agent during its run(s),
|
|
4906
|
-
* keyed by `subagentRunId`, each carrying `name` / `description` / `status`.
|
|
4907
|
-
* Empty for runs that never emit SUBAGENT_* events.
|
|
4908
|
-
*/
|
|
4909
|
-
getSubagents(agentId) {
|
|
4910
|
-
return this.subagentRegistry.getSubagents(agentId);
|
|
4911
|
-
}
|
|
4912
|
-
/**
|
|
4913
4851
|
* Tool management (delegated to RunHandler)
|
|
4914
4852
|
*/
|
|
4915
4853
|
addTool(tool) {
|
|
@@ -5135,6 +5073,9 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
5135
5073
|
getRunIdForMessage(agentId, threadId, messageId) {
|
|
5136
5074
|
return this.stateManager.getRunIdForMessage(agentId, threadId, messageId);
|
|
5137
5075
|
}
|
|
5076
|
+
getRawEventForMessage(agentId, threadId, messageId) {
|
|
5077
|
+
return this.stateManager.getRawEventForMessage(agentId, threadId, messageId);
|
|
5078
|
+
}
|
|
5138
5079
|
getRunIdsForThread(agentId, threadId) {
|
|
5139
5080
|
return this.stateManager.getRunIdsForThread(agentId, threadId);
|
|
5140
5081
|
}
|
|
@@ -5420,6 +5361,16 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
5420
5361
|
return typeof value === "string" && value.length > 0 ? value : void 0;
|
|
5421
5362
|
}
|
|
5422
5363
|
/**
|
|
5364
|
+
* REST `/threads` is agent-scoped. The Phoenix `user_meta` channel is not.
|
|
5365
|
+
* Drop live upserts that belong to a different agent, or one Inspector
|
|
5366
|
+
* `all-agents` flatten shows the same thread twice until a hard refresh.
|
|
5367
|
+
*/
|
|
5368
|
+
function threadMetadataTargetsAgent(payload, agentId) {
|
|
5369
|
+
if (!agentId || payload.operation === "deleted") return true;
|
|
5370
|
+
const threadAgentId = optionalString(payload.thread.agentId);
|
|
5371
|
+
return !threadAgentId || threadAgentId === agentId;
|
|
5372
|
+
}
|
|
5373
|
+
/**
|
|
5423
5374
|
* Converts gateway run-activity payloads into the internal TypeScript shape.
|
|
5424
5375
|
*/
|
|
5425
5376
|
function normalizeThreadRunActivityNotification(payload) {
|
|
@@ -5852,13 +5803,16 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
5852
5803
|
}))), ɵobservePhoenixJoinOutcome$(channel$).pipe((0, rxjs_operators.filter)((outcome) => outcome.type !== "joined"), (0, rxjs_operators.map)((outcome) => outcome.type === "timeout" ? threadSocketEvents.joinTimedOut({ sessionId: action.sessionId }) : threadSocketEvents.joinFailed({ sessionId: action.sessionId })))).pipe((0, rxjs_operators.takeUntil)((0, rxjs.merge)(shutdown$, fatalSocketShutdown$)));
|
|
5853
5804
|
});
|
|
5854
5805
|
}))),
|
|
5855
|
-
createEffect((actions$, state$) => actions$.pipe(ofType(threadSocketEvents.metadataReceived), (0, rxjs_operators.withLatestFrom)(state$), (0, rxjs_operators.filter)(([action, state]) =>
|
|
5806
|
+
createEffect((actions$, state$) => actions$.pipe(ofType(threadSocketEvents.metadataReceived), (0, rxjs_operators.withLatestFrom)(state$), (0, rxjs_operators.filter)(([action, state]) => {
|
|
5856
5807
|
var _state$context4;
|
|
5808
|
+
return action.sessionId === state.sessionId && threadMetadataTargetsAgent(action.payload, (_state$context4 = state.context) === null || _state$context4 === void 0 ? void 0 : _state$context4.agentId);
|
|
5809
|
+
}), (0, rxjs_operators.map)(([action, state]) => {
|
|
5810
|
+
var _state$context5;
|
|
5857
5811
|
if (action.payload.operation === "deleted") return threadDomainEvents.threadDeleted({
|
|
5858
5812
|
sessionId: action.sessionId,
|
|
5859
5813
|
threadId: action.payload.deleted.id
|
|
5860
5814
|
});
|
|
5861
|
-
if (action.payload.operation === "archived" && !((_state$
|
|
5815
|
+
if (action.payload.operation === "archived" && !((_state$context5 = state.context) === null || _state$context5 === void 0 ? void 0 : _state$context5.includeArchived)) return threadDomainEvents.threadDeleted({
|
|
5862
5816
|
sessionId: action.sessionId,
|
|
5863
5817
|
threadId: action.payload.threadId
|
|
5864
5818
|
});
|
|
@@ -6253,7 +6207,6 @@ exports.MemoryError = MemoryError;
|
|
|
6253
6207
|
exports.ProxiedCopilotRuntimeAgent = ProxiedCopilotRuntimeAgent;
|
|
6254
6208
|
exports.RunHandler = RunHandler;
|
|
6255
6209
|
exports.StateManager = StateManager;
|
|
6256
|
-
exports.SubagentRegistry = SubagentRegistry;
|
|
6257
6210
|
exports.SuggestionEngine = SuggestionEngine;
|
|
6258
6211
|
exports.ToolCallStatus = ToolCallStatus;
|
|
6259
6212
|
exports.completePartialMarkdown = completePartialMarkdown;
|