@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,368 +0,0 @@
1
- /*
2
- * proposeDashboardCard - the assistant writes a card's definition in a conversation; the person saves it by pressing
3
- * the card (ADR-0160 decision 9).
4
- *
5
- * The server checks the definition against the read it names and runs it once as the person, so a card that cannot
6
- * be drawn is sent back with what the read has - never offered. The proposal carries the definition only: the
7
- * preview on the card is run again by whoever looks at the conversation, as themselves (decision 6), and the model
8
- * is told no values - its answer is read by everyone the conversation lets in, whatever door they pass.
9
- */
10
- import { registerToolCategory, type ToolCategory, type ToolSpec } from '@things-factory/ai-client-base'
11
- import {
12
- detailReadKeys,
13
- detailReadOf,
14
- detailToolName,
15
- queryToolName,
16
- readTargetKeys,
17
- readTargetOf,
18
- registerConversationCategory,
19
- runAsCaller,
20
- toolAccessFor
21
- } from '@things-factory/ai-assistant'
22
-
23
- import { CARD_SCHEMA_VERSION, checkCardIntent, checkDefinition, LIST_OPS, MATCH_OPS, sourceOf, todayIn, VIEW_KINDS, type CardDefinition, type CardSource } from './card-definition.js'
24
- import { runCard, shapedColumnNames } from './card-run.js'
25
-
26
- import { CARD_AXIS, CARD_CATEGORY, CARD_NAME_MAX, CARD_TOOL, DASHBOARD_PAGE } from './card-names.js'
27
- import { cardIdOf } from './card-proposal.js'
28
-
29
- export { CARD_CATEGORY, CARD_TOOL, DASHBOARD_PAGE }
30
-
31
- /** What a read offers a card - for a refusal the model fixes the definition from. */
32
- function sourceSheet(source: CardSource, groupBy?: string) {
33
- return {
34
- read: source.key,
35
- ...(source.list ? { list: source.list.key } : {}),
36
- /* What the rows are - a state as of today or a ledger over time - decides whether a period is a filter at all. */
37
- description: source.description,
38
- ...(source.mine ? { mine: 'the rows are the viewer\'s own, whoever looks - no filter on a person' } : {}),
39
- conditions: source.conditions.map(one => ({ name: one.name, type: one.type, ...(one.format ? { format: 'YYYY-MM' } : {}), ...(one.many ? { takes: 'one value or a list' } : {}), ...(one.required ? { required: true } : {}), ...(one.values ? { values: one.values } : {}), ...(one.description ? { description: one.description } : {}) })),
40
- columns: source.columns.map(one => ({ name: one.name, type: one.type, ...(one.currency ? { currency: one.currency } : {}) })),
41
- ...(groupBy ? { columnsAfterGroupBy: [...shapedColumnNames(source, { groupBy }).keys()] } : {})
42
- }
43
- }
44
-
45
- /** The reads a card may name - each list read target and each detail read's list, with the tool the model knows it by. */
46
- export function cardSources(): { read: string; list?: string; tool: string; mine?: true }[] {
47
- return [
48
- ...readTargetKeys().map(key => ({ read: key, tool: queryToolName(key), ...(readTargetOf(key)?.mine ? { mine: true as const } : {}) })),
49
- ...detailReadKeys().flatMap(key => (detailReadOf(key)?.lists ?? []).map(list => ({ read: key, list: list.key, tool: detailToolName(key), ...(detailReadOf(key)?.mine ? { mine: true as const } : {}) })))
50
- ]
51
- }
52
-
53
- /**
54
- * The read a model named - its key, or the name of the tool it reads it with (`queryPlantJobOrder` is `plant.job-order`):
55
- * the model knows reads by their tools, and named the tool as the card's source (2026-10-25, plant).
56
- */
57
- export function readKeyOf(given: unknown): unknown {
58
- if (typeof given !== 'string' || readTargetOf(given) || detailReadOf(given)) return given
59
- return readTargetKeys().find(key => queryToolName(key) === given) ?? detailReadKeys().find(key => detailToolName(key) === given) ?? given
60
- }
61
-
62
- /** A part of a definition without the fields the model left empty - `groupBy: null` is no grouping, not a column named null. */
63
- function withoutEmpty<T extends Record<string, any>>(given: T | undefined): T | undefined {
64
- if (!given || typeof given !== 'object' || Array.isArray(given)) return given
65
- const kept = Object.entries(given).filter(([, value]) => value !== null && value !== undefined && value !== '')
66
- return kept.length ? (Object.fromEntries(kept) as T) : undefined
67
- }
68
-
69
- /** A saved card as a change needs it - whose it is and its version. */
70
- export type CardOf = (id: string) => Promise<{ ownerId?: string; version: number } | undefined>
71
-
72
- /** The card in the person's domain - loaded late so the rules are tested without a database. */
73
- const cardInDomain =
74
- (context: any): CardOf =>
75
- async id => {
76
- const [{ getRepository }, { DashboardCard }] = await Promise.all([import('@things-factory/shell'), import('./dashboard-card.js')])
77
- const card = await getRepository(DashboardCard).findOne({ where: { id, domain: { id: context?.state?.domain?.id } } as any })
78
- return card ? { ownerId: card.ownerId, version: card.version } : undefined
79
- }
80
-
81
- export async function proposeDashboardCard(args: any, context: any, deps: { run?: any; passesDoor?: (door: string) => Promise<boolean>; today?: string; cardOf?: CardOf } = {}) {
82
- const name = typeof args?.name === 'string' ? args.name.trim() : ''
83
- if (!name) return { rejected: true, error: 'no-name', message: 'give the card a short name in the person\'s language.' }
84
- if (name.length > CARD_NAME_MAX) return { rejected: true, error: 'name-too-long', message: `the card name has ${name.length} characters - give one of at most ${CARD_NAME_MAX} and call again now.` }
85
- const where = withoutEmpty(args?.source?.where)
86
- const rows = withoutEmpty(args?.rows)
87
- /* One value, or the list `in` and `not_in` take - kept as the match's value either way. */
88
- if (Array.isArray(rows?.match))
89
- rows.match = rows.match.map((one: any) => {
90
- if (!one || typeof one !== 'object' || !('values' in one)) return one
91
- const { values, ...match } = one
92
- return (LIST_OPS as readonly string[]).includes(match.op) ? { ...match, value: values } : match.value === undefined ? { ...match, value: values } : match
93
- })
94
- const definition: CardDefinition = {
95
- schemaVersion: CARD_SCHEMA_VERSION,
96
- source: { read: readKeyOf(args?.source?.read) as string, ...(args?.source?.list ? { list: args.source.list } : {}), ...(where ? { where } : {}) },
97
- ...(rows ? { rows } : {}),
98
- view: withoutEmpty(args?.view) as any
99
- }
100
- const { source, issue } = sourceOf(definition.source, readTargetOf, detailReadOf)
101
- if (!source) {
102
- return {
103
- rejected: true,
104
- error: issue!.code,
105
- ...issue!.params,
106
- ...(issue!.code === 'unknown-read' || issue!.code === 'not-a-card-source' ? { sources: cardSources() } : {}),
107
- message: 'source.read is one of the sources listed - its read key or its tool (a detail read also names its list). Call again now with one of them.'
108
- }
109
- }
110
- const issues = checkDefinition(definition, source)
111
- if (issues.length) {
112
- return {
113
- rejected: true,
114
- error: 'definition-unfit',
115
- issues,
116
- source: sourceSheet(source, definition.rows?.groupBy),
117
- message:
118
- 'fix every issue against the source below and call again now, in this turn - do not ask the person. source.where takes only the conditions listed (give every required one); ' +
119
- 'a column is filtered with rows.match; a period with no date condition is a rows.match on a date column, or left out when the source is a state as of today.'
120
- }
121
- }
122
- /* What the card says it shows, and whose rows it shows - checked before it runs, so a wrong card is never drawn once. */
123
- const description = typeof args?.description === 'string' ? args.description : undefined
124
- const user = context?.state?.user
125
- const mine = cardSources().filter(one => one.mine).map(one => (one.list ? `${one.read} (list ${one.list})` : one.read))
126
- const intent = checkCardIntent({ name, description, definition }, source, { id: user?.id, name: user?.name, email: user?.email }, mine)
127
- if (intent.length) {
128
- return {
129
- rejected: true,
130
- error: 'card-says-otherwise',
131
- issues: intent,
132
- source: sourceSheet(source, definition.rows?.groupBy),
133
- message:
134
- 'the card would not show what it says - fix each issue and call again now, in this turn. ' +
135
- 'period-without-condition: put the period in source.where with relative values (this-month-start..this-month-end; a YYYY-MM condition this-month; the last 6 months -5m-start..this-month-end) or as a rows.match on a date column - or, when the source is a state as of today, take the period out of the name. ' +
136
- 'period-held-to-fixed-days: use relative values so the card stays current. period-unlike-condition: make the condition the period the name says. ' +
137
- 'viewer-filter-on-own-read: drop the filter - the read is the viewer\'s own whoever looks. viewer-filter-use-own-read: read one of the listed own reads instead, with no filter on the person.'
138
- }
139
- }
140
-
141
- /* A change is of one's own card, from the version it was read at - a newer version is not overwritten unseen. */
142
- const given = typeof args?.cardId === 'string' ? args.cardId.trim() : ''
143
- const cardId = given ? cardIdOf(given) : undefined
144
- if (given && !cardId) return { rejected: true, error: 'card-id-unreadable', cardId: given, message: `cardId is the card's uuid or its key ${CARD_AXIS}:<uuid>, as readDashboardCard gave it - call again now with it.` }
145
- let baseVersion: number | undefined
146
- if (cardId) {
147
- const saved = await (deps.cardOf ?? cardInDomain(context))(cardId)
148
- if (!saved) return { rejected: true, error: 'unknown-card', message: 'there is no such card - leave cardId out to offer a new one.' }
149
- if (saved.ownerId !== context?.state?.user?.id) return { rejected: true, error: 'not-your-card', message: 'only its owner changes a card - offer a new card instead, without cardId.' }
150
- baseVersion = Number.isInteger(args?.baseVersion) ? args.baseVersion : saved.version
151
- if (baseVersion !== saved.version) return { rejected: true, error: 'stale-version', current: saved.version, message: `the card is at version ${saved.version} now - start from it and call again.` }
152
- }
153
-
154
- /* Run once as the person - what cannot be drawn is not offered. */
155
- const ran = await runCard(definition, {
156
- readTargetOf,
157
- detailReadOf,
158
- passesDoor: deps.passesDoor ?? (door => toolAccessFor(context)(door)),
159
- run: deps.run ?? runAsCaller(context),
160
- today: deps.today ?? todayIn(context?.state?.domain?.timezone),
161
- timeZone: context?.state?.domain?.timezone
162
- })
163
- if (ran.issue) {
164
- return { rejected: true, error: ran.issue.code, ...(ran.issue.params ? { params: ran.issue.params } : {}), source: sourceSheet(source, definition.rows?.groupBy), message: 'the card could not be drawn - fix the definition and call again in this turn; say plainly if it cannot be.' }
165
- }
166
- /*
167
- * A table or chart that draws nothing today is offered only when the person asked for something that may be empty - a
168
- * request that expects rows was most likely read wrong (2026-10-24: 「이번 달 미수금」 filtered a state of today by the
169
- * contract date and drew nothing).
170
- */
171
- if (ran.counts && ran.counts.shown === 0 && definition.view.kind !== 'number' && args?.allowEmpty !== true) {
172
- return {
173
- rejected: true,
174
- error: 'draws-nothing',
175
- read: ran.counts.read,
176
- source: sourceSheet(source, definition.rows?.groupBy),
177
- message:
178
- `no row meets these conditions today (${ran.counts.read} read). Read the source's description: a state as of today takes no period filter. ` +
179
- 'Fix the conditions and call again now; only if the person asked for something that may well be empty, call again with allowEmpty: true.'
180
- }
181
- }
182
- /*
183
- * Bars or a line whose names repeat cannot be read - two bars of one customer are two contracts the reader cannot tell
184
- * apart (2026-10-24: 「미수금 상위 5곳」 drew one customer twice). Asked when the card is offered; a saved card draws as
185
- * its data stands.
186
- */
187
- const x: unknown[] = Array.isArray((ran.block as any)?.x) ? (ran.block as any).x : []
188
- if (!definition.rows?.groupBy && new Set(x).size < x.length) {
189
- const label = definition.view.label!
190
- return {
191
- rejected: true,
192
- error: 'label-repeats',
193
- label,
194
- use: `rows.groupBy: '${label}' (and sortBy a summed value)`,
195
- source: sourceSheet(source, label),
196
- message: `the bars' names (${label}) repeat - one name stands for several rows. Group by it so each name is one bar, and call again now, in this turn.`
197
- }
198
- }
199
-
200
- return {
201
- proposed: true,
202
- kind: 'dashboard-card',
203
- icon: 'dashboard_customize',
204
- label: name,
205
- card: {
206
- name,
207
- ...(typeof args?.description === 'string' && args.description.trim() ? { description: args.description.trim().slice(0, 300) } : {}),
208
- definition,
209
- ...(cardId ? { cardId, baseVersion } : {})
210
- },
211
- message:
212
- 'the card is offered with its preview; the person saves it to their dashboard by pressing it. Say in one line what it shows. ' +
213
- 'Do not ask whether to save it, and do not repeat its numbers - the preview shows them to whoever looks.'
214
- }
215
- }
216
-
217
- const COLUMN = { type: 'string' }
218
-
219
- const spec = {
220
- kind: 'read',
221
- name: CARD_TOOL,
222
- /* Only someone who may save a card is offered one. The data's doors are asked when it runs, as the person. */
223
- doors: ['Mutation.saveDashboardCardProposal'],
224
- description:
225
- 'Offer a dashboard card - a definition the person saves to 나의 대시보드, drawn afterwards from the data without you. ' +
226
- 'source.read is a read you have (a list target, or a detail read with source.list naming one of its lists); source.where holds its conditions or arguments - ' +
227
- 'for a period use relative values so the card stays current - a day: today, -30d, this-month-start, this-month-end, last-month-start, this-year-start, -5m-start (the first day five months ago); ' +
228
- 'an integer year or month: this-year, last-month; a month as YYYY-MM: this-month, last-month, -5m. The last 6 months is -5m-start..this-month-end. A name that says a period has that condition. ' +
229
- `rows: match [{column, op: ${MATCH_OPS.join('|')}, value}] - every match holds (two eq of one column never do: use in [..]); not_in [..] for "not one of"; groupBy (a date groups by month), sortBy (a column, or count when grouped), desc, limit. ` +
230
- 'A read marked mine is the viewer\'s own rows, whoever looks - prefer it for "my ..." cards and never filter by a person\'s name or id. ' +
231
- `view.kind: ${VIEW_KINDS.join('|')}; label is the column along the bottom of a chart (the groupBy column by default); values are the number columns summed or drawn (none counts rows); columns lists a table's columns. ` +
232
- 'To change a saved card, pass its cardId and the version you changed as baseVersion.',
233
- schema: {
234
- type: 'object',
235
- properties: {
236
- name: { type: 'string', description: 'The card name, short, in the person\'s language.' },
237
- description: { type: 'string', description: 'One line of what it shows.' },
238
- source: {
239
- type: 'object',
240
- properties: {
241
- read: { type: 'string', description: 'The read - its key (office.receivables) or the tool that reads it (readOfficeReceivables).' },
242
- list: { type: 'string', description: 'A detail read\'s list key.' },
243
- where: { type: 'object', description: 'Conditions or arguments by name; dates may be relative.', additionalProperties: true }
244
- },
245
- required: ['read']
246
- },
247
- rows: {
248
- type: 'object',
249
- properties: {
250
- match: {
251
- type: 'array',
252
- items: {
253
- type: 'object',
254
- properties: {
255
- column: COLUMN,
256
- op: { type: 'string', enum: [...MATCH_OPS] },
257
- value: { type: 'string', description: 'A number, a day, a word or a relative date.' },
258
- values: { type: 'array', items: { type: 'string' }, description: `The values of ${LIST_OPS.join(' and ')}, in place of value.` }
259
- },
260
- required: ['column', 'op']
261
- }
262
- },
263
- groupBy: COLUMN,
264
- sortBy: COLUMN,
265
- desc: { type: 'boolean' },
266
- limit: { type: 'integer' }
267
- }
268
- },
269
- view: {
270
- type: 'object',
271
- properties: {
272
- kind: { type: 'string', enum: [...VIEW_KINDS] },
273
- label: COLUMN,
274
- values: { type: 'array', items: COLUMN },
275
- columns: { type: 'array', items: COLUMN },
276
- unit: { type: 'string' }
277
- },
278
- required: ['kind']
279
- },
280
- allowEmpty: { type: 'boolean', description: 'true only when the person asked for something that may be empty today (overdue items, alerts).' },
281
- cardId: { type: 'string', description: 'A saved card being changed.' },
282
- baseVersion: { type: 'integer', description: 'The version of that card the change starts from.' }
283
- },
284
- required: ['name', 'source', 'view']
285
- },
286
- builder: (args: any, context: any) => proposeDashboardCard(args, context)
287
- } as ToolSpec
288
-
289
- /**
290
- * A saved card's name, version and definition - no values - for a change asked from the dashboard (「AI로 고치기」 picks
291
- * the card; the model reads it here, then offers the changed definition with cardId and baseVersion).
292
- */
293
- export async function readDashboardCard(args: any, context: any, cardOf?: (id: string) => Promise<{ card?: any; access?: string }>) {
294
- const given = typeof args?.id === 'string' ? args.id.trim() : ''
295
- if (!given) return { rejected: true, error: 'no-id', message: 'give the card id the person picked.' }
296
- const id = cardIdOf(given)
297
- if (!id) return { rejected: true, error: 'card-id-unreadable', id: given, message: `a card is named by its key ${CARD_AXIS}:<uuid> (after [keys] dashboardCards) or its uuid - call again now with it.` }
298
- const found = await (cardOf ?? usableInDomain(context))(id)
299
- if (!found?.card) return { rejected: true, error: 'unknown-card', message: 'there is no such card - say so.' }
300
- if (!found.access) return { rejected: true, error: 'card-not-shared', message: 'this card is not shared with the person - say so.' }
301
- const { card, access } = found
302
- return {
303
- id: card.id,
304
- name: card.name,
305
- version: card.version,
306
- access,
307
- definition: card.definition,
308
- message:
309
- access === 'owner'
310
- ? `to change it, call ${CARD_TOOL} with the whole changed definition, cardId "${card.id}" and baseVersion ${card.version}.`
311
- : `the person does not own it - offer a new card (no cardId) made from this definition.`
312
- }
313
- }
314
-
315
- /** A card in the person's domain and how they may use it - loaded late so the rules are tested without a database. */
316
- const usableInDomain =
317
- (context: any) =>
318
- async (id: string): Promise<{ card?: any; access?: string }> => {
319
- const [{ getRepository }, { DashboardCard, DashboardCardShare }, { cardAccessOf }, { audienceMemberOf }] = await Promise.all([
320
- import('@things-factory/shell'),
321
- import('./dashboard-card.js'),
322
- import('./card-access.js'),
323
- import('@things-factory/organization')
324
- ])
325
- const domainId = context?.state?.domain?.id
326
- const card = await getRepository(DashboardCard).findOne({ where: { id, domain: { id: domainId } } as any })
327
- if (!card) return {}
328
- const shares = await getRepository(DashboardCardShare).find({ where: { card: { id: card.id } } as any })
329
- /* The same viewer the card doors see - its roles included, which this read left out until 2026-10-26. */
330
- const { ownDepartments, ...viewer } = await audienceMemberOf(context?.state?.domain, context?.state?.user ?? {})
331
- const access = cardAccessOf(card, viewer, shares)
332
- return { card, access }
333
- }
334
-
335
- const readSpec = {
336
- kind: 'read',
337
- name: 'readDashboardCard',
338
- doors: ['Query.dashboardCardRun'],
339
- description: 'Read a saved dashboard card the person picked - its name, version and definition, never its values - before changing it.',
340
- schema: { type: 'object', properties: { id: { type: 'string', description: 'The card id the person picked.' } }, required: ['id'] },
341
- builder: (args: any, context: any) => readDashboardCard(args, context)
342
- } as ToolSpec
343
-
344
- export const cardCategory: ToolCategory = {
345
- name: CARD_CATEGORY,
346
- description: 'dashboard cards - definitions the person saves and the dashboard draws from the data',
347
- guidance: [
348
- `- When the person asks for a card, a tile, a chart or a table on their dashboard (대시보드 카드, 카드로 만들어 줘), read the data with its read tool to learn its columns, then call ${CARD_TOOL} in the same turn. Never ask whether to make or save it; the card is the answer.`,
349
- `- A card is drawn later from the data as whoever opens it - you are not there. Put periods as relative values in source.where, never today's dates; say "this month" as this-month-start / this-month-end.`,
350
- `- "Top N" is rows.sortBy the amount, desc: true, limit N. Counting customers, places or months (상위 5곳, 거래처별, 월별) is rows.groupBy that column with view.values - each name one bar. Amounts in two currencies are never added - group or match by the currency, or use a column already in won.`,
351
- `- When ${CARD_TOOL} refuses, fix the definition from what it returns and call again in the same turn; if the data cannot be drawn this way, say so in one line.`,
352
- `- When the person picked a dashboard card to change (its id after [keys] dashboardCards), call readDashboardCard, then ${CARD_TOOL} with the whole changed definition, cardId and baseVersion - in the same turn. When the change makes its name untrue (top 5 → top 10), give it a true name.`
353
- ].join('\n'),
354
- specs: [spec, readSpec]
355
- }
356
-
357
- registerToolCategory(cardCategory)
358
- /* In reach of every conversation, in front on the dashboard page and for a picked card (ADR-0061 decision 9). */
359
- registerConversationCategory({
360
- name: CARD_CATEGORY,
361
- frontPages: [DASHBOARD_PAGE],
362
- frontAxes: [CARD_AXIS],
363
- /* FINISH_RULE on this page: the card is what was asked for. */
364
- pageRule:
365
- `This turn is asked from 나의 대시보드, where what the person asks to see - a figure, a total, a count, a list, a chart - is a dashboard card. ` +
366
- `Read what it needs and end the turn with ${CARD_TOOL}, in this turn; never answer with the figure in words, and never ask whether to make it. ` +
367
- `Only a question about the dashboard itself (how to share, how to move a card) is answered in words.`
368
- })
@@ -1,145 +0,0 @@
1
- import { Field, ID, InputType, Int, ObjectType } from 'type-graphql'
2
- import { GraphQLJSON } from 'graphql-scalars'
3
-
4
- import { DashboardCardShareScope } from './dashboard-card.js'
5
-
6
- @ObjectType({ description: 'Who a card is shared with, as its owner sees it.' })
7
- export class DashboardCardShareItem {
8
- @Field(type => DashboardCardShareScope, { description: 'A person, a department, a role or the domain.' })
9
- scope: DashboardCardShareScope
10
-
11
- @Field({ description: 'The user, department, role or domain id.' })
12
- targetId: string
13
-
14
- @Field({ nullable: true, description: 'Its name when it was shared.' })
15
- targetName?: string
16
- }
17
-
18
- @ObjectType({ description: 'A dashboard card as the viewer may use it.' })
19
- export class DashboardCardItem {
20
- @Field(type => ID, { description: 'Card id.' })
21
- id: string
22
-
23
- @Field({ description: 'The card name.' })
24
- name: string
25
-
26
- @Field({ nullable: true, description: 'What it shows, in a line.' })
27
- description?: string
28
-
29
- @Field(type => Int, { description: 'The current version.' })
30
- version: number
31
-
32
- @Field(type => GraphQLJSON, { description: 'The current definition.' })
33
- definition: unknown
34
-
35
- @Field({ description: "'owner' when the viewer made it, 'shared' when it was shared with them." })
36
- access: string
37
-
38
- @Field({ nullable: true, description: 'Who made it.' })
39
- ownerName?: string
40
-
41
- @Field({ nullable: true, description: 'The card it was copied from.' })
42
- copiedFromId?: string
43
-
44
- @Field({ description: 'Whether the viewer has placed it on their dashboard.' })
45
- placed: boolean
46
-
47
- @Field(type => [DashboardCardShareItem], { nullable: true, description: 'Who it is shared with - its owner only.' })
48
- shares?: DashboardCardShareItem[]
49
-
50
- @Field({ nullable: true, description: 'When it was changed last.' })
51
- updatedAt?: Date
52
- }
53
-
54
- @ObjectType({ description: 'One card placed on the viewer\'s dashboard.' })
55
- export class DashboardPlaceItem {
56
- @Field(type => ID, { description: 'Place id.' })
57
- id: string
58
-
59
- @Field(type => Int, { description: 'Its order in the grid.' })
60
- order: number
61
-
62
- @Field(type => Int, { description: 'Columns it spans, 1 to 4.' })
63
- width: number
64
-
65
- @Field(type => Int, { description: 'Rows it spans, 1 to 2.' })
66
- height: number
67
-
68
- @Field(type => DashboardCardItem, { description: 'The card.' })
69
- card: DashboardCardItem
70
- }
71
-
72
- @ObjectType({ description: 'A version of a card, as its owner sees it.' })
73
- export class DashboardCardVersionItem {
74
- @Field(type => Int, { description: 'The version number.' })
75
- version: number
76
-
77
- @Field({ description: 'The name in this version.' })
78
- name: string
79
-
80
- @Field(type => GraphQLJSON, { description: 'The definition in this version.' })
81
- definition: unknown
82
-
83
- @Field({ nullable: true, description: 'Who saved it.' })
84
- creatorName?: string
85
-
86
- @Field({ nullable: true, description: 'When it was saved.' })
87
- createdAt?: Date
88
- }
89
-
90
- @ObjectType({ description: 'A department or person a card may be shared with.' })
91
- export class DashboardShareChoice {
92
- @Field({ description: 'The department id, or the user id of a person.' })
93
- id: string
94
-
95
- @Field({ description: 'The name.' })
96
- name: string
97
-
98
- @Field({ nullable: true, description: 'Where the person works.' })
99
- note?: string
100
- }
101
-
102
- @ObjectType({ description: 'What a card may be shared with by the viewer.' })
103
- export class DashboardShareOptions {
104
- @Field({ description: 'The domain - the whole-domain share names it.' })
105
- domainId: string
106
-
107
- @Field({ description: 'The domain name.' })
108
- domainName: string
109
-
110
- @Field(type => [DashboardShareChoice], { description: "The viewer's own departments." })
111
- departments: DashboardShareChoice[]
112
-
113
- @Field({ description: 'Whether the viewer may look people up to share with them.' })
114
- peopleAvailable: boolean
115
-
116
- @Field(type => [DashboardShareChoice], { description: "The domain's roles, the ones it inherits included - a card shared with one reaches whoever holds it." })
117
- roles: DashboardShareChoice[]
118
- }
119
-
120
- @InputType({ description: 'One share of a card.' })
121
- export class DashboardCardShareInput {
122
- @Field(type => DashboardCardShareScope, { description: 'A person, a department, a role or the domain.' })
123
- scope: DashboardCardShareScope
124
-
125
- @Field({ description: 'The user, department, role or domain id.' })
126
- targetId: string
127
-
128
- @Field({ nullable: true, description: 'Its name, shown to the owner.' })
129
- targetName?: string
130
- }
131
-
132
- @InputType({ description: 'Where one placed card goes.' })
133
- export class DashboardPlaceInput {
134
- @Field(type => ID, { description: 'Place id.' })
135
- id: string
136
-
137
- @Field(type => Int, { description: 'Its order.' })
138
- order: number
139
-
140
- @Field(type => Int, { description: 'Columns, 1 to 4.' })
141
- width: number
142
-
143
- @Field(type => Int, { description: 'Rows, 1 to 2.' })
144
- height: number
145
- }
@@ -1,72 +0,0 @@
1
- /*
2
- * A card shows people words and moments they read (ADR-0163, 2026-10-26: a card of announcements showed EVENT, unread
3
- * and 2026-10-26T09:09:03.235Z) - matched and sorted by the code, drawn by the word in the viewer's language.
4
- */
5
- import { listReadTarget } from '@things-factory/ai-assistant'
6
-
7
- import { runCard, type CardRunDeps } from './card-run'
8
-
9
- const notices = listReadTarget({
10
- key: 'test.notices',
11
- title: 'title.notices',
12
- name: 'notices',
13
- listQuery: 'notices',
14
- selection: 'id title kind state publishedAt',
15
- columns: [
16
- { name: 'title', type: 'string' },
17
- { name: 'kind', type: 'string', words: 'notice.kind.' },
18
- { name: 'state', type: 'string', words: 'notice.state.' },
19
- { name: 'publishedAt', type: 'date' }
20
- ]
21
- })
22
-
23
- const items = [
24
- { id: 'n1', title: '워크숍', kind: 'EVENT', state: 'unread', publishedAt: '2026-10-26T09:09:03.235Z' },
25
- { id: 'n2', title: '휴무', kind: 'HR', state: 'read', publishedAt: '2026-10-25T20:00:00Z' },
26
- { id: 'n3', title: '점검', kind: 'EVENT', state: 'unread', publishedAt: '2026-10-24T01:00:00Z' }
27
- ]
28
- const WORDS: Record<string, string> = { 'notice.kind.HR': '인사', 'notice.kind.EVENT': '행사', 'notice.state.unread': '안 읽음', 'notice.state.read': '읽음' }
29
-
30
- const deps = (over: Partial<CardRunDeps> = {}): CardRunDeps => ({
31
- readTargetOf: key => (key === notices.key ? notices : undefined),
32
- detailReadOf: () => undefined,
33
- passesDoor: async () => true,
34
- run: async () => ({ data: { notices: { items, total: items.length } } }),
35
- today: '2026-10-26',
36
- /* Not this machine's zone - a run that forgot the domain's zone would read the machine's instead. */
37
- timeZone: 'UTC',
38
- words: (key, fallback) => (key && WORDS[key]) || fallback,
39
- ...over
40
- })
41
-
42
- it('★ a table matched by the code shows the words and the moments in the domain\'s time', async () => {
43
- const ran: any = await runCard(
44
- { schemaVersion: 1, source: { read: notices.key }, rows: { match: [{ column: 'state', op: 'eq', value: 'unread' }] }, view: { kind: 'table', columns: ['title', 'kind', 'state', 'publishedAt'] } },
45
- deps()
46
- )
47
- expect(ran.issue).toBeUndefined()
48
- expect(ran.block.rows).toEqual([
49
- { title: '워크숍', kind: '행사', state: '안 읽음', publishedAt: '2026-10-26 09:09' },
50
- { title: '점검', kind: '행사', state: '안 읽음', publishedAt: '2026-10-24 01:00' }
51
- ])
52
- })
53
-
54
- it('★ a chart grouped by a coded column names its bars by the words', async () => {
55
- const ran: any = await runCard({ schemaVersion: 1, source: { read: notices.key }, rows: { groupBy: 'kind' }, view: { kind: 'bar', values: ['count'] } }, deps())
56
- expect(ran.issue).toBeUndefined()
57
- expect([...ran.block.x].sort()).toEqual(['인사', '행사'])
58
- })
59
-
60
- it('a viewer without the words sees the code - never nothing', async () => {
61
- const ran: any = await runCard({ schemaVersion: 1, source: { read: notices.key }, view: { kind: 'table', columns: ['kind'] } }, deps({ words: undefined }))
62
- expect(ran.block.rows.map((one: any) => one.kind)).toEqual(['EVENT', 'HR', 'EVENT'])
63
- })
64
-
65
- it('★ a moment is grouped by the month of the domain\'s time - 31 October 20:00 UTC is November in Seoul', async () => {
66
- const late = [{ id: 'n9', title: '월말', kind: 'HR', state: 'read', publishedAt: '2026-10-31T20:00:00Z' }]
67
- const ran: any = await runCard(
68
- { schemaVersion: 1, source: { read: notices.key }, rows: { groupBy: 'publishedAt' }, view: { kind: 'bar', values: ['count'] } },
69
- deps({ timeZone: 'Asia/Seoul', run: async () => ({ data: { notices: { items: late, total: 1 } } }) })
70
- )
71
- expect(ran.block.x).toEqual(['2026-11'])
72
- })