blade-code 0.10.28 → 0.10.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/blade.js +2 -2
- package/dist/{chunk-0pbvrw1c.js → chunk-0prp87ys.js} +1 -1
- package/dist/{chunk-6vfctcqp.js → chunk-0rwz7tm0.js} +1 -1
- package/dist/{chunk-axcaxcgk.js → chunk-1444wfhr.js} +2 -2
- package/dist/{chunk-2ycs4wce.js → chunk-1ggxyyar.js} +1 -1
- package/dist/{chunk-4y6pjd2n.js → chunk-1sswefqp.js} +2 -2
- package/dist/{chunk-t0n90d7w.js → chunk-1zpqxjj7.js} +2 -2
- package/dist/{chunk-stmsk0kz.js → chunk-2d35rmyg.js} +2 -2
- package/dist/chunk-2wdmt91f.js +1 -0
- package/dist/{chunk-0pcwv1h8.js → chunk-37se34rx.js} +1 -1
- package/dist/{chunk-yv2sdpxk.js → chunk-39gb49pv.js} +1 -1
- package/dist/chunk-3y97cpzv.js +1 -0
- package/dist/{chunk-287fabvz.js → chunk-48tz6s0s.js} +2 -2
- package/dist/{chunk-jvtzyba4.js → chunk-4djps7bz.js} +1 -1
- package/dist/{chunk-j9djsqqy.js → chunk-4p9cwr9s.js} +2 -2
- package/dist/{chunk-hbhcj665.js → chunk-4qtb8yf6.js} +2 -2
- package/dist/{chunk-k3wmp1xm.js → chunk-4qyhtrhx.js} +1 -1
- package/dist/chunk-56hphybe.js +1 -0
- package/dist/{chunk-69r9j0ms.js → chunk-5m5nxkfs.js} +1 -1
- package/dist/{chunk-1e9cpchh.js → chunk-64hndcnj.js} +41 -41
- package/dist/{chunk-d6a4qw1m.js → chunk-6h9d9ykg.js} +1 -1
- package/dist/{chunk-sh2kjand.js → chunk-6kc12pma.js} +1 -1
- package/dist/chunk-7brnbdq8.js +10 -0
- package/dist/{chunk-q4fy74fz.js → chunk-7e7zgzag.js} +2 -2
- package/dist/{chunk-9ev9k5bd.js → chunk-82jdnt03.js} +2 -2
- package/dist/{chunk-0xhd2mzm.js → chunk-8gv6hsrf.js} +2 -2
- package/dist/{chunk-tct2ybbh.js → chunk-9mamc250.js} +2 -2
- package/dist/{chunk-1ycv8b9t.js → chunk-9pww3s5m.js} +1 -1
- package/dist/chunk-a5yd0c77.js +1 -0
- package/dist/{chunk-wn60hv0w.js → chunk-b634n0ts.js} +199 -199
- package/dist/{chunk-a1a4351m.js → chunk-btfxa4w8.js} +2 -2
- package/dist/chunk-d38t0wa2.js +6 -0
- package/dist/{chunk-5wkv5g4v.js → chunk-d4327k1v.js} +1 -1
- package/dist/{chunk-djzy4zgc.js → chunk-d9gthet1.js} +2 -2
- package/dist/chunk-e269454y.js +1 -0
- package/dist/{chunk-sjbqm4be.js → chunk-e3qzedvj.js} +2 -2
- package/dist/{chunk-dny4h2gz.js → chunk-ej1z75jf.js} +1 -1
- package/dist/{chunk-p4hf7agx.js → chunk-ekv4hpy8.js} +2 -2
- package/dist/chunk-f90v5vza.js +1 -0
- package/dist/{chunk-dx5996qr.js → chunk-fr3kysfm.js} +1 -1
- package/dist/{chunk-xqapcfw3.js → chunk-gdp6fg4e.js} +1 -1
- package/dist/{chunk-a1ftc84p.js → chunk-h9c7xec5.js} +2 -2
- package/dist/{chunk-6qdwp1t3.js → chunk-hdr8bcxt.js} +1 -1
- package/dist/{chunk-rqvejn8x.js → chunk-heydawsf.js} +2 -2
- package/dist/chunk-j3k3xdac.js +1 -0
- package/dist/{chunk-gpa4y0xk.js → chunk-j7ebts5c.js} +1 -1
- package/dist/{chunk-gbmnbckj.js → chunk-kk071ywk.js} +2 -2
- package/dist/{chunk-cbyewxx4.js → chunk-kkpxmhjv.js} +3 -3
- package/dist/chunk-m3epqvpc.js +1 -0
- package/dist/{chunk-rf3jf275.js → chunk-m8jen593.js} +3 -3
- package/dist/{chunk-8djaj8m7.js → chunk-mbrgz77y.js} +2 -2
- package/dist/chunk-n1byt26d.js +4 -0
- package/dist/{chunk-ecvk8npm.js → chunk-p6s92zj1.js} +1 -1
- package/dist/chunk-pdkj959x.js +1 -0
- package/dist/chunk-pwwm04bc.js +1 -0
- package/dist/chunk-q9ghq6jw.js +204 -0
- package/dist/chunk-qs9wwe8d.js +9 -0
- package/dist/chunk-qv1v32ts.js +22 -0
- package/dist/{chunk-x3dche8v.js → chunk-rezjy4mp.js} +2 -2
- package/dist/{chunk-78bknnzt.js → chunk-rh5g6em4.js} +2 -2
- package/dist/{chunk-70kccy7a.js → chunk-s3zfyy7r.js} +1 -1
- package/dist/chunk-s6rdv601.js +2 -0
- package/dist/chunk-szmm21q9.js +1 -0
- package/dist/{chunk-2gre3vrn.js → chunk-vx8a7e1j.js} +2 -2
- package/dist/{chunk-tdevyej4.js → chunk-vz0zsct0.js} +1 -1
- package/dist/chunk-x96czg8t.js +1 -0
- package/dist/{chunk-p2j0wcca.js → chunk-x9940mcy.js} +2 -2
- package/dist/chunk-xh2c6ycd.js +1 -0
- package/dist/{chunk-taj3qfn3.js → chunk-xr033fd3.js} +1 -1
- package/dist/{chunk-ae7f5mh9.js → chunk-z5eaph4a.js} +1 -1
- package/dist/chunk-ze8rmhs1.js +1 -0
- package/dist/web/assets/{ChatView-BtSSERlQ.js → ChatView-CjEyCR8V.js} +3 -3
- package/dist/web/assets/{CodeBlockHighlighter-CAuanOO0.js → CodeBlockHighlighter-DZxXrhQO.js} +1 -1
- package/dist/web/assets/{FilePreview-BKQ-EBj3.js → FilePreview-8fbolCzV.js} +1 -1
- package/dist/web/assets/{MarkdownRenderer-BdYjJ_NM.js → MarkdownRenderer-Bfm5TG2z.js} +3 -3
- package/dist/web/assets/{SettingsModal-CB6hM8fT.js → SettingsModal-KATzS3Iy.js} +1 -1
- package/dist/web/assets/{TaskSwitcher-sSD4B7C_.js → TaskSwitcher-BrfN6F0-.js} +1 -1
- package/dist/web/assets/{TerminalPanel-ZnEoQU6o.js → TerminalPanel-sbqhmFcK.js} +1 -1
- package/dist/web/assets/{index-DtOztVFd.js → index-xB4mFHWl.js} +3 -3
- package/dist/web/index.html +1 -1
- package/package.json +1 -1
- package/dist/chunk-03633tsz.js +0 -10
- package/dist/chunk-1kxz32m6.js +0 -1
- package/dist/chunk-1sregjyz.js +0 -1
- package/dist/chunk-2byq2qja.js +0 -1
- package/dist/chunk-3t5gqr9e.js +0 -1
- package/dist/chunk-6znn1a5v.js +0 -1
- package/dist/chunk-7hjz5jjn.js +0 -9
- package/dist/chunk-8k9ark1n.js +0 -1
- package/dist/chunk-98rbxm1y.js +0 -22
- package/dist/chunk-apq6qqjg.js +0 -204
- package/dist/chunk-br9230a2.js +0 -2
- package/dist/chunk-hb9yjfja.js +0 -1
- package/dist/chunk-jk66yar2.js +0 -1
- package/dist/chunk-k52a3bq6.js +0 -1
- package/dist/chunk-n1qmwjmc.js +0 -1
- package/dist/chunk-p2yb40zk.js +0 -4
- package/dist/chunk-qewf02br.js +0 -1
- package/dist/chunk-qsj712zc.js +0 -1
- package/dist/chunk-ry7226b5.js +0 -6
- package/dist/chunk-x1a5wv45.js +0 -1
- package/dist/chunk-z516a7nx.js +0 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{Ef as R}from"./chunk-ekv4hpy8.js";import{If as q,Kf as _}from"./chunk-8gv6hsrf.js";import{Nf as K}from"./chunk-5m5nxkfs.js";var ie={openrouter:{"HTTP-Referer":"https://github.com/echoVic/blade-code","X-Title":"Blade"},cerebras:{"X-Cerebras-3rd-Party-Integration":"blade"}},N=(e)=>ie[e]||{};var se=new Set(["user-cancel","interrupt","sibling-error","timeout"]);function A(e){return typeof e==="string"&&se.has(e)}function Ne(e){if(!e.aborted)return;if(A(e.reason))return e.reason;return"user-cancel"}function je(e){if(A(e))return!0;if(!(e instanceof Error))return!1;if(e.name==="AbortError")return!0;if(e instanceof DOMException&&e.name==="AbortError")return!0;if(e.message.includes("aborted"))return!0;return!1}function U(...e){let t=e.filter(Boolean);if(t.length===0)return new AbortController().signal;if(t.length===1)return t[0];let o=AbortSignal;if(typeof o.any==="function")return o.any(t);for(let i of t)if(i.aborted)return i;let r=new AbortController,n=new Map;for(let i of t){let a=()=>{r.abort(i.reason);for(let[u,s]of n)u.removeEventListener("abort",s)};n.set(i,a)}for(let[i,a]of n)i.addEventListener("abort",a,{once:!0});return r.signal}function P(e,t,o){let r=o?.throwOnAbort??!1;if(t?.aborted){if(r)return Promise.reject(new DOMException("Aborted","AbortError"));return Promise.resolve()}return new Promise((n,i)=>{let a,u=setTimeout(()=>{if(t&&a)t.removeEventListener("abort",a);n()},e);if(t)a=()=>{if(clearTimeout(u),r)i(new DOMException("Aborted","AbortError"));else n()},t.addEventListener("abort",a,{once:!0})})}var ae=R("Chat"),ue={input:0,output:0,cacheRead:0,cacheWrite:0,totalTokens:0,cost:{input:0,output:0,cacheRead:0,cacheWrite:0,total:0}};function E(e){if(typeof e==="string")return e;return e.filter((t)=>t.type==="text").map((t)=>t.text).join(`
|
|
2
2
|
`)}function de(e){if(!e)return{};try{let t=JSON.parse(e);return t&&typeof t==="object"&&!Array.isArray(t)?t:{}}catch{return ae.warn("[PiAIChatService] Invalid historical tool arguments",{value:e}),{}}}function ce(e){let t=e.match(/^data:([^;,]+);base64,(.+)$/s);return t?{mimeType:t[1],data:t[2]}:void 0}async function le(e,t){let o=ce(e);if(o)return{type:"image",...o};if(!/^https?:\/\//i.test(e))return{type:"text",text:`[Unsupported image source: ${e}]`};let r=await fetch(e,{signal:t});if(!r.ok)throw Error(`Failed to load image ${e}: HTTP ${r.status}`);return{type:"image",mimeType:r.headers.get("content-type")?.split(";")[0]??"image/png",data:Buffer.from(await r.arrayBuffer()).toString("base64")}}async function j(e,t,o,r,n){let i=e.filter((s)=>s.role==="system").map((s)=>E(s.content)).filter(Boolean).join(`
|
|
3
3
|
|
|
4
4
|
`),a=[];for(let s of e){if(s.role==="system")continue;if(s.role==="user"){let c=t.input.includes("image"),d=typeof s.content==="string"?s.content:await Promise.all(s.content.map((l)=>l.type==="text"?Promise.resolve({type:"text",text:l.text}):c?le(l.image_url.url,r):Promise.resolve({type:"text",text:"[Image omitted: current model does not support image input]"})));a.push({role:"user",content:d,timestamp:Date.now()});continue}if(s.role==="assistant"){let c=[];if(s.reasoningContent?.trim())c.push({type:"thinking",thinking:s.reasoningContent});let d=E(s.content);if(d)c.push({type:"text",text:d});for(let l of s.tool_calls??[]){if(!("function"in l))continue;c.push({type:"toolCall",id:l.id,name:l.function.name,arguments:de(l.function.arguments)})}a.push({role:"assistant",content:c,api:t.api,provider:t.provider,model:t.id,usage:ue,stopReason:s.tool_calls?.length?"toolUse":"stop",timestamp:Date.now()});continue}a.push({role:"toolResult",toolCallId:s.tool_call_id??"",toolName:s.name??"unknown",content:[{type:"text",text:E(s.content)}],isError:!1,timestamp:Date.now()})}let u=o?.filter((s)=>!n||s.name===n).map((s)=>({name:s.name,description:s.description,parameters:s.parameters,constrainedSampling:s.constrainedSampling}));return{...i?{systemPrompt:i}:{},messages:a,...u?.length?{tools:u}:{}}}function B(e){let t=[];for(let o=0;o<e.length;o++){let r=e[o];if(r.role==="tool")continue;let n=r.role==="assistant"&&r.tool_calls?.length?r.tool_calls:void 0;if(!n){t.push(r);continue}let i=[],a=o+1;while(a<e.length&&e[a].role==="tool")i.push(e[a++]);let u=new Set(n.map((d)=>d.id)),s=i.filter((d)=>d.tool_call_id&&u.has(d.tool_call_id)),c=new Set(s.map((d)=>d.tool_call_id));if(u.size===n.length&&s.length===u.size&&c.size===u.size)t.push(r,...s);o=a-1}return t}function F(e){return e.some((t)=>t.role==="assistant"&&Boolean(t.tool_calls?.length)&&!t.reasoningContent?.trim())}function z(e,t){return{...e,...t.baseUrl?{baseUrl:q(e.api,t.baseUrl)}:{},...t.maxOutputTokens?{maxTokens:t.maxOutputTokens}:{}}}function S(e){let t=e.modelCatalog??_();return{models:t.models,model:z(t.getModel(e.provider,e.model),e)}}function V(e,t){let o=e.modelCatalog??_();return z(o.getModel(t.provider,t.model),e)}var Y=new WeakSet,me=["gousagelimiterror","freeusagelimiterror","monthly usage limit reached","available balance","insufficient_quota","out of budget","quota exceeded","billing"],pe=["prompt_too_long","prompt is too long","maximum context length","context length exceeded","context_length_exceeded","request too large"],fe=["econnreset","econnrefused","enotfound","eai_again","etimedout","fetch failed","network error","connection error","connection refused","connection lost","other side closed","socket hang up","socket connection was closed","upstream connect","reset before headers","websocket closed","websocket error","http2 request did not get a response"];function H(e){return(e instanceof Error?e.message:String(e)).toLowerCase()}function he(e){let t=H(e);return pe.some((o)=>t.includes(o))}function X(e){if(e!==null&&typeof e==="object")Y.add(e)}function Xe(e){return e!==null&&typeof e==="object"&&Y.has(e)}function ye(e){return e!==null&&typeof e==="object"&&"code"in e?e.code:void 0}function ge(e){if(e===null||typeof e!=="object")return;let t=e;for(let o of["status","statusCode"]){let r=t[o];if(typeof r==="number"&&Number.isInteger(r))return r}return}function be(e){let t=e.match(/^(?:error:\s*)?(\d{3})\b/),o=e.match(/\b(?:status(?:\s+code)?|http)[:\s]+(\d{3})\b/),r=Number(t?.[1]??o?.[1]);return Number.isInteger(r)?r:void 0}function T(e,t){let o=H(e),r=ye(e);if(r==="STREAM_IDLE_TIMEOUT"||e instanceof Error&&e.name==="AbortError"||o.includes("request aborted")||o==="aborted")return{retryable:!1};if(me.some((i)=>o.includes(i))||he(e))return{retryable:!1};if(t?.shouldRetry==="false")return{retryable:!1,statusCode:t.statusCode};let n=t?.statusCode??ge(e)??be(o);if(t?.shouldRetry==="true")return{retryable:!0,reason:n===429?"rate_limit":n===408||n===409?"timeout":"server_error",statusCode:n};if(n===429)return{retryable:!0,reason:"rate_limit",statusCode:n};if(n===408||n===409)return{retryable:!0,reason:"timeout",statusCode:n};if(n!==void 0&&n>=500&&n<=599)return{retryable:!0,reason:"server_error",statusCode:n};if(r==="PROVIDER_STREAM_CLOSED"||o.includes("stream closed before completion")||o.includes("ended without")||o.includes("stream ended before"))return{retryable:!0,reason:"stream_closed",statusCode:n};if(fe.some((i)=>o.includes(i)))return{retryable:!0,reason:"transport",statusCode:n};if(o.includes("timeout")||o.includes("timed out")||o.includes("temporarily unavailable")||o.includes("upstream_error")||o.includes("overloaded")||o.includes("rate limit")||o.includes("too many requests")||o.includes("service unavailable")||o.includes("server error")||o.includes("internal error")||o.includes("please retry")||o.includes("try your request again"))return{retryable:!0,reason:o.includes("rate")||o.includes("too many")?"rate_limit":o.includes("timeout")||o.includes("timed out")?"timeout":"server_error",statusCode:n};return{retryable:!1,statusCode:n}}function Ce(e,t){if(!e)return;if(e.retryAfterMs!==void 0){let n=Number.parseFloat(e.retryAfterMs);if(Number.isFinite(n))return Math.max(0,n)}if(e.retryAfter===void 0)return;let o=Number.parseFloat(e.retryAfter);if(Number.isFinite(o))return Math.max(0,o*1000);let r=Date.parse(e.retryAfter);return Number.isFinite(r)?Math.max(0,r-t):void 0}function G(e,t,o={}){let r=o.now??Date.now(),n=o.maxDelayMs??60000,i=Ce(t,r);if(i!==void 0)return Math.min(Math.ceil(i),n);let a=Math.max(0,e-1),u=Math.min(500*2**a,8000),s=Math.max(0,Math.min(1,o.random??Math.random())),c=u*(0.75+s*0.25);return Math.min(Math.round(c),n)}function J(e,t){let o=e.onPayload;e.onPayload=async(r,n)=>{let i=o?await o(r,n):r;return t(i===void 0?r:i,n)}}function Me(e){if(!e.reasoningEnabled)return;return e.reasoningEffort??e.reasoningLevel??"high"}function Re(e){switch(e){case"minimal":return"MINIMAL";case"low":return"LOW";case"medium":return"MEDIUM";default:return"HIGH"}}function xe(e,t,o,r){let n=r?void 0:Me(o);if(!n){if(t.api==="anthropic-messages")e.thinkingEnabled=!1;if(t.api==="google-generative-ai"||t.api==="google-vertex")e.thinking={enabled:!1};return}switch(t.api){case"anthropic-messages":e.thinkingEnabled=!0,e.effort=n;break;case"google-generative-ai":case"google-vertex":e.thinking={enabled:!0,level:Re(n)};break;case"mistral-conversations":e.reasoningEffort="high";break;case"bedrock-converse-stream":case"pi-messages":e.reasoning=n;break;default:e.reasoningEffort=n}}function ve(e,t,o){if(!o)return;switch(t){case"anthropic-messages":case"bedrock-converse-stream":e.toolChoice={type:"tool",name:o};break;case"openai-completions":case"mistral-conversations":case"pi-messages":e.toolChoice={type:"function",function:{name:o}};break;case"openai-responses":case"openai-codex-responses":case"azure-openai-responses":e.toolChoice={type:"function",name:o};break;case"google-generative-ai":case"google-vertex":e.toolChoice="any";break}}function Te(e,t,o){let r=o.serviceTier;if(!r)return;if(t.api==="openai-responses"||t.api==="openai-codex-responses"||t.api==="azure-openai-responses"){e.serviceTier=r;return}if(t.api!=="openai-completions"&&!(t.api==="anthropic-messages"&&r==="fast"))return;J(e,(n)=>{if(!n||typeof n!=="object"||Array.isArray(n))return n;return t.api==="anthropic-messages"?{...n,speed:"fast"}:{...n,service_tier:r}})}function ke(e,t,o){let r=o.responseVerbosity;if(!r)return;if(K(t,r),t.api==="openai-codex-responses"){e.textVerbosity=r;return}J(e,(n)=>{if(!n||typeof n!=="object"||Array.isArray(n))return n;if(t.api==="openai-completions")return{...n,verbosity:r};let i="text"in n&&n.text&&typeof n.text==="object"&&!Array.isArray(n.text)?n.text:{};return{...n,text:{...i,verbosity:r}}})}function Z(e,t,o,r,n=!1){let i={apiKey:e.apiKey,headers:e.customHeaders,signal:o,temperature:r?.temperature??e.temperature??0,maxTokens:r?.maxOutputTokens??e.maxOutputTokens,timeoutMs:e.timeout,maxRetries:0,cacheRetention:e.enablePromptCaching?"short":"none"};if(xe(i,t,e,n),ve(i,t.api,r?.toolChoice?.toolName),Te(i,t,e),ke(i,t,e),t.api==="azure-openai-responses")i.azureBaseUrl=e.baseUrl,i.azureApiVersion=e.apiVersion,i.azureDeploymentName=t.id;return i}function $(e,t){let o=t.get("x-should-retry");return{statusCode:e,...t.get("retry-after")!==null?{retryAfter:t.get("retry-after")??void 0}:{},...t.get("retry-after-ms")!==null?{retryAfterMs:t.get("retry-after-ms")??void 0}:{},...o==="true"||o==="false"?{shouldRetry:o}:{}}}var we=new Set(["anthropic-messages","openai-completions","openai-responses","openai-codex-responses","azure-openai-responses","pi-messages"]);function Q(e,t,o){let r=e.onResponse;if(e.onResponse=async(i,a)=>{let u=new Headers(i.headers);o($(i.status,u)),await r?.(i,a)},!we.has(t.api)||typeof globalThis.fetch!=="function")return;let n=typeof e.fetch==="function"?e.fetch:globalThis.fetch.bind(globalThis);e.fetch=async(i,a)=>{let u=await n(i,a);return o($(u.status,u.headers)),u}}function ee(e){return{promptTokens:e.input+e.cacheRead+e.cacheWrite,completionTokens:e.output,totalTokens:e.totalTokens,costUsd:e.cost.total,...e.reasoning!==void 0?{reasoningTokens:e.reasoning}:{},...e.cacheWrite>0?{cacheCreationInputTokens:e.cacheWrite}:{},...e.cacheRead>0?{cacheReadInputTokens:e.cacheRead}:{}}}var O=300000,Ae=30000;class te extends Error{timeoutMs;code="STREAM_IDLE_TIMEOUT";constructor(e){super(`Provider stream idle timeout after ${e}ms without an event`);this.timeoutMs=e;this.name="StreamIdleTimeoutError"}}class oe extends Error{code="PROVIDER_STREAM_CLOSED";constructor(){super("Provider stream closed before completion");this.name="ProviderStreamClosedError"}}function I(e){return e.reason instanceof Error?e.reason:new DOMException("Aborted","AbortError")}function Pe(e){return e.idleTimeoutMs&&e.idleTimeoutMs>0?e.idleTimeoutMs:O}function Ee(e,t){if(t===0)return;let o=t!==void 0&&t>0?t:Ae;return Math.max(1,Math.min(o,Math.floor(e/2)))}function _e(e,t,o){if(o?.aborted)return Promise.reject(I(o));return new Promise((r,n)=>{let i=!1,a=()=>{clearTimeout(d),o?.removeEventListener("abort",c)},u=(l)=>{if(i)return;i=!0,a(),r(l)},s=(l)=>{if(i)return;i=!0,a(),n(l instanceof Error?l:Error(String(l)))},c=()=>{if(o)s(I(o))},d=setTimeout(()=>u({kind:"timer"}),Math.max(0,t));if(o?.addEventListener("abort",c,{once:!0}),o?.aborted){c();return}e.then((l)=>u({kind:"next",result:l}),s)})}async function*Se(e,t,o){let r=Pe(t),n=Ee(r,t.stallWarningMs);if(t.signal?.aborted)throw I(t.signal);let i=Date.now(),a=Promise.resolve().then(()=>e.next()),u;for(;;){let c=await _e(a,(u?r:n??r)-(Date.now()-i),t.signal);if(c.kind==="next"){if(u)yield{...u,phase:"recovered",durationMs:Math.max(u.durationMs,Date.now()-i)};return c.result}if(!u&&n!==void 0){o.stallCount++,u={phase:"detected",stallCount:o.stallCount,durationMs:n,warningAfterMs:n,timeoutMs:r,outputStarted:o.outputStarted},yield u;continue}let d=new te(r);throw t.abort?.(d),d}}async function*ne(e,t,o,r,n={}){let a=e.stream(t,o,r)[Symbol.asyncIterator](),u=0,s=!1,c={stallCount:0,outputStarted:!1};try{while(!0){let d=Se(a,n,c),l=await d.next();while(!l.done)yield{providerStall:l.value},l=await d.next();let x=l.value;if(x.done)throw new oe;let f=x.value;switch(f.type){case"text_delta":c.outputStarted=!0,yield{content:f.delta};break;case"thinking_delta":c.outputStarted=!0,yield{reasoningContent:f.delta};break;case"toolcall_end":c.outputStarted=!0,yield{toolCalls:[{index:u++,id:f.toolCall.id,type:"function",function:{name:f.toolCall.name,arguments:JSON.stringify(f.toolCall.arguments)}}]};break;case"done":s=!0,yield{finishReason:f.reason,usage:ee(f.message.usage)};return;case"error":throw Error(f.error.errorMessage??`Request ${f.reason==="aborted"?"aborted":"failed"}`)}}}finally{if(!s)Promise.resolve(a.return?.()).catch(()=>{return})}}var re=R("Chat");function Ie(e){return Boolean(e&&e.role==="user"&&Array.isArray(e.content)&&e.content.some((t)=>t.type==="image_url"))}class D{config;models;model;constructor(e){let t=S(e);this.config={...e,maxContextTokens:t.model.contextWindow,maxOutputTokens:e.maxOutputTokens??t.model.maxTokens},this.models=t.models,this.model=t.model,re.debug("[PiAIChatService] Initialized",{provider:this.model.provider,model:this.model.id,api:this.model.api})}async chat(e,t,o,r){let n="",i="",a=[],u,s;for await(let c of this.streamChat(e,t,o,r)){n+=c.content??"",i+=c.reasoningContent??"";for(let d of c.toolCalls??[])if(d.id&&d.type==="function"&&d.function?.name)a.push(d);u=c.usage??u,s=c.finishReason??s}return{content:n,...i?{reasoningContent:i}:{},...a.length>0?{toolCalls:a}:{},usage:u,finishReason:s}}async*streamChat(e,t,o,r){let n=r?.toolChoice?.toolName;if(n&&!t?.some((m)=>m.name===n))throw Error(`Required tool is unavailable: ${n}`);let i=B(e);if(i.some((m)=>Ie(m))&&!this.model.input.includes("image"))throw Error(`${this.model.name} does not support image input`);let a=Boolean(n)||F(i),u=await j(i,this.model,t,o,n),s,c=(m)=>{s=void 0;let C=new AbortController,h=o?U(o,C.signal):C.signal,M=Z(this.config,m,h,r,a);return Q(M,m,(y)=>{s=y}),ne(this.models,m,u,M,{idleTimeoutMs:this.config.streamIdleTimeout??O,signal:h,abort:(y)=>C.abort(y)})},d=this.config.maxRetries??2,l=this,x=async function*(m,C){let h,M=!1,y,v;for(let g=0;g<=d;g++)try{let b=!1;for await(let p of c(m)){if(p.providerStall){yield p;continue}if(g>0&&y&&!b)b=!0,yield{providerRetry:{phase:"recovered",attempt:g,maxRetries:d,reason:y,...v!==void 0?{statusCode:v}:{}}};M=!0,C(),yield p}return}catch(b){h=b,l.logIdleTimeout(b,M,m),await l.handleAbort(o);let p=T(b,s);if(M)throw X(b),b;if(!p.retryable||!p.reason){if(g>0&&y)yield{providerRetry:{phase:"exhausted",attempt:g,maxRetries:d,reason:y,...v!==void 0?{statusCode:v}:{}}};throw b}if(y=p.reason,v=p.statusCode,g<d){let k=g+1,w=G(k,s);yield{providerRetry:{phase:"scheduled",attempt:k,maxRetries:d,reason:p.reason,...p.statusCode!==void 0?{statusCode:p.statusCode}:{},delayMs:w,nextRetryAt:Date.now()+w}},await P(w,o,{throwOnAbort:!0}),yield{providerRetry:{phase:"attempt",attempt:k,maxRetries:d,reason:p.reason,...p.statusCode!==void 0?{statusCode:p.statusCode}:{}}}}else yield{providerRetry:{phase:"exhausted",attempt:g,maxRetries:d,reason:p.reason,...p.statusCode!==void 0?{statusCode:p.statusCode}:{}}}}throw h},f,L=!1;try{for await(let m of x(this.model,()=>{L=!0}))yield m;return}catch(m){if(f=m,L||!T(m,s).retryable)throw m}for(let m of this.config.fallbackModels??[]){yield{modelFallback:!0};let C=!1;try{let h=V(this.config,m);for await(let M of x(h,()=>{C=!0}))yield M;return}catch(h){if(f=h,C||!T(h,s).retryable)throw h}}throw f}async handleAbort(e){if(e?.aborted)await P(0,e,{throwOnAbort:!0})}logIdleTimeout(e,t,o){if(e===null||typeof e!=="object"||!("code"in e)||e.code!=="STREAM_IDLE_TIMEOUT"||!("timeoutMs"in e)||typeof e.timeoutMs!=="number")return;re.warn("[PiAIChatService] Provider stream idle timeout",{provider:o.provider,model:o.id,timeoutMs:e.timeoutMs,replayBoundaryCrossed:t})}getConfig(){return{...this.config}}updateConfig(e){let t={...this.config,...e},o=S(t);this.config={...t,maxContextTokens:o.model.contextWindow,maxOutputTokens:t.maxOutputTokens??o.model.maxTokens},this.models=o.models,this.model=o.model}}var Oe=R("Service");async function mt(e){let t=e;if(t.provider){let o=N(t.provider);if(Object.keys(o).length>0)t={...t,customHeaders:{...o,...t.customHeaders}},Oe.debug(`Injected ${t.provider} specific headers:`,Object.keys(o))}return De(t)}function De(e){return new D(e)}
|
|
5
|
-
export{Ne as
|
|
5
|
+
export{Ne as xd,je as yd,U as zd,he as Ad,Xe as Bd,D as Cd,mt as Dd};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import d from"typebox/schema";import o from"typebox/value";class u extends Error{issues;constructor(r){super(r.map((t)=>{return`${t.path.length>0?t.path.join("."):"root"}: ${t.message}`}).join("; "));this.issues=r;this.name="SchemaValidationError"}}function p(r){if(!r)return[];return r.split("/").slice(1).map((t)=>t.replace(/~1/g,"/").replace(/~0/g,"~")).map((t)=>/^(0|[1-9]\d*)$/.test(t)?Number(t):t)}function g(r,t){let n=r;for(let e of t){if(n===null||typeof n!=="object")return;n=n[e]}return n}function i(r,t){let[,n]=d.Errors(r,t);return n.map((e)=>{let s=p(e.instancePath);return{code:e.keyword,path:s,message:e.message,value:g(t,s)}})}function a(r,t){let n=o.Default(r,o.Clone(t)),e=i(r,n);if(e.length>0)return{success:!1,error:new u(e)};let s=o.Clean(r,n),c=i(r,s);if(c.length>0)return{success:!1,error:new u(c)};return{success:!0,data:s}}function f(r,t){let n=a(r,t);if(!n.success)throw n.error;return n.data}import l from"typebox";function x(r){return Object.defineProperties(r,{parse:{value:(t)=>f(r,t),enumerable:!1},safeParse:{value:(t)=>a(r,t),enumerable:!1}}),r}function b(r,t){return l.Optional({...r,default:t})}function V(r,t={}){return l.Unsafe({type:"string",enum:[...r],...t})}
|
|
2
|
-
export{a as
|
|
2
|
+
export{a as of,f as pf,l as qf,x as rf,b as sf,V as tf};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{fd as a,gd as b,hd as c,id as d,jd as e,kd as f,ld as g,md as h,nd as i,od as j,pd as k,qd as l,rd as m,sd as n,td as o,ud as p,vd as q}from"./chunk-mbrgz77y.js";import"./chunk-v508x7cg.js";import"./chunk-6kc12pma.js";import"./chunk-vx8a7e1j.js";import"./chunk-gdp6fg4e.js";import"./chunk-4qyhtrhx.js";import"./chunk-s6rdv601.js";import"./chunk-1ggxyyar.js";import"./chunk-ekv4hpy8.js";import"./chunk-8gv6hsrf.js";import"./chunk-5m5nxkfs.js";import"./chunk-7e7zgzag.js";import"./chunk-2d35rmyg.js";import"./chunk-d4327k1v.js";import"./chunk-heydawsf.js";import"./chunk-37se34rx.js";export{a as vanillaStore,c as sessionActions,l as getThinkingModeEnabled,b as getState,n as getServiceTier,o as getResponseVerbosity,m as getReasoningEffort,j as getModelById,e as getMessages,k as getMcpServers,i as getCurrentModel,f as getConfig,p as getCommunicationStyle,h as getAllModels,g as ensureStoreInitialized,q as configActions,d as appActions};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
var t=["auto","low","medium","high"],s=new Set(["openai-completions","openai-responses","openai-codex-responses","azure-openai-responses"]);function n(e){return/(?:^|[/.:_-])gpt-5(?:$|[/.:_-])/i.test(e.id)}function f(e){return typeof e==="string"&&t.includes(e)}function p(e){if(e.api==="openai-codex-responses"||s.has(e.api)&&n(e))return["low","medium","high"];return[]}function u(e,r){let i=p(e);if(r!=="auto"&&!i.includes(r))throw Error(`Response verbosity ${r} is not supported by ${e.name}`);if(r==="auto")return{selection:r,effective:"provider-default",supported:i};return{selection:r,effective:r,supported:i,providerValue:r}}var a=["auto","standard","fast","flex"],o=new Set(["openai-completions","openai-responses","openai-codex-responses","azure-openai-responses"]);function S(e){return typeof e==="string"&&a.includes(e)}function c(e){if(o.has(e.api))return["standard","fast","flex"];if(e.api==="anthropic-messages"&&/(?:^|-)claude-opus-4-6(?:-|$)/i.test(e.id))return["standard","fast"];return["standard"]}function l(e,r){let i=c(e);if(r!=="auto"&&!i.includes(r))throw Error(`Service tier ${r} is not supported by ${e.name}`);if(r==="auto")return{selection:r,effective:"provider-default",supported:i};if(r==="standard")return{selection:r,effective:"standard",supported:i,...o.has(e.api)?{providerValue:"default"}:{}};if(r==="fast")return{selection:r,effective:"fast",supported:i,providerValue:e.api==="anthropic-messages"?"fast":"priority"};return{selection:r,effective:"flex",supported:i,providerValue:"flex"}}
|
|
2
|
-
export{f as
|
|
2
|
+
export{f as Lf,p as Mf,u as Nf,S as Of,c as Pf,l as Qf};
|