@maincode-ai/matilda-code 0.19.6 → 0.19.8

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.
Files changed (37) hide show
  1. package/chunks/{agent-NN3YCAQH.js → agent-2NBSL6Q2.js} +1 -1
  2. package/chunks/{agent-headless-GCUE63J5.js → agent-headless-AXEWDJRM.js} +1 -1
  3. package/chunks/{anthropicContentGenerator-CZLOMDXF.js → anthropicContentGenerator-DKMAJXYA.js} +1 -1
  4. package/chunks/chunk-GTR4V2PV.js +8 -0
  5. package/chunks/{chunk-NRPYZBZX.js → chunk-HDVKP4RM.js} +1 -1
  6. package/chunks/{chunk-OREAJC5D.js → chunk-HUPUKBVY.js} +12 -5
  7. package/chunks/{chunk-TZIIADJW.js → chunk-ILO32IXN.js} +2 -2
  8. package/chunks/{chunk-ETVBCNID.js → chunk-OJTERV74.js} +1 -1
  9. package/chunks/{chunk-RAHHGBHX.js → chunk-WIDV26MB.js} +1 -1
  10. package/chunks/{chunk-OGLMWPGR.js → chunk-WN7W7S2V.js} +2 -2
  11. package/chunks/{computer-use-AM62LD63.js → computer-use-7PIVVKPK.js} +1 -1
  12. package/chunks/{contextCommand-CWNMYXES.js → contextCommand-SO4X2MS6.js} +1 -1
  13. package/chunks/{edit-PJD2ABCG.js → edit-B5KZGY7B.js} +1 -1
  14. package/chunks/{enter-worktree-MTT3VNXA.js → enter-worktree-RRN3GMRW.js} +1 -1
  15. package/chunks/{enterPlanMode-KJSXKSQX.js → enterPlanMode-ZPXWNPYM.js} +1 -1
  16. package/chunks/{exit-worktree-CX2HMIRN.js → exit-worktree-HND5ZVDQ.js} +1 -1
  17. package/chunks/{exitPlanMode-QQ7DSRYT.js → exitPlanMode-K7HACJ6K.js} +1 -1
  18. package/chunks/{geminiContentGenerator-HZHMNMGX.js → geminiContentGenerator-ZE6UPRAE.js} +1 -1
  19. package/chunks/{glob-L6LCKWIV.js → glob-PXQT4CHI.js} +1 -1
  20. package/chunks/{grep-PIJYRFHS.js → grep-B2OXQK7Q.js} +1 -1
  21. package/chunks/{matildaAgentContentGenerator-Y2ECTUZO.js → matildaAgentContentGenerator-Q43QK5GQ.js} +1 -1
  22. package/chunks/{matildaContentGenerator-HATVJLJF.js → matildaContentGenerator-MTZC3PAG.js} +1 -1
  23. package/chunks/{monitor-A3RDX2JT.js → monitor-6AWWXDIL.js} +1 -1
  24. package/chunks/{notebook-edit-5KEG5MTP.js → notebook-edit-7BJPP7ZB.js} +1 -1
  25. package/chunks/{openaiContentGenerator-XI6SCJ2G.js → openaiContentGenerator-JX2JAR3V.js} +1 -1
  26. package/chunks/{ripGrep-PXECRMR2.js → ripGrep-G3IY6ZWZ.js} +1 -1
  27. package/chunks/{scheduler-XG6XEE2W.js → scheduler-FFE43QWC.js} +1 -1
  28. package/chunks/{serve-RZQK4PGY.js → serve-RXBWGIMV.js} +1 -1
  29. package/chunks/{shell-CGATWESB.js → shell-4HTE526K.js} +1 -1
  30. package/chunks/{src-D4A3YMBH.js → src-F4LDZDLP.js} +1 -1
  31. package/chunks/{team-create-WADAQUBF.js → team-create-VWJKHFTR.js} +1 -1
  32. package/chunks/{web-search-XR5V4QRH.js → web-search-FEZM3B3R.js} +1 -1
  33. package/chunks/{workflow-NTYIHQG2.js → workflow-GNYDTGHJ.js} +2 -2
  34. package/chunks/{write-file-THZKUU47.js → write-file-2PLDMI5M.js} +1 -1
  35. package/cli.js +371 -371
  36. package/package.json +2 -2
  37. package/chunks/chunk-FSRNEJQB.js +0 -8
@@ -1,3 +1,3 @@
1
1
  // Force strict mode and setup for ESM
2
2
  "use strict";
3
- import{Af as c,Bf as d,Cf as e,Df as f,yf as a,zf as b}from"./chunk-OREAJC5D.js";import"./chunk-TZIDSCTF.js";import"./chunk-FUNLOUYI.js";import"./chunk-R3H6IWFK.js";import"./chunk-OMZ5SGMK.js";import"./chunk-KP6BLFQS.js";import"./chunk-RBG4ERTN.js";import"./chunk-TXMXCR7D.js";import"./chunk-YULUB745.js";import"./chunk-LQWORCPO.js";import"./chunk-TISQNFB5.js";import"./chunk-XXZH7C44.js";import"./chunk-47XR7IMP.js";import"./chunk-QEI3OETI.js";import"./chunk-QKYGQLWC.js";import"./chunk-MNGFXISD.js";import"./chunk-4R2OFVPK.js";import"./chunk-RNKDFE2S.js";import"./chunk-EMWHQSMS.js";import"./chunk-FSRNEJQB.js";import"./chunk-S4K76QPI.js";import"./chunk-RAHHGBHX.js";import"./chunk-4F4DA5UI.js";import"./chunk-2XZIKUB6.js";import"./chunk-XYA3SFGC.js";import"./chunk-4J6DC24J.js";import"./chunk-LJR4RZZ2.js";import"./chunk-U347OO7S.js";import"./chunk-CLUEFPSU.js";import"./chunk-7VGUNT5L.js";import"./chunk-CFBZKYFB.js";import"./chunk-WVY2P6WH.js";import"./chunk-UIRBHC5X.js";import"./chunk-UY2R3ZQ4.js";import"./chunk-NDR7ZFUA.js";import"./chunk-5U3A6KMU.js";import"./chunk-LLQVLTPB.js";import"./chunk-XKDGRW3K.js";import"./chunk-ESSYHTAZ.js";import"./chunk-IOCF4XSR.js";import"./chunk-QWBNNEV2.js";import"./chunk-G7R2XEEF.js";import"./chunk-OA56BXPD.js";import"./chunk-FWDMPRKU.js";import"./chunk-GZPNIYVZ.js";import"./chunk-OWGSC52X.js";export{f as AgentTool,b as TOOL_REGISTRY_REBUILT,e as createApprovalModeOverride,c as hasRebuiltToolRegistry,d as rebuildToolRegistryOnOverride,a as resolveSubagentApprovalMode};
3
+ import{Af as c,Bf as d,Cf as e,Df as f,yf as a,zf as b}from"./chunk-HUPUKBVY.js";import"./chunk-TZIDSCTF.js";import"./chunk-FUNLOUYI.js";import"./chunk-R3H6IWFK.js";import"./chunk-OMZ5SGMK.js";import"./chunk-KP6BLFQS.js";import"./chunk-RBG4ERTN.js";import"./chunk-TXMXCR7D.js";import"./chunk-YULUB745.js";import"./chunk-LQWORCPO.js";import"./chunk-TISQNFB5.js";import"./chunk-XXZH7C44.js";import"./chunk-47XR7IMP.js";import"./chunk-QEI3OETI.js";import"./chunk-QKYGQLWC.js";import"./chunk-MNGFXISD.js";import"./chunk-4R2OFVPK.js";import"./chunk-RNKDFE2S.js";import"./chunk-EMWHQSMS.js";import"./chunk-GTR4V2PV.js";import"./chunk-S4K76QPI.js";import"./chunk-WIDV26MB.js";import"./chunk-4F4DA5UI.js";import"./chunk-2XZIKUB6.js";import"./chunk-XYA3SFGC.js";import"./chunk-4J6DC24J.js";import"./chunk-LJR4RZZ2.js";import"./chunk-U347OO7S.js";import"./chunk-CLUEFPSU.js";import"./chunk-7VGUNT5L.js";import"./chunk-CFBZKYFB.js";import"./chunk-WVY2P6WH.js";import"./chunk-UIRBHC5X.js";import"./chunk-UY2R3ZQ4.js";import"./chunk-NDR7ZFUA.js";import"./chunk-5U3A6KMU.js";import"./chunk-LLQVLTPB.js";import"./chunk-XKDGRW3K.js";import"./chunk-ESSYHTAZ.js";import"./chunk-IOCF4XSR.js";import"./chunk-QWBNNEV2.js";import"./chunk-G7R2XEEF.js";import"./chunk-OA56BXPD.js";import"./chunk-FWDMPRKU.js";import"./chunk-GZPNIYVZ.js";import"./chunk-OWGSC52X.js";export{f as AgentTool,b as TOOL_REGISTRY_REBUILT,e as createApprovalModeOverride,c as hasRebuiltToolRegistry,d as rebuildToolRegistryOnOverride,a as resolveSubagentApprovalMode};
@@ -1,3 +1,3 @@
1
1
  // Force strict mode and setup for ESM
2
2
  "use strict";
3
- import{$e as c,Ze as a,_e as b}from"./chunk-OREAJC5D.js";import"./chunk-TZIDSCTF.js";import"./chunk-FUNLOUYI.js";import"./chunk-R3H6IWFK.js";import"./chunk-OMZ5SGMK.js";import"./chunk-KP6BLFQS.js";import"./chunk-RBG4ERTN.js";import"./chunk-TXMXCR7D.js";import"./chunk-YULUB745.js";import"./chunk-LQWORCPO.js";import"./chunk-TISQNFB5.js";import"./chunk-XXZH7C44.js";import"./chunk-47XR7IMP.js";import"./chunk-QEI3OETI.js";import"./chunk-QKYGQLWC.js";import"./chunk-MNGFXISD.js";import"./chunk-4R2OFVPK.js";import"./chunk-RNKDFE2S.js";import"./chunk-EMWHQSMS.js";import"./chunk-FSRNEJQB.js";import"./chunk-S4K76QPI.js";import"./chunk-RAHHGBHX.js";import"./chunk-4F4DA5UI.js";import"./chunk-2XZIKUB6.js";import"./chunk-XYA3SFGC.js";import"./chunk-4J6DC24J.js";import"./chunk-LJR4RZZ2.js";import"./chunk-U347OO7S.js";import"./chunk-CLUEFPSU.js";import"./chunk-7VGUNT5L.js";import"./chunk-CFBZKYFB.js";import"./chunk-WVY2P6WH.js";import"./chunk-UIRBHC5X.js";import"./chunk-UY2R3ZQ4.js";import"./chunk-NDR7ZFUA.js";import"./chunk-5U3A6KMU.js";import"./chunk-LLQVLTPB.js";import"./chunk-XKDGRW3K.js";import"./chunk-ESSYHTAZ.js";import"./chunk-IOCF4XSR.js";import"./chunk-QWBNNEV2.js";import"./chunk-G7R2XEEF.js";import"./chunk-OA56BXPD.js";import"./chunk-FWDMPRKU.js";import"./chunk-GZPNIYVZ.js";import"./chunk-OWGSC52X.js";export{c as AgentHeadless,a as ContextState,b as templateString};
3
+ import{$e as c,Ze as a,_e as b}from"./chunk-HUPUKBVY.js";import"./chunk-TZIDSCTF.js";import"./chunk-FUNLOUYI.js";import"./chunk-R3H6IWFK.js";import"./chunk-OMZ5SGMK.js";import"./chunk-KP6BLFQS.js";import"./chunk-RBG4ERTN.js";import"./chunk-TXMXCR7D.js";import"./chunk-YULUB745.js";import"./chunk-LQWORCPO.js";import"./chunk-TISQNFB5.js";import"./chunk-XXZH7C44.js";import"./chunk-47XR7IMP.js";import"./chunk-QEI3OETI.js";import"./chunk-QKYGQLWC.js";import"./chunk-MNGFXISD.js";import"./chunk-4R2OFVPK.js";import"./chunk-RNKDFE2S.js";import"./chunk-EMWHQSMS.js";import"./chunk-GTR4V2PV.js";import"./chunk-S4K76QPI.js";import"./chunk-WIDV26MB.js";import"./chunk-4F4DA5UI.js";import"./chunk-2XZIKUB6.js";import"./chunk-XYA3SFGC.js";import"./chunk-4J6DC24J.js";import"./chunk-LJR4RZZ2.js";import"./chunk-U347OO7S.js";import"./chunk-CLUEFPSU.js";import"./chunk-7VGUNT5L.js";import"./chunk-CFBZKYFB.js";import"./chunk-WVY2P6WH.js";import"./chunk-UIRBHC5X.js";import"./chunk-UY2R3ZQ4.js";import"./chunk-NDR7ZFUA.js";import"./chunk-5U3A6KMU.js";import"./chunk-LLQVLTPB.js";import"./chunk-XKDGRW3K.js";import"./chunk-ESSYHTAZ.js";import"./chunk-IOCF4XSR.js";import"./chunk-QWBNNEV2.js";import"./chunk-G7R2XEEF.js";import"./chunk-OA56BXPD.js";import"./chunk-FWDMPRKU.js";import"./chunk-GZPNIYVZ.js";import"./chunk-OWGSC52X.js";export{c as AgentHeadless,a as ContextState,b as templateString};
@@ -22,7 +22,7 @@ Human:`;b.AI_PROMPT=`
22
22
 
23
23
  Assistant:`;b.DEFAULT_TIMEOUT=6e5;b.AnthropicError=h;b.APIError=k;b.APIConnectionError=X;b.APIConnectionTimeoutError=ue;b.APIUserAbortError=x;b.NotFoundError=Fe;b.ConflictError=Oe;b.RateLimitError=Le;b.BadRequestError=Me;b.AuthenticationError=ve;b.InternalServerError=qe;b.PermissionDeniedError=Ie;b.UnprocessableEntityError=Be;b.toFile=Yn;b.fileFromPath=ot;b.Completions=ie;b.Messages=H;b.Models=Y;b.ModelInfosPage=ce;b.Beta=D;var{HUMAN_PROMPT:Ga,AI_PROMPT:Wa}=b,yr=b;c();c();function Qe(r){let{inputTokens:e,cacheReadTokens:t,cacheCreationTokens:n,outputTokens:s}=r,i=n===0&&t>0&&e>=t?e:e+t+n;return{promptTokenCount:i,candidatesTokenCount:s,totalTokenCount:i+s,cachedContentTokenCount:t}}var Lt=class{model;schemaCompliance;enableCacheControl;constructor(e,t="auto",n=!0){this.model=e,this.schemaCompliance=t,this.enableCacheControl=n}convertGeminiRequestToAnthropic(e,t={}){let n=[],s=this.extractTextFromContentUnion(e.config?.systemInstruction);this.processContents(e.contents,n),t.stripAssistantThinking&&this.stripThinkingFromAssistantMessages(n),t.normalizeAssistantThinkingSignature&&this.fillMissingThinkingSignatures(n),t.injectThinkingOnToolUseTurns&&this.injectEmptyThinkingOnToolUseTurns(n);let o=t.enableCacheControl??this.enableCacheControl,i=t.useGlobalCacheScope??!1,a=o?this.buildSystemWithCacheControl(s,i):s;return o&&this.addCacheControlToMessages(n),{system:a,messages:n}}async convertGeminiToolsToAnthropic(e,t={}){let n=[];for(let i of e){let a;if("tool"in i?a=await i.tool():a=i,!!a.functionDeclarations)for(let u of a.functionDeclarations){if(!u.name||!u.description)continue;let l;u.parametersJsonSchema?l={...u.parametersJsonSchema}:u.parameters&&(l=u.parameters),l||(l={type:"object",properties:{}}),l=_n(l,this.schemaCompliance),typeof l.type!="string"&&(l.type="object"),n.push({name:u.name,description:u.description,input_schema:l})}}let s=t.enableCacheControl??this.enableCacheControl,o=t.useGlobalCacheScope??!1;if(s&&n.length>0){let i=n.length-1;n[i]={...n[i],cache_control:o?{type:"ephemeral",scope:"global"}:{type:"ephemeral"}}}return n}convertAnthropicResponseToGemini(e){let t=new et,n=[];for(let i of e.content||[]){let a=String(i.type||"");if(a==="text"){let u=typeof i.text=="string"?i.text:"";u&&n.push({text:u})}else if(a==="tool_use"){let u=i;n.push({functionCall:{id:typeof u.id=="string"?u.id:void 0,name:typeof u.name=="string"?u.name:void 0,args:this.safeInputToArgs(u.input)}})}else if(a==="thinking"){let u=typeof i.thinking=="string"?i.thinking:"",l=typeof i.signature=="string"?i.signature:"";if(u||l){let m={text:u,thought:!0,thoughtSignature:l};n.push(m)}}else a==="redacted_thinking"&&n.push({text:"",thought:!0})}let s={content:{parts:n,role:"model"},index:0,safetyRatings:[]},o=this.mapAnthropicFinishReasonToGemini(e.stop_reason);return o&&(s.finishReason=o),t.candidates=[s],t.responseId=e.id,t.createTime=Date.now().toString(),t.modelVersion=e.model||this.model,t.promptFeedback={safetyRatings:[]},e.usage&&(t.usageMetadata=Qe({inputTokens:e.usage.input_tokens||0,cacheReadTokens:e.usage.cache_read_input_tokens||0,cacheCreationTokens:e.usage.cache_creation_input_tokens||0,outputTokens:e.usage.output_tokens||0})),t}processContents(e,t){if(Array.isArray(e))for(let n of e)this.processContent(n,t);else e&&this.processContent(e,t)}processContent(e,t){if(typeof e=="string"){t.push({role:"user",content:[{type:"text",text:e}]});return}if(!this.isContentObject(e))return;let n=e.parts||[],s=e.role==="model"?"assistant":"user",o=[],i=0;for(let a of n){if(typeof a=="string"){o.push({type:"text",text:a});continue}if("text"in a&&"thought"in a&&a.thought&&s==="assistant"){let l={type:"thinking",thinking:a.text||""};"thoughtSignature"in a&&typeof a.thoughtSignature=="string"&&(l.signature=a.thoughtSignature),o.push(l)}"text"in a&&a.text&&!("thought"in a&&a.thought)&&o.push({type:"text",text:a.text});let u=this.createMediaBlockFromPart(a);if(u&&o.push(u),"functionCall"in a&&a.functionCall&&s==="assistant"&&(o.push({type:"tool_use",id:a.functionCall.id||`tool_${i}`,name:a.functionCall.name||"",input:a.functionCall.args||{}}),i+=1),a.functionResponse){let l=this.createToolResultBlock(a.functionResponse);l&&s==="user"&&o.push(l)}}o.length>0&&t.push({role:s,content:o})}createToolResultBlock(e){let t=this.extractFunctionResponseContent(e.response),n=[];for(let o of e.parts||[]){let i=this.createMediaBlockFromPart(o);i&&n.push(i)}let s;if(n.length>0){let o=[];t&&o.push({type:"text",text:t}),o.push(...n),s=o}else s=t;return{type:"tool_result",tool_use_id:e.id||"",content:s}}createMediaBlockFromPart(e){if(e.inlineData?.mimeType&&e.inlineData?.data){if(this.isSupportedAnthropicImageMimeType(e.inlineData.mimeType))return{type:"image",source:{type:"base64",media_type:e.inlineData.mimeType,data:e.inlineData.data}};if(e.inlineData.mimeType==="application/pdf")return{type:"document",source:{type:"base64",media_type:"application/pdf",data:e.inlineData.data}};let t=e.inlineData.displayName?` (${e.inlineData.displayName})`:"";return{type:"text",text:`Unsupported inline media type: ${e.inlineData.mimeType}${t}.`}}if(e.fileData?.mimeType&&e.fileData?.fileUri){let t=e.fileData.displayName?` (${e.fileData.displayName})`:"",n=e.fileData.fileUri;return this.isSupportedAnthropicImageMimeType(e.fileData.mimeType)?{type:"image",source:{type:"url",url:n}}:e.fileData.mimeType==="application/pdf"?{type:"document",source:{type:"url",url:n}}:{type:"text",text:`Unsupported file media type: ${e.fileData.mimeType}${t}.`}}return null}isSupportedAnthropicImageMimeType(e){return e==="image/jpeg"||e==="image/png"||e==="image/gif"||e==="image/webp"}extractTextFromContentUnion(e){return typeof e=="string"?e:Array.isArray(e)?e.map(t=>this.extractTextFromContentUnion(t)).filter(Boolean).join(`
24
24
  `):typeof e=="object"&&e!==null&&"parts"in e&&e.parts?.map(n=>typeof n=="string"?n:"text"in n&&n.text||"").filter(Boolean).join(`
25
- `)||""}extractFunctionResponseContent(e){if(e==null)return"";if(typeof e=="string")return e;if(typeof e=="object"){let t=e,n=t.output;if(typeof n=="string")return n;let s=t.error;if(typeof s=="string")return s}try{return JSON.stringify(e)??String(e)}catch{return String(e)}}safeInputToArgs(e){return e&&typeof e=="object"?e:typeof e=="string"?tt(e,{}):{}}mapAnthropicFinishReasonToGemini(e){return e?{end_turn:Z.STOP,stop_sequence:Z.STOP,tool_use:Z.STOP,max_tokens:Z.MAX_TOKENS,content_filter:Z.SAFETY}[e]||Z.FINISH_REASON_UNSPECIFIED:void 0}isContentObject(e){return typeof e=="object"&&e!==null&&"role"in e&&"parts"in e&&Array.isArray(e.parts)}buildSystemWithCacheControl(e,t){return e&&[{type:"text",text:e,cache_control:t?{type:"ephemeral",scope:"global"}:{type:"ephemeral"}}]}stripThinkingFromAssistantMessages(e){for(let t of e){if(t.role!=="assistant"||!Array.isArray(t.content))continue;let n=t.content.filter(s=>{let o=s.type;return o!=="thinking"&&o!=="redacted_thinking"});n.length!==0&&n.length!==t.content.length&&(t.content=n)}}fillMissingThinkingSignatures(e){for(let t of e){if(t.role!=="assistant"||!Array.isArray(t.content))continue;let n=!1,s=t.content.map(o=>{let i=o;return i.type==="thinking"&&typeof i.signature!="string"?(n=!0,{...o,signature:""}):o});n&&(t.content=s)}}injectEmptyThinkingOnToolUseTurns(e){for(let t of e){if(t.role!=="assistant"||!Array.isArray(t.content))continue;let n=t.content;if(!n.some(a=>a.type==="tool_use")||n.some(a=>{let u=a.type;return u==="thinking"||u==="redacted_thinking"}))continue;let i={type:"thinking",thinking:"",signature:""};t.content=[i,...n]}}addCacheControlToMessages(e){for(let t=e.length-1;t>=0;t--){let n=e[t];if(n.role==="user"){let s=Array.isArray(n.content)?n.content:[{type:"text",text:n.content}];if(s.length>0){let o=s[s.length-1];if(typeof o=="object"&&"type"in o){let i=o.type,a=i==="text"&&(!("text"in o)||!o.text);(i==="text"||i==="tool_result")&&!a&&(o.cache_control={type:"ephemeral"})}n.content=s}break}}}};var yn=bn("ANTHROPIC");function _r(r){let e=r.baseUrl??"";if(!e)return!1;try{let t=new URL(e).hostname.toLowerCase();return t==="api.deepseek.com"||t.endsWith(".api.deepseek.com")}catch{return!1}}function vs(r){return _r(r)?!0:(r.model??"").toLowerCase().includes("deepseek")}function Is(r){let e=r.baseUrl?.trim();if(e)return e;let t=process.env.ANTHROPIC_BASE_URL?.trim();return t||"https://api.anthropic.com"}function br(r){try{let e=new URL(Is(r)).hostname.toLowerCase();return e==="api.anthropic.com"||e.endsWith(".anthropic.com")}catch{return!1}}var Ye=class{constructor(e,t){this.contentGeneratorConfig=e;this.cliConfig=t;let n=!br(e),s=this.buildHeaders(n),o=e.baseUrl,i=xn("anthropic",this.cliConfig.getProxy());this.client=new yr({...n?{authToken:e.apiKey,apiKey:null}:{apiKey:e.apiKey,authToken:null},baseURL:o,timeout:e.timeout||12e4,maxRetries:e.maxRetries,defaultHeaders:s,...i}),this.converter=new Lt(e.model,e.schemaCompliance,e.enableCacheControl)}client;converter;effortClampWarned=!1;async generateContent(e){let t;try{let n=await this.buildRequest(e);nt.recordAnthropicWireRequest(n);let s=this.buildPerRequestHeaders(n);t=await this.client.messages.create(n,{signal:e.config?.abortSignal,...s?{headers:s}:{}})}catch(n){throw _e(n)}return this.converter.convertAnthropicResponseToGemini(t)}async generateContentStream(e){let t=await this.buildRequest(e),n=this.buildPerRequestHeaders(t),s={...t,stream:!0};nt.recordAnthropicWireRequest(s);let o;try{o=await this.client.messages.create(s,{signal:e.config?.abortSignal,...n?{headers:n}:{}})}catch(i){throw _e(i)}return this.processStreamWithEmptyFallback(this.redactStreamErrors(o),t,e.config?.abortSignal,n)}async countTokens(e){try{return{totalTokens:(await new Tn().calculateTokens(e)).totalTokens}}catch(t){yn.warn("Failed to calculate tokens with tokenizer, falling back to simple method:",t);let n=JSON.stringify(e.contents);return{totalTokens:Math.ceil(n.length/4)}}}async embedContent(e){throw new Error("Anthropic does not support embeddings.")}useSummarizedThinking(){return!1}buildHeaders(e){let t=this.cliConfig.getCliVersion()||"unknown",n=e?`claude-cli/${t} (external, cli)`:`MatildaCode/${t} (${process.platform}; ${process.arch})`,{customHeaders:s}=this.contentGeneratorConfig,o={"User-Agent":n};if(e&&(o["x-app"]="cli"),s)for(let[i,a]of Object.entries(s))i.toLowerCase()==="anthropic-beta"||Cn(i)||(o[i]=a);return o}buildPerRequestHeaders(e){let t=[];for(let s of this.collectCustomBetaFlags())t.push(s);return e.thinking&&t.push("interleaved-thinking-2025-05-14"),e.output_config&&t.push("effort-2025-11-24"),this.hasGlobalCacheScopeOnWire(e)&&t.push("prompt-caching-scope-2026-01-05"),t.length===0?void 0:{"anthropic-beta":Array.from(new Set(t)).join(",")}}useGlobalCacheScope(){return this.contentGeneratorConfig.enableCacheControl!==!1&&br(this.contentGeneratorConfig)}hasGlobalCacheScopeOnWire(e){let t=n=>{if(!n||typeof n!="object")return!1;let s=n.cache_control;return!s||typeof s!="object"?!1:s.scope==="global"};if(Array.isArray(e.system)){for(let n of e.system)if(t(n))return!0}if(Array.isArray(e.tools)){for(let n of e.tools)if(t(n))return!0}return!1}collectCustomBetaFlags(){let e=this.contentGeneratorConfig.customHeaders;if(!e)return[];let t=[];for(let[n,s]of Object.entries(e))if(n.toLowerCase()==="anthropic-beta"&&!(typeof s!="string"||!s))for(let o of s.split(",")){let i=o.trim();i&&t.push(i)}return t}async buildRequest(e){let t=this.buildSamplingParameters(e),n=this.resolveEffectiveEffort(e),s=this.buildThinkingConfig(e,n),o=this.buildOutputConfig(e,n),i=vs(this.contentGeneratorConfig),a=i&&!!s,u=i&&!s,l=this.contentGeneratorConfig.enableCacheControl!==!1,m=this.useGlobalCacheScope(),f=e.config?.tools?await this.converter.convertGeminiToolsToAnthropic(e.config.tools,{enableCacheControl:l,useGlobalCacheScope:m}):void 0,_=m&&!!f&&f.length>0,g=m&&!_,{system:S,messages:y}=this.converter.convertGeminiRequestToAnthropic(e,{normalizeAssistantThinkingSignature:a,injectThinkingOnToolUseTurns:a,stripAssistantThinking:u,enableCacheControl:l,useGlobalCacheScope:g});return{model:this.contentGeneratorConfig.model,system:S,messages:y,tools:f,...t,...s?{thinking:s}:{},...o?{output_config:o}:{}}}buildSamplingParameters(e){let t=this.contentGeneratorConfig.samplingParams,n=e.config||{},s=(m,f)=>{let _=t?.[m],g=f?n[f]:void 0;return _!==void 0?_:g},o=s("max_tokens","maxOutputTokens"),i=this.contentGeneratorConfig.model,a=kn(i,"output"),u=Sn(i),l;if(o!=null)l=u?Math.min(o,a):o;else{let m=process.env.MATILDA_CODE_MAX_OUTPUT_TOKENS,f=m?parseInt(m,10):NaN;!isNaN(f)&&f>0?l=u?Math.min(f,a):f:l=Math.min(a,8e3)}return{max_tokens:l,temperature:s("temperature","temperature")??1,top_p:s("top_p","topP"),top_k:s("top_k","topK")}}resolveEffectiveEffort(e){if(e.config?.thinkingConfig?.includeThoughts===!1)return;let t=this.contentGeneratorConfig.reasoning;if(t===!1||t===void 0)return;let n=t.effort;if(n!==void 0)return n==="max"&&!_r(this.contentGeneratorConfig)?(this.effortClampWarned||(yn.warn("reasoning.effort='max' is a DeepSeek extension; clamping to 'high' for non-DeepSeek anthropic provider to avoid HTTP 400."),this.effortClampWarned=!0),"high"):n}modelSupportsAdaptiveThinking(){let t=(this.contentGeneratorConfig.model||"").toLowerCase().match(/claude-(?:opus|sonnet|haiku)-(\d+)-(\d+)/);if(!t)return!1;let n=Number.parseInt(t[1],10),s=Number.parseInt(t[2],10);return n>4||n===4&&s>=6}buildThinkingConfig(e,t){if(e.config?.thinkingConfig?.includeThoughts===!1)return;let n=this.contentGeneratorConfig.reasoning;return n===!1?void 0:n?.budget_tokens!==void 0?{type:"enabled",budget_tokens:n.budget_tokens}:this.modelSupportsAdaptiveThinking()?{type:"adaptive"}:{type:"enabled",budget_tokens:t==="low"?16e3:t==="max"?128e3:t==="high"?64e3:32e3}}buildOutputConfig(e,t){if(t!==void 0)return{effort:t}}async*redactStreamErrors(e){try{for await(let t of e)yield t}catch(t){throw _e(t)}}async*processStream(e){let t,n=this.contentGeneratorConfig.model,s=0,o=0,i=0,a=0,u,l=new Map,m=[];for await(let f of e)switch(f.type){case"message_start":{t=f.message.id??t,n=f.message.model??n,s=f.message.usage?.cache_read_input_tokens??s,o=f.message.usage?.cache_creation_input_tokens??o,i=f.message.usage?.input_tokens??i;break}case"content_block_start":{let _=f.index??0,g=String(f.content_block.type||"text"),S=g==="tool_use"&&"input"in f.content_block?JSON.stringify(f.content_block.input):"";l.set(_,{type:g,id:"id"in f.content_block?f.content_block.id:void 0,name:"name"in f.content_block?f.content_block.name:void 0,inputJson:S!=="{}"?S:"",signature:g==="thinking"&&"signature"in f.content_block&&typeof f.content_block.signature=="string"?f.content_block.signature:""});break}case"content_block_delta":{let _=f.index??0,g=f.delta.type||"",S=l.get(_);if(g==="text_delta"){let y="text"in f.delta?f.delta.text:"";if(y){let M=this.buildGeminiChunk({text:y},t,n);m.push(M),yield M}}else if(g==="thinking_delta"){let y=f.delta.thinking||"";if(y){let M=this.buildGeminiChunk({text:y,thought:!0},t,n);m.push(M),yield M}}else if(g==="signature_delta"&&S){let y=f.delta.signature||"";if(y){S.signature+=y;let M=this.buildGeminiChunk({thought:!0,thoughtSignature:y},t,n);m.push(M),yield M}}else if(g==="input_json_delta"&&S){let y=f.delta.partial_json||"";y&&(S.inputJson+=y)}break}case"content_block_stop":{let _=f.index??0,g=l.get(_);if(g?.type==="tool_use"){let S=tt(g.inputJson||"{}",{}),y=this.buildGeminiChunk({functionCall:{id:g.id,name:g.name,args:S}},t,n);m.push(y),yield y}l.delete(_);break}case"message_delta":{let _=f.delta.stop_reason;_&&(u=_);let g=f.usage,S=g&&typeof g=="object"?g:void 0;if(f.usage?.output_tokens!==void 0&&(a=f.usage.output_tokens),S?.input_tokens!==void 0){let y=S.input_tokens;typeof y=="number"&&(i=y)}if(S?.cache_read_input_tokens!==void 0){let y=S.cache_read_input_tokens;typeof y=="number"&&(s=y)}if(S?.cache_creation_input_tokens!==void 0){let y=S.cache_creation_input_tokens;typeof y=="number"&&(o=y)}if(u||f.usage){let y=this.buildGeminiChunk(void 0,t,n,u,Qe({inputTokens:i,cacheReadTokens:s,cacheCreationTokens:o,outputTokens:a}));m.push(y),yield y}break}case"message_stop":{if(i||a){let _=this.buildGeminiChunk(void 0,t,n,u,Qe({inputTokens:i,cacheReadTokens:s,cacheCreationTokens:o,outputTokens:a}));m.push(_),yield _}break}default:break}}async*processStreamWithEmptyFallback(e,t,n,s){let o=!1,i=!1;for await(let u of this.processStream(e)){let l=u.candidates??[];i||=l.some(m=>m.finishReason!==void 0),o||=l.some(m=>m.content?.parts?.some(f=>f.text||f.thought||f.thoughtSignature||f.functionCall)),yield u}if(o||i)return;yn.warn("Anthropic stream ended without assistant payload or finish reason; probing once with a non-streaming request to surface provider errors.");let a;try{nt.recordAnthropicWireRequest(t),a=await this.client.messages.create(t,{signal:n,...s?{headers:s}:{}}),yield this.converter.convertAnthropicResponseToGemini(a)}catch(u){throw _e(u)}}buildGeminiChunk(e,t,n,s,o){let i=new et;i.responseId=t,i.createTime=Date.now().toString(),i.modelVersion=n||this.contentGeneratorConfig.model,i.promptFeedback={safetyRatings:[]};let a=e?[e]:[],u=s!==void 0?this.converter.mapAnthropicFinishReasonToGemini(s):void 0;return i.candidates=[{content:{parts:a,role:"model"},index:0,safetyRatings:[],...u?{finishReason:u}:{}}],o&&(i.usageMetadata=o),i}};function gc(r,e){return new Ye(r,e)}export{Ye as AnthropicContentGenerator,gc as createAnthropicContentGenerator};
25
+ `)||""}extractFunctionResponseContent(e){if(e==null)return"";if(typeof e=="string")return e;if(typeof e=="object"){let t=e,n=t.output;if(typeof n=="string")return n;let s=t.error;if(typeof s=="string")return s}try{return JSON.stringify(e)??String(e)}catch{return String(e)}}safeInputToArgs(e){return e&&typeof e=="object"?e:typeof e=="string"?tt(e,{}):{}}mapAnthropicFinishReasonToGemini(e){return e?{end_turn:Z.STOP,stop_sequence:Z.STOP,tool_use:Z.STOP,max_tokens:Z.MAX_TOKENS,content_filter:Z.SAFETY}[e]||Z.FINISH_REASON_UNSPECIFIED:void 0}isContentObject(e){return typeof e=="object"&&e!==null&&"role"in e&&"parts"in e&&Array.isArray(e.parts)}buildSystemWithCacheControl(e,t){return e&&[{type:"text",text:e,cache_control:t?{type:"ephemeral",scope:"global"}:{type:"ephemeral"}}]}stripThinkingFromAssistantMessages(e){for(let t of e){if(t.role!=="assistant"||!Array.isArray(t.content))continue;let n=t.content.filter(s=>{let o=s.type;return o!=="thinking"&&o!=="redacted_thinking"});n.length!==0&&n.length!==t.content.length&&(t.content=n)}}fillMissingThinkingSignatures(e){for(let t of e){if(t.role!=="assistant"||!Array.isArray(t.content))continue;let n=!1,s=t.content.map(o=>{let i=o;return i.type==="thinking"&&typeof i.signature!="string"?(n=!0,{...o,signature:""}):o});n&&(t.content=s)}}injectEmptyThinkingOnToolUseTurns(e){for(let t of e){if(t.role!=="assistant"||!Array.isArray(t.content))continue;let n=t.content;if(!n.some(a=>a.type==="tool_use")||n.some(a=>{let u=a.type;return u==="thinking"||u==="redacted_thinking"}))continue;let i={type:"thinking",thinking:"",signature:""};t.content=[i,...n]}}addCacheControlToMessages(e){for(let t=e.length-1;t>=0;t--){let n=e[t];if(n.role==="user"){let s=Array.isArray(n.content)?n.content:[{type:"text",text:n.content}];if(s.length>0){let o=s[s.length-1];if(typeof o=="object"&&"type"in o){let i=o.type,a=i==="text"&&(!("text"in o)||!o.text);(i==="text"||i==="tool_result")&&!a&&(o.cache_control={type:"ephemeral"})}n.content=s}break}}}};var yn=bn("ANTHROPIC");function _r(r){let e=r.baseUrl??"";if(!e)return!1;try{let t=new URL(e).hostname.toLowerCase();return t==="api.deepseek.com"||t.endsWith(".api.deepseek.com")}catch{return!1}}function vs(r){return _r(r)?!0:(r.model??"").toLowerCase().includes("deepseek")}function Is(r){let e=r.baseUrl?.trim();if(e)return e;let t=process.env.ANTHROPIC_BASE_URL?.trim();return t||"https://api.anthropic.com"}function br(r){try{let e=new URL(Is(r)).hostname.toLowerCase();return e==="api.anthropic.com"||e.endsWith(".anthropic.com")}catch{return!1}}var Ye=class{constructor(e,t){this.contentGeneratorConfig=e;this.cliConfig=t;let n=!br(e),s=this.buildHeaders(n),o=e.baseUrl,i=xn("anthropic",this.cliConfig.getProxy());this.client=new yr({...n?{authToken:e.apiKey,apiKey:null}:{apiKey:e.apiKey,authToken:null},baseURL:o,timeout:e.timeout||6e5,maxRetries:e.maxRetries,defaultHeaders:s,...i}),this.converter=new Lt(e.model,e.schemaCompliance,e.enableCacheControl)}client;converter;effortClampWarned=!1;async generateContent(e){let t;try{let n=await this.buildRequest(e);nt.recordAnthropicWireRequest(n);let s=this.buildPerRequestHeaders(n);t=await this.client.messages.create(n,{signal:e.config?.abortSignal,...s?{headers:s}:{}})}catch(n){throw _e(n)}return this.converter.convertAnthropicResponseToGemini(t)}async generateContentStream(e){let t=await this.buildRequest(e),n=this.buildPerRequestHeaders(t),s={...t,stream:!0};nt.recordAnthropicWireRequest(s);let o;try{o=await this.client.messages.create(s,{signal:e.config?.abortSignal,...n?{headers:n}:{}})}catch(i){throw _e(i)}return this.processStreamWithEmptyFallback(this.redactStreamErrors(o),t,e.config?.abortSignal,n)}async countTokens(e){try{return{totalTokens:(await new Tn().calculateTokens(e)).totalTokens}}catch(t){yn.warn("Failed to calculate tokens with tokenizer, falling back to simple method:",t);let n=JSON.stringify(e.contents);return{totalTokens:Math.ceil(n.length/4)}}}async embedContent(e){throw new Error("Anthropic does not support embeddings.")}useSummarizedThinking(){return!1}buildHeaders(e){let t=this.cliConfig.getCliVersion()||"unknown",n=e?`claude-cli/${t} (external, cli)`:`MatildaCode/${t} (${process.platform}; ${process.arch})`,{customHeaders:s}=this.contentGeneratorConfig,o={"User-Agent":n};if(e&&(o["x-app"]="cli"),s)for(let[i,a]of Object.entries(s))i.toLowerCase()==="anthropic-beta"||Cn(i)||(o[i]=a);return o}buildPerRequestHeaders(e){let t=[];for(let s of this.collectCustomBetaFlags())t.push(s);return e.thinking&&t.push("interleaved-thinking-2025-05-14"),e.output_config&&t.push("effort-2025-11-24"),this.hasGlobalCacheScopeOnWire(e)&&t.push("prompt-caching-scope-2026-01-05"),t.length===0?void 0:{"anthropic-beta":Array.from(new Set(t)).join(",")}}useGlobalCacheScope(){return this.contentGeneratorConfig.enableCacheControl!==!1&&br(this.contentGeneratorConfig)}hasGlobalCacheScopeOnWire(e){let t=n=>{if(!n||typeof n!="object")return!1;let s=n.cache_control;return!s||typeof s!="object"?!1:s.scope==="global"};if(Array.isArray(e.system)){for(let n of e.system)if(t(n))return!0}if(Array.isArray(e.tools)){for(let n of e.tools)if(t(n))return!0}return!1}collectCustomBetaFlags(){let e=this.contentGeneratorConfig.customHeaders;if(!e)return[];let t=[];for(let[n,s]of Object.entries(e))if(n.toLowerCase()==="anthropic-beta"&&!(typeof s!="string"||!s))for(let o of s.split(",")){let i=o.trim();i&&t.push(i)}return t}async buildRequest(e){let t=this.buildSamplingParameters(e),n=this.resolveEffectiveEffort(e),s=this.buildThinkingConfig(e,n),o=this.buildOutputConfig(e,n),i=vs(this.contentGeneratorConfig),a=i&&!!s,u=i&&!s,l=this.contentGeneratorConfig.enableCacheControl!==!1,m=this.useGlobalCacheScope(),f=e.config?.tools?await this.converter.convertGeminiToolsToAnthropic(e.config.tools,{enableCacheControl:l,useGlobalCacheScope:m}):void 0,_=m&&!!f&&f.length>0,g=m&&!_,{system:S,messages:y}=this.converter.convertGeminiRequestToAnthropic(e,{normalizeAssistantThinkingSignature:a,injectThinkingOnToolUseTurns:a,stripAssistantThinking:u,enableCacheControl:l,useGlobalCacheScope:g});return{model:this.contentGeneratorConfig.model,system:S,messages:y,tools:f,...t,...s?{thinking:s}:{},...o?{output_config:o}:{}}}buildSamplingParameters(e){let t=this.contentGeneratorConfig.samplingParams,n=e.config||{},s=(m,f)=>{let _=t?.[m],g=f?n[f]:void 0;return _!==void 0?_:g},o=s("max_tokens","maxOutputTokens"),i=this.contentGeneratorConfig.model,a=kn(i,"output"),u=Sn(i),l;if(o!=null)l=u?Math.min(o,a):o;else{let m=process.env.MATILDA_CODE_MAX_OUTPUT_TOKENS,f=m?parseInt(m,10):NaN;!isNaN(f)&&f>0?l=u?Math.min(f,a):f:l=Math.min(a,8e3)}return{max_tokens:l,temperature:s("temperature","temperature")??1,top_p:s("top_p","topP"),top_k:s("top_k","topK")}}resolveEffectiveEffort(e){if(e.config?.thinkingConfig?.includeThoughts===!1)return;let t=this.contentGeneratorConfig.reasoning;if(t===!1||t===void 0)return;let n=t.effort;if(n!==void 0)return n==="max"&&!_r(this.contentGeneratorConfig)?(this.effortClampWarned||(yn.warn("reasoning.effort='max' is a DeepSeek extension; clamping to 'high' for non-DeepSeek anthropic provider to avoid HTTP 400."),this.effortClampWarned=!0),"high"):n}modelSupportsAdaptiveThinking(){let t=(this.contentGeneratorConfig.model||"").toLowerCase().match(/claude-(?:opus|sonnet|haiku)-(\d+)-(\d+)/);if(!t)return!1;let n=Number.parseInt(t[1],10),s=Number.parseInt(t[2],10);return n>4||n===4&&s>=6}buildThinkingConfig(e,t){if(e.config?.thinkingConfig?.includeThoughts===!1)return;let n=this.contentGeneratorConfig.reasoning;return n===!1?void 0:n?.budget_tokens!==void 0?{type:"enabled",budget_tokens:n.budget_tokens}:this.modelSupportsAdaptiveThinking()?{type:"adaptive"}:{type:"enabled",budget_tokens:t==="low"?16e3:t==="max"?128e3:t==="high"?64e3:32e3}}buildOutputConfig(e,t){if(t!==void 0)return{effort:t}}async*redactStreamErrors(e){try{for await(let t of e)yield t}catch(t){throw _e(t)}}async*processStream(e){let t,n=this.contentGeneratorConfig.model,s=0,o=0,i=0,a=0,u,l=new Map,m=[];for await(let f of e)switch(f.type){case"message_start":{t=f.message.id??t,n=f.message.model??n,s=f.message.usage?.cache_read_input_tokens??s,o=f.message.usage?.cache_creation_input_tokens??o,i=f.message.usage?.input_tokens??i;break}case"content_block_start":{let _=f.index??0,g=String(f.content_block.type||"text"),S=g==="tool_use"&&"input"in f.content_block?JSON.stringify(f.content_block.input):"";l.set(_,{type:g,id:"id"in f.content_block?f.content_block.id:void 0,name:"name"in f.content_block?f.content_block.name:void 0,inputJson:S!=="{}"?S:"",signature:g==="thinking"&&"signature"in f.content_block&&typeof f.content_block.signature=="string"?f.content_block.signature:""});break}case"content_block_delta":{let _=f.index??0,g=f.delta.type||"",S=l.get(_);if(g==="text_delta"){let y="text"in f.delta?f.delta.text:"";if(y){let M=this.buildGeminiChunk({text:y},t,n);m.push(M),yield M}}else if(g==="thinking_delta"){let y=f.delta.thinking||"";if(y){let M=this.buildGeminiChunk({text:y,thought:!0},t,n);m.push(M),yield M}}else if(g==="signature_delta"&&S){let y=f.delta.signature||"";if(y){S.signature+=y;let M=this.buildGeminiChunk({thought:!0,thoughtSignature:y},t,n);m.push(M),yield M}}else if(g==="input_json_delta"&&S){let y=f.delta.partial_json||"";y&&(S.inputJson+=y)}break}case"content_block_stop":{let _=f.index??0,g=l.get(_);if(g?.type==="tool_use"){let S=tt(g.inputJson||"{}",{}),y=this.buildGeminiChunk({functionCall:{id:g.id,name:g.name,args:S}},t,n);m.push(y),yield y}l.delete(_);break}case"message_delta":{let _=f.delta.stop_reason;_&&(u=_);let g=f.usage,S=g&&typeof g=="object"?g:void 0;if(f.usage?.output_tokens!==void 0&&(a=f.usage.output_tokens),S?.input_tokens!==void 0){let y=S.input_tokens;typeof y=="number"&&(i=y)}if(S?.cache_read_input_tokens!==void 0){let y=S.cache_read_input_tokens;typeof y=="number"&&(s=y)}if(S?.cache_creation_input_tokens!==void 0){let y=S.cache_creation_input_tokens;typeof y=="number"&&(o=y)}if(u||f.usage){let y=this.buildGeminiChunk(void 0,t,n,u,Qe({inputTokens:i,cacheReadTokens:s,cacheCreationTokens:o,outputTokens:a}));m.push(y),yield y}break}case"message_stop":{if(i||a){let _=this.buildGeminiChunk(void 0,t,n,u,Qe({inputTokens:i,cacheReadTokens:s,cacheCreationTokens:o,outputTokens:a}));m.push(_),yield _}break}default:break}}async*processStreamWithEmptyFallback(e,t,n,s){let o=!1,i=!1;for await(let u of this.processStream(e)){let l=u.candidates??[];i||=l.some(m=>m.finishReason!==void 0),o||=l.some(m=>m.content?.parts?.some(f=>f.text||f.thought||f.thoughtSignature||f.functionCall)),yield u}if(o||i)return;yn.warn("Anthropic stream ended without assistant payload or finish reason; probing once with a non-streaming request to surface provider errors.");let a;try{nt.recordAnthropicWireRequest(t),a=await this.client.messages.create(t,{signal:n,...s?{headers:s}:{}}),yield this.converter.convertAnthropicResponseToGemini(a)}catch(u){throw _e(u)}}buildGeminiChunk(e,t,n,s,o){let i=new et;i.responseId=t,i.createTime=Date.now().toString(),i.modelVersion=n||this.contentGeneratorConfig.model,i.promptFeedback={safetyRatings:[]};let a=e?[e]:[],u=s!==void 0?this.converter.mapAnthropicFinishReasonToGemini(s):void 0;return i.candidates=[{content:{parts:a,role:"model"},index:0,safetyRatings:[],...u?{finishReason:u}:{}}],o&&(i.usageMetadata=o),i}};function gc(r,e){return new Ye(r,e)}export{Ye as AnthropicContentGenerator,gc as createAnthropicContentGenerator};
26
26
  /**
27
27
  * @license
28
28
  * Copyright 2025 Matilda
@@ -0,0 +1,8 @@
1
+ // Force strict mode and setup for ESM
2
+ "use strict";
3
+ import{b as n}from"./chunk-GZPNIYVZ.js";n();var m="MATILDA_API_KEY";var g="matilda-code-1.0",_="Matilda",u="https://matilda.maincode.com/api/v1/code";var f={id:"matilda",label:"Matilda",description:"Connect to the Matilda Core code API endpoint",protocol:"openai",baseUrl:u,envKey:m,models:[{id:g,displayName:_,contextWindowSize:1048576,description:"Matilda Code model",generationConfig:{openAIRequestProfile:"matilda-code",timeout:6e5,samplingParams:{max_tokens:65536,chat_template_kwargs:{enable_thinking:!0}},schemaCompliance:"openapi_30",splitToolMedia:!0,customHeaders:{"User-Agent":"MatildaCode/0.1"}}}],modelNamePrefix:"",documentationUrl:"https://matilda.maincode.help/welcome/external-api",uiGroup:"third-party"};function h(a){return a.trim().replace(/\/+$/,"").replace(/\/api\/v1(?:\/code)?$/i,"")}async function E(a){let{baseUrl:i,email:s,password:d,signal:l}=a,r=h(i),p=`${r}/api/auth/login`,t;try{t=await fetch(p,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({email:s,password:d}),signal:l})}catch(o){let c=o instanceof Error?o.message:String(o);throw new Error(`Could not reach Matilda at ${r}: ${c}`)}if(t.status===401)throw new Error("Invalid email or password.");if(!t.ok)throw new Error(`Matilda sign-in failed (HTTP ${t.status}). Please try again.`);let e;try{e=await t.json()}catch{throw new Error("Matilda sign-in returned an unreadable response.")}if(!e||typeof e.token!="string"||e.token.length===0)throw new Error("Matilda sign-in did not return a token.");return{token:e.token,refreshToken:typeof e.refreshToken=="string"?e.refreshToken:void 0,userId:typeof e.userId=="string"?e.userId:void 0,email:typeof e.email=="string"?e.email:void 0,displayName:typeof e.displayName=="string"?e.displayName:void 0}}export{m as a,u as b,f as c,h as d,E as e};
4
+ /**
5
+ * @license
6
+ * Copyright 2026 Matilda Team
7
+ * SPDX-License-Identifier: Apache-2.0
8
+ */
@@ -1,6 +1,6 @@
1
1
  // Force strict mode and setup for ESM
2
2
  "use strict";
3
- import{bh as T}from"./chunk-OREAJC5D.js";import{L as b}from"./chunk-QWBNNEV2.js";import{b as o}from"./chunk-GZPNIYVZ.js";import{b as w}from"./chunk-OWGSC52X.js";o();var W=e=>{process.stdout.write(e.endsWith(`
3
+ import{bh as T}from"./chunk-HUPUKBVY.js";import{L as b}from"./chunk-QWBNNEV2.js";import{b as o}from"./chunk-GZPNIYVZ.js";import{b as w}from"./chunk-OWGSC52X.js";o();var W=e=>{process.stdout.write(e.endsWith(`
4
4
  `)?e:`${e}
5
5
  `)},m=e=>{process.stderr.write(e.endsWith(`
6
6
  `)?e:`${e}