@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.cjs
CHANGED
|
@@ -152,12 +152,6 @@ var IntelligenceAgent = class IntelligenceAgent extends _ag_ui_client.AbstractAg
|
|
|
152
152
|
activeChannel = null;
|
|
153
153
|
canonicalRunId = null;
|
|
154
154
|
sharedState;
|
|
155
|
-
/**
|
|
156
|
-
* Resolves when the active run's pipeline finalizes; `undefined` between runs.
|
|
157
|
-
* Set/cleared inside {@link connectAgent}'s observable lifecycle. Declared
|
|
158
|
-
* here so {@link RunCompletionAware} consumers can read it without a cast.
|
|
159
|
-
*/
|
|
160
|
-
activeRunCompletionPromise;
|
|
161
155
|
constructor(config, sharedState = { lastSeenEventIds: /* @__PURE__ */ new Map() }) {
|
|
162
156
|
super();
|
|
163
157
|
this.config = config;
|
|
@@ -203,7 +197,7 @@ var IntelligenceAgent = class IntelligenceAgent extends _ag_ui_client.AbstractAg
|
|
|
203
197
|
const previousMessageIds = new Set(this.messages.map((m) => m.id));
|
|
204
198
|
const subscribers = [
|
|
205
199
|
{ onRunFinishedEvent: (event) => {
|
|
206
|
-
result = event.result;
|
|
200
|
+
if (event.outcome === "success") result = event.result;
|
|
207
201
|
} },
|
|
208
202
|
...this.subscribers,
|
|
209
203
|
subscriber ?? {}
|
|
@@ -211,10 +205,10 @@ var IntelligenceAgent = class IntelligenceAgent extends _ag_ui_client.AbstractAg
|
|
|
211
205
|
await this.onInitialize(input, subscribers);
|
|
212
206
|
self.activeRunDetach$ = new rxjs.Subject();
|
|
213
207
|
let resolveCompletion;
|
|
214
|
-
|
|
208
|
+
self.activeRunCompletionPromise = new Promise((resolve) => {
|
|
215
209
|
resolveCompletion = resolve;
|
|
216
210
|
});
|
|
217
|
-
const source$ = (0, rxjs.defer)(() => this.connect(input)).pipe((0, _ag_ui_client.transformChunks)(this.
|
|
211
|
+
const source$ = (0, rxjs.defer)(() => this.connect(input)).pipe((0, _ag_ui_client.transformChunks)(this.debugLogger), (0, rxjs_operators.takeUntil)(self.activeRunDetach$));
|
|
218
212
|
const applied$ = this.apply(input, source$, subscribers);
|
|
219
213
|
await (0, rxjs.lastValueFrom)(this.processApplyEvents(input, applied$, subscribers).pipe((0, rxjs_operators.catchError)((error) => {
|
|
220
214
|
this.isRunning = false;
|
|
@@ -224,7 +218,7 @@ var IntelligenceAgent = class IntelligenceAgent extends _ag_ui_client.AbstractAg
|
|
|
224
218
|
this.onFinalize(input, subscribers);
|
|
225
219
|
resolveCompletion?.();
|
|
226
220
|
resolveCompletion = void 0;
|
|
227
|
-
|
|
221
|
+
self.activeRunCompletionPromise = void 0;
|
|
228
222
|
self.activeRunDetach$ = void 0;
|
|
229
223
|
})), { defaultValue: void 0 });
|
|
230
224
|
const newMessages = (0, _ag_ui_client.structuredClone_)(this.messages).filter((m) => !previousMessageIds.has(m.id));
|
|
@@ -726,8 +720,9 @@ var ProxiedCopilotRuntimeAgent = class ProxiedCopilotRuntimeAgent extends _ag_ui
|
|
|
726
720
|
cloned.setState(this.state);
|
|
727
721
|
cloned.setMessages(this.messages);
|
|
728
722
|
if (this.delegate) {
|
|
729
|
-
|
|
730
|
-
cloned.
|
|
723
|
+
const clonedDelegate = this.delegate.clone();
|
|
724
|
+
cloned.delegate = clonedDelegate;
|
|
725
|
+
cloned.syncDelegate(clonedDelegate);
|
|
731
726
|
}
|
|
732
727
|
return cloned;
|
|
733
728
|
}
|
|
@@ -882,6 +877,17 @@ var AgentRegistry = class {
|
|
|
882
877
|
_openGenerativeUIEnabled = false;
|
|
883
878
|
_licenseStatus;
|
|
884
879
|
_telemetryDisabled = false;
|
|
880
|
+
/**
|
|
881
|
+
* The headers each HttpAgent was constructed with, captured on the first
|
|
882
|
+
* `applyHeadersToAgent` call for that agent (which, for agents the registry
|
|
883
|
+
* owns, happens at registration before any core headers are applied). Core
|
|
884
|
+
* headers are merged ON TOP of this baseline so that headers configured
|
|
885
|
+
* directly on an agent (e.g. an `Authorization` for a self-hosted backend)
|
|
886
|
+
* survive registration instead of being silently replaced. The baseline is
|
|
887
|
+
* captured once and never re-captured, so a later direct mutation of
|
|
888
|
+
* `agent.headers` is not folded into it. See #5635.
|
|
889
|
+
*/
|
|
890
|
+
agentOwnHeaders = /* @__PURE__ */ new WeakMap();
|
|
885
891
|
constructor(core) {
|
|
886
892
|
this.core = core;
|
|
887
893
|
}
|
|
@@ -1054,10 +1060,19 @@ var AgentRegistry = class {
|
|
|
1054
1060
|
console.warn(`Agent ${id} not found`);
|
|
1055
1061
|
}
|
|
1056
1062
|
/**
|
|
1057
|
-
* Apply current headers to an agent
|
|
1063
|
+
* Apply current core headers to an agent, merged ON TOP of the agent's own
|
|
1064
|
+
* construction-time headers (the per-agent baseline in `agentOwnHeaders`).
|
|
1065
|
+
* Core wins on a key conflict. Non-`HttpAgent` agents are left untouched
|
|
1066
|
+
* because only `HttpAgent` carries a `headers` field. See #5635.
|
|
1058
1067
|
*/
|
|
1059
1068
|
applyHeadersToAgent(agent) {
|
|
1060
|
-
if (agent instanceof _ag_ui_client.HttpAgent)
|
|
1069
|
+
if (agent instanceof _ag_ui_client.HttpAgent) {
|
|
1070
|
+
if (!this.agentOwnHeaders.has(agent)) this.agentOwnHeaders.set(agent, { ...agent.headers });
|
|
1071
|
+
agent.headers = {
|
|
1072
|
+
...this.agentOwnHeaders.get(agent),
|
|
1073
|
+
...this.core.headers
|
|
1074
|
+
};
|
|
1075
|
+
}
|
|
1061
1076
|
}
|
|
1062
1077
|
/**
|
|
1063
1078
|
* Apply current headers to all agents
|
|
@@ -1729,7 +1744,7 @@ var RunHandler = class {
|
|
|
1729
1744
|
const proxied = agent;
|
|
1730
1745
|
if (incomingThreadId && typeof proxied.clearReplayCursor === "function") proxied.clearReplayCursor(incomingThreadId);
|
|
1731
1746
|
}
|
|
1732
|
-
|
|
1747
|
+
this._internal.applyHeadersToAgent(agent);
|
|
1733
1748
|
const runAgentResult = await agent.connectAgent({
|
|
1734
1749
|
forwardedProps: this._internal.properties,
|
|
1735
1750
|
tools: this.buildFrontendTools(agent.agentId),
|
|
@@ -1750,15 +1765,18 @@ var RunHandler = class {
|
|
|
1750
1765
|
context
|
|
1751
1766
|
});
|
|
1752
1767
|
}
|
|
1753
|
-
return {
|
|
1768
|
+
return {
|
|
1769
|
+
result: void 0,
|
|
1770
|
+
newMessages: []
|
|
1771
|
+
};
|
|
1754
1772
|
}
|
|
1755
1773
|
}
|
|
1756
1774
|
/**
|
|
1757
1775
|
* Run an agent
|
|
1758
1776
|
*/
|
|
1759
|
-
async runAgent({ agent, forwardedProps }) {
|
|
1777
|
+
async runAgent({ agent, forwardedProps, resume }) {
|
|
1760
1778
|
if (agent.agentId) this._internal.suggestionEngine.clearSuggestions(agent.agentId);
|
|
1761
|
-
|
|
1779
|
+
this._internal.applyHeadersToAgent(agent);
|
|
1762
1780
|
if (agent.detachActiveRun) await agent.detachActiveRun();
|
|
1763
1781
|
const isTopLevel = this._runDepth === 0;
|
|
1764
1782
|
let originalAbortRun;
|
|
@@ -1778,6 +1796,7 @@ var RunHandler = class {
|
|
|
1778
1796
|
...this._internal.properties,
|
|
1779
1797
|
...forwardedProps
|
|
1780
1798
|
},
|
|
1799
|
+
...resume !== void 0 ? { resume } : {},
|
|
1781
1800
|
tools: this.buildFrontendTools(agent.agentId),
|
|
1782
1801
|
context: this._internal.getContextForAgent(agent.agentId)
|
|
1783
1802
|
}, this.createAgentErrorSubscriber(agent));
|
|
@@ -1794,7 +1813,10 @@ var RunHandler = class {
|
|
|
1794
1813
|
code: CopilotKitCoreErrorCode.AGENT_RUN_FAILED,
|
|
1795
1814
|
context
|
|
1796
1815
|
});
|
|
1797
|
-
return {
|
|
1816
|
+
return {
|
|
1817
|
+
result: void 0,
|
|
1818
|
+
newMessages: []
|
|
1819
|
+
};
|
|
1798
1820
|
} finally {
|
|
1799
1821
|
this._runDepth--;
|
|
1800
1822
|
if (isTopLevel && originalAbortRun) agent.abortRun = originalAbortRun;
|
|
@@ -2066,18 +2088,19 @@ var RunHandler = class {
|
|
|
2066
2088
|
throw error;
|
|
2067
2089
|
}
|
|
2068
2090
|
const toolCallId = (0, _copilotkit_shared.randomUUID)();
|
|
2091
|
+
const assistantToolCall = {
|
|
2092
|
+
id: toolCallId,
|
|
2093
|
+
type: "function",
|
|
2094
|
+
function: {
|
|
2095
|
+
name,
|
|
2096
|
+
arguments: JSON.stringify(parameters)
|
|
2097
|
+
}
|
|
2098
|
+
};
|
|
2069
2099
|
const assistantMessage = {
|
|
2070
2100
|
id: (0, _copilotkit_shared.randomUUID)(),
|
|
2071
2101
|
role: "assistant",
|
|
2072
2102
|
content: "",
|
|
2073
|
-
toolCalls: [
|
|
2074
|
-
id: toolCallId,
|
|
2075
|
-
type: "function",
|
|
2076
|
-
function: {
|
|
2077
|
-
name,
|
|
2078
|
-
arguments: JSON.stringify(parameters)
|
|
2079
|
-
}
|
|
2080
|
-
}]
|
|
2103
|
+
toolCalls: [assistantToolCall]
|
|
2081
2104
|
};
|
|
2082
2105
|
agent.messages.push(assistantMessage);
|
|
2083
2106
|
let handlerResult = {
|
|
@@ -2087,7 +2110,7 @@ var RunHandler = class {
|
|
|
2087
2110
|
};
|
|
2088
2111
|
if (tool.handler) handlerResult = await this.executeToolHandler({
|
|
2089
2112
|
tool,
|
|
2090
|
-
toolCall:
|
|
2113
|
+
toolCall: assistantToolCall,
|
|
2091
2114
|
agent,
|
|
2092
2115
|
agentId: resolvedAgentId,
|
|
2093
2116
|
handlerArgs: parameters,
|
|
@@ -2173,9 +2196,9 @@ const EMPTY_TOOL_SCHEMA = {
|
|
|
2173
2196
|
*/
|
|
2174
2197
|
function createToolSchema(tool) {
|
|
2175
2198
|
if (!tool.parameters) return { ...EMPTY_TOOL_SCHEMA };
|
|
2176
|
-
const rawSchema = (0, _copilotkit_shared.schemaToJsonSchema)(tool.parameters, { zodToJsonSchema: zod_to_json_schema.zodToJsonSchema });
|
|
2199
|
+
const rawSchema = (0, _copilotkit_shared.schemaToJsonSchema)(tool.parameters, { zodToJsonSchema: (schema, options) => (0, zod_to_json_schema.zodToJsonSchema)(schema, options) });
|
|
2177
2200
|
if (!rawSchema || typeof rawSchema !== "object") return { ...EMPTY_TOOL_SCHEMA };
|
|
2178
|
-
const { $schema, ...schema } = rawSchema;
|
|
2201
|
+
const { $schema: _$schema, ...schema } = rawSchema;
|
|
2179
2202
|
if (typeof schema.type !== "string") schema.type = "object";
|
|
2180
2203
|
if (typeof schema.properties !== "object" || schema.properties === null) schema.properties = {};
|
|
2181
2204
|
stripAdditionalProperties(schema);
|
|
@@ -2762,9 +2785,19 @@ var CopilotKitCore = class {
|
|
|
2762
2785
|
* });
|
|
2763
2786
|
* ```
|
|
2764
2787
|
*
|
|
2765
|
-
* The resulting header set is also re-applied to every
|
|
2766
|
-
* `
|
|
2767
|
-
*
|
|
2788
|
+
* The resulting header set is also re-applied to every agent in the registry
|
|
2789
|
+
* and `onHeadersChanged` subscribers are notified. These headers are merged
|
|
2790
|
+
* ON TOP of the headers each `HttpAgent` was constructed with, so per-agent
|
|
2791
|
+
* headers (e.g. an `Authorization` for a self-hosted backend) are preserved;
|
|
2792
|
+
* on a key conflict the core-level value wins.
|
|
2793
|
+
*
|
|
2794
|
+
* Because the agent's construction-time headers form the merge baseline, this
|
|
2795
|
+
* method can override a per-agent header but cannot REMOVE one: clearing a
|
|
2796
|
+
* core key here only drops the core-level override, after which the agent's
|
|
2797
|
+
* own value (if any) re-surfaces. To change a header an agent was constructed
|
|
2798
|
+
* with, set it at the provider/core level instead of on the agent, or update
|
|
2799
|
+
* it on the agent directly. The clear-on-logout pattern above is for
|
|
2800
|
+
* core-level headers.
|
|
2768
2801
|
*/
|
|
2769
2802
|
setHeaders(headers) {
|
|
2770
2803
|
this._headers = normalizeHeaders(headers);
|
|
@@ -2823,6 +2856,23 @@ var CopilotKitCore = class {
|
|
|
2823
2856
|
return this.agentRegistry.getAgent(id);
|
|
2824
2857
|
}
|
|
2825
2858
|
/**
|
|
2859
|
+
* Re-apply the current headers to a single agent (delegated to
|
|
2860
|
+
* AgentRegistry). Core headers are merged on top of the agent's own
|
|
2861
|
+
* construction-time headers rather than replacing them, so headers
|
|
2862
|
+
* configured directly on an `HttpAgent` (e.g. an `Authorization` for a
|
|
2863
|
+
* self-hosted backend) survive header updates instead of being silently
|
|
2864
|
+
* dropped (see #5635). On a key conflict the core-level value wins.
|
|
2865
|
+
*
|
|
2866
|
+
* The merge baseline is the agent's headers as captured the first time the
|
|
2867
|
+
* agent is applied (at registration), so the way to change headers
|
|
2868
|
+
* afterwards is `setHeaders` (which re-applies to every agent), not mutating
|
|
2869
|
+
* `agent.headers` directly — a direct mutation is overwritten on the next
|
|
2870
|
+
* re-apply.
|
|
2871
|
+
*/
|
|
2872
|
+
applyHeadersToAgent(agent) {
|
|
2873
|
+
this.agentRegistry.applyHeadersToAgent(agent);
|
|
2874
|
+
}
|
|
2875
|
+
/**
|
|
2826
2876
|
* Context management (delegated to ContextStore).
|
|
2827
2877
|
* Pass `agentIds` to restrict the entry to runs of specific agents;
|
|
2828
2878
|
* omit it for context every agent should receive.
|
|
@@ -3548,6 +3598,7 @@ const threadAdapterEvents = createActionGroup("Thread Adapter", {
|
|
|
3548
3598
|
fetchNextPageRequested: empty(),
|
|
3549
3599
|
renameRequested: props(),
|
|
3550
3600
|
archiveRequested: props(),
|
|
3601
|
+
unarchiveRequested: props(),
|
|
3551
3602
|
deleteRequested: props()
|
|
3552
3603
|
});
|
|
3553
3604
|
const threadRestEvents = createActionGroup("Thread REST", {
|
|
@@ -3690,13 +3741,16 @@ function createThreadRequestId() {
|
|
|
3690
3741
|
threadRequestId += 1;
|
|
3691
3742
|
return `thread-request-${threadRequestId}`;
|
|
3692
3743
|
}
|
|
3744
|
+
function threadFromFetch(input, init) {
|
|
3745
|
+
return (0, rxjs_fetch.fromFetch)(input, init);
|
|
3746
|
+
}
|
|
3693
3747
|
function createThreadFetchObservable(environment, context, sessionId) {
|
|
3694
3748
|
return (0, rxjs.defer)(() => {
|
|
3695
3749
|
const params = { agentId: context.agentId };
|
|
3696
3750
|
if (context.includeArchived) params.includeArchived = "true";
|
|
3697
3751
|
if (context.limit != null) params.limit = String(context.limit);
|
|
3698
3752
|
const qs = new URLSearchParams(params);
|
|
3699
|
-
return (
|
|
3753
|
+
return threadFromFetch(`${context.runtimeUrl}/threads?${qs.toString()}`, {
|
|
3700
3754
|
selector: (response) => {
|
|
3701
3755
|
if (!response.ok) throw new Error(`Failed to fetch threads: ${response.status}`);
|
|
3702
3756
|
return response.json();
|
|
@@ -3724,7 +3778,7 @@ function createThreadFetchObservable(environment, context, sessionId) {
|
|
|
3724
3778
|
}
|
|
3725
3779
|
function createThreadMetadataCredentialsObservable(environment, context, sessionId) {
|
|
3726
3780
|
return (0, rxjs.defer)(() => {
|
|
3727
|
-
return (
|
|
3781
|
+
return threadFromFetch(`${context.runtimeUrl}${THREAD_SUBSCRIBE_PATH}`, {
|
|
3728
3782
|
selector: async (response) => {
|
|
3729
3783
|
if (!response.ok) throw new Error(`Failed to fetch thread metadata credentials: ${response.status}`);
|
|
3730
3784
|
return response.json();
|
|
@@ -3757,7 +3811,7 @@ function createThreadMetadataCredentialsObservable(environment, context, session
|
|
|
3757
3811
|
}
|
|
3758
3812
|
function createThreadMutationObservable(environment, context, request) {
|
|
3759
3813
|
return (0, rxjs.defer)(() => {
|
|
3760
|
-
return (
|
|
3814
|
+
return threadFromFetch(`${context.runtimeUrl}${request.path}`, {
|
|
3761
3815
|
selector: async (response) => {
|
|
3762
3816
|
if (!response.ok) throw new Error(`Request failed: ${response.status}`);
|
|
3763
3817
|
return null;
|
|
@@ -3856,7 +3910,7 @@ function createThreadStore(environment) {
|
|
|
3856
3910
|
};
|
|
3857
3911
|
if (context.includeArchived) params.includeArchived = "true";
|
|
3858
3912
|
if (context.limit != null) params.limit = String(context.limit);
|
|
3859
|
-
return (
|
|
3913
|
+
return threadFromFetch(`${context.runtimeUrl}/threads?${new URLSearchParams(params).toString()}`, {
|
|
3860
3914
|
selector: (response) => {
|
|
3861
3915
|
if (!response.ok) throw new Error(`Failed to fetch next page: ${response.status}`);
|
|
3862
3916
|
return response.json();
|
|
@@ -3878,7 +3932,7 @@ function createThreadStore(environment) {
|
|
|
3878
3932
|
error: error instanceof Error ? error : new Error(String(error))
|
|
3879
3933
|
}))), (0, rxjs_operators.takeUntil)(actions$.pipe(ofType(threadAdapterEvents.contextChanged, threadAdapterEvents.stopped))));
|
|
3880
3934
|
}))),
|
|
3881
|
-
createEffect((actions$, state$) => actions$.pipe(ofType(threadAdapterEvents.renameRequested, threadAdapterEvents.archiveRequested, threadAdapterEvents.deleteRequested), (0, rxjs_operators.withLatestFrom)(state$), (0, rxjs_operators.mergeMap)(([action, state]) => {
|
|
3935
|
+
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]) => {
|
|
3882
3936
|
const context = state.context;
|
|
3883
3937
|
if (!context?.runtimeUrl) {
|
|
3884
3938
|
const requestId = action.requestId;
|
|
@@ -3904,6 +3958,15 @@ function createThreadStore(environment) {
|
|
|
3904
3958
|
path: `/threads/${encodeURIComponent(action.threadId)}/archive`,
|
|
3905
3959
|
body: commonBody
|
|
3906
3960
|
});
|
|
3961
|
+
if (threadAdapterEvents.unarchiveRequested.match(action)) return createThreadMutationObservable(environment, context, {
|
|
3962
|
+
requestId: action.requestId,
|
|
3963
|
+
method: "PATCH",
|
|
3964
|
+
path: `/threads/${encodeURIComponent(action.threadId)}`,
|
|
3965
|
+
body: {
|
|
3966
|
+
...commonBody,
|
|
3967
|
+
archived: false
|
|
3968
|
+
}
|
|
3969
|
+
});
|
|
3907
3970
|
return createThreadMutationObservable(environment, context, {
|
|
3908
3971
|
requestId: action.requestId,
|
|
3909
3972
|
method: "DELETE",
|
|
@@ -3958,6 +4021,12 @@ function createThreadStore(environment) {
|
|
|
3958
4021
|
threadId
|
|
3959
4022
|
}));
|
|
3960
4023
|
},
|
|
4024
|
+
unarchiveThread(threadId) {
|
|
4025
|
+
return trackMutation(threadAdapterEvents.unarchiveRequested({
|
|
4026
|
+
requestId: createThreadRequestId(),
|
|
4027
|
+
threadId
|
|
4028
|
+
}));
|
|
4029
|
+
},
|
|
3961
4030
|
deleteThread(threadId) {
|
|
3962
4031
|
return trackMutation(threadAdapterEvents.deleteRequested({
|
|
3963
4032
|
requestId: createThreadRequestId(),
|