@weaveintel/core 0.0.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.
Files changed (266) hide show
  1. package/README.md +91 -0
  2. package/dist/a2a.d.ts +304 -0
  3. package/dist/a2a.d.ts.map +1 -0
  4. package/dist/a2a.js +68 -0
  5. package/dist/a2a.js.map +1 -0
  6. package/dist/admin-capabilities.d.ts +60 -0
  7. package/dist/admin-capabilities.d.ts.map +1 -0
  8. package/dist/admin-capabilities.js +31 -0
  9. package/dist/admin-capabilities.js.map +1 -0
  10. package/dist/agents.d.ts +214 -0
  11. package/dist/agents.d.ts.map +1 -0
  12. package/dist/agents.js +12 -0
  13. package/dist/agents.js.map +1 -0
  14. package/dist/artifacts.d.ts +70 -0
  15. package/dist/artifacts.d.ts.map +1 -0
  16. package/dist/artifacts.js +5 -0
  17. package/dist/artifacts.js.map +1 -0
  18. package/dist/cache.d.ts +177 -0
  19. package/dist/cache.d.ts.map +1 -0
  20. package/dist/cache.js +9 -0
  21. package/dist/cache.js.map +1 -0
  22. package/dist/callables.d.ts +34 -0
  23. package/dist/callables.d.ts.map +1 -0
  24. package/dist/callables.js +35 -0
  25. package/dist/callables.js.map +1 -0
  26. package/dist/capabilities.d.ts +77 -0
  27. package/dist/capabilities.d.ts.map +1 -0
  28. package/dist/capabilities.js +82 -0
  29. package/dist/capabilities.js.map +1 -0
  30. package/dist/capability-policy.d.ts +41 -0
  31. package/dist/capability-policy.d.ts.map +1 -0
  32. package/dist/capability-policy.js +34 -0
  33. package/dist/capability-policy.js.map +1 -0
  34. package/dist/collaboration.d.ts +45 -0
  35. package/dist/collaboration.d.ts.map +1 -0
  36. package/dist/collaboration.js +5 -0
  37. package/dist/collaboration.js.map +1 -0
  38. package/dist/compliance.d.ts +71 -0
  39. package/dist/compliance.d.ts.map +1 -0
  40. package/dist/compliance.js +5 -0
  41. package/dist/compliance.js.map +1 -0
  42. package/dist/connectors.d.ts +109 -0
  43. package/dist/connectors.d.ts.map +1 -0
  44. package/dist/connectors.js +24 -0
  45. package/dist/connectors.js.map +1 -0
  46. package/dist/context.d.ts +52 -0
  47. package/dist/context.d.ts.map +1 -0
  48. package/dist/context.js +70 -0
  49. package/dist/context.js.map +1 -0
  50. package/dist/contracts.d.ts +70 -0
  51. package/dist/contracts.d.ts.map +1 -0
  52. package/dist/contracts.js +5 -0
  53. package/dist/contracts.js.map +1 -0
  54. package/dist/documents.d.ts +55 -0
  55. package/dist/documents.d.ts.map +1 -0
  56. package/dist/documents.js +9 -0
  57. package/dist/documents.js.map +1 -0
  58. package/dist/error-classifier.d.ts +67 -0
  59. package/dist/error-classifier.d.ts.map +1 -0
  60. package/dist/error-classifier.js +129 -0
  61. package/dist/error-classifier.js.map +1 -0
  62. package/dist/errors.d.ts +27 -0
  63. package/dist/errors.d.ts.map +1 -0
  64. package/dist/errors.js +63 -0
  65. package/dist/errors.js.map +1 -0
  66. package/dist/evals.d.ts +55 -0
  67. package/dist/evals.d.ts.map +1 -0
  68. package/dist/evals.js +9 -0
  69. package/dist/evals.js.map +1 -0
  70. package/dist/events.d.ts +60 -0
  71. package/dist/events.d.ts.map +1 -0
  72. package/dist/events.js +108 -0
  73. package/dist/events.js.map +1 -0
  74. package/dist/extraction.d.ts +71 -0
  75. package/dist/extraction.d.ts.map +1 -0
  76. package/dist/extraction.js +5 -0
  77. package/dist/extraction.js.map +1 -0
  78. package/dist/files.d.ts +39 -0
  79. package/dist/files.d.ts.map +1 -0
  80. package/dist/files.js +9 -0
  81. package/dist/files.js.map +1 -0
  82. package/dist/finetuning.d.ts +58 -0
  83. package/dist/finetuning.d.ts.map +1 -0
  84. package/dist/finetuning.js +9 -0
  85. package/dist/finetuning.js.map +1 -0
  86. package/dist/graph.d.ts +70 -0
  87. package/dist/graph.d.ts.map +1 -0
  88. package/dist/graph.js +5 -0
  89. package/dist/graph.js.map +1 -0
  90. package/dist/guardrails.d.ts +221 -0
  91. package/dist/guardrails.d.ts.map +1 -0
  92. package/dist/guardrails.js +2 -0
  93. package/dist/guardrails.js.map +1 -0
  94. package/dist/hardened-fetch.d.ts +80 -0
  95. package/dist/hardened-fetch.d.ts.map +1 -0
  96. package/dist/hardened-fetch.js +251 -0
  97. package/dist/hardened-fetch.js.map +1 -0
  98. package/dist/human-tasks.d.ts +141 -0
  99. package/dist/human-tasks.d.ts.map +1 -0
  100. package/dist/human-tasks.js +5 -0
  101. package/dist/human-tasks.js.map +1 -0
  102. package/dist/identity.d.ts +53 -0
  103. package/dist/identity.d.ts.map +1 -0
  104. package/dist/identity.js +5 -0
  105. package/dist/identity.js.map +1 -0
  106. package/dist/index.d.ts +66 -0
  107. package/dist/index.d.ts.map +1 -0
  108. package/dist/index.js +163 -0
  109. package/dist/index.js.map +1 -0
  110. package/dist/json-patch.d.ts +72 -0
  111. package/dist/json-patch.d.ts.map +1 -0
  112. package/dist/json-patch.js +239 -0
  113. package/dist/json-patch.js.map +1 -0
  114. package/dist/logger.d.ts +29 -0
  115. package/dist/logger.d.ts.map +1 -0
  116. package/dist/logger.js +74 -0
  117. package/dist/logger.js.map +1 -0
  118. package/dist/managed-vectorstore.d.ts +88 -0
  119. package/dist/managed-vectorstore.d.ts.map +1 -0
  120. package/dist/managed-vectorstore.js +10 -0
  121. package/dist/managed-vectorstore.js.map +1 -0
  122. package/dist/mcp.d.ts +195 -0
  123. package/dist/mcp.d.ts.map +1 -0
  124. package/dist/mcp.js +9 -0
  125. package/dist/mcp.js.map +1 -0
  126. package/dist/memory.d.ts +152 -0
  127. package/dist/memory.d.ts.map +1 -0
  128. package/dist/memory.js +10 -0
  129. package/dist/memory.js.map +1 -0
  130. package/dist/middleware.d.ts +40 -0
  131. package/dist/middleware.d.ts.map +1 -0
  132. package/dist/middleware.js +79 -0
  133. package/dist/middleware.js.map +1 -0
  134. package/dist/models.d.ts +279 -0
  135. package/dist/models.d.ts.map +1 -0
  136. package/dist/models.js +12 -0
  137. package/dist/models.js.map +1 -0
  138. package/dist/moderation.d.ts +39 -0
  139. package/dist/moderation.d.ts.map +1 -0
  140. package/dist/moderation.js +10 -0
  141. package/dist/moderation.js.map +1 -0
  142. package/dist/net-guard.d.ts +60 -0
  143. package/dist/net-guard.d.ts.map +1 -0
  144. package/dist/net-guard.js +250 -0
  145. package/dist/net-guard.js.map +1 -0
  146. package/dist/notifications.d.ts +121 -0
  147. package/dist/notifications.d.ts.map +1 -0
  148. package/dist/notifications.js +12 -0
  149. package/dist/notifications.js.map +1 -0
  150. package/dist/observability-runtime.d.ts +16 -0
  151. package/dist/observability-runtime.d.ts.map +1 -0
  152. package/dist/observability-runtime.js +34 -0
  153. package/dist/observability-runtime.js.map +1 -0
  154. package/dist/observability.d.ts +130 -0
  155. package/dist/observability.d.ts.map +1 -0
  156. package/dist/observability.js +9 -0
  157. package/dist/observability.js.map +1 -0
  158. package/dist/plugins.d.ts +46 -0
  159. package/dist/plugins.d.ts.map +1 -0
  160. package/dist/plugins.js +5 -0
  161. package/dist/plugins.js.map +1 -0
  162. package/dist/prompts.d.ts +219 -0
  163. package/dist/prompts.d.ts.map +1 -0
  164. package/dist/prompts.js +5 -0
  165. package/dist/prompts.js.map +1 -0
  166. package/dist/registry.d.ts +31 -0
  167. package/dist/registry.d.ts.map +1 -0
  168. package/dist/registry.js +34 -0
  169. package/dist/registry.js.map +1 -0
  170. package/dist/reliability.d.ts +68 -0
  171. package/dist/reliability.d.ts.map +1 -0
  172. package/dist/reliability.js +5 -0
  173. package/dist/reliability.js.map +1 -0
  174. package/dist/replay.d.ts +91 -0
  175. package/dist/replay.d.ts.map +1 -0
  176. package/dist/replay.js +5 -0
  177. package/dist/replay.js.map +1 -0
  178. package/dist/responses.d.ts +273 -0
  179. package/dist/responses.d.ts.map +1 -0
  180. package/dist/responses.js +11 -0
  181. package/dist/responses.js.map +1 -0
  182. package/dist/routing.d.ts +171 -0
  183. package/dist/routing.d.ts.map +1 -0
  184. package/dist/routing.js +5 -0
  185. package/dist/routing.js.map +1 -0
  186. package/dist/run-events.d.ts +199 -0
  187. package/dist/run-events.d.ts.map +1 -0
  188. package/dist/run-events.js +88 -0
  189. package/dist/run-events.js.map +1 -0
  190. package/dist/run-journal.d.ts +66 -0
  191. package/dist/run-journal.d.ts.map +1 -0
  192. package/dist/run-journal.js +153 -0
  193. package/dist/run-journal.js.map +1 -0
  194. package/dist/run-registry.d.ts +49 -0
  195. package/dist/run-registry.d.ts.map +1 -0
  196. package/dist/run-registry.js +154 -0
  197. package/dist/run-registry.js.map +1 -0
  198. package/dist/run-substrate-contract.d.ts +48 -0
  199. package/dist/run-substrate-contract.d.ts.map +1 -0
  200. package/dist/run-substrate-contract.js +124 -0
  201. package/dist/run-substrate-contract.js.map +1 -0
  202. package/dist/runs.d.ts +94 -0
  203. package/dist/runs.d.ts.map +1 -0
  204. package/dist/runs.js +12 -0
  205. package/dist/runs.js.map +1 -0
  206. package/dist/runtime.d.ts +665 -0
  207. package/dist/runtime.d.ts.map +1 -0
  208. package/dist/runtime.js +436 -0
  209. package/dist/runtime.js.map +1 -0
  210. package/dist/sandbox.d.ts +50 -0
  211. package/dist/sandbox.d.ts.map +1 -0
  212. package/dist/sandbox.js +5 -0
  213. package/dist/sandbox.js.map +1 -0
  214. package/dist/secrets.d.ts +34 -0
  215. package/dist/secrets.d.ts.map +1 -0
  216. package/dist/secrets.js +68 -0
  217. package/dist/secrets.js.map +1 -0
  218. package/dist/security.d.ts +97 -0
  219. package/dist/security.d.ts.map +1 -0
  220. package/dist/security.js +9 -0
  221. package/dist/security.js.map +1 -0
  222. package/dist/sse-parser.d.ts +67 -0
  223. package/dist/sse-parser.d.ts.map +1 -0
  224. package/dist/sse-parser.js +156 -0
  225. package/dist/sse-parser.js.map +1 -0
  226. package/dist/sse-writer.d.ts +63 -0
  227. package/dist/sse-writer.d.ts.map +1 -0
  228. package/dist/sse-writer.js +87 -0
  229. package/dist/sse-writer.js.map +1 -0
  230. package/dist/surface-catalog.d.ts +68 -0
  231. package/dist/surface-catalog.d.ts.map +1 -0
  232. package/dist/surface-catalog.js +13 -0
  233. package/dist/surface-catalog.js.map +1 -0
  234. package/dist/tenancy.d.ts +67 -0
  235. package/dist/tenancy.d.ts.map +1 -0
  236. package/dist/tenancy.js +5 -0
  237. package/dist/tenancy.js.map +1 -0
  238. package/dist/tool-lifecycle.d.ts +118 -0
  239. package/dist/tool-lifecycle.d.ts.map +1 -0
  240. package/dist/tool-lifecycle.js +5 -0
  241. package/dist/tool-lifecycle.js.map +1 -0
  242. package/dist/tools.d.ts +96 -0
  243. package/dist/tools.d.ts.map +1 -0
  244. package/dist/tools.js +71 -0
  245. package/dist/tools.js.map +1 -0
  246. package/dist/triggers.d.ts +48 -0
  247. package/dist/triggers.d.ts.map +1 -0
  248. package/dist/triggers.js +5 -0
  249. package/dist/triggers.js.map +1 -0
  250. package/dist/ui-events.d.ts +96 -0
  251. package/dist/ui-events.d.ts.map +1 -0
  252. package/dist/ui-events.js +5 -0
  253. package/dist/ui-events.js.map +1 -0
  254. package/dist/uuid.d.ts +27 -0
  255. package/dist/uuid.d.ts.map +1 -0
  256. package/dist/uuid.js +54 -0
  257. package/dist/uuid.js.map +1 -0
  258. package/dist/vectorstore.d.ts +76 -0
  259. package/dist/vectorstore.d.ts.map +1 -0
  260. package/dist/vectorstore.js +9 -0
  261. package/dist/vectorstore.js.map +1 -0
  262. package/dist/workflows.d.ts +554 -0
  263. package/dist/workflows.d.ts.map +1 -0
  264. package/dist/workflows.js +29 -0
  265. package/dist/workflows.js.map +1 -0
  266. package/package.json +33 -0
@@ -0,0 +1,665 @@
1
+ /**
2
+ * @weaveintel/core — `weaveRuntime`
3
+ *
4
+ * Phase 2 of enterprise hardening. A single object that bundles every
5
+ * cross-cutting concern an agent / workflow / tool / connector needs, so
6
+ * none of them get constructed ad-hoc per call site:
7
+ *
8
+ * - egress hardened outbound HTTP (Phase 1)
9
+ * - tracer observability
10
+ * - secrets env / vault / KMS resolution
11
+ * - audit append-only audit logger
12
+ * - persistence durable store (optional — in-memory by default)
13
+ * - resilience signal bus (optional — for endpoint health propagation)
14
+ *
15
+ * The runtime is the *root* from which an `ExecutionContext` is derived,
16
+ * making every cross-cutting concern ambient and reachable from any callsite
17
+ * without inventing a parallel singleton. Opting out is explicit and
18
+ * surfaced via `runtime.has(...)` / `runtime.require(...)`.
19
+ *
20
+ * This package stays vendor-dep-free. Adapter slots (`persistence`,
21
+ * `resilience.signalBus`) use minimal structural interfaces so concrete
22
+ * implementations from `@weaveintel/persistence` and `@weaveintel/resilience`
23
+ * fit without importing them here.
24
+ */
25
+ import { type CapabilityId } from './capabilities.js';
26
+ import { createHardenedFetch, type HardenedFetchOptions } from './hardened-fetch.js';
27
+ import type { ExecutionContext } from './context.js';
28
+ import type { Tracer } from './observability.js';
29
+ import type { AuditLogger, Redactor, SecretResolver } from './security.js';
30
+ import type { ModelHealth } from './routing.js';
31
+ import type { SemanticMemory, WorkingMemory, MemoryStore } from './memory.js';
32
+ import type { IdentityContext, DelegationContext, AccessDecision } from './identity.js';
33
+ import type { CacheStore, SemanticCache, CacheMetrics } from './cache.js';
34
+ /**
35
+ * Cross-cutting runtime capabilities. Used with `runtime.has(cap)` and
36
+ * `runtime.require(cap)` at registration time for any feature that declares
37
+ * `requires: [...]`.
38
+ */
39
+ export declare const RuntimeCapabilities: {
40
+ readonly NetEgress: CapabilityId;
41
+ readonly Observability: CapabilityId;
42
+ readonly Secrets: CapabilityId;
43
+ readonly Audit: CapabilityId;
44
+ readonly Persistence: CapabilityId;
45
+ readonly Resilience: CapabilityId;
46
+ readonly Encryption: CapabilityId;
47
+ readonly Guardrails: CapabilityId;
48
+ readonly Routing: CapabilityId;
49
+ readonly Cost: CapabilityId;
50
+ readonly Memory: CapabilityId;
51
+ readonly Compliance: CapabilityId;
52
+ readonly Identity: CapabilityId;
53
+ readonly Cache: CapabilityId;
54
+ };
55
+ /**
56
+ * Structural slot for aggregated compliance management (Phase 6).
57
+ *
58
+ * Bundles all GDPR / data-governance primitives into a single ambient slot
59
+ * so every call site can reach them through `ctx.runtime?.compliance` without
60
+ * constructing per-route or per-chat manager instances.
61
+ *
62
+ * Concrete adapters live in `@weaveintel/compliance`;
63
+ * `createRuntimeComplianceAdapter(opts)` builds one from the durable managers.
64
+ *
65
+ * `consent` — grant / revoke / query per-user consent flags.
66
+ * `residency` — data-flow compliance (which regions are allowed).
67
+ * `deletion` — GDPR Art. 17 right-to-delete lifecycle.
68
+ * `isAllowed` — convenience consent check (most common call site).
69
+ * `canProcess` — convenience residency check.
70
+ * `requestErasure` — convenience GDPR erasure trigger.
71
+ * `requestExport` — convenience GDPR export trigger.
72
+ */
73
+ export interface RuntimeComplianceSlot {
74
+ /** Consent manager — grant / revoke / query per-user consent flags. */
75
+ readonly consent: {
76
+ isGranted(subjectId: string, purpose: string): Promise<boolean>;
77
+ grant(subjectId: string, purpose: string, source: string, expiresAt?: number): Promise<unknown>;
78
+ revoke(subjectId: string, purpose: string): Promise<boolean>;
79
+ listBySubject(subjectId: string): Promise<readonly unknown[]>;
80
+ };
81
+ /** Residency engine — validate data-flow compliance. */
82
+ readonly residency: {
83
+ isAllowed(dataCategory: string, targetRegion: string): Promise<boolean>;
84
+ getAllowedRegions(dataCategory: string): Promise<readonly string[]>;
85
+ };
86
+ /** Deletion manager — GDPR Art. 17 right-to-delete lifecycle. */
87
+ readonly deletion: {
88
+ create(subjectId: string, requestedBy: string, reason: string, dataCategories: string[]): Promise<{
89
+ id: string;
90
+ status: string;
91
+ }>;
92
+ process(id: string): Promise<unknown>;
93
+ complete(id: string): Promise<unknown>;
94
+ fail(id: string, reason: string): Promise<unknown>;
95
+ };
96
+ /** Audit-export manager — GDPR Art. 20 data portability. */
97
+ readonly auditExport: {
98
+ create(tenantId: string, requestedBy: string, format: string, categories: string[], fromDate: number, toDate: number): Promise<{
99
+ id: string;
100
+ status: string;
101
+ format: string;
102
+ }>;
103
+ markReady(id: string, recordCount: number, sizeBytes: number): Promise<unknown>;
104
+ markFailed(id: string): Promise<unknown>;
105
+ };
106
+ /**
107
+ * Convenience: check if userId has granted consent for the given purpose.
108
+ * Prefer this over `consent.isGranted` at call sites that don't need the
109
+ * full manager; it is swallowed on error and returns `true` (permit-if-no-record).
110
+ */
111
+ isAllowed(userId: string, purpose: string): Promise<boolean>;
112
+ /**
113
+ * Convenience: check whether data for `dataCategory` can flow to `targetRegion`.
114
+ * Returns `true` when no residency constraint matches (fail-open by default;
115
+ * set `COMPLIANCE_RESIDENCY_DEFAULT_DENY=true` for regulated environments).
116
+ */
117
+ canProcess(tenantId: string, dataCategory: string, targetRegion: string): Promise<boolean>;
118
+ /**
119
+ * Initiate a GDPR Art. 17 erasure request for `userId`.
120
+ * Returns a minimal { id, status } handle so callers can track the request.
121
+ */
122
+ requestErasure(userId: string, requestedBy?: string, reason?: string, dataCategories?: string[]): Promise<{
123
+ id: string;
124
+ status: string;
125
+ dataCategories: readonly string[];
126
+ }>;
127
+ /**
128
+ * Initiate a GDPR Art. 20 data export for `userId`.
129
+ * Returns a minimal { id, status, format } handle.
130
+ */
131
+ requestExport(userId: string, tenantId: string, format?: string): Promise<{
132
+ id: string;
133
+ status: string;
134
+ format: string;
135
+ }>;
136
+ }
137
+ /**
138
+ * Structural slot for typed identity evaluation (Phase 6).
139
+ *
140
+ * Surfaces the `@weaveintel/identity` RBAC engine through the DI chain so
141
+ * auth middleware, tool guards, and live-agent handlers can evaluate access
142
+ * decisions without importing the identity package directly.
143
+ *
144
+ * `resolve` — build a typed `IdentityContext` from raw user ids.
145
+ * `evaluate` — evaluate a resource + action against the RBAC policy.
146
+ * `validateDelegation` — check a delegation chain for cycles and expiry.
147
+ */
148
+ export interface RuntimeIdentitySlot {
149
+ /**
150
+ * Build a typed `IdentityContext` from a userId and optional tenantId.
151
+ * Assigns effective permissions based on the configured RBAC policy and
152
+ * any caller-supplied role overrides.
153
+ */
154
+ resolve(userId: string, tenantId: string | null, opts?: {
155
+ roles?: string[];
156
+ scopes?: string[];
157
+ persona?: string;
158
+ }): IdentityContext;
159
+ /**
160
+ * Evaluate whether the identity has permission for `resource` + `action`.
161
+ * Returns a structured `AccessDecision` — never throws; callers must check
162
+ * `.result === 'allow'` before proceeding.
163
+ */
164
+ evaluate(ctx: IdentityContext, resource: string, action: string, conditions?: Record<string, unknown>): AccessDecision;
165
+ /**
166
+ * Validate a delegation chain for cycles, expiry, and scope validity.
167
+ * Returns `{ valid: true }` or `{ valid: false, reason }`.
168
+ */
169
+ validateDelegation(delegation: DelegationContext): {
170
+ valid: boolean;
171
+ reason?: string;
172
+ };
173
+ }
174
+ /**
175
+ * Structural slot for shared response caching (Phase 7).
176
+ *
177
+ * A single shared `CacheStore` wired via `weaveRuntime` so the chat path,
178
+ * live-agent handlers, and tools all share the same cache without each
179
+ * constructing a private `weaveInMemoryCacheStore()` instance. In-process
180
+ * caches from different subsystems never benefit each other; sharing through
181
+ * the DI chain means a warm response in the chat path can serve a live-agent
182
+ * tool that asks the same question in the same process.
183
+ *
184
+ * `get` / `set` / `invalidate` mirror the `CacheStore` interface with the
185
+ * minimal surface that call sites need. The raw `store` accessor is provided
186
+ * for consumers that need the full `CacheStore` API (e.g. `has`, `clear`).
187
+ *
188
+ * `semanticGet` is optional — present only when a `SemanticCache` is wired.
189
+ * It returns a cached response for the most semantically-similar past query
190
+ * above `threshold`; useful for deduplicating near-identical LLM calls.
191
+ *
192
+ * Concrete adapter: `createRuntimeCacheAdapter(store, semanticCache?)` from
193
+ * `@weaveintel/cache`.
194
+ */
195
+ export interface RuntimeCacheSlot {
196
+ /** Retrieve a cached value by exact key. Returns `null` on miss or expiry. */
197
+ get(key: string): Promise<unknown>;
198
+ /** Store a value under `key` with an optional TTL in milliseconds. */
199
+ set(key: string, value: unknown, ttlMs?: number): Promise<void>;
200
+ /** Delete a single cache entry by key. */
201
+ invalidate(key: string): Promise<void>;
202
+ /**
203
+ * Semantic similarity lookup. When a `SemanticCache` is wired, returns the
204
+ * cached response for the most semantically-similar past `query` within
205
+ * `scope`, above `threshold`. Query-first (the previous embedding-first form
206
+ * could not match stored query embeddings). Returns `null` on no match or when
207
+ * no semantic cache is configured.
208
+ */
209
+ semanticGet?(query: string, opts?: {
210
+ scope?: string;
211
+ threshold?: number;
212
+ }): Promise<unknown>;
213
+ /** Raw `CacheStore` for consumers that need the full API (`has`, `clear`, `size`). */
214
+ readonly store: CacheStore;
215
+ /** Raw `SemanticCache` for consumers that need `store` / `invalidate` control. */
216
+ readonly semanticStore?: SemanticCache;
217
+ /**
218
+ * Phase 3 — live cache effectiveness metrics (response-cache hit rate +
219
+ * prompt-cache token/cost savings). Present when a metrics sink is wired via
220
+ * `createRuntimeCacheAdapter(store, semanticCache?, metrics?)`. Read a
221
+ * snapshot with `metrics.snapshot()`.
222
+ */
223
+ readonly metrics?: CacheMetrics;
224
+ }
225
+ /**
226
+ * Structural slot for cross-cutting agent memory (Phase 5).
227
+ *
228
+ * A single shared slot that every agent, tool, and live-agent handler can
229
+ * access via `ctx.runtime?.memory` without instantiating private memory
230
+ * objects per call site. Concrete adapters live in `@weaveintel/memory`;
231
+ * `createRuntimeMemoryAdapter(opts)` builds one from any `MemoryStore`
232
+ * backend (SQLite, pgvector, Postgres, Redis, …).
233
+ *
234
+ * `semantic` — embedding-based vector recall. Requires an embedding model.
235
+ * `working` — per-agent scratch state (patch / checkpoint / restore).
236
+ * `store` — raw `MemoryStore` for lower-level multi-type queries (useful
237
+ * for `fusedMemorySearch` across semantic + episodic + entity).
238
+ * `consolidate` — trigger the cold-path pipeline that distils episodic entries
239
+ * into durable semantic facts for a given user.
240
+ */
241
+ export interface RuntimeMemorySlot {
242
+ readonly semantic: SemanticMemory;
243
+ readonly working: WorkingMemory;
244
+ readonly store: MemoryStore;
245
+ consolidate(userId: string): Promise<void>;
246
+ }
247
+ /**
248
+ * Minimal structural key-value store that every durable subsystem
249
+ * (DLQ, cost meter, idempotency, audit ledger, etc.) can consume without
250
+ * caring whether the backend is in-memory, SQLite, Postgres, Redis, or a
251
+ * cloud KV. Concrete implementations live in `@weaveintel/persistence`;
252
+ * `weaveInMemoryPersistence()` below is the zero-config default.
253
+ *
254
+ * Keys are opaque strings (callers namespace via `prefix:tenant:id`).
255
+ * Values are opaque strings (callers JSON-encode richer payloads).
256
+ *
257
+ * `list(prefix)` returns lexicographically-sorted entries — callers can
258
+ * rely on `prefix + '\u0000'` to bound a scan if they need it.
259
+ *
260
+ * Best-effort throughout: a thrown op is surfaced to the caller, but the
261
+ * runtime itself never crashes a request when persistence misbehaves.
262
+ */
263
+ export interface RuntimeKvStore {
264
+ get(key: string): Promise<string | undefined>;
265
+ set(key: string, value: string, opts?: {
266
+ ttlMs?: number;
267
+ }): Promise<void>;
268
+ delete(key: string): Promise<boolean>;
269
+ list(prefix: string): Promise<readonly {
270
+ readonly key: string;
271
+ readonly value: string;
272
+ }[]>;
273
+ }
274
+ /** Structural slot for the durable backend. Concrete adapter comes from
275
+ * `@weaveintel/persistence` — `kind` is the discriminator, `kv` is the
276
+ * contract every durable subsystem (Phase 4) consumes. */
277
+ export interface RuntimePersistenceSlot {
278
+ readonly kind: string;
279
+ readonly kv: RuntimeKvStore;
280
+ }
281
+ /** Structural slot for a resilience signal bus. Concrete instance comes from
282
+ * `@weaveintel/resilience` — only `emit` is structurally required.
283
+ *
284
+ * Phase 0 additions: `getState`, `getLatencyP50`, `getLatencyP95` are optional
285
+ * so existing implementations remain valid. Use them to make routing decisions
286
+ * through the DI chain instead of reaching for process-global singletons. */
287
+ export interface RuntimeResilienceSlot {
288
+ emit(event: {
289
+ readonly kind: string;
290
+ readonly endpoint: string;
291
+ readonly meta?: Readonly<Record<string, unknown>>;
292
+ }): void;
293
+ /** Current circuit-breaker state for the given endpoint key. Returns `'unknown'`
294
+ * when no circuit has been registered for that endpoint. */
295
+ getState?(endpoint: string): 'closed' | 'open' | 'half_open' | 'unknown';
296
+ /** 50th-percentile latency in ms for the given endpoint, or `null` if no
297
+ * samples have been recorded yet. */
298
+ getLatencyP50?(endpoint: string): number | null;
299
+ /** 95th-percentile latency in ms for the given endpoint, or `null` if no
300
+ * samples have been recorded yet. */
301
+ getLatencyP95?(endpoint: string): number | null;
302
+ }
303
+ /**
304
+ * Structural slot for tenant-scoped encryption (Phase F). The concrete
305
+ * implementation comes from `@weaveintel/encryption` (`weaveTenantKeyManager`),
306
+ * but core stays dep-free — consumers that need to encrypt/decrypt retrieve
307
+ * the slot via `ctx.runtime?.encryption` and cast to the concrete
308
+ * `TenantKeyManager` shape they expect. Marker-only by design (no methods)
309
+ * so core takes no dependency on the encryption package.
310
+ */
311
+ export interface RuntimeEncryptionSlot {
312
+ readonly kind: string;
313
+ /**
314
+ * Lazy accessor for the underlying key manager. Returns `null` while
315
+ * encryption is disabled (no master key configured) or before the
316
+ * adopter's bootstrap has completed. Callers cast the return value to
317
+ * the concrete `TenantKeyManager` from `@weaveintel/encryption`.
318
+ *
319
+ * The accessor pattern lets adopters construct the runtime BEFORE the
320
+ * manager is ready, then mutate the underlying ref once bootstrap
321
+ * completes — without changing the runtime object.
322
+ */
323
+ getManager(): unknown;
324
+ /**
325
+ * Returns `true` when field encryption is active — i.e. the master key is
326
+ * present and the key manager has completed bootstrap. Use this before
327
+ * performing any encrypt/decrypt operation rather than checking `getManager()
328
+ * !== null`, which is implementation-dependent.
329
+ */
330
+ isActive(): boolean;
331
+ }
332
+ /**
333
+ * Structural slot for ambient guardrails (Phase 3). The agent loop, workflow
334
+ * engine, and tool registry all consult `runtime.guardrails?.checkToolCall`
335
+ * before invoking a tool and `runtime.guardrails?.checkOutput` before
336
+ * surfacing a model response. Both checks are best-effort: a missing slot
337
+ * is a no-op (allow), and a thrown check is logged via audit and treated
338
+ * as a deny rather than crashing the run — guardrails are never
339
+ * load-bearing.
340
+ *
341
+ * Concrete implementations may live in `@weaveintel/guardrails`, an app's
342
+ * policy module, or a per-tenant ruleset; the structural interface keeps
343
+ * `@weaveintel/core` free of any specific guardrail library.
344
+ */
345
+ export interface RuntimeGuardrailsSlot {
346
+ /**
347
+ * Inspect inbound user content BEFORE it reaches the model (Phase 0 addition).
348
+ * Called after PII redaction, so `input` is the cleaned text. Return
349
+ * `{ allow: false }` to block the message entirely. Swallowed on throw
350
+ * (allow-through) — guardrails are never load-bearing.
351
+ */
352
+ checkInput?(ctx: ExecutionContext, input: string): Promise<{
353
+ allow: boolean;
354
+ reason?: string;
355
+ }>;
356
+ /** Inspect a pending tool call. Return `{ allow: false }` to block. */
357
+ checkToolCall?(ctx: ExecutionContext, schema: {
358
+ readonly name: string;
359
+ readonly riskLevel?: string;
360
+ }, args: Readonly<Record<string, unknown>>): Promise<{
361
+ allow: boolean;
362
+ reason?: string;
363
+ }>;
364
+ /** Inspect a terminal model output. May return `redactedText` to rewrite. */
365
+ checkOutput?(ctx: ExecutionContext, text: string): Promise<{
366
+ allow: boolean;
367
+ redactedText?: string;
368
+ reason?: string;
369
+ }>;
370
+ }
371
+ /**
372
+ * Structural slot for shared model-health tracking (Phase 2 — Shared Routing Slot).
373
+ *
374
+ * A single shared `ModelHealthTracker` is wired via `weaveRuntime` so the
375
+ * chat path and the live-agent supervisor both observe and react to the same
376
+ * real-time health state. Outcomes recorded from one subsystem are immediately
377
+ * visible to routing in the other — no more per-instance tracker drift.
378
+ *
379
+ * Concrete implementation: `@weaveintel/routing` `createRuntimeRoutingAdapter(tracker)`.
380
+ */
381
+ export interface RuntimeRoutingSlot {
382
+ /** Record the latency and success/failure of one model call for health tracking. */
383
+ recordOutcome(modelId: string, providerId: string, latencyMs: number, success: boolean): void;
384
+ /** Block an entire provider for a window (rate-limit or degradation events). */
385
+ blockProvider(providerId: string, durationMs?: number): void;
386
+ /** Return the current health snapshot for all tracked model+provider pairs. */
387
+ listHealth(): ModelHealth[];
388
+ /** Return the set of providers currently under an active (un-expired) block. */
389
+ getBlockedProviders(): Set<string>;
390
+ /**
391
+ * Phase 7 — Multi-modal capability check. Returns `true` when at least one
392
+ * healthy model in the routing pool supports vision / image input. Call this
393
+ * before routing an `ImageContent` or `AudioContent` part so handlers can
394
+ * skip or warn rather than fail silently.
395
+ */
396
+ supportsMultiModal?(): boolean;
397
+ }
398
+ /**
399
+ * Structural slot for per-user/tenant budget enforcement (Phase 3 — Shared Cost Slot).
400
+ *
401
+ * A single shared cost ledger is wired via `weaveRuntime` so the chat path and
402
+ * the live-agent supervisor both check and record against the same runtime
403
+ * spend counter. This prevents a user from exhausting their budget via one
404
+ * surface while the other surface remains unaware.
405
+ *
406
+ * Concrete implementation: `@weaveintel/cost-governor` `createRuntimeCostAdapter(opts)`.
407
+ */
408
+ export interface RuntimeCostSlot {
409
+ /**
410
+ * Pre-flight budget check. Returns `{ allowed: false, reason }` when the
411
+ * entity (user or tenant) has exceeded their spending limit. Fail-open:
412
+ * a thrown check is treated as `{ allowed: true }` — cost gates are
413
+ * never load-bearing.
414
+ */
415
+ gate(opts: {
416
+ userId: string;
417
+ tenantId: string | null;
418
+ estimatedCostUsd?: number;
419
+ }): Promise<{
420
+ allowed: boolean;
421
+ reason?: string;
422
+ }>;
423
+ /**
424
+ * Append an observed model cost to the running ledger. Best-effort —
425
+ * KV write failures are swallowed and never crash the hot path.
426
+ */
427
+ record(opts: {
428
+ userId: string;
429
+ tenantId: string | null;
430
+ model: string;
431
+ provider: string;
432
+ promptTokens: number;
433
+ completionTokens: number;
434
+ costUsd: number;
435
+ }): Promise<void>;
436
+ /**
437
+ * Return the current spend and limit for the given entity id.
438
+ * `period` describes the accumulation window (e.g. `'lifetime'`, `'30d'`).
439
+ */
440
+ getBudgetStatus(entityId: string): Promise<{
441
+ used: number;
442
+ limit: number | null;
443
+ period: string;
444
+ }>;
445
+ }
446
+ /** Egress slot returned by `weaveRuntime` — the per-call `fetch` plus the
447
+ * `createFetch(...)` factory packages should use to build their own closure. */
448
+ export interface RuntimeEgressSlot {
449
+ /**
450
+ * Per-call hardened fetch. Pass `errorTag` (and any overrides) inline.
451
+ * For per-package usage prefer `createFetch({ errorTag, ... })` so every
452
+ * call site under that package shares the same identity.
453
+ */
454
+ fetch(input: string, init?: RequestInit, opts?: HardenedFetchOptions & {
455
+ errorTag: string;
456
+ }): Promise<Response>;
457
+ createFetch: typeof createHardenedFetch;
458
+ }
459
+ export interface WeaveRuntime {
460
+ /** Cross-cutting capabilities this runtime advertises. Always includes
461
+ * egress, observability, secrets, audit. Persistence/resilience are added
462
+ * only when their slots are configured. */
463
+ readonly capabilities: ReadonlySet<CapabilityId>;
464
+ readonly egress: RuntimeEgressSlot;
465
+ readonly tracer: Tracer;
466
+ readonly secrets: SecretResolver;
467
+ readonly audit: AuditLogger;
468
+ readonly persistence: RuntimePersistenceSlot | undefined;
469
+ readonly resilience: RuntimeResilienceSlot | undefined;
470
+ readonly guardrails: RuntimeGuardrailsSlot | undefined;
471
+ readonly encryption: RuntimeEncryptionSlot | undefined;
472
+ readonly routing: RuntimeRoutingSlot | undefined;
473
+ readonly cost: RuntimeCostSlot | undefined;
474
+ readonly memory: RuntimeMemorySlot | undefined;
475
+ readonly compliance: RuntimeComplianceSlot | undefined;
476
+ readonly identity: RuntimeIdentitySlot | undefined;
477
+ readonly cache: RuntimeCacheSlot | undefined;
478
+ readonly metadata: Readonly<Record<string, unknown>>;
479
+ has(cap: CapabilityId): boolean;
480
+ /** Throws with a single readable message naming every missing capability. */
481
+ require(...caps: CapabilityId[]): void;
482
+ }
483
+ export interface WeaveRuntimeOptions {
484
+ readonly egress?: Partial<RuntimeEgressSlot>;
485
+ /** Pass a real `Tracer` (e.g. `weaveConsoleTracer()` from `@weaveintel/observability`)
486
+ * or `'noop'` (default) for a built-in no-op so core stays dep-free. */
487
+ readonly tracer?: Tracer | 'noop';
488
+ /** When true (default), also calls `weaveSetDefaultTracer(tracer)` so legacy
489
+ * call sites still pick up the tracer. */
490
+ readonly installDefaultTracer?: boolean;
491
+ readonly secrets?: SecretResolver;
492
+ /**
493
+ * Explicit audit logger. When omitted and `persistence` is configured, the
494
+ * runtime automatically attaches a `createDurableAuditLogger` backed by the
495
+ * same persistence slot — so audit entries survive process restarts at zero
496
+ * additional configuration cost. Pass an explicit logger to override.
497
+ */
498
+ readonly audit?: AuditLogger;
499
+ readonly persistence?: RuntimePersistenceSlot;
500
+ readonly resilience?: RuntimeResilienceSlot;
501
+ readonly guardrails?: RuntimeGuardrailsSlot;
502
+ readonly encryption?: RuntimeEncryptionSlot;
503
+ readonly routing?: RuntimeRoutingSlot;
504
+ readonly cost?: RuntimeCostSlot;
505
+ /**
506
+ * Phase 5 — unified memory slot (semantic, working, store, consolidate).
507
+ * Pass a `createRuntimeMemoryAdapter(opts)` instance from `@weaveintel/memory`.
508
+ * When present, `RuntimeCapabilities.Memory` is advertised automatically.
509
+ */
510
+ readonly memory?: RuntimeMemorySlot;
511
+ /**
512
+ * Phase 6 — compliance slot (consent, residency, deletion, GDPR helpers).
513
+ * Pass a `createRuntimeComplianceAdapter(opts)` instance from `@weaveintel/compliance`.
514
+ * When present, `RuntimeCapabilities.Compliance` is advertised automatically.
515
+ */
516
+ readonly compliance?: RuntimeComplianceSlot;
517
+ /**
518
+ * Phase 6 — identity slot (resolve, evaluate, validateDelegation).
519
+ * Pass a `createRuntimeIdentityAdapter(opts)` instance from `@weaveintel/identity`.
520
+ * When present, `RuntimeCapabilities.Identity` is advertised automatically.
521
+ */
522
+ readonly identity?: RuntimeIdentitySlot;
523
+ /**
524
+ * Phase 7 — shared response cache (get, set, invalidate, optional semanticGet).
525
+ * Pass a `createRuntimeCacheAdapter(store, semanticCache?)` instance from
526
+ * `@weaveintel/cache`. When present, `RuntimeCapabilities.Cache` is advertised
527
+ * automatically. Wiring a shared cache here means chat, live-agents, and tools
528
+ * all benefit from the same warm cache within the same process.
529
+ */
530
+ readonly cache?: RuntimeCacheSlot;
531
+ /**
532
+ * Phase 5 — optional `Redactor`. When supplied, every audit entry's
533
+ * `details` object is serialised → redacted → re-parsed before the entry
534
+ * reaches the underlying logger. LLMs and audit stores never see raw PII.
535
+ * The `Redactor` interface is structural; pass any `weaveRedactor(policy)`
536
+ * from `@weaveintel/redaction` or a custom implementation.
537
+ */
538
+ readonly redactor?: Redactor;
539
+ readonly metadata?: Readonly<Record<string, unknown>>;
540
+ /** Extra capability ids to advertise on top of the auto-detected ones.
541
+ * Use this when an external package (e.g. encryption) is configured and
542
+ * should be visible via `runtime.has(...)`. */
543
+ readonly extraCapabilities?: readonly CapabilityId[];
544
+ /**
545
+ * Phase 5 — TLS floor enforcement. When `true` (default), `weaveRuntime`
546
+ * asserts that `NODE_TLS_REJECT_UNAUTHORIZED` is not set to `'0'` at
547
+ * construction time. Set to `false` only in test environments where self-
548
+ * signed certs are unavoidable, never in production. A safety-downgrade
549
+ * audit entry is emitted when the floor is disabled.
550
+ */
551
+ readonly tlsFloor?: boolean;
552
+ }
553
+ /**
554
+ * Phase 5 — TLS floor assertion. Throws when the process has disabled
555
+ * certificate verification (`NODE_TLS_REJECT_UNAUTHORIZED === '0'`), which
556
+ * silently allows MITM attacks on every outbound TLS connection.
557
+ *
558
+ * Called by `weaveRuntime()` at construction unless `tlsFloor: false` is set.
559
+ * In production this should never be suppressed; in test environments with
560
+ * self-signed certificates set the option to `false` and ensure a downgrade
561
+ * audit entry is emitted via `weaveLogSafetyDowngrade`.
562
+ */
563
+ export declare function assertTlsFloor(): void;
564
+ /**
565
+ * Phase 5 — Persistence-backed audit logger. Writes every `AuditEntry` as a
566
+ * JSON string under `${namespace}:${timestamp}:${uuid}` in the runtime KV so
567
+ * audit trails survive process restarts and scale-out deployments.
568
+ *
569
+ * Auto-wired by `weaveRuntime` when a `persistence` slot is configured and no
570
+ * explicit `audit` logger is supplied — zero config required from adopters.
571
+ *
572
+ * Falls back to `weaveInMemoryPersistence()` when no slot is given (matches
573
+ * the DLQ / cost-meter / checkpoint-store pattern).
574
+ */
575
+ export declare function createDurableAuditLogger(opts?: {
576
+ /** Persistence slot to write audit entries into. Falls back to an in-memory
577
+ * slot (zero-config DX) when not supplied — use a durable slot from
578
+ * `@weaveintel/persistence` for restart-safe audit trails. */
579
+ persistence?: RuntimePersistenceSlot;
580
+ namespace?: string;
581
+ }): AuditLogger;
582
+ /**
583
+ * Phase 5 — Auto-redacting audit logger. Wraps an existing `AuditLogger` and
584
+ * passes every entry's `details` through a `Redactor` before forwarding to
585
+ * the inner logger, so PII is stripped from audit trails without any call-site
586
+ * changes. Uses the structural `Redactor` interface — pass any implementation
587
+ * from `@weaveintel/redaction` or a custom one.
588
+ *
589
+ * Auto-wired by `weaveRuntime` when a `redactor` is configured.
590
+ */
591
+ export declare function createRedactingAuditLogger(inner: AuditLogger, redactor: Redactor): AuditLogger;
592
+ /**
593
+ * Construct a runtime. Every slot has a working default so a zero-arg call
594
+ * is the supported golden path for tests and small adopters:
595
+ *
596
+ * const runtime = weaveRuntime();
597
+ * const ctx = weaveContext({ runtime });
598
+ *
599
+ * The runtime is idempotent and side-effect-light: by default it installs
600
+ * the tracer as the framework default tracer so any legacy code that calls
601
+ * `weaveResolveTracer()` still sees it. Set `installDefaultTracer: false`
602
+ * to opt out (e.g. when constructing multiple runtimes in the same process).
603
+ */
604
+ export declare function weaveRuntime(opts?: WeaveRuntimeOptions): WeaveRuntime;
605
+ /**
606
+ * Combine the runtime's advertised capabilities with the framework's auto
607
+ * resolution rules for a single descriptive list — useful for debug endpoints
608
+ * and the admin panel.
609
+ */
610
+ export declare function describeRuntimeCapabilities(runtime: WeaveRuntime): readonly CapabilityId[];
611
+ /**
612
+ * Assert at registration time that the runtime satisfies a feature's
613
+ * declared `requires: [...]`. Returns the runtime for chaining.
614
+ *
615
+ * assertRuntimeRequires(runtime, ['runtime.net.egress', 'runtime.persistence']);
616
+ */
617
+ export declare function assertRuntimeRequires(runtime: WeaveRuntime, requires: readonly (CapabilityId | string)[], featureName?: string): WeaveRuntime;
618
+ /**
619
+ * Best-effort ambient audit emit (Phase 3). Pulls the audit logger from
620
+ * `ctx.runtime?.audit` and emits a structured entry. Swallows its own
621
+ * errors \u2014 audit is never load-bearing. Returns a promise that resolves
622
+ * once the underlying logger has accepted the entry (or immediately if
623
+ * none is wired).
624
+ *
625
+ * await weaveAudit(ctx, { action: 'tool.invoke', outcome: 'success', resource: 'web_search' });
626
+ */
627
+ export declare function weaveAudit(ctx: ExecutionContext, entry: {
628
+ action: string;
629
+ outcome: 'success' | 'failure' | 'denied';
630
+ resource?: string;
631
+ details?: Record<string, unknown>;
632
+ /** OTel span ID for trace joining (Phase 1). */
633
+ spanId?: string;
634
+ /** Caller-supplied correlation ID, e.g. an HTTP request-id (Phase 1). */
635
+ correlationId?: string;
636
+ }): Promise<void>;
637
+ /**
638
+ * Explicit, *loud* downgrade of an ambient default (Phase 3). When an
639
+ * adopter opts out of a default cross-cutting protection (e.g. disables
640
+ * guardrails on a specific agent), call this so a structured audit entry
641
+ * lands in the ambient logger \u2014 you can grep for downgrades in any audit
642
+ * sink. Returns true if an audit was actually emitted.
643
+ *
644
+ * weaveLogSafetyDowngrade(ctx, { feature: 'guardrails', reason: 'trusted-internal' });
645
+ */
646
+ export declare function weaveLogSafetyDowngrade(ctx: ExecutionContext, entry: {
647
+ feature: string;
648
+ reason: string;
649
+ component?: string;
650
+ }): Promise<void>;
651
+ /**
652
+ * Zero-config in-memory persistence slot (Phase 4). Returns the structural
653
+ * `RuntimePersistenceSlot` backed by a Map so every adopter has a working
654
+ * `runtime.persistence.kv` without depending on `@weaveintel/persistence`.
655
+ *
656
+ * - Production adopters should pass a durable slot (e.g.
657
+ * `weaveSqlitePersistence({ path })` from `@weaveintel/persistence`).
658
+ * - In-memory entries are lost on process exit; durable subsystems
659
+ * (`createDurableDeadLetterQueue`, `createDurableCostMeter`, etc.) will
660
+ * transparently survive a restart whenever a durable slot is attached.
661
+ *
662
+ * `ttlMs` is honoured (lazy expiry on read / list).
663
+ */
664
+ export declare function weaveInMemoryPersistence(): RuntimePersistenceSlot;
665
+ //# sourceMappingURL=runtime.d.ts.map