@copilotkitnext/runtime 0.0.22-alpha.9 → 0.0.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-S556ZC5H.mjs → chunk-CX7VJSUL.mjs} +106 -12
- package/dist/chunk-CX7VJSUL.mjs.map +1 -0
- package/dist/express.js +162 -45
- package/dist/express.js.map +1 -1
- package/dist/express.mjs +38 -17
- package/dist/express.mjs.map +1 -1
- package/dist/index.js +169 -53
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +43 -15
- package/dist/index.mjs.map +1 -1
- package/package.json +8 -12
- package/dist/chunk-S556ZC5H.mjs.map +0 -1
package/dist/express.js
CHANGED
|
@@ -1,20 +1,47 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var
|
|
4
|
-
var
|
|
5
|
-
var
|
|
6
|
-
var
|
|
7
|
-
|
|
8
|
-
var
|
|
9
|
-
var
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
13
29
|
|
|
14
|
-
|
|
15
|
-
var
|
|
30
|
+
// src/express.ts
|
|
31
|
+
var express_exports = {};
|
|
32
|
+
__export(express_exports, {
|
|
33
|
+
createCopilotEndpointExpress: () => createCopilotEndpointExpress,
|
|
34
|
+
createCopilotEndpointSingleRouteExpress: () => createCopilotEndpointSingleRouteExpress
|
|
35
|
+
});
|
|
36
|
+
module.exports = __toCommonJS(express_exports);
|
|
16
37
|
|
|
17
38
|
// src/endpoints/express.ts
|
|
39
|
+
var import_express = __toESM(require("express"));
|
|
40
|
+
var import_cors = __toESM(require("cors"));
|
|
41
|
+
|
|
42
|
+
// src/handlers/handle-run.ts
|
|
43
|
+
var import_client = require("@ag-ui/client");
|
|
44
|
+
var import_encoder = require("@ag-ui/encoder");
|
|
18
45
|
async function handleRunAgent({
|
|
19
46
|
runtime,
|
|
20
47
|
request,
|
|
@@ -54,13 +81,13 @@ async function handleRunAgent({
|
|
|
54
81
|
}
|
|
55
82
|
const stream = new TransformStream();
|
|
56
83
|
const writer = stream.writable.getWriter();
|
|
57
|
-
const encoder
|
|
84
|
+
const encoder = new import_encoder.EventEncoder();
|
|
58
85
|
let streamClosed = false;
|
|
59
86
|
(async () => {
|
|
60
87
|
let input;
|
|
61
88
|
try {
|
|
62
89
|
const requestBody = await request.json();
|
|
63
|
-
input =
|
|
90
|
+
input = import_client.RunAgentInputSchema.parse(requestBody);
|
|
64
91
|
} catch {
|
|
65
92
|
return new Response(
|
|
66
93
|
JSON.stringify({
|
|
@@ -80,7 +107,7 @@ async function handleRunAgent({
|
|
|
80
107
|
next: async (event) => {
|
|
81
108
|
if (!request.signal.aborted && !streamClosed) {
|
|
82
109
|
try {
|
|
83
|
-
await writer.write(encoder
|
|
110
|
+
await writer.write(encoder.encode(event));
|
|
84
111
|
} catch (error) {
|
|
85
112
|
if (error instanceof Error && error.name === "AbortError") {
|
|
86
113
|
streamClosed = true;
|
|
@@ -158,6 +185,10 @@ async function handleRunAgent({
|
|
|
158
185
|
);
|
|
159
186
|
}
|
|
160
187
|
}
|
|
188
|
+
|
|
189
|
+
// src/handlers/handle-connect.ts
|
|
190
|
+
var import_client2 = require("@ag-ui/client");
|
|
191
|
+
var import_encoder2 = require("@ag-ui/encoder");
|
|
161
192
|
async function handleConnectAgent({
|
|
162
193
|
runtime,
|
|
163
194
|
request,
|
|
@@ -179,13 +210,13 @@ async function handleConnectAgent({
|
|
|
179
210
|
}
|
|
180
211
|
const stream = new TransformStream();
|
|
181
212
|
const writer = stream.writable.getWriter();
|
|
182
|
-
const encoder
|
|
213
|
+
const encoder = new import_encoder2.EventEncoder();
|
|
183
214
|
let streamClosed = false;
|
|
184
215
|
(async () => {
|
|
185
216
|
let input;
|
|
186
217
|
try {
|
|
187
218
|
const requestBody = await request.json();
|
|
188
|
-
input =
|
|
219
|
+
input = import_client2.RunAgentInputSchema.parse(requestBody);
|
|
189
220
|
} catch {
|
|
190
221
|
return new Response(
|
|
191
222
|
JSON.stringify({
|
|
@@ -200,7 +231,7 @@ async function handleConnectAgent({
|
|
|
200
231
|
next: async (event) => {
|
|
201
232
|
if (!request.signal.aborted && !streamClosed) {
|
|
202
233
|
try {
|
|
203
|
-
await writer.write(encoder
|
|
234
|
+
await writer.write(encoder.encode(event));
|
|
204
235
|
} catch (error) {
|
|
205
236
|
if (error instanceof Error && error.name === "AbortError") {
|
|
206
237
|
streamClosed = true;
|
|
@@ -278,6 +309,9 @@ async function handleConnectAgent({
|
|
|
278
309
|
);
|
|
279
310
|
}
|
|
280
311
|
}
|
|
312
|
+
|
|
313
|
+
// src/handlers/handle-stop.ts
|
|
314
|
+
var import_client3 = require("@ag-ui/client");
|
|
281
315
|
async function handleStopAgent({
|
|
282
316
|
runtime,
|
|
283
317
|
request,
|
|
@@ -315,7 +349,7 @@ async function handleStopAgent({
|
|
|
315
349
|
JSON.stringify({
|
|
316
350
|
stopped: true,
|
|
317
351
|
interrupt: {
|
|
318
|
-
type:
|
|
352
|
+
type: import_client3.EventType.RUN_ERROR,
|
|
319
353
|
message: "Run stopped by user",
|
|
320
354
|
code: "STOPPED"
|
|
321
355
|
}
|
|
@@ -342,7 +376,73 @@ async function handleStopAgent({
|
|
|
342
376
|
|
|
343
377
|
// package.json
|
|
344
378
|
var package_default = {
|
|
345
|
-
|
|
379
|
+
name: "@copilotkitnext/runtime",
|
|
380
|
+
version: "0.0.23",
|
|
381
|
+
description: "Server-side runtime package for CopilotKit2",
|
|
382
|
+
main: "dist/index.js",
|
|
383
|
+
types: "dist/index.d.ts",
|
|
384
|
+
exports: {
|
|
385
|
+
".": {
|
|
386
|
+
types: "./dist/index.d.ts",
|
|
387
|
+
import: "./dist/index.mjs",
|
|
388
|
+
require: "./dist/index.js"
|
|
389
|
+
},
|
|
390
|
+
"./express": {
|
|
391
|
+
types: "./dist/express.d.ts",
|
|
392
|
+
import: "./dist/express.mjs",
|
|
393
|
+
require: "./dist/express.js"
|
|
394
|
+
}
|
|
395
|
+
},
|
|
396
|
+
publishConfig: {
|
|
397
|
+
access: "public"
|
|
398
|
+
},
|
|
399
|
+
scripts: {
|
|
400
|
+
build: "tsup",
|
|
401
|
+
prepublishOnly: "pnpm run build",
|
|
402
|
+
dev: "tsup --watch",
|
|
403
|
+
lint: "eslint . --max-warnings 0",
|
|
404
|
+
"check-types": "tsc --noEmit",
|
|
405
|
+
clean: "rm -rf dist",
|
|
406
|
+
test: "vitest run",
|
|
407
|
+
"test:watch": "vitest",
|
|
408
|
+
"test:coverage": "vitest run --coverage"
|
|
409
|
+
},
|
|
410
|
+
devDependencies: {
|
|
411
|
+
"@copilotkitnext/eslint-config": "workspace:*",
|
|
412
|
+
"@copilotkitnext/typescript-config": "workspace:*",
|
|
413
|
+
"@types/cors": "^2.8.17",
|
|
414
|
+
"@types/express": "^4.17.21",
|
|
415
|
+
"@types/node": "^22.15.3",
|
|
416
|
+
eslint: "^9.30.0",
|
|
417
|
+
openai: "^5.9.0",
|
|
418
|
+
supertest: "^7.1.1",
|
|
419
|
+
tsup: "^8.5.0",
|
|
420
|
+
typescript: "5.8.2",
|
|
421
|
+
vitest: "^3.0.5"
|
|
422
|
+
},
|
|
423
|
+
dependencies: {
|
|
424
|
+
"@ag-ui/client": "0.0.42-alpha.1",
|
|
425
|
+
"@ag-ui/core": "0.0.42-alpha.1",
|
|
426
|
+
"@ag-ui/encoder": "0.0.42-alpha.1",
|
|
427
|
+
"@copilotkitnext/shared": "workspace:*",
|
|
428
|
+
cors: "^2.8.5",
|
|
429
|
+
express: "^4.21.2",
|
|
430
|
+
hono: "^4.6.13",
|
|
431
|
+
rxjs: "7.8.1"
|
|
432
|
+
},
|
|
433
|
+
peerDependencies: {
|
|
434
|
+
openai: "^5.9.0"
|
|
435
|
+
},
|
|
436
|
+
peerDependenciesMeta: {},
|
|
437
|
+
engines: {
|
|
438
|
+
node: ">=18"
|
|
439
|
+
}
|
|
440
|
+
};
|
|
441
|
+
|
|
442
|
+
// src/runner/in-memory.ts
|
|
443
|
+
var import_rxjs = require("rxjs");
|
|
444
|
+
var import_client4 = require("@ag-ui/client");
|
|
445
|
+
var import_shared = require("@copilotkitnext/shared");
|
|
346
446
|
|
|
347
447
|
// src/runtime.ts
|
|
348
448
|
var VERSION = package_default.version;
|
|
@@ -484,6 +584,12 @@ async function handleTranscribe({
|
|
|
484
584
|
);
|
|
485
585
|
}
|
|
486
586
|
}
|
|
587
|
+
|
|
588
|
+
// src/endpoints/express.ts
|
|
589
|
+
var import_shared3 = require("@copilotkitnext/shared");
|
|
590
|
+
|
|
591
|
+
// src/middleware.ts
|
|
592
|
+
var import_shared2 = require("@copilotkitnext/shared");
|
|
487
593
|
async function callBeforeRequestMiddleware({
|
|
488
594
|
runtime,
|
|
489
595
|
request,
|
|
@@ -494,7 +600,7 @@ async function callBeforeRequestMiddleware({
|
|
|
494
600
|
if (typeof mw === "function") {
|
|
495
601
|
return mw({ runtime, request, path });
|
|
496
602
|
}
|
|
497
|
-
|
|
603
|
+
import_shared2.logger.warn({ mw }, "Unsupported beforeRequestMiddleware value \u2013 skipped");
|
|
498
604
|
return;
|
|
499
605
|
}
|
|
500
606
|
async function callAfterRequestMiddleware({
|
|
@@ -507,9 +613,14 @@ async function callAfterRequestMiddleware({
|
|
|
507
613
|
if (typeof mw === "function") {
|
|
508
614
|
return mw({ runtime, response, path });
|
|
509
615
|
}
|
|
510
|
-
|
|
616
|
+
import_shared2.logger.warn({ mw }, "Unsupported afterRequestMiddleware value \u2013 skipped");
|
|
511
617
|
}
|
|
512
|
-
|
|
618
|
+
|
|
619
|
+
// src/endpoints/express-utils.ts
|
|
620
|
+
var import_node_stream = require("stream");
|
|
621
|
+
var import_node_stream2 = require("stream");
|
|
622
|
+
var import_node_util = require("util");
|
|
623
|
+
var streamPipeline = (0, import_node_util.promisify)(import_node_stream2.pipeline);
|
|
513
624
|
var METHODS_WITHOUT_BODY = /* @__PURE__ */ new Set(["GET", "HEAD"]);
|
|
514
625
|
function createFetchRequestFromExpress(req) {
|
|
515
626
|
const method = req.method?.toUpperCase() ?? "GET";
|
|
@@ -529,7 +640,7 @@ function createFetchRequestFromExpress(req) {
|
|
|
529
640
|
headers
|
|
530
641
|
};
|
|
531
642
|
if (!METHODS_WITHOUT_BODY.has(method)) {
|
|
532
|
-
init.body =
|
|
643
|
+
init.body = import_node_stream.Readable.toWeb(req);
|
|
533
644
|
init.duplex = "half";
|
|
534
645
|
}
|
|
535
646
|
const controller = new AbortController();
|
|
@@ -549,7 +660,7 @@ async function sendFetchResponse(res, response) {
|
|
|
549
660
|
res.end();
|
|
550
661
|
return;
|
|
551
662
|
}
|
|
552
|
-
const nodeStream =
|
|
663
|
+
const nodeStream = import_node_stream.Readable.fromWeb(response.body);
|
|
553
664
|
try {
|
|
554
665
|
await streamPipeline(nodeStream, res);
|
|
555
666
|
} catch (error) {
|
|
@@ -565,9 +676,9 @@ function buildOrigin(req) {
|
|
|
565
676
|
|
|
566
677
|
// src/endpoints/express.ts
|
|
567
678
|
function createCopilotEndpointExpress({ runtime, basePath }) {
|
|
568
|
-
const router =
|
|
679
|
+
const router = import_express.default.Router();
|
|
569
680
|
const normalizedBase = normalizeBasePath(basePath);
|
|
570
|
-
router.use(
|
|
681
|
+
router.use((0, import_cors.default)({
|
|
571
682
|
origin: "*",
|
|
572
683
|
methods: ["GET", "HEAD", "PUT", "POST", "DELETE", "PATCH", "OPTIONS"],
|
|
573
684
|
allowedHeaders: ["*"]
|
|
@@ -606,7 +717,7 @@ function createRouteHandler(runtime, factory) {
|
|
|
606
717
|
request = maybeModifiedRequest;
|
|
607
718
|
}
|
|
608
719
|
} catch (error) {
|
|
609
|
-
|
|
720
|
+
import_shared3.logger.error({ err: error, url: request.url, path }, "Error running before request middleware");
|
|
610
721
|
if (error instanceof Response) {
|
|
611
722
|
try {
|
|
612
723
|
await sendFetchResponse(res, error);
|
|
@@ -622,7 +733,7 @@ function createRouteHandler(runtime, factory) {
|
|
|
622
733
|
const response = await factory({ request, req });
|
|
623
734
|
await sendFetchResponse(res, response);
|
|
624
735
|
callAfterRequestMiddleware({ runtime, response, path }).catch((error) => {
|
|
625
|
-
|
|
736
|
+
import_shared3.logger.error({ err: error, url: req.originalUrl ?? req.url, path }, "Error running after request middleware");
|
|
626
737
|
});
|
|
627
738
|
} catch (error) {
|
|
628
739
|
if (error instanceof Response) {
|
|
@@ -633,11 +744,11 @@ function createRouteHandler(runtime, factory) {
|
|
|
633
744
|
return;
|
|
634
745
|
}
|
|
635
746
|
callAfterRequestMiddleware({ runtime, response: error, path }).catch((mwError) => {
|
|
636
|
-
|
|
747
|
+
import_shared3.logger.error({ err: mwError, url: req.originalUrl ?? req.url, path }, "Error running after request middleware");
|
|
637
748
|
});
|
|
638
749
|
return;
|
|
639
750
|
}
|
|
640
|
-
|
|
751
|
+
import_shared3.logger.error({ err: error, url: request.url, path }, "Error running request handler");
|
|
641
752
|
next(error);
|
|
642
753
|
}
|
|
643
754
|
};
|
|
@@ -667,6 +778,11 @@ function joinPath(basePath, suffix) {
|
|
|
667
778
|
return `${basePath}${suffix.startsWith("/") ? suffix : `/${suffix}`}`;
|
|
668
779
|
}
|
|
669
780
|
|
|
781
|
+
// src/endpoints/express-single.ts
|
|
782
|
+
var import_express2 = __toESM(require("express"));
|
|
783
|
+
var import_cors2 = __toESM(require("cors"));
|
|
784
|
+
var import_shared4 = require("@copilotkitnext/shared");
|
|
785
|
+
|
|
670
786
|
// src/endpoints/single-route-helpers.ts
|
|
671
787
|
var METHOD_NAMES = [
|
|
672
788
|
"agent/run",
|
|
@@ -756,9 +872,9 @@ function createCopilotEndpointSingleRouteExpress({
|
|
|
756
872
|
runtime,
|
|
757
873
|
basePath
|
|
758
874
|
}) {
|
|
759
|
-
const router =
|
|
875
|
+
const router = import_express2.default.Router();
|
|
760
876
|
const routePath = normalizeSingleRoutePath(basePath);
|
|
761
|
-
router.use(
|
|
877
|
+
router.use((0, import_cors2.default)({
|
|
762
878
|
origin: "*",
|
|
763
879
|
methods: ["GET", "HEAD", "PUT", "POST", "DELETE", "PATCH", "OPTIONS"],
|
|
764
880
|
allowedHeaders: ["*"]
|
|
@@ -779,7 +895,7 @@ function createSingleRouteHandler(runtime) {
|
|
|
779
895
|
request = maybeModifiedRequest;
|
|
780
896
|
}
|
|
781
897
|
} catch (error) {
|
|
782
|
-
|
|
898
|
+
import_shared4.logger.error({ err: error, url: request.url, path }, "Error running before request middleware");
|
|
783
899
|
if (error instanceof Response) {
|
|
784
900
|
try {
|
|
785
901
|
await sendFetchResponse(res, error);
|
|
@@ -796,7 +912,7 @@ function createSingleRouteHandler(runtime) {
|
|
|
796
912
|
methodCall = await parseMethodCall(request);
|
|
797
913
|
} catch (error) {
|
|
798
914
|
if (error instanceof Response) {
|
|
799
|
-
|
|
915
|
+
import_shared4.logger.warn({ url: request.url }, "Invalid single-route payload");
|
|
800
916
|
try {
|
|
801
917
|
await sendFetchResponse(res, error);
|
|
802
918
|
} catch (streamError) {
|
|
@@ -804,7 +920,7 @@ function createSingleRouteHandler(runtime) {
|
|
|
804
920
|
}
|
|
805
921
|
return;
|
|
806
922
|
}
|
|
807
|
-
|
|
923
|
+
import_shared4.logger.warn({ err: error, url: request.url }, "Invalid single-route payload");
|
|
808
924
|
res.status(400).json({
|
|
809
925
|
error: "invalid_request",
|
|
810
926
|
message: error instanceof Error ? error.message : "Invalid request payload"
|
|
@@ -847,7 +963,7 @@ function createSingleRouteHandler(runtime) {
|
|
|
847
963
|
}
|
|
848
964
|
await sendFetchResponse(res, response);
|
|
849
965
|
callAfterRequestMiddleware({ runtime, response, path }).catch((error) => {
|
|
850
|
-
|
|
966
|
+
import_shared4.logger.error({ err: error, url: req.originalUrl ?? req.url, path }, "Error running after request middleware");
|
|
851
967
|
});
|
|
852
968
|
} catch (error) {
|
|
853
969
|
if (error instanceof Response) {
|
|
@@ -858,11 +974,11 @@ function createSingleRouteHandler(runtime) {
|
|
|
858
974
|
return;
|
|
859
975
|
}
|
|
860
976
|
callAfterRequestMiddleware({ runtime, response: error, path }).catch((mwError) => {
|
|
861
|
-
|
|
977
|
+
import_shared4.logger.error({ err: mwError, url: req.originalUrl ?? req.url, path }, "Error running after request middleware");
|
|
862
978
|
});
|
|
863
979
|
return;
|
|
864
980
|
}
|
|
865
|
-
|
|
981
|
+
import_shared4.logger.error({ err: error, url: request.url, path }, "Error running single-route handler");
|
|
866
982
|
next(error);
|
|
867
983
|
}
|
|
868
984
|
};
|
|
@@ -879,8 +995,9 @@ function normalizeSingleRoutePath(path) {
|
|
|
879
995
|
}
|
|
880
996
|
return path;
|
|
881
997
|
}
|
|
882
|
-
|
|
883
|
-
exports
|
|
884
|
-
|
|
885
|
-
|
|
998
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
999
|
+
0 && (module.exports = {
|
|
1000
|
+
createCopilotEndpointExpress,
|
|
1001
|
+
createCopilotEndpointSingleRouteExpress
|
|
1002
|
+
});
|
|
886
1003
|
//# sourceMappingURL=express.js.map
|