@maxanstey-meridian/tandem 0.1.6 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/dist/index.d.ts +86 -72
  2. package/dist/index.js +656 -894
  3. package/package.json +3 -1
package/dist/index.d.ts CHANGED
@@ -30,8 +30,8 @@ declare class CallbackRegistry {
30
30
  #private;
31
31
  registerSync(callback: SyncCallback): string;
32
32
  registerAsync(callback: AsyncCallback): string;
33
- invokeSync(id: string, state: string, input: string): string;
34
- invokeAsync(id: string, state: string, input: string, signal: AbortSignal): Promise<string>;
33
+ /** Never throws: failures travel back to the bridge as an encoded `CallbackResult`. */
34
+ invoke(id: string, state: string, input: string, signal: AbortSignal): string | Promise<string>;
35
35
  dispose(): void;
36
36
  }
37
37
  interface Participant<TState> {
@@ -56,13 +56,14 @@ export interface Terminal<TState> extends Participant<TState> {
56
56
  readonly kind: "terminal";
57
57
  }
58
58
  type Node<TState> = Collection<TState> | Stage<TState> | Interaction<TState, unknown, unknown> | Agent<TState> | Parallel<TState> | Terminal<TState>;
59
- export declare function stage<TState>(definition: {
59
+ type StageDefinition<TState> = {
60
60
  id: string;
61
61
  execute: (state: TState, context: {
62
62
  readonly signal: AbortSignal;
63
63
  }) => TState | Promise<TState>;
64
64
  persist?: boolean;
65
- }): Stage<TState>;
65
+ };
66
+ export declare function stage<TState>(definition: StageDefinition<TState>): Stage<TState>;
66
67
  declare const taskAgentBrand: unique symbol;
67
68
  export interface TaskAgentReference {
68
69
  readonly id: string;
@@ -252,12 +253,13 @@ type ParallelDefinition<TState, TBranches extends ParallelBranches<TState>> = {
252
253
  };
253
254
  export declare function parallel<TState>(): <const TBranches extends ParallelBranches<TState>>(definition: ParallelDefinition<TState, TBranches>) => Parallel<TState>;
254
255
  export declare function parallel<TState, const TBranches extends ParallelBranches<TState>>(definition: ParallelDefinition<TState, TBranches>): Parallel<TState>;
255
- export declare function output<TState>(definition: {
256
+ type TerminalDefinition<TState> = {
256
257
  id: string;
257
258
  summary: (state: TState) => string;
258
259
  failed?: boolean;
259
260
  persist?: boolean;
260
- }): Terminal<TState>;
261
+ };
262
+ export declare function output<TState>(definition: TerminalDefinition<TState>): Terminal<TState>;
261
263
  export interface OrdinaryRoute<TState> {
262
264
  readonly from: Stage<TState> | Collection<TState> | Interaction<TState, unknown, unknown>;
263
265
  readonly to: Node<TState>;
@@ -342,60 +344,6 @@ export interface RunResult<TState> {
342
344
  readonly state: TState;
343
345
  readonly summary: string | null;
344
346
  }
345
- export type RunObservation = {
346
- readonly visitId?: string | null;
347
- } & ({
348
- readonly version: 1;
349
- readonly kind: "stepStarted";
350
- readonly stepId: string;
351
- } | {
352
- readonly version: 1;
353
- readonly kind: "stepCompleted";
354
- readonly stepId: string;
355
- } | {
356
- readonly version: 1;
357
- readonly kind: "stepCancelled";
358
- readonly stepId: string;
359
- } | {
360
- readonly version: 1;
361
- readonly kind: "stepFaulted";
362
- readonly stepId: string;
363
- readonly error: string;
364
- } | {
365
- readonly version: 1;
366
- readonly kind: "agentText";
367
- readonly stepId: string;
368
- readonly text: string;
369
- } | {
370
- readonly version: 1;
371
- readonly kind: "agentReasoning";
372
- readonly stepId: string;
373
- readonly text: string;
374
- } | {
375
- readonly version: 1;
376
- readonly kind: "agentModelSelected";
377
- readonly stepId: string;
378
- readonly modelId: string;
379
- } | {
380
- readonly version: 1;
381
- readonly kind: "agentUsage";
382
- readonly stepId: string;
383
- readonly inputTokens: number;
384
- readonly outputTokens: number;
385
- readonly reasoningTokens: number;
386
- readonly currentContextTokens: number;
387
- readonly contextWindowTokens: number | null;
388
- } | {
389
- readonly version: 1;
390
- readonly kind: "structuredOutputRejected";
391
- readonly stepId: string;
392
- readonly attempt: number;
393
- readonly problems: readonly {
394
- readonly field: string;
395
- readonly message: string;
396
- }[];
397
- readonly rawResponse: string;
398
- });
399
347
  export interface TerminalPresentationOptions {
400
348
  readonly truncatedToolNames?: readonly string[];
401
349
  }
@@ -411,18 +359,84 @@ export interface RunOptions {
411
359
  readonly signal: AbortSignal;
412
360
  }) => void | Promise<void>;
413
361
  }
414
- declare const acceptedKinds: readonly ["StructuredOutputAccepted", "CapabilityAccepted", "InteractionRequested", "InteractionAnswered", "StepCompleted"];
415
- type AcceptedKind = (typeof acceptedKinds)[number];
416
- export type AcceptedValue = {
417
- [K in AcceptedKind]: {
418
- readonly version: 1;
419
- readonly kind: K;
420
- readonly stepId: string;
421
- readonly visitId?: string | null;
422
- readonly valueType: string | null;
423
- readonly payload: unknown | null;
424
- };
425
- }[AcceptedKind];
362
+ declare const runObservationSchema: z.ZodReadonly<z.ZodDiscriminatedUnion<[z.ZodObject<{
363
+ version: z.ZodLiteral<1>;
364
+ stepId: z.ZodString;
365
+ visitId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
366
+ kind: z.ZodLiteral<"stepStarted">;
367
+ }, z.core.$strict>, z.ZodObject<{
368
+ version: z.ZodLiteral<1>;
369
+ stepId: z.ZodString;
370
+ visitId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
371
+ kind: z.ZodLiteral<"stepCompleted">;
372
+ }, z.core.$strict>, z.ZodObject<{
373
+ version: z.ZodLiteral<1>;
374
+ stepId: z.ZodString;
375
+ visitId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
376
+ kind: z.ZodLiteral<"stepCancelled">;
377
+ }, z.core.$strict>, z.ZodObject<{
378
+ version: z.ZodLiteral<1>;
379
+ stepId: z.ZodString;
380
+ visitId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
381
+ kind: z.ZodLiteral<"stepFaulted">;
382
+ error: z.ZodString;
383
+ }, z.core.$strict>, z.ZodObject<{
384
+ version: z.ZodLiteral<1>;
385
+ stepId: z.ZodString;
386
+ visitId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
387
+ kind: z.ZodLiteral<"agentText">;
388
+ text: z.ZodString;
389
+ }, z.core.$strict>, z.ZodObject<{
390
+ version: z.ZodLiteral<1>;
391
+ stepId: z.ZodString;
392
+ visitId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
393
+ kind: z.ZodLiteral<"agentReasoning">;
394
+ text: z.ZodString;
395
+ }, z.core.$strict>, z.ZodObject<{
396
+ version: z.ZodLiteral<1>;
397
+ stepId: z.ZodString;
398
+ visitId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
399
+ kind: z.ZodLiteral<"agentModelSelected">;
400
+ modelId: z.ZodString;
401
+ }, z.core.$strict>, z.ZodObject<{
402
+ version: z.ZodLiteral<1>;
403
+ stepId: z.ZodString;
404
+ visitId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
405
+ kind: z.ZodLiteral<"agentUsage">;
406
+ inputTokens: z.ZodNumber;
407
+ outputTokens: z.ZodNumber;
408
+ reasoningTokens: z.ZodNumber;
409
+ currentContextTokens: z.ZodNumber;
410
+ contextWindowTokens: z.ZodNullable<z.ZodNumber>;
411
+ }, z.core.$strict>, z.ZodObject<{
412
+ version: z.ZodLiteral<1>;
413
+ stepId: z.ZodString;
414
+ visitId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
415
+ kind: z.ZodLiteral<"structuredOutputRejected">;
416
+ attempt: z.ZodNumber;
417
+ problems: z.ZodReadonly<z.ZodArray<z.ZodReadonly<z.ZodObject<{
418
+ field: z.ZodString;
419
+ message: z.ZodString;
420
+ }, z.core.$strict>>>>;
421
+ rawResponse: z.ZodString;
422
+ }, z.core.$strict>], "kind">>;
423
+ export type RunObservation = z.infer<typeof runObservationSchema>;
424
+ declare const acceptedValueFields: z.ZodObject<{
425
+ kind: z.ZodEnum<{
426
+ StructuredOutputAccepted: "StructuredOutputAccepted";
427
+ CapabilityAccepted: "CapabilityAccepted";
428
+ InteractionRequested: "InteractionRequested";
429
+ InteractionAnswered: "InteractionAnswered";
430
+ StepCompleted: "StepCompleted";
431
+ }>;
432
+ stepId: z.ZodString;
433
+ visitId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
434
+ valueType: z.ZodNullable<z.ZodString>;
435
+ payload: z.ZodUnknown;
436
+ }, z.core.$strict>;
437
+ export type AcceptedValue = Readonly<{
438
+ version: 1;
439
+ } & z.infer<typeof acceptedValueFields>>;
426
440
  export declare function inspectAccepted(options: {
427
441
  ledgerPath: string;
428
442
  runId: string;