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

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 (75) hide show
  1. package/dist/ai-sdk.cjs +149 -26
  2. package/dist/ai-sdk.d.cts +57 -34
  3. package/dist/ai-sdk.d.mts +57 -34
  4. package/dist/ai-sdk.mjs +147 -23
  5. package/dist/{decision-RQ0iv0oZ.mjs → decision-Bl_rKQnU.mjs} +73 -7
  6. package/dist/{decision-CmM8-HHz.cjs → decision-oevZnkBe.cjs} +112 -29
  7. package/dist/{text-logic-f5F5sCdc.cjs → event-log-Dtb16p1p.cjs} +813 -6
  8. package/dist/{text-logic-CIqHAmBi.mjs → event-log-GPZO9p7_.mjs} +679 -3
  9. package/dist/{event-log-store-BIPOz-di.d.mts → event-log-store-CN9ygggF.d.cts} +90 -5
  10. package/dist/{event-log-store-2xzFmgr2.d.cts → event-log-store-DS836wch.d.mts} +90 -5
  11. package/dist/event-log-store-bCdskPNS.cjs +95 -0
  12. package/dist/event-log-store-yalq8C77.mjs +84 -0
  13. package/dist/index.cjs +571 -58
  14. package/dist/index.d.cts +104 -510
  15. package/dist/index.d.mts +104 -510
  16. package/dist/index.mjs +542 -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-C7FFP2Sj.mjs +39 -0
  26. package/dist/model-source-DjJPjGSP.cjs +44 -0
  27. package/dist/openai.cjs +10 -10
  28. package/dist/openai.d.cts +27 -25
  29. package/dist/openai.d.mts +27 -25
  30. package/dist/openai.mjs +2 -2
  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-COXXc0RW.d.mts → run-agent-C9ubX8Tx.d.cts} +87 -30
  36. package/dist/{run-agent-xNTxpt82.mjs → run-agent-CuQT1xSS.mjs} +170 -42
  37. package/dist/{run-agent-ByO-Bxyd.d.cts → run-agent-CxSyZmIE.d.mts} +87 -30
  38. package/dist/{run-agent-Dmf8GV2d.cjs → run-agent-cToZ3K42.cjs} +219 -86
  39. package/dist/{setup-agent-DV4cTou-.cjs → setup-agent-DTF3NQg3.cjs} +31 -20
  40. package/dist/setup-agent-DlbgwsIJ.d.cts +577 -0
  41. package/dist/{setup-agent-BuanDXeh.mjs → setup-agent-DniLvDu7.mjs} +15 -9
  42. package/dist/setup-agent-tsc3vm5I.d.mts +577 -0
  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 +98 -985
  48. package/dist/testing.d.cts +51 -347
  49. package/dist/testing.d.mts +51 -347
  50. package/dist/testing.mjs +86 -973
  51. package/dist/{text-logic-IjfYy9DP.d.cts → text-logic-9fv1i9aK.d.cts} +50 -10
  52. package/dist/{text-logic-D-czVPYp.d.mts → text-logic-BDbGjYMh.d.mts} +50 -10
  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-D8UphgEA.d.mts +17 -0
  56. package/dist/usage-R1NTmLxY.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-B5qGC5WN.mjs +1181 -0
  64. package/dist/verify-CBuYIpsa.d.mts +414 -0
  65. package/dist/verify-Cqghu4gz.cjs +1222 -0
  66. package/dist/verify-DYH_2VzU.d.cts +414 -0
  67. package/package.json +44 -31
  68. package/readme.md +38 -26
  69. package/skills/generate-machine/SKILL.md +140 -66
  70. package/skills/improve-machine/SKILL.md +190 -0
  71. package/skills/improve-machine/reference.md +96 -0
  72. package/dist/event-log-store-2pAFiWuc.mjs +0 -576
  73. package/dist/event-log-store-C-COhIXP.cjs +0 -702
  74. package/dist/usage-BdEjFuIi.mjs +0 -5
  75. package/dist/usage-efOQPdf_.cjs +0 -10
package/dist/openai.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_text_logic = require("./text-logic-f5F5sCdc.cjs");
3
- const require_decision = require("./decision-CmM8-HHz.cjs");
2
+ const require_event_log = require("./event-log-Dtb16p1p.cjs");
3
+ const require_decision = require("./decision-oevZnkBe.cjs");
4
4
  //#region src/openai/index.ts
5
5
  /** Thrown for a message part Chat Completions cannot carry — dropping it would
6
6
  * silently change what the model sees. */
@@ -146,7 +146,7 @@ function toOpenAiTools(tools) {
146
146
  function: {
147
147
  name,
148
148
  description: staticDescription(descriptor),
149
- parameters: (require_text_logic.isStandardSchema(inputSchema) ? require_text_logic.getJsonSchemaSync(inputSchema) : void 0) ?? {}
149
+ parameters: (require_event_log.isStandardSchema(inputSchema) ? require_event_log.getJsonSchemaSync(inputSchema) : void 0) ?? {}
150
150
  }
151
151
  }];
152
152
  });
@@ -172,7 +172,7 @@ function toOpenAiEventTools(events) {
172
172
  function: {
173
173
  name: event.toolName,
174
174
  description: `Choose the '${event.type}' move.`,
175
- parameters: require_text_logic.getJsonSchemaSync(event.inputSchema) ?? {}
175
+ parameters: require_event_log.getJsonSchemaSync(event.inputSchema) ?? {}
176
176
  }
177
177
  }));
178
178
  }
@@ -234,7 +234,7 @@ function callSettings(options, request) {
234
234
  return entry;
235
235
  }
236
236
  function truncated(request, info, partialOutput, cause) {
237
- return new require_text_logic.AgentTruncatedError(`createOpenAiExecutors: request '${request.name ?? "(unnamed)"}' hit the output token limit — its structured output never completed. Raise \`maxOutputTokens\`, shorten the input, or ask for a smaller output schema.`, {
237
+ return new require_event_log.AgentTruncatedError(`createOpenAiExecutors: request '${request.name ?? "(unnamed)"}' hit the output token limit — its structured output never completed. Raise \`maxOutputTokens\`, shorten the input, or ask for a smaller output schema.`, {
238
238
  requestName: request.name ?? "(unnamed)",
239
239
  ...info?.requestId !== void 0 ? { requestId: info.requestId } : {},
240
240
  ...partialOutput !== void 0 ? { partialOutput } : {},
@@ -253,7 +253,7 @@ function usageField(usage) {
253
253
  function addAgentCallUsage(total, next) {
254
254
  if (!total || !next) return total ?? next;
255
255
  const sum = {};
256
- for (const field of require_text_logic.AGENT_USAGE_TOKEN_FIELDS) if (total[field] !== void 0 || next[field] !== void 0) sum[field] = (total[field] ?? 0) + (next[field] ?? 0);
256
+ for (const field of require_event_log.AGENT_USAGE_TOKEN_FIELDS) if (total[field] !== void 0 || next[field] !== void 0) sum[field] = (total[field] ?? 0) + (next[field] ?? 0);
257
257
  return sum;
258
258
  }
259
259
  /**
@@ -303,8 +303,8 @@ function createOpenAiExecutors(options) {
303
303
  };
304
304
  };
305
305
  const structuredSchema = async (request) => {
306
- if (require_text_logic.getAgentOutputMode(request.outputSchema) !== "structured") return;
307
- return require_text_logic.getJsonSchema(require_text_logic.providerOutputSchema(request.outputSchema, { reasoning: request.includeReasoning }));
306
+ if (require_event_log.getAgentOutputMode(request.outputSchema) !== "structured") return;
307
+ return require_event_log.getJsonSchema(require_event_log.providerOutputSchema(request.outputSchema, { reasoning: request.includeReasoning }));
308
308
  };
309
309
  const generateText = async (request, info) => {
310
310
  const jsonSchema = await structuredSchema(request);
@@ -350,7 +350,7 @@ function createOpenAiExecutors(options) {
350
350
  });
351
351
  }
352
352
  }
353
- const unwrap = (content) => require_text_logic.parseProviderOutput(request, content ? JSON.parse(content) : void 0);
353
+ const unwrap = (content) => require_event_log.parseProviderOutput(request, content ? JSON.parse(content) : void 0);
354
354
  const choice = response.choices[0];
355
355
  const finishReason = toAgentFinishReason(choice?.finish_reason);
356
356
  const content = choice?.message.content;
@@ -373,7 +373,7 @@ function createOpenAiExecutors(options) {
373
373
  };
374
374
  };
375
375
  const streamText = async (request, info) => {
376
- if (require_text_logic.getAgentOutputMode(request.outputSchema) === "structured") throw new Error("createOpenAiExecutors: streamText is text-only — a request declaring a structured output schema must be routed to generateText.");
376
+ if (require_event_log.getAgentOutputMode(request.outputSchema) === "structured") throw new Error("createOpenAiExecutors: streamText is text-only — a request declaring a structured output schema must be routed to generateText.");
377
377
  if (Object.keys(request.tools ?? {}).length > 0) throw new Error("createOpenAiExecutors: streamText is text-only — a request declaring tools must be routed to generateText.");
378
378
  const stream = await client.chat.completions.create({
379
379
  model: resolveModel(request.model),
package/dist/openai.d.cts CHANGED
@@ -1,11 +1,10 @@
1
- import { i as AgentToolChoice, n as AgentMessage, s as AgentTools, u as ChosenEvent } from "./types-hR5f5YXa.cjs";
2
- import { M as AgentDecisionRequest, U as AgentEventDescriptor, c as AgentRequestExecutorInfo, f as AgentTextRequest, r as AgentFinishReason, t as AgentCallUsage } from "./text-logic-IjfYy9DP.cjs";
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-9fv1i9aK.cjs";
3
3
  import OpenAI from "openai";
4
4
  import { ChatCompletion, ChatCompletionCreateParamsNonStreaming, ChatCompletionMessageParam, ChatCompletionTool } from "openai/resources/chat/completions/completions.js";
5
-
6
5
  //#region src/openai/index.d.ts
7
6
  /** Maps `AgentTextRequest.messages`/`system`/`prompt` to OpenAI chat messages. */
8
- declare function toOpenAiMessages(request: Pick<AgentTextRequest, "system" | "prompt"> & {
7
+ export declare function toOpenAiMessages(request: Pick<AgentTextRequest, "system" | "prompt"> & {
9
8
  messages?: AgentMessage[];
10
9
  }): ChatCompletionMessageParam[];
11
10
  /**
@@ -20,7 +19,7 @@ declare function toOpenAiMessages(request: Pick<AgentTextRequest, "system" | "pr
20
19
  * that's what `maxOutputTokens` targets. Chat Completions has no `top_k`
21
20
  * parameter, so `topK` is dropped.
22
21
  */
23
- declare function toOpenAiCallSettings(request: Pick<AgentTextRequest, "temperature" | "maxOutputTokens" | "topP" | "seed" | "stopSequences">): Partial<{
22
+ export declare function toOpenAiCallSettings(request: Pick<AgentTextRequest, "temperature" | "maxOutputTokens" | "topP" | "seed" | "stopSequences">): Partial<{
24
23
  temperature: number | undefined;
25
24
  max_completion_tokens: number | undefined;
26
25
  top_p: number | undefined;
@@ -28,14 +27,14 @@ declare function toOpenAiCallSettings(request: Pick<AgentTextRequest, "temperatu
28
27
  stop: string[] | undefined;
29
28
  }>;
30
29
  /** One OpenAI function tool per `AgentTools` entry. */
31
- declare function toOpenAiTools(tools: AgentTools): ChatCompletionTool[];
30
+ export declare function toOpenAiTools(tools: AgentTools): ChatCompletionTool[];
32
31
  /**
33
32
  * Maps an {@link AgentToolChoice} onto OpenAI's `tool_choice` —
34
33
  * `{ type: 'tool', name }` becomes `{ type: 'function', function: { name } }`;
35
34
  * `'auto'`/`'none'`/`'required'` are OpenAI's own vocabulary and pass through.
36
35
  * `undefined` stays `undefined`, so the key is omitted.
37
36
  */
38
- declare function toOpenAiToolChoice(toolChoice: AgentToolChoice | undefined): "auto" | "none" | "required" | {
37
+ export declare function toOpenAiToolChoice(toolChoice: AgentToolChoice | undefined): "auto" | "none" | "required" | {
39
38
  type: "function";
40
39
  function: {
41
40
  name: string;
@@ -43,13 +42,13 @@ declare function toOpenAiToolChoice(toolChoice: AgentToolChoice | undefined): "a
43
42
  } | undefined;
44
43
  /** One OpenAI function tool per candidate decision event — the "tool-per-event
45
44
  * + tool_choice: 'required'" recipe, mirroring `toAiSdkEventTools`. */
46
- declare function toOpenAiEventTools(events: AgentEventDescriptor[]): ChatCompletionTool[];
45
+ export declare function toOpenAiEventTools(events: AgentEventDescriptor[]): ChatCompletionTool[];
47
46
  /**
48
47
  * Messages for a decision request, with prior failed `attempts` rendered as an
49
48
  * appended user message so retries converge. Mirrors the AI SDK adapter's
50
49
  * `toDecisionMessages`.
51
50
  */
52
- declare function toDecisionMessages(request: Pick<AgentDecisionRequest, "messages" | "prompt" | "events" | "attempts">): ChatCompletionMessageParam[];
51
+ export declare function toDecisionMessages(request: Pick<AgentDecisionRequest, "messages" | "prompt" | "events" | "attempts">): ChatCompletionMessageParam[];
53
52
  type OpenAiUsage = NonNullable<ChatCompletion["usage"]>;
54
53
  /**
55
54
  * Folds OpenAI's usage payload onto the flat {@link AgentCallUsage} field names
@@ -58,14 +57,14 @@ type OpenAiUsage = NonNullable<ChatCompletion["usage"]>;
58
57
  * `prompt_tokens_details`; a field the response omitted stays omitted, so it
59
58
  * never contributes a `0` to a run's partial sums.
60
59
  */
61
- declare function toAgentCallUsage(usage: OpenAiUsage | undefined): AgentCallUsage | undefined;
60
+ export declare function toAgentCallUsage(usage: OpenAiUsage | undefined): AgentCallUsage | undefined;
62
61
  /**
63
62
  * Maps an OpenAI `finish_reason` onto the portable {@link AgentFinishReason}.
64
63
  * `'function_call'` (the deprecated legacy path) joins `'tool_calls'` under
65
64
  * `'tool-calls'`; anything unrecognized, including a missing reason, lands on
66
65
  * `'other'`. OpenAI's own string stays on the result's `raw`.
67
66
  */
68
- declare function toAgentFinishReason(finishReason: ChatCompletion.Choice["finish_reason"] | null | undefined): AgentFinishReason;
67
+ export declare function toAgentFinishReason(finishReason: ChatCompletion.Choice["finish_reason"] | null | undefined): AgentFinishReason;
69
68
  /**
70
69
  * Per-call OpenAI Chat Completions parameters a host can apply on top of what
71
70
  * the machine asked for — `reasoning_effort`, `service_tier`,
@@ -78,7 +77,7 @@ declare function toAgentFinishReason(finishReason: ChatCompletion.Choice["finish
78
77
  * the machine and the adapter, and a host override would silently contradict
79
78
  * them.
80
79
  */
81
- type OpenAiCallSettings = Omit<Partial<ChatCompletionCreateParamsNonStreaming>, "model" | "messages" | "tools" | "tool_choice" | "response_format" | "n" | "stream">;
80
+ export type OpenAiCallSettings = Omit<Partial<ChatCompletionCreateParamsNonStreaming>, "model" | "messages" | "tools" | "tool_choice" | "response_format" | "n" | "stream">;
82
81
  /**
83
82
  * Options for {@link createOpenAiExecutors}.
84
83
  *
@@ -98,7 +97,7 @@ type OpenAiCallSettings = Omit<Partial<ChatCompletionCreateParamsNonStreaming>,
98
97
  * defaults). Settings are merged UNDER what the request declared, so a machine
99
98
  * that set `maxOutputTokens` still wins.
100
99
  */
101
- type CreateOpenAiExecutorsOptions = {
100
+ export type CreateOpenAiExecutorsOptions = {
102
101
  client: OpenAI;
103
102
  resolveModel?: (modelRef: string) => string;
104
103
  settings?: Record<string, OpenAiCallSettings> | ((request: AgentTextRequest | AgentDecisionRequest) => OpenAiCallSettings | undefined);
@@ -109,7 +108,7 @@ type CreateOpenAiExecutorsOptions = {
109
108
  * text otherwise) plus the call metadata. Core reads `result` and `usage`;
110
109
  * everything else flows verbatim to `createAgentRuntime`'s `onResult(request, { raw })`.
111
110
  */
112
- type OpenAiGenerateResult = {
111
+ export type OpenAiGenerateResult = {
113
112
  result: unknown;
114
113
  /** The model's reasoning, present only when the request opted in via
115
114
  * `includeReasoning` and the model produced it. Never enters machine
@@ -117,19 +116,23 @@ type OpenAiGenerateResult = {
117
116
  reasoning?: string;
118
117
  /** The call's token usage, on the flat field names the runtime folds into the
119
118
  * run result's aggregated `AgentUsage`. Absent when OpenAI reported none. */
120
- usage?: AgentCallUsage; /** Why the call stopped, normalized to the portable {@link AgentFinishReason}. OpenAI's own value stays on `raw`. */
121
- finishReason: AgentFinishReason; /** The untouched OpenAI response. */
119
+ usage?: AgentCallUsage;
120
+ /** Why the call stopped, normalized to the portable {@link AgentFinishReason}. OpenAI's own value stays on `raw`. */
121
+ finishReason: AgentFinishReason;
122
+ /** The untouched OpenAI response. */
122
123
  raw: unknown;
123
124
  };
124
125
  /** Raw result shape from {@link OpenAiExecutors.streamText} — the accumulated text once the stream finishes (chunks are delivered separately via `onChunk`), plus the stream's final usage/finish metadata. */
125
- type OpenAiStreamResult = {
126
- result: string; /** Present when the stream carried a usage chunk (the adapter asks for one via `stream_options`). */
126
+ export type OpenAiStreamResult = {
127
+ result: string;
128
+ /** Present when the stream carried a usage chunk (the adapter asks for one via `stream_options`). */
127
129
  usage?: AgentCallUsage;
128
- finishReason: AgentFinishReason; /** The last chunk seen, which carries the stream's finish metadata. */
130
+ finishReason: AgentFinishReason;
131
+ /** The last chunk seen, which carries the stream's finish metadata. */
129
132
  raw: unknown;
130
133
  };
131
134
  /** Raw result shape from {@link OpenAiExecutors.decide} — the chosen event plus the call metadata, delivered per decision attempt to `onResult`. */
132
- type OpenAiDecideResult = {
135
+ export type OpenAiDecideResult = {
133
136
  event: ChosenEvent;
134
137
  usage?: AgentCallUsage;
135
138
  finishReason: AgentFinishReason;
@@ -138,7 +141,7 @@ type OpenAiDecideResult = {
138
141
  /** `createOpenAiExecutors` always populates all three slots (unlike the general
139
142
  * `AgentRequestExecutors`, where `streamText`/`decide` are optional), and its
140
143
  * results are concretely typed. */
141
- interface OpenAiExecutors {
144
+ export interface OpenAiExecutors {
142
145
  generateText: (request: AgentTextRequest & {
143
146
  tools: AgentTools;
144
147
  }, info?: AgentRequestExecutorInfo) => Promise<OpenAiGenerateResult>;
@@ -153,7 +156,7 @@ interface OpenAiExecutors {
153
156
  * the run's totals, so the steps' usages have to be summed here or the run
154
157
  * undercounts. A field neither call reported stays absent.
155
158
  */
156
- declare function addAgentCallUsage(total: AgentCallUsage | undefined, next: AgentCallUsage | undefined): AgentCallUsage | undefined;
159
+ export declare function addAgentCallUsage(total: AgentCallUsage | undefined, next: AgentCallUsage | undefined): AgentCallUsage | undefined;
157
160
  /**
158
161
  * Builds the `{ generateText, streamText, decide }` executor set for the raw
159
162
  * `openai` package's Chat Completions API. Compare `createAiSdkExecutors` —
@@ -172,6 +175,5 @@ declare function addAgentCallUsage(total: AgentCallUsage | undefined, next: Agen
172
175
  * const result = await runToQuiescence(createAgentRuntime(machine, { executors }), { input });
173
176
  * ```
174
177
  */
175
- declare function createOpenAiExecutors(options: CreateOpenAiExecutorsOptions): OpenAiExecutors;
176
- //#endregion
177
- export { CreateOpenAiExecutorsOptions, OpenAiCallSettings, OpenAiDecideResult, OpenAiExecutors, OpenAiGenerateResult, OpenAiStreamResult, addAgentCallUsage, createOpenAiExecutors, toAgentCallUsage, toAgentFinishReason, toDecisionMessages, toOpenAiCallSettings, toOpenAiEventTools, toOpenAiMessages, toOpenAiToolChoice, toOpenAiTools };
178
+ export declare function createOpenAiExecutors(options: CreateOpenAiExecutorsOptions): OpenAiExecutors;
179
+ //#endregion
package/dist/openai.d.mts CHANGED
@@ -1,11 +1,10 @@
1
- import { i as AgentToolChoice, n as AgentMessage, s as AgentTools, u as ChosenEvent } from "./types-BgNbNKnJ.mjs";
2
- import { M as AgentDecisionRequest, U as AgentEventDescriptor, c as AgentRequestExecutorInfo, f as AgentTextRequest, r as AgentFinishReason, t as AgentCallUsage } from "./text-logic-D-czVPYp.mjs";
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-BDbGjYMh.mjs";
3
3
  import OpenAI from "openai";
4
4
  import { ChatCompletion, ChatCompletionCreateParamsNonStreaming, ChatCompletionMessageParam, ChatCompletionTool } from "openai/resources/chat/completions/completions.js";
5
-
6
5
  //#region src/openai/index.d.ts
7
6
  /** Maps `AgentTextRequest.messages`/`system`/`prompt` to OpenAI chat messages. */
8
- declare function toOpenAiMessages(request: Pick<AgentTextRequest, "system" | "prompt"> & {
7
+ export declare function toOpenAiMessages(request: Pick<AgentTextRequest, "system" | "prompt"> & {
9
8
  messages?: AgentMessage[];
10
9
  }): ChatCompletionMessageParam[];
11
10
  /**
@@ -20,7 +19,7 @@ declare function toOpenAiMessages(request: Pick<AgentTextRequest, "system" | "pr
20
19
  * that's what `maxOutputTokens` targets. Chat Completions has no `top_k`
21
20
  * parameter, so `topK` is dropped.
22
21
  */
23
- declare function toOpenAiCallSettings(request: Pick<AgentTextRequest, "temperature" | "maxOutputTokens" | "topP" | "seed" | "stopSequences">): Partial<{
22
+ export declare function toOpenAiCallSettings(request: Pick<AgentTextRequest, "temperature" | "maxOutputTokens" | "topP" | "seed" | "stopSequences">): Partial<{
24
23
  temperature: number | undefined;
25
24
  max_completion_tokens: number | undefined;
26
25
  top_p: number | undefined;
@@ -28,14 +27,14 @@ declare function toOpenAiCallSettings(request: Pick<AgentTextRequest, "temperatu
28
27
  stop: string[] | undefined;
29
28
  }>;
30
29
  /** One OpenAI function tool per `AgentTools` entry. */
31
- declare function toOpenAiTools(tools: AgentTools): ChatCompletionTool[];
30
+ export declare function toOpenAiTools(tools: AgentTools): ChatCompletionTool[];
32
31
  /**
33
32
  * Maps an {@link AgentToolChoice} onto OpenAI's `tool_choice` —
34
33
  * `{ type: 'tool', name }` becomes `{ type: 'function', function: { name } }`;
35
34
  * `'auto'`/`'none'`/`'required'` are OpenAI's own vocabulary and pass through.
36
35
  * `undefined` stays `undefined`, so the key is omitted.
37
36
  */
38
- declare function toOpenAiToolChoice(toolChoice: AgentToolChoice | undefined): "auto" | "none" | "required" | {
37
+ export declare function toOpenAiToolChoice(toolChoice: AgentToolChoice | undefined): "auto" | "none" | "required" | {
39
38
  type: "function";
40
39
  function: {
41
40
  name: string;
@@ -43,13 +42,13 @@ declare function toOpenAiToolChoice(toolChoice: AgentToolChoice | undefined): "a
43
42
  } | undefined;
44
43
  /** One OpenAI function tool per candidate decision event — the "tool-per-event
45
44
  * + tool_choice: 'required'" recipe, mirroring `toAiSdkEventTools`. */
46
- declare function toOpenAiEventTools(events: AgentEventDescriptor[]): ChatCompletionTool[];
45
+ export declare function toOpenAiEventTools(events: AgentEventDescriptor[]): ChatCompletionTool[];
47
46
  /**
48
47
  * Messages for a decision request, with prior failed `attempts` rendered as an
49
48
  * appended user message so retries converge. Mirrors the AI SDK adapter's
50
49
  * `toDecisionMessages`.
51
50
  */
52
- declare function toDecisionMessages(request: Pick<AgentDecisionRequest, "messages" | "prompt" | "events" | "attempts">): ChatCompletionMessageParam[];
51
+ export declare function toDecisionMessages(request: Pick<AgentDecisionRequest, "messages" | "prompt" | "events" | "attempts">): ChatCompletionMessageParam[];
53
52
  type OpenAiUsage = NonNullable<ChatCompletion["usage"]>;
54
53
  /**
55
54
  * Folds OpenAI's usage payload onto the flat {@link AgentCallUsage} field names
@@ -58,14 +57,14 @@ type OpenAiUsage = NonNullable<ChatCompletion["usage"]>;
58
57
  * `prompt_tokens_details`; a field the response omitted stays omitted, so it
59
58
  * never contributes a `0` to a run's partial sums.
60
59
  */
61
- declare function toAgentCallUsage(usage: OpenAiUsage | undefined): AgentCallUsage | undefined;
60
+ export declare function toAgentCallUsage(usage: OpenAiUsage | undefined): AgentCallUsage | undefined;
62
61
  /**
63
62
  * Maps an OpenAI `finish_reason` onto the portable {@link AgentFinishReason}.
64
63
  * `'function_call'` (the deprecated legacy path) joins `'tool_calls'` under
65
64
  * `'tool-calls'`; anything unrecognized, including a missing reason, lands on
66
65
  * `'other'`. OpenAI's own string stays on the result's `raw`.
67
66
  */
68
- declare function toAgentFinishReason(finishReason: ChatCompletion.Choice["finish_reason"] | null | undefined): AgentFinishReason;
67
+ export declare function toAgentFinishReason(finishReason: ChatCompletion.Choice["finish_reason"] | null | undefined): AgentFinishReason;
69
68
  /**
70
69
  * Per-call OpenAI Chat Completions parameters a host can apply on top of what
71
70
  * the machine asked for — `reasoning_effort`, `service_tier`,
@@ -78,7 +77,7 @@ declare function toAgentFinishReason(finishReason: ChatCompletion.Choice["finish
78
77
  * the machine and the adapter, and a host override would silently contradict
79
78
  * them.
80
79
  */
81
- type OpenAiCallSettings = Omit<Partial<ChatCompletionCreateParamsNonStreaming>, "model" | "messages" | "tools" | "tool_choice" | "response_format" | "n" | "stream">;
80
+ export type OpenAiCallSettings = Omit<Partial<ChatCompletionCreateParamsNonStreaming>, "model" | "messages" | "tools" | "tool_choice" | "response_format" | "n" | "stream">;
82
81
  /**
83
82
  * Options for {@link createOpenAiExecutors}.
84
83
  *
@@ -98,7 +97,7 @@ type OpenAiCallSettings = Omit<Partial<ChatCompletionCreateParamsNonStreaming>,
98
97
  * defaults). Settings are merged UNDER what the request declared, so a machine
99
98
  * that set `maxOutputTokens` still wins.
100
99
  */
101
- type CreateOpenAiExecutorsOptions = {
100
+ export type CreateOpenAiExecutorsOptions = {
102
101
  client: OpenAI;
103
102
  resolveModel?: (modelRef: string) => string;
104
103
  settings?: Record<string, OpenAiCallSettings> | ((request: AgentTextRequest | AgentDecisionRequest) => OpenAiCallSettings | undefined);
@@ -109,7 +108,7 @@ type CreateOpenAiExecutorsOptions = {
109
108
  * text otherwise) plus the call metadata. Core reads `result` and `usage`;
110
109
  * everything else flows verbatim to `createAgentRuntime`'s `onResult(request, { raw })`.
111
110
  */
112
- type OpenAiGenerateResult = {
111
+ export type OpenAiGenerateResult = {
113
112
  result: unknown;
114
113
  /** The model's reasoning, present only when the request opted in via
115
114
  * `includeReasoning` and the model produced it. Never enters machine
@@ -117,19 +116,23 @@ type OpenAiGenerateResult = {
117
116
  reasoning?: string;
118
117
  /** The call's token usage, on the flat field names the runtime folds into the
119
118
  * run result's aggregated `AgentUsage`. Absent when OpenAI reported none. */
120
- usage?: AgentCallUsage; /** Why the call stopped, normalized to the portable {@link AgentFinishReason}. OpenAI's own value stays on `raw`. */
121
- finishReason: AgentFinishReason; /** The untouched OpenAI response. */
119
+ usage?: AgentCallUsage;
120
+ /** Why the call stopped, normalized to the portable {@link AgentFinishReason}. OpenAI's own value stays on `raw`. */
121
+ finishReason: AgentFinishReason;
122
+ /** The untouched OpenAI response. */
122
123
  raw: unknown;
123
124
  };
124
125
  /** Raw result shape from {@link OpenAiExecutors.streamText} — the accumulated text once the stream finishes (chunks are delivered separately via `onChunk`), plus the stream's final usage/finish metadata. */
125
- type OpenAiStreamResult = {
126
- result: string; /** Present when the stream carried a usage chunk (the adapter asks for one via `stream_options`). */
126
+ export type OpenAiStreamResult = {
127
+ result: string;
128
+ /** Present when the stream carried a usage chunk (the adapter asks for one via `stream_options`). */
127
129
  usage?: AgentCallUsage;
128
- finishReason: AgentFinishReason; /** The last chunk seen, which carries the stream's finish metadata. */
130
+ finishReason: AgentFinishReason;
131
+ /** The last chunk seen, which carries the stream's finish metadata. */
129
132
  raw: unknown;
130
133
  };
131
134
  /** Raw result shape from {@link OpenAiExecutors.decide} — the chosen event plus the call metadata, delivered per decision attempt to `onResult`. */
132
- type OpenAiDecideResult = {
135
+ export type OpenAiDecideResult = {
133
136
  event: ChosenEvent;
134
137
  usage?: AgentCallUsage;
135
138
  finishReason: AgentFinishReason;
@@ -138,7 +141,7 @@ type OpenAiDecideResult = {
138
141
  /** `createOpenAiExecutors` always populates all three slots (unlike the general
139
142
  * `AgentRequestExecutors`, where `streamText`/`decide` are optional), and its
140
143
  * results are concretely typed. */
141
- interface OpenAiExecutors {
144
+ export interface OpenAiExecutors {
142
145
  generateText: (request: AgentTextRequest & {
143
146
  tools: AgentTools;
144
147
  }, info?: AgentRequestExecutorInfo) => Promise<OpenAiGenerateResult>;
@@ -153,7 +156,7 @@ interface OpenAiExecutors {
153
156
  * the run's totals, so the steps' usages have to be summed here or the run
154
157
  * undercounts. A field neither call reported stays absent.
155
158
  */
156
- declare function addAgentCallUsage(total: AgentCallUsage | undefined, next: AgentCallUsage | undefined): AgentCallUsage | undefined;
159
+ export declare function addAgentCallUsage(total: AgentCallUsage | undefined, next: AgentCallUsage | undefined): AgentCallUsage | undefined;
157
160
  /**
158
161
  * Builds the `{ generateText, streamText, decide }` executor set for the raw
159
162
  * `openai` package's Chat Completions API. Compare `createAiSdkExecutors` —
@@ -172,6 +175,5 @@ declare function addAgentCallUsage(total: AgentCallUsage | undefined, next: Agen
172
175
  * const result = await runToQuiescence(createAgentRuntime(machine, { executors }), { input });
173
176
  * ```
174
177
  */
175
- declare function createOpenAiExecutors(options: CreateOpenAiExecutorsOptions): OpenAiExecutors;
176
- //#endregion
177
- export { CreateOpenAiExecutorsOptions, OpenAiCallSettings, OpenAiDecideResult, OpenAiExecutors, OpenAiGenerateResult, OpenAiStreamResult, addAgentCallUsage, createOpenAiExecutors, toAgentCallUsage, toAgentFinishReason, toDecisionMessages, toOpenAiCallSettings, toOpenAiEventTools, toOpenAiMessages, toOpenAiToolChoice, toOpenAiTools };
178
+ export declare function createOpenAiExecutors(options: CreateOpenAiExecutorsOptions): OpenAiExecutors;
179
+ //#endregion
package/dist/openai.mjs CHANGED
@@ -1,5 +1,5 @@
1
- import { B as AgentTruncatedError, D as getJsonSchema, N as isStandardSchema, O as getJsonSchemaSync, c as getAgentOutputMode, h as providerOutputSchema, m as parseProviderOutput, t as AGENT_USAGE_TOKEN_FIELDS } from "./text-logic-CIqHAmBi.mjs";
2
- import { o as renderDecisionAttempts } from "./decision-RQ0iv0oZ.mjs";
1
+ import { L as parseProviderOutput, R as providerOutputSchema, X as getJsonSchemaSync, Y as getJsonSchema, ct as AgentTruncatedError, j as getAgentOutputMode, tt as isStandardSchema, w as AGENT_USAGE_TOKEN_FIELDS } from "./event-log-GPZO9p7_.mjs";
2
+ import { c as renderDecisionAttempts } from "./decision-Bl_rKQnU.mjs";
3
3
  //#region src/openai/index.ts
4
4
  /** Thrown for a message part Chat Completions cannot carry — dropping it would
5
5
  * silently change what the model sees. */
package/dist/otel.cjs CHANGED
@@ -1,5 +1,4 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- require("./validate.cjs");
3
2
  let _opentelemetry_api = require("@opentelemetry/api");
4
3
  //#region src/otel/index.ts
5
4
  /**
@@ -210,12 +209,14 @@ function createOtelTraceHandler(options) {
210
209
  });
211
210
  });
212
211
  break;
213
- case "machine.transition":
214
- addRunEvent(event, "agent.transition", {
212
+ case "machine.transition": {
213
+ const attributes = {
215
214
  "agent.event_type": event.event.type,
216
215
  "agent.state": toJson(event.snapshot.value) ?? ""
217
- });
216
+ };
217
+ addRunEvent(event, "agent.transition", attributes);
218
218
  break;
219
+ }
219
220
  case "emit":
220
221
  addRunEvent(event, "agent.emit", { "agent.event_type": event.event.type });
221
222
  break;
package/dist/otel.d.cts CHANGED
@@ -1,9 +1,8 @@
1
- import { h as AgentTraceEvent } from "./run-agent-ByO-Bxyd.cjs";
1
+ import { g as AgentTraceEvent } from "./run-agent-C9ubX8Tx.cjs";
2
2
  import { Attributes, Tracer, TracerProvider } from "@opentelemetry/api";
3
-
4
3
  //#region src/otel/index.d.ts
5
4
  /** Options for {@link createOtelTraceHandler}. */
6
- interface OtelTraceHandlerOptions {
5
+ export interface OtelTraceHandlerOptions {
7
6
  /** The tracer to record with. Pass this OR {@link tracerProvider}. */
8
7
  tracer?: Tracer;
9
8
  /** A provider to take a `@statelyai/agent`-scoped tracer from. */
@@ -31,7 +30,7 @@ interface OtelTraceHandlerOptions {
31
30
  * An `onTrace` handler that writes OpenTelemetry spans, plus `dispose()` to
32
31
  * close any span still open (a run that never emitted `run.end`).
33
32
  */
34
- type OtelTraceHandler = ((event: AgentTraceEvent) => void) & {
33
+ export type OtelTraceHandler = ((event: AgentTraceEvent) => void) & {
35
34
  /**
36
35
  * Ends every span the handler still holds open and drops its state. Idempotent.
37
36
  * Required on the uncontrolled path, where no `run.end` ever arrives.
@@ -62,6 +61,5 @@ type OtelTraceHandler = ((event: AgentTraceEvent) => void) & {
62
61
  * }
63
62
  * ```
64
63
  */
65
- declare function createOtelTraceHandler(options: OtelTraceHandlerOptions): OtelTraceHandler;
66
- //#endregion
67
- export { OtelTraceHandler, OtelTraceHandlerOptions, createOtelTraceHandler };
64
+ export declare function createOtelTraceHandler(options: OtelTraceHandlerOptions): OtelTraceHandler;
65
+ //#endregion
package/dist/otel.d.mts CHANGED
@@ -1,9 +1,8 @@
1
- import { h as AgentTraceEvent } from "./run-agent-COXXc0RW.mjs";
1
+ import { g as AgentTraceEvent } from "./run-agent-CxSyZmIE.mjs";
2
2
  import { Attributes, Tracer, TracerProvider } from "@opentelemetry/api";
3
-
4
3
  //#region src/otel/index.d.ts
5
4
  /** Options for {@link createOtelTraceHandler}. */
6
- interface OtelTraceHandlerOptions {
5
+ export interface OtelTraceHandlerOptions {
7
6
  /** The tracer to record with. Pass this OR {@link tracerProvider}. */
8
7
  tracer?: Tracer;
9
8
  /** A provider to take a `@statelyai/agent`-scoped tracer from. */
@@ -31,7 +30,7 @@ interface OtelTraceHandlerOptions {
31
30
  * An `onTrace` handler that writes OpenTelemetry spans, plus `dispose()` to
32
31
  * close any span still open (a run that never emitted `run.end`).
33
32
  */
34
- type OtelTraceHandler = ((event: AgentTraceEvent) => void) & {
33
+ export type OtelTraceHandler = ((event: AgentTraceEvent) => void) & {
35
34
  /**
36
35
  * Ends every span the handler still holds open and drops its state. Idempotent.
37
36
  * Required on the uncontrolled path, where no `run.end` ever arrives.
@@ -62,6 +61,5 @@ type OtelTraceHandler = ((event: AgentTraceEvent) => void) & {
62
61
  * }
63
62
  * ```
64
63
  */
65
- declare function createOtelTraceHandler(options: OtelTraceHandlerOptions): OtelTraceHandler;
66
- //#endregion
67
- export { OtelTraceHandler, OtelTraceHandlerOptions, createOtelTraceHandler };
64
+ export declare function createOtelTraceHandler(options: OtelTraceHandlerOptions): OtelTraceHandler;
65
+ //#endregion
package/dist/otel.mjs CHANGED
@@ -208,12 +208,14 @@ function createOtelTraceHandler(options) {
208
208
  });
209
209
  });
210
210
  break;
211
- case "machine.transition":
212
- addRunEvent(event, "agent.transition", {
211
+ case "machine.transition": {
212
+ const attributes = {
213
213
  "agent.event_type": event.event.type,
214
214
  "agent.state": toJson(event.snapshot.value) ?? ""
215
- });
215
+ };
216
+ addRunEvent(event, "agent.transition", attributes);
216
217
  break;
218
+ }
217
219
  case "emit":
218
220
  addRunEvent(event, "agent.emit", { "agent.event_type": event.event.type });
219
221
  break;