@copilotkitnext/runtime 0.0.20 → 0.0.21

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.d.mts CHANGED
@@ -1,112 +1,21 @@
1
- import { MaybePromise, NonEmptyRecord } from '@copilotkitnext/shared';
2
- export { finalizeRunEvents } from '@copilotkitnext/shared';
3
- import { AbstractAgent, RunAgentInput, BaseEvent } from '@ag-ui/client';
4
- import { Observable } from 'rxjs';
1
+ import { C as CopilotRuntime, A as AgentRunner, a as AgentRunnerRunRequest, b as AgentRunnerConnectRequest, c as AgentRunnerIsRunningRequest, d as AgentRunnerStopRequest } from './runtime-BEcxV64L.mjs';
2
+ export { e as CopilotRuntimeOptions, V as VERSION } from './runtime-BEcxV64L.mjs';
5
3
  import * as hono_hono_base from 'hono/hono-base';
6
4
  import * as hono_utils_http_status from 'hono/utils/http-status';
7
-
8
- /**
9
- * Middleware support for CopilotKit Runtime.
10
- *
11
- * A middleware hook can be provided as either:
12
- * 1. A **callback function** executed in-process.
13
- * 2. A **webhook URL** (http/https). The runtime will `POST` a JSON payload
14
- * to the URL and, for *before* hooks, accept an optional modified
15
- * `Request` object in the response body.
16
- *
17
- * Two lifecycle hooks are available:
18
- * • `BEFORE_REQUEST` – runs *before* the request handler.
19
- * • `AFTER_REQUEST` – runs *after* the handler returns a `Response`.
20
- */
21
-
22
- interface BeforeRequestMiddlewareParameters {
23
- runtime: CopilotRuntime;
24
- request: Request;
25
- path: string;
26
- }
27
- interface AfterRequestMiddlewareParameters {
28
- runtime: CopilotRuntime;
29
- response: Response;
30
- path: string;
31
- }
32
- type BeforeRequestMiddlewareFn = (params: BeforeRequestMiddlewareParameters) => MaybePromise<Request | void>;
33
- type AfterRequestMiddlewareFn = (params: AfterRequestMiddlewareParameters) => MaybePromise<void>;
34
- /**
35
- * A middleware value can be either a callback function or a webhook URL.
36
- */
37
- type BeforeRequestMiddleware = BeforeRequestMiddlewareFn;
38
- type AfterRequestMiddleware = AfterRequestMiddlewareFn;
39
-
40
- interface TranscribeFileOptions {
41
- audioFile: File;
42
- /** MIME type of the audio file */
43
- mimeType?: string;
44
- /** Size of the audio file in bytes */
45
- size?: number;
46
- }
47
- declare abstract class TranscriptionService {
48
- abstract transcribeFile(options: TranscribeFileOptions): Promise<string>;
49
- }
50
-
51
- interface AgentRunnerRunRequest {
52
- threadId: string;
53
- agent: AbstractAgent;
54
- input: RunAgentInput;
55
- }
56
- interface AgentRunnerConnectRequest {
57
- threadId: string;
58
- }
59
- interface AgentRunnerIsRunningRequest {
60
- threadId: string;
61
- }
62
- interface AgentRunnerStopRequest {
63
- threadId: string;
64
- }
65
- declare abstract class AgentRunner {
66
- abstract run(request: AgentRunnerRunRequest): Observable<BaseEvent>;
67
- abstract connect(request: AgentRunnerConnectRequest): Observable<BaseEvent>;
68
- abstract isRunning(request: AgentRunnerIsRunningRequest): Promise<boolean>;
69
- abstract stop(request: AgentRunnerStopRequest): Promise<boolean | undefined>;
70
- }
71
-
72
- declare const VERSION: string;
73
- /**
74
- * Options used to construct a `CopilotRuntime` instance.
75
- */
76
- interface CopilotRuntimeOptions {
77
- /** Map of available agents (loaded lazily is fine). */
78
- agents: MaybePromise<NonEmptyRecord<Record<string, AbstractAgent>>>;
79
- /** The runner to use for running agents. */
80
- runner?: AgentRunner;
81
- /** Optional transcription service for audio processing. */
82
- transcriptionService?: TranscriptionService;
83
- /** Optional *before* middleware – callback function or webhook URL. */
84
- beforeRequestMiddleware?: BeforeRequestMiddleware;
85
- /** Optional *after* middleware – callback function or webhook URL. */
86
- afterRequestMiddleware?: AfterRequestMiddleware;
87
- }
88
- /**
89
- * Central runtime object passed to all request handlers.
90
- */
91
- declare class CopilotRuntime {
92
- agents: CopilotRuntimeOptions["agents"];
93
- transcriptionService: CopilotRuntimeOptions["transcriptionService"];
94
- beforeRequestMiddleware: CopilotRuntimeOptions["beforeRequestMiddleware"];
95
- afterRequestMiddleware: CopilotRuntimeOptions["afterRequestMiddleware"];
96
- runner: AgentRunner;
97
- constructor({ agents, transcriptionService, beforeRequestMiddleware, afterRequestMiddleware, runner, }: CopilotRuntimeOptions);
98
- }
5
+ import { Observable } from 'rxjs';
6
+ import { BaseEvent } from '@ag-ui/client';
7
+ export { finalizeRunEvents } from '@copilotkitnext/shared';
99
8
 
100
9
  interface CopilotEndpointParams {
101
10
  runtime: CopilotRuntime;
102
11
  basePath: string;
103
12
  }
104
- type CopilotEndpointContext = {
13
+ type CopilotEndpointContext$1 = {
105
14
  Variables: {
106
15
  modifiedRequest?: Request;
107
16
  };
108
17
  };
109
- declare function createCopilotEndpoint({ runtime, basePath }: CopilotEndpointParams): hono_hono_base.HonoBase<CopilotEndpointContext, {
18
+ declare function createCopilotEndpoint({ runtime, basePath }: CopilotEndpointParams): hono_hono_base.HonoBase<CopilotEndpointContext$1, {
110
19
  [x: `${string}/*`]: {};
111
20
  } & {
112
21
  [x: `${string}/agent/:agentId/run`]: {
@@ -169,6 +78,31 @@ declare function createCopilotEndpoint({ runtime, basePath }: CopilotEndpointPar
169
78
  };
170
79
  }, string>;
171
80
 
81
+ interface CopilotSingleEndpointParams {
82
+ runtime: CopilotRuntime;
83
+ /**
84
+ * Absolute path at which to mount the single-route endpoint (e.g. "/api/copilotkit").
85
+ */
86
+ basePath: string;
87
+ }
88
+ type CopilotEndpointContext = {
89
+ Variables: {
90
+ modifiedRequest?: Request;
91
+ };
92
+ };
93
+ declare function createCopilotEndpointSingleRoute({ runtime, basePath }: CopilotSingleEndpointParams): hono_hono_base.HonoBase<CopilotEndpointContext, {
94
+ [x: `${string}/*`]: {};
95
+ } & {
96
+ [x: string]: {
97
+ $post: {
98
+ input: {};
99
+ output: {};
100
+ outputFormat: string;
101
+ status: hono_utils_http_status.StatusCode;
102
+ };
103
+ };
104
+ }, string>;
105
+
172
106
  declare class InMemoryAgentRunner extends AgentRunner {
173
107
  run(request: AgentRunnerRunRequest): Observable<BaseEvent>;
174
108
  connect(request: AgentRunnerConnectRequest): Observable<BaseEvent>;
@@ -176,4 +110,4 @@ declare class InMemoryAgentRunner extends AgentRunner {
176
110
  stop(request: AgentRunnerStopRequest): Promise<boolean | undefined>;
177
111
  }
178
112
 
179
- export { AgentRunner, type AgentRunnerConnectRequest, type AgentRunnerIsRunningRequest, type AgentRunnerRunRequest, type AgentRunnerStopRequest, CopilotRuntime, type CopilotRuntimeOptions, InMemoryAgentRunner, VERSION, createCopilotEndpoint };
113
+ export { AgentRunner, AgentRunnerConnectRequest, AgentRunnerIsRunningRequest, AgentRunnerRunRequest, AgentRunnerStopRequest, CopilotRuntime, InMemoryAgentRunner, createCopilotEndpoint, createCopilotEndpointSingleRoute };
package/dist/index.d.ts CHANGED
@@ -1,112 +1,21 @@
1
- import { MaybePromise, NonEmptyRecord } from '@copilotkitnext/shared';
2
- export { finalizeRunEvents } from '@copilotkitnext/shared';
3
- import { AbstractAgent, RunAgentInput, BaseEvent } from '@ag-ui/client';
4
- import { Observable } from 'rxjs';
1
+ import { C as CopilotRuntime, A as AgentRunner, a as AgentRunnerRunRequest, b as AgentRunnerConnectRequest, c as AgentRunnerIsRunningRequest, d as AgentRunnerStopRequest } from './runtime-BEcxV64L.js';
2
+ export { e as CopilotRuntimeOptions, V as VERSION } from './runtime-BEcxV64L.js';
5
3
  import * as hono_hono_base from 'hono/hono-base';
6
4
  import * as hono_utils_http_status from 'hono/utils/http-status';
7
-
8
- /**
9
- * Middleware support for CopilotKit Runtime.
10
- *
11
- * A middleware hook can be provided as either:
12
- * 1. A **callback function** executed in-process.
13
- * 2. A **webhook URL** (http/https). The runtime will `POST` a JSON payload
14
- * to the URL and, for *before* hooks, accept an optional modified
15
- * `Request` object in the response body.
16
- *
17
- * Two lifecycle hooks are available:
18
- * • `BEFORE_REQUEST` – runs *before* the request handler.
19
- * • `AFTER_REQUEST` – runs *after* the handler returns a `Response`.
20
- */
21
-
22
- interface BeforeRequestMiddlewareParameters {
23
- runtime: CopilotRuntime;
24
- request: Request;
25
- path: string;
26
- }
27
- interface AfterRequestMiddlewareParameters {
28
- runtime: CopilotRuntime;
29
- response: Response;
30
- path: string;
31
- }
32
- type BeforeRequestMiddlewareFn = (params: BeforeRequestMiddlewareParameters) => MaybePromise<Request | void>;
33
- type AfterRequestMiddlewareFn = (params: AfterRequestMiddlewareParameters) => MaybePromise<void>;
34
- /**
35
- * A middleware value can be either a callback function or a webhook URL.
36
- */
37
- type BeforeRequestMiddleware = BeforeRequestMiddlewareFn;
38
- type AfterRequestMiddleware = AfterRequestMiddlewareFn;
39
-
40
- interface TranscribeFileOptions {
41
- audioFile: File;
42
- /** MIME type of the audio file */
43
- mimeType?: string;
44
- /** Size of the audio file in bytes */
45
- size?: number;
46
- }
47
- declare abstract class TranscriptionService {
48
- abstract transcribeFile(options: TranscribeFileOptions): Promise<string>;
49
- }
50
-
51
- interface AgentRunnerRunRequest {
52
- threadId: string;
53
- agent: AbstractAgent;
54
- input: RunAgentInput;
55
- }
56
- interface AgentRunnerConnectRequest {
57
- threadId: string;
58
- }
59
- interface AgentRunnerIsRunningRequest {
60
- threadId: string;
61
- }
62
- interface AgentRunnerStopRequest {
63
- threadId: string;
64
- }
65
- declare abstract class AgentRunner {
66
- abstract run(request: AgentRunnerRunRequest): Observable<BaseEvent>;
67
- abstract connect(request: AgentRunnerConnectRequest): Observable<BaseEvent>;
68
- abstract isRunning(request: AgentRunnerIsRunningRequest): Promise<boolean>;
69
- abstract stop(request: AgentRunnerStopRequest): Promise<boolean | undefined>;
70
- }
71
-
72
- declare const VERSION: string;
73
- /**
74
- * Options used to construct a `CopilotRuntime` instance.
75
- */
76
- interface CopilotRuntimeOptions {
77
- /** Map of available agents (loaded lazily is fine). */
78
- agents: MaybePromise<NonEmptyRecord<Record<string, AbstractAgent>>>;
79
- /** The runner to use for running agents. */
80
- runner?: AgentRunner;
81
- /** Optional transcription service for audio processing. */
82
- transcriptionService?: TranscriptionService;
83
- /** Optional *before* middleware – callback function or webhook URL. */
84
- beforeRequestMiddleware?: BeforeRequestMiddleware;
85
- /** Optional *after* middleware – callback function or webhook URL. */
86
- afterRequestMiddleware?: AfterRequestMiddleware;
87
- }
88
- /**
89
- * Central runtime object passed to all request handlers.
90
- */
91
- declare class CopilotRuntime {
92
- agents: CopilotRuntimeOptions["agents"];
93
- transcriptionService: CopilotRuntimeOptions["transcriptionService"];
94
- beforeRequestMiddleware: CopilotRuntimeOptions["beforeRequestMiddleware"];
95
- afterRequestMiddleware: CopilotRuntimeOptions["afterRequestMiddleware"];
96
- runner: AgentRunner;
97
- constructor({ agents, transcriptionService, beforeRequestMiddleware, afterRequestMiddleware, runner, }: CopilotRuntimeOptions);
98
- }
5
+ import { Observable } from 'rxjs';
6
+ import { BaseEvent } from '@ag-ui/client';
7
+ export { finalizeRunEvents } from '@copilotkitnext/shared';
99
8
 
100
9
  interface CopilotEndpointParams {
101
10
  runtime: CopilotRuntime;
102
11
  basePath: string;
103
12
  }
104
- type CopilotEndpointContext = {
13
+ type CopilotEndpointContext$1 = {
105
14
  Variables: {
106
15
  modifiedRequest?: Request;
107
16
  };
108
17
  };
109
- declare function createCopilotEndpoint({ runtime, basePath }: CopilotEndpointParams): hono_hono_base.HonoBase<CopilotEndpointContext, {
18
+ declare function createCopilotEndpoint({ runtime, basePath }: CopilotEndpointParams): hono_hono_base.HonoBase<CopilotEndpointContext$1, {
110
19
  [x: `${string}/*`]: {};
111
20
  } & {
112
21
  [x: `${string}/agent/:agentId/run`]: {
@@ -169,6 +78,31 @@ declare function createCopilotEndpoint({ runtime, basePath }: CopilotEndpointPar
169
78
  };
170
79
  }, string>;
171
80
 
81
+ interface CopilotSingleEndpointParams {
82
+ runtime: CopilotRuntime;
83
+ /**
84
+ * Absolute path at which to mount the single-route endpoint (e.g. "/api/copilotkit").
85
+ */
86
+ basePath: string;
87
+ }
88
+ type CopilotEndpointContext = {
89
+ Variables: {
90
+ modifiedRequest?: Request;
91
+ };
92
+ };
93
+ declare function createCopilotEndpointSingleRoute({ runtime, basePath }: CopilotSingleEndpointParams): hono_hono_base.HonoBase<CopilotEndpointContext, {
94
+ [x: `${string}/*`]: {};
95
+ } & {
96
+ [x: string]: {
97
+ $post: {
98
+ input: {};
99
+ output: {};
100
+ outputFormat: string;
101
+ status: hono_utils_http_status.StatusCode;
102
+ };
103
+ };
104
+ }, string>;
105
+
172
106
  declare class InMemoryAgentRunner extends AgentRunner {
173
107
  run(request: AgentRunnerRunRequest): Observable<BaseEvent>;
174
108
  connect(request: AgentRunnerConnectRequest): Observable<BaseEvent>;
@@ -176,4 +110,4 @@ declare class InMemoryAgentRunner extends AgentRunner {
176
110
  stop(request: AgentRunnerStopRequest): Promise<boolean | undefined>;
177
111
  }
178
112
 
179
- export { AgentRunner, type AgentRunnerConnectRequest, type AgentRunnerIsRunningRequest, type AgentRunnerRunRequest, type AgentRunnerStopRequest, CopilotRuntime, type CopilotRuntimeOptions, InMemoryAgentRunner, VERSION, createCopilotEndpoint };
113
+ export { AgentRunner, AgentRunnerConnectRequest, AgentRunnerIsRunningRequest, AgentRunnerRunRequest, AgentRunnerStopRequest, CopilotRuntime, InMemoryAgentRunner, createCopilotEndpoint, createCopilotEndpointSingleRoute };
package/dist/index.js CHANGED
@@ -25,14 +25,15 @@ __export(index_exports, {
25
25
  InMemoryAgentRunner: () => InMemoryAgentRunner,
26
26
  VERSION: () => VERSION,
27
27
  createCopilotEndpoint: () => createCopilotEndpoint,
28
- finalizeRunEvents: () => import_shared4.finalizeRunEvents
28
+ createCopilotEndpointSingleRoute: () => createCopilotEndpointSingleRoute,
29
+ finalizeRunEvents: () => import_shared5.finalizeRunEvents
29
30
  });
30
31
  module.exports = __toCommonJS(index_exports);
31
32
 
32
33
  // package.json
33
34
  var package_default = {
34
35
  name: "@copilotkitnext/runtime",
35
- version: "0.0.20",
36
+ version: "0.0.21",
36
37
  description: "Server-side runtime package for CopilotKit2",
37
38
  main: "dist/index.js",
38
39
  types: "dist/index.d.ts",
@@ -41,6 +42,11 @@ var package_default = {
41
42
  types: "./dist/index.d.ts",
42
43
  import: "./dist/index.mjs",
43
44
  require: "./dist/index.js"
45
+ },
46
+ "./express": {
47
+ types: "./dist/express.d.ts",
48
+ import: "./dist/express.mjs",
49
+ require: "./dist/express.js"
44
50
  }
45
51
  },
46
52
  publishConfig: {
@@ -60,18 +66,23 @@ var package_default = {
60
66
  devDependencies: {
61
67
  "@copilotkitnext/eslint-config": "workspace:*",
62
68
  "@copilotkitnext/typescript-config": "workspace:*",
69
+ "@types/cors": "^2.8.17",
70
+ "@types/express": "^4.17.21",
63
71
  "@types/node": "^22.15.3",
64
72
  eslint: "^9.30.0",
65
73
  openai: "^5.9.0",
74
+ supertest: "^7.1.1",
66
75
  tsup: "^8.5.0",
67
76
  typescript: "5.8.2",
68
77
  vitest: "^3.0.5"
69
78
  },
70
79
  dependencies: {
71
- "@ag-ui/client": "0.0.40-alpha.6",
72
- "@ag-ui/core": "0.0.40-alpha.6",
73
- "@ag-ui/encoder": "0.0.40-alpha.6",
80
+ "@ag-ui/client": "0.0.40-alpha.11",
81
+ "@ag-ui/core": "0.0.40-alpha.11",
82
+ "@ag-ui/encoder": "0.0.40-alpha.11",
74
83
  "@copilotkitnext/shared": "workspace:*",
84
+ cors: "^2.8.5",
85
+ express: "^4.21.2",
75
86
  hono: "^4.6.13",
76
87
  rxjs: "7.8.1"
77
88
  },
@@ -348,7 +359,7 @@ var CopilotRuntime = class {
348
359
  }
349
360
  };
350
361
 
351
- // src/endpoint.ts
362
+ // src/endpoints/hono.ts
352
363
  var import_hono = require("hono");
353
364
  var import_cors = require("hono/cors");
354
365
 
@@ -637,7 +648,7 @@ async function handleTranscribe({
637
648
  }
638
649
  }
639
650
 
640
- // src/endpoint.ts
651
+ // src/endpoints/hono.ts
641
652
  var import_shared3 = require("@copilotkitnext/shared");
642
653
 
643
654
  // src/middleware.ts
@@ -856,7 +867,7 @@ async function handleStopAgent({
856
867
  }
857
868
  }
858
869
 
859
- // src/endpoint.ts
870
+ // src/endpoints/hono.ts
860
871
  function createCopilotEndpoint({ runtime, basePath }) {
861
872
  const app = new import_hono.Hono();
862
873
  return app.basePath(basePath).use(
@@ -965,8 +976,210 @@ function createCopilotEndpoint({ runtime, basePath }) {
965
976
  });
966
977
  }
967
978
 
968
- // src/runner/index.ts
979
+ // src/endpoints/hono-single.ts
980
+ var import_hono2 = require("hono");
981
+ var import_cors2 = require("hono/cors");
969
982
  var import_shared4 = require("@copilotkitnext/shared");
983
+
984
+ // src/endpoints/single-route-helpers.ts
985
+ var METHOD_NAMES = [
986
+ "agent/run",
987
+ "agent/connect",
988
+ "agent/stop",
989
+ "info",
990
+ "transcribe"
991
+ ];
992
+ async function parseMethodCall(request) {
993
+ const contentType = request.headers.get("content-type") || "";
994
+ if (!contentType.includes("application/json")) {
995
+ throw createResponseError("Single-route endpoint expects JSON payloads", 415);
996
+ }
997
+ let jsonEnvelope;
998
+ try {
999
+ jsonEnvelope = await request.clone().json();
1000
+ } catch (error) {
1001
+ throw createResponseError("Invalid JSON payload", 400);
1002
+ }
1003
+ const method = validateMethod(jsonEnvelope.method);
1004
+ return {
1005
+ method,
1006
+ params: jsonEnvelope.params,
1007
+ body: jsonEnvelope.body
1008
+ };
1009
+ }
1010
+ function expectString(params, key) {
1011
+ const value = params?.[key];
1012
+ if (typeof value === "string" && value.trim().length > 0) {
1013
+ return value;
1014
+ }
1015
+ throw createResponseError(`Missing or invalid parameter '${key}'`, 400);
1016
+ }
1017
+ function createJsonRequest(base, body) {
1018
+ if (body === void 0 || body === null) {
1019
+ throw createResponseError("Missing request body for JSON handler", 400);
1020
+ }
1021
+ const headers = new Headers(base.headers);
1022
+ headers.set("content-type", "application/json");
1023
+ headers.delete("content-length");
1024
+ const serializedBody = serializeJsonBody(body);
1025
+ return new Request(base.url, {
1026
+ method: "POST",
1027
+ headers,
1028
+ body: serializedBody,
1029
+ signal: base.signal
1030
+ });
1031
+ }
1032
+ function createResponseError(message, status) {
1033
+ return new Response(
1034
+ JSON.stringify({
1035
+ error: "invalid_request",
1036
+ message
1037
+ }),
1038
+ {
1039
+ status,
1040
+ headers: {
1041
+ "Content-Type": "application/json"
1042
+ }
1043
+ }
1044
+ );
1045
+ }
1046
+ function validateMethod(method) {
1047
+ if (!method) {
1048
+ throw createResponseError("Missing method field", 400);
1049
+ }
1050
+ if (METHOD_NAMES.includes(method)) {
1051
+ return method;
1052
+ }
1053
+ throw createResponseError(`Unsupported method '${method}'`, 400);
1054
+ }
1055
+ function serializeJsonBody(body) {
1056
+ if (typeof body === "string") {
1057
+ return body;
1058
+ }
1059
+ if (body instanceof Blob || body instanceof ArrayBuffer || body instanceof Uint8Array) {
1060
+ return body;
1061
+ }
1062
+ if (body instanceof FormData || body instanceof URLSearchParams) {
1063
+ return body;
1064
+ }
1065
+ return JSON.stringify(body);
1066
+ }
1067
+
1068
+ // src/endpoints/hono-single.ts
1069
+ function createCopilotEndpointSingleRoute({ runtime, basePath }) {
1070
+ const app = new import_hono2.Hono();
1071
+ const routePath = normalizePath(basePath);
1072
+ return app.basePath(routePath).use(
1073
+ "*",
1074
+ (0, import_cors2.cors)({
1075
+ origin: "*",
1076
+ allowMethods: ["GET", "HEAD", "PUT", "POST", "DELETE", "PATCH", "OPTIONS"],
1077
+ allowHeaders: ["*"]
1078
+ })
1079
+ ).use("*", async (c, next) => {
1080
+ const request = c.req.raw;
1081
+ const path = c.req.path;
1082
+ try {
1083
+ const maybeModifiedRequest = await callBeforeRequestMiddleware({
1084
+ runtime,
1085
+ request,
1086
+ path
1087
+ });
1088
+ if (maybeModifiedRequest) {
1089
+ c.set("modifiedRequest", maybeModifiedRequest);
1090
+ }
1091
+ } catch (error) {
1092
+ import_shared4.logger.error({ err: error, url: request.url, path }, "Error running before request middleware");
1093
+ if (error instanceof Response) {
1094
+ return error;
1095
+ }
1096
+ throw error;
1097
+ }
1098
+ await next();
1099
+ }).use("*", async (c, next) => {
1100
+ await next();
1101
+ const response = c.res;
1102
+ const path = c.req.path;
1103
+ callAfterRequestMiddleware({
1104
+ runtime,
1105
+ response,
1106
+ path
1107
+ }).catch((error) => {
1108
+ import_shared4.logger.error({ err: error, url: c.req.url, path }, "Error running after request middleware");
1109
+ });
1110
+ }).post("/", async (c) => {
1111
+ const request = c.get("modifiedRequest") || c.req.raw;
1112
+ let methodCall;
1113
+ try {
1114
+ methodCall = await parseMethodCall(request);
1115
+ } catch (error) {
1116
+ if (error instanceof Response) {
1117
+ import_shared4.logger.warn({ url: request.url }, "Invalid single-route payload");
1118
+ return error;
1119
+ }
1120
+ import_shared4.logger.warn({ err: error, url: request.url }, "Invalid single-route payload");
1121
+ return c.json(
1122
+ {
1123
+ error: "invalid_request",
1124
+ message: error instanceof Error ? error.message : "Invalid request payload"
1125
+ },
1126
+ 400
1127
+ );
1128
+ }
1129
+ try {
1130
+ switch (methodCall.method) {
1131
+ case "agent/run": {
1132
+ const agentId = expectString(methodCall.params, "agentId");
1133
+ const handlerRequest = createJsonRequest(request, methodCall.body);
1134
+ return await handleRunAgent({ runtime, request: handlerRequest, agentId });
1135
+ }
1136
+ case "agent/connect": {
1137
+ const agentId = expectString(methodCall.params, "agentId");
1138
+ const handlerRequest = createJsonRequest(request, methodCall.body);
1139
+ return await handleConnectAgent({ runtime, request: handlerRequest, agentId });
1140
+ }
1141
+ case "agent/stop": {
1142
+ const agentId = expectString(methodCall.params, "agentId");
1143
+ const threadId = expectString(methodCall.params, "threadId");
1144
+ return await handleStopAgent({ runtime, request, agentId, threadId });
1145
+ }
1146
+ case "info": {
1147
+ return await handleGetRuntimeInfo({ runtime, request });
1148
+ }
1149
+ case "transcribe": {
1150
+ return await handleTranscribe({ runtime, request });
1151
+ }
1152
+ default: {
1153
+ const exhaustiveCheck = methodCall.method;
1154
+ return exhaustiveCheck;
1155
+ }
1156
+ }
1157
+ } catch (error) {
1158
+ if (error instanceof Response) {
1159
+ return error;
1160
+ }
1161
+ import_shared4.logger.error({ err: error, url: request.url, method: methodCall.method }, "Error running single-route handler");
1162
+ throw error;
1163
+ }
1164
+ }).notFound((c) => {
1165
+ return c.json({ error: "Not found" }, 404);
1166
+ });
1167
+ }
1168
+ function normalizePath(path) {
1169
+ if (!path) {
1170
+ throw new Error("basePath must be provided for single-route endpoint");
1171
+ }
1172
+ if (!path.startsWith("/")) {
1173
+ return `/${path}`;
1174
+ }
1175
+ if (path.length > 1 && path.endsWith("/")) {
1176
+ return path.slice(0, -1);
1177
+ }
1178
+ return path;
1179
+ }
1180
+
1181
+ // src/runner/index.ts
1182
+ var import_shared5 = require("@copilotkitnext/shared");
970
1183
  // Annotate the CommonJS export names for ESM import in node:
971
1184
  0 && (module.exports = {
972
1185
  AgentRunner,
@@ -974,6 +1187,7 @@ var import_shared4 = require("@copilotkitnext/shared");
974
1187
  InMemoryAgentRunner,
975
1188
  VERSION,
976
1189
  createCopilotEndpoint,
1190
+ createCopilotEndpointSingleRoute,
977
1191
  finalizeRunEvents
978
1192
  });
979
1193
  //# sourceMappingURL=index.js.map