@ekairos/events 1.22.81-beta.development.0 → 1.22.83-beta.development.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.
package/dist/codex.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { z } from "zod";
2
2
  import { createContext, defineAction } from "./context.js";
3
- import { didToolExecute } from "./context.toolcalls.js";
3
+ import { didActionExecute } from "./context.action-calls.js";
4
4
  export const DEFAULT_CODEX_TOOL_NAME = "codex";
5
5
  export const DEFAULT_CODEX_MODEL = "openai/gpt-5.2";
6
6
  export const codexToolInputSchema = z.object({
@@ -54,7 +54,7 @@ export function buildDefaultCodexNarrative(content) {
54
54
  ].join("\n");
55
55
  }
56
56
  export function didCodexToolExecute(event, toolName = DEFAULT_CODEX_TOOL_NAME) {
57
- return didToolExecute(event, toolName);
57
+ return didActionExecute(event, toolName);
58
58
  }
59
59
  export function createCodexContextBuilder(config) {
60
60
  const toolName = config.toolName ?? DEFAULT_CODEX_TOOL_NAME;
@@ -66,7 +66,7 @@ export function createCodexContextBuilder(config) {
66
66
  const model = config.model ??
67
67
  ((_ctx, env) => (typeof env.model === "string" && env.model.trim()) || DEFAULT_CODEX_MODEL);
68
68
  const shouldContinue = config.shouldContinue ??
69
- ((args) => !didToolExecute(args.reactionEvent, toolName));
69
+ ((args) => !didActionExecute(args.reactionEvent, toolName));
70
70
  let builder = createContext(config.key)
71
71
  .context(config.context)
72
72
  .narrative(narrative)
@@ -1,9 +1,9 @@
1
1
  /**
2
- * ## context.toolcalls.ts
2
+ * ## context.action-calls.ts
3
3
  *
4
4
  * This module isolates the **action-call plumbing** used by `context.engine.ts`.
5
5
  *
6
- * In our runtime, model tool calls are normalized into semantic `action` event parts.
6
+ * In our runtime, provider tool calls are normalized into semantic `action` event parts.
7
7
  * The engine needs to:
8
8
  * - extract a normalized list of action requests from `event.content.parts`, and
9
9
  * - merge action execution outcomes back into those parts.
@@ -12,9 +12,9 @@
12
12
  * these transformations testable and reusable.
13
13
  */
14
14
  import type { ContextItem } from "./context.store.js";
15
- export type ToolCall = {
16
- toolCallId: string;
17
- toolName: string;
15
+ export type ContextActionCall = {
16
+ actionCallId: string;
17
+ actionName: string;
18
18
  args: any;
19
19
  };
20
20
  /**
@@ -22,7 +22,7 @@ export type ToolCall = {
22
22
  *
23
23
  * Also accepts raw AI SDK tool UI parts before persistence normalization.
24
24
  */
25
- export declare function extractToolCallsFromParts(parts: any[] | undefined | null): ToolCall[];
25
+ export declare function extractActionCallsFromParts(parts: any[] | undefined | null): ContextActionCall[];
26
26
  /**
27
27
  * Applies an action execution outcome to the matching action part.
28
28
  *
@@ -30,19 +30,19 @@ export declare function extractToolCallsFromParts(parts: any[] | undefined | nul
30
30
  *
31
31
  * We match by action name and action call id.
32
32
  */
33
- export declare function applyToolExecutionResultToParts(parts: any[], toolCall: Pick<ToolCall, "toolCallId" | "toolName">, execution: {
33
+ export declare function applyActionExecutionResultToParts(parts: any[], actionCall: Pick<ContextActionCall, "actionCallId" | "actionName">, execution: {
34
34
  success: boolean;
35
35
  result: any;
36
36
  message?: string;
37
37
  }): any[];
38
38
  /**
39
- * Returns `true` when a given tool has a **settled** execution result in an event's parts.
39
+ * Returns `true` when a given action has a **settled** execution result in an event's parts.
40
40
  *
41
- * We treat a tool part as "executed" once it has either:
41
+ * We treat an action part as "executed" once it has either:
42
42
  * - `state: "output-available"` (success), or
43
43
  * - `state: "output-error"` (failure).
44
44
  *
45
45
  * This is useful for stop/continue logic in `context.shouldContinue(...)` where you want to
46
46
  * decide based on the persisted `reactionEvent` (not ephemeral in-memory arrays).
47
47
  */
48
- export declare function didToolExecute(event: Pick<ContextItem, "content">, toolName: string): boolean;
48
+ export declare function didActionExecute(event: Pick<ContextItem, "content">, actionName: string): boolean;
@@ -1,9 +1,9 @@
1
1
  /**
2
- * ## context.toolcalls.ts
2
+ * ## context.action-calls.ts
3
3
  *
4
4
  * This module isolates the **action-call plumbing** used by `context.engine.ts`.
5
5
  *
6
- * In our runtime, model tool calls are normalized into semantic `action` event parts.
6
+ * In our runtime, provider tool calls are normalized into semantic `action` event parts.
7
7
  * The engine needs to:
8
8
  * - extract a normalized list of action requests from `event.content.parts`, and
9
9
  * - merge action execution outcomes back into those parts.
@@ -17,20 +17,20 @@ import { isContextPartEnvelope, normalizePartsForPersistence, } from "./context.
17
17
  *
18
18
  * Also accepts raw AI SDK tool UI parts before persistence normalization.
19
19
  */
20
- export function extractToolCallsFromParts(parts) {
20
+ export function extractActionCallsFromParts(parts) {
21
21
  const safeParts = parts ?? [];
22
22
  return safeParts.reduce((acc, p) => {
23
23
  if (isContextPartEnvelope(p) && p.type === "action" && p.content.status === "started") {
24
24
  acc.push({
25
- toolCallId: p.content.actionCallId,
26
- toolName: p.content.actionName,
25
+ actionCallId: p.content.actionCallId,
26
+ actionName: p.content.actionName,
27
27
  args: p.content.input,
28
28
  });
29
29
  return acc;
30
30
  }
31
31
  if (typeof p?.type === "string" && p.type.startsWith("tool-")) {
32
- const toolName = p.type.split("-").slice(1).join("-");
33
- acc.push({ toolCallId: p.toolCallId, toolName, args: p.input });
32
+ const actionName = p.type.split("-").slice(1).join("-");
33
+ acc.push({ actionCallId: p.toolCallId, actionName, args: p.input });
34
34
  }
35
35
  return acc;
36
36
  }, []);
@@ -42,7 +42,7 @@ export function extractToolCallsFromParts(parts) {
42
42
  *
43
43
  * We match by action name and action call id.
44
44
  */
45
- export function applyToolExecutionResultToParts(parts, toolCall, execution) {
45
+ export function applyActionExecutionResultToParts(parts, actionCall, execution) {
46
46
  const normalized = normalizePartsForPersistence(parts);
47
47
  const next = [];
48
48
  let insertedResult = false;
@@ -51,8 +51,8 @@ export function applyToolExecutionResultToParts(parts, toolCall, execution) {
51
51
  if (part.type !== "action" || part.content.status !== "started") {
52
52
  continue;
53
53
  }
54
- if (part.content.actionCallId !== toolCall.toolCallId ||
55
- part.content.actionName !== toolCall.toolName) {
54
+ if (part.content.actionCallId !== actionCall.actionCallId ||
55
+ part.content.actionName !== actionCall.actionName) {
56
56
  continue;
57
57
  }
58
58
  next.push(execution.success
@@ -60,8 +60,8 @@ export function applyToolExecutionResultToParts(parts, toolCall, execution) {
60
60
  type: "action",
61
61
  content: {
62
62
  status: "completed",
63
- actionCallId: toolCall.toolCallId,
64
- actionName: toolCall.toolName,
63
+ actionCallId: actionCall.actionCallId,
64
+ actionName: actionCall.actionName,
65
65
  output: execution.result,
66
66
  },
67
67
  }
@@ -69,8 +69,8 @@ export function applyToolExecutionResultToParts(parts, toolCall, execution) {
69
69
  type: "action",
70
70
  content: {
71
71
  status: "failed",
72
- actionCallId: toolCall.toolCallId,
73
- actionName: toolCall.toolName,
72
+ actionCallId: actionCall.actionCallId,
73
+ actionName: actionCall.actionName,
74
74
  error: {
75
75
  message: String(execution.message || "Error"),
76
76
  },
@@ -84,8 +84,8 @@ export function applyToolExecutionResultToParts(parts, toolCall, execution) {
84
84
  type: "action",
85
85
  content: {
86
86
  status: "completed",
87
- actionCallId: toolCall.toolCallId,
88
- actionName: toolCall.toolName,
87
+ actionCallId: actionCall.actionCallId,
88
+ actionName: actionCall.actionName,
89
89
  output: execution.result,
90
90
  },
91
91
  }
@@ -93,8 +93,8 @@ export function applyToolExecutionResultToParts(parts, toolCall, execution) {
93
93
  type: "action",
94
94
  content: {
95
95
  status: "failed",
96
- actionCallId: toolCall.toolCallId,
97
- actionName: toolCall.toolName,
96
+ actionCallId: actionCall.actionCallId,
97
+ actionName: actionCall.actionName,
98
98
  error: {
99
99
  message: String(execution.message || "Error"),
100
100
  },
@@ -104,20 +104,20 @@ export function applyToolExecutionResultToParts(parts, toolCall, execution) {
104
104
  return next;
105
105
  }
106
106
  /**
107
- * Returns `true` when a given tool has a **settled** execution result in an event's parts.
107
+ * Returns `true` when a given action has a **settled** execution result in an event's parts.
108
108
  *
109
- * We treat a tool part as "executed" once it has either:
109
+ * We treat an action part as "executed" once it has either:
110
110
  * - `state: "output-available"` (success), or
111
111
  * - `state: "output-error"` (failure).
112
112
  *
113
113
  * This is useful for stop/continue logic in `context.shouldContinue(...)` where you want to
114
114
  * decide based on the persisted `reactionEvent` (not ephemeral in-memory arrays).
115
115
  */
116
- export function didToolExecute(event, toolName) {
116
+ export function didActionExecute(event, actionName) {
117
117
  const parts = (event.content.parts ?? []).flatMap((part) => isContextPartEnvelope(part) ? [part] : normalizePartsForPersistence([part]));
118
118
  return parts.some((p) => (p.type === "action" &&
119
- p.content.actionName === toolName &&
119
+ p.content.actionName === actionName &&
120
120
  (p.content.status === "completed" || p.content.status === "failed")) ||
121
- (p.type === `tool-${toolName}` &&
121
+ (p.type === `tool-${actionName}` &&
122
122
  (p.state === "output-available" || p.state === "output-error")));
123
123
  }
@@ -1,4 +1,4 @@
1
- import type { DomainSchemaResult } from "@ekairos/domain";
1
+ import type { DomainLike } from "@ekairos/domain";
2
2
  import type { z } from "zod";
3
3
  import type { ContextEnvironment } from "./context.config.js";
4
4
  import type { ContextToolExecuteContext } from "./context.engine.js";
@@ -19,24 +19,24 @@ export type ContextProviderDefinedAction = {
19
19
  args?: Record<string, unknown>;
20
20
  auto?: boolean;
21
21
  };
22
- export type ContextActionExecuteParams<TInput extends ContextActionSchema, Context = any, Env extends ContextEnvironment = ContextEnvironment, RequiredDomain extends DomainSchemaResult = typeof eventsDomain, Runtime extends ContextRuntime<Env> = ContextRuntime<Env>> = ContextToolExecuteContext<Context, Env, RequiredDomain, Runtime> & {
22
+ export type ContextActionExecuteParams<TInput extends ContextActionSchema, Context = any, Env extends ContextEnvironment = ContextEnvironment, RequiredDomain extends DomainLike = typeof eventsDomain, Runtime extends ContextRuntime<Env> = ContextRuntime<Env>> = ContextToolExecuteContext<Context, Env, RequiredDomain, Runtime> & {
23
23
  input: z.output<TInput>;
24
24
  };
25
- export type DefineContextActionExecute<TInput extends ContextActionSchema, TOutput extends ContextActionSchema, Context = any, Env extends ContextEnvironment = ContextEnvironment, RequiredDomain extends DomainSchemaResult = typeof eventsDomain, Runtime extends ContextRuntime<Env> = ContextRuntime<Env>> = (params: ContextActionExecuteParams<TInput, Context, Env, RequiredDomain, Runtime>) => MaybePromise<z.output<TOutput>>;
26
- export type ContextActionExecute<TInput extends ContextActionSchema, TOutput extends ContextActionSchema, Context = any, Env extends ContextEnvironment = ContextEnvironment, RequiredDomain extends DomainSchemaResult = typeof eventsDomain, Runtime extends ContextRuntime<Env> = ContextRuntime<Env>> = DefineContextActionExecute<TInput, TOutput, Context, Env, RequiredDomain, Runtime>;
27
- export type LegacyContextActionExecute<TInput extends ContextActionSchema, TOutput extends ContextActionSchema, Context = any, Env extends ContextEnvironment = ContextEnvironment, RequiredDomain extends DomainSchemaResult = typeof eventsDomain, Runtime extends ContextRuntime<Env> = ContextRuntime<Env>> = (input: z.output<TInput>, context: ContextToolExecuteContext<Context, Env, RequiredDomain, Runtime>) => MaybePromise<z.output<TOutput>>;
28
- export type DefineContextActionDefinition<TInput extends ContextActionSchema, TOutput extends ContextActionSchema, Context = any, Env extends ContextEnvironment = ContextEnvironment, RequiredDomain extends DomainSchemaResult = typeof eventsDomain, Runtime extends ContextRuntime<Env> = ContextRuntime<Env>> = ContextActionBase & {
25
+ export type DefineContextActionExecute<TInput extends ContextActionSchema, TOutput extends ContextActionSchema, Context = any, Env extends ContextEnvironment = ContextEnvironment, RequiredDomain extends DomainLike = typeof eventsDomain, Runtime extends ContextRuntime<Env> = ContextRuntime<Env>> = (params: ContextActionExecuteParams<TInput, Context, Env, RequiredDomain, Runtime>) => MaybePromise<z.output<TOutput>>;
26
+ export type ContextActionExecute<TInput extends ContextActionSchema, TOutput extends ContextActionSchema, Context = any, Env extends ContextEnvironment = ContextEnvironment, RequiredDomain extends DomainLike = typeof eventsDomain, Runtime extends ContextRuntime<Env> = ContextRuntime<Env>> = DefineContextActionExecute<TInput, TOutput, Context, Env, RequiredDomain, Runtime>;
27
+ export type LegacyContextActionExecute<TInput extends ContextActionSchema, TOutput extends ContextActionSchema, Context = any, Env extends ContextEnvironment = ContextEnvironment, RequiredDomain extends DomainLike = typeof eventsDomain, Runtime extends ContextRuntime<Env> = ContextRuntime<Env>> = (input: z.output<TInput>, context: ContextToolExecuteContext<Context, Env, RequiredDomain, Runtime>) => MaybePromise<z.output<TOutput>>;
28
+ export type DefineContextActionDefinition<TInput extends ContextActionSchema, TOutput extends ContextActionSchema, Context = any, Env extends ContextEnvironment = ContextEnvironment, RequiredDomain extends DomainLike = typeof eventsDomain, Runtime extends ContextRuntime<Env> = ContextRuntime<Env>> = ContextActionBase & {
29
29
  input: TInput;
30
30
  output: TOutput;
31
31
  execute: DefineContextActionExecute<TInput, TOutput, Context, Env, RequiredDomain, Runtime>;
32
32
  };
33
- export type LegacyContextActionDefinition<TInput extends ContextActionSchema, TOutput extends ContextActionSchema, Context = any, Env extends ContextEnvironment = ContextEnvironment, RequiredDomain extends DomainSchemaResult = typeof eventsDomain, Runtime extends ContextRuntime<Env> = ContextRuntime<Env>> = ContextActionBase & {
33
+ export type LegacyContextActionDefinition<TInput extends ContextActionSchema, TOutput extends ContextActionSchema, Context = any, Env extends ContextEnvironment = ContextEnvironment, RequiredDomain extends DomainLike = typeof eventsDomain, Runtime extends ContextRuntime<Env> = ContextRuntime<Env>> = ContextActionBase & {
34
34
  input: TInput;
35
35
  output: TOutput;
36
36
  execute: LegacyContextActionExecute<TInput, TOutput, Context, Env, RequiredDomain, Runtime>;
37
37
  };
38
- export type ContextActionDefinition<TInput extends ContextActionSchema, TOutput extends ContextActionSchema, Context = any, Env extends ContextEnvironment = ContextEnvironment, RequiredDomain extends DomainSchemaResult = typeof eventsDomain, Runtime extends ContextRuntime<Env> = ContextRuntime<Env>> = DefineContextActionDefinition<TInput, TOutput, Context, Env, RequiredDomain, Runtime>;
39
- export type ContextAction<TInput extends ContextActionSchema = ContextActionSchema, TOutput extends ContextActionSchema = ContextActionSchema, Context = any, Env extends ContextEnvironment = ContextEnvironment, RequiredDomain extends DomainSchemaResult = typeof eventsDomain, Runtime extends ContextRuntime<Env> = ContextRuntime<Env>> = ContextActionBase & {
38
+ export type ContextActionDefinition<TInput extends ContextActionSchema, TOutput extends ContextActionSchema, Context = any, Env extends ContextEnvironment = ContextEnvironment, RequiredDomain extends DomainLike = typeof eventsDomain, Runtime extends ContextRuntime<Env> = ContextRuntime<Env>> = DefineContextActionDefinition<TInput, TOutput, Context, Env, RequiredDomain, Runtime>;
39
+ export type ContextAction<TInput extends ContextActionSchema = ContextActionSchema, TOutput extends ContextActionSchema = ContextActionSchema, Context = any, Env extends ContextEnvironment = ContextEnvironment, RequiredDomain extends DomainLike = typeof eventsDomain, Runtime extends ContextRuntime<Env> = ContextRuntime<Env>> = ContextActionBase & {
40
40
  input: TInput;
41
41
  output: TOutput;
42
42
  inputSchema: TInput;
@@ -44,12 +44,12 @@ export type ContextAction<TInput extends ContextActionSchema = ContextActionSche
44
44
  execute: LegacyContextActionExecute<TInput, TOutput, Context, Env, RequiredDomain, Runtime>;
45
45
  };
46
46
  export type AnyContextAction = ContextAction<ContextActionSchema, ContextActionSchema, any, any, any, any>;
47
- export type ContextTool<Context = any, Env extends ContextEnvironment = ContextEnvironment, RequiredDomain extends DomainSchemaResult = typeof eventsDomain, Runtime extends ContextRuntime<Env> = ContextRuntime<Env>> = ContextAction<ContextActionSchema, ContextActionSchema, Context, Env, RequiredDomain, Runtime> | ContextProviderDefinedAction;
47
+ export type ContextTool<Context = any, Env extends ContextEnvironment = ContextEnvironment, RequiredDomain extends DomainLike = typeof eventsDomain, Runtime extends ContextRuntime<Env> = ContextRuntime<Env>> = ContextAction<ContextActionSchema, ContextActionSchema, Context, Env, RequiredDomain, Runtime> | ContextProviderDefinedAction;
48
48
  export type ContextActionInput<TAction> = TAction extends ContextAction<infer TInput, any, any, any> ? z.output<TInput> : never;
49
49
  export type ContextActionOutput<TAction> = TAction extends ContextAction<any, infer TOutput, any, any> ? z.output<TOutput> : never;
50
- export declare function defineAction<TInput extends ContextActionSchema, TOutput extends ContextActionSchema, Context = any, Env extends ContextEnvironment = ContextEnvironment, RequiredDomain extends DomainSchemaResult = typeof eventsDomain, Runtime extends ContextRuntime<Env> = ContextRuntime<Env>>(definition: DefineContextActionDefinition<TInput, TOutput, Context, Env, RequiredDomain, Runtime>): ContextAction<TInput, TOutput, Context, Env, RequiredDomain, Runtime>;
50
+ export declare function defineAction<TInput extends ContextActionSchema, TOutput extends ContextActionSchema, Context = any, Env extends ContextEnvironment = ContextEnvironment, RequiredDomain extends DomainLike = typeof eventsDomain, Runtime extends ContextRuntime<Env> = ContextRuntime<Env>>(definition: DefineContextActionDefinition<TInput, TOutput, Context, Env, RequiredDomain, Runtime>): ContextAction<TInput, TOutput, Context, Env, RequiredDomain, Runtime>;
51
51
  /**
52
52
  * @deprecated Use defineAction().
53
53
  */
54
- export declare function action<TInput extends ContextActionSchema, TOutput extends ContextActionSchema, Context = any, Env extends ContextEnvironment = ContextEnvironment, RequiredDomain extends DomainSchemaResult = typeof eventsDomain, Runtime extends ContextRuntime<Env> = ContextRuntime<Env>>(definition: LegacyContextActionDefinition<TInput, TOutput, Context, Env, RequiredDomain, Runtime>): ContextAction<TInput, TOutput, Context, Env, RequiredDomain, Runtime>;
54
+ export declare function action<TInput extends ContextActionSchema, TOutput extends ContextActionSchema, Context = any, Env extends ContextEnvironment = ContextEnvironment, RequiredDomain extends DomainLike = typeof eventsDomain, Runtime extends ContextRuntime<Env> = ContextRuntime<Env>>(definition: LegacyContextActionDefinition<TInput, TOutput, Context, Env, RequiredDomain, Runtime>): ContextAction<TInput, TOutput, Context, Env, RequiredDomain, Runtime>;
55
55
  export {};
@@ -1,4 +1,4 @@
1
- import type { DomainSchemaResult } from "@ekairos/domain";
1
+ import type { DomainLike } from "@ekairos/domain";
2
2
  import type { ContextEnvironment } from "./context.config.js";
3
3
  import type { ContextSkillPackage } from "./context.skill.js";
4
4
  import { ContextEngine, type ContextModelInit, type ContextOptions, type ShouldContinue, type ContextShouldContinueArgs, type ContextReactParams, type ContextDirectReactParams, type ContextDurableReactParams, type ContextReactResult, type ContextDirectRun, type ContextWorkflowRun } from "./context.engine.js";
@@ -8,7 +8,7 @@ import type { ContextReactor } from "./context.reactor.js";
8
8
  import type { ContextItem, StoredContext } from "./context.store.js";
9
9
  import { type ContextKey } from "./context.registry.js";
10
10
  import { eventsDomain } from "./schema.js";
11
- export interface ContextConfig<Context, Env extends ContextEnvironment = ContextEnvironment, RequiredDomain extends DomainSchemaResult = typeof eventsDomain> {
11
+ export interface ContextConfig<Context, Env extends ContextEnvironment = ContextEnvironment, RequiredDomain extends DomainLike = typeof eventsDomain> {
12
12
  context: (context: StoredContext<Context>, env: Env, runtime: ContextRuntimeHandleForDomain<Env, RequiredDomain>) => Promise<Context> | Context;
13
13
  expandEvents?: (events: ContextItem[], context: StoredContext<Context>, env: Env, runtime: ContextRuntimeHandleForDomain<Env, RequiredDomain>) => Promise<ContextItem[]> | ContextItem[];
14
14
  narrative: (context: StoredContext<Context>, env: Env, runtime: ContextRuntimeHandleForDomain<Env, RequiredDomain>) => Promise<string> | string;
@@ -23,25 +23,25 @@ export interface ContextConfig<Context, Env extends ContextEnvironment = Context
23
23
  shouldContinue?: (args: ContextShouldContinueArgs<Context, Env, RequiredDomain>) => Promise<ShouldContinue> | ShouldContinue;
24
24
  opts?: ContextOptions<Context, Env, RequiredDomain>;
25
25
  }
26
- export type ContextInstance<Context, Env extends ContextEnvironment = ContextEnvironment, RequiredDomain extends DomainSchemaResult = typeof eventsDomain> = ContextEngine<Context, Env, RequiredDomain> & {
26
+ export type ContextInstance<Context, Env extends ContextEnvironment = ContextEnvironment, RequiredDomain extends DomainLike = typeof eventsDomain> = ContextEngine<Context, Env, RequiredDomain> & {
27
27
  readonly __config: ContextConfig<Context, Env, RequiredDomain>;
28
28
  readonly __contextKey?: ContextKey;
29
29
  readonly __contextDomain?: RequiredDomain;
30
30
  };
31
- export declare function context<Context, Env extends ContextEnvironment = ContextEnvironment, RequiredDomain extends DomainSchemaResult = typeof eventsDomain>(config: ContextConfig<Context, Env, RequiredDomain>): ContextInstance<Context, Env, RequiredDomain>;
32
- type AnyContextInitializer<Env extends ContextEnvironment, RequiredDomain extends DomainSchemaResult> = (context: StoredContext<any>, env: Env, runtime: ContextRuntimeHandleForDomain<Env, RequiredDomain>) => Promise<any> | any;
31
+ export declare function context<Context, Env extends ContextEnvironment = ContextEnvironment, RequiredDomain extends DomainLike = typeof eventsDomain>(config: ContextConfig<Context, Env, RequiredDomain>): ContextInstance<Context, Env, RequiredDomain>;
32
+ type AnyContextInitializer<Env extends ContextEnvironment, RequiredDomain extends DomainLike> = (context: StoredContext<any>, env: Env, runtime: ContextRuntimeHandleForDomain<Env, RequiredDomain>) => Promise<any> | any;
33
33
  type InferContextFromInitializer<I extends AnyContextInitializer<any, any>> = Awaited<ReturnType<I>>;
34
- type BuilderSystemPrompt<Context, Env extends ContextEnvironment, RequiredDomain extends DomainSchemaResult> = (context: StoredContext<Context>, env: Env, runtime: ContextRuntimeHandleForDomain<Env, RequiredDomain>) => Promise<string> | string;
35
- type BuilderSkills<Context, Env extends ContextEnvironment, RequiredDomain extends DomainSchemaResult> = (context: StoredContext<Context>, env: Env, runtime: ContextRuntimeHandleForDomain<Env, RequiredDomain>) => Promise<ContextSkillPackage[]> | ContextSkillPackage[];
36
- type BuilderTools<Context, Env extends ContextEnvironment, RequiredDomain extends DomainSchemaResult> = (context: StoredContext<Context>, env: Env, runtime: ContextRuntimeHandleForDomain<Env, RequiredDomain>) => Promise<Record<string, ContextTool<Context, Env, RequiredDomain>>> | Record<string, ContextTool<Context, Env, RequiredDomain>>;
37
- type BuilderExpandEvents<Context, Env extends ContextEnvironment, RequiredDomain extends DomainSchemaResult> = (events: ContextItem[], context: StoredContext<Context>, env: Env, runtime: ContextRuntimeHandleForDomain<Env, RequiredDomain>) => Promise<ContextItem[]> | ContextItem[];
38
- type BuilderShouldContinue<Context, Env extends ContextEnvironment, RequiredDomain extends DomainSchemaResult> = (args: ContextShouldContinueArgs<Context, Env, RequiredDomain>) => Promise<ShouldContinue> | ShouldContinue;
39
- type BuilderModel<Context, Env extends ContextEnvironment, RequiredDomain extends DomainSchemaResult> = ContextModelInit | ((context: StoredContext<Context>, env: Env, runtime: ContextRuntimeHandleForDomain<Env, RequiredDomain>) => ContextModelInit);
34
+ type BuilderSystemPrompt<Context, Env extends ContextEnvironment, RequiredDomain extends DomainLike> = (context: StoredContext<Context>, env: Env, runtime: ContextRuntimeHandleForDomain<Env, RequiredDomain>) => Promise<string> | string;
35
+ type BuilderSkills<Context, Env extends ContextEnvironment, RequiredDomain extends DomainLike> = (context: StoredContext<Context>, env: Env, runtime: ContextRuntimeHandleForDomain<Env, RequiredDomain>) => Promise<ContextSkillPackage[]> | ContextSkillPackage[];
36
+ type BuilderTools<Context, Env extends ContextEnvironment, RequiredDomain extends DomainLike> = (context: StoredContext<Context>, env: Env, runtime: ContextRuntimeHandleForDomain<Env, RequiredDomain>) => Promise<Record<string, ContextTool<Context, Env, RequiredDomain>>> | Record<string, ContextTool<Context, Env, RequiredDomain>>;
37
+ type BuilderExpandEvents<Context, Env extends ContextEnvironment, RequiredDomain extends DomainLike> = (events: ContextItem[], context: StoredContext<Context>, env: Env, runtime: ContextRuntimeHandleForDomain<Env, RequiredDomain>) => Promise<ContextItem[]> | ContextItem[];
38
+ type BuilderShouldContinue<Context, Env extends ContextEnvironment, RequiredDomain extends DomainLike> = (args: ContextShouldContinueArgs<Context, Env, RequiredDomain>) => Promise<ShouldContinue> | ShouldContinue;
39
+ type BuilderModel<Context, Env extends ContextEnvironment, RequiredDomain extends DomainLike> = ContextModelInit | ((context: StoredContext<Context>, env: Env, runtime: ContextRuntimeHandleForDomain<Env, RequiredDomain>) => ContextModelInit);
40
40
  export type RegistrableContextBuilder = {
41
41
  key: ContextKey;
42
42
  register: () => void;
43
43
  };
44
- type FluentContextBuilder<Context, Env extends ContextEnvironment, RequiredDomain extends DomainSchemaResult> = {
44
+ type FluentContextBuilder<Context, Env extends ContextEnvironment, RequiredDomain extends DomainLike> = {
45
45
  key: ContextKey;
46
46
  expandEvents(fn: BuilderExpandEvents<Context, Env, RequiredDomain>): FluentContextBuilder<Context, Env, RequiredDomain>;
47
47
  narrative(fn: BuilderSystemPrompt<Context, Env, RequiredDomain>): FluentContextBuilder<Context, Env, RequiredDomain>;
@@ -63,10 +63,10 @@ type FluentContextBuilder<Context, Env extends ContextEnvironment, RequiredDomai
63
63
  config(): ContextConfig<Context, Env, RequiredDomain>;
64
64
  build(): ContextInstance<Context, Env, RequiredDomain>;
65
65
  };
66
- type CreateContextEntry<Env extends ContextEnvironment, RequiredDomain extends DomainSchemaResult> = {
66
+ type CreateContextEntry<Env extends ContextEnvironment, RequiredDomain extends DomainLike> = {
67
67
  context<Initializer extends AnyContextInitializer<Env, RequiredDomain>>(initializer: Initializer): FluentContextBuilder<InferContextFromInitializer<Initializer>, Env, RequiredDomain>;
68
68
  initialize<Initializer extends AnyContextInitializer<Env, RequiredDomain>>(initializer: Initializer): FluentContextBuilder<InferContextFromInitializer<Initializer>, Env, RequiredDomain>;
69
69
  };
70
- export declare function createContext<Env extends ContextEnvironment = ContextEnvironment, RequiredDomain extends DomainSchemaResult = DomainSchemaResult>(domain: RequiredDomain, key: ContextKey): CreateContextEntry<Env, RequiredDomain>;
70
+ export declare function createContext<Env extends ContextEnvironment = ContextEnvironment, RequiredDomain extends DomainLike = DomainLike>(domain: RequiredDomain, key: ContextKey): CreateContextEntry<Env, RequiredDomain>;
71
71
  export declare function createContext<Env extends ContextEnvironment = ContextEnvironment>(key: ContextKey): CreateContextEntry<Env, typeof eventsDomain>;
72
72
  export {};
@@ -1,5 +1,5 @@
1
1
  import type { ModelMessage, UIMessageChunk } from "ai";
2
- import type { DomainSchemaResult } from "@ekairos/domain";
2
+ import type { DomainLike } from "@ekairos/domain";
3
3
  import type { ContextEnvironment } from "./context.config.js";
4
4
  import type { ContextTool } from "./context.action.js";
5
5
  import type { ContextRuntime, ContextRuntimeHandleForDomain, ContextRuntimeForDomain } from "./context.runtime.js";
@@ -8,7 +8,7 @@ import type { ContextExecution, ContextItem, ContextIdentifier, StoredContext }
8
8
  import type { ContextSkillPackage } from "./context.skill.js";
9
9
  import { type ContextReactor } from "./context.reactor.js";
10
10
  import { getClientResumeHookUrl, toolApprovalHookToken, toolApprovalWebhookToken } from "./context.hooks.js";
11
- export interface ContextOptions<Context = any, Env extends ContextEnvironment = ContextEnvironment, RequiredDomain extends DomainSchemaResult = typeof eventsDomain> {
11
+ export interface ContextOptions<Context = any, Env extends ContextEnvironment = ContextEnvironment, RequiredDomain extends DomainLike = typeof eventsDomain> {
12
12
  onContextCreated?: (args: {
13
13
  env: Env;
14
14
  runtime: ContextRuntimeHandleForDomain<Env, RequiredDomain>;
@@ -28,7 +28,7 @@ type ContextBenchmarkRecorder = {
28
28
  add?(name: string, value: number): void;
29
29
  getCurrentStage?(): string | undefined;
30
30
  };
31
- export declare function runContextReactionDirect<Context, Env extends ContextEnvironment = ContextEnvironment, RequiredDomain extends DomainSchemaResult = typeof eventsDomain, Runtime extends ContextRuntime<Env> = ContextRuntime<Env>>(context: ContextEngine<Context, Env, RequiredDomain>, triggerEvent: ContextItem, params: ContextReactParams<Env, RequiredDomain, Runtime>): Promise<ContextReactResult<Context>>;
31
+ export declare function runContextReactionDirect<Context, Env extends ContextEnvironment = ContextEnvironment, RequiredDomain extends DomainLike = typeof eventsDomain, Runtime extends ContextRuntime<Env> = ContextRuntime<Env>>(context: ContextEngine<Context, Env, RequiredDomain>, triggerEvent: ContextItem, params: ContextReactParams<Env, RequiredDomain, Runtime>): Promise<ContextReactResult<Context>>;
32
32
  export interface ContextStreamOptions {
33
33
  /**
34
34
  * Maximum loop iterations (LLM call → tool execution → repeat).
@@ -73,7 +73,7 @@ export interface ContextStreamOptions {
73
73
  * be a `"use-step"` function (so it can be serialized by reference).
74
74
  */
75
75
  export type ContextModelInit = string | (() => Promise<any>);
76
- export type ContextReactParams<Env extends ContextEnvironment = ContextEnvironment, RequiredDomain extends DomainSchemaResult = typeof eventsDomain, Runtime extends ContextRuntime<Env> = ContextRuntime<Env>> = {
76
+ export type ContextReactParams<Env extends ContextEnvironment = ContextEnvironment, RequiredDomain extends DomainLike = typeof eventsDomain, Runtime extends ContextRuntime<Env> = ContextRuntime<Env>> = {
77
77
  runtime: ContextRuntimeForDomain<Runtime, RequiredDomain>;
78
78
  /**
79
79
  * Context selector (exclusive: `{ id }` OR `{ key }`).
@@ -98,10 +98,10 @@ export type ContextReactParams<Env extends ContextEnvironment = ContextEnvironme
98
98
  __initialContent?: unknown;
99
99
  __benchmark?: ContextBenchmarkRecorder;
100
100
  };
101
- export type ContextDurableReactParams<Env extends ContextEnvironment = ContextEnvironment, RequiredDomain extends DomainSchemaResult = typeof eventsDomain, Runtime extends ContextRuntime<Env> = ContextRuntime<Env>> = Omit<ContextReactParams<Env, RequiredDomain, Runtime>, "durable"> & {
101
+ export type ContextDurableReactParams<Env extends ContextEnvironment = ContextEnvironment, RequiredDomain extends DomainLike = typeof eventsDomain, Runtime extends ContextRuntime<Env> = ContextRuntime<Env>> = Omit<ContextReactParams<Env, RequiredDomain, Runtime>, "durable"> & {
102
102
  durable?: true | undefined;
103
103
  };
104
- export type ContextDirectReactParams<Env extends ContextEnvironment = ContextEnvironment, RequiredDomain extends DomainSchemaResult = typeof eventsDomain, Runtime extends ContextRuntime<Env> = ContextRuntime<Env>> = Omit<ContextReactParams<Env, RequiredDomain, Runtime>, "durable"> & {
104
+ export type ContextDirectReactParams<Env extends ContextEnvironment = ContextEnvironment, RequiredDomain extends DomainLike = typeof eventsDomain, Runtime extends ContextRuntime<Env> = ContextRuntime<Env>> = Omit<ContextReactParams<Env, RequiredDomain, Runtime>, "durable"> & {
105
105
  durable: false;
106
106
  };
107
107
  export type ContextReactBase<Context = any> = {
@@ -125,7 +125,7 @@ export type ContextReactRun<Context = any> = ContextWorkflowRun<Context> | Conte
125
125
  export type ContextReactResult<Context = any, Run extends ContextReactRun<Context> = ContextReactRun<Context>> = ContextReactBase<Context> & {
126
126
  run?: Run;
127
127
  };
128
- export type ContextDurableWorkflowPayload<Env extends ContextEnvironment = ContextEnvironment, RequiredDomain extends DomainSchemaResult = typeof eventsDomain, Runtime extends ContextRuntime<Env> = ContextRuntime<Env>> = {
128
+ export type ContextDurableWorkflowPayload<Env extends ContextEnvironment = ContextEnvironment, RequiredDomain extends DomainLike = typeof eventsDomain, Runtime extends ContextRuntime<Env> = ContextRuntime<Env>> = {
129
129
  contextKey: string;
130
130
  runtime: ContextRuntimeForDomain<Runtime, RequiredDomain>;
131
131
  context?: ContextIdentifier | null;
@@ -133,8 +133,8 @@ export type ContextDurableWorkflowPayload<Env extends ContextEnvironment = Conte
133
133
  options?: Omit<ContextStreamOptions, "writable">;
134
134
  bootstrap: NonNullable<ContextReactParams<Env, RequiredDomain, Runtime>["__bootstrap"]>;
135
135
  };
136
- export type ContextDurableWorkflowFunction<Context = any, Env extends ContextEnvironment = ContextEnvironment, RequiredDomain extends DomainSchemaResult = typeof eventsDomain, Runtime extends ContextRuntime<Env> = ContextRuntime<Env>> = (payload: ContextDurableWorkflowPayload<Env, RequiredDomain, Runtime>) => Promise<ContextReactFinalResult<Context>>;
137
- export type ContextToolExecuteContext<Context = any, Env extends ContextEnvironment = ContextEnvironment, RequiredDomain extends DomainSchemaResult = typeof eventsDomain, Runtime extends ContextRuntime<Env> = ContextRuntime<Env>> = {
136
+ export type ContextDurableWorkflowFunction<Context = any, Env extends ContextEnvironment = ContextEnvironment, RequiredDomain extends DomainLike = typeof eventsDomain, Runtime extends ContextRuntime<Env> = ContextRuntime<Env>> = (payload: ContextDurableWorkflowPayload<Env, RequiredDomain, Runtime>) => Promise<ContextReactFinalResult<Context>>;
137
+ export type ContextToolExecuteContext<Context = any, Env extends ContextEnvironment = ContextEnvironment, RequiredDomain extends DomainLike = typeof eventsDomain, Runtime extends ContextRuntime<Env> = ContextRuntime<Env>> = {
138
138
  runtime: ContextRuntimeForDomain<Runtime, RequiredDomain>;
139
139
  context: StoredContext<Context>;
140
140
  contextIdentifier: ContextIdentifier;
@@ -168,7 +168,7 @@ export { toolApprovalHookToken, toolApprovalWebhookToken, getClientResumeHookUrl
168
168
  * (No imports required in callers.)
169
169
  */
170
170
  export type ShouldContinue = boolean;
171
- export type ContextShouldContinueArgs<Context = any, Env extends ContextEnvironment = ContextEnvironment, RequiredDomain extends DomainSchemaResult = typeof eventsDomain> = {
171
+ export type ContextShouldContinueArgs<Context = any, Env extends ContextEnvironment = ContextEnvironment, RequiredDomain extends DomainLike = typeof eventsDomain> = {
172
172
  env: Env;
173
173
  runtime: ContextRuntimeHandleForDomain<Env, RequiredDomain>;
174
174
  context: StoredContext<Context>;
@@ -199,7 +199,7 @@ export type ContextShouldContinueArgs<Context = any, Env extends ContextEnvironm
199
199
  errorText?: string;
200
200
  }>;
201
201
  };
202
- export declare abstract class ContextEngine<Context, Env extends ContextEnvironment = ContextEnvironment, RequiredDomain extends DomainSchemaResult = typeof eventsDomain> {
202
+ export declare abstract class ContextEngine<Context, Env extends ContextEnvironment = ContextEnvironment, RequiredDomain extends DomainLike = typeof eventsDomain> {
203
203
  protected readonly opts: ContextOptions<Context, Env, RequiredDomain>;
204
204
  private readonly reactor;
205
205
  constructor(opts?: ContextOptions<Context, Env, RequiredDomain>, reactor?: ContextReactor<Context, Env, RequiredDomain>);
@@ -241,7 +241,7 @@ export declare abstract class ContextEngine<Context, Env extends ContextEnvironm
241
241
  react<Runtime extends ContextRuntime<Env>>(triggerEvent: ContextItem, params: ContextReactParams<Env, RequiredDomain, Runtime>): Promise<ContextReactResult<Context>>;
242
242
  private static prepareExecutionShell;
243
243
  private static startDurable;
244
- static runDirect<Context, Env extends ContextEnvironment, RequiredDomain extends DomainSchemaResult, Runtime extends ContextRuntime<Env>>(story: ContextEngine<Context, Env, RequiredDomain>, triggerEvent: ContextItem, params: ContextReactParams<Env, RequiredDomain, Runtime>): Promise<ContextReactResult<Context, ContextDirectRun<Context>>>;
244
+ static runDirect<Context, Env extends ContextEnvironment, RequiredDomain extends DomainLike, Runtime extends ContextRuntime<Env>>(story: ContextEngine<Context, Env, RequiredDomain>, triggerEvent: ContextItem, params: ContextReactParams<Env, RequiredDomain, Runtime>): Promise<ContextReactResult<Context, ContextDirectRun<Context>>>;
245
245
  /**
246
246
  * @deprecated Use `react()` instead. Kept for backwards compatibility.
247
247
  */
@@ -1,6 +1,6 @@
1
1
  import { getContextRuntimeServices } from "./context.runtime.js";
2
2
  import { OUTPUT_ITEM_TYPE, WEB_CHANNEL } from "./context.events.js";
3
- import { applyToolExecutionResultToParts } from "./context.toolcalls.js";
3
+ import { applyActionExecutionResultToParts } from "./context.action-calls.js";
4
4
  import { isContextPartEnvelope, normalizePartsForPersistence, } from "./context.parts.js";
5
5
  import { createAiSdkReactor, } from "./context.reactor.js";
6
6
  import { abortPersistedContextStepStream, closeContextStream, createPersistedContextStepStreamForRuntime, finalizePersistedContextStepStreamForRuntime, writeActionResultPartChunksToSession, } from "./steps/stream.steps.js";
@@ -706,6 +706,13 @@ export class ContextEngine {
706
706
  try {
707
707
  for (let iter = 0; iter < maxIterations; iter++) {
708
708
  const stagePrefix = `react.iteration.${iter}`;
709
+ runtimeHandle.__ekairosContextRun = {
710
+ contextId: currentContext.id,
711
+ executionId,
712
+ triggerEventId,
713
+ reactionEventId,
714
+ iteration: iter,
715
+ };
709
716
  // Hook: Context DSL `context()` (implemented by subclasses via `initialize()`)
710
717
  const nextContent = await measureBenchmark(params.__benchmark, `${stagePrefix}.contextMs`, async () => await story.initialize(updatedContext, env, runtimeHandle));
711
718
  const openedStep = await measureBenchmark(params.__benchmark, `${stagePrefix}.openExecutionStepMs`, async () => await ops.openExecutionStep({
@@ -1057,9 +1064,9 @@ export class ContextEngine {
1057
1064
  // Merge action results into step parts so the next reaction can see them.
1058
1065
  let finalizedStepParts = Array.isArray(stepParts) ? [...stepParts] : [];
1059
1066
  for (const r of actionResults) {
1060
- finalizedStepParts = applyToolExecutionResultToParts(finalizedStepParts, {
1061
- toolCallId: r.actionRequest.actionRef,
1062
- toolName: r.actionRequest.actionName,
1067
+ finalizedStepParts = applyActionExecutionResultToParts(finalizedStepParts, {
1068
+ actionCallId: r.actionRequest.actionRef,
1069
+ actionName: r.actionRequest.actionName,
1063
1070
  }, {
1064
1071
  success: Boolean(r.success),
1065
1072
  result: r.output,
@@ -216,6 +216,58 @@ function normalizeFileContentBlock(value) {
216
216
  fileId: typeof value.fileId === "string" ? value.fileId : undefined,
217
217
  }));
218
218
  }
219
+ function normalizeInlineContentBlock(value) {
220
+ const record = asRecord(value);
221
+ if (!record || typeof record.type !== "string")
222
+ return null;
223
+ if (record.type === "text" && typeof record.text === "string") {
224
+ return contextInlineContentSchema.parse({ type: "text", text: record.text });
225
+ }
226
+ if (record.type === "json") {
227
+ return contextInlineContentSchema.parse({ type: "json", value: record.value });
228
+ }
229
+ if (record.type === "file" || record.type === "image-data") {
230
+ return normalizeFileContentBlock(record);
231
+ }
232
+ return null;
233
+ }
234
+ function normalizeInlineContentBlocks(value) {
235
+ if (!Array.isArray(value))
236
+ return [];
237
+ return value
238
+ .map((block) => normalizeInlineContentBlock(block))
239
+ .filter((block) => Boolean(block));
240
+ }
241
+ function contentBlocksToActionValue(blocks) {
242
+ if (blocks.length === 0)
243
+ return undefined;
244
+ if (blocks.length === 1) {
245
+ const [first] = blocks;
246
+ if (first.type === "json")
247
+ return first.value;
248
+ if (first.type === "text")
249
+ return first.text;
250
+ if (first.type === "file")
251
+ return first;
252
+ }
253
+ return {
254
+ type: "content",
255
+ value: blocks,
256
+ };
257
+ }
258
+ function contentBlocksToErrorMessage(blocks) {
259
+ const text = blocks
260
+ .filter((block) => block.type === "text")
261
+ .map((block) => block.text)
262
+ .join("\n\n")
263
+ .trim();
264
+ if (text)
265
+ return text;
266
+ const jsonBlock = blocks.find((block) => block.type === "json");
267
+ if (jsonBlock)
268
+ return JSON.stringify(jsonBlock.value, null, 2);
269
+ return "";
270
+ }
219
271
  function readReactorMetadata(record) {
220
272
  const parsed = reactorMetadataSchema.safeParse(record.reactorMetadata);
221
273
  return parsed.success ? parsed.data : undefined;
@@ -239,6 +291,62 @@ function messageFromBlocks(blocks, reactorMetadata) {
239
291
  })),
240
292
  ];
241
293
  }
294
+ function normalizeExternalToolCallPart(record, reactorMetadata) {
295
+ const actionName = typeof record.toolName === "string" && record.toolName.length > 0
296
+ ? record.toolName
297
+ : "";
298
+ const actionCallId = typeof record.toolCallId === "string" && record.toolCallId.length > 0
299
+ ? record.toolCallId
300
+ : "";
301
+ if (!actionName || !actionCallId)
302
+ return [];
303
+ const blocks = normalizeInlineContentBlocks(record.content);
304
+ return [
305
+ contextActionPartSchema.parse(cleanRecord({
306
+ type: "action",
307
+ content: {
308
+ status: "started",
309
+ actionName,
310
+ actionCallId,
311
+ input: contentBlocksToActionValue(blocks),
312
+ },
313
+ reactorMetadata,
314
+ })),
315
+ ];
316
+ }
317
+ function normalizeExternalToolResultPart(record, reactorMetadata) {
318
+ const actionName = typeof record.toolName === "string" && record.toolName.length > 0
319
+ ? record.toolName
320
+ : "";
321
+ const actionCallId = typeof record.toolCallId === "string" && record.toolCallId.length > 0
322
+ ? record.toolCallId
323
+ : "";
324
+ if (!actionName || !actionCallId)
325
+ return [];
326
+ const blocks = normalizeInlineContentBlocks(record.content);
327
+ const failed = record.state === "output-error";
328
+ return [
329
+ contextActionPartSchema.parse(cleanRecord({
330
+ type: "action",
331
+ content: failed
332
+ ? {
333
+ status: "failed",
334
+ actionName,
335
+ actionCallId,
336
+ error: {
337
+ message: contentBlocksToErrorMessage(blocks) || "Action execution failed.",
338
+ },
339
+ }
340
+ : {
341
+ status: "completed",
342
+ actionName,
343
+ actionCallId,
344
+ output: contentBlocksToActionValue(blocks),
345
+ },
346
+ reactorMetadata,
347
+ })),
348
+ ];
349
+ }
242
350
  export function normalizeUiPartToContextPartEnvelopes(value) {
243
351
  const record = asRecord(value);
244
352
  if (!record || typeof record.type !== "string") {
@@ -307,6 +415,12 @@ export function normalizeUiPartToContextPartEnvelopes(value) {
307
415
  if (record.type.startsWith("data-")) {
308
416
  return messageFromBlocks([{ type: "json", value: record.data }], reactorMetadata);
309
417
  }
418
+ if (record.type === "tool-call") {
419
+ return normalizeExternalToolCallPart(record, reactorMetadata);
420
+ }
421
+ if (record.type === "tool-result") {
422
+ return normalizeExternalToolResultPart(record, reactorMetadata);
423
+ }
310
424
  if (record.type.startsWith("tool-")) {
311
425
  const actionName = record.type.slice("tool-".length);
312
426
  const actionCallId = typeof record.toolCallId === "string" ? record.toolCallId : "";
@@ -1,4 +1,4 @@
1
- import type { ActiveDomain, ConcreteDomain, DomainSchemaResult } from "@ekairos/domain";
1
+ import type { ConcreteDomain, DomainLike } from "@ekairos/domain";
2
2
  import type { EkairosRuntime, RuntimeForDomain, RuntimeResolveOptions } from "@ekairos/domain/runtime";
3
3
  import type { ContextEnvironment } from "./context.config.js";
4
4
  import type { ContextStore } from "./context.store.js";
@@ -9,10 +9,10 @@ export type ContextRuntimeServiceHandle = {
9
9
  resolve?: (...args: any[]) => Promise<any> | any;
10
10
  meta?: (...args: any[]) => Record<string, unknown> | undefined;
11
11
  };
12
- export type ContextRuntimeHandleForDomain<Env extends ContextEnvironment = ContextEnvironment, RequiredDomain extends DomainSchemaResult = typeof eventsDomain> = ContextRuntimeServiceHandle & {
13
- use<Subdomain extends typeof eventsDomain | RequiredDomain>(subdomain: Subdomain, options?: RuntimeResolveOptions): Promise<Omit<ActiveDomain<Subdomain, Env>, "env">>;
12
+ export type ContextRuntimeHandleForDomain<Env extends ContextEnvironment = ContextEnvironment, RequiredDomain extends DomainLike = typeof eventsDomain> = ContextRuntimeServiceHandle & {
13
+ use<Subdomain extends typeof eventsDomain | RequiredDomain>(subdomain: Subdomain, options?: RuntimeResolveOptions): Promise<unknown>;
14
14
  };
15
- export type ContextRuntimeForDomain<Runtime extends ContextRuntime<any>, RequiredDomain extends DomainSchemaResult = typeof eventsDomain> = RuntimeForDomain<Runtime, typeof eventsDomain> & RuntimeForDomain<Runtime, RequiredDomain>;
15
+ export type ContextRuntimeForDomain<Runtime extends ContextRuntime<any>, RequiredDomain extends DomainLike = typeof eventsDomain> = RuntimeForDomain<Runtime, typeof eventsDomain> & RuntimeForDomain<Runtime, RequiredDomain>;
16
16
  export type ContextRuntimeServices = {
17
17
  db: any;
18
18
  store: ContextStore;
package/dist/index.d.ts CHANGED
@@ -3,7 +3,7 @@ export type { ContextStore, ContextIdentifier, StoredContext, ContextItem, Conte
3
3
  export type { WireDate, ContextMirrorContext, ContextMirrorExecution, ContextMirrorWrite, ContextMirrorRequest, } from "./mirror.js";
4
4
  export { registerContext, getContext, getContextFactory, hasContext, listContexts, type ContextKey, } from "./context.registry.js";
5
5
  export { eventsDomain } from "./schema.js";
6
- export { didToolExecute, extractToolCallsFromParts } from "./context.toolcalls.js";
6
+ export { didActionExecute, extractActionCallsFromParts, type ContextActionCall, } from "./context.action-calls.js";
7
7
  export { actionsToActionSpecs, actionSpecToAiSdkTool, type SerializableActionSpec, type SerializableFunctionActionSpec, type SerializableProviderDefinedActionSpec, } from "./tools-to-model-tools.js";
8
8
  export { reactorMetadataSchema, contextPartSchema, contextPartEnvelopeSchema, contextPartContentSchema, contextMessagePartSchema, contextReasoningPartSchema, contextSourcePartSchema, contextActionPartSchema, contextEnginePartSchema, createContextPartSchema, parseContextPart, isContextPartEnvelope, parseContextPartEnvelope, normalizePartsForPersistence, } from "./context.parts.js";
9
9
  export type { ReactorMetadata, ContextEnginePart, ContextActionPart, ContextActionStartedPart, ContextActionCompletedPart, ContextActionFailedPart, ContextPartActionMap, ContextPart, ContextPartEnvelope, ContextPartContent, ContextInlineContent, } from "./context.parts.js";
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  export { context, createContext, createAiSdkReactor, createScriptedReactor, ContextEngine, defineAction, action, runContextReactionDirect, } from "./context.js";
2
2
  export { registerContext, getContext, getContextFactory, hasContext, listContexts, } from "./context.registry.js";
3
3
  export { eventsDomain } from "./schema.js";
4
- export { didToolExecute, extractToolCallsFromParts } from "./context.toolcalls.js";
4
+ export { didActionExecute, extractActionCallsFromParts, } from "./context.action-calls.js";
5
5
  export { actionsToActionSpecs, actionSpecToAiSdkTool, } from "./tools-to-model-tools.js";
6
6
  export { reactorMetadataSchema, contextPartSchema, contextPartEnvelopeSchema, contextPartContentSchema, contextMessagePartSchema, contextReasoningPartSchema, contextSourcePartSchema, contextActionPartSchema, contextEnginePartSchema, createContextPartSchema, parseContextPart, isContextPartEnvelope, parseContextPartEnvelope, normalizePartsForPersistence, } from "./context.parts.js";
7
7
  export { INPUT_ITEM_TYPE, INPUT_TEXT_ITEM_TYPE, OUTPUT_ITEM_TYPE, WEB_CHANNEL, AGENT_CHANNEL, EMAIL_CHANNEL, createUserItemFromUIMessages, createAssistantItemFromUIMessages, convertToUIMessage, convertItemToModelMessages, convertItemsToModelMessages, convertModelMessageToItem, isContextOutputPart, normalizeContextOutputPart, } from "./context.events.js";
@@ -71,6 +71,72 @@ function parseActionInputText(value) {
71
71
  return value;
72
72
  }
73
73
  }
74
+ function firstString(...values) {
75
+ for (const value of values) {
76
+ const text = asString(value).trim();
77
+ if (text)
78
+ return text;
79
+ }
80
+ return "";
81
+ }
82
+ function firstDefined(...values) {
83
+ for (const value of values) {
84
+ if (value !== undefined)
85
+ return value;
86
+ }
87
+ return undefined;
88
+ }
89
+ function parseMaybeJsonValue(value) {
90
+ if (typeof value !== "string")
91
+ return value;
92
+ return parseActionInputText(value);
93
+ }
94
+ function providerContentItemsToValue(value) {
95
+ if (!Array.isArray(value)) {
96
+ const record = asRecord(value);
97
+ if (Array.isArray(record.contentItems))
98
+ return providerContentItemsToValue(record.contentItems);
99
+ if (record.output !== undefined)
100
+ return parseMaybeJsonValue(record.output);
101
+ return parseMaybeJsonValue(value);
102
+ }
103
+ const blocks = value
104
+ .map((entry) => {
105
+ const record = asRecord(entry);
106
+ if (record.type === "inputText" ||
107
+ record.type === "outputText" ||
108
+ record.type === "text" ||
109
+ record.type === "input_text") {
110
+ const text = asString(record.text || record.input_text);
111
+ return text ? parseMaybeJsonValue(text) : undefined;
112
+ }
113
+ return Object.keys(record).length > 0 ? record : undefined;
114
+ })
115
+ .filter((entry) => entry !== undefined);
116
+ if (blocks.length === 0)
117
+ return undefined;
118
+ if (blocks.length === 1)
119
+ return blocks[0];
120
+ return { type: "content", value: blocks };
121
+ }
122
+ function readProviderActionDetails(params) {
123
+ const result = asRecord(params.rawParams.result);
124
+ const rawError = asRecord(params.rawParams.error);
125
+ const resultError = asRecord(result.error);
126
+ const rawItemError = asRecord(params.rawItem.error);
127
+ const actionCallId = firstString(params.data.actionCallId, params.raw.actionCallId, params.rawParams.actionCallId, params.data.toolCallId, params.rawParams.callId, params.rawParams.toolCallId, params.rawParams.itemId, params.rawParams.id, params.rawItem.callId, params.rawItem.toolCallId, params.rawItem.itemId, params.rawItem.id, params.raw.toolCallId, params.raw.id);
128
+ const actionName = firstString(params.data.actionName, params.raw.actionName, params.rawParams.actionName, params.rawParams.tool, params.rawParams.toolName, params.rawParams.name, params.rawItem.actionName, params.rawItem.tool, params.rawItem.toolName, params.rawItem.name, params.raw.toolName, params.raw.name);
129
+ const input = parseMaybeJsonValue(firstDefined(params.data.input, params.data.arguments, params.raw.input, params.raw.args, params.raw.arguments, params.rawParams.arguments, params.rawParams.input, params.rawParams.args, params.rawItem.arguments, params.rawItem.input, params.rawItem.args));
130
+ const output = providerContentItemsToValue(firstDefined(params.data.output, params.data.result, params.rawParams.output, result.output, result.value, result.contentItems, params.raw.output, params.raw.result, params.rawItem.output, params.rawItem.result));
131
+ const errorText = firstString(params.data.error, asRecord(params.data.error).message, params.rawParams.errorText, params.rawParams.error, rawError.message, result.errorText, result.error, resultError.message, params.rawItem.errorText, params.rawItem.error, rawItemError.message, asRecord(params.raw.error).message);
132
+ return {
133
+ actionCallId,
134
+ actionName,
135
+ input,
136
+ output,
137
+ errorText,
138
+ };
139
+ }
74
140
  function readActionInputDelta(params) {
75
141
  return (asString(params.chunk.text) ||
76
142
  asString(params.data.text) ||
@@ -278,28 +344,19 @@ export function buildLiveEventFromStepChunks(params) {
278
344
  const raw = asRecord(chunk.raw);
279
345
  const rawParams = asRecord(raw.params);
280
346
  const rawItem = asRecord(rawParams.item);
347
+ const providerAction = readProviderActionDetails({
348
+ data,
349
+ raw,
350
+ rawParams,
351
+ rawItem,
352
+ });
281
353
  const actionRef = asString(chunk.actionRef) ||
282
354
  asString(chunk.providerPartId) ||
283
- asString(data.actionCallId) ||
284
- asString(data.toolCallId) ||
285
- asString(data.callId) ||
286
- asString(data.itemId) ||
287
- asString(data.id) ||
288
- asString(rawParams.callId) ||
289
- asString(rawParams.itemId) ||
290
- asString(rawItem.id) ||
291
- asString(raw.toolCallId) ||
292
- asString(raw.id);
355
+ providerAction.actionCallId;
293
356
  if (!actionRef)
294
357
  continue;
295
- const toolName = asString(data.actionName) ||
296
- asString(data.toolName) ||
297
- asString(rawParams.tool) ||
298
- asString(rawItem.command ? "sandbox_run_command" : "") ||
299
- asString(raw.actionName) ||
300
- asString(raw.toolName) ||
301
- asString(raw.name) ||
302
- actionParts.get(actionRef)?.toolName ||
358
+ const actionName = providerAction.actionName ||
359
+ actionParts.get(actionRef)?.actionName ||
303
360
  "reactorAction";
304
361
  const previous = actionParts.get(actionRef);
305
362
  const inputDeltaText = readActionInputDelta({
@@ -318,22 +375,13 @@ export function buildLiveEventFromStepChunks(params) {
318
375
  ? `${previous?.inputDeltaText ?? ""}${inputDeltaText}`
319
376
  : previous?.inputDeltaText ?? "";
320
377
  const parsedInputDelta = parseActionInputText(nextInputDeltaText);
321
- const input = data.input ??
322
- data.arguments ??
323
- raw.input ??
324
- raw.args ??
325
- raw.arguments ??
326
- rawParams.arguments ??
378
+ const input = providerAction.input ??
327
379
  (nextInputDeltaText ? parsedInputDelta : undefined) ??
328
380
  previous?.input;
329
381
  const nextOutputDeltaText = chunkType === "chunk.action_completed" && outputDeltaText
330
382
  ? `${previous?.outputDeltaText ?? ""}${outputDeltaText}`
331
383
  : previous?.outputDeltaText ?? "";
332
- const output = data.output ??
333
- data.result ??
334
- rawParams.result ??
335
- raw.output ??
336
- raw.result ??
384
+ const output = providerAction.output ??
337
385
  (nextOutputDeltaText
338
386
  ? {
339
387
  text: nextOutputDeltaText,
@@ -348,7 +396,7 @@ export function buildLiveEventFromStepChunks(params) {
348
396
  chunkType === "chunk.action_failed"
349
397
  ? sequence
350
398
  : previous?.terminalSequence,
351
- toolName,
399
+ actionName,
352
400
  hasStarted: previous?.hasStarted ||
353
401
  chunkType === "chunk.action_started" ||
354
402
  chunkType === "chunk.action_input_delta",
@@ -365,11 +413,7 @@ export function buildLiveEventFromStepChunks(params) {
365
413
  errorText: chunkType === "chunk.action_failed"
366
414
  ? asString(chunk.text) ||
367
415
  asString(data.text) ||
368
- asString(data.error) ||
369
- asString(asRecord(data.error).message) ||
370
- asString(rawParams.error) ||
371
- asString(asRecord(rawParams.error).message) ||
372
- asString(asRecord(raw.error).message) ||
416
+ providerAction.errorText ||
373
417
  undefined
374
418
  : previous?.errorText,
375
419
  terminalStatus: chunkType === "chunk.action_failed"
@@ -415,7 +459,7 @@ export function buildLiveEventFromStepChunks(params) {
415
459
  type: "action",
416
460
  content: {
417
461
  status: "started",
418
- actionName: action.toolName,
462
+ actionName: action.actionName,
419
463
  actionCallId: toolCallId,
420
464
  input: action.input ?? {},
421
465
  },
@@ -429,7 +473,7 @@ export function buildLiveEventFromStepChunks(params) {
429
473
  type: "action",
430
474
  content: {
431
475
  status: "completed",
432
- actionName: action.toolName,
476
+ actionName: action.actionName,
433
477
  actionCallId: toolCallId,
434
478
  output: action.output ?? {},
435
479
  },
@@ -443,7 +487,7 @@ export function buildLiveEventFromStepChunks(params) {
443
487
  type: "action",
444
488
  content: {
445
489
  status: "failed",
446
- actionName: action.toolName,
490
+ actionName: action.actionName,
447
491
  actionCallId: toolCallId,
448
492
  error: {
449
493
  message: action.errorText || "Action failed.",
@@ -1,11 +1,11 @@
1
1
  import type { ContextEnvironment } from "../context.config.js";
2
- import type { DomainSchemaResult } from "@ekairos/domain";
2
+ import type { DomainLike } from "@ekairos/domain";
3
3
  import type { ContextRuntime, ContextRuntimeHandleForDomain } from "../context.runtime.js";
4
4
  import type { ContextModelInit } from "../context.engine.js";
5
5
  import type { ContextIdentifier, StoredContext, ContextItem } from "../context.store.js";
6
6
  import { eventsDomain } from "../schema.js";
7
7
  import type { ContextReactor } from "./types.js";
8
- export type CreateAiSdkReactorOptions<Context = unknown, Env extends ContextEnvironment = ContextEnvironment, RequiredDomain extends DomainSchemaResult = typeof eventsDomain, Runtime extends ContextRuntime<Env> = ContextRuntime<Env>, Config = unknown> = {
8
+ export type CreateAiSdkReactorOptions<Context = unknown, Env extends ContextEnvironment = ContextEnvironment, RequiredDomain extends DomainLike = typeof eventsDomain, Runtime extends ContextRuntime<Env> = ContextRuntime<Env>, Config = unknown> = {
9
9
  resolveConfig?: (params: {
10
10
  runtime: ContextRuntimeHandleForDomain<Env, RequiredDomain>;
11
11
  context: StoredContext<Context>;
@@ -33,4 +33,4 @@ export type CreateAiSdkReactorOptions<Context = unknown, Env extends ContextEnvi
33
33
  config: Config;
34
34
  }) => Promise<number> | number;
35
35
  };
36
- export declare function createAiSdkReactor<Context = unknown, Env extends ContextEnvironment = ContextEnvironment, RequiredDomain extends DomainSchemaResult = typeof eventsDomain, Runtime extends ContextRuntime<Env> = ContextRuntime<Env>, Config = unknown>(options?: CreateAiSdkReactorOptions<Context, Env, RequiredDomain, Runtime, Config>): ContextReactor<Context, Env, RequiredDomain, Runtime>;
36
+ export declare function createAiSdkReactor<Context = unknown, Env extends ContextEnvironment = ContextEnvironment, RequiredDomain extends DomainLike = typeof eventsDomain, Runtime extends ContextRuntime<Env> = ContextRuntime<Env>, Config = unknown>(options?: CreateAiSdkReactorOptions<Context, Env, RequiredDomain, Runtime, Config>): ContextReactor<Context, Env, RequiredDomain, Runtime>;
@@ -55,9 +55,9 @@ export function createAiSdkReactor(options) {
55
55
  });
56
56
  return {
57
57
  assistantEvent: result.assistantEvent,
58
- actionRequests: result.toolCalls.map((entry) => ({
59
- actionRef: String(entry.toolCallId),
60
- actionName: String(entry.toolName),
58
+ actionRequests: result.actionCalls.map((entry) => ({
59
+ actionRef: String(entry.actionCallId),
60
+ actionName: String(entry.actionName),
61
61
  input: entry.args,
62
62
  })),
63
63
  messagesForModel: result.messagesForModel,
@@ -32,7 +32,7 @@ export declare function executeAiSdkReaction<Env extends ContextEnvironment = Co
32
32
  stepId?: string;
33
33
  }): Promise<{
34
34
  assistantEvent: ContextItem;
35
- toolCalls: any[];
35
+ actionCalls: any[];
36
36
  messagesForModel: ModelMessage[];
37
37
  llm?: {
38
38
  provider?: string;
@@ -102,7 +102,7 @@ export async function executeAiSdkReaction(params) {
102
102
  throw error;
103
103
  }
104
104
  const { jsonSchema, gateway, smoothStream, stepCountIs, streamText } = await import("ai");
105
- const { extractToolCallsFromParts } = await import("../context.toolcalls.js");
105
+ const { extractActionCallsFromParts } = await import("../context.action-calls.js");
106
106
  const resolvedModel = typeof params.model === "string"
107
107
  ? gateway(params.model)
108
108
  : typeof params.model === "function"
@@ -233,7 +233,7 @@ export async function executeAiSdkReaction(params) {
233
233
  }
234
234
  const assistantEvent = await finishPromise;
235
235
  const finishedAtMs = Date.now();
236
- const toolCalls = extractToolCallsFromParts(assistantEvent?.content?.parts);
236
+ const actionCalls = extractActionCallsFromParts(assistantEvent?.content?.parts);
237
237
  const latencyMs = Math.max(0, finishedAtMs - startedAtMs);
238
238
  let usage = undefined;
239
239
  let providerMetadata = undefined;
@@ -347,5 +347,5 @@ export async function executeAiSdkReaction(params) {
347
347
  catch {
348
348
  // tracing must not break reaction
349
349
  }
350
- return { assistantEvent, toolCalls, messagesForModel, llm };
350
+ return { assistantEvent, actionCalls, messagesForModel, llm };
351
351
  }
@@ -1,5 +1,5 @@
1
1
  import type { ModelMessage } from "ai";
2
- import type { DomainSchemaResult } from "@ekairos/domain";
2
+ import type { DomainLike } from "@ekairos/domain";
3
3
  import type { ContextEnvironment } from "../context.config.js";
4
4
  import type { ContextRuntime } from "../context.runtime.js";
5
5
  import type { ContextItem } from "../context.store.js";
@@ -11,10 +11,10 @@ type ScriptedReactionPayload = {
11
11
  messagesForModel?: ModelMessage[];
12
12
  llm?: ContextReactionLLM;
13
13
  };
14
- export type ScriptedReactorStep<Context = unknown, Env extends ContextEnvironment = ContextEnvironment, RequiredDomain extends DomainSchemaResult = typeof eventsDomain, Runtime extends ContextRuntime<Env> = ContextRuntime<Env>> = ScriptedReactionPayload | ((params: ContextReactorParams<Context, Env, RequiredDomain, Runtime>) => Promise<ScriptedReactionPayload> | ScriptedReactionPayload);
15
- export type CreateScriptedReactorOptions<Context = unknown, Env extends ContextEnvironment = ContextEnvironment, RequiredDomain extends DomainSchemaResult = typeof eventsDomain, Runtime extends ContextRuntime<Env> = ContextRuntime<Env>> = {
14
+ export type ScriptedReactorStep<Context = unknown, Env extends ContextEnvironment = ContextEnvironment, RequiredDomain extends DomainLike = typeof eventsDomain, Runtime extends ContextRuntime<Env> = ContextRuntime<Env>> = ScriptedReactionPayload | ((params: ContextReactorParams<Context, Env, RequiredDomain, Runtime>) => Promise<ScriptedReactionPayload> | ScriptedReactionPayload);
15
+ export type CreateScriptedReactorOptions<Context = unknown, Env extends ContextEnvironment = ContextEnvironment, RequiredDomain extends DomainLike = typeof eventsDomain, Runtime extends ContextRuntime<Env> = ContextRuntime<Env>> = {
16
16
  steps: ScriptedReactorStep<Context, Env, RequiredDomain, Runtime>[];
17
17
  repeatLast?: boolean;
18
18
  };
19
- export declare function createScriptedReactor<Context = unknown, Env extends ContextEnvironment = ContextEnvironment, RequiredDomain extends DomainSchemaResult = typeof eventsDomain, Runtime extends ContextRuntime<Env> = ContextRuntime<Env>>(options: CreateScriptedReactorOptions<Context, Env, RequiredDomain, Runtime>): ContextReactor<Context, Env, RequiredDomain, Runtime>;
19
+ export declare function createScriptedReactor<Context = unknown, Env extends ContextEnvironment = ContextEnvironment, RequiredDomain extends DomainLike = typeof eventsDomain, Runtime extends ContextRuntime<Env> = ContextRuntime<Env>>(options: CreateScriptedReactorOptions<Context, Env, RequiredDomain, Runtime>): ContextReactor<Context, Env, RequiredDomain, Runtime>;
20
20
  export {};
@@ -1,5 +1,5 @@
1
1
  import type { ModelMessage, UIMessageChunk } from "ai";
2
- import type { DomainSchemaResult } from "@ekairos/domain";
2
+ import type { DomainLike } from "@ekairos/domain";
3
3
  import type { ContextEnvironment } from "../context.config.js";
4
4
  import type { ContextTool } from "../context.action.js";
5
5
  import type { ContextRuntime, ContextRuntimeHandleForDomain } from "../context.runtime.js";
@@ -34,7 +34,7 @@ export type ContextReactionResult = {
34
34
  state?: Record<string, unknown> | null;
35
35
  };
36
36
  };
37
- export type ContextReactorParams<Context = unknown, Env extends ContextEnvironment = ContextEnvironment, RequiredDomain extends DomainSchemaResult = typeof eventsDomain, Runtime extends ContextRuntime<Env> = any> = {
37
+ export type ContextReactorParams<Context = unknown, Env extends ContextEnvironment = ContextEnvironment, RequiredDomain extends DomainLike = typeof eventsDomain, Runtime extends ContextRuntime<Env> = any> = {
38
38
  runtime: ContextRuntimeHandleForDomain<Env, RequiredDomain>;
39
39
  context: StoredContext<Context>;
40
40
  contextIdentifier: ContextIdentifier;
@@ -64,4 +64,4 @@ export type ContextReactorParams<Context = unknown, Env extends ContextEnvironme
64
64
  writable?: WritableStream<UIMessageChunk>;
65
65
  persistReactionParts?: (parts: any[]) => Promise<void>;
66
66
  };
67
- export type ContextReactor<Context = unknown, Env extends ContextEnvironment = ContextEnvironment, RequiredDomain extends DomainSchemaResult = typeof eventsDomain, Runtime extends ContextRuntime<Env> = any> = (params: ContextReactorParams<Context, Env, RequiredDomain, Runtime>) => Promise<ContextReactionResult>;
67
+ export type ContextReactor<Context = unknown, Env extends ContextEnvironment = ContextEnvironment, RequiredDomain extends DomainLike = typeof eventsDomain, Runtime extends ContextRuntime<Env> = any> = (params: ContextReactorParams<Context, Env, RequiredDomain, Runtime>) => Promise<ContextReactionResult>;
@@ -12,7 +12,7 @@ export async function doContextStreamStep(params) {
12
12
  const { getWritable } = await import("workflow");
13
13
  const writable = getWritable();
14
14
  const { jsonSchema, gateway, smoothStream, stepCountIs, streamText } = await import("ai");
15
- const { extractToolCallsFromParts } = await import("../context.toolcalls.js");
15
+ const { extractActionCallsFromParts } = await import("../context.action-calls.js");
16
16
  // Match DurableAgent's model init behavior:
17
17
  // - string => AI Gateway model id, resolved via `gateway(...)` in the step runtime
18
18
  // - function => model factory (should be a `"use step"` function for workflow serialization)
@@ -82,9 +82,9 @@ export async function doContextStreamStep(params) {
82
82
  }));
83
83
  await uiStream.pipeTo(writable, { preventClose: true });
84
84
  const assistantEvent = await finishPromise;
85
- const actionRequests = extractToolCallsFromParts(assistantEvent?.content?.parts).map((entry) => ({
86
- actionRef: String(entry.toolCallId),
87
- actionName: String(entry.toolName),
85
+ const actionRequests = extractActionCallsFromParts(assistantEvent?.content?.parts).map((entry) => ({
86
+ actionRef: String(entry.actionCallId),
87
+ actionName: String(entry.actionName),
88
88
  input: entry.args,
89
89
  }));
90
90
  return {
@@ -1,5 +1,5 @@
1
1
  import "../polyfills/dom-events.js";
2
- import type { DomainSchemaResult } from "@ekairos/domain";
2
+ import type { DomainLike } from "@ekairos/domain";
3
3
  import type { ModelMessage } from "ai";
4
4
  import type { ContextItem, ContextIdentifier, ContextStatus, StoredContext, ContextStore } from "../context.store.js";
5
5
  export { parseAndStoreDocument } from "./instant.document-parser.js";
@@ -54,7 +54,7 @@ export declare class InstantStore implements ContextStore {
54
54
  export declare function createInstantStoreRuntime(params: {
55
55
  getDb: (orgId: string) => Promise<InstantStoreDb> | InstantStoreDb;
56
56
  getOrgId?: (env: Record<string, unknown>) => string;
57
- domain?: DomainSchemaResult;
57
+ domain?: DomainLike;
58
58
  }): (env: Record<string, unknown>) => Promise<{
59
59
  store: InstantStore;
60
60
  db: InstantStoreDb;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ekairos/events",
3
- "version": "1.22.81-beta.development.0",
3
+ "version": "1.22.83-beta.development.0",
4
4
  "description": "Ekairos Events - Context-first workflow runtime",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -127,7 +127,7 @@
127
127
  },
128
128
  "dependencies": {
129
129
  "@ai-sdk/openai": "^2.0.52",
130
- "@ekairos/domain": "^1.22.81-beta.development.0",
130
+ "@ekairos/domain": "^1.22.83-beta.development.0",
131
131
  "@instantdb/admin": "0.22.158",
132
132
  "@instantdb/core": "0.22.142",
133
133
  "@vercel/mcp-adapter": "^1.0.0",
@@ -138,7 +138,7 @@
138
138
  "llamaindex": "^0.12.0",
139
139
  "partial-json": "^0.1.7",
140
140
  "react": "^19.2.0",
141
- "workflow": "5.0.0-beta.1",
141
+ "workflow": "5.0.0-beta.5",
142
142
  "xmlbuilder2": "^3.1.1",
143
143
  "zod": "^4.3.6"
144
144
  },
@@ -147,8 +147,8 @@
147
147
  "@ekairos/tsconfig": "workspace:*",
148
148
  "@types/node": "^24.5.0",
149
149
  "@types/react": "^19.2.2",
150
- "@workflow/serde": "5.0.0-beta.0",
151
- "@workflow/vitest": "5.0.0-beta.1",
150
+ "@workflow/serde": "5.0.0-beta.1",
151
+ "@workflow/vitest": "5.0.0-beta.5",
152
152
  "dotenv": "^17.2.3",
153
153
  "typescript": "^5.9.2",
154
154
  "vitest": "^4.0.8"