@statelyai/agent 2.0.0-alpha.25 → 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/index.d.cts +2 -2
- package/dist/index.d.mts +2 -2
- package/dist/testing.cjs +9 -143
- package/dist/testing.d.cts +24 -9
- package/dist/testing.d.mts +24 -9
- package/dist/testing.mjs +10 -143
- package/dist/{utils-C1p37X_c.d.mts → utils-C2DPqomn.d.mts} +2 -102
- package/dist/{utils-RalRn9sk.d.cts → utils-ceStNCOh.d.cts} +2 -102
- package/package.json +3 -2
- package/readme.md +4 -2
package/dist/index.d.cts
CHANGED
|
@@ -2,7 +2,7 @@ import { C as UserMessage, S as ToolResultPart, _ as StandardSchemaV1, a as Agen
|
|
|
2
2
|
import { A as AgentDecisionExhaustedError, B as createDecisionRequest, C as getAgentOutputMode, D as parseProviderOutput, E as parseOutput, F as DecisionAttempt, G as AgentRequestOptions, H as resolveDecision, I as DecisionLogic, J as EventFromSnapshot, K as AgentRequestSource, L as DecisionLogicConfig, M as AgentDecisionRequest, N as AgentExecutorDecisionRequest, O as providerOutputSchema, P as CreateDecisionRequestOptions, Q as AgentTruncatedError, R as ResolveDecisionOptions, S as createTextLogic, T as getCallUsage, U as AgentEventDescriptor, V as renderDecisionAttempts, W as AgentInvalidEventPayloadError, X as parseAgentEvent, Y as getAcceptedEvents, Z as AgentError, _ as TextLogic, a as AgentModelRef, b as TextLogicExecutor, c as AgentRequestExecutorInfo, d as AgentRequestMode, f as AgentTextRequest, g as ProviderStructuredOutput, h as BuiltinAgentActors, i as AgentModelMap, j as AgentDecisionInput, k as AgentDecisionExecutor, l as AgentRequestExecutorResult, m as AgentUsage, n as AgentExecutorTextRequest, o as AgentOutputMode, p as AgentTextResult, q as AgentSchemas, r as AgentFinishReason, s as AgentRequestExecutor, t as AgentCallUsage, u as AgentRequestExecutors, v as TextLogicConfig, w as getCallFinishReason, x as bindRequestExecutor, y as TextLogicExecuteArgs, z as createDecisionLogic } from "./text-logic-BFEOxyxv.cjs";
|
|
3
3
|
import { C as rejectAgentStep, D as AgentUsageEvent, E as AGENT_USAGE_EVENT_TYPE, S as initialAgentStep, T as transitionAgentStep, _ as traceTransitions, a as AgentSnapshotDivergedError, b as AgentStepRequest, c as InspectedActorRef, d as RunAgentOptions, f as RunAgentResult, g as serializeTraceEvent, h as runAgent, i as AgentRunMeta, l as JsonSerializableTraceEvent, m as isAgentIdle, n as AgentInputFrom, o as AgentTraceEvent, p as inspectTransitions, r as AgentMaxModelCallsExceededError, s as AgentTransitionHandler, t as AGENT_TRACE_SCHEMA_VERSION, u as RunAgentErrorCause, v as AgentRequest, w as resolveAgentStep, x as executeAgentRequest, y as AgentStep } from "./run-agent-BOfoJg5B.cjs";
|
|
4
4
|
import { c as AgentLogEntry, d as AgentMachineVersionMismatchError, n as AgentEventLogStore, t as AgentEventLogConflictError } from "./event-log-store-DvOcs10J.cjs";
|
|
5
|
-
import {
|
|
5
|
+
import { a as getMachineStructuralHash, c as getStatePath, d as toolMessage, f as userMessage, i as getJsonSchemaSync, l as isStandardSchema, n as assistantMessage, o as getMessageText, r as getJsonSchema, s as getStateMeta, u as systemMessage } from "./utils-ceStNCOh.cjs";
|
|
6
6
|
import { AnyActorLogic, AnyMachineSnapshot, AnySetupConfig, AnyStateMachine, AsyncActorLogic, ContextFrom, DoneActorEvent, EmittedFrom, EventFromLogic, EventObject, InputFrom, MachineContext, MetaObject, NonReducibleUnknown, OutputFrom, SetupReturnFromConfig, SetupStateSchema, SnapshotFrom, StateValue, StateValueFrom } from "xstate";
|
|
7
7
|
|
|
8
8
|
//#region src/type-helpers.d.ts
|
|
@@ -739,4 +739,4 @@ interface ProvideExecutorsOptions<TMachine extends AnyStateMachine = AnyStateMac
|
|
|
739
739
|
*/
|
|
740
740
|
declare function provideExecutors<TMachine extends AnyStateMachine>(machine: TMachine, executors: AgentRequestExecutors, options?: ProvideExecutorsOptions<TMachine>): TMachine;
|
|
741
741
|
//#endregion
|
|
742
|
-
export { AGENT_TRACE_SCHEMA_VERSION, AGENT_USAGE_EVENT_TYPE, type AgentCallUsage, type AgentDecisionExecutor, AgentDecisionExhaustedError, type AgentDecisionInput, type AgentDecisionRequest, type AgentDefaultMeta, AgentError, type AgentEventDescriptor, AgentEventLogConflictError, type AgentEventLogStore, type AgentExecutorDecisionRequest, type AgentExecutorTextRequest, type AgentFinishReason, type AgentInputFrom, type AgentInteraction, type AgentInteractionDescriptor, type AgentInteractionEvent, type AgentInteractionEventMeta, type AgentInteractionMeta, AgentInvalidEventPayloadError, type AgentLogEntry, AgentMachineVersionMismatchError, AgentMaxModelCallsExceededError, type AgentMessage, type AgentModelRef, type AgentOutputMode, type AgentRequest, type AgentRequestExecutor, type AgentRequestExecutorInfo, type AgentRequestExecutorResult, type AgentRequestExecutors, type AgentRequestOptions, type AgentRequestSource, type AgentRunMeta, type AgentSchemaPack, type AgentSchemas, AgentSnapshotDivergedError, type AgentStep, type AgentStepRequest, type AgentStreamEvent, type AgentTextRequest, type AgentTextResult, type AgentTool, type AgentToolChoice, type AgentToolDescriptor, type AgentToolExecute, type AgentTools, type AgentTraceEvent, type AgentTransitionHandler, AgentTruncatedError, type AgentUsage, type AgentUsageEvent, type AgentUsageEventPayload, type AgentWorkflowActionConfig, type AgentWorkflowActorConfig, type AgentWorkflowConfig, type AgentWorkflowInvokeConfig, type AgentWorkflowRequestConfig, type AgentWorkflowStateConfig, type AgentWorkflowTransitionConfig, type AllowedEvents, type AssistantMessage, type ChosenEvent, type ContextOf, type CreateDecisionRequestOptions, type DecisionAttempt, type DecisionLogic, type DecisionLogicConfig, type DoneActorEventOf, type EventOf, type FilePart, type FromConfigOptions, type FromConfigResult, type GetInteractionOptions, type ImagePart, type InferInput, type InferOutput, type InputOf, type InspectedActorRef, type JsonSerializableTraceEvent, type MetaOf, type OutputOf, type ProvideExecutorsOptions, type ProviderStructuredOutput, type RequestNamesOf, type ResolveDecisionOptions, type RunAgentErrorCause, type RunAgentOptions, type RunAgentResult, type SchemaCompiler, type
|
|
742
|
+
export { AGENT_TRACE_SCHEMA_VERSION, AGENT_USAGE_EVENT_TYPE, type AgentCallUsage, type AgentDecisionExecutor, AgentDecisionExhaustedError, type AgentDecisionInput, type AgentDecisionRequest, type AgentDefaultMeta, AgentError, type AgentEventDescriptor, AgentEventLogConflictError, type AgentEventLogStore, type AgentExecutorDecisionRequest, type AgentExecutorTextRequest, type AgentFinishReason, type AgentInputFrom, type AgentInteraction, type AgentInteractionDescriptor, type AgentInteractionEvent, type AgentInteractionEventMeta, type AgentInteractionMeta, AgentInvalidEventPayloadError, type AgentLogEntry, AgentMachineVersionMismatchError, AgentMaxModelCallsExceededError, type AgentMessage, type AgentModelRef, type AgentOutputMode, type AgentRequest, type AgentRequestExecutor, type AgentRequestExecutorInfo, type AgentRequestExecutorResult, type AgentRequestExecutors, type AgentRequestOptions, type AgentRequestSource, type AgentRunMeta, type AgentSchemaPack, type AgentSchemas, AgentSnapshotDivergedError, type AgentStep, type AgentStepRequest, type AgentStreamEvent, type AgentTextRequest, type AgentTextResult, type AgentTool, type AgentToolChoice, type AgentToolDescriptor, type AgentToolExecute, type AgentTools, type AgentTraceEvent, type AgentTransitionHandler, AgentTruncatedError, type AgentUsage, type AgentUsageEvent, type AgentUsageEventPayload, type AgentWorkflowActionConfig, type AgentWorkflowActorConfig, type AgentWorkflowConfig, type AgentWorkflowInvokeConfig, type AgentWorkflowRequestConfig, type AgentWorkflowStateConfig, type AgentWorkflowTransitionConfig, type AllowedEvents, type AssistantMessage, type ChosenEvent, type ContextOf, type CreateDecisionRequestOptions, type DecisionAttempt, type DecisionLogic, type DecisionLogicConfig, type DoneActorEventOf, type EventOf, type FilePart, type FromConfigOptions, type FromConfigResult, type GetInteractionOptions, type ImagePart, type InferInput, type InferOutput, type InputOf, type InspectedActorRef, type JsonSerializableTraceEvent, type MetaOf, type OutputOf, type ProvideExecutorsOptions, type ProviderStructuredOutput, type RequestNamesOf, type ResolveDecisionOptions, type RunAgentErrorCause, type RunAgentOptions, type RunAgentResult, type SchemaCompiler, type SnapshotOf, type StandardSchemaV1, type StateValueOf, type SystemMessage, type TextLogic, type TextLogicConfig, type TextLogicExecuteArgs, type TextLogicExecutor, type TextPart, type ToolCallPart, type ToolMessage, type ToolResultPart, type UserMessage, type WithAgentEvents, type WithAgentUsageEvent, assistantMessage, bindRequestExecutor, createAgentSchemas, createDecisionLogic, createDecisionRequest, createTextLogic, eventFromInteraction, executeAgentRequest, getAcceptedEvents, getAgentOutputMode, getAgentSchemas, getCallFinishReason, getCallUsage, getInteraction, getJsonSchema, getJsonSchemaSync, getMachineStructuralHash, getMessageText, getStateMeta, getStatePath, initialAgentStep, inspectTransitions, interactionMetaSchema, isAgentIdle, isAgentMessages, isStandardSchema, messagesSchema, parseAgentEvent, parseOutput, parseProviderOutput, provideExecutors, providerOutputSchema, rejectAgentStep, renderDecisionAttempts, resolveAgentStep, resolveDecision, runAgent, runAgentStream, serializeTraceEvent, setupAgent, systemMessage, toolMessage, traceTransitions, transitionAgentStep, userMessage };
|
package/dist/index.d.mts
CHANGED
|
@@ -2,7 +2,7 @@ import { C as UserMessage, S as ToolResultPart, _ as StandardSchemaV1, a as Agen
|
|
|
2
2
|
import { A as AgentDecisionExhaustedError, B as createDecisionRequest, C as getAgentOutputMode, D as parseProviderOutput, E as parseOutput, F as DecisionAttempt, G as AgentRequestOptions, H as resolveDecision, I as DecisionLogic, J as EventFromSnapshot, K as AgentRequestSource, L as DecisionLogicConfig, M as AgentDecisionRequest, N as AgentExecutorDecisionRequest, O as providerOutputSchema, P as CreateDecisionRequestOptions, Q as AgentTruncatedError, R as ResolveDecisionOptions, S as createTextLogic, T as getCallUsage, U as AgentEventDescriptor, V as renderDecisionAttempts, W as AgentInvalidEventPayloadError, X as parseAgentEvent, Y as getAcceptedEvents, Z as AgentError, _ as TextLogic, a as AgentModelRef, b as TextLogicExecutor, c as AgentRequestExecutorInfo, d as AgentRequestMode, f as AgentTextRequest, g as ProviderStructuredOutput, h as BuiltinAgentActors, i as AgentModelMap, j as AgentDecisionInput, k as AgentDecisionExecutor, l as AgentRequestExecutorResult, m as AgentUsage, n as AgentExecutorTextRequest, o as AgentOutputMode, p as AgentTextResult, q as AgentSchemas, r as AgentFinishReason, s as AgentRequestExecutor, t as AgentCallUsage, u as AgentRequestExecutors, v as TextLogicConfig, w as getCallFinishReason, x as bindRequestExecutor, y as TextLogicExecuteArgs, z as createDecisionLogic } from "./text-logic-hZSiRUo1.mjs";
|
|
3
3
|
import { C as rejectAgentStep, D as AgentUsageEvent, E as AGENT_USAGE_EVENT_TYPE, S as initialAgentStep, T as transitionAgentStep, _ as traceTransitions, a as AgentSnapshotDivergedError, b as AgentStepRequest, c as InspectedActorRef, d as RunAgentOptions, f as RunAgentResult, g as serializeTraceEvent, h as runAgent, i as AgentRunMeta, l as JsonSerializableTraceEvent, m as isAgentIdle, n as AgentInputFrom, o as AgentTraceEvent, p as inspectTransitions, r as AgentMaxModelCallsExceededError, s as AgentTransitionHandler, t as AGENT_TRACE_SCHEMA_VERSION, u as RunAgentErrorCause, v as AgentRequest, w as resolveAgentStep, x as executeAgentRequest, y as AgentStep } from "./run-agent-CG343kFs.mjs";
|
|
4
4
|
import { c as AgentLogEntry, d as AgentMachineVersionMismatchError, n as AgentEventLogStore, t as AgentEventLogConflictError } from "./event-log-store-DxyVgnas.mjs";
|
|
5
|
-
import {
|
|
5
|
+
import { a as getMachineStructuralHash, c as getStatePath, d as toolMessage, f as userMessage, i as getJsonSchemaSync, l as isStandardSchema, n as assistantMessage, o as getMessageText, r as getJsonSchema, s as getStateMeta, u as systemMessage } from "./utils-C2DPqomn.mjs";
|
|
6
6
|
import { AnyActorLogic, AnyMachineSnapshot, AnySetupConfig, AnyStateMachine, AsyncActorLogic, ContextFrom, DoneActorEvent, EmittedFrom, EventFromLogic, EventObject, InputFrom, MachineContext, MetaObject, NonReducibleUnknown, OutputFrom, SetupReturnFromConfig, SetupStateSchema, SnapshotFrom, StateValue, StateValueFrom } from "xstate";
|
|
7
7
|
|
|
8
8
|
//#region src/type-helpers.d.ts
|
|
@@ -739,4 +739,4 @@ interface ProvideExecutorsOptions<TMachine extends AnyStateMachine = AnyStateMac
|
|
|
739
739
|
*/
|
|
740
740
|
declare function provideExecutors<TMachine extends AnyStateMachine>(machine: TMachine, executors: AgentRequestExecutors, options?: ProvideExecutorsOptions<TMachine>): TMachine;
|
|
741
741
|
//#endregion
|
|
742
|
-
export { AGENT_TRACE_SCHEMA_VERSION, AGENT_USAGE_EVENT_TYPE, type AgentCallUsage, type AgentDecisionExecutor, AgentDecisionExhaustedError, type AgentDecisionInput, type AgentDecisionRequest, type AgentDefaultMeta, AgentError, type AgentEventDescriptor, AgentEventLogConflictError, type AgentEventLogStore, type AgentExecutorDecisionRequest, type AgentExecutorTextRequest, type AgentFinishReason, type AgentInputFrom, type AgentInteraction, type AgentInteractionDescriptor, type AgentInteractionEvent, type AgentInteractionEventMeta, type AgentInteractionMeta, AgentInvalidEventPayloadError, type AgentLogEntry, AgentMachineVersionMismatchError, AgentMaxModelCallsExceededError, type AgentMessage, type AgentModelRef, type AgentOutputMode, type AgentRequest, type AgentRequestExecutor, type AgentRequestExecutorInfo, type AgentRequestExecutorResult, type AgentRequestExecutors, type AgentRequestOptions, type AgentRequestSource, type AgentRunMeta, type AgentSchemaPack, type AgentSchemas, AgentSnapshotDivergedError, type AgentStep, type AgentStepRequest, type AgentStreamEvent, type AgentTextRequest, type AgentTextResult, type AgentTool, type AgentToolChoice, type AgentToolDescriptor, type AgentToolExecute, type AgentTools, type AgentTraceEvent, type AgentTransitionHandler, AgentTruncatedError, type AgentUsage, type AgentUsageEvent, type AgentUsageEventPayload, type AgentWorkflowActionConfig, type AgentWorkflowActorConfig, type AgentWorkflowConfig, type AgentWorkflowInvokeConfig, type AgentWorkflowRequestConfig, type AgentWorkflowStateConfig, type AgentWorkflowTransitionConfig, type AllowedEvents, type AssistantMessage, type ChosenEvent, type ContextOf, type CreateDecisionRequestOptions, type DecisionAttempt, type DecisionLogic, type DecisionLogicConfig, type DoneActorEventOf, type EventOf, type FilePart, type FromConfigOptions, type FromConfigResult, type GetInteractionOptions, type ImagePart, type InferInput, type InferOutput, type InputOf, type InspectedActorRef, type JsonSerializableTraceEvent, type MetaOf, type OutputOf, type ProvideExecutorsOptions, type ProviderStructuredOutput, type RequestNamesOf, type ResolveDecisionOptions, type RunAgentErrorCause, type RunAgentOptions, type RunAgentResult, type SchemaCompiler, type
|
|
742
|
+
export { AGENT_TRACE_SCHEMA_VERSION, AGENT_USAGE_EVENT_TYPE, type AgentCallUsage, type AgentDecisionExecutor, AgentDecisionExhaustedError, type AgentDecisionInput, type AgentDecisionRequest, type AgentDefaultMeta, AgentError, type AgentEventDescriptor, AgentEventLogConflictError, type AgentEventLogStore, type AgentExecutorDecisionRequest, type AgentExecutorTextRequest, type AgentFinishReason, type AgentInputFrom, type AgentInteraction, type AgentInteractionDescriptor, type AgentInteractionEvent, type AgentInteractionEventMeta, type AgentInteractionMeta, AgentInvalidEventPayloadError, type AgentLogEntry, AgentMachineVersionMismatchError, AgentMaxModelCallsExceededError, type AgentMessage, type AgentModelRef, type AgentOutputMode, type AgentRequest, type AgentRequestExecutor, type AgentRequestExecutorInfo, type AgentRequestExecutorResult, type AgentRequestExecutors, type AgentRequestOptions, type AgentRequestSource, type AgentRunMeta, type AgentSchemaPack, type AgentSchemas, AgentSnapshotDivergedError, type AgentStep, type AgentStepRequest, type AgentStreamEvent, type AgentTextRequest, type AgentTextResult, type AgentTool, type AgentToolChoice, type AgentToolDescriptor, type AgentToolExecute, type AgentTools, type AgentTraceEvent, type AgentTransitionHandler, AgentTruncatedError, type AgentUsage, type AgentUsageEvent, type AgentUsageEventPayload, type AgentWorkflowActionConfig, type AgentWorkflowActorConfig, type AgentWorkflowConfig, type AgentWorkflowInvokeConfig, type AgentWorkflowRequestConfig, type AgentWorkflowStateConfig, type AgentWorkflowTransitionConfig, type AllowedEvents, type AssistantMessage, type ChosenEvent, type ContextOf, type CreateDecisionRequestOptions, type DecisionAttempt, type DecisionLogic, type DecisionLogicConfig, type DoneActorEventOf, type EventOf, type FilePart, type FromConfigOptions, type FromConfigResult, type GetInteractionOptions, type ImagePart, type InferInput, type InferOutput, type InputOf, type InspectedActorRef, type JsonSerializableTraceEvent, type MetaOf, type OutputOf, type ProvideExecutorsOptions, type ProviderStructuredOutput, type RequestNamesOf, type ResolveDecisionOptions, type RunAgentErrorCause, type RunAgentOptions, type RunAgentResult, type SchemaCompiler, type SnapshotOf, type StandardSchemaV1, type StateValueOf, type SystemMessage, type TextLogic, type TextLogicConfig, type TextLogicExecuteArgs, type TextLogicExecutor, type TextPart, type ToolCallPart, type ToolMessage, type ToolResultPart, type UserMessage, type WithAgentEvents, type WithAgentUsageEvent, assistantMessage, bindRequestExecutor, createAgentSchemas, createDecisionLogic, createDecisionRequest, createTextLogic, eventFromInteraction, executeAgentRequest, getAcceptedEvents, getAgentOutputMode, getAgentSchemas, getCallFinishReason, getCallUsage, getInteraction, getJsonSchema, getJsonSchemaSync, getMachineStructuralHash, getMessageText, getStateMeta, getStatePath, initialAgentStep, inspectTransitions, interactionMetaSchema, isAgentIdle, isAgentMessages, isStandardSchema, messagesSchema, parseAgentEvent, parseOutput, parseProviderOutput, provideExecutors, providerOutputSchema, rejectAgentStep, renderDecisionAttempts, resolveAgentStep, resolveDecision, runAgent, runAgentStream, serializeTraceEvent, setupAgent, systemMessage, toolMessage, traceTransitions, transitionAgentStep, userMessage };
|
package/dist/testing.cjs
CHANGED
|
@@ -870,43 +870,7 @@ function matchesTrajectory(actual, expected, options = {}) {
|
|
|
870
870
|
};
|
|
871
871
|
}
|
|
872
872
|
//#endregion
|
|
873
|
-
//#region src/
|
|
874
|
-
/**
|
|
875
|
-
* Scripted executors — a deterministic stand-in for a model host.
|
|
876
|
-
*
|
|
877
|
-
* `createScriptedExecutors` builds a full `{ generateText, streamText, decide }`
|
|
878
|
-
* set that plays back canned answers keyed by
|
|
879
|
-
* request name, so `runAgent` (or `provideExecutors`, or a bare
|
|
880
|
-
* `TextLogic.execute`) runs with no API key and no network.
|
|
881
|
-
*
|
|
882
|
-
* One rule: entries for a name are consumed in order, and the last entry
|
|
883
|
-
* repeats forever.
|
|
884
|
-
*
|
|
885
|
-
* @module
|
|
886
|
-
*/
|
|
887
|
-
function toQueues(value) {
|
|
888
|
-
return new Map(Object.entries(value ?? {}).map(([name, entries]) => [name, {
|
|
889
|
-
entries: Array.isArray(entries) ? [...entries] : [entries],
|
|
890
|
-
index: 0
|
|
891
|
-
}]));
|
|
892
|
-
}
|
|
893
|
-
/**
|
|
894
|
-
* Takes the next entry for `name`, holding on the last entry once the list is
|
|
895
|
-
* spent. `undefined` means the script has no route for this name at all.
|
|
896
|
-
* @internal
|
|
897
|
-
*/
|
|
898
|
-
function takeEntry(queues, name) {
|
|
899
|
-
const queue = queues.get(name) ?? queues.get("*");
|
|
900
|
-
if (!queue || queue.entries.length === 0) return;
|
|
901
|
-
const entry = queue.entries[Math.min(queue.index, queue.entries.length - 1)];
|
|
902
|
-
queue.index++;
|
|
903
|
-
return entry;
|
|
904
|
-
}
|
|
905
|
-
/** @internal */
|
|
906
|
-
function noAnswer(name, queues) {
|
|
907
|
-
const known = [...queues.keys()].join(", ") || "(none)";
|
|
908
|
-
return /* @__PURE__ */ new Error(`No scripted answer for request '${name}'. Known: ${known}`);
|
|
909
|
-
}
|
|
873
|
+
//#region src/seam.ts
|
|
910
874
|
/** The only own keys an executor result carries. @internal */
|
|
911
875
|
const TEXT_RESULT_KEYS = new Set([
|
|
912
876
|
"result",
|
|
@@ -925,123 +889,26 @@ function isTextResult(value) {
|
|
|
925
889
|
return Object.hasOwn(value, "result") && Object.keys(value).every((key) => TEXT_RESULT_KEYS.has(key));
|
|
926
890
|
}
|
|
927
891
|
/**
|
|
928
|
-
* Resolves ONE scripted
|
|
892
|
+
* Resolves ONE scripted entry to an executor result: a function entry is
|
|
929
893
|
* called with the request, and the value is taken as the executor result only
|
|
930
|
-
* when it is one (see {@link isTextResult}).
|
|
931
|
-
* queues follow the same entry conventions. @internal
|
|
894
|
+
* when it is one (see {@link isTextResult}). @internal
|
|
932
895
|
*/
|
|
933
|
-
async function
|
|
896
|
+
async function resolveSeamScriptEntry(entry, request, info) {
|
|
934
897
|
const value = typeof entry === "function" ? await entry(request, info) : entry;
|
|
935
898
|
return require_decision.isRecord(value) && isTextResult(value) ? value : { result: value };
|
|
936
899
|
}
|
|
937
|
-
/**
|
|
938
|
-
* Names a pending text request in an error message. Shared with `runSeam`.
|
|
939
|
-
* @internal
|
|
940
|
-
*/
|
|
900
|
+
/** Names a pending text request in an error message. @internal */
|
|
941
901
|
function describeText(request) {
|
|
942
902
|
return request.name ? `'${request.name}' (model '${request.model}')` : `(model '${request.model}')`;
|
|
943
903
|
}
|
|
944
904
|
/**
|
|
945
|
-
* Stream semantics with no model: the whole text lands as one chunk.
|
|
946
|
-
* with `runSeam`, whose scripted answers stream the same way. @internal
|
|
905
|
+
* Stream semantics with no model: the whole text lands as one chunk. @internal
|
|
947
906
|
*/
|
|
948
907
|
function emitScriptedChunk(result, info) {
|
|
949
908
|
const text = require_decision.isRecord(result) ? result["result"] : void 0;
|
|
950
909
|
if (typeof text === "string") info?.onChunk?.(text);
|
|
951
910
|
}
|
|
952
911
|
/**
|
|
953
|
-
* Executors that replay a script instead of calling a model. Every slot is
|
|
954
|
-
* provided, so any machine binds.
|
|
955
|
-
*
|
|
956
|
-
* Answers are keyed by the request's resolved name — its authored `name`, else
|
|
957
|
-
* the invoke `id` — and `"*"` serves anything unmatched.
|
|
958
|
-
* Entries for a name are consumed in order and the last one repeats forever, so
|
|
959
|
-
* a looping machine needs no extra option. A request the script has no route
|
|
960
|
-
* for throws an ordinary `Error` from inside the executor, which reaches the
|
|
961
|
-
* machine as an actor error.
|
|
962
|
-
*
|
|
963
|
-
* Queues are copied on creation, so the caller's arrays are never mutated and
|
|
964
|
-
* each call builds a fresh, independent playthrough. Entries may be plain
|
|
965
|
-
* values or functions of the request.
|
|
966
|
-
*
|
|
967
|
-
* @example
|
|
968
|
-
* ```ts
|
|
969
|
-
* const result = await runAgent(moderationMachine, {
|
|
970
|
-
* input: { comment: 'honestly this update is terrible', trust: 20 },
|
|
971
|
-
* executors: createScriptedExecutors({
|
|
972
|
-
* decisions: { moderate: [{ type: 'FLAG', reason: 'Borderline tone.' }] },
|
|
973
|
-
* }),
|
|
974
|
-
* });
|
|
975
|
-
* ```
|
|
976
|
-
*
|
|
977
|
-
* @example Dynamic entries
|
|
978
|
-
* ```ts
|
|
979
|
-
* createScriptedExecutors({
|
|
980
|
-
* text: { draft: (request) => `Draft about ${request.prompt}` },
|
|
981
|
-
* decisions: { route: (request) => ({ type: request.events[0]!.type }) },
|
|
982
|
-
* });
|
|
983
|
-
* ```
|
|
984
|
-
*/
|
|
985
|
-
function createScriptedExecutors(script = {}) {
|
|
986
|
-
const decisions = toQueues(script.decisions);
|
|
987
|
-
const text = toQueues(script.text);
|
|
988
|
-
const calls = [];
|
|
989
|
-
const withDefaultUsage = (result) => result.usage || !script.usage ? result : {
|
|
990
|
-
...result,
|
|
991
|
-
usage: script.usage
|
|
992
|
-
};
|
|
993
|
-
const nextText = async (kind, request, info) => {
|
|
994
|
-
const name = request.name ?? "*";
|
|
995
|
-
calls.push({
|
|
996
|
-
kind,
|
|
997
|
-
name,
|
|
998
|
-
input: request.input,
|
|
999
|
-
request
|
|
1000
|
-
});
|
|
1001
|
-
const entry = takeEntry(text, name);
|
|
1002
|
-
if (entry === void 0) throw noAnswer(name, text);
|
|
1003
|
-
return withDefaultUsage(await resolveScriptedTextEntry(entry, request, info));
|
|
1004
|
-
};
|
|
1005
|
-
return {
|
|
1006
|
-
calls,
|
|
1007
|
-
generateText: (request, info) => nextText("generateText", request, info),
|
|
1008
|
-
streamText: async (request, info) => {
|
|
1009
|
-
const name = request.name ?? "*";
|
|
1010
|
-
const streamEntry = script.stream?.[name] ?? script.stream?.["*"];
|
|
1011
|
-
if (streamEntry !== void 0) {
|
|
1012
|
-
calls.push({
|
|
1013
|
-
kind: "streamText",
|
|
1014
|
-
name,
|
|
1015
|
-
input: request.input,
|
|
1016
|
-
request
|
|
1017
|
-
});
|
|
1018
|
-
const resolved = typeof streamEntry === "function" ? await streamEntry(request, info) : streamEntry;
|
|
1019
|
-
const chunks = typeof resolved === "string" ? [resolved] : [...resolved];
|
|
1020
|
-
for (const chunk of chunks) info?.onChunk?.(chunk);
|
|
1021
|
-
return withDefaultUsage({ result: chunks.join("") });
|
|
1022
|
-
}
|
|
1023
|
-
const result = await nextText("streamText", request, info);
|
|
1024
|
-
emitScriptedChunk(result, info);
|
|
1025
|
-
return result;
|
|
1026
|
-
},
|
|
1027
|
-
decide: async (request) => {
|
|
1028
|
-
const name = request.name ?? request.id;
|
|
1029
|
-
calls.push({
|
|
1030
|
-
kind: "decide",
|
|
1031
|
-
name,
|
|
1032
|
-
input: request.input,
|
|
1033
|
-
request
|
|
1034
|
-
});
|
|
1035
|
-
const entry = takeEntry(decisions, name);
|
|
1036
|
-
if (entry === void 0) throw noAnswer(name, decisions);
|
|
1037
|
-
const value = typeof entry === "function" ? await entry(request) : entry;
|
|
1038
|
-
return withDefaultUsage(require_decision.isRecord(value) && typeof value["type"] !== "string" && "event" in value ? value : { event: value });
|
|
1039
|
-
}
|
|
1040
|
-
};
|
|
1041
|
-
}
|
|
1042
|
-
//#endregion
|
|
1043
|
-
//#region src/seam.ts
|
|
1044
|
-
/**
|
|
1045
912
|
* The seam's own answer, for scoring: the executor result's `result`.
|
|
1046
913
|
* @internal
|
|
1047
914
|
*/
|
|
@@ -1063,8 +930,8 @@ async function seamOutputOf(result, request) {
|
|
|
1063
930
|
* @example No API key: the seam is scripted too, so the whole thing runs offline.
|
|
1064
931
|
* ```ts
|
|
1065
932
|
* const run = await runSeam(emailDrafter, {
|
|
1066
|
-
* scripts: {
|
|
1067
|
-
* seam: { request: '
|
|
933
|
+
* scripts: { writeFollowUps: [followUps], emailDrafter: [draft] },
|
|
934
|
+
* seam: { request: 'writeFollowUps' },
|
|
1068
935
|
* respond: ({ state }) => (state === 'prompting' ? { type: 'PROMPT_SUBMITTED', prompt } : null),
|
|
1069
936
|
* });
|
|
1070
937
|
*
|
|
@@ -1100,7 +967,7 @@ async function runSeam(machine, options) {
|
|
|
1100
967
|
const takeScriptedSlot = async (request, info) => {
|
|
1101
968
|
const queue = queues.get(queueKeyOf(request));
|
|
1102
969
|
if (!queue?.length) return;
|
|
1103
|
-
return
|
|
970
|
+
return resolveSeamScriptEntry(options.repeatLast && queue.length === 1 ? queue[0] : queue.shift(), request, info);
|
|
1104
971
|
};
|
|
1105
972
|
const scriptedAnswer = async (request, info) => {
|
|
1106
973
|
const scripted = await takeScriptedSlot(request, info);
|
|
@@ -1214,7 +1081,6 @@ exports.AgentLintError = AgentLintError;
|
|
|
1214
1081
|
exports.AgentUnknownStateError = AgentUnknownStateError;
|
|
1215
1082
|
exports.assertAgentMachine = assertAgentMachine;
|
|
1216
1083
|
exports.canReach = canReach;
|
|
1217
|
-
exports.createScriptedExecutors = createScriptedExecutors;
|
|
1218
1084
|
exports.explorePaths = explorePaths;
|
|
1219
1085
|
exports.lintAgentMachine = lintAgentMachine;
|
|
1220
1086
|
exports.matchesTrajectory = matchesTrajectory;
|
package/dist/testing.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { u as ChosenEvent } from "./types-B1Qs2q3q.cjs";
|
|
2
|
-
import { Z as AgentError, s as AgentRequestExecutor, t as AgentCallUsage, u as AgentRequestExecutors } from "./text-logic-BFEOxyxv.cjs";
|
|
2
|
+
import { Z as AgentError, c as AgentRequestExecutorInfo, f as AgentTextRequest, s as AgentRequestExecutor, t as AgentCallUsage, u as AgentRequestExecutors } from "./text-logic-BFEOxyxv.cjs";
|
|
3
3
|
import { d as RunAgentOptions, f as RunAgentResult } from "./run-agent-BOfoJg5B.cjs";
|
|
4
|
-
import {
|
|
4
|
+
import { t as MetaOfSnapshot } from "./utils-ceStNCOh.cjs";
|
|
5
5
|
import { AnyMachineSnapshot, AnyStateMachine, EventFromLogic, InputFrom, SnapshotFrom, StateValue } from "xstate";
|
|
6
6
|
|
|
7
7
|
//#region src/verify.d.ts
|
|
@@ -435,6 +435,20 @@ interface TrajectoryMatch {
|
|
|
435
435
|
declare function matchesTrajectory(actual: readonly unknown[], expected: readonly TrajectoryItem[], options?: MatchTrajectoryOptions): TrajectoryMatch;
|
|
436
436
|
//#endregion
|
|
437
437
|
//#region src/seam.d.ts
|
|
438
|
+
/**
|
|
439
|
+
* One scripted answer in a {@link RunSeamOptions.scripts} queue: the request's
|
|
440
|
+
* output value (a string, or the object a structured request declares), or a
|
|
441
|
+
* function of the {@link AgentTextRequest} returning one.
|
|
442
|
+
*
|
|
443
|
+
* An entry is taken as the executor result (instead of the value itself)
|
|
444
|
+
* only when its OWN keys are a `result` plus, optionally, `messages`/`usage`/
|
|
445
|
+
* `raw` — that is how an entry reports token `usage`. Anything else, including
|
|
446
|
+
* an object that merely happens to have a `result` key alongside its own data
|
|
447
|
+
* (`{ result: 'draft', confidence: 0.9 }`), is the output value. For a
|
|
448
|
+
* structured request whose declared output is exactly `{ result }` (or
|
|
449
|
+
* `{ result, usage }`), wrap it once more: `{ result: { result: '…' } }`.
|
|
450
|
+
*/
|
|
451
|
+
type SeamScriptEntry = ((request: AgentTextRequest, info?: AgentRequestExecutorInfo) => unknown) | string | number | boolean | null | object;
|
|
438
452
|
/**
|
|
439
453
|
* Which model call is under test: the Nth call with this request `name` (the
|
|
440
454
|
* `setupAgent({ requests })` key, or `createTextLogic({ name })`). Name the
|
|
@@ -505,12 +519,12 @@ interface RunSeamOptions<TMachine extends AnyStateMachine> {
|
|
|
505
519
|
* machine whose requests are named routes by name and an unnamed one routes
|
|
506
520
|
* by model.
|
|
507
521
|
*
|
|
508
|
-
* Entries follow {@link
|
|
522
|
+
* Entries follow {@link SeamScriptEntry} conventions (a value, an
|
|
509
523
|
* `{ result, usage? }` object, or a function of the request). A queue that
|
|
510
524
|
* runs dry throws; set {@link RunSeamOptions.repeatLast} to replay its last
|
|
511
525
|
* entry instead.
|
|
512
526
|
*/
|
|
513
|
-
scripts?: Record<string,
|
|
527
|
+
scripts?: Record<string, SeamScriptEntry[]>;
|
|
514
528
|
/**
|
|
515
529
|
* Replay the LAST entry of a queue once it is exhausted, so a live seam that
|
|
516
530
|
* sends the run down a longer branch still finds an answer. Off by default:
|
|
@@ -534,8 +548,9 @@ interface RunSeamOptions<TMachine extends AnyStateMachine> {
|
|
|
534
548
|
/** Maximum idle pauses to answer before stopping. Default `12`. */
|
|
535
549
|
maxTurns?: number;
|
|
536
550
|
/**
|
|
537
|
-
* Base executors merged UNDER the seam routing — supply `decide` (
|
|
538
|
-
*
|
|
551
|
+
* Base executors merged UNDER the seam routing — supply `decide` (a plain
|
|
552
|
+
* function of the decision request, or `createAiSdkExecutors` over a mock
|
|
553
|
+
* model) for a machine that also decides.
|
|
539
554
|
* Text slots are always owned by the routing.
|
|
540
555
|
*/
|
|
541
556
|
executors?: Partial<AgentRequestExecutors>;
|
|
@@ -583,8 +598,8 @@ interface RunSeamResult<TMachine extends AnyStateMachine> {
|
|
|
583
598
|
* @example No API key: the seam is scripted too, so the whole thing runs offline.
|
|
584
599
|
* ```ts
|
|
585
600
|
* const run = await runSeam(emailDrafter, {
|
|
586
|
-
* scripts: {
|
|
587
|
-
* seam: { request: '
|
|
601
|
+
* scripts: { writeFollowUps: [followUps], emailDrafter: [draft] },
|
|
602
|
+
* seam: { request: 'writeFollowUps' },
|
|
588
603
|
* respond: ({ state }) => (state === 'prompting' ? { type: 'PROMPT_SUBMITTED', prompt } : null),
|
|
589
604
|
* });
|
|
590
605
|
*
|
|
@@ -599,4 +614,4 @@ interface RunSeamResult<TMachine extends AnyStateMachine> {
|
|
|
599
614
|
*/
|
|
600
615
|
declare function runSeam<TMachine extends AnyStateMachine>(machine: TMachine, options: RunSeamOptions<TMachine>): Promise<RunSeamResult<TMachine>>;
|
|
601
616
|
//#endregion
|
|
602
|
-
export { type AgentLintDiagnostic, AgentLintError, type AgentLintSeverity, type AgentPathReport, type AgentPathTerminal, AgentUnknownStateError, type AssertAgentMachineOptions, type CanReachResult, type ExplorePathsOptions, type LintAgentMachineOptions, type MatchTrajectoryOptions, type RunSeamOptions, type RunSeamResult, type
|
|
617
|
+
export { type AgentLintDiagnostic, AgentLintError, type AgentLintSeverity, type AgentPathReport, type AgentPathTerminal, AgentUnknownStateError, type AssertAgentMachineOptions, type CanReachResult, type ExplorePathsOptions, type LintAgentMachineOptions, type MatchTrajectoryOptions, type RunSeamOptions, type RunSeamResult, type SeamCall, type SeamRef, type SeamScriptEntry, type SeamSlice, type SeamTurn, type SimulateAgentOptions, type SimulateAgentResult, type SimulationScript, type SimulationTrailEntry, type TrajectoryEvent, type TrajectoryItem, type TrajectoryMatch, type TrajectoryMiss, assertAgentMachine, canReach, explorePaths, lintAgentMachine, matchesTrajectory, runSeam, simulateAgent };
|
package/dist/testing.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { u as ChosenEvent } from "./types-tA3SdczG.mjs";
|
|
2
|
-
import { Z as AgentError, s as AgentRequestExecutor, t as AgentCallUsage, u as AgentRequestExecutors } from "./text-logic-hZSiRUo1.mjs";
|
|
2
|
+
import { Z as AgentError, c as AgentRequestExecutorInfo, f as AgentTextRequest, s as AgentRequestExecutor, t as AgentCallUsage, u as AgentRequestExecutors } from "./text-logic-hZSiRUo1.mjs";
|
|
3
3
|
import { d as RunAgentOptions, f as RunAgentResult } from "./run-agent-CG343kFs.mjs";
|
|
4
|
-
import {
|
|
4
|
+
import { t as MetaOfSnapshot } from "./utils-C2DPqomn.mjs";
|
|
5
5
|
import { AnyMachineSnapshot, AnyStateMachine, EventFromLogic, InputFrom, SnapshotFrom, StateValue } from "xstate";
|
|
6
6
|
|
|
7
7
|
//#region src/verify.d.ts
|
|
@@ -435,6 +435,20 @@ interface TrajectoryMatch {
|
|
|
435
435
|
declare function matchesTrajectory(actual: readonly unknown[], expected: readonly TrajectoryItem[], options?: MatchTrajectoryOptions): TrajectoryMatch;
|
|
436
436
|
//#endregion
|
|
437
437
|
//#region src/seam.d.ts
|
|
438
|
+
/**
|
|
439
|
+
* One scripted answer in a {@link RunSeamOptions.scripts} queue: the request's
|
|
440
|
+
* output value (a string, or the object a structured request declares), or a
|
|
441
|
+
* function of the {@link AgentTextRequest} returning one.
|
|
442
|
+
*
|
|
443
|
+
* An entry is taken as the executor result (instead of the value itself)
|
|
444
|
+
* only when its OWN keys are a `result` plus, optionally, `messages`/`usage`/
|
|
445
|
+
* `raw` — that is how an entry reports token `usage`. Anything else, including
|
|
446
|
+
* an object that merely happens to have a `result` key alongside its own data
|
|
447
|
+
* (`{ result: 'draft', confidence: 0.9 }`), is the output value. For a
|
|
448
|
+
* structured request whose declared output is exactly `{ result }` (or
|
|
449
|
+
* `{ result, usage }`), wrap it once more: `{ result: { result: '…' } }`.
|
|
450
|
+
*/
|
|
451
|
+
type SeamScriptEntry = ((request: AgentTextRequest, info?: AgentRequestExecutorInfo) => unknown) | string | number | boolean | null | object;
|
|
438
452
|
/**
|
|
439
453
|
* Which model call is under test: the Nth call with this request `name` (the
|
|
440
454
|
* `setupAgent({ requests })` key, or `createTextLogic({ name })`). Name the
|
|
@@ -505,12 +519,12 @@ interface RunSeamOptions<TMachine extends AnyStateMachine> {
|
|
|
505
519
|
* machine whose requests are named routes by name and an unnamed one routes
|
|
506
520
|
* by model.
|
|
507
521
|
*
|
|
508
|
-
* Entries follow {@link
|
|
522
|
+
* Entries follow {@link SeamScriptEntry} conventions (a value, an
|
|
509
523
|
* `{ result, usage? }` object, or a function of the request). A queue that
|
|
510
524
|
* runs dry throws; set {@link RunSeamOptions.repeatLast} to replay its last
|
|
511
525
|
* entry instead.
|
|
512
526
|
*/
|
|
513
|
-
scripts?: Record<string,
|
|
527
|
+
scripts?: Record<string, SeamScriptEntry[]>;
|
|
514
528
|
/**
|
|
515
529
|
* Replay the LAST entry of a queue once it is exhausted, so a live seam that
|
|
516
530
|
* sends the run down a longer branch still finds an answer. Off by default:
|
|
@@ -534,8 +548,9 @@ interface RunSeamOptions<TMachine extends AnyStateMachine> {
|
|
|
534
548
|
/** Maximum idle pauses to answer before stopping. Default `12`. */
|
|
535
549
|
maxTurns?: number;
|
|
536
550
|
/**
|
|
537
|
-
* Base executors merged UNDER the seam routing — supply `decide` (
|
|
538
|
-
*
|
|
551
|
+
* Base executors merged UNDER the seam routing — supply `decide` (a plain
|
|
552
|
+
* function of the decision request, or `createAiSdkExecutors` over a mock
|
|
553
|
+
* model) for a machine that also decides.
|
|
539
554
|
* Text slots are always owned by the routing.
|
|
540
555
|
*/
|
|
541
556
|
executors?: Partial<AgentRequestExecutors>;
|
|
@@ -583,8 +598,8 @@ interface RunSeamResult<TMachine extends AnyStateMachine> {
|
|
|
583
598
|
* @example No API key: the seam is scripted too, so the whole thing runs offline.
|
|
584
599
|
* ```ts
|
|
585
600
|
* const run = await runSeam(emailDrafter, {
|
|
586
|
-
* scripts: {
|
|
587
|
-
* seam: { request: '
|
|
601
|
+
* scripts: { writeFollowUps: [followUps], emailDrafter: [draft] },
|
|
602
|
+
* seam: { request: 'writeFollowUps' },
|
|
588
603
|
* respond: ({ state }) => (state === 'prompting' ? { type: 'PROMPT_SUBMITTED', prompt } : null),
|
|
589
604
|
* });
|
|
590
605
|
*
|
|
@@ -599,4 +614,4 @@ interface RunSeamResult<TMachine extends AnyStateMachine> {
|
|
|
599
614
|
*/
|
|
600
615
|
declare function runSeam<TMachine extends AnyStateMachine>(machine: TMachine, options: RunSeamOptions<TMachine>): Promise<RunSeamResult<TMachine>>;
|
|
601
616
|
//#endregion
|
|
602
|
-
export { type AgentLintDiagnostic, AgentLintError, type AgentLintSeverity, type AgentPathReport, type AgentPathTerminal, AgentUnknownStateError, type AssertAgentMachineOptions, type CanReachResult, type ExplorePathsOptions, type LintAgentMachineOptions, type MatchTrajectoryOptions, type RunSeamOptions, type RunSeamResult, type
|
|
617
|
+
export { type AgentLintDiagnostic, AgentLintError, type AgentLintSeverity, type AgentPathReport, type AgentPathTerminal, AgentUnknownStateError, type AssertAgentMachineOptions, type CanReachResult, type ExplorePathsOptions, type LintAgentMachineOptions, type MatchTrajectoryOptions, type RunSeamOptions, type RunSeamResult, type SeamCall, type SeamRef, type SeamScriptEntry, type SeamSlice, type SeamTurn, type SimulateAgentOptions, type SimulateAgentResult, type SimulationScript, type SimulationTrailEntry, type TrajectoryEvent, type TrajectoryItem, type TrajectoryMatch, type TrajectoryMiss, assertAgentMachine, canReach, explorePaths, lintAgentMachine, matchesTrajectory, runSeam, simulateAgent };
|
package/dist/testing.mjs
CHANGED
|
@@ -869,43 +869,7 @@ function matchesTrajectory(actual, expected, options = {}) {
|
|
|
869
869
|
};
|
|
870
870
|
}
|
|
871
871
|
//#endregion
|
|
872
|
-
//#region src/
|
|
873
|
-
/**
|
|
874
|
-
* Scripted executors — a deterministic stand-in for a model host.
|
|
875
|
-
*
|
|
876
|
-
* `createScriptedExecutors` builds a full `{ generateText, streamText, decide }`
|
|
877
|
-
* set that plays back canned answers keyed by
|
|
878
|
-
* request name, so `runAgent` (or `provideExecutors`, or a bare
|
|
879
|
-
* `TextLogic.execute`) runs with no API key and no network.
|
|
880
|
-
*
|
|
881
|
-
* One rule: entries for a name are consumed in order, and the last entry
|
|
882
|
-
* repeats forever.
|
|
883
|
-
*
|
|
884
|
-
* @module
|
|
885
|
-
*/
|
|
886
|
-
function toQueues(value) {
|
|
887
|
-
return new Map(Object.entries(value ?? {}).map(([name, entries]) => [name, {
|
|
888
|
-
entries: Array.isArray(entries) ? [...entries] : [entries],
|
|
889
|
-
index: 0
|
|
890
|
-
}]));
|
|
891
|
-
}
|
|
892
|
-
/**
|
|
893
|
-
* Takes the next entry for `name`, holding on the last entry once the list is
|
|
894
|
-
* spent. `undefined` means the script has no route for this name at all.
|
|
895
|
-
* @internal
|
|
896
|
-
*/
|
|
897
|
-
function takeEntry(queues, name) {
|
|
898
|
-
const queue = queues.get(name) ?? queues.get("*");
|
|
899
|
-
if (!queue || queue.entries.length === 0) return;
|
|
900
|
-
const entry = queue.entries[Math.min(queue.index, queue.entries.length - 1)];
|
|
901
|
-
queue.index++;
|
|
902
|
-
return entry;
|
|
903
|
-
}
|
|
904
|
-
/** @internal */
|
|
905
|
-
function noAnswer(name, queues) {
|
|
906
|
-
const known = [...queues.keys()].join(", ") || "(none)";
|
|
907
|
-
return /* @__PURE__ */ new Error(`No scripted answer for request '${name}'. Known: ${known}`);
|
|
908
|
-
}
|
|
872
|
+
//#region src/seam.ts
|
|
909
873
|
/** The only own keys an executor result carries. @internal */
|
|
910
874
|
const TEXT_RESULT_KEYS = new Set([
|
|
911
875
|
"result",
|
|
@@ -924,123 +888,26 @@ function isTextResult(value) {
|
|
|
924
888
|
return Object.hasOwn(value, "result") && Object.keys(value).every((key) => TEXT_RESULT_KEYS.has(key));
|
|
925
889
|
}
|
|
926
890
|
/**
|
|
927
|
-
* Resolves ONE scripted
|
|
891
|
+
* Resolves ONE scripted entry to an executor result: a function entry is
|
|
928
892
|
* called with the request, and the value is taken as the executor result only
|
|
929
|
-
* when it is one (see {@link isTextResult}).
|
|
930
|
-
* queues follow the same entry conventions. @internal
|
|
893
|
+
* when it is one (see {@link isTextResult}). @internal
|
|
931
894
|
*/
|
|
932
|
-
async function
|
|
895
|
+
async function resolveSeamScriptEntry(entry, request, info) {
|
|
933
896
|
const value = typeof entry === "function" ? await entry(request, info) : entry;
|
|
934
897
|
return isRecord(value) && isTextResult(value) ? value : { result: value };
|
|
935
898
|
}
|
|
936
|
-
/**
|
|
937
|
-
* Names a pending text request in an error message. Shared with `runSeam`.
|
|
938
|
-
* @internal
|
|
939
|
-
*/
|
|
899
|
+
/** Names a pending text request in an error message. @internal */
|
|
940
900
|
function describeText(request) {
|
|
941
901
|
return request.name ? `'${request.name}' (model '${request.model}')` : `(model '${request.model}')`;
|
|
942
902
|
}
|
|
943
903
|
/**
|
|
944
|
-
* Stream semantics with no model: the whole text lands as one chunk.
|
|
945
|
-
* with `runSeam`, whose scripted answers stream the same way. @internal
|
|
904
|
+
* Stream semantics with no model: the whole text lands as one chunk. @internal
|
|
946
905
|
*/
|
|
947
906
|
function emitScriptedChunk(result, info) {
|
|
948
907
|
const text = isRecord(result) ? result["result"] : void 0;
|
|
949
908
|
if (typeof text === "string") info?.onChunk?.(text);
|
|
950
909
|
}
|
|
951
910
|
/**
|
|
952
|
-
* Executors that replay a script instead of calling a model. Every slot is
|
|
953
|
-
* provided, so any machine binds.
|
|
954
|
-
*
|
|
955
|
-
* Answers are keyed by the request's resolved name — its authored `name`, else
|
|
956
|
-
* the invoke `id` — and `"*"` serves anything unmatched.
|
|
957
|
-
* Entries for a name are consumed in order and the last one repeats forever, so
|
|
958
|
-
* a looping machine needs no extra option. A request the script has no route
|
|
959
|
-
* for throws an ordinary `Error` from inside the executor, which reaches the
|
|
960
|
-
* machine as an actor error.
|
|
961
|
-
*
|
|
962
|
-
* Queues are copied on creation, so the caller's arrays are never mutated and
|
|
963
|
-
* each call builds a fresh, independent playthrough. Entries may be plain
|
|
964
|
-
* values or functions of the request.
|
|
965
|
-
*
|
|
966
|
-
* @example
|
|
967
|
-
* ```ts
|
|
968
|
-
* const result = await runAgent(moderationMachine, {
|
|
969
|
-
* input: { comment: 'honestly this update is terrible', trust: 20 },
|
|
970
|
-
* executors: createScriptedExecutors({
|
|
971
|
-
* decisions: { moderate: [{ type: 'FLAG', reason: 'Borderline tone.' }] },
|
|
972
|
-
* }),
|
|
973
|
-
* });
|
|
974
|
-
* ```
|
|
975
|
-
*
|
|
976
|
-
* @example Dynamic entries
|
|
977
|
-
* ```ts
|
|
978
|
-
* createScriptedExecutors({
|
|
979
|
-
* text: { draft: (request) => `Draft about ${request.prompt}` },
|
|
980
|
-
* decisions: { route: (request) => ({ type: request.events[0]!.type }) },
|
|
981
|
-
* });
|
|
982
|
-
* ```
|
|
983
|
-
*/
|
|
984
|
-
function createScriptedExecutors(script = {}) {
|
|
985
|
-
const decisions = toQueues(script.decisions);
|
|
986
|
-
const text = toQueues(script.text);
|
|
987
|
-
const calls = [];
|
|
988
|
-
const withDefaultUsage = (result) => result.usage || !script.usage ? result : {
|
|
989
|
-
...result,
|
|
990
|
-
usage: script.usage
|
|
991
|
-
};
|
|
992
|
-
const nextText = async (kind, request, info) => {
|
|
993
|
-
const name = request.name ?? "*";
|
|
994
|
-
calls.push({
|
|
995
|
-
kind,
|
|
996
|
-
name,
|
|
997
|
-
input: request.input,
|
|
998
|
-
request
|
|
999
|
-
});
|
|
1000
|
-
const entry = takeEntry(text, name);
|
|
1001
|
-
if (entry === void 0) throw noAnswer(name, text);
|
|
1002
|
-
return withDefaultUsage(await resolveScriptedTextEntry(entry, request, info));
|
|
1003
|
-
};
|
|
1004
|
-
return {
|
|
1005
|
-
calls,
|
|
1006
|
-
generateText: (request, info) => nextText("generateText", request, info),
|
|
1007
|
-
streamText: async (request, info) => {
|
|
1008
|
-
const name = request.name ?? "*";
|
|
1009
|
-
const streamEntry = script.stream?.[name] ?? script.stream?.["*"];
|
|
1010
|
-
if (streamEntry !== void 0) {
|
|
1011
|
-
calls.push({
|
|
1012
|
-
kind: "streamText",
|
|
1013
|
-
name,
|
|
1014
|
-
input: request.input,
|
|
1015
|
-
request
|
|
1016
|
-
});
|
|
1017
|
-
const resolved = typeof streamEntry === "function" ? await streamEntry(request, info) : streamEntry;
|
|
1018
|
-
const chunks = typeof resolved === "string" ? [resolved] : [...resolved];
|
|
1019
|
-
for (const chunk of chunks) info?.onChunk?.(chunk);
|
|
1020
|
-
return withDefaultUsage({ result: chunks.join("") });
|
|
1021
|
-
}
|
|
1022
|
-
const result = await nextText("streamText", request, info);
|
|
1023
|
-
emitScriptedChunk(result, info);
|
|
1024
|
-
return result;
|
|
1025
|
-
},
|
|
1026
|
-
decide: async (request) => {
|
|
1027
|
-
const name = request.name ?? request.id;
|
|
1028
|
-
calls.push({
|
|
1029
|
-
kind: "decide",
|
|
1030
|
-
name,
|
|
1031
|
-
input: request.input,
|
|
1032
|
-
request
|
|
1033
|
-
});
|
|
1034
|
-
const entry = takeEntry(decisions, name);
|
|
1035
|
-
if (entry === void 0) throw noAnswer(name, decisions);
|
|
1036
|
-
const value = typeof entry === "function" ? await entry(request) : entry;
|
|
1037
|
-
return withDefaultUsage(isRecord(value) && typeof value["type"] !== "string" && "event" in value ? value : { event: value });
|
|
1038
|
-
}
|
|
1039
|
-
};
|
|
1040
|
-
}
|
|
1041
|
-
//#endregion
|
|
1042
|
-
//#region src/seam.ts
|
|
1043
|
-
/**
|
|
1044
911
|
* The seam's own answer, for scoring: the executor result's `result`.
|
|
1045
912
|
* @internal
|
|
1046
913
|
*/
|
|
@@ -1062,8 +929,8 @@ async function seamOutputOf(result, request) {
|
|
|
1062
929
|
* @example No API key: the seam is scripted too, so the whole thing runs offline.
|
|
1063
930
|
* ```ts
|
|
1064
931
|
* const run = await runSeam(emailDrafter, {
|
|
1065
|
-
* scripts: {
|
|
1066
|
-
* seam: { request: '
|
|
932
|
+
* scripts: { writeFollowUps: [followUps], emailDrafter: [draft] },
|
|
933
|
+
* seam: { request: 'writeFollowUps' },
|
|
1067
934
|
* respond: ({ state }) => (state === 'prompting' ? { type: 'PROMPT_SUBMITTED', prompt } : null),
|
|
1068
935
|
* });
|
|
1069
936
|
*
|
|
@@ -1099,7 +966,7 @@ async function runSeam(machine, options) {
|
|
|
1099
966
|
const takeScriptedSlot = async (request, info) => {
|
|
1100
967
|
const queue = queues.get(queueKeyOf(request));
|
|
1101
968
|
if (!queue?.length) return;
|
|
1102
|
-
return
|
|
969
|
+
return resolveSeamScriptEntry(options.repeatLast && queue.length === 1 ? queue[0] : queue.shift(), request, info);
|
|
1103
970
|
};
|
|
1104
971
|
const scriptedAnswer = async (request, info) => {
|
|
1105
972
|
const scripted = await takeScriptedSlot(request, info);
|
|
@@ -1209,4 +1076,4 @@ async function runSeam(machine, options) {
|
|
|
1209
1076
|
};
|
|
1210
1077
|
}
|
|
1211
1078
|
//#endregion
|
|
1212
|
-
export { AgentLintError, AgentUnknownStateError, assertAgentMachine, canReach,
|
|
1079
|
+
export { AgentLintError, AgentUnknownStateError, assertAgentMachine, canReach, explorePaths, lintAgentMachine, matchesTrajectory, runSeam, simulateAgent };
|
|
@@ -1,106 +1,6 @@
|
|
|
1
|
-
import { C as UserMessage, S as ToolResultPart, _ as StandardSchemaV1, b as ToolCallPart, f as FilePart, l as AssistantMessage, n as AgentMessage, p as ImagePart,
|
|
2
|
-
import { M as AgentDecisionRequest, c as AgentRequestExecutorInfo, f as AgentTextRequest, t as AgentCallUsage, u as AgentRequestExecutors } from "./text-logic-hZSiRUo1.mjs";
|
|
1
|
+
import { C as UserMessage, S as ToolResultPart, _ as StandardSchemaV1, b as ToolCallPart, f as FilePart, l as AssistantMessage, n as AgentMessage, p as ImagePart, v as SystemMessage, x as ToolMessage, y as TextPart } from "./types-tA3SdczG.mjs";
|
|
3
2
|
import { AnyMachineSnapshot, AnyStateMachine, StateValue } from "xstate";
|
|
4
3
|
|
|
5
|
-
//#region src/scripted-executors.d.ts
|
|
6
|
-
/**
|
|
7
|
-
* A scripted `decide` answer: either the {@link ChosenEvent} itself (an object
|
|
8
|
-
* with a string `type`), or the executor result `{ event, reason?, usage? }`
|
|
9
|
-
* when the entry also reports a `reason` or token `usage`.
|
|
10
|
-
*/
|
|
11
|
-
type ScriptedDecisionValue = ChosenEvent | {
|
|
12
|
-
event: ChosenEvent;
|
|
13
|
-
reason?: string;
|
|
14
|
-
usage?: AgentCallUsage;
|
|
15
|
-
};
|
|
16
|
-
/**
|
|
17
|
-
* One scripted `decide` answer, or a function of the
|
|
18
|
-
* {@link AgentDecisionRequest} returning one (for choices that depend on the
|
|
19
|
-
* prompt, the candidate `events`, or the prior failed `attempts`).
|
|
20
|
-
*/
|
|
21
|
-
type ScriptedDecisionEntry = ScriptedDecisionValue | ((request: AgentDecisionRequest) => ScriptedDecisionValue | PromiseLike<ScriptedDecisionValue>);
|
|
22
|
-
/**
|
|
23
|
-
* One scripted text answer: the request's output value (a string, or the
|
|
24
|
-
* object a structured request declares), or a function of the
|
|
25
|
-
* {@link AgentTextRequest} returning one.
|
|
26
|
-
*
|
|
27
|
-
* An entry is taken as the executor result (instead of the value itself)
|
|
28
|
-
* only when its OWN keys are a `result` plus, optionally, `messages`/`usage`/
|
|
29
|
-
* `raw` — that is how an entry reports token `usage`. Anything else, including
|
|
30
|
-
* an object that merely happens to have a `result` key alongside its own data
|
|
31
|
-
* (`{ result: 'draft', confidence: 0.9 }`), is the output value. For a
|
|
32
|
-
* structured request whose declared output is exactly `{ result }` (or
|
|
33
|
-
* `{ result, usage }`), wrap it once more: `{ result: { result: '…' } }`.
|
|
34
|
-
*/
|
|
35
|
-
type ScriptedTextEntry = ((request: AgentTextRequest, info?: AgentRequestExecutorInfo) => unknown) | string | number | boolean | null | object;
|
|
36
|
-
/**
|
|
37
|
-
* A request-name keyed script. The key is the request's resolved `name` — the
|
|
38
|
-
* authored name, else the invoke `id`. `"*"` is the fallback route.
|
|
39
|
-
*/
|
|
40
|
-
type ScriptedByName<TEntry> = Record<string, TEntry | TEntry[]>;
|
|
41
|
-
/** One scripted stream call: chunks, or a function producing chunks. */
|
|
42
|
-
type ScriptedStreamEntry = string | readonly string[] | ((request: AgentTextRequest, info?: AgentRequestExecutorInfo) => string | readonly string[] | PromiseLike<string | readonly string[]>);
|
|
43
|
-
/** A call observed by {@link createScriptedExecutors}. */
|
|
44
|
-
interface ScriptedExecutorCall {
|
|
45
|
-
kind: "generateText" | "streamText" | "decide";
|
|
46
|
-
name: string;
|
|
47
|
-
input: unknown;
|
|
48
|
-
request: AgentTextRequest | AgentDecisionRequest;
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* The script {@link createScriptedExecutors} plays back. Every channel is
|
|
52
|
-
* keyed by request name and consumed in order; the last entry for a name
|
|
53
|
-
* repeats forever.
|
|
54
|
-
*/
|
|
55
|
-
interface ScriptedExecutorsScript {
|
|
56
|
-
/** Answers for `decide` requests, keyed by request name. */
|
|
57
|
-
decisions?: ScriptedByName<ScriptedDecisionEntry>;
|
|
58
|
-
/** Answers for generate requests, keyed by request name. */
|
|
59
|
-
text?: ScriptedByName<ScriptedTextEntry>;
|
|
60
|
-
/** Stream chunks keyed by request name. */
|
|
61
|
-
stream?: Record<string, ScriptedStreamEntry>;
|
|
62
|
-
/** Default usage attached when an entry does not provide its own. */
|
|
63
|
-
usage?: AgentCallUsage;
|
|
64
|
-
}
|
|
65
|
-
/** What {@link createScriptedExecutors} returns: the full executor set plus the calls it observed. */
|
|
66
|
-
type ScriptedExecutors = Required<AgentRequestExecutors> & {
|
|
67
|
-
calls: ScriptedExecutorCall[];
|
|
68
|
-
};
|
|
69
|
-
/**
|
|
70
|
-
* Executors that replay a script instead of calling a model. Every slot is
|
|
71
|
-
* provided, so any machine binds.
|
|
72
|
-
*
|
|
73
|
-
* Answers are keyed by the request's resolved name — its authored `name`, else
|
|
74
|
-
* the invoke `id` — and `"*"` serves anything unmatched.
|
|
75
|
-
* Entries for a name are consumed in order and the last one repeats forever, so
|
|
76
|
-
* a looping machine needs no extra option. A request the script has no route
|
|
77
|
-
* for throws an ordinary `Error` from inside the executor, which reaches the
|
|
78
|
-
* machine as an actor error.
|
|
79
|
-
*
|
|
80
|
-
* Queues are copied on creation, so the caller's arrays are never mutated and
|
|
81
|
-
* each call builds a fresh, independent playthrough. Entries may be plain
|
|
82
|
-
* values or functions of the request.
|
|
83
|
-
*
|
|
84
|
-
* @example
|
|
85
|
-
* ```ts
|
|
86
|
-
* const result = await runAgent(moderationMachine, {
|
|
87
|
-
* input: { comment: 'honestly this update is terrible', trust: 20 },
|
|
88
|
-
* executors: createScriptedExecutors({
|
|
89
|
-
* decisions: { moderate: [{ type: 'FLAG', reason: 'Borderline tone.' }] },
|
|
90
|
-
* }),
|
|
91
|
-
* });
|
|
92
|
-
* ```
|
|
93
|
-
*
|
|
94
|
-
* @example Dynamic entries
|
|
95
|
-
* ```ts
|
|
96
|
-
* createScriptedExecutors({
|
|
97
|
-
* text: { draft: (request) => `Draft about ${request.prompt}` },
|
|
98
|
-
* decisions: { route: (request) => ({ type: request.events[0]!.type }) },
|
|
99
|
-
* });
|
|
100
|
-
* ```
|
|
101
|
-
*/
|
|
102
|
-
declare function createScriptedExecutors(script?: ScriptedExecutorsScript): ScriptedExecutors;
|
|
103
|
-
//#endregion
|
|
104
4
|
//#region src/utils.d.ts
|
|
105
5
|
/** Returns the human-readable text carried by a message, ignoring non-text parts. */
|
|
106
6
|
declare function getMessageText(message: AgentMessage): string;
|
|
@@ -206,4 +106,4 @@ declare function getJsonSchema(schema?: StandardSchemaV1): Promise<Record<string
|
|
|
206
106
|
*/
|
|
207
107
|
declare function getJsonSchemaSync(schema?: StandardSchemaV1): Record<string, unknown> | undefined;
|
|
208
108
|
//#endregion
|
|
209
|
-
export {
|
|
109
|
+
export { getMachineStructuralHash as a, getStatePath as c, toolMessage as d, userMessage as f, getJsonSchemaSync as i, isStandardSchema as l, assistantMessage as n, getMessageText as o, getJsonSchema as r, getStateMeta as s, MetaOfSnapshot as t, systemMessage as u };
|
|
@@ -1,106 +1,6 @@
|
|
|
1
|
-
import { C as UserMessage, S as ToolResultPart, _ as StandardSchemaV1, b as ToolCallPart, f as FilePart, l as AssistantMessage, n as AgentMessage, p as ImagePart,
|
|
2
|
-
import { M as AgentDecisionRequest, c as AgentRequestExecutorInfo, f as AgentTextRequest, t as AgentCallUsage, u as AgentRequestExecutors } from "./text-logic-BFEOxyxv.cjs";
|
|
1
|
+
import { C as UserMessage, S as ToolResultPart, _ as StandardSchemaV1, b as ToolCallPart, f as FilePart, l as AssistantMessage, n as AgentMessage, p as ImagePart, v as SystemMessage, x as ToolMessage, y as TextPart } from "./types-B1Qs2q3q.cjs";
|
|
3
2
|
import { AnyMachineSnapshot, AnyStateMachine, StateValue } from "xstate";
|
|
4
3
|
|
|
5
|
-
//#region src/scripted-executors.d.ts
|
|
6
|
-
/**
|
|
7
|
-
* A scripted `decide` answer: either the {@link ChosenEvent} itself (an object
|
|
8
|
-
* with a string `type`), or the executor result `{ event, reason?, usage? }`
|
|
9
|
-
* when the entry also reports a `reason` or token `usage`.
|
|
10
|
-
*/
|
|
11
|
-
type ScriptedDecisionValue = ChosenEvent | {
|
|
12
|
-
event: ChosenEvent;
|
|
13
|
-
reason?: string;
|
|
14
|
-
usage?: AgentCallUsage;
|
|
15
|
-
};
|
|
16
|
-
/**
|
|
17
|
-
* One scripted `decide` answer, or a function of the
|
|
18
|
-
* {@link AgentDecisionRequest} returning one (for choices that depend on the
|
|
19
|
-
* prompt, the candidate `events`, or the prior failed `attempts`).
|
|
20
|
-
*/
|
|
21
|
-
type ScriptedDecisionEntry = ScriptedDecisionValue | ((request: AgentDecisionRequest) => ScriptedDecisionValue | PromiseLike<ScriptedDecisionValue>);
|
|
22
|
-
/**
|
|
23
|
-
* One scripted text answer: the request's output value (a string, or the
|
|
24
|
-
* object a structured request declares), or a function of the
|
|
25
|
-
* {@link AgentTextRequest} returning one.
|
|
26
|
-
*
|
|
27
|
-
* An entry is taken as the executor result (instead of the value itself)
|
|
28
|
-
* only when its OWN keys are a `result` plus, optionally, `messages`/`usage`/
|
|
29
|
-
* `raw` — that is how an entry reports token `usage`. Anything else, including
|
|
30
|
-
* an object that merely happens to have a `result` key alongside its own data
|
|
31
|
-
* (`{ result: 'draft', confidence: 0.9 }`), is the output value. For a
|
|
32
|
-
* structured request whose declared output is exactly `{ result }` (or
|
|
33
|
-
* `{ result, usage }`), wrap it once more: `{ result: { result: '…' } }`.
|
|
34
|
-
*/
|
|
35
|
-
type ScriptedTextEntry = ((request: AgentTextRequest, info?: AgentRequestExecutorInfo) => unknown) | string | number | boolean | null | object;
|
|
36
|
-
/**
|
|
37
|
-
* A request-name keyed script. The key is the request's resolved `name` — the
|
|
38
|
-
* authored name, else the invoke `id`. `"*"` is the fallback route.
|
|
39
|
-
*/
|
|
40
|
-
type ScriptedByName<TEntry> = Record<string, TEntry | TEntry[]>;
|
|
41
|
-
/** One scripted stream call: chunks, or a function producing chunks. */
|
|
42
|
-
type ScriptedStreamEntry = string | readonly string[] | ((request: AgentTextRequest, info?: AgentRequestExecutorInfo) => string | readonly string[] | PromiseLike<string | readonly string[]>);
|
|
43
|
-
/** A call observed by {@link createScriptedExecutors}. */
|
|
44
|
-
interface ScriptedExecutorCall {
|
|
45
|
-
kind: "generateText" | "streamText" | "decide";
|
|
46
|
-
name: string;
|
|
47
|
-
input: unknown;
|
|
48
|
-
request: AgentTextRequest | AgentDecisionRequest;
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* The script {@link createScriptedExecutors} plays back. Every channel is
|
|
52
|
-
* keyed by request name and consumed in order; the last entry for a name
|
|
53
|
-
* repeats forever.
|
|
54
|
-
*/
|
|
55
|
-
interface ScriptedExecutorsScript {
|
|
56
|
-
/** Answers for `decide` requests, keyed by request name. */
|
|
57
|
-
decisions?: ScriptedByName<ScriptedDecisionEntry>;
|
|
58
|
-
/** Answers for generate requests, keyed by request name. */
|
|
59
|
-
text?: ScriptedByName<ScriptedTextEntry>;
|
|
60
|
-
/** Stream chunks keyed by request name. */
|
|
61
|
-
stream?: Record<string, ScriptedStreamEntry>;
|
|
62
|
-
/** Default usage attached when an entry does not provide its own. */
|
|
63
|
-
usage?: AgentCallUsage;
|
|
64
|
-
}
|
|
65
|
-
/** What {@link createScriptedExecutors} returns: the full executor set plus the calls it observed. */
|
|
66
|
-
type ScriptedExecutors = Required<AgentRequestExecutors> & {
|
|
67
|
-
calls: ScriptedExecutorCall[];
|
|
68
|
-
};
|
|
69
|
-
/**
|
|
70
|
-
* Executors that replay a script instead of calling a model. Every slot is
|
|
71
|
-
* provided, so any machine binds.
|
|
72
|
-
*
|
|
73
|
-
* Answers are keyed by the request's resolved name — its authored `name`, else
|
|
74
|
-
* the invoke `id` — and `"*"` serves anything unmatched.
|
|
75
|
-
* Entries for a name are consumed in order and the last one repeats forever, so
|
|
76
|
-
* a looping machine needs no extra option. A request the script has no route
|
|
77
|
-
* for throws an ordinary `Error` from inside the executor, which reaches the
|
|
78
|
-
* machine as an actor error.
|
|
79
|
-
*
|
|
80
|
-
* Queues are copied on creation, so the caller's arrays are never mutated and
|
|
81
|
-
* each call builds a fresh, independent playthrough. Entries may be plain
|
|
82
|
-
* values or functions of the request.
|
|
83
|
-
*
|
|
84
|
-
* @example
|
|
85
|
-
* ```ts
|
|
86
|
-
* const result = await runAgent(moderationMachine, {
|
|
87
|
-
* input: { comment: 'honestly this update is terrible', trust: 20 },
|
|
88
|
-
* executors: createScriptedExecutors({
|
|
89
|
-
* decisions: { moderate: [{ type: 'FLAG', reason: 'Borderline tone.' }] },
|
|
90
|
-
* }),
|
|
91
|
-
* });
|
|
92
|
-
* ```
|
|
93
|
-
*
|
|
94
|
-
* @example Dynamic entries
|
|
95
|
-
* ```ts
|
|
96
|
-
* createScriptedExecutors({
|
|
97
|
-
* text: { draft: (request) => `Draft about ${request.prompt}` },
|
|
98
|
-
* decisions: { route: (request) => ({ type: request.events[0]!.type }) },
|
|
99
|
-
* });
|
|
100
|
-
* ```
|
|
101
|
-
*/
|
|
102
|
-
declare function createScriptedExecutors(script?: ScriptedExecutorsScript): ScriptedExecutors;
|
|
103
|
-
//#endregion
|
|
104
4
|
//#region src/utils.d.ts
|
|
105
5
|
/** Returns the human-readable text carried by a message, ignoring non-text parts. */
|
|
106
6
|
declare function getMessageText(message: AgentMessage): string;
|
|
@@ -206,4 +106,4 @@ declare function getJsonSchema(schema?: StandardSchemaV1): Promise<Record<string
|
|
|
206
106
|
*/
|
|
207
107
|
declare function getJsonSchemaSync(schema?: StandardSchemaV1): Record<string, unknown> | undefined;
|
|
208
108
|
//#endregion
|
|
209
|
-
export {
|
|
109
|
+
export { getMachineStructuralHash as a, getStatePath as c, toolMessage as d, userMessage as f, getJsonSchemaSync as i, isStandardSchema as l, assistantMessage as n, getMessageText as o, getJsonSchema as r, getStateMeta as s, MetaOfSnapshot as t, systemMessage as u };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@statelyai/agent",
|
|
3
|
-
"version": "2.0.0-alpha.
|
|
3
|
+
"version": "2.0.0-alpha.26",
|
|
4
4
|
"description": "Make invalid agent actions impossible. Agent logic as state machines: deterministic, inspectable, resumable, runs anywhere.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"agent",
|
|
@@ -115,6 +115,7 @@
|
|
|
115
115
|
},
|
|
116
116
|
"devDependencies": {
|
|
117
117
|
"@ai-sdk/openai": "^4.0.0",
|
|
118
|
+
"@ai-sdk/typesafe-ai": "3.0.6",
|
|
118
119
|
"@anthropic-ai/sdk": "^0.120.0",
|
|
119
120
|
"@changesets/changelog-github": "^0.5.2",
|
|
120
121
|
"@changesets/cli": "^2.31.1",
|
|
@@ -128,7 +129,7 @@
|
|
|
128
129
|
"@opentelemetry/sdk-trace-base": "^2.10.0",
|
|
129
130
|
"@types/node": "^20.19.43",
|
|
130
131
|
"@types/react": "^19.2.18",
|
|
131
|
-
"ai": "^7.0.
|
|
132
|
+
"ai": "^7.0.113",
|
|
132
133
|
"ajv": "^8.20.0",
|
|
133
134
|
"braintrust": "^3.28.0",
|
|
134
135
|
"dotenv": "^16.6.1",
|
package/readme.md
CHANGED
|
@@ -40,6 +40,8 @@ For the optional raw OpenAI SDK executor (`@statelyai/agent/openai`):
|
|
|
40
40
|
pnpm add openai
|
|
41
41
|
```
|
|
42
42
|
|
|
43
|
+
Classification, grading, relevance, and yes/no checks are judgments: call the AI SDK's `experimental_evaluate` with `@ai-sdk/typesafe-ai` (`pnpm add ai @ai-sdk/typesafe-ai`) from an ordinary actor; see [Judgments with the AI SDK](docs/judgments.md).
|
|
44
|
+
|
|
43
45
|
Requirements:
|
|
44
46
|
|
|
45
47
|
- Node 22.18 or newer, and XState v6 alpha.46 or newer.
|
|
@@ -139,7 +141,7 @@ const liveResult = await runAgent(refundMachine, {
|
|
|
139
141
|
});
|
|
140
142
|
```
|
|
141
143
|
|
|
142
|
-
For a machine with several requests, `
|
|
144
|
+
For a machine with several requests, the executor routes on `request.name`, or `MockLanguageModelV3` from `ai/test` stands in for the provider behind `createAiSdkExecutors`. See [Evals](docs/evals.md#testing-without-a-provider).
|
|
143
145
|
|
|
144
146
|
Passing the same `models` map to `setupAgent({ models })` types the machine's model refs. Executors are always explicit, and core does not import the AI SDK. See [Hosts and executors](docs/hosts.md).
|
|
145
147
|
|
|
@@ -155,7 +157,7 @@ flowchart LR
|
|
|
155
157
|
R -->|event or output| M
|
|
156
158
|
```
|
|
157
159
|
|
|
158
|
-
The machine never talks to a model directly, so swapping `createAiSdkExecutors` for
|
|
160
|
+
The machine never talks to a model directly, so swapping `createAiSdkExecutors` for your own functions changes nothing about the agent.
|
|
159
161
|
|
|
160
162
|
The example above has one model decision and two final outcomes. Real machines add approval states, retries, parallel work, child agents, and long-running waits without changing how control flow is represented.
|
|
161
163
|
|