@ekairos/events 1.22.39-beta.development.0 → 1.22.41-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.
Files changed (47) hide show
  1. package/README.md +5 -3
  2. package/dist/codex.d.ts +11 -2
  3. package/dist/codex.js +13 -5
  4. package/dist/context.action.d.ts +55 -0
  5. package/dist/context.action.js +25 -0
  6. package/dist/context.builder.d.ts +52 -42
  7. package/dist/context.builder.js +29 -24
  8. package/dist/context.d.ts +2 -1
  9. package/dist/context.engine.d.ts +50 -47
  10. package/dist/context.engine.js +222 -173
  11. package/dist/context.events.js +28 -87
  12. package/dist/context.js +1 -0
  13. package/dist/context.part-identity.d.ts +40 -0
  14. package/dist/context.part-identity.js +268 -0
  15. package/dist/context.parts.d.ts +389 -164
  16. package/dist/context.parts.js +235 -224
  17. package/dist/context.registry.d.ts +1 -1
  18. package/dist/context.runtime.d.ts +10 -4
  19. package/dist/context.runtime.js +7 -1
  20. package/dist/context.step-stream.d.ts +16 -2
  21. package/dist/context.step-stream.js +58 -16
  22. package/dist/context.stream.d.ts +4 -0
  23. package/dist/context.stream.js +23 -1
  24. package/dist/context.toolcalls.d.ts +8 -20
  25. package/dist/context.toolcalls.js +61 -55
  26. package/dist/domain.d.ts +1 -0
  27. package/dist/domain.js +1 -0
  28. package/dist/index.d.ts +8 -4
  29. package/dist/index.js +5 -3
  30. package/dist/reactors/ai-sdk.chunk-map.js +27 -0
  31. package/dist/reactors/ai-sdk.reactor.d.ts +8 -9
  32. package/dist/reactors/ai-sdk.reactor.js +2 -5
  33. package/dist/reactors/ai-sdk.step.d.ts +2 -3
  34. package/dist/reactors/ai-sdk.step.js +10 -7
  35. package/dist/reactors/scripted.reactor.d.ts +7 -4
  36. package/dist/reactors/types.d.ts +8 -8
  37. package/dist/schema.d.ts +273 -2
  38. package/dist/schema.js +1 -1
  39. package/dist/steps/store.steps.d.ts +51 -12
  40. package/dist/steps/store.steps.js +137 -0
  41. package/dist/steps/stream.steps.d.ts +15 -0
  42. package/dist/steps/stream.steps.js +16 -5
  43. package/dist/steps/trace.steps.d.ts +4 -4
  44. package/dist/steps/trace.steps.js +21 -6
  45. package/dist/tools-to-model-tools.d.ts +4 -2
  46. package/dist/tools-to-model-tools.js +30 -11
  47. package/package.json +16 -6
@@ -20,12 +20,27 @@ export type PersistedContextStepStreamSession = {
20
20
  executionId: string;
21
21
  stepId: string;
22
22
  };
23
+ export declare function createPersistedContextStepStreamForRuntime(runtime: {
24
+ db?: any;
25
+ }, params: {
26
+ executionId: string;
27
+ stepId: string;
28
+ clientId?: string;
29
+ }): Promise<PersistedContextStepStreamSession>;
23
30
  export declare function createPersistedContextStepStream(params: {
24
31
  runtime: ContextRuntime<ContextEnvironment>;
25
32
  executionId: string;
26
33
  stepId: string;
27
34
  clientId?: string;
28
35
  }): Promise<PersistedContextStepStreamSession>;
36
+ export declare function finalizePersistedContextStepStreamForRuntime(params: {
37
+ runtime: {
38
+ db?: any;
39
+ };
40
+ session: PersistedContextStepStreamSession;
41
+ mode: "close" | "abort";
42
+ abortReason?: string | null;
43
+ }): Promise<void>;
29
44
  export declare function closePersistedContextStepStream(params: {
30
45
  runtime: ContextRuntime<ContextEnvironment>;
31
46
  session: PersistedContextStepStreamSession;
@@ -63,9 +63,7 @@ export function createContextStepStreamClientId(stepId) {
63
63
  }
64
64
  return `event-step:${normalized}`;
65
65
  }
66
- export async function createPersistedContextStepStream(params) {
67
- "use step";
68
- const runtime = await getContextRuntimeServices(params.runtime);
66
+ export async function createPersistedContextStepStreamForRuntime(runtime, params) {
69
67
  const db = runtime?.db;
70
68
  if (!db?.streams?.createWriteStream) {
71
69
  throw new Error("InstantDB streams are not available on the configured runtime. Upgrade @instantdb/admin to a streams-capable version.");
@@ -105,10 +103,13 @@ export async function createPersistedContextStepStream(params) {
105
103
  stepId: params.stepId,
106
104
  };
107
105
  }
108
- async function finalizePersistedContextStepStream(params) {
106
+ export async function createPersistedContextStepStream(params) {
109
107
  "use step";
110
108
  const runtime = await getContextRuntimeServices(params.runtime);
111
- const db = runtime?.db;
109
+ return await createPersistedContextStepStreamForRuntime(runtime, params);
110
+ }
111
+ export async function finalizePersistedContextStepStreamForRuntime(params) {
112
+ const db = params.runtime?.db;
112
113
  const writer = params.session.stream.getWriter();
113
114
  try {
114
115
  if (params.mode === "abort") {
@@ -143,6 +144,16 @@ async function finalizePersistedContextStepStream(params) {
143
144
  txs.push(unsetActive);
144
145
  await db.transact(txs);
145
146
  }
147
+ async function finalizePersistedContextStepStream(params) {
148
+ "use step";
149
+ const runtime = await getContextRuntimeServices(params.runtime);
150
+ return await finalizePersistedContextStepStreamForRuntime({
151
+ runtime,
152
+ session: params.session,
153
+ mode: params.mode,
154
+ abortReason: params.abortReason,
155
+ });
156
+ }
146
157
  export async function closePersistedContextStepStream(params) {
147
158
  return await finalizePersistedContextStepStream({
148
159
  runtime: params.runtime,
@@ -1,6 +1,6 @@
1
1
  import "../polyfills/dom-events.js";
2
2
  import type { ContextEnvironment } from "../context.config.js";
3
- import type { ContextRuntime } from "../context.runtime.js";
3
+ import type { ContextRuntimeServiceHandle } from "../context.runtime.js";
4
4
  import type { TraceEventKind } from "../context.contract.js";
5
5
  export type ContextTraceEventWrite = {
6
6
  workflowRunId: string;
@@ -33,8 +33,8 @@ export type ContextTraceEventWrite = {
33
33
  payload?: unknown;
34
34
  testId?: string;
35
35
  };
36
- export declare function writeContextTraceEvents(params: {
37
- runtime?: ContextRuntime<ContextEnvironment>;
38
- env: ContextEnvironment;
36
+ export declare function writeContextTraceEvents<Env extends ContextEnvironment = ContextEnvironment>(params: {
37
+ runtime?: ContextRuntimeServiceHandle;
38
+ env?: Env;
39
39
  events: ContextTraceEventWrite[];
40
40
  }): Promise<void>;
@@ -18,6 +18,20 @@ function requireToken() {
18
18
  throw new Error("[context/trace] Missing EKAIROS_CLERK_API_KEY");
19
19
  }
20
20
  let jwtCache = null;
21
+ function asRecord(value) {
22
+ return value && typeof value === "object" ? value : {};
23
+ }
24
+ function asTraceEnv(value) {
25
+ const record = asRecord(value);
26
+ if (Object.keys(record).length === 0)
27
+ return undefined;
28
+ return {
29
+ baseUrl: typeof record.baseUrl === "string" ? record.baseUrl : undefined,
30
+ apiKey: typeof record.apiKey === "string" ? record.apiKey : undefined,
31
+ projectId: typeof record.projectId === "string" ? record.projectId : undefined,
32
+ strict: record.strict === true,
33
+ };
34
+ }
21
35
  function parseJwtExpMs(token) {
22
36
  const parts = token.split(".");
23
37
  if (parts.length !== 3)
@@ -47,8 +61,8 @@ async function getTraceAuthHeader(baseUrl, projectId) {
47
61
  body: JSON.stringify({ projectId }),
48
62
  });
49
63
  if (res.ok) {
50
- const json = (await res.json());
51
- const token = typeof json?.token === "string" ? json.token : "";
64
+ const json = asRecord(await res.json());
65
+ const token = typeof json.token === "string" ? json.token : "";
52
66
  const expMs = parseJwtExpMs(token) ?? now + 60 * 60 * 1000;
53
67
  if (token) {
54
68
  jwtCache = { token, expMs };
@@ -79,7 +93,8 @@ async function readProjectId() {
79
93
  export async function writeContextTraceEvents(params) {
80
94
  if (!params.events?.length)
81
95
  return;
82
- const envTrace = params.env?.traces;
96
+ const envRecord = asRecord(params.env);
97
+ const envTrace = asTraceEnv(envRecord.traces);
83
98
  // Tracing must NEVER break workflows by default.
84
99
  // Use EKAIROS_TRACES_STRICT=1 if you want to fail hard.
85
100
  const strict = envTrace?.strict === true || process.env.EKAIROS_TRACES_STRICT === "1";
@@ -89,11 +104,11 @@ export async function writeContextTraceEvents(params) {
89
104
  throw new Error("[context/trace] runtime is required");
90
105
  }
91
106
  const runtime = await getContextRuntimeServices(params.runtime);
92
- const db = runtime?.db;
107
+ const db = runtime.db;
93
108
  if (db) {
94
109
  const now = new Date();
95
- const orgId = typeof params.env?.orgId === "string"
96
- ? String(params.env.orgId)
110
+ const orgId = typeof envRecord.orgId === "string"
111
+ ? String(envRecord.orgId)
97
112
  : "";
98
113
  const projectId = await readProjectId();
99
114
  const byRun = new Map();
@@ -1,4 +1,3 @@
1
- import { type Tool } from "ai";
2
1
  /**
3
2
  * Serializable "tool" shape to pass across the Workflow step boundary.
4
3
  *
@@ -10,6 +9,7 @@ export type SerializableFunctionActionSpec = {
10
9
  type?: "function";
11
10
  description?: string;
12
11
  inputSchema: unknown;
12
+ outputSchema?: unknown;
13
13
  providerOptions?: unknown;
14
14
  };
15
15
  export type SerializableProviderDefinedActionSpec = {
@@ -29,7 +29,7 @@ export type SerializableToolForModel = SerializableActionSpec;
29
29
  * This matches DurableAgent's internal `toolsToModelTools` behavior:
30
30
  * `inputSchema: asSchema(tool.inputSchema).jsonSchema`
31
31
  */
32
- export declare function actionsToActionSpecs(tools: Record<string, Tool>): Record<string, SerializableActionSpec>;
32
+ export declare function actionsToActionSpecs(tools: Record<string, unknown>): Record<string, SerializableActionSpec>;
33
33
  export declare function actionSpecToAiSdkTool(name: string, spec: SerializableActionSpec, wrapJsonSchema: (schema: unknown) => unknown): {
34
34
  type: "provider-defined";
35
35
  id: string;
@@ -37,11 +37,13 @@ export declare function actionSpecToAiSdkTool(name: string, spec: SerializableAc
37
37
  args: Record<string, unknown>;
38
38
  description?: undefined;
39
39
  inputSchema?: undefined;
40
+ outputSchema?: undefined;
40
41
  providerOptions?: undefined;
41
42
  } | {
42
43
  type: "function";
43
44
  description: string | undefined;
44
45
  inputSchema: unknown;
46
+ outputSchema: unknown;
45
47
  providerOptions: unknown;
46
48
  id?: undefined;
47
49
  name?: undefined;
@@ -1,10 +1,25 @@
1
- import { asSchema } from "ai";
1
+ import { z } from "zod";
2
+ function toJsonSchema(schema) {
3
+ if (!schema)
4
+ return schema;
5
+ const jsonSchema = schema?.jsonSchema;
6
+ if (jsonSchema)
7
+ return jsonSchema;
8
+ try {
9
+ return z.toJSONSchema(schema);
10
+ }
11
+ catch {
12
+ return schema;
13
+ }
14
+ }
15
+ function asRecord(value) {
16
+ return value && typeof value === "object" ? value : {};
17
+ }
2
18
  function isProviderDefinedTool(tool) {
3
- return (Boolean(tool) &&
4
- typeof tool === "object" &&
5
- tool.type === "provider-defined" &&
6
- typeof tool.id === "string" &&
7
- tool.id.trim().length > 0);
19
+ const record = asRecord(tool);
20
+ return (record.type === "provider-defined" &&
21
+ typeof record.id === "string" &&
22
+ record.id.trim().length > 0);
8
23
  }
9
24
  /**
10
25
  * Convert AI SDK tools to a serializable representation that can be passed to `"use-step"` functions.
@@ -24,15 +39,18 @@ export function actionsToActionSpecs(tools) {
24
39
  };
25
40
  continue;
26
41
  }
27
- const inputSchema = tool?.inputSchema;
42
+ const record = asRecord(tool);
43
+ const inputSchema = record.inputSchema ?? record.input;
28
44
  if (!inputSchema) {
29
- throw new Error(`Context: tool "${name}" is missing inputSchema (required for model tool calls)`);
45
+ throw new Error(`Context: action "${name}" is missing input/inputSchema (required for model action calls)`);
30
46
  }
47
+ const outputSchema = record.outputSchema ?? record.output;
31
48
  out[name] = {
32
49
  type: "function",
33
- description: tool?.description,
34
- inputSchema: asSchema(inputSchema).jsonSchema,
35
- providerOptions: tool?.providerOptions,
50
+ description: typeof record.description === "string" ? record.description : undefined,
51
+ inputSchema: toJsonSchema(inputSchema),
52
+ outputSchema: outputSchema ? toJsonSchema(outputSchema) : undefined,
53
+ providerOptions: record.providerOptions,
36
54
  };
37
55
  }
38
56
  return out;
@@ -50,6 +68,7 @@ export function actionSpecToAiSdkTool(name, spec, wrapJsonSchema) {
50
68
  type: "function",
51
69
  description: spec.description,
52
70
  inputSchema: wrapJsonSchema(spec.inputSchema),
71
+ outputSchema: spec.outputSchema ? wrapJsonSchema(spec.outputSchema) : undefined,
53
72
  providerOptions: spec.providerOptions,
54
73
  };
55
74
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ekairos/events",
3
- "version": "1.22.39-beta.development.0",
3
+ "version": "1.22.41-beta.development.0",
4
4
  "description": "Ekairos Events - Context-first workflow runtime",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -30,6 +30,12 @@
30
30
  "require": "./dist/schema.js",
31
31
  "default": "./dist/schema.js"
32
32
  },
33
+ "./domain": {
34
+ "types": "./dist/domain.d.ts",
35
+ "import": "./dist/domain.js",
36
+ "require": "./dist/domain.js",
37
+ "default": "./dist/domain.js"
38
+ },
33
39
  "./runtime": {
34
40
  "types": "./dist/runtime.d.ts",
35
41
  "import": "./dist/runtime.js",
@@ -78,6 +84,9 @@
78
84
  "schema": [
79
85
  "dist/schema.d.ts"
80
86
  ],
87
+ "domain": [
88
+ "dist/domain.d.ts"
89
+ ],
81
90
  "runtime": [
82
91
  "dist/runtime.d.ts"
83
92
  ],
@@ -107,6 +116,7 @@
107
116
  "watch": "tsc -p tsconfig.json --watch",
108
117
  "clean": "node -e \"require('fs').rmSync('dist', {recursive:true, force:true})\"",
109
118
  "typecheck": "tsc --noEmit",
119
+ "typecheck:tests": "tsc --noEmit -p tsconfig.typecheck.json",
110
120
  "test": "vitest run -c vitest.config.mts",
111
121
  "test:workflow": "vitest run -c vitest.workflow.config.mts",
112
122
  "pretest:ai-sdk-reactor": "pnpm --filter @ekairos/domain build",
@@ -117,7 +127,7 @@
117
127
  },
118
128
  "dependencies": {
119
129
  "@ai-sdk/openai": "^2.0.52",
120
- "@ekairos/domain": "^1.22.39-beta.development.0",
130
+ "@ekairos/domain": "^1.22.41-beta.development.0",
121
131
  "@instantdb/admin": "0.22.158",
122
132
  "@instantdb/core": "0.22.142",
123
133
  "@vercel/mcp-adapter": "^1.0.0",
@@ -134,12 +144,12 @@
134
144
  "devDependencies": {
135
145
  "@ekairos/testing": "workspace:*",
136
146
  "@ekairos/tsconfig": "workspace:*",
137
- "@workflow/serde": "5.0.0-beta.0",
138
- "@workflow/vitest": "5.0.0-beta.1",
139
147
  "@types/node": "^24.5.0",
140
148
  "@types/react": "^19.2.2",
149
+ "@workflow/serde": "5.0.0-beta.0",
150
+ "@workflow/vitest": "5.0.0-beta.1",
141
151
  "dotenv": "^17.2.3",
142
- "vitest": "^4.0.8",
143
- "typescript": "^5.9.2"
152
+ "typescript": "^5.9.2",
153
+ "vitest": "^4.0.8"
144
154
  }
145
155
  }