@things-factory/ai-dashboard 10.1.278 → 10.1.280

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
package/server/index.ts DELETED
@@ -1,16 +0,0 @@
1
- /**
2
- * `@things-factory/ai-dashboard` - 나의 대시보드 (operato-application/adr/ADR-0160.md).
3
- *
4
- * A card is a definition made with the assistant in a conversation - which declared read it draws, how its rows are
5
- * shaped and how they are drawn - kept in the database and run as the viewer whenever it is drawn, with no model.
6
- * Cards are one's own, versioned, shared with people, departments or the domain, and placed on one's dashboard.
7
- *
8
- * Uses `ai-assistant` - its read declarations, its 작업 패널 blocks and their renderer, its conversations and proposals.
9
- * An application declares its reads and puts the `my-dashboard` page in its menu.
10
- */
11
- export * from './service/index.js'
12
-
13
- import { registerRoleTask } from '@things-factory/auth-base'
14
- import { ROLE_TASKS } from './role-tasks.js'
15
-
16
- for (const task of ROLE_TASKS) registerRoleTask(task)
@@ -1,12 +0,0 @@
1
- /*
2
- * The work this module names, for the seats applications build (ADR-0139 decision 11).
3
- *
4
- * One task: keeping one's own dashboard - one's cards, their versions and shares, and where they are placed. The data
5
- * a card draws is behind the doors of the application that declared it, asked as the viewer every time (ADR-0160).
6
- *
7
- * Data only - `server/index.ts` registers it - so an application's tests read it without starting the framework.
8
- */
9
-
10
- import type { RoleTask } from '@things-factory/auth-base'
11
-
12
- export const ROLE_TASKS: RoleTask[] = [{ id: 'ai-dashboard.use', grants: [{ category: 'ai-dashboard', axes: ['query', 'mutation'] }] }]
@@ -1,173 +0,0 @@
1
- /*
2
- * Who may use a card (ADR-0160 decisions 6, 7), which proposal a press means, and what the card tool offers.
3
- */
4
- import { listReadTarget, type DetailRead } from '@things-factory/ai-assistant'
5
-
6
- import { cardAccessOf } from './card-access'
7
- import { findCardProposal } from './card-proposal'
8
- import { proposeDashboardCard, readDashboardCard } from './card-tool'
9
- import { CARD_AXIS } from './card-names'
10
- import { CARD_AXIS as CLIENT_AXIS, cardSelection } from '../../../client/utils/card-words'
11
-
12
- const viewer = { userId: 'u-me', domainId: 'd1', departmentIds: ['dep-sales'], roleIds: [] as string[] }
13
-
14
- describe('who may use a card', () => {
15
- it('★ its owner, and whoever a share names - a person, a department one is active in, the domain', () => {
16
- expect(cardAccessOf({ ownerId: 'u-me', domainId: 'd1' }, viewer, [])).toBe('owner')
17
- expect(cardAccessOf({ ownerId: 'u-x', domainId: 'd1' }, viewer, [])).toBeUndefined()
18
- expect(cardAccessOf({ ownerId: 'u-x', domainId: 'd1' }, viewer, [{ scope: 'USER', targetId: 'u-me' }])).toBe('shared')
19
- expect(cardAccessOf({ ownerId: 'u-x', domainId: 'd1' }, viewer, [{ scope: 'USER', targetId: 'u-other' }])).toBeUndefined()
20
- expect(cardAccessOf({ ownerId: 'u-x', domainId: 'd1' }, viewer, [{ scope: 'DEPARTMENT', targetId: 'dep-sales' }])).toBe('shared')
21
- expect(cardAccessOf({ ownerId: 'u-x', domainId: 'd1' }, viewer, [{ scope: 'DEPARTMENT', targetId: 'dep-hr' }])).toBeUndefined()
22
- expect(cardAccessOf({ ownerId: 'u-x', domainId: 'd1' }, viewer, [{ scope: 'DOMAIN', targetId: 'd1' }])).toBe('shared')
23
- })
24
-
25
- it('★ a role share reaches whoever holds that role in the domain, and no one else', () => {
26
- const holder = { ...viewer, roleIds: ['role-hr'] }
27
- expect(cardAccessOf({ ownerId: 'u-x', domainId: 'd1' }, holder, [{ scope: 'ROLE', targetId: 'role-hr' }])).toBe('shared')
28
- expect(cardAccessOf({ ownerId: 'u-x', domainId: 'd1' }, holder, [{ scope: 'ROLE', targetId: 'role-finance' }])).toBeUndefined()
29
- expect(cardAccessOf({ ownerId: 'u-x', domainId: 'd1' }, viewer, [{ scope: 'ROLE', targetId: 'role-hr' }])).toBeUndefined()
30
- })
31
-
32
- it('★ never across domains - not even its owner in another domain', () => {
33
- expect(cardAccessOf({ ownerId: 'u-me', domainId: 'd2' }, viewer, [])).toBeUndefined()
34
- expect(cardAccessOf({ ownerId: 'u-x', domainId: 'd2' }, viewer, [{ scope: 'DOMAIN', targetId: 'd2' }])).toBeUndefined()
35
- expect(cardAccessOf({ ownerId: 'u-me', domainId: 'd1' }, { ...viewer, userId: '' }, [])).toBeUndefined()
36
- })
37
-
38
- it('★ a department share reaches the people of the departments under it - the viewer stands in those above (organization audience)', () => {
39
- const inTeam = { ...viewer, departmentIds: ['dep-sales-1', 'dep-sales'] }
40
- expect(cardAccessOf({ ownerId: 'u-x', domainId: 'd1' }, inTeam, [{ scope: 'DEPARTMENT', targetId: 'dep-sales' }])).toBe('shared')
41
- })
42
- })
43
-
44
- describe('which proposal a press means', () => {
45
- const proposal = (key: string, card: any) => ({ key, tool: 'proposeDashboardCard', kind: 'dashboard-card', card: { definition: {}, ...card } })
46
-
47
- it('★ a later proposal of the same card replaces it; another card does not', () => {
48
- const messages = [{ proposals: [proposal('k1', { name: '미수금' })] }, { proposals: [proposal('k2', { name: '입금' })] }, { proposals: [proposal('k3', { name: '미수금' })] }]
49
- expect(findCardProposal(messages, 'k1')).toMatchObject({ superseded: true })
50
- expect(findCardProposal(messages, 'k2')).toMatchObject({ superseded: false })
51
- expect(findCardProposal(messages, 'k3')).toMatchObject({ superseded: false })
52
- })
53
-
54
- it('★ a change of a saved card is replaced by a later change of that card only', () => {
55
- const messages = [{ proposals: [proposal('a', { name: 'x', cardId: 'c1', baseVersion: 1 })] }, { proposals: [proposal('b', { name: 'x' }), proposal('c', { name: 'y', cardId: 'c2' })] }]
56
- expect(findCardProposal(messages, 'a').superseded).toBe(false)
57
- messages.push({ proposals: [proposal('d', { name: 'renamed', cardId: 'c1', baseVersion: 1 })] })
58
- expect(findCardProposal(messages, 'a').superseded).toBe(true)
59
- })
60
-
61
- it('a key that is no card, or none at all, is said', () => {
62
- expect(findCardProposal([{ proposals: [{ key: 'w', tool: 'showInWorkspace', kind: 'workspace' }] }], 'w')).toEqual({ superseded: false, notACard: true })
63
- expect(findCardProposal([], 'w')).toEqual({ superseded: false })
64
- })
65
- })
66
-
67
- describe('the card tool', () => {
68
- const receivables: DetailRead = {
69
- key: 'office.receivables',
70
- description: 'what is owed.',
71
- query: 'query ($direction: String!) { receivables(direction: $direction) { rows { customer remaining currency } } }',
72
- args: [{ name: 'direction', type: 'enum', values: ['SALES', 'PURCHASE'], required: true }],
73
- lists: [{ key: 'by-contract', at: 'rows', columns: [{ name: 'customer', type: 'string' }, { name: 'currency', type: 'string' }, { name: 'remaining', type: 'number', total: true, currency: 'currency' }] }]
74
- }
75
- /* The tool reads the registries; the fakes are declared through them. */
76
- const { declareDetailRead, clearReadTargets } = require('@things-factory/ai-assistant')
77
- beforeAll(() => {
78
- clearReadTargets()
79
- declareDetailRead(receivables)
80
- })
81
- afterAll(() => clearReadTargets())
82
-
83
- const context = { state: { user: { id: 'u-me' }, domain: { id: 'd1' } } }
84
- const deps = { run: async () => ({ data: { receivables: { rows: [{ customer: '이썸', remaining: 10, currency: 'KRW' }] } } }), passesDoor: async () => true, today: '2026-10-24' }
85
- const args = { name: '미수금 상위', source: { read: 'office.receivables', where: { direction: 'SALES' } }, rows: { groupBy: 'customer', sortBy: 'remaining', desc: true, limit: 5 }, view: { kind: 'bar', values: ['remaining'] } }
86
-
87
- it('★ a fitting card is offered with its definition only - no values for the model, none kept in the proposal', async () => {
88
- const result: any = await proposeDashboardCard(args, context, deps)
89
- expect(result).toMatchObject({ proposed: true, kind: 'dashboard-card', label: '미수금 상위' })
90
- expect(result.card.definition).toEqual({ schemaVersion: 1, source: args.source, rows: args.rows, view: args.view })
91
- expect(JSON.stringify(result)).not.toMatch(/이썸/)
92
- expect(result.forScreen).toBeUndefined()
93
- })
94
-
95
- it('★ a definition that does not fit is sent back with what the source has', async () => {
96
- const result: any = await proposeDashboardCard({ ...args, rows: { sortBy: 'debt' } }, context, deps)
97
- expect(result).toMatchObject({ rejected: true, error: 'definition-unfit' })
98
- expect(result.source.columns.map((one: any) => one.name)).toEqual(['customer', 'currency', 'remaining'])
99
- const unknown: any = await proposeDashboardCard({ ...args, source: { read: 'office.nope' } }, context, deps)
100
- expect(unknown).toMatchObject({ rejected: true, error: 'unknown-read', sources: [{ read: 'office.receivables', list: 'by-contract', tool: 'readOfficeReceivables' }] })
101
- })
102
-
103
- it('★ a read named by its tool is that read, and a field left empty is no field', async () => {
104
- const result: any = await proposeDashboardCard(
105
- { ...args, source: { read: 'readOfficeReceivables', where: { direction: 'SALES', staleDays: null } }, rows: { groupBy: 'customer', sortBy: 'remaining', desc: true, limit: 5, match: null } },
106
- context,
107
- deps
108
- )
109
- expect(result).toMatchObject({ proposed: true })
110
- expect(result.card.definition.source).toEqual({ read: 'office.receivables', where: { direction: 'SALES' } })
111
- expect(result.card.definition.rows).toEqual({ groupBy: 'customer', sortBy: 'remaining', desc: true, limit: 5 })
112
- })
113
-
114
- it('★ bars whose names repeat are sent back to be grouped - one name, one bar', async () => {
115
- const twice = { ...deps, run: async () => ({ data: { receivables: { rows: [{ customer: '이썸', remaining: 10, currency: 'KRW' }, { customer: '이썸', remaining: 5, currency: 'KRW' }] } } }) }
116
- const flat = { ...args, rows: { sortBy: 'remaining', desc: true, limit: 5 }, view: { kind: 'bar', label: 'customer', values: ['remaining'] } }
117
- expect(await proposeDashboardCard(flat, context, twice)).toMatchObject({ rejected: true, error: 'label-repeats', label: 'customer' })
118
- expect(await proposeDashboardCard(args, context, twice)).toMatchObject({ proposed: true })
119
- })
120
-
121
- it('★ a table or chart that draws nothing today is sent back, unless the person asked for what may be empty', async () => {
122
- const empty = { ...deps, run: async () => ({ data: { receivables: { rows: [] } } }) }
123
- expect(await proposeDashboardCard(args, context, empty)).toMatchObject({ rejected: true, error: 'draws-nothing', source: { description: 'what is owed.' } })
124
- expect(await proposeDashboardCard({ ...args, allowEmpty: true }, context, empty)).toMatchObject({ proposed: true })
125
- /* A number of nothing is 0 - drawn. */
126
- expect(await proposeDashboardCard({ ...args, rows: {}, view: { kind: 'number' } }, context, empty)).toMatchObject({ proposed: true })
127
- })
128
-
129
- it('★ a card the person cannot read is not offered', async () => {
130
- const result: any = await proposeDashboardCard(args, context, { ...deps, passesDoor: async () => false })
131
- expect(result).toMatchObject({ rejected: true, error: 'door-closed' })
132
- })
133
-
134
- const C1 = '75e8d067-62e6-47f5-9c2f-bf10b6b97b83'
135
- const C2 = 'f9e3afc2-2d80-4ce9-99ca-b3e628a66f02'
136
- const C9 = '00000000-0000-4000-8000-000000000009'
137
-
138
- it('★ a change is of one\'s own card, from its current version', async () => {
139
- const cardOf = async (id: string) => (id === C1 ? { ownerId: 'u-me', version: 3 } : id === C2 ? { ownerId: 'u-x', version: 1 } : undefined)
140
- expect(await proposeDashboardCard({ ...args, cardId: C1 }, context, { ...deps, cardOf })).toMatchObject({ proposed: true, card: { cardId: C1, baseVersion: 3 } })
141
- expect(await proposeDashboardCard({ ...args, cardId: C1, baseVersion: 2 }, context, { ...deps, cardOf })).toMatchObject({ rejected: true, error: 'stale-version', current: 3 })
142
- expect(await proposeDashboardCard({ ...args, cardId: C2 }, context, { ...deps, cardOf })).toMatchObject({ rejected: true, error: 'not-your-card' })
143
- expect(await proposeDashboardCard({ ...args, cardId: C9 }, context, { ...deps, cardOf })).toMatchObject({ rejected: true, error: 'unknown-card' })
144
- })
145
-
146
- it('★ a picked card is named by its key dashboard-card:<uuid> - read and changed by it; anything else is never looked up', async () => {
147
- const looked: string[] = []
148
- const cardOf = async (id: string) => (looked.push(id), id === C1 ? { ownerId: 'u-me', version: 3 } : undefined)
149
- /* The key the dashboard hands (card-words cardSelection) is the card. */
150
- const key = cardSelection({ id: C1, name: '미수금' }, '나의 대시보드').records[0].id
151
- expect(key).toBe(`dashboard-card:${C1}`)
152
- expect(await proposeDashboardCard({ ...args, cardId: key }, context, { ...deps, cardOf })).toMatchObject({ proposed: true, card: { cardId: C1, baseVersion: 3 } })
153
- /* A list name, another record's key or a name is no card - said, never handed to the database (a uuid column refuses it). */
154
- for (const wrong of [`dashboardCards:${C1}`, `contract:${C1}`, '미수금 상위 5곳']) {
155
- expect(await proposeDashboardCard({ ...args, cardId: wrong }, context, { ...deps, cardOf })).toMatchObject({ rejected: true, error: 'card-id-unreadable' })
156
- }
157
- expect(looked).toEqual([C1])
158
- const read = async (id: string) => (looked.push(id), id === C1 ? { card: { id: C1, name: '미수금', version: 3, definition: {} }, access: 'owner' } : {})
159
- expect(await readDashboardCard({ id: key }, context, read)).toMatchObject({ id: C1, version: 3, access: 'owner' })
160
- expect(await readDashboardCard({ id: 'dashboardCards' }, context, read)).toMatchObject({ rejected: true, error: 'card-id-unreadable' })
161
- expect(looked).toEqual([C1, C1])
162
- })
163
-
164
- it('★ on the dashboard, what the person asks to see ends in a card - not a figure in words', () => {
165
- const { turnSystemPrompt } = require('@things-factory/ai-assistant')
166
- expect(turnSystemPrompt('persona', { page: 'my-dashboard' })).toMatch(/end the turn with proposeDashboardCard/)
167
- expect(turnSystemPrompt('persona', { page: 'receivable-page' })).toBe('persona')
168
- })
169
-
170
- it('the client hands a card by the axis the server reads', () => {
171
- expect(CLIENT_AXIS).toBe(CARD_AXIS)
172
- })
173
- })
@@ -1,24 +0,0 @@
1
- /*
2
- * Who may use a card (ADR-0160 decisions 6, 7) - the first of the two checks; the data's own door is the second, asked
3
- * when the card is run. Using a card means reading its definition and running it as oneself: a share gives the
4
- * definition, never the data behind it. Asked again on every read, run, placing and copy - a share withdrawn is gone
5
- * at once, whatever is still placed.
6
- *
7
- * Whom a share reaches is the audience rule of organization (ADR-0163 decision 2) - the one an announcement asks too.
8
- *
9
- * Pure - the rule is tested without a database.
10
- */
11
- import { audienceReaches, type AudienceMember, type AudienceTarget } from '@things-factory/organization'
12
-
13
- export type CardAccess = 'owner' | 'shared'
14
-
15
- export type CardShareRow = AudienceTarget
16
-
17
- /** The viewer as an audience sees them - the departments they stand in (those above included) and the roles they hold. */
18
- export type CardViewer = AudienceMember
19
-
20
- export function cardAccessOf(card: { ownerId?: string | null; domainId?: string | null }, viewer: CardViewer, shares: readonly CardShareRow[]): CardAccess | undefined {
21
- if (!viewer.userId || !viewer.domainId || card.domainId !== viewer.domainId) return undefined
22
- if (card.ownerId === viewer.userId) return 'owner'
23
- return audienceReaches(shares, viewer) ? 'shared' : undefined
24
- }