@theokit/presenter 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for describing the origin of the Work and
141
+ reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 usetheo.dev
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,217 @@
1
+ import { InteractionUpdate } from '@theokit/sdk';
2
+ import { UIMessageChunk } from 'ai';
3
+
4
+ /**
5
+ * `AgentOutputEvent` — the canonical, normalized agent-output event (M49).
6
+ *
7
+ * This is the **narrow waist** of theokit's presentation layer: ONE normalized event that every SOURCE
8
+ * (the SDK's `SDKMessage` / `InteractionUpdate`) is translated INTO, and that every `Presenter`
9
+ * (web `UIMessageStream`, terminal ANSI, JSON API) is translated OUT of. Without it you get N×M
10
+ * translators — the current duplication where the web path and the terminal path each re-translate the
11
+ * SDK independently and drift. The variants are derived from the SDK's own event discriminants (source
12
+ * side), NOT from any single surface's wire format, so no surface leaks into the contract.
13
+ *
14
+ * @public
15
+ */
16
+ type AgentOutputEvent = AgentTextEvent | AgentReasoningEvent | AgentToolCallEvent | AgentPartialToolCallEvent | AgentToolResultEvent | AgentErrorEvent | AgentFinishEvent | AgentStatusEvent;
17
+ /** Assistant text output (streamed or whole). */
18
+ interface AgentTextEvent {
19
+ readonly type: 'text';
20
+ readonly text: string;
21
+ }
22
+ /** Model reasoning / thinking content (distinct from user-visible text). */
23
+ interface AgentReasoningEvent {
24
+ readonly type: 'reasoning';
25
+ readonly text: string;
26
+ }
27
+ /** A tool invocation with its (committed) input — the args the model decided on. */
28
+ interface AgentToolCallEvent {
29
+ readonly type: 'tool-call';
30
+ readonly callId: string;
31
+ readonly name: string;
32
+ readonly input: unknown;
33
+ }
34
+ /**
35
+ * Incremental tool input as the model streams the args (theokit-sdk#70) — a DISTINCT lifecycle point
36
+ * from `tool-call` (args committed). Consumers that stream tool-input render the progressive args; those
37
+ * that don't may ignore it. Never duplicates `tool-call`.
38
+ */
39
+ interface AgentPartialToolCallEvent {
40
+ readonly type: 'partial-tool-call';
41
+ readonly callId: string;
42
+ readonly name: string;
43
+ readonly input: unknown;
44
+ }
45
+ /** The result of a tool invocation, keyed by the same `callId`. `isError` marks a failed tool. */
46
+ interface AgentToolResultEvent {
47
+ readonly type: 'tool-result';
48
+ readonly callId: string;
49
+ readonly name: string;
50
+ readonly result: unknown;
51
+ readonly isError?: boolean;
52
+ }
53
+ /** A run-level error (typed message + optional code). */
54
+ interface AgentErrorEvent {
55
+ readonly type: 'error';
56
+ readonly message: string;
57
+ readonly code?: string;
58
+ }
59
+ /** Terminal event of a turn: the run finished. `usage` carries token accounting when available. */
60
+ interface AgentFinishEvent {
61
+ readonly type: 'finish';
62
+ readonly reason?: string;
63
+ readonly usage?: {
64
+ readonly totalTokens?: number;
65
+ };
66
+ }
67
+ /** A lifecycle status transition (e.g. goal `active` → `completed`), surface-agnostic. */
68
+ interface AgentStatusEvent {
69
+ readonly type: 'status';
70
+ readonly status: string;
71
+ readonly detail?: string;
72
+ }
73
+ /** The stable set of variant discriminants — useful for exhaustiveness and registry keys. */
74
+ declare const AGENT_OUTPUT_EVENT_TYPES: readonly ["text", "reasoning", "tool-call", "partial-tool-call", "tool-result", "error", "finish", "status"];
75
+ type AgentOutputEventType = (typeof AGENT_OUTPUT_EVENT_TYPES)[number];
76
+ declare const isTextEvent: (e: AgentOutputEvent) => e is AgentTextEvent;
77
+ declare const isReasoningEvent: (e: AgentOutputEvent) => e is AgentReasoningEvent;
78
+ declare const isToolCallEvent: (e: AgentOutputEvent) => e is AgentToolCallEvent;
79
+ declare const isPartialToolCallEvent: (e: AgentOutputEvent) => e is AgentPartialToolCallEvent;
80
+ declare const isToolResultEvent: (e: AgentOutputEvent) => e is AgentToolResultEvent;
81
+ declare const isErrorEvent: (e: AgentOutputEvent) => e is AgentErrorEvent;
82
+ declare const isFinishEvent: (e: AgentOutputEvent) => e is AgentFinishEvent;
83
+ declare const isStatusEvent: (e: AgentOutputEvent) => e is AgentStatusEvent;
84
+
85
+ /**
86
+ * `Presenter<TOut>` — the Strategy that turns the canonical {@link AgentOutputEvent} into ONE surface's
87
+ * output (M49). Web (`UIMessageStream`), terminal (ANSI), and JSON API are peer implementations; each
88
+ * consumes the SAME canonical event, so a source is translated once and every surface reuses it.
89
+ *
90
+ * The contract is **per-event, driven by the caller**: the host loops the event stream and calls
91
+ * `present(event)` for each, so it can INTERLEAVE a presenter's pure-output chunks with framework chunks
92
+ * (HITL approval, checkpoints, done-metadata — `@theokit/agents`) in true model order (ADR-4). Optional
93
+ * `start()` / `finish()` bracket the stream for stateful surfaces (the web stream's `start` framing and
94
+ * its open-block close + `finish`). A stateful presenter (web) holds its open-block state internally and
95
+ * is therefore instantiated **per stream**; stateless presenters (terminal/json) may be singletons.
96
+ *
97
+ * @public
98
+ */
99
+ interface Presenter<TOut> {
100
+ /** Stable surface key (`"ui-message-stream" | "terminal" | "json" | …`) — the registry resolves by it. */
101
+ readonly surface: string;
102
+ /** Optional opening framing emitted once before any event (e.g. the web stream's `{ type: 'start' }`). */
103
+ start?(): TOut[];
104
+ /** Translate one canonical event into zero or more surface chunks (may maintain internal stream state). */
105
+ present(event: AgentOutputEvent): TOut[];
106
+ /** Optional closing framing emitted once after the last event (e.g. close the open block + `finish`). */
107
+ finish?(): TOut[];
108
+ }
109
+ /** Thrown when a surface key is resolved but no presenter is registered for it (fail-fast, typed). */
110
+ declare class UnknownPresenterError extends Error {
111
+ readonly name = "UnknownPresenterError";
112
+ constructor(surface: string, known: readonly string[]);
113
+ }
114
+ /**
115
+ * A registry of presenters keyed by surface. Lets a single agent run be driven through any registered
116
+ * surface without the caller hard-wiring a concrete presenter (Open/Closed — add a surface by registering,
117
+ * not by editing a switch).
118
+ *
119
+ * @public
120
+ */
121
+ declare class PresenterRegistry {
122
+ #private;
123
+ /** Register (or replace) the presenter for its surface. Returns `this` for fluent wiring. */
124
+ register(presenter: Presenter<unknown>): this;
125
+ /** Whether a presenter is registered for `surface`. */
126
+ has(surface: string): boolean;
127
+ /** The registered surface keys. */
128
+ surfaces(): string[];
129
+ /** Resolve the presenter for `surface`, or throw {@link UnknownPresenterError} (never returns undefined). */
130
+ resolve<TOut>(surface: string): Presenter<TOut>;
131
+ }
132
+
133
+ /**
134
+ * `fromSdk` (M49) — the SINGLE source translator: `@theokit/sdk` output → the canonical
135
+ * {@link AgentOutputEvent}. Every presenter (web / terminal / json) consumes the result, so the SDK is
136
+ * parsed ONCE instead of each surface re-translating it (the duplication this layer removes).
137
+ *
138
+ * Ported faithfully from `@theokit/agents/bridge/event-translator.ts` (the proven web-path logic), but
139
+ * emitting the NARROW pure-output event: framework concerns (run-lifecycle, HITL approval, checkpoints,
140
+ * devtools artifacts) are NOT SDK output and are layered by `@theokit/agents` on top (ADR-4), so they are
141
+ * intentionally NOT produced here.
142
+ */
143
+ /** Minimal SDK message shape — duck-typed to avoid a hard import of every SDK message subtype. */
144
+ interface SdkMessage {
145
+ readonly type: string;
146
+ readonly [key: string]: unknown;
147
+ }
148
+ /** Translate ONE buffered SDK message (`run.stream()`) to zero or more canonical output events. */
149
+ declare function fromSdkMessage(msg: SdkMessage): AgentOutputEvent[];
150
+ /**
151
+ * Translate ONE real-time `onDelta` {@link InteractionUpdate} to zero or more canonical output events, in
152
+ * arrival order — the chronological path that keeps text / tool / thinking interleaved in true model order.
153
+ * `partial-tool-call` is surfaced distinctly (theokit-sdk#70); it never duplicates `tool-call`.
154
+ */
155
+ declare function fromInteractionUpdate(update: InteractionUpdate): AgentOutputEvent[];
156
+
157
+ /**
158
+ * `UIMessageStreamPresenter` (M49) — the web surface: the canonical {@link AgentOutputEvent} → the Vercel
159
+ * ai-sdk `UIMessageStream` (`UIMessageChunk`), consumed by `useChat` / assistant-ui.
160
+ *
161
+ * Ported faithfully from `@theokit/agents/bridge/ui-message-stream-translator.ts` (the M1 web path) with
162
+ * ZERO behavior change for the pure-output events. Framework chunks (HITL `tool-approval-request`,
163
+ * `data-checkpoint`) are NOT emitted here — they ride on `@theokit/agents` framework events and are
164
+ * composed by the agents web handler around this presenter (ADR-4).
165
+ *
166
+ * STATEFUL (open-block state machine) → instantiate ONE per stream. The host brackets the stream with
167
+ * {@link start} / {@link finish} and drives {@link present} per event, interleaving framework chunks.
168
+ *
169
+ * Chunk sequences (unchanged):
170
+ * text run: start → text-start{id} → text-delta{id,delta}* → text-end{id} → finish
171
+ * reasoning run: start → reasoning-start{id} → reasoning-delta{id,delta}* → reasoning-end{id} → finish
172
+ * tool run: start → tool-input-available{callId,name,input} → tool-output-available{callId,output} → finish
173
+ *
174
+ * @public
175
+ */
176
+ interface TurnMetadata {
177
+ readonly usage?: {
178
+ readonly inputTokens?: number;
179
+ readonly outputTokens?: number;
180
+ readonly totalTokens?: number;
181
+ };
182
+ readonly durationMs?: number;
183
+ readonly cost?: number;
184
+ }
185
+ interface UIMessageStreamPresenterOptions {
186
+ /** A single shared id for every text block — injected for deterministic tests (D3). */
187
+ readonly textId: string;
188
+ }
189
+ declare class UIMessageStreamPresenter implements Presenter<UIMessageChunk> {
190
+ #private;
191
+ readonly surface = "ui-message-stream";
192
+ constructor(options: UIMessageStreamPresenterOptions);
193
+ /** Emit the opening `start` chunk (exactly once, before any event). */
194
+ start(): UIMessageChunk[];
195
+ present(event: AgentOutputEvent): UIMessageChunk[];
196
+ /**
197
+ * Close any open text/reasoning block and emit the terminal `finish` chunk. When `metadata` is given
198
+ * (a clean run's turn totals from the framework `done`), it rides `messageMetadata`; otherwise the
199
+ * finish is bare (error/abort turns), byte-identical to the original translator.
200
+ */
201
+ finish(metadata?: TurnMetadata): UIMessageChunk[];
202
+ /**
203
+ * Close any open text/reasoning block WITHOUT finishing the stream. The host calls this before
204
+ * interleaving a framework chunk (HITL approval / checkpoint) that must not appear inside an open text
205
+ * block — mirroring the original translator's `closeOpenBlock` before those chunks. Idempotent.
206
+ */
207
+ closeBlock(): UIMessageChunk[];
208
+ /**
209
+ * Whether a `callId` has already been introduced (a `tool-call` or a synthesized `tool-input`). The host
210
+ * uses this so a framework `approval_required` reuses the EC-1 synthesize-input-first rule exactly once.
211
+ */
212
+ hasSeen(callId: string): boolean;
213
+ /** Mark a `callId` as introduced (the host synthesized its `tool-input` for a framework chunk). */
214
+ markSeen(callId: string): void;
215
+ }
216
+
217
+ export { AGENT_OUTPUT_EVENT_TYPES, type AgentErrorEvent, type AgentFinishEvent, type AgentOutputEvent, type AgentOutputEventType, type AgentPartialToolCallEvent, type AgentReasoningEvent, type AgentStatusEvent, type AgentTextEvent, type AgentToolCallEvent, type AgentToolResultEvent, type Presenter, PresenterRegistry, type SdkMessage, type TurnMetadata, UIMessageStreamPresenter, type UIMessageStreamPresenterOptions, UnknownPresenterError, fromInteractionUpdate, fromSdkMessage, isErrorEvent, isFinishEvent, isPartialToolCallEvent, isReasoningEvent, isStatusEvent, isTextEvent, isToolCallEvent, isToolResultEvent };
package/dist/index.js ADDED
@@ -0,0 +1,424 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+
4
+ // src/agent-output-event.ts
5
+ var AGENT_OUTPUT_EVENT_TYPES = [
6
+ "text",
7
+ "reasoning",
8
+ "tool-call",
9
+ "partial-tool-call",
10
+ "tool-result",
11
+ "error",
12
+ "finish",
13
+ "status"
14
+ ];
15
+ var isTextEvent = /* @__PURE__ */ __name((e) => e.type === "text", "isTextEvent");
16
+ var isReasoningEvent = /* @__PURE__ */ __name((e) => e.type === "reasoning", "isReasoningEvent");
17
+ var isToolCallEvent = /* @__PURE__ */ __name((e) => e.type === "tool-call", "isToolCallEvent");
18
+ var isPartialToolCallEvent = /* @__PURE__ */ __name((e) => e.type === "partial-tool-call", "isPartialToolCallEvent");
19
+ var isToolResultEvent = /* @__PURE__ */ __name((e) => e.type === "tool-result", "isToolResultEvent");
20
+ var isErrorEvent = /* @__PURE__ */ __name((e) => e.type === "error", "isErrorEvent");
21
+ var isFinishEvent = /* @__PURE__ */ __name((e) => e.type === "finish", "isFinishEvent");
22
+ var isStatusEvent = /* @__PURE__ */ __name((e) => e.type === "status", "isStatusEvent");
23
+
24
+ // src/presenter.ts
25
+ var UnknownPresenterError = class extends Error {
26
+ static {
27
+ __name(this, "UnknownPresenterError");
28
+ }
29
+ name = "UnknownPresenterError";
30
+ constructor(surface, known) {
31
+ super(`No presenter registered for surface "${surface}". Known: ${known.join(", ") || "(none)"}.`);
32
+ }
33
+ };
34
+ var PresenterRegistry = class {
35
+ static {
36
+ __name(this, "PresenterRegistry");
37
+ }
38
+ #presenters = /* @__PURE__ */ new Map();
39
+ /** Register (or replace) the presenter for its surface. Returns `this` for fluent wiring. */
40
+ register(presenter) {
41
+ this.#presenters.set(presenter.surface, presenter);
42
+ return this;
43
+ }
44
+ /** Whether a presenter is registered for `surface`. */
45
+ has(surface) {
46
+ return this.#presenters.has(surface);
47
+ }
48
+ /** The registered surface keys. */
49
+ surfaces() {
50
+ return [
51
+ ...this.#presenters.keys()
52
+ ];
53
+ }
54
+ /** Resolve the presenter for `surface`, or throw {@link UnknownPresenterError} (never returns undefined). */
55
+ resolve(surface) {
56
+ const p = this.#presenters.get(surface);
57
+ if (p === void 0) throw new UnknownPresenterError(surface, this.surfaces());
58
+ return p;
59
+ }
60
+ };
61
+
62
+ // src/source/from-sdk.ts
63
+ function asString(value, fallback) {
64
+ return typeof value === "string" ? value : fallback;
65
+ }
66
+ __name(asString, "asString");
67
+ function serializeToolResult(value, fallback) {
68
+ if (typeof value === "string") return value;
69
+ if (value === void 0 || value === null) return fallback;
70
+ try {
71
+ return JSON.stringify(value);
72
+ } catch {
73
+ return typeof value === "bigint" ? value.toString() : fallback;
74
+ }
75
+ }
76
+ __name(serializeToolResult, "serializeToolResult");
77
+ function fromAssistant(msg) {
78
+ const events = [];
79
+ const content = msg.message?.content;
80
+ if (!Array.isArray(content)) return events;
81
+ for (const block of content) {
82
+ const b = block;
83
+ if (b.type === "text" && b.text) events.push({
84
+ type: "text",
85
+ text: b.text
86
+ });
87
+ if (b.type === "tool_use") {
88
+ events.push({
89
+ type: "tool-call",
90
+ callId: b.id ?? `tc-${Date.now()}`,
91
+ name: b.name ?? "unknown",
92
+ input: b.input ?? {}
93
+ });
94
+ }
95
+ }
96
+ return events;
97
+ }
98
+ __name(fromAssistant, "fromAssistant");
99
+ function fromToolUse(msg) {
100
+ const status = msg.status;
101
+ const callId = asString(msg.call_id, `tc-${Date.now()}`);
102
+ const name = asString(msg.name, "unknown");
103
+ if (status === "completed") {
104
+ return [
105
+ {
106
+ type: "tool-result",
107
+ callId,
108
+ name,
109
+ result: serializeToolResult(msg.result, ""),
110
+ isError: false
111
+ }
112
+ ];
113
+ }
114
+ if (status === "error") {
115
+ return [
116
+ {
117
+ type: "tool-result",
118
+ callId,
119
+ name,
120
+ result: serializeToolResult(msg.result, "Tool failed"),
121
+ isError: true
122
+ }
123
+ ];
124
+ }
125
+ if (status === "running") {
126
+ return [
127
+ {
128
+ type: "tool-call",
129
+ callId,
130
+ name,
131
+ input: msg.args ?? msg.input ?? msg.arguments ?? {}
132
+ }
133
+ ];
134
+ }
135
+ return [];
136
+ }
137
+ __name(fromToolUse, "fromToolUse");
138
+ function fromStatus(msg) {
139
+ const s = msg.status;
140
+ if (s === "FINISHED" || s === "CANCELLED") return [
141
+ {
142
+ type: "finish",
143
+ reason: s.toLowerCase()
144
+ }
145
+ ];
146
+ if (s === "ERROR" || s === "EXPIRED") {
147
+ return [
148
+ {
149
+ type: "error",
150
+ message: asString(msg.message, "Agent error"),
151
+ code: "AGENT_ERROR"
152
+ }
153
+ ];
154
+ }
155
+ return [];
156
+ }
157
+ __name(fromStatus, "fromStatus");
158
+ function fromSdkMessage(msg) {
159
+ switch (msg.type) {
160
+ case "assistant":
161
+ return fromAssistant(msg);
162
+ case "tool_call":
163
+ return fromToolUse(msg);
164
+ case "thinking":
165
+ return [
166
+ {
167
+ type: "reasoning",
168
+ text: asString(msg.text, "")
169
+ }
170
+ ];
171
+ case "status":
172
+ return fromStatus(msg);
173
+ // `system` / run-lifecycle is framework framing, not pure output — intentionally skipped (ADR-4).
174
+ default:
175
+ return [];
176
+ }
177
+ }
178
+ __name(fromSdkMessage, "fromSdkMessage");
179
+ function fromInteractionUpdate(update) {
180
+ switch (update.type) {
181
+ case "text-delta":
182
+ return update.text ? [
183
+ {
184
+ type: "text",
185
+ text: update.text
186
+ }
187
+ ] : [];
188
+ case "thinking-delta":
189
+ return update.text ? [
190
+ {
191
+ type: "reasoning",
192
+ text: update.text
193
+ }
194
+ ] : [];
195
+ case "tool-call-started":
196
+ return [
197
+ {
198
+ type: "tool-call",
199
+ callId: update.callId,
200
+ name: update.toolCall.name,
201
+ input: update.toolCall.args ?? {}
202
+ }
203
+ ];
204
+ case "partial-tool-call":
205
+ return [
206
+ {
207
+ type: "partial-tool-call",
208
+ callId: update.callId,
209
+ name: update.toolCall.name,
210
+ input: update.toolCall.args ?? {}
211
+ }
212
+ ];
213
+ case "tool-call-completed":
214
+ return [
215
+ {
216
+ type: "tool-result",
217
+ callId: update.callId,
218
+ name: update.toolCall.name,
219
+ result: serializeToolResult(update.toolCall.result, ""),
220
+ isError: false
221
+ }
222
+ ];
223
+ default:
224
+ return [];
225
+ }
226
+ }
227
+ __name(fromInteractionUpdate, "fromInteractionUpdate");
228
+
229
+ // src/presenters/ui-message-stream.ts
230
+ var UIMessageStreamPresenter = class {
231
+ static {
232
+ __name(this, "UIMessageStreamPresenter");
233
+ }
234
+ surface = "ui-message-stream";
235
+ #textId;
236
+ #openBlock = null;
237
+ #reasoningId = null;
238
+ #seen = /* @__PURE__ */ new Set();
239
+ constructor(options) {
240
+ this.#textId = options.textId;
241
+ }
242
+ /** Emit the opening `start` chunk (exactly once, before any event). */
243
+ start() {
244
+ return [
245
+ {
246
+ type: "start"
247
+ }
248
+ ];
249
+ }
250
+ present(event) {
251
+ switch (event.type) {
252
+ case "text":
253
+ return this.#emitTextDelta(event.text);
254
+ case "reasoning":
255
+ return this.#emitReasoningDelta(event.text);
256
+ case "tool-call":
257
+ return [
258
+ ...this.#closeOpenBlock(),
259
+ ...this.#emitToolCall(event.callId, event.name, event.input)
260
+ ];
261
+ case "tool-result":
262
+ return [
263
+ ...this.#closeOpenBlock(),
264
+ ...this.#emitToolResult(event.callId, event.name, event.result, event.isError ?? false)
265
+ ];
266
+ case "error":
267
+ return [
268
+ {
269
+ type: "error",
270
+ errorText: event.message
271
+ }
272
+ ];
273
+ // `partial-tool-call` streams incremental args — the current web path emits no chunk for it
274
+ // (args are shown on the committed `tool-call`); `finish` / `status` are handled by finish()/host.
275
+ default:
276
+ return [];
277
+ }
278
+ }
279
+ /**
280
+ * Close any open text/reasoning block and emit the terminal `finish` chunk. When `metadata` is given
281
+ * (a clean run's turn totals from the framework `done`), it rides `messageMetadata`; otherwise the
282
+ * finish is bare (error/abort turns), byte-identical to the original translator.
283
+ */
284
+ finish(metadata) {
285
+ const out = this.#closeOpenBlock();
286
+ out.push(metadata ? {
287
+ type: "finish",
288
+ messageMetadata: metadata
289
+ } : {
290
+ type: "finish"
291
+ });
292
+ return out;
293
+ }
294
+ /**
295
+ * Close any open text/reasoning block WITHOUT finishing the stream. The host calls this before
296
+ * interleaving a framework chunk (HITL approval / checkpoint) that must not appear inside an open text
297
+ * block — mirroring the original translator's `closeOpenBlock` before those chunks. Idempotent.
298
+ */
299
+ closeBlock() {
300
+ return this.#closeOpenBlock();
301
+ }
302
+ /**
303
+ * Whether a `callId` has already been introduced (a `tool-call` or a synthesized `tool-input`). The host
304
+ * uses this so a framework `approval_required` reuses the EC-1 synthesize-input-first rule exactly once.
305
+ */
306
+ hasSeen(callId) {
307
+ return this.#seen.has(callId);
308
+ }
309
+ /** Mark a `callId` as introduced (the host synthesized its `tool-input` for a framework chunk). */
310
+ markSeen(callId) {
311
+ this.#seen.add(callId);
312
+ }
313
+ // --- internal open-block state machine (verbatim from the original translator) ---
314
+ #closeOpenBlock() {
315
+ const out = [];
316
+ if (this.#openBlock === "text") {
317
+ out.push({
318
+ type: "text-end",
319
+ id: this.#textId
320
+ });
321
+ } else if (this.#openBlock === "reasoning" && this.#reasoningId) {
322
+ out.push({
323
+ type: "reasoning-end",
324
+ id: this.#reasoningId
325
+ });
326
+ }
327
+ this.#openBlock = null;
328
+ this.#reasoningId = null;
329
+ return out;
330
+ }
331
+ #emitTextDelta(content) {
332
+ const out = [];
333
+ if (this.#openBlock !== "text") {
334
+ out.push(...this.#closeOpenBlock(), {
335
+ type: "text-start",
336
+ id: this.#textId
337
+ });
338
+ this.#openBlock = "text";
339
+ }
340
+ out.push({
341
+ type: "text-delta",
342
+ id: this.#textId,
343
+ delta: content
344
+ });
345
+ return out;
346
+ }
347
+ #emitReasoningDelta(content) {
348
+ const out = [];
349
+ let reasoningId = this.#openBlock === "reasoning" ? this.#reasoningId : null;
350
+ if (reasoningId === null) {
351
+ out.push(...this.#closeOpenBlock());
352
+ reasoningId = crypto.randomUUID();
353
+ this.#reasoningId = reasoningId;
354
+ out.push({
355
+ type: "reasoning-start",
356
+ id: reasoningId
357
+ });
358
+ this.#openBlock = "reasoning";
359
+ }
360
+ out.push({
361
+ type: "reasoning-delta",
362
+ id: reasoningId,
363
+ delta: content
364
+ });
365
+ return out;
366
+ }
367
+ #emitToolCall(callId, name, input) {
368
+ this.#seen.add(callId);
369
+ return [
370
+ {
371
+ type: "tool-input-available",
372
+ toolCallId: callId,
373
+ toolName: name,
374
+ input,
375
+ dynamic: true
376
+ }
377
+ ];
378
+ }
379
+ #emitToolResult(callId, name, result, isError) {
380
+ const out = [];
381
+ if (!this.#seen.has(callId)) {
382
+ this.#seen.add(callId);
383
+ out.push({
384
+ type: "tool-input-available",
385
+ toolCallId: callId,
386
+ toolName: name,
387
+ input: {},
388
+ dynamic: true
389
+ });
390
+ }
391
+ const output = typeof result === "string" ? result : "";
392
+ if (isError) {
393
+ out.push({
394
+ type: "tool-output-error",
395
+ toolCallId: callId,
396
+ errorText: output
397
+ });
398
+ } else {
399
+ out.push({
400
+ type: "tool-output-available",
401
+ toolCallId: callId,
402
+ output
403
+ });
404
+ }
405
+ return out;
406
+ }
407
+ };
408
+ export {
409
+ AGENT_OUTPUT_EVENT_TYPES,
410
+ PresenterRegistry,
411
+ UIMessageStreamPresenter,
412
+ UnknownPresenterError,
413
+ fromInteractionUpdate,
414
+ fromSdkMessage,
415
+ isErrorEvent,
416
+ isFinishEvent,
417
+ isPartialToolCallEvent,
418
+ isReasoningEvent,
419
+ isStatusEvent,
420
+ isTextEvent,
421
+ isToolCallEvent,
422
+ isToolResultEvent
423
+ };
424
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/agent-output-event.ts","../src/presenter.ts","../src/source/from-sdk.ts","../src/presenters/ui-message-stream.ts"],"sourcesContent":["/**\n * `AgentOutputEvent` — the canonical, normalized agent-output event (M49).\n *\n * This is the **narrow waist** of theokit's presentation layer: ONE normalized event that every SOURCE\n * (the SDK's `SDKMessage` / `InteractionUpdate`) is translated INTO, and that every `Presenter`\n * (web `UIMessageStream`, terminal ANSI, JSON API) is translated OUT of. Without it you get N×M\n * translators — the current duplication where the web path and the terminal path each re-translate the\n * SDK independently and drift. The variants are derived from the SDK's own event discriminants (source\n * side), NOT from any single surface's wire format, so no surface leaks into the contract.\n *\n * @public\n */\nexport type AgentOutputEvent =\n | AgentTextEvent\n | AgentReasoningEvent\n | AgentToolCallEvent\n | AgentPartialToolCallEvent\n | AgentToolResultEvent\n | AgentErrorEvent\n | AgentFinishEvent\n | AgentStatusEvent\n\n/** Assistant text output (streamed or whole). */\nexport interface AgentTextEvent {\n readonly type: 'text'\n readonly text: string\n}\n\n/** Model reasoning / thinking content (distinct from user-visible text). */\nexport interface AgentReasoningEvent {\n readonly type: 'reasoning'\n readonly text: string\n}\n\n/** A tool invocation with its (committed) input — the args the model decided on. */\nexport interface AgentToolCallEvent {\n readonly type: 'tool-call'\n readonly callId: string\n readonly name: string\n readonly input: unknown\n}\n\n/**\n * Incremental tool input as the model streams the args (theokit-sdk#70) — a DISTINCT lifecycle point\n * from `tool-call` (args committed). Consumers that stream tool-input render the progressive args; those\n * that don't may ignore it. Never duplicates `tool-call`.\n */\nexport interface AgentPartialToolCallEvent {\n readonly type: 'partial-tool-call'\n readonly callId: string\n readonly name: string\n readonly input: unknown\n}\n\n/** The result of a tool invocation, keyed by the same `callId`. `isError` marks a failed tool. */\nexport interface AgentToolResultEvent {\n readonly type: 'tool-result'\n readonly callId: string\n readonly name: string\n readonly result: unknown\n readonly isError?: boolean\n}\n\n/** A run-level error (typed message + optional code). */\nexport interface AgentErrorEvent {\n readonly type: 'error'\n readonly message: string\n readonly code?: string\n}\n\n/** Terminal event of a turn: the run finished. `usage` carries token accounting when available. */\nexport interface AgentFinishEvent {\n readonly type: 'finish'\n readonly reason?: string\n readonly usage?: { readonly totalTokens?: number }\n}\n\n/** A lifecycle status transition (e.g. goal `active` → `completed`), surface-agnostic. */\nexport interface AgentStatusEvent {\n readonly type: 'status'\n readonly status: string\n readonly detail?: string\n}\n\n/** The stable set of variant discriminants — useful for exhaustiveness and registry keys. */\nexport const AGENT_OUTPUT_EVENT_TYPES = [\n 'text',\n 'reasoning',\n 'tool-call',\n 'partial-tool-call',\n 'tool-result',\n 'error',\n 'finish',\n 'status',\n] as const\n\nexport type AgentOutputEventType = (typeof AGENT_OUTPUT_EVENT_TYPES)[number]\n\n// --- type guards (discriminate a canonical event without a manual `switch`) ---\n\nexport const isTextEvent = (e: AgentOutputEvent): e is AgentTextEvent => e.type === 'text'\nexport const isReasoningEvent = (e: AgentOutputEvent): e is AgentReasoningEvent =>\n e.type === 'reasoning'\nexport const isToolCallEvent = (e: AgentOutputEvent): e is AgentToolCallEvent =>\n e.type === 'tool-call'\nexport const isPartialToolCallEvent = (e: AgentOutputEvent): e is AgentPartialToolCallEvent =>\n e.type === 'partial-tool-call'\nexport const isToolResultEvent = (e: AgentOutputEvent): e is AgentToolResultEvent =>\n e.type === 'tool-result'\nexport const isErrorEvent = (e: AgentOutputEvent): e is AgentErrorEvent => e.type === 'error'\nexport const isFinishEvent = (e: AgentOutputEvent): e is AgentFinishEvent => e.type === 'finish'\nexport const isStatusEvent = (e: AgentOutputEvent): e is AgentStatusEvent => e.type === 'status'\n","import type { AgentOutputEvent } from './agent-output-event.js'\n\n/**\n * `Presenter<TOut>` — the Strategy that turns the canonical {@link AgentOutputEvent} into ONE surface's\n * output (M49). Web (`UIMessageStream`), terminal (ANSI), and JSON API are peer implementations; each\n * consumes the SAME canonical event, so a source is translated once and every surface reuses it.\n *\n * The contract is **per-event, driven by the caller**: the host loops the event stream and calls\n * `present(event)` for each, so it can INTERLEAVE a presenter's pure-output chunks with framework chunks\n * (HITL approval, checkpoints, done-metadata — `@theokit/agents`) in true model order (ADR-4). Optional\n * `start()` / `finish()` bracket the stream for stateful surfaces (the web stream's `start` framing and\n * its open-block close + `finish`). A stateful presenter (web) holds its open-block state internally and\n * is therefore instantiated **per stream**; stateless presenters (terminal/json) may be singletons.\n *\n * @public\n */\nexport interface Presenter<TOut> {\n /** Stable surface key (`\"ui-message-stream\" | \"terminal\" | \"json\" | …`) — the registry resolves by it. */\n readonly surface: string\n /** Optional opening framing emitted once before any event (e.g. the web stream's `{ type: 'start' }`). */\n start?(): TOut[]\n /** Translate one canonical event into zero or more surface chunks (may maintain internal stream state). */\n present(event: AgentOutputEvent): TOut[]\n /** Optional closing framing emitted once after the last event (e.g. close the open block + `finish`). */\n finish?(): TOut[]\n}\n\n/** Thrown when a surface key is resolved but no presenter is registered for it (fail-fast, typed). */\nexport class UnknownPresenterError extends Error {\n override readonly name = 'UnknownPresenterError'\n constructor(surface: string, known: readonly string[]) {\n super(\n `No presenter registered for surface \"${surface}\". Known: ${known.join(', ') || '(none)'}.`,\n )\n }\n}\n\n/**\n * A registry of presenters keyed by surface. Lets a single agent run be driven through any registered\n * surface without the caller hard-wiring a concrete presenter (Open/Closed — add a surface by registering,\n * not by editing a switch).\n *\n * @public\n */\nexport class PresenterRegistry {\n readonly #presenters = new Map<string, Presenter<unknown>>()\n\n /** Register (or replace) the presenter for its surface. Returns `this` for fluent wiring. */\n register(presenter: Presenter<unknown>): this {\n this.#presenters.set(presenter.surface, presenter)\n return this\n }\n\n /** Whether a presenter is registered for `surface`. */\n has(surface: string): boolean {\n return this.#presenters.has(surface)\n }\n\n /** The registered surface keys. */\n surfaces(): string[] {\n return [...this.#presenters.keys()]\n }\n\n /** Resolve the presenter for `surface`, or throw {@link UnknownPresenterError} (never returns undefined). */\n resolve<TOut>(surface: string): Presenter<TOut> {\n const p = this.#presenters.get(surface)\n if (p === undefined) throw new UnknownPresenterError(surface, this.surfaces())\n return p as Presenter<TOut>\n }\n}\n","import type { InteractionUpdate } from '@theokit/sdk'\n\nimport type { AgentOutputEvent } from '../agent-output-event.js'\n\n/**\n * `fromSdk` (M49) — the SINGLE source translator: `@theokit/sdk` output → the canonical\n * {@link AgentOutputEvent}. Every presenter (web / terminal / json) consumes the result, so the SDK is\n * parsed ONCE instead of each surface re-translating it (the duplication this layer removes).\n *\n * Ported faithfully from `@theokit/agents/bridge/event-translator.ts` (the proven web-path logic), but\n * emitting the NARROW pure-output event: framework concerns (run-lifecycle, HITL approval, checkpoints,\n * devtools artifacts) are NOT SDK output and are layered by `@theokit/agents` on top (ADR-4), so they are\n * intentionally NOT produced here.\n */\n\n/** Minimal SDK message shape — duck-typed to avoid a hard import of every SDK message subtype. */\nexport interface SdkMessage {\n readonly type: string\n readonly [key: string]: unknown\n}\n\n/** Safely coerce an unknown value to a string, else the fallback. */\nfunction asString(value: unknown, fallback: string): string {\n return typeof value === 'string' ? value : fallback\n}\n\n/**\n * Serialize a tool's `result` for the canonical `tool-result.result`. String passthrough; null/undefined →\n * fallback; otherwise JSON. `JSON.stringify` throws on BigInt / circular refs — preserve a BigInt's real\n * value, else fall back (never `[object Object]`). Mirrors event-translator's `serializeToolOutput` (#41).\n */\nfunction serializeToolResult(value: unknown, fallback: string): string {\n if (typeof value === 'string') return value\n if (value === undefined || value === null) return fallback\n try {\n return JSON.stringify(value)\n } catch {\n return typeof value === 'bigint' ? value.toString() : fallback\n }\n}\n\nfunction fromAssistant(msg: SdkMessage): AgentOutputEvent[] {\n const events: AgentOutputEvent[] = []\n const content = (msg.message as { content?: unknown } | undefined)?.content\n if (!Array.isArray(content)) return events\n for (const block of content) {\n const b = block as { type: string; text?: string; name?: string; input?: unknown; id?: string }\n if (b.type === 'text' && b.text) events.push({ type: 'text', text: b.text })\n if (b.type === 'tool_use') {\n events.push({\n type: 'tool-call',\n callId: b.id ?? `tc-${Date.now()}`,\n name: b.name ?? 'unknown',\n input: b.input ?? {},\n })\n }\n }\n return events\n}\n\nfunction fromToolUse(msg: SdkMessage): AgentOutputEvent[] {\n const status = msg.status as string\n const callId = asString(msg.call_id, `tc-${Date.now()}`)\n const name = asString(msg.name, 'unknown')\n if (status === 'completed') {\n return [\n {\n type: 'tool-result',\n callId,\n name,\n result: serializeToolResult(msg.result, ''),\n isError: false,\n },\n ]\n }\n if (status === 'error') {\n return [\n {\n type: 'tool-result',\n callId,\n name,\n result: serializeToolResult(msg.result, 'Tool failed'),\n isError: true,\n },\n ]\n }\n if (status === 'running') {\n // Tool start — emit the committed call so the UI shows the running card. The SDK carries args in\n // `args` (theokit#58; `input`/`arguments` were never the field); keep the others as defensive fallbacks.\n return [\n { type: 'tool-call', callId, name, input: msg.args ?? msg.input ?? msg.arguments ?? {} },\n ]\n }\n return []\n}\n\nfunction fromStatus(msg: SdkMessage): AgentOutputEvent[] {\n // SDKStatusMessage: UPPERCASE cloud-run lifecycle. FINISHED/CANCELLED → finish (terminal-clean);\n // ERROR/EXPIRED → error (terminal-failure, fail-loud). CREATING/RUNNING → in-progress (no output).\n const s = msg.status as string\n if (s === 'FINISHED' || s === 'CANCELLED') return [{ type: 'finish', reason: s.toLowerCase() }]\n if (s === 'ERROR' || s === 'EXPIRED') {\n return [{ type: 'error', message: asString(msg.message, 'Agent error'), code: 'AGENT_ERROR' }]\n }\n return []\n}\n\n/** Translate ONE buffered SDK message (`run.stream()`) to zero or more canonical output events. */\nexport function fromSdkMessage(msg: SdkMessage): AgentOutputEvent[] {\n switch (msg.type) {\n case 'assistant':\n return fromAssistant(msg)\n case 'tool_call':\n return fromToolUse(msg)\n case 'thinking':\n return [{ type: 'reasoning', text: asString(msg.text, '') }]\n case 'status':\n return fromStatus(msg)\n // `system` / run-lifecycle is framework framing, not pure output — intentionally skipped (ADR-4).\n default:\n return []\n }\n}\n\n/**\n * Translate ONE real-time `onDelta` {@link InteractionUpdate} to zero or more canonical output events, in\n * arrival order — the chronological path that keeps text / tool / thinking interleaved in true model order.\n * `partial-tool-call` is surfaced distinctly (theokit-sdk#70); it never duplicates `tool-call`.\n */\nexport function fromInteractionUpdate(update: InteractionUpdate): AgentOutputEvent[] {\n switch (update.type) {\n case 'text-delta':\n return update.text ? [{ type: 'text', text: update.text }] : []\n case 'thinking-delta':\n return update.text ? [{ type: 'reasoning', text: update.text }] : []\n case 'tool-call-started':\n return [\n {\n type: 'tool-call',\n callId: update.callId,\n name: update.toolCall.name,\n input: update.toolCall.args ?? {},\n },\n ]\n case 'partial-tool-call':\n return [\n {\n type: 'partial-tool-call',\n callId: update.callId,\n name: update.toolCall.name,\n input: update.toolCall.args ?? {},\n },\n ]\n case 'tool-call-completed':\n return [\n {\n type: 'tool-result',\n callId: update.callId,\n name: update.toolCall.name,\n result: serializeToolResult(update.toolCall.result, ''),\n isError: false,\n },\n ]\n default:\n return []\n }\n}\n","import type { UIMessageChunk } from 'ai'\n\nimport type { AgentOutputEvent } from '../agent-output-event.js'\nimport type { Presenter } from '../presenter.js'\n\n/**\n * `UIMessageStreamPresenter` (M49) — the web surface: the canonical {@link AgentOutputEvent} → the Vercel\n * ai-sdk `UIMessageStream` (`UIMessageChunk`), consumed by `useChat` / assistant-ui.\n *\n * Ported faithfully from `@theokit/agents/bridge/ui-message-stream-translator.ts` (the M1 web path) with\n * ZERO behavior change for the pure-output events. Framework chunks (HITL `tool-approval-request`,\n * `data-checkpoint`) are NOT emitted here — they ride on `@theokit/agents` framework events and are\n * composed by the agents web handler around this presenter (ADR-4).\n *\n * STATEFUL (open-block state machine) → instantiate ONE per stream. The host brackets the stream with\n * {@link start} / {@link finish} and drives {@link present} per event, interleaving framework chunks.\n *\n * Chunk sequences (unchanged):\n * text run: start → text-start{id} → text-delta{id,delta}* → text-end{id} → finish\n * reasoning run: start → reasoning-start{id} → reasoning-delta{id,delta}* → reasoning-end{id} → finish\n * tool run: start → tool-input-available{callId,name,input} → tool-output-available{callId,output} → finish\n *\n * @public\n */\nexport interface TurnMetadata {\n readonly usage?: {\n readonly inputTokens?: number\n readonly outputTokens?: number\n readonly totalTokens?: number\n }\n readonly durationMs?: number\n readonly cost?: number\n}\n\nexport interface UIMessageStreamPresenterOptions {\n /** A single shared id for every text block — injected for deterministic tests (D3). */\n readonly textId: string\n}\n\nexport class UIMessageStreamPresenter implements Presenter<UIMessageChunk> {\n readonly surface = 'ui-message-stream'\n readonly #textId: string\n #openBlock: 'text' | 'reasoning' | null = null\n #reasoningId: string | null = null\n readonly #seen = new Set<string>()\n\n constructor(options: UIMessageStreamPresenterOptions) {\n this.#textId = options.textId\n }\n\n /** Emit the opening `start` chunk (exactly once, before any event). */\n start(): UIMessageChunk[] {\n return [{ type: 'start' }]\n }\n\n present(event: AgentOutputEvent): UIMessageChunk[] {\n switch (event.type) {\n case 'text':\n return this.#emitTextDelta(event.text)\n case 'reasoning':\n return this.#emitReasoningDelta(event.text)\n case 'tool-call':\n return [\n ...this.#closeOpenBlock(),\n ...this.#emitToolCall(event.callId, event.name, event.input),\n ]\n case 'tool-result':\n return [\n ...this.#closeOpenBlock(),\n ...this.#emitToolResult(event.callId, event.name, event.result, event.isError ?? false),\n ]\n case 'error':\n // Surface the failure as an ai-sdk error chunk (fail-clear); the host stops and calls finish().\n return [{ type: 'error', errorText: event.message }]\n // `partial-tool-call` streams incremental args — the current web path emits no chunk for it\n // (args are shown on the committed `tool-call`); `finish` / `status` are handled by finish()/host.\n default:\n return []\n }\n }\n\n /**\n * Close any open text/reasoning block and emit the terminal `finish` chunk. When `metadata` is given\n * (a clean run's turn totals from the framework `done`), it rides `messageMetadata`; otherwise the\n * finish is bare (error/abort turns), byte-identical to the original translator.\n */\n finish(metadata?: TurnMetadata): UIMessageChunk[] {\n const out = this.#closeOpenBlock()\n out.push(metadata ? { type: 'finish', messageMetadata: metadata } : { type: 'finish' })\n return out\n }\n\n /**\n * Close any open text/reasoning block WITHOUT finishing the stream. The host calls this before\n * interleaving a framework chunk (HITL approval / checkpoint) that must not appear inside an open text\n * block — mirroring the original translator's `closeOpenBlock` before those chunks. Idempotent.\n */\n closeBlock(): UIMessageChunk[] {\n return this.#closeOpenBlock()\n }\n\n /**\n * Whether a `callId` has already been introduced (a `tool-call` or a synthesized `tool-input`). The host\n * uses this so a framework `approval_required` reuses the EC-1 synthesize-input-first rule exactly once.\n */\n hasSeen(callId: string): boolean {\n return this.#seen.has(callId)\n }\n\n /** Mark a `callId` as introduced (the host synthesized its `tool-input` for a framework chunk). */\n markSeen(callId: string): void {\n this.#seen.add(callId)\n }\n\n // --- internal open-block state machine (verbatim from the original translator) ---\n\n #closeOpenBlock(): UIMessageChunk[] {\n const out: UIMessageChunk[] = []\n if (this.#openBlock === 'text') {\n out.push({ type: 'text-end', id: this.#textId })\n } else if (this.#openBlock === 'reasoning' && this.#reasoningId) {\n out.push({ type: 'reasoning-end', id: this.#reasoningId })\n }\n this.#openBlock = null\n this.#reasoningId = null\n return out\n }\n\n #emitTextDelta(content: string): UIMessageChunk[] {\n const out: UIMessageChunk[] = []\n if (this.#openBlock !== 'text') {\n out.push(...this.#closeOpenBlock(), { type: 'text-start', id: this.#textId })\n this.#openBlock = 'text'\n }\n out.push({ type: 'text-delta', id: this.#textId, delta: content })\n return out\n }\n\n #emitReasoningDelta(content: string): UIMessageChunk[] {\n const out: UIMessageChunk[] = []\n let reasoningId = this.#openBlock === 'reasoning' ? this.#reasoningId : null\n if (reasoningId === null) {\n out.push(...this.#closeOpenBlock())\n reasoningId = crypto.randomUUID()\n this.#reasoningId = reasoningId\n out.push({ type: 'reasoning-start', id: reasoningId })\n this.#openBlock = 'reasoning'\n }\n out.push({ type: 'reasoning-delta', id: reasoningId, delta: content })\n return out\n }\n\n #emitToolCall(callId: string, name: string, input: unknown): UIMessageChunk[] {\n this.#seen.add(callId)\n return [\n { type: 'tool-input-available', toolCallId: callId, toolName: name, input, dynamic: true },\n ]\n }\n\n #emitToolResult(\n callId: string,\n name: string,\n result: unknown,\n isError: boolean,\n ): UIMessageChunk[] {\n const out: UIMessageChunk[] = []\n if (!this.#seen.has(callId)) {\n this.#seen.add(callId)\n out.push({\n type: 'tool-input-available',\n toolCallId: callId,\n toolName: name,\n input: {},\n dynamic: true,\n })\n }\n // The canonical tool-result carries a serialized string `result` (from `fromSdk`).\n const output = typeof result === 'string' ? result : ''\n if (isError) {\n out.push({ type: 'tool-output-error', toolCallId: callId, errorText: output })\n } else {\n out.push({ type: 'tool-output-available', toolCallId: callId, output })\n }\n return out\n }\n}\n"],"mappings":";;;;AAqFO,IAAMA,2BAA2B;EACtC;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;AAOK,IAAMC,cAAc,wBAACC,MAA6CA,EAAEC,SAAS,QAAzD;AACpB,IAAMC,mBAAmB,wBAACF,MAC/BA,EAAEC,SAAS,aADmB;AAEzB,IAAME,kBAAkB,wBAACH,MAC9BA,EAAEC,SAAS,aADkB;AAExB,IAAMG,yBAAyB,wBAACJ,MACrCA,EAAEC,SAAS,qBADyB;AAE/B,IAAMI,oBAAoB,wBAACL,MAChCA,EAAEC,SAAS,eADoB;AAE1B,IAAMK,eAAe,wBAACN,MAA8CA,EAAEC,SAAS,SAA1D;AACrB,IAAMM,gBAAgB,wBAACP,MAA+CA,EAAEC,SAAS,UAA3D;AACtB,IAAMO,gBAAgB,wBAACR,MAA+CA,EAAEC,SAAS,UAA3D;;;ACnFtB,IAAMQ,wBAAN,cAAoCC,MAAAA;EAD3C,OAC2CA;;;EACvBC,OAAO;EACzB,YAAYC,SAAiBC,OAA0B;AACrD,UACE,wCAAwCD,OAA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AYvB;QAAQ0B;MAAO,CAAA;IACvE;AACA,WAAOjB;EACT;AACF;","names":["AGENT_OUTPUT_EVENT_TYPES","isTextEvent","e","type","isReasoningEvent","isToolCallEvent","isPartialToolCallEvent","isToolResultEvent","isErrorEvent","isFinishEvent","isStatusEvent","UnknownPresenterError","Error","name","surface","known","join","PresenterRegistry","Map","register","presenter","set","has","surfaces","keys","resolve","p","get","undefined","asString","value","fallback","serializeToolResult","undefined","JSON","stringify","toString","fromAssistant","msg","events","content","message","Array","isArray","block","b","type","text","push","callId","id","Date","now","name","input","fromToolUse","status","call_id","result","isError","args","arguments","fromStatus","s","reason","toLowerCase","code","fromSdkMessage","fromInteractionUpdate","update","toolCall","UIMessageStreamPresenter","surface","Set","options","textId","start","type","present","event","text","callId","name","input","result","isError","errorText","message","finish","metadata","out","push","messageMetadata","closeBlock","hasSeen","has","markSeen","add","id","content","delta","reasoningId","crypto","randomUUID","toolCallId","toolName","dynamic","output"]}
package/package.json ADDED
@@ -0,0 +1,41 @@
1
+ {
2
+ "name": "@theokit/presenter",
3
+ "version": "0.2.0",
4
+ "description": "TheoKit's presentation layer — the canonical AgentOutputEvent + Presenter Strategy that turns @theokit/sdk agent output into any surface (web UIMessageStream, terminal ANSI, JSON API) from ONE normalized event.",
5
+ "type": "module",
6
+ "sideEffects": false,
7
+ "main": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/index.js"
13
+ }
14
+ },
15
+ "files": [
16
+ "dist",
17
+ "README.md",
18
+ "LICENSE"
19
+ ],
20
+ "peerDependencies": {
21
+ "@theokit/sdk": ">=3.5.0",
22
+ "ai": "^7.0.0"
23
+ },
24
+ "devDependencies": {
25
+ "@theokit/sdk": "^3.5.0",
26
+ "ai": "^7.0.0",
27
+ "tsup": "^8.5.1",
28
+ "typescript": "^5.9.3",
29
+ "vitest": "^3.2.6"
30
+ },
31
+ "license": "MIT",
32
+ "engines": {
33
+ "node": ">=22.12.0"
34
+ },
35
+ "scripts": {
36
+ "build": "tsup",
37
+ "test": "vitest run",
38
+ "test:watch": "vitest",
39
+ "typecheck": "tsc --noEmit"
40
+ }
41
+ }