eve 0.54.2 → 0.54.4

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.
Files changed (146) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/dist/src/cli/commands/init-agent-workspace.js +1 -1
  3. package/dist/src/cli/commands/init-project.d.ts +46 -0
  4. package/dist/src/cli/commands/init-project.js +1 -0
  5. package/dist/src/cli/commands/init-self-modification.d.ts +7 -0
  6. package/dist/src/cli/commands/init-self-modification.js +1 -0
  7. package/dist/src/cli/commands/init-target.js +2 -2
  8. package/dist/src/cli/commands/init-telemetry.d.ts +6 -0
  9. package/dist/src/cli/commands/init-telemetry.js +1 -0
  10. package/dist/src/cli/commands/init.d.ts +3 -0
  11. package/dist/src/cli/commands/init.js +1 -1
  12. package/dist/src/cli/dev/tui/setup-commands.js +1 -1
  13. package/dist/src/cli/telemetry/index.d.ts +1 -1
  14. package/dist/src/compiled/.vendor-stamp.json +8 -6
  15. package/dist/src/compiled/@ai-sdk/anthropic/index.js +2 -2
  16. package/dist/src/compiled/@ai-sdk/google/index.js +7 -7
  17. package/dist/src/compiled/@ai-sdk/mcp/index.js +1 -1
  18. package/dist/src/compiled/@ai-sdk/openai/index.js +4 -4
  19. package/dist/src/compiled/@opentelemetry/api/index.d.ts +2 -0
  20. package/dist/src/compiled/@workflow/core/events-consumer.d.ts +26 -0
  21. package/dist/src/compiled/@workflow/core/flushable-stream.d.ts +41 -0
  22. package/dist/src/compiled/@workflow/core/index.js +2 -2
  23. package/dist/src/compiled/@workflow/core/replay-divergence.d.ts +25 -0
  24. package/dist/src/compiled/@workflow/core/runtime/helpers.d.ts +75 -1
  25. package/dist/src/compiled/@workflow/core/runtime/quickjs-entrypoint.d.ts +30 -8
  26. package/dist/src/compiled/@workflow/core/runtime/quickjs-log-view.d.ts +129 -0
  27. package/dist/src/compiled/@workflow/core/runtime/step-executor.d.ts +2 -21
  28. package/dist/src/compiled/@workflow/core/runtime/suspension-handler.d.ts +0 -22
  29. package/dist/src/compiled/@workflow/core/runtime.js +3 -3
  30. package/dist/src/compiled/@workflow/core/serialization.d.ts +2 -2
  31. package/dist/src/compiled/@workflow/core/step/context-storage.d.ts +2 -0
  32. package/dist/src/compiled/@workflow/core/telemetry/semantic-conventions.d.ts +36 -0
  33. package/dist/src/compiled/@workflow/core/version.d.ts +1 -1
  34. package/dist/src/compiled/@workflow/core/workflow.js +1 -1
  35. package/dist/src/compiled/@workflow/world/analytics.d.ts +23 -23
  36. package/dist/src/compiled/@workflow/world/events.d.ts +4 -2
  37. package/dist/src/compiled/@workflow/world/queue.d.ts +84 -0
  38. package/dist/src/compiled/@workflow/world-local/index.js +5 -5
  39. package/dist/src/compiled/@workflow/world-vercel/index.js +18 -13
  40. package/dist/src/compiled/_chunks/workflow/attribute-changes-BAcgmlXp.js +20 -0
  41. package/dist/src/compiled/_chunks/workflow/coerce-ro2dOxbr.js +1 -0
  42. package/dist/src/compiled/_chunks/workflow/dist-KPieTJHT.js +25 -0
  43. package/dist/src/compiled/_chunks/workflow/dist-PLkAQ-U7.js +2 -0
  44. package/dist/src/compiled/_chunks/workflow/frames-BvATzM2t.js +3 -0
  45. package/dist/src/compiled/_chunks/workflow/{functions-C02-JHBK.js → functions-wMCGZAVk.js} +1 -1
  46. package/dist/src/compiled/_chunks/workflow/resume-hook-BEHe0Uut.js +1 -0
  47. package/dist/src/compiled/_chunks/workflow/run-ChHLjaCt.js +1 -0
  48. package/dist/src/compiled/_chunks/workflow/schemas-DR7NTzNe.js +50 -0
  49. package/dist/src/compiled/_chunks/workflow/sleep-BB2HuVie.js +1 -0
  50. package/dist/src/compiled/_chunks/workflow/{wrapper-BxECO5nh.js → wrapper-CKui_eTd.js} +2 -2
  51. package/dist/src/compiled/_chunks/workflow/ws-transport-CVezyWwZ.js +1 -0
  52. package/dist/src/compiled/just-secrets/LICENSE +21 -0
  53. package/dist/src/compiled/just-secrets/index.d.ts +20 -0
  54. package/dist/src/compiled/just-secrets/index.js +2 -0
  55. package/dist/src/compiled/just-secrets/windows.ps1 +138 -0
  56. package/dist/src/compiler/extension-compatibility.d.ts +12 -12
  57. package/dist/src/compiler/extension-compatibility.js +1 -1
  58. package/dist/src/compiler/normalize-manifest-helpers.d.ts +2 -1
  59. package/dist/src/compiler/normalize-manifest-helpers.js +1 -1
  60. package/dist/src/compiler/normalize-manifest.js +1 -1
  61. package/dist/src/compiler/resolve-workspace-subagent.d.ts +13 -0
  62. package/dist/src/compiler/resolve-workspace-subagent.js +1 -0
  63. package/dist/src/context/dynamic-model-lifecycle.d.ts +0 -6
  64. package/dist/src/context/dynamic-model-lifecycle.js +1 -1
  65. package/dist/src/context/dynamic-resolve-context.js +1 -1
  66. package/dist/src/context/effective-model.d.ts +5 -0
  67. package/dist/src/context/effective-model.js +1 -0
  68. package/dist/src/context/keys.d.ts +2 -0
  69. package/dist/src/context/keys.js +1 -1
  70. package/dist/src/dynamic/definition.d.ts +4 -0
  71. package/dist/src/eve-channel/index.js +1 -1
  72. package/dist/src/eve-channel/types.d.ts +9 -7
  73. package/dist/src/execution/durable-session-migrations/snapshot.d.ts +0 -16
  74. package/dist/src/execution/durable-session-migrations/snapshot.js +1 -1
  75. package/dist/src/execution/eve-workflow-attributes.d.ts +1 -1
  76. package/dist/src/execution/run-session-limits.js +1 -1
  77. package/dist/src/execution/session.js +1 -1
  78. package/dist/src/execution/tools/sleep-workflow.js +1 -1
  79. package/dist/src/execution/workflow-steps.js +1 -1
  80. package/dist/src/harness/compaction.js +1 -1
  81. package/dist/src/harness/messages.d.ts +1 -1
  82. package/dist/src/harness/messages.js +1 -1
  83. package/dist/src/harness/step-hooks.d.ts +16 -10
  84. package/dist/src/harness/step-hooks.js +1 -1
  85. package/dist/src/harness/tool-loop.js +2 -2
  86. package/dist/src/instrumentation/parent-lineage.js +1 -1
  87. package/dist/src/internal/application/package.js +1 -1
  88. package/dist/src/internal/nitro/routes/index.d.ts +6 -0
  89. package/dist/src/internal/nitro/routes/index.js +7 -7
  90. package/dist/src/internal/vercel/assemble-eve-services.js +1 -1
  91. package/dist/src/internal/vercel/build-agent-workspace.js +1 -1
  92. package/dist/src/internal/vercel/build-multi-agent-landing-page.d.ts +3 -0
  93. package/dist/src/internal/vercel/build-multi-agent-landing-page.js +1 -0
  94. package/dist/src/internal/vercel/eve-service-contribution.d.ts +4 -0
  95. package/dist/src/internal/vercel/eve-service-contribution.js +1 -1
  96. package/dist/src/internal/vercel/vercel-services-config.js +1 -1
  97. package/dist/src/protocol/baggage.d.ts +6 -0
  98. package/dist/src/protocol/baggage.js +1 -1
  99. package/dist/src/protocol/traceparent.d.ts +13 -0
  100. package/dist/src/protocol/traceparent.js +1 -1
  101. package/dist/src/public/definitions/workspace-agent.d.ts +25 -0
  102. package/dist/src/public/definitions/workspace-agent.js +1 -0
  103. package/dist/src/public/index.d.ts +1 -0
  104. package/dist/src/public/index.js +1 -1
  105. package/dist/src/public/models/openai/chatgpt/codex-app-server.d.ts +41 -0
  106. package/dist/src/public/models/openai/chatgpt/codex-app-server.js +1 -0
  107. package/dist/src/public/models/openai/chatgpt/credential-store.d.ts +26 -4
  108. package/dist/src/public/models/openai/chatgpt/credential-store.js +1 -1
  109. package/dist/src/public/models/openai/chatgpt/oauth.d.ts +6 -4
  110. package/dist/src/public/models/openai/chatgpt/token-broker.d.ts +7 -7
  111. package/dist/src/public/models/openai/chatgpt/token-broker.js +1 -1
  112. package/dist/src/public/models/openai/chatgpt/token.d.ts +13 -0
  113. package/dist/src/public/models/openai/chatgpt/token.js +1 -0
  114. package/dist/src/public/models/openai/chatgpt/transport.d.ts +2 -1
  115. package/dist/src/public/models/openai/index.d.ts +3 -2
  116. package/dist/src/public/vercel/index.d.ts +50 -0
  117. package/dist/src/public/vercel/index.js +1 -0
  118. package/dist/src/self-modification/setup.js +7 -2
  119. package/dist/src/setup/flows/chatgpt-auth.d.ts +2 -1
  120. package/dist/src/setup/flows/chatgpt-auth.js +1 -1
  121. package/dist/src/setup/flows/model.d.ts +0 -2
  122. package/dist/src/setup/flows/model.js +1 -1
  123. package/dist/src/setup/scaffold/create/project.js +1 -1
  124. package/dist/src/subagents/remote-dispatch.d.ts +3 -1
  125. package/dist/src/subagents/remote-dispatch.js +1 -1
  126. package/dist/src/tracing/agent-otel-attributes.js +1 -1
  127. package/dist/src/tracing/agent-otel-runtime-context.js +1 -1
  128. package/docs/agent-config.md +3 -3
  129. package/docs/guides/deployment/vercel.mdx +52 -1
  130. package/docs/guides/dynamic-capabilities.md +19 -7
  131. package/docs/guides/instrumentation-providers.md +1 -1
  132. package/docs/guides/instrumentation.md +25 -6
  133. package/docs/guides/remote-agents.md +5 -5
  134. package/docs/reference/cli.md +2 -2
  135. package/docs/reference/telemetry.md +1 -1
  136. package/docs/reference/typescript-api.md +14 -7
  137. package/docs/subagents/index.mdx +31 -0
  138. package/package.json +13 -6
  139. package/dist/src/compiled/_chunks/workflow/attribute-changes-C6H-fRVP.js +0 -20
  140. package/dist/src/compiled/_chunks/workflow/dist-DDeH-1ER.js +0 -40
  141. package/dist/src/compiled/_chunks/workflow/dist-DhncQSl7.js +0 -74
  142. package/dist/src/compiled/_chunks/workflow/frames-DsEqSDes.js +0 -3
  143. package/dist/src/compiled/_chunks/workflow/resume-hook-BRDLAb67.js +0 -1
  144. package/dist/src/compiled/_chunks/workflow/run-BM2OFphk.js +0 -1
  145. package/dist/src/compiled/_chunks/workflow/sleep-6cG0F99-.js +0 -1
  146. package/dist/src/compiled/_chunks/workflow/ws-transport-DuK82LLz.js +0 -1
@@ -1 +0,0 @@
1
- import{O as e,c as t,ct as n,i as r,lt as i,o as a,st as o,zl as s}from"./dist-DDeH-1ER.js";import{$ as c,C as l,D as u,F as d,G as f,Gn as ee,H as p,I as m,M as te,Mn as ne,Nn as re,Q as h,R as g,U as _,Wr as v,cr as y,dr as ie,fr as ae,gt as b,hr as oe,ir as se,jr as ce,l as le,lr as x,mr as S,mt as ue,n as de,pr as fe,qn as pe,r as C,rr as me,s as w,t as he,tr as T,tt as E,w as ge,xn as _e,yt as ve}from"./attribute-changes-C6H-fRVP.js";import{A as D,D as O,E as k,O as A,S as j,T as M,d as N,g as P,h as F,j as I,k as L,l as R,p as z,r as B,s as V,t as H,v as ye,w as be}from"./dist-xTushGCp.js";const xe=new Set([`PARSE_ERROR`,`SCHEMA_VALIDATION`,I.WORLD_CONTRACT_ERROR]),Se=new Set([`TRANSPORT`,`TIMEOUT`,I.STREAM_ERROR]),U=[L.is,F.is,be.is,z.is];function W(e){if(!D.is(e)||e.status!==void 0)return!1;let t=`cause`in e?e.cause:void 0;return e.code!==void 0&&xe.has(e.code)||e.message.startsWith(`Failed to parse response body for `)||e.message.startsWith(`Schema validation failed for `)||typeof t==`object`&&!!t&&`name`in t&&t.name===`ZodError`}function G(e){return ye.is(e)?!0:P.is(e)?e.status===void 0||e.status>=500:D.is(e)?e.status!==void 0&&e.status>=500||e.code!==void 0&&Se.has(e.code):!1}function Ce(e){if(R.is(e))return I.REPLAY_DIVERGENCE;if(H.is(e))return I.CORRUPTED_EVENT_LOG;if(V.is(e))return I.MAX_EVENTS_EXCEEDED;if(j.is(e))return I.DEPLOYMENT_MISMATCH;if(P.is(e))return I.STREAM_ERROR;if(W(e)||G(e))return I.WORLD_CONTRACT_ERROR;for(let t of U)if(t(e))return I.RUNTIME_ERROR;return I.USER_ERROR}const K=[`node`,`quickjs`];function q(e=process.env){let t=e.WORKFLOW_VM;if(t!==void 0&&t!==``){if(K.includes(t))return t;throw new L(`Invalid WORKFLOW_VM value: "${t}". Expected one of: ${K.join(`, `)}.`)}}function we(e){let t=e.executionContext?.workflowVm;if(t!==void 0){if(!K.includes(t))throw new L(`Invalid executionContext.workflowVm value: "${t}". Expected one of: ${K.join(`, `)}.`);return t===`quickjs`}return q()===`quickjs`}const Te=a();function Ee(){let e=c.getStore(),t=e?.workflowMetadata?.workflowRunId;if(t)return{[i]:e.rootRunId??t,[o]:t}}const J=s(`@workflow/core//latestNoOpWarning`,1,()=>({warned:!1}));async function Y(e,i,a){"use step";return await C(()=>{let o=e?.workflowId;if(!o)throw new L(`'start' received an invalid workflow function. Ensure the Workflow SDK is configured correctly and the function includes a 'use workflow' directive.`,{slug:`start-invalid-workflow-function`});let s=`workflow.start ${v(o)}`;return b(s,async e=>{e?.setAttributes({...ne(o),...re(`start`)});let s=[],c=a??{};Array.isArray(i)?s=i:typeof i==`object`&&(c=i),e?.setAttributes({..._e(s.length)});let u=c.world??await S();oe(u);let d=await u.getDeploymentId(),f=c.deploymentId??d;f===`latest`&&(u.resolveLatestDeploymentId?f=await u.resolveLatestDeploymentId():(J.warned||(J.warned=!0,E.warn(`deploymentId: 'latest' has no effect in this world and was ignored. It is only supported by worlds with atomic deployments, such as Vercel. The run will target the current deployment.`,{currentDeploymentId:d})),f=d));let p=`wrun_${u.createRunId?u.createRunId(c):Te()}`,m,h,g,_;if(f===d)m=!0,h=!0,g=1;else if(typeof u.streams?.get!=`function`)m=!1,h=!1,g=void 0;else{let e=await le(u,{deploymentId:f,runId:p,timeout:2e3,namespace:c.namespace}).catch(()=>void 0);_=e?.encryptionPublicKey;let t=ge(e?.workflowCoreVersion);m=t.framedByteStreams,h=t.supportedFormats.has(se.GZIP),g=e?.hookResumeInputVersion}let v=[],y=await ue(),b=c.specVersion??u.specVersion,x=t(b),C=c.allowReservedAttributes===!0,T;if(c.attributes&&Object.keys(c.attributes).length>0){if(b<4)throw new L(`Initial workflow attributes require a World that supports spec version 4 or later.`);for(let[e,t]of Object.entries(c.attributes))if(typeof t!=`string`)throw new L(`Initial workflow attribute ${JSON.stringify(e)} must be a string value.`);let e=he(c.attributes,{allowReservedAttributes:C});T=Object.fromEntries(e.map(({key:e,value:t})=>[e,t]))}let D;if(c.experimental_retention!==void 0&&c.experimental_retention!=="default"){if(c.experimental_retention!==0)throw new L(`start({ experimental_retention }) must be 0 or 'default'; received ${JSON.stringify(c.experimental_retention)}.`);if(b<4)throw new L(`start({ experimental_retention }) requires a World that supports spec version 4 or later.`);D={[n]:`0`}}let O=b>=4?Ee():void 0,k=O||D?{...O,...T,...D}:T,A=k?{attributes:k,...C||O!=null||D!=null?{allowReservedAttributes:!0}:{}}:{};if(c.replayedFromRunId!==void 0&&!r.safeParse(c.replayedFromRunId).success)throw new L(`replayedFromRunId must be a run ID (wrun_<ulid>); received ${JSON.stringify(String(c.replayedFromRunId).slice(0,64))}.`);let j=ae(_),M,N;if(j)M=me(j),N=_;else{let e=await u.getEncryptionKeyForRun?.(p,{...c,deploymentId:f});M=e?await ce(e):void 0,N=e?ie((await fe(e)).publicKey):void 0}let P=await te(s,p,M,v,globalThis,x,m,h&&b>=5),F=u.getEnvironment?.(),I=q(),R={traceCarrier:y,workflowCoreVersion:l,features:{encryption:!!M},...g===void 0?{}:{hookResumeInputVersion:g},...I?{workflowVm:I}:{},...c.replayedFromRunId?{replayedFromRunId:c.replayedFromRunId}:{}},[z,V]=await Promise.allSettled([u.events.create(p,{eventType:`run_created`,specVersion:b,eventData:{deploymentId:f,workflowName:o,input:P,executionContext:R,...N?{encryptionPublicKey:N}:{},...A}},{v1Compat:x}),u.queue(w(o,c.namespace),{runId:p,traceCarrier:y,...b>=3?{runInput:{input:P,deploymentId:f,workflowName:o,specVersion:b,executionContext:R,...N?{encryptionPublicKey:N}:{},...F===void 0?{}:{environment:F},...A}}:{}},{deploymentId:f,specVersion:b,...c.region===void 0?{}:{region:c.region}})]);if(V.status===`rejected`)throw V.reason;let H=!1;if(z.status===`rejected`){let e=z.reason;if(!B.is(e)){if(G(e))H=!0,E.warn(`Run creation event failed, but the run was accepted via the queue. The run_created event will be re-tried async by the runtime.`,{workflowRunId:p,error:e.message});else throw e}}else{let e=z.value;if(!x&&e.run.runId!==p)throw new L(`Server returned different runId than requested: expected ${p}, got ${e.run.runId}`)}return de(Promise.all(v),e=>{E.warn(`Background flush of workflow argument streams failed`,{workflowRunId:p,error:e instanceof Error?e.message:String(e)})}),e?.setAttributes({...ee(p),...ve(f),...z.status===`fulfilled`?pe(z.value.run.status):{}}),new $(p,{resilientStart:H})})})}const De=e=>Array.isArray(e)?e:[e];async function Oe(e,t,n={}){try{let r=await e.runs.get(t,{resolveData:`all`}),i=await e.getEncryptionKeyForRun?.(r),a=i?await T(i):void 0,o=De(await p(r.input,t,a,globalThis)),s=n.specVersion??r.specVersion??1,c=n.deploymentId??r.deploymentId;return(await Y({workflowId:r.workflowName},o,{deploymentId:c,world:e,specVersion:s,replayedFromRunId:t,namespace:n.namespace})).runId}catch(e){throw Error(`Failed to recreate run from ${t}: ${e instanceof Error?e.message:String(e)}`,{cause:e})}}async function X(e,n,r){try{let i=(await e.runs.get(n,{resolveData:`none`})).specVersion??1,a=t(i),o={eventType:`run_cancelled`,specVersion:i,...r?.cancelReason===void 0?{}:{eventData:{cancelReason:r.cancelReason}}};await e.events.create(n,o,{v1Compat:a})}catch(e){throw Error(`Failed to cancel run ${n}: ${e instanceof Error?e.message:String(e)}`,{cause:e})}}async function ke(e,t,n){if(t.length===0)throw Error(`cancelRuns requires at least one run ID.`);if(t.length>500)throw Error(`cancelRuns accepts at most 500 run IDs (received ${t.length}).`);if(new Set(t).size!==t.length)throw Error(`cancelRuns requires unique run IDs (duplicates found).`);if(e.runs.cancelMany)return e.runs.cancelMany({runIds:t,...n?.cancelReason===void 0?{}:{cancelReason:n.cancelReason}});let r=Array(t.length),i=0,a=async()=>{for(;;){let a=i++;if(a>=t.length)return;let o=t[a];try{await X(e,o,n),r[a]={runId:o,outcome:`cancelled`}}catch{r[a]={runId:o,outcome:`failed`,code:`internal_error`,retryable:!0}}}},o=Math.min(20,t.length);await Promise.all(Array.from({length:o},()=>a()));let s={requested:t.length,cancelled:0,alreadyCancelled:0,notCancellable:0,notFound:0,failed:0};for(let e of r)switch(e.outcome){case`cancelled`:s.cancelled++;break;case`already_cancelled`:s.alreadyCancelled++;break;case`not_cancellable`:s.notCancellable++;break;case`not_found`:s.notFound++;break;case`failed`:s.failed++}return{summary:s,results:r}}async function Ae(e,t,n){try{let r=await e.runs.get(t,{resolveData:`none`});await e.queue(w(r.workflowName,n?.namespace),{runId:t},{deploymentId:r.deploymentId,specVersion:r.specVersion??1})}catch(e){throw Error(`Failed to re-enqueue run ${t}: ${e instanceof Error?e.message:String(e)}`,{cause:e})}}async function Z(e,n,r){try{let i=await e.runs.get(n,{resolveData:`none`}),a=t(i.specVersion),o=[],s=null;do{let t=await e.events.list({runId:n,pagination:{sortOrder:`asc`,...s?{cursor:s}:{}},resolveData:`none`});o.push(...t.data),s=t.hasMore?t.cursor:null}while(s);let c=o.filter(e=>e.eventType===`wait_created`),l=new Set(o.filter(e=>e.eventType===`wait_completed`).map(e=>e.correlationId)),u=c.filter(e=>!l.has(e.correlationId));if(r?.correlationIds&&r.correlationIds.length>0){let e=new Set(r.correlationIds);u=u.filter(t=>t.correlationId&&e.has(t.correlationId))}let d=[],f=0;for(let t of u){if(!t.correlationId)continue;let r=a?{eventType:`wait_completed`,correlationId:t.correlationId}:{eventType:`wait_completed`,correlationId:t.correlationId,specVersion:i.specVersion,eventData:{resumeAt:t.eventData.resumeAt}};try{await e.events.create(n,r,{v1Compat:a}),f++}catch(e){B.is(e)?f++:d.push(e instanceof Error?e:Error(String(e)))}}if(f>0&&await e.queue(w(i.workflowName,r?.namespace),{runId:n},{deploymentId:i.deploymentId,specVersion:i.specVersion??1}),d.length>0)throw AggregateError(d,`Failed to complete ${d.length}/${u.length} pending wait(s) for run ${n}`);return{stoppedCount:f}}catch(e){throw e instanceof AggregateError?e:Error(`Failed to wake up run ${n}: ${e instanceof Error?e.message:String(e)}`,{cause:e})}}async function je(e,t,n,r){try{return await e.streams.get(t,n,r?.startIndex)}catch(e){throw P.is(e)?e:new P(`Failed to read stream ${n}: ${e instanceof Error?e.message:String(e)}`,{cause:e})}}async function Me(e,t){try{return await e.streams.list(t)}catch(e){throw P.is(e)?e:new P(`Failed to list streams for run ${t}: ${e instanceof Error?e.message:String(e)}`,{cause:e})}}const Ne=new Set([`completed`,`failed`]),Q=[1e3,3e3,6e3];function Pe(){return e(`WORKFLOW_RETURN_VALUE_POLL_INTERVAL_MS`,1e3,{integer:!0,min:1})}function Fe(){return e(`WORKFLOW_RETURN_VALUE_WAIT_MS`,5e4,{integer:!0,min:1})}function Ie(){return e(`WORKFLOW_RETURN_VALUE_MAX_LONG_POLLS`,10,{integer:!0,min:1})}function Le(){let e=process.env.WORKFLOW_RETURN_VALUE_LONG_POLL;return e===void 0||e===``||e!==`0`&&e.toLowerCase()!==`false`}var $=class e{static[x](e){return{runId:e.runId,resilientStart:e.#r}}static[y](t){return new e(t.runId,{resilientStart:t.resilientStart})}runId;#e;get#t(){return this.#e||=S(),this.#e}#n=null;#r=!1;constructor(e,t){this.runId=e,this.#r=t?.resilientStart??!1}#i(e){return this.#n||=(async()=>{let t=await this.#t,n=e??await t.runs.get(this.runId),r=await t.getEncryptionKeyForRun?.(n);return r?await T(r):void 0})(),this.#n}#a(){return()=>this.#i()}async wakeUp(e){"use step";return Z(await this.#t,this.runId,e)}async cancel(e){"use step";await(await this.#t).events.create(this.runId,{eventType:`run_cancelled`,specVersion:7,...e?.cancelReason===void 0?{}:{eventData:{cancelReason:e.cancelReason}}})}get exists(){"use step";return this.#t.then(e=>e.runs.get(this.runId,{resolveData:`none`}).then(()=>!0).catch(e=>{if(A.is(e))return!1;throw e}))}get status(){"use step";return this.#t.then(e=>e.runs.get(this.runId,{resolveData:`none`}).then(e=>e.status))}get returnValue(){"use step";return this.#c()}get workflowName(){"use step";return this.#t.then(e=>e.runs.get(this.runId).then(e=>e.workflowName))}get createdAt(){"use step";return this.#t.then(e=>e.runs.get(this.runId).then(e=>e.createdAt))}get startedAt(){"use step";return this.#t.then(e=>e.runs.get(this.runId).then(e=>e.startedAt))}get completedAt(){"use step";return this.#t.then(e=>e.runs.get(this.runId).then(e=>e.completedAt))}get readable(){return this.getReadable()}getReadable(e={}){"use step";let{ops:t=[],global:n=globalThis,startIndex:r,namespace:i}=e,a=h(this.runId,i),o=this.#a(),s=m(n,t,this.runId,a,r,o),c=this.#t,l=this.runId;return Object.assign(s,{getTailIndex:async()=>(await(await c).streams.getInfo(l,a)).tailIndex})}get writable(){return this.getWritable()}getWritable(e={}){"use step";let{ops:t=[],global:n=globalThis,namespace:r}=e,i=h(this.runId,r),a,o,s=()=>(a??=this.#o().then(async e=>{let t={key:await d(this.runId,e.deploymentId,e.encryptionPublicKey),deploymentId:e.deploymentId,encryptionPublicKey:e.encryptionPublicKey};return f(o,t),t}),a);return o=u({global:n,ops:t,runId:this.runId,name:i,key:()=>s().then(({key:e})=>e)}),o}async#o(){let e=await this.#t,t=this.#r?Q.length:0,n=0;for(;;)try{return await e.runs.get(this.runId,{resolveData:`none`})}catch(e){if(!A.is(e)||n>=t)throw e;let r=Q[n];n++,await new Promise(e=>setTimeout(e,r))}}async#s(e){let t=e.expiredAt;if(t!=null&&t<=new Date)throw new N(`Run "${this.runId}" ${e.status===`completed`?`completed`:`is ${e.status}`}, but its data expired at ${t.toISOString()} and is no longer readable.`,this.runId,e.status,t);if(e.status===`completed`){let t=await this.#i(e);return await _(e.output,this.runId,t)}if(e.status===`cancelled`)throw new M(this.runId);if(e.status===`failed`){let t=await this.#i(e),n;try{n=await g(e.error,this.runId,t)}catch{n=Error(`Failed to hydrate workflow run error`)}throw new k(this.runId,n,{errorCode:e.errorCode})}throw new O(this.runId,e.status)}async#c(){let e=await this.#t,t=0,n=this.#r?Q.length:0,r=Le()?e.runs.waitForTerminalStatus?.bind(e.runs):void 0,i=0,a=Ie();for(;;){let o=Date.now();try{let t=r&&i<a;t&&i++;let n=t?await r(this.runId,{timeoutMs:Fe(),resolveData:`none`}):await e.runs.get(this.runId,{resolveData:`none`});if(n.status===`cancelled`)throw new M(this.runId);if(Ne.has(n.status)){let t=await e.runs.get(this.runId,{resolveData:`all`});return await this.#s(t)}throw new O(this.runId,n.status)}catch(e){if(O.is(e)){let e=Pe()-(Date.now()-o);e>0&&await new Promise(t=>setTimeout(t,e));continue}if(A.is(e)&&t<n){let e=Q[t];t++,await new Promise(t=>setTimeout(t,e));continue}throw e}}}};function Re(e){return new $(e)}export{Me as a,Ae as c,we as d,Ce as f,ke as i,Z as l,W as m,Re as n,je as o,G as p,X as r,Oe as s,$ as t,Y as u};
@@ -1 +0,0 @@
1
- import{Pr as e,kr as t}from"./attribute-changes-C6H-fRVP.js";async function n(r){let i=globalThis[t];return i||e(`sleep()`,`https://workflow-sdk.dev/docs/api-reference/workflow/sleep`,n),i(r)}export{n as t};
@@ -1 +0,0 @@
1
- import{t as e}from"./debug-log-CVPstO1D.js";import{zl as t}from"./dist-DDeH-1ER.js";import{B as n,C as r,F as i,Q as a,T as o,W as s,_ as c,a as l,l as u,m as d,r as f,tt as p,u as m,w as h}from"./frames-DsEqSDes.js";import{n as g,t as _}from"./wrapper-BxECO5nh.js";var v=p();g();var y=class extends Error{constructor(e,t){super(e,{cause:t?.cause}),this.name=`WsTransportError`}};function b(e){for(let[t,n]of Object.entries(e))if(t.toLowerCase()===`authorization`)return n;return null}async function x(e){let t=(async function*(){yield e})();for await(let e of f(t))return e;throw Error(`ws-transport: received an empty/unframed message`)}function S(e){if(e.byteLength===0)return`(no message)`;let t=new TextDecoder().decode(e);try{let e=JSON.parse(t);return typeof e.message==`string`?e.message:t}catch{return t}}function C(e){return e instanceof Error?e.message:String(e)}var w=class{wsUrl;getHeaders;connection=null;connecting=null;reconnectAttempts=0;reconnectTimer=null;openCount=0;closed=!1;lastDrainReason=null;needsFreshToken=!1;lastAuthorization=null;constructor(e,t){this.wsUrl=e,this.getHeaders=t}async request(e){if(this.closed)throw new y(`workflow-server events WS channel for ${this.wsUrl} is closed`);let t=await this.ensureConnected(),n=t.nextReqId++,r=e(n),i=d(),a;try{return await new Promise((e,o)=>{t.pending.set(n,{resolve:e,reject:o}),a=setTimeout(()=>{t.pending.delete(n)&&(o(new y(`workflow-server events WS request ${n} to ${this.wsUrl} timed out after ${i}ms with no reply`)),this.failConnection(t,`workflow-server events WS connection to ${this.wsUrl} abandoned after request ${n} timed out`))},i),a.unref?.(),t.ws.send(r,e=>{e&&t.pending.delete(n)&&o(new y(`workflow-server events WS send failed: ${C(e)}`,{cause:e}))})})}finally{a!==void 0&&clearTimeout(a)}}open(){this.closed||(this.openCount++,this.connection===null&&this.connecting===null&&this.ensureConnected().catch(()=>{this.close(`connect failed`)}))}release(e){this.openCount!==0&&(this.openCount--,this.openCount===0&&this.close(e))}close(e){if(this.closed)return;this.closed=!0,this.openCount=0,this.reconnectTimer!==null&&(clearTimeout(this.reconnectTimer),this.reconnectTimer=null),T.transports.get(this.wsUrl)===this&&T.transports.delete(this.wsUrl);let t=this.connection;this.connection=null,t?.ws.close(1e3,e)}ensureConnected(){let e=this.connection;return e&&e.ws.readyState===_.default.OPEN?Promise.resolve(e):(this.connecting??=this.connectWithSpan().finally(()=>{this.connecting=null}),this.connecting)}async resolveUpgradeHeaders(){let e=this.needsFreshToken,t=await this.getHeaders({forceRefresh:e}),n=b(t);if(e&&n===this.lastAuthorization)throw new y(`workflow-server events WS connection to ${this.wsUrl} drained for auth expiry, but re-resolving the bearer produced the same token. Not reconnecting with a token the server has already rejected; the next event write will retry.`);this.lastAuthorization=n,this.needsFreshToken=!1;let r=new Headers;return await s(r),r.forEach((e,n)=>{t[n]=e}),t}consumeDrainReason(){let e=this.lastDrainReason;this.lastDrainReason=null,e===`auth_expiry`&&(this.needsFreshToken=!0)}connectWithSpan(){return r({method:`GET`,url:this.wsUrl,spanName:`workflow.events.ws.connect`,attributes:{...i(`ws`),...o(`websocket`),...n(this.reconnectAttempts)}},async e=>{try{return await this.connect()}catch(t){throw e?.setAttributes({...h(`TRANSPORT`)}),t instanceof Error&&e?.recordException?.(t),t}})}connect(){return new Promise((e,t)=>{(async()=>{let n;try{let e=await this.resolveUpgradeHeaders(),t=new _.default(this.wsUrl,{headers:e});t.binaryType=`nodebuffer`,n={ws:t,nextReqId:1,pending:new Map}}catch(e){console.error(`world-vercel: ws events transport could not open a connection to ${this.wsUrl}: ${C(e)}`),t(e instanceof y?e:new y(`workflow-server events WS connection to ${this.wsUrl} could not be opened: ${C(e)}`,{cause:e}));return}let{ws:r}=n,i=!1;r.on(`open`,()=>{if(i=!0,this.closed){r.close(1e3,`released while connecting`),t(new y(`workflow-server events WS connection to ${this.wsUrl} was released while connecting`));return}this.connection=n,this.reconnectAttempts=0,e(n)}),r.on(`message`,e=>{this.handleMessage(n,new Uint8Array(e))}),r.on(`error`,e=>{if(console.error(`world-vercel: ws events transport socket error (${this.wsUrl}): ${C(e)}`),!i){t(e);return}r.close()}),r.on(`close`,e=>{this.connection===n&&(this.connection=null),this.consumeDrainReason(),i||t(new y(`workflow-server events WS connection to ${this.wsUrl} closed before opening (code ${e})`)),this.failAllPending(n,new y(`workflow-server events WS connection closed (code ${e})`)),(i||this.reconnectAttempts>0)&&this.scheduleReconnect(e)})})()})}scheduleReconnect(e){if(this.closed||this.connection!==null||this.reconnectTimer!==null)return;if(this.reconnectAttempts>=5){console.error(`world-vercel: ws events transport giving up eager reconnect to ${this.wsUrl} after 5 attempts (last close code ${e}); the next event write will retry.`);return}let t=Math.min(100*2**this.reconnectAttempts,5e3);this.reconnectAttempts++;let n=setTimeout(()=>{this.reconnectTimer=null,this.ensureConnected().catch(()=>{})},t);n.unref?.(),this.reconnectTimer=n}async handleMessage(t,n){let r;try{r=await x(n)}catch(e){let r=`could not decode a ${n.byteLength}-byte reply frame from ${this.wsUrl}: ${C(e)}`;console.error(`world-vercel: ws events transport ${r}`),this.failConnection(t,`workflow-server events WS transport ${r}`);return}if(r.meta.type===`drain`){let t=r.meta.reason===`auth_expiry`?`auth_expiry`:`max_duration`;this.lastDrainReason=t,e(`world-vercel: ws events transport received a drain notice (reason: ${t}, graceMs: ${r.meta.graceMs??`unspecified`}); connection will close soon.`);return}let i=r.meta.reqId;if(i===-1){let e=`received a malformed-frame error from ${this.wsUrl} (reserved reqId -1, status ${String(r.meta.status??`unknown`)}): ${S(r.body)}. The server could not parse a frame this client sent, so the originating write cannot be identified`;console.error(`world-vercel: ws events transport ${e}.`),this.failConnection(t,`workflow-server events WS transport ${e}`);return}if(typeof i!=`number`){let e=`received a reply frame with no numeric reqId from ${this.wsUrl} (type: ${String(r.meta.type??`absent`)})`;console.error(`world-vercel: ws events transport ${e}.`),this.failConnection(t,`workflow-server events WS transport ${e}`);return}let a=t.pending.get(i);if(!a){console.error(`world-vercel: ws events transport received a reply for unknown reqId ${i} from ${this.wsUrl} (already settled, or the request was failed by a send error or its deadline); dropping it.`);return}t.pending.delete(i),a.resolve({meta:r.meta,body:r.body})}failAllPending(e,t){for(let n of e.pending.values())n.reject(t);e.pending.clear()}failConnection(e,t){this.failAllPending(e,new y(t)),this.connection===e&&(this.connection=null),e.ws.close()}};const T=t(`@workflow/world-vercel//wsEventsTransports@${a}`,1,()=>({transports:new Map,loggedWsProxyFallback:!1,loggedWsInUse:!1}));function E(e,t){let n=T.transports.get(e);return n||(n=new w(e,t),T.transports.set(e,n)),n}function D(e,t){let n=new URL(e);return n.protocol=n.protocol===`https:`?`wss:`:`ws:`,n.pathname=`${n.pathname.replace(/\/$/,``)}/websockets/v1/runs/${encodeURIComponent(t)}`,n.toString()}function O(t,n){if(!l())return;let r=A(t,n);if(!r)return;T.loggedWsInUse||(T.loggedWsInUse=!0,e(`world-vercel: using ws events transport (${r}).`));let i=E(r,async({forceRefresh:e})=>{e&&await k();let{headers:t}=await u(n);return c(t)});i.open();let a=!1;return()=>{a||(a=!0,i.release(`invocation complete`))}}async function k(){try{await(0,v.getVercelOidcToken)({expirationBufferMs:864e5})}catch{}}function A(t,n){let{baseUrl:r,usingProxy:i}=m(n);return i?(T.loggedWsProxyFallback||(T.loggedWsProxyFallback=!0,e(`world-vercel: ws events transport unavailable for a World with projectConfig (api-workflow proxy, resolved baseUrl: ${r}) — falling back to HTTP.`)),null):D(r,t)}function j(e,t){let n=A(e,t);if(!n)return null;let r=T.transports.get(n);return r?{transport:r,wsUrl:n}:null}export{O as openWsChannel,j as resolveWsTransport};