@things-factory/ai-assistant 10.1.91 → 10.1.97
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/client/components/assistant-chat.ts +5 -3
- package/client/components/entry-review.ts +56 -0
- package/client/utils/entry-proposal.ts +20 -5
- package/dist-client/components/assistant-chat.js +5 -3
- package/dist-client/components/assistant-chat.js.map +1 -1
- package/dist-client/components/entry-review.d.ts +5 -0
- package/dist-client/components/entry-review.js +55 -0
- package/dist-client/components/entry-review.js.map +1 -1
- package/dist-client/tsconfig.tsbuildinfo +1 -1
- package/dist-client/utils/entry-proposal.d.ts +5 -0
- package/dist-client/utils/entry-proposal.js +16 -5
- package/dist-client/utils/entry-proposal.js.map +1 -1
- package/dist-server/service/data-entry/entry-apply.d.ts +3 -3
- package/dist-server/service/data-entry/entry-apply.js +55 -2
- package/dist-server/service/data-entry/entry-apply.js.map +1 -1
- package/dist-server/service/data-entry/entry-resolver.js +3 -7
- package/dist-server/service/data-entry/entry-resolver.js.map +1 -1
- package/dist-server/service/data-entry/entry-target.d.ts +51 -0
- package/dist-server/service/data-entry/entry-target.js +77 -34
- package/dist-server/service/data-entry/entry-target.js.map +1 -1
- package/dist-server/service/data-entry/entry-tools.d.ts +7 -1
- package/dist-server/service/data-entry/entry-tools.js +73 -3
- package/dist-server/service/data-entry/entry-tools.js.map +1 -1
- package/dist-server/service/data-entry/entry-update.d.ts +99 -0
- package/dist-server/service/data-entry/entry-update.js +196 -0
- package/dist-server/service/data-entry/entry-update.js.map +1 -0
- package/dist-server/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/server/service/data-entry/data-entry-update.test.ts +192 -0
- package/server/service/data-entry/entry-apply.ts +63 -6
- package/server/service/data-entry/entry-resolver.ts +4 -9
- package/server/service/data-entry/entry-target.ts +97 -31
- package/server/service/data-entry/entry-tools.ts +77 -3
- package/server/service/data-entry/entry-update.ts +209 -0
- package/test/entry-proposal.test.ts +15 -2
- package/translations/en.json +16 -1
- package/translations/ja.json +16 -1
- package/translations/ko.json +16 -1
- package/translations/ms.json +16 -1
- package/translations/zh.json +16 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entry-target.js","sourceRoot":"","sources":["../../../server/service/data-entry/entry-target.ts"],"names":[],"mappings":";;;AA6HA,kCAOC;AAGD,4CAOC;AASD,gDAiBC;AAED,sCAEC;AAED,oCAEC;AAGD,8CAEC;AAGD,sCAOC;AAED,8CAEC;AAuCD,gDAqEC;AAGD,8CAGC;AAED,8BAEC;AAcD,oCAwBC;AAMD,0BAcC;AAMD,4DA4BC;AAeD,kCAoBC;AAxbD;;;;;;;;;;;;;GAaG;AACH,qCAA+B;AA2G/B;;;GAGG;AACH,SAAgB,WAAW,CAAC,QAAgB;IAC1C,MAAM,GAAG,GAAG,IAAA,eAAK,EAAC,QAAQ,CAAC,CAAA;IAC3B,MAAM,UAAU,GAAG,GAAG,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,GAAQ,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,KAAK,qBAAqB,CAAU,CAAA;IACpG,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC,IAAI,UAAU,CAAC,CAAC,CAAC,CAAC,SAAS,KAAK,UAAU;QAAE,MAAM,IAAI,KAAK,CAAC,qBAAqB,CAAC,CAAA;IAC7G,MAAM,MAAM,GAAG,UAAU,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,GAAQ,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,KAAK,OAAO,CAAC,CAAA;IAC/F,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,kCAAkC,CAAC,CAAA;IAC5E,OAAO,YAAY,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,CAAA;AAC3C,CAAC;AAED,yEAAyE;AAClE,KAAK,UAAU,gBAAgB,CAAC,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,CAAC,EAAE,CAAC,CAAC,GAAG,GAAG,CAAC,GAAG,GAAG,CAAA;QACnL,MAAM,KAAK,GAAe,EAAE,KAAK,EAAE,KAAK,CAAC,IAAI,EAAE,GAAG,EAAE,GAAG,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAA;QAChH,MAAM,KAAK,GAAG,QAAQ,IAAI,CAAC,QAAQ,CAAC,KAAK,IAAI,KAAK,CAAC,IAAI,CAAC,KAAK,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAA;QAC9G,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;YACxB,KAAK,CAAC,QAAQ,GAAG,KAAK,CAAA;YACtB,KAAK,CAAC,UAAU,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,KAAK,GAAG,KAAK,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC,GAAG,GAAG,CAAA;YAC9D,MAAM,IAAI,GAAG,QAAS,CAAC,YAAY,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,QAAS,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,SAAS,CAAA;YACnF,IAAI,IAAI,KAAK,SAAS;gBAAE,KAAK,CAAC,aAAa,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,OAAO,CAAC,IAAI,EAAE,YAAY,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC,CAAA;QAChI,CAAC;QACD,OAAO,KAAK,CAAA;IACd,CAAC,CAAC,CAAA;AACN,CAAC","sourcesContent":["/*\n * Data entry from material - what an application declares so the assistant can enter its records\n * (operato-application/design/ai/data-entry.md).\n *\n * A person hands the conversation what the records are made of - a bank export, a photo of a receipt,\n * lines pasted from a mail - and the assistant turns it into rows of one of the application's records.\n * Nothing is written by the model. It proposes the rows; the card shows them with what was wrong in\n * each and where each came from; a correction is said in the conversation and the model proposes again;\n * the person presses the button; the server enters each row **through the application's own GraphQL\n * mutation**, run with the person's request state - the same door, directives and checks as entering by hand.\n * There is no second way into the record.\n *\n * This file is pure - no framework, no database - so the rules a row passes are tested without a server.\n */\nimport { parse } from 'graphql'\n\nexport type EntryFieldType = 'string' | 'text' | 'number' | 'integer' | 'date' | 'boolean' | 'enum'\n\nexport interface EntryField {\n name: string\n type: EntryFieldType\n required?: boolean\n /** The allowed values of an `enum` field. */\n values?: string[]\n /** What the model reads about the field - English, like every tool description. */\n description?: string\n /** i18n key of the column heading on the card. Absent: the field name. */\n labelKey?: string\n /** A number field the card sums - and compares with the total the material prints (§ totals). */\n total?: boolean\n}\n\n/** Where a row came from - which file, and where in it. Shown on the card beside the row. */\nexport interface EntrySource {\n attachmentId?: string\n /** \"row 3\", \"the receipt photo\", \"the person's message\" - the model's words. */\n where?: string\n}\n\nexport interface EntryIssue {\n /** The field it is about. Absent: the row as a whole. */\n field?: string\n /** A code the screen translates: `ai-assistant.entry.issue.<code>`, or the target's own `messageKey`. */\n code: string\n messageKey?: string\n params?: Record<string, unknown>\n /** A blocking issue keeps the row out when the person presses the button. */\n blocking: boolean\n}\n\nexport interface EntryRowInput {\n values?: Record<string, unknown>\n sources?: EntrySource[]\n}\n\nexport interface EntryRow {\n index: number\n values: Record<string, unknown>\n sources: EntrySource[]\n issues: EntryIssue[]\n /** The line of a text source where this row's numbers and dates were all found - the server's check, not the model's word. */\n evidence?: { attachmentId: string; line: number }\n}\n\nexport interface EntryContext {\n /** The request state - domain, user, and when writing, `tx` and `afterCommit`. */\n state: any\n}\n\nexport interface EntryApplied {\n /** The created record's id, when there is one. */\n id?: string\n /** A short name for the conversation line - \"2026-09-12 · 택시 · ₩12,400\". */\n label?: string\n}\n\n/** What happened, for an application that writes down every assistant call (office's AI audit). */\nexport interface EntryEvent {\n phase: 'propose' | 'apply'\n tool: string\n rows: number\n ok: boolean\n applied?: number\n missed?: number\n error?: string\n /** propose: the rows as the model gave them; apply: the proposal key and each row's result. */\n detail?: unknown\n}\n\nexport interface EntryTarget {\n /** `<app>.<record>` - `office.expense-line`. */\n key: string\n /** i18n key of the record's name on the card. */\n labelKey: string\n /** What one row is, for the model. */\n description: string\n fields: EntryField[]\n /**\n * The application's own mutation that enters one record, as a GraphQL document with one root field -\n * `mutation ($line: NewExpenseLine!) { addExpenseLine(line: $line) { id } }`. Its root field is the door:\n * the propose tool is offered only to someone who passes it, and each row is entered by running it with\n * the person's request state, so `@privilege`, `@transaction` and the door's own checks apply as they do\n * to a person typing it in.\n */\n mutation: string\n /** The mutation's variables for one row. */\n variables(row: EntryRow): Record<string, unknown>\n /** What the conversation says of an entered row - its id and a short name. */\n appliedOf?(data: any, row: EntryRow): EntryApplied | undefined\n /** At most this many rows in one proposal. Default 200. */\n maxRows?: number\n /**\n * Read-only checks the application owns - a duplicate of what is already entered, a code that does not\n * exist. Asked when the rows are proposed and again when they are entered: the records may have moved.\n * Returns one list per row, in order.\n */\n check?(rows: EntryRow[], context: EntryContext): EntryIssue[][] | Promise<EntryIssue[][]>\n /** Told of every proposal and every entering - an application that audits its assistant writes it down. A throw is ignored. */\n record?(event: EntryEvent, context: EntryContext): void | Promise<void>\n}\n\n/**\n * `Mutation.<root field>` of the target's mutation - the one declaration both the tool's gate and the\n * entering read. A document that is not one mutation with one root field is refused at boot.\n */\nexport function entryDoorOf(mutation: string): string {\n const doc = parse(mutation)\n const operations = doc.definitions.filter((one: any) => one.kind === 'OperationDefinition') as any[]\n if (operations.length !== 1 || operations[0].operation !== 'mutation') throw new Error('is not one mutation')\n const fields = operations[0].selectionSet.selections.filter((one: any) => one.kind === 'Field')\n if (fields.length !== 1) throw new Error('must have exactly one root field')\n return `Mutation.${fields[0].name.value}`\n}\n\n/** Tells the target, and never lets its record keeping stop the work. */\nexport async function recordEntryEvent(target: EntryTarget, event: EntryEvent, context: EntryContext): Promise<void> {\n if (!target.record) return\n try {\n await target.record(event, context)\n } catch {\n /* an audit that failed to write is the application's to report */\n }\n}\n\nexport const DEFAULT_MAX_ROWS = 200\n\nconst targets = new Map<string, EntryTarget>()\n\nconst KEY = /^[a-z][a-z0-9-]*\\.[a-z][a-z0-9-]*$/\n\n/** Validates and keeps a target - `registerEntryTarget` (entry-tools.ts) also opens its tool. A malformed declaration is refused at boot, not in a conversation. */\nexport function declareEntryTarget(target: EntryTarget): void {\n if (!KEY.test(target?.key ?? '')) throw new Error(`[ai-assistant] entry target key '${target?.key}' is not '<app>.<record>'.`)\n try {\n entryDoorOf(target.mutation ?? '')\n } catch (error: any) {\n throw new Error(`[ai-assistant] entry target '${target.key}': its mutation ${error?.message ?? 'does not parse'}.`)\n }\n if (typeof target.variables !== 'function') throw new Error(`[ai-assistant] entry target '${target.key}' has no variables.`)\n if (!target.fields?.length) throw new Error(`[ai-assistant] entry target '${target.key}' declares no fields.`)\n const names = new Set<string>()\n for (const field of target.fields) {\n if (names.has(field.name)) throw new Error(`[ai-assistant] entry target '${target.key}' declares '${field.name}' twice.`)\n names.add(field.name)\n if (field.type === 'enum' && !field.values?.length)\n throw new Error(`[ai-assistant] entry target '${target.key}': enum field '${field.name}' lists no values.`)\n }\n targets.set(target.key, target)\n}\n\nexport function entryTargetOf(key: string | undefined): EntryTarget | undefined {\n return key ? targets.get(key) : undefined\n}\n\nexport function entryTargets(): EntryTarget[] {\n return [...targets.values()]\n}\n\n/** For tests. */\nexport function clearEntryTargets(): void {\n targets.clear()\n}\n\n/** `office.expense-line` → `proposeOfficeExpenseLineEntries` - one tool per target, so each has its own door. */\nexport function entryToolName(key: string): string {\n const pascal = key\n .split(/[.-]/)\n .filter(Boolean)\n .map(part => part[0].toUpperCase() + part.slice(1))\n .join('')\n return `propose${pascal}Entries`\n}\n\nexport function entryCategoryName(key: string): string {\n return `data-entry:${key}`\n}\n\nconst empty = (value: unknown) => value === undefined || value === null || (typeof value === 'string' && !value.trim())\n\n/** \"12,400\" · \"₩12,400\" · \"12 400\" → 12400. Only the separators people write; anything else is not a number. */\nfunction toNumber(value: unknown): number | undefined {\n if (typeof value === 'number') return Number.isFinite(value) ? value : undefined\n if (typeof value !== 'string') return undefined\n const cleaned = value.trim().replace(/^[₩$€¥£]\\s*/, '').replace(/[,\\s]/g, '').replace(/원$/, '')\n if (!/^-?\\d+(\\.\\d+)?$/.test(cleaned)) return undefined\n return Number(cleaned)\n}\n\n/** A calendar date as `YYYY-MM-DD` - \"2026.9.12\", \"2026/09/12\" too. A day that does not exist is not a date. */\nfunction toDate(value: unknown): string | undefined {\n if (typeof value !== 'string') return undefined\n const match = value.trim().match(/^(\\d{4})[-./](\\d{1,2})[-./](\\d{1,2})\\.?$/)\n if (!match) return undefined\n const [year, month, day] = [Number(match[1]), Number(match[2]), Number(match[3])]\n const date = new Date(Date.UTC(year, month - 1, day))\n if (date.getUTCFullYear() !== year || date.getUTCMonth() !== month - 1 || date.getUTCDate() !== day) return undefined\n return `${match[1]}-${String(month).padStart(2, '0')}-${String(day).padStart(2, '0')}`\n}\n\nfunction toBoolean(value: unknown): boolean | undefined {\n if (typeof value === 'boolean') return value\n if (typeof value !== 'string') return undefined\n const text = value.trim().toLowerCase()\n if (['true', 'yes', 'y', '1'].includes(text)) return true\n if (['false', 'no', 'n', '0'].includes(text)) return false\n return undefined\n}\n\n/**\n * The rows as the target reads them - each value in its field's type, and what was wrong said as an issue.\n *\n * A value that does not fit is **kept as it was written and marked**, never dropped or guessed: the card\n * shows what the material said, and the person corrects it in the conversation.\n */\nexport function normalizeEntryRows(target: EntryTarget, input: unknown): { rows: EntryRow[]; cut: number } {\n const list = Array.isArray(input) ? input : []\n const max = target.maxRows ?? DEFAULT_MAX_ROWS\n const fields = new Map(target.fields.map(field => [field.name, field]))\n\n const rows = list.slice(0, max).map((raw: any, index): EntryRow => {\n const given = raw && typeof raw.values === 'object' && raw.values ? raw.values : {}\n const values: Record<string, unknown> = {}\n const issues: EntryIssue[] = []\n\n for (const name of Object.keys(given)) {\n if (!fields.has(name)) issues.push({ field: name, code: 'unknown-field', blocking: false })\n }\n\n for (const field of target.fields) {\n const value = given[field.name]\n if (empty(value)) {\n if (field.required) issues.push({ field: field.name, code: 'required', blocking: true })\n continue\n }\n let read: unknown\n let code = ''\n switch (field.type) {\n case 'number':\n read = toNumber(value)\n code = 'not-a-number'\n break\n case 'integer':\n read = toNumber(value)\n if (read !== undefined && !Number.isInteger(read)) read = undefined\n code = 'not-an-integer'\n break\n case 'date':\n read = toDate(value)\n code = 'not-a-date'\n break\n case 'boolean':\n read = toBoolean(value)\n code = 'not-a-boolean'\n break\n case 'enum':\n read = field.values!.includes(String(value).trim()) ? String(value).trim() : undefined\n code = 'not-in-list'\n break\n default:\n read = String(value).trim()\n }\n if (read === undefined) {\n values[field.name] = value\n issues.push({ field: field.name, code, params: code === 'not-in-list' ? { values: field.values } : undefined, blocking: true })\n } else {\n values[field.name] = read\n }\n }\n\n const sources: EntrySource[] = Array.isArray(raw?.sources)\n ? raw.sources\n .filter((one: any) => one && (one.attachmentId || one.where))\n .map((one: any) => ({\n ...(typeof one.attachmentId === 'string' ? { attachmentId: one.attachmentId } : {}),\n ...(typeof one.where === 'string' ? { where: one.where.slice(0, 120) } : {})\n }))\n : []\n if (!sources.length) issues.push({ code: 'no-source', blocking: false })\n\n return { index, values, sources, issues }\n })\n\n return { rows, cut: Math.max(0, list.length - max) }\n}\n\n/** Adds the target's own findings to each row. A check that throws marks nothing and is reported by the caller. */\nexport function withCheckedIssues(rows: EntryRow[], found: EntryIssue[][] | undefined): EntryRow[] {\n if (!found) return rows\n return rows.map((row, i) => (found[i]?.length ? { ...row, issues: [...row.issues, ...found[i]] } : row))\n}\n\nexport function isBlocked(row: EntryRow): boolean {\n return row.issues.some(issue => issue.blocking)\n}\n\n/* ── Checking the rows against the material (design/ai/data-entry.md §4-1) ─────────────────────────────\n *\n * A row cites where it came from; the model's word is not proof. For a text source the server looks: the\n * row's numbers and dates must stand together on one line of the cited file. Found - the row carries that\n * line as evidence. A value the file does not have is marked, unless the row also cites the person's\n * message (a correction said in the conversation). A photo cannot be read here - the row says so.\n * Names and descriptions are not looked for: the model tidies them, and a tidied name is not a wrong one.\n */\n\nconst PERSON = /person|message|user|사용자|말/i\n\n/** The ways a number or a date is written in a file. */\nexport function writtenForms(type: EntryFieldType, value: unknown): string[] {\n if (type === 'number' || type === 'integer') {\n if (typeof value !== 'number' || !Number.isFinite(value)) return []\n const negative = value < 0\n const abs = Math.abs(value)\n const fixed = Number.isInteger(abs) ? String(abs) : abs.toFixed(2).replace(/0+$/, '').replace(/\\.$/, '')\n const [int, frac] = fixed.split('.')\n const grouped = int.replace(/\\B(?=(\\d{3})+(?!\\d))/g, ',')\n const forms = new Set<string>()\n for (const whole of [int, grouped]) {\n forms.add(frac ? `${whole}.${frac}` : whole)\n if (!frac) forms.add(`${whole}.00`)\n }\n return [...forms].map(form => (negative ? `-${form}` : form))\n }\n if (type === 'date') {\n const match = typeof value === 'string' ? value.match(/^(\\d{4})-(\\d{2})-(\\d{2})$/) : null\n if (!match) return []\n const [, y, m, d] = match\n const mm = String(Number(m))\n const dd = String(Number(d))\n return [`${y}-${m}-${d}`, `${y}.${m}.${d}`, `${y}/${m}/${d}`, `${y}${m}${d}`, `${y}.${mm}.${dd}`, `${y}/${mm}/${dd}`, `${y}-${mm}-${dd}`, `${y.slice(2)}.${m}.${d}`, `${y.slice(2)}/${m}/${d}`]\n }\n return []\n}\n\n/**\n * A form found as a whole number - \"12,400\" is not found in \"112,400\", \"12,4001\", \"12,400.50\" or \"12,400,000\";\n * \"2026-09-12\" not in \"2026-09-120\". A CSV's own commas are not part of the number.\n */\nexport function lineHas(line: string, forms: string[]): boolean {\n const digit = (c: string | undefined) => !!c && c >= '0' && c <= '9'\n return forms.some(form => {\n for (let at = line.indexOf(form); at >= 0; at = line.indexOf(form, at + 1)) {\n const before = line[at - 1]\n const after = line[at + form.length]\n /* A comma is also the column separator of a CSV: only a comma and three digits more continue the number. */\n if (digit(before) || (before === '.' && digit(line[at - 2]))) continue\n if (digit(after) || (after === '.' && digit(line[at + form.length + 1]))) continue\n if (after === ',' && /^,\\d{3}(?!\\d)/.test(line.slice(at + form.length))) continue\n return true\n }\n return false\n })\n}\n\n/**\n * Checks each row against the text of the files it cites. `texts` holds what could be read, by attachment id;\n * an id that is not there was an image, or could not be opened.\n */\nexport function verifyRowsAgainstSources(rows: EntryRow[], fields: EntryField[], texts: Map<string, string>): EntryRow[] {\n const checked = fields.filter(field => ['number', 'integer', 'date'].includes(field.type))\n return rows.map(row => {\n const files = row.sources.map(source => source.attachmentId).filter((id): id is string => !!id)\n if (!files.length || !checked.length) return row\n const readable = files.filter(id => texts.has(id))\n if (!readable.length) return { ...row, issues: [...row.issues, { code: 'source-not-checked', blocking: false }] }\n\n const forms = checked\n .map(field => ({ field, forms: writtenForms(field.type, row.values[field.name]) }))\n .filter(one => one.forms.length)\n if (!forms.length) return row\n\n for (const id of readable) {\n const lines = texts.get(id)!.split(/\\r?\\n/)\n const at = lines.findIndex(line => forms.every(one => lineHas(line, one.forms)))\n if (at >= 0) return { ...row, evidence: { attachmentId: id, line: at + 1 } }\n }\n\n const saidByPerson = row.sources.some(source => !source.attachmentId && PERSON.test(source.where ?? ''))\n const issues = [...row.issues]\n for (const one of forms) {\n const anywhere = readable.some(id => texts.get(id)!.split(/\\r?\\n/).some(line => lineHas(line, one.forms)))\n if (!anywhere && !saidByPerson) issues.push({ field: one.field.name, code: 'not-in-source', blocking: false })\n }\n if (issues.length === row.issues.length) issues.push({ code: 'source-scattered', blocking: false })\n return { ...row, issues }\n })\n}\n\nexport interface EntryTotal {\n field: string\n /** The sum over every row, and over the rows that will be entered. */\n all: number\n ready: number\n /** The total the material prints, as the model read it - and whether the server found it in the file. */\n declared?: number\n declaredFound?: boolean\n /** declared - all. */\n difference?: number\n}\n\n/** The sums of the fields declared `total`, and how they stand against the total the material prints. */\nexport function entryTotals(\n rows: EntryRow[],\n fields: EntryField[],\n declared: { field?: string; value?: unknown; attachmentId?: string } | undefined,\n texts: Map<string, string>\n): EntryTotal[] {\n return fields\n .filter(field => field.total && (field.type === 'number' || field.type === 'integer'))\n .map(field => {\n const sum = (list: EntryRow[]) => Math.round(list.reduce((acc, row) => acc + (typeof row.values[field.name] === 'number' ? (row.values[field.name] as number) : 0), 0) * 100) / 100\n const total: EntryTotal = { field: field.name, all: sum(rows), ready: sum(rows.filter(row => !isBlocked(row))) }\n const value = declared && (declared.field ?? field.name) === field.name ? toNumber(declared.value) : undefined\n if (value !== undefined) {\n total.declared = value\n total.difference = Math.round((value - total.all) * 100) / 100\n const text = declared!.attachmentId ? texts.get(declared!.attachmentId) : undefined\n if (text !== undefined) total.declaredFound = text.split(/\\r?\\n/).some(line => lineHas(line, writtenForms(field.type, value)))\n }\n return total\n })\n}\n\n"]}
|
|
1
|
+
{"version":3,"file":"entry-target.js","sourceRoot":"","sources":["../../../server/service/data-entry/entry-target.ts"],"names":[],"mappings":";;;AAuJA,kCAEC;AAGD,kCAOC;AAGD,4CAOC;AASD,gDAgCC;AAED,sCAEC;AAED,oCAEC;AAGD,8CAEC;AAcD,sCAOC;AAED,8CAEC;AAkCD,wCAuBC;AAGD,wCAMC;AAQD,gDA2CC;AAGD,8CAGC;AAED,8BAEC;AAcD,oCAwBC;AAMD,0BAcC;AAMD,4DA4BC;AAeD,kCAoBC;AA1fD;;;;;;;;;;;;;GAaG;AACH,qCAA+B;AAqI/B;;;GAGG;AACH,SAAgB,WAAW,CAAC,QAAgB;IAC1C,OAAO,WAAW,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAA;AAC1C,CAAC;AAED,iGAAiG;AACjG,SAAgB,WAAW,CAAC,QAAgB,EAAE,SAA+B;IAC3E,MAAM,GAAG,GAAG,IAAA,eAAK,EAAC,QAAQ,CAAC,CAAA;IAC3B,MAAM,UAAU,GAAG,GAAG,CAAC,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AG,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAA;QAChH,MAAM,KAAK,GAAG,QAAQ,IAAI,CAAC,QAAQ,CAAC,KAAK,IAAI,KAAK,CAAC,IAAI,CAAC,KAAK,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAA;QAC9G,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;YACxB,KAAK,CAAC,QAAQ,GAAG,KAAK,CAAA;YACtB,KAAK,CAAC,UAAU,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,KAAK,GAAG,KAAK,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC,GAAG,GAAG,CAAA;YAC9D,MAAM,IAAI,GAAG,QAAS,CAAC,YAAY,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,QAAS,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,SAAS,CAAA;YACnF,IAAI,IAAI,KAAK,SAAS;gBAAE,KAAK,CAAC,aAAa,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,OAAO,CAAC,IAAI,EAAE,YAAY,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC,CAAA;QAChI,CAAC;QACD,OAAO,KAAK,CAAA;IACd,CAAC,CAAC,CAAA;AACN,CAAC","sourcesContent":["/*\n * Data entry from material - what an application declares so the assistant can enter its records\n * (operato-application/design/ai/data-entry.md).\n *\n * A person hands the conversation what the records are made of - a bank export, a photo of a receipt,\n * lines pasted from a mail - and the assistant turns it into rows of one of the application's records.\n * Nothing is written by the model. It proposes the rows; the card shows them with what was wrong in\n * each and where each came from; a correction is said in the conversation and the model proposes again;\n * the person presses the button; the server enters each row **through the application's own GraphQL\n * mutation**, run with the person's request state - the same door, directives and checks as entering by hand.\n * There is no second way into the record.\n *\n * This file is pure - no framework, no database - so the rules a row passes are tested without a server.\n */\nimport { parse } from 'graphql'\n\nexport type EntryFieldType = 'string' | 'text' | 'number' | 'integer' | 'date' | 'boolean' | 'enum'\n\nexport interface EntryField {\n name: string\n type: EntryFieldType\n required?: boolean\n /** The allowed values of an `enum` field. */\n values?: string[]\n /** What the model reads about the field - English, like every tool description. */\n description?: string\n /** i18n key of the column heading on the card. Absent: the field name. */\n labelKey?: string\n /** A number field the card sums - and compares with the total the material prints (§ totals). */\n total?: boolean\n}\n\n/** Where a row came from - which file, and where in it. Shown on the card beside the row. */\nexport interface EntrySource {\n attachmentId?: string\n /** \"row 3\", \"the receipt photo\", \"the person's message\" - the model's words. */\n where?: string\n}\n\nexport interface EntryIssue {\n /** The field it is about. Absent: the row as a whole. */\n field?: string\n /** A code the screen translates: `ai-assistant.entry.issue.<code>`, or the target's own `messageKey`. */\n code: string\n messageKey?: string\n params?: Record<string, unknown>\n /** A blocking issue keeps the row out when the person presses the button. */\n blocking: boolean\n}\n\nexport interface EntryRowInput {\n values?: Record<string, unknown>\n sources?: EntrySource[]\n}\n\nexport interface EntryRow {\n index: number\n values: Record<string, unknown>\n sources: EntrySource[]\n issues: EntryIssue[]\n /** The line of a text source where this row's numbers and dates were all found - the server's check, not the model's word. */\n evidence?: { attachmentId: string; line: number }\n}\n\nexport interface EntryContext {\n /** The request state - domain, user, and when writing, `tx` and `afterCommit`. */\n state: any\n}\n\nexport interface EntryApplied {\n /** The created record's id, when there is one. */\n id?: string\n /** A short name for the conversation line - \"2026-09-12 · 택시 · ₩12,400\". */\n label?: string\n}\n\n/** What happened, for an application that writes down every assistant call (office's AI audit). */\nexport interface EntryEvent {\n phase: 'propose' | 'apply'\n tool: string\n rows: number\n ok: boolean\n applied?: number\n missed?: number\n error?: string\n /** propose: the rows as the model gave them; apply: the proposal key and each row's result. */\n detail?: unknown\n}\n\nexport interface EntryTarget {\n /** `<app>.<record>` - `office.expense-line`. */\n key: string\n /** i18n key of the record's name on the card. */\n labelKey: string\n /** What one row is, for the model. */\n description: string\n fields: EntryField[]\n /**\n * The application's own mutation that enters one record, as a GraphQL document with one root field -\n * `mutation ($line: NewExpenseLine!) { addExpenseLine(line: $line) { id } }`. Its root field is the door:\n * the propose tool is offered only to someone who passes it, and each row is entered by running it with\n * the person's request state, so `@privilege`, `@transaction` and the door's own checks apply as they do\n * to a person typing it in.\n */\n mutation: string\n /** The mutation's variables for one row. */\n variables(row: EntryRow): Record<string, unknown>\n /** What the conversation says of an entered row - its id and a short name. */\n appliedOf?(data: any, row: EntryRow): EntryApplied | undefined\n /** At most this many rows in one proposal. Default 200. */\n maxRows?: number\n /**\n * Read-only checks the application owns - a duplicate of what is already entered, a code that does not\n * exist. Asked when the rows are proposed and again when they are entered: the records may have moved.\n * Returns one list per row, in order.\n */\n check?(rows: EntryRow[], context: EntryContext): EntryIssue[][] | Promise<EntryIssue[][]>\n /** Told of every proposal and every entering - an application that audits its assistant writes it down. A throw is ignored. */\n record?(event: EntryEvent, context: EntryContext): void | Promise<void>\n /** Changing records that exist (design/ai/data-entry.md §5-1). Absent: this target only enters new ones. */\n update?: EntryUpdate\n}\n\n/** One record as the application's read query answers it - an `id` and the fields. */\nexport type EntryRecord = { id: string } & Record<string, unknown>\n\n/**\n * How records of a target are changed - every step through the application's API, as the person.\n *\n * Which record is meant is the server's to settle, never the model's memory: whichever way it was picked\n * (on screen, selected, described), the server reads it with `read` before a card is made and again before\n * it is written.\n */\nexport interface EntryUpdate {\n /** Reads the records by id, as the person - one they may not see is not found. */\n read: { query: string; variables(ids: string[]): Record<string, unknown>; recordsOf(data: any): EntryRecord[] }\n /** Finds candidates from what the person said - \"last week's 12,400 taxi\". */\n find?: { query: string; variables(criteria: Record<string, unknown>): Record<string, unknown>; recordsOf(data: any): EntryRecord[]; criteria: EntryField[] }\n /** The application's own mutation that changes one record. */\n mutation: string\n variables(change: { id: string; record: EntryRecord; values: Record<string, unknown> }): Record<string, unknown>\n /** How a record is named on the card - \"2026-09-12 · 카카오T\". */\n labelOf?(record: EntryRecord): string\n /** The fields that may change. Default: every declared field. */\n fields?: string[]\n}\n\n/**\n * `Mutation.<root field>` of the target's mutation - the one declaration both the tool's gate and the\n * entering read. A document that is not one mutation with one root field is refused at boot.\n */\nexport function entryDoorOf(mutation: string): string {\n return rootFieldOf(mutation, 'mutation')\n}\n\n/** `Query.<field>` or `Mutation.<field>` of a document with one operation and one root field. */\nexport function rootFieldOf(document: string, operation: 'query' | 'mutation'): string {\n const doc = parse(document)\n const operations = doc.definitions.filter((one: any) => one.kind === 'OperationDefinition') as any[]\n if (operations.length !== 1 || operations[0].operation !== operation) throw new Error(`is not one ${operation}`)\n const fields = operations[0].selectionSet.selections.filter((one: any) => one.kind === 'Field')\n if (fields.length !== 1) throw new Error('must have exactly one root field')\n return `${operation === 'query' ? 'Query' : 'Mutation'}.${fields[0].name.value}`\n}\n\n/** Tells the target, and never lets its record keeping stop the work. */\nexport async function recordEntryEvent(target: EntryTarget, event: EntryEvent, context: EntryContext): Promise<void> {\n if (!target.record) return\n try {\n await target.record(event, context)\n } catch {\n /* an audit that failed to write is the application's to report */\n }\n}\n\nexport const DEFAULT_MAX_ROWS = 200\n\nconst targets = new Map<string, EntryTarget>()\n\nconst KEY = /^[a-z][a-z0-9-]*\\.[a-z][a-z0-9-]*$/\n\n/** Validates and keeps a target - `registerEntryTarget` (entry-tools.ts) also opens its tool. A malformed declaration is refused at boot, not in a conversation. */\nexport function declareEntryTarget(target: EntryTarget): void {\n if (!KEY.test(target?.key ?? '')) throw new Error(`[ai-assistant] entry target key '${target?.key}' is not '<app>.<record>'.`)\n try {\n entryDoorOf(target.mutation ?? '')\n } catch (error: any) {\n throw new Error(`[ai-assistant] entry target '${target.key}': its mutation ${error?.message ?? 'does not parse'}.`)\n }\n if (typeof target.variables !== 'function') throw new Error(`[ai-assistant] entry target '${target.key}' has no variables.`)\n if (target.update) {\n for (const [what, document, operation] of [\n ['update.read', target.update.read?.query, 'query'],\n ['update.mutation', target.update.mutation, 'mutation'],\n ...(target.update.find ? [['update.find', target.update.find.query, 'query']] : [])\n ] as [string, string, 'query' | 'mutation'][]) {\n try {\n rootFieldOf(document ?? '', operation)\n } catch (error: any) {\n throw new Error(`[ai-assistant] entry target '${target.key}': ${what} ${error?.message ?? 'does not parse'}.`)\n }\n }\n const known = new Set(target.fields.map(field => field.name))\n for (const name of target.update.fields ?? []) if (!known.has(name)) throw new Error(`[ai-assistant] entry target '${target.key}': update field '${name}' is not declared.`)\n }\n if (!target.fields?.length) throw new Error(`[ai-assistant] entry target '${target.key}' declares no fields.`)\n const names = new Set<string>()\n for (const field of target.fields) {\n if (names.has(field.name)) throw new Error(`[ai-assistant] entry target '${target.key}' declares '${field.name}' twice.`)\n names.add(field.name)\n if (field.type === 'enum' && !field.values?.length)\n throw new Error(`[ai-assistant] entry target '${target.key}': enum field '${field.name}' lists no values.`)\n }\n targets.set(target.key, target)\n}\n\nexport function entryTargetOf(key: string | undefined): EntryTarget | undefined {\n return key ? targets.get(key) : undefined\n}\n\nexport function entryTargets(): EntryTarget[] {\n return [...targets.values()]\n}\n\n/** For tests. */\nexport function clearEntryTargets(): void {\n targets.clear()\n}\n\nconst pascalOf = (key: string) =>\n key\n .split(/[.-]/)\n .filter(Boolean)\n .map(part => part[0].toUpperCase() + part.slice(1))\n .join('')\n\n/** `office.expense-line` → `proposeOfficeExpenseLineChanges` / `findOfficeExpenseLine` - the tools of changing. */\nexport const changeToolName = (key: string) => `propose${pascalOf(key)}Changes`\nexport const findToolName = (key: string) => `find${pascalOf(key)}`\n\n/** `office.expense-line` → `proposeOfficeExpenseLineEntries` - one tool per target, so each has its own door. */\nexport function entryToolName(key: string): string {\n const pascal = key\n .split(/[.-]/)\n .filter(Boolean)\n .map(part => part[0].toUpperCase() + part.slice(1))\n .join('')\n return `propose${pascal}Entries`\n}\n\nexport function entryCategoryName(key: string): string {\n return `data-entry:${key}`\n}\n\nconst empty = (value: unknown) => value === undefined || value === null || (typeof value === 'string' && !value.trim())\n\n/** \"12,400\" · \"₩12,400\" · \"12 400\" → 12400. Only the separators people write; anything else is not a number. */\nfunction toNumber(value: unknown): number | undefined {\n if (typeof value === 'number') return Number.isFinite(value) ? value : undefined\n if (typeof value !== 'string') return undefined\n const cleaned = value.trim().replace(/^[₩$€¥£]\\s*/, '').replace(/[,\\s]/g, '').replace(/원$/, '')\n if (!/^-?\\d+(\\.\\d+)?$/.test(cleaned)) return undefined\n return Number(cleaned)\n}\n\n/** A calendar date as `YYYY-MM-DD` - \"2026.9.12\", \"2026/09/12\" too. A day that does not exist is not a date. */\nfunction toDate(value: unknown): string | undefined {\n if (typeof value !== 'string') return undefined\n const match = value.trim().match(/^(\\d{4})[-./](\\d{1,2})[-./](\\d{1,2})\\.?$/)\n if (!match) return undefined\n const [year, month, day] = [Number(match[1]), Number(match[2]), Number(match[3])]\n const date = new Date(Date.UTC(year, month - 1, day))\n if (date.getUTCFullYear() !== year || date.getUTCMonth() !== month - 1 || date.getUTCDate() !== day) return undefined\n return `${match[1]}-${String(month).padStart(2, '0')}-${String(day).padStart(2, '0')}`\n}\n\nfunction toBoolean(value: unknown): boolean | undefined {\n if (typeof value === 'boolean') return value\n if (typeof value !== 'string') return undefined\n const text = value.trim().toLowerCase()\n if (['true', 'yes', 'y', '1'].includes(text)) return true\n if (['false', 'no', 'n', '0'].includes(text)) return false\n return undefined\n}\n\n/** One value in its field's type - or the code of why it is not. An empty value is the caller's to judge. */\nexport function readFieldValue(field: EntryField, value: unknown): { read?: unknown; code?: string } {\n switch (field.type) {\n case 'number': {\n const read = toNumber(value)\n return read === undefined ? { code: 'not-a-number' } : { read }\n }\n case 'integer': {\n const read = toNumber(value)\n return read === undefined || !Number.isInteger(read) ? { code: 'not-an-integer' } : { read }\n }\n case 'date': {\n const read = toDate(value)\n return read === undefined ? { code: 'not-a-date' } : { read }\n }\n case 'boolean': {\n const read = toBoolean(value)\n return read === undefined ? { code: 'not-a-boolean' } : { read }\n }\n case 'enum':\n return field.values!.includes(String(value).trim()) ? { read: String(value).trim() } : { code: 'not-in-list' }\n default:\n return { read: String(value).trim() }\n }\n}\n\n/** Two values of one field the same - \"12400.00\" read from the database is 12400. */\nexport function sameFieldValue(field: EntryField, a: unknown, b: unknown): boolean {\n if (empty(a) && empty(b)) return true\n if (empty(a) || empty(b)) return false\n const x = readFieldValue(field, a)\n const y = readFieldValue(field, b)\n return x.read !== undefined && y.read !== undefined ? x.read === y.read : String(a) === String(b)\n}\n\n/**\n * The rows as the target reads them - each value in its field's type, and what was wrong said as an issue.\n *\n * A value that does not fit is **kept as it was written and marked**, never dropped or guessed: the card\n * shows what the material said, and the person corrects it in the conversation.\n */\nexport function normalizeEntryRows(target: EntryTarget, input: unknown): { rows: EntryRow[]; cut: number } {\n const list = Array.isArray(input) ? input : []\n const max = target.maxRows ?? DEFAULT_MAX_ROWS\n const fields = new Map(target.fields.map(field => [field.name, field]))\n\n const rows = list.slice(0, max).map((raw: any, index): EntryRow => {\n const given = raw && typeof raw.values === 'object' && raw.values ? raw.values : {}\n const values: Record<string, unknown> = {}\n const issues: EntryIssue[] = []\n\n for (const name of Object.keys(given)) {\n if (!fields.has(name)) issues.push({ field: name, code: 'unknown-field', blocking: false })\n }\n\n for (const field of target.fields) {\n const value = given[field.name]\n if (empty(value)) {\n if (field.required) issues.push({ field: field.name, code: 'required', blocking: true })\n continue\n }\n const { read, code } = readFieldValue(field, value)\n if (read === undefined) {\n values[field.name] = value\n issues.push({ field: field.name, code: code!, params: code === 'not-in-list' ? { values: field.values } : undefined, blocking: true })\n } else {\n values[field.name] = read\n }\n }\n\n const sources: EntrySource[] = Array.isArray(raw?.sources)\n ? raw.sources\n .filter((one: any) => one && (one.attachmentId || one.where))\n .map((one: any) => ({\n ...(typeof one.attachmentId === 'string' ? { attachmentId: one.attachmentId } : {}),\n ...(typeof one.where === 'string' ? { where: one.where.slice(0, 120) } : {})\n }))\n : []\n if (!sources.length) issues.push({ code: 'no-source', blocking: false })\n\n return { index, values, sources, issues }\n })\n\n return { rows, cut: Math.max(0, list.length - max) }\n}\n\n/** Adds the target's own findings to each row. A check that throws marks nothing and is reported by the caller. */\nexport function withCheckedIssues(rows: EntryRow[], found: EntryIssue[][] | undefined): EntryRow[] {\n if (!found) return rows\n return rows.map((row, i) => (found[i]?.length ? { ...row, issues: [...row.issues, ...found[i]] } : row))\n}\n\nexport function isBlocked(row: EntryRow): boolean {\n return row.issues.some(issue => issue.blocking)\n}\n\n/* ── Checking the rows against the material (design/ai/data-entry.md §4-1) ─────────────────────────────\n *\n * A row cites where it came from; the model's word is not proof. For a text source the server looks: the\n * row's numbers and dates must stand together on one line of the cited file. Found - the row carries that\n * line as evidence. A value the file does not have is marked, unless the row also cites the person's\n * message (a correction said in the conversation). A photo cannot be read here - the row says so.\n * Names and descriptions are not looked for: the model tidies them, and a tidied name is not a wrong one.\n */\n\nconst PERSON = /person|message|user|사용자|말/i\n\n/** The ways a number or a date is written in a file. */\nexport function writtenForms(type: EntryFieldType, value: unknown): string[] {\n if (type === 'number' || type === 'integer') {\n if (typeof value !== 'number' || !Number.isFinite(value)) return []\n const negative = value < 0\n const abs = Math.abs(value)\n const fixed = Number.isInteger(abs) ? String(abs) : abs.toFixed(2).replace(/0+$/, '').replace(/\\.$/, '')\n const [int, frac] = fixed.split('.')\n const grouped = int.replace(/\\B(?=(\\d{3})+(?!\\d))/g, ',')\n const forms = new Set<string>()\n for (const whole of [int, grouped]) {\n forms.add(frac ? `${whole}.${frac}` : whole)\n if (!frac) forms.add(`${whole}.00`)\n }\n return [...forms].map(form => (negative ? `-${form}` : form))\n }\n if (type === 'date') {\n const match = typeof value === 'string' ? value.match(/^(\\d{4})-(\\d{2})-(\\d{2})$/) : null\n if (!match) return []\n const [, y, m, d] = match\n const mm = String(Number(m))\n const dd = String(Number(d))\n return [`${y}-${m}-${d}`, `${y}.${m}.${d}`, `${y}/${m}/${d}`, `${y}${m}${d}`, `${y}.${mm}.${dd}`, `${y}/${mm}/${dd}`, `${y}-${mm}-${dd}`, `${y.slice(2)}.${m}.${d}`, `${y.slice(2)}/${m}/${d}`]\n }\n return []\n}\n\n/**\n * A form found as a whole number - \"12,400\" is not found in \"112,400\", \"12,4001\", \"12,400.50\" or \"12,400,000\";\n * \"2026-09-12\" not in \"2026-09-120\". A CSV's own commas are not part of the number.\n */\nexport function lineHas(line: string, forms: string[]): boolean {\n const digit = (c: string | undefined) => !!c && c >= '0' && c <= '9'\n return forms.some(form => {\n for (let at = line.indexOf(form); at >= 0; at = line.indexOf(form, at + 1)) {\n const before = line[at - 1]\n const after = line[at + form.length]\n /* A comma is also the column separator of a CSV: only a comma and three digits more continue the number. */\n if (digit(before) || (before === '.' && digit(line[at - 2]))) continue\n if (digit(after) || (after === '.' && digit(line[at + form.length + 1]))) continue\n if (after === ',' && /^,\\d{3}(?!\\d)/.test(line.slice(at + form.length))) continue\n return true\n }\n return false\n })\n}\n\n/**\n * Checks each row against the text of the files it cites. `texts` holds what could be read, by attachment id;\n * an id that is not there was an image, or could not be opened.\n */\nexport function verifyRowsAgainstSources(rows: EntryRow[], fields: EntryField[], texts: Map<string, string>): EntryRow[] {\n const checked = fields.filter(field => ['number', 'integer', 'date'].includes(field.type))\n return rows.map(row => {\n const files = row.sources.map(source => source.attachmentId).filter((id): id is string => !!id)\n if (!files.length || !checked.length) return row\n const readable = files.filter(id => texts.has(id))\n if (!readable.length) return { ...row, issues: [...row.issues, { code: 'source-not-checked', blocking: false }] }\n\n const forms = checked\n .map(field => ({ field, forms: writtenForms(field.type, row.values[field.name]) }))\n .filter(one => one.forms.length)\n if (!forms.length) return row\n\n for (const id of readable) {\n const lines = texts.get(id)!.split(/\\r?\\n/)\n const at = lines.findIndex(line => forms.every(one => lineHas(line, one.forms)))\n if (at >= 0) return { ...row, evidence: { attachmentId: id, line: at + 1 } }\n }\n\n const saidByPerson = row.sources.some(source => !source.attachmentId && PERSON.test(source.where ?? ''))\n const issues = [...row.issues]\n for (const one of forms) {\n const anywhere = readable.some(id => texts.get(id)!.split(/\\r?\\n/).some(line => lineHas(line, one.forms)))\n if (!anywhere && !saidByPerson) issues.push({ field: one.field.name, code: 'not-in-source', blocking: false })\n }\n if (issues.length === row.issues.length) issues.push({ code: 'source-scattered', blocking: false })\n return { ...row, issues }\n })\n}\n\nexport interface EntryTotal {\n field: string\n /** The sum over every row, and over the rows that will be entered. */\n all: number\n ready: number\n /** The total the material prints, as the model read it - and whether the server found it in the file. */\n declared?: number\n declaredFound?: boolean\n /** declared - all. */\n difference?: number\n}\n\n/** The sums of the fields declared `total`, and how they stand against the total the material prints. */\nexport function entryTotals(\n rows: EntryRow[],\n fields: EntryField[],\n declared: { field?: string; value?: unknown; attachmentId?: string } | undefined,\n texts: Map<string, string>\n): EntryTotal[] {\n return fields\n .filter(field => field.total && (field.type === 'number' || field.type === 'integer'))\n .map(field => {\n const sum = (list: EntryRow[]) => Math.round(list.reduce((acc, row) => acc + (typeof row.values[field.name] === 'number' ? (row.values[field.name] as number) : 0), 0) * 100) / 100\n const total: EntryTotal = { field: field.name, all: sum(rows), ready: sum(rows.filter(row => !isBlocked(row))) }\n const value = declared && (declared.field ?? field.name) === field.name ? toNumber(declared.value) : undefined\n if (value !== undefined) {\n total.declared = value\n total.difference = Math.round((value - total.all) * 100) / 100\n const text = declared!.attachmentId ? texts.get(declared!.attachmentId) : undefined\n if (text !== undefined) total.declaredFound = text.split(/\\r?\\n/).some(line => lineHas(line, writtenForms(field.type, value)))\n }\n return total\n })\n}\n\n"]}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type ToolCategory } from '@things-factory/ai-client-base';
|
|
2
|
+
import { type GraphqlRunner } from './entry-update.js';
|
|
2
3
|
import { type EntryRow, type EntryTarget } from './entry-target.js';
|
|
3
4
|
export type SourceTextLoader = (attachmentIds: string[], context: any) => Promise<Map<string, string>>;
|
|
4
5
|
export declare function proposeEntries(target: EntryTarget, args: any, context: any, loadTexts?: SourceTextLoader): Promise<{
|
|
@@ -34,7 +35,12 @@ export declare function proposeEntries(target: EntryTarget, args: any, context:
|
|
|
34
35
|
rejected?: undefined;
|
|
35
36
|
error?: undefined;
|
|
36
37
|
}>;
|
|
37
|
-
|
|
38
|
+
/**
|
|
39
|
+
* The application's API as the person who asked - the tool's own request state, no transaction handed on.
|
|
40
|
+
* Loaded late so the rules are tested without the shell.
|
|
41
|
+
*/
|
|
42
|
+
export declare const runAsCaller: (context: any) => GraphqlRunner;
|
|
43
|
+
export declare function entryCategoryOf(target: EntryTarget, run?: (context: any) => GraphqlRunner): ToolCategory;
|
|
38
44
|
/**
|
|
39
45
|
* What an application calls at boot to let the assistant enter one of its records.
|
|
40
46
|
*
|
|
@@ -33,6 +33,7 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.runAsCaller = void 0;
|
|
36
37
|
exports.proposeEntries = proposeEntries;
|
|
37
38
|
exports.entryCategoryOf = entryCategoryOf;
|
|
38
39
|
exports.registerEntryTarget = registerEntryTarget;
|
|
@@ -46,6 +47,7 @@ exports.registerEntryTarget = registerEntryTarget;
|
|
|
46
47
|
* field's type, asks the target's own checks, and hands back a proposal - the card.
|
|
47
48
|
*/
|
|
48
49
|
const ai_client_base_1 = require("@things-factory/ai-client-base");
|
|
50
|
+
const entry_update_js_1 = require("./entry-update.js");
|
|
49
51
|
const entry_target_js_1 = require("./entry-target.js");
|
|
50
52
|
function fieldSchema(field) {
|
|
51
53
|
const type = field.type === 'number' || field.type === 'integer' ? ['number', 'string'] : field.type === 'boolean' ? ['boolean', 'string'] : 'string';
|
|
@@ -112,7 +114,69 @@ async function proposeEntries(target, args, context, loadTexts = readSources) {
|
|
|
112
114
|
'nothing is written until the person presses the button on the card. Tell them which rows are blocked or do not match their file, and why, and ask for what is missing.'
|
|
113
115
|
};
|
|
114
116
|
}
|
|
115
|
-
|
|
117
|
+
/**
|
|
118
|
+
* The application's API as the person who asked - the tool's own request state, no transaction handed on.
|
|
119
|
+
* Loaded late so the rules are tested without the shell.
|
|
120
|
+
*/
|
|
121
|
+
const runAsCaller = (context) => async (document, variables) => {
|
|
122
|
+
const [{ GraphqlLocalClient }, { default: gql }] = await Promise.all([Promise.resolve().then(() => __importStar(require('@things-factory/shell'))), Promise.resolve().then(() => __importStar(require('graphql-tag')))]);
|
|
123
|
+
const { tx: _tx, afterCommit: _after, ...state } = context?.state ?? {};
|
|
124
|
+
const operation = /^\s*mutation\b/.test(document) ? 'mutate' : 'query';
|
|
125
|
+
const result = operation === 'mutate'
|
|
126
|
+
? await GraphqlLocalClient.client.mutate({ mutation: gql(document), variables, context: { state, t: context?.t } })
|
|
127
|
+
: await GraphqlLocalClient.client.query({ query: gql(document), variables, context: { state, t: context?.t }, fetchPolicy: 'no-cache' });
|
|
128
|
+
return { data: result.data, errors: result.errors };
|
|
129
|
+
};
|
|
130
|
+
exports.runAsCaller = runAsCaller;
|
|
131
|
+
/** The two tools of changing records - finding candidates, and the 수정안 (design/ai/data-entry.md §5-1). */
|
|
132
|
+
function changeSpecs(target, run) {
|
|
133
|
+
const update = target.update;
|
|
134
|
+
if (!update)
|
|
135
|
+
return [];
|
|
136
|
+
const readDoor = (0, entry_target_js_1.rootFieldOf)(update.read.query, 'query');
|
|
137
|
+
const specs = [
|
|
138
|
+
{
|
|
139
|
+
kind: 'read',
|
|
140
|
+
name: (0, entry_target_js_1.changeToolName)(target.key),
|
|
141
|
+
/* The person must be able to read the records and change them by hand. */
|
|
142
|
+
doors: [(0, entry_target_js_1.rootFieldOf)(update.mutation, 'mutation'), readDoor],
|
|
143
|
+
description: `Propose changes to existing records: ${target.description} ` +
|
|
144
|
+
'Name each record by ref: "current" (the one on screen), "selected" (every row selected on screen) or an id a find tool returned. ' +
|
|
145
|
+
'The server reads each record, and the card shows what it holds now and what it becomes; nothing changes until the person presses it.',
|
|
146
|
+
schema: {
|
|
147
|
+
type: 'object',
|
|
148
|
+
properties: {
|
|
149
|
+
changes: {
|
|
150
|
+
type: 'array',
|
|
151
|
+
items: {
|
|
152
|
+
type: 'object',
|
|
153
|
+
properties: {
|
|
154
|
+
ref: { type: 'string', description: '"current", "selected", or a record id from a find tool - never a guessed id.' },
|
|
155
|
+
values: { type: 'object', description: 'Only the fields that change, with their new values.', properties: Object.fromEntries((0, entry_update_js_1.changeableFields)(target).map(field => [field.name, fieldSchema(field)])) }
|
|
156
|
+
},
|
|
157
|
+
required: ['ref', 'values']
|
|
158
|
+
}
|
|
159
|
+
},
|
|
160
|
+
note: { type: 'string', description: 'One line for the card.' }
|
|
161
|
+
},
|
|
162
|
+
required: ['changes']
|
|
163
|
+
},
|
|
164
|
+
builder: (args, context) => (0, entry_update_js_1.proposeChanges)(target, args, context, run(context))
|
|
165
|
+
}
|
|
166
|
+
];
|
|
167
|
+
if (update.find) {
|
|
168
|
+
specs.push({
|
|
169
|
+
kind: 'read',
|
|
170
|
+
name: (0, entry_target_js_1.findToolName)(target.key),
|
|
171
|
+
doors: [(0, entry_target_js_1.rootFieldOf)(update.find.query, 'query')],
|
|
172
|
+
description: `Find existing records to change from what the person described: ${target.description} Returns candidates with their ids.`,
|
|
173
|
+
schema: { type: 'object', properties: Object.fromEntries(update.find.criteria.map(field => [field.name, fieldSchema(field)])) },
|
|
174
|
+
builder: (args, context) => (0, entry_update_js_1.findRecords)(target, args, run(context))
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
return specs;
|
|
178
|
+
}
|
|
179
|
+
function entryCategoryOf(target, run = exports.runAsCaller) {
|
|
116
180
|
const name = (0, entry_target_js_1.entryToolName)(target.key);
|
|
117
181
|
const spec = {
|
|
118
182
|
kind: 'read',
|
|
@@ -168,9 +232,15 @@ function entryCategoryOf(target) {
|
|
|
168
232
|
'- Give each row its sources: which attachment and where in it. A value the person gave or corrected in the conversation adds the source where: "the person\'s message". The server looks for each row\'s numbers and dates in the cited file and marks what it does not find.',
|
|
169
233
|
'- When the material prints a total, pass it as declaredTotal exactly as printed - do not add it up yourself.',
|
|
170
234
|
`- ${name} only proposes. Nothing is entered until the person presses the button on the card - never say the records were entered.`,
|
|
171
|
-
`- When the person corrects or drops rows, call ${name} again with the whole corrected set. The newest card replaces the earlier ones; an earlier card can no longer be entered
|
|
235
|
+
`- When the person corrects or drops rows, call ${name} again with the whole corrected set. The newest card replaces the earlier ones; an earlier card can no longer be entered.`,
|
|
236
|
+
...(target.update
|
|
237
|
+
? [
|
|
238
|
+
`- To change records that exist, call ${(0, entry_target_js_1.changeToolName)(target.key)}. Use ref "current" for the record on screen and "selected" for the rows selected there.${target.update.find ? ` Otherwise call ${(0, entry_target_js_1.findToolName)(target.key)} first with what the person said; if more than one record matches, list them and ask which - never pick one yourself.` : ' Otherwise ask the person to open or select the record.'}`,
|
|
239
|
+
`- ${(0, entry_target_js_1.changeToolName)(target.key)} only proposes; the card shows each record's value now and after. Never say a record was changed.`
|
|
240
|
+
]
|
|
241
|
+
: [])
|
|
172
242
|
].join('\n'),
|
|
173
|
-
specs: [spec]
|
|
243
|
+
specs: [spec, ...changeSpecs(target, run)]
|
|
174
244
|
};
|
|
175
245
|
}
|
|
176
246
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entry-tools.js","sourceRoot":"","sources":["../../../server/service/data-entry/entry-tools.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiDA,wCAkDC;AAED,0CA8DC;AAOD,kDAGC;AA7KD;;;;;;;;GAQG;AACH,mEAAuG;AAEvG,uDAc0B;AAE1B,SAAS,WAAW,CAAC,KAAiB;IACpC,MAAM,IAAI,GAAG,KAAK,CAAC,IAAI,KAAK,QAAQ,IAAI,KAAK,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CA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,IAAI,CAAC,IAAI,CAAC;QACZ,KAAK,EAAE,CAAC,IAAI,CAAC;KACd,CAAA;AACH,CAAC;AAED;;;;GAIG;AACH,SAAgB,mBAAmB,CAAC,MAAmB;IACrD,IAAA,oCAAkB,EAAC,MAAM,CAAC,CAAA;IAC1B,IAAA,qCAAoB,EAAC,eAAe,CAAC,MAAM,CAAC,CAAC,CAAA;AAC/C,CAAC","sourcesContent":["/*\n * The propose tool of each entry target (operato-application/design/ai/data-entry.md §3).\n *\n * One tool per target, so each carries its own door: the tool is offered only to a person who could enter\n * those records by hand, and its card cannot be made for someone who could not press it.\n *\n * The tool writes nothing. It reads the rows the model made from the material, puts each value in its\n * field's type, asks the target's own checks, and hands back a proposal - the card.\n */\nimport { registerToolCategory, type ToolCategory, type ToolSpec } from '@things-factory/ai-client-base'\n\nimport {\n declareEntryTarget,\n entryTotals,\n verifyRowsAgainstSources,\n entryCategoryName,\n entryDoorOf,\n entryToolName,\n isBlocked,\n normalizeEntryRows,\n recordEntryEvent,\n withCheckedIssues,\n type EntryField,\n type EntryRow,\n type EntryTarget\n} from './entry-target.js'\n\nfunction fieldSchema(field: EntryField): any {\n const type = field.type === 'number' || field.type === 'integer' ? ['number', 'string'] : field.type === 'boolean' ? ['boolean', 'string'] : 'string'\n const said = [\n field.description,\n field.required ? 'required' : 'optional',\n field.type === 'date' ? 'YYYY-MM-DD' : undefined,\n field.type === 'enum' ? `one of: ${field.values!.join(', ')}` : undefined\n ]\n .filter(Boolean)\n .join('. ')\n return { type, description: said }\n}\n\n/** What the card needs besides the rows - the columns, in the target's order. */\nfunction columnsOf(target: EntryTarget) {\n return target.fields.map(field => ({ name: field.name, type: field.type, required: !!field.required, ...(field.labelKey ? { labelKey: field.labelKey } : {}) }))\n}\n\nexport type SourceTextLoader = (attachmentIds: string[], context: any) => Promise<Map<string, string>>\n\nconst readSources: SourceTextLoader = async (ids, context) => (await import('./entry-sources.js')).loadSourceTexts(ids, context)\n\nexport async function proposeEntries(target: EntryTarget, args: any, context: any, loadTexts: SourceTextLoader = readSources) {\n const tool = entryToolName(target.key)\n const told = (event: Omit<Parameters<typeof recordEntryEvent>[1], 'phase' | 'tool'>) => recordEntryEvent(target, { phase: 'propose', tool, ...event }, { state: context?.state })\n const { rows: normalized, cut } = normalizeEntryRows(target, args?.rows)\n if (!normalized.length) {\n await told({ rows: 0, ok: false, error: 'no-rows', detail: args })\n return { rejected: true, error: 'no-rows', message: 'no rows were given. Read the material and pass every record as a row.' }\n }\n\n /* The server looks in the cited files itself - the model's citation is not proof (design/ai/data-entry.md §4-1). */\n const declared = args?.declaredTotal && typeof args.declaredTotal === 'object' ? args.declaredTotal : undefined\n const cited = [...normalized.flatMap(row => row.sources.map(source => source.attachmentId)), declared?.attachmentId].filter((id): id is string => typeof id === 'string' && !!id)\n const texts = cited.length ? await loadTexts(cited, context).catch(() => new Map<string, string>()) : new Map<string, string>()\n const read = verifyRowsAgainstSources(normalized, target.fields, texts)\n\n let rows: EntryRow[] = read\n let checkFailed: string | undefined\n if (target.check) {\n try {\n rows = withCheckedIssues(read, await target.check(read, { state: context?.state }))\n } catch (error: any) {\n checkFailed = error?.message || 'check-failed'\n }\n }\n\n const blocked = rows.filter(isBlocked).length\n const totals = entryTotals(rows, target.fields, declared, texts)\n const verified = rows.filter(row => row.evidence).length\n const unmatched = rows.filter(row => row.issues.some(issue => issue.code === 'not-in-source')).length\n await told({ rows: rows.length, ok: true, detail: args })\n return {\n proposed: true,\n kind: 'entry',\n target: target.key,\n labelKey: target.labelKey,\n label: `${rows.length} ${target.key} rows`,\n icon: 'playlist_add',\n columns: columnsOf(target),\n rows,\n counts: { rows: rows.length, ready: rows.length - blocked, blocked, cut, verified, unmatched },\n ...(totals.length ? { totals } : {}),\n ...(typeof args?.note === 'string' && args.note.trim() ? { reason: args.note.trim().slice(0, 300) } : {}),\n ...(checkFailed ? { checkFailed } : {}),\n /* For the model - the card is the answer; it says what the person must still decide. */\n message:\n `proposed ${rows.length} rows (${rows.length - blocked} ready, ${blocked} blocked${cut ? `, ${cut} cut over the limit` : ''}; ` +\n `${verified} found line by line in their files, ${unmatched} with a value the file does not have). ` +\n totals.filter(total => total.difference).map(total => `${total.field}: the material's total differs from the rows by ${total.difference}. `).join('') +\n 'nothing is written until the person presses the button on the card. Tell them which rows are blocked or do not match their file, and why, and ask for what is missing.'\n }\n}\n\nexport function entryCategoryOf(target: EntryTarget): ToolCategory {\n const name = entryToolName(target.key)\n const spec = {\n kind: 'read',\n name,\n /* The person must be able to enter these records themselves - the tool is not a second way in. */\n doors: [entryDoorOf(target.mutation)],\n description:\n `Propose records to enter: ${target.description} ` +\n 'Pass every record found in the material as one row. The rows are shown to the person as a card; nothing is written until they press it.',\n schema: {\n type: 'object',\n properties: {\n rows: {\n type: 'array',\n description: `At most ${target.maxRows ?? 200} rows.`,\n items: {\n type: 'object',\n properties: {\n values: {\n type: 'object',\n properties: Object.fromEntries(target.fields.map(field => [field.name, fieldSchema(field)]))\n },\n sources: {\n type: 'array',\n description: 'Where this row came from: the attachment id and where in it (\"row 3\", \"the receipt photo\"), or where: \"the person\\'s message\".',\n items: { type: 'object', properties: { attachmentId: { type: 'string' }, where: { type: 'string' } } }\n }\n },\n required: ['values', 'sources']\n }\n },\n note: { type: 'string', description: 'One line for the card - what this set is (\"September card statement\").' },\n declaredTotal: {\n type: 'object',\n description: 'The total the material itself prints, when it prints one - the card compares it with the sum of the rows. Never compute it yourself.',\n properties: {\n field: { type: 'string', description: `Which field it totals${target.fields.filter(field => field.total).length ? ` (${target.fields.filter(field => field.total).map(field => field.name).join(', ')})` : ''}.` },\n value: { type: ['number', 'string'] },\n attachmentId: { type: 'string' },\n where: { type: 'string' }\n }\n }\n },\n required: ['rows']\n },\n builder: (args: any, context: any) => proposeEntries(target, args, context)\n } as ToolSpec\n\n return {\n name: entryCategoryName(target.key),\n description: `data entry: ${target.key}`,\n guidance: [\n `- When the person gives material to enter as records (files, photos, pasted text), read all of it first - call readChatAttachment for a file sent in an earlier turn - then call ${name} once with every record as a row.`,\n '- Never invent a value. Leave a field out when the material does not say it; the card marks it, and you ask the person for it.',\n '- Give each row its sources: which attachment and where in it. A value the person gave or corrected in the conversation adds the source where: \"the person\\'s message\". The server looks for each row\\'s numbers and dates in the cited file and marks what it does not find.',\n '- When the material prints a total, pass it as declaredTotal exactly as printed - do not add it up yourself.',\n `- ${name} only proposes. Nothing is entered until the person presses the button on the card - never say the records were entered.`,\n `- When the person corrects or drops rows, call ${name} again with the whole corrected set. The newest card replaces the earlier ones; an earlier card can no longer be entered.`\n ].join('\\n'),\n specs: [spec]\n }\n}\n\n/**\n * What an application calls at boot to let the assistant enter one of its records.\n *\n * A mode opens it by naming the key in `entryTargets` (the tool is not in every conversation of the app).\n */\nexport function registerEntryTarget(target: EntryTarget): void {\n declareEntryTarget(target)\n registerToolCategory(entryCategoryOf(target))\n}\n"]}
|
|
1
|
+
{"version":3,"file":"entry-tools.js","sourceRoot":"","sources":["../../../server/service/data-entry/entry-tools.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqDA,wCAkDC;AAkED,0CAoEC;AAOD,kDAGC;AAvPD;;;;;;;;GAQG;AACH,mEAAuG;AAEvG,uDAAqG;AACrG,uDAiB0B;AAE1B,SAAS,WAAW,CAAC,KAAiB;IACpC,MAAM,IAAI,GAAG,KAAK,CAAC,IAAI,KAAK,QAAQ,IAAI,KAAK,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAA;IACrJ,MAAM,IAAI,GAAG;QACX,KAAK,CAAC,WAAW;QACjB,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,UAAU;QACxC,KAAK,CAAC,IAAI,KAAK,M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CAAC,CAAA;IAC1B,IAAA,qCAAoB,EAAC,eAAe,CAAC,MAAM,CAAC,CAAC,CAAA;AAC/C,CAAC","sourcesContent":["/*\n * The propose tool of each entry target (operato-application/design/ai/data-entry.md §3).\n *\n * One tool per target, so each carries its own door: the tool is offered only to a person who could enter\n * those records by hand, and its card cannot be made for someone who could not press it.\n *\n * The tool writes nothing. It reads the rows the model made from the material, puts each value in its\n * field's type, asks the target's own checks, and hands back a proposal - the card.\n */\nimport { registerToolCategory, type ToolCategory, type ToolSpec } from '@things-factory/ai-client-base'\n\nimport { findRecords, proposeChanges, changeableFields, type GraphqlRunner } from './entry-update.js'\nimport {\n changeToolName,\n findToolName,\n rootFieldOf,\n declareEntryTarget,\n entryTotals,\n verifyRowsAgainstSources,\n entryCategoryName,\n entryDoorOf,\n entryToolName,\n isBlocked,\n normalizeEntryRows,\n recordEntryEvent,\n withCheckedIssues,\n type EntryField,\n type EntryRow,\n type EntryTarget\n} from './entry-target.js'\n\nfunction fieldSchema(field: EntryField): any {\n const type = field.type === 'number' || field.type === 'integer' ? ['number', 'string'] : field.type === 'boolean' ? ['boolean', 'string'] : 'string'\n const said = [\n field.description,\n field.required ? 'required' : 'optional',\n field.type === 'date' ? 'YYYY-MM-DD' : undefined,\n field.type === 'enum' ? `one of: ${field.values!.join(', ')}` : undefined\n ]\n .filter(Boolean)\n .join('. ')\n return { type, description: said }\n}\n\n/** What the card needs besides the rows - the columns, in the target's order. */\nfunction columnsOf(target: EntryTarget) {\n return target.fields.map(field => ({ name: field.name, type: field.type, required: !!field.required, ...(field.labelKey ? { labelKey: field.labelKey } : {}) }))\n}\n\nexport type SourceTextLoader = (attachmentIds: string[], context: any) => Promise<Map<string, string>>\n\nconst readSources: SourceTextLoader = async (ids, context) => (await import('./entry-sources.js')).loadSourceTexts(ids, context)\n\nexport async function proposeEntries(target: EntryTarget, args: any, context: any, loadTexts: SourceTextLoader = readSources) {\n const tool = entryToolName(target.key)\n const told = (event: Omit<Parameters<typeof recordEntryEvent>[1], 'phase' | 'tool'>) => recordEntryEvent(target, { phase: 'propose', tool, ...event }, { state: context?.state })\n const { rows: normalized, cut } = normalizeEntryRows(target, args?.rows)\n if (!normalized.length) {\n await told({ rows: 0, ok: false, error: 'no-rows', detail: args })\n return { rejected: true, error: 'no-rows', message: 'no rows were given. Read the material and pass every record as a row.' }\n }\n\n /* The server looks in the cited files itself - the model's citation is not proof (design/ai/data-entry.md §4-1). */\n const declared = args?.declaredTotal && typeof args.declaredTotal === 'object' ? args.declaredTotal : undefined\n const cited = [...normalized.flatMap(row => row.sources.map(source => source.attachmentId)), declared?.attachmentId].filter((id): id is string => typeof id === 'string' && !!id)\n const texts = cited.length ? await loadTexts(cited, context).catch(() => new Map<string, string>()) : new Map<string, string>()\n const read = verifyRowsAgainstSources(normalized, target.fields, texts)\n\n let rows: EntryRow[] = read\n let checkFailed: string | undefined\n if (target.check) {\n try {\n rows = withCheckedIssues(read, await target.check(read, { state: context?.state }))\n } catch (error: any) {\n checkFailed = error?.message || 'check-failed'\n }\n }\n\n const blocked = rows.filter(isBlocked).length\n const totals = entryTotals(rows, target.fields, declared, texts)\n const verified = rows.filter(row => row.evidence).length\n const unmatched = rows.filter(row => row.issues.some(issue => issue.code === 'not-in-source')).length\n await told({ rows: rows.length, ok: true, detail: args })\n return {\n proposed: true,\n kind: 'entry',\n target: target.key,\n labelKey: target.labelKey,\n label: `${rows.length} ${target.key} rows`,\n icon: 'playlist_add',\n columns: columnsOf(target),\n rows,\n counts: { rows: rows.length, ready: rows.length - blocked, blocked, cut, verified, unmatched },\n ...(totals.length ? { totals } : {}),\n ...(typeof args?.note === 'string' && args.note.trim() ? { reason: args.note.trim().slice(0, 300) } : {}),\n ...(checkFailed ? { checkFailed } : {}),\n /* For the model - the card is the answer; it says what the person must still decide. */\n message:\n `proposed ${rows.length} rows (${rows.length - blocked} ready, ${blocked} blocked${cut ? `, ${cut} cut over the limit` : ''}; ` +\n `${verified} found line by line in their files, ${unmatched} with a value the file does not have). ` +\n totals.filter(total => total.difference).map(total => `${total.field}: the material's total differs from the rows by ${total.difference}. `).join('') +\n 'nothing is written until the person presses the button on the card. Tell them which rows are blocked or do not match their file, and why, and ask for what is missing.'\n }\n}\n\n/**\n * The application's API as the person who asked - the tool's own request state, no transaction handed on.\n * Loaded late so the rules are tested without the shell.\n */\nexport const runAsCaller = (context: any): GraphqlRunner => async (document, variables) => {\n const [{ GraphqlLocalClient }, { default: gql }] = await Promise.all([import('@things-factory/shell'), import('graphql-tag')])\n const { tx: _tx, afterCommit: _after, ...state } = context?.state ?? {}\n const operation = /^\\s*mutation\\b/.test(document) ? 'mutate' : 'query'\n const result: any =\n operation === 'mutate'\n ? await GraphqlLocalClient.client.mutate({ mutation: gql(document), variables, context: { state, t: context?.t } })\n : await GraphqlLocalClient.client.query({ query: gql(document), variables, context: { state, t: context?.t }, fetchPolicy: 'no-cache' })\n return { data: result.data, errors: result.errors }\n}\n\n/** The two tools of changing records - finding candidates, and the 수정안 (design/ai/data-entry.md §5-1). */\nfunction changeSpecs(target: EntryTarget, run: (context: any) => GraphqlRunner): ToolSpec[] {\n const update = target.update\n if (!update) return []\n const readDoor = rootFieldOf(update.read.query, 'query')\n const specs: ToolSpec[] = [\n {\n kind: 'read',\n name: changeToolName(target.key),\n /* The person must be able to read the records and change them by hand. */\n doors: [rootFieldOf(update.mutation, 'mutation'), readDoor],\n description:\n `Propose changes to existing records: ${target.description} ` +\n 'Name each record by ref: \"current\" (the one on screen), \"selected\" (every row selected on screen) or an id a find tool returned. ' +\n 'The server reads each record, and the card shows what it holds now and what it becomes; nothing changes until the person presses it.',\n schema: {\n type: 'object',\n properties: {\n changes: {\n type: 'array',\n items: {\n type: 'object',\n properties: {\n ref: { type: 'string', description: '\"current\", \"selected\", or a record id from a find tool - never a guessed id.' },\n values: { type: 'object', description: 'Only the fields that change, with their new values.', properties: Object.fromEntries(changeableFields(target).map(field => [field.name, fieldSchema(field)])) }\n },\n required: ['ref', 'values']\n }\n },\n note: { type: 'string', description: 'One line for the card.' }\n },\n required: ['changes']\n },\n builder: (args: any, context: any) => proposeChanges(target, args, context, run(context))\n } as ToolSpec\n ]\n if (update.find) {\n specs.push({\n kind: 'read',\n name: findToolName(target.key),\n doors: [rootFieldOf(update.find.query, 'query')],\n description: `Find existing records to change from what the person described: ${target.description} Returns candidates with their ids.`,\n schema: { type: 'object', properties: Object.fromEntries(update.find.criteria.map(field => [field.name, fieldSchema(field)])) },\n builder: (args: any, context: any) => findRecords(target, args, run(context))\n } as ToolSpec)\n }\n return specs\n}\n\nexport function entryCategoryOf(target: EntryTarget, run: (context: any) => GraphqlRunner = runAsCaller): ToolCategory {\n const name = entryToolName(target.key)\n const spec = {\n kind: 'read',\n name,\n /* The person must be able to enter these records themselves - the tool is not a second way in. */\n doors: [entryDoorOf(target.mutation)],\n description:\n `Propose records to enter: ${target.description} ` +\n 'Pass every record found in the material as one row. The rows are shown to the person as a card; nothing is written until they press it.',\n schema: {\n type: 'object',\n properties: {\n rows: {\n type: 'array',\n description: `At most ${target.maxRows ?? 200} rows.`,\n items: {\n type: 'object',\n properties: {\n values: {\n type: 'object',\n properties: Object.fromEntries(target.fields.map(field => [field.name, fieldSchema(field)]))\n },\n sources: {\n type: 'array',\n description: 'Where this row came from: the attachment id and where in it (\"row 3\", \"the receipt photo\"), or where: \"the person\\'s message\".',\n items: { type: 'object', properties: { attachmentId: { type: 'string' }, where: { type: 'string' } } }\n }\n },\n required: ['values', 'sources']\n }\n },\n note: { type: 'string', description: 'One line for the card - what this set is (\"September card statement\").' },\n declaredTotal: {\n type: 'object',\n description: 'The total the material itself prints, when it prints one - the card compares it with the sum of the rows. Never compute it yourself.',\n properties: {\n field: { type: 'string', description: `Which field it totals${target.fields.filter(field => field.total).length ? ` (${target.fields.filter(field => field.total).map(field => field.name).join(', ')})` : ''}.` },\n value: { type: ['number', 'string'] },\n attachmentId: { type: 'string' },\n where: { type: 'string' }\n }\n }\n },\n required: ['rows']\n },\n builder: (args: any, context: any) => proposeEntries(target, args, context)\n } as ToolSpec\n\n return {\n name: entryCategoryName(target.key),\n description: `data entry: ${target.key}`,\n guidance: [\n `- When the person gives material to enter as records (files, photos, pasted text), read all of it first - call readChatAttachment for a file sent in an earlier turn - then call ${name} once with every record as a row.`,\n '- Never invent a value. Leave a field out when the material does not say it; the card marks it, and you ask the person for it.',\n '- Give each row its sources: which attachment and where in it. A value the person gave or corrected in the conversation adds the source where: \"the person\\'s message\". The server looks for each row\\'s numbers and dates in the cited file and marks what it does not find.',\n '- When the material prints a total, pass it as declaredTotal exactly as printed - do not add it up yourself.',\n `- ${name} only proposes. Nothing is entered until the person presses the button on the card - never say the records were entered.`,\n `- When the person corrects or drops rows, call ${name} again with the whole corrected set. The newest card replaces the earlier ones; an earlier card can no longer be entered.`,\n ...(target.update\n ? [\n `- To change records that exist, call ${changeToolName(target.key)}. Use ref \"current\" for the record on screen and \"selected\" for the rows selected there.${target.update.find ? ` Otherwise call ${findToolName(target.key)} first with what the person said; if more than one record matches, list them and ask which - never pick one yourself.` : ' Otherwise ask the person to open or select the record.'}`,\n `- ${changeToolName(target.key)} only proposes; the card shows each record's value now and after. Never say a record was changed.`\n ]\n : [])\n ].join('\\n'),\n specs: [spec, ...changeSpecs(target, run)]\n }\n}\n\n/**\n * What an application calls at boot to let the assistant enter one of its records.\n *\n * A mode opens it by naming the key in `entryTargets` (the tool is not in every conversation of the app).\n */\nexport function registerEntryTarget(target: EntryTarget): void {\n declareEntryTarget(target)\n registerToolCategory(entryCategoryOf(target))\n}\n"]}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { type EntryField, type EntryIssue, type EntryRecord, type EntryTarget } from './entry-target.js';
|
|
2
|
+
/** Runs one of the application's queries or mutations as the person. */
|
|
3
|
+
export type GraphqlRunner = (document: string, variables: Record<string, unknown>) => Promise<{
|
|
4
|
+
data?: any;
|
|
5
|
+
errors?: readonly {
|
|
6
|
+
message: string;
|
|
7
|
+
}[];
|
|
8
|
+
}>;
|
|
9
|
+
/** How the record of a change was picked - said on the card, so the person sees the ground of it. */
|
|
10
|
+
export type ChangeVia = 'current' | 'selected' | 'id';
|
|
11
|
+
export interface ChangeRow {
|
|
12
|
+
index: number;
|
|
13
|
+
id: string;
|
|
14
|
+
via: ChangeVia;
|
|
15
|
+
label?: string;
|
|
16
|
+
/** What the record holds now, for the fields that change - read by the server. */
|
|
17
|
+
before: Record<string, unknown>;
|
|
18
|
+
values: Record<string, unknown>;
|
|
19
|
+
issues: EntryIssue[];
|
|
20
|
+
}
|
|
21
|
+
export declare const MAX_CHANGES = 100;
|
|
22
|
+
/** The fields a target lets change. */
|
|
23
|
+
export declare function changeableFields(target: EntryTarget): EntryField[];
|
|
24
|
+
/**
|
|
25
|
+
* The records the changes name. `current` is the record on screen, `selected` every row selected there -
|
|
26
|
+
* both from the surface's host context, which is **not trusted**: an id from it is only a candidate, read
|
|
27
|
+
* through the application before anything is shown. Any other ref is an id, from the find tool.
|
|
28
|
+
*/
|
|
29
|
+
export declare function resolveChangeRefs(targetKey: string, changes: unknown, host: Record<string, any> | undefined): {
|
|
30
|
+
picked: {
|
|
31
|
+
id: string;
|
|
32
|
+
via: ChangeVia;
|
|
33
|
+
values: Record<string, unknown>;
|
|
34
|
+
}[];
|
|
35
|
+
unresolved: string[];
|
|
36
|
+
};
|
|
37
|
+
/** Reads the records by id through the application's read query, as the person. */
|
|
38
|
+
export declare function readRecords(target: EntryTarget, ids: string[], run: GraphqlRunner): Promise<Map<string, EntryRecord>>;
|
|
39
|
+
/** The change rows against what the records hold now. */
|
|
40
|
+
export declare function changeRows(target: EntryTarget, picked: {
|
|
41
|
+
id: string;
|
|
42
|
+
via: ChangeVia;
|
|
43
|
+
values: Record<string, unknown>;
|
|
44
|
+
}[], records: Map<string, EntryRecord>): ChangeRow[];
|
|
45
|
+
export declare function proposeChanges(target: EntryTarget, args: any, context: any, run: GraphqlRunner): Promise<{
|
|
46
|
+
rejected: boolean;
|
|
47
|
+
error: string;
|
|
48
|
+
message: string;
|
|
49
|
+
} | {
|
|
50
|
+
message: string;
|
|
51
|
+
reason?: any;
|
|
52
|
+
proposed: boolean;
|
|
53
|
+
kind: string;
|
|
54
|
+
op: string;
|
|
55
|
+
target: string;
|
|
56
|
+
labelKey: string;
|
|
57
|
+
label: string;
|
|
58
|
+
icon: string;
|
|
59
|
+
columns: {
|
|
60
|
+
labelKey?: string;
|
|
61
|
+
name: string;
|
|
62
|
+
type: import("./entry-target.js").EntryFieldType;
|
|
63
|
+
}[];
|
|
64
|
+
rows: ChangeRow[];
|
|
65
|
+
counts: {
|
|
66
|
+
rows: number;
|
|
67
|
+
ready: number;
|
|
68
|
+
blocked: number;
|
|
69
|
+
cut: number;
|
|
70
|
+
};
|
|
71
|
+
rejected?: undefined;
|
|
72
|
+
error?: undefined;
|
|
73
|
+
}>;
|
|
74
|
+
export declare const MAX_CANDIDATES = 20;
|
|
75
|
+
/** Candidates for what the person described - the model lists them and asks when there is more than one. */
|
|
76
|
+
export declare function findRecords(target: EntryTarget, args: any, run: GraphqlRunner): Promise<{
|
|
77
|
+
rejected: boolean;
|
|
78
|
+
error: string;
|
|
79
|
+
message: string;
|
|
80
|
+
total?: undefined;
|
|
81
|
+
candidates?: undefined;
|
|
82
|
+
} | {
|
|
83
|
+
total: number;
|
|
84
|
+
candidates: {
|
|
85
|
+
record: EntryRecord;
|
|
86
|
+
label?: string;
|
|
87
|
+
id: string;
|
|
88
|
+
}[];
|
|
89
|
+
message: string;
|
|
90
|
+
rejected?: undefined;
|
|
91
|
+
error?: undefined;
|
|
92
|
+
}>;
|
|
93
|
+
/**
|
|
94
|
+
* The rows of a pressed 수정안, against what the records hold now. A row whose field moved since the card was
|
|
95
|
+
* made is kept out as `changed-since` - it is not overwritten unseen.
|
|
96
|
+
*/
|
|
97
|
+
export declare function stillAsProposed(target: EntryTarget, rows: ChangeRow[], now: Map<string, EntryRecord>): (ChangeRow & {
|
|
98
|
+
now?: EntryRecord;
|
|
99
|
+
})[];
|