langtrain 0.2.0 → 0.2.1
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/chunk-A7PMJDMV.mjs +3 -0
- package/dist/chunk-A7PMJDMV.mjs.map +1 -0
- package/dist/chunk-K5LXUJ4G.js +3 -0
- package/dist/chunk-K5LXUJ4G.js.map +1 -0
- package/dist/cli.js +10 -10
- package/dist/cli.js.map +1 -1
- package/dist/cli.mjs +2 -2
- package/dist/cli.mjs.map +1 -1
- package/dist/index.d.mts +30 -2
- package/dist/index.d.ts +30 -2
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +1 -1
- package/src/lib/base.ts +162 -12
- package/dist/chunk-36QS5AXY.mjs +0 -3
- package/dist/chunk-36QS5AXY.mjs.map +0 -1
- package/dist/chunk-ZN3AO753.js +0 -3
- package/dist/chunk-ZN3AO753.js.map +0 -1
package/dist/cli.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {d,k,f as f$1,h,a,m,g,i,r,q as q$1}from'./chunk-
|
|
2
|
+
import {d,k,f as f$1,h,a,m,g,i,r,q as q$1}from'./chunk-A7PMJDMV.mjs';import {Command}from'commander';import {select,isCancel,confirm,text,cancel,password}from'@clack/prompts';import {dim,white,magenta,blue,bold,cyan,gray,yellow,green,red,black,bgMagenta}from'kleur/colors';import D from'gradient-string';import Ge from'cli-table3';import B from'fs';import ae from'path';import _e from'os';function q(e){return new Ge({head:e.map(o=>x.magenta(x.bold(o))),chars:{top:"\u2500","top-mid":"\u252C","top-left":"\u250C","top-right":"\u2510",bottom:"\u2500","bottom-mid":"\u2534","bottom-left":"\u2514","bottom-right":"\u2518",left:"\u2502","left-mid":"\u251C",mid:"\u2500","mid-mid":"\u253C",right:"\u2502","right-mid":"\u2524",middle:"\u2502"},style:{"padding-left":1,"padding-right":1,head:[],border:["gray"]}})}function W(e){console.clear(),console.log(D(["#A855F7","#EC4899","#3B82F6"])(`
|
|
3
3
|
\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2557 \u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2588\u2557\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557\u2588\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2557\u2588\u2588\u2588\u2557 \u2588\u2588\u2557
|
|
4
4
|
\u2588\u2588\u2551 \u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2551\u2588\u2588\u2554\u2550\u2550\u2550\u2550\u255D\u255A\u2550\u2550\u2588\u2588\u2554\u2550\u2550\u255D\u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557\u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557\u2588\u2588\u2551\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2551
|
|
5
5
|
\u2588\u2588\u2551 \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2551\u2588\u2588\u2554\u2588\u2588\u2557 \u2588\u2588\u2551\u2588\u2588\u2551 \u2588\u2588\u2588\u2557 \u2588\u2588\u2551 \u2588\u2588\u2588\u2588\u2588\u2588\u2554\u255D\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2551\u2588\u2588\u2551\u2588\u2588\u2554\u2588\u2588\u2557 \u2588\u2588\u2551
|
|
@@ -16,7 +16,7 @@ import {d,k,f as f$1,h,a,m,g,i,r,q as q$1}from'./chunk-36QS5AXY.mjs';import {Com
|
|
|
16
16
|
Limits:`)),console.log(` Models: ${t.limits.max_models===-1?"Unlimited":t.limits.max_models}`),console.log(` Training Jobs: ${t.limits.max_training_jobs}`);}catch(t){a.stop(red("Failed to fetch status.")),console.error(t.message);}}async function Se(e,o){let a="",t=p();t.start("Fetching available text models...");try{let c=await o.list("text");t.stop(`Found ${c.length} text models`),c.length>0&&(a=await select({message:"Select base model:",options:c.map(l=>({value:l.id,label:l.id,hint:l.owned_by}))}));}catch{t.stop(yellow("Failed to fetch models. Using manual input.")),a=await text({message:"Enter base model (e.g., gpt-3.5-turbo):",placeholder:"gpt-3.5-turbo",validate(l){if(!l||l.length===0)return "Value is required!"}});}isCancel(a)&&(cancel("Operation cancelled."),process.exit(0));let n=await text({message:"Enter path to training file:",placeholder:"./data.jsonl",validate(c){if(!c||c.length===0)return "Value is required!"}});isCancel(n)&&cancel("Operation cancelled.");let i=await text({message:"Num Epochs:",placeholder:"3",initialValue:"3"});isCancel(i)&&cancel("Operation cancelled.");let s=await select({message:"Track this job on Langtrain Cloud?",options:[{value:"yes",label:"Yes",hint:"Upload dataset and log job"},{value:"no",label:"No",hint:"Local only"}]});if(isCancel(s)&&cancel("Operation cancelled."),s==="yes"){let c=p();c.start("Connecting to Cloud...");try{let l=f();if(!l.apiKey)throw new Error('API Key required. Run "login" first.');if(!(await new h({apiKey:l.apiKey}).getStatus()).features.includes("cloud_finetuning")){c.stop(red('Feature "cloud_finetuning" is not available on your plan.'));let V=await confirm({message:"Upgrade to Pro for cloud tracking?"});V&&!isCancel(V)&&console.log(bgMagenta(black(" Visit https://langtrain.ai/dashboard/billing to upgrade. ")));return}let S=new f$1({apiKey:l.apiKey}),M=new g({apiKey:l.apiKey});c.message("Uploading dataset...");let O=await S.upload(n);c.message("Creating Job...");let Y=await M.createJob({name:`cli-sft-${Date.now()}`,base_model:a,dataset_id:O.id,task:"text",hyperparameters:{n_epochs:parseInt(i)}});c.stop(green(`Job tracked: ${Y.id}`));}catch(l){c.stop(red(`Tracking failed: ${l.message}`));let w=await confirm({message:"Continue with local training anyway?"});if(!w||isCancel(w))return}}let r=p();r.start("Starting local fine-tuning...");try{let c={model:a,trainFile:n,preset:"default",epochs:parseInt(i),batchSize:1,learningRate:2e-5,loraRank:16,outputDir:"./output"};await e.finetune(c),r.stop(green("Fine-tuning job started successfully!"));}catch(c){throw r.stop(red("Failed to start job.")),c}}async function xe(e){let o=await text({message:"Enter model path:",placeholder:"./output/model",initialValue:"./output/model"});isCancel(o)&&cancel("Operation cancelled");let a=await text({message:"Enter prompt:",placeholder:"Hello world"});isCancel(a)&&cancel("Operation cancelled");let t=p();t.start("Connecting to Langtrain Inference API...");try{let n=await e.generate(o,{prompt:a});t.stop("Generation complete"),v("Response:"),console.log(D.pastel(n));}catch(n){throw t.stop(red("Generation failed.")),n}}async function Le(e){let o=p();o.start("Fetching fine-tuning jobs...");let t=f().workspace_id;if(!(!t&&(o.stop(yellow("Workspace ID required to list jobs.")),t=await text({message:"Enter Workspace ID:"}),isCancel(t))))try{let n=await e.listJobs(t);if(o.stop(`Found ${n.data.length} jobs`),n.data.length===0){console.log(yellow("No jobs found."));return}let i=q(["ID","Status","Model","Progress","Created"]);n.data.forEach(r=>{let c=r.status==="succeeded"?green:r.status==="failed"?red:yellow;i.push([r.id.substring(0,8)+"...",c(r.status),r.base_model,(r.progress||0)+"%",new Date(r.created_at).toLocaleDateString()]);}),console.log(i.toString()),console.log("");let s=await select({message:"Select a job to view details:",options:n.data.map(r=>({value:r.id,label:`${r.name||r.id} (${r.status})`,hint:`Created: ${new Date(r.created_at).toLocaleDateString()}`}))});if(isCancel(s))return;await Ae(e,s);}catch(n){o.stop(red(`Failed to list jobs: ${n.message}`));}}async function Ae(e,o){let a=o;if(!a&&(a=await text({message:"Enter Job ID:"}),isCancel(a)))return;let t=p();t.start(`Fetching status for ${a}...`);try{let n=await e.getJob(a);if(t.stop(`Job Status: ${n.status.toUpperCase()}`),console.log(gray("------------------------------------------------")),console.log(`${bgMagenta(black(" Job Details "))}`),console.log(`ID: ${n.id}`),console.log(`Name: ${n.name}`),console.log(`Status: ${n.status==="succeeded"?green(n.status):n.status}`),console.log(`Model: ${n.base_model}`),console.log(`Progress: ${n.progress||0}%`),n.error_message&&console.log(red(`Error: ${n.error_message}`)),console.log(gray("------------------------------------------------")),n.status==="running"||n.status==="queued"){let i=await select({message:"Action:",options:[{value:"refresh",label:"Refresh Status"},{value:"cancel",label:"Cancel Job"},{value:"back",label:"Back"}]});i==="refresh"&&await Ae(e,a),i==="cancel"&&await qe(e,a);}}catch(n){t.stop(red(`Failed to get job status: ${n.message}`));}}async function qe(e,o){let a=await confirm({message:"Are you sure you want to cancel this job?"});if(!a||isCancel(a))return;let t=p();t.start("Canceling job...");try{await e.cancelJob(o),t.stop(green("Job canceled successfully."));}catch(n){t.stop(red(`Failed to cancel job: ${n.message}`));}}async function Fe(e,o){let a="",t=p();t.start("Fetching available vision models...");try{let c=await o.list("vision");t.stop(`Found ${c.length} vision models`),c.length>0?a=await select({message:"Select base vision model:",options:c.map(l=>({value:l.id,label:l.id,hint:l.owned_by}))}):a=await text({message:"Enter base vision model:",placeholder:"llava-v1.5-7b",initialValue:"llava-v1.5-7b"});}catch{t.stop(yellow("Failed to fetch models. Using manual input.")),a=await text({message:"Enter base vision model:",placeholder:"llava-v1.5-7b",initialValue:"llava-v1.5-7b"});}isCancel(a)&&(cancel("Operation cancelled"),process.exit(0));let n=await text({message:"Enter dataset path:",placeholder:"./dataset"});isCancel(n)&&cancel("Operation cancelled");let i=await text({message:"Num Epochs:",placeholder:"3",initialValue:"3"});isCancel(i)&&cancel("Operation cancelled");let s=await select({message:"Track this job on Langtrain Cloud?",options:[{value:"yes",label:"Yes",hint:"Upload dataset and log job"},{value:"no",label:"No",hint:"Local only"}]});if(isCancel(s)&&cancel("Operation cancelled"),s==="yes"){let c=p();c.start("Connecting to Cloud...");try{let l=f();if(!l.apiKey)throw new Error('API Key required. Run "login" first.');if(!(await new h({apiKey:l.apiKey}).getStatus()).features.includes("cloud_finetuning")){c.stop(red('Feature "cloud_finetuning" is not available on your plan.'));let V=await confirm({message:"Upgrade to Pro for cloud tracking?"});V&&!isCancel(V)&&console.log(bgMagenta(black(" Visit https://langtrain.ai/dashboard/billing to upgrade. ")));return}let S=new f$1({apiKey:l.apiKey}),M=new g({apiKey:l.apiKey});c.message("Uploading dataset...");let O=await S.upload(n,void 0,"fine-tune-vision");c.message("Creating Job...");let Y=await M.createJob({name:`cli-vision-${Date.now()}`,base_model:a,dataset_id:O.id,task:"vision",training_method:"lora",hyperparameters:{n_epochs:parseInt(i)}});c.stop(green(`Job tracked: ${Y.id}`));}catch(l){c.stop(red(`Tracking failed: ${l.message}`));let w=await confirm({message:"Continue with local training anyway?"});if(!w||isCancel(w))return}}let r=p();r.start("Analyzing dataset structure..."),await new Promise(c=>setTimeout(c,800)),r.message("Starting vision fine-tuning on Langtrain Cloud...");try{let c={model:a,dataset:n,epochs:parseInt(i),batchSize:1,learningRate:2e-5,loraRank:16,outputDir:"./vision-output"};await e.finetune(c),r.stop(green("Vision fine-tuning started successfully!"));}catch(c){throw r.stop(red("Failed to start vision job.")),c}}async function Ie(e){let o=await text({message:"Enter model path:",placeholder:"./vision-output/model",initialValue:"./vision-output/model"});isCancel(o)&&cancel("Operation cancelled");let a=await text({message:"Enter prompt/image path:",placeholder:"Describe this image..."});isCancel(a)&&cancel("Operation cancelled");let t=p();t.start("Uploading image and context..."),await new Promise(n=>setTimeout(n,600)),t.message("Generating vision response...");try{let n=await e.generate(o,{prompt:a});t.stop("Generation complete"),v("Response:"),console.log(D.pastel(n));}catch(n){throw t.stop(red("Generation failed.")),n}}async function De(e,o){let a=await text({message:"Agent Name:",placeholder:"e.g. Support Bot",validate(c){if(!c||c.length===0)return "API Key is required"}});if(isCancel(a)){cancel("Operation cancelled");return}let t=await text({message:"Description:",placeholder:"e.g. A helpful support assistant"});if(isCancel(t))return;let n=await text({message:"System Prompt:",placeholder:"e.g. You are a helpful assistant.",initialValue:"You are a helpful assistant."});if(isCancel(n))return;let i="gpt-4o",s=p();s.start("Fetching agent models...");try{let c=await o.list("agent");s.stop(`Found ${c.length} models`),c.length>0&&(i=await select({message:"Select Agent Model:",options:c.map(l=>({value:l.id,label:l.id}))}));}catch{s.stop(yellow("Could not fetch models, using default."));}if(isCancel(i))return;let r=p();r.start("Creating agent...");try{let c=await e.list(),l="";if(c.length>0)l=c[0].workspace_id;else {r.stop(yellow("Workspace ID needed (no existing agents found)."));let k=await text({message:"Enter Workspace ID (UUID):",validate(S){if(!S||S.length===0)return "Required"}});if(isCancel(k))return;l=k,r.start("Creating agent...");}let w=await e.create({workspace_id:l,name:a,description:t,config:{system_prompt:n,model:i}});r.stop(green(`Agent "${w.name}" created successfully! ID: ${w.id}`));}catch(c){throw r.stop(red("Failed to create agent.")),c}}async function Ee(e){let o=p();o.start("Fetching agents...");let a=await e.list();if(o.stop(`Found ${a.length} agents`),a.length===0){v(yellow("No agents to delete."));return}let t=await select({message:"Select an agent to DELETE:",options:a.map(s=>({value:s.id,label:s.name,hint:s.description||"No description"}))});if(isCancel(t))return;if(await select({message:"Are you sure you want to delete this agent?",options:[{value:"yes",label:"Yes, delete it",hint:"Cannot be undone"},{value:"no",label:"No, keep it"}]})!=="yes"){v(gray("Deletion cancelled."));return}let i=p();i.start("Deleting agent...");try{await e.delete(t),i.stop(green("Agent deleted successfully."));}catch(s){throw i.stop(red("Failed to delete agent.")),s}}async function Pe(e){let o=p();o.start("Fetching agents...");let a=await e.list();if(o.stop(`Found ${a.length} agents`),a.length===0){v(yellow("No agents found in your workspace."));return}let t=q(["ID","Name","Model","Created"]);a.forEach(i=>{t.push([i.id.substring(0,8)+"...",i.name,i.config?.model||"default",new Date(i.created_at).toLocaleDateString()]);}),console.log(t.toString()),console.log("");let n=await select({message:"Select an agent to run:",options:a.map(i=>({value:i.id,label:i.name,hint:i.description||"No description"}))});isCancel(n)||await Ke(e,n,a.find(i=>i.id===n)?.name||"Agent");}async function Ke(e,o,a,t){v(bgMagenta(black(` Chatting with ${a} `))),console.log(gray('Type "exit" to quit conversation.'));let n;for(;;){let i=await text({message:"You:",placeholder:"Type a message..."});if(isCancel(i)||i==="exit")break;let s=p();s.start("Agent is thinking...");try{let r=await e.execute(o,{prompt:i},[],n);s.stop(),r.output?.response?console.log(D.pastel(`Agent: ${r.output.response}`)):console.log(D.pastel(`Agent: ${JSON.stringify(r.output)}`)),n=r.conversation_id;}catch(r){s.stop(red("Error running agent.")),console.error(r);}}}async function oe(){v("Initializing new Langtrain project...");let e=process.cwd();if(B.existsSync(ae.join(e,"langtrain.config.json"))){ve("langtrain.config.json already exists in this directory.");let s=await confirm({message:"Do you want to re-initialize and overwrite the config?",initialValue:false});if(isCancel(s)||!s){K("Initialization cancelled.");return}}let o=await text({message:"What is the name of your project?",placeholder:"my-ai-app",initialValue:ae.basename(e),validate(s){if(!s||s.length===0)return "Project name is required!"}});if(isCancel(o)){cancel("Operation cancelled.");return}let a=f(),t=a.apiKey;if(t)_("Found existing Langtrain credentials.");else {let s=await confirm({message:"You are not logged in. Do you want to log in now?",initialValue:true});if(isCancel(s)){cancel("Operation cancelled.");return}if(s)await N(),a=f(),t=a.apiKey;else if(t=await text({message:"Enter your Langtrain API Key (optional for local dev):",placeholder:"lt_sk_...",initialValue:""}),isCancel(t)){cancel("Operation cancelled.");return}}p().start("Creating configuration...");let i={name:o,apiKey:t||void 0,environment:"development",agents:[{name:"support-bot",description:"A helpful customer support assistant",config:{model:"llama-3-8b",system_prompt:"You are a helpful customer support assistant.",temperature:.7}}]};B.writeFileSync(ae.join(e,"langtrain.config.json"),JSON.stringify(i,null,2)),_("Project initialized successfully!"),console.log(x.dim(`
|
|
17
17
|
Next steps:`)),console.log(` 1. Run ${x.cyan("lt deploy")} to push your agent to the cloud.`),console.log(` 2. Run ${x.cyan("lt dev")} to start the local development loop.`),K("Happy coding!");}async function Te(){v("Running Langtrain Doctor...");let e=p(),o=0;e.start("Checking Node.js environment...");let a=process.version,t=_e.platform(),n=_e.arch();parseInt(a.replace("v","").split(".")[0])<18?(e.stop(x.red(`Node.js version ${a} is outdated. Please upgrade to v18+.`)),o++):e.stop(`Node.js ${a} (${t} ${n})`),e.start("Checking configuration...");let i=f();if(!i.apiKey)e.stop(x.yellow("API Key is missing. Run `langtrain login` or set LANGTRAIN_API_KEY.")),o++;else {e.stop("Configuration found."),e.start("Checking API connectivity...");try{let s=await J(i.apiKey);e.stop(`Connected to Langtrain Cloud (Plan: ${x.green(s?.plan||"unknown")})`);}catch(s){e.stop(x.red(`Failed to connect to Langtrain Cloud: ${s.message}`)),o++;}}console.log(""),o===0?_("Your Langtrain environment is healthy! Ready to build."):be(`Found ${o} issue(s). Please resolve them for the best experience.`),K("Doctor check complete.");}async function ie(e){let a=f().workspace_id,t=await text({message:"Path to file:",placeholder:"./dataset.jsonl",validate(s){if(!s)return "Required";if(!B.existsSync(s))return "File not found"}});if(isCancel(t))return;let n=await select({message:"File Purpose:",options:[{value:"fine-tune",label:"Fine-tuning (JSONL)"},{value:"vision-tune",label:"Vision Tuning (Image/Zip)"},{value:"agent-knowledge",label:"Agent Knowledge"}]});if(isCancel(n))return;let i=p();i.start("Uploading file...");try{let s=await e.upload(t,a,n);i.stop(green("File uploaded successfully!")),console.log(gray(`ID: ${s.id}`)),console.log(gray(`Name: ${s.filename}`)),console.log(gray(`Bytes: ${s.bytes}`));}catch(s){i.stop(red(`Upload failed: ${s.message}`));}}async function se(e,o){let a=f(),t=new m({apiKey:a.apiKey||"",baseUrl:a.baseUrl});if(!o){let r=p();r.start("Fetching files...");try{let c=a.workspace_id||"",l=await e.list(c);if(r.stop(`Found ${l.length} files`),l.length===0){console.log(yellow("No files found. Upload one first."));return}let w=await select({message:"Select file to refine:",options:l.map(k=>({value:k.id,label:`${k.filename} (${We(k.bytes)})`}))});if(isCancel(w))return;o=w;}catch(c){r.stop(red(`Failed to fetch files: ${c.message}`));return}}let n=p();n.start("Fetching guardrails...");let i="";try{let r=await t.list();if(n.stop(`Found ${r.length} guardrails`),r.length===0){console.log(yellow('No guardrails found. Please create one first using "lt guardrails create".'));return}let c=await select({message:"Select a Guardrail to apply:",options:r.map(l=>({value:l.id,label:l.name,hint:l.description}))});if(isCancel(c))return;i=c;}catch(r){n.stop(red(`Failed to fetch guardrails: ${r.message}`));return}let s=p();s.start("Applying guardrail (filtering dataset)...");try{let r=await t.apply(o,i);s.stop(green("Dataset refined successfully!")),console.log(gray("Stats:")),console.log(`Original Rows: ${r.original_rows}`),console.log(`Filtered Rows: ${r.filtered_rows}`),console.log(red(`Removed: ${r.removed_rows} rows`)),console.log(green(`New Dataset ID: ${r.new_dataset_id}`));}catch(r){s.stop(red(`Failed to refine dataset: ${r.message}`));}}function We(e,o=2){if(!+e)return "0 Bytes";let a=1024,t=o<0?0:o,n=["Bytes","KB","MB","GB","TB"],i=Math.floor(Math.log(e)/Math.log(a));return `${parseFloat((e/Math.pow(a,i)).toFixed(t))} ${n[i]}`}async function j(e){v("Deploying configuration to Langtrain Cloud...");let o=f(),a=o.agents||[];if(a.length===0){v(yellow("No agents found in langtrain.config.json"));return}for(let t of a){let n=p();n.start(`Deploying agent: ${t.name}...`);try{let i=await e.list(),s=i.find(r=>r.name===t.name);if(s)n.stop(yellow(`Agent ${t.name} already exists (ID: ${s.id}). Skipping update (not supported yet).`));else {let r={workspace_id:o.workspace_id||i[0]?.workspace_id||"",name:t.name,description:t.description,config:t.config};if(!r.workspace_id){n.stop(red(`Failed: Workspace ID missing in config for ${t.name}`));continue}await e.create(r),n.stop(green(`Agent ${t.name} deployed successfully!`));}}catch(i){n.stop(red(`Failed to deploy ${t.name}: ${i.message}`));}}_("Deployment complete.");}async function re(e){v("Starting Langtrain Development Server...");let o=ae.join(process.cwd(),"langtrain.config.json");if(!B.existsSync(o)){v(red('langtrain.config.json not found. Run "lt init" first.'));return}console.log(gray(`Watching ${o} for changes...`));let a=false;await j(e),B.watch(o,async t=>{if(t==="change"&&!a){a=true,console.log(yellow("Configuration changed. Redeploying...")),await new Promise(n=>setTimeout(n,500));try{await j(e);}catch(n){console.error(red(`Deploy failed: ${n.message}`));}finally{a=false,console.log(gray(`Watching ${o}...`));}}}),await new Promise(()=>{});}async function le(e){let o=f(),a=new m({apiKey:o.apiKey||"",baseUrl:o.baseUrl}),t=p();t.start("Fetching guardrails...");try{let n=await a.list();if(t.stop(`Found ${n.length} guardrails`),n.length===0){console.log(yellow('No guardrails found. Create one with "lt guardrails create".'));return}n.forEach(i=>{console.log(green(`\u2022 ${i.name}`)+gray(` (ID: ${i.id})`)),i.description&&console.log(gray(` ${i.description}`)),console.log(gray(` Config: PII=${i.config.pii_enabled}, MinLen=${i.config.min_length}`)),console.log("");});}catch(n){t.stop(red(`Failed to list guardrails: ${n.message}`));}}async function ce(e){let o=f(),a=new m({apiKey:o.apiKey||"",baseUrl:o.baseUrl});v("Create a new Data Guardrail");let t=await text({message:"Guardrail Name:",placeholder:"e.g. Strict Safety Policy",validate(l){if(!l)return "Name is required"}});if(isCancel(t))return;let n=await text({message:"Description (optional):",placeholder:"Filters PII and short text"});if(isCancel(n))return;let i=await text({message:"Minimum Text Length (0 for no limit):",initialValue:"0",validate(l){if(isNaN(Number(l)))return "Must be a number"}});if(isCancel(i))return;let s=await confirm({message:"Enable PII Filtering (Email/Phone)?",initialValue:false});if(isCancel(s))return;let r=await text({message:"Regex Patterns to Block (comma separated, optional):",placeholder:"e.g. bad_word, another_one"});if(isCancel(r))return;let c=p();c.start("Creating guardrail...");try{let l=r.split(",").map(S=>S.trim()).filter(S=>S.length>0),w={name:t,description:n,config:{min_length:Number(i),pii_enabled:s,regex_patterns:l,profanity_enabled:!1}},k=await a.create(w);c.stop(green(`Guardrail "${k.name}" created successfully!`)),console.log(gray(`ID: ${k.id}`));}catch(l){c.stop(red(`Failed to create guardrail: ${l.message}`));}}async function He(e){let o=p();o.start("Fetching secrets...");let a=f();try{let t=await e.list(a.workspace_id);if(o.stop(`Found ${t.length} secrets`),t.length===0){console.log(gray('No secrets found. Use "lt env set" to add one.'));return}console.log(gray("------------------------------------------------")),t.forEach(n=>{console.log(`${n.key.padEnd(30)} ${gray("******")}`);}),console.log(gray("------------------------------------------------"));}catch(t){o.stop(red(`Failed to list secrets: ${t.message}`));}}async function Ze(e,o){let a="",t="";if(a=await text({message:"Secret Key:",placeholder:"OPENAI_API_KEY"}),isCancel(a)||(t=await text({message:"Secret Value:",placeholder:"sk-..."}),isCancel(t)))return;let n=p();n.start(`Setting ${a}...`);let i=f();try{await e.set(a,t,i.workspace_id),n.stop(green(`Secret ${a} set successfully.`));}catch(s){n.stop(red(`Failed to set secret: ${s.message}`));}}async function ge(e){let o=await select({message:"Manage Secrets",options:[{value:"list",label:"List Secrets"},{value:"set",label:"Set Secret"},{value:"remove",label:"Remove Secret"},{value:"back",label:"Back"}]});if(!(isCancel(o)||o==="back")&&(o==="list"&&await He(e),o==="set"&&await Ze(e),o==="remove")){let a=await text({message:"Key to remove:"});if(!isCancel(a)){let t=p();t.start("Removing...");try{let n=f();await e.delete(a,n.workspace_id),t.stop(green("Removed."));}catch(n){t.stop(red(`Failed: ${n.message}`));}}}}async function ue(e,o){let a=p(),t="";if(o){a.start("Finding agent...");try{let s=(await e.list()).find(r=>r.name===o||r.id===o);if(s)t=s.id;else {a.stop(red(`Agent "${o}" not found.`));return}a.stop(green(`Found agent: ${s.name}`));}catch(i){a.stop(red(`Failed to list agents: ${i.message}`));return}}else {a.start("Fetching agents...");try{let i=await e.list();if(a.stop(`Found ${i.length} agents`),i.length===0){console.log(yellow("No agents found."));return}let s=await select({message:"Select agent to view logs:",options:i.map(r=>({value:r.id,label:r.name}))});if(isCancel(s))return;t=s;}catch(i){a.stop(red(`Failed to list agents: ${i.message}`));return}}let n=p();n.start("Fetching logs...");try{let i=await e.logs(t);n.stop("Logs fetched."),console.log(gray("------------------------------------------------")),console.log(`${bgMagenta(black(" Recent Logs "))}`),i.logs&&i.logs.length>0?i.logs.forEach(s=>console.log(s)):console.log(gray("(No logs found)")),console.log(gray("------------------------------------------------"));}catch(i){n.stop(red(`Failed to fetch logs: ${i.message}`));}}var Qe=Date.now(),T=0,Ue=0;async function pe(){let e=f(),o=e.apiKey;if(console.log(""),console.log(bold(" \u2554\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2557")),console.log(bold(" \u2551 TOKEN USAGE \u2551")),console.log(bold(" \u255A\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u255D")),console.log(""),!o){console.log(yellow(` Login required to view token usage.
|
|
18
18
|
`));return}let a$1=p();a$1.start("Fetching token usage...");try{let t=a("axios"),n=e.baseUrl||"https://api.langtrain.xyz",s=(await t.get(`${n}/v1/usage/tokens`,{headers:{Authorization:`Bearer ${o}`}})).data;a$1.stop(green("Token usage retrieved")),console.log("");let r=s.tokens_used||0,c=s.token_limit||1e4,l=Math.round(r/c*100),w=Math.max(0,c-r),k=30,S=Math.round(l/100*k),M="\u2588".repeat(S)+"\u2591".repeat(k-S),O=l>90?"\x1B[31m":l>70?"\x1B[33m":"\x1B[32m";console.log(` ${dim("Period:")} ${s.period||"Current Month"}`),console.log(` ${dim("Used:")} ${r.toLocaleString()} tokens`),console.log(` ${dim("Limit:")} ${c.toLocaleString()} tokens`),console.log(` ${dim("Remaining:")} ${w.toLocaleString()} tokens`),console.log(` ${dim("Usage:")} ${O}${M}\x1B[0m ${l}%`),console.log(""),s.breakdown&&(console.log(dim(" \u2500\u2500 Breakdown \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500")),console.log(` ${dim("Training:")} ${(s.breakdown.training||0).toLocaleString()}`),console.log(` ${dim("Inference:")} ${(s.breakdown.inference||0).toLocaleString()}`),console.log(` ${dim("Agents:")} ${(s.breakdown.agents||0).toLocaleString()}`),console.log(""));}catch{a$1.stop(""),console.log(dim(" Token data not available from server.")),console.log(dim(` Showing session estimates:
|
|
19
|
-
`)),console.log(` ${dim("Session calls:")} ${T}`),console.log(` ${dim("Est. tokens:")} ~${T*150}`),console.log("");}}async function Ne(){let e=Date.now()-Qe,o=Math.round(e/1e3),a$1=Math.floor(o/60),t=a$1>0?`${a$1}m ${o%60}s`:`${o}s`,n=0,i=0;console.log(""),console.log(bold(" \u2554\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2557")),console.log(bold(" \u2551 SESSION TELEMETRY \u2551")),console.log(bold(" \u255A\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u255D")),console.log(""),console.log(` ${dim("Session:")} ${t}`),console.log(` ${dim("API calls:")} ${T}`),console.log(` ${dim("Avg latency:")} ${n}ms`),console.log(` ${dim("Errors:")} ${Ue} (${i}%)`),console.log(""),console.log(dim(" \u2500\u2500 Environment \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500")),console.log(` ${dim("Node:")} ${process.version}`),console.log(` ${dim("Platform:")} ${process.platform} ${process.arch}`),console.log(` ${dim("Memory:")} ${Math.round(process.memoryUsage().heapUsed/1024/1024)}MB heap`),console.log(` ${dim("Config:")} ~/.langtrain/config.json`),console.log("");let s=f();if(s.apiKey){let r=p();r.start("Pinging API...");try{let c=a("axios"),l=s.baseUrl||"https://api.langtrain.xyz",w=Date.now();await c.get(`${l}/health`,{timeout:5e3});let k=Date.now()-w;r.stop(green(`API healthy (${k}ms)`));}catch{r.stop(yellow("API unreachable"));}}console.log("");}var je={version:"0.2.
|
|
19
|
+
`)),console.log(` ${dim("Session calls:")} ${T}`),console.log(` ${dim("Est. tokens:")} ~${T*150}`),console.log("");}}async function Ne(){let e=Date.now()-Qe,o=Math.round(e/1e3),a$1=Math.floor(o/60),t=a$1>0?`${a$1}m ${o%60}s`:`${o}s`,n=0,i=0;console.log(""),console.log(bold(" \u2554\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2557")),console.log(bold(" \u2551 SESSION TELEMETRY \u2551")),console.log(bold(" \u255A\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u255D")),console.log(""),console.log(` ${dim("Session:")} ${t}`),console.log(` ${dim("API calls:")} ${T}`),console.log(` ${dim("Avg latency:")} ${n}ms`),console.log(` ${dim("Errors:")} ${Ue} (${i}%)`),console.log(""),console.log(dim(" \u2500\u2500 Environment \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500")),console.log(` ${dim("Node:")} ${process.version}`),console.log(` ${dim("Platform:")} ${process.platform} ${process.arch}`),console.log(` ${dim("Memory:")} ${Math.round(process.memoryUsage().heapUsed/1024/1024)}MB heap`),console.log(` ${dim("Config:")} ~/.langtrain/config.json`),console.log("");let s=f();if(s.apiKey){let r=p();r.start("Pinging API...");try{let c=a("axios"),l=s.baseUrl||"https://api.langtrain.xyz",w=Date.now();await c.get(`${l}/health`,{timeout:5e3});let k=Date.now()-w;r.stop(green(`API healthy (${k}ms)`));}catch{r.stop(yellow("API unreachable"));}}console.log("");}var je={version:"0.2.1"};function Oe(e){let{dim:o,green:a,yellow:t,cyan:n,bold:i,gray:s}=x,r=e?.plan==="pro"?i(a("PRO")):e?.plan==="enterprise"?i(a("ENTERPRISE")):o("FREE"),c=e?.usage?.tokensUsedThisMonth||0,l=e?.usage?.tokenLimit||1e4,w=Math.round(c/l*100),k=w>80?t(`${w}%`):a(`${w}%`);console.log(o(" \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500")),console.log(` ${o("Plan:")} ${r} ${o("\u2502")} ${o("Tokens:")} ${c.toLocaleString()}/${l.toLocaleString()} ${k}`),console.log(o(` \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500
|
|
20
20
|
`));}function Ve(e,o){return {vision:new q$1({apiKey:e}),tune:new r({apiKey:e}),agent:new d({apiKey:e,baseUrl:o}),model:new i({apiKey:e,baseUrl:o}),train:new g({apiKey:e,baseUrl:o}),secret:new k({apiKey:e,baseUrl:o})}}function nt(e){switch(e){case "main":return "What would you like to do?";case "agents":return "Agents:";case "text":return "Langtune (Text):";case "vision":return "Langvision (Vision):";case "guard":return "Guardrails:";case "settings":return "Settings:";default:return "Select an option:"}}async function at(){let e=new Command,o=je.version;e.name("langtrain").description("Langtrain CLI \u2014 Fine-tuning, Agents, and AI Ops").version(o),e.command("init").description("Initialize a new Langtrain project").action(oe),e.command("deploy").description("Deploy configuration to Langtrain Cloud").action(async()=>{let n=f(),i=n.apiKey||"",s=new d({apiKey:i,baseUrl:n.baseUrl});await j(s);}),e.command("dev").description("Start local development server").action(async()=>{let n=f(),i=n.apiKey||"",s=new d({apiKey:i,baseUrl:n.baseUrl});await re(s);}),e.command("env").description("Manage secrets and environment variables").action(async()=>{let n=f(),i=n.apiKey||"",s=new k({apiKey:i,baseUrl:n.baseUrl});await ge(s);}),e.command("logs [agent]").description("Stream logs from a deployed agent").action(async n=>{let i=f(),s=i.apiKey||"",r=new d({apiKey:s,baseUrl:i.baseUrl});await ue(r,n);}),e.command("login").description("Authenticate with your API key").action(async()=>{await N();}),e.command("logout").description("Clear stored credentials").action(async()=>{await ne();}),e.command("tokens").description("View token usage for current period").action(pe);let a=e.command("data").description("Manage datasets");a.command("upload [file]").description("Upload a dataset").action(async()=>{let n=f(),i=new f$1({apiKey:n.apiKey||"",baseUrl:n.baseUrl});await ie(i);}),a.command("refine [fileId]").description("Refine a dataset using guardrails").action(async n=>{let i=f(),s=new f$1({apiKey:i.apiKey||"",baseUrl:i.baseUrl});await se(s,n);});let t=e.command("guardrails").description("Manage data guardrails");t.command("list").description("List available guardrails").action(async()=>await le()),t.command("create").description("Create a new guardrail").action(async()=>await ce()),e.action(async()=>{W(o),process.argv.includes("--first-run")&&(process.stdin.isTTY?(v("Welcome to Langtrain! Let's get you set up."),await N()):(console.log('Langtrain installed! Run "npx langtrain login" to authenticate.'),process.exit(0)));let i=f(),s=i.apiKey||"",r=te(),c=null;if(r&&s){try{c=await J(s);}catch{}Oe(c);}else console.log(x.dim(` Not logged in. Only basic options available.
|
|
21
21
|
`));let l=r?Ve(s,i.baseUrl):null,w="main";for(;;){let k=await select({message:nt(w),options:Ce(w,c,r)});if(isCancel(k))if(w==="main")K("Goodbye!"),process.exit(0);else {w="main";continue}let S=k;if(S==="exit"&&(K("Goodbye!"),process.exit(0)),S==="back"){w="main";continue}if(S.startsWith("nav-")){w=S.replace("nav-","");continue}try{switch(S){case "login":if(await N(),i=f(),s=i.apiKey||"",r=te(),r){try{c=await J(s);}catch{}l=Ve(s,i.baseUrl),console.clear(),W(o),Oe(c);}break;case "logout":await ne(),s="",r=!1,c=null,l=null,console.clear(),W(o),console.log(x.dim(` Logged out. Only basic options available.
|
|
22
22
|
`));break;case "docs":console.log(x.cyan(`
|