@effect-uai/core 0.8.0 → 0.10.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-CAX_48RU.d.mts → AiError-Bf1pq4BB.d.mts} +9 -4
- package/dist/{AiError-CAX_48RU.d.mts.map → AiError-Bf1pq4BB.d.mts.map} +1 -1
- package/dist/{Audio-DPlTsNdz.d.mts → Audio-CR7CSljJ.d.mts} +1 -1
- package/dist/{Audio-DPlTsNdz.d.mts.map → Audio-CR7CSljJ.d.mts.map} +1 -1
- package/dist/{Image-HNmMpMTh.d.mts → Image-BZmKfIdq.d.mts} +1 -1
- package/dist/{Image-HNmMpMTh.d.mts.map → Image-BZmKfIdq.d.mts.map} +1 -1
- package/dist/{Items-7ljaVxH_.d.mts → Items-BnIduEV2.d.mts} +7 -7
- package/dist/{Items-7ljaVxH_.d.mts.map → Items-BnIduEV2.d.mts.map} +1 -1
- package/dist/Loop-D8nWpowc.d.mts +173 -0
- package/dist/Loop-D8nWpowc.d.mts.map +1 -0
- package/dist/{SandboxError-BvKypkJm.d.mts → SandboxError-CIrVDOMV.d.mts} +2 -2
- package/dist/{SandboxError-BvKypkJm.d.mts.map → SandboxError-CIrVDOMV.d.mts.map} +1 -1
- package/dist/{StructuredFormat-BbN4dosH.d.mts → StructuredFormat-DHaUJBdd.d.mts} +2 -2
- package/dist/{StructuredFormat-BbN4dosH.d.mts.map → StructuredFormat-DHaUJBdd.d.mts.map} +1 -1
- package/dist/Tool-2lC_XMth.d.mts +284 -0
- package/dist/Tool-2lC_XMth.d.mts.map +1 -0
- package/dist/ToolEvent-cWZ2BnbS.d.mts +151 -0
- package/dist/ToolEvent-cWZ2BnbS.d.mts.map +1 -0
- package/dist/ToolResult-CL4hK_9z.d.mts +157 -0
- package/dist/ToolResult-CL4hK_9z.d.mts.map +1 -0
- package/dist/Toolkit-Dr9l_hNy.d.mts +196 -0
- package/dist/Toolkit-Dr9l_hNy.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 +58 -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-DV5ISja1.mjs → dist-B04dlFHg.mjs} +3 -3
- package/dist/{dist-DV5ISja1.mjs.map → dist-B04dlFHg.mjs.map} +1 -1
- package/dist/dist-DWgRbDN3.mjs +140 -0
- package/dist/dist-DWgRbDN3.mjs.map +1 -0
- 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/Image.d.mts +1 -1
- package/dist/domain/Items.d.mts +1 -1
- package/dist/domain/Music.d.mts +1 -1
- package/dist/domain/Turn.d.mts +4 -4
- 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.test.mjs +1 -1
- package/dist/embedding-model/EmbeddingModel.test.mjs.map +1 -1
- package/dist/index.d.mts +19 -13
- package/dist/index.mjs +15 -9
- package/dist/language-model/LanguageModel.d.mts +10 -5
- package/dist/language-model/LanguageModel.d.mts.map +1 -1
- package/dist/language-model/LanguageModel.mjs.map +1 -1
- package/dist/language-model/LanguageModel.test.mjs +1 -1
- package/dist/loop/Loop.d.mts +2 -141
- package/dist/loop/Loop.mjs +16 -20
- package/dist/loop/Loop.mjs.map +1 -1
- package/dist/loop/Loop.test.mjs +18 -1
- package/dist/loop/Loop.test.mjs.map +1 -1
- package/dist/{magic-string.es-BgIV5Mu3.mjs → magic-string.es-Dk-MMA0F.mjs} +1 -1
- package/dist/{magic-string.es-BgIV5Mu3.mjs.map → magic-string.es-Dk-MMA0F.mjs.map} +1 -1
- package/dist/music-generator/MusicGenerator.d.mts +2 -2
- package/dist/music-generator/MusicGenerator.test.mjs +1 -1
- package/dist/observability/Metrics.d.mts +116 -28
- package/dist/observability/Metrics.d.mts.map +1 -1
- package/dist/observability/Metrics.mjs +250 -38
- package/dist/observability/Metrics.mjs.map +1 -1
- package/dist/observability/Metrics.test.d.mts +1 -0
- package/dist/observability/Metrics.test.mjs +187 -0
- package/dist/observability/Metrics.test.mjs.map +1 -0
- package/dist/observability/Telemetry.d.mts +37 -0
- package/dist/observability/Telemetry.d.mts.map +1 -0
- package/dist/observability/Telemetry.mjs +57 -0
- package/dist/observability/Telemetry.mjs.map +1 -0
- package/dist/observability/Telemetry.test.d.mts +1 -0
- package/dist/observability/Telemetry.test.mjs +92 -0
- package/dist/observability/Telemetry.test.mjs.map +1 -0
- package/dist/retry/Retry.d.mts +2 -2
- package/dist/retry/Retry.test.mjs +1 -1
- package/dist/sandbox/Sandbox.d.mts +1 -1
- package/dist/sandbox/SandboxError.d.mts +1 -1
- package/dist/speech-synthesizer/SpeechSynthesizer.d.mts +2 -2
- package/dist/speech-synthesizer/SpeechSynthesizer.test.mjs +1 -1
- package/dist/streaming/JSONL.d.mts +1 -1
- package/dist/streaming/JSONL.test.mjs +1 -1
- package/dist/streaming/SSE.test.mjs +1 -1
- package/dist/structured-format/StructuredFormat.d.mts +1 -1
- package/dist/structured-format/StructuredFormat.mjs.map +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 +80 -40
- 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 +190 -36
- package/dist/tool/Tool.mjs.map +1 -1
- package/dist/tool/Tool.test.mjs +41 -3
- package/dist/tool/Tool.test.mjs.map +1 -1
- package/dist/tool/ToolEvent.d.mts +2 -151
- package/dist/tool/ToolEvent.mjs +5 -0
- package/dist/tool/ToolEvent.mjs.map +1 -1
- package/dist/tool/ToolResult.d.mts +2 -138
- package/dist/tool/ToolResult.mjs +32 -8
- package/dist/tool/ToolResult.mjs.map +1 -1
- package/dist/tool/Toolkit.d.mts +2 -73
- package/dist/tool/Toolkit.mjs +153 -35
- package/dist/tool/Toolkit.mjs.map +1 -1
- package/dist/tool/Toolkit.test.mjs +271 -11
- package/dist/tool/Toolkit.test.mjs.map +1 -1
- package/dist/transcriber/Transcriber.d.mts +2 -2
- 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/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 +21 -1
- 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/embedding-model/EmbeddingModel.test.ts +4 -0
- package/src/index.ts +6 -0
- package/src/language-model/LanguageModel.ts +7 -2
- package/src/loop/Loop.test.ts +22 -0
- package/src/loop/Loop.ts +27 -4
- package/src/observability/Metrics.test.ts +266 -0
- package/src/observability/Metrics.ts +505 -65
- package/src/observability/Telemetry.test.ts +123 -0
- package/src/observability/Telemetry.ts +96 -0
- package/src/structured-format/StructuredFormat.ts +4 -0
- package/src/tool/Approval.test.ts +77 -26
- package/src/tool/Approval.ts +72 -27
- package/src/tool/Tool.test.ts +55 -2
- package/src/tool/Tool.ts +335 -70
- package/src/tool/ToolEvent.ts +5 -0
- package/src/tool/ToolResult.ts +36 -9
- package/src/tool/Toolkit.test.ts +339 -9
- package/src/tool/Toolkit.ts +470 -120
- package/src/web-read/WebRead.ts +70 -0
- package/src/web-read/WebReadTool.ts +96 -0
- package/src/web-search/WebSearchTool.ts +11 -5
- package/dist/Tool-BKiieFXk.d.mts +0 -102
- package/dist/Tool-BKiieFXk.d.mts.map +0 -1
- package/dist/loop/Loop.d.mts.map +0 -1
- package/dist/tool/ToolEvent.d.mts.map +0 -1
- package/dist/tool/ToolResult.d.mts.map +0 -1
- package/dist/tool/Toolkit.d.mts.map +0 -1
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
import { o as HistoryItem, v as ToolCall } from "./Items-BnIduEV2.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-2lC_XMth.mjs";
|
|
3
|
+
import { Turn } from "./domain/Turn.mjs";
|
|
4
|
+
import { r as Step } from "./Loop-D8nWpowc.mjs";
|
|
5
|
+
import { t as ToolResult } from "./ToolResult-CL4hK_9z.mjs";
|
|
6
|
+
import { t as ToolEvent } from "./ToolEvent-cWZ2BnbS.mjs";
|
|
7
|
+
import { Cause, Effect, Stream } from "effect";
|
|
8
|
+
import * as _$effect_Types0 from "effect/Types";
|
|
9
|
+
|
|
10
|
+
//#region src/tool/Toolkit.d.ts
|
|
11
|
+
declare namespace Toolkit_d_exports {
|
|
12
|
+
export { DuplicateToolName, ExecuteOptions, Middleware, NoDuplicateNames, ToolMap, Toolkit, ToolkitE, ToolkitR, UniqueTools, appendToolResults, collectResults, compose, continueWithResults, describeFailures, descriptors, fromArray, make, makeNamespaced, namespace, run, wrap };
|
|
13
|
+
}
|
|
14
|
+
type ToolMap = Record<string, AnyTool>;
|
|
15
|
+
type Toolkit<Tools extends ToolMap = ToolMap> = Tools;
|
|
16
|
+
declare const make: <const Tools extends ReadonlyArray<AnyTool>>(...tools: UniqueTools<Tools>) => Toolkit<{ [T in Tools[number] as T["name"]]: T }>;
|
|
17
|
+
/**
|
|
18
|
+
* Build a toolkit from a dynamically-sourced array (MCP server, plugin). Names
|
|
19
|
+
* are not validated (MCP legitimately uses dots / >64 chars — sanitize at the
|
|
20
|
+
* provider adapter); same-named tools resolve last-wins. Cross-source clashes
|
|
21
|
+
* are caught by `compose`.
|
|
22
|
+
*/
|
|
23
|
+
declare const fromArray: (tools: ReadonlyArray<AnyTool>) => Toolkit;
|
|
24
|
+
/** Render the provider-facing descriptors for a toolkit on demand. */
|
|
25
|
+
declare const descriptors: (toolkit: Toolkit) => ReadonlyArray<ToolDescriptor>;
|
|
26
|
+
/**
|
|
27
|
+
* Union of every tool's `R` requirements in a toolkit. Surfaced by `run` so the
|
|
28
|
+
* loop's stream type carries the services tools need through to `Effect.provide`.
|
|
29
|
+
*
|
|
30
|
+
* The `ToolMap extends T` guard yields `never` for the wide `Toolkit` type (a
|
|
31
|
+
* toolkit passed through an untyped boundary, where the requirements aren't
|
|
32
|
+
* statically known) instead of `any`, which would otherwise poison the
|
|
33
|
+
* resulting stream's `R`. Concrete toolkits from `make` keep their precise R.
|
|
34
|
+
*/
|
|
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]>;
|
|
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;
|
|
45
|
+
type DuplicateNameError<Name extends string> = {
|
|
46
|
+
readonly __error: `Duplicate tool name: ${Name}`;
|
|
47
|
+
};
|
|
48
|
+
type NoDuplicateNames<Tools extends ReadonlyArray<AnyTool>> = [DuplicateName<Tools>] extends [never] ? unknown : DuplicateNameError<DuplicateName<Tools>>;
|
|
49
|
+
/** `Tools` constrained so a repeated literal name is a compile error in `make`. */
|
|
50
|
+
type UniqueTools<Tools extends ReadonlyArray<AnyTool>> = Tools & NoDuplicateNames<Tools>;
|
|
51
|
+
type ComposeDuplicateKey<Kits extends ReadonlyArray<Toolkit>, Seen extends string = never> = Kits extends readonly [infer Head extends Toolkit, ...infer Tail extends ReadonlyArray<Toolkit>] ? string extends keyof Head ? ComposeDuplicateKey<Tail, Seen> : Extract<keyof Head & string, Seen> extends never ? ComposeDuplicateKey<Tail, Seen | (keyof Head & string)> : Extract<keyof Head & string, Seen> : never;
|
|
52
|
+
type NoDuplicateComposedKeys<Kits extends ReadonlyArray<Toolkit>> = [ComposeDuplicateKey<Kits>] extends [never] ? unknown : DuplicateNameError<ComposeDuplicateKey<Kits>>;
|
|
53
|
+
type UnionToIntersection<U> = (U extends unknown ? (x: U) => void : never) extends ((x: infer I) => void) ? I : never;
|
|
54
|
+
type Composed<Kits extends ReadonlyArray<Toolkit>> = UnionToIntersection<Kits[number]> extends infer M ? (M extends ToolMap ? M : ToolMap) : ToolMap;
|
|
55
|
+
declare const DuplicateToolName_base: new <A extends Record<string, any> = {}>(args: _$effect_Types0.VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P] }>) => Cause.YieldableError & {
|
|
56
|
+
readonly _tag: "DuplicateToolName";
|
|
57
|
+
} & Readonly<A>;
|
|
58
|
+
/**
|
|
59
|
+
* Two composed toolkits resolved to the same final name. Carries the colliding
|
|
60
|
+
* `sources` (the positions of the clashing toolkits) so the error says *which*
|
|
61
|
+
* inputs collided. Raised at runtime by `compose` for dynamic sources; static
|
|
62
|
+
* collisions are caught earlier at compile time.
|
|
63
|
+
*/
|
|
64
|
+
declare class DuplicateToolName extends DuplicateToolName_base<{
|
|
65
|
+
readonly name: string;
|
|
66
|
+
readonly sources: ReadonlyArray<string>;
|
|
67
|
+
}> {}
|
|
68
|
+
type PrefixName<Prefix extends string, Name extends string> = `${Prefix}__${Name}`;
|
|
69
|
+
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;
|
|
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 };
|
|
71
|
+
/**
|
|
72
|
+
* Prefix every tool name with `<namespace>__`, returning a new toolkit. Use it
|
|
73
|
+
* to keep generic names (`search`) from two sources distinct before `compose`.
|
|
74
|
+
* If two namespaces collide at the `__` separator, the duplicate final name
|
|
75
|
+
* surfaces from `compose` as a `DuplicateToolName`.
|
|
76
|
+
*/
|
|
77
|
+
declare const namespace: <const Prefix extends string, const T extends ToolMap>(prefix: Prefix, toolkit: Toolkit<T>) => Toolkit<Namespaced<Prefix, T>>;
|
|
78
|
+
/** `namespace(prefix, make(...tools))` in one step, for static namespaced tools. */
|
|
79
|
+
declare const makeNamespaced: <const Prefix extends string, const Tools extends ReadonlyArray<AnyTool>>(prefix: Prefix, ...tools: UniqueTools<Tools>) => Toolkit<Namespaced<Prefix, { [T in Tools[number] as T["name"]]: T }>>;
|
|
80
|
+
/**
|
|
81
|
+
* Combine independently-built toolkits into one. This is where names from
|
|
82
|
+
* separate sources can collide, so it is the one effectful constructor: a
|
|
83
|
+
* duplicate final name fails with `DuplicateToolName` (naming the colliding
|
|
84
|
+
* input positions) instead of silently overwriting or 400-ing later at the
|
|
85
|
+
* provider. Statically-known collisions are additionally a compile error.
|
|
86
|
+
*/
|
|
87
|
+
declare const compose: <const Kits extends ReadonlyArray<Toolkit>>(...toolkits: Kits & NoDuplicateComposedKeys<Kits>) => Effect.Effect<Toolkit<Composed<Kits>>, DuplicateToolName>;
|
|
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] };
|
|
97
|
+
/**
|
|
98
|
+
* Wrap every local tool's `run` with a middleware, preserving each tool's
|
|
99
|
+
* `Input`/`Output` and unioning the middleware's requirement `R2` into the
|
|
100
|
+
* toolkit's `ToolkitR`. Non-local kinds pass through unchanged. Stack with
|
|
101
|
+
* `pipe` - inner-first, so the last `wrap` applied is the outermost and runs
|
|
102
|
+
* first:
|
|
103
|
+
*
|
|
104
|
+
* const observed = pipe(toolkit, Toolkit.wrap(logging), Toolkit.wrap(authz))
|
|
105
|
+
* Toolkit.run(observed, calls) // authz runs, then logging, then the tool
|
|
106
|
+
*
|
|
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.
|
|
111
|
+
*/
|
|
112
|
+
declare const wrap: {
|
|
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>;
|
|
132
|
+
};
|
|
133
|
+
type ExecuteOptions = {
|
|
134
|
+
readonly concurrency?: number | "unbounded";
|
|
135
|
+
};
|
|
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>>;
|
|
147
|
+
/**
|
|
148
|
+
* Append a completed turn plus tool results to a state's history, converting
|
|
149
|
+
* the results to wire-format `ToolCallOutput`s. Curried so it slots directly
|
|
150
|
+
* into `continueWithResults`:
|
|
151
|
+
*
|
|
152
|
+
* Toolkit.run(toolkit, calls).pipe(
|
|
153
|
+
* Toolkit.continueWithResults(Toolkit.appendToolResults(state, turn)),
|
|
154
|
+
* )
|
|
155
|
+
*
|
|
156
|
+
* Equivalent to `appendToHistory(state, turn, results.map(toToolCallOutput))`
|
|
157
|
+
* — the helper just hides the wire-conversion step.
|
|
158
|
+
*/
|
|
159
|
+
declare const appendToolResults: <S extends {
|
|
160
|
+
readonly history: ReadonlyArray<HistoryItem>;
|
|
161
|
+
}>(state: S, turn: Turn) => (results: ReadonlyArray<ToolResult>) => S;
|
|
162
|
+
/**
|
|
163
|
+
* Drain a `Stream<ToolEvent>` and return the accumulated `ToolResult`s
|
|
164
|
+
* from every `Output` event. One-shot — the type is `Effect<results>`,
|
|
165
|
+
* not a one-element stream — so it composes naturally with `Effect.map`
|
|
166
|
+
* to build state.
|
|
167
|
+
*
|
|
168
|
+
* Counterpart to `continueWithResults`: `continueWithResults` bundles
|
|
169
|
+
* drain + emit Next into one bridge; this one is the right arm of a
|
|
170
|
+
* broadcast/fork-and-merge for callers that want to vary the left arm
|
|
171
|
+
* (e.g., filter/tap ToolEvents before forwarding).
|
|
172
|
+
*/
|
|
173
|
+
declare const collectResults: <E, R>(stream: Stream.Stream<ToolEvent, E, R>) => Effect.Effect<ReadonlyArray<ToolResult>, E, R>;
|
|
174
|
+
/**
|
|
175
|
+
* Bridge from a `Stream<ToolEvent>` to the loop's emit shape. Forwards
|
|
176
|
+
* every ToolEvent downstream as a `Loop.value` and at end-of-stream emits
|
|
177
|
+
* one `Loop.next(build(results))` carrying the accumulated `ToolResult`s
|
|
178
|
+
* from terminal `Output` events.
|
|
179
|
+
*
|
|
180
|
+
* Conceptually a broadcast fork (one arm passes events through, the other
|
|
181
|
+
* drains them into a state). Implemented as a single-pass Ref tap + concat
|
|
182
|
+
* for zero buffering — the broadcast version is observationally equivalent
|
|
183
|
+
* but holds events in a PubSub until both arms drain. The public primitives
|
|
184
|
+
* (`Loop.value`, `collectResults`, `Loop.next`) compose the same pattern
|
|
185
|
+
* when you need to vary an arm.
|
|
186
|
+
*
|
|
187
|
+
* Dual: data-first `continueWithResults(stream, build)` and data-last
|
|
188
|
+
* `stream.pipe(continueWithResults(build))` both work.
|
|
189
|
+
*/
|
|
190
|
+
declare const continueWithResults: {
|
|
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>;
|
|
193
|
+
};
|
|
194
|
+
//#endregion
|
|
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-Dr9l_hNy.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Toolkit-Dr9l_hNy.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,OAAA,SAAgB,CAAA,WAAY,KAAA,CAAM,CAAA,OAAQ,CAAA;;;;;;AA3CpF;;KAoDY,QAAA,WAAmB,OAAA,IAAW,OAAA,SAAgB,CAAA,WAAY,KAAA,CAAM,CAAA,OAAQ,CAAA;AAAA,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AAA,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;IAAA,SAAwB,MAAA;EAAA;AAAA;AAAA,KAO7C,WAAA;EAAA,SACD,CAAA;EAAA,SACA,CAAA;EAAA,SACA,KAAA;EAAA,SACA,MAAA;AAAA;;AA3BX;;;;KAmCY,WAAA;EA1BS;;;;EAAA,SA+BV,GAAA;EA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MAAA,GACP,EAAA,EAAI,gBAAA,KACD,MAAA,CAAO,MAAA,CAAO,cAAA,EAAgB,YAAA,EAA2B,KAAA,CAAM,KAAA,GArFjB;EAAA,SAwF1C,IAAA,EAAM,MAAA,CAAO,MAAA,CAAO,aAAA,CAAc,iBAAA,GAAoB,YAAA;EAvFtD;;;;EAAA,SA6FA,OAAA,GAAU,EAAA,EAAI,gBAAA,KAAqB,MAAA,CAAO,MAAA,OAAa,YAAA;AAAA;AAAA,cACjE,YAAA;cAEY,OAAA,SAAgB,YAAA;;AAjF7B;;;cA6Fa,MAAA,GACX,OAAA,EAAS,oBAAA,KACR,MAAA,CAAO,MAAA,CAAO,cAAA,EAAgB,YAAA,EAA2B,OAAA,GAAU,KAAA,CAAM,KAAA;;;;;cAO/D,MAAA,GACX,EAAA,EAAI,gBAAA,KACH,MAAA,CAAO,MAAA,CAAO,cAAA,EAAgB,YAAA,EAA2B,OAAA,GAAU,KAAA,CAAM,KAAA;;cAI/D,IAAA,EAAM,MAAA,CAAO,MAAA,CACxB,aAAA,CAAc,iBAAA,GACd,YAAA,EACA,OAAA;;;;;cAOW,OAAA,GACX,EAAA,EAAI,gBAAA,KACH,MAAA,CAAO,MAAA,OAAa,YAAA,EAA2B,OAAA"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { n as __exportAll } from "../chunk-uyGKjUfl.mjs";
|
|
2
|
+
import { Brand, Context, Effect } from "effect";
|
|
3
|
+
//#region src/browser/Browser.ts
|
|
4
|
+
var Browser_exports = /* @__PURE__ */ __exportAll({
|
|
5
|
+
Browser: () => Browser,
|
|
6
|
+
BrowserSessionId: () => BrowserSessionId,
|
|
7
|
+
attach: () => attach,
|
|
8
|
+
create: () => create,
|
|
9
|
+
destroy: () => destroy,
|
|
10
|
+
list: () => list
|
|
11
|
+
});
|
|
12
|
+
const BrowserSessionId = Brand.nominal();
|
|
13
|
+
var Browser = class extends Context.Service()("@betalyra/effect-uai/Browser") {};
|
|
14
|
+
/**
|
|
15
|
+
* Provision a session bound to the caller's scope. Drop the `Scope.Scope`
|
|
16
|
+
* requirement with `Effect.scoped`.
|
|
17
|
+
*/
|
|
18
|
+
const create = (request) => Effect.flatMap(Browser.asEffect(), (s) => s.create(request));
|
|
19
|
+
/**
|
|
20
|
+
* Re-acquire an existing session by id. Same scope semantics as `create`,
|
|
21
|
+
* but the finalizer detaches rather than destroying.
|
|
22
|
+
*/
|
|
23
|
+
const attach = (id) => Effect.flatMap(Browser.asEffect(), (s) => s.attach(id));
|
|
24
|
+
/** Enumerate sessions for the configured account / project. */
|
|
25
|
+
const list = Effect.flatMap(Browser.asEffect(), (s) => s.list);
|
|
26
|
+
/**
|
|
27
|
+
* Destroy a session from outside its owning scope. Most callers should let
|
|
28
|
+
* the scope finalizer handle this automatically.
|
|
29
|
+
*/
|
|
30
|
+
const destroy = (id) => Effect.flatMap(Browser.asEffect(), (s) => s.destroy(id));
|
|
31
|
+
//#endregion
|
|
32
|
+
export { Browser, BrowserSessionId, attach, create, destroy, list, Browser_exports as t };
|
|
33
|
+
|
|
34
|
+
//# sourceMappingURL=Browser.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Browser.mjs","names":[],"sources":["../../src/browser/Browser.ts"],"sourcesContent":["import { Brand, Context, type Duration, Effect, Scope } from \"effect\"\nimport type * as BrowserError from \"./BrowserError.js\"\n\n// ---------------------------------------------------------------------------\n// Identity\n// ---------------------------------------------------------------------------\n\n/**\n * Session identifier. Branded `string` so providers don't accidentally\n * accept a raw user-supplied id, and so a session id can't be passed where\n * another service's id is expected. Each provider mints these per its own\n * scheme; core code treats them opaquely. Mint via `BrowserSessionId(...)`.\n */\nexport type BrowserSessionId = Brand.Branded<string, \"BrowserSessionId\">\nexport const BrowserSessionId = Brand.nominal<BrowserSessionId>()\n\n/** Reference returned by `list`; enough to `attach`. */\nexport type BrowserSessionRef = {\n readonly id: BrowserSessionId\n /** Current top-level URL, when the provider reports it. */\n readonly url?: string\n}\n\n/**\n * Output representation for {@link BrowserSession.content}. `markdown` is\n * the default.\n */\nexport type PageFormat = \"markdown\" | \"html\"\n\n// ---------------------------------------------------------------------------\n// Create request\n// ---------------------------------------------------------------------------\n\n/**\n * Cross-provider session-create request. Provider-specific knobs (proxy,\n * stealth, persistent profile, ...) live on each provider's narrowed\n * request type which extends this.\n */\nexport type CommonSessionRequest = {\n /**\n * Hard max lifetime of the session. Enforced locally (the handle is\n * disposed and further calls fail with `BrowserSessionExpired`) and,\n * where the provider supports it, passed through as a server-side cap so\n * a crashed client still gets the session reclaimed. The provider cap\n * must be >= the local reaper. Accepts millis, a string like\n * `\"5 minutes\"`, or a `Duration`.\n */\n readonly timeout?: Duration.Input\n /**\n * Idle teardown: dispose the session after this much inactivity, the\n * timer resetting on each operation. Opt-in; omit for no idle limit.\n */\n readonly idleTimeout?: Duration.Input\n /** Initial viewport size. Providers default differently. */\n readonly viewport?: { readonly width: number; readonly height: number }\n}\n\n// ---------------------------------------------------------------------------\n// Observation shapes\n// ---------------------------------------------------------------------------\n\nexport type BoundingBox = {\n readonly x: number\n readonly y: number\n readonly width: number\n readonly height: number\n}\n\n/**\n * One element returned by {@link BrowserSession.query}. Serializable data,\n * not a live handle (handles go stale across navigation and do not cross a\n * provider boundary cleanly).\n */\nexport type ElementInfo = {\n /**\n * Reference usable as a selector for a follow-up action. Valid until the\n * next navigation; do not cache across `goto` or a page-changing click.\n */\n readonly ref: string\n readonly tag: string\n readonly text?: string\n readonly attributes: Readonly<Record<string, string>>\n readonly box?: BoundingBox\n}\n\n/** Accessibility-tree node returned by {@link BrowserSession.snapshot}. */\nexport type AxNode = {\n readonly role: string\n readonly name?: string\n readonly value?: string\n /**\n * Reference usable as a selector for a follow-up action. Valid until the\n * next navigation; do not cache across `goto` or a page-changing click.\n */\n readonly ref?: string\n readonly children: ReadonlyArray<AxNode>\n}\n\n// ---------------------------------------------------------------------------\n// Interaction shapes\n// ---------------------------------------------------------------------------\n\nexport type ScrollDirection = \"up\" | \"down\" | \"left\" | \"right\"\n\nexport type ScrollOptions = {\n readonly direction: ScrollDirection\n /** Distance in CSS pixels. Provider default applies when omitted. */\n readonly pixels?: number\n}\n\nexport type ScreenshotOptions = {\n /** Clip to the first element matching this selector. */\n readonly selector?: string\n /** Capture the full scrollable page rather than the viewport. */\n readonly fullPage?: boolean\n}\n\nexport type Cookie = {\n readonly name: string\n readonly value: string\n readonly domain?: string\n readonly path?: string\n readonly expires?: number\n readonly httpOnly?: boolean\n readonly secure?: boolean\n readonly sameSite?: \"Strict\" | \"Lax\" | \"None\"\n}\n\n/** Read / write the session's cookie jar. Needed for authenticated flows. */\nexport type CookieApi = {\n readonly get: Effect.Effect<ReadonlyArray<Cookie>, BrowserError.BrowserError>\n readonly set: (cookies: ReadonlyArray<Cookie>) => Effect.Effect<void, BrowserError.BrowserError>\n}\n\n// ---------------------------------------------------------------------------\n// Live session handle\n// ---------------------------------------------------------------------------\n\n/**\n * Live session handle. Actions take a CSS selector string (so `#id` is\n * just `#id`). Methods are plain `Effect` values; disposal is the scope\n * finalizer, not a method here (see {@link BrowserService}). Anything not\n * covered by a verb is reachable via `evaluate`. Per-operation time budgets\n * are the provider's default; wrap any call in `Effect.timeout` for a\n * tighter bound.\n */\nexport type BrowserSession = {\n readonly id: BrowserSessionId\n\n // Navigation and waiting\n readonly goto: (url: string) => Effect.Effect<void, BrowserError.BrowserError>\n readonly waitFor: (selector: string) => Effect.Effect<void, BrowserError.BrowserError>\n\n // Interaction\n readonly click: (selector: string) => Effect.Effect<void, BrowserError.BrowserError>\n readonly dblclick: (selector: string) => Effect.Effect<void, BrowserError.BrowserError>\n readonly fill: (selector: string, text: string) => Effect.Effect<void, BrowserError.BrowserError>\n readonly type: (selector: string, text: string) => Effect.Effect<void, BrowserError.BrowserError>\n readonly press: (key: string) => Effect.Effect<void, BrowserError.BrowserError>\n readonly hover: (selector: string) => Effect.Effect<void, BrowserError.BrowserError>\n readonly focus: (selector: string) => Effect.Effect<void, BrowserError.BrowserError>\n readonly select: (\n selector: string,\n value: string,\n ) => Effect.Effect<void, BrowserError.BrowserError>\n readonly check: (selector: string) => Effect.Effect<void, BrowserError.BrowserError>\n readonly uncheck: (selector: string) => Effect.Effect<void, BrowserError.BrowserError>\n readonly scroll: (options: ScrollOptions) => Effect.Effect<void, BrowserError.BrowserError>\n readonly scrollIntoView: (selector: string) => Effect.Effect<void, BrowserError.BrowserError>\n\n // Observation\n readonly content: (format?: PageFormat) => Effect.Effect<string, BrowserError.BrowserError>\n readonly screenshot: (\n options?: ScreenshotOptions,\n ) => Effect.Effect<Uint8Array, BrowserError.BrowserError>\n readonly snapshot: Effect.Effect<AxNode, BrowserError.BrowserError>\n readonly query: (\n selector: string,\n ) => Effect.Effect<ReadonlyArray<ElementInfo>, BrowserError.BrowserError>\n\n // State and escape hatch\n readonly cookies: CookieApi\n readonly evaluate: (script: string) => Effect.Effect<unknown, BrowserError.BrowserError>\n}\n\n// ---------------------------------------------------------------------------\n// Service definition\n// ---------------------------------------------------------------------------\n\n/**\n * Cross-provider browser service.\n *\n * Lifetime: `create` and `attach` return a handle in `Scope.Scope`. The\n * scope finalizer disposes the session (close the transport, destroy or\n * detach the remote session, kill the local engine). Bind with\n * `Effect.scoped` for a single call, or hold a wider scope to keep a\n * session warm across many calls. This is why there is no `dispose()` on\n * {@link BrowserSession}; the scope is the lifecycle handle.\n */\nexport type BrowserService = {\n /**\n * Provision a new session, bound to the caller's scope. Disposed on\n * scope close.\n */\n readonly create: (\n request: CommonSessionRequest,\n ) => Effect.Effect<BrowserSession, BrowserError.BrowserError, Scope.Scope>\n\n /**\n * Re-acquire an existing session by id. Scope-bound, but the finalizer\n * detaches rather than destroying, for sessions kept warm beyond a\n * single run.\n */\n readonly attach: (\n id: BrowserSessionId,\n ) => Effect.Effect<BrowserSession, BrowserError.BrowserError, Scope.Scope>\n\n /** Enumerate sessions visible to the configured account / project. */\n readonly list: Effect.Effect<ReadonlyArray<BrowserSessionRef>, BrowserError.BrowserError>\n\n /**\n * Destroy a session from outside its owning scope. Most callers should\n * let the scope finalizer handle this.\n */\n readonly destroy: (id: BrowserSessionId) => Effect.Effect<void, BrowserError.BrowserError>\n}\n\nexport class Browser extends Context.Service<Browser, BrowserService>()(\n \"@betalyra/effect-uai/Browser\",\n) {}\n\n// ---------------------------------------------------------------------------\n// Free helpers\n// ---------------------------------------------------------------------------\n\n/**\n * Provision a session bound to the caller's scope. Drop the `Scope.Scope`\n * requirement with `Effect.scoped`.\n */\nexport const create = (\n request: CommonSessionRequest,\n): Effect.Effect<BrowserSession, BrowserError.BrowserError, Browser | Scope.Scope> =>\n Effect.flatMap(Browser.asEffect(), (s) => s.create(request))\n\n/**\n * Re-acquire an existing session by id. Same scope semantics as `create`,\n * but the finalizer detaches rather than destroying.\n */\nexport const attach = (\n id: BrowserSessionId,\n): Effect.Effect<BrowserSession, BrowserError.BrowserError, Browser | Scope.Scope> =>\n Effect.flatMap(Browser.asEffect(), (s) => s.attach(id))\n\n/** Enumerate sessions for the configured account / project. */\nexport const list: Effect.Effect<\n ReadonlyArray<BrowserSessionRef>,\n BrowserError.BrowserError,\n Browser\n> = Effect.flatMap(Browser.asEffect(), (s) => s.list)\n\n/**\n * Destroy a session from outside its owning scope. Most callers should let\n * the scope finalizer handle this automatically.\n */\nexport const destroy = (\n id: BrowserSessionId,\n): Effect.Effect<void, BrowserError.BrowserError, Browser> =>\n Effect.flatMap(Browser.asEffect(), (s) => s.destroy(id))\n"],"mappings":";;;;;;;;;;;AAcA,MAAa,mBAAmB,MAAM,SAA2B;AAqNjE,IAAa,UAAb,cAA6B,QAAQ,SAAkC,CACrE,+BACD,CAAC;;;;;AAUF,MAAa,UACX,YAEA,OAAO,QAAQ,QAAQ,UAAU,GAAG,MAAM,EAAE,OAAO,QAAQ,CAAC;;;;;AAM9D,MAAa,UACX,OAEA,OAAO,QAAQ,QAAQ,UAAU,GAAG,MAAM,EAAE,OAAO,GAAG,CAAC;;AAGzD,MAAa,OAIT,OAAO,QAAQ,QAAQ,UAAU,GAAG,MAAM,EAAE,KAAK;;;;;AAMrD,MAAa,WACX,OAEA,OAAO,QAAQ,QAAQ,UAAU,GAAG,MAAM,EAAE,QAAQ,GAAG,CAAC"}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { Duration } from "effect";
|
|
2
|
+
import * as _$effect_Cause0 from "effect/Cause";
|
|
3
|
+
import * as _$effect_Types0 from "effect/Types";
|
|
4
|
+
|
|
5
|
+
//#region src/browser/BrowserError.d.ts
|
|
6
|
+
declare namespace BrowserError_d_exports {
|
|
7
|
+
export { BrowserActionFailed, BrowserAuthFailed, BrowserAuthSubtype, BrowserCreateFailed, BrowserError, BrowserInvalidRequest, BrowserQuotaExceeded, BrowserSessionExpired, BrowserSessionNotFound, BrowserTimeout, BrowserUnsupported, describe };
|
|
8
|
+
}
|
|
9
|
+
declare const BrowserCreateFailed_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 & {
|
|
10
|
+
readonly _tag: "BrowserCreateFailed";
|
|
11
|
+
} & Readonly<A>;
|
|
12
|
+
/**
|
|
13
|
+
* Failed to provision a browser session: the transport could not connect,
|
|
14
|
+
* a launched engine did not come up, or the provider refused to mint a
|
|
15
|
+
* session. Provider's structured reason on `reason`; the raw transport /
|
|
16
|
+
* SDK error on `raw`.
|
|
17
|
+
*/
|
|
18
|
+
declare class BrowserCreateFailed extends BrowserCreateFailed_base<{
|
|
19
|
+
provider: string;
|
|
20
|
+
reason?: string;
|
|
21
|
+
raw: unknown;
|
|
22
|
+
}> {}
|
|
23
|
+
declare const BrowserSessionNotFound_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 & {
|
|
24
|
+
readonly _tag: "BrowserSessionNotFound";
|
|
25
|
+
} & Readonly<A>;
|
|
26
|
+
/**
|
|
27
|
+
* The requested session id does not exist. Raised by `attach` / `destroy`
|
|
28
|
+
* against a stale or never-known id. Distinct from
|
|
29
|
+
* {@link BrowserSessionExpired}, which is a session that existed and has
|
|
30
|
+
* since ended.
|
|
31
|
+
*/
|
|
32
|
+
declare class BrowserSessionNotFound extends BrowserSessionNotFound_base<{
|
|
33
|
+
provider: string;
|
|
34
|
+
id: string;
|
|
35
|
+
}> {}
|
|
36
|
+
declare const BrowserSessionExpired_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 & {
|
|
37
|
+
readonly _tag: "BrowserSessionExpired";
|
|
38
|
+
} & Readonly<A>;
|
|
39
|
+
/**
|
|
40
|
+
* An operation was issued against a session that has ended: it reached its
|
|
41
|
+
* max lifetime (the create-time `timeout`), was destroyed, or the provider
|
|
42
|
+
* reaped it. The handle is dead; `create` or `attach` a live session.
|
|
43
|
+
* Distinct from {@link BrowserTimeout} (a single live operation was too
|
|
44
|
+
* slow).
|
|
45
|
+
*/
|
|
46
|
+
declare class BrowserSessionExpired extends BrowserSessionExpired_base<{
|
|
47
|
+
provider: string;
|
|
48
|
+
id: string;
|
|
49
|
+
}> {}
|
|
50
|
+
declare const BrowserTimeout_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 & {
|
|
51
|
+
readonly _tag: "BrowserTimeout";
|
|
52
|
+
} & Readonly<A>;
|
|
53
|
+
/**
|
|
54
|
+
* A single operation exceeded its own time budget while the session was
|
|
55
|
+
* still alive (a navigation that never settled, a `waitFor` selector that
|
|
56
|
+
* never appeared). Carries the breached budget for observability.
|
|
57
|
+
*/
|
|
58
|
+
declare class BrowserTimeout extends BrowserTimeout_base<{
|
|
59
|
+
provider: string;
|
|
60
|
+
operation: "create" | "attach" | "navigate" | "action" | "query";
|
|
61
|
+
budget?: Duration.Duration;
|
|
62
|
+
raw?: unknown;
|
|
63
|
+
}> {}
|
|
64
|
+
declare const BrowserActionFailed_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 & {
|
|
65
|
+
readonly _tag: "BrowserActionFailed";
|
|
66
|
+
} & Readonly<A>;
|
|
67
|
+
/**
|
|
68
|
+
* An interaction or observation failed at the transport / protocol layer:
|
|
69
|
+
* a selector resolved to nothing, an element was not actionable, an
|
|
70
|
+
* `evaluate` script threw, a navigation errored. `selector` and `reason`
|
|
71
|
+
* carry what is known.
|
|
72
|
+
*/
|
|
73
|
+
declare class BrowserActionFailed extends BrowserActionFailed_base<{
|
|
74
|
+
provider: string;
|
|
75
|
+
operation: "navigate" | "interact" | "observe" | "evaluate" | "cookies";
|
|
76
|
+
selector?: string;
|
|
77
|
+
reason?: string;
|
|
78
|
+
raw: unknown;
|
|
79
|
+
}> {}
|
|
80
|
+
declare const BrowserQuotaExceeded_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 & {
|
|
81
|
+
readonly _tag: "BrowserQuotaExceeded";
|
|
82
|
+
} & Readonly<A>;
|
|
83
|
+
/**
|
|
84
|
+
* Provider rejected the request because an account / project quota or
|
|
85
|
+
* concurrency limit was exceeded. Separate from {@link BrowserCreateFailed}
|
|
86
|
+
* so callers can back off and retry.
|
|
87
|
+
*/
|
|
88
|
+
declare class BrowserQuotaExceeded extends BrowserQuotaExceeded_base<{
|
|
89
|
+
provider: string;
|
|
90
|
+
reason?: string;
|
|
91
|
+
raw: unknown;
|
|
92
|
+
}> {}
|
|
93
|
+
declare const BrowserInvalidRequest_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 & {
|
|
94
|
+
readonly _tag: "BrowserInvalidRequest";
|
|
95
|
+
} & Readonly<A>;
|
|
96
|
+
/**
|
|
97
|
+
* Caller's request shape is malformed for the wired provider. Adapters
|
|
98
|
+
* should reject at the request-schema layer where possible; this is the
|
|
99
|
+
* runtime fallback.
|
|
100
|
+
*/
|
|
101
|
+
declare class BrowserInvalidRequest extends BrowserInvalidRequest_base<{
|
|
102
|
+
provider: string;
|
|
103
|
+
param?: string;
|
|
104
|
+
reason?: string;
|
|
105
|
+
raw?: unknown;
|
|
106
|
+
}> {}
|
|
107
|
+
/**
|
|
108
|
+
* Transport could not authenticate against the provider. Subtype mirrors
|
|
109
|
+
* the model-side `AiError.AuthFailed` shape for consistency.
|
|
110
|
+
*/
|
|
111
|
+
type BrowserAuthSubtype = "auth" | "permission" | "billing" | "quota";
|
|
112
|
+
declare const BrowserAuthFailed_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 & {
|
|
113
|
+
readonly _tag: "BrowserAuthFailed";
|
|
114
|
+
} & Readonly<A>;
|
|
115
|
+
declare class BrowserAuthFailed extends BrowserAuthFailed_base<{
|
|
116
|
+
provider: string;
|
|
117
|
+
subtype: BrowserAuthSubtype;
|
|
118
|
+
raw: unknown;
|
|
119
|
+
}> {}
|
|
120
|
+
declare const BrowserUnsupported_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 & {
|
|
121
|
+
readonly _tag: "BrowserUnsupported";
|
|
122
|
+
} & Readonly<A>;
|
|
123
|
+
/**
|
|
124
|
+
* The wired provider does not implement the requested operation for these
|
|
125
|
+
* inputs. Distinct from {@link BrowserInvalidRequest} (malformed request)
|
|
126
|
+
* and from compile-time capability markers gating blanket provider gaps.
|
|
127
|
+
*/
|
|
128
|
+
declare class BrowserUnsupported extends BrowserUnsupported_base<{
|
|
129
|
+
provider: string;
|
|
130
|
+
capability: string;
|
|
131
|
+
reason?: string;
|
|
132
|
+
}> {}
|
|
133
|
+
type BrowserError = BrowserCreateFailed | BrowserSessionNotFound | BrowserSessionExpired | BrowserTimeout | BrowserActionFailed | BrowserQuotaExceeded | BrowserInvalidRequest | BrowserAuthFailed | BrowserUnsupported;
|
|
134
|
+
/**
|
|
135
|
+
* Short human-readable description of an error, for logs and model-facing
|
|
136
|
+
* failure messages. Prose, not a contract; branch on `_tag` instead.
|
|
137
|
+
*/
|
|
138
|
+
declare const describe: (e: BrowserError) => string;
|
|
139
|
+
//#endregion
|
|
140
|
+
export { BrowserActionFailed, BrowserAuthFailed, BrowserAuthSubtype, BrowserCreateFailed, BrowserError, BrowserInvalidRequest, BrowserQuotaExceeded, BrowserSessionExpired, BrowserSessionNotFound, BrowserTimeout, BrowserUnsupported, describe, BrowserError_d_exports as t };
|
|
141
|
+
//# sourceMappingURL=BrowserError.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BrowserError.d.mts","names":[],"sources":["../../src/browser/BrowserError.ts"],"mappings":";;;;;;;;cAA8C,wBAAA;;;;;;;;;cAQjC,mBAAA,SAA4B,wBAAA;EACvC,QAAA;EACA,MAAA;EACA,GAAA;AAAA;AAAA,cACG,2BAAA;;;;AAZyC;;;;;cAoBjC,sBAAA,SAA+B,2BAAA;EAC1C,QAAA;EACA,EAAA;AAAA;AAAA,cACG,0BAAA;;;;;;;;;;cASQ,qBAAA,SAA8B,0BAAA;EACzC,QAAA;EACA,EAAA;AAAA;AAAA,cACG,mBAAA;;;;;;AA3BL;;cAkCa,cAAA,SAAuB,mBAAA;EAClC,QAAA;EACA,SAAA;EACA,MAAA,GAAS,QAAA,CAAS,QAAA;EAClB,GAAA;AAAA;AAAA,cACG,wBAAA;;;;;;;;;cAQQ,mBAAA,SAA4B,wBAAA;EACvC,QAAA;EACA,SAAA;EACA,QAAA;EACA,MAAA;EACA,GAAA;AAAA;AAAA,cACG,yBAAA;;;;;;;;cAOQ,oBAAA,SAA6B,yBAAA;EACxC,QAAA;EACA,MAAA;EACA,GAAA;AAAA;AAAA,cACG,0BAAA;;;;;;;;cAOQ,qBAAA,SAA8B,0BAAA;EACzC,QAAA;EACA,KAAA;EACA,MAAA;EACA,GAAA;AAAA;;;;;KAOU,kBAAA;AAAA,cAAgE,sBAAA;;;cAE/D,iBAAA,SAA0B,sBAAA;EACrC,QAAA;EACA,OAAA,EAAS,kBAAA;EACT,GAAA;AAAA;AAAA,cACG,uBAAA;;;;;;;;cAOQ,kBAAA,SAA2B,uBAAA;EACtC,QAAA;EACA,UAAA;EACA,MAAA;AAAA;AAAA,KAGU,YAAA,GACR,mBAAA,GACA,sBAAA,GACA,qBAAA,GACA,cAAA,GACA,mBAAA,GACA,oBAAA,GACA,qBAAA,GACA,iBAAA,GACA,kBAAA;;;;;cASS,QAAA,GAAW,CAAA,EAAG,YAAA"}
|