@copilotkit/runtime 0.0.0-fix-restore-handle-method-node-http-20260105204107 → 0.0.0-fix-runtime-openai-api-key-passthrough-20260115003142
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 +74 -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,82 @@
|
|
|
1
1
|
# @copilotkit/runtime
|
|
2
2
|
|
|
3
|
-
## 0.0.0-fix-
|
|
3
|
+
## 0.0.0-fix-runtime-openai-api-key-passthrough-20260115003142
|
|
4
4
|
|
|
5
5
|
### Patch Changes
|
|
6
6
|
|
|
7
|
-
-
|
|
8
|
-
- @
|
|
7
|
+
- Updated dependencies [1e62c11]
|
|
8
|
+
- @copilotkitnext/agent@0.0.0-fix-runtime-openai-api-key-passthrough-20260115003142
|
|
9
|
+
- @copilotkit/shared@0.0.0-fix-runtime-openai-api-key-passthrough-20260115003142
|
|
10
|
+
- @copilotkitnext/runtime@0.0.0-fix-runtime-openai-api-key-passthrough-20260115003142
|
|
11
|
+
|
|
12
|
+
## 1.51.1
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- Updated dependencies [329653b]
|
|
17
|
+
- @copilotkitnext/agent@1.51.1
|
|
18
|
+
- @copilotkit/shared@1.51.1
|
|
19
|
+
- @copilotkitnext/runtime@1.51.1
|
|
20
|
+
|
|
21
|
+
## 1.51.0
|
|
22
|
+
|
|
23
|
+
### Patch Changes
|
|
24
|
+
|
|
25
|
+
- 2839a15: fix: restore and fix handle method in node http
|
|
26
|
+
- 2839a15: Update versioning strategy
|
|
27
|
+
- 2839a15: fix: use direct hono node integration on node-http integration
|
|
28
|
+
- 4addb72: Fix ci again but really for real this time
|
|
29
|
+
- Updated dependencies [2793a11]
|
|
30
|
+
- Updated dependencies [73f196f]
|
|
31
|
+
- Updated dependencies [2839a15]
|
|
32
|
+
- Updated dependencies [2afd4e3]
|
|
33
|
+
- @copilotkitnext/runtime@1.51.0
|
|
34
|
+
- @copilotkit/shared@1.51.0
|
|
35
|
+
- @copilotkitnext/agent@1.51.0
|
|
36
|
+
|
|
37
|
+
## 1.51.0-next.4
|
|
38
|
+
|
|
39
|
+
### Patch Changes
|
|
40
|
+
|
|
41
|
+
- Updated dependencies [2793a11]
|
|
42
|
+
- @copilotkitnext/runtime@1.51.0-next.4
|
|
43
|
+
- @copilotkit/shared@1.51.0-next.4
|
|
44
|
+
- @copilotkitnext/agent@1.51.0-next.4
|
|
45
|
+
|
|
46
|
+
## 1.51.0-next.3
|
|
47
|
+
|
|
48
|
+
### Patch Changes
|
|
49
|
+
|
|
50
|
+
- Updated dependencies [73f196f]
|
|
51
|
+
- @copilotkitnext/runtime@1.51.0-next.3
|
|
52
|
+
- @copilotkit/shared@1.51.0-next.3
|
|
53
|
+
- @copilotkitnext/agent@1.51.0-next.3
|
|
54
|
+
|
|
55
|
+
## 1.51.0-next.2
|
|
56
|
+
|
|
57
|
+
### Patch Changes
|
|
58
|
+
|
|
59
|
+
- 4addb72: Fix ci again but really for real this time
|
|
60
|
+
- Updated dependencies [2afd4e3]
|
|
61
|
+
- @copilotkit/shared@1.51.0-next.2
|
|
62
|
+
- @copilotkitnext/agent@1.51.0-next.2
|
|
63
|
+
- @copilotkitnext/runtime@1.51.0-next.2
|
|
64
|
+
|
|
65
|
+
## 1.51.0-next.1
|
|
66
|
+
|
|
67
|
+
### Patch Changes
|
|
68
|
+
|
|
69
|
+
- @copilotkit/shared@1.51.0-next.1
|
|
70
|
+
- @copilotkitnext/agent@1.51.0-next.1
|
|
71
|
+
- @copilotkitnext/runtime@1.51.0-next.1
|
|
72
|
+
|
|
73
|
+
## 1.50.2-next.0
|
|
74
|
+
|
|
75
|
+
### Patch Changes
|
|
76
|
+
|
|
77
|
+
- cf245a6: fix: restore and fix handle method in node http
|
|
78
|
+
- cf245a6: fix: use direct hono node integration on node-http integration
|
|
79
|
+
- @copilotkit/shared@1.50.2-next.0
|
|
9
80
|
|
|
10
81
|
## 1.50.1
|
|
11
82
|
|
|
@@ -522,7 +593,6 @@
|
|
|
522
593
|
### Patch Changes
|
|
523
594
|
|
|
524
595
|
- 1abcecf: - fix: add graphqlContext to constructAGUIRemoteAction for enhanced agent properties
|
|
525
|
-
|
|
526
596
|
- Updated constructAGUIRemoteAction to accept graphqlContext, allowing forwarding of properties like Authorization token to the agent.
|
|
527
597
|
- Modified setupRemoteActions to include graphqlContext in the parameters.
|
|
528
598
|
|
|
@@ -624,7 +694,6 @@
|
|
|
624
694
|
### Patch Changes
|
|
625
695
|
|
|
626
696
|
- 1abcecf: - fix: add graphqlContext to constructAGUIRemoteAction for enhanced agent properties
|
|
627
|
-
|
|
628
697
|
- Updated constructAGUIRemoteAction to accept graphqlContext, allowing forwarding of properties like Authorization token to the agent.
|
|
629
698
|
- Modified setupRemoteActions to include graphqlContext in the parameters.
|
|
630
699
|
- @copilotkit/shared@1.10.0-next.1
|
|
@@ -692,7 +761,6 @@
|
|
|
692
761
|
- remove request logging
|
|
693
762
|
- 3a7f45f: - fix: resolve agui agents only after all other endpoints
|
|
694
763
|
- fac89c2: - refactor: rename onTrace to onError throughout codebase
|
|
695
|
-
|
|
696
764
|
- Rename CopilotTraceEvent to CopilotErrorEvent and CopilotTraceHandler to CopilotErrorHandler
|
|
697
765
|
|
|
698
766
|
- 7ca7023: - feat: send node name to agui agent
|
|
@@ -793,7 +861,6 @@
|
|
|
793
861
|
### Patch Changes
|
|
794
862
|
|
|
795
863
|
- fac89c2: - refactor: rename onTrace to onError throughout codebase
|
|
796
|
-
|
|
797
864
|
- Rename CopilotTraceEvent to CopilotErrorEvent and CopilotTraceHandler to CopilotErrorHandler
|
|
798
865
|
|
|
799
866
|
- Updated dependencies [fac89c2]
|
|
@@ -1275,11 +1342,9 @@
|
|
|
1275
1342
|
- c0d3261: - full AWP support
|
|
1276
1343
|
|
|
1277
1344
|
Signed-off-by: Tyler Slaton <tyler@copilotkit.ai>
|
|
1278
|
-
|
|
1279
1345
|
- refactor: address linter issues with the new pages
|
|
1280
1346
|
|
|
1281
1347
|
Signed-off-by: Tyler Slaton <tyler@copilotkit.ai>
|
|
1282
|
-
|
|
1283
1348
|
- Merge branch 'mme/acp' into mme/mastra
|
|
1284
1349
|
- add sse example
|
|
1285
1350
|
- Create small-turkeys-agree.md
|
|
@@ -1296,17 +1361,14 @@
|
|
|
1296
1361
|
- 77a7457: - feat: Add Model Context Protocol (MCP) support
|
|
1297
1362
|
- 76d9ef9: - fix: handle langgraph client specific errors when running lgc stream
|
|
1298
1363
|
- c0d3261: - add AWP support
|
|
1299
|
-
|
|
1300
1364
|
- make it work
|
|
1301
1365
|
- update docs
|
|
1302
1366
|
- refactor: move UI files to be normal NextJS pages and update generation
|
|
1303
1367
|
|
|
1304
1368
|
Signed-off-by: Tyler Slaton <tyler@copilotkit.ai>
|
|
1305
|
-
|
|
1306
1369
|
- refactor: address linter issues with the new pages
|
|
1307
1370
|
|
|
1308
1371
|
Signed-off-by: Tyler Slaton <tyler@copilotkit.ai>
|
|
1309
|
-
|
|
1310
1372
|
- Merge branch 'mme/acp' into mme/mastra
|
|
1311
1373
|
- add sse example
|
|
1312
1374
|
|
|
@@ -1320,11 +1382,9 @@
|
|
|
1320
1382
|
- c0d3261: - full AWP support
|
|
1321
1383
|
|
|
1322
1384
|
Signed-off-by: Tyler Slaton <tyler@copilotkit.ai>
|
|
1323
|
-
|
|
1324
1385
|
- refactor: address linter issues with the new pages
|
|
1325
1386
|
|
|
1326
1387
|
Signed-off-by: Tyler Slaton <tyler@copilotkit.ai>
|
|
1327
|
-
|
|
1328
1388
|
- Merge branch 'mme/acp' into mme/mastra
|
|
1329
1389
|
- add sse example
|
|
1330
1390
|
- Create small-turkeys-agree.md
|
|
@@ -1339,17 +1399,14 @@
|
|
|
1339
1399
|
- fix missing tool call ids
|
|
1340
1400
|
|
|
1341
1401
|
- c0d3261: - add AWP support
|
|
1342
|
-
|
|
1343
1402
|
- make it work
|
|
1344
1403
|
- update docs
|
|
1345
1404
|
- refactor: move UI files to be normal NextJS pages and update generation
|
|
1346
1405
|
|
|
1347
1406
|
Signed-off-by: Tyler Slaton <tyler@copilotkit.ai>
|
|
1348
|
-
|
|
1349
1407
|
- refactor: address linter issues with the new pages
|
|
1350
1408
|
|
|
1351
1409
|
Signed-off-by: Tyler Slaton <tyler@copilotkit.ai>
|
|
1352
|
-
|
|
1353
1410
|
- Merge branch 'mme/acp' into mme/mastra
|
|
1354
1411
|
- add sse example
|
|
1355
1412
|
- @copilotkit/shared@1.8.5-next.5
|
|
@@ -2354,7 +2411,6 @@
|
|
|
2354
2411
|
- e16d95e: New prerelease
|
|
2355
2412
|
- 1721cbd: Add convertActionsToDynamicStructuredTools to sdk-js
|
|
2356
2413
|
- CopilotKit Core:
|
|
2357
|
-
|
|
2358
2414
|
- Improved error messages and overall logs
|
|
2359
2415
|
- `useCopilotAction.renderAndAwait` renamed to `.renderAndAwaitForResponse` (backwards compatible, will be deprecated in the future)
|
|
2360
2416
|
- Improved scrolling behavior. It is now possible to scroll up during LLM response generation
|
|
@@ -2362,7 +2418,6 @@
|
|
|
2362
2418
|
- Updated interfaces for better developer ergonomics
|
|
2363
2419
|
|
|
2364
2420
|
CoAgents:
|
|
2365
|
-
|
|
2366
2421
|
- Renamed `remoteActions` to `remoteEndpoints` (backwards compatible, will be deprecated in the future)
|
|
2367
2422
|
- Support for LangGraph Platform in Remote Endpoints
|
|
2368
2423
|
- LangGraph JS Support for CoAgents (locally via `langgraph dev`, `langgraph up` or deployed to LangGraph Platform)
|
|
@@ -2370,7 +2425,6 @@
|
|
|
2370
2425
|
- Enhanced state management and message handling
|
|
2371
2426
|
|
|
2372
2427
|
CopilotKid Back-end SDK:
|
|
2373
|
-
|
|
2374
2428
|
- Released a whole-new `@copilotkit/sdk-js` for building agents with LangGraph JS Support
|
|
2375
2429
|
|
|
2376
2430
|
- 8d0144f: bump
|
|
@@ -2717,7 +2771,6 @@ CopilotKid Back-end SDK:
|
|
|
2717
2771
|
### Patch Changes
|
|
2718
2772
|
|
|
2719
2773
|
- inject minified css in bundle
|
|
2720
|
-
|
|
2721
2774
|
- removes the need to import `styles.css` manually
|
|
2722
2775
|
- empty `styles.css` included in the build for backwards compatibility
|
|
2723
2776
|
- uses tsup's `injectStyles` with `postcss` to bundle and minify the CSS, then inject it as a style tag
|
|
@@ -2854,7 +2907,6 @@ CopilotKid Back-end SDK:
|
|
|
2854
2907
|
### Major Changes
|
|
2855
2908
|
|
|
2856
2909
|
- b6a4b6eb: V1.0 Release Candidate
|
|
2857
|
-
|
|
2858
2910
|
- A robust new protocol between the frontend and the Copilot Runtime
|
|
2859
2911
|
- Support for Copilot Cloud
|
|
2860
2912
|
- Generative UI
|
|
@@ -2862,7 +2914,6 @@ CopilotKid Back-end SDK:
|
|
|
2862
2914
|
- OpenAI assistant API streaming
|
|
2863
2915
|
|
|
2864
2916
|
- V1.0 Release
|
|
2865
|
-
|
|
2866
2917
|
- A robust new protocol between the frontend and the Copilot Runtime
|
|
2867
2918
|
- Support for Copilot Cloud
|
|
2868
2919
|
- Generative UI
|
|
@@ -2900,7 +2951,6 @@ CopilotKid Back-end SDK:
|
|
|
2900
2951
|
### Major Changes
|
|
2901
2952
|
|
|
2902
2953
|
- V1.0 Release Candidate
|
|
2903
|
-
|
|
2904
2954
|
- A robust new protocol between the frontend and the Copilot Runtime
|
|
2905
2955
|
- Support for Copilot Cloud
|
|
2906
2956
|
- 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);
|