@skein-js/server-kit 0.8.0 → 0.9.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.
- package/README.md +6 -0
- package/dist/index.d.ts +23 -2
- package/dist/index.js +22 -9
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -32,6 +32,8 @@ handler table.
|
|
|
32
32
|
(an unset origin resolves to `*`, never a reflected origin, so it can't pair with credentials).
|
|
33
33
|
- **Node transport** — `sendNodeResponse` / `sendNodeError`: serialize a `ProtocolResponse` (JSON / 204
|
|
34
34
|
/ SSE) onto a Node `ServerResponse`, shared by the NestJS + Next.js Pages Router adapters.
|
|
35
|
+
- **Mount prefix** — `stripBasePath`: strip the path an adapter is mounted under before matching the
|
|
36
|
+
route table, for adapters that mount a catch-all and match by hand (NestJS, Next.js).
|
|
35
37
|
|
|
36
38
|
> The route table itself (`skeinRoutes`) is **not** here — it lives with the engine in
|
|
37
39
|
> [`@skein-js/agent-protocol`](../agent-protocol), since it references the handler names. Adapters
|
|
@@ -85,6 +87,10 @@ Pass `overrides` to swap in production drivers or an auth engine while keeping t
|
|
|
85
87
|
derive CORS headers for adapters without a CORS middleware of their own.
|
|
86
88
|
- **Node transport** — `sendNodeResponse` / `sendNodeError` serialize a `ProtocolResponse`
|
|
87
89
|
(JSON / 204 / SSE) onto a Node `ServerResponse`, shared by the NestJS + Next.js Pages Router adapters.
|
|
90
|
+
- **`stripBasePath(pathname, basePath): string | null`** — the pathname relative to a mount prefix, or
|
|
91
|
+
`null` when the path is not under it (the caller passes those through untouched). The prefix may be
|
|
92
|
+
written any way the host wrote it (`api`, `/api`, `/api/`); an empty one passes everything through.
|
|
93
|
+
Needed only by adapters that mount a catch-all — Express/Fastify get this from their router.
|
|
88
94
|
|
|
89
95
|
## Learn more
|
|
90
96
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ProtocolRuntime,
|
|
1
|
+
import { ProtocolRuntime, ProtocolDeps, Logger, GraphResolver, ProtocolResponse } from '@skein-js/agent-protocol';
|
|
2
2
|
export { CompiledGraphFactory, GraphResolver, ProtocolDeps, ResolvedGraph } from '@skein-js/agent-protocol';
|
|
3
3
|
import { ModuleImporter, GraphSchemas } from '@skein-js/config';
|
|
4
4
|
import { CorsOptions } from 'cors';
|
|
@@ -44,6 +44,20 @@ interface ResolvedProtocolRuntime {
|
|
|
44
44
|
/** CORS mapped from the config's `http.cors`, or `undefined` for the injected-`deps` path. */
|
|
45
45
|
cors?: CorsOptions;
|
|
46
46
|
}
|
|
47
|
+
/** Just the dependencies behind a `{ config } | { deps }` bag — no runtime, no worker. */
|
|
48
|
+
interface ResolvedRuntimeDeps {
|
|
49
|
+
deps: ProtocolDeps;
|
|
50
|
+
/** CORS mapped from the config's `http.cors`, or `undefined` for the injected-`deps` path. */
|
|
51
|
+
cors?: CorsOptions;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Resolve the `{ config } | { deps }` seam down to a `ProtocolDeps` — injected as-is, or fresh
|
|
55
|
+
* in-memory drivers loaded from a `langgraph.json`. This is the half of
|
|
56
|
+
* {@link resolveProtocolRuntime} that stops short of building the engine, so the simplified invoke
|
|
57
|
+
* surface (which needs only graphs + store) doesn't seed assistants or start a run worker it will
|
|
58
|
+
* never use.
|
|
59
|
+
*/
|
|
60
|
+
declare function resolveRuntimeDeps(options: SkeinRuntimeOptions): Promise<ResolvedRuntimeDeps>;
|
|
47
61
|
/**
|
|
48
62
|
* Build a `ProtocolRuntime` from adapter options: resolve `deps` (injected, or fresh in-memory
|
|
49
63
|
* drivers from a `langgraph.json`), seed one assistant per declared graph, optionally warm the
|
|
@@ -214,4 +228,11 @@ declare function sendNodeResponse(response: ProtocolResponse, res: ServerRespons
|
|
|
214
228
|
/** Serialize a caught error onto the Node `res`, using the protocol status when the error carries one. */
|
|
215
229
|
declare function sendNodeError(error: unknown, res: ServerResponse, logger?: Logger, adapterName?: string): void;
|
|
216
230
|
|
|
217
|
-
|
|
231
|
+
/**
|
|
232
|
+
* The pathname relative to `basePath`, or `null` when the path is not under the mount — which the
|
|
233
|
+
* caller should treat as "not ours" and pass through untouched, so the host app's own routes still
|
|
234
|
+
* resolve. An empty (or `/`) base path passes the pathname through unchanged.
|
|
235
|
+
*/
|
|
236
|
+
declare function stripBasePath(pathname: string, basePath: string): string | null;
|
|
237
|
+
|
|
238
|
+
export { type CorsSetting, type DevStateCounts, type DevStateSnapshot, type EmbeddableGraph, type InMemoryRuntimeConfig, type LanggraphCorsConfig, type ReloadableInMemoryRuntime, type ResolvedProtocolRuntime, type ResolvedRuntimeDeps, type SkeinRuntimeCommonOptions, type SkeinRuntimeOptions, allowedOrigin, applyNodeCors, corsFromHttpConfig, corsPreflightHeaders, corsResponseHeaders, createInMemoryDeps, describeSnapshot, embedInMemoryGraphs, graphMapToResolver, joinList, loadInMemoryRuntime, loadReloadableInMemoryRuntime, loadSnapshotIntoStore, normalizeEmbeddableGraphs, readLanggraphDevState, resolveProtocolRuntime, resolveRuntimeDeps, sendNodeError, sendNodePreflight, sendNodeResponse, stripBasePath, toCorsOptions };
|
package/dist/index.js
CHANGED
|
@@ -190,16 +190,13 @@ async function loadReloadableInMemoryRuntime(configPath, importModule, staticSch
|
|
|
190
190
|
}
|
|
191
191
|
|
|
192
192
|
// src/resolve-runtime.ts
|
|
193
|
+
async function resolveRuntimeDeps(options) {
|
|
194
|
+
if (options.deps) return { deps: options.deps };
|
|
195
|
+
const loaded = await loadInMemoryRuntime(options.config, options.importModule);
|
|
196
|
+
return { deps: loaded.deps, cors: loaded.cors };
|
|
197
|
+
}
|
|
193
198
|
async function resolveProtocolRuntime(options) {
|
|
194
|
-
|
|
195
|
-
let corsFromConfig;
|
|
196
|
-
if (options.deps) {
|
|
197
|
-
deps = options.deps;
|
|
198
|
-
} else {
|
|
199
|
-
const loaded = await loadInMemoryRuntime(options.config, options.importModule);
|
|
200
|
-
deps = loaded.deps;
|
|
201
|
-
corsFromConfig = loaded.cors;
|
|
202
|
-
}
|
|
199
|
+
const { deps, cors: corsFromConfig } = await resolveRuntimeDeps(options);
|
|
203
200
|
const runtime = createProtocolRuntime(deps);
|
|
204
201
|
await runtime.service.assistants.registerGraphAssistants();
|
|
205
202
|
if (options.warm) {
|
|
@@ -639,6 +636,20 @@ function sendNodeError(error, res, logger, adapterName = "skein") {
|
|
|
639
636
|
res.writeHead(500, { "content-type": "application/json" });
|
|
640
637
|
res.end(JSON.stringify({ status: 500, message: "Internal Server Error" }));
|
|
641
638
|
}
|
|
639
|
+
|
|
640
|
+
// src/base-path.ts
|
|
641
|
+
function normalizeBasePath(basePath) {
|
|
642
|
+
if (basePath === "" || basePath === "/") return "";
|
|
643
|
+
const withLeadingSlash = basePath.startsWith("/") ? basePath : `/${basePath}`;
|
|
644
|
+
return withLeadingSlash.replace(/\/+$/, "");
|
|
645
|
+
}
|
|
646
|
+
function stripBasePath(pathname, basePath) {
|
|
647
|
+
const prefix = normalizeBasePath(basePath);
|
|
648
|
+
if (prefix === "") return pathname;
|
|
649
|
+
if (pathname === prefix) return "/";
|
|
650
|
+
if (pathname.startsWith(`${prefix}/`)) return pathname.slice(prefix.length);
|
|
651
|
+
return null;
|
|
652
|
+
}
|
|
642
653
|
export {
|
|
643
654
|
allowedOrigin,
|
|
644
655
|
applyNodeCors,
|
|
@@ -656,8 +667,10 @@ export {
|
|
|
656
667
|
normalizeEmbeddableGraphs,
|
|
657
668
|
readLanggraphDevState,
|
|
658
669
|
resolveProtocolRuntime,
|
|
670
|
+
resolveRuntimeDeps,
|
|
659
671
|
sendNodeError,
|
|
660
672
|
sendNodePreflight,
|
|
661
673
|
sendNodeResponse,
|
|
674
|
+
stripBasePath,
|
|
662
675
|
toCorsOptions
|
|
663
676
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@skein-js/server-kit",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"description": "Shared, framework-agnostic building blocks for skein-js HTTP adapters — in-memory dev runtime, LangGraph dev-state import, and langgraph.json CORS mapping.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "Maina Wycliffe <wmmaina7@gmail.com>",
|
|
@@ -43,10 +43,10 @@
|
|
|
43
43
|
"cors": "^2.8.5",
|
|
44
44
|
"superjson": "^2.2.6",
|
|
45
45
|
"zod": "^3.25.76",
|
|
46
|
-
"@skein-js/core": "0.
|
|
47
|
-
"@skein-js/
|
|
48
|
-
"@skein-js/
|
|
49
|
-
"@skein-js/storage-memory": "0.
|
|
46
|
+
"@skein-js/core": "0.9.0",
|
|
47
|
+
"@skein-js/agent-protocol": "0.9.0",
|
|
48
|
+
"@skein-js/config": "0.9.0",
|
|
49
|
+
"@skein-js/storage-memory": "0.9.0"
|
|
50
50
|
},
|
|
51
51
|
"peerDependencies": {
|
|
52
52
|
"@langchain/langgraph": "^1.4.0"
|