nexus-ai-pro 2.18.0 → 2.20.2

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 (81) hide show
  1. package/API_STABILITY.md +64 -1
  2. package/CHANGELOG.md +113 -1
  3. package/README.md +11 -3
  4. package/dist/agent/capabilities.d.ts +3 -0
  5. package/dist/agent/openapi.d.ts +139 -0
  6. package/dist/agent/openapi.js +455 -0
  7. package/dist/capabilities/negotiate.js +5 -0
  8. package/dist/decisions/completion.d.ts +48 -0
  9. package/dist/decisions/completion.js +195 -0
  10. package/dist/decisions/core.d.ts +525 -0
  11. package/dist/decisions/core.js +493 -0
  12. package/dist/decisions/index.d.ts +9 -0
  13. package/dist/decisions/index.js +3 -0
  14. package/dist/decisions/integrations.d.ts +142 -0
  15. package/dist/decisions/integrations.js +170 -0
  16. package/dist/decisions/mock.d.ts +32 -0
  17. package/dist/decisions/mock.js +47 -0
  18. package/dist/decisions/typesafe.d.ts +45 -0
  19. package/dist/decisions/typesafe.js +144 -0
  20. package/dist/evaluate/emulate.d.ts +73 -6
  21. package/dist/evaluate/emulate.js +114 -12
  22. package/dist/index.d.ts +1 -1
  23. package/dist/optimizer/densifier.js +20 -11
  24. package/dist/protocols/a2a-grpc.js +1 -1
  25. package/dist/protocols/a2a-proto.d.ts +2 -2
  26. package/dist/protocols/a2a-proto.js +76 -1
  27. package/dist/protocols/a2a.d.ts +121 -0
  28. package/dist/protocols/a2a.js +88 -29
  29. package/dist/providers/google.js +28 -0
  30. package/dist/providers/ollama.js +23 -0
  31. package/dist/providers/openai.d.ts +6 -0
  32. package/dist/providers/openai.js +26 -0
  33. package/dist/types/lifecycle.d.ts +1 -1
  34. package/dist/types/messages.d.ts +9 -0
  35. package/dist/types/providers.d.ts +2 -0
  36. package/dist/types/response.d.ts +17 -0
  37. package/dist/types/tracing.d.ts +1 -1
  38. package/dist/version.d.ts +1 -1
  39. package/dist/version.js +1 -1
  40. package/dist/workflow/chains.d.ts +13 -1
  41. package/dist/workflow/chains.js +40 -0
  42. package/dist-cjs/agent/capabilities.d.ts +3 -0
  43. package/dist-cjs/agent/openapi.d.ts +139 -0
  44. package/dist-cjs/agent/openapi.js +461 -0
  45. package/dist-cjs/capabilities/negotiate.js +5 -0
  46. package/dist-cjs/decisions/completion.d.ts +48 -0
  47. package/dist-cjs/decisions/completion.js +198 -0
  48. package/dist-cjs/decisions/core.d.ts +525 -0
  49. package/dist-cjs/decisions/core.js +509 -0
  50. package/dist-cjs/decisions/index.d.ts +9 -0
  51. package/dist-cjs/decisions/index.js +27 -0
  52. package/dist-cjs/decisions/integrations.d.ts +142 -0
  53. package/dist-cjs/decisions/integrations.js +178 -0
  54. package/dist-cjs/decisions/mock.d.ts +32 -0
  55. package/dist-cjs/decisions/mock.js +51 -0
  56. package/dist-cjs/decisions/typesafe.d.ts +45 -0
  57. package/dist-cjs/decisions/typesafe.js +148 -0
  58. package/dist-cjs/evaluate/emulate.d.ts +73 -6
  59. package/dist-cjs/evaluate/emulate.js +116 -13
  60. package/dist-cjs/index.d.ts +1 -1
  61. package/dist-cjs/optimizer/densifier.js +20 -11
  62. package/dist-cjs/protocols/a2a-grpc.js +1 -1
  63. package/dist-cjs/protocols/a2a-proto.d.ts +2 -2
  64. package/dist-cjs/protocols/a2a-proto.js +76 -1
  65. package/dist-cjs/protocols/a2a.d.ts +121 -0
  66. package/dist-cjs/protocols/a2a.js +88 -29
  67. package/dist-cjs/providers/google.js +28 -0
  68. package/dist-cjs/providers/ollama.js +23 -0
  69. package/dist-cjs/providers/openai.d.ts +6 -0
  70. package/dist-cjs/providers/openai.js +26 -0
  71. package/dist-cjs/types/lifecycle.d.ts +1 -1
  72. package/dist-cjs/types/messages.d.ts +9 -0
  73. package/dist-cjs/types/providers.d.ts +2 -0
  74. package/dist-cjs/types/response.d.ts +17 -0
  75. package/dist-cjs/types/tracing.d.ts +1 -1
  76. package/dist-cjs/version.d.ts +1 -1
  77. package/dist-cjs/version.js +1 -1
  78. package/dist-cjs/workflow/chains.d.ts +13 -1
  79. package/dist-cjs/workflow/chains.js +40 -0
  80. package/llms.txt +2 -1
  81. package/package.json +54 -2
package/API_STABILITY.md CHANGED
@@ -41,6 +41,69 @@ Both are covered by this policy:
41
41
  Deep imports into `dist`, `dist-cjs`, or `src` are not supported. Import only from `nexus-ai-pro` or
42
42
  one of its explicit subpaths.
43
43
 
44
+ ## How an item graduates
45
+
46
+ A new surface starts this way:
47
+
48
+ 1. Provider-neutral types and a deterministic mock land first.
49
+ 2. One real adapter proves the contract; conformance fixtures cover it.
50
+ 3. A second adapter on a different wire protocol proves portability.
51
+ 4. Packed-package, clean-install, and consumer type-resolution tests pass on every supported Node
52
+ line.
53
+ 5. Evaluation appropriate to the modality covers the supported capability matrix.
54
+
55
+ It leaves experimental status here only when every item below has evidence, published with the
56
+ graduation:
57
+
58
+ | Requirement | Evidence |
59
+ | --- | --- |
60
+ | API stability | Covered by the 2.x compatibility rules, with no planned breaking change |
61
+ | Conformance | Passes its contract suite on every supported backend |
62
+ | Crash recovery | Crash-injection tests at each durable boundary, where it has one |
63
+ | Concurrency | Race tests with several processes on the same records |
64
+ | Load | A published benchmark with a budget in CI |
65
+ | Tenant isolation | The isolation suite, where it stores tenant data |
66
+ | Security | A written threat review, with its findings closed |
67
+ | Upgrade | A migration test from the previous minor |
68
+ | Soak | A long-running test with flat memory and no leaked handles |
69
+
70
+ ## 2.20 stage (2.20.0)
71
+
72
+ Everything 2.20 adds is stable from the start and additive, unless this section says otherwise.
73
+
74
+ New and stable:
75
+ - `nexus-ai-pro/agent/openapi`: `openApiTools()`, `loadOpenApiTools()`, `OpenApiError`,
76
+ `OpenApiDocument`, `OpenApiOperation`, `OpenApiTools`, `OpenApiToolsOptions`, and
77
+ `OpenApiHeadersRequest`;
78
+ - the capabilities `api.read`, `api.write`, and `api.destructive`;
79
+ - in `nexus-ai-pro/evaluate/emulate`: `EmulatedWorld`, `EmulatedWorldCall`, `EmulatedWorldSnapshot`,
80
+ `EmulatedToolsOptions.world` and `reads`, and `emulationKey()`'s `world`. A key without a world is
81
+ the key of every earlier release;
82
+ - in `nexus-ai-pro/protocols/a2a`: `A2aServerOptions.tenants`, `A2aTenancyOptions`,
83
+ `A2aClientOptions.tenant`, `A2aTaskRecord.tenant`, `A2aTaskQuery.tenant`, `A2A_ERRORS.permissionDenied`,
84
+ the card's `securitySchemes`, `securityRequirements`, and `signatures`, `A2aSkill.securityRequirements`,
85
+ `A2aSecurityScheme`, `A2aOAuthFlows`, `A2aSecurityRequirement`, and `A2aCardSignature`.
86
+
87
+ Changed on purpose: the gRPC binding writes and reads a card's security schemes, requirements, and
88
+ signatures, which it read past; without `tenants`, a request's tenant is still not read. A custom
89
+ `A2aTaskStore` serving several tenants should honour `A2aTaskQuery.tenant`, for full pages; the handler
90
+ filters by tenant either way.
91
+
92
+ ## 2.19 stage (2.19.0)
93
+
94
+ Everything 2.19 adds is stable from the start and additive, unless this section says otherwise.
95
+
96
+ New and stable:
97
+ - in the root: `CompletionRequest.logprobs`, `NexusResponse.logprobs`, `TokenLogprob`, and
98
+ `ModelCapabilities.logprobs`;
99
+ - in `nexus-ai-pro/workflows`: `ClassifyRouteOptions.decisions`.
100
+
101
+ New and experimental, until the live workflow passes against TypeSafe AI's Jev and a model that
102
+ reports log probabilities: the typed decisions family, `nexus-ai-pro/decisions`,
103
+ `nexus-ai-pro/decisions/typesafe`, and `nexus-ai-pro/decisions/mock`.
104
+
105
+ Changed on purpose: `OperationFamily` and `RunKind` widen with `decision`.
106
+
44
107
  ## 2.18 stage (2.18.0)
45
108
 
46
109
  Everything 2.18 adds is stable from the start and additive, unless this section says otherwise.
@@ -640,7 +703,7 @@ These security fixes tighten more behavior, each closing a finding of a graduati
640
703
  ### Graduation
641
704
 
642
705
  A surface left experimental status in 2.4 only when every requirement in
643
- [How an item graduates](./ROADMAP.md#how-an-item-graduates) had evidence. That evidence is below.
706
+ [How an item graduates](#how-an-item-graduates) had evidence. That evidence is below.
644
707
  "n/a" names a requirement that does not apply, and says why. Every test named here runs in CI.
645
708
  Load and soak budgets are checked by `npm run bench:surfaces` and `npm run bench:runtime`, which are
646
709
  part of `check:release`. Upgrade tests run against the published 2.3.0 package, installed as a
package/CHANGELOG.md CHANGED
@@ -4,6 +4,114 @@ Notable changes to this project are recorded here. The format follows [Keep a Ch
4
4
 
5
5
  ## [Unreleased]
6
6
 
7
+ ## [2.20.2] - 2026-10-24
8
+
9
+ The first published release of 2.20. The package is 2.20.0's: the publishes of 2.20.0 and 2.20.1
10
+ stopped at a studio test that failed by chance, so neither reached npm.
11
+
12
+ ### Fixed
13
+
14
+ - The studio's load budget is judged by the fastest of five passes, after three warm-up passes
15
+ rather than one. The median of five failed the 2.20.1 publish at 3.61 calibration loops: its first
16
+ three passes took 91 to 102 ms and its last two 37 and 48 ms. A busy runner only ever adds time,
17
+ while a real slowdown slows every pass, so a request made 0.1 ms slower still fails it, at 4.3 loops.
18
+
19
+ ## [2.20.1] - 2026-10-24 (not published)
20
+
21
+ The package is 2.20.0's. Its publish stopped at the same studio test, measured another way.
22
+
23
+ ### Fixed
24
+
25
+ - The studio's load budget is measured as the median of five passes, as the surface budgets are,
26
+ rather than one: a single slow pass on a busy runner failed the 2.20.0 publish at 2.56 calibration
27
+ loops against a budget of 2.55, where the test measures 0.77. A real slowdown still fails it.
28
+
29
+ ## [2.20.0] - 2026-10-24 (not published)
30
+
31
+ Tools read from a service's OpenAPI document, an emulator that remembers the evaluation, and one A2A
32
+ handler serving many tenants.
33
+
34
+ ### Added
35
+
36
+ - **Tools from an OpenAPI document.** `openApiTools()` and `loadOpenApiTools()`, on
37
+ `nexus-ai-pro/agent/openapi`, read an OpenAPI 3.0 or 3.1 document into one tool per operation: its
38
+ name, description, and parameters the API's, its body's fields flattened, references followed, and
39
+ each declaring `api.read`, `api.write`, or `api.destructive` as its method says, with `network` for
40
+ the API's host. Given where the API lives, each tool calls it, the path encoded, the application's
41
+ headers sent, no redirect followed, and an answer read only up to a limit; a refusal is an
42
+ `OpenApiError` in the API's own words. `results` holds the schema of what each returns.
43
+ - **An emulator that remembers the evaluation.** An `EmulatedWorld`, given to `emulatedTools()` as
44
+ `world`, holds the scenario and every call across the runs of an evaluation, so a change one example
45
+ makes is there for the next; the emulator is told every change. `snapshot()` writes it as JSON,
46
+ `fork()` and `new EmulatedWorld(snapshot)` start runs from it, and the key of each answer kept carries
47
+ the world's `digest()`, so a recorded evaluation replays only after the same changes. `reads` names
48
+ tools that change nothing, beside those whose capabilities only read.
49
+ - **Capabilities for an API's operations:** `api.read:<api>/<operation>`, `api.write`, and
50
+ `api.destructive`, decided by a permission policy as MCP's are.
51
+ - **A2A for several tenants.** `a2aHandler({ tenants })` routes each request by the `tenant` it names,
52
+ in its params, its path (`/{tenant}/message:send`), or its gRPC message. Each tenant's tasks and
53
+ conversations are its own, its runs carry the tenant on their principal, and a caller that may not
54
+ act for the tenant it names is refused with `A2A_ERRORS.permissionDenied`, HTTP 403 and
55
+ `PERMISSION_DENIED` over gRPC. `A2aTenancyOptions` sets who may, and whether a tenant is required.
56
+ Task stores keep and list by tenant. A client names its interface's tenant, or its `tenant` option,
57
+ on every request, as protocol 1.0 requires.
58
+ - **A card's security.** `securitySchemes` (`A2aSecurityScheme`, with `A2aOAuthFlows`),
59
+ `securityRequirements` (`A2aSecurityRequirement`, on the card and on a skill), and `signatures`
60
+ (`A2aCardSignature`) are part of the card, and the gRPC binding writes and reads them, which it read
61
+ past before.
62
+
63
+ ### Fixed
64
+
65
+ - The prompt densifier joined a code block's fences to the text around them, so a block it meant to
66
+ keep stopped being one; it shortened phrases inside other words, turning "in order today" into
67
+ "today"; and it lowercased a phrase that began a sentence.
68
+ - A test of a call that never answers, and the unit, coverage, and studio runs, no longer let a hung
69
+ test hold the release gate: every synchronous child the tests start has a timeout, and a test that
70
+ runs past five minutes fails.
71
+
72
+ ## [2.19.0] - 2026-10-24
73
+
74
+ Typed decisions: a yes or no, a choice, or a score, answered with probabilities and a confidence read
75
+ from them, from TypeSafe AI's Jev or from any model, acted on when sure and sent to a person when not.
76
+
77
+ ### Added
78
+
79
+ - **Typed decisions.** `nexus-ai-pro/decisions` asks a `DecisionRequest`'s questions of one state: a
80
+ `YesNoQuestion`, a `ChoiceQuestion` of up to 255 options, or a `ScoreQuestion` of up to ten levels,
81
+ each answered in isolation with its probabilities and a confidence read the same way from any
82
+ provider. Answers are typed by their questions, so a choice's answer names only its options.
83
+ `DecisionManager` refuses a malformed question before it is sent, fails over, caches, traces each
84
+ decision as a run of kind `decision`, and runs it as an operation of the client, family
85
+ `decision`, budgeted at its model's price and on the tenant's key.
86
+ - **TypeSafe AI's Jev.** `TypeSafeDecisionProvider`, on `nexus-ai-pro/decisions/typesafe`, speaks the
87
+ System One API: every question of a decision in one call, its refusals naming the field at fault,
88
+ priced at $42 per billion input tokens with output free.
89
+ - **Decisions from any model.** `completionDecisions()` asks a completion model each question for a
90
+ one-token code, and reads its probabilities from that token's log probabilities where the provider
91
+ reports them, or counts them over samples where it does not, or refuses to.
92
+ - **Gates and calibration.** `gate()` acts, sends to a person, or abstains by confidence; `calibrate()`
93
+ measures how answers' probabilities track how often they are right, and chooses the threshold that
94
+ holds a target accuracy on the application's own labelled answers.
95
+ - **Decisions where the package decides.** `decisionRoute()` for a graph's branch, `decisionPermissions()`
96
+ for an agent's tool calls, `decisionGuard()` and `decisionModel()` as agent middleware,
97
+ `decisionEvaluator()` and `reviewUnsure()` for evaluation, and `classifyRoute()`'s `decisions`:
98
+ an uncertain answer goes to a person.
99
+ - **Log probabilities.** `CompletionRequest.logprobs` asks for each answer token's log probability and
100
+ its alternatives, on `NexusResponse.logprobs` as `TokenLogprob` values, from OpenAI's Chat
101
+ Completions, the OpenAI-compatible adapters that report them, Gemini, and Ollama;
102
+ `ModelCapabilities.logprobs` declares a model that cannot.
103
+ - `MockDecisionProvider`, on `nexus-ai-pro/decisions/mock`, and `runDecisionConformance()`.
104
+
105
+ ### Changed
106
+
107
+ - `OperationFamily` and `RunKind` have `decision`; a `switch` over either that names every one needs
108
+ the new one.
109
+
110
+ ### Fixed
111
+
112
+ - A test that waits forever fails at five minutes, and every child process the tests start
113
+ synchronously has a timeout of its own: the 2.18.0 publish's first attempt waited two hours on one.
114
+
7
115
  ## [2.18.0] - 2026-10-22
8
116
 
9
117
  Span events and links, media that knows its length, a tenant's threads and runs listed and paged
@@ -3179,7 +3287,11 @@ shared policy vocabulary is in place for a future release that revisits this.
3179
3287
  - URL fetching rejects unsafe private-network targets and limits response reads.
3180
3288
  - CLI and audit findings no longer disclose detected secret values.
3181
3289
 
3182
- [Unreleased]: https://github.com/mkhitar-abrahamyan/nexus-ai/compare/v2.18.0...HEAD
3290
+ [Unreleased]: https://github.com/mkhitar-abrahamyan/nexus-ai/compare/v2.20.2...HEAD
3291
+ [2.20.2]: https://github.com/mkhitar-abrahamyan/nexus-ai/compare/v2.20.1...v2.20.2
3292
+ [2.20.1]: https://github.com/mkhitar-abrahamyan/nexus-ai/compare/v2.20.0...v2.20.1
3293
+ [2.20.0]: https://github.com/mkhitar-abrahamyan/nexus-ai/compare/v2.19.0...v2.20.0
3294
+ [2.19.0]: https://github.com/mkhitar-abrahamyan/nexus-ai/compare/v2.18.0...v2.19.0
3183
3295
  [2.18.0]: https://github.com/mkhitar-abrahamyan/nexus-ai/compare/v2.17.0...v2.18.0
3184
3296
  [2.17.0]: https://github.com/mkhitar-abrahamyan/nexus-ai/compare/v2.16.0...v2.17.0
3185
3297
  [2.16.0]: https://github.com/mkhitar-abrahamyan/nexus-ai/compare/v2.15.1...v2.16.0
package/README.md CHANGED
@@ -156,6 +156,7 @@ from the doc comments. The guides live in the repository, so these links go to G
156
156
  | [Retrieval](https://github.com/mkhitar-abrahamyan/nexus-ai/blob/main/docs/retrieval.md) | Hybrid search, reranking, MMR, parent documents, and Redis, Pinecone, Weaviate, and Chroma stores |
157
157
  | [Embeddings and retrieval](https://github.com/mkhitar-abrahamyan/nexus-ai/blob/main/docs/embeddings.md) | Embeddings as a routed operation family, and RAG helpers |
158
158
  | [Media understanding](https://github.com/mkhitar-abrahamyan/nexus-ai/blob/main/docs/media.md) | Reading documents and images page by page, describing images, and answering questions about them, through any vision model or OCR |
159
+ | [Typed decisions](https://github.com/mkhitar-abrahamyan/nexus-ai/blob/main/docs/decisions.md) | A yes or no, a choice, or a score, answered with probabilities and a calibrated confidence, from TypeSafe AI's Jev or any model, so a graph, an approval, or a guardrail acts when it is sure and asks a person when not |
159
160
  | [Video generation](https://github.com/mkhitar-abrahamyan/nexus-ai/blob/main/docs/video.md) | Videos from a prompt or a first frame, on Google Veo and Runway, as durable jobs streamed into an asset store and priced per second |
160
161
  | [Images (experimental)](https://github.com/mkhitar-abrahamyan/nexus-ai/blob/main/docs/images.md) | Generation and masked edits over three backends, input safety, moderation, asset stores |
161
162
  | [Voice](https://github.com/mkhitar-abrahamyan/nexus-ai/blob/main/docs/voice.md) | Transcription, speech, voice turns, and voice sessions |
@@ -330,12 +331,19 @@ Shipped so far:
330
331
  video is extended from its own job or edited on Gemini Omni Flash, Veo, and Runway;
331
332
  - 2.18 span events and links, as OpenTelemetry has them, media that knows its length from its own
332
333
  headers, a tenant's threads and runs listed and paged across all of its regions, MCP servers that
333
- reconnect and change their tools within a session, and videos made after reference videos.
334
+ reconnect and change their tools within a session, and videos made after reference videos;
335
+ - 2.19 typed decisions: a yes or no, a choice, or a score, answered with probabilities and a
336
+ confidence, from TypeSafe AI's Jev or from any model's log probabilities, gated by thresholds a
337
+ calibration chooses, so a graph's branch, an approval, or a guardrail acts when it is sure and asks
338
+ a person when it is not;
339
+ - 2.20 tools read from a service's own OpenAPI document, which an agent calls or an emulator plays,
340
+ an emulator that holds what a whole evaluation did so examples that build on each other are
341
+ evaluated with nothing sent, and one A2A handler serving many tenants, each seeing only its own.
334
342
 
335
343
  Upgrading from 1.x: `npx nexus migrate src --write` moves your imports, and
336
344
  [MIGRATING.md](https://github.com/mkhitar-abrahamyan/nexus-ai/blob/main/MIGRATING.md) covers the rest.
337
- Next, 2.19 reads a service's own API description into emulated tools, and lets an emulator hold
338
- what a whole evaluation did, so examples that build on each other are evaluated with nothing sent.
345
+ Next, 2.21 asks typed decisions about pictures, and gathers community adapters' compatibility
346
+ records from their own CI.
339
347
  Pinecone, images, the Gemini
340
348
  embedding batch tier, media understanding, video, Gemini Live, SIP, and both phone providers
341
349
  graduate once the live workflow passes against each. The
@@ -12,6 +12,9 @@ import type { ToolDefinition } from '../types/messages.js';
12
12
  * | `mcp.read:<server>/<tool>` | An MCP tool its server says only reads |
13
13
  * | `mcp.write:<server>/<tool>` | An MCP tool its server says changes things but destroys nothing |
14
14
  * | `mcp.destructive:<server>/<tool>` | An MCP tool its server says may destroy or overwrite |
15
+ * | `api.read:<api>/<operation>` | An operation of an OpenAPI document whose method only reads |
16
+ * | `api.write:<api>/<operation>` | One whose method changes things |
17
+ * | `api.destructive:<api>/<operation>` | One whose method deletes |
15
18
  * | `<name>`, `<name>:<detail>` | Anything the application names, such as `payments:refund` |
16
19
  *
17
20
  * A tool that declares `capabilities: []` does nothing to the world; one that declares none at all
@@ -0,0 +1,139 @@
1
+ /**
2
+ * Tools read from a service's own API description, an OpenAPI document: one tool per operation, its
3
+ * name, description, and parameters the service's, the capabilities it declares read from its method,
4
+ * and what it returns kept as a schema. Given where the API lives, each tool calls it; without, the
5
+ * tools describe the API and run nowhere, as `emulatedTools()` wants them.
6
+ */
7
+ import type { ToolContext, ToolDefinition } from '../types/messages.js';
8
+ /** An OpenAPI 3 document, as parsed JSON. Only what tools are read from is typed. */
9
+ export interface OpenApiDocument {
10
+ /** The OpenAPI version, `3.0.x` or `3.1.x`. */
11
+ openapi: string;
12
+ /** The API's title and version. */
13
+ info?: {
14
+ title?: string;
15
+ version?: string;
16
+ description?: string;
17
+ };
18
+ /** Where the API is served. */
19
+ servers?: Array<{
20
+ url: string;
21
+ variables?: Record<string, {
22
+ default: string;
23
+ }>;
24
+ }>;
25
+ /** Its operations, by path and method. */
26
+ paths?: Record<string, Record<string, unknown>>;
27
+ /** Schemas, parameters, request bodies, and responses its operations refer to. */
28
+ components?: Record<string, unknown>;
29
+ [key: string]: unknown;
30
+ }
31
+ /** One operation of the API, as a tool reads it. */
32
+ export interface OpenApiOperation {
33
+ /** The tool's name: the operation's id, or its method and path. */
34
+ name: string;
35
+ /** The HTTP method, in capitals. */
36
+ method: string;
37
+ /** The path, with its `{parameters}`. */
38
+ path: string;
39
+ /** The operation's id, when it has one. */
40
+ operationId?: string;
41
+ /** Its summary, when it has one. */
42
+ summary?: string;
43
+ /** Its tags. */
44
+ tags: string[];
45
+ /** What it does to the service, read from its method: `read` for GET, HEAD, OPTIONS, and TRACE, `destructive` for DELETE, and `write` for the rest. */
46
+ access: 'read' | 'write' | 'destructive';
47
+ }
48
+ /** What a tool's headers are chosen from: the operation, and the call's context. */
49
+ export interface OpenApiHeadersRequest {
50
+ /** The operation being called. */
51
+ operation: OpenApiOperation;
52
+ /** The call's context: its tenant, principal, and thread. */
53
+ context?: ToolContext;
54
+ }
55
+ /** Options for `openApiTools()`. */
56
+ export interface OpenApiToolsOptions {
57
+ /** The API's name, in each tool's capabilities. Defaults to its title, as a slug, or `api`. */
58
+ name?: string;
59
+ /**
60
+ * Where the API lives, its path prefix included, such as `https://shop.example.com/api`. Defaults
61
+ * to the document's first server, resolved against `documentUrl` when relative. Without one, the
62
+ * tools describe the API and run nowhere.
63
+ */
64
+ baseUrl?: string;
65
+ /** Where the document came from, to resolve a relative server URL against. */
66
+ documentUrl?: string;
67
+ /**
68
+ * Headers every call sends, such as authorization, or a function choosing them per operation and
69
+ * call, such as by its tenant. They win over a header parameter the model sets.
70
+ */
71
+ headers?: Readonly<Record<string, string>> | ((request: OpenApiHeadersRequest) => Record<string, string> | Promise<Record<string, string>>);
72
+ /** Which operations become tools. Defaults to every one. */
73
+ include?: (operation: OpenApiOperation) => boolean;
74
+ /** Put before every tool's name, with an underscore, so two APIs' operations stay apart. */
75
+ prefix?: string;
76
+ /** How long a call may take, in milliseconds. Defaults to 30 seconds. */
77
+ timeoutMs?: number;
78
+ /** The largest answer a call reads, in bytes; a larger one fails the call. Defaults to 1 MB. */
79
+ maxResponseBytes?: number;
80
+ /** Replaces the global `fetch`. */
81
+ fetch?: typeof globalThis.fetch;
82
+ }
83
+ /** An API's operations as tools, with what each returns. */
84
+ export interface OpenApiTools {
85
+ /** The API's name, as its tools' capabilities carry it. */
86
+ name: string;
87
+ /** Where the tools send their calls, when they run. */
88
+ baseUrl?: string;
89
+ /** One tool per operation. */
90
+ tools: ToolDefinition[];
91
+ /** The operations, in the tools' order. */
92
+ operations: OpenApiOperation[];
93
+ /** The JSON Schema of what each tool returns, by name: its first success response's. Pass it to `emulatedTools()` as `results`. */
94
+ results: Record<string, Record<string, unknown>>;
95
+ /** Operations that could not become tools, and why: a request body of a type the tools do not send. */
96
+ skipped: Array<{
97
+ method: string;
98
+ path: string;
99
+ reason: string;
100
+ }>;
101
+ }
102
+ /** Why an API could not be read into tools, or a call to it failed. */
103
+ export declare class OpenApiError extends Error {
104
+ /**
105
+ * `OPENAPI_INVALID` for a malformed document or call, `OPENAPI_UNSUPPORTED` for one these tools
106
+ * cannot read, such as Swagger 2.0 or a reference outside the document, and `OPENAPI_REQUEST`
107
+ * for a call the API refused or did not answer.
108
+ */
109
+ readonly code: 'OPENAPI_INVALID' | 'OPENAPI_UNSUPPORTED' | 'OPENAPI_REQUEST';
110
+ /** The HTTP status the API answered with, when it did. */
111
+ readonly status?: number | undefined;
112
+ constructor(message: string,
113
+ /**
114
+ * `OPENAPI_INVALID` for a malformed document or call, `OPENAPI_UNSUPPORTED` for one these tools
115
+ * cannot read, such as Swagger 2.0 or a reference outside the document, and `OPENAPI_REQUEST`
116
+ * for a call the API refused or did not answer.
117
+ */
118
+ code: 'OPENAPI_INVALID' | 'OPENAPI_UNSUPPORTED' | 'OPENAPI_REQUEST',
119
+ /** The HTTP status the API answered with, when it did. */
120
+ status?: number | undefined);
121
+ }
122
+ /**
123
+ * Reads an OpenAPI 3 document into tools, one per operation: named by its `operationId`, or its
124
+ * method and path; described by its summary; its path, query, and header parameters, and the fields
125
+ * of a JSON body, as the tool's parameters. Each declares `api.read`, `api.write`, or
126
+ * `api.destructive` with the API's name and its own, as its method says, and `network` for the
127
+ * API's host when it runs. References within the document are followed; one outside it is refused.
128
+ *
129
+ * ```ts
130
+ * const shop = openApiTools(JSON.parse(await readFile('shop.openapi.json', 'utf8')), {
131
+ * baseUrl: 'https://shop.example.com/api',
132
+ * headers: { authorization: `Bearer ${process.env.SHOP_TOKEN}` },
133
+ * });
134
+ * const agent = createAgent({ client: ai, tools: shop.tools });
135
+ * ```
136
+ */
137
+ export declare function openApiTools(document: OpenApiDocument | string, options?: OpenApiToolsOptions): OpenApiTools;
138
+ /** Fetches an OpenAPI document, as JSON, and reads it into tools, resolving its servers against where it came from. */
139
+ export declare function loadOpenApiTools(url: string, options?: OpenApiToolsOptions): Promise<OpenApiTools>;