@orgsdk/cli 2.1.0 → 2.2.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.
Files changed (69) hide show
  1. package/dist/runtime/client.js +19 -0
  2. package/dist/runtime/contract.js +1 -0
  3. package/dist/runtime/plugins.js +16 -4
  4. package/dist/runtime/runner.js +16 -13
  5. package/dist/runtime/shell-policy.js +31 -0
  6. package/dist/server/{bun-driver-DTZUUCI3.js → bun-driver-UOZIWBHK.js} +1 -1
  7. package/dist/server/{chunk-S5SFX3JM.js → chunk-EXZNZYIJ.js} +13 -0
  8. package/dist/server/index.js +1075 -822
  9. package/dist/server/migrations/0004_shell_executable_policy.sql +9 -0
  10. package/dist/server/migrations/meta/0004_snapshot.json +3455 -0
  11. package/dist/server/migrations/meta/_journal.json +7 -0
  12. package/dist/server/{node-driver-HDJKKWXQ.js → node-driver-75PFAG2L.js} +1 -1
  13. package/dist/server/out/_next/static/chunks/0tlox6w8yf345.css +1 -0
  14. package/dist/server/out/accounts/2fa/__next._full.txt +2 -2
  15. package/dist/server/out/accounts/2fa/__next._tree.txt +2 -2
  16. package/dist/server/out/accounts/2fa/__next.accounts.2fa.__PAGE__.txt +2 -2
  17. package/dist/server/out/accounts/2fa/index.html +1 -1
  18. package/dist/server/out/accounts/2fa/index.txt +2 -2
  19. package/dist/server/out/accounts/email/__next._full.txt +2 -2
  20. package/dist/server/out/accounts/email/__next._tree.txt +2 -2
  21. package/dist/server/out/accounts/email/__next.accounts.email.__PAGE__.txt +2 -2
  22. package/dist/server/out/accounts/email/index.html +1 -1
  23. package/dist/server/out/accounts/email/index.txt +2 -2
  24. package/dist/server/out/accounts/login/__next._full.txt +2 -2
  25. package/dist/server/out/accounts/login/__next._tree.txt +2 -2
  26. package/dist/server/out/accounts/login/__next.accounts.login.__PAGE__.txt +2 -2
  27. package/dist/server/out/accounts/login/index.html +1 -1
  28. package/dist/server/out/accounts/login/index.txt +2 -2
  29. package/dist/server/out/accounts/logout/__next._full.txt +2 -2
  30. package/dist/server/out/accounts/logout/__next._tree.txt +2 -2
  31. package/dist/server/out/accounts/logout/__next.accounts.logout.__PAGE__.txt +2 -2
  32. package/dist/server/out/accounts/logout/index.html +1 -1
  33. package/dist/server/out/accounts/logout/index.txt +2 -2
  34. package/dist/server/out/accounts/password/change/__next._full.txt +2 -2
  35. package/dist/server/out/accounts/password/change/__next._tree.txt +2 -2
  36. package/dist/server/out/accounts/password/change/__next.accounts.password.change.__PAGE__.txt +2 -2
  37. package/dist/server/out/accounts/password/change/index.html +1 -1
  38. package/dist/server/out/accounts/password/change/index.txt +2 -2
  39. package/dist/server/out/accounts/password/reset/__next._full.txt +2 -2
  40. package/dist/server/out/accounts/password/reset/__next._tree.txt +2 -2
  41. package/dist/server/out/accounts/password/reset/__next.accounts.password.reset.__PAGE__.txt +2 -2
  42. package/dist/server/out/accounts/password/reset/index.html +1 -1
  43. package/dist/server/out/accounts/password/reset/index.txt +2 -2
  44. package/dist/server/out/accounts/signup/__next._full.txt +2 -2
  45. package/dist/server/out/accounts/signup/__next._tree.txt +2 -2
  46. package/dist/server/out/accounts/signup/__next.accounts.signup.__PAGE__.txt +2 -2
  47. package/dist/server/out/accounts/signup/index.html +1 -1
  48. package/dist/server/out/accounts/signup/index.txt +2 -2
  49. package/dist/server/out/setup/__next._full.txt +2 -2
  50. package/dist/server/out/setup/__next._tree.txt +2 -2
  51. package/dist/server/out/setup/__next.setup.__PAGE__.txt +2 -2
  52. package/dist/server/out/setup/index.html +1 -1
  53. package/dist/server/out/setup/index.txt +2 -2
  54. package/dist/server/out/studio/approve/__next._full.txt +2 -2
  55. package/dist/server/out/studio/approve/__next._tree.txt +2 -2
  56. package/dist/server/out/studio/approve/__next.studio.approve.__PAGE__.txt +2 -2
  57. package/dist/server/out/studio/approve/index.html +1 -1
  58. package/dist/server/out/studio/approve/index.txt +2 -2
  59. package/dist/server/out/workspaces/invite/__next._full.txt +2 -2
  60. package/dist/server/out/workspaces/invite/__next._tree.txt +2 -2
  61. package/dist/server/out/workspaces/invite/__next.workspaces.invite.__PAGE__.txt +2 -2
  62. package/dist/server/out/workspaces/invite/index.html +1 -1
  63. package/dist/server/out/workspaces/invite/index.txt +2 -2
  64. package/docs/studio.md +6 -0
  65. package/package.json +1 -1
  66. package/dist/server/out/_next/static/chunks/22w_ipn94al45.css +0 -1
  67. /package/dist/server/out/_next/static/{CkCrHy-m0W4Wo6_2T25_g → m1cOvyKRNnDjsWBMfcCJt}/_buildManifest.js +0 -0
  68. /package/dist/server/out/_next/static/{CkCrHy-m0W4Wo6_2T25_g → m1cOvyKRNnDjsWBMfcCJt}/_clientMiddlewareManifest.js +0 -0
  69. /package/dist/server/out/_next/static/{CkCrHy-m0W4Wo6_2T25_g → m1cOvyKRNnDjsWBMfcCJt}/_ssgManifest.js +0 -0
@@ -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/",
@@ -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(),
@@ -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 = snapshotContext(plugin, secret);
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(...await loadPlugin(plugin, client, agentId));
127
+ functions.push(
128
+ ...await loadPlugin(plugin, client, agentId, onApprovalWait)
129
+ );
118
130
  return functions;
119
131
  }
120
132
  export {
@@ -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
- source,
171
- { agent, stores: {}, actionRunner: {}, runId: this.job.run_id },
172
- {
173
- timeout: 3e5,
174
- parameters: inputs,
175
- signal: this.signal,
176
- onLog: (line) => enqueue("execution.log", { message: line }),
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
+ };
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  schema_exports
3
- } from "./chunk-S5SFX3JM.js";
3
+ } from "./chunk-EXZNZYIJ.js";
4
4
 
5
5
  // server/db/bun-driver.ts
6
6
  import { Database } from "bun:sqlite";
@@ -30,6 +30,7 @@ __export(schema_exports, {
30
30
  runs: () => runs,
31
31
  schedules: () => schedules,
32
32
  sessions: () => sessions,
33
+ shellRules: () => shellRules,
33
34
  tableRows: () => tableRows,
34
35
  users: () => users,
35
36
  webhookDeliveries: () => webhookDeliveries,
@@ -347,6 +348,7 @@ var approvals = sqliteTable4("approvals", {
347
348
  workspaceId: integer4("workspace_id").notNull().references(() => workspaces.id, { onDelete: "cascade" }),
348
349
  runId: text4("run_id").notNull().references(() => runs.id, { onDelete: "cascade" }),
349
350
  prompt: text4("prompt").notNull(),
351
+ shell: text4("shell", { mode: "json" }).$type(),
350
352
  status: text4("status").notNull().default(sql4`'pending'`),
351
353
  decidedBy: integer4("decided_by").references(() => users.id, {
352
354
  onDelete: "restrict"
@@ -593,6 +595,7 @@ import {
593
595
  import { sql as sql10 } from "drizzle-orm";
594
596
  import {
595
597
  integer as integer10,
598
+ primaryKey,
596
599
  sqliteTable as sqliteTable10,
597
600
  text as text10,
598
601
  uniqueIndex as uniqueIndex7
@@ -638,6 +641,15 @@ var credentials = sqliteTable10("credentials", {
638
641
  createdAt: text10("created_at").notNull(),
639
642
  updatedAt: text10("updated_at").notNull()
640
643
  });
644
+ var shellRules = sqliteTable10(
645
+ "shell_rules",
646
+ {
647
+ pluginId: text10("plugin_id").notNull().references(() => plugins.id, { onDelete: "cascade" }),
648
+ executable: text10("executable").notNull(),
649
+ decision: text10("decision", { enum: ["allow", "block"] }).notNull()
650
+ },
651
+ (table) => [primaryKey({ columns: [table.pluginId, table.executable] })]
652
+ );
641
653
 
642
654
  // server/db/schema/oauth.ts
643
655
  var oauthAttempts = sqliteTable11("oauth_attempts", {
@@ -703,6 +715,7 @@ export {
703
715
  authAttempts,
704
716
  plugins,
705
717
  credentials,
718
+ shellRules,
706
719
  oauthAttempts,
707
720
  mcpConnections,
708
721
  schema_exports