@skein-js/fetch 0.20.0 → 0.23.0

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 (2) hide show
  1. package/dist/index.js +25 -1
  2. package/package.json +6 -5
package/dist/index.js CHANGED
@@ -9,7 +9,8 @@ import {
9
9
  corsPreflightHeaders,
10
10
  corsResponseHeaders,
11
11
  resolveProtocolRuntime,
12
- stripBasePath
12
+ stripBasePath,
13
+ withNativePath
13
14
  } from "@skein-js/server-kit";
14
15
  var DEFAULT_MAX_BODY_BYTES = 100 * 1024;
15
16
  function toQuery(url) {
@@ -169,6 +170,28 @@ function createFetchHandler(resolved, options) {
169
170
  });
170
171
  }
171
172
  const extraHeaders = cors ? corsResponseHeaders(request.headers.get("origin") ?? void 0, cors) : {};
173
+ const nativeMatcher = resolved.runtime.handleRequest?.[/* @__PURE__ */ Symbol.for("@skein-js/native-request-matcher")];
174
+ if (resolved.runtime.handleRequest && nativeMatcher?.(request.method, `${url.origin}${skeinPathname}${url.search}`) !== false) {
175
+ const nativeRequest = withNativePath(request, skeinPathname);
176
+ let native;
177
+ try {
178
+ native = await resolved.runtime.handleRequest?.(nativeRequest);
179
+ if (native) {
180
+ const headers = new Headers(native.headers);
181
+ for (const [key, value] of Object.entries(extraHeaders)) headers.set(key, value);
182
+ return new Response(native.body, {
183
+ status: native.status,
184
+ statusText: native.statusText,
185
+ headers
186
+ });
187
+ }
188
+ } catch (error) {
189
+ void request.body?.cancel().catch(() => void 0);
190
+ return errorResponse(error, extraHeaders, resolved.logger);
191
+ } finally {
192
+ void (native ? request : nativeRequest).body?.cancel().catch(() => void 0);
193
+ }
194
+ }
172
195
  const match = matchRoute(request.method, skeinPathname);
173
196
  if (!match) {
174
197
  return new Response(JSON.stringify({ status: 404, message: "Not Found" }), {
@@ -186,6 +209,7 @@ function createFetchHandler(resolved, options) {
186
209
  match.binding.retainRawBody ?? false
187
210
  );
188
211
  const invoke = resolved.runtime.handlers[match.binding.handler];
212
+ if (!invoke) return new Response("Not found", { status: 404, headers: extraHeaders });
189
213
  const response = await invoke(
190
214
  match.binding.foldThreadIdIntoBody ? copyThreadIdIntoBody(protocolRequest) : protocolRequest
191
215
  );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@skein-js/fetch",
3
- "version": "0.20.0",
3
+ "version": "0.23.0",
4
4
  "description": "Runtime-neutral Fetch adapter for serving the Skein Agent Protocol on Bun and Deno.",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Maina Wycliffe <wmmaina7@gmail.com>",
@@ -40,15 +40,16 @@
40
40
  ],
41
41
  "sideEffects": false,
42
42
  "dependencies": {
43
- "@skein-js/agent-protocol": "0.20.0",
44
- "@skein-js/server-kit": "0.20.0",
45
- "@skein-js/core": "0.20.0"
43
+ "@skein-js/agent-protocol": "0.23.0",
44
+ "@skein-js/server-kit": "0.23.0",
45
+ "@skein-js/core": "0.23.0"
46
46
  },
47
47
  "peerDependencies": {
48
48
  "@langchain/langgraph": "^1.4.0"
49
49
  },
50
50
  "devDependencies": {
51
- "@langchain/langgraph": "^1.4.0"
51
+ "@langchain/langgraph": "^1.4.0",
52
+ "@skein-js/test-support": "^0.23.0"
52
53
  },
53
54
  "publishConfig": {
54
55
  "access": "public"