@hintergrund/ui 0.3.31 → 0.3.33
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/LanguageSelect-vGM6rIrX.js +2 -0
- package/dist/admin.js +2 -2
- package/dist/{anthropic-messages-BWu37L2n.js → anthropic-messages-ONkda3TH.js} +2 -2
- package/dist/google-generative-ai-DSHnmb-J.js +1 -0
- package/dist/login.js +1 -1
- package/dist/{node.browser-Ds1ZKU_l.js → node.browser-CopIczNX.js} +1 -1
- package/dist/{node.browser-DgI-vScy.js → node.browser-iT483GRP.js} +1 -1
- package/dist/openai-completions-CoiYTLsx.js +1 -0
- package/dist/openai-decisions-65NYNWDK.js +1 -0
- package/dist/openai-prompt-cache-5sS0RGen.js +1 -0
- package/dist/openai-responses-XNqoGkjv.js +1 -0
- package/dist/provider-retry-CRfxeEog.js +1 -0
- package/dist/transform-messages-BWDpoK0O.js +1 -0
- package/package.json +5 -5
- package/dist/LanguageSelect-NMSyY8kR.js +0 -2
- package/dist/env-api-keys-DEwNvwh9.js +0 -1
- package/dist/google-generative-ai-Ds5nhSQW.js +0 -1
- package/dist/models-CgcenYdX.js +0 -1
- package/dist/openai-completions-BibPS7ll.js +0 -1
- package/dist/openai-decisions-DCwsNo7V.js +0 -1
- package/dist/openai-prompt-cache-C2HSF10I.js +0 -1
- package/dist/openai-responses-E_4jJ6H1.js +0 -1
- package/dist/provider-retry-CdHXT9D0.js +0 -1
- package/dist/transform-messages-DfNS1LpB.js +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
void 0===globalThis.process&&(globalThis.process={env:{},platform:"browser",version:"",versions:{},browser:!0,nextTick:function(e){return Promise.resolve().then(e)}});import{$ as e,F as t,H as o,I as n,K as s,Z as r,nt as i,q as a,rt as p,tt as c}from"./LanguageSelect-vGM6rIrX.js";import{i as l,n as u,o as d,r as m,t as f}from"./github-copilot-headers-CdUV5uSi.js";import{a as g,i as h,n as y,t as _}from"./provider-retry-CRfxeEog.js";import{_ as v,d as x,f as k,g as b,h as w,i as I,l as T,n as R,p as M,s as S,u as C}from"./transform-messages-BWDpoK0O.js";import{n as $,t as E}from"./openai-prompt-cache-5sS0RGen.js";function A(e,t){const o={v:1,id:e};return t&&(o.phase=t),JSON.stringify(o)}function O(e){if(e){if(e.startsWith("{"))try{const t=JSON.parse(e);if(1===t.v&&"string"==typeof t.id)return"commentary"===t.phase||"final_answer"===t.phase?{id:t.id,phase:t.phase}:{id:t.id}}catch{}return{id:e}}}function P(e,t){const o=t.filter(e=>"text"===e.type).map(e=>e.text).join("\n"),n=t.filter(e=>"image"===e.type),s=o.trim().length>0;if(0===n.length||!e.input.includes("image"))return v(s?o:n.length>0?"(see attached image)":"(no tool output)");const r=[];s&&r.push({type:"input_text",text:v(o)});for(const i of n)r.push({type:"input_image",detail:"auto",image_url:`data:${i.mimeType};base64,${i.data}`});return r}function j(e){const t="This is an incremental tools update. Previously declared tools remain available unless explicitly marked unavailable. A tool declared again here is available again, and its latest definition replaces the earlier one.";return e.size>0?`${t}\nStill unavailable: ${[...e].join(", ")}.`:t}function L(e){return`The following tools are no longer available. Do not call them:\n${e.map(e=>`- ${e}`).join("\n")}`}function U(t,o,n,r){const{input:i,requestTools:p,requestEffortBaseline:l}=function(t,o,n,r){const i=s(o,r?.supportsMidConvoSystemMessages),p=[],l=e=>{const t=e.replace(/[^a-zA-Z0-9_-]/g,"_");return(t.length>64?t.slice(0,64):t).replace(/_+$/,"")},u=R(i.messages,t,(e,o,s)=>{if(!n.has(t.provider))return l(e);if(!e.includes("|"))return l(e);const[r,i]=e.split("|"),a=l(r);let p=s.provider!==t.provider||s.api!==t.api?(e=>{const t=`fc_${m(e)}`;return t.length>64?t.slice(0,64):t})(i):l(i);return p.startsWith("fc_")||(p=l(`fc_${p}`)),`${a}|${p}`}),d=function(e){return e.supportsMidConvoSystemMessages&&e.supportsAdditionalTools?"changes":e.supportsToolSearch?"additions":"none"}(r??{}),f=a(i.messages,d);let g=!1;const h=/* @__PURE__ */new Set,y=(e,t)=>{const o=e.toolsAdded??[];for(const r of o)h.delete(r.name);if(0===o.length)return;if("changes"===d)return g&&p.push({role:I,content:j(h)}),g=!0,void p.push({type:"additional_tools",role:"developer",tools:q(o,r?.toolOptions)});if("additions"!==d)return;const n=o.map(e=>e.name),s=`pi_tool_load_${m(`${t}:${n.join(",")}`)}`;p.push({type:"tool_search_call",call_id:s,execution:"client",status:"completed",arguments:{query:n.join(" "),limit:n.length}}),p.push({type:"tool_search_output",call_id:s,execution:"client",status:"completed",tools:q(o,{...r?.toolOptions,toolSearchResult:!0})})};let _,x;const b=e=>{if("initial"===r?.effortBaseline){if(x===e)return;if(x=e,void 0===_)return void(_=e)}p.push({type:"configuration_update",reasoning:{effort:e}})},w=t.compat,I=t.reasoning&&!1!==w?.supportsDeveloperRole?"developer":"system";let T=0,M=0,S=0;for(const s of u){const o=0===M++&&"system"===s.role;if("system"===s.role){const t=S++>=f.foldedSystemMessages;t&&y(s,`system:${T}`);const n=[o?e(s):c(s)];if(t){const e=new Set((s.toolsAdded??[]).map(e=>e.name)),t=(s.toolsRemoved??[]).map(e=>e.name).filter(t=>!e.has(t));t.length>0&&n.push(L(t));for(const o of t)h.add(o)}const r=n.filter(e=>e.length>0).join("\n\n");r.length>0&&p.push({role:I,content:v(r)})}else if("user"===s.role)if("string"==typeof s.content)p.push({role:"user",content:[{type:"input_text",text:v(s.content)}]});else{const e=s.content.map(e=>"text"===e.type?{type:"input_text",text:v(e.text)}:{type:"input_image",detail:"auto",image_url:`data:${e.mimeType};base64,${e.data}`});if(0===e.length)continue;p.push({role:"user",content:e})}else if("assistant"===s.role){const e=[],o=s,n=o.provider===t.provider&&o.api===t.api,i=n&&o.model===t.id,a=n&&o.model!==t.id;let c=0;for(const t of s.content)if("thinking"===t.type){if(t.thinkingSignature){const o=JSON.parse(t.thinkingSignature);e.push(o)}}else if("text"===t.type){const o=t,n=O(o.textSignature),s=0===c?`msg_pi_${T}`:`msg_pi_${T}_${c}`;c++;let r=n?.id;r?r.length>64&&(r=`msg_${m(r)}`):r=s,e.push({type:"message",role:"assistant",content:[{type:"output_text",text:v(o.text),annotations:[]}],status:"completed",id:r,phase:n?.phase})}else if("toolCall"===t.type){const o=t,[n,s]=o.id.split("|"),p=r?.grammarToolInputProperties?.get(o.name);let c=s;const l=void 0===p?"fc_":"ctc_";!a&&c?.startsWith(l)||(c=void 0);const u={id:c,call_id:n,name:o.name,status:"completed",...i&&void 0!==o.namespace?{namespace:o.namespace}:{}};void 0!==p?e.push({type:"custom_tool_call",...u,input:v(k(o.name,o.arguments,p))}):e.push({type:"function_call",...u,arguments:JSON.stringify(o.arguments)})}if(0===e.length)continue;void 0!==r?.configurationUpdateEffort&&i&&void 0!==s.providerThinkingLevel&&b(s.providerThinkingLevel),p.push(...e)}else if("toolResult"===s.role){const[e]=s.toolCallId.split("|"),o=P(t,s.content);r?.grammarToolInputProperties?.has(s.toolName)?p.push({type:"custom_tool_call_output",call_id:e,output:o}):p.push({type:"function_call_output",call_id:e,output:o})}o||T++}return void 0!==r?.configurationUpdateEffort&&b(r.configurationUpdateEffort),{input:p,requestTools:f.requestTools,requestEffortBaseline:_}}(t,o,n,r);return{input:i,requestTools:q(p,r?.toolOptions),requestEffortBaseline:l}}function q(e,t){const o=void 0!==t?.strict&&t.strict,n=t?.supportsStrictMode??!0,s=t?.supportsOpenAIGrammarTools??!1;return e.map(e=>{const r=w(e,s);if(r)return{type:"custom",name:e.name,description:e.description,format:{type:"grammar",syntax:r.format,definition:r.definition},...t?.toolSearchResult?{defer_loading:!0}:{}};const i=b(e,n)??o,a={type:"function",name:e.name,description:e.description,parameters:M(e,!0===i),...t?.toolSearchResult?{defer_loading:!0}:{}};return n&&(a.strict=i),a})}function N(e,t){const o={input:"",started:!1,closed:!1};return{kind:"custom",property:e,buffer:o,unsent:T(o,e,t)??""}}function W(e,t,o){return D(e,t,T(t.buffer,t.property,o))}function K(e,t,o){return D(e,t,C(t.buffer,t.property,o))}function D(e,t,o){if(e.arguments={[t.property]:t.buffer.input},""===t.unsent)return o;const n=t.unsent+(o??"");return t.unsent="",n}var G=/* @__PURE__ */new Set(["openai","openai-codex","opencode"]);function J(e,t){return"openai"===e.provider&&"https://api.openai.com/v1"===e.baseUrl&&void 0!==t&&!t.startsWith("sk-")}function B(e,t){if(!e)return!1;const o=t.toLowerCase();for(const[n,s]of Object.entries(e))if(n.toLowerCase()===o&&null!==s&&s.trim().length>0)return!0;return!1}function F(e,t,o){if(t)return t;if(B(o,"authorization")||B(o,"cf-aig-authorization"))return"unused";throw new Error(`No API key for provider: ${e}`)}function z(e){return"openrouter"===e.provider||e.baseUrl.includes("openrouter.ai")?"openrouter":"openai"}function H(e,t){return e||("long"===d("PI_CACHE_RETENTION",t)?"long":"short")}function Z(e){return{supportsDeveloperRole:e.compat?.supportsDeveloperRole??!0,supportsMidConvoSystemMessages:e.compat?.supportsMidConvoSystemMessages??!1,sessionAffinityFormat:e.compat?.sessionAffinityFormat??z(e),promptCacheKeyMode:e.compat?.promptCacheKeyMode??"auto",supportsLongCacheRetention:e.compat?.supportsLongCacheRetention??!0,supportsStrictMode:e.compat?.supportsStrictMode??!1,supportsOpenAIGrammarTools:e.compat?.supportsOpenAIGrammarTools??!1,supportsAdditionalTools:e.compat?.supportsAdditionalTools??!1,supportsToolSearch:e.compat?.supportsToolSearch??!1,supportsExplicitPromptCacheMode:e.compat?.supportsExplicitPromptCacheMode??!1,supportsMaxOutputTokens:e.compat?.supportsMaxOutputTokens??!0,supportsMidConvoEffort:e.compat?.supportsMidConvoEffort??!1}}function Y(e,t){return"long"===t&&e.supportsLongCacheRetention&&!e.supportsExplicitPromptCacheMode?"24h":void 0}function Q(e,t){if(e.supportsExplicitPromptCacheMode)return"none"===t?{mode:"explicit"}:"long"===t&&e.supportsLongCacheRetention?{ttl:"30m"}:void 0}var V=(e,n,a)=>{const c=new p,d=s(n,Z(e).supportsMidConvoSystemMessages);return(async()=>{const n=Z(e),s=function(e,t,o){if(o.supportsMidConvoEffort&&t?.reasoningEffort&&!J(e,t.apiKey))return e.thinkingLevelMap?.[t.reasoningEffort]??t.reasoningEffort}(e,a,n),p={role:"assistant",content:[],api:e.api,provider:e.provider,model:e.id,...void 0===s?{}:{providerThinkingLevel:s},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{const m=F(e.provider,a?.apiKey,a?.headers),g="none"===H(a?.cacheRetention,a?.env)?void 0:a?.sessionId,h=x(o(d.messages),n.supportsOpenAIGrammarTools),v=function(e,t,o,n,s,i,a){const p=Z(e),c={...r(e,s),...e.headers};if("github-copilot"===e.provider){const e=u(t.messages),o=f({messages:t.messages,hasImages:e});Object.assign(c,o)}return a&&("openrouter"===p.sessionAffinityFormat?c["x-session-id"]=a:("openai"===p.sessionAffinityFormat&&(c["session-id"]=a),c["x-client-request-id"]=a)),n&&Object.assign(c,n),new $({apiKey:o,baseURL:e.baseUrl,dangerouslyAllowBrowser:!0,fetch:i,defaultHeaders:c})}(e,d,m,a?.headers,a?.identity,a?.fetch,g);let k=function(e,t,o,n,s,r){const{input:i,requestTools:a}=U(e,t,G,{grammarToolInputProperties:s,supportsMidConvoSystemMessages:n.supportsMidConvoSystemMessages,supportsAdditionalTools:n.supportsAdditionalTools,supportsToolSearch:n.supportsToolSearch,toolOptions:{supportsStrictMode:n.supportsStrictMode,supportsOpenAIGrammarTools:n.supportsOpenAIGrammarTools},configurationUpdateEffort:r}),p=H(o?.cacheRetention,o?.env),c="none"!==p&&"disabled"!==n.promptCacheKeyMode,l=J(e,o?.apiKey),u={model:e.id,input:i,stream:!0,prompt_cache_key:c?E(o?.sessionId):void 0,prompt_cache_retention:l?void 0:Y(n,p),prompt_cache_options:l?void 0:Q(n,p),store:!1};o?.maxTokens&&n.supportsMaxOutputTokens&&!l&&(u.max_output_tokens=Math.max(o.maxTokens,16)),void 0===o?.temperature||l||(u.temperature=o?.temperature),void 0!==o?.serviceTier&&(u.service_tier=o.serviceTier),a.length>0&&(u.tools=a),void 0!==o?.toolChoice&&(u.tool_choice=o.toolChoice);const d=o?.reasoningEffort??(o?.reasoningSummary?"medium":void 0);if(e.reasoning){if(d){const t=o?.reasoningEffort?e.thinkingLevelMap?.[o.reasoningEffort]??o.reasoningEffort:d;u.reasoning={effort:void 0===r?t:"medium",summary:o?.reasoningSummary||"auto"},u.include=["reasoning.encrypted_content"]}else"github-copilot"!==e.provider&&null!==e.thinkingLevelMap?.off&&(u.reasoning={effort:e.thinkingLevelMap?.off??"none"});"xai"===e.provider&&(u.include=["reasoning.encrypted_content"])}const m=S(e,d??"off",o?.samplingParams);return m&&Object.assign(u,m),u}(e,d,a,n,h,s);const b=await(a?.onPayload?.(k,e));void 0!==b&&(k=b);const w={...a?.signal?{signal:a.signal}:{},...void 0!==a?.timeoutMs?{timeout:a.timeoutMs}:{},maxRetries:0},{data:I,response:T}=await _(()=>v.responses.create(k,w).withResponse(),{maxRetries:a?.maxRetries,maxRetryDelayMs:a?.maxRetryDelayMs,signal:a?.signal,onErrorResponse:t=>a?.onResponse?.(t,e)});if(await(a?.onResponse?.({status:T.status,headers:y(T.headers)},e)),c.push({type:"start",partial:p}),await async function(e,o,n,s,r){let a=!1;const p=/* @__PURE__ */new Map,c=/* @__PURE__ */new Set,u=/* @__PURE__ */new Map,d=e=>{"message"===e.type&&"final_answer"===e.phase&&(o.stopReason="stop")},m=(e,t)=>{const o=p.get(e);return o?.type===t?o:void 0},f=(e,t)=>{void 0!==t&&n.push({type:"toolcall_delta",contentIndex:e.contentIndex,delta:t,partial:o})},g=(e,t)=>{if("reasoning"===t.type){const t={type:"thinking",thinking:""};o.content.push(t);const s={type:"thinking",block:t,contentIndex:o.content.length-1};return p.set(e,s),n.push({type:"thinking_start",contentIndex:s.contentIndex,partial:o}),s}if("message"===t.type){d(t);const s={type:"text",text:""};o.content.push(s);const r={type:"text",block:s,contentIndex:o.content.length-1};return p.set(e,r),n.push({type:"text_start",contentIndex:r.contentIndex,partial:o}),r}if("function_call"===t.type){const s=new l,r={type:"toolCall",id:`${t.call_id}|${t.id}`,name:t.name,arguments:t.arguments?s.append(t.arguments):{},...void 0!==t.namespace?{namespace:t.namespace}:{}};o.content.push(r),c.add(r);const i={type:"toolCall",block:r,contentIndex:o.content.length-1,input:{kind:"json",arguments:s}};return p.set(e,i),n.push({type:"toolcall_start",contentIndex:i.contentIndex,partial:o}),i}if("custom_tool_call"===t.type){const s=r?.grammarToolInputProperties?.get(t.name)??"input",i=t.input||"",a={type:"toolCall",id:`${t.call_id}|${t.id}`,name:t.name,arguments:{[s]:i},...void 0!==t.namespace?{namespace:t.namespace}:{}};o.content.push(a),c.add(a);const l={type:"toolCall",block:a,contentIndex:o.content.length-1,input:N(s,i)};return p.set(e,l),n.push({type:"toolcall_start",contentIndex:l.contentIndex,partial:o}),l}},h=(e,t)=>p.get(e)??g(e,t),y=e=>{if(a=!0,(e=>{for(const t of e){if("reasoning"!==t.type||!t.encrypted_content)continue;const e=u.get(t.id);if(!e?.thinkingSignature)continue;const o=JSON.parse(e.thinkingSignature);o.encrypted_content||(e.thinkingSignature=JSON.stringify({...o,encrypted_content:t.encrypted_content}))}})(e.output??[]),function(e,t){if(!Array.isArray(t))return;const o=t.filter(e=>"reasoning"===e?.type&&"removed"===e.action&&"turn_boundary"!==e.reason);0!==o.length&&i(e,{type:"openai_input_transformations",timestamp:Date.now(),details:{transformations:o.map(({type:e,id:t,action:o,reason:n})=>({type:e,id:t,action:o,reason:n}))}})}(o,e.input_transformations),e?.id&&(o.responseId=e.id),e?.usage){const t=e.usage.input_tokens_details,n=t?.cached_tokens||0,s=t?.cache_write_tokens||0;o.usage={input:Math.max(0,(e.usage.input_tokens||0)-n-s),output:e.usage.output_tokens||0,cacheRead:n,cacheWrite:s,reasoning:e.usage.output_tokens_details?.reasoning_tokens||0,totalTokens:e.usage.total_tokens||0,cost:{input:0,output:0,cacheRead:0,cacheWrite:0,total:0}}}if(t(s,o.usage),r?.applyServiceTierPricing){const t=r.resolveServiceTier?r.resolveServiceTier(e?.service_tier,r.serviceTier):e?.service_tier??r.serviceTier;r.applyServiceTierPricing(o.usage,t)}const n=e?.status,p=e?.incomplete_details,c="string"==typeof p?.reason?p.reason:void 0;o.rawStopReason=c?`${n}.${c}`:n;const l=function(e,t){if(!e)return{stopReason:"stop"};switch(e){case"completed":case"in_progress":case"queued":return{stopReason:"stop"};case"incomplete":return"max_output_tokens"===t?{stopReason:"length"}:{stopReason:"error",errorMessage:t?`Response incomplete: ${t}`:"Response incomplete without a provider reason"};case"failed":case"cancelled":return{stopReason:"error"};default:throw new Error(`Unhandled stop reason: ${e}`)}}(n,c);o.stopReason=l.stopReason,void 0===l.errorMessage?delete o.errorMessage:o.errorMessage=l.errorMessage,o.content.some(e=>"toolCall"===e.type)&&"stop"===o.stopReason&&(o.stopReason="toolUse")};for await(const t of e)if(await(r?.onProviderStreamEvent?.(t,s)),"response.created"===t.type)o.responseId=t.response.id;else if("response.output_item.added"===t.type)g(t.output_index,t.item);else if("response.reasoning_summary_text.delta"===t.type){const e=m(t.output_index,"thinking");if(!e)continue;e.block.thinking+=t.delta,n.push({type:"thinking_delta",contentIndex:e.contentIndex,delta:t.delta,partial:o})}else if("response.reasoning_summary_part.done"===t.type){const e=m(t.output_index,"thinking");if(!e)continue;e.block.thinking+="\n\n",n.push({type:"thinking_delta",contentIndex:e.contentIndex,delta:"\n\n",partial:o})}else if("response.reasoning_text.delta"===t.type){const e=m(t.output_index,"thinking");if(!e)continue;e.block.thinking+=t.delta,n.push({type:"thinking_delta",contentIndex:e.contentIndex,delta:t.delta,partial:o})}else if("response.output_text.delta"===t.type){const e=m(t.output_index,"text");if(!e)continue;e.block.text+=t.delta,n.push({type:"text_delta",contentIndex:e.contentIndex,delta:t.delta,partial:o})}else if("response.refusal.delta"===t.type){const e=m(t.output_index,"text");if(!e)continue;e.block.text+=t.delta,n.push({type:"text_delta",contentIndex:e.contentIndex,delta:t.delta,partial:o})}else if("response.function_call_arguments.delta"===t.type){const e=m(t.output_index,"toolCall");if("json"!==e?.input.kind)continue;e.block.arguments=e.input.arguments.append(t.delta),f(e,t.delta)}else if("response.function_call_arguments.done"===t.type){const e=m(t.output_index,"toolCall");if("json"!==e?.input.kind)continue;const o=e.input.arguments.replace(t.arguments);e.block.arguments=o.arguments,o.delta&&f(e,o.delta)}else if("response.custom_tool_call_input.delta"===t.type){const e=m(t.output_index,"toolCall");if("custom"!==e?.input.kind)continue;f(e,W(e.block,e.input,t.delta))}else if("response.custom_tool_call_input.done"===t.type){const e=m(t.output_index,"toolCall");if("custom"!==e?.input.kind)continue;f(e,K(e.block,e.input,t.input))}else if("response.output_item.done"===t.type){const e=t.item;d(e);const s=h(t.output_index,e);if("reasoning"===e.type&&"thinking"===s?.type){const r=e.summary?.map(e=>e.text).join("\n\n")||"",i=e.content?.map(e=>e.text).join("\n\n")||"";s.block.thinking=r||i||s.block.thinking,s.block.thinkingSignature=JSON.stringify(e),u.set(e.id,s.block),n.push({type:"thinking_end",contentIndex:s.contentIndex,content:s.block.thinking,partial:o}),p.delete(t.output_index)}else"message"===e.type&&"text"===s?.type?(s.block.text=e.content?.map(e=>"output_text"===e.type?e.text:e.refusal).join("")||"",s.block.textSignature=A(e.id,e.phase??void 0),n.push({type:"text_end",contentIndex:s.contentIndex,content:s.block.text,partial:o}),p.delete(t.output_index)):"function_call"===e.type&&"toolCall"===s?.type&&"json"===s.input.kind?(e.arguments&&s.input.arguments.replace(e.arguments),Object.assign(s.block,s.input.arguments.finish()),void 0!==e.namespace&&(s.block.namespace=e.namespace),c.delete(s.block),n.push({type:"toolcall_end",contentIndex:s.contentIndex,toolCall:s.block,partial:o}),p.delete(t.output_index)):"custom_tool_call"===e.type&&"toolCall"===s?.type&&"custom"===s.input.kind&&(f(s,K(s.block,s.input,e.input)),void 0!==e.namespace&&(s.block.namespace=e.namespace),c.delete(s.block),n.push({type:"toolcall_end",contentIndex:s.contentIndex,toolCall:s.block,partial:o}),p.delete(t.output_index))}else if("response.completed"===t.type||"response.incomplete"===t.type)y(t.response);else{if("error"===t.type)throw new Error(`Error Code ${t.code}: ${t.message}`||"Unknown error");if("response.failed"===t.type){a=!0,o.rawStopReason=t.response?.status;const e=t.response?.error,n=t.response?.incomplete_details,s=e?`${e.code||"unknown"}: ${e.message||"no message"}`:n?.reason?`incomplete: ${n.reason}`:"Unknown error (no error details in response)";throw new Error(s)}}if(!a)throw new Error("OpenAI Responses stream ended before a terminal response event");if("toolUse"===o.stopReason)for(const t of c)throw new Error(`OpenAI Responses stream completed with an unfinished tool call: ${t.name} (${t.id})`)}(I,p,c,e,{onProviderStreamEvent:a?.onProviderStreamEvent,serviceTier:a?.serviceTier,grammarToolInputProperties:h,applyServiceTierPricing:(t,o)=>function(e,t,o){const n=function(e,t){switch(t){case"flex":return.5;case"priority":case"fast":return"gpt-5.5"===e.id?2.5:2;default:return 1}}(o,t);1!==n&&(e.cost.input*=n,e.cost.output*=n,e.cost.cacheRead*=n,e.cost.cacheWrite*=n,e.cost.total=e.cost.input+e.cost.output+e.cost.cacheRead+e.cost.cacheWrite)}(t,o,e)}),a?.signal?.aborted)throw new Error("Request was aborted");if("pending"===p.stopReason)throw new Error("OpenAI Responses stream ended without a stop reason");if("aborted"===p.stopReason||"error"===p.stopReason)throw new Error(p.errorMessage||"An unknown error occurred");c.push({type:"done",reason:p.stopReason,message:p}),c.end()}catch(m){p.stopReason=a?.signal?.aborted?"aborted":"error";const t=h(g(m),`${"openai"===e.provider?"OpenAI":e.provider} API error`);t.includes("subscription_sharing_usage_limit_exceeded")?p.errorMessage=`${t}\nCheck your ChatGPT usage: https://chatgpt.com/settings/usage`:t.includes("subscription_sharing_workplace_individual_usage_limit_exceeded")?p.errorMessage=`${t}\nYou've reached your ChatGPT workspace's usage limit. Ask your workspace admin to increase it at admin.openai.com → Workspace → Usage limits.`:p.errorMessage=t,c.push({type:"error",reason:p.stopReason,error:p}),c.end()}})(),c},X=(e,t,o)=>{F(e.provider,o?.apiKey,o?.headers);const s={...I(e,t,o,o?.apiKey),toolChoice:o?.toolChoice},r=o?.reasoning?n(e,o.reasoning):void 0;return V(e,t,{...s,reasoningEffort:"off"===r?void 0:r})};export{V as stream,X as streamSimple};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
void 0===globalThis.process&&(globalThis.process={env:{},platform:"browser",version:"",versions:{},browser:!0,nextTick:function(e){return Promise.resolve().then(e)}});import{et as e}from"./LanguageSelect-vGM6rIrX.js";function t(t){if(!(t instanceof Error))return{message:a(t),messageCarriesBody:!1};const s=t,n=function(e){return"number"==typeof e.statusCode?e.statusCode:"number"==typeof e.status?e.status:"number"==typeof e.$metadata?.httpStatusCode?e.$metadata.httpStatusCode:"number"==typeof e.$response?.statusCode?e.$response.statusCode:void 0}(s),i=function(t){const s=function(e){if("string"==typeof e.body)return e.body;if(o(e.error))return a(e.error);const t=e.$response?.body;return"string"==typeof t?t:"object"==typeof(s=t)&&null!==s&&"pipe"in s&&"function"==typeof s.pipe?void 0:o(t)?a(t):void 0;var s}(t);if(void 0===s)return;const r=s.trim();return 0===r.length?void 0:(i=4e3,(n=r).length<=i?n:`${e(n,0,i)}... [truncated ${n.length-i} chars]`);var n,i}(s),u=void 0===i||t.message.includes(i);return{status:n,body:i,message:void 0===n&&void 0===i?r(t):t.message,messageCarriesBody:u}}var s=5;function r(e){let t,r=e.cause;for(let a=0;a<s&&r instanceof Error;a++)t=r,r=r.cause;if(!t)return e.message;let o=(t.message||t.name).trim();const n=t.code;return"string"!=typeof n&&"number"!=typeof n||o.includes(String(n))||(o=o?`${o} (${n})`:String(n)),!o||e.message.includes(o)?e.message:e.message?`${e.message}: ${o}`:o}function o(e){if("object"!=typeof e||null===e)return!1;const t=Object.getPrototypeOf(e);return(t===Object.prototype||null===t)&&Object.keys(e).length>0}function n(e,t){return e.messageCarriesBody||void 0===e.status||void 0===e.body?void 0!==t&&void 0!==e.status?`${t} (${e.status}): ${e.message}`:e.message:void 0!==t?`${t} (${e.status}): ${e.body}`:`${e.status}: ${e.body}`}function a(e){try{const t=JSON.stringify(e);return void 0===t?String(e):t}catch{return String(e)}}function i(e){const t={};for(const[s,r]of e.entries())t[s]=r;return t}function u(...e){const t=/* @__PURE__ */new Map;for(const s of e)for(const[e,r]of Object.entries(s??{})){const s=e.toLowerCase();t.delete(s),null!==r&&t.set(s,[e,r])}return t.size>0?Object.fromEntries(t.values()):void 0}function c(e){return e instanceof Error&&"status"in e&&"headers"in e&&(void 0===e.status||"number"==typeof e.status)&&(void 0===e.headers||e.headers instanceof Headers)}function f(e){const t=e.headers?.get("x-should-retry");return"true"===t||"false"!==t&&(void 0===e.status||408===e.status||409===e.status||429===e.status||"number"==typeof e.status&&e.status>=500)}function d(e,t,s){const r=t??6e4;if(r>0&&e>r)throw new Error(`Server requested ${Math.ceil(e/1e3)}s retry delay (max: ${Math.ceil(r/1e3)}s). ${s}`);return e}function m(e,t,s){const r=e.headers?.get("retry-after-ms");if(r){const t=Number.parseFloat(r);if(Number.isFinite(t))return d(t,s,e.message)}const o=e.headers?.get("retry-after");if(o){const t=Number.parseFloat(o),r=Number.isNaN(t)?Date.parse(o)-Date.now():1e3*t;if(Number.isFinite(r))return d(r,s,e.message)}return 1e3*Math.min(.5*2**t,8)*(1-.25*Math.random())}function l(){const e=/* @__PURE__ */new Error("Request aborted");return e.name="AbortError",e}function g(e,t){return new Promise((s,r)=>{if(t?.aborted)return void r(l());const o=()=>{clearTimeout(n),r(l())},n=setTimeout(()=>{t?.removeEventListener("abort",o),s()},Math.max(0,e));t?.addEventListener("abort",o,{once:!0})})}async function y(e,t={}){const s=t.maxRetries??0;let r=s;for(;;)try{return await e()}catch(o){if(t.signal?.aborted)throw l();if(c(o)&&void 0!==o.status){const e=o.headers?i(o.headers):{};await(t.onErrorResponse?.({status:o.status,headers:e}))}if(r<=0||!c(o)||!f(o))throw o;if(void 0!==o.status&&t.noRetryStatuses?.includes(o.status))throw o;const e=s-r;r--,await g(m(o,e,t.maxRetryDelayMs),t.signal)}}export{t as a,n as i,i as n,r as o,u as r,y as t};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
void 0===globalThis.process&&(globalThis.process={env:{},platform:"browser",version:"",versions:{},browser:!0,nextTick:function(e){return Promise.resolve().then(e)}});import{$ as e,I as t}from"./LanguageSelect-vGM6rIrX.js";function r(e){return e.replace(/[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?<![\uD800-\uDBFF])[\uDC00-\uDFFF]/g,"")}var n=class extends Error{},o=["$ref","$defs","definitions","allOf","oneOf","patternProperties","dependentSchemas","dependencies","unevaluatedProperties","propertyNames","contains","prefixItems","not","if","then","else"];function i(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)}function s(e){if(!i(e))return!1;const t="string"==typeof e.type?[e.type]:Array.isArray(e.type)?e.type:[];return t.includes("object")||t.includes("array")||void 0!==e.properties||void 0!==e.items}function a(e){return!!i(e)&&(!!("null"===e.type||Array.isArray(e.type)&&e.type.includes("null"))||!!(null===e.const||Array.isArray(e.enum)&&e.enum.includes(null))||Array.isArray(e.anyOf)&&e.anyOf.some(e=>a(e)))}function u(e,t){if(!i(e))throw new n("boolean schemas are unsupported");for(const i of o)if(void 0!==e[i])throw new n(`${i} schemas are unsupported`);if(t)for(const[o,i]of Object.entries(e))if(t(o,i))throw new n(`${o}: ${JSON.stringify(i)} is unsupported`);if(void 0===e.type&&void 0===e.anyOf&&void 0===e.enum)throw new n("schemas without a type are unsupported");if(void 0!==e.anyOf){if(!Array.isArray(e.anyOf)||0===e.anyOf.length)throw new n("anyOf must contain at least one schema");for(const r of e.anyOf){if(s(r))throw new n("object and array unions are unsupported");u(r,t)}}if(void 0!==e.items){if(Array.isArray(e.items))throw new n("tuple schemas are unsupported");u(e.items,t)}const r="object"===e.type;if(void 0!==e.properties&&!r)throw new n("properties require type object");if(!r)return;if(void 0!==e.additionalProperties&&!1!==e.additionalProperties)throw new n("schema-valued or true additionalProperties is unsupported");if(void 0!==e.properties&&!i(e.properties))throw new n("object properties must be a schema map");if(void 0!==e.required&&(!Array.isArray(e.required)||e.required.some(e=>"string"!=typeof e)))throw new n("object required must be a string array");const l=e.properties??{},c=Object.keys(l),p=new Set(Array.isArray(e.required)?e.required:[]);if([...p].some(e=>!c.includes(e)))throw new n("required contains an unknown property");for(const[n,o]of Object.entries(l))u(o,t),p.has(n)||a(o)||(l[n]={anyOf:[o,{type:"null"}]});e.required=c,e.additionalProperties=!1}function l(e,t){const r=structuredClone(e);if(!i(r))throw new n("root schema must have type object");if(u(r,t),"object"!==r.type)throw new n("root schema must have type object");return r}function c(e){const t=e.constrainedSampling;return!!t&&"json_schema"===t.type&&"prefer"===t.strict}function p(e,t){return!0===t?l(e.parameters):e.parameters}function m(e,t,r){const n=t[r];if("string"!=typeof n)throw new Error(`Grammar tool call "${e}" requires argument "${r}" to be a string.`);return n}function f(e,t,r){if(e.closed)throw new Error(`grammar tool input for property "${t}" changed after it was closed`);if(0!==r.length)return e.input+=r,h(e,t)+JSON.stringify(r).slice(1,-1)}function d(e,t,r){if(e.closed){if(void 0===r||r===e.input)return;throw new Error(`grammar tool input for property "${t}" changed after it was closed`)}if(void 0!==r&&!r.startsWith(e.input))throw new Error(`grammar tool input for property "${t}" changed non-monotonically`);const n=void 0===r?"":r.slice(e.input.length);return void 0!==r&&(e.input=r),e.closed=!0,`${h(e,t)}${JSON.stringify(n).slice(1,-1)}"}`}function h(e,t){return e.started?"":(e.started=!0,`{${JSON.stringify(t)}:"`)}function g(e){const t=e.parameters;if("object"!==t.type)throw new Error("grammar constrained sampling requires an object parameter schema");if(!Array.isArray(t.required)||1!==t.required.length||"string"!=typeof t.required[0])throw new Error("grammar constrained sampling requires exactly one required string property");const r=t.required[0];if(!t.properties?.[r])throw new Error(`grammar constrained sampling requires a properties entry for ${r}`);if("string"!==t.properties[r]?.type)throw new Error(`grammar constrained sampling property ${r} must have type string`);return r}function y(e,t,r){const o=e.constrainedSampling;if(o&&"json_schema"===o.type){if(t)try{return l(e.parameters,r),!0}catch(i){if(!(i instanceof n))throw i;if("require"!==o.strict)return;throw new Error(`Tool "${e.name}" requires JSON-schema constrained sampling, but ${i.message}.`)}if("require"===o.strict)throw new Error(`Tool "${e.name}" requires JSON-schema constrained sampling, but strict tools are unsupported.`)}}function w(e,t){const r=e.constrainedSampling;if(!r||"grammar"!==r.type)return;if(!t)return;const n=r.variants.openai_lark,o=r.variants.openai_regex,i="string"==typeof n&&n.trim().length>0,s="string"==typeof o&&o.trim().length>0;if(!i&&!s)throw new Error(`Tool "${e.name}" cannot use grammar constrained sampling: no supported grammar variant was provided.`);try{return{format:i?"lark":"regex",definition:i?n:o,inputProperty:g(e)}}catch(a){const t=a instanceof Error?a.message:String(a);throw new Error(`Tool "${e.name}" cannot use grammar constrained sampling: ${t}.`)}}function v(e,t){const r=/* @__PURE__ */new Map;for(const n of e??[]){const e=w(n,t);e&&r.set(n.name,e.inputProperty)}return r}function x(e){return e.totalTokens||e.input+e.output+e.cacheRead+e.cacheWrite}function b(e){try{return JSON.stringify(e)??"undefined"}catch{return"[unserializable]"}}function k(e){return Math.ceil(e.length/3.5)}function A(e){return Math.ceil(function(e){if("string"==typeof e)return e.length;let t=0;for(const r of e)t+="text"===r.type?r.text.length:4800;return t}(e)/3.5)}function $(t){let r=0;if("system"===t.role)return k(e(t))+q(t.toolsAdded)+q(t.toolsRemoved);if("user"===t.role)return A(t.content);if("toolResult"===t.role)return A(t.content);for(const e of t.content)"text"===e.type?r+=e.text.length:"thinking"===e.type?r+=e.thinking.length:r+=e.name.length+b(e.arguments).length;return Math.ceil(r/3.5)}function q(e){return e&&0!==e.length?k(b(e)):0}function M(e,t,r){if(e.contextWindow<=0)return Math.max(1,r);const n=function(e){const t="messages"in e?e.messages:e,r=function(e){let t,r=Number.NEGATIVE_INFINITY;for(let n=0;n<e.length;n++){const o=e[n];if("assistant"===o.role){const e=o;e.timestamp>=r&&"aborted"!==e.stopReason&&"error"!==e.stopReason&&x(e.usage)>0&&(t={usage:e.usage,index:n})}r=Math.max(r,o.timestamp)}return t}(t);if(r){const e=x(r.usage);let n=0;for(let o=r.index+1;o<t.length;o++)n+=$(t[o]);return{tokens:e+n,usageTokens:e,trailingTokens:n,lastUsageIndex:r.index}}let n=0;for(const o of t)n+=$(o);return{tokens:n,usageTokens:0,trailingTokens:n,lastUsageIndex:null}}(t).tokens,o=Math.max(4096,Math.ceil(.15*n));let i=e.contextWindow-n-o;return i<32768&&(i=Math.min(32768,e.contextWindow-n-4096)),Math.min(r,Math.max(1,i))}function S(e,r,n){const o=t(e,r),i=e.samplingParamsByThinkingLevel?.[o];return e.samplingParams||i||n?{...e.samplingParams,...i,...n}:void 0}function O(e,t,r,n){const o=S(e,r?.reasoning??"off",r?.samplingParams);return{temperature:r?.temperature,samplingParams:o,maxTokens:M(e,t,r?.maxTokens??e.maxTokens),signal:r?.signal,telemetry:r?.telemetry,apiKey:n||r?.apiKey,fetch:r?.fetch,transport:r?.transport,cacheRetention:r?.cacheRetention,sessionId:r?.sessionId,disableContinuation:r?.disableContinuation,headers:r?.headers,identity:r?.identity,onPayload:r?.onPayload,onResponse:r?.onResponse,onProviderStreamEvent:r?.onProviderStreamEvent,timeoutMs:r?.timeoutMs,websocketConnectTimeoutMs:r?.websocketConnectTimeoutMs,maxRetries:r?.maxRetries,maxRetryDelayMs:r?.maxRetryDelayMs,metadata:r?.metadata,env:r?.env}}var T={minimal:1024,low:2048,medium:8192,high:16384};function E(e,t){return{...T,...t}[r=e,"xhigh"===r||"max"===r?"high":r];var r}function R(e,t){return Math.min(e,Math.max(0,t-1024))}function j(e,t,r,n){let o=E(r,n);const i=void 0===e?t:Math.min(e+o,t);return i<=o&&(o=R(o,i)),{maxTokens:i,thinkingBudget:o}}function P(e){if(!e.isError)return;const t=e.content.filter(e=>"image"===e.type);return 0!==t.length?{content:I(e.content,"(image attached after the tool results)"),caption:`Images from the error result of tool call ${e.toolCallId} (${e.toolName}):`,images:t}:void 0}function I(e,t){const r=[];let n=!1;for(const o of e)"image"!==o.type?(r.push(o),n=o.text===t):(n||r.push({type:"text",text:t}),n=!0);return r}function C(e,t,r){const n=/* @__PURE__ */new Map,o=function(e,t){return t.input.includes("image")?e:e.map(e=>"user"===e.role&&Array.isArray(e.content)?{...e,content:I(e.content,"(image omitted: model does not support images)")}:"toolResult"===e.role?{...e,content:I(e.content,"(tool image omitted: model does not support images)")}:e)}(e.map(e=>null==e.content?{...e,content:[]}:e),t).map(e=>{if("system"===e.role||"user"===e.role)return e;if("toolResult"===e.role){const t=n.get(e.toolCallId);return t&&t!==e.toolCallId?{...e,toolCallId:t}:e}if("assistant"===e.role){const o=e,i=o.provider===t.provider&&o.api===t.api&&o.model===t.id,s=o.content.flatMap(e=>{if("thinking"===e.type)return i&&(e.redacted||e.thinkingSignature||e.thinking&&""!==e.thinking.trim())?e:[];if("text"===e.type)return i?e:{type:"text",text:e.text};if("toolCall"===e.type){const s=e;let a=s;if(!i&&s.thoughtSignature&&(a={...s},delete a.thoughtSignature),!i&&r){const e=r(s.id,t,o);e!==s.id&&(n.set(s.id,e),a={...a,id:e})}return a}return e});return{...o,content:s}}return e}),i=[];let s=[],a=/* @__PURE__ */new Set;const u=[],l=()=>{if(s.length>0){for(const e of s)a.has(e.id)||i.push({role:"toolResult",toolCallId:e.id,toolName:e.name,content:[{type:"text",text:"No result provided"}],isError:!0,timestamp:Date.now()});s=[],a=/* @__PURE__ */new Set}i.push(...u),u.length=0};for(let c=0;c<o.length;c++){const e=o[c];if("assistant"===e.role){l();const t=e;if("error"===t.stopReason||"aborted"===t.stopReason)continue;const r=t.content.filter(e=>"toolCall"===e.type);r.length>0&&(s=r,a=/* @__PURE__ */new Set),i.push(e)}else"toolResult"===e.role?(a.add(e.toolCallId),i.push(e)):"system"===e.role?s.length>0?u.push(e):i.push(e):"user"===e.role?(l(),i.push(e)):i.push(e)}return l(),i}export{r as _,M as a,E as c,v as d,m as f,y as g,w as h,O as i,f as l,c as m,C as n,R as o,p,j as r,S as s,P as t,d as u};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hintergrund/ui",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.33",
|
|
4
4
|
"files": [
|
|
5
5
|
"dist"
|
|
6
6
|
],
|
|
@@ -27,15 +27,15 @@
|
|
|
27
27
|
"terser": "^5.44.0",
|
|
28
28
|
"typescript": "^5.9.2",
|
|
29
29
|
"vite": "^8.3.0",
|
|
30
|
-
"@hintergrund/
|
|
31
|
-
"@hintergrund/
|
|
30
|
+
"@hintergrund/sveltekit-static-preview": "0.1.0",
|
|
31
|
+
"@hintergrund/worker": "0.3.33"
|
|
32
32
|
},
|
|
33
33
|
"keywords": [
|
|
34
34
|
"svelte"
|
|
35
35
|
],
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@earendil-works/pi-agent-core": "^1.
|
|
38
|
-
"@earendil-works/pi-ai": "^1.
|
|
37
|
+
"@earendil-works/pi-agent-core": "^1.7.0",
|
|
38
|
+
"@earendil-works/pi-ai": "^1.7.0",
|
|
39
39
|
"@jridgewell/sourcemap-codec": "^1.5.5",
|
|
40
40
|
"@primer/octicons": "^19.19.0",
|
|
41
41
|
"@rich_harris/svelte-split-pane": "^3.0.0",
|