@copilotkitnext/runtime 1.51.4 → 1.51.5-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.
Files changed (138) hide show
  1. package/dist/_virtual/_rolldown/runtime.cjs +29 -0
  2. package/dist/endpoints/express-single.cjs +187 -0
  3. package/dist/endpoints/express-single.cjs.map +1 -0
  4. package/dist/endpoints/express-single.d.cts +15 -0
  5. package/dist/endpoints/express-single.d.cts.map +1 -0
  6. package/dist/endpoints/express-single.d.mts +15 -0
  7. package/dist/endpoints/express-single.d.mts.map +1 -0
  8. package/dist/endpoints/express-single.mjs +184 -0
  9. package/dist/endpoints/express-single.mjs.map +1 -0
  10. package/dist/endpoints/express-utils.cjs +118 -0
  11. package/dist/endpoints/express-utils.cjs.map +1 -0
  12. package/dist/endpoints/express-utils.mjs +116 -0
  13. package/dist/endpoints/express-utils.mjs.map +1 -0
  14. package/dist/endpoints/express.cjs +165 -0
  15. package/dist/endpoints/express.cjs.map +1 -0
  16. package/dist/endpoints/express.d.cts +15 -0
  17. package/dist/endpoints/express.d.cts.map +1 -0
  18. package/dist/endpoints/express.d.mts +15 -0
  19. package/dist/endpoints/express.d.mts.map +1 -0
  20. package/dist/endpoints/express.mjs +162 -0
  21. package/dist/endpoints/express.mjs.map +1 -0
  22. package/dist/endpoints/hono-single.cjs +140 -0
  23. package/dist/endpoints/hono-single.cjs.map +1 -0
  24. package/dist/endpoints/hono-single.d.cts +31 -0
  25. package/dist/endpoints/hono-single.d.cts.map +1 -0
  26. package/dist/endpoints/hono-single.d.mts +31 -0
  27. package/dist/endpoints/hono-single.d.mts.map +1 -0
  28. package/dist/endpoints/hono-single.mjs +139 -0
  29. package/dist/endpoints/hono-single.mjs.map +1 -0
  30. package/dist/endpoints/hono.cjs +152 -0
  31. package/dist/endpoints/hono.cjs.map +1 -0
  32. package/dist/endpoints/hono.d.cts +47 -0
  33. package/dist/endpoints/hono.d.cts.map +1 -0
  34. package/dist/endpoints/hono.d.mts +47 -0
  35. package/dist/endpoints/hono.d.mts.map +1 -0
  36. package/dist/endpoints/hono.mjs +151 -0
  37. package/dist/endpoints/hono.mjs.map +1 -0
  38. package/dist/endpoints/index.cjs +2 -0
  39. package/dist/endpoints/index.d.mts +2 -0
  40. package/dist/endpoints/index.mjs +4 -0
  41. package/dist/endpoints/single-route-helpers.cjs +67 -0
  42. package/dist/endpoints/single-route-helpers.cjs.map +1 -0
  43. package/dist/endpoints/single-route-helpers.mjs +64 -0
  44. package/dist/endpoints/single-route-helpers.mjs.map +1 -0
  45. package/dist/express.cjs +6 -0
  46. package/dist/express.d.cts +3 -0
  47. package/dist/express.d.mts +3 -19
  48. package/dist/express.mjs +3 -477
  49. package/dist/handlers/get-runtime-info.cjs +36 -0
  50. package/dist/handlers/get-runtime-info.cjs.map +1 -0
  51. package/dist/handlers/get-runtime-info.mjs +36 -0
  52. package/dist/handlers/get-runtime-info.mjs.map +1 -0
  53. package/dist/handlers/handle-connect.cjs +102 -0
  54. package/dist/handlers/handle-connect.cjs.map +1 -0
  55. package/dist/handlers/handle-connect.mjs +101 -0
  56. package/dist/handlers/handle-connect.mjs.map +1 -0
  57. package/dist/handlers/handle-run.cjs +114 -0
  58. package/dist/handlers/handle-run.cjs.map +1 -0
  59. package/dist/handlers/handle-run.mjs +113 -0
  60. package/dist/handlers/handle-run.mjs.map +1 -0
  61. package/dist/handlers/handle-stop.cjs +46 -0
  62. package/dist/handlers/handle-stop.cjs.map +1 -0
  63. package/dist/handlers/handle-stop.mjs +45 -0
  64. package/dist/handlers/handle-stop.mjs.map +1 -0
  65. package/dist/handlers/handle-transcribe.cjs +111 -0
  66. package/dist/handlers/handle-transcribe.cjs.map +1 -0
  67. package/dist/handlers/handle-transcribe.mjs +110 -0
  68. package/dist/handlers/handle-transcribe.mjs.map +1 -0
  69. package/dist/handlers/header-utils.cjs +25 -0
  70. package/dist/handlers/header-utils.cjs.map +1 -0
  71. package/dist/handlers/header-utils.mjs +24 -0
  72. package/dist/handlers/header-utils.mjs.map +1 -0
  73. package/dist/index.cjs +25 -0
  74. package/dist/index.d.cts +8 -0
  75. package/dist/index.d.mts +9 -139
  76. package/dist/index.mjs +10 -335
  77. package/dist/middleware.cjs +29 -0
  78. package/dist/middleware.cjs.map +1 -0
  79. package/dist/middleware.d.cts +24 -0
  80. package/dist/middleware.d.cts.map +1 -0
  81. package/dist/middleware.d.mts +24 -0
  82. package/dist/middleware.d.mts.map +1 -0
  83. package/dist/middleware.mjs +27 -0
  84. package/dist/middleware.mjs.map +1 -0
  85. package/dist/package.cjs +12 -0
  86. package/dist/package.cjs.map +1 -0
  87. package/dist/package.mjs +6 -0
  88. package/dist/package.mjs.map +1 -0
  89. package/dist/runner/agent-runner.cjs +7 -0
  90. package/dist/runner/agent-runner.cjs.map +1 -0
  91. package/dist/runner/agent-runner.d.cts +28 -0
  92. package/dist/runner/agent-runner.d.cts.map +1 -0
  93. package/dist/runner/agent-runner.d.mts +28 -0
  94. package/dist/runner/agent-runner.d.mts.map +1 -0
  95. package/dist/runner/agent-runner.mjs +6 -0
  96. package/dist/runner/agent-runner.mjs.map +1 -0
  97. package/dist/runner/in-memory.cjs +230 -0
  98. package/dist/runner/in-memory.cjs.map +1 -0
  99. package/dist/runner/in-memory.d.cts +14 -0
  100. package/dist/runner/in-memory.d.cts.map +1 -0
  101. package/dist/runner/in-memory.d.mts +14 -0
  102. package/dist/runner/in-memory.d.mts.map +1 -0
  103. package/dist/runner/in-memory.mjs +229 -0
  104. package/dist/runner/in-memory.mjs.map +1 -0
  105. package/dist/runner/index.cjs +4 -0
  106. package/dist/runner/index.d.cts +4 -0
  107. package/dist/runner/index.d.mts +4 -0
  108. package/dist/runner/index.mjs +5 -0
  109. package/dist/runtime.cjs +27 -0
  110. package/dist/runtime.cjs.map +1 -0
  111. package/dist/runtime.d.cts +43 -0
  112. package/dist/runtime.d.cts.map +1 -0
  113. package/dist/runtime.d.mts +43 -0
  114. package/dist/runtime.d.mts.map +1 -0
  115. package/dist/runtime.mjs +26 -0
  116. package/dist/runtime.mjs.map +1 -0
  117. package/dist/transcription-service/transcription-service.cjs +7 -0
  118. package/dist/transcription-service/transcription-service.cjs.map +1 -0
  119. package/dist/transcription-service/transcription-service.d.cts +14 -0
  120. package/dist/transcription-service/transcription-service.d.cts.map +1 -0
  121. package/dist/transcription-service/transcription-service.d.mts +14 -0
  122. package/dist/transcription-service/transcription-service.d.mts.map +1 -0
  123. package/dist/transcription-service/transcription-service.mjs +6 -0
  124. package/dist/transcription-service/transcription-service.mjs.map +1 -0
  125. package/package.json +25 -22
  126. package/tsdown.config.ts +16 -0
  127. package/dist/chunk-5GKH3W25.mjs +0 -1054
  128. package/dist/chunk-5GKH3W25.mjs.map +0 -1
  129. package/dist/express.d.ts +0 -19
  130. package/dist/express.js +0 -1292
  131. package/dist/express.js.map +0 -1
  132. package/dist/express.mjs.map +0 -1
  133. package/dist/index.d.ts +0 -139
  134. package/dist/index.js +0 -1387
  135. package/dist/index.js.map +0 -1
  136. package/dist/index.mjs.map +0 -1
  137. package/dist/runtime-BsuyYT2l.d.mts +0 -98
  138. package/dist/runtime-BsuyYT2l.d.ts +0 -98
@@ -0,0 +1,101 @@
1
+ import { extractForwardableHeaders } from "./header-utils.mjs";
2
+ import { RunAgentInputSchema } from "@ag-ui/client";
3
+ import { EventEncoder } from "@ag-ui/encoder";
4
+
5
+ //#region src/handlers/handle-connect.ts
6
+ async function handleConnectAgent({ runtime, request, agentId }) {
7
+ try {
8
+ if (!(await runtime.agents)[agentId]) return new Response(JSON.stringify({
9
+ error: "Agent not found",
10
+ message: `Agent '${agentId}' does not exist`
11
+ }), {
12
+ status: 404,
13
+ headers: { "Content-Type": "application/json" }
14
+ });
15
+ let input;
16
+ try {
17
+ const requestBody = await request.json();
18
+ input = RunAgentInputSchema.parse(requestBody);
19
+ } catch (error) {
20
+ console.error("Invalid connect request body:", error);
21
+ return new Response(JSON.stringify({
22
+ error: "Invalid request body",
23
+ details: error instanceof Error ? error.message : String(error)
24
+ }), {
25
+ status: 400,
26
+ headers: { "Content-Type": "application/json" }
27
+ });
28
+ }
29
+ const stream = new TransformStream();
30
+ const writer = stream.writable.getWriter();
31
+ const encoder = new EventEncoder();
32
+ let streamClosed = false;
33
+ (async () => {
34
+ const forwardableHeaders = extractForwardableHeaders(request);
35
+ runtime.runner.connect({
36
+ threadId: input.threadId,
37
+ headers: forwardableHeaders
38
+ }).subscribe({
39
+ next: async (event) => {
40
+ if (!request.signal.aborted && !streamClosed) try {
41
+ await writer.write(encoder.encode(event));
42
+ } catch (error) {
43
+ if (error instanceof Error && error.name === "AbortError") streamClosed = true;
44
+ }
45
+ },
46
+ error: async (error) => {
47
+ console.error("Error running agent:", error);
48
+ if (!streamClosed) try {
49
+ await writer.close();
50
+ streamClosed = true;
51
+ } catch {}
52
+ },
53
+ complete: async () => {
54
+ if (!streamClosed) try {
55
+ await writer.close();
56
+ streamClosed = true;
57
+ } catch {}
58
+ }
59
+ });
60
+ })().catch((error) => {
61
+ console.error("Error running agent:", error);
62
+ console.error("Error stack:", error instanceof Error ? error.stack : "No stack trace");
63
+ console.error("Error details:", {
64
+ name: error instanceof Error ? error.name : "Unknown",
65
+ message: error instanceof Error ? error.message : String(error),
66
+ cause: error instanceof Error ? error.cause : void 0
67
+ });
68
+ if (!streamClosed) try {
69
+ writer.close();
70
+ streamClosed = true;
71
+ } catch {}
72
+ });
73
+ return new Response(stream.readable, {
74
+ status: 200,
75
+ headers: {
76
+ "Content-Type": "text/event-stream",
77
+ "Cache-Control": "no-cache",
78
+ Connection: "keep-alive"
79
+ }
80
+ });
81
+ } catch (error) {
82
+ console.error("Error running agent:", error);
83
+ console.error("Error stack:", error instanceof Error ? error.stack : "No stack trace");
84
+ console.error("Error details:", {
85
+ name: error instanceof Error ? error.name : "Unknown",
86
+ message: error instanceof Error ? error.message : String(error),
87
+ cause: error instanceof Error ? error.cause : void 0
88
+ });
89
+ return new Response(JSON.stringify({
90
+ error: "Failed to run agent",
91
+ message: error instanceof Error ? error.message : "Unknown error"
92
+ }), {
93
+ status: 500,
94
+ headers: { "Content-Type": "application/json" }
95
+ });
96
+ }
97
+ }
98
+
99
+ //#endregion
100
+ export { handleConnectAgent };
101
+ //# sourceMappingURL=handle-connect.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handle-connect.mjs","names":[],"sources":["../../src/handlers/handle-connect.ts"],"sourcesContent":["import { RunAgentInput, RunAgentInputSchema } from \"@ag-ui/client\";\nimport { EventEncoder } from \"@ag-ui/encoder\";\nimport { CopilotRuntime } from \"../runtime\";\nimport { extractForwardableHeaders } from \"./header-utils\";\n\ninterface ConnectAgentParameters {\n request: Request;\n runtime: CopilotRuntime;\n agentId: string;\n}\n\nexport async function handleConnectAgent({\n runtime,\n request,\n agentId,\n}: ConnectAgentParameters) {\n try {\n const agents = await runtime.agents;\n\n // Check if the requested agent exists\n if (!agents[agentId]) {\n return new Response(\n JSON.stringify({\n error: \"Agent not found\",\n message: `Agent '${agentId}' does not exist`,\n }),\n {\n status: 404,\n headers: { \"Content-Type\": \"application/json\" },\n },\n );\n }\n\n // Parse and validate input BEFORE creating the stream\n // so we can return a proper error response\n let input: RunAgentInput;\n try {\n const requestBody = await request.json();\n input = RunAgentInputSchema.parse(requestBody);\n } catch (error) {\n console.error(\"Invalid connect request body:\", error);\n return new Response(\n JSON.stringify({\n error: \"Invalid request body\",\n details: error instanceof Error ? error.message : String(error),\n }),\n {\n status: 400,\n headers: { \"Content-Type\": \"application/json\" },\n },\n );\n }\n\n const stream = new TransformStream();\n const writer = stream.writable.getWriter();\n const encoder = new EventEncoder();\n let streamClosed = false;\n\n // Process the agent connect in the background\n (async () => {\n const forwardableHeaders = extractForwardableHeaders(request);\n\n runtime.runner\n .connect({\n threadId: input.threadId,\n headers: forwardableHeaders,\n })\n .subscribe({\n next: async (event) => {\n if (!request.signal.aborted && !streamClosed) {\n try {\n await writer.write(encoder.encode(event));\n } catch (error) {\n if (error instanceof Error && error.name === \"AbortError\") {\n streamClosed = true;\n }\n }\n }\n },\n error: async (error) => {\n console.error(\"Error running agent:\", error);\n if (!streamClosed) {\n try {\n await writer.close();\n streamClosed = true;\n } catch {\n // Stream already closed\n }\n }\n },\n complete: async () => {\n if (!streamClosed) {\n try {\n await writer.close();\n streamClosed = true;\n } catch {\n // Stream already closed\n }\n }\n },\n });\n })().catch((error) => {\n console.error(\"Error running agent:\", error);\n console.error(\n \"Error stack:\",\n error instanceof Error ? error.stack : \"No stack trace\",\n );\n console.error(\"Error details:\", {\n name: error instanceof Error ? error.name : \"Unknown\",\n message: error instanceof Error ? error.message : String(error),\n cause: error instanceof Error ? error.cause : undefined,\n });\n if (!streamClosed) {\n try {\n writer.close();\n streamClosed = true;\n } catch {\n // Stream already closed\n }\n }\n });\n\n // Return the SSE response\n return new Response(stream.readable, {\n status: 200,\n headers: {\n \"Content-Type\": \"text/event-stream\",\n \"Cache-Control\": \"no-cache\",\n Connection: \"keep-alive\",\n },\n });\n } catch (error) {\n console.error(\"Error running agent:\", error);\n console.error(\n \"Error stack:\",\n error instanceof Error ? error.stack : \"No stack trace\",\n );\n console.error(\"Error details:\", {\n name: error instanceof Error ? error.name : \"Unknown\",\n message: error instanceof Error ? error.message : String(error),\n cause: error instanceof Error ? error.cause : undefined,\n });\n\n return new Response(\n JSON.stringify({\n error: \"Failed to run agent\",\n message: error instanceof Error ? error.message : \"Unknown error\",\n }),\n {\n status: 500,\n headers: { \"Content-Type\": \"application/json\" },\n },\n );\n }\n}\n"],"mappings":";;;;;AAWA,eAAsB,mBAAmB,EACvC,SACA,SACA,WACyB;AACzB,KAAI;AAIF,MAAI,EAHW,MAAM,QAAQ,QAGjB,SACV,QAAO,IAAI,SACT,KAAK,UAAU;GACb,OAAO;GACP,SAAS,UAAU,QAAQ;GAC5B,CAAC,EACF;GACE,QAAQ;GACR,SAAS,EAAE,gBAAgB,oBAAoB;GAChD,CACF;EAKH,IAAI;AACJ,MAAI;GACF,MAAM,cAAc,MAAM,QAAQ,MAAM;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AC,aACH,KAAI;AACF,WAAO,OAAO;AACd,mBAAe;WACT;IAIV;AAGF,SAAO,IAAI,SAAS,OAAO,UAAU;GACnC,QAAQ;GACR,SAAS;IACP,gBAAgB;IAChB,iBAAiB;IACjB,YAAY;IACb;GACF,CAAC;UACK,OAAO;AACd,UAAQ,MAAM,wBAAwB,MAAM;AAC5C,UAAQ,MACN,gBACA,iBAAiB,QAAQ,MAAM,QAAQ,iBACxC;AACD,UAAQ,MAAM,kBAAkB;GAC9B,MAAM,iBAAiB,QAAQ,MAAM,OAAO;GAC5C,SAAS,iBAAiB,QAAQ,MAAM,UAAU,OAAO,MAAM;GAC/D,OAAO,iBAAiB,QAAQ,MAAM,QAAQ;GAC/C,CAAC;AAEF,SAAO,IAAI,SACT,KAAK,UAAU;GACb,OAAO;GACP,SAAS,iBAAiB,QAAQ,MAAM,UAAU;GACnD,CAAC,EACF;GACE,QAAQ;GACR,SAAS,EAAE,gBAAgB,oBAAoB;GAChD,CACF"}
@@ -0,0 +1,114 @@
1
+ const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
2
+ const require_header_utils = require('./header-utils.cjs');
3
+ let _ag_ui_client = require("@ag-ui/client");
4
+ let _ag_ui_encoder = require("@ag-ui/encoder");
5
+
6
+ //#region src/handlers/handle-run.ts
7
+ async function handleRunAgent({ runtime, request, agentId }) {
8
+ try {
9
+ const agents = await runtime.agents;
10
+ if (!agents[agentId]) return new Response(JSON.stringify({
11
+ error: "Agent not found",
12
+ message: `Agent '${agentId}' does not exist`
13
+ }), {
14
+ status: 404,
15
+ headers: { "Content-Type": "application/json" }
16
+ });
17
+ const agent = agents[agentId].clone();
18
+ if (agent && "headers" in agent) {
19
+ const forwardableHeaders = require_header_utils.extractForwardableHeaders(request);
20
+ agent.headers = {
21
+ ...agent.headers,
22
+ ...forwardableHeaders
23
+ };
24
+ }
25
+ let input;
26
+ try {
27
+ const requestBody = await request.json();
28
+ input = _ag_ui_client.RunAgentInputSchema.parse(requestBody);
29
+ } catch (error) {
30
+ console.error("Invalid run request body:", error);
31
+ return new Response(JSON.stringify({
32
+ error: "Invalid request body",
33
+ details: error instanceof Error ? error.message : String(error)
34
+ }), {
35
+ status: 400,
36
+ headers: { "Content-Type": "application/json" }
37
+ });
38
+ }
39
+ const stream = new TransformStream();
40
+ const writer = stream.writable.getWriter();
41
+ const encoder = new _ag_ui_encoder.EventEncoder();
42
+ let streamClosed = false;
43
+ agent.setMessages(input.messages);
44
+ agent.setState(input.state);
45
+ agent.threadId = input.threadId;
46
+ (async () => {
47
+ runtime.runner.run({
48
+ threadId: input.threadId,
49
+ agent,
50
+ input
51
+ }).subscribe({
52
+ next: async (event) => {
53
+ if (!request.signal.aborted && !streamClosed) try {
54
+ await writer.write(encoder.encode(event));
55
+ } catch (error) {
56
+ if (error instanceof Error && error.name === "AbortError") streamClosed = true;
57
+ }
58
+ },
59
+ error: async (error) => {
60
+ console.error("Error running agent:", error);
61
+ if (!streamClosed) try {
62
+ await writer.close();
63
+ streamClosed = true;
64
+ } catch {}
65
+ },
66
+ complete: async () => {
67
+ if (!streamClosed) try {
68
+ await writer.close();
69
+ streamClosed = true;
70
+ } catch {}
71
+ }
72
+ });
73
+ })().catch((error) => {
74
+ console.error("Error running agent:", error);
75
+ console.error("Error stack:", error instanceof Error ? error.stack : "No stack trace");
76
+ console.error("Error details:", {
77
+ name: error instanceof Error ? error.name : "Unknown",
78
+ message: error instanceof Error ? error.message : String(error),
79
+ cause: error instanceof Error ? error.cause : void 0
80
+ });
81
+ if (!streamClosed) try {
82
+ writer.close();
83
+ streamClosed = true;
84
+ } catch {}
85
+ });
86
+ return new Response(stream.readable, {
87
+ status: 200,
88
+ headers: {
89
+ "Content-Type": "text/event-stream",
90
+ "Cache-Control": "no-cache",
91
+ Connection: "keep-alive"
92
+ }
93
+ });
94
+ } catch (error) {
95
+ console.error("Error running agent:", error);
96
+ console.error("Error stack:", error instanceof Error ? error.stack : "No stack trace");
97
+ console.error("Error details:", {
98
+ name: error instanceof Error ? error.name : "Unknown",
99
+ message: error instanceof Error ? error.message : String(error),
100
+ cause: error instanceof Error ? error.cause : void 0
101
+ });
102
+ return new Response(JSON.stringify({
103
+ error: "Failed to run agent",
104
+ message: error instanceof Error ? error.message : "Unknown error"
105
+ }), {
106
+ status: 500,
107
+ headers: { "Content-Type": "application/json" }
108
+ });
109
+ }
110
+ }
111
+
112
+ //#endregion
113
+ exports.handleRunAgent = handleRunAgent;
114
+ //# sourceMappingURL=handle-run.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handle-run.cjs","names":["extractForwardableHeaders","RunAgentInputSchema","EventEncoder"],"sources":["../../src/handlers/handle-run.ts"],"sourcesContent":["import {\n AbstractAgent,\n RunAgentInput,\n RunAgentInputSchema,\n} from \"@ag-ui/client\";\nimport { EventEncoder } from \"@ag-ui/encoder\";\nimport { CopilotRuntime } from \"../runtime\";\nimport { extractForwardableHeaders } from \"./header-utils\";\n\ninterface RunAgentParameters {\n request: Request;\n runtime: CopilotRuntime;\n agentId: string;\n}\n\nexport async function handleRunAgent({\n runtime,\n request,\n agentId,\n}: RunAgentParameters) {\n try {\n const agents = await runtime.agents;\n\n // Check if the requested agent exists\n if (!agents[agentId]) {\n return new Response(\n JSON.stringify({\n error: \"Agent not found\",\n message: `Agent '${agentId}' does not exist`,\n }),\n {\n status: 404,\n headers: { \"Content-Type\": \"application/json\" },\n },\n );\n }\n\n const registeredAgent = agents[agentId] as AbstractAgent;\n const agent = registeredAgent.clone() as AbstractAgent;\n\n if (agent && \"headers\" in agent) {\n const forwardableHeaders = extractForwardableHeaders(request);\n agent.headers = {\n ...(agent.headers as Record<string, string>),\n ...forwardableHeaders,\n };\n }\n\n // Parse and validate input BEFORE creating the stream\n // so we can return a proper error response\n let input: RunAgentInput;\n try {\n const requestBody = await request.json();\n input = RunAgentInputSchema.parse(requestBody);\n } catch (error) {\n console.error(\"Invalid run request body:\", error);\n return new Response(\n JSON.stringify({\n error: \"Invalid request body\",\n details: error instanceof Error ? error.message : String(error),\n }),\n {\n status: 400,\n headers: { \"Content-Type\": \"application/json\" },\n },\n );\n }\n\n const stream = new TransformStream();\n const writer = stream.writable.getWriter();\n const encoder = new EventEncoder();\n let streamClosed = false;\n\n agent.setMessages(input.messages);\n agent.setState(input.state);\n agent.threadId = input.threadId;\n\n // Process the agent run in the background\n (async () => {\n runtime.runner\n .run({\n threadId: input.threadId,\n agent,\n input,\n })\n .subscribe({\n next: async (event) => {\n if (!request.signal.aborted && !streamClosed) {\n try {\n await writer.write(encoder.encode(event));\n } catch (error) {\n if (error instanceof Error && error.name === \"AbortError\") {\n streamClosed = true;\n }\n }\n }\n },\n error: async (error) => {\n console.error(\"Error running agent:\", error);\n if (!streamClosed) {\n try {\n await writer.close();\n streamClosed = true;\n } catch {\n // Stream already closed\n }\n }\n },\n complete: async () => {\n if (!streamClosed) {\n try {\n await writer.close();\n streamClosed = true;\n } catch {\n // Stream already closed\n }\n }\n },\n });\n })().catch((error) => {\n console.error(\"Error running agent:\", error);\n console.error(\n \"Error stack:\",\n error instanceof Error ? error.stack : \"No stack trace\",\n );\n console.error(\"Error details:\", {\n name: error instanceof Error ? error.name : \"Unknown\",\n message: error instanceof Error ? error.message : String(error),\n cause: error instanceof Error ? error.cause : undefined,\n });\n if (!streamClosed) {\n try {\n writer.close();\n streamClosed = true;\n } catch {\n // Stream already closed\n }\n }\n });\n\n // Return the SSE response\n return new Response(stream.readable, {\n status: 200,\n headers: {\n \"Content-Type\": \"text/event-stream\",\n \"Cache-Control\": \"no-cache\",\n Connection: \"keep-alive\",\n },\n });\n } catch (error) {\n console.error(\"Error running agent:\", error);\n console.error(\n \"Error stack:\",\n error instanceof Error ? error.stack : \"No stack trace\",\n );\n console.error(\"Error details:\", {\n name: error instanceof Error ? error.name : \"Unknown\",\n message: error instanceof Error ? error.message : String(error),\n cause: error instanceof Error ? error.cause : undefined,\n });\n\n return new Response(\n JSON.stringify({\n error: \"Failed to run agent\",\n message: error instanceof Error ? error.message : \"Unknown error\",\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ractForwardableHeaders } from "./header-utils.mjs";
2
+ import { RunAgentInputSchema } from "@ag-ui/client";
3
+ import { EventEncoder } from "@ag-ui/encoder";
4
+
5
+ //#region src/handlers/handle-run.ts
6
+ async function handleRunAgent({ runtime, request, agentId }) {
7
+ try {
8
+ const agents = await runtime.agents;
9
+ if (!agents[agentId]) return new Response(JSON.stringify({
10
+ error: "Agent not found",
11
+ message: `Agent '${agentId}' does not exist`
12
+ }), {
13
+ status: 404,
14
+ headers: { "Content-Type": "application/json" }
15
+ });
16
+ const agent = agents[agentId].clone();
17
+ if (agent && "headers" in agent) {
18
+ const forwardableHeaders = extractForwardableHeaders(request);
19
+ agent.headers = {
20
+ ...agent.headers,
21
+ ...forwardableHeaders
22
+ };
23
+ }
24
+ let input;
25
+ try {
26
+ const requestBody = await request.json();
27
+ input = RunAgentInputSchema.parse(requestBody);
28
+ } catch (error) {
29
+ console.error("Invalid run request body:", error);
30
+ return new Response(JSON.stringify({
31
+ error: "Invalid request body",
32
+ details: error instanceof Error ? error.message : String(error)
33
+ }), {
34
+ status: 400,
35
+ headers: { "Content-Type": "application/json" }
36
+ });
37
+ }
38
+ const stream = new TransformStream();
39
+ const writer = stream.writable.getWriter();
40
+ const encoder = new EventEncoder();
41
+ let streamClosed = false;
42
+ agent.setMessages(input.messages);
43
+ agent.setState(input.state);
44
+ agent.threadId = input.threadId;
45
+ (async () => {
46
+ runtime.runner.run({
47
+ threadId: input.threadId,
48
+ agent,
49
+ input
50
+ }).subscribe({
51
+ next: async (event) => {
52
+ if (!request.signal.aborted && !streamClosed) try {
53
+ await writer.write(encoder.encode(event));
54
+ } catch (error) {
55
+ if (error instanceof Error && error.name === "AbortError") streamClosed = true;
56
+ }
57
+ },
58
+ error: async (error) => {
59
+ console.error("Error running agent:", error);
60
+ if (!streamClosed) try {
61
+ await writer.close();
62
+ streamClosed = true;
63
+ } catch {}
64
+ },
65
+ complete: async () => {
66
+ if (!streamClosed) try {
67
+ await writer.close();
68
+ streamClosed = true;
69
+ } catch {}
70
+ }
71
+ });
72
+ })().catch((error) => {
73
+ console.error("Error running agent:", error);
74
+ console.error("Error stack:", error instanceof Error ? error.stack : "No stack trace");
75
+ console.error("Error details:", {
76
+ name: error instanceof Error ? error.name : "Unknown",
77
+ message: error instanceof Error ? error.message : String(error),
78
+ cause: error instanceof Error ? error.cause : void 0
79
+ });
80
+ if (!streamClosed) try {
81
+ writer.close();
82
+ streamClosed = true;
83
+ } catch {}
84
+ });
85
+ return new Response(stream.readable, {
86
+ status: 200,
87
+ headers: {
88
+ "Content-Type": "text/event-stream",
89
+ "Cache-Control": "no-cache",
90
+ Connection: "keep-alive"
91
+ }
92
+ });
93
+ } catch (error) {
94
+ console.error("Error running agent:", error);
95
+ console.error("Error stack:", error instanceof Error ? error.stack : "No stack trace");
96
+ console.error("Error details:", {
97
+ name: error instanceof Error ? error.name : "Unknown",
98
+ message: error instanceof Error ? error.message : String(error),
99
+ cause: error instanceof Error ? error.cause : void 0
100
+ });
101
+ return new Response(JSON.stringify({
102
+ error: "Failed to run agent",
103
+ message: error instanceof Error ? error.message : "Unknown error"
104
+ }), {
105
+ status: 500,
106
+ headers: { "Content-Type": "application/json" }
107
+ });
108
+ }
109
+ }
110
+
111
+ //#endregion
112
+ export { handleRunAgent };
113
+ //# sourceMappingURL=handle-run.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handle-run.mjs","names":[],"sources":["../../src/handlers/handle-run.ts"],"sourcesContent":["import {\n AbstractAgent,\n RunAgentInput,\n RunAgentInputSchema,\n} from \"@ag-ui/client\";\nimport { EventEncoder } from \"@ag-ui/encoder\";\nimport { CopilotRuntime } from \"../runtime\";\nimport { extractForwardableHeaders } from \"./header-utils\";\n\ninterface RunAgentParameters {\n request: Request;\n runtime: CopilotRuntime;\n agentId: string;\n}\n\nexport async function handleRunAgent({\n runtime,\n request,\n agentId,\n}: RunAgentParameters) {\n try {\n const agents = await runtime.agents;\n\n // Check if the requested agent exists\n if (!agents[agentId]) {\n return new Response(\n JSON.stringify({\n error: \"Agent not found\",\n message: `Agent '${agentId}' does not exist`,\n }),\n {\n status: 404,\n headers: { \"Content-Type\": \"application/json\" },\n },\n );\n }\n\n const registeredAgent = agents[agentId] as AbstractAgent;\n const agent = registeredAgent.clone() as AbstractAgent;\n\n if (agent && \"headers\" in agent) {\n const forwardableHeaders = extractForwardableHeaders(request);\n agent.headers = {\n ...(agent.headers as Record<string, string>),\n ...forwardableHeaders,\n };\n }\n\n // Parse and validate input BEFORE creating the stream\n // so we can return a proper error response\n let input: RunAgentInput;\n try {\n const requestBody = await request.json();\n input = RunAgentInputSchema.parse(requestBody);\n } catch (error) {\n console.error(\"Invalid run request body:\", error);\n return new Response(\n JSON.stringify({\n error: \"Invalid request body\",\n details: error instanceof Error ? error.message : String(error),\n }),\n {\n status: 400,\n headers: { \"Content-Type\": \"application/json\" },\n },\n );\n }\n\n const stream = new TransformStream();\n const writer = stream.writable.getWriter();\n const encoder = new EventEncoder();\n let streamClosed = false;\n\n agent.setMessages(input.messages);\n agent.setState(input.state);\n agent.threadId = input.threadId;\n\n // Process the agent run in the background\n (async () => {\n runtime.runner\n .run({\n threadId: input.threadId,\n agent,\n input,\n })\n .subscribe({\n next: async (event) => {\n if (!request.signal.aborted && !streamClosed) {\n try {\n await writer.write(encoder.encode(event));\n } catch (error) {\n if (error instanceof Error && error.name === \"AbortError\") {\n streamClosed = true;\n }\n }\n }\n },\n error: async (error) => {\n console.error(\"Error running agent:\", error);\n if (!streamClosed) {\n try {\n await writer.close();\n streamClosed = true;\n } catch {\n // Stream already closed\n }\n }\n },\n complete: async () => {\n if (!streamClosed) {\n try {\n await writer.close();\n streamClosed = true;\n } catch {\n // Stream already closed\n }\n }\n },\n });\n })().catch((error) => {\n console.error(\"Error running agent:\", error);\n console.error(\n \"Error stack:\",\n error instanceof Error ? error.stack : \"No stack trace\",\n );\n console.error(\"Error details:\", {\n name: error instanceof Error ? error.name : \"Unknown\",\n message: error instanceof Error ? error.message : String(error),\n cause: error instanceof Error ? error.cause : undefined,\n });\n if (!streamClosed) {\n try {\n writer.close();\n streamClosed = true;\n } catch {\n // Stream already closed\n }\n }\n });\n\n // Return the SSE response\n return new Response(stream.readable, {\n status: 200,\n headers: {\n \"Content-Type\": \"text/event-stream\",\n \"Cache-Control\": \"no-cache\",\n Connection: \"keep-alive\",\n },\n });\n } catch (error) {\n console.error(\"Error running agent:\", error);\n console.error(\n \"Error stack:\",\n error instanceof Error ? error.stack : \"No stack trace\",\n );\n console.error(\"Error details:\", {\n name: error instanceof Error ? error.name : \"Unknown\",\n message: error instanceof Error ? error.message : String(error),\n cause: error instanceof Error ? error.cause : undefined,\n });\n\n return new Response(\n JSON.stringify({\n error: \"Failed to run agent\",\n message: error instanceof Error ? error.message : \"Unknown error\",\n }),\n {\n status: 500,\n headers: { \"Content-Type\": \"application/json\" },\n },\n );\n }\n}\n"],"mappings":";;;;;AAeA,eAAsB,eAAe,EACnC,SACA,SACA,WACqB;AACrB,KAAI;EACF,MAAM,SAAS,MAAM,QAAQ;AAG7B,MAAI,CAAC,OAAO,SACV,QAAO,IAAI,SACT,KAAK,UAAU;GACb,OAAO;GACP,SAAS,UAAU,QAAQ;GAC5B,CAAC,EACF;GACE,QAAQ;GACR,SAAS,EAAE,gBAAgB,oBAAoB;GAChD,CACF;EAIH,MAAM,QADkB,OAAO,SACD,OAAO;AAErC,MAAI,SAAS,aAAa,OAAO;GAC/B,MAAM,qBAAqB,0BAA0B,QAAQ;AAC7D,SAAM,UAAU;IACd,GAAI,MAAM;IACV,GAAG;IACJ;;EAKH,IAAI;AACJ,MAAI;GACF,MAAM,cAAc,MAAM,QAAQ,MAAM;AACxC,WAAQ,oBAAoB,MAAM,YAAY;WACvC,OAAO;AACd,WAAQ,MAAM,6BAA6B,MAAM;AACjD,UAAO,IAAI,SACT,KAAK,UAAU;IACb,OAAO;IACP,SAAS,iBAAiB,QAAQ,MAAM,UAAU,OAAO,MAAM;IAChE,CAAC,EACF;IACE,QAAQ;IACR,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F,CAAC;UACK,OAAO;AACd,UAAQ,MAAM,wBAAwB,MAAM;AAC5C,UAAQ,MACN,gBACA,iBAAiB,QAAQ,MAAM,QAAQ,iBACxC;AACD,UAAQ,MAAM,kBAAkB;GAC9B,MAAM,iBAAiB,QAAQ,MAAM,OAAO;GAC5C,SAAS,iBAAiB,QAAQ,MAAM,UAAU,OAAO,MAAM;GAC/D,OAAO,iBAAiB,QAAQ,MAAM,QAAQ;GAC/C,CAAC;AAEF,SAAO,IAAI,SACT,KAAK,UAAU;GACb,OAAO;GACP,SAAS,iBAAiB,QAAQ,MAAM,UAAU;GACnD,CAAC,EACF;GACE,QAAQ;GACR,SAAS,EAAE,gBAAgB,oBAAoB;GAChD,CACF"}
@@ -0,0 +1,46 @@
1
+ const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
2
+ let _ag_ui_client = require("@ag-ui/client");
3
+
4
+ //#region src/handlers/handle-stop.ts
5
+ async function handleStopAgent({ runtime, request, agentId, threadId }) {
6
+ try {
7
+ if (!(await runtime.agents)[agentId]) return new Response(JSON.stringify({
8
+ error: "Agent not found",
9
+ message: `Agent '${agentId}' does not exist`
10
+ }), {
11
+ status: 404,
12
+ headers: { "Content-Type": "application/json" }
13
+ });
14
+ if (!await runtime.runner.stop({ threadId })) return new Response(JSON.stringify({
15
+ stopped: false,
16
+ message: `No active run for thread '${threadId}'.`
17
+ }), {
18
+ status: 200,
19
+ headers: { "Content-Type": "application/json" }
20
+ });
21
+ return new Response(JSON.stringify({
22
+ stopped: true,
23
+ interrupt: {
24
+ type: _ag_ui_client.EventType.RUN_ERROR,
25
+ message: "Run stopped by user",
26
+ code: "STOPPED"
27
+ }
28
+ }), {
29
+ status: 200,
30
+ headers: { "Content-Type": "application/json" }
31
+ });
32
+ } catch (error) {
33
+ console.error("Error stopping agent run:", error);
34
+ return new Response(JSON.stringify({
35
+ error: "Failed to stop agent",
36
+ message: error instanceof Error ? error.message : "Unknown error"
37
+ }), {
38
+ status: 500,
39
+ headers: { "Content-Type": "application/json" }
40
+ });
41
+ }
42
+ }
43
+
44
+ //#endregion
45
+ exports.handleStopAgent = handleStopAgent;
46
+ //# sourceMappingURL=handle-stop.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handle-stop.cjs","names":["EventType"],"sources":["../../src/handlers/handle-stop.ts"],"sourcesContent":["import { CopilotRuntime } from \"../runtime\";\nimport { EventType } from \"@ag-ui/client\";\n\ninterface StopAgentParameters {\n request: Request;\n runtime: CopilotRuntime;\n agentId: string;\n threadId: string;\n}\n\nexport async function handleStopAgent({\n runtime,\n request,\n agentId,\n threadId,\n}: StopAgentParameters) {\n try {\n const agents = await runtime.agents;\n\n if (!agents[agentId]) {\n return new Response(\n JSON.stringify({\n error: \"Agent not found\",\n message: `Agent '${agentId}' does not exist`,\n }),\n {\n status: 404,\n headers: { \"Content-Type\": \"application/json\" },\n },\n );\n }\n\n const stopped = await runtime.runner.stop({ threadId });\n\n if (!stopped) {\n return new Response(\n JSON.stringify({\n stopped: false,\n message: `No active run for thread '${threadId}'.`,\n }),\n {\n status: 200,\n headers: { \"Content-Type\": \"application/json\" },\n },\n );\n }\n\n return new Response(\n JSON.stringify({\n stopped: true,\n interrupt: {\n type: EventType.RUN_ERROR,\n message: \"Run stopped by user\",\n code: \"STOPPED\",\n },\n }),\n {\n status: 200,\n headers: { \"Content-Type\": \"application/json\" },\n },\n );\n } catch (error) {\n console.error(\"Error stopping agent run:\", error);\n\n return new Response(\n JSON.stringify({\n error: \"Failed to stop agent\",\n message: error instanceof Error ? error.message : \"Unknown error\",\n }),\n {\n status: 500,\n headers: { \"Content-Type\": \"application/json\" },\n },\n );\n }\n}\n"],"mappings":";;;;AAUA,eAAsB,gBAAgB,EACpC,SACA,SACA,SACA,YACsB;AACtB,KAAI;AAGF,MAAI,EAFW,MAAM,QAAQ,QAEjB,SACV,QAAO,IAAI,SACT,KAAK,UAAU;GACb,OAAO;GACP,SAAS,UAAU,QAAQ;GAC5B,CAAC,EACF;GACE,QAAQ;GACR,SAAS,EAAE,gBAAgB,oBAAoB;GAChD,CACF;AAKH,MAAI,CAFY,MAAM,QAAQ,OAAO,KAAK,EAAE,UAAU,CAAC,CAGrD,QAAO,IAAI,SACT,KAAK,UAAU;GACb,SAAS;GACT,SAAS,6BAA6B,SAAS;GAChD,CAAC,EACF;GACE,QAAQ;GACR,SAAS,EAAE,gBAAgB,oBAAoB;GAChD,CACF;AAGH,SAAO,IAAI,SACT,KAAK,UAAU;GACb,SAAS;GACT,WAAW;IACT,MAAMA,wBAAU;IAChB,SAAS;IACT,MAAM;IACP;GACF,CAAC,EACF;GACE,QAAQ;GACR,SAAS,EAAE,gBAAgB,oBAAoB;GAChD,CACF;UACM,OAAO;AACd,UAAQ,MAAM,6BAA6B,MAAM;AAEjD,SAAO,IAAI,SACT,KAAK,UAAU;GACb,OAAO;GACP,SAAS,iBAAiB,QAAQ,MAAM,UAAU;GACnD,CAAC,EACF;GACE,QAAQ;GACR,SAAS,EAAE,gBAAgB,oBAAoB;GAChD,CACF"}
@@ -0,0 +1,45 @@
1
+ import { EventType } from "@ag-ui/client";
2
+
3
+ //#region src/handlers/handle-stop.ts
4
+ async function handleStopAgent({ runtime, request, agentId, threadId }) {
5
+ try {
6
+ if (!(await runtime.agents)[agentId]) return new Response(JSON.stringify({
7
+ error: "Agent not found",
8
+ message: `Agent '${agentId}' does not exist`
9
+ }), {
10
+ status: 404,
11
+ headers: { "Content-Type": "application/json" }
12
+ });
13
+ if (!await runtime.runner.stop({ threadId })) return new Response(JSON.stringify({
14
+ stopped: false,
15
+ message: `No active run for thread '${threadId}'.`
16
+ }), {
17
+ status: 200,
18
+ headers: { "Content-Type": "application/json" }
19
+ });
20
+ return new Response(JSON.stringify({
21
+ stopped: true,
22
+ interrupt: {
23
+ type: EventType.RUN_ERROR,
24
+ message: "Run stopped by user",
25
+ code: "STOPPED"
26
+ }
27
+ }), {
28
+ status: 200,
29
+ headers: { "Content-Type": "application/json" }
30
+ });
31
+ } catch (error) {
32
+ console.error("Error stopping agent run:", error);
33
+ return new Response(JSON.stringify({
34
+ error: "Failed to stop agent",
35
+ message: error instanceof Error ? error.message : "Unknown error"
36
+ }), {
37
+ status: 500,
38
+ headers: { "Content-Type": "application/json" }
39
+ });
40
+ }
41
+ }
42
+
43
+ //#endregion
44
+ export { handleStopAgent };
45
+ //# sourceMappingURL=handle-stop.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handle-stop.mjs","names":[],"sources":["../../src/handlers/handle-stop.ts"],"sourcesContent":["import { CopilotRuntime } from \"../runtime\";\nimport { EventType } from \"@ag-ui/client\";\n\ninterface StopAgentParameters {\n request: Request;\n runtime: CopilotRuntime;\n agentId: string;\n threadId: string;\n}\n\nexport async function handleStopAgent({\n runtime,\n request,\n agentId,\n threadId,\n}: StopAgentParameters) {\n try {\n const agents = await runtime.agents;\n\n if (!agents[agentId]) {\n return new Response(\n JSON.stringify({\n error: \"Agent not found\",\n message: `Agent '${agentId}' does not exist`,\n }),\n {\n status: 404,\n headers: { \"Content-Type\": \"application/json\" },\n },\n );\n }\n\n const stopped = await runtime.runner.stop({ threadId });\n\n if (!stopped) {\n return new Response(\n JSON.stringify({\n stopped: false,\n message: `No active run for thread '${threadId}'.`,\n }),\n {\n status: 200,\n headers: { \"Content-Type\": \"application/json\" },\n },\n );\n }\n\n return new Response(\n JSON.stringify({\n stopped: true,\n interrupt: {\n type: EventType.RUN_ERROR,\n message: \"Run stopped by user\",\n code: \"STOPPED\",\n },\n }),\n {\n status: 200,\n headers: { \"Content-Type\": \"application/json\" },\n },\n );\n } catch (error) {\n console.error(\"Error stopping agent run:\", error);\n\n return new Response(\n JSON.stringify({\n error: \"Failed to stop agent\",\n message: error instanceof Error ? error.message : \"Unknown error\",\n }),\n {\n status: 500,\n headers: { \"Content-Type\": \"application/json\" },\n },\n );\n }\n}\n"],"mappings":";;;AAUA,eAAsB,gBAAgB,EACpC,SACA,SACA,SACA,YACsB;AACtB,KAAI;AAGF,MAAI,EAFW,MAAM,QAAQ,QAEjB,SACV,QAAO,IAAI,SACT,KAAK,UAAU;GACb,OAAO;GACP,SAAS,UAAU,QAAQ;GAC5B,CAAC,EACF;GACE,QAAQ;GACR,SAAS,EAAE,gBAAgB,oBAAoB;GAChD,CACF;AAKH,MAAI,CAFY,MAAM,QAAQ,OAAO,KAAK,EAAE,UAAU,CAAC,CAGrD,QAAO,IAAI,SACT,KAAK,UAAU;GACb,SAAS;GACT,SAAS,6BAA6B,SAAS;GAChD,CAAC,EACF;GACE,QAAQ;GACR,SAAS,EAAE,gBAAgB,oBAAoB;GAChD,CACF;AAGH,SAAO,IAAI,SACT,KAAK,UAAU;GACb,SAAS;GACT,WAAW;IACT,MAAM,UAAU;IAChB,SAAS;IACT,MAAM;IACP;GACF,CAAC,EACF;GACE,QAAQ;GACR,SAAS,EAAE,gBAAgB,oBAAoB;GAChD,CACF;UACM,OAAO;AACd,UAAQ,MAAM,6BAA6B,MAAM;AAEjD,SAAO,IAAI,SACT,KAAK,UAAU;GACb,OAAO;GACP,SAAS,iBAAiB,QAAQ,MAAM,UAAU;GACnD,CAAC,EACF;GACE,QAAQ;GACR,SAAS,EAAE,gBAAgB,oBAAoB;GAChD,CACF"}
@@ -0,0 +1,111 @@
1
+ const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
2
+ let _copilotkitnext_shared = require("@copilotkitnext/shared");
3
+
4
+ //#region src/handlers/handle-transcribe.ts
5
+ /**
6
+ * HTTP status codes for transcription error codes
7
+ */
8
+ const ERROR_STATUS_CODES = {
9
+ [_copilotkitnext_shared.TranscriptionErrorCode.SERVICE_NOT_CONFIGURED]: 503,
10
+ [_copilotkitnext_shared.TranscriptionErrorCode.INVALID_AUDIO_FORMAT]: 400,
11
+ [_copilotkitnext_shared.TranscriptionErrorCode.AUDIO_TOO_LONG]: 400,
12
+ [_copilotkitnext_shared.TranscriptionErrorCode.AUDIO_TOO_SHORT]: 400,
13
+ [_copilotkitnext_shared.TranscriptionErrorCode.RATE_LIMITED]: 429,
14
+ [_copilotkitnext_shared.TranscriptionErrorCode.AUTH_FAILED]: 401,
15
+ [_copilotkitnext_shared.TranscriptionErrorCode.PROVIDER_ERROR]: 500,
16
+ [_copilotkitnext_shared.TranscriptionErrorCode.NETWORK_ERROR]: 502,
17
+ [_copilotkitnext_shared.TranscriptionErrorCode.INVALID_REQUEST]: 400
18
+ };
19
+ const VALID_AUDIO_TYPES = [
20
+ "audio/mpeg",
21
+ "audio/mp3",
22
+ "audio/mp4",
23
+ "audio/wav",
24
+ "audio/webm",
25
+ "audio/ogg",
26
+ "audio/flac",
27
+ "audio/aac"
28
+ ];
29
+ function isValidAudioType(type) {
30
+ const baseType = type.split(";")[0]?.trim() ?? "";
31
+ return VALID_AUDIO_TYPES.includes(baseType) || baseType === "" || baseType === "application/octet-stream";
32
+ }
33
+ function createErrorResponse(errorResponse) {
34
+ const status = ERROR_STATUS_CODES[errorResponse.error] ?? 500;
35
+ return new Response(JSON.stringify(errorResponse), {
36
+ status,
37
+ headers: { "Content-Type": "application/json" }
38
+ });
39
+ }
40
+ function base64ToFile(base64, mimeType, filename) {
41
+ const base64Data = base64.includes(",") ? base64.split(",")[1] ?? base64 : base64;
42
+ const binaryString = atob(base64Data);
43
+ const bytes = new Uint8Array(binaryString.length);
44
+ for (let i = 0; i < binaryString.length; i++) bytes[i] = binaryString.charCodeAt(i);
45
+ return new File([bytes], filename, { type: mimeType });
46
+ }
47
+ async function extractAudioFromFormData(request) {
48
+ const audioFile = (await request.formData()).get("audio");
49
+ if (!audioFile || !(audioFile instanceof File)) return { error: createErrorResponse(_copilotkitnext_shared.TranscriptionErrors.invalidRequest("No audio file found in form data. Please include an 'audio' field.")) };
50
+ if (!isValidAudioType(audioFile.type)) return { error: createErrorResponse(_copilotkitnext_shared.TranscriptionErrors.invalidAudioFormat(audioFile.type, VALID_AUDIO_TYPES)) };
51
+ return { file: audioFile };
52
+ }
53
+ async function extractAudioFromJson(request) {
54
+ let body;
55
+ try {
56
+ body = await request.json();
57
+ } catch {
58
+ return { error: createErrorResponse(_copilotkitnext_shared.TranscriptionErrors.invalidRequest("Request body must be valid JSON")) };
59
+ }
60
+ if (!body.audio || typeof body.audio !== "string") return { error: createErrorResponse(_copilotkitnext_shared.TranscriptionErrors.invalidRequest("Request must include 'audio' field with base64-encoded audio data")) };
61
+ if (!body.mimeType || typeof body.mimeType !== "string") return { error: createErrorResponse(_copilotkitnext_shared.TranscriptionErrors.invalidRequest("Request must include 'mimeType' field (e.g., 'audio/webm')")) };
62
+ if (!isValidAudioType(body.mimeType)) return { error: createErrorResponse(_copilotkitnext_shared.TranscriptionErrors.invalidAudioFormat(body.mimeType, VALID_AUDIO_TYPES)) };
63
+ try {
64
+ const filename = body.filename || "recording.webm";
65
+ return { file: base64ToFile(body.audio, body.mimeType, filename) };
66
+ } catch {
67
+ return { error: createErrorResponse(_copilotkitnext_shared.TranscriptionErrors.invalidRequest("Failed to decode base64 audio data")) };
68
+ }
69
+ }
70
+ /**
71
+ * Categorize provider errors into appropriate transcription error responses.
72
+ */
73
+ function categorizeProviderError(error) {
74
+ const message = error instanceof Error ? error.message : "Unknown error occurred";
75
+ const errorStr = String(error).toLowerCase();
76
+ if (errorStr.includes("rate") || errorStr.includes("429") || errorStr.includes("too many")) return _copilotkitnext_shared.TranscriptionErrors.rateLimited();
77
+ if (errorStr.includes("auth") || errorStr.includes("401") || errorStr.includes("api key") || errorStr.includes("unauthorized")) return _copilotkitnext_shared.TranscriptionErrors.authFailed();
78
+ if (errorStr.includes("too long") || errorStr.includes("duration") || errorStr.includes("length")) return _copilotkitnext_shared.TranscriptionErrors.audioTooLong();
79
+ return _copilotkitnext_shared.TranscriptionErrors.providerError(message);
80
+ }
81
+ async function handleTranscribe({ runtime, request }) {
82
+ try {
83
+ if (!runtime.transcriptionService) return createErrorResponse(_copilotkitnext_shared.TranscriptionErrors.serviceNotConfigured());
84
+ const contentType = request.headers.get("content-type") || "";
85
+ let extractResult;
86
+ if (contentType.includes("multipart/form-data")) extractResult = await extractAudioFromFormData(request);
87
+ else if (contentType.includes("application/json")) extractResult = await extractAudioFromJson(request);
88
+ else return createErrorResponse(_copilotkitnext_shared.TranscriptionErrors.invalidRequest("Request must be multipart/form-data or application/json with base64 audio"));
89
+ if ("error" in extractResult) return extractResult.error;
90
+ const audioFile = extractResult.file;
91
+ const transcription = await runtime.transcriptionService.transcribeFile({
92
+ audioFile,
93
+ mimeType: audioFile.type,
94
+ size: audioFile.size
95
+ });
96
+ return new Response(JSON.stringify({
97
+ text: transcription,
98
+ size: audioFile.size,
99
+ type: audioFile.type
100
+ }), {
101
+ status: 200,
102
+ headers: { "Content-Type": "application/json" }
103
+ });
104
+ } catch (error) {
105
+ return createErrorResponse(categorizeProviderError(error));
106
+ }
107
+ }
108
+
109
+ //#endregion
110
+ exports.handleTranscribe = handleTranscribe;
111
+ //# sourceMappingURL=handle-transcribe.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handle-transcribe.cjs","names":["TranscriptionErrorCode","TranscriptionErrors"],"sources":["../../src/handlers/handle-transcribe.ts"],"sourcesContent":["import { CopilotRuntime } from \"../runtime\";\nimport {\n TranscriptionErrorCode,\n TranscriptionErrors,\n type TranscriptionErrorResponse,\n} from \"@copilotkitnext/shared\";\n\n/**\n * HTTP status codes for transcription error codes\n */\nconst ERROR_STATUS_CODES: Record<TranscriptionErrorCode, number> = {\n [TranscriptionErrorCode.SERVICE_NOT_CONFIGURED]: 503,\n [TranscriptionErrorCode.INVALID_AUDIO_FORMAT]: 400,\n [TranscriptionErrorCode.AUDIO_TOO_LONG]: 400,\n [TranscriptionErrorCode.AUDIO_TOO_SHORT]: 400,\n [TranscriptionErrorCode.RATE_LIMITED]: 429,\n [TranscriptionErrorCode.AUTH_FAILED]: 401,\n [TranscriptionErrorCode.PROVIDER_ERROR]: 500,\n [TranscriptionErrorCode.NETWORK_ERROR]: 502,\n [TranscriptionErrorCode.INVALID_REQUEST]: 400,\n};\n\ninterface HandleTranscribeParameters {\n runtime: CopilotRuntime;\n request: Request;\n}\n\ninterface Base64AudioInput {\n audio: string; // base64-encoded audio data\n mimeType: string;\n filename?: string;\n}\n\nconst VALID_AUDIO_TYPES = [\n \"audio/mpeg\",\n \"audio/mp3\",\n \"audio/mp4\",\n \"audio/wav\",\n \"audio/webm\",\n \"audio/ogg\",\n \"audio/flac\",\n \"audio/aac\",\n];\n\nfunction isValidAudioType(type: string): boolean {\n // Extract base MIME type (before semicolon) to handle types like \"audio/webm; codecs=opus\"\n const baseType = type.split(\";\")[0]?.trim() ?? \"\";\n return (\n VALID_AUDIO_TYPES.includes(baseType) ||\n baseType === \"\" ||\n baseType === \"application/octet-stream\"\n );\n}\n\nfunction createErrorResponse(\n errorResponse: TranscriptionErrorResponse,\n): Response {\n const status = ERROR_STATUS_CODES[errorResponse.error] ?? 500;\n return new Response(JSON.stringify(errorResponse), {\n status,\n headers: { \"Content-Type\": \"application/json\" },\n });\n}\n\nfunction base64ToFile(\n base64: string,\n mimeType: string,\n filename: string,\n): File {\n // Remove data URL prefix if present (e.g., \"data:audio/webm;base64,\")\n const base64Data = base64.includes(\",\")\n ? (base64.split(\",\")[1] ?? base64)\n : base64;\n\n // Decode base64 to binary\n const binaryString = atob(base64Data);\n const bytes = new Uint8Array(binaryString.length);\n for (let i = 0; i < binaryString.length; i++) {\n bytes[i] = binaryString.charCodeAt(i);\n }\n\n // Create File object\n return new File([bytes], filename, { type: mimeType });\n}\n\nasync function extractAudioFromFormData(\n request: Request,\n): Promise<{ file: File } | { error: Response }> {\n const formData = await request.formData();\n const audioFile = formData.get(\"audio\") as File | null;\n\n if (!audioFile || !(audioFile instanceof File)) {\n const err = TranscriptionErrors.invalidRequest(\n \"No audio file found in form data. Please include an 'audio' field.\",\n );\n return { error: createErrorResponse(err) };\n }\n\n if (!isValidAudioType(audioFile.type)) {\n const err = TranscriptionErrors.invalidAudioFormat(\n audioFile.type,\n VALID_AUDIO_TYPES,\n );\n return { error: createErrorResponse(err) };\n }\n\n return { file: audioFile };\n}\n\nasync function extractAudioFromJson(\n request: Request,\n): Promise<{ file: File } | { error: Response }> {\n let body: Base64AudioInput;\n\n try {\n body = await request.json();\n } catch {\n const err = TranscriptionErrors.invalidRequest(\n \"Request body must be valid JSON\",\n );\n return { error: createErrorResponse(err) };\n }\n\n if (!body.audio || typeof body.audio !== \"string\") {\n const err = TranscriptionErrors.invalidRequest(\n \"Request must include 'audio' field with base64-encoded audio data\",\n );\n return { error: createErrorResponse(err) };\n }\n\n if (!body.mimeType || typeof body.mimeType !== \"string\") {\n const err = TranscriptionErrors.invalidRequest(\n \"Request must include 'mimeType' field (e.g., 'audio/webm')\",\n );\n return { error: createErrorResponse(err) };\n }\n\n if (!isValidAudioType(body.mimeType)) {\n const err = TranscriptionErrors.invalidAudioFormat(\n body.mimeType,\n VALID_AUDIO_TYPES,\n );\n return { error: createErrorResponse(err) };\n }\n\n try {\n const filename = body.filename || \"recording.webm\";\n const file = base64ToFile(body.audio, body.mimeType, filename);\n return { file };\n } catch {\n const err = TranscriptionErrors.invalidRequest(\n \"Failed to decode base64 audio data\",\n );\n return { error: createErrorResponse(err) };\n }\n}\n\n/**\n * Categorize provider errors into appropriate transcription error responses.\n */\nfunction categorizeProviderError(error: unknown): TranscriptionErrorResponse {\n const message =\n error instanceof Error ? error.message : \"Unknown error occurred\";\n const errorStr = String(error).toLowerCase();\n\n // Check for rate limiting\n if (\n errorStr.includes(\"rate\") ||\n errorStr.includes(\"429\") ||\n errorStr.includes(\"too many\")\n ) {\n return TranscriptionErrors.rateLimited();\n }\n\n // Check for auth errors\n if (\n errorStr.includes(\"auth\") ||\n errorStr.includes(\"401\") ||\n errorStr.includes(\"api key\") ||\n errorStr.includes(\"unauthorized\")\n ) {\n return TranscriptionErrors.authFailed();\n }\n\n // Check for audio too long\n if (\n errorStr.includes(\"too long\") ||\n errorStr.includes(\"duration\") ||\n errorStr.includes(\"length\")\n ) {\n return TranscriptionErrors.audioTooLong();\n }\n\n // Default to provider error\n return TranscriptionErrors.providerError(message);\n}\n\nexport async function handleTranscribe({\n runtime,\n request,\n}: HandleTranscribeParameters) {\n try {\n // Check if transcription service is configured\n if (!runtime.transcriptionService) {\n const err = TranscriptionErrors.serviceNotConfigured();\n return createErrorResponse(err);\n }\n\n // Determine input type based on content-type header\n const contentType = request.headers.get(\"content-type\") || \"\";\n\n let extractResult: { file: File } | { error: Response };\n\n if (contentType.includes(\"multipart/form-data\")) {\n // Handle multipart/form-data (REST mode)\n extractResult = await extractAudioFromFormData(request);\n } else if (contentType.includes(\"application/json\")) {\n // Handle JSON with base64 audio (single-endpoint mode)\n extractResult = await extractAudioFromJson(request);\n } else {\n const err = TranscriptionErrors.invalidRequest(\n \"Request must be multipart/form-data or application/json with base64 audio\",\n );\n return createErrorResponse(err);\n }\n\n // Check for extraction errors\n if (\"error\" in extractResult) {\n return extractResult.error;\n }\n\n const audioFile = extractResult.file;\n\n // Transcribe the audio file\n const transcription = await runtime.transcriptionService.transcribeFile({\n audioFile,\n mimeType: audioFile.type,\n size: audioFile.size,\n });\n\n return new Response(\n JSON.stringify({\n text: transcription,\n size: audioFile.size,\n type: audioFile.type,\n }),\n {\n status: 200,\n headers: { \"Content-Type\": \"application/json\" },\n },\n );\n } catch (error) {\n // Categorize the error for better client-side handling\n return createErrorResponse(categorizeProviderError(error));\n }\n}\n"],"mappings":";;;;;;;AAUA,MAAM,qBAA6D;EAChEA,8CAAuB,yBAAyB;EAChDA,8CAAuB,uBAAuB;EAC9CA,8CAAuB,iBAAiB;EACxCA,8CAAuB,kBAAkB;EACzCA,8CAAuB,eAAe;EACtCA,8CAAuB,cAAc;EACrCA,8CAAuB,iBAAiB;EACxCA,8CAAuB,gBAAgB;EACvCA,8CAAuB,kBAAkB;CAC3C;AAaD,MAAM,oBAAoB;CACxB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD;AAED,SAAS,iBAAiB,MAAuB;CAE/C,MAAM,WAAW,KAAK,MAAM,IAAI,CAAC,IAAI,MAAM,IAAI;AAC/C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