@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,704 @@
|
|
|
1
|
+
import { mkdir, readFile, readdir, writeFile } from "node:fs/promises";
|
|
2
|
+
import { dirname, join } from "node:path";
|
|
3
|
+
import type {
|
|
4
|
+
InteractionEvent,
|
|
5
|
+
Logger,
|
|
6
|
+
PipelineRunner,
|
|
7
|
+
StateManager,
|
|
8
|
+
ReviseMode,
|
|
9
|
+
LLMClient,
|
|
10
|
+
BookConfig,
|
|
11
|
+
ToolDefinition,
|
|
12
|
+
} from "../index.js";
|
|
13
|
+
import { chatCompletion, chatWithTools } from "../index.js";
|
|
14
|
+
import { executeEditTransaction } from "./edit-controller.js";
|
|
15
|
+
import type { InteractionRuntimeTools } from "./runtime.js";
|
|
16
|
+
import type { BookCreationDraft } from "./session.js";
|
|
17
|
+
import { writeExportArtifact } from "./export-artifact.js";
|
|
18
|
+
import { safeChildPath } from "../utils/path-safety.js";
|
|
19
|
+
import { deriveBookIdFromTitle } from "../utils/book-id.js";
|
|
20
|
+
import { normalizePlatformOrOther } from "../models/book.js";
|
|
21
|
+
|
|
22
|
+
const SAFE_TRUTH_FLAT_FILE_NAMES = new Set([
|
|
23
|
+
"author_intent.md",
|
|
24
|
+
"current_focus.md",
|
|
25
|
+
"story_bible.md",
|
|
26
|
+
"volume_outline.md",
|
|
27
|
+
"book_rules.md",
|
|
28
|
+
"particle_ledger.md",
|
|
29
|
+
"subplot_board.md",
|
|
30
|
+
"emotional_arcs.md",
|
|
31
|
+
"style_guide.md",
|
|
32
|
+
"parent_canon.md",
|
|
33
|
+
"fanfic_canon.md",
|
|
34
|
+
"character_matrix.md",
|
|
35
|
+
"current_state.md",
|
|
36
|
+
"pending_hooks.md",
|
|
37
|
+
"chapter_summaries.md",
|
|
38
|
+
]);
|
|
39
|
+
|
|
40
|
+
const SAFE_TRUTH_OUTLINE_FILE_NAMES = new Set([
|
|
41
|
+
"outline/story_frame.md",
|
|
42
|
+
"outline/volume_map.md",
|
|
43
|
+
"outline/节奏原则.md",
|
|
44
|
+
"outline/rhythm_principles.md",
|
|
45
|
+
]);
|
|
46
|
+
|
|
47
|
+
const SAFE_ROLE_TRUTH_FILE_RE = /^roles\/(主要角色|次要角色|major|minor)\/[^/\\]+\.md$/u;
|
|
48
|
+
|
|
49
|
+
export function assertSafeTruthFileName(fileName: string): string {
|
|
50
|
+
const trimmed = fileName.trim();
|
|
51
|
+
const withExtension = trimmed.endsWith(".md") ? trimmed : `${trimmed}.md`;
|
|
52
|
+
const lower = withExtension.toLowerCase();
|
|
53
|
+
if (
|
|
54
|
+
!trimmed ||
|
|
55
|
+
withExtension.startsWith("/") ||
|
|
56
|
+
withExtension.includes("\\") ||
|
|
57
|
+
withExtension.includes("\0") ||
|
|
58
|
+
withExtension.includes("..")
|
|
59
|
+
) {
|
|
60
|
+
throw new Error(`Invalid truth file name: ${JSON.stringify(fileName)}`);
|
|
61
|
+
}
|
|
62
|
+
if (SAFE_TRUTH_FLAT_FILE_NAMES.has(lower)) return lower;
|
|
63
|
+
if (SAFE_TRUTH_OUTLINE_FILE_NAMES.has(lower)) return lower;
|
|
64
|
+
if (SAFE_ROLE_TRUTH_FILE_RE.test(withExtension)) return withExtension;
|
|
65
|
+
throw new Error(`Invalid truth file name: ${JSON.stringify(fileName)}`);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
type PipelineLike = Pick<PipelineRunner, "writeNextChapter" | "reviseDraft"> & {
|
|
69
|
+
readonly initBook?: (
|
|
70
|
+
book: BookConfig,
|
|
71
|
+
options?: {
|
|
72
|
+
readonly externalContext?: string;
|
|
73
|
+
readonly authorIntent?: string;
|
|
74
|
+
readonly currentFocus?: string;
|
|
75
|
+
},
|
|
76
|
+
) => Promise<void>;
|
|
77
|
+
};
|
|
78
|
+
type StateLike = Pick<StateManager, "ensureControlDocuments" | "bookDir" | "loadBookConfig" | "loadChapterIndex" | "saveChapterIndex" | "listBooks">;
|
|
79
|
+
type InstrumentablePipelineLike = PipelineLike & {
|
|
80
|
+
readonly config?: {
|
|
81
|
+
logger?: Logger;
|
|
82
|
+
client?: LLMClient;
|
|
83
|
+
model?: string;
|
|
84
|
+
};
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
function buildBookConfig(input: {
|
|
88
|
+
readonly title: string;
|
|
89
|
+
readonly genre?: string;
|
|
90
|
+
readonly platform?: string;
|
|
91
|
+
readonly language?: "zh" | "en";
|
|
92
|
+
readonly chapterWordCount?: number;
|
|
93
|
+
readonly targetChapters?: number;
|
|
94
|
+
}): BookConfig {
|
|
95
|
+
const now = new Date().toISOString();
|
|
96
|
+
return {
|
|
97
|
+
id: deriveBookIdFromTitle(input.title) || `book-${Date.now().toString(36)}`,
|
|
98
|
+
title: input.title,
|
|
99
|
+
platform: normalizePlatformOrOther(input.platform),
|
|
100
|
+
genre: input.genre ?? "other",
|
|
101
|
+
status: "outlining",
|
|
102
|
+
targetChapters: input.targetChapters ?? 200,
|
|
103
|
+
chapterWordCount: input.chapterWordCount ?? 3000,
|
|
104
|
+
...(input.language ? { language: input.language } : {}),
|
|
105
|
+
createdAt: now,
|
|
106
|
+
updatedAt: now,
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function buildCreationExternalContext(input: {
|
|
111
|
+
readonly blurb?: string;
|
|
112
|
+
readonly worldPremise?: string;
|
|
113
|
+
readonly settingNotes?: string;
|
|
114
|
+
readonly protagonist?: string;
|
|
115
|
+
readonly supportingCast?: string;
|
|
116
|
+
readonly conflictCore?: string;
|
|
117
|
+
readonly volumeOutline?: string;
|
|
118
|
+
readonly constraints?: string;
|
|
119
|
+
}): string | undefined {
|
|
120
|
+
const sections = [
|
|
121
|
+
input.worldPremise ? `## 世界观与核心设定\n${input.worldPremise}` : undefined,
|
|
122
|
+
input.settingNotes ? `## 补充设定\n${input.settingNotes}` : undefined,
|
|
123
|
+
input.protagonist ? `## 主角设定\n${input.protagonist}` : undefined,
|
|
124
|
+
input.supportingCast ? `## 关键角色与势力\n${input.supportingCast}` : undefined,
|
|
125
|
+
input.conflictCore ? `## 核心冲突\n${input.conflictCore}` : undefined,
|
|
126
|
+
input.volumeOutline ? `## 卷纲方向\n${input.volumeOutline}` : undefined,
|
|
127
|
+
input.blurb ? `## 简介卖点\n${input.blurb}` : undefined,
|
|
128
|
+
input.constraints ? `## 创作约束\n${input.constraints}` : undefined,
|
|
129
|
+
].filter((section): section is string => Boolean(section?.trim()));
|
|
130
|
+
|
|
131
|
+
if (sections.length === 0) {
|
|
132
|
+
return undefined;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
return sections.join("\n\n");
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export function buildChapterFileLookup(files: ReadonlyArray<string>): ReadonlyMap<number, string> {
|
|
139
|
+
const lookup = new Map<number, string>();
|
|
140
|
+
for (const file of files) {
|
|
141
|
+
if (!file.endsWith(".md") || !/^\d{4}/.test(file)) {
|
|
142
|
+
continue;
|
|
143
|
+
}
|
|
144
|
+
const chapterNumber = parseInt(file.slice(0, 4), 10);
|
|
145
|
+
if (!lookup.has(chapterNumber)) {
|
|
146
|
+
lookup.set(chapterNumber, file);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
return lookup;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
async function exportBookToPath(state: StateLike, bookId: string, options: {
|
|
153
|
+
readonly format?: "txt" | "md" | "epub";
|
|
154
|
+
readonly approvedOnly?: boolean;
|
|
155
|
+
readonly outputPath?: string;
|
|
156
|
+
}) {
|
|
157
|
+
return writeExportArtifact(state, bookId, options);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
function mapStageMessageToStatus(message: string): InteractionEvent["status"] | undefined {
|
|
161
|
+
const lower = message.trim().toLowerCase();
|
|
162
|
+
if (
|
|
163
|
+
lower.includes("planning next chapter")
|
|
164
|
+
|| lower.includes("generating foundation")
|
|
165
|
+
|| lower.includes("reviewing foundation")
|
|
166
|
+
|| lower.includes("preparing chapter inputs")
|
|
167
|
+
|| message.includes("规划下一章意图")
|
|
168
|
+
|| message.includes("生成基础设定")
|
|
169
|
+
|| message.includes("审核基础设定")
|
|
170
|
+
|| message.includes("准备章节输入")
|
|
171
|
+
) {
|
|
172
|
+
return "planning";
|
|
173
|
+
}
|
|
174
|
+
if (
|
|
175
|
+
lower.includes("composing chapter runtime context")
|
|
176
|
+
|| message.includes("组装章节运行时上下文")
|
|
177
|
+
) {
|
|
178
|
+
return "composing";
|
|
179
|
+
}
|
|
180
|
+
if (
|
|
181
|
+
lower.includes("writing chapter draft")
|
|
182
|
+
|| message.includes("撰写章节草稿")
|
|
183
|
+
) {
|
|
184
|
+
return "writing";
|
|
185
|
+
}
|
|
186
|
+
if (
|
|
187
|
+
lower.includes("auditing draft")
|
|
188
|
+
|| message.includes("审计草稿")
|
|
189
|
+
) {
|
|
190
|
+
return "assessing";
|
|
191
|
+
}
|
|
192
|
+
if (
|
|
193
|
+
lower.includes("fixing")
|
|
194
|
+
|| lower.includes("revising chapter")
|
|
195
|
+
|| lower.includes("rewrite")
|
|
196
|
+
|| lower.includes("repair")
|
|
197
|
+
|| message.includes("自动修复")
|
|
198
|
+
|| message.includes("整章改写")
|
|
199
|
+
|| message.includes("修订第")
|
|
200
|
+
) {
|
|
201
|
+
return "repairing";
|
|
202
|
+
}
|
|
203
|
+
if (
|
|
204
|
+
lower.includes("persist")
|
|
205
|
+
|| lower.includes("saving")
|
|
206
|
+
|| lower.includes("snapshot")
|
|
207
|
+
|| lower.includes("rebuilding final truth files")
|
|
208
|
+
|| lower.includes("validating truth file updates")
|
|
209
|
+
|| lower.includes("syncing memory indexes")
|
|
210
|
+
|| message.includes("落盘")
|
|
211
|
+
|| message.includes("保存")
|
|
212
|
+
|| message.includes("快照")
|
|
213
|
+
|| message.includes("校验真相文件变更")
|
|
214
|
+
|| message.includes("生成最终真相文件")
|
|
215
|
+
|| message.includes("同步记忆索引")
|
|
216
|
+
) {
|
|
217
|
+
return "persisting";
|
|
218
|
+
}
|
|
219
|
+
return undefined;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
function extractStageDetail(message: string): string | undefined {
|
|
223
|
+
if (message.startsWith("Stage: ")) {
|
|
224
|
+
return message.slice("Stage: ".length).trim();
|
|
225
|
+
}
|
|
226
|
+
if (message.startsWith("阶段:")) {
|
|
227
|
+
return message.slice("阶段:".length).trim();
|
|
228
|
+
}
|
|
229
|
+
return undefined;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
function createInteractionLogger(
|
|
233
|
+
original: Logger | undefined,
|
|
234
|
+
events: InteractionEvent[],
|
|
235
|
+
bookId: string,
|
|
236
|
+
): Logger {
|
|
237
|
+
const emit = (level: "debug" | "info" | "warn" | "error", message: string): void => {
|
|
238
|
+
const stageDetail = extractStageDetail(message);
|
|
239
|
+
const stageStatus = stageDetail ? mapStageMessageToStatus(stageDetail) : undefined;
|
|
240
|
+
|
|
241
|
+
if (stageDetail && stageStatus) {
|
|
242
|
+
events.push({
|
|
243
|
+
kind: "stage.changed",
|
|
244
|
+
timestamp: Date.now(),
|
|
245
|
+
status: stageStatus,
|
|
246
|
+
bookId,
|
|
247
|
+
detail: stageDetail,
|
|
248
|
+
});
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
if (level === "warn") {
|
|
253
|
+
events.push({
|
|
254
|
+
kind: "task.warning",
|
|
255
|
+
timestamp: Date.now(),
|
|
256
|
+
status: "blocked",
|
|
257
|
+
bookId,
|
|
258
|
+
detail: message,
|
|
259
|
+
});
|
|
260
|
+
return;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
if (level === "error") {
|
|
264
|
+
events.push({
|
|
265
|
+
kind: "task.failed",
|
|
266
|
+
timestamp: Date.now(),
|
|
267
|
+
status: "failed",
|
|
268
|
+
bookId,
|
|
269
|
+
detail: message,
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
};
|
|
273
|
+
|
|
274
|
+
const wrap = (base: Logger | undefined): Logger => ({
|
|
275
|
+
debug: (msg, ctx) => {
|
|
276
|
+
emit("debug", msg);
|
|
277
|
+
base?.debug(msg, ctx);
|
|
278
|
+
},
|
|
279
|
+
info: (msg, ctx) => {
|
|
280
|
+
emit("info", msg);
|
|
281
|
+
base?.info(msg, ctx);
|
|
282
|
+
},
|
|
283
|
+
warn: (msg, ctx) => {
|
|
284
|
+
emit("warn", msg);
|
|
285
|
+
base?.warn(msg, ctx);
|
|
286
|
+
},
|
|
287
|
+
error: (msg, ctx) => {
|
|
288
|
+
emit("error", msg);
|
|
289
|
+
base?.error(msg, ctx);
|
|
290
|
+
},
|
|
291
|
+
child: (tag, extraCtx) => wrap(base?.child(tag, extraCtx)),
|
|
292
|
+
});
|
|
293
|
+
|
|
294
|
+
return wrap(original);
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
async function withPipelineInteractionTelemetry<T extends { chapterNumber?: number }>(
|
|
298
|
+
pipeline: InstrumentablePipelineLike,
|
|
299
|
+
bookId: string,
|
|
300
|
+
executor: () => Promise<T>,
|
|
301
|
+
): Promise<T & {
|
|
302
|
+
__interaction: {
|
|
303
|
+
events: ReadonlyArray<InteractionEvent>;
|
|
304
|
+
activeChapterNumber?: number;
|
|
305
|
+
};
|
|
306
|
+
}> {
|
|
307
|
+
const events: InteractionEvent[] = [];
|
|
308
|
+
const originalLogger = pipeline.config?.logger;
|
|
309
|
+
if (pipeline.config) {
|
|
310
|
+
pipeline.config.logger = createInteractionLogger(originalLogger, events, bookId);
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
try {
|
|
314
|
+
const result = await executor();
|
|
315
|
+
return {
|
|
316
|
+
...result,
|
|
317
|
+
__interaction: {
|
|
318
|
+
events,
|
|
319
|
+
...(typeof result.chapterNumber === "number"
|
|
320
|
+
? { activeChapterNumber: result.chapterNumber }
|
|
321
|
+
: {}),
|
|
322
|
+
},
|
|
323
|
+
};
|
|
324
|
+
} finally {
|
|
325
|
+
if (pipeline.config) {
|
|
326
|
+
pipeline.config.logger = originalLogger;
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
const CREATE_BOOK_TOOL: ToolDefinition = {
|
|
332
|
+
name: "create_book",
|
|
333
|
+
description: "根据用户描述生成建书参数。系统会将参数渲染为可编辑表单,用户确认后建书。",
|
|
334
|
+
parameters: {
|
|
335
|
+
type: "object",
|
|
336
|
+
properties: {
|
|
337
|
+
title: { type: "string", description: "书名" },
|
|
338
|
+
genre: { type: "string", description: "题材标识,如 xuanhuan, urban, romance, scifi, mystery" },
|
|
339
|
+
platform: { type: "string", enum: ["tomato", "qidian", "feilu", "other"], description: "发布平台" },
|
|
340
|
+
targetChapters: { type: "number", description: "目标章数,默认 200" },
|
|
341
|
+
chapterWordCount: { type: "number", description: "每章字数,默认 3000" },
|
|
342
|
+
language: { type: "string", enum: ["zh", "en"], description: "写作语言,默认 zh" },
|
|
343
|
+
brief: { type: "string", description: "创意简述,会传给 Architect 智能体生成完整的世界观、主角、冲突等 foundation 文件。把用户提到的所有创意要素都写进这里。" },
|
|
344
|
+
},
|
|
345
|
+
required: ["title", "genre", "platform", "brief"],
|
|
346
|
+
},
|
|
347
|
+
};
|
|
348
|
+
|
|
349
|
+
const BOOK_DRAFT_SYSTEM_PROMPT = [
|
|
350
|
+
"你是 InkOS 的建书助手。用户会描述想写的书,你需要调用 create_book 工具来生成建书参数。",
|
|
351
|
+
"",
|
|
352
|
+
"规则:",
|
|
353
|
+
"1. 从用户描述中推断所有字段,大胆预填合理默认值。",
|
|
354
|
+
"2. brief 字段要详细——它会传给 Architect 智能体生成完整的世界观、主角、冲突等 foundation 文件。把用户提到的所有创意要素都写进 brief。",
|
|
355
|
+
"3. 如果用户后续要求修改某些字段,重新调用 create_book 工具,只更新被提到的字段,其余保持不变。",
|
|
356
|
+
"4. 不要只回复文字讨论——必须调用 create_book 工具输出结构化参数。",
|
|
357
|
+
].join("\n");
|
|
358
|
+
|
|
359
|
+
/** Map directive field keys to BookCreationDraft property names. */
|
|
360
|
+
function applyFieldsToDraft(
|
|
361
|
+
existing: BookCreationDraft | undefined,
|
|
362
|
+
fields: Readonly<Record<string, string>>,
|
|
363
|
+
concept: string,
|
|
364
|
+
): BookCreationDraft {
|
|
365
|
+
const draft: BookCreationDraft = {
|
|
366
|
+
concept,
|
|
367
|
+
missingFields: [],
|
|
368
|
+
readyToCreate: false,
|
|
369
|
+
...(existing ?? {}),
|
|
370
|
+
};
|
|
371
|
+
|
|
372
|
+
for (const [key, value] of Object.entries(fields)) {
|
|
373
|
+
if (!value) continue;
|
|
374
|
+
|
|
375
|
+
switch (key) {
|
|
376
|
+
case "title":
|
|
377
|
+
draft.title = value;
|
|
378
|
+
break;
|
|
379
|
+
case "genre":
|
|
380
|
+
draft.genre = value;
|
|
381
|
+
break;
|
|
382
|
+
case "platform":
|
|
383
|
+
draft.platform = value;
|
|
384
|
+
break;
|
|
385
|
+
case "language":
|
|
386
|
+
if (value === "zh" || value === "en") draft.language = value;
|
|
387
|
+
break;
|
|
388
|
+
case "targetChapters": {
|
|
389
|
+
const n = parseInt(value, 10);
|
|
390
|
+
if (!Number.isNaN(n) && n > 0) draft.targetChapters = n;
|
|
391
|
+
break;
|
|
392
|
+
}
|
|
393
|
+
case "chapterWordCount":
|
|
394
|
+
case "chapterLength": {
|
|
395
|
+
const n = parseInt(value, 10);
|
|
396
|
+
if (!Number.isNaN(n) && n > 0) draft.chapterWordCount = n;
|
|
397
|
+
break;
|
|
398
|
+
}
|
|
399
|
+
case "blurb":
|
|
400
|
+
draft.blurb = value;
|
|
401
|
+
break;
|
|
402
|
+
case "worldPremise":
|
|
403
|
+
draft.worldPremise = value;
|
|
404
|
+
break;
|
|
405
|
+
case "settingNotes":
|
|
406
|
+
draft.settingNotes = value;
|
|
407
|
+
break;
|
|
408
|
+
case "protagonist":
|
|
409
|
+
draft.protagonist = value;
|
|
410
|
+
break;
|
|
411
|
+
case "supportingCast":
|
|
412
|
+
draft.supportingCast = value;
|
|
413
|
+
break;
|
|
414
|
+
case "conflictCore":
|
|
415
|
+
draft.conflictCore = value;
|
|
416
|
+
break;
|
|
417
|
+
case "volumeOutline":
|
|
418
|
+
draft.volumeOutline = value;
|
|
419
|
+
break;
|
|
420
|
+
case "constraints":
|
|
421
|
+
draft.constraints = value;
|
|
422
|
+
break;
|
|
423
|
+
case "authorIntent":
|
|
424
|
+
draft.authorIntent = value;
|
|
425
|
+
break;
|
|
426
|
+
case "currentFocus":
|
|
427
|
+
draft.currentFocus = value;
|
|
428
|
+
break;
|
|
429
|
+
// Unknown keys are silently ignored — the LLM may emit
|
|
430
|
+
// application-level keys we don't map to the draft struct.
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
return draft;
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
function formatDraftForUserMessage(
|
|
438
|
+
existingDraft: BookCreationDraft | undefined,
|
|
439
|
+
userMessage: string,
|
|
440
|
+
): string {
|
|
441
|
+
const parts: string[] = [];
|
|
442
|
+
|
|
443
|
+
if (existingDraft) {
|
|
444
|
+
parts.push("## 当前草案状态");
|
|
445
|
+
const entries = Object.entries(existingDraft).filter(
|
|
446
|
+
([, v]) => v !== undefined && v !== "" && !(Array.isArray(v) && v.length === 0),
|
|
447
|
+
);
|
|
448
|
+
for (const [key, value] of entries) {
|
|
449
|
+
parts.push(`- **${key}**: ${typeof value === "object" ? JSON.stringify(value) : String(value)}`);
|
|
450
|
+
}
|
|
451
|
+
parts.push("");
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
parts.push("## 用户输入");
|
|
455
|
+
parts.push(userMessage);
|
|
456
|
+
|
|
457
|
+
return parts.join("\n");
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
export function createInteractionToolsFromDeps(
|
|
461
|
+
pipeline: PipelineLike,
|
|
462
|
+
state: StateLike,
|
|
463
|
+
hooks?: {
|
|
464
|
+
readonly onChatTextDelta?: (text: string) => void;
|
|
465
|
+
readonly onDraftTextDelta?: (text: string) => void;
|
|
466
|
+
readonly onDraftRawDelta?: (text: string) => void;
|
|
467
|
+
readonly getChatRequestOptions?: () => {
|
|
468
|
+
readonly temperature?: number;
|
|
469
|
+
readonly maxTokens?: number;
|
|
470
|
+
};
|
|
471
|
+
},
|
|
472
|
+
): InteractionRuntimeTools {
|
|
473
|
+
const instrumentedPipeline = pipeline as InstrumentablePipelineLike;
|
|
474
|
+
|
|
475
|
+
return {
|
|
476
|
+
listBooks: () => state.listBooks(),
|
|
477
|
+
developBookDraft: async (input, existingDraft) => {
|
|
478
|
+
const concept = existingDraft?.concept ?? input;
|
|
479
|
+
|
|
480
|
+
if (!instrumentedPipeline.config?.client || !instrumentedPipeline.config?.model) {
|
|
481
|
+
// Fallback: no LLM configured
|
|
482
|
+
return {
|
|
483
|
+
__interaction: {
|
|
484
|
+
responseText: "请先配置 LLM 模型,然后再创建书籍。",
|
|
485
|
+
details: {
|
|
486
|
+
creationDraft: {
|
|
487
|
+
concept,
|
|
488
|
+
missingFields: ["title", "genre", "targetChapters"],
|
|
489
|
+
readyToCreate: false,
|
|
490
|
+
},
|
|
491
|
+
},
|
|
492
|
+
},
|
|
493
|
+
};
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
// Build messages - include existing draft context if present
|
|
497
|
+
const userContent = existingDraft
|
|
498
|
+
? `当前草案参数:${JSON.stringify(existingDraft, null, 2)}\n\n用户输入:${input}`
|
|
499
|
+
: input;
|
|
500
|
+
|
|
501
|
+
const result = await chatWithTools(
|
|
502
|
+
instrumentedPipeline.config.client,
|
|
503
|
+
instrumentedPipeline.config.model,
|
|
504
|
+
[
|
|
505
|
+
{ role: "system", content: BOOK_DRAFT_SYSTEM_PROMPT },
|
|
506
|
+
{ role: "user", content: userContent },
|
|
507
|
+
],
|
|
508
|
+
[CREATE_BOOK_TOOL],
|
|
509
|
+
{ temperature: 0.4 },
|
|
510
|
+
);
|
|
511
|
+
|
|
512
|
+
// Extract tool call if present
|
|
513
|
+
const toolCall = result.toolCalls[0];
|
|
514
|
+
let parsedArgs: Record<string, unknown> = {};
|
|
515
|
+
if (toolCall) {
|
|
516
|
+
try {
|
|
517
|
+
parsedArgs = JSON.parse(toolCall.arguments);
|
|
518
|
+
} catch {
|
|
519
|
+
// If parsing fails, use empty args
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
// Build a draft from tool call arguments
|
|
524
|
+
const draft: BookCreationDraft = {
|
|
525
|
+
concept,
|
|
526
|
+
title: (parsedArgs.title as string) ?? existingDraft?.title,
|
|
527
|
+
genre: (parsedArgs.genre as string) ?? existingDraft?.genre,
|
|
528
|
+
platform: (parsedArgs.platform as string) ?? existingDraft?.platform,
|
|
529
|
+
language: (parsedArgs.language as "zh" | "en") ?? existingDraft?.language,
|
|
530
|
+
targetChapters: (parsedArgs.targetChapters as number) ?? existingDraft?.targetChapters,
|
|
531
|
+
chapterWordCount: (parsedArgs.chapterWordCount as number) ?? existingDraft?.chapterWordCount,
|
|
532
|
+
blurb: (parsedArgs.brief as string) ?? existingDraft?.blurb,
|
|
533
|
+
missingFields: [],
|
|
534
|
+
readyToCreate: Boolean(parsedArgs.title && parsedArgs.genre && parsedArgs.platform),
|
|
535
|
+
};
|
|
536
|
+
|
|
537
|
+
return {
|
|
538
|
+
__interaction: {
|
|
539
|
+
responseText: result.content || "已生成建书参数,请确认或修改。",
|
|
540
|
+
details: {
|
|
541
|
+
creationDraft: draft,
|
|
542
|
+
toolCall: toolCall ? { name: toolCall.name, arguments: parsedArgs } : undefined,
|
|
543
|
+
},
|
|
544
|
+
},
|
|
545
|
+
};
|
|
546
|
+
},
|
|
547
|
+
createBook: async (input) => {
|
|
548
|
+
const book = buildBookConfig(input);
|
|
549
|
+
if (!pipeline.initBook) {
|
|
550
|
+
throw new Error("Pipeline does not support shared book creation.");
|
|
551
|
+
}
|
|
552
|
+
await pipeline.initBook(book, {
|
|
553
|
+
externalContext: buildCreationExternalContext(input),
|
|
554
|
+
authorIntent: input.authorIntent,
|
|
555
|
+
currentFocus: input.currentFocus,
|
|
556
|
+
});
|
|
557
|
+
return {
|
|
558
|
+
bookId: book.id,
|
|
559
|
+
title: book.title,
|
|
560
|
+
__interaction: {
|
|
561
|
+
responseText: `Created ${book.title} (${book.id}).`,
|
|
562
|
+
details: {
|
|
563
|
+
bookId: book.id,
|
|
564
|
+
title: book.title,
|
|
565
|
+
},
|
|
566
|
+
},
|
|
567
|
+
};
|
|
568
|
+
},
|
|
569
|
+
exportBook: async (bookId, options) => {
|
|
570
|
+
const result = await exportBookToPath(state, bookId, options);
|
|
571
|
+
return {
|
|
572
|
+
...result,
|
|
573
|
+
__interaction: {
|
|
574
|
+
responseText: `Exported ${bookId} to ${result.outputPath} (${result.chaptersExported} chapters).`,
|
|
575
|
+
details: {
|
|
576
|
+
outputPath: result.outputPath,
|
|
577
|
+
chaptersExported: result.chaptersExported,
|
|
578
|
+
totalWords: result.totalWords,
|
|
579
|
+
format: result.format,
|
|
580
|
+
},
|
|
581
|
+
},
|
|
582
|
+
};
|
|
583
|
+
},
|
|
584
|
+
chat: async (input, options) => {
|
|
585
|
+
const bookLabel = options.bookId ?? "none";
|
|
586
|
+
const chatRequestOptions = hooks?.getChatRequestOptions?.() ?? {};
|
|
587
|
+
let response: Awaited<ReturnType<typeof chatCompletion>> | undefined;
|
|
588
|
+
if (instrumentedPipeline.config?.client && instrumentedPipeline.config?.model) {
|
|
589
|
+
try {
|
|
590
|
+
response = await chatCompletion(
|
|
591
|
+
instrumentedPipeline.config.client,
|
|
592
|
+
instrumentedPipeline.config.model,
|
|
593
|
+
[
|
|
594
|
+
{
|
|
595
|
+
role: "system",
|
|
596
|
+
content: [
|
|
597
|
+
"You are InkOS inside the terminal workbench.",
|
|
598
|
+
"Respond conversationally and briefly.",
|
|
599
|
+
"If there is no active book, help the user decide what to write next.",
|
|
600
|
+
"If there is an active book, keep the answer grounded in that book context.",
|
|
601
|
+
].join(" "),
|
|
602
|
+
},
|
|
603
|
+
{
|
|
604
|
+
role: "user",
|
|
605
|
+
content: `activeBook=${bookLabel}\nautomationMode=${options.automationMode}\nmessage=${input}`,
|
|
606
|
+
},
|
|
607
|
+
],
|
|
608
|
+
{
|
|
609
|
+
temperature: chatRequestOptions.temperature ?? 0.4,
|
|
610
|
+
...(chatRequestOptions.maxTokens !== undefined && { maxTokens: chatRequestOptions.maxTokens }),
|
|
611
|
+
onTextDelta: hooks?.onChatTextDelta,
|
|
612
|
+
},
|
|
613
|
+
);
|
|
614
|
+
} catch (err) {
|
|
615
|
+
// Thinking models (e.g. kimi-k2.5) may return empty content for simple inputs.
|
|
616
|
+
// Only swallow empty-content errors; re-throw everything else (network, auth, etc.)
|
|
617
|
+
const msg = err instanceof Error ? err.message : "";
|
|
618
|
+
if (!msg.includes("empty") && !msg.includes("content")) {
|
|
619
|
+
throw err;
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
return {
|
|
625
|
+
__interaction: {
|
|
626
|
+
responseText: response?.content?.trim()
|
|
627
|
+
|| (options.bookId
|
|
628
|
+
? `I’m here. Active book is ${options.bookId}.`
|
|
629
|
+
: "I’m here. No active book yet."),
|
|
630
|
+
},
|
|
631
|
+
};
|
|
632
|
+
},
|
|
633
|
+
writeNextChapter: (bookId) => withPipelineInteractionTelemetry(
|
|
634
|
+
instrumentedPipeline,
|
|
635
|
+
bookId,
|
|
636
|
+
() => pipeline.writeNextChapter(bookId),
|
|
637
|
+
),
|
|
638
|
+
reviseDraft: (bookId, chapterNumber, mode) => withPipelineInteractionTelemetry(
|
|
639
|
+
instrumentedPipeline,
|
|
640
|
+
bookId,
|
|
641
|
+
() => pipeline.reviseDraft(bookId, chapterNumber, mode as ReviseMode),
|
|
642
|
+
),
|
|
643
|
+
patchChapterText: async (bookId, chapterNumber, targetText, replacementText) => {
|
|
644
|
+
const execution = await executeEditTransaction(
|
|
645
|
+
{
|
|
646
|
+
bookDir: (targetBookId) => state.bookDir(targetBookId),
|
|
647
|
+
loadChapterIndex: (targetBookId) => state.loadChapterIndex(targetBookId),
|
|
648
|
+
saveChapterIndex: (targetBookId, index) => state.saveChapterIndex(targetBookId, index),
|
|
649
|
+
},
|
|
650
|
+
{
|
|
651
|
+
kind: "chapter-local-edit",
|
|
652
|
+
bookId,
|
|
653
|
+
chapterNumber,
|
|
654
|
+
instruction: `Replace ${targetText} with ${replacementText}`,
|
|
655
|
+
targetText,
|
|
656
|
+
replacementText,
|
|
657
|
+
},
|
|
658
|
+
);
|
|
659
|
+
return {
|
|
660
|
+
__interaction: {
|
|
661
|
+
activeChapterNumber: chapterNumber,
|
|
662
|
+
responseText: execution.summary,
|
|
663
|
+
},
|
|
664
|
+
};
|
|
665
|
+
},
|
|
666
|
+
renameEntity: async (bookId, oldValue, newValue) => {
|
|
667
|
+
const execution = await executeEditTransaction(
|
|
668
|
+
{
|
|
669
|
+
bookDir: (targetBookId) => state.bookDir(targetBookId),
|
|
670
|
+
loadChapterIndex: (targetBookId) => state.loadChapterIndex(targetBookId),
|
|
671
|
+
saveChapterIndex: (targetBookId, index) => state.saveChapterIndex(targetBookId, index),
|
|
672
|
+
},
|
|
673
|
+
{
|
|
674
|
+
kind: "entity-rename",
|
|
675
|
+
bookId,
|
|
676
|
+
entityType: "character",
|
|
677
|
+
oldValue,
|
|
678
|
+
newValue,
|
|
679
|
+
},
|
|
680
|
+
);
|
|
681
|
+
return {
|
|
682
|
+
__interaction: {
|
|
683
|
+
responseText: execution.summary,
|
|
684
|
+
},
|
|
685
|
+
};
|
|
686
|
+
},
|
|
687
|
+
updateCurrentFocus: async (bookId, content) => {
|
|
688
|
+
await state.ensureControlDocuments(bookId);
|
|
689
|
+
await writeFile(join(state.bookDir(bookId), "story", "current_focus.md"), content, "utf-8");
|
|
690
|
+
},
|
|
691
|
+
updateAuthorIntent: async (bookId, content) => {
|
|
692
|
+
await state.ensureControlDocuments(bookId);
|
|
693
|
+
await writeFile(join(state.bookDir(bookId), "story", "author_intent.md"), content, "utf-8");
|
|
694
|
+
},
|
|
695
|
+
writeTruthFile: async (bookId, fileName, content) => {
|
|
696
|
+
await state.ensureControlDocuments(bookId);
|
|
697
|
+
const storyDir = join(state.bookDir(bookId), "story");
|
|
698
|
+
const safeFileName = assertSafeTruthFileName(fileName);
|
|
699
|
+
const targetPath = safeChildPath(storyDir, safeFileName);
|
|
700
|
+
await mkdir(dirname(targetPath), { recursive: true });
|
|
701
|
+
await writeFile(targetPath, content, "utf-8");
|
|
702
|
+
},
|
|
703
|
+
};
|
|
704
|
+
}
|