@ekairos/structure 1.21.67-beta.0 → 1.21.71-beta.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.
- package/dist/clearDataset.tool.js +0 -3
- package/dist/completeObject.tool.js +0 -7
- package/dist/completeRows.tool.js +0 -9
- package/dist/executeCommand.tool.js +0 -8
- package/dist/generateSchema.tool.js +0 -18
- package/dist/sandbox/steps.js +0 -20
- package/dist/steps/persistObjectFromStory.step.js +0 -6
- package/dist/structure.js +0 -56
- package/package.json +2 -2
|
@@ -9,8 +9,6 @@ export function createClearDatasetTool({ datasetId, sandboxId, env }) {
|
|
|
9
9
|
reason: z.string().describe("Reason for clearing"),
|
|
10
10
|
}),
|
|
11
11
|
execute: async ({ reason }) => {
|
|
12
|
-
console.log("[ekairos/structure] clearDataset.tool execute begin");
|
|
13
|
-
console.log("[ekairos/structure] clearDataset.tool execute datasetId", datasetId);
|
|
14
12
|
const outputPath = getDatasetOutputPath(datasetId);
|
|
15
13
|
try {
|
|
16
14
|
await runDatasetSandboxCommandStep({ env, sandboxId, cmd: "rm", args: ["-f", outputPath] });
|
|
@@ -18,7 +16,6 @@ export function createClearDatasetTool({ datasetId, sandboxId, env }) {
|
|
|
18
16
|
catch {
|
|
19
17
|
// best-effort
|
|
20
18
|
}
|
|
21
|
-
console.log("[ekairos/structure] clearDataset.tool execute ok");
|
|
22
19
|
return { success: true, message: "Cleared", reason };
|
|
23
20
|
},
|
|
24
21
|
});
|
|
@@ -24,8 +24,6 @@ export function createCompleteObjectTool({ datasetId, sandboxId, env }) {
|
|
|
24
24
|
message: "Provide result, resultJson or resultPath",
|
|
25
25
|
}),
|
|
26
26
|
execute: async (input) => {
|
|
27
|
-
console.log("[ekairos/structure] completeObject.tool execute begin");
|
|
28
|
-
console.log("[ekairos/structure] completeObject.tool execute datasetId", datasetId);
|
|
29
27
|
const contextKey = `structure:${datasetId}`;
|
|
30
28
|
const ctxResult = await structureGetContextStep({ env, contextKey });
|
|
31
29
|
if (!ctxResult.ok)
|
|
@@ -37,7 +35,6 @@ export function createCompleteObjectTool({ datasetId, sandboxId, env }) {
|
|
|
37
35
|
else {
|
|
38
36
|
let jsonText = input.resultJson ?? "";
|
|
39
37
|
if (!jsonText && input.resultPath) {
|
|
40
|
-
console.log("[ekairos/structure] completeObject.tool execute readingResultPath");
|
|
41
38
|
const fileRead = await readDatasetSandboxTextFileStep({ env, sandboxId, path: input.resultPath });
|
|
42
39
|
jsonText = fileRead.text ?? "";
|
|
43
40
|
}
|
|
@@ -46,7 +43,6 @@ export function createCompleteObjectTool({ datasetId, sandboxId, env }) {
|
|
|
46
43
|
}
|
|
47
44
|
catch (error) {
|
|
48
45
|
const message = error instanceof Error ? error.message : String(error);
|
|
49
|
-
console.log("[ekairos/structure] completeObject.tool execute invalidJson");
|
|
50
46
|
return { success: false, error: `Invalid JSON: ${message}` };
|
|
51
47
|
}
|
|
52
48
|
}
|
|
@@ -62,17 +58,14 @@ export function createCompleteObjectTool({ datasetId, sandboxId, env }) {
|
|
|
62
58
|
const errors = Array.isArray(validator.errors)
|
|
63
59
|
? validator.errors.map((err) => err.message || "Unknown validation error")
|
|
64
60
|
: ["Unknown validation error"];
|
|
65
|
-
console.log("[ekairos/structure] completeObject.tool execute schemaValidationFailed");
|
|
66
61
|
return { success: false, error: errors.slice(0, 5).join("; ") };
|
|
67
62
|
}
|
|
68
63
|
}
|
|
69
64
|
catch (error) {
|
|
70
65
|
const message = error instanceof Error ? error.message : String(error);
|
|
71
|
-
console.log("[ekairos/structure] completeObject.tool execute schemaValidateThrew");
|
|
72
66
|
return { success: false, error: `Failed to validate schema: ${message}` };
|
|
73
67
|
}
|
|
74
68
|
}
|
|
75
|
-
console.log("[ekairos/structure] completeObject.tool execute ok");
|
|
76
69
|
return { success: true, summary: input.summary, result: obj };
|
|
77
70
|
},
|
|
78
71
|
});
|
|
@@ -18,8 +18,6 @@ export function createCompleteRowsTool({ datasetId, sandboxId, env }) {
|
|
|
18
18
|
summary: z.string().describe("Summary of the completed dataset"),
|
|
19
19
|
}),
|
|
20
20
|
execute: async ({ summary }) => {
|
|
21
|
-
console.log("[ekairos/structure] completeRows.tool execute begin");
|
|
22
|
-
console.log("[ekairos/structure] completeRows.tool execute datasetId", datasetId);
|
|
23
21
|
const contextKey = `structure:${datasetId}`;
|
|
24
22
|
const outputPath = getDatasetOutputPath(datasetId);
|
|
25
23
|
try {
|
|
@@ -27,7 +25,6 @@ export function createCompleteRowsTool({ datasetId, sandboxId, env }) {
|
|
|
27
25
|
}
|
|
28
26
|
catch (error) {
|
|
29
27
|
const message = error instanceof Error ? error.message : String(error);
|
|
30
|
-
console.log("[ekairos/structure] completeRows.tool execute missingOutputFile");
|
|
31
28
|
return { success: false, error: message };
|
|
32
29
|
}
|
|
33
30
|
const ctxResult = await structureGetContextStep({ env, contextKey });
|
|
@@ -36,7 +33,6 @@ export function createCompleteRowsTool({ datasetId, sandboxId, env }) {
|
|
|
36
33
|
const content = (ctxResult.data?.content ?? {});
|
|
37
34
|
const outputSchema = content?.structure?.outputSchema;
|
|
38
35
|
if (!outputSchema?.schema) {
|
|
39
|
-
console.log("[ekairos/structure] completeRows.tool execute schemaMissing");
|
|
40
36
|
return { success: false, error: "Schema not found in database. Please generate schema first." };
|
|
41
37
|
}
|
|
42
38
|
const schemaJson = outputSchema.schema;
|
|
@@ -48,11 +44,9 @@ export function createCompleteRowsTool({ datasetId, sandboxId, env }) {
|
|
|
48
44
|
catch (error) {
|
|
49
45
|
const message = error instanceof Error ? error.message : String(error);
|
|
50
46
|
if (mode === "auto") {
|
|
51
|
-
console.log("[ekairos/structure] completeRows.tool execute schemaCompileSkippedAuto");
|
|
52
47
|
validator = null;
|
|
53
48
|
}
|
|
54
49
|
else {
|
|
55
|
-
console.log("[ekairos/structure] completeRows.tool execute schemaCompileFailed");
|
|
56
50
|
return { success: false, error: `Failed to compile schema: ${message}` };
|
|
57
51
|
}
|
|
58
52
|
}
|
|
@@ -63,7 +57,6 @@ export function createCompleteRowsTool({ datasetId, sandboxId, env }) {
|
|
|
63
57
|
return validationResult;
|
|
64
58
|
totalValidRows = validationResult.validRowCount ?? 0;
|
|
65
59
|
}
|
|
66
|
-
console.log("[ekairos/structure] completeRows.tool execute validRowCount", totalValidRows);
|
|
67
60
|
const fileRead = await readDatasetSandboxFileStep({ env, sandboxId, path: outputPath });
|
|
68
61
|
if (!fileRead.contentBase64)
|
|
69
62
|
return { success: false, error: "Empty file content" };
|
|
@@ -74,8 +67,6 @@ export function createCompleteRowsTool({ datasetId, sandboxId, env }) {
|
|
|
74
67
|
});
|
|
75
68
|
if (!uploadResult.ok)
|
|
76
69
|
return { success: false, error: uploadResult.error };
|
|
77
|
-
console.log("[ekairos/structure] completeRows.tool execute uploadedFileId", uploadResult.data.fileId);
|
|
78
|
-
console.log("[ekairos/structure] completeRows.tool execute ok");
|
|
79
70
|
return {
|
|
80
71
|
success: true,
|
|
81
72
|
summary,
|
|
@@ -30,20 +30,15 @@ export function createExecuteCommandTool({ datasetId, sandboxId, env }) {
|
|
|
30
30
|
.describe("Name for the script file in snake_case (e.g., 'inspect_file', 'parse_csv', 'generate_output'). The file will be saved as <scriptName>.py in the workstation."),
|
|
31
31
|
}),
|
|
32
32
|
execute: async ({ pythonCode, scriptName }) => {
|
|
33
|
-
console.log("[ekairos/structure] executeCommand.tool execute begin");
|
|
34
|
-
console.log("[ekairos/structure] executeCommand.tool execute datasetId", datasetId);
|
|
35
|
-
console.log("[ekairos/structure] executeCommand.tool execute scriptName", scriptName);
|
|
36
33
|
const workstation = getDatasetWorkstation(datasetId);
|
|
37
34
|
const scriptNameWithExt = `${normalizeScriptName(scriptName)}.py`;
|
|
38
35
|
const scriptFile = `${workstation}/${scriptNameWithExt}`;
|
|
39
|
-
console.log("[ekairos/structure] executeCommand.tool execute writingScript");
|
|
40
36
|
await writeDatasetSandboxTextFileStep({
|
|
41
37
|
env,
|
|
42
38
|
sandboxId,
|
|
43
39
|
path: scriptFile,
|
|
44
40
|
text: pythonCode,
|
|
45
41
|
});
|
|
46
|
-
console.log("[ekairos/structure] executeCommand.tool execute runningPython");
|
|
47
42
|
const result = await runDatasetSandboxCommandStep({
|
|
48
43
|
env,
|
|
49
44
|
sandboxId,
|
|
@@ -58,7 +53,6 @@ export function createExecuteCommandTool({ datasetId, sandboxId, env }) {
|
|
|
58
53
|
const stdoutCapped = isStdoutTruncated ? stdout.slice(0, MAX_STDOUT_CHARS) : stdout;
|
|
59
54
|
const stderrCapped = isStderrTruncated ? stderr.slice(0, MAX_STDERR_CHARS) : stderr;
|
|
60
55
|
if (exitCode !== 0) {
|
|
61
|
-
console.log("[ekairos/structure] executeCommand.tool execute failedExitCode");
|
|
62
56
|
return {
|
|
63
57
|
success: false,
|
|
64
58
|
exitCode,
|
|
@@ -73,7 +67,6 @@ export function createExecuteCommandTool({ datasetId, sandboxId, env }) {
|
|
|
73
67
|
};
|
|
74
68
|
}
|
|
75
69
|
if (stderr && (stderr.includes("Traceback") || stderr.toLowerCase().includes("error"))) {
|
|
76
|
-
console.log("[ekairos/structure] executeCommand.tool execute pythonErrorDetected");
|
|
77
70
|
return {
|
|
78
71
|
success: false,
|
|
79
72
|
exitCode,
|
|
@@ -87,7 +80,6 @@ export function createExecuteCommandTool({ datasetId, sandboxId, env }) {
|
|
|
87
80
|
stderrOriginalLength: stderr.length,
|
|
88
81
|
};
|
|
89
82
|
}
|
|
90
|
-
console.log("[ekairos/structure] executeCommand.tool execute ok");
|
|
91
83
|
return {
|
|
92
84
|
success: true,
|
|
93
85
|
exitCode,
|
|
@@ -11,11 +11,6 @@ export function createGenerateSchemaTool({ datasetId, sandboxId, env }) {
|
|
|
11
11
|
schemaJson: z.string().describe("A JSON Schema string"),
|
|
12
12
|
}),
|
|
13
13
|
execute: async ({ schemaTitle, schemaDescription, schemaJson }) => {
|
|
14
|
-
console.log("[ekairos/structure] generateSchema.tool execute begin");
|
|
15
|
-
console.log("[ekairos/structure] generateSchema.tool execute datasetId", datasetId);
|
|
16
|
-
console.log("[ekairos/structure] generateSchema.tool execute sandboxId", sandboxId);
|
|
17
|
-
console.log("[ekairos/structure] generateSchema.tool execute schemaTitle", schemaTitle);
|
|
18
|
-
console.log("[ekairos/structure] generateSchema.tool execute schemaJsonLength", String(schemaJson ?? "").length);
|
|
19
14
|
const schemaData = {
|
|
20
15
|
title: schemaTitle,
|
|
21
16
|
description: schemaDescription,
|
|
@@ -24,17 +19,12 @@ export function createGenerateSchemaTool({ datasetId, sandboxId, env }) {
|
|
|
24
19
|
return JSON.parse(schemaJson);
|
|
25
20
|
}
|
|
26
21
|
catch (e) {
|
|
27
|
-
const message = e instanceof Error ? e.message : String(e);
|
|
28
|
-
console.log("[ekairos/structure] generateSchema.tool execute invalidSchemaJson");
|
|
29
|
-
console.log("[ekairos/structure] generateSchema.tool execute invalidSchemaJsonMessage", message);
|
|
30
|
-
console.log("[ekairos/structure] generateSchema.tool execute invalidSchemaJsonPreview", String(schemaJson ?? "").slice(0, 300));
|
|
31
22
|
throw e;
|
|
32
23
|
}
|
|
33
24
|
})(),
|
|
34
25
|
};
|
|
35
26
|
const schemaPath = getDatasetOutputSchemaPath(datasetId);
|
|
36
27
|
try {
|
|
37
|
-
console.log("[ekairos/structure] generateSchema.tool execute writingSchemaPath", schemaPath);
|
|
38
28
|
await writeDatasetSandboxTextFileStep({
|
|
39
29
|
env,
|
|
40
30
|
sandboxId,
|
|
@@ -43,17 +33,9 @@ export function createGenerateSchemaTool({ datasetId, sandboxId, env }) {
|
|
|
43
33
|
});
|
|
44
34
|
}
|
|
45
35
|
catch (e) {
|
|
46
|
-
console.log("[ekairos/structure] generateSchema.tool execute failed");
|
|
47
36
|
const message = e instanceof Error ? e.message : String(e);
|
|
48
|
-
console.log("[ekairos/structure] generateSchema.tool execute failedMessage", message);
|
|
49
|
-
if (e instanceof Error && e.stack) {
|
|
50
|
-
console.log("[ekairos/structure] generateSchema.tool execute failedStack", e.stack);
|
|
51
|
-
}
|
|
52
|
-
console.log("[ekairos/structure] generateSchema.tool execute failedSchemaPath", schemaPath);
|
|
53
|
-
console.log("[ekairos/structure] generateSchema.tool execute failedHasEnv", Boolean(env));
|
|
54
37
|
return { success: false, error: message };
|
|
55
38
|
}
|
|
56
|
-
console.log("[ekairos/structure] generateSchema.tool execute ok");
|
|
57
39
|
return { success: true, message: "Schema written", schemaPath };
|
|
58
40
|
},
|
|
59
41
|
});
|
package/dist/sandbox/steps.js
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
export async function createDatasetSandboxStep(params) {
|
|
2
2
|
"use step";
|
|
3
|
-
console.log("[ekairos/structure] sandbox.step createSandbox begin");
|
|
4
|
-
console.log("[ekairos/structure] sandbox.step createSandbox runtime", params.runtime);
|
|
5
3
|
const { resolveStoryRuntime } = await import("@ekairos/story/runtime");
|
|
6
4
|
const db = (await resolveStoryRuntime(params.env)).db;
|
|
7
5
|
const { SandboxService } = (await import("@ekairos/sandbox"));
|
|
@@ -9,15 +7,10 @@ export async function createDatasetSandboxStep(params) {
|
|
|
9
7
|
const created = await service.createSandbox(params);
|
|
10
8
|
if (!created.ok)
|
|
11
9
|
throw new Error(created.error);
|
|
12
|
-
console.log("[ekairos/structure] sandbox.step createSandbox ok");
|
|
13
|
-
console.log("[ekairos/structure] sandbox.step createSandbox sandboxId", created.data.sandboxId);
|
|
14
10
|
return { sandboxId: created.data.sandboxId };
|
|
15
11
|
}
|
|
16
12
|
export async function runDatasetSandboxCommandStep(params) {
|
|
17
13
|
"use step";
|
|
18
|
-
console.log("[ekairos/structure] sandbox.step runCommand begin");
|
|
19
|
-
console.log("[ekairos/structure] sandbox.step runCommand sandboxId", params.sandboxId);
|
|
20
|
-
console.log("[ekairos/structure] sandbox.step runCommand cmd", params.cmd);
|
|
21
14
|
const { resolveStoryRuntime } = await import("@ekairos/story/runtime");
|
|
22
15
|
const db = (await resolveStoryRuntime(params.env)).db;
|
|
23
16
|
const { SandboxService } = (await import("@ekairos/sandbox"));
|
|
@@ -30,15 +23,10 @@ export async function runDatasetSandboxCommandStep(params) {
|
|
|
30
23
|
stdout: result.data.output ?? "",
|
|
31
24
|
stderr: result.data.error ?? "",
|
|
32
25
|
};
|
|
33
|
-
console.log("[ekairos/structure] sandbox.step runCommand ok");
|
|
34
|
-
console.log("[ekairos/structure] sandbox.step runCommand exitCode", normalized.exitCode);
|
|
35
26
|
return normalized;
|
|
36
27
|
}
|
|
37
28
|
export async function writeDatasetSandboxFilesStep(params) {
|
|
38
29
|
"use step";
|
|
39
|
-
console.log("[ekairos/structure] sandbox.step writeFiles begin");
|
|
40
|
-
console.log("[ekairos/structure] sandbox.step writeFiles sandboxId", params.sandboxId);
|
|
41
|
-
console.log("[ekairos/structure] sandbox.step writeFiles paths", params.files.map((f) => f.path));
|
|
42
30
|
const { resolveStoryRuntime } = await import("@ekairos/story/runtime");
|
|
43
31
|
const db = (await resolveStoryRuntime(params.env)).db;
|
|
44
32
|
const { SandboxService } = (await import("@ekairos/sandbox"));
|
|
@@ -46,7 +34,6 @@ export async function writeDatasetSandboxFilesStep(params) {
|
|
|
46
34
|
const result = await service.writeFiles(params.sandboxId, params.files);
|
|
47
35
|
if (!result.ok)
|
|
48
36
|
throw new Error(result.error);
|
|
49
|
-
console.log("[ekairos/structure] sandbox.step writeFiles ok");
|
|
50
37
|
}
|
|
51
38
|
/**
|
|
52
39
|
* Workflow-safe helper:
|
|
@@ -66,9 +53,6 @@ export async function writeDatasetSandboxTextFileStep(params) {
|
|
|
66
53
|
}
|
|
67
54
|
export async function readDatasetSandboxFileStep(params) {
|
|
68
55
|
"use step";
|
|
69
|
-
console.log("[ekairos/structure] sandbox.step readFile begin");
|
|
70
|
-
console.log("[ekairos/structure] sandbox.step readFile sandboxId", params.sandboxId);
|
|
71
|
-
console.log("[ekairos/structure] sandbox.step readFile path", params.path);
|
|
72
56
|
const { resolveStoryRuntime } = await import("@ekairos/story/runtime");
|
|
73
57
|
const db = (await resolveStoryRuntime(params.env)).db;
|
|
74
58
|
const { SandboxService } = (await import("@ekairos/sandbox"));
|
|
@@ -76,7 +60,6 @@ export async function readDatasetSandboxFileStep(params) {
|
|
|
76
60
|
const result = await service.readFile(params.sandboxId, params.path);
|
|
77
61
|
if (!result.ok)
|
|
78
62
|
throw new Error(result.error);
|
|
79
|
-
console.log("[ekairos/structure] sandbox.step readFile ok");
|
|
80
63
|
return result.data;
|
|
81
64
|
}
|
|
82
65
|
/**
|
|
@@ -94,8 +77,6 @@ export async function readDatasetSandboxTextFileStep(params) {
|
|
|
94
77
|
}
|
|
95
78
|
export async function stopDatasetSandboxStep(params) {
|
|
96
79
|
"use step";
|
|
97
|
-
console.log("[ekairos/structure] sandbox.step stopSandbox begin");
|
|
98
|
-
console.log("[ekairos/structure] sandbox.step stopSandbox sandboxId", params.sandboxId);
|
|
99
80
|
const { resolveStoryRuntime } = await import("@ekairos/story/runtime");
|
|
100
81
|
const db = (await resolveStoryRuntime(params.env)).db;
|
|
101
82
|
const { SandboxService } = (await import("@ekairos/sandbox"));
|
|
@@ -103,5 +84,4 @@ export async function stopDatasetSandboxStep(params) {
|
|
|
103
84
|
const result = await service.stopSandbox(params.sandboxId);
|
|
104
85
|
if (!result.ok)
|
|
105
86
|
throw new Error(result.error);
|
|
106
|
-
console.log("[ekairos/structure] sandbox.step stopSandbox ok");
|
|
107
87
|
}
|
|
@@ -39,11 +39,8 @@ export async function persistObjectResultFromStoryStep(params) {
|
|
|
39
39
|
const { resolveStoryRuntime } = await import("@ekairos/story/runtime");
|
|
40
40
|
const runtime = (await resolveStoryRuntime(params.env));
|
|
41
41
|
const store = runtime.store;
|
|
42
|
-
console.log("[ekairos/structure] persistObjectFromStory.step execute begin");
|
|
43
|
-
console.log("[ekairos/structure] persistObjectFromStory.step execute datasetId", params.datasetId);
|
|
44
42
|
const contextKey = `structure:${params.datasetId}`;
|
|
45
43
|
const events = await store.getEvents({ key: contextKey });
|
|
46
|
-
console.log("[ekairos/structure] persistObjectFromStory.step execute eventsCount", Array.isArray(events) ? events.length : -1);
|
|
47
44
|
const { structurePatchContextContentStep, structureGetContextStep } = await import("../dataset/steps");
|
|
48
45
|
const ctxResult = await structureGetContextStep({ env: params.env, contextKey });
|
|
49
46
|
const existingContent = ctxResult.ok ? (ctxResult.data?.content ?? {}) : {};
|
|
@@ -58,7 +55,6 @@ export async function persistObjectResultFromStoryStep(params) {
|
|
|
58
55
|
.trim();
|
|
59
56
|
const obj = extractJsonObject(text);
|
|
60
57
|
if (obj) {
|
|
61
|
-
console.log("[ekairos/structure] persistObjectFromStory.step execute parsedJsonOk");
|
|
62
58
|
const patchResult = await structurePatchContextContentStep({
|
|
63
59
|
env: params.env,
|
|
64
60
|
contextKey,
|
|
@@ -80,10 +76,8 @@ export async function persistObjectResultFromStoryStep(params) {
|
|
|
80
76
|
const err = patchResult?.error ?? "Failed to persist object result";
|
|
81
77
|
throw new Error(err);
|
|
82
78
|
}
|
|
83
|
-
console.log("[ekairos/structure] persistObjectFromStory.step execute savedOk");
|
|
84
79
|
return { ok: true };
|
|
85
80
|
}
|
|
86
81
|
}
|
|
87
|
-
console.log("[ekairos/structure] persistObjectFromStory.step execute noJsonFound");
|
|
88
82
|
return { ok: false };
|
|
89
83
|
}
|
package/dist/structure.js
CHANGED
|
@@ -55,18 +55,11 @@ async function ensureSandboxPrepared(params) {
|
|
|
55
55
|
const workstation = getDatasetWorkstation(datasetId);
|
|
56
56
|
const outputPath = getDatasetOutputPath(datasetId);
|
|
57
57
|
if (state.initialized) {
|
|
58
|
-
console.log("[ekairos/structure] structure.ts ensureSandboxPrepared alreadyInitialized");
|
|
59
58
|
return { preparedSources: state.sources, workstation, outputPath };
|
|
60
59
|
}
|
|
61
|
-
console.log("[ekairos/structure] structure.ts ensureSandboxPrepared begin");
|
|
62
|
-
console.log("[ekairos/structure] structure.ts ensureSandboxPrepared datasetId", datasetId);
|
|
63
|
-
console.log("[ekairos/structure] structure.ts ensureSandboxPrepared sourcesCount", sources.length);
|
|
64
|
-
console.log("[ekairos/structure] structure.ts ensureSandboxPrepared sandbox.mkdir", workstation);
|
|
65
60
|
const mkdirRes = await runDatasetSandboxCommandStep({ env, sandboxId, cmd: "mkdir", args: ["-p", workstation] });
|
|
66
|
-
console.log("[ekairos/structure] structure.ts ensureSandboxPrepared sandbox.mkdir exitCode", mkdirRes.exitCode);
|
|
67
61
|
// Align with dataset sandbox behavior: install python deps up-front (once per dataset sandbox).
|
|
68
62
|
// This avoids tool-level "install if used" heuristics and ensures scripts can import pandas.
|
|
69
|
-
console.log("[ekairos/structure] structure.ts ensureSandboxPrepared installingPythonDeps pandas+openpyxl");
|
|
70
63
|
const pipInstall = await runDatasetSandboxCommandStep({
|
|
71
64
|
env,
|
|
72
65
|
sandboxId,
|
|
@@ -82,8 +75,6 @@ async function ensureSandboxPrepared(params) {
|
|
|
82
75
|
for (let i = 0; i < sources.length; i++) {
|
|
83
76
|
const src = sources[i];
|
|
84
77
|
if (src.kind === "file") {
|
|
85
|
-
console.log("[ekairos/structure] structure.ts ensureSandboxPrepared preparingFileSource");
|
|
86
|
-
console.log("[ekairos/structure] structure.ts ensureSandboxPrepared fileId", src.fileId);
|
|
87
78
|
const file = await readInstantFileStep({ env, fileId: src.fileId });
|
|
88
79
|
const fileName = String(file.contentDisposition ?? "");
|
|
89
80
|
const ext = fileName.includes(".") ? fileName.substring(fileName.lastIndexOf(".")) : "";
|
|
@@ -93,13 +84,10 @@ async function ensureSandboxPrepared(params) {
|
|
|
93
84
|
sandboxId,
|
|
94
85
|
files: [{ path, contentBase64: file.contentBase64 }],
|
|
95
86
|
});
|
|
96
|
-
console.log("[ekairos/structure] structure.ts ensureSandboxPrepared wroteFile path", path);
|
|
97
87
|
prepared.push({ kind: "file", id: src.fileId, path });
|
|
98
88
|
continue;
|
|
99
89
|
}
|
|
100
90
|
if (src.kind === "dataset") {
|
|
101
|
-
console.log("[ekairos/structure] structure.ts ensureSandboxPrepared preparingDatasetSource");
|
|
102
|
-
console.log("[ekairos/structure] structure.ts ensureSandboxPrepared sourceDatasetId", src.datasetId);
|
|
103
91
|
const content = await structureReadRowsOutputJsonlStep({ env, structureId: src.datasetId });
|
|
104
92
|
if (!content.ok) {
|
|
105
93
|
throw new Error(content.error);
|
|
@@ -110,38 +98,30 @@ async function ensureSandboxPrepared(params) {
|
|
|
110
98
|
sandboxId,
|
|
111
99
|
files: [{ path, contentBase64: content.data.contentBase64 }],
|
|
112
100
|
});
|
|
113
|
-
console.log("[ekairos/structure] structure.ts ensureSandboxPrepared wroteDatasetJsonl path", path);
|
|
114
101
|
prepared.push({ kind: "dataset", id: src.datasetId, path });
|
|
115
102
|
continue;
|
|
116
103
|
}
|
|
117
104
|
if (src.kind === "text") {
|
|
118
|
-
console.log("[ekairos/structure] structure.ts ensureSandboxPrepared preparingTextSource");
|
|
119
105
|
const ext = guessTextFileExtension(src.mimeType, src.name);
|
|
120
106
|
const textId = `text_${i}`;
|
|
121
107
|
const path = `${workstation}/${textId}${ext}`;
|
|
122
108
|
await writeDatasetSandboxTextFileStep({ env, sandboxId, path, text: String(src.text ?? "") });
|
|
123
|
-
console.log("[ekairos/structure] structure.ts ensureSandboxPrepared wroteText path", path);
|
|
124
109
|
prepared.push({ kind: "text", id: textId, path, name: src.name, mimeType: src.mimeType });
|
|
125
110
|
continue;
|
|
126
111
|
}
|
|
127
112
|
}
|
|
128
113
|
state.initialized = true;
|
|
129
114
|
state.sources = prepared;
|
|
130
|
-
console.log("[ekairos/structure] structure.ts ensureSandboxPrepared ok");
|
|
131
115
|
return { preparedSources: prepared, workstation, outputPath };
|
|
132
116
|
}
|
|
133
117
|
async function readSchemaFromSandboxIfPresent(params) {
|
|
134
118
|
const schemaPath = getDatasetOutputSchemaPath(params.datasetId);
|
|
135
|
-
console.log("[ekairos/structure] structure.ts readSchemaFromSandboxIfPresent begin");
|
|
136
|
-
console.log("[ekairos/structure] structure.ts readSchemaFromSandboxIfPresent datasetId", params.datasetId);
|
|
137
|
-
console.log("[ekairos/structure] structure.ts readSchemaFromSandboxIfPresent schemaPath", schemaPath);
|
|
138
119
|
const exists = await runDatasetSandboxCommandStep({
|
|
139
120
|
env: params.env,
|
|
140
121
|
sandboxId: params.sandboxId,
|
|
141
122
|
cmd: "test",
|
|
142
123
|
args: ["-f", schemaPath],
|
|
143
124
|
});
|
|
144
|
-
console.log("[ekairos/structure] structure.ts readSchemaFromSandboxIfPresent existsExitCode", exists.exitCode);
|
|
145
125
|
if (exists.exitCode !== 0)
|
|
146
126
|
return null;
|
|
147
127
|
const fileRead = await readDatasetSandboxFileStep({
|
|
@@ -160,11 +140,9 @@ async function readSchemaFromSandboxIfPresent(params) {
|
|
|
160
140
|
return null;
|
|
161
141
|
try {
|
|
162
142
|
const parsed = JSON.parse(jsonText);
|
|
163
|
-
console.log("[ekairos/structure] structure.ts readSchemaFromSandboxIfPresent parsedOk");
|
|
164
143
|
return parsed;
|
|
165
144
|
}
|
|
166
145
|
catch {
|
|
167
|
-
console.log("[ekairos/structure] structure.ts readSchemaFromSandboxIfPresent parsedFailed");
|
|
168
146
|
return null;
|
|
169
147
|
}
|
|
170
148
|
}
|
|
@@ -173,13 +151,11 @@ function createStructureStoryDefinition(config) {
|
|
|
173
151
|
const model = config.model ?? "openai/gpt-5.2";
|
|
174
152
|
const story = createStory("ekairos.structure")
|
|
175
153
|
.context(async (stored, env) => {
|
|
176
|
-
console.log("[ekairos/structure] structure.ts story.context begin");
|
|
177
154
|
const prev = stored?.content ?? {};
|
|
178
155
|
const sandboxState = prev.sandboxState ?? { initialized: false, sources: [] };
|
|
179
156
|
const existingSandboxId = prev.sandboxId ?? config.sandboxId ?? "";
|
|
180
157
|
let sandboxId = existingSandboxId;
|
|
181
158
|
if (!sandboxId) {
|
|
182
|
-
console.log("[ekairos/structure] structure.ts story.context creatingSandbox");
|
|
183
159
|
const created = await createDatasetSandboxStep({ env, runtime: "python3.13", timeoutMs: 10 * 60 * 1000 });
|
|
184
160
|
sandboxId = created.sandboxId;
|
|
185
161
|
}
|
|
@@ -191,7 +167,6 @@ function createStructureStoryDefinition(config) {
|
|
|
191
167
|
state: sandboxState,
|
|
192
168
|
});
|
|
193
169
|
if (config.mode === "schema" && config.outputSchema) {
|
|
194
|
-
console.log("[ekairos/structure] structure.ts story.context schemaMode outputSchemaProvided");
|
|
195
170
|
}
|
|
196
171
|
const promptContext = {
|
|
197
172
|
datasetId,
|
|
@@ -248,15 +223,12 @@ function createStructureStoryDefinition(config) {
|
|
|
248
223
|
};
|
|
249
224
|
})
|
|
250
225
|
.narrative(async (stored) => {
|
|
251
|
-
console.log("[ekairos/structure] structure.ts story.narrative begin");
|
|
252
226
|
const promptContext = stored?.content?.promptContext;
|
|
253
227
|
const base = buildStructurePrompt(promptContext);
|
|
254
228
|
const userInstructions = String(config.instructions ?? "").trim();
|
|
255
229
|
if (!userInstructions) {
|
|
256
|
-
console.log("[ekairos/structure] structure.ts story.narrative okNoUserInstructions");
|
|
257
230
|
return base;
|
|
258
231
|
}
|
|
259
|
-
console.log("[ekairos/structure] structure.ts story.narrative okWithUserInstructions");
|
|
260
232
|
return [
|
|
261
233
|
"## USER INSTRUCTIONS",
|
|
262
234
|
"The following instructions were provided by the user. Apply them in addition to (and with higher priority than) the default instructions.",
|
|
@@ -267,14 +239,10 @@ function createStructureStoryDefinition(config) {
|
|
|
267
239
|
].join("\n");
|
|
268
240
|
})
|
|
269
241
|
.actions(async (stored, env) => {
|
|
270
|
-
console.log("[ekairos/structure] structure.ts story.actions begin");
|
|
271
242
|
const sandboxId = stored?.content?.sandboxId;
|
|
272
243
|
const output = config.output;
|
|
273
244
|
const content = (stored?.content ?? {});
|
|
274
245
|
const hasOutputSchema = Boolean(content?.structure?.outputSchema?.schema);
|
|
275
|
-
console.log("[ekairos/structure] structure.ts story.actions datasetId", datasetId);
|
|
276
|
-
console.log("[ekairos/structure] structure.ts story.actions mode", config.mode);
|
|
277
|
-
console.log("[ekairos/structure] structure.ts story.actions hasOutputSchema", hasOutputSchema);
|
|
278
246
|
const actions = {
|
|
279
247
|
executeCommand: createExecuteCommandTool({ datasetId, sandboxId, env }),
|
|
280
248
|
clear: createClearDatasetTool({ datasetId, sandboxId, env }),
|
|
@@ -291,7 +259,6 @@ function createStructureStoryDefinition(config) {
|
|
|
291
259
|
? createCompleteRowsTool({ datasetId, sandboxId, env })
|
|
292
260
|
: createCompleteObjectTool({ datasetId, sandboxId, env });
|
|
293
261
|
}
|
|
294
|
-
console.log("[ekairos/structure] structure.ts story.actions ok");
|
|
295
262
|
return actions;
|
|
296
263
|
})
|
|
297
264
|
.shouldContinue(({ reactionEvent }) => {
|
|
@@ -336,11 +303,6 @@ export function structure(env, opts) {
|
|
|
336
303
|
return api;
|
|
337
304
|
},
|
|
338
305
|
async build(userPrompt) {
|
|
339
|
-
console.log("[ekairos/structure] structure.ts build begin");
|
|
340
|
-
console.log("[ekairos/structure] structure.ts build datasetId", datasetId);
|
|
341
|
-
console.log("[ekairos/structure] structure.ts build mode", mode);
|
|
342
|
-
console.log("[ekairos/structure] structure.ts build output", output);
|
|
343
|
-
console.log("[ekairos/structure] structure.ts build sourcesCount", sources.length);
|
|
344
306
|
// Guardrail: structure build MUST run inside workflow runtime ("use workflow").
|
|
345
307
|
const workflowMeta = assertRunningInsideWorkflow({ datasetId });
|
|
346
308
|
void workflowMeta?.workflowRunId;
|
|
@@ -364,22 +326,14 @@ export function structure(env, opts) {
|
|
|
364
326
|
};
|
|
365
327
|
}
|
|
366
328
|
async function runStory(evt) {
|
|
367
|
-
console.log("[ekairos/structure] structure.ts build storyReact begin");
|
|
368
|
-
console.log("[ekairos/structure] structure.ts build storyReact contextKey", contextKey);
|
|
369
|
-
console.log("[ekairos/structure] structure.ts build storyReact silent", true);
|
|
370
|
-
console.log("[ekairos/structure] structure.ts build storyReact eventId", evt?.id);
|
|
371
|
-
console.log("[ekairos/structure] structure.ts build storyReact eventType", evt?.type);
|
|
372
329
|
await story.react(evt, {
|
|
373
330
|
env,
|
|
374
331
|
context: { key: contextKey },
|
|
375
332
|
options: { silent: true, preventClose: true, sendFinish: false, maxIterations: 40, maxModelSteps: 10 },
|
|
376
333
|
});
|
|
377
|
-
console.log("[ekairos/structure] structure.ts build storyReact end");
|
|
378
334
|
// Tools are intentionally pure: persist completion outputs post-react by reading tool results from events.
|
|
379
335
|
const commit = await structureCommitFromEventsStep({ env, structureId: datasetId });
|
|
380
336
|
if (!commit.ok) {
|
|
381
|
-
console.log("[ekairos/structure] structure.ts build commitFromEvents failed");
|
|
382
|
-
console.log("[ekairos/structure] structure.ts build commitFromEvents error", commit.error);
|
|
383
337
|
}
|
|
384
338
|
}
|
|
385
339
|
async function getContextOrThrow() {
|
|
@@ -408,7 +362,6 @@ export function structure(env, opts) {
|
|
|
408
362
|
const content = (ctx?.content ?? {});
|
|
409
363
|
const hasSchema = Boolean(content?.structure?.outputSchema?.schema);
|
|
410
364
|
if (!hasSchema) {
|
|
411
|
-
console.log("[ekairos/structure] structure.ts build autoSchemaMissing followUp");
|
|
412
365
|
await runStory(makeUserMessageEvent([
|
|
413
366
|
"CRITICAL: You did not generate a schema yet.",
|
|
414
367
|
"1) Investigate Sources using executeCommand (inspect paths, read files, infer structure).",
|
|
@@ -419,38 +372,30 @@ export function structure(env, opts) {
|
|
|
419
372
|
}
|
|
420
373
|
}
|
|
421
374
|
const needsSecondPass = output === "rows" ? !(await isRowsCompleted()) : !isObjectCompleted(ctx);
|
|
422
|
-
console.log("[ekairos/structure] structure.ts build needsSecondPass", needsSecondPass);
|
|
423
375
|
if (needsSecondPass) {
|
|
424
|
-
console.log("[ekairos/structure] structure.ts build secondPass begin");
|
|
425
376
|
const followUpText = output === "rows"
|
|
426
377
|
? "Finalize now: write output.jsonl to OutputPath and call complete."
|
|
427
378
|
: "Finalize now: call complete with summary and resultJson (inline JSON).";
|
|
428
379
|
await runStory(makeUserMessageEvent(followUpText));
|
|
429
380
|
ctx = await getContextOrThrow();
|
|
430
|
-
console.log("[ekairos/structure] structure.ts build secondPass end");
|
|
431
381
|
}
|
|
432
382
|
const stillIncompleteAfterSecondPass = output === "rows" ? !(await isRowsCompleted()) : !isObjectCompleted(ctx);
|
|
433
383
|
if (stillIncompleteAfterSecondPass) {
|
|
434
|
-
console.log("[ekairos/structure] structure.ts build thirdPass begin");
|
|
435
384
|
const finalText = output === "rows"
|
|
436
385
|
? "CRITICAL: Do not do anything else. Ensure output.jsonl exists at OutputPath and immediately call complete."
|
|
437
386
|
: "CRITICAL: Do not do anything else. Immediately call complete with summary and resultJson (inline JSON).";
|
|
438
387
|
await runStory(makeUserMessageEvent(finalText));
|
|
439
388
|
ctx = await getContextOrThrow();
|
|
440
|
-
console.log("[ekairos/structure] structure.ts build thirdPass end");
|
|
441
389
|
}
|
|
442
390
|
if (output === "rows" && !(await isRowsCompleted())) {
|
|
443
391
|
throw new Error("Rows output not completed");
|
|
444
392
|
}
|
|
445
393
|
if (output === "object" && !isObjectCompleted(ctx)) {
|
|
446
|
-
console.log("[ekairos/structure] structure.ts build objectNotCompleted tryingPersistFallback");
|
|
447
394
|
const persisted = await persistObjectResultFromStoryStep({ env, datasetId });
|
|
448
395
|
if (persisted.ok) {
|
|
449
|
-
console.log("[ekairos/structure] structure.ts build persistFallback ok");
|
|
450
396
|
ctx = await getContextOrThrow();
|
|
451
397
|
}
|
|
452
398
|
else {
|
|
453
|
-
console.log("[ekairos/structure] structure.ts build persistFallback failed");
|
|
454
399
|
}
|
|
455
400
|
}
|
|
456
401
|
if (output === "object" && !isObjectCompleted(ctx)) {
|
|
@@ -518,7 +463,6 @@ export function structure(env, opts) {
|
|
|
518
463
|
};
|
|
519
464
|
},
|
|
520
465
|
};
|
|
521
|
-
console.log("[ekairos/structure] structure.ts build ok");
|
|
522
466
|
return output === "object" ? { datasetId, reader, dataset: ctx } : { datasetId, reader };
|
|
523
467
|
},
|
|
524
468
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ekairos/structure",
|
|
3
|
-
"version": "1.21.
|
|
3
|
+
"version": "1.21.71-beta.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,7 +36,7 @@
|
|
|
36
36
|
"typecheck": "tsc --noEmit"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@ekairos/domain": "^1.21.
|
|
39
|
+
"@ekairos/domain": "^1.21.71-beta.0",
|
|
40
40
|
"@ekairos/sandbox": "^1.21.60-beta.0",
|
|
41
41
|
"@instantdb/admin": "^0.22.13",
|
|
42
42
|
"@instantdb/core": "^0.22.13",
|