@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.
- package/dist/ai-sdk.cjs +150 -27
- package/dist/ai-sdk.d.cts +59 -36
- package/dist/ai-sdk.d.mts +59 -36
- package/dist/ai-sdk.mjs +148 -24
- package/dist/{decision-RQ0iv0oZ.mjs → decision-BHkvuImD.mjs} +74 -8
- package/dist/{decision-CmM8-HHz.cjs → decision-CIb7ddIv.cjs} +113 -30
- package/dist/{text-logic-f5F5sCdc.cjs → event-log-BZRfBRd7.cjs} +814 -7
- package/dist/{text-logic-CIqHAmBi.mjs → event-log-DJCMHek_.mjs} +680 -4
- package/dist/{event-log-store-BIPOz-di.d.mts → event-log-store-CIIJohjj.d.mts} +90 -5
- package/dist/{event-log-store-2xzFmgr2.d.cts → event-log-store-CLAC9q2Y.d.cts} +90 -5
- package/dist/event-log-store-DZR4IIWe.cjs +95 -0
- package/dist/event-log-store-DsP6GCRh.mjs +84 -0
- package/dist/index.cjs +576 -58
- package/dist/index.d.cts +104 -510
- package/dist/index.d.mts +104 -510
- package/dist/index.mjs +547 -32
- package/dist/log.cjs +77 -20
- package/dist/log.d.cts +5 -5
- package/dist/log.d.mts +5 -5
- package/dist/log.mjs +58 -3
- package/dist/machines.cjs +1 -1
- package/dist/machines.d.cts +15 -15
- package/dist/machines.d.mts +15 -15
- package/dist/machines.mjs +1 -1
- package/dist/model-source-BCKg4qJ1.cjs +44 -0
- package/dist/model-source-BaHwJ1wK.mjs +39 -0
- package/dist/openai.cjs +11 -11
- package/dist/openai.d.cts +28 -26
- package/dist/openai.d.mts +28 -26
- package/dist/openai.mjs +3 -3
- package/dist/otel.cjs +5 -4
- package/dist/otel.d.cts +5 -7
- package/dist/otel.d.mts +5 -7
- package/dist/otel.mjs +5 -3
- package/dist/{run-agent-xNTxpt82.mjs → run-agent-BpHqkaZw.mjs} +181 -44
- package/dist/{run-agent-COXXc0RW.d.mts → run-agent-CAVt5R-r.d.mts} +95 -30
- package/dist/{run-agent-ByO-Bxyd.d.cts → run-agent-CTlMc3Jb.d.cts} +95 -30
- package/dist/{run-agent-Dmf8GV2d.cjs → run-agent-ctLCvNgL.cjs} +230 -88
- package/dist/{setup-agent-BuanDXeh.mjs → setup-agent-7rV_cujV.mjs} +15 -9
- package/dist/setup-agent-CGELn1qZ.d.mts +577 -0
- package/dist/setup-agent-CLPCkXsu.d.cts +577 -0
- package/dist/{setup-agent-DV4cTou-.cjs → setup-agent-DoUk7EdC.cjs} +31 -20
- package/dist/tanstack-ai.cjs +627 -0
- package/dist/tanstack-ai.d.cts +204 -0
- package/dist/tanstack-ai.d.mts +204 -0
- package/dist/tanstack-ai.mjs +618 -0
- package/dist/testing.cjs +204 -985
- package/dist/testing.d.cts +132 -347
- package/dist/testing.d.mts +132 -347
- package/dist/testing.mjs +191 -973
- package/dist/{text-logic-IjfYy9DP.d.cts → text-logic-BRYOPWvY.d.mts} +52 -12
- package/dist/{text-logic-D-czVPYp.d.mts → text-logic-DmciuVUQ.d.cts} +52 -12
- package/dist/{types-BgNbNKnJ.d.mts → types-Dp5_Ru4R.d.cts} +2 -2
- package/dist/{types-hR5f5YXa.d.cts → types-Dp5_Ru4R.d.mts} +2 -2
- package/dist/usage-BkM3z02Y.d.mts +17 -0
- package/dist/usage-Cm_ovz9V.d.cts +17 -0
- package/dist/{utils-_q7F-AZu.d.mts → utils-BnXdWih3.d.mts} +1 -2
- package/dist/{utils-o4YRdHJX.d.cts → utils-ebVpCYoF.d.cts} +1 -2
- package/dist/validate.cjs +239 -8
- package/dist/validate.d.cts +110 -3
- package/dist/validate.d.mts +110 -3
- package/dist/validate.mjs +238 -7
- package/dist/verify-COFWyprJ.mjs +1181 -0
- package/dist/verify-CVlsTZ-V.cjs +1222 -0
- package/dist/verify-Cn86rT8l.d.mts +414 -0
- package/dist/verify-Dzwd4Mvk.d.cts +414 -0
- package/package.json +44 -31
- package/readme.md +40 -28
- package/skills/add-evals/SKILL.md +129 -0
- package/skills/add-traces/SKILL.md +135 -0
- package/skills/generate-machine/SKILL.md +143 -69
- package/skills/graph-engineering/SKILL.md +33 -0
- package/skills/improve-machine/SKILL.md +241 -0
- package/skills/improve-machine/reference.md +101 -0
- package/skills/loop-to-machine/SKILL.md +183 -0
- package/skills/loop-to-machine/policy.md +158 -0
- package/dist/event-log-store-2pAFiWuc.mjs +0 -576
- package/dist/event-log-store-C-COhIXP.cjs +0 -702
- package/dist/usage-BdEjFuIi.mjs +0 -5
- 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
|
|
3
|
-
const require_decision = require("./decision-
|
|
2
|
+
const require_event_log = require("./event-log-BZRfBRd7.cjs");
|
|
3
|
+
const require_decision = require("./decision-CIb7ddIv.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: (
|
|
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:
|
|
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
|
|
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
|
|
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
|
/**
|
|
@@ -284,7 +284,7 @@ function toToolContent(output) {
|
|
|
284
284
|
* ```ts
|
|
285
285
|
* const executors = createOpenAiExecutors({
|
|
286
286
|
* client: new OpenAI(),
|
|
287
|
-
* resolveModel: () => 'gpt-
|
|
287
|
+
* resolveModel: () => 'gpt-6-luna',
|
|
288
288
|
* });
|
|
289
289
|
* const result = await runToQuiescence(createAgentRuntime(machine, { executors }), { input });
|
|
290
290
|
* ```
|
|
@@ -303,8 +303,8 @@ function createOpenAiExecutors(options) {
|
|
|
303
303
|
};
|
|
304
304
|
};
|
|
305
305
|
const structuredSchema = async (request) => {
|
|
306
|
-
if (
|
|
307
|
-
return
|
|
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) =>
|
|
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 (
|
|
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-
|
|
2
|
-
import {
|
|
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
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;
|
|
121
|
-
|
|
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;
|
|
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;
|
|
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` —
|
|
@@ -167,11 +170,10 @@ declare function addAgentCallUsage(total: AgentCallUsage | undefined, next: Agen
|
|
|
167
170
|
* ```ts
|
|
168
171
|
* const executors = createOpenAiExecutors({
|
|
169
172
|
* client: new OpenAI(),
|
|
170
|
-
* resolveModel: () => 'gpt-
|
|
173
|
+
* resolveModel: () => 'gpt-6-luna',
|
|
171
174
|
* });
|
|
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-
|
|
2
|
-
import {
|
|
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
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;
|
|
121
|
-
|
|
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;
|
|
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;
|
|
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` —
|
|
@@ -167,11 +170,10 @@ declare function addAgentCallUsage(total: AgentCallUsage | undefined, next: Agen
|
|
|
167
170
|
* ```ts
|
|
168
171
|
* const executors = createOpenAiExecutors({
|
|
169
172
|
* client: new OpenAI(),
|
|
170
|
-
* resolveModel: () => 'gpt-
|
|
173
|
+
* resolveModel: () => 'gpt-6-luna',
|
|
171
174
|
* });
|
|
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 {
|
|
2
|
-
import {
|
|
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-DJCMHek_.mjs";
|
|
2
|
+
import { c as renderDecisionAttempts } from "./decision-BHkvuImD.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. */
|
|
@@ -283,7 +283,7 @@ function toToolContent(output) {
|
|
|
283
283
|
* ```ts
|
|
284
284
|
* const executors = createOpenAiExecutors({
|
|
285
285
|
* client: new OpenAI(),
|
|
286
|
-
* resolveModel: () => 'gpt-
|
|
286
|
+
* resolveModel: () => 'gpt-6-luna',
|
|
287
287
|
* });
|
|
288
288
|
* const result = await runToQuiescence(createAgentRuntime(machine, { executors }), { input });
|
|
289
289
|
* ```
|
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
|
-
|
|
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 {
|
|
1
|
+
import { g as AgentTraceEvent } from "./run-agent-CTlMc3Jb.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 {
|
|
1
|
+
import { g as AgentTraceEvent } from "./run-agent-CAVt5R-r.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
|
-
|
|
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;
|