@fungi.computer/grove 0.3.0 → 0.4.0

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.
@@ -0,0 +1 @@
1
+ import{En as e}from"./Effect-Bibd7o64.js";import{Ci as t,Jn as n,Nn as r,Xn as i,Yn as a,c as o,ho as s,i as c,ji as l,ki as u,ri as d,yi as f}from"./extension-hook-C8RQgls9.js";Object.freeze({module:n,operation:a,gate:i}),f(r),t(u(r));var p=class extends e()(`@fungi.computer/shiitake/ExtensionRead`){},m=class extends e()(`@fungi.computer/shiitake/ExtensionTx`){},h=class extends s(`ExtensionStateError`){},g=class extends s(`AdmissionError`){},_=class extends s(`ExtensionCommandError`){},v=class extends s(`ExtensionStop`){};s(`ExtensionActivationError`),t(c),t(o),l(d);export{v as a,h as i,_ as n,m as o,p as r,g as t};
@@ -0,0 +1 @@
1
+ import{a as e,m as t,n,s as r}from"./preload-helper-DY31Aviq.js";import{a as i}from"./diagnostics-CxvqSC4Q.js";import{n as a,t as o}from"./models-BM_0GHMS.js";import{n as s}from"./headers-FK4rgixo.js";import{h as c,i as l}from"./transform-messages-CgFTI6NF.js";import{t as u}from"./sanitize-unicode-DmIE6hZJ.js";import{n as d,t as f}from"./error-body-pkrba6pf.js";import{a as p,c as m,d as h,f as g,i as _,l as v,m as y,n as b,o as x,p as S,r as C,s as w,t as T,u as E}from"./google-shared-CRsSlHta.js";var D=0,O=(e,t,r)=>{let a=new i,s=n(t);return(async()=>{let t={role:`assistant`,content:[],api:`google-generative-ai`,provider:e.provider,model:e.id,usage:{input:0,output:0,cacheRead:0,cacheWrite:0,totalTokens:0,cost:{input:0,output:0,cacheRead:0,cacheWrite:0,total:0}},stopReason:`pending`,timestamp:Date.now()};try{if(r?.fetch&&r.fetch!==globalThis.fetch)throw Error(`Custom fetch is not supported by the Google Generative AI adapter`);let n=r?.apiKey;if(!n)throw Error(`No API key for provider: ${e.provider}`);let i=A(e,n,r?.headers),c=j(e,s,r),l=await r?.onPayload?.(c,e);l!==void 0&&(c=l);let u=await v(()=>i.models.generateContentStream(c),r);a.push({type:`start`,partial:t});let d=null,f=t.content,h=()=>f.length-1;for await(let n of u){await r?.onProviderStreamEvent?.(n,e),t.responseId||=n.responseId;let i=n.candidates?.[0];if(i?.content?.parts)for(let e of i.content.parts){if(e.text!==void 0){let n=_(e);(!d||n&&d.type!==`thinking`||!n&&d.type!==`text`)&&(d&&(d.type===`text`?a.push({type:`text_end`,contentIndex:f.length-1,content:d.text,partial:t}):a.push({type:`thinking_end`,contentIndex:h(),content:d.thinking,partial:t})),n?(d={type:`thinking`,thinking:``,thinkingSignature:void 0},t.content.push(d),a.push({type:`thinking_start`,contentIndex:h(),partial:t})):(d={type:`text`,text:``},t.content.push(d),a.push({type:`text_start`,contentIndex:h(),partial:t}))),d.type===`thinking`?(d.thinking+=e.text,d.thinkingSignature=m(d.thinkingSignature,e.thoughtSignature),a.push({type:`thinking_delta`,contentIndex:h(),delta:e.text,partial:t})):(d.text+=e.text,d.textSignature=m(d.textSignature,e.thoughtSignature),a.push({type:`text_delta`,contentIndex:h(),delta:e.text,partial:t}))}if(e.functionCall){d&&=(d.type===`text`?a.push({type:`text_end`,contentIndex:h(),content:d.text,partial:t}):a.push({type:`thinking_end`,contentIndex:h(),content:d.thinking,partial:t}),null);let n=e.functionCall.id,r={type:`toolCall`,id:!n||t.content.some(e=>e.type===`toolCall`&&e.id===n)?`${e.functionCall.name}_${Date.now()}_${++D}`:n,name:e.functionCall.name||``,arguments:e.functionCall.args??{},...e.thoughtSignature&&{thoughtSignature:e.thoughtSignature}};t.content.push(r),a.push({type:`toolcall_start`,contentIndex:h(),partial:t}),a.push({type:`toolcall_delta`,contentIndex:h(),delta:JSON.stringify(r.arguments),partial:t}),a.push({type:`toolcall_end`,contentIndex:h(),toolCall:r,partial:t})}}i?.finishReason&&(t.rawStopReason=i.finishReason,t.stopReason=p(i.finishReason),t.content.some(e=>e.type===`toolCall`)&&t.stopReason===`stop`&&(t.stopReason=`toolUse`)),n.usageMetadata&&(t.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,reasoning:n.usageMetadata.thoughtsTokenCount||0,totalTokens:n.usageMetadata.totalTokenCount||0,cost:{input:0,output:0,cacheRead:0,cacheWrite:0,total:0}},o(e,t.usage))}if(d&&(d.type===`text`?a.push({type:`text_end`,contentIndex:h(),content:d.text,partial:t}):a.push({type:`thinking_end`,contentIndex:h(),content:d.thinking,partial:t})),r?.signal?.aborted)throw Error(`Request was aborted`);if(t.stopReason===`pending`)throw Error(`Google stream ended without a finish reason`);if(t.stopReason===`aborted`||t.stopReason===`error`){let e=t.rawStopReason?`Provider stopped with: ${t.rawStopReason}`:`An unknown error occurred`;throw Error(e)}a.push({type:`done`,reason:t.stopReason,message:t}),a.end()}catch(e){for(let e of t.content)`index`in e&&delete e.index;t.stopReason=r?.signal?.aborted?`aborted`:`error`,t.errorMessage=f(d(e)),a.push({type:`error`,reason:t.stopReason,error:t}),a.end()}})(),a},k=(e,t,n)=>{let r=n?.apiKey;if(!r)throw Error(`No API key for provider: ${e.provider}`);let i={...l(e,t,n,r),toolChoice:n?.toolChoice};if(!n?.reasoning)return O(e,t,{...i,thinking:{enabled:!1}});let o=a(e,n.reasoning);if(o===`off`)return O(e,t,{...i,thinking:{enabled:!1}});let s=w(e,o);return S(e)?O(e,t,{...i,thinking:{enabled:!0,level:g(s)}}):O(e,t,{...i,thinking:{enabled:!0,budgetTokens:M(e,s,n.thinkingBudgets)}})};function A(e,t,n){let r={};e.baseUrl&&(r.baseUrl=e.baseUrl,r.apiVersion=``);let i=s({"User-Agent":c(),...e.headers,...n});return i&&(r.headers=i),new y({apiKey:t,httpOptions:Object.keys(r).length>0?r:void 0})}function j(n,i,a={}){let o=T(n,i),s=r(i.messages),c=e(i.messages),l={};a.temperature!==void 0&&(l.temperature=a.temperature),a.maxTokens!==void 0&&(l.maxOutputTokens=a.maxTokens);let d=E(n.id),f=c.length>0?x(c,a.toolChoice,d):void 0,p=s?t(s):``,m={...Object.keys(l).length>0&&l,...p&&{systemInstruction:u(p)},...c.length>0&&{tools:b(c,!1,d)},...f!==void 0&&{toolConfig:{functionCallingConfig:{mode:f}}}};if(a.thinking?.enabled&&n.reasoning){let e={includeThoughts:!0};a.thinking.level===void 0?a.thinking.budgetTokens!==void 0&&(e.thinkingBudget=a.thinking.budgetTokens):e.thinkingLevel=h(a.thinking.level),m.thinkingConfig=e}else n.reasoning&&a.thinking&&!a.thinking.enabled&&(m.thinkingConfig=C(n));if(a.signal){if(a.signal.aborted)throw Error(`Request aborted`);m.abortSignal=a.signal}return{model:n.id,contents:o,config:m}}function M(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{O as stream,k as streamSimple};