@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,70 @@
|
|
|
1
|
+
import { Context, type Duration, Effect } from "effect"
|
|
2
|
+
import type * as AiError from "../domain/AiError.js"
|
|
3
|
+
|
|
4
|
+
// ---------------------------------------------------------------------------
|
|
5
|
+
// Format
|
|
6
|
+
// ---------------------------------------------------------------------------
|
|
7
|
+
|
|
8
|
+
/** Representation to return for a page. `markdown` is the default. */
|
|
9
|
+
export type ReadFormat = "markdown" | "html"
|
|
10
|
+
|
|
11
|
+
// ---------------------------------------------------------------------------
|
|
12
|
+
// Request
|
|
13
|
+
// ---------------------------------------------------------------------------
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Cross-provider read request: one URL in, clean content out. Provider-specific
|
|
17
|
+
* knobs live on the provider-typed request.
|
|
18
|
+
*/
|
|
19
|
+
export type CommonReadRequest = {
|
|
20
|
+
/** The page to read. */
|
|
21
|
+
readonly url: string
|
|
22
|
+
/** Output representation. Defaults to `markdown`. See {@link ReadFormat}. */
|
|
23
|
+
readonly format?: ReadFormat
|
|
24
|
+
/** Upper bound on time spent fetching the page. */
|
|
25
|
+
readonly timeout?: Duration.Duration
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// ---------------------------------------------------------------------------
|
|
29
|
+
// Response
|
|
30
|
+
// ---------------------------------------------------------------------------
|
|
31
|
+
|
|
32
|
+
/** One normalized read result. */
|
|
33
|
+
export type ReadResponse = {
|
|
34
|
+
/** The URL that was read. */
|
|
35
|
+
readonly url: string
|
|
36
|
+
/** Extracted content in the requested {@link ReadFormat}. */
|
|
37
|
+
readonly content: string
|
|
38
|
+
/** Page title, when reported. */
|
|
39
|
+
readonly title?: string
|
|
40
|
+
/** Links discovered on the page, when returned. */
|
|
41
|
+
readonly links?: ReadonlyArray<string>
|
|
42
|
+
/** The provider-native response. */
|
|
43
|
+
readonly raw: unknown
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// ---------------------------------------------------------------------------
|
|
47
|
+
// Service + helper
|
|
48
|
+
// ---------------------------------------------------------------------------
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* The portable read surface: one operation, `read`. Every implementor can
|
|
52
|
+
* answer, so this capability needs no marker tags.
|
|
53
|
+
*/
|
|
54
|
+
export type WebReadService = {
|
|
55
|
+
readonly read: (request: CommonReadRequest) => Effect.Effect<ReadResponse, AiError.AiError>
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Generic read service tag. Yield this for provider-portable code; yield a
|
|
60
|
+
* provider tag for provider-specific knobs. A provider `layer` registers both.
|
|
61
|
+
*/
|
|
62
|
+
export class WebRead extends Context.Service<WebRead, WebReadService>()(
|
|
63
|
+
"@betalyra/effect-uai/WebRead",
|
|
64
|
+
) {}
|
|
65
|
+
|
|
66
|
+
/** Read one URL against whichever provider Layer is in scope. */
|
|
67
|
+
export const read = (
|
|
68
|
+
request: CommonReadRequest,
|
|
69
|
+
): Effect.Effect<ReadResponse, AiError.AiError, WebRead> =>
|
|
70
|
+
Effect.flatMap(WebRead.asEffect(), (s) => s.read(request))
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { Effect, Schema } from "effect"
|
|
2
|
+
import type * as AiError from "../domain/AiError.js"
|
|
3
|
+
import * as Tool from "../tool/Tool.js"
|
|
4
|
+
import { read, type ReadFormat, type ReadResponse, WebRead } from "./WebRead.js"
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Model-facing argument schema. Deliberately narrow: the URL is the only
|
|
8
|
+
* thing that is genuinely the model's call. Output format and the content
|
|
9
|
+
* cost ceiling are app policy, pinned on the constructor instead, so they
|
|
10
|
+
* are guaranteed rather than left to the model to remember each call.
|
|
11
|
+
*/
|
|
12
|
+
const WebReadToolArgs = Schema.Struct({
|
|
13
|
+
url: Schema.String.annotate({
|
|
14
|
+
description: "Absolute URL of the page to read.",
|
|
15
|
+
}),
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
export type WebReadToolArgs = typeof WebReadToolArgs.Type
|
|
19
|
+
|
|
20
|
+
/** `title / url` header plus the extracted content - what a model reads best. */
|
|
21
|
+
const defaultRender = (response: ReadResponse, maxChars: number): string => {
|
|
22
|
+
const header = response.title === undefined ? response.url : `${response.title}\n${response.url}`
|
|
23
|
+
const body =
|
|
24
|
+
response.content.length > maxChars
|
|
25
|
+
? `${response.content.slice(0, maxChars)}\n[content truncated at ${maxChars} characters]`
|
|
26
|
+
: response.content
|
|
27
|
+
return `${header}\n\n${body}`
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export type WebReadToolOptions = {
|
|
31
|
+
/** Tool name the model sees. Default `"web_read"`. */
|
|
32
|
+
readonly name?: string
|
|
33
|
+
/**
|
|
34
|
+
* App-fixed representation for every read - a policy choice, not a model
|
|
35
|
+
* knob. Default `"markdown"` (what models read best).
|
|
36
|
+
*/
|
|
37
|
+
readonly format?: ReadFormat
|
|
38
|
+
/**
|
|
39
|
+
* App-fixed ceiling on rendered content characters per call - a context
|
|
40
|
+
* cost guard, not exposed to the model. Default `20000`.
|
|
41
|
+
*/
|
|
42
|
+
readonly maxChars?: number
|
|
43
|
+
/**
|
|
44
|
+
* Override how a read response is rendered into the model-facing string.
|
|
45
|
+
* Default: `title / url` header plus the content, truncated at `maxChars`.
|
|
46
|
+
*/
|
|
47
|
+
readonly render?: (response: ReadResponse) => string
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* The canonical web-read tool. Its `R` is just `WebRead`, so providing any
|
|
52
|
+
* read-provider Layer satisfies it and the model-facing contract (name,
|
|
53
|
+
* description, schema) is identical no matter which backend answers - swap
|
|
54
|
+
* `FirecrawlRead.layer` for `JinaRead.layer` and the tool the model sees
|
|
55
|
+
* does not change. Drops straight into a `Toolkit` next to `webSearchTool`
|
|
56
|
+
* (search finds the URLs, read fetches the ones worth reading in full).
|
|
57
|
+
*
|
|
58
|
+
* `Output` is the rendered page; failures stay typed on the `AiError`
|
|
59
|
+
* channel. To let the model recover from a failed read, wrap the toolkit in
|
|
60
|
+
* `Toolkit.describeFailures(AiError.describe)`.
|
|
61
|
+
*
|
|
62
|
+
* This is a simple default implementation for quick use. For more elaborate
|
|
63
|
+
* cases (a different output contract, more model-facing knobs), build your
|
|
64
|
+
* own tool with `Tool.make` over the same `read` helper.
|
|
65
|
+
*/
|
|
66
|
+
export const webReadTool = (
|
|
67
|
+
options?: WebReadToolOptions,
|
|
68
|
+
): Tool.Tool<string, WebReadToolArgs, never, string, AiError.AiError, WebRead> => {
|
|
69
|
+
const name = options?.name ?? "web_read"
|
|
70
|
+
const format = options?.format ?? "markdown"
|
|
71
|
+
const maxChars = options?.maxChars ?? 20_000
|
|
72
|
+
const render = options?.render ?? ((response: ReadResponse) => defaultRender(response, maxChars))
|
|
73
|
+
return Tool.make({
|
|
74
|
+
name,
|
|
75
|
+
description:
|
|
76
|
+
"Read a web page and return its content as clean text. Use it to read a promising URL in full (e.g. one found via search).",
|
|
77
|
+
inputSchema: Tool.fromEffectSchema(WebReadToolArgs),
|
|
78
|
+
// The call is wrapped in a tracing span so agent traces show the tool
|
|
79
|
+
// invocation (url, format, content length) nested under the model turn.
|
|
80
|
+
// `withSpan` is a no-op until a Tracer is installed, so this is free by
|
|
81
|
+
// default and adds nothing to the requirements.
|
|
82
|
+
run: (args) =>
|
|
83
|
+
read({ url: args.url, format }).pipe(
|
|
84
|
+
Effect.tap((r) => Effect.annotateCurrentSpan("web_read.content_chars", r.content.length)),
|
|
85
|
+
Effect.map(render),
|
|
86
|
+
Effect.withSpan(name, {
|
|
87
|
+
kind: "client",
|
|
88
|
+
attributes: {
|
|
89
|
+
"web_read.url": args.url,
|
|
90
|
+
"web_read.format": format,
|
|
91
|
+
"web_read.max_chars": maxChars,
|
|
92
|
+
},
|
|
93
|
+
}),
|
|
94
|
+
),
|
|
95
|
+
})
|
|
96
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Effect, Schema } from "effect"
|
|
2
|
+
import type * as AiError from "../domain/AiError.js"
|
|
2
3
|
import * as Tool from "../tool/Tool.js"
|
|
3
4
|
import { search, SearchRecency, type SearchResult, WebSearch } from "./WebSearch.js"
|
|
4
5
|
|
|
@@ -59,14 +60,19 @@ export type WebSearchToolOptions = {
|
|
|
59
60
|
* `LanguageModel` tool-calling loop.
|
|
60
61
|
*
|
|
61
62
|
* The model controls only `query` and `recency`; domain scoping and the
|
|
62
|
-
* result cap are app policy, fixed here on the constructor. `Output` is
|
|
63
|
-
* rendered text
|
|
64
|
-
*
|
|
65
|
-
*
|
|
63
|
+
* result cap are app policy, fixed here on the constructor. `Output` is the
|
|
64
|
+
* rendered text (the model reads a numbered list better than raw
|
|
65
|
+
* `SearchResult[]`; pass `render` to change the format); failures stay typed
|
|
66
|
+
* on the `AiError` channel. To let the model recover from a failed search,
|
|
67
|
+
* wrap the toolkit in `Toolkit.describeFailures(AiError.describe)`.
|
|
68
|
+
*
|
|
69
|
+
* This is a simple default implementation for quick use. For more elaborate
|
|
70
|
+
* cases (a different output contract, more model-facing knobs), build your
|
|
71
|
+
* own tool with `Tool.make` over the same `search` helper.
|
|
66
72
|
*/
|
|
67
73
|
export const webSearchTool = (
|
|
68
74
|
options?: WebSearchToolOptions,
|
|
69
|
-
): Tool.Tool<string, WebSearchToolArgs, string, WebSearch> => {
|
|
75
|
+
): Tool.Tool<string, WebSearchToolArgs, never, string, AiError.AiError, WebSearch> => {
|
|
70
76
|
const name = options?.name ?? "web_search"
|
|
71
77
|
const render = options?.render ?? defaultRender
|
|
72
78
|
const maxResults = options?.maxResults ?? 5
|
package/dist/Tool-BKiieFXk.d.mts
DELETED
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
import { v as ToolCall, y as ToolCallOutput } from "./Items-7ljaVxH_.mjs";
|
|
2
|
-
import { Effect, Schema, Stream } from "effect";
|
|
3
|
-
import * as _$effect_Cause0 from "effect/Cause";
|
|
4
|
-
import { StandardJSONSchemaV1, StandardSchemaV1 } from "@standard-schema/spec";
|
|
5
|
-
|
|
6
|
-
//#region src/tool/Tool.d.ts
|
|
7
|
-
declare namespace Tool_d_exports {
|
|
8
|
-
export { AnyPlainTool, AnyStreamingTool, AnyTool, StreamingTool, Tool, ToolDescriptor, ToolError, ToolInputSchema, execute, fromEffectSchema, fromStandardSchema, isStreamingTool, make, streaming, toDescriptors };
|
|
9
|
-
}
|
|
10
|
-
declare const ToolError_base: Schema.Class<ToolError, Schema.TaggedStruct<"ToolError", {
|
|
11
|
-
readonly call_id: Schema.String;
|
|
12
|
-
readonly tool: Schema.String;
|
|
13
|
-
readonly message: Schema.String;
|
|
14
|
-
readonly cause: Schema.optional<Schema.Unknown>;
|
|
15
|
-
}>, _$effect_Cause0.YieldableError>;
|
|
16
|
-
declare class ToolError extends ToolError_base {}
|
|
17
|
-
/**
|
|
18
|
-
* Schemas accepted on `Tool.inputSchema`. Must implement both Standard
|
|
19
|
-
* Schema validation and JSON Schema conversion (for rendering tool
|
|
20
|
-
* descriptors to provider request bodies).
|
|
21
|
-
*
|
|
22
|
-
* Any Standard-Schema-compliant library that exposes both interfaces
|
|
23
|
-
* works directly: Zod 4+, Valibot, ArkType, Effect Schema (after
|
|
24
|
-
* `fromEffectSchema`), etc.
|
|
25
|
-
*/
|
|
26
|
-
type ToolInputSchema<Input = unknown> = StandardSchemaV1<unknown, Input> & StandardJSONSchemaV1<unknown, Input>;
|
|
27
|
-
/**
|
|
28
|
-
* Convenience wrapper for Effect Schema users - adds both the
|
|
29
|
-
* `validate` and `jsonSchema` extensions to a plain Effect Schema so it
|
|
30
|
-
* can be used as a `Tool.inputSchema`.
|
|
31
|
-
*/
|
|
32
|
-
declare const fromEffectSchema: <S extends Schema.Codec<any, any, never, any>>(schema: S) => S & ToolInputSchema<S["Type"]>;
|
|
33
|
-
/**
|
|
34
|
-
* Use any schema library that implements both Standard Schema (validation)
|
|
35
|
-
* and Standard JSON Schema (JSON Schema generation) as a `Tool.inputSchema`.
|
|
36
|
-
* Covers Zod 4.2+, Valibot 1.2+, and ArkType 2.1.28+ in one helper.
|
|
37
|
-
*
|
|
38
|
-
* Effect Schema doesn't implement Standard JSON Schema natively — use
|
|
39
|
-
* `fromEffectSchema` for those.
|
|
40
|
-
*
|
|
41
|
-
* The intersection constraint catches missing interfaces at compile time:
|
|
42
|
-
* a Zod v3 schema (no Standard JSON Schema) produces a precise type error
|
|
43
|
-
* pointing at the missing interface rather than a runtime surprise. The
|
|
44
|
-
* helper itself is a thin type-narrowing identity — schemas that satisfy
|
|
45
|
-
* both standards already structurally satisfy `ToolInputSchema`; the
|
|
46
|
-
* helper makes the input type inference explicit at the call site.
|
|
47
|
-
*/
|
|
48
|
-
declare const fromStandardSchema: <S extends StandardSchemaV1 & StandardJSONSchemaV1>(schema: S) => S & ToolInputSchema<StandardSchemaV1.InferOutput<S>>;
|
|
49
|
-
type Tool<Name extends string, Input, Output, R = never> = {
|
|
50
|
-
readonly name: Name;
|
|
51
|
-
readonly description: string;
|
|
52
|
-
readonly inputSchema: ToolInputSchema<Input>;
|
|
53
|
-
readonly run: (input: Input) => Effect.Effect<Output, unknown, R>;
|
|
54
|
-
/**
|
|
55
|
-
* Whether the provider should render this tool with its strict-mode
|
|
56
|
-
* flag (OpenAI's `strict: true`, etc). Default: true. The framework
|
|
57
|
-
* never rewrites the schema; if the rendered JSON Schema isn't
|
|
58
|
-
* compatible, the provider returns an error.
|
|
59
|
-
*/
|
|
60
|
-
readonly strict?: boolean;
|
|
61
|
-
};
|
|
62
|
-
/**
|
|
63
|
-
* Provider-agnostic tool descriptor. Each provider maps `inputSchema`
|
|
64
|
-
* to its own wire field (OpenAI → `parameters`, Anthropic →
|
|
65
|
-
* `input_schema`). Built from a `Tool` by `Tool.toDescriptors`.
|
|
66
|
-
*/
|
|
67
|
-
type ToolDescriptor = {
|
|
68
|
-
readonly name: string;
|
|
69
|
-
readonly description: string;
|
|
70
|
-
readonly inputSchema: Record<string, unknown>;
|
|
71
|
-
readonly strict?: boolean;
|
|
72
|
-
};
|
|
73
|
-
declare const make: <Name extends string, Input, Output, R = never>(spec: Tool<Name, Input, Output, R>) => Tool<Name, Input, Output, R>;
|
|
74
|
-
type StreamingTool<Name extends string, Input, Event, Output, R = never> = {
|
|
75
|
-
readonly _kind: "streaming";
|
|
76
|
-
readonly name: Name;
|
|
77
|
-
readonly description: string;
|
|
78
|
-
readonly inputSchema: ToolInputSchema<Input>;
|
|
79
|
-
readonly run: (input: Input) => Stream.Stream<Event, unknown, R>;
|
|
80
|
-
readonly finalize: (events: ReadonlyArray<Event>) => Output;
|
|
81
|
-
readonly strict?: boolean;
|
|
82
|
-
};
|
|
83
|
-
declare const streaming: <Name extends string, Input, Event, Output, R = never>(spec: Omit<StreamingTool<Name, Input, Event, Output, R>, "_kind">) => StreamingTool<Name, Input, Event, Output, R>;
|
|
84
|
-
type AnyStreamingTool<R = any> = StreamingTool<string, any, any, any, R>;
|
|
85
|
-
type AnyPlainTool<R = any> = Tool<string, any, any, R>;
|
|
86
|
-
type AnyTool<R = any> = AnyStreamingTool<R> | AnyPlainTool<R>;
|
|
87
|
-
declare const isStreamingTool: <R>(t: AnyTool<R>) => t is AnyStreamingTool<R>;
|
|
88
|
-
/**
|
|
89
|
-
* Render any-kind tools (mixed plain and streaming) to provider-agnostic
|
|
90
|
-
* descriptors. Accepts the union type so a single list can carry both
|
|
91
|
-
* plain and streaming tools.
|
|
92
|
-
*/
|
|
93
|
-
declare const toDescriptors: <R>(tools: ReadonlyArray<AnyTool<R>>) => ReadonlyArray<ToolDescriptor>;
|
|
94
|
-
/**
|
|
95
|
-
* Decode and validate the JSON arguments of a function_call against the
|
|
96
|
-
* tool's input schema, run the tool, and serialize the output into a
|
|
97
|
-
* function_call_output item.
|
|
98
|
-
*/
|
|
99
|
-
declare const execute: <Name extends string, Input, Output, R>(tool: Tool<Name, Input, Output, R>, call: ToolCall) => Effect.Effect<ToolCallOutput, ToolError, R>;
|
|
100
|
-
//#endregion
|
|
101
|
-
export { Tool as a, ToolInputSchema as c, fromEffectSchema as d, fromStandardSchema as f, toDescriptors as g, streaming as h, StreamingTool as i, Tool_d_exports as l, make as m, AnyStreamingTool as n, ToolDescriptor as o, isStreamingTool as p, AnyTool as r, ToolError as s, AnyPlainTool as t, execute as u };
|
|
102
|
-
//# sourceMappingURL=Tool-BKiieFXk.d.mts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Tool-BKiieFXk.d.mts","names":[],"sources":["../src/tool/Tool.ts"],"mappings":";;;;;;;;;cAEkE,cAAA;;;;;;cAGrD,SAAA,SAAkB,cAAA;;;;;;;;;;KAmBnB,eAAA,oBAAmC,gBAAA,UAA0B,KAAA,IACvE,oBAAA,UAA8B,KAAA;;;;AAvBkC;;cA8BrD,gBAAA,aAA8B,MAAA,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A,CAAgB,eAAA,CAAgB,CAAA;AAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ToolEvent.d.mts","names":[],"sources":["../../src/tool/ToolEvent.ts"],"mappings":";;;;;;;;KAaY,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;;;;;AAWrB;;;cAAa,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 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ToolResult.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;;;;;;AAYb;;;cAAa,UAAA;EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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