@theokit/presenter 0.6.0 → 0.7.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 +201 -0
- package/dist/chunk-Z4QWC7IK.js +7 -0
- package/dist/chunk-Z4QWC7IK.js.map +1 -0
- package/dist/index.js +211 -67
- package/dist/index.js.map +1 -1
- package/dist/wire/index.js +101 -37
- package/dist/wire/index.js.map +1 -1
- package/package.json +11 -11
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 @@
|
|
|
1
|
+
{"version":3,"sources":[],"mappings":"","names":[]}
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__name
|
|
3
|
+
} from "./chunk-Z4QWC7IK.js";
|
|
4
|
+
|
|
1
5
|
// src/agent-output-event.ts
|
|
2
6
|
var AGENT_OUTPUT_EVENT_TYPES = [
|
|
3
7
|
"text",
|
|
@@ -9,25 +13,29 @@ var AGENT_OUTPUT_EVENT_TYPES = [
|
|
|
9
13
|
"finish",
|
|
10
14
|
"status"
|
|
11
15
|
];
|
|
12
|
-
var isTextEvent = (e) => e.type === "text";
|
|
13
|
-
var isReasoningEvent = (e) => e.type === "reasoning";
|
|
14
|
-
var isToolCallEvent = (e) => e.type === "tool-call";
|
|
15
|
-
var isPartialToolCallEvent = (e) => e.type === "partial-tool-call";
|
|
16
|
-
var isToolResultEvent = (e) => e.type === "tool-result";
|
|
17
|
-
var isErrorEvent = (e) => e.type === "error";
|
|
18
|
-
var isFinishEvent = (e) => e.type === "finish";
|
|
19
|
-
var isStatusEvent = (e) => e.type === "status";
|
|
16
|
+
var isTextEvent = /* @__PURE__ */ __name((e) => e.type === "text", "isTextEvent");
|
|
17
|
+
var isReasoningEvent = /* @__PURE__ */ __name((e) => e.type === "reasoning", "isReasoningEvent");
|
|
18
|
+
var isToolCallEvent = /* @__PURE__ */ __name((e) => e.type === "tool-call", "isToolCallEvent");
|
|
19
|
+
var isPartialToolCallEvent = /* @__PURE__ */ __name((e) => e.type === "partial-tool-call", "isPartialToolCallEvent");
|
|
20
|
+
var isToolResultEvent = /* @__PURE__ */ __name((e) => e.type === "tool-result", "isToolResultEvent");
|
|
21
|
+
var isErrorEvent = /* @__PURE__ */ __name((e) => e.type === "error", "isErrorEvent");
|
|
22
|
+
var isFinishEvent = /* @__PURE__ */ __name((e) => e.type === "finish", "isFinishEvent");
|
|
23
|
+
var isStatusEvent = /* @__PURE__ */ __name((e) => e.type === "status", "isStatusEvent");
|
|
20
24
|
|
|
21
25
|
// src/presenter.ts
|
|
22
26
|
var UnknownPresenterError = class extends Error {
|
|
27
|
+
static {
|
|
28
|
+
__name(this, "UnknownPresenterError");
|
|
29
|
+
}
|
|
23
30
|
name = "UnknownPresenterError";
|
|
24
31
|
constructor(surface, known) {
|
|
25
|
-
super(
|
|
26
|
-
`No presenter registered for surface "${surface}". Known: ${known.join(", ") || "(none)"}.`
|
|
27
|
-
);
|
|
32
|
+
super(`No presenter registered for surface "${surface}". Known: ${known.join(", ") || "(none)"}.`);
|
|
28
33
|
}
|
|
29
34
|
};
|
|
30
35
|
var PresenterRegistry = class {
|
|
36
|
+
static {
|
|
37
|
+
__name(this, "PresenterRegistry");
|
|
38
|
+
}
|
|
31
39
|
#presenters = /* @__PURE__ */ new Map();
|
|
32
40
|
/** Register (or replace) the presenter for its surface. Returns `this` for fluent wiring. */
|
|
33
41
|
register(presenter) {
|
|
@@ -40,7 +48,9 @@ var PresenterRegistry = class {
|
|
|
40
48
|
}
|
|
41
49
|
/** The registered surface keys. */
|
|
42
50
|
surfaces() {
|
|
43
|
-
return [
|
|
51
|
+
return [
|
|
52
|
+
...this.#presenters.keys()
|
|
53
|
+
];
|
|
44
54
|
}
|
|
45
55
|
/** Resolve the presenter for `surface`, or throw {@link UnknownPresenterError} (never returns undefined). */
|
|
46
56
|
resolve(surface) {
|
|
@@ -54,6 +64,7 @@ var PresenterRegistry = class {
|
|
|
54
64
|
function asString(value, fallback) {
|
|
55
65
|
return typeof value === "string" ? value : fallback;
|
|
56
66
|
}
|
|
67
|
+
__name(asString, "asString");
|
|
57
68
|
function serializeToolResult(value, fallback) {
|
|
58
69
|
if (typeof value === "string") return value;
|
|
59
70
|
if (value === void 0 || value === null) return fallback;
|
|
@@ -63,13 +74,17 @@ function serializeToolResult(value, fallback) {
|
|
|
63
74
|
return typeof value === "bigint" ? value.toString() : fallback;
|
|
64
75
|
}
|
|
65
76
|
}
|
|
77
|
+
__name(serializeToolResult, "serializeToolResult");
|
|
66
78
|
function fromAssistant(msg) {
|
|
67
79
|
const events = [];
|
|
68
80
|
const content = msg.message?.content;
|
|
69
81
|
if (!Array.isArray(content)) return events;
|
|
70
82
|
for (const block of content) {
|
|
71
83
|
const b = block;
|
|
72
|
-
if (b.type === "text" && b.text) events.push({
|
|
84
|
+
if (b.type === "text" && b.text) events.push({
|
|
85
|
+
type: "text",
|
|
86
|
+
text: b.text
|
|
87
|
+
});
|
|
73
88
|
if (b.type === "tool_use") {
|
|
74
89
|
events.push({
|
|
75
90
|
type: "tool-call",
|
|
@@ -81,6 +96,7 @@ function fromAssistant(msg) {
|
|
|
81
96
|
}
|
|
82
97
|
return events;
|
|
83
98
|
}
|
|
99
|
+
__name(fromAssistant, "fromAssistant");
|
|
84
100
|
function fromToolUse(msg) {
|
|
85
101
|
const status = msg.status;
|
|
86
102
|
const callId = asString(msg.call_id, `tc-${Date.now()}`);
|
|
@@ -109,19 +125,37 @@ function fromToolUse(msg) {
|
|
|
109
125
|
}
|
|
110
126
|
if (status === "running") {
|
|
111
127
|
return [
|
|
112
|
-
{
|
|
128
|
+
{
|
|
129
|
+
type: "tool-call",
|
|
130
|
+
callId,
|
|
131
|
+
name,
|
|
132
|
+
input: msg.args ?? msg.input ?? msg.arguments ?? {}
|
|
133
|
+
}
|
|
113
134
|
];
|
|
114
135
|
}
|
|
115
136
|
return [];
|
|
116
137
|
}
|
|
138
|
+
__name(fromToolUse, "fromToolUse");
|
|
117
139
|
function fromStatus(msg) {
|
|
118
140
|
const s = msg.status;
|
|
119
|
-
if (s === "FINISHED" || s === "CANCELLED") return [
|
|
141
|
+
if (s === "FINISHED" || s === "CANCELLED") return [
|
|
142
|
+
{
|
|
143
|
+
type: "finish",
|
|
144
|
+
reason: s.toLowerCase()
|
|
145
|
+
}
|
|
146
|
+
];
|
|
120
147
|
if (s === "ERROR" || s === "EXPIRED") {
|
|
121
|
-
return [
|
|
148
|
+
return [
|
|
149
|
+
{
|
|
150
|
+
type: "error",
|
|
151
|
+
message: asString(msg.message, "Agent error"),
|
|
152
|
+
code: "AGENT_ERROR"
|
|
153
|
+
}
|
|
154
|
+
];
|
|
122
155
|
}
|
|
123
156
|
return [];
|
|
124
157
|
}
|
|
158
|
+
__name(fromStatus, "fromStatus");
|
|
125
159
|
function fromSdkMessage(msg) {
|
|
126
160
|
switch (msg.type) {
|
|
127
161
|
case "assistant":
|
|
@@ -129,7 +163,12 @@ function fromSdkMessage(msg) {
|
|
|
129
163
|
case "tool_call":
|
|
130
164
|
return fromToolUse(msg);
|
|
131
165
|
case "thinking":
|
|
132
|
-
return [
|
|
166
|
+
return [
|
|
167
|
+
{
|
|
168
|
+
type: "reasoning",
|
|
169
|
+
text: asString(msg.text, "")
|
|
170
|
+
}
|
|
171
|
+
];
|
|
133
172
|
case "status":
|
|
134
173
|
return fromStatus(msg);
|
|
135
174
|
// `system` / run-lifecycle is framework framing, not pure output — intentionally skipped (ADR-4).
|
|
@@ -137,12 +176,23 @@ function fromSdkMessage(msg) {
|
|
|
137
176
|
return [];
|
|
138
177
|
}
|
|
139
178
|
}
|
|
179
|
+
__name(fromSdkMessage, "fromSdkMessage");
|
|
140
180
|
function fromInteractionUpdate(update) {
|
|
141
181
|
switch (update.type) {
|
|
142
182
|
case "text-delta":
|
|
143
|
-
return update.text ? [
|
|
183
|
+
return update.text ? [
|
|
184
|
+
{
|
|
185
|
+
type: "text",
|
|
186
|
+
text: update.text
|
|
187
|
+
}
|
|
188
|
+
] : [];
|
|
144
189
|
case "thinking-delta":
|
|
145
|
-
return update.text ? [
|
|
190
|
+
return update.text ? [
|
|
191
|
+
{
|
|
192
|
+
type: "reasoning",
|
|
193
|
+
text: update.text
|
|
194
|
+
}
|
|
195
|
+
] : [];
|
|
146
196
|
case "tool-call-started":
|
|
147
197
|
return [
|
|
148
198
|
{
|
|
@@ -175,9 +225,13 @@ function fromInteractionUpdate(update) {
|
|
|
175
225
|
return [];
|
|
176
226
|
}
|
|
177
227
|
}
|
|
228
|
+
__name(fromInteractionUpdate, "fromInteractionUpdate");
|
|
178
229
|
|
|
179
230
|
// src/presenters/ui-message-stream.ts
|
|
180
231
|
var UIMessageStreamPresenter = class {
|
|
232
|
+
static {
|
|
233
|
+
__name(this, "UIMessageStreamPresenter");
|
|
234
|
+
}
|
|
181
235
|
surface = "ui-message-stream";
|
|
182
236
|
#textId;
|
|
183
237
|
#openBlock = null;
|
|
@@ -188,7 +242,11 @@ var UIMessageStreamPresenter = class {
|
|
|
188
242
|
}
|
|
189
243
|
/** Emit the opening `start` chunk (exactly once, before any event). */
|
|
190
244
|
start() {
|
|
191
|
-
return [
|
|
245
|
+
return [
|
|
246
|
+
{
|
|
247
|
+
type: "start"
|
|
248
|
+
}
|
|
249
|
+
];
|
|
192
250
|
}
|
|
193
251
|
present(event) {
|
|
194
252
|
switch (event.type) {
|
|
@@ -207,7 +265,12 @@ var UIMessageStreamPresenter = class {
|
|
|
207
265
|
...this.#emitToolResult(event.callId, event.name, event.result, event.isError ?? false)
|
|
208
266
|
];
|
|
209
267
|
case "error":
|
|
210
|
-
return [
|
|
268
|
+
return [
|
|
269
|
+
{
|
|
270
|
+
type: "error",
|
|
271
|
+
errorText: event.message
|
|
272
|
+
}
|
|
273
|
+
];
|
|
211
274
|
// `partial-tool-call` streams incremental args — the current web path emits no chunk for it
|
|
212
275
|
// (args are shown on the committed `tool-call`); `finish` / `status` are handled by finish()/host.
|
|
213
276
|
default:
|
|
@@ -215,27 +278,32 @@ var UIMessageStreamPresenter = class {
|
|
|
215
278
|
}
|
|
216
279
|
}
|
|
217
280
|
/**
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
281
|
+
* Close any open text/reasoning block and emit the terminal `finish` chunk. When `metadata` is given
|
|
282
|
+
* (a clean run's turn totals from the framework `done`), it rides `messageMetadata`; otherwise the
|
|
283
|
+
* finish is bare (error/abort turns), byte-identical to the original translator.
|
|
284
|
+
*/
|
|
222
285
|
finish(metadata) {
|
|
223
286
|
const out = this.#closeOpenBlock();
|
|
224
|
-
out.push(metadata ? {
|
|
287
|
+
out.push(metadata ? {
|
|
288
|
+
type: "finish",
|
|
289
|
+
messageMetadata: metadata
|
|
290
|
+
} : {
|
|
291
|
+
type: "finish"
|
|
292
|
+
});
|
|
225
293
|
return out;
|
|
226
294
|
}
|
|
227
295
|
/**
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
296
|
+
* Close any open text/reasoning block WITHOUT finishing the stream. The host calls this before
|
|
297
|
+
* interleaving a framework chunk (HITL approval / checkpoint) that must not appear inside an open text
|
|
298
|
+
* block — mirroring the original translator's `closeOpenBlock` before those chunks. Idempotent.
|
|
299
|
+
*/
|
|
232
300
|
closeBlock() {
|
|
233
301
|
return this.#closeOpenBlock();
|
|
234
302
|
}
|
|
235
303
|
/**
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
304
|
+
* Whether a `callId` has already been introduced (a `tool-call` or a synthesized `tool-input`). The host
|
|
305
|
+
* uses this so a framework `approval_required` reuses the EC-1 synthesize-input-first rule exactly once.
|
|
306
|
+
*/
|
|
239
307
|
hasSeen(callId) {
|
|
240
308
|
return this.#seen.has(callId);
|
|
241
309
|
}
|
|
@@ -247,9 +315,15 @@ var UIMessageStreamPresenter = class {
|
|
|
247
315
|
#closeOpenBlock() {
|
|
248
316
|
const out = [];
|
|
249
317
|
if (this.#openBlock === "text") {
|
|
250
|
-
out.push({
|
|
318
|
+
out.push({
|
|
319
|
+
type: "text-end",
|
|
320
|
+
id: this.#textId
|
|
321
|
+
});
|
|
251
322
|
} else if (this.#openBlock === "reasoning" && this.#reasoningId) {
|
|
252
|
-
out.push({
|
|
323
|
+
out.push({
|
|
324
|
+
type: "reasoning-end",
|
|
325
|
+
id: this.#reasoningId
|
|
326
|
+
});
|
|
253
327
|
}
|
|
254
328
|
this.#openBlock = null;
|
|
255
329
|
this.#reasoningId = null;
|
|
@@ -258,10 +332,17 @@ var UIMessageStreamPresenter = class {
|
|
|
258
332
|
#emitTextDelta(content) {
|
|
259
333
|
const out = [];
|
|
260
334
|
if (this.#openBlock !== "text") {
|
|
261
|
-
out.push(...this.#closeOpenBlock(), {
|
|
335
|
+
out.push(...this.#closeOpenBlock(), {
|
|
336
|
+
type: "text-start",
|
|
337
|
+
id: this.#textId
|
|
338
|
+
});
|
|
262
339
|
this.#openBlock = "text";
|
|
263
340
|
}
|
|
264
|
-
out.push({
|
|
341
|
+
out.push({
|
|
342
|
+
type: "text-delta",
|
|
343
|
+
id: this.#textId,
|
|
344
|
+
delta: content
|
|
345
|
+
});
|
|
265
346
|
return out;
|
|
266
347
|
}
|
|
267
348
|
#emitReasoningDelta(content) {
|
|
@@ -271,16 +352,29 @@ var UIMessageStreamPresenter = class {
|
|
|
271
352
|
out.push(...this.#closeOpenBlock());
|
|
272
353
|
reasoningId = crypto.randomUUID();
|
|
273
354
|
this.#reasoningId = reasoningId;
|
|
274
|
-
out.push({
|
|
355
|
+
out.push({
|
|
356
|
+
type: "reasoning-start",
|
|
357
|
+
id: reasoningId
|
|
358
|
+
});
|
|
275
359
|
this.#openBlock = "reasoning";
|
|
276
360
|
}
|
|
277
|
-
out.push({
|
|
361
|
+
out.push({
|
|
362
|
+
type: "reasoning-delta",
|
|
363
|
+
id: reasoningId,
|
|
364
|
+
delta: content
|
|
365
|
+
});
|
|
278
366
|
return out;
|
|
279
367
|
}
|
|
280
368
|
#emitToolCall(callId, name, input) {
|
|
281
369
|
this.#seen.add(callId);
|
|
282
370
|
return [
|
|
283
|
-
{
|
|
371
|
+
{
|
|
372
|
+
type: "tool-input-available",
|
|
373
|
+
toolCallId: callId,
|
|
374
|
+
toolName: name,
|
|
375
|
+
input,
|
|
376
|
+
dynamic: true
|
|
377
|
+
}
|
|
284
378
|
];
|
|
285
379
|
}
|
|
286
380
|
#emitToolResult(callId, name, result, isError) {
|
|
@@ -297,9 +391,17 @@ var UIMessageStreamPresenter = class {
|
|
|
297
391
|
}
|
|
298
392
|
const output = typeof result === "string" ? result : "";
|
|
299
393
|
if (isError) {
|
|
300
|
-
out.push({
|
|
394
|
+
out.push({
|
|
395
|
+
type: "tool-output-error",
|
|
396
|
+
toolCallId: callId,
|
|
397
|
+
errorText: output
|
|
398
|
+
});
|
|
301
399
|
} else {
|
|
302
|
-
out.push({
|
|
400
|
+
out.push({
|
|
401
|
+
type: "tool-output-available",
|
|
402
|
+
toolCallId: callId,
|
|
403
|
+
output
|
|
404
|
+
});
|
|
303
405
|
}
|
|
304
406
|
return out;
|
|
305
407
|
}
|
|
@@ -309,15 +411,11 @@ var UIMessageStreamPresenter = class {
|
|
|
309
411
|
var ANSI = {
|
|
310
412
|
text: "",
|
|
311
413
|
reasoning: "\x1B[2m",
|
|
312
|
-
// dim
|
|
313
414
|
tool: "\x1B[36m",
|
|
314
|
-
// cyan
|
|
315
415
|
"tool-result": "\x1B[2m",
|
|
316
416
|
"tool-error": "\x1B[31m",
|
|
317
|
-
// red
|
|
318
417
|
error: "\x1B[31m",
|
|
319
418
|
status: "\x1B[35m",
|
|
320
|
-
// magenta
|
|
321
419
|
finish: "\x1B[2m"
|
|
322
420
|
};
|
|
323
421
|
var RESET = "\x1B[0m";
|
|
@@ -326,6 +424,7 @@ function preview(value, max) {
|
|
|
326
424
|
const flat = raw.replace(/\s+/g, " ").trim();
|
|
327
425
|
return flat.length > max ? `${flat.slice(0, max - 1)}\u2026` : flat;
|
|
328
426
|
}
|
|
427
|
+
__name(preview, "preview");
|
|
329
428
|
function safeJson(value) {
|
|
330
429
|
if (value === void 0 || value === null) return "";
|
|
331
430
|
try {
|
|
@@ -334,10 +433,15 @@ function safeJson(value) {
|
|
|
334
433
|
return typeof value === "bigint" ? value.toString() : "";
|
|
335
434
|
}
|
|
336
435
|
}
|
|
436
|
+
__name(safeJson, "safeJson");
|
|
337
437
|
function suffix(open, value, close) {
|
|
338
438
|
return value === void 0 ? "" : open + value + close;
|
|
339
439
|
}
|
|
440
|
+
__name(suffix, "suffix");
|
|
340
441
|
var TerminalPresenter = class {
|
|
442
|
+
static {
|
|
443
|
+
__name(this, "TerminalPresenter");
|
|
444
|
+
}
|
|
341
445
|
surface = "terminal";
|
|
342
446
|
#ansi;
|
|
343
447
|
#max;
|
|
@@ -348,21 +452,33 @@ var TerminalPresenter = class {
|
|
|
348
452
|
present(event) {
|
|
349
453
|
switch (event.type) {
|
|
350
454
|
case "text":
|
|
351
|
-
return event.text.length > 0 ? [
|
|
455
|
+
return event.text.length > 0 ? [
|
|
456
|
+
this.#row("text", event.text)
|
|
457
|
+
] : [];
|
|
352
458
|
case "reasoning":
|
|
353
|
-
return event.text.length > 0 ? [
|
|
459
|
+
return event.text.length > 0 ? [
|
|
460
|
+
this.#row("reasoning", `\xB7 ${event.text}`)
|
|
461
|
+
] : [];
|
|
354
462
|
case "tool-call":
|
|
355
|
-
return [
|
|
463
|
+
return [
|
|
464
|
+
this.#row("tool", `\u23FA ${event.name}(${preview(event.input, this.#max)})`)
|
|
465
|
+
];
|
|
356
466
|
case "tool-result":
|
|
357
|
-
return [
|
|
467
|
+
return [
|
|
468
|
+
this.#toolResult(event.isError === true, preview(event.result, this.#max))
|
|
469
|
+
];
|
|
358
470
|
case "error":
|
|
359
|
-
return [
|
|
471
|
+
return [
|
|
472
|
+
this.#row("error", `\u2716 ${event.message}${suffix(" (", event.code, ")")}`)
|
|
473
|
+
];
|
|
360
474
|
case "status":
|
|
361
475
|
return [
|
|
362
476
|
this.#row("status", `\u25CF ${event.status}${suffix(" \u2014 ", event.detail, "")}`)
|
|
363
477
|
];
|
|
364
478
|
case "finish":
|
|
365
|
-
return [
|
|
479
|
+
return [
|
|
480
|
+
this.#row("finish", this.#finishText(event.reason, event.usage?.totalTokens))
|
|
481
|
+
];
|
|
366
482
|
// `partial-tool-call` streams incremental args — the committed `tool-call` renders them.
|
|
367
483
|
default:
|
|
368
484
|
return [];
|
|
@@ -377,12 +493,18 @@ var TerminalPresenter = class {
|
|
|
377
493
|
return `<<${r}${t} >>`;
|
|
378
494
|
}
|
|
379
495
|
#row(kind, text) {
|
|
380
|
-
return {
|
|
496
|
+
return {
|
|
497
|
+
kind,
|
|
498
|
+
text: this.#ansi && ANSI[kind] !== "" ? `${ANSI[kind]}${text}${RESET}` : text
|
|
499
|
+
};
|
|
381
500
|
}
|
|
382
501
|
};
|
|
383
502
|
|
|
384
503
|
// src/presenters/json.ts
|
|
385
504
|
var JsonPresenter = class {
|
|
505
|
+
static {
|
|
506
|
+
__name(this, "JsonPresenter");
|
|
507
|
+
}
|
|
386
508
|
surface = "json";
|
|
387
509
|
#ns;
|
|
388
510
|
constructor(options = {}) {
|
|
@@ -390,7 +512,12 @@ var JsonPresenter = class {
|
|
|
390
512
|
}
|
|
391
513
|
present(event) {
|
|
392
514
|
const { type, ...payload } = event;
|
|
393
|
-
return [
|
|
515
|
+
return [
|
|
516
|
+
{
|
|
517
|
+
type: `${this.#ns}${type}`,
|
|
518
|
+
...payload
|
|
519
|
+
}
|
|
520
|
+
];
|
|
394
521
|
}
|
|
395
522
|
};
|
|
396
523
|
|
|
@@ -400,19 +527,29 @@ function foldTurnLifecycle(vocabulary, threadId) {
|
|
|
400
527
|
let text = "";
|
|
401
528
|
let failure;
|
|
402
529
|
let nextItem = 0;
|
|
403
|
-
const idOf = (chunk) => chunk.id ?? `item_${nextItem}
|
|
404
|
-
const observe = (chunk) => {
|
|
530
|
+
const idOf = /* @__PURE__ */ __name((chunk) => chunk.id ?? `item_${nextItem}`, "idOf");
|
|
531
|
+
const observe = /* @__PURE__ */ __name((chunk) => {
|
|
405
532
|
if (!open) return [];
|
|
406
533
|
switch (chunk.kind) {
|
|
407
534
|
case "text":
|
|
408
535
|
text += chunk.delta;
|
|
409
536
|
return [];
|
|
410
537
|
case "tool-call":
|
|
411
|
-
return [
|
|
538
|
+
return [
|
|
539
|
+
vocabulary.itemStarted({
|
|
540
|
+
id: idOf(chunk),
|
|
541
|
+
kind: chunk.name
|
|
542
|
+
})
|
|
543
|
+
];
|
|
412
544
|
case "tool-result": {
|
|
413
|
-
const closing = vocabulary.itemCompleted({
|
|
545
|
+
const closing = vocabulary.itemCompleted({
|
|
546
|
+
id: idOf(chunk),
|
|
547
|
+
kind: chunk.name
|
|
548
|
+
});
|
|
414
549
|
nextItem += 1;
|
|
415
|
-
return [
|
|
550
|
+
return [
|
|
551
|
+
closing
|
|
552
|
+
];
|
|
416
553
|
}
|
|
417
554
|
case "error":
|
|
418
555
|
failure ??= chunk.message;
|
|
@@ -420,23 +557,29 @@ function foldTurnLifecycle(vocabulary, threadId) {
|
|
|
420
557
|
default:
|
|
421
558
|
return [];
|
|
422
559
|
}
|
|
423
|
-
};
|
|
424
|
-
const finish = (outcome) => {
|
|
560
|
+
}, "observe");
|
|
561
|
+
const finish = /* @__PURE__ */ __name((outcome) => {
|
|
425
562
|
if (!open) return [];
|
|
426
563
|
open = false;
|
|
427
564
|
const events = [];
|
|
428
565
|
const message = text.trim();
|
|
429
566
|
if (message.length > 0) {
|
|
430
|
-
events.push(vocabulary.itemCompleted({
|
|
567
|
+
events.push(vocabulary.itemCompleted({
|
|
568
|
+
id: "message",
|
|
569
|
+
kind: message
|
|
570
|
+
}));
|
|
431
571
|
}
|
|
432
572
|
const reason = failure ?? (outcome.status === "error" ? outcome.error ?? "turn failed" : void 0);
|
|
433
|
-
events.push(
|
|
434
|
-
|
|
435
|
-
);
|
|
573
|
+
events.push(reason === void 0 ? vocabulary.turnCompleted(outcome.usage) : vocabulary.turnFailed({
|
|
574
|
+
message: reason
|
|
575
|
+
}));
|
|
436
576
|
return events;
|
|
437
|
-
};
|
|
577
|
+
}, "finish");
|
|
438
578
|
return {
|
|
439
|
-
opened: [
|
|
579
|
+
opened: [
|
|
580
|
+
vocabulary.threadStarted(threadId),
|
|
581
|
+
vocabulary.turnStarted()
|
|
582
|
+
],
|
|
440
583
|
get isOpen() {
|
|
441
584
|
return open;
|
|
442
585
|
},
|
|
@@ -444,6 +587,7 @@ function foldTurnLifecycle(vocabulary, threadId) {
|
|
|
444
587
|
finish
|
|
445
588
|
};
|
|
446
589
|
}
|
|
590
|
+
__name(foldTurnLifecycle, "foldTurnLifecycle");
|
|
447
591
|
export {
|
|
448
592
|
AGENT_OUTPUT_EVENT_TYPES,
|
|
449
593
|
JsonPresenter,
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/agent-output-event.ts","../src/presenter.ts","../src/source/from-sdk.ts","../src/presenters/ui-message-stream.ts","../src/presenters/terminal.ts","../src/presenters/json.ts","../src/turn-lifecycle.ts"],"mappings":";AAqFO,IAAM,2BAA2B;AAAA,EACtC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAMO,IAAM,cAAc,CAAC,MAA6C,EAAE,SAAS;AAC7E,IAAM,mBAAmB,CAAC,MAC/B,EAAE,SAAS;AACN,IAAM,kBAAkB,CAAC,MAC9B,EAAE,SAAS;AACN,IAAM,yBAAyB,CAAC,MACrC,EAAE,SAAS;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,MAAM;AACd,eAAO,CAAC;AAAA,MACV,KAAK;AACH,eAAO,CAAC,WAAW,YAAY,EAAE,IAAI,KAAK,KAAK,GAAG,MAAM,MAAM,KAAK,CAAC,CAAC;AAAA,MACvE,KAAK,eAAe;AAClB,cAAM,UAAU,WAAW,cAAc,EAAE,IAAI,KAAK,KAAK,GAAG,MAAM,MAAM,KAAK,CAAC;AAC9E,oBAAY;AACZ,eAAO,CAAC,OAAO;AAAA,MACjB;AAAA,MACA,KAAK;AAGH,oBAAY,MAAM;AAClB,eAAO,CAAC;AAAA,MACV;AAIE,eAAO,CAAC;AAAA,IACZ;AAAA,EACF;AAEA,QAAM,SAAS,CAAC,YAAuC;AACrD,QAAI,CAAC,KAAM,QAAO,CAAC;AACnB,WAAO;AAEP,UAAM,SAAc,CAAC;AACrB,UAAM,UAAU,KAAK,KAAK;AAE1B,QAAI,QAAQ,SAAS,GAAG;AACtB,aAAO,KAAK,WAAW,cAAc,EAAE,IAAI,WAAW,MAAM,QAAQ,CAAC,CAAC;AAAA,IACxE;AAEA,UAAM,SAAS,YAAY,QAAQ,WAAW,UAAW,QAAQ,SAAS,gBAAiB;AAC3F,WAAO;AAAA,MACL,WAAW,SACP,WAAW,cAAc,QAAQ,KAAK,IACtC,WAAW,WAAW,EAAE,SAAS,OAAO,CAAC;AAAA,IAC/C;AACA,WAAO;AAAA,EACT;AAEA,SAAO;AAAA,IACL,QAAQ,CAAC,WAAW,cAAc,QAAQ,GAAG,WAAW,YAAY,CAAC;AAAA,IACrE,IAAI,SAAS;AACX,aAAO;AAAA,IACT;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/agent-output-event.ts","../src/presenter.ts","../src/source/from-sdk.ts","../src/presenters/ui-message-stream.ts","../src/presenters/terminal.ts","../src/presenters/json.ts","../src/turn-lifecycle.ts"],"mappings":";;;;;AAqFO,IAAMA,2BAA2B;EACtC;EACA;EACA;EACA;EACA;EACA;EACA;E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G,MAAMH,MAAMM;QAAK,CAAA;AAC7ER,oBAAY;AACZ,eAAO;UAACS;;MACV;MACA,KAAK;AAGHV,oBAAYG,MAAMS;AAClB,eAAO,CAAA;MACT;AAIE,eAAO,CAAA;IACX;EACF,GA3BgB;AA6BhB,QAAMC,SAAS,wBAACC,YAAAA;AACd,QAAI,CAAChB,KAAM,QAAO,CAAA;AAClBA,WAAO;AAEP,UAAMiB,SAAc,CAAA;AACpB,UAAMH,UAAUb,KAAKiB,KAAI;AAEzB,QAAIJ,QAAQK,SAAS,GAAG;AACtBF,aAAOG,KAAKtB,WAAWe,cAAc;QAAEP,IAAI;QAAWE,MAAMM;MAAQ,CAAA,CAAA;IACtE;AAEA,UAAMO,SACJnB,YAAYc,QAAQM,WAAW,UAAWN,QAAQO,SAAS,gBAAiBC;AAC9EP,WAAOG,KACLC,WAAWG,SACP1B,WAAW2B,cAAcT,QAAQU,KAAK,IACtC5B,WAAW6B,WAAW;MAAEb,SAASO;IAAO,CAAA,CAAA;AAE9C,WAAOJ;EACT,GAnBe;AAqBf,SAAO;IACLW,QAAQ;MAAC9B,WAAW+B,cAAc9B,QAAAA;MAAWD,WAAWgC,YAAW;;IACnE,IAAIC,SAAS;AACX,aAAO/B;IACT;IACAO;IACAQ;EACF;AACF;AA3EgBlB;","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","ANSI","text","reasoning","tool","error","status","finish","RESET","preview","value","max","raw","safeJson","flat","replace","trim","length","slice","undefined","JSON","stringify","toString","suffix","open","close","TerminalPresenter","surface","options","ansi","maxPreview","present","event","type","name","input","isError","result","message","code","detail","reason","usage","totalTokens","body","tokens","r","t","kind","JsonPresenter","surface","options","namespace","present","event","type","payload","foldTurnLifecycle","vocabulary","threadId","open","text","failure","nextItem","idOf","chunk","id","observe","kind","delta","itemStarted","name","closing","itemCompleted","message","finish","outcome","events","trim","length","push","reason","status","error","undefined","turnCompleted","usage","turnFailed","opened","threadStarted","turnStarted","isOpen"]}
|
package/dist/wire/index.js
CHANGED
|
@@ -1,20 +1,45 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__name
|
|
3
|
+
} from "../chunk-Z4QWC7IK.js";
|
|
4
|
+
|
|
1
5
|
// src/wire/chunk-schema.ts
|
|
2
6
|
import { z } from "zod";
|
|
3
7
|
var dataPartSchema = z.object({
|
|
4
|
-
type: z.custom(
|
|
5
|
-
(v) => typeof v === "string" && /^data-[a-z][a-z0-9-]*$/.test(v)
|
|
6
|
-
),
|
|
8
|
+
type: z.custom((v) => typeof v === "string" && /^data-[a-z][a-z0-9-]*$/.test(v)),
|
|
7
9
|
data: z.record(z.string(), z.unknown()),
|
|
8
10
|
transient: z.boolean().optional()
|
|
9
11
|
});
|
|
10
12
|
var fixedChunkSchema = z.discriminatedUnion("type", [
|
|
11
|
-
z.object({
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
z.object({
|
|
16
|
-
|
|
17
|
-
|
|
13
|
+
z.object({
|
|
14
|
+
type: z.literal("start"),
|
|
15
|
+
messageId: z.string().optional()
|
|
16
|
+
}),
|
|
17
|
+
z.object({
|
|
18
|
+
type: z.literal("text-start"),
|
|
19
|
+
id: z.string()
|
|
20
|
+
}),
|
|
21
|
+
z.object({
|
|
22
|
+
type: z.literal("text-delta"),
|
|
23
|
+
id: z.string(),
|
|
24
|
+
delta: z.string()
|
|
25
|
+
}),
|
|
26
|
+
z.object({
|
|
27
|
+
type: z.literal("text-end"),
|
|
28
|
+
id: z.string()
|
|
29
|
+
}),
|
|
30
|
+
z.object({
|
|
31
|
+
type: z.literal("reasoning-start"),
|
|
32
|
+
id: z.string()
|
|
33
|
+
}),
|
|
34
|
+
z.object({
|
|
35
|
+
type: z.literal("reasoning-delta"),
|
|
36
|
+
id: z.string(),
|
|
37
|
+
delta: z.string()
|
|
38
|
+
}),
|
|
39
|
+
z.object({
|
|
40
|
+
type: z.literal("reasoning-end"),
|
|
41
|
+
id: z.string()
|
|
42
|
+
}),
|
|
18
43
|
z.object({
|
|
19
44
|
type: z.literal("tool-input-available"),
|
|
20
45
|
toolCallId: z.string(),
|
|
@@ -41,10 +66,19 @@ var fixedChunkSchema = z.discriminatedUnion("type", [
|
|
|
41
66
|
// `errorText` is optional: a malformed error frame must still be RECOGNISED as an error so the
|
|
42
67
|
// reader can reject. Requiring the field would push it into the discard path and turn a real
|
|
43
68
|
// provider failure into silence — theokit#136 through a side door.
|
|
44
|
-
z.object({
|
|
45
|
-
|
|
69
|
+
z.object({
|
|
70
|
+
type: z.literal("error"),
|
|
71
|
+
errorText: z.string().optional()
|
|
72
|
+
}),
|
|
73
|
+
z.object({
|
|
74
|
+
type: z.literal("finish"),
|
|
75
|
+
messageMetadata: z.unknown().optional()
|
|
76
|
+
})
|
|
77
|
+
]);
|
|
78
|
+
var wireChunkSchema = z.union([
|
|
79
|
+
fixedChunkSchema,
|
|
80
|
+
dataPartSchema
|
|
46
81
|
]);
|
|
47
|
-
var wireChunkSchema = z.union([fixedChunkSchema, dataPartSchema]);
|
|
48
82
|
var WIRE_CHUNK_TYPES = [
|
|
49
83
|
"start",
|
|
50
84
|
"text-start",
|
|
@@ -66,14 +100,21 @@ var WIRE_DATA_PART_PREFIX = "data-";
|
|
|
66
100
|
var DONE_SENTINEL = "[DONE]";
|
|
67
101
|
var DEFAULT_MAX_FRAME_BYTES = 1e6;
|
|
68
102
|
var WireStreamError = class extends Error {
|
|
103
|
+
static {
|
|
104
|
+
__name(this, "WireStreamError");
|
|
105
|
+
}
|
|
69
106
|
name = "WireStreamError";
|
|
70
107
|
};
|
|
71
108
|
var WireFrameTooLargeError = class extends Error {
|
|
109
|
+
static {
|
|
110
|
+
__name(this, "WireFrameTooLargeError");
|
|
111
|
+
}
|
|
72
112
|
name = "WireFrameTooLargeError";
|
|
73
113
|
};
|
|
74
114
|
function normalizeEol(text) {
|
|
75
115
|
return text.replace(/\r\n|\r/g, "\n");
|
|
76
116
|
}
|
|
117
|
+
__name(normalizeEol, "normalizeEol");
|
|
77
118
|
function joinDataLines(event) {
|
|
78
119
|
const out = [];
|
|
79
120
|
for (const line of event.split("\n")) {
|
|
@@ -83,13 +124,14 @@ function joinDataLines(event) {
|
|
|
83
124
|
}
|
|
84
125
|
return out.join("\n");
|
|
85
126
|
}
|
|
127
|
+
__name(joinDataLines, "joinDataLines");
|
|
86
128
|
function parseWireStream(bytes, options = {}) {
|
|
87
129
|
const maxFrameBytes = options.maxFrameBytes ?? DEFAULT_MAX_FRAME_BYTES;
|
|
88
130
|
const warn = options.onWarn ?? (() => void 0);
|
|
89
131
|
const decoder = new TextDecoderStream();
|
|
90
132
|
const reader = bytes.pipeThrough(decoder).getReader();
|
|
91
133
|
let buffer = "";
|
|
92
|
-
const drain = (controller) => {
|
|
134
|
+
const drain = /* @__PURE__ */ __name((controller) => {
|
|
93
135
|
let emitted = 0;
|
|
94
136
|
let cut = buffer.indexOf("\n\n");
|
|
95
137
|
while (cut !== -1) {
|
|
@@ -109,7 +151,9 @@ function parseWireStream(bytes, options = {}) {
|
|
|
109
151
|
const text = raw.errorText;
|
|
110
152
|
controller.enqueue({
|
|
111
153
|
type: "error",
|
|
112
|
-
...typeof text === "string" && text.length > 0 ? {
|
|
154
|
+
...typeof text === "string" && text.length > 0 ? {
|
|
155
|
+
errorText: text
|
|
156
|
+
} : {}
|
|
113
157
|
});
|
|
114
158
|
emitted += 1;
|
|
115
159
|
continue;
|
|
@@ -119,22 +163,20 @@ function parseWireStream(bytes, options = {}) {
|
|
|
119
163
|
controller.enqueue(parsed.data);
|
|
120
164
|
emitted += 1;
|
|
121
165
|
} else {
|
|
122
|
-
warn(
|
|
123
|
-
`wire: unknown or invalid variant discarded (${String(raw.type)})`
|
|
124
|
-
);
|
|
166
|
+
warn(`wire: unknown or invalid variant discarded (${String(raw.type)})`);
|
|
125
167
|
}
|
|
126
168
|
}
|
|
127
169
|
return emitted;
|
|
128
|
-
};
|
|
170
|
+
}, "drain");
|
|
129
171
|
return new ReadableStream({
|
|
130
172
|
/**
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
173
|
+
* Loop until this pull produces at least one chunk or the source ends.
|
|
174
|
+
*
|
|
175
|
+
* A `pull` that returns having enqueued nothing is NOT reliably re-invoked by the controller,
|
|
176
|
+
* so a frame that yields no chunk (the `[DONE]` sentinel, a comment, a discarded variant) would
|
|
177
|
+
* hang the consumer on its next `read()`. Measured: the `[DONE]` test timed out at exactly this
|
|
178
|
+
* point. Looping here makes progress a property of the parser, not of the scheduler.
|
|
179
|
+
*/
|
|
138
180
|
async pull(controller) {
|
|
139
181
|
for (; ; ) {
|
|
140
182
|
const { done, value } = await reader.read();
|
|
@@ -144,9 +186,7 @@ function parseWireStream(bytes, options = {}) {
|
|
|
144
186
|
}
|
|
145
187
|
buffer += normalizeEol(value);
|
|
146
188
|
if (buffer.length > maxFrameBytes) {
|
|
147
|
-
throw new WireFrameTooLargeError(
|
|
148
|
-
`wire: frame exceeded ${maxFrameBytes} bytes with no terminator; aborting instead of accumulating`
|
|
149
|
-
);
|
|
189
|
+
throw new WireFrameTooLargeError(`wire: frame exceeded ${maxFrameBytes} bytes with no terminator; aborting instead of accumulating`);
|
|
150
190
|
}
|
|
151
191
|
if (drain(controller) > 0) return;
|
|
152
192
|
}
|
|
@@ -156,24 +196,30 @@ function parseWireStream(bytes, options = {}) {
|
|
|
156
196
|
}
|
|
157
197
|
});
|
|
158
198
|
}
|
|
199
|
+
__name(parseWireStream, "parseWireStream");
|
|
159
200
|
|
|
160
201
|
// src/wire/read-message-stream.ts
|
|
161
202
|
function snapshot(message) {
|
|
162
203
|
return structuredClone(message);
|
|
163
204
|
}
|
|
205
|
+
__name(snapshot, "snapshot");
|
|
164
206
|
function open(messageId) {
|
|
165
207
|
return {
|
|
166
|
-
message: {
|
|
208
|
+
message: {
|
|
209
|
+
id: messageId ?? "",
|
|
210
|
+
role: "assistant",
|
|
211
|
+
parts: []
|
|
212
|
+
},
|
|
167
213
|
blocks: /* @__PURE__ */ new Map(),
|
|
168
214
|
tools: /* @__PURE__ */ new Map()
|
|
169
215
|
};
|
|
170
216
|
}
|
|
217
|
+
__name(open, "open");
|
|
171
218
|
function raiseStreamError(chunk) {
|
|
172
219
|
const text = chunk.errorText;
|
|
173
|
-
throw new WireStreamError(
|
|
174
|
-
typeof text === "string" && text.length > 0 ? text : "agent stream failed without a message"
|
|
175
|
-
);
|
|
220
|
+
throw new WireStreamError(typeof text === "string" && text.length > 0 ? text : "agent stream failed without a message");
|
|
176
221
|
}
|
|
222
|
+
__name(raiseStreamError, "raiseStreamError");
|
|
177
223
|
async function* readMessageStream(chunks) {
|
|
178
224
|
let state = null;
|
|
179
225
|
for await (const chunk of chunks) {
|
|
@@ -197,6 +243,7 @@ async function* readMessageStream(chunks) {
|
|
|
197
243
|
if (applyChunk(state, chunk)) yield snapshot(state.message);
|
|
198
244
|
}
|
|
199
245
|
}
|
|
246
|
+
__name(readMessageStream, "readMessageStream");
|
|
200
247
|
function applyChunk(state, chunk) {
|
|
201
248
|
const parts = state.message.parts;
|
|
202
249
|
switch (chunk.type) {
|
|
@@ -215,12 +262,17 @@ function applyChunk(state, chunk) {
|
|
|
215
262
|
return applyDataPart(parts, chunk);
|
|
216
263
|
}
|
|
217
264
|
}
|
|
265
|
+
__name(applyChunk, "applyChunk");
|
|
218
266
|
function applyBlock(state, parts, chunk) {
|
|
219
267
|
const id = chunk.id;
|
|
220
268
|
if (chunk.type === "text-start" || chunk.type === "reasoning-start") {
|
|
221
269
|
state.blocks.set(id, parts.length);
|
|
222
270
|
const kind = chunk.type === "text-start" ? "text" : "reasoning";
|
|
223
|
-
parts.push({
|
|
271
|
+
parts.push({
|
|
272
|
+
type: kind,
|
|
273
|
+
text: "",
|
|
274
|
+
state: "streaming"
|
|
275
|
+
});
|
|
224
276
|
return true;
|
|
225
277
|
}
|
|
226
278
|
const at = state.blocks.get(id);
|
|
@@ -233,6 +285,7 @@ function applyBlock(state, parts, chunk) {
|
|
|
233
285
|
part.text = (typeof part.text === "string" ? part.text : "") + chunk.delta;
|
|
234
286
|
return true;
|
|
235
287
|
}
|
|
288
|
+
__name(applyBlock, "applyBlock");
|
|
236
289
|
function applyTool(state, parts, chunk) {
|
|
237
290
|
const c = chunk;
|
|
238
291
|
if (chunk.type === "tool-input-available") {
|
|
@@ -249,19 +302,30 @@ function applyTool(state, parts, chunk) {
|
|
|
249
302
|
const at = state.tools.get(c.toolCallId);
|
|
250
303
|
if (at === void 0) return false;
|
|
251
304
|
if (chunk.type === "tool-output-error") {
|
|
252
|
-
Object.assign(parts[at], {
|
|
305
|
+
Object.assign(parts[at], {
|
|
306
|
+
state: "output-error",
|
|
307
|
+
errorText: c.errorText
|
|
308
|
+
});
|
|
253
309
|
return true;
|
|
254
310
|
}
|
|
255
|
-
Object.assign(parts[at], {
|
|
311
|
+
Object.assign(parts[at], {
|
|
312
|
+
state: "output-available",
|
|
313
|
+
output: c.output
|
|
314
|
+
});
|
|
256
315
|
return true;
|
|
257
316
|
}
|
|
317
|
+
__name(applyTool, "applyTool");
|
|
258
318
|
function applyDataPart(parts, chunk) {
|
|
259
319
|
if (!chunk.type.startsWith("data-")) return false;
|
|
260
320
|
const part = chunk;
|
|
261
321
|
if (part.transient === true) return false;
|
|
262
|
-
parts.push({
|
|
322
|
+
parts.push({
|
|
323
|
+
type: part.type,
|
|
324
|
+
data: part.data
|
|
325
|
+
});
|
|
263
326
|
return true;
|
|
264
327
|
}
|
|
328
|
+
__name(applyDataPart, "applyDataPart");
|
|
265
329
|
export {
|
|
266
330
|
WIRE_CHUNK_TYPES,
|
|
267
331
|
WIRE_DATA_PART_PREFIX,
|
package/dist/wire/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/wire/chunk-schema.ts","../../src/wire/parse-wire-stream.ts","../../src/wire/read-message-stream.ts"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../src/wire/chunk-schema.ts","../../src/wire/parse-wire-stream.ts","../../src/wire/read-message-stream.ts"],"mappings":";;;;;AAAA,SAASA,SAAS;AA6ClB,IAAMC,iBAAiBD,EAAEE,OAAO;EAC9BC,MAAMH,EAAEI,OACN,CAACC,MAAM,OAAOA,MAAM,YAAY,yBAAyBC,KAAKD,CAAAA,CAAAA;EAEhEE,MAAMP,EAAEQ,OAAOR,EAAES,OAAM,GAAIT,EAAEU,QAAO,CAAA;EACpCC,WAAWX,EAAEY,QAAO,EAAGC,SAAQ;AACjC,CAAA;AAEA,IAAMC,mBAAmBd,EAAEe,mBAAmB,QAAQ;EACpDf,EAAEE,OAAO;IAAEC,MAAMH,EAAEgB,QAAQ,OAAA;IAAUC,WAAWjB,EAAES,OAAM,EAAGI,SAAQ;EAAG,CAAA;EAEtEb,EAAEE,OAAO;IAAEC,MAAMH,EAAEgB,QAAQ,YAAA;IAAeE,IAAIlB,EAAES,OAAM;EAAG,CAAA;EACzDT,EAAEE,OAAO;IAAEC,MAAMH,EAAEgB,QAAQ,YAAA;IAAeE,IAAIlB,EAAES,OAAM;IAAIU,OAAOnB,EAAES,OAAM;EAAG,CAAA;EAC5ET,EAAEE,OAAO;IAAEC,MAAMH,EAAEgB,QAAQ,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CmB,WAAOC,OAAOjC,MAAMwB,EAAAA,GAAK;MAAEZ,OAAO;MAAgBL,WAAWqB,EAAErB;IAAU,CAAA;AACzE,WAAO;EACT;AACAyB,SAAOC,OAAOjC,MAAMwB,EAAAA,GAAK;IAAEZ,OAAO;IAAoBsB,QAAQN,EAAEM;EAAO,CAAA;AACvE,SAAO;AACT;AA5BSf;AA2CT,SAASC,cAAcpB,OAAsBK,OAAgB;AAC3D,MAAI,CAACA,MAAMQ,KAAKsB,WAAW,OAAA,EAAU,QAAO;AAC5C,QAAMT,OAAOrB;AACb,MAAIqB,KAAKU,cAAc,KAAM,QAAO;AACpCpC,QAAMuB,KAAK;IAAEV,MAAMa,KAAKb;IAAMwB,MAAMX,KAAKW;EAAK,CAAA;AAC9C,SAAO;AACT;AANSjB;","names":["z","dataPartSchema","object","type","custom","v","test","data","record","string","unknown","transient","boolean","optional","fixedChunkSchema","discriminatedUnion","literal","messageId","id","delta","toolCallId","toolName","input","dynamic","output","errorText","approvalId","messageMetadata","wireChunkSchema","union","WIRE_CHUNK_TYPES","WIRE_DATA_PART_PREFIX","DONE_SENTINEL","DEFAULT_MAX_FRAME_BYTES","WireStreamError","Error","name","WireFrameTooLargeError","normalizeEol","text","replace","joinDataLines","event","out","line","split","startsWith","push","slice","length","join","parseWireStream","bytes","options","maxFrameBytes","warn","onWarn","undefined","decoder","TextDecoderStream","reader","pipeThrough","getReader","buffer","drain","controller","emitted","cut","indexOf","payload","raw","JSON","parse","type","errorText","enqueue","parsed","wireChunkSchema","safeParse","success","data","String","ReadableStream","pull","done","value","read","close","cancel","reason","snapshot","message","structuredClone","open","messageId","id","role","parts","blocks","Map","tools","raiseStreamError","chunk","text","errorText","WireStreamError","length","readMessageStream","chunks","state","type","undefined","metadata","messageMetadata","applyChunk","applyBlock","applyTool","applyDataPart","set","kind","push","at","get","part","delta","c","toolCallId","toolName","input","Object","assign","output","startsWith","transient","data"]}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@theokit/presenter",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "TheoKit's presentation layer
|
|
3
|
+
"version": "0.7.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
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"main": "./dist/index.js",
|
|
@@ -21,18 +21,12 @@
|
|
|
21
21
|
"README.md",
|
|
22
22
|
"LICENSE"
|
|
23
23
|
],
|
|
24
|
-
"scripts": {
|
|
25
|
-
"build": "tsup",
|
|
26
|
-
"test": "vitest run",
|
|
27
|
-
"test:watch": "vitest",
|
|
28
|
-
"typecheck": "tsc --noEmit"
|
|
29
|
-
},
|
|
30
24
|
"peerDependencies": {
|
|
31
|
-
"@theokit/sdk": "^4.
|
|
25
|
+
"@theokit/sdk": "^4.49.0",
|
|
32
26
|
"zod": "^4.0.0"
|
|
33
27
|
},
|
|
34
28
|
"devDependencies": {
|
|
35
|
-
"@theokit/sdk": "^
|
|
29
|
+
"@theokit/sdk": "^4.49.0",
|
|
36
30
|
"ai": "7.0.14",
|
|
37
31
|
"tsup": "^8.5.1",
|
|
38
32
|
"typescript": "^5.9.3",
|
|
@@ -42,5 +36,11 @@
|
|
|
42
36
|
"license": "MIT",
|
|
43
37
|
"engines": {
|
|
44
38
|
"node": ">=22.12.0"
|
|
39
|
+
},
|
|
40
|
+
"scripts": {
|
|
41
|
+
"build": "tsup",
|
|
42
|
+
"test": "vitest run",
|
|
43
|
+
"test:watch": "vitest",
|
|
44
|
+
"typecheck": "tsc --noEmit"
|
|
45
45
|
}
|
|
46
|
-
}
|
|
46
|
+
}
|