openpond 0.2.40 → 0.2.41
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/app-server.d.ts +5 -1
- package/dist/app-server.js +1 -1
- package/dist/chunks/actions-command-JPJLAR44.js +2 -0
- package/dist/chunks/{app-layer-W2M7SM2L.js → app-layer-ENO5MMPX.js} +1 -1
- package/dist/chunks/app-server-runtime-LACOVSKH.js +2 -0
- package/dist/chunks/apps-VFXTNQ25.js +2 -0
- package/dist/chunks/{chunk-ALYT2HWV.js → chunk-2Z6H32OC.js} +1 -1
- package/dist/chunks/chunk-3FXZW4G7.js +3 -0
- package/dist/chunks/{chunk-DWY6YCBI.js → chunk-452UKUIB.js} +200 -201
- package/dist/chunks/{chunk-3HQEEZPO.js → chunk-65BW2QXY.js} +1 -1
- package/dist/chunks/{chunk-4QURHV3Q.js → chunk-6C5XPL6E.js} +1 -1
- package/dist/chunks/{chunk-J4S7AVGF.js → chunk-6UGTLC7Z.js} +1 -1
- package/dist/chunks/chunk-ALZRXBEC.js +33 -0
- package/dist/chunks/chunk-AO753YWB.js +5 -0
- package/dist/chunks/chunk-AT6XYNQ5.js +2 -0
- package/dist/chunks/chunk-DLQW5X6F.js +2 -0
- package/dist/chunks/chunk-DXAZUJPA.js +2 -0
- package/dist/chunks/chunk-ERFHALGF.js +4 -0
- package/dist/chunks/chunk-FLWIBAHG.js +2 -0
- package/dist/chunks/{chunk-ASRSYRE3.js → chunk-GKP2ZPKM.js} +1 -1
- package/dist/chunks/{chunk-H7YH35JO.js → chunk-H7JB25HO.js} +1 -1
- package/dist/chunks/{chunk-JIG7KQOX.js → chunk-HLNJKX3S.js} +2 -2
- package/dist/chunks/{chunk-YHBIGFFA.js → chunk-JLZ2TEKK.js} +1 -1
- package/dist/chunks/chunk-JXD5PNF7.js +9 -0
- package/dist/chunks/{chunk-FFTVDR3E.js → chunk-JXGLH7OR.js} +139 -139
- package/dist/chunks/chunk-KCENW4ME.js +2 -0
- package/dist/chunks/{chunk-T7Y5OYO2.js → chunk-KIGN4FI6.js} +1 -1
- package/dist/chunks/{chunk-GTG2ODOV.js → chunk-KRC36KV2.js} +1 -1
- package/dist/chunks/{chunk-XRI3HLZ3.js → chunk-KVJF3H4N.js} +2 -2
- package/dist/chunks/{chunk-FUFIZ37W.js → chunk-LRGLV6JX.js} +1 -1
- package/dist/chunks/chunk-MOMDY22U.js +2 -0
- package/dist/chunks/chunk-MTJNKRXL.js +22 -0
- package/dist/chunks/{chunk-ELUCM7CG.js → chunk-NVPKY3KE.js} +1 -1
- package/dist/chunks/chunk-POWZXZJ2.js +2 -0
- package/dist/chunks/{chunk-WWCU4ETR.js → chunk-PU2JM765.js} +1 -1
- package/dist/chunks/{chunk-CYZOPDTW.js → chunk-QJX7UASW.js} +1 -1
- package/dist/chunks/chunk-R6YJY7F2.js +3 -0
- package/dist/chunks/{chunk-3QXPXBVG.js → chunk-RT6YPMWF.js} +1 -1
- package/dist/chunks/{chunk-TU5ITNMX.js → chunk-TPOW52DO.js} +3 -3
- package/dist/chunks/chunk-V62BHD5G.js +2 -0
- package/dist/chunks/{chunk-IYWNO4RB.js → chunk-VB2S5HV4.js} +2 -2
- package/dist/chunks/{chunk-3UQU3KOS.js → chunk-VKGVC26K.js} +1 -1
- package/dist/chunks/{chunk-ZCFX6HQO.js → chunk-VQG25QBJ.js} +1 -1
- package/dist/chunks/{chunk-JARGGWF5.js → chunk-XMXGITQE.js} +1 -1
- package/dist/chunks/chunk-Z2BYC6TP.js +2 -0
- package/dist/chunks/{chunk-562Q5UVS.js → chunk-ZG7QX66E.js} +1 -1
- package/dist/chunks/cli-QW2BELOE.js +2 -0
- package/dist/chunks/configuration-command-VXCGFVAP.js +2 -0
- package/dist/chunks/core-commands-XEPFY3PQ.js +2 -0
- package/dist/chunks/{datasets-W24QTQL7.js → datasets-6PTDCZQ7.js} +1 -1
- package/dist/chunks/desktop-test-JGSH4T5Z.js +3 -0
- package/dist/chunks/dist-ELWB75PL.js +2 -0
- package/dist/chunks/experiments-WKRYHZDK.js +2 -0
- package/dist/chunks/{extension-3P3JNRYN.js → extension-S2UIZH46.js} +1 -1
- package/dist/chunks/{help-23QDOMG7.js → help-ZVAGMF3C.js} +1 -1
- package/dist/chunks/hosted-harness-runtime-F4UPHTTT.js +2 -0
- package/dist/chunks/hosted-profile-compiler-4LKIBC75.js +2 -0
- package/dist/chunks/hosted-profile-evaluation-control-WPRPL4YW.js +2 -0
- package/dist/chunks/hosted-profile-evaluation-inspection-ULRRZDS2.js +3 -0
- package/dist/chunks/hosted-profile-evaluation-preparation-NWR4PRHS.js +3 -0
- package/dist/chunks/opchat-EOQ4PPE7.js +3 -0
- package/dist/chunks/organizations-4IGFWOYA.js +2 -0
- package/dist/chunks/{profile-NJMKPS6Z.js → profile-KJS7WQ3F.js} +1 -1
- package/dist/chunks/project-agent-6WNHPBXA.js +2 -0
- package/dist/chunks/sandbox-command-NCRIL6NH.js +2 -0
- package/dist/chunks/{sandbox-template-RCDR2FXX.js → sandbox-template-AAOUNWTL.js} +1 -1
- package/dist/chunks/{src-H7VE4J62.js → src-HLLPHEW4.js} +1 -1
- package/dist/chunks/{src-JVSP6UKT.js → src-PERIQ7VT.js} +91 -91
- package/dist/chunks/{teams-bot-KCKZTM3N.js → teams-bot-LKIOF3B5.js} +1 -1
- package/dist/chunks/{workspaces-J5QQUR53.js → workspaces-S3NXR6VJ.js} +1 -1
- package/dist/cli.js +3 -3
- package/dist/index.js +1 -1
- package/package.json +1 -1
- package/dist/chunks/actions-command-X2ERGYMA.js +0 -2
- package/dist/chunks/app-server-runtime-IO3FDF37.js +0 -2
- package/dist/chunks/apps-IBVU56HR.js +0 -2
- package/dist/chunks/chunk-5OA57RW4.js +0 -2
- package/dist/chunks/chunk-62H5KUOS.js +0 -12
- package/dist/chunks/chunk-AOBTILU5.js +0 -2
- package/dist/chunks/chunk-DDHUSA3I.js +0 -2
- package/dist/chunks/chunk-QCLVO56H.js +0 -4
- package/dist/chunks/chunk-QK2GLRCY.js +0 -53
- package/dist/chunks/chunk-SHCKK3SU.js +0 -2
- package/dist/chunks/chunk-ZCPIVNCS.js +0 -2
- package/dist/chunks/cli-QXO6OHZJ.js +0 -2
- package/dist/chunks/configuration-command-6VJUXQNZ.js +0 -2
- package/dist/chunks/core-commands-J6OY62PE.js +0 -2
- package/dist/chunks/desktop-test-SHS2VUYP.js +0 -3
- package/dist/chunks/dist-4OUZANXR.js +0 -2
- package/dist/chunks/experiments-O7WTSICN.js +0 -2
- package/dist/chunks/hosted-harness-runtime-U7JV7Z5T.js +0 -2
- package/dist/chunks/hosted-profile-compiler-ZCVMUTFA.js +0 -3
- package/dist/chunks/opchat-OI2YFNNY.js +0 -3
- package/dist/chunks/organizations-LB5QXKWT.js +0 -2
- package/dist/chunks/project-agent-SZLUVG3U.js +0 -2
- package/dist/chunks/sandbox-command-FQBOFZGM.js +0 -2
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { createRequire as __openpondCreateRequire } from "node:module"; var require = __openpondCreateRequire(import.meta.url);
|
|
2
|
+
import{E as h}from"./chunk-PKBU37CH.js";import{h as S}from"./chunk-JXD5PNF7.js";import{aa as A}from"./chunk-JXGLH7OR.js";import{Ba as O,Ca as k,i as I,l as P,o as b,q as H,r as w,v as f}from"./chunk-QUNRWDVO.js";import{l as g}from"./chunk-HZP5U2AA.js";import{b as c}from"./chunk-ES2ISFJC.js";import{a as u}from"./chunk-FTQLQJQV.js";import{randomUUID as T}from"node:crypto";import{readFile as v}from"node:fs/promises";import p from"node:path";import{randomUUID as $}from"node:crypto";var y=c.object({revision:c.number().int().nonnegative(),overlay:H}).strict(),z=y.extend({proposal:w}).strict(),m=class{constructor(e){this.client=e}client;static{u(this,"HostedHarnessOverlayStorage")}async getHarnessRunOverlay(e){let s=await this.client.request({contractVersion:h,requestId:$(),operation:"harness/overlay/get",params:{runId:e}});return s===null?null:y.parse(s).overlay}async putHarnessRunOverlay(e){let s=H.parse(e.overlay);if(!e.requestId.trim()||s.revision!==(e.expectedRevision===null?0:e.expectedRevision+1))throw new Error("Hosted Harness overlay mutation requires a stable request and next revision.");let r=y.parse(await this.client.request({contractVersion:h,requestId:e.requestId,operation:"harness/overlay/put",params:{runId:s.runId,expectedRevision:e.expectedRevision,overlay:s}}));if(r.revision!==s.revision||r.overlay.contentHash!==s.contentHash)throw new Error("Host Harness overlay response changed committed identity.");return r.overlay}async createHarnessRunOverlay(e){if(e.revision!==0||e.status!=="active")throw new Error("A new Harness run overlay must be active at revision 0.");return this.putHarnessRunOverlay({overlay:e,expectedRevision:null,requestId:`harness-overlay:${e.runId}:${e.contentHash}`})}async ensureHarnessRunOverlay(e){let s=await this.getHarnessRunOverlay(e.runId);if(s){if(s.workspace.workspaceId!==e.workspace.id||s.baseHarnessRelease.id!==e.harnessRelease.id||s.baseHarnessRelease.contentHash!==e.harnessRelease.contentHash)throw new Error("The durable Agent run is already bound to another Harness release.");return s}let r=f({schemaVersion:"openpond.harnessRunOverlay.v1",id:`overlay-${g({runId:e.runId,harnessRelease:e.harnessRelease}).slice(0,24)}`,runId:e.runId,baseHarnessRelease:e.harnessRelease,workspace:{workspaceId:e.workspace.id,revision:e.workspace.revision,sourceRevision:e.workspace.sourceRevision,channelRevision:e.workspace.currentChannel.revision},revision:0,status:"active",edits:[],createdAt:e.admittedAt,updatedAt:e.admittedAt,metadata:{}});return this.createHarnessRunOverlay(r)}async appendHarnessRunOverlayEditsAtomically(e){return this.transition(e,"append")}async freezeHarnessRunOverlayAtomically(e){return this.transition({...e,edits:[]},"freeze")}async abandonHarnessRunOverlayAtomically(e){return this.transition({...e,edits:[]},"abandon")}async freezeHarnessRunOverlayWithProposalAtomically(e){let s=await this.getHarnessRunOverlay(e.runId);if(!s||s.revision!==e.expectedRevision||s.status!=="active")throw new Error("Hosted Harness overlay revision or status changed.");let r=new Set(s.edits.map(i=>i.id));for(let i of e.edits){if(r.has(i.id))throw new Error(`Harness overlay edit id already exists: ${i.id}.`);r.add(i.id)}let{contentHash:l,...n}=s,t=f({...n,revision:s.revision+1,status:"frozen",edits:[...s.edits,...e.edits],updatedAt:e.updatedAt}),d=w.parse(e.buildProposal(t)),a=z.parse(await this.client.request({contractVersion:h,requestId:`harness-proposal:${t.runId}:${d.contentHash}`,operation:"harness/overlay/freezeProposal",params:{runId:t.runId,expectedRevision:s.revision,overlay:t,proposal:d}}));if(a.overlay.contentHash!==t.contentHash||a.proposal.contentHash!==d.contentHash)throw new Error("Host Harness proposal response changed committed identity.");return{overlay:a.overlay,proposal:a.proposal}}async transition(e,s){let r=await this.getHarnessRunOverlay(e.runId);if(!r||r.revision!==e.expectedRevision||r.status==="abandoned"||s!=="abandon"&&r.status!=="active")throw new Error("Hosted Harness overlay revision or status changed.");if(s==="append"&&e.edits.length===0)throw new Error("Harness overlay append requires edits.");let l=new Set(r.edits.map(a=>a.id));for(let a of e.edits){if(l.has(a.id))throw new Error(`Harness overlay edit id already exists: ${a.id}.`);l.add(a.id)}let{contentHash:n,...t}=r,d=f({...t,revision:r.revision+1,status:s==="append"?"active":s==="freeze"?"frozen":"abandoned",edits:[...r.edits,...e.edits],updatedAt:e.updatedAt});return this.putHarnessRunOverlay({overlay:d,expectedRevision:r.revision,requestId:`harness-overlay:${d.runId}:${d.contentHash}`})}};var N=c.object({workspace:b,release:c.object({id:c.string().min(1),contentHash:c.string().regex(/^[a-f0-9]{64}$/),sourceRevision:c.string().min(1),assetsPath:c.string().min(1)}).strict()}).strict();async function C(o,e=null){let s=await o.request({contractVersion:h,requestId:T(),operation:"harness/get",params:{reference:e}});if(s===null)return null;let r=N.parse(s);if(!p.isAbsolute(r.release.assetsPath))throw new Error("Hosted Harness assets path must be absolute.");let[l,n]=await Promise.all([v(p.join(r.release.assetsPath,"agent-snapshot.json"),"utf8"),v(p.join(r.release.assetsPath,"harness-release.json"),"utf8")]),t=A.parse({schemaVersion:"openpond.localHarnessReleaseRecord.v1",workspaceId:r.workspace.id,sourceRevision:r.release.sourceRevision,agentSnapshot:I.parse(JSON.parse(l)),harnessRelease:P.parse(JSON.parse(n)),bundlePath:r.release.assetsPath,createdAt:new Date().toISOString()});if(t.harnessRelease.id!==r.release.id||t.harnessRelease.contentHash!==r.release.contentHash||(e!==null?e.id!==r.release.id||e.contentHash!==r.release.contentHash:r.workspace.currentChannel.release?.contentHash!==r.release.contentHash))throw new Error("Hosted Harness release differs from its bound workspace.");return S({workspace:r.workspace,release:t})}u(C,"loadHostedHarnessRuntime");async function se(o,e){let s=e.profileComponentBinding,r=e.profileWorkflowBinding;if(s){if(r||e.currentProfile?.profileId!==s.profileId)throw new Error("Profile component binding differs from the session Profile reference.");let n=await x(o,s.harnessRelease);if(E(n,s.profileId,s.sourceRevision,e.currentProfile?.repositoryId),s.target.kind==="profile")return n;if(s.target.kind==="skill"){let i=s.target.skillPath;if(!n.release.agentSnapshot.skills.some(j=>j.path===i))throw new Error("Bound Profile Skill is unavailable in its released source.");let R=await v(p.join(n.release.bundlePath,"source",i),"utf8");return{...n,instructionContext:[n.instructionContext,`Released Profile Skill (${i}):
|
|
3
|
+
${R}`].join(`
|
|
4
|
+
|
|
5
|
+
`)}}let t=await q(n),d=s.target.actionId,a=t.actions.find(i=>i.id===d);if(!a)throw new Error("Bound Profile Agent action is unavailable in its released source.");return{...n,workflowAction:a}}if(r){if(e.currentProfile?.profileId!==r.profileId)throw new Error("Profile workflow binding differs from the session Profile reference.");let n=await x(o,r.harnessRelease);E(n,r.profileId,r.sourceRevision,e.currentProfile?.repositoryId);let t=await q(n),d=k({binding:r,harnessRelease:n.release.harnessRelease,catalog:t.catalog,catalogHash:t.catalogHash}),a=d.invocation.kind==="agent_action"?d.invocation.actionId:null,i=a?t.actions.find(R=>R.id===a):void 0;if(a&&!i)throw new Error(`Bound Profile action ${a} is missing from its release.`);return{...n,workflow:d,...i?{workflowAction:i}:{}}}let l=await new m(o).getHarnessRunOverlay(e.id);return C(o,l?.baseHarnessRelease??null)}u(se,"loadHostedHarnessRuntimeForSession");async function x(o,e){let s=await C(o,e);if(!s)throw new Error("The bound Profile Harness release is unavailable.");return s}u(x,"requireRelease");function E(o,e,s,r){let l=o.release.harnessRelease.metadata.profile;if(!l||typeof l!="object"||l.id!==e||l.sourceRevision!==s||l.repositoryId!==void 0&&l.repositoryId!==r)throw new Error("Bound Profile source differs from its released Harness source.")}u(E,"assertProfileProvenance");async function q(o){let e=p.join(o.release.bundlePath,"source"),[s,r]=await Promise.all([v(p.join(e,"workflows","catalog.json")),v(p.join(e,"workflows","actions.json"))]);return O({agentSnapshot:o.release.agentSnapshot,harnessRelease:o.release.harnessRelease,catalogBytes:s,actionBytes:r})}u(q,"loadHostedProfileCatalog");export{m as a,C as b,se as c};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { createRequire as __openpondCreateRequire } from "node:module"; var require = __openpondCreateRequire(import.meta.url);
|
|
2
|
+
import{$a as x,Pa as b,Qa as E,cb as T,eb as C,fb as _,h as S,i as A,u as M}from"./chunk-TPOW52DO.js";import{h as k,l as m,m as y}from"./chunk-HZP5U2AA.js";import{b as p}from"./chunk-ES2ISFJC.js";import{a as g}from"./chunk-FTQLQJQV.js";var w=p.object({sessionId:p.string().trim().min(1).max(500),turnId:p.string().trim().min(1).max(500)}).strict();async function $(e){T(e.manifest,e.taskset,e.catalog),_(e.taskset,e.metricSource);let o=e.manifest.profileEvaluation,t=e.catalog.definitions.find(r=>r.id===o.definitionId),d=new Map(e.taskset.tasks.map(r=>[r.id,r])),u=[],s=[];for(let r of e.manifest.population){e.signal?.throwIfAborted();let l=d.get(r.taskId),a=await e.loadCompletedMember?.(r)??null;if(a){let{receipt:f,grade:I}=a,{contentHash:P,...U}=S.parse(I);if(!E(f)||P!==m(U)||f.id!==r.receiptId||f.runManifest.id!==e.manifest.id||f.runManifest.contentHash!==e.manifest.contentHash||f.taskId!==r.taskId||f.seed!==r.seed||f.graderEvidenceRefs.length!==1||f.graderEvidenceRefs[0]?.contentHash!==P||I.taskHash!==m(l)||I.graderSetHash!==m(e.taskset.graders)||f.metadata.score!==I.score||f.metadata.passed!==I.passed)throw new Error(`Retained Profile evaluation member ${r.receiptId} differs from its admitted evidence.`);s.push(I),u.push(f);continue}let i=await e.execute({task:M(l),seed:r.seed,source:o,...e.signal?{signal:e.signal}:{}});e.signal?.throwIfAborted();let c=await A({task:l,evidence:i.evidence,graders:e.taskset.graders,...e.modelJudge?{modelJudge:e.modelJudge}:{},...e.customVerifier?{customVerifier:e.customVerifier}:{},...e.signal?{signal:e.signal}:{}}),v=k.parse(await e.saveGrade(c));if(v.contentHash!==c.contentHash)throw new Error("Stored Profile evaluation grade differs from its graded evidence.");let H=i.failureClass??c.failureClass,R=b({schemaVersion:"openpond.attemptReceipt.v1",id:r.receiptId,runManifest:{id:e.manifest.id,contentHash:e.manifest.contentHash},taskId:r.taskId,seed:r.seed,terminal:i.terminal,failureClass:H,outputHash:i.evidence.infrastructureError?null:m(i.evidence.output),traceHash:i.traceHash,artifactRefs:i.artifactRefs,graderEvidenceRefs:[v],startedAt:i.startedAt,completedAt:i.completedAt,latencyMs:i.latencyMs,costUsd:i.costUsd,metadata:{gradingRole:"evaluation",score:c.score,passed:c.passed,rewardEligible:c.rewardEligible,sourceRevision:o.sourceRevision,definitionHash:o.definitionHash,environmentHash:o.environmentHash,...i.retainedEvidenceRef?{retainedEvidenceRef:w.parse(i.retainedEvidenceRef)}:{}}});await e.saveReceipt(R),s.push(c),u.push(R)}let n=await C({manifest:e.manifest,taskset:e.taskset,receipts:u,...e.metricSource!==void 0?{source:e.metricSource}:{},...e.signal?{signal:e.signal}:{}},e.metricExecutor),h=s.filter(r=>r.passed).length/s.length;return{receipts:u,grades:s,metric:n,passRate:h,passed:h>=t.criterion.minimumPassRate&&(!t.criterion.requireComplete||u.every(r=>r.terminal))}}g($,"executeProfileEvaluationRun");function V(e,o){if(o==="agent_action"){let t=e.find(d=>d.name==="workspace_action_result"&&d.action==="profile_workflow_action")?.output;if(typeof t!="string")throw new Error("Profile Agent action evaluation did not produce a released action result.");return t}return e.filter(t=>t.name==="assistant.delta"&&typeof t.output=="string").map(t=>t.output??"").join("")}g(V,"profileEvaluationOutput");async function L(e){let{store:o,manifest:t,receipt:d}=e;if(!d.metadata.retainedEvidenceRef)return null;let u=w.parse(d.metadata.retainedEvidenceRef),[s,n]=await Promise.all([o.getSession(u.sessionId),o.getTurn(u.turnId)]),h=s?.metadata?.profileEvaluationRun,r=t.profileEvaluation;if(!s||!n||n.sessionId!==s.id||!r||!s.currentProfile||m(s.currentProfile)!==m(e.profileRef)||m(h)!==m({id:t.id,contentHash:t.contentHash})||s.metadata?.taskId!==d.taskId||s.metadata?.seed!==d.seed||!n.completedAt||n.completedAt!==d.completedAt||n.startedAt!==d.startedAt||!n.harnessSnapshot||n.harnessSnapshot.harnessRelease.id!==r.harnessRelease.id||n.harnessSnapshot.harnessRelease.contentHash!==r.harnessRelease.contentHash||t.policy.kind!=="model"||!n.modelRef||n.modelRef.providerId!==t.policy.model.provider||n.modelRef.modelId!==t.policy.model.model)throw new Error("Retained Profile policy turn differs from its admitted case.");let l=await o.runtimeEventsForTurn(n.id);if(l.some(f=>f.turnId!==n.id)||m(l)!==d.traceHash)throw new Error("Retained Profile policy trace differs from its immutable receipt.");let a=V(l,r.target.kind);if(d.outputHash!==null&&m({text:a})!==d.outputHash)throw new Error("Retained Profile output differs from its immutable receipt.");let i=await o.listModelUsageRecords({sessionId:s.id,turnId:n.id,limit:1e4}),c=e.eventAfterId?l.findIndex(f=>f.id===e.eventAfterId):-1;if(e.eventAfterId&&c<0)throw new Error("Profile trace cursor is unavailable in this case.");let v=c+1,H=Math.max(1,Math.min(250,e.eventLimit??100)),R=l.slice(v,v+H);return{ref:u,prompt:n.prompt,output:d.outputHash===null?null:{text:a},partialOutput:d.outputHash===null&&a?{text:a}:null,error:n.error,events:R,eventCount:l.length,nextEventCursor:v+R.length<l.length?R.at(-1).id:null,usage:i,usageCoverage:i.length===1e4?"partial":"complete"}}g(L,"readProfileEvaluationPolicyEvidence");var te=p.object({runId:p.string().trim().min(1).max(240),receiptId:p.string().trim().min(1).max(500).optional(),eventAfterId:p.string().trim().min(1).max(500).optional(),eventLimit:p.number().int().min(1).max(250).optional(),manifest:x.optional()}).strict().refine(e=>e.receiptId||!e.eventAfterId&&!e.eventLimit,"Select a case before requesting its trace page.").refine(e=>!e.manifest||e.receiptId,"Interrupted-run inspection requires one exact case.");async function re(e){let o=await e.store.getProfileEvaluationRun(e.runId);if(o&&m(o.profileRef)!==m(e.profileRef))throw new Error("Profile evaluation run is unavailable in the selected Profile.");let t=o?.manifest??e.manifest;if(!t||!o&&!e.receiptId)throw new Error("Profile evaluation run is unavailable in the selected Profile.");if(o){if(e.manifest&&e.manifest.contentHash!==o.manifest.contentHash)throw new Error("Profile evaluation run differs from its pinned manifest.")}else if(y(t,"Interrupted Profile evaluation manifest"),t.id!==e.runId||t.profileEvaluation?.profileId!==e.profileRef.profileId||e.profileRef.source==="openpond_git"&&t.metadata.profileRepositoryId!==e.profileRef.repositoryId)throw new Error("Profile evaluation run is unavailable in the selected Profile.");let d=t.population.map((s,n)=>({member:s,index:n})).filter(({member:s})=>!e.receiptId||s.receiptId===e.receiptId);if(e.receiptId&&d.length!==1)throw new Error("Profile evaluation case is unavailable in the selected run.");let u=await Promise.all(d.map(async({member:s,index:n})=>{let h=o?null:await e.store.getProfileEvaluationReceipt(s.receiptId),r=o?.receiptRefs[n]??(h?{id:h.id,contentHash:h.contentHash}:null),l=o?.gradeRefs[n]??h?.graderEvidenceRefs[0];if(!r||!l)throw new Error("Profile evaluation run has incomplete case evidence.");let[a,i]=await Promise.all([e.store.getProfileEvaluationReceipt(r.id),e.store.getProfileEvaluationGrade(l.contentHash)]);if(!a||!o&&!E(a)||a.contentHash!==r.contentHash||a.id!==s.receiptId||a.taskId!==s.taskId||a.seed!==s.seed||a.runManifest.id!==t.id||a.runManifest.contentHash!==t.contentHash||!i||i.contentHash!==l.contentHash||!a.graderEvidenceRefs.some(c=>c.id===l.id&&c.contentHash===l.contentHash))throw new Error("Profile evaluation case evidence differs from its retained run.");return{taskId:s.taskId,seed:s.seed,receiptId:a.id,receiptHash:a.contentHash,traceHash:a.traceHash,outputHash:a.outputHash,score:i.score,passed:i.passed,gradingStatus:i.gradingStatus,failureClass:i.failureClass,artifactCount:a.artifactRefs.length,latencyMs:a.latencyMs,costUsd:a.costUsd,terminal:a.terminal,feedback:i.components.map(c=>({graderId:c.graderId,graderVersion:c.graderVersion,score:c.score,passed:c.passed,feedback:c.feedback})),...e.receiptId?{receipt:a,evidence:await L({store:e.store,profileRef:e.profileRef,manifest:t,receipt:a,eventAfterId:e.eventAfterId,eventLimit:e.eventLimit})}:{}}}));return{runId:t.id,sourceRevision:t.profileEvaluation?.sourceRevision??null,cases:u}}g(re,"inspectProfileEvaluationRun");export{$ as a,V as b,te as c,re as d};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { createRequire as __openpondCreateRequire } from "node:module"; var require = __openpondCreateRequire(import.meta.url);
|
|
2
|
+
import{b as y}from"./chunk-AO753YWB.js";import{E as u,J as E,K as O}from"./chunk-PKBU37CH.js";import{O as w,R as S,S as b,Y as f}from"./chunk-HLNJKX3S.js";import{Ba as A}from"./chunk-QUNRWDVO.js";import{c as H,e as v,f as k,g as U,i as M,qa as j}from"./chunk-ALZRXBEC.js";import{b as n}from"./chunk-ES2ISFJC.js";import{a as h,c as R,f as x,h as l}from"./chunk-H7IWJN7L.js";import{a as i}from"./chunk-FTQLQJQV.js";import m from"node:path";import{AsyncLocalStorage as J}from"node:async_hooks";import{promises as C}from"node:fs";var T=new J;function Z(r,e=!1){let t=T.getStore();t&&(e&&(t.length=0),t.push(r))}i(Z,"onStartupFailure");async function ee(r,e){await j(r);let t;try{t=await U(m.join(l(r).runtime,"server-owner"),100)}catch(s){if(s instanceof R&&s.issue.code==="STORAGE_BUSY"){let a=await M(m.join(l(r).runtime,"endpoint.json"),()=>null);throw new R({code:"RUNTIME_ALREADY_RUNNING",path:r,message:"An OpenPond runtime already owns this home.",action:a?.url?`Connect to the existing runtime at ${a.url}, or stop it before starting another.`:"Stop the existing runtime before starting another with this home."})}throw s}let o=[];try{let s=await h(r,()=>T.run(o,e)),a=s.close.bind(s);o.length=0;let c;return{...s,close:i(()=>c??=(async()=>{try{await h(r,a)}finally{await C.rm(m.join(l(r).runtime,"endpoint.json"),{force:!0}),await t()}})(),"close")}}catch(s){try{for(let a of o.reverse())await Promise.resolve().then(()=>h(r,a)).catch(()=>{});await C.rm(m.join(l(r).runtime,"endpoint.json"),{force:!0})}finally{await t()}throw s}}i(ee,"ownHomeRuntime");async function te(r,e,t){await v(m.join(l(r).runtime,"endpoint.json"),JSON.stringify({schemaVersion:"openpond.runtimeEndpoint.v1",pid:process.pid,url:e,serverId:t}))}i(te,"publishRuntimeEndpoint");function ne(r){return W({runtime:O(r.ports),close:r.close})}i(ne,"createAppServer");function W(r){let e=!1;return{runtime:r.runtime,close:i(async()=>{e||(e=!0,await r.close?.())},"close")}}i(W,"attachAppServer");async function ie(r){let e=typeof r.appServer=="function"?null:r.appServer;try{await E({host:e?.runtime??(async()=>(e=await r.appServer(),e.runtime)),readable:r.readable,writable:r.writable,hostStorageClient:r.hostStorageClient})}finally{await e?.close()}}i(ie,"runAppServerJsonl");import{randomBytes as z}from"node:crypto";function pe(){return x()}i(pe,"appDataDir");function ue(r){return l(r).config}i(ue,"providersConfigPath");function me(r){return l(r).credentials}i(me,"providerSecretsConfigPath");function ge(r){return l(r).key}i(ge,"providerSecretsKeyPath");async function fe(r){let e=l(r).token;return k(e,async()=>{let t=(await H(e))?.trim(),o=process.env.OPENPOND_APP_TOKEN||t||z(32).toString("base64url");return o!==t&&await v(e,o),{token:o,tokenFile:e}})}i(fe,"ensureCapabilityToken");import p from"node:path";import{readFile as _}from"node:fs/promises";var F=n.object({profileId:n.string().min(1),sourceRevision:n.string().min(1),repositoryId:n.string().min(1),harnessRelease:n.object({id:n.string().min(1),contentHash:n.string().regex(/^[a-f0-9]{64}$/)}).strict(),hostExecution:n.object({conversationId:n.string().min(1),turnId:n.string().min(1)}).strict().optional(),workspaceId:n.string().min(1),assetsPath:n.string().min(1).refine(p.isAbsolute)}).strict();async function Se(r,e){let t=F.parse(e),o=await y(r,t.harnessRelease);if(!o||p.resolve(o.release.bundlePath)!==p.resolve(t.assetsPath))throw new Error("Hosted Profile release changed after admission.");let s=o.release.harnessRelease.metadata.profile;if(!s||typeof s!="object"||s.id!==t.profileId||s.sourceRevision!==t.sourceRevision||s.repositoryId!==void 0&&s.repositoryId!==t.repositoryId)throw new Error("Hosted Profile provenance differs from admitted release.");return{profile:b(),profileLibrary:S()}}i(Se,"loadHostedProfileStateAndLibrary");async function be(r,e){let t=F.parse(e),o=await y(r,t.harnessRelease);if(!o||p.resolve(o.release.bundlePath)!==p.resolve(t.assetsPath))throw new Error("Hosted Profile workflow release is unavailable.");let s=o.release.harnessRelease.metadata.profile;if(s?.id!==t.profileId||s.sourceRevision!==t.sourceRevision||s.repositoryId!==void 0&&s.repositoryId!==t.repositoryId)throw new Error("Hosted Profile workflow provenance changed.");let a=t.harnessRelease,c={source:"openpond_git",repositoryId:t.repositoryId,profileId:t.profileId};if(!o.release.harnessRelease.files.some(g=>g.path==="workflows/catalog.json"))return{profileRef:c,sourceRevision:t.sourceRevision,harnessRelease:a,workflows:[]};let d=p.join(o.release.bundlePath,"source","workflows"),I=A({agentSnapshot:o.release.agentSnapshot,harnessRelease:o.release.harnessRelease,catalogBytes:await _(p.join(d,"catalog.json")),actionBytes:await _(p.join(d,"actions.json"))});return{profileRef:c,sourceRevision:t.sourceRevision,harnessRelease:a,workflows:I.catalog.workflows.map(g=>({workflow:g,binding:{schemaVersion:"openpond.profileWorkflowBinding.v1",profileId:t.profileId,sourceRevision:t.sourceRevision,harnessRelease:a,catalogHash:I.catalogHash,workflowId:g.id}}))}}i(be,"listHostedProfileWorkflows");import{createHash as G,randomUUID as P}from"node:crypto";var N=n.object({approval:w,revision:n.number().int().positive()}).strict(),B=n.object({record:f}).strict(),$=n.object({startedAt:n.string().min(1),requestOrdinal:n.number().int().nonnegative(),id:n.string().min(1)}).strict(),q=n.object({records:n.array(f).max(200),nextBefore:$.nullable()}).strict(),V=1e4,L=class{constructor(e){this.client=e}client;static{i(this,"HostedApprovalStorage")}async readApproval(e){let t=await this.client.request({contractVersion:u,requestId:P(),operation:"approval/get",params:{approvalId:e}});return t===null?null:N.parse(t)}async getApproval(e){return(await this.readApproval(e))?.approval??null}async putApproval(e){let t=w.parse(e.approval);if(!e.requestId.trim())throw new Error("Approval mutation requires a stable request ID.");return N.parse(await this.client.request({contractVersion:u,requestId:e.requestId,operation:"approval/upsert",params:{approval:t,expectedRevision:e.expectedRevision}}))}},D=class{constructor(e){this.client=e}client;static{i(this,"HostedModelUsageStorage")}async upsertModelUsageRecord(e){let t=f.parse(e),o=G("sha256").update(JSON.stringify(t)).digest("hex"),s=await this.client.request({contractVersion:u,requestId:`usage:${o}`,operation:"usage/upsert",params:{record:t}}),a=B.parse(s).record;if(a.requestId!==t.requestId)throw new Error("Host usage upsert changed request identity.");return a}async getModelUsageRecordByRequestId(e){let t=await this.client.request({contractVersion:u,requestId:P(),operation:"usage/getByRequestId",params:{requestId:e}});return t===null?null:B.parse(t).record}async listModelUsageRecords(e={}){let t=e.limit===void 0||e.limit>=V,o=e.limit===void 0?V:Math.max(1,Math.min(1e4,Math.trunc(e.limit))),s={...e.sessionId?{sessionId:e.sessionId}:{},...e.turnId?{turnId:e.turnId}:{},...e.provider?{provider:e.provider}:{},...e.model?{model:e.model}:{},...e.startedAtFrom?{startedAtFrom:e.startedAtFrom}:{},...e.startedAtTo?{startedAtTo:e.startedAtTo}:{},...e.visibility&&e.visibility!=="all"?{visibility:e.visibility}:{},...e.status&&e.status!=="all"?{status:e.status}:{}},a=[],c=null;for(;a.length<o+(t?1:0);){let d=q.parse(await this.client.request({contractVersion:u,requestId:P(),operation:"usage/page",params:{query:s,before:c,limit:Math.min(200,o+(t?1:0)-a.length)}}));if(a.push(...d.records),a.length>o)throw new Error(`Hosted usage query exceeds ${o} rows; narrow its filters or use a streamed aggregation.`);if(d.nextBefore===null)break;if(d.records.length===0||JSON.stringify(d.nextBefore)===JSON.stringify(c))throw new Error("Host usage cursor did not advance.");c=d.nextBefore}return a}async listModelUsageRecordsComplete(e={}){return this.listModelUsageRecords(e)}};export{Z as a,ee as b,te as c,ne as d,ie as e,pe as f,ue as g,me as h,ge as i,fe as j,F as k,Se as l,be as m,L as n,D as o};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { createRequire as __openpondCreateRequire } from "node:module"; var require = __openpondCreateRequire(import.meta.url);
|
|
2
|
+
import{P as H,Q as L,_ as S}from"./chunk-ALZRXBEC.js";import{f as A,h as O}from"./chunk-H7IWJN7L.js";import{a as l}from"./chunk-FTQLQJQV.js";import Q from"node:path";var U="default",z=["apiKey","baseUrl","apiBaseUrl","chatApiBaseUrl","token","appId","conversationId"];function re(){return V()}l(re,"getConfigPath");function V(){return O(A()).config}l(V,"getGlobalConfigPath");function m(n,e){return Object.prototype.hasOwnProperty.call(n,e)}l(m,"hasOwn");function h(n){if(typeof n!="string")return null;let e=n.trim();return e.length>0?e:null}l(h,"normalizeHandle");function d(n){if(typeof n!="string")return null;let e=n.trim();return e?e.replace(/\/$/,""):null}l(d,"normalizeBaseUrl");function q(n){let e=h(n);if(!e)throw new Error("profile handle must be non-empty");return e}l(q,"requireHandle");function W(n){if(typeof n!="string")throw new Error("apiKey must be a non-empty string");let e=n.trim();if(!e)throw new Error("apiKey must be a non-empty string");return e}l(W,"requireApiKey");function b(n,e){let t=h(n),s=h(e);return!!(t&&s&&t.toLowerCase()===s.toLowerCase())}l(b,"handleEquals");function v(n,e,t){let s=d(t);return n.findIndex(i=>b(i.handle,e)?s?d(i.baseUrl)===s:!0:!1)}l(v,"findAccountIndex");function P(n){let e=h(n.handle)??U,t=d(n.baseUrl);return t?{handle:e,baseUrl:t}:{handle:e}}l(P,"selectorFromAccount");function y(n){if(!n||typeof n!="object"||Array.isArray(n))return null;let e=n,t=h(typeof e.handle=="string"?e.handle:void 0);if(!t)return null;let s=d(typeof e.baseUrl=="string"?e.baseUrl:void 0);return s?{handle:t,baseUrl:s}:{handle:t}}l(y,"sanitizeActiveProfile");function B(n){if(!n||typeof n!="object"||Array.isArray(n))return;let e=n,t=typeof e.repoPath=="string"?e.repoPath.trim():"",s=typeof e.profile=="string"&&e.profile.trim()?e.profile.trim():"default";if(!t)return;let i={repoPath:t,profile:s,mode:"local"};if(e.lastCheck&&typeof e.lastCheck=="object"&&!Array.isArray(e.lastCheck)){let o=e.lastCheck,a=o.command,u=o.status,c=o.checkedAt;(a==="inspect"||a==="build"||a==="validate"||a==="eval"||a==="run")&&(u==="passed"||u==="failed")&&typeof c=="string"&&(i.lastCheck={command:a,status:u,checkedAt:c,...typeof o.exitCode=="number"||o.exitCode===null?{exitCode:o.exitCode}:{},...typeof o.sourceHead=="string"||o.sourceHead===null?{sourceHead:o.sourceHead}:{}})}if(e.lastPush&&typeof e.lastPush=="object"&&!Array.isArray(e.lastPush)){let o=e.lastPush,a=o.status,u=o.pushedAt;(a==="pushed"||a==="failed")&&typeof u=="string"&&(i.lastPush={status:a,pushedAt:u,...typeof o.teamId=="string"||o.teamId===null?{teamId:o.teamId}:{},...typeof o.projectId=="string"||o.projectId===null?{projectId:o.projectId}:{},...typeof o.localHead=="string"||o.localHead===null?{localHead:o.localHead}:{},...typeof o.hostedHead=="string"||o.hostedHead===null?{hostedHead:o.hostedHead}:{},...typeof o.sourceRef=="string"||o.sourceRef===null?{sourceRef:o.sourceRef}:{},...o.promotionStatus==="uploaded"||o.promotionStatus==="hosted_source_materialized"||o.promotionStatus==="hosted_source_materialize_failed"||o.promotionStatus==="hosted_source_check_pending"||o.promotionStatus==="hosted_source_check_failed"||o.promotionStatus==="hosted_source_published"||o.promotionStatus==="hosted_source_publish_failed"||o.promotionStatus==="hosted_run_pending"||o.promotionStatus==="hosted_run_passed"||o.promotionStatus==="hosted_run_failed"||o.promotionStatus===null?{promotionStatus:o.promotionStatus}:{},...o.hostedRunStatus==="not_started"||o.hostedRunStatus==="running"||o.hostedRunStatus==="passed"||o.hostedRunStatus==="failed"||o.hostedRunStatus===null?{hostedRunStatus:o.hostedRunStatus}:{},...typeof o.hostedRunAgentId=="string"||o.hostedRunAgentId===null?{hostedRunAgentId:o.hostedRunAgentId}:{},...typeof o.hostedRunId=="string"||o.hostedRunId===null?{hostedRunId:o.hostedRunId}:{},...typeof o.hostedRunAt=="string"||o.hostedRunAt===null?{hostedRunAt:o.hostedRunAt}:{},...w(o.hostedSourceMaterialization)?{hostedSourceMaterialization:w(o.hostedSourceMaterialization)}:{},...E(o.hostedSourceCheck)?{hostedSourceCheck:E(o.hostedSourceCheck)}:{},...K(o.hostedPublish)?{hostedPublish:K(o.hostedPublish)}:{},...M(o.hostedRun)?{hostedRun:M(o.hostedRun)}:{},...typeof o.error=="string"||o.error===null?{error:o.error}:{}})}if(Array.isArray(e.profiles)){let o=e.profiles.flatMap(a=>{let u=B(a);if(!u)return[];let c=a,p=c.source==="github"||c.source==="openpond_git"?c.source:"local",C=typeof c.repositoryId=="string"&&c.repositoryId.trim()?c.repositoryId.trim():Q.resolve(u.repoPath);return[{source:p,repositoryId:C,repoPath:u.repoPath,profile:u.profile,...u.lastCheck?{lastCheck:u.lastCheck}:{},...u.lastPush?{lastPush:u.lastPush}:{}}]});o.length>0&&(i.profiles=o)}return i}l(B,"sanitizeLocalOpenPondProfile");function w(n){if(!n||typeof n!="object"||Array.isArray(n))return null;let e=n,t=R(e.status);return t?{status:t,...r(e,"agentId"),...r(e,"runtimeAgentId"),...r(e,"projectId"),...r(e,"sourceRoot"),...r(e,"sourceRef"),...r(e,"sourceCommitSha"),...r(e,"manifestHash"),...r(e,"manifestPath"),...r(e,"manifestSyncedAt"),...T(e,"fileCount"),...T(e,"totalBytes"),...r(e,"generatedManifestPath"),...k(e,"synthesizedOpenPondYaml"),...r(e,"uploadMetadataPath"),...f(e,"setupCommands"),...f(e,"validationCommands"),...r(e,"materializedAt"),...r(e,"error")}:null}l(w,"sanitizeHostedMaterializationStatus");function E(n){if(!n||typeof n!="object"||Array.isArray(n))return null;let e=n,t=R(e.status);return t?{status:t,...r(e,"agentId"),...r(e,"deployPlanStatus"),...k(e,"canRun"),...k(e,"canDeploy"),...r(e,"sourceRef"),...r(e,"sourceCommitSha"),...r(e,"manifestHash"),...r(e,"manifestPath"),...f(e,"setupCommands"),...f(e,"validationCommands"),...f(e,"requiredChecks"),...f(e,"evalNames"),...f(e,"blockedReasons"),...f(e,"staleReasons"),...r(e,"runtimeId"),...r(e,"sandboxId"),...f(e,"traceArtifactRefs"),...f(e,"evalResultArtifactRefs"),...f(e,"validatorArtifactRefs"),...r(e,"checkedAt"),...r(e,"error")}:null}l(E,"sanitizeHostedSourceCheckStatus");function K(n){if(!n||typeof n!="object"||Array.isArray(n))return null;let e=n,t=R(e.status);return t?{status:t,...r(e,"agentId"),...r(e,"snapshotId"),...r(e,"sourceRef"),...r(e,"sourceCommitSha"),...r(e,"manifestHash"),...r(e,"manifestPath"),...r(e,"buildStatus"),...r(e,"validationStatus"),...r(e,"evalStatus"),...r(e,"publishedAt"),...r(e,"error")}:null}l(K,"sanitizeHostedPublishStatus");function M(n){if(!n||typeof n!="object"||Array.isArray(n))return null;let e=n,t=R(e.status);return t?{status:t,...r(e,"agentId"),...r(e,"runId"),...r(e,"runtimeId"),...r(e,"sandboxId"),...r(e,"sourceRef"),...r(e,"sourceCommitSha"),...r(e,"manifestHash"),...r(e,"setupGateStatus"),...f(e,"setupRequirementRefs"),...f(e,"artifactRefs"),...f(e,"traceArtifactRefs"),...f(e,"evalArtifactRefs"),...r(e,"startedAt"),...r(e,"completedAt"),...r(e,"error")}:null}l(M,"sanitizeHostedRunSummary");function r(n,e){let t=n[e];return typeof t=="string"||t===null?{[e]:t}:{}}l(r,"nullableStringProp");function k(n,e){let t=n[e];return typeof t=="boolean"||t===null?{[e]:t}:{}}l(k,"nullableBooleanProp");function T(n,e){let t=n[e];return typeof t=="number"||t===null?{[e]:t}:{}}l(T,"nullableNumberProp");function f(n,e){let t=n[e];if(!Array.isArray(t))return{};let s=t.filter(i=>typeof i=="string");return{[e]:s}}l(f,"stringArrayProp");function R(n){return typeof n=="string"&&n.trim()?n.trim():null}l(R,"stringField");function D(n,e){if(!b(n.handle,e.handle))return!1;let t=d(e.baseUrl);return t?d(n.baseUrl)===t:!d(n.baseUrl)}l(D,"accountMatchesSelector");function I(n,e,t={}){let s=d(e.baseUrl);if(s)return v(n,e.handle,s);let i=n.findIndex(a=>D(a,e));if(i!==-1)return i;let o=n.map((a,u)=>({account:a,index:u})).filter(({account:a})=>b(a.handle,e.handle));if(o.length>1&&t.requireUnambiguous)throw new Error(`multiple profiles found for ${e.handle}; pass --base-url to select one`);return o[0]?.index??-1}l(I,"findAccountIndexForSelector");function X(n){if(!n||typeof n!="object"||Array.isArray(n))return;let e=n,t={};return typeof e.token=="string"&&(t.token=e.token),(typeof e.appId=="string"||e.appId===null)&&(t.appId=e.appId),(typeof e.conversationId=="string"||e.conversationId===null)&&(t.conversationId=e.conversationId),Object.keys(t).length>0?t:void 0}l(X,"sanitizeSession");function Z(n){if(!n||typeof n!="object"||Array.isArray(n))return null;let e=n,t=h(typeof e.handle=="string"?e.handle:void 0);if(!t)return null;let s={handle:t};typeof e.apiKey=="string"&&(s.apiKey=e.apiKey),typeof e.baseUrl=="string"&&(s.baseUrl=e.baseUrl),typeof e.apiBaseUrl=="string"&&(s.apiBaseUrl=e.apiBaseUrl),typeof e.chatApiBaseUrl=="string"&&(s.chatApiBaseUrl=e.chatApiBaseUrl),typeof e.environment=="string"&&(s.environment=e.environment);let i=X(e.session);return i&&(s.session=i),s}l(Z,"sanitizeAccount");function ee(n){let e={};return typeof n.token=="string"&&(e.token=n.token),(typeof n.appId=="string"||n.appId===null)&&(e.appId=n.appId),(typeof n.conversationId=="string"||n.conversationId===null)&&(e.conversationId=n.conversationId),Object.keys(e).length>0?e:void 0}l(ee,"extractLegacySession");function ne(n,e){let t={handle:e};typeof n.apiKey=="string"&&(t.apiKey=n.apiKey),typeof n.baseUrl=="string"&&(t.baseUrl=n.baseUrl),typeof n.apiBaseUrl=="string"&&(t.apiBaseUrl=n.apiBaseUrl),typeof n.chatApiBaseUrl=="string"&&(t.chatApiBaseUrl=n.chatApiBaseUrl);let s=ee(n);return s&&(t.session=s),t}l(ne,"extractLegacyAccount");function x(n){let e={};typeof n.lspEnabled=="boolean"&&(e.lspEnabled=n.lspEnabled),(n.executionMode==="local"||n.executionMode==="hosted")&&(e.executionMode=n.executionMode),(n.mode==="general"||n.mode==="builder")&&(e.mode=n.mode);let t=B(n.openpondProfile);t&&(e.openpondProfile=t);let s=[],i=Array.isArray(n.accounts)?n.accounts:[];for(let c of i){let p=Z(c);p&&v(s,p.handle,p.baseUrl)===-1&&s.push(p)}if(s.length===0){let c=y(n.activeProfile)?.handle||U;s.push(ne(n,c))}let o=y(n.activeProfile),a=o?I(s,o):-1,u=s[a===-1?0:a];return e.accounts=s,e.activeProfile=P(u),e}l(x,"normalizeGlobalConfig");function N(n,e,t){let s=n.accounts??[],i=d(t??process.env.OPENPOND_BASE_URL),o=h(e);if(o)return i?{handle:o,baseUrl:i}:{handle:o};let a=h(process.env.OPENPOND_ACCOUNT);if(a)return i?{handle:a,baseUrl:i}:{handle:a};let u=y(n.activeProfile);return u?i?{handle:u.handle,baseUrl:i}:u:s[0]?P(s[0]):{handle:U}}l(N,"resolveRequestedProfile");function G(n,e,t){let s=d(t);if(s){let o=v(n,e,s);if(o!==-1)return n[o]}else{let o=n.filter(a=>b(a.handle,e));if(o.length>1)throw new Error(`multiple profiles found for ${e}; pass --base-url to select one`);if(o.length===1)return o[0]}let i={handle:e};return s&&(i.baseUrl=s),n.push(i),i}l(G,"ensureAccount");function j(n){n.session&&Object.keys(n.session).length===0&&delete n.session}l(j,"cleanupAccount");function te(n,e,t,s){let i=t===null||t===void 0&&s.undefinedDeletes;switch(e){case"apiKey":{if(i){delete n.apiKey;return}typeof t=="string"&&(n.apiKey=t);return}case"baseUrl":{if(i){delete n.baseUrl;return}typeof t=="string"&&(n.baseUrl=t);return}case"apiBaseUrl":{if(i){delete n.apiBaseUrl;return}typeof t=="string"&&(n.apiBaseUrl=t);return}case"chatApiBaseUrl":{if(i){delete n.chatApiBaseUrl;return}typeof t=="string"&&(n.chatApiBaseUrl=t);return}case"token":case"appId":case"conversationId":{if(n.session||(n.session={}),i){delete n.session[e],j(n);return}(typeof t=="string"||t===null)&&(n.session[e]=t),j(n);return}}}l(te,"applyScopedKey");function $(n,e,t){if(!z.some(c=>m(e,c)))return!1;let i=n.accounts??[],o=y(e.activeProfile)??N(n),a=d(m(e,"baseUrl")?e.baseUrl??null:o.baseUrl??process.env.OPENPOND_BASE_URL),u=G(i,o.handle,a);for(let c of z)m(e,c)&&te(u,c,e[c],t);return n.accounts=i,n.activeProfile=P(u),!0}l($,"applyAccountPatch");function F(n,e){if(m(e,"lspEnabled")&&(typeof e.lspEnabled=="boolean"?n.lspEnabled=e.lspEnabled:e.lspEnabled===null&&delete n.lspEnabled),m(e,"executionMode")&&(e.executionMode==="local"||e.executionMode==="hosted"?n.executionMode=e.executionMode:e.executionMode===null&&delete n.executionMode),m(e,"mode")&&(e.mode==="general"||e.mode==="builder"?n.mode=e.mode:e.mode===null&&delete n.mode),m(e,"activeProfile")){let t=y(e.activeProfile);if(t){let s=I(n.accounts??[],t);n.activeProfile=s===-1?t:P((n.accounts??[])[s])}else e.activeProfile===null&&delete n.activeProfile}if(m(e,"openpondProfile")){let t=B(e.openpondProfile);t?n.openpondProfile=t:e.openpondProfile===null&&delete n.openpondProfile}}l(F,"applyTopLevelPatch");async function oe(n){let e=A();await S(e),await L(e,()=>n)}l(oe,"writeGlobalConfig");async function _(n){let e=A();return await S(e),await L(e,t=>{let s=x(t);return n(s),s})}l(_,"updateGlobalConfig");async function Y(){let n=A();return await S(n),x(await H(n))}l(Y,"loadGlobalConfig");async function le(n={}){let e=await Y(),t=e.accounts??[],s=N(e,n.account,n.baseUrl),i=I(t,s,{requireUnambiguous:!0}),o=i===-1?null:t[i],a=o?.session;return{...e,activeProfile:o?P(o):s,apiKey:o?.apiKey,baseUrl:o?.baseUrl,apiBaseUrl:o?.apiBaseUrl,chatApiBaseUrl:o?.chatApiBaseUrl,token:a?.token,appId:a?.appId,conversationId:a?.conversationId}}l(le,"loadConfig");async function J(){let n=await Y(),e=y(n.activeProfile);return(n.accounts??[]).map(t=>{let s=h(t.handle)??U;return{handle:s,baseUrl:d(t.baseUrl),apiBaseUrl:d(t.apiBaseUrl),chatApiBaseUrl:d(t.chatApiBaseUrl),environment:t.environment?.trim()||null,isActive:!!(e&&D({...t,handle:s},e)),hasApiKey:!!t.apiKey?.trim(),hasSessionToken:!!t.session?.token?.trim(),sessionAppId:t.session?.appId??null,sessionConversationId:t.session?.conversationId??null}})}l(J,"listConfiguredProfiles");async function ae(n,e={}){let t=q(n),s=d(e.baseUrl),i=-1;await _(a=>{let u=a.accounts??[];if(i=I(u,s?{handle:t,baseUrl:s}:{handle:t},{requireUnambiguous:!0}),i===-1)throw new Error(`profile not found: ${t}`);a.activeProfile=P(u[i])});let o=await J();return o.find(a=>a.isActive)??o[i]}l(ae,"setActiveProfile");async function ue(n){let e=q(n.handle),t=W(n.apiKey),s=d(n.baseUrl),i=d(n.apiBaseUrl),o=d(n.chatApiBaseUrl),a={handle:e};await _(p=>{let C=p.accounts??[],g=G(C,e,s);g.apiKey=t,s&&(g.baseUrl=s),i?g.apiBaseUrl=i:n.apiBaseUrl===null&&delete g.apiBaseUrl,o?g.chatApiBaseUrl=o:n.chatApiBaseUrl===null&&delete g.chatApiBaseUrl,n.environment===null?delete g.environment:typeof n.environment=="string"&&n.environment.trim()&&(g.environment=n.environment.trim()),p.accounts=C,a=P(g),n.setActive!==!1&&(p.activeProfile=a)});let c=(await J()).find(p=>b(p.handle,a.handle)?s?d(p.baseUrl)===s:!0:!1);if(!c)throw new Error(`failed to save profile: ${e}`);return c}l(ue,"saveProfileApiKey");async function ce(n){let e=x(n);F(e,n),$(e,n,{undefinedDeletes:!0}),await oe(e)}l(ce,"saveConfig");async function de(n){await _(e=>{F(e,n),$(e,n,{undefinedDeletes:!1})})}l(de,"saveGlobalConfig");export{re as a,_ as b,Y as c,le as d,J as e,ae as f,ue as g,ce as h,de as i};
|