1e16b0d5d2
- Add packages/ai: AgentController (streaming + budget), SuggestionBuilder, NoteBuilder, AIStore (Dexie/IndexedDB), SuggestionMutation - Fix createUlid to use monotonicFactory for reliable listSessions sort tiebreaker - Extend outline system prompt with setting + characters context - Add dexie dependency to packages/ai - 188 tests passing (core 47, ui 5, editor 30, ai 71, exporters 22, web 13)
3.2 KiB
3.2 KiB
CHUNK #9 — AI Roles & Suggestions
Status: In progress. Core AI session storage layer implemented and tested.
Progress
- AI session storage layer (
packages/ai/src/)agent.ts— AgentController: streaming orchestration + token budget enforcementsuggestions.ts— SuggestionBuilder: AI suggestions across brainstorm/outline/expand/tighten/continue/research/dialogue/worldbuildingnotes.ts— NoteBuilder: note builders for writing assistanceai-session.ts— AIStore: IndexedDB session persistence via Dexie (sessions, messages, suggestions, notes)suggestion-mutation.ts— SuggestionMutation: apply/insert/replace/delete logicindex.ts— package exportsdexiedependency added topackages/ai/package.json
Bug fixes
listSessionssort tiebreaker flaky in full suite —packages/core/src/ids.tscreateUlidused the non-monotoniculidfunction, so ULIDs weren't monotonic. ThelistSessionssort uses ULID comparison as a tiebreaker whenupdatedAttimestamps are equal; non-monotonic ULIDs caused the test to pass in isolation but fail in the full suite. Fixed by switchingcreateUlidtomonotonicFactoryfrom theulidpackage.mergeNotestest used wrong note id — test usednote2.notes[0]!.id(same as note1's id) instead ofnote2.notes[1]!.id, causing the merge to combine note1 with itself. Fixed the test.outlinesystem prompt missing context — test "includes the context in the system prompt" expected the outline prompt to includesettingandcharacters, but the outline prompt only includedchapterTitleandprevious. Added setting and characters to the outline prompt.- Lint errors — removed unused imports:
createInMemoryPersistence,NoteKind,AINote,AISuggestion.
Test results
- packages/core: 47 tests
- packages/ui: 5 tests
- packages/editor: 30 tests
- packages/ai: 71 tests
- packages/exporters: 22 tests
- apps/web: 13 tests
- Total: 188 tests passing
Key facts
- Chunk #9 builds
packages/aias a self-contained SSE-based provider layer (NOT the Vercel AI SDK). The SDK moved v5→v4 and@ai-sdk/openrouterdoesn't exist (404); a hand-rolled SSE client directly exercises the real deliverable (streaming orchestration, thinking-param mapping, usage tracking, 429 retry) in the mocked integration test that is the CI gate. - The Vercel AI SDK remains the intended transport for Chunk #11 (tools).
packages/core/src/tokens.tsprovidescountTokens/allocateBudget/DEFAULT_BUDGET(re-exported bypackages/ai/budget.ts).packages/aire-exports core's token-budget types asBudget(NOTTokenBudget).packages/aiuses Dexie for IndexedDB AI session persistence, coordinatingAIStore,SuggestionBuilder,NoteBuilder, andAgentController.
Remaining (per CHUNK#9.md)
- Base role prompts (
packages/ai/src/roles/): editor/reader/publisher/co-author - Context builder (
packages/ai/src/context.ts) - Tools (
packages/ai/src/tools/): applySuggestion, updateEntity, addNote, draftChapter, queryProject - Suggestion protocol: structured output + inline rendering in editor decorations
- Session UI (
apps/web/src/features/ai/): AiPanel, AiSessionsView, feedback loop