@crewhaus/runtime-core 0.3.2 → 0.4.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.
@@ -0,0 +1,14 @@
1
+ import type { KVLike, WorkerPlatform } from "@crewhaus/worker-runtime";
2
+ /**
3
+ * Build a Node-backed {@link WorkerPlatform}. `overrides` win over the
4
+ * defaults (tests inject a fixed clock / deterministic id / scripted fetch;
5
+ * production callers may pass a durable `storage`).
6
+ */
7
+ export declare function createNodeWorkerPlatform(overrides?: Partial<WorkerPlatform>): WorkerPlatform;
8
+ /**
9
+ * A process-local {@link KVLike} backed by a `Map` — a convenience for tests,
10
+ * single-process daemons, and the Node platform's optional `storage` slot.
11
+ * TTL is honoured against `Date.now()`; it is NOT durable across restarts (a
12
+ * real deployment wires Cloudflare KV, a Durable Object, or a database here).
13
+ */
14
+ export declare function createInMemoryKV(): KVLike;
@@ -0,0 +1,65 @@
1
+ /**
2
+ * runtime-core — the NODE {@link WorkerPlatform} implementation.
3
+ *
4
+ * G12 splits the agent loop into a platform-neutral core
5
+ * (`@crewhaus/worker-runtime`, which imports no `node:*`) and the host
6
+ * services that surround it. On the edge those services are a stateless
7
+ * `WorkerPlatform` the cf-worker bundle constructs; on Node THIS module is the
8
+ * platform — `Date.now()` for the clock, `node:crypto` for ids, the global
9
+ * `fetch`, and (optionally) an in-memory KV — so the same
10
+ * {@link runWorkerLoop} core runs unchanged in a Node process.
11
+ *
12
+ * runtime-core keeps its own richer node-coupled services (event log, session
13
+ * store, compaction, recovery, audit sinks) around `runChatLoop`; this
14
+ * platform is the seam through which a Node caller drives the *shared* core
15
+ * (e.g. to exercise the exact loop a cf-worker will run) without reaching for
16
+ * the edge globals directly.
17
+ */
18
+ import { randomUUID } from "node:crypto";
19
+ /**
20
+ * Build a Node-backed {@link WorkerPlatform}. `overrides` win over the
21
+ * defaults (tests inject a fixed clock / deterministic id / scripted fetch;
22
+ * production callers may pass a durable `storage`).
23
+ */
24
+ export function createNodeWorkerPlatform(overrides = {}) {
25
+ return {
26
+ now: () => Date.now(),
27
+ randomId: () => randomUUID(),
28
+ // Bind to globalThis so the reference stays valid when destructured, and
29
+ // undici's `fetch` keeps its receiver.
30
+ fetch: globalThis.fetch.bind(globalThis),
31
+ ...overrides,
32
+ };
33
+ }
34
+ /**
35
+ * A process-local {@link KVLike} backed by a `Map` — a convenience for tests,
36
+ * single-process daemons, and the Node platform's optional `storage` slot.
37
+ * TTL is honoured against `Date.now()`; it is NOT durable across restarts (a
38
+ * real deployment wires Cloudflare KV, a Durable Object, or a database here).
39
+ */
40
+ export function createInMemoryKV() {
41
+ const store = new Map();
42
+ return {
43
+ async get(key) {
44
+ const entry = store.get(key);
45
+ if (entry === undefined)
46
+ return null;
47
+ if (entry.expiresAt !== undefined && entry.expiresAt <= Date.now()) {
48
+ store.delete(key);
49
+ return null;
50
+ }
51
+ return entry.value;
52
+ },
53
+ async put(key, value, options) {
54
+ store.set(key, {
55
+ value,
56
+ ...(options?.expirationTtl !== undefined
57
+ ? { expiresAt: Date.now() + options.expirationTtl * 1000 }
58
+ : {}),
59
+ });
60
+ },
61
+ async delete(key) {
62
+ store.delete(key);
63
+ },
64
+ };
65
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crewhaus/runtime-core",
3
- "version": "0.3.2",
3
+ "version": "0.4.0",
4
4
  "type": "module",
5
5
  "description": "Minimal runtime imported by generated harness bundles",
6
6
  "main": "dist/index.js",
@@ -16,49 +16,51 @@
16
16
  },
17
17
  "dependencies": {
18
18
  "@anthropic-ai/sdk": "^0.96.0",
19
- "@crewhaus/abort-controller": "0.3.2",
20
- "@crewhaus/adapter-anthropic": "0.3.2",
21
- "@crewhaus/agent-context-isolation": "0.3.2",
22
- "@crewhaus/boundary-classifier": "0.3.2",
23
- "@crewhaus/circuit-breaker": "0.3.2",
24
- "@crewhaus/compaction-autocompact": "0.3.2",
25
- "@crewhaus/compaction-snip": "0.3.2",
26
- "@crewhaus/cost-tracker": "0.3.2",
27
- "@crewhaus/egress-classifier": "0.3.2",
28
- "@crewhaus/errors": "0.3.2",
29
- "@crewhaus/event-log": "0.3.2",
30
- "@crewhaus/hooks-engine": "0.3.2",
31
- "@crewhaus/model-router": "0.3.2",
32
- "@crewhaus/permission-engine": "0.3.2",
33
- "@crewhaus/prompt-cache-manager": "0.3.2",
34
- "@crewhaus/prompt-injection-detector": "0.3.2",
35
- "@crewhaus/rate-limiter": "0.3.2",
36
- "@crewhaus/recovery-engine": "0.3.2",
37
- "@crewhaus/routing-store": "0.3.2",
38
- "@crewhaus/run-context": "0.3.2",
39
- "@crewhaus/session-store": "0.3.2",
40
- "@crewhaus/skills-registry": "0.3.2",
41
- "@crewhaus/slash-commands": "0.3.2",
42
- "@crewhaus/state-store": "0.3.2",
43
- "@crewhaus/tenancy": "0.3.2",
44
- "@crewhaus/token-budget": "0.3.2",
45
- "@crewhaus/tool-catalog": "0.3.2",
46
- "@crewhaus/tool-executor": "0.3.2",
47
- "@crewhaus/tool-loop-detection": "0.3.2",
48
- "@crewhaus/tool-orchestrator": "0.3.2",
49
- "@crewhaus/tool-result-store": "0.3.2",
50
- "@crewhaus/streaming-tool-executor": "0.3.2",
51
- "@crewhaus/turn-state-machine": "0.3.2",
52
- "@crewhaus/trace-event-bus": "0.3.2",
53
- "@crewhaus/structured-event-printer": "0.3.2",
54
- "@crewhaus/metrics-collector": "0.3.2",
55
- "@crewhaus/otel-exporter": "0.3.2",
19
+ "@crewhaus/abort-controller": "0.4.0",
20
+ "@crewhaus/adapter-anthropic": "0.4.0",
21
+ "@crewhaus/agent-context-isolation": "0.4.0",
22
+ "@crewhaus/boundary-classifier": "0.4.0",
23
+ "@crewhaus/circuit-breaker": "0.4.0",
24
+ "@crewhaus/compaction-autocompact": "0.4.0",
25
+ "@crewhaus/compaction-curator": "0.4.0",
26
+ "@crewhaus/compaction-snip": "0.4.0",
27
+ "@crewhaus/cost-tracker": "0.4.0",
28
+ "@crewhaus/egress-classifier": "0.4.0",
29
+ "@crewhaus/errors": "0.4.0",
30
+ "@crewhaus/event-log": "0.4.0",
31
+ "@crewhaus/hooks-engine": "0.4.0",
32
+ "@crewhaus/model-router": "0.4.0",
33
+ "@crewhaus/permission-engine": "0.4.0",
34
+ "@crewhaus/prompt-cache-manager": "0.4.0",
35
+ "@crewhaus/prompt-injection-detector": "0.4.0",
36
+ "@crewhaus/rate-limiter": "0.4.0",
37
+ "@crewhaus/recovery-engine": "0.4.0",
38
+ "@crewhaus/routing-store": "0.4.0",
39
+ "@crewhaus/run-context": "0.4.0",
40
+ "@crewhaus/session-store": "0.4.0",
41
+ "@crewhaus/skills-registry": "0.4.0",
42
+ "@crewhaus/slash-commands": "0.4.0",
43
+ "@crewhaus/state-store": "0.4.0",
44
+ "@crewhaus/tenancy": "0.4.0",
45
+ "@crewhaus/token-budget": "0.4.0",
46
+ "@crewhaus/tool-catalog": "0.4.0",
47
+ "@crewhaus/tool-executor": "0.4.0",
48
+ "@crewhaus/tool-loop-detection": "0.4.0",
49
+ "@crewhaus/tool-orchestrator": "0.4.0",
50
+ "@crewhaus/tool-result-store": "0.4.0",
51
+ "@crewhaus/streaming-tool-executor": "0.4.0",
52
+ "@crewhaus/turn-state-machine": "0.4.0",
53
+ "@crewhaus/trace-event-bus": "0.4.0",
54
+ "@crewhaus/worker-runtime": "0.4.0",
55
+ "@crewhaus/structured-event-printer": "0.4.0",
56
+ "@crewhaus/metrics-collector": "0.4.0",
57
+ "@crewhaus/otel-exporter": "0.4.0",
56
58
  "zod-to-json-schema": "^3.23.5"
57
59
  },
58
60
  "devDependencies": {
59
- "@crewhaus/logging": "0.3.2",
60
- "@crewhaus/tool-builder": "0.3.2",
61
- "@crewhaus/tool-plan": "0.3.2",
61
+ "@crewhaus/logging": "0.4.0",
62
+ "@crewhaus/tool-builder": "0.4.0",
63
+ "@crewhaus/tool-plan": "0.4.0",
62
64
  "zod": "^3.23.8"
63
65
  },
64
66
  "license": "Apache-2.0",