kenobi-pages 0.1.8 → 0.1.10
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/bin/cli.mjs +9 -17
- package/package.json +1 -1
package/bin/cli.mjs
CHANGED
|
@@ -1,19 +1,13 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
var
|
|
3
|
-
`)},"writeGlobalConfig"),
|
|
2
|
+
var C=Object.defineProperty;var t=(e,o)=>C(e,"name",{value:o,configurable:!0});import{existsSync as _,mkdirSync as U,readFileSync as v,writeFileSync as x,appendFileSync as K}from"node:fs";import{readFile as J}from"node:fs/promises";import{homedir as R}from"node:os";import{join as I,resolve as y}from"node:path";import{createInterface as L}from"node:readline";var T="https://kenobi.ai",O=I(R(),".kenobi"),S=I(O,"config.json"),p="KENOBI_PAGES_KEY",E=t(()=>{try{return JSON.parse(v(S,"utf-8"))}catch{return{}}},"readGlobalConfig"),j=t(e=>{U(O,{recursive:!0}),x(S,JSON.stringify(e,null,2)+`
|
|
3
|
+
`)},"writeGlobalConfig"),F=t(()=>{let e=process.env[p]||E().apiKey;return e||(console.error("Error: No API key found."),console.error(""),console.error("Run 'npx kenobi-pages init' to set up your API key."),console.error(""),console.error("Or set the KENOBI_PAGES_KEY environment variable directly."),process.exit(1)),e},"getApiKey"),G=t(()=>(process.env.KENOBI_BASE_URL??E().baseUrl??T).replace(/\/+$/,""),"getBaseUrl"),f=t(async(e,o={})=>{let n=`${G()}${e}`,s=await fetch(n,{method:o.method??"GET",headers:{"x-kenobi-key":F(),"Content-Type":"application/json"},body:o.body?JSON.stringify(o.body):void 0});if(!s.ok){let r=await s.text().catch(()=>"Unknown error"),i=s.status===401||s.status===403?4:s.status===404?3:1;console.error(`Error ${s.status}: ${r}`),process.exit(i)}return s.json()},"fetchKenobi"),h=t(e=>new Promise(o=>{let n=L({input:process.stdin,output:process.stderr});n.question(e,s=>{n.close(),o(s.trim())})}),"prompt"),$=t(()=>new Promise((e,o)=>{let n="";process.stdin.setEncoding("utf-8"),process.stdin.on("data",s=>{n+=s}),process.stdin.on("end",()=>e(n)),process.stdin.on("error",o),process.stdin.isTTY&&e("")}),"readStdin"),N=t(async e=>{let o=e.indexOf("--file");return o!==-1&&e[o+1]?J(e[o+1],"utf-8"):null},"parseFileArg"),D=[".env.local",".env",".env.development",".env.development.local"],B=t(()=>{let e=process.cwd();return D.filter(o=>_(y(e,o)))},"discoverEnvFiles"),W=t((e,o)=>{let n=v(e,"utf-8");if(n.includes(p)){console.error(` \u2713 ${p} already present in ${e.split("/").pop()}`);return}let s=n.endsWith(`
|
|
4
4
|
`)?"":`
|
|
5
|
-
`;
|
|
6
|
-
`),console.error(
|
|
7
|
-
`),console.error(
|
|
8
|
-
${
|
|
9
|
-
`)}
|
|
10
|
-
${
|
|
11
|
-
`:""} ${a}${h}: ${i(d,2)}`}),k=`export interface ${n.title?n.title.replace(/[^a-zA-Z0-9]+/g,""):"PageContent"} {
|
|
12
|
-
${c.join(`
|
|
13
|
-
`)}
|
|
14
|
-
}
|
|
15
|
-
`;console.log(k)},"typesGen"),Z=new Set(["COMPLETED","FAILED","CANCELED","SYSTEM_FAILURE","CRASHED"]),Q=r(e=>{if(typeof e=="string")return e;if(typeof e=="object"&&e!==null&&"message"in e){let o=e.message;if(typeof o=="string")return o}return"Unknown error"},"runStatusErrorMessage"),ee=r(e=>new Promise(o=>setTimeout(o,e)),"sleep"),y=r((e,o)=>{let n=e.indexOf(o);return n!==-1&&e[n+1]?e[n+1]:void 0},"parseFlag"),oe=r(async e=>{let o=e[0];o||(console.error("Usage: kenobi-pages run <workflowId> [--params '<json>'] [--context '<text>']"),process.exit(2));let n=e.slice(1),s={},t=y(n,"--params");if(t)try{s=JSON.parse(t)}catch{console.error("Error: Invalid JSON in --params"),process.exit(2)}let i=y(n,"--context"),l={params:s};i&&(l.context=i);let c=await f(`/api/v1/workflows/${o}/run`,{method:"POST",body:l});console.error(`Run triggered: ${c.runId}`),console.error("Polling for completion...");let u=2e3,k=15e3;for(;;){await ee(u);let a=await f(`/api/v1/workflows/${o}/runs/${c.runId}`);if(console.error(` Status: ${a.status}`),Z.has(a.status)){if(a.status!=="COMPLETED"){let d=Q(a.error);console.error(`
|
|
16
|
-
Run failed (${a.status}): ${d}`),console.log(JSON.stringify(a,null,2)),process.exit(1)}console.log(JSON.stringify(a,null,2));return}u=Math.min(u*1.5,k)}},"runWorkflow"),ne=r(async()=>{let e=await f("/api/v1/workflows");console.log(JSON.stringify(e,null,2))},"listWorkflows"),se=r(async()=>{let e=await f("/api/v1/sources");console.log(JSON.stringify(e,null,2))},"listSources"),re=r(async e=>{let o=await f(`/api/v1/sources/${encodeURIComponent(e)}/sample`);console.log(JSON.stringify(o,null,2))},"sampleSource"),U=r(async e=>{let o=await _(e),n=o?null:e.find(i=>i.startsWith("{")),s=!o&&!n?await C():null,t=o??n??s;(!t||t.trim().length===0)&&(console.error("Error: No JSON provided."),console.error("Pass inline JSON, --file <path>, or pipe to stdin."),process.exit(2));try{return JSON.parse(t)}catch{console.error("Error: Invalid JSON."),process.exit(2)}},"readJsonInput"),te=r(async e=>{let o=y(e,"--name"),n=y(e,"--slug");(!o||!n)&&(console.error("Usage: kenobi-pages workflow create --name '<name>' --slug '<slug>' --config '<json>'"),console.error(" kenobi-pages workflow create --name '<name>' --slug '<slug>' --file config.json"),process.exit(2));let s=y(e,"--description"),t=e.indexOf("--config"),i=t!==-1&&e[t+1]?[e[t+1]]:e,l=await U(i),c={name:o,slug:n,config:l};s&&(c.description=s);let u=await f("/api/v1/workflows",{method:"POST",body:c});console.log(JSON.stringify(u,null,2)),console.error(`Workflow "${o}" created.`)},"workflowCreate"),ie=r(async e=>{let o=e[0];o||(console.error("Usage: kenobi-pages workflow get <workflowId>"),process.exit(2));let n=await f(`/api/v1/workflows/${o}?full=true`);console.log(JSON.stringify(n,null,2))},"workflowGet"),ae=r(async e=>{let o=e[0];o||(console.error("Usage: kenobi-pages workflow update <workflowId> --config '<json>'"),console.error(" kenobi-pages workflow update <workflowId> --file config.json"),process.exit(2));let n=e.slice(1),s=y(n,"--name"),t=y(n,"--description"),i=n.indexOf("--config"),l=i!==-1&&n[i+1]?[n[i+1]]:n,c={};s&&(c.name=s),t!==void 0&&(c.description=t),(n.includes("--config")||n.includes("--file"))&&(c.config=await U(l)),Object.keys(c).length===0&&(console.error("Error: Nothing to update. Pass --name, --description, --config, or --file."),process.exit(2));let k=await f(`/api/v1/workflows/${o}`,{method:"PUT",body:c});console.log(JSON.stringify(k,null,2)),console.error("Workflow updated.")},"workflowUpdate"),ce=r(async e=>{let o=e[0];o||(console.error("Usage: kenobi-pages workflow delete <workflowId>"),process.exit(2)),await f(`/api/v1/workflows/${o}`,{method:"DELETE"}),console.error("Workflow deleted.")},"workflowDelete"),le=`kenobi-pages \u2014 Kenobi Pages CLI
|
|
5
|
+
`;K(e,`${s}${p}="${o}"
|
|
6
|
+
`),console.error(` \u2713 Added ${p} to ${e.split("/").pop()}`)},"appendKeyToEnvFile"),M=t(async()=>{console.error(""),console.error(" Kenobi Pages \u2014 Setup"),console.error(""),console.error(" Find your API key at: https://kenobi.ai/testing/cortex"),console.error("");let e=await h(" Paste your API key (pk_live_... or pk_test_...): ");e||(console.error(" No key provided. Aborting."),process.exit(1)),!e.startsWith("pk_live_")&&!e.startsWith("pk_test_")&&(console.error(` Warning: "${e}" doesn't look like a Kenobi key (expected pk_live_... or pk_test_...).`),(await h(" Continue anyway? (y/N): ")).toLowerCase()!=="y"&&(console.error(" Aborting."),process.exit(1))),console.error("");let o=E();o.apiKey=e,j(o),console.error(` \u2713 Saved key to ${S}`);let n=B();if(n.length>0){console.error(""),console.error(" Found env files in this project:"),n.forEach((i,a)=>console.error(` ${a+1}. ${i}`)),console.error(` ${n.length+1}. Create a new file`),console.error(` ${n.length+2}. Skip`),console.error("");let s=await h(` Which file should ${p} be added to? [1]: `),r=s===""?0:parseInt(s,10)-1;if(r===n.length){let i=await h(" Filename (e.g. .env.local): ");if(i){let a=y(process.cwd(),i);x(a,`${p}="${e}"
|
|
7
|
+
`),console.error(` \u2713 Created ${i} with ${p}`)}}else r>=0&&r<n.length&&W(y(process.cwd(),n[r]),e)}else{console.error("");let s=await h(" No env files found. Create one? (filename or 'n' to skip) [.env.local]: ");if(s.toLowerCase()!=="n"&&s!==""){let r=y(process.cwd(),s);x(r,`${p}="${e}"
|
|
8
|
+
`),console.error(` \u2713 Created ${s} with ${p}`)}else if(s===""){let r=y(process.cwd(),".env.local");x(r,`${p}="${e}"
|
|
9
|
+
`),console.error(` \u2713 Created .env.local with ${p}`)}}console.error(""),console.error(" Done! Your agent can now use kenobi-pages commands."),console.error(" Run 'npx kenobi-pages --help' to see what's available."),console.error("")},"initCommand"),Y=t(async e=>{let o=e[0];o||(console.error("Usage: kenobi-pages schema get <workflowId>"),process.exit(2));let n=await f(`/api/v1/pages/${o}/schema`);console.log(JSON.stringify(n,null,2))},"schemaGet"),H=t(async e=>{let o=e[0];o||(console.error("Usage: kenobi-pages schema push <name> '<json>'"),console.error(" kenobi-pages schema push <name> --file schema.json"),console.error(" echo '<json>' | kenobi-pages schema push <name>"),process.exit(2));let n=e.slice(1),s=await N(n),r=s?null:n.find(m=>m.startsWith("{")),i=!s&&!r?await $():null,a=s??r??i;(!a||a.trim().length===0)&&(console.error("Error: No schema provided."),console.error("Pass inline JSON, --file <path>, or pipe to stdin."),process.exit(2));let c;try{c=JSON.parse(a)}catch{console.error("Error: Invalid JSON."),process.exit(2)}let d=await f("/api/v1/pages/schema",{method:"POST",body:{name:o,schema:c}});console.log(JSON.stringify(d,null,2)),console.error(`Schema "${d.name}" pushed successfully.`),console.error(`Source key: ${d.sourceKey}`),console.error("You can now select this schema as an output target in the Kenobi workflow builder.")},"schemaPush"),V=t(async e=>{let[o,n]=e;(!o||!n)&&(console.error("Usage: kenobi-pages page get <workflowId> <slug>"),process.exit(2));let s=await f(`/api/v1/pages/${o}/${n}`);console.log(JSON.stringify(s,null,2))},"pageGet"),q=new Set(["COMPLETED","FAILED","CANCELED","SYSTEM_FAILURE","CRASHED"]),z=t(e=>{if(typeof e=="string")return e;if(typeof e=="object"&&e!==null&&"message"in e){let o=e.message;if(typeof o=="string")return o}return"Unknown error"},"runStatusErrorMessage"),X=t(e=>new Promise(o=>setTimeout(o,e)),"sleep"),k=t((e,o)=>{let n=e.indexOf(o);return n!==-1&&e[n+1]?e[n+1]:void 0},"parseFlag"),Q=t(async e=>{let o=e[0];o||(console.error("Usage: kenobi-pages run <workflowId> [--params '<json>'] [--context '<text>']"),process.exit(2));let n=e.slice(1),s={},r=k(n,"--params");if(r)try{s=JSON.parse(r)}catch{console.error("Error: Invalid JSON in --params"),process.exit(2)}let i=k(n,"--context"),a={params:s};i&&(a.context=i);let c=await f(`/api/v1/workflows/${o}/run`,{method:"POST",body:a});console.error(`Run triggered: ${c.runId}`),console.error("Polling for completion...");let d=2e3,m=15e3;for(;;){await X(d);let u=await f(`/api/v1/workflows/${o}/runs/${c.runId}`);if(console.error(` Status: ${u.status}`),q.has(u.status)){if(u.status!=="COMPLETED"){let P=z(u.error);console.error(`
|
|
10
|
+
Run failed (${u.status}): ${P}`),console.log(JSON.stringify(u,null,2)),process.exit(1)}console.log(JSON.stringify(u,null,2));return}d=Math.min(d*1.5,m)}},"runWorkflow"),Z=t(async()=>{let e=await f("/api/v1/workflows");console.log(JSON.stringify(e,null,2))},"listWorkflows"),ee=t(async()=>{let e=await f("/api/v1/sources");console.log(JSON.stringify(e,null,2))},"listSources"),oe=t(async e=>{let o=await f(`/api/v1/sources/${encodeURIComponent(e)}/sample`);console.log(JSON.stringify(o,null,2))},"sampleSource"),A=t(async e=>{let o=await N(e),n=o?null:e.find(i=>i.startsWith("{")),s=!o&&!n?await $():null,r=o??n??s;(!r||r.trim().length===0)&&(console.error("Error: No JSON provided."),console.error("Pass inline JSON, --file <path>, or pipe to stdin."),process.exit(2));try{return JSON.parse(r)}catch{console.error("Error: Invalid JSON."),process.exit(2)}},"readJsonInput"),ne=t(async e=>{let o=k(e,"--name"),n=k(e,"--slug");(!o||!n)&&(console.error("Usage: kenobi-pages workflow create --name '<name>' --slug '<slug>' --config '<json>'"),console.error(" kenobi-pages workflow create --name '<name>' --slug '<slug>' --file config.json"),process.exit(2));let s=k(e,"--description"),r=e.indexOf("--config"),i=r!==-1&&e[r+1]?[e[r+1]]:e,a=await A(i),c={name:o,slug:n,config:a};s&&(c.description=s);let d=await f("/api/v1/workflows",{method:"POST",body:c});console.log(JSON.stringify(d,null,2)),console.error(`Workflow "${o}" created.`)},"workflowCreate"),se=t(async e=>{let o=e[0];o||(console.error("Usage: kenobi-pages workflow get <workflowId>"),process.exit(2));let n=await f(`/api/v1/workflows/${o}?full=true`);console.log(JSON.stringify(n,null,2))},"workflowGet"),re=t(async e=>{let o=e[0];o||(console.error("Usage: kenobi-pages workflow update <workflowId> --config '<json>'"),console.error(" kenobi-pages workflow update <workflowId> --file config.json"),process.exit(2));let n=e.slice(1),s=k(n,"--name"),r=k(n,"--description"),i=n.indexOf("--config"),a=i!==-1&&n[i+1]?[n[i+1]]:n,c={};s&&(c.name=s),r!==void 0&&(c.description=r),(n.includes("--config")||n.includes("--file"))&&(c.config=await A(a)),Object.keys(c).length===0&&(console.error("Error: Nothing to update. Pass --name, --description, --config, or --file."),process.exit(2));let m=await f(`/api/v1/workflows/${o}`,{method:"PUT",body:c});console.log(JSON.stringify(m,null,2)),console.error("Workflow updated.")},"workflowUpdate"),te=t(async e=>{let o=e[0];o||(console.error("Usage: kenobi-pages workflow delete <workflowId>"),process.exit(2)),await f(`/api/v1/workflows/${o}`,{method:"DELETE"}),console.error("Workflow deleted.")},"workflowDelete"),ie=`kenobi-pages \u2014 Kenobi Pages CLI
|
|
17
11
|
|
|
18
12
|
Commands:
|
|
19
13
|
init Set up your API key (interactive)
|
|
@@ -23,7 +17,6 @@ Commands:
|
|
|
23
17
|
schema push <name> --file f Push a schema to Kenobi (from file)
|
|
24
18
|
|
|
25
19
|
page get <workflowId> <slug> Fetch page content for a specific lead
|
|
26
|
-
types <workflowId> Generate TypeScript interface from schema
|
|
27
20
|
|
|
28
21
|
sources List connected data sources
|
|
29
22
|
sources sample <sourceKey> Preview sample rows from a source
|
|
@@ -44,7 +37,6 @@ Examples:
|
|
|
44
37
|
npx kenobi-pages sources sample "notion:abc123"
|
|
45
38
|
npx kenobi-pages schema get 42
|
|
46
39
|
npx kenobi-pages schema push "My Page" '{"fields":{"headline":{"type":"string"}}}'
|
|
47
|
-
npx kenobi-pages types 42 > lib/kenobi-types.ts
|
|
48
40
|
npx kenobi-pages page get 42 acme-corp
|
|
49
41
|
npx kenobi-pages workflows
|
|
50
42
|
npx kenobi-pages workflow create --name "Lead page" --slug "lead-page" --config '{...}'
|
|
@@ -72,4 +64,4 @@ Environment:
|
|
|
72
64
|
Key resolution order:
|
|
73
65
|
1. KENOBI_PAGES_KEY environment variable
|
|
74
66
|
2. ~/.kenobi/config.json (written by 'init')
|
|
75
|
-
`,[,,...b]=process.argv;(b.length===0||b[0]==="--help"||b[0]==="-h")&&(console.log(
|
|
67
|
+
`,[,,...b]=process.argv;(b.length===0||b[0]==="--help"||b[0]==="-h")&&(console.log(ie),process.exit(0));var[g,l,...w]=b;if(g==="init")await M();else if(g==="schema"&&l==="get")await Y(w);else if(g==="schema"&&l==="push")await H(w);else if(g==="page"&&l==="get")await V(w);else if(g==="sources")if(l==="sample"){let e=w[0];e||(console.error("Usage: kenobi-pages sources sample <sourceKey>"),process.exit(2)),await oe(e)}else l===void 0||l==="list"?await ee():(console.error(`Unknown sources subcommand: ${l}`),console.error("Run 'kenobi-pages --help' for usage."),process.exit(2));else g==="workflows"?await Z():g==="workflow"&&l==="create"?await ne(w):g==="workflow"&&l==="get"?await se(w):g==="workflow"&&l==="update"?await re(w):g==="workflow"&&l==="delete"?await te(w):g==="run"?await Q([l,...w].filter(Boolean)):(console.error(`Unknown command: ${b.join(" ")}`),console.error("Run 'kenobi-pages --help' for usage."),process.exit(1));
|