@ekairos/structure 1.22.22-beta.development.0 → 1.22.24-beta.feature-events-package-refactor.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.
@@ -0,0 +1,29 @@
1
+ declare const STRUCTURE_CONTEXT_ENTITIES: readonly ["event_contexts", "thread_contexts"];
2
+ type StructureContextEntity = (typeof STRUCTURE_CONTEXT_ENTITIES)[number];
3
+ type FindStructureContextParams = {
4
+ includeOutputFile?: boolean;
5
+ };
6
+ type FindStructureContextResult = {
7
+ entity: StructureContextEntity;
8
+ row: any;
9
+ };
10
+ export declare function findStructureContextByKey(db: any, key: string, params?: FindStructureContextParams): Promise<FindStructureContextResult | null>;
11
+ export declare function createStructureContext(db: any, params: {
12
+ id: string;
13
+ key: string;
14
+ content?: Record<string, unknown>;
15
+ status?: string;
16
+ createdAt?: Date;
17
+ }): Promise<{
18
+ entity: "event_contexts" | "thread_contexts";
19
+ id: string;
20
+ }>;
21
+ export declare function linkStructureOutputFileToContextByKey(db: any, params: {
22
+ contextKey: string;
23
+ fileId: string;
24
+ }): Promise<void>;
25
+ export declare function unlinkStructureOutputFileFromContextByKey(db: any, params: {
26
+ contextKey: string;
27
+ fileId: string;
28
+ }): Promise<void>;
29
+ export {};
@@ -0,0 +1,64 @@
1
+ const STRUCTURE_CONTEXT_ENTITIES = ["event_contexts", "thread_contexts"];
2
+ function buildContextQuery(entity, key, includeOutputFile) {
3
+ return {
4
+ [entity]: {
5
+ $: { where: { key }, limit: 1 },
6
+ ...(includeOutputFile ? { structure_output_file: {} } : {}),
7
+ },
8
+ };
9
+ }
10
+ function preferredContextEntity(db) {
11
+ if (db?.tx?.event_contexts)
12
+ return "event_contexts";
13
+ if (db?.tx?.thread_contexts)
14
+ return "thread_contexts";
15
+ throw new Error("No persisted context collection is available");
16
+ }
17
+ export async function findStructureContextByKey(db, key, params = {}) {
18
+ let lastError = null;
19
+ let queried = false;
20
+ for (const entity of STRUCTURE_CONTEXT_ENTITIES) {
21
+ try {
22
+ const res = await db.query(buildContextQuery(entity, key, Boolean(params.includeOutputFile)));
23
+ queried = true;
24
+ const row = res?.[entity]?.[0];
25
+ if (row)
26
+ return { entity, row };
27
+ }
28
+ catch (error) {
29
+ lastError = error;
30
+ }
31
+ }
32
+ if (!queried && lastError) {
33
+ throw lastError;
34
+ }
35
+ return null;
36
+ }
37
+ export async function createStructureContext(db, params) {
38
+ const entity = preferredContextEntity(db);
39
+ await db.transact([
40
+ db.tx[entity][params.id].create({
41
+ createdAt: params.createdAt ?? new Date(),
42
+ content: params.content ?? {},
43
+ key: params.key,
44
+ status: params.status ?? "open",
45
+ }),
46
+ ]);
47
+ return { entity, id: params.id };
48
+ }
49
+ export async function linkStructureOutputFileToContextByKey(db, params) {
50
+ const context = await findStructureContextByKey(db, params.contextKey);
51
+ const ctxId = context?.row?.id;
52
+ if (!context || !ctxId) {
53
+ throw new Error("Context not found");
54
+ }
55
+ await db.transact([db.tx[context.entity][ctxId].link({ structure_output_file: params.fileId })]);
56
+ }
57
+ export async function unlinkStructureOutputFileFromContextByKey(db, params) {
58
+ const context = await findStructureContextByKey(db, params.contextKey);
59
+ const ctxId = context?.row?.id;
60
+ if (!context || !ctxId) {
61
+ throw new Error("Context not found");
62
+ }
63
+ await db.transact([db.tx[context.entity][ctxId].unlink({ structure_output_file: params.fileId })]);
64
+ }
@@ -1,7 +1,8 @@
1
+ import { findStructureContextByKey, linkStructureOutputFileToContextByKey, unlinkStructureOutputFileFromContextByKey, } from "../contextPersistence.js";
1
2
  export async function structureGetOrCreateContextStep(params) {
2
3
  "use step";
3
4
  try {
4
- const { getThreadRuntime } = await import("@ekairos/thread/runtime");
5
+ const { getThreadRuntime } = await import("@ekairos/events/runtime");
5
6
  const runtime = await getThreadRuntime(params.env);
6
7
  const ctx = await runtime.store.getOrCreateContext({ key: params.contextKey });
7
8
  return { ok: true, data: ctx };
@@ -14,7 +15,7 @@ export async function structureGetOrCreateContextStep(params) {
14
15
  export async function structureGetContextStep(params) {
15
16
  "use step";
16
17
  try {
17
- const { getThreadRuntime } = await import("@ekairos/thread/runtime");
18
+ const { getThreadRuntime } = await import("@ekairos/events/runtime");
18
19
  const runtime = await getThreadRuntime(params.env);
19
20
  const ctx = await runtime.store.getContext({ key: params.contextKey });
20
21
  if (!ctx)
@@ -29,7 +30,7 @@ export async function structureGetContextStep(params) {
29
30
  export async function structureUpdateContextContentStep(params) {
30
31
  "use step";
31
32
  try {
32
- const { getThreadRuntime } = await import("@ekairos/thread/runtime");
33
+ const { getThreadRuntime } = await import("@ekairos/events/runtime");
33
34
  const runtime = await getThreadRuntime(params.env);
34
35
  const updated = await runtime.store.updateContextContent({ key: params.contextKey }, params.content);
35
36
  return { ok: true, data: updated };
@@ -42,7 +43,7 @@ export async function structureUpdateContextContentStep(params) {
42
43
  export async function structurePatchContextContentStep(params) {
43
44
  "use step";
44
45
  try {
45
- const { getThreadRuntime } = await import("@ekairos/thread/runtime");
46
+ const { getThreadRuntime } = await import("@ekairos/events/runtime");
46
47
  const runtime = await getThreadRuntime(params.env);
47
48
  const existing = await runtime.store.getOrCreateContext({ key: params.contextKey });
48
49
  const existingContent = (existing?.content ?? {});
@@ -65,7 +66,7 @@ export async function structureUploadRowsOutputJsonlStep(params) {
65
66
  "use step";
66
67
  const startedAt = Date.now();
67
68
  try {
68
- const { getThreadRuntime } = await import("@ekairos/thread/runtime");
69
+ const { getThreadRuntime } = await import("@ekairos/events/runtime");
69
70
  const runtime = await getThreadRuntime(params.env);
70
71
  const db = runtime.db;
71
72
  const storagePath = `/structure/${params.structureId}/output.jsonl`;
@@ -89,15 +90,12 @@ export async function structureLinkRowsOutputFileToContextStep(params) {
89
90
  "use step";
90
91
  const startedAt = Date.now();
91
92
  try {
92
- const { getThreadRuntime } = await import("@ekairos/thread/runtime");
93
+ const { getThreadRuntime } = await import("@ekairos/events/runtime");
93
94
  const runtime = await getThreadRuntime(params.env);
94
95
  const store = runtime.store;
95
96
  const db = runtime.db;
96
- const ctx = await store.getOrCreateContext({ key: params.contextKey });
97
- const ctxId = ctx?.id;
98
- if (!ctxId)
99
- return { ok: false, error: "Context not found" };
100
- await db.transact([db.tx.thread_contexts[ctxId].link({ structure_output_file: params.fileId })]);
97
+ await store.getOrCreateContext({ key: params.contextKey });
98
+ await linkStructureOutputFileToContextByKey(db, { contextKey: params.contextKey, fileId: params.fileId });
101
99
  console.log(`[structure:link-jsonl] contextKey=${params.contextKey} fileId=${params.fileId} elapsedMs=${Date.now() - startedAt}`);
102
100
  return { ok: true };
103
101
  }
@@ -109,15 +107,12 @@ export async function structureLinkRowsOutputFileToContextStep(params) {
109
107
  export async function structureUnlinkRowsOutputFileFromContextStep(params) {
110
108
  "use step";
111
109
  try {
112
- const { getThreadRuntime } = await import("@ekairos/thread/runtime");
110
+ const { getThreadRuntime } = await import("@ekairos/events/runtime");
113
111
  const runtime = await getThreadRuntime(params.env);
114
112
  const store = runtime.store;
115
113
  const db = runtime.db;
116
- const ctx = await store.getOrCreateContext({ key: params.contextKey });
117
- const ctxId = ctx?.id;
118
- if (!ctxId)
119
- return { ok: false, error: "Context not found" };
120
- await db.transact([db.tx.thread_contexts[ctxId].unlink({ structure_output_file: params.fileId })]);
114
+ await store.getOrCreateContext({ key: params.contextKey });
115
+ await unlinkStructureOutputFileFromContextByKey(db, { contextKey: params.contextKey, fileId: params.fileId });
121
116
  return { ok: true };
122
117
  }
123
118
  catch (error) {
@@ -128,16 +123,11 @@ export async function structureUnlinkRowsOutputFileFromContextStep(params) {
128
123
  export async function structureGetContextWithRowsOutputFileStep(params) {
129
124
  "use step";
130
125
  try {
131
- const { getThreadRuntime } = await import("@ekairos/thread/runtime");
126
+ const { getThreadRuntime } = await import("@ekairos/events/runtime");
132
127
  const runtime = await getThreadRuntime(params.env);
133
128
  const db = runtime.db;
134
- const query = (await db.query({
135
- thread_contexts: {
136
- $: { where: { key: params.contextKey }, limit: 1 },
137
- structure_output_file: {},
138
- },
139
- }));
140
- const row = query.thread_contexts?.[0];
129
+ const persisted = await findStructureContextByKey(db, params.contextKey, { includeOutputFile: true });
130
+ const row = persisted?.row;
141
131
  if (!row)
142
132
  return { ok: false, error: "Context not found" };
143
133
  return { ok: true, data: row };
@@ -152,16 +142,11 @@ export async function structureReadRowsOutputJsonlStep(params) {
152
142
  const startedAt = Date.now();
153
143
  try {
154
144
  const contextKey = `structure:${params.structureId}`;
155
- const { getThreadRuntime } = await import("@ekairos/thread/runtime");
145
+ const { getThreadRuntime } = await import("@ekairos/events/runtime");
156
146
  const runtime = await getThreadRuntime(params.env);
157
147
  const db = runtime.db;
158
- const query = (await db.query({
159
- thread_contexts: {
160
- $: { where: { key: contextKey }, limit: 1 },
161
- structure_output_file: {},
162
- },
163
- }));
164
- const ctx = query.thread_contexts?.[0];
148
+ const persisted = await findStructureContextByKey(db, contextKey, { includeOutputFile: true });
149
+ const ctx = persisted?.row;
165
150
  if (!ctx)
166
151
  return { ok: false, error: "Context not found" };
167
152
  const linked = Array.isArray(ctx?.structure_output_file) ? ctx.structure_output_file[0] : ctx.structure_output_file;
@@ -1,6 +1,6 @@
1
1
  export async function readInstantFileStep(params) {
2
2
  "use step";
3
- const { getThreadRuntime } = await import("@ekairos/thread/runtime");
3
+ const { getThreadRuntime } = await import("@ekairos/events/runtime");
4
4
  const runtime = (await getThreadRuntime(params.env));
5
5
  const db = runtime.db;
6
6
  const { DatasetService } = await import("../service.js");
@@ -1,5 +1,6 @@
1
1
  import { getDatasetOutputPath, getDatasetWorkstation } from "./datasetFiles.js";
2
2
  import { createDatasetSandboxStep, runDatasetSandboxCommandStep } from "./sandbox/steps.js";
3
+ import { findStructureContextByKey } from "./contextPersistence.js";
3
4
  import { getThreadRuntime } from "./runtime.js";
4
5
  /**
5
6
  * Step 1/2:
@@ -40,13 +41,8 @@ export async function structureDownloadRowsOutputToSandboxStep(params) {
40
41
  const storyRuntime = await getThreadRuntime(params.env);
41
42
  const db = storyRuntime.db;
42
43
  const contextKey = `structure:${params.structureId}`;
43
- const query = (await db.query({
44
- thread_contexts: {
45
- $: { where: { key: contextKey }, limit: 1 },
46
- structure_output_file: {},
47
- },
48
- }));
49
- const ctx = query.thread_contexts?.[0];
44
+ const persisted = await findStructureContextByKey(db, contextKey, { includeOutputFile: true });
45
+ const ctx = persisted?.row;
50
46
  const linked = Array.isArray(ctx?.structure_output_file) ? ctx.structure_output_file[0] : ctx.structure_output_file;
51
47
  const url = linked?.url;
52
48
  if (!url) {
@@ -1,5 +1,6 @@
1
1
  import { getDatasetOutputPath, getDatasetWorkstation } from "./datasetFiles.js";
2
2
  import { readDatasetSandboxFileStep, runDatasetSandboxCommandStep } from "./sandbox/steps.js";
3
+ import { linkStructureOutputFileToContextByKey } from "./contextPersistence.js";
3
4
  import { getThreadRuntime } from "./runtime.js";
4
5
  /**
5
6
  * Step:
@@ -102,7 +103,7 @@ export async function structureSplitRowsOutputToDatasetStep(params) {
102
103
  if (!ctxId)
103
104
  throw new Error("Failed to create child dataset context");
104
105
  // Link the output file to the context (used by DatasetService.readRecordsFromFile).
105
- await db.transact([db.tx.thread_contexts[ctxId].link({ structure_output_file: fileId })]);
106
+ await linkStructureOutputFileToContextByKey(db, { contextKey, fileId });
106
107
  // Patch metadata under `structure` namespace (never clobber Story runtime keys).
107
108
  const existingContent = (ctx?.content ?? {});
108
109
  const existingStructure = (existingContent?.structure ?? {});
package/dist/runtime.d.ts CHANGED
@@ -6,4 +6,4 @@
6
6
  * causing `ReferenceError: getThreadRuntime 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/thread/runtime").ThreadRuntime>;
9
+ export declare function getThreadRuntime(env: any): Promise<import("@ekairos/events/runtime").ThreadRuntime>;
package/dist/runtime.js CHANGED
@@ -7,6 +7,6 @@
7
7
  * - Using a dynamic import keeps the symbol resolution local to the step runtime.
8
8
  */
9
9
  export async function getThreadRuntime(env) {
10
- const { getThreadRuntime } = await import("@ekairos/thread/runtime");
10
+ const { getThreadRuntime } = await import("@ekairos/events/runtime");
11
11
  return await getThreadRuntime(env);
12
12
  }
@@ -104,7 +104,7 @@ 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/thread/runtime");
107
+ const { getThreadRuntime } = await import("@ekairos/events/runtime");
108
108
  const db = (await getThreadRuntime(env)).db;
109
109
  const { SandboxService } = (await import("@ekairos/sandbox"));
110
110
  const service = new SandboxService(db);
@@ -181,7 +181,7 @@ 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/thread/runtime");
184
+ const { getThreadRuntime } = await import("@ekairos/events/runtime");
185
185
  const db = (await getThreadRuntime(params.env)).db;
186
186
  const { SandboxService } = (await import("@ekairos/sandbox"));
187
187
  const service = new SandboxService(db);
@@ -202,7 +202,7 @@ 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/thread/runtime");
205
+ const { getThreadRuntime } = await import("@ekairos/events/runtime");
206
206
  const db = (await getThreadRuntime(params.env)).db;
207
207
  const { SandboxService } = (await import("@ekairos/sandbox"));
208
208
  const service = new SandboxService(db);
@@ -233,7 +233,7 @@ 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/thread/runtime");
236
+ const { getThreadRuntime } = await import("@ekairos/events/runtime");
237
237
  const db = (await getThreadRuntime(params.env)).db;
238
238
  const { SandboxService } = (await import("@ekairos/sandbox"));
239
239
  const service = new SandboxService(db);
@@ -262,7 +262,7 @@ 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/thread/runtime");
265
+ const { getThreadRuntime } = await import("@ekairos/events/runtime");
266
266
  const db = (await getThreadRuntime(params.env)).db;
267
267
  const { SandboxService } = (await import("@ekairos/sandbox"));
268
268
  const service = new SandboxService(db);
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/thread/schema";
3
+ import { threadDomain } 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.
@@ -19,13 +19,18 @@ const links = {
19
19
  /**
20
20
  * Structure output link (rows):
21
21
  *
22
- * - `thread_contexts.structure_output_file` points to the `$files` record for `output.jsonl`.
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.
23
24
  * - Reverse label is prefixed to avoid collisions across domains.
24
25
  */
25
26
  structureContextOutputFile: {
26
- forward: { on: "thread_contexts", has: "one", label: "structure_output_file" },
27
+ forward: { on: "event_contexts", has: "one", label: "structure_output_file" },
27
28
  reverse: { on: "$files", has: "many", label: "structure_contexts" },
28
29
  },
30
+ structureLegacyContextOutputFile: {
31
+ forward: { on: "thread_contexts", has: "one", label: "structure_output_file" },
32
+ reverse: { on: "$files", has: "many", label: "structure_legacy_contexts" },
33
+ },
29
34
  };
30
35
  const rooms = {};
31
36
  export const structureDomain = domain("structure")
package/dist/service.d.ts CHANGED
@@ -8,7 +8,7 @@ export type ServiceResult<T = any> = {
8
8
  /**
9
9
  * Back-compat helper for reading structure outputs outside the workflow runtime.
10
10
  *
11
- * IMPORTANT: The source of truth is `thread_contexts` (Story context) keyed by `structure:<id>`.
11
+ * IMPORTANT: The source of truth is the persisted Story/Event context keyed by `structure:<id>`.
12
12
  */
13
13
  export declare class DatasetService {
14
14
  private readonly db;
package/dist/service.js CHANGED
@@ -1,7 +1,8 @@
1
+ import { createStructureContext, findStructureContextByKey, linkStructureOutputFileToContextByKey, } from "./contextPersistence.js";
1
2
  /**
2
3
  * Back-compat helper for reading structure outputs outside the workflow runtime.
3
4
  *
4
- * IMPORTANT: The source of truth is `thread_contexts` (Story context) keyed by `structure:<id>`.
5
+ * IMPORTANT: The source of truth is the persisted Story/Event context keyed by `structure:<id>`.
5
6
  */
6
7
  export class DatasetService {
7
8
  constructor(db) {
@@ -13,13 +14,8 @@ export class DatasetService {
13
14
  async getDatasetById(datasetId) {
14
15
  try {
15
16
  const key = this.contextKey(datasetId);
16
- const res = await this.db.query({
17
- thread_contexts: {
18
- $: { where: { key }, limit: 1 },
19
- structure_output_file: {},
20
- },
21
- });
22
- const ctx = res.thread_contexts?.[0];
17
+ const persisted = await findStructureContextByKey(this.db, key, { includeOutputFile: true });
18
+ const ctx = persisted?.row;
23
19
  if (!ctx)
24
20
  return { ok: false, error: "Context not found" };
25
21
  return { ok: true, data: ctx };
@@ -43,13 +39,8 @@ export class DatasetService {
43
39
  async readRecordsFromFile(datasetId) {
44
40
  try {
45
41
  const key = this.contextKey(datasetId);
46
- const res = await this.db.query({
47
- thread_contexts: {
48
- $: { where: { key }, limit: 1 },
49
- structure_output_file: {},
50
- },
51
- });
52
- const ctx = res.thread_contexts?.[0];
42
+ const persisted = await findStructureContextByKey(this.db, key, { includeOutputFile: true });
43
+ const ctx = persisted?.row;
53
44
  const linked = Array.isArray(ctx?.structure_output_file) ? ctx.structure_output_file[0] : ctx?.structure_output_file;
54
45
  const url = linked?.url;
55
46
  if (!url)
@@ -89,20 +80,14 @@ export class DatasetService {
89
80
  try {
90
81
  const datasetId = params.id ?? createUuidV4();
91
82
  const key = this.contextKey(datasetId);
92
- const existing = await this.db.query({
93
- thread_contexts: { $: { where: { key }, limit: 1 } },
94
- });
95
- const ctx = existing.thread_contexts?.[0];
83
+ const existing = await findStructureContextByKey(this.db, key);
84
+ const ctx = existing?.row;
96
85
  if (ctx)
97
86
  return { ok: true, data: { datasetId } };
98
- await this.db.transact([
99
- this.db.tx.thread_contexts[createUuidV4()].create({
100
- createdAt: new Date(),
101
- content: {},
102
- key,
103
- status: "open",
104
- }),
105
- ]);
87
+ await createStructureContext(this.db, {
88
+ id: createUuidV4(),
89
+ key,
90
+ });
106
91
  return { ok: true, data: { datasetId } };
107
92
  }
108
93
  catch (error) {
@@ -133,14 +118,10 @@ export class DatasetService {
133
118
  async linkFileToDataset(params) {
134
119
  try {
135
120
  const key = this.contextKey(params.datasetId);
136
- const res = await this.db.query({
137
- thread_contexts: { $: { where: { key }, limit: 1 } },
138
- });
139
- const ctx = res?.thread_contexts?.[0];
140
- const ctxId = ctx?.id;
141
- if (!ctxId)
121
+ const persisted = await findStructureContextByKey(this.db, key);
122
+ if (!persisted?.row?.id)
142
123
  return { ok: false, error: "Context not found" };
143
- await this.db.transact([this.db.tx.thread_contexts[ctxId].link({ structure_output_file: params.fileId })]);
124
+ await linkStructureOutputFileToContextByKey(this.db, { contextKey: key, fileId: params.fileId });
144
125
  return { ok: true, data: undefined };
145
126
  }
146
127
  catch (error) {
@@ -1,3 +1,4 @@
1
+ import { linkStructureOutputFileToContextByKey } from "../contextPersistence.js";
1
2
  function isToolCompletePart(value) {
2
3
  if (!value || typeof value !== "object")
3
4
  return false;
@@ -22,7 +23,7 @@ export async function structureCommitFromEventsStep(params) {
22
23
  "use step";
23
24
  const contextKey = `structure:${params.structureId}`;
24
25
  try {
25
- const { getThreadRuntime } = await import("@ekairos/thread/runtime");
26
+ const { getThreadRuntime } = await import("@ekairos/events/runtime");
26
27
  const runtime = (await getThreadRuntime(params.env));
27
28
  const store = runtime.store;
28
29
  const db = runtime.db;
@@ -66,10 +67,9 @@ export async function structureCommitFromEventsStep(params) {
66
67
  },
67
68
  };
68
69
  // Link output file to context (domain-prefixed link)
69
- const ctxId = ctx?.id;
70
- if (!ctxId)
70
+ if (!ctx?.id)
71
71
  return { ok: false, error: "Context not found" };
72
- await db.transact(db.tx.thread_contexts[ctxId].link({ structure_output_file: out.fileId }));
72
+ await linkStructureOutputFileToContextByKey(db, { contextKey, fileId: out.fileId });
73
73
  }
74
74
  await store.updateContextContent({ key: contextKey }, { ...prevContent, structure: nextStructure });
75
75
  return { ok: true, data: { committed: true } };
@@ -36,7 +36,7 @@ function extractJsonObject(text) {
36
36
  }
37
37
  export async function persistObjectResultFromStoryStep(params) {
38
38
  "use step";
39
- const { getThreadRuntime } = await import("@ekairos/thread/runtime");
39
+ const { getThreadRuntime } = await import("@ekairos/events/runtime");
40
40
  const runtime = (await getThreadRuntime(params.env));
41
41
  const store = runtime.store;
42
42
  const contextKey = `structure:${params.datasetId}`;
package/dist/structure.js CHANGED
@@ -1,4 +1,4 @@
1
- import { createThread, didToolExecute, INPUT_TEXT_ITEM_TYPE, WEB_CHANNEL } from "@ekairos/thread";
1
+ import { createThread, 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";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ekairos/structure",
3
- "version": "1.22.22-beta.development.0",
3
+ "version": "1.22.24-beta.feature-events-package-refactor.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.22-beta.development.0",
40
- "@ekairos/sandbox": "^1.22.22-beta.development.0",
39
+ "@ekairos/domain": "^1.22.24-beta.feature-events-package-refactor.0",
40
+ "@ekairos/sandbox": "^1.22.24-beta.feature-events-package-refactor.0",
41
41
  "@instantdb/admin": "0.22.126",
42
42
  "@instantdb/core": "0.22.126",
43
43
  "ai": "^5.0.95",
@@ -46,11 +46,11 @@
46
46
  "zod": "^4.1.8"
47
47
  },
48
48
  "peerDependencies": {
49
- "@ekairos/thread": "workspace:*"
49
+ "@ekairos/events": "workspace:*"
50
50
  },
51
51
  "devDependencies": {
52
52
  "@ekairos/sandbox": "workspace:*",
53
- "@ekairos/thread": "workspace:*",
53
+ "@ekairos/events": "workspace:*",
54
54
  "@ekairos/tsconfig": "workspace:*",
55
55
  "@types/node": "^24.5.0",
56
56
  "dotenv": "^17.2.2",