@copilotkit/runtime 0.0.0-fix-restore-handle-method-node-http-20251222114321 → 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 +10 -8
- package/dist/index.js +181 -10
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +181 -10
- package/dist/index.mjs.map +1 -1
- package/package.json +13 -10
- package/src/lib/integrations/node-http/index.ts +108 -1
- package/src/lib/integrations/node-http/request-handler.ts +111 -0
- package/src/lib/runtime/copilot-runtime.ts +3 -1
package/dist/index.mjs
CHANGED
|
@@ -15,6 +15,7 @@ import { useDeferStream } from '@graphql-yoga/plugin-defer-stream';
|
|
|
15
15
|
import createPinoLogger from 'pino';
|
|
16
16
|
import pretty from 'pino-pretty';
|
|
17
17
|
import { handle } from 'hono/vercel';
|
|
18
|
+
import { Readable } from 'stream';
|
|
18
19
|
|
|
19
20
|
var __create = Object.create;
|
|
20
21
|
var __defProp = Object.defineProperty;
|
|
@@ -64,7 +65,7 @@ var require_package = __commonJS({
|
|
|
64
65
|
publishConfig: {
|
|
65
66
|
access: "public"
|
|
66
67
|
},
|
|
67
|
-
version: "1.
|
|
68
|
+
version: "1.51.1",
|
|
68
69
|
sideEffects: false,
|
|
69
70
|
main: "./dist/index.js",
|
|
70
71
|
module: "./dist/index.mjs",
|
|
@@ -88,7 +89,7 @@ var require_package = __commonJS({
|
|
|
88
89
|
types: "./dist/index.d.ts",
|
|
89
90
|
license: "MIT",
|
|
90
91
|
scripts: {
|
|
91
|
-
build:
|
|
92
|
+
build: "pnpm run generate-graphql-schema && tsup",
|
|
92
93
|
dev: 'tsup --watch --onSuccess "pnpm run generate-graphql-schema"',
|
|
93
94
|
test: "jest --passWithNoTests",
|
|
94
95
|
"check-types": "tsc --noEmit",
|
|
@@ -98,6 +99,9 @@ var require_package = __commonJS({
|
|
|
98
99
|
"unlink:global": "pnpm unlink --global"
|
|
99
100
|
},
|
|
100
101
|
devDependencies: {
|
|
102
|
+
"@copilotkit/shared": "workspace:*",
|
|
103
|
+
"@copilotkitnext/agent": "workspace:*",
|
|
104
|
+
"@copilotkitnext/runtime": "workspace:*",
|
|
101
105
|
"@jest/globals": "^29.7.0",
|
|
102
106
|
"@swc/core": "1.5.28",
|
|
103
107
|
"@types/jest": "^29.5.12",
|
|
@@ -115,12 +119,6 @@ var require_package = __commonJS({
|
|
|
115
119
|
vitest: "^3.2.4"
|
|
116
120
|
},
|
|
117
121
|
dependencies: {
|
|
118
|
-
"@ag-ui/client": "^0.0.42",
|
|
119
|
-
"@ag-ui/core": "^0.0.42",
|
|
120
|
-
"@ag-ui/langgraph": "^0.0.20",
|
|
121
|
-
"@copilotkit/shared": "workspace:*",
|
|
122
|
-
"@copilotkitnext/agent": "0.0.33",
|
|
123
|
-
"@copilotkitnext/runtime": "0.0.33",
|
|
124
122
|
"@graphql-yoga/plugin-defer-stream": "^3.3.1",
|
|
125
123
|
"@hono/node-server": "^1.13.5",
|
|
126
124
|
"@scarf/scarf": "^1.3.0",
|
|
@@ -140,7 +138,13 @@ var require_package = __commonJS({
|
|
|
140
138
|
zod: "^3.23.3"
|
|
141
139
|
},
|
|
142
140
|
peerDependencies: {
|
|
141
|
+
"@ag-ui/client": "^0.0.42",
|
|
142
|
+
"@ag-ui/core": "^0.0.42",
|
|
143
|
+
"@ag-ui/langgraph": "^0.0.20",
|
|
143
144
|
"@anthropic-ai/sdk": "^0.57.0",
|
|
145
|
+
"@copilotkit/shared": "workspace:*",
|
|
146
|
+
"@copilotkitnext/agent": "workspace:*",
|
|
147
|
+
"@copilotkitnext/runtime": "workspace:*",
|
|
144
148
|
"@langchain/aws": ">=0.1.9",
|
|
145
149
|
"@langchain/core": ">=0.3.66",
|
|
146
150
|
"@langchain/community": ">=0.3.58",
|
|
@@ -3580,7 +3584,7 @@ var CopilotRuntime = class {
|
|
|
3580
3584
|
} : {},
|
|
3581
3585
|
"cloud.base_url": cloudBaseUrl
|
|
3582
3586
|
});
|
|
3583
|
-
(_c = params == null ? void 0 : params.beforeRequestMiddleware) == null ? void 0 : _c.call(params, hookParams);
|
|
3587
|
+
const middlewareResult = await ((_c = params == null ? void 0 : params.beforeRequestMiddleware) == null ? void 0 : _c.call(params, hookParams));
|
|
3584
3588
|
if ((_d = params == null ? void 0 : params.middleware) == null ? void 0 : _d.onBeforeRequest) {
|
|
3585
3589
|
const { request: request2, runtime, path } = hookParams;
|
|
3586
3590
|
const gqlMessages = aguiToGQL(body.messages).reduce((acc, msg) => {
|
|
@@ -3603,6 +3607,7 @@ var CopilotRuntime = class {
|
|
|
3603
3607
|
url: request2.url
|
|
3604
3608
|
});
|
|
3605
3609
|
}
|
|
3610
|
+
return middlewareResult;
|
|
3606
3611
|
};
|
|
3607
3612
|
}
|
|
3608
3613
|
createOnAfterRequestHandler(params) {
|
|
@@ -4729,6 +4734,98 @@ function copilotRuntimeNextJSAppRouterEndpoint(options) {
|
|
|
4729
4734
|
};
|
|
4730
4735
|
}
|
|
4731
4736
|
__name(copilotRuntimeNextJSAppRouterEndpoint, "copilotRuntimeNextJSAppRouterEndpoint");
|
|
4737
|
+
function readableStreamToNodeStream(webStream) {
|
|
4738
|
+
const reader = webStream.getReader();
|
|
4739
|
+
return new Readable({
|
|
4740
|
+
async read() {
|
|
4741
|
+
try {
|
|
4742
|
+
const { done, value } = await reader.read();
|
|
4743
|
+
if (done) {
|
|
4744
|
+
this.push(null);
|
|
4745
|
+
} else {
|
|
4746
|
+
this.push(Buffer.from(value));
|
|
4747
|
+
}
|
|
4748
|
+
} catch (err) {
|
|
4749
|
+
this.destroy(err);
|
|
4750
|
+
}
|
|
4751
|
+
}
|
|
4752
|
+
});
|
|
4753
|
+
}
|
|
4754
|
+
__name(readableStreamToNodeStream, "readableStreamToNodeStream");
|
|
4755
|
+
function nodeStreamToReadableStream(nodeStream) {
|
|
4756
|
+
return new ReadableStream({
|
|
4757
|
+
start(controller) {
|
|
4758
|
+
nodeStream.on("data", (chunk) => {
|
|
4759
|
+
controller.enqueue(chunk instanceof Buffer ? new Uint8Array(chunk) : chunk);
|
|
4760
|
+
});
|
|
4761
|
+
nodeStream.on("end", () => {
|
|
4762
|
+
controller.close();
|
|
4763
|
+
});
|
|
4764
|
+
nodeStream.on("error", (err) => {
|
|
4765
|
+
controller.error(err);
|
|
4766
|
+
});
|
|
4767
|
+
},
|
|
4768
|
+
cancel() {
|
|
4769
|
+
nodeStream.destroy();
|
|
4770
|
+
}
|
|
4771
|
+
});
|
|
4772
|
+
}
|
|
4773
|
+
__name(nodeStreamToReadableStream, "nodeStreamToReadableStream");
|
|
4774
|
+
function getFullUrl(req) {
|
|
4775
|
+
const path = req.url || "/";
|
|
4776
|
+
const host = req.headers["x-forwarded-host"] || req.headers.host || "localhost";
|
|
4777
|
+
const proto = req.headers["x-forwarded-proto"] || (req.socket.encrypted ? "https" : "http");
|
|
4778
|
+
return `${proto}://${host}${path}`;
|
|
4779
|
+
}
|
|
4780
|
+
__name(getFullUrl, "getFullUrl");
|
|
4781
|
+
function toHeaders(rawHeaders) {
|
|
4782
|
+
const headers = new Headers();
|
|
4783
|
+
for (const [key, value] of Object.entries(rawHeaders)) {
|
|
4784
|
+
if (value === void 0)
|
|
4785
|
+
continue;
|
|
4786
|
+
if (Array.isArray(value)) {
|
|
4787
|
+
value.forEach((entry) => headers.append(key, entry));
|
|
4788
|
+
continue;
|
|
4789
|
+
}
|
|
4790
|
+
headers.append(key, value);
|
|
4791
|
+
}
|
|
4792
|
+
return headers;
|
|
4793
|
+
}
|
|
4794
|
+
__name(toHeaders, "toHeaders");
|
|
4795
|
+
function isStreamConsumed(req) {
|
|
4796
|
+
const readableState = req._readableState;
|
|
4797
|
+
return Boolean(req.readableEnded || req.complete || (readableState == null ? void 0 : readableState.ended) || (readableState == null ? void 0 : readableState.endEmitted));
|
|
4798
|
+
}
|
|
4799
|
+
__name(isStreamConsumed, "isStreamConsumed");
|
|
4800
|
+
function synthesizeBodyFromParsedBody(parsedBody, headers) {
|
|
4801
|
+
if (parsedBody === null || parsedBody === void 0) {
|
|
4802
|
+
return {
|
|
4803
|
+
body: null
|
|
4804
|
+
};
|
|
4805
|
+
}
|
|
4806
|
+
if (parsedBody instanceof Buffer || parsedBody instanceof Uint8Array) {
|
|
4807
|
+
return {
|
|
4808
|
+
body: parsedBody
|
|
4809
|
+
};
|
|
4810
|
+
}
|
|
4811
|
+
if (typeof parsedBody === "string") {
|
|
4812
|
+
return {
|
|
4813
|
+
body: parsedBody,
|
|
4814
|
+
contentType: headers.get("content-type") ?? "text/plain"
|
|
4815
|
+
};
|
|
4816
|
+
}
|
|
4817
|
+
return {
|
|
4818
|
+
body: JSON.stringify(parsedBody),
|
|
4819
|
+
contentType: "application/json"
|
|
4820
|
+
};
|
|
4821
|
+
}
|
|
4822
|
+
__name(synthesizeBodyFromParsedBody, "synthesizeBodyFromParsedBody");
|
|
4823
|
+
function isDisturbedOrLockedError(error) {
|
|
4824
|
+
return error instanceof TypeError && typeof error.message === "string" && (error.message.includes("disturbed") || error.message.includes("locked"));
|
|
4825
|
+
}
|
|
4826
|
+
__name(isDisturbedOrLockedError, "isDisturbedOrLockedError");
|
|
4827
|
+
|
|
4828
|
+
// src/lib/integrations/node-http/index.ts
|
|
4732
4829
|
function copilotRuntimeNodeHttpEndpoint(options) {
|
|
4733
4830
|
var _a;
|
|
4734
4831
|
const commonConfig = getCommonConfig(options);
|
|
@@ -4753,7 +4850,81 @@ function copilotRuntimeNodeHttpEndpoint(options) {
|
|
|
4753
4850
|
runtime: options.runtime.instance,
|
|
4754
4851
|
basePath: options.baseUrl ?? options.endpoint
|
|
4755
4852
|
});
|
|
4756
|
-
|
|
4853
|
+
const handle2 = /* @__PURE__ */ __name(async function handler(req, res) {
|
|
4854
|
+
const url = getFullUrl(req);
|
|
4855
|
+
const hasBody = req.method !== "GET" && req.method !== "HEAD";
|
|
4856
|
+
const baseHeaders = toHeaders(req.headers);
|
|
4857
|
+
const parsedBody = req.body;
|
|
4858
|
+
const streamConsumed = isStreamConsumed(req) || parsedBody !== void 0;
|
|
4859
|
+
const canStream = hasBody && !streamConsumed;
|
|
4860
|
+
let requestBody = void 0;
|
|
4861
|
+
let useDuplex = false;
|
|
4862
|
+
if (hasBody && canStream) {
|
|
4863
|
+
requestBody = nodeStreamToReadableStream(req);
|
|
4864
|
+
useDuplex = true;
|
|
4865
|
+
}
|
|
4866
|
+
if (hasBody && streamConsumed) {
|
|
4867
|
+
if (parsedBody !== void 0) {
|
|
4868
|
+
const synthesized = synthesizeBodyFromParsedBody(parsedBody, baseHeaders);
|
|
4869
|
+
requestBody = synthesized.body ?? void 0;
|
|
4870
|
+
baseHeaders.delete("content-length");
|
|
4871
|
+
if (synthesized.contentType) {
|
|
4872
|
+
baseHeaders.set("content-type", synthesized.contentType);
|
|
4873
|
+
}
|
|
4874
|
+
logger2.debug("Request stream already consumed; using parsed req.body to rebuild request.");
|
|
4875
|
+
} else {
|
|
4876
|
+
logger2.warn("Request stream consumed with no available body; sending empty payload.");
|
|
4877
|
+
requestBody = void 0;
|
|
4878
|
+
}
|
|
4879
|
+
}
|
|
4880
|
+
const buildRequest = /* @__PURE__ */ __name((body, headers, duplex) => new Request(url, {
|
|
4881
|
+
method: req.method,
|
|
4882
|
+
headers,
|
|
4883
|
+
body,
|
|
4884
|
+
duplex: duplex ? "half" : void 0
|
|
4885
|
+
}), "buildRequest");
|
|
4886
|
+
let response;
|
|
4887
|
+
try {
|
|
4888
|
+
response = await honoApp.fetch(buildRequest(requestBody, baseHeaders, useDuplex));
|
|
4889
|
+
} catch (error) {
|
|
4890
|
+
if (isDisturbedOrLockedError(error) && hasBody) {
|
|
4891
|
+
logger2.warn("Encountered disturbed/locked request body; rebuilding request using parsed body or empty payload.");
|
|
4892
|
+
const fallbackHeaders = new Headers(baseHeaders);
|
|
4893
|
+
let fallbackBody;
|
|
4894
|
+
if (parsedBody !== void 0) {
|
|
4895
|
+
const synthesized = synthesizeBodyFromParsedBody(parsedBody, fallbackHeaders);
|
|
4896
|
+
fallbackBody = synthesized.body ?? void 0;
|
|
4897
|
+
fallbackHeaders.delete("content-length");
|
|
4898
|
+
if (synthesized.contentType) {
|
|
4899
|
+
fallbackHeaders.set("content-type", synthesized.contentType);
|
|
4900
|
+
}
|
|
4901
|
+
} else {
|
|
4902
|
+
fallbackBody = void 0;
|
|
4903
|
+
}
|
|
4904
|
+
response = await honoApp.fetch(buildRequest(fallbackBody, fallbackHeaders, false));
|
|
4905
|
+
} else {
|
|
4906
|
+
throw error;
|
|
4907
|
+
}
|
|
4908
|
+
}
|
|
4909
|
+
res.statusCode = response.status;
|
|
4910
|
+
response.headers.forEach((value, key) => {
|
|
4911
|
+
res.setHeader(key, value);
|
|
4912
|
+
});
|
|
4913
|
+
if (response.body) {
|
|
4914
|
+
readableStreamToNodeStream(response.body).pipe(res);
|
|
4915
|
+
} else {
|
|
4916
|
+
res.end();
|
|
4917
|
+
}
|
|
4918
|
+
}, "handler");
|
|
4919
|
+
return function(reqOrRequest, res) {
|
|
4920
|
+
if (reqOrRequest instanceof Request) {
|
|
4921
|
+
return honoApp.fetch(reqOrRequest);
|
|
4922
|
+
}
|
|
4923
|
+
if (!res) {
|
|
4924
|
+
throw new TypeError("ServerResponse is required for Node HTTP requests");
|
|
4925
|
+
}
|
|
4926
|
+
return handle2(reqOrRequest, res);
|
|
4927
|
+
};
|
|
4757
4928
|
}
|
|
4758
4929
|
__name(copilotRuntimeNodeHttpEndpoint, "copilotRuntimeNodeHttpEndpoint");
|
|
4759
4930
|
|