@orgsdk/executor 2.1.0 → 2.3.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/client.js +19 -0
- package/dist/contract.js +1 -0
- package/dist/plugins.js +16 -4
- package/dist/runner.js +16 -13
- package/dist/shell-policy.js +31 -0
- package/package.json +1 -1
package/dist/client.js
CHANGED
|
@@ -46,6 +46,25 @@ var Client = class {
|
|
|
46
46
|
result
|
|
47
47
|
);
|
|
48
48
|
}
|
|
49
|
+
shellRules(pluginId) {
|
|
50
|
+
return this.#request(
|
|
51
|
+
`/internal/execution/v1/product/shell/${identifier(pluginId)}/`,
|
|
52
|
+
"GET"
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
requestShellApproval(pluginId, executable, args) {
|
|
56
|
+
return this.#request(
|
|
57
|
+
`/internal/execution/v1/product/shell/${identifier(pluginId)}/`,
|
|
58
|
+
"POST",
|
|
59
|
+
{ executable, args }
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
shellApproval(pluginId, id) {
|
|
63
|
+
return this.#request(
|
|
64
|
+
`/internal/execution/v1/product/shell/${identifier(pluginId)}/${identifier(id)}/`,
|
|
65
|
+
"GET"
|
|
66
|
+
);
|
|
67
|
+
}
|
|
49
68
|
createApproval(input) {
|
|
50
69
|
return this.#request(
|
|
51
70
|
"/internal/execution/v1/product/approvals/",
|
package/dist/contract.js
CHANGED
|
@@ -8,6 +8,7 @@ import { connectionSchema } from "./mcp/contract.js";
|
|
|
8
8
|
var pluginSchema = z.object({
|
|
9
9
|
distribution: z.enum(["inline", "external", "mcp"]).optional(),
|
|
10
10
|
mcp: connectionSchema.optional(),
|
|
11
|
+
shell_policy_id: z.uuid().optional(),
|
|
11
12
|
package_url: z.string().optional(),
|
|
12
13
|
configuration: z.record(z.string(), z.unknown()).optional(),
|
|
13
14
|
credential_provider: z.string().nullable().optional(),
|
package/dist/plugins.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
// src/plugins.ts
|
|
2
|
+
import { shellPolicy } from "./shell-policy.js";
|
|
2
3
|
import { importPluginModule } from "./plugin-module.js";
|
|
3
4
|
import { z } from "zod";
|
|
4
5
|
import { installPlugin } from "./plugin-store.js";
|
|
@@ -79,14 +80,23 @@ function snapshotContext(plugin, secret) {
|
|
|
79
80
|
}
|
|
80
81
|
};
|
|
81
82
|
}
|
|
82
|
-
async function loadPlugin(plugin, client, agentId) {
|
|
83
|
+
async function loadPlugin(plugin, client, agentId, onApprovalWait) {
|
|
83
84
|
const file = await installPlugin(plugin, agentId, void 0, client.signal);
|
|
84
85
|
const secret = plugin.credential_id ? await client.secret(plugin.credential_id) : void 0;
|
|
85
86
|
if (secret?.source === "first-party")
|
|
86
87
|
throw new Error(
|
|
87
88
|
"Reconnect this credential using your own OAuth application; the former first-party relay is retired"
|
|
88
89
|
);
|
|
89
|
-
const context =
|
|
90
|
+
const context = {
|
|
91
|
+
...snapshotContext(plugin, secret),
|
|
92
|
+
...plugin.shell_policy_id && plugin.slug === "shell" && plugin.distribution === "external" ? {
|
|
93
|
+
shellPolicy: shellPolicy(
|
|
94
|
+
client,
|
|
95
|
+
plugin.shell_policy_id,
|
|
96
|
+
onApprovalWait
|
|
97
|
+
)
|
|
98
|
+
} : {}
|
|
99
|
+
};
|
|
90
100
|
const exports = await importPluginModule(
|
|
91
101
|
file,
|
|
92
102
|
plugin.distribution !== "external"
|
|
@@ -111,10 +121,12 @@ async function loadPlugin(plugin, client, agentId) {
|
|
|
111
121
|
};
|
|
112
122
|
});
|
|
113
123
|
}
|
|
114
|
-
async function loadPlugins(plugins, client, agentId) {
|
|
124
|
+
async function loadPlugins(plugins, client, agentId, onApprovalWait) {
|
|
115
125
|
const functions = [];
|
|
116
126
|
for (const plugin of plugins)
|
|
117
|
-
functions.push(
|
|
127
|
+
functions.push(
|
|
128
|
+
...await loadPlugin(plugin, client, agentId, onApprovalWait)
|
|
129
|
+
);
|
|
118
130
|
return functions;
|
|
119
131
|
}
|
|
120
132
|
export {
|
package/dist/runner.js
CHANGED
|
@@ -122,13 +122,20 @@ var Runner = class {
|
|
|
122
122
|
);
|
|
123
123
|
}
|
|
124
124
|
const executor = new SandboxExecutor();
|
|
125
|
+
const toolContext = {
|
|
126
|
+
agent,
|
|
127
|
+
stores: {},
|
|
128
|
+
actionRunner: {},
|
|
129
|
+
runId: this.job.run_id
|
|
130
|
+
};
|
|
125
131
|
executor.registerBuiltins(this.builtins());
|
|
126
132
|
const remote = agent.plugins.filter((plugin) => plugin.distribution === "mcp").map((plugin) => mcpPlugin(plugin, this.client, this.signal));
|
|
127
133
|
executor.registerMultiple(
|
|
128
134
|
await loadPlugins(
|
|
129
135
|
agent.plugins.filter((plugin) => plugin.distribution !== "mcp"),
|
|
130
136
|
this.client,
|
|
131
|
-
agent.id
|
|
137
|
+
agent.id,
|
|
138
|
+
() => toolContext.resetExecutionTimeout?.()
|
|
132
139
|
)
|
|
133
140
|
);
|
|
134
141
|
executor.registerMultiple(remote.flatMap((entry) => entry.functions));
|
|
@@ -166,18 +173,14 @@ var Runner = class {
|
|
|
166
173
|
append(kind, data);
|
|
167
174
|
};
|
|
168
175
|
try {
|
|
169
|
-
const result = await executor.execute(
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
onTraceTruncated: markTruncated,
|
|
178
|
-
onStep: (step) => enqueue("execution.step", step)
|
|
179
|
-
}
|
|
180
|
-
);
|
|
176
|
+
const result = await executor.execute(source, toolContext, {
|
|
177
|
+
timeout: 3e5,
|
|
178
|
+
parameters: inputs,
|
|
179
|
+
signal: this.signal,
|
|
180
|
+
onLog: (line) => enqueue("execution.log", { message: line }),
|
|
181
|
+
onTraceTruncated: markTruncated,
|
|
182
|
+
onStep: (step) => enqueue("execution.step", step)
|
|
183
|
+
});
|
|
181
184
|
enqueue("action.result", {
|
|
182
185
|
logs: result.logs,
|
|
183
186
|
steps: result.steps,
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// src/shell-policy.ts
|
|
2
|
+
import { setTimeout as sleep } from "node:timers/promises";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
var decision = z.discriminatedUnion("status", [
|
|
5
|
+
z.object({ status: z.literal("pending"), id: z.uuid() }),
|
|
6
|
+
z.object({ status: z.enum(["approved", "denied", "interrupted"]) })
|
|
7
|
+
]);
|
|
8
|
+
function shellPolicy(client, pluginId, onApprovalWait) {
|
|
9
|
+
return {
|
|
10
|
+
listAllowed: async () => z.array(z.string()).parse(await client.shellRules(pluginId)),
|
|
11
|
+
async authorize(executable, args) {
|
|
12
|
+
let result = decision.parse(
|
|
13
|
+
await client.requestShellApproval(pluginId, executable, args)
|
|
14
|
+
);
|
|
15
|
+
while (result.status === "pending") {
|
|
16
|
+
onApprovalWait?.();
|
|
17
|
+
await sleep(500, void 0, { signal: client.signal });
|
|
18
|
+
result = decision.parse(
|
|
19
|
+
await client.shellApproval(pluginId, result.id)
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
client.signal?.throwIfAborted();
|
|
23
|
+
if (result.status !== "approved") {
|
|
24
|
+
throw new Error("Shell execution blocked or interrupted.");
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
export {
|
|
30
|
+
shellPolicy
|
|
31
|
+
};
|
package/package.json
CHANGED