@tangle-network/sandbox-cli 0.23.322 → 0.23.324

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.
@@ -1 +1 @@
1
- import{D as e,E as t,_ as n}from"./config-CGCqj2Y-.mjs";function r(e){return t(`solve`,e.profile)}function i(e){let t=r(e),i=n(void 0,t);if(!i)throw Error(`No Solve credential found for profile '${t}'. Run: tangle auth login --provider github --app solve`);return i}async function a(t){let n=e(t.apiUrl),r=await fetch(`${n}${t.path}`,{method:t.method??`GET`,headers:{Accept:`application/json`,...t.body===void 0?{}:{"Content-Type":`application/json`},Authorization:`Bearer ${i(t)}`},...t.body===void 0?{}:{body:JSON.stringify(t.body)},signal:AbortSignal.timeout(3e4)}),a=await r.json().catch(()=>null);if(!r.ok||!a?.success||a.data===void 0){let e=a?.error?.message??`Solve API request failed with HTTP ${r.status}`;throw Error(a?.error?.code?`${a.error.code}: ${e}`:e)}return a.data}function o(e){return a({path:`/v1/wallet/challenges`,method:`POST`,apiUrl:e.apiUrl,profile:e.profile,body:{deviceAddress:e.deviceAddress,...e.purpose?{purpose:e.purpose}:{}}})}function s(e){return a({path:`/v1/devices`,apiUrl:e.apiUrl,profile:e.profile})}function c(e){return a({path:`/v1/devices/revoke`,method:`POST`,apiUrl:e.apiUrl,profile:e.profile,body:{deviceAddress:e.deviceAddress,...e.reason?{reason:e.reason}:{},...e.challengeId&&e.signature?{challengeId:e.challengeId,signature:e.signature}:{}}})}export{a,r as i,s as n,c as r,o as t};
1
+ import{D as e,E as t,_ as n}from"./config-XvvPPjWh.mjs";function r(e){return t(`solve`,e.profile)}function i(e){let t=r(e),i=n(void 0,t);if(!i)throw Error(`No Solve credential found for profile '${t}'. Run: tangle auth login --provider github --app solve`);return i}async function a(t){let n=e(t.apiUrl),r=await fetch(`${n}${t.path}`,{method:t.method??`GET`,headers:{Accept:`application/json`,...t.body===void 0?{}:{"Content-Type":`application/json`},Authorization:`Bearer ${i(t)}`},...t.body===void 0?{}:{body:JSON.stringify(t.body)},signal:AbortSignal.timeout(3e4)}),a=await r.json().catch(()=>null);if(!r.ok||!a?.success||a.data===void 0){let e=a?.error?.message??`Solve API request failed with HTTP ${r.status}`;throw Error(a?.error?.code?`${a.error.code}: ${e}`:e)}return a.data}function o(e){return a({path:`/v1/wallet/challenges`,method:`POST`,apiUrl:e.apiUrl,profile:e.profile,body:{deviceAddress:e.deviceAddress,...e.purpose?{purpose:e.purpose}:{}}})}function s(e){return a({path:`/v1/devices`,apiUrl:e.apiUrl,profile:e.profile})}function c(e){return a({path:`/v1/devices/revoke`,method:`POST`,apiUrl:e.apiUrl,profile:e.profile,body:{deviceAddress:e.deviceAddress,...e.reason?{reason:e.reason}:{},...e.challengeId&&e.signature?{challengeId:e.challengeId,signature:e.signature}:{}}})}export{a,r as i,s as n,c as r,o as t};
@@ -1 +1 @@
1
- import{a as e,f as t,r as n,u as r}from"./output-BRdLZpee.mjs";import{r as i}from"./errors-DrYiP5_c.mjs";import{f as a,g as o,i as s,p as c,r as l,t as u}from"./workspace-Ikei3Odt.mjs";import{a as d}from"./api-BfuOcfdS.mjs";import*as f from"node:path";import{execFile as p}from"node:child_process";import{promisify as m}from"node:util";const h=m(p);function g(){return`Task source is '${u}'. Add your fork as 'origin', commit your candidate, push it, and open a pull request before submitting.`}async function _(p,m,_){try{let i=o(await d({path:`/v1/competitions/${encodeURIComponent(p)}`,apiUrl:_.apiUrl,profile:_.profile}),`competition response`),v=c(i.competition??i),y=f.resolve(m??v.slug),b=r(`Cloning ${v.slug}…`);_.json||b.start();try{await h(`git`,[`clone`,`--no-tags`,`--origin`,u,v.repository,y],{encoding:`utf8`,maxBuffer:1e6}),await l(y,[`checkout`,`--detach`,v.taskRevision]);let e=await l(y,[`rev-parse`,`HEAD`]);if(e.toLowerCase()!==v.taskRevision.toLowerCase())throw Error(`Pinned checkout resolved to ${e}, expected ${v.taskRevision}`);await a(f.join(y,`.tangle-solve.json`),v),await s(y)}finally{b.stop()}_.json?e({competition:v,directory:y}):(t(`Cloned ${v.slug} at ${v.taskRevision.slice(0,12)}`),v.provenance&&n(g()),n(`Run the pinned checker with: cd ${y} && tangle solve run`))}catch(e){i(e)}}export{_ as cloneCompetition};
1
+ import{a as e,f as t,r as n,u as r}from"./output-BRdLZpee.mjs";import{r as i}from"./errors-CzkPwUni.mjs";import{f as a,g as o,i as s,p as c,r as l,t as u}from"./workspace-Ikei3Odt.mjs";import{a as d}from"./api-CXfJ5r0E.mjs";import*as f from"node:path";import{execFile as p}from"node:child_process";import{promisify as m}from"node:util";const h=m(p);function g(){return`Task source is '${u}'. Add your fork as 'origin', commit your candidate, push it, and open a pull request before submitting.`}async function _(p,m,_){try{let i=o(await d({path:`/v1/competitions/${encodeURIComponent(p)}`,apiUrl:_.apiUrl,profile:_.profile}),`competition response`),v=c(i.competition??i),y=f.resolve(m??v.slug),b=r(`Cloning ${v.slug}…`);_.json||b.start();try{await h(`git`,[`clone`,`--no-tags`,`--origin`,u,v.repository,y],{encoding:`utf8`,maxBuffer:1e6}),await l(y,[`checkout`,`--detach`,v.taskRevision]);let e=await l(y,[`rev-parse`,`HEAD`]);if(e.toLowerCase()!==v.taskRevision.toLowerCase())throw Error(`Pinned checkout resolved to ${e}, expected ${v.taskRevision}`);await a(f.join(y,`.tangle-solve.json`),v),await s(y)}finally{b.stop()}_.json?e({competition:v,directory:y}):(t(`Cloned ${v.slug} at ${v.taskRevision.slice(0,12)}`),v.provenance&&n(g()),n(`Run the pinned checker with: cd ${y} && tangle solve run`))}catch(e){i(e)}}export{_ as cloneCompetition};
@@ -1 +1 @@
1
- import{t as e}from"./errors-DrYiP5_c.mjs";import{i as t,n,r}from"./credential-store-HDfpBBkD.mjs";import*as i from"node:fs";import*as a from"node:path";import{randomBytes as o}from"node:crypto";import*as s from"node:os";const c=a.join(s.homedir(),`.tangle`),l=a.join(c,`config.json`),u=`https://id.tangle.tools`,d=`https://solve.tangle.tools/api/solve`,f=`default`;function p(){return{tangleBaseUrl:process.env.TANGLE_BASE_URL,sandboxBaseUrl:process.env.SANDBOX_BASE_URL,hubUrl:process.env.TANGLE_HUB_URL}}function m(e,t){let n=b(t??(e===`solve`?`solve`:void 0));if(e===`solve`){if(n!==`solve`)throw Error(`The solve app cannot use profile '${n}'. Use the reserved 'solve' profile.`);return n}if(e===`sandbox`&&!t&&n===`solve`)return f;if(new Set([`solve`]).has(n))throw Error(`The ${e} app cannot use the reserved '${n}' profile. Use the '${e}' profile or choose a custom profile.`);return n}function h(){i.existsSync(c)||i.mkdirSync(c,{mode:448,recursive:!0})}function g(e,t){h();let n=`${e}.${process.pid}.tmp`;i.writeFileSync(n,t,{mode:384}),i.renameSync(n,e)}function _(e){return e.startsWith(`sk_`)||e.startsWith(`sk-tan-`)}function v(){try{if(i.existsSync(l))return JSON.parse(i.readFileSync(l,`utf-8`))}catch{}return{}}function y(e){let t=te(v(),e);g(l,`${JSON.stringify(t,null,2)}\n`)}function b(e){return $(e||process.env.TANGLE_PROFILE||process.env.SANDBOX_PROFILE||v().activeProfile||f)}function x(e){y({activeProfile:$(e)})}function S(){return{token:process.env.TANGLE_LINE_TOKEN,baseUrl:process.env.TANGLE_HUB_URL}}function C(){return process.env.TANGLE_SANDBOX||v().currentSandbox||void 0}function w(e){y({currentSandbox:e})}function T(){let e=v();delete e.currentSandbox,g(l,`${JSON.stringify(e,null,2)}\n`)}function E(){let e=v().deviceId;if(e&&/^[A-Za-z0-9_.-]{1,64}$/.test(e))return e;let t=s.hostname().replace(/[^A-Za-z0-9_.-]/g,`-`).replace(/^-+|-+$/g,``).slice(0,32),n=o(4).toString(`hex`),r=`${t?`${t}-`:`device-`}${n}`;return y({deviceId:r}),r}function D(){let e=v(),t=b(),n=new Set([f,...Object.keys(e.profiles??{})]);return e.activeProfile&&n.add($(e.activeProfile)),[...n].map(e=>{let n=r(e).source;return{name:e,active:e===t,hasApiKey:n!==`none`,baseUrl:R(void 0,e),apiKeySource:n}}).sort((e,t)=>e.name.localeCompare(t.name))}function O(e){let t=b(e);return{name:t,active:t===b(),baseUrl:R(void 0,t),credentialSource:r(t).source}}function k(e,n){let r=$(e),i=v(),a=Q(r,i),o={},s=n.baseUrl??a.baseUrl;s&&(o.baseUrl=s);let c=n.platformUrl===void 0?a.platformUrl:n.platformUrl;c&&(o.platformUrl=c);let l=n.activeTeamId??a.activeTeamId;l&&(o.activeTeamId=l);let u=n.activeTeamName??a.activeTeamName;u&&(o.activeTeamName=u);let d={...i.profiles??{}};o.baseUrl||o.platformUrl||o.activeTeamId||o.activeTeamName?d[r]=o:delete d[r];let f;return n.apiKey&&(f=t(r,n.apiKey)),y({profiles:Object.keys(d).length>0?d:{}}),f}function A(e){let t=b(e),r={...v().profiles??{}},i=r[t];if(i){let e={...i};e.baseUrl||e.platformUrl||e.activeTeamId||e.activeTeamName?r[t]=e:delete r[t]}y({profiles:r}),n(t)}function j(){let e=process.env.TANGLE_API_KEY_FILE;if(e){let t=i.readFileSync(e,`utf8`).trim();if(!t.startsWith(`sk-tan-`))throw Error(`Invalid sandbox credential file`);return t}return process.env.TANGLE_API_KEY}const ee={intelligence:`https://intelligence.tangle.tools`,router:`https://router.tangle.tools/v1`};function M(e,t,n){return N(`sandbox`,R(n,t),e,t)}function N(e,t,n,i){if(n)return n;let a=j();if(a)return a;let o=r(m(`sandbox`,i)).value;return o&&t!==void 0&&P(e,t,i),o}function P(t,n,r){let i=t===`sandbox`?B(r):t===`platform`?W(r)??u:ee[t],a=e=>{try{let t=new URL(e.trim()).origin;return t===`null`?void 0:t}catch{return}},o=e=>t===`sandbox`?e.trim().replace(/\/+$/,``).toLowerCase():a(e),s=o(n);if(s!==void 0&&s===o(i))return;let c={sandbox:`unset ${process.env.SANDBOX_BASE_URL&&!process.env.TANGLE_BASE_URL?`SANDBOX_BASE_URL`:`TANGLE_BASE_URL`} or drop --base-url`,platform:`unset TANGLE_PLATFORM_URL and TANGLE_HUB_URL, or drop --base-url and --platform-url`,intelligence:`unset TANGLE_INTELLIGENCE_BASE_URL, or drop --base-url and --endpoint`,router:`unset TANGLE_ROUTER_URL`}[t],l={sandbox:`if you run your own install at ${n}: tangle auth login --base-url ${n}`,platform:`if you run your own install at ${n}: TANGLE_PLATFORM_URL=${n} tangle auth login`,intelligence:`pass the key for ${n} with --api-key or TANGLE_API_KEY`,router:`pass the key for ${n} with --api-key or TANGLE_API_KEY`}[t];throw new e(`CREDENTIAL_ADDRESS_MISMATCH`,`The stored credential is for ${i}, not ${n}, so it was not sent`,`a flag or the environment named that address`,c,[l])}function F(e,t){return e||(process.env.TANGLE_SOLVE_API_KEY?process.env.TANGLE_SOLVE_API_KEY:r(m(`solve`,t)).value)}function I(e,t){let n=m(`sandbox`,t);return e?`flag`:process.env.TANGLE_API_KEY_FILE||process.env.TANGLE_API_KEY?`env`:r(n).source}function L(e,t){return e?`flag`:process.env.TANGLE_SOLVE_API_KEY?`env`:r(m(`solve`,t)).source}function R(e,t){return z(e)||B(t)}function z(e){return e||process.env.TANGLE_BASE_URL||process.env.SANDBOX_BASE_URL||void 0}function B(e){let t=b(e),n=v(),r=Q(t,n);return r.baseUrl?r.baseUrl:(t===f||t===`sandbox`)&&n.baseUrl?n.baseUrl:`https://sandbox.tangle.tools`}function V(e){if(e)return e.replace(/\/v1\/hub\/?$/,``)}function H(e){return e?.trim().replace(/\/+$/,``)||void 0}function U(e){return H(e?.flag)??G()??H(e?.cachedPlatformUrl?.())??H(W(e?.profile))??u}function W(e){return Q(b(e),v()).platformUrl}function G(){return H(V(H(process.env.TANGLE_HUB_URL)))??H(process.env.TANGLE_PLATFORM_URL)}function K(e){let t=H(e)??H(process.env.TANGLE_SOLVE_API_URL);if(t&&t!==d)throw Error(`Solve credentials may only be sent to ${d}`);return d}function q(e){let t=H(e);if(t&&t!==u)throw Error(`Solve credentials may only be sent to ${u}`);return u}function J(e){let t=m(`sandbox`,e.profile),n=M(e.apiKey,t,e.baseUrl);if(!n)throw Error(`No API key found for profile '${t}'. Set TANGLE_API_KEY or run: tangle auth login${t===f?``:` --profile ${t}`}`);return{apiKey:n,baseUrl:R(e.baseUrl,t),timeout:e.timeout??3e4,profile:t,...Y(t)}}function Y(e){let t=v(),n=Q(b(e),t);return{activeTeamId:n.activeTeamId,activeTeamName:n.activeTeamName}}function X(e,t){k(b(t),{activeTeamId:e.id,activeTeamName:e.name})}function Z(e){let t=b(e),n=v(),r={...n.profiles??{}},i=Q(t,n),a={baseUrl:i.baseUrl,platformUrl:i.platformUrl};a.baseUrl||a.platformUrl?r[t]=a:delete r[t],y({profiles:r})}function Q(e,t=v()){let n=$(e);return{...n===f?{baseUrl:t.baseUrl,activeTeamId:t.profiles?.[f]?.activeTeamId,activeTeamName:t.profiles?.[f]?.activeTeamName}:{},...t.profiles?.[n]??{}}}function te(e,t){let n=t.profiles===void 0?{...e.profiles??{}}:Object.fromEntries(Object.entries(t.profiles).filter(([,e])=>!!(e.apiKey||e.baseUrl||e.platformUrl||e.activeTeamId||e.activeTeamName)));return{...e,...t,profiles:Object.keys(n).length>0?n:void 0}}function $(e){let t=e.trim().toLowerCase();if(!t)throw Error(`Profile name cannot be empty`);if(!/^[a-z0-9][a-z0-9._-]*$/.test(t))throw Error(`Profile names may only contain lowercase letters, numbers, dots, underscores, and hyphens`);return t}export{k as A,p as C,K as D,m as E,X as M,w as N,q as O,G as S,U as T,F as _,Z as a,D as b,M as c,R as d,C as f,O as g,S as h,J as i,x as j,y as k,N as l,j as m,P as n,T as o,E as p,z as r,Y as s,c as t,I as u,L as v,A as w,v as x,_ as y};
1
+ import{t as e}from"./errors-CzkPwUni.mjs";import{i as t,n,r}from"./credential-store-HDfpBBkD.mjs";import*as i from"node:fs";import*as a from"node:path";import{randomBytes as o}from"node:crypto";import*as s from"node:os";const c=a.join(s.homedir(),`.tangle`),l=a.join(c,`config.json`),u=`https://id.tangle.tools`,d=`https://solve.tangle.tools/api/solve`,f=`default`;function p(){return{tangleBaseUrl:process.env.TANGLE_BASE_URL,sandboxBaseUrl:process.env.SANDBOX_BASE_URL,hubUrl:process.env.TANGLE_HUB_URL}}function m(e,t){let n=b(t??(e===`solve`?`solve`:void 0));if(e===`solve`){if(n!==`solve`)throw Error(`The solve app cannot use profile '${n}'. Use the reserved 'solve' profile.`);return n}if(e===`sandbox`&&!t&&n===`solve`)return f;if(new Set([`solve`]).has(n))throw Error(`The ${e} app cannot use the reserved '${n}' profile. Use the '${e}' profile or choose a custom profile.`);return n}function h(){i.existsSync(c)||i.mkdirSync(c,{mode:448,recursive:!0})}function g(e,t){h();let n=`${e}.${process.pid}.tmp`;i.writeFileSync(n,t,{mode:384}),i.renameSync(n,e)}function _(e){return e.startsWith(`sk_`)||e.startsWith(`sk-tan-`)}function v(){try{if(i.existsSync(l))return JSON.parse(i.readFileSync(l,`utf-8`))}catch{}return{}}function y(e){let t=te(v(),e);g(l,`${JSON.stringify(t,null,2)}\n`)}function b(e){return $(e||process.env.TANGLE_PROFILE||process.env.SANDBOX_PROFILE||v().activeProfile||f)}function x(e){y({activeProfile:$(e)})}function S(){return{token:process.env.TANGLE_LINE_TOKEN,baseUrl:process.env.TANGLE_HUB_URL}}function C(){return process.env.TANGLE_SANDBOX||v().currentSandbox||void 0}function w(e){y({currentSandbox:e})}function T(){let e=v();delete e.currentSandbox,g(l,`${JSON.stringify(e,null,2)}\n`)}function E(){let e=v().deviceId;if(e&&/^[A-Za-z0-9_.-]{1,64}$/.test(e))return e;let t=s.hostname().replace(/[^A-Za-z0-9_.-]/g,`-`).replace(/^-+|-+$/g,``).slice(0,32),n=o(4).toString(`hex`),r=`${t?`${t}-`:`device-`}${n}`;return y({deviceId:r}),r}function D(){let e=v(),t=b(),n=new Set([f,...Object.keys(e.profiles??{})]);return e.activeProfile&&n.add($(e.activeProfile)),[...n].map(e=>{let n=r(e).source;return{name:e,active:e===t,hasApiKey:n!==`none`,baseUrl:R(void 0,e),apiKeySource:n}}).sort((e,t)=>e.name.localeCompare(t.name))}function O(e){let t=b(e);return{name:t,active:t===b(),baseUrl:R(void 0,t),credentialSource:r(t).source}}function k(e,n){let r=$(e),i=v(),a=Q(r,i),o={},s=n.baseUrl??a.baseUrl;s&&(o.baseUrl=s);let c=n.platformUrl===void 0?a.platformUrl:n.platformUrl;c&&(o.platformUrl=c);let l=n.activeTeamId??a.activeTeamId;l&&(o.activeTeamId=l);let u=n.activeTeamName??a.activeTeamName;u&&(o.activeTeamName=u);let d={...i.profiles??{}};o.baseUrl||o.platformUrl||o.activeTeamId||o.activeTeamName?d[r]=o:delete d[r];let f;return n.apiKey&&(f=t(r,n.apiKey)),y({profiles:Object.keys(d).length>0?d:{}}),f}function A(e){let t=b(e),r={...v().profiles??{}},i=r[t];if(i){let e={...i};e.baseUrl||e.platformUrl||e.activeTeamId||e.activeTeamName?r[t]=e:delete r[t]}y({profiles:r}),n(t)}function j(){let e=process.env.TANGLE_API_KEY_FILE;if(e){let t=i.readFileSync(e,`utf8`).trim();if(!t.startsWith(`sk-tan-`))throw Error(`Invalid sandbox credential file`);return t}return process.env.TANGLE_API_KEY}const ee={intelligence:`https://intelligence.tangle.tools`,router:`https://router.tangle.tools/v1`};function M(e,t,n){return N(`sandbox`,R(n,t),e,t)}function N(e,t,n,i){if(n)return n;let a=j();if(a)return a;let o=r(m(`sandbox`,i)).value;return o&&t!==void 0&&P(e,t,i),o}function P(t,n,r){let i=t===`sandbox`?B(r):t===`platform`?W(r)??u:ee[t],a=e=>{try{let t=new URL(e.trim()).origin;return t===`null`?void 0:t}catch{return}},o=e=>t===`sandbox`?e.trim().replace(/\/+$/,``).toLowerCase():a(e),s=o(n);if(s!==void 0&&s===o(i))return;let c={sandbox:`unset ${process.env.SANDBOX_BASE_URL&&!process.env.TANGLE_BASE_URL?`SANDBOX_BASE_URL`:`TANGLE_BASE_URL`} or drop --base-url`,platform:`unset TANGLE_PLATFORM_URL and TANGLE_HUB_URL, or drop --base-url and --platform-url`,intelligence:`unset TANGLE_INTELLIGENCE_BASE_URL, or drop --base-url and --endpoint`,router:`unset TANGLE_ROUTER_URL`}[t],l={sandbox:`if you run your own install at ${n}: tangle auth login --base-url ${n}`,platform:`if you run your own install at ${n}: TANGLE_PLATFORM_URL=${n} tangle auth login`,intelligence:`pass the key for ${n} with --api-key or TANGLE_API_KEY`,router:`pass the key for ${n} with --api-key or TANGLE_API_KEY`}[t];throw new e(`CREDENTIAL_ADDRESS_MISMATCH`,`The stored credential is for ${i}, not ${n}, so it was not sent`,`a flag or the environment named that address`,c,[l])}function F(e,t){return e||(process.env.TANGLE_SOLVE_API_KEY?process.env.TANGLE_SOLVE_API_KEY:r(m(`solve`,t)).value)}function I(e,t){let n=m(`sandbox`,t);return e?`flag`:process.env.TANGLE_API_KEY_FILE||process.env.TANGLE_API_KEY?`env`:r(n).source}function L(e,t){return e?`flag`:process.env.TANGLE_SOLVE_API_KEY?`env`:r(m(`solve`,t)).source}function R(e,t){return z(e)||B(t)}function z(e){return e||process.env.TANGLE_BASE_URL||process.env.SANDBOX_BASE_URL||void 0}function B(e){let t=b(e),n=v(),r=Q(t,n);return r.baseUrl?r.baseUrl:(t===f||t===`sandbox`)&&n.baseUrl?n.baseUrl:`https://sandbox.tangle.tools`}function V(e){if(e)return e.replace(/\/v1\/hub\/?$/,``)}function H(e){return e?.trim().replace(/\/+$/,``)||void 0}function U(e){return H(e?.flag)??G()??H(e?.cachedPlatformUrl?.())??H(W(e?.profile))??u}function W(e){return Q(b(e),v()).platformUrl}function G(){return H(V(H(process.env.TANGLE_HUB_URL)))??H(process.env.TANGLE_PLATFORM_URL)}function K(e){let t=H(e)??H(process.env.TANGLE_SOLVE_API_URL);if(t&&t!==d)throw Error(`Solve credentials may only be sent to ${d}`);return d}function q(e){let t=H(e);if(t&&t!==u)throw Error(`Solve credentials may only be sent to ${u}`);return u}function J(e){let t=m(`sandbox`,e.profile),n=M(e.apiKey,t,e.baseUrl);if(!n)throw Error(`No API key found for profile '${t}'. Set TANGLE_API_KEY or run: tangle auth login${t===f?``:` --profile ${t}`}`);return{apiKey:n,baseUrl:R(e.baseUrl,t),timeout:e.timeout??3e4,profile:t,...Y(t)}}function Y(e){let t=v(),n=Q(b(e),t);return{activeTeamId:n.activeTeamId,activeTeamName:n.activeTeamName}}function X(e,t){k(b(t),{activeTeamId:e.id,activeTeamName:e.name})}function Z(e){let t=b(e),n=v(),r={...n.profiles??{}},i=Q(t,n),a={baseUrl:i.baseUrl,platformUrl:i.platformUrl};a.baseUrl||a.platformUrl?r[t]=a:delete r[t],y({profiles:r})}function Q(e,t=v()){let n=$(e);return{...n===f?{baseUrl:t.baseUrl,activeTeamId:t.profiles?.[f]?.activeTeamId,activeTeamName:t.profiles?.[f]?.activeTeamName}:{},...t.profiles?.[n]??{}}}function te(e,t){let n=t.profiles===void 0?{...e.profiles??{}}:Object.fromEntries(Object.entries(t.profiles).filter(([,e])=>!!(e.apiKey||e.baseUrl||e.platformUrl||e.activeTeamId||e.activeTeamName)));return{...e,...t,profiles:Object.keys(n).length>0?n:void 0}}function $(e){let t=e.trim().toLowerCase();if(!t)throw Error(`Profile name cannot be empty`);if(!/^[a-z0-9][a-z0-9._-]*$/.test(t))throw Error(`Profile names may only contain lowercase letters, numbers, dots, underscores, and hyphens`);return t}export{k as A,p as C,K as D,m as E,X as M,w as N,q as O,G as S,U as T,F as _,Z as a,D as b,M as c,R as d,C as f,O as g,S as h,J as i,x as j,y as k,N as l,j as m,P as n,T as o,E as p,z as r,Y as s,c as t,I as u,L as v,A as w,v as x,_ as y};
@@ -1 +1 @@
1
- import{a as e,f as t,i as n,p as r,r as i}from"./output-BRdLZpee.mjs";import{r as a}from"./errors-DrYiP5_c.mjs";import{t as o}from"./prompts-C34KLXxj.mjs";import{n as s,r as c}from"./solve-signer-DHk_-W9I.mjs";import{n as l,r as u,t as d}from"./api-BfuOcfdS.mjs";import{t as f}from"./deployment-DRFHWxa_.mjs";import{n as p,o as m,v as h,x as g}from"./transactions-BoyuFZSe.mjs";import{createPublicClient as _,getAddress as v,http as y,isAddress as b}from"viem";import{tempoModerato as x}from"viem/chains";const S={...f,chainName:`Tempo Moderato`,nativeSymbol:`TNT`},C={async read(e){let t=_({chain:x,transport:y(S.rpcUrl,{timeout:15e3})}),n=e=>e.catch(()=>null),r=await Promise.all(e.map(async e=>{let[r,i]=await Promise.all([n(t.readContract({address:S.tangleAddress,abi:g,functionName:`isPermittedCaller`,args:[S.serviceId,e]})),n(t.readContract({address:S.managerAddress,abi:h,functionName:`isDeviceRevoked`,args:[e]}))]);return[e.toLowerCase(),{permitted:r,revoked:i}]}));return new Map(r)},async revokeSelf(e){return p(await m(S,e),S)}},w={permitted:null,revoked:null};function T(e){return e.revoked?`revoked`:e.permitted===null?`unknown`:e.permitted?`permitted`:`not permitted`}async function E(t,r=C){try{let{devices:i}=await l({apiUrl:t.apiUrl,profile:t.profile}),a=s()?.account.address.toLowerCase(),o=i.map(e=>({...e,local:e.address===a,status:e.revokedAt?`revoked`:`active`}));a&&!o.some(e=>e.local)&&o.push({address:a,local:!0,status:`unbound`,boundAt:null,lastUsedAt:null,revokedAt:null,revocationMethod:null,revocationReason:null});let c=await r.read(o.map(e=>v(e.address))),u=o.map(e=>({...e,onChain:c.get(e.address)??w}));if(t.json){e({serviceId:S.serviceId.toString(),devices:u});return}n([`Address`,`Status`,`Local`,`Service ${S.serviceId}`,`Last used`,`Revoked`],u.map(e=>[e.address,e.status,e.local?`yes`:``,T(e.onChain),e.lastUsedAt??``,e.revokedAt?`${e.revokedAt} (${e.revocationMethod})`:``]))}catch(e){a(e,t.json)}}async function D(n,l,f=C){try{if(!b(n))throw Error(`${n} is not an EVM address`);let a=v(n),p=s(),m=p?.account.address===a;if(!l.yes){if(!process.stdin.isTTY)throw Error(`Revoking a device is permanent. Re-run with --yes to confirm`);if(!await o(`Permanently revoke Solve device ${a}${m?` (this machine's device)`:``}? [y/N] `,`--yes`)){i(`Revocation cancelled`);return}}let h;if(p&&m){let e=await d({deviceAddress:a,purpose:`revoke`,apiUrl:l.apiUrl,profile:l.profile});h={challengeId:e.challengeId,signature:await p.account.signMessage({message:e.message})}}let g=await u({deviceAddress:a,reason:l.reason,...h,apiUrl:l.apiUrl,profile:l.profile}),_=a.toLowerCase(),y=(await f.read([a])).get(_)??w,x;if(p&&m&&!y.revoked){try{x=await f.revokeSelf(p.account)}catch(e){let t=e instanceof Error?e.message:String(e);throw Error(`The Solve API revoked ${a}, but the on-chain revocation failed and the local key was kept: ${t}. Run the command again to retry`)}y=(await f.read([a])).get(_)??w}let C=p&&m&&y.revoked?c(p):void 0;if(l.json){e({...g,serviceId:S.serviceId.toString(),onChain:y,...x?{revocationTransaction:x}:{},localKeyRetired:!!C});return}t(g.alreadyRevoked?`${a} was already revoked in the Solve API`:`Revoked ${a}; the Solve API refuses its signatures`),x&&t(`Revoked on Tempo in ${x}; service ${S.serviceId} refuses its jobs`),C&&i("The local device key was moved aside because its address may still hold stake or rewards. Run `tangle solve account --create` for a new device"),!m&&y.permitted&&r(`The device can still submit jobs to service ${S.serviceId}. Only its key, or the Solve blueprint owner, can revoke it on chain`)}catch(e){a(e,l.json)}}export{E as listSolveDevices,D as revokeSolveDevice};
1
+ import{a as e,f as t,i as n,p as r,r as i}from"./output-BRdLZpee.mjs";import{r as a}from"./errors-CzkPwUni.mjs";import{t as o}from"./prompts-C34KLXxj.mjs";import{n as s,r as c}from"./solve-signer-DHk_-W9I.mjs";import{n as l,r as u,t as d}from"./api-CXfJ5r0E.mjs";import{t as f}from"./deployment-DRFHWxa_.mjs";import{n as p,o as m,v as h,x as g}from"./transactions-BoyuFZSe.mjs";import{createPublicClient as _,getAddress as v,http as y,isAddress as b}from"viem";import{tempoModerato as x}from"viem/chains";const S={...f,chainName:`Tempo Moderato`,nativeSymbol:`TNT`},C={async read(e){let t=_({chain:x,transport:y(S.rpcUrl,{timeout:15e3})}),n=e=>e.catch(()=>null),r=await Promise.all(e.map(async e=>{let[r,i]=await Promise.all([n(t.readContract({address:S.tangleAddress,abi:g,functionName:`isPermittedCaller`,args:[S.serviceId,e]})),n(t.readContract({address:S.managerAddress,abi:h,functionName:`isDeviceRevoked`,args:[e]}))]);return[e.toLowerCase(),{permitted:r,revoked:i}]}));return new Map(r)},async revokeSelf(e){return p(await m(S,e),S)}},w={permitted:null,revoked:null};function T(e){return e.revoked?`revoked`:e.permitted===null?`unknown`:e.permitted?`permitted`:`not permitted`}async function E(t,r=C){try{let{devices:i}=await l({apiUrl:t.apiUrl,profile:t.profile}),a=s()?.account.address.toLowerCase(),o=i.map(e=>({...e,local:e.address===a,status:e.revokedAt?`revoked`:`active`}));a&&!o.some(e=>e.local)&&o.push({address:a,local:!0,status:`unbound`,boundAt:null,lastUsedAt:null,revokedAt:null,revocationMethod:null,revocationReason:null});let c=await r.read(o.map(e=>v(e.address))),u=o.map(e=>({...e,onChain:c.get(e.address)??w}));if(t.json){e({serviceId:S.serviceId.toString(),devices:u});return}n([`Address`,`Status`,`Local`,`Service ${S.serviceId}`,`Last used`,`Revoked`],u.map(e=>[e.address,e.status,e.local?`yes`:``,T(e.onChain),e.lastUsedAt??``,e.revokedAt?`${e.revokedAt} (${e.revocationMethod})`:``]))}catch(e){a(e,t.json)}}async function D(n,l,f=C){try{if(!b(n))throw Error(`${n} is not an EVM address`);let a=v(n),p=s(),m=p?.account.address===a;if(!l.yes){if(!process.stdin.isTTY)throw Error(`Revoking a device is permanent. Re-run with --yes to confirm`);if(!await o(`Permanently revoke Solve device ${a}${m?` (this machine's device)`:``}? [y/N] `,`--yes`)){i(`Revocation cancelled`);return}}let h;if(p&&m){let e=await d({deviceAddress:a,purpose:`revoke`,apiUrl:l.apiUrl,profile:l.profile});h={challengeId:e.challengeId,signature:await p.account.signMessage({message:e.message})}}let g=await u({deviceAddress:a,reason:l.reason,...h,apiUrl:l.apiUrl,profile:l.profile}),_=a.toLowerCase(),y=(await f.read([a])).get(_)??w,x;if(p&&m&&!y.revoked){try{x=await f.revokeSelf(p.account)}catch(e){let t=e instanceof Error?e.message:String(e);throw Error(`The Solve API revoked ${a}, but the on-chain revocation failed and the local key was kept: ${t}. Run the command again to retry`)}y=(await f.read([a])).get(_)??w}let C=p&&m&&y.revoked?c(p):void 0;if(l.json){e({...g,serviceId:S.serviceId.toString(),onChain:y,...x?{revocationTransaction:x}:{},localKeyRetired:!!C});return}t(g.alreadyRevoked?`${a} was already revoked in the Solve API`:`Revoked ${a}; the Solve API refuses its signatures`),x&&t(`Revoked on Tempo in ${x}; service ${S.serviceId} refuses its jobs`),C&&i("The local device key was moved aside because its address may still hold stake or rewards. Run `tangle solve account --create` for a new device"),!m&&y.permitted&&r(`The device can still submit jobs to service ${S.serviceId}. Only its key, or the Solve blueprint owner, can revoke it on chain`)}catch(e){a(e,l.json)}}export{E as listSolveDevices,D as revokeSolveDevice};
@@ -1 +1 @@
1
- import{a as e,d as t}from"./output-BRdLZpee.mjs";import{AuthError as n,NetworkError as r,NotFoundError as i,PublicTemplatePublishError as a,QuotaError as o,StateError as s,TimeoutError as c,ValidationError as l}from"@tangle-network/sandbox";import u from"chalk";var d=class extends Error{constructor(e,t,n,r,i){super(t),this.code=e,this.cause=n,this.fix=r,this.alternatives=i,this.name=`ActionableCliError`}};const f=new Set([`AUTH_EXPIRED`,`CREDENTIAL_ADDRESS_MISMATCH`,`SANDBOX_CREDENTIAL_REFUSED`,`AUTH_WRONG_AUDIENCE`,`SEAT_NONE_DETECTED`,`SEAT_NOT_LOGGED_IN`,`SEAT_NOT_ENROLLED`,`HUB_NOT_CONNECTED`,`HUB_RECONNECT`,`HUB_APP_NOT_INSTALLED`,`HUB_APPROVAL_REQUIRED`]),p=new Set([`GRAPH_INVALID`,`STEP_REF`,`PROFILE_INVALID`,`UNKNOWN_HARNESS`,`HUB_TOOL_UNKNOWN`,`TRIGGER_INVALID`,`WORKFLOW_INPUT_FILE_INVALID`,`VALIDATION_ERROR`]),m=new Set([`UNKNOWN_COMMAND`,`GRAPH_PARAM_MISSING`,`GRAPH_PARAM_UNKNOWN`,`SEAT_SYNTAX`,`HUB_PROVIDER_UNKNOWN`,`USAGE_INVALID`]),h=new Set([`SUBSCRIPTION_REQUIRED`,`MODEL_NOT_FOUND`,`MODEL_PROVIDER_MISMATCH`,`MCP_BLOCKED`,`CLOUD_SEAT_UNSUPPORTED`,`SCHEDULE_AUTHORITY`]);function g(e){return typeof e==`object`&&e?e:{}}function _(e){return typeof e==`string`&&e.length>0?e:void 0}function v(e){let t=_(e);return t&&/^[a-z0-9][a-z0-9_-]*$/i.test(t)?t:void 0}function y(e){let t,n=e;for(let e=0;n instanceof Error&&e<5;e++,n=n.cause){let e=n.message||(n instanceof AggregateError?n.errors.map(e=>e instanceof Error?e.message:String(e)).join(`; `):``),r=_(g(n).code);(e||r)&&(t=r?`${r}${e?`: ${e}`:``}`:e)}return t}function b(e){return e.code===`credential-refused`&&e.owner===`caller`&&e.providerCode===`subscription_required`?g(e.remediation):{}}function x(e){let t=g(e),u=Array.isArray(t.runtimeFailures)?t.runtimeFailures.map(g):[],p=u.find(e=>_(b(g(e.failure)).fix))??u[0],m=g(p?.failure??t.runtimeFailure),h=b(m),x=g(t.details),S=v(t.provider??x.provider??x.providerId),C=g(e instanceof d?{alternatives:e.alternatives}:t.fix??x.fix),w=_(t.code)??`CLI_ERROR`,T=_(t.message)??String(e),E=_(m.cause)??_(t.cause)??_(x.reason)??T,D=`tangle --help`,O=typeof x.providerRetryable==`boolean`?x.providerRetryable:typeof t.retryable==`boolean`?t.retryable:null;if(e instanceof n||w===`HUB_UNAUTHENTICATED`||t.status===401)w=`AUTH_EXPIRED`,T=`Authentication failed`,D=`tangle auth login`;else if(t.status===403&&T.startsWith(`Sandbox runtime creden`))w=`SANDBOX_CREDENTIAL_REFUSED`,T=`This sandbox's own TANGLE_API_KEY may call Hub endpoints only`,D=`export TANGLE_API_KEY=<owner or workspace sk-tan- key> (or pass --api-key), or run outside the sandbox`;else if([`HUB_CONNECTION_MISSING`,`HUB_CONNECTION_REVOKED`,`HUB_CONNECTION_UNHEALTHY`,`HUB_RECONNECT_REQUIRED`,`CONNECTION_REQUIRED`].includes(w))w=[`HUB_CONNECTION_MISSING`,`CONNECTION_REQUIRED`].includes(w)?`HUB_NOT_CONNECTED`:`HUB_RECONNECT`,D=S?`tangle hub connect ${S}`:`tangle hub connections --json`;else if(w===`HUB_APPROVAL_REQUIRED`){let e=v(g(x.approval).id);D=e?`tangle hub approvals approve ${e}`:`tangle hub approvals list --json`}else w===`HUB_PROVIDER_REJECTED`?(D=`tangle hub status --json`,x.providerRetryable===!1&&(E+=`. Change the request before retrying`)):w===`provider_quota_exhausted`||w===`SEAT_LIMIT`?(w=`SEAT_LIMIT`,D=`tangle auth status`,O=!0):e instanceof o?D=`tangle usage --json`:e instanceof r?(w=`NETWORK_UNAVAILABLE`,T=`Network error: ${T}`,E=y(e.cause)??`No response arrived`,D=`tangle auth status --json`):e instanceof c?(w=`TIMEOUT`,D=`tangle sandbox list --json`):e instanceof l?(w=`VALIDATION_ERROR`,T=`Invalid input`):e instanceof i||e instanceof s?D=`tangle sandbox list --json`:w===`commander.unknownCommand`?(w=`UNKNOWN_COMMAND`,D=T.includes(`'graph'`)?`npm install -g @tangle-network/sandbox-cli@latest`:`tangle --help`):w.startsWith(`commander.`)?w=`USAGE_INVALID`:(w===`ENOENT`||w===`EACCES`)&&(w=`INPUT_UNAVAILABLE`);e instanceof d&&(D=e.fix,O=!1),_(h.fix)&&(w=h.cause===`not_authenticated`?`SEAT_NOT_LOGGED_IN`:`SUBSCRIPTION_REQUIRED`),e instanceof a&&D===`tangle --help`&&(D=`tangle template publish --help`),D=_(h.fix)??_(C.command)??(w===`HUB_NOT_CONNECTED`?void 0:_(t.fixCommand))??D,f.has(w)&&D===`tangle --help`&&(D=`tangle auth login`);let k=g(t.subject??x.subject??{node:p?.node??t.node,seat:t.seat??h.harness}),A=e instanceof r||e instanceof Error&&`batchCustody`in e?t.batchCustody:void 0;A&&(E=`Batch acceptance: ${A.acceptance}; retirement receipt ${A.cleanup?.mode===`release`&&A.cleanup.isComplete?`proved`:`unproved`}.`,O=!1,D=`tangle batch run --help`);let j=_(t.resumeAt??x.resumeAt??x.resetAt);return{code:w,...A?{batchCustody:A}:{},catalogCode:_(t.catalogCode),message:_(t.nextStep)&&_(t.message),nextStep:_(t.nextStep),subject:{..._(k.node)?{node:String(k.node)}:{},..._(k.seat)?{seat:String(k.seat)}:{}},what:T,cause:E,fix:{command:D,...Array.isArray(C.alternatives)&&C.alternatives.every(e=>typeof e==`string`)?{alternatives:C.alternatives}:{},...C.edit===void 0?{}:{edit:C.edit},..._(C.url)?{url:String(C.url)}:{}},retryable:O,...j&&Number.isFinite(Date.parse(j))?{resumeAt:j}:{},..._(t.runId)?{runId:String(t.runId)}:{},..._(t.requestId)?{requestId:String(t.requestId)}:{},...typeof t.status==`number`?{status:t.status}:{},..._(m.code)&&_(m.owner)?{runtimeFailure:{code:String(m.code),owner:String(m.owner),cause:typeof m.cause==`string`?m.cause:E,..._(m.providerCode)?{providerCode:String(m.providerCode)}:{},...typeof m.providerStatus==`number`?{providerStatus:m.providerStatus}:{},...typeof m.retryAfterMs==`number`?{retryAfterMs:m.retryAfterMs}:{},...Object.keys(h).length?{remediation:h}:{}}}:{},...e instanceof a&&e.job?{job:e.job}:{},...e instanceof d&&Array.isArray(t.failures)?{failures:t.failures.map(e=>{let{node:t,code:n,requirement:r,fix:i}=g(e);return{node:String(t),..._(n)?{code:String(n)}:{},requirement:String(r),fix:String(i)}})}:{}}}function S(e){let t=[e.subject.node&&`node ${e.subject.node}`,e.subject.seat].filter(Boolean).join(` · `);return`✗ ${`${t?`${t}: `:``}${e.what}${e.status?` (HTTP ${e.status})`:``}`}${e.cause===e.what?``:` — ${e.cause}`}${e.nextStep?`\n → next: ${e.nextStep}`:``}\n → run: ${e.fix.command}`+(e.runtimeFailure?`\n runtime: ${e.runtimeFailure.code} · ${e.runtimeFailure.owner}${e.runtimeFailure.providerCode?` · ${e.runtimeFailure.providerCode}`:``}${e.runtimeFailure.providerStatus===void 0?``:` · HTTP ${e.runtimeFailure.providerStatus}`}${e.runtimeFailure.retryAfterMs===void 0?``:` · retry-after ${e.runtimeFailure.retryAfterMs} ms`}`:``)+(e.fix.alternatives?.map(e=>`\n or: ${e}`).join(``)??``)+(e.resumeAt?`\n resumes ${e.resumeAt}${e.subject.seat?` on ${e.subject.seat}`:``}`:``)}function C(e){return S(x(e))}function w(n,r=!1){t();let i=x(n);r?e({ok:!1,error:i}):console.error(u.red(S(i)));let a=1;f.has(i.code)?a=77:p.has(i.code)?a=65:m.has(i.code)?a=64:h.has(i.code)?a=78:[`SEAT_LIMIT`,`RATE_LIMITED`].includes(i.code)?a=75:[`HARNESS_NOT_INSTALLED`,`MCP_UNREACHABLE`,`NETWORK_UNAVAILABLE`].includes(i.code)?a=69:i.code===`RUN_STOPPED`&&(a=130),process.exit(a)}export{C as n,w as r,d as t};
1
+ import{a as e,d as t}from"./output-BRdLZpee.mjs";import{AuthError as n,NetworkError as r,NotFoundError as i,PublicTemplatePublishError as a,QuotaError as o,StateError as s,TimeoutError as c,ValidationError as l}from"@tangle-network/sandbox";import u from"chalk";var d=class extends Error{constructor(e,t,n,r,i){super(t),this.code=e,this.cause=n,this.fix=r,this.alternatives=i,this.name=`ActionableCliError`}};const f=new Set([`AUTH_EXPIRED`,`CREDENTIAL_ADDRESS_MISMATCH`,`SANDBOX_CREDENTIAL_REFUSED`,`AUTH_WRONG_AUDIENCE`,`SEAT_NONE_DETECTED`,`SEAT_NOT_LOGGED_IN`,`SEAT_NOT_ENROLLED`,`HUB_NOT_CONNECTED`,`HUB_RECONNECT`,`HUB_APP_NOT_INSTALLED`,`HUB_APPROVAL_REQUIRED`]),p=new Set([`GRAPH_INVALID`,`STEP_REF`,`PROFILE_INVALID`,`UNKNOWN_HARNESS`,`HUB_TOOL_UNKNOWN`,`TRIGGER_INVALID`,`WORKFLOW_INPUT_FILE_INVALID`,`VALIDATION_ERROR`]),m=new Set([`UNKNOWN_COMMAND`,`GRAPH_PARAM_MISSING`,`GRAPH_PARAM_UNKNOWN`,`SEAT_SYNTAX`,`HUB_PROVIDER_UNKNOWN`,`USAGE_INVALID`]),h=new Set([`SUBSCRIPTION_REQUIRED`,`MODEL_NOT_FOUND`,`MODEL_PROVIDER_MISMATCH`,`MCP_BLOCKED`,`CLOUD_SEAT_UNSUPPORTED`,`SCHEDULE_AUTHORITY`]);function g(e){return typeof e==`object`&&e?e:{}}function _(e){return typeof e==`string`&&e.length>0?e:void 0}function v(e){let t=_(e);return t&&/^[a-z0-9][a-z0-9_-]*$/i.test(t)?t:void 0}function y(e){let t,n=e;for(let e=0;n instanceof Error&&e<5;e++,n=n.cause){let e=n.message||(n instanceof AggregateError?n.errors.map(e=>e instanceof Error?e.message:String(e)).join(`; `):``),r=_(g(n).code);(e||r)&&(t=r?`${r}${e?`: ${e}`:``}`:e)}return t}function b(e){return e.code===`credential-refused`&&e.owner===`caller`&&e.providerCode===`subscription_required`?g(e.remediation):{}}function x(e){let t=g(e),u=Array.isArray(t.runtimeFailures)?t.runtimeFailures.map(g):[],p=u.find(e=>_(b(g(e.failure)).fix))??u[0],m=g(p?.failure??t.runtimeFailure),h=b(m),x=g(t.details),S=v(t.provider??x.provider??x.providerId),C=g(e instanceof d?{alternatives:e.alternatives}:t.fix??x.fix),w=_(t.code)??`CLI_ERROR`,T=_(t.message)??String(e),E=_(m.cause)??_(t.cause)??_(x.reason)??T,D=`tangle --help`,O=typeof x.providerRetryable==`boolean`?x.providerRetryable:typeof t.retryable==`boolean`?t.retryable:null;if(e instanceof n||w===`HUB_UNAUTHENTICATED`||t.status===401)w=`AUTH_EXPIRED`,T=`Authentication failed`,D=`tangle auth login`;else if(t.status===403&&T.startsWith(`Sandbox runtime creden`))w=`SANDBOX_CREDENTIAL_REFUSED`,T=`This sandbox's own TANGLE_API_KEY may call Hub endpoints only`,D=`export TANGLE_API_KEY=<owner or workspace sk-tan- key> (or pass --api-key), or run outside the sandbox`;else if([`HUB_CONNECTION_MISSING`,`HUB_CONNECTION_REVOKED`,`HUB_CONNECTION_UNHEALTHY`,`HUB_RECONNECT_REQUIRED`,`CONNECTION_REQUIRED`].includes(w))w=[`HUB_CONNECTION_MISSING`,`CONNECTION_REQUIRED`].includes(w)?`HUB_NOT_CONNECTED`:`HUB_RECONNECT`,D=S?`tangle hub connect ${S}`:`tangle hub connections --json`;else if(w===`HUB_APPROVAL_REQUIRED`){let e=v(g(x.approval).id);D=e?`tangle hub approvals approve ${e}`:`tangle hub approvals list --json`}else w===`HUB_PROVIDER_REJECTED`?(D=`tangle hub status --json`,x.providerRetryable===!1&&(E+=`. Change the request before retrying`)):w===`provider_quota_exhausted`||w===`SEAT_LIMIT`?(w=`SEAT_LIMIT`,D=`tangle auth status`,O=!0):e instanceof o?D=`tangle usage --json`:e instanceof r?(w=`NETWORK_UNAVAILABLE`,T=`Network error: ${T}`,E=y(e.cause)??`No response arrived`,D=`tangle auth status --json`):e instanceof c?(w=`TIMEOUT`,D=`tangle sandbox list --json`):e instanceof l?(w=`VALIDATION_ERROR`,T=`Invalid input`):e instanceof i||e instanceof s?D=`tangle sandbox list --json`:w===`commander.unknownCommand`?(w=`UNKNOWN_COMMAND`,D=T.includes(`'graph'`)?`npm install -g @tangle-network/sandbox-cli@latest`:`tangle --help`):w.startsWith(`commander.`)?w=`USAGE_INVALID`:(w===`ENOENT`||w===`EACCES`)&&(w=`INPUT_UNAVAILABLE`);e instanceof d&&(D=e.fix,O=!1),_(h.fix)&&(w=h.cause===`not_authenticated`?`SEAT_NOT_LOGGED_IN`:`SUBSCRIPTION_REQUIRED`),e instanceof a&&D===`tangle --help`&&(D=`tangle template publish --help`),D=_(h.fix)??_(C.command)??(w===`HUB_NOT_CONNECTED`?void 0:_(t.fixCommand))??D,f.has(w)&&D===`tangle --help`&&(D=`tangle auth login`);let k=g(t.subject??x.subject??{node:p?.node??t.node,seat:t.seat??h.harness}),A=e instanceof r||e instanceof Error&&`batchCustody`in e?t.batchCustody:void 0;A?.acceptance===`refused`?E=`The service refused this batch before it started.`:A&&(E=`Batch acceptance: ${A.acceptance}; retirement receipt ${A.cleanup?.mode===`release`&&A.cleanup.isComplete?`proved`:`unproved`}.`,O=!1,D=`tangle batch run --help`);let j=_(t.resumeAt??x.resumeAt??x.resetAt);return{code:w,...A?{batchCustody:A}:{},catalogCode:_(t.catalogCode),message:_(t.nextStep)&&_(t.message),nextStep:_(t.nextStep),subject:{..._(k.node)?{node:String(k.node)}:{},..._(k.seat)?{seat:String(k.seat)}:{}},what:T,cause:E,fix:{command:D,...Array.isArray(C.alternatives)&&C.alternatives.every(e=>typeof e==`string`)?{alternatives:C.alternatives}:{},...C.edit===void 0?{}:{edit:C.edit},..._(C.url)?{url:String(C.url)}:{}},retryable:O,...j&&Number.isFinite(Date.parse(j))?{resumeAt:j}:{},..._(t.runId)?{runId:String(t.runId)}:{},..._(t.requestId)?{requestId:String(t.requestId)}:{},...typeof t.status==`number`?{status:t.status}:{},..._(m.code)&&_(m.owner)?{runtimeFailure:{code:String(m.code),owner:String(m.owner),cause:typeof m.cause==`string`?m.cause:E,..._(m.providerCode)?{providerCode:String(m.providerCode)}:{},...typeof m.providerStatus==`number`?{providerStatus:m.providerStatus}:{},...typeof m.retryAfterMs==`number`?{retryAfterMs:m.retryAfterMs}:{},...Object.keys(h).length?{remediation:h}:{}}}:{},...e instanceof a&&e.job?{job:e.job}:{},...e instanceof d&&Array.isArray(t.failures)?{failures:t.failures.map(e=>{let{node:t,code:n,requirement:r,fix:i}=g(e);return{node:String(t),..._(n)?{code:String(n)}:{},requirement:String(r),fix:String(i)}})}:{}}}function S(e){let t=[e.subject.node&&`node ${e.subject.node}`,e.subject.seat].filter(Boolean).join(` · `);return`✗ ${`${t?`${t}: `:``}${e.what}${e.status?` (HTTP ${e.status})`:``}`}${e.cause===e.what?``:` — ${e.cause}`}${e.nextStep?`\n → next: ${e.nextStep}`:``}\n → run: ${e.fix.command}`+(e.runtimeFailure?`\n runtime: ${e.runtimeFailure.code} · ${e.runtimeFailure.owner}${e.runtimeFailure.providerCode?` · ${e.runtimeFailure.providerCode}`:``}${e.runtimeFailure.providerStatus===void 0?``:` · HTTP ${e.runtimeFailure.providerStatus}`}${e.runtimeFailure.retryAfterMs===void 0?``:` · retry-after ${e.runtimeFailure.retryAfterMs} ms`}`:``)+(e.fix.alternatives?.map(e=>`\n or: ${e}`).join(``)??``)+(e.resumeAt?`\n resumes ${e.resumeAt}${e.subject.seat?` on ${e.subject.seat}`:``}`:``)}function C(e){return S(x(e))}function w(n,r=!1){t();let i=x(n);r?e({ok:!1,error:i}):console.error(u.red(S(i)));let a=1;f.has(i.code)?a=77:p.has(i.code)?a=65:m.has(i.code)?a=64:h.has(i.code)?a=78:[`SEAT_LIMIT`,`RATE_LIMITED`].includes(i.code)?a=75:[`HARNESS_NOT_INSTALLED`,`MCP_UNREACHABLE`,`NETWORK_UNAVAILABLE`].includes(i.code)?a=69:i.code===`RUN_STOPPED`&&(a=130),process.exit(a)}export{C as n,w as r,d as t};