@effect-uai/core 0.9.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.
Files changed (112) hide show
  1. package/dist/{AiError-CrdR1EQi.d.mts → AiError-Bf1pq4BB.d.mts} +8 -3
  2. package/dist/{AiError-CrdR1EQi.d.mts.map → AiError-Bf1pq4BB.d.mts.map} +1 -1
  3. package/dist/{Audio-DDSKCkSe.d.mts → Audio-CR7CSljJ.d.mts} +2 -2
  4. package/dist/{Audio-DDSKCkSe.d.mts.map → Audio-CR7CSljJ.d.mts.map} +1 -1
  5. package/dist/{Image-C_Zjpwhc.d.mts → Image-BZmKfIdq.d.mts} +2 -2
  6. package/dist/{Image-C_Zjpwhc.d.mts.map → Image-BZmKfIdq.d.mts.map} +1 -1
  7. package/dist/{Items-CgKD6Npw.d.mts → Items-BnIduEV2.d.mts} +9 -9
  8. package/dist/{Items-CgKD6Npw.d.mts.map → Items-BnIduEV2.d.mts.map} +1 -1
  9. package/dist/{Loop-B5_cqumi.d.mts → Loop-D8nWpowc.d.mts} +2 -2
  10. package/dist/{Loop-B5_cqumi.d.mts.map → Loop-D8nWpowc.d.mts.map} +1 -1
  11. package/dist/{Media-DOLyaygI.d.mts → Media-D_CpcM1Z.d.mts} +1 -1
  12. package/dist/{Media-DOLyaygI.d.mts.map → Media-D_CpcM1Z.d.mts.map} +1 -1
  13. package/dist/{StructuredFormat-CMJFD3sn.d.mts → StructuredFormat-DHaUJBdd.d.mts} +1 -1
  14. package/dist/{StructuredFormat-CMJFD3sn.d.mts.map → StructuredFormat-DHaUJBdd.d.mts.map} +1 -1
  15. package/dist/{Tool-0XUIT2A2.d.mts → Tool-2lC_XMth.d.mts} +64 -12
  16. package/dist/Tool-2lC_XMth.d.mts.map +1 -0
  17. package/dist/{ToolEvent-DYrAUJGs.d.mts → ToolEvent-cWZ2BnbS.d.mts} +2 -2
  18. package/dist/ToolEvent-cWZ2BnbS.d.mts.map +1 -0
  19. package/dist/{ToolResult-BZd-cEWW.d.mts → ToolResult-CL4hK_9z.d.mts} +10 -4
  20. package/dist/ToolResult-CL4hK_9z.d.mts.map +1 -0
  21. package/dist/{Toolkit-BKC8b8Xo.d.mts → Toolkit-Dr9l_hNy.d.mts} +64 -23
  22. package/dist/Toolkit-Dr9l_hNy.d.mts.map +1 -0
  23. package/dist/browser/Browser.d.mts +190 -0
  24. package/dist/browser/Browser.d.mts.map +1 -0
  25. package/dist/browser/Browser.mjs +34 -0
  26. package/dist/browser/Browser.mjs.map +1 -0
  27. package/dist/browser/BrowserError.d.mts +141 -0
  28. package/dist/browser/BrowserError.d.mts.map +1 -0
  29. package/dist/browser/BrowserError.mjs +89 -0
  30. package/dist/browser/BrowserError.mjs.map +1 -0
  31. package/dist/browser/BrowserTool.d.mts +58 -0
  32. package/dist/browser/BrowserTool.d.mts.map +1 -0
  33. package/dist/browser/BrowserTool.mjs +86 -0
  34. package/dist/browser/BrowserTool.mjs.map +1 -0
  35. package/dist/domain/AiError.d.mts +2 -2
  36. package/dist/domain/AiError.mjs +22 -3
  37. package/dist/domain/AiError.mjs.map +1 -1
  38. package/dist/domain/Audio.d.mts +1 -1
  39. package/dist/domain/Image.d.mts +1 -1
  40. package/dist/domain/Items.d.mts +1 -1
  41. package/dist/domain/Media.d.mts +1 -1
  42. package/dist/domain/Music.d.mts +1 -1
  43. package/dist/domain/Turn.d.mts +3 -3
  44. package/dist/embedding-model/Embedding.d.mts +1 -1
  45. package/dist/embedding-model/EmbeddingModel.d.mts +1 -1
  46. package/dist/index.d.mts +17 -12
  47. package/dist/index.mjs +14 -9
  48. package/dist/language-model/LanguageModel.d.mts +4 -4
  49. package/dist/loop/Loop.d.mts +1 -1
  50. package/dist/music-generator/MusicGenerator.d.mts +2 -2
  51. package/dist/observability/Metrics.d.mts +1 -1
  52. package/dist/retry/Retry.d.mts +1 -1
  53. package/dist/speech-synthesizer/SpeechSynthesizer.d.mts +2 -2
  54. package/dist/structured-format/StructuredFormat.d.mts +1 -1
  55. package/dist/testing/MockMusicGenerator.d.mts +1 -1
  56. package/dist/testing/MockProvider.d.mts +1 -1
  57. package/dist/testing/MockSpeechSynthesizer.d.mts +1 -1
  58. package/dist/tool/Approval.d.mts +19 -7
  59. package/dist/tool/Approval.d.mts.map +1 -1
  60. package/dist/tool/Approval.mjs +18 -11
  61. package/dist/tool/Approval.mjs.map +1 -1
  62. package/dist/tool/Approval.test.mjs +46 -7
  63. package/dist/tool/Approval.test.mjs.map +1 -1
  64. package/dist/tool/HistoryCheck.d.mts +2 -2
  65. package/dist/tool/Tool.d.mts +2 -2
  66. package/dist/tool/Tool.mjs +86 -22
  67. package/dist/tool/Tool.mjs.map +1 -1
  68. package/dist/tool/ToolEvent.d.mts +1 -1
  69. package/dist/tool/ToolEvent.mjs +5 -0
  70. package/dist/tool/ToolEvent.mjs.map +1 -1
  71. package/dist/tool/ToolResult.d.mts +2 -2
  72. package/dist/tool/ToolResult.mjs +15 -6
  73. package/dist/tool/ToolResult.mjs.map +1 -1
  74. package/dist/tool/Toolkit.d.mts +2 -2
  75. package/dist/tool/Toolkit.mjs +62 -22
  76. package/dist/tool/Toolkit.mjs.map +1 -1
  77. package/dist/tool/Toolkit.test.mjs +163 -9
  78. package/dist/tool/Toolkit.test.mjs.map +1 -1
  79. package/dist/transcriber/Transcriber.d.mts +2 -2
  80. package/dist/web-read/WebRead.d.mts +44 -0
  81. package/dist/web-read/WebRead.d.mts.map +1 -0
  82. package/dist/web-read/WebRead.mjs +18 -0
  83. package/dist/web-read/WebRead.mjs.map +1 -0
  84. package/dist/web-read/WebReadTool.d.mts +57 -0
  85. package/dist/web-read/WebReadTool.d.mts.map +1 -0
  86. package/dist/web-read/WebReadTool.mjs +59 -0
  87. package/dist/web-read/WebReadTool.mjs.map +1 -0
  88. package/dist/web-search/WebSearch.d.mts +1 -1
  89. package/dist/web-search/WebSearchTool.d.mts +12 -6
  90. package/dist/web-search/WebSearchTool.d.mts.map +1 -1
  91. package/dist/web-search/WebSearchTool.mjs +10 -5
  92. package/dist/web-search/WebSearchTool.mjs.map +1 -1
  93. package/package.json +21 -1
  94. package/src/browser/Browser.ts +268 -0
  95. package/src/browser/BrowserError.ts +145 -0
  96. package/src/browser/BrowserTool.ts +161 -0
  97. package/src/domain/AiError.ts +27 -1
  98. package/src/index.ts +5 -0
  99. package/src/tool/Approval.test.ts +55 -5
  100. package/src/tool/Approval.ts +72 -27
  101. package/src/tool/Tool.ts +146 -47
  102. package/src/tool/ToolEvent.ts +5 -0
  103. package/src/tool/ToolResult.ts +14 -8
  104. package/src/tool/Toolkit.test.ts +171 -2
  105. package/src/tool/Toolkit.ts +173 -60
  106. package/src/web-read/WebRead.ts +70 -0
  107. package/src/web-read/WebReadTool.ts +96 -0
  108. package/src/web-search/WebSearchTool.ts +11 -5
  109. package/dist/Tool-0XUIT2A2.d.mts.map +0 -1
  110. package/dist/ToolEvent-DYrAUJGs.d.mts.map +0 -1
  111. package/dist/ToolResult-BZd-cEWW.d.mts.map +0 -1
  112. package/dist/Toolkit-BKC8b8Xo.d.mts.map +0 -1
@@ -0,0 +1,44 @@
1
+ import { t as AiError } from "../AiError-Bf1pq4BB.mjs";
2
+ import { Context, Duration, Effect } from "effect";
3
+
4
+ //#region src/web-read/WebRead.d.ts
5
+ declare namespace WebRead_d_exports {
6
+ export { CommonReadRequest, ReadFormat, ReadResponse, WebRead, WebReadService, read };
7
+ }
8
+ /** Representation to return for a page. `markdown` is the default. */
9
+ type ReadFormat = "markdown" | "html";
10
+ /**
11
+ * Cross-provider read request: one URL in, clean content out. Provider-specific
12
+ * knobs live on the provider-typed request.
13
+ */
14
+ type CommonReadRequest = {
15
+ /** The page to read. */readonly url: string; /** Output representation. Defaults to `markdown`. See {@link ReadFormat}. */
16
+ readonly format?: ReadFormat; /** Upper bound on time spent fetching the page. */
17
+ readonly timeout?: Duration.Duration;
18
+ };
19
+ /** One normalized read result. */
20
+ type ReadResponse = {
21
+ /** The URL that was read. */readonly url: string; /** Extracted content in the requested {@link ReadFormat}. */
22
+ readonly content: string; /** Page title, when reported. */
23
+ readonly title?: string; /** Links discovered on the page, when returned. */
24
+ readonly links?: ReadonlyArray<string>; /** The provider-native response. */
25
+ readonly raw: unknown;
26
+ };
27
+ /**
28
+ * The portable read surface: one operation, `read`. Every implementor can
29
+ * answer, so this capability needs no marker tags.
30
+ */
31
+ type WebReadService = {
32
+ readonly read: (request: CommonReadRequest) => Effect.Effect<ReadResponse, AiError>;
33
+ };
34
+ declare const WebRead_base: Context.ServiceClass<WebRead, "@betalyra/effect-uai/WebRead", WebReadService>;
35
+ /**
36
+ * Generic read service tag. Yield this for provider-portable code; yield a
37
+ * provider tag for provider-specific knobs. A provider `layer` registers both.
38
+ */
39
+ declare class WebRead extends WebRead_base {}
40
+ /** Read one URL against whichever provider Layer is in scope. */
41
+ declare const read: (request: CommonReadRequest) => Effect.Effect<ReadResponse, AiError, WebRead>;
42
+ //#endregion
43
+ export { CommonReadRequest, ReadFormat, ReadResponse, WebRead, WebReadService, read, WebRead_d_exports as t };
44
+ //# sourceMappingURL=WebRead.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"WebRead.d.mts","names":[],"sources":["../../src/web-read/WebRead.ts"],"mappings":";;;;;;;;KAQY,UAAA;;;;;KAUA,iBAAA;mCAED,GAAA;WAEA,MAAA,GAAS,UAAA,EAdR;EAAA,SAgBD,OAAA,GAAU,QAAA,CAAS,QAAA;AAAA;;KAQlB,YAAA;EAdA,sCAgBD,GAAA;WAEA,OAAA,UAhBA;EAAA,SAkBA,KAAA,WAhBS;EAAA,SAkBT,KAAA,GAAQ,aAAA,UAhBE;EAAA,SAkBV,GAAA;AAAA;;AAVX;;;KAqBY,cAAA;EAAA,SACD,IAAA,GAAO,OAAA,EAAS,iBAAA,KAAsB,MAAA,CAAO,MAAA,CAAO,YAAA,EAAc,OAAA;AAAA;AAAA,cAC5E,YAAA;;;;;cAMY,OAAA,SAAgB,YAAA;;cAKhB,IAAA,GACX,OAAA,EAAS,iBAAA,KACR,MAAA,CAAO,MAAA,CAAO,YAAA,EAAc,OAAA,EAAiB,OAAA"}
@@ -0,0 +1,18 @@
1
+ import { n as __exportAll } from "../chunk-uyGKjUfl.mjs";
2
+ import { Context, Effect } from "effect";
3
+ //#region src/web-read/WebRead.ts
4
+ var WebRead_exports = /* @__PURE__ */ __exportAll({
5
+ WebRead: () => WebRead,
6
+ read: () => read
7
+ });
8
+ /**
9
+ * Generic read service tag. Yield this for provider-portable code; yield a
10
+ * provider tag for provider-specific knobs. A provider `layer` registers both.
11
+ */
12
+ var WebRead = class extends Context.Service()("@betalyra/effect-uai/WebRead") {};
13
+ /** Read one URL against whichever provider Layer is in scope. */
14
+ const read = (request) => Effect.flatMap(WebRead.asEffect(), (s) => s.read(request));
15
+ //#endregion
16
+ export { WebRead, read, WebRead_exports as t };
17
+
18
+ //# sourceMappingURL=WebRead.mjs.map
@@ -0,0 +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.asEffect(), (s) => s.read(request))\n"],"mappings":";;;;;;;;;;;AA6DA,IAAa,UAAb,cAA6B,QAAQ,SAAkC,CACrE,+BACD,CAAC;;AAGF,MAAa,QACX,YAEA,OAAO,QAAQ,QAAQ,UAAU,GAAG,MAAM,EAAE,KAAK,QAAQ,CAAC"}
@@ -0,0 +1,57 @@
1
+ import { l as Tool } from "../Tool-2lC_XMth.mjs";
2
+ import { t as AiError } from "../AiError-Bf1pq4BB.mjs";
3
+ import { ReadFormat, ReadResponse, WebRead } from "./WebRead.mjs";
4
+ import { Schema } from "effect";
5
+
6
+ //#region src/web-read/WebReadTool.d.ts
7
+ declare namespace WebReadTool_d_exports {
8
+ export { WebReadToolArgs, WebReadToolOptions, webReadTool };
9
+ }
10
+ /**
11
+ * Model-facing argument schema. Deliberately narrow: the URL is the only
12
+ * thing that is genuinely the model's call. Output format and the content
13
+ * cost ceiling are app policy, pinned on the constructor instead, so they
14
+ * are guaranteed rather than left to the model to remember each call.
15
+ */
16
+ declare const WebReadToolArgs: Schema.Struct<{
17
+ readonly url: Schema.String;
18
+ }>;
19
+ type WebReadToolArgs = typeof WebReadToolArgs.Type;
20
+ type WebReadToolOptions = {
21
+ /** Tool name the model sees. Default `"web_read"`. */readonly name?: string;
22
+ /**
23
+ * App-fixed representation for every read - a policy choice, not a model
24
+ * knob. Default `"markdown"` (what models read best).
25
+ */
26
+ readonly format?: ReadFormat;
27
+ /**
28
+ * App-fixed ceiling on rendered content characters per call - a context
29
+ * cost guard, not exposed to the model. Default `20000`.
30
+ */
31
+ readonly maxChars?: number;
32
+ /**
33
+ * Override how a read response is rendered into the model-facing string.
34
+ * Default: `title / url` header plus the content, truncated at `maxChars`.
35
+ */
36
+ readonly render?: (response: ReadResponse) => string;
37
+ };
38
+ /**
39
+ * The canonical web-read tool. Its `R` is just `WebRead`, so providing any
40
+ * read-provider Layer satisfies it and the model-facing contract (name,
41
+ * description, schema) is identical no matter which backend answers - swap
42
+ * `FirecrawlRead.layer` for `JinaRead.layer` and the tool the model sees
43
+ * does not change. Drops straight into a `Toolkit` next to `webSearchTool`
44
+ * (search finds the URLs, read fetches the ones worth reading in full).
45
+ *
46
+ * `Output` is the rendered page; failures stay typed on the `AiError`
47
+ * channel. To let the model recover from a failed read, wrap the toolkit in
48
+ * `Toolkit.describeFailures(AiError.describe)`.
49
+ *
50
+ * This is a simple default implementation for quick use. For more elaborate
51
+ * cases (a different output contract, more model-facing knobs), build your
52
+ * own tool with `Tool.make` over the same `read` helper.
53
+ */
54
+ declare const webReadTool: (options?: WebReadToolOptions) => Tool<string, WebReadToolArgs, never, string, AiError, WebRead>;
55
+ //#endregion
56
+ export { WebReadToolArgs, WebReadToolOptions, WebReadTool_d_exports as t, webReadTool };
57
+ //# sourceMappingURL=WebReadTool.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"WebReadTool.d.mts","names":[],"sources":["../../src/web-read/WebReadTool.ts"],"mappings":";;;;;;;;;;;;;;;cAWM,eAAA,EAAe,MAAA,CAAA,MAAA;EAAA,cAInB,MAAA,CAAA,MAAA;AAAA;AAAA,KAEU,eAAA,UAAyB,eAAA,CAAgB,IAAA;AAAA,KAYzC,kBAAA;EAlBS,+DAoBV,IAAA;EApBU;;;;EAAA,SAyBV,MAAA,GAAS,UAAA;;AAnBpB;;;WAwBW,QAAA;EAxB8C;AAYzD;;;EAZyD,SA6B9C,MAAA,IAAU,QAAA,EAAU,YAAA;AAAA;;;;;;;;;AAmB/B;;;;;;;;cAAa,WAAA,GACX,OAAA,GAAU,kBAAA,KACT,IAAA,SAAkB,eAAA,iBAAgC,OAAA,EAAiB,OAAA"}
@@ -0,0 +1,59 @@
1
+ import { n as __exportAll } from "../chunk-uyGKjUfl.mjs";
2
+ import { fromEffectSchema, make } from "../tool/Tool.mjs";
3
+ import { read } from "./WebRead.mjs";
4
+ import { Effect, Schema } from "effect";
5
+ //#region src/web-read/WebReadTool.ts
6
+ var WebReadTool_exports = /* @__PURE__ */ __exportAll({ webReadTool: () => webReadTool });
7
+ /**
8
+ * Model-facing argument schema. Deliberately narrow: the URL is the only
9
+ * thing that is genuinely the model's call. Output format and the content
10
+ * cost ceiling are app policy, pinned on the constructor instead, so they
11
+ * are guaranteed rather than left to the model to remember each call.
12
+ */
13
+ const WebReadToolArgs = Schema.Struct({ url: Schema.String.annotate({ description: "Absolute URL of the page to read." }) });
14
+ /** `title / url` header plus the extracted content - what a model reads best. */
15
+ const defaultRender = (response, maxChars) => {
16
+ return `${response.title === void 0 ? response.url : `${response.title}\n${response.url}`}\n\n${response.content.length > maxChars ? `${response.content.slice(0, maxChars)}\n[content truncated at ${maxChars} characters]` : response.content}`;
17
+ };
18
+ /**
19
+ * The canonical web-read tool. Its `R` is just `WebRead`, so providing any
20
+ * read-provider Layer satisfies it and the model-facing contract (name,
21
+ * description, schema) is identical no matter which backend answers - swap
22
+ * `FirecrawlRead.layer` for `JinaRead.layer` and the tool the model sees
23
+ * does not change. Drops straight into a `Toolkit` next to `webSearchTool`
24
+ * (search finds the URLs, read fetches the ones worth reading in full).
25
+ *
26
+ * `Output` is the rendered page; failures stay typed on the `AiError`
27
+ * channel. To let the model recover from a failed read, wrap the toolkit in
28
+ * `Toolkit.describeFailures(AiError.describe)`.
29
+ *
30
+ * This is a simple default implementation for quick use. For more elaborate
31
+ * cases (a different output contract, more model-facing knobs), build your
32
+ * own tool with `Tool.make` over the same `read` helper.
33
+ */
34
+ const webReadTool = (options) => {
35
+ const name = options?.name ?? "web_read";
36
+ const format = options?.format ?? "markdown";
37
+ const maxChars = options?.maxChars ?? 2e4;
38
+ const render = options?.render ?? ((response) => defaultRender(response, maxChars));
39
+ return make({
40
+ name,
41
+ description: "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).",
42
+ inputSchema: fromEffectSchema(WebReadToolArgs),
43
+ run: (args) => read({
44
+ url: args.url,
45
+ format
46
+ }).pipe(Effect.tap((r) => Effect.annotateCurrentSpan("web_read.content_chars", r.content.length)), Effect.map(render), Effect.withSpan(name, {
47
+ kind: "client",
48
+ attributes: {
49
+ "web_read.url": args.url,
50
+ "web_read.format": format,
51
+ "web_read.max_chars": maxChars
52
+ }
53
+ }))
54
+ });
55
+ };
56
+ //#endregion
57
+ export { WebReadTool_exports as t, webReadTool };
58
+
59
+ //# sourceMappingURL=WebReadTool.mjs.map
@@ -0,0 +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,qCACd,CAAC,EACH,CAAC;;AAKF,MAAM,iBAAiB,UAAwB,aAA6B;AAM1E,QAAO,GALQ,SAAS,UAAU,KAAA,IAAY,SAAS,MAAM,GAAG,SAAS,MAAM,IAAI,SAAS,MAK3E,MAHf,SAAS,QAAQ,SAAS,WACtB,GAAG,SAAS,QAAQ,MAAM,GAAG,SAAS,CAAC,0BAA0B,SAAS,gBAC1E,SAAS;;;;;;;;;;;;;;;;;;AAwCjB,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,SAAS;AAChG,QAAOA,KAAU;EACf;EACA,aACE;EACF,aAAaC,iBAAsB,gBAAgB;EAKnD,MAAM,SACJ,KAAK;GAAE,KAAK,KAAK;GAAK;GAAQ,CAAC,CAAC,KAC9B,OAAO,KAAK,MAAM,OAAO,oBAAoB,0BAA0B,EAAE,QAAQ,OAAO,CAAC,EACzF,OAAO,IAAI,OAAO,EAClB,OAAO,SAAS,MAAM;GACpB,MAAM;GACN,YAAY;IACV,gBAAgB,KAAK;IACrB,mBAAmB;IACnB,sBAAsB;IACvB;GACF,CAAC,CACH;EACJ,CAAC"}
@@ -1,4 +1,4 @@
1
- import { t as AiError } from "../AiError-CrdR1EQi.mjs";
1
+ import { t as AiError } from "../AiError-Bf1pq4BB.mjs";
2
2
  import { Context, DateTime, Effect, Schema } from "effect";
3
3
 
4
4
  //#region src/web-search/WebSearch.d.ts
@@ -1,4 +1,5 @@
1
- import { c as Tool } from "../Tool-0XUIT2A2.mjs";
1
+ import { l as Tool } from "../Tool-2lC_XMth.mjs";
2
+ import { t as AiError } from "../AiError-Bf1pq4BB.mjs";
2
3
  import { SearchResult, WebSearch } from "./WebSearch.mjs";
3
4
  import { Schema } from "effect";
4
5
 
@@ -47,12 +48,17 @@ type WebSearchToolOptions = {
47
48
  * `LanguageModel` tool-calling loop.
48
49
  *
49
50
  * The model controls only `query` and `recency`; domain scoping and the
50
- * result cap are app policy, fixed here on the constructor. `Output` is
51
- * rendered text, not raw `SearchResult[]`: the model reads the list, while
52
- * the app still gets the structured results through the normal tool-result
53
- * channel. Pass `render` to change the format.
51
+ * result cap are app policy, fixed here on the constructor. `Output` is the
52
+ * rendered text (the model reads a numbered list better than raw
53
+ * `SearchResult[]`; pass `render` to change the format); failures stay typed
54
+ * on the `AiError` channel. To let the model recover from a failed search,
55
+ * wrap the toolkit in `Toolkit.describeFailures(AiError.describe)`.
56
+ *
57
+ * This is a simple default implementation for quick use. For more elaborate
58
+ * cases (a different output contract, more model-facing knobs), build your
59
+ * own tool with `Tool.make` over the same `search` helper.
54
60
  */
55
- declare const webSearchTool: (options?: WebSearchToolOptions) => Tool<string, WebSearchToolArgs, never, string, WebSearch>;
61
+ declare const webSearchTool: (options?: WebSearchToolOptions) => Tool<string, WebSearchToolArgs, never, string, AiError, WebSearch>;
56
62
  //#endregion
57
63
  export { WebSearchToolArgs, WebSearchToolOptions, WebSearchTool_d_exports as t, webSearchTool };
58
64
  //# sourceMappingURL=WebSearchTool.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"WebSearchTool.d.mts","names":[],"sources":["../../src/web-search/WebSearchTool.ts"],"mappings":";;;;;;;;;;;;;;;;cAYM,iBAAA,EAAiB,MAAA,CAAA,MAAA;EAAA;;;KAKX,iBAAA,UAA2B,iBAAA,CAAkB,IAAA;AAAA,KAa7C,oBAAA;EAlBW,iEAoBZ,IAAA;EApBY;;;;EAAA,SAyBZ,UAAA;;;;;WAKA,cAAA,GAAiB,aAAA;WAEjB,cAAA,GAAiB,aAAA;;AA3B5B;;;WAgCW,MAAA,IAAU,OAAA,EAAS,aAAA,CAAc,YAAA;AAAA;AAnB5C;;;;;;;;;;;;;;AAAA,cAoCa,aAAA,GACX,OAAA,GAAU,oBAAA,KACT,IAAA,SAAkB,iBAAA,iBAAkC,SAAA"}
1
+ {"version":3,"file":"WebSearchTool.d.mts","names":[],"sources":["../../src/web-search/WebSearchTool.ts"],"mappings":";;;;;;;;;;;;;;;;;cAaM,iBAAA,EAAiB,MAAA,CAAA,MAAA;EAAA;;;KAKX,iBAAA,UAA2B,iBAAA,CAAkB,IAAA;AAAA,KAa7C,oBAAA;EAlBW,iEAoBZ,IAAA;EApBY;;;;EAAA,SAyBZ,UAAA;;;;;WAKA,cAAA,GAAiB,aAAA;WAEjB,cAAA,GAAiB,aAAA;;AA3B5B;;;WAgCW,MAAA,IAAU,OAAA,EAAS,aAAA,CAAc,YAAA;AAAA;AAnB5C;;;;;;;;;;;;;;;;;;;AAAA,cAyCa,aAAA,GACX,OAAA,GAAU,oBAAA,KACT,IAAA,SAAkB,iBAAA,iBAAkC,OAAA,EAAiB,SAAA"}
@@ -1,6 +1,6 @@
1
1
  import { n as __exportAll } from "../chunk-uyGKjUfl.mjs";
2
- import { SearchRecency, search } from "./WebSearch.mjs";
3
2
  import { fromEffectSchema, make } from "../tool/Tool.mjs";
3
+ import { SearchRecency, search } from "./WebSearch.mjs";
4
4
  import { Effect, Schema } from "effect";
5
5
  //#region src/web-search/WebSearchTool.ts
6
6
  var WebSearchTool_exports = /* @__PURE__ */ __exportAll({ webSearchTool: () => webSearchTool });
@@ -30,10 +30,15 @@ const defaultRender = (results) => results.length === 0 ? "No results found." :
30
30
  * `LanguageModel` tool-calling loop.
31
31
  *
32
32
  * The model controls only `query` and `recency`; domain scoping and the
33
- * result cap are app policy, fixed here on the constructor. `Output` is
34
- * rendered text, not raw `SearchResult[]`: the model reads the list, while
35
- * the app still gets the structured results through the normal tool-result
36
- * channel. Pass `render` to change the format.
33
+ * result cap are app policy, fixed here on the constructor. `Output` is the
34
+ * rendered text (the model reads a numbered list better than raw
35
+ * `SearchResult[]`; pass `render` to change the format); failures stay typed
36
+ * on the `AiError` channel. To let the model recover from a failed search,
37
+ * wrap the toolkit in `Toolkit.describeFailures(AiError.describe)`.
38
+ *
39
+ * This is a simple default implementation for quick use. For more elaborate
40
+ * cases (a different output contract, more model-facing knobs), build your
41
+ * own tool with `Tool.make` over the same `search` helper.
37
42
  */
38
43
  const webSearchTool = (options) => {
39
44
  const name = options?.name ?? "web_search";
@@ -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 * 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\n * rendered text, not raw `SearchResult[]`: the model reads the list, while\n * the app still gets the structured results through the normal tool-result\n * channel. Pass `render` to change the format.\n */\nexport const webSearchTool = (\n options?: WebSearchToolOptions,\n): Tool.Tool<string, WebSearchToolArgs, never, string, 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":";;;;;;;;;;;;;;AAYA,MAAM,oBAAoB,OAAO,OAAO;CACtC,OAAO,OAAO;CACd,SAAS,OAAO,SAAS,cAAc;CACxC,CAAC;;AAKF,MAAM,iBAAiB,YACrB,QAAQ,WAAW,IACf,sBACA,QACG,KAAK,GAAG,MAAM;CACb,MAAM,OAAO,GAAG,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,OAAO,EAAE;AACpD,QAAO,EAAE,YAAY,KAAA,IAAY,OAAO,GAAG,KAAK,OAAO,EAAE;EACzD,CACD,KAAK,OAAO;;;;;;;;;;;;;;;AAsCrB,MAAa,iBACX,YACmE;CACnE,MAAM,OAAO,SAAS,QAAQ;CAC9B,MAAM,SAAS,SAAS,UAAU;CAClC,MAAM,aAAa,SAAS,cAAc;CAC1C,MAAM,iBAAiB,SAAS;CAChC,MAAM,iBAAiB,SAAS;AAChC,QAAOA,KAAU;EACf;EACA,aACE;EACF,aAAaC,iBAAsB,kBAAkB;EAKrD,MAAM,SACJ,OAAO;GACL,OAAO,KAAK;GACZ;GACA,GAAI,KAAK,YAAY,KAAA,KAAa,EAAE,SAAS,KAAK,SAAS;GAC3D,GAAI,mBAAmB,KAAA,KAAa,EAAE,gBAAgB;GACtD,GAAI,mBAAmB,KAAA,KAAa,EAAE,gBAAgB;GACvD,CAAC,CAAC,KACD,OAAO,KAAK,MAAM,OAAO,oBAAoB,2BAA2B,EAAE,QAAQ,OAAO,CAAC,EAC1F,OAAO,KAAK,MAAM,OAAO,EAAE,QAAQ,CAAC,EACpC,OAAO,SAAS,MAAM;GACpB,MAAM;GACN,YAAY;IACV,oBAAoB,KAAK;IACzB,0BAA0B;IAC1B,GAAI,KAAK,YAAY,KAAA,KAAa,EAAE,sBAAsB,KAAK,SAAS;IACxE,GAAI,mBAAmB,KAAA,KAAa,EAAE,8BAA8B,gBAAgB;IACpF,GAAI,mBAAmB,KAAA,KAAa,EAAE,8BAA8B,gBAAgB;IACrF;GACF,CAAC,CACH;EACJ,CAAC"}
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,cAAc;CACxC,CAAC;;AAKF,MAAM,iBAAiB,YACrB,QAAQ,WAAW,IACf,sBACA,QACG,KAAK,GAAG,MAAM;CACb,MAAM,OAAO,GAAG,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,OAAO,EAAE;AACpD,QAAO,EAAE,YAAY,KAAA,IAAY,OAAO,GAAG,KAAK,OAAO,EAAE;EACzD,CACD,KAAK,OAAO;;;;;;;;;;;;;;;;;;;;AA2CrB,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;AAChC,QAAOA,KAAU;EACf;EACA,aACE;EACF,aAAaC,iBAAsB,kBAAkB;EAKrD,MAAM,SACJ,OAAO;GACL,OAAO,KAAK;GACZ;GACA,GAAI,KAAK,YAAY,KAAA,KAAa,EAAE,SAAS,KAAK,SAAS;GAC3D,GAAI,mBAAmB,KAAA,KAAa,EAAE,gBAAgB;GACtD,GAAI,mBAAmB,KAAA,KAAa,EAAE,gBAAgB;GACvD,CAAC,CAAC,KACD,OAAO,KAAK,MAAM,OAAO,oBAAoB,2BAA2B,EAAE,QAAQ,OAAO,CAAC,EAC1F,OAAO,KAAK,MAAM,OAAO,EAAE,QAAQ,CAAC,EACpC,OAAO,SAAS,MAAM;GACpB,MAAM;GACN,YAAY;IACV,oBAAoB,KAAK;IACzB,0BAA0B;IAC1B,GAAI,KAAK,YAAY,KAAA,KAAa,EAAE,sBAAsB,KAAK,SAAS;IACxE,GAAI,mBAAmB,KAAA,KAAa,EAAE,8BAA8B,gBAAgB;IACpF,GAAI,mBAAmB,KAAA,KAAa,EAAE,8BAA8B,gBAAgB;IACrF;GACF,CAAC,CACH;EACJ,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@effect-uai/core",
3
- "version": "0.9.0",
3
+ "version": "0.10.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,18 @@
42
42
  "types": "./dist/domain/Audio.d.mts",
43
43
  "import": "./dist/domain/Audio.mjs"
44
44
  },
45
+ "./Browser": {
46
+ "types": "./dist/browser/Browser.d.mts",
47
+ "import": "./dist/browser/Browser.mjs"
48
+ },
49
+ "./BrowserError": {
50
+ "types": "./dist/browser/BrowserError.d.mts",
51
+ "import": "./dist/browser/BrowserError.mjs"
52
+ },
53
+ "./BrowserTool": {
54
+ "types": "./dist/browser/BrowserTool.d.mts",
55
+ "import": "./dist/browser/BrowserTool.mjs"
56
+ },
45
57
  "./Image": {
46
58
  "types": "./dist/domain/Image.d.mts",
47
59
  "import": "./dist/domain/Image.mjs"
@@ -110,6 +122,14 @@
110
122
  "types": "./dist/transcriber/Transcriber.d.mts",
111
123
  "import": "./dist/transcriber/Transcriber.mjs"
112
124
  },
125
+ "./WebRead": {
126
+ "types": "./dist/web-read/WebRead.d.mts",
127
+ "import": "./dist/web-read/WebRead.mjs"
128
+ },
129
+ "./WebReadTool": {
130
+ "types": "./dist/web-read/WebReadTool.d.mts",
131
+ "import": "./dist/web-read/WebReadTool.mjs"
132
+ },
113
133
  "./WebSearch": {
114
134
  "types": "./dist/web-search/WebSearch.d.mts",
115
135
  "import": "./dist/web-search/WebSearch.mjs"
@@ -0,0 +1,268 @@
1
+ import { Brand, Context, type Duration, Effect, Scope } from "effect"
2
+ import type * as BrowserError from "./BrowserError.js"
3
+
4
+ // ---------------------------------------------------------------------------
5
+ // Identity
6
+ // ---------------------------------------------------------------------------
7
+
8
+ /**
9
+ * Session identifier. Branded `string` so providers don't accidentally
10
+ * accept a raw user-supplied id, and so a session id can't be passed where
11
+ * another service's id is expected. Each provider mints these per its own
12
+ * scheme; core code treats them opaquely. Mint via `BrowserSessionId(...)`.
13
+ */
14
+ export type BrowserSessionId = Brand.Branded<string, "BrowserSessionId">
15
+ export const BrowserSessionId = Brand.nominal<BrowserSessionId>()
16
+
17
+ /** Reference returned by `list`; enough to `attach`. */
18
+ export type BrowserSessionRef = {
19
+ readonly id: BrowserSessionId
20
+ /** Current top-level URL, when the provider reports it. */
21
+ readonly url?: string
22
+ }
23
+
24
+ /**
25
+ * Output representation for {@link BrowserSession.content}. `markdown` is
26
+ * the default.
27
+ */
28
+ export type PageFormat = "markdown" | "html"
29
+
30
+ // ---------------------------------------------------------------------------
31
+ // Create request
32
+ // ---------------------------------------------------------------------------
33
+
34
+ /**
35
+ * Cross-provider session-create request. Provider-specific knobs (proxy,
36
+ * stealth, persistent profile, ...) live on each provider's narrowed
37
+ * request type which extends this.
38
+ */
39
+ export type CommonSessionRequest = {
40
+ /**
41
+ * Hard max lifetime of the session. Enforced locally (the handle is
42
+ * disposed and further calls fail with `BrowserSessionExpired`) and,
43
+ * where the provider supports it, passed through as a server-side cap so
44
+ * a crashed client still gets the session reclaimed. The provider cap
45
+ * must be >= the local reaper. Accepts millis, a string like
46
+ * `"5 minutes"`, or a `Duration`.
47
+ */
48
+ readonly timeout?: Duration.Input
49
+ /**
50
+ * Idle teardown: dispose the session after this much inactivity, the
51
+ * timer resetting on each operation. Opt-in; omit for no idle limit.
52
+ */
53
+ readonly idleTimeout?: Duration.Input
54
+ /** Initial viewport size. Providers default differently. */
55
+ readonly viewport?: { readonly width: number; readonly height: number }
56
+ }
57
+
58
+ // ---------------------------------------------------------------------------
59
+ // Observation shapes
60
+ // ---------------------------------------------------------------------------
61
+
62
+ export type BoundingBox = {
63
+ readonly x: number
64
+ readonly y: number
65
+ readonly width: number
66
+ readonly height: number
67
+ }
68
+
69
+ /**
70
+ * One element returned by {@link BrowserSession.query}. Serializable data,
71
+ * not a live handle (handles go stale across navigation and do not cross a
72
+ * provider boundary cleanly).
73
+ */
74
+ export type ElementInfo = {
75
+ /**
76
+ * Reference usable as a selector for a follow-up action. Valid until the
77
+ * next navigation; do not cache across `goto` or a page-changing click.
78
+ */
79
+ readonly ref: string
80
+ readonly tag: string
81
+ readonly text?: string
82
+ readonly attributes: Readonly<Record<string, string>>
83
+ readonly box?: BoundingBox
84
+ }
85
+
86
+ /** Accessibility-tree node returned by {@link BrowserSession.snapshot}. */
87
+ export type AxNode = {
88
+ readonly role: string
89
+ readonly name?: string
90
+ readonly value?: string
91
+ /**
92
+ * Reference usable as a selector for a follow-up action. Valid until the
93
+ * next navigation; do not cache across `goto` or a page-changing click.
94
+ */
95
+ readonly ref?: string
96
+ readonly children: ReadonlyArray<AxNode>
97
+ }
98
+
99
+ // ---------------------------------------------------------------------------
100
+ // Interaction shapes
101
+ // ---------------------------------------------------------------------------
102
+
103
+ export type ScrollDirection = "up" | "down" | "left" | "right"
104
+
105
+ export type ScrollOptions = {
106
+ readonly direction: ScrollDirection
107
+ /** Distance in CSS pixels. Provider default applies when omitted. */
108
+ readonly pixels?: number
109
+ }
110
+
111
+ export type ScreenshotOptions = {
112
+ /** Clip to the first element matching this selector. */
113
+ readonly selector?: string
114
+ /** Capture the full scrollable page rather than the viewport. */
115
+ readonly fullPage?: boolean
116
+ }
117
+
118
+ export type Cookie = {
119
+ readonly name: string
120
+ readonly value: string
121
+ readonly domain?: string
122
+ readonly path?: string
123
+ readonly expires?: number
124
+ readonly httpOnly?: boolean
125
+ readonly secure?: boolean
126
+ readonly sameSite?: "Strict" | "Lax" | "None"
127
+ }
128
+
129
+ /** Read / write the session's cookie jar. Needed for authenticated flows. */
130
+ export type CookieApi = {
131
+ readonly get: Effect.Effect<ReadonlyArray<Cookie>, BrowserError.BrowserError>
132
+ readonly set: (cookies: ReadonlyArray<Cookie>) => Effect.Effect<void, BrowserError.BrowserError>
133
+ }
134
+
135
+ // ---------------------------------------------------------------------------
136
+ // Live session handle
137
+ // ---------------------------------------------------------------------------
138
+
139
+ /**
140
+ * Live session handle. Actions take a CSS selector string (so `#id` is
141
+ * just `#id`). Methods are plain `Effect` values; disposal is the scope
142
+ * finalizer, not a method here (see {@link BrowserService}). Anything not
143
+ * covered by a verb is reachable via `evaluate`. Per-operation time budgets
144
+ * are the provider's default; wrap any call in `Effect.timeout` for a
145
+ * tighter bound.
146
+ */
147
+ export type BrowserSession = {
148
+ readonly id: BrowserSessionId
149
+
150
+ // Navigation and waiting
151
+ readonly goto: (url: string) => Effect.Effect<void, BrowserError.BrowserError>
152
+ readonly waitFor: (selector: string) => Effect.Effect<void, BrowserError.BrowserError>
153
+
154
+ // Interaction
155
+ readonly click: (selector: string) => Effect.Effect<void, BrowserError.BrowserError>
156
+ readonly dblclick: (selector: string) => Effect.Effect<void, BrowserError.BrowserError>
157
+ readonly fill: (selector: string, text: string) => Effect.Effect<void, BrowserError.BrowserError>
158
+ readonly type: (selector: string, text: string) => Effect.Effect<void, BrowserError.BrowserError>
159
+ readonly press: (key: string) => Effect.Effect<void, BrowserError.BrowserError>
160
+ readonly hover: (selector: string) => Effect.Effect<void, BrowserError.BrowserError>
161
+ readonly focus: (selector: string) => Effect.Effect<void, BrowserError.BrowserError>
162
+ readonly select: (
163
+ selector: string,
164
+ value: string,
165
+ ) => Effect.Effect<void, BrowserError.BrowserError>
166
+ readonly check: (selector: string) => Effect.Effect<void, BrowserError.BrowserError>
167
+ readonly uncheck: (selector: string) => Effect.Effect<void, BrowserError.BrowserError>
168
+ readonly scroll: (options: ScrollOptions) => Effect.Effect<void, BrowserError.BrowserError>
169
+ readonly scrollIntoView: (selector: string) => Effect.Effect<void, BrowserError.BrowserError>
170
+
171
+ // Observation
172
+ readonly content: (format?: PageFormat) => Effect.Effect<string, BrowserError.BrowserError>
173
+ readonly screenshot: (
174
+ options?: ScreenshotOptions,
175
+ ) => Effect.Effect<Uint8Array, BrowserError.BrowserError>
176
+ readonly snapshot: Effect.Effect<AxNode, BrowserError.BrowserError>
177
+ readonly query: (
178
+ selector: string,
179
+ ) => Effect.Effect<ReadonlyArray<ElementInfo>, BrowserError.BrowserError>
180
+
181
+ // State and escape hatch
182
+ readonly cookies: CookieApi
183
+ readonly evaluate: (script: string) => Effect.Effect<unknown, BrowserError.BrowserError>
184
+ }
185
+
186
+ // ---------------------------------------------------------------------------
187
+ // Service definition
188
+ // ---------------------------------------------------------------------------
189
+
190
+ /**
191
+ * Cross-provider browser service.
192
+ *
193
+ * Lifetime: `create` and `attach` return a handle in `Scope.Scope`. The
194
+ * scope finalizer disposes the session (close the transport, destroy or
195
+ * detach the remote session, kill the local engine). Bind with
196
+ * `Effect.scoped` for a single call, or hold a wider scope to keep a
197
+ * session warm across many calls. This is why there is no `dispose()` on
198
+ * {@link BrowserSession}; the scope is the lifecycle handle.
199
+ */
200
+ export type BrowserService = {
201
+ /**
202
+ * Provision a new session, bound to the caller's scope. Disposed on
203
+ * scope close.
204
+ */
205
+ readonly create: (
206
+ request: CommonSessionRequest,
207
+ ) => Effect.Effect<BrowserSession, BrowserError.BrowserError, Scope.Scope>
208
+
209
+ /**
210
+ * Re-acquire an existing session by id. Scope-bound, but the finalizer
211
+ * detaches rather than destroying, for sessions kept warm beyond a
212
+ * single run.
213
+ */
214
+ readonly attach: (
215
+ id: BrowserSessionId,
216
+ ) => Effect.Effect<BrowserSession, BrowserError.BrowserError, Scope.Scope>
217
+
218
+ /** Enumerate sessions visible to the configured account / project. */
219
+ readonly list: Effect.Effect<ReadonlyArray<BrowserSessionRef>, BrowserError.BrowserError>
220
+
221
+ /**
222
+ * Destroy a session from outside its owning scope. Most callers should
223
+ * let the scope finalizer handle this.
224
+ */
225
+ readonly destroy: (id: BrowserSessionId) => Effect.Effect<void, BrowserError.BrowserError>
226
+ }
227
+
228
+ export class Browser extends Context.Service<Browser, BrowserService>()(
229
+ "@betalyra/effect-uai/Browser",
230
+ ) {}
231
+
232
+ // ---------------------------------------------------------------------------
233
+ // Free helpers
234
+ // ---------------------------------------------------------------------------
235
+
236
+ /**
237
+ * Provision a session bound to the caller's scope. Drop the `Scope.Scope`
238
+ * requirement with `Effect.scoped`.
239
+ */
240
+ export const create = (
241
+ request: CommonSessionRequest,
242
+ ): Effect.Effect<BrowserSession, BrowserError.BrowserError, Browser | Scope.Scope> =>
243
+ Effect.flatMap(Browser.asEffect(), (s) => s.create(request))
244
+
245
+ /**
246
+ * Re-acquire an existing session by id. Same scope semantics as `create`,
247
+ * but the finalizer detaches rather than destroying.
248
+ */
249
+ export const attach = (
250
+ id: BrowserSessionId,
251
+ ): Effect.Effect<BrowserSession, BrowserError.BrowserError, Browser | Scope.Scope> =>
252
+ Effect.flatMap(Browser.asEffect(), (s) => s.attach(id))
253
+
254
+ /** Enumerate sessions for the configured account / project. */
255
+ export const list: Effect.Effect<
256
+ ReadonlyArray<BrowserSessionRef>,
257
+ BrowserError.BrowserError,
258
+ Browser
259
+ > = Effect.flatMap(Browser.asEffect(), (s) => s.list)
260
+
261
+ /**
262
+ * Destroy a session from outside its owning scope. Most callers should let
263
+ * the scope finalizer handle this automatically.
264
+ */
265
+ export const destroy = (
266
+ id: BrowserSessionId,
267
+ ): Effect.Effect<void, BrowserError.BrowserError, Browser> =>
268
+ Effect.flatMap(Browser.asEffect(), (s) => s.destroy(id))