@remnic/core 10.0.186 → 10.0.188
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/access-admin-ops-surface.js +105 -104
- package/dist/access-audit.js +2 -2
- package/dist/access-cli.js +105 -104
- package/dist/access-cli.js.map +1 -1
- package/dist/access-coding-context-resolution.js +6 -6
- package/dist/access-extraction-force-flush-preempt.js +105 -104
- package/dist/access-extraction-force-flush.js +105 -104
- package/dist/access-http-briefing.js +105 -104
- package/dist/access-http-query.js +105 -104
- package/dist/access-http.js +105 -104
- package/dist/access-identity-continuity-surface.js +105 -104
- package/dist/access-lcm-surface.js +105 -104
- package/dist/access-mcp.js +105 -104
- package/dist/access-observe-write-category.js +6 -6
- package/dist/access-observe-write-surface.js +105 -104
- package/dist/access-offline-manifest.js +5 -5
- package/dist/access-operations-batch.js +105 -104
- package/dist/access-operations.js +105 -104
- package/dist/access-recall-concurrency.js +105 -104
- package/dist/access-recall-response.js +105 -104
- package/dist/access-recall-surface.js +105 -104
- package/dist/access-schema.js +5 -5
- package/dist/access-service.js +105 -104
- package/dist/active-recall.js +10 -10
- package/dist/adapters/index.js +4 -4
- package/dist/adapters/registry.js +2 -2
- package/dist/{auto-sync-OOEY2FSA.js → auto-sync-BJUAGKI5.js} +4 -4
- package/dist/briefing.js +7 -7
- package/dist/buffer-add-turns-bounded.js +2 -2
- package/dist/buffer-admission-idempotency.d.ts.map +1 -1
- package/dist/buffer-admission-idempotency.js +1 -1
- package/dist/buffer-persistence.d.ts +14 -0
- package/dist/buffer-persistence.d.ts.map +1 -1
- package/dist/buffer-persistence.js +3 -1
- package/dist/buffer.js +9 -8
- package/dist/calibration.js +4 -4
- package/dist/causal-consolidation.js +8 -8
- package/dist/{chunk-XYZR3NBU.js → chunk-2I3ETW3G.js} +2 -2
- package/dist/{chunk-5RWIZISF.js → chunk-2VNMSEZR.js} +3 -3
- package/dist/{chunk-4TPU36X4.js → chunk-4N33L4HY.js} +2 -2
- package/dist/{chunk-BFPF5N3H.js → chunk-4RASUAN3.js} +4 -4
- package/dist/{chunk-N2PXVLV3.js → chunk-56BNHKZM.js} +7 -7
- package/dist/{chunk-R3UQIS3F.js → chunk-5AFBFAFX.js} +4 -4
- package/dist/{chunk-3FEQNKMB.js → chunk-5WDUY2ZZ.js} +2 -2
- package/dist/{chunk-5ITPOAKW.js → chunk-65DWWJKI.js} +2 -2
- package/dist/{chunk-O5ZCDK32.js → chunk-6AMFGXG2.js} +39 -11
- package/dist/chunk-6AMFGXG2.js.map +1 -0
- package/dist/{chunk-L4TYD52M.js → chunk-6MDHK6NO.js} +2 -2
- package/dist/{chunk-FYHFM64A.js → chunk-6OHCNTKU.js} +2 -2
- package/dist/{chunk-PY5XP7GR.js → chunk-6TIQLG7I.js} +2 -2
- package/dist/{chunk-A3HLZMHD.js → chunk-7KTORRIK.js} +2 -2
- package/dist/{chunk-ENKXMLE3.js → chunk-A32EBVCZ.js} +2 -2
- package/dist/{chunk-H4HBQRGI.js → chunk-ATPY63F5.js} +2 -2
- package/dist/{chunk-2LXROA34.js → chunk-AXSQGJSG.js} +2 -2
- package/dist/chunk-B256MMS7.js +205 -0
- package/dist/chunk-B256MMS7.js.map +1 -0
- package/dist/{chunk-VUC3DLQ5.js → chunk-C6Y2YHJL.js} +2 -2
- package/dist/{chunk-FBNR3JI5.js → chunk-CIAQK2OU.js} +7 -2
- package/dist/{chunk-FBNR3JI5.js.map → chunk-CIAQK2OU.js.map} +1 -1
- package/dist/{chunk-FDXLO6CX.js → chunk-CRS2NY44.js} +2 -2
- package/dist/{chunk-AJVCM2E3.js → chunk-CYX7JI4O.js} +2 -2
- package/dist/{chunk-JK5YFQQT.js → chunk-D3FP4JQI.js} +2 -2
- package/dist/{chunk-ZNHLUYIT.js → chunk-D7HOJFDS.js} +4 -4
- package/dist/{chunk-ZX5N5D6M.js → chunk-DAOMWGO2.js} +4 -4
- package/dist/{chunk-VN3RYYMS.js → chunk-DR4TYD56.js} +2 -2
- package/dist/{chunk-7DFJ4JX2.js → chunk-DTTDMK7Q.js} +7 -7
- package/dist/{chunk-YNDLCWXS.js → chunk-EZ25VE3G.js} +4 -4
- package/dist/{chunk-QJBULLKG.js → chunk-F2MVWUNF.js} +2 -2
- package/dist/{chunk-TQXKUQFX.js → chunk-FZU62GIV.js} +7 -6
- package/dist/chunk-FZU62GIV.js.map +1 -0
- package/dist/{chunk-BAMF6J4W.js → chunk-GCHM5BYL.js} +4 -4
- package/dist/{chunk-6SROXED4.js → chunk-GRX5BE73.js} +2 -2
- package/dist/{chunk-TKWIUL3D.js → chunk-H442UKDV.js} +8 -8
- package/dist/{chunk-VFJ3PBZI.js → chunk-HL53XYHC.js} +4 -4
- package/dist/{chunk-CKTKATXL.js → chunk-IMSLPQJB.js} +20 -16
- package/dist/chunk-IMSLPQJB.js.map +1 -0
- package/dist/{chunk-63FIQIER.js → chunk-JJ42IDJU.js} +2 -2
- package/dist/{chunk-N33M4NWM.js → chunk-K3JGILZC.js} +3 -3
- package/dist/{chunk-CJERJ724.js → chunk-K6BS5RB4.js} +2 -2
- package/dist/{chunk-VAQIBC2L.js → chunk-KQIOW3TG.js} +2 -2
- package/dist/{chunk-UMGO4LEZ.js → chunk-KVTUUU7H.js} +2 -2
- package/dist/{chunk-TRFSTCQK.js → chunk-LL6WEMTC.js} +34 -6
- package/dist/chunk-LL6WEMTC.js.map +1 -0
- package/dist/{chunk-LALPM2DN.js → chunk-MTKSH7HY.js} +143 -139
- package/dist/chunk-MTKSH7HY.js.map +1 -0
- package/dist/{chunk-IK7NPYYU.js → chunk-NFQKIZK3.js} +2 -2
- package/dist/{chunk-2WITFW6F.js → chunk-NKHRIDYP.js} +2 -2
- package/dist/{chunk-KYZMCH4I.js → chunk-NN3LMWKA.js} +12 -4
- package/dist/chunk-NN3LMWKA.js.map +1 -0
- package/dist/{chunk-RXAWE76Y.js → chunk-O6QSBI3U.js} +2 -2
- package/dist/{chunk-5RBHL5TF.js → chunk-OA7YDB6A.js} +2 -2
- package/dist/{chunk-SSKIXUR5.js → chunk-PCGBESAN.js} +2 -2
- package/dist/{chunk-DYZDFOBX.js → chunk-Q6S67LHR.js} +2 -2
- package/dist/{chunk-WCXWCAUC.js → chunk-QGT5KNQT.js} +2 -2
- package/dist/{chunk-KYPFQO43.js → chunk-QPD7EYGI.js} +2 -2
- package/dist/{chunk-4KUK3KGI.js → chunk-QXHWOUS6.js} +3 -3
- package/dist/{chunk-FE43YKNJ.js → chunk-RBPC4XGU.js} +31 -8
- package/dist/chunk-RBPC4XGU.js.map +1 -0
- package/dist/{chunk-CXGD3N2Y.js → chunk-RPOG6HLI.js} +2 -2
- package/dist/{chunk-3N7I53KR.js → chunk-RVODERA5.js} +2 -2
- package/dist/{chunk-G6V32Q4F.js → chunk-SFWQZBPN.js} +2 -2
- package/dist/{chunk-DNXQVCIC.js → chunk-SUI75NTN.js} +8 -8
- package/dist/{chunk-3GD5SFDT.js → chunk-T3XOP7TA.js} +5 -5
- package/dist/{chunk-FDLPNFKE.js → chunk-T7R42MWB.js} +2 -2
- package/dist/{chunk-5BESLEU7.js → chunk-TAPF7T26.js} +2 -2
- package/dist/chunk-TK6EBBKG.js +13 -0
- package/dist/chunk-TK6EBBKG.js.map +1 -0
- package/dist/{chunk-PZ4OA7CP.js → chunk-TQODBIMW.js} +2 -2
- package/dist/{chunk-PDXO4LIH.js → chunk-UWKHLWUE.js} +13 -9
- package/dist/chunk-UWKHLWUE.js.map +1 -0
- package/dist/{chunk-QJG6PEAM.js → chunk-VQQZJ6KJ.js} +3 -3
- package/dist/{chunk-CIC3WZVO.js → chunk-X3ERYOLO.js} +2 -2
- package/dist/{chunk-T4MKFTJF.js → chunk-XHDS6HIX.js} +5 -5
- package/dist/{chunk-J7BAJ6BF.js → chunk-XQF2KLV5.js} +2 -2
- package/dist/{chunk-U7VEZ2XS.js → chunk-XWPYK5T4.js} +2 -2
- package/dist/{chunk-L7MVHAMS.js → chunk-YVXR7CPS.js} +2 -2
- package/dist/{chunk-NU5JRN3A.js → chunk-ZDLVHGIC.js} +2 -2
- package/dist/{chunk-OJXK5C6Z.js → chunk-ZG4GNPRE.js} +7 -7
- package/dist/{chunk-IJKO5RVJ.js → chunk-ZNYDDZVW.js} +3 -3
- package/dist/cli.js +105 -104
- package/dist/coding/export-okf-codegraph.js +13 -13
- package/dist/compounding/engine.js +8 -8
- package/dist/config.js +10 -10
- package/dist/connectors/codex-materialize-runner.js +7 -7
- package/dist/connectors/index.js +7 -7
- package/dist/convergence-refresh.js +9 -9
- package/dist/corpus-watermark.js +9 -9
- package/dist/dashboard-runtime.js +2 -2
- package/dist/deep-recall-http-glue.js +6 -6
- package/dist/deep-recall.js +2 -2
- package/dist/entity-retrieval.js +7 -7
- package/dist/explicit-capture.js +105 -104
- package/dist/extraction-entities-source.d.ts +11 -0
- package/dist/extraction-entities-source.d.ts.map +1 -0
- package/dist/extraction-entities-source.js +8 -0
- package/dist/extraction-entities-source.js.map +1 -0
- package/dist/extraction-judge.js +2 -2
- package/dist/extraction-normalization.js +2 -2
- package/dist/extraction-prompt.d.ts +19 -2
- package/dist/extraction-prompt.d.ts.map +1 -1
- package/dist/extraction-prompt.js +5 -1
- package/dist/extraction.d.ts +2 -1
- package/dist/extraction.d.ts.map +1 -1
- package/dist/extraction.js +18 -17
- package/dist/{first-start-migration-TCPK2I7J.js → first-start-migration-CCZ5SM3V.js} +4 -4
- package/dist/harmonic-retrieval.js +7 -7
- package/dist/index.js +125 -124
- package/dist/lcm/engine.js +3 -3
- package/dist/lcm/index.js +8 -8
- package/dist/local-llm-helpers.d.ts.map +1 -1
- package/dist/local-llm-helpers.js +2 -2
- package/dist/local-llm-transport.d.ts +82 -9
- package/dist/local-llm-transport.d.ts.map +1 -1
- package/dist/local-llm-transport.js +11 -3
- package/dist/local-llm.d.ts.map +1 -1
- package/dist/local-llm.js +3 -3
- package/dist/location/index.js +8 -8
- package/dist/maintenance/memory-governance.js +7 -7
- package/dist/maintenance/rebuild-memory-lifecycle-ledger.js +7 -7
- package/dist/maintenance/rebuild-memory-projection-runner.js +9 -9
- package/dist/maintenance/rebuild-memory-projection.js +8 -8
- package/dist/memory-browse.js +5 -5
- package/dist/namespaces/migrate.js +8 -8
- package/dist/namespaces/search.js +4 -4
- package/dist/namespaces/storage.js +7 -7
- package/dist/offline-sync-changeset-generations.js +3 -3
- package/dist/offline-sync-embedding-generation.js +2 -2
- package/dist/offline-sync-snapshot-stream.js +5 -5
- package/dist/offline-sync.js +6 -6
- package/dist/operator-doctor-corpus.js +10 -10
- package/dist/operator-toolkit.js +17 -17
- package/dist/orchestration/backlog-scheduler.js +106 -105
- package/dist/orchestration/backlog-scheduler.js.map +1 -1
- package/dist/orchestration/buffer-drain-runner.js +106 -105
- package/dist/orchestration/extraction-queue-coordinator.d.ts.map +1 -1
- package/dist/orchestration/extraction-run-helpers.d.ts +2 -1
- package/dist/orchestration/extraction-run-helpers.d.ts.map +1 -1
- package/dist/orchestration/extraction-run.d.ts.map +1 -1
- package/dist/orchestration/maintenance.js +18 -18
- package/dist/orchestrator.js +107 -106
- package/dist/qmd.js +2 -2
- package/dist/recall-navigation.js +105 -104
- package/dist/recall-state-view-admission.js +5 -5
- package/dist/recall-why-service.js +5 -5
- package/dist/resume-bundles.js +13 -13
- package/dist/search/factory.js +3 -3
- package/dist/search/index.js +3 -3
- package/dist/semantic-consolidation.js +8 -8
- package/dist/semantic-rule-promotion.js +7 -7
- package/dist/semantic-rule-verifier.js +7 -7
- package/dist/source-agent-qualifier.js +11 -10
- package/dist/standup/build.js +7 -7
- package/dist/storage/entity-canonical-id-migration-runner.d.ts.map +1 -1
- package/dist/storage.js +6 -6
- package/dist/summarizer.js +4 -4
- package/dist/support-passport/index.js +4 -4
- package/dist/transcript.js +2 -2
- package/dist/transfer/export-okf.js +7 -7
- package/dist/verified-recall.js +7 -7
- package/dist/who-knows-cli.js +8 -8
- package/dist/who-knows.js +7 -7
- package/package.json +2 -2
- package/src/buffer-admission-idempotency.test.ts +115 -0
- package/src/buffer-admission-idempotency.ts +67 -11
- package/src/buffer-persistence.ts +46 -5
- package/src/extraction-carry-forward.test.ts +147 -0
- package/src/extraction-entities-source.ts +19 -0
- package/src/extraction-prompt.ts +60 -9
- package/src/extraction.ts +11 -8
- package/src/local-llm-headers-timeout.test.ts +246 -16
- package/src/local-llm-helpers.ts +14 -4
- package/src/local-llm-transport.ts +253 -16
- package/src/local-llm.ts +7 -8
- package/src/orchestration/extraction-queue-coordinator.ts +7 -1
- package/src/orchestration/extraction-queue-lane-bias.test.ts +35 -0
- package/src/orchestration/extraction-run-helpers.ts +11 -4
- package/src/orchestration/extraction-run.test.ts +23 -12
- package/src/orchestration/extraction-run.ts +6 -5
- package/src/storage/entity-canonical-id-migration-runner.test.ts +90 -0
- package/src/storage/entity-canonical-id-migration-runner.ts +10 -0
- package/dist/chunk-5YQXWVCP.js +0 -74
- package/dist/chunk-5YQXWVCP.js.map +0 -1
- package/dist/chunk-CKTKATXL.js.map +0 -1
- package/dist/chunk-FE43YKNJ.js.map +0 -1
- package/dist/chunk-KYZMCH4I.js.map +0 -1
- package/dist/chunk-LALPM2DN.js.map +0 -1
- package/dist/chunk-O5ZCDK32.js.map +0 -1
- package/dist/chunk-PDXO4LIH.js.map +0 -1
- package/dist/chunk-TQXKUQFX.js.map +0 -1
- package/dist/chunk-TRFSTCQK.js.map +0 -1
- /package/dist/{auto-sync-OOEY2FSA.js.map → auto-sync-BJUAGKI5.js.map} +0 -0
- /package/dist/{chunk-XYZR3NBU.js.map → chunk-2I3ETW3G.js.map} +0 -0
- /package/dist/{chunk-5RWIZISF.js.map → chunk-2VNMSEZR.js.map} +0 -0
- /package/dist/{chunk-4TPU36X4.js.map → chunk-4N33L4HY.js.map} +0 -0
- /package/dist/{chunk-BFPF5N3H.js.map → chunk-4RASUAN3.js.map} +0 -0
- /package/dist/{chunk-N2PXVLV3.js.map → chunk-56BNHKZM.js.map} +0 -0
- /package/dist/{chunk-R3UQIS3F.js.map → chunk-5AFBFAFX.js.map} +0 -0
- /package/dist/{chunk-3FEQNKMB.js.map → chunk-5WDUY2ZZ.js.map} +0 -0
- /package/dist/{chunk-5ITPOAKW.js.map → chunk-65DWWJKI.js.map} +0 -0
- /package/dist/{chunk-L4TYD52M.js.map → chunk-6MDHK6NO.js.map} +0 -0
- /package/dist/{chunk-FYHFM64A.js.map → chunk-6OHCNTKU.js.map} +0 -0
- /package/dist/{chunk-PY5XP7GR.js.map → chunk-6TIQLG7I.js.map} +0 -0
- /package/dist/{chunk-A3HLZMHD.js.map → chunk-7KTORRIK.js.map} +0 -0
- /package/dist/{chunk-ENKXMLE3.js.map → chunk-A32EBVCZ.js.map} +0 -0
- /package/dist/{chunk-H4HBQRGI.js.map → chunk-ATPY63F5.js.map} +0 -0
- /package/dist/{chunk-2LXROA34.js.map → chunk-AXSQGJSG.js.map} +0 -0
- /package/dist/{chunk-VUC3DLQ5.js.map → chunk-C6Y2YHJL.js.map} +0 -0
- /package/dist/{chunk-FDXLO6CX.js.map → chunk-CRS2NY44.js.map} +0 -0
- /package/dist/{chunk-AJVCM2E3.js.map → chunk-CYX7JI4O.js.map} +0 -0
- /package/dist/{chunk-JK5YFQQT.js.map → chunk-D3FP4JQI.js.map} +0 -0
- /package/dist/{chunk-ZNHLUYIT.js.map → chunk-D7HOJFDS.js.map} +0 -0
- /package/dist/{chunk-ZX5N5D6M.js.map → chunk-DAOMWGO2.js.map} +0 -0
- /package/dist/{chunk-VN3RYYMS.js.map → chunk-DR4TYD56.js.map} +0 -0
- /package/dist/{chunk-7DFJ4JX2.js.map → chunk-DTTDMK7Q.js.map} +0 -0
- /package/dist/{chunk-YNDLCWXS.js.map → chunk-EZ25VE3G.js.map} +0 -0
- /package/dist/{chunk-QJBULLKG.js.map → chunk-F2MVWUNF.js.map} +0 -0
- /package/dist/{chunk-BAMF6J4W.js.map → chunk-GCHM5BYL.js.map} +0 -0
- /package/dist/{chunk-6SROXED4.js.map → chunk-GRX5BE73.js.map} +0 -0
- /package/dist/{chunk-TKWIUL3D.js.map → chunk-H442UKDV.js.map} +0 -0
- /package/dist/{chunk-VFJ3PBZI.js.map → chunk-HL53XYHC.js.map} +0 -0
- /package/dist/{chunk-63FIQIER.js.map → chunk-JJ42IDJU.js.map} +0 -0
- /package/dist/{chunk-N33M4NWM.js.map → chunk-K3JGILZC.js.map} +0 -0
- /package/dist/{chunk-CJERJ724.js.map → chunk-K6BS5RB4.js.map} +0 -0
- /package/dist/{chunk-VAQIBC2L.js.map → chunk-KQIOW3TG.js.map} +0 -0
- /package/dist/{chunk-UMGO4LEZ.js.map → chunk-KVTUUU7H.js.map} +0 -0
- /package/dist/{chunk-IK7NPYYU.js.map → chunk-NFQKIZK3.js.map} +0 -0
- /package/dist/{chunk-2WITFW6F.js.map → chunk-NKHRIDYP.js.map} +0 -0
- /package/dist/{chunk-RXAWE76Y.js.map → chunk-O6QSBI3U.js.map} +0 -0
- /package/dist/{chunk-5RBHL5TF.js.map → chunk-OA7YDB6A.js.map} +0 -0
- /package/dist/{chunk-SSKIXUR5.js.map → chunk-PCGBESAN.js.map} +0 -0
- /package/dist/{chunk-DYZDFOBX.js.map → chunk-Q6S67LHR.js.map} +0 -0
- /package/dist/{chunk-WCXWCAUC.js.map → chunk-QGT5KNQT.js.map} +0 -0
- /package/dist/{chunk-KYPFQO43.js.map → chunk-QPD7EYGI.js.map} +0 -0
- /package/dist/{chunk-4KUK3KGI.js.map → chunk-QXHWOUS6.js.map} +0 -0
- /package/dist/{chunk-CXGD3N2Y.js.map → chunk-RPOG6HLI.js.map} +0 -0
- /package/dist/{chunk-3N7I53KR.js.map → chunk-RVODERA5.js.map} +0 -0
- /package/dist/{chunk-G6V32Q4F.js.map → chunk-SFWQZBPN.js.map} +0 -0
- /package/dist/{chunk-DNXQVCIC.js.map → chunk-SUI75NTN.js.map} +0 -0
- /package/dist/{chunk-3GD5SFDT.js.map → chunk-T3XOP7TA.js.map} +0 -0
- /package/dist/{chunk-FDLPNFKE.js.map → chunk-T7R42MWB.js.map} +0 -0
- /package/dist/{chunk-5BESLEU7.js.map → chunk-TAPF7T26.js.map} +0 -0
- /package/dist/{chunk-PZ4OA7CP.js.map → chunk-TQODBIMW.js.map} +0 -0
- /package/dist/{chunk-QJG6PEAM.js.map → chunk-VQQZJ6KJ.js.map} +0 -0
- /package/dist/{chunk-CIC3WZVO.js.map → chunk-X3ERYOLO.js.map} +0 -0
- /package/dist/{chunk-T4MKFTJF.js.map → chunk-XHDS6HIX.js.map} +0 -0
- /package/dist/{chunk-J7BAJ6BF.js.map → chunk-XQF2KLV5.js.map} +0 -0
- /package/dist/{chunk-U7VEZ2XS.js.map → chunk-XWPYK5T4.js.map} +0 -0
- /package/dist/{chunk-L7MVHAMS.js.map → chunk-YVXR7CPS.js.map} +0 -0
- /package/dist/{chunk-NU5JRN3A.js.map → chunk-ZDLVHGIC.js.map} +0 -0
- /package/dist/{chunk-OJXK5C6Z.js.map → chunk-ZG4GNPRE.js.map} +0 -0
- /package/dist/{chunk-IJKO5RVJ.js.map → chunk-ZNYDDZVW.js.map} +0 -0
- /package/dist/{first-start-migration-TCPK2I7J.js.map → first-start-migration-CCZ5SM3V.js.map} +0 -0
package/src/local-llm.ts
CHANGED
|
@@ -8,7 +8,7 @@ import type { ModelRegistry } from "./model-registry.js";
|
|
|
8
8
|
import { launchProcessSync } from "./runtime/child-process.js";
|
|
9
9
|
import { mergeEnv, readEnvVar } from "./runtime/env.js";
|
|
10
10
|
import { resolveLocalLlmCapabilities, resolvePipelineProcessingCapabilities } from "./capabilities.js";
|
|
11
|
-
import { ChatTransport } from "./local-llm-transport.js";
|
|
11
|
+
import { ChatTransport, routeBudgets, type ChatWireResponse } from "./local-llm-transport.js";
|
|
12
12
|
import { LocalLlmRateLimitSession, resolveRateLimitSettings, isTerminalLocalLlmProxyPoolError } from "./local-llm-rate-limit.js";
|
|
13
13
|
import {
|
|
14
14
|
extractNonRecoverableBackendReason,
|
|
@@ -952,10 +952,9 @@ export class LocalLlmClient {
|
|
|
952
952
|
// Avoid logging request bodies by default (can contain sensitive user content).
|
|
953
953
|
log.debug(`local LLM: request body length=${requestBodyJson.length}`);
|
|
954
954
|
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
: this.config.localLlmTimeoutMs;
|
|
955
|
+
// Extraction floors its dispatcher inactivity budgets at fifteen minutes
|
|
956
|
+
// (issue #2148 root cause); the sizing lives with the transport budgets.
|
|
957
|
+
const { effectiveTimeoutMs, transportBudgetMs } = routeBudgets(operation, this.config.localLlmTimeoutMs, options.timeoutMs);
|
|
959
958
|
const maxAttempts = 1 + Math.max(0, this.config.localLlmRetry5xxCount);
|
|
960
959
|
// COS-447: rate-limit responses (429/503/408, LiteLLM cooldown) get
|
|
961
960
|
// their own retry budget with exponential full-jitter backoff, and a
|
|
@@ -969,7 +968,7 @@ export class LocalLlmClient {
|
|
|
969
968
|
effectiveTimeoutMs,
|
|
970
969
|
);
|
|
971
970
|
let lastRateLimitDelayMs: number | null = null;
|
|
972
|
-
let response:
|
|
971
|
+
let response: ChatWireResponse | null = null, responseBody = "";
|
|
973
972
|
let lastAbortError: Error | null = null;
|
|
974
973
|
for (let attempt = 1; attempt <= maxAttempts; attempt += 1) {
|
|
975
974
|
response = null;
|
|
@@ -998,12 +997,12 @@ export class LocalLlmClient {
|
|
|
998
997
|
}
|
|
999
998
|
const attemptTimeout = setTimeout(() => attemptAbort.abort(), effectiveTimeoutMs);
|
|
1000
999
|
const routingHeaders = buildLocalLlmRoutingHeaders(operation, options.priority);
|
|
1001
|
-
const postAttempt = (bodyJson: string): Promise<
|
|
1000
|
+
const postAttempt = (bodyJson: string): Promise<ChatWireResponse> => this.chatTransport.post({
|
|
1002
1001
|
url: chatUrl,
|
|
1003
1002
|
headers: this.buildRequestHeaders(routingHeaders),
|
|
1004
1003
|
body: bodyJson,
|
|
1005
1004
|
signal: attemptAbort.signal,
|
|
1006
|
-
budgetMs:
|
|
1005
|
+
budgetMs: transportBudgetMs,
|
|
1007
1006
|
});
|
|
1008
1007
|
try {
|
|
1009
1008
|
response = await postAttempt(requestBodyJson);
|
|
@@ -144,7 +144,13 @@ export class ExtractionQueueCoordinator {
|
|
|
144
144
|
const key = options?.key;
|
|
145
145
|
const entry: QueueEntry = { run: task, key, backlog: options?.backlog, front: options?.front };
|
|
146
146
|
if (options?.front) {
|
|
147
|
-
|
|
147
|
+
const sameKeyArmed =
|
|
148
|
+
key !== undefined &&
|
|
149
|
+
Array.from(this.preemptSlots.values()).some((slot) => slot.key === key && slot.armed !== undefined);
|
|
150
|
+
if (sameKeyArmed || this.preemptSlots.size >= this.concurrency) {
|
|
151
|
+
this.preemptRunning(options.key);
|
|
152
|
+
}
|
|
153
|
+
entry.front = true;
|
|
148
154
|
this.queue.unshift(entry);
|
|
149
155
|
} else {
|
|
150
156
|
this.queue.push(entry);
|
|
@@ -183,3 +183,38 @@ test("a front flush starts before queued backlog work (CodeRabbit Major, pure-ba
|
|
|
183
183
|
release("bl2");
|
|
184
184
|
release("flush");
|
|
185
185
|
});
|
|
186
|
+
|
|
187
|
+
test("a front flush takes the free slot instead of killing armed backlog", async () => {
|
|
188
|
+
const queue = new ExtractionQueueCoordinator(4);
|
|
189
|
+
const aborted: string[] = [];
|
|
190
|
+
const started: string[] = [];
|
|
191
|
+
for (const tag of ["b1", "b2", "b3"]) {
|
|
192
|
+
queue.enqueue(async (preempt) => {
|
|
193
|
+
started.push(tag);
|
|
194
|
+
preempt?.arm(() => aborted.push(tag));
|
|
195
|
+
await new Promise<void>(() => {}); // never settles
|
|
196
|
+
}, { backlog: true });
|
|
197
|
+
}
|
|
198
|
+
await tick();
|
|
199
|
+
assert.deepEqual(started, ["b1", "b2", "b3"]);
|
|
200
|
+
// The invariant reserve leaves one slot free; the flush must use it
|
|
201
|
+
// rather than aborting an armed backlog task.
|
|
202
|
+
queue.enqueue(async () => { started.push("flush"); }, { front: true });
|
|
203
|
+
for (let i = 0; i < 10 && !started.includes("flush"); i += 1) await tick();
|
|
204
|
+
assert.deepEqual(aborted, [], "no victim while a free slot exists");
|
|
205
|
+
assert.deepEqual(started, ["b1", "b2", "b3", "flush"], "the flush ran in the reserved slot");
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
test("a front flush beats queued backlog when the foreground floor is met", async () => {
|
|
209
|
+
const h = harness(2);
|
|
210
|
+
h.enqueue("fg", "f1");
|
|
211
|
+
await tick();
|
|
212
|
+
assert.deepEqual(h.started, ["f1"]);
|
|
213
|
+
// Backlog queued first, then a force flush jumps the queue: front
|
|
214
|
+
// priority outranks the backlog preference for ordinary queued tasks.
|
|
215
|
+
h.enqueue("bg", "b1");
|
|
216
|
+
h.queue.enqueue(async () => { h.started.push("flush"); }, { front: true });
|
|
217
|
+
for (let i = 0; i < 10 && !h.started.includes("flush"); i += 1) await tick();
|
|
218
|
+
assert.deepEqual(h.started.slice(0, 2), ["f1", "flush"],
|
|
219
|
+
"the flush wins the second slot over the queued backlog task");
|
|
220
|
+
});
|
|
@@ -4,6 +4,7 @@ import { resolveMemoryLifecycleCapabilities, resolveRecallEnhancementCapabilitie
|
|
|
4
4
|
import { log } from "../logger.js";
|
|
5
5
|
import type { ExtractionRunResult } from "./extraction-run.js";
|
|
6
6
|
import type { ExtractionEngine } from "../extraction.js";
|
|
7
|
+
import { memoizeExistingEntities, type ExistingEntitiesSource } from "../extraction-entities-source.js";
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
10
|
* Count of durable outputs an extraction result asks persistence to write
|
|
@@ -411,7 +412,7 @@ export async function extractChunkedExtraction(
|
|
|
411
412
|
engine: Pick<ExtractionEngine, "extract">,
|
|
412
413
|
config: PluginConfig,
|
|
413
414
|
turns: BufferTurn[],
|
|
414
|
-
existingEntities:
|
|
415
|
+
existingEntities: ExistingEntitiesSource,
|
|
415
416
|
signal?: AbortSignal,
|
|
416
417
|
): Promise<ExtractionResult> {
|
|
417
418
|
const budget = config.extractionPromptMaxChars;
|
|
@@ -438,11 +439,17 @@ export async function extractChunkedExtraction(
|
|
|
438
439
|
entities: [],
|
|
439
440
|
questions: [],
|
|
440
441
|
};
|
|
441
|
-
|
|
442
|
+
// Carry-forward names found in earlier chunks flow into every later
|
|
443
|
+
// fallback call: the base listing resolves once (memoized), while
|
|
444
|
+
// `foundNames` re-spreads on each call so names found after a first
|
|
445
|
+
// fallback still reach subsequent fallback chunks.
|
|
446
|
+
const foundNames: string[] = [];
|
|
447
|
+
const baseEntities = memoizeExistingEntities(existingEntities);
|
|
448
|
+
const carryForward = async () => [...(await baseEntities()), ...foundNames];
|
|
442
449
|
let skippedReason: ExtractionResult["extractionSkippedReason"];
|
|
443
450
|
let providerCalls = 0;
|
|
444
451
|
for (const chunk of chunks) {
|
|
445
|
-
const part = await engine.extract(chunk,
|
|
452
|
+
const part = await engine.extract(chunk, carryForward, signal);
|
|
446
453
|
// A provider failure keeps the single-call surface so the run stays
|
|
447
454
|
// retryable under the no-drop contract; a per-chunk prefilter skip is
|
|
448
455
|
// not a failure — later chunks can still carry real facts.
|
|
@@ -463,7 +470,7 @@ export async function extractChunkedExtraction(
|
|
|
463
470
|
merged.episodeTitle ??= part.episodeTitle;
|
|
464
471
|
// Entity names found in earlier chunks flow into later calls so the
|
|
465
472
|
// LLM reuses them instead of inventing variants.
|
|
466
|
-
|
|
473
|
+
foundNames.push(...part.entities.map((entity) => entity.name));
|
|
467
474
|
}
|
|
468
475
|
// The connector must derive from the whole claim, not the first chunk —
|
|
469
476
|
// a mixed claim resolves to no connector, same as one call over the set.
|
|
@@ -362,18 +362,6 @@ test("runExtraction bounds storage preparation by its deadline", async () => {
|
|
|
362
362
|
};
|
|
363
363
|
},
|
|
364
364
|
},
|
|
365
|
-
{
|
|
366
|
-
name: "listEntityNames",
|
|
367
|
-
stage: "during_list_entity_names",
|
|
368
|
-
configure: async (harness: Harness) => {
|
|
369
|
-
const storage = await harness.storageForNs("default");
|
|
370
|
-
const listEntityNames = storage.listEntityNames.bind(storage);
|
|
371
|
-
storage.listEntityNames = async () => {
|
|
372
|
-
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
373
|
-
return listEntityNames();
|
|
374
|
-
};
|
|
375
|
-
},
|
|
376
|
-
},
|
|
377
365
|
] as const;
|
|
378
366
|
|
|
379
367
|
for (const scenario of scenarios) {
|
|
@@ -439,6 +427,29 @@ test("runExtraction force flush reports a late deadline after clearing committed
|
|
|
439
427
|
}
|
|
440
428
|
});
|
|
441
429
|
|
|
430
|
+
test("runExtraction does not list entity names on the local extraction path", async () => {
|
|
431
|
+
const harness = await makeHarness();
|
|
432
|
+
try {
|
|
433
|
+
const storage = await harness.storageForNs("default");
|
|
434
|
+
let listCalls = 0;
|
|
435
|
+
storage.listEntityNames = async () => {
|
|
436
|
+
listCalls += 1;
|
|
437
|
+
return new Promise<string[]>(() => {});
|
|
438
|
+
};
|
|
439
|
+
harness.setRespond(() => successResult());
|
|
440
|
+
const result = await harness.newCoordinator().runExtraction(makeTurns("lazy-entities"), {
|
|
441
|
+
skipCharThreshold: true,
|
|
442
|
+
skipUserTurnThreshold: true,
|
|
443
|
+
clearBufferAfterExtraction: false,
|
|
444
|
+
bufferKey: "lazy-entities",
|
|
445
|
+
});
|
|
446
|
+
assert.equal(listCalls, 0, "local-path extraction must not list the entity store");
|
|
447
|
+
assert.equal(result.status, "completed");
|
|
448
|
+
} finally {
|
|
449
|
+
await harness.cleanup();
|
|
450
|
+
}
|
|
451
|
+
});
|
|
452
|
+
|
|
442
453
|
test("runExtraction bounds threading pre-persist work by its deadline", async () => {
|
|
443
454
|
const harness = await makeHarness({ threadingEnabled: true });
|
|
444
455
|
try {
|
|
@@ -847,14 +847,15 @@ export class ExtractionRunCoordinator {
|
|
|
847
847
|
log.warn("runExtraction: extraction retry gate check failed; proceeding (fail-open)", err);
|
|
848
848
|
}
|
|
849
849
|
}
|
|
850
|
-
//
|
|
850
|
+
// Lazy entity list. A half-open probe lists first so a slow store cannot
|
|
851
|
+
// reopen the breaker. false keeps the deadline if extract() absorbs the error.
|
|
851
852
|
// The probe owner must release on ANY pre-persistence exit too (codex P1):
|
|
852
853
|
// the big try below only covers from the extract call onward.
|
|
853
854
|
try {
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
"during_list_entity_names",
|
|
857
|
-
);
|
|
855
|
+
let entityNamesPromise: Promise<string[]> | undefined;
|
|
856
|
+
const existingEntities = (): Promise<string[]> =>
|
|
857
|
+
(entityNamesPromise ??= runDeadlineAware(() => storage.listEntityNames(), "during_list_entity_names", false));
|
|
858
|
+
if (extractionProbeOwned) await existingEntities();
|
|
858
859
|
let result: ExtractionResult;
|
|
859
860
|
// The half-open probe is bounded: one that gets no answer in time counts as
|
|
860
861
|
// a provider failure (re-opens the breaker) instead of holding every other
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { mkdir, mkdtemp } from "node:fs/promises";
|
|
3
|
+
import os from "node:os";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import test from "node:test";
|
|
6
|
+
|
|
7
|
+
import { EntityCanonicalIdMigrationRunner } from "./entity-canonical-id-migration-runner.js";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* A runner wired to a scripted fingerprint queue and a migrate spy. Reads
|
|
11
|
+
* consume the queue in order; when it runs dry every read returns the settled
|
|
12
|
+
* value (the store converged after the migration's own writes). `settle(fp)`
|
|
13
|
+
* simulates the migration's writes landing: subsequent reads report `fp`.
|
|
14
|
+
*/
|
|
15
|
+
async function makeRunner(
|
|
16
|
+
reads: string[],
|
|
17
|
+
onRun?: (settle: (fp: string) => void) => void,
|
|
18
|
+
): Promise<{
|
|
19
|
+
runner: EntityCanonicalIdMigrationRunner;
|
|
20
|
+
calls: () => number;
|
|
21
|
+
entitiesDir: string;
|
|
22
|
+
}> {
|
|
23
|
+
const entitiesDir = await mkdtemp(path.join(os.tmpdir(), "remnic-runner-entities-"));
|
|
24
|
+
let calls = 0;
|
|
25
|
+
let settled: string | null = null;
|
|
26
|
+
let last = "moving";
|
|
27
|
+
const queue = [...reads];
|
|
28
|
+
const runner = new EntityCanonicalIdMigrationRunner(
|
|
29
|
+
() => true,
|
|
30
|
+
async () => {
|
|
31
|
+
calls += 1;
|
|
32
|
+
onRun?.((fp) => {
|
|
33
|
+
settled = fp;
|
|
34
|
+
});
|
|
35
|
+
},
|
|
36
|
+
async () => {
|
|
37
|
+
const value = queue.shift() ?? settled ?? last;
|
|
38
|
+
last = value;
|
|
39
|
+
return value;
|
|
40
|
+
},
|
|
41
|
+
);
|
|
42
|
+
return { runner, calls: () => calls, entitiesDir };
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** First run completes and records the fingerprint it stabilized on; a stable unchanged fingerprint never re-runs. */
|
|
46
|
+
test("first run completes; stable unchanged fingerprint never re-runs", async () => {
|
|
47
|
+
// Run 1: start s0; the migration's writes settle the store on s0, so the
|
|
48
|
+
// post-run reads agree with the start (the void-return storage contract).
|
|
49
|
+
const { runner, calls, entitiesDir } = await makeRunner(["s0"], (settle) => settle("s0"));
|
|
50
|
+
await runner.begin(false, entitiesDir);
|
|
51
|
+
await runner.finishBegin(false);
|
|
52
|
+
await runner.drain();
|
|
53
|
+
assert.equal(calls(), 1);
|
|
54
|
+
await runner.triggerAfterUnlock();
|
|
55
|
+
await runner.drain();
|
|
56
|
+
assert.equal(calls(), 1);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
/** Issue #3713: under sustained writes the fingerprint keeps moving between reads. Re-running the full migrate on every trigger re-contends the migration lock and starves drains — the runner must DEFER (skip the run) while the fingerprint is unstable; the reconcile marker survives and a later settled trigger reconciles. */
|
|
60
|
+
test("an unstable fingerprint after completion defers the re-run until it settles", async () => {
|
|
61
|
+
// Read script, consumed in order:
|
|
62
|
+
// run 1: start s0; writes settle the store on s0 -> complete
|
|
63
|
+
// trigger 2 (sustained writes): start u1, stability u2 -> moving: defer
|
|
64
|
+
// trigger 3 (still moving): start u3, stability u4 -> defer again
|
|
65
|
+
// trigger 4 (settled): start s9, stability s9 -> reconcile run fires once,
|
|
66
|
+
// and the migration's writes settle the store on s9.
|
|
67
|
+
let runs = 0;
|
|
68
|
+
const reads: string[] = [
|
|
69
|
+
"s0", "s0", "s0", // run 1: start s0, post-run s0 s0 (stable -> complete, fp s0)
|
|
70
|
+
"u1", "u2", // trigger 2: start u1, stability u2 -> moving: defer
|
|
71
|
+
"u3", "u4", // trigger 3: still moving -> defer again
|
|
72
|
+
"s9", "s9", // trigger 4: settled -> reconcile run fires once, fp moves to s9
|
|
73
|
+
];
|
|
74
|
+
const { runner, calls, entitiesDir } = await makeRunner(reads, () => {
|
|
75
|
+
runs += 1;
|
|
76
|
+
});
|
|
77
|
+
await runner.begin(false, entitiesDir);
|
|
78
|
+
await runner.finishBegin(false);
|
|
79
|
+
await runner.drain();
|
|
80
|
+
await runner.triggerAfterUnlock();
|
|
81
|
+
await runner.drain();
|
|
82
|
+
assert.equal(calls(), 1, "sustained writes: an unstable fingerprint must defer the re-run");
|
|
83
|
+
await runner.triggerAfterUnlock();
|
|
84
|
+
await runner.drain();
|
|
85
|
+
assert.equal(calls(), 1, "still moving: defer again");
|
|
86
|
+
await runner.triggerAfterUnlock();
|
|
87
|
+
await runner.drain();
|
|
88
|
+
assert.equal(calls(), 2, "once the fingerprint settles, the reconcile run fires exactly once");
|
|
89
|
+
assert.equal(runs, 2);
|
|
90
|
+
});
|
|
@@ -71,6 +71,16 @@ export class EntityCanonicalIdMigrationRunner {
|
|
|
71
71
|
private async runOrReuse(): Promise<void> {
|
|
72
72
|
let fingerprintAtStart = await this.readFingerprint();
|
|
73
73
|
if (this.migrationComplete && fingerprintAtStart === this.completedFingerprint) return;
|
|
74
|
+
if (this.migrationComplete) {
|
|
75
|
+
// Issue #3713: under sustained writes the fingerprint keeps moving, and
|
|
76
|
+
// re-running the full migrate on every trigger re-contends the
|
|
77
|
+
// migration lock and starves drains. Defer while it is unstable: the
|
|
78
|
+
// reconcile marker survives, and a later trigger that reads a settled
|
|
79
|
+
// fingerprint serves the reconciliation.
|
|
80
|
+
const stabilityRead = await this.readFingerprint();
|
|
81
|
+
if (stabilityRead !== fingerprintAtStart) return;
|
|
82
|
+
fingerprintAtStart = stabilityRead;
|
|
83
|
+
}
|
|
74
84
|
|
|
75
85
|
for (let attempt = 0; attempt < 3; attempt += 1) {
|
|
76
86
|
const completionFingerprint = await this.runMigration();
|
package/dist/chunk-5YQXWVCP.js
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
log
|
|
3
|
-
} from "./chunk-3WCASNQZ.js";
|
|
4
|
-
|
|
5
|
-
// src/local-llm-transport.ts
|
|
6
|
-
import { Agent, getGlobalDispatcher } from "undici";
|
|
7
|
-
function isPlainPoolingAgent(dispatcher) {
|
|
8
|
-
if (dispatcher instanceof Agent) return true;
|
|
9
|
-
if (!dispatcher || typeof dispatcher !== "object") return false;
|
|
10
|
-
const ctor = dispatcher.constructor;
|
|
11
|
-
if (!ctor || typeof ctor !== "function") return false;
|
|
12
|
-
return ctor.name === "Agent";
|
|
13
|
-
}
|
|
14
|
-
var directProbeAgent = null;
|
|
15
|
-
function directProbeDispatcher() {
|
|
16
|
-
if (process.env.REMNIC_LOCAL_LLM_DIRECT !== "1") return void 0;
|
|
17
|
-
directProbeAgent ??= new Agent();
|
|
18
|
-
return directProbeAgent;
|
|
19
|
-
}
|
|
20
|
-
var ChatTransport = class {
|
|
21
|
-
agent = null;
|
|
22
|
-
agentBudgetMs = null;
|
|
23
|
-
warnedAboutCustomDispatcher = false;
|
|
24
|
-
/**
|
|
25
|
-
* The widened pool, or `undefined` when the process installed its own
|
|
26
|
-
* transport that we must not displace.
|
|
27
|
-
*
|
|
28
|
-
* A deployment can route the local endpoint through a process-wide
|
|
29
|
-
* dispatcher — a `ProxyAgent` for an HTTP proxy, or a custom
|
|
30
|
-
* connect/TLS/DNS dispatcher. Swapping in our own pool would bypass the
|
|
31
|
-
* proxy entirely and break the request, so those are left alone. A
|
|
32
|
-
* `MockAgent` is excluded by the same check, so test transports keep
|
|
33
|
-
* working. The trade-off is explicit: on those setups the 300s cap stands,
|
|
34
|
-
* because only the dispatcher's owner knows how to rebuild it.
|
|
35
|
-
*/
|
|
36
|
-
dispatcherFor(budgetMs) {
|
|
37
|
-
if (!isPlainPoolingAgent(getGlobalDispatcher()) && process.env.REMNIC_LOCAL_LLM_DIRECT !== "1") {
|
|
38
|
-
if (!this.warnedAboutCustomDispatcher) {
|
|
39
|
-
this.warnedAboutCustomDispatcher = true;
|
|
40
|
-
log.debug(
|
|
41
|
-
"local LLM: a custom global dispatcher is installed; leaving it in place. localLlmTimeoutMs above that dispatcher's headersTimeout will not take effect."
|
|
42
|
-
);
|
|
43
|
-
}
|
|
44
|
-
return void 0;
|
|
45
|
-
}
|
|
46
|
-
const normalized = Number.isFinite(budgetMs) ? Math.max(0, budgetMs) : 0;
|
|
47
|
-
if (this.agent && this.agentBudgetMs === normalized) return this.agent;
|
|
48
|
-
void this.agent?.close().catch(() => {
|
|
49
|
-
});
|
|
50
|
-
this.agent = new Agent({
|
|
51
|
-
headersTimeout: normalized,
|
|
52
|
-
bodyTimeout: normalized
|
|
53
|
-
});
|
|
54
|
-
this.agentBudgetMs = normalized;
|
|
55
|
-
return this.agent;
|
|
56
|
-
}
|
|
57
|
-
async post(request) {
|
|
58
|
-
const init = {
|
|
59
|
-
method: "POST",
|
|
60
|
-
headers: request.headers,
|
|
61
|
-
body: request.body,
|
|
62
|
-
signal: request.signal
|
|
63
|
-
};
|
|
64
|
-
const dispatcher = this.dispatcherFor(request.budgetMs);
|
|
65
|
-
if (dispatcher) init.dispatcher = dispatcher;
|
|
66
|
-
return await fetch(request.url, init);
|
|
67
|
-
}
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
export {
|
|
71
|
-
directProbeDispatcher,
|
|
72
|
-
ChatTransport
|
|
73
|
-
};
|
|
74
|
-
//# sourceMappingURL=chunk-5YQXWVCP.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/local-llm-transport.ts"],"sourcesContent":["import { Agent, getGlobalDispatcher } from \"undici\";\n\nimport { log } from \"./logger.js\";\n\n/**\n * Wire transport for local LLM chat completions.\n *\n * Split out of `local-llm.ts` so the client module keeps prompt and\n * response semantics while connection budgets live in one place.\n */\n\nexport interface ChatCompletionRequest {\n url: string;\n headers: Record<string, string>;\n body: string;\n signal: AbortSignal;\n /**\n * Ceiling for this endpoint, i.e. `localLlmTimeoutMs`. Sizes the\n * connection's inactivity budgets. Per-request budgets below the ceiling\n * stay enforced by `signal`.\n */\n budgetMs: number;\n}\n\n/**\n * Is this undici's stock pooling `Agent` — the transport we may widen?\n *\n * `instanceof` alone is not enough: Node's global fetch is backed by its\n * OWN bundled copy of undici, so the dispatcher parked on the well-known\n * global symbol is an `Agent` from a different copy than the one we import,\n * and cross-copy `instanceof` is false. Fall back to the constructor name,\n * which is stable across copies and still distinguishes `ProxyAgent` and\n * `MockAgent` from the stock pool.\n */\nfunction isPlainPoolingAgent(dispatcher: unknown): boolean {\n if (dispatcher instanceof Agent) return true;\n if (!dispatcher || typeof dispatcher !== \"object\") return false;\n const ctor = (dispatcher as { constructor?: unknown }).constructor;\n if (!ctor || typeof ctor !== \"function\") return false;\n return ctor.name === \"Agent\";\n}\n\n/**\n * REMNIC_LOCAL_LLM_DIRECT=1 declares that the local endpoint is reached\n * directly. Availability probes use this shared plain pool in that mode so they\n * take the same route as chat requests; `undefined` keeps the global dispatcher.\n */\nlet directProbeAgent: Agent | null = null;\nexport function directProbeDispatcher(): Agent | undefined {\n if (process.env.REMNIC_LOCAL_LLM_DIRECT !== \"1\") return undefined;\n directProbeAgent ??= new Agent();\n return directProbeAgent;\n}\n\n/**\n * Connection pool whose header/body inactivity budgets track the configured\n * request budget.\n *\n * Node's global fetch runs on undici, which applies a default\n * `headersTimeout` and `bodyTimeout` of 300s. A non-streaming completion\n * sends its response headers only once generation finishes, so any\n * completion slower than 300s died with a bare `fetch failed` no matter how\n * high `localLlmTimeoutMs` was set — the configured budget was dead letter\n * past five minutes (issue #2148).\n *\n * One pool per client is enough: it is keyed on the ceiling and rebuilt when\n * that changes.\n */\nexport class ChatTransport {\n private agent: Agent | null = null;\n private agentBudgetMs: number | null = null;\n private warnedAboutCustomDispatcher = false;\n\n /**\n * The widened pool, or `undefined` when the process installed its own\n * transport that we must not displace.\n *\n * A deployment can route the local endpoint through a process-wide\n * dispatcher — a `ProxyAgent` for an HTTP proxy, or a custom\n * connect/TLS/DNS dispatcher. Swapping in our own pool would bypass the\n * proxy entirely and break the request, so those are left alone. A\n * `MockAgent` is excluded by the same check, so test transports keep\n * working. The trade-off is explicit: on those setups the 300s cap stands,\n * because only the dispatcher's owner knows how to rebuild it.\n */\n dispatcherFor(budgetMs: number): Agent | undefined {\n // REMNIC_LOCAL_LLM_DIRECT=1: the operator declares the local endpoint is reached directly even though the process installed a global dispatcher for other traffic (an agent runtime's managed proxy). Without it the 300s header cap stands silently on such hosts and every completion slower than five minutes dies with `fetch failed`. Off by default so deployments that must use a proxy keep it.\n if (!isPlainPoolingAgent(getGlobalDispatcher()) && process.env.REMNIC_LOCAL_LLM_DIRECT !== \"1\") {\n if (!this.warnedAboutCustomDispatcher) {\n this.warnedAboutCustomDispatcher = true;\n log.debug(\n \"local LLM: a custom global dispatcher is installed; leaving it in place. \" +\n \"localLlmTimeoutMs above that dispatcher's headersTimeout will not take effect.\",\n );\n }\n return undefined;\n }\n const normalized = Number.isFinite(budgetMs) ? Math.max(0, budgetMs) : 0;\n if (this.agent && this.agentBudgetMs === normalized) return this.agent;\n void this.agent?.close().catch(() => {\n /* pool teardown is best-effort */\n });\n this.agent = new Agent({\n headersTimeout: normalized,\n bodyTimeout: normalized,\n });\n this.agentBudgetMs = normalized;\n return this.agent;\n }\n\n async post(request: ChatCompletionRequest): Promise<Response> {\n const init: RequestInit & { dispatcher?: Agent } = {\n method: \"POST\",\n headers: request.headers,\n body: request.body,\n signal: request.signal,\n };\n const dispatcher = this.dispatcherFor(request.budgetMs);\n if (dispatcher) init.dispatcher = dispatcher;\n return await fetch(request.url, init);\n }\n}\n"],"mappings":";;;;;AAAA,SAAS,OAAO,2BAA2B;AAkC3C,SAAS,oBAAoB,YAA8B;AACzD,MAAI,sBAAsB,MAAO,QAAO;AACxC,MAAI,CAAC,cAAc,OAAO,eAAe,SAAU,QAAO;AAC1D,QAAM,OAAQ,WAAyC;AACvD,MAAI,CAAC,QAAQ,OAAO,SAAS,WAAY,QAAO;AAChD,SAAO,KAAK,SAAS;AACvB;AAOA,IAAI,mBAAiC;AAC9B,SAAS,wBAA2C;AACzD,MAAI,QAAQ,IAAI,4BAA4B,IAAK,QAAO;AACxD,uBAAqB,IAAI,MAAM;AAC/B,SAAO;AACT;AAgBO,IAAM,gBAAN,MAAoB;AAAA,EACjB,QAAsB;AAAA,EACtB,gBAA+B;AAAA,EAC/B,8BAA8B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EActC,cAAc,UAAqC;AAEjD,QAAI,CAAC,oBAAoB,oBAAoB,CAAC,KAAK,QAAQ,IAAI,4BAA4B,KAAK;AAC9F,UAAI,CAAC,KAAK,6BAA6B;AACrC,aAAK,8BAA8B;AACnC,YAAI;AAAA,UACF;AAAA,QAEF;AAAA,MACF;AACA,aAAO;AAAA,IACT;AACA,UAAM,aAAa,OAAO,SAAS,QAAQ,IAAI,KAAK,IAAI,GAAG,QAAQ,IAAI;AACvE,QAAI,KAAK,SAAS,KAAK,kBAAkB,WAAY,QAAO,KAAK;AACjE,SAAK,KAAK,OAAO,MAAM,EAAE,MAAM,MAAM;AAAA,IAErC,CAAC;AACD,SAAK,QAAQ,IAAI,MAAM;AAAA,MACrB,gBAAgB;AAAA,MAChB,aAAa;AAAA,IACf,CAAC;AACD,SAAK,gBAAgB;AACrB,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,MAAM,KAAK,SAAmD;AAC5D,UAAM,OAA6C;AAAA,MACjD,QAAQ;AAAA,MACR,SAAS,QAAQ;AAAA,MACjB,MAAM,QAAQ;AAAA,MACd,QAAQ,QAAQ;AAAA,IAClB;AACA,UAAM,aAAa,KAAK,cAAc,QAAQ,QAAQ;AACtD,QAAI,WAAY,MAAK,aAAa;AAClC,WAAO,MAAM,MAAM,QAAQ,KAAK,IAAI;AAAA,EACtC;AACF;","names":[]}
|