- Add dependency-free TF-IDF retrieval (src/lib/retrieval.js) with NL+EN
stopwords and a WeakMap-cached index.
- Rewrite buildKbContext to ship the top-K relevant topics + verbatim-
mentioned ids only, filter relations to the included set, and append a
[kb_hash: <8 hex>] suffix so the ephemeral prompt cache busts when the
graph changes. Returns { context, retrievedTopics, allTopics }.
- Add LOOKUP_TOPIC_TOOL and drive useChat through callLLM directly with a
multi-hop tool_result loop capped at 3 hops; preserve Anthropic-provided
tool_use ids through callLLM so the loop can echo correct tool_use_id.
- Truncate R42 history to the last 12 turns and prepend a single
"(earlier conversation truncated)" assistant message.
- Set R42 chat defaults: temperature 0.3, maxTokens 2048.
- Add pb_migrations/1780500002_created_llm_calls.js (the best-effort
logger in callLLM was already wired) and a new Admin → Diagnostics
view showing the last 100 calls with token usage, cache-hit rate, and
USD cost from a local Anthropic price table.
- Finalize AI_PIPELINE_HARDENING_PLAN.md: mark Phases 1–5 shipped and
Phase 6 (eval harness) explicitly out of scope.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
210 lines
4.9 KiB
JavaScript
210 lines
4.9 KiB
JavaScript
/// <reference path="../pb_data/types.d.ts" />
|
|
migrate((app) => {
|
|
const collection = new Collection({
|
|
"createRule": "",
|
|
"deleteRule": "",
|
|
"fields": [
|
|
{
|
|
"autogeneratePattern": "[a-z0-9]{15}",
|
|
"help": "",
|
|
"hidden": false,
|
|
"id": "text3208210256",
|
|
"max": 15,
|
|
"min": 15,
|
|
"name": "id",
|
|
"pattern": "^[a-z0-9]+$",
|
|
"presentable": false,
|
|
"primaryKey": true,
|
|
"required": true,
|
|
"system": true,
|
|
"type": "text"
|
|
},
|
|
{
|
|
"autogeneratePattern": "",
|
|
"help": "",
|
|
"hidden": false,
|
|
"id": "text_llm_task",
|
|
"max": 0,
|
|
"min": 0,
|
|
"name": "task",
|
|
"pattern": "",
|
|
"presentable": false,
|
|
"primaryKey": false,
|
|
"required": false,
|
|
"system": false,
|
|
"type": "text"
|
|
},
|
|
{
|
|
"autogeneratePattern": "",
|
|
"help": "",
|
|
"hidden": false,
|
|
"id": "text_llm_model",
|
|
"max": 0,
|
|
"min": 0,
|
|
"name": "model",
|
|
"pattern": "",
|
|
"presentable": false,
|
|
"primaryKey": false,
|
|
"required": false,
|
|
"system": false,
|
|
"type": "text"
|
|
},
|
|
{
|
|
"autogeneratePattern": "",
|
|
"help": "",
|
|
"hidden": false,
|
|
"id": "text_llm_tier",
|
|
"max": 0,
|
|
"min": 0,
|
|
"name": "tier",
|
|
"pattern": "",
|
|
"presentable": false,
|
|
"primaryKey": false,
|
|
"required": false,
|
|
"system": false,
|
|
"type": "text"
|
|
},
|
|
{
|
|
"help": "",
|
|
"hidden": false,
|
|
"id": "number_llm_duration",
|
|
"max": null,
|
|
"min": null,
|
|
"name": "duration_ms",
|
|
"onlyInt": false,
|
|
"presentable": false,
|
|
"required": false,
|
|
"system": false,
|
|
"type": "number"
|
|
},
|
|
{
|
|
"help": "",
|
|
"hidden": false,
|
|
"id": "number_llm_input",
|
|
"max": null,
|
|
"min": null,
|
|
"name": "input_tokens",
|
|
"onlyInt": false,
|
|
"presentable": false,
|
|
"required": false,
|
|
"system": false,
|
|
"type": "number"
|
|
},
|
|
{
|
|
"help": "",
|
|
"hidden": false,
|
|
"id": "number_llm_output",
|
|
"max": null,
|
|
"min": null,
|
|
"name": "output_tokens",
|
|
"onlyInt": false,
|
|
"presentable": false,
|
|
"required": false,
|
|
"system": false,
|
|
"type": "number"
|
|
},
|
|
{
|
|
"help": "",
|
|
"hidden": false,
|
|
"id": "number_llm_cache_r",
|
|
"max": null,
|
|
"min": null,
|
|
"name": "cache_read_tokens",
|
|
"onlyInt": false,
|
|
"presentable": false,
|
|
"required": false,
|
|
"system": false,
|
|
"type": "number"
|
|
},
|
|
{
|
|
"help": "",
|
|
"hidden": false,
|
|
"id": "number_llm_cache_c",
|
|
"max": null,
|
|
"min": null,
|
|
"name": "cache_create_tokens",
|
|
"onlyInt": false,
|
|
"presentable": false,
|
|
"required": false,
|
|
"system": false,
|
|
"type": "number"
|
|
},
|
|
{
|
|
"autogeneratePattern": "",
|
|
"help": "",
|
|
"hidden": false,
|
|
"id": "text_llm_stop",
|
|
"max": 0,
|
|
"min": 0,
|
|
"name": "stop_reason",
|
|
"pattern": "",
|
|
"presentable": false,
|
|
"primaryKey": false,
|
|
"required": false,
|
|
"system": false,
|
|
"type": "text"
|
|
},
|
|
{
|
|
"hidden": false,
|
|
"id": "bool_llm_ok",
|
|
"name": "ok",
|
|
"presentable": false,
|
|
"required": false,
|
|
"system": false,
|
|
"type": "bool"
|
|
},
|
|
{
|
|
"autogeneratePattern": "",
|
|
"help": "",
|
|
"hidden": false,
|
|
"id": "text_llm_err",
|
|
"max": 0,
|
|
"min": 0,
|
|
"name": "error_msg",
|
|
"pattern": "",
|
|
"presentable": false,
|
|
"primaryKey": false,
|
|
"required": false,
|
|
"system": false,
|
|
"type": "text"
|
|
},
|
|
{
|
|
"hidden": false,
|
|
"id": "autodate_llm_created",
|
|
"name": "created",
|
|
"onCreate": true,
|
|
"onUpdate": false,
|
|
"presentable": false,
|
|
"system": false,
|
|
"type": "autodate"
|
|
},
|
|
{
|
|
"hidden": false,
|
|
"id": "autodate_llm_updated",
|
|
"name": "updated",
|
|
"onCreate": true,
|
|
"onUpdate": true,
|
|
"presentable": false,
|
|
"system": false,
|
|
"type": "autodate"
|
|
}
|
|
],
|
|
"id": "pbc_llm_calls_001",
|
|
"indexes": [
|
|
"CREATE INDEX `idx_llm_calls_created` ON `llm_calls` (`created`)",
|
|
"CREATE INDEX `idx_llm_calls_task` ON `llm_calls` (`task`)"
|
|
],
|
|
"listRule": "",
|
|
"name": "llm_calls",
|
|
"system": false,
|
|
"type": "base",
|
|
"updateRule": "",
|
|
"viewRule": ""
|
|
});
|
|
|
|
return app.save(collection);
|
|
}, (app) => {
|
|
const collection = app.findCollectionByNameOrId("pbc_llm_calls_001");
|
|
return app.delete(collection);
|
|
})
|