@usecontextlayer/cli 0.16.1 → 0.17.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 +4 -4
- package/dist/auth-BL9AxZGb.mjs +1214 -0
- package/dist/auth-BL9AxZGb.mjs.map +1 -0
- package/dist/auth.d.mts +17 -2
- package/dist/auth.d.mts.map +1 -1
- package/dist/auth.mjs +1 -2
- package/dist/cli.mjs +153 -195
- package/dist/cli.mjs.map +1 -1
- package/dist/database-codegen-C5TEhR5_.mjs +24 -0
- package/dist/database-codegen-C5TEhR5_.mjs.map +1 -0
- package/dist/database-dialect-BLWWgYGo.mjs +56 -0
- package/dist/database-dialect-BLWWgYGo.mjs.map +1 -0
- package/dist/database.d.mts +35 -0
- package/dist/database.d.mts.map +1 -0
- package/dist/database.mjs +32 -0
- package/dist/database.mjs.map +1 -0
- package/dist/databases-SvX3IgqC.mjs +23 -0
- package/dist/databases-SvX3IgqC.mjs.map +1 -0
- package/dist/env-C_tllJ4u.mjs +98 -0
- package/dist/env-C_tllJ4u.mjs.map +1 -0
- package/dist/local-databases-ChvVgJH6.mjs +1 -0
- package/dist/local-databases-DVI3ngFq.mjs +53 -0
- package/dist/local-databases-DVI3ngFq.mjs.map +1 -0
- package/dist/{resources-B-EYHG1j.mjs → resources-BhJbHzU0.mjs} +24 -175
- package/dist/resources-BhJbHzU0.mjs.map +1 -0
- package/dist/{auth-DOsE8GwJ.mjs → schemas-D9UReYiT.mjs} +37 -1212
- package/dist/schemas-D9UReYiT.mjs.map +1 -0
- package/dist/schemas-DeaNWrS-.d.mts +2213 -0
- package/dist/schemas-DeaNWrS-.d.mts.map +1 -0
- package/dist/template.tar.gz +0 -0
- package/dist/vite.d.mts +5 -4330
- package/dist/vite.d.mts.map +1 -1
- package/dist/vite.mjs +16 -67
- package/dist/vite.mjs.map +1 -1
- package/package.json +12 -7
- package/dist/auth-DOsE8GwJ.mjs.map +0 -1
- package/dist/resources-B-EYHG1j.mjs.map +0 -1
- package/dist/rolldown-runtime-EAsCxrDo.mjs +0 -14
- package/dist/template/AGENTS.md +0 -13
- package/dist/template/README.md +0 -46
- package/dist/template/app/root.tsx +0 -66
- package/dist/template/app/routes/home.tsx +0 -25
- package/dist/template/databases/updates/drizzle.config.ts +0 -8
- package/dist/template/databases/updates/migrations/0000_create_updates.sql +0 -6
- package/dist/template/databases/updates/migrations/meta/0000_snapshot.json +0 -14
- package/dist/template/databases/updates/migrations/meta/_journal.json +0 -13
- package/dist/template/databases/updates/migrations/migrations.js +0 -10
- package/dist/template/databases/updates/schema.ts +0 -8
- package/dist/template/public/slate.json +0 -4
- package/dist/template/vite.config.ts +0 -9
- package/dist/template/workers/app.ts +0 -8
- package/dist/template/workers/local-resources/index.ts +0 -6
- package/dist/template/workers/local-resources/wrangler.jsonc +0 -19
|
@@ -1,21 +1,23 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { a as boolean, c as literal, d as record, g as uuid, o as discriminatedUnion, p as string, u as object } from "./schemas-D9UReYiT.mjs";
|
|
2
|
+
import { c as resourcesSchema, i as collectSlateResources, o as declarationSchema, r as readLocalSecret } from "./env-C_tllJ4u.mjs";
|
|
2
3
|
import { glob, mkdir, readFile, writeFile } from "node:fs/promises";
|
|
3
|
-
import { constants } from "node:os";
|
|
4
4
|
import path, { join, resolve } from "node:path";
|
|
5
|
+
import { fileURLToPath } from "node:url";
|
|
5
6
|
import { EventEmitter, addAbortListener, on, once, setMaxListeners } from "node:events";
|
|
6
7
|
import { ChildProcess, execFile, spawn, spawnSync } from "node:child_process";
|
|
7
8
|
import fs, { appendFileSync, closeSync, createReadStream, createWriteStream, openSync, readFileSync, readSync, statSync, writeFileSync } from "node:fs";
|
|
8
9
|
import process$1, { execArgv, execPath, hrtime, platform } from "node:process";
|
|
9
10
|
import { aborted, callbackify, debuglog, inspect, promisify, stripVTControlCharacters } from "node:util";
|
|
10
|
-
import { fileURLToPath } from "node:url";
|
|
11
11
|
import { StringDecoder } from "node:string_decoder";
|
|
12
12
|
import tty from "node:tty";
|
|
13
13
|
import { scheduler, setImmediate, setTimeout } from "node:timers/promises";
|
|
14
|
+
import { constants } from "node:os";
|
|
14
15
|
import { serialize } from "node:v8";
|
|
15
16
|
import { Buffer } from "node:buffer";
|
|
16
17
|
import { finished } from "node:stream/promises";
|
|
17
18
|
import { Duplex, PassThrough, Readable, Transform, Writable, getDefaultHighWaterMark } from "node:stream";
|
|
18
19
|
import path$1 from "node:path/win32";
|
|
20
|
+
import { createHash } from "node:crypto";
|
|
19
21
|
//#region ../../node_modules/.pnpm/is-plain-obj@4.1.0/node_modules/is-plain-obj/index.js
|
|
20
22
|
function isPlainObject(value) {
|
|
21
23
|
if (typeof value !== "object" || value === null) return false;
|
|
@@ -6350,132 +6352,6 @@ createExeca(mapNode);
|
|
|
6350
6352
|
createExeca(mapScriptAsync, {}, deepScriptOptions, setScriptSync);
|
|
6351
6353
|
const { sendMessage, getOneMessage, getEachMessage, getCancelSignal } = getIpcExport();
|
|
6352
6354
|
//#endregion
|
|
6353
|
-
//#region ../shared/dist/databases.mjs
|
|
6354
|
-
const databaseJournalSchema = object({ entries: array(object({
|
|
6355
|
-
breakpoints: boolean(),
|
|
6356
|
-
idx: number().int().nonnegative(),
|
|
6357
|
-
tag: string().min(1),
|
|
6358
|
-
when: number()
|
|
6359
|
-
})) });
|
|
6360
|
-
const databaseMigrationsSchema = object({
|
|
6361
|
-
journal: databaseJournalSchema,
|
|
6362
|
-
migrations: record(string(), string())
|
|
6363
|
-
});
|
|
6364
|
-
async function readDatabaseMigrations(slug, read) {
|
|
6365
|
-
const directory = `databases/${slug}/migrations`;
|
|
6366
|
-
const contents = await read(`${directory}/meta/_journal.json`);
|
|
6367
|
-
if (contents === null) return {
|
|
6368
|
-
journal: { entries: [] },
|
|
6369
|
-
migrations: {}
|
|
6370
|
-
};
|
|
6371
|
-
const journal = databaseJournalSchema.parse(JSON.parse(contents));
|
|
6372
|
-
const migrations = await Promise.all(journal.entries.map(async (entry) => {
|
|
6373
|
-
const sql = await read(`${directory}/${entry.tag}.sql`);
|
|
6374
|
-
if (sql === null) throw new Error(`Missing database migration: ${slug}/${entry.tag}.sql`);
|
|
6375
|
-
return [`m${entry.idx.toString().padStart(4, "0")}`, sql];
|
|
6376
|
-
}));
|
|
6377
|
-
return {
|
|
6378
|
-
journal,
|
|
6379
|
-
migrations: Object.fromEntries(migrations)
|
|
6380
|
-
};
|
|
6381
|
-
}
|
|
6382
|
-
const sqlValueSchema = union([
|
|
6383
|
-
string(),
|
|
6384
|
-
number(),
|
|
6385
|
-
_null()
|
|
6386
|
-
]);
|
|
6387
|
-
const databaseQuerySchema = strictObject({
|
|
6388
|
-
params: array(sqlValueSchema).default([]),
|
|
6389
|
-
slug: string().min(1),
|
|
6390
|
-
sql: string().min(1)
|
|
6391
|
-
});
|
|
6392
|
-
const databaseResultSchema = object({
|
|
6393
|
-
columns: array(string()),
|
|
6394
|
-
rows: array(array(sqlValueSchema)),
|
|
6395
|
-
rowsRead: number(),
|
|
6396
|
-
rowsWritten: number()
|
|
6397
|
-
});
|
|
6398
|
-
//#endregion
|
|
6399
|
-
//#region ../shared/dist/declaration.mjs
|
|
6400
|
-
const credentialModeSchema = _enum(["viewer", "owner"]);
|
|
6401
|
-
const connectionRequirementSchema = strictObject({
|
|
6402
|
-
mode: credentialModeSchema,
|
|
6403
|
-
toolkit: string().min(1)
|
|
6404
|
-
});
|
|
6405
|
-
const secretNameSchema = string().regex(/^[A-Z_][A-Z0-9_]*$/);
|
|
6406
|
-
const secretRequirementSchema = strictObject({ mode: credentialModeSchema });
|
|
6407
|
-
const databaseRequirementSchema = strictObject({ mode: credentialModeSchema });
|
|
6408
|
-
const databaseSlugSchema = string().min(1).regex(/^(?!\.{1,2}$)[^/\\]+$/);
|
|
6409
|
-
const declarationSchema = strictObject({
|
|
6410
|
-
connections: record(string().min(1), connectionRequirementSchema),
|
|
6411
|
-
databases: record(databaseSlugSchema, databaseRequirementSchema).default({}),
|
|
6412
|
-
secrets: record(secretNameSchema, secretRequirementSchema).default({})
|
|
6413
|
-
});
|
|
6414
|
-
strictObject({
|
|
6415
|
-
agents: record(string().min(1), declarationSchema),
|
|
6416
|
-
app: declarationSchema
|
|
6417
|
-
});
|
|
6418
|
-
const resourceConsumerSchema = discriminatedUnion("type", [strictObject({ type: literal("app") }), strictObject({
|
|
6419
|
-
name: string().min(1),
|
|
6420
|
-
type: literal("agent")
|
|
6421
|
-
})]);
|
|
6422
|
-
const resourcesSchema = declarationSchema.extend({
|
|
6423
|
-
connections: record(string().min(1), connectionRequirementSchema.extend({ consumers: array(resourceConsumerSchema) })),
|
|
6424
|
-
databases: record(databaseSlugSchema, databaseRequirementSchema.extend({ consumers: array(resourceConsumerSchema) })),
|
|
6425
|
-
secrets: record(secretNameSchema, secretRequirementSchema.extend({ consumers: array(resourceConsumerSchema) }))
|
|
6426
|
-
});
|
|
6427
|
-
function collectSlateResources(slateDeclarations) {
|
|
6428
|
-
const declarations = [{
|
|
6429
|
-
consumer: { type: "app" },
|
|
6430
|
-
declaration: slateDeclarations.app
|
|
6431
|
-
}, ...Object.entries(slateDeclarations.agents).map(([name, declaration]) => ({
|
|
6432
|
-
consumer: {
|
|
6433
|
-
name,
|
|
6434
|
-
type: "agent"
|
|
6435
|
-
},
|
|
6436
|
-
declaration
|
|
6437
|
-
}))];
|
|
6438
|
-
return {
|
|
6439
|
-
connections: collectRequirements("connections", declarations, (declaration) => declaration.connections),
|
|
6440
|
-
databases: collectRequirements("databases", declarations, (declaration) => declaration.databases),
|
|
6441
|
-
secrets: collectRequirements("secrets", declarations, (declaration) => declaration.secrets)
|
|
6442
|
-
};
|
|
6443
|
-
}
|
|
6444
|
-
function resourcesForConsumer(resources, consumer) {
|
|
6445
|
-
return {
|
|
6446
|
-
connections: filterRequirements(resources.connections, consumer),
|
|
6447
|
-
databases: filterRequirements(resources.databases, consumer),
|
|
6448
|
-
secrets: filterRequirements(resources.secrets, consumer)
|
|
6449
|
-
};
|
|
6450
|
-
}
|
|
6451
|
-
function filterRequirements(requirements, consumer) {
|
|
6452
|
-
return Object.fromEntries(Object.entries(requirements).filter(([, requirement]) => requirement.consumers.some((declared) => declared.type === consumer.type && (consumer.type === "app" || declared.type === "agent" && declared.name === consumer.name))));
|
|
6453
|
-
}
|
|
6454
|
-
function collectRequirements(category, declarations, select) {
|
|
6455
|
-
const resources = /* @__PURE__ */ new Map();
|
|
6456
|
-
for (const { consumer, declaration } of declarations) for (const [key, requirement] of Object.entries(select(declaration))) {
|
|
6457
|
-
const existing = resources.get(key);
|
|
6458
|
-
if (!existing) {
|
|
6459
|
-
resources.set(key, {
|
|
6460
|
-
...requirement,
|
|
6461
|
-
consumers: [consumer]
|
|
6462
|
-
});
|
|
6463
|
-
continue;
|
|
6464
|
-
}
|
|
6465
|
-
if (existing.mode !== requirement.mode || existing.toolkit !== requirement.toolkit) throw new ZodError([{
|
|
6466
|
-
code: "custom",
|
|
6467
|
-
message: `Conflicting ${category} requirement "${key}": declarations must agree on mode${category === "connections" ? " and toolkit" : ""}`,
|
|
6468
|
-
path: [
|
|
6469
|
-
...consumer.type === "app" ? ["app"] : ["agents", consumer.name],
|
|
6470
|
-
category,
|
|
6471
|
-
key
|
|
6472
|
-
]
|
|
6473
|
-
}]);
|
|
6474
|
-
existing.consumers.push(consumer);
|
|
6475
|
-
}
|
|
6476
|
-
return Object.fromEntries(resources);
|
|
6477
|
-
}
|
|
6478
|
-
//#endregion
|
|
6479
6355
|
//#region ../shared/dist/slate-usage.mjs
|
|
6480
6356
|
const ownerSchema = discriminatedUnion("type", [object({
|
|
6481
6357
|
id: string().min(1),
|
|
@@ -6490,6 +6366,7 @@ object({
|
|
|
6490
6366
|
});
|
|
6491
6367
|
//#endregion
|
|
6492
6368
|
//#region ../shared/dist/slate-resources.mjs
|
|
6369
|
+
const noCommitSchema = object({ reason: literal("no-commit") });
|
|
6493
6370
|
const slateResourceConfigurationSchema = resourcesSchema.extend({
|
|
6494
6371
|
connections: record(resourcesSchema.shape.connections.keyType, resourcesSchema.shape.connections.valueType.extend({
|
|
6495
6372
|
connection_id: string().nullable(),
|
|
@@ -6499,45 +6376,23 @@ const slateResourceConfigurationSchema = resourcesSchema.extend({
|
|
|
6499
6376
|
instance_name: string().min(1),
|
|
6500
6377
|
owner: ownerSchema
|
|
6501
6378
|
})),
|
|
6502
|
-
secrets: record(resourcesSchema.shape.secrets.keyType, resourcesSchema.shape.secrets.valueType.extend({
|
|
6379
|
+
secrets: record(resourcesSchema.shape.secrets.keyType, discriminatedUnion("mode", [resourcesSchema.shape.secrets.valueType.extend({
|
|
6380
|
+
mode: literal("owner"),
|
|
6381
|
+
owner: ownerSchema
|
|
6382
|
+
}), resourcesSchema.shape.secrets.valueType.extend({
|
|
6383
|
+
mode: literal("viewer"),
|
|
6384
|
+
owner: ownerSchema,
|
|
6385
|
+
supplied: boolean()
|
|
6386
|
+
})]))
|
|
6503
6387
|
});
|
|
6504
6388
|
object({ resources: slateResourceConfigurationSchema });
|
|
6505
6389
|
const localResourceConfigurationSchema = resourcesSchema.extend({
|
|
6506
6390
|
connections: record(resourcesSchema.shape.connections.keyType, resourcesSchema.shape.connections.valueType.extend({ connection_id: string().min(1).nullable() })),
|
|
6507
|
-
databases: record(resourcesSchema.shape.databases.keyType, resourcesSchema.shape.databases.valueType.extend({
|
|
6508
|
-
instance_name: string().min(1),
|
|
6509
|
-
migrations: databaseMigrationsSchema
|
|
6510
|
-
})),
|
|
6391
|
+
databases: record(resourcesSchema.shape.databases.keyType, resourcesSchema.shape.databases.valueType.extend({ instance_name: string().min(1) })),
|
|
6511
6392
|
secrets: record(resourcesSchema.shape.secrets.keyType, resourcesSchema.shape.secrets.valueType.extend({ value: string().nullable() }))
|
|
6512
6393
|
});
|
|
6513
6394
|
//#endregion
|
|
6514
|
-
//#region env.ts
|
|
6515
|
-
function readLocalSecret(name) {
|
|
6516
|
-
return process.env[name] ?? null;
|
|
6517
|
-
}
|
|
6518
|
-
const env = object({
|
|
6519
|
-
CTX_AUTH_CLIENT_ID: string().min(1).default("QBFOYTTCdjpEiXwgDNnovDPoJBYAfRpF"),
|
|
6520
|
-
CTX_AUTH_ISSUER: url().default("https://www.usecontextlayer.com/api/auth"),
|
|
6521
|
-
CTX_PLATFORM_URL: url().default("https://platform.usecontextlayer.com")
|
|
6522
|
-
}).parse(process.env);
|
|
6523
|
-
//#endregion
|
|
6524
6395
|
//#region slate.ts
|
|
6525
|
-
async function resolveSlateTarget(target) {
|
|
6526
|
-
return target === "local" ? getLocalSlateId() : target;
|
|
6527
|
-
}
|
|
6528
|
-
async function joinSlate(target) {
|
|
6529
|
-
const slateTarget = await resolveSlateTarget(target);
|
|
6530
|
-
const response = await fetch(new URL(`/api/slates/${encodeURIComponent(slateTarget)}/join`, env.CTX_PLATFORM_URL), {
|
|
6531
|
-
headers: { authorization: `Bearer ${await getAccessToken(env)}` },
|
|
6532
|
-
method: "POST"
|
|
6533
|
-
});
|
|
6534
|
-
if (!response.ok) throw new Error(`Slate join failed: HTTP ${response.status}`);
|
|
6535
|
-
const member = object({
|
|
6536
|
-
slate_id: uuid(),
|
|
6537
|
-
user_id: string().min(1)
|
|
6538
|
-
}).parse(await response.json());
|
|
6539
|
-
console.log(JSON.stringify(member));
|
|
6540
|
-
}
|
|
6541
6396
|
async function getLocalSlateId() {
|
|
6542
6397
|
const { stdout: remote } = await execa("git", [
|
|
6543
6398
|
"remote",
|
|
@@ -6576,32 +6431,26 @@ async function readLocalConnections(directory) {
|
|
|
6576
6431
|
const contents = await readOptionalFile(resolve(directory, ".contextlayer/connections.json"));
|
|
6577
6432
|
return localConnectionsSchema.parse(contents === null ? {} : JSON.parse(contents));
|
|
6578
6433
|
}
|
|
6579
|
-
|
|
6580
|
-
|
|
6581
|
-
const ignorePath = resolve(directory, ".gitignore");
|
|
6582
|
-
const contents = await readOptionalFile(ignorePath) ?? "";
|
|
6583
|
-
if (!contents.split(/\r?\n/).includes("/.contextlayer/")) await writeFile(ignorePath, `${contents}${contents && !contents.endsWith("\n") ? "\n" : ""}/.contextlayer/\n`);
|
|
6434
|
+
function getLocalResourcesWorkerName() {
|
|
6435
|
+
return `ctx-local-resources-${createHash("sha256").update(process.cwd()).digest("hex").slice(0, 16)}`;
|
|
6584
6436
|
}
|
|
6585
6437
|
async function prepareLocalResourceConfiguration(directory = process.cwd()) {
|
|
6586
6438
|
const resources = await readLocalResources(directory);
|
|
6587
6439
|
const assignments = new Map(Object.entries(await readLocalConnections(directory)));
|
|
6588
|
-
|
|
6440
|
+
return localResourceConfigurationSchema.parse({
|
|
6589
6441
|
connections: Object.fromEntries(Object.entries(resources.connections).map(([slug, requirement]) => [slug, {
|
|
6590
6442
|
...requirement,
|
|
6591
6443
|
connection_id: assignments.get(slug) ?? null
|
|
6592
6444
|
}])),
|
|
6593
|
-
databases: Object.fromEntries(
|
|
6445
|
+
databases: Object.fromEntries(Object.entries(resources.databases).map(([slug, requirement]) => [slug, {
|
|
6594
6446
|
...requirement,
|
|
6595
|
-
instance_name: slug
|
|
6596
|
-
|
|
6597
|
-
}]))),
|
|
6447
|
+
instance_name: slug
|
|
6448
|
+
}])),
|
|
6598
6449
|
secrets: Object.fromEntries(Object.entries(resources.secrets).map(([name, requirement]) => [name, {
|
|
6599
6450
|
...requirement,
|
|
6600
6451
|
value: readLocalSecret(name)
|
|
6601
6452
|
}]))
|
|
6602
6453
|
});
|
|
6603
|
-
await prepareLocalDirectory(directory);
|
|
6604
|
-
return configuration;
|
|
6605
6454
|
}
|
|
6606
6455
|
async function saveLocalConnection(slug, connectionId, directory = process.cwd()) {
|
|
6607
6456
|
const assignment = localConnectionsSchema.parse({ [slug]: connectionId });
|
|
@@ -6609,10 +6458,10 @@ async function saveLocalConnection(slug, connectionId, directory = process.cwd()
|
|
|
6609
6458
|
...await readLocalConnections(directory),
|
|
6610
6459
|
...assignment
|
|
6611
6460
|
};
|
|
6612
|
-
await
|
|
6461
|
+
await mkdir(resolve(directory, ".contextlayer"), { recursive: true });
|
|
6613
6462
|
await writeFile(resolve(directory, ".contextlayer/connections.json"), `${JSON.stringify(connections, null, 2)}\n`);
|
|
6614
6463
|
}
|
|
6615
6464
|
//#endregion
|
|
6616
|
-
export {
|
|
6465
|
+
export { noCommitSchema as a, execa as c, getLocalSlateId as i, prepareLocalResourceConfiguration as n, slateResourceConfigurationSchema as o, saveLocalConnection as r, ownerSchema as s, getLocalResourcesWorkerName as t };
|
|
6617
6466
|
|
|
6618
|
-
//# sourceMappingURL=resources-
|
|
6467
|
+
//# sourceMappingURL=resources-BhJbHzU0.mjs.map
|