@copilotkitnext/runtime 1.51.4-next.7 → 1.51.4
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-O6YC5CJ6.mjs → chunk-5GKH3W25.mjs} +20 -8
- package/dist/chunk-5GKH3W25.mjs.map +1 -0
- package/dist/express.d.mts +1 -1
- package/dist/express.d.ts +1 -1
- package/dist/express.js +148 -57
- package/dist/express.js.map +1 -1
- package/dist/express.mjs +130 -51
- package/dist/express.mjs.map +1 -1
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +107 -25
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +89 -19
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -6
- package/.cursor/rules/runtime.always.mdc +0 -9
- package/dist/chunk-O6YC5CJ6.mjs.map +0 -1
package/dist/index.js
CHANGED
|
@@ -34,7 +34,7 @@ module.exports = __toCommonJS(index_exports);
|
|
|
34
34
|
// package.json
|
|
35
35
|
var package_default = {
|
|
36
36
|
name: "@copilotkitnext/runtime",
|
|
37
|
-
version: "1.51.4
|
|
37
|
+
version: "1.51.4",
|
|
38
38
|
description: "Server-side runtime package for CopilotKit2",
|
|
39
39
|
main: "dist/index.js",
|
|
40
40
|
types: "dist/index.d.ts",
|
|
@@ -58,7 +58,6 @@ var package_default = {
|
|
|
58
58
|
dev: "tsup --watch",
|
|
59
59
|
lint: "eslint .",
|
|
60
60
|
"check-types": "tsc --noEmit",
|
|
61
|
-
clean: "rm -rf dist",
|
|
62
61
|
test: "vitest run",
|
|
63
62
|
"test:watch": "vitest",
|
|
64
63
|
"test:coverage": "vitest run --coverage"
|
|
@@ -647,7 +646,10 @@ async function extractAudioFromFormData(request) {
|
|
|
647
646
|
return { error: createErrorResponse(err) };
|
|
648
647
|
}
|
|
649
648
|
if (!isValidAudioType(audioFile.type)) {
|
|
650
|
-
const err = import_shared2.TranscriptionErrors.invalidAudioFormat(
|
|
649
|
+
const err = import_shared2.TranscriptionErrors.invalidAudioFormat(
|
|
650
|
+
audioFile.type,
|
|
651
|
+
VALID_AUDIO_TYPES
|
|
652
|
+
);
|
|
651
653
|
return { error: createErrorResponse(err) };
|
|
652
654
|
}
|
|
653
655
|
return { file: audioFile };
|
|
@@ -657,7 +659,9 @@ async function extractAudioFromJson(request) {
|
|
|
657
659
|
try {
|
|
658
660
|
body = await request.json();
|
|
659
661
|
} catch {
|
|
660
|
-
const err = import_shared2.TranscriptionErrors.invalidRequest(
|
|
662
|
+
const err = import_shared2.TranscriptionErrors.invalidRequest(
|
|
663
|
+
"Request body must be valid JSON"
|
|
664
|
+
);
|
|
661
665
|
return { error: createErrorResponse(err) };
|
|
662
666
|
}
|
|
663
667
|
if (!body.audio || typeof body.audio !== "string") {
|
|
@@ -673,7 +677,10 @@ async function extractAudioFromJson(request) {
|
|
|
673
677
|
return { error: createErrorResponse(err) };
|
|
674
678
|
}
|
|
675
679
|
if (!isValidAudioType(body.mimeType)) {
|
|
676
|
-
const err = import_shared2.TranscriptionErrors.invalidAudioFormat(
|
|
680
|
+
const err = import_shared2.TranscriptionErrors.invalidAudioFormat(
|
|
681
|
+
body.mimeType,
|
|
682
|
+
VALID_AUDIO_TYPES
|
|
683
|
+
);
|
|
677
684
|
return { error: createErrorResponse(err) };
|
|
678
685
|
}
|
|
679
686
|
try {
|
|
@@ -681,7 +688,9 @@ async function extractAudioFromJson(request) {
|
|
|
681
688
|
const file = base64ToFile(body.audio, body.mimeType, filename);
|
|
682
689
|
return { file };
|
|
683
690
|
} catch {
|
|
684
|
-
const err = import_shared2.TranscriptionErrors.invalidRequest(
|
|
691
|
+
const err = import_shared2.TranscriptionErrors.invalidRequest(
|
|
692
|
+
"Failed to decode base64 audio data"
|
|
693
|
+
);
|
|
685
694
|
return { error: createErrorResponse(err) };
|
|
686
695
|
}
|
|
687
696
|
}
|
|
@@ -972,13 +981,25 @@ async function handleStopAgent({
|
|
|
972
981
|
}
|
|
973
982
|
|
|
974
983
|
// src/endpoints/hono.ts
|
|
975
|
-
function createCopilotEndpoint({
|
|
984
|
+
function createCopilotEndpoint({
|
|
985
|
+
runtime,
|
|
986
|
+
basePath,
|
|
987
|
+
cors: corsConfig
|
|
988
|
+
}) {
|
|
976
989
|
const app = new import_hono.Hono();
|
|
977
990
|
return app.basePath(basePath).use(
|
|
978
991
|
"*",
|
|
979
992
|
(0, import_cors.cors)({
|
|
980
993
|
origin: corsConfig?.origin ?? "*",
|
|
981
|
-
allowMethods: [
|
|
994
|
+
allowMethods: [
|
|
995
|
+
"GET",
|
|
996
|
+
"HEAD",
|
|
997
|
+
"PUT",
|
|
998
|
+
"POST",
|
|
999
|
+
"DELETE",
|
|
1000
|
+
"PATCH",
|
|
1001
|
+
"OPTIONS"
|
|
1002
|
+
],
|
|
982
1003
|
allowHeaders: ["*"],
|
|
983
1004
|
credentials: corsConfig?.credentials ?? false
|
|
984
1005
|
})
|
|
@@ -995,7 +1016,10 @@ function createCopilotEndpoint({ runtime, basePath, cors: corsConfig }) {
|
|
|
995
1016
|
c.set("modifiedRequest", maybeModifiedRequest);
|
|
996
1017
|
}
|
|
997
1018
|
} catch (error) {
|
|
998
|
-
import_shared4.logger.error(
|
|
1019
|
+
import_shared4.logger.error(
|
|
1020
|
+
{ err: error, url: request.url, path },
|
|
1021
|
+
"Error running before request middleware"
|
|
1022
|
+
);
|
|
999
1023
|
if (error instanceof Response) {
|
|
1000
1024
|
return error;
|
|
1001
1025
|
}
|
|
@@ -1011,7 +1035,10 @@ function createCopilotEndpoint({ runtime, basePath, cors: corsConfig }) {
|
|
|
1011
1035
|
response,
|
|
1012
1036
|
path
|
|
1013
1037
|
}).catch((error) => {
|
|
1014
|
-
import_shared4.logger.error(
|
|
1038
|
+
import_shared4.logger.error(
|
|
1039
|
+
{ err: error, url: c.req.url, path },
|
|
1040
|
+
"Error running after request middleware"
|
|
1041
|
+
);
|
|
1015
1042
|
});
|
|
1016
1043
|
}).post("/agent/:agentId/run", async (c) => {
|
|
1017
1044
|
const agentId = c.req.param("agentId");
|
|
@@ -1023,7 +1050,10 @@ function createCopilotEndpoint({ runtime, basePath, cors: corsConfig }) {
|
|
|
1023
1050
|
agentId
|
|
1024
1051
|
});
|
|
1025
1052
|
} catch (error) {
|
|
1026
|
-
import_shared4.logger.error(
|
|
1053
|
+
import_shared4.logger.error(
|
|
1054
|
+
{ err: error, url: request.url, path: c.req.path },
|
|
1055
|
+
"Error running request handler"
|
|
1056
|
+
);
|
|
1027
1057
|
throw error;
|
|
1028
1058
|
}
|
|
1029
1059
|
}).post("/agent/:agentId/connect", async (c) => {
|
|
@@ -1036,7 +1066,10 @@ function createCopilotEndpoint({ runtime, basePath, cors: corsConfig }) {
|
|
|
1036
1066
|
agentId
|
|
1037
1067
|
});
|
|
1038
1068
|
} catch (error) {
|
|
1039
|
-
import_shared4.logger.error(
|
|
1069
|
+
import_shared4.logger.error(
|
|
1070
|
+
{ err: error, url: request.url, path: c.req.path },
|
|
1071
|
+
"Error running request handler"
|
|
1072
|
+
);
|
|
1040
1073
|
throw error;
|
|
1041
1074
|
}
|
|
1042
1075
|
}).post("/agent/:agentId/stop/:threadId", async (c) => {
|
|
@@ -1051,7 +1084,10 @@ function createCopilotEndpoint({ runtime, basePath, cors: corsConfig }) {
|
|
|
1051
1084
|
threadId
|
|
1052
1085
|
});
|
|
1053
1086
|
} catch (error) {
|
|
1054
|
-
import_shared4.logger.error(
|
|
1087
|
+
import_shared4.logger.error(
|
|
1088
|
+
{ err: error, url: request.url, path: c.req.path },
|
|
1089
|
+
"Error running request handler"
|
|
1090
|
+
);
|
|
1055
1091
|
throw error;
|
|
1056
1092
|
}
|
|
1057
1093
|
}).get("/info", async (c) => {
|
|
@@ -1062,7 +1098,10 @@ function createCopilotEndpoint({ runtime, basePath, cors: corsConfig }) {
|
|
|
1062
1098
|
request
|
|
1063
1099
|
});
|
|
1064
1100
|
} catch (error) {
|
|
1065
|
-
import_shared4.logger.error(
|
|
1101
|
+
import_shared4.logger.error(
|
|
1102
|
+
{ err: error, url: request.url, path: c.req.path },
|
|
1103
|
+
"Error running request handler"
|
|
1104
|
+
);
|
|
1066
1105
|
throw error;
|
|
1067
1106
|
}
|
|
1068
1107
|
}).post("/transcribe", async (c) => {
|
|
@@ -1073,7 +1112,10 @@ function createCopilotEndpoint({ runtime, basePath, cors: corsConfig }) {
|
|
|
1073
1112
|
request
|
|
1074
1113
|
});
|
|
1075
1114
|
} catch (error) {
|
|
1076
|
-
import_shared4.logger.error(
|
|
1115
|
+
import_shared4.logger.error(
|
|
1116
|
+
{ err: error, url: request.url, path: c.req.path },
|
|
1117
|
+
"Error running request handler"
|
|
1118
|
+
);
|
|
1077
1119
|
throw error;
|
|
1078
1120
|
}
|
|
1079
1121
|
}).notFound((c) => {
|
|
@@ -1097,7 +1139,10 @@ var METHOD_NAMES = [
|
|
|
1097
1139
|
async function parseMethodCall(request) {
|
|
1098
1140
|
const contentType = request.headers.get("content-type") || "";
|
|
1099
1141
|
if (!contentType.includes("application/json")) {
|
|
1100
|
-
throw createResponseError(
|
|
1142
|
+
throw createResponseError(
|
|
1143
|
+
"Single-route endpoint expects JSON payloads",
|
|
1144
|
+
415
|
|
1145
|
+
);
|
|
1101
1146
|
}
|
|
1102
1147
|
let jsonEnvelope;
|
|
1103
1148
|
try {
|
|
@@ -1171,14 +1216,26 @@ function serializeJsonBody(body) {
|
|
|
1171
1216
|
}
|
|
1172
1217
|
|
|
1173
1218
|
// src/endpoints/hono-single.ts
|
|
1174
|
-
function createCopilotEndpointSingleRoute({
|
|
1219
|
+
function createCopilotEndpointSingleRoute({
|
|
1220
|
+
runtime,
|
|
1221
|
+
basePath,
|
|
1222
|
+
cors: corsConfig
|
|
1223
|
+
}) {
|
|
1175
1224
|
const app = new import_hono2.Hono();
|
|
1176
1225
|
const routePath = normalizePath(basePath);
|
|
1177
1226
|
return app.basePath(routePath).use(
|
|
1178
1227
|
"*",
|
|
1179
1228
|
(0, import_cors2.cors)({
|
|
1180
1229
|
origin: corsConfig?.origin ?? "*",
|
|
1181
|
-
allowMethods: [
|
|
1230
|
+
allowMethods: [
|
|
1231
|
+
"GET",
|
|
1232
|
+
"HEAD",
|
|
1233
|
+
"PUT",
|
|
1234
|
+
"POST",
|
|
1235
|
+
"DELETE",
|
|
1236
|
+
"PATCH",
|
|
1237
|
+
"OPTIONS"
|
|
1238
|
+
],
|
|
1182
1239
|
allowHeaders: ["*"],
|
|
1183
1240
|
credentials: corsConfig?.credentials ?? false
|
|
1184
1241
|
})
|
|
@@ -1195,7 +1252,10 @@ function createCopilotEndpointSingleRoute({ runtime, basePath, cors: corsConfig
|
|
|
1195
1252
|
c.set("modifiedRequest", maybeModifiedRequest);
|
|
1196
1253
|
}
|
|
1197
1254
|
} catch (error) {
|
|
1198
|
-
import_shared5.logger.error(
|
|
1255
|
+
import_shared5.logger.error(
|
|
1256
|
+
{ err: error, url: request.url, path },
|
|
1257
|
+
"Error running before request middleware"
|
|
1258
|
+
);
|
|
1199
1259
|
if (error instanceof Response) {
|
|
1200
1260
|
return error;
|
|
1201
1261
|
}
|
|
@@ -1211,7 +1271,10 @@ function createCopilotEndpointSingleRoute({ runtime, basePath, cors: corsConfig
|
|
|
1211
1271
|
response,
|
|
1212
1272
|
path
|
|
1213
1273
|
}).catch((error) => {
|
|
1214
|
-
import_shared5.logger.error(
|
|
1274
|
+
import_shared5.logger.error(
|
|
1275
|
+
{ err: error, url: c.req.url, path },
|
|
1276
|
+
"Error running after request middleware"
|
|
1277
|
+
);
|
|
1215
1278
|
});
|
|
1216
1279
|
}).post("/", async (c) => {
|
|
1217
1280
|
const request = c.get("modifiedRequest") || c.req.raw;
|
|
@@ -1223,7 +1286,10 @@ function createCopilotEndpointSingleRoute({ runtime, basePath, cors: corsConfig
|
|
|
1223
1286
|
import_shared5.logger.warn({ url: request.url }, "Invalid single-route payload");
|
|
1224
1287
|
return error;
|
|
1225
1288
|
}
|
|
1226
|
-
import_shared5.logger.warn(
|
|
1289
|
+
import_shared5.logger.warn(
|
|
1290
|
+
{ err: error, url: request.url },
|
|
1291
|
+
"Invalid single-route payload"
|
|
1292
|
+
);
|
|
1227
1293
|
return c.json(
|
|
1228
1294
|
{
|
|
1229
1295
|
error: "invalid_request",
|
|
@@ -1237,17 +1303,30 @@ function createCopilotEndpointSingleRoute({ runtime, basePath, cors: corsConfig
|
|
|
1237
1303
|
case "agent/run": {
|
|
1238
1304
|
const agentId = expectString(methodCall.params, "agentId");
|
|
1239
1305
|
const handlerRequest = createJsonRequest(request, methodCall.body);
|
|
1240
|
-
return await handleRunAgent({
|
|
1306
|
+
return await handleRunAgent({
|
|
1307
|
+
runtime,
|
|
1308
|
+
request: handlerRequest,
|
|
1309
|
+
agentId
|
|
1310
|
+
});
|
|
1241
1311
|
}
|
|
1242
1312
|
case "agent/connect": {
|
|
1243
1313
|
const agentId = expectString(methodCall.params, "agentId");
|
|
1244
1314
|
const handlerRequest = createJsonRequest(request, methodCall.body);
|
|
1245
|
-
return await handleConnectAgent({
|
|
1315
|
+
return await handleConnectAgent({
|
|
1316
|
+
runtime,
|
|
1317
|
+
request: handlerRequest,
|
|
1318
|
+
agentId
|
|
1319
|
+
});
|
|
1246
1320
|
}
|
|
1247
1321
|
case "agent/stop": {
|
|
1248
1322
|
const agentId = expectString(methodCall.params, "agentId");
|
|
1249
1323
|
const threadId = expectString(methodCall.params, "threadId");
|
|
1250
|
-
return await handleStopAgent({
|
|
1324
|
+
return await handleStopAgent({
|
|
1325
|
+
runtime,
|
|
1326
|
+
request,
|
|
1327
|
+
agentId,
|
|
1328
|
+
threadId
|
|
1329
|
+
});
|
|
1251
1330
|
}
|
|
1252
1331
|
case "info": {
|
|
1253
1332
|
return await handleGetRuntimeInfo({ runtime, request });
|
|
@@ -1265,7 +1344,10 @@ function createCopilotEndpointSingleRoute({ runtime, basePath, cors: corsConfig
|
|
|
1265
1344
|
if (error instanceof Response) {
|
|
1266
1345
|
return error;
|
|
1267
1346
|
}
|
|
1268
|
-
import_shared5.logger.error(
|
|
1347
|
+
import_shared5.logger.error(
|
|
1348
|
+
{ err: error, url: request.url, method: methodCall.method },
|
|
1349
|
+
"Error running single-route handler"
|
|
1350
|
+
);
|
|
1269
1351
|
throw error;
|
|
1270
1352
|
}
|
|
1271
1353
|
}).notFound((c) => {
|