@lunora/testing 1.0.0-alpha.289 → 1.0.0-alpha.290
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/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{agentHarness as o,finalTurn as t,toolCallTurn as a}from"./packem_shared/agentHarness-
|
|
1
|
+
import{agentHarness as o,finalTurn as t,toolCallTurn as a}from"./packem_shared/agentHarness-BM24QFnh.mjs";import{evaluationAttributes as l,recordEvaluation as n}from"./packem_shared/evaluationAttributes-CYLgTP1P.mjs";import{createArtifactsFake as m}from"./packem_shared/createArtifactsFake-L0tjki11.mjs";import{createFakeSecretValues as s}from"./packem_shared/createFakeSecretValues-BTNOscqQ.mjs";import{lunoraTest as f}from"./packem_shared/lunoraTest-VecnFIun.mjs";import{createStreamGate as S,recordedModel as d}from"./packem_shared/createStreamGate-Geg-yvx6.mjs";import{groundednessScorer as g,mrrScorer as k,ndcgAtK as M,precisionAtK as v,recallAtK as F}from"./packem_shared/groundednessScorer-kgXJCZDg.mjs";import{containsScorer as T,evaluate as w,exactMatchScorer as C,keywordScorer as b,llmScorer as h,regexScorer as y,scoreSample as E}from"./packem_shared/containsScorer-DoLfFOs6.mjs";import{extractLink as H,listCapturedMail as L,waitForMail as V}from"@lunora/mail/testing";export{o as agentHarness,T as containsScorer,m as createArtifactsFake,s as createFakeSecretValues,S as createStreamGate,w as evaluate,l as evaluationAttributes,C as exactMatchScorer,H as extractLink,t as finalTurn,g as groundednessScorer,b as keywordScorer,L as listCapturedMail,h as llmScorer,f as lunoraTest,k as mrrScorer,M as ndcgAtK,v as precisionAtK,F as recallAtK,n as recordEvaluation,d as recordedModel,y as regexScorer,E as scoreSample,a as toolCallTurn,V as waitForMail};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{DEFAULT_AGENT_FUNCTION_PATHS as h,runAgentLoop as E,createStreamGenerate as _,createAgentGenerate as j}from"@lunora/agent";import{createFakeSecretValues as O}from"./createFakeSecretValues-BTNOscqQ.mjs";const A="WorkflowTimeoutError",x=(p,s)=>JSON.stringify([p,s]);class H{constructor(s){this.journal=s}journal;awaited=new Map;delivered=new Map;expired=new Set;pending=new Map;reached=new Map;started=new Map;wait(s,i,n){const o=x(s,i),u=(this.started.get(o)??0)+1;if(this.started.set(o,u),this.expired.delete(o),this.delivered.has(o)){const w=this.delivered.get(o);return this.delivered.delete(o),this.notifyReached(o,u),Promise.resolve(this.record(i,n,w))}return new Promise((w,f)=>{if(this.pending.has(o)){f(new Error(`agentHarness: run "${s}" is already waiting on "${i}"`));return}this.pending.set(o,{reject:f,resolve:v=>{w(this.record(i,n,v))}}),this.notifyReached(o,u)})}deliver(s,i,n){const o=x(s,i),u=this.pending.get(o);if(u===void 0){this.expired.has(o)||this.delivered.set(o,n);return}this.pending.delete(o),u.resolve(n)}expire(s,i){const n=x(s,i),o=this.pending.get(n);if(o===void 0)throw new Error(`agentHarness: no pending wait "${i}" on run "${s}" to expire`);this.pending.delete(n),this.expired.add(n);const u=new Error(`agentHarness: wait "${i}" timed out`);u.name=A,o.reject(u)}awaitWait(s,i){const n=x(s,i),o=(this.awaited.get(n)??0)+1;return this.awaited.set(n,o),(this.started.get(n)??0)>=o?Promise.resolve():new Promise(u=>{this.reached.set(n,[...this.reached.get(n)??[],{resolve:u,target:o}])})}notifyReached(s,i){const n=this.reached.get(s)??[];this.reached.set(s,n.filter(o=>o.target>i));for(const o of n)o.target<=i&&o.resolve()}record(s,i,n){return this.journal.push({kind:"wait",name:s,payload:n,type:i}),n}}const N=900*1e3,P=p=>{const s=[...p];return()=>{const i=s.shift();if(!i)throw new Error("agentHarness: scripted generate exhausted — the run took more turns than the script provided.");return Promise.resolve(i)}};class W{constructor(s,i,n){this.waits=s,this.instanceId=i,this.journal=n}waits;instanceId;journal;invoked=[];entries=new Map;async do(s,i){const n=this.entries.get(s);if(n)return n.output;this.invoked.push(s);const o=await i();return this.entries.set(s,{output:o}),this.journal.push({kind:"step",name:s,output:o}),o}async waitForEvent(s,i){const n=this.entries.get(`wait:${s}`);if(n)return{payload:n.output,type:i.type};const o=await this.waits.wait(this.instanceId,s,i.type);return this.entries.set(`wait:${s}`,{output:o}),{payload:o,type:i.type}}}const F=(p,s)=>{const i=new Map,n=new Map,o=[],u=e=>{const t=e?.key,r=e?.instanceId,a=i.get(t);return a?(a.status="running",delete a.error,r!==void 0&&(a.instanceId=r),{outcome:"continued"}):(i.set(t,{agent:e?.agent,instanceId:r,key:t,messageCount:0,owner:e?.owner,status:"running",title:e?.title}),{outcome:"created"})},w=e=>{n.delete(`${e?.threadKey}:${e?.messageKey}`)},f=e=>{const t=e?.threadKey,r=e?.messageKey,a=`${t}:${r}`,y=n.get(a);if(y)return{seq:y.seq};const R=i.get(t);if(!R)throw new Error(`agentHarness: append to unknown thread "${t}".`);const $=R.messageCount;return R.messageCount+=1,n.set(a,{...e,seq:$}),{seq:$}},v=e=>{const t=e?.key;return[...n.values()].filter(r=>r.threadKey===t).toSorted((r,a)=>r.seq-a.seq)},m=e=>{const t=i.get(e?.key);if(t)for(const[r,a]of Object.entries(e??{}))r!=="key"&&a!==void 0&&(t[r]=a)},I=e=>{const t=i.get(e?.key);if(!e||!t||t.instanceId!==e.instanceId)return{};for(const[r,a]of Object.entries(e))r!=="key"&&r!=="instanceId"&&a!==void 0&&(t[r]=a);return{}},S=(e,t)=>JSON.stringify([e,t]),c=new Map,d=(e,t)=>{const r=[...c.values()].filter(y=>y.threadKey===e&&y.callId===t&&y.status==="pending"),[a]=r;if(!(r.length!==1||a===void 0))return{request:a,slot:a.slot}},l=e=>{const t=c.get(S(e?.threadKey,e?.toolCallId)),r=e?.instanceId;return r===void 0||t?.instanceId===r?t:void 0},g=async e=>{const t=S(e?.threadKey,e?.toolCallId),r=c.get(t),a=e?.instanceId;a!==void 0&&r?.instanceId===a||(r?.ref!==void 0&&await s.discard(r.ref),c.set(t,{callId:e?.callId??e?.toolCallId,slot:e?.toolCallId,threadKey:e?.threadKey,consumerTool:e?.consumerTool,instanceId:e?.instanceId,status:"pending"}))},T=e=>{const t=l(e);return t===void 0?{status:"expired"}:t.status==="pending"?(t.status="expired",{status:"expired"}):t.status==="supplied"||t.status==="consumed"?{status:"supplied"}:{status:t.status==="declined"?"declined":"expired"}},M=e=>{const t=l(e);return t?.ref===void 0||t.status!=="supplied"&&t.status!=="consumed"||e?.claimant!==`tool:${t.consumerTool}:${e?.consumerCallId}`?Promise.resolve(void 0):s.take(t.ref,{claimant:e.claimant,scope:e.threadKey})},q=async e=>{const t=l(e);t!==void 0&&(t.ref!==void 0&&await s.discard(t.ref),t.status==="supplied"&&(t.status="consumed"))},k=async(e,t,r)=>{const a=d(e,t);if(a===void 0)throw new Error(`agentHarness: no pending secret request for tool call "${t}" on thread "${e}"`);return a.request.ref=await s.put(r,{scope:e,ttlMs:N}),a.request.status="supplied",{instanceId:a.request.instanceId,slot:a.slot}},K=(e,t)=>{const r=d(e,t);if(r!==void 0)return r.request.status="declined",{instanceId:r.request.instanceId,slot:r.slot}},C=new Map([[h.appendMessage,f],[h.approvalGranted,()=>!1],[h.completeRun,I],[h.deleteMessage,w],[h.discardSecret,q],[h.ensureThread,u],[h.listMessages,v],[h.openSecretRequest,g],[h.patchThread,m],[h.settleSecretRequest,T],[h.takeSecret,M],...Object.entries(p)]);return{declineSecret:K,dispatches:o,expireSecretRequest:(e,t)=>{for(const r of c.values())r.instanceId===e&&r.slot===t&&r.status==="pending"&&(r.status="expired")},messages:n,run:(e,t)=>{const r=e.__lunoraRef;o.push({args:t,path:r});const a=C.get(r);if(!a)throw new Error(`agentHarness: unstubbed dispatch "${r}" — pass a \`functions\` handler for it.`);return Promise.resolve(a(t))},supplySecret:k,threads:i}},D=(p,s)=>{const i=s.exportName??"agent",n=s.env??{LUNORA_TEST:!0},o=s.secrets??O(),u=F(s.functions??{},o),w=[],f=new H(w),v=new Map,m=c=>{const d=v.get(c);if(d!==void 0)return d;const l=new W(f,c,w);return v.set(c,l),l};let I=0;const S=(c,d)=>{I+=1;const l=d?.instanceId??`wf-${String(I)}`,{model:g,onTokenDelta:T}=d??{};if(g!==void 0){const q={...p,model:g};return E({agent:p,env:n,exportName:i,generate:j(q,n),instanceId:l,onTokenDelta:k=>{k.kind!=="progress"&&T?.(k)},params:c,paths:h,run:u.run,step:m(l),streamGenerate:_(q,n)})}const M=d?.script??s.script??[];return E({agent:p,env:n,exportName:i,generate:P(M),instanceId:l,params:c,paths:h,run:u.run,step:m(l)})};return{awaitWait:(c,d)=>f.awaitWait(c,d),deliver:(c,d,l)=>{f.deliver(c,d,l)},decline:(c,d)=>{const l=u.declineSecret(c,d);l!==void 0&&f.deliver(l.instanceId,`secret:${l.slot}`,{})},dispatches:u.dispatches,expire:(c,d)=>{f.expire(c,d),d.startsWith("secret:")&&u.expireSecretRequest(c,d.slice(7))},journalEntries:()=>[...w],messages:c=>[...u.messages.values()].filter(d=>d.threadKey===c).toSorted((d,l)=>d.seq-l.seq).map(({messageKey:d,threadKey:l,...g})=>g),run:S,secrets:o,supply:async(c,d,l)=>{const g=await u.supplySecret(c,d,l);f.deliver(g.instanceId,`secret:${g.slot}`,{})},thread:c=>u.threads.get(c)}},J=(p,s)=>({text:p,toolCalls:[],...s}),V=(p,s,i,n="")=>({text:n,toolCalls:[{id:p,input:i,name:s}]});export{D as agentHarness,J as finalTurn,V as toolCallTurn};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lunora/testing",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.290",
|
|
4
4
|
"description": "Testing toolkit for Lunora: an in-memory harness for queries, mutations, and actions",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cloudflare",
|
|
@@ -50,15 +50,15 @@
|
|
|
50
50
|
"access": "public"
|
|
51
51
|
},
|
|
52
52
|
"dependencies": {
|
|
53
|
-
"@lunora/agent": "1.0.0-alpha.
|
|
54
|
-
"@lunora/bindings": "1.0.0-alpha.
|
|
53
|
+
"@lunora/agent": "1.0.0-alpha.235",
|
|
54
|
+
"@lunora/bindings": "1.0.0-alpha.129",
|
|
55
55
|
"@lunora/errors": ">=1.0.0-alpha.51 <2.0.0-0",
|
|
56
56
|
"@lunora/mail": "1.0.0-alpha.119",
|
|
57
57
|
"@lunora/notify": "1.0.0-alpha.92",
|
|
58
|
-
"@lunora/platform": "1.0.0-alpha.
|
|
59
|
-
"@lunora/queue": "1.0.0-alpha.
|
|
60
|
-
"@lunora/scheduler": "1.0.0-alpha.
|
|
61
|
-
"@lunora/server": "1.0.0-alpha.
|
|
58
|
+
"@lunora/platform": "1.0.0-alpha.73",
|
|
59
|
+
"@lunora/queue": "1.0.0-alpha.122",
|
|
60
|
+
"@lunora/scheduler": "1.0.0-alpha.144",
|
|
61
|
+
"@lunora/server": "1.0.0-alpha.227",
|
|
62
62
|
"@lunora/wire": "1.0.0-alpha.2",
|
|
63
63
|
"@visulima/notification": "1.2.0",
|
|
64
64
|
"ai": "7.0.127"
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{DEFAULT_AGENT_FUNCTION_PATHS as h,runAgentLoop as E,createStreamGenerate as _,createAgentGenerate as j}from"@lunora/agent";import{createFakeSecretValues as O}from"./createFakeSecretValues-BTNOscqQ.mjs";const A="WorkflowTimeoutError",I=(p,s)=>JSON.stringify([p,s]);class H{constructor(s){this.journal=s}journal;awaited=new Map;delivered=new Map;expired=new Set;pending=new Map;reached=new Map;started=new Map;wait(s,r,n){const i=I(s,r),u=(this.started.get(i)??0)+1;if(this.started.set(i,u),this.expired.delete(i),this.delivered.has(i)){const g=this.delivered.get(i);return this.delivered.delete(i),this.notifyReached(i,u),Promise.resolve(this.record(r,n,g))}return new Promise((g,f)=>{if(this.pending.has(i)){f(new Error(`agentHarness: run "${s}" is already waiting on "${r}"`));return}this.pending.set(i,{reject:f,resolve:v=>{g(this.record(r,n,v))}}),this.notifyReached(i,u)})}deliver(s,r,n){const i=I(s,r),u=this.pending.get(i);if(u===void 0){this.expired.has(i)||this.delivered.set(i,n);return}this.pending.delete(i),u.resolve(n)}expire(s,r){const n=I(s,r),i=this.pending.get(n);if(i===void 0)throw new Error(`agentHarness: no pending wait "${r}" on run "${s}" to expire`);this.pending.delete(n),this.expired.add(n);const u=new Error(`agentHarness: wait "${r}" timed out`);u.name=A,i.reject(u)}awaitWait(s,r){const n=I(s,r),i=(this.awaited.get(n)??0)+1;return this.awaited.set(n,i),(this.started.get(n)??0)>=i?Promise.resolve():new Promise(u=>{this.reached.set(n,[...this.reached.get(n)??[],{resolve:u,target:i}])})}notifyReached(s,r){const n=this.reached.get(s)??[];this.reached.set(s,n.filter(i=>i.target>r));for(const i of n)i.target<=r&&i.resolve()}record(s,r,n){return this.journal.push({kind:"wait",name:s,payload:n,type:r}),n}}const N=900*1e3,P=p=>{const s=[...p];return()=>{const r=s.shift();if(!r)throw new Error("agentHarness: scripted generate exhausted — the run took more turns than the script provided.");return Promise.resolve(r)}};class W{constructor(s,r,n){this.waits=s,this.instanceId=r,this.journal=n}waits;instanceId;journal;invoked=[];entries=new Map;async do(s,r){const n=this.entries.get(s);if(n)return n.output;this.invoked.push(s);const i=await r();return this.entries.set(s,{output:i}),this.journal.push({kind:"step",name:s,output:i}),i}async waitForEvent(s,r){const n=this.entries.get(`wait:${s}`);if(n)return{payload:n.output,type:r.type};const i=await this.waits.wait(this.instanceId,s,r.type);return this.entries.set(`wait:${s}`,{output:i}),{payload:i,type:r.type}}}const F=(p,s)=>{const r=new Map,n=new Map,i=[],u=e=>{const t=e?.key,o=e?.instanceId,a=r.get(t);return a?(a.status="running",delete a.error,o!==void 0&&(a.instanceId=o),{outcome:"continued"}):(r.set(t,{agent:e?.agent,instanceId:o,key:t,messageCount:0,owner:e?.owner,status:"running",title:e?.title}),{outcome:"created"})},g=e=>{n.delete(`${e?.threadKey}:${e?.messageKey}`)},f=e=>{const t=e?.threadKey,o=e?.messageKey,a=`${t}:${o}`,y=n.get(a);if(y)return{seq:y.seq};const R=r.get(t);if(!R)throw new Error(`agentHarness: append to unknown thread "${t}".`);const $=R.messageCount;return R.messageCount+=1,n.set(a,{...e,seq:$}),{seq:$}},v=e=>{const t=e?.key;return[...n.values()].filter(o=>o.threadKey===t).toSorted((o,a)=>o.seq-a.seq)},m=e=>{const t=r.get(e?.key);if(t)for(const[o,a]of Object.entries(e??{}))o!=="key"&&a!==void 0&&(t[o]=a)},S=e=>{const t=r.get(e?.key);if(!e||!t||t.instanceId!==e.instanceId)return{};for(const[o,a]of Object.entries(e))o!=="key"&&o!=="instanceId"&&a!==void 0&&(t[o]=a);return{}},k=(e,t)=>JSON.stringify([e,t]),c=new Map,d=(e,t)=>{const o=[...c.values()].filter(y=>y.threadKey===e&&y.callId===t&&y.status==="pending"),[a]=o;if(!(o.length!==1||a===void 0))return{request:a,slot:a.slot}},l=e=>c.get(k(e?.threadKey,e?.toolCallId)),w=async e=>{const t=k(e?.threadKey,e?.toolCallId),o=c.get(t),a=e?.instanceId;a!==void 0&&o?.instanceId===a||(o?.ref!==void 0&&await s.discard(o.ref),c.set(t,{callId:e?.callId??e?.toolCallId,slot:e?.toolCallId,threadKey:e?.threadKey,consumerTool:e?.consumerTool,instanceId:e?.instanceId,status:"pending"}))},T=e=>{const t=l(e);return t===void 0?{status:"expired"}:t.status==="pending"?(t.status="expired",{status:"expired"}):t.status==="supplied"||t.status==="consumed"?{status:"supplied"}:{status:t.status==="declined"?"declined":"expired"}},M=e=>{const t=l(e);return t?.ref===void 0||t.status!=="supplied"&&t.status!=="consumed"||e?.claimant!==`tool:${t.consumerTool}:${e?.consumerCallId}`?Promise.resolve(void 0):s.take(t.ref,{claimant:e.claimant,scope:e.threadKey})},q=async e=>{const t=l(e);t!==void 0&&(t.ref!==void 0&&await s.discard(t.ref),t.status==="supplied"&&(t.status="consumed"))},x=async(e,t,o)=>{const a=d(e,t);if(a===void 0)throw new Error(`agentHarness: no pending secret request for tool call "${t}" on thread "${e}"`);return a.request.ref=await s.put(o,{scope:e,ttlMs:N}),a.request.status="supplied",{instanceId:a.request.instanceId,slot:a.slot}},K=(e,t)=>{const o=d(e,t);if(o!==void 0)return o.request.status="declined",{instanceId:o.request.instanceId,slot:o.slot}},C=new Map([[h.appendMessage,f],[h.approvalGranted,()=>!1],[h.completeRun,S],[h.deleteMessage,g],[h.discardSecret,q],[h.ensureThread,u],[h.listMessages,v],[h.openSecretRequest,w],[h.patchThread,m],[h.settleSecretRequest,T],[h.takeSecret,M],...Object.entries(p)]);return{declineSecret:K,dispatches:i,expireSecretRequest:(e,t)=>{for(const o of c.values())o.instanceId===e&&o.slot===t&&o.status==="pending"&&(o.status="expired")},messages:n,run:(e,t)=>{const o=e.__lunoraRef;i.push({args:t,path:o});const a=C.get(o);if(!a)throw new Error(`agentHarness: unstubbed dispatch "${o}" — pass a \`functions\` handler for it.`);return Promise.resolve(a(t))},supplySecret:x,threads:r}},D=(p,s)=>{const r=s.exportName??"agent",n=s.env??{LUNORA_TEST:!0},i=s.secrets??O(),u=F(s.functions??{},i),g=[],f=new H(g),v=new Map,m=c=>{const d=v.get(c);if(d!==void 0)return d;const l=new W(f,c,g);return v.set(c,l),l};let S=0;const k=(c,d)=>{S+=1;const l=d?.instanceId??`wf-${String(S)}`,{model:w,onTokenDelta:T}=d??{};if(w!==void 0){const q={...p,model:w};return E({agent:p,env:n,exportName:r,generate:j(q,n),instanceId:l,onTokenDelta:x=>{x.kind!=="progress"&&T?.(x)},params:c,paths:h,run:u.run,step:m(l),streamGenerate:_(q,n)})}const M=d?.script??s.script??[];return E({agent:p,env:n,exportName:r,generate:P(M),instanceId:l,params:c,paths:h,run:u.run,step:m(l)})};return{awaitWait:(c,d)=>f.awaitWait(c,d),deliver:(c,d,l)=>{f.deliver(c,d,l)},decline:(c,d)=>{const l=u.declineSecret(c,d);l!==void 0&&f.deliver(l.instanceId,`secret:${l.slot}`,{})},dispatches:u.dispatches,expire:(c,d)=>{f.expire(c,d),d.startsWith("secret:")&&u.expireSecretRequest(c,d.slice(7))},journalEntries:()=>[...g],messages:c=>[...u.messages.values()].filter(d=>d.threadKey===c).toSorted((d,l)=>d.seq-l.seq).map(({messageKey:d,threadKey:l,...w})=>w),run:k,secrets:i,supply:async(c,d,l)=>{const w=await u.supplySecret(c,d,l);f.deliver(w.instanceId,`secret:${w.slot}`,{})},thread:c=>u.threads.get(c)}},J=(p,s)=>({text:p,toolCalls:[],...s}),V=(p,s,r,n="")=>({text:n,toolCalls:[{id:p,input:r,name:s}]});export{D as agentHarness,J as finalTurn,V as toolCallTurn};
|