Lucas 'Paperboy' Rose-Winters
|
b00bae905f
|
feat(inventory): add v2 parsing and generation support
Add full AI integration for inventory v2 format:
**Parsing (NEW: inventoryParser.js, 125 lines):**
- extractInventoryData() - Parse multi-line v2 format from AI responses
- Extracts "On Person: ..." section
- Extracts multiple "Stored - [Location]: ..." sections
- Extracts "Assets: ..." section
- Returns InventoryV2 object
- extractLegacyInventory() - Fallback parser for old v1 format
- extractInventory() - Main function that tries v2 first, falls back to v1
**Parsing Integration (parser.js):**
- Import extractInventory() from inventoryParser
- Replace old single-line regex with v2-aware extraction
- Use feature flag to switch between v1/v2 parsing modes
- Maintains backward compatibility with FEATURE_FLAGS.useNewInventory
**Generation (promptBuilder.js, 60 lines changed):**
- NEW: buildInventorySummary() - Converts v2 object to multi-line text
- Formats "On Person: ..." line
- Formats multiple "Stored - [Location]: ..." lines
- Formats "Assets: ..." line
- Handles legacy v1 string format for backward compat
- Update generateTrackerInstructions() with v2 format spec:
- Shows AI how to format inventory in multi-line v2 structure
- Includes note about multiple storage locations
- Falls back to v1 format when feature flag disabled
- Update generateContextualSummary() to use buildInventorySummary()
- Converts v2 inventory to readable context for separate mode
**Format Examples:**
AI Output (v2 format):
```
On Person: Sword (equipped), 3x Health Potions, Leather Armor
Stored - Home: Spare clothes, Tools, 50 gold coins
Stored - Bank: Family heirloom, Important documents
Assets: Motorcycle (garage), Downtown apartment (owned)
```
Parsed Result:
```js
{
version: 2,
onPerson: "Sword (equipped), 3x Health Potions, Leather Armor",
stored: {
"Home": "Spare clothes, Tools, 50 gold coins",
"Bank": "Family heirloom, Important documents"
},
assets: "Motorcycle (garage), Downtown apartment (owned)"
}
```
Changes:
- NEW: src/systems/generation/inventoryParser.js (125 lines)
- MODIFIED: src/systems/generation/parser.js (+14 lines)
- MODIFIED: src/systems/generation/promptBuilder.js (+60 lines)
Part of inventory system v2 implementation
Dependencies: v2 types, migration utility, persistence integration
|
2025-10-17 15:10:31 +11:00 |
|