@skein-js/server-kit 0.9.0 → 0.10.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 CHANGED
@@ -75,7 +75,14 @@ Pass `overrides` to swap in production drivers or an auth engine while keeping t
75
75
  graph→`GraphResolver` helpers.
76
76
  - **`resolveProtocolRuntime(options): Promise<ResolvedProtocolRuntime>`** — turn a
77
77
  `{ config } | { deps }` bag (`SkeinRuntimeOptions`) into a live runtime (assistants seeded, worker
78
- started) — the step every adapter runs before mounting routes.
78
+ started) — the step every adapter runs before mounting routes. `options.worker`
79
+ (`RunWorkerOptions`) tunes the background worker; `worker.maxConcurrency` is how many queued runs
80
+ run at once.
81
+ - **`resolveRunConcurrency(explicit?, env?): number`** — the one precedence chain behind
82
+ `worker.maxConcurrency`: explicit value → `SKEIN_RUN_CONCURRENCY` → `N_JOBS_PER_WORKER` →
83
+ `DEFAULT_RUN_CONCURRENCY` (10, matching the LangGraph CLI). The environment is validated even when
84
+ an explicit value is given, so the two sources can't silently disagree. `skein dev`/`start` use it
85
+ to resolve the number they print in the startup banner.
79
86
  - **`loadInMemoryRuntime` / `loadReloadableInMemoryRuntime`** — assemble a `ProtocolDeps` from a
80
87
  `langgraph.json` using in-process drivers. The reloadable variant adds `reloadGraphs` /
81
88
  `snapshotState` / `hydrateState` (what powers `skein dev`'s hot reload + cross-restart persistence).
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { ProtocolRuntime, ProtocolDeps, Logger, GraphResolver, ProtocolResponse } from '@skein-js/agent-protocol';
2
- export { CompiledGraphFactory, GraphResolver, ProtocolDeps, ResolvedGraph } from '@skein-js/agent-protocol';
1
+ import { ProtocolRuntime, ProtocolDeps, Logger, RunWorkerOptions, GraphResolver, ProtocolResponse } from '@skein-js/agent-protocol';
2
+ export { CompiledGraphFactory, DEFAULT_RUN_CONCURRENCY, DEFAULT_SHUTDOWN_GRACE_MS, GraphResolver, ProtocolDeps, ResolvedGraph, RunWorkerOptions } from '@skein-js/agent-protocol';
3
3
  import { ModuleImporter, GraphSchemas } from '@skein-js/config';
4
4
  import { CorsOptions } from 'cors';
5
5
  export { CorsOptions } from 'cors';
@@ -23,6 +23,23 @@ interface SkeinRuntimeCommonOptions {
23
23
  * server down.
24
24
  */
25
25
  warm?: boolean;
26
+ /**
27
+ * Background run-worker tuning. `maxConcurrency` is how many **queued** runs this instance executes
28
+ * at once (default `DEFAULT_RUN_CONCURRENCY`, matching the LangGraph CLI); omit it and skein reads
29
+ * `SKEIN_RUN_CONCURRENCY`, else the LangGraph-compatible `N_JOBS_PER_WORKER`. An explicit value
30
+ * wins, but the environment is still validated so the two sources can't silently disagree.
31
+ *
32
+ * Raising it never weakens per-thread ordering — two runs on one thread are still serialized by the
33
+ * engine's execution lock — but see the head-of-line note in docs/runs-and-redis.md if your workload
34
+ * leans on `multitask_strategy: "enqueue"`. Ignored by the invoke-only surface, which starts no
35
+ * worker.
36
+ *
37
+ * `shutdownGraceMs` is how long `worker.stop()` lets in-flight runs finish before aborting them
38
+ * (default `DEFAULT_SHUTDOWN_GRACE_MS`); omit it and skein reads `SKEIN_SHUTDOWN_GRACE_MS`, with
39
+ * the same explicit-wins-but-still-validated rule. Whatever forces the process to exit must wait
40
+ * longer than this, or the abort step never runs — see docs/deploy.md.
41
+ */
42
+ worker?: RunWorkerOptions;
26
43
  }
27
44
  /** Either point at a `langgraph.json` (in-memory runtime) or inject a ready `ProtocolDeps`. */
28
45
  type SkeinRuntimeOptions = SkeinRuntimeCommonOptions & ({
@@ -66,6 +83,32 @@ declare function resolveRuntimeDeps(options: SkeinRuntimeOptions): Promise<Resol
66
83
  */
67
84
  declare function resolveProtocolRuntime(options: SkeinRuntimeOptions): Promise<ResolvedProtocolRuntime>;
68
85
 
86
+ /**
87
+ * The one precedence chain for background-run concurrency: an explicit value (a `worker.maxConcurrency`
88
+ * option, or the CLI's `--concurrency` / `-n`) wins, else `SKEIN_RUN_CONCURRENCY`, else
89
+ * `N_JOBS_PER_WORKER`, else {@link DEFAULT_RUN_CONCURRENCY}. The environment is read and validated
90
+ * even when `explicit` is given, so a bad `SKEIN_RUN_CONCURRENCY` can't sit unnoticed in a deployment
91
+ * that also passes the option.
92
+ *
93
+ * `env` is injected (defaulting to `process.env`) so callers — and tests — can resolve against an
94
+ * environment they control.
95
+ */
96
+ declare function resolveRunConcurrency(explicit?: number, env?: NodeJS.ProcessEnv): number;
97
+
98
+ /**
99
+ * The one precedence chain for the shutdown drain window: an explicit `worker.shutdownGraceMs` wins,
100
+ * else `SKEIN_SHUTDOWN_GRACE_MS`, else {@link DEFAULT_SHUTDOWN_GRACE_MS}. The environment is read and
101
+ * validated even when `explicit` is given, so a bad value can't sit unnoticed in a deployment that
102
+ * also passes the option.
103
+ *
104
+ * Zero is allowed and means "abort in-flight runs immediately" — a legitimate choice for a fleet that
105
+ * relies on queue redelivery instead of draining.
106
+ *
107
+ * `env` is injected (defaulting to `process.env`) so callers — and tests — can resolve against an
108
+ * environment they control.
109
+ */
110
+ declare function resolveShutdownGraceMs(explicit?: number, env?: NodeJS.ProcessEnv): number;
111
+
69
112
  /** The checkpoint tuple `[checkpoint, metadata, parentId?]` with the blobs base64-encoded. */
70
113
  type SerializedCheckpointTuple = [string, string, string | undefined];
71
114
  /** `MemorySaver.storage` (thread → namespace → checkpointId → tuple) with blobs base64-encoded. */
@@ -235,4 +278,4 @@ declare function sendNodeError(error: unknown, res: ServerResponse, logger?: Log
235
278
  */
236
279
  declare function stripBasePath(pathname: string, basePath: string): string | null;
237
280
 
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 };
281
+ 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, resolveRunConcurrency, resolveRuntimeDeps, resolveShutdownGraceMs, sendNodeError, sendNodePreflight, sendNodeResponse, stripBasePath, toCorsOptions };
package/dist/index.js CHANGED
@@ -189,6 +189,55 @@ async function loadReloadableInMemoryRuntime(configPath, importModule, staticSch
189
189
  };
190
190
  }
191
191
 
192
+ // src/run-concurrency.ts
193
+ import { DEFAULT_RUN_CONCURRENCY } from "@skein-js/agent-protocol";
194
+ import { SkeinConfigError } from "@skein-js/config";
195
+ var CONCURRENCY_ENV_VARS = ["SKEIN_RUN_CONCURRENCY", "N_JOBS_PER_WORKER"];
196
+ function requirePositiveInteger(source, raw) {
197
+ const parsed = Number(raw);
198
+ if (!Number.isInteger(parsed) || parsed <= 0) {
199
+ throw new SkeinConfigError(`${source} must be a positive integer (got "${String(raw)}").`);
200
+ }
201
+ return parsed;
202
+ }
203
+ function runConcurrencyFromEnv(env) {
204
+ for (const name of CONCURRENCY_ENV_VARS) {
205
+ const raw = env[name];
206
+ if (raw === void 0 || raw.trim() === "") continue;
207
+ return requirePositiveInteger(name, raw);
208
+ }
209
+ return void 0;
210
+ }
211
+ function resolveRunConcurrency(explicit, env = process.env) {
212
+ const fromEnv = runConcurrencyFromEnv(env);
213
+ if (explicit === void 0) return fromEnv ?? DEFAULT_RUN_CONCURRENCY;
214
+ return requirePositiveInteger("worker.maxConcurrency", explicit);
215
+ }
216
+
217
+ // src/shutdown-grace.ts
218
+ import { DEFAULT_SHUTDOWN_GRACE_MS } from "@skein-js/agent-protocol";
219
+ import { SkeinConfigError as SkeinConfigError2 } from "@skein-js/config";
220
+ var SHUTDOWN_GRACE_ENV_VAR = "SKEIN_SHUTDOWN_GRACE_MS";
221
+ function requireNonNegativeInteger(source, raw) {
222
+ const parsed = Number(raw);
223
+ if (!Number.isInteger(parsed) || parsed < 0) {
224
+ throw new SkeinConfigError2(
225
+ `${source} must be a non-negative integer in milliseconds (got "${String(raw)}").`
226
+ );
227
+ }
228
+ return parsed;
229
+ }
230
+ function shutdownGraceFromEnv(env) {
231
+ const raw = env[SHUTDOWN_GRACE_ENV_VAR];
232
+ if (raw === void 0 || raw.trim() === "") return void 0;
233
+ return requireNonNegativeInteger(SHUTDOWN_GRACE_ENV_VAR, raw);
234
+ }
235
+ function resolveShutdownGraceMs(explicit, env = process.env) {
236
+ const fromEnv = shutdownGraceFromEnv(env);
237
+ if (explicit === void 0) return fromEnv ?? DEFAULT_SHUTDOWN_GRACE_MS;
238
+ return requireNonNegativeInteger("worker.shutdownGraceMs", explicit);
239
+ }
240
+
192
241
  // src/resolve-runtime.ts
193
242
  async function resolveRuntimeDeps(options) {
194
243
  if (options.deps) return { deps: options.deps };
@@ -197,7 +246,13 @@ async function resolveRuntimeDeps(options) {
197
246
  }
198
247
  async function resolveProtocolRuntime(options) {
199
248
  const { deps, cors: corsFromConfig } = await resolveRuntimeDeps(options);
200
- const runtime = createProtocolRuntime(deps);
249
+ const runtime = createProtocolRuntime(deps, {
250
+ worker: {
251
+ ...options.worker,
252
+ maxConcurrency: resolveRunConcurrency(options.worker?.maxConcurrency),
253
+ shutdownGraceMs: resolveShutdownGraceMs(options.worker?.shutdownGraceMs)
254
+ }
255
+ });
201
256
  await runtime.service.assistants.registerGraphAssistants();
202
257
  if (options.warm) {
203
258
  await Promise.all(
@@ -212,6 +267,10 @@ async function resolveProtocolRuntime(options) {
212
267
  return { runtime, cors: corsFromConfig };
213
268
  }
214
269
 
270
+ // src/index.ts
271
+ import { DEFAULT_RUN_CONCURRENCY as DEFAULT_RUN_CONCURRENCY2 } from "@skein-js/agent-protocol";
272
+ import { DEFAULT_SHUTDOWN_GRACE_MS as DEFAULT_SHUTDOWN_GRACE_MS2 } from "@skein-js/agent-protocol";
273
+
215
274
  // src/langgraph-import.ts
216
275
  import { readFile } from "fs/promises";
217
276
  import path from "path";
@@ -651,6 +710,8 @@ function stripBasePath(pathname, basePath) {
651
710
  return null;
652
711
  }
653
712
  export {
713
+ DEFAULT_RUN_CONCURRENCY2 as DEFAULT_RUN_CONCURRENCY,
714
+ DEFAULT_SHUTDOWN_GRACE_MS2 as DEFAULT_SHUTDOWN_GRACE_MS,
654
715
  allowedOrigin,
655
716
  applyNodeCors,
656
717
  corsFromHttpConfig,
@@ -667,7 +728,9 @@ export {
667
728
  normalizeEmbeddableGraphs,
668
729
  readLanggraphDevState,
669
730
  resolveProtocolRuntime,
731
+ resolveRunConcurrency,
670
732
  resolveRuntimeDeps,
733
+ resolveShutdownGraceMs,
671
734
  sendNodeError,
672
735
  sendNodePreflight,
673
736
  sendNodeResponse,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@skein-js/server-kit",
3
- "version": "0.9.0",
3
+ "version": "0.10.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>",
@@ -27,7 +27,8 @@
27
27
  "exports": {
28
28
  ".": {
29
29
  "types": "./dist/index.d.ts",
30
- "import": "./dist/index.js"
30
+ "import": "./dist/index.js",
31
+ "default": "./dist/index.js"
31
32
  }
32
33
  },
33
34
  "files": [
@@ -43,10 +44,10 @@
43
44
  "cors": "^2.8.5",
44
45
  "superjson": "^2.2.6",
45
46
  "zod": "^3.25.76",
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"
47
+ "@skein-js/agent-protocol": "0.10.0",
48
+ "@skein-js/config": "0.10.0",
49
+ "@skein-js/storage-memory": "0.10.0",
50
+ "@skein-js/core": "0.10.0"
50
51
  },
51
52
  "peerDependencies": {
52
53
  "@langchain/langgraph": "^1.4.0"