@usecontextlayer/cli 0.14.3 → 0.15.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/README.md +36 -0
- package/dist/auth-CMrKVwsH.mjs +6847 -0
- package/dist/auth-CMrKVwsH.mjs.map +1 -0
- package/dist/auth.d.mts +23 -0
- package/dist/auth.d.mts.map +1 -0
- package/dist/auth.mjs +2 -0
- package/dist/cli.mjs +141 -38
- package/dist/cli.mjs.map +1 -1
- package/dist/{resources-DEdwfmku.mjs → resources-5FTDu19i.mjs} +152 -5619
- package/dist/resources-5FTDu19i.mjs.map +1 -0
- package/dist/rolldown-runtime-EAsCxrDo.mjs +14 -0
- package/dist/template/AGENTS.md +13 -0
- package/dist/template/README.md +44 -0
- package/dist/template/app/root.tsx +28 -0
- package/dist/template/app/routes/home.tsx +16 -3
- package/dist/template/databases/updates/drizzle.config.ts +8 -0
- package/dist/template/databases/updates/migrations/0000_create_updates.sql +6 -0
- package/dist/template/databases/updates/migrations/meta/0000_snapshot.json +14 -0
- package/dist/template/databases/updates/migrations/meta/_journal.json +13 -0
- package/dist/template/databases/updates/migrations/migrations.js +10 -0
- package/dist/template/databases/updates/schema.ts +8 -0
- package/dist/template/workers/app.ts +2 -1
- package/dist/template/workers/local-resources/index.ts +1 -0
- package/dist/template/workers/local-resources/wrangler.jsonc +19 -0
- package/dist/vite.d.mts +4426 -2
- package/dist/vite.d.mts.map +1 -1
- package/dist/vite.mjs +92 -8
- package/dist/vite.mjs.map +1 -1
- package/package.json +19 -3
- package/dist/resources-DEdwfmku.mjs.map +0 -1
- package/dist/template/workers/local-tools/index.ts +0 -1
- package/dist/template/workers/local-tools/wrangler.jsonc +0 -5
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
//#region \0rolldown/runtime.js
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __commonJSMin = (cb, mod) => () => (mod || (cb((mod = { exports: {} }).exports, mod), cb = null), mod.exports);
|
|
4
|
+
var __exportAll = (all, no_symbols) => {
|
|
5
|
+
let target = {};
|
|
6
|
+
for (var name in all) __defProp(target, name, {
|
|
7
|
+
get: all[name],
|
|
8
|
+
enumerable: true
|
|
9
|
+
});
|
|
10
|
+
if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
11
|
+
return target;
|
|
12
|
+
};
|
|
13
|
+
//#endregion
|
|
14
|
+
export { __exportAll as n, __commonJSMin as t };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# ContextLayer app
|
|
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.
|
|
4
|
+
|
|
5
|
+
## Databases and migrations
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# Your ContextLayer app
|
|
2
|
+
|
|
3
|
+
This React Router app uses ContextLayer for connected services and is published through its Git remote.
|
|
4
|
+
|
|
5
|
+
## Develop locally
|
|
6
|
+
|
|
7
|
+
From this directory, run:
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
pnpm dev
|
|
11
|
+
```
|
|
12
|
+
|
|
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.
|
|
14
|
+
|
|
15
|
+
## Use connected services
|
|
16
|
+
|
|
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:
|
|
18
|
+
|
|
19
|
+
```sh
|
|
20
|
+
npx @usecontextlayer/cli connections --help
|
|
21
|
+
npx @usecontextlayer/cli connection --help
|
|
22
|
+
```
|
|
23
|
+
|
|
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.
|
|
25
|
+
|
|
26
|
+
## Store app data
|
|
27
|
+
|
|
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`.
|
|
29
|
+
|
|
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.
|
|
31
|
+
|
|
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.
|
|
33
|
+
|
|
34
|
+
## Publish
|
|
35
|
+
|
|
36
|
+
Commit your changes and push the generated `main` branch:
|
|
37
|
+
|
|
38
|
+
```sh
|
|
39
|
+
git add .
|
|
40
|
+
git commit
|
|
41
|
+
git push -u origin main
|
|
42
|
+
```
|
|
43
|
+
|
|
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.
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { connectionRequiredSchema } from "@usecontextlayer/sdk"
|
|
1
2
|
import { isRouteErrorResponse, Outlet } from "react-router"
|
|
2
3
|
import type { Route } from "./+types/root"
|
|
3
4
|
import "~/app.css"
|
|
@@ -9,6 +10,33 @@ export default function App() {
|
|
|
9
10
|
}
|
|
10
11
|
|
|
11
12
|
export function ErrorBoundary({ error }: Route.ErrorBoundaryProps) {
|
|
13
|
+
if (isRouteErrorResponse(error) && error.status === 409) {
|
|
14
|
+
const setup = connectionRequiredSchema.safeParse(error.data)
|
|
15
|
+
if (setup.success) {
|
|
16
|
+
return (
|
|
17
|
+
<main className="container mx-auto p-4 pt-16">
|
|
18
|
+
<h1 className="text-2xl font-semibold">Connect an account to continue</h1>
|
|
19
|
+
{import.meta.env.DEV ? (
|
|
20
|
+
<>
|
|
21
|
+
<p className="mt-3">
|
|
22
|
+
From your app directory, assign an account, then restart{" "}
|
|
23
|
+
<code>pnpm dev</code>:
|
|
24
|
+
</p>
|
|
25
|
+
<pre className="mt-4 overflow-x-auto">
|
|
26
|
+
<code>{`npx @usecontextlayer/cli connection local assign ${setup.data.slug}`}</code>
|
|
27
|
+
</pre>
|
|
28
|
+
</>
|
|
29
|
+
) : (
|
|
30
|
+
<p className="mt-3">
|
|
31
|
+
Open the connections menu above and choose an account, then refresh this
|
|
32
|
+
page.
|
|
33
|
+
</p>
|
|
34
|
+
)}
|
|
35
|
+
</main>
|
|
36
|
+
)
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
12
40
|
let message = "Oops!"
|
|
13
41
|
let details = "An unexpected error occurred."
|
|
14
42
|
let stack: string | undefined
|
|
@@ -1,11 +1,24 @@
|
|
|
1
1
|
export function meta() {
|
|
2
|
-
return [{ title: "
|
|
2
|
+
return [{ title: "Your ContextLayer app" }]
|
|
3
3
|
}
|
|
4
4
|
|
|
5
5
|
export default function Home() {
|
|
6
6
|
return (
|
|
7
|
-
<main className="
|
|
8
|
-
<h1 className="text-2xl font-semibold">
|
|
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>
|
|
9
|
+
<p>
|
|
10
|
+
Edit <code>app/routes/home.tsx</code> to build your first page.
|
|
11
|
+
</p>
|
|
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.
|
|
16
|
+
</p>
|
|
17
|
+
<p>
|
|
18
|
+
Your project's <code>README.md</code> explains development, connections, and
|
|
19
|
+
publishing. The SDK guide is in{" "}
|
|
20
|
+
<code>node_modules/@usecontextlayer/sdk/README.md</code>.
|
|
21
|
+
</p>
|
|
9
22
|
</main>
|
|
10
23
|
)
|
|
11
24
|
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"_meta": {
|
|
3
|
+
"columns": {},
|
|
4
|
+
"schemas": {},
|
|
5
|
+
"tables": {}
|
|
6
|
+
},
|
|
7
|
+
"dialect": "sqlite",
|
|
8
|
+
"enums": {},
|
|
9
|
+
"id": "54e1d4df-48db-4b80-9190-11f5dbd99d64",
|
|
10
|
+
"prevId": "00000000-0000-0000-0000-000000000000",
|
|
11
|
+
"tables": {},
|
|
12
|
+
"version": "6",
|
|
13
|
+
"views": {}
|
|
14
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { integer, sqliteTable, text } from "drizzle-orm/sqlite-core"
|
|
2
|
+
|
|
3
|
+
export const updates = sqliteTable("updates", {
|
|
4
|
+
body: text("body").notNull(),
|
|
5
|
+
createdAt: integer("created_at").notNull(),
|
|
6
|
+
id: text("id").primaryKey(),
|
|
7
|
+
kind: text("kind").notNull(),
|
|
8
|
+
})
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { createApp } from "@usecontextlayer/sdk/worker"
|
|
1
|
+
import { createApp, type McpToolModule } from "@usecontextlayer/sdk/worker"
|
|
2
2
|
|
|
3
3
|
export default createApp({
|
|
4
4
|
build: () => import("virtual:react-router/server-build"),
|
|
5
5
|
development: import.meta.env.DEV,
|
|
6
|
+
mcp: import.meta.glob<McpToolModule>("/mcp/*/index.ts", { eager: true }),
|
|
6
7
|
mode: import.meta.env.MODE,
|
|
7
8
|
})
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { AppDatabase, DatabaseSetup, Databases, Tools } from "@usecontextlayer/sdk/local"
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compatibility_date": "2026-09-26",
|
|
3
|
+
"durable_objects": {
|
|
4
|
+
"bindings": [
|
|
5
|
+
{
|
|
6
|
+
"class_name": "AppDatabase",
|
|
7
|
+
"name": "DATABASE_STORAGE"
|
|
8
|
+
}
|
|
9
|
+
]
|
|
10
|
+
},
|
|
11
|
+
"main": "index.ts",
|
|
12
|
+
"migrations": [
|
|
13
|
+
{
|
|
14
|
+
"new_sqlite_classes": ["AppDatabase"],
|
|
15
|
+
"tag": "v1"
|
|
16
|
+
}
|
|
17
|
+
],
|
|
18
|
+
"name": "ctx-local-resources"
|
|
19
|
+
}
|