@things-factory/ai-dashboard 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.
- package/client/components/card-dialogs.ts +24 -1
- package/client/components/dashboard-card.ts +24 -70
- package/client/index.ts +2 -0
- package/client/pages/my-dashboard-page.ts +6 -5
- package/client/utils/card-api.ts +3 -2
- package/client/utils/card-words.ts +11 -0
- package/client/utils/examples.ts +15 -0
- package/dist-client/components/card-dialogs.js +22 -1
- package/dist-client/components/card-dialogs.js.map +1 -1
- package/dist-client/components/dashboard-card.d.ts +6 -5
- package/dist-client/components/dashboard-card.js +23 -73
- package/dist-client/components/dashboard-card.js.map +1 -1
- package/dist-client/index.d.ts +1 -0
- package/dist-client/index.js +2 -0
- package/dist-client/index.js.map +1 -1
- package/dist-client/pages/my-dashboard-page.js +6 -5
- package/dist-client/pages/my-dashboard-page.js.map +1 -1
- package/dist-client/tsconfig.tsbuildinfo +1 -1
- package/dist-client/utils/card-api.d.ts +6 -1
- package/dist-client/utils/card-api.js +1 -1
- package/dist-client/utils/card-api.js.map +1 -1
- package/dist-client/utils/card-words.d.ts +14 -0
- package/dist-client/utils/card-words.js +9 -0
- package/dist-client/utils/card-words.js.map +1 -1
- package/dist-client/utils/examples.d.ts +3 -0
- package/dist-client/utils/examples.js +14 -0
- package/dist-client/utils/examples.js.map +1 -0
- package/dist-server/service/card/card-access.d.ts +8 -2
- package/dist-server/service/card/card-access.js +9 -3
- package/dist-server/service/card/card-access.js.map +1 -1
- package/dist-server/service/card/card-definition.d.ts +42 -6
- package/dist-server/service/card/card-definition.js +172 -18
- package/dist-server/service/card/card-definition.js.map +1 -1
- package/dist-server/service/card/card-names.d.ts +5 -0
- package/dist-server/service/card/card-names.js +6 -1
- package/dist-server/service/card/card-names.js.map +1 -1
- package/dist-server/service/card/card-proposal.d.ts +6 -0
- package/dist-server/service/card/card-proposal.js +9 -0
- package/dist-server/service/card/card-proposal.js.map +1 -1
- package/dist-server/service/card/card-resolver.js +24 -5
- package/dist-server/service/card/card-resolver.js.map +1 -1
- package/dist-server/service/card/card-run.js +5 -1
- package/dist-server/service/card/card-run.js.map +1 -1
- package/dist-server/service/card/card-tool.d.ts +66 -8
- package/dist-server/service/card/card-tool.js +88 -17
- package/dist-server/service/card/card-tool.js.map +1 -1
- package/dist-server/service/card/card-types.d.ts +1 -0
- package/dist-server/service/card/card-types.js +8 -4
- package/dist-server/service/card/card-types.js.map +1 -1
- package/dist-server/service/card/dashboard-card.d.ts +2 -0
- package/dist-server/service/card/dashboard-card.js +5 -3
- package/dist-server/service/card/dashboard-card.js.map +1 -1
- package/dist-server/tsconfig.tsbuildinfo +1 -1
- package/package.json +5 -5
- package/server/service/card/card-access.test.ts +62 -7
- package/server/service/card/card-access.ts +12 -5
- package/server/service/card/card-definition.ts +182 -18
- package/server/service/card/card-intent.test.ts +250 -0
- package/server/service/card/card-names.ts +5 -0
- package/server/service/card/card-proposal.ts +10 -1
- package/server/service/card/card-resolver.ts +26 -8
- package/server/service/card/card-run.ts +5 -1
- package/server/service/card/card-tool.ts +91 -20
- package/server/service/card/card-types.ts +7 -4
- package/server/service/card/dashboard-card.ts +5 -3
- package/test/card-menu.test.ts +34 -0
- package/test/translations.test.ts +1 -1
- package/translations/en.json +3 -3
- package/translations/es.json +3 -3
- package/translations/ja.json +3 -3
- package/translations/ko.json +3 -3
- package/translations/ms.json +3 -3
- package/translations/zh.json +3 -3
|
@@ -0,0 +1,250 @@
|
|
|
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
|
+
})
|
|
150
|
+
|
|
151
|
+
describe('relative periods of a list kept by month', () => {
|
|
152
|
+
it('★ months as YYYY-MM - this month, last month, five months ago, this year\'s first and last', () => {
|
|
153
|
+
expect(resolveRelativeMonth('this-month', '2026-10-25')).toBe('2026-10')
|
|
154
|
+
expect(resolveRelativeMonth('last-month', '2027-01-03')).toBe('2026-12')
|
|
155
|
+
expect(resolveRelativeMonth('-5m', '2026-03-10')).toBe('2025-10')
|
|
156
|
+
expect(resolveRelativeMonth('this-year-start', '2026-10-25')).toBe('2026-01')
|
|
157
|
+
expect(resolveRelativeMonth('last-year-end', '2026-10-25')).toBe('2025-12')
|
|
158
|
+
expect(resolveRelativeDate('-5m-start', '2026-03-10')).toBe('2025-10-01')
|
|
159
|
+
expect(resolveRelativeDate('-1m-end', '2026-03-10')).toBe('2026-02-28')
|
|
160
|
+
})
|
|
161
|
+
|
|
162
|
+
it('★ a month condition takes them as YYYY-MM, an integer month as its number', () => {
|
|
163
|
+
const source = sourceFor(myRequests.key)
|
|
164
|
+
expect(resolveWhere({ periodFrom: '-5m', periodTo: 'this-month', status: 'DRAFT' }, '2026-10-25', source.conditions)).toEqual({ periodFrom: '2026-05', periodTo: '2026-10', status: 'DRAFT' })
|
|
165
|
+
expect(resolveWhere({ year: 'this-year', month: 'last-month' }, '2027-01-15')).toEqual({ year: 2026, month: 12 })
|
|
166
|
+
})
|
|
167
|
+
|
|
168
|
+
it('★ the last six months are read as a range of months from the list', async () => {
|
|
169
|
+
const ran = await runCard(def({ source: { read: myRequests.key, where: { periodFrom: '-5m', periodTo: 'this-month' } } }), deps)
|
|
170
|
+
expect(calls[0].filters).toEqual([
|
|
171
|
+
{ name: 'month', operator: 'gte', value: '2026-05' },
|
|
172
|
+
{ name: 'month', operator: 'lte', value: '2026-10' }
|
|
173
|
+
])
|
|
174
|
+
expect(ran.block).toEqual({ kind: 'metrics', items: [{ label: 'totalAmount', value: 2000 }] })
|
|
175
|
+
})
|
|
176
|
+
|
|
177
|
+
it('★ a relative value on a column that is no date is refused - it is literal text no row holds', () => {
|
|
178
|
+
const source = sourceFor(myRequests.key)
|
|
179
|
+
const codes = (definition: CardDefinition) => checkDefinition(definition, source).map(one => one.code)
|
|
180
|
+
expect(codes(def({ rows: { match: [{ column: 'month', op: 'eq', value: 'this-month' }] } }))).toEqual(['relative-value-on-non-date-column'])
|
|
181
|
+
expect(checkDefinition(def({ rows: { match: [{ column: 'month', op: 'eq', value: 'this-month' }] } }), source)[0].params).toMatchObject({ periodConditions: ['period', 'periodFrom', 'periodTo'] })
|
|
182
|
+
expect(codes(def({ rows: { match: [{ column: 'dueDate', op: 'gte', value: 'this-month-start' }] } }))).toEqual([])
|
|
183
|
+
expect(codes(def({ rows: { match: [{ column: 'dueDate', op: 'gte', value: 'this-month' }] } }))).toEqual(['unknown-relative-value'])
|
|
184
|
+
expect(codes(def({ rows: { match: [{ column: 'month', op: 'eq', value: '2026-10' }] } }))).toEqual([])
|
|
185
|
+
})
|
|
186
|
+
|
|
187
|
+
it('a month condition refuses a day word, and a month that is no YYYY-MM is not read', () => {
|
|
188
|
+
const source = sourceFor(myRequests.key)
|
|
189
|
+
expect(checkDefinition(def({ source: { read: myRequests.key, where: { period: 'this-month-start' } } }), source).map(one => one.code)).toEqual(['relative-value-unfit'])
|
|
190
|
+
expect(readCriteria(myRequests, { period: '2026-10-01' }).refused).toEqual([{ name: 'period', code: 'not-a-month' }])
|
|
191
|
+
expect(readCriteria(myRequests, { period: '2026-10' }).criteria).toEqual({ period: '2026-10' })
|
|
192
|
+
})
|
|
193
|
+
})
|
|
194
|
+
|
|
195
|
+
describe('a card means what its name says', () => {
|
|
196
|
+
const source = sourceFor(myRequests.key)
|
|
197
|
+
const intent = (name: string, definition: CardDefinition, viewer = {}, mine: string[] = []) => checkCardIntent({ name, definition }, source, viewer, mine).map(one => one.code)
|
|
198
|
+
|
|
199
|
+
it('the periods a name says, in the languages shipped', () => {
|
|
200
|
+
expect(periodsNamed('이번 달 지출 합계')).toEqual(['month'])
|
|
201
|
+
expect(periodsNamed('최근 6개월 지출')).toEqual(['months'])
|
|
202
|
+
expect(periodsNamed('Spending this year')).toEqual(['year'])
|
|
203
|
+
expect(periodsNamed('지출결의 상태별')).toEqual([])
|
|
204
|
+
})
|
|
205
|
+
|
|
206
|
+
it('★ "this month" with no condition of the month sums all time - refused, and accepted with one', () => {
|
|
207
|
+
expect(intent('이번 달 지출 합계', def({}))).toEqual(['period-without-condition'])
|
|
208
|
+
expect(intent('이번 달 지출 합계', def({ source: { read: myRequests.key, where: { period: 'this-month' } } }))).toEqual([])
|
|
209
|
+
expect(intent('이번 달 마감 지출', def({ rows: { match: [{ column: 'dueDate', op: 'gte', value: 'this-month-start' }] } }))).toEqual([])
|
|
210
|
+
expect(intent('지출 합계', def({}))).toEqual([])
|
|
211
|
+
})
|
|
212
|
+
|
|
213
|
+
it('★ a period said relatively is not held to fixed days, nor to another period', () => {
|
|
214
|
+
expect(intent('이번 달 지출 합계', def({ source: { read: myRequests.key, where: { period: '2026-10' } } }))).toEqual(['period-held-to-fixed-days'])
|
|
215
|
+
expect(intent('최근 6개월 지출', def({ source: { read: myRequests.key, where: { period: 'this-month' } } }))).toEqual(['period-unlike-condition'])
|
|
216
|
+
/* 「이번 달 세금계산서」 held to year 2026 and month 10 - next month it still says October. */
|
|
217
|
+
const invoices = sourceOf({ read: 'office.tax-invoice' }, key => (key === 'office.tax-invoice' ? taxInvoices : undefined), () => undefined).source!
|
|
218
|
+
const held = { schemaVersion: 1, source: { read: 'office.tax-invoice', where: { year: 2026, month: 10 } }, view: { kind: 'number', values: ['amount'] } } as CardDefinition
|
|
219
|
+
expect(checkCardIntent({ name: '이번 달 세금계산서 매출', definition: held }, invoices).map(one => one.code)).toEqual(['period-held-to-fixed-days'])
|
|
220
|
+
expect(checkCardIntent({ name: '이번 달 세금계산서 매출', definition: { ...held, source: { read: 'office.tax-invoice', where: { year: 'this-year', month: 'this-month' } } } }, invoices)).toEqual([])
|
|
221
|
+
expect(intent('최근 6개월 지출', def({ source: { read: myRequests.key, where: { periodFrom: '-5m', periodTo: 'this-month' } } }))).toEqual([])
|
|
222
|
+
})
|
|
223
|
+
|
|
224
|
+
it('★ the viewer\'s own read takes no filter on the viewer - it is theirs whoever looks', () => {
|
|
225
|
+
const viewer = { id: 'u-1', name: '정연희', email: 'yh@example.com' }
|
|
226
|
+
expect(intent('내 지출', def({ rows: { match: [{ column: 'requester', op: 'eq', value: '정연희' }] } }), viewer)).toEqual(['viewer-filter-on-own-read'])
|
|
227
|
+
expect(intent('내 지출', def({ rows: { match: [{ column: 'requester', op: 'eq', value: '김철수' }] } }), viewer)).toEqual([])
|
|
228
|
+
})
|
|
229
|
+
|
|
230
|
+
it('★ another read held to the viewer\'s name is sent to the viewer\'s own read', () => {
|
|
231
|
+
const others = sourceFor(initiatives.key)
|
|
232
|
+
const definition: CardDefinition = { schemaVersion: 1, source: { read: initiatives.key }, rows: { match: [{ column: 'owner', op: 'eq', value: '정연희' }] }, view: { kind: 'table' } }
|
|
233
|
+
expect(checkCardIntent({ name: '내 경영 과제', definition }, others, { id: 'u-1', name: '정연희' }, ['office.my-strategy-work (list initiatives)'])).toEqual([
|
|
234
|
+
{ code: 'viewer-filter-use-own-read', params: { filters: ['owner'], mine: ['office.my-strategy-work (list initiatives)'] } }
|
|
235
|
+
])
|
|
236
|
+
/* Held to someone else, or with no own read to offer, it is the person's choice. */
|
|
237
|
+
expect(checkCardIntent({ name: '김철수의 과제', definition: { ...definition, rows: { match: [{ column: 'owner', op: 'eq', value: '김철수' }] } } }, others, { name: '정연희' }, ['x']).length).toBe(0)
|
|
238
|
+
})
|
|
239
|
+
|
|
240
|
+
it('★ the tool refuses such a card and says why, in the same answer', async () => {
|
|
241
|
+
const result: any = await proposeDashboardCard(
|
|
242
|
+
{ name: '이번 달 지출 합계', source: { read: myRequests.key }, view: { kind: 'number', values: ['totalAmount'] } },
|
|
243
|
+
{ state: { user: { id: 'u-1', name: '정연희' }, domain: { id: 'd1' } } },
|
|
244
|
+
{ run, passesDoor: async () => true, today: '2026-10-25' }
|
|
245
|
+
)
|
|
246
|
+
expect(result).toMatchObject({ rejected: true, error: 'card-says-otherwise', issues: [{ code: 'period-without-condition' }] })
|
|
247
|
+
expect(result.message).toMatch(/this-month/)
|
|
248
|
+
expect(result.source.mine).toBeTruthy()
|
|
249
|
+
})
|
|
250
|
+
})
|
|
@@ -3,3 +3,8 @@ export const CARD_CATEGORY = 'dashboard-card'
|
|
|
3
3
|
export const CARD_TOOL = 'proposeDashboardCard'
|
|
4
4
|
/** The route of the dashboard page - its conversations put the card tool in front. */
|
|
5
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'
|
|
@@ -2,7 +2,16 @@
|
|
|
2
2
|
* The card proposals of a conversation - which one a press means, and whether a later one replaced it
|
|
3
3
|
* (ADR-0160 decision 9). Pure - tested without a database.
|
|
4
4
|
*/
|
|
5
|
-
import {
|
|
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)
|
|
6
15
|
|
|
7
16
|
export interface CardProposal {
|
|
8
17
|
key: string
|
|
@@ -10,8 +10,8 @@ import { Arg, Ctx, Directive, Int, Mutation, Query, Resolver } from 'type-graphq
|
|
|
10
10
|
import { GraphQLJSON } from 'graphql-scalars'
|
|
11
11
|
import { In, IsNull, Not } from 'typeorm'
|
|
12
12
|
|
|
13
|
-
import { getRepository } from '@things-factory/shell'
|
|
14
|
-
import { User } from '@things-factory/auth-base'
|
|
13
|
+
import { applyDomainInheritanceFilter, getRepository, InheritedValueType } from '@things-factory/shell'
|
|
14
|
+
import { Role, User } from '@things-factory/auth-base'
|
|
15
15
|
import {
|
|
16
16
|
assertMayWriteSession,
|
|
17
17
|
ChatMessage,
|
|
@@ -27,7 +27,7 @@ import {
|
|
|
27
27
|
|
|
28
28
|
import { cardAccessOf, departmentsOfEmployees, shareRefusal, type CardAccess, type CardViewer } from './card-access.js'
|
|
29
29
|
import { CARD_SCHEMA_VERSION, checkDefinition, sourceOf, todayIn, type CardDefinition } from './card-definition.js'
|
|
30
|
-
import { findCardProposal } from './card-proposal.js'
|
|
30
|
+
import { cardIdOf, findCardProposal } from './card-proposal.js'
|
|
31
31
|
import { runCard, type CardRunResult } from './card-run.js'
|
|
32
32
|
import { DashboardCard, DashboardCardPlace, DashboardCardShare, DashboardCardShareScope, DashboardCardVersion } from './dashboard-card.js'
|
|
33
33
|
import { DashboardCardItem, DashboardCardShareInput, DashboardCardVersionItem, DashboardPlaceInput, DashboardPlaceItem, DashboardShareChoice, DashboardShareOptions } from './card-types.js'
|
|
@@ -47,6 +47,17 @@ function refuse(context: ResolverContext, code: string, fallback: string, option
|
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
/** The viewer of a request, with the departments they belong to for sharing - asked once per request. */
|
|
50
|
+
/**
|
|
51
|
+
* The roles of the domain - the ones it inherits from its parent included, as its privileges are (User.getPrivilegesByDomain);
|
|
52
|
+
* `holder` keeps those one person holds.
|
|
53
|
+
*/
|
|
54
|
+
async function domainRoles(context: ResolverContext, holder?: string, tx?: any): Promise<Role[]> {
|
|
55
|
+
const qb = getRepository(Role, tx).createQueryBuilder('ROLE')
|
|
56
|
+
if (holder) qb.innerJoin('ROLE.users', 'HOLDER', 'HOLDER.id = :holder', { holder })
|
|
57
|
+
applyDomainInheritanceFilter(qb, 'ROLE', context.state.domain as any, InheritedValueType.Include)
|
|
58
|
+
return await qb.orderBy('ROLE.name').getMany()
|
|
59
|
+
}
|
|
60
|
+
|
|
50
61
|
async function viewerOf(context: ResolverContext): Promise<{ viewer: CardViewer; departmentsAvailable: boolean; departments: { id: string; name: string }[] }> {
|
|
51
62
|
const state: any = context.state
|
|
52
63
|
if (state.__aiDashboardViewer) return state.__aiDashboardViewer
|
|
@@ -60,8 +71,9 @@ async function viewerOf(context: ResolverContext): Promise<{ viewer: CardViewer;
|
|
|
60
71
|
}
|
|
61
72
|
const departmentIds = departmentsOfEmployees(records)
|
|
62
73
|
const departments = departmentIds.map(id => ({ id, name: records!.find(one => one?.department?.id === id)?.department?.name ?? id }))
|
|
74
|
+
const roleIds = state.user?.id ? (await domainRoles(context, state.user.id)).map(one => one.id) : []
|
|
63
75
|
const answer = {
|
|
64
|
-
viewer: { userId: state.user?.id, domainId: state.domain?.id, departmentIds },
|
|
76
|
+
viewer: { userId: state.user?.id, domainId: state.domain?.id, departmentIds, roleIds },
|
|
65
77
|
departmentsAvailable: records !== undefined,
|
|
66
78
|
departments
|
|
67
79
|
}
|
|
@@ -73,7 +85,10 @@ const sharesOf = async (cardIds: string[], tx?: any) =>
|
|
|
73
85
|
cardIds.length ? await getRepository(DashboardCardShare, tx).find({ where: { card: { id: In(cardIds) } } as any }) : []
|
|
74
86
|
|
|
75
87
|
/** A card the viewer may use, and how - refused otherwise (decision 7). */
|
|
76
|
-
async function usableCard(
|
|
88
|
+
async function usableCard(given: string, context: ResolverContext, tx?: any): Promise<{ card: DashboardCard; access: CardAccess }> {
|
|
89
|
+
/* A card's uuid or its key - anything else is no card, and is not handed to a database that refuses it as no uuid. */
|
|
90
|
+
const id = cardIdOf(given)
|
|
91
|
+
if (!id) refuse(context, 'unknown-card', 'there is no such card.')
|
|
77
92
|
const card = await getRepository(DashboardCard, tx).findOne({ where: { id, domain: { id: context.state.domain.id } } as any })
|
|
78
93
|
if (!card) refuse(context, 'unknown-card', 'there is no such card.')
|
|
79
94
|
const { viewer } = await viewerOf(context)
|
|
@@ -183,7 +198,8 @@ export class DashboardCardResolver {
|
|
|
183
198
|
where: [
|
|
184
199
|
{ domain: { id: viewer.domainId }, scope: DashboardCardShareScope.USER, targetId: viewer.userId },
|
|
185
200
|
{ domain: { id: viewer.domainId }, scope: DashboardCardShareScope.DOMAIN, targetId: viewer.domainId },
|
|
186
|
-
...(viewer.departmentIds.length ? [{ domain: { id: viewer.domainId }, scope: DashboardCardShareScope.DEPARTMENT, targetId: In([...viewer.departmentIds]) }] : [])
|
|
201
|
+
...(viewer.departmentIds.length ? [{ domain: { id: viewer.domainId }, scope: DashboardCardShareScope.DEPARTMENT, targetId: In([...viewer.departmentIds]) }] : []),
|
|
202
|
+
...(viewer.roleIds?.length ? [{ domain: { id: viewer.domainId }, scope: DashboardCardShareScope.ROLE, targetId: In([...viewer.roleIds]) }] : [])
|
|
187
203
|
] as any
|
|
188
204
|
})
|
|
189
205
|
const ids = [...new Set(shares.map(one => one.cardId))]
|
|
@@ -217,7 +233,8 @@ export class DashboardCardResolver {
|
|
|
217
233
|
domainName: domain.name ?? domain.subdomain ?? domain.id,
|
|
218
234
|
departmentsAvailable,
|
|
219
235
|
departments,
|
|
220
|
-
peopleAvailable: await toolAccessFor(context)('Query.employees')
|
|
236
|
+
peopleAvailable: await toolAccessFor(context)('Query.employees'),
|
|
237
|
+
roles: (await domainRoles(context)).map(one => ({ id: one.id, name: one.name, ...(one.description ? { note: one.description } : {}) }))
|
|
221
238
|
}
|
|
222
239
|
}
|
|
223
240
|
|
|
@@ -365,9 +382,10 @@ export class DashboardCardResolver {
|
|
|
365
382
|
const { domain, user, tx } = context.state as any
|
|
366
383
|
const card = await ownCard(id, context, tx)
|
|
367
384
|
const { departmentsAvailable } = await viewerOf(context)
|
|
385
|
+
const roleIds = (shares ?? []).some(one => one.scope === DashboardCardShareScope.ROLE) ? (await domainRoles(context, undefined, tx)).map(one => one.id) : []
|
|
368
386
|
const wanted = new Map<string, DashboardCardShareInput>()
|
|
369
387
|
for (const share of shares ?? []) {
|
|
370
|
-
const refusal = shareRefusal(share, { domainId: domain.id, departmentsAvailable })
|
|
388
|
+
const refusal = shareRefusal(share, { domainId: domain.id, departmentsAvailable, roleIds })
|
|
371
389
|
if (refusal) refuse(context, `share-${refusal}`, 'this share cannot be given ({code}).', { code: refusal })
|
|
372
390
|
if (share.scope === DashboardCardShareScope.USER && share.targetId === user.id) continue
|
|
373
391
|
wanted.set(`${share.scope}:${share.targetId}`, share)
|
|
@@ -82,6 +82,10 @@ const compare = (a: unknown, b: unknown): number => {
|
|
|
82
82
|
|
|
83
83
|
function matches(row: Row, column: ReadColumn, op: string, given: unknown, today: string): boolean {
|
|
84
84
|
const cell = row[column.name]
|
|
85
|
+
if (op === 'in' || op === 'not_in') {
|
|
86
|
+
const listed = (given as unknown[]).some(one => (column.type === 'number' ? Number(cell) === Number(one) : String(cell ?? '') === String(one)))
|
|
87
|
+
return op === 'in' ? listed : !listed
|
|
88
|
+
}
|
|
85
89
|
const value = column.type === 'date' && isRelativeDate(given) ? resolveRelativeDate(given as string, today) : given
|
|
86
90
|
if (op === 'eq') return column.type === 'number' ? Number(cell) === Number(value) : String(cell ?? '') === String(value)
|
|
87
91
|
if (op === 'ne') return column.type === 'number' ? Number(cell) !== Number(value) : String(cell ?? '') !== String(value)
|
|
@@ -197,7 +201,7 @@ export async function runCard(definition: CardDefinition, deps: CardRunDeps): Pr
|
|
|
197
201
|
/* ① The viewer may read this source at all - a shared card gives the definition, never the data (decision 6). */
|
|
198
202
|
if (!(await deps.passesDoor(rootFieldOf(source.query, 'query')))) return { issue: { code: 'door-closed' }, asOf, source: about }
|
|
199
203
|
|
|
200
|
-
const read = await readSource(source, resolveWhere(definition.source.where, asOf), deps)
|
|
204
|
+
const read = await readSource(source, resolveWhere(definition.source.where, asOf, source.conditions), deps)
|
|
201
205
|
if (read.issue) return { issue: read.issue, asOf, source: about }
|
|
202
206
|
const rowsDef = definition.rows ?? {}
|
|
203
207
|
const view = definition.view
|
|
@@ -11,6 +11,8 @@ import { registerToolCategory, type ToolCategory, type ToolSpec } from '@things-
|
|
|
11
11
|
import {
|
|
12
12
|
detailReadKeys,
|
|
13
13
|
detailReadOf,
|
|
14
|
+
detailToolName,
|
|
15
|
+
queryToolName,
|
|
14
16
|
readTargetKeys,
|
|
15
17
|
readTargetOf,
|
|
16
18
|
registerConversationCategory,
|
|
@@ -18,10 +20,11 @@ import {
|
|
|
18
20
|
toolAccessFor
|
|
19
21
|
} from '@things-factory/ai-assistant'
|
|
20
22
|
|
|
21
|
-
import { CARD_SCHEMA_VERSION, checkDefinition, MATCH_OPS, sourceOf, todayIn, VIEW_KINDS, type CardDefinition, type CardSource } from './card-definition.js'
|
|
23
|
+
import { CARD_SCHEMA_VERSION, checkCardIntent, checkDefinition, LIST_OPS, MATCH_OPS, sourceOf, todayIn, VIEW_KINDS, type CardDefinition, type CardSource } from './card-definition.js'
|
|
22
24
|
import { runCard, shapedColumnNames } from './card-run.js'
|
|
23
25
|
|
|
24
|
-
import { CARD_CATEGORY, CARD_TOOL, DASHBOARD_PAGE } from './card-names.js'
|
|
26
|
+
import { CARD_AXIS, CARD_CATEGORY, CARD_TOOL, DASHBOARD_PAGE } from './card-names.js'
|
|
27
|
+
import { cardIdOf } from './card-proposal.js'
|
|
25
28
|
|
|
26
29
|
export { CARD_CATEGORY, CARD_TOOL, DASHBOARD_PAGE }
|
|
27
30
|
|
|
@@ -32,20 +35,37 @@ function sourceSheet(source: CardSource, groupBy?: string) {
|
|
|
32
35
|
...(source.list ? { list: source.list.key } : {}),
|
|
33
36
|
/* What the rows are - a state as of today or a ledger over time - decides whether a period is a filter at all. */
|
|
34
37
|
description: source.description,
|
|
35
|
-
|
|
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 } : {}) })),
|
|
36
40
|
columns: source.columns.map(one => ({ name: one.name, type: one.type, ...(one.currency ? { currency: one.currency } : {}) })),
|
|
37
41
|
...(groupBy ? { columnsAfterGroupBy: [...shapedColumnNames(source, { groupBy }).keys()] } : {})
|
|
38
42
|
}
|
|
39
43
|
}
|
|
40
44
|
|
|
41
|
-
/** The reads a card may name - list read
|
|
42
|
-
export function cardSources(): string[] {
|
|
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 }[] {
|
|
43
47
|
return [
|
|
44
|
-
...readTargetKeys(),
|
|
45
|
-
...detailReadKeys().flatMap(key => (detailReadOf(key)?.lists ?? []).map(list =>
|
|
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 } : {}) })))
|
|
46
50
|
]
|
|
47
51
|
}
|
|
48
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
|
+
|
|
49
69
|
/** A saved card as a change needs it - whose it is and its version. */
|
|
50
70
|
export type CardOf = (id: string) => Promise<{ ownerId?: string; version: number } | undefined>
|
|
51
71
|
|
|
@@ -61,11 +81,20 @@ const cardInDomain =
|
|
|
61
81
|
export async function proposeDashboardCard(args: any, context: any, deps: { run?: any; passesDoor?: (door: string) => Promise<boolean>; today?: string; cardOf?: CardOf } = {}) {
|
|
62
82
|
const name = typeof args?.name === 'string' ? args.name.trim().slice(0, 100) : ''
|
|
63
83
|
if (!name) return { rejected: true, error: 'no-name', message: 'give the card a short name in the person\'s language.' }
|
|
84
|
+
const where = withoutEmpty(args?.source?.where)
|
|
85
|
+
const rows = withoutEmpty(args?.rows)
|
|
86
|
+
/* One value, or the list `in` and `not_in` take - kept as the match's value either way. */
|
|
87
|
+
if (Array.isArray(rows?.match))
|
|
88
|
+
rows.match = rows.match.map((one: any) => {
|
|
89
|
+
if (!one || typeof one !== 'object' || !('values' in one)) return one
|
|
90
|
+
const { values, ...match } = one
|
|
91
|
+
return (LIST_OPS as readonly string[]).includes(match.op) ? { ...match, value: values } : match.value === undefined ? { ...match, value: values } : match
|
|
92
|
+
})
|
|
64
93
|
const definition: CardDefinition = {
|
|
65
94
|
schemaVersion: CARD_SCHEMA_VERSION,
|
|
66
|
-
source: { read: args?.source?.read, ...(args?.source?.list ? { list: args.source.list } : {}), ...(
|
|
67
|
-
...(
|
|
68
|
-
view: args?.view
|
|
95
|
+
source: { read: readKeyOf(args?.source?.read) as string, ...(args?.source?.list ? { list: args.source.list } : {}), ...(where ? { where } : {}) },
|
|
96
|
+
...(rows ? { rows } : {}),
|
|
97
|
+
view: withoutEmpty(args?.view) as any
|
|
69
98
|
}
|
|
70
99
|
const { source, issue } = sourceOf(definition.source, readTargetOf, detailReadOf)
|
|
71
100
|
if (!source) {
|
|
@@ -74,7 +103,7 @@ export async function proposeDashboardCard(args: any, context: any, deps: { run?
|
|
|
74
103
|
error: issue!.code,
|
|
75
104
|
...issue!.params,
|
|
76
105
|
...(issue!.code === 'unknown-read' || issue!.code === 'not-a-card-source' ? { sources: cardSources() } : {}),
|
|
77
|
-
message: '
|
|
106
|
+
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.'
|
|
78
107
|
}
|
|
79
108
|
}
|
|
80
109
|
const issues = checkDefinition(definition, source)
|
|
@@ -89,9 +118,29 @@ export async function proposeDashboardCard(args: any, context: any, deps: { run?
|
|
|
89
118
|
'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.'
|
|
90
119
|
}
|
|
91
120
|
}
|
|
121
|
+
/* What the card says it shows, and whose rows it shows - checked before it runs, so a wrong card is never drawn once. */
|
|
122
|
+
const description = typeof args?.description === 'string' ? args.description : undefined
|
|
123
|
+
const user = context?.state?.user
|
|
124
|
+
const mine = cardSources().filter(one => one.mine).map(one => (one.list ? `${one.read} (list ${one.list})` : one.read))
|
|
125
|
+
const intent = checkCardIntent({ name, description, definition }, source, { id: user?.id, name: user?.name, email: user?.email }, mine)
|
|
126
|
+
if (intent.length) {
|
|
127
|
+
return {
|
|
128
|
+
rejected: true,
|
|
129
|
+
error: 'card-says-otherwise',
|
|
130
|
+
issues: intent,
|
|
131
|
+
source: sourceSheet(source, definition.rows?.groupBy),
|
|
132
|
+
message:
|
|
133
|
+
'the card would not show what it says - fix each issue and call again now, in this turn. ' +
|
|
134
|
+
'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. ' +
|
|
135
|
+
'period-held-to-fixed-days: use relative values so the card stays current. period-unlike-condition: make the condition the period the name says. ' +
|
|
136
|
+
'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.'
|
|
137
|
+
}
|
|
138
|
+
}
|
|
92
139
|
|
|
93
140
|
/* A change is of one's own card, from the version it was read at - a newer version is not overwritten unseen. */
|
|
94
|
-
const
|
|
141
|
+
const given = typeof args?.cardId === 'string' ? args.cardId.trim() : ''
|
|
142
|
+
const cardId = given ? cardIdOf(given) : undefined
|
|
143
|
+
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.` }
|
|
95
144
|
let baseVersion: number | undefined
|
|
96
145
|
if (cardId) {
|
|
97
146
|
const saved = await (deps.cardOf ?? cardInDomain(context))(cardId)
|
|
@@ -173,8 +222,10 @@ const spec = {
|
|
|
173
222
|
description:
|
|
174
223
|
'Offer a dashboard card - a definition the person saves to 나의 대시보드, drawn afterwards from the data without you. ' +
|
|
175
224
|
'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 - ' +
|
|
176
|
-
'for a period use relative values
|
|
177
|
-
|
|
225
|
+
'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); ' +
|
|
226
|
+
'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. ' +
|
|
227
|
+
`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. ` +
|
|
228
|
+
'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. ' +
|
|
178
229
|
`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. ` +
|
|
179
230
|
'To change a saved card, pass its cardId and the version you changed as baseVersion.',
|
|
180
231
|
schema: {
|
|
@@ -185,7 +236,7 @@ const spec = {
|
|
|
185
236
|
source: {
|
|
186
237
|
type: 'object',
|
|
187
238
|
properties: {
|
|
188
|
-
read: { type: 'string', description: 'The read key
|
|
239
|
+
read: { type: 'string', description: 'The read - its key (office.receivables) or the tool that reads it (readOfficeReceivables).' },
|
|
189
240
|
list: { type: 'string', description: 'A detail read\'s list key.' },
|
|
190
241
|
where: { type: 'object', description: 'Conditions or arguments by name; dates may be relative.', additionalProperties: true }
|
|
191
242
|
},
|
|
@@ -196,7 +247,16 @@ const spec = {
|
|
|
196
247
|
properties: {
|
|
197
248
|
match: {
|
|
198
249
|
type: 'array',
|
|
199
|
-
items: {
|
|
250
|
+
items: {
|
|
251
|
+
type: 'object',
|
|
252
|
+
properties: {
|
|
253
|
+
column: COLUMN,
|
|
254
|
+
op: { type: 'string', enum: [...MATCH_OPS] },
|
|
255
|
+
value: { type: 'string', description: 'A number, a day, a word or a relative date.' },
|
|
256
|
+
values: { type: 'array', items: { type: 'string' }, description: `The values of ${LIST_OPS.join(' and ')}, in place of value.` }
|
|
257
|
+
},
|
|
258
|
+
required: ['column', 'op']
|
|
259
|
+
}
|
|
200
260
|
},
|
|
201
261
|
groupBy: COLUMN,
|
|
202
262
|
sortBy: COLUMN,
|
|
@@ -229,8 +289,10 @@ const spec = {
|
|
|
229
289
|
* the card; the model reads it here, then offers the changed definition with cardId and baseVersion).
|
|
230
290
|
*/
|
|
231
291
|
export async function readDashboardCard(args: any, context: any, cardOf?: (id: string) => Promise<{ card?: any; access?: string }>) {
|
|
232
|
-
const
|
|
233
|
-
if (!
|
|
292
|
+
const given = typeof args?.id === 'string' ? args.id.trim() : ''
|
|
293
|
+
if (!given) return { rejected: true, error: 'no-id', message: 'give the card id the person picked.' }
|
|
294
|
+
const id = cardIdOf(given)
|
|
295
|
+
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.` }
|
|
234
296
|
const found = await (cardOf ?? usableInDomain(context))(id)
|
|
235
297
|
if (!found?.card) return { rejected: true, error: 'unknown-card', message: 'there is no such card - say so.' }
|
|
236
298
|
if (!found.access) return { rejected: true, error: 'card-not-shared', message: 'this card is not shared with the person - say so.' }
|
|
@@ -295,5 +357,14 @@ export const cardCategory: ToolCategory = {
|
|
|
295
357
|
}
|
|
296
358
|
|
|
297
359
|
registerToolCategory(cardCategory)
|
|
298
|
-
/* In reach of every conversation, in front on the dashboard page
|
|
299
|
-
registerConversationCategory({
|
|
360
|
+
/* In reach of every conversation, in front on the dashboard page and for a picked card (ADR-0061 decision 9). */
|
|
361
|
+
registerConversationCategory({
|
|
362
|
+
name: CARD_CATEGORY,
|
|
363
|
+
frontPages: [DASHBOARD_PAGE],
|
|
364
|
+
frontAxes: [CARD_AXIS],
|
|
365
|
+
/* FINISH_RULE on this page: the card is what was asked for. */
|
|
366
|
+
pageRule:
|
|
367
|
+
`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. ` +
|
|
368
|
+
`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. ` +
|
|
369
|
+
`Only a question about the dashboard itself (how to share, how to move a card) is answered in words.`
|
|
370
|
+
})
|
|
@@ -5,10 +5,10 @@ import { DashboardCardShareScope } from './dashboard-card.js'
|
|
|
5
5
|
|
|
6
6
|
@ObjectType({ description: 'Who a card is shared with, as its owner sees it.' })
|
|
7
7
|
export class DashboardCardShareItem {
|
|
8
|
-
@Field(type => DashboardCardShareScope, { description: 'A person, a department or the domain.' })
|
|
8
|
+
@Field(type => DashboardCardShareScope, { description: 'A person, a department, a role or the domain.' })
|
|
9
9
|
scope: DashboardCardShareScope
|
|
10
10
|
|
|
11
|
-
@Field({ description: 'The user, department or domain id.' })
|
|
11
|
+
@Field({ description: 'The user, department, role or domain id.' })
|
|
12
12
|
targetId: string
|
|
13
13
|
|
|
14
14
|
@Field({ nullable: true, description: 'Its name when it was shared.' })
|
|
@@ -115,14 +115,17 @@ export class DashboardShareOptions {
|
|
|
115
115
|
|
|
116
116
|
@Field({ description: 'Whether the viewer may look people up to share with them.' })
|
|
117
117
|
peopleAvailable: boolean
|
|
118
|
+
|
|
119
|
+
@Field(type => [DashboardShareChoice], { description: "The domain's roles, the ones it inherits included - a card shared with one reaches whoever holds it." })
|
|
120
|
+
roles: DashboardShareChoice[]
|
|
118
121
|
}
|
|
119
122
|
|
|
120
123
|
@InputType({ description: 'One share of a card.' })
|
|
121
124
|
export class DashboardCardShareInput {
|
|
122
|
-
@Field(type => DashboardCardShareScope, { description: 'A person, a department or the domain.' })
|
|
125
|
+
@Field(type => DashboardCardShareScope, { description: 'A person, a department, a role or the domain.' })
|
|
123
126
|
scope: DashboardCardShareScope
|
|
124
127
|
|
|
125
|
-
@Field({ description: 'The user, department or domain id.' })
|
|
128
|
+
@Field({ description: 'The user, department, role or domain id.' })
|
|
126
129
|
targetId: string
|
|
127
130
|
|
|
128
131
|
@Field({ nullable: true, description: 'Its name, shown to the owner.' })
|