@ekairos/events 1.22.4-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 (84) hide show
  1. package/README.md +115 -0
  2. package/dist/codex.d.ts +95 -0
  3. package/dist/codex.js +91 -0
  4. package/dist/context.builder.d.ts +62 -0
  5. package/dist/context.builder.js +143 -0
  6. package/dist/context.config.d.ts +9 -0
  7. package/dist/context.config.js +30 -0
  8. package/dist/context.contract.d.ts +47 -0
  9. package/dist/context.contract.js +132 -0
  10. package/dist/context.d.ts +4 -0
  11. package/dist/context.durable.d.ts +5 -0
  12. package/dist/context.durable.js +13 -0
  13. package/dist/context.engine.d.ts +216 -0
  14. package/dist/context.engine.js +1098 -0
  15. package/dist/context.events.d.ts +55 -0
  16. package/dist/context.events.js +431 -0
  17. package/dist/context.hooks.d.ts +21 -0
  18. package/dist/context.hooks.js +31 -0
  19. package/dist/context.js +3 -0
  20. package/dist/context.parts.d.ts +241 -0
  21. package/dist/context.parts.js +360 -0
  22. package/dist/context.reactor.d.ts +3 -0
  23. package/dist/context.reactor.js +2 -0
  24. package/dist/context.registry.d.ts +13 -0
  25. package/dist/context.registry.js +30 -0
  26. package/dist/context.skill.d.ts +9 -0
  27. package/dist/context.skill.js +1 -0
  28. package/dist/context.step-stream.d.ts +26 -0
  29. package/dist/context.step-stream.js +59 -0
  30. package/dist/context.store.d.ts +85 -0
  31. package/dist/context.store.js +1 -0
  32. package/dist/context.stream.d.ts +148 -0
  33. package/dist/context.stream.js +141 -0
  34. package/dist/context.toolcalls.d.ts +60 -0
  35. package/dist/context.toolcalls.js +117 -0
  36. package/dist/env.d.ts +3 -0
  37. package/dist/env.js +53 -0
  38. package/dist/index.d.ts +18 -0
  39. package/dist/index.js +11 -0
  40. package/dist/mcp.d.ts +1 -0
  41. package/dist/mcp.js +1 -0
  42. package/dist/mirror.d.ts +41 -0
  43. package/dist/mirror.js +1 -0
  44. package/dist/oidc.d.ts +7 -0
  45. package/dist/oidc.js +25 -0
  46. package/dist/polyfills/dom-events.d.ts +1 -0
  47. package/dist/polyfills/dom-events.js +89 -0
  48. package/dist/react.d.ts +42 -0
  49. package/dist/react.js +88 -0
  50. package/dist/reactors/ai-sdk.chunk-map.d.ts +12 -0
  51. package/dist/reactors/ai-sdk.chunk-map.js +143 -0
  52. package/dist/reactors/ai-sdk.reactor.d.ts +33 -0
  53. package/dist/reactors/ai-sdk.reactor.js +65 -0
  54. package/dist/reactors/ai-sdk.step.d.ts +48 -0
  55. package/dist/reactors/ai-sdk.step.js +343 -0
  56. package/dist/reactors/scripted.reactor.d.ts +17 -0
  57. package/dist/reactors/scripted.reactor.js +51 -0
  58. package/dist/reactors/types.d.ts +52 -0
  59. package/dist/reactors/types.js +1 -0
  60. package/dist/runtime.d.ts +19 -0
  61. package/dist/runtime.js +26 -0
  62. package/dist/runtime.step.d.ts +9 -0
  63. package/dist/runtime.step.js +7 -0
  64. package/dist/schema.d.ts +2 -0
  65. package/dist/schema.js +191 -0
  66. package/dist/steps/do-context-stream-step.d.ts +34 -0
  67. package/dist/steps/do-context-stream-step.js +96 -0
  68. package/dist/steps/mirror.steps.d.ts +6 -0
  69. package/dist/steps/mirror.steps.js +48 -0
  70. package/dist/steps/store.steps.d.ts +96 -0
  71. package/dist/steps/store.steps.js +595 -0
  72. package/dist/steps/stream.steps.d.ts +86 -0
  73. package/dist/steps/stream.steps.js +270 -0
  74. package/dist/steps/trace.steps.d.ts +38 -0
  75. package/dist/steps/trace.steps.js +270 -0
  76. package/dist/stores/instant.document-parser.d.ts +6 -0
  77. package/dist/stores/instant.document-parser.js +210 -0
  78. package/dist/stores/instant.documents.d.ts +16 -0
  79. package/dist/stores/instant.documents.js +152 -0
  80. package/dist/stores/instant.store.d.ts +66 -0
  81. package/dist/stores/instant.store.js +575 -0
  82. package/dist/tools-to-model-tools.d.ts +19 -0
  83. package/dist/tools-to-model-tools.js +21 -0
  84. package/package.json +142 -0
@@ -0,0 +1,241 @@
1
+ import { z } from "zod";
2
+ export declare const contextPartContentSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
3
+ type: z.ZodLiteral<"text">;
4
+ text: z.ZodString;
5
+ }, z.core.$strip>, z.ZodObject<{
6
+ type: z.ZodLiteral<"file">;
7
+ mediaType: z.ZodString;
8
+ filename: z.ZodOptional<z.ZodString>;
9
+ data: z.ZodOptional<z.ZodString>;
10
+ url: z.ZodOptional<z.ZodString>;
11
+ fileId: z.ZodOptional<z.ZodString>;
12
+ }, z.core.$strip>, z.ZodObject<{
13
+ type: z.ZodLiteral<"json">;
14
+ value: z.ZodUnknown;
15
+ }, z.core.$strip>, z.ZodObject<{
16
+ type: z.ZodLiteral<"source-url">;
17
+ sourceId: z.ZodString;
18
+ url: z.ZodString;
19
+ title: z.ZodOptional<z.ZodString>;
20
+ }, z.core.$strip>, z.ZodObject<{
21
+ type: z.ZodLiteral<"source-document">;
22
+ sourceId: z.ZodString;
23
+ mediaType: z.ZodString;
24
+ title: z.ZodString;
25
+ filename: z.ZodOptional<z.ZodString>;
26
+ }, z.core.$strip>], "type">;
27
+ declare const contextInlineContentSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
28
+ type: z.ZodLiteral<"text">;
29
+ text: z.ZodString;
30
+ }, z.core.$strip>, z.ZodObject<{
31
+ type: z.ZodLiteral<"file">;
32
+ mediaType: z.ZodString;
33
+ filename: z.ZodOptional<z.ZodString>;
34
+ data: z.ZodOptional<z.ZodString>;
35
+ url: z.ZodOptional<z.ZodString>;
36
+ fileId: z.ZodOptional<z.ZodString>;
37
+ }, z.core.$strip>, z.ZodObject<{
38
+ type: z.ZodLiteral<"json">;
39
+ value: z.ZodUnknown;
40
+ }, z.core.$strip>], "type">;
41
+ export declare const contextPartSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
42
+ type: z.ZodLiteral<"content">;
43
+ content: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
44
+ type: z.ZodLiteral<"text">;
45
+ text: z.ZodString;
46
+ }, z.core.$strip>, z.ZodObject<{
47
+ type: z.ZodLiteral<"file">;
48
+ mediaType: z.ZodString;
49
+ filename: z.ZodOptional<z.ZodString>;
50
+ data: z.ZodOptional<z.ZodString>;
51
+ url: z.ZodOptional<z.ZodString>;
52
+ fileId: z.ZodOptional<z.ZodString>;
53
+ }, z.core.$strip>, z.ZodObject<{
54
+ type: z.ZodLiteral<"json">;
55
+ value: z.ZodUnknown;
56
+ }, z.core.$strip>], "type">>;
57
+ state: z.ZodOptional<z.ZodEnum<{
58
+ streaming: "streaming";
59
+ done: "done";
60
+ }>>;
61
+ }, z.core.$strip>, z.ZodObject<{
62
+ type: z.ZodLiteral<"reasoning">;
63
+ content: z.ZodArray<z.ZodObject<{
64
+ type: z.ZodLiteral<"text">;
65
+ text: z.ZodString;
66
+ }, z.core.$strip>>;
67
+ state: z.ZodOptional<z.ZodEnum<{
68
+ streaming: "streaming";
69
+ done: "done";
70
+ }>>;
71
+ }, z.core.$strip>, z.ZodObject<{
72
+ type: z.ZodLiteral<"source">;
73
+ content: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
74
+ type: z.ZodLiteral<"source-url">;
75
+ sourceId: z.ZodString;
76
+ url: z.ZodString;
77
+ title: z.ZodOptional<z.ZodString>;
78
+ }, z.core.$strip>, z.ZodObject<{
79
+ type: z.ZodLiteral<"source-document">;
80
+ sourceId: z.ZodString;
81
+ mediaType: z.ZodString;
82
+ title: z.ZodString;
83
+ filename: z.ZodOptional<z.ZodString>;
84
+ }, z.core.$strip>], "type">>;
85
+ }, z.core.$strip>, z.ZodObject<{
86
+ type: z.ZodLiteral<"tool-call">;
87
+ toolCallId: z.ZodString;
88
+ toolName: z.ZodString;
89
+ content: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
90
+ type: z.ZodLiteral<"text">;
91
+ text: z.ZodString;
92
+ }, z.core.$strip>, z.ZodObject<{
93
+ type: z.ZodLiteral<"file">;
94
+ mediaType: z.ZodString;
95
+ filename: z.ZodOptional<z.ZodString>;
96
+ data: z.ZodOptional<z.ZodString>;
97
+ url: z.ZodOptional<z.ZodString>;
98
+ fileId: z.ZodOptional<z.ZodString>;
99
+ }, z.core.$strip>, z.ZodObject<{
100
+ type: z.ZodLiteral<"json">;
101
+ value: z.ZodUnknown;
102
+ }, z.core.$strip>], "type">>;
103
+ state: z.ZodOptional<z.ZodEnum<{
104
+ "input-streaming": "input-streaming";
105
+ "input-available": "input-available";
106
+ }>>;
107
+ }, z.core.$strip>, z.ZodObject<{
108
+ type: z.ZodLiteral<"tool-result">;
109
+ toolCallId: z.ZodString;
110
+ toolName: z.ZodString;
111
+ content: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
112
+ type: z.ZodLiteral<"text">;
113
+ text: z.ZodString;
114
+ }, z.core.$strip>, z.ZodObject<{
115
+ type: z.ZodLiteral<"file">;
116
+ mediaType: z.ZodString;
117
+ filename: z.ZodOptional<z.ZodString>;
118
+ data: z.ZodOptional<z.ZodString>;
119
+ url: z.ZodOptional<z.ZodString>;
120
+ fileId: z.ZodOptional<z.ZodString>;
121
+ }, z.core.$strip>, z.ZodObject<{
122
+ type: z.ZodLiteral<"json">;
123
+ value: z.ZodUnknown;
124
+ }, z.core.$strip>], "type">>;
125
+ state: z.ZodOptional<z.ZodEnum<{
126
+ "output-available": "output-available";
127
+ "output-error": "output-error";
128
+ }>>;
129
+ }, z.core.$strip>], "type">;
130
+ export declare const contextPartEnvelopeSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
131
+ type: z.ZodLiteral<"content">;
132
+ content: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
133
+ type: z.ZodLiteral<"text">;
134
+ text: z.ZodString;
135
+ }, z.core.$strip>, z.ZodObject<{
136
+ type: z.ZodLiteral<"file">;
137
+ mediaType: z.ZodString;
138
+ filename: z.ZodOptional<z.ZodString>;
139
+ data: z.ZodOptional<z.ZodString>;
140
+ url: z.ZodOptional<z.ZodString>;
141
+ fileId: z.ZodOptional<z.ZodString>;
142
+ }, z.core.$strip>, z.ZodObject<{
143
+ type: z.ZodLiteral<"json">;
144
+ value: z.ZodUnknown;
145
+ }, z.core.$strip>], "type">>;
146
+ state: z.ZodOptional<z.ZodEnum<{
147
+ streaming: "streaming";
148
+ done: "done";
149
+ }>>;
150
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
151
+ }, z.core.$strip>, z.ZodObject<{
152
+ type: z.ZodLiteral<"reasoning">;
153
+ content: z.ZodArray<z.ZodObject<{
154
+ type: z.ZodLiteral<"text">;
155
+ text: z.ZodString;
156
+ }, z.core.$strip>>;
157
+ state: z.ZodOptional<z.ZodEnum<{
158
+ streaming: "streaming";
159
+ done: "done";
160
+ }>>;
161
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
162
+ }, z.core.$strip>, z.ZodObject<{
163
+ type: z.ZodLiteral<"source">;
164
+ content: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
165
+ type: z.ZodLiteral<"source-url">;
166
+ sourceId: z.ZodString;
167
+ url: z.ZodString;
168
+ title: z.ZodOptional<z.ZodString>;
169
+ }, z.core.$strip>, z.ZodObject<{
170
+ type: z.ZodLiteral<"source-document">;
171
+ sourceId: z.ZodString;
172
+ mediaType: z.ZodString;
173
+ title: z.ZodString;
174
+ filename: z.ZodOptional<z.ZodString>;
175
+ }, z.core.$strip>], "type">>;
176
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
177
+ }, z.core.$strip>, z.ZodObject<{
178
+ type: z.ZodLiteral<"tool-call">;
179
+ toolCallId: z.ZodString;
180
+ toolName: z.ZodString;
181
+ content: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
182
+ type: z.ZodLiteral<"text">;
183
+ text: z.ZodString;
184
+ }, z.core.$strip>, z.ZodObject<{
185
+ type: z.ZodLiteral<"file">;
186
+ mediaType: z.ZodString;
187
+ filename: z.ZodOptional<z.ZodString>;
188
+ data: z.ZodOptional<z.ZodString>;
189
+ url: z.ZodOptional<z.ZodString>;
190
+ fileId: z.ZodOptional<z.ZodString>;
191
+ }, z.core.$strip>, z.ZodObject<{
192
+ type: z.ZodLiteral<"json">;
193
+ value: z.ZodUnknown;
194
+ }, z.core.$strip>], "type">>;
195
+ state: z.ZodOptional<z.ZodEnum<{
196
+ "input-streaming": "input-streaming";
197
+ "input-available": "input-available";
198
+ }>>;
199
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
200
+ }, z.core.$strip>, z.ZodObject<{
201
+ type: z.ZodLiteral<"tool-result">;
202
+ toolCallId: z.ZodString;
203
+ toolName: z.ZodString;
204
+ content: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
205
+ type: z.ZodLiteral<"text">;
206
+ text: z.ZodString;
207
+ }, z.core.$strip>, z.ZodObject<{
208
+ type: z.ZodLiteral<"file">;
209
+ mediaType: z.ZodString;
210
+ filename: z.ZodOptional<z.ZodString>;
211
+ data: z.ZodOptional<z.ZodString>;
212
+ url: z.ZodOptional<z.ZodString>;
213
+ fileId: z.ZodOptional<z.ZodString>;
214
+ }, z.core.$strip>, z.ZodObject<{
215
+ type: z.ZodLiteral<"json">;
216
+ value: z.ZodUnknown;
217
+ }, z.core.$strip>], "type">>;
218
+ state: z.ZodOptional<z.ZodEnum<{
219
+ "output-available": "output-available";
220
+ "output-error": "output-error";
221
+ }>>;
222
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
223
+ }, z.core.$strip>], "type">;
224
+ export type ContextPartContent = z.infer<typeof contextPartContentSchema>;
225
+ export type ContextInlineContent = z.infer<typeof contextInlineContentSchema>;
226
+ export type ContextPart = z.infer<typeof contextPartSchema>;
227
+ export type ContextPartEnvelope = z.infer<typeof contextPartEnvelopeSchema>;
228
+ export declare function isContextPartEnvelope(value: unknown): value is ContextPartEnvelope;
229
+ export declare function parseContextPartEnvelope(value: unknown): ContextPartEnvelope;
230
+ export declare function splitContextPartEnvelope(value: ContextPartEnvelope): {
231
+ part: ContextPart;
232
+ metadata?: Record<string, unknown>;
233
+ };
234
+ export declare function mergeContextPartEnvelope(params: {
235
+ part: unknown;
236
+ metadata?: unknown;
237
+ }): ContextPartEnvelope;
238
+ export declare function normalizeToolResultContentToBlocks(value: unknown): ContextInlineContent[];
239
+ export declare function normalizeUiPartToContextPartEnvelopes(value: unknown): ContextPartEnvelope[];
240
+ export declare function normalizePartsForPersistence(parts: unknown[]): ContextPartEnvelope[];
241
+ export {};
@@ -0,0 +1,360 @@
1
+ import { z } from "zod";
2
+ const metadataSchema = z.record(z.string(), z.unknown()).optional();
3
+ const textContentSchema = z.object({
4
+ type: z.literal("text"),
5
+ text: z.string(),
6
+ });
7
+ const fileContentSchema = z
8
+ .object({
9
+ type: z.literal("file"),
10
+ mediaType: z.string().min(1),
11
+ filename: z.string().optional(),
12
+ data: z.string().optional(),
13
+ url: z.string().optional(),
14
+ fileId: z.string().optional(),
15
+ })
16
+ .superRefine((value, ctx) => {
17
+ if (!value.data && !value.url && !value.fileId) {
18
+ ctx.addIssue({
19
+ code: z.ZodIssueCode.custom,
20
+ message: "file content requires one of data, url, or fileId",
21
+ });
22
+ }
23
+ });
24
+ const jsonContentSchema = z.object({
25
+ type: z.literal("json"),
26
+ value: z.unknown(),
27
+ });
28
+ const sourceUrlContentSchema = z.object({
29
+ type: z.literal("source-url"),
30
+ sourceId: z.string(),
31
+ url: z.string().min(1),
32
+ title: z.string().optional(),
33
+ });
34
+ const sourceDocumentContentSchema = z.object({
35
+ type: z.literal("source-document"),
36
+ sourceId: z.string(),
37
+ mediaType: z.string().min(1),
38
+ title: z.string().min(1),
39
+ filename: z.string().optional(),
40
+ });
41
+ export const contextPartContentSchema = z.discriminatedUnion("type", [
42
+ textContentSchema,
43
+ fileContentSchema,
44
+ jsonContentSchema,
45
+ sourceUrlContentSchema,
46
+ sourceDocumentContentSchema,
47
+ ]);
48
+ const contextInlineContentSchema = z.discriminatedUnion("type", [
49
+ textContentSchema,
50
+ fileContentSchema,
51
+ jsonContentSchema,
52
+ ]);
53
+ const contextContentPartSchema = z.object({
54
+ type: z.literal("content"),
55
+ content: z.array(contextInlineContentSchema),
56
+ state: z.enum(["streaming", "done"]).optional(),
57
+ });
58
+ const contextReasoningPartSchema = z.object({
59
+ type: z.literal("reasoning"),
60
+ content: z.array(textContentSchema),
61
+ state: z.enum(["streaming", "done"]).optional(),
62
+ });
63
+ const contextSourcePartSchema = z.object({
64
+ type: z.literal("source"),
65
+ content: z.array(z.discriminatedUnion("type", [sourceUrlContentSchema, sourceDocumentContentSchema])),
66
+ });
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(),
73
+ });
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(),
80
+ });
81
+ export const contextPartSchema = z.discriminatedUnion("type", [
82
+ contextContentPartSchema,
83
+ contextReasoningPartSchema,
84
+ contextSourcePartSchema,
85
+ contextToolCallPartSchema,
86
+ contextToolResultPartSchema,
87
+ ]);
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
+ }),
104
+ ]);
105
+ function asRecord(value) {
106
+ if (!value || typeof value !== "object")
107
+ return null;
108
+ return value;
109
+ }
110
+ function cleanRecord(value) {
111
+ return Object.fromEntries(Object.entries(value).filter(([, item]) => item !== undefined));
112
+ }
113
+ function normalizeMetadata(value) {
114
+ if (!value || typeof value !== "object")
115
+ return undefined;
116
+ return value;
117
+ }
118
+ export function isContextPartEnvelope(value) {
119
+ return contextPartEnvelopeSchema.safeParse(value).success;
120
+ }
121
+ export function parseContextPartEnvelope(value) {
122
+ return contextPartEnvelopeSchema.parse(value);
123
+ }
124
+ export function splitContextPartEnvelope(value) {
125
+ const { metadata, ...part } = value;
126
+ return {
127
+ part,
128
+ metadata,
129
+ };
130
+ }
131
+ export function mergeContextPartEnvelope(params) {
132
+ return parseContextPartEnvelope({
133
+ ...(asRecord(params.part) ?? {}),
134
+ metadata: normalizeMetadata(params.metadata),
135
+ });
136
+ }
137
+ function normalizeFileContentBlock(value) {
138
+ return contextInlineContentSchema.parse(cleanRecord({
139
+ type: "file",
140
+ mediaType: typeof value.mediaType === "string" ? value.mediaType : "application/octet-stream",
141
+ filename: typeof value.filename === "string" ? value.filename : undefined,
142
+ data: typeof value.data === "string" ? value.data : undefined,
143
+ url: typeof value.url === "string" ? value.url : undefined,
144
+ fileId: typeof value.fileId === "string" ? value.fileId : undefined,
145
+ }));
146
+ }
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 }];
198
+ }
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;
205
+ }
206
+ export function normalizeUiPartToContextPartEnvelopes(value) {
207
+ const record = asRecord(value);
208
+ if (!record || typeof record.type !== "string") {
209
+ return [];
210
+ }
211
+ const metadata = metadataFromUiPart(record);
212
+ 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
+ ];
221
+ }
222
+ if (record.type === "reasoning" && typeof record.text === "string") {
223
+ return [
224
+ {
225
+ type: "reasoning",
226
+ content: [{ type: "text", text: record.text }],
227
+ state: record.state === "streaming" ? "streaming" : "done",
228
+ metadata,
229
+ },
230
+ ];
231
+ }
232
+ 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
+ ];
251
+ }
252
+ if (record.type === "source-url") {
253
+ return [
254
+ {
255
+ 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
+ },
266
+ ];
267
+ }
268
+ if (record.type === "source-document") {
269
+ return [
270
+ {
271
+ 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
+ },
287
+ ];
288
+ }
289
+ 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
+ ];
307
+ }
308
+ 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) {
312
+ return [];
313
+ }
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") {
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
+ },
346
+ ];
347
+ }
348
+ return [callPart];
349
+ }
350
+ return [];
351
+ }
352
+ export function normalizePartsForPersistence(parts) {
353
+ const normalized = parts.flatMap((part) => {
354
+ if (isContextPartEnvelope(part)) {
355
+ return [parseContextPartEnvelope(part)];
356
+ }
357
+ return normalizeUiPartToContextPartEnvelopes(part);
358
+ });
359
+ return normalized;
360
+ }
@@ -0,0 +1,3 @@
1
+ export { createAiSdkReactor, type CreateAiSdkReactorOptions, } from "./reactors/ai-sdk.reactor.js";
2
+ export { createScriptedReactor, type CreateScriptedReactorOptions, type ScriptedReactorStep, } from "./reactors/scripted.reactor.js";
3
+ export type { ContextReactor, ContextReactorParams, ContextReactionResult, ContextActionRequest, ContextReactionLLM, } from "./reactors/types.js";
@@ -0,0 +1,2 @@
1
+ export { createAiSdkReactor, } from "./reactors/ai-sdk.reactor.js";
2
+ export { createScriptedReactor, } from "./reactors/scripted.reactor.js";
@@ -0,0 +1,13 @@
1
+ import type { ContextEnvironment } from "./context.config.js";
2
+ import type { ContextInstance } from "./context.builder.js";
3
+ export type ContextKey = string;
4
+ type AnyContext = ContextInstance<any, any>;
5
+ export type ContextFactory = () => AnyContext;
6
+ export declare function registerContext(key: ContextKey, factory: ContextFactory): void;
7
+ export declare function hasContext(key: ContextKey): boolean;
8
+ export declare function getContext<Env extends ContextEnvironment = ContextEnvironment>(key: ContextKey): AnyContext & {
9
+ __config: {};
10
+ };
11
+ export declare function getContextFactory(key: ContextKey): ContextFactory;
12
+ export declare function listContexts(): string[];
13
+ export {};
@@ -0,0 +1,30 @@
1
+ const registry = new Map();
2
+ export function registerContext(key, factory) {
3
+ if (!key || typeof key !== "string") {
4
+ throw new Error("registerContext: key must be a non-empty string");
5
+ }
6
+ if (typeof factory !== "function") {
7
+ throw new Error("registerContext: factory must be a function");
8
+ }
9
+ registry.set(key, factory);
10
+ }
11
+ export function hasContext(key) {
12
+ return registry.has(key);
13
+ }
14
+ export function getContext(key) {
15
+ const factory = registry.get(key);
16
+ if (!factory) {
17
+ throw new Error(`Context "${key}" is not registered. Ensure the module that calls createContext("${key}") is imported during boot.`);
18
+ }
19
+ return factory();
20
+ }
21
+ export function getContextFactory(key) {
22
+ const factory = registry.get(key);
23
+ if (!factory) {
24
+ throw new Error(`Context "${key}" is not registered. Ensure the module that calls createContext("${key}") is imported during boot.`);
25
+ }
26
+ return factory;
27
+ }
28
+ export function listContexts() {
29
+ return Array.from(registry.keys());
30
+ }
@@ -0,0 +1,9 @@
1
+ export type ContextSkillPackageFile = {
2
+ path: string;
3
+ contentBase64: string;
4
+ };
5
+ export type ContextSkillPackage = {
6
+ name: string;
7
+ description?: string;
8
+ files: ContextSkillPackageFile[];
9
+ };
@@ -0,0 +1 @@
1
+ export {};