@usecontextlayer/cli 0.17.0 → 0.18.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/cli.mjs CHANGED
@@ -2,7 +2,7 @@
2
2
  import { a as login, i as listOrganizations, n as getAccessToken, r as getCurrentUser, t as LoginRequiredError } from "./auth-BL9AxZGb.mjs";
3
3
  import { a as boolean, c as literal, g as uuid, h as url, i as array, o as discriminatedUnion, p as string, r as _undefined, s as hostname, u as object } from "./schemas-D9UReYiT.mjs";
4
4
  import { a as databaseSlugSchema, l as secretNameSchema, n as env, s as resourcesForConsumer } from "./env-C_tllJ4u.mjs";
5
- import { a as noCommitSchema, c as execa, n as prepareLocalResourceConfiguration, o as slateResourceConfigurationSchema, r as saveLocalConnection, s as ownerSchema } from "./resources-BhJbHzU0.mjs";
5
+ import { a as noCommitSchema, c as execa, n as prepareLocalResourceConfiguration, o as slateResourceConfigurationSchema, r as saveLocalConnection, s as ownerSchema } from "./resources-0GJALfam.mjs";
6
6
  import { t as databaseQuerySchema } from "./databases-SvX3IgqC.mjs";
7
7
  import { readFile } from "node:fs/promises";
8
8
  import path, { join, resolve } from "node:path";
@@ -2971,15 +2971,15 @@ function useColor() {
2971
2971
  }
2972
2972
  new Command();
2973
2973
  //#endregion
2974
- //#region ../shared/dist/connections.mjs
2975
- const connectionSchema = object({
2974
+ //#region ../shared/dist/accounts.mjs
2975
+ const accountSchema = object({
2976
2976
  alias: string().nullable(),
2977
2977
  display_name: string().nullable(),
2978
2978
  id: string(),
2979
2979
  status: literal("ACTIVE"),
2980
2980
  toolkit: string()
2981
2981
  });
2982
- const connectionsSchema = object({ connections: array(connectionSchema) });
2982
+ const accountsSchema = object({ accounts: array(accountSchema) });
2983
2983
  //#endregion
2984
2984
  //#region owner.ts
2985
2985
  const ownerOptionsSchema = object({ org: string().min(1).optional() });
@@ -3003,7 +3003,7 @@ function ownerPath(owner) {
3003
3003
  async function connectAccount(toolkit, org) {
3004
3004
  const headers = { authorization: `Bearer ${await getAccessToken(env)}` };
3005
3005
  const owner = await resolveOwner(org, headers);
3006
- const response = await fetch(new URL(`/api/connections/${ownerPath(owner)}`, env.CTX_PLATFORM_URL), {
3006
+ const response = await fetch(new URL(`/api/accounts/${ownerPath(owner)}`, env.CTX_PLATFORM_URL), {
3007
3007
  body: JSON.stringify({ toolkit }),
3008
3008
  headers: {
3009
3009
  ...headers,
@@ -3016,19 +3016,19 @@ async function connectAccount(toolkit, org) {
3016
3016
  console.log(`Open this link to connect the Owner's account:\n${redirect_url}`);
3017
3017
  console.log("After connecting in your browser, assign the connected account to a slate's declared connection.");
3018
3018
  if (!org) console.log("From your checkout, assign your connected account to a connection declared in slate.json:\n npx @usecontextlayer/cli connections local assign <slug>");
3019
- console.log(`For a hosted slate, get the connected account ID and assign it:\n npx @usecontextlayer/cli accounts${org ? ` --org '${org.replaceAll("'", "'\\''")}'` : ""} list\n npx @usecontextlayer/cli connections <SlateID-or-hostname> assign <slug> <connection_id>`);
3019
+ console.log(`For a hosted slate, get the connected account ID and assign it:\n npx @usecontextlayer/cli accounts${org ? ` --org '${org.replaceAll("'", "'\\''")}'` : ""} list\n npx @usecontextlayer/cli connections <SlateID-or-hostname> assign <slug> <account_id>`);
3020
3020
  }
3021
3021
  async function listAccounts(org) {
3022
3022
  const headers = { authorization: `Bearer ${await getAccessToken(env)}` };
3023
3023
  const owner = await resolveOwner(org, headers);
3024
- const response = await fetch(new URL(`/api/connections/${ownerPath(owner)}`, env.CTX_PLATFORM_URL), { headers });
3024
+ const response = await fetch(new URL(`/api/accounts/${ownerPath(owner)}`, env.CTX_PLATFORM_URL), { headers });
3025
3025
  if (!response.ok) throw new Error(`Connected account list failed: HTTP ${response.status}`);
3026
- const { connections } = connectionsSchema.parse(await response.json());
3027
- if (connections.length === 0) {
3026
+ const { accounts } = accountsSchema.parse(await response.json());
3027
+ if (accounts.length === 0) {
3028
3028
  console.log("No connected accounts.");
3029
3029
  return;
3030
3030
  }
3031
- console.table(connections);
3031
+ console.table(accounts);
3032
3032
  }
3033
3033
  //#endregion
3034
3034
  //#region agents.ts
@@ -3050,7 +3050,7 @@ async function runLocalAgent(name, prompt) {
3050
3050
  name,
3051
3051
  type: "agent"
3052
3052
  });
3053
- const { openLocalDatabases } = await import("./local-databases-ChvVgJH6.mjs");
3053
+ const { openLocalDatabases } = await import("./local-databases-C5qUZcUH.mjs");
3054
3054
  const storage = await openLocalDatabases(bindings.workerName, configuration.databases);
3055
3055
  const { query, createSdkMcpServer, tool } = await import("@anthropic-ai/claude-agent-sdk");
3056
3056
  const run = query({
@@ -3952,58 +3952,58 @@ const slateConnectionsSchema = object({ connections: array(slateConnectionSchema
3952
3952
  //#endregion
3953
3953
  //#region connections.ts
3954
3954
  const connectionsCommandSchema = discriminatedUnion("operation", [object({
3955
- connection_id: _undefined(),
3955
+ account_id: _undefined(),
3956
3956
  operation: literal("list"),
3957
3957
  slug: _undefined(),
3958
3958
  target: string().min(1)
3959
3959
  }), object({
3960
- connection_id: string().min(1).optional(),
3960
+ account_id: string().min(1).optional(),
3961
3961
  operation: literal("assign"),
3962
3962
  slug: string().min(1),
3963
3963
  target: string().min(1)
3964
3964
  }).superRefine((input, ctx) => {
3965
- if (input.target !== "local" && input.connection_id === void 0) ctx.addIssue({
3965
+ if (input.target !== "local" && input.account_id === void 0) ctx.addIssue({
3966
3966
  code: "custom",
3967
- message: "Hosted assignment requires a connection ID",
3968
- path: ["connection_id"]
3967
+ message: "Hosted assignment requires an account ID",
3968
+ path: ["account_id"]
3969
3969
  });
3970
3970
  })]);
3971
- async function assignSlateConnection(target, slug, connectionId) {
3971
+ async function assignSlateConnection(target, slug, accountId) {
3972
3972
  if (target === "local") {
3973
3973
  const configuration = await prepareLocalResourceConfiguration();
3974
3974
  const requirement = new Map(Object.entries(configuration.connections)).get(slug);
3975
3975
  if (!requirement) throw new Error(`No local connection requirement for "${slug}"`);
3976
- if (connectionId === void 0 && !process.stdin.isTTY) throw new Error("Supply a connection ID when assigning without a terminal");
3977
- const url = new URL("/api/connections", env.CTX_PLATFORM_URL);
3976
+ if (accountId === void 0 && !process.stdin.isTTY) throw new Error("Supply an account ID when assigning without a terminal");
3977
+ const url = new URL("/api/accounts", env.CTX_PLATFORM_URL);
3978
3978
  url.searchParams.set("toolkit", requirement.toolkit);
3979
3979
  const response = await fetch(url, { headers: { authorization: `Bearer ${await getAccessToken(env)}` } });
3980
3980
  if (!response.ok) throw new Error(`Personal connected account list failed: HTTP ${response.status}`);
3981
- const { connections } = connectionsSchema.parse(await response.json());
3982
- if (connections.length === 0) throw new Error(`No personal connected accounts for ${requirement.toolkit}. Run npx @usecontextlayer/cli accounts add ${requirement.toolkit} to connect an account in your browser, then rerun this assignment.`);
3983
- if (connectionId === void 0) {
3984
- const accountId = await select({
3981
+ const { accounts } = accountsSchema.parse(await response.json());
3982
+ if (accounts.length === 0) throw new Error(`No personal connected accounts for ${requirement.toolkit}. Run npx @usecontextlayer/cli accounts add ${requirement.toolkit} to connect an account in your browser, then rerun this assignment.`);
3983
+ if (accountId === void 0) {
3984
+ const selectedAccountId = await select({
3985
3985
  message: `Assign a connected ${requirement.toolkit} account to ${slug}`,
3986
- options: connections.map((connection) => ({
3987
- label: `${connection.display_name ?? connection.alias ?? connection.id} (${connection.id}; ${connection.status})`,
3988
- value: connection.id
3986
+ options: accounts.map((account) => ({
3987
+ label: `${account.display_name ?? account.alias ?? account.id} (${account.id}; ${account.status})`,
3988
+ value: account.id
3989
3989
  })),
3990
3990
  output: process.stderr
3991
3991
  });
3992
- if (isCancel(accountId)) {
3992
+ if (isCancel(selectedAccountId)) {
3993
3993
  process.exitCode = 130;
3994
3994
  return;
3995
3995
  }
3996
- connectionId = accountId;
3996
+ accountId = selectedAccountId;
3997
3997
  }
3998
- if (!connections.some(({ id }) => id === connectionId)) throw new Error(`Connected account ${connectionId} is not one of your connected ${requirement.toolkit} accounts`);
3999
- await saveLocalConnection(slug, connectionId);
4000
- console.log(`${slug} → ${connectionId}`);
3998
+ if (!accounts.some(({ id }) => id === accountId)) throw new Error(`Connected account ${accountId} is not one of your connected ${requirement.toolkit} accounts`);
3999
+ await saveLocalConnection(slug, accountId);
4000
+ console.log(`${slug} → ${accountId}`);
4001
4001
  console.log("Start or restart pnpm dev to use this assignment.");
4002
4002
  return;
4003
4003
  }
4004
4004
  const response = await fetch(new URL(`/api/slates/${encodeURIComponent(target)}/connections/assign`, env.CTX_PLATFORM_URL), {
4005
4005
  body: JSON.stringify({
4006
- connection_id: connectionId,
4006
+ account_id: accountId,
4007
4007
  slug
4008
4008
  }),
4009
4009
  headers: {
@@ -4015,10 +4015,10 @@ async function assignSlateConnection(target, slug, connectionId) {
4015
4015
  if (response.status === 409 && noCommitSchema.safeParse(await response.json()).success) throw new Error("Nothing has been pushed to this slate yet. Push to main before configuring hosted resources.");
4016
4016
  if (!response.ok) throw new Error(`Connection assignment failed: HTTP ${response.status}`);
4017
4017
  const assignment = object({
4018
- connection_id: string(),
4018
+ account_id: string(),
4019
4019
  slug: string()
4020
4020
  }).parse(await response.json());
4021
- console.log(`${assignment.slug} → ${assignment.connection_id}`);
4021
+ console.log(`${assignment.slug} → ${assignment.account_id}`);
4022
4022
  }
4023
4023
  async function prepareSlateConnections(target) {
4024
4024
  if (target === "local") {
@@ -4046,9 +4046,9 @@ async function listSlateConnections(target) {
4046
4046
  console.log("No connection requirements.");
4047
4047
  return;
4048
4048
  }
4049
- console.table(connections.map(({ connection_id, consumers, ...requirement }) => ({
4049
+ console.table(connections.map(({ account_id, consumers, ...requirement }) => ({
4050
4050
  ...requirement,
4051
- connected_account: connection_id ?? "unassigned",
4051
+ connected_account: account_id ?? "unassigned",
4052
4052
  consumers: consumers.map((consumer) => consumer.type === "app" ? "app" : `agent:${consumer.name}`).join(", ")
4053
4053
  })));
4054
4054
  }
@@ -4094,7 +4094,7 @@ async function gitCredential(operation) {
4094
4094
  }
4095
4095
  //#endregion
4096
4096
  //#region package.json
4097
- var version = "0.17.0";
4097
+ var version = "0.18.0";
4098
4098
  //#endregion
4099
4099
  //#region secrets.ts
4100
4100
  const secretOptionsSchema = ownerOptionsSchema.extend({ stdin: boolean().default(false) });
@@ -4267,13 +4267,13 @@ const accounts = program.command("accounts").description("Connect and list the s
4267
4267
  accounts.command("list").description("List the selected Owner's connected accounts with their toolkit, identity, and status").action(async (_options, command) => {
4268
4268
  await listAccounts(ownerOptionsSchema.parse(command.optsWithGlobals()).org);
4269
4269
  });
4270
- accounts.command("add <toolkit>").description("Connect the selected Owner's account in your browser (for example, gmail), then assign it with ctx connections <target> assign <slug> [connection_id]").action(async (toolkit, _options, command) => {
4270
+ accounts.command("add <toolkit>").description("Connect the selected Owner's account in your browser (for example, gmail), then assign it with ctx connections <target> assign <slug> [account_id]").action(async (toolkit, _options, command) => {
4271
4271
  const options = ownerOptionsSchema.parse(command.optsWithGlobals());
4272
4272
  await connectAccount(string().min(1).parse(toolkit), options.org);
4273
4273
  });
4274
- program.command("connections").description("List declared app and agent connections or assign connected accounts; local reads and saves checkout configuration, SlateID/hostname uses pushed declarations and hosted assignments").argument("<target>", "SlateID, public hostname, or local (run from the checkout root)").addArgument(new Argument("<operation>").choices(["list", "assign"])).argument("[slug]", "Required for assign: connection slug declared in slate.json (for example, work-email)").argument("[connection_id]", "For assign: connected account ID; omit locally to choose interactively; required for hosted targets").action(async (target, operation, slug, connectionId, _options, command) => {
4274
+ program.command("connections").description("List declared app and agent connections or assign connected accounts; local reads and saves checkout configuration, SlateID/hostname uses pushed declarations and hosted assignments").argument("<target>", "SlateID, public hostname, or local (run from the checkout root)").addArgument(new Argument("<operation>").choices(["list", "assign"])).argument("[slug]", "Required for assign: connection slug declared in slate.json (for example, work-email)").argument("[account_id]", "For assign: connected account ID; omit locally to choose interactively; required for hosted targets").action(async (target, operation, slug, accountId, _options, command) => {
4275
4275
  const parsed = connectionsCommandSchema.safeParse({
4276
- connection_id: connectionId,
4276
+ account_id: accountId,
4277
4277
  operation,
4278
4278
  slug,
4279
4279
  target
@@ -4286,7 +4286,7 @@ program.command("connections").description("List declared app and agent connecti
4286
4286
  await listSlateConnections(input.target);
4287
4287
  break;
4288
4288
  case "assign":
4289
- await assignSlateConnection(input.target, input.slug, input.connection_id);
4289
+ await assignSlateConnection(input.target, input.slug, input.account_id);
4290
4290
  break;
4291
4291
  default: throw new Error(`Unhandled connections operation: ${JSON.stringify(input)}`);
4292
4292
  }
@@ -4309,7 +4309,7 @@ secrets.command("drop").argument("<name>", "Secret name: uppercase letters, digi
4309
4309
  await dropSecret(secretNameSchema.parse(name), secretOptionsSchema.parse(command.optsWithGlobals()).org);
4310
4310
  });
4311
4311
  program.command("db.codegen").argument("<slug>", "Database declared in public/slate.json or agents/<name>/slate.json").description("Generate databases/<slug>/types.ts from the migrated local database").addHelpText("after", "\nRun from the slate root with pnpm dev running.\nApply migrations with pnpm exec kysely before generating types.\n\nExample:\n pnpm db.codegen notes").action(async (slug, _options, command) => {
4312
- const { generateDatabaseTypes } = await import("./database-codegen-C5TEhR5_.mjs");
4312
+ const { generateDatabaseTypes } = await import("./database-codegen-CxDtyvam.mjs");
4313
4313
  try {
4314
4314
  await generateDatabaseTypes(databaseSlugSchema.parse(slug));
4315
4315
  } catch (error) {