@effect-uai/core 0.5.2 → 0.6.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/README.md +1 -1
- package/dist/{Items-BH8xUkoR.d.mts → Items-pXR5BAgW.d.mts} +12 -12
- package/dist/Items-pXR5BAgW.d.mts.map +1 -0
- package/dist/SandboxError-BvKypkJm.d.mts +158 -0
- package/dist/SandboxError-BvKypkJm.d.mts.map +1 -0
- package/dist/{Tool-87ViKCCO.d.mts → Tool-DP-AwKOf.d.mts} +11 -11
- package/dist/{Tool-87ViKCCO.d.mts.map → Tool-DP-AwKOf.d.mts.map} +1 -1
- package/dist/domain/Items.d.mts +2 -2
- package/dist/domain/Items.mjs +15 -15
- package/dist/domain/Items.mjs.map +1 -1
- package/dist/domain/Turn.d.mts +388 -2
- package/dist/domain/Turn.d.mts.map +1 -0
- package/dist/domain/Turn.mjs +13 -13
- package/dist/domain/Turn.mjs.map +1 -1
- package/dist/index.d.mts +11 -6
- package/dist/index.mjs +8 -3
- package/dist/language-model/LanguageModel.d.mts +5 -5
- package/dist/language-model/LanguageModel.d.mts.map +1 -1
- package/dist/language-model/LanguageModel.mjs.map +1 -1
- package/dist/loop/Loop.d.mts +37 -90
- package/dist/loop/Loop.d.mts.map +1 -1
- package/dist/loop/Loop.mjs +39 -93
- package/dist/loop/Loop.mjs.map +1 -1
- package/dist/loop/Loop.test.mjs +46 -54
- package/dist/loop/Loop.test.mjs.map +1 -1
- package/dist/sandbox/Memory.d.mts +53 -0
- package/dist/sandbox/Memory.d.mts.map +1 -0
- package/dist/sandbox/Memory.mjs +68 -0
- package/dist/sandbox/Memory.mjs.map +1 -0
- package/dist/sandbox/Sandbox.d.mts +717 -0
- package/dist/sandbox/Sandbox.d.mts.map +1 -0
- package/dist/sandbox/Sandbox.mjs +192 -0
- package/dist/sandbox/Sandbox.mjs.map +1 -0
- package/dist/sandbox/SandboxError.d.mts +2 -0
- package/dist/sandbox/SandboxError.mjs +89 -0
- package/dist/sandbox/SandboxError.mjs.map +1 -0
- package/dist/sandbox/SandboxImage.d.mts +28 -0
- package/dist/sandbox/SandboxImage.d.mts.map +1 -0
- package/dist/sandbox/SandboxImage.mjs +32 -0
- package/dist/sandbox/SandboxImage.mjs.map +1 -0
- package/dist/sandbox/SandboxNetwork.d.mts +34 -0
- package/dist/sandbox/SandboxNetwork.d.mts.map +1 -0
- package/dist/sandbox/SandboxNetwork.mjs +36 -0
- package/dist/sandbox/SandboxNetwork.mjs.map +1 -0
- package/dist/speech-synthesizer/SpeechSynthesizer.d.mts +98 -2
- package/dist/speech-synthesizer/SpeechSynthesizer.d.mts.map +1 -1
- package/dist/speech-synthesizer/SpeechSynthesizer.mjs +32 -2
- package/dist/speech-synthesizer/SpeechSynthesizer.mjs.map +1 -1
- package/dist/speech-synthesizer/SpeechSynthesizer.test.mjs +56 -2
- package/dist/speech-synthesizer/SpeechSynthesizer.test.mjs.map +1 -1
- package/dist/testing/MockProvider.d.mts +3 -3
- package/dist/testing/MockProvider.d.mts.map +1 -1
- package/dist/testing/MockProvider.mjs.map +1 -1
- package/dist/testing/MockSandbox.d.mts +604 -0
- package/dist/testing/MockSandbox.d.mts.map +1 -0
- package/dist/testing/MockSandbox.mjs +160 -0
- package/dist/testing/MockSandbox.mjs.map +1 -0
- package/dist/testing/MockSpeechSynthesizer.d.mts +26 -11
- package/dist/testing/MockSpeechSynthesizer.d.mts.map +1 -1
- package/dist/testing/MockSpeechSynthesizer.mjs +75 -51
- package/dist/testing/MockSpeechSynthesizer.mjs.map +1 -1
- package/dist/tool/{Resolvers.d.mts → Approval.d.mts} +27 -27
- package/dist/tool/Approval.d.mts.map +1 -0
- package/dist/tool/{Resolvers.mjs → Approval.mjs} +18 -18
- package/dist/tool/Approval.mjs.map +1 -0
- package/dist/tool/{Resolvers.test.mjs → Approval.test.mjs} +40 -40
- package/dist/tool/Approval.test.mjs.map +1 -0
- package/dist/tool/HistoryCheck.d.mts +6 -6
- package/dist/tool/HistoryCheck.d.mts.map +1 -1
- package/dist/tool/HistoryCheck.mjs +5 -5
- package/dist/tool/HistoryCheck.mjs.map +1 -1
- package/dist/tool/Tool.d.mts +2 -2
- package/dist/tool/Tool.mjs +4 -4
- package/dist/tool/Tool.mjs.map +1 -1
- package/dist/tool/ToolEvent.d.mts +19 -19
- package/dist/tool/ToolEvent.d.mts.map +1 -1
- package/dist/tool/ToolEvent.mjs +8 -8
- package/dist/tool/ToolEvent.mjs.map +1 -1
- package/dist/tool/{Outcome.d.mts → ToolResult.d.mts} +29 -29
- package/dist/tool/ToolResult.d.mts.map +1 -0
- package/dist/tool/ToolResult.mjs +61 -0
- package/dist/tool/ToolResult.mjs.map +1 -0
- package/dist/tool/Toolkit.d.mts +58 -26
- package/dist/tool/Toolkit.d.mts.map +1 -1
- package/dist/tool/Toolkit.mjs +62 -34
- package/dist/tool/Toolkit.mjs.map +1 -1
- package/dist/tool/Toolkit.test.mjs +13 -13
- package/dist/tool/Toolkit.test.mjs.map +1 -1
- package/package.json +31 -7
- package/src/domain/Items.ts +9 -9
- package/src/domain/Turn.ts +16 -16
- package/src/index.ts +7 -2
- package/src/language-model/LanguageModel.ts +3 -3
- package/src/loop/Loop.test.ts +93 -91
- package/src/loop/Loop.ts +72 -170
- package/src/sandbox/Memory.ts +128 -0
- package/src/sandbox/Sandbox.ts +639 -0
- package/src/sandbox/SandboxError.ts +140 -0
- package/src/sandbox/SandboxImage.ts +26 -0
- package/src/sandbox/SandboxNetwork.ts +34 -0
- package/src/speech-synthesizer/SpeechSynthesizer.test.ts +89 -0
- package/src/speech-synthesizer/SpeechSynthesizer.ts +124 -0
- package/src/testing/MockProvider.ts +21 -20
- package/src/testing/MockSandbox.ts +342 -0
- package/src/testing/MockSpeechSynthesizer.ts +137 -77
- package/src/tool/{Resolvers.test.ts → Approval.test.ts} +45 -54
- package/src/tool/{Resolvers.ts → Approval.ts} +25 -25
- package/src/tool/HistoryCheck.ts +10 -13
- package/src/tool/Tool.ts +13 -15
- package/src/tool/ToolEvent.ts +7 -7
- package/src/tool/{Outcome.ts → ToolResult.ts} +20 -20
- package/src/tool/Toolkit.test.ts +13 -13
- package/src/tool/Toolkit.ts +97 -73
- package/dist/Items-BH8xUkoR.d.mts.map +0 -1
- package/dist/Turn-0CwCAyVe.d.mts +0 -388
- package/dist/Turn-0CwCAyVe.d.mts.map +0 -1
- package/dist/tool/Outcome.d.mts.map +0 -1
- package/dist/tool/Outcome.mjs +0 -61
- package/dist/tool/Outcome.mjs.map +0 -1
- package/dist/tool/Resolvers.d.mts.map +0 -1
- package/dist/tool/Resolvers.mjs.map +0 -1
- package/dist/tool/Resolvers.test.mjs.map +0 -1
- /package/dist/tool/{Resolvers.test.d.mts → Approval.test.d.mts} +0 -0
package/dist/domain/Turn.d.mts
CHANGED
|
@@ -1,2 +1,388 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { i as ImageSource } from "../Image-HNmMpMTh.mjs";
|
|
2
|
+
import { d as Message, m as Reasoning, o as HistoryItem, v as ToolCall, x as Usage, y as ToolCallOutput } from "../Items-pXR5BAgW.mjs";
|
|
3
|
+
import { i as StructuredFormat, n as JsonParseError, r as StructuredDecodeError } from "../StructuredFormat-BbN4dosH.mjs";
|
|
4
|
+
import { Data, Effect, Schema, Stream } from "effect";
|
|
5
|
+
import * as _$effect_Types0 from "effect/Types";
|
|
6
|
+
import * as _$effect_Cause0 from "effect/Cause";
|
|
7
|
+
import * as _$effect_Unify0 from "effect/Unify";
|
|
8
|
+
|
|
9
|
+
//#region src/domain/Turn.d.ts
|
|
10
|
+
declare namespace Turn_d_exports {
|
|
11
|
+
export { InteractionEvent, RefusalRejected, Turn, TurnEvent, appendToHistory, assistantMessages, assistantText, assistantTexts, decodeStructured, getToolCalls, isTurnComplete, reasonings, textDeltas };
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* The result of a single LLM generation. A turn produces zero or more items
|
|
15
|
+
* (typically one assistant message and zero or more function_call items)
|
|
16
|
+
* and reports usage + a stop reason.
|
|
17
|
+
*/
|
|
18
|
+
declare const Turn: Schema.Struct<{
|
|
19
|
+
readonly items: Schema.$Array<Schema.Union<readonly [Schema.Struct<{
|
|
20
|
+
readonly type: Schema.Literal<"message">;
|
|
21
|
+
readonly role: Schema.Literals<readonly ["user", "assistant", "system"]>;
|
|
22
|
+
readonly content: Schema.$Array<Schema.Union<readonly [Schema.Struct<{
|
|
23
|
+
readonly type: Schema.Literal<"input_text">;
|
|
24
|
+
readonly text: Schema.String;
|
|
25
|
+
}>, Schema.Struct<{
|
|
26
|
+
readonly type: Schema.Literal<"input_image">;
|
|
27
|
+
readonly source: Schema.Schema<ImageSource>;
|
|
28
|
+
}>, Schema.Struct<{
|
|
29
|
+
readonly type: Schema.Literal<"output_text">;
|
|
30
|
+
readonly text: Schema.String;
|
|
31
|
+
readonly annotations: Schema.optional<Schema.$Array<Schema.Union<readonly [Schema.Struct<{
|
|
32
|
+
readonly type: Schema.Literal<"url_citation">;
|
|
33
|
+
readonly url: Schema.String;
|
|
34
|
+
readonly start_index: Schema.Number;
|
|
35
|
+
readonly end_index: Schema.Number;
|
|
36
|
+
readonly title: Schema.String;
|
|
37
|
+
}>, Schema.Struct<{
|
|
38
|
+
readonly type: Schema.Literal<"file_citation">;
|
|
39
|
+
readonly file_id: Schema.String;
|
|
40
|
+
readonly index: Schema.Number;
|
|
41
|
+
}>, Schema.Struct<{
|
|
42
|
+
readonly type: Schema.Literal<"container_file_citation">;
|
|
43
|
+
readonly container_id: Schema.String;
|
|
44
|
+
readonly file_id: Schema.String;
|
|
45
|
+
readonly start_index: Schema.Number;
|
|
46
|
+
readonly end_index: Schema.Number;
|
|
47
|
+
}>, Schema.Struct<{
|
|
48
|
+
readonly type: Schema.Literal<"file_path">;
|
|
49
|
+
readonly file_id: Schema.String;
|
|
50
|
+
readonly index: Schema.Number;
|
|
51
|
+
}>]>>>;
|
|
52
|
+
}>, Schema.Struct<{
|
|
53
|
+
readonly type: Schema.Literal<"refusal">;
|
|
54
|
+
readonly text: Schema.String;
|
|
55
|
+
}>]>>;
|
|
56
|
+
readonly providerData: Schema.optional<Schema.Unknown>;
|
|
57
|
+
}>, Schema.Struct<{
|
|
58
|
+
readonly type: Schema.Literal<"function_call">;
|
|
59
|
+
readonly call_id: Schema.String;
|
|
60
|
+
readonly name: Schema.String;
|
|
61
|
+
readonly arguments: Schema.String;
|
|
62
|
+
readonly providerData: Schema.optional<Schema.Unknown>;
|
|
63
|
+
}>, Schema.Struct<{
|
|
64
|
+
readonly type: Schema.Literal<"function_call_output">;
|
|
65
|
+
readonly call_id: Schema.String;
|
|
66
|
+
readonly output: Schema.String;
|
|
67
|
+
readonly providerData: Schema.optional<Schema.Unknown>;
|
|
68
|
+
}>, Schema.Struct<{
|
|
69
|
+
readonly type: Schema.Literal<"reasoning">;
|
|
70
|
+
readonly id: Schema.optional<Schema.String>;
|
|
71
|
+
readonly summary: Schema.optional<Schema.String>;
|
|
72
|
+
readonly signature: Schema.optional<Schema.String>;
|
|
73
|
+
readonly providerData: Schema.optional<Schema.Unknown>;
|
|
74
|
+
}>]>>;
|
|
75
|
+
readonly usage: Schema.Struct<{
|
|
76
|
+
readonly input_tokens: Schema.optional<Schema.Number>;
|
|
77
|
+
readonly output_tokens: Schema.optional<Schema.Number>;
|
|
78
|
+
readonly total_tokens: Schema.optional<Schema.Number>;
|
|
79
|
+
readonly input_tokens_details: Schema.optional<Schema.Struct<{
|
|
80
|
+
readonly cached_tokens: Schema.optional<Schema.Number>;
|
|
81
|
+
}>>;
|
|
82
|
+
readonly output_tokens_details: Schema.optional<Schema.Struct<{
|
|
83
|
+
readonly reasoning_tokens: Schema.optional<Schema.Number>;
|
|
84
|
+
}>>;
|
|
85
|
+
}>;
|
|
86
|
+
readonly stop_reason: Schema.Literals<readonly ["stop", "tool_calls", "max_tokens", "refusal", "content_filter", "max_tool_calls"]>;
|
|
87
|
+
}>;
|
|
88
|
+
type Turn = typeof Turn.Type;
|
|
89
|
+
/**
|
|
90
|
+
* Canonical events emitted while a single turn is being generated. Most
|
|
91
|
+
* variants are streaming deltas (text, reasoning, tool-call args); the
|
|
92
|
+
* terminal `TurnComplete` carries the assembled `Turn`. Lifecycle members
|
|
93
|
+
* aren't deltas, hence the union name.
|
|
94
|
+
*
|
|
95
|
+
* `ReasoningDelta.kind`: `trace` is the model's raw chain-of-thought;
|
|
96
|
+
* `summary` is a model-written summary intended for display. OpenAI
|
|
97
|
+
* Responses emits both; Anthropic and Gemini only emit `trace`.
|
|
98
|
+
*
|
|
99
|
+
* `RefusalDelta`: the model declined to answer. OpenAI Responses emits
|
|
100
|
+
* this as its own event; Anthropic surfaces refusals via `stop_reason`
|
|
101
|
+
* and Gemini collapses them into `finishReason: SAFETY` — both go
|
|
102
|
+
* without a `RefusalDelta`.
|
|
103
|
+
*
|
|
104
|
+
* `UsageUpdate`: mid-stream cumulative usage. Anthropic emits this on
|
|
105
|
+
* `message_start` and `message_delta`; other providers may only deliver
|
|
106
|
+
* usage via `TurnComplete.turn.usage`.
|
|
107
|
+
*/
|
|
108
|
+
type TurnEvent = Data.TaggedEnum<{
|
|
109
|
+
TextDelta: {
|
|
110
|
+
readonly text: string;
|
|
111
|
+
};
|
|
112
|
+
ReasoningDelta: {
|
|
113
|
+
readonly text: string;
|
|
114
|
+
readonly kind: "trace" | "summary";
|
|
115
|
+
};
|
|
116
|
+
RefusalDelta: {
|
|
117
|
+
readonly text: string;
|
|
118
|
+
};
|
|
119
|
+
ToolCallStart: {
|
|
120
|
+
readonly call_id: string;
|
|
121
|
+
readonly name: string;
|
|
122
|
+
};
|
|
123
|
+
ToolCallArgsDelta: {
|
|
124
|
+
readonly call_id: string;
|
|
125
|
+
readonly delta: string;
|
|
126
|
+
};
|
|
127
|
+
UsageUpdate: {
|
|
128
|
+
readonly usage: Usage;
|
|
129
|
+
};
|
|
130
|
+
TurnComplete: {
|
|
131
|
+
readonly turn: Turn;
|
|
132
|
+
};
|
|
133
|
+
}>;
|
|
134
|
+
declare const TurnEvent: {
|
|
135
|
+
readonly TextDelta: Data.TaggedEnum.ConstructorFrom<{
|
|
136
|
+
readonly _tag: "TextDelta";
|
|
137
|
+
readonly text: string;
|
|
138
|
+
}, "_tag">;
|
|
139
|
+
readonly ReasoningDelta: Data.TaggedEnum.ConstructorFrom<{
|
|
140
|
+
readonly _tag: "ReasoningDelta";
|
|
141
|
+
readonly text: string;
|
|
142
|
+
readonly kind: "trace" | "summary";
|
|
143
|
+
}, "_tag">;
|
|
144
|
+
readonly RefusalDelta: Data.TaggedEnum.ConstructorFrom<{
|
|
145
|
+
readonly _tag: "RefusalDelta";
|
|
146
|
+
readonly text: string;
|
|
147
|
+
}, "_tag">;
|
|
148
|
+
readonly ToolCallStart: Data.TaggedEnum.ConstructorFrom<{
|
|
149
|
+
readonly _tag: "ToolCallStart";
|
|
150
|
+
readonly call_id: string;
|
|
151
|
+
readonly name: string;
|
|
152
|
+
}, "_tag">;
|
|
153
|
+
readonly ToolCallArgsDelta: Data.TaggedEnum.ConstructorFrom<{
|
|
154
|
+
readonly _tag: "ToolCallArgsDelta";
|
|
155
|
+
readonly call_id: string;
|
|
156
|
+
readonly delta: string;
|
|
157
|
+
}, "_tag">;
|
|
158
|
+
readonly UsageUpdate: Data.TaggedEnum.ConstructorFrom<{
|
|
159
|
+
readonly _tag: "UsageUpdate";
|
|
160
|
+
readonly usage: Usage;
|
|
161
|
+
}, "_tag">;
|
|
162
|
+
readonly TurnComplete: Data.TaggedEnum.ConstructorFrom<{
|
|
163
|
+
readonly _tag: "TurnComplete";
|
|
164
|
+
readonly turn: Turn;
|
|
165
|
+
}, "_tag">;
|
|
166
|
+
readonly $is: <Tag extends "TextDelta" | "ReasoningDelta" | "RefusalDelta" | "ToolCallStart" | "ToolCallArgsDelta" | "UsageUpdate" | "TurnComplete">(tag: Tag) => (u: unknown) => u is Extract<{
|
|
167
|
+
readonly _tag: "TextDelta";
|
|
168
|
+
readonly text: string;
|
|
169
|
+
}, {
|
|
170
|
+
readonly _tag: Tag;
|
|
171
|
+
}> | Extract<{
|
|
172
|
+
readonly _tag: "ReasoningDelta";
|
|
173
|
+
readonly text: string;
|
|
174
|
+
readonly kind: "trace" | "summary";
|
|
175
|
+
}, {
|
|
176
|
+
readonly _tag: Tag;
|
|
177
|
+
}> | Extract<{
|
|
178
|
+
readonly _tag: "RefusalDelta";
|
|
179
|
+
readonly text: string;
|
|
180
|
+
}, {
|
|
181
|
+
readonly _tag: Tag;
|
|
182
|
+
}> | Extract<{
|
|
183
|
+
readonly _tag: "ToolCallStart";
|
|
184
|
+
readonly call_id: string;
|
|
185
|
+
readonly name: string;
|
|
186
|
+
}, {
|
|
187
|
+
readonly _tag: Tag;
|
|
188
|
+
}> | Extract<{
|
|
189
|
+
readonly _tag: "ToolCallArgsDelta";
|
|
190
|
+
readonly call_id: string;
|
|
191
|
+
readonly delta: string;
|
|
192
|
+
}, {
|
|
193
|
+
readonly _tag: Tag;
|
|
194
|
+
}> | Extract<{
|
|
195
|
+
readonly _tag: "UsageUpdate";
|
|
196
|
+
readonly usage: Usage;
|
|
197
|
+
}, {
|
|
198
|
+
readonly _tag: Tag;
|
|
199
|
+
}> | Extract<{
|
|
200
|
+
readonly _tag: "TurnComplete";
|
|
201
|
+
readonly turn: Turn;
|
|
202
|
+
}, {
|
|
203
|
+
readonly _tag: Tag;
|
|
204
|
+
}>;
|
|
205
|
+
readonly $match: {
|
|
206
|
+
<Cases extends {
|
|
207
|
+
readonly TextDelta: (args: {
|
|
208
|
+
readonly _tag: "TextDelta";
|
|
209
|
+
readonly text: string;
|
|
210
|
+
}) => any;
|
|
211
|
+
readonly ReasoningDelta: (args: {
|
|
212
|
+
readonly _tag: "ReasoningDelta";
|
|
213
|
+
readonly text: string;
|
|
214
|
+
readonly kind: "trace" | "summary";
|
|
215
|
+
}) => any;
|
|
216
|
+
readonly RefusalDelta: (args: {
|
|
217
|
+
readonly _tag: "RefusalDelta";
|
|
218
|
+
readonly text: string;
|
|
219
|
+
}) => any;
|
|
220
|
+
readonly ToolCallStart: (args: {
|
|
221
|
+
readonly _tag: "ToolCallStart";
|
|
222
|
+
readonly call_id: string;
|
|
223
|
+
readonly name: string;
|
|
224
|
+
}) => any;
|
|
225
|
+
readonly ToolCallArgsDelta: (args: {
|
|
226
|
+
readonly _tag: "ToolCallArgsDelta";
|
|
227
|
+
readonly call_id: string;
|
|
228
|
+
readonly delta: string;
|
|
229
|
+
}) => any;
|
|
230
|
+
readonly UsageUpdate: (args: {
|
|
231
|
+
readonly _tag: "UsageUpdate";
|
|
232
|
+
readonly usage: Usage;
|
|
233
|
+
}) => any;
|
|
234
|
+
readonly TurnComplete: (args: {
|
|
235
|
+
readonly _tag: "TurnComplete";
|
|
236
|
+
readonly turn: Turn;
|
|
237
|
+
}) => any;
|
|
238
|
+
}>(cases: Cases): (value: {
|
|
239
|
+
readonly _tag: "TextDelta";
|
|
240
|
+
readonly text: string;
|
|
241
|
+
} | {
|
|
242
|
+
readonly _tag: "ReasoningDelta";
|
|
243
|
+
readonly text: string;
|
|
244
|
+
readonly kind: "trace" | "summary";
|
|
245
|
+
} | {
|
|
246
|
+
readonly _tag: "RefusalDelta";
|
|
247
|
+
readonly text: string;
|
|
248
|
+
} | {
|
|
249
|
+
readonly _tag: "ToolCallStart";
|
|
250
|
+
readonly call_id: string;
|
|
251
|
+
readonly name: string;
|
|
252
|
+
} | {
|
|
253
|
+
readonly _tag: "ToolCallArgsDelta";
|
|
254
|
+
readonly call_id: string;
|
|
255
|
+
readonly delta: string;
|
|
256
|
+
} | {
|
|
257
|
+
readonly _tag: "UsageUpdate";
|
|
258
|
+
readonly usage: Usage;
|
|
259
|
+
} | {
|
|
260
|
+
readonly _tag: "TurnComplete";
|
|
261
|
+
readonly turn: Turn;
|
|
262
|
+
}) => _$effect_Unify0.Unify<ReturnType<Cases["TextDelta" | "ReasoningDelta" | "RefusalDelta" | "ToolCallStart" | "ToolCallArgsDelta" | "UsageUpdate" | "TurnComplete"]>>;
|
|
263
|
+
<Cases extends {
|
|
264
|
+
readonly TextDelta: (args: {
|
|
265
|
+
readonly _tag: "TextDelta";
|
|
266
|
+
readonly text: string;
|
|
267
|
+
}) => any;
|
|
268
|
+
readonly ReasoningDelta: (args: {
|
|
269
|
+
readonly _tag: "ReasoningDelta";
|
|
270
|
+
readonly text: string;
|
|
271
|
+
readonly kind: "trace" | "summary";
|
|
272
|
+
}) => any;
|
|
273
|
+
readonly RefusalDelta: (args: {
|
|
274
|
+
readonly _tag: "RefusalDelta";
|
|
275
|
+
readonly text: string;
|
|
276
|
+
}) => any;
|
|
277
|
+
readonly ToolCallStart: (args: {
|
|
278
|
+
readonly _tag: "ToolCallStart";
|
|
279
|
+
readonly call_id: string;
|
|
280
|
+
readonly name: string;
|
|
281
|
+
}) => any;
|
|
282
|
+
readonly ToolCallArgsDelta: (args: {
|
|
283
|
+
readonly _tag: "ToolCallArgsDelta";
|
|
284
|
+
readonly call_id: string;
|
|
285
|
+
readonly delta: string;
|
|
286
|
+
}) => any;
|
|
287
|
+
readonly UsageUpdate: (args: {
|
|
288
|
+
readonly _tag: "UsageUpdate";
|
|
289
|
+
readonly usage: Usage;
|
|
290
|
+
}) => any;
|
|
291
|
+
readonly TurnComplete: (args: {
|
|
292
|
+
readonly _tag: "TurnComplete";
|
|
293
|
+
readonly turn: Turn;
|
|
294
|
+
}) => any;
|
|
295
|
+
}>(value: {
|
|
296
|
+
readonly _tag: "TextDelta";
|
|
297
|
+
readonly text: string;
|
|
298
|
+
} | {
|
|
299
|
+
readonly _tag: "ReasoningDelta";
|
|
300
|
+
readonly text: string;
|
|
301
|
+
readonly kind: "trace" | "summary";
|
|
302
|
+
} | {
|
|
303
|
+
readonly _tag: "RefusalDelta";
|
|
304
|
+
readonly text: string;
|
|
305
|
+
} | {
|
|
306
|
+
readonly _tag: "ToolCallStart";
|
|
307
|
+
readonly call_id: string;
|
|
308
|
+
readonly name: string;
|
|
309
|
+
} | {
|
|
310
|
+
readonly _tag: "ToolCallArgsDelta";
|
|
311
|
+
readonly call_id: string;
|
|
312
|
+
readonly delta: string;
|
|
313
|
+
} | {
|
|
314
|
+
readonly _tag: "UsageUpdate";
|
|
315
|
+
readonly usage: Usage;
|
|
316
|
+
} | {
|
|
317
|
+
readonly _tag: "TurnComplete";
|
|
318
|
+
readonly turn: Turn;
|
|
319
|
+
}, cases: Cases): _$effect_Unify0.Unify<ReturnType<Cases["TextDelta" | "ReasoningDelta" | "RefusalDelta" | "ToolCallStart" | "ToolCallArgsDelta" | "UsageUpdate" | "TurnComplete"]>>;
|
|
320
|
+
};
|
|
321
|
+
};
|
|
322
|
+
/**
|
|
323
|
+
* What flows out of an agent loop body to its consumer per turn: every
|
|
324
|
+
* `TurnEvent` the provider emits (including the terminal `TurnComplete`
|
|
325
|
+
* carrying the assembled `Turn`), plus the output of any tool the loop ran.
|
|
326
|
+
* Both variants carry a `_tag` discriminator.
|
|
327
|
+
*/
|
|
328
|
+
type InteractionEvent = TurnEvent | ToolCallOutput;
|
|
329
|
+
declare const isTurnComplete: (u: unknown) => u is {
|
|
330
|
+
readonly _tag: "TurnComplete";
|
|
331
|
+
readonly turn: Turn;
|
|
332
|
+
};
|
|
333
|
+
declare const getToolCalls: (turn: Turn) => ReadonlyArray<ToolCall>;
|
|
334
|
+
declare const reasonings: (turn: Turn) => ReadonlyArray<Reasoning>;
|
|
335
|
+
declare const assistantMessages: (turn: Turn) => ReadonlyArray<Message>;
|
|
336
|
+
/**
|
|
337
|
+
* Every `output_text` payload across every assistant message in the turn,
|
|
338
|
+
* preserving order. Refusals and other content blocks are dropped — use
|
|
339
|
+
* `assistantMessages` if you need to inspect them. The primitive for
|
|
340
|
+
* "give me the assistant's text"; callers decide how to combine
|
|
341
|
+
* (typically `.join("")` for prose or `.join(" ")` for log strings).
|
|
342
|
+
*/
|
|
343
|
+
declare const assistantTexts: (turn: Turn) => ReadonlyArray<string>;
|
|
344
|
+
/**
|
|
345
|
+
* Sugar over `assistantTexts(turn).join("")` — the common case for
|
|
346
|
+
* summarizers, classifiers, judge calls, and structured-output backstops
|
|
347
|
+
* that want one concatenated string.
|
|
348
|
+
*/
|
|
349
|
+
declare const assistantText: (turn: Turn) => string;
|
|
350
|
+
/**
|
|
351
|
+
* Append a completed turn and optional follow-up items to a state record's
|
|
352
|
+
* history. Recipes use this at the point where structured tool results are
|
|
353
|
+
* converted to model-facing `ToolCallOutput`s.
|
|
354
|
+
*/
|
|
355
|
+
declare const appendToHistory: <S extends {
|
|
356
|
+
readonly history: ReadonlyArray<HistoryItem>;
|
|
357
|
+
}>(state: S, turn: Turn, items?: ReadonlyArray<HistoryItem>) => S;
|
|
358
|
+
/**
|
|
359
|
+
* Project a `TurnEvent` stream onto its `TextDelta` payloads. Other
|
|
360
|
+
* variants are dropped. Composes with `Lines.lines` +
|
|
361
|
+
* `decodeJsonLines` for prompted-JSONL streaming.
|
|
362
|
+
*/
|
|
363
|
+
declare const textDeltas: <E, R>(self: Stream.Stream<TurnEvent, E, R>) => Stream.Stream<string, E, R>;
|
|
364
|
+
declare const RefusalRejected_base: new <A extends Record<string, any> = {}>(args: _$effect_Types0.VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P] }>) => _$effect_Cause0.YieldableError & {
|
|
365
|
+
readonly _tag: "RefusalRejected";
|
|
366
|
+
} & Readonly<A>;
|
|
367
|
+
/**
|
|
368
|
+
* The assistant message on the just-completed turn was a refusal block,
|
|
369
|
+
* not an `output_text` payload. Returned by `decodeStructured` to short-circuit
|
|
370
|
+
* decoding before `JSON.parse` / schema validation runs.
|
|
371
|
+
*/
|
|
372
|
+
declare class RefusalRejected extends RefusalRejected_base<{
|
|
373
|
+
readonly turn: Turn;
|
|
374
|
+
}> {}
|
|
375
|
+
/**
|
|
376
|
+
* Validate a completed `Turn` against a `StructuredFormat`. Concatenates
|
|
377
|
+
* `output_text` blocks on the last assistant message, then runs
|
|
378
|
+
* `JSON.parse` + the format's schema validation.
|
|
379
|
+
*
|
|
380
|
+
* Three failure modes:
|
|
381
|
+
* - `RefusalRejected` — the assistant emitted a refusal block.
|
|
382
|
+
* - `JsonParseError` — the assembled text wasn't valid JSON.
|
|
383
|
+
* - `StructuredDecodeError` — the JSON didn't match the schema.
|
|
384
|
+
*/
|
|
385
|
+
declare const decodeStructured: <A>(turn: Turn, format: StructuredFormat<A>) => Effect.Effect<A, RefusalRejected | JsonParseError | StructuredDecodeError>;
|
|
386
|
+
//#endregion
|
|
387
|
+
export { InteractionEvent, RefusalRejected, Turn, TurnEvent, appendToHistory, assistantMessages, assistantText, assistantTexts, decodeStructured, getToolCalls, isTurnComplete, reasonings, Turn_d_exports as t, textDeltas };
|
|
388
|
+
//# sourceMappingURL=Turn.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Turn.d.mts","names":[],"sources":["../../src/domain/Turn.ts"],"mappings":";;;;;;;;;;;;;;;;;cAqBa,IAAA,EAAI,MAAA,CAAA,MAAA;EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAKL,IAAA,UAAc,IAAA,CAAK,IAAA;;;;;;;;;;;;;;;;;;;;KAqBnB,SAAA,GAAY,IAAA,CAAK,UAAA;EAC3B,SAAA;IAAA,SAAsB,IAAA;EAAA;EACtB,cAAA;IAAA,SAA2B,IAAA;IAAA,SAAuB,IAAA;EAAA;EAClD,YAAA;IAAA,SAAyB,IAAA;EAAA;EACzB,aAAA;IAAA,SAA0B,OAAA;IAAA,SAA0B,IAAA;EAAA;EACpD,iBAAA;IAAA,SAA8B,OAAA;IAAA,SAA0B,KAAA;EAAA;EACxD,WAAA;IAAA,SAAwB,KAAA,EAAO,KAAA;EAAA;EAC/B,YAAA;IAAA,SAAyB,IAAA,EAAM,IAAA;EAAA;AAAA;AAAA,cAGpB,SAAA;EAAA;;;;;;;;;;;;;;;;;;;;;;;;;oBAJoB,KAAA;EAAA;EAAA;;mBACA,IAAA;EAAA;EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;oBADA,KAAA;EAAA;IAAA;;;mBACA,IAAA;EAAA;IAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBADA,KAAA;MAAA;MAAA;;uBACA,IAAA;MAAA;IAAA;;;;;;;;;;;;;;;;;;;;sBADA,KAAA;IAAA;MAAA;qBACA,IAAA;IAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;wBADA,KAAA;MAAA;MAAA;;uBACA,IAAA;MAAA;IAAA;;;;;;;;;;;;;;;;;;;;sBADA,KAAA;IAAA;MAAA;qBACA,IAAA;IAAA;;;;;;;;;KAWrB,gBAAA,GAAmB,SAAA,GAAY,cAAA;AAAA,cAE9B,cAAA,GAAc,CAAA,cAAA,CAAA;EAAA;iBAbM,IAAA;AAAA;AAAA,cAepB,YAAA,GAAgB,IAAA,EAAM,IAAA,KAAO,aAAA,CAAc,QAAA;AAAA,cAE3C,UAAA,GAAc,IAAA,EAAM,IAAA,KAAO,aAAA,CAAc,SAAA;AAAA,cAEzC,iBAAA,GAAqB,IAAA,EAAM,IAAA,KAAO,aAAA,CAAc,OAAA;;;;;;;;cAUhD,cAAA,GAAkB,IAAA,EAAM,IAAA,KAAO,aAAA;;;;;;cAW/B,aAAA,GAAiB,IAAA,EAAM,IAAA;;;;;AA/CpC;cAsDa,eAAA;EAAA,SAAwC,OAAA,EAAS,aAAA,CAAc,WAAA;AAAA,GAC1E,KAAA,EAAO,CAAA,EACP,IAAA,EAAM,IAAA,EACN,KAAA,GAAO,aAAA,CAAc,WAAA,MACpB,CAAA;;;;;;cAcU,UAAA,SACX,IAAA,EAAM,MAAA,CAAO,MAAA,CAAO,SAAA,EAAW,CAAA,EAAG,CAAA,MACjC,MAAA,CAAO,MAAA,SAAe,CAAA,EAAG,CAAA;AAAA,cAGzB,oBAAA;;;;;;;;cAWU,eAAA,SAAwB,oBAAA;EAAA,SAC1B,IAAA,EAAM,IAAA;AAAA;;;;;;;;;;AA/EjB;cAwGa,gBAAA,MACX,IAAA,EAAM,IAAA,EACN,MAAA,EAAQ,gBAAA,CAAkC,CAAA,MACzC,MAAA,CAAO,MAAA,CACR,CAAA,EACA,eAAA,GAAkB,cAAA,GAAkC,qBAAA"}
|
package/dist/domain/Turn.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { n as __exportAll } from "../chunk-uyGKjUfl.mjs";
|
|
2
|
-
import {
|
|
2
|
+
import { HistoryItem, StopReason, Usage, isOutputText, isReasoning, isRefusal, isToolCall } from "./Items.mjs";
|
|
3
3
|
import { parseJson } from "../structured-format/StructuredFormat.mjs";
|
|
4
4
|
import { Data, Effect, Result, Schema, Stream, pipe } from "effect";
|
|
5
5
|
//#region src/domain/Turn.ts
|
|
@@ -7,15 +7,15 @@ var Turn_exports = /* @__PURE__ */ __exportAll({
|
|
|
7
7
|
RefusalRejected: () => RefusalRejected,
|
|
8
8
|
Turn: () => Turn,
|
|
9
9
|
TurnEvent: () => TurnEvent,
|
|
10
|
-
|
|
10
|
+
appendToHistory: () => appendToHistory,
|
|
11
11
|
assistantMessages: () => assistantMessages,
|
|
12
12
|
assistantText: () => assistantText,
|
|
13
13
|
assistantTexts: () => assistantTexts,
|
|
14
|
-
|
|
14
|
+
decodeStructured: () => decodeStructured,
|
|
15
|
+
getToolCalls: () => getToolCalls,
|
|
15
16
|
isTurnComplete: () => isTurnComplete,
|
|
16
17
|
reasonings: () => reasonings,
|
|
17
|
-
textDeltas: () => textDeltas
|
|
18
|
-
toStructured: () => toStructured
|
|
18
|
+
textDeltas: () => textDeltas
|
|
19
19
|
});
|
|
20
20
|
/**
|
|
21
21
|
* The result of a single LLM generation. A turn produces zero or more items
|
|
@@ -23,14 +23,14 @@ var Turn_exports = /* @__PURE__ */ __exportAll({
|
|
|
23
23
|
* and reports usage + a stop reason.
|
|
24
24
|
*/
|
|
25
25
|
const Turn = Schema.Struct({
|
|
26
|
-
items: Schema.Array(
|
|
26
|
+
items: Schema.Array(HistoryItem),
|
|
27
27
|
usage: Usage,
|
|
28
28
|
stop_reason: StopReason
|
|
29
29
|
});
|
|
30
30
|
const TurnEvent = Data.taggedEnum();
|
|
31
31
|
const isTurnComplete = TurnEvent.$is("TurnComplete");
|
|
32
|
-
const
|
|
33
|
-
const reasonings = (turn) => turn.items.filter(
|
|
32
|
+
const getToolCalls = (turn) => turn.items.filter(isToolCall);
|
|
33
|
+
const reasonings = (turn) => turn.items.filter(isReasoning);
|
|
34
34
|
const assistantMessages = (turn) => turn.items.filter((i) => i.type === "message" && i.role === "assistant");
|
|
35
35
|
/**
|
|
36
36
|
* Every `output_text` payload across every assistant message in the turn,
|
|
@@ -49,9 +49,9 @@ const assistantText = (turn) => assistantTexts(turn).join("");
|
|
|
49
49
|
/**
|
|
50
50
|
* Append a completed turn and optional follow-up items to a state record's
|
|
51
51
|
* history. Recipes use this at the point where structured tool results are
|
|
52
|
-
* converted to model-facing `
|
|
52
|
+
* converted to model-facing `ToolCallOutput`s.
|
|
53
53
|
*/
|
|
54
|
-
const
|
|
54
|
+
const appendToHistory = (state, turn, items = []) => ({
|
|
55
55
|
...state,
|
|
56
56
|
history: [
|
|
57
57
|
...state.history,
|
|
@@ -67,7 +67,7 @@ const appendTurn = (state, turn, items = []) => ({
|
|
|
67
67
|
const textDeltas = (self) => self.pipe(Stream.filterMap((ev) => ev._tag === "TextDelta" ? Result.succeed(ev.text) : Result.failVoid));
|
|
68
68
|
/**
|
|
69
69
|
* The assistant message on the just-completed turn was a refusal block,
|
|
70
|
-
* not an `output_text` payload. Returned by `
|
|
70
|
+
* not an `output_text` payload. Returned by `decodeStructured` to short-circuit
|
|
71
71
|
* decoding before `JSON.parse` / schema validation runs.
|
|
72
72
|
*/
|
|
73
73
|
var RefusalRejected = class extends Data.TaggedError("RefusalRejected") {};
|
|
@@ -97,8 +97,8 @@ const lastAssistantContent = (turn) => {
|
|
|
97
97
|
* - `JsonParseError` — the assembled text wasn't valid JSON.
|
|
98
98
|
* - `StructuredDecodeError` — the JSON didn't match the schema.
|
|
99
99
|
*/
|
|
100
|
-
const
|
|
100
|
+
const decodeStructured = (turn, format) => pipe(lastAssistantContent(turn), ({ text, refused }) => refused ? Effect.fail(new RefusalRejected({ turn })) : parseJson(format)(text));
|
|
101
101
|
//#endregion
|
|
102
|
-
export { RefusalRejected, Turn, TurnEvent,
|
|
102
|
+
export { RefusalRejected, Turn, TurnEvent, appendToHistory, assistantMessages, assistantText, assistantTexts, decodeStructured, getToolCalls, isTurnComplete, reasonings, Turn_exports as t, textDeltas };
|
|
103
103
|
|
|
104
104
|
//# sourceMappingURL=Turn.mjs.map
|
package/dist/domain/Turn.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Turn.mjs","names":["StructuredFormat.parseJson"],"sources":["../../src/domain/Turn.ts"],"sourcesContent":["import { Data, Effect, Result, Schema, Stream, pipe } from \"effect\"\nimport * as StructuredFormat from \"../structured-format/StructuredFormat.js\"\nimport {\n
|
|
1
|
+
{"version":3,"file":"Turn.mjs","names":["StructuredFormat.parseJson"],"sources":["../../src/domain/Turn.ts"],"sourcesContent":["import { Data, Effect, Result, Schema, Stream, pipe } from \"effect\"\nimport * as StructuredFormat from \"../structured-format/StructuredFormat.js\"\nimport {\n HistoryItem,\n Message,\n Reasoning,\n StopReason,\n ToolCall,\n ToolCallOutput,\n Usage,\n isOutputText,\n isReasoning,\n isRefusal,\n isToolCall,\n} from \"./Items.js\"\n\n/**\n * The result of a single LLM generation. A turn produces zero or more items\n * (typically one assistant message and zero or more function_call items)\n * and reports usage + a stop reason.\n */\nexport const Turn = Schema.Struct({\n items: Schema.Array(HistoryItem),\n usage: Usage,\n stop_reason: StopReason,\n})\nexport type Turn = typeof Turn.Type\n\n/**\n * Canonical events emitted while a single turn is being generated. Most\n * variants are streaming deltas (text, reasoning, tool-call args); the\n * terminal `TurnComplete` carries the assembled `Turn`. Lifecycle members\n * aren't deltas, hence the union name.\n *\n * `ReasoningDelta.kind`: `trace` is the model's raw chain-of-thought;\n * `summary` is a model-written summary intended for display. OpenAI\n * Responses emits both; Anthropic and Gemini only emit `trace`.\n *\n * `RefusalDelta`: the model declined to answer. OpenAI Responses emits\n * this as its own event; Anthropic surfaces refusals via `stop_reason`\n * and Gemini collapses them into `finishReason: SAFETY` — both go\n * without a `RefusalDelta`.\n *\n * `UsageUpdate`: mid-stream cumulative usage. Anthropic emits this on\n * `message_start` and `message_delta`; other providers may only deliver\n * usage via `TurnComplete.turn.usage`.\n */\nexport type TurnEvent = Data.TaggedEnum<{\n TextDelta: { readonly text: string }\n ReasoningDelta: { readonly text: string; readonly kind: \"trace\" | \"summary\" }\n RefusalDelta: { readonly text: string }\n ToolCallStart: { readonly call_id: string; readonly name: string }\n ToolCallArgsDelta: { readonly call_id: string; readonly delta: string }\n UsageUpdate: { readonly usage: Usage }\n TurnComplete: { readonly turn: Turn }\n}>\n\nexport const TurnEvent = Data.taggedEnum<TurnEvent>()\n\n/**\n * What flows out of an agent loop body to its consumer per turn: every\n * `TurnEvent` the provider emits (including the terminal `TurnComplete`\n * carrying the assembled `Turn`), plus the output of any tool the loop ran.\n * Both variants carry a `_tag` discriminator.\n */\nexport type InteractionEvent = TurnEvent | ToolCallOutput\n\nexport const isTurnComplete = TurnEvent.$is(\"TurnComplete\")\n\nexport const getToolCalls = (turn: Turn): ReadonlyArray<ToolCall> => turn.items.filter(isToolCall)\n\nexport const reasonings = (turn: Turn): ReadonlyArray<Reasoning> => turn.items.filter(isReasoning)\n\nexport const assistantMessages = (turn: Turn): ReadonlyArray<Message> =>\n turn.items.filter((i): i is Message => i.type === \"message\" && i.role === \"assistant\")\n\n/**\n * Every `output_text` payload across every assistant message in the turn,\n * preserving order. Refusals and other content blocks are dropped — use\n * `assistantMessages` if you need to inspect them. The primitive for\n * \"give me the assistant's text\"; callers decide how to combine\n * (typically `.join(\"\")` for prose or `.join(\" \")` for log strings).\n */\nexport const assistantTexts = (turn: Turn): ReadonlyArray<string> =>\n assistantMessages(turn)\n .flatMap((m) => m.content)\n .filter(isOutputText)\n .map((b) => b.text)\n\n/**\n * Sugar over `assistantTexts(turn).join(\"\")` — the common case for\n * summarizers, classifiers, judge calls, and structured-output backstops\n * that want one concatenated string.\n */\nexport const assistantText = (turn: Turn): string => assistantTexts(turn).join(\"\")\n\n/**\n * Append a completed turn and optional follow-up items to a state record's\n * history. Recipes use this at the point where structured tool results are\n * converted to model-facing `ToolCallOutput`s.\n */\nexport const appendToHistory = <S extends { readonly history: ReadonlyArray<HistoryItem> }>(\n state: S,\n turn: Turn,\n items: ReadonlyArray<HistoryItem> = [],\n): S => ({\n ...state,\n history: [...state.history, ...turn.items, ...items],\n})\n\n// ---------------------------------------------------------------------------\n// Stream operators\n// ---------------------------------------------------------------------------\n\n/**\n * Project a `TurnEvent` stream onto its `TextDelta` payloads. Other\n * variants are dropped. Composes with `Lines.lines` +\n * `decodeJsonLines` for prompted-JSONL streaming.\n */\nexport const textDeltas = <E, R>(\n self: Stream.Stream<TurnEvent, E, R>,\n): Stream.Stream<string, E, R> =>\n self.pipe(\n Stream.filterMap((ev) => (ev._tag === \"TextDelta\" ? Result.succeed(ev.text) : Result.failVoid)),\n )\n\n// ---------------------------------------------------------------------------\n// Structured-output integration\n// ---------------------------------------------------------------------------\n\n/**\n * The assistant message on the just-completed turn was a refusal block,\n * not an `output_text` payload. Returned by `decodeStructured` to short-circuit\n * decoding before `JSON.parse` / schema validation runs.\n */\nexport class RefusalRejected extends Data.TaggedError(\"RefusalRejected\")<{\n readonly turn: Turn\n}> {}\n\nconst lastAssistantContent = (turn: Turn): { readonly text: string; readonly refused: boolean } => {\n const assistants = assistantMessages(turn)\n const last = assistants[assistants.length - 1]\n if (last === undefined) return { text: \"\", refused: false }\n if (last.content.some(isRefusal)) return { text: \"\", refused: true }\n const text = last.content\n .filter(isOutputText)\n .map((b) => b.text)\n .join(\"\")\n return { text, refused: false }\n}\n\n/**\n * Validate a completed `Turn` against a `StructuredFormat`. Concatenates\n * `output_text` blocks on the last assistant message, then runs\n * `JSON.parse` + the format's schema validation.\n *\n * Three failure modes:\n * - `RefusalRejected` — the assistant emitted a refusal block.\n * - `JsonParseError` — the assembled text wasn't valid JSON.\n * - `StructuredDecodeError` — the JSON didn't match the schema.\n */\nexport const decodeStructured = <A>(\n turn: Turn,\n format: StructuredFormat.StructuredFormat<A>,\n): Effect.Effect<\n A,\n RefusalRejected | StructuredFormat.JsonParseError | StructuredFormat.StructuredDecodeError\n> =>\n pipe(lastAssistantContent(turn), ({ text, refused }) =>\n refused ? Effect.fail(new RefusalRejected({ turn })) : StructuredFormat.parseJson(format)(text),\n )\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAqBA,MAAa,OAAO,OAAO,OAAO;CAChC,OAAO,OAAO,MAAM,YAAY;CAChC,OAAO;CACP,aAAa;CACd,CAAC;AAgCF,MAAa,YAAY,KAAK,YAAuB;AAUrD,MAAa,iBAAiB,UAAU,IAAI,eAAe;AAE3D,MAAa,gBAAgB,SAAwC,KAAK,MAAM,OAAO,WAAW;AAElG,MAAa,cAAc,SAAyC,KAAK,MAAM,OAAO,YAAY;AAElG,MAAa,qBAAqB,SAChC,KAAK,MAAM,QAAQ,MAAoB,EAAE,SAAS,aAAa,EAAE,SAAS,YAAY;;;;;;;;AASxF,MAAa,kBAAkB,SAC7B,kBAAkB,KAAK,CACpB,SAAS,MAAM,EAAE,QAAQ,CACzB,OAAO,aAAa,CACpB,KAAK,MAAM,EAAE,KAAK;;;;;;AAOvB,MAAa,iBAAiB,SAAuB,eAAe,KAAK,CAAC,KAAK,GAAG;;;;;;AAOlF,MAAa,mBACX,OACA,MACA,QAAoC,EAAE,MAC/B;CACP,GAAG;CACH,SAAS;EAAC,GAAG,MAAM;EAAS,GAAG,KAAK;EAAO,GAAG;EAAM;CACrD;;;;;;AAWD,MAAa,cACX,SAEA,KAAK,KACH,OAAO,WAAW,OAAQ,GAAG,SAAS,cAAc,OAAO,QAAQ,GAAG,KAAK,GAAG,OAAO,SAAU,CAChG;;;;;;AAWH,IAAa,kBAAb,cAAqC,KAAK,YAAY,kBAAkB,CAErE;AAEH,MAAM,wBAAwB,SAAqE;CACjG,MAAM,aAAa,kBAAkB,KAAK;CAC1C,MAAM,OAAO,WAAW,WAAW,SAAS;AAC5C,KAAI,SAAS,KAAA,EAAW,QAAO;EAAE,MAAM;EAAI,SAAS;EAAO;AAC3D,KAAI,KAAK,QAAQ,KAAK,UAAU,CAAE,QAAO;EAAE,MAAM;EAAI,SAAS;EAAM;AAKpE,QAAO;EAAE,MAJI,KAAK,QACf,OAAO,aAAa,CACpB,KAAK,MAAM,EAAE,KAAK,CAClB,KAAK,GACK;EAAE,SAAS;EAAO;;;;;;;;;;;;AAajC,MAAa,oBACX,MACA,WAKA,KAAK,qBAAqB,KAAK,GAAG,EAAE,MAAM,cACxC,UAAU,OAAO,KAAK,IAAI,gBAAgB,EAAE,MAAM,CAAC,CAAC,GAAGA,UAA2B,OAAO,CAAC,KAAK,CAChG"}
|
package/dist/index.d.mts
CHANGED
|
@@ -2,28 +2,33 @@ import { n as AiError_d_exports } from "./AiError-CAX_48RU.mjs";
|
|
|
2
2
|
import { a as Media_d_exports } from "./Media-D_CpcM1Z.mjs";
|
|
3
3
|
import { o as Audio_d_exports } from "./Audio-BfCTGnH3.mjs";
|
|
4
4
|
import { o as Image_d_exports } from "./Image-HNmMpMTh.mjs";
|
|
5
|
-
import {
|
|
5
|
+
import { u as Items_d_exports } from "./Items-pXR5BAgW.mjs";
|
|
6
6
|
import { t as Music_d_exports } from "./domain/Music.mjs";
|
|
7
7
|
import { t as Transcript_d_exports } from "./domain/Transcript.mjs";
|
|
8
8
|
import { a as StructuredFormat_d_exports } from "./StructuredFormat-BbN4dosH.mjs";
|
|
9
|
-
import {
|
|
9
|
+
import { t as Turn_d_exports } from "./domain/Turn.mjs";
|
|
10
10
|
import { t as Embedding_d_exports } from "./embedding-model/Embedding.mjs";
|
|
11
11
|
import { t as EmbeddingModel_d_exports } from "./embedding-model/EmbeddingModel.mjs";
|
|
12
|
-
import { l as Tool_d_exports } from "./Tool-
|
|
12
|
+
import { l as Tool_d_exports } from "./Tool-DP-AwKOf.mjs";
|
|
13
13
|
import { t as LanguageModel_d_exports } from "./language-model/LanguageModel.mjs";
|
|
14
14
|
import { t as MusicGenerator_d_exports } from "./music-generator/MusicGenerator.mjs";
|
|
15
|
+
import { t as Memory_d_exports } from "./sandbox/Memory.mjs";
|
|
16
|
+
import { o as SandboxError_d_exports } from "./SandboxError-BvKypkJm.mjs";
|
|
17
|
+
import { t as Sandbox_d_exports } from "./sandbox/Sandbox.mjs";
|
|
18
|
+
import { t as SandboxImage_d_exports } from "./sandbox/SandboxImage.mjs";
|
|
19
|
+
import { t as SandboxNetwork_d_exports } from "./sandbox/SandboxNetwork.mjs";
|
|
15
20
|
import { t as SpeechSynthesizer_d_exports } from "./speech-synthesizer/SpeechSynthesizer.mjs";
|
|
16
21
|
import { t as Transcriber_d_exports } from "./transcriber/Transcriber.mjs";
|
|
17
22
|
import { t as Vector_d_exports } from "./math/Vector.mjs";
|
|
18
23
|
import { t as Loop_d_exports } from "./loop/Loop.mjs";
|
|
19
24
|
import { t as Retry_d_exports } from "./retry/Retry.mjs";
|
|
20
|
-
import { t as
|
|
25
|
+
import { t as ToolResult_d_exports } from "./tool/ToolResult.mjs";
|
|
21
26
|
import { t as ToolEvent_d_exports } from "./tool/ToolEvent.mjs";
|
|
22
27
|
import { t as Toolkit_d_exports } from "./tool/Toolkit.mjs";
|
|
23
|
-
import { t as
|
|
28
|
+
import { t as Approval_d_exports } from "./tool/Approval.mjs";
|
|
24
29
|
import { t as HistoryCheck_d_exports } from "./tool/HistoryCheck.mjs";
|
|
25
30
|
import { t as JSONL_d_exports } from "./streaming/JSONL.mjs";
|
|
26
31
|
import { t as Lines_d_exports } from "./streaming/Lines.mjs";
|
|
27
32
|
import { t as SSE_d_exports } from "./streaming/SSE.mjs";
|
|
28
33
|
import { t as Metrics_d_exports } from "./observability/Metrics.mjs";
|
|
29
|
-
export { AiError_d_exports as AiError, Audio_d_exports as Audio, Embedding_d_exports as Embedding, EmbeddingModel_d_exports as EmbeddingModel, HistoryCheck_d_exports as HistoryCheck, Image_d_exports as Image, Items_d_exports as Items, JSONL_d_exports as JSONL, LanguageModel_d_exports as LanguageModel, Lines_d_exports as Lines, Loop_d_exports as Loop, Media_d_exports as Media, Metrics_d_exports as Metrics, Music_d_exports as Music, MusicGenerator_d_exports as MusicGenerator,
|
|
34
|
+
export { AiError_d_exports as AiError, Approval_d_exports as Approval, Audio_d_exports as Audio, Embedding_d_exports as Embedding, EmbeddingModel_d_exports as EmbeddingModel, HistoryCheck_d_exports as HistoryCheck, Image_d_exports as Image, Items_d_exports as Items, JSONL_d_exports as JSONL, LanguageModel_d_exports as LanguageModel, Lines_d_exports as Lines, Loop_d_exports as Loop, Media_d_exports as Media, Memory_d_exports as Memory, Metrics_d_exports as Metrics, Music_d_exports as Music, MusicGenerator_d_exports as MusicGenerator, Retry_d_exports as Retry, SSE_d_exports as SSE, Sandbox_d_exports as Sandbox, SandboxError_d_exports as SandboxError, SandboxImage_d_exports as SandboxImage, SandboxNetwork_d_exports as SandboxNetwork, SpeechSynthesizer_d_exports as SpeechSynthesizer, StructuredFormat_d_exports as StructuredFormat, Tool_d_exports as Tool, ToolEvent_d_exports as ToolEvent, ToolResult_d_exports as ToolResult, Toolkit_d_exports as Toolkit, Transcriber_d_exports as Transcriber, Transcript_d_exports as Transcript, Turn_d_exports as Turn, Vector_d_exports as Vector };
|
package/dist/index.mjs
CHANGED
|
@@ -11,19 +11,24 @@ import { t as Embedding_exports } from "./embedding-model/Embedding.mjs";
|
|
|
11
11
|
import { t as EmbeddingModel_exports } from "./embedding-model/EmbeddingModel.mjs";
|
|
12
12
|
import { t as LanguageModel_exports } from "./language-model/LanguageModel.mjs";
|
|
13
13
|
import { t as MusicGenerator_exports } from "./music-generator/MusicGenerator.mjs";
|
|
14
|
+
import { t as Memory_exports } from "./sandbox/Memory.mjs";
|
|
15
|
+
import { t as Sandbox_exports } from "./sandbox/Sandbox.mjs";
|
|
16
|
+
import { t as SandboxError_exports } from "./sandbox/SandboxError.mjs";
|
|
17
|
+
import { t as SandboxImage_exports } from "./sandbox/SandboxImage.mjs";
|
|
18
|
+
import { t as SandboxNetwork_exports } from "./sandbox/SandboxNetwork.mjs";
|
|
14
19
|
import { t as SpeechSynthesizer_exports } from "./speech-synthesizer/SpeechSynthesizer.mjs";
|
|
15
20
|
import { t as Transcriber_exports } from "./transcriber/Transcriber.mjs";
|
|
16
21
|
import { t as Vector_exports } from "./math/Vector.mjs";
|
|
17
22
|
import { t as Loop_exports } from "./loop/Loop.mjs";
|
|
18
23
|
import { t as Retry_exports } from "./retry/Retry.mjs";
|
|
19
24
|
import { t as Tool_exports } from "./tool/Tool.mjs";
|
|
20
|
-
import { t as
|
|
25
|
+
import { t as ToolResult_exports } from "./tool/ToolResult.mjs";
|
|
21
26
|
import { t as ToolEvent_exports } from "./tool/ToolEvent.mjs";
|
|
22
27
|
import { t as Toolkit_exports } from "./tool/Toolkit.mjs";
|
|
23
|
-
import { t as
|
|
28
|
+
import { t as Approval_exports } from "./tool/Approval.mjs";
|
|
24
29
|
import { t as HistoryCheck_exports } from "./tool/HistoryCheck.mjs";
|
|
25
30
|
import { t as JSONL_exports } from "./streaming/JSONL.mjs";
|
|
26
31
|
import { t as Lines_exports } from "./streaming/Lines.mjs";
|
|
27
32
|
import { t as SSE_exports } from "./streaming/SSE.mjs";
|
|
28
33
|
import { t as Metrics_exports } from "./observability/Metrics.mjs";
|
|
29
|
-
export { AiError_exports as AiError, Audio_exports as Audio, Embedding_exports as Embedding, EmbeddingModel_exports as EmbeddingModel, HistoryCheck_exports as HistoryCheck, Image_exports as Image, Items_exports as Items, JSONL_exports as JSONL, LanguageModel_exports as LanguageModel, Lines_exports as Lines, Loop_exports as Loop, Media_exports as Media, Metrics_exports as Metrics, Music_exports as Music, MusicGenerator_exports as MusicGenerator,
|
|
34
|
+
export { AiError_exports as AiError, Approval_exports as Approval, Audio_exports as Audio, Embedding_exports as Embedding, EmbeddingModel_exports as EmbeddingModel, HistoryCheck_exports as HistoryCheck, Image_exports as Image, Items_exports as Items, JSONL_exports as JSONL, LanguageModel_exports as LanguageModel, Lines_exports as Lines, Loop_exports as Loop, Media_exports as Media, Memory_exports as Memory, Metrics_exports as Metrics, Music_exports as Music, MusicGenerator_exports as MusicGenerator, Retry_exports as Retry, SSE_exports as SSE, Sandbox_exports as Sandbox, SandboxError_exports as SandboxError, SandboxImage_exports as SandboxImage, SandboxNetwork_exports as SandboxNetwork, SpeechSynthesizer_exports as SpeechSynthesizer, StructuredFormat_exports as StructuredFormat, Tool_exports as Tool, ToolEvent_exports as ToolEvent, ToolResult_exports as ToolResult, Toolkit_exports as Toolkit, Transcriber_exports as Transcriber, Transcript_exports as Transcript, Turn_exports as Turn, Vector_exports as Vector };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { t as AiError } from "../AiError-CAX_48RU.mjs";
|
|
2
|
-
import {
|
|
2
|
+
import { o as HistoryItem } from "../Items-pXR5BAgW.mjs";
|
|
3
3
|
import { i as StructuredFormat } from "../StructuredFormat-BbN4dosH.mjs";
|
|
4
|
-
import {
|
|
5
|
-
import { o as ToolDescriptor } from "../Tool-
|
|
4
|
+
import { Turn, TurnEvent } from "../domain/Turn.mjs";
|
|
5
|
+
import { o as ToolDescriptor } from "../Tool-DP-AwKOf.mjs";
|
|
6
6
|
import { Context, Effect, Stream } from "effect";
|
|
7
7
|
|
|
8
8
|
//#region src/language-model/LanguageModel.d.ts
|
|
@@ -16,7 +16,7 @@ declare namespace LanguageModel_d_exports {
|
|
|
16
16
|
* ...) lives in that provider's own request interface, which extends this.
|
|
17
17
|
*/
|
|
18
18
|
type CommonRequest = {
|
|
19
|
-
readonly history: ReadonlyArray<
|
|
19
|
+
readonly history: ReadonlyArray<HistoryItem>;
|
|
20
20
|
/**
|
|
21
21
|
* Model identifier. Each provider narrows this to its typed literal union,
|
|
22
22
|
* so code that yields a typed provider tag gets autocompletion.
|
|
@@ -32,7 +32,7 @@ type CommonRequest = {
|
|
|
32
32
|
readonly maxOutputTokens?: number;
|
|
33
33
|
/**
|
|
34
34
|
* Schema-bound JSON output. The provider constrains the wire to match the
|
|
35
|
-
* schema; pair with `Turn.
|
|
35
|
+
* schema; pair with `Turn.decodeStructured` for runtime validation. Supported
|
|
36
36
|
* across all current providers (OpenAI Responses json_schema, Anthropic
|
|
37
37
|
* `output_config`, Gemini `responseJsonSchema`).
|
|
38
38
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LanguageModel.d.mts","names":[],"sources":["../../src/language-model/LanguageModel.ts"],"mappings":";;;;;;;;;;;;;;;;;KAaY,aAAA;EAAA,SACD,OAAA,EAAS,aAAA,CAAc,
|
|
1
|
+
{"version":3,"file":"LanguageModel.d.mts","names":[],"sources":["../../src/language-model/LanguageModel.ts"],"mappings":";;;;;;;;;;;;;;;;;KAaY,aAAA;EAAA,SACD,OAAA,EAAS,aAAA,CAAc,WAAA;;;;AADlC;WAMW,KAAA;EAAA,SACA,KAAA,GAAQ,aAAA,CAAc,cAAA;EAAA,SACtB,UAAA;IAAA,SAIM,IAAA;IAAA,SAA2B,IAAA;EAAA;EAAA,SACjC,WAAA;EAAA,SACA,IAAA;EAAA,SACA,eAAA;EAdA;;;;;;EAAA,SAqBA,UAAA,GAAa,gBAAA;AAAA;AAAA,KAGZ,oBAAA;EAAA,SACD,UAAA,GAAa,OAAA,EAAS,aAAA,KAAkB,MAAA,CAAO,MAAA,CAAO,SAAA,EAAW,OAAA;EAbjE;;;;;;;;AAYX;EAZW,SAuBA,IAAA,GAAO,OAAA,EAAS,aAAA,KAAkB,MAAA,CAAO,MAAA,CAAO,IAAA,EAAM,OAAA;AAAA;AAAA,cAChE,kBAAA;cAEY,aAAA,SAAsB,kBAAA;;;;cAOtB,UAAA,GACX,OAAA,EAAS,aAAA,KACR,MAAA,CAAO,MAAA,CAAO,SAAA,EAAW,OAAA,EAAiB,aAAA;;;;;;;cAShC,IAAA,GAAQ,OAAA,EAAS,aAAA,KAAgB,MAAA,CAAO,MAAA,CAAO,IAAA,EAAM,OAAA,EAAiB,aAAA;;;;;;;cAStE,cAAA,QACL,UAAA,GAAa,OAAA,EAAS,GAAA,KAAQ,MAAA,CAAO,MAAA,CAAO,SAAA,EAAW,OAAA,OAC5D,OAAA,EAAS,GAAA,KAAM,MAAA,CAAO,MAAA,CAAO,IAAA,EAAM,OAAA"}
|