create-cf-open-agents-api 0.2.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/LICENSE +202 -0
- package/NOTICE +25 -0
- package/README.md +96 -0
- package/dist/answers.d.ts +30 -0
- package/dist/answers.js +83 -0
- package/dist/answers.js.map +1 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +31 -0
- package/dist/cli.js.map +1 -0
- package/dist/commands/doctor.d.ts +51 -0
- package/dist/commands/doctor.js +26 -0
- package/dist/commands/doctor.js.map +1 -0
- package/dist/commands/init.d.ts +177 -0
- package/dist/commands/init.js +85 -0
- package/dist/commands/init.js.map +1 -0
- package/dist/commands/setup.d.ts +67 -0
- package/dist/commands/setup.js +31 -0
- package/dist/commands/setup.js.map +1 -0
- package/dist/commands/vendor.d.ts +69 -0
- package/dist/commands/vendor.js +37 -0
- package/dist/commands/vendor.js.map +1 -0
- package/dist/doctor.d.ts +26 -0
- package/dist/doctor.js +136 -0
- package/dist/doctor.js.map +1 -0
- package/dist/exec.d.ts +16 -0
- package/dist/exec.js +33 -0
- package/dist/exec.js.map +1 -0
- package/dist/fs.d.ts +24 -0
- package/dist/fs.js +54 -0
- package/dist/fs.js.map +1 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +17 -0
- package/dist/index.js.map +1 -0
- package/dist/init.d.ts +37 -0
- package/dist/init.js +179 -0
- package/dist/init.js.map +1 -0
- package/dist/jsonc.d.ts +17 -0
- package/dist/jsonc.js +55 -0
- package/dist/jsonc.js.map +1 -0
- package/dist/plan.d.ts +23 -0
- package/dist/plan.js +36 -0
- package/dist/plan.js.map +1 -0
- package/dist/project.d.ts +62 -0
- package/dist/project.js +52 -0
- package/dist/project.js.map +1 -0
- package/dist/setup.d.ts +26 -0
- package/dist/setup.js +139 -0
- package/dist/setup.js.map +1 -0
- package/dist/steps/agents-file.d.ts +5 -0
- package/dist/steps/agents-file.js +19 -0
- package/dist/steps/agents-file.js.map +1 -0
- package/dist/steps/dev-vars.d.ts +17 -0
- package/dist/steps/dev-vars.js +65 -0
- package/dist/steps/dev-vars.js.map +1 -0
- package/dist/steps/entry.d.ts +7 -0
- package/dist/steps/entry.js +36 -0
- package/dist/steps/entry.js.map +1 -0
- package/dist/steps/gitignore.d.ts +5 -0
- package/dist/steps/gitignore.js +20 -0
- package/dist/steps/gitignore.js.map +1 -0
- package/dist/steps/package-json.d.ts +12 -0
- package/dist/steps/package-json.js +45 -0
- package/dist/steps/package-json.js.map +1 -0
- package/dist/steps/standalone.d.ts +8 -0
- package/dist/steps/standalone.js +18 -0
- package/dist/steps/standalone.js.map +1 -0
- package/dist/steps/tsconfig.d.ts +4 -0
- package/dist/steps/tsconfig.js +18 -0
- package/dist/steps/tsconfig.js.map +1 -0
- package/dist/steps/vendor.d.ts +30 -0
- package/dist/steps/vendor.js +158 -0
- package/dist/steps/vendor.js.map +1 -0
- package/dist/steps/wrangler.d.ts +35 -0
- package/dist/steps/wrangler.js +197 -0
- package/dist/steps/wrangler.js.map +1 -0
- package/dist/templates/agents.d.ts +27 -0
- package/dist/templates/agents.js +265 -0
- package/dist/templates/agents.js.map +1 -0
- package/dist/templates/standalone.d.ts +12 -0
- package/dist/templates/standalone.js +44 -0
- package/dist/templates/standalone.js.map +1 -0
- package/dist/token.d.ts +3 -0
- package/dist/token.js +7 -0
- package/dist/token.js.map +1 -0
- package/dist/ui.d.ts +33 -0
- package/dist/ui.js +82 -0
- package/dist/ui.js.map +1 -0
- package/dist/vendor.d.ts +9 -0
- package/dist/vendor.js +14 -0
- package/dist/vendor.js.map +1 -0
- package/dist/versions.d.ts +30 -0
- package/dist/versions.js +33 -0
- package/dist/versions.js.map +1 -0
- package/package.json +54 -0
package/dist/exec.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export interface RunOptions {
|
|
2
|
+
cwd?: string;
|
|
3
|
+
input?: string;
|
|
4
|
+
}
|
|
5
|
+
export interface RunResult {
|
|
6
|
+
ok: boolean;
|
|
7
|
+
stdout: string;
|
|
8
|
+
stderr: string;
|
|
9
|
+
}
|
|
10
|
+
/** Runs a command to completion; a failure is a result, not an exception. */
|
|
11
|
+
export type Runner = (command: string, args: readonly string[], options?: RunOptions) => RunResult;
|
|
12
|
+
export declare const run: Runner;
|
|
13
|
+
export type PackageManager = "pnpm" | "npm" | "yarn" | "bun";
|
|
14
|
+
/** The `<pm> exec`-style prefix that runs a project-local binary such as wrangler. */
|
|
15
|
+
export declare function packageManagerExec(manager: PackageManager): readonly string[];
|
|
16
|
+
export declare function installCommand(manager: PackageManager): string;
|
package/dist/exec.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { execFileSync } from "node:child_process";
|
|
2
|
+
export const run = (command, args, options = {}) => {
|
|
3
|
+
try {
|
|
4
|
+
const stdout = execFileSync(command, [...args], {
|
|
5
|
+
cwd: options.cwd,
|
|
6
|
+
input: options.input,
|
|
7
|
+
encoding: "utf8",
|
|
8
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
9
|
+
});
|
|
10
|
+
return { ok: true, stdout, stderr: "" };
|
|
11
|
+
}
|
|
12
|
+
catch (error) {
|
|
13
|
+
const failure = error;
|
|
14
|
+
return { ok: false, stdout: failure.stdout ?? "", stderr: failure.stderr ?? String(error) };
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
/** The `<pm> exec`-style prefix that runs a project-local binary such as wrangler. */
|
|
18
|
+
export function packageManagerExec(manager) {
|
|
19
|
+
switch (manager) {
|
|
20
|
+
case "pnpm":
|
|
21
|
+
return ["pnpm", "exec"];
|
|
22
|
+
case "yarn":
|
|
23
|
+
return ["yarn"];
|
|
24
|
+
case "bun":
|
|
25
|
+
return ["bunx"];
|
|
26
|
+
default:
|
|
27
|
+
return ["npx"];
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
export function installCommand(manager) {
|
|
31
|
+
return `${manager} install`;
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=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AAU,cAAc,CAAC,OAAuB;IACpD,OAAO,GAAG,OAAO,UAAU,CAAC;AAC9B,CAAC"}
|
package/dist/fs.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { StepResult } from "./plan.js";
|
|
2
|
+
export declare function readIfExists(path: string): string | undefined;
|
|
3
|
+
/** Forward-slash path relative to the project, for the report. */
|
|
4
|
+
export declare function display(root: string, path: string): string;
|
|
5
|
+
/**
|
|
6
|
+
* The project's files. Writes happen only when content differs; a dry run keeps them in
|
|
7
|
+
* an overlay so later steps see what earlier steps would have written.
|
|
8
|
+
*/
|
|
9
|
+
export declare class Files {
|
|
10
|
+
readonly root: string;
|
|
11
|
+
readonly dryRun: boolean;
|
|
12
|
+
private readonly overlay;
|
|
13
|
+
constructor(root: string, dryRun: boolean);
|
|
14
|
+
read(path: string): string | undefined;
|
|
15
|
+
exists(path: string): boolean;
|
|
16
|
+
write(path: string, content: string, note?: string): StepResult;
|
|
17
|
+
}
|
|
18
|
+
export interface Formatting {
|
|
19
|
+
insertSpaces: boolean;
|
|
20
|
+
tabSize: number;
|
|
21
|
+
eol: "\n" | "\r\n";
|
|
22
|
+
}
|
|
23
|
+
/** Indentation and line endings of an existing file, so edits match it. */
|
|
24
|
+
export declare function detectFormatting(text: string): Formatting;
|
package/dist/fs.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { dirname, relative } from "node:path";
|
|
3
|
+
export function readIfExists(path) {
|
|
4
|
+
return existsSync(path) ? readFileSync(path, "utf8") : undefined;
|
|
5
|
+
}
|
|
6
|
+
/** Forward-slash path relative to the project, for the report. */
|
|
7
|
+
export function display(root, path) {
|
|
8
|
+
return relative(root, path).split("\\").join("/") || ".";
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* The project's files. Writes happen only when content differs; a dry run keeps them in
|
|
12
|
+
* an overlay so later steps see what earlier steps would have written.
|
|
13
|
+
*/
|
|
14
|
+
export class Files {
|
|
15
|
+
root;
|
|
16
|
+
dryRun;
|
|
17
|
+
overlay = new Map();
|
|
18
|
+
constructor(root, dryRun) {
|
|
19
|
+
this.root = root;
|
|
20
|
+
this.dryRun = dryRun;
|
|
21
|
+
}
|
|
22
|
+
read(path) {
|
|
23
|
+
return this.overlay.get(path) ?? readIfExists(path);
|
|
24
|
+
}
|
|
25
|
+
exists(path) {
|
|
26
|
+
return this.overlay.has(path) || existsSync(path);
|
|
27
|
+
}
|
|
28
|
+
write(path, content, note) {
|
|
29
|
+
const file = display(this.root, path);
|
|
30
|
+
const current = this.read(path);
|
|
31
|
+
if (current === content)
|
|
32
|
+
return { status: "skipped", file };
|
|
33
|
+
if (this.dryRun)
|
|
34
|
+
this.overlay.set(path, content);
|
|
35
|
+
else {
|
|
36
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
37
|
+
writeFileSync(path, content);
|
|
38
|
+
}
|
|
39
|
+
return {
|
|
40
|
+
status: current === undefined ? "created" : "updated",
|
|
41
|
+
file,
|
|
42
|
+
...(note ? { note } : {}),
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
/** Indentation and line endings of an existing file, so edits match it. */
|
|
47
|
+
export function detectFormatting(text) {
|
|
48
|
+
const eol = text.includes("\r\n") ? "\r\n" : "\n";
|
|
49
|
+
const indent = /^(?:\r?\n)*[^\n]*\r?\n( +|\t)\S/.exec(text)?.[1];
|
|
50
|
+
if (indent === "\t")
|
|
51
|
+
return { insertSpaces: false, tabSize: 2, eol };
|
|
52
|
+
return { insertSpaces: true, tabSize: indent ? indent.length : 2, eol };
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=fs.js.map
|
package/dist/fs.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fs.js","sourceRoot":"","sources":["../src/fs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EA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AAI,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;aAC5C,CAAC;YACJ,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;YAC9C,aAAa,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;QAC/B,CAAC;QACD,OAAO;YACL,MAAM,EAAE,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS;YACrD,IAAI;YACJ,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SAC1B,CAAC;IACJ,CAAC;CACF;AAOD,2EAA2E;AAC3E,MAAM,UAAU,gBAAgB,CAAC,IAAY;IAC3C,MAAM,GAAG,GAAG,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC;IAClD,MAAM,MAAM,GAAG,iCAAiC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IACjE,IAAI,MAAM,KAAK,IAAI;QAAE,OAAO,EAAE,YAAY,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC;IACrE,OAAO,EAAE,YAAY,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC;AAC1E,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/** Programmatic surface: what the commands call and what the tests drive. */
|
|
2
|
+
export { collectAnswers, type InitAnswers, type InitPreferences } from "./answers.js";
|
|
3
|
+
export { configChecks, devVarsCheck, renderReport, runDoctor, snapshotCheck } from "./doctor.js";
|
|
4
|
+
export { Files } from "./fs.js";
|
|
5
|
+
export { type InitOptions, type InitResult, runInit } from "./init.js";
|
|
6
|
+
export { CliError, Plan, type StepResult } from "./plan.js";
|
|
7
|
+
export { detectPackageManager, locateProject, workerNameFrom } from "./project.js";
|
|
8
|
+
export { accountIds, runSetup, type SetupOptions } from "./setup.js";
|
|
9
|
+
export { ensureDevVars, ensureDevVarsExample, parseDevVars } from "./steps/dev-vars.js";
|
|
10
|
+
export { agentsSpecifier } from "./steps/entry.js";
|
|
11
|
+
export { ensureVendor, readVendorManifest, type VendorManifest } from "./steps/vendor.js";
|
|
12
|
+
export { upsertWranglerConfig, type WranglerInput } from "./steps/wrangler.js";
|
|
13
|
+
export { type CompositionInput, describeSecret, type Harness, HARNESSES, type Provider, PROVIDERS, providerPackages, renderComposition, } from "./templates/agents.js";
|
|
14
|
+
export { defaultPrompter, plainReporter, type Prompter, type Reporter } from "./ui.js";
|
|
15
|
+
export { runVendor } from "./vendor.js";
|
|
16
|
+
export * as versions from "./versions.js";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/** Programmatic surface: what the commands call and what the tests drive. */
|
|
2
|
+
export { collectAnswers } from "./answers.js";
|
|
3
|
+
export { configChecks, devVarsCheck, renderReport, runDoctor, snapshotCheck } from "./doctor.js";
|
|
4
|
+
export { Files } from "./fs.js";
|
|
5
|
+
export { runInit } from "./init.js";
|
|
6
|
+
export { CliError, Plan } from "./plan.js";
|
|
7
|
+
export { detectPackageManager, locateProject, workerNameFrom } from "./project.js";
|
|
8
|
+
export { accountIds, runSetup } from "./setup.js";
|
|
9
|
+
export { ensureDevVars, ensureDevVarsExample, parseDevVars } from "./steps/dev-vars.js";
|
|
10
|
+
export { agentsSpecifier } from "./steps/entry.js";
|
|
11
|
+
export { ensureVendor, readVendorManifest } from "./steps/vendor.js";
|
|
12
|
+
export { upsertWranglerConfig } from "./steps/wrangler.js";
|
|
13
|
+
export { describeSecret, HARNESSES, PROVIDERS, providerPackages, renderComposition, } from "./templates/agents.js";
|
|
14
|
+
export { defaultPrompter, plainReporter } from "./ui.js";
|
|
15
|
+
export { runVendor } from "./vendor.js";
|
|
16
|
+
export * as versions from "./versions.js";
|
|
17
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,OAAO,EAAE,cAAc,EAA0C,MAAM,cAAc,CAAC;AACtF,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,YAAY,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AACjG,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAqC,OAAO,EAAE,MAAM,WAAW,CAAC;AACvE,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAmB,MAAM,WAAW,CAAC;AAC5D,OAAO,EAAE,oBAAoB,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AACnF,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAqB,MAAM,YAAY,CAAC;AACrE,OAAO,EAAE,aAAa,EAAE,oBAAoB,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACxF,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAuB,MAAM,mBAAmB,CAAC;AAC1F,OAAO,EAAE,oBAAoB,EAAsB,MAAM,qBAAqB,CAAC;AAC/E,OAAO,EAEL,cAAc,EAEd,SAAS,EAET,SAAS,EACT,gBAAgB,EAChB,iBAAiB,GAClB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,eAAe,EAAE,aAAa,EAAgC,MAAM,SAAS,CAAC;AACvF,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,KAAK,QAAQ,MAAM,eAAe,CAAC"}
|
package/dist/init.d.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { type InitAnswers, type InitPreferences } from "./answers.js";
|
|
2
|
+
import { type Runner } from "./exec.js";
|
|
3
|
+
import { Files } from "./fs.js";
|
|
4
|
+
import { Plan } from "./plan.js";
|
|
5
|
+
import { type Project, type WranglerConfig } from "./project.js";
|
|
6
|
+
import { type Prompter, type Reporter } from "./ui.js";
|
|
7
|
+
export interface InitOptions extends InitPreferences {
|
|
8
|
+
dir: string;
|
|
9
|
+
yes: boolean;
|
|
10
|
+
force: boolean;
|
|
11
|
+
dryRun: boolean;
|
|
12
|
+
/** Path of the composition module; the default sits next to the Wrangler entry. */
|
|
13
|
+
agentsFile?: string;
|
|
14
|
+
/** Pre-publication: a packed library tarball or package directory for a `file:` dependency. */
|
|
15
|
+
library?: string;
|
|
16
|
+
cliPackage?: string;
|
|
17
|
+
ref?: string;
|
|
18
|
+
source?: string;
|
|
19
|
+
prompter?: Prompter;
|
|
20
|
+
reporter?: Reporter;
|
|
21
|
+
runner?: Runner;
|
|
22
|
+
fetch?: typeof globalThis.fetch;
|
|
23
|
+
env?: NodeJS.ProcessEnv;
|
|
24
|
+
today?: string;
|
|
25
|
+
token?: () => string;
|
|
26
|
+
}
|
|
27
|
+
export interface InitResult {
|
|
28
|
+
project: Project;
|
|
29
|
+
answers: InitAnswers;
|
|
30
|
+
plan: Plan;
|
|
31
|
+
agentsPath: string;
|
|
32
|
+
}
|
|
33
|
+
export declare function runInit(options: InitOptions): Promise<InitResult>;
|
|
34
|
+
export declare function readConfig(files: Files, project: Project): {
|
|
35
|
+
text: string;
|
|
36
|
+
config: WranglerConfig;
|
|
37
|
+
};
|
package/dist/init.js
ADDED
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import { dirname, join, resolve } from "node:path";
|
|
2
|
+
import { collectAnswers } from "./answers.js";
|
|
3
|
+
import { installCommand, packageManagerExec, run } from "./exec.js";
|
|
4
|
+
import { Files } from "./fs.js";
|
|
5
|
+
import { parseJsonc } from "./jsonc.js";
|
|
6
|
+
import { CliError, Plan } from "./plan.js";
|
|
7
|
+
import { locateProject } from "./project.js";
|
|
8
|
+
import { ensureAgentsFile } from "./steps/agents-file.js";
|
|
9
|
+
import { ensureDevVars, ensureDevVarsExample } from "./steps/dev-vars.js";
|
|
10
|
+
import { ensureEntryExports } from "./steps/entry.js";
|
|
11
|
+
import { ensureGitignore } from "./steps/gitignore.js";
|
|
12
|
+
import { ensurePackageJson, vendorScript } from "./steps/package-json.js";
|
|
13
|
+
import { ensureStandaloneSkeleton } from "./steps/standalone.js";
|
|
14
|
+
import { ensureTsconfigExclude } from "./steps/tsconfig.js";
|
|
15
|
+
import { ensureVendor } from "./steps/vendor.js";
|
|
16
|
+
import { upsertWranglerConfig } from "./steps/wrangler.js";
|
|
17
|
+
import { describeSecret, PRESET_NAMES, providerPackages, } from "./templates/agents.js";
|
|
18
|
+
import { clackPrompter, clackReporter, defaultPrompter, interactive, plainReporter, } from "./ui.js";
|
|
19
|
+
import { CLI_NAME, CLI_VERSION, LIBRARY_NAME, PEER_VERSIONS, TOOLCHAIN_VERSIONS, } from "./versions.js";
|
|
20
|
+
const today = () => new Date().toISOString().slice(0, 10);
|
|
21
|
+
const fileDependency = (path, fallback) => path ? `file:${resolve(path)}` : fallback;
|
|
22
|
+
function choosePrompter(options) {
|
|
23
|
+
if (options.prompter)
|
|
24
|
+
return options.prompter;
|
|
25
|
+
if (options.yes)
|
|
26
|
+
return defaultPrompter();
|
|
27
|
+
if (!interactive())
|
|
28
|
+
throw new CliError("Not a terminal; pass --yes to accept the defaults.");
|
|
29
|
+
return clackPrompter();
|
|
30
|
+
}
|
|
31
|
+
const chooseReporter = (options) => options.reporter ?? (interactive() && !options.yes ? clackReporter() : plainReporter());
|
|
32
|
+
export async function runInit(options) {
|
|
33
|
+
const root = resolve(options.dir);
|
|
34
|
+
const project = locateProject(root);
|
|
35
|
+
const prompter = choosePrompter(options);
|
|
36
|
+
const reporter = chooseReporter(options);
|
|
37
|
+
const files = new Files(root, options.dryRun);
|
|
38
|
+
reporter.intro(`${CLI_NAME} ${CLI_VERSION}${options.dryRun ? " (dry run)" : ""}`);
|
|
39
|
+
await confirmNewProject(project, prompter);
|
|
40
|
+
const configName = project.mode === "retrofit" ? readConfig(files, project).config.name : undefined;
|
|
41
|
+
const answers = await collectAnswers(project, configName, options, prompter);
|
|
42
|
+
const plan = new Plan();
|
|
43
|
+
if (project.mode === "standalone")
|
|
44
|
+
for (const result of ensureStandaloneSkeleton({
|
|
45
|
+
files,
|
|
46
|
+
name: answers.name,
|
|
47
|
+
publicRoute: answers.publicRoute,
|
|
48
|
+
today: options.today ?? today(),
|
|
49
|
+
}))
|
|
50
|
+
plan.add(result);
|
|
51
|
+
plan.add(await vendor(options, root, reporter));
|
|
52
|
+
const config = readConfig(files, project).config;
|
|
53
|
+
const entryPath = resolve(root, config.main ?? "src/index.ts");
|
|
54
|
+
const inEntry = compositionInEntry(files, project, entryPath);
|
|
55
|
+
configureWrangler(files, project, answers, options, plan, !inEntry);
|
|
56
|
+
const { agentsPath, composition } = compose(files, entryPath, inEntry, answers, options, plan);
|
|
57
|
+
const secret = describeSecret(composition);
|
|
58
|
+
plan.add(ensureDevVars({ files, secret, token: options.token }));
|
|
59
|
+
plan.add(ensureDevVarsExample({ files, secret }));
|
|
60
|
+
plan.add(ensureGitignore(files));
|
|
61
|
+
plan.add(ensurePackageJson(manifestChanges(files, project, composition, options)));
|
|
62
|
+
if (project.mode === "retrofit")
|
|
63
|
+
plan.add(ensureTsconfigExclude(files));
|
|
64
|
+
if (!options.library)
|
|
65
|
+
plan.note(`${LIBRARY_NAME}@${CLI_VERSION} must be on npm for install to succeed; before that, pass --library <tarball>.`);
|
|
66
|
+
if (answers.install && !options.dryRun)
|
|
67
|
+
await install(project, reporter, options.runner ?? run);
|
|
68
|
+
reporter.note(nextSteps(project, answers, agentsPath), "Next steps");
|
|
69
|
+
reporter.plan(plan, options.dryRun ? "Dry run: nothing was written" : "Done");
|
|
70
|
+
return { project, answers, plan, agentsPath };
|
|
71
|
+
}
|
|
72
|
+
async function confirmNewProject(project, prompter) {
|
|
73
|
+
if (project.mode === "retrofit")
|
|
74
|
+
return;
|
|
75
|
+
const create = await prompter.confirm(`No Wrangler configuration in ${project.root}. Create a new Workers project here?`, true);
|
|
76
|
+
if (!create)
|
|
77
|
+
throw new CliError("Nothing to do: run inside a Workers project or let the CLI create one.");
|
|
78
|
+
}
|
|
79
|
+
/** A new project composes in its entry; so does a project this CLI created earlier. */
|
|
80
|
+
function compositionInEntry(files, project, entryPath) {
|
|
81
|
+
if (project.mode === "standalone")
|
|
82
|
+
return true;
|
|
83
|
+
return /defineAgentWorker[<(]/.test(files.read(entryPath) ?? "");
|
|
84
|
+
}
|
|
85
|
+
function configureWrangler(files, project, answers, options, plan, agentsBinding) {
|
|
86
|
+
const { text } = readConfig(files, project);
|
|
87
|
+
const outcome = upsertWranglerConfig(text, {
|
|
88
|
+
name: answers.name,
|
|
89
|
+
agentsBinding,
|
|
90
|
+
workersAi: answers.workersAi || answers.provider === "workers-ai",
|
|
91
|
+
codeLoader: answers.codeLoader,
|
|
92
|
+
force: options.force,
|
|
93
|
+
}, project.configPath.slice(project.root.length + 1));
|
|
94
|
+
plan.add(files.write(project.configPath, outcome.text));
|
|
95
|
+
for (const note of outcome.notes)
|
|
96
|
+
plan.note(note);
|
|
97
|
+
}
|
|
98
|
+
function compose(files, entryPath, inEntry, answers, options, plan) {
|
|
99
|
+
const agentsPath = inEntry
|
|
100
|
+
? entryPath
|
|
101
|
+
: resolve(files.root, options.agentsFile ?? join(dirname(entryPath), "agents.ts"));
|
|
102
|
+
const composition = {
|
|
103
|
+
provider: answers.provider,
|
|
104
|
+
harnesses: answers.harnesses,
|
|
105
|
+
workersAi: answers.workersAi,
|
|
106
|
+
baseURL: answers.baseURL,
|
|
107
|
+
model: answers.model,
|
|
108
|
+
standalone: inEntry,
|
|
109
|
+
};
|
|
110
|
+
plan.add(ensureAgentsFile(files, agentsPath, composition, options.force));
|
|
111
|
+
if (!inEntry)
|
|
112
|
+
plan.add(ensureEntryExports(files, entryPath, agentsPath));
|
|
113
|
+
return { agentsPath, composition };
|
|
114
|
+
}
|
|
115
|
+
function manifestChanges(files, project, composition, options) {
|
|
116
|
+
return {
|
|
117
|
+
files,
|
|
118
|
+
force: options.force,
|
|
119
|
+
dependencies: {
|
|
120
|
+
[LIBRARY_NAME]: fileDependency(options.library, CLI_VERSION),
|
|
121
|
+
...PEER_VERSIONS,
|
|
122
|
+
...providerPackages(composition),
|
|
123
|
+
},
|
|
124
|
+
devDependencies: {
|
|
125
|
+
[CLI_NAME]: fileDependency(options.cliPackage, CLI_VERSION),
|
|
126
|
+
...(project.mode === "standalone" ? TOOLCHAIN_VERSIONS : {}),
|
|
127
|
+
},
|
|
128
|
+
scripts: { postinstall: vendorScript },
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
function vendor(options, root, reporter) {
|
|
132
|
+
return reporter.spin("Fetching the Docker image snapshot", () => ensureVendor({
|
|
133
|
+
root,
|
|
134
|
+
version: CLI_VERSION,
|
|
135
|
+
ref: options.ref,
|
|
136
|
+
source: options.source,
|
|
137
|
+
force: options.force,
|
|
138
|
+
dryRun: options.dryRun,
|
|
139
|
+
fetch: options.fetch,
|
|
140
|
+
runner: options.runner,
|
|
141
|
+
env: options.env,
|
|
142
|
+
}), (result) => `Image snapshot ${result.status}`);
|
|
143
|
+
}
|
|
144
|
+
export function readConfig(files, project) {
|
|
145
|
+
const text = files.read(project.configPath);
|
|
146
|
+
if (text === undefined)
|
|
147
|
+
throw new CliError(`${project.configPath} is missing`);
|
|
148
|
+
return { text, config: parseJsonc(text, project.configPath) };
|
|
149
|
+
}
|
|
150
|
+
async function install(project, reporter, runner) {
|
|
151
|
+
const [command = "npm", ...args] = installCommand(project.packageManager).split(" ");
|
|
152
|
+
const result = await reporter.spin(`Running ${installCommand(project.packageManager)}`, () => Promise.resolve(runner(command, args, { cwd: project.root })), (outcome) => (outcome.ok ? "Dependencies installed" : "Install failed"));
|
|
153
|
+
if (!result.ok)
|
|
154
|
+
throw new CliError(`${installCommand(project.packageManager)} failed:\n${result.stderr.trim()}`);
|
|
155
|
+
}
|
|
156
|
+
function firstPreset(answers) {
|
|
157
|
+
if (answers.workersAi)
|
|
158
|
+
return "workers";
|
|
159
|
+
return PRESET_NAMES[answers.harnesses[0] ?? "codex"];
|
|
160
|
+
}
|
|
161
|
+
function nextSteps(project, answers, agentsPath) {
|
|
162
|
+
const exec = packageManagerExec(project.packageManager).join(" ");
|
|
163
|
+
const composition = agentsPath.slice(project.root.length + 1);
|
|
164
|
+
const dev = project.mode === "standalone"
|
|
165
|
+
? `${exec} wrangler dev`
|
|
166
|
+
: "your dev server (vite dev or wrangler dev)";
|
|
167
|
+
const use = project.mode === "retrofit"
|
|
168
|
+
? `Forward the API from your Worker: app.all("/v1/*", (c) => c.env.AGENTS.fetch(c.req.raw)) with AGENTS: Fetcher & AgentRPC.`
|
|
169
|
+
: `curl -X POST http://localhost:8787/v1/agents/sessions -H "Authorization: Bearer <API_TOKEN from .dev.vars>" -H "Content-Type: application/json" -H "Idempotency-Key: first" -d '{"agent":{"model":"${firstPreset(answers)}"},"environment":{"type":"openai_hosted"},"input":"Write /workspace/outputs/hello.txt"}'`;
|
|
170
|
+
return [
|
|
171
|
+
`1. ${installCommand(project.packageManager)} (postinstall keeps the image snapshot current)`,
|
|
172
|
+
`2. ${exec} wrangler login (the AI binding and deployments need your account)`,
|
|
173
|
+
`3. Start Docker, then ${dev}; the first image build takes several minutes.`,
|
|
174
|
+
`4. ${use}`,
|
|
175
|
+
`5. Presets and models live in ${composition}; the API token and provider key in .dev.vars.`,
|
|
176
|
+
`6. Production: ${CLI_NAME} setup (R2 buckets and secrets), then ${exec} wrangler deploy.`,
|
|
177
|
+
].join("\n");
|
|
178
|
+
}
|
|
179
|
+
//# sourceMappingURL=init.js.map
|
package/dist/init.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"init.js","s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C,CAAC,2HAA2H;QAC7H,CAAC,CAAC,sMAAsM,WAAW,CAAC,OAAO,CAAC,0FAA0F,CAAC;IAC3T,OAAO;QACL,MAAM,cAAc,CAAC,OAAO,CAAC,cAAc,CAAC,kDAAkD;QAC9F,MAAM,IAAI,qEAAqE;QAC/E,yBAAyB,GAAG,gDAAgD;QAC5E,MAAM,GAAG,EAAE;QACX,iCAAiC,WAAW,gDAAgD;QAC5F,kBAAkB,QAAQ,yCAAyC,IAAI,mBAAmB;KAC3F,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACf,CAAC"}
|
package/dist/jsonc.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type JSONPath } from "jsonc-parser";
|
|
2
|
+
import { type Formatting } from "./fs.js";
|
|
3
|
+
/** A JSONC file kept as text so comments and formatting survive every edit. */
|
|
4
|
+
export interface JsoncDocument {
|
|
5
|
+
text: string;
|
|
6
|
+
formatting: Formatting;
|
|
7
|
+
}
|
|
8
|
+
export declare function openJsonc(text: string): JsoncDocument;
|
|
9
|
+
export declare function parseJsonc<T>(text: string, file: string): T;
|
|
10
|
+
/** Sets a value at a path, creating missing objects; `-1` on an array appends. */
|
|
11
|
+
export declare function setValue(document: JsoncDocument, path: JSONPath, value: unknown, insert?: boolean): JsoncDocument;
|
|
12
|
+
export declare function appendItem(document: JsoncDocument, path: JSONPath, value: unknown): JsoncDocument;
|
|
13
|
+
/**
|
|
14
|
+
* `modify` expands every array in the range it reformats, including neighbours it did
|
|
15
|
+
* not change. Formatters put a short array of scalars on one line, so put those back.
|
|
16
|
+
*/
|
|
17
|
+
export declare function collapsePrimitiveArrays(document: JsoncDocument, width?: number): JsoncDocument;
|
package/dist/jsonc.js
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { applyEdits, modify, parse, parseTree, printParseErrorCode, } from "jsonc-parser";
|
|
2
|
+
import { detectFormatting } from "./fs.js";
|
|
3
|
+
import { CliError } from "./plan.js";
|
|
4
|
+
export function openJsonc(text) {
|
|
5
|
+
return { text, formatting: detectFormatting(text) };
|
|
6
|
+
}
|
|
7
|
+
export function parseJsonc(text, file) {
|
|
8
|
+
const errors = [];
|
|
9
|
+
const value = parse(text, errors, { allowTrailingComma: true });
|
|
10
|
+
if (errors.length > 0) {
|
|
11
|
+
const first = errors[0];
|
|
12
|
+
const reason = first ? printParseErrorCode(first.error) : "unknown";
|
|
13
|
+
throw new CliError(`${file} is not valid JSONC (${reason} at offset ${first?.offset ?? 0})`);
|
|
14
|
+
}
|
|
15
|
+
return value;
|
|
16
|
+
}
|
|
17
|
+
/** Sets a value at a path, creating missing objects; `-1` on an array appends. */
|
|
18
|
+
export function setValue(document, path, value, insert = false) {
|
|
19
|
+
const edits = modify(document.text, path, value, {
|
|
20
|
+
isArrayInsertion: insert,
|
|
21
|
+
formattingOptions: {
|
|
22
|
+
insertSpaces: document.formatting.insertSpaces,
|
|
23
|
+
tabSize: document.formatting.tabSize,
|
|
24
|
+
eol: document.formatting.eol,
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
return { ...document, text: applyEdits(document.text, edits) };
|
|
28
|
+
}
|
|
29
|
+
export function appendItem(document, path, value) {
|
|
30
|
+
return setValue(document, [...path, -1], value, true);
|
|
31
|
+
}
|
|
32
|
+
const isPrimitiveArray = (node) => node.type === "array" &&
|
|
33
|
+
(node.children ?? []).every((child) => ["string", "number", "boolean", "null"].includes(child.type));
|
|
34
|
+
const arrays = (node) => isPrimitiveArray(node) ? [node] : (node.children ?? []).flatMap(arrays);
|
|
35
|
+
/**
|
|
36
|
+
* `modify` expands every array in the range it reformats, including neighbours it did
|
|
37
|
+
* not change. Formatters put a short array of scalars on one line, so put those back.
|
|
38
|
+
*/
|
|
39
|
+
export function collapsePrimitiveArrays(document, width = 100) {
|
|
40
|
+
const root = parseTree(document.text);
|
|
41
|
+
if (!root)
|
|
42
|
+
return document;
|
|
43
|
+
let text = document.text;
|
|
44
|
+
// Edit from the end so earlier offsets stay valid.
|
|
45
|
+
for (const node of arrays(root).sort((a, b) => b.offset - a.offset)) {
|
|
46
|
+
const items = (node.children ?? []).map((child) => text.slice(child.offset, child.offset + child.length));
|
|
47
|
+
const inline = `[${items.join(", ")}]`;
|
|
48
|
+
const lineStart = text.lastIndexOf("\n", node.offset) + 1;
|
|
49
|
+
if (node.offset - lineStart + inline.length > width)
|
|
50
|
+
continue;
|
|
51
|
+
text = text.slice(0, node.offset) + inline + text.slice(node.offset + node.length);
|
|
52
|
+
}
|
|
53
|
+
return { ...document, text };
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=jsonc.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jsonc.js","sourceRoot":"","sources":["../src/jsonc.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EAEV,MAAM,EAEN,KAAK,EAEL,SAAS,EACT,mBAAmB,GACpB,MAAM,cAAc,CAAC;AAEtB,OAAO,EAAE,gBAAgB,EAAmB,MAAM,SAAS,CAAC;AAC5D,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAQrC,MAAM,UAAU,SAAS,CAAC,IAAY;IACpC,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,gBAAgB,CAAC,IAAI,CAAC,EAAE,CAAC;AACtD,CAAC;AAED,MAAM,UAAU,UAAU,CAAI,IAAY,EAAE,IAAY;IACtD,MAAM,MAAM,GAAiB,EAAE,CAAC;IAChC,MAAM,KAAK,GAAG,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,kBAAkB,EAAE,IAAI,EAAE,CAAM,CAAC;IACrE,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACtB,MAAM,KAAK,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;QACxB,MAAM,MAAM,GAAG,KAAK,CAAC,CAAC,CAAC,mBAAmB,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;QACpE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AAC,MAAM,CAAC,CAAC;IACrF,CAAC;IACD,OAAO,EAAE,GAAG,QAAQ,EAAE,IAAI,EAAE,CAAC;AAC/B,CAAC"}
|
package/dist/plan.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export type StepStatus = "created" | "updated" | "skipped";
|
|
2
|
+
/** One idempotent change; `note` explains a skip or a decision the user should know about. */
|
|
3
|
+
export interface StepResult {
|
|
4
|
+
status: StepStatus;
|
|
5
|
+
file: string;
|
|
6
|
+
note?: string;
|
|
7
|
+
}
|
|
8
|
+
/** An expected failure: printed as one line, exit code 1, no stack trace. */
|
|
9
|
+
export declare class CliError extends Error {
|
|
10
|
+
readonly name = "CliError";
|
|
11
|
+
}
|
|
12
|
+
export declare class Plan {
|
|
13
|
+
readonly created: string[];
|
|
14
|
+
readonly updated: string[];
|
|
15
|
+
readonly skipped: string[];
|
|
16
|
+
readonly notes: string[];
|
|
17
|
+
/** A file touched twice is listed once, under its first status. */
|
|
18
|
+
add(result: StepResult): StepResult;
|
|
19
|
+
note(text: string): void;
|
|
20
|
+
/** The Created/Updated/Skipped/Notes report, one bullet per file. */
|
|
21
|
+
render(title: string): string;
|
|
22
|
+
body(): string;
|
|
23
|
+
}
|
package/dist/plan.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/** An expected failure: printed as one line, exit code 1, no stack trace. */
|
|
2
|
+
export class CliError extends Error {
|
|
3
|
+
name = "CliError";
|
|
4
|
+
}
|
|
5
|
+
export class Plan {
|
|
6
|
+
created = [];
|
|
7
|
+
updated = [];
|
|
8
|
+
skipped = [];
|
|
9
|
+
notes = [];
|
|
10
|
+
/** A file touched twice is listed once, under its first status. */
|
|
11
|
+
add(result) {
|
|
12
|
+
const listed = [...this.created, ...this.updated, ...this.skipped].includes(result.file);
|
|
13
|
+
if (!listed)
|
|
14
|
+
this[result.status].push(result.file);
|
|
15
|
+
if (result.note)
|
|
16
|
+
this.notes.push(result.note);
|
|
17
|
+
return result;
|
|
18
|
+
}
|
|
19
|
+
note(text) {
|
|
20
|
+
this.notes.push(text);
|
|
21
|
+
}
|
|
22
|
+
/** The Created/Updated/Skipped/Notes report, one bullet per file. */
|
|
23
|
+
render(title) {
|
|
24
|
+
return `${title}\n${this.body()}`;
|
|
25
|
+
}
|
|
26
|
+
body() {
|
|
27
|
+
const block = (heading, items) => items.length === 0 ? [] : [heading, ...items.map((item) => ` - ${item}`)];
|
|
28
|
+
return [
|
|
29
|
+
...block("Created", this.created),
|
|
30
|
+
...block("Updated", this.updated),
|
|
31
|
+
...block("Skipped", this.skipped),
|
|
32
|
+
...block("Notes", this.notes),
|
|
33
|
+
].join("\n");
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=plan.js.map
|
package/dist/plan.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plan.js","sourceRoot":"","sources":["../src/plan.ts"],"names":[],"mappings":"AASA,6EAA6E;AAC7E,MAAM,OAAO,QAAS,SAAQ,KAAK;IACf,IAAI,GAAG,UAAU,CAAC;CACrC;AAED,MAAM,OAAO,IAAI;IACN,OAAO,GAAa,EAAE,CAAC;IACvB,OAAO,GAAa,EAAE,CAAC;IACvB,OAAO,GAAa,EAAE,CAAC;IACvB,KAAK,GAAa,EAAE,CAAC;IAE9B,mEAAmE;IACnE,GAAG,CAAC,MAAkB;QACpB,MAAM,MAAM,GAAG,CAAC,GAAG,IAAI,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,OAAO,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QACzF,IAAI,CAAC,MAAM;YAAE,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QACnD,IAAI,MAAM,CAAC,IAAI;YAAE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAC9C,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,IAAI,CAAC,IAAY;QACf,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACxB,CAAC;IAED,qEAAqE;IACrE,MAAM,CAAC,KAAa;QAClB,OAAO,GAAG,KAAK,KAAK,IAAI,CAAC,IAAI,EAAE,EAAE,CAAC;IACpC,CAAC;IAED,IAAI;QACF,MAAM,KAAK,GAAG,CAAC,OAAe,EAAE,KAAwB,EAAE,EAAE,CAC1D,KAAK,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,OAAO,IAAI,EAAE,CAAC,CAAC,CAAC;QAC7E,OAAO;YACL,GAAG,KAAK,CAAC,SAAS,EAAE,IAAI,CAAC,OAAO,CAAC;YACjC,GAAG,KAAK,CAAC,SAAS,EAAE,IAAI,CAAC,OAAO,CAAC;YACjC,GAAG,KAAK,CAAC,SAAS,EAAE,IAAI,CAAC,OAAO,CAAC;YACjC,GAAG,KAAK,CAAC,OAAO,EAAE,IAAI,CAAC,KAAK,CAAC;SAC9B,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACf,CAAC;CACF"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { PackageManager } from "./exec.js";
|
|
2
|
+
export type ProjectMode = "retrofit" | "standalone";
|
|
3
|
+
export interface Project {
|
|
4
|
+
root: string;
|
|
5
|
+
mode: ProjectMode;
|
|
6
|
+
/** `wrangler.jsonc` or `wrangler.json`; the standalone skeleton creates `wrangler.jsonc`. */
|
|
7
|
+
configPath: string;
|
|
8
|
+
packageManager: PackageManager;
|
|
9
|
+
}
|
|
10
|
+
export interface WranglerBinding {
|
|
11
|
+
binding?: string;
|
|
12
|
+
name?: string;
|
|
13
|
+
class_name?: string;
|
|
14
|
+
script_name?: string;
|
|
15
|
+
bucket_name?: string;
|
|
16
|
+
service?: string;
|
|
17
|
+
entrypoint?: string;
|
|
18
|
+
}
|
|
19
|
+
export interface WranglerContainer {
|
|
20
|
+
class_name?: string;
|
|
21
|
+
name?: string;
|
|
22
|
+
image?: string;
|
|
23
|
+
image_build_context?: string;
|
|
24
|
+
instance_type?: string;
|
|
25
|
+
max_instances?: number;
|
|
26
|
+
}
|
|
27
|
+
export interface WranglerMigration {
|
|
28
|
+
tag?: string;
|
|
29
|
+
new_classes?: string[];
|
|
30
|
+
new_sqlite_classes?: string[];
|
|
31
|
+
renamed_classes?: {
|
|
32
|
+
from?: string;
|
|
33
|
+
to?: string;
|
|
34
|
+
}[];
|
|
35
|
+
}
|
|
36
|
+
/** The parts of a Wrangler configuration the CLI reads; everything else is left alone. */
|
|
37
|
+
export interface WranglerConfig {
|
|
38
|
+
name?: string;
|
|
39
|
+
main?: string;
|
|
40
|
+
compatibility_date?: string;
|
|
41
|
+
compatibility_flags?: string[];
|
|
42
|
+
workers_dev?: boolean;
|
|
43
|
+
durable_objects?: {
|
|
44
|
+
bindings?: WranglerBinding[];
|
|
45
|
+
};
|
|
46
|
+
migrations?: WranglerMigration[];
|
|
47
|
+
containers?: WranglerContainer[];
|
|
48
|
+
r2_buckets?: WranglerBinding[];
|
|
49
|
+
services?: WranglerBinding[];
|
|
50
|
+
vars?: Record<string, unknown>;
|
|
51
|
+
ai?: {
|
|
52
|
+
binding?: string;
|
|
53
|
+
};
|
|
54
|
+
worker_loaders?: WranglerBinding[];
|
|
55
|
+
env?: Record<string, unknown>;
|
|
56
|
+
}
|
|
57
|
+
/** Finds the Wrangler configuration; a directory without one becomes a new project. */
|
|
58
|
+
export declare function locateProject(root: string): Project;
|
|
59
|
+
export declare function detectPackageManager(root: string): PackageManager;
|
|
60
|
+
export declare function readManifest(root: string): Record<string, unknown> | undefined;
|
|
61
|
+
/** A Worker name from a directory name: lowercase, dashes, no leading or trailing dash. */
|
|
62
|
+
export declare function workerNameFrom(root: string): string;
|