blade-code 0.6.4 → 0.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/blade.js +2 -2
- package/dist/{chunk-j7nh0j36.js → chunk-0afbeec0.js} +1 -1
- package/dist/chunk-0k8js58t.js +6 -0
- package/dist/chunk-0vd9antx.js +1 -0
- package/dist/{chunk-w96xaeyd.js → chunk-1dt2y16n.js} +1 -1
- package/dist/{chunk-jm9r362m.js → chunk-2dvn9y9f.js} +1 -1
- package/dist/{chunk-hc91pmdk.js → chunk-56frm8dx.js} +1 -1
- package/dist/chunk-6jezjq4h.js +6 -0
- package/dist/chunk-6k4vs71p.js +1 -0
- package/dist/chunk-70ya127f.js +1 -0
- package/dist/{chunk-sfr69fw8.js → chunk-7v7s2aag.js} +2 -2
- package/dist/{chunk-nm2w2ftg.js → chunk-7z6ba6t9.js} +1 -1
- package/dist/{chunk-m41xq6d0.js → chunk-867h27ke.js} +4 -4
- package/dist/chunk-92qcc3gj.js +2138 -0
- package/dist/{chunk-ck43cs45.js → chunk-a2nshjdc.js} +2 -2
- package/dist/chunk-a7dw8fwn.js +1 -0
- package/dist/chunk-a8eedntd.js +6 -0
- package/dist/{chunk-59e6eg4b.js → chunk-aam53te2.js} +6 -6
- package/dist/{chunk-evc1xkeb.js → chunk-b0q2q0ax.js} +1 -1
- package/dist/{chunk-ey640ttd.js → chunk-bmxgshct.js} +1 -1
- package/dist/chunk-d3db8wrw.js +1 -0
- package/dist/chunk-dzmrdtpc.js +612 -0
- package/dist/chunk-e06p3dkw.js +157 -0
- package/dist/{chunk-f24ahjpc.js → chunk-f76d6jxg.js} +1 -1
- package/dist/chunk-f8mjpmdx.js +4 -0
- package/dist/chunk-h7qab07x.js +2 -0
- package/dist/{chunk-h46kk20y.js → chunk-k9h9bw13.js} +2 -2
- package/dist/chunk-m51xzgwt.js +1 -0
- package/dist/{chunk-bpx8x87m.js → chunk-mt1c5da4.js} +2 -2
- package/dist/chunk-qdnx9x5g.js +2 -0
- package/dist/chunk-qds0yxfy.js +41 -0
- package/dist/chunk-qyfdt8h1.js +2 -0
- package/dist/chunk-r6paqm6d.js +1 -0
- package/dist/chunk-v0rjbvky.js +9 -0
- package/dist/{chunk-cfe1fywb.js → chunk-v1d0d4b4.js} +2 -2
- package/dist/chunk-vs915jzz.js +1 -0
- package/dist/chunk-xmdpc0y5.js +2 -0
- package/dist/chunk-zbtb3jxm.js +1 -0
- package/dist/{chunk-sh1pk5j3.js → chunk-zm4jr1k2.js} +1 -1
- package/dist/chunk-zvk6ktj1.js +6 -0
- package/dist/{chunk-m26jr2tg.js → chunk-zxddgwsb.js} +1 -1
- package/dist/web/assets/{FilePreview-R1mRzyRz.js → FilePreview-DLnUh-wQ.js} +1 -1
- package/dist/web/assets/{MarkdownRenderer-B46lJYAn.js → MarkdownRenderer-C5KTk9XG.js} +1 -1
- package/dist/web/assets/{McpModal-QRv5Ij61.js → McpModal-B9qJ4ewt.js} +1 -1
- package/dist/web/assets/{SettingsModal-D-mi6mUR.js → SettingsModal-DpeZ6cJb.js} +1 -1
- package/dist/web/assets/{SettingsStore-Dmo3sZ_R.js → SettingsStore-IzKtyAnM.js} +1 -1
- package/dist/web/assets/{SkillsModal-DNXjbjEs.js → SkillsModal-BDfzgJIj.js} +1 -1
- package/dist/web/assets/{TerminalPanel-DG_Q4UKr.js → TerminalPanel-B2iTF_CR.js} +1 -1
- package/dist/web/assets/{dialog-CsiChiYt.js → dialog-sI3ihAze.js} +1 -1
- package/dist/web/assets/{index-BeYCsOvo.js → index-D8mo0jzF.js} +8 -8
- package/dist/web/index.html +1 -1
- package/package.json +4 -2
- package/dist/chunk-07xv0cqp.js +0 -1
- package/dist/chunk-0e9dhemy.js +0 -41
- package/dist/chunk-2zk921d9.js +0 -1
- package/dist/chunk-3mmm8g84.js +0 -1
- package/dist/chunk-5bs94pb1.js +0 -157
- package/dist/chunk-6mfmy7nq.js +0 -8
- package/dist/chunk-7c9k2c9m.js +0 -1
- package/dist/chunk-7t23swne.js +0 -2125
- package/dist/chunk-9p4fe43p.js +0 -1
- package/dist/chunk-9vsbmtqj.js +0 -1
- package/dist/chunk-dmc5gf4f.js +0 -6
- package/dist/chunk-k063tt5h.js +0 -1
- package/dist/chunk-mpn4zfcn.js +0 -6
- package/dist/chunk-njq4w631.js +0 -613
- package/dist/chunk-p8pggabj.js +0 -2
- package/dist/chunk-qnvkxpkw.js +0 -2
- package/dist/chunk-tdarh4fh.js +0 -1
- package/dist/chunk-tz44akn7.js +0 -6
- package/dist/chunk-vxgexcsm.js +0 -1
- package/dist/chunk-zm78rg9t.js +0 -6
- package/dist/chunk-zwwvv85t.js +0 -4
package/dist/chunk-6mfmy7nq.js
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import{Hb as S}from"./chunk-bpx8x87m.js";var f=["anthropic","openai","deepseek","google-generative-ai","groq","openrouter"],u={anthropic:"",openai:"","google-generative-ai":"",deepseek:"",groq:"",openrouter:"",azure:"",ollama:"",together:"",fireworks:"",mistral:"",cohere:"",perplexity:"",xai:"",default:""},c={anthropic:"https://api.anthropic.com",openai:"https://api.openai.com/v1",google:"https://generativelanguage.googleapis.com/v1beta",deepseek:"https://api.deepseek.com/v1",groq:"https://api.groq.com/openai/v1",openrouter:"https://openrouter.ai/api/v1",togetherai:"https://api.together.xyz/v1","fireworks-ai":"https://api.fireworks.ai/inference/v1",mistral:"https://api.mistral.ai/v1",cohere:"https://api.cohere.ai/v1",perplexity:"https://api.perplexity.ai",xai:"https://api.x.ai/v1",cerebras:"https://api.cerebras.ai/v1","novita-ai":"https://api.novita.ai/v3/openai",nvidia:"https://integrate.api.nvidia.com/v1"},T={anthropic:{"anthropic-beta":"claude-code-20250219,interleaved-thinking-2025-05-14,fine-grained-tool-streaming-2025-05-14"},openrouter:{"HTTP-Referer":"https://github.com/anthropics/blade","X-Title":"Blade"},cerebras:{"X-Cerebras-3rd-Party-Integration":"blade"},vercel:{"http-referer":"https://github.com/anthropics/blade","x-title":"blade"},zenmux:{"HTTP-Referer":"https://github.com/anthropics/blade","X-Title":"blade"}},H=(Q)=>{return T[Q]||{}};import{createAnthropic as I}from"@ai-sdk/anthropic";import{createAzure as K}from"@ai-sdk/azure";import{createDeepSeek as A}from"@ai-sdk/deepseek";import{createGoogleGenerativeAI as E}from"@ai-sdk/google";import{createOpenAI as y}from"@ai-sdk/openai";import{createOpenAICompatible as V}from"@ai-sdk/openai-compatible";import{generateText as U,jsonSchema as x,streamText as M}from"ai";var j=S("Chat");function O(Q){let q=new Set;for(let X of Q)if(X.role==="assistant"&&X.tool_calls)for(let W of X.tool_calls)q.add(W.id);return Q.filter((X)=>{if(X.role==="tool"){if(!X.tool_call_id)return!1;return q.has(X.tool_call_id)}return!0})}function L(Q){if(typeof Q==="string")return Q;return Q.filter((q)=>q.type==="text").map((q)=>q.text).join(`
|
|
2
|
-
`)}function h(Q){let q=Q;return q.text??q.textDelta??q.delta}function C(Q,q={}){try{return JSON.parse(Q)}catch{return j.warn("[VercelAIChatService] Failed to parse JSON, using fallback",{str:Q}),q}}class R{model;config;constructor(Q){this.config=Q,this.model=this.createModel(Q),j.debug("[VercelAIChatService] Initialized",{provider:Q.provider,model:Q.model})}createModel(Q){let{provider:q,apiKey:X,baseUrl:W,model:Y,customHeaders:Z,apiVersion:J}=Q;switch(q){case"openai":return y({apiKey:X,baseURL:W||void 0,headers:Z})(Y);case"anthropic":return I({apiKey:X,baseURL:W||void 0,headers:Z})(Y);case"gemini":{if(W&&!this.isGeminiOfficialUrl(W))return V({name:"gemini",apiKey:X,baseURL:W,headers:Z})(Y);return E({apiKey:X,baseURL:W||void 0})(Y)}case"google":case"google-generative-ai":case"google-vertex":{if(W&&!this.isGeminiOfficialUrl(W))return V({name:q,apiKey:X,baseURL:W,headers:Z})(Y);return E({apiKey:X,baseURL:W||void 0})(Y)}case"azure-openai":{let $=this.extractAzureResourceName(W);if($)return K({apiKey:X,resourceName:$,apiVersion:J||"2024-08-01-preview"})(Y);let _=this.buildAzureBaseUrl(W,Y);return V({name:"azure-openai",apiKey:X,baseURL:_,headers:{...Z,"api-key":X},queryParams:{"api-version":J||"2024-08-01-preview"}})(Y)}case"azure":{let $=this.extractAzureResourceName(W);if($)return K({apiKey:X,resourceName:$,apiVersion:J||"2024-08-01-preview"})(Y);let _=this.buildAzureBaseUrl(W,Y);return V({name:"azure-openai",apiKey:X,baseURL:_,headers:{...Z,"api-key":X},queryParams:{"api-version":J||"2024-08-01-preview"}})(Y)}case"deepseek":return A({apiKey:X,baseURL:W||void 0,headers:Z})(Y);default:return V({name:q,apiKey:X,baseURL:W,headers:Z})(Y)}}extractAzureResourceName(Q){if(!Q)return;let q=Q.match(/https:\/\/([^.]+)\.openai\.azure(?:\.com|\.us|\.cn|\.de)/);return q?q[1]:void 0}buildAzureBaseUrl(Q,q){if(!Q)return"";let X=Q.replace(/\/$/,"").replace(/\?.*$/,"");if(X.includes("/openai/deployments/"))return X;return`${X}/openai/deployments/${q}`}isGeminiOfficialUrl(Q){return Q.includes("generativelanguage.googleapis.com")||Q.includes("aiplatform.googleapis.com")}needsThinkingReplayMetadata(){return/deepseek/i.test([this.config.provider,this.config.model,this.config.baseUrl].join(" "))}getThinkingReplayProviderOptions(Q){let q=Q?.trim();if(!q||!this.needsThinkingReplayMetadata())return;return{openaiCompatible:{reasoning_content:q}}}shouldFlattenDeepSeekThinkingToolHistory(){return this.needsThinkingReplayMetadata()}flattenDeepSeekThinkingToolHistory(Q){let q=[],X,W=()=>{if(!X)return;q.push({role:"assistant",content:L(X.content).trim()||"I will use the requested tool and continue from its result."}),X=void 0};for(let Y of Q){if(Y.role==="system"){W(),q.push({role:"user",content:`<system>
|
|
3
|
-
${L(Y.content)}
|
|
4
|
-
</system>`});continue}if(Y.role==="assistant"&&Y.tool_calls&&Y.tool_calls.length>0&&Y.reasoningContent?.trim()){W(),X=Y;continue}if(Y.role==="tool"&&X){let Z=X.tool_calls?.find(($)=>$.id===Y.tool_call_id),J=Z?.type==="function"?Z.function:void 0;q.push({role:"user",content:`Tool result for ${Y.name||J?.name||"tool"}${J?.arguments?`(${J.arguments})`:""}:
|
|
5
|
-
${L(Y.content)}
|
|
6
|
-
|
|
7
|
-
Continue from this tool result.`});continue}W(),q.push(Y)}return W(),q}convertMessages(Q){let q=[],X=this.shouldFlattenDeepSeekThinkingToolHistory()?this.flattenDeepSeekThinkingToolHistory(Q):Q;for(let W of X)if(W.role==="system")if(Array.isArray(W.content)){let Y=W.content.find((J)=>J.type==="text"),Z={role:"system",content:L(W.content)};if(Y?.providerOptions)Z.providerOptions=Y.providerOptions;q.push(Z)}else q.push({role:"system",content:W.content});else if(W.role==="user")if(Array.isArray(W.content)){let Y=W.content.map((Z)=>{if(Z.type==="text"){let J={type:"text",text:Z.text};if(Z.providerOptions)J.providerOptions=Z.providerOptions;return J}return{type:"image",image:Z.image_url.url}});q.push({role:"user",content:Y})}else q.push({role:"user",content:W.content});else if(W.role==="assistant")if(W.tool_calls&&W.tool_calls.length>0){let Y=W.tool_calls.map((_)=>{let w=_.function;return{type:"tool-call",toolCallId:_.id,toolName:w?.name||"",input:C(w?.arguments||"{}",{})}}),Z=L(W.content),J=W.reasoningContent?.trim()?[{type:"reasoning",text:W.reasoningContent}]:[],$=this.getThinkingReplayProviderOptions(W.reasoningContent);if(Z){let _={role:"assistant",content:[...J,{type:"text",text:Z},...Y]};if($)_.providerOptions=$;q.push(_)}else if(J.length>0){let _={role:"assistant",content:[...J,...Y]};if($)_.providerOptions=$;q.push(_)}else q.push({role:"assistant",content:Y})}else if(W.reasoningContent?.trim()){let Y=L(W.content),Z=[{type:"reasoning",text:W.reasoningContent}];if(Y)Z.push({type:"text",text:Y});let J={role:"assistant",content:Z},$=this.getThinkingReplayProviderOptions(W.reasoningContent);if($)J.providerOptions=$;q.push(J)}else q.push({role:"assistant",content:L(W.content)});else if(W.role==="tool")q.push({role:"tool",content:[{type:"tool-result",toolCallId:W.tool_call_id,toolName:W.name||"unknown",output:{type:"text",value:L(W.content)}}]});if(this.config.enablePromptCaching&&this.config.provider==="anthropic"){let W=0;for(let Y of q)if(Y.role==="system"&&W<2)Y.providerOptions={anthropic:{cacheControl:{type:"ephemeral"}}},W++;for(let Y=q.length-1;Y>=0;Y--)if(q[Y].role==="user"){q[Y].providerOptions={anthropic:{cacheControl:{type:"ephemeral"}}};break}}return q}convertTools(Q){if(!Q||Q.length===0)return;let q={};for(let X of Q)q[X.name]={description:X.description,inputSchema:x(X.parameters)};return q}convertToolCalls(Q){return Q.map((q)=>({id:q.toolCallId,type:"function",function:{name:q.toolName,arguments:JSON.stringify(q.args??q.input??{})}}))}convertUsage(Q,q){if(!Q)return;let X=Q.promptTokens??Q.inputTokens??0,W=Q.completionTokens??Q.outputTokens??0,Y={promptTokens:X,completionTokens:W,totalTokens:Q.totalTokens??X+W};if(Q.reasoningTokens)Y.reasoningTokens=Q.reasoningTokens;if(q?.anthropic){if(q.anthropic.cacheCreationInputTokens!==void 0)Y.cacheCreationInputTokens=q.anthropic.cacheCreationInputTokens;if(q.anthropic.cacheReadInputTokens!==void 0)Y.cacheReadInputTokens=q.anthropic.cacheReadInputTokens}return Y}isFallbackableError(Q){if(!(Q instanceof Error))return!1;let q=Q.message.toLowerCase();if(q.includes("timeout")||q.includes("econnrefused")||q.includes("enotfound"))return!0;let X=q.match(/status[:\s]*(\d{3})/),W=X?parseInt(X[1],10):Q.status;return W!==void 0&&[429,529,503,502,500].includes(W)}async retryWithBackoff(Q,q,X=2,W=1000){let Y;for(let Z=0;Z<=X;Z++)try{return await Q()}catch(J){if(Y=J,Z>=X)break;if(!this.isFallbackableError(J))throw J;if(q?.aborted)throw J;let $=W*Math.pow(2,Z);j.debug(`[VercelAIChatService] Retry ${Z+1}/${X} after ${$}ms`),await new Promise((_)=>setTimeout(_,$))}throw Y}getFallbackModelIds(){let Q=[];if(this.config.fallbackModels&&this.config.fallbackModels.length>0)Q.push(...this.config.fallbackModels);else if(this.config.fallbackModel)Q.push(this.config.fallbackModel);return Q}getThinkingProviderOptions(){if(!this.config.supportsThinking)return;let Q=this.config.thinkingMode??"budget";if(Q==="off")return;let q=Q==="adaptive",X=this.config.thinkingBudget??1e4;if(this.config.provider==="anthropic")return{anthropic:{thinking:q?{type:"enabled",budgetTokens:0}:{type:"enabled",budgetTokens:X}}};if(this.config.provider==="deepseek"||/deepseek/i.test(this.config.model))return{deepseek:{thinking:q?{type:"enabled",budgetTokens:0}:{type:"enabled",budgetTokens:X}}};return}getStreamTextOptions(Q,q,X,W){let Y=W;if(this.config.timeout&&this.config.timeout>0){let $=AbortSignal.timeout(this.config.timeout);if(W)Y=AbortSignal.any([W,$]);else Y=$}let Z={model:Q,messages:q,tools:X,maxOutputTokens:this.config.maxOutputTokens,temperature:this.config.temperature??0,abortSignal:Y,allowSystemInMessages:!0},J=this.getThinkingProviderOptions();if(J)Z.providerOptions=J;return Z}async chat(Q,q,X){let W=Date.now();j.debug("[VercelAIChatService] Starting chat request");let Y=O(Q),Z=this.convertMessages(Y),J=this.convertTools(q),$=async(_)=>{let w=await U(this.getStreamTextOptions(_,Z,J,X)),N=w.toolCalls&&w.toolCalls.length>0?this.convertToolCalls(w.toolCalls):void 0,z=Array.isArray(w.reasoning)?w.reasoning.map((B)=>B.text).join(""):void 0;return{content:w.text,reasoningContent:z,toolCalls:N,usage:this.convertUsage(w.usage,w.providerMetadata),finishReason:w.finishReason}};try{return await this.retryWithBackoff(()=>$(this.model),X,this.config.maxRetries)}catch(_){let w=Date.now()-W;if(j.error("[VercelAIChatService] Chat failed after",w,"ms"),!this.isFallbackableError(_))throw _;let N=this.getFallbackModelIds();if(N.length===0)throw _;for(let z of N){j.warn(`[VercelAIChatService] Trying fallback model: ${z}`);let B=this.createModel({...this.config,model:z});try{return await $(B)}catch(F){if(j.warn(`[VercelAIChatService] Fallback ${z} failed: ${F instanceof Error?F.message:F}`),!this.isFallbackableError(F))throw F}}throw _}}async*streamChat(Q,q,X){let W=Date.now();j.debug("[VercelAIChatService] Starting stream request");let Y=O(Q),Z=this.convertMessages(Y),J=this.convertTools(q),$=async function*(B,F){let D=M(B.getStreamTextOptions(F,Z,J,X)),P=0;for await(let G of D.fullStream)switch(G.type){case"text-delta":yield{content:h(G)};break;case"reasoning-delta":yield{reasoningContent:h(G)};break;case"tool-call":yield{toolCalls:[{index:P++,id:G.toolCallId,type:"function",function:{name:G.toolName,arguments:JSON.stringify(G.args??G.input??{})}}]};break;case"finish":yield{finishReason:G.finishReason,usage:B.convertUsage(G.totalUsage,G.providerMetadata)};break}},_=this.config.maxRetries??2,w;for(let B=0;B<=_;B++)try{yield*$(this,this.model);let F=Date.now()-W;j.debug("[VercelAIChatService] Stream completed in",F,"ms");return}catch(F){if(w=F,!this.isFallbackableError(F))throw F;if(B<_){let D=1000*Math.pow(2,B);j.debug(`[VercelAIChatService] Stream retry ${B+1}/${_} after ${D}ms`),await new Promise((P)=>setTimeout(P,D));continue}}let N=Date.now()-W;j.error("[VercelAIChatService] Stream failed after",N,"ms");let z=this.getFallbackModelIds();if(z.length===0)throw w;for(let B of z){j.warn(`[VercelAIChatService] Stream fallback: ${B}`),yield{modelFallback:!0};let F=this.createModel({...this.config,model:B});try{yield*$(this,F);return}catch(D){if(j.warn(`[VercelAIChatService] Stream fallback ${B} failed`),!this.isFallbackableError(D))throw D}}throw w}getConfig(){return{...this.config}}updateConfig(Q){j.debug("[VercelAIChatService] Updating configuration"),this.config={...this.config,...Q},this.model=this.createModel(this.config),j.debug("[VercelAIChatService] Configuration updated")}}var v=S("Service");async function qq(Q){let q=Q;if(q.provider){let X=H(q.provider);if(Object.keys(X).length>0)q={...q,customHeaders:{...X,...q.customHeaders}},v.debug(`Injected ${q.provider} specific headers:`,Object.keys(X))}return b(q)}function b(Q){return new R(Q)}
|
|
8
|
-
export{f as ob,u as pb,c as qb,qq as rb};
|
package/dist/chunk-7c9k2c9m.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{g as a,h as b,i as c,j as d,k as e}from"./chunk-sfr69fw8.js";import"./chunk-j7nh0j36.js";export{b as setSkipUntilVersion,d as performUpgrade,c as getUpgradeCommand,e as checkVersionOnStartup,a as checkVersion};
|