@skein-js/server-kit 0.9.1 → 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/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
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';
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';
@@ -33,6 +33,11 @@ interface SkeinRuntimeCommonOptions {
33
33
  * engine's execution lock — but see the head-of-line note in docs/runs-and-redis.md if your workload
34
34
  * leans on `multitask_strategy: "enqueue"`. Ignored by the invoke-only surface, which starts no
35
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.
36
41
  */
37
42
  worker?: RunWorkerOptions;
38
43
  }
@@ -90,6 +95,20 @@ declare function resolveProtocolRuntime(options: SkeinRuntimeOptions): Promise<R
90
95
  */
91
96
  declare function resolveRunConcurrency(explicit?: number, env?: NodeJS.ProcessEnv): number;
92
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
+
93
112
  /** The checkpoint tuple `[checkpoint, metadata, parentId?]` with the blobs base64-encoded. */
94
113
  type SerializedCheckpointTuple = [string, string, string | undefined];
95
114
  /** `MemorySaver.storage` (thread → namespace → checkpointId → tuple) with blobs base64-encoded. */
@@ -259,4 +278,4 @@ declare function sendNodeError(error: unknown, res: ServerResponse, logger?: Log
259
278
  */
260
279
  declare function stripBasePath(pathname: string, basePath: string): string | null;
261
280
 
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 };
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
@@ -214,6 +214,30 @@ function resolveRunConcurrency(explicit, env = process.env) {
214
214
  return requirePositiveInteger("worker.maxConcurrency", explicit);
215
215
  }
216
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
+
217
241
  // src/resolve-runtime.ts
218
242
  async function resolveRuntimeDeps(options) {
219
243
  if (options.deps) return { deps: options.deps };
@@ -225,7 +249,8 @@ async function resolveProtocolRuntime(options) {
225
249
  const runtime = createProtocolRuntime(deps, {
226
250
  worker: {
227
251
  ...options.worker,
228
- maxConcurrency: resolveRunConcurrency(options.worker?.maxConcurrency)
252
+ maxConcurrency: resolveRunConcurrency(options.worker?.maxConcurrency),
253
+ shutdownGraceMs: resolveShutdownGraceMs(options.worker?.shutdownGraceMs)
229
254
  }
230
255
  });
231
256
  await runtime.service.assistants.registerGraphAssistants();
@@ -244,6 +269,7 @@ async function resolveProtocolRuntime(options) {
244
269
 
245
270
  // src/index.ts
246
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";
247
273
 
248
274
  // src/langgraph-import.ts
249
275
  import { readFile } from "fs/promises";
@@ -685,6 +711,7 @@ function stripBasePath(pathname, basePath) {
685
711
  }
686
712
  export {
687
713
  DEFAULT_RUN_CONCURRENCY2 as DEFAULT_RUN_CONCURRENCY,
714
+ DEFAULT_SHUTDOWN_GRACE_MS2 as DEFAULT_SHUTDOWN_GRACE_MS,
688
715
  allowedOrigin,
689
716
  applyNodeCors,
690
717
  corsFromHttpConfig,
@@ -703,6 +730,7 @@ export {
703
730
  resolveProtocolRuntime,
704
731
  resolveRunConcurrency,
705
732
  resolveRuntimeDeps,
733
+ resolveShutdownGraceMs,
706
734
  sendNodeError,
707
735
  sendNodePreflight,
708
736
  sendNodeResponse,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@skein-js/server-kit",
3
- "version": "0.9.1",
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/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"
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"