webfox 4.11.0 → 4.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.
Files changed (95) hide show
  1. package/README.md +5 -2
  2. package/dist/adapter-2HWVV4H7.js +144 -0
  3. package/dist/{adapter-QQZFHUOP.js → adapter-2V73476L.js} +69 -131
  4. package/dist/{adapter-SZMVKAMC.js → adapter-3V4OZDZZ.js} +10 -14
  5. package/dist/adapter-64462GL3.js +247 -0
  6. package/dist/{adapter-WXEVTCM3.js → adapter-BCZ4UE7S.js} +38 -81
  7. package/dist/{adapter-YVZ4YBK5.js → adapter-BHDA6JOK.js} +40 -56
  8. package/dist/adapter-EQ3LZTZ4.js +152 -0
  9. package/dist/adapter-EQSFB26L.js +58 -0
  10. package/dist/{adapter-ODDFBGJG.js → adapter-EXDS6465.js} +36 -57
  11. package/dist/adapter-IWGMWJ5A.js +121 -0
  12. package/dist/{adapter-XSQX3GAI.js → adapter-JQNYUBYZ.js} +33 -23
  13. package/dist/{adapter-VXT4C6RZ.js → adapter-OTMS6OEU.js} +81 -102
  14. package/dist/{adapter-MZ7USB6Q.js → adapter-PW4UL2DR.js} +12 -32
  15. package/dist/adapter-RBSOVQCV.js +84 -0
  16. package/dist/{adapter-GFXYSHKP.js → adapter-RJ334ZU5.js} +28 -76
  17. package/dist/{adapter-XU2APKPC.js → adapter-T6UEERC7.js} +19 -24
  18. package/dist/{adapter-BZO5UEI6.js → adapter-VVWNAGWI.js} +118 -142
  19. package/dist/{adapter-GJOUFE2U.js → adapter-XMEXVEMQ.js} +7 -10
  20. package/dist/adapter-ZLS55DG2.js +341 -0
  21. package/dist/{chunk-NENL6L6N.js → chunk-46OIVYHW.js} +1 -0
  22. package/dist/{chunk-WCTOYZVB.js → chunk-6UC3ZBNK.js} +15 -5
  23. package/dist/{chunk-YILOS4E7.js → chunk-7NTO6AQX.js} +110 -72
  24. package/dist/{chunk-PVNWACMT.js → chunk-EBKQHHCO.js} +199 -20
  25. package/dist/chunk-HZVTFUBC.js +139 -0
  26. package/dist/{chunk-LDVDVA4Z.js → chunk-I4HLGP7F.js} +3 -7
  27. package/dist/chunk-U4I3X7IN.js +267 -0
  28. package/dist/chunk-V4SQCDI3.js +336 -0
  29. package/dist/chunk-VMIDLDYP.js +111 -0
  30. package/dist/cli.js +9 -9
  31. package/dist/config.schema.json +222 -1
  32. package/dist/document-schema.d.ts +4 -4
  33. package/dist/domain.d.ts +1 -1
  34. package/dist/durable.js +73 -65
  35. package/dist/index.js +8 -7
  36. package/dist/pi-render.d.ts +3 -2
  37. package/dist/pi-shared.d.ts +39 -0
  38. package/dist/pi.js +87 -191
  39. package/dist/providers/brave/adapter.d.ts +4 -5
  40. package/dist/providers/cloudflare/adapter.d.ts +3 -2
  41. package/dist/providers/contract.d.ts +20 -19
  42. package/dist/providers/custom/adapter.d.ts +2 -2
  43. package/dist/providers/exa/adapter.d.ts +6 -6
  44. package/dist/providers/firecrawl/adapter.d.ts +5 -5
  45. package/dist/providers/gemini/adapter.d.ts +5 -10
  46. package/dist/providers/keenable/adapter.d.ts +2 -3
  47. package/dist/providers/linkup/adapter.d.ts +5 -5
  48. package/dist/providers/ollama/adapter.d.ts +4 -4
  49. package/dist/providers/openai/adapter.d.ts +4 -4
  50. package/dist/providers/openai/types.d.ts +2 -4
  51. package/dist/providers/parallel/adapter.d.ts +4 -4
  52. package/dist/providers/perplexity/adapter.d.ts +4 -5
  53. package/dist/providers/registry.d.ts +1 -0
  54. package/dist/providers/serpbase/types.d.ts +2 -4
  55. package/dist/providers/serper/adapter.d.ts +2 -2
  56. package/dist/providers/serper/types.d.ts +2 -4
  57. package/dist/providers/shared.d.ts +50 -0
  58. package/dist/providers/sofya/adapter.d.ts +6 -6
  59. package/dist/providers/tapline/adapter.d.ts +4 -0
  60. package/dist/providers/tapline/definition.d.ts +1 -0
  61. package/dist/providers/tavily/adapter.d.ts +4 -4
  62. package/dist/providers/valyu/adapter.d.ts +6 -6
  63. package/dist/providers/youcom/adapter.d.ts +2 -3
  64. package/dist/runtime/duration.d.ts +2 -0
  65. package/dist/runtime/execute.d.ts +3 -1
  66. package/dist/runtime/lifecycle.d.ts +0 -1
  67. package/dist/runtime/outward.d.ts +6 -1
  68. package/dist/runtime/polling.d.ts +2 -3
  69. package/docs/provider.md +29 -0
  70. package/package.json +14 -20
  71. package/dist/adapter-44ZBIK47.js +0 -121
  72. package/dist/adapter-57MELLYI.js +0 -160
  73. package/dist/adapter-D4EXZEDL.js +0 -213
  74. package/dist/adapter-DJCTEEOA.js +0 -159
  75. package/dist/adapter-DLNMW34W.js +0 -214
  76. package/dist/adapter-RR55EZAW.js +0 -73
  77. package/dist/chunk-FSTCLBSF.js +0 -76
  78. package/dist/chunk-I2UIACY3.js +0 -12
  79. package/dist/chunk-KMUCUJVN.js +0 -251
  80. package/dist/chunk-TYJ6RHKB.js +0 -31
  81. package/dist/chunk-VVOQKYOP.js +0 -112
  82. package/dist/contents.d.ts +0 -24
  83. package/dist/providers/brave/types.d.ts +0 -4
  84. package/dist/providers/exa/types.d.ts +0 -4
  85. package/dist/providers/firecrawl/types.d.ts +0 -4
  86. package/dist/providers/gemini/types.d.ts +0 -3
  87. package/dist/providers/keenable/types.d.ts +0 -4
  88. package/dist/providers/linkup/types.d.ts +0 -4
  89. package/dist/providers/ollama/types.d.ts +0 -4
  90. package/dist/providers/parallel/types.d.ts +0 -4
  91. package/dist/providers/perplexity/types.d.ts +0 -4
  92. package/dist/providers/sofya/types.d.ts +0 -4
  93. package/dist/providers/tavily/types.d.ts +0 -4
  94. package/dist/providers/valyu/types.d.ts +0 -4
  95. package/dist/providers/youcom/types.d.ts +0 -4
package/dist/cli.js CHANGED
@@ -1,7 +1,4 @@
1
1
  #!/usr/bin/env node
2
- import {
3
- formatDuration
4
- } from "./chunk-I2UIACY3.js";
5
2
  import {
6
3
  renderTextDocument
7
4
  } from "./chunk-6RQGO727.js";
@@ -11,19 +8,22 @@ import {
11
8
  redactConfig,
12
9
  resolveConfigPath,
13
10
  setCapabilityDefault
14
- } from "./chunk-YILOS4E7.js";
15
- import "./chunk-WCTOYZVB.js";
11
+ } from "./chunk-7NTO6AQX.js";
16
12
  import {
17
- PACKAGE_VERSION
18
- } from "./chunk-KMUCUJVN.js";
13
+ formatDuration
14
+ } from "./chunk-6UC3ZBNK.js";
15
+ import "./chunk-VMIDLDYP.js";
19
16
  import {
20
17
  validateConfiguredOptions
21
- } from "./chunk-PVNWACMT.js";
18
+ } from "./chunk-EBKQHHCO.js";
19
+ import {
20
+ PACKAGE_VERSION
21
+ } from "./chunk-HZVTFUBC.js";
22
22
  import "./chunk-ZVTVERW5.js";
23
23
  import {
24
24
  CAPABILITIES,
25
25
  PROVIDER_IDS
26
- } from "./chunk-NENL6L6N.js";
26
+ } from "./chunk-46OIVYHW.js";
27
27
  import {
28
28
  WebfoxError
29
29
  } from "./chunk-U4BLULLV.js";
@@ -32,6 +32,7 @@
32
32
  "serpbase",
33
33
  "serper",
34
34
  "sofya",
35
+ "tapline",
35
36
  "tavily",
36
37
  "valyu",
37
38
  "youcom"
@@ -3973,6 +3974,160 @@
3973
3974
  }
3974
3975
  }
3975
3976
  },
3977
+ "tapline": {
3978
+ "type": "object",
3979
+ "additionalProperties": false,
3980
+ "properties": {
3981
+ "credentials": {
3982
+ "type": "object",
3983
+ "additionalProperties": false,
3984
+ "properties": {
3985
+ "api": {
3986
+ "oneOf": [
3987
+ {
3988
+ "type": "object",
3989
+ "additionalProperties": false,
3990
+ "properties": {
3991
+ "env": {
3992
+ "type": "string",
3993
+ "minLength": 1
3994
+ }
3995
+ },
3996
+ "required": ["env"]
3997
+ },
3998
+ {
3999
+ "type": "object",
4000
+ "additionalProperties": false,
4001
+ "properties": {
4002
+ "value": {
4003
+ "type": "string",
4004
+ "minLength": 1
4005
+ }
4006
+ },
4007
+ "required": ["value"]
4008
+ },
4009
+ {
4010
+ "type": "object",
4011
+ "additionalProperties": false,
4012
+ "properties": {
4013
+ "command": {
4014
+ "type": "array",
4015
+ "minItems": 1,
4016
+ "items": {
4017
+ "type": "string",
4018
+ "minLength": 1
4019
+ }
4020
+ }
4021
+ },
4022
+ "required": ["command"]
4023
+ }
4024
+ ]
4025
+ }
4026
+ }
4027
+ },
4028
+ "baseUrl": {
4029
+ "type": "string",
4030
+ "minLength": 1
4031
+ },
4032
+ "options": {
4033
+ "type": "object",
4034
+ "additionalProperties": false,
4035
+ "properties": {
4036
+ "search": {
4037
+ "type": "object",
4038
+ "properties": {
4039
+ "country": {
4040
+ "type": "string",
4041
+ "enum": [
4042
+ "ar",
4043
+ "at",
4044
+ "au",
4045
+ "be",
4046
+ "br",
4047
+ "ca",
4048
+ "ch",
4049
+ "cl",
4050
+ "cn",
4051
+ "de",
4052
+ "dk",
4053
+ "es",
4054
+ "fi",
4055
+ "fr",
4056
+ "gb",
4057
+ "gr",
4058
+ "hk",
4059
+ "id",
4060
+ "in",
4061
+ "it",
4062
+ "jp",
4063
+ "kr",
4064
+ "mx",
4065
+ "my",
4066
+ "nl",
4067
+ "no",
4068
+ "nz",
4069
+ "ph",
4070
+ "pl",
4071
+ "pt",
4072
+ "ru",
4073
+ "sa",
4074
+ "se",
4075
+ "sg",
4076
+ "tr",
4077
+ "tw",
4078
+ "us",
4079
+ "za"
4080
+ ],
4081
+ "description": "Lowercase country code to search from, e.g. 'us' (default) or 'de'."
4082
+ },
4083
+ "search_language": {
4084
+ "type": "string",
4085
+ "enum": ["en", "de", "es", "fr", "it", "ja", "pt", "zh"],
4086
+ "description": "Language to rank results toward."
4087
+ },
4088
+ "safe_search": {
4089
+ "type": "string",
4090
+ "enum": ["strict", "moderate", "off"],
4091
+ "description": "Adult-content filter."
4092
+ },
4093
+ "freshness": {
4094
+ "type": "string",
4095
+ "enum": [
4096
+ "any",
4097
+ "past_day",
4098
+ "past_week",
4099
+ "past_month",
4100
+ "past_year"
4101
+ ],
4102
+ "description": "Only pages from the past day, week, month, or year."
4103
+ },
4104
+ "date_from": {
4105
+ "type": "string",
4106
+ "pattern": "^\\d{4}-\\d{2}-\\d{2}$",
4107
+ "description": "Start of a published-date range as YYYY-MM-DD; requires date_to."
4108
+ },
4109
+ "date_to": {
4110
+ "type": "string",
4111
+ "pattern": "^\\d{4}-\\d{2}-\\d{2}$",
4112
+ "description": "End of a published-date range as YYYY-MM-DD; requires date_from."
4113
+ },
4114
+ "goggle_url": {
4115
+ "type": "string",
4116
+ "pattern": "^https://(raw\\.githubusercontent\\.com/\\S{1,480}\\.goggles?|gist\\.githubusercontent\\.com/\\S{1,480}|gitlab\\.com/\\S{1,480}\\.goggles?)$",
4117
+ "description": "Brave Goggle URL that re-ranks results: a .goggle file on raw.githubusercontent.com or gitlab.com, or a gist.githubusercontent.com URL. Goggles that Brave has not indexed are ignored."
4118
+ },
4119
+ "spellcheck": {
4120
+ "type": "boolean",
4121
+ "description": "Correct misspelt queries (default true)."
4122
+ }
4123
+ },
4124
+ "description": "Tapline search options.",
4125
+ "additionalProperties": false
4126
+ }
4127
+ }
4128
+ }
4129
+ }
4130
+ },
3976
4131
  "tavily": {
3977
4132
  "type": "object",
3978
4133
  "additionalProperties": false,
@@ -4142,10 +4297,18 @@
4142
4297
  "type": "boolean",
4143
4298
  "description": "Include related images."
4144
4299
  },
4300
+ "includeImageDescriptions": {
4301
+ "type": "boolean",
4302
+ "description": "Request descriptions for returned images."
4303
+ },
4145
4304
  "includeFavicon": {
4146
4305
  "type": "boolean",
4147
4306
  "description": "Include favicon URLs."
4148
4307
  },
4308
+ "includeUsage": {
4309
+ "type": "boolean",
4310
+ "description": "Request credit usage details."
4311
+ },
4149
4312
  "includeDomains": {
4150
4313
  "type": "array",
4151
4314
  "items": {
@@ -4153,6 +4316,11 @@
4153
4316
  },
4154
4317
  "description": "Restrict results to these domains."
4155
4318
  },
4319
+ "includeDomainsMode": {
4320
+ "type": "string",
4321
+ "enum": ["restrict", "prefer"],
4322
+ "description": "How to apply includeDomains."
4323
+ },
4156
4324
  "excludeDomains": {
4157
4325
  "type": "array",
4158
4326
  "items": {
@@ -4160,6 +4328,40 @@
4160
4328
  },
4161
4329
  "description": "Exclude these domains from results."
4162
4330
  },
4331
+ "maxAgeHours": {
4332
+ "type": "number",
4333
+ "minimum": 0,
4334
+ "description": "Maximum acceptable cache age in hours."
4335
+ },
4336
+ "fetchTimeout": {
4337
+ "type": "number",
4338
+ "exclusiveMinimum": 0,
4339
+ "description": "Live-fetch time budget in seconds."
4340
+ },
4341
+ "cacheFallback": {
4342
+ "type": "boolean",
4343
+ "description": "Allow cached content when live fetching fails."
4344
+ },
4345
+ "language": {
4346
+ "type": "string",
4347
+ "description": "Preferred content language."
4348
+ },
4349
+ "filterByLanguage": {
4350
+ "type": "boolean",
4351
+ "description": "Restrict results to the requested language."
4352
+ },
4353
+ "safeSearch": {
4354
+ "type": "boolean",
4355
+ "description": "Filter explicit content from results."
4356
+ },
4357
+ "includePublishedDate": {
4358
+ "type": "boolean",
4359
+ "description": "Request detected publication dates."
4360
+ },
4361
+ "filterByPublishedDate": {
4362
+ "type": "boolean",
4363
+ "description": "Exclude undated results and results outside the requested date window; also enables publication dates."
4364
+ },
4163
4365
  "days": {
4164
4366
  "type": "integer",
4165
4367
  "minimum": 1,
@@ -4213,6 +4415,10 @@
4213
4415
  "includeFavicon": {
4214
4416
  "type": "boolean",
4215
4417
  "description": "Include favicon URLs."
4418
+ },
4419
+ "includeUsage": {
4420
+ "type": "boolean",
4421
+ "description": "Request credit usage details."
4216
4422
  }
4217
4423
  },
4218
4424
  "description": "Tavily extract options.",
@@ -4558,7 +4764,7 @@
4558
4764
  "description": "Use Valyu fast mode when lower latency is preferred."
4559
4765
  }
4560
4766
  },
4561
- "description": "Valyu answer options.",
4767
+ "description": "Valyu answer options. Deprecated upstream (retires 2026-12-17); prefer Valyu research with mode='instant' or search.",
4562
4768
  "additionalProperties": false
4563
4769
  },
4564
4770
  "research": {
@@ -4566,6 +4772,10 @@
4566
4772
  "properties": {
4567
4773
  "mode": {
4568
4774
  "anyOf": [
4775
+ {
4776
+ "type": "string",
4777
+ "const": "instant"
4778
+ },
4569
4779
  {
4570
4780
  "type": "string",
4571
4781
  "const": "fast"
@@ -4606,6 +4816,10 @@
4606
4816
  {
4607
4817
  "type": "string",
4608
4818
  "const": "toon"
4819
+ },
4820
+ {
4821
+ "type": "string",
4822
+ "const": "structured_report"
4609
4823
  }
4610
4824
  ]
4611
4825
  },
@@ -4619,6 +4833,13 @@
4619
4833
  },
4620
4834
  "description": "Requested Valyu research output formats."
4621
4835
  },
4836
+ "skills": {
4837
+ "type": "array",
4838
+ "items": {
4839
+ "type": "string"
4840
+ },
4841
+ "description": "Skills to enable for this research task (for example 'forecasting')."
4842
+ },
4622
4843
  "search": {
4623
4844
  "type": "object",
4624
4845
  "properties": {
@@ -8,7 +8,7 @@ export declare const DOCUMENT_SCHEMAS: {
8
8
  readonly search: Type.TObject<{
9
9
  schemaVersion: Type.TLiteral<1>;
10
10
  capability: Type.TLiteral<"search">;
11
- provider: Type.TEnum<["brave", "cloudflare", "custom", "exa", "firecrawl", "gemini", "keenable", "linkup", "ollama", "openai", "parallel", "perplexity", "serpbase", "serper", "sofya", "tavily", "valyu", "youcom"]>;
11
+ provider: Type.TEnum<["brave", "cloudflare", "custom", "exa", "firecrawl", "gemini", "keenable", "linkup", "ollama", "openai", "parallel", "perplexity", "serpbase", "serper", "sofya", "tapline", "tavily", "valyu", "youcom"]>;
12
12
  status: Type.TEnum<["ok", "partial"]>;
13
13
  results: Type.TArray<Type.TUnion<[Type.TObject<{
14
14
  input: Type.TString;
@@ -35,7 +35,7 @@ export declare const DOCUMENT_SCHEMAS: {
35
35
  readonly contents: Type.TObject<{
36
36
  schemaVersion: Type.TLiteral<1>;
37
37
  capability: Type.TLiteral<"contents">;
38
- provider: Type.TEnum<["brave", "cloudflare", "custom", "exa", "firecrawl", "gemini", "keenable", "linkup", "ollama", "openai", "parallel", "perplexity", "serpbase", "serper", "sofya", "tavily", "valyu", "youcom"]>;
38
+ provider: Type.TEnum<["brave", "cloudflare", "custom", "exa", "firecrawl", "gemini", "keenable", "linkup", "ollama", "openai", "parallel", "perplexity", "serpbase", "serper", "sofya", "tapline", "tavily", "valyu", "youcom"]>;
39
39
  status: Type.TEnum<["ok", "partial"]>;
40
40
  results: Type.TArray<Type.TUnion<[Type.TObject<{
41
41
  input: Type.TString;
@@ -59,7 +59,7 @@ export declare const DOCUMENT_SCHEMAS: {
59
59
  readonly answer: Type.TObject<{
60
60
  schemaVersion: Type.TLiteral<1>;
61
61
  capability: Type.TLiteral<"answer">;
62
- provider: Type.TEnum<["brave", "cloudflare", "custom", "exa", "firecrawl", "gemini", "keenable", "linkup", "ollama", "openai", "parallel", "perplexity", "serpbase", "serper", "sofya", "tavily", "valyu", "youcom"]>;
62
+ provider: Type.TEnum<["brave", "cloudflare", "custom", "exa", "firecrawl", "gemini", "keenable", "linkup", "ollama", "openai", "parallel", "perplexity", "serpbase", "serper", "sofya", "tapline", "tavily", "valyu", "youcom"]>;
63
63
  status: Type.TEnum<["ok", "partial"]>;
64
64
  results: Type.TArray<Type.TUnion<[Type.TObject<{
65
65
  input: Type.TString;
@@ -88,7 +88,7 @@ export declare const DOCUMENT_SCHEMAS: {
88
88
  readonly research: Type.TObject<{
89
89
  schemaVersion: Type.TLiteral<1>;
90
90
  capability: Type.TLiteral<"research">;
91
- provider: Type.TEnum<["brave", "cloudflare", "custom", "exa", "firecrawl", "gemini", "keenable", "linkup", "ollama", "openai", "parallel", "perplexity", "serpbase", "serper", "sofya", "tavily", "valyu", "youcom"]>;
91
+ provider: Type.TEnum<["brave", "cloudflare", "custom", "exa", "firecrawl", "gemini", "keenable", "linkup", "ollama", "openai", "parallel", "perplexity", "serpbase", "serper", "sofya", "tapline", "tavily", "valyu", "youcom"]>;
92
92
  status: Type.TEnum<["ok", "partial"]>;
93
93
  results: Type.TArray<Type.TUnion<[Type.TObject<{
94
94
  input: Type.TString;
package/dist/domain.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  export declare const CAPABILITIES: readonly ["search", "contents", "answer", "research"];
2
2
  export type Capability = (typeof CAPABILITIES)[number];
3
- export declare const PROVIDER_IDS: readonly ["brave", "cloudflare", "custom", "exa", "firecrawl", "gemini", "keenable", "linkup", "ollama", "openai", "parallel", "perplexity", "serpbase", "serper", "sofya", "tavily", "valyu", "youcom"];
3
+ export declare const PROVIDER_IDS: readonly ["brave", "cloudflare", "custom", "exa", "firecrawl", "gemini", "keenable", "linkup", "ollama", "openai", "parallel", "perplexity", "serpbase", "serper", "sofya", "tapline", "tavily", "valyu", "youcom"];
4
4
  export type ProviderId = (typeof PROVIDER_IDS)[number];
5
5
  export declare const WEBFOX_ERROR_CODES: readonly ["INVALID_CONFIG", "INVALID_INPUT", "PROVIDER_UNAVAILABLE", "PROVIDER_FAILURE", "PARTIAL_BATCH", "TIMEOUT", "CANCELLED"];
6
6
  export type WebfoxErrorCode = (typeof WEBFOX_ERROR_CODES)[number];
package/dist/durable.js CHANGED
@@ -1,46 +1,35 @@
1
1
  import {
2
+ DOCUMENT_SCHEMAS,
3
+ WEB_NAMESPACE,
4
+ createClientCache,
2
5
  descriptions,
6
+ executeCapability,
7
+ formatToolOutput,
3
8
  prepareToolArguments,
4
9
  webToolParameters
5
- } from "./chunk-VVOQKYOP.js";
6
- import {
7
- renderTextDocument
8
- } from "./chunk-6RQGO727.js";
9
- import {
10
- createWebfox
11
- } from "./chunk-YILOS4E7.js";
12
- import "./chunk-WCTOYZVB.js";
13
- import "./chunk-KMUCUJVN.js";
14
- import "./chunk-PVNWACMT.js";
10
+ } from "./chunk-V4SQCDI3.js";
11
+ import "./chunk-6RQGO727.js";
12
+ import "./chunk-7NTO6AQX.js";
13
+ import "./chunk-6UC3ZBNK.js";
14
+ import "./chunk-VMIDLDYP.js";
15
+ import "./chunk-EBKQHHCO.js";
16
+ import "./chunk-HZVTFUBC.js";
15
17
  import "./chunk-ZVTVERW5.js";
16
18
  import {
17
19
  CAPABILITIES
18
- } from "./chunk-NENL6L6N.js";
20
+ } from "./chunk-46OIVYHW.js";
19
21
  import "./chunk-U4BLULLV.js";
20
22
 
21
23
  // src/durable.ts
22
24
  import { mkdtemp, writeFile } from "node:fs/promises";
23
25
  import { tmpdir } from "node:os";
24
26
  import { join } from "node:path";
25
- import {
26
- truncateHead,
27
- withFileMutationQueue
28
- } from "@earendil-works/pi-coding-agent";
29
27
  import {
30
28
  defineExtension,
31
29
  defineTool
32
30
  } from "@earendil-works/pi-durable";
33
31
  function createWebfoxExtension(options = {}) {
34
- const clients = /* @__PURE__ */ new Map();
35
- const clientFor = (cwd) => {
36
- if (options.client) return options.client;
37
- let client = clients.get(cwd);
38
- if (!client) {
39
- client = createWebfox({ ...options, cwd });
40
- clients.set(cwd, client);
41
- }
42
- return client;
43
- };
32
+ const clientFor = createClientCache(options);
44
33
  const initialCwd = options.cwd ?? process.cwd();
45
34
  const initial = clientFor(initialCwd);
46
35
  const inspections = CAPABILITIES.map(
@@ -48,6 +37,7 @@ function createWebfoxExtension(options = {}) {
48
37
  ).filter((inspection) => inspection.provider);
49
38
  return defineExtension({
50
39
  name: "webfox",
40
+ namespace: { ...WEB_NAMESPACE },
51
41
  tools: inspections.map((inspection) => {
52
42
  const capability = inspection.capability;
53
43
  const parameters = webToolParameters(inspection);
@@ -56,9 +46,10 @@ function createWebfoxExtension(options = {}) {
56
46
  description: [
57
47
  descriptions[capability],
58
48
  ...inspection.promptGuidelines ?? [],
59
- "Output is limited to 2000 lines or 50 KiB; complete results are saved to a private file when truncated."
49
+ "Output is limited to 2000 lines or 50 KiB; complete results are saved to a private file when truncated. Codemode scripts receive complete structured results."
60
50
  ].join("\n"),
61
51
  parameters,
52
+ structuredOutputSchema: DOCUMENT_SCHEMAS[capability],
62
53
  // Web requests may incur charges. A crash reports interruption rather than silently charging again.
63
54
  replay: "unsafe",
64
55
  prepareArguments: (args) => prepareToolArguments(parameters, args),
@@ -66,47 +57,64 @@ function createWebfoxExtension(options = {}) {
66
57
  const client = clientFor(
67
58
  api.env?.cwd ?? (await api.agent(context)).cwd ?? initialCwd
68
59
  );
69
- const request = {
70
- provider: inspection.provider,
71
- signal: context.abortSignal,
72
- options: args.options,
73
- onProgress: (event) => api.output(`${event.message}
60
+ const result = await executeCapability(
61
+ client,
62
+ capability,
63
+ inspection.provider,
64
+ args,
65
+ context.abortSignal,
66
+ (event) => api.output(`${event.message}
74
67
  `)
75
- };
76
- const result = capability === "search" ? await client.search({
77
- ...request,
78
- queries: args.queries,
79
- maxResults: args.maxResults
80
- }) : capability === "contents" ? await client.contents({
81
- ...request,
82
- urls: args.urls
83
- }) : capability === "answer" ? await client.answer({
84
- ...request,
85
- queries: args.queries
86
- }) : await client.research({
87
- ...request,
88
- input: args.input
89
- });
90
- const truncated = truncateHead(renderTextDocument(result));
91
- let body = truncated.content;
92
- let fullOutputPath;
93
- if (truncated.truncated) {
94
- fullOutputPath = join(
95
- await mkdtemp(join(tmpdir(), "web-")),
96
- "result.json"
97
- );
98
- await withFileMutationQueue(
99
- fullOutputPath,
100
- () => writeFile(fullOutputPath, JSON.stringify(result), {
101
- mode: 384
102
- })
103
- );
104
- body += `
105
-
106
- Full results: ${fullOutputPath}`;
107
- }
68
+ );
69
+ const { body, json, fullOutputPath } = await formatToolOutput(
70
+ result,
71
+ async (serialized) => {
72
+ if (api.env) {
73
+ const dir = await api.env.createTempDir("web-", context);
74
+ if (!dir.ok) {
75
+ if (context.abortSignal?.aborted || dir.error.code === "aborted")
76
+ throw dir.error;
77
+ return { error: dir.error.message };
78
+ }
79
+ const path = await api.env.joinPath(
80
+ [dir.value, "result.json"],
81
+ context
82
+ );
83
+ if (!path.ok) {
84
+ if (context.abortSignal?.aborted || path.error.code === "aborted")
85
+ throw path.error;
86
+ return { error: path.error.message };
87
+ }
88
+ const written = await api.env.writeFile(
89
+ path.value,
90
+ serialized,
91
+ context
92
+ );
93
+ if (!written.ok) {
94
+ if (context.abortSignal?.aborted || written.error.code === "aborted")
95
+ throw written.error;
96
+ return { error: written.error.message };
97
+ }
98
+ return { path: path.value };
99
+ }
100
+ try {
101
+ const path = join(
102
+ await mkdtemp(join(tmpdir(), "web-")),
103
+ "result.json"
104
+ );
105
+ await writeFile(path, serialized, { mode: 384 });
106
+ return { path };
107
+ } catch (error) {
108
+ if (context.abortSignal?.aborted) throw error;
109
+ return {
110
+ error: error instanceof Error ? error.message : String(error)
111
+ };
112
+ }
113
+ }
114
+ );
108
115
  return {
109
- content: [{ type: "text", text: body }],
116
+ output: [{ type: "text", text: body }],
117
+ structuredOutput: JSON.parse(json),
110
118
  isError: result.status === "partial",
111
119
  details: {
112
120
  status: result.status,
package/dist/index.js CHANGED
@@ -6,20 +6,21 @@ import {
6
6
  resolveConfigPath,
7
7
  setCapabilityDefault,
8
8
  validateConfig
9
- } from "./chunk-YILOS4E7.js";
10
- import "./chunk-WCTOYZVB.js";
11
- import {
12
- CONFIG_SCHEMA_URL
13
- } from "./chunk-KMUCUJVN.js";
9
+ } from "./chunk-7NTO6AQX.js";
10
+ import "./chunk-6UC3ZBNK.js";
11
+ import "./chunk-VMIDLDYP.js";
14
12
  import {
15
13
  validateConfiguredOptions
16
- } from "./chunk-PVNWACMT.js";
14
+ } from "./chunk-EBKQHHCO.js";
15
+ import {
16
+ CONFIG_SCHEMA_URL
17
+ } from "./chunk-HZVTFUBC.js";
17
18
  import "./chunk-ZVTVERW5.js";
18
19
  import {
19
20
  CAPABILITIES,
20
21
  PROVIDER_IDS,
21
22
  WEBFOX_ERROR_CODES
22
- } from "./chunk-NENL6L6N.js";
23
+ } from "./chunk-46OIVYHW.js";
23
24
  import {
24
25
  WebfoxError
25
26
  } from "./chunk-U4BLULLV.js";
@@ -1,5 +1,5 @@
1
1
  import { type Theme } from "@earendil-works/pi-coding-agent";
2
- import { type Component } from "@earendil-works/pi-tui";
2
+ import { type Component, type Keybinding } from "@earendil-works/pi-tui";
3
3
  import type { Capability } from "./domain.js";
4
4
  declare const inputStates: {
5
5
  readonly queued: {
@@ -32,8 +32,9 @@ export declare class WebCall implements Component {
32
32
  private args;
33
33
  private theme;
34
34
  private expanded;
35
+ private keyText?;
35
36
  constructor(capability: Capability);
36
- update(args: unknown, theme: Theme, expanded: boolean): void;
37
+ update(args: unknown, theme: Theme, expanded: boolean, keyText?: (keybinding: Keybinding) => string): void;
37
38
  render(width: number): string[];
38
39
  invalidate(): void;
39
40
  }
@@ -0,0 +1,39 @@
1
+ import { type Capability, type CreateWebfoxOptions, type ProgressEvent, type ProviderId, type WebDocument, type WebfoxClient } from "./index.js";
2
+ export declare const WEB_NAMESPACE: {
3
+ readonly name: "web";
4
+ readonly description: "Search, extract pages, answer, and research the web.";
5
+ };
6
+ export declare const DEFAULT_TOOL_MAX_LINES = 2000;
7
+ export declare const DEFAULT_TOOL_MAX_BYTES: number;
8
+ export interface WebToolParams {
9
+ queries?: string[];
10
+ urls?: string[];
11
+ input?: string;
12
+ maxResults?: number;
13
+ options?: Record<string, unknown>;
14
+ }
15
+ export declare function createClientCache(options?: Omit<CreateWebfoxOptions, "cwd"> & {
16
+ client?: WebfoxClient;
17
+ }): (cwd: string) => WebfoxClient;
18
+ export declare function executeCapability(client: WebfoxClient, capability: Capability, provider: ProviderId, params: WebToolParams, signal: AbortSignal | undefined, onProgress: ((event: ProgressEvent) => void) | undefined): Promise<WebDocument>;
19
+ /**
20
+ * Head-truncate text to at most `maxLines` lines and `maxBytes` UTF-8 bytes
21
+ * without emitting partial lines (matching Pi's `truncateHead` contract).
22
+ */
23
+ export declare function truncateHeadOutput(content: string, { maxLines, maxBytes, }?: {
24
+ maxLines?: number;
25
+ maxBytes?: number;
26
+ }): {
27
+ content: string;
28
+ truncated: boolean;
29
+ };
30
+ export type SpillWriteResult = {
31
+ path: string;
32
+ } | {
33
+ error: string;
34
+ };
35
+ export declare function formatToolOutput(result: WebDocument, writeSpill: (json: string) => Promise<SpillWriteResult>): Promise<{
36
+ body: string;
37
+ json: string;
38
+ fullOutputPath?: string;
39
+ }>;