@things-factory/ai-assistant 10.1.278 → 10.1.279
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist-client/bootstrap.d.ts +4 -4
- package/dist-client/bootstrap.js +4 -8
- package/dist-client/components/ai-model-price-table.d.ts +32 -0
- package/dist-client/components/ai-model-price-table.js +311 -0
- package/dist-client/components/ai-usage-table.d.ts +17 -0
- package/dist-client/components/ai-usage-table.js +151 -0
- package/dist-client/index.d.ts +1 -0
- package/dist-client/index.js +2 -0
- package/dist-client/pages/ai-model-price-page.d.ts +37 -0
- package/dist-client/pages/ai-model-price-page.js +312 -0
- package/dist-client/route.d.ts +1 -1
- package/dist-client/route.js +4 -0
- package/dist-client/settings/ai-agent-setting-let.js +11 -0
- package/dist-client/utils/model-price-model.d.ts +31 -0
- package/dist-client/utils/model-price-model.js +30 -0
- package/dist-client/utils/usage-charts.d.ts +21 -0
- package/dist-client/utils/usage-charts.js +45 -0
- package/dist-client/utils/usage-model.d.ts +44 -0
- package/dist-client/utils/usage-model.js +44 -0
- package/dist-server/service/ai-agent-resolver.d.ts +46 -0
- package/dist-server/service/ai-agent-resolver.js +252 -0
- package/package.json +25 -10
- package/things-factory.config.js +4 -1
- package/translations/en.json +46 -4
- package/translations/es.json +43 -1
- package/translations/ja.json +43 -1
- package/translations/ko.json +46 -4
- package/translations/ms.json +43 -1
- package/translations/zh.json +43 -1
- package/client/bootstrap.ts +0 -27
- package/client/components/assistant-chat.test.ts +0 -149
- package/client/components/assistant-chat.ts +0 -5599
- package/client/components/assistant-dock.ts +0 -1036
- package/client/components/assistant-invite.ts +0 -138
- package/client/components/assistant-mode.test.ts +0 -119
- package/client/components/assistant-mode.ts +0 -174
- package/client/components/assistant-selection-bar.test.ts +0 -167
- package/client/components/assistant-selection-bar.ts +0 -178
- package/client/components/assistant-session-manager.ts +0 -915
- package/client/components/assistant-session-toolbar.ts +0 -80
- package/client/components/chat-defaults.ts +0 -64
- package/client/components/chat-echo-dedup.test.ts +0 -253
- package/client/components/chat-echo-dedup.ts +0 -190
- package/client/components/chat-input-builder.test.ts +0 -86
- package/client/components/chat-input-builder.ts +0 -133
- package/client/components/chat-proposal-survival.test.ts +0 -73
- package/client/components/entry-review.ts +0 -346
- package/client/components/markdown.test.ts +0 -518
- package/client/components/markdown.ts +0 -508
- package/client/components/mention-popup-helpers.ts +0 -433
- package/client/components/mention-popup.test.ts +0 -588
- package/client/components/mention-popup.ts +0 -261
- package/client/components/panel-aria.test.ts +0 -59
- package/client/components/proposal-outcome-line.ts +0 -74
- package/client/components/proposal-request.test.ts +0 -73
- package/client/components/reply-message.test.ts +0 -15
- package/client/components/reply-message.ts +0 -11
- package/client/components/roster-identity.test.ts +0 -8
- package/client/components/roster-identity.ts +0 -4
- package/client/components/workspace-view.ts +0 -486
- package/client/index.ts +0 -36
- package/client/pages/assistant-workspace-page.ts +0 -317
- package/client/route.ts +0 -9
- package/client/settings/agent-settings-model.ts +0 -164
- package/client/settings/ai-agent-setting-let.ts +0 -667
- package/client/settings/ai-usage-setting-let.ts +0 -240
- package/client/settings/usage-model.ts +0 -46
- package/client/setup-assistant-dock.ts +0 -177
- package/client/tsconfig.json +0 -13
- package/client/utils/addressed-draft.test.ts +0 -31
- package/client/utils/agent-choice.ts +0 -56
- package/client/utils/applied-screens.ts +0 -36
- package/client/utils/assistant-activity.ts +0 -122
- package/client/utils/assistant-ask.test.ts +0 -38
- package/client/utils/assistant-ask.ts +0 -93
- package/client/utils/assistant-capability-read.ts +0 -24
- package/client/utils/assistant-capability.test.ts +0 -17
- package/client/utils/assistant-capability.ts +0 -19
- package/client/utils/assistant-navigation.test.ts +0 -66
- package/client/utils/assistant-navigation.ts +0 -11
- package/client/utils/assistant-proposals.ts +0 -85
- package/client/utils/assistant-request-context.ts +0 -63
- package/client/utils/assistant-selection.test.ts +0 -54
- package/client/utils/assistant-selection.ts +0 -75
- package/client/utils/assistant-session-actions.ts +0 -32
- package/client/utils/assistant-session-admin.ts +0 -239
- package/client/utils/assistant-session-controller.test.ts +0 -75
- package/client/utils/assistant-session-controller.ts +0 -208
- package/client/utils/assistant-session-transport.ts +0 -46
- package/client/utils/assistant-surface.ts +0 -178
- package/client/utils/assistant-typing.test.ts +0 -33
- package/client/utils/assistant-typing.ts +0 -53
- package/client/utils/attachment-policy.ts +0 -106
- package/client/utils/composer-frame.ts +0 -77
- package/client/utils/document-text.ts +0 -332
- package/client/utils/entry-hash.ts +0 -35
- package/client/utils/entry-proposal.ts +0 -215
- package/client/utils/entry-workspace.ts +0 -70
- package/client/utils/invite-proposal-register.ts +0 -31
- package/client/utils/invite-proposal.test.ts +0 -40
- package/client/utils/invite-proposal.ts +0 -54
- package/client/utils/menu-room.ts +0 -33
- package/client/utils/open-page.ts +0 -21
- package/client/utils/pasted-table.ts +0 -145
- package/client/utils/pdf-pages.ts +0 -25
- package/client/utils/spreadsheet-text.ts +0 -125
- package/client/utils/workspace.ts +0 -89
- package/dist-client/bootstrap.js.map +0 -1
- package/dist-client/components/assistant-chat.js.map +0 -1
- package/dist-client/components/assistant-chat.test.d.ts +0 -1
- package/dist-client/components/assistant-chat.test.js +0 -138
- package/dist-client/components/assistant-chat.test.js.map +0 -1
- package/dist-client/components/assistant-dock.js.map +0 -1
- package/dist-client/components/assistant-invite.js.map +0 -1
- package/dist-client/components/assistant-mode.js.map +0 -1
- package/dist-client/components/assistant-mode.test.d.ts +0 -1
- package/dist-client/components/assistant-mode.test.js +0 -100
- package/dist-client/components/assistant-mode.test.js.map +0 -1
- package/dist-client/components/assistant-selection-bar.js.map +0 -1
- package/dist-client/components/assistant-selection-bar.test.d.ts +0 -1
- package/dist-client/components/assistant-selection-bar.test.js +0 -148
- package/dist-client/components/assistant-selection-bar.test.js.map +0 -1
- package/dist-client/components/assistant-session-manager.js.map +0 -1
- package/dist-client/components/assistant-session-toolbar.js.map +0 -1
- package/dist-client/components/chat-defaults.js.map +0 -1
- package/dist-client/components/chat-echo-dedup.js.map +0 -1
- package/dist-client/components/chat-echo-dedup.test.d.ts +0 -1
- package/dist-client/components/chat-echo-dedup.test.js +0 -223
- package/dist-client/components/chat-echo-dedup.test.js.map +0 -1
- package/dist-client/components/chat-input-builder.js.map +0 -1
- package/dist-client/components/chat-input-builder.test.d.ts +0 -1
- package/dist-client/components/chat-input-builder.test.js +0 -70
- package/dist-client/components/chat-input-builder.test.js.map +0 -1
- package/dist-client/components/chat-proposal-survival.test.d.ts +0 -1
- package/dist-client/components/chat-proposal-survival.test.js +0 -61
- package/dist-client/components/chat-proposal-survival.test.js.map +0 -1
- package/dist-client/components/entry-review.js.map +0 -1
- package/dist-client/components/markdown.js.map +0 -1
- package/dist-client/components/markdown.test.d.ts +0 -1
- package/dist-client/components/markdown.test.js +0 -418
- package/dist-client/components/markdown.test.js.map +0 -1
- package/dist-client/components/mention-popup-helpers.js.map +0 -1
- package/dist-client/components/mention-popup.js.map +0 -1
- package/dist-client/components/mention-popup.test.d.ts +0 -1
- package/dist-client/components/mention-popup.test.js +0 -474
- package/dist-client/components/mention-popup.test.js.map +0 -1
- package/dist-client/components/panel-aria.test.d.ts +0 -1
- package/dist-client/components/panel-aria.test.js +0 -53
- package/dist-client/components/panel-aria.test.js.map +0 -1
- package/dist-client/components/proposal-outcome-line.js.map +0 -1
- package/dist-client/components/proposal-request.test.d.ts +0 -1
- package/dist-client/components/proposal-request.test.js +0 -63
- package/dist-client/components/proposal-request.test.js.map +0 -1
- package/dist-client/components/reply-message.js.map +0 -1
- package/dist-client/components/reply-message.test.d.ts +0 -1
- package/dist-client/components/reply-message.test.js +0 -16
- package/dist-client/components/reply-message.test.js.map +0 -1
- package/dist-client/components/roster-identity.js.map +0 -1
- package/dist-client/components/roster-identity.test.d.ts +0 -1
- package/dist-client/components/roster-identity.test.js +0 -9
- package/dist-client/components/roster-identity.test.js.map +0 -1
- package/dist-client/components/workspace-view.js.map +0 -1
- package/dist-client/index.js.map +0 -1
- package/dist-client/pages/assistant-workspace-page.js.map +0 -1
- package/dist-client/route.js.map +0 -1
- package/dist-client/settings/agent-settings-model.js.map +0 -1
- package/dist-client/settings/ai-agent-setting-let.js.map +0 -1
- package/dist-client/settings/ai-usage-setting-let.d.ts +0 -25
- package/dist-client/settings/ai-usage-setting-let.js +0 -258
- package/dist-client/settings/ai-usage-setting-let.js.map +0 -1
- package/dist-client/settings/usage-model.d.ts +0 -32
- package/dist-client/settings/usage-model.js +0 -25
- package/dist-client/settings/usage-model.js.map +0 -1
- package/dist-client/setup-assistant-dock.js.map +0 -1
- package/dist-client/tsconfig.tsbuildinfo +0 -1
- package/dist-client/utils/addressed-draft.test.d.ts +0 -1
- package/dist-client/utils/addressed-draft.test.js +0 -27
- package/dist-client/utils/addressed-draft.test.js.map +0 -1
- package/dist-client/utils/agent-choice.js.map +0 -1
- package/dist-client/utils/applied-screens.js.map +0 -1
- package/dist-client/utils/assistant-activity.js.map +0 -1
- package/dist-client/utils/assistant-ask.js.map +0 -1
- package/dist-client/utils/assistant-ask.test.d.ts +0 -1
- package/dist-client/utils/assistant-ask.test.js +0 -40
- package/dist-client/utils/assistant-ask.test.js.map +0 -1
- package/dist-client/utils/assistant-capability-read.js.map +0 -1
- package/dist-client/utils/assistant-capability.js.map +0 -1
- package/dist-client/utils/assistant-capability.test.d.ts +0 -1
- package/dist-client/utils/assistant-capability.test.js +0 -16
- package/dist-client/utils/assistant-capability.test.js.map +0 -1
- package/dist-client/utils/assistant-navigation.js.map +0 -1
- package/dist-client/utils/assistant-navigation.test.d.ts +0 -1
- package/dist-client/utils/assistant-navigation.test.js +0 -63
- package/dist-client/utils/assistant-navigation.test.js.map +0 -1
- package/dist-client/utils/assistant-proposals.js.map +0 -1
- package/dist-client/utils/assistant-request-context.js.map +0 -1
- package/dist-client/utils/assistant-selection.js.map +0 -1
- package/dist-client/utils/assistant-selection.test.d.ts +0 -1
- package/dist-client/utils/assistant-selection.test.js +0 -46
- package/dist-client/utils/assistant-selection.test.js.map +0 -1
- package/dist-client/utils/assistant-session-actions.js.map +0 -1
- package/dist-client/utils/assistant-session-admin.js.map +0 -1
- package/dist-client/utils/assistant-session-controller.js.map +0 -1
- package/dist-client/utils/assistant-session-controller.test.d.ts +0 -1
- package/dist-client/utils/assistant-session-controller.test.js +0 -56
- package/dist-client/utils/assistant-session-controller.test.js.map +0 -1
- package/dist-client/utils/assistant-session-transport.js.map +0 -1
- package/dist-client/utils/assistant-surface.js.map +0 -1
- package/dist-client/utils/assistant-typing.js.map +0 -1
- package/dist-client/utils/assistant-typing.test.d.ts +0 -1
- package/dist-client/utils/assistant-typing.test.js +0 -30
- package/dist-client/utils/assistant-typing.test.js.map +0 -1
- package/dist-client/utils/attachment-policy.js.map +0 -1
- package/dist-client/utils/composer-frame.js.map +0 -1
- package/dist-client/utils/document-text.js.map +0 -1
- package/dist-client/utils/entry-hash.js.map +0 -1
- package/dist-client/utils/entry-proposal.js.map +0 -1
- package/dist-client/utils/entry-workspace.js.map +0 -1
- package/dist-client/utils/invite-proposal-register.js.map +0 -1
- package/dist-client/utils/invite-proposal.js.map +0 -1
- package/dist-client/utils/invite-proposal.test.d.ts +0 -1
- package/dist-client/utils/invite-proposal.test.js +0 -35
- package/dist-client/utils/invite-proposal.test.js.map +0 -1
- package/dist-client/utils/menu-room.js.map +0 -1
- package/dist-client/utils/open-page.js.map +0 -1
- package/dist-client/utils/pasted-table.js.map +0 -1
- package/dist-client/utils/pdf-pages.js.map +0 -1
- package/dist-client/utils/spreadsheet-text.js.map +0 -1
- package/dist-client/utils/workspace.js.map +0 -1
- package/dist-server/door-declaration-report.js.map +0 -1
- package/dist-server/index.js.map +0 -1
- package/dist-server/role-tasks.js.map +0 -1
- package/dist-server/service/ai-agent-resolver.js.map +0 -1
- package/dist-server/service/assistant-capability-resolver.js.map +0 -1
- package/dist-server/service/assistant-chat-resolver.js.map +0 -1
- package/dist-server/service/assistant-mode/assistant-mode-resolver.js.map +0 -1
- package/dist-server/service/assistant-mode/fallback-subjects.js.map +0 -1
- package/dist-server/service/assistant-mode/index.js.map +0 -1
- package/dist-server/service/assistant-mode/mode-categories.js.map +0 -1
- package/dist-server/service/assistant-mode/record-subject.js.map +0 -1
- package/dist-server/service/assistant-mode/registry.js.map +0 -1
- package/dist-server/service/assistant-mode/resolve.js.map +0 -1
- package/dist-server/service/assistant-mode/screen-rules.js.map +0 -1
- package/dist-server/service/assistant-mode/turn-lines.js.map +0 -1
- package/dist-server/service/assistant-mode/types.js.map +0 -1
- package/dist-server/service/chat-message/carried-turns.js.map +0 -1
- package/dist-server/service/chat-message/chat-message-broadcast.js.map +0 -1
- package/dist-server/service/chat-message/chat-message-publish.js.map +0 -1
- package/dist-server/service/chat-message/chat-message-room.js.map +0 -1
- package/dist-server/service/chat-message/chat-message-subscription.js.map +0 -1
- package/dist-server/service/chat-message/chat-message.js.map +0 -1
- package/dist-server/service/chat-message/chat-typing-subscription.js.map +0 -1
- package/dist-server/service/chat-message/chat-typing.js.map +0 -1
- package/dist-server/service/chat-message/door-access.js.map +0 -1
- package/dist-server/service/chat-message/fold-history.js.map +0 -1
- package/dist-server/service/chat-message/fold-session-history.js.map +0 -1
- package/dist-server/service/chat-message/history-summary.js.map +0 -1
- package/dist-server/service/chat-message/index.js.map +0 -1
- package/dist-server/service/chat-message/llm-history.js.map +0 -1
- package/dist-server/service/chat-message/message-doors.js.map +0 -1
- package/dist-server/service/chat-message/proposal-outcome.js.map +0 -1
- package/dist-server/service/chat-message/reader-gate.js.map +0 -1
- package/dist-server/service/chat-message/room-message.js.map +0 -1
- package/dist-server/service/chat-message/room-turn.js.map +0 -1
- package/dist-server/service/chat-message/used-tools.js.map +0 -1
- package/dist-server/service/chat-session/attachment-policy.js.map +0 -1
- package/dist-server/service/chat-session/attachment-route.js.map +0 -1
- package/dist-server/service/chat-session/attachment-tool-result.js.map +0 -1
- package/dist-server/service/chat-session/attachment-tools.js.map +0 -1
- package/dist-server/service/chat-session/chat-session.js.map +0 -1
- package/dist-server/service/chat-session/index.js.map +0 -1
- package/dist-server/service/chat-session/session-activity-broadcast.js.map +0 -1
- package/dist-server/service/chat-session/session-activity-publish.js.map +0 -1
- package/dist-server/service/chat-session/session-activity-subscription.js.map +0 -1
- package/dist-server/service/chat-session/session-anchor.js.map +0 -1
- package/dist-server/service/chat-session/session-attachments.js.map +0 -1
- package/dist-server/service/chat-session/session-cleanup.js.map +0 -1
- package/dist-server/service/chat-session/session-inbox.js.map +0 -1
- package/dist-server/service/chat-session/session-kind.js.map +0 -1
- package/dist-server/service/chat-session/session-name.js.map +0 -1
- package/dist-server/service/chat-session/session-purge.js.map +0 -1
- package/dist-server/service/chat-session/session-retention.js.map +0 -1
- package/dist-server/service/chat-session/session-visibility.js.map +0 -1
- package/dist-server/service/chat-session/session-write-gate.js.map +0 -1
- package/dist-server/service/chat-session/station-session-guard.js.map +0 -1
- package/dist-server/service/chat-session/turn-attachments.js.map +0 -1
- package/dist-server/service/chat-session-participant/chat-session-participant.js.map +0 -1
- package/dist-server/service/chat-session-participant/index.js.map +0 -1
- package/dist-server/service/chat-session-participant/invite-notification.js.map +0 -1
- package/dist-server/service/chat-session-participant/mention-invite.js.map +0 -1
- package/dist-server/service/chat-session-participant/participant-lookup-roles.js.map +0 -1
- package/dist-server/service/chat-session-participant/participant-lookup.js.map +0 -1
- package/dist-server/service/chat-session-participant/presence.js.map +0 -1
- package/dist-server/service/chat-session-participant/read-roster.js.map +0 -1
- package/dist-server/service/chat-session-resolver.js.map +0 -1
- package/dist-server/service/data-entry/entry-apply.js.map +0 -1
- package/dist-server/service/data-entry/entry-hash.js.map +0 -1
- package/dist-server/service/data-entry/entry-refusal.js.map +0 -1
- package/dist-server/service/data-entry/entry-resolver.js.map +0 -1
- package/dist-server/service/data-entry/entry-screen.js.map +0 -1
- package/dist-server/service/data-entry/entry-sources.js.map +0 -1
- package/dist-server/service/data-entry/entry-target.js.map +0 -1
- package/dist-server/service/data-entry/entry-tools.js.map +0 -1
- package/dist-server/service/data-entry/entry-update.js.map +0 -1
- package/dist-server/service/data-read/list-read.js.map +0 -1
- package/dist-server/service/data-read/read-target.js.map +0 -1
- package/dist-server/service/data-read/read-tools.js.map +0 -1
- package/dist-server/service/grounding-sources.js.map +0 -1
- package/dist-server/service/help-documents/help-keys.js.map +0 -1
- package/dist-server/service/help-documents/help-tools.js.map +0 -1
- package/dist-server/service/index.js.map +0 -1
- package/dist-server/service/people/index.js.map +0 -1
- package/dist-server/service/people/invite-tools.js.map +0 -1
- package/dist-server/service/people/people-keys.js.map +0 -1
- package/dist-server/service/people/people-read.js.map +0 -1
- package/dist-server/service/people/person-subject.js.map +0 -1
- package/dist-server/service/request-translator.js.map +0 -1
- package/dist-server/service/testing/conversation-script.js.map +0 -1
- package/dist-server/service/testing/mode-conformance.js.map +0 -1
- package/dist-server/service/tool-access.js.map +0 -1
- package/dist-server/service/types.js.map +0 -1
- package/dist-server/service/unattended-run/assistant-run.js.map +0 -1
- package/dist-server/service/unattended-run/index.js.map +0 -1
- package/dist-server/service/unattended-run/limits.js.map +0 -1
- package/dist-server/service/unattended-run/run-as.js.map +0 -1
- package/dist-server/service/unattended-run/run-budget.js.map +0 -1
- package/dist-server/service/unattended-run/run-ledger.js.map +0 -1
- package/dist-server/service/unattended-run/run-outcome.js.map +0 -1
- package/dist-server/service/unattended-run/run-store.js.map +0 -1
- package/dist-server/service/unattended-run/run-unattended.js.map +0 -1
- package/dist-server/service/unattended-run/unattended-prompt.js.map +0 -1
- package/dist-server/service/workspace/workspace-blocks.js.map +0 -1
- package/dist-server/service/workspace/workspace-tools.js.map +0 -1
- package/dist-server/tool-registry-boot-report.js.map +0 -1
- package/dist-server/tsconfig.tsbuildinfo +0 -1
- package/docs/session-controller.md +0 -52
- package/server/door-declaration-report.test.ts +0 -53
- package/server/door-declaration-report.ts +0 -61
- package/server/explicit-graphql-types.test.ts +0 -56
- package/server/index.ts +0 -36
- package/server/role-tasks.ts +0 -14
- package/server/service/ai-agent-resolver.ts +0 -330
- package/server/service/assistant-capability-resolver.ts +0 -66
- package/server/service/assistant-chat-resolver.ts +0 -640
- package/server/service/assistant-mode/assistant-mode-resolver.ts +0 -101
- package/server/service/assistant-mode/conversation-category.test.ts +0 -48
- package/server/service/assistant-mode/fallback-subjects.ts +0 -36
- package/server/service/assistant-mode/index.ts +0 -22
- package/server/service/assistant-mode/mode-categories.ts +0 -178
- package/server/service/assistant-mode/mode-front.test.ts +0 -183
- package/server/service/assistant-mode/one-conversation-per-subject.test.ts +0 -37
- package/server/service/assistant-mode/open-subject-door.test.ts +0 -52
- package/server/service/assistant-mode/record-subject.test.ts +0 -41
- package/server/service/assistant-mode/record-subject.ts +0 -44
- package/server/service/assistant-mode/registry.test.ts +0 -171
- package/server/service/assistant-mode/registry.ts +0 -139
- package/server/service/assistant-mode/resolve.test.ts +0 -129
- package/server/service/assistant-mode/resolve.ts +0 -113
- package/server/service/assistant-mode/screen-rules.test.ts +0 -99
- package/server/service/assistant-mode/screen-rules.ts +0 -103
- package/server/service/assistant-mode/turn-lines.ts +0 -43
- package/server/service/assistant-mode/types.ts +0 -138
- package/server/service/chat-message/carried-turns.test.ts +0 -80
- package/server/service/chat-message/carried-turns.ts +0 -112
- package/server/service/chat-message/chat-message-broadcast.integration.test.ts +0 -73
- package/server/service/chat-message/chat-message-broadcast.test.ts +0 -40
- package/server/service/chat-message/chat-message-broadcast.ts +0 -70
- package/server/service/chat-message/chat-message-publish.ts +0 -22
- package/server/service/chat-message/chat-message-room.test.ts +0 -145
- package/server/service/chat-message/chat-message-room.ts +0 -50
- package/server/service/chat-message/chat-message-subscription.ts +0 -77
- package/server/service/chat-message/chat-message.ts +0 -289
- package/server/service/chat-message/chat-typing-subscription.ts +0 -52
- package/server/service/chat-message/chat-typing.test.ts +0 -45
- package/server/service/chat-message/chat-typing.ts +0 -48
- package/server/service/chat-message/door-access.test.ts +0 -72
- package/server/service/chat-message/door-access.ts +0 -65
- package/server/service/chat-message/fold-history-window.test.ts +0 -184
- package/server/service/chat-message/fold-history.test.ts +0 -98
- package/server/service/chat-message/fold-history.ts +0 -77
- package/server/service/chat-message/fold-session-history.test.ts +0 -116
- package/server/service/chat-message/fold-session-history.ts +0 -115
- package/server/service/chat-message/history-summary.test.ts +0 -127
- package/server/service/chat-message/history-summary.ts +0 -100
- package/server/service/chat-message/index.ts +0 -13
- package/server/service/chat-message/llm-history.test.ts +0 -245
- package/server/service/chat-message/llm-history.ts +0 -182
- package/server/service/chat-message/message-doors.test.ts +0 -124
- package/server/service/chat-message/message-doors.ts +0 -132
- package/server/service/chat-message/proposal-outcome.test.ts +0 -111
- package/server/service/chat-message/proposal-outcome.ts +0 -99
- package/server/service/chat-message/reader-gate.ts +0 -44
- package/server/service/chat-message/room-message.test.ts +0 -21
- package/server/service/chat-message/room-message.ts +0 -22
- package/server/service/chat-message/room-turn.ts +0 -42
- package/server/service/chat-message/used-tools.test.ts +0 -19
- package/server/service/chat-message/used-tools.ts +0 -25
- package/server/service/chat-session/attachment-policy.test.ts +0 -42
- package/server/service/chat-session/attachment-policy.ts +0 -91
- package/server/service/chat-session/attachment-route.ts +0 -45
- package/server/service/chat-session/attachment-tool-result.test.ts +0 -63
- package/server/service/chat-session/attachment-tool-result.ts +0 -37
- package/server/service/chat-session/attachment-tools.ts +0 -66
- package/server/service/chat-session/chat-session.ts +0 -244
- package/server/service/chat-session/group-room.test.ts +0 -233
- package/server/service/chat-session/index.ts +0 -5
- package/server/service/chat-session/session-activity-broadcast.ts +0 -77
- package/server/service/chat-session/session-activity-publish.ts +0 -49
- package/server/service/chat-session/session-activity-receivers.test.ts +0 -26
- package/server/service/chat-session/session-activity-subscription.ts +0 -66
- package/server/service/chat-session/session-anchor.ts +0 -142
- package/server/service/chat-session/session-attachments.ts +0 -90
- package/server/service/chat-session/session-cleanup.test.ts +0 -83
- package/server/service/chat-session/session-cleanup.ts +0 -69
- package/server/service/chat-session/session-inbox.test.ts +0 -273
- package/server/service/chat-session/session-inbox.ts +0 -240
- package/server/service/chat-session/session-kind.test.ts +0 -24
- package/server/service/chat-session/session-kind.ts +0 -32
- package/server/service/chat-session/session-name.ts +0 -32
- package/server/service/chat-session/session-purge.test.ts +0 -24
- package/server/service/chat-session/session-purge.ts +0 -117
- package/server/service/chat-session/session-retention.ts +0 -17
- package/server/service/chat-session/session-visibility.test.ts +0 -130
- package/server/service/chat-session/session-visibility.ts +0 -68
- package/server/service/chat-session/session-write-gate.test.ts +0 -59
- package/server/service/chat-session/session-write-gate.ts +0 -31
- package/server/service/chat-session/station-session-guard.ts +0 -25
- package/server/service/chat-session/turn-attachments.test.ts +0 -106
- package/server/service/chat-session/turn-attachments.ts +0 -45
- package/server/service/chat-session-participant/chat-session-participant.ts +0 -135
- package/server/service/chat-session-participant/index.ts +0 -8
- package/server/service/chat-session-participant/invite-notification.test.ts +0 -80
- package/server/service/chat-session-participant/invite-notification.ts +0 -118
- package/server/service/chat-session-participant/mention-invite.test.ts +0 -173
- package/server/service/chat-session-participant/mention-invite.ts +0 -180
- package/server/service/chat-session-participant/participant-lookup-roles.ts +0 -6
- package/server/service/chat-session-participant/participant-lookup.ts +0 -22
- package/server/service/chat-session-participant/presence.test.ts +0 -39
- package/server/service/chat-session-participant/presence.ts +0 -21
- package/server/service/chat-session-participant/read-roster.test.ts +0 -27
- package/server/service/chat-session-participant/read-roster.ts +0 -17
- package/server/service/chat-session-resolver.ts +0 -1455
- package/server/service/data-entry/data-entry-update.test.ts +0 -378
- package/server/service/data-entry/data-entry.test.ts +0 -494
- package/server/service/data-entry/entry-apply.ts +0 -247
- package/server/service/data-entry/entry-hash.ts +0 -35
- package/server/service/data-entry/entry-refusal.test.ts +0 -73
- package/server/service/data-entry/entry-refusal.ts +0 -20
- package/server/service/data-entry/entry-resolver.ts +0 -74
- package/server/service/data-entry/entry-screen.ts +0 -14
- package/server/service/data-entry/entry-sources.ts +0 -39
- package/server/service/data-entry/entry-target.ts +0 -774
- package/server/service/data-entry/entry-tools.ts +0 -282
- package/server/service/data-entry/entry-update.ts +0 -238
- package/server/service/data-read/data-read.test.ts +0 -395
- package/server/service/data-read/detail-lists.test.ts +0 -61
- package/server/service/data-read/list-missing.test.ts +0 -49
- package/server/service/data-read/list-read.ts +0 -146
- package/server/service/data-read/list-status.test.ts +0 -46
- package/server/service/data-read/read-target.ts +0 -509
- package/server/service/data-read/read-tools.ts +0 -334
- package/server/service/data-read/read-words.test.ts +0 -99
- package/server/service/data-read/record-keys.test.ts +0 -42
- package/server/service/grounding-sources.test.ts +0 -55
- package/server/service/grounding-sources.ts +0 -46
- package/server/service/help-documents/help-keys.ts +0 -2
- package/server/service/help-documents/help-tools.test.ts +0 -40
- package/server/service/help-documents/help-tools.ts +0 -88
- package/server/service/index.ts +0 -99
- package/server/service/people/index.ts +0 -15
- package/server/service/people/invite-tools.ts +0 -159
- package/server/service/people/invite.test.ts +0 -159
- package/server/service/people/people-keys.ts +0 -16
- package/server/service/people/people-read.test.ts +0 -82
- package/server/service/people/people-read.ts +0 -56
- package/server/service/people/person-subject.test.ts +0 -161
- package/server/service/people/person-subject.ts +0 -83
- package/server/service/request-translator.test.ts +0 -45
- package/server/service/request-translator.ts +0 -33
- package/server/service/session-anchor.test.ts +0 -198
- package/server/service/station-session-guard.test.ts +0 -31
- package/server/service/testing/conversation-scenario.test.ts +0 -164
- package/server/service/testing/conversation-script.test.ts +0 -133
- package/server/service/testing/conversation-script.ts +0 -296
- package/server/service/testing/mode-conformance.test.ts +0 -61
- package/server/service/testing/mode-conformance.ts +0 -165
- package/server/service/tool-access.test.ts +0 -96
- package/server/service/tool-access.ts +0 -36
- package/server/service/types.ts +0 -15
- package/server/service/unattended-run/assistant-run.ts +0 -199
- package/server/service/unattended-run/index.ts +0 -10
- package/server/service/unattended-run/limits.ts +0 -24
- package/server/service/unattended-run/run-as.ts +0 -38
- package/server/service/unattended-run/run-budget.ts +0 -58
- package/server/service/unattended-run/run-ledger.ts +0 -31
- package/server/service/unattended-run/run-outcome.ts +0 -43
- package/server/service/unattended-run/run-store-race.pg.test.ts +0 -83
- package/server/service/unattended-run/run-store.ts +0 -162
- package/server/service/unattended-run/run-unattended.test.ts +0 -478
- package/server/service/unattended-run/run-unattended.ts +0 -248
- package/server/service/unattended-run/unattended-prompt.ts +0 -24
- package/server/service/workspace/workspace-blocks.ts +0 -134
- package/server/service/workspace/workspace-tools.ts +0 -108
- package/server/service/workspace/workspace.test.ts +0 -74
- package/server/tool-registry-boot-report.test.ts +0 -41
- package/server/tool-registry-boot-report.ts +0 -63
- package/test/ai-agent-settings.test.ts +0 -123
- package/test/applied-screens.test.ts +0 -65
- package/test/assistant-chat-call-sites.test.ts +0 -92
- package/test/assistant-dock.test.ts +0 -294
- package/test/assistant-request-context.test.ts +0 -72
- package/test/assistant-session-controller.test.ts +0 -87
- package/test/assistant-session-manager.test.ts +0 -186
- package/test/assistant-session-toolbar.test.ts +0 -43
- package/test/attachment-one-rule.test.ts +0 -46
- package/test/attachment-policy-agree.test.ts +0 -38
- package/test/composer-frame.test.ts +0 -173
- package/test/document-text.test.ts +0 -175
- package/test/entry-card-styles.test.ts +0 -18
- package/test/entry-proposal.test.ts +0 -186
- package/test/entry-workspace.test.ts +0 -89
- package/test/menu-room.test.ts +0 -33
- package/test/open-doors.test.ts +0 -164
- package/test/open-page.test.ts +0 -31
- package/test/pasted-table.test.ts +0 -147
- package/test/refusals-in-korean.test.ts +0 -80
- package/test/session-discovery.test.ts +0 -43
- package/test/spreadsheet-text.test.ts +0 -92
- package/test/translations.test.ts +0 -80
- package/test/workspace.test.ts +0 -54
- package/tsconfig.json +0 -9
|
@@ -1,332 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* A document read into text the conversation can carry (design/ai/shared-dock.md §9-6) - PDF, Word (.docx) and
|
|
3
|
-
* PowerPoint (.pptx), as a spreadsheet is (spreadsheet-text.ts): the door takes images and text only, so a mode that
|
|
4
|
-
* opens 'document' has the screen read the file before sending (2026-10-28, the user: 「pdf, word, ppt 파일은 처리할
|
|
5
|
-
* 수 없는가?」).
|
|
6
|
-
*
|
|
7
|
-
* - Every page and slide is marked with its own number, so an answer can say "page 3" or "slide 5" and be checked.
|
|
8
|
-
* - A PDF page with no text on it is a scan: it is drawn into an image and sent beside the text, named by its page.
|
|
9
|
-
* - The old binary .doc and .ppt are refused by name, as .xls is - nothing here opens them.
|
|
10
|
-
* - The limit is on the text after reading. A document over it is refused, never cut: a cut contract is read as the
|
|
11
|
-
* whole contract.
|
|
12
|
-
* - Word keeps no pages (they are laid out when printed), so a .docx is read in order with its headings marked.
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
|
-
export type DocumentKind = 'pdf' | 'docx' | 'pptx' | 'doc' | 'ppt'
|
|
16
|
-
|
|
17
|
-
const PDF_TYPE = 'application/pdf'
|
|
18
|
-
const DOCX_TYPE = 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'
|
|
19
|
-
const PPTX_TYPE = 'application/vnd.openxmlformats-officedocument.presentationml.presentation'
|
|
20
|
-
const DOC_TYPE = 'application/msword'
|
|
21
|
-
const PPT_TYPE = 'application/vnd.ms-powerpoint'
|
|
22
|
-
|
|
23
|
-
/** The picker's `accept` for documents. */
|
|
24
|
-
export const DOCUMENT_ACCEPT = ['.pdf', PDF_TYPE, '.docx', DOCX_TYPE, '.pptx', PPTX_TYPE]
|
|
25
|
-
|
|
26
|
-
/** A document by its type, or by its name when the browser did not know the type. */
|
|
27
|
-
export function documentKindOf(file: { type?: string; name?: string }): DocumentKind | null {
|
|
28
|
-
const type = (file.type || '').toLowerCase()
|
|
29
|
-
const name = (file.name || '').toLowerCase()
|
|
30
|
-
if (type === PDF_TYPE || name.endsWith('.pdf')) return 'pdf'
|
|
31
|
-
if (type === DOCX_TYPE || name.endsWith('.docx')) return 'docx'
|
|
32
|
-
if (type === PPTX_TYPE || name.endsWith('.pptx')) return 'pptx'
|
|
33
|
-
if (type === DOC_TYPE || name.endsWith('.doc')) return 'doc'
|
|
34
|
-
if (type === PPT_TYPE || name.endsWith('.ppt')) return 'ppt'
|
|
35
|
-
return null
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export type DocumentRefusal =
|
|
39
|
-
| { code: 'attachment-old-office-not-read'; name: string }
|
|
40
|
-
| { code: 'attachment-document-unreadable'; name: string }
|
|
41
|
-
| { code: 'attachment-document-empty'; name: string }
|
|
42
|
-
| { code: 'attachment-document-too-long'; name: string; maxChars: number }
|
|
43
|
-
| { code: 'attachment-scan-needs-images'; name: string }
|
|
44
|
-
| { code: 'attachment-scan-too-many-pages'; name: string; pages: number; max: number }
|
|
45
|
-
|
|
46
|
-
/** What a document becomes: one text file, and the scanned pages of a PDF as images. */
|
|
47
|
-
export interface DocumentFiles {
|
|
48
|
-
text: { name: string; text: string }
|
|
49
|
-
images: { name: string; page: number; blob: Blob }[]
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
/** The file name the text travels under - "계약서.pdf" → "계약서.pdf.txt", so the source stays readable. */
|
|
53
|
-
export const documentTextName = (fileName: string) => `${fileName}.txt`
|
|
54
|
-
|
|
55
|
-
/** The file name a scanned page travels under - "계약서.pdf" page 3 → "계약서.pdf - p3.jpg". */
|
|
56
|
-
export const scannedPageName = (fileName: string, page: number) => `${fileName} - p${page}.jpg`
|
|
57
|
-
|
|
58
|
-
/* ── OOXML, read without a DOM: a small pull reader over the tags the text lives in ─────────────────────────── */
|
|
59
|
-
|
|
60
|
-
export interface XmlToken {
|
|
61
|
-
kind: 'open' | 'close' | 'empty' | 'text'
|
|
62
|
-
name?: string
|
|
63
|
-
attrs?: string
|
|
64
|
-
text?: string
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
const ENTITIES: Record<string, string> = { amp: '&', lt: '<', gt: '>', quot: '"', apos: "'" }
|
|
68
|
-
|
|
69
|
-
export function xmlDecode(text: string): string {
|
|
70
|
-
return text.replace(/&(#x[0-9a-f]+|#\d+|[a-z]+);/gi, (whole, code: string) => {
|
|
71
|
-
if (code[0] === '#') {
|
|
72
|
-
const n = code[1] === 'x' || code[1] === 'X' ? parseInt(code.slice(2), 16) : parseInt(code.slice(1), 10)
|
|
73
|
-
return Number.isFinite(n) ? String.fromCodePoint(n) : whole
|
|
74
|
-
}
|
|
75
|
-
return ENTITIES[code.toLowerCase()] ?? whole
|
|
76
|
-
})
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
/** Tags and text in document order. Comments, declarations and processing instructions are skipped. */
|
|
80
|
-
export function* xmlTokens(xml: string): Generator<XmlToken> {
|
|
81
|
-
const pattern = /<!--[\s\S]*?-->|<\?[\s\S]*?\?>|<!\[CDATA\[([\s\S]*?)\]\]>|<!(?:[^>]*)>|<(\/?)([\w:.-]+)([^>]*?)(\/?)>|([^<]+)/g
|
|
82
|
-
for (const match of xml.matchAll(pattern)) {
|
|
83
|
-
const [, cdata, slash, name, attrs, selfClose, text] = match
|
|
84
|
-
if (cdata !== undefined) yield { kind: 'text', text: cdata }
|
|
85
|
-
else if (name) yield { kind: slash ? 'close' : selfClose ? 'empty' : 'open', name, attrs }
|
|
86
|
-
else if (text !== undefined) yield { kind: 'text', text: xmlDecode(text) }
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
const attrOf = (attrs: string | undefined, name: string) => new RegExp(`\\b${name}="([^"]*)"`).exec(attrs ?? '')?.[1]
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* A Word body as text: paragraphs in order, a heading led by "#" for its level, a table as one line per row with its
|
|
94
|
-
* cells between " | ". Text inside a table cell is joined with spaces, so a row stays one line.
|
|
95
|
-
*/
|
|
96
|
-
export function docxText(xml: string): string {
|
|
97
|
-
const lines: string[] = []
|
|
98
|
-
let paragraph = ''
|
|
99
|
-
let heading = 0
|
|
100
|
-
let inText = false
|
|
101
|
-
let tableDepth = 0
|
|
102
|
-
let row: string[] | null = null
|
|
103
|
-
let cell: string[] | null = null
|
|
104
|
-
|
|
105
|
-
for (const token of xmlTokens(xml)) {
|
|
106
|
-
const name = token.name
|
|
107
|
-
if (token.kind === 'text') {
|
|
108
|
-
if (inText) paragraph += token.text
|
|
109
|
-
continue
|
|
110
|
-
}
|
|
111
|
-
if (name === 'w:t') inText = token.kind === 'open'
|
|
112
|
-
else if (name === 'w:tab' && token.kind !== 'close') paragraph += '\t'
|
|
113
|
-
else if ((name === 'w:br' || name === 'w:cr') && token.kind !== 'close') paragraph += '\n'
|
|
114
|
-
else if (name === 'w:pStyle') {
|
|
115
|
-
const level = /^heading\s*(\d)$/i.exec(attrOf(token.attrs, 'w:val') ?? '')?.[1] ?? (/^title$/i.test(attrOf(token.attrs, 'w:val') ?? '') ? '1' : '')
|
|
116
|
-
heading = level ? Number(level) : 0
|
|
117
|
-
} else if (name === 'w:p' && token.kind === 'open') {
|
|
118
|
-
paragraph = ''
|
|
119
|
-
heading = 0
|
|
120
|
-
} else if (name === 'w:p' && token.kind !== 'open') {
|
|
121
|
-
const text = paragraph.replace(/[ ]+$/g, '')
|
|
122
|
-
if (cell) cell.push(text.trim())
|
|
123
|
-
else if (text.trim()) lines.push(heading ? `${'#'.repeat(heading)} ${text.trim()}` : text)
|
|
124
|
-
paragraph = ''
|
|
125
|
-
} else if (name === 'w:tbl') {
|
|
126
|
-
tableDepth += token.kind === 'open' ? 1 : token.kind === 'close' ? -1 : 0
|
|
127
|
-
} else if (name === 'w:tr' && tableDepth === 1) {
|
|
128
|
-
if (token.kind === 'open') row = []
|
|
129
|
-
else if (row) {
|
|
130
|
-
if (row.some(one => one)) lines.push(`| ${row.join(' | ')} |`)
|
|
131
|
-
row = null
|
|
132
|
-
}
|
|
133
|
-
} else if (name === 'w:tc' && tableDepth === 1) {
|
|
134
|
-
if (token.kind === 'open') cell = []
|
|
135
|
-
else if (cell) {
|
|
136
|
-
row?.push(cell.filter(Boolean).join(' '))
|
|
137
|
-
cell = null
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
return lines.join('\n')
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
/* What a slide or its notes repeat on every page - its number, date, footer, header - is not its content. */
|
|
145
|
-
const REPEATED_PLACEHOLDERS = ['sldNum', 'dt', 'ftr', 'hdr']
|
|
146
|
-
|
|
147
|
-
/** The text of one slide or notes part: each paragraph on its own line, the repeated placeholders left out. */
|
|
148
|
-
export function drawingText(xml: string): string[] {
|
|
149
|
-
const lines: string[] = []
|
|
150
|
-
let paragraph = ''
|
|
151
|
-
let inText = false
|
|
152
|
-
let repeated = false
|
|
153
|
-
for (const token of xmlTokens(xml)) {
|
|
154
|
-
if (token.kind === 'text') {
|
|
155
|
-
if (inText) paragraph += token.text
|
|
156
|
-
continue
|
|
157
|
-
}
|
|
158
|
-
if (token.name === 'p:sp' && token.kind === 'open') repeated = false
|
|
159
|
-
else if (token.name === 'p:ph' && token.kind !== 'close') repeated = REPEATED_PLACEHOLDERS.includes(attrOf(token.attrs, 'type') ?? '')
|
|
160
|
-
else if (token.name === 'a:t') inText = token.kind === 'open'
|
|
161
|
-
else if (token.name === 'a:br' && token.kind !== 'close') paragraph += '\n'
|
|
162
|
-
else if (token.name === 'a:p' && token.kind !== 'open') {
|
|
163
|
-
if (paragraph.trim() && !repeated) lines.push(paragraph.trim())
|
|
164
|
-
paragraph = ''
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
return lines
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
/** The slides in the order the presentation shows them - its slide list read through its relationships. */
|
|
171
|
-
export function slideOrder(presentationXml: string, relsXml: string): string[] {
|
|
172
|
-
const targets = new Map<string, string>()
|
|
173
|
-
for (const token of xmlTokens(relsXml)) {
|
|
174
|
-
if (token.name !== 'Relationship') continue
|
|
175
|
-
const id = attrOf(token.attrs, 'Id')
|
|
176
|
-
const target = attrOf(token.attrs, 'Target')
|
|
177
|
-
if (id && target) targets.set(id, target.replace(/^\/?ppt\//, '').replace(/^\.\//, ''))
|
|
178
|
-
}
|
|
179
|
-
const order: string[] = []
|
|
180
|
-
for (const token of xmlTokens(presentationXml)) {
|
|
181
|
-
if (token.name !== 'p:sldId') continue
|
|
182
|
-
const target = targets.get(attrOf(token.attrs, 'r:id') ?? '')
|
|
183
|
-
if (target) order.push(`ppt/${target}`)
|
|
184
|
-
}
|
|
185
|
-
return order
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
/** The notes part a slide points at, if it has one. */
|
|
189
|
-
export function notesTarget(slidePath: string, slideRelsXml: string): string | null {
|
|
190
|
-
for (const token of xmlTokens(slideRelsXml)) {
|
|
191
|
-
if (token.name !== 'Relationship' || !/notesSlide$/.test(attrOf(token.attrs, 'Type') ?? '')) continue
|
|
192
|
-
const target = attrOf(token.attrs, 'Target')
|
|
193
|
-
if (!target) continue
|
|
194
|
-
const base = slidePath.split('/').slice(0, -1)
|
|
195
|
-
for (const part of target.split('/')) {
|
|
196
|
-
if (part === '..') base.pop()
|
|
197
|
-
else if (part !== '.') base.push(part)
|
|
198
|
-
}
|
|
199
|
-
return base.join('/')
|
|
200
|
-
}
|
|
201
|
-
return null
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
/** One slide as text: its paragraphs, then its speaker notes. */
|
|
205
|
-
export function slideText(number: number, slide: string[], notes: string[]): string {
|
|
206
|
-
return [`--- slide ${number} ---`, ...slide, ...(notes.length ? ['notes:', ...notes] : [])].join('\n')
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
/** One PDF page's text items as lines - pdf.js marks the end of a line on the item that ends it. */
|
|
210
|
-
export function pdfPageText(items: { str?: string; hasEOL?: boolean }[]): string {
|
|
211
|
-
let text = ''
|
|
212
|
-
for (const item of items) {
|
|
213
|
-
text += item.str ?? ''
|
|
214
|
-
if (item.hasEOL) text += '\n'
|
|
215
|
-
}
|
|
216
|
-
return text
|
|
217
|
-
.split('\n')
|
|
218
|
-
.map(line => line.replace(/[ \t]+/g, ' ').trim())
|
|
219
|
-
.filter(Boolean)
|
|
220
|
-
.join('\n')
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
/** A page with fewer letters than this is a scan - its text is a page number or a stray mark, not its content. */
|
|
224
|
-
export const SCANNED_PAGE_LETTERS = 16
|
|
225
|
-
|
|
226
|
-
export const isScannedPage = (text: string) => text.replace(/\s/g, '').length < SCANNED_PAGE_LETTERS
|
|
227
|
-
|
|
228
|
-
/** The header line of a document's text - what it was and how it is marked. */
|
|
229
|
-
export function documentHeader(fileName: string, kind: 'pdf' | 'docx' | 'pptx', count?: number): string {
|
|
230
|
-
const many = (word: string) => `${count} ${word}${count === 1 ? '' : 's'}`
|
|
231
|
-
if (kind === 'pdf') return `# ${fileName} · PDF · ${many('page')} · each page begins with "--- page N ---", N its own page number`
|
|
232
|
-
if (kind === 'pptx') return `# ${fileName} · PowerPoint · ${many('slide')} · each slide begins with "--- slide N ---", its notes after "notes:"`
|
|
233
|
-
return `# ${fileName} · Word · read in order, headings led by "#", table rows between "|"`
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
/** A finished text checked against the limit and for emptiness - the same three answers for every kind. */
|
|
237
|
-
function settle(fileName: string, text: string, body: string, maxChars: number, images: DocumentFiles['images'] = []): { files: DocumentFiles } | { refusal: DocumentRefusal } {
|
|
238
|
-
if (!body.trim() && !images.length) return { refusal: { code: 'attachment-document-empty', name: fileName } }
|
|
239
|
-
if (text.length > maxChars) return { refusal: { code: 'attachment-document-too-long', name: fileName, maxChars } }
|
|
240
|
-
return { files: { text: { name: documentTextName(fileName), text }, images } }
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
/** What reads a zip - JSZip, passed in so the screen loads it only when a document is attached. */
|
|
244
|
-
export interface ZipReader {
|
|
245
|
-
loadAsync(data: ArrayBuffer | Uint8Array): Promise<{ file(path: string): { async(type: 'string'): Promise<string> } | null }>
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
export async function readDocx(data: ArrayBuffer | Uint8Array, fileName: string, maxChars: number, zip: ZipReader) {
|
|
249
|
-
let body: string
|
|
250
|
-
try {
|
|
251
|
-
const archive = await zip.loadAsync(data)
|
|
252
|
-
const part = archive.file('word/document.xml')
|
|
253
|
-
if (!part) return { refusal: { code: 'attachment-document-unreadable', name: fileName } as DocumentRefusal }
|
|
254
|
-
body = docxText(await part.async('string'))
|
|
255
|
-
} catch {
|
|
256
|
-
return { refusal: { code: 'attachment-document-unreadable', name: fileName } as DocumentRefusal }
|
|
257
|
-
}
|
|
258
|
-
return settle(fileName, `${documentHeader(fileName, 'docx')}\n${body}\n`, body, maxChars)
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
export async function readPptx(data: ArrayBuffer | Uint8Array, fileName: string, maxChars: number, zip: ZipReader) {
|
|
262
|
-
const slides: string[] = []
|
|
263
|
-
try {
|
|
264
|
-
const archive = await zip.loadAsync(data)
|
|
265
|
-
const read = async (path: string) => (await archive.file(path)?.async('string')) ?? null
|
|
266
|
-
const presentation = await read('ppt/presentation.xml')
|
|
267
|
-
const rels = await read('ppt/_rels/presentation.xml.rels')
|
|
268
|
-
if (!presentation || !rels) return { refusal: { code: 'attachment-document-unreadable', name: fileName } as DocumentRefusal }
|
|
269
|
-
const order = slideOrder(presentation, rels)
|
|
270
|
-
for (const [index, path] of order.entries()) {
|
|
271
|
-
const slide = await read(path)
|
|
272
|
-
if (slide === null) continue
|
|
273
|
-
const slideRels = await read(path.replace(/slides\/(slide\d+\.xml)$/, 'slides/_rels/$1.rels'))
|
|
274
|
-
const notesPath = slideRels ? notesTarget(path, slideRels) : null
|
|
275
|
-
const notes = notesPath ? await read(notesPath) : null
|
|
276
|
-
slides.push(slideText(index + 1, drawingText(slide), notes ? drawingText(notes) : []))
|
|
277
|
-
}
|
|
278
|
-
} catch {
|
|
279
|
-
return { refusal: { code: 'attachment-document-unreadable', name: fileName } as DocumentRefusal }
|
|
280
|
-
}
|
|
281
|
-
const body = slides.join('\n')
|
|
282
|
-
const said = slides.some(slide => slide.split('\n').length > 1)
|
|
283
|
-
return settle(fileName, `${documentHeader(fileName, 'pptx', slides.length)}\n${body}\n`, said ? body : '', maxChars)
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
/** What reads a PDF - pdf.js's document, narrowed to what is used, so a test can hand in pages. */
|
|
287
|
-
export interface PdfSource {
|
|
288
|
-
numPages: number
|
|
289
|
-
getPage(number: number): Promise<{ getTextContent(): Promise<{ items: any[] }> }>
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
/**
|
|
293
|
-
* Every page of a PDF as text, its scanned pages drawn as images by `drawPage` (the screen's canvas). A scan cannot be
|
|
294
|
-
* read unless the mode takes images, and no more scanned pages are drawn than the message may carry - both refused by
|
|
295
|
-
* name, never dropped.
|
|
296
|
-
*/
|
|
297
|
-
export async function readPdf(
|
|
298
|
-
open: () => Promise<PdfSource>,
|
|
299
|
-
fileName: string,
|
|
300
|
-
maxChars: number,
|
|
301
|
-
scans: { allowed: boolean; max: number },
|
|
302
|
-
drawPage: (number: number) => Promise<Blob>
|
|
303
|
-
): Promise<{ files: DocumentFiles } | { refusal: DocumentRefusal }> {
|
|
304
|
-
const pages: string[] = []
|
|
305
|
-
const scanned: number[] = []
|
|
306
|
-
let count = 0
|
|
307
|
-
try {
|
|
308
|
-
const pdf = await open()
|
|
309
|
-
count = pdf.numPages
|
|
310
|
-
for (let number = 1; number <= count; number++) {
|
|
311
|
-
const page = await pdf.getPage(number)
|
|
312
|
-
const text = pdfPageText((await page.getTextContent()).items)
|
|
313
|
-
if (isScannedPage(text)) {
|
|
314
|
-
scanned.push(number)
|
|
315
|
-
pages.push(`--- page ${number} ---\n(no text on this page - a scan, sent as the image "${scannedPageName(fileName, number)}")`)
|
|
316
|
-
} else pages.push(`--- page ${number} ---\n${text}`)
|
|
317
|
-
}
|
|
318
|
-
} catch {
|
|
319
|
-
return { refusal: { code: 'attachment-document-unreadable', name: fileName } }
|
|
320
|
-
}
|
|
321
|
-
if (scanned.length && !scans.allowed) return { refusal: { code: 'attachment-scan-needs-images', name: fileName } }
|
|
322
|
-
if (scanned.length > scans.max) return { refusal: { code: 'attachment-scan-too-many-pages', name: fileName, pages: scanned.length, max: scans.max } }
|
|
323
|
-
const images: DocumentFiles['images'] = []
|
|
324
|
-
try {
|
|
325
|
-
for (const page of scanned) images.push({ name: scannedPageName(fileName, page), page, blob: await drawPage(page) })
|
|
326
|
-
} catch {
|
|
327
|
-
return { refusal: { code: 'attachment-document-unreadable', name: fileName } }
|
|
328
|
-
}
|
|
329
|
-
const body = pages.join('\n')
|
|
330
|
-
const read = scanned.length < count ? body : ''
|
|
331
|
-
return settle(fileName, `${documentHeader(fileName, 'pdf', count)}\n${body}\n`, read, maxChars, images)
|
|
332
|
-
}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* One 입력안's fingerprint - what the AI 작업 패널 showed and what the card enters are the same proposal
|
|
3
|
-
* (operato-application/design/ai/workspace.md §6-1). The screen's copy and the server's are one rule;
|
|
4
|
-
* `test/entry-hash-agree.test.ts` runs both over one table.
|
|
5
|
-
*
|
|
6
|
-
* It covers what is entered: the key, the target, create or change, and each row's index, record and values.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
const canonical = (value: unknown): string => {
|
|
10
|
-
if (value === null || value === undefined) return 'null'
|
|
11
|
-
if (Array.isArray(value)) return `[${value.map(canonical).join(',')}]`
|
|
12
|
-
if (typeof value === 'object')
|
|
13
|
-
return `{${Object.keys(value as object)
|
|
14
|
-
.filter(name => (value as any)[name] !== undefined)
|
|
15
|
-
.sort()
|
|
16
|
-
.map(name => `${JSON.stringify(name)}:${canonical((value as any)[name])}`)
|
|
17
|
-
.join(',')}}`
|
|
18
|
-
return JSON.stringify(value)
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/** FNV-1a over the canonical text - a fingerprint to compare, not a secret. */
|
|
22
|
-
export function entryProposalHash(proposal: any): string {
|
|
23
|
-
const text = canonical({
|
|
24
|
-
key: proposal?.key,
|
|
25
|
-
target: proposal?.target,
|
|
26
|
-
op: proposal?.op ?? 'create',
|
|
27
|
-
rows: (proposal?.rows ?? []).map((row: any) => ({ index: row?.index, id: row?.id, values: row?.values ?? {} }))
|
|
28
|
-
})
|
|
29
|
-
let hash = 0x811c9dc5
|
|
30
|
-
for (let i = 0; i < text.length; i++) {
|
|
31
|
-
hash ^= text.charCodeAt(i)
|
|
32
|
-
hash = Math.imul(hash, 0x01000193) >>> 0
|
|
33
|
-
}
|
|
34
|
-
return `${hash.toString(16).padStart(8, '0')}-${text.length.toString(16)}`
|
|
35
|
-
}
|
|
@@ -1,215 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* The data entry card's rules and its handler (operato-application/design/ai/data-entry.md §5).
|
|
3
|
-
*
|
|
4
|
-
* The card is a review, not an editor: a correction is said in the conversation and the model proposes
|
|
5
|
-
* again - the newer card replaces the older one. Pressing asks the server to enter the stored rows; the
|
|
6
|
-
* screen sends no rows of its own.
|
|
7
|
-
*/
|
|
8
|
-
import { encodeListQuery } from '@operato/utils/list-query.js'
|
|
9
|
-
|
|
10
|
-
import type { ProposalContext, ProposalOutcome } from './assistant-proposals.js'
|
|
11
|
-
import { reviewedHashOf, reviewStillHolds } from './entry-workspace.js'
|
|
12
|
-
|
|
13
|
-
export interface EntryIssueView {
|
|
14
|
-
field?: string
|
|
15
|
-
code: string
|
|
16
|
-
messageKey?: string
|
|
17
|
-
params?: Record<string, unknown>
|
|
18
|
-
paramKeys?: Record<string, string>
|
|
19
|
-
blocking: boolean
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export interface EntryRowView {
|
|
23
|
-
index: number
|
|
24
|
-
values: Record<string, unknown>
|
|
25
|
-
sources: { attachmentId?: string; where?: string; person?: boolean }[]
|
|
26
|
-
issues: EntryIssueView[]
|
|
27
|
-
/** The server found this row's numbers and dates together on this line of the cited file. */
|
|
28
|
-
evidence?: { attachmentId: string; line: number }
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export interface EntryTotalView {
|
|
32
|
-
field: string
|
|
33
|
-
all: number
|
|
34
|
-
ready: number
|
|
35
|
-
declared?: number
|
|
36
|
-
declaredFound?: boolean
|
|
37
|
-
difference?: number
|
|
38
|
-
declaredBy?: 'model' | 'file'
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export interface EntryRowResult {
|
|
42
|
-
index: number
|
|
43
|
-
ok: boolean
|
|
44
|
-
id?: string
|
|
45
|
-
label?: string
|
|
46
|
-
error?: string
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export interface EntryApplyAnswer extends ProposalOutcome {
|
|
50
|
-
rows?: EntryRowResult[]
|
|
51
|
-
refusal?: { message: string; extensions: Record<string, unknown>; path: string[] }
|
|
52
|
-
/** Set by the handler from the card - which words the conversation line uses. */
|
|
53
|
-
op?: string
|
|
54
|
-
/** Set by the handler from the card - which card and record kind the entered ids belong to. */
|
|
55
|
-
key?: string
|
|
56
|
-
target?: string
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
export function isEntryProposal(proposal: any): boolean {
|
|
60
|
-
return proposal?.kind === 'entry' && Array.isArray(proposal?.rows)
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
export function entryReadyCount(proposal: any): number {
|
|
64
|
-
const rows: EntryRowView[] = proposal?.rows ?? []
|
|
65
|
-
const blocked = (row: EntryRowView) => row.issues?.some(issue => issue.blocking)
|
|
66
|
-
if (!proposal?.groupBy) return rows.filter(row => !blocked(row)).length
|
|
67
|
-
/* Lines of one record go in together - a record with a line kept out is kept out whole, and its lines do not count. */
|
|
68
|
-
const keyOf = (row: EntryRowView) => {
|
|
69
|
-
const value: any = row.values?.[proposal.groupBy]
|
|
70
|
-
return value === undefined || value === null || value === '' ? `row-${row.index}` : String(typeof value === 'object' ? value.id ?? value.text : value)
|
|
71
|
-
}
|
|
72
|
-
const out = new Set(rows.filter(blocked).map(keyOf))
|
|
73
|
-
return rows.filter(row => !out.has(keyOf(row))).length
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/** The i18n key of an issue - the target's own, or the framework's by code. */
|
|
77
|
-
export function entryIssueKey(issue: EntryIssueView): string {
|
|
78
|
-
return issue.messageKey || `ai-assistant.entry.issue.${issue.code}`
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/** The issues of one cell, and of the row as a whole (no field). */
|
|
82
|
-
export function entryCellIssues(row: EntryRowView, field?: string): EntryIssueView[] {
|
|
83
|
-
return (row.issues ?? []).filter(issue => (field ? issue.field === field : !issue.field))
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
/** What stays in the conversation - the model reads it on its next turn, and the person sees what went in. */
|
|
87
|
-
export function entryOutcomeNote(answer: EntryApplyAnswer, t: (key: string, options?: any) => string): string {
|
|
88
|
-
const refused = (answer.rows ?? []).filter(row => !row.ok)
|
|
89
|
-
const head = answer.op === 'update'
|
|
90
|
-
? answer.applied
|
|
91
|
-
? t('ai-assistant.entry.changed', { defaultValue: 'changed {count} records.', count: answer.applied })
|
|
92
|
-
: t('ai-assistant.entry.changed-none', { defaultValue: 'no record was changed.' })
|
|
93
|
-
: answer.applied
|
|
94
|
-
? t('ai-assistant.entry.entered', { defaultValue: 'entered {count} rows.', count: answer.applied })
|
|
95
|
-
: t('ai-assistant.entry.entered-none', { defaultValue: 'no row was entered.' })
|
|
96
|
-
const lines = refused.slice(0, 20).map(row => t('ai-assistant.entry.row-refused', { defaultValue: 'row {n}: {reason}', n: row.index + 1, reason: row.error || '' }))
|
|
97
|
-
const more = refused.length > 20 ? [t('ai-assistant.entry.more-refused', { defaultValue: '{count} more rows were not entered.', count: refused.length - 20 })] : []
|
|
98
|
-
const records = entryRecordsLine(answer)
|
|
99
|
-
return [head, ...appliedNames(answer, t), ...lines, ...more, ...(records ? [records] : [])].join('\n')
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
/**
|
|
103
|
-
* The line of an entry note that names the records a card entered - for the card, which opens them on their screen, and
|
|
104
|
-
* for the model. The conversation does not draw it. Not `[keys]`: that line is the person's selection, and a card's
|
|
105
|
-
* records must not replace what "these" means.
|
|
106
|
-
*/
|
|
107
|
-
export const ENTRY_RECORDS_PREFIX = '[records]'
|
|
108
|
-
|
|
109
|
-
const enteredIds = (answer: EntryApplyAnswer): string[] => [...new Set((answer.rows ?? []).filter(row => row.ok && row.id).map(row => row.id as string))]
|
|
110
|
-
|
|
111
|
-
function entryRecordsLine(answer: EntryApplyAnswer): string {
|
|
112
|
-
const ids = enteredIds(answer)
|
|
113
|
-
return ids.length && answer.key && answer.target ? `${ENTRY_RECORDS_PREFIX} ${answer.key} ${answer.target} ${ids.join(' ')}` : ''
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
/** The card key, record kind and ids of an entry note's records line - undefined for any other content. */
|
|
117
|
-
export function entryRecordsOf(content: string): { key: string; target: string; ids: string[] } | undefined {
|
|
118
|
-
const line = (content ?? '').split('\n').find(one => one.startsWith(`${ENTRY_RECORDS_PREFIX} `))
|
|
119
|
-
const [key, target, ...ids] = line ? line.slice(ENTRY_RECORDS_PREFIX.length).trim().split(/\s+/) : []
|
|
120
|
-
return key && target && ids.length ? { key, target, ids } : undefined
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
/** At most this many ids narrow a list in its address - more open the list as it is. */
|
|
124
|
-
export const ENTRY_SCREEN_IDS = 50
|
|
125
|
-
|
|
126
|
-
/**
|
|
127
|
-
* Where the card's "see on the screen" goes. One record of a kind with a 360 opens that 360 beside its list; records
|
|
128
|
-
* of the list the screen shows narrow it to them, a condition the person sees and removes; otherwise the screen as it is.
|
|
129
|
-
*/
|
|
130
|
-
export function entryScreenAddress(proposal: any, ids: string[] | undefined, has360: (kind: string) => boolean): string {
|
|
131
|
-
const screen: string = proposal?.screen
|
|
132
|
-
const kind = String(proposal?.target ?? '').split('.')[1] ?? ''
|
|
133
|
-
if (ids?.length === 1 && kind && has360(kind)) return `${screen}?${new URLSearchParams({ f: `${kind}:${ids[0]}` })}`
|
|
134
|
-
if (ids?.length && ids.length <= ENTRY_SCREEN_IDS && proposal?.screenLists)
|
|
135
|
-
return `${screen}?${encodeListQuery({ filters: [{ name: 'id', operator: 'in', value: ids }] })}`
|
|
136
|
-
return screen
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
/*
|
|
140
|
-
* Which records went in, by name - the person finds them on the screen by it, and the model reads which ones they were.
|
|
141
|
-
* Lines of one record share its name; a record without one is only counted.
|
|
142
|
-
*/
|
|
143
|
-
function appliedNames(answer: EntryApplyAnswer, t: (key: string, options?: any) => string): string[] {
|
|
144
|
-
const names = [...new Set((answer.rows ?? []).filter(row => row.ok && row.label).map(row => row.label as string))]
|
|
145
|
-
if (!names.length) return []
|
|
146
|
-
const shown = names.slice(0, 10).join(', ')
|
|
147
|
-
return [names.length > 10 ? `${shown} ${t('ai-assistant.entry.more-applied', { defaultValue: 'and {count} more', count: names.length - 10 })}` : shown]
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
/** The handler every entry card runs - built with the mutation so the rules are tested without a server. */
|
|
151
|
-
export function entryProposalHandler(
|
|
152
|
-
apply: (sessionId: string, proposalKey: string, reviewedHash?: string) => Promise<EntryApplyAnswer>,
|
|
153
|
-
t: (key: string, options?: any) => string,
|
|
154
|
-
reviewedOf: (key: string) => string | undefined = reviewedHashOf,
|
|
155
|
-
reportRefusal: (notification: { level: 'error'; message: string; ex: NonNullable<EntryApplyAnswer['refusal']>[] }) => void | Promise<void> = async notification => {
|
|
156
|
-
/* The generic toast transport. auth-ui alone interprets the refusal and offers an access request. */
|
|
157
|
-
const { notify } = await import('@operato/layout')
|
|
158
|
-
notify(notification)
|
|
159
|
-
}
|
|
160
|
-
) {
|
|
161
|
-
return async (proposal: any, context: ProposalContext): Promise<ProposalOutcome> => {
|
|
162
|
-
if (!context.sessionId || !proposal?.key) return { verdict: 'unavailable', errorCode: 'no-conversation' }
|
|
163
|
-
/* Reviewed in the 작업 패널: entered only as it was shown there (design/ai/workspace.md §6-1) - here, and again at the server. */
|
|
164
|
-
const reviewed = reviewedOf(proposal.key)
|
|
165
|
-
if (!reviewStillHolds(proposal, reviewed)) return { verdict: 'refused', errorCode: 'review-stale', note: t('ai-assistant.entry.review-stale', { defaultValue: 'this proposal changed after it was reviewed in the workspace - review it again before entering.' }) } as any
|
|
166
|
-
const answer = { ...(await apply(context.sessionId, proposal.key, reviewed)), op: proposal.op, key: proposal.key, target: proposal.target }
|
|
167
|
-
if (answer.verdict === 'refused' && answer.errorCode === 'door-closed' && answer.refusal) {
|
|
168
|
-
try {
|
|
169
|
-
await reportRefusal({ level: 'error', message: answer.refusal.message, ex: [answer.refusal] })
|
|
170
|
-
} catch {
|
|
171
|
-
/* Notification delivery is best-effort; it never changes the stored proposal's refusal. */
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
if (answer.errorCode === 'review-stale')
|
|
175
|
-
return { verdict: 'refused', errorCode: 'review-stale', applied: 0, missed: 0, note: t('ai-assistant.entry.review-stale', { defaultValue: 'this proposal changed after it was reviewed in the workspace - review it again before entering.' }) }
|
|
176
|
-
return {
|
|
177
|
-
verdict: answer.verdict,
|
|
178
|
-
...(answer.errorCode ? { errorCode: answer.errorCode } : {}),
|
|
179
|
-
applied: answer.applied ?? 0,
|
|
180
|
-
missed: answer.missed ?? 0,
|
|
181
|
-
note: entryOutcomeNote(answer, t),
|
|
182
|
-
records: enteredIds(answer)
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
/**
|
|
188
|
-
* The newest card per record, over the conversation's proposals in order - an older one is replaced and
|
|
189
|
-
* cannot be entered (the server refuses it as `superseded`; the card says so before anyone presses).
|
|
190
|
-
*/
|
|
191
|
-
export function latestEntryKeys(proposalsInOrder: any[][]): Map<string, string> {
|
|
192
|
-
const latest = new Map<string, string>()
|
|
193
|
-
for (const list of proposalsInOrder) for (const one of list ?? []) if (isEntryProposal(one) && one.key) latest.set(entryGroupOf(one), one.key)
|
|
194
|
-
return latest
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
/** A 입력안 and a 수정안 of one record are counted apart - a newer one of the same kind replaces the older. */
|
|
198
|
-
export function entryGroupOf(proposal: any): string {
|
|
199
|
-
return `${proposal?.target}:${proposal?.op ?? 'create'}`
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
/**
|
|
203
|
-
* The card's title - the record's name from the target (`부서`, `거래처`) and the kind of card from here, so a
|
|
204
|
-
* 수정안 is never titled as a 입력안.
|
|
205
|
-
*/
|
|
206
|
-
export function entryTitle(proposal: any, t: (key: string, options?: any) => string): string {
|
|
207
|
-
const name = proposal?.labelKey ? t(proposal.labelKey) : proposal?.target ?? ''
|
|
208
|
-
return proposal?.op === 'update'
|
|
209
|
-
? t('ai-assistant.entry.title-update', { defaultValue: '{name} to change', name })
|
|
210
|
-
: t('ai-assistant.entry.title-create', { defaultValue: '{name} to enter', name })
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
export function isChangeProposal(proposal: any): boolean {
|
|
214
|
-
return isEntryProposal(proposal) && proposal.op === 'update'
|
|
215
|
-
}
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Reviewing a 입력안 in the AI 작업 패널 (operato-application/design/ai/workspace.md §6-1). Pure but for the
|
|
3
|
-
* session store - tested without a browser.
|
|
4
|
-
*
|
|
5
|
-
* The page is read-only: every column and every row, sorted as stored, issues marked. The one place that enters
|
|
6
|
-
* is the dock's card. What the page showed is remembered by its fingerprint, and the card sends it - a proposal
|
|
7
|
-
* that changed in between is refused, and the person reviews it again.
|
|
8
|
-
*/
|
|
9
|
-
import { entryProposalHash } from './entry-hash.js'
|
|
10
|
-
|
|
11
|
-
/** A card wide or long enough not to be read in the dock. */
|
|
12
|
-
export const WORKSPACE_ROWS = 20
|
|
13
|
-
export const WORKSPACE_COLUMNS = 6
|
|
14
|
-
|
|
15
|
-
export function offersWorkspaceReview(proposal: any): boolean {
|
|
16
|
-
return (proposal?.rows?.length ?? 0) > WORKSPACE_ROWS || (proposal?.columns?.length ?? 0) > WORKSPACE_COLUMNS
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export function entryReviewAddress(sessionId: string, proposalKey: string): string {
|
|
20
|
-
return `assistant-workspace?${new URLSearchParams({ session: sessionId, entry: proposalKey }).toString()}`
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/** The proposal of that key among the conversation's messages, and whether a newer card of the same record replaced it. */
|
|
24
|
-
export function entryForReview(messages: { id: string; createdAt?: string; proposalsJson?: any[] | null }[], key: string): { proposal?: any; createdAt?: string; superseded: boolean } {
|
|
25
|
-
let at = -1
|
|
26
|
-
let proposal: any
|
|
27
|
-
let createdAt: string | undefined
|
|
28
|
-
messages.forEach((message, i) => {
|
|
29
|
-
for (const one of message.proposalsJson ?? []) if (one?.kind === 'entry' && one?.key === key) (at = i), (proposal = one), (createdAt = message.createdAt)
|
|
30
|
-
})
|
|
31
|
-
if (!proposal) return { superseded: false }
|
|
32
|
-
const superseded = messages
|
|
33
|
-
.slice(at + 1)
|
|
34
|
-
.some(message => (message.proposalsJson ?? []).some(one => one?.kind === 'entry' && one?.target === proposal.target && (one?.op ?? 'create') === (proposal.op ?? 'create')))
|
|
35
|
-
return { proposal, createdAt, superseded }
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
const STORE = 'ai-assistant.entry-reviewed:'
|
|
39
|
-
|
|
40
|
-
/** Remembers what the page showed for this key. A browser that keeps nothing keeps nothing - the card then sends no fingerprint. */
|
|
41
|
-
export function rememberReviewed(proposal: any, store: Pick<Storage, 'setItem'> | undefined = safeSession()): string {
|
|
42
|
-
const hash = entryProposalHash(proposal)
|
|
43
|
-
try {
|
|
44
|
-
store?.setItem(STORE + proposal.key, hash)
|
|
45
|
-
} catch {
|
|
46
|
-
/* private window or blocked storage */
|
|
47
|
-
}
|
|
48
|
-
return hash
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
export function reviewedHashOf(key: string, store: Pick<Storage, 'getItem'> | undefined = safeSession()): string | undefined {
|
|
52
|
-
try {
|
|
53
|
-
return store?.getItem(STORE + key) ?? undefined
|
|
54
|
-
} catch {
|
|
55
|
-
return undefined
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/** Whether the card may be pressed: not reviewed, or reviewed as it stands now. */
|
|
60
|
-
export function reviewStillHolds(proposal: any, reviewed: string | undefined): boolean {
|
|
61
|
-
return !reviewed || reviewed === entryProposalHash(proposal)
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
function safeSession(): Storage | undefined {
|
|
65
|
-
try {
|
|
66
|
-
return typeof sessionStorage === 'undefined' ? undefined : sessionStorage
|
|
67
|
-
} catch {
|
|
68
|
-
return undefined
|
|
69
|
-
}
|
|
70
|
-
}
|