@things-factory/ai-assistant 10.1.88 → 10.1.91
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/assistant-chat.ts +45 -5
- package/client/components/assistant-dock.ts +30 -2
- package/client/components/entry-review.ts +246 -0
- package/client/components/workspace-view.ts +428 -0
- package/client/pages/assistant-workspace-page.ts +237 -0
- package/client/route.ts +9 -0
- package/client/utils/assistant-proposals.ts +11 -1
- package/client/utils/entry-proposal.ts +103 -0
- package/client/utils/workspace.ts +89 -0
- package/dist-client/components/assistant-chat.d.ts +3 -0
- package/dist-client/components/assistant-chat.js +46 -5
- package/dist-client/components/assistant-chat.js.map +1 -1
- package/dist-client/components/assistant-dock.d.ts +1 -0
- package/dist-client/components/assistant-dock.js +25 -2
- package/dist-client/components/assistant-dock.js.map +1 -1
- package/dist-client/components/entry-review.d.ts +9 -0
- package/dist-client/components/entry-review.js +247 -0
- package/dist-client/components/entry-review.js.map +1 -0
- package/dist-client/components/workspace-view.d.ts +19 -0
- package/dist-client/components/workspace-view.js +416 -0
- package/dist-client/components/workspace-view.js.map +1 -0
- package/dist-client/pages/assistant-workspace-page.d.ts +27 -0
- package/dist-client/pages/assistant-workspace-page.js +263 -0
- package/dist-client/pages/assistant-workspace-page.js.map +1 -0
- package/dist-client/route.d.ts +1 -0
- package/dist-client/route.js +10 -0
- package/dist-client/route.js.map +1 -0
- package/dist-client/tsconfig.tsbuildinfo +1 -1
- package/dist-client/utils/assistant-proposals.d.ts +1 -0
- package/dist-client/utils/assistant-proposals.js +9 -1
- package/dist-client/utils/assistant-proposals.js.map +1 -1
- package/dist-client/utils/entry-proposal.d.ts +55 -0
- package/dist-client/utils/entry-proposal.js +52 -0
- package/dist-client/utils/entry-proposal.js.map +1 -0
- package/dist-client/utils/workspace.d.ts +40 -0
- package/dist-client/utils/workspace.js +68 -0
- package/dist-client/utils/workspace.js.map +1 -0
- package/dist-server/service/assistant-mode/registry.js +13 -0
- package/dist-server/service/assistant-mode/registry.js.map +1 -1
- package/dist-server/service/assistant-mode/resolve.d.ts +11 -0
- package/dist-server/service/assistant-mode/resolve.js +15 -3
- package/dist-server/service/assistant-mode/resolve.js.map +1 -1
- package/dist-server/service/assistant-mode/types.d.ts +7 -1
- package/dist-server/service/assistant-mode/types.js.map +1 -1
- package/dist-server/service/data-entry/entry-apply.d.ts +46 -0
- package/dist-server/service/data-entry/entry-apply.js +102 -0
- package/dist-server/service/data-entry/entry-apply.js.map +1 -0
- package/dist-server/service/data-entry/entry-resolver.d.ts +4 -0
- package/dist-server/service/data-entry/entry-resolver.js +80 -0
- package/dist-server/service/data-entry/entry-resolver.js.map +1 -0
- package/dist-server/service/data-entry/entry-sources.d.ts +1 -0
- package/dist-server/service/data-entry/entry-sources.js +41 -0
- package/dist-server/service/data-entry/entry-sources.js.map +1 -0
- package/dist-server/service/data-entry/entry-target.d.ts +157 -0
- package/dist-server/service/data-entry/entry-target.js +343 -0
- package/dist-server/service/data-entry/entry-target.js.map +1 -0
- package/dist-server/service/data-entry/entry-tools.d.ts +43 -0
- package/dist-server/service/data-entry/entry-tools.js +185 -0
- package/dist-server/service/data-entry/entry-tools.js.map +1 -0
- package/dist-server/service/index.d.ts +6 -1
- package/dist-server/service/index.js +13 -2
- package/dist-server/service/index.js.map +1 -1
- package/dist-server/service/workspace/workspace-blocks.d.ts +24 -0
- package/dist-server/service/workspace/workspace-blocks.js +118 -0
- package/dist-server/service/workspace/workspace-blocks.js.map +1 -0
- package/dist-server/service/workspace/workspace-tools.d.ts +24 -0
- package/dist-server/service/workspace/workspace-tools.js +65 -0
- package/dist-server/service/workspace/workspace-tools.js.map +1 -0
- package/dist-server/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/server/service/assistant-mode/registry.ts +13 -0
- package/server/service/assistant-mode/resolve.test.ts +2 -1
- package/server/service/assistant-mode/resolve.ts +15 -3
- package/server/service/assistant-mode/types.ts +7 -1
- package/server/service/data-entry/data-entry.test.ts +311 -0
- package/server/service/data-entry/entry-apply.ts +134 -0
- package/server/service/data-entry/entry-resolver.ts +74 -0
- package/server/service/data-entry/entry-sources.ts +35 -0
- package/server/service/data-entry/entry-target.ts +442 -0
- package/server/service/data-entry/entry-tools.ts +174 -0
- package/server/service/index.ts +10 -1
- package/server/service/workspace/workspace-blocks.ts +127 -0
- package/server/service/workspace/workspace-tools.ts +66 -0
- package/server/service/workspace/workspace.test.ts +58 -0
- package/test/entry-proposal.test.ts +67 -0
- package/test/open-doors.test.ts +2 -1
- package/test/workspace.test.ts +54 -0
- package/things-factory.config.js +6 -1
- package/translations/en.json +56 -1
- package/translations/ja.json +56 -1
- package/translations/ko.json +56 -1
- package/translations/ms.json +56 -1
- package/translations/zh.json +56 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entry-tools.js","sourceRoot":"","sources":["../../../server/service/data-entry/entry-tools.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiDA,wCAkDC;AAED,0CA8DC;AAOD,kDAGC;AA7KD;;;;;;;;GAQG;AACH,mEAAuG;AAEvG,uDAc0B;AAE1B,SAAS,WAAW,CAAC,KAAiB;IACpC,MAAM,IAAI,GAAG,KAAK,CAAC,IAAI,KAAK,QAAQ,IAAI,KAAK,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAA;IACrJ,MAAM,IAAI,GAAG;QACX,KAAK,CAAC,WAAW;QACjB,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,UAAU;QACxC,KAAK,CAAC,IAAI,KAAK,MAAM,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,SAAS;QAChD,KAAK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ato-application/design/ai/data-entry.md §3).\n *\n * One tool per target, so each carries its own door: the tool is offered only to a person who could enter\n * those records by hand, and its card cannot be made for someone who could not press it.\n *\n * The tool writes nothing. It reads the rows the model made from the material, puts each value in its\n * field's type, asks the target's own checks, and hands back a proposal - the card.\n */\nimport { registerToolCategory, type ToolCategory, type ToolSpec } from '@things-factory/ai-client-base'\n\nimport {\n declareEntryTarget,\n entryTotals,\n verifyRowsAgainstSources,\n entryCategoryName,\n entryDoorOf,\n entryToolName,\n isBlocked,\n normalizeEntryRows,\n recordEntryEvent,\n withCheckedIssues,\n type EntryField,\n type EntryRow,\n type EntryTarget\n} from './entry-target.js'\n\nfunction fieldSchema(field: EntryField): any {\n const type = field.type === 'number' || field.type === 'integer' ? ['number', 'string'] : field.type === 'boolean' ? ['boolean', 'string'] : 'string'\n const said = [\n field.description,\n field.required ? 'required' : 'optional',\n field.type === 'date' ? 'YYYY-MM-DD' : undefined,\n field.type === 'enum' ? `one of: ${field.values!.join(', ')}` : undefined\n ]\n .filter(Boolean)\n .join('. ')\n return { type, description: said }\n}\n\n/** What the card needs besides the rows - the columns, in the target's order. */\nfunction columnsOf(target: EntryTarget) {\n return target.fields.map(field => ({ name: field.name, type: field.type, required: !!field.required, ...(field.labelKey ? { labelKey: field.labelKey } : {}) }))\n}\n\nexport type SourceTextLoader = (attachmentIds: string[], context: any) => Promise<Map<string, string>>\n\nconst readSources: SourceTextLoader = async (ids, context) => (await import('./entry-sources.js')).loadSourceTexts(ids, context)\n\nexport async function proposeEntries(target: EntryTarget, args: any, context: any, loadTexts: SourceTextLoader = readSources) {\n const tool = entryToolName(target.key)\n const told = (event: Omit<Parameters<typeof recordEntryEvent>[1], 'phase' | 'tool'>) => recordEntryEvent(target, { phase: 'propose', tool, ...event }, { state: context?.state })\n const { rows: normalized, cut } = normalizeEntryRows(target, args?.rows)\n if (!normalized.length) {\n await told({ rows: 0, ok: false, error: 'no-rows', detail: args })\n return { rejected: true, error: 'no-rows', message: 'no rows were given. Read the material and pass every record as a row.' }\n }\n\n /* The server looks in the cited files itself - the model's citation is not proof (design/ai/data-entry.md §4-1). */\n const declared = args?.declaredTotal && typeof args.declaredTotal === 'object' ? args.declaredTotal : undefined\n const cited = [...normalized.flatMap(row => row.sources.map(source => source.attachmentId)), declared?.attachmentId].filter((id): id is string => typeof id === 'string' && !!id)\n const texts = cited.length ? await loadTexts(cited, context).catch(() => new Map<string, string>()) : new Map<string, string>()\n const read = verifyRowsAgainstSources(normalized, target.fields, texts)\n\n let rows: EntryRow[] = read\n let checkFailed: string | undefined\n if (target.check) {\n try {\n rows = withCheckedIssues(read, await target.check(read, { state: context?.state }))\n } catch (error: any) {\n checkFailed = error?.message || 'check-failed'\n }\n }\n\n const blocked = rows.filter(isBlocked).length\n const totals = entryTotals(rows, target.fields, declared, texts)\n const verified = rows.filter(row => row.evidence).length\n const unmatched = rows.filter(row => row.issues.some(issue => issue.code === 'not-in-source')).length\n await told({ rows: rows.length, ok: true, detail: args })\n return {\n proposed: true,\n kind: 'entry',\n target: target.key,\n labelKey: target.labelKey,\n label: `${rows.length} ${target.key} rows`,\n icon: 'playlist_add',\n columns: columnsOf(target),\n rows,\n counts: { rows: rows.length, ready: rows.length - blocked, blocked, cut, verified, unmatched },\n ...(totals.length ? { totals } : {}),\n ...(typeof args?.note === 'string' && args.note.trim() ? { reason: args.note.trim().slice(0, 300) } : {}),\n ...(checkFailed ? { checkFailed } : {}),\n /* For the model - the card is the answer; it says what the person must still decide. */\n message:\n `proposed ${rows.length} rows (${rows.length - blocked} ready, ${blocked} blocked${cut ? `, ${cut} cut over the limit` : ''}; ` +\n `${verified} found line by line in their files, ${unmatched} with a value the file does not have). ` +\n totals.filter(total => total.difference).map(total => `${total.field}: the material's total differs from the rows by ${total.difference}. `).join('') +\n 'nothing is written until the person presses the button on the card. Tell them which rows are blocked or do not match their file, and why, and ask for what is missing.'\n }\n}\n\nexport function entryCategoryOf(target: EntryTarget): ToolCategory {\n const name = entryToolName(target.key)\n const spec = {\n kind: 'read',\n name,\n /* The person must be able to enter these records themselves - the tool is not a second way in. */\n doors: [entryDoorOf(target.mutation)],\n description:\n `Propose records to enter: ${target.description} ` +\n 'Pass every record found in the material as one row. The rows are shown to the person as a card; nothing is written until they press it.',\n schema: {\n type: 'object',\n properties: {\n rows: {\n type: 'array',\n description: `At most ${target.maxRows ?? 200} rows.`,\n items: {\n type: 'object',\n properties: {\n values: {\n type: 'object',\n properties: Object.fromEntries(target.fields.map(field => [field.name, fieldSchema(field)]))\n },\n sources: {\n type: 'array',\n description: 'Where this row came from: the attachment id and where in it (\"row 3\", \"the receipt photo\"), or where: \"the person\\'s message\".',\n items: { type: 'object', properties: { attachmentId: { type: 'string' }, where: { type: 'string' } } }\n }\n },\n required: ['values', 'sources']\n }\n },\n note: { type: 'string', description: 'One line for the card - what this set is (\"September card statement\").' },\n declaredTotal: {\n type: 'object',\n description: 'The total the material itself prints, when it prints one - the card compares it with the sum of the rows. Never compute it yourself.',\n properties: {\n field: { type: 'string', description: `Which field it totals${target.fields.filter(field => field.total).length ? ` (${target.fields.filter(field => field.total).map(field => field.name).join(', ')})` : ''}.` },\n value: { type: ['number', 'string'] },\n attachmentId: { type: 'string' },\n where: { type: 'string' }\n }\n }\n },\n required: ['rows']\n },\n builder: (args: any, context: any) => proposeEntries(target, args, context)\n } as ToolSpec\n\n return {\n name: entryCategoryName(target.key),\n description: `data entry: ${target.key}`,\n guidance: [\n `- When the person gives material to enter as records (files, photos, pasted text), read all of it first - call readChatAttachment for a file sent in an earlier turn - then call ${name} once with every record as a row.`,\n '- Never invent a value. Leave a field out when the material does not say it; the card marks it, and you ask the person for it.',\n '- Give each row its sources: which attachment and where in it. A value the person gave or corrected in the conversation adds the source where: \"the person\\'s message\". The server looks for each row\\'s numbers and dates in the cited file and marks what it does not find.',\n '- When the material prints a total, pass it as declaredTotal exactly as printed - do not add it up yourself.',\n `- ${name} only proposes. Nothing is entered until the person presses the button on the card - never say the records were entered.`,\n `- When the person corrects or drops rows, call ${name} again with the whole corrected set. The newest card replaces the earlier ones; an earlier card can no longer be entered.`\n ].join('\\n'),\n specs: [spec]\n }\n}\n\n/**\n * What an application calls at boot to let the assistant enter one of its records.\n *\n * A mode opens it by naming the key in `entryTargets` (the tool is not in every conversation of the app).\n */\nexport function registerEntryTarget(target: EntryTarget): void {\n declareEntryTarget(target)\n registerToolCategory(entryCategoryOf(target))\n}\n"]}
|
|
@@ -7,6 +7,8 @@ import { ChatMessageSubscription } from './chat-message/chat-message-subscriptio
|
|
|
7
7
|
import './chat-session/attachment-tools.js';
|
|
8
8
|
import './chat-session/session-purge.js';
|
|
9
9
|
import './chat-session/attachment-route.js';
|
|
10
|
+
import { EntryProposalResolver } from './data-entry/entry-resolver.js';
|
|
11
|
+
import './workspace/workspace-tools.js';
|
|
10
12
|
export * from './types.js';
|
|
11
13
|
export * from './chat-session-resolver.js';
|
|
12
14
|
export * from './assistant-chat-resolver.js';
|
|
@@ -14,6 +16,9 @@ export * from './assistant-mode/index.js';
|
|
|
14
16
|
export { requestTranslator } from './request-translator.js';
|
|
15
17
|
export * from './assistant-capability-resolver.js';
|
|
16
18
|
export * from './tool-access.js';
|
|
19
|
+
export * from './data-entry/entry-target.js';
|
|
20
|
+
export { registerEntryTarget, entryCategoryOf } from './data-entry/entry-tools.js';
|
|
21
|
+
export * from './workspace/workspace-blocks.js';
|
|
17
22
|
export * from './grounding-sources.js';
|
|
18
23
|
export * from './chat-session/session-anchor.js';
|
|
19
24
|
export * from './chat-session/session-visibility.js';
|
|
@@ -36,5 +41,5 @@ export * from './chat-message/index.js';
|
|
|
36
41
|
export * from './chat-session-participant/index.js';
|
|
37
42
|
export declare const entities: (typeof import("./chat-message/chat-message.js").ChatMessage | typeof import("./chat-session/chat-session.js").ChatSession | typeof import("./chat-session-participant/chat-session-participant.js").ChatSessionParticipant)[];
|
|
38
43
|
export declare const schema: {
|
|
39
|
-
resolverClasses: (typeof ChatSessionResolver | typeof AssistantChatResolver | typeof AssistantModeResolver | typeof AssistantCapabilityResolver | typeof MySessionActivitySubscription | typeof ChatMessageSubscription)[];
|
|
44
|
+
resolverClasses: (typeof ChatSessionResolver | typeof AssistantChatResolver | typeof AssistantModeResolver | typeof AssistantCapabilityResolver | typeof MySessionActivitySubscription | typeof ChatMessageSubscription | typeof EntryProposalResolver)[];
|
|
40
45
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.schema = exports.entities = exports.requestTranslator = void 0;
|
|
3
|
+
exports.schema = exports.entities = exports.entryCategoryOf = exports.registerEntryTarget = exports.requestTranslator = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const chat_session_resolver_js_1 = require("./chat-session-resolver.js");
|
|
6
6
|
const assistant_chat_resolver_js_1 = require("./assistant-chat-resolver.js");
|
|
@@ -14,6 +14,8 @@ const index_js_3 = require("./chat-session-participant/index.js");
|
|
|
14
14
|
require("./chat-session/attachment-tools.js");
|
|
15
15
|
require("./chat-session/session-purge.js");
|
|
16
16
|
require("./chat-session/attachment-route.js");
|
|
17
|
+
const entry_resolver_js_1 = require("./data-entry/entry-resolver.js");
|
|
18
|
+
require("./workspace/workspace-tools.js");
|
|
17
19
|
tslib_1.__exportStar(require("./types.js"), exports);
|
|
18
20
|
tslib_1.__exportStar(require("./chat-session-resolver.js"), exports);
|
|
19
21
|
tslib_1.__exportStar(require("./assistant-chat-resolver.js"), exports);
|
|
@@ -27,6 +29,13 @@ tslib_1.__exportStar(require("./assistant-capability-resolver.js"), exports);
|
|
|
27
29
|
* 실린다. 시험은 경로로 가져온다: `…/service/testing/conversation-script.js`.
|
|
28
30
|
*/
|
|
29
31
|
tslib_1.__exportStar(require("./tool-access.js"), exports);
|
|
32
|
+
/* Data entry from material - an app registers what it can enter; a mode names it (design/ai/data-entry.md). */
|
|
33
|
+
tslib_1.__exportStar(require("./data-entry/entry-target.js"), exports);
|
|
34
|
+
var entry_tools_js_1 = require("./data-entry/entry-tools.js");
|
|
35
|
+
Object.defineProperty(exports, "registerEntryTarget", { enumerable: true, get: function () { return entry_tools_js_1.registerEntryTarget; } });
|
|
36
|
+
Object.defineProperty(exports, "entryCategoryOf", { enumerable: true, get: function () { return entry_tools_js_1.entryCategoryOf; } });
|
|
37
|
+
/* The AI 작업판 - large results on a page of their own (design/ai/workspace.md). */
|
|
38
|
+
tslib_1.__exportStar(require("./workspace/workspace-blocks.js"), exports);
|
|
30
39
|
/* 무엇이 근거인가 — 도구 결과 밖의 셋(프롬프트 · 대화 · 화면 스냅숏). */
|
|
31
40
|
tslib_1.__exportStar(require("./grounding-sources.js"), exports);
|
|
32
41
|
/* 앵커 순수 로직 — 호스트가 앵커 종류를 참조한다(리졸버는 데코레이터 때문에 무겁다). */
|
|
@@ -65,7 +74,9 @@ exports.schema = {
|
|
|
65
74
|
assistant_capability_resolver_js_1.AssistantCapabilityResolver,
|
|
66
75
|
chat_message_subscription_js_1.ChatMessageSubscription,
|
|
67
76
|
/* 내가 참여한 모든 세션의 활동 — 창을 닫아 둔 표면이 배지·목록을 갱신할 수 있게. */
|
|
68
|
-
session_activity_subscription_js_1.MySessionActivitySubscription
|
|
77
|
+
session_activity_subscription_js_1.MySessionActivitySubscription,
|
|
78
|
+
/* 사람이 누른 입력 제안을 쓰는 자리 — 행마다 앱의 코드로, 그 사람의 권한으로. */
|
|
79
|
+
entry_resolver_js_1.EntryProposalResolver
|
|
69
80
|
]
|
|
70
81
|
};
|
|
71
82
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../server/service/index.ts"],"names":[],"mappings":";;;;AAAA,yEAAgE;AAChE,6EAAoE;AACpE,4FAAmF;AACnF,yFAAgF;AAChF,sGAA+F;AAC/F,8FAAqF;AACrF,sDAAyE;AACzE,sDAAyE;AACzE,kEAAgG;AAChG,8CAA2C;AAC3C,2CAAwC;AACxC,8CAA2C;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../server/service/index.ts"],"names":[],"mappings":";;;;AAAA,yEAAgE;AAChE,6EAAoE;AACpE,4FAAmF;AACnF,yFAAgF;AAChF,sGAA+F;AAC/F,8FAAqF;AACrF,sDAAyE;AACzE,sDAAyE;AACzE,kEAAgG;AAChG,8CAA2C;AAC3C,2CAAwC;AACxC,8CAA2C;AAC3C,sEAAsE;AACtE,0CAAuC;AAEvC,qDAA0B;AAC1B,qEAA0C;AAC1C,uEAA4C;AAC5C,oGAAoG;AACpG,oEAAyC;AACzC,iEAA2D;AAAlD,0HAAA,iBAAiB,OAAA;AAC1B,6EAAkD;AAClD;;;GAGG;AACH,2DAAgC;AAChC,+GAA+G;AAC/G,uEAA4C;AAC5C,8DAAkF;AAAzE,qHAAA,mBAAmB,OAAA;AAAE,iHAAA,eAAe,OAAA;AAC7C,iFAAiF;AACjF,0EAA+C;AAC/C,gDAAgD;AAChD,iEAAsC;AACtC,sDAAsD;AACtD,2EAAgD;AAChD,gHAAgH;AAChH,+EAAoD;AACpD,kEAAuC;AACvC,8DAA8D;AAC9D,0EAA+C;AAC/C,8EAAmD;AACnD,0EAA+C;AAC/C,qFAA0D;AAC1D,uFAA4D;AAC5D,wEAA6C;AAC7C,4EAAiD;AACjD,yEAA8C;AAC9C,wDAAwD;AACxD,iFAAsD;AACtD,iFAAsD;AACtD,mFAAwD;AACxD,4FAAiE;AACjE,2DAA2D;AAC3D,uFAA4D;AAC5D,iFAAsD;AACtD,kEAAuC;AACvC,8EAAmD;AAEtC,QAAA,QAAQ,GAAG,CAAC,GAAG,mBAAmB,EAAE,GAAG,mBAAmB,EAAE,GAAG,mBAA8B,CAAC,CAAA;AAE9F,QAAA,MAAM,GAAG;IACpB,eAAe,EAAE;QACf,8CAAmB;QACnB,sDAAsD;QACtD,kDAAqB;QACrB,uDAAuD;QACvD,kDAAqB;QACrB,wDAAwD;QACxD,8DAA2B;QAC3B,sDAAuB;QACvB,qDAAqD;QACrD,gEAA6B;QAC7B,mDAAmD;QACnD,yCAAqB;KACtB;CACF,CAAA","sourcesContent":["import { ChatSessionResolver } from './chat-session-resolver.js'\nimport { AssistantChatResolver } from './assistant-chat-resolver.js'\nimport { AssistantModeResolver } from './assistant-mode/assistant-mode-resolver.js'\nimport { AssistantCapabilityResolver } from './assistant-capability-resolver.js'\nimport { MySessionActivitySubscription } from './chat-session/session-activity-subscription.js'\nimport { ChatMessageSubscription } from './chat-message/chat-message-subscription.js'\nimport { entities as ChatSessionEntities } from './chat-session/index.js'\nimport { entities as ChatMessageEntities } from './chat-message/index.js'\nimport { entities as ChatSessionParticipantEntities } from './chat-session-participant/index.js'\nimport './chat-session/attachment-tools.js'\nimport './chat-session/session-purge.js'\nimport './chat-session/attachment-route.js'\nimport { EntryProposalResolver } from './data-entry/entry-resolver.js'\nimport './workspace/workspace-tools.js'\n\nexport * from './types.js'\nexport * from './chat-session-resolver.js'\nexport * from './assistant-chat-resolver.js'\n/* The mode registry — each app server declares what its conversations are (ADR-0061 decision 7). */\nexport * from './assistant-mode/index.js'\nexport { requestTranslator } from './request-translator.js'\nexport * from './assistant-capability-resolver.js'\n/*\n * 대화 각본 하네스는 **런타임 export 에서 뺀다**(ADR-0070 A15 결정 ④) — 시험 도구가 서버 번들에\n * 실린다. 시험은 경로로 가져온다: `…/service/testing/conversation-script.js`.\n */\nexport * from './tool-access.js'\n/* Data entry from material - an app registers what it can enter; a mode names it (design/ai/data-entry.md). */\nexport * from './data-entry/entry-target.js'\nexport { registerEntryTarget, entryCategoryOf } from './data-entry/entry-tools.js'\n/* The AI 작업판 - large results on a page of their own (design/ai/workspace.md). */\nexport * from './workspace/workspace-blocks.js'\n/* 무엇이 근거인가 — 도구 결과 밖의 셋(프롬프트 · 대화 · 화면 스냅숏). */\nexport * from './grounding-sources.js'\n/* 앵커 순수 로직 — 호스트가 앵커 종류를 참조한다(리졸버는 데코레이터 때문에 무겁다). */\nexport * from './chat-session/session-anchor.js'\n/* Who may read a conversation — one rule, also asked by doors outside this package (board-ai's revertPatch). */\nexport * from './chat-session/session-visibility.js'\nexport * from './chat-session/index.js'\n/* 순수 로직들 — 호스트(board-ai 등)가 같은 규칙을 쓰라고 공개한다. 베끼면 한쪽만 고쳐진다. */\nexport * from './chat-session/session-inbox.js'\nexport * from './chat-session/attachment-policy.js'\nexport * from './chat-session/session-purge.js'\nexport * from './chat-session/session-activity-publish.js'\nexport * from './chat-session/session-activity-broadcast.js'\nexport * from './chat-message/llm-history.js'\nexport * from './chat-message/history-summary.js'\nexport * from './chat-message/fold-history.js'\n/* 상한 밖으로 밀려난 앞부분을 요약으로 접는 orchestration — 중립 문이 부른다. */\nexport * from './chat-message/fold-session-history.js'\nexport * from './chat-message/chat-message-publish.js'\nexport * from './chat-message/chat-message-broadcast.js'\nexport * from './chat-session-participant/invite-notification.js'\n/* 멘션이 사람을 불러들이는 자리 — 사람의 말을 저장하는 문만 부른다(ADR-0071 결정 1). */\nexport * from './chat-session-participant/mention-invite.js'\nexport * from './chat-session-participant/presence.js'\nexport * from './chat-message/index.js'\nexport * from './chat-session-participant/index.js'\n\nexport const entities = [...ChatSessionEntities, ...ChatMessageEntities, ...ChatSessionParticipantEntities]\n\nexport const schema = {\n resolverClasses: [\n ChatSessionResolver,\n /* 문서를 갖지 않은 표면의 대화 — board 를 안 싣는 제품이 물어볼 수 있는 자리. */\n AssistantChatResolver,\n /* 화면이 자기 대화가 무엇을 주는지 묻는 자리 — 문구는 서버가 요청 로케일로 옮겨 낸다. */\n AssistantModeResolver,\n /* 「이 배포에 AI 가 있나 · 무엇이 선언 없이 등록됐나」 — 창구 하나(표준 A7-a). */\n AssistantCapabilityResolver,\n ChatMessageSubscription,\n /* 내가 참여한 모든 세션의 활동 — 창을 닫아 둔 표면이 배지·목록을 갱신할 수 있게. */\n MySessionActivitySubscription,\n /* 사람이 누른 입력 제안을 쓰는 자리 — 행마다 앱의 코드로, 그 사람의 권한으로. */\n EntryProposalResolver\n ]\n}\n"]}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export declare const WORKSPACE_BLOCK_KINDS: readonly ["heading", "text", "metrics", "table", "chart", "steps"];
|
|
2
|
+
export type WorkspaceBlockKind = (typeof WORKSPACE_BLOCK_KINDS)[number];
|
|
3
|
+
export declare const MAX_BLOCKS = 40;
|
|
4
|
+
export declare const MAX_TABLE_ROWS = 1000;
|
|
5
|
+
export declare const MAX_SERIES = 8;
|
|
6
|
+
export interface WorkspaceBlock {
|
|
7
|
+
kind: WorkspaceBlockKind | 'unreadable';
|
|
8
|
+
[key: string]: unknown;
|
|
9
|
+
}
|
|
10
|
+
export interface Workspace {
|
|
11
|
+
name: string;
|
|
12
|
+
title: string;
|
|
13
|
+
summary?: string;
|
|
14
|
+
blocks: WorkspaceBlock[];
|
|
15
|
+
}
|
|
16
|
+
/** A short key of the workspace - the same name in one conversation is the same workspace, a new version. */
|
|
17
|
+
export declare function workspaceName(name: unknown, title: string): string;
|
|
18
|
+
/** The workspace as the screen reads it. */
|
|
19
|
+
export declare function normalizeWorkspace(args: any): {
|
|
20
|
+
workspace?: Workspace;
|
|
21
|
+
error?: string;
|
|
22
|
+
};
|
|
23
|
+
/** One line of what is in it - for the card in the conversation and for the model. */
|
|
24
|
+
export declare function workspaceContents(workspace: Workspace): Record<string, number>;
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* The AI 작업판 - what a workspace is made of (operato-application/design/ai/workspace.md §3).
|
|
4
|
+
*
|
|
5
|
+
* The model does not write HTML. A workspace is a list of blocks of known kinds; the screen draws each, so
|
|
6
|
+
* theme, language and accessibility are the framework's. A block that does not fit is not dropped: it is
|
|
7
|
+
* kept as a fact in its place ("a block that cannot be drawn"), so the person sees that something was meant
|
|
8
|
+
* to be there. Pure - tested without a server.
|
|
9
|
+
*/
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.MAX_SERIES = exports.MAX_TABLE_ROWS = exports.MAX_BLOCKS = exports.WORKSPACE_BLOCK_KINDS = void 0;
|
|
12
|
+
exports.workspaceName = workspaceName;
|
|
13
|
+
exports.normalizeWorkspace = normalizeWorkspace;
|
|
14
|
+
exports.workspaceContents = workspaceContents;
|
|
15
|
+
exports.WORKSPACE_BLOCK_KINDS = ['heading', 'text', 'metrics', 'table', 'chart', 'steps'];
|
|
16
|
+
exports.MAX_BLOCKS = 40;
|
|
17
|
+
exports.MAX_TABLE_ROWS = 1000;
|
|
18
|
+
exports.MAX_SERIES = 8;
|
|
19
|
+
const MAX_TEXT = 20_000;
|
|
20
|
+
const text = (value, max = 500) => (typeof value === 'string' && value.trim() ? value.trim().slice(0, max) : undefined);
|
|
21
|
+
const scalar = (value) => value === null || value === undefined ? null : typeof value === 'number' || typeof value === 'boolean' ? value : String(value).slice(0, 500);
|
|
22
|
+
/** A short key of the workspace - the same name in one conversation is the same workspace, a new version. */
|
|
23
|
+
function workspaceName(name, title) {
|
|
24
|
+
const given = typeof name === 'string' ? name.trim().toLowerCase() : '';
|
|
25
|
+
if (/^[a-z0-9][a-z0-9-]{0,63}$/.test(given))
|
|
26
|
+
return given;
|
|
27
|
+
const slug = (given || title)
|
|
28
|
+
.toLowerCase()
|
|
29
|
+
.replace(/[^a-z0-9가-힣]+/g, '-')
|
|
30
|
+
.replace(/^-+|-+$/g, '')
|
|
31
|
+
.slice(0, 64);
|
|
32
|
+
return slug || 'workspace';
|
|
33
|
+
}
|
|
34
|
+
function unreadable(kind, reason) {
|
|
35
|
+
return { kind: 'unreadable', was: typeof kind === 'string' ? kind.slice(0, 40) : null, reason };
|
|
36
|
+
}
|
|
37
|
+
function block(raw) {
|
|
38
|
+
const kind = raw?.kind;
|
|
39
|
+
switch (kind) {
|
|
40
|
+
case 'heading': {
|
|
41
|
+
const value = text(raw.text, 200);
|
|
42
|
+
if (!value)
|
|
43
|
+
return unreadable(kind, 'no-text');
|
|
44
|
+
const level = [1, 2, 3].includes(raw.level) ? raw.level : 2;
|
|
45
|
+
return { kind, text: value, level };
|
|
46
|
+
}
|
|
47
|
+
case 'text': {
|
|
48
|
+
const value = text(raw.markdown ?? raw.text, MAX_TEXT);
|
|
49
|
+
return value ? { kind, markdown: value } : unreadable(kind, 'no-text');
|
|
50
|
+
}
|
|
51
|
+
case 'metrics': {
|
|
52
|
+
const items = (Array.isArray(raw.items) ? raw.items : [])
|
|
53
|
+
.filter((one) => text(one?.label) && one?.value !== undefined && one?.value !== null)
|
|
54
|
+
.slice(0, 12)
|
|
55
|
+
.map((one) => ({ 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) } : {}) }));
|
|
56
|
+
return items.length ? { kind, items } : unreadable(kind, 'no-items');
|
|
57
|
+
}
|
|
58
|
+
case 'table': {
|
|
59
|
+
const columns = (Array.isArray(raw.columns) ? raw.columns : [])
|
|
60
|
+
.filter((one) => text(one?.name, 80))
|
|
61
|
+
.slice(0, 30)
|
|
62
|
+
.map((one) => ({ name: text(one.name, 80), ...(text(one.label, 80) ? { label: text(one.label, 80) } : {}), type: ['number', 'date', 'string'].includes(one.type) ? one.type : 'string' }));
|
|
63
|
+
if (!columns.length)
|
|
64
|
+
return unreadable(kind, 'no-columns');
|
|
65
|
+
const given = Array.isArray(raw.rows) ? raw.rows : [];
|
|
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])])));
|
|
68
|
+
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
|
+
}
|
|
70
|
+
case 'chart': {
|
|
71
|
+
const x = (Array.isArray(raw.x) ? raw.x : []).slice(0, 200).map((one) => String(one ?? '').slice(0, 60));
|
|
72
|
+
const series = (Array.isArray(raw.series) ? raw.series : [])
|
|
73
|
+
.filter((one) => text(one?.name, 60) && Array.isArray(one?.values))
|
|
74
|
+
.map((one) => ({ name: text(one.name, 60), values: x.map((_, i) => (typeof one.values[i] === 'number' && Number.isFinite(one.values[i]) ? one.values[i] : null)) }));
|
|
75
|
+
if (!x.length || !series.length)
|
|
76
|
+
return unreadable(kind, 'no-series');
|
|
77
|
+
/* Never a ninth hue: past eight, the first seven stay and the rest fold into one "other". */
|
|
78
|
+
const shown = series.length > exports.MAX_SERIES
|
|
79
|
+
? [
|
|
80
|
+
...series.slice(0, exports.MAX_SERIES - 1),
|
|
81
|
+
{ name: 'other', other: true, values: x.map((_, i) => series.slice(exports.MAX_SERIES - 1).reduce((acc, one) => acc + (one.values[i] ?? 0), 0)) }
|
|
82
|
+
]
|
|
83
|
+
: series;
|
|
84
|
+
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) } : {}) };
|
|
85
|
+
}
|
|
86
|
+
case 'steps': {
|
|
87
|
+
const items = (Array.isArray(raw.items) ? raw.items : [])
|
|
88
|
+
.filter((one) => text(one?.label, 200))
|
|
89
|
+
.slice(0, 50)
|
|
90
|
+
.map((one) => ({ 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) } : {}) }));
|
|
91
|
+
return items.length ? { kind, items } : unreadable(kind, 'no-items');
|
|
92
|
+
}
|
|
93
|
+
default:
|
|
94
|
+
return unreadable(kind, 'unknown-kind');
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
/** The workspace as the screen reads it. */
|
|
98
|
+
function normalizeWorkspace(args) {
|
|
99
|
+
const title = text(args?.title, 200);
|
|
100
|
+
if (!title)
|
|
101
|
+
return { error: 'no-title' };
|
|
102
|
+
const given = Array.isArray(args?.blocks) ? args.blocks : [];
|
|
103
|
+
if (!given.length)
|
|
104
|
+
return { error: 'no-blocks' };
|
|
105
|
+
const blocks = given.slice(0, exports.MAX_BLOCKS).map(block);
|
|
106
|
+
if (given.length > exports.MAX_BLOCKS)
|
|
107
|
+
blocks.push({ kind: 'unreadable', was: null, reason: 'too-many-blocks', cut: given.length - exports.MAX_BLOCKS });
|
|
108
|
+
return { workspace: { name: workspaceName(args?.name, title), title, ...(text(args?.summary, 500) ? { summary: text(args.summary, 500) } : {}), blocks } };
|
|
109
|
+
}
|
|
110
|
+
/** One line of what is in it - for the card in the conversation and for the model. */
|
|
111
|
+
function workspaceContents(workspace) {
|
|
112
|
+
const counts = {};
|
|
113
|
+
for (const one of workspace.blocks)
|
|
114
|
+
if (['table', 'chart', 'metrics', 'steps'].includes(one.kind))
|
|
115
|
+
counts[one.kind] = (counts[one.kind] ?? 0) + 1;
|
|
116
|
+
return counts;
|
|
117
|
+
}
|
|
118
|
+
//# sourceMappingURL=workspace-blocks.js.map
|
|
@@ -0,0 +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,KA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AI,CAAC,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC;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"]}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { type ToolCategory } from '@things-factory/ai-client-base';
|
|
2
|
+
export declare const WORKSPACE_CATEGORY = "assistant-workspace";
|
|
3
|
+
export declare function showInWorkspace(args: any): {
|
|
4
|
+
rejected: boolean;
|
|
5
|
+
error: string;
|
|
6
|
+
message: string;
|
|
7
|
+
proposed?: undefined;
|
|
8
|
+
kind?: undefined;
|
|
9
|
+
icon?: undefined;
|
|
10
|
+
label?: undefined;
|
|
11
|
+
workspace?: undefined;
|
|
12
|
+
contents?: undefined;
|
|
13
|
+
} | {
|
|
14
|
+
proposed: boolean;
|
|
15
|
+
kind: string;
|
|
16
|
+
icon: string;
|
|
17
|
+
label: string;
|
|
18
|
+
workspace: import("./workspace-blocks.js").Workspace;
|
|
19
|
+
contents: Record<string, number>;
|
|
20
|
+
message: string;
|
|
21
|
+
rejected?: undefined;
|
|
22
|
+
error?: undefined;
|
|
23
|
+
};
|
|
24
|
+
export declare const workspaceCategory: ToolCategory;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.workspaceCategory = exports.WORKSPACE_CATEGORY = void 0;
|
|
4
|
+
exports.showInWorkspace = showInWorkspace;
|
|
5
|
+
/*
|
|
6
|
+
* showInWorkspace - the model puts a large result on the AI 작업판 (operato-application/design/ai/workspace.md §5).
|
|
7
|
+
*
|
|
8
|
+
* The result rides on the answer as a proposal of kind 'workspace', so the conversation's gates hold for it:
|
|
9
|
+
* who may read the conversation reads the workspace, and a value behind a door the reader cannot pass hides
|
|
10
|
+
* it with the answer (ADR-0073). The tool itself reaches no door - what it carries came from the turn's other
|
|
11
|
+
* tools, whose doors the answer row collects.
|
|
12
|
+
*/
|
|
13
|
+
const ai_client_base_1 = require("@things-factory/ai-client-base");
|
|
14
|
+
const workspace_blocks_js_1 = require("./workspace-blocks.js");
|
|
15
|
+
exports.WORKSPACE_CATEGORY = 'assistant-workspace';
|
|
16
|
+
function showInWorkspace(args) {
|
|
17
|
+
const { workspace, error } = (0, workspace_blocks_js_1.normalizeWorkspace)(args);
|
|
18
|
+
if (!workspace)
|
|
19
|
+
return { rejected: true, error, message: 'a workspace needs a title and at least one block.' };
|
|
20
|
+
const contents = (0, workspace_blocks_js_1.workspaceContents)(workspace);
|
|
21
|
+
return {
|
|
22
|
+
proposed: true,
|
|
23
|
+
kind: 'workspace',
|
|
24
|
+
icon: 'dashboard',
|
|
25
|
+
label: workspace.title,
|
|
26
|
+
workspace,
|
|
27
|
+
contents,
|
|
28
|
+
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.`
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
const spec = {
|
|
32
|
+
kind: 'read',
|
|
33
|
+
name: 'showInWorkspace',
|
|
34
|
+
doors: [],
|
|
35
|
+
description: 'Put a large result on the AI workspace - a page the person opens from a card, beside the conversation. Blocks: ' +
|
|
36
|
+
'heading{text,level}, text{markdown}, metrics{items:[{label,value,unit,note}]}, table{columns:[{name,label,type:number|date|string}],rows,caption}, ' +
|
|
37
|
+
'chart{chart:bar|line, x:[labels], series:[{name,values:[numbers]}], unit, caption}, steps{items:[{label,state:done|doing|todo|failed,note}]}.',
|
|
38
|
+
schema: {
|
|
39
|
+
type: 'object',
|
|
40
|
+
properties: {
|
|
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
|
+
title: { type: 'string' },
|
|
43
|
+
summary: { type: 'string', description: 'One line under the title.' },
|
|
44
|
+
blocks: {
|
|
45
|
+
type: 'array',
|
|
46
|
+
items: { type: 'object', properties: { kind: { type: 'string', enum: [...workspace_blocks_js_1.WORKSPACE_BLOCK_KINDS] } }, required: ['kind'] }
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
required: ['name', 'title', 'blocks']
|
|
50
|
+
},
|
|
51
|
+
builder: (args) => showInWorkspace(args)
|
|
52
|
+
};
|
|
53
|
+
exports.workspaceCategory = {
|
|
54
|
+
name: exports.WORKSPACE_CATEGORY,
|
|
55
|
+
description: 'the AI workspace - a page for results too large for the conversation',
|
|
56
|
+
guidance: [
|
|
57
|
+
'- 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.',
|
|
58
|
+
'- Every number in a block comes from a tool result in this conversation - never computed or guessed by you.',
|
|
59
|
+
'- To change a workspace, call showInWorkspace again with the same name and the whole new content; it becomes a new version.',
|
|
60
|
+
'- Never say something is on the workspace unless you called showInWorkspace in this turn.'
|
|
61
|
+
].join('\n'),
|
|
62
|
+
specs: [spec]
|
|
63
|
+
};
|
|
64
|
+
(0, ai_client_base_1.registerToolCategory)(exports.workspaceCategory);
|
|
65
|
+
//# sourceMappingURL=workspace-tools.js.map
|
|
@@ -0,0 +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,C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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 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"]}
|