@lostgradient/weft 0.2.1 → 0.3.0
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/README.md +47 -22
- package/dist/cli/generated/operation-client.generated.d.ts +28 -1
- package/dist/cli/generated/operation-client.generated.js +2 -0
- package/dist/cli-main.js +79 -79
- package/dist/client/handle-delegation.d.ts +4 -0
- package/dist/client/handle-delegation.js +6 -0
- package/dist/client/http-client-requests.d.ts +2 -0
- package/dist/client/http-client-requests.js +3 -0
- package/dist/client/http-client.d.ts +4 -1
- package/dist/client/http-client.js +9 -1
- package/dist/client/interface.d.ts +57 -2
- package/dist/client/local.d.ts +4 -1
- package/dist/client/local.js +7 -0
- package/dist/client/start-body.d.ts +7 -1
- package/dist/client/start-body.js +13 -4
- package/dist/core/codec/extension-codec.js +4 -2
- package/dist/core/codec/index.d.ts +1 -0
- package/dist/core/codec/index.js +1 -0
- package/dist/core/codec/serializer-registry.d.ts +122 -0
- package/dist/core/codec/serializer-registry.js +51 -0
- package/dist/core/context/index.d.ts +9 -0
- package/dist/core/context/internals.d.ts +9 -0
- package/dist/core/context/internals.js +3 -0
- package/dist/core/context/run-operation.d.ts +16 -3
- package/dist/core/context/run-operation.js +16 -7
- package/dist/core/engine/bulk-operations.js +1 -1
- package/dist/core/engine/construction.d.ts +0 -1
- package/dist/core/engine/construction.js +10 -1
- package/dist/core/engine/disposal.js +12 -0
- package/dist/core/engine/engine-create-types.d.ts +0 -14
- package/dist/core/engine/engine-internal-types.d.ts +12 -0
- package/dist/core/engine/engine-leak-warnings.d.ts +6 -0
- package/dist/core/engine/engine-leak-warnings.js +4 -0
- package/dist/core/engine/engine-runtime-helpers.d.ts +17 -0
- package/dist/core/engine/engine-runtime-helpers.js +26 -5
- package/dist/core/engine/errors.d.ts +74 -0
- package/dist/core/engine/errors.js +25 -1
- package/dist/core/engine/handle-result.js +1 -1
- package/dist/core/engine/handles.d.ts +89 -40
- package/dist/core/engine/handles.js +25 -27
- package/dist/core/engine/index.d.ts +96 -4
- package/dist/core/engine/index.js +75 -4
- package/dist/core/engine/inline-launch-queue.d.ts +14 -0
- package/dist/core/engine/inline-launch-queue.js +32 -7
- package/dist/core/engine/internals.d.ts +18 -10
- package/dist/core/engine/lifecycle/fork-helpers.js +1 -7
- package/dist/core/engine/lifecycle/persist.js +5 -20
- package/dist/core/engine/lifecycle/resume.js +25 -4
- package/dist/core/engine/lifecycle/start-commit.d.ts +47 -0
- package/dist/core/engine/lifecycle/start-commit.js +27 -0
- package/dist/core/engine/lifecycle/start-exec.d.ts +30 -2
- package/dist/core/engine/lifecycle/start-exec.js +38 -0
- package/dist/core/engine/lifecycle/start-or-signal-resolution.d.ts +79 -0
- package/dist/core/engine/lifecycle/start-or-signal-resolution.js +60 -0
- package/dist/core/engine/lifecycle/start-or-signal.d.ts +45 -0
- package/dist/core/engine/lifecycle/start-or-signal.js +141 -0
- package/dist/core/engine/lifecycle/start.d.ts +3 -3
- package/dist/core/engine/lifecycle/start.js +31 -37
- package/dist/core/engine/lifecycle.d.ts +3 -2
- package/dist/core/engine/lifecycle.js +9 -2
- package/dist/core/engine/listing.js +1 -1
- package/dist/core/engine/persisted-data-version.d.ts +5 -9
- package/dist/core/engine/persisted-data-version.js +4 -5
- package/dist/core/engine/schedule-handle.d.ts +45 -0
- package/dist/core/engine/schedule-handle.js +26 -0
- package/dist/core/engine/schedules.d.ts +1 -1
- package/dist/core/engine/schedules.js +7 -3
- package/dist/core/engine/second-instance-detector.d.ts +96 -0
- package/dist/core/engine/second-instance-detector.js +108 -0
- package/dist/core/engine/signals.d.ts +22 -0
- package/dist/core/engine/signals.js +15 -0
- package/dist/core/engine/termination/cleanup.d.ts +25 -0
- package/dist/core/engine/termination/cleanup.js +19 -1
- package/dist/core/engine/termination/complete.js +4 -3
- package/dist/core/engine/termination/suspend.d.ts +68 -0
- package/dist/core/engine/termination/suspend.js +41 -0
- package/dist/core/engine/termination.d.ts +4 -2
- package/dist/core/engine/termination.js +2 -0
- package/dist/core/engine/validation.js +25 -1
- package/dist/core/engine/workflow-feed.d.ts +5 -3
- package/dist/core/events/event-map.d.ts +2 -1
- package/dist/core/events/workflow-events.d.ts +23 -0
- package/dist/core/events/workflow-events.js +9 -0
- package/dist/core/list-filter-validation.js +2 -1
- package/dist/core/start-workflow-validation.d.ts +22 -0
- package/dist/core/start-workflow-validation.js +11 -1
- package/dist/core/step-context.d.ts +10 -6
- package/dist/core/step-context.js +7 -15
- package/dist/core/types/activity.d.ts +6 -3
- package/dist/core/types/identity.d.ts +8 -1
- package/dist/core/types/launch-metadata.d.ts +33 -0
- package/dist/core/types/launch-metadata.js +0 -0
- package/dist/core/types/message-handles.d.ts +25 -0
- package/dist/core/types/options.d.ts +48 -54
- package/dist/core/types/reviews.d.ts +2 -1
- package/dist/core/types/services-resolution.d.ts +47 -0
- package/dist/core/types/services-resolution.js +0 -0
- package/dist/core/types/state.d.ts +11 -11
- package/dist/core/types/workflow-builder.d.ts +5 -4
- package/dist/core/types/workflow-function.d.ts +17 -0
- package/dist/core/types/workflow-snapshot.d.ts +29 -0
- package/dist/core/types/workflow-snapshot.js +0 -0
- package/dist/core/types.d.ts +3 -0
- package/dist/core/types.js +3 -0
- package/dist/core/weft-error.d.ts +1 -1
- package/dist/core/weft-error.js +3 -1
- package/dist/diagnostics/doctor.js +6 -3
- package/dist/diagnostics/format.js +2 -2
- package/dist/diagnostics/types.d.ts +1 -0
- package/dist/diagnostics/version-check.js +6 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.js +10 -1
- package/dist/json-schema.js +1 -1
- package/dist/mcp/cli.js +35 -35
- package/dist/mcp/list-filter.js +2 -1
- package/dist/mcp/session.js +1 -0
- package/dist/observability/index.js +2 -2
- package/dist/server/handler.js +30 -30
- package/dist/server/index.js +33 -33
- package/dist/server/interactive-operations.js +1 -0
- package/dist/server/operations/resume-workflow.js +2 -2
- package/dist/server/operations/start-or-signal-workflow.d.ts +39 -0
- package/dist/server/operations/start-or-signal-workflow.js +140 -0
- package/dist/server/operations/start-workflow-options.d.ts +32 -0
- package/dist/server/operations/start-workflow-options.js +63 -0
- package/dist/server/operations/start-workflow.js +7 -69
- package/dist/server/operations/suspend-workflow.d.ts +13 -0
- package/dist/server/operations/suspend-workflow.js +36 -0
- package/dist/server/rest-binding.d.ts +18 -7
- package/dist/server/rest-bindings.js +12 -0
- package/dist/server/runtime/task-dispatch.js +5 -3
- package/dist/server/runtime/task-polling.d.ts +16 -2
- package/dist/server/runtime/task-polling.js +20 -5
- package/dist/server/runtime/websocket-worker.js +8 -0
- package/dist/server/serve-internals.d.ts +8 -0
- package/dist/server/serve-internals.js +4 -2
- package/dist/server/task-state.d.ts +8 -0
- package/dist/service-worker/index.js +28 -28
- package/dist/storage/capabilities.d.ts +10 -2
- package/dist/storage/capabilities.js +2 -2
- package/dist/storage/http.js +2 -2
- package/dist/storage/index.d.ts +6 -1
- package/dist/storage/indexeddb.js +1 -1
- package/dist/storage/interface.d.ts +26 -0
- package/dist/storage/interface.js +1 -1
- package/dist/storage/key-prefixes.d.ts +1 -1
- package/dist/storage/key-prefixes.js +2 -0
- package/dist/storage/lmdb.js +1 -1
- package/dist/storage/memory.js +1 -1
- package/dist/storage/neon-value-mapping.d.ts +47 -0
- package/dist/storage/neon-value-mapping.js +11 -0
- package/dist/storage/neon.d.ts +108 -0
- package/dist/storage/neon.js +10 -0
- package/dist/storage/node-sqlite-loader.d.ts +71 -0
- package/dist/storage/node-sqlite-loader.js +41 -0
- package/dist/storage/node-sqlite.d.ts +1 -19
- package/dist/storage/node-sqlite.js +38 -32
- package/dist/storage/postgres-key-value-queries.d.ts +79 -0
- package/dist/storage/postgres-key-value-queries.js +63 -0
- package/dist/storage/resolve.d.ts +2 -165
- package/dist/storage/resolve.js +1 -1
- package/dist/storage/scoped-storage.js +1 -1
- package/dist/storage/storage-configuration.d.ts +209 -0
- package/dist/storage/storage-configuration.js +0 -0
- package/dist/storage/text-value-store.d.ts +9 -9
- package/dist/storage/turso.js +2 -2
- package/dist/storage/typed-storage.js +1 -1
- package/dist/storage/web-extension.js +1 -1
- package/dist/testing/index.js +33 -33
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/worker/index.js +9 -5
- package/dist/worker/long-poll.js +4 -0
- package/dist/worker/protocol-messages.d.ts +20 -0
- package/dist/worker/protocol-schemas.d.ts +32 -0
- package/dist/worker/protocol-schemas.js +8 -4
- package/dist/worker/protocol-task-result.d.ts +28 -0
- package/dist/worker/protocol-task-result.js +76 -0
- package/dist/worker/protocol.d.ts +4 -15
- package/dist/worker/protocol.js +1 -1
- package/dist/worker/registry/fair-share.d.ts +29 -0
- package/dist/worker/registry/fair-share.js +30 -0
- package/dist/worker/registry/routing.d.ts +18 -0
- package/dist/worker/registry/routing.js +14 -0
- package/dist/worker/registry/types.d.ts +7 -0
- package/dist/worker/registry.d.ts +16 -1
- package/dist/worker/registry.js +24 -36
- package/package.json +17 -4
package/dist/mcp/list-filter.js
CHANGED
package/dist/mcp/session.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
var OS=Object.defineProperty;var PS=(S)=>S;function bS(S,$){this[S]=PS.bind(null,$)}var eS=(S,$)=>{for(var G in $)OS(S,G,{get:$[G],enumerable:!0,configurable:!0,set:bS.bind($,G)})};var Q=(S,$)=>()=>(S&&($=S(S=0)),$);var m,d,i,n;var o=Q(()=>{m=class m extends Event{static type="activity:started";operationId;workflowId;activityName;attempt;constructor(S,$,G,K){super(m.type);this.operationId=S,this.workflowId=$,this.activityName=G,this.attempt=K}};d=class d extends Event{static type="activity:completed";operationId;workflowId;activityName;duration;constructor(S,$,G,K){super(d.type);this.operationId=S,this.workflowId=$,this.activityName=G,this.duration=K}};i=class i extends Event{static type="activity:async-pending";token;operationId;workflowId;activityName;attempt;constructor(S,$,G,K,L){super(i.type);this.token=S,this.operationId=$,this.workflowId=G,this.activityName=K,this.attempt=L}};n=class n extends Event{static type="activity:failed";operationId;workflowId;activityName;error;attempt;constructor(S,$,G,K,L){super(n.type);this.operationId=S,this.workflowId=$,this.activityName=G,this.error=K,this.attempt=L}}});var l;var r=Q(()=>{l=class l extends Event{static type="attributes:changed";workflowId;changes;constructor(S,$){super(l.type);this.workflowId=S,this.changes=$}}});var s,a;var t=Q(()=>{s=class s extends Event{static type="signal:received";workflowId;signalName;payload;constructor(S,$,G){super(s.type);this.workflowId=S,this.signalName=$,this.payload=G}};a=class a extends Event{static type="signal:delivered";workflowId;signalName;constructor(S,$){super(a.type);this.workflowId=S,this.signalName=$}}});var e,SS,$S,GS,KS,LS,xS;var WS=Q(()=>{e=class e extends Event{static type="checkpoint:size-warning";workflowId;sizeBytes;step;constructor(S,$,G){super(e.type);this.workflowId=S,this.sizeBytes=$,this.step=G}};SS=class SS extends Event{static type="development:warning";workflowId;message;fieldPaths;constructor(S,$,G){super(SS.type);this.workflowId=S,this.message=$,this.fieldPaths=G}};$S=class $S extends Event{static type="cleanup:warning";source;error;workflowId;constructor(S,$,G){super($S.type);this.source=S,this.error=$,this.workflowId=G}};GS=class GS extends Event{static type="storage:size-reported";sizeBytes;constructor(S){super(GS.type);this.sizeBytes=S}};KS=class KS extends Event{static type="alert:fired";metric;threshold;currentValue;window;constructor(S,$,G,K){super(KS.type);this.metric=S,this.threshold=$,this.currentValue=G,this.window=K}};LS=class LS extends Event{static type="alert:resolved";metric;threshold;currentValue;window;constructor(S,$,G,K){super(LS.type);this.metric=S,this.threshold=$,this.currentValue=G,this.window=K}};xS=class xS extends Event{static type="constraint:violated";workflowId;constraintName;scope;onViolation;constructor(S,$,G,K){super(xS.type);this.workflowId=S,this.constraintName=$,this.scope=G,this.onViolation=K}}});var XS,TS;var JS=Q(()=>{XS=class XS extends Event{static type="update:received";updateId;workflowId;name;payload;constructor(S,$,G,K){super(XS.type);this.updateId=S,this.workflowId=$,this.name=G,this.payload=K}};TS=class TS extends Event{static type="update:completed";updateId;workflowId;name;result;error;constructor(S,$,G,K,L){super(TS.type);this.updateId=S,this.workflowId=$,this.name=G,this.result=K,this.error=L}}});var QS,j,q,H,Y,B0,jS,qS;var HS=Q(()=>{QS=class QS extends Event{static type="workflow:started";workflowId;workflowType;input;constructor(S,$,G){super(QS.type);this.workflowId=S,this.workflowType=$,this.input=G}};j=class j extends Event{static type="workflow:completed";workflowId;result;duration;constructor(S,$,G){super(j.type);this.workflowId=S,this.result=$,this.duration=G}};q=class q extends Event{static type="workflow:failed";workflowId;error;constructor(S,$){super(q.type);this.workflowId=S,this.error=$}};H=class H extends Event{static type="workflow:cancelled";workflowId;constructor(S){super(H.type);this.workflowId=S}};Y=class Y extends Event{static type="workflow:timed-out";workflowId;timeoutType;elapsed;reason;constructor(S,$,G,K){super(Y.type);if(this.workflowId=S,this.timeoutType=$,this.elapsed=G,K!==void 0)this.reason=K}};B0=new Set([j.type,q.type,H.type,Y.type]);jS=class jS extends Event{static type="workflow:resumed";workflowId;fromStep;constructor(S,$){super(jS.type);this.workflowId=S,this.fromStep=$}};qS=class qS extends Event{static type="workflow:recovery-skipped";workflowId;workflowType;reason;constructor(S,$,G){super(qS.type);this.workflowId=S,this.workflowType=$,this.reason=G}}});var YS=Q(()=>{o();r();t();WS();JS();HS()});var ZS=Q(()=>{YS()});var DS={traceId:"0".repeat(32),spanId:"0".repeat(16),traceFlags:0},P={setAttribute(){},setStatus(){},recordException(){},end(){},spanContext(){return DS}},z={setAttribute:(...S)=>P.setAttribute(...S),setStatus:(...S)=>P.setStatus(...S),recordException:(...S)=>P.recordException(...S),end:(...S)=>P.end(...S)},US={startSpan(){return P}},V={record(){},add(){}},_S={createHistogram(){return V},createCounter(){return V},createUpDownCounter(){return V}},yS=Symbol("ROOT_CONTEXT"),RS={trace:{getTracer(){return US},setSpan(S){return S}},metrics:{getMeter(){return _S}},context:{ROOT_CONTEXT:yS,with(S,$){return $()}},SpanStatusCode:{OK:1,ERROR:2,UNSET:0}},M;function AS(){let S=globalThis.require;if(typeof S==="function")return($)=>S($);return()=>{return}}function VS(S){return S?.trace?.getTracer!=null&&S.SpanStatusCode!=null}function fS(S=AS()){try{let $=S("@opentelemetry/api");if(VS($))return $}catch{}return}function k(S){if(M)return M;let $=fS(S);if($)return M=$,M;return M=RS,M}function I(S){let $=new Uint8Array(S);return crypto.getRandomValues($),Array.from($,(G)=>G.toString(16).padStart(2,"0")).join("")}var N="traceparent",CS=/^([0-9a-f]{2})-([0-9a-f]{32})-([0-9a-f]{16})-([0-9a-f]{2})$/,zS="00000000000000000000000000000000",IS="0000000000000000";function p(S){let $=CS.exec(S);if(!$)return null;let[,G,K,L,W]=$;if(K===zS)return null;if(L===IS)return null;return{version:G,traceId:K,spanId:L,traceFlags:parseInt(W,16)}}function g(S){let $=S.traceFlags.toString(16).padStart(2,"0");return`${S.version}-${S.traceId}-${S.spanId}-${$}`}function b(S){let $=S.get(N);if(!$)return null;return p($)}function f(S,$){S.set(N,g($))}function NS(){return I(16)}function pS(){return I(8)}var u=1024;function w(S,$){let G;try{G=JSON.stringify(S)}catch{G=String(S)}if(G.length>$)return G.slice(0,$)+"...";return G}function gS(S){return S instanceof Error?S.message:String(S)}function uS(S){return S instanceof Error?S:Error(String(S))}function D(S,$){let G=S.spanContext();f($,{version:"00",traceId:G.traceId,spanId:G.spanId,traceFlags:G.traceFlags})}function B(S,$,G){let K=S.attributeExtractor;if(!K)return;let L=K(G);for(let[W,X]of Object.entries(L))$.setAttribute(W,X)}function U(S,$){let G=S.workflowSpans.get($);return G?S.trace.setSpan(S.api.context.ROOT_CONTEXT,G.span):S.api.context.ROOT_CONTEXT}function C(S,$,G){$.setStatus({code:S.SpanStatusCode.ERROR,message:gS(G)}),$.recordException(uS(G))}function h(S,$,G,K){try{let L=G();return $.setStatus({code:S.SpanStatusCode.OK}),K?.(L),L}catch(L){throw C(S,$,L),L}finally{$.end()}}async function _(S,$,G,K){try{let L=await G();return $.setStatus({code:S.SpanStatusCode.OK}),K?.(L),L}catch(L){throw C(S,$,L),L}finally{$.end()}}function*y(S,$,G,K){try{let L=yield*G();return $.setStatus({code:S.SpanStatusCode.OK}),K?.(L),L}catch(L){throw C(S,$,L),L}finally{$.end()}}function E(S){return{async execute($,G){let K=b($.headers),L=S.api.context.ROOT_CONTEXT;if(K){let X={...z,spanContext(){return{traceId:K.traceId,spanId:K.spanId,traceFlags:K.traceFlags}}};L=S.trace.setSpan(S.api.context.ROOT_CONTEXT,X)}let W=S.tracer.startSpan(`activity:execute:${$.activityName}`,{attributes:{"weft.activity.name":$.activityName,"weft.activity.attempt":$.attempt,...K?{"weft.parent.trace_id":K.traceId}:{}}},L);if(S.recordPayloads&&$.input!==void 0)W.setAttribute("weft.payload.input",w($.input,S.maxPayloadSize));return _(S,W,()=>G($))}}}var F={workflowDuration:{name:"weft.workflow.duration",description:"Duration of workflow execution in milliseconds",unit:"ms",type:"histogram"},activityDuration:{name:"weft.activity.duration",description:"Duration of activity execution in milliseconds",unit:"ms",type:"histogram"},activityAttempts:{name:"weft.activity.attempts",description:"Total activity execution attempts",unit:"attempts",type:"counter"},workflowActive:{name:"weft.workflow.active",description:"Number of currently active workflows",unit:"workflows",type:"gauge"},workflowStarted:{name:"weft.workflow.started",description:"Total workflows started",unit:"workflows",type:"counter"},workflowCompleted:{name:"weft.workflow.completed",description:"Total workflows completed",unit:"workflows",type:"counter"},workflowFailed:{name:"weft.workflow.failed",description:"Total workflows failed",unit:"workflows",type:"counter"},promptCacheHits:{name:"weft.prompt_cache.hits",description:"Total prompt prefix cache hits",unit:"hits",type:"counter"},promptCacheMisses:{name:"weft.prompt_cache.misses",description:"Total prompt prefix cache misses",unit:"misses",type:"counter"},dpmoDefects:{name:"weft.dpmo.defects",description:"Total failed workflows (DPMO numerator)",unit:"workflows",type:"counter"},dpmoOperations:{name:"weft.dpmo.operations",description:"Total started workflows (DPMO denominator)",unit:"workflows",type:"counter"},taskBacklog:{name:"weft.task.backlog",description:"Number of queued tasks waiting for workers",unit:"tasks",type:"gauge"},taskQueueLatency:{name:"weft.task.queue_latency",description:"Time tasks spend queued before dispatch in milliseconds",unit:"ms",type:"histogram"},taskExecutionLatency:{name:"weft.task.execution_latency",description:"Time tasks spend executing after worker start in milliseconds",unit:"ms",type:"histogram"},taskRetries:{name:"weft.task.retries",description:"Total task retry attempts after the first dispatch attempt",unit:"retries",type:"counter"},taskRequeues:{name:"weft.task.requeues",description:"Total visibility-timeout or disconnect task requeues",unit:"requeues",type:"counter"},taskStaleHeartbeats:{name:"weft.task.stale_heartbeats",description:"Number of in-flight tasks whose heartbeat age exceeds the diagnostic threshold",unit:"tasks",type:"gauge"},workerCapacitySaturation:{name:"weft.worker.capacity_saturation",description:"Ratio of in-flight worker slots to total worker concurrency",unit:"ratio",type:"gauge"}};var hS=1e4;class v{#S;#G=0;#$=0;constructor(S){this.#S=new Float64Array(S)}push(S){if(this.#S[this.#G]=S,this.#G=(this.#G+1)%this.#S.length,this.#$<this.#S.length)this.#$++}toArray(){if(this.#$<this.#S.length)return Array.from(this.#S.subarray(0,this.#$));let S=Array.from({length:this.#$});for(let $=0;$<this.#$;$++)S[$]=this.#S[(this.#G+$)%this.#S.length];return S}}class R{#S;#G;#$;constructor(){this.#S=new Map,this.#G=new Map,this.#$=new Map}increment(S,$=1){this.#S.set(S,(this.#S.get(S)??0)+$)}record(S,$){let G=this.#G.get(S);if(!G)G=new v(hS),this.#G.set(S,G);G.push($)}gauge(S,$){this.#$.set(S,$)}snapshot(){let S={};for(let[$,G]of this.#S)S[$]={type:"counter",value:G};for(let[$,G]of this.#G){let K=G.toArray(),L=vS(K);S[$]={type:"histogram",count:K.length,sum:cS(K),p50:L[Math.floor(L.length*0.5)]??0,p99:L[Math.floor(L.length*0.99)]??0,min:L[0]??0,max:L[L.length-1]??0}}for(let[$,G]of this.#$)S[$]={type:"gauge",value:G};return S}reset(){this.#S.clear(),this.#G.clear(),this.#$.clear()}}function ES(S){let $;if(typeof S==="string")$=k().metrics.getMeter(S);else if(S)$=S;else $=k().metrics.getMeter("weft");return{workflowDuration:$.createHistogram("weft.workflow.duration",{unit:"ms"}),activityDuration:$.createHistogram("weft.activity.duration",{unit:"ms"}),activityAttempts:$.createCounter("weft.activity.attempts"),activeWorkflows:$.createUpDownCounter("weft.workflow.active")}}function vS(S){let $=[...S];return $.sort((G,K)=>G-K),$}function cS(S){let $=0;for(let G of S)$+=G;return $}function mS(S,$){let G=$?.type==="histogram"?$.count:0,K=$?.type==="histogram"?$.sum:0;return[`# TYPE ${S} histogram`,`${S}_count ${G}`,`${S}_sum ${K}`]}function dS(S,$){let G=$?.type==="counter"?$.value:0;return[`# TYPE ${S} counter`,`${S}_total ${G}`]}function iS(S,$){let G=$?.type==="gauge"?$.value:0;return[`# TYPE ${S} gauge`,`${S} ${G}`]}var nS={histogram:mS,counter:dS,gauge:iS};function oS(S,$){let G=S.name.replace(/\./g,"_"),K=$[S.name];return[`# HELP ${G} ${S.description}`,...nS[S.type](G,K)]}function lS(S){let $=S[F.dpmoDefects.name],G=S[F.dpmoOperations.name],K=$?.type==="counter"?$.value:0,L=G?.type==="counter"?G.value:0,W=L===0?0:K*1e6/L,X="weft_dpmo";return["# HELP weft_dpmo Defects per million operations (failed workflows / started workflows * 1e6)","# TYPE weft_dpmo gauge",`weft_dpmo ${W}`]}function c(S){let $=[];for(let G of Object.values(F))$.push(...oS(G,S));return $.push(...lS(S)),$.join(`
|
|
2
|
+
var DS=Object.defineProperty;var US=(S)=>S;function _S(S,$){this[S]=US.bind(null,$)}var S0=(S,$)=>{for(var G in $)DS(S,G,{get:$[G],enumerable:!0,configurable:!0,set:_S.bind($,G)})};var W=(S,$)=>()=>(S&&($=S(S=0)),$);var m,d,i,n;var o=W(()=>{m=class m extends Event{static type="activity:started";operationId;workflowId;activityName;attempt;constructor(S,$,G,K){super(m.type);this.operationId=S,this.workflowId=$,this.activityName=G,this.attempt=K}};d=class d extends Event{static type="activity:completed";operationId;workflowId;activityName;duration;constructor(S,$,G,K){super(d.type);this.operationId=S,this.workflowId=$,this.activityName=G,this.duration=K}};i=class i extends Event{static type="activity:async-pending";token;operationId;workflowId;activityName;attempt;constructor(S,$,G,K,L){super(i.type);this.token=S,this.operationId=$,this.workflowId=G,this.activityName=K,this.attempt=L}};n=class n extends Event{static type="activity:failed";operationId;workflowId;activityName;error;attempt;constructor(S,$,G,K,L){super(n.type);this.operationId=S,this.workflowId=$,this.activityName=G,this.error=K,this.attempt=L}}});var l;var r=W(()=>{l=class l extends Event{static type="attributes:changed";workflowId;changes;constructor(S,$){super(l.type);this.workflowId=S,this.changes=$}}});var s,a;var t=W(()=>{s=class s extends Event{static type="signal:received";workflowId;signalName;payload;constructor(S,$,G){super(s.type);this.workflowId=S,this.signalName=$,this.payload=G}};a=class a extends Event{static type="signal:delivered";workflowId;signalName;constructor(S,$){super(a.type);this.workflowId=S,this.signalName=$}}});var e,SS,$S,GS,KS,LS,xS;var XS=W(()=>{e=class e extends Event{static type="checkpoint:size-warning";workflowId;sizeBytes;step;constructor(S,$,G){super(e.type);this.workflowId=S,this.sizeBytes=$,this.step=G}};SS=class SS extends Event{static type="development:warning";workflowId;message;fieldPaths;constructor(S,$,G){super(SS.type);this.workflowId=S,this.message=$,this.fieldPaths=G}};$S=class $S extends Event{static type="cleanup:warning";source;error;workflowId;constructor(S,$,G){super($S.type);this.source=S,this.error=$,this.workflowId=G}};GS=class GS extends Event{static type="storage:size-reported";sizeBytes;constructor(S){super(GS.type);this.sizeBytes=S}};KS=class KS extends Event{static type="alert:fired";metric;threshold;currentValue;window;constructor(S,$,G,K){super(KS.type);this.metric=S,this.threshold=$,this.currentValue=G,this.window=K}};LS=class LS extends Event{static type="alert:resolved";metric;threshold;currentValue;window;constructor(S,$,G,K){super(LS.type);this.metric=S,this.threshold=$,this.currentValue=G,this.window=K}};xS=class xS extends Event{static type="constraint:violated";workflowId;constraintName;scope;onViolation;constructor(S,$,G,K){super(xS.type);this.workflowId=S,this.constraintName=$,this.scope=G,this.onViolation=K}}});var TS,JS;var QS=W(()=>{TS=class TS extends Event{static type="update:received";updateId;workflowId;name;payload;constructor(S,$,G,K){super(TS.type);this.updateId=S,this.workflowId=$,this.name=G,this.payload=K}};JS=class JS extends Event{static type="update:completed";updateId;workflowId;name;result;error;constructor(S,$,G,K,L){super(JS.type);this.updateId=S,this.workflowId=$,this.name=G,this.result=K,this.error=L}}});var WS,j,q,H,Y,P0,jS,qS,HS;var YS=W(()=>{WS=class WS extends Event{static type="workflow:started";workflowId;workflowType;input;constructor(S,$,G){super(WS.type);this.workflowId=S,this.workflowType=$,this.input=G}};j=class j extends Event{static type="workflow:completed";workflowId;result;duration;constructor(S,$,G){super(j.type);this.workflowId=S,this.result=$,this.duration=G}};q=class q extends Event{static type="workflow:failed";workflowId;error;constructor(S,$){super(q.type);this.workflowId=S,this.error=$}};H=class H extends Event{static type="workflow:cancelled";workflowId;constructor(S){super(H.type);this.workflowId=S}};Y=class Y extends Event{static type="workflow:timed-out";workflowId;timeoutType;elapsed;reason;constructor(S,$,G,K){super(Y.type);if(this.workflowId=S,this.timeoutType=$,this.elapsed=G,K!==void 0)this.reason=K}};P0=new Set([j.type,q.type,H.type,Y.type]);jS=class jS extends Event{static type="workflow:resumed";workflowId;fromStep;constructor(S,$){super(jS.type);this.workflowId=S,this.fromStep=$}};qS=class qS extends Event{static type="workflow:suspended";workflowId;constructor(S){super(qS.type);this.workflowId=S}};HS=class HS extends Event{static type="workflow:recovery-skipped";workflowId;workflowType;reason;constructor(S,$,G){super(HS.type);this.workflowId=S,this.workflowType=$,this.reason=G}}});var ZS=W(()=>{o();r();t();XS();QS();YS()});var MS=W(()=>{ZS()});var kS={traceId:"0".repeat(32),spanId:"0".repeat(16),traceFlags:0},D={setAttribute(){},setStatus(){},recordException(){},end(){},spanContext(){return kS}},f={setAttribute:(...S)=>D.setAttribute(...S),setStatus:(...S)=>D.setStatus(...S),recordException:(...S)=>D.recordException(...S),end:(...S)=>D.end(...S)},yS={startSpan(){return D}},V={record(){},add(){}},RS={createHistogram(){return V},createCounter(){return V},createUpDownCounter(){return V}},wS=Symbol("ROOT_CONTEXT"),AS={trace:{getTracer(){return yS},setSpan(S){return S}},metrics:{getMeter(){return RS}},context:{ROOT_CONTEXT:wS,with(S,$){return $()}},SpanStatusCode:{OK:1,ERROR:2,UNSET:0}},M;function VS(){let S=globalThis.require;if(typeof S==="function")return($)=>S($);return()=>{return}}function CS(S){return S?.trace?.getTracer!=null&&S.SpanStatusCode!=null}function zS(S=VS()){try{let $=S("@opentelemetry/api");if(CS($))return $}catch{}return}function B(S){if(M)return M;let $=zS(S);if($)return M=$,M;return M=AS,M}function I(S){let $=new Uint8Array(S);return crypto.getRandomValues($),Array.from($,(G)=>G.toString(16).padStart(2,"0")).join("")}var N="traceparent",fS=/^([0-9a-f]{2})-([0-9a-f]{32})-([0-9a-f]{16})-([0-9a-f]{2})$/,IS="00000000000000000000000000000000",NS="0000000000000000";function p(S){let $=fS.exec(S);if(!$)return null;let[,G,K,L,X]=$;if(K===IS)return null;if(L===NS)return null;return{version:G,traceId:K,spanId:L,traceFlags:parseInt(X,16)}}function g(S){let $=S.traceFlags.toString(16).padStart(2,"0");return`${S.version}-${S.traceId}-${S.spanId}-${$}`}function U(S){let $=S.get(N);if(!$)return null;return p($)}function C(S,$){S.set(N,g($))}function pS(){return I(16)}function gS(){return I(8)}var u=1024;function F(S,$){let G;try{G=JSON.stringify(S)}catch{G=String(S)}if(G.length>$)return G.slice(0,$)+"...";return G}function uS(S){return S instanceof Error?S.message:String(S)}function hS(S){return S instanceof Error?S:Error(String(S))}function _(S,$){let G=S.spanContext();C($,{version:"00",traceId:G.traceId,spanId:G.spanId,traceFlags:G.traceFlags})}function O(S,$,G){let K=S.attributeExtractor;if(!K)return;let L=K(G);for(let[X,T]of Object.entries(L))$.setAttribute(X,T)}function k(S,$){let G=S.workflowSpans.get($);return G?S.trace.setSpan(S.api.context.ROOT_CONTEXT,G.span):S.api.context.ROOT_CONTEXT}function z(S,$,G){$.setStatus({code:S.SpanStatusCode.ERROR,message:uS(G)}),$.recordException(hS(G))}function h(S,$,G,K){try{let L=G();return $.setStatus({code:S.SpanStatusCode.OK}),K?.(L),L}catch(L){throw z(S,$,L),L}finally{$.end()}}async function y(S,$,G,K){try{let L=await G();return $.setStatus({code:S.SpanStatusCode.OK}),K?.(L),L}catch(L){throw z(S,$,L),L}finally{$.end()}}function*R(S,$,G,K){try{let L=yield*G();return $.setStatus({code:S.SpanStatusCode.OK}),K?.(L),L}catch(L){throw z(S,$,L),L}finally{$.end()}}function E(S){return{async execute($,G){let K=U($.headers),L=S.api.context.ROOT_CONTEXT;if(K){let T={...f,spanContext(){return{traceId:K.traceId,spanId:K.spanId,traceFlags:K.traceFlags}}};L=S.trace.setSpan(S.api.context.ROOT_CONTEXT,T)}let X=S.tracer.startSpan(`activity:execute:${$.activityName}`,{attributes:{"weft.activity.name":$.activityName,"weft.activity.attempt":$.attempt,...K?{"weft.parent.trace_id":K.traceId}:{}}},L);if(S.recordPayloads&&$.input!==void 0)X.setAttribute("weft.payload.input",F($.input,S.maxPayloadSize));return y(S,X,()=>G($))}}}var P={workflowDuration:{name:"weft.workflow.duration",description:"Duration of workflow execution in milliseconds",unit:"ms",type:"histogram"},activityDuration:{name:"weft.activity.duration",description:"Duration of activity execution in milliseconds",unit:"ms",type:"histogram"},activityAttempts:{name:"weft.activity.attempts",description:"Total activity execution attempts",unit:"attempts",type:"counter"},workflowActive:{name:"weft.workflow.active",description:"Number of currently active workflows",unit:"workflows",type:"gauge"},workflowStarted:{name:"weft.workflow.started",description:"Total workflows started",unit:"workflows",type:"counter"},workflowCompleted:{name:"weft.workflow.completed",description:"Total workflows completed",unit:"workflows",type:"counter"},workflowFailed:{name:"weft.workflow.failed",description:"Total workflows failed",unit:"workflows",type:"counter"},promptCacheHits:{name:"weft.prompt_cache.hits",description:"Total prompt prefix cache hits",unit:"hits",type:"counter"},promptCacheMisses:{name:"weft.prompt_cache.misses",description:"Total prompt prefix cache misses",unit:"misses",type:"counter"},dpmoDefects:{name:"weft.dpmo.defects",description:"Total failed workflows (DPMO numerator)",unit:"workflows",type:"counter"},dpmoOperations:{name:"weft.dpmo.operations",description:"Total started workflows (DPMO denominator)",unit:"workflows",type:"counter"},taskBacklog:{name:"weft.task.backlog",description:"Number of queued tasks waiting for workers",unit:"tasks",type:"gauge"},taskQueueLatency:{name:"weft.task.queue_latency",description:"Time tasks spend queued before dispatch in milliseconds",unit:"ms",type:"histogram"},taskExecutionLatency:{name:"weft.task.execution_latency",description:"Time tasks spend executing after worker start in milliseconds",unit:"ms",type:"histogram"},taskRetries:{name:"weft.task.retries",description:"Total task retry attempts after the first dispatch attempt",unit:"retries",type:"counter"},taskRequeues:{name:"weft.task.requeues",description:"Total visibility-timeout or disconnect task requeues",unit:"requeues",type:"counter"},taskStaleHeartbeats:{name:"weft.task.stale_heartbeats",description:"Number of in-flight tasks whose heartbeat age exceeds the diagnostic threshold",unit:"tasks",type:"gauge"},workerCapacitySaturation:{name:"weft.worker.capacity_saturation",description:"Ratio of in-flight worker slots to total worker concurrency",unit:"ratio",type:"gauge"}};var ES=1e4;class v{#S;#G=0;#$=0;constructor(S){this.#S=new Float64Array(S)}push(S){if(this.#S[this.#G]=S,this.#G=(this.#G+1)%this.#S.length,this.#$<this.#S.length)this.#$++}toArray(){if(this.#$<this.#S.length)return Array.from(this.#S.subarray(0,this.#$));let S=Array.from({length:this.#$});for(let $=0;$<this.#$;$++)S[$]=this.#S[(this.#G+$)%this.#S.length];return S}}class w{#S;#G;#$;constructor(){this.#S=new Map,this.#G=new Map,this.#$=new Map}increment(S,$=1){this.#S.set(S,(this.#S.get(S)??0)+$)}record(S,$){let G=this.#G.get(S);if(!G)G=new v(ES),this.#G.set(S,G);G.push($)}gauge(S,$){this.#$.set(S,$)}snapshot(){let S={};for(let[$,G]of this.#S)S[$]={type:"counter",value:G};for(let[$,G]of this.#G){let K=G.toArray(),L=cS(K);S[$]={type:"histogram",count:K.length,sum:mS(K),p50:L[Math.floor(L.length*0.5)]??0,p99:L[Math.floor(L.length*0.99)]??0,min:L[0]??0,max:L[L.length-1]??0}}for(let[$,G]of this.#$)S[$]={type:"gauge",value:G};return S}reset(){this.#S.clear(),this.#G.clear(),this.#$.clear()}}function vS(S){let $;if(typeof S==="string")$=B().metrics.getMeter(S);else if(S)$=S;else $=B().metrics.getMeter("weft");return{workflowDuration:$.createHistogram("weft.workflow.duration",{unit:"ms"}),activityDuration:$.createHistogram("weft.activity.duration",{unit:"ms"}),activityAttempts:$.createCounter("weft.activity.attempts"),activeWorkflows:$.createUpDownCounter("weft.workflow.active")}}function cS(S){let $=[...S];return $.sort((G,K)=>G-K),$}function mS(S){let $=0;for(let G of S)$+=G;return $}function dS(S,$){let G=$?.type==="histogram"?$.count:0,K=$?.type==="histogram"?$.sum:0;return[`# TYPE ${S} histogram`,`${S}_count ${G}`,`${S}_sum ${K}`]}function iS(S,$){let G=$?.type==="counter"?$.value:0;return[`# TYPE ${S} counter`,`${S}_total ${G}`]}function nS(S,$){let G=$?.type==="gauge"?$.value:0;return[`# TYPE ${S} gauge`,`${S} ${G}`]}var oS={histogram:dS,counter:iS,gauge:nS};function lS(S,$){let G=S.name.replace(/\./g,"_"),K=$[S.name];return[`# HELP ${G} ${S.description}`,...oS[S.type](G,K)]}function rS(S){let $=S[P.dpmoDefects.name],G=S[P.dpmoOperations.name],K=$?.type==="counter"?$.value:0,L=G?.type==="counter"?G.value:0,X=L===0?0:K*1e6/L,T="weft_dpmo";return["# HELP weft_dpmo Defects per million operations (failed workflows / started workflows * 1e6)","# TYPE weft_dpmo gauge",`weft_dpmo ${X}`]}function c(S){let $=[];for(let G of Object.values(P))$.push(...lS(G,S));return $.push(...rS(S)),$.join(`
|
|
3
3
|
`)+`
|
|
4
|
-
`}function
|
|
4
|
+
`}function sS(S){return{serialize(){let $=S?.snapshot()??{};return c($)}}}MS();var aS=3600000,BS=1e4,tS=3600000;function FS(S){let $=Date.now();for(let[G,K]of S.workflowSpans)if($-K.createdAt>aS)K.span.end(),S.workflowSpans.delete(G);if(S.workflowSpans.size>BS){let G=S.workflowSpans.size-BS,K=0;for(let[L,X]of S.workflowSpans){if(K>=G)break;X.span.end(),S.workflowSpans.delete(L),K++}}}function OS(S,$){let G=S.workflowSpans.get($);if(G)G.span.end(),S.workflowSpans.delete($)}function PS(S){function $(x,Z,J){let Q=S.workflowSpans.get(x);if(!Q)return;if(Z==="error")Q.span.setStatus({code:S.SpanStatusCode.ERROR,...J?{message:J}:{}});else Q.span.setStatus({code:S.SpanStatusCode.OK});Q.span.end(),S.workflowSpans.delete(x)}let G=(x)=>{if(!(x instanceof j))return;$(x.workflowId,"ok")},K=(x)=>{if(!(x instanceof q))return;$(x.workflowId,"error",x.error.message),S.metrics.increment("weft.dpmo.defects")},L=(x)=>{if(!(x instanceof H))return;$(x.workflowId,"error","Workflow cancelled")},X=(x)=>{if(!(x instanceof Y))return;$(x.workflowId,"error",`Workflow timed out (${x.timeoutType}) after ${x.elapsed}ms`),S.metrics.increment("weft.dpmo.defects")};if(S.eventTarget)S.eventTarget.addEventListener(j.type,G),S.eventTarget.addEventListener(q.type,K),S.eventTarget.addEventListener(H.type,L),S.eventTarget.addEventListener(Y.type,X);function T(x=tS){let Z=Date.now()-x,J=0;for(let[Q,b]of S.workflowSpans)if(b.createdAt<=Z)b.span.setStatus({code:S.SpanStatusCode.ERROR,message:"span evicted (stale)"}),b.span.end(),S.workflowSpans.delete(Q),J++;return J}function A(){if(S.eventTarget)S.eventTarget.removeEventListener(j.type,G),S.eventTarget.removeEventListener(q.type,K),S.eventTarget.removeEventListener(H.type,L),S.eventTarget.removeEventListener(Y.type,X);for(let x of S.workflowSpans.values())x.span.setStatus({code:S.SpanStatusCode.ERROR,message:"Observability disposed"}),x.span.end();S.workflowSpans.clear()}return{endWorkflowSpan:$,evictStaleSpans:T,dispose:A}}function bS(S){return{workflowStart($,G){FS(S);let K=S.workflowSpans.get($.workflowId);if(K)K.span.setStatus({code:S.SpanStatusCode.OK}),OS(S,$.workflowId);let L=S.tracer.startSpan(`workflow:${$.workflowType}`,{attributes:{"weft.workflow.id":$.workflowId,"weft.workflow.type":$.workflowType}});if(S.workflowSpans.set($.workflowId,{span:L,createdAt:Date.now()}),_(L,$.headers),S.recordPayloads&&$.input!==void 0)L.setAttribute("weft.payload.input",F($.input,S.maxPayloadSize));O(S,L,$),S.metrics.increment("weft.workflow.started"),S.metrics.increment("weft.dpmo.operations"),G($)},*activity($,G){let K=S.tracer.startSpan(`activity:${$.activityName}`,{attributes:{"weft.activity.name":$.activityName,"weft.activity.attempt":$.attempt}},k(S,$.workflowId));if(_(K,$.headers),S.recordPayloads&&$.input!==void 0)K.setAttribute("weft.payload.input",F($.input,S.maxPayloadSize));O(S,K,$);let L=Date.now();return yield*R(S,K,()=>G($),()=>{S.metrics.record("weft.activity.duration",Date.now()-L),S.metrics.increment("weft.activity.attempts")})},*sleep($,G){let K=S.tracer.startSpan("sleep",{attributes:{"weft.sleep.duration":$.duration}},k(S,$.workflowId));O(S,K,$),yield*R(S,K,()=>G($))},*waitForSignal($,G){let K=S.tracer.startSpan("waitForSignal",{attributes:{"weft.signal.name":$.signalName}},k(S,$.workflowId));return O(S,K,$),yield*R(S,K,()=>G($))},async childWorkflow($,G){let K=[],L=U($.parentHeaders);if(L)K.push({context:{traceId:L.traceId,spanId:L.spanId,traceFlags:L.traceFlags}});let X=S.tracer.startSpan(`childWorkflow:${$.workflowType}`,{attributes:{"weft.child_workflow.type":$.workflowType,"weft.child_workflow.id":$.childWorkflowId,"weft.child_workflow.parent_id":$.workflowId},links:K},S.api.context.ROOT_CONTEXT);if(_(X,$.headers),S.recordPayloads&&$.input!==void 0)X.setAttribute("weft.payload.input",F($.input,S.maxPayloadSize));return S.metrics.increment("weft.child_workflow.started"),y(S,X,()=>G($))},signalReceived($,G){let K=S.tracer.startSpan(`signal:received:${$.signalName}`,{attributes:{"weft.signal.name":$.signalName,"weft.signal.workflow_id":$.workflowId}});O(S,K,$),h(S,K,()=>G($))}}}function eS(S){let{attributeExtractor:$,eventTarget:G,maxPayloadSize:K=u,metrics:L=new w,openTelemetryApi:X=B(),recordPayloads:T=!1,tracerName:A="weft",tracerVersion:x}=S??{},Z=X,{trace:J,SpanStatusCode:Q}=Z,b=J.getTracer(A,x);return{api:Z,trace:J,SpanStatusCode:Q,tracer:b,recordPayloads:T,maxPayloadSize:K,attributeExtractor:$,eventTarget:G,metrics:L,workflowSpans:new Map}}function d0(S){let $=eS(S),G=bS($),K=E($),L={...G,...K},X=PS($);return{interceptor:L,metrics:$.metrics,...X}}export{c as serializeMetricsSnapshotForPrometheus,p as parseTraceParent,C as injectTraceParent,B as getOpenTelemetryApi,pS as generateTraceId,gS as generateSpanId,g as formatTraceParent,U as extractTraceParent,vS as createOpenTelemetryMetrics,d0 as createObservabilityInterceptors,sS as createMetricsCollectorExporter,w as MetricsCollector,P as METRICS};
|