@ekairos/structure 1.22.28-beta.feature-events-package-refactor.0 → 1.22.30-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.
@@ -1,4 +1,4 @@
1
- declare const STRUCTURE_CONTEXT_ENTITIES: readonly ["event_contexts", "thread_contexts"];
1
+ declare const STRUCTURE_CONTEXT_ENTITIES: readonly ["event_contexts"];
2
2
  type StructureContextEntity = (typeof STRUCTURE_CONTEXT_ENTITIES)[number];
3
3
  type FindStructureContextParams = {
4
4
  includeOutputFile?: boolean;
@@ -15,7 +15,7 @@ export declare function createStructureContext(db: any, params: {
15
15
  status?: string;
16
16
  createdAt?: Date;
17
17
  }): Promise<{
18
- entity: "event_contexts" | "thread_contexts";
18
+ entity: "event_contexts";
19
19
  id: string;
20
20
  }>;
21
21
  export declare function linkStructureOutputFileToContextByKey(db: any, params: {
@@ -1,4 +1,4 @@
1
- const STRUCTURE_CONTEXT_ENTITIES = ["event_contexts", "thread_contexts"];
1
+ const STRUCTURE_CONTEXT_ENTITIES = ["event_contexts"];
2
2
  function buildContextQuery(entity, key, includeOutputFile) {
3
3
  return {
4
4
  [entity]: {
@@ -10,8 +10,6 @@ function buildContextQuery(entity, key, includeOutputFile) {
10
10
  function preferredContextEntity(db) {
11
11
  if (db?.tx?.event_contexts)
12
12
  return "event_contexts";
13
- if (db?.tx?.thread_contexts)
14
- return "thread_contexts";
15
13
  throw new Error("No persisted context collection is available");
16
14
  }
17
15
  export async function findStructureContextByKey(db, key, params = {}) {
@@ -2,8 +2,8 @@ import { findStructureContextByKey, linkStructureOutputFileToContextByKey, unlin
2
2
  export async function structureGetOrCreateContextStep(params) {
3
3
  "use step";
4
4
  try {
5
- const { getThreadRuntime } = await import("@ekairos/events/runtime");
6
- const runtime = await getThreadRuntime(params.env);
5
+ const { getContextRuntime } = await import("@ekairos/events/runtime");
6
+ const runtime = await getContextRuntime(params.env);
7
7
  const ctx = await runtime.store.getOrCreateContext({ key: params.contextKey });
8
8
  return { ok: true, data: ctx };
9
9
  }
@@ -15,8 +15,8 @@ export async function structureGetOrCreateContextStep(params) {
15
15
  export async function structureGetContextStep(params) {
16
16
  "use step";
17
17
  try {
18
- const { getThreadRuntime } = await import("@ekairos/events/runtime");
19
- const runtime = await getThreadRuntime(params.env);
18
+ const { getContextRuntime } = await import("@ekairos/events/runtime");
19
+ const runtime = await getContextRuntime(params.env);
20
20
  const ctx = await runtime.store.getContext({ key: params.contextKey });
21
21
  if (!ctx)
22
22
  return { ok: false, error: "Context not found" };
@@ -30,8 +30,8 @@ export async function structureGetContextStep(params) {
30
30
  export async function structureUpdateContextContentStep(params) {
31
31
  "use step";
32
32
  try {
33
- const { getThreadRuntime } = await import("@ekairos/events/runtime");
34
- const runtime = await getThreadRuntime(params.env);
33
+ const { getContextRuntime } = await import("@ekairos/events/runtime");
34
+ const runtime = await getContextRuntime(params.env);
35
35
  const updated = await runtime.store.updateContextContent({ key: params.contextKey }, params.content);
36
36
  return { ok: true, data: updated };
37
37
  }
@@ -43,8 +43,8 @@ export async function structureUpdateContextContentStep(params) {
43
43
  export async function structurePatchContextContentStep(params) {
44
44
  "use step";
45
45
  try {
46
- const { getThreadRuntime } = await import("@ekairos/events/runtime");
47
- const runtime = await getThreadRuntime(params.env);
46
+ const { getContextRuntime } = await import("@ekairos/events/runtime");
47
+ const runtime = await getContextRuntime(params.env);
48
48
  const existing = await runtime.store.getOrCreateContext({ key: params.contextKey });
49
49
  const existingContent = (existing?.content ?? {});
50
50
  const existingStructure = (existingContent?.structure ?? {});
@@ -66,8 +66,8 @@ export async function structureUploadRowsOutputJsonlStep(params) {
66
66
  "use step";
67
67
  const startedAt = Date.now();
68
68
  try {
69
- const { getThreadRuntime } = await import("@ekairos/events/runtime");
70
- const runtime = await getThreadRuntime(params.env);
69
+ const { getContextRuntime } = await import("@ekairos/events/runtime");
70
+ const runtime = await getContextRuntime(params.env);
71
71
  const db = runtime.db;
72
72
  const storagePath = `/structure/${params.structureId}/output.jsonl`;
73
73
  const fileBuffer = Buffer.from(params.contentBase64 ?? "", "base64");
@@ -90,8 +90,8 @@ export async function structureLinkRowsOutputFileToContextStep(params) {
90
90
  "use step";
91
91
  const startedAt = Date.now();
92
92
  try {
93
- const { getThreadRuntime } = await import("@ekairos/events/runtime");
94
- const runtime = await getThreadRuntime(params.env);
93
+ const { getContextRuntime } = await import("@ekairos/events/runtime");
94
+ const runtime = await getContextRuntime(params.env);
95
95
  const store = runtime.store;
96
96
  const db = runtime.db;
97
97
  await store.getOrCreateContext({ key: params.contextKey });
@@ -107,8 +107,8 @@ export async function structureLinkRowsOutputFileToContextStep(params) {
107
107
  export async function structureUnlinkRowsOutputFileFromContextStep(params) {
108
108
  "use step";
109
109
  try {
110
- const { getThreadRuntime } = await import("@ekairos/events/runtime");
111
- const runtime = await getThreadRuntime(params.env);
110
+ const { getContextRuntime } = await import("@ekairos/events/runtime");
111
+ const runtime = await getContextRuntime(params.env);
112
112
  const store = runtime.store;
113
113
  const db = runtime.db;
114
114
  await store.getOrCreateContext({ key: params.contextKey });
@@ -123,8 +123,8 @@ export async function structureUnlinkRowsOutputFileFromContextStep(params) {
123
123
  export async function structureGetContextWithRowsOutputFileStep(params) {
124
124
  "use step";
125
125
  try {
126
- const { getThreadRuntime } = await import("@ekairos/events/runtime");
127
- const runtime = await getThreadRuntime(params.env);
126
+ const { getContextRuntime } = await import("@ekairos/events/runtime");
127
+ const runtime = await getContextRuntime(params.env);
128
128
  const db = runtime.db;
129
129
  const persisted = await findStructureContextByKey(db, params.contextKey, { includeOutputFile: true });
130
130
  const row = persisted?.row;
@@ -142,8 +142,8 @@ export async function structureReadRowsOutputJsonlStep(params) {
142
142
  const startedAt = Date.now();
143
143
  try {
144
144
  const contextKey = `structure:${params.structureId}`;
145
- const { getThreadRuntime } = await import("@ekairos/events/runtime");
146
- const runtime = await getThreadRuntime(params.env);
145
+ const { getContextRuntime } = await import("@ekairos/events/runtime");
146
+ const runtime = await getContextRuntime(params.env);
147
147
  const db = runtime.db;
148
148
  const persisted = await findStructureContextByKey(db, contextKey, { includeOutputFile: true });
149
149
  const ctx = persisted?.row;
@@ -1,7 +1,7 @@
1
1
  export async function readInstantFileStep(params) {
2
2
  "use step";
3
- const { getThreadRuntime } = await import("@ekairos/events/runtime");
4
- const runtime = (await getThreadRuntime(params.env));
3
+ const { getContextRuntime } = await import("@ekairos/events/runtime");
4
+ const runtime = (await getContextRuntime(params.env));
5
5
  const db = runtime.db;
6
6
  const { DatasetService } = await import("../service.js");
7
7
  const service = new DatasetService(db);
@@ -1,7 +1,7 @@
1
1
  import { getDatasetOutputPath, getDatasetWorkstation } from "./datasetFiles.js";
2
2
  import { createDatasetSandboxStep, runDatasetSandboxCommandStep } from "./sandbox/steps.js";
3
3
  import { findStructureContextByKey } from "./contextPersistence.js";
4
- import { getThreadRuntime } from "./runtime.js";
4
+ import { getContextRuntime } from "./runtime.js";
5
5
  /**
6
6
  * Step 1/2:
7
7
  * Download the rows output.jsonl from Instant storage into a sandbox file.
@@ -38,7 +38,7 @@ export async function structureDownloadRowsOutputToSandboxStep(params) {
38
38
  if (exists.exitCode === 0) {
39
39
  return { sandboxId, localPath };
40
40
  }
41
- const storyRuntime = await getThreadRuntime(params.env);
41
+ const storyRuntime = await getContextRuntime(params.env);
42
42
  const db = storyRuntime.db;
43
43
  const contextKey = `structure:${params.structureId}`;
44
44
  const persisted = await findStructureContextByKey(db, contextKey, { includeOutputFile: true });
@@ -1,7 +1,7 @@
1
1
  import { getDatasetOutputPath, getDatasetWorkstation } from "./datasetFiles.js";
2
2
  import { readDatasetSandboxFileStep, runDatasetSandboxCommandStep } from "./sandbox/steps.js";
3
3
  import { linkStructureOutputFileToContextByKey } from "./contextPersistence.js";
4
- import { getThreadRuntime } from "./runtime.js";
4
+ import { getContextRuntime } from "./runtime.js";
5
5
  /**
6
6
  * Step:
7
7
  * Split a sandbox-local `output.jsonl` into a child dataset (also `output.jsonl`) of up to `limit` ROW entries.
@@ -85,7 +85,7 @@ export async function structureSplitRowsOutputToDatasetStep(params) {
85
85
  sandboxId: params.sandboxId,
86
86
  path: outPath,
87
87
  });
88
- const storyRuntime = await getThreadRuntime(params.env);
88
+ const storyRuntime = await getContextRuntime(params.env);
89
89
  const db = storyRuntime.db;
90
90
  const store = storyRuntime.store;
91
91
  const storagePath = `/structure/${params.childDatasetId}/output.jsonl`;
package/dist/runtime.d.ts CHANGED
@@ -3,7 +3,7 @@
3
3
  *
4
4
  * Why dynamic import?
5
5
  * - Some bundlers (notably Turbopack step bundles) can drop/hoist static imports in "use-step" modules,
6
- * causing `ReferenceError: getThreadRuntime is not defined`.
6
+ * causing `ReferenceError: getContextRuntime is not defined`.
7
7
  * - Using a dynamic import keeps the symbol resolution local to the step runtime.
8
8
  */
9
- export declare function getThreadRuntime(env: any): Promise<import("@ekairos/events/runtime").ThreadRuntime>;
9
+ export declare function getContextRuntime(env: any): Promise<import("@ekairos/events/runtime").ContextRuntime>;
package/dist/runtime.js CHANGED
@@ -3,10 +3,10 @@
3
3
  *
4
4
  * Why dynamic import?
5
5
  * - Some bundlers (notably Turbopack step bundles) can drop/hoist static imports in "use-step" modules,
6
- * causing `ReferenceError: getThreadRuntime is not defined`.
6
+ * causing `ReferenceError: getContextRuntime is not defined`.
7
7
  * - Using a dynamic import keeps the symbol resolution local to the step runtime.
8
8
  */
9
- export async function getThreadRuntime(env) {
10
- const { getThreadRuntime } = await import("@ekairos/events/runtime");
11
- return await getThreadRuntime(env);
9
+ export async function getContextRuntime(env) {
10
+ const { getContextRuntime } = await import("@ekairos/events/runtime");
11
+ return await getContextRuntime(env);
12
12
  }
@@ -104,8 +104,8 @@ export async function createDatasetSandboxStep(params) {
104
104
  "use step";
105
105
  const startedAt = Date.now();
106
106
  const { env, ...configInput } = params;
107
- const { getThreadRuntime } = await import("@ekairos/events/runtime");
108
- const db = (await getThreadRuntime(env)).db;
107
+ const { getContextRuntime } = await import("@ekairos/events/runtime");
108
+ const db = (await getContextRuntime(env)).db;
109
109
  const { SandboxService } = (await import("@ekairos/sandbox"));
110
110
  const service = new SandboxService(db);
111
111
  const daytonaDefaults = getStructureDaytonaDefaults();
@@ -181,8 +181,8 @@ export async function createDatasetSandboxStep(params) {
181
181
  export async function runDatasetSandboxCommandStep(params) {
182
182
  "use step";
183
183
  const startedAt = Date.now();
184
- const { getThreadRuntime } = await import("@ekairos/events/runtime");
185
- const db = (await getThreadRuntime(params.env)).db;
184
+ const { getContextRuntime } = await import("@ekairos/events/runtime");
185
+ const db = (await getContextRuntime(params.env)).db;
186
186
  const { SandboxService } = (await import("@ekairos/sandbox"));
187
187
  const service = new SandboxService(db);
188
188
  const result = await service.runCommand(params.sandboxId, params.cmd, params.args ?? []);
@@ -202,8 +202,8 @@ export async function runDatasetSandboxCommandStep(params) {
202
202
  export async function writeDatasetSandboxFilesStep(params) {
203
203
  "use step";
204
204
  const startedAt = Date.now();
205
- const { getThreadRuntime } = await import("@ekairos/events/runtime");
206
- const db = (await getThreadRuntime(params.env)).db;
205
+ const { getContextRuntime } = await import("@ekairos/events/runtime");
206
+ const db = (await getContextRuntime(params.env)).db;
207
207
  const { SandboxService } = (await import("@ekairos/sandbox"));
208
208
  const service = new SandboxService(db);
209
209
  const result = await service.writeFiles(params.sandboxId, params.files);
@@ -233,8 +233,8 @@ export async function writeDatasetSandboxTextFileStep(params) {
233
233
  export async function readDatasetSandboxFileStep(params) {
234
234
  "use step";
235
235
  const startedAt = Date.now();
236
- const { getThreadRuntime } = await import("@ekairos/events/runtime");
237
- const db = (await getThreadRuntime(params.env)).db;
236
+ const { getContextRuntime } = await import("@ekairos/events/runtime");
237
+ const db = (await getContextRuntime(params.env)).db;
238
238
  const { SandboxService } = (await import("@ekairos/sandbox"));
239
239
  const service = new SandboxService(db);
240
240
  const result = await service.readFile(params.sandboxId, params.path);
@@ -262,8 +262,8 @@ export async function readDatasetSandboxTextFileStep(params) {
262
262
  export async function stopDatasetSandboxStep(params) {
263
263
  "use step";
264
264
  const startedAt = Date.now();
265
- const { getThreadRuntime } = await import("@ekairos/events/runtime");
266
- const db = (await getThreadRuntime(params.env)).db;
265
+ const { getContextRuntime } = await import("@ekairos/events/runtime");
266
+ const db = (await getContextRuntime(params.env)).db;
267
267
  const { SandboxService } = (await import("@ekairos/sandbox"));
268
268
  const service = new SandboxService(db);
269
269
  const result = await service.stopSandbox(params.sandboxId);
package/dist/schema.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { i } from "@instantdb/core";
2
2
  import { domain } from "@ekairos/domain";
3
- import { threadDomain } from "@ekairos/events/schema";
3
+ import { eventsDomain } from "@ekairos/events/schema";
4
4
  import { sandboxDomain } from "@ekairos/sandbox/schema";
5
5
  const entities = {
6
6
  // Keep $files compatible with Instant's base file fields used by structure flows.
@@ -20,20 +20,15 @@ const links = {
20
20
  * Structure output link (rows):
21
21
  *
22
22
  * - `event_contexts.structure_output_file` points to the `$files` record for `output.jsonl`.
23
- * - A legacy `thread_contexts` link is kept for mixed deployments during migration.
24
23
  * - Reverse label is prefixed to avoid collisions across domains.
25
24
  */
26
25
  structureContextOutputFile: {
27
26
  forward: { on: "event_contexts", has: "one", label: "structure_output_file" },
28
27
  reverse: { on: "$files", has: "many", label: "structure_contexts" },
29
28
  },
30
- structureLegacyContextOutputFile: {
31
- forward: { on: "thread_contexts", has: "one", label: "structure_output_file" },
32
- reverse: { on: "$files", has: "many", label: "structure_legacy_contexts" },
33
- },
34
29
  };
35
30
  const rooms = {};
36
31
  export const structureDomain = domain("structure")
37
- .includes(threadDomain)
32
+ .includes(eventsDomain)
38
33
  .includes(sandboxDomain)
39
34
  .schema({ entities, links, rooms });
@@ -23,8 +23,8 @@ export async function structureCommitFromEventsStep(params) {
23
23
  "use step";
24
24
  const contextKey = `structure:${params.structureId}`;
25
25
  try {
26
- const { getThreadRuntime } = await import("@ekairos/events/runtime");
27
- const runtime = (await getThreadRuntime(params.env));
26
+ const { getContextRuntime } = await import("@ekairos/events/runtime");
27
+ const runtime = (await getContextRuntime(params.env));
28
28
  const store = runtime.store;
29
29
  const db = runtime.db;
30
30
  const events = await store.getItems({ key: contextKey });
@@ -33,8 +33,8 @@ function toSerializableError(error) {
33
33
  }
34
34
  export async function ensureExecutionTrailStep(params) {
35
35
  "use step";
36
- const { getThreadRuntime } = await import("@ekairos/events/runtime");
37
- const runtime = (await getThreadRuntime(params.env));
36
+ const { getContextRuntime } = await import("@ekairos/events/runtime");
37
+ const runtime = (await getContextRuntime(params.env));
38
38
  const store = runtime.store;
39
39
  if (!store?.saveItem ||
40
40
  !store?.createExecution ||
@@ -36,8 +36,8 @@ function extractJsonObject(text) {
36
36
  }
37
37
  export async function persistObjectResultFromStoryStep(params) {
38
38
  "use step";
39
- const { getThreadRuntime } = await import("@ekairos/events/runtime");
40
- const runtime = (await getThreadRuntime(params.env));
39
+ const { getContextRuntime } = await import("@ekairos/events/runtime");
40
+ const runtime = (await getContextRuntime(params.env));
41
41
  const store = runtime.store;
42
42
  const contextKey = `structure:${params.datasetId}`;
43
43
  const events = await store.getEvents({ key: contextKey });
package/dist/structure.js CHANGED
@@ -1,4 +1,4 @@
1
- import { createThread, didToolExecute, INPUT_TEXT_ITEM_TYPE, WEB_CHANNEL } from "@ekairos/events";
1
+ import { createContext, didToolExecute, INPUT_TEXT_ITEM_TYPE, WEB_CHANNEL } from "@ekairos/events";
2
2
  import { getDatasetOutputPath, getDatasetOutputSchemaPath, getDatasetWorkstation, getDaytonaVolumeMountPath, getDaytonaVolumeName, } from "./datasetFiles.js";
3
3
  import { structureDownloadRowsOutputToSandboxStep, structureReadRowsOutputPageFromSandboxStep, } from "./rowsOutputPaging.js";
4
4
  import { structureSplitRowsOutputToDatasetStep } from "./rowsOutputSplit.js";
@@ -281,7 +281,7 @@ function createStructureStoryDefinition(config) {
281
281
  const model = config.model ?? "openai/gpt-5.2";
282
282
  const defaultSandboxConfig = getDefaultSandboxConfig(datasetId);
283
283
  const resolvedSandboxConfig = mergeSandboxConfig(defaultSandboxConfig, config.sandboxConfig);
284
- const story = createThread("ekairos.structure")
284
+ const story = createContext("ekairos.structure")
285
285
  .context(async (stored, env) => {
286
286
  const prev = stored?.content ?? {};
287
287
  const sandboxState = prev.sandboxState ?? { initialized: false, sources: [] };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ekairos/structure",
3
- "version": "1.22.28-beta.feature-events-package-refactor.0",
3
+ "version": "1.22.30-beta.development.0",
4
4
  "description": "Ekairos Structure - Unified structured extraction (rows or object) from file/text/dataset inputs",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -36,8 +36,8 @@
36
36
  "typecheck": "tsc --noEmit"
37
37
  },
38
38
  "dependencies": {
39
- "@ekairos/domain": "^1.22.28-beta.feature-events-package-refactor.0",
40
- "@ekairos/sandbox": "^1.22.28-beta.feature-events-package-refactor.0",
39
+ "@ekairos/domain": "^1.22.30-beta.development.0",
40
+ "@ekairos/sandbox": "^1.22.30-beta.development.0",
41
41
  "@instantdb/admin": "0.22.126",
42
42
  "@instantdb/core": "0.22.126",
43
43
  "ai": "^5.0.95",