@pentoshi/clai 4.18.0 → 4.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CONTRIBUTING.md +3 -2
- package/PROVIDERS.md +1 -1
- package/README.md +108 -267
- package/SECURITY.md +5 -1
- package/dist/agent/compaction-summary.d.ts +1 -1
- package/dist/agent/compaction-summary.js +4 -4
- package/dist/agent/compaction-summary.js.map +1 -1
- package/dist/agent/context/compaction-user-instructions.js +1 -1
- package/dist/agent/context/compaction-user-instructions.js.map +1 -1
- package/dist/agent/durable-envelope.js +1 -1
- package/dist/agent/durable-envelope.js.map +1 -1
- package/dist/agent/turn/tool-execution/result-framing.js +8 -6
- package/dist/agent/turn/tool-execution/result-framing.js.map +1 -1
- package/dist/app/adapters/current-store-adapter.js +7 -3
- package/dist/app/adapters/current-store-adapter.js.map +1 -1
- package/dist/app/commands/catalog.js +4 -0
- package/dist/app/commands/catalog.js.map +1 -1
- package/dist/app/commands/registry.js +1 -1
- package/dist/app/commands/registry.js.map +1 -1
- package/dist/app/controllers/session-changes.d.ts +5 -0
- package/dist/app/controllers/session-changes.js +50 -20
- package/dist/app/controllers/session-changes.js.map +1 -1
- package/dist/app/controllers/session-controller.d.ts +8 -0
- package/dist/app/controllers/session-controller.js +64 -6
- package/dist/app/controllers/session-controller.js.map +1 -1
- package/dist/app/controllers/session-id.d.ts +1 -0
- package/dist/app/controllers/session-id.js +4 -0
- package/dist/app/controllers/session-id.js.map +1 -0
- package/dist/app/controllers/session-late-work.d.ts +27 -0
- package/dist/app/controllers/session-late-work.js +113 -0
- package/dist/app/controllers/session-late-work.js.map +1 -0
- package/dist/app/controllers/session-persistence.d.ts +5 -3
- package/dist/app/controllers/session-persistence.js +8 -5
- package/dist/app/controllers/session-persistence.js.map +1 -1
- package/dist/app/ports/persistence-port.d.ts +6 -1
- package/dist/classic/app/app-wiring.d.ts +4 -2
- package/dist/classic/app/app-wiring.js +6 -2
- package/dist/classic/app/app-wiring.js.map +1 -1
- package/dist/classic/app/use-feed.js +9 -2
- package/dist/classic/app/use-feed.js.map +1 -1
- package/dist/classic/app/wiring-interactions.d.ts +3 -2
- package/dist/classic/app/wiring-interactions.js +15 -7
- package/dist/classic/app/wiring-interactions.js.map +1 -1
- package/dist/classic/app/wiring-lifecycle.js +9 -1
- package/dist/classic/app/wiring-lifecycle.js.map +1 -1
- package/dist/classic/app/wiring-types.d.ts +4 -1
- package/dist/classic/bootstrap/renderer-handle.js +11 -3
- package/dist/classic/bootstrap/renderer-handle.js.map +1 -1
- package/dist/classic/bootstrap/start-classic.js +4 -17
- package/dist/classic/bootstrap/start-classic.js.map +1 -1
- package/dist/classic/feed/background-layout.d.ts +26 -0
- package/dist/classic/feed/background-layout.js +77 -0
- package/dist/classic/feed/background-layout.js.map +1 -0
- package/dist/classic/feed/estimated-height.d.ts +2 -0
- package/dist/classic/feed/estimated-height.js +24 -0
- package/dist/classic/feed/estimated-height.js.map +1 -0
- package/dist/classic/feed/feed-blocks.d.ts +4 -1
- package/dist/classic/feed/feed-blocks.js +26 -6
- package/dist/classic/feed/feed-blocks.js.map +1 -1
- package/dist/classic/feed/transcript-window.d.ts +1 -0
- package/dist/classic/feed/transcript-window.js +41 -15
- package/dist/classic/feed/transcript-window.js.map +1 -1
- package/dist/classic/panels/pager-panel.d.ts +11 -8
- package/dist/classic/panels/pager-panel.js +42 -28
- package/dist/classic/panels/pager-panel.js.map +1 -1
- package/dist/classic/panels/pager-region-paint.d.ts +3 -0
- package/dist/classic/panels/pager-region-paint.js +43 -0
- package/dist/classic/panels/pager-region-paint.js.map +1 -0
- package/dist/classic/panels/pager-search-paint.d.ts +3 -0
- package/dist/classic/panels/pager-search-paint.js +59 -0
- package/dist/classic/panels/pager-search-paint.js.map +1 -0
- package/dist/classic/panels/pager-source-controller.js +2 -0
- package/dist/classic/panels/pager-source-controller.js.map +1 -1
- package/dist/classic/panels/panel-controller.js +5 -6
- package/dist/classic/panels/panel-controller.js.map +1 -1
- package/dist/classic/panels/panel-host.js +2 -2
- package/dist/classic/panels/panel-host.js.map +1 -1
- package/dist/classic/panels/panel-initial-states.d.ts +1 -0
- package/dist/classic/panels/panel-initial-states.js +1 -0
- package/dist/classic/panels/panel-initial-states.js.map +1 -1
- package/dist/classic/panels/panel-types.d.ts +1 -0
- package/dist/classic/panels/panel-wheel.js +2 -2
- package/dist/classic/panels/panel-wheel.js.map +1 -1
- package/dist/classic/panels/text-editor-panel.d.ts +2 -1
- package/dist/classic/panels/text-editor-panel.js +21 -12
- package/dist/classic/panels/text-editor-panel.js.map +1 -1
- package/dist/classic/render/ansi-text.js +49 -33
- package/dist/classic/render/ansi-text.js.map +1 -1
- package/dist/classic/render/ink-theme.js +1 -1
- package/dist/classic/render/ink-theme.js.map +1 -1
- package/dist/classic/render/measure.js +2 -3
- package/dist/classic/render/measure.js.map +1 -1
- package/dist/commands/current-version.d.ts +1 -0
- package/dist/commands/current-version.js +42 -0
- package/dist/commands/current-version.js.map +1 -0
- package/dist/commands/update.d.ts +2 -1
- package/dist/commands/update.js +4 -41
- package/dist/commands/update.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +21 -12
- package/dist/index.js.map +1 -1
- package/dist/llm/capabilities.js +13 -6
- package/dist/llm/capabilities.js.map +1 -1
- package/dist/llm/capability/vision-patterns.js +1 -1
- package/dist/llm/capability/vision-patterns.js.map +1 -1
- package/dist/llm/freebuff-agent-prompt.d.ts +1 -0
- package/dist/llm/freebuff-agent-prompt.js +46 -0
- package/dist/llm/freebuff-agent-prompt.js.map +1 -0
- package/dist/llm/freebuff-auth.js +15 -3
- package/dist/llm/freebuff-auth.js.map +1 -1
- package/dist/llm/freebuff-device-key.d.ts +39 -0
- package/dist/llm/freebuff-device-key.js +330 -0
- package/dist/llm/freebuff-device-key.js.map +1 -0
- package/dist/llm/freebuff-env-profile.d.ts +41 -0
- package/dist/llm/freebuff-env-profile.js +205 -0
- package/dist/llm/freebuff-env-profile.js.map +1 -0
- package/dist/llm/freebuff-fingerprint.d.ts +21 -0
- package/dist/llm/freebuff-fingerprint.js +137 -0
- package/dist/llm/freebuff-fingerprint.js.map +1 -0
- package/dist/llm/freebuff-models.d.ts +26 -5
- package/dist/llm/freebuff-models.js +137 -80
- package/dist/llm/freebuff-models.js.map +1 -1
- package/dist/llm/freebuff-run.d.ts +2 -0
- package/dist/llm/freebuff-run.js +77 -24
- package/dist/llm/freebuff-run.js.map +1 -1
- package/dist/llm/freebuff-session-api.d.ts +3 -1
- package/dist/llm/freebuff-session-api.js +26 -18
- package/dist/llm/freebuff-session-api.js.map +1 -1
- package/dist/llm/freebuff-session.d.ts +7 -1
- package/dist/llm/freebuff-session.js +81 -31
- package/dist/llm/freebuff-session.js.map +1 -1
- package/dist/llm/freebuff-wire.d.ts +8 -0
- package/dist/llm/freebuff-wire.js +42 -20
- package/dist/llm/freebuff-wire.js.map +1 -1
- package/dist/llm/freebuff.js +79 -9
- package/dist/llm/freebuff.js.map +1 -1
- package/dist/llm/main-effort-discovery.d.ts +16 -0
- package/dist/llm/main-effort-discovery.js +71 -0
- package/dist/llm/main-effort-discovery.js.map +1 -0
- package/dist/llm/omnirush-session-upload.d.ts +1 -0
- package/dist/llm/omnirush-session-upload.js +14 -1
- package/dist/llm/omnirush-session-upload.js.map +1 -1
- package/dist/llm/provider-profiles.js +28 -2
- package/dist/llm/provider-profiles.js.map +1 -1
- package/dist/llm/provider.js +2 -1
- package/dist/llm/provider.js.map +1 -1
- package/dist/llm/request-plan.js +13 -7
- package/dist/llm/request-plan.js.map +1 -1
- package/dist/llm/responses-request.js +8 -1
- package/dist/llm/responses-request.js.map +1 -1
- package/dist/llm/river-models.js +3 -1
- package/dist/llm/river-models.js.map +1 -1
- package/dist/llm/routing/attempt-complete.js +6 -1
- package/dist/llm/routing/attempt-complete.js.map +1 -1
- package/dist/llm/routing/attempt-request.d.ts +3 -1
- package/dist/llm/routing/attempt-request.js +39 -5
- package/dist/llm/routing/attempt-request.js.map +1 -1
- package/dist/llm/routing/attempt-stream.js +8 -1
- package/dist/llm/routing/attempt-stream.js.map +1 -1
- package/dist/llm/routing/error-classification.d.ts +1 -0
- package/dist/llm/routing/error-classification.js +9 -1
- package/dist/llm/routing/error-classification.js.map +1 -1
- package/dist/llm/wire/effort-preflight.d.ts +4 -1
- package/dist/llm/wire/effort-preflight.js +49 -6
- package/dist/llm/wire/effort-preflight.js.map +1 -1
- package/dist/llm/wire/openai-complete.d.ts +1 -0
- package/dist/llm/wire/openai-complete.js +5 -1
- package/dist/llm/wire/openai-complete.js.map +1 -1
- package/dist/llm/wire/openai-stream.d.ts +1 -0
- package/dist/llm/wire/openai-stream.js +1 -0
- package/dist/llm/wire/openai-stream.js.map +1 -1
- package/dist/llm/wire/responses-first.js +3 -0
- package/dist/llm/wire/responses-first.js.map +1 -1
- package/dist/os/ownership-repair.d.ts +5 -0
- package/dist/os/ownership-repair.js +62 -0
- package/dist/os/ownership-repair.js.map +1 -0
- package/dist/os/permissions.d.ts +7 -0
- package/dist/os/permissions.js +27 -22
- package/dist/os/permissions.js.map +1 -1
- package/dist/os/settle-within.d.ts +1 -0
- package/dist/os/settle-within.js +12 -0
- package/dist/os/settle-within.js.map +1 -0
- package/dist/os/user-environment.d.ts +1 -0
- package/dist/os/user-environment.js +3 -0
- package/dist/os/user-environment.js.map +1 -0
- package/dist/os/user-identity.d.ts +11 -0
- package/dist/os/user-identity.js +163 -0
- package/dist/os/user-identity.js.map +1 -0
- package/dist/safety/tool-classification.js +6 -0
- package/dist/safety/tool-classification.js.map +1 -1
- package/dist/security/known-secrets.d.ts +5 -0
- package/dist/security/known-secrets.js +50 -0
- package/dist/security/known-secrets.js.map +1 -0
- package/dist/session-runtime/client.d.ts +1 -1
- package/dist/session-runtime/client.js +6 -3
- package/dist/session-runtime/client.js.map +1 -1
- package/dist/session-runtime/host.js +2 -0
- package/dist/session-runtime/host.js.map +1 -1
- package/dist/session-runtime/paths.js +14 -6
- package/dist/session-runtime/paths.js.map +1 -1
- package/dist/session-runtime/start-runtime.js +5 -8
- package/dist/session-runtime/start-runtime.js.map +1 -1
- package/dist/session-runtime/store.js +4 -1
- package/dist/session-runtime/store.js.map +1 -1
- package/dist/store/config/endpoints.js +3 -1
- package/dist/store/config/endpoints.js.map +1 -1
- package/dist/store/credentials/crypto.d.ts +7 -0
- package/dist/store/credentials/crypto.js +118 -0
- package/dist/store/credentials/crypto.js.map +1 -0
- package/dist/store/credentials.d.ts +21 -0
- package/dist/store/credentials.js +150 -0
- package/dist/store/credentials.js.map +1 -0
- package/dist/store/history/freshness.d.ts +2 -0
- package/dist/store/history/freshness.js +3 -2
- package/dist/store/history/freshness.js.map +1 -1
- package/dist/store/history/jsonl-backend.js +20 -6
- package/dist/store/history/jsonl-backend.js.map +1 -1
- package/dist/store/history/jsonl-lock.d.ts +1 -0
- package/dist/store/history/jsonl-lock.js +94 -71
- package/dist/store/history/jsonl-lock.js.map +1 -1
- package/dist/store/history/recovery.d.ts +2 -0
- package/dist/store/history/recovery.js.map +1 -1
- package/dist/store/history/session-queries.js +0 -3
- package/dist/store/history/session-queries.js.map +1 -1
- package/dist/store/history/sqlite-backend.js +2 -0
- package/dist/store/history/sqlite-backend.js.map +1 -1
- package/dist/store/history/transcript-merge.d.ts +2 -0
- package/dist/store/history/transcript-merge.js +46 -0
- package/dist/store/history/transcript-merge.js.map +1 -0
- package/dist/store/history-index.d.ts +2 -0
- package/dist/store/history-index.js +3 -2
- package/dist/store/history-index.js.map +1 -1
- package/dist/store/history.d.ts +2 -1
- package/dist/store/history.js +43 -11
- package/dist/store/history.js.map +1 -1
- package/dist/store/keys/secret-store.js +5 -2
- package/dist/store/keys/secret-store.js.map +1 -1
- package/dist/store/legacy-location.d.ts +1 -0
- package/dist/store/legacy-location.js +37 -0
- package/dist/store/legacy-location.js.map +1 -0
- package/dist/store/ownership.d.ts +3 -0
- package/dist/store/ownership.js +23 -0
- package/dist/store/ownership.js.map +1 -0
- package/dist/store/paths.js +3 -2
- package/dist/store/paths.js.map +1 -1
- package/dist/store/redaction-cache.d.ts +0 -5
- package/dist/store/redaction-cache.js +6 -5
- package/dist/store/redaction-cache.js.map +1 -1
- package/dist/store/scope.js +7 -2
- package/dist/store/scope.js.map +1 -1
- package/dist/store/session-prompts.d.ts +1 -0
- package/dist/store/session-prompts.js +34 -13
- package/dist/store/session-prompts.js.map +1 -1
- package/dist/store/session-workspace.js +3 -0
- package/dist/store/session-workspace.js.map +1 -1
- package/dist/tools/credentials.d.ts +2 -0
- package/dist/tools/credentials.js +27 -0
- package/dist/tools/credentials.js.map +1 -0
- package/dist/tools/definitions/aggregate.js +2 -0
- package/dist/tools/definitions/aggregate.js.map +1 -1
- package/dist/tools/definitions/credentials.d.ts +1 -0
- package/dist/tools/definitions/credentials.js +15 -0
- package/dist/tools/definitions/credentials.js.map +1 -0
- package/dist/tools/definitions/fs-read.js +3 -2
- package/dist/tools/definitions/fs-read.js.map +1 -1
- package/dist/tools/definitions/terminal.js +2 -1
- package/dist/tools/definitions/terminal.js.map +1 -1
- package/dist/tools/elevated-shell.js +11 -14
- package/dist/tools/elevated-shell.js.map +1 -1
- package/dist/tools/interactive-session-tools.js +20 -4
- package/dist/tools/interactive-session-tools.js.map +1 -1
- package/dist/tools/registry.js +2 -0
- package/dist/tools/registry.js.map +1 -1
- package/dist/tools/sudo-session.d.ts +2 -1
- package/dist/tools/sudo-session.js +26 -9
- package/dist/tools/sudo-session.js.map +1 -1
- package/dist/tui-v2/app/App.js +9 -9
- package/dist/tui-v2/app/App.js.map +1 -1
- package/dist/tui-v2/app/layout-widths.js +4 -4
- package/dist/tui-v2/app/layout-widths.js.map +1 -1
- package/dist/tui-v2/bootstrap/renderer-handle.d.ts +2 -0
- package/dist/tui-v2/bootstrap/renderer-handle.js +21 -10
- package/dist/tui-v2/bootstrap/renderer-handle.js.map +1 -1
- package/dist/tui-v2/bootstrap/start-tui-v2.js +13 -28
- package/dist/tui-v2/bootstrap/start-tui-v2.js.map +1 -1
- package/dist/tui-v2/components/modal/text-editor-modal.js +4 -0
- package/dist/tui-v2/components/modal/text-editor-modal.js.map +1 -1
- package/dist/tui-v2/components/overlay/overlay-host.js +1 -2
- package/dist/tui-v2/components/overlay/overlay-host.js.map +1 -1
- package/dist/tui-v2/components/pager/pager-line.d.ts +1 -0
- package/dist/tui-v2/components/pager/pager-line.js +46 -27
- package/dist/tui-v2/components/pager/pager-line.js.map +1 -1
- package/dist/tui-v2/components/pager/pager-rows.d.ts +3 -0
- package/dist/tui-v2/components/pager/pager-rows.js +18 -1
- package/dist/tui-v2/components/pager/pager-rows.js.map +1 -1
- package/dist/tui-v2/components/pager/pager.d.ts +2 -0
- package/dist/tui-v2/components/pager/pager.js +10 -6
- package/dist/tui-v2/components/pager/pager.js.map +1 -1
- package/dist/tui-v2/components/plan/plan-view.js +5 -3
- package/dist/tui-v2/components/plan/plan-view.js.map +1 -1
- package/dist/tui-v2/components/toast/toast-anim.d.ts +6 -0
- package/dist/tui-v2/components/toast/toast-anim.js +17 -0
- package/dist/tui-v2/components/toast/toast-anim.js.map +1 -1
- package/dist/tui-v2/components/toast/toast-host.js +15 -5
- package/dist/tui-v2/components/toast/toast-host.js.map +1 -1
- package/dist/tui-v2/components/transcript/tool-card.js +5 -2
- package/dist/tui-v2/components/transcript/tool-card.js.map +1 -1
- package/dist/tui-v2/components/transcript/transcript-anchor.d.ts +20 -0
- package/dist/tui-v2/components/transcript/transcript-anchor.js +43 -0
- package/dist/tui-v2/components/transcript/transcript-anchor.js.map +1 -0
- package/dist/tui-v2/components/transcript/transcript-view.js +27 -40
- package/dist/tui-v2/components/transcript/transcript-view.js.map +1 -1
- package/dist/tui-v2/components/transcript/user-message.js +31 -21
- package/dist/tui-v2/components/transcript/user-message.js.map +1 -1
- package/dist/tui-v2/rendering/pager-markdown.d.ts +3 -2
- package/dist/tui-v2/rendering/pager-markdown.js +15 -11
- package/dist/tui-v2/rendering/pager-markdown.js.map +1 -1
- package/dist/types.d.ts +1 -0
- package/dist/ui-core/bootstrap/composition-root.js +23 -0
- package/dist/ui-core/bootstrap/composition-root.js.map +1 -1
- package/dist/ui-core/bootstrap/lifecycle.d.ts +1 -0
- package/dist/ui-core/bootstrap/lifecycle.js +6 -0
- package/dist/ui-core/bootstrap/lifecycle.js.map +1 -1
- package/dist/ui-core/bootstrap/resume-option.d.ts +11 -0
- package/dist/ui-core/bootstrap/resume-option.js +9 -0
- package/dist/ui-core/bootstrap/resume-option.js.map +1 -0
- package/dist/ui-core/bootstrap/session-merge.d.ts +4 -0
- package/dist/ui-core/bootstrap/session-merge.js +19 -0
- package/dist/ui-core/bootstrap/session-merge.js.map +1 -0
- package/dist/ui-core/bootstrap/session-resume.d.ts +2 -11
- package/dist/ui-core/bootstrap/session-resume.js +2 -8
- package/dist/ui-core/bootstrap/session-resume.js.map +1 -1
- package/dist/ui-core/bootstrap/shutdown-services.d.ts +3 -0
- package/dist/ui-core/bootstrap/shutdown-services.js +24 -0
- package/dist/ui-core/bootstrap/shutdown-services.js.map +1 -0
- package/dist/ui-core/commands/change-commands.js +53 -15
- package/dist/ui-core/commands/change-commands.js.map +1 -1
- package/dist/ui-core/commands/command-handlers.js +2 -0
- package/dist/ui-core/commands/command-handlers.js.map +1 -1
- package/dist/ui-core/commands/credential-commands.d.ts +7 -0
- package/dist/ui-core/commands/credential-commands.js +114 -0
- package/dist/ui-core/commands/credential-commands.js.map +1 -0
- package/dist/ui-core/commands/pickers/search-reasoning.js +14 -4
- package/dist/ui-core/commands/pickers/search-reasoning.js.map +1 -1
- package/dist/ui-core/controllers/overlay-controller.d.ts +4 -1
- package/dist/ui-core/controllers/overlay-controller.js +3 -2
- package/dist/ui-core/controllers/overlay-controller.js.map +1 -1
- package/dist/ui-core/layout/compute-layout.d.ts +3 -1
- package/dist/ui-core/layout/compute-layout.js +4 -2
- package/dist/ui-core/layout/compute-layout.js.map +1 -1
- package/dist/{classic/render/palette.js → ui-core/rendering/ansi-palette.js} +1 -1
- package/dist/ui-core/rendering/ansi-palette.js.map +1 -0
- package/dist/ui-core/rendering/artifact-pager-source.d.ts +1 -0
- package/dist/ui-core/rendering/artifact-pager-source.js.map +1 -1
- package/dist/ui-core/rendering/markdown-diff-rows.d.ts +12 -0
- package/dist/ui-core/rendering/markdown-diff-rows.js +85 -0
- package/dist/ui-core/rendering/markdown-diff-rows.js.map +1 -0
- package/dist/ui-core/rendering/markdown.d.ts +1 -0
- package/dist/ui-core/rendering/markdown.js +12 -0
- package/dist/ui-core/rendering/markdown.js.map +1 -1
- package/dist/ui-core/rendering/open-tool-output.js +40 -14
- package/dist/ui-core/rendering/open-tool-output.js.map +1 -1
- package/dist/ui-core/rendering/pager-regions.d.ts +7 -0
- package/dist/ui-core/rendering/pager-regions.js +8 -0
- package/dist/ui-core/rendering/pager-regions.js.map +1 -0
- package/dist/ui-core/rendering/plan-view.js +5 -5
- package/dist/ui-core/rendering/plan-view.js.map +1 -1
- package/dist/ui-core/rendering/render-markdown-lines.d.ts +1 -0
- package/dist/ui-core/rendering/render-markdown-lines.js +5 -2
- package/dist/ui-core/rendering/render-markdown-lines.js.map +1 -1
- package/dist/ui-core/rendering/session-change-diff.d.ts +2 -0
- package/dist/ui-core/rendering/session-change-diff.js +85 -0
- package/dist/ui-core/rendering/session-change-diff.js.map +1 -0
- package/dist/ui-core/rendering/session-prompts-pager-source.js +1 -1
- package/dist/ui-core/rendering/session-prompts-pager-source.js.map +1 -1
- package/dist/ui-core/rendering/task-disclosure.js +3 -3
- package/dist/ui-core/rendering/task-disclosure.js.map +1 -1
- package/dist/ui-core/rendering/text-width.d.ts +1 -0
- package/dist/ui-core/rendering/text-width.js +80 -4
- package/dist/ui-core/rendering/text-width.js.map +1 -1
- package/dist/ui-core/rendering/tool-presenter.d.ts +2 -0
- package/dist/ui-core/rendering/tool-presenter.js +53 -0
- package/dist/ui-core/rendering/tool-presenter.js.map +1 -1
- package/dist/ui-core/state/pager-search.d.ts +8 -0
- package/dist/ui-core/state/pager-search.js +20 -0
- package/dist/ui-core/state/pager-search.js.map +1 -1
- package/dist/ui-core/state/transcript-store.d.ts +2 -1
- package/dist/ui-core/state/transcript-store.js +35 -0
- package/dist/ui-core/state/transcript-store.js.map +1 -1
- package/dist/ui-core/state/transcript-window.d.ts +2 -2
- package/dist/ui-core/state/transcript-window.js +2 -2
- package/dist/ui-core/state/transcript-window.js.map +1 -1
- package/dist/version.generated.d.ts +2 -2
- package/dist/version.generated.js +2 -2
- package/package.json +1 -1
- package/dist/classic/render/palette.js.map +0 -1
- package/dist/tui-v2/components/modal/prompt-actions-modal.d.ts +0 -10
- package/dist/tui-v2/components/modal/prompt-actions-modal.js +0 -101
- package/dist/tui-v2/components/modal/prompt-actions-modal.js.map +0 -1
- package/dist/ui-core/rendering/prompt-preview.d.ts +0 -5
- package/dist/ui-core/rendering/prompt-preview.js +0 -27
- package/dist/ui-core/rendering/prompt-preview.js.map +0 -1
- /package/dist/{classic/render/palette.d.ts → ui-core/rendering/ansi-palette.d.ts} +0 -0
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { createHash, randomBytes } from "node:crypto";
|
|
2
|
+
import { readFileSync } from "node:fs";
|
|
3
|
+
import { arch as osArch, cpus as osCpus, hostname as osHostname, networkInterfaces as osNetworkInterfaces, platform as osPlatform, } from "node:os";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
import { normalizeFreebuffProcessName } from "./freebuff-env-profile.js";
|
|
6
|
+
const DEFAULT_MACHINE_ID_PATHS = ["/etc/machine-id", "/var/lib/dbus/machine-id"];
|
|
7
|
+
const DEFAULT_DMI_DIR = "/sys/class/dmi/id";
|
|
8
|
+
const DEFAULT_CPUINFO_PATH = "/proc/cpuinfo";
|
|
9
|
+
const DEFAULT_OS_RELEASE_PATH = "/etc/os-release";
|
|
10
|
+
const ZERO_MAC = "00:00:00:00:00:00";
|
|
11
|
+
export function createLegacyFreebuffFingerprintId() {
|
|
12
|
+
return `codebuff-cli-${randomBytes(6).toString("base64url").substring(0, 8)}`;
|
|
13
|
+
}
|
|
14
|
+
function readTextDefault(path) {
|
|
15
|
+
try {
|
|
16
|
+
return readFileSync(path, "utf8");
|
|
17
|
+
}
|
|
18
|
+
catch {
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
function machineIdOf(deps) {
|
|
23
|
+
const read = deps.readText ?? readTextDefault;
|
|
24
|
+
for (const path of deps.machineIdPaths ?? DEFAULT_MACHINE_ID_PATHS) {
|
|
25
|
+
const value = read(path)?.trim();
|
|
26
|
+
if (value && value !== "unknown" && value.length >= 8)
|
|
27
|
+
return value;
|
|
28
|
+
}
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
function dmiValue(deps, field) {
|
|
32
|
+
const read = deps.readText ?? readTextDefault;
|
|
33
|
+
return read(join(deps.dmiDir ?? DEFAULT_DMI_DIR, field))?.trim() ?? "";
|
|
34
|
+
}
|
|
35
|
+
function parseCpuInfo(text) {
|
|
36
|
+
let manufacturer = "";
|
|
37
|
+
let brand = "";
|
|
38
|
+
let physicalCores = 0;
|
|
39
|
+
for (const line of text.split("\n")) {
|
|
40
|
+
const separator = line.indexOf(":");
|
|
41
|
+
if (separator < 0)
|
|
42
|
+
continue;
|
|
43
|
+
const name = line.slice(0, separator).trim();
|
|
44
|
+
const value = line.slice(separator + 1).trim();
|
|
45
|
+
if (!value)
|
|
46
|
+
continue;
|
|
47
|
+
if (!manufacturer && (name === "vendor_id" || name === "CPU implementer"))
|
|
48
|
+
manufacturer = value;
|
|
49
|
+
if (!brand && (name === "model name" || name === "Processor" || name === "Hardware"))
|
|
50
|
+
brand = value;
|
|
51
|
+
if (!physicalCores && name === "cpu cores") {
|
|
52
|
+
const cores = Number(value);
|
|
53
|
+
if (Number.isSafeInteger(cores) && cores > 0)
|
|
54
|
+
physicalCores = cores;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return { manufacturer, brand, physicalCores };
|
|
58
|
+
}
|
|
59
|
+
function distroOf(deps) {
|
|
60
|
+
const read = deps.readText ?? readTextDefault;
|
|
61
|
+
const release = read(deps.osReleasePath ?? DEFAULT_OS_RELEASE_PATH);
|
|
62
|
+
if (!release)
|
|
63
|
+
return "";
|
|
64
|
+
const match = /^PRETTY_NAME=(.*)$/m.exec(release);
|
|
65
|
+
return match?.[1]?.trim().replace(/^"|"$/g, "") ?? "";
|
|
66
|
+
}
|
|
67
|
+
function networkSnapshot(deps) {
|
|
68
|
+
const interfaces = deps.networkInterfaces
|
|
69
|
+
? deps.networkInterfaces()
|
|
70
|
+
: osNetworkInterfaces();
|
|
71
|
+
const macAddresses = Object.values(interfaces)
|
|
72
|
+
.flatMap((entries) => (entries ?? []).filter((entry) => entry && !entry.internal && entry.mac && entry.mac !== ZERO_MAC))
|
|
73
|
+
.map((entry) => entry.mac)
|
|
74
|
+
.sort();
|
|
75
|
+
return { macAddresses, interfaceCount: Object.keys(interfaces).length };
|
|
76
|
+
}
|
|
77
|
+
async function enhancedFreebuffFingerprintId(deps) {
|
|
78
|
+
try {
|
|
79
|
+
const machineId = machineIdOf(deps);
|
|
80
|
+
if (!machineId)
|
|
81
|
+
return null;
|
|
82
|
+
const env = deps.env ?? process.env;
|
|
83
|
+
const read = deps.readText ?? readTextDefault;
|
|
84
|
+
const cpu = parseCpuInfo(read(deps.cpuInfoPath ?? DEFAULT_CPUINFO_PATH) ?? "");
|
|
85
|
+
const platform = deps.platform ?? osPlatform();
|
|
86
|
+
const network = networkSnapshot(deps);
|
|
87
|
+
const profile = {
|
|
88
|
+
system: {
|
|
89
|
+
manufacturer: dmiValue(deps, "sys_vendor"),
|
|
90
|
+
model: dmiValue(deps, "product_name"),
|
|
91
|
+
serial: dmiValue(deps, "product_serial"),
|
|
92
|
+
uuid: dmiValue(deps, "product_uuid"),
|
|
93
|
+
},
|
|
94
|
+
cpu: {
|
|
95
|
+
manufacturer: cpu.manufacturer,
|
|
96
|
+
brand: cpu.brand,
|
|
97
|
+
cores: (deps.cpuCount ?? (() => osCpus().length))(),
|
|
98
|
+
physicalCores: cpu.physicalCores,
|
|
99
|
+
},
|
|
100
|
+
os: {
|
|
101
|
+
platform,
|
|
102
|
+
distro: distroOf(deps),
|
|
103
|
+
arch: deps.arch ?? osArch(),
|
|
104
|
+
hostname: (deps.hostname ?? osHostname)(),
|
|
105
|
+
},
|
|
106
|
+
runtime: {
|
|
107
|
+
nodeVersion: deps.nodeVersion ?? process.version,
|
|
108
|
+
platform,
|
|
109
|
+
arch: deps.arch ?? osArch(),
|
|
110
|
+
shell: normalizeFreebuffProcessName(env.SHELL),
|
|
111
|
+
cpuCount: (deps.cpuCount ?? (() => osCpus().length))(),
|
|
112
|
+
},
|
|
113
|
+
network,
|
|
114
|
+
machineId,
|
|
115
|
+
fingerprintVersion: "2.0",
|
|
116
|
+
};
|
|
117
|
+
const digest = createHash("sha256").update(JSON.stringify(profile)).digest("base64url");
|
|
118
|
+
return `enhanced-${digest}`;
|
|
119
|
+
}
|
|
120
|
+
catch {
|
|
121
|
+
return null;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
let cachedFingerprint;
|
|
125
|
+
async function computeFreebuffFingerprintId(deps) {
|
|
126
|
+
return (await enhancedFreebuffFingerprintId(deps)) ?? createLegacyFreebuffFingerprintId();
|
|
127
|
+
}
|
|
128
|
+
export function freebuffFingerprintId(deps = {}) {
|
|
129
|
+
if (!cachedFingerprint) {
|
|
130
|
+
cachedFingerprint = computeFreebuffFingerprintId(deps).catch(() => createLegacyFreebuffFingerprintId());
|
|
131
|
+
}
|
|
132
|
+
return cachedFingerprint;
|
|
133
|
+
}
|
|
134
|
+
export function resetFreebuffFingerprint() {
|
|
135
|
+
cachedFingerprint = undefined;
|
|
136
|
+
}
|
|
137
|
+
//# sourceMappingURL=freebuff-fingerprint.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"freebuff-fingerprint.js","sourceRoot":"","sources":["../../src/llm/freebuff-fingerprint.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,WAAW,EA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 +1,29 @@
|
|
|
1
|
-
|
|
2
|
-
export declare const
|
|
1
|
+
export declare const FREEBUFF_CATALOG_PROTOCOL = "1";
|
|
2
|
+
export declare const FREEBUFF_CATALOG_PROTOCOL_HEADER = "x-freebuff-catalog-protocol";
|
|
3
|
+
export declare const FREEBUFF_CATALOG_FETCH_HEADER = "x-freebuff-catalog-fetch";
|
|
4
|
+
export declare const FREEBUFF_CATALOG_CLIENT = "cli";
|
|
3
5
|
export declare const FREEBUFF_STATIC_MODEL_IDS: readonly string[];
|
|
4
|
-
export
|
|
6
|
+
export interface FreebuffCatalogRow {
|
|
7
|
+
readonly key: string;
|
|
8
|
+
readonly handle: string;
|
|
9
|
+
readonly access: string | undefined;
|
|
10
|
+
readonly opensAt: number | undefined;
|
|
11
|
+
}
|
|
12
|
+
export interface FreebuffCatalogSnapshot {
|
|
13
|
+
readonly version: string | undefined;
|
|
14
|
+
readonly fetchId: string | undefined;
|
|
15
|
+
readonly rows: readonly FreebuffCatalogRow[];
|
|
16
|
+
}
|
|
17
|
+
export interface FreebuffCatalogDeps {
|
|
18
|
+
readonly fetch?: typeof fetch | undefined;
|
|
19
|
+
readonly baseUrl?: string | undefined;
|
|
20
|
+
readonly now?: (() => number) | undefined;
|
|
21
|
+
}
|
|
22
|
+
export declare function freebuffCatalogSnapshot(token: string, deps?: FreebuffCatalogDeps): FreebuffCatalogSnapshot | undefined;
|
|
23
|
+
export declare function freebuffCatalogHandle(token: string, model: string, deps?: FreebuffCatalogDeps): string | undefined;
|
|
24
|
+
export declare function refreshFreebuffCatalog(token: string, signal?: AbortSignal, deps?: FreebuffCatalogDeps): Promise<FreebuffCatalogSnapshot | null>;
|
|
25
|
+
export declare function visibleFreebuffCatalogModelIds(snapshot: FreebuffCatalogSnapshot, now?: number): string[];
|
|
5
26
|
export declare function mergeFreebuffModelIds(visible: readonly string[]): string[];
|
|
6
|
-
export declare function resetFreebuffCatalogCache(): void;
|
|
7
|
-
export declare function fetchFreebuffModelIds(token: string, signal?: AbortSignal): Promise<string[]>;
|
|
8
27
|
export declare function freebuffStaticModelIds(): string[];
|
|
28
|
+
export declare function resetFreebuffCatalogCache(): void;
|
|
29
|
+
export declare function fetchFreebuffModelIds(token: string, signal?: AbortSignal, deps?: FreebuffCatalogDeps): Promise<string[]>;
|
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
import { createHash } from "node:crypto";
|
|
2
|
-
import {
|
|
3
|
-
|
|
2
|
+
import { FREEBUFF_API_BASE_URL } from "./freebuff-auth.js";
|
|
3
|
+
import { freebuffDeviceHeaders, freebuffForgetDeviceKeyRegistration, isFreebuffDeviceKeyError, } from "./freebuff-device-key.js";
|
|
4
|
+
const CATALOG_PATH = "/api/v1/freebuff/models";
|
|
5
|
+
export const FREEBUFF_CATALOG_PROTOCOL = "1";
|
|
6
|
+
export const FREEBUFF_CATALOG_PROTOCOL_HEADER = "x-freebuff-catalog-protocol";
|
|
7
|
+
export const FREEBUFF_CATALOG_FETCH_HEADER = "x-freebuff-catalog-fetch";
|
|
8
|
+
export const FREEBUFF_CATALOG_CLIENT = "cli";
|
|
4
9
|
const CACHE_TTL_MS = 30 * 60 * 1000;
|
|
10
|
+
const CATALOG_TIMEOUT_MS = 20_000;
|
|
11
|
+
const MAX_CACHED_ACCOUNTS = 10;
|
|
5
12
|
export const FREEBUFF_STATIC_MODEL_IDS = [
|
|
6
13
|
"anthropic/claude-fable-5.1",
|
|
7
14
|
"anthropic/claude-opus-4.8",
|
|
@@ -66,112 +73,162 @@ export const FREEBUFF_STATIC_MODEL_IDS = [
|
|
|
66
73
|
"z-ai/glm-5.3-flashx",
|
|
67
74
|
"z-ai/glm-5.3-prime",
|
|
68
75
|
];
|
|
69
|
-
function collectKeys(value, into) {
|
|
70
|
-
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
71
|
-
return;
|
|
72
|
-
for (const key of Object.keys(value)) {
|
|
73
|
-
if (key.trim())
|
|
74
|
-
into.add(key.trim());
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
function planRequiredIds(freebucks) {
|
|
78
|
-
const required = new Set();
|
|
79
|
-
const ids = freebucks?.planRequiredModelIds;
|
|
80
|
-
if (Array.isArray(ids)) {
|
|
81
|
-
for (const id of ids) {
|
|
82
|
-
if (typeof id === "string" && id.trim())
|
|
83
|
-
required.add(id.trim());
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
return required;
|
|
87
|
-
}
|
|
88
|
-
function zeroPriceIds(freebucks) {
|
|
89
|
-
const free = new Set();
|
|
90
|
-
const prices = freebucks?.prices;
|
|
91
|
-
if (!prices || typeof prices !== "object" || Array.isArray(prices))
|
|
92
|
-
return free;
|
|
93
|
-
for (const [id, price] of Object.entries(prices)) {
|
|
94
|
-
if (id.trim() && price === 0)
|
|
95
|
-
free.add(id.trim());
|
|
96
|
-
}
|
|
97
|
-
return free;
|
|
98
|
-
}
|
|
99
|
-
export function visibleFreebuffModelIds(response) {
|
|
100
|
-
const record = response;
|
|
101
|
-
const blocked = planRequiredIds(record.freebucks);
|
|
102
|
-
const ids = new Set();
|
|
103
|
-
if (typeof record.model === "string" && record.model.trim())
|
|
104
|
-
ids.add(record.model.trim());
|
|
105
|
-
collectKeys(record.rateLimitsByModel, ids);
|
|
106
|
-
for (const id of zeroPriceIds(record.freebucks))
|
|
107
|
-
ids.add(id);
|
|
108
|
-
for (const id of blocked)
|
|
109
|
-
ids.delete(id);
|
|
110
|
-
return [...ids];
|
|
111
|
-
}
|
|
112
|
-
export function mergeFreebuffModelIds(visible) {
|
|
113
|
-
const merged = new Set(FREEBUFF_STATIC_MODEL_IDS);
|
|
114
|
-
for (const id of visible) {
|
|
115
|
-
const trimmed = id.trim();
|
|
116
|
-
if (trimmed)
|
|
117
|
-
merged.add(trimmed);
|
|
118
|
-
}
|
|
119
|
-
return [...merged].sort((a, b) => a.localeCompare(b));
|
|
120
|
-
}
|
|
121
76
|
const cached = new Map();
|
|
122
77
|
const requestsInFlight = new Map();
|
|
123
|
-
const MAX_CACHED_ACCOUNTS = 10;
|
|
124
|
-
export function resetFreebuffCatalogCache() {
|
|
125
|
-
cached.clear();
|
|
126
|
-
requestsInFlight.clear();
|
|
127
|
-
}
|
|
128
78
|
function tokenCacheKey(token) {
|
|
129
79
|
return createHash("sha256").update(token).digest("hex");
|
|
130
80
|
}
|
|
131
|
-
function
|
|
81
|
+
function catalogUrl(base) {
|
|
82
|
+
return `${base.replace(/\/$/, "")}${CATALOG_PATH}`;
|
|
83
|
+
}
|
|
84
|
+
function recordOf(value) {
|
|
85
|
+
return value !== null && typeof value === "object" && !Array.isArray(value)
|
|
86
|
+
? value
|
|
87
|
+
: undefined;
|
|
88
|
+
}
|
|
89
|
+
function parseSnapshot(payload) {
|
|
90
|
+
const record = recordOf(payload);
|
|
91
|
+
if (!record || record.protocol !== 1 || !Array.isArray(record.rows))
|
|
92
|
+
return null;
|
|
93
|
+
const rows = [];
|
|
94
|
+
for (const raw of record.rows) {
|
|
95
|
+
const row = recordOf(raw);
|
|
96
|
+
const key = row?.key;
|
|
97
|
+
const handle = row?.handle;
|
|
98
|
+
if (typeof key !== "string" || !key.trim() || typeof handle !== "string" || !handle.trim())
|
|
99
|
+
continue;
|
|
100
|
+
rows.push({
|
|
101
|
+
key: key.trim(),
|
|
102
|
+
handle: handle.trim(),
|
|
103
|
+
access: typeof row?.access === "string" ? row.access : undefined,
|
|
104
|
+
opensAt: typeof row?.opensAt === "number" && Number.isFinite(row.opensAt) ? row.opensAt : undefined,
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
return {
|
|
108
|
+
version: typeof record.version === "string" ? record.version : undefined,
|
|
109
|
+
fetchId: typeof record.fetchId === "string" ? record.fetchId : undefined,
|
|
110
|
+
rows,
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
function cacheSnapshot(tokenHash, snapshot, fetchedAt) {
|
|
132
114
|
cached.delete(tokenHash);
|
|
133
|
-
cached.set(tokenHash, {
|
|
115
|
+
cached.set(tokenHash, { snapshot, fetchedAt });
|
|
134
116
|
if (cached.size > MAX_CACHED_ACCOUNTS) {
|
|
135
117
|
const oldest = cached.keys().next().value;
|
|
136
118
|
if (oldest)
|
|
137
119
|
cached.delete(oldest);
|
|
138
120
|
}
|
|
139
121
|
}
|
|
140
|
-
|
|
122
|
+
function pruneStaleEntries(now) {
|
|
123
|
+
for (const [key, entry] of cached) {
|
|
124
|
+
if (now - entry.fetchedAt >= CACHE_TTL_MS)
|
|
125
|
+
cached.delete(key);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
async function requestCatalog(token, deps, signal, register) {
|
|
129
|
+
const url = catalogUrl(deps.baseUrl ?? FREEBUFF_API_BASE_URL);
|
|
130
|
+
const timeout = AbortSignal.timeout(CATALOG_TIMEOUT_MS);
|
|
131
|
+
const combined = signal ? AbortSignal.any([signal, timeout]) : timeout;
|
|
132
|
+
const headers = {
|
|
133
|
+
authorization: `Bearer ${token}`,
|
|
134
|
+
[FREEBUFF_CATALOG_PROTOCOL_HEADER]: FREEBUFF_CATALOG_PROTOCOL,
|
|
135
|
+
"x-freebuff-client": FREEBUFF_CATALOG_CLIENT,
|
|
136
|
+
"user-agent": "Bun/1.3.14",
|
|
137
|
+
accept: "*/*",
|
|
138
|
+
"accept-encoding": "gzip, deflate, br",
|
|
139
|
+
};
|
|
140
|
+
const current = cached.get(tokenCacheKey(token))?.snapshot;
|
|
141
|
+
Object.assign(headers, await freebuffDeviceHeaders({
|
|
142
|
+
token,
|
|
143
|
+
method: "GET",
|
|
144
|
+
url,
|
|
145
|
+
...(current?.fetchId !== undefined ? { fetchId: current.fetchId } : {}),
|
|
146
|
+
register,
|
|
147
|
+
}));
|
|
148
|
+
const response = await (deps.fetch ?? fetch)(url, { method: "GET", headers, signal: combined });
|
|
149
|
+
if (!response.ok) {
|
|
150
|
+
const payload = (await response.json().catch(() => null));
|
|
151
|
+
const error = (recordOf(payload)?.error);
|
|
152
|
+
if (typeof error === "string") {
|
|
153
|
+
if (isFreebuffDeviceKeyError(error))
|
|
154
|
+
freebuffForgetDeviceKeyRegistration(token, url);
|
|
155
|
+
}
|
|
156
|
+
return null;
|
|
157
|
+
}
|
|
158
|
+
return parseSnapshot(await response.json().catch(() => null));
|
|
159
|
+
}
|
|
160
|
+
async function loadCatalog(token, deps, signal, force) {
|
|
141
161
|
const tokenHash = tokenCacheKey(token);
|
|
142
|
-
const now = Date.now();
|
|
162
|
+
const now = deps.now?.() ?? Date.now();
|
|
163
|
+
pruneStaleEntries(now);
|
|
143
164
|
const previous = cached.get(tokenHash);
|
|
144
|
-
if (previous && now - previous.fetchedAt < CACHE_TTL_MS)
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
const inFlight = requestsInFlight.get(tokenHash);
|
|
150
|
-
if (inFlight)
|
|
151
|
-
return [...(await inFlight)];
|
|
165
|
+
if (!force && previous && now - previous.fetchedAt < CACHE_TTL_MS)
|
|
166
|
+
return previous.snapshot;
|
|
167
|
+
const inflight = requestsInFlight.get(tokenHash);
|
|
168
|
+
if (inflight)
|
|
169
|
+
return inflight;
|
|
152
170
|
const request = (async () => {
|
|
153
171
|
try {
|
|
154
|
-
const
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
return modelIds;
|
|
172
|
+
const snapshot = await requestCatalog(token, deps, signal, Boolean(previous));
|
|
173
|
+
if (snapshot)
|
|
174
|
+
cacheSnapshot(tokenHash, snapshot, deps.now?.() ?? Date.now());
|
|
175
|
+
return snapshot ?? previous?.snapshot ?? null;
|
|
159
176
|
}
|
|
160
177
|
catch {
|
|
161
|
-
return previous
|
|
178
|
+
return previous?.snapshot ?? null;
|
|
162
179
|
}
|
|
163
180
|
})();
|
|
164
181
|
requestsInFlight.set(tokenHash, request);
|
|
165
182
|
try {
|
|
166
|
-
return
|
|
183
|
+
return await request;
|
|
167
184
|
}
|
|
168
185
|
finally {
|
|
169
|
-
if (requestsInFlight.get(tokenHash) === request)
|
|
186
|
+
if (requestsInFlight.get(tokenHash) === request)
|
|
170
187
|
requestsInFlight.delete(tokenHash);
|
|
171
|
-
}
|
|
172
188
|
}
|
|
173
189
|
}
|
|
190
|
+
export function freebuffCatalogSnapshot(token, deps = {}) {
|
|
191
|
+
const now = deps.now?.() ?? Date.now();
|
|
192
|
+
pruneStaleEntries(now);
|
|
193
|
+
return cached.get(tokenCacheKey(token))?.snapshot;
|
|
194
|
+
}
|
|
195
|
+
export function freebuffCatalogHandle(token, model, deps = {}) {
|
|
196
|
+
const snapshot = freebuffCatalogSnapshot(token, deps);
|
|
197
|
+
return snapshot?.rows.find((row) => row.key === model)?.handle;
|
|
198
|
+
}
|
|
199
|
+
export function refreshFreebuffCatalog(token, signal, deps = {}) {
|
|
200
|
+
return loadCatalog(token, deps, signal, true);
|
|
201
|
+
}
|
|
202
|
+
export function visibleFreebuffCatalogModelIds(snapshot, now = Date.now()) {
|
|
203
|
+
const ids = new Set();
|
|
204
|
+
for (const row of snapshot.rows) {
|
|
205
|
+
if (row.access === "locked")
|
|
206
|
+
continue;
|
|
207
|
+
if (row.opensAt !== undefined && row.opensAt > now)
|
|
208
|
+
continue;
|
|
209
|
+
ids.add(row.key);
|
|
210
|
+
}
|
|
211
|
+
return [...ids];
|
|
212
|
+
}
|
|
213
|
+
export function mergeFreebuffModelIds(visible) {
|
|
214
|
+
const merged = new Set(FREEBUFF_STATIC_MODEL_IDS);
|
|
215
|
+
for (const id of visible) {
|
|
216
|
+
const trimmed = id.trim();
|
|
217
|
+
if (trimmed)
|
|
218
|
+
merged.add(trimmed);
|
|
219
|
+
}
|
|
220
|
+
return [...merged].sort((a, b) => a.localeCompare(b));
|
|
221
|
+
}
|
|
174
222
|
export function freebuffStaticModelIds() {
|
|
175
223
|
return mergeFreebuffModelIds([]);
|
|
176
224
|
}
|
|
225
|
+
export function resetFreebuffCatalogCache() {
|
|
226
|
+
cached.clear();
|
|
227
|
+
requestsInFlight.clear();
|
|
228
|
+
}
|
|
229
|
+
export async function fetchFreebuffModelIds(token, signal, deps = {}) {
|
|
230
|
+
const snapshot = await loadCatalog(token, deps, signal, false);
|
|
231
|
+
const ids = snapshot ? visibleFreebuffCatalogModelIds(snapshot).sort((a, b) => a.localeCompare(b)) : [];
|
|
232
|
+
return ids.length > 0 ? ids : freebuffStaticModelIds();
|
|
233
|
+
}
|
|
177
234
|
//# sourceMappingURL=freebuff-models.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"freebuff-models.js","sourceRoot":"","sources":["../../src/llm/freebuff-models.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"freebuff-models.js","sourceRoot":"","sources":["../../src/llm/freebuff-models.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAC3D,OAAO,EACL,qBAAqB,EACrB,mCAAmC,EACnC,wBAAwB,GACzB,MAAM,0BAA0B,CAAC;AAElC,MAAM,YAAY,GAAG,yBAAyB,CAAC;AAC/C,MAAM,CAAC,MAAM,yBAAyB,GAAG,GAAG,CAAC;AAC7C,MAAM,CAAC,MAAM,gCAAgC,GAAG,6BAA6B,CAAC;AAC9E,MAAM,CAAC,MAAM,6BAA6B,GAAG,0BAA0B,CAAC;AACxE,MAAM,CAAC,MAAM,uBAAuB,GAAG,KAAK,CAAC;AAE7C,MAAM,YAAY,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;AACpC,MAAM,kBAAkB,GAAG,MAAM,CAAC;AAClC,MAAM,mBAAmB,GAAG,EAAE,CAAC;AAE/B,MAAM,CAAC,MAAM,yBAAyB,GAAsB;IAC1D,4BAA4B;IAC5B,2BAA2B;IAC3B,yBAAyB;IACzB,2BAA2B;IAC3B,6BAA6B;IAC7B,2BAA2B;IAC3B,kBAAkB;IAClB,4BAA4B;IAC5B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CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,sBAAsB,EAAE,CAAC;AACzD,CAAC"}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
export declare const FREEBUFF_CATALOG_AGENT_ID = "base3-free-catalog";
|
|
1
2
|
export declare function freebuffAgentId(model: string): string;
|
|
3
|
+
export declare function freebuffAgentIdForToken(token: string, model: string): string;
|
|
2
4
|
export interface FreebuffRun {
|
|
3
5
|
readonly runId: string;
|
|
4
6
|
readonly clientId: string;
|
package/dist/llm/freebuff-run.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { randomUUID } from "node:crypto";
|
|
2
2
|
import { ProviderError } from "./http.js";
|
|
3
3
|
import { FREEBUFF_API_BASE_URL } from "./freebuff-auth.js";
|
|
4
|
+
import { freebuffCatalogSnapshot } from "./freebuff-models.js";
|
|
5
|
+
import { freebuffActingUserHeaders } from "./freebuff-wire.js";
|
|
4
6
|
const RUN_PATH = "/api/v1/agent-runs";
|
|
5
7
|
const RUN_TIMEOUT_MS = 30_000;
|
|
6
8
|
const BASE3_AGENT_BY_MODEL = {
|
|
@@ -89,11 +91,15 @@ const BASE2_AGENT_BY_MODEL = {
|
|
|
89
91
|
"z-ai/glm-5.3-flashx": "base2-free-glm-5-3-flashx",
|
|
90
92
|
"z-ai/glm-5.3-prime": "base2-free-glm-5-3-prime",
|
|
91
93
|
};
|
|
92
|
-
const FALLBACK_AGENT_ID = "
|
|
94
|
+
const FALLBACK_AGENT_ID = "base2-free";
|
|
95
|
+
export const FREEBUFF_CATALOG_AGENT_ID = "base3-free-catalog";
|
|
93
96
|
export function freebuffAgentId(model) {
|
|
94
97
|
const id = model.trim();
|
|
95
|
-
|
|
96
|
-
|
|
98
|
+
return BASE3_AGENT_BY_MODEL[id] ?? BASE2_AGENT_BY_MODEL[id] ?? FALLBACK_AGENT_ID;
|
|
99
|
+
}
|
|
100
|
+
export function freebuffAgentIdForToken(token, model) {
|
|
101
|
+
const row = freebuffCatalogSnapshot(token)?.rows.find((candidate) => candidate.key === model.trim());
|
|
102
|
+
return row ? FREEBUFF_CATALOG_AGENT_ID : freebuffAgentId(model);
|
|
97
103
|
}
|
|
98
104
|
function runUrl(base) {
|
|
99
105
|
return `${base.replace(/\/$/, "")}${RUN_PATH}`;
|
|
@@ -102,31 +108,78 @@ function runSignal(signal) {
|
|
|
102
108
|
const timeout = AbortSignal.timeout(RUN_TIMEOUT_MS);
|
|
103
109
|
return signal ? AbortSignal.any([signal, timeout]) : timeout;
|
|
104
110
|
}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
111
|
+
const RUN_RETRIES = 3;
|
|
112
|
+
const RUN_RETRY_BASE_MS = 1_000;
|
|
113
|
+
const RUN_RETRY_CAP_MS = 8_000;
|
|
114
|
+
const RETRYABLE_RUN_STATUSES = new Set([408, 429, 500, 502, 503, 504]);
|
|
115
|
+
function runRetryDelay(attempt) {
|
|
116
|
+
return Math.min(RUN_RETRY_BASE_MS * 2 ** attempt, RUN_RETRY_CAP_MS);
|
|
117
|
+
}
|
|
118
|
+
function delay(ms, signal) {
|
|
119
|
+
return new Promise((resolve, reject) => {
|
|
120
|
+
if (signal?.aborted) {
|
|
121
|
+
reject(signal.reason ?? new DOMException("Aborted", "AbortError"));
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
const timer = setTimeout(() => {
|
|
125
|
+
signal?.removeEventListener("abort", onAbort);
|
|
126
|
+
resolve();
|
|
127
|
+
}, ms);
|
|
128
|
+
function onAbort() {
|
|
129
|
+
clearTimeout(timer);
|
|
130
|
+
reject(signal?.reason ?? new DOMException("Aborted", "AbortError"));
|
|
131
|
+
}
|
|
132
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
114
133
|
});
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
134
|
+
}
|
|
135
|
+
async function postRun(token, body, action, deps) {
|
|
136
|
+
const url = runUrl(deps.baseUrl ?? FREEBUFF_API_BASE_URL);
|
|
137
|
+
const requestBody = JSON.stringify(body);
|
|
138
|
+
let lastError;
|
|
139
|
+
for (let attempt = 0; attempt <= RUN_RETRIES; attempt += 1) {
|
|
140
|
+
let response;
|
|
141
|
+
try {
|
|
142
|
+
response = await (deps.fetch ?? fetch)(url, {
|
|
143
|
+
method: "POST",
|
|
144
|
+
headers: {
|
|
145
|
+
authorization: `Bearer ${token}`,
|
|
146
|
+
"content-type": "application/json",
|
|
147
|
+
"user-agent": "Bun/1.3.14",
|
|
148
|
+
accept: "*/*",
|
|
149
|
+
"accept-encoding": "gzip, deflate, br",
|
|
150
|
+
...freebuffActingUserHeaders(),
|
|
151
|
+
},
|
|
152
|
+
body: requestBody,
|
|
153
|
+
signal: runSignal(deps.signal),
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
catch (error) {
|
|
157
|
+
lastError = error;
|
|
158
|
+
if (attempt === RUN_RETRIES || deps.signal?.aborted)
|
|
159
|
+
throw error;
|
|
160
|
+
await delay(runRetryDelay(attempt), deps.signal);
|
|
161
|
+
continue;
|
|
162
|
+
}
|
|
163
|
+
const text = await response.text().catch(() => "");
|
|
164
|
+
if (response.ok) {
|
|
165
|
+
if (!text)
|
|
166
|
+
return undefined;
|
|
167
|
+
try {
|
|
168
|
+
return JSON.parse(text);
|
|
169
|
+
}
|
|
170
|
+
catch {
|
|
171
|
+
return undefined;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
lastError = new ProviderError(`Freebuff ${action} failed (${response.status}${text ? `: ${text.slice(0, 300)}` : ""})`, response.status, text.slice(0, 2_000));
|
|
175
|
+
if (!RETRYABLE_RUN_STATUSES.has(response.status) || attempt === RUN_RETRIES)
|
|
176
|
+
throw lastError;
|
|
177
|
+
await delay(runRetryDelay(attempt), deps.signal);
|
|
126
178
|
}
|
|
179
|
+
throw lastError instanceof Error ? lastError : new ProviderError(`Freebuff ${action} failed after retries.`);
|
|
127
180
|
}
|
|
128
181
|
export async function startFreebuffRun(token, model, deps = {}) {
|
|
129
|
-
const agentId =
|
|
182
|
+
const agentId = freebuffAgentIdForToken(token, model);
|
|
130
183
|
const payload = await postRun(token, { action: "START", agentId, ancestorRunIds: [] }, "run start", deps);
|
|
131
184
|
const runId = payload?.["runId"];
|
|
132
185
|
if (typeof runId !== "string" || !runId) {
|