@opencomputer/cli 0.4.11 → 0.5.1

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/README.md CHANGED
@@ -50,6 +50,11 @@ Secret values are read from a hidden prompt, or from standard input in CI.
50
50
  They are write-only: list output contains names, scope, environment, and
51
51
  allowed origins, never values.
52
52
 
53
+ During development, put agent secrets in `opencomputer/.env.local`. The CLI
54
+ syncs only names referenced by `useSecret()` and limits each value to origins
55
+ declared by `defineConnection()`. It asks before the first upload, watches for
56
+ changes, and skips unrelated variables rather than granting wildcard access.
57
+
53
58
  ```bash
54
59
  # Project-level development secret. Allowed origins are inferred from code.
55
60
  opencomputer secrets set GITHUB_TOKEN
@@ -63,8 +68,8 @@ opencomputer secrets list --environment development
63
68
  opencomputer secrets remove GITHUB_TOKEN --environment development
64
69
  ```
65
70
 
66
- Agent code declares secret-backed destinations with `defineConnection()`,
67
- `useSecret()`, and `useConnection()`. Requests use the managed gateway, which
71
+ Agent code declares secret-backed destinations with `defineConnection()` and
72
+ `useSecret()`. Requests use the managed gateway, which
68
73
  injects a secret only for the declared origin, path, method, agent, and
69
74
  environment. The plaintext secret is not added to the deployment or runtime.
70
75
 
package/dist/api.d.ts CHANGED
@@ -35,32 +35,6 @@ export interface ManagedAgentDeployment {
35
35
  alias: string;
36
36
  createdAt: string;
37
37
  }
38
- export interface ManagedConnection {
39
- id: string;
40
- kind?: "channel" | "tool";
41
- provider: string;
42
- label: string;
43
- agentId?: string;
44
- alias?: string;
45
- externalAccountId?: string;
46
- displayName?: string;
47
- scopes?: string[];
48
- status: string;
49
- createdAt?: string;
50
- updatedAt?: string;
51
- }
52
- export interface ManagedSlackConnection {
53
- id: string;
54
- agentId: string;
55
- alias: string;
56
- appId?: string;
57
- teamId?: string;
58
- teamName?: string;
59
- botUserId?: string;
60
- status: string;
61
- createdAt: string;
62
- updatedAt: string;
63
- }
64
38
  export interface ManagedAgentEvent {
65
39
  id: string;
66
40
  seq: number;
@@ -185,6 +159,10 @@ export declare class OpenComputerClient {
185
159
  }>;
186
160
  methods?: string[];
187
161
  pathPrefix?: string;
162
+ redirectOrigins?: Array<{
163
+ origin: string;
164
+ pathPrefix?: string;
165
+ }>;
188
166
  }>;
189
167
  source: {
190
168
  digest: string;
@@ -193,43 +171,6 @@ export declare class OpenComputerClient {
193
171
  body: string;
194
172
  };
195
173
  }): Promise<ManagedAgentDeployment>;
196
- connections(): Promise<ManagedConnection[]>;
197
- disconnectConnection(connectionId: string): Promise<ManagedConnection>;
198
- linkManagedConnection(service: string, label: string): Promise<{
199
- connectionId: string;
200
- label: string;
201
- service: string;
202
- toolkit: string;
203
- status: "connected" | "pending";
204
- connectedAccountId?: string;
205
- authorizationUrl?: string;
206
- expiresAt?: string;
207
- }>;
208
- managedConnection(connectionId: string, service: string): Promise<{
209
- connectionId: string;
210
- label: string;
211
- service: string;
212
- toolkit: string;
213
- status: "connected" | "pending";
214
- connectedAccountId?: string;
215
- authorizationUrl?: string;
216
- expiresAt?: string;
217
- }>;
218
- disconnectManagedConnection(connectionId: string, service: string): Promise<{
219
- connectionId: string;
220
- label: string;
221
- service: string;
222
- toolkit: string;
223
- status: "disconnected";
224
- connectedAccountId?: string;
225
- }>;
226
- createSlackConnection(agentId: string): Promise<{
227
- connection: ManagedSlackConnection;
228
- webhookUrl: string;
229
- }>;
230
- channelConnections(): Promise<ManagedSlackConnection[]>;
231
- completeSlackConnection(connectionId: string, botToken: string): Promise<ManagedSlackConnection>;
232
- disconnectSlack(connectionId: string): Promise<ManagedSlackConnection>;
233
174
  createSession(agentId: string): Promise<CreateSessionResult>;
234
175
  sessions(): Promise<ManagedSessionSnapshot[]>;
235
176
  session(sessionId: string): Promise<ManagedSessionSnapshot>;
package/dist/api.js CHANGED
@@ -126,46 +126,6 @@ export class OpenComputerClient {
126
126
  registerDeployment(input) {
127
127
  return this.request("/api/managed-agents/deployments", { method: "POST", body: JSON.stringify(input) });
128
128
  }
129
- async connections() {
130
- const result = await this.request("/api/managed-agents/connections");
131
- return result.connections;
132
- }
133
- disconnectConnection(connectionId) {
134
- return this.request(`/api/managed-agents/connections/${encodeURIComponent(connectionId)}`, { method: "DELETE" });
135
- }
136
- linkManagedConnection(service, label) {
137
- return this.request("/api/managed-agents/connections/link", {
138
- method: "POST",
139
- body: JSON.stringify({ service, label }),
140
- });
141
- }
142
- managedConnection(connectionId, service) {
143
- const provider = service === "github" ? "github" : "google";
144
- return this.request(`/api/managed-agents/connections/${provider}/status?service=${encodeURIComponent(service)}&connectionId=${encodeURIComponent(connectionId)}`);
145
- }
146
- disconnectManagedConnection(connectionId, service) {
147
- const provider = service === "github" ? "github" : "google";
148
- return this.request(`/api/managed-agents/connections/${provider}?service=${encodeURIComponent(service)}&connectionId=${encodeURIComponent(connectionId)}`, { method: "DELETE" });
149
- }
150
- createSlackConnection(agentId) {
151
- return this.request("/api/managed-agents/channels/slack/connections", {
152
- method: "POST",
153
- body: JSON.stringify({ agentId }),
154
- });
155
- }
156
- async channelConnections() {
157
- const result = await this.request("/api/managed-agents/channels");
158
- return result.channels ?? result.connections ?? [];
159
- }
160
- completeSlackConnection(connectionId, botToken) {
161
- return this.request(`/api/managed-agents/channels/slack/connections/${encodeURIComponent(connectionId)}`, {
162
- method: "PUT",
163
- body: JSON.stringify({ botToken }),
164
- });
165
- }
166
- disconnectSlack(connectionId) {
167
- return this.request(`/api/managed-agents/channels/slack/connections/${encodeURIComponent(connectionId)}`, { method: "DELETE" });
168
- }
169
129
  createSession(agentId) {
170
130
  return this.request("/api/managed-agents/sessions", {
171
131
  method: "POST",
package/dist/api.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"api.js","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"AAuHA,MAAM,OAAO,QAAS,SAAQ,KAAK;IAGtB;IAFX,YACE,OAAe,EACN,MAAc;QAEvB,KAAK,CAAC,OAAO,CAAC,CAAC;QAFN,WAAM,GAAN,MAAM,CAAQ;IAGzB,CAAC;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EAAE,MAAM,EAAE,CACnB,CAAC;IACJ,CAAC;IAED,gBAAgB,CAAC,SAAiB;QAChC,OAAO,IAAI,CAAC,OAAO,CACjB,gCAAgC,kBAAkB,CAAC,SAAS,CAAC,YAAY,EACzE,EAAE,MAAM,EAAE,MAAM,EAAE,CACnB,CAAC;IACJ,CAAC;CACF"}
package/dist/commands.js CHANGED
@@ -1,12 +1,10 @@
1
- import { rm } from "node:fs/promises";
2
1
  import { OpenComputerClient, } from "./api.js";
3
- import { login, logout, openBrowser } from "./auth.js";
2
+ import { login, logout } from "./auth.js";
4
3
  import { resolveConfig } from "./config.js";
5
4
  import { runCloudDevelopment } from "./dev.js";
6
5
  import { ensureProjectBinding, findOpenComputerProjectRoot, } from "./binding.js";
7
6
  import { runLocalAgent } from "./local.js";
8
- import { addSlackChannel, assertStarterTarget, buildAgentArtifact, findAgentRoot, initializeAgentProject, readManifest, } from "./project.js";
9
- import { captureLocalSlackState, clearSlackState, readLocalSlackState, readRemoteSlackState, remoteSlackStatePath, requireSlackAgentRoot, runSlackCli, slackManifest, writeRemoteSlackState, } from "./slack.js";
7
+ import { assertStarterTarget, buildAgentArtifact, findAgentRoot, initializeAgentProject, readManifest, } from "./project.js";
10
8
  function printJSON(value) {
11
9
  process.stdout.write(`${JSON.stringify(value, null, 2)}\n`);
12
10
  }
@@ -124,35 +122,6 @@ async function requireAgentRoot() {
124
122
  }
125
123
  return root;
126
124
  }
127
- async function connectManagedService(client, service, label = "default") {
128
- const displayName = service === "calendar"
129
- ? "Google Calendar"
130
- : service === "github"
131
- ? "GitHub"
132
- : "Gmail";
133
- const started = await client.linkManagedConnection(service, label);
134
- if (started.status === "connected") {
135
- process.stdout.write(`${displayName} connection "${label}" is already connected.\n`);
136
- return;
137
- }
138
- if (!started.authorizationUrl) {
139
- throw new Error(`${displayName} did not return an authorization link.`);
140
- }
141
- process.stdout.write(`Authorize ${displayName}:\n${started.authorizationUrl}\n`);
142
- openBrowser(started.authorizationUrl);
143
- const deadline = started.expiresAt
144
- ? Date.parse(started.expiresAt)
145
- : Date.now() + 5 * 60_000;
146
- while (Date.now() < deadline) {
147
- await new Promise((resolve) => setTimeout(resolve, 1_500));
148
- if ((await client.managedConnection(started.connectionId, service)).status ===
149
- "connected") {
150
- process.stdout.write(`${displayName} connection "${label}" connected.\n`);
151
- return;
152
- }
153
- }
154
- throw new Error(`${displayName} authorization timed out.`);
155
- }
156
125
  async function inferAgentReference(alias) {
157
126
  const root = await findAgentRoot();
158
127
  if (!root)
@@ -545,7 +514,10 @@ export async function runCommand(command, rawArgs, globals) {
545
514
  const built = await buildAgentArtifact(await requireAgentRoot());
546
515
  allowedOrigins = built.httpConnections
547
516
  .filter((connection) => Object.values(connection.headers).some((value) => typeof value !== "string" && value.name === name))
548
- .map((connection) => connection.origin);
517
+ .flatMap((connection) => [
518
+ connection.origin,
519
+ ...(connection.redirectOrigins ?? []).map((redirect) => redirect.origin),
520
+ ]);
549
521
  }
550
522
  allowedOrigins = [...new Set(allowedOrigins)];
551
523
  if (!allowedOrigins.length) {
@@ -749,256 +721,6 @@ export async function runCommand(command, rawArgs, globals) {
749
721
  }
750
722
  return;
751
723
  }
752
- if (command === "connect") {
753
- const provider = args.shift();
754
- if ((provider !== "google" && provider !== "gmail") || args.length) {
755
- throw new Error("Usage: opencomputer connect google");
756
- }
757
- await connectManagedService(client, "gmail", "default");
758
- return;
759
- }
760
- if (command === "connection" || command === "connections") {
761
- const action = args.shift();
762
- if (action === "add" || action === "connect") {
763
- const provider = args.shift();
764
- const alias = option(args, "--alias") ?? "default";
765
- const service = provider === "google" ? "gmail" : provider;
766
- if ((service !== "gmail" &&
767
- service !== "calendar" &&
768
- service !== "github") ||
769
- args.length) {
770
- throw new Error("Usage: opencomputer connection add <gmail|calendar|github> [--alias <name>]");
771
- }
772
- await connectManagedService(client, service, alias);
773
- return;
774
- }
775
- if (action === "remove" || action === "disconnect") {
776
- const connectionReference = args.shift();
777
- if (!connectionReference || args.length) {
778
- throw new Error("Usage: opencomputer connection remove <alias|connection-id>");
779
- }
780
- const connections = await client.connections();
781
- const matches = connections.filter((connection) => connection.id === connectionReference ||
782
- connection.label === connectionReference);
783
- if (!matches.length) {
784
- throw new Error(`Connection "${connectionReference}" was not found.`);
785
- }
786
- if (matches.length > 1) {
787
- throw new Error(`More than one connection is named "${connectionReference}". Remove it by connection ID.`);
788
- }
789
- const connection = matches[0];
790
- const googleService = connection.scopes?.some((scope) => scope.includes("/auth/calendar"))
791
- ? "calendar"
792
- : "gmail";
793
- const managedService = connection.provider === "github" ? "github" : googleService;
794
- const disconnected = connection.provider === "google" || connection.provider === "github"
795
- ? await client.disconnectManagedConnection(connection.id, managedService)
796
- : await client.disconnectConnection(connection.id);
797
- if (globals.json)
798
- printJSON(disconnected);
799
- else
800
- process.stdout.write(`Removed connection "${connection.label}".\n`);
801
- return;
802
- }
803
- if (action !== "list" || args.length) {
804
- throw new Error("Use `opencomputer connection add`, `list`, or `remove`.");
805
- }
806
- const connections = await client.connections();
807
- if (globals.json)
808
- printJSON(connections);
809
- else if (!connections.length)
810
- process.stdout.write("No connections.\n");
811
- else {
812
- for (const connection of connections) {
813
- process.stdout.write(`${connection.id} ${connection.provider.padEnd(10)} ` +
814
- `${connection.status.padEnd(11)} ` +
815
- `${connection.label.padEnd(16)} ` +
816
- `${connection.displayName ?? ""}\n`);
817
- }
818
- }
819
- return;
820
- }
821
- if (command === "channels") {
822
- const action = args.shift();
823
- if (action === "add" || action === "connect") {
824
- throw new Error("Connect Slack from the deployed agent's Channels tab in the OpenComputer dashboard.");
825
- }
826
- if (action === "list") {
827
- const localOnly = flag(args, "--local");
828
- const remoteOnly = flag(args, "--remote");
829
- if (localOnly && remoteOnly) {
830
- throw new Error("Choose either --local or --remote.");
831
- }
832
- if (args.length)
833
- throw new Error(`Unexpected argument: ${args[0]}`);
834
- const root = await findAgentRoot();
835
- const localState = !remoteOnly && root ? await readLocalSlackState(root) : undefined;
836
- const remoteConnections = localOnly
837
- ? []
838
- : await client.channelConnections();
839
- if (globals.json) {
840
- printJSON({
841
- local: localState,
842
- remote: remoteConnections,
843
- });
844
- }
845
- else if (!localState && !remoteConnections.length) {
846
- process.stdout.write("No channel connections.\n");
847
- }
848
- else {
849
- if (localState) {
850
- process.stdout.write(`local slack connected ${localState.teamName ?? localState.teamId}\n`);
851
- }
852
- for (const connection of remoteConnections) {
853
- process.stdout.write(`${connection.id} slack ${connection.status.padEnd(12)} ` +
854
- `${connection.agentId}@${connection.alias} ` +
855
- `${connection.teamName ?? connection.teamId ?? "pending"}\n`);
856
- }
857
- }
858
- return;
859
- }
860
- const channel = args.shift();
861
- if (channel !== "slack") {
862
- throw new Error("Use `opencomputer channels add|connect|list|disconnect slack`.");
863
- }
864
- if (action === "add") {
865
- if (args.length)
866
- throw new Error(`Unexpected argument: ${args[0]}`);
867
- const root = await requireAgentRoot();
868
- const files = await addSlackChannel(root);
869
- await import("./slack.js").then(({ ensureSlackHooks }) => ensureSlackHooks(root));
870
- process.stdout.write(`${files.map((file) => `Created ${file}`).join("\n")}\n`);
871
- return;
872
- }
873
- if (action === "connect") {
874
- const local = flag(args, "--local");
875
- const remote = flag(args, "--remote");
876
- const agentOption = option(args, "--agent");
877
- const alias = option(args, "--alias") ?? "production";
878
- if (local === remote) {
879
- throw new Error("Choose exactly one of --local or --remote for Slack.");
880
- }
881
- if (args.length)
882
- throw new Error(`Unexpected argument: ${args[0]}`);
883
- const root = await requireSlackAgentRoot();
884
- if (local) {
885
- await runSlackCli(root, ["app", "install", "--environment", "local"], "local");
886
- const state = await captureLocalSlackState(root);
887
- process.stdout.write(`Connected local Slack app ${state.appId} to ` +
888
- `${state.teamName ?? state.teamId}.\n`);
889
- return;
890
- }
891
- const agent = agentOption ?? (await inferAgentReference(alias));
892
- if (!agent) {
893
- throw new Error("No agent repository found. Pass --agent <agent>@<alias>.");
894
- }
895
- const previous = await readRemoteSlackState(root);
896
- const started = await client.createSlackConnection(agent);
897
- await writeRemoteSlackState(root, {
898
- version: 1,
899
- connectionId: started.connection.id,
900
- agentId: `${started.connection.agentId}@${started.connection.alias}`,
901
- webhookUrl: started.webhookUrl,
902
- apiUrl: config.apiUrl,
903
- });
904
- try {
905
- await runSlackCli(root, ["deploy", "--app", "deployed"], "remote");
906
- const connected = (await client.channelConnections()).find((connection) => connection.id === started.connection.id);
907
- if (!connected || connected.status !== "connected") {
908
- throw new Error("Slack CLI finished without completing the connection.");
909
- }
910
- if (previous && previous.connectionId !== connected.id) {
911
- await client
912
- .disconnectSlack(previous.connectionId)
913
- .catch(() => undefined);
914
- }
915
- if (globals.json)
916
- printJSON(connected);
917
- else {
918
- process.stdout.write(`Connected ${connected.agentId}@${connected.alias} to ` +
919
- `${connected.teamName ?? connected.teamId ?? "Slack"}.\n`);
920
- }
921
- }
922
- catch (error) {
923
- await client
924
- .disconnectSlack(started.connection.id)
925
- .catch(() => undefined);
926
- if (previous)
927
- await writeRemoteSlackState(root, previous);
928
- else
929
- await rm(remoteSlackStatePath(root), { force: true });
930
- throw error;
931
- }
932
- return;
933
- }
934
- if (action === "disconnect") {
935
- const local = flag(args, "--local");
936
- const remote = flag(args, "--remote");
937
- const connectionId = args.shift();
938
- if (local && remote) {
939
- throw new Error("Choose either --local or --remote.");
940
- }
941
- if (args.length)
942
- throw new Error(`Unexpected argument: ${args[0]}`);
943
- const root = await requireSlackAgentRoot();
944
- if (local) {
945
- await runSlackCli(root, ["app", "uninstall", "--app", "local"], "local");
946
- await clearSlackState(root, "local");
947
- process.stdout.write("Disconnected the local Slack app.\n");
948
- return;
949
- }
950
- const stored = await readRemoteSlackState(root);
951
- const id = connectionId ?? stored?.connectionId;
952
- if (!id) {
953
- throw new Error("Pass a connection ID or connect Slack from this agent first.");
954
- }
955
- const disconnected = await client.disconnectSlack(id);
956
- if (stored?.connectionId === id) {
957
- await clearSlackState(root, "remote");
958
- }
959
- if (globals.json)
960
- printJSON(disconnected);
961
- else
962
- process.stdout.write(`Disconnected Slack connection ${id}.\n`);
963
- return;
964
- }
965
- throw new Error("Use `opencomputer channels add|connect|list|disconnect slack`.");
966
- }
967
- if (command === "slack-hook") {
968
- const action = args.shift();
969
- // Slack CLI app hooks append metadata such as --source=<directory>.
970
- // The hook already resolves its repository from the working directory,
971
- // so these Slack-owned arguments are intentionally ignored.
972
- const root = await requireSlackAgentRoot();
973
- const mode = process.env.OPENCOMPUTER_SLACK_MODE === "remote" ? "remote" : "local";
974
- if (action === "manifest") {
975
- printJSON(await slackManifest(root, mode));
976
- return;
977
- }
978
- if (action === "deploy") {
979
- const state = await readRemoteSlackState(root);
980
- if (!state) {
981
- throw new Error("Run `opencomputer channels connect slack --remote` first.");
982
- }
983
- const botToken = process.env.SLACK_BOT_TOKEN ?? process.env.SLACK_CLI_XOXB;
984
- if (!botToken) {
985
- throw new Error("Slack CLI did not provide SLACK_BOT_TOKEN.");
986
- }
987
- const hookConfig = await resolveConfig({
988
- ...globals,
989
- apiUrl: state.apiUrl,
990
- });
991
- const connection = await new OpenComputerClient(hookConfig).completeSlackConnection(state.connectionId, botToken);
992
- process.stdout.write(`OpenComputer connected ${connection.agentId}@${connection.alias} ` +
993
- `to ${connection.teamName ?? connection.teamId ?? "Slack"}.\n`);
994
- return;
995
- }
996
- if (action === "start") {
997
- await runLocalAgent(["dev"], config);
998
- return;
999
- }
1000
- throw new Error("Unsupported Slack CLI hook.");
1001
- }
1002
724
  throw new Error(`Unknown command: ${command}`);
1003
725
  }
1004
726
  //# sourceMappingURL=commands.js.map