@kalphq/cli 0.0.2 → 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/dist/add-KRHLYYTO.js +138 -0
- package/dist/add-KRHLYYTO.js.map +1 -0
- package/dist/chunk-6LLXGS2P.js +25 -0
- package/dist/chunk-6LLXGS2P.js.map +1 -0
- package/dist/chunk-INB3LG6O.js +25 -0
- package/dist/chunk-INB3LG6O.js.map +1 -0
- package/dist/chunk-MMS3GWBG.js +50 -0
- package/dist/chunk-MMS3GWBG.js.map +1 -0
- package/dist/create-7J5R6OVF.js +82 -0
- package/dist/create-7J5R6OVF.js.map +1 -0
- package/dist/delete-47ZP6XRB.js +144 -0
- package/dist/delete-47ZP6XRB.js.map +1 -0
- package/dist/index.js +54 -4
- package/dist/index.js.map +1 -1
- package/dist/link-WZQSR2TM.js +36 -0
- package/dist/link-WZQSR2TM.js.map +1 -0
- package/dist/list-3ZQIFUOT.js +119 -0
- package/dist/list-3ZQIFUOT.js.map +1 -0
- package/dist/login-JYPWGL6P.js +38 -0
- package/dist/login-JYPWGL6P.js.map +1 -0
- package/dist/logout-V67DZZXO.js +31 -0
- package/dist/logout-V67DZZXO.js.map +1 -0
- package/dist/push-RBTBXCP7.js +205 -0
- package/dist/push-RBTBXCP7.js.map +1 -0
- package/dist/secrets-KFMVBKJQ.js +49 -0
- package/dist/secrets-KFMVBKJQ.js.map +1 -0
- package/dist/sync-YFM5P3IS.js +120 -0
- package/dist/sync-YFM5P3IS.js.map +1 -0
- package/package.json +11 -11
- package/dist/agents/b2b-sales/signals/.gitkeep +0 -0
- package/dist/agents/b2b-sales/webhooks/.gitkeep +0 -0
- package/dist/agents/customer-support/signals/.gitkeep +0 -0
- package/dist/agents/customer-support/webhooks/.gitkeep +0 -0
- package/dist/agents/financial-agent/signals/.gitkeep +0 -0
- package/dist/agents/financial-agent/webhooks/.gitkeep +0 -0
- package/dist/agents/minimal/signals/.gitkeep +0 -0
- package/dist/agents/minimal/webhooks/.gitkeep +0 -0
- package/dist/build-ZMN2247N.js +0 -121
- package/dist/build-ZMN2247N.js.map +0 -1
- package/dist/chunk-BO2MEQKM.js +0 -121
- package/dist/chunk-BO2MEQKM.js.map +0 -1
- package/dist/create-ZNKKOQLH.js +0 -118
- package/dist/create-ZNKKOQLH.js.map +0 -1
- package/dist/init-7FSWWKI5.js +0 -66
- package/dist/init-7FSWWKI5.js.map +0 -1
- package/dist/templates/agents/b2b-sales/signals/.gitkeep +0 -0
- package/dist/templates/agents/b2b-sales/webhooks/.gitkeep +0 -0
- package/dist/templates/agents/customer-support/signals/.gitkeep +0 -0
- package/dist/templates/agents/customer-support/webhooks/.gitkeep +0 -0
- package/dist/templates/agents/financial-agent/signals/.gitkeep +0 -0
- package/dist/templates/agents/financial-agent/webhooks/.gitkeep +0 -0
- package/dist/templates/agents/minimal/signals/.gitkeep +0 -0
- package/dist/templates/agents/minimal/webhooks/.gitkeep +0 -0
- package/templates/agents/b2b-sales/index.ts +0 -28
- package/templates/agents/b2b-sales/signals/.gitkeep +0 -0
- package/templates/agents/b2b-sales/steps/score-lead.ts +0 -24
- package/templates/agents/b2b-sales/tools/enrich-company.ts +0 -17
- package/templates/agents/b2b-sales/webhooks/.gitkeep +0 -0
- package/templates/agents/customer-support/index.ts +0 -28
- package/templates/agents/customer-support/signals/.gitkeep +0 -0
- package/templates/agents/customer-support/steps/classify-ticket.ts +0 -22
- package/templates/agents/customer-support/tools/search-kb.ts +0 -13
- package/templates/agents/customer-support/webhooks/.gitkeep +0 -0
- package/templates/agents/financial-agent/index.ts +0 -28
- package/templates/agents/financial-agent/signals/.gitkeep +0 -0
- package/templates/agents/financial-agent/steps/analyze-signal.ts +0 -26
- package/templates/agents/financial-agent/tools/fetch-market-data.ts +0 -13
- package/templates/agents/financial-agent/webhooks/.gitkeep +0 -0
- package/templates/agents/minimal/index.ts +0 -16
- package/templates/agents/minimal/signals/.gitkeep +0 -0
- package/templates/agents/minimal/steps/example-step.ts +0 -13
- package/templates/agents/minimal/tools/example-tool.ts +0 -13
- package/templates/agents/minimal/webhooks/.gitkeep +0 -0
- package/templates/project/meta/deployed.json +0 -1
- package/templates/project/package.json +0 -13
- package/templates/project/tsconfig.json +0 -14
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// src/commands/link.ts
|
|
4
|
+
import { defineCommand } from "citty";
|
|
5
|
+
import * as p from "@clack/prompts";
|
|
6
|
+
import pc from "picocolors";
|
|
7
|
+
import { mkdir, writeFile } from "fs/promises";
|
|
8
|
+
import { join } from "path";
|
|
9
|
+
var LOGO = "\u{1F98B}";
|
|
10
|
+
var link_default = defineCommand({
|
|
11
|
+
meta: { name: "link", description: "Link project to Kalp cloud" },
|
|
12
|
+
async run() {
|
|
13
|
+
const cwd = process.cwd();
|
|
14
|
+
p.intro(`${LOGO} ${pc.bold("kalp link")}`);
|
|
15
|
+
const s = p.spinner();
|
|
16
|
+
s.start("Linking to workspace");
|
|
17
|
+
const tempDir = join(cwd, ".temp");
|
|
18
|
+
await mkdir(tempDir, { recursive: true });
|
|
19
|
+
const workspaceConfig = {
|
|
20
|
+
workspaceId: "mock-workspace-id",
|
|
21
|
+
linkedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
22
|
+
projectPath: cwd
|
|
23
|
+
};
|
|
24
|
+
await writeFile(
|
|
25
|
+
join(tempDir, "workspace.json"),
|
|
26
|
+
JSON.stringify(workspaceConfig, null, 2),
|
|
27
|
+
"utf-8"
|
|
28
|
+
);
|
|
29
|
+
s.stop("Workspace linked");
|
|
30
|
+
p.outro(pc.green("Project linked to Kalp Cloud"));
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
export {
|
|
34
|
+
link_default as default
|
|
35
|
+
};
|
|
36
|
+
//# sourceMappingURL=link-WZQSR2TM.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/commands/link.ts"],"sourcesContent":["import { defineCommand } from \"citty\";\nimport * as p from \"@clack/prompts\";\nimport pc from \"picocolors\";\nimport { mkdir, writeFile } from \"node:fs/promises\";\nimport { join } from \"node:path\";\n\nconst LOGO = \"🦋\";\n\nexport default defineCommand({\n meta: { name: \"link\", description: \"Link project to Kalp cloud\" },\n async run() {\n const cwd = process.cwd();\n\n p.intro(`${LOGO} ${pc.bold(\"kalp link\")}`);\n\n const s = p.spinner();\n s.start(\"Linking to workspace\");\n\n // Create .temp directory and workspace config (project local)\n const tempDir = join(cwd, \".temp\");\n await mkdir(tempDir, { recursive: true });\n\n // TODO: Get actual workspace ID from API after login\n const workspaceConfig = {\n workspaceId: \"mock-workspace-id\",\n linkedAt: new Date().toISOString(),\n projectPath: cwd,\n };\n\n await writeFile(\n join(tempDir, \"workspace.json\"),\n JSON.stringify(workspaceConfig, null, 2),\n \"utf-8\",\n );\n\n s.stop(\"Workspace linked\");\n p.outro(pc.green(\"Project linked to Kalp Cloud\"));\n },\n});\n"],"mappings":";;;AAAA,SAAS,qBAAqB;AAC9B,YAAY,OAAO;AACnB,OAAO,QAAQ;AACf,SAAS,OAAO,iBAAiB;AACjC,SAAS,YAAY;AAErB,IAAM,OAAO;AAEb,IAAO,eAAQ,cAAc;AAAA,EAC3B,MAAM,EAAE,MAAM,QAAQ,aAAa,6BAA6B;AAAA,EAChE,MAAM,MAAM;AACV,UAAM,MAAM,QAAQ,IAAI;AAExB,IAAE,QAAM,GAAG,IAAI,IAAI,GAAG,KAAK,WAAW,CAAC,EAAE;AAEzC,UAAM,IAAM,UAAQ;AACpB,MAAE,MAAM,sBAAsB;AAG9B,UAAM,UAAU,KAAK,KAAK,OAAO;AACjC,UAAM,MAAM,SAAS,EAAE,WAAW,KAAK,CAAC;AAGxC,UAAM,kBAAkB;AAAA,MACtB,aAAa;AAAA,MACb,WAAU,oBAAI,KAAK,GAAE,YAAY;AAAA,MACjC,aAAa;AAAA,IACf;AAEA,UAAM;AAAA,MACJ,KAAK,SAAS,gBAAgB;AAAA,MAC9B,KAAK,UAAU,iBAAiB,MAAM,CAAC;AAAA,MACvC;AAAA,IACF;AAEA,MAAE,KAAK,kBAAkB;AACzB,IAAE,QAAM,GAAG,MAAM,8BAA8B,CAAC;AAAA,EAClD;AACF,CAAC;","names":[]}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
getAuthToken
|
|
4
|
+
} from "./chunk-6LLXGS2P.js";
|
|
5
|
+
|
|
6
|
+
// src/commands/secrets/list.ts
|
|
7
|
+
import { defineCommand } from "citty";
|
|
8
|
+
import * as p from "@clack/prompts";
|
|
9
|
+
import pc from "picocolors";
|
|
10
|
+
import { readFile } from "fs/promises";
|
|
11
|
+
import { join } from "path";
|
|
12
|
+
var LOGO = "\u{1F98B}";
|
|
13
|
+
async function fetchSecretsFromCloud() {
|
|
14
|
+
return [
|
|
15
|
+
{ key: "STRIPE_SECRET_KEY", createdAt: "2024-01-15T10:30:00Z" },
|
|
16
|
+
{ key: "OPENAI_API_KEY", createdAt: "2024-01-16T14:22:00Z" }
|
|
17
|
+
];
|
|
18
|
+
}
|
|
19
|
+
async function readLocalSecrets(cwd) {
|
|
20
|
+
try {
|
|
21
|
+
const configPath = join(cwd, "kalp.config.ts");
|
|
22
|
+
const content = await readFile(configPath, "utf-8");
|
|
23
|
+
const match = content.match(/secrets:\s*\[([^\]]*)\]/);
|
|
24
|
+
if (!match) return [];
|
|
25
|
+
const secretsStr = match[1];
|
|
26
|
+
const secrets = [];
|
|
27
|
+
const regex = /["']([^"']+)["']/g;
|
|
28
|
+
if (!secretsStr) {
|
|
29
|
+
return [];
|
|
30
|
+
}
|
|
31
|
+
let m;
|
|
32
|
+
while ((m = regex.exec(secretsStr)) !== null) {
|
|
33
|
+
if (m[1]) {
|
|
34
|
+
secrets.push(m[1]);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return secrets;
|
|
38
|
+
} catch {
|
|
39
|
+
return [];
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
var list_default = defineCommand({
|
|
43
|
+
meta: {
|
|
44
|
+
name: "list",
|
|
45
|
+
description: "List all secrets from Kalp Cloud"
|
|
46
|
+
},
|
|
47
|
+
args: {
|
|
48
|
+
help: {
|
|
49
|
+
type: "boolean",
|
|
50
|
+
alias: "h",
|
|
51
|
+
description: "Show help",
|
|
52
|
+
default: false
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
async run({ args }) {
|
|
56
|
+
const cwd = process.cwd();
|
|
57
|
+
if (args.help) {
|
|
58
|
+
p.log.info(`${pc.bold("Usage")}: kalp secrets list`);
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
p.intro(`${LOGO} ${pc.bold("kalp secrets list")}`);
|
|
62
|
+
const token = await getAuthToken();
|
|
63
|
+
if (!token) {
|
|
64
|
+
p.log.warn(pc.yellow("Not logged in. Run `kalp login` first."));
|
|
65
|
+
p.outro("Authentication required");
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
const s = p.spinner();
|
|
69
|
+
s.start("Fetching secrets from Kalp Cloud...");
|
|
70
|
+
try {
|
|
71
|
+
const [cloudSecrets, localSecrets] = await Promise.all([
|
|
72
|
+
fetchSecretsFromCloud(),
|
|
73
|
+
readLocalSecrets(cwd)
|
|
74
|
+
]);
|
|
75
|
+
s.stop(`Found ${cloudSecrets.length} secrets`);
|
|
76
|
+
if (cloudSecrets.length === 0) {
|
|
77
|
+
p.log.info(pc.dim("No secrets found in Kalp Cloud."));
|
|
78
|
+
p.log.info(pc.dim(`Add secrets with: ${pc.cyan("kalp secrets add")}`));
|
|
79
|
+
} else {
|
|
80
|
+
console.log("");
|
|
81
|
+
p.log.info(pc.bold("Cloud Secrets:"));
|
|
82
|
+
for (const secret of cloudSecrets) {
|
|
83
|
+
const isSynced = localSecrets.includes(secret.key);
|
|
84
|
+
const syncIcon = isSynced ? pc.green("\u2713") : pc.yellow("\u25CB");
|
|
85
|
+
console.log(
|
|
86
|
+
` ${syncIcon} ${pc.cyan(secret.key)} ${pc.dim(`(${secret.createdAt})`)}`
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
if (localSecrets.length > 0) {
|
|
90
|
+
const unsynced = localSecrets.filter(
|
|
91
|
+
(k) => !cloudSecrets.some((s2) => s2.key === k)
|
|
92
|
+
);
|
|
93
|
+
if (unsynced.length > 0) {
|
|
94
|
+
console.log("");
|
|
95
|
+
p.log.warn(
|
|
96
|
+
pc.yellow(
|
|
97
|
+
`Local-only secrets (not synced): ${unsynced.join(", ")}`
|
|
98
|
+
)
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
p.outro("Done");
|
|
104
|
+
} catch (error) {
|
|
105
|
+
s.stop("Failed to fetch secrets");
|
|
106
|
+
p.log.error(
|
|
107
|
+
pc.red(
|
|
108
|
+
`Error: ${error instanceof Error ? error.message : String(error)}`
|
|
109
|
+
)
|
|
110
|
+
);
|
|
111
|
+
p.outro("Failed");
|
|
112
|
+
process.exit(1);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
export {
|
|
117
|
+
list_default as default
|
|
118
|
+
};
|
|
119
|
+
//# sourceMappingURL=list-3ZQIFUOT.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/commands/secrets/list.ts"],"sourcesContent":["import { defineCommand } from \"citty\";\nimport * as p from \"@clack/prompts\";\nimport pc from \"picocolors\";\nimport { readFile } from \"node:fs/promises\";\nimport { join } from \"node:path\";\nimport { getAuthToken } from \"@/utils/auth\";\n\nconst LOGO = \"🦋\";\n\ninterface CloudSecret {\n key: string;\n createdAt: string;\n}\n\nasync function fetchSecretsFromCloud(): Promise<CloudSecret[]> {\n return [\n { key: \"STRIPE_SECRET_KEY\", createdAt: \"2024-01-15T10:30:00Z\" },\n { key: \"OPENAI_API_KEY\", createdAt: \"2024-01-16T14:22:00Z\" },\n ];\n}\n\nasync function readLocalSecrets(cwd: string): Promise<string[]> {\n try {\n const configPath = join(cwd, \"kalp.config.ts\");\n const content = await readFile(configPath, \"utf-8\");\n // Extract secrets array from config\n const match = content.match(/secrets:\\s*\\[([^\\]]*)\\]/);\n if (!match) return [];\n const secretsStr = match[1];\n // Extract quoted strings\n const secrets: string[] = [];\n const regex = /[\"']([^\"']+)[\"']/g;\n\n if (!secretsStr) {\n return [];\n }\n\n let m: RegExpExecArray | null;\n while ((m = regex.exec(secretsStr)) !== null) {\n if (m[1]) {\n secrets.push(m[1]);\n }\n }\n return secrets;\n } catch {\n return [];\n }\n}\n\nexport default defineCommand({\n meta: {\n name: \"list\",\n description: \"List all secrets from Kalp Cloud\",\n },\n args: {\n help: {\n type: \"boolean\",\n alias: \"h\",\n description: \"Show help\",\n default: false,\n },\n },\n async run({ args }) {\n const cwd = process.cwd();\n\n if (args.help) {\n p.log.info(`${pc.bold(\"Usage\")}: kalp secrets list`);\n return;\n }\n\n p.intro(`${LOGO} ${pc.bold(\"kalp secrets list\")}`);\n\n const token = await getAuthToken();\n if (!token) {\n p.log.warn(pc.yellow(\"Not logged in. Run `kalp login` first.\"));\n p.outro(\"Authentication required\");\n return;\n }\n\n const s = p.spinner();\n s.start(\"Fetching secrets from Kalp Cloud...\");\n\n try {\n const [cloudSecrets, localSecrets] = await Promise.all([\n fetchSecretsFromCloud(),\n readLocalSecrets(cwd),\n ]);\n\n s.stop(`Found ${cloudSecrets.length} secrets`);\n\n if (cloudSecrets.length === 0) {\n p.log.info(pc.dim(\"No secrets found in Kalp Cloud.\"));\n p.log.info(pc.dim(`Add secrets with: ${pc.cyan(\"kalp secrets add\")}`));\n } else {\n console.log(\"\");\n p.log.info(pc.bold(\"Cloud Secrets:\"));\n for (const secret of cloudSecrets) {\n const isSynced = localSecrets.includes(secret.key);\n const syncIcon = isSynced ? pc.green(\"✓\") : pc.yellow(\"○\");\n console.log(\n ` ${syncIcon} ${pc.cyan(secret.key)} ${pc.dim(`(${secret.createdAt})`)}`,\n );\n }\n\n if (localSecrets.length > 0) {\n const unsynced = localSecrets.filter(\n (k) => !cloudSecrets.some((s) => s.key === k),\n );\n if (unsynced.length > 0) {\n console.log(\"\");\n p.log.warn(\n pc.yellow(\n `Local-only secrets (not synced): ${unsynced.join(\", \")}`,\n ),\n );\n }\n }\n }\n\n p.outro(\"Done\");\n } catch (error) {\n s.stop(\"Failed to fetch secrets\");\n p.log.error(\n pc.red(\n `Error: ${error instanceof Error ? error.message : String(error)}`,\n ),\n );\n p.outro(\"Failed\");\n process.exit(1);\n }\n },\n});\n"],"mappings":";;;;;;AAAA,SAAS,qBAAqB;AAC9B,YAAY,OAAO;AACnB,OAAO,QAAQ;AACf,SAAS,gBAAgB;AACzB,SAAS,YAAY;AAGrB,IAAM,OAAO;AAOb,eAAe,wBAAgD;AAC7D,SAAO;AAAA,IACL,EAAE,KAAK,qBAAqB,WAAW,uBAAuB;AAAA,IAC9D,EAAE,KAAK,kBAAkB,WAAW,uBAAuB;AAAA,EAC7D;AACF;AAEA,eAAe,iBAAiB,KAAgC;AAC9D,MAAI;AACF,UAAM,aAAa,KAAK,KAAK,gBAAgB;AAC7C,UAAM,UAAU,MAAM,SAAS,YAAY,OAAO;AAElD,UAAM,QAAQ,QAAQ,MAAM,yBAAyB;AACrD,QAAI,CAAC,MAAO,QAAO,CAAC;AACpB,UAAM,aAAa,MAAM,CAAC;AAE1B,UAAM,UAAoB,CAAC;AAC3B,UAAM,QAAQ;AAEd,QAAI,CAAC,YAAY;AACf,aAAO,CAAC;AAAA,IACV;AAEA,QAAI;AACJ,YAAQ,IAAI,MAAM,KAAK,UAAU,OAAO,MAAM;AAC5C,UAAI,EAAE,CAAC,GAAG;AACR,gBAAQ,KAAK,EAAE,CAAC,CAAC;AAAA,MACnB;AAAA,IACF;AACA,WAAO;AAAA,EACT,QAAQ;AACN,WAAO,CAAC;AAAA,EACV;AACF;AAEA,IAAO,eAAQ,cAAc;AAAA,EAC3B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AI,GAAG,KAAK,OAAO,GAAG,CAAC,IAAI,GAAG,IAAI,IAAI,OAAO,SAAS,GAAG,CAAC;AAAA,UACzE;AAAA,QACF;AAEA,YAAI,aAAa,SAAS,GAAG;AAC3B,gBAAM,WAAW,aAAa;AAAA,YAC5B,CAAC,MAAM,CAAC,aAAa,KAAK,CAACA,OAAMA,GAAE,QAAQ,CAAC;AAAA,UAC9C;AACA,cAAI,SAAS,SAAS,GAAG;AACvB,oBAAQ,IAAI,EAAE;AACd,YAAE,MAAI;AAAA,cACJ,GAAG;AAAA,gBACD,oCAAoC,SAAS,KAAK,IAAI,CAAC;AAAA,cACzD;AAAA,YACF;AAAA,UACF;AAAA,QACF;AAAA,MACF;AAEA,MAAE,QAAM,MAAM;AAAA,IAChB,SAAS,OAAO;AACd,QAAE,KAAK,yBAAyB;AAChC,MAAE,MAAI;AAAA,QACJ,GAAG;AAAA,UACD,UAAU,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,CAAC;AAAA,QAClE;AAAA,MACF;AACA,MAAE,QAAM,QAAQ;AAChB,cAAQ,KAAK,CAAC;AAAA,IAChB;AAAA,EACF;AACF,CAAC;","names":["s"]}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// src/commands/login.ts
|
|
4
|
+
import { defineCommand } from "citty";
|
|
5
|
+
import * as p from "@clack/prompts";
|
|
6
|
+
import pc from "picocolors";
|
|
7
|
+
import { mkdir, writeFile } from "fs/promises";
|
|
8
|
+
import { join } from "path";
|
|
9
|
+
import { homedir } from "os";
|
|
10
|
+
var LOGO = "\u{1F98B}";
|
|
11
|
+
var login_default = defineCommand({
|
|
12
|
+
meta: { name: "login", description: "Authenticate with Kalp" },
|
|
13
|
+
async run() {
|
|
14
|
+
const home = homedir();
|
|
15
|
+
p.intro(`${LOGO} ${pc.bold("kalp login")}`);
|
|
16
|
+
const s = p.spinner();
|
|
17
|
+
s.start("Authenticating...");
|
|
18
|
+
const kalpDir = join(home, ".kalp");
|
|
19
|
+
await mkdir(kalpDir, { recursive: true });
|
|
20
|
+
const authData = {
|
|
21
|
+
token: "mock-token-" + Date.now(),
|
|
22
|
+
email: "user@example.com",
|
|
23
|
+
expiresAt: new Date(Date.now() + 30 * 24 * 60 * 60 * 1e3).toISOString()
|
|
24
|
+
};
|
|
25
|
+
await writeFile(
|
|
26
|
+
join(kalpDir, "auth.json"),
|
|
27
|
+
JSON.stringify(authData, null, 2),
|
|
28
|
+
"utf-8"
|
|
29
|
+
);
|
|
30
|
+
s.stop("Authenticated successfully");
|
|
31
|
+
p.log.success(`Logged in as ${pc.cyan(authData.email)}`);
|
|
32
|
+
p.outro(pc.green("Ready to use Kalp Cloud"));
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
export {
|
|
36
|
+
login_default as default
|
|
37
|
+
};
|
|
38
|
+
//# sourceMappingURL=login-JYPWGL6P.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/commands/login.ts"],"sourcesContent":["import { defineCommand } from \"citty\";\nimport * as p from \"@clack/prompts\";\nimport pc from \"picocolors\";\nimport { mkdir, writeFile } from \"node:fs/promises\";\nimport { join } from \"node:path\";\nimport { homedir } from \"node:os\";\n\nconst LOGO = \"🦋\";\n\nexport default defineCommand({\n meta: { name: \"login\", description: \"Authenticate with Kalp\" },\n async run() {\n const home = homedir();\n\n p.intro(`${LOGO} ${pc.bold(\"kalp login\")}`);\n\n const s = p.spinner();\n s.start(\"Authenticating...\");\n\n // Create ~/.kalp directory (global user config)\n const kalpDir = join(home, \".kalp\");\n await mkdir(kalpDir, { recursive: true });\n\n // Create mock auth.json\n const authData = {\n token: \"mock-token-\" + Date.now(),\n email: \"user@example.com\",\n expiresAt: new Date(Date.now() + 30 * 24 * 60 * 60 * 1000).toISOString(),\n };\n\n await writeFile(\n join(kalpDir, \"auth.json\"),\n JSON.stringify(authData, null, 2),\n \"utf-8\",\n );\n\n s.stop(\"Authenticated successfully\");\n p.log.success(`Logged in as ${pc.cyan(authData.email)}`);\n p.outro(pc.green(\"Ready to use Kalp Cloud\"));\n },\n});\n"],"mappings":";;;AAAA,SAAS,qBAAqB;AAC9B,YAAY,OAAO;AACnB,OAAO,QAAQ;AACf,SAAS,OAAO,iBAAiB;AACjC,SAAS,YAAY;AACrB,SAAS,eAAe;AAExB,IAAM,OAAO;AAEb,IAAO,gBAAQ,cAAc;AAAA,EAC3B,MAAM,EAAE,MAAM,SAAS,aAAa,yBAAyB;AAAA,EAC7D,MAAM,MAAM;AACV,UAAM,OAAO,QAAQ;AAErB,IAAE,QAAM,GAAG,IAAI,IAAI,GAAG,KAAK,YAAY,CAAC,EAAE;AAE1C,UAAM,IAAM,UAAQ;AACpB,MAAE,MAAM,mBAAmB;AAG3B,UAAM,UAAU,KAAK,MAAM,OAAO;AAClC,UAAM,MAAM,SAAS,EAAE,WAAW,KAAK,CAAC;AAGxC,UAAM,WAAW;AAAA,MACf,OAAO,gBAAgB,KAAK,IAAI;AAAA,MAChC,OAAO;AAAA,MACP,WAAW,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,KAAK,KAAK,GAAI,EAAE,YAAY;AAAA,IACzE;AAEA,UAAM;AAAA,MACJ,KAAK,SAAS,WAAW;AAAA,MACzB,KAAK,UAAU,UAAU,MAAM,CAAC;AAAA,MAChC;AAAA,IACF;AAEA,MAAE,KAAK,4BAA4B;AACnC,IAAE,MAAI,QAAQ,gBAAgB,GAAG,KAAK,SAAS,KAAK,CAAC,EAAE;AACvD,IAAE,QAAM,GAAG,MAAM,yBAAyB,CAAC;AAAA,EAC7C;AACF,CAAC;","names":[]}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// src/commands/logout.ts
|
|
4
|
+
import { defineCommand } from "citty";
|
|
5
|
+
import * as p from "@clack/prompts";
|
|
6
|
+
import pc from "picocolors";
|
|
7
|
+
import { rm } from "fs/promises";
|
|
8
|
+
import { join } from "path";
|
|
9
|
+
import { homedir } from "os";
|
|
10
|
+
var LOGO = "\u{1F98B}";
|
|
11
|
+
var logout_default = defineCommand({
|
|
12
|
+
meta: { name: "logout", description: "Sign out from Kalp" },
|
|
13
|
+
async run() {
|
|
14
|
+
const home = homedir();
|
|
15
|
+
p.intro(`${LOGO} ${pc.bold("kalp logout")}`);
|
|
16
|
+
const s = p.spinner();
|
|
17
|
+
s.start("Signing out...");
|
|
18
|
+
try {
|
|
19
|
+
await rm(join(home, ".kalp", "auth.json"), { force: true });
|
|
20
|
+
s.stop("Signed out successfully");
|
|
21
|
+
p.outro(pc.green("Logged out from Kalp"));
|
|
22
|
+
} catch {
|
|
23
|
+
s.stop("Nothing to do");
|
|
24
|
+
p.outro(pc.dim("No active session found"));
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
export {
|
|
29
|
+
logout_default as default
|
|
30
|
+
};
|
|
31
|
+
//# sourceMappingURL=logout-V67DZZXO.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/commands/logout.ts"],"sourcesContent":["import { defineCommand } from \"citty\";\nimport * as p from \"@clack/prompts\";\nimport pc from \"picocolors\";\nimport { rm } from \"node:fs/promises\";\nimport { join } from \"node:path\";\nimport { homedir } from \"node:os\";\n\nconst LOGO = \"🦋\";\n\nexport default defineCommand({\n meta: { name: \"logout\", description: \"Sign out from Kalp\" },\n async run() {\n const home = homedir();\n\n p.intro(`${LOGO} ${pc.bold(\"kalp logout\")}`);\n\n const s = p.spinner();\n s.start(\"Signing out...\");\n\n try {\n await rm(join(home, \".kalp\", \"auth.json\"), { force: true });\n s.stop(\"Signed out successfully\");\n p.outro(pc.green(\"Logged out from Kalp\"));\n } catch {\n s.stop(\"Nothing to do\");\n p.outro(pc.dim(\"No active session found\"));\n }\n },\n});\n"],"mappings":";;;AAAA,SAAS,qBAAqB;AAC9B,YAAY,OAAO;AACnB,OAAO,QAAQ;AACf,SAAS,UAAU;AACnB,SAAS,YAAY;AACrB,SAAS,eAAe;AAExB,IAAM,OAAO;AAEb,IAAO,iBAAQ,cAAc;AAAA,EAC3B,MAAM,EAAE,MAAM,UAAU,aAAa,qBAAqB;AAAA,EAC1D,MAAM,MAAM;AACV,UAAM,OAAO,QAAQ;AAErB,IAAE,QAAM,GAAG,IAAI,IAAI,GAAG,KAAK,aAAa,CAAC,EAAE;AAE3C,UAAM,IAAM,UAAQ;AACpB,MAAE,MAAM,gBAAgB;AAExB,QAAI;AACF,YAAM,GAAG,KAAK,MAAM,SAAS,WAAW,GAAG,EAAE,OAAO,KAAK,CAAC;AAC1D,QAAE,KAAK,yBAAyB;AAChC,MAAE,QAAM,GAAG,MAAM,sBAAsB,CAAC;AAAA,IAC1C,QAAQ;AACN,QAAE,KAAK,eAAe;AACtB,MAAE,QAAM,GAAG,IAAI,yBAAyB,CAAC;AAAA,IAC3C;AAAA,EACF;AACF,CAAC;","names":[]}
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
ensureConfig
|
|
4
|
+
} from "./chunk-INB3LG6O.js";
|
|
5
|
+
|
|
6
|
+
// src/commands/push.ts
|
|
7
|
+
import { access as access2 } from "fs/promises";
|
|
8
|
+
import { join as join3 } from "path";
|
|
9
|
+
import { defineCommand } from "citty";
|
|
10
|
+
import * as p from "@clack/prompts";
|
|
11
|
+
import pc from "picocolors";
|
|
12
|
+
|
|
13
|
+
// src/utils/manifest/index.ts
|
|
14
|
+
import { access } from "fs/promises";
|
|
15
|
+
import { join as join2 } from "path";
|
|
16
|
+
import { compileAgent } from "@kalphq/compiler";
|
|
17
|
+
|
|
18
|
+
// src/utils/manifest/build.ts
|
|
19
|
+
import { existsSync } from "fs";
|
|
20
|
+
import { mkdtemp, readFile, rm } from "fs/promises";
|
|
21
|
+
import { basename, join, resolve } from "path";
|
|
22
|
+
import { pathToFileURL } from "url";
|
|
23
|
+
import { build } from "esbuild";
|
|
24
|
+
async function getHash(payload) {
|
|
25
|
+
const { createHash: createHash2 } = await import("crypto");
|
|
26
|
+
return createHash2("sha256").update(payload).digest("hex");
|
|
27
|
+
}
|
|
28
|
+
async function loadAgentModule(agentPath, cwd) {
|
|
29
|
+
const tempDir = await mkdtemp(join(cwd, ".kalp-temp-"));
|
|
30
|
+
const outFile = join(tempDir, "agent.manifest.mjs");
|
|
31
|
+
await build({
|
|
32
|
+
entryPoints: [agentPath],
|
|
33
|
+
outfile: outFile,
|
|
34
|
+
bundle: true,
|
|
35
|
+
format: "esm",
|
|
36
|
+
platform: "node",
|
|
37
|
+
target: "node18",
|
|
38
|
+
logLevel: "silent",
|
|
39
|
+
packages: "external",
|
|
40
|
+
plugins: [
|
|
41
|
+
{
|
|
42
|
+
name: "relative-js-to-ts",
|
|
43
|
+
setup(buildCtx) {
|
|
44
|
+
buildCtx.onResolve({ filter: /^\.\/.*\.js$/ }, (args) => {
|
|
45
|
+
const resolved = resolve(args.resolveDir, args.path);
|
|
46
|
+
if (existsSync(resolved)) {
|
|
47
|
+
return { path: resolved };
|
|
48
|
+
}
|
|
49
|
+
const tsPath = resolved.replace(/\.js$/, ".ts");
|
|
50
|
+
if (existsSync(tsPath)) {
|
|
51
|
+
return { path: tsPath };
|
|
52
|
+
}
|
|
53
|
+
const tsxPath = resolved.replace(/\.js$/, ".tsx");
|
|
54
|
+
if (existsSync(tsxPath)) {
|
|
55
|
+
return { path: tsxPath };
|
|
56
|
+
}
|
|
57
|
+
return null;
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
name: "tsconfig-paths",
|
|
63
|
+
setup(buildCtx) {
|
|
64
|
+
buildCtx.onResolve({ filter: /^@\// }, (args) => {
|
|
65
|
+
const withoutPrefix = args.path.replace(/^@\//, "");
|
|
66
|
+
const resolved = resolve(cwd, withoutPrefix);
|
|
67
|
+
if (existsSync(resolved)) {
|
|
68
|
+
return { path: resolved };
|
|
69
|
+
}
|
|
70
|
+
const tsPath = resolved + ".ts";
|
|
71
|
+
if (existsSync(tsPath)) {
|
|
72
|
+
return { path: tsPath };
|
|
73
|
+
}
|
|
74
|
+
const tsxPath = resolved + ".tsx";
|
|
75
|
+
if (existsSync(tsxPath)) {
|
|
76
|
+
return { path: tsxPath };
|
|
77
|
+
}
|
|
78
|
+
const indexTsPath = join(resolved, "index.ts");
|
|
79
|
+
if (existsSync(indexTsPath)) {
|
|
80
|
+
return { path: indexTsPath };
|
|
81
|
+
}
|
|
82
|
+
return null;
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
]
|
|
87
|
+
});
|
|
88
|
+
const loaded = await import(`${pathToFileURL(outFile).href}?t=${Date.now()}`);
|
|
89
|
+
const bundledCode = await readFile(outFile, "utf-8");
|
|
90
|
+
const codeHash = await getHash(bundledCode);
|
|
91
|
+
return {
|
|
92
|
+
agent: loaded.default,
|
|
93
|
+
entry: basename(outFile),
|
|
94
|
+
tempDir,
|
|
95
|
+
codeHash
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
async function cleanupTempDir(tempDir) {
|
|
99
|
+
await rm(tempDir, { recursive: true, force: true });
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// src/utils/ir/hashIR.ts
|
|
103
|
+
import { createHash } from "crypto";
|
|
104
|
+
function getIRHash(ir) {
|
|
105
|
+
return createHash("sha256").update(JSON.stringify(ir)).digest("hex");
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// src/utils/manifest/index.ts
|
|
109
|
+
async function readAgentManifest(params) {
|
|
110
|
+
const { cwd, agentName } = params;
|
|
111
|
+
const agentPath = join2(cwd, "agents", agentName, "index.ts");
|
|
112
|
+
await access(agentPath);
|
|
113
|
+
let tempDir;
|
|
114
|
+
try {
|
|
115
|
+
const loaded = await loadAgentModule(agentPath, cwd);
|
|
116
|
+
tempDir = loaded.tempDir;
|
|
117
|
+
const ir = await compileAgent(loaded.agent);
|
|
118
|
+
return {
|
|
119
|
+
format: "kalp-agent-manifest",
|
|
120
|
+
schemaVersion: 2,
|
|
121
|
+
codeHash: loaded.codeHash,
|
|
122
|
+
ir,
|
|
123
|
+
bundle: {
|
|
124
|
+
entry: loaded.entry,
|
|
125
|
+
hash: loaded.codeHash
|
|
126
|
+
},
|
|
127
|
+
metadata: {
|
|
128
|
+
generatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
} finally {
|
|
132
|
+
if (tempDir) {
|
|
133
|
+
await cleanupTempDir(tempDir);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// src/commands/push.ts
|
|
139
|
+
var LOGO = "\u{1F98B}";
|
|
140
|
+
var CLOUD_API = process.env.KALP_CLOUD_URL || "http://localhost:3000";
|
|
141
|
+
var push_default = defineCommand({
|
|
142
|
+
meta: { name: "push", description: "Push agent to Kalp cloud" },
|
|
143
|
+
args: {
|
|
144
|
+
agent: {
|
|
145
|
+
type: "string",
|
|
146
|
+
alias: "a",
|
|
147
|
+
description: "Agent name to push",
|
|
148
|
+
required: false
|
|
149
|
+
}
|
|
150
|
+
},
|
|
151
|
+
async run({ args }) {
|
|
152
|
+
const cwd = process.cwd();
|
|
153
|
+
const agentName = args.agent;
|
|
154
|
+
p.intro(`${LOGO} ${pc.bold("kalp push")}`);
|
|
155
|
+
if (!agentName) {
|
|
156
|
+
p.log.error(`Missing required flag ${pc.cyan("-a <agent-name>")}`);
|
|
157
|
+
process.exit(1);
|
|
158
|
+
}
|
|
159
|
+
try {
|
|
160
|
+
await ensureConfig(cwd);
|
|
161
|
+
} catch {
|
|
162
|
+
p.log.error(`${pc.cyan("kalp.config.ts")} not found`);
|
|
163
|
+
process.exit(1);
|
|
164
|
+
}
|
|
165
|
+
const agentPath = join3(cwd, "agents", agentName, "index.ts");
|
|
166
|
+
try {
|
|
167
|
+
await access2(agentPath);
|
|
168
|
+
} catch {
|
|
169
|
+
p.log.error(`Agent ${pc.cyan(agentName)} not found`);
|
|
170
|
+
process.exit(1);
|
|
171
|
+
}
|
|
172
|
+
const s = p.spinner();
|
|
173
|
+
s.start(`Compiling ${pc.cyan(agentName)}`);
|
|
174
|
+
const manifest = await readAgentManifest({ cwd, agentName });
|
|
175
|
+
const hash = getIRHash(manifest.ir);
|
|
176
|
+
s.stop(`Compiled ${pc.cyan(agentName)}`);
|
|
177
|
+
s.start(`Pushing to cloud`);
|
|
178
|
+
const response = await fetch(`${CLOUD_API}/api/agents/push`, {
|
|
179
|
+
method: "POST",
|
|
180
|
+
headers: { "Content-Type": "application/json" },
|
|
181
|
+
body: JSON.stringify({
|
|
182
|
+
agentName,
|
|
183
|
+
ir: manifest.ir,
|
|
184
|
+
hash
|
|
185
|
+
})
|
|
186
|
+
});
|
|
187
|
+
if (!response.ok) {
|
|
188
|
+
s.stop(pc.red("Push failed"));
|
|
189
|
+
p.log.error(`Cloud error: ${response.status}`);
|
|
190
|
+
process.exit(1);
|
|
191
|
+
}
|
|
192
|
+
s.stop(pc.green("Pushed successfully"));
|
|
193
|
+
console.log("\n" + pc.dim("\u2500".repeat(50)));
|
|
194
|
+
console.log(pc.cyan("\u2714 deployed"));
|
|
195
|
+
console.log("");
|
|
196
|
+
console.log(`${pc.bold("agent:")} ${agentName}`);
|
|
197
|
+
console.log(`${pc.bold("hash:")} ${hash}`);
|
|
198
|
+
console.log(pc.dim("\u2500".repeat(50)) + "\n");
|
|
199
|
+
p.outro(`${LOGO} ${pc.green("Agent pushed to cloud")}`);
|
|
200
|
+
}
|
|
201
|
+
});
|
|
202
|
+
export {
|
|
203
|
+
push_default as default
|
|
204
|
+
};
|
|
205
|
+
//# sourceMappingURL=push-RBTBXCP7.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/commands/push.ts","../src/utils/manifest/index.ts","../src/utils/manifest/build.ts","../src/utils/ir/hashIR.ts"],"sourcesContent":["import { access } from \"node:fs/promises\";\nimport { join } from \"node:path\";\nimport { defineCommand } from \"citty\";\nimport * as p from \"@clack/prompts\";\nimport pc from \"picocolors\";\nimport { ensureConfig } from \"@/utils/fs\";\nimport { readAgentManifest, getIRHash } from \"@/utils/manifest\";\n\nconst LOGO = \"🦋\";\nconst CLOUD_API = process.env.KALP_CLOUD_URL || \"http://localhost:3000\";\n\nexport default defineCommand({\n meta: { name: \"push\", description: \"Push agent to Kalp cloud\" },\n args: {\n agent: {\n type: \"string\",\n alias: \"a\",\n description: \"Agent name to push\",\n required: false,\n },\n },\n async run({ args }) {\n const cwd = process.cwd();\n const agentName = args.agent;\n\n p.intro(`${LOGO} ${pc.bold(\"kalp push\")}`);\n\n if (!agentName) {\n p.log.error(`Missing required flag ${pc.cyan(\"-a <agent-name>\")}`);\n process.exit(1);\n }\n\n try {\n await ensureConfig(cwd);\n } catch {\n p.log.error(`${pc.cyan(\"kalp.config.ts\")} not found`);\n process.exit(1);\n }\n\n const agentPath = join(cwd, \"agents\", agentName, \"index.ts\");\n try {\n await access(agentPath);\n } catch {\n p.log.error(`Agent ${pc.cyan(agentName)} not found`);\n process.exit(1);\n }\n\n const s = p.spinner();\n s.start(`Compiling ${pc.cyan(agentName)}`);\n\n const manifest = await readAgentManifest({ cwd, agentName });\n const hash = getIRHash(manifest.ir);\n\n s.stop(`Compiled ${pc.cyan(agentName)}`);\n s.start(`Pushing to cloud`);\n\n const response = await fetch(`${CLOUD_API}/api/agents/push`, {\n method: \"POST\",\n headers: { \"Content-Type\": \"application/json\" },\n body: JSON.stringify({\n agentName,\n ir: manifest.ir,\n hash,\n }),\n });\n\n if (!response.ok) {\n s.stop(pc.red(\"Push failed\"));\n p.log.error(`Cloud error: ${response.status}`);\n process.exit(1);\n }\n\n s.stop(pc.green(\"Pushed successfully\"));\n\n console.log(\"\\n\" + pc.dim(\"─\".repeat(50)));\n console.log(pc.cyan(\"✔ deployed\"));\n console.log(\"\");\n console.log(`${pc.bold(\"agent:\")} ${agentName}`);\n console.log(`${pc.bold(\"hash:\")} ${hash}`);\n console.log(pc.dim(\"─\".repeat(50)) + \"\\n\");\n\n p.outro(`${LOGO} ${pc.green(\"Agent pushed to cloud\")}`);\n },\n});\n","import { access } from \"node:fs/promises\";\nimport { join } from \"node:path\";\nimport { compileAgent } from \"@kalphq/compiler\";\nimport { loadAgentModule, cleanupTempDir } from \"@/utils/manifest/build\";\nimport type { AgentManifestV2 } from \"@/utils/manifest/types\";\n\nexport type {\n AgentManifestV2,\n LoadedAgentModule,\n} from \"@/utils/manifest/types\";\n\nexport { asRecord, asString, asArray } from \"@/utils/manifest/types\";\n\nexport { loadAgentModule, cleanupTempDir } from \"@/utils/manifest/build\";\n\nexport { getManifestHash } from \"@/utils/manifest/hash\";\n\nexport { getIRHash } from \"@/utils/ir/hashIR\";\n\nexport async function readAgentManifest(params: {\n cwd: string;\n agentName: string;\n}): Promise<AgentManifestV2> {\n const { cwd, agentName } = params;\n const agentPath = join(cwd, \"agents\", agentName, \"index.ts\");\n await access(agentPath);\n\n let tempDir: string | undefined;\n\n try {\n const loaded = await loadAgentModule(agentPath, cwd);\n tempDir = loaded.tempDir;\n\n const ir = await compileAgent(loaded.agent);\n\n return {\n format: \"kalp-agent-manifest\",\n schemaVersion: 2,\n codeHash: loaded.codeHash,\n ir,\n bundle: {\n entry: loaded.entry,\n hash: loaded.codeHash,\n },\n metadata: {\n generatedAt: new Date().toISOString(),\n },\n };\n } finally {\n if (tempDir) {\n await cleanupTempDir(tempDir);\n }\n }\n}\n","import { existsSync } from \"node:fs\";\nimport { mkdtemp, readFile, rm } from \"node:fs/promises\";\nimport { basename, join, resolve } from \"node:path\";\nimport { pathToFileURL } from \"node:url\";\nimport { build } from \"esbuild\";\nimport type { LoadedAgentModule } from \"@/utils/manifest/types\";\n\nasync function getHash(payload: string): Promise<string> {\n const { createHash } = await import(\"node:crypto\");\n return createHash(\"sha256\").update(payload).digest(\"hex\");\n}\n\nexport async function loadAgentModule(\n agentPath: string,\n cwd: string,\n): Promise<LoadedAgentModule> {\n const tempDir = await mkdtemp(join(cwd, \".kalp-temp-\"));\n const outFile = join(tempDir, \"agent.manifest.mjs\");\n\n await build({\n entryPoints: [agentPath],\n outfile: outFile,\n bundle: true,\n format: \"esm\",\n platform: \"node\",\n target: \"node18\",\n logLevel: \"silent\",\n packages: \"external\",\n plugins: [\n {\n name: \"relative-js-to-ts\",\n setup(buildCtx) {\n buildCtx.onResolve({ filter: /^\\.\\/.*\\.js$/ }, (args) => {\n const resolved = resolve(args.resolveDir, args.path);\n if (existsSync(resolved)) {\n return { path: resolved };\n }\n\n const tsPath = resolved.replace(/\\.js$/, \".ts\");\n if (existsSync(tsPath)) {\n return { path: tsPath };\n }\n\n const tsxPath = resolved.replace(/\\.js$/, \".tsx\");\n if (existsSync(tsxPath)) {\n return { path: tsxPath };\n }\n\n return null;\n });\n },\n },\n {\n name: \"tsconfig-paths\",\n setup(buildCtx) {\n buildCtx.onResolve({ filter: /^@\\// }, (args) => {\n const withoutPrefix = args.path.replace(/^@\\//, \"\");\n const resolved = resolve(cwd, withoutPrefix);\n\n if (existsSync(resolved)) {\n return { path: resolved };\n }\n\n const tsPath = resolved + \".ts\";\n if (existsSync(tsPath)) {\n return { path: tsPath };\n }\n\n const tsxPath = resolved + \".tsx\";\n if (existsSync(tsxPath)) {\n return { path: tsxPath };\n }\n\n const indexTsPath = join(resolved, \"index.ts\");\n if (existsSync(indexTsPath)) {\n return { path: indexTsPath };\n }\n\n return null;\n });\n },\n },\n ],\n });\n\n const loaded = (await import(\n `${pathToFileURL(outFile).href}?t=${Date.now()}`\n )) as { default?: unknown };\n\n const bundledCode = await readFile(outFile, \"utf-8\");\n const codeHash = await getHash(bundledCode);\n\n return {\n agent: loaded.default,\n entry: basename(outFile),\n tempDir,\n codeHash,\n };\n}\n\nexport async function cleanupTempDir(tempDir: string): Promise<void> {\n await rm(tempDir, { recursive: true, force: true });\n}\n","import type { IRGraph } from \"@kalphq/sdk\";\nimport { createHash } from \"crypto\";\n\nexport function getIRHash(ir: IRGraph): string {\n return createHash(\"sha256\")\n .update(JSON.stringify(ir))\n .digest(\"hex\");\n}\n"],"mappings":";;;;;;AAAA,SAAS,UAAAA,eAAc;AACvB,SAAS,QAAAC,aAAY;AACrB,SAAS,qBAAqB;AAC9B,YAAY,OAAO;AACnB,OAAO,QAAQ;;;ACJf,SAAS,cAAc;AACvB,SAAS,QAAAC,aAAY;AACrB,SAAS,oBAAoB;;;ACF7B,SAAS,kBAAkB;AAC3B,SAAS,SAAS,UAAU,UAAU;AACtC,SAAS,UAAU,MAAM,eAAe;AACxC,SAAS,qBAAqB;AAC9B,SAAS,aAAa;AAGtB,eAAe,QAAQ,SAAkC;AACvD,QAAM,EAAE,YAAAC,YAAW,IAAI,MAAM,OAAO,QAAa;AACjD,SAAOA,YAAW,QAAQ,EAAE,OAAO,OAAO,EAAE,OAAO,KAAK;AAC1D;AAEA,eAAsB,gBACpB,WACA,KAC4B;AAC5B,QAAM,UAAU,MAAM,QAAQ,KAAK,KAAK,aAAa,CAAC;AACtD,QAAM,UAAU,KAAK,SAAS,oBAAoB;AAElD,QAAM,MAAM;AAAA,IACV,aAAa,CAAC,SAAS;AAAA,IACvB,SAAS;AAAA,IACT,QAAQ;AAAA,IACR,QAAQ;AAAA,IACR,UAAU;AAAA,IACV,QAAQ;AAAA,IACR,UAAU;AAAA,IACV,UAAU;AAAA,IACV,SAAS;AAAA,MACP;AAAA,QACE,MAAM;AAAA,QACN,MAAM,UAAU;AACd,mBAAS,UAAU,EAAE,QAAQ,eAAe,GAAG,CAAC,SAAS;AACvD,kBAAM,WAAW,QAAQ,KAAK,YAAY,KAAK,IAAI;AACnD,gBAAI,WAAW,QAAQ,GAAG;AACxB,qBAAO,EAAE,MAAM,SAAS;AAAA,YAC1B;AAEA,kBAAM,SAAS,SAAS,QAAQ,SAAS,KAAK;AAC9C,gBAAI,WAAW,MAAM,GAAG;AACtB,qBAAO,EAAE,MAAM,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AACd,YAAQ,IAAI,GAAG,GAAG,KAAK,QAAQ,CAAC,IAAI,SAAS,EAAE;AAC/C,YAAQ,IAAI,GAAG,GAAG,KAAK,OAAO,CAAC,IAAI,IAAI,EAAE;AACzC,YAAQ,IAAI,GAAG,IAAI,SAAI,OAAO,EAAE,CAAC,IAAI,IAAI;AAEzC,IAAE,QAAM,GAAG,IAAI,IAAI,GAAG,MAAM,uBAAuB,CAAC,EAAE;AAAA,EACxD;AACF,CAAC;","names":["access","join","join","createHash","join","join","access"]}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// src/commands/secrets/index.ts
|
|
4
|
+
import { defineCommand } from "citty";
|
|
5
|
+
import * as p from "@clack/prompts";
|
|
6
|
+
import pc from "picocolors";
|
|
7
|
+
var LOGO = "\u{1F98B}";
|
|
8
|
+
var secrets_default = defineCommand({
|
|
9
|
+
meta: {
|
|
10
|
+
name: "secrets",
|
|
11
|
+
description: "Manage Kalp Cloud secrets"
|
|
12
|
+
},
|
|
13
|
+
args: {
|
|
14
|
+
help: {
|
|
15
|
+
type: "boolean",
|
|
16
|
+
alias: "h",
|
|
17
|
+
description: "Show help",
|
|
18
|
+
default: false
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
subCommands: {
|
|
22
|
+
list: () => import("./list-3ZQIFUOT.js").then((r) => r.default),
|
|
23
|
+
add: () => import("./add-KRHLYYTO.js").then((r) => r.default),
|
|
24
|
+
delete: () => import("./delete-47ZP6XRB.js").then((r) => r.default),
|
|
25
|
+
sync: () => import("./sync-YFM5P3IS.js").then((r) => r.default)
|
|
26
|
+
},
|
|
27
|
+
run({ args }) {
|
|
28
|
+
if (!args.help) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
p.intro(`${LOGO} ${pc.bold("kalp secrets")}`);
|
|
32
|
+
p.log.message(pc.bold("Available subcommands:"));
|
|
33
|
+
p.log.message(` ${pc.cyan("list")} List secrets from Kalp Cloud`);
|
|
34
|
+
p.log.message(` ${pc.cyan("add")} Add a secret to Kalp Cloud`);
|
|
35
|
+
p.log.message(` ${pc.cyan("delete")} Delete a secret from Kalp Cloud`);
|
|
36
|
+
p.log.message(
|
|
37
|
+
` ${pc.cyan("sync")} Sync secrets from Kalp Cloud to local config`
|
|
38
|
+
);
|
|
39
|
+
p.log.message("");
|
|
40
|
+
p.log.message(
|
|
41
|
+
`Run ${pc.cyan("kalp secrets <subcommand> --help")} for more info.`
|
|
42
|
+
);
|
|
43
|
+
p.outro(pc.dim("Done"));
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
export {
|
|
47
|
+
secrets_default as default
|
|
48
|
+
};
|
|
49
|
+
//# sourceMappingURL=secrets-KFMVBKJQ.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/commands/secrets/index.ts"],"sourcesContent":["import { defineCommand } from \"citty\";\nimport * as p from \"@clack/prompts\";\nimport pc from \"picocolors\";\n\nconst LOGO = \"🦋\";\n\nexport default defineCommand({\n meta: {\n name: \"secrets\",\n description: \"Manage Kalp Cloud secrets\",\n },\n args: {\n help: {\n type: \"boolean\",\n alias: \"h\",\n description: \"Show help\",\n default: false,\n },\n },\n subCommands: {\n list: () => import(\"./list\").then((r) => r.default),\n add: () => import(\"./add\").then((r) => r.default),\n delete: () => import(\"./delete\").then((r) => r.default),\n sync: () => import(\"./sync\").then((r) => r.default),\n },\n run({ args }) {\n if (!args.help) {\n return;\n }\n\n p.intro(`${LOGO} ${pc.bold(\"kalp secrets\")}`);\n p.log.message(pc.bold(\"Available subcommands:\"));\n p.log.message(` ${pc.cyan(\"list\")} List secrets from Kalp Cloud`);\n p.log.message(` ${pc.cyan(\"add\")} Add a secret to Kalp Cloud`);\n p.log.message(` ${pc.cyan(\"delete\")} Delete a secret from Kalp Cloud`);\n p.log.message(\n ` ${pc.cyan(\"sync\")} Sync secrets from Kalp Cloud to local config`,\n );\n p.log.message(\"\");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MAAI;AAAA,MACJ,OAAO,GAAG,KAAK,kCAAkC,CAAC;AAAA,IACpD;AACA,IAAE,QAAM,GAAG,IAAI,MAAM,CAAC;AAAA,EACxB;AACF,CAAC;","names":[]}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
generateTypes
|
|
4
|
+
} from "./chunk-MMS3GWBG.js";
|
|
5
|
+
import {
|
|
6
|
+
getAuthToken
|
|
7
|
+
} from "./chunk-6LLXGS2P.js";
|
|
8
|
+
|
|
9
|
+
// src/commands/secrets/sync.ts
|
|
10
|
+
import { defineCommand } from "citty";
|
|
11
|
+
import * as p from "@clack/prompts";
|
|
12
|
+
import pc from "picocolors";
|
|
13
|
+
import { readFile, writeFile } from "fs/promises";
|
|
14
|
+
import { join } from "path";
|
|
15
|
+
var LOGO = "\u{1F98B}";
|
|
16
|
+
async function fetchSecretsFromCloud() {
|
|
17
|
+
console.log(pc.dim("[Simulated] Fetching secrets from Kalp Cloud..."));
|
|
18
|
+
return [
|
|
19
|
+
{ key: "STRIPE_SECRET_KEY", createdAt: "2024-01-15T10:30:00Z" },
|
|
20
|
+
{ key: "OPENAI_API_KEY", createdAt: "2024-01-16T14:20:00Z" }
|
|
21
|
+
];
|
|
22
|
+
}
|
|
23
|
+
async function replaceSecretsInConfig(cwd, secrets) {
|
|
24
|
+
const configPath = join(cwd, "kalp.config.ts");
|
|
25
|
+
let content;
|
|
26
|
+
try {
|
|
27
|
+
content = await readFile(configPath, "utf-8");
|
|
28
|
+
} catch {
|
|
29
|
+
content = `import { defineConfig } from "@kalphq/sdk";
|
|
30
|
+
|
|
31
|
+
export default defineConfig({
|
|
32
|
+
secrets: [],
|
|
33
|
+
});
|
|
34
|
+
`;
|
|
35
|
+
}
|
|
36
|
+
const secretsArray = secrets.length > 0 ? secrets.map((s) => `"${s}"`).join(", ") : "";
|
|
37
|
+
const newArray = `secrets: [${secretsArray}]`;
|
|
38
|
+
if (content.match(/secrets:\s*\[([^\]]*)\]/)) {
|
|
39
|
+
content = content.replace(/secrets:\s*\[([^\]]*)\]/, newArray);
|
|
40
|
+
} else {
|
|
41
|
+
content = content.replace(
|
|
42
|
+
/defineConfig\({/,
|
|
43
|
+
`defineConfig({
|
|
44
|
+
secrets: [${secretsArray}],`
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
await writeFile(configPath, content, "utf-8");
|
|
48
|
+
}
|
|
49
|
+
var sync_default = defineCommand({
|
|
50
|
+
meta: {
|
|
51
|
+
name: "sync",
|
|
52
|
+
description: "Sync secrets from Kalp Cloud to local config"
|
|
53
|
+
},
|
|
54
|
+
async run() {
|
|
55
|
+
const cwd = process.cwd();
|
|
56
|
+
p.intro(`${LOGO} ${pc.bold("kalp secrets sync")}`);
|
|
57
|
+
const token = await getAuthToken();
|
|
58
|
+
if (!token) {
|
|
59
|
+
p.log.error("Not authenticated. Run 'kalp login' first.");
|
|
60
|
+
process.exit(1);
|
|
61
|
+
}
|
|
62
|
+
const s = p.spinner();
|
|
63
|
+
try {
|
|
64
|
+
s.start("Fetching secrets from Kalp Cloud");
|
|
65
|
+
const cloudSecrets = await fetchSecretsFromCloud();
|
|
66
|
+
s.stop(`Found ${pc.cyan(String(cloudSecrets.length))} secrets in cloud`);
|
|
67
|
+
if (cloudSecrets.length === 0) {
|
|
68
|
+
p.log.warn("No secrets found in Kalp Cloud");
|
|
69
|
+
const shouldClear = await p.confirm({
|
|
70
|
+
message: "Clear local secrets config?",
|
|
71
|
+
initialValue: false
|
|
72
|
+
});
|
|
73
|
+
if (p.isCancel(shouldClear) || !shouldClear) {
|
|
74
|
+
p.outro("Cancelled");
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
s.start("Clearing local secrets");
|
|
78
|
+
await replaceSecretsInConfig(cwd, []);
|
|
79
|
+
await generateTypes(cwd);
|
|
80
|
+
s.stop("Local secrets cleared");
|
|
81
|
+
p.outro("Done");
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
p.log.info(pc.bold("Secrets to sync:"));
|
|
85
|
+
for (const secret of cloudSecrets) {
|
|
86
|
+
console.log(` ${pc.dim("\u2022")} ${pc.cyan(secret.key)}`);
|
|
87
|
+
}
|
|
88
|
+
const confirm2 = await p.confirm({
|
|
89
|
+
message: `Replace local secrets with ${cloudSecrets.length} secrets from cloud?`,
|
|
90
|
+
initialValue: true
|
|
91
|
+
});
|
|
92
|
+
if (p.isCancel(confirm2) || !confirm2) {
|
|
93
|
+
p.outro("Cancelled");
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
s.start("Updating local config");
|
|
97
|
+
const secretKeys = cloudSecrets.map((s2) => s2.key);
|
|
98
|
+
await replaceSecretsInConfig(cwd, secretKeys);
|
|
99
|
+
s.stop("Config updated");
|
|
100
|
+
s.start("Regenerating types");
|
|
101
|
+
await generateTypes(cwd);
|
|
102
|
+
s.stop("Types regenerated");
|
|
103
|
+
p.log.success(pc.green(`Synced ${cloudSecrets.length} secrets`));
|
|
104
|
+
p.outro("Done");
|
|
105
|
+
} catch (error) {
|
|
106
|
+
s.stop("Sync failed");
|
|
107
|
+
p.log.error(
|
|
108
|
+
pc.red(
|
|
109
|
+
`Error: ${error instanceof Error ? error.message : String(error)}`
|
|
110
|
+
)
|
|
111
|
+
);
|
|
112
|
+
p.outro("Failed");
|
|
113
|
+
process.exit(1);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
export {
|
|
118
|
+
sync_default as default
|
|
119
|
+
};
|
|
120
|
+
//# sourceMappingURL=sync-YFM5P3IS.js.map
|