@wrongstack/core 0.313.0 → 0.316.1
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/chronicle/index.js +84 -6391
- package/dist/chronicle/legacy-journal-import.d.ts +0 -6
- package/dist/chronicle/metrics-ingest.d.ts +14 -0
- package/dist/chronicle/metrics-schema.d.ts +10 -1
- package/dist/chronicle/metrics-store.d.ts +20 -2
- package/dist/chronicle/project-server.js +98 -4874
- package/dist/chronicle/sink.d.ts +13 -0
- package/dist/chronicle/sqlite-journal.d.ts +20 -2
- package/dist/chunk-25LSLC3G.js +334 -0
- package/dist/chunk-27QIURLN.js +1073 -0
- package/dist/chunk-2FK4WTFF.js +207 -0
- package/dist/chunk-2YU4WVBW.js +134 -0
- package/dist/chunk-3AGWVSS7.js +4608 -0
- package/dist/chunk-3BDV7RL3.js +211 -0
- package/dist/chunk-3ECENVHL.js +325 -0
- package/dist/chunk-3XPVB7BA.js +135 -0
- package/dist/chunk-45WI72ZB.js +16884 -0
- package/dist/chunk-4BMVPOHO.js +3748 -0
- package/dist/chunk-4I7HGVVA.js +363 -0
- package/dist/chunk-4LCZVJVF.js +317 -0
- package/dist/chunk-4SJNS7OB.js +217 -0
- package/dist/chunk-4VWO3ZXL.js +342 -0
- package/dist/chunk-57GEWK5X.js +26 -0
- package/dist/chunk-5BMIE7QG.js +46 -0
- package/dist/chunk-5S437PRC.js +50 -0
- package/dist/chunk-5XDUGTKN.js +511 -0
- package/dist/chunk-5YPSXQXM.js +1443 -0
- package/dist/chunk-6FHWXLPT.js +10 -0
- package/dist/chunk-6H5GEOET.js +2406 -0
- package/dist/chunk-6NWEVFEL.js +151 -0
- package/dist/chunk-AYW5YINX.js +58 -0
- package/dist/chunk-B4AMLZPB.js +9 -0
- package/dist/chunk-B7F4WVP4.js +65 -0
- package/dist/chunk-BJHVULHO.js +55 -0
- package/dist/chunk-BPBKKBUK.js +2085 -0
- package/dist/chunk-BYD345OX.js +589 -0
- package/dist/chunk-C27KDLOX.js +279 -0
- package/dist/chunk-CU546ESW.js +597 -0
- package/dist/chunk-DLHHXUAM.js +172 -0
- package/dist/chunk-DOTHQSJ2.js +429 -0
- package/dist/chunk-DYLPMV4Q.js +711 -0
- package/dist/chunk-EODDVJBM.js +82 -0
- package/dist/chunk-F3JWNST7.js +361 -0
- package/dist/chunk-FC2ZGRF3.js +140 -0
- package/dist/chunk-FCBTO76Z.js +5786 -0
- package/dist/chunk-FHZVFYSL.js +396 -0
- package/dist/chunk-FNXVT7HF.js +52 -0
- package/dist/chunk-FWNLEZYG.js +259 -0
- package/dist/chunk-FXQLIX3K.js +211 -0
- package/dist/chunk-G5S3S5ZN.js +38 -0
- package/dist/chunk-GDQ7CZRQ.js +116 -0
- package/dist/chunk-GJJGJB2R.js +1374 -0
- package/dist/chunk-GTCU6DZ3.js +1 -0
- package/dist/chunk-HA4ZYA6T.js +178 -0
- package/dist/chunk-HI3JGZR2.js +188 -0
- package/dist/chunk-HMLIGAU7.js +395 -0
- package/dist/chunk-HXKZ7OBQ.js +303 -0
- package/dist/chunk-I7DALG7J.js +292 -0
- package/dist/chunk-IRUTEHCE.js +960 -0
- package/dist/chunk-IYFBFX34.js +86 -0
- package/dist/chunk-J2WRWR37.js +1104 -0
- package/dist/chunk-JFPJ6LLQ.js +129 -0
- package/dist/chunk-JMULFFLN.js +9 -0
- package/dist/chunk-JO4MGB6Z.js +1264 -0
- package/dist/chunk-JVKB2TBL.js +48 -0
- package/dist/chunk-JX7VBZDK.js +31 -0
- package/dist/chunk-K6BXGITA.js +931 -0
- package/dist/chunk-KDQJCT2J.js +45 -0
- package/dist/chunk-KJ2ZTQSL.js +47 -0
- package/dist/chunk-KZMSZV32.js +187 -0
- package/dist/chunk-LA7CLDRW.js +129 -0
- package/dist/chunk-LHOA5DWA.js +28 -0
- package/dist/chunk-LSMMOS2Z.js +119 -0
- package/dist/chunk-LX5QWLBL.js +27 -0
- package/dist/chunk-LXWCMQNJ.js +789 -0
- package/dist/chunk-M27LIEKV.js +2829 -0
- package/dist/chunk-MJPHJRAL.js +663 -0
- package/dist/chunk-MTL4O5YR.js +228 -0
- package/dist/chunk-NDBIPFNY.js +102 -0
- package/dist/chunk-NEMIWEXC.js +1199 -0
- package/dist/chunk-NHJ75HXY.js +1 -0
- package/dist/chunk-NIOAGFPB.js +1510 -0
- package/dist/chunk-NS52ISWS.js +355 -0
- package/dist/chunk-NSOFPKGT.js +5352 -0
- package/dist/chunk-NVIZG63R.js +757 -0
- package/dist/chunk-O37BQ65S.js +21 -0
- package/dist/chunk-OOYZPOXM.js +308 -0
- package/dist/chunk-OSGLYW5J.js +28 -0
- package/dist/chunk-PFCMSSUF.js +1640 -0
- package/dist/chunk-PFZO3C6H.js +14 -0
- package/dist/chunk-PGRVXIMY.js +158 -0
- package/dist/chunk-PHH7LD45.js +113 -0
- package/dist/chunk-PISBFBJN.js +109 -0
- package/dist/chunk-POOOIWE5.js +9 -0
- package/dist/chunk-PQNS3U7Z.js +1240 -0
- package/dist/chunk-QSTSJOCK.js +402 -0
- package/dist/chunk-RFQMOKWK.js +282 -0
- package/dist/chunk-RJIZEJ42.js +30 -0
- package/dist/chunk-RTOTNK3P.js +484 -0
- package/dist/chunk-RXKSDUAU.js +1172 -0
- package/dist/chunk-S45JPKQN.js +3317 -0
- package/dist/chunk-SAFHACFA.js +152 -0
- package/dist/chunk-SQJVFEBV.js +41 -0
- package/dist/chunk-SVT4RNTR.js +49 -0
- package/dist/chunk-SWUFN7XM.js +43 -0
- package/dist/chunk-SXMVYC5H.js +174 -0
- package/dist/chunk-SZ6AYUIZ.js +23 -0
- package/dist/chunk-TBRL2RCC.js +9 -0
- package/dist/chunk-TCCHINEF.js +655 -0
- package/dist/chunk-THEGTRAG.js +316 -0
- package/dist/chunk-TR4LQE7L.js +2256 -0
- package/dist/chunk-TRT2HRWZ.js +18 -0
- package/dist/chunk-TWJMGXCI.js +900 -0
- package/dist/chunk-U45AXT5D.js +1023 -0
- package/dist/chunk-U4FWBSO3.js +509 -0
- package/dist/chunk-UBGDX6FI.js +147 -0
- package/dist/chunk-UJILKYES.js +75 -0
- package/dist/chunk-ULMAQV3T.js +234 -0
- package/dist/chunk-VVBP6KGT.js +9 -0
- package/dist/chunk-W5VITDM2.js +168 -0
- package/dist/chunk-WAHQVNWT.js +194 -0
- package/dist/chunk-WBPVKEEE.js +227 -0
- package/dist/chunk-WGGYRBXH.js +5434 -0
- package/dist/chunk-WLYKU45P.js +5770 -0
- package/dist/chunk-WP7BVANJ.js +53 -0
- package/dist/chunk-WQQON3SV.js +473 -0
- package/dist/chunk-WQTOVMGV.js +119 -0
- package/dist/chunk-XBDP4QPW.js +7 -0
- package/dist/chunk-XEBHSJLT.js +103 -0
- package/dist/chunk-XF4VUMKW.js +231 -0
- package/dist/chunk-XQ2ECNK3.js +1 -0
- package/dist/chunk-Y5YXDM7D.js +74 -0
- package/dist/chunk-YOPAUVU4.js +2588 -0
- package/dist/chunk-YPT4A46F.js +362 -0
- package/dist/chunk-YWXT3JNM.js +425 -0
- package/dist/chunk-YY6APYUM.js +49 -0
- package/dist/chunk-Z2IJUO45.js +691 -0
- package/dist/chunk-ZHZ2Y2DH.js +1643 -0
- package/dist/chunk-ZT7JNIGX.js +152 -0
- package/dist/coordination/agent-monitor.d.ts +9 -1
- package/dist/coordination/agent-subagent-runner.d.ts +1 -1
- package/dist/coordination/agents/agent-prompts.d.ts +8 -0
- package/dist/coordination/agents/index.d.ts +33 -1
- package/dist/coordination/agents/index.js +184 -6269
- package/dist/coordination/agents/phase3-wave1-platform.d.ts +1 -3
- package/dist/coordination/agents/phase3-wave2-meta.d.ts +1 -3
- package/dist/coordination/agents/phase8-wave3-products.d.ts +1 -3
- package/dist/coordination/agents/phase9-wave4-platform-meta.d.ts +1 -3
- package/dist/coordination/agents/project-agent-identity.d.ts +11 -11
- package/dist/coordination/agents/types.d.ts +13 -2
- package/dist/coordination/brain-monitor.d.ts +30 -7
- package/dist/coordination/collab-debug.d.ts +1 -1
- package/dist/coordination/collab-pause.d.ts +1 -1
- package/dist/coordination/delegate-tool.d.ts +7 -5
- package/dist/coordination/director-kanban-queue-helpers.d.ts +1 -0
- package/dist/coordination/director-options.d.ts +7 -0
- package/dist/coordination/director-spawn-model.d.ts +17 -0
- package/dist/coordination/director-tools.d.ts +2 -2
- package/dist/coordination/director.d.ts +12 -0
- package/dist/coordination/dispatcher.d.ts +8 -0
- package/dist/coordination/fleet-bus.d.ts +35 -4
- package/dist/coordination/fleet-supervisor.d.ts +10 -2
- package/dist/coordination/fleet.d.ts +16 -7
- package/dist/coordination/index.d.ts +4 -0
- package/dist/coordination/index.js +402 -34324
- package/dist/coordination/kanban-dispatch-port.d.ts +2 -2
- package/dist/coordination/mailbox-http-router.d.ts +4 -3
- package/dist/coordination/mailbox-http-validation.d.ts +1 -1
- package/dist/coordination/mailbox-project-server.js +48 -3276
- package/dist/coordination/mailbox-types.d.ts +24 -6
- package/dist/coordination/model-tier-leader.d.ts +122 -0
- package/dist/coordination/model-tier.d.ts +122 -0
- package/dist/coordination/multi-agent-coordinator.d.ts +24 -0
- package/dist/coordination/origin-session.d.ts +16 -0
- package/dist/coordination/provider-status-tracker.d.ts +41 -5
- package/dist/coordination/session-note-hub.d.ts +44 -0
- package/dist/coordination/session-note-tool.d.ts +10 -0
- package/dist/core/agent.d.ts +15 -2
- package/dist/core/context.d.ts +22 -3
- package/dist/core/index.d.ts +2 -0
- package/dist/core/index.js +239 -12360
- package/dist/core/model-ref.js +5 -23
- package/dist/core/provider-runner.d.ts +36 -1
- package/dist/core/request-conversation-binding.d.ts +37 -0
- package/dist/core/session-notes.d.ts +25 -0
- package/dist/core/system-prompt-builder.d.ts +11 -2
- package/dist/core/system-prompt-variants.d.ts +78 -0
- package/dist/design/index.js +50 -1087
- package/dist/execution/auto-compaction-middleware.d.ts +11 -0
- package/dist/execution/autonomy-brain.d.ts +2 -1
- package/dist/execution/autonomy-prompt-contributor.d.ts +7 -2
- package/dist/execution/compaction-core.d.ts +4 -4
- package/dist/execution/eternal-autonomy.d.ts +1 -1
- package/dist/execution/index.d.ts +1 -1
- package/dist/execution/index.js +1615 -21895
- package/dist/execution/model-runtime.d.ts +0 -7
- package/dist/execution/parallel-eternal-engine.d.ts +7 -7
- package/dist/execution/prompt-enhancer.js +16 -535
- package/dist/execution/retry-policy.d.ts +31 -1
- package/dist/extension/index.js +7 -311
- package/dist/goal/index.js +33 -3435
- package/dist/hooks/index.js +14 -1138
- package/dist/hq/index.js +114 -5139
- package/dist/hq/persistence/event-log.d.ts +0 -1
- package/dist/hq/persistence.d.ts +4 -4
- package/dist/hq/protocol.js +21 -668
- package/dist/hq/publisher.d.ts +2 -0
- package/dist/index.d.ts +14 -11
- package/dist/index.js +1502 -92655
- package/dist/infrastructure/index.d.ts +4 -4
- package/dist/infrastructure/index.js +504 -5230
- package/dist/infrastructure/token-counter.d.ts +9 -0
- package/dist/kernel/events/agent-events.d.ts +77 -3
- package/dist/kernel/events/brain-events.d.ts +12 -0
- package/dist/kernel/events/provider-events.d.ts +22 -1
- package/dist/kernel/events/session-events.d.ts +14 -0
- package/dist/kernel/events/tool-events.d.ts +13 -0
- package/dist/kernel/index.js +14 -992
- package/dist/mailbox-attach.d.ts +1 -1
- package/dist/models/index.js +41 -1117
- package/dist/notifications/index.js +3 -108
- package/dist/observability/event-bridge.d.ts +25 -5
- package/dist/observability/index.d.ts +9 -8
- package/dist/observability/index.js +477 -631
- package/dist/observability/tool-usage-source.d.ts +65 -0
- package/dist/plugin/index.d.ts +5 -0
- package/dist/plugin/index.js +600 -14835
- package/dist/plugins/auto-review-plugin.d.ts +3 -2
- package/dist/plugins/review-finding-commands.d.ts +0 -8
- package/dist/plugins/review-finding-store.js +22 -0
- package/dist/plugins/review-finding-types.js +19 -0
- package/dist/plugins/review-report-integration.js +21 -0
- package/dist/plugins/review-report-store.js +20 -0
- package/dist/plugins/review-report-types.js +13 -0
- package/dist/prompts/index.js +14 -948
- package/dist/registry/index.js +9 -822
- package/dist/registry/tool-registry.d.ts +59 -9
- package/dist/registry-7N4O3E7W.js +14 -0
- package/dist/replay/index.js +6 -84
- package/dist/security/capabilities.d.ts +6 -0
- package/dist/security/file-permissions.d.ts +1 -1
- package/dist/security/index.js +161 -2235
- package/dist/security/permission-policy.d.ts +12 -1
- package/dist/security/secret-scrubber.d.ts +15 -0
- package/dist/session-catalog/index.d.ts +1 -0
- package/dist/session-catalog/index.js +41 -2103
- package/dist/session-catalog/project-server.js +59 -1435
- package/dist/session-catalog/protocol.d.ts +32 -1
- package/dist/session-catalog/registry.d.ts +17 -1
- package/dist/session-catalog/session-agents.d.ts +56 -0
- package/dist/session-catalog/store-rebuild.d.ts +14 -0
- package/dist/session-catalog/store-schema.d.ts +26 -0
- package/dist/session-catalog/store.d.ts +27 -1
- package/dist/session-note-attach.d.ts +9 -0
- package/dist/skills/index.js +35 -1578
- package/dist/statusline/index.d.ts +43 -0
- package/dist/statusline/index.js +102 -0
- package/dist/storage/board-store-port.d.ts +2 -2
- package/dist/storage/config-loader/in-project-policy.d.ts +29 -0
- package/dist/storage/config-loader.d.ts +3 -2
- package/dist/storage/file-session-writer.d.ts +4 -2
- package/dist/storage/goal-coordination.d.ts +6 -1
- package/dist/storage/goal-kanban.d.ts +4 -1
- package/dist/storage/index.d.ts +12 -4
- package/dist/storage/index.js +198 -15601
- package/dist/storage/input-history-store.d.ts +2 -4
- package/dist/storage/memory-curator.d.ts +133 -0
- package/dist/storage/session-agent-attribution.d.ts +39 -0
- package/dist/storage/session-doctor.d.ts +109 -0
- package/dist/storage/session-event-bridge.d.ts +5 -7
- package/dist/storage/session-outcome.d.ts +42 -0
- package/dist/storage/session-recovery.d.ts +55 -0
- package/dist/storage/session-store/load-session-data.d.ts +11 -0
- package/dist/storage/session-store/prune-helpers.d.ts +1 -1
- package/dist/storage/session-store/resume-session.d.ts +0 -2
- package/dist/storage/session-store/types.d.ts +8 -0
- package/dist/storage/session-store.d.ts +3 -3
- package/dist/storage/session-summary-tracker.d.ts +8 -1
- package/dist/storage/session-write-buffer.d.ts +18 -0
- package/dist/storage/session-writer-truncate.d.ts +2 -0
- package/dist/tasking/index.js +10 -676
- package/dist/tools/fallback-manage-tools.d.ts +6 -4
- package/dist/tools/index.js +52 -9590
- package/dist/tools/model-tier-set-tool.d.ts +66 -0
- package/dist/types/agent-bridge.d.ts +2 -1
- package/dist/types/config/autonomy.d.ts +5 -0
- package/dist/types/config/mcp-features.d.ts +7 -0
- package/dist/types/config/model-tiers.d.ts +148 -0
- package/dist/types/config/root.d.ts +9 -0
- package/dist/types/config/tools.d.ts +73 -0
- package/dist/types/config/ui.d.ts +1 -1
- package/dist/types/config.d.ts +1 -0
- package/dist/types/context.d.ts +2 -0
- package/dist/types/default-config.d.ts +6 -0
- package/dist/types/errors.d.ts +20 -1
- package/dist/types/index.d.ts +11 -9
- package/dist/types/index.js +131 -1342
- package/dist/types/multi-agent.d.ts +43 -0
- package/dist/types/plugin.d.ts +1 -1
- package/dist/types/provider-runner.d.ts +8 -0
- package/dist/types/provider.d.ts +15 -0
- package/dist/types/runtime-capability-manifest.d.ts +1 -1
- package/dist/types/secret-scrubber.d.ts +15 -0
- package/dist/types/session-markers.d.ts +37 -10
- package/dist/types/session-markers.js +8 -144
- package/dist/types/session-timeline.d.ts +197 -0
- package/dist/types/session-timeline.js +12 -0
- package/dist/types/session.d.ts +172 -11
- package/dist/types/system-prompt.d.ts +27 -0
- package/dist/utils/config-backup.d.ts +9 -1
- package/dist/utils/error.js +3 -4
- package/dist/utils/expect-defined.js +3 -9
- package/dist/utils/heap-watchdog.js +6 -706
- package/dist/utils/index.js +271 -5685
- package/dist/utils/message-invariants.d.ts +4 -1
- package/dist/utils/regex-guard.d.ts +1 -1
- package/dist/utils/sage-output-block.js +5 -42
- package/dist/utils/socket-path.d.ts +1 -1
- package/dist/utils/token-estimate.d.ts +6 -2
- package/dist/utils/wstack-paths.d.ts +2 -0
- package/dist/wiring/proxy-rewrite.d.ts +46 -0
- package/dist/wiring/proxy-rewrite.js +24 -121
- package/dist/worktree/index.js +6 -887
- package/instructions/agents/explore-companion.md +45 -18
- package/instructions/agents/memory-curator.md +34 -22
- package/instructions/coordination/director-preamble.md +12 -7
- package/instructions/coordination/subagent-baseline.md +26 -5
- package/instructions/leader-after-task.md +4 -1
- package/instructions/llm/chimera-review.md +30 -9
- package/instructions/llm/memory-curator.md +31 -0
- package/instructions/sections/tool/delegation-compact.md +2 -0
- package/instructions/sections/tool/delegation-full.md +5 -1
- package/instructions/sections/tool/mailbox-compact.md +5 -1
- package/instructions/sections/tool/mailbox-full.md +3 -0
- package/instructions/sections/tool/session-note-compact.md +3 -0
- package/instructions/sections/tool/session-note-full.md +15 -0
- package/instructions/system-lite.md +9 -4
- package/instructions/system-pro.md +66 -143
- package/instructions/system.md +73 -175
- package/package.json +32 -4
- package/dist/coordination/agents.d.ts +0 -8
- package/dist/coordination/transport.d.ts +0 -2
- package/dist/storage/session-writer/session-writer-summary-tracker.d.ts +0 -28
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
import {
|
|
2
|
+
SESSION_MARKER_EVENT_TYPES,
|
|
3
|
+
isSystemInjectedMessage,
|
|
4
|
+
projectSessionMarkers
|
|
5
|
+
} from "./chunk-ULMAQV3T.js";
|
|
6
|
+
|
|
7
|
+
// src/types/session-timeline.ts
|
|
8
|
+
function projectSessionToolMeta(events) {
|
|
9
|
+
const out = [];
|
|
10
|
+
for (const event of events) {
|
|
11
|
+
if (event.type !== "tool_call_end") continue;
|
|
12
|
+
out.push({
|
|
13
|
+
id: event.id,
|
|
14
|
+
name: event.name,
|
|
15
|
+
durationMs: event.durationMs,
|
|
16
|
+
// `outputSize` is the legacy name for the same number; prefer the modern
|
|
17
|
+
// field but fall back so old journals keep their tool card stats.
|
|
18
|
+
outputBytes: event.outputBytes ?? event.outputSize,
|
|
19
|
+
outputTokens: event.outputTokens,
|
|
20
|
+
outputLines: event.outputLines,
|
|
21
|
+
ok: event.ok,
|
|
22
|
+
agentId: event.agentId
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
return out;
|
|
26
|
+
}
|
|
27
|
+
function projectLastRequestTokens(events) {
|
|
28
|
+
if (!events) return void 0;
|
|
29
|
+
for (let i = events.length - 1; i >= 0; i -= 1) {
|
|
30
|
+
const event = events[i];
|
|
31
|
+
if (event?.type !== "llm_response") continue;
|
|
32
|
+
const usage = event.usage;
|
|
33
|
+
const total = usage.input + (usage.cacheRead ?? 0) + (usage.cacheWrite ?? 0);
|
|
34
|
+
return total > 0 ? total : void 0;
|
|
35
|
+
}
|
|
36
|
+
return void 0;
|
|
37
|
+
}
|
|
38
|
+
function toolMetaIndex(meta) {
|
|
39
|
+
const index = /* @__PURE__ */ new Map();
|
|
40
|
+
if (!meta) return index;
|
|
41
|
+
for (const entry of meta) index.set(entry.id, entry);
|
|
42
|
+
return index;
|
|
43
|
+
}
|
|
44
|
+
function imagesOf(blocks) {
|
|
45
|
+
const images = [];
|
|
46
|
+
for (const block of blocks) {
|
|
47
|
+
if (block.type !== "image") continue;
|
|
48
|
+
images.push({
|
|
49
|
+
mediaType: block.source.media_type,
|
|
50
|
+
data: block.source.data,
|
|
51
|
+
url: block.source.url
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
return images.length > 0 ? images : void 0;
|
|
55
|
+
}
|
|
56
|
+
function resultText(content) {
|
|
57
|
+
return typeof content === "string" ? content : JSON.stringify(content);
|
|
58
|
+
}
|
|
59
|
+
function projectSessionTimeline(input) {
|
|
60
|
+
const {
|
|
61
|
+
messages,
|
|
62
|
+
events,
|
|
63
|
+
thinkingPlacement = "inline",
|
|
64
|
+
textBlocks = "split",
|
|
65
|
+
textSeparator = "",
|
|
66
|
+
hideSystemInjections = true
|
|
67
|
+
} = input;
|
|
68
|
+
const markers = input.markers ?? (events ? projectSessionMarkers(events, input.markerSources ?? SESSION_MARKER_EVENT_TYPES) : []);
|
|
69
|
+
const meta = toolMetaIndex(input.toolMeta ?? (events ? projectSessionToolMeta(events) : void 0));
|
|
70
|
+
const backbone = [];
|
|
71
|
+
const toolEntries = /* @__PURE__ */ new Map();
|
|
72
|
+
let thinkingIndex = 0;
|
|
73
|
+
let lastTs = "";
|
|
74
|
+
const pushText = (role, raw, ts, final) => {
|
|
75
|
+
const text = raw.trim();
|
|
76
|
+
if (!text) return;
|
|
77
|
+
if (hideSystemInjections && isSystemInjectedMessage(text)) return;
|
|
78
|
+
if (role === "assistant") backbone.push({ kind: "assistant", ts, text, final });
|
|
79
|
+
else if (role === "system") backbone.push({ kind: "system", ts, text });
|
|
80
|
+
else backbone.push({ kind: "user", ts, text });
|
|
81
|
+
};
|
|
82
|
+
const pushThinking = (text, ts) => {
|
|
83
|
+
if (!text.trim()) return;
|
|
84
|
+
thinkingIndex += 1;
|
|
85
|
+
backbone.push({ kind: "thinking", ts, text, index: thinkingIndex });
|
|
86
|
+
};
|
|
87
|
+
for (const message of messages) {
|
|
88
|
+
const ts = message.ts ?? lastTs;
|
|
89
|
+
if (message.ts) lastTs = message.ts;
|
|
90
|
+
if (typeof message.content === "string") {
|
|
91
|
+
pushText(message.role, message.content, ts, true);
|
|
92
|
+
continue;
|
|
93
|
+
}
|
|
94
|
+
const blocks = message.content;
|
|
95
|
+
if (thinkingPlacement === "inline") {
|
|
96
|
+
for (const block of blocks) {
|
|
97
|
+
if (block.type === "thinking") pushThinking(block.thinking, ts);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
const images = message.role === "user" ? imagesOf(blocks) : void 0;
|
|
101
|
+
const final = !blocks.some((block) => block.type === "tool_use");
|
|
102
|
+
const textParts = [];
|
|
103
|
+
const flushText = () => {
|
|
104
|
+
if (textBlocks === "join") return;
|
|
105
|
+
const text = textParts.join(textSeparator).trim();
|
|
106
|
+
if (text) pushText(message.role, text, ts, final);
|
|
107
|
+
textParts.length = 0;
|
|
108
|
+
};
|
|
109
|
+
if (textBlocks === "join") {
|
|
110
|
+
const joined = blocks.filter((block) => block.type === "text").map((block) => block.text).join(textSeparator).trim();
|
|
111
|
+
if (joined) pushText(message.role, joined, ts, final);
|
|
112
|
+
}
|
|
113
|
+
for (const block of blocks) {
|
|
114
|
+
if (block.type === "text") {
|
|
115
|
+
textParts.push(block.text);
|
|
116
|
+
continue;
|
|
117
|
+
}
|
|
118
|
+
if (block.type === "tool_use") {
|
|
119
|
+
flushText();
|
|
120
|
+
const known2 = meta.get(block.id);
|
|
121
|
+
const entry = {
|
|
122
|
+
kind: "tool",
|
|
123
|
+
ts,
|
|
124
|
+
toolUseId: block.id,
|
|
125
|
+
name: block.name,
|
|
126
|
+
input: block.input,
|
|
127
|
+
// Left undefined until a tool_result arrives: an unfinished call is
|
|
128
|
+
// not a failed one.
|
|
129
|
+
ok: known2?.ok,
|
|
130
|
+
durationMs: known2?.durationMs,
|
|
131
|
+
outputBytes: known2?.outputBytes,
|
|
132
|
+
outputTokens: known2?.outputTokens,
|
|
133
|
+
outputLines: known2?.outputLines,
|
|
134
|
+
agentId: known2?.agentId
|
|
135
|
+
};
|
|
136
|
+
backbone.push(entry);
|
|
137
|
+
toolEntries.set(block.id, entry);
|
|
138
|
+
continue;
|
|
139
|
+
}
|
|
140
|
+
if (block.type !== "tool_result") continue;
|
|
141
|
+
flushText();
|
|
142
|
+
const existing = toolEntries.get(block.tool_use_id);
|
|
143
|
+
if (existing) {
|
|
144
|
+
existing.output = resultText(block.content);
|
|
145
|
+
existing.ok = !block.is_error;
|
|
146
|
+
toolEntries.delete(block.tool_use_id);
|
|
147
|
+
continue;
|
|
148
|
+
}
|
|
149
|
+
const known = meta.get(block.tool_use_id);
|
|
150
|
+
backbone.push({
|
|
151
|
+
kind: "tool",
|
|
152
|
+
ts,
|
|
153
|
+
toolUseId: block.tool_use_id,
|
|
154
|
+
name: block.name ?? known?.name ?? block.tool_use_id,
|
|
155
|
+
output: resultText(block.content),
|
|
156
|
+
ok: !block.is_error,
|
|
157
|
+
durationMs: known?.durationMs,
|
|
158
|
+
outputBytes: known?.outputBytes,
|
|
159
|
+
outputTokens: known?.outputTokens,
|
|
160
|
+
outputLines: known?.outputLines,
|
|
161
|
+
agentId: known?.agentId
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
flushText();
|
|
165
|
+
if (thinkingPlacement === "merged-after") {
|
|
166
|
+
const joined = blocks.filter(
|
|
167
|
+
(block) => block.type === "thinking"
|
|
168
|
+
).map((block) => block.thinking).join("\n\n");
|
|
169
|
+
pushThinking(joined.trim(), ts);
|
|
170
|
+
}
|
|
171
|
+
if (images) {
|
|
172
|
+
const last = backbone[backbone.length - 1];
|
|
173
|
+
if (last?.kind === "user" && last.ts === ts) last.images = images;
|
|
174
|
+
else backbone.push({ kind: "user", ts, text: "", images });
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
const out = [];
|
|
178
|
+
let i = 0;
|
|
179
|
+
let j = 0;
|
|
180
|
+
while (i < backbone.length && j < markers.length) {
|
|
181
|
+
const marker = markers[j];
|
|
182
|
+
if (marker.ts < backbone[i].ts) {
|
|
183
|
+
out.push(markerEntry(marker));
|
|
184
|
+
j += 1;
|
|
185
|
+
} else {
|
|
186
|
+
out.push(backbone[i]);
|
|
187
|
+
i += 1;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
while (i < backbone.length) out.push(backbone[i++]);
|
|
191
|
+
while (j < markers.length) out.push(markerEntry(markers[j++]));
|
|
192
|
+
return out;
|
|
193
|
+
}
|
|
194
|
+
function markerEntry(marker) {
|
|
195
|
+
return {
|
|
196
|
+
kind: "marker",
|
|
197
|
+
ts: marker.ts,
|
|
198
|
+
source: marker.source,
|
|
199
|
+
level: marker.level,
|
|
200
|
+
text: marker.text,
|
|
201
|
+
agentId: marker.agentId,
|
|
202
|
+
detail: marker.detail
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
export {
|
|
207
|
+
projectSessionToolMeta,
|
|
208
|
+
projectLastRequestTokens,
|
|
209
|
+
projectSessionTimeline
|
|
210
|
+
};
|
|
211
|
+
//# sourceMappingURL=chunk-3BDV7RL3.js.map
|
|
@@ -0,0 +1,325 @@
|
|
|
1
|
+
import {
|
|
2
|
+
truncate
|
|
3
|
+
} from "./chunk-B4AMLZPB.js";
|
|
4
|
+
import {
|
|
5
|
+
ERROR_CODES,
|
|
6
|
+
WrongStackError
|
|
7
|
+
} from "./chunk-25LSLC3G.js";
|
|
8
|
+
|
|
9
|
+
// src/types/quota-regex.ts
|
|
10
|
+
var QUOTA_EXHAUSTED_RE = /(?:insufficient|exhausted|depleted|exceeded|no|not enough)[-_\s]*(?:quota|credit|balance)|(?:quota|credit|balance)(?:\s+(?:has|have))?(?:\s+been)?[-_\s]*(?:exhausted|depleted|exceeded|insufficient)|billing[_\s-]*(?:hard[_\s-]*)?limit|payment required|spending limit|plan limit|(?:usage|credit)[-_\s]*(?:quota|limit)(?![-_\w])|usage[-_\s]*(?:limit|quota)[-_\s]*(?:reached|exceeded|for)/i;
|
|
11
|
+
var ROUTE_SCOPED_QUOTA_RE = /\b(?:for|on)\s+(?:(?:this|the)\s+)?(?:route|model)\b|\b(?:route|model)(?:[-_\s]+[\w.-]+)?[-_\s]*(?:quota|limit)\b|\b(?:quota|limit).{0,24}\b(?:for|on)\s+(?:(?:this|the)\s+)?(?:route|model)\b/i;
|
|
12
|
+
|
|
13
|
+
// src/types/provider.ts
|
|
14
|
+
var REASONING_EFFORT_LEVELS = [
|
|
15
|
+
"none",
|
|
16
|
+
"minimal",
|
|
17
|
+
"low",
|
|
18
|
+
"medium",
|
|
19
|
+
"high",
|
|
20
|
+
"xhigh",
|
|
21
|
+
"max"
|
|
22
|
+
];
|
|
23
|
+
function isReasoningEffort(value) {
|
|
24
|
+
return typeof value === "string" && REASONING_EFFORT_LEVELS.includes(value);
|
|
25
|
+
}
|
|
26
|
+
function effectiveInputTokens(usage) {
|
|
27
|
+
return usage.input + (usage.cacheRead ?? 0) + (usage.cacheWrite ?? 0);
|
|
28
|
+
}
|
|
29
|
+
function freshInputTokens(usage) {
|
|
30
|
+
return Math.max(0, effectiveInputTokens(usage) - (usage.cacheRead ?? 0));
|
|
31
|
+
}
|
|
32
|
+
function totalUsageTokens(usage) {
|
|
33
|
+
return effectiveInputTokens(usage) + usage.output;
|
|
34
|
+
}
|
|
35
|
+
function promptCacheHitRatio(usage) {
|
|
36
|
+
const total = effectiveInputTokens(usage);
|
|
37
|
+
if (!Number.isFinite(total) || total <= 0) return 0;
|
|
38
|
+
const cached = Number.isFinite(usage.cacheRead) ? Math.max(0, usage.cacheRead ?? 0) : 0;
|
|
39
|
+
return Math.min(1, cached / total);
|
|
40
|
+
}
|
|
41
|
+
var CONTEXT_OVERFLOW_RE = /context.length|context.window|maximum context|max.*tokens?.*exceeded|(?:prompt|request|input|messages?).{0,12}too (?:large|long)|exceeds the context|\btokens\b.*exceed|too many tokens|reduce the length|resulted in \d+ tokens|context_length_exceeded/i;
|
|
42
|
+
var CONTENT_FILTER_RE = /content.(filter|policy|moderation)|safety (system|filter)/i;
|
|
43
|
+
function classifyProviderError(status, body, message) {
|
|
44
|
+
const type = body?.type;
|
|
45
|
+
const messageText = [message, body?.message, type].filter(Boolean).join("\n");
|
|
46
|
+
const text = [messageText, body?.raw].filter(Boolean).join("\n");
|
|
47
|
+
if (status === 0) return "network";
|
|
48
|
+
if (status === 408) return "timeout";
|
|
49
|
+
if (status === 599) return "stream_hang";
|
|
50
|
+
if (QUOTA_EXHAUSTED_RE.test(messageText)) return "quota_exhausted";
|
|
51
|
+
if (status === 402) return "quota_exhausted";
|
|
52
|
+
if (type === "rate_limit_error" || status === 429) return "rate_limit";
|
|
53
|
+
if (type === "overloaded_error" || status === 529) return "overloaded";
|
|
54
|
+
if (status >= 500) return "server";
|
|
55
|
+
if (type === "authentication_error" || type === "permission_error" || status === 401 || status === 403) {
|
|
56
|
+
return "auth";
|
|
57
|
+
}
|
|
58
|
+
if (type === "content_filter" || CONTENT_FILTER_RE.test(text)) return "content_filter";
|
|
59
|
+
if (status === 413 || status >= 400 && CONTEXT_OVERFLOW_RE.test(text)) {
|
|
60
|
+
return "context_overflow";
|
|
61
|
+
}
|
|
62
|
+
if (status >= 400) return "invalid_request";
|
|
63
|
+
return "unknown";
|
|
64
|
+
}
|
|
65
|
+
var MAX_RESET_HINT_MS = 7 * 24 * 60 * 60 * 1e3;
|
|
66
|
+
var RESET_HINT_LEAD_RE = /(?:try again|retry|resets?|resetting|available|returns?|back online|usable again)\s+(?:in|after)\s+/i;
|
|
67
|
+
var RESET_AT_LEAD_RE = /resets?\s+(?:at|on)\s+/i;
|
|
68
|
+
var DURATION_TOKEN_RE = /(\d+(?:\.\d+)?)\s*(ms|secs?|seconds?|s|mins?|minutes?|m|hrs?|hours?|h|days?|d)(?![a-z])/gi;
|
|
69
|
+
var UNIT_MS = {
|
|
70
|
+
ms: 1,
|
|
71
|
+
s: 1e3,
|
|
72
|
+
m: 6e4,
|
|
73
|
+
h: 36e5,
|
|
74
|
+
d: 864e5
|
|
75
|
+
};
|
|
76
|
+
function unitMs(unit) {
|
|
77
|
+
const u = unit.toLowerCase();
|
|
78
|
+
if (u === "ms") return 1;
|
|
79
|
+
if (u.startsWith("s")) return UNIT_MS["s"];
|
|
80
|
+
if (u.startsWith("m")) return UNIT_MS["m"];
|
|
81
|
+
if (u.startsWith("h")) return UNIT_MS["h"];
|
|
82
|
+
return UNIT_MS["d"];
|
|
83
|
+
}
|
|
84
|
+
var ISO_TIMESTAMP_RE = /(\d{4}-\d{2}-\d{2}(?:[T ]\d{2}:\d{2}(?::\d{2}(?:\.\d+)?)?(?:\s*(?:Z|[+-]\d{2}:?\d{2}|UTC|GMT))?)?)/i;
|
|
85
|
+
function parseResetHintMs(message, now = Date.now()) {
|
|
86
|
+
if (!message) return void 0;
|
|
87
|
+
const lead = RESET_HINT_LEAD_RE.exec(message);
|
|
88
|
+
if (lead) {
|
|
89
|
+
const window = message.slice(lead.index + lead[0].length, lead.index + lead[0].length + 80);
|
|
90
|
+
let total = 0;
|
|
91
|
+
let matched = false;
|
|
92
|
+
DURATION_TOKEN_RE.lastIndex = 0;
|
|
93
|
+
for (let m = DURATION_TOKEN_RE.exec(window); m; m = DURATION_TOKEN_RE.exec(window)) {
|
|
94
|
+
const value = Number.parseFloat(m[1]);
|
|
95
|
+
if (Number.isFinite(value) && value > 0) {
|
|
96
|
+
total += value * unitMs(m[2]);
|
|
97
|
+
matched = true;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
if (!matched) {
|
|
101
|
+
const bare = /^(?:an?\s+)?(second|minute|hour|day)\b/i.exec(window.trim());
|
|
102
|
+
if (bare) {
|
|
103
|
+
total = unitMs(bare[1]);
|
|
104
|
+
matched = true;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
if (matched && total > 0) {
|
|
108
|
+
return Math.min(total, MAX_RESET_HINT_MS);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
const atLead = RESET_AT_LEAD_RE.exec(message);
|
|
112
|
+
if (atLead) {
|
|
113
|
+
const window = message.slice(atLead.index + atLead[0].length);
|
|
114
|
+
const iso = ISO_TIMESTAMP_RE.exec(window);
|
|
115
|
+
if (iso) {
|
|
116
|
+
const normalized = iso[1].replace(/^(\d{4}-\d{2}-\d{2}) (\d{2}:\d{2})/, "$1T$2").replace(/\s*(UTC|GMT)$/i, "Z");
|
|
117
|
+
const ts = Date.parse(normalized);
|
|
118
|
+
if (Number.isFinite(ts) && ts > now) {
|
|
119
|
+
return Math.min(ts - now, MAX_RESET_HINT_MS);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
return void 0;
|
|
124
|
+
}
|
|
125
|
+
function isRetryableKind(kind) {
|
|
126
|
+
return RETRYABLE_BY_KIND[kind];
|
|
127
|
+
}
|
|
128
|
+
var RETRYABLE_BY_KIND = {
|
|
129
|
+
rate_limit: true,
|
|
130
|
+
quota_exhausted: false,
|
|
131
|
+
overloaded: true,
|
|
132
|
+
server: true,
|
|
133
|
+
timeout: true,
|
|
134
|
+
network: true,
|
|
135
|
+
stream_hang: true,
|
|
136
|
+
auth: false,
|
|
137
|
+
context_overflow: false,
|
|
138
|
+
content_filter: false,
|
|
139
|
+
invalid_request: false,
|
|
140
|
+
unknown: false
|
|
141
|
+
};
|
|
142
|
+
function isFallbackWorthy(kind) {
|
|
143
|
+
return FALLBACK_WORTHY_BY_KIND[kind];
|
|
144
|
+
}
|
|
145
|
+
var FALLBACK_WORTHY_BY_KIND = {
|
|
146
|
+
rate_limit: true,
|
|
147
|
+
quota_exhausted: true,
|
|
148
|
+
overloaded: true,
|
|
149
|
+
server: true,
|
|
150
|
+
timeout: true,
|
|
151
|
+
network: true,
|
|
152
|
+
stream_hang: true,
|
|
153
|
+
auth: false,
|
|
154
|
+
context_overflow: false,
|
|
155
|
+
content_filter: false,
|
|
156
|
+
invalid_request: false,
|
|
157
|
+
unknown: false
|
|
158
|
+
};
|
|
159
|
+
var ProviderError = class extends WrongStackError {
|
|
160
|
+
status;
|
|
161
|
+
retryable;
|
|
162
|
+
providerId;
|
|
163
|
+
/** Canonical failure classification — see {@link ProviderErrorKind}. */
|
|
164
|
+
kind;
|
|
165
|
+
body;
|
|
166
|
+
/**
|
|
167
|
+
* Duck-type guard: checks whether an unknown value *looks like* a
|
|
168
|
+
* ProviderError by probing for its structural properties. Use this
|
|
169
|
+
* anywhere the constructor identity might cross a package boundary
|
|
170
|
+
* (e.g. `@wrongstack/providers` creates the error, but the runner in
|
|
171
|
+
* `@wrongstack/core` checks it). A plain `instanceof ProviderError`
|
|
172
|
+
* can fail when npm hoists duplicate copies of `@wrongstack/core`,
|
|
173
|
+
* each with its own class identity.
|
|
174
|
+
*
|
|
175
|
+
* The check tests for the four invariant properties defined in the
|
|
176
|
+
* constructor: `name === 'ProviderError'`, `status` (number),
|
|
177
|
+
* `retryable` (boolean), and `kind` (string). This tolerates both
|
|
178
|
+
* true `ProviderError` instances and cross-boundary copies.
|
|
179
|
+
*/
|
|
180
|
+
static isProviderError(err) {
|
|
181
|
+
if (!err || typeof err !== "object") return false;
|
|
182
|
+
const e = err;
|
|
183
|
+
const name = e.name;
|
|
184
|
+
if (typeof name !== "string" || !name.endsWith("Error")) return false;
|
|
185
|
+
return typeof e.status === "number" && typeof e.retryable === "boolean" && typeof e.kind === "string" && typeof e.describe === "function";
|
|
186
|
+
}
|
|
187
|
+
constructor(message, status, retryable, providerId, opts = {}) {
|
|
188
|
+
const kind = opts.kind ?? classifyProviderError(status, opts.body, message);
|
|
189
|
+
super({
|
|
190
|
+
message,
|
|
191
|
+
code: kindToCode(kind),
|
|
192
|
+
subsystem: "provider",
|
|
193
|
+
severity: status >= 500 ? "error" : "warning",
|
|
194
|
+
recoverable: retryable,
|
|
195
|
+
context: { providerId, status },
|
|
196
|
+
cause: opts.cause
|
|
197
|
+
});
|
|
198
|
+
this.name = "ProviderError";
|
|
199
|
+
this.status = status;
|
|
200
|
+
this.retryable = retryable;
|
|
201
|
+
this.providerId = providerId;
|
|
202
|
+
this.kind = kind;
|
|
203
|
+
this.body = opts.body;
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Render a one-line, user-facing description. Designed for the CLI/TUI
|
|
207
|
+
* status line and the agent's retry warning. Avoids dumping raw JSON
|
|
208
|
+
* (which is what users see today when a 529 lands and the log message
|
|
209
|
+
* includes the full `{"type":"error",...}` body).
|
|
210
|
+
*
|
|
211
|
+
* Examples:
|
|
212
|
+
* "minimax-coding-plan overloaded (529): High traffic detected. Upgrade for highspeed model. [req 06534785201de9c0…]"
|
|
213
|
+
* "openai rate limited (429): Retry after 12s"
|
|
214
|
+
* "anthropic invalid request (400): messages.0.role must be one of 'user'|'assistant'"
|
|
215
|
+
* "groq HTTP 500 (server error)"
|
|
216
|
+
*/
|
|
217
|
+
describe() {
|
|
218
|
+
const kind = describeStatus(this.status, this.body?.type);
|
|
219
|
+
const head = `${this.providerId} ${kind}`;
|
|
220
|
+
const detail = this.body?.message?.trim();
|
|
221
|
+
const reqId = this.body?.requestId ? ` [req ${this.body.requestId.slice(0, 16)}${this.body.requestId.length > 16 ? "\u2026" : ""}]` : "";
|
|
222
|
+
if (detail && detail.length > 0) {
|
|
223
|
+
return `${head}: ${truncate(detail, 240)}${reqId}`;
|
|
224
|
+
}
|
|
225
|
+
return `${head}${reqId}`;
|
|
226
|
+
}
|
|
227
|
+
};
|
|
228
|
+
function isContextOverflowShaped(err) {
|
|
229
|
+
if (!(err instanceof ProviderError) && !ProviderError.isProviderError(err)) return false;
|
|
230
|
+
const providerErr = err;
|
|
231
|
+
if (providerErr.kind === "context_overflow" || providerErr.status === 413) return true;
|
|
232
|
+
if (providerErr.status < 400) return false;
|
|
233
|
+
const text = [
|
|
234
|
+
providerErr.message,
|
|
235
|
+
providerErr.body?.message,
|
|
236
|
+
providerErr.body?.type,
|
|
237
|
+
providerErr.body?.raw
|
|
238
|
+
].filter(Boolean).join("\n");
|
|
239
|
+
return CONTEXT_OVERFLOW_RE.test(text);
|
|
240
|
+
}
|
|
241
|
+
function describeStatus(status, type) {
|
|
242
|
+
if (status === 0) return "network error";
|
|
243
|
+
if (status === 599) return `stream hang (${status})`;
|
|
244
|
+
if (type === "overloaded_error" || status === 529) return `overloaded (${status})`;
|
|
245
|
+
if (type === "rate_limit_error" || status === 429) return `rate limited (${status})`;
|
|
246
|
+
if (type === "authentication_error" || status === 401) return `auth failed (${status})`;
|
|
247
|
+
if (type === "permission_error" || status === 403) return `forbidden (${status})`;
|
|
248
|
+
if (type === "not_found_error" || status === 404) return `not found (${status})`;
|
|
249
|
+
if (type === "content_filter") return `content filtered (${status})`;
|
|
250
|
+
if (type === "invalid_request_error" || status === 400) return `invalid request (${status})`;
|
|
251
|
+
if (status === 408) return `timeout (${status})`;
|
|
252
|
+
if (status >= 500 && status < 600) return `HTTP ${status} (server error)`;
|
|
253
|
+
if (type) return `${type} (${status})`;
|
|
254
|
+
return `HTTP ${status}`;
|
|
255
|
+
}
|
|
256
|
+
var StreamHangError = class extends ProviderError {
|
|
257
|
+
/** Name of the provider that hung, e.g. "zai", "anthropic". */
|
|
258
|
+
hungProviderId;
|
|
259
|
+
/** Model that was being called when the hang occurred. */
|
|
260
|
+
hungModel;
|
|
261
|
+
/** How long (ms) we waited for the next chunk before declaring a hang. */
|
|
262
|
+
hangTimeoutMs;
|
|
263
|
+
/** How many bytes were received before the hang. */
|
|
264
|
+
bytesReceived;
|
|
265
|
+
/** Elapsed time (ms) from the start of the stream until the hang. */
|
|
266
|
+
elapsedMs;
|
|
267
|
+
constructor(opts) {
|
|
268
|
+
super(
|
|
269
|
+
`Stream hang: ${opts.providerId}/${opts.model} \u2014 no data for ${opts.hangTimeoutMs}ms after ${opts.bytesReceived} bytes (${opts.elapsedMs}ms elapsed)`,
|
|
270
|
+
599,
|
|
271
|
+
true,
|
|
272
|
+
// always retryable
|
|
273
|
+
opts.providerId,
|
|
274
|
+
{
|
|
275
|
+
body: {
|
|
276
|
+
message: `Stream stalled after ${opts.elapsedMs}ms, ${opts.bytesReceived} bytes received`
|
|
277
|
+
},
|
|
278
|
+
cause: opts.cause
|
|
279
|
+
}
|
|
280
|
+
);
|
|
281
|
+
this.name = "StreamHangError";
|
|
282
|
+
this.hungProviderId = opts.providerId;
|
|
283
|
+
this.hungModel = opts.model;
|
|
284
|
+
this.hangTimeoutMs = opts.hangTimeoutMs;
|
|
285
|
+
this.bytesReceived = opts.bytesReceived;
|
|
286
|
+
this.elapsedMs = opts.elapsedMs;
|
|
287
|
+
}
|
|
288
|
+
};
|
|
289
|
+
var KIND_TO_CODE = {
|
|
290
|
+
network: ERROR_CODES.PROVIDER_NETWORK_ERROR,
|
|
291
|
+
timeout: ERROR_CODES.PROVIDER_NETWORK_ERROR,
|
|
292
|
+
rate_limit: ERROR_CODES.PROVIDER_RATE_LIMITED,
|
|
293
|
+
quota_exhausted: ERROR_CODES.PROVIDER_RATE_LIMITED,
|
|
294
|
+
auth: ERROR_CODES.PROVIDER_AUTH_FAILED,
|
|
295
|
+
overloaded: ERROR_CODES.PROVIDER_OVERLOADED,
|
|
296
|
+
context_overflow: ERROR_CODES.PROVIDER_CONTEXT_OVERFLOW,
|
|
297
|
+
server: ERROR_CODES.PROVIDER_SERVER_ERROR,
|
|
298
|
+
stream_hang: ERROR_CODES.PROVIDER_SERVER_ERROR,
|
|
299
|
+
content_filter: ERROR_CODES.PROVIDER_INVALID_REQUEST,
|
|
300
|
+
invalid_request: ERROR_CODES.PROVIDER_INVALID_REQUEST,
|
|
301
|
+
unknown: ERROR_CODES.PROVIDER_INVALID_REQUEST
|
|
302
|
+
};
|
|
303
|
+
function kindToCode(kind) {
|
|
304
|
+
return KIND_TO_CODE[kind];
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
export {
|
|
308
|
+
QUOTA_EXHAUSTED_RE,
|
|
309
|
+
ROUTE_SCOPED_QUOTA_RE,
|
|
310
|
+
REASONING_EFFORT_LEVELS,
|
|
311
|
+
isReasoningEffort,
|
|
312
|
+
effectiveInputTokens,
|
|
313
|
+
freshInputTokens,
|
|
314
|
+
totalUsageTokens,
|
|
315
|
+
promptCacheHitRatio,
|
|
316
|
+
classifyProviderError,
|
|
317
|
+
MAX_RESET_HINT_MS,
|
|
318
|
+
parseResetHintMs,
|
|
319
|
+
isRetryableKind,
|
|
320
|
+
isFallbackWorthy,
|
|
321
|
+
ProviderError,
|
|
322
|
+
isContextOverflowShaped,
|
|
323
|
+
StreamHangError
|
|
324
|
+
};
|
|
325
|
+
//# sourceMappingURL=chunk-3ECENVHL.js.map
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
// src/plugin/config.ts
|
|
2
|
+
function resolvePluginConfig(input) {
|
|
3
|
+
const names = [.../* @__PURE__ */ new Set([...input.aliases ?? [], input.name])];
|
|
4
|
+
const options = { ...input.defaults ?? {} };
|
|
5
|
+
const sources = [];
|
|
6
|
+
let configured = false;
|
|
7
|
+
const merge = (value, source) => {
|
|
8
|
+
if (!isRecord(value)) return;
|
|
9
|
+
Object.assign(options, value);
|
|
10
|
+
configured = true;
|
|
11
|
+
if (!sources.includes(source)) sources.push(source);
|
|
12
|
+
};
|
|
13
|
+
const plugins = input.config?.plugins;
|
|
14
|
+
if (isRecord(plugins)) {
|
|
15
|
+
for (const name of names) merge(plugins[name], "legacy-plugin-map");
|
|
16
|
+
} else if (Array.isArray(plugins)) {
|
|
17
|
+
for (const candidate of plugins) {
|
|
18
|
+
if (!isPluginEntry(candidate) || !names.includes(candidate.name)) continue;
|
|
19
|
+
merge(candidate.options, "plugin-entry");
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
const extensions = input.config?.extensions;
|
|
23
|
+
for (const name of names) merge(extensions?.[name], "extension");
|
|
24
|
+
merge(input.explicitOptions, "explicit-options");
|
|
25
|
+
return { options, configured, sources };
|
|
26
|
+
}
|
|
27
|
+
function pluginEntryMatchesName(configuredName, name, aliases = []) {
|
|
28
|
+
for (const candidate of [name, ...aliases]) {
|
|
29
|
+
if (configuredName === candidate) return true;
|
|
30
|
+
if (configuredName === `@wrongstack/plugins/${candidate}`) return true;
|
|
31
|
+
}
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
function resolvePluginEnablement(input) {
|
|
35
|
+
if (input.config?.features?.plugins === false) {
|
|
36
|
+
return { enabled: false, source: "feature-flag" };
|
|
37
|
+
}
|
|
38
|
+
const names = [.../* @__PURE__ */ new Set([input.name, ...input.aliases ?? []])];
|
|
39
|
+
const matches = input.matches ?? ((configuredName) => pluginEntryMatchesName(configuredName, input.name, input.aliases ?? []));
|
|
40
|
+
const plugins = input.config?.plugins;
|
|
41
|
+
if (Array.isArray(plugins)) {
|
|
42
|
+
for (const candidate of plugins) {
|
|
43
|
+
if (typeof candidate === "string") {
|
|
44
|
+
if (matches(candidate)) return { enabled: true, source: "plugin-entry" };
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
if (!isPluginEntry(candidate) || !matches(candidate.name)) continue;
|
|
48
|
+
return { enabled: candidate.enabled !== false, source: "plugin-entry" };
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
for (const name of names) {
|
|
52
|
+
const enabled = input.config?.extensions?.[name]?.["enabled"];
|
|
53
|
+
if (typeof enabled === "boolean") return { enabled, source: "extension" };
|
|
54
|
+
}
|
|
55
|
+
return { enabled: input.defaultState === "active", source: "default" };
|
|
56
|
+
}
|
|
57
|
+
function resolvePluginManifestConfig(plugin, config, explicitOptions) {
|
|
58
|
+
return resolvePluginConfig({
|
|
59
|
+
name: plugin.name,
|
|
60
|
+
aliases: plugin.configAliases,
|
|
61
|
+
defaults: plugin.defaultConfig,
|
|
62
|
+
config,
|
|
63
|
+
explicitOptions
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
function diffPluginConfig(previous, next, fields) {
|
|
67
|
+
const keys = /* @__PURE__ */ new Set([...Object.keys(previous), ...Object.keys(next)]);
|
|
68
|
+
const changes = [];
|
|
69
|
+
for (const key of keys) {
|
|
70
|
+
if (valuesEqual(previous[key], next[key])) continue;
|
|
71
|
+
const metadata = fields[key];
|
|
72
|
+
changes.push({
|
|
73
|
+
key,
|
|
74
|
+
lifecycle: metadata?.lifecycle ?? "immutable",
|
|
75
|
+
secret: metadata?.secret === true,
|
|
76
|
+
previous: metadata?.secret === true ? "[REDACTED]" : previous[key],
|
|
77
|
+
next: metadata?.secret === true ? "[REDACTED]" : next[key]
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
return changes;
|
|
81
|
+
}
|
|
82
|
+
function redactPluginConfig(options, fields) {
|
|
83
|
+
const redacted = { ...options };
|
|
84
|
+
for (const [key, metadata] of Object.entries(fields)) {
|
|
85
|
+
if (metadata.secret === true && key in redacted) redacted[key] = "[REDACTED]";
|
|
86
|
+
}
|
|
87
|
+
return redacted;
|
|
88
|
+
}
|
|
89
|
+
function validatePluginConfigMetadata(plugin) {
|
|
90
|
+
if (!plugin.configFields) return [];
|
|
91
|
+
const declared = plugin.configFields;
|
|
92
|
+
const expected = /* @__PURE__ */ new Set([
|
|
93
|
+
...Object.keys(plugin.configSchema?.properties ?? {}),
|
|
94
|
+
...Object.keys(plugin.defaultConfig ?? {})
|
|
95
|
+
]);
|
|
96
|
+
const issues = [];
|
|
97
|
+
for (const key of expected) {
|
|
98
|
+
if (!declared[key]) issues.push(`missing configFields metadata for "${key}"`);
|
|
99
|
+
}
|
|
100
|
+
for (const [key, metadata] of Object.entries(declared)) {
|
|
101
|
+
if (!["hot", "restart", "immutable"].includes(metadata.lifecycle)) {
|
|
102
|
+
issues.push(`invalid lifecycle for configFields."${key}"`);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
return issues;
|
|
106
|
+
}
|
|
107
|
+
function isPluginEntry(value) {
|
|
108
|
+
return isRecord(value) && typeof value["name"] === "string";
|
|
109
|
+
}
|
|
110
|
+
function isRecord(value) {
|
|
111
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
112
|
+
}
|
|
113
|
+
function valuesEqual(left, right) {
|
|
114
|
+
if (Object.is(left, right)) return true;
|
|
115
|
+
if (Array.isArray(left) && Array.isArray(right)) {
|
|
116
|
+
return left.length === right.length && left.every((value, index) => valuesEqual(value, right[index]));
|
|
117
|
+
}
|
|
118
|
+
if (isRecord(left) && isRecord(right)) {
|
|
119
|
+
const leftKeys = Object.keys(left);
|
|
120
|
+
const rightKeys = Object.keys(right);
|
|
121
|
+
return leftKeys.length === rightKeys.length && leftKeys.every((key) => key in right && valuesEqual(left[key], right[key]));
|
|
122
|
+
}
|
|
123
|
+
return false;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export {
|
|
127
|
+
resolvePluginConfig,
|
|
128
|
+
pluginEntryMatchesName,
|
|
129
|
+
resolvePluginEnablement,
|
|
130
|
+
resolvePluginManifestConfig,
|
|
131
|
+
diffPluginConfig,
|
|
132
|
+
redactPluginConfig,
|
|
133
|
+
validatePluginConfigMetadata
|
|
134
|
+
};
|
|
135
|
+
//# sourceMappingURL=chunk-3XPVB7BA.js.map
|