@aglyn/plugins-ai 1.2.0 → 1.4.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/package.json +17 -17
- package/src/lib/components/ai-insight-dialog.component.js +7 -2
- package/src/lib/components/ai-insight-dialog.component.js.map +1 -1
- package/src/lib/components/ai-job-request.component.d.ts +28 -0
- package/src/lib/components/ai-job-request.component.js +103 -0
- package/src/lib/components/ai-job-request.component.js.map +1 -0
- package/src/lib/components/ai-jobs-list-page.component.d.ts +2 -0
- package/src/lib/components/ai-jobs-list-page.component.js +2 -2
- package/src/lib/components/ai-jobs-list-page.component.js.map +1 -1
- package/src/lib/components/ai-site-build-page.component.js +36 -6
- package/src/lib/components/ai-site-build-page.component.js.map +1 -1
- package/src/lib/components/ai-site-import-job.component.js +2 -2
- package/src/lib/components/ai-site-import-job.component.js.map +1 -1
- package/src/lib/insights/ai-insight-digest.d.ts +34 -5
- package/src/lib/insights/ai-insight-digest.js +171 -10
- package/src/lib/insights/ai-insight-digest.js.map +1 -1
- package/src/lib/jobs/ai-job-import-step.d.ts +35 -2
- package/src/lib/jobs/ai-job-import-step.js +124 -12
- package/src/lib/jobs/ai-job-import-step.js.map +1 -1
- package/src/lib/jobs/ai-job-insight-step.d.ts +1 -1
- package/src/lib/jobs/ai-job-insight-step.js +5 -1
- package/src/lib/jobs/ai-job-insight-step.js.map +1 -1
- package/src/lib/jobs/ai-jobs.d.ts +6 -0
- package/src/lib/jobs/ai-jobs.js +43 -6
- package/src/lib/jobs/ai-jobs.js.map +1 -1
- package/src/lib/jobs/ai-layout-stock-photos.d.ts +13 -6
- package/src/lib/jobs/ai-layout-stock-photos.js +104 -32
- package/src/lib/jobs/ai-layout-stock-photos.js.map +1 -1
- package/src/lib/jobs/ai-site-import-compile.js +110 -23
- package/src/lib/jobs/ai-site-import-compile.js.map +1 -1
- package/src/lib/jobs/ai-site-import-document.d.ts +5 -0
- package/src/lib/jobs/ai-site-import-document.js.map +1 -1
- package/src/lib/jobs/ai-site-import-forms.d.ts +83 -0
- package/src/lib/jobs/ai-site-import-forms.js +376 -0
- package/src/lib/jobs/ai-site-import-forms.js.map +1 -0
- package/src/lib/jobs/fixtures/ai-stock-photo-agl4092-1101-recordings.d.ts +21 -0
- package/src/lib/jobs/fixtures/ai-stock-photo-agl4092-1101-recordings.js +77 -0
- package/src/lib/jobs/fixtures/ai-stock-photo-agl4092-1101-recordings.js.map +1 -0
- package/src/lib/layout-language/ai-layout-compiler.d.ts +2 -0
- package/src/lib/layout-language/ai-layout-compiler.js +215 -30
- package/src/lib/layout-language/ai-layout-compiler.js.map +1 -1
- package/src/lib/layout-language/ai-layout-language.d.ts +12 -0
- package/src/lib/layout-language/ai-layout-language.js.map +1 -1
- package/src/lib/model/ai-credit-estimate.d.ts +25 -22
- package/src/lib/model/ai-credit-estimate.js +24 -22
- package/src/lib/model/ai-credit-estimate.js.map +1 -1
- package/src/lib/model/ai-insight.d.ts +4 -0
- package/src/lib/model/ai-insight.js +1 -0
- package/src/lib/model/ai-insight.js.map +1 -1
- package/src/lib/model/ai-site-build-progress.d.ts +8 -0
- package/src/lib/model/ai-site-build-progress.js +62 -1
- package/src/lib/model/ai-site-build-progress.js.map +1 -1
- package/src/lib/model/ai-site-import-fidelity.d.ts +2 -0
- package/src/lib/model/ai-site-import-fidelity.js +41 -5
- package/src/lib/model/ai-site-import-fidelity.js.map +1 -1
- package/src/lib/model/ai-site-import-report.d.ts +60 -0
- package/src/lib/model/ai-site-import-report.js +116 -0
- package/src/lib/model/ai-site-import-report.js.map +1 -0
- package/src/lib/model/ai-site-import-view.d.ts +7 -1
- package/src/lib/model/ai-site-import-view.js +14 -2
- package/src/lib/model/ai-site-import-view.js.map +1 -1
- package/src/lib/model/ai-site-import.d.ts +49 -2
- package/src/lib/model/ai-site-import.js +81 -23
- package/src/lib/model/ai-site-import.js.map +1 -1
- package/src/lib/plugin.js +1 -1
- package/src/lib/plugin.js.map +1 -1
- package/src/lib/runtime/ai-insight-check.js +22 -6
- package/src/lib/runtime/ai-insight-check.js.map +1 -1
- package/src/lib/server/ai-insight-digest-route.js +3 -1
- package/src/lib/server/ai-insight-digest-route.js.map +1 -1
- package/src/lib/site-import/fixtures/site-layout-recordings.d.ts +4 -0
- package/src/lib/site-import/fixtures/site-layout-recordings.js +9 -4
- package/src/lib/site-import/fixtures/site-layout-recordings.js.map +1 -1
- package/src/lib/site-import/site-import-css.d.ts +10 -1
- package/src/lib/site-import/site-import-css.js +19 -12
- package/src/lib/site-import/site-import-css.js.map +1 -1
- package/src/lib/site-import/site-import-html.d.ts +17 -4
- package/src/lib/site-import/site-import-html.js +146 -17
- package/src/lib/site-import/site-import-html.js.map +1 -1
- package/src/lib/site-import/site-import-layout.js +194 -32
- package/src/lib/site-import/site-import-layout.js.map +1 -1
- package/src/lib/tools/ai-insight-tool.js +11 -3
- package/src/lib/tools/ai-insight-tool.js.map +1 -1
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { _ as _extends } from "@swc/helpers/_/_extends";
|
|
1
2
|
/**
|
|
2
3
|
* @license
|
|
3
4
|
* Copyright 2026 Aglyn LLC
|
|
@@ -13,7 +14,7 @@
|
|
|
13
14
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
15
|
* See the License for the specific language governing permissions and
|
|
15
16
|
* limitations under the License.
|
|
16
|
-
*/ import { AI_INSIGHT_GAP_MAX_CHARS, AI_INSIGHT_MAX_CHARS, AI_INSIGHT_MAX_CITED_ROWS, AI_INSIGHT_MAX_CITES, AI_INSIGHT_MAX_INSIGHTS, AI_INSIGHT_MAX_READS } from "../model/ai-insight.js";
|
|
17
|
+
*/ import { AI_INSIGHT_GAP_MAX_CHARS, AI_INSIGHT_HEADLINE_MAX_CHARS, AI_INSIGHT_MAX_CHARS, AI_INSIGHT_MAX_CITED_ROWS, AI_INSIGHT_MAX_CITES, AI_INSIGHT_MAX_INSIGHTS, AI_INSIGHT_MAX_READS } from "../model/ai-insight.js";
|
|
17
18
|
/**
|
|
18
19
|
* The two strict tools an insight job answers through (AGL-2915).
|
|
19
20
|
*
|
|
@@ -98,9 +99,13 @@ export function aiInsightAnswerTool() {
|
|
|
98
99
|
items: {
|
|
99
100
|
type: 'object',
|
|
100
101
|
properties: {
|
|
102
|
+
headline: {
|
|
103
|
+
type: 'string',
|
|
104
|
+
description: `What happened, in a few words, with no full stop; at most ${AI_INSIGHT_HEADLINE_MAX_CHARS} characters.`
|
|
105
|
+
},
|
|
101
106
|
text: {
|
|
102
107
|
type: 'string',
|
|
103
|
-
description: `
|
|
108
|
+
description: `Why it matters, in one or two plain sentences that do not repeat the headline; at most ${AI_INSIGHT_MAX_CHARS} characters.`
|
|
104
109
|
},
|
|
105
110
|
cites: {
|
|
106
111
|
type: 'array',
|
|
@@ -129,6 +134,7 @@ export function aiInsightAnswerTool() {
|
|
|
129
134
|
}
|
|
130
135
|
},
|
|
131
136
|
required: [
|
|
137
|
+
'headline',
|
|
132
138
|
'text',
|
|
133
139
|
'cites'
|
|
134
140
|
],
|
|
@@ -183,7 +189,9 @@ const isRecord = (value)=>typeof value === 'object' && value !== null && !Array.
|
|
|
183
189
|
* — not this reader — decides what an unreadable citation costs.
|
|
184
190
|
*/ export function parseAiInsightAnswer(input) {
|
|
185
191
|
if (!isRecord(input) || !Array.isArray(input['insights'])) return null;
|
|
186
|
-
const insights = input['insights'].filter(isRecord).map((raw)=>({
|
|
192
|
+
const insights = input['insights'].filter(isRecord).map((raw)=>_extends({}, typeof raw['headline'] === 'string' ? {
|
|
193
|
+
headline: raw['headline']
|
|
194
|
+
} : {}, {
|
|
187
195
|
text: typeof raw['text'] === 'string' ? raw['text'] : '',
|
|
188
196
|
cites: (Array.isArray(raw['cites']) ? raw['cites'] : []).filter(isRecord).map((cite)=>({
|
|
189
197
|
table: typeof cite['table'] === 'string' ? cite['table'] : '',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../libs/plugins/ai/src/lib/tools/ai-insight-tool.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n AI_INSIGHT_GAP_MAX_CHARS,\n AI_INSIGHT_MAX_CHARS,\n AI_INSIGHT_MAX_CITED_ROWS,\n AI_INSIGHT_MAX_CITES,\n AI_INSIGHT_MAX_INSIGHTS,\n AI_INSIGHT_MAX_READS,\n type AiInsightAnswer,\n} from '../model/ai-insight'\nimport type { AiTool } from '../providers/contract'\n\n/**\n * The two strict tools an insight job answers through (AGL-2915).\n *\n * `read_figures` names readers — an id, a window and the reader's own\n * parameters — and nothing else: the model never writes a query, a field\n * path or a filter of its own, only a choice among the readers the request\n * lists. `submit_insights` is the answer, each insight citing the table rows\n * its figures come from. Lengths and counts are stated in the descriptions,\n * as the platform's other strict tools state them; the step holds every one.\n */\n\nexport const AI_INSIGHT_READ_TOOL_NAME = 'read_figures'\nexport const AI_INSIGHT_ANSWER_TOOL_NAME = 'submit_insights'\n\nexport function aiInsightReadTool(): AiTool {\n return {\n name: AI_INSIGHT_READ_TOOL_NAME,\n description:\n `Choose the readers whose tables answer the question: at most ${AI_INSIGHT_MAX_READS}, ` +\n 'each from the list the request gives. Every field is required.',\n strict: true,\n inputSchema: {\n type: 'object',\n properties: {\n reads: {\n type: 'array',\n description: `The readers to read, most useful first; at most ${AI_INSIGHT_MAX_READS}.`,\n items: {\n type: 'object',\n properties: {\n reader: { type: 'string', description: 'A reader id from the list, exactly as written.' },\n days: {\n type: 'integer',\n description: 'One of the windows that reader lists, in days; 0 for a reader that lists none.',\n },\n params: {\n type: 'array',\n description: 'The parameters that reader lists, by name; empty when it lists none.',\n items: {\n type: 'object',\n properties: {\n name: { type: 'string' },\n value: { type: 'string' },\n },\n required: ['name', 'value'],\n additionalProperties: false,\n },\n },\n },\n required: ['reader', 'days', 'params'],\n additionalProperties: false,\n },\n },\n },\n required: ['reads'],\n additionalProperties: false,\n },\n }\n}\n\nexport function aiInsightAnswerTool(): AiTool {\n return {\n name: AI_INSIGHT_ANSWER_TOOL_NAME,\n description:\n `Answer with at most ${AI_INSIGHT_MAX_INSIGHTS} insights, each citing the table rows its figures come from. ` +\n 'Every field is required.',\n strict: true,\n inputSchema: {\n type: 'object',\n properties: {\n insights: {\n type: 'array',\n description: `Most useful first; at most ${AI_INSIGHT_MAX_INSIGHTS}.`,\n items: {\n type: 'object',\n properties: {\n text: {\n type: 'string',\n description: `One or two plain sentences; at most ${AI_INSIGHT_MAX_CHARS} characters.`,\n },\n cites: {\n type: 'array',\n description: `The tables and rows its figures come from; at most ${AI_INSIGHT_MAX_CITES} tables.`,\n items: {\n type: 'object',\n properties: {\n table: { type: 'string', description: 'The table handle: t1, t2, …' },\n rows: {\n type: 'array',\n description: `Row numbers as the table numbers them, from 0; at most ${AI_INSIGHT_MAX_CITED_ROWS}.`,\n items: { type: 'integer' },\n },\n },\n required: ['table', 'rows'],\n additionalProperties: false,\n },\n },\n },\n required: ['text', 'cites'],\n additionalProperties: false,\n },\n },\n gap: {\n anyOf: [{ type: 'string' }, { type: 'null' }],\n description: `What the tables cannot answer, in one sentence without numbers; at most ${AI_INSIGHT_GAP_MAX_CHARS} characters. null when nothing.`,\n },\n },\n required: ['insights', 'gap'],\n additionalProperties: false,\n },\n }\n}\n\n/** One reader the model asked for, as it asked. */\nexport interface AiInsightReadRequest {\n reader: string\n days: number\n params: Record<string, string>\n}\n\nconst isRecord = (value: unknown): value is Record<string, unknown> =>\n typeof value === 'object' && value !== null && !Array.isArray(value)\n\n/** The reads a `read_figures` call names, shape-checked and bounded; the step decides which are real. */\nexport function parseAiInsightReads(input: unknown): AiInsightReadRequest[] {\n const reads = isRecord(input) && Array.isArray(input['reads']) ? input['reads'] : []\n const parsed: AiInsightReadRequest[] = []\n for (const raw of reads) {\n if (parsed.length === AI_INSIGHT_MAX_READS) break\n if (!isRecord(raw) || typeof raw['reader'] !== 'string') continue\n const params: Record<string, string> = {}\n for (const pair of Array.isArray(raw['params']) ? raw['params'] : []) {\n if (isRecord(pair) && typeof pair['name'] === 'string' && typeof pair['value'] === 'string') {\n params[pair['name']] = pair['value']\n }\n }\n const days = Number(raw['days'])\n parsed.push({\n reader: raw['reader'].trim(),\n days: Number.isInteger(days) && days >= 0 ? days : 0,\n params,\n })\n }\n return parsed\n}\n\n/**\n * A `submit_insights` call as the trace reads it, or `null` when the call is\n * not an answer at all. Values keep the types the model wrote, so the trace\n * — not this reader — decides what an unreadable citation costs.\n */\nexport function parseAiInsightAnswer(input: unknown): AiInsightAnswer | null {\n if (!isRecord(input) || !Array.isArray(input['insights'])) return null\n const insights = input['insights']\n .filter(isRecord)\n .map((raw) => ({\n text: typeof raw['text'] === 'string' ? raw['text'] : '',\n cites: (Array.isArray(raw['cites']) ? raw['cites'] : []).filter(isRecord).map((cite) => ({\n table: typeof cite['table'] === 'string' ? cite['table'] : '',\n rows: (Array.isArray(cite['rows']) ? cite['rows'] : []) as number[],\n })),\n }))\n const gap = typeof input['gap'] === 'string' ? input['gap'] : null\n return { insights, gap }\n}\n"],"names":["AI_INSIGHT_GAP_MAX_CHARS","AI_INSIGHT_MAX_CHARS","AI_INSIGHT_MAX_CITED_ROWS","AI_INSIGHT_MAX_CITES","AI_INSIGHT_MAX_INSIGHTS","AI_INSIGHT_MAX_READS","AI_INSIGHT_READ_TOOL_NAME","AI_INSIGHT_ANSWER_TOOL_NAME","aiInsightReadTool","name","description","strict","inputSchema","type","properties","reads","items","reader","days","params","value","required","additionalProperties","aiInsightAnswerTool","insights","text","cites","table","rows","gap","anyOf","isRecord","Array","isArray","parseAiInsightReads","input","parsed","raw","length","pair","Number","push","trim","isInteger","parseAiInsightAnswer","filter","map","cite"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED,SACEA,wBAAwB,EACxBC,oBAAoB,EACpBC,yBAAyB,EACzBC,oBAAoB,EACpBC,uBAAuB,EACvBC,oBAAoB,QAEf,yBAAqB;AAG5B;;;;;;;;;CASC,GAED,OAAO,MAAMC,4BAA4B,eAAc;AACvD,OAAO,MAAMC,8BAA8B,kBAAiB;AAE5D,OAAO,SAASC;IACd,OAAO;QACLC,MAAMH;QACNI,aACE,CAAC,6DAA6D,EAAEL,qBAAqB,EAAE,CAAC,GACxF;QACFM,QAAQ;QACRC,aAAa;YACXC,MAAM;YACNC,YAAY;gBACVC,OAAO;oBACLF,MAAM;oBACNH,aAAa,CAAC,gDAAgD,EAAEL,qBAAqB,CAAC,CAAC;oBACvFW,OAAO;wBACLH,MAAM;wBACNC,YAAY;4BACVG,QAAQ;gCAAEJ,MAAM;gCAAUH,aAAa;4BAAiD;4BACxFQ,MAAM;gCACJL,MAAM;gCACNH,aAAa;4BACf;4BACAS,QAAQ;gCACNN,MAAM;gCACNH,aAAa;gCACbM,OAAO;oCACLH,MAAM;oCACNC,YAAY;wCACVL,MAAM;4CAAEI,MAAM;wCAAS;wCACvBO,OAAO;4CAAEP,MAAM;wCAAS;oCAC1B;oCACAQ,UAAU;wCAAC;wCAAQ;qCAAQ;oCAC3BC,sBAAsB;gCACxB;4BACF;wBACF;wBACAD,UAAU;4BAAC;4BAAU;4BAAQ;yBAAS;wBACtCC,sBAAsB;oBACxB;gBACF;YACF;YACAD,UAAU;gBAAC;aAAQ;YACnBC,sBAAsB;QACxB;IACF;AACF;AAEA,OAAO,SAASC;IACd,OAAO;QACLd,MAAMF;QACNG,aACE,CAAC,oBAAoB,EAAEN,wBAAwB,6DAA6D,CAAC,GAC7G;QACFO,QAAQ;QACRC,aAAa;YACXC,MAAM;YACNC,YAAY;gBACVU,UAAU;oBACRX,MAAM;oBACNH,aAAa,C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AAG,EAAE;gBACxD,CAAA;QACF,CAAA;IACF,MAAMlB,MAAM,OAAOM,KAAK,CAAC,MAAM,KAAK,WAAWA,KAAK,CAAC,MAAM,GAAG;IAC9D,OAAO;QAAEX;QAAUK;IAAI;AACzB"}
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/plugins/ai/src/lib/tools/ai-insight-tool.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n AI_INSIGHT_GAP_MAX_CHARS,\n AI_INSIGHT_HEADLINE_MAX_CHARS,\n AI_INSIGHT_MAX_CHARS,\n AI_INSIGHT_MAX_CITED_ROWS,\n AI_INSIGHT_MAX_CITES,\n AI_INSIGHT_MAX_INSIGHTS,\n AI_INSIGHT_MAX_READS,\n type AiInsightAnswer,\n} from '../model/ai-insight'\nimport type { AiTool } from '../providers/contract'\n\n/**\n * The two strict tools an insight job answers through (AGL-2915).\n *\n * `read_figures` names readers — an id, a window and the reader's own\n * parameters — and nothing else: the model never writes a query, a field\n * path or a filter of its own, only a choice among the readers the request\n * lists. `submit_insights` is the answer, each insight citing the table rows\n * its figures come from. Lengths and counts are stated in the descriptions,\n * as the platform's other strict tools state them; the step holds every one.\n */\n\nexport const AI_INSIGHT_READ_TOOL_NAME = 'read_figures'\nexport const AI_INSIGHT_ANSWER_TOOL_NAME = 'submit_insights'\n\nexport function aiInsightReadTool(): AiTool {\n return {\n name: AI_INSIGHT_READ_TOOL_NAME,\n description:\n `Choose the readers whose tables answer the question: at most ${AI_INSIGHT_MAX_READS}, ` +\n 'each from the list the request gives. Every field is required.',\n strict: true,\n inputSchema: {\n type: 'object',\n properties: {\n reads: {\n type: 'array',\n description: `The readers to read, most useful first; at most ${AI_INSIGHT_MAX_READS}.`,\n items: {\n type: 'object',\n properties: {\n reader: { type: 'string', description: 'A reader id from the list, exactly as written.' },\n days: {\n type: 'integer',\n description: 'One of the windows that reader lists, in days; 0 for a reader that lists none.',\n },\n params: {\n type: 'array',\n description: 'The parameters that reader lists, by name; empty when it lists none.',\n items: {\n type: 'object',\n properties: {\n name: { type: 'string' },\n value: { type: 'string' },\n },\n required: ['name', 'value'],\n additionalProperties: false,\n },\n },\n },\n required: ['reader', 'days', 'params'],\n additionalProperties: false,\n },\n },\n },\n required: ['reads'],\n additionalProperties: false,\n },\n }\n}\n\nexport function aiInsightAnswerTool(): AiTool {\n return {\n name: AI_INSIGHT_ANSWER_TOOL_NAME,\n description:\n `Answer with at most ${AI_INSIGHT_MAX_INSIGHTS} insights, each citing the table rows its figures come from. ` +\n 'Every field is required.',\n strict: true,\n inputSchema: {\n type: 'object',\n properties: {\n insights: {\n type: 'array',\n description: `Most useful first; at most ${AI_INSIGHT_MAX_INSIGHTS}.`,\n items: {\n type: 'object',\n properties: {\n headline: {\n type: 'string',\n description: `What happened, in a few words, with no full stop; at most ${AI_INSIGHT_HEADLINE_MAX_CHARS} characters.`,\n },\n text: {\n type: 'string',\n description: `Why it matters, in one or two plain sentences that do not repeat the headline; at most ${AI_INSIGHT_MAX_CHARS} characters.`,\n },\n cites: {\n type: 'array',\n description: `The tables and rows its figures come from; at most ${AI_INSIGHT_MAX_CITES} tables.`,\n items: {\n type: 'object',\n properties: {\n table: { type: 'string', description: 'The table handle: t1, t2, …' },\n rows: {\n type: 'array',\n description: `Row numbers as the table numbers them, from 0; at most ${AI_INSIGHT_MAX_CITED_ROWS}.`,\n items: { type: 'integer' },\n },\n },\n required: ['table', 'rows'],\n additionalProperties: false,\n },\n },\n },\n required: ['headline', 'text', 'cites'],\n additionalProperties: false,\n },\n },\n gap: {\n anyOf: [{ type: 'string' }, { type: 'null' }],\n description: `What the tables cannot answer, in one sentence without numbers; at most ${AI_INSIGHT_GAP_MAX_CHARS} characters. null when nothing.`,\n },\n },\n required: ['insights', 'gap'],\n additionalProperties: false,\n },\n }\n}\n\n/** One reader the model asked for, as it asked. */\nexport interface AiInsightReadRequest {\n reader: string\n days: number\n params: Record<string, string>\n}\n\nconst isRecord = (value: unknown): value is Record<string, unknown> =>\n typeof value === 'object' && value !== null && !Array.isArray(value)\n\n/** The reads a `read_figures` call names, shape-checked and bounded; the step decides which are real. */\nexport function parseAiInsightReads(input: unknown): AiInsightReadRequest[] {\n const reads = isRecord(input) && Array.isArray(input['reads']) ? input['reads'] : []\n const parsed: AiInsightReadRequest[] = []\n for (const raw of reads) {\n if (parsed.length === AI_INSIGHT_MAX_READS) break\n if (!isRecord(raw) || typeof raw['reader'] !== 'string') continue\n const params: Record<string, string> = {}\n for (const pair of Array.isArray(raw['params']) ? raw['params'] : []) {\n if (isRecord(pair) && typeof pair['name'] === 'string' && typeof pair['value'] === 'string') {\n params[pair['name']] = pair['value']\n }\n }\n const days = Number(raw['days'])\n parsed.push({\n reader: raw['reader'].trim(),\n days: Number.isInteger(days) && days >= 0 ? days : 0,\n params,\n })\n }\n return parsed\n}\n\n/**\n * A `submit_insights` call as the trace reads it, or `null` when the call is\n * not an answer at all. Values keep the types the model wrote, so the trace\n * — not this reader — decides what an unreadable citation costs.\n */\nexport function parseAiInsightAnswer(input: unknown): AiInsightAnswer | null {\n if (!isRecord(input) || !Array.isArray(input['insights'])) return null\n const insights = input['insights']\n .filter(isRecord)\n .map((raw) => ({\n ...(typeof raw['headline'] === 'string' ? { headline: raw['headline'] } : {}),\n text: typeof raw['text'] === 'string' ? raw['text'] : '',\n cites: (Array.isArray(raw['cites']) ? raw['cites'] : []).filter(isRecord).map((cite) => ({\n table: typeof cite['table'] === 'string' ? cite['table'] : '',\n rows: (Array.isArray(cite['rows']) ? cite['rows'] : []) as number[],\n })),\n }))\n const gap = typeof input['gap'] === 'string' ? input['gap'] : null\n return { insights, gap }\n}\n"],"names":["AI_INSIGHT_GAP_MAX_CHARS","AI_INSIGHT_HEADLINE_MAX_CHARS","AI_INSIGHT_MAX_CHARS","AI_INSIGHT_MAX_CITED_ROWS","AI_INSIGHT_MAX_CITES","AI_INSIGHT_MAX_INSIGHTS","AI_INSIGHT_MAX_READS","AI_INSIGHT_READ_TOOL_NAME","AI_INSIGHT_ANSWER_TOOL_NAME","aiInsightReadTool","name","description","strict","inputSchema","type","properties","reads","items","reader","days","params","value","required","additionalProperties","aiInsightAnswerTool","insights","headline","text","cites","table","rows","gap","anyOf","isRecord","Array","isArray","parseAiInsightReads","input","parsed","raw","length","pair","Number","push","trim","isInteger","parseAiInsightAnswer","filter","map","cite"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED,SACEA,wBAAwB,EACxBC,6BAA6B,EAC7BC,oBAAoB,EACpBC,yBAAyB,EACzBC,oBAAoB,EACpBC,uBAAuB,EACvBC,oBAAoB,QAEf,yBAAqB;AAG5B;;;;;;;;;CASC,GAED,OAAO,MAAMC,4BAA4B,eAAc;AACvD,OAAO,MAAMC,8BAA8B,kBAAiB;AAE5D,OAAO,SAASC;IACd,OAAO;QACLC,MAAMH;QACNI,aACE,CAAC,6DAA6D,EAAEL,qBAAqB,EAAE,CAAC,GACxF;QACFM,QAAQ;QACRC,aAAa;YACXC,MAAM;YACNC,YAAY;gBACVC,OAAO;oBACLF,MAAM;oBACNH,aAAa,CAAC,gDAAgD,EAAEL,qBAAqB,CAAC,CAAC;oBACvFW,OAAO;wBACLH,MAAM;wBACNC,YAAY;4BACVG,QAAQ;gCAAEJ,MAAM;gCAAUH,aAAa;4BAAiD;4BACxFQ,MAAM;gCACJL,MAAM;gCACNH,aAAa;4BACf;4BACAS,QAAQ;gCACNN,MAAM;gCACNH,aAAa;gCACbM,OAAO;oCACLH,MAAM;oCACNC,YAAY;wCACVL,MAAM;4CAAEI,MAAM;wCAAS;wCACv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