@things-factory/ai-assistant 10.1.91 → 10.1.98

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 (47) hide show
  1. package/client/components/assistant-chat.ts +5 -3
  2. package/client/components/entry-review.ts +56 -0
  3. package/client/utils/entry-proposal.ts +20 -5
  4. package/dist-client/components/assistant-chat.js +5 -3
  5. package/dist-client/components/assistant-chat.js.map +1 -1
  6. package/dist-client/components/entry-review.d.ts +5 -0
  7. package/dist-client/components/entry-review.js +55 -0
  8. package/dist-client/components/entry-review.js.map +1 -1
  9. package/dist-client/tsconfig.tsbuildinfo +1 -1
  10. package/dist-client/utils/entry-proposal.d.ts +5 -0
  11. package/dist-client/utils/entry-proposal.js +16 -5
  12. package/dist-client/utils/entry-proposal.js.map +1 -1
  13. package/dist-server/service/data-entry/entry-apply.d.ts +3 -3
  14. package/dist-server/service/data-entry/entry-apply.js +55 -2
  15. package/dist-server/service/data-entry/entry-apply.js.map +1 -1
  16. package/dist-server/service/data-entry/entry-resolver.js +3 -7
  17. package/dist-server/service/data-entry/entry-resolver.js.map +1 -1
  18. package/dist-server/service/data-entry/entry-target.d.ts +51 -0
  19. package/dist-server/service/data-entry/entry-target.js +77 -34
  20. package/dist-server/service/data-entry/entry-target.js.map +1 -1
  21. package/dist-server/service/data-entry/entry-tools.d.ts +7 -1
  22. package/dist-server/service/data-entry/entry-tools.js +79 -5
  23. package/dist-server/service/data-entry/entry-tools.js.map +1 -1
  24. package/dist-server/service/data-entry/entry-update.d.ts +99 -0
  25. package/dist-server/service/data-entry/entry-update.js +196 -0
  26. package/dist-server/service/data-entry/entry-update.js.map +1 -0
  27. package/dist-server/service/workspace/workspace-blocks.js +9 -1
  28. package/dist-server/service/workspace/workspace-blocks.js.map +1 -1
  29. package/dist-server/service/workspace/workspace-tools.js +43 -1
  30. package/dist-server/service/workspace/workspace-tools.js.map +1 -1
  31. package/dist-server/tsconfig.tsbuildinfo +1 -1
  32. package/package.json +2 -2
  33. package/server/service/data-entry/data-entry-update.test.ts +207 -0
  34. package/server/service/data-entry/entry-apply.ts +63 -6
  35. package/server/service/data-entry/entry-resolver.ts +4 -9
  36. package/server/service/data-entry/entry-target.ts +97 -31
  37. package/server/service/data-entry/entry-tools.ts +83 -5
  38. package/server/service/data-entry/entry-update.ts +209 -0
  39. package/server/service/workspace/workspace-blocks.ts +8 -1
  40. package/server/service/workspace/workspace-tools.ts +43 -1
  41. package/server/service/workspace/workspace.test.ts +16 -0
  42. package/test/entry-proposal.test.ts +15 -2
  43. package/translations/en.json +16 -1
  44. package/translations/ja.json +16 -1
  45. package/translations/ko.json +16 -1
  46. package/translations/ms.json +16 -1
  47. package/translations/zh.json +16 -1
@@ -0,0 +1,196 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MAX_CANDIDATES = exports.MAX_CHANGES = void 0;
4
+ exports.changeableFields = changeableFields;
5
+ exports.resolveChangeRefs = resolveChangeRefs;
6
+ exports.readRecords = readRecords;
7
+ exports.changeRows = changeRows;
8
+ exports.proposeChanges = proposeChanges;
9
+ exports.findRecords = findRecords;
10
+ exports.stillAsProposed = stillAsProposed;
11
+ /*
12
+ * Changing records that exist - the 수정안 (operato-application/design/ai/data-entry.md §5-1).
13
+ *
14
+ * The most expensive mistake is changing the wrong record, so which record is meant is settled here, by the
15
+ * server, never by the model's memory. A record is picked by the screen (the one being looked at, the rows
16
+ * selected) or by an id the find tool handed back; whichever way, it is read again through the application's
17
+ * read query as the person, and a record they cannot see is not found. The card shows what is there now and
18
+ * what it becomes; pressing reads it once more, and a field that moved in between keeps its row out.
19
+ *
20
+ * Pure but for the GraphQL runner, which comes in as an argument - the rules are tested without a server.
21
+ */
22
+ const entry_target_js_1 = require("./entry-target.js");
23
+ exports.MAX_CHANGES = 100;
24
+ const blockedChange = (row) => row.issues.some(issue => issue.blocking);
25
+ /** The fields a target lets change. */
26
+ function changeableFields(target) {
27
+ const names = target.update?.fields;
28
+ return names ? target.fields.filter(field => names.includes(field.name)) : target.fields;
29
+ }
30
+ /**
31
+ * The records the changes name. `current` is the record on screen, `selected` every row selected there -
32
+ * both from the surface's host context, which is **not trusted**: an id from it is only a candidate, read
33
+ * through the application before anything is shown. Any other ref is an id, from the find tool.
34
+ */
35
+ function resolveChangeRefs(targetKey, changes, host) {
36
+ const picked = [];
37
+ const unresolved = [];
38
+ const mine = (one) => !one?.target || one.target === targetKey;
39
+ for (const change of Array.isArray(changes) ? changes : []) {
40
+ const values = change?.values && typeof change.values === 'object' ? change.values : {};
41
+ const ref = typeof change?.ref === 'string' ? change.ref.trim() : '';
42
+ if (ref === 'current') {
43
+ const id = mine(host?.record) ? host?.record?.id : undefined;
44
+ if (typeof id === 'string' && id)
45
+ picked.push({ id, via: 'current', values });
46
+ else
47
+ unresolved.push('current');
48
+ }
49
+ else if (ref === 'selected') {
50
+ const ids = mine(host?.selection) && Array.isArray(host?.selection?.ids) ? host.selection.ids.filter((id) => typeof id === 'string' && id) : [];
51
+ if (ids.length)
52
+ for (const id of ids)
53
+ picked.push({ id, via: 'selected', values });
54
+ else
55
+ unresolved.push('selected');
56
+ }
57
+ else if (ref) {
58
+ picked.push({ id: ref, via: 'id', values });
59
+ }
60
+ else {
61
+ unresolved.push('no-ref');
62
+ }
63
+ }
64
+ return { picked: picked.slice(0, exports.MAX_CHANGES), unresolved };
65
+ }
66
+ /** Reads the records by id through the application's read query, as the person. */
67
+ async function readRecords(target, ids, run) {
68
+ const update = target.update;
69
+ const answer = await run(update.read.query, update.read.variables([...new Set(ids)]));
70
+ if (answer.errors?.length)
71
+ throw new Error(answer.errors.map(one => one.message).join('; '));
72
+ return new Map((update.read.recordsOf(answer.data) ?? []).filter(record => record && typeof record.id === 'string').map(record => [record.id, record]));
73
+ }
74
+ /** The change rows against what the records hold now. */
75
+ function changeRows(target, picked, records) {
76
+ const fields = new Map(changeableFields(target).map(field => [field.name, field]));
77
+ return picked.map((one, index) => {
78
+ const record = records.get(one.id);
79
+ const issues = [];
80
+ const values = {};
81
+ const before = {};
82
+ for (const [name, value] of Object.entries(one.values)) {
83
+ const field = fields.get(name);
84
+ if (!field) {
85
+ issues.push({ field: name, code: 'not-changeable', blocking: false });
86
+ continue;
87
+ }
88
+ const { read, code } = value === null || value === '' ? { read: null, code: undefined } : (0, entry_target_js_1.readFieldValue)(field, value);
89
+ if (read === undefined) {
90
+ values[name] = value;
91
+ issues.push({ field: name, code: code, params: code === 'not-in-list' ? { values: field.values } : undefined, blocking: true });
92
+ }
93
+ else {
94
+ if (read === null && field.required)
95
+ issues.push({ field: name, code: 'required', blocking: true });
96
+ values[name] = read;
97
+ }
98
+ if (record)
99
+ before[name] = record[name] ?? null;
100
+ }
101
+ if (!record)
102
+ issues.push({ code: 'record-not-found', blocking: true });
103
+ else if (Object.keys(values).length && Object.keys(values).every(name => (0, entry_target_js_1.sameFieldValue)(fields.get(name), before[name], values[name])))
104
+ issues.push({ code: 'no-change', blocking: true });
105
+ if (!Object.keys(values).length && !issues.some(issue => issue.blocking))
106
+ issues.push({ code: 'nothing-to-change', blocking: true });
107
+ return { index, id: one.id, via: one.via, ...(record && target.update?.labelOf ? { label: target.update.labelOf(record) } : {}), before, values, issues };
108
+ });
109
+ }
110
+ /** What the card needs besides the rows - the fields that change, in the target's order. */
111
+ function changedColumns(target, rows) {
112
+ const used = new Set(rows.flatMap(row => Object.keys(row.values)));
113
+ return changeableFields(target)
114
+ .filter(field => used.has(field.name))
115
+ .map(field => ({ name: field.name, type: field.type, ...(field.labelKey ? { labelKey: field.labelKey } : {}) }));
116
+ }
117
+ async function proposeChanges(target, args, context, run) {
118
+ const { picked, unresolved } = resolveChangeRefs(target.key, args?.changes, context?.host);
119
+ if (!picked.length) {
120
+ return {
121
+ rejected: true,
122
+ error: unresolved.length ? `unresolved-${unresolved[0]}` : 'no-changes',
123
+ message: unresolved[0] === 'current' || unresolved[0] === 'selected'
124
+ ? `the screen names no ${unresolved[0] === 'current' ? 'record' : 'selected rows'} of this kind. Ask the person which record, or call ${(0, entry_target_js_1.findToolName)(target.key)}.`
125
+ : `name each record: ref "current", "selected", or an id from ${(0, entry_target_js_1.findToolName)(target.key)}. Never guess an id.`
126
+ };
127
+ }
128
+ let records;
129
+ try {
130
+ records = await readRecords(target, picked.map(one => one.id), run);
131
+ }
132
+ catch (error) {
133
+ return { rejected: true, error: 'read-failed', message: `could not read the records: ${error?.message ?? error}` };
134
+ }
135
+ const rows = changeRows(target, picked, records);
136
+ const blocked = rows.filter(blockedChange).length;
137
+ return {
138
+ proposed: true,
139
+ kind: 'entry',
140
+ op: 'update',
141
+ target: target.key,
142
+ labelKey: target.labelKey,
143
+ label: `${rows.length} ${target.key} changes`,
144
+ icon: 'edit_note',
145
+ columns: changedColumns(target, rows),
146
+ rows,
147
+ counts: { rows: rows.length, ready: rows.length - blocked, blocked, cut: 0 },
148
+ ...(typeof args?.note === 'string' && args.note.trim() ? { reason: args.note.trim().slice(0, 300) } : {}),
149
+ message: `proposed ${rows.length} changes (${rows.length - blocked} ready, ${blocked} blocked). Nothing changes until the person presses the card. ` +
150
+ 'Tell them which records are not found or would not change.'
151
+ };
152
+ }
153
+ exports.MAX_CANDIDATES = 20;
154
+ /** Candidates for what the person described - the model lists them and asks when there is more than one. */
155
+ async function findRecords(target, args, run) {
156
+ const find = target.update?.find;
157
+ if (!find)
158
+ return { rejected: true, error: 'no-find', message: 'this record cannot be searched.' };
159
+ const criteria = {};
160
+ for (const field of find.criteria) {
161
+ const value = args?.[field.name];
162
+ if (value === undefined || value === null || value === '')
163
+ continue;
164
+ const { read } = (0, entry_target_js_1.readFieldValue)(field, value);
165
+ if (read !== undefined)
166
+ criteria[field.name] = read;
167
+ }
168
+ const answer = await run(find.query, find.variables(criteria));
169
+ if (answer.errors?.length)
170
+ return { rejected: true, error: 'find-failed', message: answer.errors.map(one => one.message).join('; ') };
171
+ const found = (find.recordsOf(answer.data) ?? []).filter(record => record && typeof record.id === 'string');
172
+ return {
173
+ total: found.length,
174
+ candidates: found.slice(0, exports.MAX_CANDIDATES).map(record => ({ id: record.id, ...(target.update?.labelOf ? { label: target.update.labelOf(record) } : {}), record })),
175
+ message: found.length === 1
176
+ ? `one record matches; pass its id to ${(0, entry_target_js_1.changeToolName)(target.key)}.`
177
+ : found.length
178
+ ? `${found.length} records match${found.length > exports.MAX_CANDIDATES ? ` (first ${exports.MAX_CANDIDATES} shown)` : ''}. List them to the person and ask which - never pick one yourself.`
179
+ : 'no record matches. Tell the person and ask for more to go on.'
180
+ };
181
+ }
182
+ /**
183
+ * The rows of a pressed 수정안, against what the records hold now. A row whose field moved since the card was
184
+ * made is kept out as `changed-since` - it is not overwritten unseen.
185
+ */
186
+ function stillAsProposed(target, rows, now) {
187
+ const fields = new Map(target.fields.map(field => [field.name, field]));
188
+ return rows.map(row => {
189
+ const record = now.get(row.id);
190
+ if (!record)
191
+ return { ...row, issues: [...row.issues, { code: 'record-not-found', blocking: true }] };
192
+ const moved = Object.keys(row.values).find(name => fields.get(name) && !(0, entry_target_js_1.sameFieldValue)(fields.get(name), record[name] ?? null, row.before[name]));
193
+ return moved ? { ...row, now: record, issues: [...row.issues, { field: moved, code: 'changed-since', blocking: true }] } : { ...row, now: record };
194
+ });
195
+ }
196
+ //# sourceMappingURL=entry-update.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"entry-update.js","sourceRoot":"","sources":["../../../server/service/data-entry/entry-update.ts"],"names":[],"mappings":";;;AA4CA,4CAGC;AAOD,8CA0BC;AAGD,kCAKC;AAGD,gCA6BC;AAUD,wCAoCC;AAKD,kCAuBC;AAMD,0CAQC;AAhND;;;;;;;;;;GAUG;AACH,uDAS0B;AAmBb,QAAA,WAAW,GAAG,GAAG,CAAA;AAE9B,MAAM,aAAa,GAAG,CAAC,GAA6B,EAAE,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAA;AAEjG,uCAAuC;AACvC,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AAK,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC,CAAA;IACvE,OAAO,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE;QACpB,MAAM,MAAM,GAAG,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,CAAA;QAC9B,IAAI,CAAC,MAAM;YAAE,OAAO,EAAE,GAAG,GAAG,EAAE,MAAM,EAAE,CAAC,GAAG,GAAG,CAAC,MAAM,EAAE,EAAE,IAAI,EAAE,kBAAkB,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,EAAE,CAAA;QACrG,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,IAAA,gCAAc,EAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAE,EAAE,MAAM,CAAC,IAAI,CAAC,IAAI,IAAI,EAAE,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;QAClJ,OAAO,KAAK,CAAC,CAAC,CAAC,EAAE,GAAG,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,GAAG,GAAG,CAAC,MAAM,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,eAAe,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,GAAG,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,CAAA;IACpJ,CAAC,CAAC,CAAA;AACJ,CAAC","sourcesContent":["/*\n * Changing records that exist - the 수정안 (operato-application/design/ai/data-entry.md §5-1).\n *\n * The most expensive mistake is changing the wrong record, so which record is meant is settled here, by the\n * server, never by the model's memory. A record is picked by the screen (the one being looked at, the rows\n * selected) or by an id the find tool handed back; whichever way, it is read again through the application's\n * read query as the person, and a record they cannot see is not found. The card shows what is there now and\n * what it becomes; pressing reads it once more, and a field that moved in between keeps its row out.\n *\n * Pure but for the GraphQL runner, which comes in as an argument - the rules are tested without a server.\n */\nimport {\n changeToolName,\n findToolName,\n readFieldValue,\n sameFieldValue,\n type EntryField,\n type EntryIssue,\n type EntryRecord,\n type EntryTarget\n} from './entry-target.js'\n\n/** Runs one of the application's queries or mutations as the person. */\nexport type GraphqlRunner = (document: string, variables: Record<string, unknown>) => Promise<{ data?: any; errors?: readonly { message: string }[] }>\n\n/** How the record of a change was picked - said on the card, so the person sees the ground of it. */\nexport type ChangeVia = 'current' | 'selected' | 'id'\n\nexport interface ChangeRow {\n index: number\n id: string\n via: ChangeVia\n label?: string\n /** What the record holds now, for the fields that change - read by the server. */\n before: Record<string, unknown>\n values: Record<string, unknown>\n issues: EntryIssue[]\n}\n\nexport const MAX_CHANGES = 100\n\nconst blockedChange = (row: { issues: EntryIssue[] }) => row.issues.some(issue => issue.blocking)\n\n/** The fields a target lets change. */\nexport function changeableFields(target: EntryTarget): EntryField[] {\n const names = target.update?.fields\n return names ? target.fields.filter(field => names.includes(field.name)) : target.fields\n}\n\n/**\n * The records the changes name. `current` is the record on screen, `selected` every row selected there -\n * both from the surface's host context, which is **not trusted**: an id from it is only a candidate, read\n * through the application before anything is shown. Any other ref is an id, from the find tool.\n */\nexport function resolveChangeRefs(\n targetKey: string,\n changes: unknown,\n host: Record<string, any> | undefined\n): { picked: { id: string; via: ChangeVia; values: Record<string, unknown> }[]; unresolved: string[] } {\n const picked: { id: string; via: ChangeVia; values: Record<string, unknown> }[] = []\n const unresolved: string[] = []\n const mine = (one: any) => !one?.target || one.target === targetKey\n for (const change of Array.isArray(changes) ? changes : []) {\n const values = change?.values && typeof change.values === 'object' ? change.values : {}\n const ref = typeof change?.ref === 'string' ? change.ref.trim() : ''\n if (ref === 'current') {\n const id = mine(host?.record) ? host?.record?.id : undefined\n if (typeof id === 'string' && id) picked.push({ id, via: 'current', values })\n else unresolved.push('current')\n } else if (ref === 'selected') {\n const ids = mine(host?.selection) && Array.isArray(host?.selection?.ids) ? host!.selection.ids.filter((id: unknown) => typeof id === 'string' && id) : []\n if (ids.length) for (const id of ids) picked.push({ id, via: 'selected', values })\n else unresolved.push('selected')\n } else if (ref) {\n picked.push({ id: ref, via: 'id', values })\n } else {\n unresolved.push('no-ref')\n }\n }\n return { picked: picked.slice(0, MAX_CHANGES), unresolved }\n}\n\n/** Reads the records by id through the application's read query, as the person. */\nexport async function readRecords(target: EntryTarget, ids: string[], run: GraphqlRunner): Promise<Map<string, EntryRecord>> {\n const update = target.update!\n const answer = await run(update.read.query, update.read.variables([...new Set(ids)]))\n if (answer.errors?.length) throw new Error(answer.errors.map(one => one.message).join('; '))\n return new Map((update.read.recordsOf(answer.data) ?? []).filter(record => record && typeof record.id === 'string').map(record => [record.id, record]))\n}\n\n/** The change rows against what the records hold now. */\nexport function changeRows(target: EntryTarget, picked: { id: string; via: ChangeVia; values: Record<string, unknown> }[], records: Map<string, EntryRecord>): ChangeRow[] {\n const fields = new Map(changeableFields(target).map(field => [field.name, field]))\n return picked.map((one, index): ChangeRow => {\n const record = records.get(one.id)\n const issues: EntryIssue[] = []\n const values: Record<string, unknown> = {}\n const before: Record<string, unknown> = {}\n for (const [name, value] of Object.entries(one.values)) {\n const field = fields.get(name)\n if (!field) {\n issues.push({ field: name, code: 'not-changeable', blocking: false })\n continue\n }\n const { read, code } = value === null || value === '' ? { read: null, code: undefined } : readFieldValue(field, value)\n if (read === undefined) {\n values[name] = value\n issues.push({ field: name, code: code!, params: code === 'not-in-list' ? { values: field.values } : undefined, blocking: true })\n } else {\n if (read === null && field.required) issues.push({ field: name, code: 'required', blocking: true })\n values[name] = read\n }\n if (record) before[name] = record[name] ?? null\n }\n if (!record) issues.push({ code: 'record-not-found', blocking: true })\n else if (Object.keys(values).length && Object.keys(values).every(name => sameFieldValue(fields.get(name)!, before[name], values[name])))\n issues.push({ code: 'no-change', blocking: true })\n if (!Object.keys(values).length && !issues.some(issue => issue.blocking)) issues.push({ code: 'nothing-to-change', blocking: true })\n return { index, id: one.id, via: one.via, ...(record && target.update?.labelOf ? { label: target.update.labelOf(record) } : {}), before, values, issues }\n })\n}\n\n/** What the card needs besides the rows - the fields that change, in the target's order. */\nfunction changedColumns(target: EntryTarget, rows: ChangeRow[]) {\n const used = new Set(rows.flatMap(row => Object.keys(row.values)))\n return changeableFields(target)\n .filter(field => used.has(field.name))\n .map(field => ({ name: field.name, type: field.type, ...(field.labelKey ? { labelKey: field.labelKey } : {}) }))\n}\n\nexport async function proposeChanges(target: EntryTarget, args: any, context: any, run: GraphqlRunner) {\n const { picked, unresolved } = resolveChangeRefs(target.key, args?.changes, context?.host)\n if (!picked.length) {\n return {\n rejected: true,\n error: unresolved.length ? `unresolved-${unresolved[0]}` : 'no-changes',\n message:\n unresolved[0] === 'current' || unresolved[0] === 'selected'\n ? `the screen names no ${unresolved[0] === 'current' ? 'record' : 'selected rows'} of this kind. Ask the person which record, or call ${findToolName(target.key)}.`\n : `name each record: ref \"current\", \"selected\", or an id from ${findToolName(target.key)}. Never guess an id.`\n }\n }\n let records: Map<string, EntryRecord>\n try {\n records = await readRecords(target, picked.map(one => one.id), run)\n } catch (error: any) {\n return { rejected: true, error: 'read-failed', message: `could not read the records: ${error?.message ?? error}` }\n }\n const rows = changeRows(target, picked, records)\n const blocked = rows.filter(blockedChange).length\n return {\n proposed: true,\n kind: 'entry',\n op: 'update',\n target: target.key,\n labelKey: target.labelKey,\n label: `${rows.length} ${target.key} changes`,\n icon: 'edit_note',\n columns: changedColumns(target, rows),\n rows,\n counts: { rows: rows.length, ready: rows.length - blocked, blocked, cut: 0 },\n ...(typeof args?.note === 'string' && args.note.trim() ? { reason: args.note.trim().slice(0, 300) } : {}),\n message:\n `proposed ${rows.length} changes (${rows.length - blocked} ready, ${blocked} blocked). Nothing changes until the person presses the card. ` +\n 'Tell them which records are not found or would not change.'\n }\n}\n\nexport const MAX_CANDIDATES = 20\n\n/** Candidates for what the person described - the model lists them and asks when there is more than one. */\nexport async function findRecords(target: EntryTarget, args: any, run: GraphqlRunner) {\n const find = target.update?.find\n if (!find) return { rejected: true, error: 'no-find', message: 'this record cannot be searched.' }\n const criteria: Record<string, unknown> = {}\n for (const field of find.criteria) {\n const value = args?.[field.name]\n if (value === undefined || value === null || value === '') continue\n const { read } = readFieldValue(field, value)\n if (read !== undefined) criteria[field.name] = read\n }\n const answer = await run(find.query, find.variables(criteria))\n if (answer.errors?.length) return { rejected: true, error: 'find-failed', message: answer.errors.map(one => one.message).join('; ') }\n const found = (find.recordsOf(answer.data) ?? []).filter(record => record && typeof record.id === 'string')\n return {\n total: found.length,\n candidates: found.slice(0, MAX_CANDIDATES).map(record => ({ id: record.id, ...(target.update?.labelOf ? { label: target.update.labelOf(record) } : {}), record })),\n message:\n found.length === 1\n ? `one record matches; pass its id to ${changeToolName(target.key)}.`\n : found.length\n ? `${found.length} records match${found.length > MAX_CANDIDATES ? ` (first ${MAX_CANDIDATES} shown)` : ''}. List them to the person and ask which - never pick one yourself.`\n : 'no record matches. Tell the person and ask for more to go on.'\n }\n}\n\n/**\n * The rows of a pressed 수정안, against what the records hold now. A row whose field moved since the card was\n * made is kept out as `changed-since` - it is not overwritten unseen.\n */\nexport function stillAsProposed(target: EntryTarget, rows: ChangeRow[], now: Map<string, EntryRecord>): (ChangeRow & { now?: EntryRecord })[] {\n const fields = new Map(target.fields.map(field => [field.name, field]))\n return rows.map(row => {\n const record = now.get(row.id)\n if (!record) return { ...row, issues: [...row.issues, { code: 'record-not-found', blocking: true }] }\n const moved = Object.keys(row.values).find(name => fields.get(name) && !sameFieldValue(fields.get(name)!, record[name] ?? null, row.before[name]))\n return moved ? { ...row, now: record, issues: [...row.issues, { field: moved, code: 'changed-since', blocking: true }] } : { ...row, now: record }\n })\n}\n"]}
@@ -64,7 +64,15 @@ function block(raw) {
64
64
  return unreadable(kind, 'no-columns');
65
65
  const given = Array.isArray(raw.rows) ? raw.rows : [];
66
66
  /* A row is an object by column name, or an array in column order - models write both. */
67
- const rows = given.slice(0, exports.MAX_TABLE_ROWS).map((row) => Object.fromEntries(columns.map((column, i) => [column.name, scalar(Array.isArray(row) ? row[i] : row?.[column.name])])));
67
+ /* A number column reads "12,400" as 12400 - cells come as text from a model told one type per field. */
68
+ const cell = (column, value) => {
69
+ const read = scalar(value);
70
+ if (column.type !== 'number' || typeof read !== 'string')
71
+ return read;
72
+ const number = Number(read.replace(/[,\s₩$€]/g, ''));
73
+ return read.trim() && Number.isFinite(number) ? number : read;
74
+ };
75
+ const rows = given.slice(0, exports.MAX_TABLE_ROWS).map((row) => Object.fromEntries(columns.map((column, i) => [column.name, cell(column, Array.isArray(row) ? row[i] : row?.[column.name])])));
68
76
  return { kind, columns, rows, ...(text(raw.caption, 300) ? { caption: text(raw.caption, 300) } : {}), ...(given.length > exports.MAX_TABLE_ROWS ? { cut: given.length - exports.MAX_TABLE_ROWS } : {}) };
69
77
  }
70
78
  case 'chart': {
@@ -1 +1 @@
1
- {"version":3,"file":"workspace-blocks.js","sourceRoot":"","sources":["../../../server/service/workspace/workspace-blocks.ts"],"names":[],"mappings":";AAAA;;;;;;;GAOG;;;AA2BH,sCASC;AAoED,gDAQC;AAGD,8CAIC;AArHY,QAAA,qBAAqB,GAAG,CAAC,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,CAAU,CAAA;AAG1F,QAAA,UAAU,GAAG,EAAE,CAAA;AACf,QAAA,cAAc,GAAG,IAAI,CAAA;AACrB,QAAA,UAAU,GAAG,CAAC,CAAA;AAC3B,MAAM,QAAQ,GAAG,MAAM,CAAA;AAcvB,MAAM,IAAI,GAAG,CAAC,KAAc,EAAE,GAAG,GAAG,GAAG,EAAsB,EAAE,CAAC,CAAC,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,KA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AC;YAAE,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAA;IACjJ,OAAO,MAAM,CAAA;AACf,CAAC","sourcesContent":["/*\n * The AI 작업판 - what a workspace is made of (operato-application/design/ai/workspace.md §3).\n *\n * The model does not write HTML. A workspace is a list of blocks of known kinds; the screen draws each, so\n * theme, language and accessibility are the framework's. A block that does not fit is not dropped: it is\n * kept as a fact in its place (\"a block that cannot be drawn\"), so the person sees that something was meant\n * to be there. Pure - tested without a server.\n */\n\nexport const WORKSPACE_BLOCK_KINDS = ['heading', 'text', 'metrics', 'table', 'chart', 'steps'] as const\nexport type WorkspaceBlockKind = (typeof WORKSPACE_BLOCK_KINDS)[number]\n\nexport const MAX_BLOCKS = 40\nexport const MAX_TABLE_ROWS = 1000\nexport const MAX_SERIES = 8\nconst MAX_TEXT = 20_000\n\nexport interface WorkspaceBlock {\n kind: WorkspaceBlockKind | 'unreadable'\n [key: string]: unknown\n}\n\nexport interface Workspace {\n name: string\n title: string\n summary?: string\n blocks: WorkspaceBlock[]\n}\n\nconst text = (value: unknown, max = 500): string | undefined => (typeof value === 'string' && value.trim() ? value.trim().slice(0, max) : undefined)\nconst scalar = (value: unknown): string | number | boolean | null =>\n value === null || value === undefined ? null : typeof value === 'number' || typeof value === 'boolean' ? value : String(value).slice(0, 500)\n\n/** A short key of the workspace - the same name in one conversation is the same workspace, a new version. */\nexport function workspaceName(name: unknown, title: string): string {\n const given = typeof name === 'string' ? name.trim().toLowerCase() : ''\n if (/^[a-z0-9][a-z0-9-]{0,63}$/.test(given)) return given\n const slug = (given || title)\n .toLowerCase()\n .replace(/[^a-z0-9가-힣]+/g, '-')\n .replace(/^-+|-+$/g, '')\n .slice(0, 64)\n return slug || 'workspace'\n}\n\nfunction unreadable(kind: unknown, reason: string): WorkspaceBlock {\n return { kind: 'unreadable', was: typeof kind === 'string' ? kind.slice(0, 40) : null, reason }\n}\n\nfunction block(raw: any): WorkspaceBlock {\n const kind = raw?.kind\n switch (kind) {\n case 'heading': {\n const value = text(raw.text, 200)\n if (!value) return unreadable(kind, 'no-text')\n const level = [1, 2, 3].includes(raw.level) ? raw.level : 2\n return { kind, text: value, level }\n }\n case 'text': {\n const value = text(raw.markdown ?? raw.text, MAX_TEXT)\n return value ? { kind, markdown: value } : unreadable(kind, 'no-text')\n }\n case 'metrics': {\n const items = (Array.isArray(raw.items) ? raw.items : [])\n .filter((one: any) => text(one?.label) && one?.value !== undefined && one?.value !== null)\n .slice(0, 12)\n .map((one: any) => ({ label: text(one.label, 80), value: scalar(one.value), ...(text(one.unit, 20) ? { unit: text(one.unit, 20) } : {}), ...(text(one.note, 200) ? { note: text(one.note, 200) } : {}) }))\n return items.length ? { kind, items } : unreadable(kind, 'no-items')\n }\n case 'table': {\n const columns = (Array.isArray(raw.columns) ? raw.columns : [])\n .filter((one: any) => text(one?.name, 80))\n .slice(0, 30)\n .map((one: any) => ({ name: text(one.name, 80)!, ...(text(one.label, 80) ? { label: text(one.label, 80) } : {}), type: ['number', 'date', 'string'].includes(one.type) ? one.type : 'string' }))\n if (!columns.length) return unreadable(kind, 'no-columns')\n const given = Array.isArray(raw.rows) ? raw.rows : []\n /* A row is an object by column name, or an array in column order - models write both. */\n const rows = given.slice(0, MAX_TABLE_ROWS).map((row: any) =>\n Object.fromEntries(columns.map((column: any, i: number) => [column.name, scalar(Array.isArray(row) ? row[i] : row?.[column.name])]))\n )\n return { kind, columns, rows, ...(text(raw.caption, 300) ? { caption: text(raw.caption, 300) } : {}), ...(given.length > MAX_TABLE_ROWS ? { cut: given.length - MAX_TABLE_ROWS } : {}) }\n }\n case 'chart': {\n const x = (Array.isArray(raw.x) ? raw.x : []).slice(0, 200).map((one: unknown) => String(one ?? '').slice(0, 60))\n const series = (Array.isArray(raw.series) ? raw.series : [])\n .filter((one: any) => text(one?.name, 60) && Array.isArray(one?.values))\n .map((one: any) => ({ name: text(one.name, 60)!, values: x.map((_: unknown, i: number) => (typeof one.values[i] === 'number' && Number.isFinite(one.values[i]) ? one.values[i] : null)) }))\n if (!x.length || !series.length) return unreadable(kind, 'no-series')\n /* Never a ninth hue: past eight, the first seven stay and the rest fold into one \"other\". */\n const shown =\n series.length > MAX_SERIES\n ? [\n ...series.slice(0, MAX_SERIES - 1),\n { name: 'other', other: true, values: x.map((_: unknown, i: number) => series.slice(MAX_SERIES - 1).reduce((acc: number, one: any) => acc + (one.values[i] ?? 0), 0)) }\n ]\n : series\n return { kind, chart: raw.chart === 'line' || raw.type === 'line' || raw.shape === 'line' ? 'line' : 'bar', x, series: shown, ...(text(raw.unit, 20) ? { unit: text(raw.unit, 20) } : {}), ...(text(raw.caption, 300) ? { caption: text(raw.caption, 300) } : {}) }\n }\n case 'steps': {\n const items = (Array.isArray(raw.items) ? raw.items : [])\n .filter((one: any) => text(one?.label, 200))\n .slice(0, 50)\n .map((one: any) => ({ label: text(one.label, 200), state: ['done', 'doing', 'todo', 'failed'].includes(one.state) ? one.state : 'todo', ...(text(one.note, 300) ? { note: text(one.note, 300) } : {}) }))\n return items.length ? { kind, items } : unreadable(kind, 'no-items')\n }\n default:\n return unreadable(kind, 'unknown-kind')\n }\n}\n\n/** The workspace as the screen reads it. */\nexport function normalizeWorkspace(args: any): { workspace?: Workspace; error?: string } {\n const title = text(args?.title, 200)\n if (!title) return { error: 'no-title' }\n const given = Array.isArray(args?.blocks) ? args.blocks : []\n if (!given.length) return { error: 'no-blocks' }\n const blocks = given.slice(0, MAX_BLOCKS).map(block)\n if (given.length > MAX_BLOCKS) blocks.push({ kind: 'unreadable', was: null, reason: 'too-many-blocks', cut: given.length - MAX_BLOCKS })\n return { workspace: { name: workspaceName(args?.name, title), title, ...(text(args?.summary, 500) ? { summary: text(args.summary, 500) } : {}), blocks } }\n}\n\n/** One line of what is in it - for the card in the conversation and for the model. */\nexport function workspaceContents(workspace: Workspace): Record<string, number> {\n const counts: Record<string, number> = {}\n for (const one of workspace.blocks) if (['table', 'chart', 'metrics', 'steps'].includes(one.kind)) counts[one.kind] = (counts[one.kind] ?? 0) + 1\n return counts\n}\n"]}
1
+ {"version":3,"file":"workspace-blocks.js","sourceRoot":"","sources":["../../../server/service/workspace/workspace-blocks.ts"],"names":[],"mappings":";AAAA;;;;;;;GAOG;;;AA2BH,sCASC;AA2ED,gDAQC;AAGD,8CAIC;AA5HY,QAAA,qBAAqB,GAAG,CAAC,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,CAAU,CAAA;AAG1F,QAAA,UAAU,GAAG,EAAE,CAAA;AACf,QAAA,cAAc,GAAG,IAAI,CAAA;AACrB,QAAA,UAAU,GAAG,CAAC,CAAA;AAC3B,MAAM,QAAQ,GAAG,MAAM,CAAA;AAcvB,MAAM,IAAI,GAAG,CAAC,KAAc,EAAE,GAAG,GAAG,GAAG,EAAsB,EAAE,CAAC,CAAC,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAA;AACpJ,MAAM,MAAM,GAAG,CAAC,KAAc,EAAoC,EAAE,CAClE,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,KAAK,KAAK,QAAQ,IAAI,OAAO,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,CAAA;AAE9I,6GAA6G;AAC7G,SAAgB,aAAa,CAAC,IAAa,EAAE,KAAa;IACxD,MAAM,KAAK,GAAG,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,EAA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,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAA;IACjJ,OAAO,MAAM,CAAA;AACf,CAAC","sourcesContent":["/*\n * The AI 작업판 - what a workspace is made of (operato-application/design/ai/workspace.md §3).\n *\n * The model does not write HTML. A workspace is a list of blocks of known kinds; the screen draws each, so\n * theme, language and accessibility are the framework's. A block that does not fit is not dropped: it is\n * kept as a fact in its place (\"a block that cannot be drawn\"), so the person sees that something was meant\n * to be there. Pure - tested without a server.\n */\n\nexport const WORKSPACE_BLOCK_KINDS = ['heading', 'text', 'metrics', 'table', 'chart', 'steps'] as const\nexport type WorkspaceBlockKind = (typeof WORKSPACE_BLOCK_KINDS)[number]\n\nexport const MAX_BLOCKS = 40\nexport const MAX_TABLE_ROWS = 1000\nexport const MAX_SERIES = 8\nconst MAX_TEXT = 20_000\n\nexport interface WorkspaceBlock {\n kind: WorkspaceBlockKind | 'unreadable'\n [key: string]: unknown\n}\n\nexport interface Workspace {\n name: string\n title: string\n summary?: string\n blocks: WorkspaceBlock[]\n}\n\nconst text = (value: unknown, max = 500): string | undefined => (typeof value === 'string' && value.trim() ? value.trim().slice(0, max) : undefined)\nconst scalar = (value: unknown): string | number | boolean | null =>\n value === null || value === undefined ? null : typeof value === 'number' || typeof value === 'boolean' ? value : String(value).slice(0, 500)\n\n/** A short key of the workspace - the same name in one conversation is the same workspace, a new version. */\nexport function workspaceName(name: unknown, title: string): string {\n const given = typeof name === 'string' ? name.trim().toLowerCase() : ''\n if (/^[a-z0-9][a-z0-9-]{0,63}$/.test(given)) return given\n const slug = (given || title)\n .toLowerCase()\n .replace(/[^a-z0-9가-힣]+/g, '-')\n .replace(/^-+|-+$/g, '')\n .slice(0, 64)\n return slug || 'workspace'\n}\n\nfunction unreadable(kind: unknown, reason: string): WorkspaceBlock {\n return { kind: 'unreadable', was: typeof kind === 'string' ? kind.slice(0, 40) : null, reason }\n}\n\nfunction block(raw: any): WorkspaceBlock {\n const kind = raw?.kind\n switch (kind) {\n case 'heading': {\n const value = text(raw.text, 200)\n if (!value) return unreadable(kind, 'no-text')\n const level = [1, 2, 3].includes(raw.level) ? raw.level : 2\n return { kind, text: value, level }\n }\n case 'text': {\n const value = text(raw.markdown ?? raw.text, MAX_TEXT)\n return value ? { kind, markdown: value } : unreadable(kind, 'no-text')\n }\n case 'metrics': {\n const items = (Array.isArray(raw.items) ? raw.items : [])\n .filter((one: any) => text(one?.label) && one?.value !== undefined && one?.value !== null)\n .slice(0, 12)\n .map((one: any) => ({ label: text(one.label, 80), value: scalar(one.value), ...(text(one.unit, 20) ? { unit: text(one.unit, 20) } : {}), ...(text(one.note, 200) ? { note: text(one.note, 200) } : {}) }))\n return items.length ? { kind, items } : unreadable(kind, 'no-items')\n }\n case 'table': {\n const columns = (Array.isArray(raw.columns) ? raw.columns : [])\n .filter((one: any) => text(one?.name, 80))\n .slice(0, 30)\n .map((one: any) => ({ name: text(one.name, 80)!, ...(text(one.label, 80) ? { label: text(one.label, 80) } : {}), type: ['number', 'date', 'string'].includes(one.type) ? one.type : 'string' }))\n if (!columns.length) return unreadable(kind, 'no-columns')\n const given = Array.isArray(raw.rows) ? raw.rows : []\n /* A row is an object by column name, or an array in column order - models write both. */\n /* A number column reads \"12,400\" as 12400 - cells come as text from a model told one type per field. */\n const cell = (column: any, value: unknown) => {\n const read = scalar(value)\n if (column.type !== 'number' || typeof read !== 'string') return read\n const number = Number(read.replace(/[,\\s₩$€]/g, ''))\n return read.trim() && Number.isFinite(number) ? number : read\n }\n const rows = given.slice(0, MAX_TABLE_ROWS).map((row: any) =>\n Object.fromEntries(columns.map((column: any, i: number) => [column.name, cell(column, Array.isArray(row) ? row[i] : row?.[column.name])]))\n )\n return { kind, columns, rows, ...(text(raw.caption, 300) ? { caption: text(raw.caption, 300) } : {}), ...(given.length > MAX_TABLE_ROWS ? { cut: given.length - MAX_TABLE_ROWS } : {}) }\n }\n case 'chart': {\n const x = (Array.isArray(raw.x) ? raw.x : []).slice(0, 200).map((one: unknown) => String(one ?? '').slice(0, 60))\n const series = (Array.isArray(raw.series) ? raw.series : [])\n .filter((one: any) => text(one?.name, 60) && Array.isArray(one?.values))\n .map((one: any) => ({ name: text(one.name, 60)!, values: x.map((_: unknown, i: number) => (typeof one.values[i] === 'number' && Number.isFinite(one.values[i]) ? one.values[i] : null)) }))\n if (!x.length || !series.length) return unreadable(kind, 'no-series')\n /* Never a ninth hue: past eight, the first seven stay and the rest fold into one \"other\". */\n const shown =\n series.length > MAX_SERIES\n ? [\n ...series.slice(0, MAX_SERIES - 1),\n { name: 'other', other: true, values: x.map((_: unknown, i: number) => series.slice(MAX_SERIES - 1).reduce((acc: number, one: any) => acc + (one.values[i] ?? 0), 0)) }\n ]\n : series\n return { kind, chart: raw.chart === 'line' || raw.type === 'line' || raw.shape === 'line' ? 'line' : 'bar', x, series: shown, ...(text(raw.unit, 20) ? { unit: text(raw.unit, 20) } : {}), ...(text(raw.caption, 300) ? { caption: text(raw.caption, 300) } : {}) }\n }\n case 'steps': {\n const items = (Array.isArray(raw.items) ? raw.items : [])\n .filter((one: any) => text(one?.label, 200))\n .slice(0, 50)\n .map((one: any) => ({ label: text(one.label, 200), state: ['done', 'doing', 'todo', 'failed'].includes(one.state) ? one.state : 'todo', ...(text(one.note, 300) ? { note: text(one.note, 300) } : {}) }))\n return items.length ? { kind, items } : unreadable(kind, 'no-items')\n }\n default:\n return unreadable(kind, 'unknown-kind')\n }\n}\n\n/** The workspace as the screen reads it. */\nexport function normalizeWorkspace(args: any): { workspace?: Workspace; error?: string } {\n const title = text(args?.title, 200)\n if (!title) return { error: 'no-title' }\n const given = Array.isArray(args?.blocks) ? args.blocks : []\n if (!given.length) return { error: 'no-blocks' }\n const blocks = given.slice(0, MAX_BLOCKS).map(block)\n if (given.length > MAX_BLOCKS) blocks.push({ kind: 'unreadable', was: null, reason: 'too-many-blocks', cut: given.length - MAX_BLOCKS })\n return { workspace: { name: workspaceName(args?.name, title), title, ...(text(args?.summary, 500) ? { summary: text(args.summary, 500) } : {}), blocks } }\n}\n\n/** One line of what is in it - for the card in the conversation and for the model. */\nexport function workspaceContents(workspace: Workspace): Record<string, number> {\n const counts: Record<string, number> = {}\n for (const one of workspace.blocks) if (['table', 'chart', 'metrics', 'steps'].includes(one.kind)) counts[one.kind] = (counts[one.kind] ?? 0) + 1\n return counts\n}\n"]}
@@ -41,9 +41,51 @@ const spec = {
41
41
  name: { type: 'string', description: 'A short key, lowercase with dashes ("contracts-by-customer"). The same name again makes a new version of the same workspace.' },
42
42
  title: { type: 'string' },
43
43
  summary: { type: 'string', description: 'One line under the title.' },
44
+ /*
45
+ * Every field of every block is declared, each with one type: Gemini's function schema (an OpenAPI 3.0
46
+ * subset) refuses a list of types and may leave out a field it was not told of (2026-10-01).
47
+ */
44
48
  blocks: {
45
49
  type: 'array',
46
- items: { type: 'object', properties: { kind: { type: 'string', enum: [...workspace_blocks_js_1.WORKSPACE_BLOCK_KINDS] } }, required: ['kind'] }
50
+ items: {
51
+ type: 'object',
52
+ properties: {
53
+ kind: { type: 'string', enum: [...workspace_blocks_js_1.WORKSPACE_BLOCK_KINDS] },
54
+ text: { type: 'string', description: 'heading' },
55
+ level: { type: 'integer', description: 'heading: 1-3' },
56
+ markdown: { type: 'string', description: 'text' },
57
+ caption: { type: 'string', description: 'table, chart' },
58
+ unit: { type: 'string', description: 'chart' },
59
+ chart: { type: 'string', enum: ['bar', 'line'], description: 'chart' },
60
+ items: {
61
+ type: 'array',
62
+ description: 'metrics: {label,value,unit,note}; steps: {label,state,note}',
63
+ items: {
64
+ type: 'object',
65
+ properties: {
66
+ label: { type: 'string' },
67
+ value: { type: 'string' },
68
+ unit: { type: 'string' },
69
+ note: { type: 'string' },
70
+ state: { type: 'string', enum: ['done', 'doing', 'todo', 'failed'] }
71
+ }
72
+ }
73
+ },
74
+ columns: {
75
+ type: 'array',
76
+ description: 'table',
77
+ items: { type: 'object', properties: { name: { type: 'string' }, label: { type: 'string' }, type: { type: 'string', enum: ['number', 'date', 'string'] } } }
78
+ },
79
+ rows: { type: 'array', description: 'table: each row is its cells in column order', items: { type: 'array', items: { type: 'string' } } },
80
+ x: { type: 'array', description: 'chart: the labels along the bottom', items: { type: 'string' } },
81
+ series: {
82
+ type: 'array',
83
+ description: 'chart',
84
+ items: { type: 'object', properties: { name: { type: 'string' }, values: { type: 'array', items: { type: 'number' } } } }
85
+ }
86
+ },
87
+ required: ['kind']
88
+ }
47
89
  }
48
90
  },
49
91
  required: ['name', 'title', 'blocks']
@@ -1 +1 @@
1
- {"version":3,"file":"workspace-tools.js","sourceRoot":"","sources":["../../../server/service/workspace/workspace-tools.ts"],"names":[],"mappings":";;;AAcA,0CAaC;AA3BD;;;;;;;GAOG;AACH,mEAAuG;AAEvG,+DAAoG;AAEvF,QAAA,kBAAkB,GAAG,qBAAqB,CAAA;AAEvD,SAAgB,eAAe,CAAC,IAAS;IACvC,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,GAAG,IAAA,wCAAkB,EAAC,IAAI,CAAC,CAAA;IACrD,IAAI,CAAC,SAAS;QAAE,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,mDAAmD,EAAE,CAAA;IAC9G,MAAM,QAAQ,GAAG,IAAA,uCAAiB,EAAC,SAAS,CAAC,CAAA;IAC7C,OAAO;QACL,QAAQ,EAAE,IAAI;QACd,IAAI,EAAE,WAAW;QACjB,IAAI,EAAE,WAAW;QACjB,KAAK,EAAE,SAAS,CAAC,KAAK;QACtB,SAAS;QACT,QAAQ;QACR,OAAO,EAAE,QAAQ,SAAS,CAAC,KAAK,uBAAuB,SAAS,CAAC,MAAM,CAAC,MAAM,sHAAsH;KACrM,CAAA;AACH,CAAC;AAED,MAAM,IAAI,GAAG;IACX,IAAI,EAAE,MAAM;IACZ,IAAI,EAAE,iBAAiB;IACvB,KAAK,EAAE,EAAE;IACT,WAAW,EACT,iHAAiH;QACjH,qJAAqJ;QACrJ,+IAA+I;IACjJ,MAAM,EAAE;QACN,IAAI,EAAE,QAAQ;QACd,UAAU,EAAE;YACV,IAAI,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,8HAA8H,EAAE;YACrK,KAAK,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;YACzB,OAAO,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,2BAA2B,EAAE;YACrE,MAAM,EAAE;gBACN,IAAI,EAAE,OAAO;gBACb,KAAK,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,UAAU,EAAE,EAAE,IAAI,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,GAAG,2CAAqB,CAAC,EAAE,EAAE,EAAE,QAAQ,EAAE,CAAC,MAAM,CAAC,EAAE;aAC1H;SACF;QACD,QAAQ,EAAE,CAAC,MAAM,EAAE,OAAO,EAAE,QAAQ,CAAC;KACtC;IACD,OAAO,EAAE,CAAC,IAAS,EAAE,EAAE,CAAC,eAAe,CAAC,IAAI,CAAC;CAClC,CAAA;AAEA,QAAA,iBAAiB,GAAiB;IAC7C,IAAI,EAAE,0BAAkB;IACxB,WAAW,EAAE,sEAAsE;IACnF,QAAQ,EAAE;QACR,qNAAqN;QACrN,6GAA6G;QAC7G,6HAA6H;QAC7H,2FAA2F;KAC5F,CAAC,IAAI,CAAC,IAAI,CAAC;IACZ,KAAK,EAAE,CAAC,IAAI,CAAC;CACd,CAAA;AAED,IAAA,qCAAoB,EAAC,yBAAiB,CAAC,CAAA","sourcesContent":["/*\n * showInWorkspace - the model puts a large result on the AI 작업판 (operato-application/design/ai/workspace.md §5).\n *\n * The result rides on the answer as a proposal of kind 'workspace', so the conversation's gates hold for it:\n * who may read the conversation reads the workspace, and a value behind a door the reader cannot pass hides\n * it with the answer (ADR-0073). The tool itself reaches no door - what it carries came from the turn's other\n * tools, whose doors the answer row collects.\n */\nimport { registerToolCategory, type ToolCategory, type ToolSpec } from '@things-factory/ai-client-base'\n\nimport { normalizeWorkspace, workspaceContents, WORKSPACE_BLOCK_KINDS } from './workspace-blocks.js'\n\nexport const WORKSPACE_CATEGORY = 'assistant-workspace'\n\nexport function showInWorkspace(args: any) {\n const { workspace, error } = normalizeWorkspace(args)\n if (!workspace) return { rejected: true, error, message: 'a workspace needs a title and at least one block.' }\n const contents = workspaceContents(workspace)\n return {\n proposed: true,\n kind: 'workspace',\n icon: 'dashboard',\n label: workspace.title,\n workspace,\n contents,\n message: `put \"${workspace.title}\" on the workspace (${workspace.blocks.length} blocks). The person opens it from the card - say in one line what it holds; do not repeat its tables in the answer.`\n }\n}\n\nconst spec = {\n kind: 'read',\n name: 'showInWorkspace',\n doors: [],\n description:\n 'Put a large result on the AI workspace - a page the person opens from a card, beside the conversation. Blocks: ' +\n 'heading{text,level}, text{markdown}, metrics{items:[{label,value,unit,note}]}, table{columns:[{name,label,type:number|date|string}],rows,caption}, ' +\n 'chart{chart:bar|line, x:[labels], series:[{name,values:[numbers]}], unit, caption}, steps{items:[{label,state:done|doing|todo|failed,note}]}.',\n schema: {\n type: 'object',\n properties: {\n name: { type: 'string', description: 'A short key, lowercase with dashes (\"contracts-by-customer\"). The same name again makes a new version of the same workspace.' },\n title: { type: 'string' },\n summary: { type: 'string', description: 'One line under the title.' },\n blocks: {\n type: 'array',\n items: { type: 'object', properties: { kind: { type: 'string', enum: [...WORKSPACE_BLOCK_KINDS] } }, required: ['kind'] }\n }\n },\n required: ['name', 'title', 'blocks']\n },\n builder: (args: any) => showInWorkspace(args)\n} as ToolSpec\n\nexport const workspaceCategory: ToolCategory = {\n name: WORKSPACE_CATEGORY,\n description: 'the AI workspace - a page for results too large for the conversation',\n guidance: [\n '- When a result is more than a short table (over 20 rows, or two or more tables or charts), or the person asks for a page, call showInWorkspace. Keep the answer short: the point, and that it is on the workspace.',\n '- Every number in a block comes from a tool result in this conversation - never computed or guessed by you.',\n '- To change a workspace, call showInWorkspace again with the same name and the whole new content; it becomes a new version.',\n '- Never say something is on the workspace unless you called showInWorkspace in this turn.'\n ].join('\\n'),\n specs: [spec]\n}\n\nregisterToolCategory(workspaceCategory)\n"]}
1
+ {"version":3,"file":"workspace-tools.js","sourceRoot":"","sources":["../../../server/service/workspace/workspace-tools.ts"],"names":[],"mappings":";;;AAcA,0CAaC;AA3BD;;;;;;;GAOG;AACH,mEAAuG;AAEvG,+DAAoG;AAEvF,QAAA,kBAAkB,GAAG,qBAAqB,CAAA;AAEvD,SAAgB,eAAe,CAAC,IAAS;IACvC,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,GAAG,IAAA,wCAAkB,EAAC,IAAI,CAAC,CAAA;IACrD,IAAI,CAAC,SAAS;QAAE,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,mDAAmD,EAAE,CAAA;IAC9G,MAAM,QAAQ,GAAG,IAAA,uCAAiB,EAAC,SAAS,CAAC,CAAA;IAC7C,OAAO;QACL,QAAQ,EAAE,IAAI;QACd,IAAI,EAAE,WAAW;QACjB,IAAI,EAAE,WAAW;QACjB,KAAK,EAAE,SAAS,CAAC,KAAK;QACtB,SAAS;QACT,QAAQ;QACR,OAAO,EAAE,QAAQ,SAAS,CAAC,KAAK,uBAAuB,SAAS,CAAC,MAAM,CAAC,MAAM,sHAAsH;KACrM,CAAA;AACH,CAAC;AAED,MAAM,IAAI,GAAG;IACX,IAAI,EAAE,MAAM;IACZ,IAAI,EAAE,iBAAiB;IACvB,KAAK,EAAE,EAAE;IACT,WAAW,EACT,iHAAiH;QACjH,qJAAqJ;QACrJ,+IAA+I;IACjJ,MAAM,EAAE;QACN,IAAI,EAAE,QAAQ;QACd,UAAU,EAAE;YACV,IAAI,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,8HAA8H,EAAE;YACrK,KAAK,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;YACzB,OAAO,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE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F,QAAQ,EAAE;QACR,qNAAqN;QACrN,6GAA6G;QAC7G,6HAA6H;QAC7H,2FAA2F;KAC5F,CAAC,IAAI,CAAC,IAAI,CAAC;IACZ,KAAK,EAAE,CAAC,IAAI,CAAC;CACd,CAAA;AAED,IAAA,qCAAoB,EAAC,yBAAiB,CAAC,CAAA","sourcesContent":["/*\n * showInWorkspace - the model puts a large result on the AI 작업판 (operato-application/design/ai/workspace.md §5).\n *\n * The result rides on the answer as a proposal of kind 'workspace', so the conversation's gates hold for it:\n * who may read the conversation reads the workspace, and a value behind a door the reader cannot pass hides\n * it with the answer (ADR-0073). The tool itself reaches no door - what it carries came from the turn's other\n * tools, whose doors the answer row collects.\n */\nimport { registerToolCategory, type ToolCategory, type ToolSpec } from '@things-factory/ai-client-base'\n\nimport { normalizeWorkspace, workspaceContents, WORKSPACE_BLOCK_KINDS } from './workspace-blocks.js'\n\nexport const WORKSPACE_CATEGORY = 'assistant-workspace'\n\nexport function showInWorkspace(args: any) {\n const { workspace, error } = normalizeWorkspace(args)\n if (!workspace) return { rejected: true, error, message: 'a workspace needs a title and at least one block.' }\n const contents = workspaceContents(workspace)\n return {\n proposed: true,\n kind: 'workspace',\n icon: 'dashboard',\n label: workspace.title,\n workspace,\n contents,\n message: `put \"${workspace.title}\" on the workspace (${workspace.blocks.length} blocks). The person opens it from the card - say in one line what it holds; do not repeat its tables in the answer.`\n }\n}\n\nconst spec = {\n kind: 'read',\n name: 'showInWorkspace',\n doors: [],\n description:\n 'Put a large result on the AI workspace - a page the person opens from a card, beside the conversation. Blocks: ' +\n 'heading{text,level}, text{markdown}, metrics{items:[{label,value,unit,note}]}, table{columns:[{name,label,type:number|date|string}],rows,caption}, ' +\n 'chart{chart:bar|line, x:[labels], series:[{name,values:[numbers]}], unit, caption}, steps{items:[{label,state:done|doing|todo|failed,note}]}.',\n schema: {\n type: 'object',\n properties: {\n name: { type: 'string', description: 'A short key, lowercase with dashes (\"contracts-by-customer\"). The same name again makes a new version of the same workspace.' },\n title: { type: 'string' },\n summary: { type: 'string', description: 'One line under the title.' },\n /*\n * Every field of every block is declared, each with one type: Gemini's function schema (an OpenAPI 3.0\n * subset) refuses a list of types and may leave out a field it was not told of (2026-10-01).\n */\n blocks: {\n type: 'array',\n items: {\n type: 'object',\n properties: {\n kind: { type: 'string', enum: [...WORKSPACE_BLOCK_KINDS] },\n text: { type: 'string', description: 'heading' },\n level: { type: 'integer', description: 'heading: 1-3' },\n markdown: { type: 'string', description: 'text' },\n caption: { type: 'string', description: 'table, chart' },\n unit: { type: 'string', description: 'chart' },\n chart: { type: 'string', enum: ['bar', 'line'], description: 'chart' },\n items: {\n type: 'array',\n description: 'metrics: {label,value,unit,note}; steps: {label,state,note}',\n items: {\n type: 'object',\n properties: {\n label: { type: 'string' },\n value: { type: 'string' },\n unit: { type: 'string' },\n note: { type: 'string' },\n state: { type: 'string', enum: ['done', 'doing', 'todo', 'failed'] }\n }\n }\n },\n columns: {\n type: 'array',\n description: 'table',\n items: { type: 'object', properties: { name: { type: 'string' }, label: { type: 'string' }, type: { type: 'string', enum: ['number', 'date', 'string'] } } }\n },\n rows: { type: 'array', description: 'table: each row is its cells in column order', items: { type: 'array', items: { type: 'string' } } },\n x: { type: 'array', description: 'chart: the labels along the bottom', items: { type: 'string' } },\n series: {\n type: 'array',\n description: 'chart',\n items: { type: 'object', properties: { name: { type: 'string' }, values: { type: 'array', items: { type: 'number' } } } }\n }\n },\n required: ['kind']\n }\n }\n },\n required: ['name', 'title', 'blocks']\n },\n builder: (args: any) => showInWorkspace(args)\n} as ToolSpec\n\nexport const workspaceCategory: ToolCategory = {\n name: WORKSPACE_CATEGORY,\n description: 'the AI workspace - a page for results too large for the conversation',\n guidance: [\n '- When a result is more than a short table (over 20 rows, or two or more tables or charts), or the person asks for a page, call showInWorkspace. Keep the answer short: the point, and that it is on the workspace.',\n '- Every number in a block comes from a tool result in this conversation - never computed or guessed by you.',\n '- To change a workspace, call showInWorkspace again with the same name and the whole new content; it becomes a new version.',\n '- Never say something is on the workspace unless you called showInWorkspace in this turn.'\n ].join('\\n'),\n specs: [spec]\n}\n\nregisterToolCategory(workspaceCategory)\n"]}