@minimax-ai/code 0.6.1 → 0.6.3
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/CHANGELOG.md +19 -0
- package/CHANGELOG.zh-CN.md +15 -0
- package/README.md +21 -0
- package/README.zh-CN.md +15 -0
- package/chunks/{auth-command-7CDRKDVD.js → auth-command-CO6IUQQ5.js} +1 -1
- package/chunks/{chunk-UNHOACX2.js → chunk-7CKVJIAL.js} +1 -1
- package/chunks/{chunk-UI7OHI22.js → chunk-EL5XOH23.js} +510 -510
- package/chunks/chunk-G7Q4HUMC.js +23 -0
- package/chunks/{chunk-JVKXU2EF.js → chunk-K7X2ELVZ.js} +2 -2
- package/chunks/{chunk-H2MLHV4N.js → chunk-T4F6MBL2.js} +1 -1
- package/chunks/{chunk-FD7DWNRT.js → chunk-T6KXDH7B.js} +1 -1
- package/chunks/{chunk-PUFWXRWS.js → chunk-U7ACBEGU.js} +5 -5
- package/chunks/{chunk-K3IQFB2P.js → chunk-VN3EYAMT.js} +1 -1
- package/chunks/chunk-WROGTDVD.js +3 -0
- package/chunks/{chunk-5DNOXYNO.js → chunk-YC47AWPX.js} +1 -1
- package/chunks/{data-dir-3FQYZA5W.js → data-dir-4GSZVAMG.js} +1 -1
- package/chunks/{launcher-Z2CKZB4R.js → launcher-ST7GNBTY.js} +152 -152
- package/chunks/{lifecycle-SQHUVIJ7.js → lifecycle-MEDWAANQ.js} +1 -1
- package/chunks/main-7X6VQMDB.js +9 -0
- package/chunks/{plugin-command-YRAYZBNS.js → plugin-command-EZNOWONW.js} +1 -1
- package/chunks/{provider-command-GJYV7UUM.js → provider-command-OJLRQ76A.js} +1 -1
- package/chunks/{run-acp-command-MUUZAUTS.js → run-acp-command-Z5CVNHZZ.js} +2 -2
- package/chunks/run-exec-command-MT4Y6VPF.js +17 -0
- package/cli.js +2 -2
- package/package.json +1 -1
- package/chunks/chunk-Q45WUEPQ.js +0 -3
- package/chunks/chunk-RO4BB34M.js +0 -2
- package/chunks/main-2G4XWJUW.js +0 -30
- package/chunks/run-exec-command-NWUGZRC4.js +0 -17
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createRequire as __mavis_cR } from "module"; import { basename as __mavis_basename, dirname as __mavis_dirname, join as __mavis_join } from "path"; import { fileURLToPath as __mavis_fileURLToPath, pathToFileURL as __mavis_pathToFileURL } from "url"; const __mavis_tuiCurrentModuleDir = __mavis_dirname(__mavis_fileURLToPath(import.meta.url)); const __mavis_tuiPackageRoot = __mavis_basename(__mavis_tuiCurrentModuleDir) === "chunks" ? __mavis_dirname(__mavis_tuiCurrentModuleDir) : __mavis_tuiCurrentModuleDir; const __mavis_tuiPackageEntryUrl = __mavis_pathToFileURL(__mavis_join(__mavis_tuiPackageRoot, "cli.js")).href; const require = __mavis_cR(__mavis_tuiPackageEntryUrl); const __dirname = __mavis_tuiPackageRoot;
|
|
2
|
-
import{a as m}from"./chunk-
|
|
2
|
+
import{a as m}from"./chunk-WROGTDVD.js";import{b as X}from"./chunk-EL5XOH23.js";import{N as $,W as A}from"./chunk-Z4VKGZFA.js";import{e as I}from"./chunk-D76SO2ME.js";import{execFile as F}from"node:child_process";import{platform as O,release as W}from"node:os";import{posix as M}from"node:path";import{promisify as V}from"node:util";var j=V(F);async function he(e,n){if(!/^(?:[a-z]:[\\/]|\\\\)/iu.test(e)||O()!=="linux"||!(process.env.WSL_DISTRO_NAME||process.env.WSL_INTEROP||process.env.WSLENV||/microsoft/iu.test(W())))return e;try{let{stdout:t}=await j("wslpath",["-a","-u",e],{encoding:"utf8",timeout:1e3,maxBuffer:65536,...n?{signal:n}:{}}),r=t.replace(/\r?\n$/u,"");if(!M.isAbsolute(r)||/[\r\n\0]/u.test(r))throw new Error("wslpath did not return an absolute Linux path.");return r}catch(t){throw new Error("Could not convert the Windows path with wslpath. Use an accessible Linux path instead.",{cause:t})}}var _=I(X(),1);var q=1e6,z=1e3,B=32,x=/^(?![A-Za-z]:[\\/])(?![\\/])(?!.*(?:^|[\\/])\.\.(?:[\\/]|$))[^\0]+$/u,L=/^sha256:[a-f0-9]{64}$/u,G=/^git-blob:[a-f0-9]{40,64}$/u;function ve(e){if(!E(e))return;let n=e.reviewOutcome;return n==="pass"||n==="needs_changes"||n==="failed"?n:void 0}function be(e){let n=e.trim();if(!(!n.startsWith("<annotation-result")||!n.endsWith("</annotation-result>")))try{let t=K(n);if(R(t,"annotation-result"),g(t,["version","source","review-run-id","trigger","mode","verdict"]),c(t,"version")!=="2"||c(t,"source")!=="code-review"||c(t,"verdict")!=="needs-changes"||!c(t,"review-run-id"))return;let r=c(t,"trigger"),i=c(t,"mode");if(r!=="slash"&&r!=="natural_language"||i!=="inline"&&i!=="subagent")return;h(t),T(t,["summary","annotations"]);let s=b(f(t,"summary")),o=f(t,"annotations");if(g(o,[]),h(o),o.children.some(l=>l.name!=="annotation"))return;let u=o.children.map(U);return!s||u.length===0?void 0:{schemaVersion:1,type:"review.result",scope:"local_changes",verdict:"needs_changes",summary:s,findings:u,mode:i}}catch{return}}function xe(e){let n=e.trim();if(n)return{schemaVersion:1,type:"review.result",scope:"local_changes",verdict:"pass",summary:n,findings:[]}}function Re(e){return!E(e)||e.schemaVersion!==1||e.type!=="review.result"||e.scope!=="local_changes"||e.verdict!=="pass"&&e.verdict!=="needs_changes"||typeof e.summary!="string"||!e.summary.trim()||!Array.isArray(e.findings)||!e.findings.every(Y)||e.mode!==void 0&&e.mode!=="inline"&&e.mode!=="subagent"?!1:e.verdict==="pass"?e.findings.length===0:e.findings.length>0}function Te(e){return e.verdict==="pass"?m(e.summary):[m(e.summary),...e.findings.flatMap(n=>["",`[${n.priority}] ${m(n.title)}`,m(H(n)),m(n.content)])].join(`
|
|
3
3
|
`)}function H(e){if(e.targetType==="file")return e.path;let n=e.startLine===e.endLine?String(e.startLine):`${String(e.startLine)}-${String(e.endLine)}`;return`${e.path}:${n}${e.side?` (${e.side})`:""}`}function U(e){if(R(e,"annotation"),g(e,["id","kind","priority"]),c(e,"kind")!=="code-review")throw new Error("annotation kind must be code-review");let n=c(e,"id"),t=c(e,"priority");if(!n||!S(t))throw new Error("annotation identity is invalid");h(e),T(e,["target","title","content"]);let r=Z(f(e,"target")),i=b(f(e,"title")),s=b(f(e,"content"));if(!i||!s)throw new Error("annotation text is empty");return{id:n,priority:t,...r,title:i,content:s}}function Z(e){R(e,"target");let n=c(e,"uri");if(!x.test(n)||c(e,"type")!=="file")throw new Error("annotation target is invalid");if(h(e),e.attributes.state==="deleted"){if(g(e,["type","uri","state","blob-revision"]),e.children.length>0||!G.test(c(e,"blob-revision")))throw new Error("deleted annotation target is invalid");return{targetType:"file",path:n}}g(e,["type","uri"]),T(e,["selector","related-change"]);let t=f(e,"selector");if(g(t,["type","side","start-line","end-line","anchor-revision","context-before","context-after"]),h(t),t.children.length>0||c(t,"type")!=="line-range")throw new Error("annotation selector is invalid");let r=c(t,"side"),i=y(c(t,"start-line")),s=y(c(t,"end-line")),o=t.attributes["anchor-revision"];if(r!=="old"&&r!=="new"||s<i||o!==void 0&&!L.test(o)||!k(t.attributes["context-before"])||!k(t.attributes["context-after"]))throw new Error("annotation selector is invalid");let u=Q(e,"related-change");return u&&J(u),{targetType:"line-range",path:n,side:r,startLine:i,endLine:s}}function J(e){g(e,["path","side","start-line","end-line","revision"]),h(e);let n=c(e,"path"),t=c(e,"side"),r=y(c(e,"start-line")),i=y(c(e,"end-line"));if(e.children.length>0||!x.test(n)||t!=="old"&&t!=="new"||i<r||!L.test(c(e,"revision")))throw new Error("related change is invalid")}function K(e){if(e.length>q)throw new Error("Review result is too large");let n,t=!1,r=0,i="",s=[],o=new _.SaxesParser({xmlns:!1});if(o.on("opentag",u=>{r+=1,(r>z||s.length>=B)&&(t=!0);let l={name:u.name,attributes:Object.fromEntries(Object.entries(u.attributes).map(([a,p])=>[a,String(p)])),children:[],text:""},d=s.at(-1);d?d.children.push(l):n?t=!0:n=l,s.push(l)}),o.on("text",u=>{let l=s.at(-1);l?l.text+=u:i+=u}),o.on("closetag",()=>{s.pop()}),o.on("cdata",()=>{t=!0}),o.on("comment",()=>{t=!0}),o.on("doctype",()=>{t=!0}),o.on("processinginstruction",()=>{t=!0}),o.on("error",()=>{t=!0}),o.write(e).close(),t||!n||s.length>0||i.trim())throw new Error("Review result XML is invalid");return n}function b(e){if(g(e,[]),e.children.length>0)throw new Error(`${e.name} must contain text only`);return e.text.trim()}function R(e,n){if(e.name!==n)throw new Error(`Expected ${n}`)}function g(e,n){let t=[...n].sort().join("\0");if(Object.keys(e.attributes).sort().join("\0")!==t)throw new Error(`${e.name} attributes are invalid`)}function h(e){if(e.text.trim())throw new Error(`${e.name} contains unexpected text`)}function T(e,n){let t=new Set(n);if(e.children.some(r=>!t.has(r.name)))throw new Error(`${e.name} contains an unexpected element`)}function f(e,n){let t=e.children.filter(i=>i.name===n),r=t[0];if(t.length!==1||!r)throw new Error(`${e.name} must contain one ${n}`);return r}function Q(e,n){let t=e.children.filter(r=>r.name===n);if(t.length>1)throw new Error(`${e.name} contains duplicate ${n}`);return t[0]}function c(e,n){let t=e.attributes[n];if(t===void 0)throw new Error(`${e.name}.${n} is required`);return t}function y(e){if(!/^[1-9]\d*$/u.test(e))throw new Error("Expected a positive integer");let n=Number(e);if(!Number.isSafeInteger(n))throw new Error("Integer is out of range");return n}function k(e){return e===void 0||/^[0-3]$/u.test(e)}function S(e){return e==="P0"||e==="P1"||e==="P2"||e==="P3"}function Y(e){return!E(e)||typeof e.id!="string"||!e.id||typeof e.priority!="string"||!S(e.priority)||typeof e.path!="string"||!x.test(e.path)||typeof e.title!="string"||!e.title.trim()||typeof e.content!="string"||!e.content.trim()?!1:e.targetType==="file"?e.side===void 0&&e.startLine===void 0&&e.endLine===void 0:e.targetType==="line-range"&&(e.side==="old"||e.side==="new")&&typeof e.startLine=="number"&&Number.isSafeInteger(e.startLine)&&e.startLine>0&&typeof e.endLine=="number"&&Number.isSafeInteger(e.endLine)&&e.endLine>=e.startLine}function E(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}var N=/<(?:deliver[-_]assets|media|publish[_-]artifact|preview_card|genui-|mavis-widget|mavis-thinking|mavis-progress|think|final|permission-(?:ask|response)|questionnaire-(?:ask|response))\b|^\s*preview_cards?:\s*$/imu;function ke(e){let n=ee(e);return n.assets.length===0?n.text:[n.text,ue(n.assets)].filter(Boolean).join(`
|
|
4
4
|
|
|
5
5
|
`)}function ee(e){let n=m(e);if(!n||!N.test(n))return{text:n,assets:[]};let t=$(n),r=[],i=[],s="\uE000mcode-protected";for(;n.includes(s);)s+="-";let o=!1,u=t.map(a=>{if(a.type==="protected"){let p=r.push(a.content)-1;return`${s}-${p}\uE001`}return N.test(a.content)?(o=!0,te(a.content,i)):a.content}).join("");if(!o)return{text:n,assets:[]};let l=de(u);r.forEach((a,p)=>{l=l.replace(`${s}-${p}\uE001`,a)});let d=[...new Map(i.map(a=>[a.path.trim(),a])).values()];return{text:l,assets:d.map(a=>({path:a.path.trim(),...a.name?.trim()?{name:a.name.trim()}:{}}))}}function te(e,n){let t=e;return t=w(t,"mavis-thinking"),t=w(t,"think"),t=ne(t,"mavis-progress"),t=w(t,"permission-ask"),t=w(t,"permission-response"),t=w(t,"questionnaire-ask"),t=w(t,"questionnaire-response"),t=t.replace(/<\/?final\b[^>]*>/giu,""),t=re(t),t=ie(t),t=se(t),t=ae(t),t=ce(t,n),t=t.replace(/<\/?(?:deliver-assets|deliver_assets)\b[^>]*>/giu,"file attachment").replace(/<media\b[^>]*\/?>/giu,"file attachment").replace(/<media\b[^>]*$/iu,""),t}function w(e,n){let t=new RegExp(`<${n}\\b[^>]*>((?:(?!<${n}\\b)[\\s\\S])*?)<\\/${n}\\s*>`,"giu"),r=e,i=e.replace(t,"");for(;i!==r;)r=i,i=i.replace(t,"");return i}function ne(e,n){let t=new RegExp(`<${n}\\b[^>]*>((?:(?!<${n}\\b)[\\s\\S])*?)<\\/${n}\\s*>`,"giu"),r=e,i=e.replace(t,(s,o)=>o.trim());for(;i!==r;)r=i,i=i.replace(t,(s,o)=>o.trim());return i}function re(e){let n=/<mavis-widget\b([^>]*)>([\s\S]*?)<\/mavis-widget\s*>/giu,t=e.replace(n,(r,i,s)=>{let o=/<mavis-fallback\b[^>]*>([\s\S]*?)<\/mavis-fallback\s*>/iu.exec(s)?.[1];return o?.trim()?o.trim():P(v(i))});return t=t.replace(/<mavis-widget\b([^>]*)>[\s\S]*$/iu,(r,i)=>P(v(i))),t.replace(/<mavis-widget\b[^>]*$/iu,"Interactive content is loading\u2026")}function P(e){let n=e.kind?.trim(),t=e.title?.trim();return n&&t?`Interactive ${n}: ${t} (open in Desktop).`:t?`Interactive content: ${t} (open in Desktop).`:"Interactive content available in Desktop."}function ie(e){let n=/<genui-([\w-]+)\b([^>]*)>[\s\S]*?<\/genui-\1\s*>/giu,t=/<genui-([\w-]+)\b([^>]*?)\/\s*>/giu,r=e.replace(n,(i,s,o)=>C(s,v(o)));return r=r.replace(t,(i,s,o)=>C(s,v(o))),r.replace(/<genui-[\w-]*\b[^>]*$/iu,"Interactive content is loading\u2026")}function C(e,n){if(e.toLocaleLowerCase()==="mcp-auth"){let t=n.label?.trim()||n["server-id"]?.trim();return t?`MCP authorization required: ${t} (open in Desktop).`:"MCP authorization required (open in Desktop)."}if(e.toLocaleLowerCase()==="agent-team-recommendation"){let t=n.status?.trim().toLocaleLowerCase();return t==="accepted"?"Team recommendation accepted.":t==="skipped"?"Team recommendation skipped.":"Team recommendation available in Desktop."}return"Interactive content available in Desktop."}function v(e){let n={},t=/([\w-]+)\s*=\s*(["'])(.*?)\2/gu,r;for(;(r=t.exec(e))!==null;){let i=r[1],s=r[3];i&&s!==void 0&&(n[i]=oe(s))}return n}function se(e){let n=/<(deliver-assets|deliver_assets)\b[^>]*>\s*<\/\1\s*>/giu,t=e,r=e.replace(n,"");for(;r!==t;)t=r,r=r.replace(n,"");return r}function oe(e){return e.replace(/"/gu,'"').replace(/'|'/gu,"'").replace(/</gu,"<").replace(/>/gu,">").replace(/&/gu,"&")}function ae(e){let n=/<\/?(deliver-assets|deliver_assets)\b[^>]*>/giu,t=[],r;for(;(r=n.exec(e))!==null;)t.push({start:r.index,end:n.lastIndex,name:r[1]?.toLocaleLowerCase()??"",closing:r[0].startsWith("</")});if(t.length===0)return e;let i=[],s=new Set;if(t.forEach((l,d)=>{if(!l.closing){i.push(d);return}for(let a=i.length-1;a>=0;a-=1){let p=i[a];if(!(p===void 0||t[p]?.name!==l.name)){i.splice(a,1),s.add(p),s.add(d);return}}}),s.size===t.length)return e;let o=0,u="";return t.forEach((l,d)=>{u+=e.slice(o,l.start),u+=s.has(d)?e.slice(l.start,l.end):"file attachment",o=l.end}),u+e.slice(o)}function ce(e,n){let t=e;for(let r=0;r<3;r+=1){let i=A(t),s=le(i);if(t=s.text,s.assets.length===0)break;n.push(...s.assets)}return t}function le(e){let n=[],t=[];for(let r of e)r.type==="deliver-assets"||r.type==="image-gallery"?t.push(...r.items):r.content.trim()&&n.push(r.content.trim());return{text:n.join(`
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { createRequire as __mavis_cR } from "module"; import { basename as __mavis_basename, dirname as __mavis_dirname, join as __mavis_join } from "path"; import { fileURLToPath as __mavis_fileURLToPath, pathToFileURL as __mavis_pathToFileURL } from "url"; const __mavis_tuiCurrentModuleDir = __mavis_dirname(__mavis_fileURLToPath(import.meta.url)); const __mavis_tuiPackageRoot = __mavis_basename(__mavis_tuiCurrentModuleDir) === "chunks" ? __mavis_dirname(__mavis_tuiCurrentModuleDir) : __mavis_tuiCurrentModuleDir; const __mavis_tuiPackageEntryUrl = __mavis_pathToFileURL(__mavis_join(__mavis_tuiPackageRoot, "cli.js")).href; const require = __mavis_cR(__mavis_tuiPackageEntryUrl); const __dirname = __mavis_tuiPackageRoot;
|
|
2
|
+
import{q as O}from"./chunk-K7X2ELVZ.js";import{a as p}from"./chunk-PRXIML4F.js";var b=["totalTokens","inputTokens","outputTokens","reasoningTokens","cacheReadTokens","cacheWriteTokens"];function v(e,t){return e.role==="assistant"&&(e.turnId===void 0||e.turnId===t)&&e.kind?.startsWith("compaction")===!0}function L(e,t){if(e.role!=="assistant"||e.turnId!==void 0&&e.turnId!==t||v(e,t))return;let i=Object.fromEntries(b.flatMap(r=>T(e.usage?.[r])?[[r,e.usage?.[r]]]:[])),n=b.some(r=>e.usage?.[r]!==void 0&&!T(e.usage?.[r]));return{...e.id?.trim()?{messageId:e.id}:{},...Object.keys(i).length?{usage:i}:{},...n?{usageIncomplete:!0}:{}}}function N(e,t){let i=t.messageId?e.findIndex(r=>r.messageId===t.messageId):-1,n=e[i];if(!n){e.push(t);return}e[i]={...n,...t,...n.usage||t.usage?{usage:{...n.usage,...t.usage}}:{}}}function Q(e){let t=e.length===0||e.some(n=>!T(n.usage?.inputTokens)||!T(n.usage?.outputTokens)||n.usageIncomplete),i=Object.fromEntries(b.flatMap(n=>{let r=e.map(a=>a.usage?.[n]).filter(T);if(!r.length)return[];let o=r.reduce((a,c)=>a+c,0);return Number.isFinite(o)?[[n,o]]:(t=!0,[])}));return{...Object.keys(i).length?{usage:i}:{},usageIncomplete:t}}function T(e){return typeof e=="number"&&Number.isFinite(e)&&e>=0}function D(e,t){let i=e.type==="message"?e.message.turnId:e.turnId;return i&&i!==t?!1:(e.type==="message"?e.message.toolCalls:e.type==="delta"?e.toolCalls:void 0)?.some(r=>{if(r.error||r.status!==2&&r.status!=="2"&&r.status!=="finished"||!r.output||typeof r.output!="object"||Array.isArray(r.output))return!1;let o=r.output.details;return typeof o=="object"&&o!==null&&!Array.isArray(o)&&o.waiting_for_user===!0})??!1}async function F(e,t,i,n=O,r){let o=await e.getPendingQuestionnaire?.(n,t,r);return o?.requester?.sessionId===t&&o.requester.runId===i?o:void 0}var $=1e3,j=class{constructor(t,i={}){this.runtime=t;this.options=i;this.nowMs=i.nowMs??Date.now}activeRun;retiringRun;nowMs;activeTurnId(){return this.activeRun?.turnId}detachActiveRun(t){let i=this.activeRun;return!i||t!==void 0&&i.turnId!==t?!1:(this.activeRun=void 0,!0)}retiringTurnId(){return this.retiringRun?.turnId}retirement(){return this.retiringRun?.settlement}async*sendWithQueueRecovery(t,i,n,r){let o=V(t,i,r),a=!1;try{for await(let c of this.runtime.sendMessage(o,n))a=!0,yield c}catch(c){if(a||r!==void 0||!(c instanceof p)||c.code!=="local_session_queue_paused"||!t.onQueuePaused||n.aborted)throw c;let d=await t.onQueuePaused(i.sessionId,n);if(n.throwIfAborted(),d==="cancel")throw new p("cancelled","The draft was kept.",{code:"PAUSED_QUEUE_SEND_CANCELLED"});yield*this.runtime.sendMessage(o,n,{pausedQueueAction:d==="paused-queue-clear"?"clear":"keep"})}}async execute(t,i=()=>{},n,r){if(this.activeRun)throw new Error("A run is already active.");if(this.retiringRun)throw new Error("The previous run is still stopping.");let o=te(t.turnId);this.activeRun=o;let a=this.nowMs(),c,d,w=!1,u="succeeded",m=null,g="",l,E=0,y=[],P=!1,_=!1;try{if(d=await ne(t.session,o.controller.signal),!d)throw o.controller.signal.reason??new Error("Turn cancelled before Session setup.");o.sessionId=d.sessionId;let f;t.policy?.timeoutMs!==void 0&&(f=this.nowMs()+t.policy.timeoutMs,c=setTimeout(()=>{this.stopActive(o,"timeout").catch(()=>{})},t.policy.timeoutMs),c.unref?.());let M=this.sendWithQueueRecovery(t,d,o.controller.signal,f)[Symbol.asyncIterator]();try{for(;;){let k=await M.next();if(k.done)break;let s=k.value;_||=D(s,t.turnId),w||(w=!0,n?.());let C=J(s);if(C){u="awaiting-user-continuation",l=C,await G(i,s);break}if(H(s)){P||=v(s.message,t.turnId);let U=L(s.message,t.turnId);if(U&&N(y,U),t.policy?.maxSteps!==void 0&&E>=t.policy.maxSteps){u="limit_exceeded",await this.stopActive(o,"limit");break}if(E+=1,s.message.toolCalls?.length)this.reportAnswerSelection({kind:"answer_excluded",messageId:s.message.id,reason:"tool_calls"}),m=null,g="";else{let A=s.message.content?.trim()?s.message.content:g;m=A.trim()?A:null,this.reportAnswerSelection({kind:"answer_selected",messageId:s.message.id,answerSource:s.message.content?.trim()?"completed_message":"completed_message_draft",answerBytes:Buffer.byteLength(A),finishReason:s.message.finishReason}),g=""}}else K(s)&&(g+=s.content);let h=Z(s);h&&(u=h.status,l=h.error),await G(i,s)}}finally{await M.return?.(void 0)}g.trim()&&(this.reportAnswerSelection({kind:"answer_selected",answerSource:"trailing_draft",answerBytes:Buffer.byteLength(g),replacedAnswer:m!==null}),m=g),u==="succeeded"&&!o.controller.signal.aborted&&(_||await F(this.runtime,d.sessionId,t.turnId,d.agentName,o.controller.signal))&&(u="awaiting-user-continuation",m=null,l=W()),t.policy?.requireAnswer===!0&&u==="succeeded"&&m===null&&(u="failed",l={category:"runtime",code:"EMPTY_RESPONSE",message:"Runtime completed without a final assistant response.",retryable:!0}),u=B(o.stopReason,u)}catch(f){o.stopReason||o.controller.signal.aborted?u=B(o.stopReason,"cancelled"):(u="failed",l=ee(f))}finally{c&&clearTimeout(c),this.activeRun===o&&(this.activeRun=void 0)}let{usage:x}=Q(y),R={sessionId:d?.sessionId??"",turnId:t.turnId,status:u,answer:m,...t.model?{model:{...t.model}}:{},...x?{usage:x}:{},...y.length?{usageResponses:y}:{},...P?{usageIncomplete:!0}:{},...l?{error:l}:{},durationMs:Math.max(0,this.nowMs()-a)};if(r)try{await r(R)}catch{u="failed";let f={category:"internal",code:"AUTOMATION_RESULT_WRITE_FAILED",message:"Could not publish the TUI automation result.",retryable:!0};l=f,R={...R,status:u,error:f}}return o.resolveSettled(),{turnId:t.turnId,...d?{session:d}:{},status:u,outcome:R,...l?.message?{error:l.message}:{}}}async abort(){let t=this.activeRun;return t?(t.abortPromise??=this.stopAndSettle(t),t.abortPromise):!1}reportAnswerSelection(t){try{this.options.onAnswerSelection?.(t)}catch{}}async stopAndSettle(t){let i=await this.stopActive(t,"user_stop"),n=t.settled.then(()=>i),r=await ie(n,this.options.cancellationSettlementTimeoutMs??$);if(this.activeRun===t&&(this.activeRun=void 0),r.settled)return r.value;let o={turnId:t.turnId,settlement:n};return o.settlement=n.finally(()=>{this.retiringRun===o&&(this.retiringRun=void 0)}),this.retiringRun=o,i}async stopActive(t,i){t.stopReason??=i;let n=t.sessionId,r=n?this.runtime.abortSession({id:n,turnId:t.turnId,reason:i==="limit"?"max_steps":i}).catch(()=>!1):Promise.resolve(!0);return t.controller.abort(new Error(`Turn stopped: ${i}`)),r}};function V(e,t,i){return{id:t.sessionId,turnId:e.turnId,content:e.content,...e.displayContent!==void 0?{displayContent:e.displayContent}:{},...i!==void 0?{executionDeadlineAtMs:i}:{},...e.executionDiagnostics?{executionDiagnostics:!0}:{},...e.clientIntent?{clientIntent:e.clientIntent}:{},...e.reviewRequest?{reviewRequest:e.reviewRequest}:{},...e.attachments?.length?{attachments:e.attachments.map(n=>({meta:{attachmentType:n.type,fileName:n.fileName,mimeType:n.mimeType,sizeBytes:n.sizeBytes},local:{...n.filePath?{filePath:n.filePath}:{},...n.assetId?{assetId:n.assetId}:{}}}))}:{},...e.model?{model:{...e.model}}:{},...e.outputSchema?{outputSchema:e.outputSchema}:{}}}function H(e){return e.type==="message"&&e.message.role==="assistant"}function K(e){return e.type==="delta"&&e.role==="assistant"&&typeof e.content=="string"}function Y(e){return e.type==="generic"&&(e.eventType==="questionnaire.ask"||e.eventType==="runtime.action-required"&&e.data.kind==="questionnaire")}function J(e){if(Y(e))return W()}function W(){return{category:"runtime",code:"QUESTIONNAIRE_REQUIRED",message:"Questionnaire requires user input.",retryable:!0}}function Z(e){if(e.type==="generic"&&e.eventType==="messages-rewound")return{status:"failed",error:{category:"runtime",code:"CONTENT_REVIEW_BLOCKED",message:"Content review blocked the request.",retryable:!0}};if(e.type==="error")return{status:"failed",error:{category:"runtime",message:e.message,retryable:!0}};if(e.type==="session-status"){if(e.status==="error")return{status:"failed",error:{category:"runtime",message:e.message??"Runtime turn failed.",retryable:!0}};if(e.status==="aborted"||e.status==="interrupted")return{status:"cancelled"}}}function ee(e){if(e instanceof p)return{category:e.category==="config"||e.category==="internal"?e.category:"runtime",code:e.code,message:e.message,retryable:e.retryable};if(e&&typeof e=="object"){let t=e;if(typeof t.message=="string")return{category:t.category==="config"||t.category==="internal"?t.category:"runtime",...typeof t.code=="string"?{code:t.code}:{},message:t.message,...typeof t.retryable=="boolean"?{retryable:t.retryable}:{retryable:!0}}}return{category:"runtime",message:e instanceof Error?e.message:String(e),retryable:!0}}function B(e,t){return e==="timeout"?"timeout":e==="limit"?"limit_exceeded":e==="user_stop"?"cancelled":t}async function G(e,t){try{await e(t)}catch{}}function te(e){let t=()=>{},i=new Promise(n=>{t=n});return{turnId:e,controller:new AbortController,settled:i,resolveSettled:t}}async function ne(e,t){if(!t.aborted)return new Promise((i,n)=>{let r=()=>t.removeEventListener("abort",o),o=()=>{r(),i(void 0)};t.addEventListener("abort",o,{once:!0}),e.then(a=>{r(),i(a)},a=>{r(),n(a)})})}async function ie(e,t){if(t<=0)return{settled:!1};let i,n=await Promise.race([e.then(r=>({settled:!0,value:r})),new Promise(r=>{i=setTimeout(()=>r({settled:!1}),t),i.unref?.()})]);return i&&clearTimeout(i),n}var q="Sign in to MiniMax to use Agent features. Run /login, then retry.",I="Sign in to MiniMax to use Agent features. Run `mcode login`, then retry.",S=class extends p{constructor(i,n=I){super("config",n,{code:"auth.login_required",retryable:!1});this.account=i;this.name="TuiLoginRequiredError"}};function re(e){return e.modelSource?e.modelSource==="token-plan":e.authMode==="managed-login"}function X(e){return e.status==="needs-login"||re(e)&&e.managedTokenPresent!==!0}function Te(e){return X(e)}async function z(e,t,i,n){let r=await e.getAccountStatus(t,n);return i?.(r),r}async function oe(e,t,i=I,n){let r=await z(e,t,n);if(X(r))throw new S(r,i);return r}async function se(e,t,i=I,n){let r=await z(e,t,n,{requireManagedAuth:!0});if(r.managedTokenPresent!==!0)throw new S(r,i);return r}async function ye(e,t,i){let n=e.getAccountStatus;n&&await oe({getAccountStatus:n.bind(e)},t,q,i)}async function Re(e,t,i){let n=e.getAccountStatus;n&&await se({getAccountStatus:n.bind(e)},t,q,i)}import{stripVTControlCharacters as ue}from"node:util";function Ae(e){let t=e.replace(/(?:\u001b\]|\u009d)[\s\S]*?(?:\u0007|\u001b\\|\u009c|$)|(?:\u001b[P^_X]|[\u0090\u0098\u009e\u009f])[\s\S]*?(?:\u001b\\|\u009c|$)/gu,"");return ue(t).replace(/\r\n/gu,`
|
|
3
|
+
`).replace(/\r/gu," ").replace(/[\u0000-\u0008\u000b\u000c\u000e-\u001f\u007f-\u009f]/gu,"")}export{Ae as a,v as b,L as c,N as d,Q as e,F as f,$ as g,j as h,S as i,Te as j,oe as k,ye as l,Re as m};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { createRequire as __mavis_cR } from "module"; import { basename as __mavis_basename, dirname as __mavis_dirname, join as __mavis_join } from "path"; import { fileURLToPath as __mavis_fileURLToPath, pathToFileURL as __mavis_pathToFileURL } from "url"; const __mavis_tuiCurrentModuleDir = __mavis_dirname(__mavis_fileURLToPath(import.meta.url)); const __mavis_tuiPackageRoot = __mavis_basename(__mavis_tuiCurrentModuleDir) === "chunks" ? __mavis_dirname(__mavis_tuiCurrentModuleDir) : __mavis_tuiCurrentModuleDir; const __mavis_tuiPackageEntryUrl = __mavis_pathToFileURL(__mavis_join(__mavis_tuiPackageRoot, "cli.js")).href; const require = __mavis_cR(__mavis_tuiPackageEntryUrl); const __dirname = __mavis_tuiPackageRoot;
|
|
2
|
-
import{a as p}from"./chunk-
|
|
2
|
+
import{a as p}from"./chunk-T6KXDH7B.js";import{e as g,k as d,m as h}from"./chunk-7CKVJIAL.js";import{isAbsolute as f,resolve as A}from"node:path";import{spawn as E}from"node:child_process";import{fileURLToPath as y}from"node:url";function T(e){return t=>R(t,e)}function R(e,t){let i=S(e,t),[o,r]=process.platform==="darwin"?["open",[i]]:process.platform==="win32"?["rundll32",["url.dll,FileProtocolHandler",i]]:["xdg-open",[i]];return new Promise((s,u)=>{let n=E(o,r,{detached:!0,stdio:"ignore",windowsHide:!0});n.once("error",u),n.once("spawn",()=>{n.unref(),s()})})}function S(e,t){return/^https?:\/\//iu.test(e)?e:/^file:\/\//iu.test(e)?y(e):f(e)?e:A(t,e)}var x="mcode-internal";function k(e){try{let t=new URL(e);return t.searchParams.set("client_surface","tui"),t.searchParams.set("download_source",x),t.toString()}catch{return e}}var w={cn:{dev:"https://agent.minimaxi.com",test:"https://agent.minimaxi.com",staging:"https://agent.minimaxi.com",prod:"https://agent.minimax.cn"},en:{dev:"https://agent.minimax.io",test:"https://agent.minimax.io",staging:"https://agent.minimax.io",prod:"https://agent.minimax.io"}};function m(e){let t=w[e.region][e.buildEnv];return`${t}/auth/logout?logout_redirect_uri=${encodeURIComponent(t)}`}var c=class{constructor(t){this.options=t;let i=d({runtimeRegion:process.env.MAVIS_REGION==="en"?"en":"cn"});this.scope={region:t.region??i.region,buildEnv:t.buildEnv??i.buildEnv}}scope;async login(t,i=this.scope.region){this.track("login_click",{hailuo_user_id:this.hailuoUserId()});try{let o={...this.scope,region:i},r=!P(o,this.scope),s=this.options.sharedAuthCore;if(r){if(!this.options.resolveSharedAuthCore)throw new Error(C(this.scope,o));s=this.options.resolveSharedAuthCore(i)}let u=(await s.getStatus()).status==="authenticated",n=!1;await s.login({onDeviceAuthorization:M=>{n=!0,t?.({state:"device-authorization",...M})}}),this.persistRegionPreference(o);let l=u&&!n,v={state:l?"already-authenticated":"authenticated",message:l?r?`Already signed in with ${a(o.region)}.`:"Already signed in with MiniMax.":r?`Signed in with ${a(o.region)}.`:"Signed in with MiniMax.",...r?{restartRequired:!0}:{}};return this.trackLoginResult("1",""),v}catch(o){throw this.trackLoginResult("2",b(o)),o}}async logout(){this.track("logout_click",{hailuo_user_id:this.hailuoUserId()});let t=await this.options.sharedAuthCore.getStatus(),i=await this.options.sharedAuthCore.logout({revoke:!0}),o=m(this.scope);return t.status==="anonymous"&&i.status==="anonymous"?{state:"already-signed-out",message:"Already signed out of MiniMax.",logoutUrl:o}:{state:"signed-out",logoutUrl:o,message:i.status==="logout_pending"?`Signed out locally from ${a(this.scope.region)} across MCode. Server revocation is pending until the network recovers.`:`Signed out of ${a(this.scope.region)} on Desktop, CLI/TUI, and embedded mcode-tools.`}}trackLoginResult(t,i){this.track("login_result",{hailuo_user_id:this.hailuoUserId(),source:this.options.telemetrySource??"mcode_cli",result_type:t,fail_reason:i,login_type:"minimax_oauth"})}persistRegionPreference(t){try{this.options.writeRegionPreference?.(this.options.dataDir,t)}catch{}}hailuoUserId(){try{return this.options.hailuoUserId?.()?.trim()??""}catch{return""}}track(t,i){try{this.options.telemetry?.track(t,i)}catch{}}};function b(e){let t=e instanceof Error?e.message:String(e);return/cancel/iu.test(t)?"3":/network|offline|fetch|ECONN|ENOTFOUND|ETIMEDOUT/iu.test(t)?"2":/oauth|authorization|login failed|invalid login state/iu.test(t)?"5":/server|HTTP 5\d\d/iu.test(t)?"1":"4"}function P(e,t){return e.region===t.region&&e.buildEnv===t.buildEnv}function C(e,t){return e.region!==t.region?`Signed in to ${a(e.region)}. Run \`mcode logout\` before signing in to ${a(t.region)}.`:`Signed in to another MiniMax ${e.buildEnv} environment. Run \`mcode logout\` before signing in to ${t.buildEnv}.`}function a(e){return e==="cn"?"MiniMax China":"MiniMax Global"}function j(e){let t=d({runtimeRegion:e.region,runtimeBuildEnv:e.buildEnv}),i=e.region??t.region,o=e.buildEnv??t.buildEnv,r={dataDir:e.dataDir,region:i,buildEnv:o,...e.telemetry?{telemetry:e.telemetry}:{},...e.telemetrySource?{telemetrySource:e.telemetrySource}:{},...e.hailuoUserId?{hailuoUserId:e.hailuoUserId}:{},writeRegionPreference:e.writeRegionPreference??h},s=n=>(e.createSharedSession??p)({dataDir:e.dataDir,region:n,buildEnv:o,oauthEndpoints:g(e.oauthEndpointEnvironment??process.env,{buildEnv:o,region:n})}),u=e.sharedAuthCore??s(i);return new c({...r,sharedAuthCore:u,resolveSharedAuthCore:s})}export{T as a,k as b,j as c};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { createRequire as __mavis_cR } from "module"; import { basename as __mavis_basename, dirname as __mavis_dirname, join as __mavis_join } from "path"; import { fileURLToPath as __mavis_fileURLToPath, pathToFileURL as __mavis_pathToFileURL } from "url"; const __mavis_tuiCurrentModuleDir = __mavis_dirname(__mavis_fileURLToPath(import.meta.url)); const __mavis_tuiPackageRoot = __mavis_basename(__mavis_tuiCurrentModuleDir) === "chunks" ? __mavis_dirname(__mavis_tuiCurrentModuleDir) : __mavis_tuiCurrentModuleDir; const __mavis_tuiPackageEntryUrl = __mavis_pathToFileURL(__mavis_join(__mavis_tuiPackageRoot, "cli.js")).href; const require = __mavis_cR(__mavis_tuiPackageEntryUrl); const __dirname = __mavis_tuiPackageRoot;
|
|
2
|
-
import{a,b,c,d}from"./chunk-
|
|
2
|
+
import{a,b,c,d}from"./chunk-T4F6MBL2.js";import"./chunk-7CKVJIAL.js";import"./chunk-XYED4XTT.js";import"./chunk-Z4VKGZFA.js";import"./chunk-CWWDVX6C.js";import"./chunk-ZITT4GJK.js";import"./chunk-D76SO2ME.js";export{b as getTuiDataDirPath,d as prepareTuiDataDir,a as resolveDefaultTuiDataDir,c as resolveTuiDataDir};
|