@effect-uai/core 0.12.0 → 0.13.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-Bf1pq4BB.d.mts → AiError-eLV9t1lU.d.mts} +12 -16
- package/dist/AiError-eLV9t1lU.d.mts.map +1 -0
- package/dist/{Audio-CR7CSljJ.d.mts → Audio-60lKKHxS.d.mts} +4 -5
- package/dist/Audio-60lKKHxS.d.mts.map +1 -0
- package/dist/{Image-C4vuBmu0.d.mts → Image-BK8-4H6s.d.mts} +12 -14
- package/dist/Image-BK8-4H6s.d.mts.map +1 -0
- package/dist/{Items-BKQgqJ8A.d.mts → Items-SfUabNuB.d.mts} +74 -76
- package/dist/Items-SfUabNuB.d.mts.map +1 -0
- package/dist/{Loop-D8nWpowc.d.mts → Loop-B54AB1ME.d.mts} +19 -21
- package/dist/Loop-B54AB1ME.d.mts.map +1 -0
- package/dist/{Media-D_CpcM1Z.d.mts → Media-DwgpifPD.d.mts} +1 -1
- package/dist/Media-DwgpifPD.d.mts.map +1 -0
- package/dist/{SandboxError-CIrVDOMV.d.mts → SandboxError-BN8b28Bh.d.mts} +11 -15
- package/dist/SandboxError-BN8b28Bh.d.mts.map +1 -0
- package/dist/{StructuredFormat-DHaUJBdd.d.mts → StructuredFormat-BlZhyOsi.d.mts} +3 -7
- package/dist/StructuredFormat-BlZhyOsi.d.mts.map +1 -0
- package/dist/{Tool-u5bag8SO.d.mts → Tool-DE-rnvkw.d.mts} +5 -8
- package/dist/Tool-DE-rnvkw.d.mts.map +1 -0
- package/dist/{ToolEvent-BBfOdhF_.d.mts → ToolEvent-D99MGQYH.d.mts} +56 -63
- package/dist/ToolEvent-D99MGQYH.d.mts.map +1 -0
- package/dist/{ToolResult-CRpmkBXR.d.mts → ToolResult-Cj8ChodL.d.mts} +49 -54
- package/dist/ToolResult-Cj8ChodL.d.mts.map +1 -0
- package/dist/{Toolkit-D4mQvhjq.d.mts → Toolkit-BEZrNPTI.d.mts} +13 -16
- package/dist/Toolkit-BEZrNPTI.d.mts.map +1 -0
- package/dist/browser/Browser.d.mts +11 -7
- package/dist/browser/Browser.d.mts.map +1 -1
- package/dist/browser/Browser.mjs +1 -1
- package/dist/browser/Browser.mjs.map +1 -1
- package/dist/browser/BrowserError.d.mts +9 -13
- package/dist/browser/BrowserError.d.mts.map +1 -1
- package/dist/browser/BrowserError.mjs +1 -1
- package/dist/browser/BrowserError.mjs.map +1 -1
- package/dist/browser/BrowserTool.d.mts +33 -36
- package/dist/browser/BrowserTool.d.mts.map +1 -1
- package/dist/browser/BrowserTool.mjs +1 -1
- package/dist/browser/BrowserTool.mjs.map +1 -1
- package/dist/capabilities/Capabilities.d.mts +8 -6
- package/dist/capabilities/Capabilities.d.mts.map +1 -1
- package/dist/capabilities/Capabilities.mjs +1 -1
- package/dist/capabilities/Capabilities.mjs.map +1 -1
- package/dist/chunker/Chunker.d.mts +32 -0
- package/dist/chunker/Chunker.d.mts.map +1 -0
- package/dist/chunker/Chunker.mjs +14 -0
- package/dist/chunker/Chunker.mjs.map +1 -0
- package/dist/dist-BaenoU1A.mjs +145 -0
- package/dist/dist-BaenoU1A.mjs.map +1 -0
- package/dist/{dist-C0m0QnUP.mjs → dist-nohcnkD6.mjs} +16 -15
- package/dist/dist-nohcnkD6.mjs.map +1 -0
- package/dist/domain/AiError.d.mts +1 -1
- package/dist/domain/AiError.mjs +1 -1
- package/dist/domain/AiError.mjs.map +1 -1
- package/dist/domain/Audio.d.mts +1 -1
- package/dist/domain/Audio.mjs +1 -1
- package/dist/domain/Citation.d.mts +0 -2
- package/dist/domain/Citation.d.mts.map +1 -1
- package/dist/domain/Citation.mjs +1 -1
- package/dist/domain/Image.d.mts +1 -1
- package/dist/domain/Image.mjs +1 -1
- package/dist/domain/Image.mjs.map +1 -1
- package/dist/domain/Items.d.mts +1 -1
- package/dist/domain/Items.mjs +1 -1
- package/dist/domain/Items.mjs.map +1 -1
- package/dist/domain/Media.d.mts +1 -1
- package/dist/domain/Media.mjs +1 -1
- package/dist/domain/Music.d.mts +18 -11
- package/dist/domain/Music.d.mts.map +1 -1
- package/dist/domain/Music.mjs +1 -1
- package/dist/domain/Music.mjs.map +1 -1
- package/dist/domain/Research.d.mts +3 -4
- package/dist/domain/Research.d.mts.map +1 -1
- package/dist/domain/Research.mjs +1 -1
- package/dist/domain/Transcript.d.mts +2 -3
- package/dist/domain/Transcript.d.mts.map +1 -1
- package/dist/domain/Transcript.mjs +1 -1
- package/dist/domain/Turn.d.mts +143 -164
- package/dist/domain/Turn.d.mts.map +1 -1
- package/dist/domain/Turn.mjs +1 -1
- package/dist/domain/Turn.mjs.map +1 -1
- package/dist/domain/Turn.test.d.mts +1 -1
- package/dist/domain/Turn.test.mjs +28 -18
- package/dist/domain/Turn.test.mjs.map +1 -1
- package/dist/embedding-model/Embedding.d.mts +1 -3
- package/dist/embedding-model/Embedding.d.mts.map +1 -1
- package/dist/embedding-model/Embedding.mjs +1 -1
- package/dist/embedding-model/EmbeddingModel.d.mts +1 -3
- package/dist/embedding-model/EmbeddingModel.d.mts.map +1 -1
- package/dist/embedding-model/EmbeddingModel.mjs +1 -1
- package/dist/embedding-model/EmbeddingModel.mjs.map +1 -1
- package/dist/embedding-model/EmbeddingModel.test.d.mts +1 -1
- package/dist/embedding-model/EmbeddingModel.test.mjs +14 -9
- package/dist/embedding-model/EmbeddingModel.test.mjs.map +1 -1
- package/dist/index.d.mts +16 -13
- package/dist/index.mjs +4 -1
- package/dist/job/Job.d.mts +4 -4
- package/dist/job/Job.d.mts.map +1 -1
- package/dist/job/Job.mjs +1 -1
- package/dist/job/Job.mjs.map +1 -1
- package/dist/language-model/LanguageModel.d.mts +4 -6
- package/dist/language-model/LanguageModel.d.mts.map +1 -1
- package/dist/language-model/LanguageModel.mjs +1 -1
- package/dist/language-model/LanguageModel.mjs.map +1 -1
- package/dist/language-model/LanguageModel.test.d.mts +1 -1
- package/dist/language-model/LanguageModel.test.mjs +6 -3
- package/dist/language-model/LanguageModel.test.mjs.map +1 -1
- package/dist/loop/Loop.d.mts +1 -1
- package/dist/loop/Loop.mjs +1 -1
- package/dist/loop/Loop.mjs.map +1 -1
- package/dist/loop/Loop.test.d.mts +1 -1
- package/dist/loop/Loop.test.mjs +60 -34
- package/dist/loop/Loop.test.mjs.map +1 -1
- package/dist/{magic-string.es-Dk-MMA0F.mjs → magic-string.es-CB2hOw9v.mjs} +14 -13
- package/dist/{magic-string.es-Dk-MMA0F.mjs.map → magic-string.es-CB2hOw9v.mjs.map} +1 -1
- package/dist/math/Vector.d.mts +0 -2
- package/dist/math/Vector.d.mts.map +1 -1
- package/dist/math/Vector.mjs +1 -1
- package/dist/math/Vector.mjs.map +1 -1
- package/dist/music-generator/MusicGenerator.d.mts +2 -4
- package/dist/music-generator/MusicGenerator.d.mts.map +1 -1
- package/dist/music-generator/MusicGenerator.mjs +1 -1
- package/dist/music-generator/MusicGenerator.mjs.map +1 -1
- package/dist/music-generator/MusicGenerator.test.d.mts +1 -1
- package/dist/music-generator/MusicGenerator.test.mjs +19 -10
- package/dist/music-generator/MusicGenerator.test.mjs.map +1 -1
- package/dist/observability/Metrics.d.mts +10 -7
- package/dist/observability/Metrics.d.mts.map +1 -1
- package/dist/observability/Metrics.mjs +1 -1
- package/dist/observability/Metrics.mjs.map +1 -1
- package/dist/observability/Metrics.test.d.mts +1 -1
- package/dist/observability/Metrics.test.mjs +50 -28
- package/dist/observability/Metrics.test.mjs.map +1 -1
- package/dist/observability/Telemetry.d.mts +2 -3
- package/dist/observability/Telemetry.d.mts.map +1 -1
- package/dist/observability/Telemetry.mjs +1 -1
- package/dist/observability/Telemetry.mjs.map +1 -1
- package/dist/observability/Telemetry.test.d.mts +1 -1
- package/dist/observability/Telemetry.test.mjs +15 -7
- package/dist/observability/Telemetry.test.mjs.map +1 -1
- package/dist/reranker/Reranker.d.mts +46 -0
- package/dist/reranker/Reranker.d.mts.map +1 -0
- package/dist/reranker/Reranker.mjs +14 -0
- package/dist/reranker/Reranker.mjs.map +1 -0
- package/dist/research/DeepResearch.d.mts +1 -3
- package/dist/research/DeepResearch.d.mts.map +1 -1
- package/dist/research/DeepResearch.mjs +1 -1
- package/dist/research/DeepResearch.mjs.map +1 -1
- package/dist/retry/Retry.d.mts +2 -6
- package/dist/retry/Retry.d.mts.map +1 -1
- package/dist/retry/Retry.mjs +1 -1
- package/dist/retry/Retry.mjs.map +1 -1
- package/dist/retry/Retry.test.d.mts +1 -1
- package/dist/retry/Retry.test.mjs +6 -3
- package/dist/retry/Retry.test.mjs.map +1 -1
- package/dist/sandbox/Memory.d.mts +0 -2
- package/dist/sandbox/Memory.d.mts.map +1 -1
- package/dist/sandbox/Memory.mjs +4 -4
- package/dist/sandbox/Memory.mjs.map +1 -1
- package/dist/sandbox/Sandbox.d.mts +144 -156
- package/dist/sandbox/Sandbox.d.mts.map +1 -1
- package/dist/sandbox/Sandbox.mjs +1 -1
- package/dist/sandbox/Sandbox.mjs.map +1 -1
- package/dist/sandbox/SandboxError.d.mts +1 -1
- package/dist/sandbox/SandboxError.mjs +1 -1
- package/dist/sandbox/SandboxError.mjs.map +1 -1
- package/dist/sandbox/SandboxImage.d.mts +0 -2
- package/dist/sandbox/SandboxImage.d.mts.map +1 -1
- package/dist/sandbox/SandboxImage.mjs +1 -1
- package/dist/sandbox/SandboxImage.mjs.map +1 -1
- package/dist/sandbox/SandboxNetwork.d.mts +0 -2
- package/dist/sandbox/SandboxNetwork.d.mts.map +1 -1
- package/dist/sandbox/SandboxNetwork.mjs +1 -1
- package/dist/sandbox/SandboxNetwork.mjs.map +1 -1
- package/dist/speech-synthesizer/SpeechSynthesizer.d.mts +8 -7
- package/dist/speech-synthesizer/SpeechSynthesizer.d.mts.map +1 -1
- package/dist/speech-synthesizer/SpeechSynthesizer.mjs +1 -1
- package/dist/speech-synthesizer/SpeechSynthesizer.mjs.map +1 -1
- package/dist/speech-synthesizer/SpeechSynthesizer.test.d.mts +1 -1
- package/dist/speech-synthesizer/SpeechSynthesizer.test.mjs +31 -16
- package/dist/speech-synthesizer/SpeechSynthesizer.test.mjs.map +1 -1
- package/dist/streaming/JSONL.d.mts +1 -5
- package/dist/streaming/JSONL.d.mts.map +1 -1
- package/dist/streaming/JSONL.mjs +1 -1
- package/dist/streaming/JSONL.mjs.map +1 -1
- package/dist/streaming/JSONL.test.d.mts +1 -1
- package/dist/streaming/JSONL.test.mjs +16 -8
- package/dist/streaming/JSONL.test.mjs.map +1 -1
- package/dist/streaming/Lines.d.mts +0 -2
- package/dist/streaming/Lines.d.mts.map +1 -1
- package/dist/streaming/Lines.mjs +1 -1
- package/dist/streaming/Lines.mjs.map +1 -1
- package/dist/streaming/SSE.d.mts +0 -2
- package/dist/streaming/SSE.d.mts.map +1 -1
- package/dist/streaming/SSE.mjs +1 -1
- package/dist/streaming/SSE.mjs.map +1 -1
- package/dist/streaming/SSE.test.d.mts +1 -1
- package/dist/streaming/SSE.test.mjs +34 -17
- package/dist/streaming/SSE.test.mjs.map +1 -1
- package/dist/structured-format/StructuredFormat.d.mts +1 -1
- package/dist/structured-format/StructuredFormat.mjs +1 -1
- package/dist/structured-format/StructuredFormat.mjs.map +1 -1
- package/dist/structured-format/StructuredFormat.test.d.mts +1 -1
- package/dist/structured-format/StructuredFormat.test.mjs +7 -4
- package/dist/structured-format/StructuredFormat.test.mjs.map +1 -1
- package/dist/{dist-CcRV3-A5.mjs → test.DNmyFkvJ-YPzDR0Co.mjs} +1644 -5172
- package/dist/test.DNmyFkvJ-YPzDR0Co.mjs.map +1 -0
- package/dist/testing/MockMusicGenerator.d.mts +4 -3
- package/dist/testing/MockMusicGenerator.d.mts.map +1 -1
- package/dist/testing/MockMusicGenerator.mjs.map +1 -1
- package/dist/testing/MockProvider.d.mts +1 -2
- package/dist/testing/MockProvider.d.mts.map +1 -1
- package/dist/testing/MockProvider.mjs.map +1 -1
- package/dist/testing/MockSandbox.d.mts +256 -290
- package/dist/testing/MockSandbox.d.mts.map +1 -1
- package/dist/testing/MockSandbox.mjs.map +1 -1
- package/dist/testing/MockSpeechSynthesizer.d.mts +10 -6
- package/dist/testing/MockSpeechSynthesizer.d.mts.map +1 -1
- package/dist/testing/MockSpeechSynthesizer.mjs.map +1 -1
- package/dist/testing/MockTranscriber.d.mts +3 -2
- package/dist/testing/MockTranscriber.d.mts.map +1 -1
- package/dist/testing/MockTranscriber.mjs.map +1 -1
- package/dist/tokenizer/Tokenizer.d.mts +22 -0
- package/dist/tokenizer/Tokenizer.d.mts.map +1 -0
- package/dist/tokenizer/Tokenizer.mjs +9 -0
- package/dist/tokenizer/Tokenizer.mjs.map +1 -0
- package/dist/tool/Approval.d.mts +31 -36
- package/dist/tool/Approval.d.mts.map +1 -1
- package/dist/tool/Approval.mjs +1 -1
- package/dist/tool/Approval.mjs.map +1 -1
- package/dist/tool/Approval.test.d.mts +1 -1
- package/dist/tool/Approval.test.mjs +37 -24
- package/dist/tool/Approval.test.mjs.map +1 -1
- package/dist/tool/HistoryCheck.d.mts +2 -4
- package/dist/tool/HistoryCheck.d.mts.map +1 -1
- package/dist/tool/HistoryCheck.mjs +1 -1
- package/dist/tool/HistoryCheck.mjs.map +1 -1
- package/dist/tool/Tool.d.mts +1 -1
- package/dist/tool/Tool.mjs +4 -4
- package/dist/tool/Tool.mjs.map +1 -1
- package/dist/tool/Tool.test.d.mts +1 -1
- package/dist/tool/Tool.test.mjs +23 -11
- package/dist/tool/Tool.test.mjs.map +1 -1
- package/dist/tool/ToolEvent.d.mts +1 -1
- package/dist/tool/ToolEvent.mjs +1 -1
- package/dist/tool/ToolEvent.mjs.map +1 -1
- package/dist/tool/ToolResult.d.mts +1 -1
- package/dist/tool/ToolResult.mjs +1 -1
- package/dist/tool/ToolResult.mjs.map +1 -1
- package/dist/tool/Toolkit.d.mts +1 -1
- package/dist/tool/Toolkit.mjs +4 -3
- package/dist/tool/Toolkit.mjs.map +1 -1
- package/dist/tool/Toolkit.test.d.mts +1 -1
- package/dist/tool/Toolkit.test.mjs +40 -21
- package/dist/tool/Toolkit.test.mjs.map +1 -1
- package/dist/transcriber/Transcriber.d.mts +6 -6
- package/dist/transcriber/Transcriber.d.mts.map +1 -1
- package/dist/transcriber/Transcriber.mjs +1 -1
- package/dist/transcriber/Transcriber.mjs.map +1 -1
- package/dist/transcriber/Transcriber.test.d.mts +1 -1
- package/dist/transcriber/Transcriber.test.mjs +20 -10
- package/dist/transcriber/Transcriber.test.mjs.map +1 -1
- package/dist/utils-CiH_DjFW.mjs +3918 -0
- package/dist/utils-CiH_DjFW.mjs.map +1 -0
- package/dist/web-read/WebRead.d.mts +15 -9
- package/dist/web-read/WebRead.d.mts.map +1 -1
- package/dist/web-read/WebRead.mjs +1 -1
- package/dist/web-read/WebRead.mjs.map +1 -1
- package/dist/web-read/WebReadTool.d.mts +4 -5
- package/dist/web-read/WebReadTool.d.mts.map +1 -1
- package/dist/web-read/WebReadTool.mjs +1 -1
- package/dist/web-read/WebReadTool.mjs.map +1 -1
- package/dist/web-search/WebSearch.d.mts +22 -13
- package/dist/web-search/WebSearch.d.mts.map +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 +6 -6
- package/dist/web-search/WebSearchTool.d.mts.map +1 -1
- package/dist/web-search/WebSearchTool.mjs +1 -1
- package/dist/web-search/WebSearchTool.mjs.map +1 -1
- package/package.json +16 -4
- package/src/chunker/Chunker.ts +34 -0
- package/src/index.ts +3 -0
- package/src/loop/Loop.test.ts +13 -14
- package/src/loop/Loop.ts +74 -76
- package/src/reranker/Reranker.ts +51 -0
- package/src/testing/MockProvider.ts +8 -9
- package/src/tokenizer/Tokenizer.ts +19 -0
- package/src/tool/Tool.ts +13 -13
- package/dist/AiError-Bf1pq4BB.d.mts.map +0 -1
- package/dist/Audio-CR7CSljJ.d.mts.map +0 -1
- package/dist/Image-C4vuBmu0.d.mts.map +0 -1
- package/dist/Items-BKQgqJ8A.d.mts.map +0 -1
- package/dist/Loop-D8nWpowc.d.mts.map +0 -1
- package/dist/Media-D_CpcM1Z.d.mts.map +0 -1
- package/dist/SandboxError-CIrVDOMV.d.mts.map +0 -1
- package/dist/StructuredFormat-DHaUJBdd.d.mts.map +0 -1
- package/dist/Tool-u5bag8SO.d.mts.map +0 -1
- package/dist/ToolEvent-BBfOdhF_.d.mts.map +0 -1
- package/dist/ToolResult-CRpmkBXR.d.mts.map +0 -1
- package/dist/Toolkit-D4mQvhjq.d.mts.map +0 -1
- package/dist/dist-C0m0QnUP.mjs.map +0 -1
- package/dist/dist-CcRV3-A5.mjs.map +0 -1
- /package/dist/{chunk-uyGKjUfl.mjs → rolldown-runtime-EAsCxrDo.mjs} +0 -0
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import { t as AiError } from "../AiError-
|
|
1
|
+
import { t as AiError } from "../AiError-eLV9t1lU.mjs";
|
|
2
2
|
import { Context, Duration, Effect } from "effect";
|
|
3
|
-
|
|
4
|
-
//#region src/web-read/WebRead.d.ts
|
|
5
3
|
declare namespace WebRead_d_exports {
|
|
6
4
|
export { CommonReadRequest, ReadFormat, ReadResponse, WebRead, WebReadService, read };
|
|
7
5
|
}
|
|
@@ -12,16 +10,24 @@ type ReadFormat = "markdown" | "html";
|
|
|
12
10
|
* knobs live on the provider-typed request.
|
|
13
11
|
*/
|
|
14
12
|
type CommonReadRequest = {
|
|
15
|
-
/** The page to read. */
|
|
16
|
-
readonly
|
|
13
|
+
/** The page to read. */
|
|
14
|
+
readonly url: string;
|
|
15
|
+
/** Output representation. Defaults to `markdown`. See {@link ReadFormat}. */
|
|
16
|
+
readonly format?: ReadFormat;
|
|
17
|
+
/** Upper bound on time spent fetching the page. */
|
|
17
18
|
readonly timeout?: Duration.Duration;
|
|
18
19
|
};
|
|
19
20
|
/** One normalized read result. */
|
|
20
21
|
type ReadResponse = {
|
|
21
|
-
/** The URL that was read. */
|
|
22
|
-
readonly
|
|
23
|
-
|
|
24
|
-
readonly
|
|
22
|
+
/** The URL that was read. */
|
|
23
|
+
readonly url: string;
|
|
24
|
+
/** Extracted content in the requested {@link ReadFormat}. */
|
|
25
|
+
readonly content: string;
|
|
26
|
+
/** Page title, when reported. */
|
|
27
|
+
readonly title?: string;
|
|
28
|
+
/** Links discovered on the page, when returned. */
|
|
29
|
+
readonly links?: ReadonlyArray<string>;
|
|
30
|
+
/** The provider-native response. */
|
|
25
31
|
readonly raw: unknown;
|
|
26
32
|
};
|
|
27
33
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WebRead.d.mts","names":[],"sources":["../../src/web-read/WebRead.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"WebRead.d.mts","names":[],"sources":["../../src/web-read/WebRead.ts"],"mappings":";;;;;;KAQY;;;;;KAUA;;WAED;;WAEA,SAAS;;WAET,UAAU,SAAS;;;KAQlB;;WAED;;WAEA;;WAEA;;WAEA,QAAQ;;WAER;;;;;;KAWC;WACD,OAAO,SAAS,sBAAsB,OAAO,OAAO,cAAc;;;;;;;cAOhE,gBAAgB;;cAKhB,OAAI,SACN,sBACR,OAAO,OAAO,cAAc,SAAiB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WebRead.mjs","names":[],"sources":["../../src/web-read/WebRead.ts"],"sourcesContent":["import { Context, type Duration, Effect } from \"effect\"\nimport type * as AiError from \"../domain/AiError.js\"\n\n// ---------------------------------------------------------------------------\n// Format\n// ---------------------------------------------------------------------------\n\n/** Representation to return for a page. `markdown` is the default. */\nexport type ReadFormat = \"markdown\" | \"html\"\n\n// ---------------------------------------------------------------------------\n// Request\n// ---------------------------------------------------------------------------\n\n/**\n * Cross-provider read request: one URL in, clean content out. Provider-specific\n * knobs live on the provider-typed request.\n */\nexport type CommonReadRequest = {\n /** The page to read. */\n readonly url: string\n /** Output representation. Defaults to `markdown`. See {@link ReadFormat}. */\n readonly format?: ReadFormat\n /** Upper bound on time spent fetching the page. */\n readonly timeout?: Duration.Duration\n}\n\n// ---------------------------------------------------------------------------\n// Response\n// ---------------------------------------------------------------------------\n\n/** One normalized read result. */\nexport type ReadResponse = {\n /** The URL that was read. */\n readonly url: string\n /** Extracted content in the requested {@link ReadFormat}. */\n readonly content: string\n /** Page title, when reported. */\n readonly title?: string\n /** Links discovered on the page, when returned. */\n readonly links?: ReadonlyArray<string>\n /** The provider-native response. */\n readonly raw: unknown\n}\n\n// ---------------------------------------------------------------------------\n// Service + helper\n// ---------------------------------------------------------------------------\n\n/**\n * The portable read surface: one operation, `read`. Every implementor can\n * answer, so this capability needs no marker tags.\n */\nexport type WebReadService = {\n readonly read: (request: CommonReadRequest) => Effect.Effect<ReadResponse, AiError.AiError>\n}\n\n/**\n * Generic read service tag. Yield this for provider-portable code; yield a\n * provider tag for provider-specific knobs. A provider `layer` registers both.\n */\nexport class WebRead extends Context.Service<WebRead, WebReadService>()(\n \"@betalyra/effect-uai/WebRead\",\n) {}\n\n/** Read one URL against whichever provider Layer is in scope. */\nexport const read = (\n request: CommonReadRequest,\n): Effect.Effect<ReadResponse, AiError.AiError, WebRead> =>\n Effect.flatMap(WebRead, (s) => s.read(request))\n"],"mappings":";;;;;;;;;;;AA6DA,IAAa,UAAb,cAA6B,QAAQ,
|
|
1
|
+
{"version":3,"file":"WebRead.mjs","names":[],"sources":["../../src/web-read/WebRead.ts"],"sourcesContent":["import { Context, type Duration, Effect } from \"effect\"\nimport type * as AiError from \"../domain/AiError.js\"\n\n// ---------------------------------------------------------------------------\n// Format\n// ---------------------------------------------------------------------------\n\n/** Representation to return for a page. `markdown` is the default. */\nexport type ReadFormat = \"markdown\" | \"html\"\n\n// ---------------------------------------------------------------------------\n// Request\n// ---------------------------------------------------------------------------\n\n/**\n * Cross-provider read request: one URL in, clean content out. Provider-specific\n * knobs live on the provider-typed request.\n */\nexport type CommonReadRequest = {\n /** The page to read. */\n readonly url: string\n /** Output representation. Defaults to `markdown`. See {@link ReadFormat}. */\n readonly format?: ReadFormat\n /** Upper bound on time spent fetching the page. */\n readonly timeout?: Duration.Duration\n}\n\n// ---------------------------------------------------------------------------\n// Response\n// ---------------------------------------------------------------------------\n\n/** One normalized read result. */\nexport type ReadResponse = {\n /** The URL that was read. */\n readonly url: string\n /** Extracted content in the requested {@link ReadFormat}. */\n readonly content: string\n /** Page title, when reported. */\n readonly title?: string\n /** Links discovered on the page, when returned. */\n readonly links?: ReadonlyArray<string>\n /** The provider-native response. */\n readonly raw: unknown\n}\n\n// ---------------------------------------------------------------------------\n// Service + helper\n// ---------------------------------------------------------------------------\n\n/**\n * The portable read surface: one operation, `read`. Every implementor can\n * answer, so this capability needs no marker tags.\n */\nexport type WebReadService = {\n readonly read: (request: CommonReadRequest) => Effect.Effect<ReadResponse, AiError.AiError>\n}\n\n/**\n * Generic read service tag. Yield this for provider-portable code; yield a\n * provider tag for provider-specific knobs. A provider `layer` registers both.\n */\nexport class WebRead extends Context.Service<WebRead, WebReadService>()(\n \"@betalyra/effect-uai/WebRead\",\n) {}\n\n/** Read one URL against whichever provider Layer is in scope. */\nexport const read = (\n request: CommonReadRequest,\n): Effect.Effect<ReadResponse, AiError.AiError, WebRead> =>\n Effect.flatMap(WebRead, (s) => s.read(request))\n"],"mappings":";;;;;;;;;;;AA6DA,IAAa,UAAb,cAA6B,QAAQ,QAAiC,CAAC,CACrE,8BACF,CAAC,CAAC,CAAC;;AAGH,MAAa,QACX,YAEA,OAAO,QAAQ,UAAU,MAAM,EAAE,KAAK,OAAO,CAAC"}
|
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import { l as Tool } from "../Tool-
|
|
2
|
-
import { t as AiError } from "../AiError-
|
|
1
|
+
import { l as Tool } from "../Tool-DE-rnvkw.mjs";
|
|
2
|
+
import { t as AiError } from "../AiError-eLV9t1lU.mjs";
|
|
3
3
|
import { ReadFormat, ReadResponse, WebRead } from "./WebRead.mjs";
|
|
4
4
|
import { Schema } from "effect";
|
|
5
|
-
|
|
6
|
-
//#region src/web-read/WebReadTool.d.ts
|
|
7
5
|
declare namespace WebReadTool_d_exports {
|
|
8
6
|
export { WebReadToolArgs, WebReadToolOptions, webReadTool };
|
|
9
7
|
}
|
|
@@ -18,7 +16,8 @@ declare const WebReadToolArgs: Schema.Struct<{
|
|
|
18
16
|
}>;
|
|
19
17
|
type WebReadToolArgs = typeof WebReadToolArgs.Type;
|
|
20
18
|
type WebReadToolOptions = {
|
|
21
|
-
/** Tool name the model sees. Default `"web_read"`. */
|
|
19
|
+
/** Tool name the model sees. Default `"web_read"`. */
|
|
20
|
+
readonly name?: string;
|
|
22
21
|
/**
|
|
23
22
|
* App-fixed representation for every read - a policy choice, not a model
|
|
24
23
|
* knob. Default `"markdown"` (what models read best).
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WebReadTool.d.mts","names":[],"sources":["../../src/web-read/WebReadTool.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"WebReadTool.d.mts","names":[],"sources":["../../src/web-read/WebReadTool.ts"],"mappings":";;;;;;;;;;;;;cAWM,iBAAe,OAAA;gBAAf,OAAA;;KAMM,yBAAyB,gBAAgB;KAYzC;;WAED;;;;;WAKA,SAAS;;;;;WAKT;;;;;WAKA,UAAU,UAAU;;;;;;;;;;;;;;;;;;cAmBlB,cAAW,UACZ,uBACT,aAAkB,gCAAgC,SAAiB"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as __exportAll } from "../
|
|
1
|
+
import { n as __exportAll } from "../rolldown-runtime-EAsCxrDo.mjs";
|
|
2
2
|
import { fromEffectSchema, make } from "../tool/Tool.mjs";
|
|
3
3
|
import { read } from "./WebRead.mjs";
|
|
4
4
|
import { Effect, Schema } from "effect";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WebReadTool.mjs","names":["Tool.make","Tool.fromEffectSchema"],"sources":["../../src/web-read/WebReadTool.ts"],"sourcesContent":["import { Effect, Schema } from \"effect\"\nimport type * as AiError from \"../domain/AiError.js\"\nimport * as Tool from \"../tool/Tool.js\"\nimport { read, type ReadFormat, type ReadResponse, WebRead } from \"./WebRead.js\"\n\n/**\n * Model-facing argument schema. Deliberately narrow: the URL is the only\n * thing that is genuinely the model's call. Output format and the content\n * cost ceiling are app policy, pinned on the constructor instead, so they\n * are guaranteed rather than left to the model to remember each call.\n */\nconst WebReadToolArgs = Schema.Struct({\n url: Schema.String.annotate({\n description: \"Absolute URL of the page to read.\",\n }),\n})\n\nexport type WebReadToolArgs = typeof WebReadToolArgs.Type\n\n/** `title / url` header plus the extracted content - what a model reads best. */\nconst defaultRender = (response: ReadResponse, maxChars: number): string => {\n const header = response.title === undefined ? response.url : `${response.title}\\n${response.url}`\n const body =\n response.content.length > maxChars\n ? `${response.content.slice(0, maxChars)}\\n[content truncated at ${maxChars} characters]`\n : response.content\n return `${header}\\n\\n${body}`\n}\n\nexport type WebReadToolOptions = {\n /** Tool name the model sees. Default `\"web_read\"`. */\n readonly name?: string\n /**\n * App-fixed representation for every read - a policy choice, not a model\n * knob. Default `\"markdown\"` (what models read best).\n */\n readonly format?: ReadFormat\n /**\n * App-fixed ceiling on rendered content characters per call - a context\n * cost guard, not exposed to the model. Default `20000`.\n */\n readonly maxChars?: number\n /**\n * Override how a read response is rendered into the model-facing string.\n * Default: `title / url` header plus the content, truncated at `maxChars`.\n */\n readonly render?: (response: ReadResponse) => string\n}\n\n/**\n * The canonical web-read tool. Its `R` is just `WebRead`, so providing any\n * read-provider Layer satisfies it and the model-facing contract (name,\n * description, schema) is identical no matter which backend answers - swap\n * `FirecrawlRead.layer` for `JinaRead.layer` and the tool the model sees\n * does not change. Drops straight into a `Toolkit` next to `webSearchTool`\n * (search finds the URLs, read fetches the ones worth reading in full).\n *\n * `Output` is the rendered page; failures stay typed on the `AiError`\n * channel. To let the model recover from a failed read, wrap the toolkit in\n * `Toolkit.describeFailures(AiError.describe)`.\n *\n * This is a simple default implementation for quick use. For more elaborate\n * cases (a different output contract, more model-facing knobs), build your\n * own tool with `Tool.make` over the same `read` helper.\n */\nexport const webReadTool = (\n options?: WebReadToolOptions,\n): Tool.Tool<string, WebReadToolArgs, never, string, AiError.AiError, WebRead> => {\n const name = options?.name ?? \"web_read\"\n const format = options?.format ?? \"markdown\"\n const maxChars = options?.maxChars ?? 20_000\n const render = options?.render ?? ((response: ReadResponse) => defaultRender(response, maxChars))\n return Tool.make({\n name,\n description:\n \"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).\",\n inputSchema: Tool.fromEffectSchema(WebReadToolArgs),\n // The call is wrapped in a tracing span so agent traces show the tool\n // invocation (url, format, content length) nested under the model turn.\n // `withSpan` is a no-op until a Tracer is installed, so this is free by\n // default and adds nothing to the requirements.\n run: (args) =>\n read({ url: args.url, format }).pipe(\n Effect.tap((r) => Effect.annotateCurrentSpan(\"web_read.content_chars\", r.content.length)),\n Effect.map(render),\n Effect.withSpan(name, {\n kind: \"client\",\n attributes: {\n \"web_read.url\": args.url,\n \"web_read.format\": format,\n \"web_read.max_chars\": maxChars,\n },\n }),\n ),\n })\n}\n"],"mappings":";;;;;;;;;;;;AAWA,MAAM,kBAAkB,OAAO,OAAO,EACpC,KAAK,OAAO,OAAO,SAAS,EAC1B,aAAa,
|
|
1
|
+
{"version":3,"file":"WebReadTool.mjs","names":["Tool.make","Tool.fromEffectSchema"],"sources":["../../src/web-read/WebReadTool.ts"],"sourcesContent":["import { Effect, Schema } from \"effect\"\nimport type * as AiError from \"../domain/AiError.js\"\nimport * as Tool from \"../tool/Tool.js\"\nimport { read, type ReadFormat, type ReadResponse, WebRead } from \"./WebRead.js\"\n\n/**\n * Model-facing argument schema. Deliberately narrow: the URL is the only\n * thing that is genuinely the model's call. Output format and the content\n * cost ceiling are app policy, pinned on the constructor instead, so they\n * are guaranteed rather than left to the model to remember each call.\n */\nconst WebReadToolArgs = Schema.Struct({\n url: Schema.String.annotate({\n description: \"Absolute URL of the page to read.\",\n }),\n})\n\nexport type WebReadToolArgs = typeof WebReadToolArgs.Type\n\n/** `title / url` header plus the extracted content - what a model reads best. */\nconst defaultRender = (response: ReadResponse, maxChars: number): string => {\n const header = response.title === undefined ? response.url : `${response.title}\\n${response.url}`\n const body =\n response.content.length > maxChars\n ? `${response.content.slice(0, maxChars)}\\n[content truncated at ${maxChars} characters]`\n : response.content\n return `${header}\\n\\n${body}`\n}\n\nexport type WebReadToolOptions = {\n /** Tool name the model sees. Default `\"web_read\"`. */\n readonly name?: string\n /**\n * App-fixed representation for every read - a policy choice, not a model\n * knob. Default `\"markdown\"` (what models read best).\n */\n readonly format?: ReadFormat\n /**\n * App-fixed ceiling on rendered content characters per call - a context\n * cost guard, not exposed to the model. Default `20000`.\n */\n readonly maxChars?: number\n /**\n * Override how a read response is rendered into the model-facing string.\n * Default: `title / url` header plus the content, truncated at `maxChars`.\n */\n readonly render?: (response: ReadResponse) => string\n}\n\n/**\n * The canonical web-read tool. Its `R` is just `WebRead`, so providing any\n * read-provider Layer satisfies it and the model-facing contract (name,\n * description, schema) is identical no matter which backend answers - swap\n * `FirecrawlRead.layer` for `JinaRead.layer` and the tool the model sees\n * does not change. Drops straight into a `Toolkit` next to `webSearchTool`\n * (search finds the URLs, read fetches the ones worth reading in full).\n *\n * `Output` is the rendered page; failures stay typed on the `AiError`\n * channel. To let the model recover from a failed read, wrap the toolkit in\n * `Toolkit.describeFailures(AiError.describe)`.\n *\n * This is a simple default implementation for quick use. For more elaborate\n * cases (a different output contract, more model-facing knobs), build your\n * own tool with `Tool.make` over the same `read` helper.\n */\nexport const webReadTool = (\n options?: WebReadToolOptions,\n): Tool.Tool<string, WebReadToolArgs, never, string, AiError.AiError, WebRead> => {\n const name = options?.name ?? \"web_read\"\n const format = options?.format ?? \"markdown\"\n const maxChars = options?.maxChars ?? 20_000\n const render = options?.render ?? ((response: ReadResponse) => defaultRender(response, maxChars))\n return Tool.make({\n name,\n description:\n \"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).\",\n inputSchema: Tool.fromEffectSchema(WebReadToolArgs),\n // The call is wrapped in a tracing span so agent traces show the tool\n // invocation (url, format, content length) nested under the model turn.\n // `withSpan` is a no-op until a Tracer is installed, so this is free by\n // default and adds nothing to the requirements.\n run: (args) =>\n read({ url: args.url, format }).pipe(\n Effect.tap((r) => Effect.annotateCurrentSpan(\"web_read.content_chars\", r.content.length)),\n Effect.map(render),\n Effect.withSpan(name, {\n kind: \"client\",\n attributes: {\n \"web_read.url\": args.url,\n \"web_read.format\": format,\n \"web_read.max_chars\": maxChars,\n },\n }),\n ),\n })\n}\n"],"mappings":";;;;;;;;;;;;AAWA,MAAM,kBAAkB,OAAO,OAAO,EACpC,KAAK,OAAO,OAAO,SAAS,EAC1B,aAAa,oCACf,CAAC,EACH,CAAC;;AAKD,MAAM,iBAAiB,UAAwB,aAA6B;CAM1E,OAAO,GALQ,SAAS,UAAU,KAAA,IAAY,SAAS,MAAM,GAAG,SAAS,MAAM,IAAI,SAAS,MAK3E,MAHf,SAAS,QAAQ,SAAS,WACtB,GAAG,SAAS,QAAQ,MAAM,GAAG,QAAQ,EAAE,0BAA0B,SAAS,gBAC1E,SAAS;AAEjB;;;;;;;;;;;;;;;;;AAsCA,MAAa,eACX,YACgF;CAChF,MAAM,OAAO,SAAS,QAAQ;CAC9B,MAAM,SAAS,SAAS,UAAU;CAClC,MAAM,WAAW,SAAS,YAAY;CACtC,MAAM,SAAS,SAAS,YAAY,aAA2B,cAAc,UAAU,QAAQ;CAC/F,OAAOA,KAAU;EACf;EACA,aACE;EACF,aAAaC,iBAAsB,eAAe;EAKlD,MAAM,SACJ,KAAK;GAAE,KAAK,KAAK;GAAK;EAAO,CAAC,CAAC,CAAC,KAC9B,OAAO,KAAK,MAAM,OAAO,oBAAoB,0BAA0B,EAAE,QAAQ,MAAM,CAAC,GACxF,OAAO,IAAI,MAAM,GACjB,OAAO,SAAS,MAAM;GACpB,MAAM;GACN,YAAY;IACV,gBAAgB,KAAK;IACrB,mBAAmB;IACnB,sBAAsB;GACxB;EACF,CAAC,CACH;CACJ,CAAC;AACH"}
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import { t as AiError } from "../AiError-
|
|
1
|
+
import { t as AiError } from "../AiError-eLV9t1lU.mjs";
|
|
2
2
|
import { Context, DateTime, Effect, Schema } from "effect";
|
|
3
|
-
|
|
4
|
-
//#region src/web-search/WebSearch.d.ts
|
|
5
3
|
declare namespace WebSearch_d_exports {
|
|
6
4
|
export { CommonSearchRequest, SearchRecency, SearchResponse, SearchResult, WebSearch, WebSearchService, search };
|
|
7
5
|
}
|
|
@@ -35,7 +33,8 @@ type SearchRecency = typeof SearchRecency.Type;
|
|
|
35
33
|
* `searchDepth`) is a mode knob, so it stays on the provider-typed request.
|
|
36
34
|
*/
|
|
37
35
|
type CommonSearchRequest = {
|
|
38
|
-
/** The search query. The one field every provider requires. */
|
|
36
|
+
/** The search query. The one field every provider requires. */
|
|
37
|
+
readonly query: string;
|
|
39
38
|
/**
|
|
40
39
|
* Upper bound on the number of results to return in this one call.
|
|
41
40
|
* Providers cap differently (Perplexity / Tavily / Brave at ~20, Exa /
|
|
@@ -43,18 +42,24 @@ type CommonSearchRequest = {
|
|
|
43
42
|
* provider. There is no common pagination - only two providers paginate
|
|
44
43
|
* and only shallowly, so `offset` is provider-typed.
|
|
45
44
|
*/
|
|
46
|
-
readonly maxResults?: number;
|
|
47
|
-
|
|
45
|
+
readonly maxResults?: number;
|
|
46
|
+
/** Restrict results to these domains (e.g. `["docs.foo.com"]`). */
|
|
47
|
+
readonly includeDomains?: ReadonlyArray<string>;
|
|
48
|
+
/** Drop results from these domains. */
|
|
48
49
|
readonly excludeDomains?: ReadonlyArray<string>;
|
|
49
50
|
/**
|
|
50
51
|
* Coarse freshness filter - see {@link SearchRecency}. Sugar over an
|
|
51
52
|
* explicit `startDate`; ignored where {@link startDate} is also set and
|
|
52
53
|
* the provider takes only one.
|
|
53
54
|
*/
|
|
54
|
-
readonly recency?: SearchRecency;
|
|
55
|
-
|
|
56
|
-
readonly
|
|
57
|
-
|
|
55
|
+
readonly recency?: SearchRecency;
|
|
56
|
+
/** Published-after bound. The precise alternative to {@link recency}. */
|
|
57
|
+
readonly startDate?: DateTime.DateTime;
|
|
58
|
+
/** Published-before bound. */
|
|
59
|
+
readonly endDate?: DateTime.DateTime;
|
|
60
|
+
/** ISO 3166-1 alpha-2 country code to localize results (e.g. `"us"`). */
|
|
61
|
+
readonly country?: string;
|
|
62
|
+
/** ISO 639-1 language code to bias results toward (e.g. `"en"`). */
|
|
58
63
|
readonly language?: string;
|
|
59
64
|
};
|
|
60
65
|
/**
|
|
@@ -65,7 +70,9 @@ type CommonSearchRequest = {
|
|
|
65
70
|
* here (`author`, `favicon`, multi-chunk `snippets[]`, …).
|
|
66
71
|
*/
|
|
67
72
|
type SearchResult = {
|
|
68
|
-
/** Canonical result URL. Always present. */
|
|
73
|
+
/** Canonical result URL. Always present. */
|
|
74
|
+
readonly url: string;
|
|
75
|
+
/** Result title / headline, when the provider returns one. */
|
|
69
76
|
readonly title?: string;
|
|
70
77
|
/**
|
|
71
78
|
* Primary short excerpt - the one text field all providers return (under
|
|
@@ -73,7 +80,8 @@ type SearchResult = {
|
|
|
73
80
|
* extract fields (`text`, `highlights`, `summary`) belong to the
|
|
74
81
|
* out-of-scope extract feature and stay on the provider-typed result.
|
|
75
82
|
*/
|
|
76
|
-
readonly snippet?: string;
|
|
83
|
+
readonly snippet?: string;
|
|
84
|
+
/** Publication date, when the provider reports one. */
|
|
77
85
|
readonly publishedDate?: DateTime.DateTime;
|
|
78
86
|
/**
|
|
79
87
|
* Relevance score, only from providers that rank (Exa, Tavily);
|
|
@@ -81,7 +89,8 @@ type SearchResult = {
|
|
|
81
89
|
* being non-universal because ranking is core to what a "search result"
|
|
82
90
|
* means - and `undefined` cleanly says "this backend doesn't score."
|
|
83
91
|
*/
|
|
84
|
-
readonly score?: number;
|
|
92
|
+
readonly score?: number;
|
|
93
|
+
/** The provider-native result object, never lossy. */
|
|
85
94
|
readonly raw: unknown;
|
|
86
95
|
};
|
|
87
96
|
type SearchResponse = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WebSearch.d.mts","names":[],"sources":["../../src/web-search/WebSearch.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"WebSearch.d.mts","names":[],"sources":["../../src/web-search/WebSearch.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;cAsBa,eAAa,OAAA;KAEd,uBAAuB,cAAc;;;;;;;;;;;;;KAkBrC;;WAED;;;;;;;;WAQA;;WAEA,iBAAiB;;WAEjB,iBAAiB;;;;;;WAMjB,UAAU;;WAEV,YAAY,SAAS;;WAErB,UAAU,SAAS;;WAEnB;;WAEA;;;;;;;;;KAcC;;WAED;;WAEA;;;;;;;WAOA;;WAEA,gBAAgB,SAAS;;;;;;;WAOzB;;WAEA;;KAGC;WACD,SAAS,cAAc;;;;;;;;;WASvB;;;;;;;;KAaC;WACD,SAAS,SAAS,wBAAwB,OAAO,OAAO,gBAAgB;;;;;;;;cAQtE,kBAAkB;;cAKlB,SAAM,SACR,wBACR,OAAO,OAAO,gBAAgB,SAAiB"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as __exportAll } from "../
|
|
1
|
+
import { n as __exportAll } from "../rolldown-runtime-EAsCxrDo.mjs";
|
|
2
2
|
import { Context, Effect, Schema } from "effect";
|
|
3
3
|
//#region src/web-search/WebSearch.ts
|
|
4
4
|
var WebSearch_exports = /* @__PURE__ */ __exportAll({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WebSearch.mjs","names":[],"sources":["../../src/web-search/WebSearch.ts"],"sourcesContent":["import { Context, type DateTime, Effect, Schema } from \"effect\"\nimport type * as AiError from \"../domain/AiError.js\"\n\n// ---------------------------------------------------------------------------\n// Recency\n// ---------------------------------------------------------------------------\n\n/**\n * Convenience freshness enum shared by every provider. A coarse \"published\n * within the last …\" filter that maps onto each provider's native recency\n * knob (Perplexity `search_recency_filter`, Brave `freshness`, Tavily\n * `time_range`, You.com `freshness`), or onto a computed published-date\n * range where a provider has no enum (Exa).\n *\n * For a precise window use {@link CommonSearchRequest.startDate} /\n * {@link CommonSearchRequest.endDate} instead; `recency` is the sugar for\n * the common \"past week / past month\" case.\n *\n * Exposed as a `Schema` so {@link \"../web-search/WebSearchTool\".webSearchTool}\n * can hand it straight to a model as a tool parameter; the\n * {@link SearchRecency} type is derived from it.\n */\nexport const SearchRecency = Schema.Literals([\"hour\", \"day\", \"week\", \"month\", \"year\"])\n\nexport type SearchRecency = typeof SearchRecency.Type\n\n// ---------------------------------------------------------------------------\n// Request\n// ---------------------------------------------------------------------------\n\n/**\n * Cross-provider web-search request. A field earns a place here only if\n * most of the supported providers honor it and a developer would expect it\n * from a generic search interface; everything provider-specific (Exa\n * `type`, Tavily `searchDepth`, Brave `goggles`, pagination `offset`,\n * `safeSearch`, `topic`, …) lives on that provider's typed request.\n *\n * Note the one structural difference from `EmbeddingModel` /\n * `Transcriber`: there is no `model`. None of the pure-`/search` endpoints\n * take one - what looks model-shaped on a provider (Exa `type`, Tavily\n * `searchDepth`) is a mode knob, so it stays on the provider-typed request.\n */\nexport type CommonSearchRequest = {\n /** The search query. The one field every provider requires. */\n readonly query: string\n /**\n * Upper bound on the number of results to return in this one call.\n * Providers cap differently (Perplexity / Tavily / Brave at ~20, Exa /\n * You.com at ~100); a value above a provider's cap is clamped by that\n * provider. There is no common pagination - only two providers paginate\n * and only shallowly, so `offset` is provider-typed.\n */\n readonly maxResults?: number\n /** Restrict results to these domains (e.g. `[\"docs.foo.com\"]`). */\n readonly includeDomains?: ReadonlyArray<string>\n /** Drop results from these domains. */\n readonly excludeDomains?: ReadonlyArray<string>\n /**\n * Coarse freshness filter - see {@link SearchRecency}. Sugar over an\n * explicit `startDate`; ignored where {@link startDate} is also set and\n * the provider takes only one.\n */\n readonly recency?: SearchRecency\n /** Published-after bound. The precise alternative to {@link recency}. */\n readonly startDate?: DateTime.DateTime\n /** Published-before bound. */\n readonly endDate?: DateTime.DateTime\n /** ISO 3166-1 alpha-2 country code to localize results (e.g. `\"us\"`). */\n readonly country?: string\n /** ISO 639-1 language code to bias results toward (e.g. `\"en\"`). */\n readonly language?: string\n}\n\n// ---------------------------------------------------------------------------\n// Response\n// ---------------------------------------------------------------------------\n\n/**\n * One normalized web-search hit. A flat record with optionals rather than a\n * tagged union: the providers differ by *which fields are present*, not by\n * *kind*. The provider's untouched result object is always on `raw`, so a\n * caller holding a typed provider tag can recover anything not promoted\n * here (`author`, `favicon`, multi-chunk `snippets[]`, …).\n */\nexport type SearchResult = {\n /** Canonical result URL. Always present. */\n readonly url: string\n /** Result title / headline, when the provider returns one. */\n readonly title?: string\n /**\n * Primary short excerpt - the one text field all providers return (under\n * various wire names: `snippet`, `content`, `description`). The richer\n * extract fields (`text`, `highlights`, `summary`) belong to the\n * out-of-scope extract feature and stay on the provider-typed result.\n */\n readonly snippet?: string\n /** Publication date, when the provider reports one. */\n readonly publishedDate?: DateTime.DateTime\n /**\n * Relevance score, only from providers that rank (Exa, Tavily);\n * `undefined` for providers that return an unscored list. Kept despite\n * being non-universal because ranking is core to what a \"search result\"\n * means - and `undefined` cleanly says \"this backend doesn't score.\"\n */\n readonly score?: number\n /** The provider-native result object, never lossy. */\n readonly raw: unknown\n}\n\nexport type SearchResponse = {\n readonly results: ReadonlyArray<SearchResult>\n /**\n * The provider-native top-level response object. Cost / usage reporting\n * is deliberately not modeled on this surface yet: providers disagree on\n * both what (Exa returns USD, Tavily credits, Brave nothing in-body) and\n * where (Brave reports cost in response headers), so it is deferred to the\n * unified usage design (see plans/usage-tracking.md). Anything a provider\n * reports survives here on `raw`.\n */\n readonly raw: unknown\n}\n\n// ---------------------------------------------------------------------------\n// Service + helper\n// ---------------------------------------------------------------------------\n\n/**\n * The portable web-search surface: one operation, `search`. Pure search is\n * the one thing every provider does, so - unlike `SpeechSynthesizer` /\n * `Transcriber` - this capability needs no marker tags; every provider\n * Layer can answer.\n */\nexport type WebSearchService = {\n readonly search: (request: CommonSearchRequest) => Effect.Effect<SearchResponse, AiError.AiError>\n}\n\n/**\n * Generic web-search service tag. Yield this for provider-portable code;\n * yield a provider tag (`PerplexitySearch`, `ExaSearch`, …) when you need\n * that provider's own knobs. A provider's `layer` registers both.\n */\nexport class WebSearch extends Context.Service<WebSearch, WebSearchService>()(\n \"@betalyra/effect-uai/WebSearch\",\n) {}\n\n/** Run one web search against whichever provider Layer is in scope. */\nexport const search = (\n request: CommonSearchRequest,\n): Effect.Effect<SearchResponse, AiError.AiError, WebSearch> =>\n Effect.flatMap(WebSearch, (s) => s.search(request))\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAsBA,MAAa,gBAAgB,OAAO,SAAS;CAAC;CAAQ;CAAO;CAAQ;CAAS;
|
|
1
|
+
{"version":3,"file":"WebSearch.mjs","names":[],"sources":["../../src/web-search/WebSearch.ts"],"sourcesContent":["import { Context, type DateTime, Effect, Schema } from \"effect\"\nimport type * as AiError from \"../domain/AiError.js\"\n\n// ---------------------------------------------------------------------------\n// Recency\n// ---------------------------------------------------------------------------\n\n/**\n * Convenience freshness enum shared by every provider. A coarse \"published\n * within the last …\" filter that maps onto each provider's native recency\n * knob (Perplexity `search_recency_filter`, Brave `freshness`, Tavily\n * `time_range`, You.com `freshness`), or onto a computed published-date\n * range where a provider has no enum (Exa).\n *\n * For a precise window use {@link CommonSearchRequest.startDate} /\n * {@link CommonSearchRequest.endDate} instead; `recency` is the sugar for\n * the common \"past week / past month\" case.\n *\n * Exposed as a `Schema` so {@link \"../web-search/WebSearchTool\".webSearchTool}\n * can hand it straight to a model as a tool parameter; the\n * {@link SearchRecency} type is derived from it.\n */\nexport const SearchRecency = Schema.Literals([\"hour\", \"day\", \"week\", \"month\", \"year\"])\n\nexport type SearchRecency = typeof SearchRecency.Type\n\n// ---------------------------------------------------------------------------\n// Request\n// ---------------------------------------------------------------------------\n\n/**\n * Cross-provider web-search request. A field earns a place here only if\n * most of the supported providers honor it and a developer would expect it\n * from a generic search interface; everything provider-specific (Exa\n * `type`, Tavily `searchDepth`, Brave `goggles`, pagination `offset`,\n * `safeSearch`, `topic`, …) lives on that provider's typed request.\n *\n * Note the one structural difference from `EmbeddingModel` /\n * `Transcriber`: there is no `model`. None of the pure-`/search` endpoints\n * take one - what looks model-shaped on a provider (Exa `type`, Tavily\n * `searchDepth`) is a mode knob, so it stays on the provider-typed request.\n */\nexport type CommonSearchRequest = {\n /** The search query. The one field every provider requires. */\n readonly query: string\n /**\n * Upper bound on the number of results to return in this one call.\n * Providers cap differently (Perplexity / Tavily / Brave at ~20, Exa /\n * You.com at ~100); a value above a provider's cap is clamped by that\n * provider. There is no common pagination - only two providers paginate\n * and only shallowly, so `offset` is provider-typed.\n */\n readonly maxResults?: number\n /** Restrict results to these domains (e.g. `[\"docs.foo.com\"]`). */\n readonly includeDomains?: ReadonlyArray<string>\n /** Drop results from these domains. */\n readonly excludeDomains?: ReadonlyArray<string>\n /**\n * Coarse freshness filter - see {@link SearchRecency}. Sugar over an\n * explicit `startDate`; ignored where {@link startDate} is also set and\n * the provider takes only one.\n */\n readonly recency?: SearchRecency\n /** Published-after bound. The precise alternative to {@link recency}. */\n readonly startDate?: DateTime.DateTime\n /** Published-before bound. */\n readonly endDate?: DateTime.DateTime\n /** ISO 3166-1 alpha-2 country code to localize results (e.g. `\"us\"`). */\n readonly country?: string\n /** ISO 639-1 language code to bias results toward (e.g. `\"en\"`). */\n readonly language?: string\n}\n\n// ---------------------------------------------------------------------------\n// Response\n// ---------------------------------------------------------------------------\n\n/**\n * One normalized web-search hit. A flat record with optionals rather than a\n * tagged union: the providers differ by *which fields are present*, not by\n * *kind*. The provider's untouched result object is always on `raw`, so a\n * caller holding a typed provider tag can recover anything not promoted\n * here (`author`, `favicon`, multi-chunk `snippets[]`, …).\n */\nexport type SearchResult = {\n /** Canonical result URL. Always present. */\n readonly url: string\n /** Result title / headline, when the provider returns one. */\n readonly title?: string\n /**\n * Primary short excerpt - the one text field all providers return (under\n * various wire names: `snippet`, `content`, `description`). The richer\n * extract fields (`text`, `highlights`, `summary`) belong to the\n * out-of-scope extract feature and stay on the provider-typed result.\n */\n readonly snippet?: string\n /** Publication date, when the provider reports one. */\n readonly publishedDate?: DateTime.DateTime\n /**\n * Relevance score, only from providers that rank (Exa, Tavily);\n * `undefined` for providers that return an unscored list. Kept despite\n * being non-universal because ranking is core to what a \"search result\"\n * means - and `undefined` cleanly says \"this backend doesn't score.\"\n */\n readonly score?: number\n /** The provider-native result object, never lossy. */\n readonly raw: unknown\n}\n\nexport type SearchResponse = {\n readonly results: ReadonlyArray<SearchResult>\n /**\n * The provider-native top-level response object. Cost / usage reporting\n * is deliberately not modeled on this surface yet: providers disagree on\n * both what (Exa returns USD, Tavily credits, Brave nothing in-body) and\n * where (Brave reports cost in response headers), so it is deferred to the\n * unified usage design (see plans/usage-tracking.md). Anything a provider\n * reports survives here on `raw`.\n */\n readonly raw: unknown\n}\n\n// ---------------------------------------------------------------------------\n// Service + helper\n// ---------------------------------------------------------------------------\n\n/**\n * The portable web-search surface: one operation, `search`. Pure search is\n * the one thing every provider does, so - unlike `SpeechSynthesizer` /\n * `Transcriber` - this capability needs no marker tags; every provider\n * Layer can answer.\n */\nexport type WebSearchService = {\n readonly search: (request: CommonSearchRequest) => Effect.Effect<SearchResponse, AiError.AiError>\n}\n\n/**\n * Generic web-search service tag. Yield this for provider-portable code;\n * yield a provider tag (`PerplexitySearch`, `ExaSearch`, …) when you need\n * that provider's own knobs. A provider's `layer` registers both.\n */\nexport class WebSearch extends Context.Service<WebSearch, WebSearchService>()(\n \"@betalyra/effect-uai/WebSearch\",\n) {}\n\n/** Run one web search against whichever provider Layer is in scope. */\nexport const search = (\n request: CommonSearchRequest,\n): Effect.Effect<SearchResponse, AiError.AiError, WebSearch> =>\n Effect.flatMap(WebSearch, (s) => s.search(request))\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAsBA,MAAa,gBAAgB,OAAO,SAAS;CAAC;CAAQ;CAAO;CAAQ;CAAS;AAAM,CAAC;;;;;;AAuHrF,IAAa,YAAb,cAA+B,QAAQ,QAAqC,CAAC,CAC3E,gCACF,CAAC,CAAC,CAAC;;AAGH,MAAa,UACX,YAEA,OAAO,QAAQ,YAAY,MAAM,EAAE,OAAO,OAAO,CAAC"}
|
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import { l as Tool } from "../Tool-
|
|
2
|
-
import { t as AiError } from "../AiError-
|
|
1
|
+
import { l as Tool } from "../Tool-DE-rnvkw.mjs";
|
|
2
|
+
import { t as AiError } from "../AiError-eLV9t1lU.mjs";
|
|
3
3
|
import { SearchResult, WebSearch } from "./WebSearch.mjs";
|
|
4
4
|
import { Schema } from "effect";
|
|
5
|
-
|
|
6
|
-
//#region src/web-search/WebSearchTool.d.ts
|
|
7
5
|
declare namespace WebSearchTool_d_exports {
|
|
8
6
|
export { WebSearchToolArgs, WebSearchToolOptions, webSearchTool };
|
|
9
7
|
}
|
|
@@ -21,7 +19,8 @@ declare const WebSearchToolArgs: Schema.Struct<{
|
|
|
21
19
|
}>;
|
|
22
20
|
type WebSearchToolArgs = typeof WebSearchToolArgs.Type;
|
|
23
21
|
type WebSearchToolOptions = {
|
|
24
|
-
/** Tool name the model sees. Default `"web_search"`. */
|
|
22
|
+
/** Tool name the model sees. Default `"web_search"`. */
|
|
23
|
+
readonly name?: string;
|
|
25
24
|
/**
|
|
26
25
|
* App-fixed ceiling on results per call - a cost guard, not exposed to
|
|
27
26
|
* the model. Default `5`.
|
|
@@ -31,7 +30,8 @@ type WebSearchToolOptions = {
|
|
|
31
30
|
* App-fixed allowlist applied to every search. A policy scope ("only
|
|
32
31
|
* search our docs"), not a model knob - so it is enforced, not requested.
|
|
33
32
|
*/
|
|
34
|
-
readonly includeDomains?: ReadonlyArray<string>;
|
|
33
|
+
readonly includeDomains?: ReadonlyArray<string>;
|
|
34
|
+
/** App-fixed denylist applied to every search ("never return X"). */
|
|
35
35
|
readonly excludeDomains?: ReadonlyArray<string>;
|
|
36
36
|
/**
|
|
37
37
|
* Override how results are rendered into the model-facing string.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WebSearchTool.d.mts","names":[],"sources":["../../src/web-search/WebSearchTool.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"WebSearchTool.d.mts","names":[],"sources":["../../src/web-search/WebSearchTool.ts"],"mappings":";;;;;;;;;;;;;;;cAaM,mBAAiB,OAAA;;;;KAKX,2BAA2B,kBAAkB;KAa7C;;WAED;;;;;WAKA;;;;;WAKA,iBAAiB;;WAEjB,iBAAiB;;;;;WAKjB,UAAU,SAAS,cAAc;;;;;;;;;;;;;;;;;;;;;cAsB/B,gBAAa,UACd,yBACT,aAAkB,kCAAkC,SAAiB"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as __exportAll } from "../
|
|
1
|
+
import { n as __exportAll } from "../rolldown-runtime-EAsCxrDo.mjs";
|
|
2
2
|
import { fromEffectSchema, make } from "../tool/Tool.mjs";
|
|
3
3
|
import { SearchRecency, search } from "./WebSearch.mjs";
|
|
4
4
|
import { Effect, Schema } from "effect";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WebSearchTool.mjs","names":["Tool.make","Tool.fromEffectSchema"],"sources":["../../src/web-search/WebSearchTool.ts"],"sourcesContent":["import { Effect, Schema } from \"effect\"\nimport type * as AiError from \"../domain/AiError.js\"\nimport * as Tool from \"../tool/Tool.js\"\nimport { search, SearchRecency, type SearchResult, WebSearch } from \"./WebSearch.js\"\n\n/**\n * Model-facing argument schema. Deliberately narrow: `query` plus the one\n * filter that is genuinely the model's call - `recency` (it knows whether a\n * question is about current events or evergreen). App-policy scoping\n * (`includeDomains` / `excludeDomains`) and the `maxResults` cost ceiling\n * are pinned on the constructor instead, so they are guaranteed rather than\n * left to the model to remember each call.\n */\nconst WebSearchToolArgs = Schema.Struct({\n query: Schema.String,\n recency: Schema.optional(SearchRecency),\n})\n\nexport type WebSearchToolArgs = typeof WebSearchToolArgs.Type\n\n/** Numbered `title / url / snippet` list - what a model reads best. */\nconst defaultRender = (results: ReadonlyArray<SearchResult>): string =>\n results.length === 0\n ? \"No results found.\"\n : results\n .map((r, i) => {\n const head = `${i + 1}. ${r.title ?? r.url}\\n ${r.url}`\n return r.snippet === undefined ? head : `${head}\\n ${r.snippet}`\n })\n .join(\"\\n\\n\")\n\nexport type WebSearchToolOptions = {\n /** Tool name the model sees. Default `\"web_search\"`. */\n readonly name?: string\n /**\n * App-fixed ceiling on results per call - a cost guard, not exposed to\n * the model. Default `5`.\n */\n readonly maxResults?: number\n /**\n * App-fixed allowlist applied to every search. A policy scope (\"only\n * search our docs\"), not a model knob - so it is enforced, not requested.\n */\n readonly includeDomains?: ReadonlyArray<string>\n /** App-fixed denylist applied to every search (\"never return X\"). */\n readonly excludeDomains?: ReadonlyArray<string>\n /**\n * Override how results are rendered into the model-facing string.\n * Default: a numbered `title / url / snippet` list.\n */\n readonly render?: (results: ReadonlyArray<SearchResult>) => string\n}\n\n/**\n * The canonical web-search tool. Its `R` is just `WebSearch`, so providing\n * any search-provider Layer satisfies it and the model-facing contract\n * (name, description, schema) is identical no matter which backend answers\n * - swap `PerplexitySearch.layer` for `ExaSearch.layer` and the tool the\n * model sees does not change. Drops straight into a `Toolkit` and the\n * `LanguageModel` tool-calling loop.\n *\n * The model controls only `query` and `recency`; domain scoping and the\n * result cap are app policy, fixed here on the constructor. `Output` is the\n * rendered text (the model reads a numbered list better than raw\n * `SearchResult[]`; pass `render` to change the format); failures stay typed\n * on the `AiError` channel. To let the model recover from a failed search,\n * wrap the toolkit in `Toolkit.describeFailures(AiError.describe)`.\n *\n * This is a simple default implementation for quick use. For more elaborate\n * cases (a different output contract, more model-facing knobs), build your\n * own tool with `Tool.make` over the same `search` helper.\n */\nexport const webSearchTool = (\n options?: WebSearchToolOptions,\n): Tool.Tool<string, WebSearchToolArgs, never, string, AiError.AiError, WebSearch> => {\n const name = options?.name ?? \"web_search\"\n const render = options?.render ?? defaultRender\n const maxResults = options?.maxResults ?? 5\n const includeDomains = options?.includeDomains\n const excludeDomains = options?.excludeDomains\n return Tool.make({\n name,\n description:\n \"Search the web for current information. Returns ranked results with titles, URLs, and snippets.\",\n inputSchema: Tool.fromEffectSchema(WebSearchToolArgs),\n // The call is wrapped in a tracing span so agent traces show the tool\n // invocation (query, filters, result count) nested under the model turn.\n // `withSpan` is a no-op until a Tracer is installed, so this is free by\n // default and adds nothing to the requirements.\n run: (args) =>\n search({\n query: args.query,\n maxResults,\n ...(args.recency !== undefined && { recency: args.recency }),\n ...(includeDomains !== undefined && { includeDomains }),\n ...(excludeDomains !== undefined && { excludeDomains }),\n }).pipe(\n Effect.tap((r) => Effect.annotateCurrentSpan(\"web_search.result_count\", r.results.length)),\n Effect.map((r) => render(r.results)),\n Effect.withSpan(name, {\n kind: \"client\",\n attributes: {\n \"web_search.query\": args.query,\n \"web_search.max_results\": maxResults,\n ...(args.recency !== undefined && { \"web_search.recency\": args.recency }),\n ...(includeDomains !== undefined && { \"web_search.include_domains\": includeDomains }),\n ...(excludeDomains !== undefined && { \"web_search.exclude_domains\": excludeDomains }),\n },\n }),\n ),\n })\n}\n"],"mappings":";;;;;;;;;;;;;;AAaA,MAAM,oBAAoB,OAAO,OAAO;CACtC,OAAO,OAAO;CACd,SAAS,OAAO,SAAS,
|
|
1
|
+
{"version":3,"file":"WebSearchTool.mjs","names":["Tool.make","Tool.fromEffectSchema"],"sources":["../../src/web-search/WebSearchTool.ts"],"sourcesContent":["import { Effect, Schema } from \"effect\"\nimport type * as AiError from \"../domain/AiError.js\"\nimport * as Tool from \"../tool/Tool.js\"\nimport { search, SearchRecency, type SearchResult, WebSearch } from \"./WebSearch.js\"\n\n/**\n * Model-facing argument schema. Deliberately narrow: `query` plus the one\n * filter that is genuinely the model's call - `recency` (it knows whether a\n * question is about current events or evergreen). App-policy scoping\n * (`includeDomains` / `excludeDomains`) and the `maxResults` cost ceiling\n * are pinned on the constructor instead, so they are guaranteed rather than\n * left to the model to remember each call.\n */\nconst WebSearchToolArgs = Schema.Struct({\n query: Schema.String,\n recency: Schema.optional(SearchRecency),\n})\n\nexport type WebSearchToolArgs = typeof WebSearchToolArgs.Type\n\n/** Numbered `title / url / snippet` list - what a model reads best. */\nconst defaultRender = (results: ReadonlyArray<SearchResult>): string =>\n results.length === 0\n ? \"No results found.\"\n : results\n .map((r, i) => {\n const head = `${i + 1}. ${r.title ?? r.url}\\n ${r.url}`\n return r.snippet === undefined ? head : `${head}\\n ${r.snippet}`\n })\n .join(\"\\n\\n\")\n\nexport type WebSearchToolOptions = {\n /** Tool name the model sees. Default `\"web_search\"`. */\n readonly name?: string\n /**\n * App-fixed ceiling on results per call - a cost guard, not exposed to\n * the model. Default `5`.\n */\n readonly maxResults?: number\n /**\n * App-fixed allowlist applied to every search. A policy scope (\"only\n * search our docs\"), not a model knob - so it is enforced, not requested.\n */\n readonly includeDomains?: ReadonlyArray<string>\n /** App-fixed denylist applied to every search (\"never return X\"). */\n readonly excludeDomains?: ReadonlyArray<string>\n /**\n * Override how results are rendered into the model-facing string.\n * Default: a numbered `title / url / snippet` list.\n */\n readonly render?: (results: ReadonlyArray<SearchResult>) => string\n}\n\n/**\n * The canonical web-search tool. Its `R` is just `WebSearch`, so providing\n * any search-provider Layer satisfies it and the model-facing contract\n * (name, description, schema) is identical no matter which backend answers\n * - swap `PerplexitySearch.layer` for `ExaSearch.layer` and the tool the\n * model sees does not change. Drops straight into a `Toolkit` and the\n * `LanguageModel` tool-calling loop.\n *\n * The model controls only `query` and `recency`; domain scoping and the\n * result cap are app policy, fixed here on the constructor. `Output` is the\n * rendered text (the model reads a numbered list better than raw\n * `SearchResult[]`; pass `render` to change the format); failures stay typed\n * on the `AiError` channel. To let the model recover from a failed search,\n * wrap the toolkit in `Toolkit.describeFailures(AiError.describe)`.\n *\n * This is a simple default implementation for quick use. For more elaborate\n * cases (a different output contract, more model-facing knobs), build your\n * own tool with `Tool.make` over the same `search` helper.\n */\nexport const webSearchTool = (\n options?: WebSearchToolOptions,\n): Tool.Tool<string, WebSearchToolArgs, never, string, AiError.AiError, WebSearch> => {\n const name = options?.name ?? \"web_search\"\n const render = options?.render ?? defaultRender\n const maxResults = options?.maxResults ?? 5\n const includeDomains = options?.includeDomains\n const excludeDomains = options?.excludeDomains\n return Tool.make({\n name,\n description:\n \"Search the web for current information. Returns ranked results with titles, URLs, and snippets.\",\n inputSchema: Tool.fromEffectSchema(WebSearchToolArgs),\n // The call is wrapped in a tracing span so agent traces show the tool\n // invocation (query, filters, result count) nested under the model turn.\n // `withSpan` is a no-op until a Tracer is installed, so this is free by\n // default and adds nothing to the requirements.\n run: (args) =>\n search({\n query: args.query,\n maxResults,\n ...(args.recency !== undefined && { recency: args.recency }),\n ...(includeDomains !== undefined && { includeDomains }),\n ...(excludeDomains !== undefined && { excludeDomains }),\n }).pipe(\n Effect.tap((r) => Effect.annotateCurrentSpan(\"web_search.result_count\", r.results.length)),\n Effect.map((r) => render(r.results)),\n Effect.withSpan(name, {\n kind: \"client\",\n attributes: {\n \"web_search.query\": args.query,\n \"web_search.max_results\": maxResults,\n ...(args.recency !== undefined && { \"web_search.recency\": args.recency }),\n ...(includeDomains !== undefined && { \"web_search.include_domains\": includeDomains }),\n ...(excludeDomains !== undefined && { \"web_search.exclude_domains\": excludeDomains }),\n },\n }),\n ),\n })\n}\n"],"mappings":";;;;;;;;;;;;;;AAaA,MAAM,oBAAoB,OAAO,OAAO;CACtC,OAAO,OAAO;CACd,SAAS,OAAO,SAAS,aAAa;AACxC,CAAC;;AAKD,MAAM,iBAAiB,YACrB,QAAQ,WAAW,IACf,sBACA,QACG,KAAK,GAAG,MAAM;CACb,MAAM,OAAO,GAAG,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,OAAO,EAAE;CACpD,OAAO,EAAE,YAAY,KAAA,IAAY,OAAO,GAAG,KAAK,OAAO,EAAE;AAC3D,CAAC,CAAC,CACD,KAAK,MAAM;;;;;;;;;;;;;;;;;;;;AA2CpB,MAAa,iBACX,YACoF;CACpF,MAAM,OAAO,SAAS,QAAQ;CAC9B,MAAM,SAAS,SAAS,UAAU;CAClC,MAAM,aAAa,SAAS,cAAc;CAC1C,MAAM,iBAAiB,SAAS;CAChC,MAAM,iBAAiB,SAAS;CAChC,OAAOA,KAAU;EACf;EACA,aACE;EACF,aAAaC,iBAAsB,iBAAiB;EAKpD,MAAM,SACJ,OAAO;GACL,OAAO,KAAK;GACZ;GACA,GAAI,KAAK,YAAY,KAAA,KAAa,EAAE,SAAS,KAAK,QAAQ;GAC1D,GAAI,mBAAmB,KAAA,KAAa,EAAE,eAAe;GACrD,GAAI,mBAAmB,KAAA,KAAa,EAAE,eAAe;EACvD,CAAC,CAAC,CAAC,KACD,OAAO,KAAK,MAAM,OAAO,oBAAoB,2BAA2B,EAAE,QAAQ,MAAM,CAAC,GACzF,OAAO,KAAK,MAAM,OAAO,EAAE,OAAO,CAAC,GACnC,OAAO,SAAS,MAAM;GACpB,MAAM;GACN,YAAY;IACV,oBAAoB,KAAK;IACzB,0BAA0B;IAC1B,GAAI,KAAK,YAAY,KAAA,KAAa,EAAE,sBAAsB,KAAK,QAAQ;IACvE,GAAI,mBAAmB,KAAA,KAAa,EAAE,8BAA8B,eAAe;IACnF,GAAI,mBAAmB,KAAA,KAAa,EAAE,8BAA8B,eAAe;GACrF;EACF,CAAC,CACH;CACJ,CAAC;AACH"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@effect-uai/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.0",
|
|
4
4
|
"description": "Low-level primitives (loop, conversation, items, tools, streaming codecs) for building AI agents with Effect.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"agents",
|
|
@@ -42,6 +42,10 @@
|
|
|
42
42
|
"types": "./dist/domain/Audio.d.mts",
|
|
43
43
|
"import": "./dist/domain/Audio.mjs"
|
|
44
44
|
},
|
|
45
|
+
"./Chunker": {
|
|
46
|
+
"types": "./dist/chunker/Chunker.d.mts",
|
|
47
|
+
"import": "./dist/chunker/Chunker.mjs"
|
|
48
|
+
},
|
|
45
49
|
"./Citation": {
|
|
46
50
|
"types": "./dist/domain/Citation.d.mts",
|
|
47
51
|
"import": "./dist/domain/Citation.mjs"
|
|
@@ -110,6 +114,10 @@
|
|
|
110
114
|
"types": "./dist/music-generator/MusicGenerator.d.mts",
|
|
111
115
|
"import": "./dist/music-generator/MusicGenerator.mjs"
|
|
112
116
|
},
|
|
117
|
+
"./Reranker": {
|
|
118
|
+
"types": "./dist/reranker/Reranker.d.mts",
|
|
119
|
+
"import": "./dist/reranker/Reranker.mjs"
|
|
120
|
+
},
|
|
113
121
|
"./Memory": {
|
|
114
122
|
"types": "./dist/sandbox/Memory.d.mts",
|
|
115
123
|
"import": "./dist/sandbox/Memory.mjs"
|
|
@@ -166,6 +174,10 @@
|
|
|
166
174
|
"types": "./dist/math/Vector.d.mts",
|
|
167
175
|
"import": "./dist/math/Vector.mjs"
|
|
168
176
|
},
|
|
177
|
+
"./Tokenizer": {
|
|
178
|
+
"types": "./dist/tokenizer/Tokenizer.d.mts",
|
|
179
|
+
"import": "./dist/tokenizer/Tokenizer.mjs"
|
|
180
|
+
},
|
|
169
181
|
"./Tool": {
|
|
170
182
|
"types": "./dist/tool/Tool.d.mts",
|
|
171
183
|
"import": "./dist/tool/Tool.mjs"
|
|
@@ -242,11 +254,11 @@
|
|
|
242
254
|
"@standard-schema/spec": "^1.1.0"
|
|
243
255
|
},
|
|
244
256
|
"devDependencies": {
|
|
245
|
-
"effect": "4.0.0-
|
|
246
|
-
"typescript": "^
|
|
257
|
+
"effect": "4.0.0-rc.111",
|
|
258
|
+
"typescript": "^7.0.2"
|
|
247
259
|
},
|
|
248
260
|
"peerDependencies": {
|
|
249
|
-
"effect": ">=4.0.0-
|
|
261
|
+
"effect": ">=4.0.0-rc.111 <5.0.0"
|
|
250
262
|
},
|
|
251
263
|
"scripts": {
|
|
252
264
|
"build": "tsdown",
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Context, Effect } from "effect"
|
|
2
|
+
import type * as AiError from "../domain/AiError.js"
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* A passage of a document, with the character offsets it came from.
|
|
6
|
+
*
|
|
7
|
+
* Implementor contract: `text` is the input's `[start, end)` slice verbatim,
|
|
8
|
+
* so a retrieved passage can be traced back to its source and enriched with
|
|
9
|
+
* what surrounds it. Chunks may overlap.
|
|
10
|
+
*/
|
|
11
|
+
export type Chunk = {
|
|
12
|
+
readonly text: string
|
|
13
|
+
readonly start: number
|
|
14
|
+
readonly end: number
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Splitting a document into retrievable passages. Strategy and sizing are
|
|
19
|
+
* fixed when the layer is built, so callers stay portable across a local
|
|
20
|
+
* splitter and a hosted chunking service.
|
|
21
|
+
*/
|
|
22
|
+
export type ChunkerService = {
|
|
23
|
+
readonly chunk: (text: string) => Effect.Effect<ReadonlyArray<Chunk>, AiError.AiError>
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export class Chunker extends Context.Service<Chunker, ChunkerService>()(
|
|
27
|
+
"@betalyra/effect-uai/Chunker",
|
|
28
|
+
) {}
|
|
29
|
+
|
|
30
|
+
/** Split a document into passages. */
|
|
31
|
+
export const chunk = (
|
|
32
|
+
text: string,
|
|
33
|
+
): Effect.Effect<ReadonlyArray<Chunk>, AiError.AiError, Chunker> =>
|
|
34
|
+
Effect.flatMap(Chunker, (chunker) => chunker.chunk(text))
|
package/src/index.ts
CHANGED
|
@@ -4,6 +4,7 @@ export * as Browser from "./browser/Browser.js"
|
|
|
4
4
|
export * as BrowserError from "./browser/BrowserError.js"
|
|
5
5
|
export * as BrowserTool from "./browser/BrowserTool.js"
|
|
6
6
|
export * as Capabilities from "./capabilities/Capabilities.js"
|
|
7
|
+
export * as Chunker from "./chunker/Chunker.js"
|
|
7
8
|
export * as Citation from "./domain/Citation.js"
|
|
8
9
|
export * as DeepResearch from "./research/DeepResearch.js"
|
|
9
10
|
export * as Image from "./domain/Image.js"
|
|
@@ -18,6 +19,7 @@ export * as Embedding from "./embedding-model/Embedding.js"
|
|
|
18
19
|
export * as EmbeddingModel from "./embedding-model/EmbeddingModel.js"
|
|
19
20
|
export * as LanguageModel from "./language-model/LanguageModel.js"
|
|
20
21
|
export * as MusicGenerator from "./music-generator/MusicGenerator.js"
|
|
22
|
+
export * as Reranker from "./reranker/Reranker.js"
|
|
21
23
|
export * as Memory from "./sandbox/Memory.js"
|
|
22
24
|
export * as Sandbox from "./sandbox/Sandbox.js"
|
|
23
25
|
export * as SandboxError from "./sandbox/SandboxError.js"
|
|
@@ -30,6 +32,7 @@ export * as WebReadTool from "./web-read/WebReadTool.js"
|
|
|
30
32
|
export * as WebSearch from "./web-search/WebSearch.js"
|
|
31
33
|
export * as WebSearchTool from "./web-search/WebSearchTool.js"
|
|
32
34
|
export * as Vector from "./math/Vector.js"
|
|
35
|
+
export * as Tokenizer from "./tokenizer/Tokenizer.js"
|
|
33
36
|
export * as Loop from "./loop/Loop.js"
|
|
34
37
|
export * as Retry from "./retry/Retry.js"
|
|
35
38
|
export * as Tool from "./tool/Tool.js"
|
package/src/loop/Loop.test.ts
CHANGED
|
@@ -68,10 +68,8 @@ describe("Loop.loop", () => {
|
|
|
68
68
|
|
|
69
69
|
it("propagates errors from the body's stream", async () => {
|
|
70
70
|
const boom = new Error("boom")
|
|
71
|
-
const stream = loop(
|
|
72
|
-
|
|
73
|
-
(n: number): Stream.Stream<Step<number, number>, Error> =>
|
|
74
|
-
n === 2 ? Stream.fail(boom) : Stream.succeed(value(n)).pipe(Stream.concat(next(n + 1))),
|
|
71
|
+
const stream = loop(0, (n: number): Stream.Stream<Step<number, number>, Error> =>
|
|
72
|
+
n === 2 ? Stream.fail(boom) : Stream.succeed(value(n)).pipe(Stream.concat(next(n + 1))),
|
|
75
73
|
)
|
|
76
74
|
|
|
77
75
|
const result = await Effect.runPromiseExit(Stream.runCollect(stream))
|
|
@@ -293,13 +291,12 @@ const conversationLoop = (initial: State, runTool: ToolRunner) =>
|
|
|
293
291
|
? Ref.update(textsRef, (t) => [...t, d.text])
|
|
294
292
|
: Ref.update(toolCallsRef, (t) => [...t, { id: d.id, name: d.name }]),
|
|
295
293
|
),
|
|
296
|
-
Stream.flatMap(
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
]),
|
|
294
|
+
Stream.flatMap((d): Stream.Stream<Step<UiEvent, State>> =>
|
|
295
|
+
d.type === "text"
|
|
296
|
+
? Stream.fromIterable([value<UiEvent>({ type: "text", text: d.text })])
|
|
297
|
+
: Stream.fromIterable([
|
|
298
|
+
value<UiEvent>({ type: "tool_started", id: d.id, name: d.name }),
|
|
299
|
+
]),
|
|
303
300
|
),
|
|
304
301
|
)
|
|
305
302
|
|
|
@@ -314,9 +311,11 @@ const conversationLoop = (initial: State, runTool: ToolRunner) =>
|
|
|
314
311
|
|
|
315
312
|
const turnItems: ReadonlyArray<HistoryItem> = [
|
|
316
313
|
...(texts.length > 0 ? [{ type: "assistant" as const, text: texts.join("") }] : []),
|
|
317
|
-
...toolCalls.map(
|
|
318
|
-
|
|
319
|
-
|
|
314
|
+
...toolCalls.map((tc): HistoryItem => ({
|
|
315
|
+
type: "tool_call",
|
|
316
|
+
id: tc.id,
|
|
317
|
+
name: tc.name,
|
|
318
|
+
})),
|
|
320
319
|
]
|
|
321
320
|
|
|
322
321
|
const outcomes = toolCalls.map((call) => ({ call, outcome: runTool(call) }))
|