@kienmatu/inkos-core 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +661 -0
- package/dist/agent/agent-session.d.ts +100 -0
- package/dist/agent/agent-session.d.ts.map +1 -0
- package/dist/agent/agent-session.js +1102 -0
- package/dist/agent/agent-session.js.map +1 -0
- package/dist/agent/agent-system-prompt.d.ts +12 -0
- package/dist/agent/agent-system-prompt.d.ts.map +1 -0
- package/dist/agent/agent-system-prompt.js +596 -0
- package/dist/agent/agent-system-prompt.js.map +1 -0
- package/dist/agent/agent-tools.d.ts +508 -0
- package/dist/agent/agent-tools.d.ts.map +1 -0
- package/dist/agent/agent-tools.js +3083 -0
- package/dist/agent/agent-tools.js.map +1 -0
- package/dist/agent/chapter-import-source.d.ts +16 -0
- package/dist/agent/chapter-import-source.d.ts.map +1 -0
- package/dist/agent/chapter-import-source.js +48 -0
- package/dist/agent/chapter-import-source.js.map +1 -0
- package/dist/agent/context-transform.d.ts +13 -0
- package/dist/agent/context-transform.d.ts.map +1 -0
- package/dist/agent/context-transform.js +183 -0
- package/dist/agent/context-transform.js.map +1 -0
- package/dist/agent/film-authoring-tools.d.ts +98 -0
- package/dist/agent/film-authoring-tools.d.ts.map +1 -0
- package/dist/agent/film-authoring-tools.js +405 -0
- package/dist/agent/film-authoring-tools.js.map +1 -0
- package/dist/agent/forecast-tools.d.ts +22 -0
- package/dist/agent/forecast-tools.d.ts.map +1 -0
- package/dist/agent/forecast-tools.js +153 -0
- package/dist/agent/forecast-tools.js.map +1 -0
- package/dist/agent/index.d.ts +8 -0
- package/dist/agent/index.d.ts.map +1 -0
- package/dist/agent/index.js +8 -0
- package/dist/agent/index.js.map +1 -0
- package/dist/agent/llm-stub.d.ts +19 -0
- package/dist/agent/llm-stub.d.ts.map +1 -0
- package/dist/agent/llm-stub.js +134 -0
- package/dist/agent/llm-stub.js.map +1 -0
- package/dist/agent/pi-stream.d.ts +8 -0
- package/dist/agent/pi-stream.d.ts.map +1 -0
- package/dist/agent/pi-stream.js +31 -0
- package/dist/agent/pi-stream.js.map +1 -0
- package/dist/agent/skill-tool.d.ts +42 -0
- package/dist/agent/skill-tool.d.ts.map +1 -0
- package/dist/agent/skill-tool.js +279 -0
- package/dist/agent/skill-tool.js.map +1 -0
- package/dist/agent/worker-agent.d.ts +24 -0
- package/dist/agent/worker-agent.d.ts.map +1 -0
- package/dist/agent/worker-agent.js +288 -0
- package/dist/agent/worker-agent.js.map +1 -0
- package/dist/agents/ai-tells.d.ts +26 -0
- package/dist/agents/ai-tells.d.ts.map +1 -0
- package/dist/agents/ai-tells.js +140 -0
- package/dist/agents/ai-tells.js.map +1 -0
- package/dist/agents/architect.d.ts +78 -0
- package/dist/agents/architect.d.ts.map +1 -0
- package/dist/agents/architect.js +1184 -0
- package/dist/agents/architect.js.map +1 -0
- package/dist/agents/base.d.ts +42 -0
- package/dist/agents/base.d.ts.map +1 -0
- package/dist/agents/base.js +123 -0
- package/dist/agents/base.js.map +1 -0
- package/dist/agents/chapter-analyzer.d.ts +30 -0
- package/dist/agents/chapter-analyzer.d.ts.map +1 -0
- package/dist/agents/chapter-analyzer.js +509 -0
- package/dist/agents/chapter-analyzer.js.map +1 -0
- package/dist/agents/composer.d.ts +67 -0
- package/dist/agents/composer.d.ts.map +1 -0
- package/dist/agents/composer.js +936 -0
- package/dist/agents/composer.js.map +1 -0
- package/dist/agents/consolidator.d.ts +39 -0
- package/dist/agents/consolidator.d.ts.map +1 -0
- package/dist/agents/consolidator.js +179 -0
- package/dist/agents/consolidator.js.map +1 -0
- package/dist/agents/continuity.d.ts +45 -0
- package/dist/agents/continuity.d.ts.map +1 -0
- package/dist/agents/continuity.js +722 -0
- package/dist/agents/continuity.js.map +1 -0
- package/dist/agents/detection-insights.d.ts +9 -0
- package/dist/agents/detection-insights.d.ts.map +1 -0
- package/dist/agents/detection-insights.js +54 -0
- package/dist/agents/detection-insights.js.map +1 -0
- package/dist/agents/detector.d.ts +17 -0
- package/dist/agents/detector.d.ts.map +1 -0
- package/dist/agents/detector.js +77 -0
- package/dist/agents/detector.js.map +1 -0
- package/dist/agents/en-prompt-sections.d.ts +4 -0
- package/dist/agents/en-prompt-sections.d.ts.map +1 -0
- package/dist/agents/en-prompt-sections.js +9 -0
- package/dist/agents/en-prompt-sections.js.map +1 -0
- package/dist/agents/fanfic-canon-importer.d.ts +16 -0
- package/dist/agents/fanfic-canon-importer.d.ts.map +1 -0
- package/dist/agents/fanfic-canon-importer.js +164 -0
- package/dist/agents/fanfic-canon-importer.js.map +1 -0
- package/dist/agents/fanfic-dimensions.d.ts +14 -0
- package/dist/agents/fanfic-dimensions.d.ts.map +1 -0
- package/dist/agents/fanfic-dimensions.js +63 -0
- package/dist/agents/fanfic-dimensions.js.map +1 -0
- package/dist/agents/fanfic-prompt-sections.d.ts +5 -0
- package/dist/agents/fanfic-prompt-sections.d.ts.map +1 -0
- package/dist/agents/fanfic-prompt-sections.js +85 -0
- package/dist/agents/fanfic-prompt-sections.js.map +1 -0
- package/dist/agents/foundation-reviewer.d.ts +34 -0
- package/dist/agents/foundation-reviewer.d.ts.map +1 -0
- package/dist/agents/foundation-reviewer.js +174 -0
- package/dist/agents/foundation-reviewer.js.map +1 -0
- package/dist/agents/observer-prompts.d.ts +10 -0
- package/dist/agents/observer-prompts.d.ts.map +1 -0
- package/dist/agents/observer-prompts.js +113 -0
- package/dist/agents/observer-prompts.js.map +1 -0
- package/dist/agents/planner-context.d.ts +53 -0
- package/dist/agents/planner-context.d.ts.map +1 -0
- package/dist/agents/planner-context.js +238 -0
- package/dist/agents/planner-context.js.map +1 -0
- package/dist/agents/planner-prompts.d.ts +45 -0
- package/dist/agents/planner-prompts.d.ts.map +1 -0
- package/dist/agents/planner-prompts.js +391 -0
- package/dist/agents/planner-prompts.js.map +1 -0
- package/dist/agents/planner.d.ts +90 -0
- package/dist/agents/planner.d.ts.map +1 -0
- package/dist/agents/planner.js +715 -0
- package/dist/agents/planner.js.map +1 -0
- package/dist/agents/polisher.d.ts +33 -0
- package/dist/agents/polisher.d.ts.map +1 -0
- package/dist/agents/polisher.js +122 -0
- package/dist/agents/polisher.js.map +1 -0
- package/dist/agents/post-write-validator.d.ts +35 -0
- package/dist/agents/post-write-validator.d.ts.map +1 -0
- package/dist/agents/post-write-validator.js +758 -0
- package/dist/agents/post-write-validator.js.map +1 -0
- package/dist/agents/radar-source.d.ts +38 -0
- package/dist/agents/radar-source.d.ts.map +1 -0
- package/dist/agents/radar-source.js +92 -0
- package/dist/agents/radar-source.js.map +1 -0
- package/dist/agents/radar.d.ts +24 -0
- package/dist/agents/radar.d.ts.map +1 -0
- package/dist/agents/radar.js +85 -0
- package/dist/agents/radar.js.map +1 -0
- package/dist/agents/researcher.d.ts +38 -0
- package/dist/agents/researcher.d.ts.map +1 -0
- package/dist/agents/researcher.js +164 -0
- package/dist/agents/researcher.js.map +1 -0
- package/dist/agents/reviser.d.ts +35 -0
- package/dist/agents/reviser.d.ts.map +1 -0
- package/dist/agents/reviser.js +496 -0
- package/dist/agents/reviser.js.map +1 -0
- package/dist/agents/rules-reader.d.ts +32 -0
- package/dist/agents/rules-reader.d.ts.map +1 -0
- package/dist/agents/rules-reader.js +129 -0
- package/dist/agents/rules-reader.js.map +1 -0
- package/dist/agents/script-storyboard.d.ts +66 -0
- package/dist/agents/script-storyboard.d.ts.map +1 -0
- package/dist/agents/script-storyboard.js +657 -0
- package/dist/agents/script-storyboard.js.map +1 -0
- package/dist/agents/sensitive-words.d.ts +24 -0
- package/dist/agents/sensitive-words.d.ts.map +1 -0
- package/dist/agents/sensitive-words.js +103 -0
- package/dist/agents/sensitive-words.js.map +1 -0
- package/dist/agents/settler-delta-parser.d.ts +7 -0
- package/dist/agents/settler-delta-parser.d.ts.map +1 -0
- package/dist/agents/settler-delta-parser.js +40 -0
- package/dist/agents/settler-delta-parser.js.map +1 -0
- package/dist/agents/settler-parser.d.ts +13 -0
- package/dist/agents/settler-parser.d.ts.map +1 -0
- package/dist/agents/settler-parser.js +20 -0
- package/dist/agents/settler-parser.js.map +1 -0
- package/dist/agents/settler-prompts.d.ts +22 -0
- package/dist/agents/settler-prompts.d.ts.map +1 -0
- package/dist/agents/settler-prompts.js +195 -0
- package/dist/agents/settler-prompts.js.map +1 -0
- package/dist/agents/short-fiction.d.ts +120 -0
- package/dist/agents/short-fiction.d.ts.map +1 -0
- package/dist/agents/short-fiction.js +353 -0
- package/dist/agents/short-fiction.js.map +1 -0
- package/dist/agents/state-validator.d.ts +33 -0
- package/dist/agents/state-validator.d.ts.map +1 -0
- package/dist/agents/state-validator.js +262 -0
- package/dist/agents/state-validator.js.map +1 -0
- package/dist/agents/style-analyzer.d.ts +11 -0
- package/dist/agents/style-analyzer.d.ts.map +1 -0
- package/dist/agents/style-analyzer.js +98 -0
- package/dist/agents/style-analyzer.js.map +1 -0
- package/dist/agents/writer-parser.d.ts +17 -0
- package/dist/agents/writer-parser.d.ts.map +1 -0
- package/dist/agents/writer-parser.js +131 -0
- package/dist/agents/writer-parser.js.map +1 -0
- package/dist/agents/writer-prompts.d.ts +12 -0
- package/dist/agents/writer-prompts.d.ts.map +1 -0
- package/dist/agents/writer-prompts.js +495 -0
- package/dist/agents/writer-prompts.js.map +1 -0
- package/dist/agents/writer.d.ts +102 -0
- package/dist/agents/writer.d.ts.map +1 -0
- package/dist/agents/writer.js +882 -0
- package/dist/agents/writer.js.map +1 -0
- package/dist/forecast/agent.d.ts +22 -0
- package/dist/forecast/agent.d.ts.map +1 -0
- package/dist/forecast/agent.js +48 -0
- package/dist/forecast/agent.js.map +1 -0
- package/dist/forecast/context-builder.d.ts +35 -0
- package/dist/forecast/context-builder.d.ts.map +1 -0
- package/dist/forecast/context-builder.js +214 -0
- package/dist/forecast/context-builder.js.map +1 -0
- package/dist/forecast/prompts.d.ts +12 -0
- package/dist/forecast/prompts.d.ts.map +1 -0
- package/dist/forecast/prompts.js +114 -0
- package/dist/forecast/prompts.js.map +1 -0
- package/dist/forecast/render.d.ts +9 -0
- package/dist/forecast/render.d.ts.map +1 -0
- package/dist/forecast/render.js +154 -0
- package/dist/forecast/render.js.map +1 -0
- package/dist/forecast/runner.d.ts +51 -0
- package/dist/forecast/runner.d.ts.map +1 -0
- package/dist/forecast/runner.js +115 -0
- package/dist/forecast/runner.js.map +1 -0
- package/dist/forecast/schema.d.ts +767 -0
- package/dist/forecast/schema.d.ts.map +1 -0
- package/dist/forecast/schema.js +115 -0
- package/dist/forecast/schema.js.map +1 -0
- package/dist/forecast/store.d.ts +32 -0
- package/dist/forecast/store.d.ts.map +1 -0
- package/dist/forecast/store.js +129 -0
- package/dist/forecast/store.js.map +1 -0
- package/dist/index.d.ts +160 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +172 -0
- package/dist/index.js.map +1 -0
- package/dist/interaction/action-envelope.d.ts +1493 -0
- package/dist/interaction/action-envelope.d.ts.map +1 -0
- package/dist/interaction/action-envelope.js +257 -0
- package/dist/interaction/action-envelope.js.map +1 -0
- package/dist/interaction/book-session-store.d.ts +29 -0
- package/dist/interaction/book-session-store.d.ts.map +1 -0
- package/dist/interaction/book-session-store.js +185 -0
- package/dist/interaction/book-session-store.js.map +1 -0
- package/dist/interaction/draft-directive-parser.d.ts +38 -0
- package/dist/interaction/draft-directive-parser.d.ts.map +1 -0
- package/dist/interaction/draft-directive-parser.js +208 -0
- package/dist/interaction/draft-directive-parser.js.map +1 -0
- package/dist/interaction/edit-controller.d.ts +62 -0
- package/dist/interaction/edit-controller.d.ts.map +1 -0
- package/dist/interaction/edit-controller.js +381 -0
- package/dist/interaction/edit-controller.js.map +1 -0
- package/dist/interaction/events.d.ts +45 -0
- package/dist/interaction/events.d.ts.map +1 -0
- package/dist/interaction/events.js +32 -0
- package/dist/interaction/events.js.map +1 -0
- package/dist/interaction/export-artifact.d.ts +32 -0
- package/dist/interaction/export-artifact.d.ts.map +1 -0
- package/dist/interaction/export-artifact.js +103 -0
- package/dist/interaction/export-artifact.js.map +1 -0
- package/dist/interaction/intents.d.ts +99 -0
- package/dist/interaction/intents.d.ts.map +1 -0
- package/dist/interaction/intents.js +59 -0
- package/dist/interaction/intents.js.map +1 -0
- package/dist/interaction/modes.d.ts +5 -0
- package/dist/interaction/modes.d.ts.map +1 -0
- package/dist/interaction/modes.js +7 -0
- package/dist/interaction/modes.js.map +1 -0
- package/dist/interaction/project-control.d.ts +45 -0
- package/dist/interaction/project-control.d.ts.map +1 -0
- package/dist/interaction/project-control.js +71 -0
- package/dist/interaction/project-control.js.map +1 -0
- package/dist/interaction/project-session-store.d.ts +9 -0
- package/dist/interaction/project-session-store.d.ts.map +1 -0
- package/dist/interaction/project-session-store.js +64 -0
- package/dist/interaction/project-session-store.js.map +1 -0
- package/dist/interaction/project-tools.d.ts +23 -0
- package/dist/interaction/project-tools.d.ts.map +1 -0
- package/dist/interaction/project-tools.js +408 -0
- package/dist/interaction/project-tools.js.map +1 -0
- package/dist/interaction/request-router.d.ts +3 -0
- package/dist/interaction/request-router.d.ts.map +1 -0
- package/dist/interaction/request-router.js +5 -0
- package/dist/interaction/request-router.js.map +1 -0
- package/dist/interaction/runtime.d.ts +54 -0
- package/dist/interaction/runtime.d.ts.map +1 -0
- package/dist/interaction/runtime.js +919 -0
- package/dist/interaction/runtime.js.map +1 -0
- package/dist/interaction/session-transcript-legacy.d.ts +4 -0
- package/dist/interaction/session-transcript-legacy.d.ts.map +1 -0
- package/dist/interaction/session-transcript-legacy.js +102 -0
- package/dist/interaction/session-transcript-legacy.js.map +1 -0
- package/dist/interaction/session-transcript-restore.d.ts +18 -0
- package/dist/interaction/session-transcript-restore.d.ts.map +1 -0
- package/dist/interaction/session-transcript-restore.js +746 -0
- package/dist/interaction/session-transcript-restore.js.map +1 -0
- package/dist/interaction/session-transcript-schema.d.ts +435 -0
- package/dist/interaction/session-transcript-schema.d.ts.map +1 -0
- package/dist/interaction/session-transcript-schema.js +65 -0
- package/dist/interaction/session-transcript-schema.js.map +1 -0
- package/dist/interaction/session-transcript.d.ts +21 -0
- package/dist/interaction/session-transcript.d.ts.map +1 -0
- package/dist/interaction/session-transcript.js +164 -0
- package/dist/interaction/session-transcript.js.map +1 -0
- package/dist/interaction/session.d.ts +1194 -0
- package/dist/interaction/session.d.ts.map +1 -0
- package/dist/interaction/session.js +194 -0
- package/dist/interaction/session.js.map +1 -0
- package/dist/interaction/truth-authority.d.ts +4 -0
- package/dist/interaction/truth-authority.d.ts.map +1 -0
- package/dist/interaction/truth-authority.js +37 -0
- package/dist/interaction/truth-authority.js.map +1 -0
- package/dist/interactive-film/authoring-store.d.ts +35 -0
- package/dist/interactive-film/authoring-store.d.ts.map +1 -0
- package/dist/interactive-film/authoring-store.js +114 -0
- package/dist/interactive-film/authoring-store.js.map +1 -0
- package/dist/interactive-film/authoring-tools.d.ts +9 -0
- package/dist/interactive-film/authoring-tools.d.ts.map +1 -0
- package/dist/interactive-film/authoring-tools.js +19 -0
- package/dist/interactive-film/authoring-tools.js.map +1 -0
- package/dist/interactive-film/delta.d.ts +591 -0
- package/dist/interactive-film/delta.d.ts.map +1 -0
- package/dist/interactive-film/delta.js +54 -0
- package/dist/interactive-film/delta.js.map +1 -0
- package/dist/interactive-film/emotion.d.ts +20 -0
- package/dist/interactive-film/emotion.d.ts.map +1 -0
- package/dist/interactive-film/emotion.js +57 -0
- package/dist/interactive-film/emotion.js.map +1 -0
- package/dist/interactive-film/evaluator.d.ts +7 -0
- package/dist/interactive-film/evaluator.d.ts.map +1 -0
- package/dist/interactive-film/evaluator.js +40 -0
- package/dist/interactive-film/evaluator.js.map +1 -0
- package/dist/interactive-film/export-html.d.ts +6 -0
- package/dist/interactive-film/export-html.d.ts.map +1 -0
- package/dist/interactive-film/export-html.js +84 -0
- package/dist/interactive-film/export-html.js.map +1 -0
- package/dist/interactive-film/export-ink.d.ts +3 -0
- package/dist/interactive-film/export-ink.d.ts.map +1 -0
- package/dist/interactive-film/export-ink.js +51 -0
- package/dist/interactive-film/export-ink.js.map +1 -0
- package/dist/interactive-film/film-context.d.ts +4 -0
- package/dist/interactive-film/film-context.d.ts.map +1 -0
- package/dist/interactive-film/film-context.js +30 -0
- package/dist/interactive-film/film-context.js.map +1 -0
- package/dist/interactive-film/generate.d.ts +15 -0
- package/dist/interactive-film/generate.d.ts.map +1 -0
- package/dist/interactive-film/generate.js +51 -0
- package/dist/interactive-film/generate.js.map +1 -0
- package/dist/interactive-film/graph-schema.d.ts +819 -0
- package/dist/interactive-film/graph-schema.d.ts.map +1 -0
- package/dist/interactive-film/graph-schema.js +84 -0
- package/dist/interactive-film/graph-schema.js.map +1 -0
- package/dist/interactive-film/graph-store.d.ts +5 -0
- package/dist/interactive-film/graph-store.d.ts.map +1 -0
- package/dist/interactive-film/graph-store.js +24 -0
- package/dist/interactive-film/graph-store.js.map +1 -0
- package/dist/interactive-film/memory-link.d.ts +9 -0
- package/dist/interactive-film/memory-link.d.ts.map +1 -0
- package/dist/interactive-film/memory-link.js +15 -0
- package/dist/interactive-film/memory-link.js.map +1 -0
- package/dist/interactive-film/node-image.d.ts +29 -0
- package/dist/interactive-film/node-image.d.ts.map +1 -0
- package/dist/interactive-film/node-image.js +52 -0
- package/dist/interactive-film/node-image.js.map +1 -0
- package/dist/interactive-film/paths.d.ts +14 -0
- package/dist/interactive-film/paths.d.ts.map +1 -0
- package/dist/interactive-film/paths.js +60 -0
- package/dist/interactive-film/paths.js.map +1 -0
- package/dist/interactive-film/tool-schemas.d.ts +182 -0
- package/dist/interactive-film/tool-schemas.d.ts.map +1 -0
- package/dist/interactive-film/tool-schemas.js +125 -0
- package/dist/interactive-film/tool-schemas.js.map +1 -0
- package/dist/interactive-film/validation.d.ts +14 -0
- package/dist/interactive-film/validation.d.ts.map +1 -0
- package/dist/interactive-film/validation.js +292 -0
- package/dist/interactive-film/validation.js.map +1 -0
- package/dist/llm/agent-trajectory.d.ts +27 -0
- package/dist/llm/agent-trajectory.d.ts.map +1 -0
- package/dist/llm/agent-trajectory.js +74 -0
- package/dist/llm/agent-trajectory.js.map +1 -0
- package/dist/llm/config-migration.d.ts +5 -0
- package/dist/llm/config-migration.d.ts.map +1 -0
- package/dist/llm/config-migration.js +51 -0
- package/dist/llm/config-migration.js.map +1 -0
- package/dist/llm/cover-providers.d.ts +14 -0
- package/dist/llm/cover-providers.d.ts.map +1 -0
- package/dist/llm/cover-providers.js +51 -0
- package/dist/llm/cover-providers.js.map +1 -0
- package/dist/llm/long-form-completion.d.ts +16 -0
- package/dist/llm/long-form-completion.d.ts.map +1 -0
- package/dist/llm/long-form-completion.js +62 -0
- package/dist/llm/long-form-completion.js.map +1 -0
- package/dist/llm/provider.d.ts +110 -0
- package/dist/llm/provider.d.ts.map +1 -0
- package/dist/llm/provider.js +1405 -0
- package/dist/llm/provider.js.map +1 -0
- package/dist/llm/providers/endpoints/ai360.d.ts +10 -0
- package/dist/llm/providers/endpoints/ai360.d.ts.map +1 -0
- package/dist/llm/providers/endpoints/ai360.js +34 -0
- package/dist/llm/providers/endpoints/ai360.js.map +1 -0
- package/dist/llm/providers/endpoints/anthropic.d.ts +12 -0
- package/dist/llm/providers/endpoints/anthropic.d.ts.map +1 -0
- package/dist/llm/providers/endpoints/anthropic.js +72 -0
- package/dist/llm/providers/endpoints/anthropic.js.map +1 -0
- package/dist/llm/providers/endpoints/astronCodingPlan.d.ts +16 -0
- package/dist/llm/providers/endpoints/astronCodingPlan.d.ts.map +1 -0
- package/dist/llm/providers/endpoints/astronCodingPlan.js +16 -0
- package/dist/llm/providers/endpoints/astronCodingPlan.js.map +1 -0
- package/dist/llm/providers/endpoints/baichuan.d.ts +10 -0
- package/dist/llm/providers/endpoints/baichuan.d.ts.map +1 -0
- package/dist/llm/providers/endpoints/baichuan.js +20 -0
- package/dist/llm/providers/endpoints/baichuan.js.map +1 -0
- package/dist/llm/providers/endpoints/bailian.d.ts +25 -0
- package/dist/llm/providers/endpoints/bailian.d.ts.map +1 -0
- package/dist/llm/providers/endpoints/bailian.js +42 -0
- package/dist/llm/providers/endpoints/bailian.js.map +1 -0
- package/dist/llm/providers/endpoints/bailianCodingPlan.d.ts +10 -0
- package/dist/llm/providers/endpoints/bailianCodingPlan.d.ts.map +1 -0
- package/dist/llm/providers/endpoints/bailianCodingPlan.js +22 -0
- package/dist/llm/providers/endpoints/bailianCodingPlan.js.map +1 -0
- package/dist/llm/providers/endpoints/custom.d.ts +16 -0
- package/dist/llm/providers/endpoints/custom.d.ts.map +1 -0
- package/dist/llm/providers/endpoints/custom.js +15 -0
- package/dist/llm/providers/endpoints/custom.js.map +1 -0
- package/dist/llm/providers/endpoints/deepseek.d.ts +17 -0
- package/dist/llm/providers/endpoints/deepseek.d.ts.map +1 -0
- package/dist/llm/providers/endpoints/deepseek.js +20 -0
- package/dist/llm/providers/endpoints/deepseek.js.map +1 -0
- package/dist/llm/providers/endpoints/giteeai.d.ts +10 -0
- package/dist/llm/providers/endpoints/giteeai.d.ts.map +1 -0
- package/dist/llm/providers/endpoints/giteeai.js +33 -0
- package/dist/llm/providers/endpoints/giteeai.js.map +1 -0
- package/dist/llm/providers/endpoints/githubCopilot.d.ts +10 -0
- package/dist/llm/providers/endpoints/githubCopilot.d.ts.map +1 -0
- package/dist/llm/providers/endpoints/githubCopilot.js +35 -0
- package/dist/llm/providers/endpoints/githubCopilot.js.map +1 -0
- package/dist/llm/providers/endpoints/glmCodingPlan.d.ts +9 -0
- package/dist/llm/providers/endpoints/glmCodingPlan.d.ts.map +1 -0
- package/dist/llm/providers/endpoints/glmCodingPlan.js +21 -0
- package/dist/llm/providers/endpoints/glmCodingPlan.js.map +1 -0
- package/dist/llm/providers/endpoints/google.d.ts +12 -0
- package/dist/llm/providers/endpoints/google.d.ts.map +1 -0
- package/dist/llm/providers/endpoints/google.js +41 -0
- package/dist/llm/providers/endpoints/google.js.map +1 -0
- package/dist/llm/providers/endpoints/hunyuan.d.ts +10 -0
- package/dist/llm/providers/endpoints/hunyuan.d.ts.map +1 -0
- package/dist/llm/providers/endpoints/hunyuan.js +34 -0
- package/dist/llm/providers/endpoints/hunyuan.js.map +1 -0
- package/dist/llm/providers/endpoints/infiniai.d.ts +10 -0
- package/dist/llm/providers/endpoints/infiniai.d.ts.map +1 -0
- package/dist/llm/providers/endpoints/infiniai.js +64 -0
- package/dist/llm/providers/endpoints/infiniai.js.map +1 -0
- package/dist/llm/providers/endpoints/internlm.d.ts +10 -0
- package/dist/llm/providers/endpoints/internlm.d.ts.map +1 -0
- package/dist/llm/providers/endpoints/internlm.js +20 -0
- package/dist/llm/providers/endpoints/internlm.js.map +1 -0
- package/dist/llm/providers/endpoints/kimiCode.d.ts +9 -0
- package/dist/llm/providers/endpoints/kimiCode.d.ts.map +1 -0
- package/dist/llm/providers/endpoints/kimiCode.js +16 -0
- package/dist/llm/providers/endpoints/kimiCode.js.map +1 -0
- package/dist/llm/providers/endpoints/kimiCodingPlan.d.ts +9 -0
- package/dist/llm/providers/endpoints/kimiCodingPlan.d.ts.map +1 -0
- package/dist/llm/providers/endpoints/kimiCodingPlan.js +17 -0
- package/dist/llm/providers/endpoints/kimiCodingPlan.js.map +1 -0
- package/dist/llm/providers/endpoints/kkaiapi.d.ts +14 -0
- package/dist/llm/providers/endpoints/kkaiapi.d.ts.map +1 -0
- package/dist/llm/providers/endpoints/kkaiapi.js +44 -0
- package/dist/llm/providers/endpoints/kkaiapi.js.map +1 -0
- package/dist/llm/providers/endpoints/lmstudio.d.ts +10 -0
- package/dist/llm/providers/endpoints/lmstudio.d.ts.map +1 -0
- package/dist/llm/providers/endpoints/lmstudio.js +15 -0
- package/dist/llm/providers/endpoints/lmstudio.js.map +1 -0
- package/dist/llm/providers/endpoints/longcat.d.ts +9 -0
- package/dist/llm/providers/endpoints/longcat.d.ts.map +1 -0
- package/dist/llm/providers/endpoints/longcat.js +18 -0
- package/dist/llm/providers/endpoints/longcat.js.map +1 -0
- package/dist/llm/providers/endpoints/minimax.d.ts +15 -0
- package/dist/llm/providers/endpoints/minimax.d.ts.map +1 -0
- package/dist/llm/providers/endpoints/minimax.js +27 -0
- package/dist/llm/providers/endpoints/minimax.js.map +1 -0
- package/dist/llm/providers/endpoints/minimaxCodingPlan.d.ts +9 -0
- package/dist/llm/providers/endpoints/minimaxCodingPlan.d.ts.map +1 -0
- package/dist/llm/providers/endpoints/minimaxCodingPlan.js +21 -0
- package/dist/llm/providers/endpoints/minimaxCodingPlan.js.map +1 -0
- package/dist/llm/providers/endpoints/mistral.d.ts +11 -0
- package/dist/llm/providers/endpoints/mistral.d.ts.map +1 -0
- package/dist/llm/providers/endpoints/mistral.js +31 -0
- package/dist/llm/providers/endpoints/mistral.js.map +1 -0
- package/dist/llm/providers/endpoints/modelscope.d.ts +10 -0
- package/dist/llm/providers/endpoints/modelscope.d.ts.map +1 -0
- package/dist/llm/providers/endpoints/modelscope.js +22 -0
- package/dist/llm/providers/endpoints/modelscope.js.map +1 -0
- package/dist/llm/providers/endpoints/moonshot.d.ts +12 -0
- package/dist/llm/providers/endpoints/moonshot.d.ts.map +1 -0
- package/dist/llm/providers/endpoints/moonshot.js +29 -0
- package/dist/llm/providers/endpoints/moonshot.js.map +1 -0
- package/dist/llm/providers/endpoints/newapi.d.ts +14 -0
- package/dist/llm/providers/endpoints/newapi.d.ts.map +1 -0
- package/dist/llm/providers/endpoints/newapi.js +14 -0
- package/dist/llm/providers/endpoints/newapi.js.map +1 -0
- package/dist/llm/providers/endpoints/ollama.d.ts +12 -0
- package/dist/llm/providers/endpoints/ollama.d.ts.map +1 -0
- package/dist/llm/providers/endpoints/ollama.js +63 -0
- package/dist/llm/providers/endpoints/ollama.js.map +1 -0
- package/dist/llm/providers/endpoints/openai.d.ts +12 -0
- package/dist/llm/providers/endpoints/openai.d.ts.map +1 -0
- package/dist/llm/providers/endpoints/openai.js +67 -0
- package/dist/llm/providers/endpoints/openai.js.map +1 -0
- package/dist/llm/providers/endpoints/opencodeCodingPlan.d.ts +9 -0
- package/dist/llm/providers/endpoints/opencodeCodingPlan.d.ts.map +1 -0
- package/dist/llm/providers/endpoints/opencodeCodingPlan.js +23 -0
- package/dist/llm/providers/endpoints/opencodeCodingPlan.js.map +1 -0
- package/dist/llm/providers/endpoints/openrouter.d.ts +15 -0
- package/dist/llm/providers/endpoints/openrouter.d.ts.map +1 -0
- package/dist/llm/providers/endpoints/openrouter.js +75 -0
- package/dist/llm/providers/endpoints/openrouter.js.map +1 -0
- package/dist/llm/providers/endpoints/ppio.d.ts +15 -0
- package/dist/llm/providers/endpoints/ppio.d.ts.map +1 -0
- package/dist/llm/providers/endpoints/ppio.js +73 -0
- package/dist/llm/providers/endpoints/ppio.js.map +1 -0
- package/dist/llm/providers/endpoints/qiniu.d.ts +10 -0
- package/dist/llm/providers/endpoints/qiniu.d.ts.map +1 -0
- package/dist/llm/providers/endpoints/qiniu.js +24 -0
- package/dist/llm/providers/endpoints/qiniu.js.map +1 -0
- package/dist/llm/providers/endpoints/sensenova.d.ts +10 -0
- package/dist/llm/providers/endpoints/sensenova.d.ts.map +1 -0
- package/dist/llm/providers/endpoints/sensenova.js +37 -0
- package/dist/llm/providers/endpoints/sensenova.js.map +1 -0
- package/dist/llm/providers/endpoints/siliconcloud.d.ts +14 -0
- package/dist/llm/providers/endpoints/siliconcloud.d.ts.map +1 -0
- package/dist/llm/providers/endpoints/siliconcloud.js +114 -0
- package/dist/llm/providers/endpoints/siliconcloud.js.map +1 -0
- package/dist/llm/providers/endpoints/spark.d.ts +14 -0
- package/dist/llm/providers/endpoints/spark.d.ts.map +1 -0
- package/dist/llm/providers/endpoints/spark.js +21 -0
- package/dist/llm/providers/endpoints/spark.js.map +1 -0
- package/dist/llm/providers/endpoints/stepfun.d.ts +10 -0
- package/dist/llm/providers/endpoints/stepfun.d.ts.map +1 -0
- package/dist/llm/providers/endpoints/stepfun.js +27 -0
- package/dist/llm/providers/endpoints/stepfun.js.map +1 -0
- package/dist/llm/providers/endpoints/tencentcloud.d.ts +10 -0
- package/dist/llm/providers/endpoints/tencentcloud.d.ts.map +1 -0
- package/dist/llm/providers/endpoints/tencentcloud.js +17 -0
- package/dist/llm/providers/endpoints/tencentcloud.js.map +1 -0
- package/dist/llm/providers/endpoints/volcengine.d.ts +10 -0
- package/dist/llm/providers/endpoints/volcengine.d.ts.map +1 -0
- package/dist/llm/providers/endpoints/volcengine.js +44 -0
- package/dist/llm/providers/endpoints/volcengine.js.map +1 -0
- package/dist/llm/providers/endpoints/volcengineCodingPlan.d.ts +19 -0
- package/dist/llm/providers/endpoints/volcengineCodingPlan.d.ts.map +1 -0
- package/dist/llm/providers/endpoints/volcengineCodingPlan.js +25 -0
- package/dist/llm/providers/endpoints/volcengineCodingPlan.js.map +1 -0
- package/dist/llm/providers/endpoints/wenxin.d.ts +10 -0
- package/dist/llm/providers/endpoints/wenxin.d.ts.map +1 -0
- package/dist/llm/providers/endpoints/wenxin.js +98 -0
- package/dist/llm/providers/endpoints/wenxin.js.map +1 -0
- package/dist/llm/providers/endpoints/xai.d.ts +11 -0
- package/dist/llm/providers/endpoints/xai.d.ts.map +1 -0
- package/dist/llm/providers/endpoints/xai.js +25 -0
- package/dist/llm/providers/endpoints/xai.js.map +1 -0
- package/dist/llm/providers/endpoints/xiaomimimo.d.ts +12 -0
- package/dist/llm/providers/endpoints/xiaomimimo.d.ts.map +1 -0
- package/dist/llm/providers/endpoints/xiaomimimo.js +16 -0
- package/dist/llm/providers/endpoints/xiaomimimo.js.map +1 -0
- package/dist/llm/providers/endpoints/zeroone.d.ts +10 -0
- package/dist/llm/providers/endpoints/zeroone.d.ts.map +1 -0
- package/dist/llm/providers/endpoints/zeroone.js +26 -0
- package/dist/llm/providers/endpoints/zeroone.js.map +1 -0
- package/dist/llm/providers/endpoints/zhipu.d.ts +12 -0
- package/dist/llm/providers/endpoints/zhipu.d.ts.map +1 -0
- package/dist/llm/providers/endpoints/zhipu.js +51 -0
- package/dist/llm/providers/endpoints/zhipu.js.map +1 -0
- package/dist/llm/providers/index.d.ts +5 -0
- package/dist/llm/providers/index.d.ts.map +1 -0
- package/dist/llm/providers/index.js +64 -0
- package/dist/llm/providers/index.js.map +1 -0
- package/dist/llm/providers/lookup.d.ts +16 -0
- package/dist/llm/providers/lookup.d.ts.map +1 -0
- package/dist/llm/providers/lookup.js +68 -0
- package/dist/llm/providers/lookup.js.map +1 -0
- package/dist/llm/providers/probe.d.ts +11 -0
- package/dist/llm/providers/probe.d.ts.map +1 -0
- package/dist/llm/providers/probe.js +24 -0
- package/dist/llm/providers/probe.js.map +1 -0
- package/dist/llm/providers/types.d.ts +71 -0
- package/dist/llm/providers/types.d.ts.map +1 -0
- package/dist/llm/providers/types.js +9 -0
- package/dist/llm/providers/types.js.map +1 -0
- package/dist/llm/providers/verify.d.ts +27 -0
- package/dist/llm/providers/verify.d.ts.map +1 -0
- package/dist/llm/providers/verify.js +77 -0
- package/dist/llm/providers/verify.js.map +1 -0
- package/dist/llm/secrets.d.ts +9 -0
- package/dist/llm/secrets.d.ts.map +1 -0
- package/dist/llm/secrets.js +56 -0
- package/dist/llm/secrets.js.map +1 -0
- package/dist/llm/service-presets.d.ts +45 -0
- package/dist/llm/service-presets.d.ts.map +1 -0
- package/dist/llm/service-presets.js +180 -0
- package/dist/llm/service-presets.js.map +1 -0
- package/dist/llm/service-resolver.d.ts +10 -0
- package/dist/llm/service-resolver.d.ts.map +1 -0
- package/dist/llm/service-resolver.js +62 -0
- package/dist/llm/service-resolver.js.map +1 -0
- package/dist/llm/think-tag-stripper.d.ts +15 -0
- package/dist/llm/think-tag-stripper.d.ts.map +1 -0
- package/dist/llm/think-tag-stripper.js +60 -0
- package/dist/llm/think-tag-stripper.js.map +1 -0
- package/dist/materials/ingest.d.ts +31 -0
- package/dist/materials/ingest.d.ts.map +1 -0
- package/dist/materials/ingest.js +224 -0
- package/dist/materials/ingest.js.map +1 -0
- package/dist/materials/retrieve.d.ts +20 -0
- package/dist/materials/retrieve.d.ts.map +1 -0
- package/dist/materials/retrieve.js +109 -0
- package/dist/materials/retrieve.js.map +1 -0
- package/dist/models/book-rules.d.ts +142 -0
- package/dist/models/book-rules.d.ts.map +1 -0
- package/dist/models/book-rules.js +286 -0
- package/dist/models/book-rules.js.map +1 -0
- package/dist/models/book.d.ts +94 -0
- package/dist/models/book.d.ts.map +1 -0
- package/dist/models/book.js +79 -0
- package/dist/models/book.js.map +1 -0
- package/dist/models/chapter.d.ts +131 -0
- package/dist/models/chapter.d.ts.map +1 -0
- package/dist/models/chapter.js +38 -0
- package/dist/models/chapter.js.map +1 -0
- package/dist/models/context-compression.d.ts +13 -0
- package/dist/models/context-compression.d.ts.map +1 -0
- package/dist/models/context-compression.js +2 -0
- package/dist/models/context-compression.js.map +1 -0
- package/dist/models/detection.d.ts +25 -0
- package/dist/models/detection.d.ts.map +1 -0
- package/dist/models/detection.js +2 -0
- package/dist/models/detection.js.map +1 -0
- package/dist/models/genre-profile.d.ts +45 -0
- package/dist/models/genre-profile.d.ts.map +1 -0
- package/dist/models/genre-profile.js +26 -0
- package/dist/models/genre-profile.js.map +1 -0
- package/dist/models/input-governance.d.ts +437 -0
- package/dist/models/input-governance.d.ts.map +1 -0
- package/dist/models/input-governance.js +104 -0
- package/dist/models/input-governance.js.map +1 -0
- package/dist/models/length-governance.d.ts +85 -0
- package/dist/models/length-governance.d.ts.map +1 -0
- package/dist/models/length-governance.js +31 -0
- package/dist/models/length-governance.js.map +1 -0
- package/dist/models/play.d.ts +530 -0
- package/dist/models/play.d.ts.map +1 -0
- package/dist/models/play.js +318 -0
- package/dist/models/play.js.map +1 -0
- package/dist/models/project.d.ts +797 -0
- package/dist/models/project.d.ts.map +1 -0
- package/dist/models/project.js +152 -0
- package/dist/models/project.js.map +1 -0
- package/dist/models/runtime-state.d.ts +708 -0
- package/dist/models/runtime-state.d.ts.map +1 -0
- package/dist/models/runtime-state.js +105 -0
- package/dist/models/runtime-state.js.map +1 -0
- package/dist/models/state.d.ts +48 -0
- package/dist/models/state.d.ts.map +1 -0
- package/dist/models/state.js +6 -0
- package/dist/models/state.js.map +1 -0
- package/dist/models/style-profile.d.ts +16 -0
- package/dist/models/style-profile.d.ts.map +1 -0
- package/dist/models/style-profile.js +2 -0
- package/dist/models/style-profile.js.map +1 -0
- package/dist/notify/dispatcher.d.ts +10 -0
- package/dist/notify/dispatcher.d.ts.map +1 -0
- package/dist/notify/dispatcher.js +67 -0
- package/dist/notify/dispatcher.js.map +1 -0
- package/dist/notify/feishu.d.ts +6 -0
- package/dist/notify/feishu.d.ts.map +1 -0
- package/dist/notify/feishu.js +32 -0
- package/dist/notify/feishu.js.map +1 -0
- package/dist/notify/format.d.ts +12 -0
- package/dist/notify/format.d.ts.map +1 -0
- package/dist/notify/format.js +11 -0
- package/dist/notify/format.js.map +1 -0
- package/dist/notify/telegram.d.ts +7 -0
- package/dist/notify/telegram.d.ts.map +1 -0
- package/dist/notify/telegram.js +18 -0
- package/dist/notify/telegram.js.map +1 -0
- package/dist/notify/webhook.d.ts +15 -0
- package/dist/notify/webhook.d.ts.map +1 -0
- package/dist/notify/webhook.js +28 -0
- package/dist/notify/webhook.js.map +1 -0
- package/dist/notify/wechat-work.d.ts +6 -0
- package/dist/notify/wechat-work.d.ts.map +1 -0
- package/dist/notify/wechat-work.js +15 -0
- package/dist/notify/wechat-work.js.map +1 -0
- package/dist/pipeline/chapter-persistence.d.ts +33 -0
- package/dist/pipeline/chapter-persistence.d.ts.map +1 -0
- package/dist/pipeline/chapter-persistence.js +39 -0
- package/dist/pipeline/chapter-persistence.js.map +1 -0
- package/dist/pipeline/chapter-review-cycle.d.ts +81 -0
- package/dist/pipeline/chapter-review-cycle.d.ts.map +1 -0
- package/dist/pipeline/chapter-review-cycle.js +190 -0
- package/dist/pipeline/chapter-review-cycle.js.map +1 -0
- package/dist/pipeline/chapter-state-recovery.d.ts +61 -0
- package/dist/pipeline/chapter-state-recovery.d.ts.map +1 -0
- package/dist/pipeline/chapter-state-recovery.js +135 -0
- package/dist/pipeline/chapter-state-recovery.js.map +1 -0
- package/dist/pipeline/chapter-truth-validation.d.ts +42 -0
- package/dist/pipeline/chapter-truth-validation.d.ts.map +1 -0
- package/dist/pipeline/chapter-truth-validation.js +93 -0
- package/dist/pipeline/chapter-truth-validation.js.map +1 -0
- package/dist/pipeline/detection-runner.d.ts +31 -0
- package/dist/pipeline/detection-runner.d.ts.map +1 -0
- package/dist/pipeline/detection-runner.js +109 -0
- package/dist/pipeline/detection-runner.js.map +1 -0
- package/dist/pipeline/persisted-governed-plan.d.ts +5 -0
- package/dist/pipeline/persisted-governed-plan.d.ts.map +1 -0
- package/dist/pipeline/persisted-governed-plan.js +249 -0
- package/dist/pipeline/persisted-governed-plan.js.map +1 -0
- package/dist/pipeline/runner.d.ts +334 -0
- package/dist/pipeline/runner.d.ts.map +1 -0
- package/dist/pipeline/runner.js +2974 -0
- package/dist/pipeline/runner.js.map +1 -0
- package/dist/pipeline/scheduler.d.ts +58 -0
- package/dist/pipeline/scheduler.d.ts.map +1 -0
- package/dist/pipeline/scheduler.js +322 -0
- package/dist/pipeline/scheduler.js.map +1 -0
- package/dist/pipeline/script-storyboard-runner.d.ts +130 -0
- package/dist/pipeline/script-storyboard-runner.d.ts.map +1 -0
- package/dist/pipeline/script-storyboard-runner.js +532 -0
- package/dist/pipeline/script-storyboard-runner.js.map +1 -0
- package/dist/pipeline/short-fiction-runner.d.ts +110 -0
- package/dist/pipeline/short-fiction-runner.d.ts.map +1 -0
- package/dist/pipeline/short-fiction-runner.js +864 -0
- package/dist/pipeline/short-fiction-runner.js.map +1 -0
- package/dist/play/play-agents.d.ts +72 -0
- package/dist/play/play-agents.d.ts.map +1 -0
- package/dist/play/play-agents.js +580 -0
- package/dist/play/play-agents.js.map +1 -0
- package/dist/play/play-db-factory.d.ts +9 -0
- package/dist/play/play-db-factory.d.ts.map +1 -0
- package/dist/play/play-db-factory.js +18 -0
- package/dist/play/play-db-factory.js.map +1 -0
- package/dist/play/play-db.d.ts +22 -0
- package/dist/play/play-db.d.ts.map +1 -0
- package/dist/play/play-db.js +248 -0
- package/dist/play/play-db.js.map +1 -0
- package/dist/play/play-file-db.d.ts +32 -0
- package/dist/play/play-file-db.d.ts.map +1 -0
- package/dist/play/play-file-db.js +156 -0
- package/dist/play/play-file-db.js.map +1 -0
- package/dist/play/play-image.d.ts +58 -0
- package/dist/play/play-image.d.ts.map +1 -0
- package/dist/play/play-image.js +142 -0
- package/dist/play/play-image.js.map +1 -0
- package/dist/play/play-reducer.d.ts +31 -0
- package/dist/play/play-reducer.d.ts.map +1 -0
- package/dist/play/play-reducer.js +261 -0
- package/dist/play/play-reducer.js.map +1 -0
- package/dist/play/play-runner.d.ts +116 -0
- package/dist/play/play-runner.d.ts.map +1 -0
- package/dist/play/play-runner.js +582 -0
- package/dist/play/play-runner.js.map +1 -0
- package/dist/play/play-store.d.ts +113 -0
- package/dist/play/play-store.d.ts.map +1 -0
- package/dist/play/play-store.js +314 -0
- package/dist/play/play-store.js.map +1 -0
- package/dist/production/harness.d.ts +57 -0
- package/dist/production/harness.d.ts.map +1 -0
- package/dist/production/harness.js +51 -0
- package/dist/production/harness.js.map +1 -0
- package/dist/prompts/builtin-prompts.d.ts +10 -0
- package/dist/prompts/builtin-prompts.d.ts.map +1 -0
- package/dist/prompts/builtin-prompts.js +157 -0
- package/dist/prompts/builtin-prompts.js.map +1 -0
- package/dist/prompts/index.d.ts +5 -0
- package/dist/prompts/index.d.ts.map +1 -0
- package/dist/prompts/index.js +5 -0
- package/dist/prompts/index.js.map +1 -0
- package/dist/prompts/prompt-pack.d.ts +33 -0
- package/dist/prompts/prompt-pack.d.ts.map +1 -0
- package/dist/prompts/prompt-pack.js +82 -0
- package/dist/prompts/prompt-pack.js.map +1 -0
- package/dist/prompts/short-fiction.d.ts +58 -0
- package/dist/prompts/short-fiction.d.ts.map +1 -0
- package/dist/prompts/short-fiction.js +480 -0
- package/dist/prompts/short-fiction.js.map +1 -0
- package/dist/prompts/types.d.ts +22 -0
- package/dist/prompts/types.d.ts.map +1 -0
- package/dist/prompts/types.js +9 -0
- package/dist/prompts/types.js.map +1 -0
- package/dist/references/book-references.d.ts +40 -0
- package/dist/references/book-references.d.ts.map +1 -0
- package/dist/references/book-references.js +207 -0
- package/dist/references/book-references.js.map +1 -0
- package/dist/references/reference-context.d.ts +26 -0
- package/dist/references/reference-context.d.ts.map +1 -0
- package/dist/references/reference-context.js +120 -0
- package/dist/references/reference-context.js.map +1 -0
- package/dist/retrieval/local-search.d.ts +38 -0
- package/dist/retrieval/local-search.d.ts.map +1 -0
- package/dist/retrieval/local-search.js +232 -0
- package/dist/retrieval/local-search.js.map +1 -0
- package/dist/skills/builtin-loader.d.ts +9 -0
- package/dist/skills/builtin-loader.d.ts.map +1 -0
- package/dist/skills/builtin-loader.js +24 -0
- package/dist/skills/builtin-loader.js.map +1 -0
- package/dist/skills/external-loader.d.ts +26 -0
- package/dist/skills/external-loader.d.ts.map +1 -0
- package/dist/skills/external-loader.js +186 -0
- package/dist/skills/external-loader.js.map +1 -0
- package/dist/skills/index.d.ts +6 -0
- package/dist/skills/index.d.ts.map +1 -0
- package/dist/skills/index.js +6 -0
- package/dist/skills/index.js.map +1 -0
- package/dist/skills/production-bindings.d.ts +18 -0
- package/dist/skills/production-bindings.d.ts.map +1 -0
- package/dist/skills/production-bindings.js +37 -0
- package/dist/skills/production-bindings.js.map +1 -0
- package/dist/skills/registry.d.ts +6 -0
- package/dist/skills/registry.d.ts.map +1 -0
- package/dist/skills/registry.js +68 -0
- package/dist/skills/registry.js.map +1 -0
- package/dist/skills/types.d.ts +42 -0
- package/dist/skills/types.d.ts.map +1 -0
- package/dist/skills/types.js +10 -0
- package/dist/skills/types.js.map +1 -0
- package/dist/state/chapter-delete.d.ts +30 -0
- package/dist/state/chapter-delete.d.ts.map +1 -0
- package/dist/state/chapter-delete.js +78 -0
- package/dist/state/chapter-delete.js.map +1 -0
- package/dist/state/chapter-word-sync.d.ts +30 -0
- package/dist/state/chapter-word-sync.d.ts.map +1 -0
- package/dist/state/chapter-word-sync.js +62 -0
- package/dist/state/chapter-word-sync.js.map +1 -0
- package/dist/state/chapter-workspace.d.ts +15 -0
- package/dist/state/chapter-workspace.d.ts.map +1 -0
- package/dist/state/chapter-workspace.js +118 -0
- package/dist/state/chapter-workspace.js.map +1 -0
- package/dist/state/manager.d.ts +70 -0
- package/dist/state/manager.d.ts.map +1 -0
- package/dist/state/manager.js +727 -0
- package/dist/state/manager.js.map +1 -0
- package/dist/state/memory-db.d.ts +83 -0
- package/dist/state/memory-db.d.ts.map +1 -0
- package/dist/state/memory-db.js +249 -0
- package/dist/state/memory-db.js.map +1 -0
- package/dist/state/runtime-state-store.d.ts +38 -0
- package/dist/state/runtime-state-store.d.ts.map +1 -0
- package/dist/state/runtime-state-store.js +164 -0
- package/dist/state/runtime-state-store.js.map +1 -0
- package/dist/state/state-bootstrap.d.ts +21 -0
- package/dist/state/state-bootstrap.d.ts.map +1 -0
- package/dist/state/state-bootstrap.js +476 -0
- package/dist/state/state-bootstrap.js.map +1 -0
- package/dist/state/state-projections.d.ts +7 -0
- package/dist/state/state-projections.d.ts.map +1 -0
- package/dist/state/state-projections.js +209 -0
- package/dist/state/state-projections.js.map +1 -0
- package/dist/state/state-reducer.d.ts +13 -0
- package/dist/state/state-reducer.d.ts.map +1 -0
- package/dist/state/state-reducer.js +193 -0
- package/dist/state/state-reducer.js.map +1 -0
- package/dist/state/state-validator.d.ts +12 -0
- package/dist/state/state-validator.d.ts.map +1 -0
- package/dist/state/state-validator.js +67 -0
- package/dist/state/state-validator.js.map +1 -0
- package/dist/translation/epub.d.ts +10 -0
- package/dist/translation/epub.d.ts.map +1 -0
- package/dist/translation/epub.js +86 -0
- package/dist/translation/epub.js.map +1 -0
- package/dist/translation/export.d.ts +6 -0
- package/dist/translation/export.d.ts.map +1 -0
- package/dist/translation/export.js +68 -0
- package/dist/translation/export.js.map +1 -0
- package/dist/translation/index.d.ts +9 -0
- package/dist/translation/index.d.ts.map +1 -0
- package/dist/translation/index.js +9 -0
- package/dist/translation/index.js.map +1 -0
- package/dist/translation/llm-model.d.ts +11 -0
- package/dist/translation/llm-model.d.ts.map +1 -0
- package/dist/translation/llm-model.js +135 -0
- package/dist/translation/llm-model.js.map +1 -0
- package/dist/translation/project.d.ts +3 -0
- package/dist/translation/project.d.ts.map +1 -0
- package/dist/translation/project.js +76 -0
- package/dist/translation/project.js.map +1 -0
- package/dist/translation/run-store.d.ts +12 -0
- package/dist/translation/run-store.d.ts.map +1 -0
- package/dist/translation/run-store.js +69 -0
- package/dist/translation/run-store.js.map +1 -0
- package/dist/translation/runner.d.ts +6 -0
- package/dist/translation/runner.d.ts.map +1 -0
- package/dist/translation/runner.js +155 -0
- package/dist/translation/runner.js.map +1 -0
- package/dist/translation/source.d.ts +12 -0
- package/dist/translation/source.d.ts.map +1 -0
- package/dist/translation/source.js +66 -0
- package/dist/translation/source.js.map +1 -0
- package/dist/translation/text.d.ts +10 -0
- package/dist/translation/text.d.ts.map +1 -0
- package/dist/translation/text.js +110 -0
- package/dist/translation/text.js.map +1 -0
- package/dist/translation/types.d.ts +96 -0
- package/dist/translation/types.d.ts.map +1 -0
- package/dist/translation/types.js +2 -0
- package/dist/translation/types.js.map +1 -0
- package/dist/utils/analytics.d.ts +39 -0
- package/dist/utils/analytics.d.ts.map +1 -0
- package/dist/utils/analytics.js +50 -0
- package/dist/utils/analytics.js.map +1 -0
- package/dist/utils/atomic-file-set.d.ts +12 -0
- package/dist/utils/atomic-file-set.d.ts.map +1 -0
- package/dist/utils/atomic-file-set.js +93 -0
- package/dist/utils/atomic-file-set.js.map +1 -0
- package/dist/utils/book-eval.d.ts +35 -0
- package/dist/utils/book-eval.d.ts.map +1 -0
- package/dist/utils/book-eval.js +116 -0
- package/dist/utils/book-eval.js.map +1 -0
- package/dist/utils/book-id.d.ts +4 -0
- package/dist/utils/book-id.d.ts.map +1 -0
- package/dist/utils/book-id.js +27 -0
- package/dist/utils/book-id.js.map +1 -0
- package/dist/utils/cadence-policy.d.ts +36 -0
- package/dist/utils/cadence-policy.d.ts.map +1 -0
- package/dist/utils/cadence-policy.js +38 -0
- package/dist/utils/cadence-policy.js.map +1 -0
- package/dist/utils/chapter-cadence.d.ts +34 -0
- package/dist/utils/chapter-cadence.d.ts.map +1 -0
- package/dist/utils/chapter-cadence.js +143 -0
- package/dist/utils/chapter-cadence.js.map +1 -0
- package/dist/utils/chapter-memo-parser.d.ts +22 -0
- package/dist/utils/chapter-memo-parser.d.ts.map +1 -0
- package/dist/utils/chapter-memo-parser.js +158 -0
- package/dist/utils/chapter-memo-parser.js.map +1 -0
- package/dist/utils/chapter-splitter.d.ts +18 -0
- package/dist/utils/chapter-splitter.d.ts.map +1 -0
- package/dist/utils/chapter-splitter.js +60 -0
- package/dist/utils/chapter-splitter.js.map +1 -0
- package/dist/utils/config-loader.d.ts +11 -0
- package/dist/utils/config-loader.d.ts.map +1 -0
- package/dist/utils/config-loader.js +16 -0
- package/dist/utils/config-loader.js.map +1 -0
- package/dist/utils/context-assembly.d.ts +29 -0
- package/dist/utils/context-assembly.d.ts.map +1 -0
- package/dist/utils/context-assembly.js +117 -0
- package/dist/utils/context-assembly.js.map +1 -0
- package/dist/utils/context-filter.d.ts +31 -0
- package/dist/utils/context-filter.d.ts.map +1 -0
- package/dist/utils/context-filter.js +163 -0
- package/dist/utils/context-filter.js.map +1 -0
- package/dist/utils/effective-llm-config.d.ts +34 -0
- package/dist/utils/effective-llm-config.d.ts.map +1 -0
- package/dist/utils/effective-llm-config.js +463 -0
- package/dist/utils/effective-llm-config.js.map +1 -0
- package/dist/utils/governed-context.d.ts +11 -0
- package/dist/utils/governed-context.d.ts.map +1 -0
- package/dist/utils/governed-context.js +42 -0
- package/dist/utils/governed-context.js.map +1 -0
- package/dist/utils/governed-working-set.d.ts +18 -0
- package/dist/utils/governed-working-set.d.ts.map +1 -0
- package/dist/utils/governed-working-set.js +296 -0
- package/dist/utils/governed-working-set.js.map +1 -0
- package/dist/utils/hook-arbiter.d.ts +16 -0
- package/dist/utils/hook-arbiter.d.ts.map +1 -0
- package/dist/utils/hook-arbiter.js +161 -0
- package/dist/utils/hook-arbiter.js.map +1 -0
- package/dist/utils/hook-governance.d.ts +26 -0
- package/dist/utils/hook-governance.d.ts.map +1 -0
- package/dist/utils/hook-governance.js +65 -0
- package/dist/utils/hook-governance.js.map +1 -0
- package/dist/utils/hook-health.d.ts +15 -0
- package/dist/utils/hook-health.d.ts.map +1 -0
- package/dist/utils/hook-health.js +131 -0
- package/dist/utils/hook-health.js.map +1 -0
- package/dist/utils/hook-ledger-validator.d.ts +82 -0
- package/dist/utils/hook-ledger-validator.d.ts.map +1 -0
- package/dist/utils/hook-ledger-validator.js +225 -0
- package/dist/utils/hook-ledger-validator.js.map +1 -0
- package/dist/utils/hook-lifecycle.d.ts +41 -0
- package/dist/utils/hook-lifecycle.d.ts.map +1 -0
- package/dist/utils/hook-lifecycle.js +183 -0
- package/dist/utils/hook-lifecycle.js.map +1 -0
- package/dist/utils/hook-policy.d.ts +57 -0
- package/dist/utils/hook-policy.d.ts.map +1 -0
- package/dist/utils/hook-policy.js +96 -0
- package/dist/utils/hook-policy.js.map +1 -0
- package/dist/utils/hook-promotion.d.ts +83 -0
- package/dist/utils/hook-promotion.d.ts.map +1 -0
- package/dist/utils/hook-promotion.js +241 -0
- package/dist/utils/hook-promotion.js.map +1 -0
- package/dist/utils/hook-stale-detection.d.ts +51 -0
- package/dist/utils/hook-stale-detection.d.ts.map +1 -0
- package/dist/utils/hook-stale-detection.js +125 -0
- package/dist/utils/hook-stale-detection.js.map +1 -0
- package/dist/utils/language.d.ts +19 -0
- package/dist/utils/language.d.ts.map +1 -0
- package/dist/utils/language.js +29 -0
- package/dist/utils/language.js.map +1 -0
- package/dist/utils/length-metrics.d.ts +12 -0
- package/dist/utils/length-metrics.d.ts.map +1 -0
- package/dist/utils/length-metrics.js +85 -0
- package/dist/utils/length-metrics.js.map +1 -0
- package/dist/utils/llm-endpoint-auth.d.ts +5 -0
- package/dist/utils/llm-endpoint-auth.d.ts.map +1 -0
- package/dist/utils/llm-endpoint-auth.js +36 -0
- package/dist/utils/llm-endpoint-auth.js.map +1 -0
- package/dist/utils/llm-env.d.ts +14 -0
- package/dist/utils/llm-env.d.ts.map +1 -0
- package/dist/utils/llm-env.js +53 -0
- package/dist/utils/llm-env.js.map +1 -0
- package/dist/utils/logger.d.ts +31 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +79 -0
- package/dist/utils/logger.js.map +1 -0
- package/dist/utils/long-span-fatigue.d.ts +28 -0
- package/dist/utils/long-span-fatigue.d.ts.map +1 -0
- package/dist/utils/long-span-fatigue.js +406 -0
- package/dist/utils/long-span-fatigue.js.map +1 -0
- package/dist/utils/memory-retrieval.d.ts +71 -0
- package/dist/utils/memory-retrieval.d.ts.map +1 -0
- package/dist/utils/memory-retrieval.js +360 -0
- package/dist/utils/memory-retrieval.js.map +1 -0
- package/dist/utils/narrative-control.d.ts +16 -0
- package/dist/utils/narrative-control.d.ts.map +1 -0
- package/dist/utils/narrative-control.js +131 -0
- package/dist/utils/narrative-control.js.map +1 -0
- package/dist/utils/outline-paths.d.ts +63 -0
- package/dist/utils/outline-paths.d.ts.map +1 -0
- package/dist/utils/outline-paths.js +311 -0
- package/dist/utils/outline-paths.js.map +1 -0
- package/dist/utils/path-safety.d.ts +2 -0
- package/dist/utils/path-safety.d.ts.map +1 -0
- package/dist/utils/path-safety.js +11 -0
- package/dist/utils/path-safety.js.map +1 -0
- package/dist/utils/planning-materials.d.ts +35 -0
- package/dist/utils/planning-materials.d.ts.map +1 -0
- package/dist/utils/planning-materials.js +123 -0
- package/dist/utils/planning-materials.js.map +1 -0
- package/dist/utils/posix-path.d.ts +2 -0
- package/dist/utils/posix-path.d.ts.map +1 -0
- package/dist/utils/posix-path.js +7 -0
- package/dist/utils/posix-path.js.map +1 -0
- package/dist/utils/pov-filter.d.ts +30 -0
- package/dist/utils/pov-filter.d.ts.map +1 -0
- package/dist/utils/pov-filter.js +129 -0
- package/dist/utils/pov-filter.js.map +1 -0
- package/dist/utils/proxy-fetch.d.ts +9 -0
- package/dist/utils/proxy-fetch.d.ts.map +1 -0
- package/dist/utils/proxy-fetch.js +31 -0
- package/dist/utils/proxy-fetch.js.map +1 -0
- package/dist/utils/runtime-writer.d.ts +14 -0
- package/dist/utils/runtime-writer.d.ts.map +1 -0
- package/dist/utils/runtime-writer.js +21 -0
- package/dist/utils/runtime-writer.js.map +1 -0
- package/dist/utils/spot-fix-patches.d.ts +21 -0
- package/dist/utils/spot-fix-patches.d.ts.map +1 -0
- package/dist/utils/spot-fix-patches.js +148 -0
- package/dist/utils/spot-fix-patches.js.map +1 -0
- package/dist/utils/story-markdown.d.ts +13 -0
- package/dist/utils/story-markdown.d.ts.map +1 -0
- package/dist/utils/story-markdown.js +320 -0
- package/dist/utils/story-markdown.js.map +1 -0
- package/dist/utils/web-search.d.ts +28 -0
- package/dist/utils/web-search.d.ts.map +1 -0
- package/dist/utils/web-search.js +72 -0
- package/dist/utils/web-search.js.map +1 -0
- package/dist/utils/writing-methodology.d.ts +10 -0
- package/dist/utils/writing-methodology.d.ts.map +1 -0
- package/dist/utils/writing-methodology.js +163 -0
- package/dist/utils/writing-methodology.js.map +1 -0
- package/genres/cozy.md +43 -0
- package/genres/cultivation.md +42 -0
- package/genres/dungeon-core.md +40 -0
- package/genres/horror.md +51 -0
- package/genres/isekai.md +43 -0
- package/genres/litrpg.md +43 -0
- package/genres/other.md +24 -0
- package/genres/progression.md +41 -0
- package/genres/romantasy.md +45 -0
- package/genres/sci-fi.md +42 -0
- package/genres/system-apocalypse.md +40 -0
- package/genres/tower-climber.md +41 -0
- package/genres/urban.md +53 -0
- package/genres/xianxia.md +46 -0
- package/genres/xuanhuan.md +64 -0
- package/package.json +76 -0
- package/skills/inkos-interactive-film/SKILL.md +16 -0
- package/skills/inkos-interactive-film/references/branch-state-craft.md +13 -0
- package/skills/inkos-long-market-research/SKILL.md +16 -0
- package/skills/inkos-long-market-research/references/research-rubric.md +19 -0
- package/skills/inkos-long-story-analysis/SKILL.md +17 -0
- package/skills/inkos-long-story-analysis/references/analysis-lens.md +16 -0
- package/skills/inkos-long-writing/SKILL.md +17 -0
- package/skills/inkos-long-writing/references/reader-contract-and-progression.md +13 -0
- package/skills/inkos-long-writing/references/scene-dialogue-and-length-budget.md +13 -0
- package/skills/inkos-play-world/SKILL.md +17 -0
- package/skills/inkos-play-world/references/world-turn-continuity.md +13 -0
- package/skills/inkos-script-writing/SKILL.md +15 -0
- package/skills/inkos-script-writing/references/episode-scene-craft.md +13 -0
- package/skills/inkos-short-market-research/SKILL.md +17 -0
- package/skills/inkos-short-market-research/references/short-market-rubric.md +16 -0
- package/skills/inkos-short-story-analysis/SKILL.md +16 -0
- package/skills/inkos-short-story-analysis/references/deconstruction-template.md +14 -0
- package/skills/inkos-short-writing/SKILL.md +18 -0
- package/skills/inkos-short-writing/references/production-checklist.md +19 -0
- package/skills/inkos-story-cover/SKILL.md +17 -0
- package/skills/inkos-story-cover/references/cover-brief.md +16 -0
- package/skills/inkos-story-deslop/SKILL.md +16 -0
- package/skills/inkos-story-deslop/references/semantic-cleanup.md +13 -0
- package/skills/inkos-story-import/SKILL.md +19 -0
- package/skills/inkos-story-import/references/reconstruction-rubric.md +13 -0
- package/skills/inkos-story-review/SKILL.md +16 -0
- package/skills/inkos-story-review/references/review-matrix.md +21 -0
- package/skills/inkos-storyboard/SKILL.md +15 -0
- package/skills/inkos-storyboard/references/shot-continuity.md +13 -0
- package/skills/inkos-translation/SKILL.md +14 -0
- package/skills/inkos-translation/references/long-form-consistency.md +13 -0
|
@@ -0,0 +1,1102 @@
|
|
|
1
|
+
import { createHash, randomUUID } from "node:crypto";
|
|
2
|
+
import { Agent } from "@mariozechner/pi-agent-core";
|
|
3
|
+
import { getModel, getEnvApiKey, createAssistantMessageEventStream } from "@mariozechner/pi-ai";
|
|
4
|
+
import { buildAgentSystemPrompt } from "./agent-system-prompt.js";
|
|
5
|
+
import { createPatchChapterTextTool, createReplaceChapterTextTool, createResyncChapterStateTool, createDeleteLatestChapterTool, createRenameEntityTool, createSubAgentTool, createReadTool, createGrepTool, createLsTool, createWriteTruthFileTool, createShortFictionRunTool, createGenerateCoverTool, createPlayEditTool, createPlayReviseTool, createPlayStartTool, createPlayStepTool, createProposeActionTool, createScriptCreationTool, createStoryboardCreationTool, createInteractiveFilmCreationTool, createTranslationCreateTool, createFanficBookTool, createContinuationImportTool, createSpinoffBookTool, createImitationBookTool, createResearchWebTool, createIngestMaterialTool, createRetrieveMaterialTool, createManageBookReferenceTool, createImportChaptersTool, } from "./agent-tools.js";
|
|
6
|
+
import { createFilmAuthoringTools, filmLLMDepsFromClient } from "./film-authoring-tools.js";
|
|
7
|
+
import { createNarrativeForecastCreateTool, createNarrativeForecastGetTool, createNarrativeForecastSelectTool, } from "./forecast-tools.js";
|
|
8
|
+
import { createBookContextTransform, createInteractiveFilmContextTransform } from "./context-transform.js";
|
|
9
|
+
import { appendTranscriptEvents, readTranscriptEvents, } from "../interaction/session-transcript.js";
|
|
10
|
+
import { TOOL_RESULT_BRIDGE_TEXT, adaptRestoredAgentMessagesForModel, appendRestoredHistoryBoundary, restoreAgentMessagesFromTranscript, } from "../interaction/session-transcript-restore.js";
|
|
11
|
+
import { createSkillRegistry, loadAvailableAgentSkills, mergeActivatedSkillGuidance, resolveProductionSkillActivations, } from "../skills/index.js";
|
|
12
|
+
import { assertSafeBookId } from "../utils/book-id.js";
|
|
13
|
+
import { PlayStore } from "../play/play-store.js";
|
|
14
|
+
import { isLlmStubEnabled, stubAgentStream } from "./llm-stub.js";
|
|
15
|
+
import { assistantInvokesSkill, createUseSkillTool, sanitizeSkillTurnMessage, } from "./skill-tool.js";
|
|
16
|
+
import { opaqueConversationId, runWithAgentTrajectory } from "../llm/agent-trajectory.js";
|
|
17
|
+
import { guardedPiStream } from "./pi-stream.js";
|
|
18
|
+
const agentCache = new Map();
|
|
19
|
+
const agentSessionQueues = new Map();
|
|
20
|
+
/** TTL for cached agents: 5 minutes. */
|
|
21
|
+
const CACHE_TTL_MS = 5 * 60 * 1000;
|
|
22
|
+
const EMPTY_USAGE = {
|
|
23
|
+
input: 0,
|
|
24
|
+
output: 0,
|
|
25
|
+
cacheRead: 0,
|
|
26
|
+
cacheWrite: 0,
|
|
27
|
+
totalTokens: 0,
|
|
28
|
+
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 },
|
|
29
|
+
};
|
|
30
|
+
/** Cleanup interval handle (lazy-started). */
|
|
31
|
+
let cleanupTimer = null;
|
|
32
|
+
function ensureCleanupTimer() {
|
|
33
|
+
if (cleanupTimer)
|
|
34
|
+
return;
|
|
35
|
+
cleanupTimer = setInterval(() => {
|
|
36
|
+
const now = Date.now();
|
|
37
|
+
for (const [id, entry] of agentCache) {
|
|
38
|
+
if (now - entry.lastActive > CACHE_TTL_MS) {
|
|
39
|
+
agentCache.delete(id);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
// Stop the timer when nothing left to watch.
|
|
43
|
+
if (agentCache.size === 0 && cleanupTimer) {
|
|
44
|
+
clearInterval(cleanupTimer);
|
|
45
|
+
cleanupTimer = null;
|
|
46
|
+
}
|
|
47
|
+
}, 60_000); // run every 60 s
|
|
48
|
+
// Allow the process to exit even if this timer is alive.
|
|
49
|
+
if (cleanupTimer && typeof cleanupTimer === "object" && "unref" in cleanupTimer) {
|
|
50
|
+
cleanupTimer.unref();
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
// ---------------------------------------------------------------------------
|
|
54
|
+
// Helpers
|
|
55
|
+
// ---------------------------------------------------------------------------
|
|
56
|
+
function resolveModel(spec) {
|
|
57
|
+
if (!spec) {
|
|
58
|
+
throw new Error("Model is required but was undefined. Check LLM configuration.");
|
|
59
|
+
}
|
|
60
|
+
if (typeof spec === "object" && "id" in spec && "api" in spec) {
|
|
61
|
+
// Already a Model object.
|
|
62
|
+
return spec;
|
|
63
|
+
}
|
|
64
|
+
const { provider, modelId } = spec;
|
|
65
|
+
if (!provider || !modelId) {
|
|
66
|
+
throw new Error(`Invalid model spec: provider=${provider}, modelId=${modelId}`);
|
|
67
|
+
}
|
|
68
|
+
return getModel(provider, modelId);
|
|
69
|
+
}
|
|
70
|
+
function envFlagEnabled(value, defaultValue) {
|
|
71
|
+
if (value === undefined)
|
|
72
|
+
return defaultValue;
|
|
73
|
+
if (value === "1" || value.toLowerCase() === "true")
|
|
74
|
+
return true;
|
|
75
|
+
if (value === "0" || value.toLowerCase() === "false")
|
|
76
|
+
return false;
|
|
77
|
+
return defaultValue;
|
|
78
|
+
}
|
|
79
|
+
function agentModelIdentity(model) {
|
|
80
|
+
return [
|
|
81
|
+
model.api,
|
|
82
|
+
model.provider,
|
|
83
|
+
model.baseUrl ?? "",
|
|
84
|
+
model.id,
|
|
85
|
+
].join("::");
|
|
86
|
+
}
|
|
87
|
+
function actionPayloadCacheKey(payload) {
|
|
88
|
+
return payload ? JSON.stringify(payload) : "";
|
|
89
|
+
}
|
|
90
|
+
function skillResolutionCacheKey(value) {
|
|
91
|
+
return createHash("sha256").update(JSON.stringify({
|
|
92
|
+
used: value.usedSkills.map((skill) => ({
|
|
93
|
+
id: skill.id,
|
|
94
|
+
source: skill.source,
|
|
95
|
+
body: skill.body ?? "",
|
|
96
|
+
})),
|
|
97
|
+
forced: value.forcedSkillIds,
|
|
98
|
+
missing: value.missingSkillIds,
|
|
99
|
+
disabled: value.disabledSkillIds,
|
|
100
|
+
available: value.availableSkills.map((skill) => ({
|
|
101
|
+
id: skill.id,
|
|
102
|
+
name: skill.name,
|
|
103
|
+
description: skill.description,
|
|
104
|
+
body: skill.body ?? "",
|
|
105
|
+
baseDir: skill.baseDir ?? "",
|
|
106
|
+
})),
|
|
107
|
+
})).digest("hex");
|
|
108
|
+
}
|
|
109
|
+
function sessionQueueKey(projectRoot, sessionId) {
|
|
110
|
+
return `${projectRoot}\0${sessionId}`;
|
|
111
|
+
}
|
|
112
|
+
function agentCacheKey(projectRoot, sessionId) {
|
|
113
|
+
return sessionQueueKey(projectRoot, sessionId);
|
|
114
|
+
}
|
|
115
|
+
function buildAttachmentUserBlock(attachments, language) {
|
|
116
|
+
if (!attachments?.length)
|
|
117
|
+
return "";
|
|
118
|
+
const isEn = language === "en";
|
|
119
|
+
const lines = [
|
|
120
|
+
isEn
|
|
121
|
+
? "\n\n## Uploaded Files (host-provided, user-authorized)"
|
|
122
|
+
: "\n\n## 用户上传文件(宿主已接收,用户授权本轮使用)",
|
|
123
|
+
];
|
|
124
|
+
for (const attachment of attachments) {
|
|
125
|
+
lines.push(`\n### ${attachment.filename}`);
|
|
126
|
+
lines.push(`- id: ${attachment.id}`);
|
|
127
|
+
lines.push(`- mime: ${attachment.mimeType || "application/octet-stream"}`);
|
|
128
|
+
lines.push(`- size: ${attachment.size}`);
|
|
129
|
+
if (attachment.storedPath)
|
|
130
|
+
lines.push(`- stored_path: ${attachment.storedPath}`);
|
|
131
|
+
if (attachment.text) {
|
|
132
|
+
lines.push(isEn ? "\nContent:" : "\n内容:");
|
|
133
|
+
lines.push("```");
|
|
134
|
+
lines.push(attachment.text);
|
|
135
|
+
lines.push("```");
|
|
136
|
+
}
|
|
137
|
+
else if (attachment.image) {
|
|
138
|
+
lines.push(isEn ? "- image: attached as multimodal input" : "- 图片:已作为多模态输入附加");
|
|
139
|
+
}
|
|
140
|
+
else {
|
|
141
|
+
lines.push(isEn
|
|
142
|
+
? "- content: stored only; no extractor is available for this MIME type yet"
|
|
143
|
+
: "- 内容:已保存;当前 MIME 类型暂未配置文本抽取器");
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
return lines.join("\n");
|
|
147
|
+
}
|
|
148
|
+
function attachmentImages(attachments) {
|
|
149
|
+
return (attachments ?? [])
|
|
150
|
+
.filter((attachment) => attachment.image)
|
|
151
|
+
.map((attachment) => ({
|
|
152
|
+
type: "image",
|
|
153
|
+
data: attachment.image.data,
|
|
154
|
+
mimeType: attachment.image.mimeType,
|
|
155
|
+
}));
|
|
156
|
+
}
|
|
157
|
+
function localAssistantStopStream(model) {
|
|
158
|
+
const stream = createAssistantMessageEventStream();
|
|
159
|
+
const message = {
|
|
160
|
+
role: "assistant",
|
|
161
|
+
content: [],
|
|
162
|
+
api: model.api,
|
|
163
|
+
provider: model.provider,
|
|
164
|
+
model: model.id,
|
|
165
|
+
usage: EMPTY_USAGE,
|
|
166
|
+
stopReason: "stop",
|
|
167
|
+
timestamp: Date.now(),
|
|
168
|
+
};
|
|
169
|
+
queueMicrotask(() => {
|
|
170
|
+
stream.push({ type: "done", reason: "stop", message });
|
|
171
|
+
stream.end(message);
|
|
172
|
+
});
|
|
173
|
+
return stream;
|
|
174
|
+
}
|
|
175
|
+
export function isTerminalProductionToolName(toolName) {
|
|
176
|
+
return toolName === "propose_action"
|
|
177
|
+
|| toolName === "sub_agent"
|
|
178
|
+
|| toolName === "resync_chapter_state"
|
|
179
|
+
|| toolName === "short_fiction_run"
|
|
180
|
+
|| toolName === "script_create"
|
|
181
|
+
|| toolName === "storyboard_create"
|
|
182
|
+
|| toolName === "interactive_film_create"
|
|
183
|
+
|| toolName === "translation_create"
|
|
184
|
+
|| toolName === "fanfic_create"
|
|
185
|
+
|| toolName === "continuation_import"
|
|
186
|
+
|| toolName === "spinoff_create"
|
|
187
|
+
|| toolName === "imitation_create"
|
|
188
|
+
|| toolName === "generate_cover"
|
|
189
|
+
|| toolName === "play_start"
|
|
190
|
+
|| toolName === "play_edit"
|
|
191
|
+
|| toolName === "play_revise"
|
|
192
|
+
|| toolName === "play_step"
|
|
193
|
+
|| toolName === "create_narrative_forecast"
|
|
194
|
+
|| toolName === "get_narrative_forecast"
|
|
195
|
+
|| toolName === "select_narrative_branch";
|
|
196
|
+
}
|
|
197
|
+
function hasUnansweredTerminalToolResult(messages) {
|
|
198
|
+
let assistantTextAfterTool = false;
|
|
199
|
+
for (let index = messages.length - 1; index >= 0; index -= 1) {
|
|
200
|
+
const message = messages[index];
|
|
201
|
+
if (!message || typeof message !== "object" || !("role" in message))
|
|
202
|
+
continue;
|
|
203
|
+
const role = message.role;
|
|
204
|
+
if (role === "user")
|
|
205
|
+
return false;
|
|
206
|
+
if (role === "assistant") {
|
|
207
|
+
const text = extractTextFromAssistant(message).trim();
|
|
208
|
+
if (text)
|
|
209
|
+
assistantTextAfterTool = true;
|
|
210
|
+
continue;
|
|
211
|
+
}
|
|
212
|
+
if (role !== "toolResult")
|
|
213
|
+
continue;
|
|
214
|
+
const toolName = message.toolName;
|
|
215
|
+
if (isTerminalProductionToolName(toolName)) {
|
|
216
|
+
return !assistantTextAfterTool;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
return false;
|
|
220
|
+
}
|
|
221
|
+
async function runInAgentSessionQueue(projectRoot, sessionId, task) {
|
|
222
|
+
const key = sessionQueueKey(projectRoot, sessionId);
|
|
223
|
+
const previous = agentSessionQueues.get(key) ?? Promise.resolve();
|
|
224
|
+
let release;
|
|
225
|
+
const gate = new Promise((resolve) => {
|
|
226
|
+
release = resolve;
|
|
227
|
+
});
|
|
228
|
+
const queued = previous.catch(() => undefined).then(() => gate);
|
|
229
|
+
agentSessionQueues.set(key, queued);
|
|
230
|
+
await previous.catch(() => undefined);
|
|
231
|
+
try {
|
|
232
|
+
return await task();
|
|
233
|
+
}
|
|
234
|
+
finally {
|
|
235
|
+
release();
|
|
236
|
+
if (agentSessionQueues.get(key) === queued) {
|
|
237
|
+
agentSessionQueues.delete(key);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
async function latestCommittedSeq(projectRoot, sessionId) {
|
|
242
|
+
const events = await readTranscriptEvents(projectRoot, sessionId);
|
|
243
|
+
return events
|
|
244
|
+
.filter((event) => event.type === "request_committed")
|
|
245
|
+
.reduce((max, event) => Math.max(max, event.seq), 0);
|
|
246
|
+
}
|
|
247
|
+
function transcriptRoleForMessage(message) {
|
|
248
|
+
if (!message || typeof message !== "object" || !("role" in message))
|
|
249
|
+
return null;
|
|
250
|
+
const role = message.role;
|
|
251
|
+
return role === "user" || role === "assistant" || role === "toolResult" || role === "system"
|
|
252
|
+
? role
|
|
253
|
+
: null;
|
|
254
|
+
}
|
|
255
|
+
function firstToolCallId(message) {
|
|
256
|
+
if (!message || typeof message !== "object" || !("content" in message))
|
|
257
|
+
return undefined;
|
|
258
|
+
const content = message.content;
|
|
259
|
+
if (!Array.isArray(content))
|
|
260
|
+
return undefined;
|
|
261
|
+
const block = content.find((item) => !!item &&
|
|
262
|
+
typeof item === "object" &&
|
|
263
|
+
item.type === "toolCall" &&
|
|
264
|
+
typeof item.id === "string");
|
|
265
|
+
return block?.id;
|
|
266
|
+
}
|
|
267
|
+
function toolCallIdForMessage(message) {
|
|
268
|
+
if (!message || typeof message !== "object")
|
|
269
|
+
return undefined;
|
|
270
|
+
if (message.role === "toolResult") {
|
|
271
|
+
const toolCallId = message.toolCallId;
|
|
272
|
+
return typeof toolCallId === "string" && toolCallId.length > 0 ? toolCallId : undefined;
|
|
273
|
+
}
|
|
274
|
+
return firstToolCallId(message);
|
|
275
|
+
}
|
|
276
|
+
function messageTimestamp(message) {
|
|
277
|
+
if (message && typeof message === "object") {
|
|
278
|
+
const timestamp = message.timestamp;
|
|
279
|
+
if (typeof timestamp === "number" && Number.isFinite(timestamp) && timestamp >= 0) {
|
|
280
|
+
return Math.floor(timestamp);
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
return Date.now();
|
|
284
|
+
}
|
|
285
|
+
async function ensureSessionCreatedEvent(projectRoot, sessionId, bookId, sessionKind) {
|
|
286
|
+
await appendTranscriptEvents(projectRoot, sessionId, ({ events, nextSeq }) => {
|
|
287
|
+
if (events.some((event) => event.type === "session_created"))
|
|
288
|
+
return [];
|
|
289
|
+
const now = Date.now();
|
|
290
|
+
return [{
|
|
291
|
+
type: "session_created",
|
|
292
|
+
version: 1,
|
|
293
|
+
sessionId,
|
|
294
|
+
seq: nextSeq,
|
|
295
|
+
timestamp: now,
|
|
296
|
+
bookId,
|
|
297
|
+
...(sessionKind ? { sessionKind } : {}),
|
|
298
|
+
title: null,
|
|
299
|
+
createdAt: now,
|
|
300
|
+
updatedAt: now,
|
|
301
|
+
}];
|
|
302
|
+
});
|
|
303
|
+
}
|
|
304
|
+
async function appendAgentTranscriptEvent(projectRoot, sessionId, buildEvent) {
|
|
305
|
+
const events = await appendTranscriptEvents(projectRoot, sessionId, ({ nextSeq }) => [
|
|
306
|
+
buildEvent(nextSeq),
|
|
307
|
+
]);
|
|
308
|
+
const event = events[0];
|
|
309
|
+
if (!event)
|
|
310
|
+
throw new Error(`Failed to append transcript event for session "${sessionId}"`);
|
|
311
|
+
return event;
|
|
312
|
+
}
|
|
313
|
+
/**
|
|
314
|
+
* Extract readable text from an AssistantMessage's content array.
|
|
315
|
+
* Filters out tool-call blocks; concatenates text blocks.
|
|
316
|
+
*/
|
|
317
|
+
function extractTextFromAssistant(msg) {
|
|
318
|
+
return msg.content
|
|
319
|
+
.filter((c) => c.type === "text")
|
|
320
|
+
.map((c) => c.text)
|
|
321
|
+
.join("");
|
|
322
|
+
}
|
|
323
|
+
function lastAssistantMessage(messages) {
|
|
324
|
+
for (let i = messages.length - 1; i >= 0; i--) {
|
|
325
|
+
const msg = messages[i];
|
|
326
|
+
if (msg && typeof msg === "object" && "role" in msg && msg.role === "assistant") {
|
|
327
|
+
return msg;
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
return undefined;
|
|
331
|
+
}
|
|
332
|
+
function assistantErrorMessage(message) {
|
|
333
|
+
return message &&
|
|
334
|
+
(message.stopReason === "error" || message.stopReason === "aborted") &&
|
|
335
|
+
message.errorMessage
|
|
336
|
+
? message.errorMessage
|
|
337
|
+
: undefined;
|
|
338
|
+
}
|
|
339
|
+
function convertAgentMessagesForModel(messages, model) {
|
|
340
|
+
const llmMessages = messages.flatMap((message) => {
|
|
341
|
+
if (!message || typeof message !== "object" || !("role" in message))
|
|
342
|
+
return [];
|
|
343
|
+
const raw = message;
|
|
344
|
+
if (raw.role === "user" || raw.role === "assistant" || raw.role === "toolResult") {
|
|
345
|
+
return [message];
|
|
346
|
+
}
|
|
347
|
+
if (raw.role === "system" && typeof raw.content === "string") {
|
|
348
|
+
return [{
|
|
349
|
+
role: "user",
|
|
350
|
+
content: raw.content,
|
|
351
|
+
timestamp: messageTimestamp(message),
|
|
352
|
+
}];
|
|
353
|
+
}
|
|
354
|
+
return [];
|
|
355
|
+
});
|
|
356
|
+
const candidate = model;
|
|
357
|
+
// InkOS's internal `toolResult` role is not part of the OpenAI Chat Completions spec.
|
|
358
|
+
// Many openai-completions upstreams (Google, and kkaiapi/DeepSeek-Pro-style gateways) reject
|
|
359
|
+
// it outright — which surfaces as an opaque "503 provider temporarily unavailable" — so fold
|
|
360
|
+
// tool results into a plain user message for EVERY openai-completions endpoint, not just Google.
|
|
361
|
+
// Anthropic-format endpoints (MiniMax / 百炼) handle tool results natively and are left untouched.
|
|
362
|
+
const isOpenAICompletionsCompatible = candidate.api === "openai-completions";
|
|
363
|
+
if (!isOpenAICompletionsCompatible)
|
|
364
|
+
return llmMessages;
|
|
365
|
+
const converted = [];
|
|
366
|
+
const pushToolResultsAsUser = (toolResults) => {
|
|
367
|
+
const lines = toolResults.flatMap((result) => {
|
|
368
|
+
const content = result.content
|
|
369
|
+
.map((block) => block.type === "text" ? block.text : "[image]")
|
|
370
|
+
.filter(Boolean)
|
|
371
|
+
.join("\n")
|
|
372
|
+
.trim() || "(empty tool result)";
|
|
373
|
+
return [`- ${result.toolName} (${result.toolCallId}):`, content];
|
|
374
|
+
});
|
|
375
|
+
converted.push({
|
|
376
|
+
role: "user",
|
|
377
|
+
content: [
|
|
378
|
+
"[Tool results]",
|
|
379
|
+
...lines,
|
|
380
|
+
"Use these tool results to answer the active user request. If a tool failed, explain the failure and choose the next useful action.",
|
|
381
|
+
].join("\n"),
|
|
382
|
+
timestamp: toolResults.reduce((max, result) => Math.max(max, messageTimestamp(result)), 0) || Date.now(),
|
|
383
|
+
});
|
|
384
|
+
};
|
|
385
|
+
for (let i = 0; i < llmMessages.length; i++) {
|
|
386
|
+
const message = llmMessages[i];
|
|
387
|
+
if (message.role === "assistant") {
|
|
388
|
+
const textContent = message.content.filter((block) => block.type === "text" && typeof block.text === "string" && block.text.trim().length > 0);
|
|
389
|
+
if (textContent.length === 1 &&
|
|
390
|
+
message.content.length === 1 &&
|
|
391
|
+
textContent[0].text.trim() === TOOL_RESULT_BRIDGE_TEXT) {
|
|
392
|
+
continue;
|
|
393
|
+
}
|
|
394
|
+
const toolCallIds = new Set();
|
|
395
|
+
for (const block of message.content) {
|
|
396
|
+
if (block.type === "toolCall" && typeof block.id === "string" && block.id.length > 0) {
|
|
397
|
+
toolCallIds.add(block.id);
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
if (toolCallIds.size === 0) {
|
|
401
|
+
converted.push(message);
|
|
402
|
+
continue;
|
|
403
|
+
}
|
|
404
|
+
if (textContent.length > 0) {
|
|
405
|
+
converted.push({ ...message, content: textContent });
|
|
406
|
+
}
|
|
407
|
+
const toolResults = [];
|
|
408
|
+
let nextIndex = i + 1;
|
|
409
|
+
while (nextIndex < llmMessages.length) {
|
|
410
|
+
const next = llmMessages[nextIndex];
|
|
411
|
+
if (next.role !== "toolResult" || !toolCallIds.has(next.toolCallId))
|
|
412
|
+
break;
|
|
413
|
+
toolResults.push(next);
|
|
414
|
+
nextIndex += 1;
|
|
415
|
+
}
|
|
416
|
+
if (toolResults.length > 0) {
|
|
417
|
+
pushToolResultsAsUser(toolResults);
|
|
418
|
+
i = nextIndex - 1;
|
|
419
|
+
}
|
|
420
|
+
continue;
|
|
421
|
+
}
|
|
422
|
+
if (message.role === "toolResult") {
|
|
423
|
+
pushToolResultsAsUser([message]);
|
|
424
|
+
continue;
|
|
425
|
+
}
|
|
426
|
+
converted.push(message);
|
|
427
|
+
}
|
|
428
|
+
return converted;
|
|
429
|
+
}
|
|
430
|
+
/**
|
|
431
|
+
* Extract thinking/reasoning text from an AssistantMessage's content array.
|
|
432
|
+
*/
|
|
433
|
+
function extractThinkingFromAssistant(msg) {
|
|
434
|
+
return msg.content
|
|
435
|
+
.filter((c) => c.type === "thinking")
|
|
436
|
+
.map((c) => c.thinking ?? "")
|
|
437
|
+
.join("");
|
|
438
|
+
}
|
|
439
|
+
/**
|
|
440
|
+
* Convert plain `{ role, content }` messages (from BookSession disk storage)
|
|
441
|
+
* back into pi-agent AgentMessage format so they can be loaded into an Agent.
|
|
442
|
+
*/
|
|
443
|
+
function plainToAgentMessages(plain) {
|
|
444
|
+
return plain.map((m) => {
|
|
445
|
+
const ts = Date.now();
|
|
446
|
+
if (m.role === "user") {
|
|
447
|
+
return { role: "user", content: m.content, timestamp: ts };
|
|
448
|
+
}
|
|
449
|
+
// For stored assistant messages we only have the text.
|
|
450
|
+
// Re-wrap as a minimal AssistantMessage with a single TextContent.
|
|
451
|
+
return {
|
|
452
|
+
role: "assistant",
|
|
453
|
+
content: [{ type: "text", text: m.content }],
|
|
454
|
+
api: "anthropic-messages",
|
|
455
|
+
provider: "anthropic",
|
|
456
|
+
model: "unknown",
|
|
457
|
+
usage: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, totalTokens: 0, cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 } },
|
|
458
|
+
stopReason: "stop",
|
|
459
|
+
timestamp: ts,
|
|
460
|
+
};
|
|
461
|
+
});
|
|
462
|
+
}
|
|
463
|
+
/**
|
|
464
|
+
* Flatten the Agent's in-memory messages to plain `{ role, content }` pairs
|
|
465
|
+
* suitable for BookSession persistence.
|
|
466
|
+
*/
|
|
467
|
+
function agentMessagesToPlain(messages) {
|
|
468
|
+
const out = [];
|
|
469
|
+
for (const msg of messages) {
|
|
470
|
+
if (!msg || typeof msg !== "object" || !("role" in msg))
|
|
471
|
+
continue;
|
|
472
|
+
const m = msg;
|
|
473
|
+
if (m.role === "user") {
|
|
474
|
+
const content = typeof m.content === "string"
|
|
475
|
+
? m.content
|
|
476
|
+
: Array.isArray(m.content)
|
|
477
|
+
? m.content
|
|
478
|
+
.filter((c) => c.type === "text")
|
|
479
|
+
.map((c) => c.text)
|
|
480
|
+
.join("")
|
|
481
|
+
: "";
|
|
482
|
+
if (content)
|
|
483
|
+
out.push({ role: "user", content });
|
|
484
|
+
}
|
|
485
|
+
else if (m.role === "assistant") {
|
|
486
|
+
const text = extractTextFromAssistant(m);
|
|
487
|
+
const thinking = extractThinkingFromAssistant(m);
|
|
488
|
+
if (text || thinking) {
|
|
489
|
+
const entry = { role: "assistant", content: text };
|
|
490
|
+
if (thinking)
|
|
491
|
+
entry.thinking = thinking;
|
|
492
|
+
out.push(entry);
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
// ToolResult messages are internal; skip them for persistence.
|
|
496
|
+
}
|
|
497
|
+
return out;
|
|
498
|
+
}
|
|
499
|
+
// ---------------------------------------------------------------------------
|
|
500
|
+
// Main entry point
|
|
501
|
+
// ---------------------------------------------------------------------------
|
|
502
|
+
/**
|
|
503
|
+
* 会创建/修改书籍与产物的生产工具。suppressProductionTools 为 true(同会话
|
|
504
|
+
* 有后台生产任务在运行)时从工具表剔除;read/grep/ls、research/material 与
|
|
505
|
+
* propose_action 保留——propose_action 引发的确认任务在 host 侧另有单任务闸门。
|
|
506
|
+
*/
|
|
507
|
+
const PRODUCTION_MUTATION_TOOL_NAMES = new Set([
|
|
508
|
+
"sub_agent",
|
|
509
|
+
"generate_cover",
|
|
510
|
+
"write_truth_file",
|
|
511
|
+
"rename_entity",
|
|
512
|
+
"patch_chapter_text",
|
|
513
|
+
"replace_chapter_text",
|
|
514
|
+
"resync_chapter_state",
|
|
515
|
+
"delete_latest_chapter",
|
|
516
|
+
"import_chapters",
|
|
517
|
+
"fanfic_create",
|
|
518
|
+
"continuation_import",
|
|
519
|
+
"spinoff_create",
|
|
520
|
+
"imitation_create",
|
|
521
|
+
]);
|
|
522
|
+
function createAgentToolsForMode(params) {
|
|
523
|
+
const tools = createModeTools(params);
|
|
524
|
+
return params.intentSkillTool ? [...tools, params.intentSkillTool] : tools;
|
|
525
|
+
}
|
|
526
|
+
function createModeTools(params) {
|
|
527
|
+
const lang = params.language === "en" ? "en" : "zh";
|
|
528
|
+
const subAgentTool = createSubAgentTool(params.pipeline, params.bookId, params.projectRoot, {
|
|
529
|
+
actionPayload: params.actionPayload,
|
|
530
|
+
language: lang,
|
|
531
|
+
activeSkills: params.activeSkills,
|
|
532
|
+
workerSkills: params.workerSkills,
|
|
533
|
+
});
|
|
534
|
+
const proposalTool = createProposeActionTool(lang, {
|
|
535
|
+
sameSession: params.sessionKind !== "chat",
|
|
536
|
+
requestedSkillIds: params.requestedSkillIds,
|
|
537
|
+
attachmentPaths: params.attachmentPaths,
|
|
538
|
+
});
|
|
539
|
+
const researchTool = createResearchWebTool(params.projectRoot);
|
|
540
|
+
const materialTool = createIngestMaterialTool(params.projectRoot);
|
|
541
|
+
const materialRetrievalTool = createRetrieveMaterialTool(params.projectRoot);
|
|
542
|
+
const projectReadTool = createReadTool(params.projectRoot, { scope: "project" });
|
|
543
|
+
const importChaptersTool = createImportChaptersTool(params.pipeline, params.bookId, params.projectRoot);
|
|
544
|
+
const isConfirmed = (intent) => {
|
|
545
|
+
return (params.actionSource === "button" || params.actionSource === "slash")
|
|
546
|
+
&& params.requestedIntent === intent;
|
|
547
|
+
};
|
|
548
|
+
if (params.sessionKind === "chat") {
|
|
549
|
+
if (isConfirmed("translation_create")) {
|
|
550
|
+
return [createTranslationCreateTool(params.projectRoot, { actionPayload: params.actionPayload })];
|
|
551
|
+
}
|
|
552
|
+
if (isConfirmed("fanfic_init")) {
|
|
553
|
+
return [createFanficBookTool(params.pipeline, params.projectRoot, {
|
|
554
|
+
defaultSkills: params.productionSkills?.("longWriting"),
|
|
555
|
+
activeSkills: params.activeSkills,
|
|
556
|
+
})];
|
|
557
|
+
}
|
|
558
|
+
if (isConfirmed("continuation_import")) {
|
|
559
|
+
return [createContinuationImportTool(params.pipeline, params.bookId, params.projectRoot, {
|
|
560
|
+
defaultSkills: params.productionSkills?.("longWriting"),
|
|
561
|
+
activeSkills: params.activeSkills,
|
|
562
|
+
})];
|
|
563
|
+
}
|
|
564
|
+
if (isConfirmed("spinoff_create")) {
|
|
565
|
+
return [createSpinoffBookTool(params.pipeline, params.projectRoot, {
|
|
566
|
+
defaultSkills: params.productionSkills?.("longWriting"),
|
|
567
|
+
activeSkills: params.activeSkills,
|
|
568
|
+
})];
|
|
569
|
+
}
|
|
570
|
+
if (isConfirmed("style_imitation")) {
|
|
571
|
+
return [createImitationBookTool(params.pipeline, params.projectRoot, {
|
|
572
|
+
defaultSkills: params.productionSkills?.("longWriting"),
|
|
573
|
+
activeSkills: params.activeSkills,
|
|
574
|
+
})];
|
|
575
|
+
}
|
|
576
|
+
return [proposalTool, researchTool, materialTool, materialRetrievalTool, importChaptersTool];
|
|
577
|
+
}
|
|
578
|
+
if (params.sessionKind === "short") {
|
|
579
|
+
if (isConfirmed("short_run")) {
|
|
580
|
+
return [createShortFictionRunTool(params.pipeline, params.projectRoot, {
|
|
581
|
+
actionPayload: params.actionPayload,
|
|
582
|
+
language: lang,
|
|
583
|
+
defaultSkills: params.productionSkills?.("shortWriting"),
|
|
584
|
+
activeSkills: params.activeSkills,
|
|
585
|
+
})];
|
|
586
|
+
}
|
|
587
|
+
if (isConfirmed("generate_cover")) {
|
|
588
|
+
return [createGenerateCoverTool(params.projectRoot, { actionPayload: params.actionPayload })];
|
|
589
|
+
}
|
|
590
|
+
return [proposalTool, materialTool, materialRetrievalTool];
|
|
591
|
+
}
|
|
592
|
+
if (params.sessionKind === "script") {
|
|
593
|
+
if (isConfirmed("script_create")) {
|
|
594
|
+
return [createScriptCreationTool(params.pipeline, params.projectRoot, {
|
|
595
|
+
actionPayload: params.actionPayload,
|
|
596
|
+
language: lang,
|
|
597
|
+
defaultSkills: params.productionSkills?.("script"),
|
|
598
|
+
activeSkills: params.activeSkills,
|
|
599
|
+
})];
|
|
600
|
+
}
|
|
601
|
+
return [proposalTool, projectReadTool, materialTool, materialRetrievalTool];
|
|
602
|
+
}
|
|
603
|
+
if (params.sessionKind === "storyboard") {
|
|
604
|
+
if (isConfirmed("storyboard_create")) {
|
|
605
|
+
return [createStoryboardCreationTool(params.pipeline, params.projectRoot, {
|
|
606
|
+
actionPayload: params.actionPayload,
|
|
607
|
+
language: lang,
|
|
608
|
+
defaultSkills: params.productionSkills?.("storyboard"),
|
|
609
|
+
activeSkills: params.activeSkills,
|
|
610
|
+
})];
|
|
611
|
+
}
|
|
612
|
+
return [proposalTool, projectReadTool, materialTool, materialRetrievalTool];
|
|
613
|
+
}
|
|
614
|
+
if (params.sessionKind === "interactive-film") {
|
|
615
|
+
if (isConfirmed("interactive_film_create")) {
|
|
616
|
+
return [createInteractiveFilmCreationTool(params.pipeline, params.projectRoot, {
|
|
617
|
+
actionPayload: params.actionPayload,
|
|
618
|
+
language: lang,
|
|
619
|
+
defaultSkills: params.productionSkills?.("interactiveFilm"),
|
|
620
|
+
activeSkills: params.activeSkills,
|
|
621
|
+
})];
|
|
622
|
+
}
|
|
623
|
+
return [proposalTool, projectReadTool, materialTool, materialRetrievalTool];
|
|
624
|
+
}
|
|
625
|
+
if (params.sessionKind === "interactive-film-authoring") {
|
|
626
|
+
const projectId = params.bookId;
|
|
627
|
+
if (!projectId) {
|
|
628
|
+
throw new Error("interactive-film-authoring session requires a non-null bookId");
|
|
629
|
+
}
|
|
630
|
+
const agentCtx = params.pipeline.createAgentContext("film-authoring", projectId);
|
|
631
|
+
const llm = filmLLMDepsFromClient(agentCtx.client, agentCtx.model, {
|
|
632
|
+
activatedSkills: () => mergeActivatedSkillGuidance(params.productionSkills?.("interactiveFilm") ?? [], params.activeSkills?.() ?? []),
|
|
633
|
+
});
|
|
634
|
+
return createFilmAuthoringTools({
|
|
635
|
+
projectRoot: params.projectRoot,
|
|
636
|
+
projectId,
|
|
637
|
+
llm,
|
|
638
|
+
proposeActionTool: proposalTool,
|
|
639
|
+
confirmedIntent: params.requestedIntent,
|
|
640
|
+
language: lang,
|
|
641
|
+
});
|
|
642
|
+
}
|
|
643
|
+
if (params.sessionKind === "play") {
|
|
644
|
+
if (isConfirmed("play_start")) {
|
|
645
|
+
return [createPlayStartTool(params.pipeline, params.projectRoot, params.sessionId, params.playMode, {
|
|
646
|
+
actionPayload: params.actionPayload,
|
|
647
|
+
defaultSkills: params.productionSkills?.("play"),
|
|
648
|
+
activeSkills: params.activeSkills,
|
|
649
|
+
})];
|
|
650
|
+
}
|
|
651
|
+
if (params.playWorldExists) {
|
|
652
|
+
return [
|
|
653
|
+
createPlayEditTool(params.projectRoot, params.sessionId, lang),
|
|
654
|
+
createPlayReviseTool(params.pipeline, params.projectRoot, params.sessionId, {
|
|
655
|
+
language: lang,
|
|
656
|
+
defaultSkills: params.productionSkills?.("play"),
|
|
657
|
+
activeSkills: params.activeSkills,
|
|
658
|
+
}),
|
|
659
|
+
createPlayStepTool(params.pipeline, params.projectRoot, params.sessionId, {
|
|
660
|
+
language: lang,
|
|
661
|
+
defaultSkills: params.productionSkills?.("play"),
|
|
662
|
+
activeSkills: params.activeSkills,
|
|
663
|
+
}),
|
|
664
|
+
materialTool,
|
|
665
|
+
materialRetrievalTool,
|
|
666
|
+
];
|
|
667
|
+
}
|
|
668
|
+
return [proposalTool, materialTool, materialRetrievalTool];
|
|
669
|
+
}
|
|
670
|
+
if (params.sessionKind === "book-create" && !params.bookId) {
|
|
671
|
+
if (isConfirmed("create_book")) {
|
|
672
|
+
return [createSubAgentTool(params.pipeline, params.bookId, params.projectRoot, {
|
|
673
|
+
actionPayload: params.actionPayload,
|
|
674
|
+
architectCreateOnly: true,
|
|
675
|
+
language: lang,
|
|
676
|
+
activeSkills: params.activeSkills,
|
|
677
|
+
workerSkills: params.workerSkills,
|
|
678
|
+
})];
|
|
679
|
+
}
|
|
680
|
+
return [proposalTool, researchTool, materialTool, materialRetrievalTool];
|
|
681
|
+
}
|
|
682
|
+
if (!params.bookId) {
|
|
683
|
+
return [];
|
|
684
|
+
}
|
|
685
|
+
const bookTools = [
|
|
686
|
+
subAgentTool,
|
|
687
|
+
createGenerateCoverTool(params.projectRoot, { actionPayload: params.actionPayload }),
|
|
688
|
+
createReadTool(params.projectRoot, { allowSystemPaths: params.allowSystemFileRead }),
|
|
689
|
+
createWriteTruthFileTool(params.pipeline, params.projectRoot, params.bookId),
|
|
690
|
+
createRenameEntityTool(params.pipeline, params.projectRoot, params.bookId),
|
|
691
|
+
createPatchChapterTextTool(params.pipeline, params.projectRoot, params.bookId),
|
|
692
|
+
createReplaceChapterTextTool(params.pipeline, params.projectRoot, params.bookId),
|
|
693
|
+
createResyncChapterStateTool(params.pipeline, params.bookId, {
|
|
694
|
+
language: lang,
|
|
695
|
+
defaultSkills: params.productionSkills?.("longWriting"),
|
|
696
|
+
activeSkills: params.activeSkills,
|
|
697
|
+
}),
|
|
698
|
+
createDeleteLatestChapterTool(params.projectRoot, params.bookId),
|
|
699
|
+
researchTool,
|
|
700
|
+
materialTool,
|
|
701
|
+
materialRetrievalTool,
|
|
702
|
+
createManageBookReferenceTool(params.projectRoot, params.bookId),
|
|
703
|
+
importChaptersTool,
|
|
704
|
+
createNarrativeForecastCreateTool(params.pipeline, params.bookId, params.projectRoot),
|
|
705
|
+
createNarrativeForecastGetTool(params.bookId, params.projectRoot),
|
|
706
|
+
createNarrativeForecastSelectTool(params.bookId, params.projectRoot),
|
|
707
|
+
createGrepTool(params.projectRoot),
|
|
708
|
+
createLsTool(params.projectRoot),
|
|
709
|
+
];
|
|
710
|
+
if (params.sessionKind === "edit") {
|
|
711
|
+
// Edit mode stays deterministic: forecast create runs an LLM projection,
|
|
712
|
+
// and get/select belong to the planning workflow, not text editing.
|
|
713
|
+
return bookTools.filter((tool) => ![
|
|
714
|
+
"sub_agent",
|
|
715
|
+
"generate_cover",
|
|
716
|
+
"research_web",
|
|
717
|
+
"import_chapters",
|
|
718
|
+
"create_narrative_forecast",
|
|
719
|
+
"get_narrative_forecast",
|
|
720
|
+
"select_narrative_branch",
|
|
721
|
+
].includes(tool.name));
|
|
722
|
+
}
|
|
723
|
+
return bookTools;
|
|
724
|
+
}
|
|
725
|
+
/**
|
|
726
|
+
* Run a single conversation turn within a cached Agent session.
|
|
727
|
+
*
|
|
728
|
+
* If the session already exists in the cache, reuses the Agent (with its full
|
|
729
|
+
* in-memory message history including tool calls). Otherwise creates a new
|
|
730
|
+
* Agent, optionally restoring messages from `initialMessages`.
|
|
731
|
+
*/
|
|
732
|
+
export async function runAgentSession(config, userMessage, initialMessages) {
|
|
733
|
+
return runInAgentSessionQueue(config.projectRoot, config.sessionId, () => runAgentSessionUnlocked(config, userMessage, initialMessages));
|
|
734
|
+
}
|
|
735
|
+
async function runAgentSessionUnlocked(config, userMessage, initialMessages) {
|
|
736
|
+
const { sessionId, language, pipeline, projectRoot, onEvent, onContextCompression } = config;
|
|
737
|
+
// Normalize at the entry point so downstream comparisons, closures, and
|
|
738
|
+
// fs paths never see `undefined`. The type is already `string | null`, but
|
|
739
|
+
// some callers may bypass the type system (e.g. `activeBookId ?? null` gets
|
|
740
|
+
// skipped) and we don't want that to (a) throw in path.join or (b) trigger
|
|
741
|
+
// a spurious cache eviction because `null !== undefined`.
|
|
742
|
+
const bookId = config.bookId ? assertSafeBookId(config.bookId) : null;
|
|
743
|
+
const sessionKind = config.sessionKind ?? (bookId ? "book" : "chat");
|
|
744
|
+
const playMode = config.playMode;
|
|
745
|
+
const actionSource = config.actionSource ?? "free-text";
|
|
746
|
+
const requestedIntent = config.requestedIntent;
|
|
747
|
+
const actionPayload = config.actionPayload;
|
|
748
|
+
const actionPayloadKey = actionPayloadCacheKey(actionPayload);
|
|
749
|
+
const configuredSkills = await loadAvailableAgentSkills({ projectRoot });
|
|
750
|
+
const skillRegistry = createSkillRegistry({ skills: configuredSkills.skills });
|
|
751
|
+
const skillResolution = skillRegistry.resolveSkills({
|
|
752
|
+
requestedSkills: config.requestedSkills,
|
|
753
|
+
disabledSkills: config.disabledSkills,
|
|
754
|
+
});
|
|
755
|
+
const skillResolutionKey = skillResolutionCacheKey(skillResolution);
|
|
756
|
+
const model = resolveModel(config.model);
|
|
757
|
+
const requestedModelIdentity = agentModelIdentity(model);
|
|
758
|
+
const allowSystemFileRead = config.allowSystemFileRead ?? envFlagEnabled(process.env.INKOS_AGENT_ALLOW_SYSTEM_READ, false);
|
|
759
|
+
const suppressProductionTools = config.suppressProductionTools ?? false;
|
|
760
|
+
const playWorldExists = sessionKind === "play"
|
|
761
|
+
? Boolean(await new PlayStore(projectRoot).loadWorld(sessionId))
|
|
762
|
+
: false;
|
|
763
|
+
const cacheKey = agentCacheKey(projectRoot, sessionId);
|
|
764
|
+
// ----- Resolve or create Agent -----
|
|
765
|
+
let cached = agentCache.get(cacheKey);
|
|
766
|
+
let currentCommittedSeq;
|
|
767
|
+
if (cached) {
|
|
768
|
+
currentCommittedSeq = await latestCommittedSeq(projectRoot, sessionId);
|
|
769
|
+
// Evict and rebuild if model protocol identity OR bookId changed. Both are
|
|
770
|
+
// captured into the Agent at construction time (model via initialState,
|
|
771
|
+
// bookId via closures in systemPrompt / tools / transformContext), so a
|
|
772
|
+
// mismatch means the cached Agent would keep using stale context.
|
|
773
|
+
const modelChanged = cached.modelIdentity !== requestedModelIdentity;
|
|
774
|
+
const projectRootChanged = cached.projectRoot !== projectRoot;
|
|
775
|
+
const bookChanged = cached.bookId !== bookId;
|
|
776
|
+
const sessionKindChanged = cached.sessionKind !== sessionKind;
|
|
777
|
+
const actionSourceChanged = cached.actionSource !== actionSource;
|
|
778
|
+
const requestedIntentChanged = cached.requestedIntent !== requestedIntent;
|
|
779
|
+
const actionPayloadChanged = cached.actionPayloadKey !== actionPayloadKey;
|
|
780
|
+
const skillResolutionChanged = cached.skillResolutionKey !== skillResolutionKey;
|
|
781
|
+
const languageChanged = cached.language !== language;
|
|
782
|
+
const apiKeyChanged = cached.apiKey !== config.apiKey;
|
|
783
|
+
const readPermissionChanged = cached.allowSystemFileRead !== allowSystemFileRead;
|
|
784
|
+
const playWorldChanged = cached.playWorldExists !== playWorldExists;
|
|
785
|
+
const backgroundTaskContextChanged = cached.backgroundTaskContext !== config.backgroundTaskContext;
|
|
786
|
+
const suppressProductionToolsChanged = cached.suppressProductionTools !== suppressProductionTools;
|
|
787
|
+
const transcriptChanged = cached.lastCommittedSeq !== currentCommittedSeq;
|
|
788
|
+
if (modelChanged ||
|
|
789
|
+
projectRootChanged ||
|
|
790
|
+
bookChanged ||
|
|
791
|
+
sessionKindChanged ||
|
|
792
|
+
actionSourceChanged ||
|
|
793
|
+
requestedIntentChanged ||
|
|
794
|
+
actionPayloadChanged ||
|
|
795
|
+
skillResolutionChanged ||
|
|
796
|
+
languageChanged ||
|
|
797
|
+
apiKeyChanged ||
|
|
798
|
+
readPermissionChanged ||
|
|
799
|
+
playWorldChanged ||
|
|
800
|
+
backgroundTaskContextChanged ||
|
|
801
|
+
suppressProductionToolsChanged ||
|
|
802
|
+
transcriptChanged) {
|
|
803
|
+
agentCache.delete(cacheKey);
|
|
804
|
+
cached = undefined;
|
|
805
|
+
}
|
|
806
|
+
}
|
|
807
|
+
if (!cached) {
|
|
808
|
+
const restoredHistory = await restoreAgentMessagesFromTranscript(projectRoot, sessionId, sessionKind);
|
|
809
|
+
if (restoredHistory.length > 0) {
|
|
810
|
+
onContextCompression?.({
|
|
811
|
+
category: "session_context",
|
|
812
|
+
phase: "start",
|
|
813
|
+
sources: ["session transcript"],
|
|
814
|
+
});
|
|
815
|
+
onContextCompression?.({
|
|
816
|
+
category: "session_context",
|
|
817
|
+
phase: "end",
|
|
818
|
+
sources: ["session transcript"],
|
|
819
|
+
});
|
|
820
|
+
}
|
|
821
|
+
const restoredMessages = appendRestoredHistoryBoundary(adaptRestoredAgentMessagesForModel(restoredHistory, model), language);
|
|
822
|
+
const initialAgentMessages = restoredMessages.length > 0
|
|
823
|
+
? restoredMessages
|
|
824
|
+
: initialMessages && initialMessages.length > 0
|
|
825
|
+
? plainToAgentMessages(initialMessages)
|
|
826
|
+
: [];
|
|
827
|
+
let terminalToolResultTail = false;
|
|
828
|
+
const turnSkills = new Map(skillResolution.usedSkills.map((skill) => [skill.id, { skill, resources: [] }]));
|
|
829
|
+
const productionSkills = (capability) => (resolveProductionSkillActivations(skillResolution.availableSkills, capability));
|
|
830
|
+
const allowIntentSkillSelection = actionSource === "free-text"
|
|
831
|
+
&& skillResolution.forcedSkillIds.length === 0;
|
|
832
|
+
const baseSystemPrompt = buildAgentSystemPrompt(bookId, language, sessionKind, {
|
|
833
|
+
actionSource,
|
|
834
|
+
requestedIntent,
|
|
835
|
+
playWorldExists,
|
|
836
|
+
skills: skillResolution,
|
|
837
|
+
allowIntentSkillSelection,
|
|
838
|
+
});
|
|
839
|
+
const intentSkillTool = allowIntentSkillSelection
|
|
840
|
+
? createUseSkillTool({
|
|
841
|
+
registry: skillRegistry,
|
|
842
|
+
disabledSkillIds: skillResolution.disabledSkillIds,
|
|
843
|
+
onActivate: (activation) => turnSkills.set(activation.skill.id, activation),
|
|
844
|
+
})
|
|
845
|
+
: undefined;
|
|
846
|
+
const agentTools = createAgentToolsForMode({
|
|
847
|
+
pipeline,
|
|
848
|
+
bookId,
|
|
849
|
+
sessionId,
|
|
850
|
+
sessionKind,
|
|
851
|
+
actionSource,
|
|
852
|
+
requestedIntent,
|
|
853
|
+
actionPayload,
|
|
854
|
+
projectRoot,
|
|
855
|
+
allowSystemFileRead,
|
|
856
|
+
language,
|
|
857
|
+
playMode,
|
|
858
|
+
playWorldExists,
|
|
859
|
+
intentSkillTool,
|
|
860
|
+
requestedSkillIds: () => [...turnSkills.keys()],
|
|
861
|
+
attachmentPaths: () => cached?.currentAttachmentPaths ?? [],
|
|
862
|
+
activeSkills: () => [...turnSkills.values()],
|
|
863
|
+
workerSkills: (agent) => {
|
|
864
|
+
if (agent === "architect" || agent === "writer")
|
|
865
|
+
return productionSkills("longWriting");
|
|
866
|
+
if (agent === "auditor" || agent === "reviser")
|
|
867
|
+
return productionSkills("longReview");
|
|
868
|
+
return [];
|
|
869
|
+
},
|
|
870
|
+
productionSkills,
|
|
871
|
+
});
|
|
872
|
+
const agent = new Agent({
|
|
873
|
+
initialState: {
|
|
874
|
+
model,
|
|
875
|
+
systemPrompt: config.backgroundTaskContext
|
|
876
|
+
? `${baseSystemPrompt}\n\n${config.backgroundTaskContext}`
|
|
877
|
+
: baseSystemPrompt,
|
|
878
|
+
tools: suppressProductionTools
|
|
879
|
+
? agentTools.filter((tool) => !PRODUCTION_MUTATION_TOOL_NAMES.has(tool.name))
|
|
880
|
+
: agentTools,
|
|
881
|
+
messages: initialAgentMessages,
|
|
882
|
+
},
|
|
883
|
+
transformContext: sessionKind === "interactive-film-authoring" && bookId
|
|
884
|
+
? createInteractiveFilmContextTransform(bookId, projectRoot)
|
|
885
|
+
: createBookContextTransform(bookId, projectRoot, { onContextCompression }),
|
|
886
|
+
convertToLlm: (messages) => {
|
|
887
|
+
terminalToolResultTail = hasUnansweredTerminalToolResult(messages);
|
|
888
|
+
return convertAgentMessagesForModel(messages, model);
|
|
889
|
+
},
|
|
890
|
+
streamFn: (streamModel, context, options) => {
|
|
891
|
+
if (terminalToolResultTail) {
|
|
892
|
+
terminalToolResultTail = false;
|
|
893
|
+
return localAssistantStopStream(streamModel);
|
|
894
|
+
}
|
|
895
|
+
if (isLlmStubEnabled())
|
|
896
|
+
return stubAgentStream(streamModel, context);
|
|
897
|
+
return guardedPiStream(streamModel, context, options);
|
|
898
|
+
},
|
|
899
|
+
getApiKey: (provider) => {
|
|
900
|
+
if (config.apiKey)
|
|
901
|
+
return config.apiKey;
|
|
902
|
+
return getEnvApiKey(provider);
|
|
903
|
+
},
|
|
904
|
+
});
|
|
905
|
+
cached = {
|
|
906
|
+
agent,
|
|
907
|
+
sessionId,
|
|
908
|
+
projectRoot,
|
|
909
|
+
bookId,
|
|
910
|
+
sessionKind,
|
|
911
|
+
actionSource,
|
|
912
|
+
requestedIntent,
|
|
913
|
+
actionPayloadKey,
|
|
914
|
+
skillResolutionKey,
|
|
915
|
+
turnSkills,
|
|
916
|
+
playWorldExists,
|
|
917
|
+
language,
|
|
918
|
+
modelIdentity: requestedModelIdentity,
|
|
919
|
+
apiKey: config.apiKey,
|
|
920
|
+
allowSystemFileRead,
|
|
921
|
+
backgroundTaskContext: config.backgroundTaskContext,
|
|
922
|
+
suppressProductionTools,
|
|
923
|
+
currentAttachmentPaths: (config.attachments ?? [])
|
|
924
|
+
.map((attachment) => attachment.storedPath?.trim())
|
|
925
|
+
.filter((path) => Boolean(path)),
|
|
926
|
+
lastCommittedSeq: currentCommittedSeq ?? await latestCommittedSeq(projectRoot, sessionId),
|
|
927
|
+
lastActive: Date.now(),
|
|
928
|
+
};
|
|
929
|
+
agentCache.set(cacheKey, cached);
|
|
930
|
+
ensureCleanupTimer();
|
|
931
|
+
}
|
|
932
|
+
cached.lastActive = Date.now();
|
|
933
|
+
cached.currentAttachmentPaths = (config.attachments ?? [])
|
|
934
|
+
.map((attachment) => attachment.storedPath?.trim())
|
|
935
|
+
.filter((path) => Boolean(path));
|
|
936
|
+
cached.turnSkills.clear();
|
|
937
|
+
for (const skill of skillResolution.usedSkills) {
|
|
938
|
+
cached.turnSkills.set(skill.id, { skill, resources: [] });
|
|
939
|
+
}
|
|
940
|
+
const { agent } = cached;
|
|
941
|
+
const attachmentBlock = buildAttachmentUserBlock(config.attachments, language);
|
|
942
|
+
const promptMessage = attachmentBlock ? `${userMessage}${attachmentBlock}` : userMessage;
|
|
943
|
+
const promptImages = attachmentImages(config.attachments);
|
|
944
|
+
// ----- Prepare transcript persistence -----
|
|
945
|
+
const requestId = randomUUID();
|
|
946
|
+
await ensureSessionCreatedEvent(projectRoot, sessionId, bookId, sessionKind);
|
|
947
|
+
await appendAgentTranscriptEvent(projectRoot, sessionId, (seq) => ({
|
|
948
|
+
type: "request_started",
|
|
949
|
+
version: 1,
|
|
950
|
+
sessionId,
|
|
951
|
+
requestId,
|
|
952
|
+
seq,
|
|
953
|
+
timestamp: Date.now(),
|
|
954
|
+
sessionKind,
|
|
955
|
+
input: promptMessage,
|
|
956
|
+
}));
|
|
957
|
+
let parentUuid = null;
|
|
958
|
+
let piTurnIndex = 0;
|
|
959
|
+
let lastAssistantUuid = null;
|
|
960
|
+
let skillTurnActive = cached.turnSkills.size > 0;
|
|
961
|
+
const persistAgentEvent = async (event) => {
|
|
962
|
+
if (event.type === "turn_start") {
|
|
963
|
+
piTurnIndex += 1;
|
|
964
|
+
return;
|
|
965
|
+
}
|
|
966
|
+
if (event.type !== "message_end")
|
|
967
|
+
return;
|
|
968
|
+
const role = transcriptRoleForMessage(event.message);
|
|
969
|
+
if (!role)
|
|
970
|
+
return;
|
|
971
|
+
if (assistantInvokesSkill(event.message))
|
|
972
|
+
skillTurnActive = true;
|
|
973
|
+
const persistedMessage = sanitizeSkillTurnMessage(event.message, skillTurnActive);
|
|
974
|
+
const uuid = randomUUID();
|
|
975
|
+
const isToolResult = role === "toolResult";
|
|
976
|
+
const toolCallId = toolCallIdForMessage(event.message);
|
|
977
|
+
await appendAgentTranscriptEvent(projectRoot, sessionId, (seq) => ({
|
|
978
|
+
type: "message",
|
|
979
|
+
version: 1,
|
|
980
|
+
sessionId,
|
|
981
|
+
requestId,
|
|
982
|
+
uuid,
|
|
983
|
+
parentUuid: isToolResult && lastAssistantUuid ? lastAssistantUuid : parentUuid,
|
|
984
|
+
seq,
|
|
985
|
+
role,
|
|
986
|
+
timestamp: messageTimestamp(event.message),
|
|
987
|
+
piTurnIndex,
|
|
988
|
+
...(toolCallId ? { toolCallId } : {}),
|
|
989
|
+
...(isToolResult && lastAssistantUuid
|
|
990
|
+
? { sourceToolAssistantUuid: lastAssistantUuid }
|
|
991
|
+
: {}),
|
|
992
|
+
message: persistedMessage,
|
|
993
|
+
}));
|
|
994
|
+
if (role === "assistant")
|
|
995
|
+
lastAssistantUuid = uuid;
|
|
996
|
+
parentUuid = uuid;
|
|
997
|
+
};
|
|
998
|
+
// ----- Subscribe to events (transcript persistence + SSE forwarding) -----
|
|
999
|
+
const unsubscribe = agent.subscribe(async (event) => {
|
|
1000
|
+
await persistAgentEvent(event);
|
|
1001
|
+
onEvent?.(event);
|
|
1002
|
+
});
|
|
1003
|
+
// ----- Execute the turn -----
|
|
1004
|
+
let finalAssistant;
|
|
1005
|
+
let errorMessage;
|
|
1006
|
+
const turnMessageStartIndex = agent.state.messages.length;
|
|
1007
|
+
try {
|
|
1008
|
+
await runWithAgentTrajectory({
|
|
1009
|
+
conversationId: opaqueConversationId(sessionId),
|
|
1010
|
+
runId: requestId,
|
|
1011
|
+
agentRole: "main",
|
|
1012
|
+
}, async () => {
|
|
1013
|
+
if (promptImages.length > 0) {
|
|
1014
|
+
await agent.prompt(promptMessage, promptImages);
|
|
1015
|
+
}
|
|
1016
|
+
else {
|
|
1017
|
+
await agent.prompt(promptMessage);
|
|
1018
|
+
}
|
|
1019
|
+
});
|
|
1020
|
+
finalAssistant = lastAssistantMessage(agent.state.messages);
|
|
1021
|
+
agent.state.messages = agent.state.messages.map((message, index) => (sanitizeSkillTurnMessage(message, skillTurnActive && index >= turnMessageStartIndex)));
|
|
1022
|
+
errorMessage = assistantErrorMessage(finalAssistant);
|
|
1023
|
+
if (errorMessage) {
|
|
1024
|
+
const failedError = errorMessage;
|
|
1025
|
+
await appendAgentTranscriptEvent(projectRoot, sessionId, (seq) => ({
|
|
1026
|
+
type: "request_failed",
|
|
1027
|
+
version: 1,
|
|
1028
|
+
sessionId,
|
|
1029
|
+
requestId,
|
|
1030
|
+
seq,
|
|
1031
|
+
timestamp: Date.now(),
|
|
1032
|
+
error: failedError,
|
|
1033
|
+
}));
|
|
1034
|
+
agentCache.delete(cacheKey);
|
|
1035
|
+
}
|
|
1036
|
+
else {
|
|
1037
|
+
const committed = await appendAgentTranscriptEvent(projectRoot, sessionId, (seq) => ({
|
|
1038
|
+
type: "request_committed",
|
|
1039
|
+
version: 1,
|
|
1040
|
+
sessionId,
|
|
1041
|
+
requestId,
|
|
1042
|
+
seq,
|
|
1043
|
+
timestamp: Date.now(),
|
|
1044
|
+
}));
|
|
1045
|
+
cached.lastCommittedSeq = committed.seq;
|
|
1046
|
+
}
|
|
1047
|
+
}
|
|
1048
|
+
catch (error) {
|
|
1049
|
+
await appendAgentTranscriptEvent(projectRoot, sessionId, (seq) => ({
|
|
1050
|
+
type: "request_failed",
|
|
1051
|
+
version: 1,
|
|
1052
|
+
sessionId,
|
|
1053
|
+
requestId,
|
|
1054
|
+
seq,
|
|
1055
|
+
timestamp: Date.now(),
|
|
1056
|
+
error: error instanceof Error ? error.message : String(error),
|
|
1057
|
+
}));
|
|
1058
|
+
agentCache.delete(cacheKey);
|
|
1059
|
+
throw error;
|
|
1060
|
+
}
|
|
1061
|
+
finally {
|
|
1062
|
+
unsubscribe();
|
|
1063
|
+
}
|
|
1064
|
+
// ----- Extract result -----
|
|
1065
|
+
const allMessages = agent.state.messages;
|
|
1066
|
+
finalAssistant ??= lastAssistantMessage(allMessages);
|
|
1067
|
+
const responseText = finalAssistant ? extractTextFromAssistant(finalAssistant) : "";
|
|
1068
|
+
errorMessage ??= assistantErrorMessage(finalAssistant);
|
|
1069
|
+
return {
|
|
1070
|
+
responseText,
|
|
1071
|
+
messages: allMessages.slice(),
|
|
1072
|
+
...(errorMessage ? { errorMessage } : {}),
|
|
1073
|
+
};
|
|
1074
|
+
}
|
|
1075
|
+
// ---------------------------------------------------------------------------
|
|
1076
|
+
// Cache management
|
|
1077
|
+
// ---------------------------------------------------------------------------
|
|
1078
|
+
/** Manually evict a cached Agent session. */
|
|
1079
|
+
export function evictAgentCache(sessionId) {
|
|
1080
|
+
let deleted = agentCache.delete(sessionId);
|
|
1081
|
+
for (const [key, entry] of agentCache) {
|
|
1082
|
+
if (entry.sessionId !== sessionId)
|
|
1083
|
+
continue;
|
|
1084
|
+
agentCache.delete(key);
|
|
1085
|
+
deleted = true;
|
|
1086
|
+
}
|
|
1087
|
+
return deleted;
|
|
1088
|
+
}
|
|
1089
|
+
/** Abort an active cached pi-agent session and evict it from cache. */
|
|
1090
|
+
export function abortAgentSession(projectRoot, sessionId) {
|
|
1091
|
+
let aborted = false;
|
|
1092
|
+
for (const [key, entry] of agentCache) {
|
|
1093
|
+
if (entry.projectRoot !== projectRoot || entry.sessionId !== sessionId)
|
|
1094
|
+
continue;
|
|
1095
|
+
entry.agent.abort();
|
|
1096
|
+
entry.agent.clearAllQueues?.();
|
|
1097
|
+
agentCache.delete(key);
|
|
1098
|
+
aborted = true;
|
|
1099
|
+
}
|
|
1100
|
+
return aborted;
|
|
1101
|
+
}
|
|
1102
|
+
//# sourceMappingURL=agent-session.js.map
|