@exulu/backend 5.13.0 → 5.15.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/{chunk-RNZ4IDCT.js → chunk-KLPCQWM3.js} +74 -18
- package/dist/{chunk-4W3V7IHR.js → chunk-NBDSN45T.js} +22 -0
- package/dist/{chunk-URX7KJQV.js → chunk-S4UXKMN5.js} +3641 -1701
- package/dist/{convert-exulu-tools-to-ai-sdk-tools-IYEO2RV6.js → convert-exulu-tools-to-ai-sdk-tools-GLRM3PM6.js} +2 -2
- package/dist/doc_processor-SVOSOVOY.js +12 -0
- package/dist/index.cjs +3736 -1579
- package/dist/index.d.cts +91 -3
- package/dist/index.d.ts +91 -3
- package/dist/index.js +202 -196
- package/ee/invoke-skills/artifact-filter.test.ts +42 -1
- package/ee/invoke-skills/artifact-filter.ts +37 -0
- package/ee/invoke-skills/create-sandbox.env.test.ts +7 -1
- package/ee/invoke-skills/create-sandbox.readonly-skills.sandbox.test.ts +221 -0
- package/ee/invoke-skills/create-sandbox.readonly-skills.test.ts +290 -0
- package/ee/invoke-skills/create-sandbox.run-command.test.ts +135 -0
- package/ee/invoke-skills/create-sandbox.skill-actions.test.ts +176 -0
- package/ee/invoke-skills/create-sandbox.ts +268 -88
- package/ee/invoke-skills/safe-fs.test.ts +59 -1
- package/ee/invoke-skills/safe-fs.ts +61 -2
- package/ee/invoke-skills/skill-actions/load.test.ts +88 -0
- package/ee/invoke-skills/skill-actions/load.ts +107 -0
- package/ee/invoke-skills/skill-actions/schema.test.ts +72 -0
- package/ee/invoke-skills/skill-actions/schema.ts +97 -0
- package/ee/invoke-skills/skill-actions/tool.test.ts +464 -0
- package/ee/invoke-skills/skill-actions/tool.ts +415 -0
- package/ee/python/documents/processing/doc_processor.limits.test.ts +257 -0
- package/ee/python/documents/processing/doc_processor.progress.test.ts +151 -0
- package/ee/python/documents/processing/doc_processor.ts +115 -13
- package/ee/python/documents/processing/limits.test.ts +35 -0
- package/ee/python/documents/processing/limits.ts +54 -0
- package/package.json +2 -1
- package/dist/doc_processor-E5GCE2ZT.js +0 -10
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* runCommand: the programmatic runner used by skill actions. Real (direct-exec) sandbox,
|
|
3
|
+
* S3 mocked, persistence enabled (userId 7), same harness as create-sandbox.symlink.test.ts.
|
|
4
|
+
*/
|
|
5
|
+
jest.mock("@anthropic-ai/sandbox-runtime", () => ({
|
|
6
|
+
SandboxManager: {
|
|
7
|
+
initialize: jest.fn(async () => {}),
|
|
8
|
+
wrapWithSandbox: jest.fn(async (cmd: string) => cmd),
|
|
9
|
+
reset: jest.fn(async () => {}),
|
|
10
|
+
},
|
|
11
|
+
}));
|
|
12
|
+
jest.mock("@SRC/uppy/index.ts", () => ({
|
|
13
|
+
listS3ObjectsByPrefix: jest.fn(async () => []),
|
|
14
|
+
getS3ObjectBytes: jest.fn(),
|
|
15
|
+
uploadFile: jest.fn(async (_c: Buffer, key: string) => `bucket/user_7/${key}`),
|
|
16
|
+
getPresignedUrl: jest.fn(async () => "https://signed"),
|
|
17
|
+
}));
|
|
18
|
+
jest.mock("@SRC/postgres/client", () => ({
|
|
19
|
+
postgresClient: jest.fn(async () => ({ db: { from: () => ({ select: async () => [] }) } })),
|
|
20
|
+
}));
|
|
21
|
+
jest.mock("@SRC/exulu/system-dependencies.ts", () => ({ getNpmGlobalRoot: jest.fn(async () => null) }));
|
|
22
|
+
jest.mock("@SRC/utils/python-setup.ts", () => ({ getPythonVenvPath: () => undefined }));
|
|
23
|
+
|
|
24
|
+
import { realpathSync, existsSync } from "node:fs";
|
|
25
|
+
import { join } from "node:path";
|
|
26
|
+
import { uploadFile } from "@SRC/uppy/index.ts";
|
|
27
|
+
import { createSessionSandbox, type SessionSandboxHandle } from "./create-sandbox";
|
|
28
|
+
|
|
29
|
+
const upload = uploadFile as jest.Mock;
|
|
30
|
+
const config = { fileUploads: { s3Bucket: "bucket" } } as any;
|
|
31
|
+
let handle: SessionSandboxHandle;
|
|
32
|
+
|
|
33
|
+
beforeEach(async () => {
|
|
34
|
+
upload.mockClear();
|
|
35
|
+
jest.spyOn(console, "warn").mockImplementation(() => {});
|
|
36
|
+
jest.spyOn(console, "log").mockImplementation(() => {});
|
|
37
|
+
handle = await createSessionSandbox(
|
|
38
|
+
`jest-runcmd-${process.pid}-${Math.random().toString(36).slice(2)}`,
|
|
39
|
+
[],
|
|
40
|
+
config,
|
|
41
|
+
7,
|
|
42
|
+
undefined,
|
|
43
|
+
{ projectId: null },
|
|
44
|
+
);
|
|
45
|
+
});
|
|
46
|
+
afterEach(async () => {
|
|
47
|
+
await handle.cleanup();
|
|
48
|
+
jest.restoreAllMocks();
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
test("extraEnv reaches the command and does not leak into the next call", async () => {
|
|
52
|
+
const a = await handle.runCommand('printf %s "$EXULU_INPUTS_DIR"', { extraEnv: { EXULU_INPUTS_DIR: "/x" } });
|
|
53
|
+
expect(a.stdout.startsWith("/x")).toBe(true);
|
|
54
|
+
const b = await handle.runCommand('printf %s "${EXULU_INPUTS_DIR:-none}"');
|
|
55
|
+
expect(b.stdout.startsWith("none")).toBe(true);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
test("the command runs in the session directory and reports its exit code", async () => {
|
|
59
|
+
const r = await handle.runCommand("pwd; echo oops >&2; exit 3");
|
|
60
|
+
expect(realpathSync(r.stdout.trim().split("\n")[0]!)).toBe(realpathSync(handle.sessionDir));
|
|
61
|
+
expect(r.stderr).toContain("oops");
|
|
62
|
+
expect(r.exitCode).toBe(3);
|
|
63
|
+
expect(r.timedOut).toBe(false);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
test("timeout kills the whole process group", async () => {
|
|
67
|
+
const r = await handle.runCommand("sleep 5; echo done", { timeoutMs: 200 });
|
|
68
|
+
expect(r.timedOut).toBe(true);
|
|
69
|
+
expect(r.exitCode).toBe(124);
|
|
70
|
+
expect(r.stdout).not.toContain("done");
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
test("a file created by the command is mirrored, .exulu-inputs is not", async () => {
|
|
74
|
+
const r = await handle.runCommand(
|
|
75
|
+
"mkdir -p .exulu-inputs/r1 && echo x > .exulu-inputs/r1/a.json && echo y > out.txt",
|
|
76
|
+
);
|
|
77
|
+
expect(r.artifacts.map((a) => a.relativePath)).toEqual(["out.txt"]);
|
|
78
|
+
expect(r.stdout).toContain("[exulu-artifacts]");
|
|
79
|
+
expect(r.stdout).toContain("out.txt: https://signed");
|
|
80
|
+
expect(upload.mock.calls.map((c) => c[1] as string).some((k) => k.includes(".exulu-inputs"))).toBe(false);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
test("the bash tool still returns stdout, exit code and the artifacts block", async () => {
|
|
84
|
+
const r: any = await (handle.tools.bash as any).execute(
|
|
85
|
+
{ command: "echo hello; echo y > made.txt" },
|
|
86
|
+
{ toolCallId: "t", messages: [] },
|
|
87
|
+
);
|
|
88
|
+
expect(r.stdout).toContain("hello");
|
|
89
|
+
expect(r.exitCode).toBe(0);
|
|
90
|
+
expect(r.artifacts.map((a: any) => a.relativePath)).toEqual(["made.txt"]);
|
|
91
|
+
expect(r.stdout).toContain("[exulu-artifacts]");
|
|
92
|
+
expect(r.stdout).toContain("made.txt: https://signed");
|
|
93
|
+
expect(r.artifactsOmitted).toBeUndefined();
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
test("pwd prints the session dir", async () => {
|
|
97
|
+
const r = await handle.runCommand("pwd");
|
|
98
|
+
expect(realpathSync(r.stdout.trim())).toBe(realpathSync(handle.sessionDir));
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
test("the command gets the constructed env, not the backend's process.env (declared secret is stripped)", async () => {
|
|
102
|
+
process.env.POSTGRES_DB_PASSWORD = "leaked";
|
|
103
|
+
try {
|
|
104
|
+
const h2 = await createSessionSandbox(
|
|
105
|
+
`jest-runcmd-env-${process.pid}-${Math.random().toString(36).slice(2)}`,
|
|
106
|
+
[], config, 7, undefined, { projectId: null },
|
|
107
|
+
);
|
|
108
|
+
try {
|
|
109
|
+
const r = await h2.runCommand('printf %s "${POSTGRES_DB_PASSWORD:-none}"');
|
|
110
|
+
expect(r.stdout.startsWith("none")).toBe(true);
|
|
111
|
+
} finally {
|
|
112
|
+
await h2.cleanup();
|
|
113
|
+
}
|
|
114
|
+
} finally {
|
|
115
|
+
delete process.env.POSTGRES_DB_PASSWORD;
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
test("writeFile into .exulu-inputs is neither uploaded nor given a URL, but exists on disk", async () => {
|
|
120
|
+
const r: any = await (handle.tools.writeFile as any).execute(
|
|
121
|
+
{ path: ".exulu-inputs/r1/x.json", content: "{}" },
|
|
122
|
+
{ toolCallId: "t", messages: [] },
|
|
123
|
+
);
|
|
124
|
+
expect(upload).not.toHaveBeenCalled();
|
|
125
|
+
expect(r.url).toBeUndefined();
|
|
126
|
+
expect(existsSync(join(handle.sessionDir, ".exulu-inputs/r1/x.json"))).toBe(true);
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
test("a multi-byte character split across output chunks arrives intact", async () => {
|
|
130
|
+
// The first byte of "ä" (0xC3), a pause so the pipe delivers it as its own chunk, then 0xA4.
|
|
131
|
+
const r = await handle.runCommand("printf 'Gr\\303'; sleep 0.3; printf '\\244\\303'; sleep 0.3; printf '\\274'; printf '\\303' >&2; sleep 0.3; printf '\\266' >&2");
|
|
132
|
+
expect(r.stdout.startsWith("Gräü")).toBe(true);
|
|
133
|
+
expect(r.stderr).toBe("ö");
|
|
134
|
+
expect(r.stdout).not.toContain("�");
|
|
135
|
+
});
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Skill actions are pinned from the bytes downloaded from skill storage, never re-read from
|
|
3
|
+
* the session copy the agent can write. Real (direct-exec) sandbox, S3 mocked, no persistence.
|
|
4
|
+
*/
|
|
5
|
+
jest.mock("@anthropic-ai/sandbox-runtime", () => ({
|
|
6
|
+
SandboxManager: {
|
|
7
|
+
initialize: jest.fn(async () => {}),
|
|
8
|
+
wrapWithSandbox: jest.fn(async (cmd: string) => cmd),
|
|
9
|
+
reset: jest.fn(async () => {}),
|
|
10
|
+
},
|
|
11
|
+
}));
|
|
12
|
+
jest.mock("@SRC/uppy/index.ts", () => ({
|
|
13
|
+
listS3ObjectsByPrefix: jest.fn(),
|
|
14
|
+
getS3ObjectBytes: jest.fn(),
|
|
15
|
+
uploadFile: jest.fn(async (_c: Buffer, key: string) => `bucket/${key}`),
|
|
16
|
+
getPresignedUrl: jest.fn(async () => "https://signed"),
|
|
17
|
+
}));
|
|
18
|
+
jest.mock("@SRC/postgres/client", () => ({
|
|
19
|
+
postgresClient: jest.fn(async () => ({ db: { from: () => ({ select: async () => [] }) } })),
|
|
20
|
+
}));
|
|
21
|
+
jest.mock("@SRC/exulu/system-dependencies.ts", () => ({ getNpmGlobalRoot: jest.fn(async () => null) }));
|
|
22
|
+
jest.mock("@SRC/utils/python-setup.ts", () => ({ getPythonVenvPath: () => undefined }));
|
|
23
|
+
|
|
24
|
+
import { promises as fs } from "node:fs";
|
|
25
|
+
import { join } from "node:path";
|
|
26
|
+
import { getS3ObjectBytes, listS3ObjectsByPrefix } from "@SRC/uppy/index.ts";
|
|
27
|
+
import { createSessionSandbox, refreshSessionSkills, type SessionSandboxHandle, type SkillRef } from "./create-sandbox";
|
|
28
|
+
import { loadSkillActions } from "./skill-actions/load";
|
|
29
|
+
|
|
30
|
+
const config = { fileUploads: { s3Bucket: "bucket" } } as any;
|
|
31
|
+
|
|
32
|
+
const actionsYaml = (name: string, context = "deals") => `version: 1
|
|
33
|
+
actions:
|
|
34
|
+
${name}:
|
|
35
|
+
description: Does ${name}.
|
|
36
|
+
run: python3 "$EXULU_SKILL_DIR/run.py"
|
|
37
|
+
inputs:
|
|
38
|
+
deal:
|
|
39
|
+
type: item
|
|
40
|
+
context: ${context}
|
|
41
|
+
`;
|
|
42
|
+
|
|
43
|
+
/** S3 key -> bytes. Skill files live under skills/<id>/v<version>/. */
|
|
44
|
+
let store: Map<string, Buffer>;
|
|
45
|
+
const put = (skill: SkillRef, version: number, files: Record<string, string>) => {
|
|
46
|
+
for (const [rel, text] of Object.entries(files)) store.set(`skills/${skill.id}/v${version}/${rel}`, Buffer.from(text));
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
let sessionId: string;
|
|
50
|
+
let handle: SessionSandboxHandle | undefined;
|
|
51
|
+
const turn = async (skills: SkillRef[]) => {
|
|
52
|
+
handle = await createSessionSandbox(sessionId, skills, config, undefined, undefined, { projectId: null });
|
|
53
|
+
return handle;
|
|
54
|
+
};
|
|
55
|
+
const actionsOf = (h: SessionSandboxHandle, skills: SkillRef[]) => loadSkillActions(h.sessionDir, skills, h.skillActions);
|
|
56
|
+
|
|
57
|
+
beforeEach(() => {
|
|
58
|
+
store = new Map();
|
|
59
|
+
(listS3ObjectsByPrefix as jest.Mock).mockImplementation(async (prefix: string) =>
|
|
60
|
+
[...store.keys()].filter((k) => k.startsWith(prefix)).map((key) => ({ key })),
|
|
61
|
+
);
|
|
62
|
+
(getS3ObjectBytes as jest.Mock).mockImplementation(async (key: string) => {
|
|
63
|
+
const bytes = store.get(key);
|
|
64
|
+
if (!bytes) throw new Error(`no object ${key}`);
|
|
65
|
+
return bytes;
|
|
66
|
+
});
|
|
67
|
+
jest.spyOn(console, "warn").mockImplementation(() => {});
|
|
68
|
+
jest.spyOn(console, "log").mockImplementation(() => {});
|
|
69
|
+
sessionId = `jest-skillactions-${process.pid}-${Math.random().toString(36).slice(2)}`;
|
|
70
|
+
handle = undefined;
|
|
71
|
+
});
|
|
72
|
+
afterEach(async () => {
|
|
73
|
+
await handle?.cleanup();
|
|
74
|
+
jest.restoreAllMocks();
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
const plain: SkillRef = { id: "s-plain", name: "plain", s3folder: "skills/s-plain", current_version: 1 };
|
|
78
|
+
const exporter: SkillRef = { id: "s-export", name: "exporter", s3folder: "skills/s-export", current_version: 1 };
|
|
79
|
+
|
|
80
|
+
test("an actions.yaml written into the session copy after download adds no action", async () => {
|
|
81
|
+
put(plain, 1, { "SKILL.md": "# plain" });
|
|
82
|
+
const h = await turn([plain]);
|
|
83
|
+
const file = join(h.sessionDir, "skills", "plain", "actions.yaml");
|
|
84
|
+
await fs.writeFile(file, actionsYaml("steal", "secrets"));
|
|
85
|
+
// The agent's own writeFile refuses the path (skills/ is read-only in a session);
|
|
86
|
+
// the direct write above stands in for degraded mode, where bash can still write it.
|
|
87
|
+
await expect(
|
|
88
|
+
(h.tools.writeFile as any).execute(
|
|
89
|
+
{ path: "skills/plain/actions.yaml", content: actionsYaml("steal", "secrets") },
|
|
90
|
+
{ toolCallId: "t", messages: [] },
|
|
91
|
+
),
|
|
92
|
+
).rejects.toThrow(/read-only/);
|
|
93
|
+
const next = await turn([plain]); // cache hit, same version: nothing is re-downloaded
|
|
94
|
+
expect(next).toBe(h);
|
|
95
|
+
expect(await fs.readFile(file, "utf8")).toContain("steal");
|
|
96
|
+
expect(actionsOf(next, [plain])).toEqual({ bySkill: {}, problems: [] });
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
test("modifying, replacing with a link or deleting the session copy leaves the pinned action intact", async () => {
|
|
100
|
+
put(exporter, 1, { "SKILL.md": "# exporter", "actions.yaml": actionsYaml("export") });
|
|
101
|
+
const h = await turn([exporter]);
|
|
102
|
+
const file = join(h.sessionDir, "skills", "exporter", "actions.yaml");
|
|
103
|
+
const expectPinned = async () => {
|
|
104
|
+
const loaded = actionsOf(await turn([exporter]), [exporter]);
|
|
105
|
+
expect(Object.keys(loaded.bySkill.exporter!.actions)).toEqual(["export"]);
|
|
106
|
+
expect(loaded.bySkill.exporter!.actions.export!.inputs.deal).toMatchObject({ context: "deals" });
|
|
107
|
+
expect(loaded.bySkill.exporter!.skillDir).toBe(join(h.sessionDir, "skills", "exporter"));
|
|
108
|
+
expect(loaded.problems).toEqual([]);
|
|
109
|
+
};
|
|
110
|
+
await expectPinned();
|
|
111
|
+
|
|
112
|
+
await fs.writeFile(file, actionsYaml("other", "secrets"));
|
|
113
|
+
await expectPinned();
|
|
114
|
+
|
|
115
|
+
await fs.rm(file);
|
|
116
|
+
const decoy = join(h.sessionDir, "decoy.yaml");
|
|
117
|
+
await fs.writeFile(decoy, actionsYaml("linked", "secrets"));
|
|
118
|
+
await fs.symlink(decoy, file);
|
|
119
|
+
await expectPinned();
|
|
120
|
+
|
|
121
|
+
await fs.rm(file);
|
|
122
|
+
await expectPinned();
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
test("a nested actions.yaml in the download declares nothing", async () => {
|
|
126
|
+
put(plain, 1, { "SKILL.md": "# plain", "scripts/actions.yaml": actionsYaml("nested") });
|
|
127
|
+
const h = await turn([plain]);
|
|
128
|
+
expect(actionsOf(h, [plain])).toEqual({ bySkill: {}, problems: [] });
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
test("a version change replaces the pinned declaration from the new bytes", async () => {
|
|
132
|
+
put(exporter, 1, { "actions.yaml": actionsYaml("export") });
|
|
133
|
+
put(exporter, 2, { "actions.yaml": actionsYaml("export_v2") });
|
|
134
|
+
put(exporter, 3, { "SKILL.md": "# no actions any more" });
|
|
135
|
+
await turn([exporter]);
|
|
136
|
+
|
|
137
|
+
const v2 = { ...exporter, current_version: 2 };
|
|
138
|
+
let loaded = actionsOf(await turn([v2]), [v2]);
|
|
139
|
+
expect(Object.keys(loaded.bySkill.exporter!.actions)).toEqual(["export_v2"]);
|
|
140
|
+
|
|
141
|
+
const v3 = { ...exporter, current_version: 3 };
|
|
142
|
+
loaded = actionsOf(await turn([v3]), [v3]);
|
|
143
|
+
expect(loaded).toEqual({ bySkill: {}, problems: [] });
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
test("reloading the skills re-pins from the re-downloaded bytes", async () => {
|
|
147
|
+
put(exporter, 1, { "actions.yaml": actionsYaml("export") });
|
|
148
|
+
const h = await turn([exporter]);
|
|
149
|
+
put(exporter, 1, { "actions.yaml": actionsYaml("reloaded") });
|
|
150
|
+
await fs.writeFile(join(h.sessionDir, "skills", "exporter", "actions.yaml"), actionsYaml("planted"));
|
|
151
|
+
expect(await refreshSessionSkills(sessionId, [exporter], config)).toEqual({ refreshed: 1, sandbox: true });
|
|
152
|
+
expect(Object.keys(actionsOf(h, [exporter]).bySkill.exporter!.actions)).toEqual(["reloaded"]);
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
test("a skill no longer enabled contributes no actions", async () => {
|
|
156
|
+
put(exporter, 1, { "actions.yaml": actionsYaml("export") });
|
|
157
|
+
put(plain, 1, { "SKILL.md": "# plain" });
|
|
158
|
+
await turn([exporter, plain]);
|
|
159
|
+
const h = await turn([plain]);
|
|
160
|
+
expect(actionsOf(h, [plain])).toEqual({ bySkill: {}, problems: [] });
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
test("an invalid downloaded actions.yaml yields a problem entry and no actions", async () => {
|
|
164
|
+
put(exporter, 1, { "actions.yaml": "version: 2\n" });
|
|
165
|
+
const h = await turn([exporter]);
|
|
166
|
+
const loaded = actionsOf(h, [exporter]);
|
|
167
|
+
expect(loaded.bySkill).toEqual({});
|
|
168
|
+
expect(loaded.problems).toEqual([{ skill: "exporter", error: expect.any(String) }]);
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
test("a skill with a path-like name and no actions.yaml yields no problem", async () => {
|
|
172
|
+
const odd: SkillRef = { id: "s-odd", name: "Vertrieb/Angebote", s3folder: "skills/s-odd", current_version: 1 };
|
|
173
|
+
put(odd, 1, { "SKILL.md": "# odd" });
|
|
174
|
+
const h = await turn([odd]);
|
|
175
|
+
expect(actionsOf(h, [odd])).toEqual({ bySkill: {}, problems: [] });
|
|
176
|
+
});
|