@copilotkit/core 1.61.1 → 1.61.2
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 +107 -38
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +99 -25
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +99 -25
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +107 -38
- package/dist/index.mjs.map +1 -1
- package/dist/index.umd.js +97 -42
- package/dist/index.umd.js.map +1 -1
- package/package.json +3 -2
package/dist/index.umd.js
CHANGED
|
@@ -193,16 +193,6 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
193
193
|
_defineProperty(this, "activeChannel", null);
|
|
194
194
|
_defineProperty(this, "canonicalRunId", null);
|
|
195
195
|
_defineProperty(this, "sharedState", void 0);
|
|
196
|
-
_defineProperty(
|
|
197
|
-
this,
|
|
198
|
-
/**
|
|
199
|
-
* Resolves when the active run's pipeline finalizes; `undefined` between runs.
|
|
200
|
-
* Set/cleared inside {@link connectAgent}'s observable lifecycle. Declared
|
|
201
|
-
* here so {@link RunCompletionAware} consumers can read it without a cast.
|
|
202
|
-
*/
|
|
203
|
-
"activeRunCompletionPromise",
|
|
204
|
-
void 0
|
|
205
|
-
);
|
|
206
196
|
this.config = config;
|
|
207
197
|
this.sharedState = sharedState;
|
|
208
198
|
}
|
|
@@ -247,7 +237,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
247
237
|
const previousMessageIds = new Set(this.messages.map((m) => m.id));
|
|
248
238
|
const subscribers = [
|
|
249
239
|
{ onRunFinishedEvent: (event) => {
|
|
250
|
-
result = event.result;
|
|
240
|
+
if (event.outcome === "success") result = event.result;
|
|
251
241
|
} },
|
|
252
242
|
...this.subscribers,
|
|
253
243
|
subscriber !== null && subscriber !== void 0 ? subscriber : {}
|
|
@@ -255,10 +245,10 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
255
245
|
await this.onInitialize(input, subscribers);
|
|
256
246
|
self.activeRunDetach$ = new rxjs.Subject();
|
|
257
247
|
let resolveCompletion;
|
|
258
|
-
|
|
248
|
+
self.activeRunCompletionPromise = new Promise((resolve) => {
|
|
259
249
|
resolveCompletion = resolve;
|
|
260
250
|
});
|
|
261
|
-
const source$ = (0, rxjs.defer)(() => this.connect(input)).pipe((0, _ag_ui_client.transformChunks)(this.
|
|
251
|
+
const source$ = (0, rxjs.defer)(() => this.connect(input)).pipe((0, _ag_ui_client.transformChunks)(this.debugLogger), (0, rxjs_operators.takeUntil)(self.activeRunDetach$));
|
|
262
252
|
const applied$ = this.apply(input, source$, subscribers);
|
|
263
253
|
await (0, rxjs.lastValueFrom)(this.processApplyEvents(input, applied$, subscribers).pipe((0, rxjs_operators.catchError)((error) => {
|
|
264
254
|
this.isRunning = false;
|
|
@@ -268,7 +258,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
268
258
|
this.onFinalize(input, subscribers);
|
|
269
259
|
resolveCompletion === null || resolveCompletion === void 0 || resolveCompletion();
|
|
270
260
|
resolveCompletion = void 0;
|
|
271
|
-
|
|
261
|
+
self.activeRunCompletionPromise = void 0;
|
|
272
262
|
self.activeRunDetach$ = void 0;
|
|
273
263
|
})), { defaultValue: void 0 });
|
|
274
264
|
const newMessages = (0, _ag_ui_client.structuredClone_)(this.messages).filter((m) => !previousMessageIds.has(m.id));
|
|
@@ -810,8 +800,9 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
810
800
|
cloned.setState(this.state);
|
|
811
801
|
cloned.setMessages(this.messages);
|
|
812
802
|
if (this.delegate) {
|
|
813
|
-
|
|
814
|
-
cloned.
|
|
803
|
+
const clonedDelegate = this.delegate.clone();
|
|
804
|
+
cloned.delegate = clonedDelegate;
|
|
805
|
+
cloned.syncDelegate(clonedDelegate);
|
|
815
806
|
}
|
|
816
807
|
return cloned;
|
|
817
808
|
}
|
|
@@ -1000,6 +991,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
1000
991
|
_defineProperty(this, "_openGenerativeUIEnabled", false);
|
|
1001
992
|
_defineProperty(this, "_licenseStatus", void 0);
|
|
1002
993
|
_defineProperty(this, "_telemetryDisabled", false);
|
|
994
|
+
_defineProperty(this, "agentOwnHeaders", /* @__PURE__ */ new WeakMap());
|
|
1003
995
|
}
|
|
1004
996
|
/**
|
|
1005
997
|
* Get all agents as a readonly record
|
|
@@ -1170,10 +1162,19 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
1170
1162
|
console.warn(`Agent ${id} not found`);
|
|
1171
1163
|
}
|
|
1172
1164
|
/**
|
|
1173
|
-
* Apply current headers to an agent
|
|
1165
|
+
* Apply current core headers to an agent, merged ON TOP of the agent's own
|
|
1166
|
+
* construction-time headers (the per-agent baseline in `agentOwnHeaders`).
|
|
1167
|
+
* Core wins on a key conflict. Non-`HttpAgent` agents are left untouched
|
|
1168
|
+
* because only `HttpAgent` carries a `headers` field. See #5635.
|
|
1174
1169
|
*/
|
|
1175
1170
|
applyHeadersToAgent(agent) {
|
|
1176
|
-
if (agent instanceof _ag_ui_client.HttpAgent)
|
|
1171
|
+
if (agent instanceof _ag_ui_client.HttpAgent) {
|
|
1172
|
+
if (!this.agentOwnHeaders.has(agent)) this.agentOwnHeaders.set(agent, { ...agent.headers });
|
|
1173
|
+
agent.headers = {
|
|
1174
|
+
...this.agentOwnHeaders.get(agent),
|
|
1175
|
+
...this.core.headers
|
|
1176
|
+
};
|
|
1177
|
+
}
|
|
1177
1178
|
}
|
|
1178
1179
|
/**
|
|
1179
1180
|
* Apply current headers to all agents
|
|
@@ -1852,7 +1853,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
1852
1853
|
const proxied = agent;
|
|
1853
1854
|
if (incomingThreadId && typeof proxied.clearReplayCursor === "function") proxied.clearReplayCursor(incomingThreadId);
|
|
1854
1855
|
}
|
|
1855
|
-
|
|
1856
|
+
this._internal.applyHeadersToAgent(agent);
|
|
1856
1857
|
const runAgentResult = await agent.connectAgent({
|
|
1857
1858
|
forwardedProps: this._internal.properties,
|
|
1858
1859
|
tools: this.buildFrontendTools(agent.agentId),
|
|
@@ -1873,15 +1874,18 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
1873
1874
|
context
|
|
1874
1875
|
});
|
|
1875
1876
|
}
|
|
1876
|
-
return {
|
|
1877
|
+
return {
|
|
1878
|
+
result: void 0,
|
|
1879
|
+
newMessages: []
|
|
1880
|
+
};
|
|
1877
1881
|
}
|
|
1878
1882
|
}
|
|
1879
1883
|
/**
|
|
1880
1884
|
* Run an agent
|
|
1881
1885
|
*/
|
|
1882
|
-
async runAgent({ agent, forwardedProps }) {
|
|
1886
|
+
async runAgent({ agent, forwardedProps, resume }) {
|
|
1883
1887
|
if (agent.agentId) this._internal.suggestionEngine.clearSuggestions(agent.agentId);
|
|
1884
|
-
|
|
1888
|
+
this._internal.applyHeadersToAgent(agent);
|
|
1885
1889
|
if (agent.detachActiveRun) await agent.detachActiveRun();
|
|
1886
1890
|
const isTopLevel = this._runDepth === 0;
|
|
1887
1891
|
let originalAbortRun;
|
|
@@ -1901,6 +1905,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
1901
1905
|
...this._internal.properties,
|
|
1902
1906
|
...forwardedProps
|
|
1903
1907
|
},
|
|
1908
|
+
...resume !== void 0 ? { resume } : {},
|
|
1904
1909
|
tools: this.buildFrontendTools(agent.agentId),
|
|
1905
1910
|
context: this._internal.getContextForAgent(agent.agentId)
|
|
1906
1911
|
}, this.createAgentErrorSubscriber(agent));
|
|
@@ -1917,7 +1922,10 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
1917
1922
|
code: CopilotKitCoreErrorCode.AGENT_RUN_FAILED,
|
|
1918
1923
|
context
|
|
1919
1924
|
});
|
|
1920
|
-
return {
|
|
1925
|
+
return {
|
|
1926
|
+
result: void 0,
|
|
1927
|
+
newMessages: []
|
|
1928
|
+
};
|
|
1921
1929
|
} finally {
|
|
1922
1930
|
this._runDepth--;
|
|
1923
1931
|
if (isTopLevel && originalAbortRun) agent.abortRun = originalAbortRun;
|
|
@@ -2203,18 +2211,19 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
2203
2211
|
throw error;
|
|
2204
2212
|
}
|
|
2205
2213
|
const toolCallId = (0, _copilotkit_shared.randomUUID)();
|
|
2214
|
+
const assistantToolCall = {
|
|
2215
|
+
id: toolCallId,
|
|
2216
|
+
type: "function",
|
|
2217
|
+
function: {
|
|
2218
|
+
name,
|
|
2219
|
+
arguments: JSON.stringify(parameters)
|
|
2220
|
+
}
|
|
2221
|
+
};
|
|
2206
2222
|
const assistantMessage = {
|
|
2207
2223
|
id: (0, _copilotkit_shared.randomUUID)(),
|
|
2208
2224
|
role: "assistant",
|
|
2209
2225
|
content: "",
|
|
2210
|
-
toolCalls: [
|
|
2211
|
-
id: toolCallId,
|
|
2212
|
-
type: "function",
|
|
2213
|
-
function: {
|
|
2214
|
-
name,
|
|
2215
|
-
arguments: JSON.stringify(parameters)
|
|
2216
|
-
}
|
|
2217
|
-
}]
|
|
2226
|
+
toolCalls: [assistantToolCall]
|
|
2218
2227
|
};
|
|
2219
2228
|
agent.messages.push(assistantMessage);
|
|
2220
2229
|
let handlerResult = {
|
|
@@ -2224,7 +2233,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
2224
2233
|
};
|
|
2225
2234
|
if (tool.handler) handlerResult = await this.executeToolHandler({
|
|
2226
2235
|
tool,
|
|
2227
|
-
toolCall:
|
|
2236
|
+
toolCall: assistantToolCall,
|
|
2228
2237
|
agent,
|
|
2229
2238
|
agentId: resolvedAgentId,
|
|
2230
2239
|
handlerArgs: parameters,
|
|
@@ -2314,9 +2323,9 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
2314
2323
|
*/
|
|
2315
2324
|
function createToolSchema(tool) {
|
|
2316
2325
|
if (!tool.parameters) return { ...EMPTY_TOOL_SCHEMA };
|
|
2317
|
-
const rawSchema = (0, _copilotkit_shared.schemaToJsonSchema)(tool.parameters, { zodToJsonSchema: zod_to_json_schema.zodToJsonSchema });
|
|
2326
|
+
const rawSchema = (0, _copilotkit_shared.schemaToJsonSchema)(tool.parameters, { zodToJsonSchema: (schema, options) => (0, zod_to_json_schema.zodToJsonSchema)(schema, options) });
|
|
2318
2327
|
if (!rawSchema || typeof rawSchema !== "object") return { ...EMPTY_TOOL_SCHEMA };
|
|
2319
|
-
const { $schema, ...schema } = rawSchema;
|
|
2328
|
+
const { $schema: _$schema, ...schema } = rawSchema;
|
|
2320
2329
|
if (typeof schema.type !== "string") schema.type = "object";
|
|
2321
2330
|
if (typeof schema.properties !== "object" || schema.properties === null) schema.properties = {};
|
|
2322
2331
|
stripAdditionalProperties(schema);
|
|
@@ -2915,9 +2924,19 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
2915
2924
|
* });
|
|
2916
2925
|
* ```
|
|
2917
2926
|
*
|
|
2918
|
-
* The resulting header set is also re-applied to every
|
|
2919
|
-
* `
|
|
2920
|
-
*
|
|
2927
|
+
* The resulting header set is also re-applied to every agent in the registry
|
|
2928
|
+
* and `onHeadersChanged` subscribers are notified. These headers are merged
|
|
2929
|
+
* ON TOP of the headers each `HttpAgent` was constructed with, so per-agent
|
|
2930
|
+
* headers (e.g. an `Authorization` for a self-hosted backend) are preserved;
|
|
2931
|
+
* on a key conflict the core-level value wins.
|
|
2932
|
+
*
|
|
2933
|
+
* Because the agent's construction-time headers form the merge baseline, this
|
|
2934
|
+
* method can override a per-agent header but cannot REMOVE one: clearing a
|
|
2935
|
+
* core key here only drops the core-level override, after which the agent's
|
|
2936
|
+
* own value (if any) re-surfaces. To change a header an agent was constructed
|
|
2937
|
+
* with, set it at the provider/core level instead of on the agent, or update
|
|
2938
|
+
* it on the agent directly. The clear-on-logout pattern above is for
|
|
2939
|
+
* core-level headers.
|
|
2921
2940
|
*/
|
|
2922
2941
|
setHeaders(headers) {
|
|
2923
2942
|
this._headers = normalizeHeaders(headers);
|
|
@@ -2982,6 +3001,23 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
2982
3001
|
return this.agentRegistry.getAgent(id);
|
|
2983
3002
|
}
|
|
2984
3003
|
/**
|
|
3004
|
+
* Re-apply the current headers to a single agent (delegated to
|
|
3005
|
+
* AgentRegistry). Core headers are merged on top of the agent's own
|
|
3006
|
+
* construction-time headers rather than replacing them, so headers
|
|
3007
|
+
* configured directly on an `HttpAgent` (e.g. an `Authorization` for a
|
|
3008
|
+
* self-hosted backend) survive header updates instead of being silently
|
|
3009
|
+
* dropped (see #5635). On a key conflict the core-level value wins.
|
|
3010
|
+
*
|
|
3011
|
+
* The merge baseline is the agent's headers as captured the first time the
|
|
3012
|
+
* agent is applied (at registration), so the way to change headers
|
|
3013
|
+
* afterwards is `setHeaders` (which re-applies to every agent), not mutating
|
|
3014
|
+
* `agent.headers` directly — a direct mutation is overwritten on the next
|
|
3015
|
+
* re-apply.
|
|
3016
|
+
*/
|
|
3017
|
+
applyHeadersToAgent(agent) {
|
|
3018
|
+
this.agentRegistry.applyHeadersToAgent(agent);
|
|
3019
|
+
}
|
|
3020
|
+
/**
|
|
2985
3021
|
* Context management (delegated to ContextStore).
|
|
2986
3022
|
* Pass `agentIds` to restrict the entry to runs of specific agents;
|
|
2987
3023
|
* omit it for context every agent should receive.
|
|
@@ -3710,6 +3746,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
3710
3746
|
fetchNextPageRequested: empty(),
|
|
3711
3747
|
renameRequested: props(),
|
|
3712
3748
|
archiveRequested: props(),
|
|
3749
|
+
unarchiveRequested: props(),
|
|
3713
3750
|
deleteRequested: props()
|
|
3714
3751
|
});
|
|
3715
3752
|
const threadRestEvents = createActionGroup("Thread REST", {
|
|
@@ -3853,13 +3890,16 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
3853
3890
|
threadRequestId += 1;
|
|
3854
3891
|
return `thread-request-${threadRequestId}`;
|
|
3855
3892
|
}
|
|
3893
|
+
function threadFromFetch(input, init) {
|
|
3894
|
+
return (0, rxjs_fetch.fromFetch)(input, init);
|
|
3895
|
+
}
|
|
3856
3896
|
function createThreadFetchObservable(environment, context, sessionId) {
|
|
3857
3897
|
return (0, rxjs.defer)(() => {
|
|
3858
3898
|
const params = { agentId: context.agentId };
|
|
3859
3899
|
if (context.includeArchived) params.includeArchived = "true";
|
|
3860
3900
|
if (context.limit != null) params.limit = String(context.limit);
|
|
3861
3901
|
const qs = new URLSearchParams(params);
|
|
3862
|
-
return (
|
|
3902
|
+
return threadFromFetch(`${context.runtimeUrl}/threads?${qs.toString()}`, {
|
|
3863
3903
|
selector: (response) => {
|
|
3864
3904
|
if (!response.ok) throw new Error(`Failed to fetch threads: ${response.status}`);
|
|
3865
3905
|
return response.json();
|
|
@@ -3890,7 +3930,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
3890
3930
|
}
|
|
3891
3931
|
function createThreadMetadataCredentialsObservable(environment, context, sessionId) {
|
|
3892
3932
|
return (0, rxjs.defer)(() => {
|
|
3893
|
-
return (
|
|
3933
|
+
return threadFromFetch(`${context.runtimeUrl}${THREAD_SUBSCRIBE_PATH}`, {
|
|
3894
3934
|
selector: async (response) => {
|
|
3895
3935
|
if (!response.ok) throw new Error(`Failed to fetch thread metadata credentials: ${response.status}`);
|
|
3896
3936
|
return response.json();
|
|
@@ -3923,7 +3963,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
3923
3963
|
}
|
|
3924
3964
|
function createThreadMutationObservable(environment, context, request) {
|
|
3925
3965
|
return (0, rxjs.defer)(() => {
|
|
3926
|
-
return (
|
|
3966
|
+
return threadFromFetch(`${context.runtimeUrl}${request.path}`, {
|
|
3927
3967
|
selector: async (response) => {
|
|
3928
3968
|
if (!response.ok) throw new Error(`Request failed: ${response.status}`);
|
|
3929
3969
|
return null;
|
|
@@ -4025,7 +4065,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
4025
4065
|
};
|
|
4026
4066
|
if (context.includeArchived) params.includeArchived = "true";
|
|
4027
4067
|
if (context.limit != null) params.limit = String(context.limit);
|
|
4028
|
-
return (
|
|
4068
|
+
return threadFromFetch(`${context.runtimeUrl}/threads?${new URLSearchParams(params).toString()}`, {
|
|
4029
4069
|
selector: (response) => {
|
|
4030
4070
|
if (!response.ok) throw new Error(`Failed to fetch next page: ${response.status}`);
|
|
4031
4071
|
return response.json();
|
|
@@ -4050,7 +4090,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
4050
4090
|
error: error instanceof Error ? error : new Error(String(error))
|
|
4051
4091
|
}))), (0, rxjs_operators.takeUntil)(actions$.pipe(ofType(threadAdapterEvents.contextChanged, threadAdapterEvents.stopped))));
|
|
4052
4092
|
}))),
|
|
4053
|
-
createEffect((actions$, state$) => actions$.pipe(ofType(threadAdapterEvents.renameRequested, threadAdapterEvents.archiveRequested, threadAdapterEvents.deleteRequested), (0, rxjs_operators.withLatestFrom)(state$), (0, rxjs_operators.mergeMap)(([action, state]) => {
|
|
4093
|
+
createEffect((actions$, state$) => actions$.pipe(ofType(threadAdapterEvents.renameRequested, threadAdapterEvents.archiveRequested, threadAdapterEvents.unarchiveRequested, threadAdapterEvents.deleteRequested), (0, rxjs_operators.withLatestFrom)(state$), (0, rxjs_operators.mergeMap)(([action, state]) => {
|
|
4054
4094
|
const context = state.context;
|
|
4055
4095
|
if (!(context === null || context === void 0 ? void 0 : context.runtimeUrl)) {
|
|
4056
4096
|
const requestId = action.requestId;
|
|
@@ -4076,6 +4116,15 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
4076
4116
|
path: `/threads/${encodeURIComponent(action.threadId)}/archive`,
|
|
4077
4117
|
body: commonBody
|
|
4078
4118
|
});
|
|
4119
|
+
if (threadAdapterEvents.unarchiveRequested.match(action)) return createThreadMutationObservable(environment, context, {
|
|
4120
|
+
requestId: action.requestId,
|
|
4121
|
+
method: "PATCH",
|
|
4122
|
+
path: `/threads/${encodeURIComponent(action.threadId)}`,
|
|
4123
|
+
body: {
|
|
4124
|
+
...commonBody,
|
|
4125
|
+
archived: false
|
|
4126
|
+
}
|
|
4127
|
+
});
|
|
4079
4128
|
return createThreadMutationObservable(environment, context, {
|
|
4080
4129
|
requestId: action.requestId,
|
|
4081
4130
|
method: "DELETE",
|
|
@@ -4130,6 +4179,12 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
4130
4179
|
threadId
|
|
4131
4180
|
}));
|
|
4132
4181
|
},
|
|
4182
|
+
unarchiveThread(threadId) {
|
|
4183
|
+
return trackMutation(threadAdapterEvents.unarchiveRequested({
|
|
4184
|
+
requestId: createThreadRequestId(),
|
|
4185
|
+
threadId
|
|
4186
|
+
}));
|
|
4187
|
+
},
|
|
4133
4188
|
deleteThread(threadId) {
|
|
4134
4189
|
return trackMutation(threadAdapterEvents.deleteRequested({
|
|
4135
4190
|
requestId: createThreadRequestId(),
|