@effect-uai/core 0.9.0 → 0.11.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/dist/{AiError-CrdR1EQi.d.mts → AiError-Bf1pq4BB.d.mts} +8 -3
- package/dist/{AiError-CrdR1EQi.d.mts.map → AiError-Bf1pq4BB.d.mts.map} +1 -1
- package/dist/{Audio-DDSKCkSe.d.mts → Audio-CR7CSljJ.d.mts} +2 -2
- package/dist/{Audio-DDSKCkSe.d.mts.map → Audio-CR7CSljJ.d.mts.map} +1 -1
- package/dist/{Image-C_Zjpwhc.d.mts → Image-C4vuBmu0.d.mts} +12 -12
- package/dist/{Image-C_Zjpwhc.d.mts.map → Image-C4vuBmu0.d.mts.map} +1 -1
- package/dist/{Items-CgKD6Npw.d.mts → Items-BWNu6VGp.d.mts} +118 -92
- package/dist/Items-BWNu6VGp.d.mts.map +1 -0
- package/dist/{Loop-B5_cqumi.d.mts → Loop-D8nWpowc.d.mts} +2 -2
- package/dist/{Loop-B5_cqumi.d.mts.map → Loop-D8nWpowc.d.mts.map} +1 -1
- package/dist/{Media-DOLyaygI.d.mts → Media-D_CpcM1Z.d.mts} +1 -1
- package/dist/{Media-DOLyaygI.d.mts.map → Media-D_CpcM1Z.d.mts.map} +1 -1
- package/dist/{StructuredFormat-CMJFD3sn.d.mts → StructuredFormat-DHaUJBdd.d.mts} +1 -1
- package/dist/{StructuredFormat-CMJFD3sn.d.mts.map → StructuredFormat-DHaUJBdd.d.mts.map} +1 -1
- package/dist/{Tool-0XUIT2A2.d.mts → Tool-CXFHCQrT.d.mts} +101 -16
- package/dist/Tool-CXFHCQrT.d.mts.map +1 -0
- package/dist/{ToolEvent-DYrAUJGs.d.mts → ToolEvent-nVijCrvm.d.mts} +2 -2
- package/dist/ToolEvent-nVijCrvm.d.mts.map +1 -0
- package/dist/{ToolResult-BZd-cEWW.d.mts → ToolResult-CQqKkcDa.d.mts} +10 -4
- package/dist/ToolResult-CQqKkcDa.d.mts.map +1 -0
- package/dist/{Toolkit-BKC8b8Xo.d.mts → Toolkit-BYPwwu-j.d.mts} +65 -24
- package/dist/Toolkit-BYPwwu-j.d.mts.map +1 -0
- package/dist/browser/Browser.d.mts +190 -0
- package/dist/browser/Browser.d.mts.map +1 -0
- package/dist/browser/Browser.mjs +34 -0
- package/dist/browser/Browser.mjs.map +1 -0
- package/dist/browser/BrowserError.d.mts +141 -0
- package/dist/browser/BrowserError.d.mts.map +1 -0
- package/dist/browser/BrowserError.mjs +89 -0
- package/dist/browser/BrowserError.mjs.map +1 -0
- package/dist/browser/BrowserTool.d.mts +59 -0
- package/dist/browser/BrowserTool.d.mts.map +1 -0
- package/dist/browser/BrowserTool.mjs +86 -0
- package/dist/browser/BrowserTool.mjs.map +1 -0
- package/dist/{dist-DWgRbDN3.mjs → dist-C0m0QnUP.mjs} +71 -30
- package/dist/dist-C0m0QnUP.mjs.map +1 -0
- package/dist/{dist-B04dlFHg.mjs → dist-CcRV3-A5.mjs} +8 -8
- package/dist/{dist-B04dlFHg.mjs.map → dist-CcRV3-A5.mjs.map} +1 -1
- package/dist/domain/AiError.d.mts +2 -2
- package/dist/domain/AiError.mjs +22 -3
- package/dist/domain/AiError.mjs.map +1 -1
- package/dist/domain/Audio.d.mts +1 -1
- package/dist/domain/Citation.d.mts +60 -0
- package/dist/domain/Citation.d.mts.map +1 -0
- package/dist/domain/Citation.mjs +7 -0
- package/dist/domain/Citation.mjs.map +1 -0
- package/dist/domain/Image.d.mts +1 -1
- package/dist/domain/Items.d.mts +1 -1
- package/dist/domain/Items.mjs +13 -3
- package/dist/domain/Items.mjs.map +1 -1
- package/dist/domain/Media.d.mts +1 -1
- package/dist/domain/Music.d.mts +1 -1
- package/dist/domain/Research.d.mts +37 -0
- package/dist/domain/Research.d.mts.map +1 -0
- package/dist/domain/Research.mjs +7 -0
- package/dist/domain/Research.mjs.map +1 -0
- package/dist/domain/Turn.d.mts +92 -10
- package/dist/domain/Turn.d.mts.map +1 -1
- package/dist/domain/Turn.mjs +8 -1
- package/dist/domain/Turn.mjs.map +1 -1
- package/dist/domain/Turn.test.mjs +1 -1
- package/dist/embedding-model/Embedding.d.mts +1 -1
- package/dist/embedding-model/EmbeddingModel.d.mts +1 -1
- package/dist/embedding-model/EmbeddingModel.mjs +2 -2
- package/dist/embedding-model/EmbeddingModel.mjs.map +1 -1
- package/dist/embedding-model/EmbeddingModel.test.mjs +1 -1
- package/dist/index.d.mts +22 -13
- package/dist/index.mjs +18 -9
- package/dist/job/Job.d.mts +80 -0
- package/dist/job/Job.d.mts.map +1 -0
- package/dist/job/Job.mjs +49 -0
- package/dist/job/Job.mjs.map +1 -0
- package/dist/language-model/LanguageModel.d.mts +4 -4
- package/dist/language-model/LanguageModel.mjs +2 -2
- package/dist/language-model/LanguageModel.mjs.map +1 -1
- package/dist/language-model/LanguageModel.test.mjs +1 -1
- package/dist/loop/Loop.d.mts +1 -1
- package/dist/loop/Loop.test.mjs +1 -1
- package/dist/music-generator/MusicGenerator.d.mts +2 -2
- package/dist/music-generator/MusicGenerator.mjs +4 -4
- package/dist/music-generator/MusicGenerator.mjs.map +1 -1
- package/dist/music-generator/MusicGenerator.test.mjs +1 -1
- package/dist/observability/Metrics.d.mts +1 -1
- package/dist/observability/Metrics.test.mjs +2 -2
- package/dist/observability/Telemetry.test.mjs +2 -2
- package/dist/research/DeepResearch.d.mts +71 -0
- package/dist/research/DeepResearch.d.mts.map +1 -0
- package/dist/research/DeepResearch.mjs +61 -0
- package/dist/research/DeepResearch.mjs.map +1 -0
- package/dist/retry/Retry.d.mts +1 -1
- package/dist/retry/Retry.test.mjs +1 -1
- package/dist/sandbox/Sandbox.mjs +18 -18
- package/dist/sandbox/Sandbox.mjs.map +1 -1
- package/dist/speech-synthesizer/SpeechSynthesizer.d.mts +2 -2
- package/dist/speech-synthesizer/SpeechSynthesizer.mjs +8 -8
- package/dist/speech-synthesizer/SpeechSynthesizer.mjs.map +1 -1
- package/dist/speech-synthesizer/SpeechSynthesizer.test.mjs +1 -1
- package/dist/streaming/JSONL.d.mts +3 -1
- package/dist/streaming/JSONL.d.mts.map +1 -1
- package/dist/streaming/JSONL.mjs +5 -11
- package/dist/streaming/JSONL.mjs.map +1 -1
- package/dist/streaming/JSONL.test.mjs +10 -1
- package/dist/streaming/JSONL.test.mjs.map +1 -1
- package/dist/streaming/SSE.d.mts +5 -3
- package/dist/streaming/SSE.d.mts.map +1 -1
- package/dist/streaming/SSE.mjs +28 -38
- package/dist/streaming/SSE.mjs.map +1 -1
- package/dist/streaming/SSE.test.mjs +54 -4
- package/dist/streaming/SSE.test.mjs.map +1 -1
- package/dist/structured-format/StructuredFormat.d.mts +1 -1
- package/dist/structured-format/StructuredFormat.test.mjs +1 -1
- package/dist/testing/MockMusicGenerator.d.mts +1 -1
- package/dist/testing/MockProvider.d.mts +1 -1
- package/dist/testing/MockSpeechSynthesizer.d.mts +1 -1
- package/dist/tool/Approval.d.mts +19 -7
- package/dist/tool/Approval.d.mts.map +1 -1
- package/dist/tool/Approval.mjs +18 -11
- package/dist/tool/Approval.mjs.map +1 -1
- package/dist/tool/Approval.test.mjs +47 -8
- package/dist/tool/Approval.test.mjs.map +1 -1
- package/dist/tool/HistoryCheck.d.mts +2 -2
- package/dist/tool/Tool.d.mts +2 -2
- package/dist/tool/Tool.mjs +112 -28
- package/dist/tool/Tool.mjs.map +1 -1
- package/dist/tool/Tool.test.mjs +127 -3
- package/dist/tool/Tool.test.mjs.map +1 -1
- package/dist/tool/ToolEvent.d.mts +1 -1
- package/dist/tool/ToolEvent.mjs +5 -0
- package/dist/tool/ToolEvent.mjs.map +1 -1
- package/dist/tool/ToolResult.d.mts +2 -2
- package/dist/tool/ToolResult.mjs +15 -6
- package/dist/tool/ToolResult.mjs.map +1 -1
- package/dist/tool/Toolkit.d.mts +2 -2
- package/dist/tool/Toolkit.mjs +62 -22
- package/dist/tool/Toolkit.mjs.map +1 -1
- package/dist/tool/Toolkit.test.mjs +207 -9
- package/dist/tool/Toolkit.test.mjs.map +1 -1
- package/dist/transcriber/Transcriber.d.mts +2 -2
- package/dist/transcriber/Transcriber.mjs +3 -3
- package/dist/transcriber/Transcriber.mjs.map +1 -1
- package/dist/transcriber/Transcriber.test.mjs +1 -1
- package/dist/web-read/WebRead.d.mts +44 -0
- package/dist/web-read/WebRead.d.mts.map +1 -0
- package/dist/web-read/WebRead.mjs +18 -0
- package/dist/web-read/WebRead.mjs.map +1 -0
- package/dist/web-read/WebReadTool.d.mts +57 -0
- package/dist/web-read/WebReadTool.d.mts.map +1 -0
- package/dist/web-read/WebReadTool.mjs +59 -0
- package/dist/web-read/WebReadTool.mjs.map +1 -0
- package/dist/web-search/WebSearch.d.mts +1 -1
- package/dist/web-search/WebSearch.mjs +1 -1
- package/dist/web-search/WebSearch.mjs.map +1 -1
- package/dist/web-search/WebSearchTool.d.mts +12 -6
- package/dist/web-search/WebSearchTool.d.mts.map +1 -1
- package/dist/web-search/WebSearchTool.mjs +10 -5
- package/dist/web-search/WebSearchTool.mjs.map +1 -1
- package/package.json +39 -3
- package/src/browser/Browser.ts +268 -0
- package/src/browser/BrowserError.ts +145 -0
- package/src/browser/BrowserTool.ts +161 -0
- package/src/domain/AiError.ts +27 -1
- package/src/domain/Citation.ts +64 -0
- package/src/domain/Items.ts +14 -4
- package/src/domain/Research.ts +42 -0
- package/src/domain/Turn.ts +26 -0
- package/src/embedding-model/EmbeddingModel.ts +2 -2
- package/src/index.ts +9 -0
- package/src/job/Job.ts +125 -0
- package/src/language-model/LanguageModel.ts +2 -2
- package/src/music-generator/MusicGenerator.ts +4 -4
- package/src/research/DeepResearch.ts +137 -0
- package/src/sandbox/Sandbox.ts +18 -18
- package/src/speech-synthesizer/SpeechSynthesizer.ts +8 -8
- package/src/streaming/JSONL.test.ts +19 -0
- package/src/streaming/JSONL.ts +6 -38
- package/src/streaming/SSE.test.ts +86 -3
- package/src/streaming/SSE.ts +36 -80
- package/src/tool/Approval.test.ts +55 -5
- package/src/tool/Approval.ts +72 -27
- package/src/tool/Tool.test.ts +151 -1
- package/src/tool/Tool.ts +263 -66
- package/src/tool/ToolEvent.ts +5 -0
- package/src/tool/ToolResult.ts +14 -8
- package/src/tool/Toolkit.test.ts +231 -2
- package/src/tool/Toolkit.ts +175 -62
- package/src/transcriber/Transcriber.ts +3 -3
- package/src/web-read/WebRead.ts +70 -0
- package/src/web-read/WebReadTool.ts +96 -0
- package/src/web-search/WebSearch.ts +1 -1
- package/src/web-search/WebSearchTool.ts +11 -5
- package/dist/Items-CgKD6Npw.d.mts.map +0 -1
- package/dist/Tool-0XUIT2A2.d.mts.map +0 -1
- package/dist/ToolEvent-DYrAUJGs.d.mts.map +0 -1
- package/dist/ToolResult-BZd-cEWW.d.mts.map +0 -1
- package/dist/Toolkit-BKC8b8Xo.d.mts.map +0 -1
- package/dist/dist-DWgRbDN3.mjs.map +0 -1
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { v as ToolCall, y as ToolCallOutput } from "./Items-
|
|
1
|
+
import { v as ToolCall, y as ToolCallOutput } from "./Items-BWNu6VGp.mjs";
|
|
2
2
|
import { Effect, Schema } from "effect";
|
|
3
3
|
import * as _$effect_Cause0 from "effect/Cause";
|
|
4
4
|
import { StandardJSONSchemaV1, StandardSchemaV1 } from "@standard-schema/spec";
|
|
5
5
|
|
|
6
6
|
//#region src/tool/Tool.d.ts
|
|
7
7
|
declare namespace Tool_d_exports {
|
|
8
|
-
export { AnyLocalTool, AnyTool, DecodableTool, Emit, InteractionTool, ProviderTool, SignalTool, Tool, ToolDescriptor, ToolError, ToolInputSchema, ToolR, ToolValidationError, decodeArgs, descriptorsOf, execute, fromEffectSchema, fromStandardSchema, interaction, make, provider, signal, toDescriptors, withName, withRun };
|
|
8
|
+
export { AnyLocalTool, AnyTool, DecodableTool, DecodeResult, Emit, InteractionTool, ProviderTool, SignalTool, Tool, ToolDescriptor, ToolE, ToolError, ToolFailed, ToolInputSchema, ToolR, ToolValidationError, decodeArgs, decodeCallInput, descriptorsOf, execute, fail, fromEffectSchema, fromStandardSchema, interaction, isProviderTool, make, noInput, provider, providerToolsOf, signal, toDescriptors, withName, withRun };
|
|
9
9
|
}
|
|
10
10
|
declare const ToolError_base: Schema.Class<ToolError, Schema.TaggedStruct<"ToolError", {
|
|
11
11
|
readonly call_id: Schema.String;
|
|
@@ -29,6 +29,28 @@ declare const ToolValidationError_base: Schema.Class<ToolValidationError, Schema
|
|
|
29
29
|
* structured `issues` survive instead of being flattened into a message string.
|
|
30
30
|
*/
|
|
31
31
|
declare class ToolValidationError extends ToolValidationError_base {}
|
|
32
|
+
declare const ToolFailed_base: Schema.Class<ToolFailed, Schema.TaggedStruct<"ToolFailed", {
|
|
33
|
+
readonly message: Schema.String;
|
|
34
|
+
readonly kind: Schema.optional<Schema.String>;
|
|
35
|
+
}>, _$effect_Cause0.YieldableError>;
|
|
36
|
+
/**
|
|
37
|
+
* The deliberate "speak to the model" failure sentinel. A tool's `run` that
|
|
38
|
+
* fails with a `ToolFailed` (or a bare `string`, its sugar) is absorbed by
|
|
39
|
+
* `Toolkit.run` into a `ToolResult.Failure` the model reads and adapts to,
|
|
40
|
+
* instead of ending the run. Every other error type propagates typed on the
|
|
41
|
+
* executor's stream. `kind` overrides the synthesized `Failure.kind`
|
|
42
|
+
* (default `"tool_failed"`) so a tool can hand the model a distinguishable
|
|
43
|
+
* category (`"not_found"`, `"rate_limited"`) without a new result variant.
|
|
44
|
+
*/
|
|
45
|
+
declare class ToolFailed extends ToolFailed_base {}
|
|
46
|
+
/**
|
|
47
|
+
* Fail a tool's `run` with a model-visible message (optionally a `kind`).
|
|
48
|
+
* `yield* Tool.fail("page not found", { kind: "not_found" })` inside a
|
|
49
|
+
* `run`'s `Effect.gen`; the executor absorbs it as `ToolResult.Failure`.
|
|
50
|
+
*/
|
|
51
|
+
declare const fail: (message: string, options?: {
|
|
52
|
+
readonly kind?: string;
|
|
53
|
+
}) => Effect.Effect<never, ToolFailed>;
|
|
32
54
|
/**
|
|
33
55
|
* Schemas accepted on `Tool.inputSchema`. Must implement both Standard
|
|
34
56
|
* Schema validation and JSON Schema conversion (for rendering tool
|
|
@@ -61,6 +83,14 @@ declare const fromEffectSchema: <S extends Schema.Codec<any, any, never, any>>(s
|
|
|
61
83
|
* helper makes the input type inference explicit at the call site.
|
|
62
84
|
*/
|
|
63
85
|
declare const fromStandardSchema: <S extends StandardSchemaV1 & StandardJSONSchemaV1>(schema: S) => S & ToolInputSchema<StandardSchemaV1.InferOutput<S>>;
|
|
86
|
+
/**
|
|
87
|
+
* Input schema for a tool that takes no arguments. Renders a clean
|
|
88
|
+
* `{ type: "object", properties: {} }`; validation accepts anything and
|
|
89
|
+
* yields `{}`. Use it instead of `fromEffectSchema(Schema.Struct({}))`,
|
|
90
|
+
* which renders a degenerate `anyOf` (object-or-array) that strict
|
|
91
|
+
* providers like Gemini reject.
|
|
92
|
+
*/
|
|
93
|
+
declare const noInput: ToolInputSchema<Record<string, never>>;
|
|
64
94
|
/**
|
|
65
95
|
* Emit one intermediate `Event` from inside a tool's `run`. Backed by the
|
|
66
96
|
* executor's per-call queue, so it returns an `Effect` (backpressure) and
|
|
@@ -79,12 +109,12 @@ type Emit<Event> = (event: Event) => Effect.Effect<void>;
|
|
|
79
109
|
* no local executor — see their constructors below. `Tool` keeps its name (and
|
|
80
110
|
* the `Tool.make` constructor) because the local kind is by far the common one.
|
|
81
111
|
*/
|
|
82
|
-
type Tool<Name extends string, Input, Event, Output, R = never> = {
|
|
112
|
+
type Tool<Name extends string, Input, Event, Output, E = unknown, R = never> = {
|
|
83
113
|
readonly _tag: "LocalTool";
|
|
84
114
|
readonly name: Name;
|
|
85
115
|
readonly description: string;
|
|
86
116
|
readonly inputSchema: ToolInputSchema<Input>;
|
|
87
|
-
readonly run: (input: Input, emit: Emit<Event>) => Effect.Effect<Output,
|
|
117
|
+
readonly run: (input: Input, emit: Emit<Event>) => Effect.Effect<Output, E, R>;
|
|
88
118
|
/**
|
|
89
119
|
* Bound on this tool's emit queue. Unbounded when omitted. Per-tool because
|
|
90
120
|
* backpressure depends on how a given tool emits, unlike `concurrency`
|
|
@@ -139,16 +169,18 @@ type InteractionTool<Name extends string, Input> = {
|
|
|
139
169
|
readonly inputSchema: ToolInputSchema<Input>;
|
|
140
170
|
};
|
|
141
171
|
/** A local (executable) tool of any shape. Readability alias. */
|
|
142
|
-
type AnyLocalTool<R = any> = Tool<string, any, any, any, R>;
|
|
172
|
+
type AnyLocalTool<E = any, R = any> = Tool<string, any, any, any, E, R>;
|
|
143
173
|
/** Any of the four model-visible tool kinds. */
|
|
144
|
-
type AnyTool<R = any> = Tool<string, any, any, any, R> | ProviderTool<string, any, string, any> | SignalTool<string, any> | InteractionTool<string, any>;
|
|
174
|
+
type AnyTool<E = any, R = any> = Tool<string, any, any, any, E, R> | ProviderTool<string, any, string, any> | SignalTool<string, any> | InteractionTool<string, any>;
|
|
145
175
|
/** A model-visible tool that carries a decodable input schema (every kind). */
|
|
146
176
|
type DecodableTool<Input> = {
|
|
147
177
|
readonly name: string;
|
|
148
178
|
readonly inputSchema: ToolInputSchema<Input>;
|
|
149
179
|
};
|
|
150
180
|
/** Extract the `R` of a local tool; non-local kinds contribute `never`. */
|
|
151
|
-
type ToolR<T> = T extends Tool<string, any, any, any, infer R> ? R : never;
|
|
181
|
+
type ToolR<T> = T extends Tool<string, any, any, any, any, infer R> ? R : never;
|
|
182
|
+
/** Extract the `E` of a local tool; non-local kinds contribute `never`. */
|
|
183
|
+
type ToolE<T> = T extends Tool<string, any, any, any, infer E, any> ? E : never;
|
|
152
184
|
/**
|
|
153
185
|
* Provider-agnostic tool descriptor. Each provider maps `inputSchema`
|
|
154
186
|
* to its own wire field (OpenAI → `parameters`, Anthropic →
|
|
@@ -161,25 +193,45 @@ type ToolDescriptor = {
|
|
|
161
193
|
readonly strict?: boolean;
|
|
162
194
|
};
|
|
163
195
|
/** A model-visible tool with a local `Effect` executor. */
|
|
164
|
-
declare const make:
|
|
196
|
+
declare const make: {
|
|
197
|
+
<Name extends string, S extends Schema.Codec<any, any, never, any>, Event, Output, E = never, R = never>(spec: Omit<Tool<Name, S["Type"], Event, Output, E, R>, "_tag" | "inputSchema"> & {
|
|
198
|
+
readonly inputSchema: S;
|
|
199
|
+
}): Tool<Name, S["Type"], Event, Output, E, R>;
|
|
200
|
+
<Name extends string, Input, Event, Output, E = never, R = never>(spec: Omit<Tool<Name, Input, Event, Output, E, R>, "_tag">): Tool<Name, Input, Event, Output, E, R>;
|
|
201
|
+
};
|
|
165
202
|
/**
|
|
166
203
|
* A provider-hosted tool (native web search, code execution, RAG grounding).
|
|
167
204
|
* No local executor — `provider`/`config` drive the provider adapter's
|
|
168
205
|
* rendering. The model sees it; `Toolkit.run` reports it as `non_local_tool`.
|
|
169
206
|
*/
|
|
170
|
-
declare const provider:
|
|
207
|
+
declare const provider: {
|
|
208
|
+
<Name extends string, S extends Schema.Codec<any, any, never, any>, Provider extends string, Config>(spec: Omit<ProviderTool<Name, S["Type"], Provider, Config>, "_tag" | "inputSchema"> & {
|
|
209
|
+
readonly inputSchema: S;
|
|
210
|
+
}): ProviderTool<Name, S["Type"], Provider, Config>;
|
|
211
|
+
<Name extends string, Input, Provider extends string, Config>(spec: Omit<ProviderTool<Name, Input, Provider, Config>, "_tag">): ProviderTool<Name, Input, Provider, Config>;
|
|
212
|
+
};
|
|
171
213
|
/**
|
|
172
214
|
* A typed control-flow signal to the agent loop (escalate, pause, schedule,
|
|
173
215
|
* hand off). Decode-only: the loop interprets the call rather than executing a
|
|
174
216
|
* handler, so there is no `run`.
|
|
175
217
|
*/
|
|
176
|
-
declare const signal:
|
|
218
|
+
declare const signal: {
|
|
219
|
+
<Name extends string, S extends Schema.Codec<any, any, never, any>>(spec: Omit<SignalTool<Name, S["Type"]>, "_tag" | "inputSchema"> & {
|
|
220
|
+
readonly inputSchema: S;
|
|
221
|
+
}): SignalTool<Name, S["Type"]>;
|
|
222
|
+
<Name extends string, Input>(spec: Omit<SignalTool<Name, Input>, "_tag">): SignalTool<Name, Input>;
|
|
223
|
+
};
|
|
177
224
|
/**
|
|
178
225
|
* A typed request for an external actor to respond before the loop resumes
|
|
179
226
|
* (frontend, Telegram, CLI prompt). Decode-only; the loop stops/pauses and
|
|
180
227
|
* resumes by appending the actor's `function_call_output`.
|
|
181
228
|
*/
|
|
182
|
-
declare const interaction:
|
|
229
|
+
declare const interaction: {
|
|
230
|
+
<Name extends string, S extends Schema.Codec<any, any, never, any>>(spec: Omit<InteractionTool<Name, S["Type"]>, "_tag" | "inputSchema"> & {
|
|
231
|
+
readonly inputSchema: S;
|
|
232
|
+
}): InteractionTool<Name, S["Type"]>;
|
|
233
|
+
<Name extends string, Input>(spec: Omit<InteractionTool<Name, Input>, "_tag">): InteractionTool<Name, Input>;
|
|
234
|
+
};
|
|
183
235
|
/**
|
|
184
236
|
* Return a copy of a tool under a new `name`. Useful for resolving a name
|
|
185
237
|
* clash before combining tools into one `Toolkit`. Literal-preserving, so the
|
|
@@ -199,8 +251,21 @@ declare const withName: <N extends string, T extends AnyTool>(tool: T, name: N)
|
|
|
199
251
|
* Descriptors stay identical to production, so a mocked toolkit can't drift
|
|
200
252
|
* from the contract the model sees.
|
|
201
253
|
*/
|
|
202
|
-
declare const withRun: <Name extends string, Input, Event, Output, R, Output2, R2 = never>(tool: Tool<Name, Input, Event, Output, R>, run: (input: Input, emit: Emit<Event>) => Effect.Effect<Output2,
|
|
203
|
-
/**
|
|
254
|
+
declare const withRun: <Name extends string, Input, Event, Output, E, R, Output2, E2 = never, R2 = never>(tool: Tool<Name, Input, Event, Output, E, R>, run: (input: Input, emit: Emit<Event>) => Effect.Effect<Output2, E2, R2>) => Tool<Name, Input, Event, Output2, E2, R2>;
|
|
255
|
+
/** True for provider-hosted tools — the kind a provider renders natively. */
|
|
256
|
+
declare const isProviderTool: (tool: AnyTool) => tool is ProviderTool<string, any, string, any>;
|
|
257
|
+
/**
|
|
258
|
+
* The `ProviderTool`s in a toolkit, for a provider adapter to render as its
|
|
259
|
+
* native hosted-tool entries (web search, code execution, grounding). The other
|
|
260
|
+
* kinds render as function declarations via `descriptorsOf`.
|
|
261
|
+
*/
|
|
262
|
+
declare const providerToolsOf: (toolkit?: Readonly<Record<string, AnyTool>>) => ReadonlyArray<ProviderTool<string, any, string, any>>;
|
|
263
|
+
/**
|
|
264
|
+
* Render tools to provider-agnostic descriptors. `ProviderTool`s are excluded:
|
|
265
|
+
* they are provider-hosted and must never leak into the function-declaration
|
|
266
|
+
* list — each adapter renders them natively via `providerToolsOf`. Every other
|
|
267
|
+
* kind is model-visible as a declaration.
|
|
268
|
+
*/
|
|
204
269
|
declare const toDescriptors: (tools: ReadonlyArray<AnyTool>) => ReadonlyArray<ToolDescriptor>;
|
|
205
270
|
/**
|
|
206
271
|
* Render a `Toolkit` (a name-indexed record of tools) to descriptors, treating
|
|
@@ -210,6 +275,26 @@ declare const toDescriptors: (tools: ReadonlyArray<AnyTool>) => ReadonlyArray<To
|
|
|
210
275
|
* free of a dependency on the toolkit module — it only needs the tool values.
|
|
211
276
|
*/
|
|
212
277
|
declare const descriptorsOf: (toolkit?: Readonly<Record<string, AnyTool>>) => ReadonlyArray<ToolDescriptor>;
|
|
278
|
+
/**
|
|
279
|
+
* Outcome of decoding a call's `arguments` against a tool's `inputSchema`,
|
|
280
|
+
* as data so both the typed (`decodeArgs`) and result-synthesizing
|
|
281
|
+
* (`Toolkit.run`) callers can translate it their own way.
|
|
282
|
+
*/
|
|
283
|
+
type DecodeResult<Input> = {
|
|
284
|
+
readonly _tag: "ok";
|
|
285
|
+
readonly input: Input;
|
|
286
|
+
} | {
|
|
287
|
+
readonly _tag: "parseError";
|
|
288
|
+
} | {
|
|
289
|
+
readonly _tag: "invalid";
|
|
290
|
+
readonly issues: ReadonlyArray<StandardSchemaV1.Issue>;
|
|
291
|
+
};
|
|
292
|
+
/**
|
|
293
|
+
* Parse and validate a call's `arguments`. Empty arguments normalize to
|
|
294
|
+
* `{}` (some models emit `""` for zero-arg tools); a throwing validator is
|
|
295
|
+
* captured, not propagated. Never fails.
|
|
296
|
+
*/
|
|
297
|
+
declare const decodeCallInput: <Input>(tool: DecodableTool<Input>, call: ToolCall) => Effect.Effect<DecodeResult<Input>>;
|
|
213
298
|
/**
|
|
214
299
|
* Decode and validate a function_call's JSON `arguments` against the tool's
|
|
215
300
|
* own `inputSchema`, yielding the typed input. The decode-only half of
|
|
@@ -226,7 +311,7 @@ declare const decodeArgs: <Input>(tool: DecodableTool<Input>, call: ToolCall) =>
|
|
|
226
311
|
* function_call_output item. Single-shot: intermediate events emitted by
|
|
227
312
|
* `run` are discarded (use `Toolkit.run` to stream them).
|
|
228
313
|
*/
|
|
229
|
-
declare const execute: <Name extends string, Input, Event, Output, R>(tool: Tool<Name, Input, Event, Output, R>, call: ToolCall) => Effect.Effect<ToolCallOutput, ToolError | ToolValidationError, R>;
|
|
314
|
+
declare const execute: <Name extends string, Input, Event, Output, E, R>(tool: Tool<Name, Input, Event, Output, E, R>, call: ToolCall) => Effect.Effect<ToolCallOutput, E | ToolError | ToolValidationError, R>;
|
|
230
315
|
//#endregion
|
|
231
|
-
export {
|
|
232
|
-
//# sourceMappingURL=Tool-
|
|
316
|
+
export { providerToolsOf as A, fromEffectSchema as C, make as D, isProviderTool as E, toDescriptors as M, withName as N, noInput as O, withRun as P, fail as S, interaction as T, Tool_d_exports as _, Emit as a, descriptorsOf as b, SignalTool as c, ToolE as d, ToolError as f, ToolValidationError as g, ToolR as h, DecodeResult as i, signal as j, provider as k, Tool as l, ToolInputSchema as m, AnyTool as n, InteractionTool as o, ToolFailed as p, DecodableTool as r, ProviderTool as s, AnyLocalTool as t, ToolDescriptor as u, decodeArgs as v, fromStandardSchema as w, execute as x, decodeCallInput as y };
|
|
317
|
+
//# sourceMappingURL=Tool-CXFHCQrT.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Tool-CXFHCQrT.d.mts","names":[],"sources":["../src/tool/Tool.ts"],"mappings":";;;;;;;;;cAEkE,cAAA;;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A,CAAO,cAAA,EAAgB,CAAA,GAAI,SAAA,GAAY,mBAAA,EAAqB,CAAA"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as ToolResult } from "./ToolResult-
|
|
1
|
+
import { t as ToolResult } from "./ToolResult-CQqKkcDa.mjs";
|
|
2
2
|
import { Data } from "effect";
|
|
3
3
|
import * as _$effect_Unify0 from "effect/Unify";
|
|
4
4
|
|
|
@@ -148,4 +148,4 @@ declare const isOutput: (u: unknown) => u is {
|
|
|
148
148
|
};
|
|
149
149
|
//#endregion
|
|
150
150
|
export { isProgress as a, isOutput as i, ToolEvent_d_exports as n, isApprovalRequested as r, ToolEvent as t };
|
|
151
|
-
//# sourceMappingURL=ToolEvent-
|
|
151
|
+
//# sourceMappingURL=ToolEvent-nVijCrvm.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ToolEvent-nVijCrvm.d.mts","names":[],"sources":["../src/tool/ToolEvent.ts"],"mappings":";;;;;;;;KAkBY,SAAA,GAAY,IAAA,CAAK,UAAA;EAC3B,iBAAA;IAAA,SACW,OAAA;IAAA,SACA,IAAA;IAAA,SACA,SAAA;EAAA;EAEX,QAAA;IAAA,SACW,OAAA;IAAA,SACA,IAAA;IAAA,SACA,IAAA;EAAA;EAEX,MAAA;IAAA,SACW,MAAA,EAAQ,UAAA;EAAA;AAAA;;;;;;;;cAWR,SAAA;EAAA;;;;;;;;;;;;;;qBAXQ,UAAA;EAAA;EAAA;;;;;;;;;;;;;;;;qBAAA,UAAA;EAAA;IAAA;;;;;;;;;;;;;;;;;;yBAAA,UAAA;MAAA;IAAA;;;;;;;;;;;;uBAAA,UAAA;IAAA;;;;;;;;;;;;;;;;yBAAA,UAAA;MAAA;IAAA;;;;;;;;;;;;uBAAA,UAAA;IAAA;;;cAaR,mBAAA,GAAmB,CAAA,cAAA,CAAA;EAAA;;;;;cACnB,UAAA,GAAU,CAAA,cAAA,CAAA;EAAA;;;;;cACV,QAAA,GAAQ,CAAA,cAAA,CAAA;EAAA;mBAfA,UAAA;AAAA"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { v as ToolCall, y as ToolCallOutput } from "./Items-
|
|
1
|
+
import { v as ToolCall, y as ToolCallOutput } from "./Items-BWNu6VGp.mjs";
|
|
2
2
|
import { Data } from "effect";
|
|
3
3
|
import * as _$effect_Unify0 from "effect/Unify";
|
|
4
4
|
|
|
5
5
|
//#region src/tool/ToolResult.d.ts
|
|
6
6
|
declare namespace ToolResult_d_exports {
|
|
7
|
-
export { ToolResult, cancelled, denied, executionError, failed, isFailure, isOk, nonLocalTool, toToolCallOutput, validationError };
|
|
7
|
+
export { ToolResult, cancelled, denied, executionError, failed, isFailure, isOk, nonLocalTool, serializeValue, toToolCallOutput, validationError };
|
|
8
8
|
}
|
|
9
9
|
type ToolResult = Data.TaggedEnum<{
|
|
10
10
|
Ok: {
|
|
@@ -145,7 +145,13 @@ declare const nonLocalTool: (call: ToolCall, reason?: string) => ToolResult;
|
|
|
145
145
|
* runtime crash.
|
|
146
146
|
*/
|
|
147
147
|
declare const validationError: (call: ToolCall, reason?: string) => ToolResult;
|
|
148
|
+
/**
|
|
149
|
+
* Serialize a success value for the wire. A `string` passes through raw
|
|
150
|
+
* (models read plain text best; JSON.stringify would quote and escape it);
|
|
151
|
+
* `undefined` becomes `"null"`; anything else is JSON.
|
|
152
|
+
*/
|
|
153
|
+
declare const serializeValue: (value: unknown) => string;
|
|
148
154
|
declare const toToolCallOutput: (r: ToolResult) => ToolCallOutput;
|
|
149
155
|
//#endregion
|
|
150
|
-
export { executionError as a, isOk as c,
|
|
151
|
-
//# sourceMappingURL=ToolResult-
|
|
156
|
+
export { executionError as a, isOk as c, toToolCallOutput as d, validationError as f, denied as i, nonLocalTool as l, ToolResult_d_exports as n, failed as o, cancelled as r, isFailure as s, ToolResult as t, serializeValue as u };
|
|
157
|
+
//# sourceMappingURL=ToolResult-CQqKkcDa.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ToolResult-CQqKkcDa.d.mts","names":[],"sources":["../src/tool/ToolResult.ts"],"mappings":";;;;;;;;KAqBY,UAAA,GAAa,IAAA,CAAK,UAAA;EAC5B,EAAA;IAAA,SACW,OAAA;IAAA,SACA,IAAA;IAAA,SACA,KAAA;EAAA;EAEX,OAAA;IAAA,SACW,OAAA;IAAA,SACA,IAAA;IAAA,SACA,IAAA;IAAA,SACA,MAAA;EAAA;AAAA;;;;;;;;;cAYA,UAAA;EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAEA,IAAA,GAAI,CAAA,cAAA,CAAA;EAAA;;;;;cACJ,SAAA,GAAS,CAAA,cAAA,CAAA;EAAA;;;;;;cAMT,MAAA,GAAU,IAAA,EAAM,QAAA,EAAU,IAAA,UAAc,MAAA,cAAkB,UAAA;;cAS1D,MAAA,GAAU,IAAA,EAAM,QAAA,EAAU,MAAA,cAAkB,UAAA;;cAI5C,SAAA,GAAa,IAAA,EAAM,QAAA,EAAU,MAAA,cAAkB,UAAA;;cAI/C,cAAA,GAAkB,IAAA,EAAM,QAAA,EAAU,MAAA,aAAiB,UAAA;;;;;;;cASnD,YAAA,GAAgB,IAAA,EAAM,QAAA,EAAU,MAAA,cAAkB,UAAA;;;;;;cAYlD,eAAA,GAAmB,IAAA,EAAM,QAAA,EAAU,MAAA,cAAkB,UAAA;;AA7ClE;;;;cAyDa,cAAA,GAAkB,KAAA;AAAA,cAOlB,gBAAA,GAAoB,CAAA,EAAG,UAAA,KAAa,cAAA"}
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import { o as HistoryItem, v as ToolCall } from "./Items-
|
|
1
|
+
import { o as HistoryItem, v as ToolCall } from "./Items-BWNu6VGp.mjs";
|
|
2
|
+
import { a as Emit, c as SignalTool, d as ToolE, h as ToolR, l as Tool, n as AnyTool, o as InteractionTool, p as ToolFailed, s as ProviderTool, u as ToolDescriptor } from "./Tool-CXFHCQrT.mjs";
|
|
2
3
|
import { Turn } from "./domain/Turn.mjs";
|
|
3
|
-
import { r as Step } from "./Loop-
|
|
4
|
-
import {
|
|
5
|
-
import { t as
|
|
6
|
-
import { t as ToolEvent } from "./ToolEvent-DYrAUJGs.mjs";
|
|
4
|
+
import { r as Step } from "./Loop-D8nWpowc.mjs";
|
|
5
|
+
import { t as ToolResult } from "./ToolResult-CQqKkcDa.mjs";
|
|
6
|
+
import { t as ToolEvent } from "./ToolEvent-nVijCrvm.mjs";
|
|
7
7
|
import { Cause, Effect, Stream } from "effect";
|
|
8
8
|
import * as _$effect_Types0 from "effect/Types";
|
|
9
9
|
|
|
10
10
|
//#region src/tool/Toolkit.d.ts
|
|
11
11
|
declare namespace Toolkit_d_exports {
|
|
12
|
-
export { DuplicateToolName, ExecuteOptions, Middleware, NoDuplicateNames, ToolMap, Toolkit, ToolkitR, UniqueTools, appendToolResults, collectResults, compose, continueWithResults, descriptors, fromArray, make, makeNamespaced, namespace, run, wrap };
|
|
12
|
+
export { DuplicateToolName, ExecuteOptions, Middleware, NoDuplicateNames, ToolMap, Toolkit, ToolkitE, ToolkitR, UniqueTools, appendToolResults, collectResults, compose, continueWithResults, describeFailures, descriptors, fromArray, make, makeNamespaced, namespace, run, wrap };
|
|
13
13
|
}
|
|
14
14
|
type ToolMap = Record<string, AnyTool>;
|
|
15
15
|
type Toolkit<Tools extends ToolMap = ToolMap> = Tools;
|
|
@@ -33,6 +33,14 @@ declare const descriptors: (toolkit: Toolkit) => ReadonlyArray<ToolDescriptor>;
|
|
|
33
33
|
* resulting stream's `R`. Concrete toolkits from `make` keep their precise R.
|
|
34
34
|
*/
|
|
35
35
|
type ToolkitR<T extends Toolkit> = ToolMap extends T ? never : ToolR<T[keyof T]>;
|
|
36
|
+
/**
|
|
37
|
+
* Union of every tool's `E` error type in a toolkit. `Toolkit.run` reports
|
|
38
|
+
* `Exclude<ToolkitE<T>, string | ToolFailed>` on its stream: the sentinel
|
|
39
|
+
* failures are absorbed into results, everything else propagates typed. The
|
|
40
|
+
* same `ToolMap extends T` guard as `ToolkitR` keeps a wide toolkit at
|
|
41
|
+
* `never` rather than `any`.
|
|
42
|
+
*/
|
|
43
|
+
type ToolkitE<T extends Toolkit> = ToolMap extends T ? never : ToolE<T[keyof T]>;
|
|
36
44
|
type DuplicateName<Tools extends ReadonlyArray<AnyTool>, Seen extends string = never> = Tools extends readonly [infer Head extends AnyTool, ...infer Tail extends ReadonlyArray<AnyTool>] ? Head["name"] extends Seen ? Head["name"] : DuplicateName<Tail, Seen | Head["name"]> : never;
|
|
37
45
|
type DuplicateNameError<Name extends string> = {
|
|
38
46
|
readonly __error: `Duplicate tool name: ${Name}`;
|
|
@@ -58,7 +66,7 @@ declare class DuplicateToolName extends DuplicateToolName_base<{
|
|
|
58
66
|
readonly sources: ReadonlyArray<string>;
|
|
59
67
|
}> {}
|
|
60
68
|
type PrefixName<Prefix extends string, Name extends string> = `${Prefix}__${Name}`;
|
|
61
|
-
type PrefixTool<Prefix extends string, T extends AnyTool> = T extends Tool<infer N, infer I, infer Ev, infer O, infer R> ? Tool<PrefixName<Prefix, N>, I, Ev, O, R> : T extends ProviderTool<infer N, infer I, infer P, infer C> ? ProviderTool<PrefixName<Prefix, N>, I, P, C> : T extends SignalTool<infer N, infer I> ? SignalTool<PrefixName<Prefix, N>, I> : T extends InteractionTool<infer N, infer I> ? InteractionTool<PrefixName<Prefix, N>, I> : T;
|
|
69
|
+
type PrefixTool<Prefix extends string, T extends AnyTool> = T extends Tool<infer N, infer I, infer Ev, infer O, infer E, infer R> ? Tool<PrefixName<Prefix, N>, I, Ev, O, E, R> : T extends ProviderTool<infer N, infer I, infer P, infer C> ? ProviderTool<PrefixName<Prefix, N>, I, P, C> : T extends SignalTool<infer N, infer I> ? SignalTool<PrefixName<Prefix, N>, I> : T extends InteractionTool<infer N, infer I> ? InteractionTool<PrefixName<Prefix, N>, I> : T;
|
|
62
70
|
type Namespaced<Prefix extends string, T extends ToolMap> = { readonly [K in keyof T & string as PrefixName<Prefix, K>]: T[K] extends AnyTool ? PrefixTool<Prefix, T[K]> : never };
|
|
63
71
|
/**
|
|
64
72
|
* Prefix every tool name with `<namespace>__`, returning a new toolkit. Use it
|
|
@@ -77,32 +85,65 @@ declare const makeNamespaced: <const Prefix extends string, const Tools extends
|
|
|
77
85
|
* provider. Statically-known collisions are additionally a compile error.
|
|
78
86
|
*/
|
|
79
87
|
declare const compose: <const Kits extends ReadonlyArray<Toolkit>>(...toolkits: Kits & NoDuplicateComposedKeys<Kits>) => Effect.Effect<Toolkit<Composed<Kits>>, DuplicateToolName>;
|
|
80
|
-
type Handler<Input, Event, Output, R> = (input: Input, emit: Emit<Event>) => Effect.Effect<Output,
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
88
|
+
type Handler<Input, Event, Output, E, R> = (input: Input, emit: Emit<Event>) => Effect.Effect<Output, E, R>;
|
|
89
|
+
/**
|
|
90
|
+
* A `run` transform, tracking an added requirement `R2` and optional added
|
|
91
|
+
* error `E2`. The tool's own `E` is preserved; `describeFailures` is the
|
|
92
|
+
* combinator that *replaces* it (mapping every error to `string`).
|
|
93
|
+
*/
|
|
94
|
+
type Middleware<R2 = never, E2 = never> = <Input, Event, Output, E, R>(run: Handler<Input, Event, Output, E, R>, name: string) => Handler<Input, Event, Output, E | E2, R | R2>;
|
|
95
|
+
type WrapTool<T extends AnyTool, R2, E2> = T extends Tool<infer N, infer I, infer Ev, infer O, infer E, infer R> ? Tool<N, I, Ev, O, E | E2, R | R2> : T;
|
|
96
|
+
type WrapToolkit<T extends ToolMap, R2, E2> = { readonly [K in keyof T]: T[K] extends AnyTool ? WrapTool<T[K], R2, E2> : T[K] };
|
|
84
97
|
/**
|
|
85
98
|
* Wrap every local tool's `run` with a middleware, preserving each tool's
|
|
86
99
|
* `Input`/`Output` and unioning the middleware's requirement `R2` into the
|
|
87
100
|
* toolkit's `ToolkitR`. Non-local kinds pass through unchanged. Stack with
|
|
88
|
-
* `pipe
|
|
101
|
+
* `pipe` - inner-first, so the last `wrap` applied is the outermost and runs
|
|
102
|
+
* first:
|
|
89
103
|
*
|
|
90
104
|
* const observed = pipe(toolkit, Toolkit.wrap(logging), Toolkit.wrap(authz))
|
|
91
|
-
* Toolkit.run(observed, calls) //
|
|
105
|
+
* Toolkit.run(observed, calls) // authz runs, then logging, then the tool
|
|
92
106
|
*
|
|
93
|
-
* A middleware that `
|
|
94
|
-
* executor
|
|
95
|
-
* "
|
|
107
|
+
* A middleware that fails with `string` / `ToolFailed` is absorbed by the
|
|
108
|
+
* executor into a `ToolResult.Failure`; any other error propagates typed. Use
|
|
109
|
+
* `describeFailures` for the total "everything to the model" case, or the
|
|
110
|
+
* `Approval` flow for a distinct "denied" verdict.
|
|
96
111
|
*/
|
|
97
112
|
declare const wrap: {
|
|
98
|
-
<R2>(middleware: Middleware<R2>): <T extends Toolkit>(toolkit: T) => WrapToolkit<T, R2>;
|
|
99
|
-
<T extends Toolkit, R2>(toolkit: T, middleware: Middleware<R2>): WrapToolkit<T, R2>;
|
|
113
|
+
<R2, E2>(middleware: Middleware<R2, E2>): <T extends Toolkit>(toolkit: T) => WrapToolkit<T, R2, E2>;
|
|
114
|
+
<T extends Toolkit, R2, E2>(toolkit: T, middleware: Middleware<R2, E2>): WrapToolkit<T, R2, E2>;
|
|
115
|
+
};
|
|
116
|
+
type DescribeTool<T extends AnyTool> = T extends Tool<infer N, infer I, infer Ev, infer O, any, infer R> ? Tool<N, I, Ev, O, string, R> : T;
|
|
117
|
+
type DescribeToolkit<T extends ToolMap> = { readonly [K in keyof T]: T[K] extends AnyTool ? DescribeTool<T[K]> : T[K] };
|
|
118
|
+
/**
|
|
119
|
+
* Map every local tool's error to a `string`, so `Toolkit.run` absorbs those
|
|
120
|
+
* failures into `ToolResult.Failure` the model reads and adapts to. Pairs
|
|
121
|
+
* with the domain `describe` helpers (`AiError.describe`,
|
|
122
|
+
* `BrowserError.describe`). Non-local kinds pass through.
|
|
123
|
+
*
|
|
124
|
+
* const kit = yield* Toolkit.compose(
|
|
125
|
+
* Toolkit.describeFailures(searchKit, AiError.describe),
|
|
126
|
+
* browserToolkit(session), // failures stay typed
|
|
127
|
+
* )
|
|
128
|
+
*/
|
|
129
|
+
declare const describeFailures: {
|
|
130
|
+
<E>(describe: (e: E) => string): <T extends Toolkit>(toolkit: T) => DescribeToolkit<T>;
|
|
131
|
+
<T extends Toolkit>(toolkit: T, describe: (e: ToolkitE<T>) => string): DescribeToolkit<T>;
|
|
100
132
|
};
|
|
101
133
|
type ExecuteOptions = {
|
|
102
134
|
readonly concurrency?: number | "unbounded";
|
|
103
135
|
};
|
|
104
|
-
/**
|
|
105
|
-
|
|
136
|
+
/**
|
|
137
|
+
* Execute every provided call. Approval/rejection policy belongs upstream.
|
|
138
|
+
*
|
|
139
|
+
* String and `ToolFailed` failures are absorbed into `ToolResult.Failure`
|
|
140
|
+
* (the model reads and adapts to them); every other tool error propagates
|
|
141
|
+
* typed on the stream, so `Exclude<ToolkitE<T>, string | ToolFailed>` is
|
|
142
|
+
* what a caller catches or lets end the run. If one call in a concurrent
|
|
143
|
+
* batch fails the stream, siblings may go unanswered: a loop that catches
|
|
144
|
+
* and continues must reconcile history first (`HistoryCheck.cancelAllPending`).
|
|
145
|
+
*/
|
|
146
|
+
declare const run: <T extends Toolkit>(toolkit: T, calls: ReadonlyArray<ToolCall>, options?: ExecuteOptions) => Stream.Stream<ToolEvent, Exclude<ToolkitE<T>, string | ToolFailed>, ToolkitR<T>>;
|
|
106
147
|
/**
|
|
107
148
|
* Append a completed turn plus tool results to a state's history, converting
|
|
108
149
|
* the results to wire-format `ToolCallOutput`s. Curried so it slots directly
|
|
@@ -147,9 +188,9 @@ declare const collectResults: <E, R>(stream: Stream.Stream<ToolEvent, E, R>) =>
|
|
|
147
188
|
* `stream.pipe(continueWithResults(build))` both work.
|
|
148
189
|
*/
|
|
149
190
|
declare const continueWithResults: {
|
|
150
|
-
<S>(build: (results: ReadonlyArray<ToolResult>) => S): <R>(stream: Stream.Stream<ToolEvent,
|
|
151
|
-
<S, R>(stream: Stream.Stream<ToolEvent,
|
|
191
|
+
<S>(build: (results: ReadonlyArray<ToolResult>) => S): <E, R>(stream: Stream.Stream<ToolEvent, E, R>) => Stream.Stream<Step<ToolEvent, S>, E, R>;
|
|
192
|
+
<S, E, R>(stream: Stream.Stream<ToolEvent, E, R>, build: (results: ReadonlyArray<ToolResult>) => S): Stream.Stream<Step<ToolEvent, S>, E, R>;
|
|
152
193
|
};
|
|
153
194
|
//#endregion
|
|
154
|
-
export {
|
|
155
|
-
//# sourceMappingURL=Toolkit-
|
|
195
|
+
export { wrap as S, fromArray as _, ToolMap as a, namespace as b, ToolkitR as c, appendToolResults as d, collectResults as f, descriptors as g, describeFailures as h, NoDuplicateNames as i, Toolkit_d_exports as l, continueWithResults as m, ExecuteOptions as n, Toolkit as o, compose as p, Middleware as r, ToolkitE as s, DuplicateToolName as t, UniqueTools as u, make as v, run as x, makeNamespaced as y };
|
|
196
|
+
//# sourceMappingURL=Toolkit-BYPwwu-j.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Toolkit-BYPwwu-j.d.mts","names":[],"sources":["../src/tool/Toolkit.ts"],"mappings":";;;;;;;;;;;;;KAqDY,OAAA,GAAU,MAAA,SAAe,OAAA;AAAA,KAEzB,OAAA,eAAsB,OAAA,GAAU,OAAA,IAAW,KAAA;AAAA,cAgB1C,IAAA,uBAA4B,aAAA,CAAc,OAAA,MAClD,KAAA,EAAO,WAAA,CAAY,KAAA,MACrB,OAAA,SAAgB,KAAA,YAAiB,CAAA,WAAY,CAAA;;;;;;;cAQnC,SAAA,GAAa,KAAA,EAAO,aAAA,CAAc,OAAA,MAAW,OAAA;;cAG7C,WAAA,GAAe,OAAA,EAAS,OAAA,KAAU,aAAA,CAAc,cAAA;;;;;;;;;;KAYjD,QAAA,WAAmB,OAAA,IAAW,O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A,GAAI,CAAA,EAAG,CAAA;EAAA,UAE7F,MAAA,EAAQ,MAAA,CAAO,MAAA,CAAO,SAAA,EAAW,CAAA,EAAG,CAAA,GACpC,KAAA,GAAQ,OAAA,EAAS,aAAA,CAAc,UAAA,MAAgB,CAAA,GAC9C,MAAA,CAAO,MAAA,CAAO,IAAA,CAAU,SAAA,EAAW,CAAA,GAAI,CAAA,EAAG,CAAA;AAAA"}
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
import { BrowserError } from "./BrowserError.mjs";
|
|
2
|
+
import { Brand, Context, Duration, Effect, Scope } from "effect";
|
|
3
|
+
|
|
4
|
+
//#region src/browser/Browser.d.ts
|
|
5
|
+
declare namespace Browser_d_exports {
|
|
6
|
+
export { AxNode, BoundingBox, Browser, BrowserService, BrowserSession, BrowserSessionId, BrowserSessionRef, CommonSessionRequest, Cookie, CookieApi, ElementInfo, PageFormat, ScreenshotOptions, ScrollDirection, ScrollOptions, attach, create, destroy, list };
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Session identifier. Branded `string` so providers don't accidentally
|
|
10
|
+
* accept a raw user-supplied id, and so a session id can't be passed where
|
|
11
|
+
* another service's id is expected. Each provider mints these per its own
|
|
12
|
+
* scheme; core code treats them opaquely. Mint via `BrowserSessionId(...)`.
|
|
13
|
+
*/
|
|
14
|
+
type BrowserSessionId = Brand.Branded<string, "BrowserSessionId">;
|
|
15
|
+
declare const BrowserSessionId: Brand.Constructor<BrowserSessionId>;
|
|
16
|
+
/** Reference returned by `list`; enough to `attach`. */
|
|
17
|
+
type BrowserSessionRef = {
|
|
18
|
+
readonly id: BrowserSessionId; /** Current top-level URL, when the provider reports it. */
|
|
19
|
+
readonly url?: string;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Output representation for {@link BrowserSession.content}. `markdown` is
|
|
23
|
+
* the default.
|
|
24
|
+
*/
|
|
25
|
+
type PageFormat = "markdown" | "html";
|
|
26
|
+
/**
|
|
27
|
+
* Cross-provider session-create request. Provider-specific knobs (proxy,
|
|
28
|
+
* stealth, persistent profile, ...) live on each provider's narrowed
|
|
29
|
+
* request type which extends this.
|
|
30
|
+
*/
|
|
31
|
+
type CommonSessionRequest = {
|
|
32
|
+
/**
|
|
33
|
+
* Hard max lifetime of the session. Enforced locally (the handle is
|
|
34
|
+
* disposed and further calls fail with `BrowserSessionExpired`) and,
|
|
35
|
+
* where the provider supports it, passed through as a server-side cap so
|
|
36
|
+
* a crashed client still gets the session reclaimed. The provider cap
|
|
37
|
+
* must be >= the local reaper. Accepts millis, a string like
|
|
38
|
+
* `"5 minutes"`, or a `Duration`.
|
|
39
|
+
*/
|
|
40
|
+
readonly timeout?: Duration.Input;
|
|
41
|
+
/**
|
|
42
|
+
* Idle teardown: dispose the session after this much inactivity, the
|
|
43
|
+
* timer resetting on each operation. Opt-in; omit for no idle limit.
|
|
44
|
+
*/
|
|
45
|
+
readonly idleTimeout?: Duration.Input; /** Initial viewport size. Providers default differently. */
|
|
46
|
+
readonly viewport?: {
|
|
47
|
+
readonly width: number;
|
|
48
|
+
readonly height: number;
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
type BoundingBox = {
|
|
52
|
+
readonly x: number;
|
|
53
|
+
readonly y: number;
|
|
54
|
+
readonly width: number;
|
|
55
|
+
readonly height: number;
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* One element returned by {@link BrowserSession.query}. Serializable data,
|
|
59
|
+
* not a live handle (handles go stale across navigation and do not cross a
|
|
60
|
+
* provider boundary cleanly).
|
|
61
|
+
*/
|
|
62
|
+
type ElementInfo = {
|
|
63
|
+
/**
|
|
64
|
+
* Reference usable as a selector for a follow-up action. Valid until the
|
|
65
|
+
* next navigation; do not cache across `goto` or a page-changing click.
|
|
66
|
+
*/
|
|
67
|
+
readonly ref: string;
|
|
68
|
+
readonly tag: string;
|
|
69
|
+
readonly text?: string;
|
|
70
|
+
readonly attributes: Readonly<Record<string, string>>;
|
|
71
|
+
readonly box?: BoundingBox;
|
|
72
|
+
};
|
|
73
|
+
/** Accessibility-tree node returned by {@link BrowserSession.snapshot}. */
|
|
74
|
+
type AxNode = {
|
|
75
|
+
readonly role: string;
|
|
76
|
+
readonly name?: string;
|
|
77
|
+
readonly value?: string;
|
|
78
|
+
/**
|
|
79
|
+
* Reference usable as a selector for a follow-up action. Valid until the
|
|
80
|
+
* next navigation; do not cache across `goto` or a page-changing click.
|
|
81
|
+
*/
|
|
82
|
+
readonly ref?: string;
|
|
83
|
+
readonly children: ReadonlyArray<AxNode>;
|
|
84
|
+
};
|
|
85
|
+
type ScrollDirection = "up" | "down" | "left" | "right";
|
|
86
|
+
type ScrollOptions = {
|
|
87
|
+
readonly direction: ScrollDirection; /** Distance in CSS pixels. Provider default applies when omitted. */
|
|
88
|
+
readonly pixels?: number;
|
|
89
|
+
};
|
|
90
|
+
type ScreenshotOptions = {
|
|
91
|
+
/** Clip to the first element matching this selector. */readonly selector?: string; /** Capture the full scrollable page rather than the viewport. */
|
|
92
|
+
readonly fullPage?: boolean;
|
|
93
|
+
};
|
|
94
|
+
type Cookie = {
|
|
95
|
+
readonly name: string;
|
|
96
|
+
readonly value: string;
|
|
97
|
+
readonly domain?: string;
|
|
98
|
+
readonly path?: string;
|
|
99
|
+
readonly expires?: number;
|
|
100
|
+
readonly httpOnly?: boolean;
|
|
101
|
+
readonly secure?: boolean;
|
|
102
|
+
readonly sameSite?: "Strict" | "Lax" | "None";
|
|
103
|
+
};
|
|
104
|
+
/** Read / write the session's cookie jar. Needed for authenticated flows. */
|
|
105
|
+
type CookieApi = {
|
|
106
|
+
readonly get: Effect.Effect<ReadonlyArray<Cookie>, BrowserError>;
|
|
107
|
+
readonly set: (cookies: ReadonlyArray<Cookie>) => Effect.Effect<void, BrowserError>;
|
|
108
|
+
};
|
|
109
|
+
/**
|
|
110
|
+
* Live session handle. Actions take a CSS selector string (so `#id` is
|
|
111
|
+
* just `#id`). Methods are plain `Effect` values; disposal is the scope
|
|
112
|
+
* finalizer, not a method here (see {@link BrowserService}). Anything not
|
|
113
|
+
* covered by a verb is reachable via `evaluate`. Per-operation time budgets
|
|
114
|
+
* are the provider's default; wrap any call in `Effect.timeout` for a
|
|
115
|
+
* tighter bound.
|
|
116
|
+
*/
|
|
117
|
+
type BrowserSession = {
|
|
118
|
+
readonly id: BrowserSessionId;
|
|
119
|
+
readonly goto: (url: string) => Effect.Effect<void, BrowserError>;
|
|
120
|
+
readonly waitFor: (selector: string) => Effect.Effect<void, BrowserError>;
|
|
121
|
+
readonly click: (selector: string) => Effect.Effect<void, BrowserError>;
|
|
122
|
+
readonly dblclick: (selector: string) => Effect.Effect<void, BrowserError>;
|
|
123
|
+
readonly fill: (selector: string, text: string) => Effect.Effect<void, BrowserError>;
|
|
124
|
+
readonly type: (selector: string, text: string) => Effect.Effect<void, BrowserError>;
|
|
125
|
+
readonly press: (key: string) => Effect.Effect<void, BrowserError>;
|
|
126
|
+
readonly hover: (selector: string) => Effect.Effect<void, BrowserError>;
|
|
127
|
+
readonly focus: (selector: string) => Effect.Effect<void, BrowserError>;
|
|
128
|
+
readonly select: (selector: string, value: string) => Effect.Effect<void, BrowserError>;
|
|
129
|
+
readonly check: (selector: string) => Effect.Effect<void, BrowserError>;
|
|
130
|
+
readonly uncheck: (selector: string) => Effect.Effect<void, BrowserError>;
|
|
131
|
+
readonly scroll: (options: ScrollOptions) => Effect.Effect<void, BrowserError>;
|
|
132
|
+
readonly scrollIntoView: (selector: string) => Effect.Effect<void, BrowserError>;
|
|
133
|
+
readonly content: (format?: PageFormat) => Effect.Effect<string, BrowserError>;
|
|
134
|
+
readonly screenshot: (options?: ScreenshotOptions) => Effect.Effect<Uint8Array, BrowserError>;
|
|
135
|
+
readonly snapshot: Effect.Effect<AxNode, BrowserError>;
|
|
136
|
+
readonly query: (selector: string) => Effect.Effect<ReadonlyArray<ElementInfo>, BrowserError>;
|
|
137
|
+
readonly cookies: CookieApi;
|
|
138
|
+
readonly evaluate: (script: string) => Effect.Effect<unknown, BrowserError>;
|
|
139
|
+
};
|
|
140
|
+
/**
|
|
141
|
+
* Cross-provider browser service.
|
|
142
|
+
*
|
|
143
|
+
* Lifetime: `create` and `attach` return a handle in `Scope.Scope`. The
|
|
144
|
+
* scope finalizer disposes the session (close the transport, destroy or
|
|
145
|
+
* detach the remote session, kill the local engine). Bind with
|
|
146
|
+
* `Effect.scoped` for a single call, or hold a wider scope to keep a
|
|
147
|
+
* session warm across many calls. This is why there is no `dispose()` on
|
|
148
|
+
* {@link BrowserSession}; the scope is the lifecycle handle.
|
|
149
|
+
*/
|
|
150
|
+
type BrowserService = {
|
|
151
|
+
/**
|
|
152
|
+
* Provision a new session, bound to the caller's scope. Disposed on
|
|
153
|
+
* scope close.
|
|
154
|
+
*/
|
|
155
|
+
readonly create: (request: CommonSessionRequest) => Effect.Effect<BrowserSession, BrowserError, Scope.Scope>;
|
|
156
|
+
/**
|
|
157
|
+
* Re-acquire an existing session by id. Scope-bound, but the finalizer
|
|
158
|
+
* detaches rather than destroying, for sessions kept warm beyond a
|
|
159
|
+
* single run.
|
|
160
|
+
*/
|
|
161
|
+
readonly attach: (id: BrowserSessionId) => Effect.Effect<BrowserSession, BrowserError, Scope.Scope>; /** Enumerate sessions visible to the configured account / project. */
|
|
162
|
+
readonly list: Effect.Effect<ReadonlyArray<BrowserSessionRef>, BrowserError>;
|
|
163
|
+
/**
|
|
164
|
+
* Destroy a session from outside its owning scope. Most callers should
|
|
165
|
+
* let the scope finalizer handle this.
|
|
166
|
+
*/
|
|
167
|
+
readonly destroy: (id: BrowserSessionId) => Effect.Effect<void, BrowserError>;
|
|
168
|
+
};
|
|
169
|
+
declare const Browser_base: Context.ServiceClass<Browser, "@betalyra/effect-uai/Browser", BrowserService>;
|
|
170
|
+
declare class Browser extends Browser_base {}
|
|
171
|
+
/**
|
|
172
|
+
* Provision a session bound to the caller's scope. Drop the `Scope.Scope`
|
|
173
|
+
* requirement with `Effect.scoped`.
|
|
174
|
+
*/
|
|
175
|
+
declare const create: (request: CommonSessionRequest) => Effect.Effect<BrowserSession, BrowserError, Browser | Scope.Scope>;
|
|
176
|
+
/**
|
|
177
|
+
* Re-acquire an existing session by id. Same scope semantics as `create`,
|
|
178
|
+
* but the finalizer detaches rather than destroying.
|
|
179
|
+
*/
|
|
180
|
+
declare const attach: (id: BrowserSessionId) => Effect.Effect<BrowserSession, BrowserError, Browser | Scope.Scope>;
|
|
181
|
+
/** Enumerate sessions for the configured account / project. */
|
|
182
|
+
declare const list: Effect.Effect<ReadonlyArray<BrowserSessionRef>, BrowserError, Browser>;
|
|
183
|
+
/**
|
|
184
|
+
* Destroy a session from outside its owning scope. Most callers should let
|
|
185
|
+
* the scope finalizer handle this automatically.
|
|
186
|
+
*/
|
|
187
|
+
declare const destroy: (id: BrowserSessionId) => Effect.Effect<void, BrowserError, Browser>;
|
|
188
|
+
//#endregion
|
|
189
|
+
export { AxNode, BoundingBox, Browser, BrowserService, BrowserSession, BrowserSessionId, BrowserSessionRef, CommonSessionRequest, Cookie, CookieApi, ElementInfo, PageFormat, ScreenshotOptions, ScrollDirection, ScrollOptions, attach, create, destroy, list, Browser_d_exports as t };
|
|
190
|
+
//# sourceMappingURL=Browser.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Browser.d.mts","names":[],"sources":["../../src/browser/Browser.ts"],"mappings":";;;;;;;;;;;;;KAaY,gBAAA,GAAmB,KAAA,CAAM,OAAA;AAAA,cACxB,gBAAA,EAAgB,KAAA,CAAA,WAAA,CAAA,gBAAA;;KAGjB,iBAAA;EAAA,SACD,EAAA,EAAI,gBAAA;WAEJ,GAAA;AAAA;;;;;KAOC,UAAA;;;;;;KAWA,oBAAA;EAzBgB;;;;AAC5B;;;;EAD4B,SAkCjB,OAAA,GAAU,QAAA,CAAS,KAAA;EAjCD;;;;EAAA,SAsClB,WAAA,GAAc,QAAA,CAAS,KAAA,EAnCL;EAAA,SAqClB,QAAA;IAAA,SAAsB,KAAA;IAA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