@e4779/pi-fabric 0.117.2-fork.31 → 0.131.0-fork.32
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 +12 -5
- package/THIRD_PARTY_NOTICES.md +6 -14
- package/dist/activity/store.d.ts +2 -1
- package/dist/activity/store.d.ts.map +1 -1
- package/dist/actors/binding-store.d.ts +13 -0
- package/dist/actors/binding-store.d.ts.map +1 -1
- package/dist/actors/directory.d.ts.map +1 -1
- package/dist/actors/global-registry.d.ts +8 -0
- package/dist/actors/global-registry.d.ts.map +1 -1
- package/dist/actors/host-event-payload.d.ts +14 -0
- package/dist/actors/host-event-payload.d.ts.map +1 -1
- package/dist/actors/manager.d.ts +4 -3
- package/dist/actors/manager.d.ts.map +1 -1
- package/dist/actors/mesh-monitor.d.ts +2 -0
- package/dist/actors/mesh-monitor.d.ts.map +1 -1
- package/dist/actors/name-policy.d.ts +3 -0
- package/dist/actors/name-policy.d.ts.map +1 -0
- package/dist/actors/registry-store.d.ts +14 -5
- package/dist/actors/registry-store.d.ts.map +1 -1
- package/dist/actors/store-read.d.ts +16 -0
- package/dist/actors/store-read.d.ts.map +1 -0
- package/dist/agents/agent-files.d.ts +80 -0
- package/dist/agents/agent-files.d.ts.map +1 -0
- package/dist/agents/agent-files.js +327 -0
- package/dist/agents/agent-files.js.map +7 -0
- package/dist/agents/child-skills.d.ts +60 -0
- package/dist/agents/child-skills.d.ts.map +1 -0
- package/dist/agents/child-skills.js +94 -0
- package/dist/agents/child-skills.js.map +7 -0
- package/dist/agents/clone-first-worktree.d.ts +6 -0
- package/dist/agents/clone-first-worktree.d.ts.map +1 -1
- package/dist/agents/cow-clone.d.ts.map +1 -1
- package/dist/agents/handoff.d.ts +12 -2
- package/dist/agents/handoff.d.ts.map +1 -1
- package/dist/agents/herdr-status.d.ts +26 -0
- package/dist/agents/herdr-status.d.ts.map +1 -0
- package/dist/agents/herdr-status.js +161 -0
- package/dist/agents/herdr-status.js.map +7 -0
- package/dist/agents/hosted-run.d.ts +20 -4
- package/dist/agents/hosted-run.d.ts.map +1 -1
- package/dist/agents/manager.d.ts +18 -2
- package/dist/agents/manager.d.ts.map +1 -1
- package/dist/agents/model-pin-guard.d.ts +27 -0
- package/dist/agents/model-pin-guard.d.ts.map +1 -0
- package/dist/agents/model-pin-guard.js +86 -0
- package/dist/agents/model-pin-guard.js.map +7 -0
- package/dist/agents/model-pin.d.ts +25 -0
- package/dist/agents/model-pin.d.ts.map +1 -0
- package/dist/agents/provider-bridge.d.ts +7 -6
- package/dist/agents/provider-bridge.d.ts.map +1 -1
- package/dist/agents/provider-bridge.js +33 -5
- package/dist/agents/provider-bridge.js.map +3 -3
- package/dist/agents/request.d.ts.map +1 -1
- package/dist/agents/result.d.ts.map +1 -1
- package/dist/agents/result.js +1 -1
- package/dist/agents/runner-notice.d.ts.map +1 -1
- package/dist/agents/runner-protocol.d.ts +8 -0
- package/dist/agents/runner-protocol.d.ts.map +1 -1
- package/dist/agents/service-schema.d.ts.map +1 -1
- package/dist/agents/transports/herdr-socket.d.ts +12 -0
- package/dist/agents/transports/herdr-socket.d.ts.map +1 -0
- package/dist/agents/transports/herdr-transport.d.ts.map +1 -1
- package/dist/agents/types.d.ts +51 -0
- package/dist/agents/types.d.ts.map +1 -1
- package/dist/agents/worker-recovery.d.ts +75 -0
- package/dist/agents/worker-recovery.d.ts.map +1 -0
- package/dist/agents/worktree-manager.d.ts.map +1 -1
- package/dist/agents.js +12 -11
- package/dist/agents.js.map +2 -2
- package/dist/audit/details.d.ts +36 -1
- package/dist/audit/details.d.ts.map +1 -1
- package/dist/audit/projection.d.ts.map +1 -1
- package/dist/audit/trace-schema.d.ts +50 -0
- package/dist/audit/trace-schema.d.ts.map +1 -0
- package/dist/audit/trace.d.ts +2 -48
- package/dist/audit/trace.d.ts.map +1 -1
- package/dist/chunks/chunk-2RWNVCFD.js +483 -0
- package/dist/chunks/chunk-2RWNVCFD.js.map +7 -0
- package/dist/chunks/chunk-2SCMGO2Z.js +16 -0
- package/dist/chunks/chunk-2SCMGO2Z.js.map +7 -0
- package/dist/chunks/chunk-35EEGOH3.js +324 -0
- package/dist/chunks/chunk-35EEGOH3.js.map +7 -0
- package/dist/chunks/{chunk-3FJUP3GV.js → chunk-36XQFTEN.js} +2 -2
- package/dist/chunks/{chunk-UTOBAZ5T.js → chunk-37NIOSVU.js} +1 -1
- package/dist/chunks/chunk-37NIOSVU.js.map +7 -0
- package/dist/chunks/chunk-3IJEQBFS.js +25 -0
- package/dist/chunks/chunk-3IJEQBFS.js.map +7 -0
- package/dist/chunks/{chunk-EHQQ4KCX.js → chunk-3MOY6WIB.js} +84 -19
- package/dist/chunks/chunk-3MOY6WIB.js.map +7 -0
- package/dist/chunks/chunk-3PKZSIRA.js +1312 -0
- package/dist/chunks/chunk-3PKZSIRA.js.map +7 -0
- package/dist/chunks/chunk-3VK6UGAN.js +64 -0
- package/dist/chunks/chunk-3VK6UGAN.js.map +7 -0
- package/dist/chunks/{chunk-ROTCDDOV.js → chunk-3XT5WHSG.js} +59 -119
- package/dist/chunks/chunk-3XT5WHSG.js.map +7 -0
- package/dist/chunks/{chunk-FIDUHKMM.js → chunk-4BYS4ZLY.js} +16 -16
- package/dist/chunks/chunk-4BYS4ZLY.js.map +7 -0
- package/dist/chunks/{chunk-K7J2ABAZ.js → chunk-4KX6BIPL.js} +91 -31
- package/dist/chunks/chunk-4KX6BIPL.js.map +7 -0
- package/dist/chunks/{chunk-UOM37PE4.js → chunk-4PBW54I2.js} +162 -92
- package/dist/chunks/chunk-4PBW54I2.js.map +7 -0
- package/dist/chunks/{chunk-ZEXCKK4K.js → chunk-4WKD3YM3.js} +3 -3
- package/dist/chunks/{chunk-PK4NIJEV.js → chunk-4XMXFHAR.js} +62 -3
- package/dist/chunks/chunk-4XMXFHAR.js.map +7 -0
- package/dist/chunks/{chunk-4EW7GVUR.js → chunk-56NMRVTV.js} +589 -377
- package/dist/chunks/chunk-56NMRVTV.js.map +7 -0
- package/dist/chunks/{chunk-GIK2WNAK.js → chunk-5BOTHX47.js} +109 -20
- package/dist/chunks/chunk-5BOTHX47.js.map +7 -0
- package/dist/chunks/chunk-5QJFDKPN.js +179 -0
- package/dist/chunks/chunk-5QJFDKPN.js.map +7 -0
- package/dist/chunks/{chunk-P7CBPPHY.js → chunk-6GWDGTHC.js} +5 -5
- package/dist/chunks/{chunk-P7CBPPHY.js.map → chunk-6GWDGTHC.js.map} +1 -1
- package/dist/chunks/chunk-6HO2IUQ5.js +104 -0
- package/dist/chunks/chunk-6HO2IUQ5.js.map +7 -0
- package/dist/chunks/chunk-6OGYPHNQ.js +62 -0
- package/dist/chunks/chunk-6OGYPHNQ.js.map +7 -0
- package/dist/chunks/{chunk-GO32KSEZ.js → chunk-7CIES6X2.js} +84 -9
- package/dist/chunks/chunk-7CIES6X2.js.map +7 -0
- package/dist/chunks/{chunk-G4TLWHRS.js → chunk-7N7IC3Z2.js} +4 -3
- package/dist/chunks/{chunk-G4TLWHRS.js.map → chunk-7N7IC3Z2.js.map} +2 -2
- package/dist/chunks/{chunk-5XBYFSI5.js → chunk-7YNE4NB2.js} +2 -2
- package/dist/chunks/{chunk-NTC2MCB6.js → chunk-B5L3X3ID.js} +1 -1
- package/dist/chunks/{chunk-NTC2MCB6.js.map → chunk-B5L3X3ID.js.map} +1 -1
- package/dist/chunks/chunk-BIBRWZWQ.js +325 -0
- package/dist/chunks/chunk-BIBRWZWQ.js.map +7 -0
- package/dist/chunks/{chunk-K6QXUGS5.js → chunk-BMAEZNZ5.js} +2 -1
- package/dist/chunks/{chunk-FSB2VIRZ.js → chunk-CBIV747V.js} +14 -3
- package/dist/chunks/chunk-CBIV747V.js.map +7 -0
- package/dist/chunks/{chunk-CCHZXF6K.js → chunk-CXYJJ3HZ.js} +3 -3
- package/dist/chunks/{chunk-R2XQ6AHT.js → chunk-DGERP4VL.js} +22 -10
- package/dist/chunks/chunk-DGERP4VL.js.map +7 -0
- package/dist/chunks/chunk-F2LGSRIN.js +38 -0
- package/dist/chunks/chunk-F2LGSRIN.js.map +7 -0
- package/dist/chunks/chunk-F6A6MQ6G.js +609 -0
- package/dist/chunks/chunk-F6A6MQ6G.js.map +7 -0
- package/dist/chunks/{chunk-IR3PIHJM.js → chunk-FK73YJKV.js} +67 -2
- package/dist/chunks/chunk-FK73YJKV.js.map +7 -0
- package/dist/chunks/{chunk-VYQV5JRT.js → chunk-GJVKEHDL.js} +2 -2
- package/dist/chunks/chunk-GJVKEHDL.js.map +7 -0
- package/dist/chunks/{chunk-TIIIHPHF.js → chunk-GS67KDMV.js} +2 -2
- package/dist/chunks/{chunk-D5NYNIST.js → chunk-H57KPL3V.js} +5 -5
- package/dist/chunks/{chunk-KVYNGDGC.js → chunk-HFDJWLMS.js} +6 -6
- package/dist/chunks/{chunk-KVYNGDGC.js.map → chunk-HFDJWLMS.js.map} +1 -1
- package/dist/chunks/{chunk-INRXG4J5.js → chunk-HGD75NZY.js} +2 -2
- package/dist/chunks/{chunk-CRRUW26I.js → chunk-HRDMBGMY.js} +12 -12
- package/dist/chunks/{chunk-CRRUW26I.js.map → chunk-HRDMBGMY.js.map} +2 -2
- package/dist/chunks/{chunk-MLLYR3Y6.js → chunk-HSEZPCL5.js} +19 -78
- package/dist/chunks/chunk-HSEZPCL5.js.map +7 -0
- package/dist/chunks/{chunk-LNASO4VT.js → chunk-IOGDTIGN.js} +44 -19
- package/dist/chunks/chunk-IOGDTIGN.js.map +7 -0
- package/dist/chunks/chunk-JMUUNW2H.js +65 -0
- package/dist/chunks/chunk-JMUUNW2H.js.map +7 -0
- package/dist/chunks/{chunk-UXIBKMUM.js → chunk-KIFOEBYJ.js} +4 -4
- package/dist/chunks/{chunk-SPCJXN4K.js → chunk-LKYLD5SN.js} +298 -65
- package/dist/chunks/chunk-LKYLD5SN.js.map +7 -0
- package/dist/chunks/{chunk-FUY6XVRX.js → chunk-MPMEK3IQ.js} +2 -2
- package/dist/chunks/{chunk-HP5P7NBO.js → chunk-MSDL7U6Q.js} +4 -4
- package/dist/chunks/chunk-N7ZAK2PB.js +132 -0
- package/dist/chunks/chunk-N7ZAK2PB.js.map +7 -0
- package/dist/chunks/{chunk-VSDUSNIA.js → chunk-NBIYYMKS.js} +8 -2
- package/dist/chunks/chunk-NBIYYMKS.js.map +7 -0
- package/dist/chunks/chunk-NENQZCGW.js +45 -0
- package/dist/chunks/chunk-NENQZCGW.js.map +7 -0
- package/dist/chunks/chunk-NJHJKINP.js +47 -0
- package/dist/chunks/chunk-NJHJKINP.js.map +7 -0
- package/dist/chunks/{chunk-U366I5K2.js → chunk-NQ7IWEIF.js} +18 -6
- package/dist/chunks/chunk-NQ7IWEIF.js.map +7 -0
- package/dist/chunks/{chunk-ZQMBS5SH.js → chunk-OJ4HAALD.js} +15 -12
- package/dist/chunks/chunk-OJ4HAALD.js.map +7 -0
- package/dist/chunks/chunk-OZCJU3PZ.js +33 -0
- package/dist/chunks/chunk-OZCJU3PZ.js.map +7 -0
- package/dist/chunks/chunk-P3DCXKL3.js +40 -0
- package/dist/chunks/chunk-P3DCXKL3.js.map +7 -0
- package/dist/chunks/chunk-P7YSPKTM.js +294 -0
- package/dist/chunks/chunk-P7YSPKTM.js.map +7 -0
- package/dist/chunks/chunk-PQVUMJ5J.js +223 -0
- package/dist/chunks/chunk-PQVUMJ5J.js.map +7 -0
- package/dist/chunks/chunk-PUBHBEYO.js +84 -0
- package/dist/chunks/chunk-PUBHBEYO.js.map +7 -0
- package/dist/chunks/{chunk-P4KH4S4S.js → chunk-QGTD3LAZ.js} +5 -20
- package/dist/chunks/chunk-QGTD3LAZ.js.map +7 -0
- package/dist/chunks/{chunk-TIJ3YQXX.js → chunk-QOEOKW2X.js} +2 -2
- package/dist/chunks/{chunk-TIJ3YQXX.js.map → chunk-QOEOKW2X.js.map} +1 -1
- package/dist/chunks/{chunk-QT4W5YVB.js → chunk-RAA3FAYZ.js} +2 -2
- package/dist/chunks/{chunk-WJJXODAB.js → chunk-RLKRZXSX.js} +8 -1
- package/dist/chunks/{chunk-WJJXODAB.js.map → chunk-RLKRZXSX.js.map} +2 -2
- package/dist/chunks/chunk-RWKQ5SRW.js +129 -0
- package/dist/chunks/chunk-RWKQ5SRW.js.map +7 -0
- package/dist/chunks/chunk-SW25R47N.js +71 -0
- package/dist/chunks/chunk-SW25R47N.js.map +7 -0
- package/dist/chunks/{chunk-EFETPXU2.js → chunk-TJZYM2SP.js} +118 -237
- package/dist/chunks/chunk-TJZYM2SP.js.map +7 -0
- package/dist/chunks/{chunk-53N2I4QA.js → chunk-TXCNZCZP.js} +2 -2
- package/dist/chunks/chunk-UD7LFV43.js +28 -0
- package/dist/chunks/chunk-UD7LFV43.js.map +7 -0
- package/dist/chunks/{chunk-ASSLHWZS.js → chunk-UFMYN5TA.js} +2 -2
- package/dist/chunks/{chunk-7QKKLBHJ.js → chunk-UPMWLOKL.js} +10 -1
- package/dist/chunks/{chunk-7QKKLBHJ.js.map → chunk-UPMWLOKL.js.map} +2 -2
- package/dist/chunks/chunk-V4OW2ULC.js +422 -0
- package/dist/chunks/chunk-V4OW2ULC.js.map +7 -0
- package/dist/chunks/{chunk-FE6NOAO7.js → chunk-VNWQIGQL.js} +1820 -649
- package/dist/chunks/chunk-VNWQIGQL.js.map +7 -0
- package/dist/chunks/{chunk-PYFJW3HC.js → chunk-W5FEHVZA.js} +2 -16
- package/dist/chunks/{chunk-PYFJW3HC.js.map → chunk-W5FEHVZA.js.map} +3 -3
- package/dist/chunks/{chunk-XCEEQ5AB.js → chunk-WGMCNCP6.js} +1567 -1564
- package/dist/chunks/chunk-WGMCNCP6.js.map +7 -0
- package/dist/chunks/chunk-WKFRGICG.js +101 -0
- package/dist/chunks/chunk-WKFRGICG.js.map +7 -0
- package/dist/chunks/{chunk-3UGN25XS.js → chunk-WWTGWGH7.js} +80 -1662
- package/dist/chunks/chunk-WWTGWGH7.js.map +7 -0
- package/dist/chunks/{chunk-5UBRGTVN.js → chunk-X7QETPBC.js} +31 -15
- package/dist/chunks/chunk-X7QETPBC.js.map +7 -0
- package/dist/chunks/{chunk-LEU5CDSL.js → chunk-XFOSUGLU.js} +5 -5
- package/dist/chunks/{chunk-MZUC6LLH.js → chunk-XMYG2TKR.js} +4 -4
- package/dist/chunks/{chunk-MZUC6LLH.js.map → chunk-XMYG2TKR.js.map} +1 -1
- package/dist/chunks/chunk-YC65P7ZO.js +57 -0
- package/dist/chunks/chunk-YC65P7ZO.js.map +7 -0
- package/dist/chunks/{chunk-EKODKR6Y.js → chunk-YHFWMAQ5.js} +1 -24
- package/dist/chunks/chunk-YHFWMAQ5.js.map +7 -0
- package/dist/chunks/{chunk-C7Z6F3SO.js → chunk-ZFWICFNJ.js} +27 -20
- package/dist/chunks/{chunk-C7Z6F3SO.js.map → chunk-ZFWICFNJ.js.map} +2 -2
- package/dist/cli/decisions.d.ts.map +1 -1
- package/dist/cli/decisions.js +15 -3
- package/dist/cli/decisions.js.map +2 -2
- package/dist/cli/mesh.js +4 -3
- package/dist/cli/mesh.js.map +1 -1
- package/dist/commands/fabric-handler.d.ts +7 -0
- package/dist/commands/fabric-handler.d.ts.map +1 -0
- package/dist/commands/fabric-handler.js +916 -0
- package/dist/commands/fabric-handler.js.map +7 -0
- package/dist/commands/fabric.d.ts +11 -1
- package/dist/commands/fabric.d.ts.map +1 -1
- package/dist/compaction/claim-events.d.ts +61 -0
- package/dist/compaction/claim-events.d.ts.map +1 -0
- package/dist/compaction/claim-events.js +210 -0
- package/dist/compaction/claim-events.js.map +7 -0
- package/dist/compaction/claim.d.ts +51 -0
- package/dist/compaction/claim.d.ts.map +1 -0
- package/dist/compaction/hook.d.ts +28 -2
- package/dist/compaction/hook.d.ts.map +1 -1
- package/dist/compaction/hook.js +12 -7
- package/dist/compaction/owner.js +9 -8
- package/dist/compaction/trace-events.d.ts +1 -1
- package/dist/compaction/trace-events.d.ts.map +1 -1
- package/dist/components/configuration.js +6 -6
- package/dist/components/effect-scope.d.ts.map +1 -1
- package/dist/config.d.ts +39 -2
- package/dist/config.d.ts.map +1 -1
- package/dist/core/action-arguments.d.ts.map +1 -1
- package/dist/core/action-policy-hooks.d.ts +69 -0
- package/dist/core/action-policy-hooks.d.ts.map +1 -0
- package/dist/core/action-registry.d.ts +31 -10
- package/dist/core/action-registry.d.ts.map +1 -1
- package/dist/core/action-registry.js +12 -9
- package/dist/core/approval-controller.d.ts +23 -3
- package/dist/core/approval-controller.d.ts.map +1 -1
- package/dist/core/atomic-write.d.ts +164 -0
- package/dist/core/atomic-write.d.ts.map +1 -1
- package/dist/core/child-tool-allowlist.d.ts +17 -1
- package/dist/core/child-tool-allowlist.d.ts.map +1 -1
- package/dist/core/compact-controller.d.ts +34 -0
- package/dist/core/compact-controller.d.ts.map +1 -1
- package/dist/core/core-override-guidance.d.ts +3 -1
- package/dist/core/core-override-guidance.d.ts.map +1 -1
- package/dist/core/file-lock.d.ts.map +1 -1
- package/dist/core/foreground-tools.d.ts +4 -1
- package/dist/core/foreground-tools.d.ts.map +1 -1
- package/dist/core/host-policy.d.ts +43 -0
- package/dist/core/host-policy.d.ts.map +1 -0
- package/dist/core/host-sdk-runtime.d.ts.map +1 -1
- package/dist/core/host-sdk.d.ts.map +1 -1
- package/dist/core/host-sdk.js +1 -1
- package/dist/core/managed-host-guidance.d.ts +5 -0
- package/dist/core/managed-host-guidance.d.ts.map +1 -0
- package/dist/core/model-aliases.d.ts +22 -0
- package/dist/core/model-aliases.d.ts.map +1 -0
- package/dist/core/model-resolution.d.ts +41 -20
- package/dist/core/model-resolution.d.ts.map +1 -1
- package/dist/core/native-tool-result.d.ts +1 -0
- package/dist/core/native-tool-result.d.ts.map +1 -1
- package/dist/core/program-tasks.d.ts +52 -0
- package/dist/core/program-tasks.d.ts.map +1 -0
- package/dist/core/prompt-guidance.d.ts +5 -0
- package/dist/core/prompt-guidance.d.ts.map +1 -0
- package/dist/core/prompt-guidance.js +159 -0
- package/dist/core/prompt-guidance.js.map +7 -0
- package/dist/core/provider-operations.d.ts.map +1 -1
- package/dist/core/provider-operations.js +60 -108
- package/dist/core/provider-operations.js.map +3 -3
- package/dist/core/shell-inbox.d.ts.map +1 -1
- package/dist/core/shell-jobs.d.ts +7 -5
- package/dist/core/shell-jobs.d.ts.map +1 -1
- package/dist/core/shell-timing.d.ts.map +1 -1
- package/dist/core/skill-prompt.d.ts +1 -1
- package/dist/core/skill-prompt.d.ts.map +1 -1
- package/dist/core/skill-references.d.ts +1 -1
- package/dist/core/skill-references.d.ts.map +1 -1
- package/dist/core/system-guidance.d.ts.map +1 -1
- package/dist/core/tool-result-proxy.d.ts.map +1 -1
- package/dist/decisions/command.d.ts +2 -1
- package/dist/decisions/command.d.ts.map +1 -1
- package/dist/decisions/command.js +40 -12
- package/dist/decisions/command.js.map +2 -2
- package/dist/decisions/events.d.ts +12 -0
- package/dist/decisions/events.d.ts.map +1 -0
- package/dist/decisions/events.js +130 -0
- package/dist/decisions/events.js.map +7 -0
- package/dist/decisions/host.d.ts +31 -3
- package/dist/decisions/host.d.ts.map +1 -1
- package/dist/decisions/render.d.ts +44 -0
- package/dist/decisions/render.d.ts.map +1 -0
- package/dist/decisions/store.d.ts +8 -0
- package/dist/decisions/store.d.ts.map +1 -1
- package/dist/durable/agent.d.ts +8 -0
- package/dist/durable/agent.d.ts.map +1 -1
- package/dist/durable/extension-load-error.d.ts +8 -0
- package/dist/durable/extension-load-error.d.ts.map +1 -0
- package/dist/durable/session.d.ts +1 -0
- package/dist/durable/session.d.ts.map +1 -1
- package/dist/durable/worker-host.d.ts +10 -1
- package/dist/durable/worker-host.d.ts.map +1 -1
- package/dist/durable/worker-host.js +10 -1181
- package/dist/durable/worker-host.js.map +4 -4
- package/dist/durable/worker-options.d.ts +3 -0
- package/dist/durable/worker-options.d.ts.map +1 -1
- package/dist/durable/worker-role-seed.d.ts +82 -0
- package/dist/durable/worker-role-seed.d.ts.map +1 -0
- package/dist/durable/worker.js +43 -4
- package/dist/durable/worker.js.map +2 -2
- package/dist/durable-controls.d.ts.map +1 -1
- package/dist/durable-extension-wasm.d.ts +8 -0
- package/dist/durable-extension-wasm.d.ts.map +1 -0
- package/dist/durable-extension-wasm.js +32 -0
- package/dist/durable-extension-wasm.js.map +7 -0
- package/dist/durable-extension.d.ts +94 -0
- package/dist/durable-extension.d.ts.map +1 -0
- package/dist/durable-extension.js +649 -0
- package/dist/durable-extension.js.map +7 -0
- package/dist/durable-host.d.ts +8 -0
- package/dist/durable-host.d.ts.map +1 -0
- package/dist/durable-host.js +20 -0
- package/dist/durable-host.js.map +7 -0
- package/dist/durable-journal.d.ts +94 -0
- package/dist/durable-journal.d.ts.map +1 -0
- package/dist/durable.d.ts.map +1 -1
- package/dist/durable.js +10 -8
- package/dist/durable.js.map +2 -2
- package/dist/entropy/index.js +12 -10
- package/dist/entropy/pool-store.d.ts.map +1 -1
- package/dist/execution-service.d.ts +14 -0
- package/dist/execution-service.d.ts.map +1 -1
- package/dist/extension-bootstrap.d.ts.map +1 -1
- package/dist/extension-bootstrap.js +28 -27
- package/dist/extension-bootstrap.js.map +2 -2
- package/dist/extension-copy.d.ts +21 -0
- package/dist/extension-copy.d.ts.map +1 -0
- package/dist/extension-copy.js +90 -0
- package/dist/extension-copy.js.map +7 -0
- package/dist/extension.d.ts +1 -1
- package/dist/extension.d.ts.map +1 -1
- package/dist/fabric-exec-arguments.d.ts.map +1 -1
- package/dist/fabric-exec-tool.d.ts +2 -1
- package/dist/fabric-exec-tool.d.ts.map +1 -1
- package/dist/fabric-runtime-state.d.ts +19 -0
- package/dist/fabric-runtime-state.d.ts.map +1 -1
- package/dist/fabric-runtime-state.js +2125 -786
- package/dist/fabric-runtime-state.js.map +4 -4
- package/dist/fabric-state.d.ts +44 -1
- package/dist/fabric-state.d.ts.map +1 -1
- package/dist/index.d.ts +5 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +88 -53
- package/dist/index.js.map +2 -2
- package/dist/jev/client.js +2 -2
- package/dist/jev/manager.d.ts +3 -0
- package/dist/jev/manager.d.ts.map +1 -1
- package/dist/jev/observation.d.ts +1 -1
- package/dist/jev/observation.js +6 -6
- package/dist/jev-fabric/bridge.d.ts.map +1 -1
- package/dist/jev.js +11 -12
- package/dist/managed-host.d.ts +13 -0
- package/dist/managed-host.d.ts.map +1 -1
- package/dist/memory/digest.js +2 -2
- package/dist/memory/discovery.js +6 -7
- package/dist/memory/file-worker.js +10 -11
- package/dist/memory/file-worker.js.map +1 -1
- package/dist/memory/normalize.js +5 -6
- package/dist/memory/search.js +7 -8
- package/dist/memory/worker-provider.js +11 -12
- package/dist/memory.js +11 -12
- package/dist/memory.js.map +1 -1
- package/dist/mesh/grants.d.ts +3 -3
- package/dist/mesh/grants.d.ts.map +1 -1
- package/dist/mesh/store.d.ts +8 -0
- package/dist/mesh/store.d.ts.map +1 -1
- package/dist/native-codemode.d.ts.map +1 -1
- package/dist/native-tool-catalog.d.ts.map +1 -1
- package/dist/native-tool-catalog.js +12 -3
- package/dist/native-tool-catalog.js.map +2 -2
- package/dist/programs/host.d.ts +18 -6
- package/dist/programs/host.d.ts.map +1 -1
- package/dist/programs/host.js +71 -47
- package/dist/programs/host.js.map +2 -2
- package/dist/programs/source.d.ts +11 -0
- package/dist/programs/source.d.ts.map +1 -1
- package/dist/programs/store.d.ts.map +1 -1
- package/dist/protocol.d.ts +504 -8
- package/dist/protocol.d.ts.map +1 -1
- package/dist/protocol.js +41 -11
- package/dist/provider-globals.d.ts +13 -0
- package/dist/provider-globals.d.ts.map +1 -0
- package/dist/providers/agents-actions.d.ts.map +1 -1
- package/dist/providers/agents-provider.d.ts +3 -0
- package/dist/providers/agents-provider.d.ts.map +1 -1
- package/dist/providers/captured-tools-provider.d.ts +5 -0
- package/dist/providers/captured-tools-provider.d.ts.map +1 -1
- package/dist/providers/compact-provider.d.ts +4 -1
- package/dist/providers/compact-provider.d.ts.map +1 -1
- package/dist/providers/components-provider.d.ts.map +1 -1
- package/dist/providers/decisions-provider.d.ts +9 -1
- package/dist/providers/decisions-provider.d.ts.map +1 -1
- package/dist/providers/jev-provider.d.ts +1 -1
- package/dist/providers/jev-provider.js +11 -12
- package/dist/providers/memory-provider.js +10 -11
- package/dist/providers/pi-tools-provider.d.ts +14 -0
- package/dist/providers/pi-tools-provider.d.ts.map +1 -1
- package/dist/providers/programs-provider.d.ts.map +1 -1
- package/dist/providers/sessions-provider.d.ts +7 -0
- package/dist/providers/sessions-provider.d.ts.map +1 -1
- package/dist/repeat-guard.d.ts +7 -6
- package/dist/repeat-guard.d.ts.map +1 -1
- package/dist/residency/actor-client.js +3 -3
- package/dist/residency/client.d.ts +15 -0
- package/dist/residency/client.d.ts.map +1 -1
- package/dist/residency/host.d.ts.map +1 -1
- package/dist/residency/host.js +34 -23
- package/dist/residency/launcher.js +1 -1
- package/dist/residency/pi-entry.js +34 -23
- package/dist/residency/pi-entry.js.map +1 -1
- package/dist/residency/protocol.d.ts +2 -0
- package/dist/residency/protocol.d.ts.map +1 -1
- package/dist/runners.js +11 -1
- package/dist/runners.js.map +2 -2
- package/dist/runtime/core-override-guest-types.js +2 -2
- package/dist/runtime/cpython-child-source.d.ts.map +1 -1
- package/dist/runtime/cpython-runtime.d.ts.map +1 -1
- package/dist/runtime/cpython-runtime.js +51 -21
- package/dist/runtime/cpython-runtime.js.map +2 -2
- package/dist/runtime/deadline-pause.d.ts +2 -0
- package/dist/runtime/deadline-pause.d.ts.map +1 -1
- package/dist/runtime/dynamic-guest-types.d.ts.map +1 -1
- package/dist/runtime/dynamic-guest-types.js +2 -1
- package/dist/runtime/exec-journal.d.ts +73 -0
- package/dist/runtime/exec-journal.d.ts.map +1 -0
- package/dist/runtime/exec-journal.js +335 -0
- package/dist/runtime/exec-journal.js.map +7 -0
- package/dist/runtime/guest-types.d.ts +3 -2
- package/dist/runtime/guest-types.d.ts.map +1 -1
- package/dist/runtime/guest-types.js +1 -1
- package/dist/runtime/journal-shim.d.ts +3 -0
- package/dist/runtime/journal-shim.d.ts.map +1 -0
- package/dist/runtime/kernel.d.ts +95 -1
- package/dist/runtime/kernel.d.ts.map +1 -1
- package/dist/runtime/monty-bridge.d.ts +6 -2
- package/dist/runtime/monty-bridge.d.ts.map +1 -1
- package/dist/runtime/monty-runtime.d.ts.map +1 -1
- package/dist/runtime/monty-runtime.js +27 -15
- package/dist/runtime/monty-runtime.js.map +2 -2
- package/dist/runtime/native-codemode-guest.d.ts.map +1 -1
- package/dist/runtime/node-process-runtime.d.ts.map +1 -1
- package/dist/runtime/node-process-runtime.js +7 -5
- package/dist/runtime/quickjs-runtime.d.ts +7 -1
- package/dist/runtime/quickjs-runtime.d.ts.map +1 -1
- package/dist/runtime/quickjs-runtime.js +5 -4
- package/dist/runtime/sha256.d.ts +4 -0
- package/dist/runtime/sha256.d.ts.map +1 -0
- package/dist/runtime/transpile.d.ts +8 -0
- package/dist/runtime/transpile.d.ts.map +1 -0
- package/dist/runtime/type-checker.d.ts +1 -7
- package/dist/runtime/type-checker.d.ts.map +1 -1
- package/dist/runtime/type-checker.js +4 -2
- package/dist/runtime/typescript-kernel.js +13 -10
- package/dist/runtime/typescript-kernel.js.map +1 -1
- package/dist/runtime-state-builtins.d.ts.map +1 -1
- package/dist/speculation/scanner.js +1 -1
- package/dist/speculation/store.d.ts +7 -16
- package/dist/speculation/store.d.ts.map +1 -1
- package/dist/speculation/types.d.ts +1 -0
- package/dist/speculation/types.d.ts.map +1 -1
- package/dist/storage/retention.d.ts.map +1 -1
- package/dist/topology/participant-directory.d.ts +26 -1
- package/dist/topology/participant-directory.d.ts.map +1 -1
- package/dist/topology/peer-presence.d.ts.map +1 -1
- package/dist/topology/peer-settle.js +11 -0
- package/dist/topology/peer-settle.js.map +7 -0
- package/dist/topology/session-label-settings.d.ts +13 -0
- package/dist/topology/session-label-settings.d.ts.map +1 -0
- package/dist/topology/session-label.d.ts +60 -0
- package/dist/topology/session-label.d.ts.map +1 -0
- package/dist/topology/types.d.ts +27 -0
- package/dist/topology/types.d.ts.map +1 -1
- package/dist/type-error-guidance.js +1 -1
- package/dist/ui/controller.d.ts +1 -0
- package/dist/ui/controller.d.ts.map +1 -1
- package/dist/ui/conversation-chrome.d.ts.map +1 -1
- package/dist/ui/conversation-chrome.js +3 -2
- package/dist/ui/conversation-commands.d.ts +1 -1
- package/dist/ui/conversation-commands.d.ts.map +1 -1
- package/dist/ui/conversation-native-reader.js +2 -2
- package/dist/ui/conversation-selection.d.ts +4 -1
- package/dist/ui/conversation-selection.d.ts.map +1 -1
- package/dist/ui/conversation-targets.d.ts.map +1 -1
- package/dist/ui/conversation-targets.js +2 -2
- package/dist/ui/conversation.d.ts +25 -24
- package/dist/ui/conversation.d.ts.map +1 -1
- package/dist/ui/conversation.js +170 -339
- package/dist/ui/conversation.js.map +2 -2
- package/dist/ui/core-tool-render.d.ts +1 -0
- package/dist/ui/core-tool-render.d.ts.map +1 -1
- package/dist/ui/dashboard.d.ts.map +1 -1
- package/dist/ui/dashboard.js +17 -13
- package/dist/ui/dashboard.js.map +2 -2
- package/dist/ui/fabric-render.d.ts +6 -0
- package/dist/ui/fabric-render.d.ts.map +1 -1
- package/dist/ui/footer-dock.d.ts +48 -0
- package/dist/ui/footer-dock.d.ts.map +1 -0
- package/dist/ui/format.d.ts +7 -0
- package/dist/ui/format.d.ts.map +1 -1
- package/dist/ui/settings-sections-lifecycle.d.ts.map +1 -1
- package/dist/ui/settings-sections-presentation.d.ts.map +1 -1
- package/dist/ui/settings-values.d.ts +1 -0
- package/dist/ui/settings-values.d.ts.map +1 -1
- package/dist/ui/settings.js +59 -18
- package/dist/ui/settings.js.map +2 -2
- package/dist/ui/shell-hang-keys.d.ts +8 -1
- package/dist/ui/shell-hang-keys.d.ts.map +1 -1
- package/dist/ui/shell-tasks.d.ts +2 -2
- package/dist/ui/shell-tasks.d.ts.map +1 -1
- package/dist/ui/shell-tasks.js +27 -94
- package/dist/ui/shell-tasks.js.map +2 -2
- package/dist/ui/snapshot.d.ts.map +1 -1
- package/dist/ui/terminal-title.d.ts +41 -0
- package/dist/ui/terminal-title.d.ts.map +1 -0
- package/dist/ui/types.d.ts +4 -0
- package/dist/ui/types.d.ts.map +1 -1
- package/dist/ui/widget-keys.d.ts +5 -0
- package/dist/ui/widget-keys.d.ts.map +1 -0
- package/dist/ui/widget.d.ts +34 -16
- package/dist/ui/widget.d.ts.map +1 -1
- package/dist/ui/word-diff/line-emphasis.js +1603 -0
- package/dist/ui/word-diff/line-emphasis.js.map +7 -0
- package/dist/util.d.ts +2 -0
- package/dist/util.d.ts.map +1 -1
- package/dist/verified/authority.d.ts +2 -2
- package/dist/verified/authority.d.ts.map +1 -1
- package/dist/verified/budget.d.ts +4 -0
- package/dist/verified/budget.d.ts.map +1 -0
- package/dist/verified/generated/actor-name.d.ts +4 -0
- package/dist/verified/generated/actor-name.js +17 -0
- package/dist/verified/generated/authority.d.ts +4 -0
- package/dist/verified/generated/authority.js +28 -0
- package/dist/verified/generated/budget.d.ts +4 -0
- package/dist/verified/generated/budget.js +17 -0
- package/dist/verified/generated/compaction.d.ts +4 -0
- package/dist/verified/generated/compaction.js +19 -0
- package/dist/verified/generated/grants.d.ts +4 -0
- package/dist/verified/generated/grants.js +17 -0
- package/dist/verified/generated/lifecycle.d.ts +4 -0
- package/dist/verified/generated/lifecycle.js +50 -0
- package/dist/verified/generated/manifest.json +137 -48
- package/dist/verified/generated/policy.d.ts +17 -0
- package/dist/verified/generated/policy.js +211 -0
- package/dist/verified/generated/provider.d.ts +4 -0
- package/dist/verified/generated/provider.js +18 -0
- package/dist/verified/generated/resources.d.ts +6 -0
- package/dist/verified/generated/resources.js +73 -0
- package/dist/verified/generated/speculation.d.ts +6 -0
- package/dist/verified/generated/speculation.js +48 -0
- package/dist/verified/generated/storage.d.ts +4 -0
- package/dist/verified/generated/storage.js +18 -0
- package/dist/verified/grants.d.ts +22 -0
- package/dist/verified/grants.d.ts.map +1 -0
- package/dist/verified/lifecycle.d.ts +31 -0
- package/dist/verified/lifecycle.d.ts.map +1 -0
- package/dist/verified/machine.d.ts +18 -0
- package/dist/verified/machine.d.ts.map +1 -0
- package/dist/verified/memory.d.ts +1 -1
- package/dist/verified/memory.d.ts.map +1 -1
- package/dist/verified/nat.d.ts +1 -1
- package/dist/verified/nat.d.ts.map +1 -1
- package/dist/verified/policy.d.ts +17 -5
- package/dist/verified/policy.d.ts.map +1 -1
- package/dist/verified/provider.d.ts +22 -0
- package/dist/verified/provider.d.ts.map +1 -0
- package/dist/verified/resources.d.ts +21 -7
- package/dist/verified/resources.d.ts.map +1 -1
- package/dist/verified/speculation.d.ts +36 -0
- package/dist/verified/speculation.d.ts.map +1 -0
- package/dist/verified/storage.d.ts.map +1 -1
- package/dist/worker/missing-install.d.ts +8 -0
- package/dist/worker/missing-install.d.ts.map +1 -0
- package/dist/worker/options.d.ts.map +1 -1
- package/dist/worker/options.js +25 -0
- package/dist/worker/options.js.map +2 -2
- package/dist/worker/prompt-lifecycle.d.ts +16 -0
- package/dist/worker/prompt-lifecycle.d.ts.map +1 -0
- package/dist/worker/prompt-lifecycle.js +90 -0
- package/dist/worker/prompt-lifecycle.js.map +7 -0
- package/dist/worker/questions.d.ts +15 -3
- package/dist/worker/questions.d.ts.map +1 -1
- package/dist/worker/questions.js +53 -8
- package/dist/worker/questions.js.map +2 -2
- package/dist/worker/recovery-watchdog.d.ts +22 -0
- package/dist/worker/recovery-watchdog.d.ts.map +1 -1
- package/dist/worker/recovery-watchdog.js +116 -1
- package/dist/worker/recovery-watchdog.js.map +2 -2
- package/dist/worker/result.js +1 -1
- package/dist/worker/result.js.map +2 -2
- package/dist/worker.js +131 -21
- package/dist/worker.js.map +2 -2
- package/docs/actor-name-policy-handoff.md +5 -0
- package/docs/agents.md +164 -17
- package/docs/architecture.md +5 -1
- package/docs/audit-trace.md +2 -1
- package/docs/background-tasks.md +102 -16
- package/docs/codemode-parity.md +2 -2
- package/docs/compaction.md +21 -5
- package/docs/components.md +1 -1
- package/docs/configuration.md +111 -66
- package/docs/decisions.md +92 -10
- package/docs/durable-extension.md +121 -0
- package/docs/durable-pi.md +306 -6
- package/docs/extractive-history.md +3 -1
- package/docs/interface.md +20 -17
- package/docs/jev.md +1 -1
- package/docs/kernels.md +1 -1
- package/{node_modules/pi-coralbricks-provider/LICENSE → docs/licenses/gdp-wired-mit.txt} +1 -1
- package/docs/managed-host-migration.md +50 -0
- package/docs/programmatic-compaction.md +216 -6
- package/docs/programs.md +23 -1
- package/docs/prompt-cache.md +4 -2
- package/docs/provider-capabilities.md +15 -14
- package/docs/providers.md +99 -3
- package/docs/shell-composition.md +15 -0
- package/docs/short-lock-protocol.md +90 -0
- package/docs/skills.md +5 -1
- package/docs/speculation.md +6 -0
- package/docs/verified-kernels.md +309 -220
- package/package.json +45 -24
- package/proofs/actor-name.ts +27 -0
- package/proofs/authority.ts +62 -0
- package/proofs/budget.ts +24 -0
- package/proofs/compaction.ts +51 -0
- package/proofs/grants.ts +39 -0
- package/proofs/index.ts +40 -0
- package/proofs/kernel.ts +44 -0
- package/proofs/lifecycle.ts +128 -0
- package/proofs/policy.ts +195 -0
- package/proofs/provider.ts +52 -0
- package/proofs/resources.ts +160 -0
- package/proofs/speculation.ts +69 -0
- package/proofs/storage.ts +66 -0
- package/scripts/verified-kernels.ts +141 -0
- package/skillsets/python/fabric-council/SKILL.md +92 -20
- package/skillsets/python/fabric-exec/SKILL.md +2 -2
- package/skillsets/python/fabric-exec/references/agents.md +10 -4
- package/skillsets/python/fabric-fusion/SKILL.md +1 -1
- package/skillsets/python/fabric-guide/SKILL.md +1 -1
- package/skillsets/typescript/fabric-council/SKILL.md +109 -22
- package/skillsets/typescript/fabric-exec/SKILL.md +7 -7
- package/skillsets/typescript/fabric-exec/references/agents.md +12 -3
- package/skillsets/typescript/fabric-fusion/SKILL.md +1 -1
- package/skillsets/typescript/fabric-guide/SKILL.md +1 -1
- package/LAWS.bend +0 -502
- package/PROOF.bend +0 -452
- package/dist/chunks/chunk-3UGN25XS.js.map +0 -7
- package/dist/chunks/chunk-4EW7GVUR.js.map +0 -7
- package/dist/chunks/chunk-5UBRGTVN.js.map +0 -7
- package/dist/chunks/chunk-BN7F52EG.js +0 -525
- package/dist/chunks/chunk-BN7F52EG.js.map +0 -7
- package/dist/chunks/chunk-DK35W6U7.js +0 -259
- package/dist/chunks/chunk-DK35W6U7.js.map +0 -7
- package/dist/chunks/chunk-EFETPXU2.js.map +0 -7
- package/dist/chunks/chunk-EHQQ4KCX.js.map +0 -7
- package/dist/chunks/chunk-EKODKR6Y.js.map +0 -7
- package/dist/chunks/chunk-FE6NOAO7.js.map +0 -7
- package/dist/chunks/chunk-FIDUHKMM.js.map +0 -7
- package/dist/chunks/chunk-FSB2VIRZ.js.map +0 -7
- package/dist/chunks/chunk-GIK2WNAK.js.map +0 -7
- package/dist/chunks/chunk-GO32KSEZ.js.map +0 -7
- package/dist/chunks/chunk-IR3PIHJM.js.map +0 -7
- package/dist/chunks/chunk-ITVLKXCI.js +0 -266
- package/dist/chunks/chunk-ITVLKXCI.js.map +0 -7
- package/dist/chunks/chunk-K7J2ABAZ.js.map +0 -7
- package/dist/chunks/chunk-KJZAOENY.js +0 -212
- package/dist/chunks/chunk-KJZAOENY.js.map +0 -7
- package/dist/chunks/chunk-LNASO4VT.js.map +0 -7
- package/dist/chunks/chunk-MLLYR3Y6.js.map +0 -7
- package/dist/chunks/chunk-P4KH4S4S.js.map +0 -7
- package/dist/chunks/chunk-PK4NIJEV.js.map +0 -7
- package/dist/chunks/chunk-Q2JQ3RYZ.js +0 -99
- package/dist/chunks/chunk-Q2JQ3RYZ.js.map +0 -7
- package/dist/chunks/chunk-R2XQ6AHT.js.map +0 -7
- package/dist/chunks/chunk-ROTCDDOV.js.map +0 -7
- package/dist/chunks/chunk-SPCJXN4K.js.map +0 -7
- package/dist/chunks/chunk-U366I5K2.js.map +0 -7
- package/dist/chunks/chunk-UKMQK5VP.js +0 -231
- package/dist/chunks/chunk-UKMQK5VP.js.map +0 -7
- package/dist/chunks/chunk-UOM37PE4.js.map +0 -7
- package/dist/chunks/chunk-UTOBAZ5T.js.map +0 -7
- package/dist/chunks/chunk-VSDUSNIA.js.map +0 -7
- package/dist/chunks/chunk-VTK2FEH7.js +0 -229
- package/dist/chunks/chunk-VTK2FEH7.js.map +0 -7
- package/dist/chunks/chunk-VYQV5JRT.js.map +0 -7
- package/dist/chunks/chunk-XCEEQ5AB.js.map +0 -7
- package/dist/chunks/chunk-ZLNJDTCN.js +0 -226
- package/dist/chunks/chunk-ZLNJDTCN.js.map +0 -7
- package/dist/chunks/chunk-ZQMBS5SH.js.map +0 -7
- package/dist/ui/conversation-shortcut.d.ts +0 -3
- package/dist/ui/conversation-shortcut.d.ts.map +0 -1
- package/dist/ui/widget-activity.d.ts +0 -21
- package/dist/ui/widget-activity.d.ts.map +0 -1
- package/dist/verified/generated/authority-kernel.d.ts +0 -10
- package/dist/verified/generated/authority-kernel.js +0 -127
- package/dist/verified/generated/kernel.d.ts +0 -31
- package/dist/verified/generated/kernel.js +0 -389
- package/dist/verified/generated/lifecycle-kernel.d.ts +0 -7
- package/dist/verified/generated/lifecycle-kernel.js +0 -164
- package/dist/verified/generated/provider-kernel.d.ts +0 -9
- package/dist/verified/generated/provider-kernel.js +0 -87
- package/dist/verified/generated/storage-kernel.d.ts +0 -11
- package/dist/verified/generated/storage-kernel.js +0 -107
- package/docs/licenses/bend-apache-2.0.txt +0 -202
- package/node_modules/pi-coralbricks-provider/README.md +0 -306
- package/node_modules/pi-coralbricks-provider/auth.ts +0 -30
- package/node_modules/pi-coralbricks-provider/custom-models.json +0 -1
- package/node_modules/pi-coralbricks-provider/deprecated-models.json +0 -1
- package/node_modules/pi-coralbricks-provider/guard.ts +0 -155
- package/node_modules/pi-coralbricks-provider/index.ts +0 -662
- package/node_modules/pi-coralbricks-provider/models.json +0 -88
- package/node_modules/pi-coralbricks-provider/package.json +0 -74
- package/node_modules/pi-coralbricks-provider/park.ts +0 -122
- package/node_modules/pi-coralbricks-provider/patch.json +0 -34
- package/node_modules/pi-coralbricks-provider/scripts/update-models.js +0 -658
- package/node_modules/pi-coralbricks-provider/settings.ts +0 -143
- package/node_modules/pi-coralbricks-provider/sync-policy.ts +0 -309
- package/proofs/abi.json +0 -308
- package/proofs/authority-abi.json +0 -7
- package/proofs/authority-kernel.bend +0 -23
- package/proofs/authority-proof.bend +0 -74
- package/proofs/authority-spec.bend +0 -30
- package/proofs/authority-state.bend +0 -43
- package/proofs/authority-types.d.ts +0 -3
- package/proofs/kernel.bend +0 -139
- package/proofs/lifecycle-abi.json +0 -3
- package/proofs/lifecycle-kernel.bend +0 -11
- package/proofs/lifecycle-proof.bend +0 -249
- package/proofs/lifecycle-spec.bend +0 -261
- package/proofs/lifecycle-types.d.ts +0 -4
- package/proofs/lifecycle.bend +0 -119
- package/proofs/provider-abi.json +0 -4
- package/proofs/provider-kernel.bend +0 -14
- package/proofs/provider-plans.bend +0 -28
- package/proofs/provider-spec.bend +0 -14
- package/proofs/provider-types.d.ts +0 -5
- package/proofs/resource-proof.bend +0 -633
- package/proofs/resource-spec.bend +0 -133
- package/proofs/resources.bend +0 -160
- package/proofs/state-kernel.bend +0 -17
- package/proofs/state-plans.bend +0 -40
- package/proofs/state-proof.bend +0 -42
- package/proofs/state-spec.bend +0 -26
- package/proofs/storage-abi.json +0 -3
- package/proofs/storage-kernel.bend +0 -11
- package/proofs/storage-plans.bend +0 -100
- package/proofs/storage-proof.bend +0 -176
- package/proofs/storage-spec.bend +0 -70
- package/proofs/storage-types.d.ts +0 -8
- package/proofs/types.d.ts +0 -7
- package/scripts/test-verified-kernels.mjs +0 -107
- package/scripts/verified-kernels.mjs +0 -176
- /package/dist/chunks/{chunk-3FJUP3GV.js.map → chunk-36XQFTEN.js.map} +0 -0
- /package/dist/chunks/{chunk-ZEXCKK4K.js.map → chunk-4WKD3YM3.js.map} +0 -0
- /package/dist/chunks/{chunk-5XBYFSI5.js.map → chunk-7YNE4NB2.js.map} +0 -0
- /package/dist/chunks/{chunk-K6QXUGS5.js.map → chunk-BMAEZNZ5.js.map} +0 -0
- /package/dist/chunks/{chunk-CCHZXF6K.js.map → chunk-CXYJJ3HZ.js.map} +0 -0
- /package/dist/chunks/{chunk-TIIIHPHF.js.map → chunk-GS67KDMV.js.map} +0 -0
- /package/dist/chunks/{chunk-D5NYNIST.js.map → chunk-H57KPL3V.js.map} +0 -0
- /package/dist/chunks/{chunk-INRXG4J5.js.map → chunk-HGD75NZY.js.map} +0 -0
- /package/dist/chunks/{chunk-UXIBKMUM.js.map → chunk-KIFOEBYJ.js.map} +0 -0
- /package/dist/chunks/{chunk-FUY6XVRX.js.map → chunk-MPMEK3IQ.js.map} +0 -0
- /package/dist/chunks/{chunk-HP5P7NBO.js.map → chunk-MSDL7U6Q.js.map} +0 -0
- /package/dist/chunks/{chunk-QT4W5YVB.js.map → chunk-RAA3FAYZ.js.map} +0 -0
- /package/dist/chunks/{chunk-53N2I4QA.js.map → chunk-TXCNZCZP.js.map} +0 -0
- /package/dist/chunks/{chunk-ASSLHWZS.js.map → chunk-UFMYN5TA.js.map} +0 -0
- /package/dist/chunks/{chunk-LEU5CDSL.js.map → chunk-XFOSUGLU.js.map} +0 -0
|
@@ -1,1187 +1,16 @@
|
|
|
1
|
-
// src/durable/worker-host.ts
|
|
2
|
-
import { createHash, randomUUID as randomUUID2 } from "node:crypto";
|
|
3
|
-
import path from "node:path";
|
|
4
|
-
import { BACKGROUND_CONTEXT as BACKGROUND_CONTEXT2 } from "@earendil-works/chord/context";
|
|
5
1
|
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
hasTrustRequiringProjectResources,
|
|
14
|
-
ProjectTrustStore,
|
|
15
|
-
resolveCliModel,
|
|
16
|
-
runRpcMode,
|
|
17
|
-
SessionManager as SessionManager2,
|
|
18
|
-
SettingsManager as SettingsManager2
|
|
19
|
-
} from "@earendil-works/pi-coding-agent";
|
|
20
|
-
|
|
21
|
-
// src/durable/session.ts
|
|
22
|
-
import { homedir } from "node:os";
|
|
23
|
-
import { join, resolve } from "node:path";
|
|
24
|
-
import { clampThinkingLevel } from "@earendil-works/pi-ai/compat";
|
|
25
|
-
import {
|
|
26
|
-
AgentSession,
|
|
27
|
-
convertToLlm,
|
|
28
|
-
DefaultResourceLoader,
|
|
29
|
-
getAgentDir,
|
|
30
|
-
ModelRuntime,
|
|
31
|
-
SessionManager,
|
|
32
|
-
SettingsManager
|
|
33
|
-
} from "@earendil-works/pi-coding-agent";
|
|
34
|
-
|
|
35
|
-
// src/durable/agent.ts
|
|
36
|
-
import { randomUUID } from "node:crypto";
|
|
37
|
-
import { AsyncLocalStorage } from "node:async_hooks";
|
|
38
|
-
import { BACKGROUND_CONTEXT } from "@earendil-works/chord/context";
|
|
39
|
-
import { Agent, runToolCall } from "@earendil-works/pi-agent-core";
|
|
40
|
-
import { getCurrentSystemMessage, getCurrentTools, getToolStateChanges, toToolDeclaration, normalizeContext } from "@earendil-works/pi-ai";
|
|
41
|
-
import { Harness, createRegistry, defineDoc, defineTask } from "@earendil-works/pi-durable";
|
|
42
|
-
var EVENT = "fabric.agent.event.v1";
|
|
43
|
-
var HISTORY = "fabric.agent.history.v1";
|
|
44
|
-
var copy = (value) => JSON.parse(JSON.stringify(value));
|
|
45
|
-
var wire = (value) => copy(value);
|
|
46
|
-
var TRANSIENT = "fabricTransient";
|
|
47
|
-
var Ledger = defineDoc({
|
|
48
|
-
kind: "fabric.agent.ledger",
|
|
49
|
-
version: 1,
|
|
50
|
-
scope: "conversation",
|
|
51
|
-
history: "latest",
|
|
52
|
-
fork: "initial",
|
|
53
|
-
initial: () => ({ runId: "", requests: {}, active: 0, steering: [], followup: [] })
|
|
54
|
-
});
|
|
55
|
-
var DurableAgent = class extends Agent {
|
|
56
|
-
durableOptions;
|
|
57
|
-
observers = /* @__PURE__ */ new Set();
|
|
58
|
-
registry = createRegistry();
|
|
59
|
-
engine;
|
|
60
|
-
root;
|
|
61
|
-
opening;
|
|
62
|
-
releaseStartup;
|
|
63
|
-
startup = new Promise((resolve3) => {
|
|
64
|
-
this.releaseStartup = resolve3;
|
|
65
|
-
});
|
|
66
|
-
/** Reconcile committed history without replaying events, before any recovered task runs. */
|
|
67
|
-
recoverHistory;
|
|
68
|
-
delivery = Promise.resolve();
|
|
69
|
-
admission = Promise.resolve();
|
|
70
|
-
running;
|
|
71
|
-
controller;
|
|
72
|
-
requestId;
|
|
73
|
-
firstRequest = true;
|
|
74
|
-
closing = false;
|
|
75
|
-
closeRequested = false;
|
|
76
|
-
closed;
|
|
77
|
-
active = false;
|
|
78
|
-
partial;
|
|
79
|
-
failure;
|
|
80
|
-
pending = /* @__PURE__ */ new Set();
|
|
81
|
-
emitted = [];
|
|
82
|
-
restored = false;
|
|
83
|
-
resetPending = false;
|
|
84
|
-
queuePreview = [];
|
|
85
|
-
transient = /* @__PURE__ */ new Map();
|
|
86
|
-
transientSequence = 0;
|
|
87
|
-
// Harness keeps its scheduler alive between requests. Never inherit the
|
|
88
|
-
// scheduler's first-request permission/extension scope for later work.
|
|
89
|
-
requestScope = AsyncLocalStorage.snapshot();
|
|
90
|
-
toolTask;
|
|
91
|
-
runTask;
|
|
92
|
-
constructor(options) {
|
|
93
|
-
super(options);
|
|
94
|
-
if (!options.runId) throw new Error("DurableAgent requires a non-empty runId");
|
|
95
|
-
this.durableOptions = options;
|
|
96
|
-
Object.defineProperties(super.state, {
|
|
97
|
-
isStreaming: { get: () => this.active },
|
|
98
|
-
streamingMessage: { get: () => this.partial },
|
|
99
|
-
pendingToolCalls: { get: () => this.pending },
|
|
100
|
-
errorMessage: { get: () => this.failure }
|
|
101
|
-
});
|
|
102
|
-
this.toolTask = this.scopedTask({
|
|
103
|
-
name: "fabric.agent.tool",
|
|
104
|
-
version: 1,
|
|
105
|
-
initial: () => ({ phase: "execute" }),
|
|
106
|
-
phases: { execute: async (task, runtime, ctx) => {
|
|
107
|
-
await this.delivery;
|
|
108
|
-
const { call, message } = task.input;
|
|
109
|
-
const context = await this.executionContext();
|
|
110
|
-
const tool = context.tools?.find((t) => t.name === call.name);
|
|
111
|
-
const prior = await runtime.memo("intent", ctx);
|
|
112
|
-
if (!prior) {
|
|
113
|
-
await runtime.memo("intent", true, ctx);
|
|
114
|
-
await runtime.commit(async (tx) => {
|
|
115
|
-
await this.event(tx, { type: "tool_execution_start", toolCallId: call.id, toolName: call.name, args: call.arguments });
|
|
116
|
-
}, ctx);
|
|
117
|
-
await this.delivery;
|
|
118
|
-
}
|
|
119
|
-
const outcome = prior && !(task.input.replaySafe === true && tool?.replay === "safe") ? { isError: true, result: { content: [{ type: "text", text: "Tool execution interrupted; unsafe effect was not replayed." }], details: { interrupted: true } } } : await runToolCall(call, {
|
|
120
|
-
tools: context.tools ?? [],
|
|
121
|
-
assistantMessage: message,
|
|
122
|
-
context,
|
|
123
|
-
signal: runtime.signal,
|
|
124
|
-
...this.beforeToolCall ? { beforeToolCall: this.beforeToolCall } : {},
|
|
125
|
-
...this.afterToolCall ? { afterToolCall: this.afterToolCall } : {},
|
|
126
|
-
onUpdate: async (result2) => {
|
|
127
|
-
await this.transientEvent((change) => runtime.commit(change, ctx), { type: "tool_execution_update", toolCallId: call.id, toolName: call.name, args: call.arguments, partialResult: result2 });
|
|
128
|
-
}
|
|
129
|
-
});
|
|
130
|
-
const result = {
|
|
131
|
-
role: "toolResult",
|
|
132
|
-
toolCallId: call.id,
|
|
133
|
-
toolName: call.name,
|
|
134
|
-
content: outcome.result.content ?? [],
|
|
135
|
-
details: outcome.result.details,
|
|
136
|
-
isError: outcome.isError,
|
|
137
|
-
...outcome.result.usage ? { usage: outcome.result.usage } : {},
|
|
138
|
-
timestamp: Date.now()
|
|
139
|
-
};
|
|
140
|
-
await runtime.commit(async (tx) => {
|
|
141
|
-
await this.event(tx, { type: "tool_execution_end", toolCallId: call.id, toolName: call.name, result: outcome.result, isError: outcome.isError });
|
|
142
|
-
return { status: "terminal", outcome: { status: "completed", result: copy({ ...result, terminate: "terminate" in outcome.result && outcome.result.terminate === true }) } };
|
|
143
|
-
}, ctx);
|
|
144
|
-
} },
|
|
145
|
-
abort: async (task, runtime, ctx) => {
|
|
146
|
-
const { call } = task.input;
|
|
147
|
-
const result = { role: "toolResult", toolCallId: call.id, toolName: call.name, content: [{ type: "text", text: "Tool execution aborted" }], isError: true, timestamp: Date.now() };
|
|
148
|
-
await runtime.commit(async (tx) => {
|
|
149
|
-
await this.event(tx, { type: "tool_execution_end", toolCallId: call.id, toolName: call.name, result, isError: true });
|
|
150
|
-
return { status: "terminal", outcome: { status: "completed", result } };
|
|
151
|
-
}, ctx);
|
|
152
|
-
}
|
|
153
|
-
});
|
|
154
|
-
this.runTask = this.scopedTask({
|
|
155
|
-
name: "fabric.agent.run",
|
|
156
|
-
version: 1,
|
|
157
|
-
initial: () => ({ phase: "prepare" }),
|
|
158
|
-
phases: {
|
|
159
|
-
prepare: async (task, runtime, ctx) => {
|
|
160
|
-
await this.delivery;
|
|
161
|
-
let context = await this.executionContext();
|
|
162
|
-
const saved = await this.engine.snapshot(Ledger, runtime.conversationId, ctx);
|
|
163
|
-
let model = saved?.config?.model ?? this.state.model;
|
|
164
|
-
let thinking = saved?.config?.thinking ?? this.state.thinkingLevel;
|
|
165
|
-
if (task.state.checkpoint.next) {
|
|
166
|
-
const turn = { ...task.state.checkpoint.next, context };
|
|
167
|
-
const update2 = this.prepareNextTurnWithContext ? await this.prepareNextTurnWithContext(turn, runtime.signal) : await this.prepareNextTurn?.(runtime.signal);
|
|
168
|
-
if (update2?.context) context = update2.context;
|
|
169
|
-
model = update2?.model ?? model;
|
|
170
|
-
thinking = update2?.thinkingLevel ?? thinking;
|
|
171
|
-
await runtime.commit(async (tx) => {
|
|
172
|
-
await this.event(tx, { type: "turn_start" });
|
|
173
|
-
}, ctx);
|
|
174
|
-
await this.delivery;
|
|
175
|
-
if (update2?.messages?.length) {
|
|
176
|
-
const additions = update2.messages;
|
|
177
|
-
await runtime.commit(async (tx) => {
|
|
178
|
-
for (const m of additions) await this.message(tx, m);
|
|
179
|
-
}, ctx);
|
|
180
|
-
await this.delivery;
|
|
181
|
-
context = { ...context, messages: [...context.messages, ...additions] };
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
await this.admission;
|
|
185
|
-
await runtime.commit(async (tx) => {
|
|
186
|
-
const ledger = await tx.doc(Ledger, runtime.conversationId);
|
|
187
|
-
const queued = task.state.checkpoint.pending?.map(wire) ?? (task.state.checkpoint.skipSteering ? [] : ledger.steering.splice(0, this.steeringMode === "all" ? ledger.steering.length : 1));
|
|
188
|
-
for (const value of queued) {
|
|
189
|
-
const message = value;
|
|
190
|
-
await this.message(tx, message);
|
|
191
|
-
context.messages.push(message);
|
|
192
|
-
}
|
|
193
|
-
const changes = getToolStateChanges(getCurrentTools(context.messages), (context.tools ?? []).map(toToolDeclaration));
|
|
194
|
-
if (changes.toolsAdded.length || changes.toolsRemoved.length) {
|
|
195
|
-
const message = { role: "system", content: "", timestamp: Date.now(), ...changes };
|
|
196
|
-
await this.message(tx, message);
|
|
197
|
-
context.messages.push(message);
|
|
198
|
-
}
|
|
199
|
-
}, ctx);
|
|
200
|
-
await this.delivery;
|
|
201
|
-
const update = await this.prepareRequest?.({ context, model, thinkingLevel: thinking }, runtime.signal);
|
|
202
|
-
context = update?.context ?? context;
|
|
203
|
-
model = update?.model ?? model;
|
|
204
|
-
thinking = update?.thinkingLevel ?? thinking;
|
|
205
|
-
const transformed = this.transformContext ? await this.transformContext(context.messages, runtime.signal) : context.messages;
|
|
206
|
-
const messages = await this.convertToLlm(transformed);
|
|
207
|
-
await runtime.commit(async (tx) => {
|
|
208
|
-
const ledger = await tx.doc(Ledger, runtime.conversationId);
|
|
209
|
-
ledger.config = { model: wire(model), thinking };
|
|
210
|
-
if ((context.tools ?? []).some((tool) => !this.state.tools.includes(tool))) throw new Error("Durable request tools must be registered in agent.state.tools");
|
|
211
|
-
ledger.context = { messages: context.messages.map(wire), tools: (context.tools ?? []).map((tool) => tool.name) };
|
|
212
|
-
return { status: "running", checkpoint: { phase: "model", messages: copy(messages), model: copy(model), thinking } };
|
|
213
|
-
}, ctx);
|
|
214
|
-
},
|
|
215
|
-
model: async (task, runtime, ctx) => {
|
|
216
|
-
await this.delivery;
|
|
217
|
-
const cp = task.state.checkpoint;
|
|
218
|
-
const stream = await this.streamFunction(cp.model, normalizeContext({ messages: cp.messages }), {
|
|
219
|
-
signal: runtime.signal,
|
|
220
|
-
...cp.thinking === "off" ? {} : { reasoning: cp.thinking },
|
|
221
|
-
...this.sessionId ? { sessionId: this.sessionId } : {},
|
|
222
|
-
...this.thinkingBudgets ? { thinkingBudgets: this.thinkingBudgets } : {},
|
|
223
|
-
transport: this.transport,
|
|
224
|
-
...this.maxRetryDelayMs !== void 0 ? { maxRetryDelayMs: this.maxRetryDelayMs } : {},
|
|
225
|
-
...this.getApiKey ? { apiKey: await this.getApiKey(cp.model.provider) ?? "" } : {},
|
|
226
|
-
...this.onPayload ? { onPayload: this.onPayload } : {},
|
|
227
|
-
...this.onResponse ? { onResponse: this.onResponse } : {},
|
|
228
|
-
...this.onProviderStreamEvent ? { onProviderStreamEvent: this.onProviderStreamEvent } : {}
|
|
229
|
-
});
|
|
230
|
-
let started = false;
|
|
231
|
-
for await (const event of stream) {
|
|
232
|
-
if (event.type === "done" || event.type === "error") continue;
|
|
233
|
-
if (!started) {
|
|
234
|
-
await runtime.commit(async (tx) => {
|
|
235
|
-
await this.event(tx, { type: "message_start", message: event.partial });
|
|
236
|
-
}, ctx);
|
|
237
|
-
await this.delivery;
|
|
238
|
-
}
|
|
239
|
-
started = true;
|
|
240
|
-
if (event.type !== "start") await this.transientEvent((change) => runtime.commit(change, ctx), { type: "message_update", message: event.partial, assistantMessageEvent: event });
|
|
241
|
-
}
|
|
242
|
-
const message = copy({ ...await stream.result(), thinkingLevel: cp.thinking });
|
|
243
|
-
await runtime.commit(async (tx) => {
|
|
244
|
-
if (!started) await this.event(tx, { type: "message_start", message });
|
|
245
|
-
await this.event(tx, { type: "message_end", message });
|
|
246
|
-
const calls = message.stopReason !== "error" && message.stopReason !== "aborted" ? message.content.filter((c) => c.type === "toolCall") : [];
|
|
247
|
-
if (message.stopReason === "length" && calls.length) {
|
|
248
|
-
const results = [];
|
|
249
|
-
for (const call of calls) {
|
|
250
|
-
const result = { content: [{ type: "text", text: "Tool call was truncated by the output token limit; execution refused." }], details: {} };
|
|
251
|
-
await this.event(tx, { type: "tool_execution_start", toolCallId: call.id, toolName: call.name, args: call.arguments });
|
|
252
|
-
await this.event(tx, { type: "tool_execution_end", toolCallId: call.id, toolName: call.name, result, isError: true });
|
|
253
|
-
const toolResult = { role: "toolResult", toolCallId: call.id, toolName: call.name, ...result, isError: true, timestamp: Date.now() };
|
|
254
|
-
results.push(toolResult);
|
|
255
|
-
await this.message(tx, toolResult);
|
|
256
|
-
}
|
|
257
|
-
return { status: "running", checkpoint: { phase: "boundary", message, results } };
|
|
258
|
-
}
|
|
259
|
-
const sequential = this.toolExecution === "sequential" || calls.some((c) => this.state.tools.find((t) => t.name === c.name)?.executionMode === "sequential");
|
|
260
|
-
const children = [];
|
|
261
|
-
for (const call of sequential ? calls.slice(0, 1) : calls) children.push(await tx.createTask(this.toolTask, { message, call, replaySafe: this.state.tools.find((t) => t.name === call.name)?.replay === "safe" }, { ownership: { kind: "task", taskId: task.id } }));
|
|
262
|
-
return children.length ? { status: "waiting", checkpoint: { phase: "tools", message, children }, on: children, policy: "allSettled" } : { status: "running", checkpoint: { phase: "boundary", message, results: [] } };
|
|
263
|
-
}, ctx);
|
|
264
|
-
},
|
|
265
|
-
tools: async (task, runtime, ctx) => {
|
|
266
|
-
await this.delivery;
|
|
267
|
-
const { message, children } = task.state.checkpoint;
|
|
268
|
-
const calls = message.content.filter((c) => c.type === "toolCall");
|
|
269
|
-
if (children.length < calls.length) {
|
|
270
|
-
await runtime.commit(async (tx) => {
|
|
271
|
-
const child = await tx.createTask(this.toolTask, { message, call: calls[children.length], replaySafe: this.state.tools.find((t) => t.name === calls[children.length].name)?.replay === "safe" }, { ownership: { kind: "task", taskId: task.id } });
|
|
272
|
-
return { status: "waiting", checkpoint: { phase: "tools", message, children: [...children, child] }, on: [child], policy: "allSettled" };
|
|
273
|
-
}, ctx);
|
|
274
|
-
return;
|
|
275
|
-
}
|
|
276
|
-
const outcomes = await runtime.outcomes(children, ctx);
|
|
277
|
-
const results = outcomes.map((o, index) => o.status === "completed" ? o.result : {
|
|
278
|
-
role: "toolResult",
|
|
279
|
-
toolCallId: calls[index].id,
|
|
280
|
-
toolName: calls[index].name,
|
|
281
|
-
content: [{ type: "text", text: `Tool task ${o.status}` }],
|
|
282
|
-
isError: true,
|
|
283
|
-
timestamp: Date.now()
|
|
284
|
-
});
|
|
285
|
-
const terminate = results.length > 0 && results.every((r) => r.terminate);
|
|
286
|
-
for (const result of results) delete result.terminate;
|
|
287
|
-
await runtime.commit(async (tx) => {
|
|
288
|
-
for (const result of results) await this.message(tx, result);
|
|
289
|
-
return { status: "running", checkpoint: copy({ phase: "boundary", message, results, terminate }) };
|
|
290
|
-
}, ctx);
|
|
291
|
-
},
|
|
292
|
-
boundary: async (task, runtime, ctx) => {
|
|
293
|
-
await this.delivery;
|
|
294
|
-
const { message, results, terminate } = task.state.checkpoint;
|
|
295
|
-
const decision = await this.finishTurn?.({ message: this.lastAssistant(message), toolResults: this.canonicalToolResults(results), context: await this.executionContext(), newMessages: this.emitted.slice() }, runtime.signal);
|
|
296
|
-
await runtime.commit(async (tx) => {
|
|
297
|
-
await this.event(tx, { type: "turn_end", message, toolResults: results });
|
|
298
|
-
return { status: "running", checkpoint: { phase: "decide", message, results, ...decision ? { action: decision.action } : {}, ...terminate ? { terminate: true } : {} } };
|
|
299
|
-
}, ctx);
|
|
300
|
-
},
|
|
301
|
-
decide: async (task, runtime, ctx) => {
|
|
302
|
-
await this.delivery;
|
|
303
|
-
await this.admission;
|
|
304
|
-
const cp = task.state.checkpoint;
|
|
305
|
-
await runtime.commit(async (tx) => {
|
|
306
|
-
const ledger = await tx.doc(Ledger, runtime.conversationId);
|
|
307
|
-
const hardEnd = cp.message.stopReason === "error" || cp.message.stopReason === "aborted" || cp.action === "end";
|
|
308
|
-
let queued = [];
|
|
309
|
-
if (!hardEnd) {
|
|
310
|
-
queued = ledger.steering.splice(0, this.steeringMode === "all" ? ledger.steering.length : 1);
|
|
311
|
-
if (!queued.length && (!cp.results.length || cp.terminate) && cp.action !== "continue") queued = ledger.followup.splice(0, this.followUpMode === "all" ? ledger.followup.length : 1);
|
|
312
|
-
}
|
|
313
|
-
if (!hardEnd && (queued.length || cp.results.length && !cp.terminate || cp.action === "continue")) {
|
|
314
|
-
const next = copy({ message: cp.message, toolResults: cp.results, newMessages: this.emitted.slice() });
|
|
315
|
-
return { status: "running", checkpoint: { phase: "prepare", next, ...queued.length ? { pending: copy(queued) } : {}, skipSteering: queued.length > 0 } };
|
|
316
|
-
}
|
|
317
|
-
ledger.active = 0;
|
|
318
|
-
await this.event(tx, { type: "agent_end", messages: this.emitted.slice() });
|
|
319
|
-
return { status: "terminal", outcome: { status: "completed", result: null } };
|
|
320
|
-
}, ctx);
|
|
321
|
-
}
|
|
322
|
-
},
|
|
323
|
-
abort: async (task, runtime, ctx) => {
|
|
324
|
-
await this.delivery;
|
|
325
|
-
const results = [];
|
|
326
|
-
if (task.state.checkpoint.phase === "tools") {
|
|
327
|
-
const { message, children } = task.state.checkpoint;
|
|
328
|
-
const calls = message.content.filter((c) => c.type === "toolCall");
|
|
329
|
-
for (const [index, call] of calls.entries()) {
|
|
330
|
-
const child = children[index] ? await runtime.getTask(children[index], ctx) : void 0;
|
|
331
|
-
const outcome = child?.state.status === "terminal" ? child.state.outcome : void 0;
|
|
332
|
-
const result = outcome?.status === "completed" ? copy(outcome.result) : {
|
|
333
|
-
role: "toolResult",
|
|
334
|
-
toolCallId: call.id,
|
|
335
|
-
toolName: call.name,
|
|
336
|
-
content: [{ type: "text", text: "Tool execution aborted" }],
|
|
337
|
-
isError: true,
|
|
338
|
-
timestamp: Date.now()
|
|
339
|
-
};
|
|
340
|
-
delete result.terminate;
|
|
341
|
-
results.push(result);
|
|
342
|
-
}
|
|
343
|
-
}
|
|
344
|
-
await runtime.commit(async (tx) => {
|
|
345
|
-
const ledger = await tx.doc(Ledger, runtime.conversationId);
|
|
346
|
-
ledger.active = 0;
|
|
347
|
-
for (const result of results) await this.message(tx, result);
|
|
348
|
-
const message = this.failureMessage("Operation aborted", true);
|
|
349
|
-
await this.message(tx, message);
|
|
350
|
-
await this.event(tx, { type: "turn_end", message, toolResults: results });
|
|
351
|
-
await this.event(tx, { type: "agent_end", messages: [...this.emitted, ...results, message] });
|
|
352
|
-
return { status: "terminal", outcome: { status: "aborted" } };
|
|
353
|
-
}, ctx);
|
|
354
|
-
}
|
|
355
|
-
});
|
|
356
|
-
this.registry.install({ name: "fabric-agent", tasks: [this.runTask, this.toolTask] });
|
|
357
|
-
}
|
|
358
|
-
scopedTask(definition) {
|
|
359
|
-
const phases = Object.fromEntries(Object.entries(definition.phases).map(([name, handler]) => [
|
|
360
|
-
name,
|
|
361
|
-
async (...args) => {
|
|
362
|
-
if (!await this.startup) throw new Error("DurableAgent recovery failed");
|
|
363
|
-
return this.requestScope(handler, ...args);
|
|
364
|
-
}
|
|
365
|
-
]));
|
|
366
|
-
const abort = definition.abort;
|
|
367
|
-
return defineTask({ ...definition, phases, ...abort ? { abort: async (...args) => {
|
|
368
|
-
if (!await this.startup) throw new Error("DurableAgent recovery failed");
|
|
369
|
-
return this.requestScope(abort, ...args);
|
|
370
|
-
} } : {} });
|
|
371
|
-
}
|
|
372
|
-
failureMessage(errorMessage, aborted) {
|
|
373
|
-
return {
|
|
374
|
-
role: "assistant",
|
|
375
|
-
content: [],
|
|
376
|
-
api: this.state.model.api,
|
|
377
|
-
provider: this.state.model.provider,
|
|
378
|
-
model: this.state.model.id,
|
|
379
|
-
usage: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, totalTokens: 0, cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 } },
|
|
380
|
-
stopReason: aborted ? "aborted" : "error",
|
|
381
|
-
errorMessage,
|
|
382
|
-
timestamp: Date.now()
|
|
383
|
-
};
|
|
384
|
-
}
|
|
385
|
-
context() {
|
|
386
|
-
return { messages: this.state.messages.slice(), tools: this.state.tools.slice() };
|
|
387
|
-
}
|
|
388
|
-
async executionContext() {
|
|
389
|
-
const saved = await this.engine.snapshot(Ledger, this.root.id, BACKGROUND_CONTEXT);
|
|
390
|
-
if (!saved?.context) return this.context();
|
|
391
|
-
return { messages: copy(saved.context.messages), tools: this.state.tools.filter((tool) => saved.context.tools.includes(tool.name)) };
|
|
392
|
-
}
|
|
393
|
-
canonicalToolResults(results) {
|
|
394
|
-
const messages = this.state.messages.slice().reverse();
|
|
395
|
-
return results.map((result) => messages.find((message) => message.role === "toolResult" && message.toolCallId === result.toolCallId) ?? result);
|
|
396
|
-
}
|
|
397
|
-
lastAssistant(fallback) {
|
|
398
|
-
return this.state.messages.slice().reverse().find((m) => m.role === "assistant") ?? fallback;
|
|
399
|
-
}
|
|
400
|
-
async event(tx, event) {
|
|
401
|
-
await tx.appendEntry(this.root.id, { kind: EVENT, data: wire(event) });
|
|
402
|
-
if (event.type === "message_end") {
|
|
403
|
-
const ledger = await tx.doc(Ledger, this.root.id);
|
|
404
|
-
ledger.context?.messages.push(wire(event.message));
|
|
405
|
-
}
|
|
406
|
-
}
|
|
407
|
-
/** Commit an ordered, slim marker for a streaming update; its payload stays in memory until delivery. */
|
|
408
|
-
async transientEvent(commit, event) {
|
|
409
|
-
const sequence = ++this.transientSequence;
|
|
410
|
-
this.transient.set(sequence, copy(event));
|
|
411
|
-
let marker;
|
|
412
|
-
if (event.type === "message_update") {
|
|
413
|
-
const { partial: _partial, ...delta } = event.assistantMessageEvent;
|
|
414
|
-
marker = { type: event.type, assistantMessageEvent: delta };
|
|
415
|
-
} else marker = { type: event.type, toolCallId: event.toolCallId, toolName: event.toolName };
|
|
416
|
-
try {
|
|
417
|
-
await commit(async (tx) => {
|
|
418
|
-
await tx.appendEntry(this.root.id, { kind: EVENT, data: wire({ ...marker, [TRANSIENT]: sequence }) });
|
|
419
|
-
return void 0;
|
|
420
|
-
});
|
|
421
|
-
} catch (error) {
|
|
422
|
-
this.transient.delete(sequence);
|
|
423
|
-
throw error;
|
|
424
|
-
}
|
|
425
|
-
await this.delivery;
|
|
426
|
-
}
|
|
427
|
-
/** Restore a committed streaming marker to the full event; undefined when its payload is not in this process. */
|
|
428
|
-
rehydrate(data) {
|
|
429
|
-
const sequence = data[TRANSIENT];
|
|
430
|
-
if (typeof sequence !== "number") return data;
|
|
431
|
-
const event = this.transient.get(sequence);
|
|
432
|
-
this.transient.delete(sequence);
|
|
433
|
-
return event;
|
|
434
|
-
}
|
|
435
|
-
async message(tx, message) {
|
|
436
|
-
await this.event(tx, { type: "message_start", message });
|
|
437
|
-
await this.event(tx, { type: "message_end", message });
|
|
438
|
-
}
|
|
439
|
-
async expose(event) {
|
|
440
|
-
if (event.type === "turn_end") event = {
|
|
441
|
-
...event,
|
|
442
|
-
message: event.message.role === "assistant" ? this.lastAssistant(event.message) : event.message,
|
|
443
|
-
toolResults: this.canonicalToolResults(event.toolResults)
|
|
444
|
-
};
|
|
445
|
-
if (event.type === "message_start" && event.message.role === "assistant") this.partial = event.message;
|
|
446
|
-
if (event.type === "message_update") this.partial = event.message;
|
|
447
|
-
if (event.type === "message_end") {
|
|
448
|
-
this.state.messages = [...this.state.messages, event.message];
|
|
449
|
-
this.emitted.push(event.message);
|
|
450
|
-
this.partial = void 0;
|
|
451
|
-
if (event.message.role === "assistant") this.failure = event.message.errorMessage;
|
|
452
|
-
const index = this.queuePreview.findIndex((q) => JSON.stringify(q.message) === JSON.stringify(event.message));
|
|
453
|
-
if (index >= 0) this.queuePreview.splice(index, 1);
|
|
454
|
-
}
|
|
455
|
-
if (event.type === "tool_execution_start") this.pending.add(event.toolCallId);
|
|
456
|
-
if (event.type === "tool_execution_end") this.pending.delete(event.toolCallId);
|
|
457
|
-
for (const observer of this.observers) await observer(event, this.controller?.signal ?? new AbortController().signal);
|
|
458
|
-
}
|
|
459
|
-
async open() {
|
|
460
|
-
if (this.closing) throw new Error("DurableAgent is closed");
|
|
461
|
-
return this.opening ??= (async () => {
|
|
462
|
-
const borrowed = new Proxy(this.durableOptions.storage, { get(target, key) {
|
|
463
|
-
if (key === "close") return async () => {
|
|
464
|
-
};
|
|
465
|
-
const value = Reflect.get(target, key, target);
|
|
466
|
-
return typeof value === "function" ? value.bind(target) : value;
|
|
467
|
-
} });
|
|
468
|
-
const harness = await Harness.open(borrowed, { models: this.durableOptions.models, registry: this.registry }, BACKGROUND_CONTEXT);
|
|
469
|
-
this.engine = harness;
|
|
470
|
-
this.root = await harness.root(BACKGROUND_CONTEXT);
|
|
471
|
-
const ledger = await harness.snapshot(Ledger, this.root.id, BACKGROUND_CONTEXT);
|
|
472
|
-
if (ledger?.runId && ledger.runId !== this.durableOptions.runId) throw new Error("DurableAgent storage belongs to a different runId");
|
|
473
|
-
const history = (await this.root.context(BACKGROUND_CONTEXT)).entries;
|
|
474
|
-
const messages = [];
|
|
475
|
-
for (const entry of history) {
|
|
476
|
-
if (entry.kind === HISTORY) {
|
|
477
|
-
messages.splice(0, messages.length, ...entry.data);
|
|
478
|
-
this.restored = true;
|
|
479
|
-
}
|
|
480
|
-
if (entry.kind === EVENT) {
|
|
481
|
-
const event = entry.data;
|
|
482
|
-
if (event.type === "agent_start") this.emitted = [];
|
|
483
|
-
if (event.type === "message_end") {
|
|
484
|
-
messages.push(event.message);
|
|
485
|
-
this.emitted.push(event.message);
|
|
486
|
-
}
|
|
487
|
-
}
|
|
488
|
-
}
|
|
489
|
-
if (this.restored && !this.resetPending) this.state.messages = messages;
|
|
490
|
-
if (this.restored && !this.resetPending) await this.recoverHistory?.(copy(messages));
|
|
491
|
-
this.queuePreview = [...this.queuePreview, ...(ledger?.steering ?? []).map((message) => ({ mode: "steering", message })), ...(ledger?.followup ?? []).map((message) => ({ mode: "followup", message }))];
|
|
492
|
-
harness.subscribeCommits((publication) => {
|
|
493
|
-
for (const change of publication.changes) {
|
|
494
|
-
if (change.type !== "entry" || change.value.conversationId !== this.root.id || change.value.kind !== EVENT) continue;
|
|
495
|
-
const event = this.rehydrate(copy(change.value.data));
|
|
496
|
-
if (!event) continue;
|
|
497
|
-
this.delivery = this.delivery.then(() => this.requestScope(() => this.expose(event)));
|
|
498
|
-
void this.delivery.catch(() => {
|
|
499
|
-
});
|
|
500
|
-
}
|
|
501
|
-
});
|
|
502
|
-
this.releaseStartup(true);
|
|
503
|
-
})().catch((error) => {
|
|
504
|
-
this.releaseStartup(false);
|
|
505
|
-
throw error;
|
|
506
|
-
});
|
|
507
|
-
}
|
|
508
|
-
/** Resolves only after all controls accepted so far have committed. */
|
|
509
|
-
awaitControls() {
|
|
510
|
-
return this.admission;
|
|
511
|
-
}
|
|
512
|
-
setRequestId(id) {
|
|
513
|
-
if (!id) throw new Error("requestId must not be empty");
|
|
514
|
-
this.requestId = id;
|
|
515
|
-
}
|
|
516
|
-
subscribe(listener) {
|
|
517
|
-
this.observers.add(listener);
|
|
518
|
-
return () => {
|
|
519
|
-
this.observers.delete(listener);
|
|
520
|
-
};
|
|
521
|
-
}
|
|
522
|
-
get signal() {
|
|
523
|
-
return this.controller?.signal;
|
|
524
|
-
}
|
|
525
|
-
waitForIdle() {
|
|
526
|
-
return this.running ?? Promise.resolve();
|
|
527
|
-
}
|
|
528
|
-
abort() {
|
|
529
|
-
this.controller?.abort();
|
|
530
|
-
if (this.root && this.active) {
|
|
531
|
-
const aborting = this.root.abort(BACKGROUND_CONTEXT);
|
|
532
|
-
this.admission = this.admission.then(() => aborting);
|
|
533
|
-
void this.admission.catch(() => {
|
|
534
|
-
});
|
|
535
|
-
}
|
|
536
|
-
}
|
|
537
|
-
prompt(input, images) {
|
|
538
|
-
const messages = typeof input === "string" ? [{ role: "user", content: images?.length ? [{ type: "text", text: input }, ...images] : input, timestamp: Date.now() }] : Array.isArray(input) ? input : [input];
|
|
539
|
-
return this.start(messages);
|
|
540
|
-
}
|
|
541
|
-
continue() {
|
|
542
|
-
return this.start([]);
|
|
543
|
-
}
|
|
544
|
-
start(messages) {
|
|
545
|
-
if (this.active) return Promise.reject(new Error("Agent is already processing a prompt"));
|
|
546
|
-
if (this.closeRequested) return Promise.reject(new Error("DurableAgent is closed"));
|
|
547
|
-
const request = this.requestId ?? (this.firstRequest && messages.length ? this.durableOptions.runId : randomUUID());
|
|
548
|
-
this.requestId = void 0;
|
|
549
|
-
this.firstRequest = false;
|
|
550
|
-
this.requestScope = AsyncLocalStorage.snapshot();
|
|
551
|
-
this.active = true;
|
|
552
|
-
this.failure = void 0;
|
|
553
|
-
this.emitted = [];
|
|
554
|
-
this.controller = new AbortController();
|
|
555
|
-
const run = (async () => {
|
|
556
|
-
await this.open();
|
|
557
|
-
await this.admission;
|
|
558
|
-
let id;
|
|
559
|
-
await this.root.commit(async (tx) => {
|
|
560
|
-
const ledger = await tx.doc(Ledger, this.root.id);
|
|
561
|
-
ledger.runId = this.durableOptions.runId;
|
|
562
|
-
if (Object.hasOwn(ledger.requests, request)) {
|
|
563
|
-
id = ledger.requests[request];
|
|
564
|
-
return;
|
|
565
|
-
}
|
|
566
|
-
if (ledger.active) {
|
|
567
|
-
if (messages.length) throw new Error("Unfinished durable run: resume with continue() or its original requestId");
|
|
568
|
-
id = ledger.active;
|
|
569
|
-
ledger.requests = { ...ledger.requests, [request]: id };
|
|
570
|
-
return;
|
|
571
|
-
}
|
|
572
|
-
if (!messages.length) {
|
|
573
|
-
const last = this.state.messages.at(-1);
|
|
574
|
-
if (!last || this.state.messages.every((m) => m.role === "system")) throw new Error("No messages to continue from");
|
|
575
|
-
if (last.role === "assistant") {
|
|
576
|
-
const queue = ledger.steering.length ? ledger.steering : ledger.followup;
|
|
577
|
-
const mode = ledger.steering.length ? this.steeringMode : this.followUpMode;
|
|
578
|
-
messages = queue.splice(0, mode === "all" ? queue.length : 1);
|
|
579
|
-
if (!messages.length) throw new Error("Cannot continue from message role: assistant");
|
|
580
|
-
}
|
|
581
|
-
}
|
|
582
|
-
delete ledger.context;
|
|
583
|
-
ledger.config = { model: wire(this.state.model), thinking: this.state.thinkingLevel };
|
|
584
|
-
if (!this.restored || this.resetPending || !ledger.active) {
|
|
585
|
-
await tx.appendEntry(this.root.id, { kind: HISTORY, data: wire(this.state.messages) });
|
|
586
|
-
this.restored = true;
|
|
587
|
-
this.resetPending = false;
|
|
588
|
-
}
|
|
589
|
-
this.emitted = [];
|
|
590
|
-
await this.event(tx, { type: "agent_start" });
|
|
591
|
-
await this.event(tx, { type: "turn_start" });
|
|
592
|
-
for (const message of messages) await this.message(tx, message);
|
|
593
|
-
id = await tx.createTask(this.runTask, { request }, { ownership: { kind: "conversation" } });
|
|
594
|
-
ledger.requests = { ...ledger.requests, [request]: id };
|
|
595
|
-
ledger.active = id;
|
|
596
|
-
}, BACKGROUND_CONTEXT);
|
|
597
|
-
await this.delivery;
|
|
598
|
-
if (this.controller.signal.aborted) await this.engine.abortTask(id, BACKGROUND_CONTEXT);
|
|
599
|
-
const settled = await this.engine.waitForTask(id, BACKGROUND_CONTEXT);
|
|
600
|
-
await this.delivery;
|
|
601
|
-
if (settled.state.outcome.status === "failed" || settled.state.outcome.status === "faulted") {
|
|
602
|
-
const message = this.failureMessage(settled.state.outcome.error.message, false);
|
|
603
|
-
await this.root.commit(async (tx) => {
|
|
604
|
-
const ledger = await tx.doc(Ledger, this.root.id);
|
|
605
|
-
if (ledger.active !== id) return;
|
|
606
|
-
ledger.active = 0;
|
|
607
|
-
await this.message(tx, message);
|
|
608
|
-
await this.event(tx, { type: "turn_end", message, toolResults: [] });
|
|
609
|
-
await this.event(tx, { type: "agent_end", messages: [...this.emitted, message] });
|
|
610
|
-
}, BACKGROUND_CONTEXT);
|
|
611
|
-
await this.delivery;
|
|
612
|
-
}
|
|
613
|
-
})().finally(() => {
|
|
614
|
-
this.active = false;
|
|
615
|
-
this.partial = void 0;
|
|
616
|
-
this.pending.clear();
|
|
617
|
-
this.controller = void 0;
|
|
618
|
-
this.running = void 0;
|
|
619
|
-
});
|
|
620
|
-
this.running = run;
|
|
621
|
-
return run;
|
|
622
|
-
}
|
|
623
|
-
enqueue(mode, message) {
|
|
624
|
-
if (this.closeRequested) throw new Error("DurableAgent is closed");
|
|
625
|
-
const request = this.requestId;
|
|
626
|
-
this.requestId = void 0;
|
|
627
|
-
this.queuePreview.push({ mode, message: copy(message) });
|
|
628
|
-
this.admission = this.admission.then(async () => {
|
|
629
|
-
await this.open();
|
|
630
|
-
await this.root.commit(async (tx) => {
|
|
631
|
-
const ledger = await tx.doc(Ledger, this.root.id);
|
|
632
|
-
ledger.runId ||= this.durableOptions.runId;
|
|
633
|
-
ledger.controls ??= {};
|
|
634
|
-
if (request && Object.hasOwn(ledger.controls, request)) {
|
|
635
|
-
const index = this.queuePreview.findIndex((q) => q.mode === mode && JSON.stringify(q.message) === JSON.stringify(message));
|
|
636
|
-
if (index >= 0) this.queuePreview.splice(index, 1);
|
|
637
|
-
return;
|
|
638
|
-
}
|
|
639
|
-
if (request) ledger.controls = { ...ledger.controls, [request]: true };
|
|
640
|
-
ledger[mode].push(wire(message));
|
|
641
|
-
}, BACKGROUND_CONTEXT);
|
|
642
|
-
});
|
|
643
|
-
void this.admission.catch(() => {
|
|
644
|
-
});
|
|
645
|
-
}
|
|
646
|
-
steer(message) {
|
|
647
|
-
this.enqueue("steering", message);
|
|
648
|
-
}
|
|
649
|
-
followUp(message) {
|
|
650
|
-
this.enqueue("followup", message);
|
|
651
|
-
}
|
|
652
|
-
clear(mode) {
|
|
653
|
-
if (this.closeRequested) throw new Error("DurableAgent is closed");
|
|
654
|
-
this.queuePreview = this.queuePreview.filter((q) => mode !== void 0 && q.mode !== mode);
|
|
655
|
-
this.admission = this.admission.then(async () => {
|
|
656
|
-
await this.open();
|
|
657
|
-
await this.root.commit(async (tx) => {
|
|
658
|
-
const d = await tx.doc(Ledger, this.root.id);
|
|
659
|
-
if (!mode || mode === "steering") d.steering = [];
|
|
660
|
-
if (!mode || mode === "followup") d.followup = [];
|
|
661
|
-
}, BACKGROUND_CONTEXT);
|
|
662
|
-
});
|
|
663
|
-
void this.admission.catch(() => {
|
|
664
|
-
});
|
|
665
|
-
}
|
|
666
|
-
clearSteeringQueue() {
|
|
667
|
-
this.clear("steering");
|
|
668
|
-
}
|
|
669
|
-
clearFollowUpQueue() {
|
|
670
|
-
this.clear("followup");
|
|
671
|
-
}
|
|
672
|
-
clearAllQueues() {
|
|
673
|
-
this.clear();
|
|
674
|
-
}
|
|
675
|
-
hasQueuedMessages() {
|
|
676
|
-
return this.queuePreview.length > 0;
|
|
677
|
-
}
|
|
678
|
-
peekQueuedMessages() {
|
|
679
|
-
const steering = this.queuePreview.filter((q) => q.mode === "steering").map((q) => q.message);
|
|
680
|
-
const followup = this.queuePreview.filter((q) => q.mode === "followup").map((q) => q.message);
|
|
681
|
-
return steering.length ? this.steeringMode === "all" ? steering : steering.slice(0, 1) : this.followUpMode === "all" ? followup : followup.slice(0, 1);
|
|
682
|
-
}
|
|
683
|
-
reset() {
|
|
684
|
-
if (this.active) throw new Error("Cannot reset a running DurableAgent");
|
|
685
|
-
const baseline = getCurrentSystemMessage(this.state.messages);
|
|
686
|
-
this.state.messages = baseline ? [baseline] : [];
|
|
687
|
-
this.partial = void 0;
|
|
688
|
-
this.failure = void 0;
|
|
689
|
-
this.pending.clear();
|
|
690
|
-
this.clearAllQueues();
|
|
691
|
-
this.resetPending = true;
|
|
692
|
-
}
|
|
693
|
-
/** Close cancels invocations, NOT durable tasks. A new Harness resumes their checkpoints. */
|
|
694
|
-
close() {
|
|
695
|
-
this.closeRequested = true;
|
|
696
|
-
return this.closed ??= (async () => {
|
|
697
|
-
const drained = await Promise.allSettled([this.opening, this.admission]);
|
|
698
|
-
this.closing = true;
|
|
699
|
-
if (this.engine) await this.engine.close(BACKGROUND_CONTEXT);
|
|
700
|
-
await this.delivery;
|
|
701
|
-
const rejected = drained.find((result) => result.status === "rejected");
|
|
702
|
-
if (rejected?.status === "rejected") throw rejected.reason;
|
|
703
|
-
})();
|
|
704
|
-
}
|
|
705
|
-
};
|
|
706
|
-
|
|
707
|
-
// src/durable/session.ts
|
|
708
|
-
var absolute = (path2) => resolve(path2 === "~" ? homedir() : path2.startsWith("~/") ? join(homedir(), path2.slice(2)) : path2);
|
|
709
|
-
async function createDurableAgentSession(options) {
|
|
710
|
-
if (!options.runId.trim()) throw new Error("A durable session requires a non-empty runId");
|
|
711
|
-
const cwd = absolute(options.cwd ?? options.sessionManager?.getCwd() ?? process.cwd());
|
|
712
|
-
const agentDir = absolute(options.agentDir ?? getAgentDir());
|
|
713
|
-
const modelRuntime = options.modelRuntime ?? await ModelRuntime.create({
|
|
714
|
-
authPath: join(agentDir, "auth.json"),
|
|
715
|
-
modelsPath: join(agentDir, "models.json")
|
|
716
|
-
});
|
|
717
|
-
const settingsManager = options.settingsManager ?? SettingsManager.create(cwd, agentDir);
|
|
718
|
-
const sessionManager = options.sessionManager ?? SessionManager.create(
|
|
719
|
-
cwd,
|
|
720
|
-
join(agentDir, "sessions", `--${cwd.replace(/^[/\\]/, "").replace(/[/\\:]/g, "-")}--`)
|
|
721
|
-
);
|
|
722
|
-
let resourceLoader = options.resourceLoader;
|
|
723
|
-
if (!resourceLoader) {
|
|
724
|
-
resourceLoader = new DefaultResourceLoader({ cwd, agentDir, settingsManager });
|
|
725
|
-
await resourceLoader.reload();
|
|
726
|
-
}
|
|
727
|
-
const existing = sessionManager.buildSessionContext();
|
|
728
|
-
const branch = sessionManager.getBranch();
|
|
729
|
-
const hasHistory = existing.messages.length > 0;
|
|
730
|
-
const hasThinking = branch.some((entry) => entry.type === "thinking_level_change");
|
|
731
|
-
const lastSelection = branch.slice().reverse().find((entry) => entry.type === "model_change");
|
|
732
|
-
const selected = lastSelection?.type === "model_change" ? modelRuntime.getModel(lastSelection.provider, lastSelection.modelId) : void 0;
|
|
733
|
-
const saved = selected?.api === "pi-virtual" ? selected : existing.model ? modelRuntime.getModel(existing.model.provider, existing.model.modelId) : void 0;
|
|
734
|
-
let model = options.model;
|
|
735
|
-
if (!model && hasHistory && (lastSelection || existing.model)) {
|
|
736
|
-
if (!saved || saved.api !== "pi-virtual" && !modelRuntime.hasConfiguredAuth(saved.provider)) {
|
|
737
|
-
throw new Error("Cannot restore durable session model; explicitly select an available model");
|
|
738
|
-
}
|
|
739
|
-
model = saved;
|
|
740
|
-
}
|
|
741
|
-
if (!model) {
|
|
742
|
-
const available = await modelRuntime.getAvailable();
|
|
743
|
-
const provider = settingsManager.getDefaultProvider();
|
|
744
|
-
const modelId = settingsManager.getDefaultModel();
|
|
745
|
-
model = provider || modelId ? available.find((candidate) => (!provider || candidate.provider === provider) && (!modelId || candidate.id === modelId)) : available[0];
|
|
746
|
-
if (!model && (provider || modelId)) throw new Error(`Configured durable model is unavailable: ${provider ?? "*"}/${modelId ?? "*"}`);
|
|
747
|
-
}
|
|
748
|
-
if (!model) throw new Error("No available model for durable session; supply model and modelRuntime");
|
|
749
|
-
const savedThinking = ["off", "minimal", "low", "medium", "high", "xhigh", "max"].includes(existing.thinkingLevel) ? existing.thinkingLevel : "medium";
|
|
750
|
-
const thinkingLevel = clampThinkingLevel(model, options.thinkingLevel ?? (hasHistory ? hasThinking ? savedThinking : settingsManager.getDefaultThinkingLevel() ?? "medium" : void 0) ?? settingsManager.getModelThinkingLevel(model.provider, model.id) ?? settingsManager.getDefaultThinkingLevel() ?? "medium");
|
|
751
|
-
const extensionRunnerRef = {};
|
|
752
|
-
const agentOptions = {
|
|
753
|
-
initialState: { systemPrompt: "", model, thinkingLevel, tools: [], messages: existing.messages },
|
|
754
|
-
convertToLlm: (messages) => {
|
|
755
|
-
const converted = convertToLlm(messages);
|
|
756
|
-
if (!settingsManager.getBlockImages()) return converted;
|
|
757
|
-
return converted.map((message) => {
|
|
758
|
-
if (message.role !== "user" && message.role !== "toolResult" || !Array.isArray(message.content)) return message;
|
|
759
|
-
return { ...message, content: message.content.map((part) => part.type === "image" ? { type: "text", text: "Image reading is disabled." } : part) };
|
|
760
|
-
});
|
|
761
|
-
},
|
|
762
|
-
transformContext: async (messages) => extensionRunnerRef.current?.emitContext(messages) ?? messages,
|
|
763
|
-
streamFn: (requestModel, context, requestOptions = {}) => {
|
|
764
|
-
const retry = settingsManager.getProviderRetrySettings();
|
|
765
|
-
const idleTimeout = settingsManager.getHttpIdleTimeoutMs();
|
|
766
|
-
const websocketConnectTimeoutMs = requestOptions.websocketConnectTimeoutMs ?? settingsManager.getWebSocketConnectTimeoutMs();
|
|
767
|
-
const maxRetries = requestOptions.maxRetries ?? retry.maxRetries;
|
|
768
|
-
return modelRuntime.streamSimple(requestModel, context, {
|
|
769
|
-
...requestOptions,
|
|
770
|
-
timeoutMs: requestOptions.timeoutMs ?? retry.timeoutMs ?? (idleTimeout === 0 ? 2147483647 : idleTimeout),
|
|
771
|
-
...websocketConnectTimeoutMs !== void 0 ? { websocketConnectTimeoutMs } : {},
|
|
772
|
-
...maxRetries !== void 0 ? { maxRetries } : {},
|
|
773
|
-
maxRetryDelayMs: requestOptions.maxRetryDelayMs ?? retry.maxRetryDelayMs,
|
|
774
|
-
transformHeaders: async (headers) => {
|
|
775
|
-
const transformed = headers;
|
|
776
|
-
const runner = extensionRunnerRef.current;
|
|
777
|
-
return runner?.hasHandlers("before_provider_headers") ? runner.emitBeforeProviderHeaders(transformed ?? {}) : transformed ?? {};
|
|
778
|
-
}
|
|
779
|
-
});
|
|
780
|
-
},
|
|
781
|
-
onPayload: async (payload) => {
|
|
782
|
-
const runner = extensionRunnerRef.current;
|
|
783
|
-
return runner?.hasHandlers("before_provider_request") ? runner.emitBeforeProviderRequest(payload) : payload;
|
|
784
|
-
},
|
|
785
|
-
onResponse: async (response) => {
|
|
786
|
-
const runner = extensionRunnerRef.current;
|
|
787
|
-
if (runner?.hasHandlers("after_provider_response")) {
|
|
788
|
-
await runner.emit({ type: "after_provider_response", status: response.status, headers: response.headers });
|
|
789
|
-
}
|
|
790
|
-
},
|
|
791
|
-
onProviderStreamEvent: async (data, requestModel) => {
|
|
792
|
-
const runner = extensionRunnerRef.current;
|
|
793
|
-
if (runner?.hasHandlers("provider_stream_event")) {
|
|
794
|
-
await runner.emit({ type: "provider_stream_event", data, provider: requestModel.provider, api: requestModel.api, model: requestModel.id });
|
|
795
|
-
}
|
|
796
|
-
},
|
|
797
|
-
sessionId: sessionManager.getSessionId(),
|
|
798
|
-
steeringMode: settingsManager.getSteeringMode(),
|
|
799
|
-
followUpMode: settingsManager.getFollowUpMode(),
|
|
800
|
-
transport: settingsManager.getTransport(),
|
|
801
|
-
...settingsManager.getThinkingBudgets() ? { thinkingBudgets: settingsManager.getThinkingBudgets() } : {},
|
|
802
|
-
...settingsManager.getProviderRetrySettings().maxRetryDelayMs !== void 0 ? { maxRetryDelayMs: settingsManager.getProviderRetrySettings().maxRetryDelayMs } : {}
|
|
803
|
-
};
|
|
804
|
-
const borrowedStorage = new Proxy(options.storage, {
|
|
805
|
-
get(target, property) {
|
|
806
|
-
if (property === "close") return async () => {
|
|
807
|
-
};
|
|
808
|
-
const value = Reflect.get(target, property, target);
|
|
809
|
-
return typeof value === "function" ? value.bind(target) : value;
|
|
810
|
-
}
|
|
811
|
-
});
|
|
812
|
-
const agent = new DurableAgent({ ...agentOptions, models: modelRuntime, storage: borrowedStorage, runId: options.runId });
|
|
813
|
-
try {
|
|
814
|
-
if (!hasHistory) sessionManager.appendModelChange(model.provider, model.id);
|
|
815
|
-
if (!hasHistory || !hasThinking) sessionManager.appendThinkingLevelChange(thinkingLevel);
|
|
816
|
-
const excluded = new Set(options.excludeTools);
|
|
817
|
-
const session = new AgentSession({
|
|
818
|
-
agent,
|
|
819
|
-
cwd,
|
|
820
|
-
sessionManager,
|
|
821
|
-
settingsManager,
|
|
822
|
-
resourceLoader,
|
|
823
|
-
modelRuntime,
|
|
824
|
-
extensionRunnerRef,
|
|
825
|
-
...options.customTools ? { customTools: options.customTools } : {},
|
|
826
|
-
...options.scopedModels ? { scopedModels: options.scopedModels } : {},
|
|
827
|
-
...options.sessionStartEvent ? { sessionStartEvent: options.sessionStartEvent } : {},
|
|
828
|
-
initialActiveToolNames: (options.tools ?? (options.noTools ? [] : settingsManager.getDefaultTools() ?? ["read", "bash", "edit", "write"])).filter((name) => !excluded.has(name)),
|
|
829
|
-
usesDefaultTools: options.tools === void 0 && !options.noTools,
|
|
830
|
-
...options.tools || options.noTools === "all" ? { allowedToolNames: options.tools ?? [] } : {},
|
|
831
|
-
...options.excludeTools ? { excludedToolNames: options.excludeTools } : {}
|
|
832
|
-
});
|
|
833
|
-
agent.recoverHistory = (messages) => {
|
|
834
|
-
const key = (message) => JSON.stringify(message);
|
|
835
|
-
const projected = sessionManager.buildSessionContext().messages;
|
|
836
|
-
const branch2 = sessionManager.getBranch();
|
|
837
|
-
const counts = (values) => {
|
|
838
|
-
const result = /* @__PURE__ */ new Map();
|
|
839
|
-
for (const value of values) result.set(value, (result.get(value) ?? 0) + 1);
|
|
840
|
-
return result;
|
|
841
|
-
};
|
|
842
|
-
const present = counts(projected.map(key));
|
|
843
|
-
for (const [value, count] of counts(branch2.flatMap((entry) => entry.type === "message" ? [key(entry.message)] : []))) {
|
|
844
|
-
present.set(value, Math.max(present.get(value) ?? 0, count));
|
|
845
|
-
}
|
|
846
|
-
const seen = /* @__PURE__ */ new Map();
|
|
847
|
-
let end = 0;
|
|
848
|
-
messages.forEach((message, index) => {
|
|
849
|
-
const value = key(message);
|
|
850
|
-
const count = (seen.get(value) ?? 0) + 1;
|
|
851
|
-
seen.set(value, count);
|
|
852
|
-
if ((present.get(value) ?? 0) >= count) end = index + 1;
|
|
853
|
-
});
|
|
854
|
-
const missing = messages.slice(end);
|
|
855
|
-
const branchIds = new Set(branch2.map((entry) => entry.id));
|
|
856
|
-
const elsewhere = new Set(sessionManager.getEntries().flatMap((entry) => entry.type === "message" && !branchIds.has(entry.id) ? [key(entry.message)] : []));
|
|
857
|
-
if (!missing.some((message) => elsewhere.has(key(message)))) {
|
|
858
|
-
for (const message of missing) {
|
|
859
|
-
if (message.role === "compactionSummary") {
|
|
860
|
-
sessionManager.appendCompaction(message.summary, null, message.tokensBefore);
|
|
861
|
-
} else if (message.role === "branchSummary") {
|
|
862
|
-
sessionManager.branchWithSummary(sessionManager.getLeafId(), message.summary);
|
|
863
|
-
} else {
|
|
864
|
-
sessionManager.appendMessage(message);
|
|
865
|
-
}
|
|
866
|
-
}
|
|
867
|
-
}
|
|
868
|
-
agent.state.messages = sessionManager.buildSessionContext().messages;
|
|
869
|
-
};
|
|
870
|
-
const steer = session.steer.bind(session);
|
|
871
|
-
session.steer = async (...args) => {
|
|
872
|
-
const result = await steer(...args);
|
|
873
|
-
await agent.awaitControls();
|
|
874
|
-
return result;
|
|
875
|
-
};
|
|
876
|
-
const followUp = session.followUp.bind(session);
|
|
877
|
-
session.followUp = async (...args) => {
|
|
878
|
-
const result = await followUp(...args);
|
|
879
|
-
await agent.awaitControls();
|
|
880
|
-
return result;
|
|
881
|
-
};
|
|
882
|
-
let closing;
|
|
883
|
-
return { session, agent, close: () => closing ??= (async () => {
|
|
884
|
-
try {
|
|
885
|
-
await session.abort();
|
|
886
|
-
await session.extensionRunner.emit({ type: "session_shutdown", reason: "quit" });
|
|
887
|
-
} finally {
|
|
888
|
-
try {
|
|
889
|
-
session.dispose();
|
|
890
|
-
} finally {
|
|
891
|
-
await agent.close();
|
|
892
|
-
}
|
|
893
|
-
}
|
|
894
|
-
})() };
|
|
895
|
-
} catch (error) {
|
|
896
|
-
await agent.close();
|
|
897
|
-
throw error;
|
|
898
|
-
}
|
|
899
|
-
}
|
|
900
|
-
|
|
901
|
-
// src/durable/storage.ts
|
|
902
|
-
import { constants } from "node:fs";
|
|
903
|
-
import { chmod, lstat, mkdir, open, readdir, realpath } from "node:fs/promises";
|
|
904
|
-
import { basename, dirname, join as join2, resolve as resolve2 } from "node:path";
|
|
905
|
-
var ownedDirectories = /* @__PURE__ */ new Map();
|
|
906
|
-
async function openDurableWorkerStorage(directory) {
|
|
907
|
-
await mkdir(directory, { recursive: true, mode: 448 });
|
|
908
|
-
const canonical = await realpath(directory);
|
|
909
|
-
if (ownedDirectories.has(canonical)) throw new Error(`Durable worker storage is locked: ${canonical}`);
|
|
910
|
-
const ownership = Symbol(canonical);
|
|
911
|
-
ownedDirectories.set(canonical, ownership);
|
|
912
|
-
const forget = () => {
|
|
913
|
-
if (ownedDirectories.get(canonical) === ownership) ownedDirectories.delete(canonical);
|
|
914
|
-
};
|
|
915
|
-
try {
|
|
916
|
-
return await acquire(canonical, forget);
|
|
917
|
-
} catch (error) {
|
|
918
|
-
forget();
|
|
919
|
-
throw error;
|
|
920
|
-
}
|
|
921
|
-
}
|
|
922
|
-
async function acquire(canonical, forget) {
|
|
923
|
-
await chmod(canonical, 448);
|
|
924
|
-
const leasePath = join2(canonical, "lease.sqlite");
|
|
925
|
-
const regular = async (path2, missing = false) => {
|
|
926
|
-
try {
|
|
927
|
-
const info = await lstat(path2);
|
|
928
|
-
if (!info.isFile() || info.nlink !== 1) throw new Error(`Durable file must be a regular, singly-linked file (no symlinks/hardlinks): ${path2}`);
|
|
929
|
-
} catch (error) {
|
|
930
|
-
if (!missing || error.code !== "ENOENT") throw error;
|
|
931
|
-
}
|
|
932
|
-
};
|
|
933
|
-
await regular(leasePath, true);
|
|
934
|
-
try {
|
|
935
|
-
const leaseFile = await open(leasePath, constants.O_CREAT | constants.O_EXCL | constants.O_WRONLY | constants.O_NOFOLLOW, 384);
|
|
936
|
-
await leaseFile.close();
|
|
937
|
-
} catch (error) {
|
|
938
|
-
if (error.code !== "EEXIST") throw error;
|
|
939
|
-
}
|
|
940
|
-
await regular(leasePath);
|
|
941
|
-
await chmod(leasePath, 384);
|
|
942
|
-
for (const suffix of ["-journal", "-wal", "-shm"]) await regular(leasePath + suffix, true);
|
|
943
|
-
const { DatabaseSync } = await import("node:sqlite");
|
|
944
|
-
const lease = new DatabaseSync(leasePath, { timeout: 0 });
|
|
945
|
-
let released = false;
|
|
946
|
-
const release = async () => {
|
|
947
|
-
if (released) return;
|
|
948
|
-
lease.close();
|
|
949
|
-
released = true;
|
|
950
|
-
forget();
|
|
951
|
-
};
|
|
952
|
-
try {
|
|
953
|
-
lease.exec("PRAGMA busy_timeout = 0; PRAGMA journal_mode = DELETE; BEGIN EXCLUSIVE;");
|
|
954
|
-
const store = join2(canonical, "store");
|
|
955
|
-
await mkdir(store, { recursive: true, mode: 448 });
|
|
956
|
-
if (!(await lstat(store)).isDirectory()) throw new Error("Durable store must be a directory, not a symlink");
|
|
957
|
-
await chmod(store, 448);
|
|
958
|
-
for (const name of await readdir(store)) {
|
|
959
|
-
const path2 = join2(store, name);
|
|
960
|
-
await regular(path2);
|
|
961
|
-
await chmod(path2, 384);
|
|
962
|
-
}
|
|
963
|
-
const [{ JsonlStorage }, { NodeExecutionEnv }, { FileError }, { BACKGROUND_CONTEXT: BACKGROUND_CONTEXT3 }] = await Promise.all([
|
|
964
|
-
import("@earendil-works/pi-durable/storage/jsonl"),
|
|
965
|
-
import("@earendil-works/pi-durable/env/node"),
|
|
966
|
-
import("@earendil-works/pi-durable/env"),
|
|
967
|
-
import("@earendil-works/chord/context")
|
|
968
|
-
]);
|
|
969
|
-
const fs = new NodeExecutionEnv({ cwd: canonical });
|
|
970
|
-
const checked = async (path2) => {
|
|
971
|
-
if (dirname(resolve2(path2)) !== store || !/^(?:main|(?:doc|task)-(?:0|[1-9]\d*))\.jsonl(?:\.reclaim)?$/.test(basename(path2))) {
|
|
972
|
-
throw new Error(`Durable path escapes storage: ${path2}`);
|
|
973
|
-
}
|
|
974
|
-
if (!(await lstat(store)).isDirectory()) throw new Error("Durable store directory was replaced");
|
|
975
|
-
await regular(path2, true);
|
|
976
|
-
};
|
|
977
|
-
const syncDirectory = async () => {
|
|
978
|
-
if (process.platform === "win32") return;
|
|
979
|
-
const dir = await open(store, constants.O_RDONLY | constants.O_NOFOLLOW);
|
|
980
|
-
try {
|
|
981
|
-
await dir.sync();
|
|
982
|
-
} finally {
|
|
983
|
-
await dir.close();
|
|
984
|
-
}
|
|
985
|
-
};
|
|
986
|
-
for (const method of ["appendFile", "writeFile"]) {
|
|
987
|
-
fs[method] = async (path2, content, context) => {
|
|
988
|
-
try {
|
|
989
|
-
context.abortSignal?.throwIfAborted();
|
|
990
|
-
await checked(path2);
|
|
991
|
-
const file = await open(path2, constants.O_CREAT | constants.O_WRONLY | constants.O_NOFOLLOW | (method === "appendFile" ? constants.O_APPEND : 0), 384);
|
|
992
|
-
try {
|
|
993
|
-
const info = await file.stat();
|
|
994
|
-
if (!info.isFile() || info.nlink !== 1) throw new Error("Durable file was replaced");
|
|
995
|
-
await file.chmod(384);
|
|
996
|
-
if (method === "writeFile") await file.truncate(0);
|
|
997
|
-
await file.writeFile(content);
|
|
998
|
-
await file.sync();
|
|
999
|
-
} finally {
|
|
1000
|
-
await file.close();
|
|
1001
|
-
}
|
|
1002
|
-
await syncDirectory();
|
|
1003
|
-
return { ok: true, value: void 0 };
|
|
1004
|
-
} catch (error) {
|
|
1005
|
-
return { ok: false, error: new FileError("unknown", String(error), path2, error instanceof Error ? error : void 0) };
|
|
1006
|
-
}
|
|
1007
|
-
};
|
|
1008
|
-
}
|
|
1009
|
-
for (const method of ["openTextLineReader", "flushFile"]) {
|
|
1010
|
-
const original = fs[method].bind(fs);
|
|
1011
|
-
const guarded = async (path2, context) => {
|
|
1012
|
-
await checked(path2);
|
|
1013
|
-
return original(path2, context);
|
|
1014
|
-
};
|
|
1015
|
-
Object.defineProperty(fs, method, { value: guarded });
|
|
1016
|
-
}
|
|
1017
|
-
const truncate = fs.truncateFile.bind(fs);
|
|
1018
|
-
fs.truncateFile = async (path2, size, context) => {
|
|
1019
|
-
await checked(path2);
|
|
1020
|
-
const result = await truncate(path2, size, context);
|
|
1021
|
-
return result.ok ? fs.flushFile(path2, context) : result;
|
|
1022
|
-
};
|
|
1023
|
-
const storage = await JsonlStorage.open(store, fs, BACKGROUND_CONTEXT3, { fsync: true });
|
|
1024
|
-
return { storage, release };
|
|
1025
|
-
} catch (error) {
|
|
1026
|
-
await release();
|
|
1027
|
-
throw new Error(`Cannot acquire durable worker storage at ${canonical}: ${error instanceof Error ? error.message : String(error)}`, { cause: error });
|
|
1028
|
-
}
|
|
1029
|
-
}
|
|
1030
|
-
|
|
1031
|
-
// src/durable/worker-host.ts
|
|
1032
|
-
async function resolveDurableProjectTrust(options) {
|
|
1033
|
-
if (!hasTrustRequiringProjectResources(options.cwd)) return true;
|
|
1034
|
-
const store = new ProjectTrustStore(options.agentDir);
|
|
1035
|
-
const context = {
|
|
1036
|
-
cwd: options.cwd,
|
|
1037
|
-
mode: "rpc",
|
|
1038
|
-
hasUI: false,
|
|
1039
|
-
ui: {
|
|
1040
|
-
select: async () => void 0,
|
|
1041
|
-
confirm: async () => false,
|
|
1042
|
-
input: async () => void 0,
|
|
1043
|
-
notify: (message) => process.stderr.write(`${message}
|
|
1044
|
-
`)
|
|
1045
|
-
}
|
|
1046
|
-
};
|
|
1047
|
-
for (const extension of options.extensionsResult.extensions) {
|
|
1048
|
-
for (const handler of extension.handlers.get("project_trust")?.slice() ?? []) {
|
|
1049
|
-
try {
|
|
1050
|
-
const result = await handler({ type: "project_trust", cwd: options.cwd }, context);
|
|
1051
|
-
if (result?.trusted !== "yes" && result?.trusted !== "no") continue;
|
|
1052
|
-
const trusted = result.trusted === "yes";
|
|
1053
|
-
if (result.remember === true) store.set(options.cwd, trusted);
|
|
1054
|
-
return trusted;
|
|
1055
|
-
} catch (error) {
|
|
1056
|
-
process.stderr.write(`Extension ${extension.path} project_trust error: ${String(error)}
|
|
1057
|
-
`);
|
|
1058
|
-
}
|
|
1059
|
-
}
|
|
1060
|
-
}
|
|
1061
|
-
return store.get(options.cwd) ?? options.defaultProjectTrust === "always";
|
|
1062
|
-
}
|
|
1063
|
-
var advertiseHostExtensionRunner = () => {
|
|
1064
|
-
const key = Symbol.for("pi-fabric.host-extension-runners.v1");
|
|
1065
|
-
const holder = globalThis;
|
|
1066
|
-
(holder[key] ??= /* @__PURE__ */ new Set()).add(ExtensionRunner);
|
|
1067
|
-
};
|
|
1068
|
-
async function createDurableWorkerRuntime(options) {
|
|
1069
|
-
advertiseHostExtensionRunner();
|
|
1070
|
-
const cwd = process.cwd();
|
|
1071
|
-
const agentDir = getAgentDir2();
|
|
1072
|
-
const manager = options.sessionFile ? SessionManager2.open(options.sessionFile, void 0, cwd) : SessionManager2.inMemory(cwd);
|
|
1073
|
-
let current;
|
|
1074
|
-
const initialSessionId = manager.getSessionId();
|
|
1075
|
-
let first = true;
|
|
1076
|
-
const closeCurrent = async () => {
|
|
1077
|
-
const previous = current;
|
|
1078
|
-
current = void 0;
|
|
1079
|
-
await previous?.close();
|
|
1080
|
-
};
|
|
1081
|
-
const factory = async (target) => {
|
|
1082
|
-
await closeCurrent();
|
|
1083
|
-
const settings = SettingsManager2.create(target.cwd, target.agentDir, { projectTrusted: false });
|
|
1084
|
-
const services = await createAgentSessionServices({
|
|
1085
|
-
cwd: target.cwd,
|
|
1086
|
-
agentDir: target.agentDir,
|
|
1087
|
-
settingsManager: settings,
|
|
1088
|
-
modelRuntimeSignal: AbortSignal.timeout(15e3),
|
|
1089
|
-
resourceLoaderReloadOptions: {
|
|
1090
|
-
resolveProjectTrust: ({ extensionsResult }) => resolveDurableProjectTrust({
|
|
1091
|
-
cwd: target.cwd,
|
|
1092
|
-
agentDir: target.agentDir,
|
|
1093
|
-
extensionsResult,
|
|
1094
|
-
defaultProjectTrust: settings.getDefaultProjectTrust()
|
|
1095
|
-
})
|
|
1096
|
-
},
|
|
1097
|
-
resourceLoaderOptions: {
|
|
1098
|
-
additionalExtensionPaths: options.extensions,
|
|
1099
|
-
noExtensions: options.noExtensions,
|
|
1100
|
-
appendSystemPrompt: options.appendSystemPrompt ? [options.appendSystemPrompt] : [],
|
|
1101
|
-
extensionFactories: [
|
|
1102
|
-
{ name: "codemode", factory: createCodemodeExtension(), builtin: true, replaceable: true },
|
|
1103
|
-
{ name: "tool-search", factory: createToolSearchExtension(), builtin: true, replaceable: true },
|
|
1104
|
-
{ name: "mcp", factory: createMcpExtension(), builtin: true, replaceable: true }
|
|
1105
|
-
]
|
|
1106
|
-
}
|
|
1107
|
-
});
|
|
1108
|
-
const extensionErrors = services.resourceLoader.getExtensions().errors;
|
|
1109
|
-
if (extensionErrors.length) throw new Error(`Durable worker extension loading failed: ${JSON.stringify(extensionErrors)}`);
|
|
1110
|
-
for (const diagnostic of services.diagnostics) {
|
|
1111
|
-
process.stderr.write(`${diagnostic.type}: ${diagnostic.message}
|
|
1112
|
-
`);
|
|
1113
|
-
}
|
|
1114
|
-
const selection = resolveCliModel({
|
|
1115
|
-
...options.model ? { cliModel: options.model } : {},
|
|
1116
|
-
...options.provider ? { cliProvider: options.provider } : {},
|
|
1117
|
-
...options.thinking ? { cliThinking: options.thinking } : {},
|
|
1118
|
-
modelRuntime: services.modelRuntime
|
|
1119
|
-
});
|
|
1120
|
-
if (selection.error) throw new Error(selection.error);
|
|
1121
|
-
if (selection.warning) process.stderr.write(`${selection.warning}
|
|
1122
|
-
`);
|
|
1123
|
-
const recoverInitialRequest = first;
|
|
1124
|
-
const sessionId = target.sessionManager.getSessionId();
|
|
1125
|
-
const key = sessionId === initialSessionId ? "initial" : createHash("sha256").update(sessionId).digest("hex");
|
|
1126
|
-
first = false;
|
|
1127
|
-
const lease = await openDurableWorkerStorage(path.join(options.directory, key));
|
|
1128
|
-
try {
|
|
1129
|
-
const host = await createDurableAgentSession({
|
|
1130
|
-
...services,
|
|
1131
|
-
sessionManager: target.sessionManager,
|
|
1132
|
-
...target.sessionStartEvent ? { sessionStartEvent: target.sessionStartEvent } : {},
|
|
1133
|
-
storage: lease.storage,
|
|
1134
|
-
runId: `${options.runId}:${key}`,
|
|
1135
|
-
...selection.model ? { model: selection.model } : {},
|
|
1136
|
-
...options.thinking ?? selection.thinkingLevel ? { thinkingLevel: options.thinking ?? selection.thinkingLevel } : {},
|
|
1137
|
-
...options.tools ? { tools: options.tools } : {},
|
|
1138
|
-
...options.noTools ? { noTools: options.noTools } : {}
|
|
1139
|
-
});
|
|
1140
|
-
if (!recoverInitialRequest) host.agent.setRequestId(randomUUID2());
|
|
1141
|
-
current = { close: async () => {
|
|
1142
|
-
try {
|
|
1143
|
-
await host.agent.close();
|
|
1144
|
-
} finally {
|
|
1145
|
-
try {
|
|
1146
|
-
await lease.storage.close(BACKGROUND_CONTEXT2);
|
|
1147
|
-
} finally {
|
|
1148
|
-
await lease.release();
|
|
1149
|
-
}
|
|
1150
|
-
}
|
|
1151
|
-
} };
|
|
1152
|
-
return { session: host.session, extensionsResult: services.resourceLoader.getExtensions(), services, diagnostics: services.diagnostics };
|
|
1153
|
-
} catch (error) {
|
|
1154
|
-
try {
|
|
1155
|
-
await lease.storage.close(BACKGROUND_CONTEXT2);
|
|
1156
|
-
} finally {
|
|
1157
|
-
await lease.release();
|
|
1158
|
-
}
|
|
1159
|
-
throw error;
|
|
1160
|
-
}
|
|
1161
|
-
};
|
|
1162
|
-
const initial = await factory({ cwd, agentDir, sessionManager: manager });
|
|
1163
|
-
class DurableRuntime extends AgentSessionRuntime {
|
|
1164
|
-
async dispose() {
|
|
1165
|
-
try {
|
|
1166
|
-
await super.dispose();
|
|
1167
|
-
} finally {
|
|
1168
|
-
await closeCurrent();
|
|
1169
|
-
}
|
|
1170
|
-
}
|
|
1171
|
-
}
|
|
1172
|
-
return new DurableRuntime(initial.session, initial.services, factory, initial.diagnostics);
|
|
1173
|
-
}
|
|
1174
|
-
async function runDurableWorker(options) {
|
|
1175
|
-
const runtime = await createDurableWorkerRuntime(options);
|
|
1176
|
-
try {
|
|
1177
|
-
await runRpcMode(runtime);
|
|
1178
|
-
} finally {
|
|
1179
|
-
await runtime.dispose();
|
|
1180
|
-
}
|
|
1181
|
-
}
|
|
2
|
+
configureDurableHttp,
|
|
3
|
+
createDurableWorkerRuntime,
|
|
4
|
+
resolveDurableProjectTrust,
|
|
5
|
+
runDurableWorker,
|
|
6
|
+
sweepFabricJournals
|
|
7
|
+
} from "../chunks/chunk-3PKZSIRA.js";
|
|
8
|
+
import "../chunks/chunk-6OGYPHNQ.js";
|
|
1182
9
|
export {
|
|
10
|
+
configureDurableHttp,
|
|
1183
11
|
createDurableWorkerRuntime,
|
|
1184
12
|
resolveDurableProjectTrust,
|
|
1185
|
-
runDurableWorker
|
|
13
|
+
runDurableWorker,
|
|
14
|
+
sweepFabricJournals
|
|
1186
15
|
};
|
|
1187
16
|
//# sourceMappingURL=worker-host.js.map
|