@ablehi/server-execution-contract 0.1.2 → 0.1.3
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/edge.js +1 -1
- package/dist/index.d.ts +8 -2
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/dist/edge.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var ee="0.2.8";function u(e){return{ok:!0,value:e}}function r(e){return{ok:!1,reason:e}}function i(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}var qe="/cleanup-state-scopes";function y(e){if(!i(e)||typeof e.kind!="string")return r("context state scope surface shape is invalid");switch(e.kind){case"webhook-trigger":return te(e);case"polling-trigger":return ne(e);case"flow-action":return re(e);default:return r("context state scope kind is invalid")}}function We(e){if(!i(e))return r("cleanup request body must be a JSON object");let t=b(e,["scopes"]);if(t!==void 0)return r(`cleanup request does not accept the "${t}" field`);if(!Array.isArray(e.scopes))return r("cleanup request scopes must be an array");let n=[];for(let o of e.scopes){let s=y(o);if(!s.ok)return s;n.push(s.value)}return u({scopes:n})}function je(e){return!i(e)||typeof e.deleted!="number"||!Number.isSafeInteger(e.deleted)||e.deleted<0?r("cleanup response data surface shape is invalid"):u({deleted:e.deleted})}function te(e){let t=b(e,["kind","workspaceId","triggerInstanceId"]);return t!==void 0?r(`webhook trigger scope does not accept "${t}"`):e.kind!=="webhook-trigger"||!R(e.workspaceId)||!R(e.triggerInstanceId)?r("webhook trigger state scope is invalid"):u({kind:"webhook-trigger",workspaceId:e.workspaceId,triggerInstanceId:e.triggerInstanceId})}function ne(e){let t=b(e,["kind","workspaceId","pollingInstanceId"]);return t!==void 0?r(`polling trigger scope does not accept "${t}"`):e.kind!=="polling-trigger"||!R(e.workspaceId)||!R(e.pollingInstanceId)?r("polling trigger state scope is invalid"):u({kind:"polling-trigger",workspaceId:e.workspaceId,pollingInstanceId:e.pollingInstanceId})}function re(e){let t=b(e,["kind","workspaceId","flowId","nodeId","connectionId"]);if(t!==void 0)return r(`flow action scope does not accept "${t}"`);let n=e.connectionId;return e.kind!=="flow-action"||!R(e.workspaceId)||!R(e.flowId)||!R(e.nodeId)||n!==null&&!R(n)?r("flow action state scope is invalid"):u({kind:"flow-action",workspaceId:e.workspaceId,flowId:e.flowId,nodeId:e.nodeId,connectionId:n})}function R(e){return typeof e=="string"&&e.length>0}function b(e,t){return Object.keys(e).find(n=>!t.includes(n))}var f="/internal/flow-runs",Ye="/:flowRunId/execution-context";function ze(e){return`${f}/${encodeURIComponent(e)}/execution-context`}function oe(e){return!i(e)||!B(e.fileMaxBytes)||!B(e.fileReadMaxBytes)||!B(e.inlineMultipartBytesMax)?r("file runtime limits must carry three positive integer bounds"):u({fileMaxBytes:e.fileMaxBytes,fileReadMaxBytes:e.fileReadMaxBytes,inlineMultipartBytesMax:e.inlineMultipartBytesMax})}function Qe(e){if(!i(e))return r("execution context must be a JSON object");let t=e.compiled;if(typeof e.flowRunId!="string"||typeof e.workspaceId!="string"||!i(e.input)||!i(t)||typeof t.irSchemaVersion!="string"||typeof t.interpreterContractVersion!="string"||typeof t.compiledArtifactId!="string"||!i(t.ir)||!Array.isArray(t.ir.nodes)||!se(e.executionBindings))return r("execution context surface shape is invalid");let n=ie(e.fileRuntime);return n.ok?u({...e,fileRuntime:n.value}):r(n.reason)}function ie(e){if(e===null)return u(null);if(!i(e))return r("fileRuntime must be null or an object");let t=oe(e.limits);return t.ok?u({limits:t.value}):r(t.reason)}function se(e){return Array.isArray(e)?e.every(t=>{if(!i(t))return!1;let n=t.connection,o=y(t.stateScope);return typeof t.nodeId=="string"&&typeof t.toolRef=="string"&&i(t.toolDescriptor)&&i(t.integrationDescriptor)&&i(n)&&typeof n.installationId=="string"&&typeof n.connectionRef=="string"&&typeof n.connectionId=="string"&&typeof n.authProfileRef=="string"&&typeof n.authType=="string"&&o.ok}):!1}function B(e){return typeof e=="number"&&Number.isSafeInteger(e)&&e>0}import{parseAblehiErrorDigest as L}from"@ablehi/error-contract";var rt="/:flowRunId/steps/:nodeId/result",ot="/:flowRunId/result",it="/:flowRunId/event-waits/:nodeId";function st(e,t){return`${f}/${encodeURIComponent(e)}/steps/${encodeURIComponent(t)}/result`}function ut(e){return`${f}/${encodeURIComponent(e)}/result`}function at(e,t){return`${f}/${encodeURIComponent(e)}/event-waits/${encodeURIComponent(t)}`}function ct(e){if(!i(e))return{ok:!1,kind:"validation",reason:"step record body must be a JSON object"};let t=k(e,["attempt","result","durationMs"]);if(t!==void 0)return{ok:!1,kind:"validation",reason:`step record does not accept the "${t}" field`};let n=e.attempt;if(typeof n!="number"||!Number.isInteger(n)||n<=0)return{ok:!1,kind:"validation",reason:"attempt must be a positive integer"};let o=ue(e.result);if(!o.ok)return o;let s={attempt:n,result:o.value};if(e.durationMs!==void 0){let a=e.durationMs;if(typeof a!="number"||!Number.isFinite(a)||a<0)return{ok:!1,kind:"validation",reason:"durationMs must be a non-negative number"};s.durationMs=a}return{ok:!0,value:s}}function ue(e){if(!i(e))return{ok:!1,kind:"step_result_invalid",reason:"result must be a JSON object"};let t=e.status;if(t==="succeeded"){let n=k(e,["status","output"]);return n!==void 0?{ok:!1,kind:"validation",reason:`step record result does not accept the "${n}" field`}:"output"in e?{ok:!0,value:{status:"succeeded",output:e.output}}:{ok:!1,kind:"step_result_invalid",reason:"a succeeded result must carry output"}}if(t==="failed"){let n=k(e,["status","error"]);if(n!==void 0)return{ok:!1,kind:"validation",reason:`step record result does not accept the "${n}" field`};let o=L(e.error);return o.ok?{ok:!0,value:{status:"failed",error:o.value}}:{ok:!1,kind:"step_result_invalid",reason:`a failed result must carry an AblehiErrorDigest: ${o.reason}`}}return{ok:!1,kind:"step_result_invalid",reason:'result status must be "succeeded" or "failed"'}}function dt(e){return!i(e)||typeof e.flowRunId!="string"||typeof e.nodeId!="string"||e.recorded!=="succeeded"&&e.recorded!=="failed"?r("step record data surface shape is invalid"):u({flowRunId:e.flowRunId,nodeId:e.nodeId,recorded:e.recorded})}function lt(e){if(!i(e))return r("result body must be a JSON object");let t=k(e,["status","output","error","composition"]);if(t!==void 0)return r(`result does not accept the "${t}" field`);let n=e.status;if(n!=="succeeded"&&n!=="failed")return r('result status must be "succeeded" or "failed"');let o={status:n};if(e.output!==void 0){if(n!=="succeeded")return r("output is only allowed on a succeeded result");o.output=e.output}if(e.error!==void 0){if(n!=="failed")return r("error is only allowed on a failed result");let s=L(e.error);if(!s.ok)return r(`result error must be an AblehiErrorDigest: ${s.reason}`);o.error=s.value}if(n==="failed"&&o.error===void 0)return r("a failed result must carry an AblehiErrorDigest");if(e.composition!==void 0){if(n!=="succeeded")return r("composition is only allowed on a succeeded result");o.composition=e.composition}return u(o)}function pt(e){return i(e)?u(e):r("flow run result data must be a JSON object")}var ae=/^[A-Za-z0-9_-]{1,100}$/;function gt(e){if(!i(e))return r("register body must be a JSON object");let t=k(e,["eventType","correlationKey"]);if(t!==void 0)return r(`register wait does not accept the "${t}" field`);let n=q(e.eventType);if(!n.ok)return r(n.reason);let o=e.correlationKey;return typeof o!="string"||o.length===0?r("correlationKey must be a non-empty string"):u({eventType:n.value,correlationKey:o})}function ft(e){if(!i(e))return r("complete body must be a JSON object");let t=k(e,["eventType","correlationKey","outcome","eventId"]);if(t!==void 0)return r(`complete wait does not accept the "${t}" field`);let n=e.outcome;if(n!=="received"&&n!=="timed_out")return r('outcome must be "received" or "timed_out"');let o=q(e.eventType);if(!o.ok)return r(o.reason);let s=e.correlationKey;if(typeof s!="string"||s.length===0)return r("correlationKey must be a non-empty string");let a={eventType:o.value,correlationKey:s,outcome:n};if(e.eventId!==void 0){if(typeof e.eventId!="string"||e.eventId.length===0)return r("eventId must be a non-empty string");a.eventId=e.eventId}return u(a)}function Rt(e){return!i(e)||e.registered!==!0?r("register wait data surface shape is invalid"):u({registered:!0})}function q(e){return typeof e!="string"||e.length===0?r("eventType must be a non-empty string"):ae.test(e)?u(e):r("eventType must match ^[A-Za-z0-9_-]{1,100}$")}function k(e,t){return Object.keys(e).find(n=>!t.includes(n))}var ce="/internal/flow-versions",yt="/:flowVersionId/handler-bundles",F="/internal/installations",kt="/:installationId/handler-bundles";function It(e,t){return`${ce}/${encodeURIComponent(e)}/handler-bundles?compiledArtifactId=${encodeURIComponent(t)}`}function _t(e){return`${F}/${encodeURIComponent(e.installationId)}/handler-bundles?workspaceId=${encodeURIComponent(e.workspaceId)}&artifactDigest=${encodeURIComponent(e.artifactDigest)}`}var de=new Set(["managed_only","managed_plus_unmanaged_sdk"]);function C(e){if(!I(e))return H("runtimeNetwork must be a JSON object");let t=e.networkModel;return typeof t!="string"||!de.has(t)?H("runtimeNetwork.networkModel is unknown"):!W(e.apiHosts)||!W(e.authHosts)||typeof e.httpsOnly!="boolean"?H("runtimeNetwork host/https fields are invalid"):{ok:!0,value:{networkModel:t,apiHosts:e.apiHosts,authHosts:e.authHosts,httpsOnly:e.httpsOnly}}}function Et(e){if(!I(e)||typeof e.flowVersionId!="string"||typeof e.compiledArtifactId!="string"||!Array.isArray(e.bundles))return h("handler bundles data surface shape is invalid");let t=j(e.bundles);return t.ok?{ok:!0,value:{flowVersionId:e.flowVersionId,compiledArtifactId:e.compiledArtifactId,bundles:t.value}}:t}function ht(e){if(!I(e)||typeof e.installationId!="string"||typeof e.artifactDigest!="string"||!Array.isArray(e.bundles))return h("tool handler bundles data surface shape is invalid");let t=j(e.bundles);return t.ok?{ok:!0,value:{installationId:e.installationId,artifactDigest:e.artifactDigest,bundles:t.value}}:t}function j(e){let t=[];for(let n of e){let o=le(n);if(!o.ok)return o;t.push(o.value)}return{ok:!0,value:t}}function le(e){if(!I(e)||typeof e.toolRef!="string"||e.kind!=="handler"&&e.kind!=="request")return h("handler bundle entry shape is invalid");if(e.kind==="request"){if(e.module!==void 0)return h("a request bundle must not carry a module");let o=C(e.runtimeNetwork);return o.ok?{ok:!0,value:{toolRef:e.toolRef,kind:"request",runtimeNetwork:o.value}}:o}let t=e.module;if(!I(t)||typeof t.entry!="string"||t.entry.length===0||!pe(t.files))return h("a handler bundle must carry a { entry, files } module");let n=C(e.runtimeNetwork);return n.ok?{ok:!0,value:{toolRef:e.toolRef,kind:"handler",module:{entry:t.entry,files:t.files},runtimeNetwork:n.value}}:n}function h(e){return{ok:!1,kind:"shape",reason:e}}function H(e){return{ok:!1,kind:"runtime_network",reason:e}}function I(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function W(e){return Array.isArray(e)&&e.every(t=>typeof t=="string")}function pe(e){return I(e)&&Object.values(e).every(t=>typeof t=="string")}var x="/internal/webhook-trigger-instances",bt="/:triggerInstanceId/context",Ct="/:triggerInstanceId/handler-bundles",At="/:triggerInstanceId/deliveries/:deliveryId",vt="/:triggerInstanceId/events",Nt="/:triggerInstanceId/rearm",w=e=>`${x}/${encodeURIComponent(e)}`;function Ot(e,t){return`${w(e)}/context?artifactDigest=${encodeURIComponent(t)}`}function Dt(e,t){return`${w(e)}/handler-bundles?artifactDigest=${encodeURIComponent(t)}`}function Ut(e,t){return`${w(e)}/deliveries/${encodeURIComponent(t)}`}function Bt(e){return`${w(e)}/events`}function Ht(e){return`${w(e)}/rearm`}var Ft="/:installationId/webhook-protocol-adapter-bundle";function $t(e){return`${F}/${encodeURIComponent(e.installationId)}/webhook-protocol-adapter-bundle?workspaceId=${encodeURIComponent(e.workspaceId)}&artifactDigest=${encodeURIComponent(e.artifactDigest)}`}var Gt="modules/webhook/protocol-adapter.js";function Mt(e){return`modules/webhook/protocol-adapter-${e}.js`}function Kt(e){let t=i(e)?y(e.stateScope):r("webhook watcher context state scope is invalid");return!i(e)||typeof e.artifactDigest!="string"||typeof e.triggerRef!="string"||typeof e.triggerName!="string"||typeof e.integrationRef!="string"||!i(e.inputs)||e.connection!==null&&!ge(e.connection)||!fe(e.runtime)||!t.ok||t.value.kind!=="webhook-trigger"?r("webhook watcher context surface shape is invalid"):u(e)}function ge(e){return i(e)&&typeof e.connectionId=="string"&&typeof e.connectionRef=="string"&&typeof e.integrationRef=="string"&&typeof e.authProfileRef=="string"&&typeof e.authType=="string"}function fe(e){if(!i(e)||e.type!=="webhook"||typeof e.trigger_ref!="string")return!1;let t=e.webhook;return i(t)&&typeof t.event_handler_module=="string"&&typeof t.enable_handler_module=="string"&&typeof t.disable_handler_module=="string"}function Lt(e){if(!i(e)||typeof e.deliveryId!="string"||typeof e.receivedAt!="string"||!i(e.request))return r("webhook delivery surface shape is invalid");let t=e.request;return t.method!=="POST"||!i(t.headers)||typeof t.rawBody!="string"?r("webhook delivery request shape is invalid"):u(e)}function qt(e){if(!i(e)||typeof e.triggerRef!="string"||typeof e.artifactDigest!="string"||!Array.isArray(e.modules)||!e.modules.every(Re))return{ok:!1,kind:"shape",reason:"trigger handler bundles data surface shape is invalid"};let t=C(e.runtimeNetwork);return t.ok?{ok:!0,value:{triggerRef:e.triggerRef,artifactDigest:e.artifactDigest,modules:e.modules,runtimeNetwork:t.value}}:t}function Re(e){return i(e)&&typeof e.specifier=="string"&&e.specifier.length>0&&typeof e.source=="string"}function Wt(e){if(!i(e))return r("publish events body must be a JSON object");let t=$(e,["deliveryId","events"]);if(t!==void 0)return r(`publish events does not accept the "${t}" field`);let n=e.deliveryId;if(typeof n!="string"||n.length===0)return r("deliveryId must be a non-empty string");let o=e.events;if(!Array.isArray(o))return r("events must be an array");let s=[];for(let a of o){let c=me(a);if(!c.ok)return c;s.push(c.value)}return u({deliveryId:n,events:s})}function me(e){if(!i(e))return r("each event must be a JSON object");let t=$(e,["eventId","occurredAt","dedupeKey","payload"]);if(t!==void 0)return r(`event does not accept the "${t}" field`);let n=e.eventId;if(typeof n!="string"||n.length===0)return r("eventId must be a non-empty string");let o=e.occurredAt;if(typeof o!="string"||o.length===0)return r("occurredAt must be a non-empty string");if(!i(e.payload))return r("event payload must be a JSON object");let s={eventId:n,occurredAt:o,payload:e.payload};if(e.dedupeKey!==void 0){if(typeof e.dedupeKey!="string"||e.dedupeKey.length===0)return r("dedupeKey must be a non-empty string");s.dedupeKey=e.dedupeKey}return u(s)}function jt(e){if(!i(e))return r("rearm body must be a JSON object");let t=$(e,["expectedWatcherInstanceId"]);if(t!==void 0)return r(`rearm does not accept the "${t}" field`);let n=e.expectedWatcherInstanceId;return typeof n!="string"||n.length===0?r("expectedWatcherInstanceId must be a non-empty string"):u({expectedWatcherInstanceId:n})}function $(e,t){return Object.keys(e).find(n=>!t.includes(n))}var T="/internal/polling-trigger-instances",Yt="/:pollingInstanceId/context",zt="/:pollingInstanceId/handler-bundles",Qt="/:pollingInstanceId/ticks/:tickId/events",G=e=>`${T}/${encodeURIComponent(e)}`;function Zt(e,t,n){return`${G(e)}/context?artifactDigest=${encodeURIComponent(t)}&tickId=${encodeURIComponent(n)}`}function en(e,t){return`${G(e)}/handler-bundles?artifactDigest=${encodeURIComponent(t)}`}function tn(e,t){return`${G(e)}/ticks/${encodeURIComponent(t)}/events`}function nn(e){let t=i(e)?y(e.stateScope):r("polling trigger context state scope is invalid");return!i(e)||typeof e.artifactDigest!="string"||typeof e.triggerRef!="string"||typeof e.triggerName!="string"||typeof e.integrationRef!="string"||!i(e.inputs)||e.connection!==null&&!ye(e.connection)||!ke(e.runtime)||!t.ok||t.value.kind!=="polling-trigger"||!Ie(e.tick)||!_e(e.limits)?r("polling trigger context surface shape is invalid"):u(e)}function ye(e){return i(e)&&typeof e.connectionId=="string"&&typeof e.connectionRef=="string"&&typeof e.integrationRef=="string"&&typeof e.authProfileRef=="string"&&typeof e.authType=="string"}function ke(e){if(!i(e)||e.type!=="polling"||typeof e.trigger_id!="string"||typeof e.trigger_ref!="string")return!1;let t=e.polling;if(!i(t)||typeof t.run_handler_module!="string")return!1;let n=t.schedule;if(!i(n)||n.type!=="interval"||typeof n.every_seconds!="number")return!1;let o=t.dedup;return i(o)&&(o.strategy==="cursor"||o.strategy==="hash"||o.strategy==="id_field")}function Ie(e){return i(e)&&typeof e.tickId=="string"&&typeof e.scheduledAt=="string"&&typeof e.attempt=="number"}function _e(e){return i(e)&&typeof e.maxEventsPerTick=="number"}function rn(e){if(!i(e))return r("publish body must be a JSON object");let t=V(e,["events","nextCursor"]);if(t!==void 0)return r(`publish does not accept the "${t}" field`);let n=e.events;if(!Array.isArray(n))return r("events must be an array");let o=[];for(let a of n){let c=Ee(a);if(!c.ok)return c;o.push(c.value)}let s={events:o};if("nextCursor"in e){let a=e.nextCursor;if(a!==null&&typeof a!="string")return r("nextCursor must be a string, null, or omitted");s.nextCursor=a}return u(s)}function Ee(e){if(!i(e))return r("each event must be a JSON object");let t=V(e,["eventId","occurredAt","dedupeKey","payload"]);if(t!==void 0)return r(`event does not accept the "${t}" field`);if(typeof e.eventId!="string"||e.eventId.length===0)return r("event eventId must be a non-empty string");if(!i(e.payload))return r("event payload must be a JSON object");let n={eventId:e.eventId,payload:e.payload};if(e.occurredAt!==void 0){if(typeof e.occurredAt!="string"||e.occurredAt.length===0)return r("event occurredAt must be a non-empty string");n.occurredAt=e.occurredAt}if(e.dedupeKey!==void 0){if(typeof e.dedupeKey!="string"||e.dedupeKey.length===0)return r("event dedupeKey must be a non-empty string");n.dedupeKey=e.dedupeKey}return u(n)}function on(e){return!i(e)||typeof e.tickId!="string"||typeof e.cursorUpdated!="boolean"||!Array.isArray(e.results)||!e.results.every(he)?r("publish polling tick events data surface shape is invalid"):u(e)}function he(e){return i(e)&&typeof e.eventId=="string"&&typeof e.dedupeKey=="string"&&typeof e.duplicate=="boolean"&&(e.flowRunId===null||typeof e.flowRunId=="string")}function V(e,t){return Object.keys(e).find(n=>!t.includes(n))}var J="/internal/egress-grants",M="/internal/tool-invocations",ln="/:flowRunId/egress-grant",pn="/:invocationId/egress-grant",gn="/:pollingInstanceId/egress-grant",fn="/:triggerInstanceId/egress-grant",Rn="/:grantId/consume",mn="/:grantId/audit",yn=e=>`${f}/${encodeURIComponent(e)}/egress-grant`,kn=e=>`${M}/${encodeURIComponent(e)}/egress-grant`,In=e=>`${T}/${encodeURIComponent(e)}/egress-grant`,_n=e=>`${x}/${encodeURIComponent(e)}/egress-grant`,En=e=>`${J}/${encodeURIComponent(e)}/consume`,hn=e=>`${J}/${encodeURIComponent(e)}/audit`,xe=["flow_action","single_tool","polling_trigger","webhook_trigger"],we=/^[A-Za-z0-9][A-Za-z0-9:_+/=.-]{15,1023}$/;function P(e){return typeof e=="string"&&we.test(e)}function Te(e){if(!i(e)||e.body_type!=="multipart")return!1;let t=e.body;if(!i(t))return!1;let n=t.parts;return Array.isArray(n)?n.some(o=>i(o)?o.kind==="file"&&typeof o.file_id=="string"&&o.file_id.length>0:!1):!1}function d(e){return{ok:!1,kind:"shape",reason:e}}function S(){return{ok:!1,kind:"request_digest",reason:"request digest is missing or malformed"}}function v(e,t){if(!i(e))return{ok:!1,reason:"grant request body must be a JSON object"};for(let n of Object.keys(e))if(!t.includes(n))return{ok:!1,reason:`grant request does not accept the "${n}" field`};return{ok:!0,record:e}}function N(e){if(!i(e))return"request must be a JSON object"}function xn(e){let t=v(e,["nodeId","request","requestDigest"]);if(!t.ok)return d(t.reason);let n=t.record.nodeId;if(typeof n!="string"||n.length===0)return d("nodeId is required");let o=N(t.record.request);if(o!==void 0)return d(o);let s=t.record.requestDigest;return P(s)?{ok:!0,value:{nodeId:n,requestDigest:s,requestHasMultipartFiles:Te(t.record.request)}}:S()}function wn(e){let t=v(e,["request","requestDigest"]);if(!t.ok)return d(t.reason);let n=N(t.record.request);if(n!==void 0)return d(n);let o=t.record.requestDigest;return P(o)?{ok:!0,value:{requestDigest:o}}:S()}function Tn(e){let t=v(e,["tickId","request","requestDigest"]);if(!t.ok)return d(t.reason);let n=t.record.tickId;if(typeof n!="string"||n.length===0)return d("tickId is required");let o=N(t.record.request);if(o!==void 0)return d(o);let s=t.record.requestDigest;return P(s)?{ok:!0,value:{tickId:n,requestDigest:s}}:S()}function Pn(e){let t=v(e,["phase","lifecycle","request","requestDigest"]);if(!t.ok)return d(t.reason);let n=t.record.phase;if(n!=="lifecycle"&&n!=="handler")return d('phase must be "lifecycle" or "handler"');let o=t.record.lifecycle,s;if(o!==void 0){if(o!=="enable"&&o!=="disable"&&o!=="renew")return d('lifecycle must be "enable", "disable", or "renew"');s=o}if(n==="lifecycle"&&s===void 0)return d("lifecycle is required for the lifecycle phase");let a=N(t.record.request);if(a!==void 0)return d(a);let c=t.record.requestDigest;return P(c)?{ok:!0,value:{phase:n,...s!==void 0?{lifecycle:s}:{},requestDigest:c}}:S()}function X(e){return xe.includes(e)?e:void 0}var Pe=["scopeKind","scopeId","requestDigest"];function Sn(e){if(!i(e))return d("consume body must be a JSON object");for(let s of Object.keys(e))if(!Pe.includes(s))return d(`consume does not accept the "${s}" field`);let t=X(e.scopeKind);if(t===void 0)return d("scopeKind is invalid");let n=e.scopeId;if(typeof n!="string"||n.length===0)return d("scopeId is required");let o=e.requestDigest;return P(o)?{ok:!0,value:{scopeKind:t,scopeId:n,requestDigest:o}}:S()}var Se=["scopeKind","scopeId","providerHost","status","durationMs","requestBytes","responseBytes","errorCode"];function A(e,t){return typeof e!="number"||!Number.isInteger(e)||e<0?{ok:!1,reason:`${t} must be a non-negative integer`}:{ok:!0,value:e}}function bn(e){if(!i(e))return d("audit body must be a JSON object");for(let p of Object.keys(e))if(!Se.includes(p))return d(`audit does not accept the "${p}" field`);let t=X(e.scopeKind);if(t===void 0)return d("scopeKind is invalid");let n=e.scopeId;if(typeof n!="string"||n.length===0)return d("scopeId is required");let o=e.providerHost;if(typeof o!="string"||o.length===0)return d("providerHost is required");let s=A(e.durationMs,"durationMs");if(!s.ok)return d(s.reason);let a;if(e.status!==void 0){let p=A(e.status,"status");if(!p.ok)return d(p.reason);a=p.value}let c;if(e.requestBytes!==void 0){let p=A(e.requestBytes,"requestBytes");if(!p.ok)return d(p.reason);c=p.value}let l;if(e.responseBytes!==void 0){let p=A(e.responseBytes,"responseBytes");if(!p.ok)return d(p.reason);l=p.value}let U;if(e.errorCode!==void 0){let p=e.errorCode;if(typeof p!="string"||p.length===0)return d("errorCode must be a non-empty string");U=p}return{ok:!0,value:{scopeKind:t,scopeId:n,providerHost:o,...a!==void 0?{status:a}:{},durationMs:s.value,...c!==void 0?{requestBytes:c}:{},...l!==void 0?{responseBytes:l}:{},...U!==void 0?{errorCode:U}:{}}}}function Cn(e){return!i(e)||!i(e.grant)?r("egress grant envelope must carry a grant object"):u(e.grant)}function An(e){return!i(e)||e.consumed!==!0?r("egress grant consume data must carry consumed:true"):u({consumed:!0})}var Hn="/:flowRunId/runtime-credential",Fn="/:invocationId/runtime-credential",$n="/:pollingInstanceId/runtime-credential",Gn="/:triggerInstanceId/runtime-credential",Mn=e=>`${f}/${encodeURIComponent(e)}/runtime-credential`,Kn=e=>`${M}/${encodeURIComponent(e)}/runtime-credential`,Ln=e=>`${T}/${encodeURIComponent(e)}/runtime-credential`,qn=e=>`${x}/${encodeURIComponent(e)}/runtime-credential`,Wn=["flow_action","tool_invoke","polling_trigger","webhook_trigger"];function O(e,t){if(!i(e))return{ok:!1,reason:"runtime credential request body must be a JSON object"};for(let n of Object.keys(e))if(!t.includes(n))return{ok:!1,reason:`runtime credential request does not accept the "${n}" field`};return{ok:!0,record:e}}function jn(e){let t=O(e,["nodeId"]);if(!t.ok)return r(t.reason);let n=t.record.nodeId;return typeof n!="string"||n.length===0?r("nodeId is required"):u({nodeId:n})}function Vn(e){let t=O(e??{},[]);return t.ok?u(null):r(t.reason)}function Jn(e){let t=O(e,["tickId"]);if(!t.ok)return r(t.reason);let n=t.record.tickId;return typeof n!="string"||n.length===0?r("tickId is required"):u({tickId:n})}function Xn(e){let t=O(e,["executionKind","deliveryId","lifecycleOperation"]);if(!t.ok)return r(t.reason);let n=t.record.executionKind;if(n!=="event_handler"&&n!=="lifecycle")return r('executionKind must be "event_handler" or "lifecycle"');let o,s=t.record.deliveryId;if(s!==void 0){if(typeof s!="string"||s.length===0)return r("deliveryId must be a non-empty string");o=s}let a,c=t.record.lifecycleOperation;if(c!==void 0){if(c!=="enable"&&c!=="disable"&&c!=="renew")return r('lifecycleOperation must be "enable", "disable", or "renew"');a=c}return n==="lifecycle"&&a===void 0?r("lifecycleOperation is required for the lifecycle execution kind"):u({executionKind:n,...o!==void 0?{deliveryId:o}:{},...a!==void 0?{lifecycleOperation:a}:{}})}function Yn(e){return!i(e)||typeof e.sessionId!="string"||typeof e.connectionId!="string"||typeof e.authProfileRef!="string"||typeof e.authType!="string"||!i(e.credential)?r("runtime credential session must carry sessionId, connectionId, auth profile facts and a credential object"):u(e.credential)}function D(e){return!i(e)||typeof e.file_id!="string"||typeof e.name!="string"||typeof e.size_bytes!="number"||typeof e.created_at!="string"||typeof e.expires_at!="string"||e.mime_type!==void 0&&typeof e.mime_type!="string"||e.sha256!==void 0&&typeof e.sha256!="string"||e.source!==void 0&&typeof e.source!="string"?r("file ref data does not match the AIS file-ref shape"):u(e)}function K(e){return!i(e)||e.method!=="GET"&&e.method!=="PUT"||typeof e.url!="string"||typeof e.expires_at!="string"||!Ae(e.headers)?r("presigned file URL data is invalid"):u(e)}function be(e){if(!i(e))return r("file upload session data is invalid");let t=D(e.file);if(!t.ok)return r(t.reason);let n=K(e.upload);return n.ok?u({file:t.value,upload:n.value}):r(n.reason)}function Ce(e){if(!i(e))return r("file metadata data is invalid");let t=D(e.file);return t.ok?u({file:t.value}):r(t.reason)}function Ae(e){return i(e)?Object.values(e).every(t=>typeof t=="string"):!1}var _="/internal/files",nr="/upload-session",rr="/:fileId/complete",or="/:fileId/access",ir="/:fileId/stat",sr="/:fileId/content",ur=()=>_,ar=()=>`${_}/upload-session`,cr=e=>`${_}/${encodeURIComponent(e)}/complete`,dr=(e,t)=>`${_}/${encodeURIComponent(e)}/access?intent=${encodeURIComponent(t)}`,Y=e=>`?scope_kind=${encodeURIComponent(e.scopeKind)}&scope_id=${encodeURIComponent(e.scopeId)}`,lr=(e,t)=>`${_}/${encodeURIComponent(e)}/stat${Y(t)}`,pr=(e,t)=>`${_}/${encodeURIComponent(e)}/content${Y(t)}`;function gr(e){if(!i(e))return r("internal file access data is invalid");if(e.intent==="runtime_read"||e.intent==="provider_multipart"){let t=D(e.file);if(!t.ok)return r(t.reason);let n=K(e.access);return n.ok?u({file:t.value,access:n.value,intent:e.intent}):r(n.reason)}return r("internal file access intent is invalid")}var yr="/:flowRunId/human-inputs",kr="/:flowRunId/human-inputs/:requestId",Ir="/:flowRunId/human-inputs/:requestId/expire",_r="/:flowRunId/human-inputs/:requestId/acknowledge",ve=e=>`${f}/${encodeURIComponent(e)}/human-inputs`,z=(e,t)=>`${ve(e)}/${encodeURIComponent(t)}`,Er=(e,t)=>`${z(e,t)}/expire`,hr=(e,t)=>`${z(e,t)}/acknowledge`,Ne="human_input_resolved";function xr(e){return`${Ne}_${e}`}function g(e){return{ok:!1,reason:e}}function m(e,t){return i(e)?{ok:!0,value:e}:g(`${t} must be an object`)}function E(e,t){return typeof e!="string"||e.length===0?g(`${t} must be a non-empty string`):{ok:!0,value:e}}var Oe=/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{1,9})?(?:Z|[+-]\d{2}:\d{2})$/;function De(e,t){return typeof e!="string"||!Oe.test(e)||Number.isNaN(Date.parse(e))?g(`${t} must be an ISO-8601 timestamp`):{ok:!0,value:e}}function Ue(e){let t=m(e,"renderedPrompt");if(!t.ok)return t;let n=E(t.value.title,"renderedPrompt.title");if(!n.ok)return n;let o={title:n.value};if(t.value.body!==void 0){if(typeof t.value.body!="string")return g("renderedPrompt.body must be a string");o.body=t.value.body}if(t.value.format!==void 0){if(t.value.format!=="plain"&&t.value.format!=="markdown")return g("renderedPrompt.format is invalid");o.format=t.value.format}return{ok:!0,value:o}}function Be(e){let t=m(e,"input");if(!t.ok)return t;let n=t.value.kind;if(n==="choice"){if(!Array.isArray(t.value.choices))return g("input.choices must be an array")}else if(n!=="text")if(n==="form"){if(!Array.isArray(t.value.fields))return g("input.fields must be an array")}else return g("input.kind is invalid");return{ok:!0,value:t.value}}function He(e){if(e==null)return{ok:!0,value:void 0};let t=m(e,"partiallyRenderedDelivery");if(!t.ok)return t;let n=t.value.actions;if(n===void 0)return{ok:!0,value:{}};if(!Array.isArray(n))return g("partiallyRenderedDelivery.actions must be an array");let o=[];for(let s of n){let a=m(s,"delivery action");if(!a.ok)return a;let c=E(a.value.id,"delivery action id");if(!c.ok)return c;let l=Q(a.value.inputs,`delivery action '${c.value}' inputs`);if(!l.ok)return l;o.push({id:c.value,inputs:l.value})}return{ok:!0,value:{actions:o}}}function Q(e,t){let n=m(e,t);if(!n.ok)return n;let o={};for(let[s,a]of Object.entries(n.value)){let c=Z(a,`${t}.${s}`);if(!c.ok)return c;o[s]=c.value}return{ok:!0,value:o}}function Z(e,t){let n=m(e,t);if(!n.ok)return n;switch(n.value.kind){case"literal":return{ok:!0,value:{kind:"literal",value:n.value.value}};case"human_input_ref":{let s=E(n.value.path,`${t}.path`);return s.ok?{ok:!0,value:{kind:"human_input_ref",path:s.value}}:s}case"array":{if(!Array.isArray(n.value.items))return g(`${t}.items must be an array`);let s=[];for(let[a,c]of n.value.items.entries()){let l=Z(c,`${t}[${a}]`);if(!l.ok)return l;s.push(l.value)}return{ok:!0,value:{kind:"array",items:s}}}case"object":{let s=Q(n.value.entries,`${t}.entries`);return s.ok?{ok:!0,value:{kind:"object",entries:s.value}}:s}case"template":{if(!Array.isArray(n.value.parts))return g(`${t}.parts must be an array`);let s=[];for(let[a,c]of n.value.parts.entries()){let l=Fe(c,`${t}.parts[${a}]`);if(!l.ok)return l;s.push(l.value)}return{ok:!0,value:{kind:"template",parts:s}}}default:return g(`${t}.kind is invalid`)}}function Fe(e,t){let n=m(e,t);if(!n.ok)return n;let o=n.value.kind;if(o==="literal")return typeof n.value.value!="string"?g(`${t}.value must be a string`):{ok:!0,value:{kind:"literal",value:n.value.value}};if(o==="human_input_ref"){let s=E(n.value.path,`${t}.path`);return s.ok?{ok:!0,value:{kind:"human_input_ref",path:s.value}}:s}return g(`${t}.kind is invalid`)}function wr(e){let t=m(e,"request body");if(!t.ok)return r(t.reason);let n=E(t.value.nodeId,"nodeId");if(!n.ok)return r(n.reason);let o=Ue(t.value.renderedPrompt);if(!o.ok)return r(o.reason);let s=Be(t.value.input);if(!s.ok)return r(s.reason);let a=E(t.value.timeout,"timeout");if(!a.ok)return r(a.reason);let c=De(t.value.expiresAt,"expiresAt");if(!c.ok)return r(c.reason);let l=He(t.value.partiallyRenderedDelivery);return l.ok?u({nodeId:n.value,renderedPrompt:o.value,input:s.value,timeout:a.value,expiresAt:c.value,...l.value!==void 0?{partiallyRenderedDelivery:l.value}:{}}):r(l.reason)}function $e(e){return!i(e)||typeof e.id!="string"||e.id.length===0||typeof e.nodeId!="string"||typeof e.status!="string"||!(e.output===null||i(e.output))?r("human input request view must carry id, nodeId, status and output"):u(e)}function Tr(e){if(!i(e)||typeof e.created!="boolean")return r("human input create data must carry created:boolean");let t=$e(e.request);return t.ok?u({created:e.created,request:t.value}):t}function Pr(e){return!i(e)||e.acknowledged!==!0?r("human input acknowledge data must carry acknowledged:true"):u({acknowledged:!0})}var br="ablehi-wfp-user-runtime-manifest/v1",Cr="unknown";function Ar(e){return e.endsWith(".js")?`${e.slice(0,-3)}.manifest.json`:`${e}.manifest.json`}var Nr="/internal/deployment-handshake",Ge=["start","terminate","send-event","start-webhook-watcher","run-polling-tick","invoke-tool","invoke-trigger-handler","invoke-webhook-protocol-adapter","deployment-handshake"],Or=Ge,Dr="HANDSHAKE_REQUEST_INVALID",Ur="HANDSHAKE_SECRET_UNCONFIGURED",Br="HANDSHAKE_SECRET_MISMATCH",Hr="HANDSHAKE_CONTRACT_VERSION_MISMATCH",Fr="HANDSHAKE_DISPATCH_NAMESPACE_MISMATCH",$r="HANDSHAKE_CAPABILITY_MISSING";function Gr(e){return[e.nonce,e.timestamp,e.contractVersion,e.dispatchNamespace].map(n=>`${n.length}:${n}`).join(".")}function Mr(e){return["response",e.nonce,e.contractVersion,e.dispatchNamespace,...e.capabilities].map(n=>`${n.length}:${n}`).join(".")}export{qe as CONTEXT_STATE_CLEANUP_ROUTE_PATH,Ge as DEPLOYMENT_HANDSHAKE_DISPATCHER_CAPABILITIES,Or as DEPLOYMENT_HANDSHAKE_REQUIRED_CAPABILITIES,Nr as DEPLOYMENT_HANDSHAKE_ROUTE,mn as EGRESS_GRANT_AUDIT_ROUTE_SUBPATH,Rn as EGRESS_GRANT_CONSUME_ROUTE_SUBPATH,xe as EGRESS_GRANT_SCOPE_KINDS,it as EVENT_WAIT_ROUTE_SUBPATH,Ye as EXECUTION_CONTEXT_ROUTE_SUBPATH,or as FILE_ACCESS_ROUTE_SUBPATH,rr as FILE_COMPLETE_ROUTE_SUBPATH,sr as FILE_CONTENT_ROUTE_SUBPATH,ir as FILE_STAT_ROUTE_SUBPATH,nr as FILE_UPLOAD_SESSION_ROUTE_SUBPATH,ln as FLOW_RUN_EGRESS_GRANT_ROUTE_SUBPATH,ot as FLOW_RUN_RESULT_ROUTE_SUBPATH,Hn as FLOW_RUN_RUNTIME_CREDENTIAL_ROUTE_SUBPATH,yt as HANDLER_BUNDLES_ROUTE_SUBPATH,$r as HANDSHAKE_CAPABILITY_MISSING,Hr as HANDSHAKE_CONTRACT_VERSION_MISMATCH,Fr as HANDSHAKE_DISPATCH_NAMESPACE_MISMATCH,Dr as HANDSHAKE_REQUEST_INVALID,Br as HANDSHAKE_SECRET_MISMATCH,Ur as HANDSHAKE_SECRET_UNCONFIGURED,yr as HUMAN_INPUTS_ROUTE_SUBPATH,_r as HUMAN_INPUT_ACKNOWLEDGE_ROUTE_SUBPATH,Ir as HUMAN_INPUT_EXPIRE_ROUTE_SUBPATH,kr as HUMAN_INPUT_REQUEST_ROUTE_SUBPATH,Ne as HUMAN_INPUT_RESOLVED_EVENT_PREFIX,J as INTERNAL_EGRESS_GRANTS_ROUTE_PREFIX,_ as INTERNAL_FILES_ROUTE_PREFIX,f as INTERNAL_FLOW_RUNS_ROUTE_PREFIX,ce as INTERNAL_FLOW_VERSIONS_ROUTE_PREFIX,F as INTERNAL_INSTALLATIONS_ROUTE_PREFIX,T as INTERNAL_POLLING_TRIGGER_INSTANCES_ROUTE_PREFIX,M as INTERNAL_TOOL_INVOCATIONS_ROUTE_PREFIX,x as INTERNAL_WEBHOOK_TRIGGER_INSTANCES_ROUTE_PREFIX,Yt as POLLING_TRIGGER_CONTEXT_ROUTE_SUBPATH,gn as POLLING_TRIGGER_EGRESS_GRANT_ROUTE_SUBPATH,zt as POLLING_TRIGGER_HANDLER_BUNDLES_ROUTE_SUBPATH,$n as POLLING_TRIGGER_RUNTIME_CREDENTIAL_ROUTE_SUBPATH,Qt as POLLING_TRIGGER_TICK_EVENTS_ROUTE_SUBPATH,Wn as RUNTIME_CREDENTIAL_SESSION_SCOPE_KINDS,ee as SERVER_EXECUTION_CONTRACT_VERSION,rt as STEP_RESULT_ROUTE_SUBPATH,kt as TOOL_HANDLER_BUNDLES_ROUTE_SUBPATH,pn as TOOL_INVOCATION_EGRESS_GRANT_ROUTE_SUBPATH,Fn as TOOL_INVOCATION_RUNTIME_CREDENTIAL_ROUTE_SUBPATH,Ft as WEBHOOK_PROTOCOL_ADAPTER_BUNDLE_ROUTE_SUBPATH,Gt as WEBHOOK_PROTOCOL_ADAPTER_MODULE,bt as WEBHOOK_TRIGGER_CONTEXT_ROUTE_SUBPATH,At as WEBHOOK_TRIGGER_DELIVERY_ROUTE_SUBPATH,fn as WEBHOOK_TRIGGER_EGRESS_GRANT_ROUTE_SUBPATH,vt as WEBHOOK_TRIGGER_EVENTS_ROUTE_SUBPATH,Ct as WEBHOOK_TRIGGER_HANDLER_BUNDLES_ROUTE_SUBPATH,Nt as WEBHOOK_TRIGGER_REARM_ROUTE_SUBPATH,Gn as WEBHOOK_TRIGGER_RUNTIME_CREDENTIAL_ROUTE_SUBPATH,br as WFP_USER_RUNTIME_MANIFEST_FORMAT_VERSION,Cr as WFP_USER_RUNTIME_UNKNOWN_SOURCE_REVISION,Gr as deploymentHandshakeProbePayload,Mr as deploymentHandshakeResponseProofPayload,hn as egressGrantAuditPath,En as egressGrantConsumePath,at as eventWaitPath,ze as executionContextPath,yn as flowRunEgressGrantPath,ut as flowRunResultPath,Mn as flowRunRuntimeCredentialPath,Mt as flowScriptProtocolAdapterModuleName,It as handlerBundlesPath,hr as humanInputAcknowledgePath,Er as humanInputExpirePath,z as humanInputRequestPath,xr as humanInputResolvedEventType,ve as humanInputsPath,dr as internalFileAccessPath,cr as internalFileCompletePath,pr as internalFileContentPath,lr as internalFileStatPath,ar as internalFileUploadSessionPath,ur as internalFilesPath,P as isValidRequestDigest,ft as parseCompleteFlowRunWaitBody,We as parseContextStateCleanupRequestBody,je as parseContextStateCleanupResponseData,y as parseContextStateScope,wr as parseCreateHumanInputBody,bn as parseEgressGrantAuditBody,Sn as parseEgressGrantConsumeBody,An as parseEgressGrantConsumeData,Cn as parseEgressGrantData,Qe as parseExecutionContextData,Ce as parseFileMetadataData,D as parseFileRefData,oe as parseFileRuntimeLimits,be as parseFileUploadSessionData,xn as parseFlowActionGrantBody,lt as parseFlowRunResultBody,pt as parseFlowRunResultData,jn as parseFlowRuntimeCredentialBody,le as parseHandlerBundle,Et as parseHandlerBundlesData,Pr as parseHumanInputAcknowledgeData,Tr as parseHumanInputCreateData,$e as parseHumanInputRequestViewData,gr as parseInternalFileAccessData,rn as parsePollingPublishBody,Jn as parsePollingRuntimeCredentialBody,nn as parsePollingTriggerContext,Tn as parsePollingTriggerGrantBody,on as parsePublishPollingTickEventsData,gt as parseRegisterFlowRunWaitBody,Rt as parseRegisterFlowRunWaitData,Yn as parseRuntimeCredentialSessionCredential,C as parseRuntimeNetwork,wn as parseSingleToolGrantBody,Vn as parseSingleToolRuntimeCredentialBody,ct as parseStepRecordBody,dt as parseStepRecordData,ht as parseToolHandlerBundlesData,qt as parseTriggerHandlerBundlesData,Lt as parseWebhookDelivery,Wt as parseWebhookPublishEventsBody,jt as parseWebhookRearmBody,Xn as parseWebhookRuntimeCredentialBody,Pn as parseWebhookTriggerGrantBody,Kt as parseWebhookWatcherContext,Zt as pollingTriggerContextPath,In as pollingTriggerEgressGrantPath,en as pollingTriggerHandlerBundlesPath,Ln as pollingTriggerRuntimeCredentialPath,tn as pollingTriggerTickEventsPath,Te as requestHasMultipartFileParts,st as stepResultPath,_t as toolHandlerBundlesPath,kn as toolInvocationEgressGrantPath,Kn as toolInvocationRuntimeCredentialPath,$t as webhookProtocolAdapterBundlePath,Ot as webhookTriggerContextPath,Ut as webhookTriggerDeliveryPath,_n as webhookTriggerEgressGrantPath,Bt as webhookTriggerEventsPath,Dt as webhookTriggerHandlerBundlesPath,Ht as webhookTriggerRearmPath,qn as webhookTriggerRuntimeCredentialPath,Ar as wfpUserRuntimeManifestPath};
|
|
1
|
+
var ee="0.2.9";function u(e){return{ok:!0,value:e}}function r(e){return{ok:!1,reason:e}}function i(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}var We="/cleanup-state-scopes";function k(e){if(!i(e)||typeof e.kind!="string")return r("context state scope surface shape is invalid");switch(e.kind){case"webhook-trigger":return te(e);case"polling-trigger":return ne(e);case"flow-action":return re(e);default:return r("context state scope kind is invalid")}}function je(e){if(!i(e))return r("cleanup request body must be a JSON object");let t=b(e,["scopes"]);if(t!==void 0)return r(`cleanup request does not accept the "${t}" field`);if(!Array.isArray(e.scopes))return r("cleanup request scopes must be an array");let n=[];for(let o of e.scopes){let s=k(o);if(!s.ok)return s;n.push(s.value)}return u({scopes:n})}function Ve(e){return!i(e)||typeof e.deleted!="number"||!Number.isSafeInteger(e.deleted)||e.deleted<0?r("cleanup response data surface shape is invalid"):u({deleted:e.deleted})}function te(e){let t=b(e,["kind","workspaceId","triggerInstanceId"]);return t!==void 0?r(`webhook trigger scope does not accept "${t}"`):e.kind!=="webhook-trigger"||!R(e.workspaceId)||!R(e.triggerInstanceId)?r("webhook trigger state scope is invalid"):u({kind:"webhook-trigger",workspaceId:e.workspaceId,triggerInstanceId:e.triggerInstanceId})}function ne(e){let t=b(e,["kind","workspaceId","pollingInstanceId"]);return t!==void 0?r(`polling trigger scope does not accept "${t}"`):e.kind!=="polling-trigger"||!R(e.workspaceId)||!R(e.pollingInstanceId)?r("polling trigger state scope is invalid"):u({kind:"polling-trigger",workspaceId:e.workspaceId,pollingInstanceId:e.pollingInstanceId})}function re(e){let t=b(e,["kind","workspaceId","flowId","nodeId","connectionId"]);if(t!==void 0)return r(`flow action scope does not accept "${t}"`);let n=e.connectionId;return e.kind!=="flow-action"||!R(e.workspaceId)||!R(e.flowId)||!R(e.nodeId)||n!==null&&!R(n)?r("flow action state scope is invalid"):u({kind:"flow-action",workspaceId:e.workspaceId,flowId:e.flowId,nodeId:e.nodeId,connectionId:n})}function R(e){return typeof e=="string"&&e.length>0}function b(e,t){return Object.keys(e).find(n=>!t.includes(n))}var g="/internal/flow-runs",ze="/:flowRunId/execution-context";function Qe(e){return`${g}/${encodeURIComponent(e)}/execution-context`}function oe(e){return!i(e)||!B(e.fileMaxBytes)||!B(e.fileReadMaxBytes)||!B(e.inlineMultipartBytesMax)?r("file runtime limits must carry three positive integer bounds"):u({fileMaxBytes:e.fileMaxBytes,fileReadMaxBytes:e.fileReadMaxBytes,inlineMultipartBytesMax:e.inlineMultipartBytesMax})}function Ze(e){if(!i(e))return r("execution context must be a JSON object");let t=e.compiled;if(typeof e.flowRunId!="string"||typeof e.workspaceId!="string"||!i(e.input)||!i(t)||typeof t.irSchemaVersion!="string"||typeof t.interpreterContractVersion!="string"||typeof t.compiledArtifactId!="string"||!i(t.ir)||!Array.isArray(t.ir.nodes)||!se(e.executionBindings))return r("execution context surface shape is invalid");let n=ie(e.fileRuntime);return n.ok?u({...e,fileRuntime:n.value}):r(n.reason)}function ie(e){if(e===null)return u(null);if(!i(e))return r("fileRuntime must be null or an object");let t=oe(e.limits);return t.ok?u({limits:t.value}):r(t.reason)}function se(e){return Array.isArray(e)?e.every(t=>{if(!i(t))return!1;let n=t.connection,o=k(t.stateScope);return typeof t.nodeId=="string"&&typeof t.toolRef=="string"&&i(t.toolDescriptor)&&i(t.integrationDescriptor)&&i(n)&&typeof n.installationId=="string"&&typeof n.connectionRef=="string"&&typeof n.connectionId=="string"&&typeof n.authProfileRef=="string"&&typeof n.authType=="string"&&o.ok}):!1}function B(e){return typeof e=="number"&&Number.isSafeInteger(e)&&e>0}import{parseAblehiErrorDigest as H}from"@ablehi/error-contract";var ot="/:flowRunId/steps/:nodeId/result",it="/:flowRunId/result",st="/:flowRunId/event-waits/:nodeId";function ut(e,t){return`${g}/${encodeURIComponent(e)}/steps/${encodeURIComponent(t)}/result`}function at(e){return`${g}/${encodeURIComponent(e)}/result`}function dt(e,t){return`${g}/${encodeURIComponent(e)}/event-waits/${encodeURIComponent(t)}`}function ct(e){if(!i(e))return{ok:!1,kind:"validation",reason:"step record body must be a JSON object"};let t=m(e,["attempt","result","durationMs"]);if(t!==void 0)return{ok:!1,kind:"validation",reason:`step record does not accept the "${t}" field`};let n=e.attempt;if(typeof n!="number"||!Number.isInteger(n)||n<=0)return{ok:!1,kind:"validation",reason:"attempt must be a positive integer"};let o=ue(e.result);if(!o.ok)return o;let s={attempt:n,result:o.value};if(e.durationMs!==void 0){let a=e.durationMs;if(typeof a!="number"||!Number.isFinite(a)||a<0)return{ok:!1,kind:"validation",reason:"durationMs must be a non-negative number"};s.durationMs=a}return{ok:!0,value:s}}function ue(e){if(!i(e))return{ok:!1,kind:"step_result_invalid",reason:"result must be a JSON object"};let t=e.status;if(t==="succeeded"){let n=m(e,["status","output"]);return n!==void 0?{ok:!1,kind:"validation",reason:`step record result does not accept the "${n}" field`}:"output"in e?{ok:!0,value:{status:"succeeded",output:e.output}}:{ok:!1,kind:"step_result_invalid",reason:"a succeeded result must carry output"}}if(t==="failed"){let n=m(e,["status","error"]);if(n!==void 0)return{ok:!1,kind:"validation",reason:`step record result does not accept the "${n}" field`};let o=H(e.error);return o.ok?{ok:!0,value:{status:"failed",error:o.value}}:{ok:!1,kind:"step_result_invalid",reason:`a failed result must carry an AblehiErrorDigest: ${o.reason}`}}if(t==="skipped"){let n=m(e,["status","reason"]);return n!==void 0?{ok:!1,kind:"validation",reason:`step record result does not accept the "${n}" field`}:e.reason!=="run_if_false"?{ok:!1,kind:"step_result_invalid",reason:'a skipped result reason must be "run_if_false"'}:{ok:!0,value:{status:"skipped",reason:"run_if_false"}}}if(t==="timed_out"){let n=m(e,["status","error"]);if(n!==void 0)return{ok:!1,kind:"validation",reason:`step record result does not accept the "${n}" field`};let o=H(e.error);return o.ok?{ok:!0,value:{status:"timed_out",error:o.value}}:{ok:!1,kind:"step_result_invalid",reason:`a timed_out result must carry an AblehiErrorDigest: ${o.reason}`}}return{ok:!1,kind:"step_result_invalid",reason:'result status must be "succeeded", "failed", "skipped", or "timed_out"'}}function lt(e){return!i(e)||typeof e.flowRunId!="string"||typeof e.nodeId!="string"||!ae(e.recorded)?r("step record data surface shape is invalid"):u({flowRunId:e.flowRunId,nodeId:e.nodeId,recorded:e.recorded})}function ae(e){return e==="succeeded"||e==="failed"||e==="skipped"||e==="timed_out"}function pt(e){if(!i(e))return r("result body must be a JSON object");let t=m(e,["status","output","error","composition"]);if(t!==void 0)return r(`result does not accept the "${t}" field`);let n=e.status;if(n!=="succeeded"&&n!=="failed")return r('result status must be "succeeded" or "failed"');let o={status:n};if(e.output!==void 0){if(n!=="succeeded")return r("output is only allowed on a succeeded result");o.output=e.output}if(e.error!==void 0){if(n!=="failed")return r("error is only allowed on a failed result");let s=H(e.error);if(!s.ok)return r(`result error must be an AblehiErrorDigest: ${s.reason}`);o.error=s.value}if(n==="failed"&&o.error===void 0)return r("a failed result must carry an AblehiErrorDigest");if(e.composition!==void 0){if(n!=="succeeded")return r("composition is only allowed on a succeeded result");o.composition=e.composition}return u(o)}function ft(e){return i(e)?u(e):r("flow run result data must be a JSON object")}var de=/^[A-Za-z0-9_-]{1,100}$/;function gt(e){if(!i(e))return r("register body must be a JSON object");let t=m(e,["eventType","correlationKey"]);if(t!==void 0)return r(`register wait does not accept the "${t}" field`);let n=q(e.eventType);if(!n.ok)return r(n.reason);let o=e.correlationKey;return typeof o!="string"||o.length===0?r("correlationKey must be a non-empty string"):u({eventType:n.value,correlationKey:o})}function Rt(e){if(!i(e))return r("complete body must be a JSON object");let t=m(e,["eventType","correlationKey","outcome","eventId"]);if(t!==void 0)return r(`complete wait does not accept the "${t}" field`);let n=e.outcome;if(n!=="received"&&n!=="timed_out")return r('outcome must be "received" or "timed_out"');let o=q(e.eventType);if(!o.ok)return r(o.reason);let s=e.correlationKey;if(typeof s!="string"||s.length===0)return r("correlationKey must be a non-empty string");let a={eventType:o.value,correlationKey:s,outcome:n};if(e.eventId!==void 0){if(typeof e.eventId!="string"||e.eventId.length===0)return r("eventId must be a non-empty string");a.eventId=e.eventId}return u(a)}function mt(e){return!i(e)||e.registered!==!0?r("register wait data surface shape is invalid"):u({registered:!0})}function q(e){return typeof e!="string"||e.length===0?r("eventType must be a non-empty string"):de.test(e)?u(e):r("eventType must match ^[A-Za-z0-9_-]{1,100}$")}function m(e,t){return Object.keys(e).find(n=>!t.includes(n))}var ce="/internal/flow-versions",kt="/:flowVersionId/handler-bundles",$="/internal/installations",It="/:installationId/handler-bundles";function _t(e,t){return`${ce}/${encodeURIComponent(e)}/handler-bundles?compiledArtifactId=${encodeURIComponent(t)}`}function ht(e){return`${$}/${encodeURIComponent(e.installationId)}/handler-bundles?workspaceId=${encodeURIComponent(e.workspaceId)}&artifactDigest=${encodeURIComponent(e.artifactDigest)}`}var le=new Set(["managed_only","managed_plus_unmanaged_sdk"]);function C(e){if(!I(e))return F("runtimeNetwork must be a JSON object");let t=e.networkModel;return typeof t!="string"||!le.has(t)?F("runtimeNetwork.networkModel is unknown"):!W(e.apiHosts)||!W(e.authHosts)||typeof e.httpsOnly!="boolean"?F("runtimeNetwork host/https fields are invalid"):{ok:!0,value:{networkModel:t,apiHosts:e.apiHosts,authHosts:e.authHosts,httpsOnly:e.httpsOnly}}}function Et(e){if(!I(e)||typeof e.flowVersionId!="string"||typeof e.compiledArtifactId!="string"||!Array.isArray(e.bundles))return E("handler bundles data surface shape is invalid");let t=j(e.bundles);return t.ok?{ok:!0,value:{flowVersionId:e.flowVersionId,compiledArtifactId:e.compiledArtifactId,bundles:t.value}}:t}function xt(e){if(!I(e)||typeof e.installationId!="string"||typeof e.artifactDigest!="string"||!Array.isArray(e.bundles))return E("tool handler bundles data surface shape is invalid");let t=j(e.bundles);return t.ok?{ok:!0,value:{installationId:e.installationId,artifactDigest:e.artifactDigest,bundles:t.value}}:t}function j(e){let t=[];for(let n of e){let o=pe(n);if(!o.ok)return o;t.push(o.value)}return{ok:!0,value:t}}function pe(e){if(!I(e)||typeof e.toolRef!="string"||e.kind!=="handler"&&e.kind!=="request")return E("handler bundle entry shape is invalid");if(e.kind==="request"){if(e.module!==void 0)return E("a request bundle must not carry a module");let o=C(e.runtimeNetwork);return o.ok?{ok:!0,value:{toolRef:e.toolRef,kind:"request",runtimeNetwork:o.value}}:o}let t=e.module;if(!I(t)||typeof t.entry!="string"||t.entry.length===0||!fe(t.files))return E("a handler bundle must carry a { entry, files } module");let n=C(e.runtimeNetwork);return n.ok?{ok:!0,value:{toolRef:e.toolRef,kind:"handler",module:{entry:t.entry,files:t.files},runtimeNetwork:n.value}}:n}function E(e){return{ok:!1,kind:"shape",reason:e}}function F(e){return{ok:!1,kind:"runtime_network",reason:e}}function I(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function W(e){return Array.isArray(e)&&e.every(t=>typeof t=="string")}function fe(e){return I(e)&&Object.values(e).every(t=>typeof t=="string")}var x="/internal/webhook-trigger-instances",Ct="/:triggerInstanceId/context",At="/:triggerInstanceId/handler-bundles",vt="/:triggerInstanceId/deliveries/:deliveryId",Nt="/:triggerInstanceId/events",Ot="/:triggerInstanceId/rearm",w=e=>`${x}/${encodeURIComponent(e)}`;function Dt(e,t){return`${w(e)}/context?artifactDigest=${encodeURIComponent(t)}`}function Ut(e,t){return`${w(e)}/handler-bundles?artifactDigest=${encodeURIComponent(t)}`}function Bt(e,t){return`${w(e)}/deliveries/${encodeURIComponent(t)}`}function Ht(e){return`${w(e)}/events`}function Ft(e){return`${w(e)}/rearm`}var $t="/:installationId/webhook-protocol-adapter-bundle";function Gt(e){return`${$}/${encodeURIComponent(e.installationId)}/webhook-protocol-adapter-bundle?workspaceId=${encodeURIComponent(e.workspaceId)}&artifactDigest=${encodeURIComponent(e.artifactDigest)}`}var Mt="modules/webhook/protocol-adapter.js";function Kt(e){return`modules/webhook/protocol-adapter-${e}.js`}function Lt(e){let t=i(e)?k(e.stateScope):r("webhook watcher context state scope is invalid");return!i(e)||typeof e.artifactDigest!="string"||typeof e.triggerRef!="string"||typeof e.triggerName!="string"||typeof e.integrationRef!="string"||!i(e.inputs)||e.connection!==null&&!ge(e.connection)||!Re(e.runtime)||!t.ok||t.value.kind!=="webhook-trigger"?r("webhook watcher context surface shape is invalid"):u(e)}function ge(e){return i(e)&&typeof e.connectionId=="string"&&typeof e.connectionRef=="string"&&typeof e.integrationRef=="string"&&typeof e.authProfileRef=="string"&&typeof e.authType=="string"}function Re(e){if(!i(e)||e.type!=="webhook"||typeof e.trigger_ref!="string")return!1;let t=e.webhook;return i(t)&&typeof t.event_handler_module=="string"&&typeof t.enable_handler_module=="string"&&typeof t.disable_handler_module=="string"}function qt(e){if(!i(e)||typeof e.deliveryId!="string"||typeof e.receivedAt!="string"||!i(e.request))return r("webhook delivery surface shape is invalid");let t=e.request;return t.method!=="POST"||!i(t.headers)||typeof t.rawBody!="string"?r("webhook delivery request shape is invalid"):u(e)}function Wt(e){if(!i(e)||typeof e.triggerRef!="string"||typeof e.artifactDigest!="string"||!Array.isArray(e.modules)||!e.modules.every(me))return{ok:!1,kind:"shape",reason:"trigger handler bundles data surface shape is invalid"};let t=C(e.runtimeNetwork);return t.ok?{ok:!0,value:{triggerRef:e.triggerRef,artifactDigest:e.artifactDigest,modules:e.modules,runtimeNetwork:t.value}}:t}function me(e){return i(e)&&typeof e.specifier=="string"&&e.specifier.length>0&&typeof e.source=="string"}function jt(e){if(!i(e))return r("publish events body must be a JSON object");let t=G(e,["deliveryId","events"]);if(t!==void 0)return r(`publish events does not accept the "${t}" field`);let n=e.deliveryId;if(typeof n!="string"||n.length===0)return r("deliveryId must be a non-empty string");let o=e.events;if(!Array.isArray(o))return r("events must be an array");let s=[];for(let a of o){let d=ye(a);if(!d.ok)return d;s.push(d.value)}return u({deliveryId:n,events:s})}function ye(e){if(!i(e))return r("each event must be a JSON object");let t=G(e,["eventId","occurredAt","dedupeKey","payload"]);if(t!==void 0)return r(`event does not accept the "${t}" field`);let n=e.eventId;if(typeof n!="string"||n.length===0)return r("eventId must be a non-empty string");let o=e.occurredAt;if(typeof o!="string"||o.length===0)return r("occurredAt must be a non-empty string");if(!i(e.payload))return r("event payload must be a JSON object");let s={eventId:n,occurredAt:o,payload:e.payload};if(e.dedupeKey!==void 0){if(typeof e.dedupeKey!="string"||e.dedupeKey.length===0)return r("dedupeKey must be a non-empty string");s.dedupeKey=e.dedupeKey}return u(s)}function Vt(e){if(!i(e))return r("rearm body must be a JSON object");let t=G(e,["expectedWatcherInstanceId"]);if(t!==void 0)return r(`rearm does not accept the "${t}" field`);let n=e.expectedWatcherInstanceId;return typeof n!="string"||n.length===0?r("expectedWatcherInstanceId must be a non-empty string"):u({expectedWatcherInstanceId:n})}function G(e,t){return Object.keys(e).find(n=>!t.includes(n))}var T="/internal/polling-trigger-instances",zt="/:pollingInstanceId/context",Qt="/:pollingInstanceId/handler-bundles",Zt="/:pollingInstanceId/ticks/:tickId/events",M=e=>`${T}/${encodeURIComponent(e)}`;function en(e,t,n){return`${M(e)}/context?artifactDigest=${encodeURIComponent(t)}&tickId=${encodeURIComponent(n)}`}function tn(e,t){return`${M(e)}/handler-bundles?artifactDigest=${encodeURIComponent(t)}`}function nn(e,t){return`${M(e)}/ticks/${encodeURIComponent(t)}/events`}function rn(e){let t=i(e)?k(e.stateScope):r("polling trigger context state scope is invalid");return!i(e)||typeof e.artifactDigest!="string"||typeof e.triggerRef!="string"||typeof e.triggerName!="string"||typeof e.integrationRef!="string"||!i(e.inputs)||e.connection!==null&&!ke(e.connection)||!Ie(e.runtime)||!t.ok||t.value.kind!=="polling-trigger"||!_e(e.tick)||!he(e.limits)?r("polling trigger context surface shape is invalid"):u(e)}function ke(e){return i(e)&&typeof e.connectionId=="string"&&typeof e.connectionRef=="string"&&typeof e.integrationRef=="string"&&typeof e.authProfileRef=="string"&&typeof e.authType=="string"}function Ie(e){if(!i(e)||e.type!=="polling"||typeof e.trigger_id!="string"||typeof e.trigger_ref!="string")return!1;let t=e.polling;if(!i(t)||typeof t.run_handler_module!="string")return!1;let n=t.schedule;if(!i(n)||n.type!=="interval"||typeof n.every_seconds!="number")return!1;let o=t.dedup;return i(o)&&(o.strategy==="cursor"||o.strategy==="hash"||o.strategy==="id_field")}function _e(e){return i(e)&&typeof e.tickId=="string"&&typeof e.scheduledAt=="string"&&typeof e.attempt=="number"}function he(e){return i(e)&&typeof e.maxEventsPerTick=="number"}function on(e){if(!i(e))return r("publish body must be a JSON object");let t=V(e,["events","nextCursor"]);if(t!==void 0)return r(`publish does not accept the "${t}" field`);let n=e.events;if(!Array.isArray(n))return r("events must be an array");let o=[];for(let a of n){let d=Ee(a);if(!d.ok)return d;o.push(d.value)}let s={events:o};if("nextCursor"in e){let a=e.nextCursor;if(a!==null&&typeof a!="string")return r("nextCursor must be a string, null, or omitted");s.nextCursor=a}return u(s)}function Ee(e){if(!i(e))return r("each event must be a JSON object");let t=V(e,["eventId","occurredAt","dedupeKey","payload"]);if(t!==void 0)return r(`event does not accept the "${t}" field`);if(typeof e.eventId!="string"||e.eventId.length===0)return r("event eventId must be a non-empty string");if(!i(e.payload))return r("event payload must be a JSON object");let n={eventId:e.eventId,payload:e.payload};if(e.occurredAt!==void 0){if(typeof e.occurredAt!="string"||e.occurredAt.length===0)return r("event occurredAt must be a non-empty string");n.occurredAt=e.occurredAt}if(e.dedupeKey!==void 0){if(typeof e.dedupeKey!="string"||e.dedupeKey.length===0)return r("event dedupeKey must be a non-empty string");n.dedupeKey=e.dedupeKey}return u(n)}function sn(e){return!i(e)||typeof e.tickId!="string"||typeof e.cursorUpdated!="boolean"||!Array.isArray(e.results)||!e.results.every(xe)?r("publish polling tick events data surface shape is invalid"):u(e)}function xe(e){return i(e)&&typeof e.eventId=="string"&&typeof e.dedupeKey=="string"&&typeof e.duplicate=="boolean"&&(e.flowRunId===null||typeof e.flowRunId=="string")}function V(e,t){return Object.keys(e).find(n=>!t.includes(n))}var J="/internal/egress-grants",K="/internal/tool-invocations",pn="/:flowRunId/egress-grant",fn="/:invocationId/egress-grant",gn="/:pollingInstanceId/egress-grant",Rn="/:triggerInstanceId/egress-grant",mn="/:grantId/consume",yn="/:grantId/audit",kn=e=>`${g}/${encodeURIComponent(e)}/egress-grant`,In=e=>`${K}/${encodeURIComponent(e)}/egress-grant`,_n=e=>`${T}/${encodeURIComponent(e)}/egress-grant`,hn=e=>`${x}/${encodeURIComponent(e)}/egress-grant`,En=e=>`${J}/${encodeURIComponent(e)}/consume`,xn=e=>`${J}/${encodeURIComponent(e)}/audit`,we=["flow_action","single_tool","polling_trigger","webhook_trigger"],Te=/^[A-Za-z0-9][A-Za-z0-9:_+/=.-]{15,1023}$/;function P(e){return typeof e=="string"&&Te.test(e)}function Pe(e){if(!i(e)||e.body_type!=="multipart")return!1;let t=e.body;if(!i(t))return!1;let n=t.parts;return Array.isArray(n)?n.some(o=>i(o)?o.kind==="file"&&typeof o.file_id=="string"&&o.file_id.length>0:!1):!1}function c(e){return{ok:!1,kind:"shape",reason:e}}function S(){return{ok:!1,kind:"request_digest",reason:"request digest is missing or malformed"}}function v(e,t){if(!i(e))return{ok:!1,reason:"grant request body must be a JSON object"};for(let n of Object.keys(e))if(!t.includes(n))return{ok:!1,reason:`grant request does not accept the "${n}" field`};return{ok:!0,record:e}}function N(e){if(!i(e))return"request must be a JSON object"}function wn(e){let t=v(e,["nodeId","request","requestDigest"]);if(!t.ok)return c(t.reason);let n=t.record.nodeId;if(typeof n!="string"||n.length===0)return c("nodeId is required");let o=N(t.record.request);if(o!==void 0)return c(o);let s=t.record.requestDigest;return P(s)?{ok:!0,value:{nodeId:n,requestDigest:s,requestHasMultipartFiles:Pe(t.record.request)}}:S()}function Tn(e){let t=v(e,["request","requestDigest"]);if(!t.ok)return c(t.reason);let n=N(t.record.request);if(n!==void 0)return c(n);let o=t.record.requestDigest;return P(o)?{ok:!0,value:{requestDigest:o}}:S()}function Pn(e){let t=v(e,["tickId","request","requestDigest"]);if(!t.ok)return c(t.reason);let n=t.record.tickId;if(typeof n!="string"||n.length===0)return c("tickId is required");let o=N(t.record.request);if(o!==void 0)return c(o);let s=t.record.requestDigest;return P(s)?{ok:!0,value:{tickId:n,requestDigest:s}}:S()}function Sn(e){let t=v(e,["phase","lifecycle","request","requestDigest"]);if(!t.ok)return c(t.reason);let n=t.record.phase;if(n!=="lifecycle"&&n!=="handler")return c('phase must be "lifecycle" or "handler"');let o=t.record.lifecycle,s;if(o!==void 0){if(o!=="enable"&&o!=="disable"&&o!=="renew")return c('lifecycle must be "enable", "disable", or "renew"');s=o}if(n==="lifecycle"&&s===void 0)return c("lifecycle is required for the lifecycle phase");let a=N(t.record.request);if(a!==void 0)return c(a);let d=t.record.requestDigest;return P(d)?{ok:!0,value:{phase:n,...s!==void 0?{lifecycle:s}:{},requestDigest:d}}:S()}function X(e){return we.includes(e)?e:void 0}var Se=["scopeKind","scopeId","requestDigest"];function bn(e){if(!i(e))return c("consume body must be a JSON object");for(let s of Object.keys(e))if(!Se.includes(s))return c(`consume does not accept the "${s}" field`);let t=X(e.scopeKind);if(t===void 0)return c("scopeKind is invalid");let n=e.scopeId;if(typeof n!="string"||n.length===0)return c("scopeId is required");let o=e.requestDigest;return P(o)?{ok:!0,value:{scopeKind:t,scopeId:n,requestDigest:o}}:S()}var be=["scopeKind","scopeId","providerHost","status","durationMs","requestBytes","responseBytes","errorCode"];function A(e,t){return typeof e!="number"||!Number.isInteger(e)||e<0?{ok:!1,reason:`${t} must be a non-negative integer`}:{ok:!0,value:e}}function Cn(e){if(!i(e))return c("audit body must be a JSON object");for(let p of Object.keys(e))if(!be.includes(p))return c(`audit does not accept the "${p}" field`);let t=X(e.scopeKind);if(t===void 0)return c("scopeKind is invalid");let n=e.scopeId;if(typeof n!="string"||n.length===0)return c("scopeId is required");let o=e.providerHost;if(typeof o!="string"||o.length===0)return c("providerHost is required");let s=A(e.durationMs,"durationMs");if(!s.ok)return c(s.reason);let a;if(e.status!==void 0){let p=A(e.status,"status");if(!p.ok)return c(p.reason);a=p.value}let d;if(e.requestBytes!==void 0){let p=A(e.requestBytes,"requestBytes");if(!p.ok)return c(p.reason);d=p.value}let l;if(e.responseBytes!==void 0){let p=A(e.responseBytes,"responseBytes");if(!p.ok)return c(p.reason);l=p.value}let U;if(e.errorCode!==void 0){let p=e.errorCode;if(typeof p!="string"||p.length===0)return c("errorCode must be a non-empty string");U=p}return{ok:!0,value:{scopeKind:t,scopeId:n,providerHost:o,...a!==void 0?{status:a}:{},durationMs:s.value,...d!==void 0?{requestBytes:d}:{},...l!==void 0?{responseBytes:l}:{},...U!==void 0?{errorCode:U}:{}}}}function An(e){return!i(e)||!i(e.grant)?r("egress grant envelope must carry a grant object"):u(e.grant)}function vn(e){return!i(e)||e.consumed!==!0?r("egress grant consume data must carry consumed:true"):u({consumed:!0})}var Fn="/:flowRunId/runtime-credential",$n="/:invocationId/runtime-credential",Gn="/:pollingInstanceId/runtime-credential",Mn="/:triggerInstanceId/runtime-credential",Kn=e=>`${g}/${encodeURIComponent(e)}/runtime-credential`,Ln=e=>`${K}/${encodeURIComponent(e)}/runtime-credential`,qn=e=>`${T}/${encodeURIComponent(e)}/runtime-credential`,Wn=e=>`${x}/${encodeURIComponent(e)}/runtime-credential`,jn=["flow_action","tool_invoke","polling_trigger","webhook_trigger"];function O(e,t){if(!i(e))return{ok:!1,reason:"runtime credential request body must be a JSON object"};for(let n of Object.keys(e))if(!t.includes(n))return{ok:!1,reason:`runtime credential request does not accept the "${n}" field`};return{ok:!0,record:e}}function Vn(e){let t=O(e,["nodeId"]);if(!t.ok)return r(t.reason);let n=t.record.nodeId;return typeof n!="string"||n.length===0?r("nodeId is required"):u({nodeId:n})}function Jn(e){let t=O(e??{},[]);return t.ok?u(null):r(t.reason)}function Xn(e){let t=O(e,["tickId"]);if(!t.ok)return r(t.reason);let n=t.record.tickId;return typeof n!="string"||n.length===0?r("tickId is required"):u({tickId:n})}function Yn(e){let t=O(e,["executionKind","deliveryId","lifecycleOperation"]);if(!t.ok)return r(t.reason);let n=t.record.executionKind;if(n!=="event_handler"&&n!=="lifecycle")return r('executionKind must be "event_handler" or "lifecycle"');let o,s=t.record.deliveryId;if(s!==void 0){if(typeof s!="string"||s.length===0)return r("deliveryId must be a non-empty string");o=s}let a,d=t.record.lifecycleOperation;if(d!==void 0){if(d!=="enable"&&d!=="disable"&&d!=="renew")return r('lifecycleOperation must be "enable", "disable", or "renew"');a=d}return n==="lifecycle"&&a===void 0?r("lifecycleOperation is required for the lifecycle execution kind"):u({executionKind:n,...o!==void 0?{deliveryId:o}:{},...a!==void 0?{lifecycleOperation:a}:{}})}function zn(e){return!i(e)||typeof e.sessionId!="string"||typeof e.connectionId!="string"||typeof e.authProfileRef!="string"||typeof e.authType!="string"||!i(e.credential)?r("runtime credential session must carry sessionId, connectionId, auth profile facts and a credential object"):u(e.credential)}function D(e){return!i(e)||typeof e.file_id!="string"||typeof e.name!="string"||typeof e.size_bytes!="number"||typeof e.created_at!="string"||typeof e.expires_at!="string"||e.mime_type!==void 0&&typeof e.mime_type!="string"||e.sha256!==void 0&&typeof e.sha256!="string"||e.source!==void 0&&typeof e.source!="string"?r("file ref data does not match the AIS file-ref shape"):u(e)}function L(e){return!i(e)||e.method!=="GET"&&e.method!=="PUT"||typeof e.url!="string"||typeof e.expires_at!="string"||!ve(e.headers)?r("presigned file URL data is invalid"):u(e)}function Ce(e){if(!i(e))return r("file upload session data is invalid");let t=D(e.file);if(!t.ok)return r(t.reason);let n=L(e.upload);return n.ok?u({file:t.value,upload:n.value}):r(n.reason)}function Ae(e){if(!i(e))return r("file metadata data is invalid");let t=D(e.file);return t.ok?u({file:t.value}):r(t.reason)}function ve(e){return i(e)?Object.values(e).every(t=>typeof t=="string"):!1}var _="/internal/files",rr="/upload-session",or="/:fileId/complete",ir="/:fileId/access",sr="/:fileId/stat",ur="/:fileId/content",ar=()=>_,dr=()=>`${_}/upload-session`,cr=e=>`${_}/${encodeURIComponent(e)}/complete`,lr=(e,t)=>`${_}/${encodeURIComponent(e)}/access?intent=${encodeURIComponent(t)}`,Y=e=>`?scope_kind=${encodeURIComponent(e.scopeKind)}&scope_id=${encodeURIComponent(e.scopeId)}`,pr=(e,t)=>`${_}/${encodeURIComponent(e)}/stat${Y(t)}`,fr=(e,t)=>`${_}/${encodeURIComponent(e)}/content${Y(t)}`;function gr(e){if(!i(e))return r("internal file access data is invalid");if(e.intent==="runtime_read"||e.intent==="provider_multipart"){let t=D(e.file);if(!t.ok)return r(t.reason);let n=L(e.access);return n.ok?u({file:t.value,access:n.value,intent:e.intent}):r(n.reason)}return r("internal file access intent is invalid")}var kr="/:flowRunId/human-inputs",Ir="/:flowRunId/human-inputs/:requestId",_r="/:flowRunId/human-inputs/:requestId/expire",hr="/:flowRunId/human-inputs/:requestId/acknowledge",Ne=e=>`${g}/${encodeURIComponent(e)}/human-inputs`,z=(e,t)=>`${Ne(e)}/${encodeURIComponent(t)}`,Er=(e,t)=>`${z(e,t)}/expire`,xr=(e,t)=>`${z(e,t)}/acknowledge`,Oe="human_input_resolved";function wr(e){return`${Oe}_${e}`}function f(e){return{ok:!1,reason:e}}function y(e,t){return i(e)?{ok:!0,value:e}:f(`${t} must be an object`)}function h(e,t){return typeof e!="string"||e.length===0?f(`${t} must be a non-empty string`):{ok:!0,value:e}}var De=/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{1,9})?(?:Z|[+-]\d{2}:\d{2})$/;function Ue(e,t){return typeof e!="string"||!De.test(e)||Number.isNaN(Date.parse(e))?f(`${t} must be an ISO-8601 timestamp`):{ok:!0,value:e}}function Be(e){let t=y(e,"renderedPrompt");if(!t.ok)return t;let n=h(t.value.title,"renderedPrompt.title");if(!n.ok)return n;let o={title:n.value};if(t.value.body!==void 0){if(typeof t.value.body!="string")return f("renderedPrompt.body must be a string");o.body=t.value.body}if(t.value.format!==void 0){if(t.value.format!=="plain"&&t.value.format!=="markdown")return f("renderedPrompt.format is invalid");o.format=t.value.format}return{ok:!0,value:o}}function He(e){let t=y(e,"input");if(!t.ok)return t;let n=t.value.kind;if(n==="choice"){if(!Array.isArray(t.value.choices))return f("input.choices must be an array")}else if(n!=="text")if(n==="form"){if(!Array.isArray(t.value.fields))return f("input.fields must be an array")}else return f("input.kind is invalid");return{ok:!0,value:t.value}}function Fe(e){if(e==null)return{ok:!0,value:void 0};let t=y(e,"partiallyRenderedDelivery");if(!t.ok)return t;let n=t.value.actions;if(n===void 0)return{ok:!0,value:{}};if(!Array.isArray(n))return f("partiallyRenderedDelivery.actions must be an array");let o=[];for(let s of n){let a=y(s,"delivery action");if(!a.ok)return a;let d=h(a.value.id,"delivery action id");if(!d.ok)return d;let l=Q(a.value.inputs,`delivery action '${d.value}' inputs`);if(!l.ok)return l;o.push({id:d.value,inputs:l.value})}return{ok:!0,value:{actions:o}}}function Q(e,t){let n=y(e,t);if(!n.ok)return n;let o={};for(let[s,a]of Object.entries(n.value)){let d=Z(a,`${t}.${s}`);if(!d.ok)return d;o[s]=d.value}return{ok:!0,value:o}}function Z(e,t){let n=y(e,t);if(!n.ok)return n;switch(n.value.kind){case"literal":return{ok:!0,value:{kind:"literal",value:n.value.value}};case"human_input_ref":{let s=h(n.value.path,`${t}.path`);return s.ok?{ok:!0,value:{kind:"human_input_ref",path:s.value}}:s}case"array":{if(!Array.isArray(n.value.items))return f(`${t}.items must be an array`);let s=[];for(let[a,d]of n.value.items.entries()){let l=Z(d,`${t}[${a}]`);if(!l.ok)return l;s.push(l.value)}return{ok:!0,value:{kind:"array",items:s}}}case"object":{let s=Q(n.value.entries,`${t}.entries`);return s.ok?{ok:!0,value:{kind:"object",entries:s.value}}:s}case"template":{if(!Array.isArray(n.value.parts))return f(`${t}.parts must be an array`);let s=[];for(let[a,d]of n.value.parts.entries()){let l=$e(d,`${t}.parts[${a}]`);if(!l.ok)return l;s.push(l.value)}return{ok:!0,value:{kind:"template",parts:s}}}default:return f(`${t}.kind is invalid`)}}function $e(e,t){let n=y(e,t);if(!n.ok)return n;let o=n.value.kind;if(o==="literal")return typeof n.value.value!="string"?f(`${t}.value must be a string`):{ok:!0,value:{kind:"literal",value:n.value.value}};if(o==="human_input_ref"){let s=h(n.value.path,`${t}.path`);return s.ok?{ok:!0,value:{kind:"human_input_ref",path:s.value}}:s}return f(`${t}.kind is invalid`)}function Tr(e){let t=y(e,"request body");if(!t.ok)return r(t.reason);let n=h(t.value.nodeId,"nodeId");if(!n.ok)return r(n.reason);let o=Be(t.value.renderedPrompt);if(!o.ok)return r(o.reason);let s=He(t.value.input);if(!s.ok)return r(s.reason);let a=h(t.value.timeout,"timeout");if(!a.ok)return r(a.reason);let d=Ue(t.value.expiresAt,"expiresAt");if(!d.ok)return r(d.reason);let l=Fe(t.value.partiallyRenderedDelivery);return l.ok?u({nodeId:n.value,renderedPrompt:o.value,input:s.value,timeout:a.value,expiresAt:d.value,...l.value!==void 0?{partiallyRenderedDelivery:l.value}:{}}):r(l.reason)}function Ge(e){return!i(e)||typeof e.id!="string"||e.id.length===0||typeof e.nodeId!="string"||typeof e.status!="string"||!(e.output===null||i(e.output))?r("human input request view must carry id, nodeId, status and output"):u(e)}function Pr(e){if(!i(e)||typeof e.created!="boolean")return r("human input create data must carry created:boolean");let t=Ge(e.request);return t.ok?u({created:e.created,request:t.value}):t}function Sr(e){return!i(e)||e.acknowledged!==!0?r("human input acknowledge data must carry acknowledged:true"):u({acknowledged:!0})}var Cr="ablehi-wfp-user-runtime-manifest/v1",Ar="unknown";function vr(e){return e.endsWith(".js")?`${e.slice(0,-3)}.manifest.json`:`${e}.manifest.json`}var Or="/internal/deployment-handshake",Me=["start","terminate","send-event","start-webhook-watcher","run-polling-tick","invoke-tool","invoke-trigger-handler","invoke-webhook-protocol-adapter","deployment-handshake"],Dr=Me,Ur="HANDSHAKE_REQUEST_INVALID",Br="HANDSHAKE_SECRET_UNCONFIGURED",Hr="HANDSHAKE_SECRET_MISMATCH",Fr="HANDSHAKE_CONTRACT_VERSION_MISMATCH",$r="HANDSHAKE_DISPATCH_NAMESPACE_MISMATCH",Gr="HANDSHAKE_CAPABILITY_MISSING";function Mr(e){return[e.nonce,e.timestamp,e.contractVersion,e.dispatchNamespace].map(n=>`${n.length}:${n}`).join(".")}function Kr(e){return["response",e.nonce,e.contractVersion,e.dispatchNamespace,...e.capabilities].map(n=>`${n.length}:${n}`).join(".")}export{We as CONTEXT_STATE_CLEANUP_ROUTE_PATH,Me as DEPLOYMENT_HANDSHAKE_DISPATCHER_CAPABILITIES,Dr as DEPLOYMENT_HANDSHAKE_REQUIRED_CAPABILITIES,Or as DEPLOYMENT_HANDSHAKE_ROUTE,yn as EGRESS_GRANT_AUDIT_ROUTE_SUBPATH,mn as EGRESS_GRANT_CONSUME_ROUTE_SUBPATH,we as EGRESS_GRANT_SCOPE_KINDS,st as EVENT_WAIT_ROUTE_SUBPATH,ze as EXECUTION_CONTEXT_ROUTE_SUBPATH,ir as FILE_ACCESS_ROUTE_SUBPATH,or as FILE_COMPLETE_ROUTE_SUBPATH,ur as FILE_CONTENT_ROUTE_SUBPATH,sr as FILE_STAT_ROUTE_SUBPATH,rr as FILE_UPLOAD_SESSION_ROUTE_SUBPATH,pn as FLOW_RUN_EGRESS_GRANT_ROUTE_SUBPATH,it as FLOW_RUN_RESULT_ROUTE_SUBPATH,Fn as FLOW_RUN_RUNTIME_CREDENTIAL_ROUTE_SUBPATH,kt as HANDLER_BUNDLES_ROUTE_SUBPATH,Gr as HANDSHAKE_CAPABILITY_MISSING,Fr as HANDSHAKE_CONTRACT_VERSION_MISMATCH,$r as HANDSHAKE_DISPATCH_NAMESPACE_MISMATCH,Ur as HANDSHAKE_REQUEST_INVALID,Hr as HANDSHAKE_SECRET_MISMATCH,Br as HANDSHAKE_SECRET_UNCONFIGURED,kr as HUMAN_INPUTS_ROUTE_SUBPATH,hr as HUMAN_INPUT_ACKNOWLEDGE_ROUTE_SUBPATH,_r as HUMAN_INPUT_EXPIRE_ROUTE_SUBPATH,Ir as HUMAN_INPUT_REQUEST_ROUTE_SUBPATH,Oe as HUMAN_INPUT_RESOLVED_EVENT_PREFIX,J as INTERNAL_EGRESS_GRANTS_ROUTE_PREFIX,_ as INTERNAL_FILES_ROUTE_PREFIX,g as INTERNAL_FLOW_RUNS_ROUTE_PREFIX,ce as INTERNAL_FLOW_VERSIONS_ROUTE_PREFIX,$ as INTERNAL_INSTALLATIONS_ROUTE_PREFIX,T as INTERNAL_POLLING_TRIGGER_INSTANCES_ROUTE_PREFIX,K as INTERNAL_TOOL_INVOCATIONS_ROUTE_PREFIX,x as INTERNAL_WEBHOOK_TRIGGER_INSTANCES_ROUTE_PREFIX,zt as POLLING_TRIGGER_CONTEXT_ROUTE_SUBPATH,gn as POLLING_TRIGGER_EGRESS_GRANT_ROUTE_SUBPATH,Qt as POLLING_TRIGGER_HANDLER_BUNDLES_ROUTE_SUBPATH,Gn as POLLING_TRIGGER_RUNTIME_CREDENTIAL_ROUTE_SUBPATH,Zt as POLLING_TRIGGER_TICK_EVENTS_ROUTE_SUBPATH,jn as RUNTIME_CREDENTIAL_SESSION_SCOPE_KINDS,ee as SERVER_EXECUTION_CONTRACT_VERSION,ot as STEP_RESULT_ROUTE_SUBPATH,It as TOOL_HANDLER_BUNDLES_ROUTE_SUBPATH,fn as TOOL_INVOCATION_EGRESS_GRANT_ROUTE_SUBPATH,$n as TOOL_INVOCATION_RUNTIME_CREDENTIAL_ROUTE_SUBPATH,$t as WEBHOOK_PROTOCOL_ADAPTER_BUNDLE_ROUTE_SUBPATH,Mt as WEBHOOK_PROTOCOL_ADAPTER_MODULE,Ct as WEBHOOK_TRIGGER_CONTEXT_ROUTE_SUBPATH,vt as WEBHOOK_TRIGGER_DELIVERY_ROUTE_SUBPATH,Rn as WEBHOOK_TRIGGER_EGRESS_GRANT_ROUTE_SUBPATH,Nt as WEBHOOK_TRIGGER_EVENTS_ROUTE_SUBPATH,At as WEBHOOK_TRIGGER_HANDLER_BUNDLES_ROUTE_SUBPATH,Ot as WEBHOOK_TRIGGER_REARM_ROUTE_SUBPATH,Mn as WEBHOOK_TRIGGER_RUNTIME_CREDENTIAL_ROUTE_SUBPATH,Cr as WFP_USER_RUNTIME_MANIFEST_FORMAT_VERSION,Ar as WFP_USER_RUNTIME_UNKNOWN_SOURCE_REVISION,Mr as deploymentHandshakeProbePayload,Kr as deploymentHandshakeResponseProofPayload,xn as egressGrantAuditPath,En as egressGrantConsumePath,dt as eventWaitPath,Qe as executionContextPath,kn as flowRunEgressGrantPath,at as flowRunResultPath,Kn as flowRunRuntimeCredentialPath,Kt as flowScriptProtocolAdapterModuleName,_t as handlerBundlesPath,xr as humanInputAcknowledgePath,Er as humanInputExpirePath,z as humanInputRequestPath,wr as humanInputResolvedEventType,Ne as humanInputsPath,lr as internalFileAccessPath,cr as internalFileCompletePath,fr as internalFileContentPath,pr as internalFileStatPath,dr as internalFileUploadSessionPath,ar as internalFilesPath,P as isValidRequestDigest,Rt as parseCompleteFlowRunWaitBody,je as parseContextStateCleanupRequestBody,Ve as parseContextStateCleanupResponseData,k as parseContextStateScope,Tr as parseCreateHumanInputBody,Cn as parseEgressGrantAuditBody,bn as parseEgressGrantConsumeBody,vn as parseEgressGrantConsumeData,An as parseEgressGrantData,Ze as parseExecutionContextData,Ae as parseFileMetadataData,D as parseFileRefData,oe as parseFileRuntimeLimits,Ce as parseFileUploadSessionData,wn as parseFlowActionGrantBody,pt as parseFlowRunResultBody,ft as parseFlowRunResultData,Vn as parseFlowRuntimeCredentialBody,pe as parseHandlerBundle,Et as parseHandlerBundlesData,Sr as parseHumanInputAcknowledgeData,Pr as parseHumanInputCreateData,Ge as parseHumanInputRequestViewData,gr as parseInternalFileAccessData,on as parsePollingPublishBody,Xn as parsePollingRuntimeCredentialBody,rn as parsePollingTriggerContext,Pn as parsePollingTriggerGrantBody,sn as parsePublishPollingTickEventsData,gt as parseRegisterFlowRunWaitBody,mt as parseRegisterFlowRunWaitData,zn as parseRuntimeCredentialSessionCredential,C as parseRuntimeNetwork,Tn as parseSingleToolGrantBody,Jn as parseSingleToolRuntimeCredentialBody,ct as parseStepRecordBody,lt as parseStepRecordData,xt as parseToolHandlerBundlesData,Wt as parseTriggerHandlerBundlesData,qt as parseWebhookDelivery,jt as parseWebhookPublishEventsBody,Vt as parseWebhookRearmBody,Yn as parseWebhookRuntimeCredentialBody,Sn as parseWebhookTriggerGrantBody,Lt as parseWebhookWatcherContext,en as pollingTriggerContextPath,_n as pollingTriggerEgressGrantPath,tn as pollingTriggerHandlerBundlesPath,qn as pollingTriggerRuntimeCredentialPath,nn as pollingTriggerTickEventsPath,Pe as requestHasMultipartFileParts,ut as stepResultPath,ht as toolHandlerBundlesPath,In as toolInvocationEgressGrantPath,Ln as toolInvocationRuntimeCredentialPath,Gt as webhookProtocolAdapterBundlePath,Dt as webhookTriggerContextPath,Bt as webhookTriggerDeliveryPath,hn as webhookTriggerEgressGrantPath,Ht as webhookTriggerEventsPath,Ut as webhookTriggerHandlerBundlesPath,Ft as webhookTriggerRearmPath,Wn as webhookTriggerRuntimeCredentialPath,vr as wfpUserRuntimeManifestPath};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { PublishedFlowDefinition, RuntimeHumanInputSpec } from '@ablehi/flow-contract';
|
|
2
2
|
import { AblehiErrorDigest } from '@ablehi/error-contract';
|
|
3
3
|
|
|
4
|
-
declare const SERVER_EXECUTION_CONTRACT_VERSION = "0.2.
|
|
4
|
+
declare const SERVER_EXECUTION_CONTRACT_VERSION = "0.2.9";
|
|
5
5
|
type ServerExecutionContractVersion = typeof SERVER_EXECUTION_CONTRACT_VERSION;
|
|
6
6
|
|
|
7
7
|
type ContractParseResult<T> = {
|
|
@@ -94,6 +94,12 @@ type StepRecordResult = {
|
|
|
94
94
|
} | {
|
|
95
95
|
status: "failed";
|
|
96
96
|
error: AblehiErrorDigest;
|
|
97
|
+
} | {
|
|
98
|
+
status: "skipped";
|
|
99
|
+
reason: "run_if_false";
|
|
100
|
+
} | {
|
|
101
|
+
status: "timed_out";
|
|
102
|
+
error: AblehiErrorDigest;
|
|
97
103
|
};
|
|
98
104
|
type StepRecordBody = {
|
|
99
105
|
attempt: number;
|
|
@@ -103,7 +109,7 @@ type StepRecordBody = {
|
|
|
103
109
|
type StepRecordData = {
|
|
104
110
|
flowRunId: string;
|
|
105
111
|
nodeId: string;
|
|
106
|
-
recorded: "
|
|
112
|
+
recorded: StepRecordResult["status"];
|
|
107
113
|
};
|
|
108
114
|
type StepRecordBodyParseResult = {
|
|
109
115
|
ok: true;
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var ee="0.2.8";function u(e){return{ok:!0,value:e}}function r(e){return{ok:!1,reason:e}}function i(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}var qe="/cleanup-state-scopes";function y(e){if(!i(e)||typeof e.kind!="string")return r("context state scope surface shape is invalid");switch(e.kind){case"webhook-trigger":return te(e);case"polling-trigger":return ne(e);case"flow-action":return re(e);default:return r("context state scope kind is invalid")}}function We(e){if(!i(e))return r("cleanup request body must be a JSON object");let t=b(e,["scopes"]);if(t!==void 0)return r(`cleanup request does not accept the "${t}" field`);if(!Array.isArray(e.scopes))return r("cleanup request scopes must be an array");let n=[];for(let o of e.scopes){let s=y(o);if(!s.ok)return s;n.push(s.value)}return u({scopes:n})}function je(e){return!i(e)||typeof e.deleted!="number"||!Number.isSafeInteger(e.deleted)||e.deleted<0?r("cleanup response data surface shape is invalid"):u({deleted:e.deleted})}function te(e){let t=b(e,["kind","workspaceId","triggerInstanceId"]);return t!==void 0?r(`webhook trigger scope does not accept "${t}"`):e.kind!=="webhook-trigger"||!R(e.workspaceId)||!R(e.triggerInstanceId)?r("webhook trigger state scope is invalid"):u({kind:"webhook-trigger",workspaceId:e.workspaceId,triggerInstanceId:e.triggerInstanceId})}function ne(e){let t=b(e,["kind","workspaceId","pollingInstanceId"]);return t!==void 0?r(`polling trigger scope does not accept "${t}"`):e.kind!=="polling-trigger"||!R(e.workspaceId)||!R(e.pollingInstanceId)?r("polling trigger state scope is invalid"):u({kind:"polling-trigger",workspaceId:e.workspaceId,pollingInstanceId:e.pollingInstanceId})}function re(e){let t=b(e,["kind","workspaceId","flowId","nodeId","connectionId"]);if(t!==void 0)return r(`flow action scope does not accept "${t}"`);let n=e.connectionId;return e.kind!=="flow-action"||!R(e.workspaceId)||!R(e.flowId)||!R(e.nodeId)||n!==null&&!R(n)?r("flow action state scope is invalid"):u({kind:"flow-action",workspaceId:e.workspaceId,flowId:e.flowId,nodeId:e.nodeId,connectionId:n})}function R(e){return typeof e=="string"&&e.length>0}function b(e,t){return Object.keys(e).find(n=>!t.includes(n))}var f="/internal/flow-runs",Ye="/:flowRunId/execution-context";function ze(e){return`${f}/${encodeURIComponent(e)}/execution-context`}function oe(e){return!i(e)||!B(e.fileMaxBytes)||!B(e.fileReadMaxBytes)||!B(e.inlineMultipartBytesMax)?r("file runtime limits must carry three positive integer bounds"):u({fileMaxBytes:e.fileMaxBytes,fileReadMaxBytes:e.fileReadMaxBytes,inlineMultipartBytesMax:e.inlineMultipartBytesMax})}function Qe(e){if(!i(e))return r("execution context must be a JSON object");let t=e.compiled;if(typeof e.flowRunId!="string"||typeof e.workspaceId!="string"||!i(e.input)||!i(t)||typeof t.irSchemaVersion!="string"||typeof t.interpreterContractVersion!="string"||typeof t.compiledArtifactId!="string"||!i(t.ir)||!Array.isArray(t.ir.nodes)||!se(e.executionBindings))return r("execution context surface shape is invalid");let n=ie(e.fileRuntime);return n.ok?u({...e,fileRuntime:n.value}):r(n.reason)}function ie(e){if(e===null)return u(null);if(!i(e))return r("fileRuntime must be null or an object");let t=oe(e.limits);return t.ok?u({limits:t.value}):r(t.reason)}function se(e){return Array.isArray(e)?e.every(t=>{if(!i(t))return!1;let n=t.connection,o=y(t.stateScope);return typeof t.nodeId=="string"&&typeof t.toolRef=="string"&&i(t.toolDescriptor)&&i(t.integrationDescriptor)&&i(n)&&typeof n.installationId=="string"&&typeof n.connectionRef=="string"&&typeof n.connectionId=="string"&&typeof n.authProfileRef=="string"&&typeof n.authType=="string"&&o.ok}):!1}function B(e){return typeof e=="number"&&Number.isSafeInteger(e)&&e>0}import{parseAblehiErrorDigest as L}from"@ablehi/error-contract";var rt="/:flowRunId/steps/:nodeId/result",ot="/:flowRunId/result",it="/:flowRunId/event-waits/:nodeId";function st(e,t){return`${f}/${encodeURIComponent(e)}/steps/${encodeURIComponent(t)}/result`}function ut(e){return`${f}/${encodeURIComponent(e)}/result`}function at(e,t){return`${f}/${encodeURIComponent(e)}/event-waits/${encodeURIComponent(t)}`}function ct(e){if(!i(e))return{ok:!1,kind:"validation",reason:"step record body must be a JSON object"};let t=k(e,["attempt","result","durationMs"]);if(t!==void 0)return{ok:!1,kind:"validation",reason:`step record does not accept the "${t}" field`};let n=e.attempt;if(typeof n!="number"||!Number.isInteger(n)||n<=0)return{ok:!1,kind:"validation",reason:"attempt must be a positive integer"};let o=ue(e.result);if(!o.ok)return o;let s={attempt:n,result:o.value};if(e.durationMs!==void 0){let a=e.durationMs;if(typeof a!="number"||!Number.isFinite(a)||a<0)return{ok:!1,kind:"validation",reason:"durationMs must be a non-negative number"};s.durationMs=a}return{ok:!0,value:s}}function ue(e){if(!i(e))return{ok:!1,kind:"step_result_invalid",reason:"result must be a JSON object"};let t=e.status;if(t==="succeeded"){let n=k(e,["status","output"]);return n!==void 0?{ok:!1,kind:"validation",reason:`step record result does not accept the "${n}" field`}:"output"in e?{ok:!0,value:{status:"succeeded",output:e.output}}:{ok:!1,kind:"step_result_invalid",reason:"a succeeded result must carry output"}}if(t==="failed"){let n=k(e,["status","error"]);if(n!==void 0)return{ok:!1,kind:"validation",reason:`step record result does not accept the "${n}" field`};let o=L(e.error);return o.ok?{ok:!0,value:{status:"failed",error:o.value}}:{ok:!1,kind:"step_result_invalid",reason:`a failed result must carry an AblehiErrorDigest: ${o.reason}`}}return{ok:!1,kind:"step_result_invalid",reason:'result status must be "succeeded" or "failed"'}}function dt(e){return!i(e)||typeof e.flowRunId!="string"||typeof e.nodeId!="string"||e.recorded!=="succeeded"&&e.recorded!=="failed"?r("step record data surface shape is invalid"):u({flowRunId:e.flowRunId,nodeId:e.nodeId,recorded:e.recorded})}function lt(e){if(!i(e))return r("result body must be a JSON object");let t=k(e,["status","output","error","composition"]);if(t!==void 0)return r(`result does not accept the "${t}" field`);let n=e.status;if(n!=="succeeded"&&n!=="failed")return r('result status must be "succeeded" or "failed"');let o={status:n};if(e.output!==void 0){if(n!=="succeeded")return r("output is only allowed on a succeeded result");o.output=e.output}if(e.error!==void 0){if(n!=="failed")return r("error is only allowed on a failed result");let s=L(e.error);if(!s.ok)return r(`result error must be an AblehiErrorDigest: ${s.reason}`);o.error=s.value}if(n==="failed"&&o.error===void 0)return r("a failed result must carry an AblehiErrorDigest");if(e.composition!==void 0){if(n!=="succeeded")return r("composition is only allowed on a succeeded result");o.composition=e.composition}return u(o)}function pt(e){return i(e)?u(e):r("flow run result data must be a JSON object")}var ae=/^[A-Za-z0-9_-]{1,100}$/;function gt(e){if(!i(e))return r("register body must be a JSON object");let t=k(e,["eventType","correlationKey"]);if(t!==void 0)return r(`register wait does not accept the "${t}" field`);let n=q(e.eventType);if(!n.ok)return r(n.reason);let o=e.correlationKey;return typeof o!="string"||o.length===0?r("correlationKey must be a non-empty string"):u({eventType:n.value,correlationKey:o})}function ft(e){if(!i(e))return r("complete body must be a JSON object");let t=k(e,["eventType","correlationKey","outcome","eventId"]);if(t!==void 0)return r(`complete wait does not accept the "${t}" field`);let n=e.outcome;if(n!=="received"&&n!=="timed_out")return r('outcome must be "received" or "timed_out"');let o=q(e.eventType);if(!o.ok)return r(o.reason);let s=e.correlationKey;if(typeof s!="string"||s.length===0)return r("correlationKey must be a non-empty string");let a={eventType:o.value,correlationKey:s,outcome:n};if(e.eventId!==void 0){if(typeof e.eventId!="string"||e.eventId.length===0)return r("eventId must be a non-empty string");a.eventId=e.eventId}return u(a)}function Rt(e){return!i(e)||e.registered!==!0?r("register wait data surface shape is invalid"):u({registered:!0})}function q(e){return typeof e!="string"||e.length===0?r("eventType must be a non-empty string"):ae.test(e)?u(e):r("eventType must match ^[A-Za-z0-9_-]{1,100}$")}function k(e,t){return Object.keys(e).find(n=>!t.includes(n))}var ce="/internal/flow-versions",yt="/:flowVersionId/handler-bundles",F="/internal/installations",kt="/:installationId/handler-bundles";function It(e,t){return`${ce}/${encodeURIComponent(e)}/handler-bundles?compiledArtifactId=${encodeURIComponent(t)}`}function _t(e){return`${F}/${encodeURIComponent(e.installationId)}/handler-bundles?workspaceId=${encodeURIComponent(e.workspaceId)}&artifactDigest=${encodeURIComponent(e.artifactDigest)}`}var de=new Set(["managed_only","managed_plus_unmanaged_sdk"]);function C(e){if(!I(e))return H("runtimeNetwork must be a JSON object");let t=e.networkModel;return typeof t!="string"||!de.has(t)?H("runtimeNetwork.networkModel is unknown"):!W(e.apiHosts)||!W(e.authHosts)||typeof e.httpsOnly!="boolean"?H("runtimeNetwork host/https fields are invalid"):{ok:!0,value:{networkModel:t,apiHosts:e.apiHosts,authHosts:e.authHosts,httpsOnly:e.httpsOnly}}}function Et(e){if(!I(e)||typeof e.flowVersionId!="string"||typeof e.compiledArtifactId!="string"||!Array.isArray(e.bundles))return h("handler bundles data surface shape is invalid");let t=j(e.bundles);return t.ok?{ok:!0,value:{flowVersionId:e.flowVersionId,compiledArtifactId:e.compiledArtifactId,bundles:t.value}}:t}function ht(e){if(!I(e)||typeof e.installationId!="string"||typeof e.artifactDigest!="string"||!Array.isArray(e.bundles))return h("tool handler bundles data surface shape is invalid");let t=j(e.bundles);return t.ok?{ok:!0,value:{installationId:e.installationId,artifactDigest:e.artifactDigest,bundles:t.value}}:t}function j(e){let t=[];for(let n of e){let o=le(n);if(!o.ok)return o;t.push(o.value)}return{ok:!0,value:t}}function le(e){if(!I(e)||typeof e.toolRef!="string"||e.kind!=="handler"&&e.kind!=="request")return h("handler bundle entry shape is invalid");if(e.kind==="request"){if(e.module!==void 0)return h("a request bundle must not carry a module");let o=C(e.runtimeNetwork);return o.ok?{ok:!0,value:{toolRef:e.toolRef,kind:"request",runtimeNetwork:o.value}}:o}let t=e.module;if(!I(t)||typeof t.entry!="string"||t.entry.length===0||!pe(t.files))return h("a handler bundle must carry a { entry, files } module");let n=C(e.runtimeNetwork);return n.ok?{ok:!0,value:{toolRef:e.toolRef,kind:"handler",module:{entry:t.entry,files:t.files},runtimeNetwork:n.value}}:n}function h(e){return{ok:!1,kind:"shape",reason:e}}function H(e){return{ok:!1,kind:"runtime_network",reason:e}}function I(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function W(e){return Array.isArray(e)&&e.every(t=>typeof t=="string")}function pe(e){return I(e)&&Object.values(e).every(t=>typeof t=="string")}var x="/internal/webhook-trigger-instances",bt="/:triggerInstanceId/context",Ct="/:triggerInstanceId/handler-bundles",At="/:triggerInstanceId/deliveries/:deliveryId",vt="/:triggerInstanceId/events",Nt="/:triggerInstanceId/rearm",w=e=>`${x}/${encodeURIComponent(e)}`;function Ot(e,t){return`${w(e)}/context?artifactDigest=${encodeURIComponent(t)}`}function Dt(e,t){return`${w(e)}/handler-bundles?artifactDigest=${encodeURIComponent(t)}`}function Ut(e,t){return`${w(e)}/deliveries/${encodeURIComponent(t)}`}function Bt(e){return`${w(e)}/events`}function Ht(e){return`${w(e)}/rearm`}var Ft="/:installationId/webhook-protocol-adapter-bundle";function $t(e){return`${F}/${encodeURIComponent(e.installationId)}/webhook-protocol-adapter-bundle?workspaceId=${encodeURIComponent(e.workspaceId)}&artifactDigest=${encodeURIComponent(e.artifactDigest)}`}var Gt="modules/webhook/protocol-adapter.js";function Mt(e){return`modules/webhook/protocol-adapter-${e}.js`}function Kt(e){let t=i(e)?y(e.stateScope):r("webhook watcher context state scope is invalid");return!i(e)||typeof e.artifactDigest!="string"||typeof e.triggerRef!="string"||typeof e.triggerName!="string"||typeof e.integrationRef!="string"||!i(e.inputs)||e.connection!==null&&!ge(e.connection)||!fe(e.runtime)||!t.ok||t.value.kind!=="webhook-trigger"?r("webhook watcher context surface shape is invalid"):u(e)}function ge(e){return i(e)&&typeof e.connectionId=="string"&&typeof e.connectionRef=="string"&&typeof e.integrationRef=="string"&&typeof e.authProfileRef=="string"&&typeof e.authType=="string"}function fe(e){if(!i(e)||e.type!=="webhook"||typeof e.trigger_ref!="string")return!1;let t=e.webhook;return i(t)&&typeof t.event_handler_module=="string"&&typeof t.enable_handler_module=="string"&&typeof t.disable_handler_module=="string"}function Lt(e){if(!i(e)||typeof e.deliveryId!="string"||typeof e.receivedAt!="string"||!i(e.request))return r("webhook delivery surface shape is invalid");let t=e.request;return t.method!=="POST"||!i(t.headers)||typeof t.rawBody!="string"?r("webhook delivery request shape is invalid"):u(e)}function qt(e){if(!i(e)||typeof e.triggerRef!="string"||typeof e.artifactDigest!="string"||!Array.isArray(e.modules)||!e.modules.every(Re))return{ok:!1,kind:"shape",reason:"trigger handler bundles data surface shape is invalid"};let t=C(e.runtimeNetwork);return t.ok?{ok:!0,value:{triggerRef:e.triggerRef,artifactDigest:e.artifactDigest,modules:e.modules,runtimeNetwork:t.value}}:t}function Re(e){return i(e)&&typeof e.specifier=="string"&&e.specifier.length>0&&typeof e.source=="string"}function Wt(e){if(!i(e))return r("publish events body must be a JSON object");let t=$(e,["deliveryId","events"]);if(t!==void 0)return r(`publish events does not accept the "${t}" field`);let n=e.deliveryId;if(typeof n!="string"||n.length===0)return r("deliveryId must be a non-empty string");let o=e.events;if(!Array.isArray(o))return r("events must be an array");let s=[];for(let a of o){let c=me(a);if(!c.ok)return c;s.push(c.value)}return u({deliveryId:n,events:s})}function me(e){if(!i(e))return r("each event must be a JSON object");let t=$(e,["eventId","occurredAt","dedupeKey","payload"]);if(t!==void 0)return r(`event does not accept the "${t}" field`);let n=e.eventId;if(typeof n!="string"||n.length===0)return r("eventId must be a non-empty string");let o=e.occurredAt;if(typeof o!="string"||o.length===0)return r("occurredAt must be a non-empty string");if(!i(e.payload))return r("event payload must be a JSON object");let s={eventId:n,occurredAt:o,payload:e.payload};if(e.dedupeKey!==void 0){if(typeof e.dedupeKey!="string"||e.dedupeKey.length===0)return r("dedupeKey must be a non-empty string");s.dedupeKey=e.dedupeKey}return u(s)}function jt(e){if(!i(e))return r("rearm body must be a JSON object");let t=$(e,["expectedWatcherInstanceId"]);if(t!==void 0)return r(`rearm does not accept the "${t}" field`);let n=e.expectedWatcherInstanceId;return typeof n!="string"||n.length===0?r("expectedWatcherInstanceId must be a non-empty string"):u({expectedWatcherInstanceId:n})}function $(e,t){return Object.keys(e).find(n=>!t.includes(n))}var T="/internal/polling-trigger-instances",Yt="/:pollingInstanceId/context",zt="/:pollingInstanceId/handler-bundles",Qt="/:pollingInstanceId/ticks/:tickId/events",G=e=>`${T}/${encodeURIComponent(e)}`;function Zt(e,t,n){return`${G(e)}/context?artifactDigest=${encodeURIComponent(t)}&tickId=${encodeURIComponent(n)}`}function en(e,t){return`${G(e)}/handler-bundles?artifactDigest=${encodeURIComponent(t)}`}function tn(e,t){return`${G(e)}/ticks/${encodeURIComponent(t)}/events`}function nn(e){let t=i(e)?y(e.stateScope):r("polling trigger context state scope is invalid");return!i(e)||typeof e.artifactDigest!="string"||typeof e.triggerRef!="string"||typeof e.triggerName!="string"||typeof e.integrationRef!="string"||!i(e.inputs)||e.connection!==null&&!ye(e.connection)||!ke(e.runtime)||!t.ok||t.value.kind!=="polling-trigger"||!Ie(e.tick)||!_e(e.limits)?r("polling trigger context surface shape is invalid"):u(e)}function ye(e){return i(e)&&typeof e.connectionId=="string"&&typeof e.connectionRef=="string"&&typeof e.integrationRef=="string"&&typeof e.authProfileRef=="string"&&typeof e.authType=="string"}function ke(e){if(!i(e)||e.type!=="polling"||typeof e.trigger_id!="string"||typeof e.trigger_ref!="string")return!1;let t=e.polling;if(!i(t)||typeof t.run_handler_module!="string")return!1;let n=t.schedule;if(!i(n)||n.type!=="interval"||typeof n.every_seconds!="number")return!1;let o=t.dedup;return i(o)&&(o.strategy==="cursor"||o.strategy==="hash"||o.strategy==="id_field")}function Ie(e){return i(e)&&typeof e.tickId=="string"&&typeof e.scheduledAt=="string"&&typeof e.attempt=="number"}function _e(e){return i(e)&&typeof e.maxEventsPerTick=="number"}function rn(e){if(!i(e))return r("publish body must be a JSON object");let t=V(e,["events","nextCursor"]);if(t!==void 0)return r(`publish does not accept the "${t}" field`);let n=e.events;if(!Array.isArray(n))return r("events must be an array");let o=[];for(let a of n){let c=Ee(a);if(!c.ok)return c;o.push(c.value)}let s={events:o};if("nextCursor"in e){let a=e.nextCursor;if(a!==null&&typeof a!="string")return r("nextCursor must be a string, null, or omitted");s.nextCursor=a}return u(s)}function Ee(e){if(!i(e))return r("each event must be a JSON object");let t=V(e,["eventId","occurredAt","dedupeKey","payload"]);if(t!==void 0)return r(`event does not accept the "${t}" field`);if(typeof e.eventId!="string"||e.eventId.length===0)return r("event eventId must be a non-empty string");if(!i(e.payload))return r("event payload must be a JSON object");let n={eventId:e.eventId,payload:e.payload};if(e.occurredAt!==void 0){if(typeof e.occurredAt!="string"||e.occurredAt.length===0)return r("event occurredAt must be a non-empty string");n.occurredAt=e.occurredAt}if(e.dedupeKey!==void 0){if(typeof e.dedupeKey!="string"||e.dedupeKey.length===0)return r("event dedupeKey must be a non-empty string");n.dedupeKey=e.dedupeKey}return u(n)}function on(e){return!i(e)||typeof e.tickId!="string"||typeof e.cursorUpdated!="boolean"||!Array.isArray(e.results)||!e.results.every(he)?r("publish polling tick events data surface shape is invalid"):u(e)}function he(e){return i(e)&&typeof e.eventId=="string"&&typeof e.dedupeKey=="string"&&typeof e.duplicate=="boolean"&&(e.flowRunId===null||typeof e.flowRunId=="string")}function V(e,t){return Object.keys(e).find(n=>!t.includes(n))}var J="/internal/egress-grants",M="/internal/tool-invocations",ln="/:flowRunId/egress-grant",pn="/:invocationId/egress-grant",gn="/:pollingInstanceId/egress-grant",fn="/:triggerInstanceId/egress-grant",Rn="/:grantId/consume",mn="/:grantId/audit",yn=e=>`${f}/${encodeURIComponent(e)}/egress-grant`,kn=e=>`${M}/${encodeURIComponent(e)}/egress-grant`,In=e=>`${T}/${encodeURIComponent(e)}/egress-grant`,_n=e=>`${x}/${encodeURIComponent(e)}/egress-grant`,En=e=>`${J}/${encodeURIComponent(e)}/consume`,hn=e=>`${J}/${encodeURIComponent(e)}/audit`,xe=["flow_action","single_tool","polling_trigger","webhook_trigger"],we=/^[A-Za-z0-9][A-Za-z0-9:_+/=.-]{15,1023}$/;function P(e){return typeof e=="string"&&we.test(e)}function Te(e){if(!i(e)||e.body_type!=="multipart")return!1;let t=e.body;if(!i(t))return!1;let n=t.parts;return Array.isArray(n)?n.some(o=>i(o)?o.kind==="file"&&typeof o.file_id=="string"&&o.file_id.length>0:!1):!1}function d(e){return{ok:!1,kind:"shape",reason:e}}function S(){return{ok:!1,kind:"request_digest",reason:"request digest is missing or malformed"}}function v(e,t){if(!i(e))return{ok:!1,reason:"grant request body must be a JSON object"};for(let n of Object.keys(e))if(!t.includes(n))return{ok:!1,reason:`grant request does not accept the "${n}" field`};return{ok:!0,record:e}}function N(e){if(!i(e))return"request must be a JSON object"}function xn(e){let t=v(e,["nodeId","request","requestDigest"]);if(!t.ok)return d(t.reason);let n=t.record.nodeId;if(typeof n!="string"||n.length===0)return d("nodeId is required");let o=N(t.record.request);if(o!==void 0)return d(o);let s=t.record.requestDigest;return P(s)?{ok:!0,value:{nodeId:n,requestDigest:s,requestHasMultipartFiles:Te(t.record.request)}}:S()}function wn(e){let t=v(e,["request","requestDigest"]);if(!t.ok)return d(t.reason);let n=N(t.record.request);if(n!==void 0)return d(n);let o=t.record.requestDigest;return P(o)?{ok:!0,value:{requestDigest:o}}:S()}function Tn(e){let t=v(e,["tickId","request","requestDigest"]);if(!t.ok)return d(t.reason);let n=t.record.tickId;if(typeof n!="string"||n.length===0)return d("tickId is required");let o=N(t.record.request);if(o!==void 0)return d(o);let s=t.record.requestDigest;return P(s)?{ok:!0,value:{tickId:n,requestDigest:s}}:S()}function Pn(e){let t=v(e,["phase","lifecycle","request","requestDigest"]);if(!t.ok)return d(t.reason);let n=t.record.phase;if(n!=="lifecycle"&&n!=="handler")return d('phase must be "lifecycle" or "handler"');let o=t.record.lifecycle,s;if(o!==void 0){if(o!=="enable"&&o!=="disable"&&o!=="renew")return d('lifecycle must be "enable", "disable", or "renew"');s=o}if(n==="lifecycle"&&s===void 0)return d("lifecycle is required for the lifecycle phase");let a=N(t.record.request);if(a!==void 0)return d(a);let c=t.record.requestDigest;return P(c)?{ok:!0,value:{phase:n,...s!==void 0?{lifecycle:s}:{},requestDigest:c}}:S()}function X(e){return xe.includes(e)?e:void 0}var Pe=["scopeKind","scopeId","requestDigest"];function Sn(e){if(!i(e))return d("consume body must be a JSON object");for(let s of Object.keys(e))if(!Pe.includes(s))return d(`consume does not accept the "${s}" field`);let t=X(e.scopeKind);if(t===void 0)return d("scopeKind is invalid");let n=e.scopeId;if(typeof n!="string"||n.length===0)return d("scopeId is required");let o=e.requestDigest;return P(o)?{ok:!0,value:{scopeKind:t,scopeId:n,requestDigest:o}}:S()}var Se=["scopeKind","scopeId","providerHost","status","durationMs","requestBytes","responseBytes","errorCode"];function A(e,t){return typeof e!="number"||!Number.isInteger(e)||e<0?{ok:!1,reason:`${t} must be a non-negative integer`}:{ok:!0,value:e}}function bn(e){if(!i(e))return d("audit body must be a JSON object");for(let p of Object.keys(e))if(!Se.includes(p))return d(`audit does not accept the "${p}" field`);let t=X(e.scopeKind);if(t===void 0)return d("scopeKind is invalid");let n=e.scopeId;if(typeof n!="string"||n.length===0)return d("scopeId is required");let o=e.providerHost;if(typeof o!="string"||o.length===0)return d("providerHost is required");let s=A(e.durationMs,"durationMs");if(!s.ok)return d(s.reason);let a;if(e.status!==void 0){let p=A(e.status,"status");if(!p.ok)return d(p.reason);a=p.value}let c;if(e.requestBytes!==void 0){let p=A(e.requestBytes,"requestBytes");if(!p.ok)return d(p.reason);c=p.value}let l;if(e.responseBytes!==void 0){let p=A(e.responseBytes,"responseBytes");if(!p.ok)return d(p.reason);l=p.value}let U;if(e.errorCode!==void 0){let p=e.errorCode;if(typeof p!="string"||p.length===0)return d("errorCode must be a non-empty string");U=p}return{ok:!0,value:{scopeKind:t,scopeId:n,providerHost:o,...a!==void 0?{status:a}:{},durationMs:s.value,...c!==void 0?{requestBytes:c}:{},...l!==void 0?{responseBytes:l}:{},...U!==void 0?{errorCode:U}:{}}}}function Cn(e){return!i(e)||!i(e.grant)?r("egress grant envelope must carry a grant object"):u(e.grant)}function An(e){return!i(e)||e.consumed!==!0?r("egress grant consume data must carry consumed:true"):u({consumed:!0})}var Hn="/:flowRunId/runtime-credential",Fn="/:invocationId/runtime-credential",$n="/:pollingInstanceId/runtime-credential",Gn="/:triggerInstanceId/runtime-credential",Mn=e=>`${f}/${encodeURIComponent(e)}/runtime-credential`,Kn=e=>`${M}/${encodeURIComponent(e)}/runtime-credential`,Ln=e=>`${T}/${encodeURIComponent(e)}/runtime-credential`,qn=e=>`${x}/${encodeURIComponent(e)}/runtime-credential`,Wn=["flow_action","tool_invoke","polling_trigger","webhook_trigger"];function O(e,t){if(!i(e))return{ok:!1,reason:"runtime credential request body must be a JSON object"};for(let n of Object.keys(e))if(!t.includes(n))return{ok:!1,reason:`runtime credential request does not accept the "${n}" field`};return{ok:!0,record:e}}function jn(e){let t=O(e,["nodeId"]);if(!t.ok)return r(t.reason);let n=t.record.nodeId;return typeof n!="string"||n.length===0?r("nodeId is required"):u({nodeId:n})}function Vn(e){let t=O(e??{},[]);return t.ok?u(null):r(t.reason)}function Jn(e){let t=O(e,["tickId"]);if(!t.ok)return r(t.reason);let n=t.record.tickId;return typeof n!="string"||n.length===0?r("tickId is required"):u({tickId:n})}function Xn(e){let t=O(e,["executionKind","deliveryId","lifecycleOperation"]);if(!t.ok)return r(t.reason);let n=t.record.executionKind;if(n!=="event_handler"&&n!=="lifecycle")return r('executionKind must be "event_handler" or "lifecycle"');let o,s=t.record.deliveryId;if(s!==void 0){if(typeof s!="string"||s.length===0)return r("deliveryId must be a non-empty string");o=s}let a,c=t.record.lifecycleOperation;if(c!==void 0){if(c!=="enable"&&c!=="disable"&&c!=="renew")return r('lifecycleOperation must be "enable", "disable", or "renew"');a=c}return n==="lifecycle"&&a===void 0?r("lifecycleOperation is required for the lifecycle execution kind"):u({executionKind:n,...o!==void 0?{deliveryId:o}:{},...a!==void 0?{lifecycleOperation:a}:{}})}function Yn(e){return!i(e)||typeof e.sessionId!="string"||typeof e.connectionId!="string"||typeof e.authProfileRef!="string"||typeof e.authType!="string"||!i(e.credential)?r("runtime credential session must carry sessionId, connectionId, auth profile facts and a credential object"):u(e.credential)}function D(e){return!i(e)||typeof e.file_id!="string"||typeof e.name!="string"||typeof e.size_bytes!="number"||typeof e.created_at!="string"||typeof e.expires_at!="string"||e.mime_type!==void 0&&typeof e.mime_type!="string"||e.sha256!==void 0&&typeof e.sha256!="string"||e.source!==void 0&&typeof e.source!="string"?r("file ref data does not match the AIS file-ref shape"):u(e)}function K(e){return!i(e)||e.method!=="GET"&&e.method!=="PUT"||typeof e.url!="string"||typeof e.expires_at!="string"||!Ae(e.headers)?r("presigned file URL data is invalid"):u(e)}function be(e){if(!i(e))return r("file upload session data is invalid");let t=D(e.file);if(!t.ok)return r(t.reason);let n=K(e.upload);return n.ok?u({file:t.value,upload:n.value}):r(n.reason)}function Ce(e){if(!i(e))return r("file metadata data is invalid");let t=D(e.file);return t.ok?u({file:t.value}):r(t.reason)}function Ae(e){return i(e)?Object.values(e).every(t=>typeof t=="string"):!1}var _="/internal/files",nr="/upload-session",rr="/:fileId/complete",or="/:fileId/access",ir="/:fileId/stat",sr="/:fileId/content",ur=()=>_,ar=()=>`${_}/upload-session`,cr=e=>`${_}/${encodeURIComponent(e)}/complete`,dr=(e,t)=>`${_}/${encodeURIComponent(e)}/access?intent=${encodeURIComponent(t)}`,Y=e=>`?scope_kind=${encodeURIComponent(e.scopeKind)}&scope_id=${encodeURIComponent(e.scopeId)}`,lr=(e,t)=>`${_}/${encodeURIComponent(e)}/stat${Y(t)}`,pr=(e,t)=>`${_}/${encodeURIComponent(e)}/content${Y(t)}`;function gr(e){if(!i(e))return r("internal file access data is invalid");if(e.intent==="runtime_read"||e.intent==="provider_multipart"){let t=D(e.file);if(!t.ok)return r(t.reason);let n=K(e.access);return n.ok?u({file:t.value,access:n.value,intent:e.intent}):r(n.reason)}return r("internal file access intent is invalid")}var yr="/:flowRunId/human-inputs",kr="/:flowRunId/human-inputs/:requestId",Ir="/:flowRunId/human-inputs/:requestId/expire",_r="/:flowRunId/human-inputs/:requestId/acknowledge",ve=e=>`${f}/${encodeURIComponent(e)}/human-inputs`,z=(e,t)=>`${ve(e)}/${encodeURIComponent(t)}`,Er=(e,t)=>`${z(e,t)}/expire`,hr=(e,t)=>`${z(e,t)}/acknowledge`,Ne="human_input_resolved";function xr(e){return`${Ne}_${e}`}function g(e){return{ok:!1,reason:e}}function m(e,t){return i(e)?{ok:!0,value:e}:g(`${t} must be an object`)}function E(e,t){return typeof e!="string"||e.length===0?g(`${t} must be a non-empty string`):{ok:!0,value:e}}var Oe=/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{1,9})?(?:Z|[+-]\d{2}:\d{2})$/;function De(e,t){return typeof e!="string"||!Oe.test(e)||Number.isNaN(Date.parse(e))?g(`${t} must be an ISO-8601 timestamp`):{ok:!0,value:e}}function Ue(e){let t=m(e,"renderedPrompt");if(!t.ok)return t;let n=E(t.value.title,"renderedPrompt.title");if(!n.ok)return n;let o={title:n.value};if(t.value.body!==void 0){if(typeof t.value.body!="string")return g("renderedPrompt.body must be a string");o.body=t.value.body}if(t.value.format!==void 0){if(t.value.format!=="plain"&&t.value.format!=="markdown")return g("renderedPrompt.format is invalid");o.format=t.value.format}return{ok:!0,value:o}}function Be(e){let t=m(e,"input");if(!t.ok)return t;let n=t.value.kind;if(n==="choice"){if(!Array.isArray(t.value.choices))return g("input.choices must be an array")}else if(n!=="text")if(n==="form"){if(!Array.isArray(t.value.fields))return g("input.fields must be an array")}else return g("input.kind is invalid");return{ok:!0,value:t.value}}function He(e){if(e==null)return{ok:!0,value:void 0};let t=m(e,"partiallyRenderedDelivery");if(!t.ok)return t;let n=t.value.actions;if(n===void 0)return{ok:!0,value:{}};if(!Array.isArray(n))return g("partiallyRenderedDelivery.actions must be an array");let o=[];for(let s of n){let a=m(s,"delivery action");if(!a.ok)return a;let c=E(a.value.id,"delivery action id");if(!c.ok)return c;let l=Q(a.value.inputs,`delivery action '${c.value}' inputs`);if(!l.ok)return l;o.push({id:c.value,inputs:l.value})}return{ok:!0,value:{actions:o}}}function Q(e,t){let n=m(e,t);if(!n.ok)return n;let o={};for(let[s,a]of Object.entries(n.value)){let c=Z(a,`${t}.${s}`);if(!c.ok)return c;o[s]=c.value}return{ok:!0,value:o}}function Z(e,t){let n=m(e,t);if(!n.ok)return n;switch(n.value.kind){case"literal":return{ok:!0,value:{kind:"literal",value:n.value.value}};case"human_input_ref":{let s=E(n.value.path,`${t}.path`);return s.ok?{ok:!0,value:{kind:"human_input_ref",path:s.value}}:s}case"array":{if(!Array.isArray(n.value.items))return g(`${t}.items must be an array`);let s=[];for(let[a,c]of n.value.items.entries()){let l=Z(c,`${t}[${a}]`);if(!l.ok)return l;s.push(l.value)}return{ok:!0,value:{kind:"array",items:s}}}case"object":{let s=Q(n.value.entries,`${t}.entries`);return s.ok?{ok:!0,value:{kind:"object",entries:s.value}}:s}case"template":{if(!Array.isArray(n.value.parts))return g(`${t}.parts must be an array`);let s=[];for(let[a,c]of n.value.parts.entries()){let l=Fe(c,`${t}.parts[${a}]`);if(!l.ok)return l;s.push(l.value)}return{ok:!0,value:{kind:"template",parts:s}}}default:return g(`${t}.kind is invalid`)}}function Fe(e,t){let n=m(e,t);if(!n.ok)return n;let o=n.value.kind;if(o==="literal")return typeof n.value.value!="string"?g(`${t}.value must be a string`):{ok:!0,value:{kind:"literal",value:n.value.value}};if(o==="human_input_ref"){let s=E(n.value.path,`${t}.path`);return s.ok?{ok:!0,value:{kind:"human_input_ref",path:s.value}}:s}return g(`${t}.kind is invalid`)}function wr(e){let t=m(e,"request body");if(!t.ok)return r(t.reason);let n=E(t.value.nodeId,"nodeId");if(!n.ok)return r(n.reason);let o=Ue(t.value.renderedPrompt);if(!o.ok)return r(o.reason);let s=Be(t.value.input);if(!s.ok)return r(s.reason);let a=E(t.value.timeout,"timeout");if(!a.ok)return r(a.reason);let c=De(t.value.expiresAt,"expiresAt");if(!c.ok)return r(c.reason);let l=He(t.value.partiallyRenderedDelivery);return l.ok?u({nodeId:n.value,renderedPrompt:o.value,input:s.value,timeout:a.value,expiresAt:c.value,...l.value!==void 0?{partiallyRenderedDelivery:l.value}:{}}):r(l.reason)}function $e(e){return!i(e)||typeof e.id!="string"||e.id.length===0||typeof e.nodeId!="string"||typeof e.status!="string"||!(e.output===null||i(e.output))?r("human input request view must carry id, nodeId, status and output"):u(e)}function Tr(e){if(!i(e)||typeof e.created!="boolean")return r("human input create data must carry created:boolean");let t=$e(e.request);return t.ok?u({created:e.created,request:t.value}):t}function Pr(e){return!i(e)||e.acknowledged!==!0?r("human input acknowledge data must carry acknowledged:true"):u({acknowledged:!0})}var br="ablehi-wfp-user-runtime-manifest/v1",Cr="unknown";function Ar(e){return e.endsWith(".js")?`${e.slice(0,-3)}.manifest.json`:`${e}.manifest.json`}var Nr="/internal/deployment-handshake",Ge=["start","terminate","send-event","start-webhook-watcher","run-polling-tick","invoke-tool","invoke-trigger-handler","invoke-webhook-protocol-adapter","deployment-handshake"],Or=Ge,Dr="HANDSHAKE_REQUEST_INVALID",Ur="HANDSHAKE_SECRET_UNCONFIGURED",Br="HANDSHAKE_SECRET_MISMATCH",Hr="HANDSHAKE_CONTRACT_VERSION_MISMATCH",Fr="HANDSHAKE_DISPATCH_NAMESPACE_MISMATCH",$r="HANDSHAKE_CAPABILITY_MISSING";function Gr(e){return[e.nonce,e.timestamp,e.contractVersion,e.dispatchNamespace].map(n=>`${n.length}:${n}`).join(".")}function Mr(e){return["response",e.nonce,e.contractVersion,e.dispatchNamespace,...e.capabilities].map(n=>`${n.length}:${n}`).join(".")}export{qe as CONTEXT_STATE_CLEANUP_ROUTE_PATH,Ge as DEPLOYMENT_HANDSHAKE_DISPATCHER_CAPABILITIES,Or as DEPLOYMENT_HANDSHAKE_REQUIRED_CAPABILITIES,Nr as DEPLOYMENT_HANDSHAKE_ROUTE,mn as EGRESS_GRANT_AUDIT_ROUTE_SUBPATH,Rn as EGRESS_GRANT_CONSUME_ROUTE_SUBPATH,xe as EGRESS_GRANT_SCOPE_KINDS,it as EVENT_WAIT_ROUTE_SUBPATH,Ye as EXECUTION_CONTEXT_ROUTE_SUBPATH,or as FILE_ACCESS_ROUTE_SUBPATH,rr as FILE_COMPLETE_ROUTE_SUBPATH,sr as FILE_CONTENT_ROUTE_SUBPATH,ir as FILE_STAT_ROUTE_SUBPATH,nr as FILE_UPLOAD_SESSION_ROUTE_SUBPATH,ln as FLOW_RUN_EGRESS_GRANT_ROUTE_SUBPATH,ot as FLOW_RUN_RESULT_ROUTE_SUBPATH,Hn as FLOW_RUN_RUNTIME_CREDENTIAL_ROUTE_SUBPATH,yt as HANDLER_BUNDLES_ROUTE_SUBPATH,$r as HANDSHAKE_CAPABILITY_MISSING,Hr as HANDSHAKE_CONTRACT_VERSION_MISMATCH,Fr as HANDSHAKE_DISPATCH_NAMESPACE_MISMATCH,Dr as HANDSHAKE_REQUEST_INVALID,Br as HANDSHAKE_SECRET_MISMATCH,Ur as HANDSHAKE_SECRET_UNCONFIGURED,yr as HUMAN_INPUTS_ROUTE_SUBPATH,_r as HUMAN_INPUT_ACKNOWLEDGE_ROUTE_SUBPATH,Ir as HUMAN_INPUT_EXPIRE_ROUTE_SUBPATH,kr as HUMAN_INPUT_REQUEST_ROUTE_SUBPATH,Ne as HUMAN_INPUT_RESOLVED_EVENT_PREFIX,J as INTERNAL_EGRESS_GRANTS_ROUTE_PREFIX,_ as INTERNAL_FILES_ROUTE_PREFIX,f as INTERNAL_FLOW_RUNS_ROUTE_PREFIX,ce as INTERNAL_FLOW_VERSIONS_ROUTE_PREFIX,F as INTERNAL_INSTALLATIONS_ROUTE_PREFIX,T as INTERNAL_POLLING_TRIGGER_INSTANCES_ROUTE_PREFIX,M as INTERNAL_TOOL_INVOCATIONS_ROUTE_PREFIX,x as INTERNAL_WEBHOOK_TRIGGER_INSTANCES_ROUTE_PREFIX,Yt as POLLING_TRIGGER_CONTEXT_ROUTE_SUBPATH,gn as POLLING_TRIGGER_EGRESS_GRANT_ROUTE_SUBPATH,zt as POLLING_TRIGGER_HANDLER_BUNDLES_ROUTE_SUBPATH,$n as POLLING_TRIGGER_RUNTIME_CREDENTIAL_ROUTE_SUBPATH,Qt as POLLING_TRIGGER_TICK_EVENTS_ROUTE_SUBPATH,Wn as RUNTIME_CREDENTIAL_SESSION_SCOPE_KINDS,ee as SERVER_EXECUTION_CONTRACT_VERSION,rt as STEP_RESULT_ROUTE_SUBPATH,kt as TOOL_HANDLER_BUNDLES_ROUTE_SUBPATH,pn as TOOL_INVOCATION_EGRESS_GRANT_ROUTE_SUBPATH,Fn as TOOL_INVOCATION_RUNTIME_CREDENTIAL_ROUTE_SUBPATH,Ft as WEBHOOK_PROTOCOL_ADAPTER_BUNDLE_ROUTE_SUBPATH,Gt as WEBHOOK_PROTOCOL_ADAPTER_MODULE,bt as WEBHOOK_TRIGGER_CONTEXT_ROUTE_SUBPATH,At as WEBHOOK_TRIGGER_DELIVERY_ROUTE_SUBPATH,fn as WEBHOOK_TRIGGER_EGRESS_GRANT_ROUTE_SUBPATH,vt as WEBHOOK_TRIGGER_EVENTS_ROUTE_SUBPATH,Ct as WEBHOOK_TRIGGER_HANDLER_BUNDLES_ROUTE_SUBPATH,Nt as WEBHOOK_TRIGGER_REARM_ROUTE_SUBPATH,Gn as WEBHOOK_TRIGGER_RUNTIME_CREDENTIAL_ROUTE_SUBPATH,br as WFP_USER_RUNTIME_MANIFEST_FORMAT_VERSION,Cr as WFP_USER_RUNTIME_UNKNOWN_SOURCE_REVISION,Gr as deploymentHandshakeProbePayload,Mr as deploymentHandshakeResponseProofPayload,hn as egressGrantAuditPath,En as egressGrantConsumePath,at as eventWaitPath,ze as executionContextPath,yn as flowRunEgressGrantPath,ut as flowRunResultPath,Mn as flowRunRuntimeCredentialPath,Mt as flowScriptProtocolAdapterModuleName,It as handlerBundlesPath,hr as humanInputAcknowledgePath,Er as humanInputExpirePath,z as humanInputRequestPath,xr as humanInputResolvedEventType,ve as humanInputsPath,dr as internalFileAccessPath,cr as internalFileCompletePath,pr as internalFileContentPath,lr as internalFileStatPath,ar as internalFileUploadSessionPath,ur as internalFilesPath,P as isValidRequestDigest,ft as parseCompleteFlowRunWaitBody,We as parseContextStateCleanupRequestBody,je as parseContextStateCleanupResponseData,y as parseContextStateScope,wr as parseCreateHumanInputBody,bn as parseEgressGrantAuditBody,Sn as parseEgressGrantConsumeBody,An as parseEgressGrantConsumeData,Cn as parseEgressGrantData,Qe as parseExecutionContextData,Ce as parseFileMetadataData,D as parseFileRefData,oe as parseFileRuntimeLimits,be as parseFileUploadSessionData,xn as parseFlowActionGrantBody,lt as parseFlowRunResultBody,pt as parseFlowRunResultData,jn as parseFlowRuntimeCredentialBody,le as parseHandlerBundle,Et as parseHandlerBundlesData,Pr as parseHumanInputAcknowledgeData,Tr as parseHumanInputCreateData,$e as parseHumanInputRequestViewData,gr as parseInternalFileAccessData,rn as parsePollingPublishBody,Jn as parsePollingRuntimeCredentialBody,nn as parsePollingTriggerContext,Tn as parsePollingTriggerGrantBody,on as parsePublishPollingTickEventsData,gt as parseRegisterFlowRunWaitBody,Rt as parseRegisterFlowRunWaitData,Yn as parseRuntimeCredentialSessionCredential,C as parseRuntimeNetwork,wn as parseSingleToolGrantBody,Vn as parseSingleToolRuntimeCredentialBody,ct as parseStepRecordBody,dt as parseStepRecordData,ht as parseToolHandlerBundlesData,qt as parseTriggerHandlerBundlesData,Lt as parseWebhookDelivery,Wt as parseWebhookPublishEventsBody,jt as parseWebhookRearmBody,Xn as parseWebhookRuntimeCredentialBody,Pn as parseWebhookTriggerGrantBody,Kt as parseWebhookWatcherContext,Zt as pollingTriggerContextPath,In as pollingTriggerEgressGrantPath,en as pollingTriggerHandlerBundlesPath,Ln as pollingTriggerRuntimeCredentialPath,tn as pollingTriggerTickEventsPath,Te as requestHasMultipartFileParts,st as stepResultPath,_t as toolHandlerBundlesPath,kn as toolInvocationEgressGrantPath,Kn as toolInvocationRuntimeCredentialPath,$t as webhookProtocolAdapterBundlePath,Ot as webhookTriggerContextPath,Ut as webhookTriggerDeliveryPath,_n as webhookTriggerEgressGrantPath,Bt as webhookTriggerEventsPath,Dt as webhookTriggerHandlerBundlesPath,Ht as webhookTriggerRearmPath,qn as webhookTriggerRuntimeCredentialPath,Ar as wfpUserRuntimeManifestPath};
|
|
1
|
+
var ee="0.2.9";function u(e){return{ok:!0,value:e}}function r(e){return{ok:!1,reason:e}}function i(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}var We="/cleanup-state-scopes";function k(e){if(!i(e)||typeof e.kind!="string")return r("context state scope surface shape is invalid");switch(e.kind){case"webhook-trigger":return te(e);case"polling-trigger":return ne(e);case"flow-action":return re(e);default:return r("context state scope kind is invalid")}}function je(e){if(!i(e))return r("cleanup request body must be a JSON object");let t=b(e,["scopes"]);if(t!==void 0)return r(`cleanup request does not accept the "${t}" field`);if(!Array.isArray(e.scopes))return r("cleanup request scopes must be an array");let n=[];for(let o of e.scopes){let s=k(o);if(!s.ok)return s;n.push(s.value)}return u({scopes:n})}function Ve(e){return!i(e)||typeof e.deleted!="number"||!Number.isSafeInteger(e.deleted)||e.deleted<0?r("cleanup response data surface shape is invalid"):u({deleted:e.deleted})}function te(e){let t=b(e,["kind","workspaceId","triggerInstanceId"]);return t!==void 0?r(`webhook trigger scope does not accept "${t}"`):e.kind!=="webhook-trigger"||!R(e.workspaceId)||!R(e.triggerInstanceId)?r("webhook trigger state scope is invalid"):u({kind:"webhook-trigger",workspaceId:e.workspaceId,triggerInstanceId:e.triggerInstanceId})}function ne(e){let t=b(e,["kind","workspaceId","pollingInstanceId"]);return t!==void 0?r(`polling trigger scope does not accept "${t}"`):e.kind!=="polling-trigger"||!R(e.workspaceId)||!R(e.pollingInstanceId)?r("polling trigger state scope is invalid"):u({kind:"polling-trigger",workspaceId:e.workspaceId,pollingInstanceId:e.pollingInstanceId})}function re(e){let t=b(e,["kind","workspaceId","flowId","nodeId","connectionId"]);if(t!==void 0)return r(`flow action scope does not accept "${t}"`);let n=e.connectionId;return e.kind!=="flow-action"||!R(e.workspaceId)||!R(e.flowId)||!R(e.nodeId)||n!==null&&!R(n)?r("flow action state scope is invalid"):u({kind:"flow-action",workspaceId:e.workspaceId,flowId:e.flowId,nodeId:e.nodeId,connectionId:n})}function R(e){return typeof e=="string"&&e.length>0}function b(e,t){return Object.keys(e).find(n=>!t.includes(n))}var g="/internal/flow-runs",ze="/:flowRunId/execution-context";function Qe(e){return`${g}/${encodeURIComponent(e)}/execution-context`}function oe(e){return!i(e)||!B(e.fileMaxBytes)||!B(e.fileReadMaxBytes)||!B(e.inlineMultipartBytesMax)?r("file runtime limits must carry three positive integer bounds"):u({fileMaxBytes:e.fileMaxBytes,fileReadMaxBytes:e.fileReadMaxBytes,inlineMultipartBytesMax:e.inlineMultipartBytesMax})}function Ze(e){if(!i(e))return r("execution context must be a JSON object");let t=e.compiled;if(typeof e.flowRunId!="string"||typeof e.workspaceId!="string"||!i(e.input)||!i(t)||typeof t.irSchemaVersion!="string"||typeof t.interpreterContractVersion!="string"||typeof t.compiledArtifactId!="string"||!i(t.ir)||!Array.isArray(t.ir.nodes)||!se(e.executionBindings))return r("execution context surface shape is invalid");let n=ie(e.fileRuntime);return n.ok?u({...e,fileRuntime:n.value}):r(n.reason)}function ie(e){if(e===null)return u(null);if(!i(e))return r("fileRuntime must be null or an object");let t=oe(e.limits);return t.ok?u({limits:t.value}):r(t.reason)}function se(e){return Array.isArray(e)?e.every(t=>{if(!i(t))return!1;let n=t.connection,o=k(t.stateScope);return typeof t.nodeId=="string"&&typeof t.toolRef=="string"&&i(t.toolDescriptor)&&i(t.integrationDescriptor)&&i(n)&&typeof n.installationId=="string"&&typeof n.connectionRef=="string"&&typeof n.connectionId=="string"&&typeof n.authProfileRef=="string"&&typeof n.authType=="string"&&o.ok}):!1}function B(e){return typeof e=="number"&&Number.isSafeInteger(e)&&e>0}import{parseAblehiErrorDigest as H}from"@ablehi/error-contract";var ot="/:flowRunId/steps/:nodeId/result",it="/:flowRunId/result",st="/:flowRunId/event-waits/:nodeId";function ut(e,t){return`${g}/${encodeURIComponent(e)}/steps/${encodeURIComponent(t)}/result`}function at(e){return`${g}/${encodeURIComponent(e)}/result`}function dt(e,t){return`${g}/${encodeURIComponent(e)}/event-waits/${encodeURIComponent(t)}`}function ct(e){if(!i(e))return{ok:!1,kind:"validation",reason:"step record body must be a JSON object"};let t=m(e,["attempt","result","durationMs"]);if(t!==void 0)return{ok:!1,kind:"validation",reason:`step record does not accept the "${t}" field`};let n=e.attempt;if(typeof n!="number"||!Number.isInteger(n)||n<=0)return{ok:!1,kind:"validation",reason:"attempt must be a positive integer"};let o=ue(e.result);if(!o.ok)return o;let s={attempt:n,result:o.value};if(e.durationMs!==void 0){let a=e.durationMs;if(typeof a!="number"||!Number.isFinite(a)||a<0)return{ok:!1,kind:"validation",reason:"durationMs must be a non-negative number"};s.durationMs=a}return{ok:!0,value:s}}function ue(e){if(!i(e))return{ok:!1,kind:"step_result_invalid",reason:"result must be a JSON object"};let t=e.status;if(t==="succeeded"){let n=m(e,["status","output"]);return n!==void 0?{ok:!1,kind:"validation",reason:`step record result does not accept the "${n}" field`}:"output"in e?{ok:!0,value:{status:"succeeded",output:e.output}}:{ok:!1,kind:"step_result_invalid",reason:"a succeeded result must carry output"}}if(t==="failed"){let n=m(e,["status","error"]);if(n!==void 0)return{ok:!1,kind:"validation",reason:`step record result does not accept the "${n}" field`};let o=H(e.error);return o.ok?{ok:!0,value:{status:"failed",error:o.value}}:{ok:!1,kind:"step_result_invalid",reason:`a failed result must carry an AblehiErrorDigest: ${o.reason}`}}if(t==="skipped"){let n=m(e,["status","reason"]);return n!==void 0?{ok:!1,kind:"validation",reason:`step record result does not accept the "${n}" field`}:e.reason!=="run_if_false"?{ok:!1,kind:"step_result_invalid",reason:'a skipped result reason must be "run_if_false"'}:{ok:!0,value:{status:"skipped",reason:"run_if_false"}}}if(t==="timed_out"){let n=m(e,["status","error"]);if(n!==void 0)return{ok:!1,kind:"validation",reason:`step record result does not accept the "${n}" field`};let o=H(e.error);return o.ok?{ok:!0,value:{status:"timed_out",error:o.value}}:{ok:!1,kind:"step_result_invalid",reason:`a timed_out result must carry an AblehiErrorDigest: ${o.reason}`}}return{ok:!1,kind:"step_result_invalid",reason:'result status must be "succeeded", "failed", "skipped", or "timed_out"'}}function lt(e){return!i(e)||typeof e.flowRunId!="string"||typeof e.nodeId!="string"||!ae(e.recorded)?r("step record data surface shape is invalid"):u({flowRunId:e.flowRunId,nodeId:e.nodeId,recorded:e.recorded})}function ae(e){return e==="succeeded"||e==="failed"||e==="skipped"||e==="timed_out"}function pt(e){if(!i(e))return r("result body must be a JSON object");let t=m(e,["status","output","error","composition"]);if(t!==void 0)return r(`result does not accept the "${t}" field`);let n=e.status;if(n!=="succeeded"&&n!=="failed")return r('result status must be "succeeded" or "failed"');let o={status:n};if(e.output!==void 0){if(n!=="succeeded")return r("output is only allowed on a succeeded result");o.output=e.output}if(e.error!==void 0){if(n!=="failed")return r("error is only allowed on a failed result");let s=H(e.error);if(!s.ok)return r(`result error must be an AblehiErrorDigest: ${s.reason}`);o.error=s.value}if(n==="failed"&&o.error===void 0)return r("a failed result must carry an AblehiErrorDigest");if(e.composition!==void 0){if(n!=="succeeded")return r("composition is only allowed on a succeeded result");o.composition=e.composition}return u(o)}function ft(e){return i(e)?u(e):r("flow run result data must be a JSON object")}var de=/^[A-Za-z0-9_-]{1,100}$/;function gt(e){if(!i(e))return r("register body must be a JSON object");let t=m(e,["eventType","correlationKey"]);if(t!==void 0)return r(`register wait does not accept the "${t}" field`);let n=q(e.eventType);if(!n.ok)return r(n.reason);let o=e.correlationKey;return typeof o!="string"||o.length===0?r("correlationKey must be a non-empty string"):u({eventType:n.value,correlationKey:o})}function Rt(e){if(!i(e))return r("complete body must be a JSON object");let t=m(e,["eventType","correlationKey","outcome","eventId"]);if(t!==void 0)return r(`complete wait does not accept the "${t}" field`);let n=e.outcome;if(n!=="received"&&n!=="timed_out")return r('outcome must be "received" or "timed_out"');let o=q(e.eventType);if(!o.ok)return r(o.reason);let s=e.correlationKey;if(typeof s!="string"||s.length===0)return r("correlationKey must be a non-empty string");let a={eventType:o.value,correlationKey:s,outcome:n};if(e.eventId!==void 0){if(typeof e.eventId!="string"||e.eventId.length===0)return r("eventId must be a non-empty string");a.eventId=e.eventId}return u(a)}function mt(e){return!i(e)||e.registered!==!0?r("register wait data surface shape is invalid"):u({registered:!0})}function q(e){return typeof e!="string"||e.length===0?r("eventType must be a non-empty string"):de.test(e)?u(e):r("eventType must match ^[A-Za-z0-9_-]{1,100}$")}function m(e,t){return Object.keys(e).find(n=>!t.includes(n))}var ce="/internal/flow-versions",kt="/:flowVersionId/handler-bundles",$="/internal/installations",It="/:installationId/handler-bundles";function _t(e,t){return`${ce}/${encodeURIComponent(e)}/handler-bundles?compiledArtifactId=${encodeURIComponent(t)}`}function ht(e){return`${$}/${encodeURIComponent(e.installationId)}/handler-bundles?workspaceId=${encodeURIComponent(e.workspaceId)}&artifactDigest=${encodeURIComponent(e.artifactDigest)}`}var le=new Set(["managed_only","managed_plus_unmanaged_sdk"]);function C(e){if(!I(e))return F("runtimeNetwork must be a JSON object");let t=e.networkModel;return typeof t!="string"||!le.has(t)?F("runtimeNetwork.networkModel is unknown"):!W(e.apiHosts)||!W(e.authHosts)||typeof e.httpsOnly!="boolean"?F("runtimeNetwork host/https fields are invalid"):{ok:!0,value:{networkModel:t,apiHosts:e.apiHosts,authHosts:e.authHosts,httpsOnly:e.httpsOnly}}}function Et(e){if(!I(e)||typeof e.flowVersionId!="string"||typeof e.compiledArtifactId!="string"||!Array.isArray(e.bundles))return E("handler bundles data surface shape is invalid");let t=j(e.bundles);return t.ok?{ok:!0,value:{flowVersionId:e.flowVersionId,compiledArtifactId:e.compiledArtifactId,bundles:t.value}}:t}function wt(e){if(!I(e)||typeof e.installationId!="string"||typeof e.artifactDigest!="string"||!Array.isArray(e.bundles))return E("tool handler bundles data surface shape is invalid");let t=j(e.bundles);return t.ok?{ok:!0,value:{installationId:e.installationId,artifactDigest:e.artifactDigest,bundles:t.value}}:t}function j(e){let t=[];for(let n of e){let o=pe(n);if(!o.ok)return o;t.push(o.value)}return{ok:!0,value:t}}function pe(e){if(!I(e)||typeof e.toolRef!="string"||e.kind!=="handler"&&e.kind!=="request")return E("handler bundle entry shape is invalid");if(e.kind==="request"){if(e.module!==void 0)return E("a request bundle must not carry a module");let o=C(e.runtimeNetwork);return o.ok?{ok:!0,value:{toolRef:e.toolRef,kind:"request",runtimeNetwork:o.value}}:o}let t=e.module;if(!I(t)||typeof t.entry!="string"||t.entry.length===0||!fe(t.files))return E("a handler bundle must carry a { entry, files } module");let n=C(e.runtimeNetwork);return n.ok?{ok:!0,value:{toolRef:e.toolRef,kind:"handler",module:{entry:t.entry,files:t.files},runtimeNetwork:n.value}}:n}function E(e){return{ok:!1,kind:"shape",reason:e}}function F(e){return{ok:!1,kind:"runtime_network",reason:e}}function I(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function W(e){return Array.isArray(e)&&e.every(t=>typeof t=="string")}function fe(e){return I(e)&&Object.values(e).every(t=>typeof t=="string")}var w="/internal/webhook-trigger-instances",Ct="/:triggerInstanceId/context",At="/:triggerInstanceId/handler-bundles",vt="/:triggerInstanceId/deliveries/:deliveryId",Nt="/:triggerInstanceId/events",Ot="/:triggerInstanceId/rearm",x=e=>`${w}/${encodeURIComponent(e)}`;function Dt(e,t){return`${x(e)}/context?artifactDigest=${encodeURIComponent(t)}`}function Ut(e,t){return`${x(e)}/handler-bundles?artifactDigest=${encodeURIComponent(t)}`}function Bt(e,t){return`${x(e)}/deliveries/${encodeURIComponent(t)}`}function Ht(e){return`${x(e)}/events`}function Ft(e){return`${x(e)}/rearm`}var $t="/:installationId/webhook-protocol-adapter-bundle";function Gt(e){return`${$}/${encodeURIComponent(e.installationId)}/webhook-protocol-adapter-bundle?workspaceId=${encodeURIComponent(e.workspaceId)}&artifactDigest=${encodeURIComponent(e.artifactDigest)}`}var Mt="modules/webhook/protocol-adapter.js";function Kt(e){return`modules/webhook/protocol-adapter-${e}.js`}function Lt(e){let t=i(e)?k(e.stateScope):r("webhook watcher context state scope is invalid");return!i(e)||typeof e.artifactDigest!="string"||typeof e.triggerRef!="string"||typeof e.triggerName!="string"||typeof e.integrationRef!="string"||!i(e.inputs)||e.connection!==null&&!ge(e.connection)||!Re(e.runtime)||!t.ok||t.value.kind!=="webhook-trigger"?r("webhook watcher context surface shape is invalid"):u(e)}function ge(e){return i(e)&&typeof e.connectionId=="string"&&typeof e.connectionRef=="string"&&typeof e.integrationRef=="string"&&typeof e.authProfileRef=="string"&&typeof e.authType=="string"}function Re(e){if(!i(e)||e.type!=="webhook"||typeof e.trigger_ref!="string")return!1;let t=e.webhook;return i(t)&&typeof t.event_handler_module=="string"&&typeof t.enable_handler_module=="string"&&typeof t.disable_handler_module=="string"}function qt(e){if(!i(e)||typeof e.deliveryId!="string"||typeof e.receivedAt!="string"||!i(e.request))return r("webhook delivery surface shape is invalid");let t=e.request;return t.method!=="POST"||!i(t.headers)||typeof t.rawBody!="string"?r("webhook delivery request shape is invalid"):u(e)}function Wt(e){if(!i(e)||typeof e.triggerRef!="string"||typeof e.artifactDigest!="string"||!Array.isArray(e.modules)||!e.modules.every(me))return{ok:!1,kind:"shape",reason:"trigger handler bundles data surface shape is invalid"};let t=C(e.runtimeNetwork);return t.ok?{ok:!0,value:{triggerRef:e.triggerRef,artifactDigest:e.artifactDigest,modules:e.modules,runtimeNetwork:t.value}}:t}function me(e){return i(e)&&typeof e.specifier=="string"&&e.specifier.length>0&&typeof e.source=="string"}function jt(e){if(!i(e))return r("publish events body must be a JSON object");let t=G(e,["deliveryId","events"]);if(t!==void 0)return r(`publish events does not accept the "${t}" field`);let n=e.deliveryId;if(typeof n!="string"||n.length===0)return r("deliveryId must be a non-empty string");let o=e.events;if(!Array.isArray(o))return r("events must be an array");let s=[];for(let a of o){let d=ye(a);if(!d.ok)return d;s.push(d.value)}return u({deliveryId:n,events:s})}function ye(e){if(!i(e))return r("each event must be a JSON object");let t=G(e,["eventId","occurredAt","dedupeKey","payload"]);if(t!==void 0)return r(`event does not accept the "${t}" field`);let n=e.eventId;if(typeof n!="string"||n.length===0)return r("eventId must be a non-empty string");let o=e.occurredAt;if(typeof o!="string"||o.length===0)return r("occurredAt must be a non-empty string");if(!i(e.payload))return r("event payload must be a JSON object");let s={eventId:n,occurredAt:o,payload:e.payload};if(e.dedupeKey!==void 0){if(typeof e.dedupeKey!="string"||e.dedupeKey.length===0)return r("dedupeKey must be a non-empty string");s.dedupeKey=e.dedupeKey}return u(s)}function Vt(e){if(!i(e))return r("rearm body must be a JSON object");let t=G(e,["expectedWatcherInstanceId"]);if(t!==void 0)return r(`rearm does not accept the "${t}" field`);let n=e.expectedWatcherInstanceId;return typeof n!="string"||n.length===0?r("expectedWatcherInstanceId must be a non-empty string"):u({expectedWatcherInstanceId:n})}function G(e,t){return Object.keys(e).find(n=>!t.includes(n))}var T="/internal/polling-trigger-instances",zt="/:pollingInstanceId/context",Qt="/:pollingInstanceId/handler-bundles",Zt="/:pollingInstanceId/ticks/:tickId/events",M=e=>`${T}/${encodeURIComponent(e)}`;function en(e,t,n){return`${M(e)}/context?artifactDigest=${encodeURIComponent(t)}&tickId=${encodeURIComponent(n)}`}function tn(e,t){return`${M(e)}/handler-bundles?artifactDigest=${encodeURIComponent(t)}`}function nn(e,t){return`${M(e)}/ticks/${encodeURIComponent(t)}/events`}function rn(e){let t=i(e)?k(e.stateScope):r("polling trigger context state scope is invalid");return!i(e)||typeof e.artifactDigest!="string"||typeof e.triggerRef!="string"||typeof e.triggerName!="string"||typeof e.integrationRef!="string"||!i(e.inputs)||e.connection!==null&&!ke(e.connection)||!Ie(e.runtime)||!t.ok||t.value.kind!=="polling-trigger"||!_e(e.tick)||!he(e.limits)?r("polling trigger context surface shape is invalid"):u(e)}function ke(e){return i(e)&&typeof e.connectionId=="string"&&typeof e.connectionRef=="string"&&typeof e.integrationRef=="string"&&typeof e.authProfileRef=="string"&&typeof e.authType=="string"}function Ie(e){if(!i(e)||e.type!=="polling"||typeof e.trigger_id!="string"||typeof e.trigger_ref!="string")return!1;let t=e.polling;if(!i(t)||typeof t.run_handler_module!="string")return!1;let n=t.schedule;if(!i(n)||n.type!=="interval"||typeof n.every_seconds!="number")return!1;let o=t.dedup;return i(o)&&(o.strategy==="cursor"||o.strategy==="hash"||o.strategy==="id_field")}function _e(e){return i(e)&&typeof e.tickId=="string"&&typeof e.scheduledAt=="string"&&typeof e.attempt=="number"}function he(e){return i(e)&&typeof e.maxEventsPerTick=="number"}function on(e){if(!i(e))return r("publish body must be a JSON object");let t=V(e,["events","nextCursor"]);if(t!==void 0)return r(`publish does not accept the "${t}" field`);let n=e.events;if(!Array.isArray(n))return r("events must be an array");let o=[];for(let a of n){let d=Ee(a);if(!d.ok)return d;o.push(d.value)}let s={events:o};if("nextCursor"in e){let a=e.nextCursor;if(a!==null&&typeof a!="string")return r("nextCursor must be a string, null, or omitted");s.nextCursor=a}return u(s)}function Ee(e){if(!i(e))return r("each event must be a JSON object");let t=V(e,["eventId","occurredAt","dedupeKey","payload"]);if(t!==void 0)return r(`event does not accept the "${t}" field`);if(typeof e.eventId!="string"||e.eventId.length===0)return r("event eventId must be a non-empty string");if(!i(e.payload))return r("event payload must be a JSON object");let n={eventId:e.eventId,payload:e.payload};if(e.occurredAt!==void 0){if(typeof e.occurredAt!="string"||e.occurredAt.length===0)return r("event occurredAt must be a non-empty string");n.occurredAt=e.occurredAt}if(e.dedupeKey!==void 0){if(typeof e.dedupeKey!="string"||e.dedupeKey.length===0)return r("event dedupeKey must be a non-empty string");n.dedupeKey=e.dedupeKey}return u(n)}function sn(e){return!i(e)||typeof e.tickId!="string"||typeof e.cursorUpdated!="boolean"||!Array.isArray(e.results)||!e.results.every(we)?r("publish polling tick events data surface shape is invalid"):u(e)}function we(e){return i(e)&&typeof e.eventId=="string"&&typeof e.dedupeKey=="string"&&typeof e.duplicate=="boolean"&&(e.flowRunId===null||typeof e.flowRunId=="string")}function V(e,t){return Object.keys(e).find(n=>!t.includes(n))}var J="/internal/egress-grants",K="/internal/tool-invocations",pn="/:flowRunId/egress-grant",fn="/:invocationId/egress-grant",gn="/:pollingInstanceId/egress-grant",Rn="/:triggerInstanceId/egress-grant",mn="/:grantId/consume",yn="/:grantId/audit",kn=e=>`${g}/${encodeURIComponent(e)}/egress-grant`,In=e=>`${K}/${encodeURIComponent(e)}/egress-grant`,_n=e=>`${T}/${encodeURIComponent(e)}/egress-grant`,hn=e=>`${w}/${encodeURIComponent(e)}/egress-grant`,En=e=>`${J}/${encodeURIComponent(e)}/consume`,wn=e=>`${J}/${encodeURIComponent(e)}/audit`,xe=["flow_action","single_tool","polling_trigger","webhook_trigger"],Te=/^[A-Za-z0-9][A-Za-z0-9:_+/=.-]{15,1023}$/;function P(e){return typeof e=="string"&&Te.test(e)}function Pe(e){if(!i(e)||e.body_type!=="multipart")return!1;let t=e.body;if(!i(t))return!1;let n=t.parts;return Array.isArray(n)?n.some(o=>i(o)?o.kind==="file"&&typeof o.file_id=="string"&&o.file_id.length>0:!1):!1}function c(e){return{ok:!1,kind:"shape",reason:e}}function S(){return{ok:!1,kind:"request_digest",reason:"request digest is missing or malformed"}}function v(e,t){if(!i(e))return{ok:!1,reason:"grant request body must be a JSON object"};for(let n of Object.keys(e))if(!t.includes(n))return{ok:!1,reason:`grant request does not accept the "${n}" field`};return{ok:!0,record:e}}function N(e){if(!i(e))return"request must be a JSON object"}function xn(e){let t=v(e,["nodeId","request","requestDigest"]);if(!t.ok)return c(t.reason);let n=t.record.nodeId;if(typeof n!="string"||n.length===0)return c("nodeId is required");let o=N(t.record.request);if(o!==void 0)return c(o);let s=t.record.requestDigest;return P(s)?{ok:!0,value:{nodeId:n,requestDigest:s,requestHasMultipartFiles:Pe(t.record.request)}}:S()}function Tn(e){let t=v(e,["request","requestDigest"]);if(!t.ok)return c(t.reason);let n=N(t.record.request);if(n!==void 0)return c(n);let o=t.record.requestDigest;return P(o)?{ok:!0,value:{requestDigest:o}}:S()}function Pn(e){let t=v(e,["tickId","request","requestDigest"]);if(!t.ok)return c(t.reason);let n=t.record.tickId;if(typeof n!="string"||n.length===0)return c("tickId is required");let o=N(t.record.request);if(o!==void 0)return c(o);let s=t.record.requestDigest;return P(s)?{ok:!0,value:{tickId:n,requestDigest:s}}:S()}function Sn(e){let t=v(e,["phase","lifecycle","request","requestDigest"]);if(!t.ok)return c(t.reason);let n=t.record.phase;if(n!=="lifecycle"&&n!=="handler")return c('phase must be "lifecycle" or "handler"');let o=t.record.lifecycle,s;if(o!==void 0){if(o!=="enable"&&o!=="disable"&&o!=="renew")return c('lifecycle must be "enable", "disable", or "renew"');s=o}if(n==="lifecycle"&&s===void 0)return c("lifecycle is required for the lifecycle phase");let a=N(t.record.request);if(a!==void 0)return c(a);let d=t.record.requestDigest;return P(d)?{ok:!0,value:{phase:n,...s!==void 0?{lifecycle:s}:{},requestDigest:d}}:S()}function X(e){return xe.includes(e)?e:void 0}var Se=["scopeKind","scopeId","requestDigest"];function bn(e){if(!i(e))return c("consume body must be a JSON object");for(let s of Object.keys(e))if(!Se.includes(s))return c(`consume does not accept the "${s}" field`);let t=X(e.scopeKind);if(t===void 0)return c("scopeKind is invalid");let n=e.scopeId;if(typeof n!="string"||n.length===0)return c("scopeId is required");let o=e.requestDigest;return P(o)?{ok:!0,value:{scopeKind:t,scopeId:n,requestDigest:o}}:S()}var be=["scopeKind","scopeId","providerHost","status","durationMs","requestBytes","responseBytes","errorCode"];function A(e,t){return typeof e!="number"||!Number.isInteger(e)||e<0?{ok:!1,reason:`${t} must be a non-negative integer`}:{ok:!0,value:e}}function Cn(e){if(!i(e))return c("audit body must be a JSON object");for(let p of Object.keys(e))if(!be.includes(p))return c(`audit does not accept the "${p}" field`);let t=X(e.scopeKind);if(t===void 0)return c("scopeKind is invalid");let n=e.scopeId;if(typeof n!="string"||n.length===0)return c("scopeId is required");let o=e.providerHost;if(typeof o!="string"||o.length===0)return c("providerHost is required");let s=A(e.durationMs,"durationMs");if(!s.ok)return c(s.reason);let a;if(e.status!==void 0){let p=A(e.status,"status");if(!p.ok)return c(p.reason);a=p.value}let d;if(e.requestBytes!==void 0){let p=A(e.requestBytes,"requestBytes");if(!p.ok)return c(p.reason);d=p.value}let l;if(e.responseBytes!==void 0){let p=A(e.responseBytes,"responseBytes");if(!p.ok)return c(p.reason);l=p.value}let U;if(e.errorCode!==void 0){let p=e.errorCode;if(typeof p!="string"||p.length===0)return c("errorCode must be a non-empty string");U=p}return{ok:!0,value:{scopeKind:t,scopeId:n,providerHost:o,...a!==void 0?{status:a}:{},durationMs:s.value,...d!==void 0?{requestBytes:d}:{},...l!==void 0?{responseBytes:l}:{},...U!==void 0?{errorCode:U}:{}}}}function An(e){return!i(e)||!i(e.grant)?r("egress grant envelope must carry a grant object"):u(e.grant)}function vn(e){return!i(e)||e.consumed!==!0?r("egress grant consume data must carry consumed:true"):u({consumed:!0})}var Fn="/:flowRunId/runtime-credential",$n="/:invocationId/runtime-credential",Gn="/:pollingInstanceId/runtime-credential",Mn="/:triggerInstanceId/runtime-credential",Kn=e=>`${g}/${encodeURIComponent(e)}/runtime-credential`,Ln=e=>`${K}/${encodeURIComponent(e)}/runtime-credential`,qn=e=>`${T}/${encodeURIComponent(e)}/runtime-credential`,Wn=e=>`${w}/${encodeURIComponent(e)}/runtime-credential`,jn=["flow_action","tool_invoke","polling_trigger","webhook_trigger"];function O(e,t){if(!i(e))return{ok:!1,reason:"runtime credential request body must be a JSON object"};for(let n of Object.keys(e))if(!t.includes(n))return{ok:!1,reason:`runtime credential request does not accept the "${n}" field`};return{ok:!0,record:e}}function Vn(e){let t=O(e,["nodeId"]);if(!t.ok)return r(t.reason);let n=t.record.nodeId;return typeof n!="string"||n.length===0?r("nodeId is required"):u({nodeId:n})}function Jn(e){let t=O(e??{},[]);return t.ok?u(null):r(t.reason)}function Xn(e){let t=O(e,["tickId"]);if(!t.ok)return r(t.reason);let n=t.record.tickId;return typeof n!="string"||n.length===0?r("tickId is required"):u({tickId:n})}function Yn(e){let t=O(e,["executionKind","deliveryId","lifecycleOperation"]);if(!t.ok)return r(t.reason);let n=t.record.executionKind;if(n!=="event_handler"&&n!=="lifecycle")return r('executionKind must be "event_handler" or "lifecycle"');let o,s=t.record.deliveryId;if(s!==void 0){if(typeof s!="string"||s.length===0)return r("deliveryId must be a non-empty string");o=s}let a,d=t.record.lifecycleOperation;if(d!==void 0){if(d!=="enable"&&d!=="disable"&&d!=="renew")return r('lifecycleOperation must be "enable", "disable", or "renew"');a=d}return n==="lifecycle"&&a===void 0?r("lifecycleOperation is required for the lifecycle execution kind"):u({executionKind:n,...o!==void 0?{deliveryId:o}:{},...a!==void 0?{lifecycleOperation:a}:{}})}function zn(e){return!i(e)||typeof e.sessionId!="string"||typeof e.connectionId!="string"||typeof e.authProfileRef!="string"||typeof e.authType!="string"||!i(e.credential)?r("runtime credential session must carry sessionId, connectionId, auth profile facts and a credential object"):u(e.credential)}function D(e){return!i(e)||typeof e.file_id!="string"||typeof e.name!="string"||typeof e.size_bytes!="number"||typeof e.created_at!="string"||typeof e.expires_at!="string"||e.mime_type!==void 0&&typeof e.mime_type!="string"||e.sha256!==void 0&&typeof e.sha256!="string"||e.source!==void 0&&typeof e.source!="string"?r("file ref data does not match the AIS file-ref shape"):u(e)}function L(e){return!i(e)||e.method!=="GET"&&e.method!=="PUT"||typeof e.url!="string"||typeof e.expires_at!="string"||!ve(e.headers)?r("presigned file URL data is invalid"):u(e)}function Ce(e){if(!i(e))return r("file upload session data is invalid");let t=D(e.file);if(!t.ok)return r(t.reason);let n=L(e.upload);return n.ok?u({file:t.value,upload:n.value}):r(n.reason)}function Ae(e){if(!i(e))return r("file metadata data is invalid");let t=D(e.file);return t.ok?u({file:t.value}):r(t.reason)}function ve(e){return i(e)?Object.values(e).every(t=>typeof t=="string"):!1}var _="/internal/files",rr="/upload-session",or="/:fileId/complete",ir="/:fileId/access",sr="/:fileId/stat",ur="/:fileId/content",ar=()=>_,dr=()=>`${_}/upload-session`,cr=e=>`${_}/${encodeURIComponent(e)}/complete`,lr=(e,t)=>`${_}/${encodeURIComponent(e)}/access?intent=${encodeURIComponent(t)}`,Y=e=>`?scope_kind=${encodeURIComponent(e.scopeKind)}&scope_id=${encodeURIComponent(e.scopeId)}`,pr=(e,t)=>`${_}/${encodeURIComponent(e)}/stat${Y(t)}`,fr=(e,t)=>`${_}/${encodeURIComponent(e)}/content${Y(t)}`;function gr(e){if(!i(e))return r("internal file access data is invalid");if(e.intent==="runtime_read"||e.intent==="provider_multipart"){let t=D(e.file);if(!t.ok)return r(t.reason);let n=L(e.access);return n.ok?u({file:t.value,access:n.value,intent:e.intent}):r(n.reason)}return r("internal file access intent is invalid")}var kr="/:flowRunId/human-inputs",Ir="/:flowRunId/human-inputs/:requestId",_r="/:flowRunId/human-inputs/:requestId/expire",hr="/:flowRunId/human-inputs/:requestId/acknowledge",Ne=e=>`${g}/${encodeURIComponent(e)}/human-inputs`,z=(e,t)=>`${Ne(e)}/${encodeURIComponent(t)}`,Er=(e,t)=>`${z(e,t)}/expire`,wr=(e,t)=>`${z(e,t)}/acknowledge`,Oe="human_input_resolved";function xr(e){return`${Oe}_${e}`}function f(e){return{ok:!1,reason:e}}function y(e,t){return i(e)?{ok:!0,value:e}:f(`${t} must be an object`)}function h(e,t){return typeof e!="string"||e.length===0?f(`${t} must be a non-empty string`):{ok:!0,value:e}}var De=/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{1,9})?(?:Z|[+-]\d{2}:\d{2})$/;function Ue(e,t){return typeof e!="string"||!De.test(e)||Number.isNaN(Date.parse(e))?f(`${t} must be an ISO-8601 timestamp`):{ok:!0,value:e}}function Be(e){let t=y(e,"renderedPrompt");if(!t.ok)return t;let n=h(t.value.title,"renderedPrompt.title");if(!n.ok)return n;let o={title:n.value};if(t.value.body!==void 0){if(typeof t.value.body!="string")return f("renderedPrompt.body must be a string");o.body=t.value.body}if(t.value.format!==void 0){if(t.value.format!=="plain"&&t.value.format!=="markdown")return f("renderedPrompt.format is invalid");o.format=t.value.format}return{ok:!0,value:o}}function He(e){let t=y(e,"input");if(!t.ok)return t;let n=t.value.kind;if(n==="choice"){if(!Array.isArray(t.value.choices))return f("input.choices must be an array")}else if(n!=="text")if(n==="form"){if(!Array.isArray(t.value.fields))return f("input.fields must be an array")}else return f("input.kind is invalid");return{ok:!0,value:t.value}}function Fe(e){if(e==null)return{ok:!0,value:void 0};let t=y(e,"partiallyRenderedDelivery");if(!t.ok)return t;let n=t.value.actions;if(n===void 0)return{ok:!0,value:{}};if(!Array.isArray(n))return f("partiallyRenderedDelivery.actions must be an array");let o=[];for(let s of n){let a=y(s,"delivery action");if(!a.ok)return a;let d=h(a.value.id,"delivery action id");if(!d.ok)return d;let l=Q(a.value.inputs,`delivery action '${d.value}' inputs`);if(!l.ok)return l;o.push({id:d.value,inputs:l.value})}return{ok:!0,value:{actions:o}}}function Q(e,t){let n=y(e,t);if(!n.ok)return n;let o={};for(let[s,a]of Object.entries(n.value)){let d=Z(a,`${t}.${s}`);if(!d.ok)return d;o[s]=d.value}return{ok:!0,value:o}}function Z(e,t){let n=y(e,t);if(!n.ok)return n;switch(n.value.kind){case"literal":return{ok:!0,value:{kind:"literal",value:n.value.value}};case"human_input_ref":{let s=h(n.value.path,`${t}.path`);return s.ok?{ok:!0,value:{kind:"human_input_ref",path:s.value}}:s}case"array":{if(!Array.isArray(n.value.items))return f(`${t}.items must be an array`);let s=[];for(let[a,d]of n.value.items.entries()){let l=Z(d,`${t}[${a}]`);if(!l.ok)return l;s.push(l.value)}return{ok:!0,value:{kind:"array",items:s}}}case"object":{let s=Q(n.value.entries,`${t}.entries`);return s.ok?{ok:!0,value:{kind:"object",entries:s.value}}:s}case"template":{if(!Array.isArray(n.value.parts))return f(`${t}.parts must be an array`);let s=[];for(let[a,d]of n.value.parts.entries()){let l=$e(d,`${t}.parts[${a}]`);if(!l.ok)return l;s.push(l.value)}return{ok:!0,value:{kind:"template",parts:s}}}default:return f(`${t}.kind is invalid`)}}function $e(e,t){let n=y(e,t);if(!n.ok)return n;let o=n.value.kind;if(o==="literal")return typeof n.value.value!="string"?f(`${t}.value must be a string`):{ok:!0,value:{kind:"literal",value:n.value.value}};if(o==="human_input_ref"){let s=h(n.value.path,`${t}.path`);return s.ok?{ok:!0,value:{kind:"human_input_ref",path:s.value}}:s}return f(`${t}.kind is invalid`)}function Tr(e){let t=y(e,"request body");if(!t.ok)return r(t.reason);let n=h(t.value.nodeId,"nodeId");if(!n.ok)return r(n.reason);let o=Be(t.value.renderedPrompt);if(!o.ok)return r(o.reason);let s=He(t.value.input);if(!s.ok)return r(s.reason);let a=h(t.value.timeout,"timeout");if(!a.ok)return r(a.reason);let d=Ue(t.value.expiresAt,"expiresAt");if(!d.ok)return r(d.reason);let l=Fe(t.value.partiallyRenderedDelivery);return l.ok?u({nodeId:n.value,renderedPrompt:o.value,input:s.value,timeout:a.value,expiresAt:d.value,...l.value!==void 0?{partiallyRenderedDelivery:l.value}:{}}):r(l.reason)}function Ge(e){return!i(e)||typeof e.id!="string"||e.id.length===0||typeof e.nodeId!="string"||typeof e.status!="string"||!(e.output===null||i(e.output))?r("human input request view must carry id, nodeId, status and output"):u(e)}function Pr(e){if(!i(e)||typeof e.created!="boolean")return r("human input create data must carry created:boolean");let t=Ge(e.request);return t.ok?u({created:e.created,request:t.value}):t}function Sr(e){return!i(e)||e.acknowledged!==!0?r("human input acknowledge data must carry acknowledged:true"):u({acknowledged:!0})}var Cr="ablehi-wfp-user-runtime-manifest/v1",Ar="unknown";function vr(e){return e.endsWith(".js")?`${e.slice(0,-3)}.manifest.json`:`${e}.manifest.json`}var Or="/internal/deployment-handshake",Me=["start","terminate","send-event","start-webhook-watcher","run-polling-tick","invoke-tool","invoke-trigger-handler","invoke-webhook-protocol-adapter","deployment-handshake"],Dr=Me,Ur="HANDSHAKE_REQUEST_INVALID",Br="HANDSHAKE_SECRET_UNCONFIGURED",Hr="HANDSHAKE_SECRET_MISMATCH",Fr="HANDSHAKE_CONTRACT_VERSION_MISMATCH",$r="HANDSHAKE_DISPATCH_NAMESPACE_MISMATCH",Gr="HANDSHAKE_CAPABILITY_MISSING";function Mr(e){return[e.nonce,e.timestamp,e.contractVersion,e.dispatchNamespace].map(n=>`${n.length}:${n}`).join(".")}function Kr(e){return["response",e.nonce,e.contractVersion,e.dispatchNamespace,...e.capabilities].map(n=>`${n.length}:${n}`).join(".")}export{We as CONTEXT_STATE_CLEANUP_ROUTE_PATH,Me as DEPLOYMENT_HANDSHAKE_DISPATCHER_CAPABILITIES,Dr as DEPLOYMENT_HANDSHAKE_REQUIRED_CAPABILITIES,Or as DEPLOYMENT_HANDSHAKE_ROUTE,yn as EGRESS_GRANT_AUDIT_ROUTE_SUBPATH,mn as EGRESS_GRANT_CONSUME_ROUTE_SUBPATH,xe as EGRESS_GRANT_SCOPE_KINDS,st as EVENT_WAIT_ROUTE_SUBPATH,ze as EXECUTION_CONTEXT_ROUTE_SUBPATH,ir as FILE_ACCESS_ROUTE_SUBPATH,or as FILE_COMPLETE_ROUTE_SUBPATH,ur as FILE_CONTENT_ROUTE_SUBPATH,sr as FILE_STAT_ROUTE_SUBPATH,rr as FILE_UPLOAD_SESSION_ROUTE_SUBPATH,pn as FLOW_RUN_EGRESS_GRANT_ROUTE_SUBPATH,it as FLOW_RUN_RESULT_ROUTE_SUBPATH,Fn as FLOW_RUN_RUNTIME_CREDENTIAL_ROUTE_SUBPATH,kt as HANDLER_BUNDLES_ROUTE_SUBPATH,Gr as HANDSHAKE_CAPABILITY_MISSING,Fr as HANDSHAKE_CONTRACT_VERSION_MISMATCH,$r as HANDSHAKE_DISPATCH_NAMESPACE_MISMATCH,Ur as HANDSHAKE_REQUEST_INVALID,Hr as HANDSHAKE_SECRET_MISMATCH,Br as HANDSHAKE_SECRET_UNCONFIGURED,kr as HUMAN_INPUTS_ROUTE_SUBPATH,hr as HUMAN_INPUT_ACKNOWLEDGE_ROUTE_SUBPATH,_r as HUMAN_INPUT_EXPIRE_ROUTE_SUBPATH,Ir as HUMAN_INPUT_REQUEST_ROUTE_SUBPATH,Oe as HUMAN_INPUT_RESOLVED_EVENT_PREFIX,J as INTERNAL_EGRESS_GRANTS_ROUTE_PREFIX,_ as INTERNAL_FILES_ROUTE_PREFIX,g as INTERNAL_FLOW_RUNS_ROUTE_PREFIX,ce as INTERNAL_FLOW_VERSIONS_ROUTE_PREFIX,$ as INTERNAL_INSTALLATIONS_ROUTE_PREFIX,T as INTERNAL_POLLING_TRIGGER_INSTANCES_ROUTE_PREFIX,K as INTERNAL_TOOL_INVOCATIONS_ROUTE_PREFIX,w as INTERNAL_WEBHOOK_TRIGGER_INSTANCES_ROUTE_PREFIX,zt as POLLING_TRIGGER_CONTEXT_ROUTE_SUBPATH,gn as POLLING_TRIGGER_EGRESS_GRANT_ROUTE_SUBPATH,Qt as POLLING_TRIGGER_HANDLER_BUNDLES_ROUTE_SUBPATH,Gn as POLLING_TRIGGER_RUNTIME_CREDENTIAL_ROUTE_SUBPATH,Zt as POLLING_TRIGGER_TICK_EVENTS_ROUTE_SUBPATH,jn as RUNTIME_CREDENTIAL_SESSION_SCOPE_KINDS,ee as SERVER_EXECUTION_CONTRACT_VERSION,ot as STEP_RESULT_ROUTE_SUBPATH,It as TOOL_HANDLER_BUNDLES_ROUTE_SUBPATH,fn as TOOL_INVOCATION_EGRESS_GRANT_ROUTE_SUBPATH,$n as TOOL_INVOCATION_RUNTIME_CREDENTIAL_ROUTE_SUBPATH,$t as WEBHOOK_PROTOCOL_ADAPTER_BUNDLE_ROUTE_SUBPATH,Mt as WEBHOOK_PROTOCOL_ADAPTER_MODULE,Ct as WEBHOOK_TRIGGER_CONTEXT_ROUTE_SUBPATH,vt as WEBHOOK_TRIGGER_DELIVERY_ROUTE_SUBPATH,Rn as WEBHOOK_TRIGGER_EGRESS_GRANT_ROUTE_SUBPATH,Nt as WEBHOOK_TRIGGER_EVENTS_ROUTE_SUBPATH,At as WEBHOOK_TRIGGER_HANDLER_BUNDLES_ROUTE_SUBPATH,Ot as WEBHOOK_TRIGGER_REARM_ROUTE_SUBPATH,Mn as WEBHOOK_TRIGGER_RUNTIME_CREDENTIAL_ROUTE_SUBPATH,Cr as WFP_USER_RUNTIME_MANIFEST_FORMAT_VERSION,Ar as WFP_USER_RUNTIME_UNKNOWN_SOURCE_REVISION,Mr as deploymentHandshakeProbePayload,Kr as deploymentHandshakeResponseProofPayload,wn as egressGrantAuditPath,En as egressGrantConsumePath,dt as eventWaitPath,Qe as executionContextPath,kn as flowRunEgressGrantPath,at as flowRunResultPath,Kn as flowRunRuntimeCredentialPath,Kt as flowScriptProtocolAdapterModuleName,_t as handlerBundlesPath,wr as humanInputAcknowledgePath,Er as humanInputExpirePath,z as humanInputRequestPath,xr as humanInputResolvedEventType,Ne as humanInputsPath,lr as internalFileAccessPath,cr as internalFileCompletePath,fr as internalFileContentPath,pr as internalFileStatPath,dr as internalFileUploadSessionPath,ar as internalFilesPath,P as isValidRequestDigest,Rt as parseCompleteFlowRunWaitBody,je as parseContextStateCleanupRequestBody,Ve as parseContextStateCleanupResponseData,k as parseContextStateScope,Tr as parseCreateHumanInputBody,Cn as parseEgressGrantAuditBody,bn as parseEgressGrantConsumeBody,vn as parseEgressGrantConsumeData,An as parseEgressGrantData,Ze as parseExecutionContextData,Ae as parseFileMetadataData,D as parseFileRefData,oe as parseFileRuntimeLimits,Ce as parseFileUploadSessionData,xn as parseFlowActionGrantBody,pt as parseFlowRunResultBody,ft as parseFlowRunResultData,Vn as parseFlowRuntimeCredentialBody,pe as parseHandlerBundle,Et as parseHandlerBundlesData,Sr as parseHumanInputAcknowledgeData,Pr as parseHumanInputCreateData,Ge as parseHumanInputRequestViewData,gr as parseInternalFileAccessData,on as parsePollingPublishBody,Xn as parsePollingRuntimeCredentialBody,rn as parsePollingTriggerContext,Pn as parsePollingTriggerGrantBody,sn as parsePublishPollingTickEventsData,gt as parseRegisterFlowRunWaitBody,mt as parseRegisterFlowRunWaitData,zn as parseRuntimeCredentialSessionCredential,C as parseRuntimeNetwork,Tn as parseSingleToolGrantBody,Jn as parseSingleToolRuntimeCredentialBody,ct as parseStepRecordBody,lt as parseStepRecordData,wt as parseToolHandlerBundlesData,Wt as parseTriggerHandlerBundlesData,qt as parseWebhookDelivery,jt as parseWebhookPublishEventsBody,Vt as parseWebhookRearmBody,Yn as parseWebhookRuntimeCredentialBody,Sn as parseWebhookTriggerGrantBody,Lt as parseWebhookWatcherContext,en as pollingTriggerContextPath,_n as pollingTriggerEgressGrantPath,tn as pollingTriggerHandlerBundlesPath,qn as pollingTriggerRuntimeCredentialPath,nn as pollingTriggerTickEventsPath,Pe as requestHasMultipartFileParts,ut as stepResultPath,ht as toolHandlerBundlesPath,In as toolInvocationEgressGrantPath,Ln as toolInvocationRuntimeCredentialPath,Gt as webhookProtocolAdapterBundlePath,Dt as webhookTriggerContextPath,Bt as webhookTriggerDeliveryPath,hn as webhookTriggerEgressGrantPath,Ht as webhookTriggerEventsPath,Ut as webhookTriggerHandlerBundlesPath,Ft as webhookTriggerRearmPath,Wn as webhookTriggerRuntimeCredentialPath,vr as wfpUserRuntimeManifestPath};
|