@things-factory/ai-assistant 10.1.213 → 10.1.215

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.
Files changed (89) hide show
  1. package/client/components/assistant-dock.ts +6 -3
  2. package/client/components/assistant-selection-bar.test.ts +42 -0
  3. package/client/components/assistant-selection-bar.ts +129 -0
  4. package/client/components/assistant-session-manager.ts +263 -12
  5. package/client/index.ts +2 -0
  6. package/client/utils/assistant-selection.test.ts +25 -1
  7. package/client/utils/assistant-selection.ts +27 -0
  8. package/client/utils/assistant-session-actions.ts +12 -0
  9. package/client/utils/assistant-session-admin.ts +70 -5
  10. package/dist-client/components/assistant-dock.js +6 -3
  11. package/dist-client/components/assistant-dock.js.map +1 -1
  12. package/dist-client/components/assistant-selection-bar.d.ts +44 -0
  13. package/dist-client/components/assistant-selection-bar.js +149 -0
  14. package/dist-client/components/assistant-selection-bar.js.map +1 -0
  15. package/dist-client/components/assistant-selection-bar.test.d.ts +1 -0
  16. package/dist-client/components/assistant-selection-bar.test.js +38 -0
  17. package/dist-client/components/assistant-selection-bar.test.js.map +1 -0
  18. package/dist-client/components/assistant-session-manager.d.ts +37 -0
  19. package/dist-client/components/assistant-session-manager.js +281 -13
  20. package/dist-client/components/assistant-session-manager.js.map +1 -1
  21. package/dist-client/index.d.ts +1 -0
  22. package/dist-client/index.js +2 -0
  23. package/dist-client/index.js.map +1 -1
  24. package/dist-client/tsconfig.tsbuildinfo +1 -1
  25. package/dist-client/utils/assistant-selection.d.ts +24 -0
  26. package/dist-client/utils/assistant-selection.js +24 -0
  27. package/dist-client/utils/assistant-selection.js.map +1 -1
  28. package/dist-client/utils/assistant-selection.test.js +21 -1
  29. package/dist-client/utils/assistant-selection.test.js.map +1 -1
  30. package/dist-client/utils/assistant-session-actions.d.ts +15 -0
  31. package/dist-client/utils/assistant-session-actions.js +11 -0
  32. package/dist-client/utils/assistant-session-actions.js.map +1 -1
  33. package/dist-client/utils/assistant-session-admin.d.ts +32 -1
  34. package/dist-client/utils/assistant-session-admin.js +36 -5
  35. package/dist-client/utils/assistant-session-admin.js.map +1 -1
  36. package/dist-server/service/assistant-chat-resolver.js +6 -4
  37. package/dist-server/service/assistant-chat-resolver.js.map +1 -1
  38. package/dist-server/service/assistant-mode/index.d.ts +1 -1
  39. package/dist-server/service/assistant-mode/index.js +2 -1
  40. package/dist-server/service/assistant-mode/index.js.map +1 -1
  41. package/dist-server/service/assistant-mode/mode-categories.d.ts +30 -0
  42. package/dist-server/service/assistant-mode/mode-categories.js +35 -2
  43. package/dist-server/service/assistant-mode/mode-categories.js.map +1 -1
  44. package/dist-server/service/chat-session/session-cleanup.d.ts +28 -0
  45. package/dist-server/service/chat-session/session-cleanup.js +69 -0
  46. package/dist-server/service/chat-session/session-cleanup.js.map +1 -0
  47. package/dist-server/service/chat-session/session-inbox.d.ts +15 -0
  48. package/dist-server/service/chat-session/session-inbox.js +11 -0
  49. package/dist-server/service/chat-session/session-inbox.js.map +1 -1
  50. package/dist-server/service/chat-session/session-purge.d.ts +4 -0
  51. package/dist-server/service/chat-session/session-purge.js +45 -11
  52. package/dist-server/service/chat-session/session-purge.js.map +1 -1
  53. package/dist-server/service/chat-session-resolver.d.ts +24 -2
  54. package/dist-server/service/chat-session-resolver.js +193 -13
  55. package/dist-server/service/chat-session-resolver.js.map +1 -1
  56. package/dist-server/service/data-read/list-read.d.ts +3 -1
  57. package/dist-server/service/data-read/list-read.js +27 -2
  58. package/dist-server/service/data-read/list-read.js.map +1 -1
  59. package/dist-server/service/data-read/read-target.d.ts +16 -0
  60. package/dist-server/service/data-read/read-target.js +18 -1
  61. package/dist-server/service/data-read/read-target.js.map +1 -1
  62. package/dist-server/service/data-read/read-tools.js +3 -1
  63. package/dist-server/service/data-read/read-tools.js.map +1 -1
  64. package/dist-server/tsconfig.tsbuildinfo +1 -1
  65. package/package.json +6 -6
  66. package/server/service/assistant-chat-resolver.ts +7 -5
  67. package/server/service/assistant-mode/conversation-category.test.ts +15 -2
  68. package/server/service/assistant-mode/index.ts +1 -1
  69. package/server/service/assistant-mode/mode-categories.ts +48 -2
  70. package/server/service/assistant-mode/mode-front.test.ts +27 -1
  71. package/server/service/assistant-mode/open-subject-door.test.ts +3 -1
  72. package/server/service/chat-session/session-cleanup.test.ts +83 -0
  73. package/server/service/chat-session/session-cleanup.ts +69 -0
  74. package/server/service/chat-session/session-inbox.ts +13 -0
  75. package/server/service/chat-session/session-purge.ts +46 -10
  76. package/server/service/chat-session-resolver.ts +150 -14
  77. package/server/service/data-read/list-read.ts +30 -3
  78. package/server/service/data-read/list-status.test.ts +46 -0
  79. package/server/service/data-read/read-target.ts +32 -1
  80. package/server/service/data-read/read-tools.ts +2 -1
  81. package/test/assistant-dock.test.ts +12 -1
  82. package/test/assistant-session-manager.test.ts +53 -1
  83. package/test/open-doors.test.ts +3 -1
  84. package/translations/en.json +45 -2
  85. package/translations/es.json +45 -2
  86. package/translations/ja.json +45 -2
  87. package/translations/ko.json +45 -2
  88. package/translations/ms.json +45 -2
  89. package/translations/zh.json +45 -2
@@ -22,10 +22,34 @@ function listReadTarget(list) {
22
22
  ? [{ name: 'flow', type: 'enum', values: ['INCOME', 'EXPENSE'], labelKey: 'ai-assistant.read.flow', description: 'money in or out', filter: (v) => ({ name: narrowing.flow, operator: 'eq', value: v }) }]
23
23
  : []),
24
24
  ...(list.monthField
25
- ? [{ name: 'period', type: 'string', labelKey: 'ai-assistant.read.period', description: 'a month as YYYY-MM', filter: (v) => ({ name: list.monthField, operator: 'eq', value: v }) }]
25
+ ? [
26
+ { name: 'period', type: 'string', format: 'month', labelKey: 'ai-assistant.read.period', description: 'a month as YYYY-MM', filter: (v) => ({ name: list.monthField, operator: 'eq', value: v }) },
27
+ /* A range of months - "the last six months" of a list kept by month (2026-10-25: only one fixed month could be read). */
28
+ { name: 'periodFrom', type: 'string', format: 'month', labelKey: 'ai-assistant.read.period-from', description: 'the first month, inclusive, as YYYY-MM', filter: (v) => ({ name: list.monthField, operator: 'gte', value: v }) },
29
+ { name: 'periodTo', type: 'string', format: 'month', labelKey: 'ai-assistant.read.period-to', description: 'the last month, inclusive, as YYYY-MM', filter: (v) => ({ name: list.monthField, operator: 'lte', value: v }) }
30
+ ]
26
31
  : []),
27
32
  ...(list.status
28
- ? [{ name: 'status', type: 'enum', values: list.status.values, labelKey: 'ai-assistant.read.status', filter: (v) => ({ name: list.status.field, operator: 'eq', value: v }) }]
33
+ ? [
34
+ {
35
+ name: 'status',
36
+ type: 'enum',
37
+ values: list.status.values,
38
+ many: true,
39
+ labelKey: 'ai-assistant.read.status',
40
+ description: 'the statuses to read',
41
+ filter: (v) => (Array.isArray(v) && v.length > 1 ? { name: list.status.field, operator: 'in', value: v } : { name: list.status.field, operator: 'eq', value: [v].flat()[0] })
42
+ },
43
+ {
44
+ name: 'statusNot',
45
+ type: 'enum',
46
+ values: list.status.values,
47
+ many: true,
48
+ labelKey: 'ai-assistant.read.status-not',
49
+ description: 'the statuses to leave out - every other status is read',
50
+ filter: (v) => ({ name: list.status.field, operator: 'notin', value: [v].flat() })
51
+ }
52
+ ]
29
53
  : []),
30
54
  ...(list.missing?.length
31
55
  ? [
@@ -58,6 +82,7 @@ function listReadTarget(list) {
58
82
  criteria,
59
83
  ...(list.fixedFilters?.length ? { fixedFilters: list.fixedFilters } : {}),
60
84
  columns: list.columns,
85
+ ...(list.mine ? { mine: true } : {}),
61
86
  rowsOf: data => ({ rows: data?.[list.listQuery]?.items ?? [], total: data?.[list.listQuery]?.total ?? 0 }),
62
87
  ...(search ? { search: { description: `the ${list.search}` } } : {}),
63
88
  ...(list.dateField ? { sortings: [{ name: list.dateField, desc: true }] } : {}),
@@ -1 +1 @@
1
- {"version":3,"file":"list-read.js","sourceRoot":"","sources":["../../../server/service/data-read/list-read.ts"],"names":[],"mappings":";;AA8CA,wCAwEC;AA3ED,qHAAqH;AACrH,MAAM,QAAQ,GAAG,CAAC,IAAc,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI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I,EAAE,IAAI,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAC/E,GAAG,CAAC,IAAI,CAAC,KAAK;YACZ,CAAC,CAAC;gBACE,MAAM,EAAE;oBACN,KAAK,EAAE,IAAI,CAAC,KAAK;oBACjB,QAAQ,EAAE,IAAI,CAAC,KAAK;oBACpB,KAAK;oBACL,UAAU,EAAE,CAAC,CAAC,IAAI,CAAC,WAAW;oBAC9B,MAAM,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE,CAAC;iBACnB;aACF;YACH,CAAC,CAAC,EAAE,CAAC;KACR,CAAA;AACH,CAAC","sourcesContent":["/*\n * A list declared in one line (operato-application/design/ai/read-targets.md §3) - the shape most list screens share:\n * a ListParam query, the fields it reads, a date to range over, a status, an amount, search words, and a screen.\n * Each application writes its lists as these lines; this turns one into a read target with the conditions it takes.\n */\nimport type { ReadColumn, ReadCriterion, ReadFilter, ReadTarget } from './read-target.js'\n\nexport interface ListRead {\n /** `<app>.<record>`. */\n key: string\n /** i18n key of the screen's title - the card's name. */\n title: string\n /** The screen's name as the person knows it - the model picks the list by it. */\n name: string\n /** The ListParam query (`transactions`). */\n listQuery: string\n /** Filters every read applies, out of the model's reach - the records the list is of (`category` CONFIRMED). */\n fixedFilters?: ReadFilter[]\n /** The fields of each item it reads - the screen's own selection where there is one. */\n selection: string\n columns: ReadColumn[]\n /** A date (or date-time) field the `from` / `to` conditions range over. */\n dateField?: string\n /** Integer year and month fields, and an in/out field (INCOME | EXPENSE) - the `year`, `month`, `flow` conditions. */\n narrowing?: { year?: string; month?: string; flow?: string }\n /** A field holding the period as YYYY-MM - the `period` condition. */\n monthField?: string\n /** A status field and its values - the `status` condition. */\n status?: { field: string; values: string[] }\n /** The resolver's searchables, said for the model - the list takes ListParam search (the `text` condition). */\n search?: string\n /** The screen's route. Left out, the list has no screen card. */\n route?: string\n /** The route has a URL-bound grid. Otherwise conditions are disclosed as not applied on its screen card. */\n screenQuery?: boolean\n /**\n * What a row may be missing - the screen's own \"no counterparty\", \"no account subject\" filters - the `missing`\n * condition. Asked to fill the bank lines' unregistered parties, the model had no way to say \"unregistered\" and\n * searched the asker's own name (2026-10-24).\n */\n missing?: { name: string; description: string; filters: ReadFilter[] }[]\n}\n\n/** The money column a minimum or maximum amount means - `amount` when there is one, else the first summed column. */\nconst amountOf = (list: ListRead) => list.columns.find(one => one.name === 'amount' && one.type === 'number')?.name ?? list.columns.find(one => one.total)?.name\n\nexport function listReadTarget(list: ListRead): ReadTarget {\n const search = !!list.search\n const amount = amountOf(list)\n /* A bound compares the stored number - in each row's own currency when the column has one. */\n const inCurrency = list.columns.find(one => one.name === amount)?.currency ? `, compared in each row's own ${list.columns.find(one => one.name === amount)!.currency} - a row in another currency is held to the same number` : ''\n const narrowing = list.narrowing ?? {}\n const criteria: ReadCriterion[] = [\n ...(list.dateField\n ? [\n { name: 'from', type: 'date', labelKey: 'ai-assistant.read.from', description: `the first ${list.dateField}, inclusive`, filter: (v: any) => ({ name: list.dateField!, operator: 'gte', value: v }) },\n { name: 'to', type: 'date', labelKey: 'ai-assistant.read.to', description: `the last ${list.dateField}, inclusive`, filter: (v: any) => ({ name: list.dateField!, operator: 'lte', value: `${v}${/T/.test(String(v)) ? '' : 'T23:59:59.999'}` }) }\n ]\n : []),\n ...(narrowing.year ? [{ name: 'year', type: 'integer', labelKey: 'ai-assistant.read.year', description: 'a year (2026)', filter: (v: any) => ({ name: narrowing.year!, operator: 'eq', value: v }) }] : []),\n ...(narrowing.month ? [{ name: 'month', type: 'integer', labelKey: 'ai-assistant.read.month', description: '1-12, with a year', filter: (v: any) => ({ name: narrowing.month!, operator: 'eq', value: v }) }] : []),\n ...(narrowing.flow\n ? [{ name: 'flow', type: 'enum', values: ['INCOME', 'EXPENSE'], labelKey: 'ai-assistant.read.flow', description: 'money in or out', filter: (v: any) => ({ name: narrowing.flow!, operator: 'eq', value: v }) }]\n : []),\n ...(list.monthField\n ? [{ name: 'period', type: 'string', labelKey: 'ai-assistant.read.period', description: 'a month as YYYY-MM', filter: (v: any) => ({ name: list.monthField!, operator: 'eq', value: v }) }]\n : []),\n ...(list.status\n ? [{ name: 'status', type: 'enum', values: list.status.values, labelKey: 'ai-assistant.read.status', filter: (v: any) => ({ name: list.status!.field, operator: 'eq', value: v }) }]\n : []),\n ...(list.missing?.length\n ? [\n {\n name: 'missing',\n type: 'enum',\n values: list.missing.map(one => one.name),\n labelKey: 'ai-assistant.read.missing',\n description: `the rows missing one thing: ${list.missing.map(one => `${one.name} - ${one.description}`).join('; ')}`,\n filter: (v: any) => list.missing!.find(one => one.name === v)!.filters\n }\n ]\n : []),\n ...(amount\n ? [\n { name: 'minAmount', type: 'number', labelKey: 'ai-assistant.read.min-amount', description: `at least this ${amount}${inCurrency}`, filter: (v: any) => ({ name: amount, operator: 'gte', value: v }) },\n { name: 'maxAmount', type: 'number', labelKey: 'ai-assistant.read.max-amount', description: `at most this ${amount}${inCurrency}`, filter: (v: any) => ({ name: amount, operator: 'lte', value: v }) }\n ]\n : [])\n ] as ReadCriterion[]\n\n const takes = list.screenQuery\n ? ['id', ...criteria.map(criterion => criterion.name), ...(search ? ['text'] : [])]\n : []\n return {\n key: list.key,\n labelKey: list.title,\n description: `the rows of the list 「${list.name}」 (${list.columns.map(one => one.name).join(', ')}).`,\n query:\n `query ($filters: [Filter!], $pagination: Pagination, $sortings: [Sorting!]${search ? ', $search: String' : ''}) ` +\n `{ ${list.listQuery}(filters: $filters, pagination: $pagination, sortings: $sortings${search ? ', search: $search' : ''}) { items { ${list.selection} } total } }`,\n criteria,\n ...(list.fixedFilters?.length ? { fixedFilters: list.fixedFilters } : {}),\n columns: list.columns,\n rowsOf: data => ({ rows: data?.[list.listQuery]?.items ?? [], total: data?.[list.listQuery]?.total ?? 0 }),\n ...(search ? { search: { description: `the ${list.search}` } } : {}),\n ...(list.dateField ? { sortings: [{ name: list.dateField, desc: true }] } : {}),\n ...(list.route\n ? {\n screen: {\n route: list.route,\n labelKey: list.title,\n takes,\n queryState: !!list.screenQuery,\n params: () => ({})\n }\n }\n : {})\n }\n}\n"]}
1
+ {"version":3,"file":"list-read.js","sourceRoot":"","sources":["../../../server/service/data-read/list-read.ts"],"names":[],"mappings":";;AAgDA,wCAiGC;AApGD,qHAAqH;AACrH,MAAM,QAAQ,GAAG,CAAC,IAAc,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,IAAI,KAAK,QAAQ,IAAI,GAAG,CAAC,IAAI,KAAK,QAAQ,CAAC,EAAE,IAAI,IAAI,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,IAAI,CAAA;AAEhK,SAAgB,cAAc,CAAC,IAAc;IAC3C,MAAM,MAAM,GAAG,CAAC,CAAC,IAAI,CAAC,MAAM,CAAA;IAC5B,MAAM,MAAM,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAA;IAC7B,8FAA8F;IAC9F,MAAM,UAAU,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,IAAI,KAAK,MAAM,CAAC,EAAE,QAAQ,CAAC,CAAC,CAAC,gCAAgC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,IAAI,KAAK,MAAM,CAAE,CAAC,QAAQ,yDAAyD,CAAC,CAAC,CAAC,EAAE,CAAA;IAClO,MAAM,SAAS,GAAG,IAAI,CAAC,SAAS,IAAI,EAAE,CAAA;IACtC,MAAM,QAAQ,GAAoB;QAChC,GAAG,CAAC,IAAI,CAAC,SAAS;YAChB,CAAC,CAAC;gBACE,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,wBAAwB,EAAE,WAAW,EAAE,aAAa,IAAI,CAAC,SAAS,aAAa,EAAE,MAA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,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,KAAK,IAAI,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,KAAK,IAAI,CAAC,EAAE,CAAC;QAC1G,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,WAAW,EAAE,OAAO,IAAI,CAAC,MAAM,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACpE,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAC/E,GAAG,CAAC,IAAI,CAAC,KAAK;YACZ,CAAC,CAAC;gBACE,MAAM,EAAE;oBACN,KAAK,EAAE,IAAI,CAAC,KAAK;oBACjB,QAAQ,EAAE,IAAI,CAAC,KAAK;oBACpB,KAAK;oBACL,UAAU,EAAE,CAAC,CAAC,IAAI,CAAC,WAAW;oBAC9B,MAAM,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE,CAAC;iBACnB;aACF;YACH,CAAC,CAAC,EAAE,CAAC;KACR,CAAA;AACH,CAAC","sourcesContent":["/*\n * A list declared in one line (operato-application/design/ai/read-targets.md §3) - the shape most list screens share:\n * a ListParam query, the fields it reads, a date to range over, a status, an amount, search words, and a screen.\n * Each application writes its lists as these lines; this turns one into a read target with the conditions it takes.\n */\nimport type { ReadColumn, ReadCriterion, ReadFilter, ReadTarget } from './read-target.js'\n\nexport interface ListRead {\n /** `<app>.<record>`. */\n key: string\n /** i18n key of the screen's title - the card's name. */\n title: string\n /** The screen's name as the person knows it - the model picks the list by it. */\n name: string\n /** The ListParam query (`transactions`). */\n listQuery: string\n /** Filters every read applies, out of the model's reach - the records the list is of (`category` CONFIRMED). */\n fixedFilters?: ReadFilter[]\n /** The fields of each item it reads - the screen's own selection where there is one. */\n selection: string\n columns: ReadColumn[]\n /** A date (or date-time) field the `from` / `to` conditions range over. */\n dateField?: string\n /** Integer year and month fields, and an in/out field (INCOME | EXPENSE) - the `year`, `month`, `flow` conditions. */\n narrowing?: { year?: string; month?: string; flow?: string }\n /** A field holding the period as YYYY-MM - the `period` condition, and `periodFrom` / `periodTo` for a range of months. */\n monthField?: string\n /** A status field and its values - the `status` condition. */\n status?: { field: string; values: string[] }\n /** The resolver's searchables, said for the model - the list takes ListParam search (the `text` condition). */\n search?: string\n /** The screen's route. Left out, the list has no screen card. */\n route?: string\n /** The route has a URL-bound grid. Otherwise conditions are disclosed as not applied on its screen card. */\n screenQuery?: boolean\n /**\n * What a row may be missing - the screen's own \"no counterparty\", \"no account subject\" filters - the `missing`\n * condition. Asked to fill the bank lines' unregistered parties, the model had no way to say \"unregistered\" and\n * searched the asker's own name (2026-10-24).\n */\n missing?: { name: string; description: string; filters: ReadFilter[] }[]\n /** The rows are the person's own, whoever reads them (`myExpenditureRequests`) - ReadTarget.mine. */\n mine?: boolean\n}\n\n/** The money column a minimum or maximum amount means - `amount` when there is one, else the first summed column. */\nconst amountOf = (list: ListRead) => list.columns.find(one => one.name === 'amount' && one.type === 'number')?.name ?? list.columns.find(one => one.total)?.name\n\nexport function listReadTarget(list: ListRead): ReadTarget {\n const search = !!list.search\n const amount = amountOf(list)\n /* A bound compares the stored number - in each row's own currency when the column has one. */\n const inCurrency = list.columns.find(one => one.name === amount)?.currency ? `, compared in each row's own ${list.columns.find(one => one.name === amount)!.currency} - a row in another currency is held to the same number` : ''\n const narrowing = list.narrowing ?? {}\n const criteria: ReadCriterion[] = [\n ...(list.dateField\n ? [\n { name: 'from', type: 'date', labelKey: 'ai-assistant.read.from', description: `the first ${list.dateField}, inclusive`, filter: (v: any) => ({ name: list.dateField!, operator: 'gte', value: v }) },\n { name: 'to', type: 'date', labelKey: 'ai-assistant.read.to', description: `the last ${list.dateField}, inclusive`, filter: (v: any) => ({ name: list.dateField!, operator: 'lte', value: `${v}${/T/.test(String(v)) ? '' : 'T23:59:59.999'}` }) }\n ]\n : []),\n ...(narrowing.year ? [{ name: 'year', type: 'integer', labelKey: 'ai-assistant.read.year', description: 'a year (2026)', filter: (v: any) => ({ name: narrowing.year!, operator: 'eq', value: v }) }] : []),\n ...(narrowing.month ? [{ name: 'month', type: 'integer', labelKey: 'ai-assistant.read.month', description: '1-12, with a year', filter: (v: any) => ({ name: narrowing.month!, operator: 'eq', value: v }) }] : []),\n ...(narrowing.flow\n ? [{ name: 'flow', type: 'enum', values: ['INCOME', 'EXPENSE'], labelKey: 'ai-assistant.read.flow', description: 'money in or out', filter: (v: any) => ({ name: narrowing.flow!, operator: 'eq', value: v }) }]\n : []),\n ...(list.monthField\n ? [\n { name: 'period', type: 'string', format: 'month', labelKey: 'ai-assistant.read.period', description: 'a month as YYYY-MM', filter: (v: any) => ({ name: list.monthField!, operator: 'eq', value: v }) },\n /* A range of months - \"the last six months\" of a list kept by month (2026-10-25: only one fixed month could be read). */\n { name: 'periodFrom', type: 'string', format: 'month', labelKey: 'ai-assistant.read.period-from', description: 'the first month, inclusive, as YYYY-MM', filter: (v: any) => ({ name: list.monthField!, operator: 'gte', value: v }) },\n { name: 'periodTo', type: 'string', format: 'month', labelKey: 'ai-assistant.read.period-to', description: 'the last month, inclusive, as YYYY-MM', filter: (v: any) => ({ name: list.monthField!, operator: 'lte', value: v }) }\n ]\n : []),\n ...(list.status\n ? [\n {\n name: 'status',\n type: 'enum',\n values: list.status.values,\n many: true,\n labelKey: 'ai-assistant.read.status',\n description: 'the statuses to read',\n filter: (v: any) => (Array.isArray(v) && v.length > 1 ? { name: list.status!.field, operator: 'in', value: v } : { name: list.status!.field, operator: 'eq', value: [v].flat()[0] })\n },\n {\n name: 'statusNot',\n type: 'enum',\n values: list.status.values,\n many: true,\n labelKey: 'ai-assistant.read.status-not',\n description: 'the statuses to leave out - every other status is read',\n filter: (v: any) => ({ name: list.status!.field, operator: 'notin', value: [v].flat() })\n }\n ]\n : []),\n ...(list.missing?.length\n ? [\n {\n name: 'missing',\n type: 'enum',\n values: list.missing.map(one => one.name),\n labelKey: 'ai-assistant.read.missing',\n description: `the rows missing one thing: ${list.missing.map(one => `${one.name} - ${one.description}`).join('; ')}`,\n filter: (v: any) => list.missing!.find(one => one.name === v)!.filters\n }\n ]\n : []),\n ...(amount\n ? [\n { name: 'minAmount', type: 'number', labelKey: 'ai-assistant.read.min-amount', description: `at least this ${amount}${inCurrency}`, filter: (v: any) => ({ name: amount, operator: 'gte', value: v }) },\n { name: 'maxAmount', type: 'number', labelKey: 'ai-assistant.read.max-amount', description: `at most this ${amount}${inCurrency}`, filter: (v: any) => ({ name: amount, operator: 'lte', value: v }) }\n ]\n : [])\n ] as ReadCriterion[]\n\n const takes = list.screenQuery\n ? ['id', ...criteria.map(criterion => criterion.name), ...(search ? ['text'] : [])]\n : []\n return {\n key: list.key,\n labelKey: list.title,\n description: `the rows of the list 「${list.name}」 (${list.columns.map(one => one.name).join(', ')}).`,\n query:\n `query ($filters: [Filter!], $pagination: Pagination, $sortings: [Sorting!]${search ? ', $search: String' : ''}) ` +\n `{ ${list.listQuery}(filters: $filters, pagination: $pagination, sortings: $sortings${search ? ', search: $search' : ''}) { items { ${list.selection} } total } }`,\n criteria,\n ...(list.fixedFilters?.length ? { fixedFilters: list.fixedFilters } : {}),\n columns: list.columns,\n ...(list.mine ? { mine: true } : {}),\n rowsOf: data => ({ rows: data?.[list.listQuery]?.items ?? [], total: data?.[list.listQuery]?.total ?? 0 }),\n ...(search ? { search: { description: `the ${list.search}` } } : {}),\n ...(list.dateField ? { sortings: [{ name: list.dateField, desc: true }] } : {}),\n ...(list.route\n ? {\n screen: {\n route: list.route,\n labelKey: list.title,\n takes,\n queryState: !!list.screenQuery,\n params: () => ({})\n }\n }\n : {})\n }\n}\n"]}
@@ -8,6 +8,13 @@ export interface ReadFilter {
8
8
  /** A condition the model may set - read with the entry fields' rules, turned into the query's filters by the application. */
9
9
  export interface ReadCriterion extends Omit<EntryField, 'required' | 'reference' | 'total'> {
10
10
  filter: (value: any) => ReadFilter | ReadFilter[];
11
+ /** A string condition holding a month as YYYY-MM - a value of another shape is refused (`not-a-month`). */
12
+ format?: 'month';
13
+ /**
14
+ * The condition takes several values at once - its filter is given the list. Asked for the expenditure requests not
15
+ * approved, rejected or withdrawn, the model read the list once per status and stopped (2026-10-25).
16
+ */
17
+ many?: boolean;
11
18
  }
12
19
  export interface ReadColumn {
13
20
  /** The key in the workspace table. */
@@ -71,6 +78,11 @@ export interface ReadTarget {
71
78
  desc?: boolean;
72
79
  }[];
73
80
  screen?: ReadScreen;
81
+ /**
82
+ * The rows are the person's own, whoever reads them (내 지출결의) - the query answers for the one asking. A dashboard
83
+ * card of it shows each viewer their own rows and takes no filter on a person (ADR-0160).
84
+ */
85
+ mine?: boolean;
74
86
  }
75
87
  /** At most this many rows are read - the AI 작업판 table's own limit (workspace-blocks MAX_TABLE_ROWS). */
76
88
  export declare const MAX_READ_ROWS = 1000;
@@ -97,6 +109,8 @@ export interface DetailArg {
97
109
  required?: boolean;
98
110
  /** A record's id: the axis (or axes) of the record, whose key `<axis>:<id>` the model may have been shown (EntryField.axis). */
99
111
  axis?: string | readonly string[];
112
+ /** A string argument holding a month as YYYY-MM. */
113
+ format?: 'month';
100
114
  }
101
115
  /**
102
116
  * A query whose answer is one thing, not a list - a 360's summary, the receivables, a statement (design/ai/read-targets.md
@@ -123,6 +137,8 @@ export interface DetailRead {
123
137
  * (ADR-0160 decision 2). The card keeps only `key`; where the rows are and what their columns are is read here.
124
138
  */
125
139
  lists?: DetailList[];
140
+ /** The answer is the person's own, whoever asks (나의 전략 업무, 내 급여) - ReadTarget.mine. */
141
+ mine?: boolean;
126
142
  }
127
143
  /** A list inside a detail read's answer. */
128
144
  export interface DetailList {
@@ -152,6 +152,8 @@ function declareDetailRead(target) {
152
152
  function detailReadOf(key) {
153
153
  return key ? details.get(key) : undefined;
154
154
  }
155
+ /** A month as a `month` condition holds it. */
156
+ const MONTH = /^\d{4}-(0[1-9]|1[0-2])$/;
155
157
  /** The conditions the model set, read by their declared types; a value that does not fit is said, never guessed at. */
156
158
  function readCriteria(target, args) {
157
159
  const criteria = {};
@@ -163,11 +165,26 @@ function readCriteria(target, args) {
163
165
  criteria.text = args.text.trim();
164
166
  for (const criterion of target.criteria) {
165
167
  const value = args?.[criterion.name];
166
- if (value === undefined || value === null || value === '')
168
+ if (value === undefined || value === null || value === '' || (Array.isArray(value) && !value.length))
167
169
  continue;
170
+ if (criterion.many && Array.isArray(value)) {
171
+ const each = value.map(one => (0, entry_target_js_1.readFieldValue)(criterion, one));
172
+ const wrong = each.find(one => one.read === undefined);
173
+ if (wrong)
174
+ refused.push({ name: criterion.name, code: wrong.code ?? 'unreadable' });
175
+ else
176
+ criteria[criterion.name] = [...new Set(each.map(one => one.read))];
177
+ continue;
178
+ }
179
+ if (Array.isArray(value)) {
180
+ refused.push({ name: criterion.name, code: 'one-value' });
181
+ continue;
182
+ }
168
183
  const { read, code } = (0, entry_target_js_1.readFieldValue)(criterion, value);
169
184
  if (read === undefined)
170
185
  refused.push({ name: criterion.name, code: code ?? 'unreadable' });
186
+ else if (criterion.format === 'month' && !MONTH.test(String(read)))
187
+ refused.push({ name: criterion.name, code: 'not-a-month' });
171
188
  else
172
189
  criteria[criterion.name] = read;
173
190
  }
@@ -1 +1 @@
1
- {"version":3,"file":"read-target.js","sourceRoot":"","sources":["../../../server/service/data-read/read-target.ts"],"names":[],"mappings":";;;AAuHA,8CAgBC;AAED,oCAEC;AAGD,wCAEC;AAGD,wCAEC;AAED,4CAGC;AAmED,8CAuBC;AAED,oCAEC;AAGD,oCAcC;AAED,8BAOC;AAKD,sBAcC;AAMD,4BAkBC;AAiBD,wBAeC;AAGD,oCAIC;AAGD,4BAsBC;AAGD,sCAmBC;AAnZD;;;;;;;;;;GAUG;AACH,mEAA2G;AAC3G,gEAA8D;A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AAU,GAAG,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;IAC/G,MAAM,KAAK,GAAG,MAAM,CAAC,UAAU;QAC7B,CAAC,CAAC,IAAA,+BAAe,EAAC;YACd,OAAO,EAAE,SAAS,CAAC,MAAM,EAAE,UAAU,CAAC;YACtC,MAAM,EAAE,OAAO,UAAU,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS;YACzE,OAAO,EAAE,MAAM,CAAC,QAAQ;SACzB,CAAC;QACJ,CAAC,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAA;IACrB,OAAO;QACL,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,KAAK,IAAI,KAAK,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK;QACvD,OAAO,EAAE,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;QAC1D,UAAU,EAAE,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;KAC/D,CAAA;AACH,CAAC","sourcesContent":["/*\n * AI 조회 - an application's list, read through its own query as the person (operato-application/design/ai/read-targets.md).\n *\n * The application declares what it lets the assistant read: its list query, the conditions the model may set and\n * how each becomes one of the query's filters, the columns to show, and the screen that lists the same records.\n * The framework reads the rows through that query with the person's request state - the same @privilege and\n * domain as the screen - counts and sums them itself, and puts a long result on the AI 작업판 as the query returned\n * it. The model is told the count, the sums and a few rows; it never copies a table.\n *\n * Pure but for the GraphQL runner, which comes in as an argument - the rules are tested without a server.\n */\nimport { readFieldValue, recordIdOfKey, rootFieldOf, type EntryField } from '../data-entry/entry-target.js'\nimport { encodeListQuery } from '@operato/utils/list-query.js'\nimport type { GraphqlRunner } from '../data-entry/entry-update.js'\nimport { parse } from 'graphql'\n\nexport interface ReadFilter {\n name: string\n operator: string\n value: unknown\n}\n\n/** A condition the model may set - read with the entry fields' rules, turned into the query's filters by the application. */\nexport interface ReadCriterion extends Omit<EntryField, 'required' | 'reference' | 'total'> {\n filter: (value: any) => ReadFilter | ReadFilter[]\n}\n\nexport interface ReadColumn {\n /** The key in the workspace table. */\n name: string\n /** Where the value is in a row - a dotted path into the query's item (`account.name`). Defaults to `name`. */\n path?: string\n type: 'string' | 'number' | 'date'\n labelKey?: string\n /** A number column the server sums. */\n total?: boolean\n /**\n * The column that holds this amount's currency (ISO 4217, `KRW`). Its sums are kept per currency - amounts of two\n * currencies are never added into one number.\n */\n currency?: string\n}\n\nexport interface ReadScreen {\n /** A URL-bound grid accepts the same predicates used by readRows, including conditions outside its form. */\n queryState?: boolean\n /** The application's route of the list screen (`cash-transaction-list`). */\n route: string\n /** The conditions the screen takes, as its address's query arguments. A condition left out is said on the card. */\n params: (criteria: Record<string, any>) => Record<string, string | number | undefined>\n /** The conditions `params` carries - the card names the others as not applied on the screen. */\n takes: string[]\n labelKey?: string\n}\n\nexport interface ReadTarget {\n /** `<app>.<record>` - the tools are named after it. */\n key: string\n /** i18n key naming the records (「은행 입출금」). */\n labelKey?: string\n /** What the records are, for the model. */\n description: string\n /**\n * The list query - takes `$filters: [Filter!]`, `$pagination: Pagination` and `$sortings: [Sorting!]`, and\n * `$search: String` when `search` is declared.\n */\n query: string\n /**\n * The list takes ListParam's free-text term, matched by the resolver across its own searchable fields - the\n * condition `text`. Say what it finds in, for the model.\n */\n search?: { description: string }\n criteria: ReadCriterion[]\n /**\n * Filters every read of this list applies - the records it is of (a book's confirmed lines, not its forecasts). Not\n * a condition: the model neither sees nor sets them, so a read can narrow the list but never widen it.\n */\n fixedFilters?: ReadFilter[]\n columns: ReadColumn[]\n rowsOf: (data: any) => { rows: any[]; total: number }\n /** Orders the rows; the query's own order when left out. */\n sortings?: { name: string; desc?: boolean }[]\n screen?: ReadScreen\n}\n\n/** At most this many rows are read - the AI 작업판 table's own limit (workspace-blocks MAX_TABLE_ROWS). */\nexport const MAX_READ_ROWS = 1000\n/** Rows the model is shown; the rest stay on the card. */\nexport const ROWS_FOR_MODEL = 20\n/** A page of the list query. */\nexport const READ_PAGE = 200\n\nconst registry = new Map<string, ReadTarget>()\n\nconst pascalOf = (key: string) =>\n key\n .split(/[^a-zA-Z0-9]+/)\n .filter(Boolean)\n .map(part => part[0].toUpperCase() + part.slice(1))\n .join('')\n\nexport const queryToolName = (key: string) => `query${pascalOf(key)}`\nexport const screenToolName = (key: string) => `open${pascalOf(key)}Screen`\nexport const readCategoryName = (key: string) => `data-read:${key}`\n\n/** The columns of a list - shown, each named once, a currency only on a summed number and taken from a string column. */\nfunction checkColumns(of: string, columns: ReadColumn[]): void {\n if (!columns.length) throw new Error(`read target '${of}' shows no column`)\n const names = new Set<string>()\n for (const column of columns) {\n if (names.has(column.name)) throw new Error(`read target '${of}' names the column '${column.name}' twice`)\n names.add(column.name)\n }\n for (const column of columns.filter(one => one.currency)) {\n if (!column.total || column.type !== 'number') throw new Error(`column '${column.name}' of '${of}' names a currency but is not a summed number`)\n if (columns.find(one => one.name === column.currency)?.type !== 'string') throw new Error(`column '${column.name}' of '${of}' takes its currency from '${column.currency}', which is no string column`)\n }\n}\n\nexport function declareReadTarget(target: ReadTarget): void {\n if (!/^[a-z0-9-]+\\.[a-z0-9-]+$/.test(target.key)) throw new Error(`read target key '${target.key}' is not <app>.<record>`)\n if (registry.has(target.key) || details.has(target.key)) throw new Error(`read target '${target.key}' is declared twice`)\n rootFieldOf(target.query, 'query')\n checkColumns(target.key, target.columns)\n const names = new Set<string>(['id'])\n for (const criterion of target.criteria) {\n if (criterion.name === 'id') throw new Error(`read target '${target.key}' declares 'id' - every target takes it`)\n if (criterion.name === 'text' && target.search) throw new Error(`read target '${target.key}' declares 'text' and search - search is the text condition`)\n if (names.has(criterion.name)) throw new Error(`read target '${target.key}' names the condition '${criterion.name}' twice`)\n names.add(criterion.name)\n if (criterion.type === 'enum' && !criterion.values?.length) throw new Error(`condition '${criterion.name}' of '${target.key}' lists no values`)\n }\n if (target.search) names.add('text')\n for (const taken of target.screen?.takes ?? []) if (!names.has(taken)) throw new Error(`the screen of '${target.key}' takes '${taken}', which is no condition`)\n registry.set(target.key, target)\n}\n\nexport function readTargetOf(key: string | undefined): ReadTarget | undefined {\n return key ? registry.get(key) : undefined\n}\n\n/** Every list read target declared - what else reads the declarations (a dashboard card, ADR-0160) lists them by key. */\nexport function readTargetKeys(): string[] {\n return [...registry.keys()]\n}\n\n/** Every detail read declared. */\nexport function detailReadKeys(): string[] {\n return [...details.keys()]\n}\n\nexport function clearReadTargets(): void {\n registry.clear()\n details.clear()\n}\n\n/* ── One answer of a query ──────────────────────────────────────────────────────────────────────────────────── */\n\n/** An argument of a detail read - one variable of its query, read with the entry fields' rules. */\nexport interface DetailArg {\n name: string\n type: 'string' | 'integer' | 'number' | 'boolean' | 'date' | 'enum'\n values?: string[]\n description?: string\n required?: boolean\n /** A record's id: the axis (or axes) of the record, whose key `<axis>:<id>` the model may have been shown (EntryField.axis). */\n axis?: string | readonly string[]\n}\n\n/**\n * A query whose answer is one thing, not a list - a 360's summary, the receivables, a statement (design/ai/read-targets.md\n * §9). The application declares the query with the fields its screen reads; the framework runs it as the person, with\n * the arguments the model set, and hands the answer over as the query returned it. Nothing is summed or cut here: the\n * selection is the projection, and an answer too long to hand over is refused, never cut.\n */\nexport interface DetailRead {\n /** `<app>.<thing>` - the tool is named after it. */\n key: string\n labelKey?: string\n /** What it answers, for the model. */\n description: string\n /** One query with one root field. Its variables are the arguments - each declared in `args`. */\n query: string\n args?: DetailArg[]\n /**\n * The records the answer is about, whose screens put it in front (EntryTarget.axes) - the management check answers\n * for any ledger record; asked on a deposit's 360 why it was in the check, the model never opened it (2026-10-24).\n */\n axes?: string[]\n /**\n * The lists the answer holds, each a table of typed columns - what a dashboard card may draw from a one-answer read\n * (ADR-0160 decision 2). The card keeps only `key`; where the rows are and what their columns are is read here.\n */\n lists?: DetailList[]\n}\n\n/** A list inside a detail read's answer. */\nexport interface DetailList {\n /** A name stable within the read (`by-contract`) - what a card keeps. */\n key: string\n /** A dotted path inside the value of the query's root field (`rows`); '' when the root field is the list. */\n at: string\n labelKey?: string\n /** What the rows are, for the model. */\n description?: string\n columns: ReadColumn[]\n}\n\n/** Characters of an answer handed to the model - a longer one is refused, and the model narrows it. */\nexport const MAX_DETAIL_CHARS = 60_000\n\nconst details = new Map<string, DetailRead>()\n\nexport const detailToolName = (key: string) => `read${pascalOf(key)}`\n\n/** The variables a query declares, and whether each is required (`!`). */\nfunction variablesOf(document: string): { name: string; required: boolean }[] {\n const operation: any = parse(document).definitions.find((one: any) => one.kind === 'OperationDefinition')\n return (operation?.variableDefinitions ?? []).map((one: any) => ({ name: one.variable.name.value, required: one.type.kind === 'NonNullType' && !one.defaultValue }))\n}\n\nexport function declareDetailRead(target: DetailRead): void {\n if (!/^[a-z0-9-]+\\.[a-z0-9-]+$/.test(target.key)) throw new Error(`detail read key '${target.key}' is not <app>.<thing>`)\n if (details.has(target.key) || registry.has(target.key)) throw new Error(`read target '${target.key}' is declared twice`)\n rootFieldOf(target.query, 'query')\n const args = target.args ?? []\n for (const variable of variablesOf(target.query)) {\n const arg = args.find(one => one.name === variable.name)\n if (!arg) throw new Error(`detail read '${target.key}' takes $${variable.name}, which is no argument`)\n if (variable.required && !arg.required) throw new Error(`detail read '${target.key}': $${variable.name} is required by the query - declare it required`)\n }\n for (const arg of args) {\n if (!variablesOf(target.query).some(one => one.name === arg.name)) throw new Error(`detail read '${target.key}' declares '${arg.name}', which its query does not take`)\n if (arg.type === 'enum' && !arg.values?.length) throw new Error(`argument '${arg.name}' of '${target.key}' lists no values`)\n }\n const lists = new Set<string>()\n for (const list of target.lists ?? []) {\n if (!/^[a-z0-9-]+$/.test(list.key)) throw new Error(`list '${list.key}' of '${target.key}' is not a lowercase key`)\n if (lists.has(list.key)) throw new Error(`detail read '${target.key}' names the list '${list.key}' twice`)\n lists.add(list.key)\n if (!/^([A-Za-z0-9_]+(\\.[A-Za-z0-9_]+)*)?$/.test(list.at)) throw new Error(`list '${list.key}' of '${target.key}' is at '${list.at}', which is no dotted path`)\n checkColumns(`${target.key}/${list.key}`, list.columns)\n }\n details.set(target.key, target)\n}\n\nexport function detailReadOf(key: string | undefined): DetailRead | undefined {\n return key ? details.get(key) : undefined\n}\n\n/** The conditions the model set, read by their declared types; a value that does not fit is said, never guessed at. */\nexport function readCriteria(target: ReadTarget, args: any): { criteria: Record<string, unknown>; refused: { name: string; code: string }[] } {\n const criteria: Record<string, unknown> = {}\n const refused: { name: string; code: string }[] = []\n /* One record by its id - every target takes it (the id a list answer or a find tool gave, or the key `<axis>:<id>` an open record is shown by, the axis being the key's last part). */\n if (typeof args?.id === 'string' && args.id.trim()) criteria.id = recordIdOfKey(target.key.split('.').pop()!, args.id) ?? args.id.trim()\n if (target.search && typeof args?.text === 'string' && args.text.trim()) criteria.text = args.text.trim()\n for (const criterion of target.criteria) {\n const value = args?.[criterion.name]\n if (value === undefined || value === null || value === '') continue\n const { read, code } = readFieldValue(criterion as EntryField, value)\n if (read === undefined) refused.push({ name: criterion.name, code: code ?? 'unreadable' })\n else criteria[criterion.name] = read\n }\n return { criteria, refused }\n}\n\nexport function filtersOf(target: ReadTarget, criteria: Record<string, unknown>): ReadFilter[] {\n return [\n ...(typeof criteria.id === 'string' ? [{ name: 'id', operator: 'eq', value: criteria.id }] : []),\n ...target.criteria.flatMap(criterion =>\n criterion.name in criteria ? [criterion.filter(criteria[criterion.name])].flat() : []\n )\n ]\n}\n\nexport const valueAt = (row: any, path: string) => path.split('.').reduce((at, part) => (at === null || at === undefined ? undefined : at[part]), row)\n\n/** One row as the columns say - a number column as a number, a missing value as null. */\nexport function rowOf(target: Pick<ReadTarget, 'columns'>, item: any): Record<string, string | number | null> {\n return Object.fromEntries([\n /* The id names the record to the model - for one record's detail, a change, or its screen. */\n ...(item?.id ? [['id', String(item.id)] as [string, string]] : []),\n ...target.columns.map(column => {\n const raw = valueAt(item, column.path ?? column.name)\n if (raw === undefined || raw === null || raw === '') return [column.name, null]\n if (column.type === 'number') {\n const number = Number(raw)\n return [column.name, Number.isFinite(number) ? number : null]\n }\n return [column.name, String(raw)]\n })\n ])\n}\n\n/**\n * Reads the rows through the application's query, page by page, up to MAX_READ_ROWS. `complete` is false when the\n * list holds more - a sum of the rows read is then not the sum of the list, and is never said as one.\n */\nexport async function readRows(target: ReadTarget, filters: ReadFilter[], run: GraphqlRunner, search?: string): Promise<{ rows: Record<string, any>[]; total: number; complete: boolean }> {\n const rows: Record<string, any>[] = []\n let total = 0\n for (let page = 1; rows.length < MAX_READ_ROWS; page++) {\n const answer = await run(target.query, {\n filters: [...filters, ...(target.fixedFilters ?? [])],\n ...(search ? { search } : {}),\n pagination: { page, limit: READ_PAGE },\n ...(target.sortings ? { sortings: target.sortings } : {})\n })\n if (answer.errors?.length) throw new Error(answer.errors.map(one => one.message).join('; '))\n const read = target.rowsOf(answer.data)\n total = Number(read?.total) || 0\n const items = read?.rows ?? []\n rows.push(...items.slice(0, MAX_READ_ROWS - rows.length).map(item => rowOf(target, item)))\n if (items.length < READ_PAGE || rows.length >= total) break\n }\n return { rows, total, complete: rows.length >= total }\n}\n\n/** A column's sum - one number, or one per currency when the column names its currency (`{ KRW: 1000, USD: 100 }`). */\nexport type ReadSum = number | Record<string, number>\n\nexport interface ReadGroup {\n key: string\n count: number\n sums: Record<string, ReadSum>\n}\n\n/** The currency a row without one is summed under - said as it is, never taken for the domain's own. */\nexport const UNKNOWN_CURRENCY = 'unknown'\n\nconst sumOf = (rows: Record<string, any>[], name: string) => Math.round(rows.reduce((sum, row) => sum + (typeof row[name] === 'number' ? row[name] : 0), 0) * 100) / 100\n\n/** The sums of the number columns marked total - the server's, never the model's; a column with a currency per currency. */\nexport function sumsOf(target: Pick<ReadTarget, 'columns'>, rows: Record<string, any>[]): Record<string, ReadSum> {\n const sums: Record<string, ReadSum> = {}\n for (const column of target.columns.filter(one => one.total && one.type === 'number')) {\n if (!column.currency) {\n sums[column.name] = sumOf(rows, column.name)\n continue\n }\n const byCurrency = new Map<string, Record<string, any>[]>()\n for (const row of rows) {\n const code = typeof row[column.currency] === 'string' && row[column.currency] ? row[column.currency] : UNKNOWN_CURRENCY\n byCurrency.set(code, [...(byCurrency.get(code) ?? []), row])\n }\n sums[column.name] = Object.fromEntries([...byCurrency].sort(([a], [b]) => a.localeCompare(b)).map(([code, members]) => [code, sumOf(members, column.name)]))\n }\n return sums\n}\n\n/** The currencies a set of sums holds for one column - none for a column summed as one number. */\nexport function currenciesOf(sums: Record<string, ReadSum>[], column: string): string[] {\n const codes = new Set<string>()\n for (const one of sums) if (one[column] && typeof one[column] === 'object') for (const code of Object.keys(one[column] as object)) codes.add(code)\n return [...codes].sort()\n}\n\n/** The rows grouped by one column - a date column by its month - each with its count and sums, largest first. */\nexport function groupsOf(target: Pick<ReadTarget, 'columns'>, rows: Record<string, any>[], by: string): ReadGroup[] | undefined {\n const column = target.columns.find(one => one.name === by)\n if (!column) return undefined\n const groups = new Map<string, Record<string, any>[]>()\n for (const row of rows) {\n const value = row[by]\n const key = value === null || value === undefined ? '' : column.type === 'date' ? String(value).slice(0, 7) : String(value)\n groups.set(key, [...(groups.get(key) ?? []), row])\n }\n const list = [...groups].map(([key, members]) => ({ key, count: members.length, sums: sumsOf(target, members) }))\n if (column.type === 'date') return list.sort((a, b) => a.key.localeCompare(b.key))\n /* Largest first by the first sum - in its one currency; groups in two currencies have no common size, so by count. */\n const first = target.columns.find(one => one.total)?.name\n const codes = first ? currenciesOf(list.map(group => group.sums), first) : []\n const size = (group: ReadGroup) => {\n const sum = first ? group.sums[first] : undefined\n return typeof sum === 'number' ? Math.abs(sum) : codes.length === 1 && sum ? Math.abs(sum[codes[0]] ?? 0) : undefined\n }\n return list.sort((a, b) => {\n const [x, y] = [size(a), size(b)]\n return x !== undefined && y !== undefined && codes.length <= 1 ? y - x : b.count - a.count\n })\n}\n\n/** The address of the target's list screen with the conditions it takes, and the conditions it does not. */\nexport function screenAddress(target: ReadTarget, criteria: Record<string, unknown>): { href: string; applied: string[]; notApplied: string[] } | undefined {\n const screen = target.screen\n if (!screen) return undefined\n const params = new URLSearchParams()\n for (const [name, value] of Object.entries(screen.params(criteria))) if (value !== undefined && value !== null && value !== '') params.set(name, String(value))\n const given = Object.keys(criteria)\n const applicable = Object.fromEntries(Object.entries(criteria).filter(([name]) => screen.takes.includes(name)))\n const query = screen.queryState\n ? encodeListQuery({\n filters: filtersOf(target, applicable),\n search: typeof applicable.text === 'string' ? applicable.text : undefined,\n sorters: target.sortings\n })\n : params.toString()\n return {\n href: query ? `${screen.route}?${query}` : screen.route,\n applied: given.filter(name => screen.takes.includes(name)),\n notApplied: given.filter(name => !screen.takes.includes(name))\n }\n}\n"]}
1
+ {"version":3,"file":"read-target.js","sourceRoot":"","sources":["../../../server/service/data-read/read-target.ts"],"names":[],"mappings":";;;AAmIA,8CAgBC;AAED,oCAEC;AAGD,wCAEC;AAGD,wCAEC;AAED,4CAGC;AAuED,8CAuBC;AAED,oCAEC;AAMD,oCA0BC;AAED,8BAOC;AAKD,sBAcC;AAMD,4BAkBC;AAiBD,wBAeC;AAGD,oCAIC;AAGD,4BAsBC;AAGD,sCAmBC;AAlbD;;;;;;;;;;GAUG;AACH,mEAA2G;AAC3G,gEAA8D;AAE9D,qCAA+B;AAmF/B,wGAAwG;AAC3F,QAAA,aAAa,GAAG,IAAI,CAAA;AACjC,0DAA0D;AAC7C,QAAA,cAAc,GAAG,EAAE,CAAA;AAChC,gCAAgC;AACnB,QAAA,SAAS,GAAG,GAAG,CAAA;AAE5B,MAAM,QAAQ,GAAG,IAAI,GAAG,EAAsB,CA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,MAAM,CAAC,UAAU;QAC7B,CAAC,CAAC,IAAA,+BAAe,EAAC;YACd,OAAO,EAAE,SAAS,CAAC,MAAM,EAAE,UAAU,CAAC;YACtC,MAAM,EAAE,OAAO,UAAU,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS;YACzE,OAAO,EAAE,MAAM,CAAC,QAAQ;SACzB,CAAC;QACJ,CAAC,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAA;IACrB,OAAO;QACL,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,KAAK,IAAI,KAAK,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK;QACvD,OAAO,EAAE,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;QAC1D,UAAU,EAAE,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;KAC/D,CAAA;AACH,CAAC","sourcesContent":["/*\n * AI 조회 - an application's list, read through its own query as the person (operato-application/design/ai/read-targets.md).\n *\n * The application declares what it lets the assistant read: its list query, the conditions the model may set and\n * how each becomes one of the query's filters, the columns to show, and the screen that lists the same records.\n * The framework reads the rows through that query with the person's request state - the same @privilege and\n * domain as the screen - counts and sums them itself, and puts a long result on the AI 작업판 as the query returned\n * it. The model is told the count, the sums and a few rows; it never copies a table.\n *\n * Pure but for the GraphQL runner, which comes in as an argument - the rules are tested without a server.\n */\nimport { readFieldValue, recordIdOfKey, rootFieldOf, type EntryField } from '../data-entry/entry-target.js'\nimport { encodeListQuery } from '@operato/utils/list-query.js'\nimport type { GraphqlRunner } from '../data-entry/entry-update.js'\nimport { parse } from 'graphql'\n\nexport interface ReadFilter {\n name: string\n operator: string\n value: unknown\n}\n\n/** A condition the model may set - read with the entry fields' rules, turned into the query's filters by the application. */\nexport interface ReadCriterion extends Omit<EntryField, 'required' | 'reference' | 'total'> {\n filter: (value: any) => ReadFilter | ReadFilter[]\n /** A string condition holding a month as YYYY-MM - a value of another shape is refused (`not-a-month`). */\n format?: 'month'\n /**\n * The condition takes several values at once - its filter is given the list. Asked for the expenditure requests not\n * approved, rejected or withdrawn, the model read the list once per status and stopped (2026-10-25).\n */\n many?: boolean\n}\n\nexport interface ReadColumn {\n /** The key in the workspace table. */\n name: string\n /** Where the value is in a row - a dotted path into the query's item (`account.name`). Defaults to `name`. */\n path?: string\n type: 'string' | 'number' | 'date'\n labelKey?: string\n /** A number column the server sums. */\n total?: boolean\n /**\n * The column that holds this amount's currency (ISO 4217, `KRW`). Its sums are kept per currency - amounts of two\n * currencies are never added into one number.\n */\n currency?: string\n}\n\nexport interface ReadScreen {\n /** A URL-bound grid accepts the same predicates used by readRows, including conditions outside its form. */\n queryState?: boolean\n /** The application's route of the list screen (`cash-transaction-list`). */\n route: string\n /** The conditions the screen takes, as its address's query arguments. A condition left out is said on the card. */\n params: (criteria: Record<string, any>) => Record<string, string | number | undefined>\n /** The conditions `params` carries - the card names the others as not applied on the screen. */\n takes: string[]\n labelKey?: string\n}\n\nexport interface ReadTarget {\n /** `<app>.<record>` - the tools are named after it. */\n key: string\n /** i18n key naming the records (「은행 입출금」). */\n labelKey?: string\n /** What the records are, for the model. */\n description: string\n /**\n * The list query - takes `$filters: [Filter!]`, `$pagination: Pagination` and `$sortings: [Sorting!]`, and\n * `$search: String` when `search` is declared.\n */\n query: string\n /**\n * The list takes ListParam's free-text term, matched by the resolver across its own searchable fields - the\n * condition `text`. Say what it finds in, for the model.\n */\n search?: { description: string }\n criteria: ReadCriterion[]\n /**\n * Filters every read of this list applies - the records it is of (a book's confirmed lines, not its forecasts). Not\n * a condition: the model neither sees nor sets them, so a read can narrow the list but never widen it.\n */\n fixedFilters?: ReadFilter[]\n columns: ReadColumn[]\n rowsOf: (data: any) => { rows: any[]; total: number }\n /** Orders the rows; the query's own order when left out. */\n sortings?: { name: string; desc?: boolean }[]\n screen?: ReadScreen\n /**\n * The rows are the person's own, whoever reads them (내 지출결의) - the query answers for the one asking. A dashboard\n * card of it shows each viewer their own rows and takes no filter on a person (ADR-0160).\n */\n mine?: boolean\n}\n\n/** At most this many rows are read - the AI 작업판 table's own limit (workspace-blocks MAX_TABLE_ROWS). */\nexport const MAX_READ_ROWS = 1000\n/** Rows the model is shown; the rest stay on the card. */\nexport const ROWS_FOR_MODEL = 20\n/** A page of the list query. */\nexport const READ_PAGE = 200\n\nconst registry = new Map<string, ReadTarget>()\n\nconst pascalOf = (key: string) =>\n key\n .split(/[^a-zA-Z0-9]+/)\n .filter(Boolean)\n .map(part => part[0].toUpperCase() + part.slice(1))\n .join('')\n\nexport const queryToolName = (key: string) => `query${pascalOf(key)}`\nexport const screenToolName = (key: string) => `open${pascalOf(key)}Screen`\nexport const readCategoryName = (key: string) => `data-read:${key}`\n\n/** The columns of a list - shown, each named once, a currency only on a summed number and taken from a string column. */\nfunction checkColumns(of: string, columns: ReadColumn[]): void {\n if (!columns.length) throw new Error(`read target '${of}' shows no column`)\n const names = new Set<string>()\n for (const column of columns) {\n if (names.has(column.name)) throw new Error(`read target '${of}' names the column '${column.name}' twice`)\n names.add(column.name)\n }\n for (const column of columns.filter(one => one.currency)) {\n if (!column.total || column.type !== 'number') throw new Error(`column '${column.name}' of '${of}' names a currency but is not a summed number`)\n if (columns.find(one => one.name === column.currency)?.type !== 'string') throw new Error(`column '${column.name}' of '${of}' takes its currency from '${column.currency}', which is no string column`)\n }\n}\n\nexport function declareReadTarget(target: ReadTarget): void {\n if (!/^[a-z0-9-]+\\.[a-z0-9-]+$/.test(target.key)) throw new Error(`read target key '${target.key}' is not <app>.<record>`)\n if (registry.has(target.key) || details.has(target.key)) throw new Error(`read target '${target.key}' is declared twice`)\n rootFieldOf(target.query, 'query')\n checkColumns(target.key, target.columns)\n const names = new Set<string>(['id'])\n for (const criterion of target.criteria) {\n if (criterion.name === 'id') throw new Error(`read target '${target.key}' declares 'id' - every target takes it`)\n if (criterion.name === 'text' && target.search) throw new Error(`read target '${target.key}' declares 'text' and search - search is the text condition`)\n if (names.has(criterion.name)) throw new Error(`read target '${target.key}' names the condition '${criterion.name}' twice`)\n names.add(criterion.name)\n if (criterion.type === 'enum' && !criterion.values?.length) throw new Error(`condition '${criterion.name}' of '${target.key}' lists no values`)\n }\n if (target.search) names.add('text')\n for (const taken of target.screen?.takes ?? []) if (!names.has(taken)) throw new Error(`the screen of '${target.key}' takes '${taken}', which is no condition`)\n registry.set(target.key, target)\n}\n\nexport function readTargetOf(key: string | undefined): ReadTarget | undefined {\n return key ? registry.get(key) : undefined\n}\n\n/** Every list read target declared - what else reads the declarations (a dashboard card, ADR-0160) lists them by key. */\nexport function readTargetKeys(): string[] {\n return [...registry.keys()]\n}\n\n/** Every detail read declared. */\nexport function detailReadKeys(): string[] {\n return [...details.keys()]\n}\n\nexport function clearReadTargets(): void {\n registry.clear()\n details.clear()\n}\n\n/* ── One answer of a query ──────────────────────────────────────────────────────────────────────────────────── */\n\n/** An argument of a detail read - one variable of its query, read with the entry fields' rules. */\nexport interface DetailArg {\n name: string\n type: 'string' | 'integer' | 'number' | 'boolean' | 'date' | 'enum'\n values?: string[]\n description?: string\n required?: boolean\n /** A record's id: the axis (or axes) of the record, whose key `<axis>:<id>` the model may have been shown (EntryField.axis). */\n axis?: string | readonly string[]\n /** A string argument holding a month as YYYY-MM. */\n format?: 'month'\n}\n\n/**\n * A query whose answer is one thing, not a list - a 360's summary, the receivables, a statement (design/ai/read-targets.md\n * §9). The application declares the query with the fields its screen reads; the framework runs it as the person, with\n * the arguments the model set, and hands the answer over as the query returned it. Nothing is summed or cut here: the\n * selection is the projection, and an answer too long to hand over is refused, never cut.\n */\nexport interface DetailRead {\n /** `<app>.<thing>` - the tool is named after it. */\n key: string\n labelKey?: string\n /** What it answers, for the model. */\n description: string\n /** One query with one root field. Its variables are the arguments - each declared in `args`. */\n query: string\n args?: DetailArg[]\n /**\n * The records the answer is about, whose screens put it in front (EntryTarget.axes) - the management check answers\n * for any ledger record; asked on a deposit's 360 why it was in the check, the model never opened it (2026-10-24).\n */\n axes?: string[]\n /**\n * The lists the answer holds, each a table of typed columns - what a dashboard card may draw from a one-answer read\n * (ADR-0160 decision 2). The card keeps only `key`; where the rows are and what their columns are is read here.\n */\n lists?: DetailList[]\n /** The answer is the person's own, whoever asks (나의 전략 업무, 내 급여) - ReadTarget.mine. */\n mine?: boolean\n}\n\n/** A list inside a detail read's answer. */\nexport interface DetailList {\n /** A name stable within the read (`by-contract`) - what a card keeps. */\n key: string\n /** A dotted path inside the value of the query's root field (`rows`); '' when the root field is the list. */\n at: string\n labelKey?: string\n /** What the rows are, for the model. */\n description?: string\n columns: ReadColumn[]\n}\n\n/** Characters of an answer handed to the model - a longer one is refused, and the model narrows it. */\nexport const MAX_DETAIL_CHARS = 60_000\n\nconst details = new Map<string, DetailRead>()\n\nexport const detailToolName = (key: string) => `read${pascalOf(key)}`\n\n/** The variables a query declares, and whether each is required (`!`). */\nfunction variablesOf(document: string): { name: string; required: boolean }[] {\n const operation: any = parse(document).definitions.find((one: any) => one.kind === 'OperationDefinition')\n return (operation?.variableDefinitions ?? []).map((one: any) => ({ name: one.variable.name.value, required: one.type.kind === 'NonNullType' && !one.defaultValue }))\n}\n\nexport function declareDetailRead(target: DetailRead): void {\n if (!/^[a-z0-9-]+\\.[a-z0-9-]+$/.test(target.key)) throw new Error(`detail read key '${target.key}' is not <app>.<thing>`)\n if (details.has(target.key) || registry.has(target.key)) throw new Error(`read target '${target.key}' is declared twice`)\n rootFieldOf(target.query, 'query')\n const args = target.args ?? []\n for (const variable of variablesOf(target.query)) {\n const arg = args.find(one => one.name === variable.name)\n if (!arg) throw new Error(`detail read '${target.key}' takes $${variable.name}, which is no argument`)\n if (variable.required && !arg.required) throw new Error(`detail read '${target.key}': $${variable.name} is required by the query - declare it required`)\n }\n for (const arg of args) {\n if (!variablesOf(target.query).some(one => one.name === arg.name)) throw new Error(`detail read '${target.key}' declares '${arg.name}', which its query does not take`)\n if (arg.type === 'enum' && !arg.values?.length) throw new Error(`argument '${arg.name}' of '${target.key}' lists no values`)\n }\n const lists = new Set<string>()\n for (const list of target.lists ?? []) {\n if (!/^[a-z0-9-]+$/.test(list.key)) throw new Error(`list '${list.key}' of '${target.key}' is not a lowercase key`)\n if (lists.has(list.key)) throw new Error(`detail read '${target.key}' names the list '${list.key}' twice`)\n lists.add(list.key)\n if (!/^([A-Za-z0-9_]+(\\.[A-Za-z0-9_]+)*)?$/.test(list.at)) throw new Error(`list '${list.key}' of '${target.key}' is at '${list.at}', which is no dotted path`)\n checkColumns(`${target.key}/${list.key}`, list.columns)\n }\n details.set(target.key, target)\n}\n\nexport function detailReadOf(key: string | undefined): DetailRead | undefined {\n return key ? details.get(key) : undefined\n}\n\n/** A month as a `month` condition holds it. */\nconst MONTH = /^\\d{4}-(0[1-9]|1[0-2])$/\n\n/** The conditions the model set, read by their declared types; a value that does not fit is said, never guessed at. */\nexport function readCriteria(target: ReadTarget, args: any): { criteria: Record<string, unknown>; refused: { name: string; code: string }[] } {\n const criteria: Record<string, unknown> = {}\n const refused: { name: string; code: string }[] = []\n /* One record by its id - every target takes it (the id a list answer or a find tool gave, or the key `<axis>:<id>` an open record is shown by, the axis being the key's last part). */\n if (typeof args?.id === 'string' && args.id.trim()) criteria.id = recordIdOfKey(target.key.split('.').pop()!, args.id) ?? args.id.trim()\n if (target.search && typeof args?.text === 'string' && args.text.trim()) criteria.text = args.text.trim()\n for (const criterion of target.criteria) {\n const value = args?.[criterion.name]\n if (value === undefined || value === null || value === '' || (Array.isArray(value) && !value.length)) continue\n if (criterion.many && Array.isArray(value)) {\n const each = value.map(one => readFieldValue(criterion as EntryField, one))\n const wrong = each.find(one => one.read === undefined)\n if (wrong) refused.push({ name: criterion.name, code: wrong.code ?? 'unreadable' })\n else criteria[criterion.name] = [...new Set(each.map(one => one.read))]\n continue\n }\n if (Array.isArray(value)) {\n refused.push({ name: criterion.name, code: 'one-value' })\n continue\n }\n const { read, code } = readFieldValue(criterion as EntryField, value)\n if (read === undefined) refused.push({ name: criterion.name, code: code ?? 'unreadable' })\n else if (criterion.format === 'month' && !MONTH.test(String(read))) refused.push({ name: criterion.name, code: 'not-a-month' })\n else criteria[criterion.name] = read\n }\n return { criteria, refused }\n}\n\nexport function filtersOf(target: ReadTarget, criteria: Record<string, unknown>): ReadFilter[] {\n return [\n ...(typeof criteria.id === 'string' ? [{ name: 'id', operator: 'eq', value: criteria.id }] : []),\n ...target.criteria.flatMap(criterion =>\n criterion.name in criteria ? [criterion.filter(criteria[criterion.name])].flat() : []\n )\n ]\n}\n\nexport const valueAt = (row: any, path: string) => path.split('.').reduce((at, part) => (at === null || at === undefined ? undefined : at[part]), row)\n\n/** One row as the columns say - a number column as a number, a missing value as null. */\nexport function rowOf(target: Pick<ReadTarget, 'columns'>, item: any): Record<string, string | number | null> {\n return Object.fromEntries([\n /* The id names the record to the model - for one record's detail, a change, or its screen. */\n ...(item?.id ? [['id', String(item.id)] as [string, string]] : []),\n ...target.columns.map(column => {\n const raw = valueAt(item, column.path ?? column.name)\n if (raw === undefined || raw === null || raw === '') return [column.name, null]\n if (column.type === 'number') {\n const number = Number(raw)\n return [column.name, Number.isFinite(number) ? number : null]\n }\n return [column.name, String(raw)]\n })\n ])\n}\n\n/**\n * Reads the rows through the application's query, page by page, up to MAX_READ_ROWS. `complete` is false when the\n * list holds more - a sum of the rows read is then not the sum of the list, and is never said as one.\n */\nexport async function readRows(target: ReadTarget, filters: ReadFilter[], run: GraphqlRunner, search?: string): Promise<{ rows: Record<string, any>[]; total: number; complete: boolean }> {\n const rows: Record<string, any>[] = []\n let total = 0\n for (let page = 1; rows.length < MAX_READ_ROWS; page++) {\n const answer = await run(target.query, {\n filters: [...filters, ...(target.fixedFilters ?? [])],\n ...(search ? { search } : {}),\n pagination: { page, limit: READ_PAGE },\n ...(target.sortings ? { sortings: target.sortings } : {})\n })\n if (answer.errors?.length) throw new Error(answer.errors.map(one => one.message).join('; '))\n const read = target.rowsOf(answer.data)\n total = Number(read?.total) || 0\n const items = read?.rows ?? []\n rows.push(...items.slice(0, MAX_READ_ROWS - rows.length).map(item => rowOf(target, item)))\n if (items.length < READ_PAGE || rows.length >= total) break\n }\n return { rows, total, complete: rows.length >= total }\n}\n\n/** A column's sum - one number, or one per currency when the column names its currency (`{ KRW: 1000, USD: 100 }`). */\nexport type ReadSum = number | Record<string, number>\n\nexport interface ReadGroup {\n key: string\n count: number\n sums: Record<string, ReadSum>\n}\n\n/** The currency a row without one is summed under - said as it is, never taken for the domain's own. */\nexport const UNKNOWN_CURRENCY = 'unknown'\n\nconst sumOf = (rows: Record<string, any>[], name: string) => Math.round(rows.reduce((sum, row) => sum + (typeof row[name] === 'number' ? row[name] : 0), 0) * 100) / 100\n\n/** The sums of the number columns marked total - the server's, never the model's; a column with a currency per currency. */\nexport function sumsOf(target: Pick<ReadTarget, 'columns'>, rows: Record<string, any>[]): Record<string, ReadSum> {\n const sums: Record<string, ReadSum> = {}\n for (const column of target.columns.filter(one => one.total && one.type === 'number')) {\n if (!column.currency) {\n sums[column.name] = sumOf(rows, column.name)\n continue\n }\n const byCurrency = new Map<string, Record<string, any>[]>()\n for (const row of rows) {\n const code = typeof row[column.currency] === 'string' && row[column.currency] ? row[column.currency] : UNKNOWN_CURRENCY\n byCurrency.set(code, [...(byCurrency.get(code) ?? []), row])\n }\n sums[column.name] = Object.fromEntries([...byCurrency].sort(([a], [b]) => a.localeCompare(b)).map(([code, members]) => [code, sumOf(members, column.name)]))\n }\n return sums\n}\n\n/** The currencies a set of sums holds for one column - none for a column summed as one number. */\nexport function currenciesOf(sums: Record<string, ReadSum>[], column: string): string[] {\n const codes = new Set<string>()\n for (const one of sums) if (one[column] && typeof one[column] === 'object') for (const code of Object.keys(one[column] as object)) codes.add(code)\n return [...codes].sort()\n}\n\n/** The rows grouped by one column - a date column by its month - each with its count and sums, largest first. */\nexport function groupsOf(target: Pick<ReadTarget, 'columns'>, rows: Record<string, any>[], by: string): ReadGroup[] | undefined {\n const column = target.columns.find(one => one.name === by)\n if (!column) return undefined\n const groups = new Map<string, Record<string, any>[]>()\n for (const row of rows) {\n const value = row[by]\n const key = value === null || value === undefined ? '' : column.type === 'date' ? String(value).slice(0, 7) : String(value)\n groups.set(key, [...(groups.get(key) ?? []), row])\n }\n const list = [...groups].map(([key, members]) => ({ key, count: members.length, sums: sumsOf(target, members) }))\n if (column.type === 'date') return list.sort((a, b) => a.key.localeCompare(b.key))\n /* Largest first by the first sum - in its one currency; groups in two currencies have no common size, so by count. */\n const first = target.columns.find(one => one.total)?.name\n const codes = first ? currenciesOf(list.map(group => group.sums), first) : []\n const size = (group: ReadGroup) => {\n const sum = first ? group.sums[first] : undefined\n return typeof sum === 'number' ? Math.abs(sum) : codes.length === 1 && sum ? Math.abs(sum[codes[0]] ?? 0) : undefined\n }\n return list.sort((a, b) => {\n const [x, y] = [size(a), size(b)]\n return x !== undefined && y !== undefined && codes.length <= 1 ? y - x : b.count - a.count\n })\n}\n\n/** The address of the target's list screen with the conditions it takes, and the conditions it does not. */\nexport function screenAddress(target: ReadTarget, criteria: Record<string, unknown>): { href: string; applied: string[]; notApplied: string[] } | undefined {\n const screen = target.screen\n if (!screen) return undefined\n const params = new URLSearchParams()\n for (const [name, value] of Object.entries(screen.params(criteria))) if (value !== undefined && value !== null && value !== '') params.set(name, String(value))\n const given = Object.keys(criteria)\n const applicable = Object.fromEntries(Object.entries(criteria).filter(([name]) => screen.takes.includes(name)))\n const query = screen.queryState\n ? encodeListQuery({\n filters: filtersOf(target, applicable),\n search: typeof applicable.text === 'string' ? applicable.text : undefined,\n sorters: target.sortings\n })\n : params.toString()\n return {\n href: query ? `${screen.route}?${query}` : screen.route,\n applied: given.filter(name => screen.takes.includes(name)),\n notApplied: given.filter(name => !screen.takes.includes(name))\n }\n}\n"]}
@@ -36,9 +36,11 @@ const wordsOf = (context) => (key, fallback) => {
36
36
  function criterionSchema(criterion) {
37
37
  /* One type per field - Gemini's function schema refuses a list of types (2026-10-01). */
38
38
  const type = criterion.type === 'number' ? 'number' : criterion.type === 'integer' ? 'integer' : criterion.type === 'boolean' ? 'boolean' : 'string';
39
- const said = [criterion.description, criterion.type === 'date' ? 'YYYY-MM-DD' : undefined, criterion.type === 'enum' ? `one of: ${criterion.values.join(', ')}` : undefined]
39
+ const said = [criterion.description, criterion.type === 'date' ? 'YYYY-MM-DD' : criterion.format === 'month' ? 'YYYY-MM' : undefined, criterion.type === 'enum' ? `one of: ${criterion.values.join(', ')}` : undefined]
40
40
  .filter(Boolean)
41
41
  .join('. ');
42
+ if (criterion.many)
43
+ return { type: 'array', items: { type }, ...(said ? { description: `${said} - one or more` } : {}) };
42
44
  return { type, ...(said ? { description: said } : {}) };
43
45
  }
44
46
  async function queryRecords(target, args, context, run) {
@@ -1 +1 @@
1
- {"version":3,"file":"read-tools.js","sourceRoot":"","sources":["../../../server/service/data-read/read-tools.ts"],"names":[],"mappings":";;AAwDA,oCAmFC;AAED,gCAqBC;AAED,wCAuDC;AAMD,gDAGC;AAwBD,8BAyBC;AAGD,kCAYC;AAED,4CAuBC;AAGD,gDAGC;AAnUD;;;;;;;GAOG;AACH,mEAAuG;AAEvG,mEAA2E;AAE3E,iEAA0D;AAC1D,0EAAwF;AACxF,qDAoByB;AAEzB,yFAAyF;AACzF,MAAM,OAAO,GAAG,CAAC,OAAY,EAAE,EAAE,CAAC,CAAC,GAAuB,EAAE,QAAgB,EAAE,EAAE;IAC9E,IAAI,CAAC,GAAG,IAAI,OAAO,OAAO,EAAE,CAAC,KAAK,UAAU;QAAE,OAAO,QAAQ,CAAA;IAC7D,IAAI,CAAC;QACH,MAAM,IAAI,GAAG,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,CAAA;QAC3B,OAAO,IAAI,IAAI,IAAI,KAAK,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,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AM,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,MAAM,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;oBAC5I,UAAU,EAAE,MAAM,CAAC,WAAW,CAAC,CAAC,MAAM,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,IAAI,EAAE,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;iBAC3F;gBACD,OAAO,EAAE,CAAC,IAAS,EAAE,OAAY,EAAE,EAAE,CAAC,WAAW,CAAC,MAAM,EAAE,IAAI,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC;aAClE;SACd;KACF,CAAA;AACH,CAAC;AAED,kIAAkI;AAClI,SAAgB,kBAAkB,CAAC,MAAkB;IACnD,IAAA,kCAAiB,EAAC,MAAM,CAAC,CAAA;IACzB,IAAA,qCAAoB,EAAC,gBAAgB,CAAC,MAAM,CAAC,CAAC,CAAA;AAChD,CAAC","sourcesContent":["/*\n * The tools of an AI 조회 target (operato-application/design/ai/read-targets.md §4, §5).\n *\n * query<X> reads the rows through the application's list query as the person, and tells the model the count, the\n * sums, the groups and a few rows. A longer result goes on the AI 작업판 as a proposal the server builds from the rows\n * themselves - the table is never written by the model. open<X>Screen reads nothing: it hands the card the address\n * of the application's list screen with the conditions it takes.\n */\nimport { registerToolCategory, type ToolCategory, type ToolSpec } from '@things-factory/ai-client-base'\n\nimport { readFieldValue, rootFieldOf } from '../data-entry/entry-target.js'\nimport type { GraphqlRunner } from '../data-entry/entry-update.js'\nimport { runAsCaller } from '../data-entry/entry-tools.js'\nimport { normalizeWorkspace, workspaceContents } from '../workspace/workspace-blocks.js'\nimport {\n declareReadTarget,\n filtersOf,\n currenciesOf,\n declareDetailRead,\n detailToolName,\n MAX_DETAIL_CHARS,\n type DetailArg,\n type DetailRead,\n groupsOf,\n queryToolName,\n readCategoryName,\n readCriteria,\n readRows,\n ROWS_FOR_MODEL,\n screenAddress,\n screenToolName,\n sumsOf,\n type ReadCriterion,\n type ReadTarget\n} from './read-target.js'\n\n/** The reader's words for a key - the key's own default when the translator has none. */\nconst wordsOf = (context: any) => (key: string | undefined, fallback: string) => {\n if (!key || typeof context?.t !== 'function') return fallback\n try {\n const said = context.t(key)\n return said && said !== key ? String(said) : fallback\n } catch {\n return fallback\n }\n}\n\nfunction criterionSchema(criterion: ReadCriterion): any {\n /* One type per field - Gemini's function schema refuses a list of types (2026-10-01). */\n const type = criterion.type === 'number' ? 'number' : criterion.type === 'integer' ? 'integer' : criterion.type === 'boolean' ? 'boolean' : 'string'\n const said = [criterion.description, criterion.type === 'date' ? 'YYYY-MM-DD' : undefined, criterion.type === 'enum' ? `one of: ${criterion.values!.join(', ')}` : undefined]\n .filter(Boolean)\n .join('. ')\n return { type, ...(said ? { description: said } : {}) }\n}\n\nexport async function queryRecords(target: ReadTarget, args: any, context: any, run: GraphqlRunner) {\n const { criteria, refused } = readCriteria(target, args)\n if (refused.length) {\n return { rejected: true, error: 'condition-unreadable', refused, message: `these conditions do not fit their type: ${refused.map(one => `${one.name} (${one.code})`).join(', ')}. Fix them and call again.` }\n }\n let read\n try {\n read = await readRows(target, filtersOf(target, criteria), run, typeof criteria.text === 'string' && target.search ? criteria.text : undefined)\n } catch (error: any) {\n return { rejected: true, error: 'query-failed', message: `the list could not be read: ${error?.message ?? error}` }\n }\n const { rows, total, complete } = read\n const sums = sumsOf(target, rows)\n const groupBy = typeof args?.groupBy === 'string' && args.groupBy ? args.groupBy : undefined\n const groups = groupBy ? groupsOf(target, rows, groupBy) : undefined\n const words = wordsOf(context)\n const label = words(target.labelKey, target.key)\n\n const said = {\n target: target.key,\n criteria,\n total,\n read: rows.length,\n complete,\n sums,\n ...(groupBy ? (groups ? { groupBy, groups: groups.slice(0, 50), ...(groups.length > 50 ? { moreGroups: groups.length - 50 } : {}) } : { groupBy, groupRefused: 'no such column' }) : {}),\n rows: rows.slice(0, ROWS_FOR_MODEL),\n ...(rows.length > ROWS_FOR_MODEL ? { rowsNotShown: rows.length - ROWS_FOR_MODEL } : {})\n }\n const incomplete = complete\n ? ''\n : ` Only ${rows.length} of ${total} rows were read; the sums and groups are of those rows, not of the list - say so, and ask the person to narrow the conditions.`\n\n if (rows.length === 1 && args?.show !== 'workspace') {\n return { ...said, record: rows[0], message: 'one record - answer from its fields; say a field it does not have as not recorded.' }\n }\n if (rows.length <= ROWS_FOR_MODEL && args?.show !== 'workspace') {\n return { ...said, message: `${rows.length} rows of ${total}.${incomplete} Answer from these rows; every number you say comes from them.` }\n }\n\n /* The workspace is built here from the rows as read - the model never copies the table. */\n const columns = target.columns.map(column => ({ name: column.name, label: words(column.labelKey, column.name), type: column.type }))\n const totalColumns = target.columns.filter(one => one.total)\n /* A sum per currency is one figure and one group column per currency it holds - 「계약금액 (USD)」. */\n const sumColumns = totalColumns.flatMap(column => {\n const label = words(column.labelKey, column.name)\n const codes = currenciesOf([sums, ...(groups ?? []).map(group => group.sums)], column.name)\n return column.currency\n ? codes.map(code => ({ name: `${column.name}:${code}`, label: `${label} (${code})`, of: (one: Record<string, any>) => one[column.name]?.[code] ?? 0 }))\n : [{ name: column.name, label, of: (one: Record<string, any>) => one[column.name] }]\n })\n const title = typeof args?.title === 'string' && args.title.trim() ? args.title.trim() : `${label} · ${rows.length}`\n const { workspace } = normalizeWorkspace({\n name: typeof args?.name === 'string' && args.name ? args.name : target.key.replace(/\\./g, '-'),\n title,\n ...(complete ? {} : { summary: `${total} / ${rows.length}` }),\n blocks: [\n {\n kind: 'metrics',\n items: [{ label: words('ai-assistant.read.count', 'rows'), value: String(rows.length), ...(complete ? {} : { note: `/ ${total}` }) }, ...sumColumns.map(column => ({ label: column.label, value: String(column.of(sums)) }))]\n },\n ...(groups\n ? [\n {\n kind: 'table',\n caption: words(target.columns.find(one => one.name === groupBy)?.labelKey, groupBy!),\n columns: [{ name: 'key', label: words(target.columns.find(one => one.name === groupBy)?.labelKey, groupBy!), type: 'string' }, { name: 'count', label: words('ai-assistant.read.count', 'rows'), type: 'number' }, ...sumColumns.map(column => ({ name: column.name, label: column.label, type: 'number' }))],\n rows: groups.map(group => ({ key: group.key, count: group.count, ...Object.fromEntries(sumColumns.map(column => [column.name, column.of(group.sums)])) }))\n }\n ]\n : []),\n { kind: 'table', caption: label, columns, rows }\n ]\n })\n return {\n proposed: true,\n kind: 'workspace',\n icon: 'table_view',\n label: title,\n ...said,\n forScreen: { workspace, contents: workspaceContents(workspace!) },\n message: `${rows.length} rows of ${total} are on the AI 작업판 as read - the person opens it from the card.${incomplete} Say the point in one or two lines from the sums, groups and rows above; do not write the table out.`\n }\n}\n\nexport function openScreen(target: ReadTarget, args: any, context: any) {\n const { criteria, refused } = readCriteria(target, args)\n if (refused.length) return { rejected: true, error: 'condition-unreadable', refused, message: 'fix the conditions and call again.' }\n const address = screenAddress(target, criteria)\n if (!address) return { rejected: true, error: 'no-screen', message: 'this list has no screen to open.' }\n const words = wordsOf(context)\n return {\n proposed: true,\n kind: 'open-page',\n icon: 'open_in_new',\n label: words(target.screen!.labelKey ?? target.labelKey, target.key),\n target: target.key,\n href: address.href,\n applied: address.applied,\n notApplied: address.notApplied,\n /* The card says them in the reader's words. */\n notAppliedLabels: address.notApplied.map(name => words(target.criteria.find(one => one.name === name)?.labelKey ?? (name === 'text' || name === 'id' ? `ai-assistant.read.${name}` : undefined), name)),\n message:\n 'the card opens the screen when the person presses it.' +\n (address.notApplied.length ? ` The screen does not take ${address.notApplied.join(', ')} - say so.` : '')\n }\n}\n\nexport function readCategoryOf(target: ReadTarget, run: (context: any) => GraphqlRunner = runAsCaller): ToolCategory {\n const door = rootFieldOf(target.query, 'query')\n const conditions = {\n ...Object.fromEntries(target.criteria.map(criterion => [criterion.name, criterionSchema(criterion)])),\n ...(target.search ? { text: { type: 'string', description: `words to find - ${target.search.description}` } } : {})\n }\n const specs: ToolSpec[] = [\n {\n kind: 'read',\n name: queryToolName(target.key),\n /* The person must be able to read the list on its screen - the tool is not a second way in. */\n doors: [door],\n description:\n `Read ${target.description} Set the conditions the question names. Returns the count, the sums, ` +\n `groups when groupBy is given (a date column groups by month) and the first ${ROWS_FOR_MODEL} rows; more rows go on the AI 작업판 as read.`,\n schema: {\n type: 'object',\n properties: {\n id: { type: 'string', description: 'One record by its id, from an earlier answer - its detail.' },\n ...conditions,\n groupBy: { type: 'string', description: `One column to group by: ${target.columns.map(one => one.name).join(', ')}.` },\n show: { type: 'string', enum: ['answer', 'workspace'], description: 'workspace to put even a short result on the AI 작업판.' },\n title: { type: 'string', description: 'The workspace title, in the person\\'s language.' },\n name: { type: 'string', description: 'The workspace key; the same key again makes a new version.' }\n }\n },\n builder: (args: any, context: any) => queryRecords(target, args, context, run(context))\n } as ToolSpec,\n ...(target.screen\n ? [\n {\n kind: 'read',\n name: screenToolName(target.key),\n doors: [door],\n description: `Offer the person the screen that lists ${target.description} with these conditions. Reads nothing. The screen takes: ${target.screen.takes.join(', ')}.`,\n schema: { type: 'object', properties: conditions },\n builder: (args: any, context: any) => openScreen(target, args, context)\n } as ToolSpec\n ]\n : [])\n ]\n return {\n name: readCategoryName(target.key),\n description: `data read: ${target.key}`,\n guidance: [\n `- To answer from ${target.key} records - a list, or one record found by its name, code or id - call ${queryToolName(target.key)} with the conditions the question names. Every number you say comes from its result - never add up rows yourself; use its sums and groups.`,\n `- A list, a summary by item or month, or a comparison: call it with groupBy, and let a long result go on the AI 작업판 - then answer in one or two lines.`,\n `- When the result says complete: false, say how many of how many were read and ask to narrow - never call partial sums the total.`,\n ...(target.columns.some(one => one.currency)\n ? [`- Sums of ${target.columns.filter(one => one.currency).map(one => one.name).join(', ')} come per currency. Say each currency's sum; never add two currencies into one number. A comparison across currencies uses a rate you read, and says the rate and its date.`]\n : []),\n ...(target.screen ? [`- When the person wants to work on the records themselves (edit, sort, export), call ${screenToolName(target.key)}; say which conditions the screen does not take.`] : [])\n ].join('\\n'),\n specs\n }\n}\n\n/**\n * What an application calls at boot to let the assistant read one of its lists. A mode opens it by naming the key\n * in `readTargets`.\n */\nexport function registerReadTarget(target: ReadTarget): void {\n declareReadTarget(target)\n registerToolCategory(readCategoryOf(target))\n}\n\n/* ── One answer of a query (DetailRead) ───────────────────────────────────────────────────────────────────── */\n\nfunction argSchema(arg: DetailArg): any {\n const type = arg.type === 'number' ? 'number' : arg.type === 'integer' ? 'integer' : arg.type === 'boolean' ? 'boolean' : 'string'\n const said = [arg.description, arg.type === 'date' ? 'YYYY-MM-DD' : undefined, arg.type === 'enum' ? `one of: ${arg.values!.join(', ')}` : undefined].filter(Boolean).join('. ')\n return { type, ...(said ? { description: said } : {}) }\n}\n\n/**\n * What running a detail read as the person gave - the root field's value, or why there is none. Shared by the tool,\n * which hands the value to the model, and by every other reader of a detail read (a dashboard card, ADR-0160\n * decision 2), which has its own limits: the arguments, the door and the query are one, the size rule is the tool's.\n */\nexport interface DetailRun {\n /** The root field's value - absent when `error` says why. */\n value?: unknown\n error?: 'argument-unreadable' | 'query-failed' | 'not-found'\n refused?: { name: string; code: string }[]\n message?: string\n}\n\n/** Runs the query as the person with the arguments given - read by their declared types, a missing required one refused. */\nexport async function runDetail(target: DetailRead, args: any, run: GraphqlRunner): Promise<DetailRun> {\n const variables: Record<string, unknown> = {}\n const refused: { name: string; code: string }[] = []\n for (const arg of target.args ?? []) {\n const value = args?.[arg.name]\n if (value === undefined || value === null || value === '') {\n if (arg.required) refused.push({ name: arg.name, code: 'required' })\n continue\n }\n const { read, code } = readFieldValue({ name: arg.name, type: arg.type === 'string' ? 'text' : arg.type, values: arg.values, axis: arg.axis } as any, value)\n if (read === undefined) refused.push({ name: arg.name, code: code ?? 'unreadable' })\n else variables[arg.name] = read\n }\n if (refused.length) return { error: 'argument-unreadable', refused }\n let answer\n try {\n answer = await run(target.query, variables)\n } catch (error: any) {\n return { error: 'query-failed', message: String(error?.message ?? error) }\n }\n if (answer.errors?.length) return { error: 'query-failed', message: answer.errors.map(one => one.message).join('; ') }\n const root = rootFieldOf(target.query, 'query').replace(/^Query\\./, '')\n const value = answer.data?.[root]\n if (value === null || value === undefined) return { error: 'not-found' }\n return { value }\n}\n\n/** Runs the query as the person with the arguments the model set; the answer as the query returned it. */\nexport async function queryDetail(target: DetailRead, args: any, run: GraphqlRunner) {\n const ran = await runDetail(target, args, run)\n if (ran.error) {\n if (ran.error === 'argument-unreadable')\n return { rejected: true, error: 'argument-unreadable', refused: ran.refused, message: `these arguments are missing or do not fit their type: ${ran.refused.map(one => `${one.name} (${one.code})`).join(', ')}. Fix them and call again.` }\n if (ran.error === 'query-failed') return { rejected: true, error: 'query-failed', message: `it could not be read: ${ran.message}` }\n return { target: target.key, found: false, message: 'nothing was found for these arguments - say so; do not fill it in.' }\n }\n const value = ran.value\n const size = JSON.stringify(value).length\n if (size > MAX_DETAIL_CHARS) return { rejected: true, error: 'answer-too-large', size, message: `the answer runs to ${size} characters, more than ${MAX_DETAIL_CHARS} - narrow the arguments, or read the list it is made of.` }\n return { target: target.key, answer: value, message: 'answer from these fields; every number you say comes from them. Amounts are in the currency beside them - never add two currencies into one number.' }\n}\n\nexport function detailCategoryOf(target: DetailRead, run: (context: any) => GraphqlRunner = runAsCaller): ToolCategory {\n const door = rootFieldOf(target.query, 'query')\n const name = detailToolName(target.key)\n return {\n name: readCategoryName(target.key),\n description: `data read: ${target.key}`,\n guidance: `- To answer about ${target.description.replace(/\\.$/, '')}, call ${name}. Every number you say comes from its answer.`,\n specs: [\n {\n kind: 'read',\n name,\n /* The person must be able to run the query on its screen - the tool is not a second way in. */\n doors: [door],\n description: `Read ${target.description}`,\n schema: {\n type: 'object',\n ...((target.args ?? []).some(one => one.required) ? { required: (target.args ?? []).filter(one => one.required).map(one => one.name) } : {}),\n properties: Object.fromEntries((target.args ?? []).map(arg => [arg.name, argSchema(arg)]))\n },\n builder: (args: any, context: any) => queryDetail(target, args, run(context))\n } as ToolSpec\n ]\n }\n}\n\n/** What an application calls at boot to let the assistant read one answer of its API. A mode opens it by key in `readTargets`. */\nexport function registerDetailRead(target: DetailRead): void {\n declareDetailRead(target)\n registerToolCategory(detailCategoryOf(target))\n}\n"]}
1
+ {"version":3,"file":"read-tools.js","sourceRoot":"","sources":["../../../server/service/data-read/read-tools.ts"],"names":[],"mappings":";;AAyDA,oCAmFC;AAED,gCAqBC;AAED,wCAuDC;AAMD,gDAGC;AAwBD,8BAyBC;AAGD,kCAYC;AAED,4CAuBC;AAGD,gDAGC;AApUD;;;;;;;GAOG;AACH,mEAAuG;AAEvG,mEAA2E;AAE3E,iEAA0D;AAC1D,0EAAwF;AACxF,qDAoByB;AAEzB,yFAAyF;AACzF,MAAM,OAAO,GAAG,CAAC,OAAY,EAAE,EAAE,CAAC,CAAC,GAAuB,EAAE,QAAgB,EAAE,EAAE;IAC9E,IAAI,CAAC,GAAG,IAAI,OAAO,OAAO,EAAE,CAAC,KAAK,UAAU;QAAE,OAAO,QAAQ,CAAA;IAC7D,IAAI,CAAC;QACH,MAAM,IAAI,GAAG,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,CAAA;QAC3B,OAAO,IAAI,IAAI,IAAI,KAAK,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAA;IACvD,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,QAAQ,CAAA;IACjB,CAAC;AACH,CAAC,CAAA;AAED,SAAS,eAAe,CAAC,SAAwB;IAC/C,yFAAyF;IACzF,MAAM,IAAI,GAAG,SAAS,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS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AAQ;oBACd,GAAG,CAAC,CAAC,MAAM,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,MAAM,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;oBAC5I,UAAU,EAAE,MAAM,CAAC,WAAW,CAAC,CAAC,MAAM,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,IAAI,EAAE,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;iBAC3F;gBACD,OAAO,EAAE,CAAC,IAAS,EAAE,OAAY,EAAE,EAAE,CAAC,WAAW,CAAC,MAAM,EAAE,IAAI,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC;aAClE;SACd;KACF,CAAA;AACH,CAAC;AAED,kIAAkI;AAClI,SAAgB,kBAAkB,CAAC,MAAkB;IACnD,IAAA,kCAAiB,EAAC,MAAM,CAAC,CAAA;IACzB,IAAA,qCAAoB,EAAC,gBAAgB,CAAC,MAAM,CAAC,CAAC,CAAA;AAChD,CAAC","sourcesContent":["/*\n * The tools of an AI 조회 target (operato-application/design/ai/read-targets.md §4, §5).\n *\n * query<X> reads the rows through the application's list query as the person, and tells the model the count, the\n * sums, the groups and a few rows. A longer result goes on the AI 작업판 as a proposal the server builds from the rows\n * themselves - the table is never written by the model. open<X>Screen reads nothing: it hands the card the address\n * of the application's list screen with the conditions it takes.\n */\nimport { registerToolCategory, type ToolCategory, type ToolSpec } from '@things-factory/ai-client-base'\n\nimport { readFieldValue, rootFieldOf } from '../data-entry/entry-target.js'\nimport type { GraphqlRunner } from '../data-entry/entry-update.js'\nimport { runAsCaller } from '../data-entry/entry-tools.js'\nimport { normalizeWorkspace, workspaceContents } from '../workspace/workspace-blocks.js'\nimport {\n declareReadTarget,\n filtersOf,\n currenciesOf,\n declareDetailRead,\n detailToolName,\n MAX_DETAIL_CHARS,\n type DetailArg,\n type DetailRead,\n groupsOf,\n queryToolName,\n readCategoryName,\n readCriteria,\n readRows,\n ROWS_FOR_MODEL,\n screenAddress,\n screenToolName,\n sumsOf,\n type ReadCriterion,\n type ReadTarget\n} from './read-target.js'\n\n/** The reader's words for a key - the key's own default when the translator has none. */\nconst wordsOf = (context: any) => (key: string | undefined, fallback: string) => {\n if (!key || typeof context?.t !== 'function') return fallback\n try {\n const said = context.t(key)\n return said && said !== key ? String(said) : fallback\n } catch {\n return fallback\n }\n}\n\nfunction criterionSchema(criterion: ReadCriterion): any {\n /* One type per field - Gemini's function schema refuses a list of types (2026-10-01). */\n const type = criterion.type === 'number' ? 'number' : criterion.type === 'integer' ? 'integer' : criterion.type === 'boolean' ? 'boolean' : 'string'\n const said = [criterion.description, criterion.type === 'date' ? 'YYYY-MM-DD' : criterion.format === 'month' ? 'YYYY-MM' : undefined, criterion.type === 'enum' ? `one of: ${criterion.values!.join(', ')}` : undefined]\n .filter(Boolean)\n .join('. ')\n if (criterion.many) return { type: 'array', items: { type }, ...(said ? { description: `${said} - one or more` } : {}) }\n return { type, ...(said ? { description: said } : {}) }\n}\n\nexport async function queryRecords(target: ReadTarget, args: any, context: any, run: GraphqlRunner) {\n const { criteria, refused } = readCriteria(target, args)\n if (refused.length) {\n return { rejected: true, error: 'condition-unreadable', refused, message: `these conditions do not fit their type: ${refused.map(one => `${one.name} (${one.code})`).join(', ')}. Fix them and call again.` }\n }\n let read\n try {\n read = await readRows(target, filtersOf(target, criteria), run, typeof criteria.text === 'string' && target.search ? criteria.text : undefined)\n } catch (error: any) {\n return { rejected: true, error: 'query-failed', message: `the list could not be read: ${error?.message ?? error}` }\n }\n const { rows, total, complete } = read\n const sums = sumsOf(target, rows)\n const groupBy = typeof args?.groupBy === 'string' && args.groupBy ? args.groupBy : undefined\n const groups = groupBy ? groupsOf(target, rows, groupBy) : undefined\n const words = wordsOf(context)\n const label = words(target.labelKey, target.key)\n\n const said = {\n target: target.key,\n criteria,\n total,\n read: rows.length,\n complete,\n sums,\n ...(groupBy ? (groups ? { groupBy, groups: groups.slice(0, 50), ...(groups.length > 50 ? { moreGroups: groups.length - 50 } : {}) } : { groupBy, groupRefused: 'no such column' }) : {}),\n rows: rows.slice(0, ROWS_FOR_MODEL),\n ...(rows.length > ROWS_FOR_MODEL ? { rowsNotShown: rows.length - ROWS_FOR_MODEL } : {})\n }\n const incomplete = complete\n ? ''\n : ` Only ${rows.length} of ${total} rows were read; the sums and groups are of those rows, not of the list - say so, and ask the person to narrow the conditions.`\n\n if (rows.length === 1 && args?.show !== 'workspace') {\n return { ...said, record: rows[0], message: 'one record - answer from its fields; say a field it does not have as not recorded.' }\n }\n if (rows.length <= ROWS_FOR_MODEL && args?.show !== 'workspace') {\n return { ...said, message: `${rows.length} rows of ${total}.${incomplete} Answer from these rows; every number you say comes from them.` }\n }\n\n /* The workspace is built here from the rows as read - the model never copies the table. */\n const columns = target.columns.map(column => ({ name: column.name, label: words(column.labelKey, column.name), type: column.type }))\n const totalColumns = target.columns.filter(one => one.total)\n /* A sum per currency is one figure and one group column per currency it holds - 「계약금액 (USD)」. */\n const sumColumns = totalColumns.flatMap(column => {\n const label = words(column.labelKey, column.name)\n const codes = currenciesOf([sums, ...(groups ?? []).map(group => group.sums)], column.name)\n return column.currency\n ? codes.map(code => ({ name: `${column.name}:${code}`, label: `${label} (${code})`, of: (one: Record<string, any>) => one[column.name]?.[code] ?? 0 }))\n : [{ name: column.name, label, of: (one: Record<string, any>) => one[column.name] }]\n })\n const title = typeof args?.title === 'string' && args.title.trim() ? args.title.trim() : `${label} · ${rows.length}`\n const { workspace } = normalizeWorkspace({\n name: typeof args?.name === 'string' && args.name ? args.name : target.key.replace(/\\./g, '-'),\n title,\n ...(complete ? {} : { summary: `${total} / ${rows.length}` }),\n blocks: [\n {\n kind: 'metrics',\n items: [{ label: words('ai-assistant.read.count', 'rows'), value: String(rows.length), ...(complete ? {} : { note: `/ ${total}` }) }, ...sumColumns.map(column => ({ label: column.label, value: String(column.of(sums)) }))]\n },\n ...(groups\n ? [\n {\n kind: 'table',\n caption: words(target.columns.find(one => one.name === groupBy)?.labelKey, groupBy!),\n columns: [{ name: 'key', label: words(target.columns.find(one => one.name === groupBy)?.labelKey, groupBy!), type: 'string' }, { name: 'count', label: words('ai-assistant.read.count', 'rows'), type: 'number' }, ...sumColumns.map(column => ({ name: column.name, label: column.label, type: 'number' }))],\n rows: groups.map(group => ({ key: group.key, count: group.count, ...Object.fromEntries(sumColumns.map(column => [column.name, column.of(group.sums)])) }))\n }\n ]\n : []),\n { kind: 'table', caption: label, columns, rows }\n ]\n })\n return {\n proposed: true,\n kind: 'workspace',\n icon: 'table_view',\n label: title,\n ...said,\n forScreen: { workspace, contents: workspaceContents(workspace!) },\n message: `${rows.length} rows of ${total} are on the AI 작업판 as read - the person opens it from the card.${incomplete} Say the point in one or two lines from the sums, groups and rows above; do not write the table out.`\n }\n}\n\nexport function openScreen(target: ReadTarget, args: any, context: any) {\n const { criteria, refused } = readCriteria(target, args)\n if (refused.length) return { rejected: true, error: 'condition-unreadable', refused, message: 'fix the conditions and call again.' }\n const address = screenAddress(target, criteria)\n if (!address) return { rejected: true, error: 'no-screen', message: 'this list has no screen to open.' }\n const words = wordsOf(context)\n return {\n proposed: true,\n kind: 'open-page',\n icon: 'open_in_new',\n label: words(target.screen!.labelKey ?? target.labelKey, target.key),\n target: target.key,\n href: address.href,\n applied: address.applied,\n notApplied: address.notApplied,\n /* The card says them in the reader's words. */\n notAppliedLabels: address.notApplied.map(name => words(target.criteria.find(one => one.name === name)?.labelKey ?? (name === 'text' || name === 'id' ? `ai-assistant.read.${name}` : undefined), name)),\n message:\n 'the card opens the screen when the person presses it.' +\n (address.notApplied.length ? ` The screen does not take ${address.notApplied.join(', ')} - say so.` : '')\n }\n}\n\nexport function readCategoryOf(target: ReadTarget, run: (context: any) => GraphqlRunner = runAsCaller): ToolCategory {\n const door = rootFieldOf(target.query, 'query')\n const conditions = {\n ...Object.fromEntries(target.criteria.map(criterion => [criterion.name, criterionSchema(criterion)])),\n ...(target.search ? { text: { type: 'string', description: `words to find - ${target.search.description}` } } : {})\n }\n const specs: ToolSpec[] = [\n {\n kind: 'read',\n name: queryToolName(target.key),\n /* The person must be able to read the list on its screen - the tool is not a second way in. */\n doors: [door],\n description:\n `Read ${target.description} Set the conditions the question names. Returns the count, the sums, ` +\n `groups when groupBy is given (a date column groups by month) and the first ${ROWS_FOR_MODEL} rows; more rows go on the AI 작업판 as read.`,\n schema: {\n type: 'object',\n properties: {\n id: { type: 'string', description: 'One record by its id, from an earlier answer - its detail.' },\n ...conditions,\n groupBy: { type: 'string', description: `One column to group by: ${target.columns.map(one => one.name).join(', ')}.` },\n show: { type: 'string', enum: ['answer', 'workspace'], description: 'workspace to put even a short result on the AI 작업판.' },\n title: { type: 'string', description: 'The workspace title, in the person\\'s language.' },\n name: { type: 'string', description: 'The workspace key; the same key again makes a new version.' }\n }\n },\n builder: (args: any, context: any) => queryRecords(target, args, context, run(context))\n } as ToolSpec,\n ...(target.screen\n ? [\n {\n kind: 'read',\n name: screenToolName(target.key),\n doors: [door],\n description: `Offer the person the screen that lists ${target.description} with these conditions. Reads nothing. The screen takes: ${target.screen.takes.join(', ')}.`,\n schema: { type: 'object', properties: conditions },\n builder: (args: any, context: any) => openScreen(target, args, context)\n } as ToolSpec\n ]\n : [])\n ]\n return {\n name: readCategoryName(target.key),\n description: `data read: ${target.key}`,\n guidance: [\n `- To answer from ${target.key} records - a list, or one record found by its name, code or id - call ${queryToolName(target.key)} with the conditions the question names. Every number you say comes from its result - never add up rows yourself; use its sums and groups.`,\n `- A list, a summary by item or month, or a comparison: call it with groupBy, and let a long result go on the AI 작업판 - then answer in one or two lines.`,\n `- When the result says complete: false, say how many of how many were read and ask to narrow - never call partial sums the total.`,\n ...(target.columns.some(one => one.currency)\n ? [`- Sums of ${target.columns.filter(one => one.currency).map(one => one.name).join(', ')} come per currency. Say each currency's sum; never add two currencies into one number. A comparison across currencies uses a rate you read, and says the rate and its date.`]\n : []),\n ...(target.screen ? [`- When the person wants to work on the records themselves (edit, sort, export), call ${screenToolName(target.key)}; say which conditions the screen does not take.`] : [])\n ].join('\\n'),\n specs\n }\n}\n\n/**\n * What an application calls at boot to let the assistant read one of its lists. A mode opens it by naming the key\n * in `readTargets`.\n */\nexport function registerReadTarget(target: ReadTarget): void {\n declareReadTarget(target)\n registerToolCategory(readCategoryOf(target))\n}\n\n/* ── One answer of a query (DetailRead) ───────────────────────────────────────────────────────────────────── */\n\nfunction argSchema(arg: DetailArg): any {\n const type = arg.type === 'number' ? 'number' : arg.type === 'integer' ? 'integer' : arg.type === 'boolean' ? 'boolean' : 'string'\n const said = [arg.description, arg.type === 'date' ? 'YYYY-MM-DD' : undefined, arg.type === 'enum' ? `one of: ${arg.values!.join(', ')}` : undefined].filter(Boolean).join('. ')\n return { type, ...(said ? { description: said } : {}) }\n}\n\n/**\n * What running a detail read as the person gave - the root field's value, or why there is none. Shared by the tool,\n * which hands the value to the model, and by every other reader of a detail read (a dashboard card, ADR-0160\n * decision 2), which has its own limits: the arguments, the door and the query are one, the size rule is the tool's.\n */\nexport interface DetailRun {\n /** The root field's value - absent when `error` says why. */\n value?: unknown\n error?: 'argument-unreadable' | 'query-failed' | 'not-found'\n refused?: { name: string; code: string }[]\n message?: string\n}\n\n/** Runs the query as the person with the arguments given - read by their declared types, a missing required one refused. */\nexport async function runDetail(target: DetailRead, args: any, run: GraphqlRunner): Promise<DetailRun> {\n const variables: Record<string, unknown> = {}\n const refused: { name: string; code: string }[] = []\n for (const arg of target.args ?? []) {\n const value = args?.[arg.name]\n if (value === undefined || value === null || value === '') {\n if (arg.required) refused.push({ name: arg.name, code: 'required' })\n continue\n }\n const { read, code } = readFieldValue({ name: arg.name, type: arg.type === 'string' ? 'text' : arg.type, values: arg.values, axis: arg.axis } as any, value)\n if (read === undefined) refused.push({ name: arg.name, code: code ?? 'unreadable' })\n else variables[arg.name] = read\n }\n if (refused.length) return { error: 'argument-unreadable', refused }\n let answer\n try {\n answer = await run(target.query, variables)\n } catch (error: any) {\n return { error: 'query-failed', message: String(error?.message ?? error) }\n }\n if (answer.errors?.length) return { error: 'query-failed', message: answer.errors.map(one => one.message).join('; ') }\n const root = rootFieldOf(target.query, 'query').replace(/^Query\\./, '')\n const value = answer.data?.[root]\n if (value === null || value === undefined) return { error: 'not-found' }\n return { value }\n}\n\n/** Runs the query as the person with the arguments the model set; the answer as the query returned it. */\nexport async function queryDetail(target: DetailRead, args: any, run: GraphqlRunner) {\n const ran = await runDetail(target, args, run)\n if (ran.error) {\n if (ran.error === 'argument-unreadable')\n return { rejected: true, error: 'argument-unreadable', refused: ran.refused, message: `these arguments are missing or do not fit their type: ${ran.refused.map(one => `${one.name} (${one.code})`).join(', ')}. Fix them and call again.` }\n if (ran.error === 'query-failed') return { rejected: true, error: 'query-failed', message: `it could not be read: ${ran.message}` }\n return { target: target.key, found: false, message: 'nothing was found for these arguments - say so; do not fill it in.' }\n }\n const value = ran.value\n const size = JSON.stringify(value).length\n if (size > MAX_DETAIL_CHARS) return { rejected: true, error: 'answer-too-large', size, message: `the answer runs to ${size} characters, more than ${MAX_DETAIL_CHARS} - narrow the arguments, or read the list it is made of.` }\n return { target: target.key, answer: value, message: 'answer from these fields; every number you say comes from them. Amounts are in the currency beside them - never add two currencies into one number.' }\n}\n\nexport function detailCategoryOf(target: DetailRead, run: (context: any) => GraphqlRunner = runAsCaller): ToolCategory {\n const door = rootFieldOf(target.query, 'query')\n const name = detailToolName(target.key)\n return {\n name: readCategoryName(target.key),\n description: `data read: ${target.key}`,\n guidance: `- To answer about ${target.description.replace(/\\.$/, '')}, call ${name}. Every number you say comes from its answer.`,\n specs: [\n {\n kind: 'read',\n name,\n /* The person must be able to run the query on its screen - the tool is not a second way in. */\n doors: [door],\n description: `Read ${target.description}`,\n schema: {\n type: 'object',\n ...((target.args ?? []).some(one => one.required) ? { required: (target.args ?? []).filter(one => one.required).map(one => one.name) } : {}),\n properties: Object.fromEntries((target.args ?? []).map(arg => [arg.name, argSchema(arg)]))\n },\n builder: (args: any, context: any) => queryDetail(target, args, run(context))\n } as ToolSpec\n ]\n }\n}\n\n/** What an application calls at boot to let the assistant read one answer of its API. A mode opens it by key in `readTargets`. */\nexport function registerDetailRead(target: DetailRead): void {\n declareDetailRead(target)\n registerToolCategory(detailCategoryOf(target))\n}\n"]}