@things-factory/ai-dashboard 10.1.278 → 10.1.279

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 (60) hide show
  1. package/package.json +22 -8
  2. package/client/bootstrap.ts +0 -25
  3. package/client/components/card-dialogs.ts +0 -445
  4. package/client/components/card-library.ts +0 -285
  5. package/client/components/dashboard-card.ts +0 -411
  6. package/client/components/proposal-preview.ts +0 -95
  7. package/client/index.ts +0 -5
  8. package/client/pages/my-dashboard-page.ts +0 -373
  9. package/client/route.ts +0 -8
  10. package/client/tsconfig.json +0 -13
  11. package/client/utils/card-api.ts +0 -99
  12. package/client/utils/card-words.ts +0 -91
  13. package/client/utils/examples.ts +0 -15
  14. package/dist-client/bootstrap.js.map +0 -1
  15. package/dist-client/components/card-dialogs.js.map +0 -1
  16. package/dist-client/components/card-library.js.map +0 -1
  17. package/dist-client/components/dashboard-card.js.map +0 -1
  18. package/dist-client/components/proposal-preview.js.map +0 -1
  19. package/dist-client/index.js.map +0 -1
  20. package/dist-client/pages/my-dashboard-page.js.map +0 -1
  21. package/dist-client/route.js.map +0 -1
  22. package/dist-client/tsconfig.tsbuildinfo +0 -1
  23. package/dist-client/utils/card-api.js.map +0 -1
  24. package/dist-client/utils/card-words.js.map +0 -1
  25. package/dist-client/utils/examples.js.map +0 -1
  26. package/dist-server/index.js.map +0 -1
  27. package/dist-server/role-tasks.js.map +0 -1
  28. package/dist-server/service/card/card-access.js.map +0 -1
  29. package/dist-server/service/card/card-definition.js.map +0 -1
  30. package/dist-server/service/card/card-names.js.map +0 -1
  31. package/dist-server/service/card/card-proposal.js.map +0 -1
  32. package/dist-server/service/card/card-resolver.js.map +0 -1
  33. package/dist-server/service/card/card-run.js.map +0 -1
  34. package/dist-server/service/card/card-tool.js.map +0 -1
  35. package/dist-server/service/card/card-types.js.map +0 -1
  36. package/dist-server/service/card/dashboard-card.js.map +0 -1
  37. package/dist-server/service/card/long-text.js.map +0 -1
  38. package/dist-server/service/index.js.map +0 -1
  39. package/dist-server/tsconfig.tsbuildinfo +0 -1
  40. package/server/index.ts +0 -16
  41. package/server/role-tasks.ts +0 -12
  42. package/server/service/card/card-access.test.ts +0 -173
  43. package/server/service/card/card-access.ts +0 -24
  44. package/server/service/card/card-definition.ts +0 -468
  45. package/server/service/card/card-intent.test.ts +0 -285
  46. package/server/service/card/card-names.ts +0 -12
  47. package/server/service/card/card-proposal.ts +0 -46
  48. package/server/service/card/card-resolver.ts +0 -440
  49. package/server/service/card/card-run.test.ts +0 -237
  50. package/server/service/card/card-run.ts +0 -302
  51. package/server/service/card/card-tool.ts +0 -368
  52. package/server/service/card/card-types.ts +0 -145
  53. package/server/service/card/card-words.test.ts +0 -72
  54. package/server/service/card/dashboard-card.ts +0 -303
  55. package/server/service/card/long-text.ts +0 -25
  56. package/server/service/index.ts +0 -16
  57. package/test/card-menu.test.ts +0 -50
  58. package/test/translations.test.ts +0 -42
  59. package/test/words-not-codes.test.ts +0 -24
  60. package/tsconfig.json +0 -9
@@ -1,285 +0,0 @@
1
- /*
2
- * What the assistant wrote looked valid and was wrong (2026-10-25, employee cards on :4700): a status that was two
3
- * values at once, "this month" that summed all time, a strategy card held to one person's name on a read employees do
4
- * not have. And what it could not write: "this month" of a list kept by month, "the last six months", "not one of".
5
- */
6
- import { listReadTarget, readCriteria, type DetailRead } from '@things-factory/ai-assistant'
7
-
8
- import { checkCardIntent, checkDefinition, periodsNamed, resolveRelativeDate, resolveRelativeMonth, resolveWhere, sourceOf, type CardDefinition } from './card-definition'
9
- import { runCard } from './card-run'
10
- import { proposeDashboardCard } from './card-tool'
11
-
12
- /* 내 지출결의 - a list kept by month, the person's own rows. */
13
- let requests: any[]
14
- const myRequests = listReadTarget({
15
- key: 'office.my-expenditure-request',
16
- title: 'menu.my-expenditure-request-list',
17
- name: '내 지출결의',
18
- listQuery: 'myExpenditureRequests',
19
- selection: 'id month status totalAmount dueDate requester { name }',
20
- columns: [
21
- { name: 'month', type: 'string' },
22
- { name: 'status', type: 'string' },
23
- { name: 'requester', path: 'requester.name', type: 'string' },
24
- { name: 'dueDate', type: 'date' },
25
- { name: 'totalAmount', type: 'number', total: true }
26
- ],
27
- monthField: 'month',
28
- status: { field: 'status', values: ['DRAFT', 'SUBMITTED', 'APPROVED', 'REJECTED', 'WITHDRAWN'] },
29
- mine: true
30
- })
31
- /* 경영 과제 - everyone's initiatives, behind the strategy door. */
32
- const initiatives = listReadTarget({
33
- key: 'office.management-initiative-list',
34
- title: 'menu.management-initiative-list',
35
- name: '경영 과제',
36
- listQuery: 'managementInitiatives',
37
- selection: 'id title status owner { name } nextActionDue',
38
- columns: [
39
- { name: 'title', type: 'string' },
40
- { name: 'owner', path: 'owner.name', type: 'string' },
41
- { name: 'status', type: 'string' },
42
- { name: 'nextActionDue', type: 'date' }
43
- ],
44
- dateField: 'nextActionDue'
45
- })
46
- /* 세금계산서 - a ledger narrowed by an integer year and month. */
47
- const taxInvoices = listReadTarget({
48
- key: 'office.tax-invoice',
49
- title: 'menu.tax-invoice-list',
50
- name: '세금계산서',
51
- listQuery: 'officeTaxInvoices',
52
- selection: 'id year month type amount',
53
- columns: [
54
- { name: 'type', type: 'string' },
55
- { name: 'amount', type: 'number', total: true }
56
- ],
57
- narrowing: { year: 'year', month: 'month', flow: 'type' }
58
- })
59
- /* 나의 전략 업무 - one answer holding the person's own lists. */
60
- const myStrategy: DetailRead = {
61
- key: 'office.my-strategy-work',
62
- description: 'the strategy work the person is named on.',
63
- query: 'query { myStrategyWork { initiatives { id title status nextActionDue } } }',
64
- mine: true,
65
- lists: [{ key: 'initiatives', at: 'initiatives', columns: [{ name: 'title', type: 'string' }, { name: 'status', type: 'string' }, { name: 'nextActionDue', type: 'date' }] }]
66
- }
67
-
68
- const targets: Record<string, any> = { [myRequests.key]: myRequests, [initiatives.key]: initiatives }
69
- const readTargetOf = (key: string) => targets[key]
70
- const detailReadOf = (key: string) => (key === myStrategy.key ? myStrategy : undefined)
71
- const sourceFor = (read: string, list?: string) => sourceOf({ read, ...(list ? { list } : {}) }, readTargetOf, detailReadOf).source!
72
-
73
- const calls: any[] = []
74
- const run = async (_document: string, variables: any) => {
75
- calls.push(variables)
76
- const keep = (row: any) =>
77
- (variables.filters ?? []).every((f: any) => (f.operator === 'gte' ? row[f.name] >= f.value : f.operator === 'lte' ? row[f.name] <= f.value : f.operator === 'eq' ? row[f.name] === f.value : true))
78
- const all = requests.filter(keep)
79
- return { data: { myExpenditureRequests: { items: all, total: all.length } } }
80
- }
81
- const deps = { readTargetOf, detailReadOf, passesDoor: async () => true, run, today: '2026-10-25' }
82
-
83
- /* The tool reads the registries; the fakes are declared through them. */
84
- const { declareReadTarget, declareDetailRead, clearReadTargets } = require('@things-factory/ai-assistant')
85
- beforeAll(() => {
86
- clearReadTargets()
87
- declareReadTarget(myRequests)
88
- declareReadTarget(initiatives)
89
- declareDetailRead(myStrategy)
90
- })
91
- afterAll(() => clearReadTargets())
92
-
93
- beforeEach(() => {
94
- calls.length = 0
95
- requests = [
96
- { id: 'e1', month: '2026-04', status: 'APPROVED', totalAmount: 100, requester: { name: '정연희' } },
97
- { id: 'e2', month: '2026-05', status: 'SUBMITTED', totalAmount: 200, requester: { name: '정연희' } },
98
- { id: 'e3', month: '2026-09', status: 'DRAFT', totalAmount: 300, requester: { name: '정연희' } },
99
- { id: 'e4', month: '2026-10', status: 'SUBMITTED', totalAmount: 400, requester: { name: '정연희' } },
100
- { id: 'e5', month: '2026-10', status: 'REJECTED', totalAmount: 500, requester: { name: '정연희' } },
101
- { id: 'e6', month: '2026-10', status: 'WITHDRAWN', totalAmount: 600, requester: { name: '정연희' } }
102
- ]
103
- })
104
-
105
- const def = (over: Partial<CardDefinition>): CardDefinition => ({ schemaVersion: 1, source: { read: myRequests.key }, view: { kind: 'number', values: ['totalAmount'] }, ...over })
106
-
107
- describe('conditions no row can meet are refused', () => {
108
- const source = sourceFor(myRequests.key)
109
- const codes = (definition: CardDefinition) => checkDefinition(definition, source).map(one => one.code)
110
-
111
- it('★ two eq of one column - 작성중 AND 상신 - never hold; one eq is fine, and two ne narrow', () => {
112
- expect(codes(def({ rows: { match: [{ column: 'status', op: 'eq', value: 'DRAFT' }, { column: 'status', op: 'eq', value: 'SUBMITTED' }] } }))).toEqual(['match-never-true'])
113
- expect(codes(def({ rows: { match: [{ column: 'status', op: 'eq', value: 'DRAFT' }, { column: 'status', op: 'eq', value: 'DRAFT' }] } }))).toEqual([])
114
- expect(codes(def({ rows: { match: [{ column: 'status', op: 'ne', value: 'APPROVED' }, { column: 'status', op: 'ne', value: 'REJECTED' }] } }))).toEqual([])
115
- expect(codes(def({ rows: { match: [{ column: 'status', op: 'in', value: ['DRAFT', 'SUBMITTED'] }, { column: 'status', op: 'eq', value: 'APPROVED' }] } }))).toEqual(['match-never-true'])
116
- expect(codes(def({ rows: { match: [{ column: 'status', op: 'in', value: ['DRAFT', 'SUBMITTED'] }, { column: 'status', op: 'eq', value: 'DRAFT' }] } }))).toEqual([])
117
- })
118
-
119
- it('★ in and not_in take a list of values, and nothing else', () => {
120
- expect(codes(def({ rows: { match: [{ column: 'status', op: 'not_in', value: ['APPROVED', 'REJECTED', 'WITHDRAWN'] }] } }))).toEqual([])
121
- expect(codes(def({ rows: { match: [{ column: 'status', op: 'not_in', value: 'APPROVED' }] } }))).toEqual(['match-without-values'])
122
- expect(codes(def({ rows: { match: [{ column: 'status', op: 'in', value: [] }] } }))).toEqual(['match-without-values'])
123
- expect(codes(def({ rows: { match: [{ column: 'status', op: 'eq', value: ['A'] as any }] } }))).toEqual(['match-without-value'])
124
- })
125
- })
126
-
127
- describe('"not one of" is a filter of the card (pending = not approved, rejected or withdrawn)', () => {
128
- it('★ not_in keeps the rows outside the list; in keeps those inside it', async () => {
129
- const pending = await runCard(def({ rows: { match: [{ column: 'status', op: 'not_in', value: ['APPROVED', 'REJECTED', 'WITHDRAWN'] }] } }), deps)
130
- expect(pending.block).toEqual({ kind: 'metrics', items: [{ label: 'totalAmount', value: 900 }] })
131
- const open = await runCard(def({ rows: { match: [{ column: 'status', op: 'in', value: ['DRAFT', 'SUBMITTED'] }] } }), deps)
132
- expect(open.block).toEqual({ kind: 'metrics', items: [{ label: 'totalAmount', value: 900 }] })
133
- })
134
-
135
- it('a number sums every row it keeps - a limit or an order does not cut it', async () => {
136
- const ran = await runCard(def({ rows: { match: [{ column: 'status', op: 'eq', value: 'SUBMITTED' }], sortBy: 'totalAmount', desc: true, limit: 1 } }), deps)
137
- expect(ran.block).toEqual({ kind: 'metrics', items: [{ label: 'totalAmount', value: 600 }] })
138
- })
139
-
140
- it('★ the tool takes the list as values beside the operator', async () => {
141
- const result: any = await proposeDashboardCard(
142
- { name: '결재 대기 지출결의', source: { read: myRequests.key }, rows: { match: [{ column: 'status', op: 'not_in', values: ['APPROVED', 'REJECTED', 'WITHDRAWN'] }] }, view: { kind: 'number', values: ['totalAmount'] } },
143
- { state: { user: { id: 'u-1', name: '정연희' }, domain: { id: 'd1' } } },
144
- { run, passesDoor: async () => true, today: '2026-10-25' }
145
- )
146
- expect(result).toMatchObject({ proposed: true })
147
- expect(result.card.definition.rows.match).toEqual([{ column: 'status', op: 'not_in', value: ['APPROVED', 'REJECTED', 'WITHDRAWN'] }])
148
- })
149
- /* A name over the bound was cut at 100 without a word (inline help audit 2026-10-30) - the model is told to shorten it. */
150
- it('★ a card name over the bound is turned back, not cut', async () => {
151
- const propose = (name: string) =>
152
- proposeDashboardCard(
153
- { name, source: { read: myRequests.key }, view: { kind: 'number', values: ['totalAmount'] } },
154
- { state: { user: { id: 'u-1', name: '정연희' }, domain: { id: 'd1' } } },
155
- { run, passesDoor: async () => true, today: '2026-10-25' }
156
- ) as Promise<any>
157
- expect(await propose('가'.repeat(101))).toMatchObject({ rejected: true, error: 'name-too-long' })
158
- const kept = await propose('가'.repeat(100))
159
- expect(kept).toMatchObject({ proposed: true })
160
- expect(kept.card.name).toBe('가'.repeat(100))
161
- })
162
- })
163
-
164
- describe('a date column that holds a month', () => {
165
- it('★ a pay month is within the days of its month - the first of 「최근 6개월」 is kept', async () => {
166
- const slips: DetailRead = {
167
- key: 'office.my-payslips',
168
- description: 'pay slips.',
169
- query: 'query { myPayslips { payMonth net } }',
170
- mine: true,
171
- lists: [{ key: 'by-month', at: '', columns: [{ name: 'payMonth', type: 'date' }, { name: 'net', type: 'number', total: true }] }]
172
- }
173
- const months = ['2026-04', '2026-05', '2026-06', '2026-07', '2026-08', '2026-09', '2026-10'].map((payMonth, i) => ({ payMonth, net: i + 1 }))
174
- const ran = await runCard(
175
- { schemaVersion: 1, source: { read: slips.key }, rows: { match: [{ column: 'payMonth', op: 'gte', value: '-5m-start' }, { column: 'payMonth', op: 'lte', value: 'this-month-end' }] }, view: { kind: 'table' } },
176
- { readTargetOf: () => undefined, detailReadOf: key => (key === slips.key ? slips : undefined), passesDoor: async () => true, run: async () => ({ data: { myPayslips: months } }), today: '2026-10-25' }
177
- )
178
- expect((ran.block as any).rows.map((row: any) => row.payMonth)).toEqual(['2026-05', '2026-06', '2026-07', '2026-08', '2026-09', '2026-10'])
179
- })
180
- })
181
-
182
- describe('relative periods of a list kept by month', () => {
183
- it('★ months as YYYY-MM - this month, last month, five months ago, this year\'s first and last', () => {
184
- expect(resolveRelativeMonth('this-month', '2026-10-25')).toBe('2026-10')
185
- expect(resolveRelativeMonth('last-month', '2027-01-03')).toBe('2026-12')
186
- expect(resolveRelativeMonth('-5m', '2026-03-10')).toBe('2025-10')
187
- expect(resolveRelativeMonth('this-year-start', '2026-10-25')).toBe('2026-01')
188
- expect(resolveRelativeMonth('last-year-end', '2026-10-25')).toBe('2025-12')
189
- expect(resolveRelativeDate('-5m-start', '2026-03-10')).toBe('2025-10-01')
190
- expect(resolveRelativeDate('-1m-end', '2026-03-10')).toBe('2026-02-28')
191
- })
192
-
193
- it('★ a month condition takes them as YYYY-MM, an integer month as its number', () => {
194
- const source = sourceFor(myRequests.key)
195
- expect(resolveWhere({ periodFrom: '-5m', periodTo: 'this-month', status: 'DRAFT' }, '2026-10-25', source.conditions)).toEqual({ periodFrom: '2026-05', periodTo: '2026-10', status: 'DRAFT' })
196
- expect(resolveWhere({ year: 'this-year', month: 'last-month' }, '2027-01-15')).toEqual({ year: 2026, month: 12 })
197
- })
198
-
199
- it('★ the last six months are read as a range of months from the list', async () => {
200
- const ran = await runCard(def({ source: { read: myRequests.key, where: { periodFrom: '-5m', periodTo: 'this-month' } } }), deps)
201
- expect(calls[0].filters).toEqual([
202
- { name: 'month', operator: 'gte', value: '2026-05' },
203
- { name: 'month', operator: 'lte', value: '2026-10' }
204
- ])
205
- expect(ran.block).toEqual({ kind: 'metrics', items: [{ label: 'totalAmount', value: 2000 }] })
206
- })
207
-
208
- it('★ a relative value on a column that is no date is refused - it is literal text no row holds', () => {
209
- const source = sourceFor(myRequests.key)
210
- const codes = (definition: CardDefinition) => checkDefinition(definition, source).map(one => one.code)
211
- expect(codes(def({ rows: { match: [{ column: 'month', op: 'eq', value: 'this-month' }] } }))).toEqual(['relative-value-on-non-date-column'])
212
- expect(checkDefinition(def({ rows: { match: [{ column: 'month', op: 'eq', value: 'this-month' }] } }), source)[0].params).toMatchObject({ periodConditions: ['period', 'periodFrom', 'periodTo'] })
213
- expect(codes(def({ rows: { match: [{ column: 'dueDate', op: 'gte', value: 'this-month-start' }] } }))).toEqual([])
214
- expect(codes(def({ rows: { match: [{ column: 'dueDate', op: 'gte', value: 'this-month' }] } }))).toEqual(['unknown-relative-value'])
215
- expect(codes(def({ rows: { match: [{ column: 'month', op: 'eq', value: '2026-10' }] } }))).toEqual([])
216
- })
217
-
218
- it('a month condition refuses a day word, and a month that is no YYYY-MM is not read', () => {
219
- const source = sourceFor(myRequests.key)
220
- expect(checkDefinition(def({ source: { read: myRequests.key, where: { period: 'this-month-start' } } }), source).map(one => one.code)).toEqual(['relative-value-unfit'])
221
- expect(readCriteria(myRequests, { period: '2026-10-01' }).refused).toEqual([{ name: 'period', code: 'not-a-month' }])
222
- expect(readCriteria(myRequests, { period: '2026-10' }).criteria).toEqual({ period: '2026-10' })
223
- })
224
- })
225
-
226
- describe('a card means what its name says', () => {
227
- const source = sourceFor(myRequests.key)
228
- const intent = (name: string, definition: CardDefinition, viewer = {}, mine: string[] = []) => checkCardIntent({ name, definition }, source, viewer, mine).map(one => one.code)
229
-
230
- it('the periods a name says, in the languages shipped', () => {
231
- expect(periodsNamed('이번 달 지출 합계')).toEqual(['month'])
232
- expect(periodsNamed('최근 6개월 지출')).toEqual(['months'])
233
- expect(periodsNamed('Spending this year')).toEqual(['year'])
234
- expect(periodsNamed('지출결의 상태별')).toEqual([])
235
- /* When a state is read is no period: the estimate as it stands today needs no condition. */
236
- expect(periodsNamed('내 퇴직금 (오늘 기준)')).toEqual([])
237
- expect(periodsNamed('Severance as of today')).toEqual([])
238
- expect(periodsNamed('오늘 휴가자')).toEqual(['day'])
239
- })
240
-
241
- it('★ "this month" with no condition of the month sums all time - refused, and accepted with one', () => {
242
- expect(intent('이번 달 지출 합계', def({}))).toEqual(['period-without-condition'])
243
- expect(intent('이번 달 지출 합계', def({ source: { read: myRequests.key, where: { period: 'this-month' } } }))).toEqual([])
244
- expect(intent('이번 달 마감 지출', def({ rows: { match: [{ column: 'dueDate', op: 'gte', value: 'this-month-start' }] } }))).toEqual([])
245
- expect(intent('지출 합계', def({}))).toEqual([])
246
- })
247
-
248
- it('★ a period said relatively is not held to fixed days, nor to another period', () => {
249
- expect(intent('이번 달 지출 합계', def({ source: { read: myRequests.key, where: { period: '2026-10' } } }))).toEqual(['period-held-to-fixed-days'])
250
- expect(intent('최근 6개월 지출', def({ source: { read: myRequests.key, where: { period: 'this-month' } } }))).toEqual(['period-unlike-condition'])
251
- /* 「이번 달 세금계산서」 held to year 2026 and month 10 - next month it still says October. */
252
- const invoices = sourceOf({ read: 'office.tax-invoice' }, key => (key === 'office.tax-invoice' ? taxInvoices : undefined), () => undefined).source!
253
- const held = { schemaVersion: 1, source: { read: 'office.tax-invoice', where: { year: 2026, month: 10 } }, view: { kind: 'number', values: ['amount'] } } as CardDefinition
254
- expect(checkCardIntent({ name: '이번 달 세금계산서 매출', definition: held }, invoices).map(one => one.code)).toEqual(['period-held-to-fixed-days'])
255
- expect(checkCardIntent({ name: '이번 달 세금계산서 매출', definition: { ...held, source: { read: 'office.tax-invoice', where: { year: 'this-year', month: 'this-month' } } } }, invoices)).toEqual([])
256
- expect(intent('최근 6개월 지출', def({ source: { read: myRequests.key, where: { periodFrom: '-5m', periodTo: 'this-month' } } }))).toEqual([])
257
- })
258
-
259
- it('★ the viewer\'s own read takes no filter on the viewer - it is theirs whoever looks', () => {
260
- const viewer = { id: 'u-1', name: '정연희', email: 'yh@example.com' }
261
- expect(intent('내 지출', def({ rows: { match: [{ column: 'requester', op: 'eq', value: '정연희' }] } }), viewer)).toEqual(['viewer-filter-on-own-read'])
262
- expect(intent('내 지출', def({ rows: { match: [{ column: 'requester', op: 'eq', value: '김철수' }] } }), viewer)).toEqual([])
263
- })
264
-
265
- it('★ another read held to the viewer\'s name is sent to the viewer\'s own read', () => {
266
- const others = sourceFor(initiatives.key)
267
- const definition: CardDefinition = { schemaVersion: 1, source: { read: initiatives.key }, rows: { match: [{ column: 'owner', op: 'eq', value: '정연희' }] }, view: { kind: 'table' } }
268
- expect(checkCardIntent({ name: '내 경영 과제', definition }, others, { id: 'u-1', name: '정연희' }, ['office.my-strategy-work (list initiatives)'])).toEqual([
269
- { code: 'viewer-filter-use-own-read', params: { filters: ['owner'], mine: ['office.my-strategy-work (list initiatives)'] } }
270
- ])
271
- /* Held to someone else, or with no own read to offer, it is the person's choice. */
272
- expect(checkCardIntent({ name: '김철수의 과제', definition: { ...definition, rows: { match: [{ column: 'owner', op: 'eq', value: '김철수' }] } } }, others, { name: '정연희' }, ['x']).length).toBe(0)
273
- })
274
-
275
- it('★ the tool refuses such a card and says why, in the same answer', async () => {
276
- const result: any = await proposeDashboardCard(
277
- { name: '이번 달 지출 합계', source: { read: myRequests.key }, view: { kind: 'number', values: ['totalAmount'] } },
278
- { state: { user: { id: 'u-1', name: '정연희' }, domain: { id: 'd1' } } },
279
- { run, passesDoor: async () => true, today: '2026-10-25' }
280
- )
281
- expect(result).toMatchObject({ rejected: true, error: 'card-says-otherwise', issues: [{ code: 'period-without-condition' }] })
282
- expect(result.message).toMatch(/this-month/)
283
- expect(result.source.mine).toBeTruthy()
284
- })
285
- })
@@ -1,12 +0,0 @@
1
- /** The names other files of this package and its client share - kept apart so the pure rules load nothing else. */
2
- export const CARD_CATEGORY = 'dashboard-card'
3
- export const CARD_TOOL = 'proposeDashboardCard'
4
- /** The route of the dashboard page - its conversations put the card tool in front. */
5
- export const DASHBOARD_PAGE = 'my-dashboard'
6
- /**
7
- * The axis of a saved card - its key `dashboard-card:<uuid>` is how a picked card is handed to the conversation, like a
8
- * picked row of any list (ai-assistant `selectedRecords`). The client's `CARD_AXIS` (card-words.ts) is the same word.
9
- */
10
- export const CARD_AXIS = 'dashboard-card'
11
- /** A card name's bound - the screen's `maxlength`, refused with the bound on the server, never cut. */
12
- export const CARD_NAME_MAX = 100
@@ -1,46 +0,0 @@
1
- /*
2
- * The card proposals of a conversation - which one a press means, and whether a later one replaced it
3
- * (ADR-0160 decision 9). Pure - tested without a database.
4
- */
5
- import { recordIdOfKey } from '@things-factory/ai-assistant'
6
-
7
- import { CARD_AXIS, CARD_TOOL } from './card-names.js'
8
-
9
- /**
10
- * The saved card a model named - its uuid, written alone or as the key `dashboard-card:<uuid>` a picked card is handed
11
- * by. Nothing for anything else: a key of another record or a name is no card, and is never looked up as one (a
12
- * database whose ids are uuids refuses the lookup itself - the card edit failed on 「card id not uuid」, 2026-10-25).
13
- */
14
- export const cardIdOf = (given: unknown): string | undefined => (typeof given === 'string' ? recordIdOfKey(CARD_AXIS, given) : undefined)
15
-
16
- export interface CardProposal {
17
- key: string
18
- tool: string
19
- kind: string
20
- label?: string
21
- card: {
22
- name: string
23
- description?: string
24
- definition: any
25
- cardId?: string
26
- baseVersion?: number
27
- }
28
- }
29
-
30
- const isCardProposal = (one: any): one is CardProposal => one?.tool === CARD_TOOL && one?.kind === 'dashboard-card' && !!one?.card?.definition
31
-
32
- /** The same card, said again - a change of one saved card, or a new card of the same name. */
33
- const sameCard = (a: CardProposal, b: CardProposal) => (a.card.cardId || b.card.cardId ? a.card.cardId === b.card.cardId : a.card.name === b.card.name)
34
-
35
- /** The proposal a key names in a conversation's messages (oldest first), and whether a later card proposal replaced it. */
36
- export function findCardProposal(messages: readonly { proposals?: any[] | null }[], key: string): { proposal?: CardProposal; superseded: boolean; notACard?: boolean } {
37
- let at = -1
38
- let found: any
39
- messages.forEach((message, i) => {
40
- for (const one of message.proposals ?? []) if (one?.key === key) (at = i), (found = one)
41
- })
42
- if (!found) return { superseded: false }
43
- if (!isCardProposal(found)) return { superseded: false, notACard: true }
44
- const superseded = messages.slice(at + 1).some(message => (message.proposals ?? []).some(one => isCardProposal(one) && sameCard(one, found)))
45
- return { proposal: found, superseded }
46
- }