@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,1167 @@
|
|
|
1
|
+
import type { AutomationMode } from "./modes.js";
|
|
2
|
+
import { routeInteractionRequest } from "./request-router.js";
|
|
3
|
+
import type { InteractionRequest } from "./intents.js";
|
|
4
|
+
import type { ExecutionState, InteractionEvent } from "./events.js";
|
|
5
|
+
import type { PendingDecision, InteractionSession, DraftRound } from "./session.js";
|
|
6
|
+
import {
|
|
7
|
+
appendInteractionEvent,
|
|
8
|
+
bindActiveBook,
|
|
9
|
+
clearCreationDraft,
|
|
10
|
+
clearPendingDecision,
|
|
11
|
+
updateCreationDraft,
|
|
12
|
+
updateAutomationMode,
|
|
13
|
+
} from "./session.js";
|
|
14
|
+
|
|
15
|
+
type ReviseMode = "local-fix" | "rewrite";
|
|
16
|
+
type RuntimeLanguage = "zh" | "en";
|
|
17
|
+
|
|
18
|
+
export interface InteractionRuntimeTools {
|
|
19
|
+
readonly listBooks: () => Promise<ReadonlyArray<string>>;
|
|
20
|
+
readonly developBookDraft?: (
|
|
21
|
+
input: string,
|
|
22
|
+
existingDraft?: InteractionSession["creationDraft"],
|
|
23
|
+
) => Promise<unknown>;
|
|
24
|
+
readonly createBook?: (input: {
|
|
25
|
+
readonly title: string;
|
|
26
|
+
readonly genre?: string;
|
|
27
|
+
readonly platform?: string;
|
|
28
|
+
readonly language?: "zh" | "en";
|
|
29
|
+
readonly chapterWordCount?: number;
|
|
30
|
+
readonly targetChapters?: number;
|
|
31
|
+
readonly blurb?: string;
|
|
32
|
+
readonly worldPremise?: string;
|
|
33
|
+
readonly settingNotes?: string;
|
|
34
|
+
readonly protagonist?: string;
|
|
35
|
+
readonly supportingCast?: string;
|
|
36
|
+
readonly conflictCore?: string;
|
|
37
|
+
readonly volumeOutline?: string;
|
|
38
|
+
readonly constraints?: string;
|
|
39
|
+
readonly authorIntent?: string;
|
|
40
|
+
readonly currentFocus?: string;
|
|
41
|
+
}) => Promise<unknown>;
|
|
42
|
+
readonly exportBook?: (bookId: string, options: {
|
|
43
|
+
readonly format?: "txt" | "md" | "epub";
|
|
44
|
+
readonly approvedOnly?: boolean;
|
|
45
|
+
readonly outputPath?: string;
|
|
46
|
+
}) => Promise<unknown>;
|
|
47
|
+
readonly chat?: (
|
|
48
|
+
input: string,
|
|
49
|
+
options: {
|
|
50
|
+
readonly bookId?: string;
|
|
51
|
+
readonly automationMode: AutomationMode;
|
|
52
|
+
},
|
|
53
|
+
) => Promise<unknown>;
|
|
54
|
+
readonly writeNextChapter: (bookId: string) => Promise<unknown>;
|
|
55
|
+
readonly reviseDraft: (bookId: string, chapterNumber: number, mode: ReviseMode) => Promise<unknown>;
|
|
56
|
+
readonly patchChapterText: (
|
|
57
|
+
bookId: string,
|
|
58
|
+
chapterNumber: number,
|
|
59
|
+
targetText: string,
|
|
60
|
+
replacementText: string,
|
|
61
|
+
) => Promise<unknown>;
|
|
62
|
+
readonly renameEntity: (
|
|
63
|
+
bookId: string,
|
|
64
|
+
oldValue: string,
|
|
65
|
+
newValue: string,
|
|
66
|
+
) => Promise<unknown>;
|
|
67
|
+
readonly updateCurrentFocus: (bookId: string, content: string) => Promise<unknown>;
|
|
68
|
+
readonly updateAuthorIntent: (bookId: string, content: string) => Promise<unknown>;
|
|
69
|
+
readonly writeTruthFile: (bookId: string, fileName: string, content: string) => Promise<unknown>;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export interface InteractionRuntimeResult {
|
|
73
|
+
readonly session: InteractionSession;
|
|
74
|
+
readonly responseText?: string;
|
|
75
|
+
readonly details?: Readonly<Record<string, unknown>>;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
interface InteractionToolMetadata {
|
|
79
|
+
readonly events?: ReadonlyArray<InteractionEvent>;
|
|
80
|
+
readonly activeChapterNumber?: number;
|
|
81
|
+
readonly currentExecution?: ExecutionState;
|
|
82
|
+
readonly pendingDecision?: PendingDecision;
|
|
83
|
+
readonly responseText?: string;
|
|
84
|
+
readonly details?: Readonly<Record<string, unknown>>;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function extractToolMetadata(value: unknown): InteractionToolMetadata {
|
|
88
|
+
const chapterNumber = typeof value === "object" && value !== null && "chapterNumber" in value
|
|
89
|
+
&& typeof (value as { chapterNumber?: unknown }).chapterNumber === "number"
|
|
90
|
+
? (value as { chapterNumber: number }).chapterNumber
|
|
91
|
+
: undefined;
|
|
92
|
+
|
|
93
|
+
if (!value || typeof value !== "object" || !("__interaction" in value)) {
|
|
94
|
+
return {
|
|
95
|
+
...(chapterNumber !== undefined ? { activeChapterNumber: chapterNumber } : {}),
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const interaction = (value as {
|
|
100
|
+
readonly __interaction?: InteractionToolMetadata;
|
|
101
|
+
}).__interaction;
|
|
102
|
+
|
|
103
|
+
return {
|
|
104
|
+
...interaction,
|
|
105
|
+
...(interaction?.activeChapterNumber === undefined && chapterNumber !== undefined
|
|
106
|
+
? { activeChapterNumber: chapterNumber }
|
|
107
|
+
: {}),
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function resolveRuntimeLanguage(request: InteractionRequest): RuntimeLanguage {
|
|
112
|
+
return request.language === "en" ? "en" : "zh";
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function localize<T>(language: RuntimeLanguage, messages: { zh: T; en: T }): T {
|
|
116
|
+
return language === "en" ? messages.en : messages.zh;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function localizeMode(mode: AutomationMode, language: RuntimeLanguage): string {
|
|
120
|
+
if (language === "en") {
|
|
121
|
+
return mode;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
return {
|
|
125
|
+
auto: "自动",
|
|
126
|
+
semi: "半自动",
|
|
127
|
+
manual: "手动",
|
|
128
|
+
}[mode] ?? mode;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function renderCreationDraft(
|
|
132
|
+
draft: NonNullable<InteractionSession["creationDraft"]>,
|
|
133
|
+
language: RuntimeLanguage,
|
|
134
|
+
): string {
|
|
135
|
+
const lines = language === "en"
|
|
136
|
+
? [
|
|
137
|
+
"# Current Book Draft",
|
|
138
|
+
draft.title ? `- Title: ${draft.title}` : undefined,
|
|
139
|
+
draft.genre ? `- Genre: ${draft.genre}` : undefined,
|
|
140
|
+
draft.platform ? `- Platform: ${draft.platform}` : undefined,
|
|
141
|
+
draft.worldPremise ? `- World: ${draft.worldPremise}` : undefined,
|
|
142
|
+
draft.protagonist ? `- Protagonist: ${draft.protagonist}` : undefined,
|
|
143
|
+
draft.conflictCore ? `- Core Conflict: ${draft.conflictCore}` : undefined,
|
|
144
|
+
draft.volumeOutline ? `- Volume Direction: ${draft.volumeOutline}` : undefined,
|
|
145
|
+
draft.blurb ? `- Blurb: ${draft.blurb}` : undefined,
|
|
146
|
+
draft.nextQuestion ? `- Next: ${draft.nextQuestion}` : undefined,
|
|
147
|
+
]
|
|
148
|
+
: [
|
|
149
|
+
"# 当前创作草案",
|
|
150
|
+
draft.title ? `- 书名:${draft.title}` : undefined,
|
|
151
|
+
draft.genre ? `- 题材:${draft.genre}` : undefined,
|
|
152
|
+
draft.platform ? `- 平台:${draft.platform}` : undefined,
|
|
153
|
+
draft.worldPremise ? `- 世界观:${draft.worldPremise}` : undefined,
|
|
154
|
+
draft.protagonist ? `- 主角:${draft.protagonist}` : undefined,
|
|
155
|
+
draft.conflictCore ? `- 核心冲突:${draft.conflictCore}` : undefined,
|
|
156
|
+
draft.volumeOutline ? `- 卷纲方向:${draft.volumeOutline}` : undefined,
|
|
157
|
+
draft.blurb ? `- 简介:${draft.blurb}` : undefined,
|
|
158
|
+
draft.nextQuestion ? `- 下一步:${draft.nextQuestion}` : undefined,
|
|
159
|
+
];
|
|
160
|
+
return lines.filter(Boolean).join("\n");
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
function buildTaskStartedState(
|
|
164
|
+
session: InteractionSession,
|
|
165
|
+
request: InteractionRequest,
|
|
166
|
+
language: RuntimeLanguage,
|
|
167
|
+
): ExecutionState {
|
|
168
|
+
switch (request.intent) {
|
|
169
|
+
case "write_next":
|
|
170
|
+
case "continue_book":
|
|
171
|
+
return {
|
|
172
|
+
status: "planning",
|
|
173
|
+
bookId: request.bookId ?? session.activeBookId,
|
|
174
|
+
chapterNumber: session.activeChapterNumber,
|
|
175
|
+
stageLabel: localize(language, {
|
|
176
|
+
zh: "准备章节输入",
|
|
177
|
+
en: "preparing chapter inputs",
|
|
178
|
+
}),
|
|
179
|
+
};
|
|
180
|
+
case "develop_book":
|
|
181
|
+
return {
|
|
182
|
+
status: "planning",
|
|
183
|
+
bookId: request.bookId ?? session.activeBookId,
|
|
184
|
+
stageLabel: localize(language, {
|
|
185
|
+
zh: "收敛创作草案",
|
|
186
|
+
en: "developing book draft",
|
|
187
|
+
}),
|
|
188
|
+
};
|
|
189
|
+
case "create_book":
|
|
190
|
+
return {
|
|
191
|
+
status: "planning",
|
|
192
|
+
bookId: request.bookId ?? session.activeBookId,
|
|
193
|
+
stageLabel: localize(language, {
|
|
194
|
+
zh: "创建作品基础",
|
|
195
|
+
en: "creating book foundation",
|
|
196
|
+
}),
|
|
197
|
+
};
|
|
198
|
+
case "export_book":
|
|
199
|
+
return {
|
|
200
|
+
status: "persisting",
|
|
201
|
+
bookId: request.bookId ?? session.activeBookId,
|
|
202
|
+
chapterNumber: session.activeChapterNumber,
|
|
203
|
+
stageLabel: localize(language, {
|
|
204
|
+
zh: "导出作品文件",
|
|
205
|
+
en: "exporting book artifacts",
|
|
206
|
+
}),
|
|
207
|
+
};
|
|
208
|
+
case "revise_chapter":
|
|
209
|
+
case "rewrite_chapter":
|
|
210
|
+
return {
|
|
211
|
+
status: "repairing",
|
|
212
|
+
bookId: request.bookId ?? session.activeBookId,
|
|
213
|
+
chapterNumber: request.chapterNumber ?? session.activeChapterNumber,
|
|
214
|
+
stageLabel: request.intent === "rewrite_chapter"
|
|
215
|
+
? localize(language, { zh: "重写章节", en: "rewriting chapter" })
|
|
216
|
+
: localize(language, { zh: "修订章节", en: "revising chapter" }),
|
|
217
|
+
};
|
|
218
|
+
case "update_focus":
|
|
219
|
+
case "update_author_intent":
|
|
220
|
+
case "edit_truth":
|
|
221
|
+
return {
|
|
222
|
+
status: "persisting",
|
|
223
|
+
bookId: request.bookId ?? session.activeBookId,
|
|
224
|
+
chapterNumber: session.activeChapterNumber,
|
|
225
|
+
stageLabel: localize(language, {
|
|
226
|
+
zh: "应用项目修改",
|
|
227
|
+
en: "applying project edit",
|
|
228
|
+
}),
|
|
229
|
+
};
|
|
230
|
+
case "pause_book":
|
|
231
|
+
case "discard_book_draft":
|
|
232
|
+
return {
|
|
233
|
+
status: "blocked",
|
|
234
|
+
bookId: request.bookId ?? session.activeBookId,
|
|
235
|
+
chapterNumber: session.activeChapterNumber,
|
|
236
|
+
stageLabel: localize(language, {
|
|
237
|
+
zh: "已由用户暂停",
|
|
238
|
+
en: "paused by user",
|
|
239
|
+
}),
|
|
240
|
+
};
|
|
241
|
+
default:
|
|
242
|
+
return {
|
|
243
|
+
status: "planning",
|
|
244
|
+
bookId: request.bookId ?? session.activeBookId,
|
|
245
|
+
chapterNumber: session.activeChapterNumber,
|
|
246
|
+
stageLabel: localize(language, {
|
|
247
|
+
zh: `处理中:${request.intent}`,
|
|
248
|
+
en: `handling ${request.intent}`,
|
|
249
|
+
}),
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
function shouldWaitForHuman(
|
|
255
|
+
automationMode: AutomationMode,
|
|
256
|
+
request: InteractionRequest,
|
|
257
|
+
): boolean {
|
|
258
|
+
const contentIntent = request.intent === "write_next"
|
|
259
|
+
|| request.intent === "continue_book"
|
|
260
|
+
|| request.intent === "revise_chapter"
|
|
261
|
+
|| request.intent === "rewrite_chapter"
|
|
262
|
+
|| request.intent === "patch_chapter_text";
|
|
263
|
+
const editIntent = request.intent === "update_focus"
|
|
264
|
+
|| request.intent === "update_author_intent"
|
|
265
|
+
|| request.intent === "edit_truth"
|
|
266
|
+
|| request.intent === "rename_entity";
|
|
267
|
+
|
|
268
|
+
if (automationMode === "auto") {
|
|
269
|
+
return false;
|
|
270
|
+
}
|
|
271
|
+
if (automationMode === "semi") {
|
|
272
|
+
return contentIntent;
|
|
273
|
+
}
|
|
274
|
+
return contentIntent || editIntent;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
function buildPendingDecision(
|
|
278
|
+
session: InteractionSession,
|
|
279
|
+
request: InteractionRequest,
|
|
280
|
+
language: RuntimeLanguage,
|
|
281
|
+
chapterNumber?: number,
|
|
282
|
+
): PendingDecision | undefined {
|
|
283
|
+
if (!shouldWaitForHuman(session.automationMode, request)) {
|
|
284
|
+
return undefined;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
const bookId = request.bookId ?? session.activeBookId;
|
|
288
|
+
if (!bookId) {
|
|
289
|
+
return undefined;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
return {
|
|
293
|
+
kind: "review-next-step",
|
|
294
|
+
bookId,
|
|
295
|
+
...(chapterNumber !== undefined ? { chapterNumber } : {}),
|
|
296
|
+
summary: session.automationMode === "manual"
|
|
297
|
+
? localize(language, {
|
|
298
|
+
zh: "执行已完成。请明确选择下一步操作。",
|
|
299
|
+
en: "Execution finished. Choose the next action explicitly.",
|
|
300
|
+
})
|
|
301
|
+
: localize(language, {
|
|
302
|
+
zh: "执行已完成,等待你的下一步决定。",
|
|
303
|
+
en: "Execution finished. Waiting for your next decision.",
|
|
304
|
+
}),
|
|
305
|
+
};
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
function buildWaitingExecution(
|
|
309
|
+
session: InteractionSession,
|
|
310
|
+
request: InteractionRequest,
|
|
311
|
+
language: RuntimeLanguage,
|
|
312
|
+
chapterNumber?: number,
|
|
313
|
+
): ExecutionState {
|
|
314
|
+
return {
|
|
315
|
+
status: "waiting_human",
|
|
316
|
+
bookId: request.bookId ?? session.activeBookId,
|
|
317
|
+
...(chapterNumber !== undefined ? { chapterNumber } : {}),
|
|
318
|
+
stageLabel: localize(language, {
|
|
319
|
+
zh: "等待你的下一步决定",
|
|
320
|
+
en: "waiting for your next decision",
|
|
321
|
+
}),
|
|
322
|
+
};
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
function appendToolEvents(
|
|
326
|
+
session: InteractionSession,
|
|
327
|
+
events: ReadonlyArray<InteractionEvent> | undefined,
|
|
328
|
+
): InteractionSession {
|
|
329
|
+
if (!events || events.length === 0) {
|
|
330
|
+
return session;
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
const baseTimestamp = Date.now();
|
|
334
|
+
return events.reduce((nextSession, event, index) => appendInteractionEvent(nextSession, {
|
|
335
|
+
...event,
|
|
336
|
+
timestamp: baseTimestamp - events.length + index,
|
|
337
|
+
}), session);
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
interface RuntimeRequestHelpers {
|
|
341
|
+
readonly language: RuntimeLanguage;
|
|
342
|
+
readonly addEvent: (
|
|
343
|
+
nextSession: InteractionSession,
|
|
344
|
+
kind: string,
|
|
345
|
+
status: InteractionEvent["status"],
|
|
346
|
+
detail: string,
|
|
347
|
+
) => InteractionSession;
|
|
348
|
+
readonly markCompleted: (nextSession: InteractionSession) => InteractionSession;
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
async function handleDraftLifecycleRequest(params: {
|
|
352
|
+
readonly session: InteractionSession;
|
|
353
|
+
readonly request: InteractionRequest;
|
|
354
|
+
readonly tools: InteractionRuntimeTools;
|
|
355
|
+
readonly helpers: RuntimeRequestHelpers;
|
|
356
|
+
}): Promise<InteractionRuntimeResult | undefined> {
|
|
357
|
+
const { session, request, tools, helpers } = params;
|
|
358
|
+
const { language, addEvent, markCompleted } = helpers;
|
|
359
|
+
|
|
360
|
+
switch (request.intent) {
|
|
361
|
+
case "develop_book": {
|
|
362
|
+
if (!tools.developBookDraft) {
|
|
363
|
+
throw new Error(localize(language, {
|
|
364
|
+
zh: "创作草案会话暂未实现。",
|
|
365
|
+
en: "Book-draft ideation is not implemented yet.",
|
|
366
|
+
}));
|
|
367
|
+
}
|
|
368
|
+
if (!request.instruction) {
|
|
369
|
+
throw new Error(localize(language, {
|
|
370
|
+
zh: "创作草案需要一条用户输入。",
|
|
371
|
+
en: "Book-draft ideation requires user input.",
|
|
372
|
+
}));
|
|
373
|
+
}
|
|
374
|
+
const toolResult = await tools.developBookDraft(request.instruction, session.creationDraft);
|
|
375
|
+
const metadata = extractToolMetadata(toolResult);
|
|
376
|
+
const draft = metadata.details?.creationDraft as InteractionSession["creationDraft"] | undefined;
|
|
377
|
+
if (!draft) {
|
|
378
|
+
throw new Error(localize(language, {
|
|
379
|
+
zh: "创作草案工具没有返回草案数据。",
|
|
380
|
+
en: "Book-draft tool did not return draft data.",
|
|
381
|
+
}));
|
|
382
|
+
}
|
|
383
|
+
const newRound: DraftRound = {
|
|
384
|
+
roundId: (session.draftRounds?.length ?? 0) + 1,
|
|
385
|
+
userMessage: request.instruction ?? "",
|
|
386
|
+
assistantRaw: metadata.details?.draftRaw as string ?? "",
|
|
387
|
+
fieldsUpdated: (metadata.details?.fieldsUpdated as string[]) ?? [],
|
|
388
|
+
summary: metadata.details?.draftSummary as string ?? "",
|
|
389
|
+
timestamp: Date.now(),
|
|
390
|
+
};
|
|
391
|
+
const withDraft = updateCreationDraft(session, draft);
|
|
392
|
+
const withRounds = {
|
|
393
|
+
...withDraft,
|
|
394
|
+
draftRounds: [...(withDraft.draftRounds ?? []), newRound],
|
|
395
|
+
};
|
|
396
|
+
const nextSession = appendToolEvents(withRounds, metadata.events);
|
|
397
|
+
const completed = {
|
|
398
|
+
...markCompleted(nextSession),
|
|
399
|
+
currentExecution: metadata.currentExecution ?? markCompleted(nextSession).currentExecution,
|
|
400
|
+
};
|
|
401
|
+
return {
|
|
402
|
+
session: addEvent(completed, "task.completed", "completed", localize(language, {
|
|
403
|
+
zh: "已更新创作草案。",
|
|
404
|
+
en: "Updated the book draft.",
|
|
405
|
+
})),
|
|
406
|
+
responseText: metadata.responseText ?? localize(language, {
|
|
407
|
+
zh: "已更新创作草案。",
|
|
408
|
+
en: "Updated the book draft.",
|
|
409
|
+
}),
|
|
410
|
+
details: metadata.details,
|
|
411
|
+
};
|
|
412
|
+
}
|
|
413
|
+
case "show_book_draft": {
|
|
414
|
+
if (!session.creationDraft) {
|
|
415
|
+
return {
|
|
416
|
+
session: markCompleted(session),
|
|
417
|
+
responseText: localize(language, {
|
|
418
|
+
zh: "当前还没有创作草案。先告诉我你想写什么,再逐步把书收出来。",
|
|
419
|
+
en: "There is no active book draft yet. Start by telling me what you want to write.",
|
|
420
|
+
}),
|
|
421
|
+
};
|
|
422
|
+
}
|
|
423
|
+
return {
|
|
424
|
+
session: markCompleted(session),
|
|
425
|
+
responseText: renderCreationDraft(session.creationDraft, language),
|
|
426
|
+
};
|
|
427
|
+
}
|
|
428
|
+
case "create_book": {
|
|
429
|
+
if (!tools.createBook) {
|
|
430
|
+
throw new Error(localize(language, {
|
|
431
|
+
zh: "交互运行时暂未实现创建作品。",
|
|
432
|
+
en: "Book creation is not implemented in the interaction runtime yet.",
|
|
433
|
+
}));
|
|
434
|
+
}
|
|
435
|
+
const effectiveDraft = session.creationDraft;
|
|
436
|
+
const title = request.title ?? effectiveDraft?.title;
|
|
437
|
+
if (!title) {
|
|
438
|
+
throw new Error(localize(language, {
|
|
439
|
+
zh: "创建作品需要标题。",
|
|
440
|
+
en: "Book creation requires a title.",
|
|
441
|
+
}));
|
|
442
|
+
}
|
|
443
|
+
const toolResult = await tools.createBook({
|
|
444
|
+
title,
|
|
445
|
+
genre: request.genre ?? effectiveDraft?.genre,
|
|
446
|
+
platform: request.platform ?? effectiveDraft?.platform,
|
|
447
|
+
language: request.language ?? effectiveDraft?.language,
|
|
448
|
+
chapterWordCount: request.chapterWordCount ?? effectiveDraft?.chapterWordCount,
|
|
449
|
+
targetChapters: request.targetChapters ?? effectiveDraft?.targetChapters,
|
|
450
|
+
blurb: request.blurb ?? effectiveDraft?.blurb,
|
|
451
|
+
worldPremise: request.worldPremise ?? effectiveDraft?.worldPremise,
|
|
452
|
+
settingNotes: request.settingNotes ?? effectiveDraft?.settingNotes,
|
|
453
|
+
protagonist: request.protagonist ?? effectiveDraft?.protagonist,
|
|
454
|
+
supportingCast: request.supportingCast ?? effectiveDraft?.supportingCast,
|
|
455
|
+
conflictCore: request.conflictCore ?? effectiveDraft?.conflictCore,
|
|
456
|
+
volumeOutline: request.volumeOutline ?? effectiveDraft?.volumeOutline,
|
|
457
|
+
constraints: request.constraints ?? effectiveDraft?.constraints,
|
|
458
|
+
authorIntent: request.authorIntent ?? effectiveDraft?.authorIntent,
|
|
459
|
+
currentFocus: request.currentFocus ?? effectiveDraft?.currentFocus,
|
|
460
|
+
});
|
|
461
|
+
const metadata = extractToolMetadata(toolResult);
|
|
462
|
+
const createdBookId = typeof toolResult === "object" && toolResult !== null && "bookId" in toolResult
|
|
463
|
+
&& typeof (toolResult as { bookId?: unknown }).bookId === "string"
|
|
464
|
+
? (toolResult as { bookId: string }).bookId
|
|
465
|
+
: undefined;
|
|
466
|
+
if (!createdBookId) {
|
|
467
|
+
throw new Error(localize(language, {
|
|
468
|
+
zh: "创建作品工具没有返回作品 ID。",
|
|
469
|
+
en: "Create-book tool did not return a book id.",
|
|
470
|
+
}));
|
|
471
|
+
}
|
|
472
|
+
const nextSession = appendToolEvents(
|
|
473
|
+
clearCreationDraft(bindActiveBook(session, createdBookId)),
|
|
474
|
+
metadata.events,
|
|
475
|
+
);
|
|
476
|
+
const completed = {
|
|
477
|
+
...markCompleted(nextSession),
|
|
478
|
+
currentExecution: metadata.currentExecution ?? markCompleted(nextSession).currentExecution,
|
|
479
|
+
};
|
|
480
|
+
return {
|
|
481
|
+
session: addEvent(completed, "task.completed", "completed", localize(language, {
|
|
482
|
+
zh: `已创建作品 ${createdBookId}。`,
|
|
483
|
+
en: `Created ${createdBookId}.`,
|
|
484
|
+
})),
|
|
485
|
+
responseText: metadata.responseText ?? localize(language, {
|
|
486
|
+
zh: `已创建作品 ${createdBookId}。`,
|
|
487
|
+
en: `Created ${createdBookId}.`,
|
|
488
|
+
}),
|
|
489
|
+
details: metadata.details,
|
|
490
|
+
};
|
|
491
|
+
}
|
|
492
|
+
case "discard_book_draft": {
|
|
493
|
+
const completed = markCompleted(clearCreationDraft(session));
|
|
494
|
+
return {
|
|
495
|
+
session: addEvent(completed, "task.completed", "completed", localize(language, {
|
|
496
|
+
zh: "已丢弃当前创作草案。",
|
|
497
|
+
en: "Discarded the current book draft.",
|
|
498
|
+
})),
|
|
499
|
+
responseText: localize(language, {
|
|
500
|
+
zh: "已丢弃当前创作草案。",
|
|
501
|
+
en: "Discarded the current book draft.",
|
|
502
|
+
}),
|
|
503
|
+
};
|
|
504
|
+
}
|
|
505
|
+
default:
|
|
506
|
+
return undefined;
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
async function handleBookSelectionRequest(params: {
|
|
511
|
+
readonly session: InteractionSession;
|
|
512
|
+
readonly request: InteractionRequest;
|
|
513
|
+
readonly tools: InteractionRuntimeTools;
|
|
514
|
+
readonly helpers: RuntimeRequestHelpers;
|
|
515
|
+
}): Promise<InteractionRuntimeResult | undefined> {
|
|
516
|
+
const { session, request, tools, helpers } = params;
|
|
517
|
+
const { language, addEvent, markCompleted } = helpers;
|
|
518
|
+
|
|
519
|
+
switch (request.intent) {
|
|
520
|
+
case "list_books": {
|
|
521
|
+
const books = await tools.listBooks();
|
|
522
|
+
const completed = markCompleted(session);
|
|
523
|
+
return {
|
|
524
|
+
session: addEvent(completed, "task.completed", "completed", localize(language, {
|
|
525
|
+
zh: `已列出 ${books.length} 本作品。`,
|
|
526
|
+
en: `Listed ${books.length} book(s).`,
|
|
527
|
+
})),
|
|
528
|
+
responseText: books.length > 0
|
|
529
|
+
? localize(language, {
|
|
530
|
+
zh: `作品列表:${books.join("、")}`,
|
|
531
|
+
en: `Books: ${books.join(", ")}`,
|
|
532
|
+
})
|
|
533
|
+
: localize(language, {
|
|
534
|
+
zh: "当前项目下没有作品。",
|
|
535
|
+
en: "No books found in this project.",
|
|
536
|
+
}),
|
|
537
|
+
};
|
|
538
|
+
}
|
|
539
|
+
case "select_book": {
|
|
540
|
+
if (!request.bookId) {
|
|
541
|
+
throw new Error(localize(language, {
|
|
542
|
+
zh: "切换作品需要提供作品 ID。",
|
|
543
|
+
en: "Book selection requires a book id.",
|
|
544
|
+
}));
|
|
545
|
+
}
|
|
546
|
+
const books = await tools.listBooks();
|
|
547
|
+
if (!books.includes(request.bookId)) {
|
|
548
|
+
throw new Error(localize(language, {
|
|
549
|
+
zh: `当前项目中找不到作品「${request.bookId}」。`,
|
|
550
|
+
en: `Book "${request.bookId}" not found in this project.`,
|
|
551
|
+
}));
|
|
552
|
+
}
|
|
553
|
+
const completed = markCompleted(bindActiveBook(session, request.bookId));
|
|
554
|
+
return {
|
|
555
|
+
session: addEvent(completed, "task.completed", "completed", localize(language, {
|
|
556
|
+
zh: `已切换当前作品到 ${request.bookId}。`,
|
|
557
|
+
en: `Bound active book to ${request.bookId}.`,
|
|
558
|
+
})),
|
|
559
|
+
responseText: localize(language, {
|
|
560
|
+
zh: `当前作品:${request.bookId}`,
|
|
561
|
+
en: `Active book: ${request.bookId}`,
|
|
562
|
+
}),
|
|
563
|
+
};
|
|
564
|
+
}
|
|
565
|
+
default:
|
|
566
|
+
return undefined;
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
export async function runInteractionRequest(params: {
|
|
571
|
+
readonly session: InteractionSession;
|
|
572
|
+
readonly request: InteractionRequest;
|
|
573
|
+
readonly tools: InteractionRuntimeTools;
|
|
574
|
+
}): Promise<InteractionRuntimeResult> {
|
|
575
|
+
const request = routeInteractionRequest(params.request);
|
|
576
|
+
const language = resolveRuntimeLanguage(request);
|
|
577
|
+
let session = params.session;
|
|
578
|
+
const addEvent = (
|
|
579
|
+
nextSession: InteractionSession,
|
|
580
|
+
kind: string,
|
|
581
|
+
status: InteractionEvent["status"],
|
|
582
|
+
detail: string,
|
|
583
|
+
): InteractionSession => appendInteractionEvent(nextSession, {
|
|
584
|
+
kind,
|
|
585
|
+
timestamp: Date.now(),
|
|
586
|
+
status,
|
|
587
|
+
bookId: nextSession.activeBookId,
|
|
588
|
+
chapterNumber: nextSession.activeChapterNumber,
|
|
589
|
+
detail,
|
|
590
|
+
});
|
|
591
|
+
|
|
592
|
+
if (request.mode) {
|
|
593
|
+
session = updateAutomationMode(session, request.mode as AutomationMode);
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
session = clearPendingDecision({
|
|
597
|
+
...session,
|
|
598
|
+
currentExecution: buildTaskStartedState(session, request, language),
|
|
599
|
+
});
|
|
600
|
+
session = addEvent(session, "task.started", session.currentExecution!.status, localize(language, {
|
|
601
|
+
zh: `开始执行 ${request.intent}。`,
|
|
602
|
+
en: `Started ${request.intent}.`,
|
|
603
|
+
}));
|
|
604
|
+
|
|
605
|
+
const markCompleted = (nextSession: InteractionSession): InteractionSession => ({
|
|
606
|
+
...nextSession,
|
|
607
|
+
currentExecution: {
|
|
608
|
+
status: "completed",
|
|
609
|
+
bookId: nextSession.activeBookId,
|
|
610
|
+
chapterNumber: nextSession.activeChapterNumber,
|
|
611
|
+
stageLabel: localize(language, {
|
|
612
|
+
zh: "已完成",
|
|
613
|
+
en: "completed",
|
|
614
|
+
}),
|
|
615
|
+
},
|
|
616
|
+
});
|
|
617
|
+
|
|
618
|
+
const helperContext: RuntimeRequestHelpers = {
|
|
619
|
+
language,
|
|
620
|
+
addEvent,
|
|
621
|
+
markCompleted,
|
|
622
|
+
};
|
|
623
|
+
|
|
624
|
+
const draftLifecycleResult = await handleDraftLifecycleRequest({
|
|
625
|
+
session,
|
|
626
|
+
request,
|
|
627
|
+
tools: params.tools,
|
|
628
|
+
helpers: helperContext,
|
|
629
|
+
});
|
|
630
|
+
if (draftLifecycleResult) {
|
|
631
|
+
return draftLifecycleResult;
|
|
632
|
+
}
|
|
633
|
+
|
|
634
|
+
const bookSelectionResult = await handleBookSelectionRequest({
|
|
635
|
+
session,
|
|
636
|
+
request,
|
|
637
|
+
tools: params.tools,
|
|
638
|
+
helpers: helperContext,
|
|
639
|
+
});
|
|
640
|
+
if (bookSelectionResult) {
|
|
641
|
+
return bookSelectionResult;
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
switch (request.intent) {
|
|
645
|
+
case "write_next":
|
|
646
|
+
case "continue_book": {
|
|
647
|
+
const bookId = request.bookId ?? session.activeBookId;
|
|
648
|
+
if (!bookId) {
|
|
649
|
+
throw new Error(localize(language, {
|
|
650
|
+
zh: "当前交互会话还没有绑定作品。",
|
|
651
|
+
en: "No active book is bound to the interaction session.",
|
|
652
|
+
}));
|
|
653
|
+
}
|
|
654
|
+
const toolResult = await params.tools.writeNextChapter(bookId);
|
|
655
|
+
const metadata = extractToolMetadata(toolResult);
|
|
656
|
+
session = bindActiveBook(session, bookId, metadata.activeChapterNumber);
|
|
657
|
+
session = appendToolEvents(session, metadata.events);
|
|
658
|
+
const pendingDecision = metadata.pendingDecision ?? buildPendingDecision(
|
|
659
|
+
session,
|
|
660
|
+
request,
|
|
661
|
+
language,
|
|
662
|
+
metadata.activeChapterNumber,
|
|
663
|
+
);
|
|
664
|
+
const completed = pendingDecision
|
|
665
|
+
? {
|
|
666
|
+
...session,
|
|
667
|
+
pendingDecision,
|
|
668
|
+
currentExecution: metadata.currentExecution ?? buildWaitingExecution(session, request, language, metadata.activeChapterNumber),
|
|
669
|
+
}
|
|
670
|
+
: {
|
|
671
|
+
...markCompleted(session),
|
|
672
|
+
currentExecution: metadata.currentExecution ?? markCompleted(session).currentExecution,
|
|
673
|
+
};
|
|
674
|
+
return {
|
|
675
|
+
session: addEvent(completed, "task.completed", "completed", localize(language, {
|
|
676
|
+
zh: `已为 ${bookId} 完成下一章写作。`,
|
|
677
|
+
en: `Completed write_next for ${bookId}.`,
|
|
678
|
+
})),
|
|
679
|
+
responseText: metadata.responseText ?? (
|
|
680
|
+
pendingDecision
|
|
681
|
+
? localize(language, {
|
|
682
|
+
zh: `已为 ${bookId} 完成下一章写作,等待你的下一步决定。`,
|
|
683
|
+
en: `Completed write_next for ${bookId}; waiting for your next decision.`,
|
|
684
|
+
})
|
|
685
|
+
: localize(language, {
|
|
686
|
+
zh: `已为 ${bookId} 完成下一章写作。`,
|
|
687
|
+
en: `Completed write_next for ${bookId}.`,
|
|
688
|
+
})
|
|
689
|
+
),
|
|
690
|
+
};
|
|
691
|
+
}
|
|
692
|
+
case "revise_chapter":
|
|
693
|
+
case "rewrite_chapter": {
|
|
694
|
+
const bookId = request.bookId ?? session.activeBookId;
|
|
695
|
+
if (!bookId) {
|
|
696
|
+
throw new Error(localize(language, {
|
|
697
|
+
zh: "当前交互会话还没有绑定作品。",
|
|
698
|
+
en: "No active book is bound to the interaction session.",
|
|
699
|
+
}));
|
|
700
|
+
}
|
|
701
|
+
if (!request.chapterNumber) {
|
|
702
|
+
throw new Error(localize(language, {
|
|
703
|
+
zh: "修订章节需要章节号。",
|
|
704
|
+
en: "Chapter number is required for chapter revision.",
|
|
705
|
+
}));
|
|
706
|
+
}
|
|
707
|
+
const mode: ReviseMode = request.intent === "rewrite_chapter" ? "rewrite" : "local-fix";
|
|
708
|
+
const toolResult = await params.tools.reviseDraft(bookId, request.chapterNumber, mode);
|
|
709
|
+
const metadata = extractToolMetadata(toolResult);
|
|
710
|
+
const chapterNumber = metadata.activeChapterNumber ?? request.chapterNumber;
|
|
711
|
+
session = bindActiveBook(session, bookId, chapterNumber);
|
|
712
|
+
session = appendToolEvents(session, metadata.events);
|
|
713
|
+
const pendingDecision = metadata.pendingDecision ?? buildPendingDecision(
|
|
714
|
+
session,
|
|
715
|
+
request,
|
|
716
|
+
language,
|
|
717
|
+
chapterNumber,
|
|
718
|
+
);
|
|
719
|
+
const completed = pendingDecision
|
|
720
|
+
? {
|
|
721
|
+
...session,
|
|
722
|
+
pendingDecision,
|
|
723
|
+
currentExecution: metadata.currentExecution ?? buildWaitingExecution(session, request, language, chapterNumber),
|
|
724
|
+
}
|
|
725
|
+
: {
|
|
726
|
+
...markCompleted(session),
|
|
727
|
+
currentExecution: metadata.currentExecution ?? markCompleted(session).currentExecution,
|
|
728
|
+
};
|
|
729
|
+
return {
|
|
730
|
+
session: addEvent(completed, "task.completed", "completed", localize(language, {
|
|
731
|
+
zh: request.intent === "rewrite_chapter"
|
|
732
|
+
? `已为 ${bookId} 完成章节重写。`
|
|
733
|
+
: `已为 ${bookId} 完成章节修订。`,
|
|
734
|
+
en: `Completed ${request.intent} for ${bookId}.`,
|
|
735
|
+
})),
|
|
736
|
+
responseText: metadata.responseText ?? (
|
|
737
|
+
pendingDecision
|
|
738
|
+
? localize(language, {
|
|
739
|
+
zh: request.intent === "rewrite_chapter"
|
|
740
|
+
? `已为 ${bookId} 完成章节重写,等待你的下一步决定。`
|
|
741
|
+
: `已为 ${bookId} 完成章节修订,等待你的下一步决定。`,
|
|
742
|
+
en: `Completed ${request.intent} for ${bookId}; waiting for your next decision.`,
|
|
743
|
+
})
|
|
744
|
+
: localize(language, {
|
|
745
|
+
zh: request.intent === "rewrite_chapter"
|
|
746
|
+
? `已为 ${bookId} 完成章节重写。`
|
|
747
|
+
: `已为 ${bookId} 完成章节修订。`,
|
|
748
|
+
en: `Completed ${request.intent} for ${bookId}.`,
|
|
749
|
+
})
|
|
750
|
+
),
|
|
751
|
+
};
|
|
752
|
+
}
|
|
753
|
+
case "patch_chapter_text": {
|
|
754
|
+
const bookId = request.bookId ?? session.activeBookId;
|
|
755
|
+
if (!bookId) {
|
|
756
|
+
throw new Error(localize(language, {
|
|
757
|
+
zh: "当前交互会话还没有绑定作品。",
|
|
758
|
+
en: "No active book is bound to the interaction session.",
|
|
759
|
+
}));
|
|
760
|
+
}
|
|
761
|
+
if (!request.chapterNumber || !request.targetText || !request.replacementText) {
|
|
762
|
+
throw new Error(localize(language, {
|
|
763
|
+
zh: "正文修补需要章节号、目标文本和替换文本。",
|
|
764
|
+
en: "Chapter patch requires chapter number, target text, and replacement text.",
|
|
765
|
+
}));
|
|
766
|
+
}
|
|
767
|
+
const toolResult = await params.tools.patchChapterText(
|
|
768
|
+
bookId,
|
|
769
|
+
request.chapterNumber,
|
|
770
|
+
request.targetText,
|
|
771
|
+
request.replacementText,
|
|
772
|
+
);
|
|
773
|
+
const metadata = extractToolMetadata(toolResult);
|
|
774
|
+
const chapterNumber = metadata.activeChapterNumber ?? request.chapterNumber;
|
|
775
|
+
session = bindActiveBook(session, bookId, chapterNumber);
|
|
776
|
+
session = appendToolEvents(session, metadata.events);
|
|
777
|
+
const pendingDecision = metadata.pendingDecision ?? buildPendingDecision(
|
|
778
|
+
session,
|
|
779
|
+
request,
|
|
780
|
+
language,
|
|
781
|
+
chapterNumber,
|
|
782
|
+
);
|
|
783
|
+
const completed = pendingDecision
|
|
784
|
+
? {
|
|
785
|
+
...session,
|
|
786
|
+
pendingDecision,
|
|
787
|
+
currentExecution: metadata.currentExecution ?? buildWaitingExecution(session, request, language, chapterNumber),
|
|
788
|
+
}
|
|
789
|
+
: {
|
|
790
|
+
...markCompleted(session),
|
|
791
|
+
currentExecution: metadata.currentExecution ?? markCompleted(session).currentExecution,
|
|
792
|
+
};
|
|
793
|
+
return {
|
|
794
|
+
session: addEvent(completed, "task.completed", "completed", localize(language, {
|
|
795
|
+
zh: `已修补 ${bookId} 的第 ${chapterNumber} 章。`,
|
|
796
|
+
en: `Patched chapter ${chapterNumber} for ${bookId}.`,
|
|
797
|
+
})),
|
|
798
|
+
responseText: metadata.responseText ?? (
|
|
799
|
+
pendingDecision
|
|
800
|
+
? localize(language, {
|
|
801
|
+
zh: `已修补 ${bookId} 的第 ${chapterNumber} 章,等待你的下一步决定。`,
|
|
802
|
+
en: `Patched chapter ${chapterNumber} for ${bookId}; waiting for your next decision.`,
|
|
803
|
+
})
|
|
804
|
+
: localize(language, {
|
|
805
|
+
zh: `已修补 ${bookId} 的第 ${chapterNumber} 章。`,
|
|
806
|
+
en: `Patched chapter ${chapterNumber} for ${bookId}.`,
|
|
807
|
+
})
|
|
808
|
+
),
|
|
809
|
+
};
|
|
810
|
+
}
|
|
811
|
+
case "rename_entity": {
|
|
812
|
+
const bookId = request.bookId ?? session.activeBookId;
|
|
813
|
+
if (!bookId) {
|
|
814
|
+
throw new Error(localize(language, {
|
|
815
|
+
zh: "当前交互会话还没有绑定作品。",
|
|
816
|
+
en: "No active book is bound to the interaction session.",
|
|
817
|
+
}));
|
|
818
|
+
}
|
|
819
|
+
if (!request.oldValue || !request.newValue) {
|
|
820
|
+
throw new Error(localize(language, {
|
|
821
|
+
zh: "实体改名需要旧值和新值。",
|
|
822
|
+
en: "Entity rename requires old and new values.",
|
|
823
|
+
}));
|
|
824
|
+
}
|
|
825
|
+
const toolResult = await params.tools.renameEntity(bookId, request.oldValue, request.newValue);
|
|
826
|
+
const metadata = extractToolMetadata(toolResult);
|
|
827
|
+
session = bindActiveBook(session, bookId, metadata.activeChapterNumber);
|
|
828
|
+
session = appendToolEvents(session, metadata.events);
|
|
829
|
+
const pendingDecision = metadata.pendingDecision ?? buildPendingDecision(
|
|
830
|
+
session,
|
|
831
|
+
request,
|
|
832
|
+
language,
|
|
833
|
+
metadata.activeChapterNumber,
|
|
834
|
+
);
|
|
835
|
+
const completed = pendingDecision
|
|
836
|
+
? {
|
|
837
|
+
...session,
|
|
838
|
+
pendingDecision,
|
|
839
|
+
currentExecution: metadata.currentExecution ?? buildWaitingExecution(session, request, language, metadata.activeChapterNumber),
|
|
840
|
+
}
|
|
841
|
+
: {
|
|
842
|
+
...markCompleted(session),
|
|
843
|
+
currentExecution: metadata.currentExecution ?? markCompleted(session).currentExecution,
|
|
844
|
+
};
|
|
845
|
+
return {
|
|
846
|
+
session: addEvent(completed, "task.completed", "completed", localize(language, {
|
|
847
|
+
zh: `已在 ${bookId} 中把 ${request.oldValue} 改成 ${request.newValue}。`,
|
|
848
|
+
en: `Renamed ${request.oldValue} to ${request.newValue} in ${bookId}.`,
|
|
849
|
+
})),
|
|
850
|
+
responseText: metadata.responseText ?? (
|
|
851
|
+
pendingDecision
|
|
852
|
+
? localize(language, {
|
|
853
|
+
zh: `已在 ${bookId} 中把 ${request.oldValue} 改成 ${request.newValue},等待你的下一步决定。`,
|
|
854
|
+
en: `Renamed ${request.oldValue} to ${request.newValue} in ${bookId}; waiting for your next decision.`,
|
|
855
|
+
})
|
|
856
|
+
: localize(language, {
|
|
857
|
+
zh: `已在 ${bookId} 中把 ${request.oldValue} 改成 ${request.newValue}。`,
|
|
858
|
+
en: `Renamed ${request.oldValue} to ${request.newValue} in ${bookId}.`,
|
|
859
|
+
})
|
|
860
|
+
),
|
|
861
|
+
};
|
|
862
|
+
}
|
|
863
|
+
case "update_focus": {
|
|
864
|
+
const bookId = request.bookId ?? session.activeBookId;
|
|
865
|
+
if (!bookId) {
|
|
866
|
+
throw new Error(localize(language, {
|
|
867
|
+
zh: "当前交互会话还没有绑定作品。",
|
|
868
|
+
en: "No active book is bound to the interaction session.",
|
|
869
|
+
}));
|
|
870
|
+
}
|
|
871
|
+
if (!request.instruction) {
|
|
872
|
+
throw new Error(localize(language, {
|
|
873
|
+
zh: "更新焦点需要提供内容。",
|
|
874
|
+
en: "Focus update requires instruction content.",
|
|
875
|
+
}));
|
|
876
|
+
}
|
|
877
|
+
const toolResult = await params.tools.updateCurrentFocus(bookId, request.instruction);
|
|
878
|
+
const metadata = extractToolMetadata(toolResult);
|
|
879
|
+
session = bindActiveBook(session, bookId);
|
|
880
|
+
session = appendToolEvents(session, metadata.events);
|
|
881
|
+
const pendingDecision = metadata.pendingDecision ?? buildPendingDecision(session, request, language);
|
|
882
|
+
const completed = pendingDecision
|
|
883
|
+
? {
|
|
884
|
+
...session,
|
|
885
|
+
pendingDecision,
|
|
886
|
+
currentExecution: metadata.currentExecution ?? buildWaitingExecution(session, request, language),
|
|
887
|
+
}
|
|
888
|
+
: {
|
|
889
|
+
...markCompleted(session),
|
|
890
|
+
currentExecution: metadata.currentExecution ?? markCompleted(session).currentExecution,
|
|
891
|
+
};
|
|
892
|
+
return {
|
|
893
|
+
session: addEvent(completed, "task.completed", "completed", localize(language, {
|
|
894
|
+
zh: `已更新 ${bookId} 的当前焦点。`,
|
|
895
|
+
en: `Updated current focus for ${bookId}.`,
|
|
896
|
+
})),
|
|
897
|
+
responseText: metadata.responseText ?? (
|
|
898
|
+
pendingDecision
|
|
899
|
+
? localize(language, {
|
|
900
|
+
zh: `已更新 ${bookId} 的当前焦点,等待你的下一步决定。`,
|
|
901
|
+
en: `Updated current focus for ${bookId}; waiting for your next decision.`,
|
|
902
|
+
})
|
|
903
|
+
: localize(language, {
|
|
904
|
+
zh: `已更新 ${bookId} 的当前焦点。`,
|
|
905
|
+
en: `Updated current focus for ${bookId}.`,
|
|
906
|
+
})
|
|
907
|
+
),
|
|
908
|
+
};
|
|
909
|
+
}
|
|
910
|
+
case "update_author_intent": {
|
|
911
|
+
const bookId = request.bookId ?? session.activeBookId;
|
|
912
|
+
if (!bookId) {
|
|
913
|
+
throw new Error(localize(language, {
|
|
914
|
+
zh: "当前交互会话还没有绑定作品。",
|
|
915
|
+
en: "No active book is bound to the interaction session.",
|
|
916
|
+
}));
|
|
917
|
+
}
|
|
918
|
+
if (!request.instruction) {
|
|
919
|
+
throw new Error(localize(language, {
|
|
920
|
+
zh: "更新作者意图需要提供内容。",
|
|
921
|
+
en: "Author intent update requires instruction content.",
|
|
922
|
+
}));
|
|
923
|
+
}
|
|
924
|
+
const toolResult = await params.tools.updateAuthorIntent(bookId, request.instruction);
|
|
925
|
+
const metadata = extractToolMetadata(toolResult);
|
|
926
|
+
session = bindActiveBook(session, bookId);
|
|
927
|
+
session = appendToolEvents(session, metadata.events);
|
|
928
|
+
const pendingDecision = metadata.pendingDecision ?? buildPendingDecision(session, request, language);
|
|
929
|
+
const completed = pendingDecision
|
|
930
|
+
? {
|
|
931
|
+
...session,
|
|
932
|
+
pendingDecision,
|
|
933
|
+
currentExecution: metadata.currentExecution ?? buildWaitingExecution(session, request, language),
|
|
934
|
+
}
|
|
935
|
+
: {
|
|
936
|
+
...markCompleted(session),
|
|
937
|
+
currentExecution: metadata.currentExecution ?? markCompleted(session).currentExecution,
|
|
938
|
+
};
|
|
939
|
+
return {
|
|
940
|
+
session: addEvent(completed, "task.completed", "completed", localize(language, {
|
|
941
|
+
zh: `已更新 ${bookId} 的作者意图。`,
|
|
942
|
+
en: `Updated author intent for ${bookId}.`,
|
|
943
|
+
})),
|
|
944
|
+
responseText: metadata.responseText ?? (
|
|
945
|
+
pendingDecision
|
|
946
|
+
? localize(language, {
|
|
947
|
+
zh: `已更新 ${bookId} 的作者意图,等待你的下一步决定。`,
|
|
948
|
+
en: `Updated author intent for ${bookId}; waiting for your next decision.`,
|
|
949
|
+
})
|
|
950
|
+
: localize(language, {
|
|
951
|
+
zh: `已更新 ${bookId} 的作者意图。`,
|
|
952
|
+
en: `Updated author intent for ${bookId}.`,
|
|
953
|
+
})
|
|
954
|
+
),
|
|
955
|
+
};
|
|
956
|
+
}
|
|
957
|
+
case "edit_truth": {
|
|
958
|
+
const bookId = request.bookId ?? session.activeBookId;
|
|
959
|
+
if (!bookId) {
|
|
960
|
+
throw new Error(localize(language, {
|
|
961
|
+
zh: "当前交互会话还没有绑定作品。",
|
|
962
|
+
en: "No active book is bound to the interaction session.",
|
|
963
|
+
}));
|
|
964
|
+
}
|
|
965
|
+
if (!request.fileName || !request.instruction) {
|
|
966
|
+
throw new Error(localize(language, {
|
|
967
|
+
zh: "编辑真相文件需要文件名和内容。",
|
|
968
|
+
en: "Truth-file edit requires a file name and content.",
|
|
969
|
+
}));
|
|
970
|
+
}
|
|
971
|
+
const toolResult = await params.tools.writeTruthFile(bookId, request.fileName, request.instruction);
|
|
972
|
+
const metadata = extractToolMetadata(toolResult);
|
|
973
|
+
session = bindActiveBook(session, bookId);
|
|
974
|
+
session = appendToolEvents(session, metadata.events);
|
|
975
|
+
const pendingDecision = metadata.pendingDecision ?? buildPendingDecision(session, request, language);
|
|
976
|
+
const completed = pendingDecision
|
|
977
|
+
? {
|
|
978
|
+
...session,
|
|
979
|
+
pendingDecision,
|
|
980
|
+
currentExecution: metadata.currentExecution ?? buildWaitingExecution(session, request, language),
|
|
981
|
+
}
|
|
982
|
+
: {
|
|
983
|
+
...markCompleted(session),
|
|
984
|
+
currentExecution: metadata.currentExecution ?? markCompleted(session).currentExecution,
|
|
985
|
+
};
|
|
986
|
+
return {
|
|
987
|
+
session: addEvent(completed, "task.completed", "completed", localize(language, {
|
|
988
|
+
zh: `已更新 ${bookId} 的 ${request.fileName}。`,
|
|
989
|
+
en: `Updated ${request.fileName} for ${bookId}.`,
|
|
990
|
+
})),
|
|
991
|
+
responseText: metadata.responseText ?? (
|
|
992
|
+
pendingDecision
|
|
993
|
+
? localize(language, {
|
|
994
|
+
zh: `已更新 ${bookId} 的 ${request.fileName},等待你的下一步决定。`,
|
|
995
|
+
en: `Updated ${request.fileName} for ${bookId}; waiting for your next decision.`,
|
|
996
|
+
})
|
|
997
|
+
: localize(language, {
|
|
998
|
+
zh: `已更新 ${bookId} 的 ${request.fileName}。`,
|
|
999
|
+
en: `Updated ${request.fileName} for ${bookId}.`,
|
|
1000
|
+
})
|
|
1001
|
+
),
|
|
1002
|
+
};
|
|
1003
|
+
}
|
|
1004
|
+
case "export_book": {
|
|
1005
|
+
const bookId = request.bookId ?? session.activeBookId;
|
|
1006
|
+
if (!params.tools.exportBook) {
|
|
1007
|
+
throw new Error(localize(language, {
|
|
1008
|
+
zh: "交互运行时暂未实现导出作品。",
|
|
1009
|
+
en: "Book export is not implemented in the interaction runtime yet.",
|
|
1010
|
+
}));
|
|
1011
|
+
}
|
|
1012
|
+
if (!bookId) {
|
|
1013
|
+
throw new Error(localize(language, {
|
|
1014
|
+
zh: "当前交互会话还没有绑定作品。",
|
|
1015
|
+
en: "No active book is bound to the interaction session.",
|
|
1016
|
+
}));
|
|
1017
|
+
}
|
|
1018
|
+
const toolResult = await params.tools.exportBook(bookId, {
|
|
1019
|
+
format: request.format,
|
|
1020
|
+
approvedOnly: request.approvedOnly,
|
|
1021
|
+
outputPath: request.outputPath,
|
|
1022
|
+
});
|
|
1023
|
+
const metadata = extractToolMetadata(toolResult);
|
|
1024
|
+
session = bindActiveBook(session, bookId, metadata.activeChapterNumber);
|
|
1025
|
+
session = appendToolEvents(session, metadata.events);
|
|
1026
|
+
const completed = {
|
|
1027
|
+
...markCompleted(session),
|
|
1028
|
+
currentExecution: metadata.currentExecution ?? markCompleted(session).currentExecution,
|
|
1029
|
+
};
|
|
1030
|
+
return {
|
|
1031
|
+
session: addEvent(completed, "task.completed", "completed", localize(language, {
|
|
1032
|
+
zh: `已导出 ${bookId}。`,
|
|
1033
|
+
en: `Exported ${bookId}.`,
|
|
1034
|
+
})),
|
|
1035
|
+
responseText: metadata.responseText ?? localize(language, {
|
|
1036
|
+
zh: `已导出 ${bookId}。`,
|
|
1037
|
+
en: `Exported ${bookId}.`,
|
|
1038
|
+
}),
|
|
1039
|
+
details: metadata.details,
|
|
1040
|
+
};
|
|
1041
|
+
}
|
|
1042
|
+
case "switch_mode":
|
|
1043
|
+
session = markCompleted(session);
|
|
1044
|
+
return {
|
|
1045
|
+
session: addEvent(session, "task.completed", "completed", localize(language, {
|
|
1046
|
+
zh: `已切换到${localizeMode(session.automationMode, language)}模式。`,
|
|
1047
|
+
en: `Switched mode to ${session.automationMode}.`,
|
|
1048
|
+
})),
|
|
1049
|
+
responseText: localize(language, {
|
|
1050
|
+
zh: `已切换到${localizeMode(session.automationMode, language)}模式。`,
|
|
1051
|
+
en: `Switched mode to ${session.automationMode}.`,
|
|
1052
|
+
}),
|
|
1053
|
+
};
|
|
1054
|
+
case "pause_book": {
|
|
1055
|
+
const bookId = request.bookId ?? session.activeBookId;
|
|
1056
|
+
const paused = {
|
|
1057
|
+
...session,
|
|
1058
|
+
currentExecution: {
|
|
1059
|
+
status: "blocked" as const,
|
|
1060
|
+
bookId,
|
|
1061
|
+
chapterNumber: session.activeChapterNumber,
|
|
1062
|
+
stageLabel: localize(language, {
|
|
1063
|
+
zh: "已由用户暂停",
|
|
1064
|
+
en: "paused by user",
|
|
1065
|
+
}),
|
|
1066
|
+
},
|
|
1067
|
+
};
|
|
1068
|
+
return {
|
|
1069
|
+
session: addEvent(paused, "task.completed", "blocked", localize(language, {
|
|
1070
|
+
zh: `已暂停${bookId ?? "当前作品"}。`,
|
|
1071
|
+
en: `Paused ${bookId ?? "current book"}.`,
|
|
1072
|
+
})),
|
|
1073
|
+
responseText: localize(language, {
|
|
1074
|
+
zh: `已暂停${bookId ?? "当前作品"}。`,
|
|
1075
|
+
en: `Paused ${bookId ?? "current book"}.`,
|
|
1076
|
+
}),
|
|
1077
|
+
};
|
|
1078
|
+
}
|
|
1079
|
+
case "resume_book": {
|
|
1080
|
+
const bookId = request.bookId ?? session.activeBookId;
|
|
1081
|
+
const resumed = {
|
|
1082
|
+
...session,
|
|
1083
|
+
currentExecution: {
|
|
1084
|
+
status: "completed" as const,
|
|
1085
|
+
bookId,
|
|
1086
|
+
chapterNumber: session.activeChapterNumber,
|
|
1087
|
+
stageLabel: localize(language, {
|
|
1088
|
+
zh: "可继续执行",
|
|
1089
|
+
en: "ready to continue",
|
|
1090
|
+
}),
|
|
1091
|
+
},
|
|
1092
|
+
};
|
|
1093
|
+
return {
|
|
1094
|
+
session: addEvent(resumed, "task.completed", "completed", localize(language, {
|
|
1095
|
+
zh: `已恢复${bookId ?? "当前作品"}。`,
|
|
1096
|
+
en: `Resumed ${bookId ?? "current book"}.`,
|
|
1097
|
+
})),
|
|
1098
|
+
responseText: localize(language, {
|
|
1099
|
+
zh: `已恢复${bookId ?? "当前作品"}。`,
|
|
1100
|
+
en: `Resumed ${bookId ?? "current book"}.`,
|
|
1101
|
+
}),
|
|
1102
|
+
};
|
|
1103
|
+
}
|
|
1104
|
+
case "chat": {
|
|
1105
|
+
const bookId = request.bookId ?? session.activeBookId;
|
|
1106
|
+
const prompt = request.instruction?.trim().toLowerCase() ?? "";
|
|
1107
|
+
const toolResult = params.tools.chat
|
|
1108
|
+
? await params.tools.chat(request.instruction ?? "", {
|
|
1109
|
+
bookId,
|
|
1110
|
+
automationMode: session.automationMode,
|
|
1111
|
+
})
|
|
1112
|
+
: undefined;
|
|
1113
|
+
const metadata = extractToolMetadata(toolResult);
|
|
1114
|
+
const responseText = metadata.responseText ?? (
|
|
1115
|
+
/^(hi|hello|hey|你好|嗨|哈喽)$/i.test(prompt)
|
|
1116
|
+
? (bookId
|
|
1117
|
+
? localize(language, {
|
|
1118
|
+
zh: `你好。当前作品是 ${bookId}。你可以让我继续写、修订章节,或者解释当前卡住的原因。`,
|
|
1119
|
+
en: `Hi. Active book is ${bookId}. Ask me to continue, revise a chapter, or explain what is blocked.`,
|
|
1120
|
+
})
|
|
1121
|
+
: localize(language, {
|
|
1122
|
+
zh: "你好。当前还没有激活作品。你可以先打开作品、列出作品,或者直接告诉我你要写什么。",
|
|
1123
|
+
en: "Hi. No active book yet. Open a book, list books, or tell me what you want to write.",
|
|
1124
|
+
}))
|
|
1125
|
+
: (bookId
|
|
1126
|
+
? localize(language, {
|
|
1127
|
+
zh: `我在。当前作品是 ${bookId}。你可以让我继续写、修订章节、重写、调整焦点,或者查看流水线为何停止。`,
|
|
1128
|
+
en: `I’m here. Active book is ${bookId}. You can ask me to continue, revise a chapter, rewrite, change focus, or inspect why the pipeline stopped.`,
|
|
1129
|
+
})
|
|
1130
|
+
: localize(language, {
|
|
1131
|
+
zh: "我在。当前还没有绑定作品。先打开作品、列出作品,或者直接描述你要写什么。",
|
|
1132
|
+
en: "I’m here. No active book is bound yet. Open a book, list books, or describe what you want to write.",
|
|
1133
|
+
}))
|
|
1134
|
+
);
|
|
1135
|
+
const completed = markCompleted(session);
|
|
1136
|
+
return {
|
|
1137
|
+
session: addEvent(completed, "task.completed", "completed", responseText),
|
|
1138
|
+
responseText,
|
|
1139
|
+
};
|
|
1140
|
+
}
|
|
1141
|
+
case "explain_status":
|
|
1142
|
+
case "explain_failure": {
|
|
1143
|
+
const bookId = request.bookId ?? session.activeBookId;
|
|
1144
|
+
const baselineExecution = params.session.currentExecution;
|
|
1145
|
+
const stage = baselineExecution?.stageLabel ?? baselineExecution?.status ?? "idle";
|
|
1146
|
+
const summary = request.intent === "explain_failure"
|
|
1147
|
+
? localize(language, {
|
|
1148
|
+
zh: `当前失败上下文:${bookId ?? "当前无激活作品"} 处于 ${stage}。`,
|
|
1149
|
+
en: `Current failure context: ${bookId ?? "no active book"} is at ${stage}.`,
|
|
1150
|
+
})
|
|
1151
|
+
: localize(language, {
|
|
1152
|
+
zh: `当前状态:${bookId ?? "当前无激活作品"} 处于 ${stage}。`,
|
|
1153
|
+
en: `Current status: ${bookId ?? "no active book"} is at ${stage}.`,
|
|
1154
|
+
});
|
|
1155
|
+
const completed = markCompleted(session);
|
|
1156
|
+
return {
|
|
1157
|
+
session: addEvent(completed, "task.completed", "completed", summary),
|
|
1158
|
+
responseText: summary,
|
|
1159
|
+
};
|
|
1160
|
+
}
|
|
1161
|
+
default:
|
|
1162
|
+
throw new Error(localize(language, {
|
|
1163
|
+
zh: `交互运行时暂未实现意图「${request.intent}」。`,
|
|
1164
|
+
en: `Intent "${request.intent}" is not implemented in the interaction runtime yet.`,
|
|
1165
|
+
}));
|
|
1166
|
+
}
|
|
1167
|
+
}
|