opik 2.2.86 → 2.2.87
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/cli.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {spawnSync}from'child_process';import {chalkStderr}from'chalk';import {randomUUID,createHash}from'crypto';import C,{accessSync,constants}from'fs';import f from'os';import i from'path';import U from'ini';var L="https://stats.comet.com/notify/event/",x="opik_typescript_sdk__configuration__cli",l=3e3,_="default",p="npx",g="OPIK_CLI_LAUNCHER",h="2.2.87";function b(n){return `${x}__${n}`}function T(n=process.env){let e=n.OPIK_ANALYTICS_ENABLE;return e===void 0?true:!["0","false","no"].includes(e.trim().toLowerCase())}var K=/^--[a-z][a-z0-9-]*$/,D=/^-[A-Za-z]$/,M=/^[a-z][a-z0-9-]*$/,$=3;function V(n){let e=[],t=[],o=false;for(let r of n){if(r==="--")break;if(r.startsWith("-")){o=true;let s=r.split("=")[0];(K.test(s)||D.test(s))&&t.push(s);continue}!o&&e.length<$&&M.test(r)&&e.push(r);}return {command:e.join(" "),flags:[...new Set(t)].join(",")}}function F(n=process.env,e=f.homedir()){var r;let t=((r=E(n.OPIK_WORKSPACE))!=null?r:j(n,e)).trim();if(t!==""&&t!==_)return t;let o=createHash("sha256").update(f.hostname()+J()).digest("hex");return `${_}_${o}`}function v(n,e=process.env){var m;let t=T(e),o=(m=e.OPIK_ANALYTICS_URL)!=null?m:L,r=t?F(e):"",{command:s,flags:c}=V(n),A=randomUUID(),u=[];return {track(d,O={}){if(!t||o==="")return;let w={anonymous_id:r,event_type:b(d),event_properties:{run_id:A,launcher:p,sdk_version:h,command:s,flags:c,node_version:process.versions.node,os:process.platform,arch:process.arch,ci:!!e.CI,...O}};u.push(H(o,w));},async flush(){u.length!==0&&await Promise.race([Promise.allSettled(u),new Promise(d=>setTimeout(d,l).unref())]);}}}async function H(n,e){try{await fetch(n,{method:"POST",headers:{"Content-Type":"application/json","User-Agent":`opik-typescript-sdk/${h}`},body:JSON.stringify(e),signal:AbortSignal.timeout(l)});}catch{}}function j(n,e){var r;let t=E(n.OPIK_CONFIG_PATH),o=t===void 0?i.join(e,".opik.config"):t.trim().replace(/^~(?=$|\/|\\)/,e);try{let s=U.parse(C.readFileSync(o,"utf8")),c=(r=s==null?void 0:s.opik)==null?void 0:r.workspace;return typeof c=="string"?c:""}catch{return ""}}function E(n){return n===void 0||n.trim()===""?void 0:n}function J(){try{return f.userInfo().username}catch{return ""}}var X=1e4;function y(n=process.platform){return n==="win32"?"uv.exe":"uv"}function Y(n=process.env,e=process.platform,t=f.homedir()){let o=[S(n.XDG_BIN_HOME),S(n.CARGO_HOME,"bin"),i.join(t,".local","bin"),i.join(t,".cargo","bin")].filter(s=>s!==void 0),r=y(e);return [...new Set(o)].map(s=>i.join(s,r))}function S(n,...e){let t=(n!=null?n:"").trim();if(!(t===""||!i.isAbsolute(t)))return i.join(t,...e)}function P(){let n=y();if(N(n))return {path:n,source:"path"};for(let e of Y())if(q(e)&&N(e))return {path:e,source:"install-dir"}}function q(n){try{return accessSync(n,constants.X_OK),!0}catch{return false}}function N(n){let e=spawnSync(n,["--version"],{stdio:"ignore",timeout:X});return e.error===void 0&&e.status===0}var Q="https://www.comet.com/docs/opik/mcp-server#install-uv-if-you-dont-have-it";async function nn(){var r;let n=process.argv.slice(2),e=v(n);e.track("invoked");let t=P();if(e.track("uv_detected",{uv_found:t!==void 0,uv_source:t==null?void 0:t.source}),t===void 0)return process.stderr.write(`
|
|
3
|
+
${chalkStderr.red("\u2717")} ${chalkStderr.bold("The Opik MCP configuration requires uv, which is not installed on this machine.")}
|
|
4
|
+
|
|
5
|
+
How to install uv: ${chalkStderr.cyan.underline(Q)}
|
|
6
|
+
|
|
7
|
+
Once it is installed, re-run this command.
|
|
8
|
+
|
|
9
|
+
`),e.track("error_shown",{reason:"uv_missing"}),await e.flush(),1;e.track("handoff"),await e.flush();let o=spawnSync(t.path,["tool","run","opik",...n],{stdio:"inherit",env:{...process.env,[g]:p}});return o.error!==void 0?(process.stderr.write(chalkStderr.red(`Could not run uv: ${o.error.message}`)+`
|
|
10
|
+
`),1):(r=o.status)!=null?r:1}nn().then(n=>{process.exitCode=n;},n=>{process.stderr.write(`${String(n)}
|
|
11
|
+
`),process.exitCode=1;});
|