@copilotkit/runtime 0.0.0-fix-restore-handle-method-node-http-20260105204107 → 0.0.0-fix-runtime-openai-api-key-passthrough-20260115015318
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/CHANGELOG.md +75 -24
- package/LICENSE +21 -0
- package/dist/index.d.ts +4 -3
- package/dist/index.js +172 -11
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +172 -11
- package/dist/index.mjs.map +1 -1
- package/package.json +13 -10
- package/src/lib/integrations/node-http/index.ts +94 -2
- package/src/lib/integrations/node-http/request-handler.ts +111 -0
- package/src/lib/runtime/copilot-runtime.ts +3 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,11 +1,83 @@
|
|
|
1
1
|
# @copilotkit/runtime
|
|
2
2
|
|
|
3
|
-
## 0.0.0-fix-
|
|
3
|
+
## 0.0.0-fix-runtime-openai-api-key-passthrough-20260115015318
|
|
4
4
|
|
|
5
5
|
### Patch Changes
|
|
6
6
|
|
|
7
|
-
-
|
|
8
|
-
|
|
7
|
+
- 1e62c11: fix: add apiKey parameter to BuiltInAgentConfiguration
|
|
8
|
+
- Updated dependencies [1e62c11]
|
|
9
|
+
- @copilotkitnext/agent@0.0.0-fix-runtime-openai-api-key-passthrough-20260115015318
|
|
10
|
+
- @copilotkit/shared@0.0.0-fix-runtime-openai-api-key-passthrough-20260115015318
|
|
11
|
+
- @copilotkitnext/runtime@0.0.0-fix-runtime-openai-api-key-passthrough-20260115015318
|
|
12
|
+
|
|
13
|
+
## 1.51.1
|
|
14
|
+
|
|
15
|
+
### Patch Changes
|
|
16
|
+
|
|
17
|
+
- Updated dependencies [329653b]
|
|
18
|
+
- @copilotkitnext/agent@1.51.1
|
|
19
|
+
- @copilotkit/shared@1.51.1
|
|
20
|
+
- @copilotkitnext/runtime@1.51.1
|
|
21
|
+
|
|
22
|
+
## 1.51.0
|
|
23
|
+
|
|
24
|
+
### Patch Changes
|
|
25
|
+
|
|
26
|
+
- 2839a15: fix: restore and fix handle method in node http
|
|
27
|
+
- 2839a15: Update versioning strategy
|
|
28
|
+
- 2839a15: fix: use direct hono node integration on node-http integration
|
|
29
|
+
- 4addb72: Fix ci again but really for real this time
|
|
30
|
+
- Updated dependencies [2793a11]
|
|
31
|
+
- Updated dependencies [73f196f]
|
|
32
|
+
- Updated dependencies [2839a15]
|
|
33
|
+
- Updated dependencies [2afd4e3]
|
|
34
|
+
- @copilotkitnext/runtime@1.51.0
|
|
35
|
+
- @copilotkit/shared@1.51.0
|
|
36
|
+
- @copilotkitnext/agent@1.51.0
|
|
37
|
+
|
|
38
|
+
## 1.51.0-next.4
|
|
39
|
+
|
|
40
|
+
### Patch Changes
|
|
41
|
+
|
|
42
|
+
- Updated dependencies [2793a11]
|
|
43
|
+
- @copilotkitnext/runtime@1.51.0-next.4
|
|
44
|
+
- @copilotkit/shared@1.51.0-next.4
|
|
45
|
+
- @copilotkitnext/agent@1.51.0-next.4
|
|
46
|
+
|
|
47
|
+
## 1.51.0-next.3
|
|
48
|
+
|
|
49
|
+
### Patch Changes
|
|
50
|
+
|
|
51
|
+
- Updated dependencies [73f196f]
|
|
52
|
+
- @copilotkitnext/runtime@1.51.0-next.3
|
|
53
|
+
- @copilotkit/shared@1.51.0-next.3
|
|
54
|
+
- @copilotkitnext/agent@1.51.0-next.3
|
|
55
|
+
|
|
56
|
+
## 1.51.0-next.2
|
|
57
|
+
|
|
58
|
+
### Patch Changes
|
|
59
|
+
|
|
60
|
+
- 4addb72: Fix ci again but really for real this time
|
|
61
|
+
- Updated dependencies [2afd4e3]
|
|
62
|
+
- @copilotkit/shared@1.51.0-next.2
|
|
63
|
+
- @copilotkitnext/agent@1.51.0-next.2
|
|
64
|
+
- @copilotkitnext/runtime@1.51.0-next.2
|
|
65
|
+
|
|
66
|
+
## 1.51.0-next.1
|
|
67
|
+
|
|
68
|
+
### Patch Changes
|
|
69
|
+
|
|
70
|
+
- @copilotkit/shared@1.51.0-next.1
|
|
71
|
+
- @copilotkitnext/agent@1.51.0-next.1
|
|
72
|
+
- @copilotkitnext/runtime@1.51.0-next.1
|
|
73
|
+
|
|
74
|
+
## 1.50.2-next.0
|
|
75
|
+
|
|
76
|
+
### Patch Changes
|
|
77
|
+
|
|
78
|
+
- cf245a6: fix: restore and fix handle method in node http
|
|
79
|
+
- cf245a6: fix: use direct hono node integration on node-http integration
|
|
80
|
+
- @copilotkit/shared@1.50.2-next.0
|
|
9
81
|
|
|
10
82
|
## 1.50.1
|
|
11
83
|
|
|
@@ -522,7 +594,6 @@
|
|
|
522
594
|
### Patch Changes
|
|
523
595
|
|
|
524
596
|
- 1abcecf: - fix: add graphqlContext to constructAGUIRemoteAction for enhanced agent properties
|
|
525
|
-
|
|
526
597
|
- Updated constructAGUIRemoteAction to accept graphqlContext, allowing forwarding of properties like Authorization token to the agent.
|
|
527
598
|
- Modified setupRemoteActions to include graphqlContext in the parameters.
|
|
528
599
|
|
|
@@ -624,7 +695,6 @@
|
|
|
624
695
|
### Patch Changes
|
|
625
696
|
|
|
626
697
|
- 1abcecf: - fix: add graphqlContext to constructAGUIRemoteAction for enhanced agent properties
|
|
627
|
-
|
|
628
698
|
- Updated constructAGUIRemoteAction to accept graphqlContext, allowing forwarding of properties like Authorization token to the agent.
|
|
629
699
|
- Modified setupRemoteActions to include graphqlContext in the parameters.
|
|
630
700
|
- @copilotkit/shared@1.10.0-next.1
|
|
@@ -692,7 +762,6 @@
|
|
|
692
762
|
- remove request logging
|
|
693
763
|
- 3a7f45f: - fix: resolve agui agents only after all other endpoints
|
|
694
764
|
- fac89c2: - refactor: rename onTrace to onError throughout codebase
|
|
695
|
-
|
|
696
765
|
- Rename CopilotTraceEvent to CopilotErrorEvent and CopilotTraceHandler to CopilotErrorHandler
|
|
697
766
|
|
|
698
767
|
- 7ca7023: - feat: send node name to agui agent
|
|
@@ -793,7 +862,6 @@
|
|
|
793
862
|
### Patch Changes
|
|
794
863
|
|
|
795
864
|
- fac89c2: - refactor: rename onTrace to onError throughout codebase
|
|
796
|
-
|
|
797
865
|
- Rename CopilotTraceEvent to CopilotErrorEvent and CopilotTraceHandler to CopilotErrorHandler
|
|
798
866
|
|
|
799
867
|
- Updated dependencies [fac89c2]
|
|
@@ -1275,11 +1343,9 @@
|
|
|
1275
1343
|
- c0d3261: - full AWP support
|
|
1276
1344
|
|
|
1277
1345
|
Signed-off-by: Tyler Slaton <tyler@copilotkit.ai>
|
|
1278
|
-
|
|
1279
1346
|
- refactor: address linter issues with the new pages
|
|
1280
1347
|
|
|
1281
1348
|
Signed-off-by: Tyler Slaton <tyler@copilotkit.ai>
|
|
1282
|
-
|
|
1283
1349
|
- Merge branch 'mme/acp' into mme/mastra
|
|
1284
1350
|
- add sse example
|
|
1285
1351
|
- Create small-turkeys-agree.md
|
|
@@ -1296,17 +1362,14 @@
|
|
|
1296
1362
|
- 77a7457: - feat: Add Model Context Protocol (MCP) support
|
|
1297
1363
|
- 76d9ef9: - fix: handle langgraph client specific errors when running lgc stream
|
|
1298
1364
|
- c0d3261: - add AWP support
|
|
1299
|
-
|
|
1300
1365
|
- make it work
|
|
1301
1366
|
- update docs
|
|
1302
1367
|
- refactor: move UI files to be normal NextJS pages and update generation
|
|
1303
1368
|
|
|
1304
1369
|
Signed-off-by: Tyler Slaton <tyler@copilotkit.ai>
|
|
1305
|
-
|
|
1306
1370
|
- refactor: address linter issues with the new pages
|
|
1307
1371
|
|
|
1308
1372
|
Signed-off-by: Tyler Slaton <tyler@copilotkit.ai>
|
|
1309
|
-
|
|
1310
1373
|
- Merge branch 'mme/acp' into mme/mastra
|
|
1311
1374
|
- add sse example
|
|
1312
1375
|
|
|
@@ -1320,11 +1383,9 @@
|
|
|
1320
1383
|
- c0d3261: - full AWP support
|
|
1321
1384
|
|
|
1322
1385
|
Signed-off-by: Tyler Slaton <tyler@copilotkit.ai>
|
|
1323
|
-
|
|
1324
1386
|
- refactor: address linter issues with the new pages
|
|
1325
1387
|
|
|
1326
1388
|
Signed-off-by: Tyler Slaton <tyler@copilotkit.ai>
|
|
1327
|
-
|
|
1328
1389
|
- Merge branch 'mme/acp' into mme/mastra
|
|
1329
1390
|
- add sse example
|
|
1330
1391
|
- Create small-turkeys-agree.md
|
|
@@ -1339,17 +1400,14 @@
|
|
|
1339
1400
|
- fix missing tool call ids
|
|
1340
1401
|
|
|
1341
1402
|
- c0d3261: - add AWP support
|
|
1342
|
-
|
|
1343
1403
|
- make it work
|
|
1344
1404
|
- update docs
|
|
1345
1405
|
- refactor: move UI files to be normal NextJS pages and update generation
|
|
1346
1406
|
|
|
1347
1407
|
Signed-off-by: Tyler Slaton <tyler@copilotkit.ai>
|
|
1348
|
-
|
|
1349
1408
|
- refactor: address linter issues with the new pages
|
|
1350
1409
|
|
|
1351
1410
|
Signed-off-by: Tyler Slaton <tyler@copilotkit.ai>
|
|
1352
|
-
|
|
1353
1411
|
- Merge branch 'mme/acp' into mme/mastra
|
|
1354
1412
|
- add sse example
|
|
1355
1413
|
- @copilotkit/shared@1.8.5-next.5
|
|
@@ -2354,7 +2412,6 @@
|
|
|
2354
2412
|
- e16d95e: New prerelease
|
|
2355
2413
|
- 1721cbd: Add convertActionsToDynamicStructuredTools to sdk-js
|
|
2356
2414
|
- CopilotKit Core:
|
|
2357
|
-
|
|
2358
2415
|
- Improved error messages and overall logs
|
|
2359
2416
|
- `useCopilotAction.renderAndAwait` renamed to `.renderAndAwaitForResponse` (backwards compatible, will be deprecated in the future)
|
|
2360
2417
|
- Improved scrolling behavior. It is now possible to scroll up during LLM response generation
|
|
@@ -2362,7 +2419,6 @@
|
|
|
2362
2419
|
- Updated interfaces for better developer ergonomics
|
|
2363
2420
|
|
|
2364
2421
|
CoAgents:
|
|
2365
|
-
|
|
2366
2422
|
- Renamed `remoteActions` to `remoteEndpoints` (backwards compatible, will be deprecated in the future)
|
|
2367
2423
|
- Support for LangGraph Platform in Remote Endpoints
|
|
2368
2424
|
- LangGraph JS Support for CoAgents (locally via `langgraph dev`, `langgraph up` or deployed to LangGraph Platform)
|
|
@@ -2370,7 +2426,6 @@
|
|
|
2370
2426
|
- Enhanced state management and message handling
|
|
2371
2427
|
|
|
2372
2428
|
CopilotKid Back-end SDK:
|
|
2373
|
-
|
|
2374
2429
|
- Released a whole-new `@copilotkit/sdk-js` for building agents with LangGraph JS Support
|
|
2375
2430
|
|
|
2376
2431
|
- 8d0144f: bump
|
|
@@ -2717,7 +2772,6 @@ CopilotKid Back-end SDK:
|
|
|
2717
2772
|
### Patch Changes
|
|
2718
2773
|
|
|
2719
2774
|
- inject minified css in bundle
|
|
2720
|
-
|
|
2721
2775
|
- removes the need to import `styles.css` manually
|
|
2722
2776
|
- empty `styles.css` included in the build for backwards compatibility
|
|
2723
2777
|
- uses tsup's `injectStyles` with `postcss` to bundle and minify the CSS, then inject it as a style tag
|
|
@@ -2854,7 +2908,6 @@ CopilotKid Back-end SDK:
|
|
|
2854
2908
|
### Major Changes
|
|
2855
2909
|
|
|
2856
2910
|
- b6a4b6eb: V1.0 Release Candidate
|
|
2857
|
-
|
|
2858
2911
|
- A robust new protocol between the frontend and the Copilot Runtime
|
|
2859
2912
|
- Support for Copilot Cloud
|
|
2860
2913
|
- Generative UI
|
|
@@ -2862,7 +2915,6 @@ CopilotKid Back-end SDK:
|
|
|
2862
2915
|
- OpenAI assistant API streaming
|
|
2863
2916
|
|
|
2864
2917
|
- V1.0 Release
|
|
2865
|
-
|
|
2866
2918
|
- A robust new protocol between the frontend and the Copilot Runtime
|
|
2867
2919
|
- Support for Copilot Cloud
|
|
2868
2920
|
- Generative UI
|
|
@@ -2900,7 +2952,6 @@ CopilotKid Back-end SDK:
|
|
|
2900
2952
|
### Major Changes
|
|
2901
2953
|
|
|
2902
2954
|
- V1.0 Release Candidate
|
|
2903
|
-
|
|
2904
2955
|
- A robust new protocol between the frontend and the Copilot Runtime
|
|
2905
2956
|
- Support for Copilot Cloud
|
|
2906
2957
|
- Generative UI
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) Atai Barkai
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
package/dist/index.d.ts
CHANGED
|
@@ -7,7 +7,8 @@ import { IterableReadableStream, IterableReadableStreamInterface } from '@langch
|
|
|
7
7
|
import { Groq } from 'groq-sdk';
|
|
8
8
|
import Anthropic from '@anthropic-ai/sdk';
|
|
9
9
|
import * as graphql from 'graphql';
|
|
10
|
-
import * as
|
|
10
|
+
import * as createPinoLogger from 'pino';
|
|
11
|
+
import createPinoLogger__default from 'pino';
|
|
11
12
|
import { YogaInitialContext, createYoga } from 'graphql-yoga';
|
|
12
13
|
import { CopilotRuntimeOptions, CopilotRuntime as CopilotRuntime$1, AgentRunner } from '@copilotkitnext/runtime';
|
|
13
14
|
import { AbstractAgent } from '@ag-ui/client';
|
|
@@ -1301,9 +1302,9 @@ type CopilotRuntimeLogger = ReturnType<typeof createLogger>;
|
|
|
1301
1302
|
declare function createLogger(options?: {
|
|
1302
1303
|
level?: LogLevel;
|
|
1303
1304
|
component?: string;
|
|
1304
|
-
}):
|
|
1305
|
+
}): createPinoLogger__default.Logger<never, boolean>;
|
|
1305
1306
|
|
|
1306
|
-
declare const logger:
|
|
1307
|
+
declare const logger: createPinoLogger.Logger<never, boolean>;
|
|
1307
1308
|
declare const addCustomHeaderPlugin: {
|
|
1308
1309
|
onResponse({ response }: {
|
|
1309
1310
|
response: any;
|
package/dist/index.js
CHANGED
|
@@ -17,7 +17,7 @@ var pluginDeferStream = require('@graphql-yoga/plugin-defer-stream');
|
|
|
17
17
|
var createPinoLogger = require('pino');
|
|
18
18
|
var pretty = require('pino-pretty');
|
|
19
19
|
var vercel = require('hono/vercel');
|
|
20
|
-
var
|
|
20
|
+
var stream = require('stream');
|
|
21
21
|
|
|
22
22
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
23
23
|
|
|
@@ -72,7 +72,7 @@ var require_package = __commonJS({
|
|
|
72
72
|
publishConfig: {
|
|
73
73
|
access: "public"
|
|
74
74
|
},
|
|
75
|
-
version: "1.
|
|
75
|
+
version: "1.51.1",
|
|
76
76
|
sideEffects: false,
|
|
77
77
|
main: "./dist/index.js",
|
|
78
78
|
module: "./dist/index.mjs",
|
|
@@ -96,7 +96,7 @@ var require_package = __commonJS({
|
|
|
96
96
|
types: "./dist/index.d.ts",
|
|
97
97
|
license: "MIT",
|
|
98
98
|
scripts: {
|
|
99
|
-
build:
|
|
99
|
+
build: "pnpm run generate-graphql-schema && tsup",
|
|
100
100
|
dev: 'tsup --watch --onSuccess "pnpm run generate-graphql-schema"',
|
|
101
101
|
test: "jest --passWithNoTests",
|
|
102
102
|
"check-types": "tsc --noEmit",
|
|
@@ -106,6 +106,9 @@ var require_package = __commonJS({
|
|
|
106
106
|
"unlink:global": "pnpm unlink --global"
|
|
107
107
|
},
|
|
108
108
|
devDependencies: {
|
|
109
|
+
"@copilotkit/shared": "workspace:*",
|
|
110
|
+
"@copilotkitnext/agent": "workspace:*",
|
|
111
|
+
"@copilotkitnext/runtime": "workspace:*",
|
|
109
112
|
"@jest/globals": "^29.7.0",
|
|
110
113
|
"@swc/core": "1.5.28",
|
|
111
114
|
"@types/jest": "^29.5.12",
|
|
@@ -123,12 +126,6 @@ var require_package = __commonJS({
|
|
|
123
126
|
vitest: "^3.2.4"
|
|
124
127
|
},
|
|
125
128
|
dependencies: {
|
|
126
|
-
"@ag-ui/client": "^0.0.42",
|
|
127
|
-
"@ag-ui/core": "^0.0.42",
|
|
128
|
-
"@ag-ui/langgraph": "^0.0.20",
|
|
129
|
-
"@copilotkit/shared": "workspace:*",
|
|
130
|
-
"@copilotkitnext/agent": "0.0.33",
|
|
131
|
-
"@copilotkitnext/runtime": "0.0.33",
|
|
132
129
|
"@graphql-yoga/plugin-defer-stream": "^3.3.1",
|
|
133
130
|
"@hono/node-server": "^1.13.5",
|
|
134
131
|
"@scarf/scarf": "^1.3.0",
|
|
@@ -148,7 +145,13 @@ var require_package = __commonJS({
|
|
|
148
145
|
zod: "^3.23.3"
|
|
149
146
|
},
|
|
150
147
|
peerDependencies: {
|
|
148
|
+
"@ag-ui/client": "^0.0.42",
|
|
149
|
+
"@ag-ui/core": "^0.0.42",
|
|
150
|
+
"@ag-ui/langgraph": "^0.0.20",
|
|
151
151
|
"@anthropic-ai/sdk": "^0.57.0",
|
|
152
|
+
"@copilotkit/shared": "workspace:*",
|
|
153
|
+
"@copilotkitnext/agent": "workspace:*",
|
|
154
|
+
"@copilotkitnext/runtime": "workspace:*",
|
|
152
155
|
"@langchain/aws": ">=0.1.9",
|
|
153
156
|
"@langchain/core": ">=0.3.66",
|
|
154
157
|
"@langchain/community": ">=0.3.58",
|
|
@@ -3588,7 +3591,7 @@ var CopilotRuntime = class {
|
|
|
3588
3591
|
} : {},
|
|
3589
3592
|
"cloud.base_url": cloudBaseUrl
|
|
3590
3593
|
});
|
|
3591
|
-
(_c = params == null ? void 0 : params.beforeRequestMiddleware) == null ? void 0 : _c.call(params, hookParams);
|
|
3594
|
+
const middlewareResult = await ((_c = params == null ? void 0 : params.beforeRequestMiddleware) == null ? void 0 : _c.call(params, hookParams));
|
|
3592
3595
|
if ((_d = params == null ? void 0 : params.middleware) == null ? void 0 : _d.onBeforeRequest) {
|
|
3593
3596
|
const { request: request2, runtime, path } = hookParams;
|
|
3594
3597
|
const gqlMessages = aguiToGQL(body.messages).reduce((acc, msg) => {
|
|
@@ -3611,6 +3614,7 @@ var CopilotRuntime = class {
|
|
|
3611
3614
|
url: request2.url
|
|
3612
3615
|
});
|
|
3613
3616
|
}
|
|
3617
|
+
return middlewareResult;
|
|
3614
3618
|
};
|
|
3615
3619
|
}
|
|
3616
3620
|
createOnAfterRequestHandler(params) {
|
|
@@ -4737,6 +4741,98 @@ function copilotRuntimeNextJSAppRouterEndpoint(options) {
|
|
|
4737
4741
|
};
|
|
4738
4742
|
}
|
|
4739
4743
|
__name(copilotRuntimeNextJSAppRouterEndpoint, "copilotRuntimeNextJSAppRouterEndpoint");
|
|
4744
|
+
function readableStreamToNodeStream(webStream) {
|
|
4745
|
+
const reader = webStream.getReader();
|
|
4746
|
+
return new stream.Readable({
|
|
4747
|
+
async read() {
|
|
4748
|
+
try {
|
|
4749
|
+
const { done, value } = await reader.read();
|
|
4750
|
+
if (done) {
|
|
4751
|
+
this.push(null);
|
|
4752
|
+
} else {
|
|
4753
|
+
this.push(Buffer.from(value));
|
|
4754
|
+
}
|
|
4755
|
+
} catch (err) {
|
|
4756
|
+
this.destroy(err);
|
|
4757
|
+
}
|
|
4758
|
+
}
|
|
4759
|
+
});
|
|
4760
|
+
}
|
|
4761
|
+
__name(readableStreamToNodeStream, "readableStreamToNodeStream");
|
|
4762
|
+
function nodeStreamToReadableStream(nodeStream) {
|
|
4763
|
+
return new ReadableStream({
|
|
4764
|
+
start(controller) {
|
|
4765
|
+
nodeStream.on("data", (chunk) => {
|
|
4766
|
+
controller.enqueue(chunk instanceof Buffer ? new Uint8Array(chunk) : chunk);
|
|
4767
|
+
});
|
|
4768
|
+
nodeStream.on("end", () => {
|
|
4769
|
+
controller.close();
|
|
4770
|
+
});
|
|
4771
|
+
nodeStream.on("error", (err) => {
|
|
4772
|
+
controller.error(err);
|
|
4773
|
+
});
|
|
4774
|
+
},
|
|
4775
|
+
cancel() {
|
|
4776
|
+
nodeStream.destroy();
|
|
4777
|
+
}
|
|
4778
|
+
});
|
|
4779
|
+
}
|
|
4780
|
+
__name(nodeStreamToReadableStream, "nodeStreamToReadableStream");
|
|
4781
|
+
function getFullUrl(req) {
|
|
4782
|
+
const path = req.url || "/";
|
|
4783
|
+
const host = req.headers["x-forwarded-host"] || req.headers.host || "localhost";
|
|
4784
|
+
const proto = req.headers["x-forwarded-proto"] || (req.socket.encrypted ? "https" : "http");
|
|
4785
|
+
return `${proto}://${host}${path}`;
|
|
4786
|
+
}
|
|
4787
|
+
__name(getFullUrl, "getFullUrl");
|
|
4788
|
+
function toHeaders(rawHeaders) {
|
|
4789
|
+
const headers = new Headers();
|
|
4790
|
+
for (const [key, value] of Object.entries(rawHeaders)) {
|
|
4791
|
+
if (value === void 0)
|
|
4792
|
+
continue;
|
|
4793
|
+
if (Array.isArray(value)) {
|
|
4794
|
+
value.forEach((entry) => headers.append(key, entry));
|
|
4795
|
+
continue;
|
|
4796
|
+
}
|
|
4797
|
+
headers.append(key, value);
|
|
4798
|
+
}
|
|
4799
|
+
return headers;
|
|
4800
|
+
}
|
|
4801
|
+
__name(toHeaders, "toHeaders");
|
|
4802
|
+
function isStreamConsumed(req) {
|
|
4803
|
+
const readableState = req._readableState;
|
|
4804
|
+
return Boolean(req.readableEnded || req.complete || (readableState == null ? void 0 : readableState.ended) || (readableState == null ? void 0 : readableState.endEmitted));
|
|
4805
|
+
}
|
|
4806
|
+
__name(isStreamConsumed, "isStreamConsumed");
|
|
4807
|
+
function synthesizeBodyFromParsedBody(parsedBody, headers) {
|
|
4808
|
+
if (parsedBody === null || parsedBody === void 0) {
|
|
4809
|
+
return {
|
|
4810
|
+
body: null
|
|
4811
|
+
};
|
|
4812
|
+
}
|
|
4813
|
+
if (parsedBody instanceof Buffer || parsedBody instanceof Uint8Array) {
|
|
4814
|
+
return {
|
|
4815
|
+
body: parsedBody
|
|
4816
|
+
};
|
|
4817
|
+
}
|
|
4818
|
+
if (typeof parsedBody === "string") {
|
|
4819
|
+
return {
|
|
4820
|
+
body: parsedBody,
|
|
4821
|
+
contentType: headers.get("content-type") ?? "text/plain"
|
|
4822
|
+
};
|
|
4823
|
+
}
|
|
4824
|
+
return {
|
|
4825
|
+
body: JSON.stringify(parsedBody),
|
|
4826
|
+
contentType: "application/json"
|
|
4827
|
+
};
|
|
4828
|
+
}
|
|
4829
|
+
__name(synthesizeBodyFromParsedBody, "synthesizeBodyFromParsedBody");
|
|
4830
|
+
function isDisturbedOrLockedError(error) {
|
|
4831
|
+
return error instanceof TypeError && typeof error.message === "string" && (error.message.includes("disturbed") || error.message.includes("locked"));
|
|
4832
|
+
}
|
|
4833
|
+
__name(isDisturbedOrLockedError, "isDisturbedOrLockedError");
|
|
4834
|
+
|
|
4835
|
+
// src/lib/integrations/node-http/index.ts
|
|
4740
4836
|
function copilotRuntimeNodeHttpEndpoint(options) {
|
|
4741
4837
|
var _a;
|
|
4742
4838
|
const commonConfig = getCommonConfig(options);
|
|
@@ -4761,7 +4857,72 @@ function copilotRuntimeNodeHttpEndpoint(options) {
|
|
|
4761
4857
|
runtime: options.runtime.instance,
|
|
4762
4858
|
basePath: options.baseUrl ?? options.endpoint
|
|
4763
4859
|
});
|
|
4764
|
-
const handle2 =
|
|
4860
|
+
const handle2 = /* @__PURE__ */ __name(async function handler(req, res) {
|
|
4861
|
+
const url = getFullUrl(req);
|
|
4862
|
+
const hasBody = req.method !== "GET" && req.method !== "HEAD";
|
|
4863
|
+
const baseHeaders = toHeaders(req.headers);
|
|
4864
|
+
const parsedBody = req.body;
|
|
4865
|
+
const streamConsumed = isStreamConsumed(req) || parsedBody !== void 0;
|
|
4866
|
+
const canStream = hasBody && !streamConsumed;
|
|
4867
|
+
let requestBody = void 0;
|
|
4868
|
+
let useDuplex = false;
|
|
4869
|
+
if (hasBody && canStream) {
|
|
4870
|
+
requestBody = nodeStreamToReadableStream(req);
|
|
4871
|
+
useDuplex = true;
|
|
4872
|
+
}
|
|
4873
|
+
if (hasBody && streamConsumed) {
|
|
4874
|
+
if (parsedBody !== void 0) {
|
|
4875
|
+
const synthesized = synthesizeBodyFromParsedBody(parsedBody, baseHeaders);
|
|
4876
|
+
requestBody = synthesized.body ?? void 0;
|
|
4877
|
+
baseHeaders.delete("content-length");
|
|
4878
|
+
if (synthesized.contentType) {
|
|
4879
|
+
baseHeaders.set("content-type", synthesized.contentType);
|
|
4880
|
+
}
|
|
4881
|
+
logger2.debug("Request stream already consumed; using parsed req.body to rebuild request.");
|
|
4882
|
+
} else {
|
|
4883
|
+
logger2.warn("Request stream consumed with no available body; sending empty payload.");
|
|
4884
|
+
requestBody = void 0;
|
|
4885
|
+
}
|
|
4886
|
+
}
|
|
4887
|
+
const buildRequest = /* @__PURE__ */ __name((body, headers, duplex) => new Request(url, {
|
|
4888
|
+
method: req.method,
|
|
4889
|
+
headers,
|
|
4890
|
+
body,
|
|
4891
|
+
duplex: duplex ? "half" : void 0
|
|
4892
|
+
}), "buildRequest");
|
|
4893
|
+
let response;
|
|
4894
|
+
try {
|
|
4895
|
+
response = await honoApp.fetch(buildRequest(requestBody, baseHeaders, useDuplex));
|
|
4896
|
+
} catch (error) {
|
|
4897
|
+
if (isDisturbedOrLockedError(error) && hasBody) {
|
|
4898
|
+
logger2.warn("Encountered disturbed/locked request body; rebuilding request using parsed body or empty payload.");
|
|
4899
|
+
const fallbackHeaders = new Headers(baseHeaders);
|
|
4900
|
+
let fallbackBody;
|
|
4901
|
+
if (parsedBody !== void 0) {
|
|
4902
|
+
const synthesized = synthesizeBodyFromParsedBody(parsedBody, fallbackHeaders);
|
|
4903
|
+
fallbackBody = synthesized.body ?? void 0;
|
|
4904
|
+
fallbackHeaders.delete("content-length");
|
|
4905
|
+
if (synthesized.contentType) {
|
|
4906
|
+
fallbackHeaders.set("content-type", synthesized.contentType);
|
|
4907
|
+
}
|
|
4908
|
+
} else {
|
|
4909
|
+
fallbackBody = void 0;
|
|
4910
|
+
}
|
|
4911
|
+
response = await honoApp.fetch(buildRequest(fallbackBody, fallbackHeaders, false));
|
|
4912
|
+
} else {
|
|
4913
|
+
throw error;
|
|
4914
|
+
}
|
|
4915
|
+
}
|
|
4916
|
+
res.statusCode = response.status;
|
|
4917
|
+
response.headers.forEach((value, key) => {
|
|
4918
|
+
res.setHeader(key, value);
|
|
4919
|
+
});
|
|
4920
|
+
if (response.body) {
|
|
4921
|
+
readableStreamToNodeStream(response.body).pipe(res);
|
|
4922
|
+
} else {
|
|
4923
|
+
res.end();
|
|
4924
|
+
}
|
|
4925
|
+
}, "handler");
|
|
4765
4926
|
return function(reqOrRequest, res) {
|
|
4766
4927
|
if (reqOrRequest instanceof Request) {
|
|
4767
4928
|
return honoApp.fetch(reqOrRequest);
|