@usecontextlayer/cli 0.15.0 → 0.16.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.
@@ -1,13 +1,13 @@
1
- # ContextLayer app
1
+ # ContextLayer slate
2
2
 
3
- The interactive app declares resources in public/slate.json. Each agent declares its resources in agents/<name>/slate.json. All declarations share one namespace: matching database slugs select the same database, and repeated declarations must agree on owner/viewer mode. Connections and secrets follow the same namespace rule.
3
+ Follow ContextLayer's [domain model and resource invariants](https://github.com/usecontextlayer/contextlayer/blob/main/ARCHITECTURE.md#domain-model). Put the app's declaration in `public/slate.json`, agent declarations in `agents/<name>/slate.json`, and MCP declarations in `mcp/<name>/slate.json`. Declare each resource in every consumer that needs it. All declarations share one namespace: matching database slugs select the same database, and repeated declarations must agree on owner/viewer mode. Connections and secrets follow the same namespace rule. MCP declaration resource collections must currently be empty because MCP resource execution is not implemented.
4
4
 
5
5
  ## Databases and migrations
6
6
 
7
- Persistent app data belongs in declared SQLite databases. Each database keeps its Drizzle configuration, query schema and migration history under databases/<name>. The updates directory is an example; declare it in the relevant Slates to use it, or create the corresponding directory for your own database.
7
+ Keep persistent slate data in declared SQLite databases and treat agent filesystem files as scratch data. Keep each database's Drizzle configuration, query schema, and migration history under `databases/<slug>`. The `updates` directory is an example; declare it where needed or create the corresponding directory for another database.
8
8
 
9
- Write SQL migrations explicitly. Run pnpm db:migration --config databases/<name>/drizzle.config.ts --name <change> to scaffold a blank migration with Drizzle Kit's native metadata, then author its SQL. Separate statements with Drizzle's --> statement-breakpoint marker. Commit the SQL and generated metadata. Never generate migrations from schema changes, run drizzle-kit push, or change deployed schemas ad hoc. Update schema.ts for typed queries alongside the SQL; the schema does not create tables.
9
+ Write SQL migrations explicitly, following the [README workflow](README.md#store-slate-data). Separate statements with Drizzle's `--> statement-breakpoint` marker. Commit the SQL and generated metadata together. Never generate migrations from schema changes, run `drizzle-kit push`, or change deployed schemas ad hoc. Update `schema.ts` for typed queries alongside the SQL; the schema does not create tables.
10
10
 
11
- Platform applies pending migrations when publishing the app and when a member joins. Local Vite startup applies current-checkout migrations to ignored .contextlayer/databases before the app runs. Local agents use that same native local storage. Owner/viewer modes select hosted ownership; both use developer-local storage during development. No database selector or assignment is needed.
11
+ Preserve platform's [database ownership and provisioning boundary](https://github.com/usecontextlayer/contextlayer/blob/main/ARCHITECTURE.md#slate-databases-and-authored-migrations). Authored code names declared slugs; leave physical instances and credentials to ContextLayer.
12
12
 
13
- Loaders and actions receive the request-scoped databasesContext from @usecontextlayer/sdk. Use database(context.get(databasesContext), "updates", schema) for native Drizzle queries, or call the capability's query(slug, sql, params) for SQL. Import the query schema through the app’s @/databases alias. Authored code selects declared slugs; platform owns physical instances and credentials. Agent database_query writes persist immediately. Sandbox files are scratch data.
13
+ Use `databasesContext` from `@usecontextlayer/sdk` in loaders and actions, and `database_query` in agents. Import the query schema through the checkout's `@/databases` alias. The [SDK guide](https://www.npmjs.com/package/@usecontextlayer/sdk) documents the Drizzle and direct SQL APIs.
@@ -1,37 +1,39 @@
1
- # Your ContextLayer app
1
+ # Your ContextLayer slate
2
2
 
3
- This React Router app uses ContextLayer for connected services and is published through its Git remote.
3
+ This slate contains an interactive React Router app, uses ContextLayer for connected services, and is deployed through its Git remote.
4
+
5
+ See ContextLayer's [domain model](https://github.com/usecontextlayer/contextlayer/blob/main/ARCHITECTURE.md#domain-model) for declarations, resources, Owners, and assignments.
4
6
 
5
7
  ## Develop locally
6
8
 
7
- From this directory, run:
9
+ From the checkout root, run:
8
10
 
9
11
  ```sh
10
12
  pnpm dev
11
13
  ```
12
14
 
13
- Open the local URL printed by the development server. Edit `app/routes/home.tsx` to build your first page. Use `pnpm typecheck` and `pnpm build` for the app's normal TypeScript and production-build commands.
15
+ Open the local URL printed by the development server. Edit `app/routes/home.tsx` to build your first page. Use `pnpm typecheck` and `pnpm build` for the checkout's normal TypeScript and production-build commands.
14
16
 
15
17
  ## Use connected services
16
18
 
17
- Declare the services your app needs in `public/slate.json`. Authorization connects your account to ContextLayer; assignment binds that account to one of your app's declared connection slugs. Approve authorization in your browser, then use the local assignment chooser to select the account. An already connected account can go directly to assignment. Command help supplies the supported operations:
19
+ Declare the connections your app needs in `public/slate.json`. Connect an account to ContextLayer in your browser, then assign the connected account to one of your app's declared connections. An already connected account can go directly to assignment. Command help supplies the supported operations:
18
20
 
19
21
  ```sh
20
22
  npx @usecontextlayer/cli connections --help
21
23
  npx @usecontextlayer/cli connection --help
22
24
  ```
23
25
 
24
- The installed SDK guide at `node_modules/@usecontextlayer/sdk/README.md` gives the complete Gmail sequence: copy its route and declaration, authorize Gmail when needed, assign `work-email`, and start development. Local account choices are saved in ignored `.contextlayer/connections.json`. Restart `pnpm dev` after changing declarations or local assignments.
26
+ The installed SDK guide at `node_modules/@usecontextlayer/sdk/README.md` gives the complete Gmail sequence: copy its route and declaration, connect a Gmail account when needed, assign it to `work-email`, and start development. Local assignments are saved in ignored `.contextlayer/connections.json`. Restart `pnpm dev` after changing declarations or local assignments.
25
27
 
26
- ## Store app data
28
+ ## Store slate data
27
29
 
28
- Declare database slugs in `public/slate.json` or `agents/<name>/slate.json`. Matching declarations within this app share data; each declaration selects hosted `owner` or `viewer` mode. Local development persists SQLite state in ignored `.contextlayer/databases`.
30
+ Declare database slugs in `public/slate.json` or `agents/<name>/slate.json`, following the [resource invariants](https://github.com/usecontextlayer/contextlayer/blob/main/ARCHITECTURE.md#resource-configuration-and-execution--principles). Local development persists SQLite state in ignored `.contextlayer/databases`.
29
31
 
30
- Keep each database’s Drizzle configuration, query schema and migrations under `databases/<name>`. Run `pnpm db:migration --config databases/<name>/drizzle.config.ts --name <change>`, then write the blank SQL migration explicitly and update the query schema. Commit the SQL and native journal together. The query schema supplies types and does not generate the deployed database schema. The installed SDK guide documents `databasesContext` and the native Drizzle query client.
32
+ Keep each database’s Drizzle configuration, query schema and migrations under `databases/<slug>`. Run `pnpm db:migration --config databases/<slug>/drizzle.config.ts --name <change>`, then write the blank SQL migration explicitly and update the query schema. Commit the SQL and native journal together. The query schema supplies types and does not generate the deployed database schema. The installed SDK guide documents `databasesContext` and the native Drizzle query client.
31
33
 
32
- Local startup applies the checkout’s migrations before queries. Hosted publication applies pending committed migrations for existing members, and joining applies the full history for a new member. Viewer-mode hosted execution requires joining; account configuration is available before joining. Agent filesystem files are scratch; use `database_query` for persistent data.
34
+ Restart local development after adding a migration. Push committed migrations to `main` for hosted provisioning; see [database ownership and provisioning](https://github.com/usecontextlayer/contextlayer/blob/main/ARCHITECTURE.md#slate-databases-and-authored-migrations) for its lifecycle. Use `database_query` for persistent agent data.
33
35
 
34
- ## Publish
36
+ ## Deploy
35
37
 
36
38
  Commit your changes and push the generated `main` branch:
37
39
 
@@ -41,4 +43,4 @@ git commit
41
43
  git push -u origin main
42
44
  ```
43
45
 
44
- ContextLayer builds and deploys the app through its native Git remote. Your dashboard and hosted URL were printed by initialization. The hosted URL becomes usable after deployment succeeds. The app starts private; sign in with your ContextLayer account to open it. Hosted account selection uses the app's ContextLayer header.
46
+ ContextLayer builds and deploys the slate through its native Git remote. Your dashboard and hosted URL were printed by initialization. The hosted URL becomes usable after deployment succeeds. The slate starts private; sign in with your ContextLayer account to open it. Configure hosted assignments in the header of the [chrome](https://github.com/usecontextlayer/contextlayer/blob/main/ARCHITECTURE.md#slate-chrome).
@@ -11,25 +11,25 @@ export default function App() {
11
11
 
12
12
  export function ErrorBoundary({ error }: Route.ErrorBoundaryProps) {
13
13
  if (isRouteErrorResponse(error) && error.status === 409) {
14
- const setup = connectionRequiredSchema.safeParse(error.data)
15
- if (setup.success) {
14
+ const unassignedConnection = connectionRequiredSchema.safeParse(error.data)
15
+ if (unassignedConnection.success) {
16
16
  return (
17
17
  <main className="container mx-auto p-4 pt-16">
18
- <h1 className="text-2xl font-semibold">Connect an account to continue</h1>
18
+ <h1 className="text-2xl font-semibold">Assign an account to continue</h1>
19
19
  {import.meta.env.DEV ? (
20
20
  <>
21
21
  <p className="mt-3">
22
- From your app directory, assign an account, then restart{" "}
22
+ From the checkout root, assign a connected account, then restart{" "}
23
23
  <code>pnpm dev</code>:
24
24
  </p>
25
25
  <pre className="mt-4 overflow-x-auto">
26
- <code>{`npx @usecontextlayer/cli connection local assign ${setup.data.slug}`}</code>
26
+ <code>{`npx @usecontextlayer/cli connection local assign ${unassignedConnection.data.slug}`}</code>
27
27
  </pre>
28
28
  </>
29
29
  ) : (
30
30
  <p className="mt-3">
31
- Open the connections menu above and choose an account, then refresh this
32
- page.
31
+ Open the connections menu in the ContextLayer header above and assign a
32
+ connected account, then refresh this page.
33
33
  </p>
34
34
  )}
35
35
  </main>
@@ -1,22 +1,23 @@
1
1
  export function meta() {
2
- return [{ title: "Your ContextLayer app" }]
2
+ return [{ title: "Your ContextLayer slate" }]
3
3
  }
4
4
 
5
5
  export default function Home() {
6
6
  return (
7
7
  <main className="mx-auto max-w-2xl space-y-6 px-4 py-16">
8
- <h1 className="text-2xl font-semibold">Your ContextLayer app is ready</h1>
8
+ <h1 className="text-2xl font-semibold">Your ContextLayer slate is ready</h1>
9
9
  <p>
10
10
  Edit <code>app/routes/home.tsx</code> to build your first page.
11
11
  </p>
12
12
  <p>
13
- To read from a connected service, declare it in <code>public/slate.json</code>,
14
- assign your account through the CLI, and call its tools from a route loader.
15
- Follow the Gmail example in the SDK guide to get started.
13
+ To read from a connected service, declare a connection in{" "}
14
+ <code>public/slate.json</code>, assign a connected account through the CLI, and
15
+ call its tools from a route loader. Follow the Gmail example in the SDK guide to
16
+ get started.
16
17
  </p>
17
18
  <p>
18
- Your project&apos;s <code>README.md</code> explains development, connections, and
19
- publishing. The SDK guide is in{" "}
19
+ Your checkout&apos;s <code>README.md</code> explains development, connections, and
20
+ deployment. The SDK guide is in{" "}
20
21
  <code>node_modules/@usecontextlayer/sdk/README.md</code>.
21
22
  </p>
22
23
  </main>
@@ -1,6 +1,6 @@
1
- import { createApp, type McpToolModule } from "@usecontextlayer/sdk/worker"
1
+ import { createSlateWorker, type McpToolModule } from "@usecontextlayer/sdk/worker"
2
2
 
3
- export default createApp({
3
+ export default createSlateWorker({
4
4
  build: () => import("virtual:react-router/server-build"),
5
5
  development: import.meta.env.DEV,
6
6
  mcp: import.meta.glob<McpToolModule>("/mcp/*/index.ts", { eager: true }),
@@ -1 +1,6 @@
1
- export { AppDatabase, DatabaseSetup, Databases, Tools } from "@usecontextlayer/sdk/local"
1
+ export {
2
+ DatabaseProvisioning,
3
+ Databases,
4
+ SlateDatabase,
5
+ Tools,
6
+ } from "@usecontextlayer/sdk/local"
@@ -3,7 +3,7 @@
3
3
  "durable_objects": {
4
4
  "bindings": [
5
5
  {
6
- "class_name": "AppDatabase",
6
+ "class_name": "SlateDatabase",
7
7
  "name": "DATABASE_STORAGE"
8
8
  }
9
9
  ]
@@ -11,7 +11,7 @@
11
11
  "main": "index.ts",
12
12
  "migrations": [
13
13
  {
14
- "new_sqlite_classes": ["AppDatabase"],
14
+ "new_sqlite_classes": ["SlateDatabase"],
15
15
  "tag": "v1"
16
16
  }
17
17
  ],
package/dist/vite.d.mts CHANGED
@@ -4273,7 +4273,22 @@ declare namespace external_d_exports {
4273
4273
  export { $brand, $input, $output, BRAND, CompileOptions, GlobalMeta, INVALID, Infer, IssueData, JSONType, NEVER, $RefinementCtx as RefinementCtx, SafeExtendShape, Schema, TimePrecision, TypeOf, ZodAny, ZodArray, ZodBase64, ZodBase64URL, ZodBigInt, ZodBigIntFormat, ZodBoolean, ZodCIDRv4, ZodCIDRv6, ZodCUID, ZodCUID2, ZodCatch, ZodCodec, ZodCoercedBigInt, ZodCoercedBoolean, ZodCoercedDate, ZodCoercedNumber, ZodCoercedString, ZodCompileAsyncError, ZodCompileUnsupportedError, ZodCreditCard, ZodCustom, ZodCustomStringFormat, ZodDate, ZodDefault, ZodDiscriminatedUnion, ZodE164, ZodEmail, ZodEmoji, ZodEnum, ZodError, ZodErrorMap, ZodExactOptional, ZodFile, ZodFirstPartySchemaTypes, ZodFirstPartyTypeKind, ZodFlattenedError, ZodFloat32, ZodFloat64, ZodFormattedError, ZodFunction, ZodGUID, ZodIBAN, ZodIPv4, ZodIPv6, ZodISODate, ZodISODateTime, ZodISODuration, ZodISOTime, ZodInstanceOf, ZodInt, ZodInt32, ZodInt64, ZodIntersection, ZodIssue, ZodIssueCode, ZodJSONSchema, ZodJSONSchemaInternals, ZodJWT, ZodKSUID, ZodLazy, ZodLiteral, ZodMAC, ZodMap, ZodNaN, ZodNanoID, ZodNever, ZodNonOptional, ZodNull, ZodNullable, ZodNumber, ZodNumberFormat, ZodObject, ZodOptional, ZodPipe, ZodPrefault, ZodPreprocess, ZodPromise, ZodRawShape, ZodReadonly, ZodRealError, ZodRecord, ZodSafeParseError, ZodSafeParseResult, ZodSafeParseSuccess, ZodSchema, ZodSet, ZodStandardSchemaWithJSON, ZodString, ZodStringFormat, ZodSuccess, ZodSymbol, ZodTemplateLiteral, ZodTransform, ZodTuple, ZodType, ZodTypeAny, ZodUInt32, ZodUInt64, ZodULID, ZodURL, ZodUUID, ZodUndefined, ZodUnion, ZodUnknown, ZodVoid, ZodXID, ZodXor, _ZodBigInt, _ZodBoolean, _ZodDate, _ZodNumber, _ZodString, _ZodType, _default, _function, any, array, base64, base64url, bigint$1 as bigint, boolean$1 as boolean, _catch as catch, check, cidrv4, cidrv6, clone, codec, coerce_d_exports as coerce, compile, config, index_d_exports as core, creditCard, cuid, cuid2, currencyCode, custom, date$2 as date, decode, decodeAsync, deepPartial, describe, discriminatedUnion, e164, email, emoji, encode, encodeAsync, _endsWith as endsWith, _enum as enum, exactOptional, file, flattenError, float32, float64, formatError, fromJSONSchema, _function as function, getDiscriminatedOption, getErrorMap, globalRegistry, _gt as gt, _gte as gte, guid, hash, hex, hostname, httpUrl, iban, _includes as includes, output$1 as infer, inferFlattenedErrors, inferFormattedError, input, _instanceof as instanceof, int, int32, int64, intersection, invertCodec, ipv4, ipv6, iso_d_exports as iso, json, jwt, keyof, ksuid, lazy, _length as length, literal, index_d_exports$1 as locales, looseObject, looseRecord, _lowercase as lowercase, _lt as lt, _lte as lte, mac, map, _maxLength as maxLength, _maxSize as maxSize, memoizer, meta, _mime as mime, _minLength as minLength, _minSize as minSize, _multipleOf as multipleOf, nan, nanoid, nativeEnum, _negative as negative, never, _nonnegative as nonnegative, nonoptional, _nonpositive as nonpositive, _normalize as normalize, _null as null, nullable, nullish, number$1 as number, object, optional, output, _overwrite as overwrite, parse, parseAsync, partialRecord, pipe, _positive as positive, prefault, preprocess, prettifyError, promise, _properties as properties, _property as property, readonly, record, refine, _regex as regex, regexes_d_exports as regexes, registry, safeDecode, safeDecodeAsync, safeEncode, safeEncodeAsync, safeParse, safeParseAsync, set, setErrorMap, _size as size, _slugify as slugify, _startsWith as startsWith, strictObject, string$1 as string, stringFormat, stringbool, success, superRefine, symbol, templateLiteral, toJSONSchema, _toLowerCase as toLowerCase, _toUpperCase as toUpperCase, toZod, transform, treeifyError, _trim as trim, tuple, uint32, uint64, ulid, _undefined as undefined, union, unknown, _uppercase as uppercase, url, util_d_exports as util, uuid, uuidv4, uuidv6, uuidv7, validate, validateAsync, _void as void, withParser, xid, xor };
4274
4274
  }
4275
4275
  //#endregion
4276
- //#region ../shared/dist/app-resources-CJH87mYB.d.mts
4276
+ //#region ../shared/dist/databases.d.mts
4277
+ declare const sqlValueSchema: ZodUnion<readonly [ZodString, ZodNumber, ZodNull]>;
4278
+ type SqlValue = output$1<typeof sqlValueSchema>;
4279
+ declare const databaseResultSchema: ZodObject<{
4280
+ columns: ZodArray<ZodString>;
4281
+ rows: ZodArray<ZodArray<ZodUnion<readonly [ZodString, ZodNumber, ZodNull]>>>;
4282
+ rowsRead: ZodNumber;
4283
+ rowsWritten: ZodNumber;
4284
+ }, $strip>;
4285
+ type DatabaseResult = output$1<typeof databaseResultSchema>;
4286
+ interface Databases {
4287
+ query(slug: string, sql: string, params?: SqlValue[]): Promise<DatabaseResult>;
4288
+ }
4289
+ //#endregion
4290
+ //#endregion
4291
+ //#region ../shared/dist/slate-resources-zjMlTUWg.d.mts
4277
4292
  declare const localResourceConfigurationSchema: ZodObject<{
4278
4293
  connections: ZodRecord<ZodString, ZodObject<{
4279
4294
  mode: ZodEnum<{
@@ -4329,23 +4344,8 @@ declare const localResourceConfigurationSchema: ZodObject<{
4329
4344
  }, $strict>;
4330
4345
  type LocalResourceConfiguration = output$1<typeof localResourceConfigurationSchema>;
4331
4346
  //#endregion
4332
- //#region ../shared/dist/databases.d.mts
4333
- declare const sqlValueSchema: ZodUnion<readonly [ZodString, ZodNumber, ZodNull]>;
4334
- type SqlValue = output$1<typeof sqlValueSchema>;
4335
- declare const databaseResultSchema: ZodObject<{
4336
- columns: ZodArray<ZodString>;
4337
- rows: ZodArray<ZodArray<ZodUnion<readonly [ZodString, ZodNumber, ZodNull]>>>;
4338
- rowsRead: ZodNumber;
4339
- rowsWritten: ZodNumber;
4340
- }, $strip>;
4341
- type DatabaseResult = output$1<typeof databaseResultSchema>;
4342
- interface Databases {
4343
- query(slug: string, sql: string, params?: SqlValue[]): Promise<DatabaseResult>;
4344
- }
4345
- //#endregion
4346
- //#endregion
4347
4347
  //#region vite.d.ts
4348
- export declare function localDatabaseSetup(bindings: Awaited<ReturnType<typeof getLocalResourcesBindings>>): Plugin;
4348
+ export declare function localDatabaseProvisioning(bindings: Awaited<ReturnType<typeof getLocalResourcesBindings>>): Plugin;
4349
4349
  export declare function getPreparedLocalBindings(server: ViteDevServer): Awaited<ReturnType<typeof getLocalResourcesBindings>>;
4350
4350
  export declare function getLocalResourcesBindings(): Promise<{
4351
4351
  configuration: {
@@ -4418,7 +4418,6 @@ export declare function getLocalResourcesBindings(): Promise<{
4418
4418
  };
4419
4419
  };
4420
4420
  props: {
4421
- appId: string;
4422
4421
  connections: {
4423
4422
  [k: string]: {
4424
4423
  mode: "owner" | "viewer";
@@ -4436,6 +4435,7 @@ export declare function getLocalResourcesBindings(): Promise<{
4436
4435
  token: string;
4437
4436
  type: "access-token";
4438
4437
  };
4438
+ slateId: string;
4439
4439
  } | undefined;
4440
4440
  proxyConfigPath: string;
4441
4441
  vars: {
@@ -4447,6 +4447,6 @@ export declare function openLocalDatabases(workerName: string, databases: LocalR
4447
4447
  databases: Databases;
4448
4448
  dispose: PlatformProxy["dispose"];
4449
4449
  }>;
4450
- export declare function setupLocalDatabases(bindings: Awaited<ReturnType<typeof getLocalResourcesBindings>>): Promise<void>;
4450
+ export declare function provisionLocalDatabases(bindings: Awaited<ReturnType<typeof getLocalResourcesBindings>>): Promise<void>;
4451
4451
  //#endregion
4452
4452
  //# sourceMappingURL=vite.d.mts.map