@ekairos/events 1.22.39-beta.development.0 → 1.22.40-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 (45) 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/index.d.ts +8 -4
  27. package/dist/index.js +5 -3
  28. package/dist/reactors/ai-sdk.chunk-map.js +27 -0
  29. package/dist/reactors/ai-sdk.reactor.d.ts +8 -9
  30. package/dist/reactors/ai-sdk.reactor.js +2 -5
  31. package/dist/reactors/ai-sdk.step.d.ts +2 -3
  32. package/dist/reactors/ai-sdk.step.js +10 -7
  33. package/dist/reactors/scripted.reactor.d.ts +7 -4
  34. package/dist/reactors/types.d.ts +8 -8
  35. package/dist/schema.d.ts +273 -2
  36. package/dist/schema.js +1 -1
  37. package/dist/steps/store.steps.d.ts +51 -12
  38. package/dist/steps/store.steps.js +137 -0
  39. package/dist/steps/stream.steps.d.ts +15 -0
  40. package/dist/steps/stream.steps.js +16 -5
  41. package/dist/steps/trace.steps.d.ts +4 -4
  42. package/dist/steps/trace.steps.js +21 -6
  43. package/dist/tools-to-model-tools.d.ts +4 -2
  44. package/dist/tools-to-model-tools.js +30 -11
  45. package/package.json +7 -6
@@ -1,5 +1,13 @@
1
1
  import { z } from "zod";
2
- const metadataSchema = z.record(z.string(), z.unknown()).optional();
2
+ export const reactorMetadataSchema = z
3
+ .object({
4
+ reactorKind: z.string().min(1),
5
+ executionId: z.string().optional(),
6
+ itemId: z.string().optional(),
7
+ eventName: z.string().optional(),
8
+ actionCallId: z.string().optional(),
9
+ })
10
+ .catchall(z.unknown());
3
11
  const textContentSchema = z.object({
4
12
  type: z.literal("text"),
5
13
  text: z.string(),
@@ -45,63 +53,87 @@ export const contextPartContentSchema = z.discriminatedUnion("type", [
45
53
  sourceUrlContentSchema,
46
54
  sourceDocumentContentSchema,
47
55
  ]);
48
- const contextInlineContentSchema = z.discriminatedUnion("type", [
56
+ export const contextInlineContentSchema = z.discriminatedUnion("type", [
49
57
  textContentSchema,
50
58
  fileContentSchema,
51
59
  jsonContentSchema,
52
60
  ]);
53
- const contextContentPartSchema = z.object({
54
- type: z.literal("content"),
55
- content: z.array(contextInlineContentSchema),
56
- state: z.enum(["streaming", "done"]).optional(),
61
+ const messageContentSchema = z
62
+ .object({
63
+ text: z.string().optional(),
64
+ blocks: z.array(contextInlineContentSchema).optional(),
65
+ })
66
+ .superRefine((value, ctx) => {
67
+ const hasText = typeof value.text === "string" && value.text.length > 0;
68
+ const hasBlocks = Array.isArray(value.blocks) && value.blocks.length > 0;
69
+ if (!hasText && !hasBlocks) {
70
+ ctx.addIssue({
71
+ code: z.ZodIssueCode.custom,
72
+ message: "message content requires text or blocks",
73
+ });
74
+ }
75
+ });
76
+ export const contextMessagePartSchema = z.object({
77
+ type: z.literal("message"),
78
+ content: messageContentSchema,
79
+ reactorMetadata: reactorMetadataSchema.optional(),
57
80
  });
58
- const contextReasoningPartSchema = z.object({
81
+ export const contextReasoningPartSchema = z.object({
59
82
  type: z.literal("reasoning"),
60
- content: z.array(textContentSchema),
61
- state: z.enum(["streaming", "done"]).optional(),
83
+ content: z.object({
84
+ text: z.string(),
85
+ state: z.enum(["streaming", "done"]).optional(),
86
+ }),
87
+ reactorMetadata: reactorMetadataSchema.optional(),
62
88
  });
63
- const contextSourcePartSchema = z.object({
89
+ export const contextSourcePartSchema = z.object({
64
90
  type: z.literal("source"),
65
- content: z.array(z.discriminatedUnion("type", [sourceUrlContentSchema, sourceDocumentContentSchema])),
91
+ content: z.object({
92
+ sources: z.array(z.discriminatedUnion("type", [sourceUrlContentSchema, sourceDocumentContentSchema])),
93
+ }),
94
+ reactorMetadata: reactorMetadataSchema.optional(),
66
95
  });
67
- const contextToolCallPartSchema = z.object({
68
- type: z.literal("tool-call"),
69
- toolCallId: z.string().min(1),
70
- toolName: z.string().min(1),
71
- content: z.array(contextInlineContentSchema),
72
- state: z.enum(["input-streaming", "input-available"]).optional(),
96
+ const contextActionErrorSchema = z.object({
97
+ message: z.string(),
98
+ code: z.string().optional(),
99
+ details: z.unknown().optional(),
73
100
  });
74
- const contextToolResultPartSchema = z.object({
75
- type: z.literal("tool-result"),
76
- toolCallId: z.string().min(1),
77
- toolName: z.string().min(1),
78
- content: z.array(contextInlineContentSchema),
79
- state: z.enum(["output-available", "output-error"]).optional(),
101
+ export const contextActionPartSchema = z.object({
102
+ type: z.literal("action"),
103
+ content: z.discriminatedUnion("status", [
104
+ z.object({
105
+ status: z.literal("started"),
106
+ actionName: z.string().min(1),
107
+ actionCallId: z.string().min(1),
108
+ input: z.unknown(),
109
+ }),
110
+ z.object({
111
+ status: z.literal("completed"),
112
+ actionName: z.string().min(1),
113
+ actionCallId: z.string().min(1),
114
+ output: z.unknown(),
115
+ }),
116
+ z.object({
117
+ status: z.literal("failed"),
118
+ actionName: z.string().min(1),
119
+ actionCallId: z.string().min(1),
120
+ error: contextActionErrorSchema,
121
+ }),
122
+ ]),
123
+ reactorMetadata: reactorMetadataSchema.optional(),
80
124
  });
81
- export const contextPartSchema = z.discriminatedUnion("type", [
82
- contextContentPartSchema,
125
+ export const contextEnginePartSchema = z.discriminatedUnion("type", [
126
+ contextMessagePartSchema,
83
127
  contextReasoningPartSchema,
84
128
  contextSourcePartSchema,
85
- contextToolCallPartSchema,
86
- contextToolResultPartSchema,
87
129
  ]);
88
- export const contextPartEnvelopeSchema = z.discriminatedUnion("type", [
89
- contextContentPartSchema.extend({
90
- metadata: metadataSchema,
91
- }),
92
- contextReasoningPartSchema.extend({
93
- metadata: metadataSchema,
94
- }),
95
- contextSourcePartSchema.extend({
96
- metadata: metadataSchema,
97
- }),
98
- contextToolCallPartSchema.extend({
99
- metadata: metadataSchema,
100
- }),
101
- contextToolResultPartSchema.extend({
102
- metadata: metadataSchema,
103
- }),
130
+ export const contextPartSchema = z.discriminatedUnion("type", [
131
+ contextMessagePartSchema,
132
+ contextReasoningPartSchema,
133
+ contextSourcePartSchema,
134
+ contextActionPartSchema,
104
135
  ]);
136
+ export const contextPartEnvelopeSchema = contextPartSchema;
105
137
  function asRecord(value) {
106
138
  if (!value || typeof value !== "object")
107
139
  return null;
@@ -110,10 +142,54 @@ function asRecord(value) {
110
142
  function cleanRecord(value) {
111
143
  return Object.fromEntries(Object.entries(value).filter(([, item]) => item !== undefined));
112
144
  }
113
- function normalizeMetadata(value) {
114
- if (!value || typeof value !== "object")
115
- return undefined;
116
- return value;
145
+ function createContextActionPartSchemas(actions) {
146
+ const schemas = [];
147
+ for (const [actionName, action] of Object.entries(actions)) {
148
+ schemas.push(z.object({
149
+ type: z.literal("action"),
150
+ content: z.object({
151
+ status: z.literal("started"),
152
+ actionName: z.literal(actionName),
153
+ actionCallId: z.string().min(1),
154
+ input: action.input,
155
+ }),
156
+ reactorMetadata: reactorMetadataSchema.optional(),
157
+ }), z.object({
158
+ type: z.literal("action"),
159
+ content: z.object({
160
+ status: z.literal("completed"),
161
+ actionName: z.literal(actionName),
162
+ actionCallId: z.string().min(1),
163
+ output: action.output,
164
+ }),
165
+ reactorMetadata: reactorMetadataSchema.optional(),
166
+ }), z.object({
167
+ type: z.literal("action"),
168
+ content: z.object({
169
+ status: z.literal("failed"),
170
+ actionName: z.literal(actionName),
171
+ actionCallId: z.string().min(1),
172
+ error: contextActionErrorSchema,
173
+ }),
174
+ reactorMetadata: reactorMetadataSchema.optional(),
175
+ }));
176
+ }
177
+ return schemas;
178
+ }
179
+ export function createContextPartSchema(actions) {
180
+ const actionSchemas = actions ? createContextActionPartSchemas(actions) : [];
181
+ if (actionSchemas.length === 0) {
182
+ return contextEnginePartSchema;
183
+ }
184
+ return z.union([
185
+ contextMessagePartSchema,
186
+ contextReasoningPartSchema,
187
+ contextSourcePartSchema,
188
+ ...actionSchemas,
189
+ ]);
190
+ }
191
+ export function parseContextPart(actions, value) {
192
+ return createContextPartSchema(actions).parse(value);
117
193
  }
118
194
  export function isContextPartEnvelope(value) {
119
195
  return contextPartEnvelopeSchema.safeParse(value).success;
@@ -122,17 +198,13 @@ export function parseContextPartEnvelope(value) {
122
198
  return contextPartEnvelopeSchema.parse(value);
123
199
  }
124
200
  export function splitContextPartEnvelope(value) {
125
- const { metadata, ...part } = value;
126
201
  return {
127
- part,
128
- metadata,
202
+ part: parseContextPartEnvelope(value),
203
+ metadata: undefined,
129
204
  };
130
205
  }
131
206
  export function mergeContextPartEnvelope(params) {
132
- return parseContextPartEnvelope({
133
- ...(asRecord(params.part) ?? {}),
134
- metadata: normalizeMetadata(params.metadata),
135
- });
207
+ return parseContextPartEnvelope(params.part);
136
208
  }
137
209
  function normalizeFileContentBlock(value) {
138
210
  return contextInlineContentSchema.parse(cleanRecord({
@@ -144,217 +216,156 @@ function normalizeFileContentBlock(value) {
144
216
  fileId: typeof value.fileId === "string" ? value.fileId : undefined,
145
217
  }));
146
218
  }
147
- export function normalizeToolResultContentToBlocks(value) {
148
- if (value === undefined || value === null) {
149
- return [];
150
- }
151
- if (typeof value === "string") {
152
- return [{ type: "text", text: value }];
153
- }
154
- const record = asRecord(value);
155
- if (!record) {
156
- return [{ type: "json", value }];
157
- }
158
- if (record.type === "json") {
159
- return [{ type: "json", value: record.value }];
160
- }
161
- if (record.type === "content" && Array.isArray(record.value)) {
162
- const blocks = [];
163
- for (const entry of record.value) {
164
- const contentRecord = asRecord(entry);
165
- if (!contentRecord || typeof contentRecord.type !== "string") {
166
- blocks.push({ type: "json", value: entry });
167
- continue;
168
- }
169
- if (contentRecord.type === "text" && typeof contentRecord.text === "string") {
170
- blocks.push({ type: "text", text: contentRecord.text });
171
- continue;
172
- }
173
- if (contentRecord.type === "image-data") {
174
- blocks.push(cleanRecord({
175
- type: "file",
176
- mediaType: typeof contentRecord.mediaType === "string"
177
- ? contentRecord.mediaType
178
- : "application/octet-stream",
179
- filename: typeof contentRecord.filename === "string"
180
- ? contentRecord.filename
181
- : undefined,
182
- data: typeof contentRecord.data === "string" ? contentRecord.data : undefined,
183
- }));
184
- continue;
185
- }
186
- if (contentRecord.type === "file") {
187
- blocks.push(normalizeFileContentBlock(contentRecord));
188
- continue;
189
- }
190
- blocks.push({ type: "json", value: entry });
191
- }
192
- return blocks;
193
- }
194
- if (record.type === "file") {
195
- return [normalizeFileContentBlock(record)];
196
- }
197
- return [{ type: "json", value }];
219
+ function readReactorMetadata(record) {
220
+ const parsed = reactorMetadataSchema.safeParse(record.reactorMetadata);
221
+ return parsed.success ? parsed.data : undefined;
198
222
  }
199
- function metadataFromUiPart(part) {
200
- const metadata = cleanRecord({
201
- provider: normalizeMetadata(part.providerMetadata),
202
- providerCall: normalizeMetadata(part.callProviderMetadata),
203
- });
204
- return Object.keys(metadata).length > 0 ? metadata : undefined;
223
+ function messageFromBlocks(blocks, reactorMetadata) {
224
+ if (blocks.length === 0)
225
+ return [];
226
+ const text = blocks
227
+ .filter((block) => block.type === "text")
228
+ .map((block) => block.text)
229
+ .join("\n");
230
+ const hasNonText = blocks.some((block) => block.type !== "text");
231
+ return [
232
+ contextMessagePartSchema.parse(cleanRecord({
233
+ type: "message",
234
+ content: cleanRecord({
235
+ text: text || undefined,
236
+ blocks: hasNonText ? blocks : undefined,
237
+ }),
238
+ reactorMetadata,
239
+ })),
240
+ ];
205
241
  }
206
242
  export function normalizeUiPartToContextPartEnvelopes(value) {
207
243
  const record = asRecord(value);
208
244
  if (!record || typeof record.type !== "string") {
209
245
  return [];
210
246
  }
211
- const metadata = metadataFromUiPart(record);
247
+ const reactorMetadata = readReactorMetadata(record);
212
248
  if (record.type === "text" && typeof record.text === "string") {
213
- return [
214
- {
215
- type: "content",
216
- content: [{ type: "text", text: record.text }],
217
- state: record.state === "streaming" ? "streaming" : "done",
218
- metadata,
219
- },
220
- ];
249
+ return messageFromBlocks([{ type: "text", text: record.text }], reactorMetadata);
221
250
  }
222
251
  if (record.type === "reasoning" && typeof record.text === "string") {
223
252
  return [
224
- {
253
+ contextReasoningPartSchema.parse(cleanRecord({
225
254
  type: "reasoning",
226
- content: [{ type: "text", text: record.text }],
227
- state: record.state === "streaming" ? "streaming" : "done",
228
- metadata,
229
- },
255
+ content: cleanRecord({
256
+ text: record.text,
257
+ state: record.state === "streaming" ? "streaming" : "done",
258
+ }),
259
+ reactorMetadata,
260
+ })),
230
261
  ];
231
262
  }
232
263
  if (record.type === "file") {
233
- return [
234
- {
235
- type: "content",
236
- content: [
237
- cleanRecord({
238
- type: "file",
239
- mediaType: typeof record.mediaType === "string"
240
- ? record.mediaType
241
- : "application/octet-stream",
242
- filename: typeof record.filename === "string" ? record.filename : undefined,
243
- url: typeof record.url === "string" ? record.url : undefined,
244
- data: typeof record.data === "string" ? record.data : undefined,
245
- fileId: typeof record.fileId === "string" ? record.fileId : undefined,
246
- }),
247
- ],
248
- metadata,
249
- },
250
- ];
264
+ return messageFromBlocks([normalizeFileContentBlock(record)], reactorMetadata);
251
265
  }
252
266
  if (record.type === "source-url") {
253
267
  return [
254
- {
268
+ contextSourcePartSchema.parse(cleanRecord({
255
269
  type: "source",
256
- content: [
257
- {
258
- type: "source-url",
259
- sourceId: typeof record.sourceId === "string" ? record.sourceId : "source-url",
260
- url: typeof record.url === "string" ? record.url : "",
261
- title: typeof record.title === "string" ? record.title : undefined,
262
- },
263
- ],
264
- metadata,
265
- },
270
+ content: {
271
+ sources: [
272
+ cleanRecord({
273
+ type: "source-url",
274
+ sourceId: typeof record.sourceId === "string" ? record.sourceId : "source-url",
275
+ url: typeof record.url === "string" ? record.url : "",
276
+ title: typeof record.title === "string" ? record.title : undefined,
277
+ }),
278
+ ],
279
+ },
280
+ reactorMetadata,
281
+ })),
266
282
  ];
267
283
  }
268
284
  if (record.type === "source-document") {
269
285
  return [
270
- {
286
+ contextSourcePartSchema.parse(cleanRecord({
271
287
  type: "source",
272
- content: [
273
- {
274
- type: "source-document",
275
- sourceId: typeof record.sourceId === "string"
276
- ? record.sourceId
277
- : "source-document",
278
- mediaType: typeof record.mediaType === "string"
279
- ? record.mediaType
280
- : "application/octet-stream",
281
- title: typeof record.title === "string" ? record.title : "Document",
282
- filename: typeof record.filename === "string" ? record.filename : undefined,
283
- },
284
- ],
285
- metadata,
286
- },
288
+ content: {
289
+ sources: [
290
+ cleanRecord({
291
+ type: "source-document",
292
+ sourceId: typeof record.sourceId === "string"
293
+ ? record.sourceId
294
+ : "source-document",
295
+ mediaType: typeof record.mediaType === "string"
296
+ ? record.mediaType
297
+ : "application/octet-stream",
298
+ title: typeof record.title === "string" ? record.title : "Document",
299
+ filename: typeof record.filename === "string" ? record.filename : undefined,
300
+ }),
301
+ ],
302
+ },
303
+ reactorMetadata,
304
+ })),
287
305
  ];
288
306
  }
289
307
  if (record.type.startsWith("data-")) {
290
- return [
291
- {
292
- type: "content",
293
- content: [
294
- {
295
- type: "json",
296
- value: record.data,
297
- },
298
- ],
299
- metadata: cleanRecord({
300
- ...(metadata ?? {}),
301
- app: {
302
- dataPartType: record.type.slice("data-".length),
303
- },
304
- }),
305
- },
306
- ];
308
+ return messageFromBlocks([{ type: "json", value: record.data }], reactorMetadata);
307
309
  }
308
310
  if (record.type.startsWith("tool-")) {
309
- const toolName = record.type.slice("tool-".length);
310
- const toolCallId = typeof record.toolCallId === "string" ? record.toolCallId : "";
311
- if (!toolName || !toolCallId) {
311
+ const actionName = record.type.slice("tool-".length);
312
+ const actionCallId = typeof record.toolCallId === "string" ? record.toolCallId : "";
313
+ if (!actionName || !actionCallId) {
312
314
  return [];
313
315
  }
314
- const callPart = {
315
- type: "tool-call",
316
- toolCallId,
317
- toolName,
318
- state: record.state === "input-streaming"
319
- ? "input-streaming"
320
- : "input-available",
321
- content: "input" in record && record.input !== undefined
322
- ? [{ type: "json", value: record.input }]
323
- : [],
324
- metadata,
325
- };
326
- if (record.state === "output-available" || record.state === "output-error") {
316
+ const startedPart = contextActionPartSchema.parse(cleanRecord({
317
+ type: "action",
318
+ content: cleanRecord({
319
+ status: "started",
320
+ actionName,
321
+ actionCallId,
322
+ input: "input" in record ? record.input : undefined,
323
+ }),
324
+ reactorMetadata,
325
+ }));
326
+ if (record.state === "output-available") {
327
327
  return [
328
- callPart,
329
- {
330
- type: "tool-result",
331
- toolCallId,
332
- toolName,
333
- state: record.state,
334
- content: record.state === "output-error"
335
- ? [
336
- {
337
- type: "text",
338
- text: typeof record.errorText === "string" && record.errorText.length > 0
339
- ? record.errorText
340
- : "Tool execution failed.",
341
- },
342
- ]
343
- : normalizeToolResultContentToBlocks(record.output),
344
- metadata,
345
- },
328
+ startedPart,
329
+ contextActionPartSchema.parse(cleanRecord({
330
+ type: "action",
331
+ content: {
332
+ status: "completed",
333
+ actionName,
334
+ actionCallId,
335
+ output: record.output,
336
+ },
337
+ reactorMetadata,
338
+ })),
339
+ ];
340
+ }
341
+ if (record.state === "output-error") {
342
+ return [
343
+ startedPart,
344
+ contextActionPartSchema.parse(cleanRecord({
345
+ type: "action",
346
+ content: {
347
+ status: "failed",
348
+ actionName,
349
+ actionCallId,
350
+ error: {
351
+ message: typeof record.errorText === "string" && record.errorText.length > 0
352
+ ? record.errorText
353
+ : "Action execution failed.",
354
+ },
355
+ },
356
+ reactorMetadata,
357
+ })),
346
358
  ];
347
359
  }
348
- return [callPart];
360
+ return [startedPart];
349
361
  }
350
362
  return [];
351
363
  }
352
364
  export function normalizePartsForPersistence(parts) {
353
- const normalized = parts.flatMap((part) => {
365
+ return parts.flatMap((part) => {
354
366
  if (isContextPartEnvelope(part)) {
355
367
  return [parseContextPartEnvelope(part)];
356
368
  }
357
369
  return normalizeUiPartToContextPartEnvelopes(part);
358
370
  });
359
- return normalized;
360
371
  }
@@ -1,7 +1,7 @@
1
1
  import type { ContextEnvironment } from "./context.config.js";
2
2
  import type { ContextInstance } from "./context.builder.js";
3
3
  export type ContextKey = string;
4
- type AnyContext = ContextInstance<any, any>;
4
+ type AnyContext = ContextInstance<any, any, any>;
5
5
  export type ContextFactory = () => AnyContext;
6
6
  export declare function registerContext(key: ContextKey, factory: ContextFactory): void;
7
7
  export declare function hasContext(key: ContextKey): boolean;
@@ -1,11 +1,17 @@
1
- import type { ConcreteDomain } from "@ekairos/domain";
2
- import type { ExplicitRuntimeLike } from "@ekairos/domain/runtime";
1
+ import type { ActiveDomain, ConcreteDomain, DomainSchemaResult } from "@ekairos/domain";
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";
5
- export type ContextRuntime<Env extends ContextEnvironment = ContextEnvironment> = ExplicitRuntimeLike<Env, any, any>;
5
+ import { eventsDomain } from "./schema.js";
6
+ export type ContextRuntime<Env extends ContextEnvironment = ContextEnvironment> = EkairosRuntime<Env, any, any>;
7
+ export type ContextRuntimeServiceHandle = Pick<ContextRuntime<any>, "db" | "resolve" | "meta">;
8
+ export type ContextRuntimeHandleForDomain<Env extends ContextEnvironment = ContextEnvironment, RequiredDomain extends DomainSchemaResult = typeof eventsDomain> = ContextRuntimeServiceHandle & {
9
+ use<Subdomain extends typeof eventsDomain | RequiredDomain>(subdomain: Subdomain, options?: RuntimeResolveOptions): Promise<Omit<ActiveDomain<Subdomain, Env>, "env">>;
10
+ };
11
+ export type ContextRuntimeForDomain<Runtime extends ContextRuntime<any>, RequiredDomain extends DomainSchemaResult = typeof eventsDomain> = RuntimeForDomain<Runtime, typeof eventsDomain> & RuntimeForDomain<Runtime, RequiredDomain>;
6
12
  export type ContextRuntimeServices = {
7
13
  db: any;
8
14
  store: ContextStore;
9
15
  domain?: ConcreteDomain<any, any>;
10
16
  };
11
- export declare function getContextRuntimeServices(runtime: ContextRuntime<any>): Promise<ContextRuntimeServices>;
17
+ export declare function getContextRuntimeServices(runtime: ContextRuntimeServiceHandle): Promise<ContextRuntimeServices>;
@@ -1,4 +1,7 @@
1
1
  const storeByDb = new WeakMap();
2
+ function asRecord(value) {
3
+ return value && typeof value === "object" ? value : {};
4
+ }
2
5
  export async function getContextRuntimeServices(runtime) {
3
6
  const db = await runtime.db();
4
7
  if (!db) {
@@ -13,9 +16,12 @@ export async function getContextRuntimeServices(runtime) {
13
16
  }
14
17
  }
15
18
  const resolved = await runtime.resolve();
19
+ const resolvedMeta = asRecord(resolved).meta;
20
+ const meta = typeof resolvedMeta === "function" ? resolvedMeta() : undefined;
21
+ const domain = asRecord(meta).domain;
16
22
  return {
17
23
  db,
18
24
  store,
19
- domain: typeof resolved === "object" && resolved !== null ? resolved.meta?.()?.domain : undefined,
25
+ domain: domain,
20
26
  };
21
27
  }
@@ -5,22 +5,36 @@ export type ContextStepStreamChunk = {
5
5
  at: string;
6
6
  sequence: number;
7
7
  chunkType: ContextStreamChunkType;
8
+ partId?: string;
9
+ providerPartId?: string;
10
+ partType?: string;
11
+ partSlot?: string;
8
12
  provider?: string;
9
13
  providerChunkType?: string;
10
14
  actionRef?: string;
11
15
  data?: unknown;
12
16
  raw?: unknown;
13
17
  };
18
+ export type ContextStepStreamChunkValidationOptions = {
19
+ stepId?: string;
20
+ label?: string;
21
+ };
14
22
  export declare function createContextStepStreamChunk(params: {
15
23
  at?: string;
16
24
  sequence: number;
17
25
  chunkType: ContextStreamChunkType;
26
+ stepId?: string;
27
+ partId?: string;
28
+ providerPartId?: string;
29
+ partType?: string;
30
+ partSlot?: string;
18
31
  provider?: string;
19
32
  providerChunkType?: string;
20
33
  actionRef?: string;
21
34
  data?: unknown;
22
35
  raw?: unknown;
23
36
  }): ContextStepStreamChunk;
24
- export declare function parseContextStepStreamChunk(value: string | unknown): ContextStepStreamChunk;
25
- export declare function encodeContextStepStreamChunk(chunk: ContextStepStreamChunk): string;
37
+ export declare function validateContextStepStreamChunk(value: unknown, options?: ContextStepStreamChunkValidationOptions): asserts value is ContextStepStreamChunk;
38
+ export declare function parseContextStepStreamChunk(value: string | unknown, options?: ContextStepStreamChunkValidationOptions): ContextStepStreamChunk;
39
+ export declare function encodeContextStepStreamChunk(chunk: ContextStepStreamChunk, options?: ContextStepStreamChunkValidationOptions): string;
26
40
  export declare function contextStreamByteLength(value: string): number;