@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,97 @@
1
+ /**
2
+ * @weaveintel/core — Security & redaction contracts
3
+ *
4
+ * Why: Security is built-in, not bolted on. Redaction runs before logging,
5
+ * memory persistence, and any outbound data flow. Policy engines gate
6
+ * tool use, connector access, and content classification.
7
+ */
8
+ import type { ExecutionContext } from './context.js';
9
+ export interface RedactionResult {
10
+ readonly redacted: string;
11
+ readonly detections: readonly Detection[];
12
+ readonly wasModified: boolean;
13
+ }
14
+ export interface Detection {
15
+ readonly type: string;
16
+ readonly start: number;
17
+ readonly end: number;
18
+ readonly original?: string;
19
+ readonly token?: string;
20
+ }
21
+ export interface Redactor {
22
+ redact(ctx: ExecutionContext, text: string): Promise<RedactionResult>;
23
+ restore?(ctx: ExecutionContext, text: string, tokens: Detection[]): Promise<string>;
24
+ }
25
+ export interface RedactionPolicy {
26
+ readonly patterns: readonly RedactionPattern[];
27
+ readonly allowlist?: readonly string[];
28
+ readonly denylist?: readonly string[];
29
+ readonly reversible?: boolean;
30
+ }
31
+ export interface RedactionPattern {
32
+ readonly name: string;
33
+ readonly type: 'regex' | 'builtin' | 'model';
34
+ readonly pattern?: string;
35
+ readonly builtinType?: string;
36
+ readonly replacement?: string;
37
+ }
38
+ export interface ClassificationResult {
39
+ readonly labels: readonly ClassificationLabel[];
40
+ readonly flagged: boolean;
41
+ }
42
+ export interface ClassificationLabel {
43
+ readonly category: string;
44
+ readonly confidence: number;
45
+ readonly flagged: boolean;
46
+ }
47
+ export interface ContentClassifier {
48
+ classify(ctx: ExecutionContext, content: string): Promise<ClassificationResult>;
49
+ }
50
+ export interface PolicyEvaluation {
51
+ readonly allowed: boolean;
52
+ readonly reason?: string;
53
+ readonly policies: readonly string[];
54
+ }
55
+ export interface PolicyRule {
56
+ readonly name: string;
57
+ readonly description?: string;
58
+ evaluate(ctx: ExecutionContext, input: PolicyInput): Promise<PolicyEvaluation>;
59
+ }
60
+ export interface PolicyInput {
61
+ readonly action: string;
62
+ readonly resource?: string;
63
+ readonly data?: Record<string, unknown>;
64
+ }
65
+ export interface PolicyEngine {
66
+ addRule(rule: PolicyRule): void;
67
+ evaluate(ctx: ExecutionContext, input: PolicyInput): Promise<PolicyEvaluation>;
68
+ }
69
+ export interface AccessEvaluator {
70
+ canAccess(ctx: ExecutionContext, resource: string, action: string): Promise<{
71
+ allowed: boolean;
72
+ reason?: string;
73
+ }>;
74
+ }
75
+ export interface AuditEntry {
76
+ readonly timestamp: string;
77
+ readonly executionId: string;
78
+ readonly tenantId?: string;
79
+ readonly userId?: string;
80
+ readonly action: string;
81
+ readonly resource?: string;
82
+ readonly outcome: 'success' | 'failure' | 'denied';
83
+ readonly details?: Record<string, unknown>;
84
+ /** OTel span ID of the active span at the time of the audit event.
85
+ * Allows joining audit rows to OTel traces in observability platforms. */
86
+ readonly spanId?: string;
87
+ /** Caller-supplied correlation ID (e.g. HTTP request-id, traceId).
88
+ * Propagate as X-Correlation-ID from the inbound request. */
89
+ readonly correlationId?: string;
90
+ }
91
+ export interface AuditLogger {
92
+ log(entry: AuditEntry): Promise<void>;
93
+ }
94
+ export interface SecretResolver {
95
+ resolve(key: string): Promise<string | undefined>;
96
+ }
97
+ //# sourceMappingURL=security.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"security.d.ts","sourceRoot":"","sources":["../src/security.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAIrD,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,UAAU,EAAE,SAAS,SAAS,EAAE,CAAC;IAC1C,QAAQ,CAAC,WAAW,EAAE,OAAO,CAAC;CAC/B;AAED,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,MAAM,WAAW,QAAQ;IACvB,MAAM,CAAC,GAAG,EAAE,gBAAgB,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC,CAAC;IACtE,OAAO,CAAC,CAAC,GAAG,EAAE,gBAAgB,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM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AC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC3C;+EAC2E;IAC3E,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB;kEAC8D;IAC9D,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,CAAC;CACjC;AAED,MAAM,WAAW,WAAW;IAC1B,GAAG,CAAC,KAAK,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACvC;AAID,MAAM,WAAW,cAAc;IAC7B,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAAC;CACnD"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * @weaveintel/core — Security & redaction contracts
3
+ *
4
+ * Why: Security is built-in, not bolted on. Redaction runs before logging,
5
+ * memory persistence, and any outbound data flow. Policy engines gate
6
+ * tool use, connector access, and content classification.
7
+ */
8
+ export {};
9
+ //# sourceMappingURL=security.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"security.js","sourceRoot":"","sources":["../src/security.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG"}
@@ -0,0 +1,67 @@
1
+ /**
2
+ * parseSseStream — THE canonical SSE byte→event decoder for the platform.
3
+ *
4
+ * Collaboration Phase 0 (de-duplication): this used to be re-implemented in
5
+ * three places — `@weaveintel/client` (the run-stream transport), `@weaveintel/a2a`
6
+ * (the agent-to-agent SSE reader), and `apps/geneweave-ui`. It now lives once in
7
+ * `@weaveintel/core` (the dependency-light, browser-safe contracts package) and
8
+ * everyone else consumes it. `@weaveintel/client` re-exports it; `@weaveintel/a2a`
9
+ * layers a JSON `.map` on top.
10
+ *
11
+ * --- For someone new to this ---
12
+ * "SSE" = Server-Sent Events: a simple text protocol where a server streams a
13
+ * series of events to a client over one long-lived HTTP response. Each event is
14
+ * a few `key: value` lines (`data:`, `event:`, …) followed by a blank line. This
15
+ * function turns the raw bytes of that stream into one {@link SseEvent} object
16
+ * per event, so callers can just `for await` over events instead of fiddling
17
+ * with byte buffers and line splitting.
18
+ *
19
+ * It follows the WHATWG `text/event-stream` rules (HTML §9.2): one `TextDecoder`
20
+ * per stream (so a multi-byte character split across two network chunks decodes
21
+ * correctly), LF/CRLF/CR line endings, `data:` values joined with `\n`, `:comment`
22
+ * keepalive lines ignored, dispatch on a blank line, and a trailing record
23
+ * flushed if the stream ends without a final blank line. `id:`/`retry:` are
24
+ * accepted-and-ignored (the run protocol carries its own sequence numbers).
25
+ *
26
+ * It adds two ergonomics the spec leaves to the host: an optional **stall
27
+ * timeout** (reject if no bytes arrive within a window, so a dead connection
28
+ * can't hang forever) and **cooperative cancellation** (abort via an
29
+ * `AbortSignal`, or just `break` the loop — either cancels the underlying
30
+ * reader).
31
+ *
32
+ * NOTE: browser-safe — uses only `ReadableStream` + `TextDecoder`; no Node APIs.
33
+ */
34
+ /** A single decoded SSE record. */
35
+ export interface SseEvent {
36
+ /** The joined `data:` payload (the empty string for a data-less record). */
37
+ data: string;
38
+ /** The `event:` field, when present. */
39
+ event?: string;
40
+ /**
41
+ * The `id:` field, when present (Collaboration Phase 6). Browsers echo the last
42
+ * id back as `Last-Event-ID` on reconnect; a Node consumer can read it here to
43
+ * drive its own resume cursor.
44
+ */
45
+ id?: string;
46
+ }
47
+ export interface ParseSseOptions {
48
+ /** Abort the read (and cancel the reader) when this fires. */
49
+ signal?: AbortSignal;
50
+ /**
51
+ * Reject with a stall error if no bytes arrive within this window (ms).
52
+ * 0 / undefined disables the timeout.
53
+ */
54
+ stallTimeoutMs?: number;
55
+ }
56
+ /** Thrown when `stallTimeoutMs` elapses with no incoming bytes. */
57
+ export declare class SseStallError extends Error {
58
+ constructor(ms: number);
59
+ }
60
+ /**
61
+ * Decode an SSE byte stream into discrete events.
62
+ *
63
+ * Consume with `for await (const ev of parseSseStream(stream, opts)) { ... }`.
64
+ * `break`ing the loop (or aborting `opts.signal`) cancels the reader.
65
+ */
66
+ export declare function parseSseStream(stream: ReadableStream<Uint8Array>, opts?: ParseSseOptions): AsyncGenerator<SseEvent, void, unknown>;
67
+ //# sourceMappingURL=sse-parser.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sse-parser.d.ts","sourceRoot":"","sources":["../src/sse-parser.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AAEH,mCAAmC;AACnC,MAAM,WAAW,QAAQ;IACvB,4EAA4E;IAC5E,IAAI,EAAE,MAAM,CAAC;IACb,wCAAwC;IACxC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;;;OAIG;IACH,EAAE,CAAC,EAAE,MAAM,CAAC;CACb;AAED,MAAM,WAAW,eAAe;IAC9B,8DAA8D;IAC9D,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB;;;OAGG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,mEAAmE;AACnE,qBAAa,aAAc,SAAQ,KAAK;gBAC1B,EAAE,EAAE,MAAM;CAIvB;AAED;;;;;GAKG;AACH,wBAAuB,cAAc,CACnC,MAAM,EAAE,cAAc,CAAC,UAAU,CAAC,EAClC,IAAI,GAAE,eAAoB,GACzB,cAAc,CAAC,QAAQ,EAAE,IAAI,EAAE,OAAO,CAAC,CAmGzC"}
@@ -0,0 +1,156 @@
1
+ /**
2
+ * parseSseStream — THE canonical SSE byte→event decoder for the platform.
3
+ *
4
+ * Collaboration Phase 0 (de-duplication): this used to be re-implemented in
5
+ * three places — `@weaveintel/client` (the run-stream transport), `@weaveintel/a2a`
6
+ * (the agent-to-agent SSE reader), and `apps/geneweave-ui`. It now lives once in
7
+ * `@weaveintel/core` (the dependency-light, browser-safe contracts package) and
8
+ * everyone else consumes it. `@weaveintel/client` re-exports it; `@weaveintel/a2a`
9
+ * layers a JSON `.map` on top.
10
+ *
11
+ * --- For someone new to this ---
12
+ * "SSE" = Server-Sent Events: a simple text protocol where a server streams a
13
+ * series of events to a client over one long-lived HTTP response. Each event is
14
+ * a few `key: value` lines (`data:`, `event:`, …) followed by a blank line. This
15
+ * function turns the raw bytes of that stream into one {@link SseEvent} object
16
+ * per event, so callers can just `for await` over events instead of fiddling
17
+ * with byte buffers and line splitting.
18
+ *
19
+ * It follows the WHATWG `text/event-stream` rules (HTML §9.2): one `TextDecoder`
20
+ * per stream (so a multi-byte character split across two network chunks decodes
21
+ * correctly), LF/CRLF/CR line endings, `data:` values joined with `\n`, `:comment`
22
+ * keepalive lines ignored, dispatch on a blank line, and a trailing record
23
+ * flushed if the stream ends without a final blank line. `id:`/`retry:` are
24
+ * accepted-and-ignored (the run protocol carries its own sequence numbers).
25
+ *
26
+ * It adds two ergonomics the spec leaves to the host: an optional **stall
27
+ * timeout** (reject if no bytes arrive within a window, so a dead connection
28
+ * can't hang forever) and **cooperative cancellation** (abort via an
29
+ * `AbortSignal`, or just `break` the loop — either cancels the underlying
30
+ * reader).
31
+ *
32
+ * NOTE: browser-safe — uses only `ReadableStream` + `TextDecoder`; no Node APIs.
33
+ */
34
+ /** Thrown when `stallTimeoutMs` elapses with no incoming bytes. */
35
+ export class SseStallError extends Error {
36
+ constructor(ms) {
37
+ super(`SSE stream stalled — no data within ${ms}ms`);
38
+ this.name = 'SseStallError';
39
+ }
40
+ }
41
+ /**
42
+ * Decode an SSE byte stream into discrete events.
43
+ *
44
+ * Consume with `for await (const ev of parseSseStream(stream, opts)) { ... }`.
45
+ * `break`ing the loop (or aborting `opts.signal`) cancels the reader.
46
+ */
47
+ export async function* parseSseStream(stream, opts = {}) {
48
+ const { signal, stallTimeoutMs = 0 } = opts;
49
+ if (signal?.aborted)
50
+ return;
51
+ const reader = stream.getReader();
52
+ const decoder = new TextDecoder();
53
+ let buf = '';
54
+ let dataLines = [];
55
+ let currentEvent;
56
+ let currentId;
57
+ // Apply one already-CR-stripped line to the in-progress record.
58
+ const applyLine = (line) => {
59
+ if (line.startsWith(':'))
60
+ return; // comment / keepalive
61
+ if (line.startsWith('event:'))
62
+ currentEvent = line.slice(6).trim();
63
+ else if (line.startsWith('data:'))
64
+ dataLines.push(line.slice(5).replace(/^ /, ''));
65
+ else if (line.startsWith('id:'))
66
+ currentId = line.slice(3).replace(/^ /, ''); // Phase 6: surfaced for Last-Event-ID
67
+ // `retry:` and any other field — ignored by the run protocol.
68
+ };
69
+ // Drain a completed record (blank-line boundary or end-of-stream). A record
70
+ // with no `data:` line and no `event:` is whitespace/keepalive — skipped.
71
+ const take = () => {
72
+ if (dataLines.length === 0 && currentEvent === undefined) {
73
+ currentId = undefined;
74
+ return null;
75
+ }
76
+ const data = dataLines.join('\n');
77
+ const evName = currentEvent;
78
+ const evId = currentId;
79
+ dataLines = [];
80
+ currentEvent = undefined;
81
+ currentId = undefined;
82
+ return {
83
+ data,
84
+ ...(evName !== undefined ? { event: evName } : {}),
85
+ ...(evId !== undefined ? { id: evId } : {}),
86
+ };
87
+ };
88
+ // Resolve abort as a clean end (not an error), racing it against read().
89
+ let onAbort;
90
+ const abortPromise = signal
91
+ ? new Promise((resolve) => {
92
+ onAbort = () => resolve({ aborted: true });
93
+ signal.addEventListener('abort', onAbort, { once: true });
94
+ })
95
+ : null;
96
+ try {
97
+ while (true) {
98
+ let timer;
99
+ const races = [
100
+ reader.read(),
101
+ ];
102
+ if (abortPromise)
103
+ races.push(abortPromise);
104
+ if (stallTimeoutMs > 0) {
105
+ races.push(new Promise((_, reject) => {
106
+ timer = setTimeout(() => reject(new SseStallError(stallTimeoutMs)), stallTimeoutMs);
107
+ }));
108
+ }
109
+ let result;
110
+ try {
111
+ result = await Promise.race(races);
112
+ }
113
+ finally {
114
+ if (timer)
115
+ clearTimeout(timer);
116
+ }
117
+ if ('aborted' in result)
118
+ break;
119
+ if (result.done)
120
+ break;
121
+ buf += decoder.decode(result.value, { stream: true });
122
+ // Split on LF; the per-line `\r` strip below absorbs a trailing CR (CRLF).
123
+ const lines = buf.split('\n');
124
+ buf = lines.pop() ?? '';
125
+ for (const raw of lines) {
126
+ const line = raw.replace(/\r$/, '');
127
+ if (line === '') {
128
+ const ev = take();
129
+ if (ev)
130
+ yield ev;
131
+ }
132
+ else {
133
+ applyLine(line);
134
+ }
135
+ }
136
+ }
137
+ // The stream ended: parse any trailing partial line still in the buffer,
138
+ // then flush a final record if it had no terminating blank line.
139
+ if (buf.length > 0)
140
+ applyLine(buf.replace(/\r$/, ''));
141
+ const tail = take();
142
+ if (tail)
143
+ yield tail;
144
+ }
145
+ finally {
146
+ if (signal && onAbort)
147
+ signal.removeEventListener('abort', onAbort);
148
+ try {
149
+ await reader.cancel();
150
+ }
151
+ catch {
152
+ /* already closed */
153
+ }
154
+ }
155
+ }
156
+ //# sourceMappingURL=sse-parser.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sse-parser.js","sourceRoot":"","sources":["../src/sse-parser.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AA0BH,mEAAmE;AACnE,MAAM,OAAO,aAAc,SAAQ,KAAK;IACtC,YAAY,EAAU;QACpB,KAAK,CAAC,uCAAuC,EAAE,IAAI,CAAC,CAAC;QACrD,IAAI,CAAC,IAAI,GAAG,eAAe,CAAC;IAC9B,CAAC;CACF;AAED;;;;;GAKG;AACH,MAAM,CAAC,KAAK,SAAS,CAAC,CAAC,cAAc,CACnC,MAAkC,EAClC,OAAwB,EAAE;IAE1B,MAAM,EAAE,MAAM,EAAE,cAAc,GAAG,CAAC,EAAE,GAAG,IAAI,CAAC;IAC5C,IAAI,MAAM,EAAE,OAAO;QAAE,OAAO;IAE5B,MAAM,MAAM,GAAG,MAAM,CAAC,SAAS,EAAE,CAAC;IAClC,MAAM,OAAO,GAAG,IAAI,WAAW,EAAE,CAAC;IAClC,IAAI,GAAG,GAAG,EAAE,CAAC;IACb,IAAI,SAAS,GAAa,EAAE,CAAC;IAC7B,IAAI,YAAgC,CAAC;IACrC,IAAI,SAA6B,CAAC;IAElC,gEAAgE;IAChE,MAAM,SAAS,GAAG,CAAC,IAAY,EA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AEvB,GAAG,IAAI,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC;YACtD,2EAA2E;YAC3E,MAAM,KAAK,GAAG,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;YAC9B,GAAG,GAAG,KAAK,CAAC,GAAG,EAAE,IAAI,EAAE,CAAC;YAExB,KAAK,MAAM,GAAG,IAAI,KAAK,EAAE,CAAC;gBACxB,MAAM,IAAI,GAAG,GAAG,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;gBACpC,IAAI,IAAI,KAAK,EAAE,EAAE,CAAC;oBAChB,MAAM,EAAE,GAAG,IAAI,EAAE,CAAC;oBAClB,IAAI,EAAE;wBAAE,MAAM,EAAE,CAAC;gBACnB,CAAC;qBAAM,CAAC;oBACN,SAAS,CAAC,IAAI,CAAC,CAAC;gBAClB,CAAC;YACH,CAAC;QACH,CAAC;QACD,yEAAyE;QACzE,iEAAiE;QACjE,IAAI,GAAG,CAAC,MAAM,GAAG,CAAC;YAAE,SAAS,CAAC,GAAG,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,CAAC;QACtD,MAAM,IAAI,GAAG,IAAI,EAAE,CAAC;QACpB,IAAI,IAAI;YAAE,MAAM,IAAI,CAAC;IACvB,CAAC;YAAS,CAAC;QACT,IAAI,MAAM,IAAI,OAAO;YAAE,MAAM,CAAC,mBAAmB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QACpE,IAAI,CAAC;YACH,MAAM,MAAM,CAAC,MAAM,EAAE,CAAC;QACxB,CAAC;QAAC,MAAM,CAAC;YACP,oBAAoB;QACtB,CAAC;IACH,CAAC;AACH,CAAC"}
@@ -0,0 +1,63 @@
1
+ /**
2
+ * Server-Sent Events WRITER (Collaboration Phase 6) — the emit half of the SSE
3
+ * transport. `@weaveintel/core` already owns the canonical READER
4
+ * (`parseSseStream`); this is its counterpart so the geneWeave run-stream route,
5
+ * the a2a server, and any other producer format frames ONE way instead of three.
6
+ *
7
+ * --- For someone new to this ---
8
+ * "Server-Sent Events" is a dead-simple streaming format: the server writes lines
9
+ * of text, the browser's `EventSource` reads them. Each event looks like:
10
+ * id: 42
11
+ * event: message
12
+ * data: {"hello":"world"}
13
+ * <blank line>
14
+ * The blank line ends the event. This module just builds that text correctly —
15
+ * including the bits that make a stream RESUMABLE and proxy-proof:
16
+ * - `id:` on every event → on reconnect the browser auto-sends the last id back
17
+ * in the `Last-Event-ID` header, so the server can replay only what was missed.
18
+ * - `retry:` → tells the browser how long to wait before reconnecting.
19
+ * - comment frames (`: keepalive`) → keep idle proxies from killing the stream.
20
+ *
21
+ * Pure string formatting (browser-safe); the optional `writeSse*` helpers take any
22
+ * object with a `write` method so they work with a Node `ServerResponse` without
23
+ * importing `node:http`.
24
+ */
25
+ /** Minimal sink — a Node `ServerResponse` satisfies this without importing http. */
26
+ export interface SseSink {
27
+ write(chunk: string): boolean | void;
28
+ }
29
+ /** Response headers that make an SSE stream behave (no caching, no proxy buffering). */
30
+ export declare const SSE_RESPONSE_HEADERS: Record<string, string>;
31
+ export interface SseFrame {
32
+ /** Event id — echoed back by the browser as `Last-Event-ID` on reconnect. */
33
+ id?: string | number;
34
+ /** Named event type (`event:` line). Omit for the default `message` event. */
35
+ event?: string;
36
+ /** The payload. Objects are JSON-encoded; strings are sent verbatim. */
37
+ data: unknown;
38
+ /** Reconnection delay hint (ms) — emitted as a `retry:` line. */
39
+ retry?: number;
40
+ }
41
+ /**
42
+ * Format one SSE frame as wire text (ending in the blank-line separator).
43
+ * Multi-line data is split across multiple `data:` lines per the SSE spec.
44
+ */
45
+ export declare function formatSseFrame(frame: SseFrame): string;
46
+ /** A heartbeat comment frame (`: keepalive`) — ignored by clients, defeats idle timeouts. */
47
+ export declare function formatSseComment(text?: string): string;
48
+ /** Write a formatted SSE frame to a sink. Returns false if the sink rejected the write. */
49
+ export declare function writeSseFrame(sink: SseSink, frame: SseFrame): boolean;
50
+ /** Write a keepalive comment to a sink. */
51
+ export declare function writeSseComment(sink: SseSink, text?: string): boolean;
52
+ /**
53
+ * Resolve the resume cursor for a request: the standard `Last-Event-ID` header
54
+ * (sent automatically by `EventSource` on reconnect) takes precedence, falling
55
+ * back to an explicit `?after=` query value, else `defaultAfter`. Returns the
56
+ * numeric sequence to resume AFTER. Non-numeric/empty ids fall through.
57
+ */
58
+ export declare function resolveResumeCursor(opts: {
59
+ lastEventId?: string | null;
60
+ afterParam?: string | null;
61
+ defaultAfter?: number;
62
+ }): number;
63
+ //# sourceMappingURL=sse-writer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sse-writer.d.ts","sourceRoot":"","sources":["../src/sse-writer.ts"],"names":[],"mappings":"AACA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,oFAAoF;AACpF,MAAM,WAAW,OAAO;IACtB,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,GAAG,IAAI,CAAC;CACtC;AAED,wFAAwF;AACxF,eAAO,MAAM,oBAAoB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAKvD,CAAC;AAEF,MAAM,WAAW,QAAQ;IACvB,6EAA6E;IAC7E,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACrB,8EAA8E;IAC9E,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,wEAAwE;IACxE,IAAI,EAAE,OAAO,CAAC;IACd,iEAAiE;IACjE,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,QAAQ,GAAG,MAAM,CAQtD;AAED,6FAA6F;AAC7F,wBAAgB,gBAAgB,CAAC,IAAI,SAAc,GAAG,MAAM,CAE3D;AAED,2FAA2F;AAC3F,wBAAgB,aAAa,CAAC,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,QAAQ,GAAG,OAAO,CAErE;AAED,2CAA2C;AAC3C,wBAAgB,eAAe,CAAC,IAAI,EAAE,OAAO,EAAE,IAAI,SAAc,GAAG,OAAO,CAE1E;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE;IAAE,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,YAAY,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,MAAM,CAMpI"}
@@ -0,0 +1,87 @@
1
+ // SPDX-License-Identifier: MIT
2
+ /**
3
+ * Server-Sent Events WRITER (Collaboration Phase 6) — the emit half of the SSE
4
+ * transport. `@weaveintel/core` already owns the canonical READER
5
+ * (`parseSseStream`); this is its counterpart so the geneWeave run-stream route,
6
+ * the a2a server, and any other producer format frames ONE way instead of three.
7
+ *
8
+ * --- For someone new to this ---
9
+ * "Server-Sent Events" is a dead-simple streaming format: the server writes lines
10
+ * of text, the browser's `EventSource` reads them. Each event looks like:
11
+ * id: 42
12
+ * event: message
13
+ * data: {"hello":"world"}
14
+ * <blank line>
15
+ * The blank line ends the event. This module just builds that text correctly —
16
+ * including the bits that make a stream RESUMABLE and proxy-proof:
17
+ * - `id:` on every event → on reconnect the browser auto-sends the last id back
18
+ * in the `Last-Event-ID` header, so the server can replay only what was missed.
19
+ * - `retry:` → tells the browser how long to wait before reconnecting.
20
+ * - comment frames (`: keepalive`) → keep idle proxies from killing the stream.
21
+ *
22
+ * Pure string formatting (browser-safe); the optional `writeSse*` helpers take any
23
+ * object with a `write` method so they work with a Node `ServerResponse` without
24
+ * importing `node:http`.
25
+ */
26
+ /** Response headers that make an SSE stream behave (no caching, no proxy buffering). */
27
+ export const SSE_RESPONSE_HEADERS = {
28
+ 'Content-Type': 'text/event-stream',
29
+ 'Cache-Control': 'no-cache, no-transform',
30
+ 'Connection': 'keep-alive',
31
+ 'X-Accel-Buffering': 'no', // disable nginx proxy buffering
32
+ };
33
+ /**
34
+ * Format one SSE frame as wire text (ending in the blank-line separator).
35
+ * Multi-line data is split across multiple `data:` lines per the SSE spec.
36
+ */
37
+ export function formatSseFrame(frame) {
38
+ let out = '';
39
+ if (frame.id !== undefined)
40
+ out += `id: ${String(frame.id)}\n`;
41
+ if (frame.event !== undefined)
42
+ out += `event: ${frame.event}\n`;
43
+ if (frame.retry !== undefined)
44
+ out += `retry: ${Math.max(0, Math.floor(frame.retry))}\n`;
45
+ const text = typeof frame.data === 'string' ? frame.data : JSON.stringify(frame.data);
46
+ for (const line of text.split('\n'))
47
+ out += `data: ${line}\n`;
48
+ return `${out}\n`;
49
+ }
50
+ /** A heartbeat comment frame (`: keepalive`) — ignored by clients, defeats idle timeouts. */
51
+ export function formatSseComment(text = 'keepalive') {
52
+ return `: ${text}\n\n`;
53
+ }
54
+ /** Write a formatted SSE frame to a sink. Returns false if the sink rejected the write. */
55
+ export function writeSseFrame(sink, frame) {
56
+ try {
57
+ return sink.write(formatSseFrame(frame)) !== false;
58
+ }
59
+ catch {
60
+ return false;
61
+ }
62
+ }
63
+ /** Write a keepalive comment to a sink. */
64
+ export function writeSseComment(sink, text = 'keepalive') {
65
+ try {
66
+ return sink.write(formatSseComment(text)) !== false;
67
+ }
68
+ catch {
69
+ return false;
70
+ }
71
+ }
72
+ /**
73
+ * Resolve the resume cursor for a request: the standard `Last-Event-ID` header
74
+ * (sent automatically by `EventSource` on reconnect) takes precedence, falling
75
+ * back to an explicit `?after=` query value, else `defaultAfter`. Returns the
76
+ * numeric sequence to resume AFTER. Non-numeric/empty ids fall through.
77
+ */
78
+ export function resolveResumeCursor(opts) {
79
+ const fromHeader = opts.lastEventId != null && opts.lastEventId !== '' ? Number(opts.lastEventId) : NaN;
80
+ if (Number.isFinite(fromHeader))
81
+ return fromHeader;
82
+ const fromParam = opts.afterParam != null && opts.afterParam !== '' ? Number(opts.afterParam) : NaN;
83
+ if (Number.isFinite(fromParam))
84
+ return fromParam;
85
+ return opts.defaultAfter ?? -1;
86
+ }
87
+ //# sourceMappingURL=sse-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voice, …).
5
+ * The surface catalog tells a client which capabilities (modes, agents, models,
6
+ * skills, tools) are available to a particular principal on a particular surface.
7
+ *
8
+ * The resolver lives in `@weaveintel/identity`; sources are supplied by the app.
9
+ *
10
+ * Vocabulary rule: no "chat" / "conversation" / "message" / "turn" vocabulary.
11
+ */
12
+ import type { ExecutionContext } from './context.js';
13
+ /**
14
+ * Input to a surface catalog resolution.
15
+ * `surfaceId` is app-defined (e.g. `'mobile'`, `'desktop'`, `'web'`).
16
+ */
17
+ export interface SurfaceCatalogRequest {
18
+ readonly surfaceId: string;
19
+ }
20
+ /**
21
+ * A single capability entry in the catalog.
22
+ *
23
+ * Entries are resolved from DB-backed sources and filtered by the access-check
24
+ * policy in the resolver. Entries that fail the access check are excluded; the
25
+ * error is logged but never surfaced to the caller (fail-closed).
26
+ */
27
+ export interface CatalogEntry {
28
+ /** Stable unique identifier for this entry within the tenant. */
29
+ readonly id: string;
30
+ /**
31
+ * Discriminant used by clients to render the correct UI affordance.
32
+ * - `mode` — an operating mode (e.g. "Assistant", "Agent", "Team").
33
+ * - `agent` — a named live-agent configuration.
34
+ * - `model` — a model deployment the principal may select.
35
+ * - `skill` — a reusable skill pack.
36
+ * - `tool` — a tool from the operator tool catalog.
37
+ * - `custom` — application-defined; clients use `metadata` for rendering hints.
38
+ */
39
+ readonly kind: 'mode' | 'agent' | 'model' | 'skill' | 'tool' | 'custom';
40
+ /** Human-readable display name. */
41
+ readonly label: string;
42
+ /** Optional short description for tooltips / onboarding. */
43
+ readonly description?: string;
44
+ /** Whether this entry should be pre-selected when the surface opens. */
45
+ readonly default?: boolean;
46
+ /** Arbitrary app-defined hints (icon, color, feature flags, etc.). */
47
+ readonly metadata?: Record<string, unknown>;
48
+ }
49
+ /**
50
+ * The resolved catalog for a specific principal + surface combination.
51
+ */
52
+ export interface SurfaceCatalog {
53
+ readonly surfaceId: string;
54
+ readonly entries: readonly CatalogEntry[];
55
+ /** ISO-8601 timestamp of resolution — used for cache TTL display. */
56
+ readonly resolvedAt: string;
57
+ }
58
+ /**
59
+ * Implemented by `@weaveintel/identity` `createSurfaceCatalogResolver(...)`.
60
+ *
61
+ * Callers supply the `ExecutionContext` (for principal + tenant scoping) and a
62
+ * `SurfaceCatalogRequest`; the resolver handles filtering, caching, and emitting
63
+ * the `catalog.resolved` observability event.
64
+ */
65
+ export interface SurfaceCatalogResolver {
66
+ resolve(ctx: ExecutionContext, req: SurfaceCatalogRequest): Promise<SurfaceCatalog>;
67
+ }
68
+ //# sourceMappingURL=surface-catalog.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"surface-catalog.d.ts","sourceRoot":"","sources":["../src/surface-catalog.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAIrD;;;GAGG;AACH,MAAM,WAAW,qBAAqB;IACpC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;CAC5B;AAID;;;;;;GAMG;AACH,MAAM,WAAW,YAAY;IAC3B,iEAAiE;IACjE,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB;;;;;;;;OAQG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,GAAG,OAAO,GAAG,OAAO,GAAG,MAAM,GAAG,QAAQ,CAAC;IACxE,mCAAmC;IACnC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,4DAA4D;IAC5D,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B,wEAAwE;IACxE,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC;IAC3B,sEAAsE;IACtE,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC7C;AAID;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,OAAO,EAAE,SAAS,YAAY,EAAE,CAAC;IAC1C,qEAAqE;IACrE,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;CAC7B;AAID;;;;;;GAMG;AACH,MAAM,WAAW,sBAAsB;IACrC,OAAO,CAAC,GAAG,EAAE,gBAAgB,EAAE,GAAG,EAAE,qBAAqB,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC;CACrF"}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * @weaveintel/core — Surface catalog contracts
3
+ *
4
+ * A *surface* is a specific client context (mobile, desktop, web, voice, …).
5
+ * The surface catalog tells a client which capabilities (modes, agents, models,
6
+ * skills, tools) are available to a particular principal on a particular surface.
7
+ *
8
+ * The resolver lives in `@weaveintel/identity`; sources are supplied by the app.
9
+ *
10
+ * Vocabulary rule: no "chat" / "conversation" / "message" / "turn" vocabulary.
11
+ */
12
+ export {};
13
+ //# sourceMappingURL=surface-catalog.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"surface-catalog.js","sourceRoot":"","sources":["../src/surface-catalog.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG"}