@zwbigi/ink-xy 0.1.2 → 0.1.4
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/.next/BUILD_ID +1 -1
- package/.next/app-path-routes-manifest.json +2 -2
- package/.next/build-manifest.json +2 -2
- package/.next/server/app/_global-error.html +1 -1
- package/.next/server/app/_global-error.rsc +1 -1
- package/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
- package/.next/server/app/_global-error.segments/_global-error/__PAGE__.segment.rsc +1 -1
- package/.next/server/app/_global-error.segments/_global-error.segment.rsc +1 -1
- package/.next/server/app/_global-error.segments/_head.segment.rsc +1 -1
- package/.next/server/app/_global-error.segments/_index.segment.rsc +1 -1
- package/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
- package/.next/server/app/_not-found.html +1 -1
- package/.next/server/app/_not-found.rsc +1 -1
- package/.next/server/app/_not-found.segments/_full.segment.rsc +1 -1
- package/.next/server/app/_not-found.segments/_head.segment.rsc +1 -1
- package/.next/server/app/_not-found.segments/_index.segment.rsc +1 -1
- package/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +1 -1
- package/.next/server/app/_not-found.segments/_not-found.segment.rsc +1 -1
- package/.next/server/app/_not-found.segments/_tree.segment.rsc +1 -1
- package/.next/server/app/api/inkos/route.js.nft.json +1 -1
- package/.next/server/app/api/skills/install/route.js.nft.json +1 -1
- package/.next/server/app/api/skills/search/route.js.nft.json +1 -1
- package/.next/server/app/index.html +1 -1
- package/.next/server/app/index.rsc +1 -1
- package/.next/server/app/index.segments/__PAGE__.segment.rsc +1 -1
- package/.next/server/app/index.segments/_full.segment.rsc +1 -1
- package/.next/server/app/index.segments/_head.segment.rsc +1 -1
- package/.next/server/app/index.segments/_index.segment.rsc +1 -1
- package/.next/server/app/index.segments/_tree.segment.rsc +1 -1
- package/.next/server/app-paths-manifest.json +2 -2
- package/.next/server/chunks/162.js +1 -1
- package/.next/server/middleware-build-manifest.js +1 -1
- package/.next/server/pages/404.html +1 -1
- package/.next/server/pages/500.html +1 -1
- package/.next/trace +4 -4
- package/.next/trace-build +1 -1
- package/bin/pi-web.js +4 -1
- package/inkos/.env.example +20 -0
- package/inkos/.node-version +1 -0
- package/inkos/.nvmrc +1 -0
- package/inkos/CHANGELOG.md +787 -0
- package/inkos/CONTRIBUTING.md +89 -0
- package/inkos/LICENSE +661 -0
- package/inkos/README.en.md +483 -0
- package/inkos/README.ja.md +461 -0
- package/inkos/README.md +272 -0
- package/inkos/assets/15qun.jpg +0 -0
- package/inkos/assets/41777702961_.pic.jpg +0 -0
- package/inkos/assets/inkos-short-demo-cover.png +0 -0
- package/inkos/assets/inkos-text.svg +40 -0
- package/inkos/assets/logo.svg +47 -0
- package/inkos/assets/screenshot-chapters.png +0 -0
- package/inkos/assets/screenshot-pipeline.png +0 -0
- package/inkos/assets/screenshot-state.png +0 -0
- package/inkos/assets/screenshot-terminal.png +0 -0
- package/inkos/assets/wechat-group-v8.jpg +0 -0
- package/inkos/package.json +42 -0
- package/inkos/packages/cli/package.json +74 -0
- package/inkos/packages/cli/src/__tests__/analytics.test.ts +154 -0
- package/inkos/packages/cli/src/__tests__/cli-integration.test.ts +1031 -0
- package/inkos/packages/cli/src/__tests__/daemon.test.ts +93 -0
- package/inkos/packages/cli/src/__tests__/doctor.test.ts +36 -0
- package/inkos/packages/cli/src/__tests__/interact-command.test.ts +142 -0
- package/inkos/packages/cli/src/__tests__/interaction-tools.test.ts +107 -0
- package/inkos/packages/cli/src/__tests__/llm-overrides.test.ts +25 -0
- package/inkos/packages/cli/src/__tests__/localization.test.ts +121 -0
- package/inkos/packages/cli/src/__tests__/progress-text.test.ts +92 -0
- package/inkos/packages/cli/src/__tests__/project-bootstrap.test.ts +71 -0
- package/inkos/packages/cli/src/__tests__/publish-package.test.ts +272 -0
- package/inkos/packages/cli/src/__tests__/revision-command.test.ts +82 -0
- package/inkos/packages/cli/src/__tests__/runtime-requirements.test.ts +89 -0
- package/inkos/packages/cli/src/__tests__/short-fiction-command.test.ts +48 -0
- package/inkos/packages/cli/src/__tests__/studio-runtime.test.ts +142 -0
- package/inkos/packages/cli/src/__tests__/studio.test.ts +87 -0
- package/inkos/packages/cli/src/__tests__/tui-activity-state.test.ts +20 -0
- package/inkos/packages/cli/src/__tests__/tui-agent-session.test.ts +213 -0
- package/inkos/packages/cli/src/__tests__/tui-chat-depth.test.ts +27 -0
- package/inkos/packages/cli/src/__tests__/tui-chat-draft.test.ts +44 -0
- package/inkos/packages/cli/src/__tests__/tui-command.test.ts +86 -0
- package/inkos/packages/cli/src/__tests__/tui-composer-caret.test.ts +46 -0
- package/inkos/packages/cli/src/__tests__/tui-composer-display.test.ts +40 -0
- package/inkos/packages/cli/src/__tests__/tui-dashboard.test.tsx +219 -0
- package/inkos/packages/cli/src/__tests__/tui-effects-i18n.test.ts +29 -0
- package/inkos/packages/cli/src/__tests__/tui-i18n.test.ts +22 -0
- package/inkos/packages/cli/src/__tests__/tui-input-chrome.test.ts +10 -0
- package/inkos/packages/cli/src/__tests__/tui-input-history.test.ts +40 -0
- package/inkos/packages/cli/src/__tests__/tui-layout.test.ts +55 -0
- package/inkos/packages/cli/src/__tests__/tui-local-commands.test.ts +47 -0
- package/inkos/packages/cli/src/__tests__/tui-session-store.test.ts +81 -0
- package/inkos/packages/cli/src/__tests__/tui-setup-i18n.test.ts +31 -0
- package/inkos/packages/cli/src/__tests__/tui-slash-autocomplete.test.ts +33 -0
- package/inkos/packages/cli/src/commands/agent.ts +65 -0
- package/inkos/packages/cli/src/commands/analytics.ts +77 -0
- package/inkos/packages/cli/src/commands/audit.ts +52 -0
- package/inkos/packages/cli/src/commands/book.ts +260 -0
- package/inkos/packages/cli/src/commands/compose.ts +50 -0
- package/inkos/packages/cli/src/commands/config.ts +328 -0
- package/inkos/packages/cli/src/commands/consolidate.ts +50 -0
- package/inkos/packages/cli/src/commands/daemon.ts +121 -0
- package/inkos/packages/cli/src/commands/detect.ts +125 -0
- package/inkos/packages/cli/src/commands/doctor.ts +391 -0
- package/inkos/packages/cli/src/commands/draft.ts +43 -0
- package/inkos/packages/cli/src/commands/eval.ts +217 -0
- package/inkos/packages/cli/src/commands/export.ts +45 -0
- package/inkos/packages/cli/src/commands/fanfic.ts +183 -0
- package/inkos/packages/cli/src/commands/genre.ts +160 -0
- package/inkos/packages/cli/src/commands/import.ts +158 -0
- package/inkos/packages/cli/src/commands/init.ts +47 -0
- package/inkos/packages/cli/src/commands/interact.ts +109 -0
- package/inkos/packages/cli/src/commands/plan.ts +54 -0
- package/inkos/packages/cli/src/commands/radar.ts +60 -0
- package/inkos/packages/cli/src/commands/review.ts +253 -0
- package/inkos/packages/cli/src/commands/revise.ts +58 -0
- package/inkos/packages/cli/src/commands/short-fiction.ts +294 -0
- package/inkos/packages/cli/src/commands/status.ts +138 -0
- package/inkos/packages/cli/src/commands/studio.ts +194 -0
- package/inkos/packages/cli/src/commands/style.ts +99 -0
- package/inkos/packages/cli/src/commands/tui.ts +18 -0
- package/inkos/packages/cli/src/commands/update.ts +45 -0
- package/inkos/packages/cli/src/commands/write.ts +324 -0
- package/inkos/packages/cli/src/index.ts +5 -0
- package/inkos/packages/cli/src/interaction/tools.ts +49 -0
- package/inkos/packages/cli/src/localization.ts +215 -0
- package/inkos/packages/cli/src/program.ts +106 -0
- package/inkos/packages/cli/src/progress-text.ts +85 -0
- package/inkos/packages/cli/src/project-bootstrap.ts +175 -0
- package/inkos/packages/cli/src/runtime-requirements.ts +135 -0
- package/inkos/packages/cli/src/tui/__tests__/markdown.test.ts +64 -0
- package/inkos/packages/cli/src/tui/activity-state.ts +41 -0
- package/inkos/packages/cli/src/tui/agent-input.ts +264 -0
- package/inkos/packages/cli/src/tui/ansi.ts +72 -0
- package/inkos/packages/cli/src/tui/app.ts +130 -0
- package/inkos/packages/cli/src/tui/chat-depth.ts +22 -0
- package/inkos/packages/cli/src/tui/chat-draft.ts +42 -0
- package/inkos/packages/cli/src/tui/composer-caret.ts +22 -0
- package/inkos/packages/cli/src/tui/composer-display.ts +26 -0
- package/inkos/packages/cli/src/tui/dashboard-model.ts +164 -0
- package/inkos/packages/cli/src/tui/dashboard.tsx +544 -0
- package/inkos/packages/cli/src/tui/effects.ts +542 -0
- package/inkos/packages/cli/src/tui/i18n.ts +278 -0
- package/inkos/packages/cli/src/tui/input-history.ts +69 -0
- package/inkos/packages/cli/src/tui/local-commands.ts +55 -0
- package/inkos/packages/cli/src/tui/markdown.ts +64 -0
- package/inkos/packages/cli/src/tui/session-store.ts +6 -0
- package/inkos/packages/cli/src/tui/setup.ts +397 -0
- package/inkos/packages/cli/src/tui/slash-autocomplete.ts +62 -0
- package/inkos/packages/cli/src/tui/theme.ts +17 -0
- package/inkos/packages/cli/src/utils.ts +222 -0
- package/inkos/packages/cli/tsconfig.json +9 -0
- package/inkos/packages/core/genres/cozy.md +43 -0
- package/inkos/packages/core/genres/cultivation.md +42 -0
- package/inkos/packages/core/genres/dungeon-core.md +40 -0
- package/inkos/packages/core/genres/horror.md +51 -0
- package/inkos/packages/core/genres/isekai.md +43 -0
- package/inkos/packages/core/genres/litrpg.md +43 -0
- package/inkos/packages/core/genres/other.md +24 -0
- package/inkos/packages/core/genres/progression.md +41 -0
- package/inkos/packages/core/genres/romantasy.md +45 -0
- package/inkos/packages/core/genres/sci-fi.md +42 -0
- package/inkos/packages/core/genres/system-apocalypse.md +40 -0
- package/inkos/packages/core/genres/tower-climber.md +41 -0
- package/inkos/packages/core/genres/urban.md +53 -0
- package/inkos/packages/core/genres/xianxia.md +46 -0
- package/inkos/packages/core/genres/xuanhuan.md +64 -0
- package/inkos/packages/core/package.json +61 -0
- package/inkos/packages/core/src/__tests__/agent-max-tokens-policy.test.ts +29 -0
- package/inkos/packages/core/src/__tests__/agent-session.test.ts +866 -0
- package/inkos/packages/core/src/__tests__/agent-system-prompt.test.ts +167 -0
- package/inkos/packages/core/src/__tests__/agent-tools-params.test.ts +197 -0
- package/inkos/packages/core/src/__tests__/agent-tools.test.ts +421 -0
- package/inkos/packages/core/src/__tests__/ai-tells.test.ts +90 -0
- package/inkos/packages/core/src/__tests__/architect-phase5-consolidated.test.ts +445 -0
- package/inkos/packages/core/src/__tests__/architect-phase5.test.ts +455 -0
- package/inkos/packages/core/src/__tests__/architect-phase7.test.ts +210 -0
- package/inkos/packages/core/src/__tests__/architect.test.ts +859 -0
- package/inkos/packages/core/src/__tests__/audit-parse.test.ts +78 -0
- package/inkos/packages/core/src/__tests__/book-id.test.ts +26 -0
- package/inkos/packages/core/src/__tests__/book-session-store.test.ts +447 -0
- package/inkos/packages/core/src/__tests__/book-session.test.ts +113 -0
- package/inkos/packages/core/src/__tests__/chapter-analyzer.test.ts +574 -0
- package/inkos/packages/core/src/__tests__/chapter-memo-parser.test.ts +247 -0
- package/inkos/packages/core/src/__tests__/chapter-persistence.test.ts +198 -0
- package/inkos/packages/core/src/__tests__/chapter-review-cycle.test.ts +294 -0
- package/inkos/packages/core/src/__tests__/chapter-splitter.test.ts +156 -0
- package/inkos/packages/core/src/__tests__/chapter-state-recovery.test.ts +235 -0
- package/inkos/packages/core/src/__tests__/chapter-truth-validation.test.ts +253 -0
- package/inkos/packages/core/src/__tests__/composer.test.ts +627 -0
- package/inkos/packages/core/src/__tests__/config-loader.test.ts +325 -0
- package/inkos/packages/core/src/__tests__/config-migration.test.ts +102 -0
- package/inkos/packages/core/src/__tests__/consolidator.test.ts +32 -0
- package/inkos/packages/core/src/__tests__/context-filter.test.ts +60 -0
- package/inkos/packages/core/src/__tests__/context-transform.test.ts +108 -0
- package/inkos/packages/core/src/__tests__/continuity.test.ts +391 -0
- package/inkos/packages/core/src/__tests__/detection-insights.test.ts +59 -0
- package/inkos/packages/core/src/__tests__/detector.test.ts +86 -0
- package/inkos/packages/core/src/__tests__/draft-directive-parser.test.ts +386 -0
- package/inkos/packages/core/src/__tests__/edit-controller.test.ts +190 -0
- package/inkos/packages/core/src/__tests__/effective-llm-config.test.ts +486 -0
- package/inkos/packages/core/src/__tests__/fanfic-dimensions.test.ts +58 -0
- package/inkos/packages/core/src/__tests__/fanfic-models.test.ts +69 -0
- package/inkos/packages/core/src/__tests__/governed-working-set.test.ts +155 -0
- package/inkos/packages/core/src/__tests__/hook-arbiter.test.ts +124 -0
- package/inkos/packages/core/src/__tests__/hook-governance.test.ts +228 -0
- package/inkos/packages/core/src/__tests__/hook-health.test.ts +166 -0
- package/inkos/packages/core/src/__tests__/hook-ledger-validator.test.ts +236 -0
- package/inkos/packages/core/src/__tests__/hook-promotion.test.ts +192 -0
- package/inkos/packages/core/src/__tests__/hook-stale-detection.test.ts +136 -0
- package/inkos/packages/core/src/__tests__/index-notify-lazy.test.ts +20 -0
- package/inkos/packages/core/src/__tests__/interaction-chat-tokens.test.ts +170 -0
- package/inkos/packages/core/src/__tests__/interaction-models.test.ts +155 -0
- package/inkos/packages/core/src/__tests__/interaction-nl-router.test.ts +223 -0
- package/inkos/packages/core/src/__tests__/interaction-runtime.test.ts +633 -0
- package/inkos/packages/core/src/__tests__/interaction-tools.test.ts +343 -0
- package/inkos/packages/core/src/__tests__/length-metrics.test.ts +82 -0
- package/inkos/packages/core/src/__tests__/length-normalizer.test.ts +331 -0
- package/inkos/packages/core/src/__tests__/list-models.test.ts +109 -0
- package/inkos/packages/core/src/__tests__/llm-env.test.ts +31 -0
- package/inkos/packages/core/src/__tests__/logger.test.ts +175 -0
- package/inkos/packages/core/src/__tests__/long-span-fatigue.test.ts +160 -0
- package/inkos/packages/core/src/__tests__/memory-retrieval.test.ts +1303 -0
- package/inkos/packages/core/src/__tests__/models.test.ts +918 -0
- package/inkos/packages/core/src/__tests__/outline-paths.test.ts +97 -0
- package/inkos/packages/core/src/__tests__/path-safety.test.ts +22 -0
- package/inkos/packages/core/src/__tests__/persisted-governed-plan.test.ts +134 -0
- package/inkos/packages/core/src/__tests__/phase5-cleanup.test.ts +393 -0
- package/inkos/packages/core/src/__tests__/phase5-hotfix.test.ts +288 -0
- package/inkos/packages/core/src/__tests__/phase7-hotfix.test.ts +614 -0
- package/inkos/packages/core/src/__tests__/pipeline-agent.test.ts +354 -0
- package/inkos/packages/core/src/__tests__/pipeline-runner-memory-sync.test.ts +317 -0
- package/inkos/packages/core/src/__tests__/pipeline-runner.test.ts +5200 -0
- package/inkos/packages/core/src/__tests__/planner-context.test.ts +137 -0
- package/inkos/packages/core/src/__tests__/planner-prompts-ratio.test.ts +11 -0
- package/inkos/packages/core/src/__tests__/planner-prompts.test.ts +171 -0
- package/inkos/packages/core/src/__tests__/planner.test.ts +362 -0
- package/inkos/packages/core/src/__tests__/planning-materials.test.ts +90 -0
- package/inkos/packages/core/src/__tests__/polisher.test.ts +189 -0
- package/inkos/packages/core/src/__tests__/post-write-validator.test.ts +291 -0
- package/inkos/packages/core/src/__tests__/probe.test.ts +77 -0
- package/inkos/packages/core/src/__tests__/project-interaction.test.ts +241 -0
- package/inkos/packages/core/src/__tests__/provider.test.ts +953 -0
- package/inkos/packages/core/src/__tests__/providers-group.test.ts +34 -0
- package/inkos/packages/core/src/__tests__/providers-lookup.test.ts +81 -0
- package/inkos/packages/core/src/__tests__/providers-schema.test.ts +158 -0
- package/inkos/packages/core/src/__tests__/proxy-fetch.test.ts +75 -0
- package/inkos/packages/core/src/__tests__/revise-foundation.test.ts +514 -0
- package/inkos/packages/core/src/__tests__/reviser.test.ts +859 -0
- package/inkos/packages/core/src/__tests__/runtime-state-store.test.ts +388 -0
- package/inkos/packages/core/src/__tests__/scheduler.test.ts +123 -0
- package/inkos/packages/core/src/__tests__/secrets-migration.test.ts +71 -0
- package/inkos/packages/core/src/__tests__/secrets.test.ts +95 -0
- package/inkos/packages/core/src/__tests__/sensitive-words.test.ts +88 -0
- package/inkos/packages/core/src/__tests__/service-presets-regression.test.ts +73 -0
- package/inkos/packages/core/src/__tests__/service-resolver-regression.test.ts +75 -0
- package/inkos/packages/core/src/__tests__/service-resolver.test.ts +228 -0
- package/inkos/packages/core/src/__tests__/session-transcript-restore.test.ts +1311 -0
- package/inkos/packages/core/src/__tests__/session-transcript.test.ts +195 -0
- package/inkos/packages/core/src/__tests__/settler-delta-parser.test.ts +133 -0
- package/inkos/packages/core/src/__tests__/short-fiction-public.test.ts +241 -0
- package/inkos/packages/core/src/__tests__/spot-fix-patches.test.ts +104 -0
- package/inkos/packages/core/src/__tests__/state-manager.test.ts +1298 -0
- package/inkos/packages/core/src/__tests__/state-projections.test.ts +130 -0
- package/inkos/packages/core/src/__tests__/state-reducer.test.ts +372 -0
- package/inkos/packages/core/src/__tests__/state-validator-agent.test.ts +165 -0
- package/inkos/packages/core/src/__tests__/state-validator.test.ts +122 -0
- package/inkos/packages/core/src/__tests__/style-analyzer.test.ts +61 -0
- package/inkos/packages/core/src/__tests__/temperature-constraints.test.ts +57 -0
- package/inkos/packages/core/src/__tests__/v13-hotfix-round4.test.ts +343 -0
- package/inkos/packages/core/src/__tests__/verify-service.test.ts +77 -0
- package/inkos/packages/core/src/__tests__/webhook.test.ts +91 -0
- package/inkos/packages/core/src/__tests__/writer-parser.test.ts +348 -0
- package/inkos/packages/core/src/__tests__/writer-prompts.test.ts +269 -0
- package/inkos/packages/core/src/__tests__/writer.test.ts +1360 -0
- package/inkos/packages/core/src/agent/agent-session.ts +737 -0
- package/inkos/packages/core/src/agent/agent-system-prompt.ts +199 -0
- package/inkos/packages/core/src/agent/agent-tools.ts +835 -0
- package/inkos/packages/core/src/agent/context-transform.ts +85 -0
- package/inkos/packages/core/src/agent/index.ts +14 -0
- package/inkos/packages/core/src/agents/ai-tells.ts +161 -0
- package/inkos/packages/core/src/agents/architect.ts +1291 -0
- package/inkos/packages/core/src/agents/base.ts +100 -0
- package/inkos/packages/core/src/agents/chapter-analyzer.ts +634 -0
- package/inkos/packages/core/src/agents/composer.ts +469 -0
- package/inkos/packages/core/src/agents/consolidator.ts +218 -0
- package/inkos/packages/core/src/agents/continuity.ts +824 -0
- package/inkos/packages/core/src/agents/detection-insights.ts +72 -0
- package/inkos/packages/core/src/agents/detector.ts +224 -0
- package/inkos/packages/core/src/agents/en-prompt-sections.ts +129 -0
- package/inkos/packages/core/src/agents/fanfic-canon-importer.ts +146 -0
- package/inkos/packages/core/src/agents/fanfic-dimensions.ts +87 -0
- package/inkos/packages/core/src/agents/fanfic-prompt-sections.ts +109 -0
- package/inkos/packages/core/src/agents/foundation-reviewer.ts +204 -0
- package/inkos/packages/core/src/agents/length-normalizer.ts +218 -0
- package/inkos/packages/core/src/agents/observer-prompts.ts +127 -0
- package/inkos/packages/core/src/agents/planner-context.ts +297 -0
- package/inkos/packages/core/src/agents/planner-prompts.ts +404 -0
- package/inkos/packages/core/src/agents/planner.ts +783 -0
- package/inkos/packages/core/src/agents/polisher.ts +153 -0
- package/inkos/packages/core/src/agents/post-write-validator.ts +873 -0
- package/inkos/packages/core/src/agents/radar-source.ts +123 -0
- package/inkos/packages/core/src/agents/radar.ts +120 -0
- package/inkos/packages/core/src/agents/reviser.ts +701 -0
- package/inkos/packages/core/src/agents/rules-reader.ts +155 -0
- package/inkos/packages/core/src/agents/sensitive-words.ts +142 -0
- package/inkos/packages/core/src/agents/settler-delta-parser.ts +53 -0
- package/inkos/packages/core/src/agents/settler-parser.ts +38 -0
- package/inkos/packages/core/src/agents/settler-prompts.ts +230 -0
- package/inkos/packages/core/src/agents/short-fiction.ts +429 -0
- package/inkos/packages/core/src/agents/state-validator.ts +322 -0
- package/inkos/packages/core/src/agents/style-analyzer.ts +93 -0
- package/inkos/packages/core/src/agents/writer-parser.ts +178 -0
- package/inkos/packages/core/src/agents/writer-prompts.ts +899 -0
- package/inkos/packages/core/src/agents/writer.ts +1450 -0
- package/inkos/packages/core/src/index.ts +392 -0
- package/inkos/packages/core/src/interaction/book-session-store.ts +226 -0
- package/inkos/packages/core/src/interaction/draft-directive-parser.ts +266 -0
- package/inkos/packages/core/src/interaction/edit-controller.ts +270 -0
- package/inkos/packages/core/src/interaction/events.ts +41 -0
- package/inkos/packages/core/src/interaction/export-artifact.ts +151 -0
- package/inkos/packages/core/src/interaction/intents.ts +63 -0
- package/inkos/packages/core/src/interaction/modes.ts +13 -0
- package/inkos/packages/core/src/interaction/nl-router.ts +258 -0
- package/inkos/packages/core/src/interaction/project-control.ts +150 -0
- package/inkos/packages/core/src/interaction/project-session-store.ts +81 -0
- package/inkos/packages/core/src/interaction/project-tools.ts +704 -0
- package/inkos/packages/core/src/interaction/request-router.ts +5 -0
- package/inkos/packages/core/src/interaction/runtime.ts +1167 -0
- package/inkos/packages/core/src/interaction/session-transcript-legacy.ts +113 -0
- package/inkos/packages/core/src/interaction/session-transcript-restore.ts +607 -0
- package/inkos/packages/core/src/interaction/session-transcript-schema.ts +76 -0
- package/inkos/packages/core/src/interaction/session-transcript.ts +189 -0
- package/inkos/packages/core/src/interaction/session.ts +226 -0
- package/inkos/packages/core/src/interaction/truth-authority.ts +45 -0
- package/inkos/packages/core/src/llm/config-migration.ts +58 -0
- package/inkos/packages/core/src/llm/cover-providers.ts +45 -0
- package/inkos/packages/core/src/llm/provider.ts +1331 -0
- package/inkos/packages/core/src/llm/providers/endpoints/ai360.ts +42 -0
- package/inkos/packages/core/src/llm/providers/endpoints/anthropic.ts +82 -0
- package/inkos/packages/core/src/llm/providers/endpoints/astronCodingPlan.ts +30 -0
- package/inkos/packages/core/src/llm/providers/endpoints/baichuan.ts +28 -0
- package/inkos/packages/core/src/llm/providers/endpoints/bailian.ts +65 -0
- package/inkos/packages/core/src/llm/providers/endpoints/bailianCodingPlan.ts +30 -0
- package/inkos/packages/core/src/llm/providers/endpoints/custom.ts +22 -0
- package/inkos/packages/core/src/llm/providers/endpoints/deepseek.ts +35 -0
- package/inkos/packages/core/src/llm/providers/endpoints/giteeai.ts +41 -0
- package/inkos/packages/core/src/llm/providers/endpoints/githubCopilot.ts +43 -0
- package/inkos/packages/core/src/llm/providers/endpoints/glmCodingPlan.ts +28 -0
- package/inkos/packages/core/src/llm/providers/endpoints/google.ts +51 -0
- package/inkos/packages/core/src/llm/providers/endpoints/hunyuan.ts +42 -0
- package/inkos/packages/core/src/llm/providers/endpoints/infiniai.ts +72 -0
- package/inkos/packages/core/src/llm/providers/endpoints/internlm.ts +28 -0
- package/inkos/packages/core/src/llm/providers/endpoints/kimiCode.ts +23 -0
- package/inkos/packages/core/src/llm/providers/endpoints/kimiCodingPlan.ts +24 -0
- package/inkos/packages/core/src/llm/providers/endpoints/kkaiapi.ts +56 -0
- package/inkos/packages/core/src/llm/providers/endpoints/longcat.ts +25 -0
- package/inkos/packages/core/src/llm/providers/endpoints/minimax.ts +39 -0
- package/inkos/packages/core/src/llm/providers/endpoints/minimaxCodingPlan.ts +28 -0
- package/inkos/packages/core/src/llm/providers/endpoints/mistral.ts +40 -0
- package/inkos/packages/core/src/llm/providers/endpoints/modelscope.ts +30 -0
- package/inkos/packages/core/src/llm/providers/endpoints/moonshot.ts +39 -0
- package/inkos/packages/core/src/llm/providers/endpoints/newapi.ts +21 -0
- package/inkos/packages/core/src/llm/providers/endpoints/ollama.ts +73 -0
- package/inkos/packages/core/src/llm/providers/endpoints/openai.ts +77 -0
- package/inkos/packages/core/src/llm/providers/endpoints/opencodeCodingPlan.ts +30 -0
- package/inkos/packages/core/src/llm/providers/endpoints/openrouter.ts +87 -0
- package/inkos/packages/core/src/llm/providers/endpoints/ppio.ts +86 -0
- package/inkos/packages/core/src/llm/providers/endpoints/qiniu.ts +32 -0
- package/inkos/packages/core/src/llm/providers/endpoints/sensenova.ts +45 -0
- package/inkos/packages/core/src/llm/providers/endpoints/siliconcloud.ts +126 -0
- package/inkos/packages/core/src/llm/providers/endpoints/spark.ts +33 -0
- package/inkos/packages/core/src/llm/providers/endpoints/stepfun.ts +35 -0
- package/inkos/packages/core/src/llm/providers/endpoints/tencentcloud.ts +25 -0
- package/inkos/packages/core/src/llm/providers/endpoints/volcengine.ts +52 -0
- package/inkos/packages/core/src/llm/providers/endpoints/volcengineCodingPlan.ts +42 -0
- package/inkos/packages/core/src/llm/providers/endpoints/wenxin.ts +106 -0
- package/inkos/packages/core/src/llm/providers/endpoints/xai.ts +34 -0
- package/inkos/packages/core/src/llm/providers/endpoints/xiaomimimo.ts +26 -0
- package/inkos/packages/core/src/llm/providers/endpoints/zeroone.ts +34 -0
- package/inkos/packages/core/src/llm/providers/endpoints/zhipu.ts +61 -0
- package/inkos/packages/core/src/llm/providers/index.ts +71 -0
- package/inkos/packages/core/src/llm/providers/lookup.ts +70 -0
- package/inkos/packages/core/src/llm/providers/probe.ts +35 -0
- package/inkos/packages/core/src/llm/providers/types.ts +89 -0
- package/inkos/packages/core/src/llm/providers/verify.ts +104 -0
- package/inkos/packages/core/src/llm/secrets.ts +77 -0
- package/inkos/packages/core/src/llm/service-presets.ts +215 -0
- package/inkos/packages/core/src/llm/service-resolver.ts +91 -0
- package/inkos/packages/core/src/models/book-rules.ts +126 -0
- package/inkos/packages/core/src/models/book.ts +70 -0
- package/inkos/packages/core/src/models/chapter.ts +42 -0
- package/inkos/packages/core/src/models/detection.ts +25 -0
- package/inkos/packages/core/src/models/genre-profile.ts +36 -0
- package/inkos/packages/core/src/models/input-governance.ts +99 -0
- package/inkos/packages/core/src/models/length-governance.ts +46 -0
- package/inkos/packages/core/src/models/project.ts +161 -0
- package/inkos/packages/core/src/models/runtime-state.ts +144 -0
- package/inkos/packages/core/src/models/state.ts +52 -0
- package/inkos/packages/core/src/models/style-profile.ts +15 -0
- package/inkos/packages/core/src/notify/dispatcher.ts +96 -0
- package/inkos/packages/core/src/notify/feishu.ts +34 -0
- package/inkos/packages/core/src/notify/telegram.ts +25 -0
- package/inkos/packages/core/src/notify/webhook.ts +58 -0
- package/inkos/packages/core/src/notify/wechat-work.ts +22 -0
- package/inkos/packages/core/src/pipeline/agent.ts +691 -0
- package/inkos/packages/core/src/pipeline/chapter-persistence.ts +79 -0
- package/inkos/packages/core/src/pipeline/chapter-review-cycle.ts +324 -0
- package/inkos/packages/core/src/pipeline/chapter-state-recovery.ts +236 -0
- package/inkos/packages/core/src/pipeline/chapter-truth-validation.ts +145 -0
- package/inkos/packages/core/src/pipeline/detection-runner.ts +164 -0
- package/inkos/packages/core/src/pipeline/persisted-governed-plan.ts +216 -0
- package/inkos/packages/core/src/pipeline/runner.ts +3438 -0
- package/inkos/packages/core/src/pipeline/scheduler.ts +411 -0
- package/inkos/packages/core/src/pipeline/short-fiction-runner.ts +801 -0
- package/inkos/packages/core/src/prompts/index.ts +1 -0
- package/inkos/packages/core/src/prompts/short-fiction.ts +273 -0
- package/inkos/packages/core/src/state/manager.ts +560 -0
- package/inkos/packages/core/src/state/memory-db.ts +359 -0
- package/inkos/packages/core/src/state/runtime-state-store.ts +164 -0
- package/inkos/packages/core/src/state/state-bootstrap.ts +657 -0
- package/inkos/packages/core/src/state/state-projections.ts +255 -0
- package/inkos/packages/core/src/state/state-reducer.ts +260 -0
- package/inkos/packages/core/src/state/state-validator.ts +117 -0
- package/inkos/packages/core/src/utils/analytics.ts +92 -0
- package/inkos/packages/core/src/utils/book-id.ts +31 -0
- package/inkos/packages/core/src/utils/cadence-policy.ts +46 -0
- package/inkos/packages/core/src/utils/chapter-cadence.ts +211 -0
- package/inkos/packages/core/src/utils/chapter-memo-parser.ts +157 -0
- package/inkos/packages/core/src/utils/chapter-splitter.ts +80 -0
- package/inkos/packages/core/src/utils/config-loader.ts +29 -0
- package/inkos/packages/core/src/utils/context-assembly.ts +98 -0
- package/inkos/packages/core/src/utils/context-filter.ts +190 -0
- package/inkos/packages/core/src/utils/effective-llm-config.ts +529 -0
- package/inkos/packages/core/src/utils/governed-context.ts +101 -0
- package/inkos/packages/core/src/utils/governed-working-set.ts +395 -0
- package/inkos/packages/core/src/utils/hook-arbiter.ts +332 -0
- package/inkos/packages/core/src/utils/hook-governance.ts +199 -0
- package/inkos/packages/core/src/utils/hook-health.ts +189 -0
- package/inkos/packages/core/src/utils/hook-ledger-validator.ts +277 -0
- package/inkos/packages/core/src/utils/hook-lifecycle.ts +224 -0
- package/inkos/packages/core/src/utils/hook-policy.ts +115 -0
- package/inkos/packages/core/src/utils/hook-promotion.ts +313 -0
- package/inkos/packages/core/src/utils/hook-stale-detection.ts +168 -0
- package/inkos/packages/core/src/utils/length-metrics.ts +123 -0
- package/inkos/packages/core/src/utils/llm-endpoint-auth.ts +40 -0
- package/inkos/packages/core/src/utils/llm-env.ts +74 -0
- package/inkos/packages/core/src/utils/logger.ts +123 -0
- package/inkos/packages/core/src/utils/long-span-fatigue.ts +545 -0
- package/inkos/packages/core/src/utils/memory-retrieval.ts +527 -0
- package/inkos/packages/core/src/utils/narrative-control.ts +177 -0
- package/inkos/packages/core/src/utils/outline-paths.ts +275 -0
- package/inkos/packages/core/src/utils/path-safety.ts +11 -0
- package/inkos/packages/core/src/utils/planning-materials.ts +185 -0
- package/inkos/packages/core/src/utils/pov-filter.ts +149 -0
- package/inkos/packages/core/src/utils/proxy-fetch.ts +44 -0
- package/inkos/packages/core/src/utils/runtime-writer.ts +41 -0
- package/inkos/packages/core/src/utils/spot-fix-patches.ts +189 -0
- package/inkos/packages/core/src/utils/story-markdown.ts +346 -0
- package/inkos/packages/core/src/utils/web-search.ts +82 -0
- package/inkos/packages/core/src/utils/writing-methodology.ts +164 -0
- package/inkos/packages/core/tsconfig.json +8 -0
- package/inkos/packages/core/vitest.config.ts +7 -0
- package/inkos/packages/studio/components.json +25 -0
- package/inkos/packages/studio/index.html +13 -0
- package/inkos/packages/studio/package.json +72 -0
- package/inkos/packages/studio/postcss.config.js +3 -0
- package/inkos/packages/studio/src/App.test.ts +25 -0
- package/inkos/packages/studio/src/App.tsx +280 -0
- package/inkos/packages/studio/src/api/__tests__/normalize-base-url.test.ts +40 -0
- package/inkos/packages/studio/src/api/book-create.test.ts +104 -0
- package/inkos/packages/studio/src/api/book-create.ts +94 -0
- package/inkos/packages/studio/src/api/errors.ts +17 -0
- package/inkos/packages/studio/src/api/index.ts +30 -0
- package/inkos/packages/studio/src/api/lib/run-store.ts +177 -0
- package/inkos/packages/studio/src/api/lib/sse.ts +50 -0
- package/inkos/packages/studio/src/api/phase5-hotfix.test.ts +335 -0
- package/inkos/packages/studio/src/api/safety.ts +6 -0
- package/inkos/packages/studio/src/api/server.test.ts +3162 -0
- package/inkos/packages/studio/src/api/server.ts +3666 -0
- package/inkos/packages/studio/src/api/v13-hotfix-round4.test.ts +226 -0
- package/inkos/packages/studio/src/app-state.test.ts +8 -0
- package/inkos/packages/studio/src/app-state.ts +1 -0
- package/inkos/packages/studio/src/components/ConfirmDialog.tsx +95 -0
- package/inkos/packages/studio/src/components/ServiceConfigSourceCard.tsx +139 -0
- package/inkos/packages/studio/src/components/ServiceQuickLinks.tsx +65 -0
- package/inkos/packages/studio/src/components/Sidebar.tsx +652 -0
- package/inkos/packages/studio/src/components/ai-elements/code-block.tsx +562 -0
- package/inkos/packages/studio/src/components/ai-elements/confirmation.tsx +174 -0
- package/inkos/packages/studio/src/components/ai-elements/message.tsx +360 -0
- package/inkos/packages/studio/src/components/ai-elements/prompt-input.tsx +1457 -0
- package/inkos/packages/studio/src/components/ai-elements/reasoning.tsx +226 -0
- package/inkos/packages/studio/src/components/ai-elements/shimmer.tsx +77 -0
- package/inkos/packages/studio/src/components/ai-elements/tool.tsx +173 -0
- package/inkos/packages/studio/src/components/chat/BookSidebar.tsx +291 -0
- package/inkos/packages/studio/src/components/chat/ChatMessage.tsx +39 -0
- package/inkos/packages/studio/src/components/chat/QuickActions.tsx +73 -0
- package/inkos/packages/studio/src/components/chat/ToolExecutionSteps.tsx +320 -0
- package/inkos/packages/studio/src/components/chat/__tests__/ToolExecutionSteps.test.ts +114 -0
- package/inkos/packages/studio/src/components/chat-utils.ts +56 -0
- package/inkos/packages/studio/src/components/chatbar-state.test.ts +69 -0
- package/inkos/packages/studio/src/components/sidebar/ChaptersSection.tsx +66 -0
- package/inkos/packages/studio/src/components/sidebar/CharacterSection.tsx +129 -0
- package/inkos/packages/studio/src/components/sidebar/FoundationSection.tsx +61 -0
- package/inkos/packages/studio/src/components/sidebar/ProgressSection.tsx +124 -0
- package/inkos/packages/studio/src/components/sidebar/SidebarCard.tsx +30 -0
- package/inkos/packages/studio/src/components/sidebar/SummarySection.tsx +89 -0
- package/inkos/packages/studio/src/components/ui/alert.tsx +76 -0
- package/inkos/packages/studio/src/components/ui/badge.tsx +52 -0
- package/inkos/packages/studio/src/components/ui/button-group.tsx +87 -0
- package/inkos/packages/studio/src/components/ui/button.tsx +58 -0
- package/inkos/packages/studio/src/components/ui/collapsible.tsx +19 -0
- package/inkos/packages/studio/src/components/ui/command.tsx +194 -0
- package/inkos/packages/studio/src/components/ui/dialog.tsx +158 -0
- package/inkos/packages/studio/src/components/ui/dropdown-menu.tsx +266 -0
- package/inkos/packages/studio/src/components/ui/hover-card.tsx +51 -0
- package/inkos/packages/studio/src/components/ui/input-group.tsx +158 -0
- package/inkos/packages/studio/src/components/ui/input.tsx +20 -0
- package/inkos/packages/studio/src/components/ui/select.tsx +199 -0
- package/inkos/packages/studio/src/components/ui/separator.tsx +23 -0
- package/inkos/packages/studio/src/components/ui/spinner.tsx +10 -0
- package/inkos/packages/studio/src/components/ui/textarea.tsx +18 -0
- package/inkos/packages/studio/src/components/ui/tooltip.tsx +66 -0
- package/inkos/packages/studio/src/constants/service-groups.ts +29 -0
- package/inkos/packages/studio/src/hooks/use-api.test.ts +93 -0
- package/inkos/packages/studio/src/hooks/use-api.ts +189 -0
- package/inkos/packages/studio/src/hooks/use-book-activity.test.ts +129 -0
- package/inkos/packages/studio/src/hooks/use-book-activity.ts +180 -0
- package/inkos/packages/studio/src/hooks/use-colors.ts +27 -0
- package/inkos/packages/studio/src/hooks/use-hash-route.test.ts +101 -0
- package/inkos/packages/studio/src/hooks/use-hash-route.ts +89 -0
- package/inkos/packages/studio/src/hooks/use-i18n.ts +289 -0
- package/inkos/packages/studio/src/hooks/use-session-events.ts +64 -0
- package/inkos/packages/studio/src/hooks/use-sse.test.ts +52 -0
- package/inkos/packages/studio/src/hooks/use-sse.ts +92 -0
- package/inkos/packages/studio/src/hooks/use-theme.test.ts +31 -0
- package/inkos/packages/studio/src/hooks/use-theme.ts +75 -0
- package/inkos/packages/studio/src/index.css +323 -0
- package/inkos/packages/studio/src/lib/error-copy.test.ts +34 -0
- package/inkos/packages/studio/src/lib/error-copy.ts +37 -0
- package/inkos/packages/studio/src/lib/utils.ts +6 -0
- package/inkos/packages/studio/src/main.tsx +10 -0
- package/inkos/packages/studio/src/pages/Analytics.tsx +80 -0
- package/inkos/packages/studio/src/pages/BookCreate.tsx +895 -0
- package/inkos/packages/studio/src/pages/BookDetail.tsx +652 -0
- package/inkos/packages/studio/src/pages/ChapterReader.tsx +266 -0
- package/inkos/packages/studio/src/pages/ChatPage.tsx +521 -0
- package/inkos/packages/studio/src/pages/DaemonControl.tsx +116 -0
- package/inkos/packages/studio/src/pages/Dashboard.tsx +379 -0
- package/inkos/packages/studio/src/pages/DoctorView.tsx +82 -0
- package/inkos/packages/studio/src/pages/GenreManager.tsx +464 -0
- package/inkos/packages/studio/src/pages/ImportManager.tsx +216 -0
- package/inkos/packages/studio/src/pages/LanguageSelector.tsx +74 -0
- package/inkos/packages/studio/src/pages/LogViewer.tsx +82 -0
- package/inkos/packages/studio/src/pages/RadarView.tsx +157 -0
- package/inkos/packages/studio/src/pages/ServiceDetailPage.tsx +393 -0
- package/inkos/packages/studio/src/pages/ServiceListPage.tsx +463 -0
- package/inkos/packages/studio/src/pages/StyleManager.tsx +225 -0
- package/inkos/packages/studio/src/pages/TruthFiles.tsx +194 -0
- package/inkos/packages/studio/src/pages/chat-page-state.test.ts +206 -0
- package/inkos/packages/studio/src/pages/chat-page-state.ts +112 -0
- package/inkos/packages/studio/src/pages/page-state.test.ts +258 -0
- package/inkos/packages/studio/src/pages/service-detail-state.test.ts +294 -0
- package/inkos/packages/studio/src/pages/service-detail-state.ts +234 -0
- package/inkos/packages/studio/src/pages/style-manager-state.test.ts +22 -0
- package/inkos/packages/studio/src/pages/truth-files-state.test.ts +61 -0
- package/inkos/packages/studio/src/shared/contracts.ts +143 -0
- package/inkos/packages/studio/src/store/chat/__tests__/message-parts.test.ts +172 -0
- package/inkos/packages/studio/src/store/chat/index.ts +3 -0
- package/inkos/packages/studio/src/store/chat/initialState.ts +8 -0
- package/inkos/packages/studio/src/store/chat/message-policy.test.ts +16 -0
- package/inkos/packages/studio/src/store/chat/message-policy.ts +5 -0
- package/inkos/packages/studio/src/store/chat/parts-builder.ts +187 -0
- package/inkos/packages/studio/src/store/chat/selectors.ts +13 -0
- package/inkos/packages/studio/src/store/chat/slices/create/action.ts +10 -0
- package/inkos/packages/studio/src/store/chat/slices/create/initialState.ts +9 -0
- package/inkos/packages/studio/src/store/chat/slices/message/action.ts +417 -0
- package/inkos/packages/studio/src/store/chat/slices/message/initialState.ts +10 -0
- package/inkos/packages/studio/src/store/chat/slices/message/runtime.test.ts +21 -0
- package/inkos/packages/studio/src/store/chat/slices/message/runtime.ts +233 -0
- package/inkos/packages/studio/src/store/chat/slices/message/stream-events.ts +272 -0
- package/inkos/packages/studio/src/store/chat/store.ts +11 -0
- package/inkos/packages/studio/src/store/chat/types.ts +169 -0
- package/inkos/packages/studio/src/store/service/index.ts +2 -0
- package/inkos/packages/studio/src/store/service/store.ts +123 -0
- package/inkos/packages/studio/src/store/service/types.ts +50 -0
- package/inkos/packages/studio/tsconfig.json +24 -0
- package/inkos/packages/studio/tsconfig.server.json +11 -0
- package/inkos/packages/studio/vite.config.ts +34 -0
- package/inkos/packages/studio/vitest.config.ts +14 -0
- package/inkos/pnpm-lock.yaml +9569 -0
- package/inkos/pnpm-workspace.yaml +2 -0
- package/inkos/scripts/prepare-package-for-publish.mjs +135 -0
- package/inkos/scripts/restore-package-json.mjs +31 -0
- package/inkos/scripts/set-package-versions.mjs +74 -0
- package/inkos/scripts/verify-no-workspace-protocol.mjs +140 -0
- package/inkos/skills/SKILL.md +654 -0
- package/inkos/tsconfig.json +19 -0
- package/package.json +4 -3
- /package/.next/static/{F2hMZMf1IyCVAWpkbtRz7 → -3vIrBZXdQ0rp7Wa3Kz40}/_buildManifest.js +0 -0
- /package/.next/static/{F2hMZMf1IyCVAWpkbtRz7 → -3vIrBZXdQ0rp7Wa3Kz40}/_ssgManifest.js +0 -0
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
Message,
|
|
3
|
+
MessagePart,
|
|
4
|
+
PipelineStage,
|
|
5
|
+
SessionMessage,
|
|
6
|
+
SessionRuntime,
|
|
7
|
+
SessionSummary,
|
|
8
|
+
ToolExecution,
|
|
9
|
+
} from "../../types";
|
|
10
|
+
import { localizeKnownRuntimeMessage } from "../../../../lib/error-copy";
|
|
11
|
+
|
|
12
|
+
const NULL_BOOK_KEY = "__null__";
|
|
13
|
+
|
|
14
|
+
const AGENT_LABELS: Record<string, string> = {
|
|
15
|
+
architect: "建书",
|
|
16
|
+
writer: "写作",
|
|
17
|
+
auditor: "审计",
|
|
18
|
+
reviser: "修订",
|
|
19
|
+
exporter: "导出",
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const TOOL_LABELS: Record<string, string> = {
|
|
23
|
+
read: "读取文件",
|
|
24
|
+
edit: "编辑文件",
|
|
25
|
+
grep: "搜索",
|
|
26
|
+
ls: "列目录",
|
|
27
|
+
short_fiction_run: "短篇生产",
|
|
28
|
+
generate_cover: "生成封面",
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export function bookKey(bookId: string | null | undefined): string {
|
|
32
|
+
return bookId ?? NULL_BOOK_KEY;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function extractErrorMessage(error: string | { code?: string; message?: string }): string {
|
|
36
|
+
if (typeof error === "string") return localizeKnownRuntimeMessage(error);
|
|
37
|
+
return localizeKnownRuntimeMessage(error.message ?? "Unknown error");
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function resolveToolLabel(tool: string, agent?: string): string {
|
|
41
|
+
if (tool === "sub_agent" && agent) return AGENT_LABELS[agent] ?? agent;
|
|
42
|
+
return TOOL_LABELS[tool] ?? tool;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function summarizeResult(result: unknown): string {
|
|
46
|
+
if (typeof result === "string") return result.slice(0, 2000);
|
|
47
|
+
if (result && typeof result === "object") {
|
|
48
|
+
const record = result as Record<string, unknown>;
|
|
49
|
+
if (typeof record.content === "string") return record.content.slice(0, 2000);
|
|
50
|
+
if (Array.isArray(record.content)) {
|
|
51
|
+
const text = record.content
|
|
52
|
+
.map((part) => {
|
|
53
|
+
const item = part as { type?: unknown; text?: unknown };
|
|
54
|
+
return item.type === "text" && typeof item.text === "string" ? item.text : "";
|
|
55
|
+
})
|
|
56
|
+
.filter(Boolean)
|
|
57
|
+
.join("\n");
|
|
58
|
+
if (text.trim()) return text.slice(0, 2000);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return String(result).slice(0, 2000);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export function extractToolDetails(result: unknown): unknown {
|
|
65
|
+
if (!result || typeof result !== "object") return undefined;
|
|
66
|
+
return (result as Record<string, unknown>).details;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export function extractToolError(result: unknown): string {
|
|
70
|
+
if (typeof result === "string") return localizeKnownRuntimeMessage(result).slice(0, 500);
|
|
71
|
+
if (result && typeof result === "object") {
|
|
72
|
+
const record = result as Record<string, unknown>;
|
|
73
|
+
if (typeof record.content === "string") return localizeKnownRuntimeMessage(record.content).slice(0, 500);
|
|
74
|
+
if (record.content && Array.isArray(record.content)) {
|
|
75
|
+
const textPart = record.content.find((content: any) => content.type === "text");
|
|
76
|
+
if (textPart) return localizeKnownRuntimeMessage((textPart as any).text ?? "").slice(0, 500);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return localizeKnownRuntimeMessage(String(result)).slice(0, 500);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export function getOrCreateStream(
|
|
83
|
+
messages: ReadonlyArray<Message>,
|
|
84
|
+
streamTs: number,
|
|
85
|
+
): [ReadonlyArray<Message>, Message] {
|
|
86
|
+
const last = messages[messages.length - 1];
|
|
87
|
+
if (last?.timestamp === streamTs && last.role === "assistant") {
|
|
88
|
+
return [messages, last];
|
|
89
|
+
}
|
|
90
|
+
const message: Message = { role: "assistant", content: "", timestamp: streamTs, parts: [] };
|
|
91
|
+
return [[...messages, message], message];
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export function replaceLast(
|
|
95
|
+
messages: ReadonlyArray<Message>,
|
|
96
|
+
updated: Message,
|
|
97
|
+
): ReadonlyArray<Message> {
|
|
98
|
+
return [...messages.slice(0, -1), updated];
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export function findRunningToolPart(
|
|
102
|
+
parts: MessagePart[],
|
|
103
|
+
): (MessagePart & { type: "tool" }) | undefined {
|
|
104
|
+
for (let i = parts.length - 1; i >= 0; i -= 1) {
|
|
105
|
+
const part = parts[i];
|
|
106
|
+
if (part.type === "tool" && part.execution.status === "running") {
|
|
107
|
+
return part as MessagePart & { type: "tool" };
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return undefined;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export function deriveFlat(
|
|
114
|
+
parts: MessagePart[],
|
|
115
|
+
): { content: string; thinking?: string; thinkingStreaming?: boolean; toolExecutions?: ToolExecution[] } {
|
|
116
|
+
let content = "";
|
|
117
|
+
let thinking = "";
|
|
118
|
+
let thinkingStreaming = false;
|
|
119
|
+
const toolExecutions: ToolExecution[] = [];
|
|
120
|
+
|
|
121
|
+
for (const part of parts) {
|
|
122
|
+
if (part.type === "thinking") {
|
|
123
|
+
if (thinking) thinking += "\n\n---\n\n";
|
|
124
|
+
thinking += part.content;
|
|
125
|
+
if (part.streaming) thinkingStreaming = true;
|
|
126
|
+
continue;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
if (part.type === "text") {
|
|
130
|
+
content += part.content;
|
|
131
|
+
continue;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
toolExecutions.push(part.execution);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
return {
|
|
138
|
+
content,
|
|
139
|
+
...(thinking ? { thinking } : {}),
|
|
140
|
+
...(thinkingStreaming ? { thinkingStreaming: true } : {}),
|
|
141
|
+
...(toolExecutions.length > 0 ? { toolExecutions } : {}),
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export function createSessionRuntime(input: {
|
|
146
|
+
sessionId: string;
|
|
147
|
+
bookId: string | null;
|
|
148
|
+
title: string | null;
|
|
149
|
+
messages?: ReadonlyArray<Message>;
|
|
150
|
+
isDraft?: boolean;
|
|
151
|
+
}): SessionRuntime {
|
|
152
|
+
return {
|
|
153
|
+
sessionId: input.sessionId,
|
|
154
|
+
bookId: input.bookId,
|
|
155
|
+
title: input.title,
|
|
156
|
+
messages: input.messages ?? [],
|
|
157
|
+
stream: null,
|
|
158
|
+
isStreaming: false,
|
|
159
|
+
lastError: null,
|
|
160
|
+
isDraft: input.isDraft ?? false,
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
export function deserializeMessages(
|
|
165
|
+
msgs: ReadonlyArray<SessionMessage>,
|
|
166
|
+
): ReadonlyArray<Message> {
|
|
167
|
+
return msgs
|
|
168
|
+
.filter((message) => message.role === "user" || message.role === "assistant")
|
|
169
|
+
.map((message) => {
|
|
170
|
+
const toolExecutions = (message as any).toolExecutions as ToolExecution[] | undefined;
|
|
171
|
+
const parts: MessagePart[] = [];
|
|
172
|
+
if (message.thinking) parts.push({ type: "thinking", content: message.thinking, streaming: false });
|
|
173
|
+
if (toolExecutions) {
|
|
174
|
+
for (const execution of toolExecutions) {
|
|
175
|
+
parts.push({ type: "tool", execution });
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
if (message.content) parts.push({ type: "text", content: message.content });
|
|
179
|
+
return {
|
|
180
|
+
role: message.role as "user" | "assistant",
|
|
181
|
+
content: message.content,
|
|
182
|
+
thinking: message.thinking,
|
|
183
|
+
toolExecutions,
|
|
184
|
+
timestamp: message.timestamp,
|
|
185
|
+
parts: parts.length > 0 ? parts : undefined,
|
|
186
|
+
};
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
export function updateSession(
|
|
191
|
+
sessions: Record<string, SessionRuntime>,
|
|
192
|
+
sessionId: string,
|
|
193
|
+
updater: (session: SessionRuntime) => Partial<SessionRuntime>,
|
|
194
|
+
): Record<string, SessionRuntime> {
|
|
195
|
+
const existing = sessions[sessionId];
|
|
196
|
+
if (!existing) return sessions;
|
|
197
|
+
return {
|
|
198
|
+
...sessions,
|
|
199
|
+
[sessionId]: {
|
|
200
|
+
...existing,
|
|
201
|
+
...updater(existing),
|
|
202
|
+
},
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
export function upsertSessionSummary(
|
|
207
|
+
sessions: Record<string, SessionRuntime>,
|
|
208
|
+
summary: Pick<SessionSummary, "sessionId" | "bookId" | "title">,
|
|
209
|
+
): Record<string, SessionRuntime> {
|
|
210
|
+
const existing = sessions[summary.sessionId];
|
|
211
|
+
return {
|
|
212
|
+
...sessions,
|
|
213
|
+
[summary.sessionId]: existing
|
|
214
|
+
? { ...existing, bookId: summary.bookId, title: summary.title }
|
|
215
|
+
: createSessionRuntime(summary),
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
export function mergeSessionIds(
|
|
220
|
+
existing: ReadonlyArray<string> | undefined,
|
|
221
|
+
incoming: ReadonlyArray<string>,
|
|
222
|
+
): ReadonlyArray<string> {
|
|
223
|
+
if (!existing?.length) return [...incoming];
|
|
224
|
+
const seen = new Set(existing);
|
|
225
|
+
const appended = incoming.filter((id) => !seen.has(id));
|
|
226
|
+
if (appended.length === 0) return existing as string[];
|
|
227
|
+
return [...existing, ...appended];
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
export function sessionMatchesEvent(sessionId: string, data: unknown): boolean {
|
|
231
|
+
if (!data || typeof data !== "object") return false;
|
|
232
|
+
return (data as { sessionId?: unknown }).sessionId === sessionId;
|
|
233
|
+
}
|
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
import type { StateCreator } from "zustand";
|
|
2
|
+
import type { ChatStore, MessageActions, PipelineStage } from "../../types";
|
|
3
|
+
import { shouldRefreshSidebarForTool } from "../../message-policy";
|
|
4
|
+
import {
|
|
5
|
+
deriveFlat,
|
|
6
|
+
extractToolDetails,
|
|
7
|
+
extractToolError,
|
|
8
|
+
findRunningToolPart,
|
|
9
|
+
getOrCreateStream,
|
|
10
|
+
replaceLast,
|
|
11
|
+
resolveToolLabel,
|
|
12
|
+
sessionMatchesEvent,
|
|
13
|
+
summarizeResult,
|
|
14
|
+
updateSession,
|
|
15
|
+
} from "./runtime";
|
|
16
|
+
|
|
17
|
+
type SliceSet = Parameters<StateCreator<ChatStore, [], [], MessageActions>>[0];
|
|
18
|
+
type SliceGet = Parameters<StateCreator<ChatStore, [], [], MessageActions>>[1];
|
|
19
|
+
|
|
20
|
+
interface AttachSessionStreamListenersInput {
|
|
21
|
+
sessionId: string;
|
|
22
|
+
streamTs: number;
|
|
23
|
+
streamEs: EventSource;
|
|
24
|
+
set: SliceSet;
|
|
25
|
+
get: SliceGet;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function attachSessionStreamListeners({
|
|
29
|
+
sessionId,
|
|
30
|
+
streamTs,
|
|
31
|
+
streamEs,
|
|
32
|
+
set,
|
|
33
|
+
get,
|
|
34
|
+
}: AttachSessionStreamListenersInput): void {
|
|
35
|
+
streamEs.addEventListener("thinking:start", (event: MessageEvent) => {
|
|
36
|
+
try {
|
|
37
|
+
const data = event.data ? JSON.parse(event.data) : null;
|
|
38
|
+
if (!sessionMatchesEvent(sessionId, data)) return;
|
|
39
|
+
set((state) => ({
|
|
40
|
+
sessions: updateSession(state.sessions, sessionId, (runtime) => {
|
|
41
|
+
const [messages, stream] = getOrCreateStream(runtime.messages, streamTs);
|
|
42
|
+
const parts = [...(stream.parts ?? []), { type: "thinking" as const, content: "", streaming: true }];
|
|
43
|
+
const flat = deriveFlat(parts);
|
|
44
|
+
return { messages: replaceLast(messages, { ...stream, ...flat, parts }) };
|
|
45
|
+
}),
|
|
46
|
+
}));
|
|
47
|
+
} catch {
|
|
48
|
+
// ignore
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
streamEs.addEventListener("thinking:delta", (event: MessageEvent) => {
|
|
53
|
+
try {
|
|
54
|
+
const data = event.data ? JSON.parse(event.data) : null;
|
|
55
|
+
if (!sessionMatchesEvent(sessionId, data) || !data?.text) return;
|
|
56
|
+
set((state) => ({
|
|
57
|
+
sessions: updateSession(state.sessions, sessionId, (runtime) => {
|
|
58
|
+
const [messages, stream] = getOrCreateStream(runtime.messages, streamTs);
|
|
59
|
+
const parts = [...(stream.parts ?? [])];
|
|
60
|
+
const last = parts[parts.length - 1];
|
|
61
|
+
if (last?.type === "thinking") {
|
|
62
|
+
parts[parts.length - 1] = { ...last, content: last.content + data.text };
|
|
63
|
+
}
|
|
64
|
+
const flat = deriveFlat(parts);
|
|
65
|
+
return { messages: replaceLast(messages, { ...stream, ...flat, parts }) };
|
|
66
|
+
}),
|
|
67
|
+
}));
|
|
68
|
+
} catch {
|
|
69
|
+
// ignore
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
streamEs.addEventListener("thinking:end", (event: MessageEvent) => {
|
|
74
|
+
try {
|
|
75
|
+
const data = event.data ? JSON.parse(event.data) : null;
|
|
76
|
+
if (!sessionMatchesEvent(sessionId, data)) return;
|
|
77
|
+
set((state) => ({
|
|
78
|
+
sessions: updateSession(state.sessions, sessionId, (runtime) => {
|
|
79
|
+
const [messages, stream] = getOrCreateStream(runtime.messages, streamTs);
|
|
80
|
+
const parts = [...(stream.parts ?? [])];
|
|
81
|
+
const last = parts[parts.length - 1];
|
|
82
|
+
if (last?.type === "thinking") {
|
|
83
|
+
parts[parts.length - 1] = { ...last, streaming: false };
|
|
84
|
+
}
|
|
85
|
+
const flat = deriveFlat(parts);
|
|
86
|
+
return { messages: replaceLast(messages, { ...stream, ...flat, parts }) };
|
|
87
|
+
}),
|
|
88
|
+
}));
|
|
89
|
+
} catch {
|
|
90
|
+
// ignore
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
streamEs.addEventListener("draft:delta", (event: MessageEvent) => {
|
|
95
|
+
try {
|
|
96
|
+
const data = event.data ? JSON.parse(event.data) : null;
|
|
97
|
+
if (!sessionMatchesEvent(sessionId, data) || !data?.text) return;
|
|
98
|
+
set((state) => ({
|
|
99
|
+
sessions: updateSession(state.sessions, sessionId, (runtime) => {
|
|
100
|
+
const [messages, stream] = getOrCreateStream(runtime.messages, streamTs);
|
|
101
|
+
const parts = [...(stream.parts ?? [])];
|
|
102
|
+
const last = parts[parts.length - 1];
|
|
103
|
+
if (last?.type === "text") {
|
|
104
|
+
parts[parts.length - 1] = { ...last, content: last.content + data.text };
|
|
105
|
+
} else {
|
|
106
|
+
parts.push({ type: "text", content: data.text });
|
|
107
|
+
}
|
|
108
|
+
const flat = deriveFlat(parts);
|
|
109
|
+
return { messages: replaceLast(messages, { ...stream, ...flat, parts }) };
|
|
110
|
+
}),
|
|
111
|
+
}));
|
|
112
|
+
} catch {
|
|
113
|
+
// ignore
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
streamEs.addEventListener("tool:start", (event: MessageEvent) => {
|
|
118
|
+
try {
|
|
119
|
+
const data = event.data ? JSON.parse(event.data) : null;
|
|
120
|
+
if (!sessionMatchesEvent(sessionId, data) || !data?.tool) return;
|
|
121
|
+
set((state) => ({
|
|
122
|
+
sessions: updateSession(state.sessions, sessionId, (runtime) => {
|
|
123
|
+
const [messages, stream] = getOrCreateStream(runtime.messages, streamTs);
|
|
124
|
+
const parts = [...(stream.parts ?? [])];
|
|
125
|
+
|
|
126
|
+
if (data.tool === "sub_agent") {
|
|
127
|
+
const last = parts[parts.length - 1];
|
|
128
|
+
if (last?.type === "text" && last.content) {
|
|
129
|
+
parts.pop();
|
|
130
|
+
const prev = parts[parts.length - 1];
|
|
131
|
+
if (prev?.type === "thinking") {
|
|
132
|
+
parts[parts.length - 1] = {
|
|
133
|
+
...prev,
|
|
134
|
+
content: prev.content + (prev.content ? "\n\n" : "") + last.content,
|
|
135
|
+
};
|
|
136
|
+
} else {
|
|
137
|
+
parts.push({ type: "thinking", content: last.content, streaming: false });
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
const agent = data.tool === "sub_agent" ? (data.args?.agent as string | undefined) : undefined;
|
|
143
|
+
const stages: PipelineStage[] | undefined = Array.isArray(data.stages) && data.stages.length > 0
|
|
144
|
+
? (data.stages as string[]).map((label) => ({ label, status: "pending" as const }))
|
|
145
|
+
: undefined;
|
|
146
|
+
|
|
147
|
+
parts.push({
|
|
148
|
+
type: "tool",
|
|
149
|
+
execution: {
|
|
150
|
+
id: data.id as string,
|
|
151
|
+
tool: data.tool as string,
|
|
152
|
+
agent,
|
|
153
|
+
label: resolveToolLabel(data.tool as string, agent),
|
|
154
|
+
status: "running",
|
|
155
|
+
args: data.args as Record<string, unknown> | undefined,
|
|
156
|
+
stages,
|
|
157
|
+
startedAt: Date.now(),
|
|
158
|
+
},
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
const flat = deriveFlat(parts);
|
|
162
|
+
return { messages: replaceLast(messages, { ...stream, ...flat, parts }) };
|
|
163
|
+
}),
|
|
164
|
+
}));
|
|
165
|
+
} catch {
|
|
166
|
+
// ignore
|
|
167
|
+
}
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
streamEs.addEventListener("tool:end", (event: MessageEvent) => {
|
|
171
|
+
try {
|
|
172
|
+
const data = event.data ? JSON.parse(event.data) : null;
|
|
173
|
+
if (!sessionMatchesEvent(sessionId, data) || !data?.tool) return;
|
|
174
|
+
set((state) => ({
|
|
175
|
+
sessions: updateSession(state.sessions, sessionId, (runtime) => {
|
|
176
|
+
const [messages, stream] = getOrCreateStream(runtime.messages, streamTs);
|
|
177
|
+
const parts = (stream.parts ?? []).map((part) => {
|
|
178
|
+
if (part.type !== "tool" || part.execution.id !== data.id) return part;
|
|
179
|
+
const execution = { ...part.execution };
|
|
180
|
+
execution.status = data.isError ? "error" : "completed";
|
|
181
|
+
execution.completedAt = Date.now();
|
|
182
|
+
execution.stages = execution.stages?.map((stage) =>
|
|
183
|
+
stage.status !== "completed"
|
|
184
|
+
? { ...stage, status: "completed" as const, progress: undefined }
|
|
185
|
+
: stage,
|
|
186
|
+
);
|
|
187
|
+
if (data.isError) execution.error = extractToolError(data.result);
|
|
188
|
+
else execution.result = summarizeResult(data.result);
|
|
189
|
+
const details = data.details ?? extractToolDetails(data.result);
|
|
190
|
+
if (details !== undefined) execution.details = details;
|
|
191
|
+
return { type: "tool" as const, execution };
|
|
192
|
+
});
|
|
193
|
+
const flat = deriveFlat(parts);
|
|
194
|
+
return { messages: replaceLast(messages, { ...stream, ...flat, parts }) };
|
|
195
|
+
}),
|
|
196
|
+
}));
|
|
197
|
+
|
|
198
|
+
if (shouldRefreshSidebarForTool(data.tool as string)) {
|
|
199
|
+
get().bumpBookDataVersion();
|
|
200
|
+
}
|
|
201
|
+
} catch {
|
|
202
|
+
// ignore
|
|
203
|
+
}
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
streamEs.addEventListener("log", (event: MessageEvent) => {
|
|
207
|
+
try {
|
|
208
|
+
const data = event.data ? JSON.parse(event.data) : null;
|
|
209
|
+
if (!sessionMatchesEvent(sessionId, data)) return;
|
|
210
|
+
const message = data?.message as string | undefined;
|
|
211
|
+
if (!message) return;
|
|
212
|
+
set((state) => ({
|
|
213
|
+
sessions: updateSession(state.sessions, sessionId, (runtime) => {
|
|
214
|
+
const [messages, stream] = getOrCreateStream(runtime.messages, streamTs);
|
|
215
|
+
const runningTool = findRunningToolPart([...(stream.parts ?? [])]);
|
|
216
|
+
if (!runningTool) return {};
|
|
217
|
+
const parts = (stream.parts ?? []).map((part) => {
|
|
218
|
+
if (part.type !== "tool" || part.execution.id !== runningTool.execution.id) return part;
|
|
219
|
+
return {
|
|
220
|
+
type: "tool" as const,
|
|
221
|
+
execution: { ...part.execution, logs: [...(part.execution.logs ?? []), message] },
|
|
222
|
+
};
|
|
223
|
+
});
|
|
224
|
+
const flat = deriveFlat(parts);
|
|
225
|
+
return { messages: replaceLast(messages, { ...stream, ...flat, parts }) };
|
|
226
|
+
}),
|
|
227
|
+
}));
|
|
228
|
+
} catch {
|
|
229
|
+
// ignore
|
|
230
|
+
}
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
streamEs.addEventListener("llm:progress", (event: MessageEvent) => {
|
|
234
|
+
try {
|
|
235
|
+
const data = event.data ? JSON.parse(event.data) : null;
|
|
236
|
+
if (!sessionMatchesEvent(sessionId, data)) return;
|
|
237
|
+
set((state) => ({
|
|
238
|
+
sessions: updateSession(state.sessions, sessionId, (runtime) => {
|
|
239
|
+
const [messages, stream] = getOrCreateStream(runtime.messages, streamTs);
|
|
240
|
+
const runningTool = findRunningToolPart([...(stream.parts ?? [])]);
|
|
241
|
+
if (!runningTool?.execution.stages) return {};
|
|
242
|
+
const parts = (stream.parts ?? []).map((part) => {
|
|
243
|
+
if (part.type !== "tool" || part.execution.id !== runningTool.execution.id) return part;
|
|
244
|
+
return {
|
|
245
|
+
type: "tool" as const,
|
|
246
|
+
execution: {
|
|
247
|
+
...part.execution,
|
|
248
|
+
stages: part.execution.stages?.map((stage) =>
|
|
249
|
+
stage.status === "active"
|
|
250
|
+
? {
|
|
251
|
+
...stage,
|
|
252
|
+
progress: {
|
|
253
|
+
status: data.status,
|
|
254
|
+
elapsedMs: data.elapsedMs,
|
|
255
|
+
totalChars: data.totalChars,
|
|
256
|
+
chineseChars: data.chineseChars,
|
|
257
|
+
},
|
|
258
|
+
}
|
|
259
|
+
: stage,
|
|
260
|
+
),
|
|
261
|
+
},
|
|
262
|
+
};
|
|
263
|
+
});
|
|
264
|
+
const flat = deriveFlat(parts);
|
|
265
|
+
return { messages: replaceLast(messages, { ...stream, ...flat, parts }) };
|
|
266
|
+
}),
|
|
267
|
+
}));
|
|
268
|
+
} catch {
|
|
269
|
+
// ignore
|
|
270
|
+
}
|
|
271
|
+
});
|
|
272
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { create } from "zustand";
|
|
2
|
+
import type { ChatStore } from "./types";
|
|
3
|
+
import { initialChatState } from "./initialState";
|
|
4
|
+
import { createMessageSlice } from "./slices/message/action";
|
|
5
|
+
import { createCreateSlice } from "./slices/create/action";
|
|
6
|
+
|
|
7
|
+
export const useChatStore = create<ChatStore>()((...a) => ({
|
|
8
|
+
...initialChatState,
|
|
9
|
+
...createMessageSlice(...a),
|
|
10
|
+
...createCreateSlice(...a),
|
|
11
|
+
}));
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
// -- Data types --
|
|
2
|
+
|
|
3
|
+
export interface ToolCall {
|
|
4
|
+
readonly name: string;
|
|
5
|
+
readonly arguments: Record<string, unknown>;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export interface PipelineStage {
|
|
9
|
+
label: string;
|
|
10
|
+
status: "pending" | "active" | "completed";
|
|
11
|
+
progress?: {
|
|
12
|
+
status?: string; // "thinking" | "streaming" | ...
|
|
13
|
+
elapsedMs: number;
|
|
14
|
+
totalChars: number;
|
|
15
|
+
chineseChars: number;
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface ToolExecution {
|
|
20
|
+
id: string;
|
|
21
|
+
tool: string;
|
|
22
|
+
agent?: string;
|
|
23
|
+
label: string;
|
|
24
|
+
status: "running" | "processing" | "completed" | "error";
|
|
25
|
+
args?: Record<string, unknown>;
|
|
26
|
+
result?: string;
|
|
27
|
+
details?: unknown;
|
|
28
|
+
error?: string;
|
|
29
|
+
stages?: PipelineStage[];
|
|
30
|
+
logs?: string[];
|
|
31
|
+
startedAt: number;
|
|
32
|
+
completedAt?: number;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// -- Message parts (chronologically ordered for rendering) --
|
|
36
|
+
|
|
37
|
+
export type MessagePart =
|
|
38
|
+
| { type: "thinking"; content: string; streaming: boolean }
|
|
39
|
+
| { type: "text"; content: string }
|
|
40
|
+
| { type: "tool"; execution: ToolExecution };
|
|
41
|
+
|
|
42
|
+
export interface Message {
|
|
43
|
+
readonly role: "user" | "assistant";
|
|
44
|
+
readonly content: string;
|
|
45
|
+
readonly thinking?: string;
|
|
46
|
+
readonly thinkingStreaming?: boolean;
|
|
47
|
+
readonly timestamp: number;
|
|
48
|
+
readonly toolCall?: ToolCall;
|
|
49
|
+
readonly toolExecutions?: ToolExecution[];
|
|
50
|
+
readonly parts?: MessagePart[]; // chronological parts for interleaved rendering
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export interface SessionMessage {
|
|
54
|
+
readonly role: "user" | "assistant" | "system";
|
|
55
|
+
readonly content: string;
|
|
56
|
+
readonly thinking?: string;
|
|
57
|
+
readonly toolExecutions?: ReadonlyArray<ToolExecution>;
|
|
58
|
+
readonly timestamp: number;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export interface SessionSummary {
|
|
62
|
+
readonly sessionId: string;
|
|
63
|
+
readonly bookId: string | null;
|
|
64
|
+
readonly title: string | null;
|
|
65
|
+
readonly messageCount: number;
|
|
66
|
+
readonly createdAt: number;
|
|
67
|
+
readonly updatedAt: number;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export interface AgentResponse {
|
|
71
|
+
readonly response?: string;
|
|
72
|
+
readonly error?: string | { code?: string; message?: string };
|
|
73
|
+
readonly details?: {
|
|
74
|
+
readonly draftRaw?: string;
|
|
75
|
+
readonly toolCall?: ToolCall;
|
|
76
|
+
};
|
|
77
|
+
readonly session?: {
|
|
78
|
+
readonly sessionId?: string;
|
|
79
|
+
readonly bookId?: string | null;
|
|
80
|
+
readonly title?: string | null;
|
|
81
|
+
readonly activeBookId?: string;
|
|
82
|
+
readonly creationDraft?: unknown;
|
|
83
|
+
readonly messages?: ReadonlyArray<SessionMessage>;
|
|
84
|
+
};
|
|
85
|
+
readonly request?: unknown;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export interface SessionResponse {
|
|
89
|
+
readonly session?: {
|
|
90
|
+
readonly sessionId?: string;
|
|
91
|
+
readonly bookId?: string | null;
|
|
92
|
+
readonly title?: string | null;
|
|
93
|
+
readonly activeBookId?: string;
|
|
94
|
+
readonly messages?: ReadonlyArray<SessionMessage>;
|
|
95
|
+
};
|
|
96
|
+
readonly activeBookId?: string;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// -- State interfaces --
|
|
100
|
+
|
|
101
|
+
export interface BookSummary {
|
|
102
|
+
world: string;
|
|
103
|
+
protagonist: string;
|
|
104
|
+
cast: string;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export interface SessionRuntime {
|
|
108
|
+
readonly sessionId: string;
|
|
109
|
+
readonly bookId: string | null;
|
|
110
|
+
readonly title: string | null;
|
|
111
|
+
readonly messages: ReadonlyArray<Message>;
|
|
112
|
+
readonly stream: EventSource | null;
|
|
113
|
+
readonly isStreaming: boolean;
|
|
114
|
+
readonly lastError: string | null;
|
|
115
|
+
// 仅前端存在、尚未持久化到磁盘的草稿会话。发送第一条消息时才调 POST /sessions 把它落盘。
|
|
116
|
+
readonly isDraft: boolean;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export interface MessageState {
|
|
120
|
+
sessions: Record<string, SessionRuntime>;
|
|
121
|
+
sessionIdsByBook: Record<string, ReadonlyArray<string>>;
|
|
122
|
+
activeSessionId: string | null;
|
|
123
|
+
input: string;
|
|
124
|
+
selectedModel: string | null;
|
|
125
|
+
selectedService: string | null;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export interface CreateState {
|
|
129
|
+
bookDataVersion: number;
|
|
130
|
+
sidebarView: "panel" | "artifact";
|
|
131
|
+
artifactFile: string | null; // foundation file name, e.g. "story_bible.md"
|
|
132
|
+
artifactChapter: number | null; // chapter number, e.g. 1
|
|
133
|
+
bookSummary: BookSummary | null;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
export type ChatState = MessageState & CreateState;
|
|
137
|
+
|
|
138
|
+
// -- Action interfaces --
|
|
139
|
+
|
|
140
|
+
export interface MessageActions {
|
|
141
|
+
activateSession: (sessionId: string | null) => void;
|
|
142
|
+
setInput: (text: string) => void;
|
|
143
|
+
addUserMessage: (sessionId: string, content: string) => void;
|
|
144
|
+
appendStreamChunk: (sessionId: string, text: string, streamTs: number) => void;
|
|
145
|
+
finalizeStream: (sessionId: string, streamTs: number, content: string, toolCall?: ToolCall) => void;
|
|
146
|
+
replaceStreamWithError: (sessionId: string, streamTs: number, errorMsg: string) => void;
|
|
147
|
+
addErrorMessage: (sessionId: string, errorMsg: string) => void;
|
|
148
|
+
loadSessionMessages: (sessionId: string, msgs: ReadonlyArray<SessionMessage>) => void;
|
|
149
|
+
loadSessionList: (bookId: string | null) => Promise<ReadonlyArray<SessionSummary>>;
|
|
150
|
+
createSession: (bookId: string | null) => Promise<string>;
|
|
151
|
+
createDraftSession: (bookId: string | null) => string;
|
|
152
|
+
renameSession: (sessionId: string, title: string) => Promise<void>;
|
|
153
|
+
deleteSession: (sessionId: string) => Promise<void>;
|
|
154
|
+
loadSessionDetail: (sessionId: string) => Promise<void>;
|
|
155
|
+
sendMessage: (sessionId: string, text: string, activeBookId?: string) => Promise<void>;
|
|
156
|
+
setSelectedModel: (model: string, service: string) => void;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
export interface CreateActions {
|
|
160
|
+
bumpBookDataVersion: () => void;
|
|
161
|
+
openArtifact: (file: string) => void;
|
|
162
|
+
openChapterArtifact: (chapterNum: number) => void;
|
|
163
|
+
closeArtifact: () => void;
|
|
164
|
+
setBookSummary: (summary: BookSummary | null) => void;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// -- Composed store type --
|
|
168
|
+
|
|
169
|
+
export type ChatStore = ChatState & MessageActions & CreateActions;
|