@statelyai/agent 2.0.0-alpha.28 → 2.0.0-alpha.30

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 (80) hide show
  1. package/dist/ai-sdk.cjs +150 -27
  2. package/dist/ai-sdk.d.cts +59 -36
  3. package/dist/ai-sdk.d.mts +59 -36
  4. package/dist/ai-sdk.mjs +148 -24
  5. package/dist/{decision-RQ0iv0oZ.mjs → decision-BHkvuImD.mjs} +74 -8
  6. package/dist/{decision-CmM8-HHz.cjs → decision-CIb7ddIv.cjs} +113 -30
  7. package/dist/{text-logic-f5F5sCdc.cjs → event-log-BZRfBRd7.cjs} +814 -7
  8. package/dist/{text-logic-CIqHAmBi.mjs → event-log-DJCMHek_.mjs} +680 -4
  9. package/dist/{event-log-store-BIPOz-di.d.mts → event-log-store-CIIJohjj.d.mts} +90 -5
  10. package/dist/{event-log-store-2xzFmgr2.d.cts → event-log-store-CLAC9q2Y.d.cts} +90 -5
  11. package/dist/event-log-store-DZR4IIWe.cjs +95 -0
  12. package/dist/event-log-store-DsP6GCRh.mjs +84 -0
  13. package/dist/index.cjs +576 -58
  14. package/dist/index.d.cts +104 -510
  15. package/dist/index.d.mts +104 -510
  16. package/dist/index.mjs +547 -32
  17. package/dist/log.cjs +77 -20
  18. package/dist/log.d.cts +5 -5
  19. package/dist/log.d.mts +5 -5
  20. package/dist/log.mjs +58 -3
  21. package/dist/machines.cjs +1 -1
  22. package/dist/machines.d.cts +15 -15
  23. package/dist/machines.d.mts +15 -15
  24. package/dist/machines.mjs +1 -1
  25. package/dist/model-source-BCKg4qJ1.cjs +44 -0
  26. package/dist/model-source-BaHwJ1wK.mjs +39 -0
  27. package/dist/openai.cjs +11 -11
  28. package/dist/openai.d.cts +28 -26
  29. package/dist/openai.d.mts +28 -26
  30. package/dist/openai.mjs +3 -3
  31. package/dist/otel.cjs +5 -4
  32. package/dist/otel.d.cts +5 -7
  33. package/dist/otel.d.mts +5 -7
  34. package/dist/otel.mjs +5 -3
  35. package/dist/{run-agent-xNTxpt82.mjs → run-agent-BpHqkaZw.mjs} +181 -44
  36. package/dist/{run-agent-COXXc0RW.d.mts → run-agent-CAVt5R-r.d.mts} +95 -30
  37. package/dist/{run-agent-ByO-Bxyd.d.cts → run-agent-CTlMc3Jb.d.cts} +95 -30
  38. package/dist/{run-agent-Dmf8GV2d.cjs → run-agent-ctLCvNgL.cjs} +230 -88
  39. package/dist/{setup-agent-BuanDXeh.mjs → setup-agent-7rV_cujV.mjs} +15 -9
  40. package/dist/setup-agent-CGELn1qZ.d.mts +577 -0
  41. package/dist/setup-agent-CLPCkXsu.d.cts +577 -0
  42. package/dist/{setup-agent-DV4cTou-.cjs → setup-agent-DoUk7EdC.cjs} +31 -20
  43. package/dist/tanstack-ai.cjs +627 -0
  44. package/dist/tanstack-ai.d.cts +204 -0
  45. package/dist/tanstack-ai.d.mts +204 -0
  46. package/dist/tanstack-ai.mjs +618 -0
  47. package/dist/testing.cjs +204 -985
  48. package/dist/testing.d.cts +132 -347
  49. package/dist/testing.d.mts +132 -347
  50. package/dist/testing.mjs +191 -973
  51. package/dist/{text-logic-IjfYy9DP.d.cts → text-logic-BRYOPWvY.d.mts} +52 -12
  52. package/dist/{text-logic-D-czVPYp.d.mts → text-logic-DmciuVUQ.d.cts} +52 -12
  53. package/dist/{types-BgNbNKnJ.d.mts → types-Dp5_Ru4R.d.cts} +2 -2
  54. package/dist/{types-hR5f5YXa.d.cts → types-Dp5_Ru4R.d.mts} +2 -2
  55. package/dist/usage-BkM3z02Y.d.mts +17 -0
  56. package/dist/usage-Cm_ovz9V.d.cts +17 -0
  57. package/dist/{utils-_q7F-AZu.d.mts → utils-BnXdWih3.d.mts} +1 -2
  58. package/dist/{utils-o4YRdHJX.d.cts → utils-ebVpCYoF.d.cts} +1 -2
  59. package/dist/validate.cjs +239 -8
  60. package/dist/validate.d.cts +110 -3
  61. package/dist/validate.d.mts +110 -3
  62. package/dist/validate.mjs +238 -7
  63. package/dist/verify-COFWyprJ.mjs +1181 -0
  64. package/dist/verify-CVlsTZ-V.cjs +1222 -0
  65. package/dist/verify-Cn86rT8l.d.mts +414 -0
  66. package/dist/verify-Dzwd4Mvk.d.cts +414 -0
  67. package/package.json +44 -31
  68. package/readme.md +40 -28
  69. package/skills/add-evals/SKILL.md +129 -0
  70. package/skills/add-traces/SKILL.md +135 -0
  71. package/skills/generate-machine/SKILL.md +143 -69
  72. package/skills/graph-engineering/SKILL.md +33 -0
  73. package/skills/improve-machine/SKILL.md +241 -0
  74. package/skills/improve-machine/reference.md +101 -0
  75. package/skills/loop-to-machine/SKILL.md +183 -0
  76. package/skills/loop-to-machine/policy.md +158 -0
  77. package/dist/event-log-store-2pAFiWuc.mjs +0 -576
  78. package/dist/event-log-store-C-COhIXP.cjs +0 -702
  79. package/dist/usage-BdEjFuIi.mjs +0 -5
  80. package/dist/usage-efOQPdf_.cjs +0 -10
@@ -0,0 +1,204 @@
1
+ import { i as AgentToolChoice, n as AgentMessage, s as AgentTools, u as ChosenEvent } from "./types-Dp5_Ru4R.cjs";
2
+ import { N as AgentDecisionRequest, W as AgentEventDescriptor, c as AgentRequestExecutorInfo, f as AgentTextRequest, r as AgentFinishReason, t as AgentCallUsage } from "./text-logic-DmciuVUQ.cjs";
3
+ import { AnyStateMachine } from "xstate";
4
+ import { AnyTextAdapter, ModelMessage, StreamChunk, TokenUsage, Tool } from "@tanstack/ai";
5
+ import { TextActivityOptions } from "@tanstack/ai/adapters";
6
+ //#region src/tanstack-ai/index.d.ts
7
+ /**
8
+ * Maps `AgentTextRequest.messages`/`system`/`prompt` onto `chat()`'s
9
+ * `systemPrompts` and `messages`. TanStack AI's model messages have no
10
+ * `system` role — a provider adapter may forward one as a user turn — so every
11
+ * system message, and the request's `system`, becomes a system prompt.
12
+ */
13
+ export declare function toTanStackAiMessages(request: Pick<AgentTextRequest, "system" | "prompt"> & {
14
+ messages?: AgentMessage[];
15
+ }): {
16
+ systemPrompts: string[];
17
+ messages: ModelMessage[];
18
+ };
19
+ /**
20
+ * One TanStack AI tool per `AgentTools` entry. A tool with an `execute` (or a
21
+ * bare function) is a server tool `chat()` runs in its loop; a tool without one
22
+ * is a client tool, so the run stops at its call and hands the call back.
23
+ * Input schemas travel as JSON Schema.
24
+ */
25
+ export declare function toTanStackAiTools(tools: AgentTools): Tool[];
26
+ /** One client tool per candidate decision event: no `execute`, so the run
27
+ * stops at the model's first call — the "tool-per-event" recipe. */
28
+ export declare function toTanStackAiEventTools(events: AgentEventDescriptor[]): Tool[];
29
+ /** The generation settings a text and a decision request share. */
30
+ type GenerationSettings = Pick<AgentTextRequest, "temperature" | "maxOutputTokens" | "topP" | "topK" | "seed" | "stopSequences">;
31
+ /**
32
+ * Maps the request's portable generation settings and tool choice onto the
33
+ * `modelOptions` of the adapter's provider. TanStack AI has no portable
34
+ * sampling or tool-choice options — each provider adapter names its own — so
35
+ * the mapping is per provider (`adapter.name`):
36
+ *
37
+ * - `openai` (Responses API): `temperature`, `top_p`, `max_output_tokens`,
38
+ * `tool_choice`. The API has no `top_k`, `seed`, or `stop`; those are dropped.
39
+ * - `anthropic`: `temperature`, `top_p`, `top_k`, `max_tokens`,
40
+ * `stop_sequences`, `tool_choice`. `seed` is dropped.
41
+ * - `gemini`: `temperature`, `topP`, `topK`, `maxOutputTokens`, `seed`,
42
+ * `stopSequences`, `toolConfig.functionCallingConfig`.
43
+ *
44
+ * Any other provider gets none of them: map them yourself through the
45
+ * `settings` option, which receives the request.
46
+ */
47
+ export declare function toTanStackAiModelOptions(adapter: Pick<AnyTextAdapter, "name">, request: GenerationSettings & {
48
+ toolChoice?: AgentToolChoice;
49
+ }): Record<string, unknown>;
50
+ /**
51
+ * Messages for a decision request, with prior failed `attempts` rendered as
52
+ * appended user messages so retries converge. Mirrors the AI SDK adapter's
53
+ * `toDecisionMessages`.
54
+ */
55
+ export declare function toDecisionMessages(request: Pick<AgentDecisionRequest, "system" | "messages" | "prompt" | "events" | "attempts">): {
56
+ systemPrompts: string[];
57
+ messages: ModelMessage[];
58
+ };
59
+ /**
60
+ * Folds TanStack AI's `TokenUsage` onto the flat {@link AgentCallUsage} field
61
+ * names core aggregates. A field the provider omitted stays omitted, so it
62
+ * never contributes a `0` to a run's partial sums.
63
+ */
64
+ export declare function toAgentCallUsage(usage: TokenUsage | undefined): AgentCallUsage | undefined;
65
+ /**
66
+ * Maps a TanStack AI finish reason onto the portable {@link AgentFinishReason}.
67
+ * Anything unrecognized, including a missing reason, lands on `'other'`.
68
+ */
69
+ export declare function toAgentFinishReason(finishReason: string | null | undefined): AgentFinishReason;
70
+ /** A model's tool call, as read off the run's `TOOL_CALL_*` events. */
71
+ export type TanStackAiToolCall = {
72
+ toolCallId: string;
73
+ toolName: string;
74
+ input: unknown;
75
+ };
76
+ /**
77
+ * Per-call `chat()` options a host can apply on top of what the machine asked
78
+ * for — provider `modelOptions` (reasoning effort, …), `middleware`,
79
+ * `metadata`, `debug`, and anything else `chat()` accepts. Typed off the
80
+ * installed `@tanstack/ai`, so it tracks that version.
81
+ *
82
+ * The request's own fields are excluded: messages, system prompts, tools,
83
+ * output schema, streaming, cancellation, and the tool-loop bound belong to the
84
+ * machine and the adapter.
85
+ */
86
+ export type TanStackAiCallSettings = Omit<TextActivityOptions<AnyTextAdapter, undefined, boolean>, "adapter" | "messages" | "systemPrompts" | "tools" | "outputSchema" | "stream" | "abortController" | "agentLoopStrategy">;
87
+ /**
88
+ * One entry in a {@link TanStackAiModelMap}: a bare text adapter, or an adapter
89
+ * paired with the {@link TanStackAiCallSettings} that ref always runs with — how
90
+ * a host gives a ref a persona without the machine naming a provider knob.
91
+ */
92
+ export type TanStackAiModelEntry = AnyTextAdapter | {
93
+ adapter: AnyTextAdapter;
94
+ settings?: TanStackAiCallSettings;
95
+ };
96
+ /** Model registry: maps model refs (as used in `setupAgent({ models })`) to
97
+ * TanStack AI text adapters, or to `{ adapter, settings }` pairs. */
98
+ export type TanStackAiModelMap<TKey extends string = string> = Record<TKey, TanStackAiModelEntry>;
99
+ /**
100
+ * Options for {@link createTanStackAiExecutors}: a static `models` map, a
101
+ * `resolveModel` function (refs resolved dynamically), or both —
102
+ * `resolveModel` takes precedence when both are supplied.
103
+ *
104
+ * `settings` carries `chat()` options that are the HOST's business, such as
105
+ * provider `modelOptions`. Pass an object to apply it to every call, or a
106
+ * function to vary it per request (`request.name` is the request's registered
107
+ * key). Precedence is global `settings`, then the model entry's `settings`,
108
+ * then the request's own generation settings (see
109
+ * {@link toTanStackAiModelOptions}); `modelOptions` merge key by key.
110
+ */
111
+ export type CreateTanStackAiExecutorsOptions<TModels extends TanStackAiModelMap = TanStackAiModelMap> = {
112
+ settings?: TanStackAiCallSettings | ((request: AgentTextRequest | AgentDecisionRequest) => TanStackAiCallSettings | undefined);
113
+ } & ({
114
+ models: TModels;
115
+ resolveModel?: (modelRef: keyof TModels & string) => AnyTextAdapter;
116
+ } | {
117
+ models?: TModels;
118
+ resolveModel: (modelRef: string) => AnyTextAdapter;
119
+ });
120
+ /**
121
+ * Raw result shape from {@link TanStackAiExecutors.generateText} — `result`
122
+ * (the parsed structured object for structured-output requests, or the text
123
+ * otherwise) plus the run metadata. Core reads `result` and `usage`; everything
124
+ * else flows verbatim to `onResult(request, { raw })`.
125
+ */
126
+ export type TanStackAiGenerateResult = {
127
+ result: unknown;
128
+ /** The model's reasoning, present only when the request opted in via
129
+ * `includeReasoning` and the model produced it. */
130
+ reasoning?: string;
131
+ /** Token usage summed over every model turn of the run. */
132
+ usage?: AgentCallUsage;
133
+ /** Why the run stopped, normalized to the portable {@link AgentFinishReason}. */
134
+ finishReason: AgentFinishReason;
135
+ /** Every tool call the model made during the run. */
136
+ toolCalls: TanStackAiToolCall[];
137
+ /** The run's response messages — each turn's assistant text and tool
138
+ * calls, and the tool results fed back — ready to append to a
139
+ * conversation. */
140
+ messages: AgentMessage[];
141
+ /** Every chunk the run produced, in order. */
142
+ raw: StreamChunk[];
143
+ };
144
+ /** Raw result shape from {@link TanStackAiExecutors.streamText} — the
145
+ * accumulated text once the stream finishes (deltas are delivered via
146
+ * `onChunk`), plus the run's usage and finish reason. */
147
+ export type TanStackAiStreamResult = {
148
+ result: string;
149
+ usage?: AgentCallUsage;
150
+ finishReason: AgentFinishReason;
151
+ /** The run's response messages, as on {@link TanStackAiGenerateResult}. */
152
+ messages: AgentMessage[];
153
+ raw: StreamChunk[];
154
+ };
155
+ /** Raw result shape from {@link TanStackAiExecutors.decide} — the chosen event
156
+ * plus the call metadata, delivered per decision attempt to `onResult`. */
157
+ export type TanStackAiDecideResult = {
158
+ event: ChosenEvent;
159
+ usage?: AgentCallUsage;
160
+ finishReason: AgentFinishReason;
161
+ raw: StreamChunk[];
162
+ };
163
+ /** `createTanStackAiExecutors` always populates all three slots, and its
164
+ * results are concretely typed. */
165
+ export interface TanStackAiExecutors {
166
+ generateText: (request: AgentTextRequest & {
167
+ tools: AgentTools;
168
+ }, info?: AgentRequestExecutorInfo) => Promise<TanStackAiGenerateResult>;
169
+ streamText: (request: AgentTextRequest & {
170
+ tools: AgentTools;
171
+ }, info?: AgentRequestExecutorInfo) => Promise<TanStackAiStreamResult>;
172
+ decide: (request: AgentDecisionRequest, info?: AgentRequestExecutorInfo) => Promise<TanStackAiDecideResult>;
173
+ }
174
+ /** The text adapter inside a map entry, whichever form it takes. */
175
+ export declare function toTextAdapter(entry: TanStackAiModelEntry): AnyTextAdapter;
176
+ /**
177
+ * Builds the `{ generateText, streamText, decide }` executor set over TanStack
178
+ * AI's `chat()`. Compare `createAiSdkExecutors` — same shape, different SDK
179
+ * underneath.
180
+ *
181
+ * - Structured output uses `chat({ outputSchema })` around the
182
+ * `{ result, reasoning? }` provider output schema.
183
+ * - Tools run in `chat()`'s own loop, for `generateText` and `streamText`
184
+ * alike, bounded by the request's `maxSteps` (default 1). A tool with no
185
+ * `execute` stops the run at its call.
186
+ * - Decisions offer one tool per candidate event, with no `execute`, so the
187
+ * run stops at the model's first call; the tool choice is forced where the
188
+ * provider supports it (see {@link toTanStackAiModelOptions}).
189
+ *
190
+ * Pass the options object, or pass the machine (or its `setupAgent(...)`
191
+ * result) to reuse the `models` declared in `setupAgent({ models })`. Anything
192
+ * else throws here, at construction.
193
+ *
194
+ * @example
195
+ * ```ts
196
+ * import { openaiText } from '@tanstack/ai-openai';
197
+ *
198
+ * const executors = createTanStackAiExecutors({ models: { quick: openaiText('gpt-6-luna') } });
199
+ * const result = await runToQuiescence(createAgentRuntime(machine, { executors }), { input });
200
+ * ```
201
+ */
202
+ export declare function createTanStackAiExecutors<TModels extends TanStackAiModelMap>(options: CreateTanStackAiExecutorsOptions<TModels>): TanStackAiExecutors;
203
+ export declare function createTanStackAiExecutors(machine: AnyStateMachine): TanStackAiExecutors;
204
+ //#endregion
@@ -0,0 +1,204 @@
1
+ import { i as AgentToolChoice, n as AgentMessage, s as AgentTools, u as ChosenEvent } from "./types-Dp5_Ru4R.mjs";
2
+ import { N as AgentDecisionRequest, W as AgentEventDescriptor, c as AgentRequestExecutorInfo, f as AgentTextRequest, r as AgentFinishReason, t as AgentCallUsage } from "./text-logic-BRYOPWvY.mjs";
3
+ import { AnyStateMachine } from "xstate";
4
+ import { AnyTextAdapter, ModelMessage, StreamChunk, TokenUsage, Tool } from "@tanstack/ai";
5
+ import { TextActivityOptions } from "@tanstack/ai/adapters";
6
+ //#region src/tanstack-ai/index.d.ts
7
+ /**
8
+ * Maps `AgentTextRequest.messages`/`system`/`prompt` onto `chat()`'s
9
+ * `systemPrompts` and `messages`. TanStack AI's model messages have no
10
+ * `system` role — a provider adapter may forward one as a user turn — so every
11
+ * system message, and the request's `system`, becomes a system prompt.
12
+ */
13
+ export declare function toTanStackAiMessages(request: Pick<AgentTextRequest, "system" | "prompt"> & {
14
+ messages?: AgentMessage[];
15
+ }): {
16
+ systemPrompts: string[];
17
+ messages: ModelMessage[];
18
+ };
19
+ /**
20
+ * One TanStack AI tool per `AgentTools` entry. A tool with an `execute` (or a
21
+ * bare function) is a server tool `chat()` runs in its loop; a tool without one
22
+ * is a client tool, so the run stops at its call and hands the call back.
23
+ * Input schemas travel as JSON Schema.
24
+ */
25
+ export declare function toTanStackAiTools(tools: AgentTools): Tool[];
26
+ /** One client tool per candidate decision event: no `execute`, so the run
27
+ * stops at the model's first call — the "tool-per-event" recipe. */
28
+ export declare function toTanStackAiEventTools(events: AgentEventDescriptor[]): Tool[];
29
+ /** The generation settings a text and a decision request share. */
30
+ type GenerationSettings = Pick<AgentTextRequest, "temperature" | "maxOutputTokens" | "topP" | "topK" | "seed" | "stopSequences">;
31
+ /**
32
+ * Maps the request's portable generation settings and tool choice onto the
33
+ * `modelOptions` of the adapter's provider. TanStack AI has no portable
34
+ * sampling or tool-choice options — each provider adapter names its own — so
35
+ * the mapping is per provider (`adapter.name`):
36
+ *
37
+ * - `openai` (Responses API): `temperature`, `top_p`, `max_output_tokens`,
38
+ * `tool_choice`. The API has no `top_k`, `seed`, or `stop`; those are dropped.
39
+ * - `anthropic`: `temperature`, `top_p`, `top_k`, `max_tokens`,
40
+ * `stop_sequences`, `tool_choice`. `seed` is dropped.
41
+ * - `gemini`: `temperature`, `topP`, `topK`, `maxOutputTokens`, `seed`,
42
+ * `stopSequences`, `toolConfig.functionCallingConfig`.
43
+ *
44
+ * Any other provider gets none of them: map them yourself through the
45
+ * `settings` option, which receives the request.
46
+ */
47
+ export declare function toTanStackAiModelOptions(adapter: Pick<AnyTextAdapter, "name">, request: GenerationSettings & {
48
+ toolChoice?: AgentToolChoice;
49
+ }): Record<string, unknown>;
50
+ /**
51
+ * Messages for a decision request, with prior failed `attempts` rendered as
52
+ * appended user messages so retries converge. Mirrors the AI SDK adapter's
53
+ * `toDecisionMessages`.
54
+ */
55
+ export declare function toDecisionMessages(request: Pick<AgentDecisionRequest, "system" | "messages" | "prompt" | "events" | "attempts">): {
56
+ systemPrompts: string[];
57
+ messages: ModelMessage[];
58
+ };
59
+ /**
60
+ * Folds TanStack AI's `TokenUsage` onto the flat {@link AgentCallUsage} field
61
+ * names core aggregates. A field the provider omitted stays omitted, so it
62
+ * never contributes a `0` to a run's partial sums.
63
+ */
64
+ export declare function toAgentCallUsage(usage: TokenUsage | undefined): AgentCallUsage | undefined;
65
+ /**
66
+ * Maps a TanStack AI finish reason onto the portable {@link AgentFinishReason}.
67
+ * Anything unrecognized, including a missing reason, lands on `'other'`.
68
+ */
69
+ export declare function toAgentFinishReason(finishReason: string | null | undefined): AgentFinishReason;
70
+ /** A model's tool call, as read off the run's `TOOL_CALL_*` events. */
71
+ export type TanStackAiToolCall = {
72
+ toolCallId: string;
73
+ toolName: string;
74
+ input: unknown;
75
+ };
76
+ /**
77
+ * Per-call `chat()` options a host can apply on top of what the machine asked
78
+ * for — provider `modelOptions` (reasoning effort, …), `middleware`,
79
+ * `metadata`, `debug`, and anything else `chat()` accepts. Typed off the
80
+ * installed `@tanstack/ai`, so it tracks that version.
81
+ *
82
+ * The request's own fields are excluded: messages, system prompts, tools,
83
+ * output schema, streaming, cancellation, and the tool-loop bound belong to the
84
+ * machine and the adapter.
85
+ */
86
+ export type TanStackAiCallSettings = Omit<TextActivityOptions<AnyTextAdapter, undefined, boolean>, "adapter" | "messages" | "systemPrompts" | "tools" | "outputSchema" | "stream" | "abortController" | "agentLoopStrategy">;
87
+ /**
88
+ * One entry in a {@link TanStackAiModelMap}: a bare text adapter, or an adapter
89
+ * paired with the {@link TanStackAiCallSettings} that ref always runs with — how
90
+ * a host gives a ref a persona without the machine naming a provider knob.
91
+ */
92
+ export type TanStackAiModelEntry = AnyTextAdapter | {
93
+ adapter: AnyTextAdapter;
94
+ settings?: TanStackAiCallSettings;
95
+ };
96
+ /** Model registry: maps model refs (as used in `setupAgent({ models })`) to
97
+ * TanStack AI text adapters, or to `{ adapter, settings }` pairs. */
98
+ export type TanStackAiModelMap<TKey extends string = string> = Record<TKey, TanStackAiModelEntry>;
99
+ /**
100
+ * Options for {@link createTanStackAiExecutors}: a static `models` map, a
101
+ * `resolveModel` function (refs resolved dynamically), or both —
102
+ * `resolveModel` takes precedence when both are supplied.
103
+ *
104
+ * `settings` carries `chat()` options that are the HOST's business, such as
105
+ * provider `modelOptions`. Pass an object to apply it to every call, or a
106
+ * function to vary it per request (`request.name` is the request's registered
107
+ * key). Precedence is global `settings`, then the model entry's `settings`,
108
+ * then the request's own generation settings (see
109
+ * {@link toTanStackAiModelOptions}); `modelOptions` merge key by key.
110
+ */
111
+ export type CreateTanStackAiExecutorsOptions<TModels extends TanStackAiModelMap = TanStackAiModelMap> = {
112
+ settings?: TanStackAiCallSettings | ((request: AgentTextRequest | AgentDecisionRequest) => TanStackAiCallSettings | undefined);
113
+ } & ({
114
+ models: TModels;
115
+ resolveModel?: (modelRef: keyof TModels & string) => AnyTextAdapter;
116
+ } | {
117
+ models?: TModels;
118
+ resolveModel: (modelRef: string) => AnyTextAdapter;
119
+ });
120
+ /**
121
+ * Raw result shape from {@link TanStackAiExecutors.generateText} — `result`
122
+ * (the parsed structured object for structured-output requests, or the text
123
+ * otherwise) plus the run metadata. Core reads `result` and `usage`; everything
124
+ * else flows verbatim to `onResult(request, { raw })`.
125
+ */
126
+ export type TanStackAiGenerateResult = {
127
+ result: unknown;
128
+ /** The model's reasoning, present only when the request opted in via
129
+ * `includeReasoning` and the model produced it. */
130
+ reasoning?: string;
131
+ /** Token usage summed over every model turn of the run. */
132
+ usage?: AgentCallUsage;
133
+ /** Why the run stopped, normalized to the portable {@link AgentFinishReason}. */
134
+ finishReason: AgentFinishReason;
135
+ /** Every tool call the model made during the run. */
136
+ toolCalls: TanStackAiToolCall[];
137
+ /** The run's response messages — each turn's assistant text and tool
138
+ * calls, and the tool results fed back — ready to append to a
139
+ * conversation. */
140
+ messages: AgentMessage[];
141
+ /** Every chunk the run produced, in order. */
142
+ raw: StreamChunk[];
143
+ };
144
+ /** Raw result shape from {@link TanStackAiExecutors.streamText} — the
145
+ * accumulated text once the stream finishes (deltas are delivered via
146
+ * `onChunk`), plus the run's usage and finish reason. */
147
+ export type TanStackAiStreamResult = {
148
+ result: string;
149
+ usage?: AgentCallUsage;
150
+ finishReason: AgentFinishReason;
151
+ /** The run's response messages, as on {@link TanStackAiGenerateResult}. */
152
+ messages: AgentMessage[];
153
+ raw: StreamChunk[];
154
+ };
155
+ /** Raw result shape from {@link TanStackAiExecutors.decide} — the chosen event
156
+ * plus the call metadata, delivered per decision attempt to `onResult`. */
157
+ export type TanStackAiDecideResult = {
158
+ event: ChosenEvent;
159
+ usage?: AgentCallUsage;
160
+ finishReason: AgentFinishReason;
161
+ raw: StreamChunk[];
162
+ };
163
+ /** `createTanStackAiExecutors` always populates all three slots, and its
164
+ * results are concretely typed. */
165
+ export interface TanStackAiExecutors {
166
+ generateText: (request: AgentTextRequest & {
167
+ tools: AgentTools;
168
+ }, info?: AgentRequestExecutorInfo) => Promise<TanStackAiGenerateResult>;
169
+ streamText: (request: AgentTextRequest & {
170
+ tools: AgentTools;
171
+ }, info?: AgentRequestExecutorInfo) => Promise<TanStackAiStreamResult>;
172
+ decide: (request: AgentDecisionRequest, info?: AgentRequestExecutorInfo) => Promise<TanStackAiDecideResult>;
173
+ }
174
+ /** The text adapter inside a map entry, whichever form it takes. */
175
+ export declare function toTextAdapter(entry: TanStackAiModelEntry): AnyTextAdapter;
176
+ /**
177
+ * Builds the `{ generateText, streamText, decide }` executor set over TanStack
178
+ * AI's `chat()`. Compare `createAiSdkExecutors` — same shape, different SDK
179
+ * underneath.
180
+ *
181
+ * - Structured output uses `chat({ outputSchema })` around the
182
+ * `{ result, reasoning? }` provider output schema.
183
+ * - Tools run in `chat()`'s own loop, for `generateText` and `streamText`
184
+ * alike, bounded by the request's `maxSteps` (default 1). A tool with no
185
+ * `execute` stops the run at its call.
186
+ * - Decisions offer one tool per candidate event, with no `execute`, so the
187
+ * run stops at the model's first call; the tool choice is forced where the
188
+ * provider supports it (see {@link toTanStackAiModelOptions}).
189
+ *
190
+ * Pass the options object, or pass the machine (or its `setupAgent(...)`
191
+ * result) to reuse the `models` declared in `setupAgent({ models })`. Anything
192
+ * else throws here, at construction.
193
+ *
194
+ * @example
195
+ * ```ts
196
+ * import { openaiText } from '@tanstack/ai-openai';
197
+ *
198
+ * const executors = createTanStackAiExecutors({ models: { quick: openaiText('gpt-6-luna') } });
199
+ * const result = await runToQuiescence(createAgentRuntime(machine, { executors }), { input });
200
+ * ```
201
+ */
202
+ export declare function createTanStackAiExecutors<TModels extends TanStackAiModelMap>(options: CreateTanStackAiExecutorsOptions<TModels>): TanStackAiExecutors;
203
+ export declare function createTanStackAiExecutors(machine: AnyStateMachine): TanStackAiExecutors;
204
+ //#endregion