@rarebit-one/harness-kernel 0.5.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 (163) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +286 -0
  3. package/dist/agent.d.ts +71 -0
  4. package/dist/agent.d.ts.map +1 -0
  5. package/dist/agent.js +258 -0
  6. package/dist/agent.js.map +1 -0
  7. package/dist/connectors/mcpClient.d.ts +22 -0
  8. package/dist/connectors/mcpClient.d.ts.map +1 -0
  9. package/dist/connectors/mcpClient.js +63 -0
  10. package/dist/connectors/mcpClient.js.map +1 -0
  11. package/dist/context/types.d.ts +68 -0
  12. package/dist/context/types.d.ts.map +1 -0
  13. package/dist/context/types.js +43 -0
  14. package/dist/context/types.js.map +1 -0
  15. package/dist/engines/capability.d.ts +67 -0
  16. package/dist/engines/capability.d.ts.map +1 -0
  17. package/dist/engines/capability.js +73 -0
  18. package/dist/engines/capability.js.map +1 -0
  19. package/dist/engines/capabilityEmissions.d.ts +27 -0
  20. package/dist/engines/capabilityEmissions.d.ts.map +1 -0
  21. package/dist/engines/capabilityEmissions.js +37 -0
  22. package/dist/engines/capabilityEmissions.js.map +1 -0
  23. package/dist/engines/capabilityMcp.d.ts +23 -0
  24. package/dist/engines/capabilityMcp.d.ts.map +1 -0
  25. package/dist/engines/capabilityMcp.js +36 -0
  26. package/dist/engines/capabilityMcp.js.map +1 -0
  27. package/dist/engines/capabilityStdio.d.ts +46 -0
  28. package/dist/engines/capabilityStdio.d.ts.map +1 -0
  29. package/dist/engines/capabilityStdio.js +39 -0
  30. package/dist/engines/capabilityStdio.js.map +1 -0
  31. package/dist/engines/claudeCode.d.ts +73 -0
  32. package/dist/engines/claudeCode.d.ts.map +1 -0
  33. package/dist/engines/claudeCode.js +100 -0
  34. package/dist/engines/claudeCode.js.map +1 -0
  35. package/dist/engines/claudeCodeDriver.d.ts +14 -0
  36. package/dist/engines/claudeCodeDriver.d.ts.map +1 -0
  37. package/dist/engines/claudeCodeDriver.js +90 -0
  38. package/dist/engines/claudeCodeDriver.js.map +1 -0
  39. package/dist/engines/codex.d.ts +72 -0
  40. package/dist/engines/codex.d.ts.map +1 -0
  41. package/dist/engines/codex.js +157 -0
  42. package/dist/engines/codex.js.map +1 -0
  43. package/dist/engines/codexDriver.d.ts +43 -0
  44. package/dist/engines/codexDriver.d.ts.map +1 -0
  45. package/dist/engines/codexDriver.js +110 -0
  46. package/dist/engines/codexDriver.js.map +1 -0
  47. package/dist/engines/connectorMcp.d.ts +60 -0
  48. package/dist/engines/connectorMcp.d.ts.map +1 -0
  49. package/dist/engines/connectorMcp.js +137 -0
  50. package/dist/engines/connectorMcp.js.map +1 -0
  51. package/dist/engines/index.d.ts +33 -0
  52. package/dist/engines/index.d.ts.map +1 -0
  53. package/dist/engines/index.js +29 -0
  54. package/dist/engines/index.js.map +1 -0
  55. package/dist/engines/native.d.ts +55 -0
  56. package/dist/engines/native.d.ts.map +1 -0
  57. package/dist/engines/native.js +117 -0
  58. package/dist/engines/native.js.map +1 -0
  59. package/dist/engines/types.d.ts +107 -0
  60. package/dist/engines/types.d.ts.map +1 -0
  61. package/dist/engines/types.js +2 -0
  62. package/dist/engines/types.js.map +1 -0
  63. package/dist/events.d.ts +211 -0
  64. package/dist/events.d.ts.map +1 -0
  65. package/dist/events.js +69 -0
  66. package/dist/events.js.map +1 -0
  67. package/dist/index.d.ts +63 -0
  68. package/dist/index.d.ts.map +1 -0
  69. package/dist/index.js +82 -0
  70. package/dist/index.js.map +1 -0
  71. package/dist/loop.d.ts +132 -0
  72. package/dist/loop.d.ts.map +1 -0
  73. package/dist/loop.js +77 -0
  74. package/dist/loop.js.map +1 -0
  75. package/dist/models/chat.d.ts +65 -0
  76. package/dist/models/chat.d.ts.map +1 -0
  77. package/dist/models/chat.js +66 -0
  78. package/dist/models/chat.js.map +1 -0
  79. package/dist/models/middleware.d.ts +63 -0
  80. package/dist/models/middleware.d.ts.map +1 -0
  81. package/dist/models/middleware.js +139 -0
  82. package/dist/models/middleware.js.map +1 -0
  83. package/dist/models/registry.d.ts +78 -0
  84. package/dist/models/registry.d.ts.map +1 -0
  85. package/dist/models/registry.js +0 -0
  86. package/dist/models/registry.js.map +1 -0
  87. package/dist/models/types.d.ts +149 -0
  88. package/dist/models/types.d.ts.map +1 -0
  89. package/dist/models/types.js +64 -0
  90. package/dist/models/types.js.map +1 -0
  91. package/dist/primitives/codeExec.d.ts +25 -0
  92. package/dist/primitives/codeExec.d.ts.map +1 -0
  93. package/dist/primitives/codeExec.js +69 -0
  94. package/dist/primitives/codeExec.js.map +1 -0
  95. package/dist/primitives/download.d.ts +19 -0
  96. package/dist/primitives/download.d.ts.map +1 -0
  97. package/dist/primitives/download.js +113 -0
  98. package/dist/primitives/download.js.map +1 -0
  99. package/dist/primitives/fs.d.ts +5 -0
  100. package/dist/primitives/fs.d.ts.map +1 -0
  101. package/dist/primitives/fs.js +59 -0
  102. package/dist/primitives/fs.js.map +1 -0
  103. package/dist/primitives/http.d.ts +100 -0
  104. package/dist/primitives/http.d.ts.map +1 -0
  105. package/dist/primitives/http.js +257 -0
  106. package/dist/primitives/http.js.map +1 -0
  107. package/dist/providers/anthropic.d.ts +15 -0
  108. package/dist/providers/anthropic.d.ts.map +1 -0
  109. package/dist/providers/anthropic.js +90 -0
  110. package/dist/providers/anthropic.js.map +1 -0
  111. package/dist/providers/clientOptions.d.ts +14 -0
  112. package/dist/providers/clientOptions.d.ts.map +1 -0
  113. package/dist/providers/clientOptions.js +26 -0
  114. package/dist/providers/clientOptions.js.map +1 -0
  115. package/dist/providers/index.d.ts +24 -0
  116. package/dist/providers/index.d.ts.map +1 -0
  117. package/dist/providers/index.js +51 -0
  118. package/dist/providers/index.js.map +1 -0
  119. package/dist/providers/mock.d.ts +25 -0
  120. package/dist/providers/mock.d.ts.map +1 -0
  121. package/dist/providers/mock.js +85 -0
  122. package/dist/providers/mock.js.map +1 -0
  123. package/dist/providers/openai.d.ts +32 -0
  124. package/dist/providers/openai.d.ts.map +1 -0
  125. package/dist/providers/openai.js +118 -0
  126. package/dist/providers/openai.js.map +1 -0
  127. package/dist/providers/openrouter.d.ts +29 -0
  128. package/dist/providers/openrouter.d.ts.map +1 -0
  129. package/dist/providers/openrouter.js +35 -0
  130. package/dist/providers/openrouter.js.map +1 -0
  131. package/dist/providers/types.d.ts +60 -0
  132. package/dist/providers/types.d.ts.map +1 -0
  133. package/dist/providers/types.js +2 -0
  134. package/dist/providers/types.js.map +1 -0
  135. package/dist/routing/staticResolver.d.ts +41 -0
  136. package/dist/routing/staticResolver.d.ts.map +1 -0
  137. package/dist/routing/staticResolver.js +67 -0
  138. package/dist/routing/staticResolver.js.map +1 -0
  139. package/dist/routing/types.d.ts +72 -0
  140. package/dist/routing/types.d.ts.map +1 -0
  141. package/dist/routing/types.js +11 -0
  142. package/dist/routing/types.js.map +1 -0
  143. package/dist/secrets.d.ts +8 -0
  144. package/dist/secrets.d.ts.map +1 -0
  145. package/dist/secrets.js +14 -0
  146. package/dist/secrets.js.map +1 -0
  147. package/dist/tools/metadata.d.ts +93 -0
  148. package/dist/tools/metadata.d.ts.map +1 -0
  149. package/dist/tools/metadata.js +49 -0
  150. package/dist/tools/metadata.js.map +1 -0
  151. package/dist/tools/modelTool.d.ts +35 -0
  152. package/dist/tools/modelTool.d.ts.map +1 -0
  153. package/dist/tools/modelTool.js +37 -0
  154. package/dist/tools/modelTool.js.map +1 -0
  155. package/dist/tools/registry.d.ts +65 -0
  156. package/dist/tools/registry.d.ts.map +1 -0
  157. package/dist/tools/registry.js +166 -0
  158. package/dist/tools/registry.js.map +1 -0
  159. package/dist/types.d.ts +71 -0
  160. package/dist/types.d.ts.map +1 -0
  161. package/dist/types.js +10 -0
  162. package/dist/types.js.map +1 -0
  163. package/package.json +72 -0
@@ -0,0 +1,107 @@
1
+ import type { RunEventSink } from "../events.js";
2
+ import type { ProviderSelection } from "../providers/index.js";
3
+ import type { ConnectorConfig, Permissions, WorkflowDefinition } from "../types.js";
4
+ /**
5
+ * The provider-neutral, harness-neutral description of one workflow run, handed
6
+ * to an {@link AgentEngine}. It carries the *materials* (a prepared on-disk
7
+ * working tree, the workflow, assembled context, permissions, secrets,
8
+ * connectors, provider selection) — NOT a fixed prompt or tool set, which are
9
+ * each engine's own concern.
10
+ *
11
+ * Crucially, file mutations are out-of-band: an engine edits files under
12
+ * {@link RunSpec.workdir} and the caller (executeRun) computes the change set by
13
+ * diffing that tree against the input manifest. So the engine contract never
14
+ * has to model "an edit" uniformly across the native loop, Claude Code, or Codex.
15
+ */
16
+ export interface RunSpec {
17
+ runId: string;
18
+ workspaceId: string;
19
+ workflowPath: string;
20
+ /** The parsed workflow YAML (prompt, runner profile, verify steps, …). */
21
+ workflow: WorkflowDefinition;
22
+ /** The run's structured inputs (context_bundle.inputs). */
23
+ inputs: Record<string, unknown>;
24
+ /** Pre-assembled curated context text. The native loop bakes it into the
25
+ * prompt; a filesystem-native engine (Claude Code) may ignore it and explore. */
26
+ context: string;
27
+ /** Absolute path to the prepared sandbox working tree (the engine edits here). */
28
+ workdir: string;
29
+ permissions: Permissions;
30
+ /** Workflow-declared secrets, resolved by the caller. */
31
+ secrets: Record<string, string>;
32
+ /** Connectors (MCP/HTTP) with auth tokens already resolved. */
33
+ connectors: ConnectorConfig[];
34
+ /** Preferred provider + per-run model + per-org BYO keys. */
35
+ provider: {
36
+ preferred?: string | null;
37
+ } & ProviderSelection;
38
+ /** Optional budget overrides; engines that don't honour these ignore them. */
39
+ limits?: {
40
+ maxSteps?: number;
41
+ maxDurationMs?: number;
42
+ };
43
+ }
44
+ export interface EngineContext {
45
+ /** Append a timestamped line to the run's logs. */
46
+ log: (line: string) => void;
47
+ /**
48
+ * Optional structured event sink for the run.
49
+ *
50
+ * `log` is prose for a human; this is the machine-readable account of the
51
+ * same run. Optional so every existing caller and every existing engine
52
+ * compiles and behaves unchanged — an engine that has nothing structured to
53
+ * say simply never calls it, and a caller that wants only logs omits it.
54
+ *
55
+ * Engines differ in what they can honour, and that is expected rather than a
56
+ * gap to close: the in-process loop emits the full stream because it sees
57
+ * every turn and every tool call, whereas an out-of-process engine only sees
58
+ * what its transport surfaces. An engine emitting a subset is not degrading
59
+ * silently — the events it does emit are exact.
60
+ */
61
+ emit?: RunEventSink;
62
+ }
63
+ /**
64
+ * What an engine returns.
65
+ *
66
+ * `text` is the run's prose — the one thing every engine has. `emissions` is
67
+ * whatever else the run produced, and the kernel **never inspects it**: what a
68
+ * run may emit is the application's vocabulary, not the kernel's.
69
+ *
70
+ * This used to be `knowledge: KnowledgeEntry[]` and `issues: IssueEntry[]` —
71
+ * one application's run protocol, in the kernel's own return type, which the
72
+ * comment here admitted was wrong and named this as the intended end state. The
73
+ * in-process engines left them empty and only the out-of-process engine filled
74
+ * them, so the fields cost every engine a shape they had no use for.
75
+ *
76
+ * Opaque means opaque: the kernel does not parse, validate, or default it. An
77
+ * engine that has nothing to hand back omits it, and a caller casts it to
78
+ * whatever its own capability surface agreed to write.
79
+ */
80
+ export interface EngineResult {
81
+ /** Final assistant prose for the run; the caller writes it as the run artifact. */
82
+ text: string;
83
+ /** Anything else the run produced, in the application's own shape. */
84
+ emissions?: unknown;
85
+ }
86
+ /** The outcome of an engine's capability check for a given run. */
87
+ export type EngineSupport = {
88
+ ok: true;
89
+ } | {
90
+ ok: false;
91
+ reason: string;
92
+ };
93
+ /**
94
+ * A pluggable agent harness. Implementations: the in-process native tool-use
95
+ * loop, and (as adapters) Claude Code / Codex. An engine drives the agent to
96
+ * completion against {@link RunSpec.workdir} and returns prose plus whatever
97
+ * else the run emitted; file changes land on disk and are captured by the
98
+ * caller's change-set diff.
99
+ */
100
+ export interface AgentEngine {
101
+ readonly name: string;
102
+ /** Whether this engine can honour the run's hard requirements (capabilities,
103
+ * isolation). A false result fails the run rather than degrading silently. */
104
+ supports(spec: RunSpec): EngineSupport;
105
+ run(spec: RunSpec, ctx: EngineContext): Promise<EngineResult>;
106
+ }
107
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0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WAAW,YAAY;IAC3B,mFAAmF;IACnF,IAAI,EAAE,MAAM,CAAA;IACZ,sEAAsE;IACtE,SAAS,CAAC,EAAE,OAAO,CAAA;CACpB;AAED,mEAAmE;AACnE,MAAM,MAAM,aAAa,GAAG;IAAE,EAAE,EAAE,IAAI,CAAA;CAAE,GAAG;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAA;AAExE;;;;;;GAMG;AACH,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB;mFAC+E;IAC/E,QAAQ,CAAC,IAAI,EAAE,OAAO,GAAG,aAAa,CAAA;IACtC,GAAG,CAAC,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,aAAa,GAAG,OAAO,CAAC,YAAY,CAAC,CAAA;CAC9D"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/engines/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,211 @@
1
+ /**
2
+ * The run event stream: a structured, ordered record of what happened inside a
3
+ * run, alongside the human-readable `log` line callback that predates it.
4
+ *
5
+ * **The kernel EMITS the stream; it never STORES it.** There is no session
6
+ * store, no resume, no fork and no replay in here — those need persistence and
7
+ * a schema, which is exactly the infrastructure a kernel must not ship. What
8
+ * the kernel owes an application is a faithful, ordered, machine-readable
9
+ * account of the run; what the application does with it (append to a log,
10
+ * project into a UI, compute a rollback plan) is policy and lives above.
11
+ *
12
+ * This is the same split the rest of the kernel already makes: `ToolMetadata`
13
+ * declares that a tool is `reversible` without implementing undo, and
14
+ * `requiresConfirmation` without implementing a confirmation flow. The events
15
+ * here are the missing half of that bargain — the metadata says a tool *can* be
16
+ * undone, and the stream is what records that it *was called*, so an
17
+ * application has something concrete to undo.
18
+ *
19
+ * Two properties are deliberate and load-bearing:
20
+ *
21
+ * - **Ordered.** Every event carries a monotonic `seq` from a single counter
22
+ * per run. A consumer that receives events out of band can still sort them,
23
+ * and a gap in the sequence is detectable — a dropped event is not allowed
24
+ * to look like an event that never happened.
25
+ * - **Non-fatal.** A sink that throws is reported through `log` and skipped;
26
+ * it never fails the run. Observability that can take production down is
27
+ * worse than no observability, and the kernel already applies this rule to
28
+ * context providers.
29
+ */
30
+ /** Every event kind the loop emits. */
31
+ export type RunEventType = "run.started" | "model.turn" | "tool.called" | "tool.succeeded" | "tool.failed" | "run.budget_exhausted" | "run.finished";
32
+ /**
33
+ * Fields common to every event.
34
+ *
35
+ * `seq` is per-run and starts at 0. `at` is epoch milliseconds rather than a
36
+ * formatted string: a consumer that wants a locale-formatted timestamp can make
37
+ * one, but a consumer handed a formatted string cannot reliably get the instant
38
+ * back.
39
+ */
40
+ export interface RunEventBase {
41
+ seq: number;
42
+ at: number;
43
+ }
44
+ /** Why a run stopped. `failed` means the loop threw — the error propagates to
45
+ * the caller unchanged, but the stream is closed first so a persistent
46
+ * consumer can tell a crashed run from one that is still going. */
47
+ export type RunOutcome = "completed" | "steps_exhausted" | "timed_out" | "failed";
48
+ /** Which budget ran out. */
49
+ export type BudgetKind = "steps" | "duration";
50
+ /** The loop is about to take its first turn. Carries the resolved budgets and
51
+ * the tool surface actually handed to the model — which is the projected
52
+ * surface, after metadata scoping, not everything the caller passed in. */
53
+ export interface RunStartedEvent extends RunEventBase {
54
+ type: "run.started";
55
+ maxSteps: number;
56
+ maxDurationMs: number;
57
+ tools: string[];
58
+ }
59
+ /** One assistant turn: its prose and the tool calls it requested. */
60
+ export interface ModelTurnEvent extends RunEventBase {
61
+ type: "model.turn";
62
+ step: number;
63
+ text: string;
64
+ toolCalls: {
65
+ id: string;
66
+ name: string;
67
+ }[];
68
+ }
69
+ /**
70
+ * A tool is about to execute. Emitted before the call so a crash mid-tool still
71
+ * leaves evidence that the effect may have started — which is precisely the
72
+ * case a rollback consumer must not miss.
73
+ *
74
+ * It carries the same reversibility fields as {@link ToolSucceededEvent}, and
75
+ * that duplication is the point: a tool that half-applies its effect and then
76
+ * throws produces `tool.called` + `tool.failed`, so if undo metadata appeared
77
+ * only on success the one case this event exists for would be the one case a
78
+ * consumer could not act on.
79
+ *
80
+ * `input` is a detached copy, never the object handed to the tool — see the
81
+ * note in the loop. **It is also the raw tool arguments**: anything a model
82
+ * passed as an argument, including a secret or PII it was given, now reaches
83
+ * every attached sink. Nothing outside the model conversation captured these
84
+ * before, so a sink that persists or forwards events is a new place for that
85
+ * data to land and should redact accordingly.
86
+ */
87
+ export interface ToolCalledEvent extends RunEventBase {
88
+ type: "tool.called";
89
+ step: number;
90
+ callId: string;
91
+ name: string;
92
+ input: Record<string, unknown>;
93
+ reversible?: boolean;
94
+ undoToolName?: string | null;
95
+ undoWindowSeconds?: number | null;
96
+ }
97
+ /**
98
+ * A tool executed successfully.
99
+ *
100
+ * The reversibility fields are copied from the tool's own {@link ToolMetadata}
101
+ * at call time, not looked up later: the tool set can differ between runs and
102
+ * between steps, so a consumer reading the stream after the fact must not have
103
+ * to reconstruct which registry was in play. `reversible` absent means the tool
104
+ * declared nothing, which per the metadata contract means "no restriction" —
105
+ * and here specifically means "makes no claim", never "safe to undo".
106
+ */
107
+ export interface ToolSucceededEvent extends RunEventBase {
108
+ type: "tool.succeeded";
109
+ step: number;
110
+ callId: string;
111
+ name: string;
112
+ /** UTF-8 byte length of the model-facing string, before truncation. Bytes
113
+ * rather than `String.length`, which counts UTF-16 code units and
114
+ * under-reports anything outside the BMP. */
115
+ bytes: number;
116
+ reversible?: boolean;
117
+ undoToolName?: string | null;
118
+ undoWindowSeconds?: number | null;
119
+ }
120
+ /** A tool call did not produce a result. `unknown_tool` is separated from
121
+ * `threw` because they mean different things to a consumer: one is a model
122
+ * hallucinating a name, the other is a real effect that may have partially
123
+ * landed. */
124
+ export interface ToolFailedEvent extends RunEventBase {
125
+ type: "tool.failed";
126
+ step: number;
127
+ callId: string;
128
+ name: string;
129
+ reason: "threw" | "unknown_tool";
130
+ error: string;
131
+ }
132
+ /** A budget was exhausted. Emitted at the moment the loop notices, which for
133
+ * `duration` is between steps — see the overshoot note on the loop itself. */
134
+ export interface RunBudgetExhaustedEvent extends RunEventBase {
135
+ type: "run.budget_exhausted";
136
+ kind: BudgetKind;
137
+ step: number;
138
+ }
139
+ /**
140
+ * The run is over. Always the last event, whatever the outcome — including when
141
+ * the loop throws, in which case it is emitted before the error propagates.
142
+ *
143
+ * `steps` and `text` are optional because on the failure path they are genuinely
144
+ * unknown: the loop threw and never returned a result, so any number here would
145
+ * be **invented**. They are omitted rather than zeroed — a wrong number is worse
146
+ * than an absent one, and the `model.turn` events already in the stream are the
147
+ * authoritative record of how far the run got. On every other outcome both are
148
+ * present.
149
+ */
150
+ export interface RunFinishedEvent extends RunEventBase {
151
+ type: "run.finished";
152
+ outcome: RunOutcome;
153
+ steps?: number;
154
+ text?: string;
155
+ /** Present only when `outcome` is `failed`. */
156
+ error?: string;
157
+ }
158
+ export type RunEvent = RunStartedEvent | ModelTurnEvent | ToolCalledEvent | ToolSucceededEvent | ToolFailedEvent | RunBudgetExhaustedEvent | RunFinishedEvent;
159
+ /** Where events go. Synchronous and returning void on purpose: a sink that
160
+ * needs to do I/O should buffer and flush on its own schedule rather than make
161
+ * the loop await it. */
162
+ export type RunEventSink = (event: RunEvent) => void;
163
+ /** The per-event fields a caller supplies; `seq` and `at` are the emitter's. */
164
+ export type RunEventInput = Omit<RunStartedEvent, keyof RunEventBase> | Omit<ModelTurnEvent, keyof RunEventBase> | Omit<ToolCalledEvent, keyof RunEventBase> | Omit<ToolSucceededEvent, keyof RunEventBase> | Omit<ToolFailedEvent, keyof RunEventBase> | Omit<RunBudgetExhaustedEvent, keyof RunEventBase> | Omit<RunFinishedEvent, keyof RunEventBase>;
165
+ /**
166
+ * The events a {@link Loop} may emit: everything except the bookends.
167
+ *
168
+ * `run.started` and `run.finished` belong to `runWithEvents`, which brackets
169
+ * whichever loop runs. A loop that emitted its own would produce a duplicate
170
+ * start, or a premature terminal event that a consumer stops reading at — and
171
+ * a loop migrated from the older API, where loops DID own their stream, is
172
+ * exactly the code that would try. Excluding them from the type means that
173
+ * migration fails to compile instead of producing a subtly wrong stream.
174
+ */
175
+ export type LoopEventInput = Exclude<RunEventInput, {
176
+ type: "run.started";
177
+ } | {
178
+ type: "run.finished";
179
+ }>;
180
+ /** Stamps `seq`/`at` and delivers to a sink, isolating sink failures. */
181
+ export interface LoopEventEmitter {
182
+ emit(event: LoopEventInput): void;
183
+ readonly count: number;
184
+ }
185
+ export interface RunEventEmitter {
186
+ emit(event: RunEventInput): void;
187
+ /** How many events have been stamped. Lets a caller close a run with the
188
+ * step/event count without threading a second counter through the loop. */
189
+ readonly count: number;
190
+ }
191
+ /**
192
+ * Build an emitter over an optional sink.
193
+ *
194
+ * With no sink this is a functioning no-op — the counter still advances, so
195
+ * turning the sink on later cannot change the sequence numbering. Callers
196
+ * therefore never branch on whether events are wanted.
197
+ */
198
+ export declare function runEventEmitter(sink?: RunEventSink, log?: (line: string) => void): RunEventEmitter;
199
+ /**
200
+ * An in-memory append-only recorder — the smallest possible session log, and
201
+ * the reference shape for a persistent one.
202
+ *
203
+ * Provided because a caller should not have to write an array-push to test that
204
+ * a run emitted what it should. It is explicitly NOT a session store: it has no
205
+ * persistence, no identity and no bound on growth.
206
+ */
207
+ export declare function recordRunEvents(): {
208
+ sink: RunEventSink;
209
+ events: RunEvent[];
210
+ };
211
+ //# sourceMappingURL=events.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../src/events.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH,uCAAuC;AACvC,MAAM,MAAM,YAAY,GACpB,aAAa,GACb,YAAY,GACZ,aAAa,GACb,gBAAgB,GAChB,aAAa,GACb,sBAAsB,GACtB,cAAc,CAAA;AAElB;;;;;;;GAOG;AACH,MAAM,WAAW,YAAY;IAC3B,GAAG,EAAE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BAAkB,EAAE,MAAM,YAAY,CAAC,GAC5C,IAAI,CAAC,eAAe,EAAE,MAAM,YAAY,CAAC,GACzC,IAAI,CAAC,uBAAuB,EAAE,MAAM,YAAY,CAAC,GACjD,IAAI,CAAC,gBAAgB,EAAE,MAAM,YAAY,CAAC,CAAA;AAE9C;;;;;;;;;GASG;AACH,MAAM,MAAM,cAAc,GAAG,OAAO,CAClC,aAAa,EACb;IAAE,IAAI,EAAE,aAAa,CAAA;CAAE,GAAG;IAAE,IAAI,EAAE,cAAc,CAAA;CAAE,CACnD,CAAA;AAED,yEAAyE;AACzE,MAAM,WAAW,gBAAgB;IAC/B,IAAI,CAAC,KAAK,EAAE,cAAc,GAAG,IAAI,CAAA;IACjC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;CACvB;AAED,MAAM,WAAW,eAAe;IAC9B,IAAI,CAAC,KAAK,EAAE,aAAa,GAAG,IAAI,CAAA;IAChC;gFAC4E;IAC5E,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;CACvB;AAED;;;;;;GAMG;AACH,wBAAgB,eAAe,CAC7B,IAAI,CAAC,EAAE,YAAY,EACnB,GAAG,GAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAe,GACrC,eAAe,CAmBjB;AAED;;;;;;;GAOG;AACH,wBAAgB,eAAe,IAAI;IAAE,IAAI,EAAE,YAAY,CAAC;IAAC,MAAM,EAAE,QAAQ,EAAE,CAAA;CAAE,CAG5E"}
package/dist/events.js ADDED
@@ -0,0 +1,69 @@
1
+ /**
2
+ * The run event stream: a structured, ordered record of what happened inside a
3
+ * run, alongside the human-readable `log` line callback that predates it.
4
+ *
5
+ * **The kernel EMITS the stream; it never STORES it.** There is no session
6
+ * store, no resume, no fork and no replay in here — those need persistence and
7
+ * a schema, which is exactly the infrastructure a kernel must not ship. What
8
+ * the kernel owes an application is a faithful, ordered, machine-readable
9
+ * account of the run; what the application does with it (append to a log,
10
+ * project into a UI, compute a rollback plan) is policy and lives above.
11
+ *
12
+ * This is the same split the rest of the kernel already makes: `ToolMetadata`
13
+ * declares that a tool is `reversible` without implementing undo, and
14
+ * `requiresConfirmation` without implementing a confirmation flow. The events
15
+ * here are the missing half of that bargain — the metadata says a tool *can* be
16
+ * undone, and the stream is what records that it *was called*, so an
17
+ * application has something concrete to undo.
18
+ *
19
+ * Two properties are deliberate and load-bearing:
20
+ *
21
+ * - **Ordered.** Every event carries a monotonic `seq` from a single counter
22
+ * per run. A consumer that receives events out of band can still sort them,
23
+ * and a gap in the sequence is detectable — a dropped event is not allowed
24
+ * to look like an event that never happened.
25
+ * - **Non-fatal.** A sink that throws is reported through `log` and skipped;
26
+ * it never fails the run. Observability that can take production down is
27
+ * worse than no observability, and the kernel already applies this rule to
28
+ * context providers.
29
+ */
30
+ /**
31
+ * Build an emitter over an optional sink.
32
+ *
33
+ * With no sink this is a functioning no-op — the counter still advances, so
34
+ * turning the sink on later cannot change the sequence numbering. Callers
35
+ * therefore never branch on whether events are wanted.
36
+ */
37
+ export function runEventEmitter(sink, log = () => { }) {
38
+ let seq = 0;
39
+ return {
40
+ emit(event) {
41
+ const stamped = { ...event, seq: seq++, at: Date.now() };
42
+ if (!sink)
43
+ return;
44
+ try {
45
+ sink(stamped);
46
+ }
47
+ catch (err) {
48
+ // Never fail a run because its observability failed.
49
+ log(`event sink threw on ${stamped.type}: ${err instanceof Error ? err.message : String(err)}`);
50
+ }
51
+ },
52
+ get count() {
53
+ return seq;
54
+ },
55
+ };
56
+ }
57
+ /**
58
+ * An in-memory append-only recorder — the smallest possible session log, and
59
+ * the reference shape for a persistent one.
60
+ *
61
+ * Provided because a caller should not have to write an array-push to test that
62
+ * a run emitted what it should. It is explicitly NOT a session store: it has no
63
+ * persistence, no identity and no bound on growth.
64
+ */
65
+ export function recordRunEvents() {
66
+ const events = [];
67
+ return { sink: (event) => void events.push(event), events };
68
+ }
69
+ //# sourceMappingURL=events.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"events.js","sourceRoot":"","sources":["../src/events.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAqMH;;;;;;GAMG;AACH,MAAM,UAAU,eAAe,CAC7B,IAAmB,EACnB,MAA8B,GAAG,EAAE,GAAE,CAAC;IAEtC,IAAI,GAAG,GAAG,CAAC,CAAA;IACX,OAAO;QACL,IAAI,CAAC,KAAoB;YACvB,MAAM,OAAO,GAAa,EAAE,GAAG,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE,EAAE,EAAE,EAAE,IAAI,CAAC,GAAG,EAAE,EAAE,CAAA;YAClE,IAAI,CAAC,IAAI;gBAAE,OAAM;YACjB,IAAI,CAAC;gBACH,IAAI,CAAC,OAAO,CAAC,CAAA;YACf,CAAC;YAAC,OAAO,GAAG,EAAE,CAAC;gBACb,qDAAqD;gBACrD,GAAG,CACD,uBAAuB,OAAO,CAAC,IAAI,KAAK,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAC3F,CAAA;YACH,CAAC;QACH,CAAC;QACD,IAAI,KAAK;YACP,OAAO,GAAG,CAAA;QACZ,CAAC;KACF,CAAA;AACH,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,eAAe;IAC7B,MAAM,MAAM,GAAe,EAAE,CAAA;IAC7B,OAAO,EAAE,IAAI,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,MAAM,EAAE,CAAA;AAC7D,CAAC"}
@@ -0,0 +1,63 @@
1
+ export type { ConnectorConfig, Permissions, WorkflowDefinition } from "./types.js";
2
+ export { selectProvider } from "./providers/index.js";
3
+ export type { ProviderSelection } from "./providers/index.js";
4
+ export type { Provider, CompletionRequest, ConverseRequest, ConverseResult, AgentMessage, ToolSpec, ToolCall, ToolResult, } from "./providers/types.js";
5
+ export { AnthropicProvider } from "./providers/anthropic.js";
6
+ export { OpenAIProvider, OpenAICompatibleProvider } from "./providers/openai.js";
7
+ export type { OpenAICompatibleOptions } from "./providers/openai.js";
8
+ export { OpenRouterProvider } from "./providers/openrouter.js";
9
+ export type { OpenRouterAttribution } from "./providers/openrouter.js";
10
+ export { MockProvider } from "./providers/mock.js";
11
+ export { emitCompleteToolCall, invokeStreaming, modelIdentity, requireCapability, CapabilityError, } from "./models/types.js";
12
+ export type { ModelInvocation, ModelKind, ModelCaps, ModelIdentity, ModelResult, InvokeContext, StreamSink, Usage, TokenUsage, UnitUsage, Health, HealthStatus, } from "./models/types.js";
13
+ export { chatModel, asChatModel, isChatModel, chatRequest, CHAT_KIND } from "./models/chat.js";
14
+ export type { ChatModel, ChatRequest, ChatResponse, ChatPart, BinaryRef } from "./models/chat.js";
15
+ export { ModelRegistry, UnknownModelError } from "./models/registry.js";
16
+ export type { ModelRef, ModelFactory, ModelSupport } from "./models/registry.js";
17
+ export { withMiddleware, correlationMiddleware, loggingMiddleware, healthTrackingMiddleware, errorRedactionMiddleware, HealthTracker, } from "./models/middleware.js";
18
+ export type { Middleware, Invoker, StreamInvoker } from "./models/middleware.js";
19
+ export { StaticRouteResolver } from "./routing/staticResolver.js";
20
+ export { UnknownCapabilityError } from "./routing/types.js";
21
+ export type { RouteResolver, RouteContext, RouteLimits, CapabilityDefinition, ResolvedRoute, } from "./routing/types.js";
22
+ export { assembleContext, renderContext } from "./context/types.js";
23
+ export type { ContextProvider, ContextFragment, ContextSpec } from "./context/types.js";
24
+ export { runAgent, maxToolResultBytes, resolveLoopLimits } from "./agent.js";
25
+ export type { RunAgentOptions } from "./agent.js";
26
+ export { nativeLoop, runWithEvents } from "./loop.js";
27
+ export type { Loop, LoopRequest, LoopContext, RunContext, LoopResult } from "./loop.js";
28
+ export { runEventEmitter, recordRunEvents } from "./events.js";
29
+ export type { RunEvent, RunEventType, RunEventBase, RunEventInput, RunEventSink, RunEventEmitter, LoopEventInput, LoopEventEmitter, RunOutcome, BudgetKind, RunStartedEvent, ModelTurnEvent, ToolCalledEvent, ToolSucceededEvent, ToolFailedEvent, RunBudgetExhaustedEvent, RunFinishedEvent, } from "./events.js";
30
+ export { primitiveTools, connectorTools, executeTool } from "./tools/registry.js";
31
+ export type { Tool, ToolOutput } from "./tools/registry.js";
32
+ export { selectTools, isToolVisible, toToolSpecs, toolsRequiringConfirmation, undoToolFor, } from "./tools/metadata.js";
33
+ export type { ToolMetadata, ToolSelection, InvocationMode, ResultRetention, ClientResultVisibility, } from "./tools/metadata.js";
34
+ export { modelAsTool } from "./tools/modelTool.js";
35
+ export type { ModelToolOptions } from "./tools/modelTool.js";
36
+ export { runCode } from "./primitives/codeExec.js";
37
+ export type { RunCodeOptions, RunCodeResult } from "./primitives/codeExec.js";
38
+ export { readFileSafe, listFiles } from "./primitives/fs.js";
39
+ export { httpFetch } from "./primitives/http.js";
40
+ export type { HttpFetchOptions, HttpResponse } from "./primitives/http.js";
41
+ export { downloadToFile } from "./primitives/download.js";
42
+ export type { DownloadOptions } from "./primitives/download.js";
43
+ export { connectMcp, MCP_CLIENT_NAME } from "./connectors/mcpClient.js";
44
+ export type { McpConnection } from "./connectors/mcpClient.js";
45
+ export { selectEngine } from "./engines/index.js";
46
+ export type { EngineSelection } from "./engines/index.js";
47
+ export type { AgentEngine, EngineContext, EngineResult, EngineSupport, RunSpec, } from "./engines/types.js";
48
+ export { NativeEngine } from "./engines/native.js";
49
+ export type { NativeEngineOptions, DomainToolFactory } from "./engines/native.js";
50
+ export { ClaudeCodeEngine } from "./engines/claudeCode.js";
51
+ export type { ClaudeCodeOptions, ClaudeCodeDriver } from "./engines/claudeCode.js";
52
+ export { CodexEngine } from "./engines/codex.js";
53
+ export type { CodexOptions, CodexDriver } from "./engines/codex.js";
54
+ export { writeFileCapability, denyCrossWorkspace, resolveWithin } from "./engines/capability.js";
55
+ export type { CapabilityContext, CapabilityResult, CapabilityTool } from "./engines/capability.js";
56
+ export { defaultCapabilityTools } from "./engines/claudeCode.js";
57
+ export type { CapabilityToolFactory } from "./engines/claudeCode.js";
58
+ export { capabilitySdkServer, capabilityToolIds, CAPABILITY_SERVER_NAME, } from "./engines/capabilityMcp.js";
59
+ export { buildCapabilityStdioServer, serveCapability, capabilityStdioConfigFromEnv, } from "./engines/capabilityStdio.js";
60
+ export type { CapabilityStdioOptions, CapabilityStdioConfig } from "./engines/capabilityStdio.js";
61
+ export { readEmissions, writeEmissions } from "./engines/capabilityEmissions.js";
62
+ export { secretsToEnv } from "./secrets.js";
63
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAOA,YAAY,EAAE,eAAe,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAA;AAKlF,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AACrD,YAAY,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAA;AAC7D,YAAY,EACV,QAAQ,EACR,iBAAiB,EACjB,eAAe,EACf,cAAc,EACd,YAAY,EACZ,QAAQ,EACR,QAAQ,EACR,UAAU,GACX,MAAM,sBAAsB,CAAA;AAC7B,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAA;AAC5D,OAAO,EAAE,cAAc,EAAE,wBAAwB,EAAE,MAAM,uBAAuB,CAAA;AAChF,YAAY,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAA;AACpE,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAA;AAC9D,YAAY,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAA;AACtE,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AAKlD,OAAO,EACL,oBAAoB,EACpB,eAAe,EACf,aAAa,EACb,iBAAiB,EACjB,eAAe,GAChB,MAAM,mBAAmB,CAAA;AAC1B,YAAY,EACV,eAAe,EACf,SAAS,EACT,SAAS,EACT,aAAa,E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ADDED
@@ -0,0 +1,82 @@
1
+ // The kernel's public API. Anything not re-exported here is internal and may
2
+ // change without notice — adding an export is a compatibility commitment, so do
3
+ // it deliberately.
4
+ // ---------------------------------------------------------------------------
5
+ // Providers — the model adapters and their selection
6
+ // ---------------------------------------------------------------------------
7
+ export { selectProvider } from "./providers/index.js";
8
+ export { AnthropicProvider } from "./providers/anthropic.js";
9
+ export { OpenAIProvider, OpenAICompatibleProvider } from "./providers/openai.js";
10
+ export { OpenRouterProvider } from "./providers/openrouter.js";
11
+ export { MockProvider } from "./providers/mock.js";
12
+ // ---------------------------------------------------------------------------
13
+ // The model seam — the neutral arrow every model kind is invoked through
14
+ // ---------------------------------------------------------------------------
15
+ export { emitCompleteToolCall, invokeStreaming, modelIdentity, requireCapability, CapabilityError, } from "./models/types.js";
16
+ // The chat kind, and the adapter that puts an existing Provider on the seam.
17
+ export { chatModel, asChatModel, isChatModel, chatRequest, CHAT_KIND } from "./models/chat.js";
18
+ // Extension point 1 — bind kind+id to a concrete invocation.
19
+ export { ModelRegistry, UnknownModelError } from "./models/registry.js";
20
+ // Extension point 3 — cross-cutting concerns over every kind, uniformly.
21
+ export { withMiddleware, correlationMiddleware, loggingMiddleware, healthTrackingMiddleware, errorRedactionMiddleware, HealthTracker, } from "./models/middleware.js";
22
+ // ---------------------------------------------------------------------------
23
+ // Extension point 2 — route resolution (capability → model + prompt + tools)
24
+ // ---------------------------------------------------------------------------
25
+ export { StaticRouteResolver } from "./routing/staticResolver.js";
26
+ export { UnknownCapabilityError } from "./routing/types.js";
27
+ // ---------------------------------------------------------------------------
28
+ // Extension point 5 — pluggable context assembly
29
+ // ---------------------------------------------------------------------------
30
+ export { assembleContext, renderContext } from "./context/types.js";
31
+ // ---------------------------------------------------------------------------
32
+ // The tool-use loop
33
+ // ---------------------------------------------------------------------------
34
+ export { runAgent, maxToolResultBytes, resolveLoopLimits } from "./agent.js";
35
+ // Extension point 7 — the control loop itself. The kernel ships exactly one
36
+ // (`nativeLoop`, the loop `runAgent` has always run); this is the interface
37
+ // around it, so an application can change control flow without forking.
38
+ export { nativeLoop, runWithEvents } from "./loop.js";
39
+ // The run event stream. The kernel emits it; storing, resuming or replaying it
40
+ // is the application's, because that needs persistence a kernel must not ship.
41
+ export { runEventEmitter, recordRunEvents } from "./events.js";
42
+ // ---------------------------------------------------------------------------
43
+ // Extension point 6 — tools: generic primitives, injectable domain emissions,
44
+ // MCP connectors, rich metadata + projections, and models-as-tools
45
+ // ---------------------------------------------------------------------------
46
+ export { primitiveTools, connectorTools, executeTool } from "./tools/registry.js";
47
+ export { selectTools, isToolVisible, toToolSpecs, toolsRequiringConfirmation, undoToolFor, } from "./tools/metadata.js";
48
+ export { modelAsTool } from "./tools/modelTool.js";
49
+ // ---------------------------------------------------------------------------
50
+ // Sandbox primitives (the executors the tools are built on)
51
+ // ---------------------------------------------------------------------------
52
+ export { runCode } from "./primitives/codeExec.js";
53
+ export { readFileSafe, listFiles } from "./primitives/fs.js";
54
+ export { httpFetch } from "./primitives/http.js";
55
+ export { downloadToFile } from "./primitives/download.js";
56
+ // ---------------------------------------------------------------------------
57
+ // MCP connectors
58
+ // ---------------------------------------------------------------------------
59
+ export { connectMcp, MCP_CLIENT_NAME } from "./connectors/mcpClient.js";
60
+ // ---------------------------------------------------------------------------
61
+ // Engines — the pluggable-harness seam
62
+ // ---------------------------------------------------------------------------
63
+ export { selectEngine } from "./engines/index.js";
64
+ export { NativeEngine } from "./engines/native.js";
65
+ export { ClaudeCodeEngine } from "./engines/claudeCode.js";
66
+ export { CodexEngine } from "./engines/codex.js";
67
+ // The capability mechanism. The kernel supplies the workspace-scope guards, the
68
+ // one capability with no product semantics (write_file), and the two transports
69
+ // that expose a surface to an external engine. WHICH capabilities a run gets is
70
+ // the application's decision, injected via the seams above.
71
+ export { writeFileCapability, denyCrossWorkspace, resolveWithin } from "./engines/capability.js";
72
+ export { defaultCapabilityTools } from "./engines/claudeCode.js";
73
+ export { capabilitySdkServer, capabilityToolIds, CAPABILITY_SERVER_NAME, } from "./engines/capabilityMcp.js";
74
+ export { buildCapabilityStdioServer, serveCapability, capabilityStdioConfigFromEnv, } from "./engines/capabilityStdio.js";
75
+ // The emissions file: the generic seam for getting state back out of an
76
+ // out-of-process engine, which cannot share memory with the run that spawned it.
77
+ export { readEmissions, writeEmissions } from "./engines/capabilityEmissions.js";
78
+ // ---------------------------------------------------------------------------
79
+ // Secrets
80
+ // ---------------------------------------------------------------------------
81
+ export { secretsToEnv } from "./secrets.js";
82
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,gFAAgF;AAChF,mBAAmB;AAOnB,8EAA8E;AAC9E,qDAAqD;AACrD,8EAA8E;AAC9E,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAYrD,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAA;AAC5D,OAAO,EAAE,cAAc,EAAE,wBAAwB,EAAE,MAAM,uBAAuB,CAAA;AAEhF,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAA;AAE9D,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AAElD,8EAA8E;AAC9E,yEAAyE;AACzE,8EAA8E;AAC9E,OAAO,EACL,oBAAoB,EACpB,eAAe,EACf,aAAa,EACb,iBAAiB,EACjB,eAAe,GAChB,MAAM,mBAAmB,CAAA;AAgB1B,6EAA6E;AAC7E,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,WAAW,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AAG9F,6DAA6D;AAC7D,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAA;AAGvE,yEAAyE;AACzE,OAAO,EACL,cAAc,EACd,qBAAqB,EACrB,iBAAiB,EACjB,wBAAwB,EACxB,wBAAwB,EACxB,aAAa,GACd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