@copilotkitnext/runtime 1.54.0 → 1.54.1-next.1
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/endpoints/express-single.cjs.map +1 -1
- package/dist/endpoints/express-single.d.cts +2 -2
- package/dist/endpoints/express-single.d.cts.map +1 -1
- package/dist/endpoints/express-single.d.mts +2 -2
- package/dist/endpoints/express-single.d.mts.map +1 -1
- package/dist/endpoints/express-single.mjs.map +1 -1
- package/dist/endpoints/express.cjs +38 -0
- package/dist/endpoints/express.cjs.map +1 -1
- package/dist/endpoints/express.d.cts +2 -2
- package/dist/endpoints/express.d.cts.map +1 -1
- package/dist/endpoints/express.d.mts +2 -2
- package/dist/endpoints/express.d.mts.map +1 -1
- package/dist/endpoints/express.mjs +38 -0
- package/dist/endpoints/express.mjs.map +1 -1
- package/dist/endpoints/hono-single.cjs.map +1 -1
- package/dist/endpoints/hono-single.d.cts +2 -2
- package/dist/endpoints/hono-single.d.cts.map +1 -1
- package/dist/endpoints/hono-single.d.mts +2 -2
- package/dist/endpoints/hono-single.d.mts.map +1 -1
- package/dist/endpoints/hono-single.mjs.map +1 -1
- package/dist/endpoints/hono.cjs +83 -0
- package/dist/endpoints/hono.cjs.map +1 -1
- package/dist/endpoints/hono.d.cts +3 -3
- package/dist/endpoints/hono.d.cts.map +1 -1
- package/dist/endpoints/hono.d.mts +3 -3
- package/dist/endpoints/hono.d.mts.map +1 -1
- package/dist/endpoints/hono.mjs +83 -0
- package/dist/endpoints/hono.mjs.map +1 -1
- package/dist/handlers/get-runtime-info.cjs +2 -0
- package/dist/handlers/get-runtime-info.cjs.map +1 -1
- package/dist/handlers/get-runtime-info.mjs +3 -1
- package/dist/handlers/get-runtime-info.mjs.map +1 -1
- package/dist/handlers/handle-connect.cjs +18 -80
- package/dist/handlers/handle-connect.cjs.map +1 -1
- package/dist/handlers/handle-connect.mjs +18 -79
- package/dist/handlers/handle-connect.mjs.map +1 -1
- package/dist/handlers/handle-run.cjs +26 -98
- package/dist/handlers/handle-run.cjs.map +1 -1
- package/dist/handlers/handle-run.mjs +26 -97
- package/dist/handlers/handle-run.mjs.map +1 -1
- package/dist/handlers/handle-stop.cjs.map +1 -1
- package/dist/handlers/handle-stop.mjs.map +1 -1
- package/dist/handlers/handle-threads.cjs +1 -0
- package/dist/handlers/handle-threads.mjs +3 -0
- package/dist/handlers/handle-transcribe.cjs.map +1 -1
- package/dist/handlers/handle-transcribe.mjs.map +1 -1
- package/dist/handlers/intelligence/connect.cjs +28 -0
- package/dist/handlers/intelligence/connect.cjs.map +1 -0
- package/dist/handlers/intelligence/connect.mjs +28 -0
- package/dist/handlers/intelligence/connect.mjs.map +1 -0
- package/dist/handlers/intelligence/run.cjs +77 -0
- package/dist/handlers/intelligence/run.cjs.map +1 -0
- package/dist/handlers/intelligence/run.mjs +76 -0
- package/dist/handlers/intelligence/run.mjs.map +1 -0
- package/dist/handlers/intelligence/thread-names.cjs +144 -0
- package/dist/handlers/intelligence/thread-names.cjs.map +1 -0
- package/dist/handlers/intelligence/thread-names.mjs +143 -0
- package/dist/handlers/intelligence/thread-names.mjs.map +1 -0
- package/dist/handlers/intelligence/threads.cjs +133 -0
- package/dist/handlers/intelligence/threads.cjs.map +1 -0
- package/dist/handlers/intelligence/threads.mjs +128 -0
- package/dist/handlers/intelligence/threads.mjs.map +1 -0
- package/dist/handlers/shared/agent-utils.cjs +73 -0
- package/dist/handlers/shared/agent-utils.cjs.map +1 -0
- package/dist/handlers/shared/agent-utils.mjs +69 -0
- package/dist/handlers/shared/agent-utils.mjs.map +1 -0
- package/dist/handlers/shared/intelligence-utils.cjs +20 -0
- package/dist/handlers/shared/intelligence-utils.cjs.map +1 -0
- package/dist/handlers/shared/intelligence-utils.mjs +19 -0
- package/dist/handlers/shared/intelligence-utils.mjs.map +1 -0
- package/dist/handlers/shared/json-response.cjs +7 -0
- package/dist/handlers/shared/json-response.cjs.map +1 -0
- package/dist/handlers/shared/json-response.mjs +6 -0
- package/dist/handlers/shared/json-response.mjs.map +1 -0
- package/dist/handlers/shared/sse-response.cjs +63 -0
- package/dist/handlers/shared/sse-response.cjs.map +1 -0
- package/dist/handlers/shared/sse-response.mjs +62 -0
- package/dist/handlers/shared/sse-response.mjs.map +1 -0
- package/dist/handlers/sse/connect.cjs +17 -0
- package/dist/handlers/sse/connect.cjs.map +1 -0
- package/dist/handlers/sse/connect.mjs +17 -0
- package/dist/handlers/sse/connect.mjs.map +1 -0
- package/dist/handlers/sse/run.cjs +17 -0
- package/dist/handlers/sse/run.cjs.map +1 -0
- package/dist/handlers/sse/run.mjs +17 -0
- package/dist/handlers/sse/run.mjs.map +1 -0
- package/dist/index.cjs +8 -2
- package/dist/index.d.cts +3 -2
- package/dist/index.d.mts +4 -2
- package/dist/index.mjs +5 -3
- package/dist/intelligence-platform/client.cjs +318 -0
- package/dist/intelligence-platform/client.cjs.map +1 -0
- package/dist/intelligence-platform/client.d.cts +327 -0
- package/dist/intelligence-platform/client.d.cts.map +1 -0
- package/dist/intelligence-platform/client.d.mts +327 -0
- package/dist/intelligence-platform/client.d.mts.map +1 -0
- package/dist/intelligence-platform/client.mjs +316 -0
- package/dist/intelligence-platform/client.mjs.map +1 -0
- package/dist/intelligence-platform/index.cjs +1 -0
- package/dist/intelligence-platform/index.d.mts +1 -0
- package/dist/intelligence-platform/index.mjs +3 -0
- package/dist/middleware.cjs.map +1 -1
- package/dist/middleware.d.cts +3 -3
- package/dist/middleware.d.cts.map +1 -1
- package/dist/middleware.d.mts +3 -3
- package/dist/middleware.d.mts.map +1 -1
- package/dist/middleware.mjs.map +1 -1
- package/dist/package.cjs +1 -1
- package/dist/package.mjs +1 -1
- package/dist/runner/agent-runner.cjs.map +1 -1
- package/dist/runner/agent-runner.d.cts +4 -1
- package/dist/runner/agent-runner.d.cts.map +1 -1
- package/dist/runner/agent-runner.d.mts +4 -1
- package/dist/runner/agent-runner.d.mts.map +1 -1
- package/dist/runner/agent-runner.mjs.map +1 -1
- package/dist/runner/in-memory.cjs +1 -1
- package/dist/runner/in-memory.mjs +1 -1
- package/dist/runner/intelligence.cjs +87 -24
- package/dist/runner/intelligence.cjs.map +1 -1
- package/dist/runner/intelligence.d.cts +8 -3
- package/dist/runner/intelligence.d.cts.map +1 -1
- package/dist/runner/intelligence.d.mts +8 -3
- package/dist/runner/intelligence.d.mts.map +1 -1
- package/dist/runner/intelligence.mjs +87 -24
- package/dist/runner/intelligence.mjs.map +1 -1
- package/dist/runtime.cjs +76 -6
- package/dist/runtime.cjs.map +1 -1
- package/dist/runtime.d.cts +71 -21
- package/dist/runtime.d.cts.map +1 -1
- package/dist/runtime.d.mts +72 -21
- package/dist/runtime.d.mts.map +1 -1
- package/dist/runtime.mjs +73 -7
- package/dist/runtime.mjs.map +1 -1
- package/package.json +5 -5
|
@@ -0,0 +1,316 @@
|
|
|
1
|
+
import { logger } from "@copilotkitnext/shared";
|
|
2
|
+
|
|
3
|
+
//#region src/intelligence-platform/client.ts
|
|
4
|
+
/**
|
|
5
|
+
* Error thrown when an Intelligence platform HTTP request returns a non-2xx
|
|
6
|
+
* status. Carries the HTTP {@link status} code so callers can branch on
|
|
7
|
+
* specific failures (e.g. 404 for "not found", 409 for "conflict") without
|
|
8
|
+
* parsing the error message string.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* try {
|
|
13
|
+
* await intelligence.getThread({ threadId });
|
|
14
|
+
* } catch (error) {
|
|
15
|
+
* if (error instanceof PlatformRequestError && error.status === 404) {
|
|
16
|
+
* // thread does not exist yet
|
|
17
|
+
* }
|
|
18
|
+
* }
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
var PlatformRequestError = class extends Error {
|
|
22
|
+
constructor(message, status) {
|
|
23
|
+
super(message);
|
|
24
|
+
this.status = status;
|
|
25
|
+
this.name = "PlatformRequestError";
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
var CopilotKitIntelligence = class {
|
|
29
|
+
#apiUrl;
|
|
30
|
+
#runnerWsUrl;
|
|
31
|
+
#clientWsUrl;
|
|
32
|
+
#apiKey;
|
|
33
|
+
#tenantId;
|
|
34
|
+
#threadCreatedListeners = /* @__PURE__ */ new Set();
|
|
35
|
+
#threadUpdatedListeners = /* @__PURE__ */ new Set();
|
|
36
|
+
#threadDeletedListeners = /* @__PURE__ */ new Set();
|
|
37
|
+
constructor(config) {
|
|
38
|
+
const intelligenceWsUrl = normalizeIntelligenceWsUrl(config.wsUrl);
|
|
39
|
+
this.#apiUrl = config.apiUrl.replace(/\/$/, "");
|
|
40
|
+
this.#runnerWsUrl = deriveRunnerWsUrl(intelligenceWsUrl);
|
|
41
|
+
this.#clientWsUrl = deriveClientWsUrl(intelligenceWsUrl);
|
|
42
|
+
this.#apiKey = config.apiKey;
|
|
43
|
+
this.#tenantId = config.tenantId;
|
|
44
|
+
if (config.onThreadCreated) this.onThreadCreated(config.onThreadCreated);
|
|
45
|
+
if (config.onThreadUpdated) this.onThreadUpdated(config.onThreadUpdated);
|
|
46
|
+
if (config.onThreadDeleted) this.onThreadDeleted(config.onThreadDeleted);
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Register a listener invoked whenever a thread is created.
|
|
50
|
+
*
|
|
51
|
+
* Multiple listeners can be registered. Each call returns an unsubscribe
|
|
52
|
+
* function that removes the listener when called.
|
|
53
|
+
*
|
|
54
|
+
* @param callback - Receives the newly created {@link ThreadSummary}.
|
|
55
|
+
* @returns A function that removes this listener when called.
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* ```ts
|
|
59
|
+
* const unsubscribe = intelligence.onThreadCreated((thread) => {
|
|
60
|
+
* console.log("Thread created:", thread.id);
|
|
61
|
+
* });
|
|
62
|
+
* // later…
|
|
63
|
+
* unsubscribe();
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
onThreadCreated(callback) {
|
|
67
|
+
this.#threadCreatedListeners.add(callback);
|
|
68
|
+
return () => {
|
|
69
|
+
this.#threadCreatedListeners.delete(callback);
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Register a listener invoked whenever a thread is updated (including archive).
|
|
74
|
+
*
|
|
75
|
+
* Multiple listeners can be registered. Each call returns an unsubscribe
|
|
76
|
+
* function that removes the listener when called.
|
|
77
|
+
*
|
|
78
|
+
* @param callback - Receives the updated {@link ThreadSummary}.
|
|
79
|
+
* @returns A function that removes this listener when called.
|
|
80
|
+
*/
|
|
81
|
+
onThreadUpdated(callback) {
|
|
82
|
+
this.#threadUpdatedListeners.add(callback);
|
|
83
|
+
return () => {
|
|
84
|
+
this.#threadUpdatedListeners.delete(callback);
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Register a listener invoked whenever a thread is deleted.
|
|
89
|
+
*
|
|
90
|
+
* Multiple listeners can be registered. Each call returns an unsubscribe
|
|
91
|
+
* function that removes the listener when called.
|
|
92
|
+
*
|
|
93
|
+
* @param callback - Receives the {@link ThreadDeletedPayload} identifying
|
|
94
|
+
* the deleted thread.
|
|
95
|
+
* @returns A function that removes this listener when called.
|
|
96
|
+
*/
|
|
97
|
+
onThreadDeleted(callback) {
|
|
98
|
+
this.#threadDeletedListeners.add(callback);
|
|
99
|
+
return () => {
|
|
100
|
+
this.#threadDeletedListeners.delete(callback);
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
ɵgetApiUrl() {
|
|
104
|
+
return this.#apiUrl;
|
|
105
|
+
}
|
|
106
|
+
ɵgetRunnerWsUrl() {
|
|
107
|
+
return this.#runnerWsUrl;
|
|
108
|
+
}
|
|
109
|
+
ɵgetClientWsUrl() {
|
|
110
|
+
return this.#clientWsUrl;
|
|
111
|
+
}
|
|
112
|
+
ɵgetTenantId() {
|
|
113
|
+
return this.#tenantId;
|
|
114
|
+
}
|
|
115
|
+
ɵgetRunnerAuthToken() {
|
|
116
|
+
return this.#apiKey;
|
|
117
|
+
}
|
|
118
|
+
async #request(method, path, body) {
|
|
119
|
+
const url = `${this.#apiUrl}${path}`;
|
|
120
|
+
const headers = {
|
|
121
|
+
Authorization: `Bearer ${this.#apiKey}`,
|
|
122
|
+
"Content-Type": "application/json",
|
|
123
|
+
"X-Tenant-Id": this.#tenantId
|
|
124
|
+
};
|
|
125
|
+
const response = await fetch(url, {
|
|
126
|
+
method,
|
|
127
|
+
headers,
|
|
128
|
+
body: body ? JSON.stringify(body) : void 0
|
|
129
|
+
});
|
|
130
|
+
if (!response.ok) {
|
|
131
|
+
const text = await response.text().catch(() => "");
|
|
132
|
+
logger.error({
|
|
133
|
+
status: response.status,
|
|
134
|
+
body: text,
|
|
135
|
+
path
|
|
136
|
+
}, "Intelligence platform request failed");
|
|
137
|
+
throw new PlatformRequestError(`Intelligence platform error ${response.status}: ${text || response.statusText}`, response.status);
|
|
138
|
+
}
|
|
139
|
+
const text = await response.text();
|
|
140
|
+
if (!text) return;
|
|
141
|
+
return JSON.parse(text);
|
|
142
|
+
}
|
|
143
|
+
#invokeLifecycleCallback(callbackName, payload) {
|
|
144
|
+
const listeners = callbackName === "onThreadCreated" ? this.#threadCreatedListeners : callbackName === "onThreadUpdated" ? this.#threadUpdatedListeners : this.#threadDeletedListeners;
|
|
145
|
+
for (const callback of listeners) try {
|
|
146
|
+
callback(payload);
|
|
147
|
+
} catch (error) {
|
|
148
|
+
logger.error({
|
|
149
|
+
err: error,
|
|
150
|
+
callbackName,
|
|
151
|
+
payload
|
|
152
|
+
}, "Intelligence lifecycle callback failed");
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* List all non-archived threads for a given user and agent.
|
|
157
|
+
*
|
|
158
|
+
* @param params.userId - User whose threads to list.
|
|
159
|
+
* @param params.agentId - Agent whose threads to list.
|
|
160
|
+
* @returns The thread list along with realtime subscription credentials.
|
|
161
|
+
* @throws {@link PlatformRequestError} on non-2xx responses.
|
|
162
|
+
*/
|
|
163
|
+
async listThreads(params) {
|
|
164
|
+
const query = new URLSearchParams(params).toString();
|
|
165
|
+
return this.#request("GET", `/api/threads?${query}`);
|
|
166
|
+
}
|
|
167
|
+
async ɵsubscribeToThreads(params) {
|
|
168
|
+
return this.#request("POST", "/api/threads/subscribe", { userId: params.userId });
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Update thread metadata (e.g. name).
|
|
172
|
+
*
|
|
173
|
+
* Triggers the `onThreadUpdated` lifecycle callback on success.
|
|
174
|
+
*
|
|
175
|
+
* @returns The updated thread summary.
|
|
176
|
+
* @throws {@link PlatformRequestError} on non-2xx responses.
|
|
177
|
+
*/
|
|
178
|
+
async updateThread(params) {
|
|
179
|
+
const response = await this.#request("PATCH", `/api/threads/${encodeURIComponent(params.threadId)}`, {
|
|
180
|
+
userId: params.userId,
|
|
181
|
+
agentId: params.agentId,
|
|
182
|
+
...params.updates
|
|
183
|
+
});
|
|
184
|
+
this.#invokeLifecycleCallback("onThreadUpdated", response.thread);
|
|
185
|
+
return response.thread;
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Create a new thread on the platform.
|
|
189
|
+
*
|
|
190
|
+
* Triggers the `onThreadCreated` lifecycle callback on success.
|
|
191
|
+
*
|
|
192
|
+
* @returns The newly created thread summary.
|
|
193
|
+
* @throws {@link PlatformRequestError} with status 409 if a thread with the
|
|
194
|
+
* same `threadId` already exists.
|
|
195
|
+
*/
|
|
196
|
+
async createThread(params) {
|
|
197
|
+
const response = await this.#request("POST", `/api/threads`, {
|
|
198
|
+
threadId: params.threadId,
|
|
199
|
+
userId: params.userId,
|
|
200
|
+
agentId: params.agentId,
|
|
201
|
+
...params.name !== void 0 ? { name: params.name } : {}
|
|
202
|
+
});
|
|
203
|
+
this.#invokeLifecycleCallback("onThreadCreated", response.thread);
|
|
204
|
+
return response.thread;
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Fetch a single thread by ID.
|
|
208
|
+
*
|
|
209
|
+
* @returns The thread summary.
|
|
210
|
+
* @throws {@link PlatformRequestError} with status 404 if the thread does
|
|
211
|
+
* not exist.
|
|
212
|
+
*/
|
|
213
|
+
async getThread(params) {
|
|
214
|
+
return (await this.#request("GET", `/api/threads/${encodeURIComponent(params.threadId)}`)).thread;
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Get an existing thread or create it if it does not exist.
|
|
218
|
+
*
|
|
219
|
+
* Handles the race where a concurrent request creates the thread between
|
|
220
|
+
* the initial 404 and the subsequent `createThread` call by catching the
|
|
221
|
+
* 409 Conflict and retrying the get.
|
|
222
|
+
*
|
|
223
|
+
* Triggers the `onThreadCreated` lifecycle callback when a new thread is
|
|
224
|
+
* created.
|
|
225
|
+
*
|
|
226
|
+
* @returns An object containing the thread and a `created` flag indicating
|
|
227
|
+
* whether the thread was newly created (`true`) or already existed (`false`).
|
|
228
|
+
* @throws {@link PlatformRequestError} on non-2xx responses other than
|
|
229
|
+
* 404 (get) and 409 (create race).
|
|
230
|
+
*/
|
|
231
|
+
async getOrCreateThread(params) {
|
|
232
|
+
try {
|
|
233
|
+
return {
|
|
234
|
+
thread: await this.getThread({ threadId: params.threadId }),
|
|
235
|
+
created: false
|
|
236
|
+
};
|
|
237
|
+
} catch (error) {
|
|
238
|
+
if (!(error instanceof PlatformRequestError && error.status === 404)) throw error;
|
|
239
|
+
}
|
|
240
|
+
try {
|
|
241
|
+
return {
|
|
242
|
+
thread: await this.createThread(params),
|
|
243
|
+
created: true
|
|
244
|
+
};
|
|
245
|
+
} catch (error) {
|
|
246
|
+
if (error instanceof PlatformRequestError && error.status === 409) return {
|
|
247
|
+
thread: await this.getThread({ threadId: params.threadId }),
|
|
248
|
+
created: false
|
|
249
|
+
};
|
|
250
|
+
throw error;
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* Fetch the full message history for a thread.
|
|
255
|
+
*
|
|
256
|
+
* @returns All persisted messages in chronological order.
|
|
257
|
+
* @throws {@link PlatformRequestError} on non-2xx responses.
|
|
258
|
+
*/
|
|
259
|
+
async getThreadMessages(params) {
|
|
260
|
+
return this.#request("GET", `/api/threads/${encodeURIComponent(params.threadId)}/messages`);
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* Mark a thread as archived.
|
|
264
|
+
*
|
|
265
|
+
* Archived threads are excluded from {@link listThreads} results.
|
|
266
|
+
* Triggers the `onThreadUpdated` lifecycle callback on success.
|
|
267
|
+
*
|
|
268
|
+
* @throws {@link PlatformRequestError} on non-2xx responses.
|
|
269
|
+
*/
|
|
270
|
+
async archiveThread(params) {
|
|
271
|
+
const response = await this.#request("PATCH", `/api/threads/${encodeURIComponent(params.threadId)}`, {
|
|
272
|
+
userId: params.userId,
|
|
273
|
+
agentId: params.agentId,
|
|
274
|
+
archived: true
|
|
275
|
+
});
|
|
276
|
+
this.#invokeLifecycleCallback("onThreadUpdated", response.thread);
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* Permanently delete a thread and its message history.
|
|
280
|
+
*
|
|
281
|
+
* This is irreversible. Triggers the `onThreadDeleted` lifecycle callback
|
|
282
|
+
* on success.
|
|
283
|
+
*
|
|
284
|
+
* @throws {@link PlatformRequestError} on non-2xx responses.
|
|
285
|
+
*/
|
|
286
|
+
async deleteThread(params) {
|
|
287
|
+
await this.#request("DELETE", `/api/threads/${encodeURIComponent(params.threadId)}`, { reason: `Deleted via CopilotKit runtime (userId=${params.userId}, agentId=${params.agentId})` });
|
|
288
|
+
this.#invokeLifecycleCallback("onThreadDeleted", params);
|
|
289
|
+
}
|
|
290
|
+
async ɵacquireThreadLock(params) {
|
|
291
|
+
return this.#request("POST", `/api/threads/${encodeURIComponent(params.threadId)}/lock`, { runId: params.runId });
|
|
292
|
+
}
|
|
293
|
+
async ɵgetActiveJoinCode(params) {
|
|
294
|
+
return this.#request("GET", `/api/threads/${encodeURIComponent(params.threadId)}/join-code`);
|
|
295
|
+
}
|
|
296
|
+
async ɵconnectThread(params) {
|
|
297
|
+
return await this.#request("POST", `/api/threads/${encodeURIComponent(params.threadId)}/connect`, { ...params.lastSeenEventId !== void 0 ? { lastSeenEventId: params.lastSeenEventId } : {} }) ?? null;
|
|
298
|
+
}
|
|
299
|
+
};
|
|
300
|
+
function normalizeIntelligenceWsUrl(wsUrl) {
|
|
301
|
+
return wsUrl.replace(/\/$/, "");
|
|
302
|
+
}
|
|
303
|
+
function deriveRunnerWsUrl(wsUrl) {
|
|
304
|
+
if (wsUrl.endsWith("/runner")) return wsUrl;
|
|
305
|
+
if (wsUrl.endsWith("/client")) return `${wsUrl.slice(0, -7)}/runner`;
|
|
306
|
+
return `${wsUrl}/runner`;
|
|
307
|
+
}
|
|
308
|
+
function deriveClientWsUrl(wsUrl) {
|
|
309
|
+
if (wsUrl.endsWith("/client")) return wsUrl;
|
|
310
|
+
if (wsUrl.endsWith("/runner")) return `${wsUrl.slice(0, -7)}/client`;
|
|
311
|
+
return `${wsUrl}/client`;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
//#endregion
|
|
315
|
+
export { CopilotKitIntelligence, PlatformRequestError };
|
|
316
|
+
//# sourceMappingURL=client.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.mjs","names":["#apiUrl","#runnerWsUrl","#clientWsUrl","#apiKey","#tenantId","#threadCreatedListeners","#threadUpdatedListeners","#threadDeletedListeners","#request","#invokeLifecycleCallback"],"sources":["../../src/intelligence-platform/client.ts"],"sourcesContent":["import { logger } from \"@copilotkitnext/shared\";\nimport type { BaseEvent } from \"@ag-ui/client\";\n\n/**\n * Error thrown when an Intelligence platform HTTP request returns a non-2xx\n * status. Carries the HTTP {@link status} code so callers can branch on\n * specific failures (e.g. 404 for \"not found\", 409 for \"conflict\") without\n * parsing the error message string.\n *\n * @example\n * ```ts\n * try {\n * await intelligence.getThread({ threadId });\n * } catch (error) {\n * if (error instanceof PlatformRequestError && error.status === 404) {\n * // thread does not exist yet\n * }\n * }\n * ```\n */\nexport class PlatformRequestError extends Error {\n constructor(\n message: string,\n /** The HTTP status code returned by the platform (e.g. 404, 409, 500). */\n public readonly status: number,\n ) {\n super(message);\n this.name = \"PlatformRequestError\";\n }\n}\n\n/**\n * Client for the CopilotKit Intelligence Platform REST API.\n *\n * Construct the client once and pass it to any consumers that need it\n * (e.g. `CopilotRuntime`, `IntelligenceAgentRunner`):\n *\n * ```ts\n * import { CopilotKitIntelligence, CopilotRuntime } from \"@copilotkitnext/runtime\";\n *\n * const intelligence = new CopilotKitIntelligence({\n * apiUrl: \"https://api.copilotkit.ai\",\n * wsUrl: \"wss://api.copilotkit.ai\",\n * apiKey: process.env.COPILOTKIT_API_KEY!,\n * tenantId: process.env.COPILOTKIT_TENANT_ID!,\n * });\n *\n * const runtime = new CopilotRuntime({\n * agents,\n * intelligence,\n * });\n * ```\n */\n\n/** Payload passed to `onThreadDeleted` listeners. */\nexport interface ThreadDeletedPayload {\n threadId: string;\n userId: string;\n agentId: string;\n}\n\nexport interface CopilotKitIntelligenceConfig {\n /** Base URL of the intelligence platform API, e.g. \"https://api.copilotkit.ai\" */\n apiUrl: string;\n /** Intelligence websocket base URL. Runner and client socket URLs are derived from this. */\n wsUrl: string;\n /** API key for authenticating with the intelligence platform */\n apiKey: string;\n /** Tenant identifier used for self-hosted Intelligence instances */\n tenantId: string;\n /**\n * Initial listener invoked after a thread is created.\n * Prefer {@link CopilotKitIntelligence.onThreadCreated} for multiple listeners.\n */\n onThreadCreated?: (thread: ThreadSummary) => void;\n /**\n * Initial listener invoked after a thread is updated.\n * Prefer {@link CopilotKitIntelligence.onThreadUpdated} for multiple listeners.\n */\n onThreadUpdated?: (thread: ThreadSummary) => void;\n /**\n * Initial listener invoked after a thread is deleted.\n * Prefer {@link CopilotKitIntelligence.onThreadDeleted} for multiple listeners.\n */\n onThreadDeleted?: (params: ThreadDeletedPayload) => void;\n}\n\n/**\n * Summary metadata for a single thread returned by the platform.\n *\n * This is the shape returned by list, get, create, and update operations.\n * It does not include the thread's message history — use\n * {@link CopilotKitIntelligence.getThreadMessages} for that.\n */\nexport interface ThreadSummary {\n /** Platform-assigned unique identifier. */\n id: string;\n /** Human-readable display name, or `null` if the thread has not been named. */\n name: string | null;\n /** ISO-8601 timestamp of the most recent agent run on this thread. */\n lastRunAt?: string;\n /** ISO-8601 timestamp of the most recent metadata update. */\n lastUpdatedAt?: string;\n /** ISO-8601 timestamp when the thread was created. */\n createdAt?: string;\n /** ISO-8601 timestamp when the thread was last updated. */\n updatedAt?: string;\n /** Whether the thread has been archived. Archived threads are excluded from default list results. */\n archived?: boolean;\n /** The agent that owns this thread. */\n agentId?: string;\n /** The user who created this thread. */\n createdById?: string;\n /** The tenant this thread belongs to. */\n tenantId?: string;\n}\n\n/** Response from listing threads for a user/agent pair. */\nexport interface ListThreadsResponse {\n /** The matching threads, sorted by the platform's default ordering. */\n threads: ThreadSummary[];\n /** Join code for subscribing to realtime metadata updates for these threads. */\n joinCode: string;\n /** Short-lived token for authenticating the realtime subscription. */\n joinToken?: string;\n}\n\n/**\n * Fields that can be updated on a thread via {@link CopilotKitIntelligence.updateThread}.\n *\n * Additional platform-specific fields can be passed as extra keys and will be\n * forwarded to the PATCH request body.\n */\nexport interface UpdateThreadRequest {\n /** New human-readable display name for the thread. */\n name?: string;\n [key: string]: unknown;\n}\n\n/** Parameters for creating a new thread via {@link CopilotKitIntelligence.createThread}. */\nexport interface CreateThreadRequest {\n /** Client-generated unique identifier for the new thread. */\n threadId: string;\n /** The user creating the thread. Used for authorization and scoping. */\n userId: string;\n /** The agent this thread belongs to. */\n agentId: string;\n /** Optional initial display name. If omitted, the thread is unnamed until explicitly renamed. */\n name?: string;\n}\n\n/** Credentials returned when locking or joining a thread's realtime channel. */\nexport interface ThreadConnectionResponse {\n /** Short-lived token for authenticating the Phoenix channel join. */\n joinToken: string;\n /** Optional join code that can be shared with other clients to join the same channel. */\n joinCode?: string;\n}\n\nexport interface SubscribeToThreadsRequest {\n userId: string;\n}\n\nexport interface SubscribeToThreadsResponse {\n joinToken: string;\n}\n\nexport interface ConnectThreadBootstrapResponse {\n mode: \"bootstrap\";\n latestEventId: string | null;\n events: BaseEvent[];\n}\n\nexport interface ConnectThreadLiveResponse {\n mode: \"live\";\n joinToken: string;\n joinFromEventId: string | null;\n events: BaseEvent[];\n}\n\nexport type ConnectThreadResponse =\n | ConnectThreadBootstrapResponse\n | ConnectThreadLiveResponse\n | null;\n\n/** A single message within a thread's persisted history. */\nexport interface ThreadMessage {\n /** Unique identifier for this message. */\n id: string;\n /** Message role, e.g. `\"user\"`, `\"assistant\"`, `\"tool\"`. */\n role: string;\n /** Text content of the message. May be absent for tool-call-only messages. */\n content?: string;\n /** Tool calls initiated by this message (assistant role only). */\n toolCalls?: Array<{\n id: string;\n name: string;\n /** JSON-encoded arguments passed to the tool. */\n args: string;\n }>;\n /** For tool-result messages, the ID of the tool call this message responds to. */\n toolCallId?: string;\n}\n\n/** Response from {@link CopilotKitIntelligence.getThreadMessages}. */\nexport interface ThreadMessagesResponse {\n messages: ThreadMessage[];\n}\n\nexport interface AcquireThreadLockRequest {\n threadId: string;\n runId: string;\n}\n\ninterface ThreadEnvelope {\n thread: ThreadSummary;\n}\n\nexport class CopilotKitIntelligence {\n #apiUrl: string;\n #runnerWsUrl: string;\n #clientWsUrl: string;\n #apiKey: string;\n #tenantId: string;\n #threadCreatedListeners = new Set<(thread: ThreadSummary) => void>();\n #threadUpdatedListeners = new Set<(thread: ThreadSummary) => void>();\n #threadDeletedListeners = new Set<(params: ThreadDeletedPayload) => void>();\n\n constructor(config: CopilotKitIntelligenceConfig) {\n const intelligenceWsUrl = normalizeIntelligenceWsUrl(config.wsUrl);\n\n this.#apiUrl = config.apiUrl.replace(/\\/$/, \"\");\n this.#runnerWsUrl = deriveRunnerWsUrl(intelligenceWsUrl);\n this.#clientWsUrl = deriveClientWsUrl(intelligenceWsUrl);\n this.#apiKey = config.apiKey;\n this.#tenantId = config.tenantId;\n\n if (config.onThreadCreated) {\n this.onThreadCreated(config.onThreadCreated);\n }\n if (config.onThreadUpdated) {\n this.onThreadUpdated(config.onThreadUpdated);\n }\n if (config.onThreadDeleted) {\n this.onThreadDeleted(config.onThreadDeleted);\n }\n }\n\n /**\n * Register a listener invoked whenever a thread is created.\n *\n * Multiple listeners can be registered. Each call returns an unsubscribe\n * function that removes the listener when called.\n *\n * @param callback - Receives the newly created {@link ThreadSummary}.\n * @returns A function that removes this listener when called.\n *\n * @example\n * ```ts\n * const unsubscribe = intelligence.onThreadCreated((thread) => {\n * console.log(\"Thread created:\", thread.id);\n * });\n * // later…\n * unsubscribe();\n * ```\n */\n onThreadCreated(callback: (thread: ThreadSummary) => void): () => void {\n this.#threadCreatedListeners.add(callback);\n return () => {\n this.#threadCreatedListeners.delete(callback);\n };\n }\n\n /**\n * Register a listener invoked whenever a thread is updated (including archive).\n *\n * Multiple listeners can be registered. Each call returns an unsubscribe\n * function that removes the listener when called.\n *\n * @param callback - Receives the updated {@link ThreadSummary}.\n * @returns A function that removes this listener when called.\n */\n onThreadUpdated(callback: (thread: ThreadSummary) => void): () => void {\n this.#threadUpdatedListeners.add(callback);\n return () => {\n this.#threadUpdatedListeners.delete(callback);\n };\n }\n\n /**\n * Register a listener invoked whenever a thread is deleted.\n *\n * Multiple listeners can be registered. Each call returns an unsubscribe\n * function that removes the listener when called.\n *\n * @param callback - Receives the {@link ThreadDeletedPayload} identifying\n * the deleted thread.\n * @returns A function that removes this listener when called.\n */\n onThreadDeleted(\n callback: (params: ThreadDeletedPayload) => void,\n ): () => void {\n this.#threadDeletedListeners.add(callback);\n return () => {\n this.#threadDeletedListeners.delete(callback);\n };\n }\n\n ɵgetApiUrl(): string {\n return this.#apiUrl;\n }\n\n ɵgetRunnerWsUrl(): string {\n return this.#runnerWsUrl;\n }\n\n ɵgetClientWsUrl(): string {\n return this.#clientWsUrl;\n }\n\n ɵgetTenantId(): string {\n return this.#tenantId;\n }\n\n ɵgetRunnerAuthToken(): string {\n return this.#apiKey;\n }\n\n async #request<T>(method: string, path: string, body?: unknown): Promise<T> {\n const url = `${this.#apiUrl}${path}`;\n\n const headers: Record<string, string> = {\n Authorization: `Bearer ${this.#apiKey}`,\n \"Content-Type\": \"application/json\",\n \"X-Tenant-Id\": this.#tenantId,\n };\n\n const response = await fetch(url, {\n method,\n headers,\n body: body ? JSON.stringify(body) : undefined,\n });\n\n if (!response.ok) {\n const text = await response.text().catch(() => \"\");\n logger.error(\n { status: response.status, body: text, path },\n \"Intelligence platform request failed\",\n );\n throw new PlatformRequestError(\n `Intelligence platform error ${response.status}: ${text || response.statusText}`,\n response.status,\n );\n }\n\n const text = await response.text();\n if (!text) {\n return undefined as T;\n }\n return JSON.parse(text) as T;\n }\n\n #invokeLifecycleCallback(\n callbackName: \"onThreadCreated\" | \"onThreadUpdated\" | \"onThreadDeleted\",\n payload: ThreadSummary | ThreadDeletedPayload,\n ): void {\n const listeners =\n callbackName === \"onThreadCreated\"\n ? this.#threadCreatedListeners\n : callbackName === \"onThreadUpdated\"\n ? this.#threadUpdatedListeners\n : this.#threadDeletedListeners;\n\n for (const callback of listeners) {\n try {\n void (callback as (p: typeof payload) => void)(payload);\n } catch (error) {\n logger.error(\n { err: error, callbackName, payload },\n \"Intelligence lifecycle callback failed\",\n );\n }\n }\n }\n\n /**\n * List all non-archived threads for a given user and agent.\n *\n * @param params.userId - User whose threads to list.\n * @param params.agentId - Agent whose threads to list.\n * @returns The thread list along with realtime subscription credentials.\n * @throws {@link PlatformRequestError} on non-2xx responses.\n */\n async listThreads(params: {\n userId: string;\n agentId: string;\n }): Promise<ListThreadsResponse> {\n const query = new URLSearchParams(params).toString();\n return this.#request<ListThreadsResponse>(\"GET\", `/api/threads?${query}`);\n }\n\n async ɵsubscribeToThreads(\n params: SubscribeToThreadsRequest,\n ): Promise<SubscribeToThreadsResponse> {\n return this.#request<SubscribeToThreadsResponse>(\n \"POST\",\n \"/api/threads/subscribe\",\n {\n userId: params.userId,\n },\n );\n }\n\n /**\n * Update thread metadata (e.g. name).\n *\n * Triggers the `onThreadUpdated` lifecycle callback on success.\n *\n * @returns The updated thread summary.\n * @throws {@link PlatformRequestError} on non-2xx responses.\n */\n async updateThread(params: {\n threadId: string;\n userId: string;\n agentId: string;\n updates: UpdateThreadRequest;\n }): Promise<ThreadSummary> {\n const response = await this.#request<ThreadEnvelope>(\n \"PATCH\",\n `/api/threads/${encodeURIComponent(params.threadId)}`,\n {\n userId: params.userId,\n agentId: params.agentId,\n ...params.updates,\n },\n );\n this.#invokeLifecycleCallback(\"onThreadUpdated\", response.thread);\n return response.thread;\n }\n\n /**\n * Create a new thread on the platform.\n *\n * Triggers the `onThreadCreated` lifecycle callback on success.\n *\n * @returns The newly created thread summary.\n * @throws {@link PlatformRequestError} with status 409 if a thread with the\n * same `threadId` already exists.\n */\n async createThread(params: CreateThreadRequest): Promise<ThreadSummary> {\n const response = await this.#request<ThreadEnvelope>(\n \"POST\",\n `/api/threads`,\n {\n threadId: params.threadId,\n userId: params.userId,\n agentId: params.agentId,\n ...(params.name !== undefined ? { name: params.name } : {}),\n },\n );\n this.#invokeLifecycleCallback(\"onThreadCreated\", response.thread);\n return response.thread;\n }\n\n /**\n * Fetch a single thread by ID.\n *\n * @returns The thread summary.\n * @throws {@link PlatformRequestError} with status 404 if the thread does\n * not exist.\n */\n async getThread(params: { threadId: string }): Promise<ThreadSummary> {\n const response = await this.#request<ThreadEnvelope>(\n \"GET\",\n `/api/threads/${encodeURIComponent(params.threadId)}`,\n );\n return response.thread;\n }\n\n /**\n * Get an existing thread or create it if it does not exist.\n *\n * Handles the race where a concurrent request creates the thread between\n * the initial 404 and the subsequent `createThread` call by catching the\n * 409 Conflict and retrying the get.\n *\n * Triggers the `onThreadCreated` lifecycle callback when a new thread is\n * created.\n *\n * @returns An object containing the thread and a `created` flag indicating\n * whether the thread was newly created (`true`) or already existed (`false`).\n * @throws {@link PlatformRequestError} on non-2xx responses other than\n * 404 (get) and 409 (create race).\n */\n async getOrCreateThread(\n params: CreateThreadRequest,\n ): Promise<{ thread: ThreadSummary; created: boolean }> {\n try {\n const thread = await this.getThread({ threadId: params.threadId });\n return { thread, created: false };\n } catch (error) {\n if (!(error instanceof PlatformRequestError && error.status === 404)) {\n throw error;\n }\n }\n\n try {\n const thread = await this.createThread(params);\n return { thread, created: true };\n } catch (error) {\n // Another request created the thread between our get and create — retry get.\n if (error instanceof PlatformRequestError && error.status === 409) {\n const thread = await this.getThread({ threadId: params.threadId });\n return { thread, created: false };\n }\n throw error;\n }\n }\n\n /**\n * Fetch the full message history for a thread.\n *\n * @returns All persisted messages in chronological order.\n * @throws {@link PlatformRequestError} on non-2xx responses.\n */\n async getThreadMessages(params: {\n threadId: string;\n }): Promise<ThreadMessagesResponse> {\n return this.#request<ThreadMessagesResponse>(\n \"GET\",\n `/api/threads/${encodeURIComponent(params.threadId)}/messages`,\n );\n }\n\n /**\n * Mark a thread as archived.\n *\n * Archived threads are excluded from {@link listThreads} results.\n * Triggers the `onThreadUpdated` lifecycle callback on success.\n *\n * @throws {@link PlatformRequestError} on non-2xx responses.\n */\n async archiveThread(params: {\n threadId: string;\n userId: string;\n agentId: string;\n }): Promise<void> {\n const response = await this.#request<ThreadEnvelope>(\n \"PATCH\",\n `/api/threads/${encodeURIComponent(params.threadId)}`,\n { userId: params.userId, agentId: params.agentId, archived: true },\n );\n this.#invokeLifecycleCallback(\"onThreadUpdated\", response.thread);\n }\n\n /**\n * Permanently delete a thread and its message history.\n *\n * This is irreversible. Triggers the `onThreadDeleted` lifecycle callback\n * on success.\n *\n * @throws {@link PlatformRequestError} on non-2xx responses.\n */\n async deleteThread(params: {\n threadId: string;\n userId: string;\n agentId: string;\n }): Promise<void> {\n await this.#request<void>(\n \"DELETE\",\n `/api/threads/${encodeURIComponent(params.threadId)}`,\n {\n reason: `Deleted via CopilotKit runtime (userId=${params.userId}, agentId=${params.agentId})`,\n },\n );\n this.#invokeLifecycleCallback(\"onThreadDeleted\", params);\n }\n\n async ɵacquireThreadLock(\n params: AcquireThreadLockRequest,\n ): Promise<ThreadConnectionResponse> {\n return this.#request<ThreadConnectionResponse>(\n \"POST\",\n `/api/threads/${encodeURIComponent(params.threadId)}/lock`,\n { runId: params.runId },\n );\n }\n\n async ɵgetActiveJoinCode(params: {\n threadId: string;\n }): Promise<ThreadConnectionResponse> {\n return this.#request<ThreadConnectionResponse>(\n \"GET\",\n `/api/threads/${encodeURIComponent(params.threadId)}/join-code`,\n );\n }\n\n async ɵconnectThread(params: {\n threadId: string;\n lastSeenEventId?: string | null;\n }): Promise<ConnectThreadResponse> {\n const result = await this.#request<\n ConnectThreadBootstrapResponse | ConnectThreadLiveResponse\n >(\"POST\", `/api/threads/${encodeURIComponent(params.threadId)}/connect`, {\n ...(params.lastSeenEventId !== undefined\n ? { lastSeenEventId: params.lastSeenEventId }\n : {}),\n });\n\n // request() returns undefined for empty/204 responses\n return result ?? null;\n }\n}\n\nfunction normalizeIntelligenceWsUrl(wsUrl: string): string {\n return wsUrl.replace(/\\/$/, \"\");\n}\n\nfunction deriveRunnerWsUrl(wsUrl: string): string {\n if (wsUrl.endsWith(\"/runner\")) {\n return wsUrl;\n }\n\n if (wsUrl.endsWith(\"/client\")) {\n return `${wsUrl.slice(0, -\"/client\".length)}/runner`;\n }\n\n return `${wsUrl}/runner`;\n}\n\nfunction deriveClientWsUrl(wsUrl: string): string {\n if (wsUrl.endsWith(\"/client\")) {\n return wsUrl;\n }\n\n if (wsUrl.endsWith(\"/runner\")) {\n return `${wsUrl.slice(0, -\"/runner\".length)}/client`;\n }\n\n return `${wsUrl}/client`;\n}\n"],"mappings":"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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const require_client = require('./client.cjs');
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import { CopilotKitIntelligence, CopilotKitIntelligenceConfig, CreateThreadRequest, ListThreadsResponse, SubscribeToThreadsRequest, SubscribeToThreadsResponse, ThreadSummary, UpdateThreadRequest } from "./client.mjs";
|
package/dist/middleware.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"middleware.cjs","names":["parseSSEResponse"],"sources":["../src/middleware.ts"],"sourcesContent":["/**\n * Middleware support for CopilotKit Runtime.\n *\n * A middleware hook can be provided as either:\n * 1. A **callback function** executed in-process.\n * 2. A **webhook URL** (http/https). The runtime will `POST` a JSON payload\n * to the URL and, for *before* hooks, accept an optional modified\n * `Request` object in the response body.\n *\n * Two lifecycle hooks are available:\n * • `BEFORE_REQUEST` – runs *before* the request handler.\n * • `AFTER_REQUEST` – runs *after* the handler returns a `Response`.\n */\n\nimport type {
|
|
1
|
+
{"version":3,"file":"middleware.cjs","names":["parseSSEResponse"],"sources":["../src/middleware.ts"],"sourcesContent":["/**\n * Middleware support for CopilotKit Runtime.\n *\n * A middleware hook can be provided as either:\n * 1. A **callback function** executed in-process.\n * 2. A **webhook URL** (http/https). The runtime will `POST` a JSON payload\n * to the URL and, for *before* hooks, accept an optional modified\n * `Request` object in the response body.\n *\n * Two lifecycle hooks are available:\n * • `BEFORE_REQUEST` – runs *before* the request handler.\n * • `AFTER_REQUEST` – runs *after* the handler returns a `Response`.\n */\n\nimport type { CopilotRuntimeLike } from \"./runtime\";\nimport type { MaybePromise } from \"@copilotkitnext/shared\";\nimport { logger } from \"@copilotkitnext/shared\";\nimport { parseSSEResponse } from \"./middleware-sse-parser\";\nimport type { Message } from \"./middleware-sse-parser\";\n\n/* ------------------------------------------------------------------------------------------------\n * Public types\n * --------------------------------------------------------------------------------------------- */\n\nexport interface BeforeRequestMiddlewareParameters {\n runtime: CopilotRuntimeLike;\n request: Request;\n path: string;\n}\nexport interface AfterRequestMiddlewareParameters {\n runtime: CopilotRuntimeLike;\n response: Response;\n path: string;\n /** Reconstructed messages from the SSE stream (empty for non-SSE responses). */\n messages?: Message[];\n /** Thread ID extracted from the RUN_STARTED event. */\n threadId?: string;\n /** Run ID extracted from the RUN_STARTED event. */\n runId?: string;\n}\n\nexport type BeforeRequestMiddlewareFn = (\n params: BeforeRequestMiddlewareParameters,\n) => MaybePromise<Request | void>;\nexport type AfterRequestMiddlewareFn = (\n params: AfterRequestMiddlewareParameters,\n) => MaybePromise<void>;\n\n/**\n * A middleware value can be either a callback function or a webhook URL.\n */\nexport type BeforeRequestMiddleware = BeforeRequestMiddlewareFn;\nexport type AfterRequestMiddleware = AfterRequestMiddlewareFn;\n\n/** Lifecycle events emitted to webhook middleware. */\nexport enum CopilotKitMiddlewareEvent {\n BeforeRequest = \"BEFORE_REQUEST\",\n AfterRequest = \"AFTER_REQUEST\",\n}\n\n/** Stages used by the Middleware Webhook Protocol */\n/** Stages used by the CopilotKit webhook protocol */\nexport enum WebhookStage {\n BeforeRequest = \"before_request\",\n AfterRequest = \"after_request\",\n}\n\n/* ------------------------------------------------------------------------------------------------\n * Internal helpers – (de)serialisation\n * --------------------------------------------------------------------------------------------- */\n\nexport async function callBeforeRequestMiddleware({\n runtime,\n request,\n path,\n}: BeforeRequestMiddlewareParameters): Promise<Request | void> {\n const mw = runtime.beforeRequestMiddleware;\n if (!mw) return;\n\n // Function-based middleware (in-process)\n if (typeof mw === \"function\") {\n return (mw as BeforeRequestMiddlewareFn)({ runtime, request, path });\n }\n\n logger.warn({ mw }, \"Unsupported beforeRequestMiddleware value – skipped\");\n return;\n}\n\nexport async function callAfterRequestMiddleware({\n runtime,\n response,\n path,\n}: {\n runtime: CopilotRuntimeLike;\n response: Response;\n path: string;\n}): Promise<void> {\n const mw = runtime.afterRequestMiddleware;\n if (!mw) return;\n\n const { messages, threadId, runId } = await parseSSEResponse(response);\n\n if (typeof mw === \"function\") {\n return (mw as AfterRequestMiddlewareFn)({\n runtime,\n response,\n path,\n messages,\n threadId,\n runId,\n });\n }\n\n logger.warn({ mw }, \"Unsupported afterRequestMiddleware value – skipped\");\n}\n"],"mappings":";;;;;AAuEA,eAAsB,4BAA4B,EAChD,SACA,SACA,QAC6D;CAC7D,MAAM,KAAK,QAAQ;AACnB,KAAI,CAAC,GAAI;AAGT,KAAI,OAAO,OAAO,WAChB,QAAQ,GAAiC;EAAE;EAAS;EAAS;EAAM,CAAC;AAGtE,+BAAO,KAAK,EAAE,IAAI,EAAE,sDAAsD;;AAI5E,eAAsB,2BAA2B,EAC/C,SACA,UACA,QAKgB;CAChB,MAAM,KAAK,QAAQ;AACnB,KAAI,CAAC,GAAI;CAET,MAAM,EAAE,UAAU,UAAU,UAAU,MAAMA,+CAAiB,SAAS;AAEtE,KAAI,OAAO,OAAO,WAChB,QAAQ,GAAgC;EACtC;EACA;EACA;EACA;EACA;EACA;EACD,CAAC;AAGJ,+BAAO,KAAK,EAAE,IAAI,EAAE,qDAAqD"}
|
package/dist/middleware.d.cts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { Message } from "./middleware-sse-parser.cjs";
|
|
2
|
-
import {
|
|
2
|
+
import { CopilotRuntimeLike } from "./runtime.cjs";
|
|
3
3
|
import { MaybePromise } from "@copilotkitnext/shared";
|
|
4
4
|
|
|
5
5
|
//#region src/middleware.d.ts
|
|
6
6
|
interface BeforeRequestMiddlewareParameters {
|
|
7
|
-
runtime:
|
|
7
|
+
runtime: CopilotRuntimeLike;
|
|
8
8
|
request: Request;
|
|
9
9
|
path: string;
|
|
10
10
|
}
|
|
11
11
|
interface AfterRequestMiddlewareParameters {
|
|
12
|
-
runtime:
|
|
12
|
+
runtime: CopilotRuntimeLike;
|
|
13
13
|
response: Response;
|
|
14
14
|
path: string;
|
|
15
15
|
/** Reconstructed messages from the SSE stream (empty for non-SSE responses). */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"middleware.d.cts","names":[],"sources":["../src/middleware.ts"],"mappings":";;;;;UAwBiB,iCAAA;EACf,OAAA,EAAS,
|
|
1
|
+
{"version":3,"file":"middleware.d.cts","names":[],"sources":["../src/middleware.ts"],"mappings":";;;;;UAwBiB,iCAAA;EACf,OAAA,EAAS,kBAAA;EACT,OAAA,EAAS,OAAA;EACT,IAAA;AAAA;AAAA,UAEe,gCAAA;EACf,OAAA,EAAS,kBAAA;EACT,QAAA,EAAU,QAAA;EACV,IAAA;EAFS;EAIT,QAAA,GAAW,OAAA;EAHD;EAKV,QAAA;EAFA;EAIA,KAAA;AAAA;AAAA,KAGU,yBAAA,IACV,MAAA,EAAQ,iCAAA,KACL,YAAA,CAAa,OAAA;AAAA,KACN,wBAAA,IACV,MAAA,EAAQ,gCAAA,KACL,YAAA;;AALL;;KAUY,uBAAA,GAA0B,yBAAA;AAAA,KAC1B,sBAAA,GAAyB,wBAAA"}
|
package/dist/middleware.d.mts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { Message } from "./middleware-sse-parser.mjs";
|
|
2
|
-
import {
|
|
2
|
+
import { CopilotRuntimeLike } from "./runtime.mjs";
|
|
3
3
|
import { MaybePromise } from "@copilotkitnext/shared";
|
|
4
4
|
|
|
5
5
|
//#region src/middleware.d.ts
|
|
6
6
|
interface BeforeRequestMiddlewareParameters {
|
|
7
|
-
runtime:
|
|
7
|
+
runtime: CopilotRuntimeLike;
|
|
8
8
|
request: Request;
|
|
9
9
|
path: string;
|
|
10
10
|
}
|
|
11
11
|
interface AfterRequestMiddlewareParameters {
|
|
12
|
-
runtime:
|
|
12
|
+
runtime: CopilotRuntimeLike;
|
|
13
13
|
response: Response;
|
|
14
14
|
path: string;
|
|
15
15
|
/** Reconstructed messages from the SSE stream (empty for non-SSE responses). */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"middleware.d.mts","names":[],"sources":["../src/middleware.ts"],"mappings":";;;;;UAwBiB,iCAAA;EACf,OAAA,EAAS,
|
|
1
|
+
{"version":3,"file":"middleware.d.mts","names":[],"sources":["../src/middleware.ts"],"mappings":";;;;;UAwBiB,iCAAA;EACf,OAAA,EAAS,kBAAA;EACT,OAAA,EAAS,OAAA;EACT,IAAA;AAAA;AAAA,UAEe,gCAAA;EACf,OAAA,EAAS,kBAAA;EACT,QAAA,EAAU,QAAA;EACV,IAAA;EAFS;EAIT,QAAA,GAAW,OAAA;EAHD;EAKV,QAAA;EAFA;EAIA,KAAA;AAAA;AAAA,KAGU,yBAAA,IACV,MAAA,EAAQ,iCAAA,KACL,YAAA,CAAa,OAAA;AAAA,KACN,wBAAA,IACV,MAAA,EAAQ,gCAAA,KACL,YAAA;;AALL;;KAUY,uBAAA,GAA0B,yBAAA;AAAA,KAC1B,sBAAA,GAAyB,wBAAA"}
|
package/dist/middleware.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"middleware.mjs","names":[],"sources":["../src/middleware.ts"],"sourcesContent":["/**\n * Middleware support for CopilotKit Runtime.\n *\n * A middleware hook can be provided as either:\n * 1. A **callback function** executed in-process.\n * 2. A **webhook URL** (http/https). The runtime will `POST` a JSON payload\n * to the URL and, for *before* hooks, accept an optional modified\n * `Request` object in the response body.\n *\n * Two lifecycle hooks are available:\n * • `BEFORE_REQUEST` – runs *before* the request handler.\n * • `AFTER_REQUEST` – runs *after* the handler returns a `Response`.\n */\n\nimport type {
|
|
1
|
+
{"version":3,"file":"middleware.mjs","names":[],"sources":["../src/middleware.ts"],"sourcesContent":["/**\n * Middleware support for CopilotKit Runtime.\n *\n * A middleware hook can be provided as either:\n * 1. A **callback function** executed in-process.\n * 2. A **webhook URL** (http/https). The runtime will `POST` a JSON payload\n * to the URL and, for *before* hooks, accept an optional modified\n * `Request` object in the response body.\n *\n * Two lifecycle hooks are available:\n * • `BEFORE_REQUEST` – runs *before* the request handler.\n * • `AFTER_REQUEST` – runs *after* the handler returns a `Response`.\n */\n\nimport type { CopilotRuntimeLike } from \"./runtime\";\nimport type { MaybePromise } from \"@copilotkitnext/shared\";\nimport { logger } from \"@copilotkitnext/shared\";\nimport { parseSSEResponse } from \"./middleware-sse-parser\";\nimport type { Message } from \"./middleware-sse-parser\";\n\n/* ------------------------------------------------------------------------------------------------\n * Public types\n * --------------------------------------------------------------------------------------------- */\n\nexport interface BeforeRequestMiddlewareParameters {\n runtime: CopilotRuntimeLike;\n request: Request;\n path: string;\n}\nexport interface AfterRequestMiddlewareParameters {\n runtime: CopilotRuntimeLike;\n response: Response;\n path: string;\n /** Reconstructed messages from the SSE stream (empty for non-SSE responses). */\n messages?: Message[];\n /** Thread ID extracted from the RUN_STARTED event. */\n threadId?: string;\n /** Run ID extracted from the RUN_STARTED event. */\n runId?: string;\n}\n\nexport type BeforeRequestMiddlewareFn = (\n params: BeforeRequestMiddlewareParameters,\n) => MaybePromise<Request | void>;\nexport type AfterRequestMiddlewareFn = (\n params: AfterRequestMiddlewareParameters,\n) => MaybePromise<void>;\n\n/**\n * A middleware value can be either a callback function or a webhook URL.\n */\nexport type BeforeRequestMiddleware = BeforeRequestMiddlewareFn;\nexport type AfterRequestMiddleware = AfterRequestMiddlewareFn;\n\n/** Lifecycle events emitted to webhook middleware. */\nexport enum CopilotKitMiddlewareEvent {\n BeforeRequest = \"BEFORE_REQUEST\",\n AfterRequest = \"AFTER_REQUEST\",\n}\n\n/** Stages used by the Middleware Webhook Protocol */\n/** Stages used by the CopilotKit webhook protocol */\nexport enum WebhookStage {\n BeforeRequest = \"before_request\",\n AfterRequest = \"after_request\",\n}\n\n/* ------------------------------------------------------------------------------------------------\n * Internal helpers – (de)serialisation\n * --------------------------------------------------------------------------------------------- */\n\nexport async function callBeforeRequestMiddleware({\n runtime,\n request,\n path,\n}: BeforeRequestMiddlewareParameters): Promise<Request | void> {\n const mw = runtime.beforeRequestMiddleware;\n if (!mw) return;\n\n // Function-based middleware (in-process)\n if (typeof mw === \"function\") {\n return (mw as BeforeRequestMiddlewareFn)({ runtime, request, path });\n }\n\n logger.warn({ mw }, \"Unsupported beforeRequestMiddleware value – skipped\");\n return;\n}\n\nexport async function callAfterRequestMiddleware({\n runtime,\n response,\n path,\n}: {\n runtime: CopilotRuntimeLike;\n response: Response;\n path: string;\n}): Promise<void> {\n const mw = runtime.afterRequestMiddleware;\n if (!mw) return;\n\n const { messages, threadId, runId } = await parseSSEResponse(response);\n\n if (typeof mw === \"function\") {\n return (mw as AfterRequestMiddlewareFn)({\n runtime,\n response,\n path,\n messages,\n threadId,\n runId,\n });\n }\n\n logger.warn({ mw }, \"Unsupported afterRequestMiddleware value – skipped\");\n}\n"],"mappings":";;;;AAuEA,eAAsB,4BAA4B,EAChD,SACA,SACA,QAC6D;CAC7D,MAAM,KAAK,QAAQ;AACnB,KAAI,CAAC,GAAI;AAGT,KAAI,OAAO,OAAO,WAChB,QAAQ,GAAiC;EAAE;EAAS;EAAS;EAAM,CAAC;AAGtE,QAAO,KAAK,EAAE,IAAI,EAAE,sDAAsD;;AAI5E,eAAsB,2BAA2B,EAC/C,SACA,UACA,QAKgB;CAChB,MAAM,KAAK,QAAQ;AACnB,KAAI,CAAC,GAAI;CAET,MAAM,EAAE,UAAU,UAAU,UAAU,MAAM,iBAAiB,SAAS;AAEtE,KAAI,OAAO,OAAO,WAChB,QAAQ,GAAgC;EACtC;EACA;EACA;EACA;EACA;EACA;EACD,CAAC;AAGJ,QAAO,KAAK,EAAE,IAAI,EAAE,qDAAqD"}
|
package/dist/package.cjs
CHANGED
package/dist/package.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent-runner.cjs","names":[],"sources":["../../src/runner/agent-runner.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"agent-runner.cjs","names":[],"sources":["../../src/runner/agent-runner.ts"],"sourcesContent":["import {\n AbstractAgent,\n BaseEvent,\n Message,\n RunAgentInput,\n} from \"@ag-ui/client\";\nimport { Observable } from \"rxjs\";\n\nexport interface AgentRunnerRunRequest {\n threadId: string;\n agent: AbstractAgent;\n input: RunAgentInput;\n joinCode?: string;\n persistedInputMessages?: Message[];\n}\n\nexport interface AgentRunnerConnectRequest {\n threadId: string;\n headers?: Record<string, string>;\n joinCode?: string;\n}\n\nexport interface AgentRunnerIsRunningRequest {\n threadId: string;\n}\n\nexport interface AgentRunnerStopRequest {\n threadId: string;\n}\n\nexport abstract class AgentRunner {\n abstract run(request: AgentRunnerRunRequest): Observable<BaseEvent>;\n abstract connect(request: AgentRunnerConnectRequest): Observable<BaseEvent>;\n abstract isRunning(request: AgentRunnerIsRunningRequest): Promise<boolean>;\n abstract stop(request: AgentRunnerStopRequest): Promise<boolean | undefined>;\n}\n"],"mappings":";;AA8BA,IAAsB,cAAtB,MAAkC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AbstractAgent, BaseEvent, RunAgentInput } from "@ag-ui/client";
|
|
1
|
+
import { AbstractAgent, BaseEvent, Message, RunAgentInput } from "@ag-ui/client";
|
|
2
2
|
import { Observable } from "rxjs";
|
|
3
3
|
|
|
4
4
|
//#region src/runner/agent-runner.d.ts
|
|
@@ -6,10 +6,13 @@ interface AgentRunnerRunRequest {
|
|
|
6
6
|
threadId: string;
|
|
7
7
|
agent: AbstractAgent;
|
|
8
8
|
input: RunAgentInput;
|
|
9
|
+
joinCode?: string;
|
|
10
|
+
persistedInputMessages?: Message[];
|
|
9
11
|
}
|
|
10
12
|
interface AgentRunnerConnectRequest {
|
|
11
13
|
threadId: string;
|
|
12
14
|
headers?: Record<string, string>;
|
|
15
|
+
joinCode?: string;
|
|
13
16
|
}
|
|
14
17
|
interface AgentRunnerIsRunningRequest {
|
|
15
18
|
threadId: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent-runner.d.cts","names":[],"sources":["../../src/runner/agent-runner.ts"],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"agent-runner.d.cts","names":[],"sources":["../../src/runner/agent-runner.ts"],"mappings":";;;;UAQiB,qBAAA;EACf,QAAA;EACA,KAAA,EAAO,aAAA;EACP,KAAA,EAAO,aAAA;EACP,QAAA;EACA,sBAAA,GAAyB,OAAA;AAAA;AAAA,UAGV,yBAAA;EACf,QAAA;EACA,OAAA,GAAU,MAAA;EACV,QAAA;AAAA;AAAA,UAGe,2BAAA;EACf,QAAA;AAAA;AAAA,UAGe,sBAAA;EACf,QAAA;AAAA;AAAA,uBAGoB,WAAA;EAAA,SACX,GAAA,CAAI,OAAA,EAAS,qBAAA,GAAwB,UAAA,CAAW,SAAA;EAAA,SAChD,OAAA,CAAQ,OAAA,EAAS,yBAAA,GAA4B,UAAA,CAAW,SAAA;EAAA,SACxD,SAAA,CAAU,OAAA,EAAS,2BAAA,GAA8B,OAAA;EAAA,SACjD,IAAA,CAAK,OAAA,EAAS,sBAAA,GAAyB,OAAA;AAAA"}
|
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
import { Observable } from "rxjs";
|
|
2
|
-
import { AbstractAgent, BaseEvent, RunAgentInput } from "@ag-ui/client";
|
|
2
|
+
import { AbstractAgent, BaseEvent, Message, RunAgentInput } from "@ag-ui/client";
|
|
3
3
|
|
|
4
4
|
//#region src/runner/agent-runner.d.ts
|
|
5
5
|
interface AgentRunnerRunRequest {
|
|
6
6
|
threadId: string;
|
|
7
7
|
agent: AbstractAgent;
|
|
8
8
|
input: RunAgentInput;
|
|
9
|
+
joinCode?: string;
|
|
10
|
+
persistedInputMessages?: Message[];
|
|
9
11
|
}
|
|
10
12
|
interface AgentRunnerConnectRequest {
|
|
11
13
|
threadId: string;
|
|
12
14
|
headers?: Record<string, string>;
|
|
15
|
+
joinCode?: string;
|
|
13
16
|
}
|
|
14
17
|
interface AgentRunnerIsRunningRequest {
|
|
15
18
|
threadId: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent-runner.d.mts","names":[],"sources":["../../src/runner/agent-runner.ts"],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"agent-runner.d.mts","names":[],"sources":["../../src/runner/agent-runner.ts"],"mappings":";;;;UAQiB,qBAAA;EACf,QAAA;EACA,KAAA,EAAO,aAAA;EACP,KAAA,EAAO,aAAA;EACP,QAAA;EACA,sBAAA,GAAyB,OAAA;AAAA;AAAA,UAGV,yBAAA;EACf,QAAA;EACA,OAAA,GAAU,MAAA;EACV,QAAA;AAAA;AAAA,UAGe,2BAAA;EACf,QAAA;AAAA;AAAA,UAGe,sBAAA;EACf,QAAA;AAAA;AAAA,uBAGoB,WAAA;EAAA,SACX,GAAA,CAAI,OAAA,EAAS,qBAAA,GAAwB,UAAA,CAAW,SAAA;EAAA,SAChD,OAAA,CAAQ,OAAA,EAAS,yBAAA,GAA4B,UAAA,CAAW,SAAA;EAAA,SACxD,SAAA,CAAU,OAAA,EAAS,2BAAA,GAA8B,OAAA;EAAA,SACjD,IAAA,CAAK,OAAA,EAAS,sBAAA,GAAyB,OAAA;AAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent-runner.mjs","names":[],"sources":["../../src/runner/agent-runner.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"agent-runner.mjs","names":[],"sources":["../../src/runner/agent-runner.ts"],"sourcesContent":["import {\n AbstractAgent,\n BaseEvent,\n Message,\n RunAgentInput,\n} from \"@ag-ui/client\";\nimport { Observable } from \"rxjs\";\n\nexport interface AgentRunnerRunRequest {\n threadId: string;\n agent: AbstractAgent;\n input: RunAgentInput;\n joinCode?: string;\n persistedInputMessages?: Message[];\n}\n\nexport interface AgentRunnerConnectRequest {\n threadId: string;\n headers?: Record<string, string>;\n joinCode?: string;\n}\n\nexport interface AgentRunnerIsRunningRequest {\n threadId: string;\n}\n\nexport interface AgentRunnerStopRequest {\n threadId: string;\n}\n\nexport abstract class AgentRunner {\n abstract run(request: AgentRunnerRunRequest): Observable<BaseEvent>;\n abstract connect(request: AgentRunnerConnectRequest): Observable<BaseEvent>;\n abstract isRunning(request: AgentRunnerIsRunningRequest): Promise<boolean>;\n abstract stop(request: AgentRunnerStopRequest): Promise<boolean | undefined>;\n}\n"],"mappings":";AA8BA,IAAsB,cAAtB,MAAkC"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
2
2
|
const require_agent_runner = require('./agent-runner.cjs');
|
|
3
|
+
let _copilotkitnext_shared = require("@copilotkitnext/shared");
|
|
3
4
|
let rxjs = require("rxjs");
|
|
4
5
|
let _ag_ui_client = require("@ag-ui/client");
|
|
5
|
-
let _copilotkitnext_shared = require("@copilotkitnext/shared");
|
|
6
6
|
|
|
7
7
|
//#region src/runner/in-memory.ts
|
|
8
8
|
var InMemoryEventStore = class {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { AgentRunner } from "./agent-runner.mjs";
|
|
2
|
+
import { finalizeRunEvents } from "@copilotkitnext/shared";
|
|
2
3
|
import { ReplaySubject } from "rxjs";
|
|
3
4
|
import { EventType, compactEvents } from "@ag-ui/client";
|
|
4
|
-
import { finalizeRunEvents } from "@copilotkitnext/shared";
|
|
5
5
|
|
|
6
6
|
//#region src/runner/in-memory.ts
|
|
7
7
|
var InMemoryEventStore = class {
|