import{c as e,i as t}from"../../_chunks/workflow/dist-6a3viBXZ.js";import{at as n,c as r,it as i,l as a,ot as o,s}from"../../_chunks/workflow/symbols-BUTtwS7j.js";import{Bt as c,C as l,Ht as u,R as d,T as f,Vt as p,g as m,n as h,z as g,zt as _}from"../../_chunks/workflow/resume-hook-CEAS3opc.js";import{n as v,t as y}from"../../_chunks/workflow/sleep-Cup6vPoA.js";function b(e){n(`createHook()`,`https://workflow-sdk.dev/docs/api-reference/workflow/create-hook`,b)}function x(e){n(`createWebhook()`,`https://workflow-sdk.dev/docs/api-reference/workflow/create-webhook`,x)}function S({schema:e}={}){function t(e){n(`defineHook().create()`,`https://workflow-sdk.dev/docs/api-reference/workflow/define-hook`,t)}return{create:t,async resume(t,n){if(!e?.[`~standard`])return await h(t,n);let r=e[`~standard`].validate(n);if(r instanceof Promise&&(r=await r),r.issues){let e=r.issues.map(e=>{let t=e.path?.map(e=>String(typeof e==`object`&&e?e.key:e)).join(`.`);return t?`  at "${t}": ${e.message}`:`  ${e.message}`});throw Error(`Hook payload did not match the defined schema:\n${e.join(`
`)}`)}return await h(t,r.value)}}}const C=Symbol.for(`@workflow/setAttributes//unsupportedWorldWarned`);async function w(e,n={}){let r=g.getStore()?.workflowMetadata?.workflowRunId;if(!r)throw new t(`experimental_setAttributes() must be called from a 'use workflow' or 'use step' function. Calling it from plain host code is not supported.`);let i=v(e,n);if(i.length===0)return;let a=await _();if(typeof a.runs.experimentalSetAttributes!=`function`){let e=globalThis;if(!e[C]){e[C]=!0;let t=`name`in a&&typeof a.name==`string`?a.name:``,n=t?` (${t})`:``;console.warn(`[workflow] setAttributes: the current world implementation${n} does not implement experimentalSetAttributes; this call (and any subsequent setAttributes calls in this process) is a no-op. Attributes will become available once the world adapter adds support.`)}return}await a.runs.experimentalSetAttributes(r,i,n.allowReservedAttributes===!0?{allowReservedAttributes:!0}:{})}function T(){let e=g.getStore();return e||i(`getStepMetadata()`,`https://workflow-sdk.dev/docs/api-reference/workflow/get-step-metadata`,T),e.stepMetadata}function E(){let e=g.getStore();return e||o(`getWorkflowMetadata()`,`https://workflow-sdk.dev/docs/api-reference/workflow/get-workflow-metadata`,E),e.workflowMetadata}function D(e={}){let t=g.getStore();t||o(`getWritable()`,`https://workflow-sdk.dev/docs/api-reference/workflow/get-writable`,D);let{namespace:n}=e,i=t.workflowMetadata.workflowRunId,h=d(i,n),_=t.writables??=new Map,v=_.get(h);if(v)return v.writable;let y=f(l(globalThis,t.ops,i,t.encryptionKey),t.encryptionKey),b=new m(i,h),x=c();return t.ops.push(x.promise),p(y.readable,b,x).catch(()=>{}),u(y.writable,x),Object.defineProperty(y.writable,s,{value:h,writable:!1}),Object.defineProperty(y.writable,a,{value:i,writable:!1}),t.workflowDeploymentId&&Object.defineProperty(y.writable,r,{value:t.workflowDeploymentId,writable:!1}),_.set(h,{writable:y.writable,state:x}),y.writable}export{t as FatalError,e as RetryableError,b as createHook,x as createWebhook,S as defineHook,w as experimental_setAttributes,T as getStepMetadata,E as getWorkflowMetadata,D as getWritable,y as sleep};