@statelyai/agent 2.0.0-alpha.24 → 2.0.0-alpha.26
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 +30 -34
- package/dist/ai-sdk.d.cts +27 -31
- package/dist/ai-sdk.d.mts +27 -31
- package/dist/ai-sdk.mjs +27 -31
- package/dist/decision-CM9CYZ6t.cjs +519 -0
- package/dist/decision-DzSv1NpD.mjs +453 -0
- package/dist/event-log-store-Ba2fsc4E.mjs +576 -0
- package/dist/event-log-store-DQmImLYk.cjs +702 -0
- package/dist/event-log-store-DvOcs10J.d.cts +338 -0
- package/dist/event-log-store-DxyVgnas.d.mts +338 -0
- package/dist/index.cjs +429 -4272
- package/dist/index.d.cts +104 -1005
- package/dist/index.d.mts +104 -1005
- package/dist/index.mjs +389 -4202
- package/dist/log.cjs +392 -0
- package/dist/log.d.cts +32 -0
- package/dist/log.d.mts +32 -0
- package/dist/log.mjs +371 -0
- package/dist/machines.cjs +27 -16
- package/dist/machines.d.cts +1 -1
- package/dist/machines.d.mts +1 -1
- package/dist/machines.mjs +27 -16
- package/dist/openai.cjs +16 -15
- package/dist/openai.d.cts +9 -9
- package/dist/openai.d.mts +9 -9
- package/dist/openai.mjs +10 -9
- package/dist/otel.d.cts +1 -1
- package/dist/otel.d.mts +1 -1
- package/dist/{run-agent-Ck7Sa3Tb.d.mts → run-agent-BOfoJg5B.d.cts} +86 -387
- package/dist/{run-agent-DWqA8KiI.d.cts → run-agent-CG343kFs.d.mts} +86 -387
- package/dist/run-agent-Cb1-LS5P.cjs +1783 -0
- package/dist/run-agent-DvDQd4If.mjs +1669 -0
- package/dist/{setup-agent-CeO2fARv.mjs → setup-agent-CFW-jPI8.mjs} +9 -20
- package/dist/{setup-agent-Dl2VELLi.cjs → setup-agent-CPf7MxnG.cjs} +20 -37
- package/dist/testing.cjs +1088 -0
- package/dist/testing.d.cts +617 -0
- package/dist/testing.d.mts +617 -0
- package/dist/testing.mjs +1079 -0
- package/dist/{text-logic-DJBK3LbG.d.mts → text-logic-BFEOxyxv.d.cts} +71 -147
- package/dist/text-logic-Bl_ZRxDi.mjs +833 -0
- package/dist/text-logic-C8xyr6Ag.cjs +1091 -0
- package/dist/{text-logic-C7bSnH_B.d.cts → text-logic-hZSiRUo1.d.mts} +71 -147
- package/dist/{types-CjHk5OdH.d.cts → types-B1Qs2q3q.d.cts} +2 -1
- package/dist/{types-DWA6X9R-.d.mts → types-tA3SdczG.d.mts} +2 -1
- package/dist/usage-BdEjFuIi.mjs +5 -0
- package/dist/usage-efOQPdf_.cjs +10 -0
- package/dist/utils-C2DPqomn.d.mts +109 -0
- package/dist/utils-ceStNCOh.d.cts +109 -0
- package/package.json +26 -5
- package/readme.md +5 -3
- package/skills/generate-machine/SKILL.md +4 -6
- package/dist/decision-BBZ2jMO1.mjs +0 -1490
- package/dist/decision-Cv6SfNWl.cjs +0 -1856
package/dist/openai.cjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const
|
|
2
|
+
const require_text_logic = require("./text-logic-C8xyr6Ag.cjs");
|
|
3
|
+
const require_decision = require("./decision-CM9CYZ6t.cjs");
|
|
3
4
|
//#region src/openai/index.ts
|
|
4
5
|
/** Thrown for a message part Chat Completions cannot carry — dropping it would
|
|
5
6
|
* silently change what the model sees. */
|
|
@@ -145,7 +146,7 @@ function toOpenAiTools(tools) {
|
|
|
145
146
|
function: {
|
|
146
147
|
name,
|
|
147
148
|
description: staticDescription(descriptor),
|
|
148
|
-
parameters: (
|
|
149
|
+
parameters: (require_text_logic.isStandardSchema(inputSchema) ? require_text_logic.getJsonSchemaSync(inputSchema) : void 0) ?? {}
|
|
149
150
|
}
|
|
150
151
|
}];
|
|
151
152
|
});
|
|
@@ -171,7 +172,7 @@ function toOpenAiEventTools(events) {
|
|
|
171
172
|
function: {
|
|
172
173
|
name: event.toolName,
|
|
173
174
|
description: `Choose the '${event.type}' move.`,
|
|
174
|
-
parameters:
|
|
175
|
+
parameters: require_text_logic.getJsonSchemaSync(event.inputSchema) ?? {}
|
|
175
176
|
}
|
|
176
177
|
}));
|
|
177
178
|
}
|
|
@@ -233,7 +234,7 @@ function callSettings(options, request) {
|
|
|
233
234
|
return entry;
|
|
234
235
|
}
|
|
235
236
|
function truncated(request, info, partialOutput, cause) {
|
|
236
|
-
return new
|
|
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
238
|
requestName: request.name ?? "(unnamed)",
|
|
238
239
|
...info?.requestId !== void 0 ? { requestId: info.requestId } : {},
|
|
239
240
|
...partialOutput !== void 0 ? { partialOutput } : {},
|
|
@@ -252,7 +253,7 @@ function usageField(usage) {
|
|
|
252
253
|
function addAgentCallUsage(total, next) {
|
|
253
254
|
if (!total || !next) return total ?? next;
|
|
254
255
|
const sum = {};
|
|
255
|
-
for (const field of
|
|
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
257
|
return sum;
|
|
257
258
|
}
|
|
258
259
|
/**
|
|
@@ -276,7 +277,7 @@ function toToolContent(output) {
|
|
|
276
277
|
* same shape, different SDK underneath.
|
|
277
278
|
*
|
|
278
279
|
* Structured output uses `response_format: { type: 'json_schema' }` around the
|
|
279
|
-
*
|
|
280
|
+
* `{ result, reasoning? }` provider output schema, and decisions force a tool call
|
|
280
281
|
* with `tool_choice: 'required'`, one function tool per candidate event.
|
|
281
282
|
*
|
|
282
283
|
* @example
|
|
@@ -301,12 +302,12 @@ function createOpenAiExecutors(options) {
|
|
|
301
302
|
...extra
|
|
302
303
|
};
|
|
303
304
|
};
|
|
304
|
-
const
|
|
305
|
-
if (
|
|
306
|
-
return
|
|
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 }));
|
|
307
308
|
};
|
|
308
309
|
const generateText = async (request, info) => {
|
|
309
|
-
const jsonSchema = await
|
|
310
|
+
const jsonSchema = await structuredSchema(request);
|
|
310
311
|
const responseFormat = jsonSchema ? { response_format: {
|
|
311
312
|
type: "json_schema",
|
|
312
313
|
json_schema: {
|
|
@@ -349,7 +350,7 @@ function createOpenAiExecutors(options) {
|
|
|
349
350
|
});
|
|
350
351
|
}
|
|
351
352
|
}
|
|
352
|
-
const unwrap = (content) =>
|
|
353
|
+
const unwrap = (content) => require_text_logic.parseProviderOutput(request, content ? JSON.parse(content) : void 0);
|
|
353
354
|
const choice = response.choices[0];
|
|
354
355
|
const finishReason = toAgentFinishReason(choice?.finish_reason);
|
|
355
356
|
const content = choice?.message.content;
|
|
@@ -357,7 +358,7 @@ function createOpenAiExecutors(options) {
|
|
|
357
358
|
if (finishReason === "length") throw truncated(request, info, content ?? void 0);
|
|
358
359
|
const parsed = unwrap(content);
|
|
359
360
|
return {
|
|
360
|
-
|
|
361
|
+
result: parsed.result,
|
|
361
362
|
...typeof parsed.reasoning === "string" ? { reasoning: parsed.reasoning } : {},
|
|
362
363
|
...usageField(usage),
|
|
363
364
|
finishReason,
|
|
@@ -365,14 +366,14 @@ function createOpenAiExecutors(options) {
|
|
|
365
366
|
};
|
|
366
367
|
}
|
|
367
368
|
return {
|
|
368
|
-
|
|
369
|
+
result: content ?? "",
|
|
369
370
|
...usageField(usage),
|
|
370
371
|
finishReason,
|
|
371
372
|
raw: response
|
|
372
373
|
};
|
|
373
374
|
};
|
|
374
375
|
const streamText = async (request, info) => {
|
|
375
|
-
if (
|
|
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
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.");
|
|
377
378
|
const stream = await client.chat.completions.create({
|
|
378
379
|
model: resolveModel(request.model),
|
|
@@ -398,7 +399,7 @@ function createOpenAiExecutors(options) {
|
|
|
398
399
|
if (chunk.usage) usage = chunk.usage;
|
|
399
400
|
}
|
|
400
401
|
return {
|
|
401
|
-
|
|
402
|
+
result: text,
|
|
402
403
|
...usageField(toAgentCallUsage(usage)),
|
|
403
404
|
finishReason,
|
|
404
405
|
raw: last
|
package/dist/openai.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
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-B1Qs2q3q.cjs";
|
|
2
|
+
import { M as AgentDecisionRequest, U as AgentEventDescriptor, c as AgentRequestExecutorInfo, f as AgentTextRequest, r as AgentFinishReason, t as AgentCallUsage } from "./text-logic-BFEOxyxv.cjs";
|
|
3
3
|
import OpenAI from "openai";
|
|
4
4
|
import { ChatCompletion, ChatCompletionCreateParamsNonStreaming, ChatCompletionMessageParam, ChatCompletionTool } from "openai/resources/chat/completions/completions.js";
|
|
5
5
|
|
|
@@ -104,13 +104,13 @@ type CreateOpenAiExecutorsOptions = {
|
|
|
104
104
|
settings?: Record<string, OpenAiCallSettings> | ((request: AgentTextRequest | AgentDecisionRequest) => OpenAiCallSettings | undefined);
|
|
105
105
|
};
|
|
106
106
|
/**
|
|
107
|
-
* Raw result shape from {@link OpenAiExecutors.generateText} —
|
|
108
|
-
*
|
|
109
|
-
*
|
|
110
|
-
* verbatim to `runAgent`'s `onResult(request, { raw })`.
|
|
107
|
+
* Raw result shape from {@link OpenAiExecutors.generateText} — `result` (the
|
|
108
|
+
* validated structured object for structured-output requests, or the model's
|
|
109
|
+
* text otherwise) plus the call metadata. Core reads `result` and `usage`;
|
|
110
|
+
* everything else flows verbatim to `runAgent`'s `onResult(request, { raw })`.
|
|
111
111
|
*/
|
|
112
112
|
type OpenAiGenerateResult = {
|
|
113
|
-
|
|
113
|
+
result: unknown;
|
|
114
114
|
/** The model's reasoning, present only when the request opted in via
|
|
115
115
|
* `includeReasoning` and the model produced it. Never enters machine
|
|
116
116
|
* context/output. */
|
|
@@ -123,7 +123,7 @@ type OpenAiGenerateResult = {
|
|
|
123
123
|
};
|
|
124
124
|
/** 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
125
|
type OpenAiStreamResult = {
|
|
126
|
-
|
|
126
|
+
result: string; /** Present when the stream carried a usage chunk (the adapter asks for one via `stream_options`). */
|
|
127
127
|
usage?: AgentCallUsage;
|
|
128
128
|
finishReason: AgentFinishReason; /** The last chunk seen, which carries the stream's finish metadata. */
|
|
129
129
|
raw: unknown;
|
|
@@ -160,7 +160,7 @@ declare function addAgentCallUsage(total: AgentCallUsage | undefined, next: Agen
|
|
|
160
160
|
* same shape, different SDK underneath.
|
|
161
161
|
*
|
|
162
162
|
* Structured output uses `response_format: { type: 'json_schema' }` around the
|
|
163
|
-
*
|
|
163
|
+
* `{ result, reasoning? }` provider output schema, and decisions force a tool call
|
|
164
164
|
* with `tool_choice: 'required'`, one function tool per candidate event.
|
|
165
165
|
*
|
|
166
166
|
* @example
|
package/dist/openai.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
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-tA3SdczG.mjs";
|
|
2
|
+
import { M as AgentDecisionRequest, U as AgentEventDescriptor, c as AgentRequestExecutorInfo, f as AgentTextRequest, r as AgentFinishReason, t as AgentCallUsage } from "./text-logic-hZSiRUo1.mjs";
|
|
3
3
|
import OpenAI from "openai";
|
|
4
4
|
import { ChatCompletion, ChatCompletionCreateParamsNonStreaming, ChatCompletionMessageParam, ChatCompletionTool } from "openai/resources/chat/completions/completions.js";
|
|
5
5
|
|
|
@@ -104,13 +104,13 @@ type CreateOpenAiExecutorsOptions = {
|
|
|
104
104
|
settings?: Record<string, OpenAiCallSettings> | ((request: AgentTextRequest | AgentDecisionRequest) => OpenAiCallSettings | undefined);
|
|
105
105
|
};
|
|
106
106
|
/**
|
|
107
|
-
* Raw result shape from {@link OpenAiExecutors.generateText} —
|
|
108
|
-
*
|
|
109
|
-
*
|
|
110
|
-
* verbatim to `runAgent`'s `onResult(request, { raw })`.
|
|
107
|
+
* Raw result shape from {@link OpenAiExecutors.generateText} — `result` (the
|
|
108
|
+
* validated structured object for structured-output requests, or the model's
|
|
109
|
+
* text otherwise) plus the call metadata. Core reads `result` and `usage`;
|
|
110
|
+
* everything else flows verbatim to `runAgent`'s `onResult(request, { raw })`.
|
|
111
111
|
*/
|
|
112
112
|
type OpenAiGenerateResult = {
|
|
113
|
-
|
|
113
|
+
result: unknown;
|
|
114
114
|
/** The model's reasoning, present only when the request opted in via
|
|
115
115
|
* `includeReasoning` and the model produced it. Never enters machine
|
|
116
116
|
* context/output. */
|
|
@@ -123,7 +123,7 @@ type OpenAiGenerateResult = {
|
|
|
123
123
|
};
|
|
124
124
|
/** 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
125
|
type OpenAiStreamResult = {
|
|
126
|
-
|
|
126
|
+
result: string; /** Present when the stream carried a usage chunk (the adapter asks for one via `stream_options`). */
|
|
127
127
|
usage?: AgentCallUsage;
|
|
128
128
|
finishReason: AgentFinishReason; /** The last chunk seen, which carries the stream's finish metadata. */
|
|
129
129
|
raw: unknown;
|
|
@@ -160,7 +160,7 @@ declare function addAgentCallUsage(total: AgentCallUsage | undefined, next: Agen
|
|
|
160
160
|
* same shape, different SDK underneath.
|
|
161
161
|
*
|
|
162
162
|
* Structured output uses `response_format: { type: 'json_schema' }` around the
|
|
163
|
-
*
|
|
163
|
+
* `{ result, reasoning? }` provider output schema, and decisions force a tool call
|
|
164
164
|
* with `tool_choice: 'required'`, one function tool per candidate event.
|
|
165
165
|
*
|
|
166
166
|
* @example
|
package/dist/openai.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { A as getJsonSchema, I as isStandardSchema, U as AgentTruncatedError, g as providerOutputSchema, h as parseProviderOutput, j as getJsonSchemaSync, l as getAgentOutputMode, t as AGENT_USAGE_TOKEN_FIELDS } from "./text-logic-Bl_ZRxDi.mjs";
|
|
2
|
+
import { o as renderDecisionAttempts } from "./decision-DzSv1NpD.mjs";
|
|
2
3
|
//#region src/openai/index.ts
|
|
3
4
|
/** Thrown for a message part Chat Completions cannot carry — dropping it would
|
|
4
5
|
* silently change what the model sees. */
|
|
@@ -275,7 +276,7 @@ function toToolContent(output) {
|
|
|
275
276
|
* same shape, different SDK underneath.
|
|
276
277
|
*
|
|
277
278
|
* Structured output uses `response_format: { type: 'json_schema' }` around the
|
|
278
|
-
*
|
|
279
|
+
* `{ result, reasoning? }` provider output schema, and decisions force a tool call
|
|
279
280
|
* with `tool_choice: 'required'`, one function tool per candidate event.
|
|
280
281
|
*
|
|
281
282
|
* @example
|
|
@@ -300,12 +301,12 @@ function createOpenAiExecutors(options) {
|
|
|
300
301
|
...extra
|
|
301
302
|
};
|
|
302
303
|
};
|
|
303
|
-
const
|
|
304
|
+
const structuredSchema = async (request) => {
|
|
304
305
|
if (getAgentOutputMode(request.outputSchema) !== "structured") return;
|
|
305
|
-
return getJsonSchema(
|
|
306
|
+
return getJsonSchema(providerOutputSchema(request.outputSchema, { reasoning: request.includeReasoning }));
|
|
306
307
|
};
|
|
307
308
|
const generateText = async (request, info) => {
|
|
308
|
-
const jsonSchema = await
|
|
309
|
+
const jsonSchema = await structuredSchema(request);
|
|
309
310
|
const responseFormat = jsonSchema ? { response_format: {
|
|
310
311
|
type: "json_schema",
|
|
311
312
|
json_schema: {
|
|
@@ -348,7 +349,7 @@ function createOpenAiExecutors(options) {
|
|
|
348
349
|
});
|
|
349
350
|
}
|
|
350
351
|
}
|
|
351
|
-
const unwrap = (content) =>
|
|
352
|
+
const unwrap = (content) => parseProviderOutput(request, content ? JSON.parse(content) : void 0);
|
|
352
353
|
const choice = response.choices[0];
|
|
353
354
|
const finishReason = toAgentFinishReason(choice?.finish_reason);
|
|
354
355
|
const content = choice?.message.content;
|
|
@@ -356,7 +357,7 @@ function createOpenAiExecutors(options) {
|
|
|
356
357
|
if (finishReason === "length") throw truncated(request, info, content ?? void 0);
|
|
357
358
|
const parsed = unwrap(content);
|
|
358
359
|
return {
|
|
359
|
-
|
|
360
|
+
result: parsed.result,
|
|
360
361
|
...typeof parsed.reasoning === "string" ? { reasoning: parsed.reasoning } : {},
|
|
361
362
|
...usageField(usage),
|
|
362
363
|
finishReason,
|
|
@@ -364,7 +365,7 @@ function createOpenAiExecutors(options) {
|
|
|
364
365
|
};
|
|
365
366
|
}
|
|
366
367
|
return {
|
|
367
|
-
|
|
368
|
+
result: content ?? "",
|
|
368
369
|
...usageField(usage),
|
|
369
370
|
finishReason,
|
|
370
371
|
raw: response
|
|
@@ -397,7 +398,7 @@ function createOpenAiExecutors(options) {
|
|
|
397
398
|
if (chunk.usage) usage = chunk.usage;
|
|
398
399
|
}
|
|
399
400
|
return {
|
|
400
|
-
|
|
401
|
+
result: text,
|
|
401
402
|
...usageField(toAgentCallUsage(usage)),
|
|
402
403
|
finishReason,
|
|
403
404
|
raw: last
|
package/dist/otel.d.cts
CHANGED
package/dist/otel.d.mts
CHANGED