@ekairos/events 1.22.82-beta.development.0 → 1.22.84-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.
@@ -23,6 +23,14 @@ export type ContextContentUpdatedEvent = ContextStreamEventBase & {
23
23
  type: "context.content_updated";
24
24
  contextId: string;
25
25
  };
26
+ export type ContextDefinitionUpdatedEvent = ContextStreamEventBase & {
27
+ type: "context.definition_updated";
28
+ contextId: string;
29
+ };
30
+ export type ContextResourcesUpdatedEvent = ContextStreamEventBase & {
31
+ type: "context.resources_updated";
32
+ contextId: string;
33
+ };
26
34
  export type ExecutionCreatedEvent = ContextStreamEventBase & {
27
35
  type: "execution.created";
28
36
  executionId: string;
@@ -138,7 +146,7 @@ export type ChunkEmittedEvent = ContextStreamEventBase & {
138
146
  data?: unknown;
139
147
  raw?: unknown;
140
148
  };
141
- export type ContextLifecycleEvent = ContextCreatedEvent | ContextResolvedEvent | ContextStatusChangedEvent | ContextContentUpdatedEvent;
149
+ export type ContextLifecycleEvent = ContextCreatedEvent | ContextResolvedEvent | ContextStatusChangedEvent | ContextContentUpdatedEvent | ContextDefinitionUpdatedEvent | ContextResourcesUpdatedEvent;
142
150
  export type ExecutionEvent = ExecutionCreatedEvent | ExecutionCompletedEvent | ExecutionFailedEvent;
143
151
  export type ItemEvent = ItemCreatedEvent | ItemUpdatedEvent | ItemPendingEvent | ItemCompletedEvent;
144
152
  export type StepEvent = StepCreatedEvent | StepUpdatedEvent | StepCompletedEvent | StepFailedEvent;
@@ -48,6 +48,14 @@ export function parseContextStreamEvent(value) {
48
48
  assertString(value.contextId, `${type}.contextId`);
49
49
  return value;
50
50
  }
51
+ case "context.definition_updated": {
52
+ assertString(value.contextId, `${type}.contextId`);
53
+ return value;
54
+ }
55
+ case "context.resources_updated": {
56
+ assertString(value.contextId, `${type}.contextId`);
57
+ return value;
58
+ }
51
59
  case "execution.created":
52
60
  case "execution.completed":
53
61
  case "execution.failed": {
package/dist/index.d.ts CHANGED
@@ -1,9 +1,9 @@
1
- export { context, createContext, createAiSdkReactor, createScriptedReactor, type CreateAiSdkReactorOptions, type CreateScriptedReactorOptions, type ScriptedReactorStep, type ContextConfig, type ContextInstance, type ContextOptions, type ContextStreamOptions, type ContextReactor, type ContextReactorParams, type ContextReactionResult, type ContextActionRequest, type ContextReactionLLM, ContextEngine, defineAction, action, type RegistrableContextBuilder, type ContextReactParams, type ContextDirectReactParams, type ContextDurableReactParams, type ContextReactResult, type ContextReactBase, type ContextReactFinalResult, type ContextDirectRun, type ContextReactRun, type ContextWorkflowRun, type ContextDurableWorkflowPayload, type ContextDurableWorkflowFunction, type ContextModelInit, type ContextTool, type ContextAction, type ContextActionBase, type ContextActionExecuteParams, type AnyContextAction, type ContextActionDefinition, type DefineContextActionDefinition, type DefineContextActionExecute, type LegacyContextActionDefinition, type LegacyContextActionExecute, type ContextActionExecute, type ContextActionInput, type ContextActionOutput, type ContextProviderDefinedAction, type ContextActionSchema, type ContextToolExecuteContext, runContextReactionDirect, } from "./context.js";
2
- export type { ContextStore, ContextIdentifier, StoredContext, ContextItem, ContextExecution, } from "./context.store.js";
1
+ export { context, createContext, createAiSdkReactor, createScriptedReactor, type CreateAiSdkReactorOptions, type CreateScriptedReactorOptions, type ScriptedReactorStep, type ContextConfig, type ContextResourcesParams, type ContextInstance, type ContextOptions, type ContextStreamOptions, type ContextReactor, type ContextReactorParams, type ContextReactionResult, type ContextActionRequest, type ContextReactionLLM, ContextEngine, defineAction, action, type RegistrableContextBuilder, type ContextReactParams, type ContextDirectReactParams, type ContextDurableReactParams, type ContextReactResult, type ContextReactBase, type ContextReactFinalResult, type ContextDirectRun, type ContextReactRun, type ContextWorkflowRun, type ContextDurableWorkflowPayload, type ContextDurableWorkflowFunction, type ContextModelInit, type ContextTool, type ContextAction, type ContextActionBase, type ContextActionExecuteParams, type AnyContextAction, type ContextActionDefinition, type DefineContextActionDefinition, type DefineContextActionExecute, type LegacyContextActionDefinition, type LegacyContextActionExecute, type ContextActionExecute, type ContextActionInput, type ContextActionOutput, type ContextProviderDefinedAction, type ContextActionSchema, type ContextToolExecuteContext, runContextReactionDirect, } from "./context.js";
2
+ export type { ContextStore, ContextIdentifier, StoredContext, ContextResource, ContextResourceBase, ContextFileResource, ContextLinkResource, ContextRepositoryResource, ContextDatasetResource, ContextExternalResource, StoredContextResource, ContextItem, ContextExecution, } from "./context.store.js";
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";
@@ -16,6 +16,6 @@ export { CONTEXT_STEP_STREAM_VERSION, createContextStepStreamChunk, validateCont
16
16
  export type { ContextStepStreamChunkValidationOptions, } from "./context.step-stream.js";
17
17
  export { CONTEXT_PART_ID_NAMESPACE, CONTEXT_PART_UUID_RE, CONTEXT_STREAM_PART_TYPES, assertValidContextPartChunkIdentity, resolveContextPartChunkDescriptor, resolveContextPartChunkIdentity, resolveContextPartId, resolveContextStreamPartSlot, resolveContextStreamPartType, uuidV5, } from "./context.part-identity.js";
18
18
  export type { ContextPartChunkDescriptor, ContextPartChunkIdentity, ContextPartChunkIdentityInput, ContextPartChunkValidationInput, ContextStreamPartSlot, ContextStreamPartType, } from "./context.part-identity.js";
19
- export type { ContextStreamEvent, ContextCreatedEvent, ContextResolvedEvent, ContextStatusChangedEvent, ContextContentUpdatedEvent, ExecutionCreatedEvent, ExecutionCompletedEvent, ExecutionFailedEvent, ItemCreatedEvent, ItemUpdatedEvent, ItemPendingEvent, ItemCompletedEvent, StepCreatedEvent, StepUpdatedEvent, StepCompletedEvent, StepFailedEvent, PartCreatedEvent, PartUpdatedEvent, ChunkEmittedEvent, } from "./context.stream.js";
19
+ export type { ContextStreamEvent, ContextCreatedEvent, ContextResolvedEvent, ContextStatusChangedEvent, ContextContentUpdatedEvent, ContextDefinitionUpdatedEvent, ContextResourcesUpdatedEvent, ExecutionCreatedEvent, ExecutionCompletedEvent, ExecutionFailedEvent, ItemCreatedEvent, ItemUpdatedEvent, ItemPendingEvent, ItemCompletedEvent, StepCreatedEvent, StepUpdatedEvent, StepCompletedEvent, StepFailedEvent, PartCreatedEvent, PartUpdatedEvent, ChunkEmittedEvent, } from "./context.stream.js";
20
20
  export type { ContextStepStreamChunk } from "./context.step-stream.js";
21
21
  export type { ContextSkillPackage, ContextSkillPackageFile } from "./context.skill.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>;
@@ -46,7 +46,6 @@ export function createAiSdkReactor(options) {
46
46
  iteration: params.iteration,
47
47
  maxSteps,
48
48
  sendStart: params.sendStart,
49
- silent: params.silent,
50
49
  contextStepStream: params.contextStepStream,
51
50
  writable: params.writable,
52
51
  executionId: params.executionId,
@@ -55,9 +54,9 @@ export function createAiSdkReactor(options) {
55
54
  });
56
55
  return {
57
56
  assistantEvent: result.assistantEvent,
58
- actionRequests: result.toolCalls.map((entry) => ({
59
- actionRef: String(entry.toolCallId),
60
- actionName: String(entry.toolName),
57
+ actionRequests: result.actionCalls.map((entry) => ({
58
+ actionRef: String(entry.actionCallId),
59
+ actionName: String(entry.actionName),
61
60
  input: entry.args,
62
61
  })),
63
62
  messagesForModel: result.messagesForModel,
@@ -24,7 +24,6 @@ export declare function executeAiSdkReaction<Env extends ContextEnvironment = Co
24
24
  iteration?: number;
25
25
  maxSteps: number;
26
26
  sendStart?: boolean;
27
- silent?: boolean;
28
27
  contextStepStream?: WritableStream<string>;
29
28
  writable?: WritableStream<UIMessageChunk>;
30
29
  executionId?: string;
@@ -32,7 +31,7 @@ export declare function executeAiSdkReaction<Env extends ContextEnvironment = Co
32
31
  stepId?: string;
33
32
  }): Promise<{
34
33
  assistantEvent: ContextItem;
35
- toolCalls: any[];
34
+ actionCalls: any[];
36
35
  messagesForModel: ModelMessage[];
37
36
  llm?: {
38
37
  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,10 +1,10 @@
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";
6
6
  import type { ContextModelInit } from "../context.engine.js";
7
- import type { ContextIdentifier, StoredContext, ContextItem } from "../context.store.js";
7
+ import type { ContextIdentifier, StoredContext, StoredContextResource, ContextItem } from "../context.store.js";
8
8
  import type { ContextSkillPackage } from "../context.skill.js";
9
9
  import { eventsDomain } from "../schema.js";
10
10
  export type ContextActionRequest = {
@@ -34,10 +34,11 @@ 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;
41
+ resources: StoredContextResource[];
41
42
  /**
42
43
  * Context items after the engine-level expansion stage.
43
44
  *
@@ -59,9 +60,8 @@ export type ContextReactorParams<Context = unknown, Env extends ContextEnvironme
59
60
  iteration: number;
60
61
  maxModelSteps: number;
61
62
  sendStart: boolean;
62
- silent: boolean;
63
63
  contextStepStream?: WritableStream<string>;
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>;
package/dist/schema.d.ts CHANGED
@@ -6,6 +6,9 @@ export declare const eventsDomain: import("@ekairos/domain").DomainSchemaResult<
6
6
  name: import("@instantdb/core").DataAttrDef<string, false, false, false>;
7
7
  status: import("@instantdb/core").DataAttrDef<string, false, true, false>;
8
8
  content: import("@instantdb/core").DataAttrDef<any, false, false, false>;
9
+ description: import("@instantdb/core").DataAttrDef<string, false, false, false>;
10
+ goal: import("@instantdb/core").DataAttrDef<string, false, false, false>;
11
+ resources: import("@instantdb/core").DataAttrDef<any, false, false, false>;
9
12
  reactor: import("@instantdb/core").DataAttrDef<any, false, false, false>;
10
13
  }, {}, unknown>;
11
14
  event_items: import("@instantdb/core").EntityDef<{
package/dist/schema.js CHANGED
@@ -10,6 +10,9 @@ export const eventsDomain = domain("events")
10
10
  name: i.string().optional(),
11
11
  status: i.string().optional().indexed(), // open_idle | open_streaming | closed
12
12
  content: i.any().optional(),
13
+ description: i.string().optional(),
14
+ goal: i.string().optional(),
15
+ resources: i.any().optional(),
13
16
  reactor: i.json().optional(),
14
17
  }),
15
18
  event_items: i.entity({
@@ -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,7 +1,6 @@
1
- import type { UIMessageChunk } from "ai";
2
1
  import type { ContextEnvironment } from "../context.config.js";
3
2
  import type { ContextRuntime } from "../context.runtime.js";
4
- import type { ContextExecution, ContextItem, ContextIdentifier, StoredContext, ContextStatus } from "../context.store.js";
3
+ import type { ContextExecution, ContextItem, ContextIdentifier, ContextResource, StoredContextResource, StoredContext, ContextStatus } from "../context.store.js";
5
4
  import type { ContextStreamEvent } from "../context.stream.js";
6
5
  import { type ContextActionResultForStream, type PersistedContextStepStreamSession } from "./stream.steps.js";
7
6
  type RuntimeParams<Env extends ContextEnvironment = ContextEnvironment> = {
@@ -22,10 +21,6 @@ type ContextStepPatch = {
22
21
  */
23
22
  export declare function initializeContext<C>(params: RuntimeParams & {
24
23
  contextIdentifier: ContextIdentifier | null;
25
- opts?: {
26
- silent?: boolean;
27
- writable?: WritableStream<UIMessageChunk>;
28
- };
29
24
  }): Promise<{
30
25
  context: StoredContext<C>;
31
26
  isNew: boolean;
@@ -34,6 +29,17 @@ export declare function updateContextContent<C>(params: RuntimeParams & {
34
29
  contextIdentifier: ContextIdentifier;
35
30
  content: C;
36
31
  }): Promise<StoredContext<C>>;
32
+ export declare function updateContextDefinition<C>(params: RuntimeParams & {
33
+ contextIdentifier: ContextIdentifier;
34
+ definition: {
35
+ description?: string | null;
36
+ goal?: string | null;
37
+ };
38
+ }): Promise<StoredContext<C>>;
39
+ export declare function upsertContextResources(params: RuntimeParams & {
40
+ contextIdentifier: ContextIdentifier;
41
+ resources: ContextResource[];
42
+ }): Promise<StoredContextResource[]>;
37
43
  export declare function updateContextReactor<C>(params: RuntimeParams & {
38
44
  contextIdentifier: ContextIdentifier;
39
45
  reactor: {
@@ -143,6 +143,16 @@ export async function updateContextContent(params) {
143
143
  const { runtime } = await getRuntimeAndEnv(params);
144
144
  return await runtime.store.updateContextContent(params.contextIdentifier, params.content);
145
145
  }
146
+ export async function updateContextDefinition(params) {
147
+ "use step";
148
+ const { runtime } = await getRuntimeAndEnv(params);
149
+ return await runtime.store.updateContextDefinition(params.contextIdentifier, params.definition);
150
+ }
151
+ export async function upsertContextResources(params) {
152
+ "use step";
153
+ const { runtime } = await getRuntimeAndEnv(params);
154
+ return await runtime.store.upsertContextResources(params.contextIdentifier, params.resources);
155
+ }
146
156
  export async function updateContextReactor(params) {
147
157
  "use step";
148
158
  const { runtime } = await getRuntimeAndEnv(params);
@@ -1,7 +1,7 @@
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
- import type { ContextItem, ContextIdentifier, ContextStatus, StoredContext, ContextStore } from "../context.store.js";
4
+ import type { ContextItem, ContextIdentifier, ContextResource, ContextStatus, StoredContextResource, StoredContext, ContextStore } from "../context.store.js";
5
5
  export { parseAndStoreDocument } from "./instant.document-parser.js";
6
6
  export { coerceDocumentTextPages, expandEventsWithInstantDocuments, } from "./instant.documents.js";
7
7
  export type InstantStoreDb = any;
@@ -14,12 +14,20 @@ export declare class InstantStore implements ContextStore {
14
14
  getOrCreateContext<C>(contextIdentifier: ContextIdentifier | null): Promise<StoredContext<C>>;
15
15
  getContext<C>(contextIdentifier: ContextIdentifier): Promise<StoredContext<C> | null>;
16
16
  updateContextContent<C>(contextIdentifier: ContextIdentifier, content: C): Promise<StoredContext<C>>;
17
+ updateContextDefinition<C>(contextIdentifier: ContextIdentifier, definition: {
18
+ description?: string | null;
19
+ goal?: string | null;
20
+ }): Promise<StoredContext<C>>;
17
21
  updateContextReactor<C>(contextIdentifier: ContextIdentifier, reactor: {
18
22
  kind: string;
19
23
  state?: Record<string, unknown> | null;
20
24
  }): Promise<StoredContext<C>>;
21
25
  updateContextStatus(contextIdentifier: ContextIdentifier, status: ContextStatus): Promise<void>;
22
26
  private resolveContext;
27
+ private normalizeContextResource;
28
+ private normalizeContextResources;
29
+ getContextResources(contextIdentifier: ContextIdentifier): Promise<StoredContextResource[]>;
30
+ upsertContextResources(contextIdentifier: ContextIdentifier, resources: ContextResource[]): Promise<StoredContextResource[]>;
23
31
  saveItem(contextIdentifier: ContextIdentifier, event: ContextItem): Promise<ContextItem>;
24
32
  updateItem(eventId: string, event: ContextItem): Promise<ContextItem>;
25
33
  getItem(eventId: string): Promise<ContextItem | null>;
@@ -54,7 +62,7 @@ export declare class InstantStore implements ContextStore {
54
62
  export declare function createInstantStoreRuntime(params: {
55
63
  getDb: (orgId: string) => Promise<InstantStoreDb> | InstantStoreDb;
56
64
  getOrgId?: (env: Record<string, unknown>) => string;
57
- domain?: DomainSchemaResult;
65
+ domain?: DomainLike;
58
66
  }): (env: Record<string, unknown>) => Promise<{
59
67
  store: InstantStore;
60
68
  db: InstantStoreDb;