sliccy 2.5.2 → 2.5.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- import{a as e,n as t,r as n,s as r}from"./simple-options-DEbfD_Ko.js";import{o as i}from"./index-DP3Ol2R4.js";import{t as a}from"./sanitize-unicode-ncMKN_SD.js";import{c as o,i as s,n as c,o as l,r as u,s as d,t as f}from"./google-shared-jyMmIrwc.js";var p=0,m=(t,n,a)=>{let o=new e;return(async()=>{let e={role:`assistant`,content:[],api:`google-generative-ai`,provider:t.provider,model:t.id,usage:{input:0,output:0,cacheRead:0,cacheWrite:0,totalTokens:0,cost:{input:0,output:0,cacheRead:0,cacheWrite:0,total:0}},stopReason:`stop`,timestamp:Date.now()};try{let c=g(t,a?.apiKey||i(t.provider)||``,a?.headers),l=_(t,n,a),f=await a?.onPayload?.(l,t);f!==void 0&&(l=f);let m=await c.models.generateContentStream(l);o.push({type:`start`,partial:e});let h=null,v=e.content,y=()=>v.length-1;for await(let n of m){e.responseId||=n.responseId;let i=n.candidates?.[0];if(i?.content?.parts)for(let t of i.content.parts){if(t.text!==void 0){let n=u(t);(!h||n&&h.type!==`thinking`||!n&&h.type!==`text`)&&(h&&(h.type===`text`?o.push({type:`text_end`,contentIndex:v.length-1,content:h.text,partial:e}):o.push({type:`thinking_end`,contentIndex:y(),content:h.thinking,partial:e})),n?(h={type:`thinking`,thinking:``,thinkingSignature:void 0},e.content.push(h),o.push({type:`thinking_start`,contentIndex:y(),partial:e})):(h={type:`text`,text:``},e.content.push(h),o.push({type:`text_start`,contentIndex:y(),partial:e}))),h.type===`thinking`?(h.thinking+=t.text,h.thinkingSignature=d(h.thinkingSignature,t.thoughtSignature),o.push({type:`thinking_delta`,contentIndex:y(),delta:t.text,partial:e})):(h.text+=t.text,h.textSignature=d(h.textSignature,t.thoughtSignature),o.push({type:`text_delta`,contentIndex:y(),delta:t.text,partial:e}))}if(t.functionCall){h&&=(h.type===`text`?o.push({type:`text_end`,contentIndex:y(),content:h.text,partial:e}):o.push({type:`thinking_end`,contentIndex:y(),content:h.thinking,partial:e}),null);let n=t.functionCall.id,r={type:`toolCall`,id:!n||e.content.some(e=>e.type===`toolCall`&&e.id===n)?`${t.functionCall.name}_${Date.now()}_${++p}`:n,name:t.functionCall.name||``,arguments:t.functionCall.args??{},...t.thoughtSignature&&{thoughtSignature:t.thoughtSignature}};e.content.push(r),o.push({type:`toolcall_start`,contentIndex:y(),partial:e}),o.push({type:`toolcall_delta`,contentIndex:y(),delta:JSON.stringify(r.arguments),partial:e}),o.push({type:`toolcall_end`,contentIndex:y(),toolCall:r,partial:e})}}i?.finishReason&&(e.stopReason=s(i.finishReason),e.content.some(e=>e.type===`toolCall`)&&(e.stopReason=`toolUse`)),n.usageMetadata&&(e.usage={input:(n.usageMetadata.promptTokenCount||0)-(n.usageMetadata.cachedContentTokenCount||0),output:(n.usageMetadata.candidatesTokenCount||0)+(n.usageMetadata.thoughtsTokenCount||0),cacheRead:n.usageMetadata.cachedContentTokenCount||0,cacheWrite:0,totalTokens:n.usageMetadata.totalTokenCount||0,cost:{input:0,output:0,cacheRead:0,cacheWrite:0,total:0}},r(t,e.usage))}if(h&&(h.type===`text`?o.push({type:`text_end`,contentIndex:y(),content:h.text,partial:e}):o.push({type:`thinking_end`,contentIndex:y(),content:h.thinking,partial:e})),a?.signal?.aborted)throw Error(`Request was aborted`);if(e.stopReason===`aborted`||e.stopReason===`error`)throw Error(`An unknown error occurred`);o.push({type:`done`,reason:e.stopReason,message:e}),o.end()}catch(t){for(let t of e.content)`index`in t&&delete t.index;e.stopReason=a?.signal?.aborted?`aborted`:`error`,e.errorMessage=t instanceof Error?t.message:JSON.stringify(t),o.push({type:`error`,reason:e.stopReason,error:e}),o.end()}})(),o},h=(e,r,a)=>{let o=a?.apiKey||i(e.provider);if(!o)throw Error(`No API key for provider: ${e.provider}`);let s=t(e,a,o);if(!a?.reasoning)return m(e,r,{...s,thinking:{enabled:!1}});let c=n(a.reasoning),l=e;return y(l)||b(l)||v(l)?m(e,r,{...s,thinking:{enabled:!0,level:S(c,l)}}):m(e,r,{...s,thinking:{enabled:!0,budgetTokens:C(l,c,a.thinkingBudgets)}})};function g(e,t,n){let r={};return e.baseUrl&&(r.baseUrl=e.baseUrl,r.apiVersion=``),(e.headers||n)&&(r.headers={...e.headers,...n}),new o({apiKey:t,httpOptions:Object.keys(r).length>0?r:void 0})}function _(e,t,n={}){let r=f(e,t),i={};n.temperature!==void 0&&(i.temperature=n.temperature),n.maxTokens!==void 0&&(i.maxOutputTokens=n.maxTokens);let o={...Object.keys(i).length>0&&i,...t.systemPrompt&&{systemInstruction:a(t.systemPrompt)},...t.tools&&t.tools.length>0&&{tools:c(t.tools)}};if(t.tools&&t.tools.length>0&&n.toolChoice?o.toolConfig={functionCallingConfig:{mode:l(n.toolChoice)}}:o.toolConfig=void 0,n.thinking?.enabled&&e.reasoning){let e={includeThoughts:!0};n.thinking.level===void 0?n.thinking.budgetTokens!==void 0&&(e.thinkingBudget=n.thinking.budgetTokens):e.thinkingLevel=n.thinking.level,o.thinkingConfig=e}else e.reasoning&&n.thinking&&!n.thinking.enabled&&(o.thinkingConfig=x(e));if(n.signal){if(n.signal.aborted)throw Error(`Request aborted`);o.abortSignal=n.signal}return{model:e.id,contents:r,config:o}}function v(e){return/gemma-?4/.test(e.id.toLowerCase())}function y(e){return/gemini-3(?:\.\d+)?-pro/.test(e.id.toLowerCase())}function b(e){return/gemini-3(?:\.\d+)?-flash/.test(e.id.toLowerCase())}function x(e){return y(e)?{thinkingLevel:`LOW`}:b(e)||v(e)?{thinkingLevel:`MINIMAL`}:{thinkingBudget:0}}function S(e,t){if(y(t))switch(e){case`minimal`:case`low`:return`LOW`;case`medium`:case`high`:return`HIGH`}if(v(t))switch(e){case`minimal`:case`low`:return`MINIMAL`;case`medium`:case`high`:return`HIGH`}switch(e){case`minimal`:return`MINIMAL`;case`low`:return`LOW`;case`medium`:return`MEDIUM`;case`high`:return`HIGH`}}function C(e,t,n){return n?.[t]===void 0?e.id.includes(`2.5-pro`)?{minimal:128,low:2048,medium:8192,high:32768}[t]:e.id.includes(`2.5-flash-lite`)?{minimal:512,low:2048,medium:8192,high:24576}[t]:e.id.includes(`2.5-flash`)?{minimal:128,low:2048,medium:8192,high:24576}[t]:-1:n[t]}export{m as streamGoogle,h as streamSimpleGoogle};
1
+ import{a as e,n as t,r as n,s as r}from"./simple-options-DEbfD_Ko.js";import{o as i}from"./index-CnmNKZhe.js";import{t as a}from"./sanitize-unicode-ncMKN_SD.js";import{c as o,i as s,n as c,o as l,r as u,s as d,t as f}from"./google-shared-jyMmIrwc.js";var p=0,m=(t,n,a)=>{let o=new e;return(async()=>{let e={role:`assistant`,content:[],api:`google-generative-ai`,provider:t.provider,model:t.id,usage:{input:0,output:0,cacheRead:0,cacheWrite:0,totalTokens:0,cost:{input:0,output:0,cacheRead:0,cacheWrite:0,total:0}},stopReason:`stop`,timestamp:Date.now()};try{let c=g(t,a?.apiKey||i(t.provider)||``,a?.headers),l=_(t,n,a),f=await a?.onPayload?.(l,t);f!==void 0&&(l=f);let m=await c.models.generateContentStream(l);o.push({type:`start`,partial:e});let h=null,v=e.content,y=()=>v.length-1;for await(let n of m){e.responseId||=n.responseId;let i=n.candidates?.[0];if(i?.content?.parts)for(let t of i.content.parts){if(t.text!==void 0){let n=u(t);(!h||n&&h.type!==`thinking`||!n&&h.type!==`text`)&&(h&&(h.type===`text`?o.push({type:`text_end`,contentIndex:v.length-1,content:h.text,partial:e}):o.push({type:`thinking_end`,contentIndex:y(),content:h.thinking,partial:e})),n?(h={type:`thinking`,thinking:``,thinkingSignature:void 0},e.content.push(h),o.push({type:`thinking_start`,contentIndex:y(),partial:e})):(h={type:`text`,text:``},e.content.push(h),o.push({type:`text_start`,contentIndex:y(),partial:e}))),h.type===`thinking`?(h.thinking+=t.text,h.thinkingSignature=d(h.thinkingSignature,t.thoughtSignature),o.push({type:`thinking_delta`,contentIndex:y(),delta:t.text,partial:e})):(h.text+=t.text,h.textSignature=d(h.textSignature,t.thoughtSignature),o.push({type:`text_delta`,contentIndex:y(),delta:t.text,partial:e}))}if(t.functionCall){h&&=(h.type===`text`?o.push({type:`text_end`,contentIndex:y(),content:h.text,partial:e}):o.push({type:`thinking_end`,contentIndex:y(),content:h.thinking,partial:e}),null);let n=t.functionCall.id,r={type:`toolCall`,id:!n||e.content.some(e=>e.type===`toolCall`&&e.id===n)?`${t.functionCall.name}_${Date.now()}_${++p}`:n,name:t.functionCall.name||``,arguments:t.functionCall.args??{},...t.thoughtSignature&&{thoughtSignature:t.thoughtSignature}};e.content.push(r),o.push({type:`toolcall_start`,contentIndex:y(),partial:e}),o.push({type:`toolcall_delta`,contentIndex:y(),delta:JSON.stringify(r.arguments),partial:e}),o.push({type:`toolcall_end`,contentIndex:y(),toolCall:r,partial:e})}}i?.finishReason&&(e.stopReason=s(i.finishReason),e.content.some(e=>e.type===`toolCall`)&&(e.stopReason=`toolUse`)),n.usageMetadata&&(e.usage={input:(n.usageMetadata.promptTokenCount||0)-(n.usageMetadata.cachedContentTokenCount||0),output:(n.usageMetadata.candidatesTokenCount||0)+(n.usageMetadata.thoughtsTokenCount||0),cacheRead:n.usageMetadata.cachedContentTokenCount||0,cacheWrite:0,totalTokens:n.usageMetadata.totalTokenCount||0,cost:{input:0,output:0,cacheRead:0,cacheWrite:0,total:0}},r(t,e.usage))}if(h&&(h.type===`text`?o.push({type:`text_end`,contentIndex:y(),content:h.text,partial:e}):o.push({type:`thinking_end`,contentIndex:y(),content:h.thinking,partial:e})),a?.signal?.aborted)throw Error(`Request was aborted`);if(e.stopReason===`aborted`||e.stopReason===`error`)throw Error(`An unknown error occurred`);o.push({type:`done`,reason:e.stopReason,message:e}),o.end()}catch(t){for(let t of e.content)`index`in t&&delete t.index;e.stopReason=a?.signal?.aborted?`aborted`:`error`,e.errorMessage=t instanceof Error?t.message:JSON.stringify(t),o.push({type:`error`,reason:e.stopReason,error:e}),o.end()}})(),o},h=(e,r,a)=>{let o=a?.apiKey||i(e.provider);if(!o)throw Error(`No API key for provider: ${e.provider}`);let s=t(e,a,o);if(!a?.reasoning)return m(e,r,{...s,thinking:{enabled:!1}});let c=n(a.reasoning),l=e;return y(l)||b(l)||v(l)?m(e,r,{...s,thinking:{enabled:!0,level:S(c,l)}}):m(e,r,{...s,thinking:{enabled:!0,budgetTokens:C(l,c,a.thinkingBudgets)}})};function g(e,t,n){let r={};return e.baseUrl&&(r.baseUrl=e.baseUrl,r.apiVersion=``),(e.headers||n)&&(r.headers={...e.headers,...n}),new o({apiKey:t,httpOptions:Object.keys(r).length>0?r:void 0})}function _(e,t,n={}){let r=f(e,t),i={};n.temperature!==void 0&&(i.temperature=n.temperature),n.maxTokens!==void 0&&(i.maxOutputTokens=n.maxTokens);let o={...Object.keys(i).length>0&&i,...t.systemPrompt&&{systemInstruction:a(t.systemPrompt)},...t.tools&&t.tools.length>0&&{tools:c(t.tools)}};if(t.tools&&t.tools.length>0&&n.toolChoice?o.toolConfig={functionCallingConfig:{mode:l(n.toolChoice)}}:o.toolConfig=void 0,n.thinking?.enabled&&e.reasoning){let e={includeThoughts:!0};n.thinking.level===void 0?n.thinking.budgetTokens!==void 0&&(e.thinkingBudget=n.thinking.budgetTokens):e.thinkingLevel=n.thinking.level,o.thinkingConfig=e}else e.reasoning&&n.thinking&&!n.thinking.enabled&&(o.thinkingConfig=x(e));if(n.signal){if(n.signal.aborted)throw Error(`Request aborted`);o.abortSignal=n.signal}return{model:e.id,contents:r,config:o}}function v(e){return/gemma-?4/.test(e.id.toLowerCase())}function y(e){return/gemini-3(?:\.\d+)?-pro/.test(e.id.toLowerCase())}function b(e){return/gemini-3(?:\.\d+)?-flash/.test(e.id.toLowerCase())}function x(e){return y(e)?{thinkingLevel:`LOW`}:b(e)||v(e)?{thinkingLevel:`MINIMAL`}:{thinkingBudget:0}}function S(e,t){if(y(t))switch(e){case`minimal`:case`low`:return`LOW`;case`medium`:case`high`:return`HIGH`}if(v(t))switch(e){case`minimal`:case`low`:return`MINIMAL`;case`medium`:case`high`:return`HIGH`}switch(e){case`minimal`:return`MINIMAL`;case`low`:return`LOW`;case`medium`:return`MEDIUM`;case`high`:return`HIGH`}}function C(e,t,n){return n?.[t]===void 0?e.id.includes(`2.5-pro`)?{minimal:128,low:2048,medium:8192,high:32768}[t]:e.id.includes(`2.5-flash-lite`)?{minimal:512,low:2048,medium:8192,high:24576}[t]:e.id.includes(`2.5-flash`)?{minimal:128,low:2048,medium:8192,high:24576}[t]:-1:n[t]}export{m as streamGoogle,h as streamSimpleGoogle};