@skein-js/server-kit 0.9.0 → 0.9.1

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, 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,18 @@ 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
+ worker?: RunWorkerOptions;
26
38
  }
27
39
  /** Either point at a `langgraph.json` (in-memory runtime) or inject a ready `ProtocolDeps`. */
28
40
  type SkeinRuntimeOptions = SkeinRuntimeCommonOptions & ({
@@ -66,6 +78,18 @@ declare function resolveRuntimeDeps(options: SkeinRuntimeOptions): Promise<Resol
66
78
  */
67
79
  declare function resolveProtocolRuntime(options: SkeinRuntimeOptions): Promise<ResolvedProtocolRuntime>;
68
80
 
81
+ /**
82
+ * The one precedence chain for background-run concurrency: an explicit value (a `worker.maxConcurrency`
83
+ * option, or the CLI's `--concurrency` / `-n`) wins, else `SKEIN_RUN_CONCURRENCY`, else
84
+ * `N_JOBS_PER_WORKER`, else {@link DEFAULT_RUN_CONCURRENCY}. The environment is read and validated
85
+ * even when `explicit` is given, so a bad `SKEIN_RUN_CONCURRENCY` can't sit unnoticed in a deployment
86
+ * that also passes the option.
87
+ *
88
+ * `env` is injected (defaulting to `process.env`) so callers — and tests — can resolve against an
89
+ * environment they control.
90
+ */
91
+ declare function resolveRunConcurrency(explicit?: number, env?: NodeJS.ProcessEnv): number;
92
+
69
93
  /** The checkpoint tuple `[checkpoint, metadata, parentId?]` with the blobs base64-encoded. */
70
94
  type SerializedCheckpointTuple = [string, string, string | undefined];
71
95
  /** `MemorySaver.storage` (thread → namespace → checkpointId → tuple) with blobs base64-encoded. */
@@ -235,4 +259,4 @@ declare function sendNodeError(error: unknown, res: ServerResponse, logger?: Log
235
259
  */
236
260
  declare function stripBasePath(pathname: string, basePath: string): string | null;
237
261
 
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 };
262
+ 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, sendNodeError, sendNodePreflight, sendNodeResponse, stripBasePath, toCorsOptions };
package/dist/index.js CHANGED
@@ -189,6 +189,31 @@ 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
+
192
217
  // src/resolve-runtime.ts
193
218
  async function resolveRuntimeDeps(options) {
194
219
  if (options.deps) return { deps: options.deps };
@@ -197,7 +222,12 @@ async function resolveRuntimeDeps(options) {
197
222
  }
198
223
  async function resolveProtocolRuntime(options) {
199
224
  const { deps, cors: corsFromConfig } = await resolveRuntimeDeps(options);
200
- const runtime = createProtocolRuntime(deps);
225
+ const runtime = createProtocolRuntime(deps, {
226
+ worker: {
227
+ ...options.worker,
228
+ maxConcurrency: resolveRunConcurrency(options.worker?.maxConcurrency)
229
+ }
230
+ });
201
231
  await runtime.service.assistants.registerGraphAssistants();
202
232
  if (options.warm) {
203
233
  await Promise.all(
@@ -212,6 +242,9 @@ async function resolveProtocolRuntime(options) {
212
242
  return { runtime, cors: corsFromConfig };
213
243
  }
214
244
 
245
+ // src/index.ts
246
+ import { DEFAULT_RUN_CONCURRENCY as DEFAULT_RUN_CONCURRENCY2 } from "@skein-js/agent-protocol";
247
+
215
248
  // src/langgraph-import.ts
216
249
  import { readFile } from "fs/promises";
217
250
  import path from "path";
@@ -651,6 +684,7 @@ function stripBasePath(pathname, basePath) {
651
684
  return null;
652
685
  }
653
686
  export {
687
+ DEFAULT_RUN_CONCURRENCY2 as DEFAULT_RUN_CONCURRENCY,
654
688
  allowedOrigin,
655
689
  applyNodeCors,
656
690
  corsFromHttpConfig,
@@ -667,6 +701,7 @@ export {
667
701
  normalizeEmbeddableGraphs,
668
702
  readLanggraphDevState,
669
703
  resolveProtocolRuntime,
704
+ resolveRunConcurrency,
670
705
  resolveRuntimeDeps,
671
706
  sendNodeError,
672
707
  sendNodePreflight,
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.9.1",
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.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"
46
+ "@skein-js/agent-protocol": "0.9.1",
47
+ "@skein-js/core": "0.9.1",
48
+ "@skein-js/storage-memory": "0.9.1",
49
+ "@skein-js/config": "0.9.1"
50
50
  },
51
51
  "peerDependencies": {
52
52
  "@langchain/langgraph": "^1.4.0"