@lunora/agent 1.0.0-alpha.276 → 1.0.0-alpha.278
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 -2
- package/dist/channels.d.mts +2 -2
- package/dist/channels.d.ts +2 -2
- package/dist/channels.mjs +1 -1
- package/dist/component.mjs +1 -1
- package/dist/core.d.mts +204 -0
- package/dist/core.d.ts +204 -0
- package/dist/core.mjs +1 -0
- package/dist/inbound.d.mts +4 -4
- package/dist/inbound.d.ts +4 -4
- package/dist/inbound.mjs +1 -1
- package/dist/index.d.mts +7 -167
- package/dist/index.d.ts +7 -167
- package/dist/index.mjs +1 -1
- package/dist/packem_chunks/createAgentGenerate.mjs +3 -0
- package/dist/packem_chunks/otlpTelemetry.mjs +1 -0
- package/dist/packem_chunks/resolve-run.mjs +1 -0
- package/dist/packem_chunks/runAgentLoop.mjs +3 -0
- package/dist/packem_shared/SecretUnavailableError-DOy2M4Ak.mjs +1 -0
- package/dist/packem_shared/VoiceSessionDO-CdvG2L-D.mjs +1 -0
- package/dist/packem_shared/{adaptMcpResult-DOud9k_Q.mjs → adaptMcpResult-CA-3ovJd.mjs} +1 -1
- package/dist/packem_shared/agentAsTool-BF-7Dnzy.mjs +1 -0
- package/dist/packem_shared/app-call-options-BE0CQ6Qg.mjs +1 -0
- package/dist/packem_shared/codeTool-Cn8TuNjk.mjs +1 -0
- package/dist/packem_shared/collectAgenticMemoryTools-X7AqELV3.mjs +1 -0
- package/dist/packem_shared/compileAgentWorkflow-yZB8fbYc.mjs +1 -0
- package/dist/packem_shared/component-shared--SPcu0Iw.mjs +1 -0
- package/dist/packem_shared/createAgentContext-C8k1y2Ot.mjs +1 -0
- package/dist/packem_shared/defineAgent-6Ih7L9E9.mjs +3 -0
- package/dist/packem_shared/functionTool-Cf433Hdo.mjs +1 -0
- package/dist/packem_shared/inbound-shard-A7S7dnf_.mjs +1 -0
- package/dist/packem_shared/{jsCodeTool-Bh4jaeoy.mjs → jsCodeTool-BJB3Fpm2.mjs} +1 -1
- package/dist/packem_shared/jsonSchema-fhoaBWpN.mjs +1 -0
- package/dist/packem_shared/memory-JI0lUu84.mjs +1 -0
- package/dist/packem_shared/{normalizeEntityName-Rr5OQxhc.mjs → normalizeEntityName-BiUH5B5W.mjs} +1 -1
- package/dist/packem_shared/run-shard-B7iMrAI0.mjs +1 -0
- package/dist/packem_shared/runVoiceTurn-DPa5UZ45.mjs +1 -0
- package/dist/packem_shared/{types.d-vAmttAsE.d.mts → types.d-Bzy_Qah6.d.mts} +81 -2
- package/dist/packem_shared/{types.d-vAmttAsE.d.ts → types.d-Bzy_Qah6.d.ts} +81 -2
- package/dist/packem_shared/voice-turn-B9omvXoR.mjs +1 -0
- package/dist/packem_shared/webSearchTool-BzXW0R4r.mjs +1 -0
- package/dist/packem_shared/withAgentScheduleShard-Bn3bdW5b.mjs +1 -0
- package/dist/reply.d.mts +1 -1
- package/dist/reply.d.ts +1 -1
- package/dist/sandbox.d.mts +1 -1
- package/dist/sandbox.d.ts +1 -1
- package/dist/sandbox.mjs +1 -1
- package/dist/skill-markdown.d.mts +1 -1
- package/dist/skill-markdown.d.ts +1 -1
- package/dist/telemetry/index.mjs +1 -1
- package/package.json +5 -1
- package/dist/packem_shared/SecretUnavailableError-D8u6pPM6.mjs +0 -1
- package/dist/packem_shared/VoiceSessionDO-D4dEV12P.mjs +0 -1
- package/dist/packem_shared/agent-loop-C11GY0Yw.mjs +0 -3
- package/dist/packem_shared/agentAsTool-ifwGRMR6.mjs +0 -1
- package/dist/packem_shared/codeTool-BZkKDqsZ.mjs +0 -1
- package/dist/packem_shared/collectAgenticMemoryTools-Dxs7mpo6.mjs +0 -1
- package/dist/packem_shared/compileAgentWorkflow-DDQ-_8S0.mjs +0 -1
- package/dist/packem_shared/component-shared-DdXFbng-.mjs +0 -1
- package/dist/packem_shared/createAgentContext-CjdW-jip.mjs +0 -1
- package/dist/packem_shared/createAgentGenerate-CTkL_e0Z.mjs +0 -3
- package/dist/packem_shared/defineAgent-BsDM3vh8.mjs +0 -3
- package/dist/packem_shared/functionTool-C95ns65V.mjs +0 -1
- package/dist/packem_shared/json-schema-CHVg-SsJ.mjs +0 -1
- package/dist/packem_shared/otlpTelemetry-CiSI9HE_.mjs +0 -1
- package/dist/packem_shared/runAgentLoop-8K0vPhGY.mjs +0 -1
- package/dist/packem_shared/runVoiceTurn-C4BAG61O.mjs +0 -1
- package/dist/packem_shared/voice-turn-BjkorohD.mjs +0 -1
- package/dist/packem_shared/webSearchTool-DUubGqov.mjs +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{a as f}from"./DEFAULT_DISPATCH_TIMEOUT_MS-DiRHEqJU-BRtWNzq1.mjs";import{LunoraError as o}from"@lunora/errors";import{h as g,B as w}from"./branch-marker-boZ00zmk.mjs";import{r as h}from"./workflow-binding-Dm9hBzx_.mjs";import{toFunctionReference as E,DEFAULT_AGENT_FUNCTION_PATHS as N}from"./AGENT_MODULE-CYBmT9SD.mjs";const _=(r,c,i={})=>{const{dispatch:u,exports:l}=i,s={},d=E(N.patchThread),p=()=>u??f({env:r,label:"@lunora/agent"});for(const e of c){const n=()=>{const t=h(r,l,e.className,["create","get"]);if(t===void 0)throw new o("INTERNAL",`@lunora/agent: no "${e.className}" on ctx.exports or env for agent "${e.exportName}" — run codegen/dev so wrangler.jsonc declares it`);return t};s[e.exportName]={cancel:async t=>{await(await n().get(t)).terminate();try{await p()(d,{instanceId:t,status:"cancelled"})}catch{}},publicRun:e.publicRun===!0,run:async(t,a)=>{if(g(t))throw new o("BAD_REQUEST",`@lunora/agent: run input ${w}`);return{id:(await n().create({...a?.id===void 0?{}:{id:a.id},params:t})).id}},sendEvent:async(t,a)=>{await(await n().get(t)).sendEvent(a)},status:async t=>(await n().get(t)).status()}}return s};export{_ as default};
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import{usageStatus as O}from"@lunora/ai/create";import{LunoraError as j}from"@lunora/errors";import{r as P}from"./agent-ai-CP87uSoZ.mjs";import{j as R}from"./json-schema-CHVg-SsJ.mjs";import{F as v,s as b}from"./common-DBc9y7Np.mjs";const m=e=>({...e,status:O(e)}),k=e=>m(b(e)),x=e=>e.map(t=>{const o={id:t.toolCallId,input:t.input,name:t.toolName};return t.invalid!==!0?o:{...o,invalid:t.error instanceof Error?t.error.message:String(t.error)}}),h=(e,t)=>{if(typeof e=="function")return e(t);if(typeof e=="string"){const o=P(t);if(!o)throw new j("INTERNAL",`@lunora/agent: the agent model "${e}" is a Workers AI id but there is no \`AI\` binding on the workflow env — declare the ai binding in wrangler.jsonc`);return o.model(e)}return e};let T;const f=()=>(T??=import("ai").catch(e=>{throw T=void 0,e}),T),q=(e,t,o)=>{const r=h(t.model,o),n={};for(const[a,u]of Object.entries(t.tools??{}))n[a]=e.tool({description:u.description,inputSchema:e.asSchema(u.inputSchema)});const i=t.output===void 0?void 0:e.Output.object({schema:t.output}),s={...t.temperature===void 0?{}:{temperature:t.temperature},...t.maxOutputTokens===void 0?{}:{maxOutputTokens:t.maxOutputTokens},...t.telemetry===void 0?{}:{telemetry:t.telemetry},...t.repairToolCall===void 0?{}:{experimental_repairToolCall:t.repairToolCall}};return{defaultModel:r,output:i,staticSettings:s,tools:n}},E=(e,t)=>{let o;return()=>(o??=f().then(r=>({ai:r,base:q(r,e,t)})).catch(r=>{throw o=void 0,r}),o)},S=(e,{activeTools:t,messages:o,model:r,signal:n,toolChoice:i})=>{const{defaultModel:s,output:a,staticSettings:u,tools:l}=e,d=t===void 0?l:Object.fromEntries(Object.entries(l).filter(([g])=>t.includes(g)));return{messages:o,model:r??s,...u,...Object.keys(d).length>0?{tools:d}:{},...i===void 0?{}:{toolChoice:i},...a===void 0?{}:{output:a},...n===void 0?{}:{abortSignal:n}}},M=e=>e instanceof Error?e:new Error(`model stream failed: ${String(e)}`,{cause:e}),N=e=>({inputTokens:{cacheRead:e?.inputTokens?.cacheRead,cacheWrite:e?.inputTokens?.cacheWrite,noCache:void 0,total:e?.inputTokens?.total},outputTokens:{reasoning:e?.outputTokens?.reasoning,text:void 0,total:e?.outputTokens?.total}}),_=e=>{if(e===void 0)return m(void 0);const t=e.inputTokens?.total,o=e.outputTokens?.total,r=t===void 0||o===void 0?void 0:t+o;return m(b({inputTokens:t,inputTokenDetails:{cacheReadTokens:e.inputTokens?.cacheRead,cacheWriteTokens:e.inputTokens?.cacheWrite},outputTokens:o,outputTokenDetails:{reasoningTokens:e.outputTokens?.reasoning},totalTokens:r}))},y=(e,t)=>{const o=new Error(e.raw===void 0?"model finished with an error reason":`model finished with an error reason (provider reason: ${e.raw})`,{cause:e});return o[v]=_(t),o},B=e=>{if(!(typeof e!="object"||e===null))return e[v]},I=(e,t)=>e.wrapLanguageModel({middleware:{wrapGenerate:async({doGenerate:o})=>{const r=await o();if(r.finishReason.unified==="error")throw y(r.finishReason,r.usage);return r},wrapStream:async({doStream:o})=>{const{stream:r,...n}=await o();let i=!1;return{...n,stream:r.pipeThrough(new TransformStream({flush:s=>{i||s.enqueue({error:new Error("model stream ended without a finish part"),type:"error"})},transform:(s,a)=>{if(s.type==="finish"&&(i=!0,s.finishReason.unified==="error")){a.enqueue({...s,usage:N(s.usage)}),a.enqueue({error:y(s.finishReason,s.usage),type:"error"});return}a.enqueue(s)}}))}}},model:t}),p=(e,t)=>typeof t=="string"?t:I(e,t),H=(e,t)=>{const o=E(e,t);return async r=>{const{ai:n,base:i}=await o(),s=S(i,r),a=await n.generateText({...s,model:p(n,s.model)});return{text:a.text,toolCalls:x(a.toolCalls),usage:k(a.usage),...i.output===void 0?{}:{output:a.output}}}},X=(e,t)=>{const o=E(e,t);return async(r,n)=>{const{ai:i,base:s}=await o(),a=S(s,r),u=i.streamText({...a,model:p(i,a.model)});let l="";try{for await(const c of u.stream){if(c.type==="error")throw M(c.error);c.type==="text-delta"&&(l+=c.text,n(c.text))}}catch(c){if(!r.signal?.aborted)throw c}if(r.signal?.aborted)return{text:l,toolCalls:[],usage:m(void 0)};const[d,g,A,C]=await Promise.all([u.text,u.toolCalls,u.usage,s.output===void 0?Promise.resolve(void 0):u.output]);return{text:d,toolCalls:x(g),usage:k(A),...s.output===void 0?{}:{output:C}}}},U=R({additionalProperties:!1,properties:{entities:{description:"The distinct entities (people, orgs, places, things, concepts) named in the exchange.",items:{additionalProperties:!1,properties:{name:{description:"The entity's canonical name.",type:"string"},type:{description:"An optional coarse type, e.g. person, org, place, product.",type:"string"}},required:["name"],type:"object"},type:"array"},relations:{description:"The directed relationships between the entities, as (src)-[label]->(dst) triples.",items:{additionalProperties:!1,properties:{confidence:{description:"Confidence in the relation, 0..1.",type:"number"},dst:{description:"The destination entity name (must appear in `entities`).",type:"string"},label:{description:"The relationship, a short snake_case verb phrase, e.g. works_at.",type:"string"},src:{description:"The source entity name (must appear in `entities`).",type:"string"}},required:["src","dst","label"],type:"object"},type:"array"}},required:["entities","relations"],type:"object"}),$=(e,t)=>["Extract a knowledge graph of the durable facts stated in the following exchange.","Return the distinct entities and the directed relationships between them.","Only include facts actually stated — do not invent entities or relations. Prefer few, high-signal triples.","",`User: ${e}`,"",`Assistant: ${t}`].join(`
|
|
2
|
-
`),J=()=>async({assistantText:e,env:t,model:o,userInput:r})=>{const n=await f(),{output:i}=await n.generateText({model:p(n,h(o,t)),output:n.Output.object({schema:U}),prompt:$(r,e)});return i},G=(e,t)=>["Summarize the following exchange as ONE concise past-tense sentence for a long-term memory log.","Capture what the user wanted and what was done or decided — a durable fact worth recalling in a later conversation.","No preamble and no quotes: return only the sentence.","",`User: ${e}`,"",`Assistant: ${t}`].join(`
|
|
3
|
-
`),K=()=>async({assistantText:e,env:t,model:o,userInput:r})=>{const n=await f(),{text:i}=await n.generateText({model:p(n,h(o,t)),prompt:G(r,e)});return{summary:i.trim()}},w="You are compacting an ongoing conversation. Summarize the messages so far into a concise brief that preserves decisions made, facts established, open questions, and current task state — everything the assistant needs to continue coherently. Write it as notes for the assistant, not a reply to the user. No preamble.",W=" An existing brief of the earlier conversation is included above. UPDATE that brief: keep every still-relevant fact from it and fold in the newly aged-out messages. Do not replace it with a summary of only the new messages.",Q=()=>async({env:e,messages:t,model:o,previousSummary:r})=>{const n=await f(),{text:i}=await n.generateText({messages:t,model:p(n,h(o,e)),system:r===void 0?w:`${w}${W}`});return i.trim()};export{H as createAgentGenerate,Q as createCompact,K as createEpisodeExtract,J as createGraphExtract,X as createStreamGenerate,h as resolveAgentModel,B as usageOfFailedTurn};
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import{LunoraError as r}from"@lunora/errors";import{a as g,i as m}from"./agent-loop-C11GY0Yw.mjs";import{collectAgenticMemoryTools as f}from"./collectAgenticMemoryTools-Dxs7mpo6.mjs";import{agentAsTool as p}from"./agentAsTool-ifwGRMR6.mjs";import{i as u}from"./positive-integer-ztHqqpBk.mjs";import{SKILL_NAME_PATTERN as w,RESERVED_SKILL_NAME as c}from"./defineSkill-DGGvDWNq.mjs";const T=e=>{if(e!==void 0&&(typeof e!="string"||e.length===0))throw new r("INTERNAL","@lunora/agent: defineAgent `name` must be a non-empty string when provided")},N=/^[a-zA-Z][\w-]*$/u,A=(e,n)=>{const o={...e.tools};for(const t of n)for(const[s,a]of Object.entries(t.tools??{})){if(Object.hasOwn(o,s))throw new r("INTERNAL",`@lunora/agent: skill "${t.name}" tool "${s}" collides with an existing tool — rename one (the agent's tool namespace is flat)`);o[s]=a}return o},k=(e,n)=>{const o=[];for(const t of[e.instructions,...n.map(s=>s.instructions)])t&&o.push(t);return o.length<=1?o[0]:t=>o.map(s=>typeof s=="function"?s(t):s).filter(s=>s.length>0).join(`
|
|
2
|
-
|
|
3
|
-
`)},y=(e,n)=>{const o=[];e.memory&&m(e.memory)&&o.push({key:"default",...e.memory});for(const t of n)t.knowledge&&m(t.knowledge)&&o.push({key:t.name,...t.knowledge});return o},v=e=>{const n=new Set;for(const o of e){if(typeof o.name!="string"||!w.test(o.name))throw new r("INTERNAL",`@lunora/agent: skill \`name\` must be a valid identifier (letters, digits, _ or -, starting with a letter), got ${JSON.stringify(o.name)}`);if(o.name===c)throw new r("INTERNAL",`@lunora/agent: skill name "${c}" is reserved (it keys the agent's own \`memory\` source / the \`memory:retrieve\` step) — choose another name`);if(n.has(o.name))throw new r("INTERNAL",`@lunora/agent: skill name "${o.name}" is used by more than one skill — rename one (a skill name keys its knowledge memory source, which must be unique)`);n.add(o.name)}},E=(e,n)=>{if(e===void 0)return;const o=Object.keys(n).filter(t=>!e.includes(t));if(o.length>0)throw new r("INTERNAL",`@lunora/agent: \`activeTools\` omits the agentic-memory tool(s) ${o.map(t=>`"${t}"`).join(", ")} — the model could never call them; add them to \`activeTools\` (or drop \`activeTools\` to expose every tool)`)},L=(e,n)=>{const o=(t,s)=>{if(t&&t.kind!=="graph"&&t.kind!=="episodic"&&t.source===void 0)throw new r("INTERNAL",`@lunora/agent: ${s} requires a \`source\` action unless \`kind: "graph"\` or \`kind: "episodic"\``)};o(e.memory,"`memory`");for(const t of n)o(t.knowledge,`skill "${t.name}" \`knowledge\``)},I=e=>{if(e===void 0)return;const n=g(e);if(!Number.isFinite(n)||n<=0)throw new r("INTERNAL","@lunora/agent: `approvalTimeout` must resolve to a positive duration")},j=e=>{const n=e.model;if(n==null||typeof n=="string"&&n.length===0)throw new r("INTERNAL","@lunora/agent: defineAgent requires a `model` (a Workers AI id, an AI SDK LanguageModel, or an (env) => model thunk)");if(T(e.name),e.maxTurns!==void 0&&!u(e.maxTurns))throw new r("INTERNAL","@lunora/agent: `maxTurns` must be a positive integer");if(e.voice?.maxTurns!==void 0&&!u(e.voice.maxTurns))throw new r("INTERNAL","@lunora/agent: `voice.maxTurns` must be a positive integer");I(e.approvalTimeout);const o=e.skills??[];v(o),L(e,o);const t=A(e,o),s=f(e,o);for(const[i,h]of Object.entries(s)){if(Object.hasOwn(t,i))throw new r("INTERNAL",`@lunora/agent: agentic-memory tool "${i}" collides with an existing tool — rename one (the agent's tool namespace is flat)`);t[i]=h}const a=Object.keys(s).length>0;E(e.activeTools,s);for(const i of Object.keys(t))if(!N.test(i))throw new r("INTERNAL",`@lunora/agent: tool name "${i}" is not a valid identifier (letters, digits, _ or -, starting with a letter)`);const l=y(e,o),d=k(e,o);return{...e,asTool:p,isLunoraAgent:!0,...o.some(i=>!!i.instructions)?{instructions:d}:{},...l.length>0?{memorySources:l}:{},...o.length>0||a?{tools:t}:{}}},M=e=>typeof e=="object"&&e!==null&&e.isLunoraAgent===!0,_=e=>{if(typeof e.execute!="function")throw new r("INTERNAL","@lunora/agent: defineAgentTool requires an `execute` function");if(typeof e.description!="string"||e.description.length===0)throw new r("INTERNAL","@lunora/agent: defineAgentTool requires a non-empty `description` (the model decides from it)");return{...e,isLunoraAgentTool:!0}};export{j as defineAgent,_ as defineAgentTool,M as isAgentDefinition};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{LunoraError as o}from"@lunora/errors";import{toFunctionReference as c}from"./AGENT_MODULE-CYBmT9SD.mjs";const m=(r,e)=>{if(typeof e.description!="string"||e.description.length===0)throw new o("INTERNAL","@lunora/agent: functionTool requires a non-empty `description` (the model decides from it)");if(e.inputSchema===void 0)throw new o("INTERNAL","@lunora/agent: functionTool requires an `inputSchema` (a zod schema or `jsonSchema(...)`)");const t=c(r);return{description:e.description,execute:(i,n)=>n.run(t,{...i,idempotencyKey:n.idempotencyKey}),inputSchema:e.inputSchema,isLunoraAgentTool:!0}};export{m as functionTool};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
const r=Symbol.for("vercel.ai.schema"),n=(o,{validate:t}={})=>{let e=o;return{[r]:!0,_type:void 0,get jsonSchema(){return typeof e=="function"&&(e=e()),e},validate:t}};export{n as j};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{usageStatus as X,USAGE_ATTRIBUTE as _,estimateModelCost as Y}from"@lunora/ai/create";import{a as G,r as d,f as H,s as q,e as j,c as K,t as Q}from"./common-DBc9y7Np.mjs";import{c as Z}from"./in-flight-calls-C9QGq8uH.mjs";const W=t=>`${String(Math.round(t))}000000`,ee=Array.from({length:256},(t,o)=>o.toString(16).padStart(2,"0")),O=512,$=new Uint8Array(O);let k=O;const D=(t,o,n)=>{let l="";for(let i=0;i<n;i+=1)l+=ee[t[o+i]];return l},F=t=>{if(t>O){const n=new Uint8Array(t);return crypto.getRandomValues(n),D(n,0,t)}k+t>O&&(crypto.getRandomValues($),k=0);const o=D($,k,t);return k+=t,o},w=(t,o)=>typeof o=="boolean"?{key:t,value:{boolValue:o}}:typeof o=="number"?Number.isFinite(o)?Number.isSafeInteger(o)?{key:t,value:{intValue:String(o)}}:{key:t,value:{doubleValue:o}}:{key:t,value:{stringValue:String(o)}}:{key:t,value:{stringValue:o}},te=(t,o,n)=>{const l={},i=new Map,S=(p,h)=>{const b=p.toLowerCase(),x=i.get(b);x===void 0?(i.set(b,p),l[p]=h):l[x]=h};for(const[p,h]of Object.entries(t))S(p,h);for(const[p,h]of Object.entries(o??{}))S(p,h);return n!==void 0&&n.length>0&&S("authorization",`Bearer ${n}`),l},oe=t=>Array.isArray(t)?t:[t],ne=(t,o)=>{const n={"service.name":t};for(const[l,i]of Object.entries({}))n[l]=i;return Object.entries(n).map(([l,i])=>w(l,i))},se=(t,o,n,l)=>({resourceSpans:[{resource:{attributes:ne(n)},scopeSpans:[{scope:{name:o},spans:oe(t)}]}]}),re=50,ae=256*1024,ce=new TextEncoder,r=(t,o,n)=>{if(n!=null){if(typeof n=="boolean"||typeof n=="number"||typeof n=="string"){t.push(w(o,n));return}t.push(w(o,JSON.stringify(n)))}},ie=(t,o)=>{(async()=>{let l;try{l=await t}catch(i){o(!1,i instanceof Error?i.message:String(i),void 0);return}o(!0,void 0,l)})().catch(()=>{})},ge=t=>{const{conversationId:o,endpoint:n,headers:l,recordInputs:i=!1,recordOutputs:S=!1,token:p,traceId:h,waitUntil:b}=t,x=t.serviceName??"lunora";let A=n;for(;A.endsWith("/");)A=A.slice(0,-1);const P=`${A}/v1/traces`,z=te({"content-type":"application/json"},l,p);let I=[],N=0;const R=()=>{if(I.length===0)return;const e=I;I=[],N=0;try{const s=fetch(P,{body:JSON.stringify(se(e,"@lunora/agent",x)),headers:z,method:"POST"}).catch(()=>{});b?.(s)}catch{}},U=(e,s,a,u,y)=>{const f={attributes:y,endTimeUnixNano:W(Date.now()),kind:1,name:e,spanId:F(8),startTimeUnixNano:W(s),status:a?{code:1}:{code:2,message:u??""},traceId:h??F(16)};I.push(f),N+=ce.encode(JSON.stringify(f)).byteLength,(I.length>=re||N>=ae)&&R()},T=Z((e,s,a,u)=>{const{messages:y,modelId:f,provider:C,result:m,startTs:J}=e,c=[];r(c,"gen_ai.operation.name","chat"),r(c,"gen_ai.request.model",f),r(c,"gen_ai.system",C),r(c,"gen_ai.conversation.id",o);const g=q(d(u,"usage")??d(m,"usage")),L=X(g);r(c,"lunora.usage.status",L),r(c,_.inputTokens,g?.inputTokens),r(c,_.outputTokens,g?.outputTokens),r(c,"gen_ai.usage.total_tokens",g?.totalTokens),r(c,_.cacheReadTokens,g?.cacheReadTokens),r(c,_.cacheWriteTokens,g?.cacheWriteTokens),r(c,_.reasoningTokens,g?.reasoningTokens);const E=j(u)??j(m);E&&(r(c,"gen_ai.response.cached",E.cached),r(c,"cf.aig.log_id",E.logId));const M=E?.cost,V=M??(typeof f=="string"&&L==="complete"?Y(f,{cacheReadTokens:g?.cacheReadTokens,cacheWriteTokens:g?.cacheWriteTokens,inputTokens:g?.inputTokens,outputTokens:g?.outputTokens}):void 0);V!==void 0&&(r(c,"gen_ai.usage.cost",V),r(c,"lunora.usage.cost.source",M===void 0?"estimated":"provider")),i&&r(c,"gen_ai.prompt",y),S&&r(c,"gen_ai.completion",K(d(u,"content")??d(m,"content"))),U(typeof f=="string"?`chat ${f}`:"language_model_call",J,s,a,c)}),v=(e,s,a)=>{const u=d(e,"callId");if(typeof u!="string")return;let y=a;s instanceof Error?y=s.message:typeof s=="string"&&s.length>0&&(y=s),T.close(u,!1,y,H(s))},B=e=>({messages:d(e,"messages"),modelId:d(e,"modelId"),provider:d(e,"provider"),result:void 0,startTs:Date.now()});return{flush:R,executeLanguageModelCall:async e=>{const{callId:s}=e;T.open(s,()=>B(e));try{const a=await e.execute(),u=T.get(s);return u!==void 0&&(u.result=a),a}catch(a){throw T.close(s,!1,a instanceof Error?a.message:String(a),H(a)),a}},onAbort:e=>{v(e,d(e,"reason"),"aborted")},onEnd:e=>{T.fromLifecycle(e)},onError:e=>{v(e,d(e,"error"),"the model call failed")},onLanguageModelCallEnd:e=>{typeof d(e,"callId")=="string"&&T.fromLifecycle(e)},onLanguageModelCallStart:e=>{const s=d(e,"callId");typeof s=="string"&&T.open(s,()=>B(e))},onStepEnd:e=>{T.fromLifecycle(e)},executeTool:e=>{const s=Date.now(),a=G(e),u=e.execute();return ie(u,(f,C)=>{const m=[];r(m,"gen_ai.operation.name","execute_tool"),r(m,"gen_ai.tool.name",a),r(m,"gen_ai.tool.call.id",d(e,"toolCallId")),i&&r(m,"gen_ai.tool.input",Q(e)),U(typeof a=="string"?`execute_tool ${a}`:"execute_tool",s,f,C,m)}),u}}};export{ge as otlpTelemetry};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import"./DEFAULT_DISPATCH_TIMEOUT_MS-DiRHEqJU-BRtWNzq1.mjs";import"./workflow-binding-Dm9hBzx_.mjs";import"./component-shared-DdXFbng-.mjs";import"./createAgentGenerate-CTkL_e0Z.mjs";import{b as g,a as l,c as u,r as b,s as f}from"./agent-loop-C11GY0Yw.mjs";import"./buildModelMessages-DVQdQ7_1.mjs";import"../naming.mjs";import"./AGENT_MODULE-CYBmT9SD.mjs";import"./positive-integer-ztHqqpBk.mjs";import"./SecretUnavailableError-D8u6pPM6.mjs";import"./tool-output-Cmk3JWMG.mjs";export{g as addUsage,l as approvalTimeoutMs,u as compactHistory,b as runAgentLoop,f as splitForCompaction};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{p as s,c as i,f as p,e as n,r as m,g as c}from"./voice-turn-BjkorohD.mjs";import"./agent-loop-C11GY0Yw.mjs";import"./buildModelMessages-DVQdQ7_1.mjs";import"./AGENT_MODULE-CYBmT9SD.mjs";export{s as parseIdentity,i as pcmToWav,p as readSynthesisAudio,n as readTranscriptionText,m as runVoiceTurn,c as toByteIterable};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{c as Y}from"./agent-loop-C11GY0Yw.mjs";import{buildModelMessages as Z}from"./buildModelMessages-DVQdQ7_1.mjs";import{toFunctionReference as A}from"./AGENT_MODULE-CYBmT9SD.mjs";const ut=t=>{let e="";for(let r=0;r<t.length;r+=32768)e+=String.fromCharCode(...t.subarray(r,r+32768));return btoa(e)},C=t=>{const e=atob(t),n=new Uint8Array(e.length);for(let r=0;r<e.length;r+=1)n[r]=e.codePointAt(r)??0;return n},F=t=>{const e=t.replaceAll("-","+").replaceAll("_","/"),n=e+"=".repeat((4-e.length%4)%4);return C(n)},H=new TextDecoder;new TextEncoder;const M="=",tt=t=>{if(t)try{const e=t[0]==="{"?t:H.decode(F(t)),n=JSON.parse(e);if(n&&typeof n=="object"&&!Array.isArray(n))return n}catch{}},yt=t=>{if(t){if(!t.startsWith(M))return t;try{return H.decode(F(t.slice(M.length)))}catch{return}}},ft=t=>{const e=Number(t);return Number.isFinite(e)&&e>0?e:void 0},lt=t=>typeof t=="number"&&Date.now()>=t,pt=t=>{try{t.send(JSON.stringify({code:"TOKEN_EXPIRED",error:{code:"TOKEN_EXPIRED",message:"authentication token expired"},message:"authentication token expired",type:"error"})),t.close?.(4001,"token_expired")}catch{}},et=16e3,nt=1,rt=16,P=/[.!?]\s/u,st=/\s/u,at=async function*(t){if(t instanceof Uint8Array){yield t;return}if(t instanceof ReadableStream){const e=t.getReader();try{for(;;){const{done:n,value:r}=await e.read();if(n)break;yield r}}finally{e.releaseLock()}return}yield*t},ht=(t,e=et,n=nt,r=rt)=>{const a=n*r/8,p=e*a,m=new ArrayBuffer(44+t.byteLength),s=new DataView(m),u=(y,b)=>{for(let d=0;d<b.length;d+=1)s.setUint8(y+d,b.codePointAt(d)??0)};u(0,"RIFF"),s.setUint32(4,36+t.byteLength,!0),u(8,"WAVE"),u(12,"fmt "),s.setUint32(16,16,!0),s.setUint16(20,1,!0),s.setUint16(22,n,!0),s.setUint32(24,e,!0),s.setUint32(28,p,!0),s.setUint16(32,a,!0),s.setUint16(34,r,!0),u(36,"data"),s.setUint32(40,t.byteLength,!0);const i=new Uint8Array(m);return i.set(t,44),i},it=t=>{const e=[];let n=t,r=P.exec(n);for(;r;){let a=r.index+1;for(;a<n.length&&st.test(n[a]??"");)a+=1;const p=n.slice(0,a).trim();p.length>0&&e.push(p),n=n.slice(a),r=P.exec(n)}return{rest:n,sentences:e}},gt=async t=>{const{agent:e,compact:n,connectionId:r,env:a,exportName:p,owner:m,paths:s,pcm:u,run:i,send:y,sendAudio:b,signal:d,streamGenerate:L,synthesize:B,text:O,threadKey:o,transcribe:$,turn:U,waitForDrain:K}=t;let _=!1,v=!1;const j=()=>v,h=()=>d.aborted||_,I=A(s.appendMessage),W=A(s.ensureThread),V=A(s.listMessages),x=A(s.patchThread);await i(W,{agent:p,key:o,...e.initialState===void 0?{}:{initialState:e.initialState},...m===void 0?{}:{owner:m}});try{const f=(O??(u?await $(u):"")).trim();if(f.length===0)return await i(x,{key:o,status:"idle"}),{assistantText:"",interrupted:!1,userText:""};y({text:f,type:"user_transcript"}),await i(I,{content:f,messageKey:`voice:${r}:${String(U)}:user`,role:"user",threadKey:o}),await i(x,{key:o,status:"running"});const R=typeof e.instructions=="function"?e.instructions({env:a,input:f,threadKey:o}):e.instructions,X=await i(V,{key:o}),{history:J,summary:N}=await Y({agent:e,compact:n,env:a},X),q=Z({history:J,...R===void 0?{}:{instructions:R},...N===void 0?{}:{summary:N}});let g="",E="",k=Promise.resolve();const z=async c=>{if(h()||c.length===0)return;let w=!1;try{for await(const l of at(await B(c,d))){if(h()||(await K?.(),h()))break;b(l),w=!0}}catch(l){y({message:l instanceof Error?l.message:String(l),type:"error"})}w&&(E=E.length>0?`${E} ${c}`:c)},D=c=>{k=k.then(async()=>z(c))},G=await L({messages:q,signal:d},c=>{if(h())return;v=!0,y({text:c,type:"assistant_delta"}),g+=c;const{rest:w,sentences:l}=it(g);g=w;for(const Q of l)D(Q)});!h()&&g.trim().length>0&&D(g.trim()),g="",await k;const S=h(),T=S?E:G.text;return await i(I,{content:T,messageKey:`voice:${r}:${String(U)}:assistant`,role:"assistant",threadKey:o}),await i(x,{key:o,status:"idle"}),y(S?{type:"interrupted"}:{text:T,type:"assistant_done"}),{assistantText:T,interrupted:S,userText:f}}catch(f){throw _=!0,j()&&y({type:"assistant_discarded"}),await i(x,{key:o,status:"idle"}),f}},mt=t=>tt(t),bt=t=>{if(typeof t=="object"&&t!==null&&"text"in t){const{text:e}=t;return typeof e=="string"?e:""}return""},xt=t=>{if(t instanceof Uint8Array||t instanceof ReadableStream)return t;if(t instanceof Response&&t.body)return t.body;if(typeof t=="object"&&t!==null&&"audio"in t){const{audio:e}=t;if(typeof e=="string")return C(e);if(e instanceof ReadableStream||e instanceof Uint8Array)return e}return new Uint8Array(0)};export{ft as a,pt as b,ht as c,yt as d,bt as e,xt as f,at as g,lt as i,mt as p,gt as r,ut as t};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{LunoraError as c}from"@lunora/errors";import{r as h}from"./agent-ai-CP87uSoZ.mjs";import{j as u}from"./json-schema-CHVg-SsJ.mjs";const l=5,d="Search the web for current information. Returns up to a handful of results, each with a url, a title and (when the provider has one) a description. Use it for facts that may have changed after your training data, then cite the urls you relied on.",m=u({properties:{query:{description:"The search query, 1–1024 characters.",maxLength:1024,minLength:1,type:"string"}},required:["query"],type:"object"}),E=new Set(["BAD_REQUEST","INTERNAL","NOT_IMPLEMENTED"]),T=(t={})=>{const{description:a=d,limit:o=l,...n}=t;return{description:a,execute:async(s,i)=>{const r=h(i.env);if(!r)return"Web search is unavailable: this Worker has no `AI` binding. Answer from what you already know, and say that you could not search.";try{return(await r.websearch(s.query,{...n,limit:o})).items}catch(e){if(e instanceof c&&E.has(e.code))return`Web search failed: ${e.message}`;throw e}},inputSchema:m,isLunoraAgentTool:!0}};export{T as webSearchTool};
|