@andreprado/agentkit 0.1.0-alpha.3 → 0.1.0-alpha.5

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.
@@ -0,0 +1,162 @@
1
+ import { listTargetsWithCapability } from "../runtime/core/targets";
2
+ import { loadCapsuleEnv } from "../runtime/env";
3
+ import { AgentKitError } from "../runtime/errors";
4
+ import { defaultAgentKitCloudApiUrl } from "./constants";
5
+
6
+ export function parsePort(value: string | boolean | undefined, usage = "agentkit dev --port <number>"): number | undefined {
7
+ if (value === undefined) {
8
+ return undefined;
9
+ }
10
+
11
+ if (typeof value !== "string") {
12
+ throw new Error(`Missing port. Usage: ${usage}`);
13
+ }
14
+
15
+ const port = Number(value);
16
+
17
+ if (!Number.isInteger(port) || port <= 0 || port > 65535) {
18
+ throw new Error(`Invalid port. Usage: ${usage}`);
19
+ }
20
+
21
+ return port;
22
+ }
23
+
24
+ export function parseTargetFlag(value: string | boolean | undefined, capability: "build" | "deploy"): string {
25
+ if (value === undefined) {
26
+ return "cloudflare";
27
+ }
28
+
29
+ if (typeof value !== "string") {
30
+ throw new Error(
31
+ `Missing target. Usage: agentkit ${capability} --target ${listTargetsWithCapability(capability).join("|")}`,
32
+ );
33
+ }
34
+
35
+ return value;
36
+ }
37
+
38
+ export function parseCloudApiUrl(value: string | boolean | undefined): string {
39
+ if (value === undefined) {
40
+ return process.env.AGENTKIT_CLOUD_API_URL ?? defaultAgentKitCloudApiUrl;
41
+ }
42
+
43
+ if (typeof value !== "string") {
44
+ throw new Error("Missing API URL. Usage: agentkit deploy --api <url>");
45
+ }
46
+
47
+ return value;
48
+ }
49
+
50
+ export function parseRequiredStringFlag(value: string | boolean | undefined, name: string, usage: string): string {
51
+ if (typeof value !== "string" || value.trim().length === 0) {
52
+ throw new Error(`Missing ${name}. Usage: ${usage}`);
53
+ }
54
+
55
+ return value.trim();
56
+ }
57
+
58
+ export function parseOptionalStringFlag(value: string | boolean | undefined, name: string, usage: string): string | undefined {
59
+ if (value === undefined) {
60
+ return undefined;
61
+ }
62
+
63
+ if (typeof value !== "string" || value.trim().length === 0) {
64
+ throw new Error(`Missing ${name}. Usage: ${usage}`);
65
+ }
66
+
67
+ return value.trim();
68
+ }
69
+
70
+ export async function resolveSecretInputValue(options: {
71
+ name: string | undefined;
72
+ valueParts: string[];
73
+ stdinFlag: string | boolean | undefined;
74
+ fromEnvFlag: string | boolean | undefined;
75
+ fromLocalEnvFlag: string | boolean | undefined;
76
+ localEnvRoot?: string;
77
+ usage: string;
78
+ inlineSensitiveHelp?: string;
79
+ }): Promise<string> {
80
+ const { name, valueParts, stdinFlag, fromEnvFlag, fromLocalEnvFlag, localEnvRoot, usage, inlineSensitiveHelp } = options;
81
+
82
+ if (!name) {
83
+ throw new Error(`Missing name. Usage: ${usage}`);
84
+ }
85
+
86
+ const hasInlineValue = valueParts.length > 0;
87
+ const hasStdin = stdinFlag !== undefined;
88
+ const hasFromEnv = fromEnvFlag !== undefined;
89
+ const hasFromLocalEnv = fromLocalEnvFlag !== undefined;
90
+ const inputModes = [hasInlineValue, hasStdin, hasFromEnv, hasFromLocalEnv].filter(Boolean).length;
91
+
92
+ if (inputModes !== 1) {
93
+ throw new Error(`Provide exactly one value source. Usage: ${usage}`);
94
+ }
95
+
96
+ let value: string;
97
+
98
+ if (hasInlineValue) {
99
+ value = valueParts.join(" ");
100
+ if (looksLikeSecretName(name)) {
101
+ console.error(
102
+ `Warning: ${name} looks sensitive. ${inlineSensitiveHelp ?? "Prefer --stdin or --from-env so the value does not enter shell history."}`,
103
+ );
104
+ }
105
+ } else if (hasStdin) {
106
+ if (stdinFlag !== true) {
107
+ throw new Error(`--stdin does not take a value. Usage: ${usage}`);
108
+ }
109
+
110
+ value = stripOneTrailingNewline(await readStdinText());
111
+ } else if (hasFromEnv) {
112
+ const envName = fromEnvFlag === true ? name : parseRequiredStringFlag(fromEnvFlag, "env name", usage);
113
+ const envValue = process.env[envName];
114
+
115
+ if (envValue === undefined) {
116
+ throw new AgentKitError("secret_not_found", `Environment variable ${envName} is not set.`);
117
+ }
118
+
119
+ value = envValue;
120
+ } else {
121
+ if (fromLocalEnvFlag !== true) {
122
+ throw new Error(`--from-local-env does not take a value. Usage: ${usage}`);
123
+ }
124
+
125
+ if (!localEnvRoot) {
126
+ throw new Error(`--from-local-env is not available for this command. Usage: ${usage}`);
127
+ }
128
+
129
+ const localEnv = await loadCapsuleEnv(localEnvRoot, {});
130
+ const localValue = localEnv[name];
131
+
132
+ if (localValue === undefined) {
133
+ throw new AgentKitError("secret_not_found", `Local .env does not contain ${name}.`);
134
+ }
135
+
136
+ value = localValue;
137
+ }
138
+
139
+ if (value.length === 0) {
140
+ throw new Error(`Secret value cannot be empty. Usage: ${usage}`);
141
+ }
142
+
143
+ return value;
144
+ }
145
+
146
+ function looksLikeSecretName(name: string): boolean {
147
+ return /(?:SECRET|TOKEN|KEY|PASSWORD|CREDENTIAL|PRIVATE)/i.test(name);
148
+ }
149
+
150
+ async function readStdinText(): Promise<string> {
151
+ const chunks: Buffer[] = [];
152
+
153
+ for await (const chunk of process.stdin) {
154
+ chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
155
+ }
156
+
157
+ return Buffer.concat(chunks).toString("utf8");
158
+ }
159
+
160
+ function stripOneTrailingNewline(value: string): string {
161
+ return value.replace(/\r?\n$/, "");
162
+ }
@@ -0,0 +1,158 @@
1
+ export function renderHelp(): string {
2
+ return `AgentKit
3
+
4
+ Create, run, inspect, and deploy Agent Capsules.
5
+
6
+ Quick start:
7
+ agentkit new support-agent --template support
8
+ cd support-agent
9
+ npm run dev
10
+ npm run chat -- --message "hello"
11
+
12
+ Usage:
13
+ agentkit <command> [options]
14
+
15
+ Start:
16
+ agentkit new <name> [--template blank|support|dentista] [--no-install]
17
+ agentkit dev
18
+ agentkit open
19
+ agentkit chat-ui --deploy
20
+ agentkit chat --message <text> [--conversation-id <id>]
21
+ agentkit inspect
22
+
23
+ Build:
24
+ agentkit tool <name> [--input <path-or-json>]
25
+ agentkit db migrate
26
+ agentkit eval run
27
+ agentkit conversations list
28
+
29
+ Deploy:
30
+ agentkit login --token <token>
31
+ agentkit deploy doctor
32
+ agentkit secret set <NAME> --stdin
33
+ agentkit secret sync --from-local
34
+ agentkit deploy --smoke "hello"
35
+ agentkit deploy status
36
+
37
+ More:
38
+ agentkit channels ...
39
+ agentkit access token ...
40
+ agentkit env ...
41
+ agentkit docs full
42
+ agentkit help commands
43
+ `;
44
+ }
45
+
46
+ export function renderCommandReference(): string {
47
+ return `AgentKit Command Reference
48
+
49
+ Usage:
50
+ agentkit new <name> [--template blank|support|dentista] [--no-install]
51
+ agentkit dev [--port <number>]
52
+ agentkit open
53
+ agentkit chat-ui --deploy [--port <number>] [--token-file <path>]
54
+ agentkit chat --message <text> [--conversation-id <id>]
55
+ agentkit tool <name> [--input <path-or-json>]
56
+ agentkit db migrate
57
+ agentkit db reset --yes
58
+ agentkit db shell
59
+ agentkit db seed [--file <path>]
60
+ agentkit eval run
61
+ agentkit conversations list
62
+ agentkit conversations show <conversation-id>
63
+ agentkit channels list
64
+ agentkit channels add <website|telegram|whatsapp> <name> [--provider zapster|meta] [--api <url>]
65
+ agentkit channels setup <name> [--apply] [--api <url>]
66
+ agentkit channels status <name> [--api <url>]
67
+ agentkit channels test <name> [--message <text>] [--fixture <path>] [--api <url>]
68
+ agentkit channels deliveries list <name> [--api <url>]
69
+ agentkit channels deliveries show <delivery-id> [--api <url>]
70
+ agentkit inspect
71
+ agentkit build [--target cloudflare|container]
72
+ agentkit login --token <token> [--api <url>]
73
+ agentkit logout
74
+ agentkit deploy [--target cloudflare|vps] [--host <host>] [--api <url>] [--dry-run] [--anonymous] [--local-wrangler] [--smoke <message>]
75
+ agentkit deploy doctor [--api <url>] [--anonymous]
76
+ agentkit deploy smoke [--message <text>] [--api <url>]
77
+ agentkit deploy status [--api <url>]
78
+ agentkit deploy pause [--api <url>]
79
+ agentkit deploy resume [--api <url>]
80
+ agentkit secret set <NAME> <VALUE> [--api <url>]
81
+ agentkit secret set <NAME> --stdin [--api <url>]
82
+ agentkit secret set <NAME> --from-env [ENV_NAME] [--api <url>]
83
+ agentkit secret set <NAME> --from-local-env [--api <url>]
84
+ agentkit secret sync --from-local [--api <url>]
85
+ agentkit secret list [--api <url>]
86
+ agentkit secret unset <NAME> [--api <url>]
87
+ agentkit access token create <name> [--api <url>] [--out <path>]
88
+ agentkit access token list [--api <url>]
89
+ agentkit access token revoke <token-id> [--api <url>]
90
+ agentkit env set <NAME> <VALUE>
91
+ agentkit env set <NAME> --stdin
92
+ agentkit env set <NAME> --from-env [ENV_NAME]
93
+ agentkit env list
94
+ agentkit env unset <NAME>
95
+ agentkit docs path
96
+ agentkit docs llms
97
+ agentkit docs full
98
+ agentkit handoff codex [goal]
99
+ agentkit help commands
100
+ agentkit --help
101
+
102
+ Commands:
103
+ new Create a new Agent Capsule
104
+ dev Run the Agent Capsule locally
105
+ open Open the local Agent Capsule UI if it is already running
106
+ chat-ui Run a local chat UI, optionally pointed at a hosted deploy
107
+ chat Send one message to the local Agent Capsule
108
+ tool Run one registered tool directly
109
+ db Manage the local SQLite database
110
+ eval Run local eval files
111
+ conversations List and inspect stored local conversations
112
+ channels Manage hosted channel resources
113
+ inspect Print machine-readable Agent Capsule state
114
+ build Build a hosted deploy artifact
115
+ login Store an AgentKit Cloud alpha token outside the capsule
116
+ logout Remove the stored AgentKit Cloud alpha token
117
+ deploy Build and send a hosted artifact to AgentKit Cloud
118
+ secret Manage hosted AgentKit Cloud secrets without readback
119
+ access Manage hosted deploy access tokens
120
+ env Manage local .env values without opening code
121
+ docs Print AgentKit docs locations
122
+ handoff Print a ready-to-paste prompt for another coding agent
123
+ help Print focused help or the full command reference
124
+
125
+ Examples:
126
+ agentkit new support-agent --template support
127
+ cd support-agent
128
+ agentkit dev
129
+ agentkit open
130
+ agentkit tool lookup_order --input '{"orderId":"A100"}'
131
+ agentkit eval run
132
+
133
+ agentkit new clara-dentista --template dentista
134
+ `;
135
+ }
136
+
137
+ export function renderCommandHelp(command: string): string {
138
+ const usage: Record<string, string> = {
139
+ new: "agentkit new <name> [--template blank|support|dentista] [--no-install]",
140
+ dev: "agentkit dev [--port <number>]",
141
+ open: "agentkit open",
142
+ "chat-ui": "agentkit chat-ui --deploy [--port <number>] [--token-file <path>]",
143
+ chat: 'agentkit chat --message "hello" [--conversation-id <id>]',
144
+ tool: "agentkit tool <name> [--input <path-or-json>]",
145
+ deploy:
146
+ 'agentkit deploy [--smoke "hello"] | agentkit deploy smoke [--message "hello"] | agentkit deploy doctor | status | pause | resume',
147
+ secret:
148
+ "agentkit secret set <NAME> --stdin | --from-env [ENV_NAME] | --from-local-env | agentkit secret sync --from-local | list | unset <NAME>",
149
+ access: "agentkit access token create <name> [--out <path>] | list | revoke <token-id>",
150
+ env: "agentkit env set <NAME> --stdin | --from-env [ENV_NAME] | list | unset <NAME>",
151
+ docs: "agentkit docs path | llms | full",
152
+ handoff: "agentkit handoff codex [goal] | agentkit handoff claude [goal]",
153
+ };
154
+
155
+ return `Usage: ${usage[command] ?? "agentkit <command> [options]"}
156
+
157
+ Run \`agentkit help commands\` for the full command reference.`;
158
+ }