@stackfactor/agent-utils 1.2.16 → 1.2.19
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/README.md +69 -1
- package/dist/cjs/agentProto.d.ts +1 -1
- package/dist/cjs/agentProto.d.ts.map +1 -1
- package/dist/cjs/agentProto.js +6 -0
- package/dist/cjs/client.d.ts +7 -0
- package/dist/cjs/client.d.ts.map +1 -1
- package/dist/cjs/index.d.ts +1 -1
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/langChain.d.ts +67 -0
- package/dist/cjs/langChain.d.ts.map +1 -1
- package/dist/cjs/langChain.js +317 -34
- package/dist/cjs/serve.d.ts.map +1 -1
- package/dist/cjs/serve.js +104 -37
- package/dist/esm/agentProto.d.ts +1 -1
- package/dist/esm/agentProto.d.ts.map +1 -1
- package/dist/esm/agentProto.js +6 -0
- package/dist/esm/client.d.ts +7 -0
- package/dist/esm/client.d.ts.map +1 -1
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/langChain.d.ts +67 -0
- package/dist/esm/langChain.d.ts.map +1 -1
- package/dist/esm/langChain.js +317 -34
- package/dist/esm/serve.d.ts.map +1 -1
- package/dist/esm/serve.js +104 -37
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -40,7 +40,7 @@ When `expectsJsonResponse` is `true` (the default), JSON escape instructions are
|
|
|
40
40
|
| Parameter | Type | Default | Description |
|
|
41
41
|
| --------------------- | -------------------- | --------------- | -------------------------------------------------------------------------------------------------------- |
|
|
42
42
|
| `modelName` | `string` | — | Model identifier: `"gpt-4o"`, `"claude-3-5-sonnet"`, `"gemini-1.5-pro"`, `"deepseek-chat"`, `"kimi-k2-0905-preview"`, `"glm-4.6"`, etc. |
|
|
43
|
-
| `config` | `object` | — | API keys (`openAIAPIKey`, `anthropicAPIKey`, `googleAPIKey`, `deepSeekAPIKey`, `kimiAPIKey`, `glmAPIKey`), `temperature`, `agentic`, `recursionLimit` |
|
|
43
|
+
| `config` | `object` | — | API keys (`openAIAPIKey`, `anthropicAPIKey`, `googleAPIKey`, `deepSeekAPIKey`, `kimiAPIKey`, `glmAPIKey`), `temperature`, `agentic`, `recursionLimit`, `webSearch` |
|
|
44
44
|
| `prompt` | `string \| object[]` | — | Plain string or array of `{ role, content }` message objects |
|
|
45
45
|
| `onProgressReport` | `function \| null` | `null` | Async callback receiving `{ message, progress }` updates |
|
|
46
46
|
| `minPercent` | `number` | `0` | Lower bound for progress percentage |
|
|
@@ -254,6 +254,71 @@ Shared constants used across the package.
|
|
|
254
254
|
|
|
255
255
|
---
|
|
256
256
|
|
|
257
|
+
## Web Search
|
|
258
|
+
|
|
259
|
+
Set `config.webSearch` to enable each provider's own web search tool. The provider runs the search server-side inside the same request — there is no client-side agent loop and no extra round trip — so every calling convention (streaming, non-streaming, agentic, with or without a Zod schema) is unchanged.
|
|
260
|
+
|
|
261
|
+
| Provider | Native tool | Context control | Billing |
|
|
262
|
+
| --------- | -------------------------------------------------------------------------------------------------------------- | ------------------------------------- | --------------------------- |
|
|
263
|
+
| Anthropic | [`web_search` server tool](https://platform.claude.com/docs/en/agents-and-tools/tool-use/web-search-tool) | Dynamic filtering (**on by default**) | $10 per 1,000 searches |
|
|
264
|
+
| OpenAI | [`web_search` hosted tool](https://platform.openai.com/docs/guides/tools-web-search) (Responses API) | `search_context_size` | Per search, model-dependent |
|
|
265
|
+
| Google | [`googleSearch` grounding](https://ai.google.dev/gemini-api/docs/google-search) | None offered by the API | Per grounded request |
|
|
266
|
+
|
|
267
|
+
```typescript
|
|
268
|
+
const usageTracker = {};
|
|
269
|
+
const result = await langChain.runPromptWithModel(
|
|
270
|
+
"claude-opus-5",
|
|
271
|
+
{
|
|
272
|
+
anthropicAPIKey: "sk-ant-...",
|
|
273
|
+
"claude-opus-5-web-search-costs": 10, // USD per 1,000 searches
|
|
274
|
+
webSearch: { maxUses: 5, allowedDomains: ["reuters.com", "bbc.com"] },
|
|
275
|
+
},
|
|
276
|
+
"What happened in the markets today?",
|
|
277
|
+
null, 0, 100, false, null, "StackFactor", [], usageTracker,
|
|
278
|
+
);
|
|
279
|
+
// usageTracker.tokens["claude-opus-5_webSearches"] === 2
|
|
280
|
+
// usageTracker.cost includes 2 / 1000 * 10
|
|
281
|
+
// usageTracker.webSearchSources === [{ url: "https://reuters.com/...", title: "..." }, ...]
|
|
282
|
+
```
|
|
283
|
+
|
|
284
|
+
### `WebSearchConfig`
|
|
285
|
+
|
|
286
|
+
`webSearch: true` uses provider defaults. Pass an object to configure it; each field is only sent to the providers that accept it, and the rest are ignored.
|
|
287
|
+
|
|
288
|
+
| Field | Applies to | Default | Description |
|
|
289
|
+
| ------------------- | ----------------- | ------------ | ----------------------------------------------------------------------------------------------- |
|
|
290
|
+
| `maxUses` | Anthropic | unlimited | Hard cap on searches per request |
|
|
291
|
+
| `allowedDomains` | Anthropic, OpenAI | — | Restrict results to these domains (bare domains, no scheme) |
|
|
292
|
+
| `blockedDomains` | Anthropic | — | Exclude these domains; cannot be combined with `allowedDomains` |
|
|
293
|
+
| `userLocation` | Anthropic, OpenAI | — | `{ city, region, country, timezone }` — ISO 3166-1 alpha-2 country, IANA timezone |
|
|
294
|
+
| `searchContextSize` | OpenAI | `"medium"` | `"low" \| "medium" \| "high"` — how much context window results may consume |
|
|
295
|
+
| `timeRange` | Google | — | `{ startTime, endTime }` RFC 3339 window (`excludeDomains` is Vertex AI only and is not sent) |
|
|
296
|
+
| `dynamicFiltering` | Anthropic | `true` | Filter results with code before they enter the context window; `false` forces `allowed_callers: ["direct"]` |
|
|
297
|
+
| `responseInclusion` | Anthropic | `"excluded"` | Whether filtered-away result blocks are echoed back in the response |
|
|
298
|
+
| `toolVersion` | Anthropic | per model | Pin the dated tool version instead of selecting it per model |
|
|
299
|
+
|
|
300
|
+
### Context management
|
|
301
|
+
|
|
302
|
+
Search results are the largest thing web search puts into a request, so each provider's context controls are applied up front rather than left at their defaults.
|
|
303
|
+
|
|
304
|
+
**Anthropic — dynamic filtering, on by default.** Basic search (`web_search_20250305`) loads *every* raw search result into the context window. From `web_search_20260209` Claude instead writes and runs code that filters the results first, so only relevant content is ingested. `buildWebSearchTool` picks the tool version per model: Claude 4.6 and later get `web_search_20260318` with filtering enabled and `response_inclusion: "excluded"` (which also keeps the consumed result blocks out of the response, cutting billed output tokens); earlier models, which lack programmatic tool calling, fall back to `web_search_20250305`. Pinning a filtering version on an older model via `toolVersion` automatically adds `allowed_callers: ["direct"]` so the request cannot 400. Anthropic provisions the code execution that filtering needs automatically and does not charge extra for it beyond token costs.
|
|
305
|
+
|
|
306
|
+
**OpenAI — `search_context_size`.** This is OpenAI's only context knob and it is a genuine quality/cost tradeoff, so it is left at OpenAI's own balanced default of `"medium"` rather than silently downgraded. Set `searchContextSize: "low"` to minimize ingested context where answer depth matters less.
|
|
307
|
+
|
|
308
|
+
**Google — no equivalent exists.** The Gemini API's `GoogleSearch` tool has no result-filtering or context-size field; grounded results are injected as-is. The only related lever, `dynamicRetrievalConfig`, belongs to the legacy Gemini 1.5 `googleSearchRetrieval` tool and gates *whether* a search happens, not how much of it is ingested. `searchTypes` is deliberately left unset so grounding stays on text-only web results instead of also returning image bytes.
|
|
309
|
+
|
|
310
|
+
**Downstream.** Non-text blocks (`server_tool_use`, `web_search_tool_result`, code execution results) are dropped by `extractTextContent` and never re-sent: the library issues one self-contained request per call, so encrypted search results are not carried into follow-up turns. In agentic mode the agent loop does resend history, which is where dynamic filtering and `response_inclusion: "excluded"` matter most.
|
|
311
|
+
|
|
312
|
+
**Notes**
|
|
313
|
+
|
|
314
|
+
- Models without a native web search tool (DeepSeek, Kimi, GLM) log a warning and run the prompt without search, so one config can be pointed at any model.
|
|
315
|
+
- Searches performed are added to `usageTracker` as `<model>_webSearches`, costed from `<model>-web-search-costs`. Sources are collected on `usageTracker.webSearchSources`, deduplicated by URL — Anthropic and Google both require citing the original sources when their output is shown to end users.
|
|
316
|
+
- Combining web search with a Zod `schema` requires Gemini 3 or later on Google; Gemini 1.5/2.x reject `responseSchema` alongside `googleSearch` with a 400.
|
|
317
|
+
- With `response_inclusion: "excluded"`, `usageTracker.webSearchSources` is populated from the citations attached to the answer rather than from every raw result — the sources actually used, which is what has to be displayed.
|
|
318
|
+
- Enabling web search on a `gpt-*` model routes the request through OpenAI's Responses API, where the structured-output schema is sent as `text.format` instead of `response_format`. This is handled automatically.
|
|
319
|
+
|
|
320
|
+
---
|
|
321
|
+
|
|
257
322
|
## Supported Models
|
|
258
323
|
|
|
259
324
|
### Text / Chat
|
|
@@ -294,6 +359,9 @@ The `config` object accepted by LangChain methods supports the following keys:
|
|
|
294
359
|
| `maxTokens` | `number` | Maximum output tokens (default: `16384` for Claude, `200000` for other providers). For Claude, values above `21333` automatically enable LangChain streaming to bypass the Anthropic SDK's 10-minute non-streaming guard. |
|
|
295
360
|
| `agentic` | `boolean` | Enable agentic mode in `runPromptWithModel` |
|
|
296
361
|
| `recursionLimit` | `number` | Max agent steps (default: `25`) |
|
|
362
|
+
| `webSearch` | `boolean \| WebSearchConfig` | Enable the provider's native web search tool (see [Web Search](#web-search)) |
|
|
363
|
+
|
|
364
|
+
Per-model cost constants are read from the same object using flat keys: `<model>-input-token-costs`, `<model>-output-token-costs`, `<model>-image-input-token-costs`, `<model>-image-output-token-costs`, `<model>-character-costs` (all USD per million), and `<model>-web-search-costs` (USD per **1,000** searches).
|
|
297
365
|
|
|
298
366
|
---
|
|
299
367
|
|
package/dist/cjs/agentProto.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ import * as grpc from "@grpc/grpc-js";
|
|
|
6
6
|
* zero or more `Progress` frames (driven by the agent's `onProgress`) followed
|
|
7
7
|
* by exactly one `Result` or `Error`.
|
|
8
8
|
*/
|
|
9
|
-
export declare const PROTO = "\nsyntax = \"proto3\";\npackage stackfactor.agent.v1;\n\nservice Agent {\n rpc Execute(ExecuteRequest) returns (stream Update);\n // Liveness/health probe served by serve() itself \u2014 no agent code required.\n // deep=true also exercises the StackFactor auth callback (BACKEND_URL).\n rpc HealthCheck(HealthCheckRequest) returns (HealthCheckResponse);\n}\n\nmessage ExecuteRequest {\n string content_type = 1;\n string data_json = 2;\n string config_json = 3;\n string request_json = 4;\n int32 event = 5;\n}\n\nmessage HealthCheckRequest {\n // Optional JSON carrying { authToken } for the deep backend-callback check.\n string request_json = 1;\n bool deep = 2;\n // Deep check only: repo-relative path to the agent's self-check module to run\n // (e.g. \"src/check.js\"). Empty \u2192 fall back to the conventional \"src/check.js\".\n string check_code = 3;\n // Deep check only: JSON of the resolved agent config (constantsAndVars/\n // secrets) made available to the self-check as ctx.config. May be empty.\n string config_json = 4;\n}\n\n// One result row from the agent's self-check module. The agent owns only its\n// own checks; reachability/ingress/version-drift rows are synthesised backend-\n// side. severity is optional: \"warn\" marks a failing check as non-blocking;\n// empty or \"error\" is blocking.\nmessage CheckResult {\n string name = 1;\n bool ok = 2;\n string detail = 3;\n string severity = 4;\n}\n\nmessage HealthCheckResponse {\n bool ok = 1;\n bool backend_reachable = 2;\n string version = 3;\n string message = 4;\n repeated CheckResult checks = 5;\n}\n\nmessage Update {\n oneof payload {\n Progress progress = 1;\n Result result = 2;\n ErrorInfo error = 3;\n }\n}\n\nmessage Progress { int32 progress = 1; string message = 2; }\nmessage Result { string result_json = 1; }\nmessage ErrorInfo { int32 code = 1; string message = 2; }\n";
|
|
9
|
+
export declare const PROTO = "\nsyntax = \"proto3\";\npackage stackfactor.agent.v1;\n\nservice Agent {\n rpc Execute(ExecuteRequest) returns (stream Update);\n // Liveness/health probe served by serve() itself \u2014 no agent code required.\n // deep=true also exercises the StackFactor auth callback (BACKEND_URL).\n rpc HealthCheck(HealthCheckRequest) returns (HealthCheckResponse);\n}\n\nmessage ExecuteRequest {\n string content_type = 1;\n string data_json = 2;\n string config_json = 3;\n string request_json = 4;\n int32 event = 5;\n // Optional repo-relative module to run INSTEAD of the agent's main (e.g.\n // \"src/webhooks/inbound-sms.js\"). Empty -> main, which is every pre-webhook\n // caller, so this stays wire-compatible with agents built before it existed.\n // Set by the webhook receiver from the integration's webHooks[].code. Follows\n // the same untrusted-path rules as HealthCheck's check_code.\n string code = 6;\n}\n\nmessage HealthCheckRequest {\n // Optional JSON carrying { authToken } for the deep backend-callback check.\n string request_json = 1;\n bool deep = 2;\n // Deep check only: repo-relative path to the agent's self-check module to run\n // (e.g. \"src/check.js\"). Empty \u2192 fall back to the conventional \"src/check.js\".\n string check_code = 3;\n // Deep check only: JSON of the resolved agent config (constantsAndVars/\n // secrets) made available to the self-check as ctx.config. May be empty.\n string config_json = 4;\n}\n\n// One result row from the agent's self-check module. The agent owns only its\n// own checks; reachability/ingress/version-drift rows are synthesised backend-\n// side. severity is optional: \"warn\" marks a failing check as non-blocking;\n// empty or \"error\" is blocking.\nmessage CheckResult {\n string name = 1;\n bool ok = 2;\n string detail = 3;\n string severity = 4;\n}\n\nmessage HealthCheckResponse {\n bool ok = 1;\n bool backend_reachable = 2;\n string version = 3;\n string message = 4;\n repeated CheckResult checks = 5;\n}\n\nmessage Update {\n oneof payload {\n Progress progress = 1;\n Result result = 2;\n ErrorInfo error = 3;\n }\n}\n\nmessage Progress { int32 progress = 1; string message = 2; }\nmessage Result { string result_json = 1; }\nmessage ErrorInfo { int32 code = 1; string message = 2; }\n";
|
|
10
10
|
/**
|
|
11
11
|
* Loads the Agent proto package. proto-loader reads from a file, so the embedded
|
|
12
12
|
* schema is written to a temp path — keeps the package self-contained across the
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agentProto.d.ts","sourceRoot":"","sources":["../../src/agentProto.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,eAAe,CAAC;AAMtC;;;;;;GAMG;AACH,eAAO,MAAM,KAAK,
|
|
1
|
+
{"version":3,"file":"agentProto.d.ts","sourceRoot":"","sources":["../../src/agentProto.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,eAAe,CAAC;AAMtC;;;;;;GAMG;AACH,eAAO,MAAM,KAAK,y3EAmEjB,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB,QAAO,GAWnC,CAAC;AAEF,oEAAoE;AACpE,eAAO,MAAM,gBAAgB,QAAO,IAAI,CAAC,iBACc,CAAC"}
|
package/dist/cjs/agentProto.js
CHANGED
|
@@ -63,6 +63,12 @@ message ExecuteRequest {
|
|
|
63
63
|
string config_json = 3;
|
|
64
64
|
string request_json = 4;
|
|
65
65
|
int32 event = 5;
|
|
66
|
+
// Optional repo-relative module to run INSTEAD of the agent's main (e.g.
|
|
67
|
+
// "src/webhooks/inbound-sms.js"). Empty -> main, which is every pre-webhook
|
|
68
|
+
// caller, so this stays wire-compatible with agents built before it existed.
|
|
69
|
+
// Set by the webhook receiver from the integration's webHooks[].code. Follows
|
|
70
|
+
// the same untrusted-path rules as HealthCheck's check_code.
|
|
71
|
+
string code = 6;
|
|
66
72
|
}
|
|
67
73
|
|
|
68
74
|
message HealthCheckRequest {
|
package/dist/cjs/client.d.ts
CHANGED
|
@@ -10,6 +10,13 @@ export interface AgentExecuteRequest {
|
|
|
10
10
|
config_json: string;
|
|
11
11
|
request_json: string;
|
|
12
12
|
event: number;
|
|
13
|
+
/**
|
|
14
|
+
* Optional repo-relative module to run instead of the agent's `main` — the
|
|
15
|
+
* webhook receiver sets it from the integration's `webHooks[].code`. Omit (or
|
|
16
|
+
* pass "") for every other caller; the agent then runs `main` exactly as
|
|
17
|
+
* before. Agents built against an older agent-utils ignore the field.
|
|
18
|
+
*/
|
|
19
|
+
code?: string;
|
|
13
20
|
}
|
|
14
21
|
export interface CallAgentOptions {
|
|
15
22
|
/**
|
package/dist/cjs/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":"AAGA;;;;;GAKG;AACH,MAAM,WAAW,mBAAmB;IAClC,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,MAAM,C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C,EAAE,MAAM,CAAC;IACnB;;;OAGG;IACH,MAAM,CAAC,EAAE,GAAG,CAAC;IACb,uEAAuE;IACvE,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,+DAA+D;AAC/D,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,OAAO,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,uDAAuD;IACvD,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,WAAW;IAC1B,2EAA2E;IAC3E,EAAE,EAAE,OAAO,CAAC;IACZ,gFAAgF;IAChF,gBAAgB,EAAE,OAAO,CAAC;IAC1B,8DAA8D;IAC9D,OAAO,EAAE,MAAM,CAAC;IAChB,6EAA6E;IAC7E,OAAO,EAAE,MAAM,CAAC;IAChB,gFAAgF;IAChF,MAAM,EAAE,UAAU,EAAE,CAAC;CACtB;AAID;;;;;;;GAOG;AACH,eAAO,MAAM,UAAU,GACrB,UAAU,MAAM,EAChB,UAAS,iBAAsB,KAC9B,OAAO,CAAC,WAAW,CA8ClB,CAAC"}
|
package/dist/cjs/index.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ export { constants };
|
|
|
9
9
|
export { errorHandling, AppError };
|
|
10
10
|
export type { ParsedError } from "./errorHandling.js";
|
|
11
11
|
export { langChain };
|
|
12
|
-
export type { UsageTracker } from "./langChain.js";
|
|
12
|
+
export type { UsageTracker, WebSearchConfig } from "./langChain.js";
|
|
13
13
|
export { logger };
|
|
14
14
|
export { serve };
|
|
15
15
|
export { callAgent };
|
package/dist/cjs/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,YAAY,CAAC;AACnC,OAAO,aAAa,EAAE,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC7D,OAAO,SAAS,MAAM,gBA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mBAAmB,EACnB,gBAAgB,EAChB,iBAAiB,EACjB,WAAW,GACZ,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,cAAc,EAAE,CAAC"}
|
package/dist/cjs/langChain.d.ts
CHANGED
|
@@ -9,6 +9,73 @@ export type UsageTracker = {
|
|
|
9
9
|
tokens: {
|
|
10
10
|
[tokenKey: string]: number;
|
|
11
11
|
};
|
|
12
|
+
/**
|
|
13
|
+
* Sources returned by native web search, deduplicated by URL across every
|
|
14
|
+
* call in the run. Only present once a search has actually run. Anthropic and
|
|
15
|
+
* Google both require the original sources to be cited when their output is
|
|
16
|
+
* shown to end users, so they are surfaced here rather than discarded with
|
|
17
|
+
* the rest of the non-text content blocks.
|
|
18
|
+
*/
|
|
19
|
+
webSearchSources?: {
|
|
20
|
+
url: string;
|
|
21
|
+
title?: string;
|
|
22
|
+
}[];
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Caller-facing options for the providers' native web search tools. Enable web
|
|
26
|
+
* search by setting `config.webSearch` to `true` (provider defaults) or to one
|
|
27
|
+
* of these objects. Every field is optional and is only forwarded to the
|
|
28
|
+
* providers that accept it — see `buildWebSearchTool` for the mapping.
|
|
29
|
+
*/
|
|
30
|
+
export type WebSearchConfig = {
|
|
31
|
+
/** Anthropic only: hard cap on searches per request (`max_uses`). */
|
|
32
|
+
maxUses?: number;
|
|
33
|
+
/** Anthropic (`allowed_domains`) and OpenAI (`filters.allowed_domains`). */
|
|
34
|
+
allowedDomains?: string[];
|
|
35
|
+
/** Anthropic only (`blocked_domains`); cannot be combined with `allowedDomains`. */
|
|
36
|
+
blockedDomains?: string[];
|
|
37
|
+
/** Anthropic and OpenAI: approximate location used to localize results. */
|
|
38
|
+
userLocation?: {
|
|
39
|
+
city?: string;
|
|
40
|
+
region?: string;
|
|
41
|
+
/** Two-letter ISO 3166-1 alpha-2 code, e.g. `"US"`. */
|
|
42
|
+
country?: string;
|
|
43
|
+
/** IANA timezone ID, e.g. `"America/Los_Angeles"`. */
|
|
44
|
+
timezone?: string;
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* OpenAI only: how much of the context window search results may consume.
|
|
48
|
+
* OpenAI's default is `"medium"`; `"low"` minimizes context at some cost to
|
|
49
|
+
* answer quality, `"high"` is the expensive end.
|
|
50
|
+
*/
|
|
51
|
+
searchContextSize?: "low" | "medium" | "high";
|
|
52
|
+
/** Gemini only: RFC 3339 window the search is restricted to. */
|
|
53
|
+
timeRange?: {
|
|
54
|
+
startTime: string;
|
|
55
|
+
endTime: string;
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* Anthropic only: opt out of dynamic filtering by forcing the search to be
|
|
59
|
+
* called directly (`allowed_callers: ["direct"]`). Defaults to `true` on
|
|
60
|
+
* models that support it — see `supportsAnthropicDynamicFiltering`. Turning
|
|
61
|
+
* this off means every raw search result lands in the context window.
|
|
62
|
+
*/
|
|
63
|
+
dynamicFiltering?: boolean;
|
|
64
|
+
/**
|
|
65
|
+
* Anthropic only: whether search result blocks consumed by dynamic filtering
|
|
66
|
+
* are echoed back in the response. Defaults to `"excluded"`, which drops them
|
|
67
|
+
* and cuts the output tokens billed for content nothing downstream reads.
|
|
68
|
+
*/
|
|
69
|
+
responseInclusion?: "full" | "excluded";
|
|
70
|
+
/**
|
|
71
|
+
* Anthropic only: pin the dated tool version instead of letting
|
|
72
|
+
* `buildWebSearchTool` pick per model. `web_search_20250305` is basic search,
|
|
73
|
+
* `web_search_20260209` adds dynamic filtering, `web_search_20260318` adds
|
|
74
|
+
* response-inclusion control. Pinning a filtering version on a model that
|
|
75
|
+
* cannot do programmatic tool calling returns a 400 unless
|
|
76
|
+
* `dynamicFiltering: false` is also set.
|
|
77
|
+
*/
|
|
78
|
+
toolVersion?: string;
|
|
12
79
|
};
|
|
13
80
|
declare const _default: {
|
|
14
81
|
checkIfAIProviderConfigured: (config: any) => void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"langChain.d.ts","sourceRoot":"","sources":["../../src/langChain.ts"],"names":[],"mappings":"AAuGA;;;;;GAKG;AACH,MAAM,MAAM,YAAY,GAAG;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE;QAAE,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"langChain.d.ts","sourceRoot":"","sources":["../../src/langChain.ts"],"names":[],"mappings":"AAuGA;;;;;GAKG;AACH,MAAM,MAAM,YAAY,GAAG;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE;QAAE,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAC;IACvC;;;;;;OAMG;IACH,gBAAgB,CAAC,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;CACtD,CAAC;AAskBF;;;;;GAKG;AACH,MAAM,MAAM,eAAe,GAAG;IAC5B,qEAAqE;IACrE,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,4EAA4E;IAC5E,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;IAC1B,oFAAoF;IACpF,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;IAC1B,2EAA2E;IAC3E,YAAY,CAAC,EAAE;QACb,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,uDAAuD;QACvD,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,sDAAsD;QACtD,QAAQ,CAAC,EAAE,MAAM,CAAC;KACnB,CAAC;IACF;;;;OAIG;IACH,iBAAiB,CAAC,EAAE,KAAK,GAAG,QAAQ,GAAG,MAAM,CAAC;IAC9C,gEAAgE;IAChE,SAAS,CAAC,EAAE;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;IACnD;;;;;OAKG;IACH,gBAAgB,CAAC,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