@rubytech/create-maxy-code 0.1.446 → 0.1.447
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/package.json +1 -1
- package/payload/platform/lib/graph-style/dist/index.d.ts.map +1 -1
- package/payload/platform/lib/graph-style/dist/index.js +6 -0
- package/payload/platform/lib/graph-style/dist/index.js.map +1 -1
- package/payload/platform/lib/graph-style/src/index.ts +7 -0
- package/payload/platform/neo4j/schema.cypher +32 -1
- package/payload/platform/plugins/.claude-plugin/marketplace.json +5 -0
- package/payload/platform/plugins/admin/hooks/lib/maxy-mcp-plugins.txt +1 -0
- package/payload/platform/plugins/admin/skills/platform-architecture/SKILL.md +42 -5
- package/payload/platform/plugins/docs/references/calendar-booking.md +18 -1
- package/payload/platform/plugins/docs/references/claudeai-connectors.md +15 -0
- package/payload/platform/plugins/docs/references/outlook-guide.md +8 -3
- package/payload/platform/plugins/email/skills/email-composition/SKILL.md +4 -4
- package/payload/platform/plugins/memory/references/schema-construction.md +7 -2
- package/payload/platform/plugins/outlook/.claude-plugin/plugin.json +1 -1
- package/payload/platform/plugins/outlook/PLUGIN.md +23 -5
- package/payload/platform/plugins/outlook/mcp/dist/__tests__/draft-edit.test.d.ts +2 -0
- package/payload/platform/plugins/outlook/mcp/dist/__tests__/draft-edit.test.d.ts.map +1 -0
- package/payload/platform/plugins/outlook/mcp/dist/__tests__/draft-edit.test.js +70 -0
- package/payload/platform/plugins/outlook/mcp/dist/__tests__/draft-edit.test.js.map +1 -0
- package/payload/platform/plugins/outlook/mcp/dist/__tests__/html-to-text.test.d.ts +2 -0
- package/payload/platform/plugins/outlook/mcp/dist/__tests__/html-to-text.test.d.ts.map +1 -0
- package/payload/platform/plugins/outlook/mcp/dist/__tests__/html-to-text.test.js +22 -0
- package/payload/platform/plugins/outlook/mcp/dist/__tests__/html-to-text.test.js.map +1 -0
- package/payload/platform/plugins/outlook/mcp/dist/__tests__/mail-delete.test.d.ts +2 -0
- package/payload/platform/plugins/outlook/mcp/dist/__tests__/mail-delete.test.d.ts.map +1 -0
- package/payload/platform/plugins/outlook/mcp/dist/__tests__/mail-delete.test.js +60 -0
- package/payload/platform/plugins/outlook/mcp/dist/__tests__/mail-delete.test.js.map +1 -0
- package/payload/platform/plugins/outlook/mcp/dist/__tests__/mail-fetch-body.test.d.ts +2 -0
- package/payload/platform/plugins/outlook/mcp/dist/__tests__/mail-fetch-body.test.d.ts.map +1 -0
- package/payload/platform/plugins/outlook/mcp/dist/__tests__/mail-fetch-body.test.js +80 -0
- package/payload/platform/plugins/outlook/mcp/dist/__tests__/mail-fetch-body.test.js.map +1 -0
- package/payload/platform/plugins/outlook/mcp/dist/__tests__/mail-otp-extract.test.d.ts +2 -0
- package/payload/platform/plugins/outlook/mcp/dist/__tests__/mail-otp-extract.test.d.ts.map +1 -0
- package/payload/platform/plugins/outlook/mcp/dist/__tests__/mail-otp-extract.test.js +90 -0
- package/payload/platform/plugins/outlook/mcp/dist/__tests__/mail-otp-extract.test.js.map +1 -0
- package/payload/platform/plugins/outlook/mcp/dist/__tests__/mail-reply.test.d.ts +2 -0
- package/payload/platform/plugins/outlook/mcp/dist/__tests__/mail-reply.test.d.ts.map +1 -0
- package/payload/platform/plugins/outlook/mcp/dist/__tests__/mail-reply.test.js +194 -0
- package/payload/platform/plugins/outlook/mcp/dist/__tests__/mail-reply.test.js.map +1 -0
- package/payload/platform/plugins/outlook/mcp/dist/__tests__/otp.test.d.ts +2 -0
- package/payload/platform/plugins/outlook/mcp/dist/__tests__/otp.test.d.ts.map +1 -0
- package/payload/platform/plugins/outlook/mcp/dist/__tests__/otp.test.js +16 -0
- package/payload/platform/plugins/outlook/mcp/dist/__tests__/otp.test.js.map +1 -0
- package/payload/platform/plugins/outlook/mcp/dist/__tests__/outbound-attachments.test.d.ts +2 -0
- package/payload/platform/plugins/outlook/mcp/dist/__tests__/outbound-attachments.test.d.ts.map +1 -0
- package/payload/platform/plugins/outlook/mcp/dist/__tests__/outbound-attachments.test.js +103 -0
- package/payload/platform/plugins/outlook/mcp/dist/__tests__/outbound-attachments.test.js.map +1 -0
- package/payload/platform/plugins/outlook/mcp/dist/index.js +88 -0
- package/payload/platform/plugins/outlook/mcp/dist/index.js.map +1 -1
- package/payload/platform/plugins/outlook/mcp/dist/lib/html-to-text.d.ts +9 -0
- package/payload/platform/plugins/outlook/mcp/dist/lib/html-to-text.d.ts.map +1 -0
- package/payload/platform/plugins/outlook/mcp/dist/lib/html-to-text.js +24 -0
- package/payload/platform/plugins/outlook/mcp/dist/lib/html-to-text.js.map +1 -0
- package/payload/platform/plugins/outlook/mcp/dist/lib/otp.d.ts +2 -0
- package/payload/platform/plugins/outlook/mcp/dist/lib/otp.d.ts.map +1 -0
- package/payload/platform/plugins/outlook/mcp/dist/lib/otp.js +49 -0
- package/payload/platform/plugins/outlook/mcp/dist/lib/otp.js.map +1 -0
- package/payload/platform/plugins/outlook/mcp/dist/lib/outbound-attachments.d.ts +58 -0
- package/payload/platform/plugins/outlook/mcp/dist/lib/outbound-attachments.d.ts.map +1 -0
- package/payload/platform/plugins/outlook/mcp/dist/lib/outbound-attachments.js +127 -0
- package/payload/platform/plugins/outlook/mcp/dist/lib/outbound-attachments.js.map +1 -0
- package/payload/platform/plugins/outlook/mcp/dist/lib/upload-session.d.ts +28 -0
- package/payload/platform/plugins/outlook/mcp/dist/lib/upload-session.d.ts.map +1 -0
- package/payload/platform/plugins/outlook/mcp/dist/lib/upload-session.js +54 -0
- package/payload/platform/plugins/outlook/mcp/dist/lib/upload-session.js.map +1 -0
- package/payload/platform/plugins/outlook/mcp/dist/tools/draft-edit.d.ts +21 -0
- package/payload/platform/plugins/outlook/mcp/dist/tools/draft-edit.d.ts.map +1 -0
- package/payload/platform/plugins/outlook/mcp/dist/tools/draft-edit.js +38 -0
- package/payload/platform/plugins/outlook/mcp/dist/tools/draft-edit.js.map +1 -0
- package/payload/platform/plugins/outlook/mcp/dist/tools/mail-delete.d.ts +14 -0
- package/payload/platform/plugins/outlook/mcp/dist/tools/mail-delete.d.ts.map +1 -0
- package/payload/platform/plugins/outlook/mcp/dist/tools/mail-delete.js +39 -0
- package/payload/platform/plugins/outlook/mcp/dist/tools/mail-delete.js.map +1 -0
- package/payload/platform/plugins/outlook/mcp/dist/tools/mail-fetch-body.d.ts +23 -0
- package/payload/platform/plugins/outlook/mcp/dist/tools/mail-fetch-body.d.ts.map +1 -0
- package/payload/platform/plugins/outlook/mcp/dist/tools/mail-fetch-body.js +44 -0
- package/payload/platform/plugins/outlook/mcp/dist/tools/mail-fetch-body.js.map +1 -0
- package/payload/platform/plugins/outlook/mcp/dist/tools/mail-otp-extract.d.ts +22 -0
- package/payload/platform/plugins/outlook/mcp/dist/tools/mail-otp-extract.d.ts.map +1 -0
- package/payload/platform/plugins/outlook/mcp/dist/tools/mail-otp-extract.js +90 -0
- package/payload/platform/plugins/outlook/mcp/dist/tools/mail-otp-extract.js.map +1 -0
- package/payload/platform/plugins/outlook/mcp/dist/tools/mail-reply.d.ts +27 -0
- package/payload/platform/plugins/outlook/mcp/dist/tools/mail-reply.d.ts.map +1 -0
- package/payload/platform/plugins/outlook/mcp/dist/tools/mail-reply.js +75 -0
- package/payload/platform/plugins/outlook/mcp/dist/tools/mail-reply.js.map +1 -0
- package/payload/platform/plugins/outlook/references/graph-surfaces.md +57 -1
- package/payload/platform/plugins/outlook/skills/outlook/SKILL.md +15 -4
- package/payload/platform/plugins/scheduling/PLUGIN.md +15 -0
- package/payload/platform/plugins/scheduling/mcp/dist/index.js +29 -1
- package/payload/platform/plugins/scheduling/mcp/dist/index.js.map +1 -1
- package/payload/platform/plugins/scheduling/mcp/dist/lib/__tests__/booking-reconcile.test.js +53 -1
- package/payload/platform/plugins/scheduling/mcp/dist/lib/__tests__/booking-reconcile.test.js.map +1 -1
- package/payload/platform/plugins/scheduling/mcp/dist/lib/booking-reconcile.d.ts +21 -0
- package/payload/platform/plugins/scheduling/mcp/dist/lib/booking-reconcile.d.ts.map +1 -1
- package/payload/platform/plugins/scheduling/mcp/dist/lib/booking-reconcile.js +80 -0
- package/payload/platform/plugins/scheduling/mcp/dist/lib/booking-reconcile.js.map +1 -1
- package/payload/platform/plugins/scheduling/mcp/dist/scripts/reconcile-bookings.d.ts +4 -0
- package/payload/platform/plugins/scheduling/mcp/dist/scripts/reconcile-bookings.d.ts.map +1 -1
- package/payload/platform/plugins/scheduling/mcp/dist/scripts/reconcile-bookings.js +68 -1
- package/payload/platform/plugins/scheduling/mcp/dist/scripts/reconcile-bookings.js.map +1 -1
- package/payload/platform/plugins/scheduling/mcp/dist/tools/__tests__/schedule-connector-busy-sync.test.d.ts +2 -0
- package/payload/platform/plugins/scheduling/mcp/dist/tools/__tests__/schedule-connector-busy-sync.test.d.ts.map +1 -0
- package/payload/platform/plugins/scheduling/mcp/dist/tools/__tests__/schedule-connector-busy-sync.test.js +75 -0
- package/payload/platform/plugins/scheduling/mcp/dist/tools/__tests__/schedule-connector-busy-sync.test.js.map +1 -0
- package/payload/platform/plugins/scheduling/mcp/dist/tools/schedule-connector-busy-sync.d.ts +31 -0
- package/payload/platform/plugins/scheduling/mcp/dist/tools/schedule-connector-busy-sync.d.ts.map +1 -0
- package/payload/platform/plugins/scheduling/mcp/dist/tools/schedule-connector-busy-sync.js +41 -0
- package/payload/platform/plugins/scheduling/mcp/dist/tools/schedule-connector-busy-sync.js.map +1 -0
- package/payload/platform/plugins/voice-mirror/.claude-plugin/plugin.json +21 -0
- package/payload/platform/plugins/voice-mirror/PLUGIN.md +72 -0
- package/payload/{premium-plugins/writer-craft → platform/plugins/voice-mirror}/mcp/dist/index.js +10 -10
- package/payload/{premium-plugins/writer-craft → platform/plugins/voice-mirror}/mcp/dist/index.js.map +1 -1
- package/payload/{premium-plugins/writer-craft → platform/plugins/voice-mirror}/mcp/dist/lib/neo4j.d.ts +1 -1
- package/payload/{premium-plugins/writer-craft → platform/plugins/voice-mirror}/mcp/dist/lib/neo4j.js +4 -4
- package/payload/{premium-plugins/writer-craft → platform/plugins/voice-mirror}/mcp/dist/lib/neo4j.js.map +1 -1
- package/payload/{premium-plugins/writer-craft → platform/plugins/voice-mirror}/mcp/dist/tools/voice-record-feedback.js +1 -1
- package/payload/{premium-plugins/writer-craft → platform/plugins/voice-mirror}/mcp/dist/tools/voice-record-feedback.js.map +1 -1
- package/payload/{premium-plugins/writer-craft → platform/plugins/voice-mirror}/mcp/package-lock.json +2 -2
- package/payload/{premium-plugins/writer-craft → platform/plugins/voice-mirror}/mcp/package.json +1 -1
- package/payload/{premium-plugins/writer-craft → platform/plugins/voice-mirror}/mcp/scripts/smoke.mjs +9 -9
- package/payload/{premium-plugins/writer-craft → platform/plugins/voice-mirror}/skills/voice-mirror/SKILL.md +1 -1
- package/payload/platform/services/claude-session-manager/dist/canonical-tool-names.generated.d.ts.map +1 -1
- package/payload/platform/services/claude-session-manager/dist/canonical-tool-names.generated.js +12 -0
- package/payload/platform/services/claude-session-manager/dist/canonical-tool-names.generated.js.map +1 -1
- package/payload/platform/services/claude-session-manager/dist/http-server.js +1 -1
- package/payload/platform/services/claude-session-manager/dist/http-server.js.map +1 -1
- package/payload/platform/templates/agents/admin/AGENTS.md +1 -1
- package/payload/platform/templates/specialists/agents/content-producer.md +1 -1
- package/payload/platform/templates/specialists/agents/personal-assistant.md +6 -2
- package/payload/premium-plugins/writer-craft/.claude-plugin/plugin.json +1 -14
- package/payload/premium-plugins/writer-craft/PLUGIN.md +2 -51
- package/payload/server/public/assets/{AdminLoginScreens-D9L-CuWi.js → AdminLoginScreens-Bvf4HKmq.js} +1 -1
- package/payload/server/public/assets/AdminShell-CaGc8ODG.js +2 -0
- package/payload/server/public/assets/{Checkbox-CFdt8ljo.js → Checkbox-2SswiICc.js} +1 -1
- package/payload/server/public/assets/admin-B7GPCzpr.js +1 -0
- package/payload/server/public/assets/browser-CodHC_MO.js +1 -0
- package/payload/server/public/assets/calendar-DH7cyXKF.js +1 -0
- package/payload/server/public/assets/chat-BQyPAEMv.js +1 -0
- package/payload/server/public/assets/chevron-left-Cmev0R9v.js +1 -0
- package/payload/server/public/assets/data-DWxZzMfL.js +1 -0
- package/payload/server/public/assets/{graph-DrE7KupQ.js → graph-BToB78LG.js} +2 -2
- package/payload/server/public/assets/graph-labels-JRGrstzM.js +1 -0
- package/payload/server/public/assets/maximize-2-CEQRv64B.js +1 -0
- package/payload/server/public/assets/operator-Cx8cq2wf.js +1 -0
- package/payload/server/public/assets/page-D6kzsk18.js +32 -0
- package/payload/server/public/assets/page-TCsQy4eP.js +1 -0
- package/payload/server/public/assets/public-B61xcmAr.js +1 -0
- package/payload/server/public/assets/{rotate-ccw-Cqp4oqHV.js → rotate-ccw-7_3ol0Z4.js} +1 -1
- package/payload/server/public/assets/{tasks-bQKOhMga.js → tasks-BY9ajKXf.js} +1 -1
- package/payload/server/public/assets/{time-entry-format-BIL4ZaDK.js → time-entry-format-DmNhIJnM.js} +1 -1
- package/payload/server/public/assets/useCopyFeedback-C5-GOl5l.js +1 -0
- package/payload/server/public/assets/useSelectionMode-UOUVnP9B.js +1 -0
- package/payload/server/public/assets/{useSubAccountSwitcher-CVHKTSst.css → useSubAccountSwitcher-DgM1ergs.css} +1 -1
- package/payload/server/public/assets/useVoiceRecorder-BAP3yGxs.js +2 -0
- package/payload/server/public/browser.html +5 -5
- package/payload/server/public/calendar.html +6 -6
- package/payload/server/public/chat.html +12 -12
- package/payload/server/public/data.html +10 -10
- package/payload/server/public/graph.html +11 -11
- package/payload/server/public/index.html +13 -13
- package/payload/server/public/operator.html +14 -14
- package/payload/server/public/public.html +12 -12
- package/payload/server/public/tasks.html +5 -5
- package/payload/server/server.js +349 -171
- package/payload/premium-plugins/writer-craft/lib/mcp-lifeline/dist/index.d.ts +0 -8
- package/payload/premium-plugins/writer-craft/lib/mcp-lifeline/dist/index.d.ts.map +0 -1
- package/payload/premium-plugins/writer-craft/lib/mcp-lifeline/dist/index.js +0 -71
- package/payload/premium-plugins/writer-craft/lib/mcp-lifeline/dist/index.js.map +0 -1
- package/payload/premium-plugins/writer-craft/lib/mcp-lifeline/package.json +0 -7
- package/payload/premium-plugins/writer-craft/lib/mcp-stderr-tee/dist/index.d.ts +0 -51
- package/payload/premium-plugins/writer-craft/lib/mcp-stderr-tee/dist/index.d.ts.map +0 -1
- package/payload/premium-plugins/writer-craft/lib/mcp-stderr-tee/dist/index.js +0 -196
- package/payload/premium-plugins/writer-craft/lib/mcp-stderr-tee/dist/index.js.map +0 -1
- package/payload/premium-plugins/writer-craft/lib/mcp-stderr-tee/package.json +0 -7
- package/payload/premium-plugins/writer-craft/mcp/dist/cli/ingest-session-text.d.ts +0 -3
- package/payload/premium-plugins/writer-craft/mcp/dist/cli/ingest-session-text.d.ts.map +0 -1
- package/payload/premium-plugins/writer-craft/mcp/dist/cli/ingest-session-text.js +0 -58
- package/payload/premium-plugins/writer-craft/mcp/dist/cli/ingest-session-text.js.map +0 -1
- package/payload/premium-plugins/writer-craft/mcp/src/index.ts +0 -457
- package/payload/premium-plugins/writer-craft/mcp/src/lib/neo4j.ts +0 -56
- package/payload/premium-plugins/writer-craft/mcp/src/lib/voice-corpus.ts +0 -154
- package/payload/premium-plugins/writer-craft/mcp/src/tools/voice-distil-profile.ts +0 -833
- package/payload/premium-plugins/writer-craft/mcp/src/tools/voice-ingest-session-text.ts +0 -153
- package/payload/premium-plugins/writer-craft/mcp/src/tools/voice-record-feedback.ts +0 -148
- package/payload/premium-plugins/writer-craft/mcp/src/tools/voice-retrieve-conditioning.ts +0 -270
- package/payload/premium-plugins/writer-craft/mcp/src/tools/voice-tag-content.ts +0 -181
- package/payload/premium-plugins/writer-craft/mcp/tsconfig.json +0 -8
- package/payload/server/public/assets/AdminShell-DSQrvZXq.js +0 -2
- package/payload/server/public/assets/admin-Ch4n-G0j.js +0 -1
- package/payload/server/public/assets/browser-B2AIxiuk.js +0 -1
- package/payload/server/public/assets/calendar-BvItH3B0.js +0 -1
- package/payload/server/public/assets/chat-eQFMaX9y.js +0 -1
- package/payload/server/public/assets/chevron-left-D2AnCEyE.js +0 -1
- package/payload/server/public/assets/data-BzOmbHoe.js +0 -1
- package/payload/server/public/assets/file-download-CK9j_Jx2.js +0 -1
- package/payload/server/public/assets/graph-labels-CwEtvIRV.js +0 -1
- package/payload/server/public/assets/maximize-2-CuzEom3K.js +0 -1
- package/payload/server/public/assets/operator-DlboYPPu.js +0 -1
- package/payload/server/public/assets/page-BuWH5gNK.js +0 -1
- package/payload/server/public/assets/page-Co9E8U5x.js +0 -32
- package/payload/server/public/assets/public-DtFpPMTG.js +0 -1
- package/payload/server/public/assets/useCopyFeedback-rB8QuqyH.js +0 -1
- package/payload/server/public/assets/useVoiceRecorder-Ctny8qWx.js +0 -2
- /package/payload/{premium-plugins/writer-craft → platform/plugins/voice-mirror}/lib/mcp-spawn-tee/index.js +0 -0
- /package/payload/{premium-plugins/writer-craft → platform/plugins/voice-mirror}/lib/mcp-spawn-tee/package.json +0 -0
- /package/payload/{premium-plugins/writer-craft → platform/plugins/voice-mirror}/mcp/dist/index.d.ts +0 -0
- /package/payload/{premium-plugins/writer-craft → platform/plugins/voice-mirror}/mcp/dist/index.d.ts.map +0 -0
- /package/payload/{premium-plugins/writer-craft → platform/plugins/voice-mirror}/mcp/dist/lib/neo4j.d.ts.map +0 -0
- /package/payload/{premium-plugins/writer-craft → platform/plugins/voice-mirror}/mcp/dist/lib/voice-corpus.d.ts +0 -0
- /package/payload/{premium-plugins/writer-craft → platform/plugins/voice-mirror}/mcp/dist/lib/voice-corpus.d.ts.map +0 -0
- /package/payload/{premium-plugins/writer-craft → platform/plugins/voice-mirror}/mcp/dist/lib/voice-corpus.js +0 -0
- /package/payload/{premium-plugins/writer-craft → platform/plugins/voice-mirror}/mcp/dist/lib/voice-corpus.js.map +0 -0
- /package/payload/{premium-plugins/writer-craft → platform/plugins/voice-mirror}/mcp/dist/tools/voice-distil-profile.d.ts +0 -0
- /package/payload/{premium-plugins/writer-craft → platform/plugins/voice-mirror}/mcp/dist/tools/voice-distil-profile.d.ts.map +0 -0
- /package/payload/{premium-plugins/writer-craft → platform/plugins/voice-mirror}/mcp/dist/tools/voice-distil-profile.js +0 -0
- /package/payload/{premium-plugins/writer-craft → platform/plugins/voice-mirror}/mcp/dist/tools/voice-distil-profile.js.map +0 -0
- /package/payload/{premium-plugins/writer-craft → platform/plugins/voice-mirror}/mcp/dist/tools/voice-ingest-session-text.d.ts +0 -0
- /package/payload/{premium-plugins/writer-craft → platform/plugins/voice-mirror}/mcp/dist/tools/voice-ingest-session-text.d.ts.map +0 -0
- /package/payload/{premium-plugins/writer-craft → platform/plugins/voice-mirror}/mcp/dist/tools/voice-ingest-session-text.js +0 -0
- /package/payload/{premium-plugins/writer-craft → platform/plugins/voice-mirror}/mcp/dist/tools/voice-ingest-session-text.js.map +0 -0
- /package/payload/{premium-plugins/writer-craft → platform/plugins/voice-mirror}/mcp/dist/tools/voice-record-feedback.d.ts +0 -0
- /package/payload/{premium-plugins/writer-craft → platform/plugins/voice-mirror}/mcp/dist/tools/voice-record-feedback.d.ts.map +0 -0
- /package/payload/{premium-plugins/writer-craft → platform/plugins/voice-mirror}/mcp/dist/tools/voice-retrieve-conditioning.d.ts +0 -0
- /package/payload/{premium-plugins/writer-craft → platform/plugins/voice-mirror}/mcp/dist/tools/voice-retrieve-conditioning.d.ts.map +0 -0
- /package/payload/{premium-plugins/writer-craft → platform/plugins/voice-mirror}/mcp/dist/tools/voice-retrieve-conditioning.js +0 -0
- /package/payload/{premium-plugins/writer-craft → platform/plugins/voice-mirror}/mcp/dist/tools/voice-retrieve-conditioning.js.map +0 -0
- /package/payload/{premium-plugins/writer-craft → platform/plugins/voice-mirror}/mcp/dist/tools/voice-tag-content.d.ts +0 -0
- /package/payload/{premium-plugins/writer-craft → platform/plugins/voice-mirror}/mcp/dist/tools/voice-tag-content.d.ts.map +0 -0
- /package/payload/{premium-plugins/writer-craft → platform/plugins/voice-mirror}/mcp/dist/tools/voice-tag-content.js +0 -0
- /package/payload/{premium-plugins/writer-craft → platform/plugins/voice-mirror}/mcp/dist/tools/voice-tag-content.js.map +0 -0
- /package/payload/server/public/assets/{useSubAccountSwitcher-CHEt_m6q.js → useSubAccountSwitcher-DF6bohQA.js} +0 -0
|
@@ -1,833 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* voice-distil-profile — walk the operator's `human-only` corpus and
|
|
3
|
-
* persist a `:VoiceProfile` style card.
|
|
4
|
-
*
|
|
5
|
-
* Task 462: one `:VoiceProfile` per `(accountId, userId, format)`.
|
|
6
|
-
* `format` ∈ `{text, email, social-post, article, marketing-copy, note}`.
|
|
7
|
-
*
|
|
8
|
-
* - When `format` is supplied, distils that format only.
|
|
9
|
-
* - When `format` is omitted, enumerates distinct format values present
|
|
10
|
-
* in the corpus (nodes where `n.format IS NOT NULL`) and distils each
|
|
11
|
-
* that fires the cadence guard. Returns `skipReason: 'no-format-tagged-content'`
|
|
12
|
-
* when enumeration yields zero formats.
|
|
13
|
-
*
|
|
14
|
-
* Cadence guard: re-runs on ≥20% corpus growth since last profile, OR
|
|
15
|
-
* ≥30 days since `generatedAt`. `force: true` overrides both.
|
|
16
|
-
*
|
|
17
|
-
* Body-text sampling caps at ~120k chars (rough proxy for tokens at
|
|
18
|
-
* 4 chars/token = 30k tokens) — well inside Haiku's 200k context window
|
|
19
|
-
* with headroom for the system prompt + tool schema.
|
|
20
|
-
*
|
|
21
|
-
* Task 424 — the Haiku style-card composition moved into the calling agent's
|
|
22
|
-
* turn. The agent reads the corpus exemplars and feedback intents (this tool
|
|
23
|
-
* returns them when called with `mode='sample'`), composes the style-card
|
|
24
|
-
* YAML, then calls this tool again with `mode='write'` + `styleCardYaml` set.
|
|
25
|
-
*/
|
|
26
|
-
import neo4j from "neo4j-driver";
|
|
27
|
-
import { getSession } from "../lib/neo4j.js";
|
|
28
|
-
import { notTrashed } from "../lib/voice-corpus.js";
|
|
29
|
-
import {
|
|
30
|
-
VOICE_CORPUS_WHERE,
|
|
31
|
-
voiceCorpusWhereWithFormat,
|
|
32
|
-
voiceCorpusWhereWithFormatAndAuthor,
|
|
33
|
-
profileUserIdForScope,
|
|
34
|
-
FORMAT_VALUES,
|
|
35
|
-
type VoiceFormat,
|
|
36
|
-
type VoiceScope,
|
|
37
|
-
} from "../lib/voice-corpus.js";
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Coerce a neo4j cypher RETURN value to a plain JS number.
|
|
41
|
-
*
|
|
42
|
-
* Neo4j-driver represents INTs as `Integer` objects (high/low 32-bit
|
|
43
|
-
* pair to safely carry int64). `Number()` *usually* works via valueOf()
|
|
44
|
-
* but the safe path is `Integer#toNumber()`. Returns null when the
|
|
45
|
-
* value is null/undefined so cadence-guard arithmetic stays explicit
|
|
46
|
-
* about the "no prior profile" case.
|
|
47
|
-
*/
|
|
48
|
-
function toJsNumber(value: unknown): number | null {
|
|
49
|
-
if (value === null || value === undefined) return null;
|
|
50
|
-
if (typeof value === "number") return value;
|
|
51
|
-
if (neo4j.isInt(value)) return (value as { toNumber: () => number }).toNumber();
|
|
52
|
-
if (typeof value === "string") {
|
|
53
|
-
const parsed = Number(value);
|
|
54
|
-
return Number.isFinite(parsed) ? parsed : null;
|
|
55
|
-
}
|
|
56
|
-
return null;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
const SAMPLE_CHAR_CAP = 120_000;
|
|
60
|
-
const RE_RUN_GROWTH_FRACTION = 0.2;
|
|
61
|
-
const RE_RUN_AGE_DAYS = 30;
|
|
62
|
-
|
|
63
|
-
export interface VoiceDistilProfileParams {
|
|
64
|
-
accountId: string;
|
|
65
|
-
userId: string;
|
|
66
|
-
/**
|
|
67
|
-
* Profile scope (Task 676). `'personal'` (default) distils the operator's
|
|
68
|
-
* own author-filtered corpus onto `:AdminUser`; `'org'` distils the whole
|
|
69
|
-
* account onto `:LocalBusiness` under the reserved sentinel userId.
|
|
70
|
-
*/
|
|
71
|
-
scope?: VoiceScope;
|
|
72
|
-
force?: boolean;
|
|
73
|
-
/**
|
|
74
|
-
* Writing format to distil. When omitted on `sample`, enumerates distinct
|
|
75
|
-
* format values in the corpus and distils each that fires the cadence
|
|
76
|
-
* guard. Required on `amend` and `write`.
|
|
77
|
-
*/
|
|
78
|
-
format?: VoiceFormat;
|
|
79
|
-
/**
|
|
80
|
-
* Operation mode:
|
|
81
|
-
* - `'sample'` (default, Task 424) — walk the full per-format corpus and
|
|
82
|
-
* return exemplars + feedback intents. No write. The calling agent
|
|
83
|
-
* composes the style-card YAML in-turn.
|
|
84
|
-
* - `'write'` (Task 424) — persist the style card the agent produced.
|
|
85
|
-
* Requires `styleCardYaml`. Optional `amendedFromNodeIds` adds
|
|
86
|
-
* `LEARNED_FROM` edges to the named nodes (additive — MERGE preserves
|
|
87
|
-
* prior edges).
|
|
88
|
-
* - `'amend'` (Task 472) — operator-initiated incremental update from
|
|
89
|
-
* one or more named documents. Reads only those nodes plus the
|
|
90
|
-
* existing `:VoiceProfile.styleCard` so the agent can decide whether
|
|
91
|
-
* the document moves the profile. Format predicate is dropped on the
|
|
92
|
-
* read (the operator picked the docs); `authorshipMode` + trashed +
|
|
93
|
-
* label predicates still apply per-document. Cadence guard does not
|
|
94
|
-
* apply.
|
|
95
|
-
*/
|
|
96
|
-
mode?: "sample" | "write" | "amend";
|
|
97
|
-
/** Required when `mode='write'`. The style-card YAML produced by the agent. */
|
|
98
|
-
styleCardYaml?: string;
|
|
99
|
-
/**
|
|
100
|
-
* Required when `mode='amend'`. ElementIds of the documents to fold into
|
|
101
|
-
* the profile. Each id is eligibility-checked; ineligible ones are
|
|
102
|
-
* reported in the return payload (the agent surfaces them to the operator).
|
|
103
|
-
*/
|
|
104
|
-
nodeIds?: string[];
|
|
105
|
-
/**
|
|
106
|
-
* Optional on `mode='write'` after an `amend` sample. ElementIds the
|
|
107
|
-
* agent decided moved the profile. Each becomes a `LEARNED_FROM` edge
|
|
108
|
-
* from the persisted `:VoiceProfile`. Additive — pre-existing edges
|
|
109
|
-
* remain via `MERGE`.
|
|
110
|
-
*/
|
|
111
|
-
amendedFromNodeIds?: string[];
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
export interface VoiceCorpusExemplar {
|
|
115
|
-
id: string;
|
|
116
|
-
label: string;
|
|
117
|
-
body: string;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
export interface VoiceDistilProfileResult {
|
|
121
|
-
profileId: string | null;
|
|
122
|
-
corpusSize: number;
|
|
123
|
-
generatedAt: string | null;
|
|
124
|
-
feedbackEntries: number;
|
|
125
|
-
skipped: boolean;
|
|
126
|
-
/** Present only on the multi-format path: the format this result was distilled for. */
|
|
127
|
-
format?: VoiceFormat;
|
|
128
|
-
skipReason?:
|
|
129
|
-
| "below-threshold"
|
|
130
|
-
| "recent"
|
|
131
|
-
| "empty-corpus"
|
|
132
|
-
| "missing-style-card"
|
|
133
|
-
| "no-format-tagged-content"
|
|
134
|
-
| "amend-no-eligible-documents";
|
|
135
|
-
errorReason?: string;
|
|
136
|
-
/** Present when `mode='sample'` or `mode='amend'`: corpus exemplars for the agent to read. */
|
|
137
|
-
exemplars?: VoiceCorpusExemplar[];
|
|
138
|
-
/** Present when `mode='sample'` or `mode='amend'`: operator-edit intents to fold into the style card. */
|
|
139
|
-
feedbackIntents?: string[];
|
|
140
|
-
/**
|
|
141
|
-
* Present when `mode='amend'`: the current `:VoiceProfile.styleCard` (or
|
|
142
|
-
* null if no profile exists yet) so the agent can compare the named
|
|
143
|
-
* documents against the prior card and decide update-or-skip.
|
|
144
|
-
*/
|
|
145
|
-
existingStyleCard?: string | null;
|
|
146
|
-
/** Present when `mode='amend'`: count of input nodeIds that passed eligibility. */
|
|
147
|
-
eligible?: number;
|
|
148
|
-
/**
|
|
149
|
-
* Present when `mode='amend'`: per-input-id ineligibility records. Each
|
|
150
|
-
* entry names the nodeId and the first failing predicate so the agent
|
|
151
|
-
* can tell the operator which documents were rejected and why.
|
|
152
|
-
*/
|
|
153
|
-
ineligible?: { nodeId: string; reason: string }[];
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
// The agent produces a YAML style card with at minimum these keys:
|
|
157
|
-
// sentenceLengthDistribution, register, favoured, avoided, taboos,
|
|
158
|
-
// openingPattern, closingPattern, exemplarSentences
|
|
159
|
-
// Exemplar sentences should be quoted verbatim from the returned corpus.
|
|
160
|
-
|
|
161
|
-
/**
|
|
162
|
-
* Single-format distil. Opens a new session for each call.
|
|
163
|
-
*/
|
|
164
|
-
async function distilForFormat(
|
|
165
|
-
params: Required<Pick<VoiceDistilProfileParams, "accountId" | "userId">> &
|
|
166
|
-
Pick<VoiceDistilProfileParams, "force" | "mode" | "styleCardYaml" | "scope"> & {
|
|
167
|
-
format: VoiceFormat;
|
|
168
|
-
},
|
|
169
|
-
): Promise<VoiceDistilProfileResult> {
|
|
170
|
-
const { accountId, userId, format, force = false } = params;
|
|
171
|
-
const scope: VoiceScope = params.scope ?? "personal";
|
|
172
|
-
const profileUserId = profileUserIdForScope(scope, userId);
|
|
173
|
-
const anchorLabel = scope === "org" ? "LocalBusiness" : "AdminUser";
|
|
174
|
-
// Org walks the whole account; personal narrows to one author's content.
|
|
175
|
-
const corpusWhere =
|
|
176
|
-
scope === "org"
|
|
177
|
-
? voiceCorpusWhereWithFormat(format)
|
|
178
|
-
: voiceCorpusWhereWithFormatAndAuthor(format);
|
|
179
|
-
const corpusParams =
|
|
180
|
-
scope === "org"
|
|
181
|
-
? { accountId, format }
|
|
182
|
-
: { accountId, format, voiceAuthor: userId };
|
|
183
|
-
const session = getSession();
|
|
184
|
-
const now = new Date();
|
|
185
|
-
const nowIso = now.toISOString();
|
|
186
|
-
|
|
187
|
-
try {
|
|
188
|
-
// 1. Read existing scoped profile (if any) for cadence-guard comparison.
|
|
189
|
-
// Key-only match — the (accountId, profileUserId, format) triple is the
|
|
190
|
-
// unique constraint key, so no anchor traversal is needed on the read.
|
|
191
|
-
const existing = await session.run(
|
|
192
|
-
`OPTIONAL MATCH (p:VoiceProfile {accountId: $accountId, userId: $profileUserId, format: $format})
|
|
193
|
-
RETURN elementId(p) AS profileId, p.corpusSize AS corpusSize,
|
|
194
|
-
p.generatedAt AS generatedAt`,
|
|
195
|
-
{ accountId, profileUserId, format },
|
|
196
|
-
);
|
|
197
|
-
const existingRow = existing.records[0];
|
|
198
|
-
const prevProfileId = (existingRow?.get("profileId") as string | null) ?? null;
|
|
199
|
-
const prevCorpusSize = toJsNumber(existingRow?.get("corpusSize"));
|
|
200
|
-
const prevGeneratedAt = (existingRow?.get("generatedAt") as string | null) ?? null;
|
|
201
|
-
|
|
202
|
-
// 2. Count corpus for this scope + format.
|
|
203
|
-
const countResult = await session.run(
|
|
204
|
-
`MATCH (n)
|
|
205
|
-
WHERE ${corpusWhere}
|
|
206
|
-
RETURN count(n) AS c`,
|
|
207
|
-
corpusParams,
|
|
208
|
-
);
|
|
209
|
-
const corpusSize = toJsNumber(countResult.records[0]?.get("c")) ?? 0;
|
|
210
|
-
|
|
211
|
-
if (corpusSize === 0) {
|
|
212
|
-
process.stderr.write(
|
|
213
|
-
`[voice-distil] scope=${scope} userId=${profileUserId} format=${format} skip reason=empty-corpus\n`,
|
|
214
|
-
);
|
|
215
|
-
return {
|
|
216
|
-
profileId: prevProfileId,
|
|
217
|
-
corpusSize: 0,
|
|
218
|
-
generatedAt: prevGeneratedAt,
|
|
219
|
-
feedbackEntries: 0,
|
|
220
|
-
skipped: true,
|
|
221
|
-
skipReason: "empty-corpus",
|
|
222
|
-
};
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
// 3. Cadence guard.
|
|
226
|
-
if (!force && prevProfileId && prevCorpusSize !== null && prevGeneratedAt) {
|
|
227
|
-
const ageMs = now.getTime() - new Date(prevGeneratedAt).getTime();
|
|
228
|
-
const ageDays = ageMs / (24 * 60 * 60 * 1000);
|
|
229
|
-
const growth =
|
|
230
|
-
prevCorpusSize > 0
|
|
231
|
-
? (corpusSize - prevCorpusSize) / prevCorpusSize
|
|
232
|
-
: 1;
|
|
233
|
-
const ageTrigger = ageDays >= RE_RUN_AGE_DAYS;
|
|
234
|
-
const growthTrigger = growth >= RE_RUN_GROWTH_FRACTION;
|
|
235
|
-
if (!ageTrigger && !growthTrigger) {
|
|
236
|
-
const reason = ageDays < 1 ? "recent" : "below-threshold";
|
|
237
|
-
process.stderr.write(
|
|
238
|
-
`[voice-distil] scope=${scope} userId=${profileUserId} format=${format} skip reason=${reason} corpusSize=${corpusSize} prevCorpus=${prevCorpusSize} ageDays=${ageDays.toFixed(1)}\n`,
|
|
239
|
-
);
|
|
240
|
-
return {
|
|
241
|
-
profileId: prevProfileId,
|
|
242
|
-
corpusSize,
|
|
243
|
-
generatedAt: prevGeneratedAt,
|
|
244
|
-
feedbackEntries: 0,
|
|
245
|
-
skipped: true,
|
|
246
|
-
skipReason: reason,
|
|
247
|
-
};
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
// 4. Sample corpus bodies up to the char cap. Pick recent first.
|
|
252
|
-
//
|
|
253
|
-
// Body resolution (Task 471):
|
|
254
|
-
// - For a :KnowledgeDocument with HAS_SECTION children, concatenate
|
|
255
|
-
// child :Section bodies in `position` order — KD.body itself is
|
|
256
|
-
// null after the Task 465 server-slicing change.
|
|
257
|
-
// - Other labels (:Message, :SocialPost, :Section chat chunks) read
|
|
258
|
-
// n.body directly via the existing COALESCE fallback chain.
|
|
259
|
-
//
|
|
260
|
-
// `collect(s.body)` is null-skipping in Cypher, so KDs with no children
|
|
261
|
-
// produce sectionBodies = [] and fall through to the COALESCE branch
|
|
262
|
-
// correctly. The `usedSectionWalk` flag is returned for per-exemplar
|
|
263
|
-
// observability.
|
|
264
|
-
const sampled = await session.run(
|
|
265
|
-
`MATCH (n)
|
|
266
|
-
WHERE ${corpusWhere}
|
|
267
|
-
WITH n, coalesce(n.dateSent, n.datePublished, n.firstMessageAt, n.dateCreated, n.createdAt) AS ts
|
|
268
|
-
OPTIONAL MATCH (parent:KnowledgeDocument)-[:HAS_SECTION]->(n)
|
|
269
|
-
WHERE 'Section' IN labels(n) AND parent.conversationIdentity IS NOT NULL
|
|
270
|
-
AND ${notTrashed("parent")}
|
|
271
|
-
WITH n, ts, parent
|
|
272
|
-
OPTIONAL MATCH (n)-[:HAS_SECTION]->(s:Section)
|
|
273
|
-
WHERE ${notTrashed("s")}
|
|
274
|
-
WITH n, ts, parent, s ORDER BY s.position
|
|
275
|
-
WITH n, ts, parent, collect(s.body) AS sectionBodies
|
|
276
|
-
WITH n, ts, parent,
|
|
277
|
-
'KnowledgeDocument' IN labels(n) AND size(sectionBodies) > 0 AS usedSectionWalk,
|
|
278
|
-
CASE
|
|
279
|
-
WHEN 'KnowledgeDocument' IN labels(n) AND size(sectionBodies) > 0
|
|
280
|
-
THEN reduce(acc = '', b IN sectionBodies | acc + b + '\n\n')
|
|
281
|
-
ELSE coalesce(n.body, n.abstract, n.subject, n.title, n.summary, '')
|
|
282
|
-
END AS body
|
|
283
|
-
RETURN elementId(n) AS id,
|
|
284
|
-
labels(n) AS labels,
|
|
285
|
-
body,
|
|
286
|
-
usedSectionWalk,
|
|
287
|
-
parent.conversationIdentity IS NOT NULL AS isConversationChunk,
|
|
288
|
-
ts
|
|
289
|
-
ORDER BY ts IS NULL, ts DESC
|
|
290
|
-
LIMIT 500`,
|
|
291
|
-
corpusParams,
|
|
292
|
-
);
|
|
293
|
-
const samples: { id: string; label: string; body: string }[] = [];
|
|
294
|
-
let sectionWalkCount = 0;
|
|
295
|
-
let nBodyCount = 0;
|
|
296
|
-
let charBudget = SAMPLE_CHAR_CAP;
|
|
297
|
-
for (const r of sampled.records) {
|
|
298
|
-
const body = (r.get("body") as string | null) ?? "";
|
|
299
|
-
const labels = (r.get("labels") as string[]) ?? [];
|
|
300
|
-
const isConversationChunk = Boolean(r.get("isConversationChunk"));
|
|
301
|
-
const usedSectionWalk = Boolean(r.get("usedSectionWalk"));
|
|
302
|
-
const label = isConversationChunk
|
|
303
|
-
? "Conversation"
|
|
304
|
-
: (labels.find((l) =>
|
|
305
|
-
["KnowledgeDocument", "Message", "SocialPost"].includes(l),
|
|
306
|
-
) ?? labels[0] ?? "Unknown");
|
|
307
|
-
if (body.length === 0) continue;
|
|
308
|
-
const trimmed = body.length > charBudget ? body.slice(0, charBudget) : body;
|
|
309
|
-
samples.push({ id: r.get("id") as string, label, body: trimmed });
|
|
310
|
-
if (usedSectionWalk) sectionWalkCount += 1;
|
|
311
|
-
else nBodyCount += 1;
|
|
312
|
-
charBudget -= trimmed.length;
|
|
313
|
-
if (charBudget <= 0) break;
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
// 5. Pull feedback intents from existing :VoiceEdit nodes for this scope +
|
|
317
|
-
// format. Keyed by profileUserId: org edits live under the sentinel, so
|
|
318
|
-
// org distil reads org feedback and personal distil reads only this
|
|
319
|
-
// operator's edits — no extra scope predicate needed.
|
|
320
|
-
const feedback = await session.run(
|
|
321
|
-
`MATCH (e:VoiceEdit {userId: $profileUserId, accountId: $accountId, format: $format})
|
|
322
|
-
RETURN e.intent AS intent ORDER BY e.occurredAt DESC LIMIT 50`,
|
|
323
|
-
{ accountId, profileUserId, format },
|
|
324
|
-
);
|
|
325
|
-
const feedbackIntents = feedback.records
|
|
326
|
-
.map((r) => r.get("intent") as string | null)
|
|
327
|
-
.filter((x): x is string => typeof x === "string" && x.length > 0);
|
|
328
|
-
|
|
329
|
-
// 6. Mode branch (Task 424).
|
|
330
|
-
const mode = params.mode ?? "sample";
|
|
331
|
-
if (mode === "sample") {
|
|
332
|
-
process.stderr.write(
|
|
333
|
-
`[voice-distil] scope=${scope} userId=${profileUserId} format=${format} mode=sample corpusSize=${corpusSize} ` +
|
|
334
|
-
`exemplars=${samples.length} feedbackEntries=${feedbackIntents.length} ` +
|
|
335
|
-
`sample-body-source=section-walk:${sectionWalkCount} n.body:${nBodyCount}\n`,
|
|
336
|
-
);
|
|
337
|
-
return {
|
|
338
|
-
profileId: prevProfileId,
|
|
339
|
-
corpusSize,
|
|
340
|
-
generatedAt: prevGeneratedAt,
|
|
341
|
-
feedbackEntries: feedbackIntents.length,
|
|
342
|
-
skipped: true,
|
|
343
|
-
skipReason: "missing-style-card",
|
|
344
|
-
exemplars: samples,
|
|
345
|
-
feedbackIntents,
|
|
346
|
-
};
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
const styleCardYaml = (params.styleCardYaml ?? "").trim();
|
|
350
|
-
if (!styleCardYaml) {
|
|
351
|
-
throw new Error(
|
|
352
|
-
"voice-distil-profile: mode='write' requires styleCardYaml (the YAML you composed from the sample-mode response).",
|
|
353
|
-
);
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
// 7. Write the :VoiceProfile node — keyed on (accountId, profileUserId,
|
|
357
|
-
// format) — anchored on :AdminUser (personal) or :LocalBusiness (org),
|
|
358
|
-
// plus LEARNED_FROM edges to every sampled node. `scope` is SET after the
|
|
359
|
-
// MERGE (never inside the pattern) so a legacy scope-less personal
|
|
360
|
-
// profile is matched and backfilled rather than duplicated.
|
|
361
|
-
const anchorMatch =
|
|
362
|
-
scope === "org"
|
|
363
|
-
? `MATCH (anchor:LocalBusiness {accountId: $accountId})`
|
|
364
|
-
: `MATCH (anchor:AdminUser {accountId: $accountId, userId: $profileUserId})`;
|
|
365
|
-
// Two-step MERGE: the profile node is MERGEd by its unique key alone, then
|
|
366
|
-
// the anchor edge is MERGEd separately. MERGEing the node through the anchor
|
|
367
|
-
// pattern would create a duplicate (constraint error) if the node existed
|
|
368
|
-
// but its anchor edge did not. Keying the node first mirrors the key-only
|
|
369
|
-
// reads and keeps the legacy scope-less backfill matching by key.
|
|
370
|
-
const writeResult = await session.run(
|
|
371
|
-
`${anchorMatch}
|
|
372
|
-
MERGE (p:VoiceProfile {accountId: $accountId, userId: $profileUserId, format: $format})
|
|
373
|
-
ON CREATE SET p.createdAt = $now
|
|
374
|
-
MERGE (anchor)-[:HAS_VOICE_PROFILE]->(p)
|
|
375
|
-
SET p.scope = $scope,
|
|
376
|
-
p.styleCard = $styleCard,
|
|
377
|
-
p.generatedAt = $now,
|
|
378
|
-
p.corpusSize = $corpusSize,
|
|
379
|
-
p.feedbackEntries = $feedbackEntries,
|
|
380
|
-
p.updatedAt = $now
|
|
381
|
-
WITH p
|
|
382
|
-
UNWIND $sampleIds AS sid
|
|
383
|
-
MATCH (s) WHERE elementId(s) = sid
|
|
384
|
-
MERGE (p)-[:LEARNED_FROM]->(s)
|
|
385
|
-
RETURN elementId(p) AS profileId`,
|
|
386
|
-
{
|
|
387
|
-
accountId,
|
|
388
|
-
profileUserId,
|
|
389
|
-
format,
|
|
390
|
-
scope,
|
|
391
|
-
styleCard: styleCardYaml,
|
|
392
|
-
now: nowIso,
|
|
393
|
-
corpusSize,
|
|
394
|
-
feedbackEntries: feedbackIntents.length,
|
|
395
|
-
sampleIds: samples.map((s) => s.id),
|
|
396
|
-
},
|
|
397
|
-
);
|
|
398
|
-
if (writeResult.records.length === 0) {
|
|
399
|
-
throw new Error(
|
|
400
|
-
scope === "org"
|
|
401
|
-
? `voice-mirror: :LocalBusiness {accountId='${accountId}'} not found. The account org node must exist before an org distil (created at onboarding alongside :AdminUser).`
|
|
402
|
-
: `voice-mirror: :AdminUser {accountId='${accountId}', userId='${userId}'} not found. Onboarding must promote the operator to :AdminUser before distillation.`,
|
|
403
|
-
);
|
|
404
|
-
}
|
|
405
|
-
const profileId = writeResult.records[0].get("profileId") as string;
|
|
406
|
-
|
|
407
|
-
process.stderr.write(
|
|
408
|
-
`[voice-distil] scope=${scope} userId=${profileUserId} anchor=${anchorLabel} format=${format} corpusSize=${corpusSize} generatedAt=${nowIso} feedbackEntries=${feedbackIntents.length}${scope === "org" ? " sentinel=__org__" : ""}\n`,
|
|
409
|
-
);
|
|
410
|
-
|
|
411
|
-
return {
|
|
412
|
-
profileId,
|
|
413
|
-
corpusSize,
|
|
414
|
-
generatedAt: nowIso,
|
|
415
|
-
feedbackEntries: feedbackIntents.length,
|
|
416
|
-
skipped: false,
|
|
417
|
-
};
|
|
418
|
-
} finally {
|
|
419
|
-
await session.close();
|
|
420
|
-
}
|
|
421
|
-
}
|
|
422
|
-
|
|
423
|
-
/**
|
|
424
|
-
* Single-document amend (Task 472).
|
|
425
|
-
*
|
|
426
|
-
* Operator-initiated incremental update: the operator names one or more
|
|
427
|
-
* documents (`nodeIds`), the tool reads only those plus the existing
|
|
428
|
-
* `:VoiceProfile.styleCard` for the format, and the calling agent decides
|
|
429
|
-
* whether the documents move the profile or don't. Same body-resolution
|
|
430
|
-
* and trashed/authorshipMode/label predicates as the full-corpus sample;
|
|
431
|
-
* the corpus-wide format predicate is dropped (the operator picked the
|
|
432
|
-
* docs); the cadence guard does not apply.
|
|
433
|
-
*/
|
|
434
|
-
async function amendForFormat(params: {
|
|
435
|
-
accountId: string;
|
|
436
|
-
userId: string;
|
|
437
|
-
format: VoiceFormat;
|
|
438
|
-
nodeIds: string[];
|
|
439
|
-
scope?: VoiceScope;
|
|
440
|
-
}): Promise<VoiceDistilProfileResult> {
|
|
441
|
-
const { accountId, userId, format, nodeIds } = params;
|
|
442
|
-
const scope: VoiceScope = params.scope ?? "personal";
|
|
443
|
-
const profileUserId = profileUserIdForScope(scope, userId);
|
|
444
|
-
const session = getSession();
|
|
445
|
-
|
|
446
|
-
try {
|
|
447
|
-
// 1. Existing scoped profile (may be absent — first-time amend, no prior
|
|
448
|
-
// card). Key-only match on the unique (accountId, profileUserId, format).
|
|
449
|
-
const profileRow = await session.run(
|
|
450
|
-
`OPTIONAL MATCH (p:VoiceProfile {accountId: $accountId, userId: $profileUserId, format: $format})
|
|
451
|
-
RETURN elementId(p) AS profileId,
|
|
452
|
-
p.styleCard AS styleCard,
|
|
453
|
-
p.corpusSize AS corpusSize,
|
|
454
|
-
p.generatedAt AS generatedAt`,
|
|
455
|
-
{ accountId, profileUserId, format },
|
|
456
|
-
);
|
|
457
|
-
const prow = profileRow.records[0];
|
|
458
|
-
const prevProfileId = (prow?.get("profileId") as string | null) ?? null;
|
|
459
|
-
const existingStyleCard = (prow?.get("styleCard") as string | null) ?? null;
|
|
460
|
-
const prevCorpusSize = toJsNumber(prow?.get("corpusSize")) ?? 0;
|
|
461
|
-
const prevGeneratedAt = (prow?.get("generatedAt") as string | null) ?? null;
|
|
462
|
-
|
|
463
|
-
// 2. Per-document eligibility classification. Each input id gets a
|
|
464
|
-
// verdict; the first failing predicate wins. The predicate set mirrors
|
|
465
|
-
// VOICE_CORPUS_WHERE except `format` is dropped (operator picked the
|
|
466
|
-
// docs) and conversation-section sub-pattern is inlined for the
|
|
467
|
-
// per-document case.
|
|
468
|
-
const eligibilityResult = await session.run(
|
|
469
|
-
`UNWIND $nodeIds AS nid
|
|
470
|
-
OPTIONAL MATCH (n) WHERE elementId(n) = nid
|
|
471
|
-
WITH nid, n,
|
|
472
|
-
CASE
|
|
473
|
-
WHEN n IS NULL THEN 'node-not-found'
|
|
474
|
-
WHEN n.accountId <> $accountId THEN 'wrong-account'
|
|
475
|
-
WHEN NOT coalesce(n.authorshipMode, '') IN ['human-only', 'human-led-agent-assisted']
|
|
476
|
-
THEN 'ineligible-authorship-mode'
|
|
477
|
-
WHEN n:Trashed OR n.deletedAt IS NOT NULL THEN 'trashed'
|
|
478
|
-
WHEN NOT (
|
|
479
|
-
any(lbl IN labels(n) WHERE lbl IN ['KnowledgeDocument', 'Message', 'SocialPost'])
|
|
480
|
-
OR ('Section' IN labels(n) AND EXISTS {
|
|
481
|
-
MATCH (parent:KnowledgeDocument)-[:HAS_SECTION]->(n)
|
|
482
|
-
WHERE parent.conversationIdentity IS NOT NULL
|
|
483
|
-
AND ${notTrashed("parent")}
|
|
484
|
-
})
|
|
485
|
-
) THEN 'ineligible-label'
|
|
486
|
-
ELSE 'ok'
|
|
487
|
-
END AS verdict
|
|
488
|
-
RETURN nid, verdict`,
|
|
489
|
-
{ accountId, nodeIds },
|
|
490
|
-
);
|
|
491
|
-
|
|
492
|
-
const eligibleIds: string[] = [];
|
|
493
|
-
const ineligible: { nodeId: string; reason: string }[] = [];
|
|
494
|
-
for (const r of eligibilityResult.records) {
|
|
495
|
-
const nid = r.get("nid") as string;
|
|
496
|
-
const verdict = r.get("verdict") as string;
|
|
497
|
-
if (verdict === "ok") eligibleIds.push(nid);
|
|
498
|
-
else ineligible.push({ nodeId: nid, reason: verdict });
|
|
499
|
-
}
|
|
500
|
-
|
|
501
|
-
// 3. Feedback intents (same as sample) — agent benefits even on a no-op
|
|
502
|
-
// amend ("you've already corrected this voice tic ten times"). Keyed by
|
|
503
|
-
// profileUserId so org amends read org feedback.
|
|
504
|
-
const feedback = await session.run(
|
|
505
|
-
`MATCH (e:VoiceEdit {userId: $profileUserId, accountId: $accountId, format: $format})
|
|
506
|
-
RETURN e.intent AS intent ORDER BY e.occurredAt DESC LIMIT 50`,
|
|
507
|
-
{ accountId, profileUserId, format },
|
|
508
|
-
);
|
|
509
|
-
const feedbackIntents = feedback.records
|
|
510
|
-
.map((r) => r.get("intent") as string | null)
|
|
511
|
-
.filter((x): x is string => typeof x === "string" && x.length > 0);
|
|
512
|
-
|
|
513
|
-
if (eligibleIds.length === 0) {
|
|
514
|
-
process.stderr.write(
|
|
515
|
-
`[voice-distil] scope=${scope} mode=amend userId=${profileUserId} format=${format} nodeIds=${nodeIds.length} ` +
|
|
516
|
-
`existingProfile=${prevProfileId ?? "none"} eligible=0 ineligible=${ineligible.length}\n`,
|
|
517
|
-
);
|
|
518
|
-
return {
|
|
519
|
-
profileId: prevProfileId,
|
|
520
|
-
corpusSize: prevCorpusSize,
|
|
521
|
-
generatedAt: prevGeneratedAt,
|
|
522
|
-
feedbackEntries: feedbackIntents.length,
|
|
523
|
-
skipped: true,
|
|
524
|
-
skipReason: "amend-no-eligible-documents",
|
|
525
|
-
existingStyleCard,
|
|
526
|
-
eligible: 0,
|
|
527
|
-
ineligible,
|
|
528
|
-
exemplars: [],
|
|
529
|
-
feedbackIntents,
|
|
530
|
-
};
|
|
531
|
-
}
|
|
532
|
-
|
|
533
|
-
// 4. Body walk for eligible ids — identical body resolution to the
|
|
534
|
-
// full-corpus sample path: KD-with-Section-children concatenates child
|
|
535
|
-
// bodies in `position` order (trashed sections filtered); other labels
|
|
536
|
-
// fall through to the COALESCE chain.
|
|
537
|
-
const bodyResult = await session.run(
|
|
538
|
-
`UNWIND $eligibleIds AS nid
|
|
539
|
-
MATCH (n) WHERE elementId(n) = nid
|
|
540
|
-
OPTIONAL MATCH (parent:KnowledgeDocument)-[:HAS_SECTION]->(n)
|
|
541
|
-
WHERE 'Section' IN labels(n) AND parent.conversationIdentity IS NOT NULL
|
|
542
|
-
AND ${notTrashed("parent")}
|
|
543
|
-
WITH n, parent
|
|
544
|
-
OPTIONAL MATCH (n)-[:HAS_SECTION]->(s:Section)
|
|
545
|
-
WHERE ${notTrashed("s")}
|
|
546
|
-
WITH n, parent, s ORDER BY s.position
|
|
547
|
-
WITH n, parent, collect(s.body) AS sectionBodies
|
|
548
|
-
WITH n, parent,
|
|
549
|
-
'KnowledgeDocument' IN labels(n) AND size(sectionBodies) > 0 AS usedSectionWalk,
|
|
550
|
-
CASE
|
|
551
|
-
WHEN 'KnowledgeDocument' IN labels(n) AND size(sectionBodies) > 0
|
|
552
|
-
THEN reduce(acc = '', b IN sectionBodies | acc + b + '\n\n')
|
|
553
|
-
ELSE coalesce(n.body, n.abstract, n.subject, n.title, n.summary, '')
|
|
554
|
-
END AS body
|
|
555
|
-
RETURN elementId(n) AS id,
|
|
556
|
-
labels(n) AS labels,
|
|
557
|
-
body,
|
|
558
|
-
usedSectionWalk,
|
|
559
|
-
parent.conversationIdentity IS NOT NULL AS isConversationChunk`,
|
|
560
|
-
{ eligibleIds },
|
|
561
|
-
);
|
|
562
|
-
|
|
563
|
-
const exemplars: VoiceCorpusExemplar[] = [];
|
|
564
|
-
let charBudget = SAMPLE_CHAR_CAP;
|
|
565
|
-
let sectionWalkCount = 0;
|
|
566
|
-
let nBodyCount = 0;
|
|
567
|
-
for (const r of bodyResult.records) {
|
|
568
|
-
const body = (r.get("body") as string | null) ?? "";
|
|
569
|
-
if (body.length === 0) continue;
|
|
570
|
-
const labels = (r.get("labels") as string[]) ?? [];
|
|
571
|
-
const isConversationChunk = Boolean(r.get("isConversationChunk"));
|
|
572
|
-
const usedSectionWalk = Boolean(r.get("usedSectionWalk"));
|
|
573
|
-
const label = isConversationChunk
|
|
574
|
-
? "Conversation"
|
|
575
|
-
: (labels.find((l) =>
|
|
576
|
-
["KnowledgeDocument", "Message", "SocialPost"].includes(l),
|
|
577
|
-
) ?? labels[0] ?? "Unknown");
|
|
578
|
-
const trimmed = body.length > charBudget ? body.slice(0, charBudget) : body;
|
|
579
|
-
exemplars.push({ id: r.get("id") as string, label, body: trimmed });
|
|
580
|
-
if (usedSectionWalk) sectionWalkCount += 1;
|
|
581
|
-
else nBodyCount += 1;
|
|
582
|
-
charBudget -= trimmed.length;
|
|
583
|
-
if (charBudget <= 0) break;
|
|
584
|
-
}
|
|
585
|
-
|
|
586
|
-
process.stderr.write(
|
|
587
|
-
`[voice-distil] scope=${scope} mode=amend userId=${profileUserId} format=${format} nodeIds=${nodeIds.length} ` +
|
|
588
|
-
`existingProfile=${prevProfileId ?? "none"} eligible=${eligibleIds.length} ineligible=${ineligible.length} ` +
|
|
589
|
-
`exemplars=${exemplars.length} sample-body-source=section-walk:${sectionWalkCount} n.body:${nBodyCount}\n`,
|
|
590
|
-
);
|
|
591
|
-
|
|
592
|
-
// `skipped: false` because the function DID deliver value — exemplars
|
|
593
|
-
// + existingStyleCard for the agent to act on. The agent decides
|
|
594
|
-
// whether to compose new YAML (calls `mode='write'`) or replies "no
|
|
595
|
-
// material delta"; either is a valid amend outcome, neither is a
|
|
596
|
-
// "skip" in the cadence-guard sense.
|
|
597
|
-
return {
|
|
598
|
-
profileId: prevProfileId,
|
|
599
|
-
corpusSize: prevCorpusSize,
|
|
600
|
-
generatedAt: prevGeneratedAt,
|
|
601
|
-
feedbackEntries: feedbackIntents.length,
|
|
602
|
-
skipped: false,
|
|
603
|
-
existingStyleCard,
|
|
604
|
-
eligible: eligibleIds.length,
|
|
605
|
-
ineligible,
|
|
606
|
-
exemplars,
|
|
607
|
-
feedbackIntents,
|
|
608
|
-
};
|
|
609
|
-
} finally {
|
|
610
|
-
await session.close();
|
|
611
|
-
}
|
|
612
|
-
}
|
|
613
|
-
|
|
614
|
-
/**
|
|
615
|
-
* Amend write (Task 472). Persists the agent-composed style card after an
|
|
616
|
-
* `amend` sample. Bypasses the cadence guard and the full corpus walk; the
|
|
617
|
-
* only `LEARNED_FROM` edges added are to `amendedFromNodeIds`. Pre-existing
|
|
618
|
-
* `LEARNED_FROM` edges remain via `MERGE`. `corpusSize` on the profile is
|
|
619
|
-
* untouched — the amend doesn't change the operator's qualifying corpus,
|
|
620
|
-
* only the styleCard's interpretation of it.
|
|
621
|
-
*/
|
|
622
|
-
async function amendWriteForFormat(params: {
|
|
623
|
-
accountId: string;
|
|
624
|
-
userId: string;
|
|
625
|
-
format: VoiceFormat;
|
|
626
|
-
styleCardYaml: string;
|
|
627
|
-
amendedFromNodeIds: string[];
|
|
628
|
-
scope?: VoiceScope;
|
|
629
|
-
}): Promise<VoiceDistilProfileResult> {
|
|
630
|
-
const { accountId, userId, format, styleCardYaml, amendedFromNodeIds } = params;
|
|
631
|
-
const scope: VoiceScope = params.scope ?? "personal";
|
|
632
|
-
const profileUserId = profileUserIdForScope(scope, userId);
|
|
633
|
-
const anchorLabel = scope === "org" ? "LocalBusiness" : "AdminUser";
|
|
634
|
-
const session = getSession();
|
|
635
|
-
const nowIso = new Date().toISOString();
|
|
636
|
-
try {
|
|
637
|
-
// 1. Pre-resolve the amend ids and refuse if none survive. The write
|
|
638
|
-
// Cypher SETs `p` before the UNWIND/MATCH on amend ids, so if every
|
|
639
|
-
// id is stale the profile would be mutated then the function would
|
|
640
|
-
// throw — leaving a silently advanced styleCard the operator never
|
|
641
|
-
// confirmed. Resolving here means the SET never runs on an empty
|
|
642
|
-
// target list, and stale ids surface as a structured error before
|
|
643
|
-
// any write commits. Code-review pass-1 fix.
|
|
644
|
-
const resolve = await session.run(
|
|
645
|
-
`UNWIND $amendIds AS sid
|
|
646
|
-
MATCH (s) WHERE elementId(s) = sid
|
|
647
|
-
RETURN elementId(s) AS id`,
|
|
648
|
-
{ amendIds: amendedFromNodeIds },
|
|
649
|
-
);
|
|
650
|
-
const resolvedAmendIds = resolve.records.map(
|
|
651
|
-
(r) => r.get("id") as string,
|
|
652
|
-
);
|
|
653
|
-
if (resolvedAmendIds.length === 0) {
|
|
654
|
-
throw new Error(
|
|
655
|
-
`voice-mirror: none of amendedFromNodeIds=${JSON.stringify(amendedFromNodeIds)} ` +
|
|
656
|
-
`resolved to live nodes. Confirm the named docs exist and are accessible.`,
|
|
657
|
-
);
|
|
658
|
-
}
|
|
659
|
-
|
|
660
|
-
const feedback = await session.run(
|
|
661
|
-
`MATCH (e:VoiceEdit {userId: $profileUserId, accountId: $accountId, format: $format})
|
|
662
|
-
RETURN count(e) AS c`,
|
|
663
|
-
{ accountId, profileUserId, format },
|
|
664
|
-
);
|
|
665
|
-
const feedbackEntries = toJsNumber(feedback.records[0]?.get("c")) ?? 0;
|
|
666
|
-
|
|
667
|
-
const anchorMatch =
|
|
668
|
-
scope === "org"
|
|
669
|
-
? `MATCH (anchor:LocalBusiness {accountId: $accountId})`
|
|
670
|
-
: `MATCH (anchor:AdminUser {accountId: $accountId, userId: $profileUserId})`;
|
|
671
|
-
// Two-step MERGE (see distilForFormat): node by unique key, then anchor edge.
|
|
672
|
-
const result = await session.run(
|
|
673
|
-
`${anchorMatch}
|
|
674
|
-
MERGE (p:VoiceProfile {accountId: $accountId, userId: $profileUserId, format: $format})
|
|
675
|
-
ON CREATE SET p.createdAt = $now, p.corpusSize = 0
|
|
676
|
-
MERGE (anchor)-[:HAS_VOICE_PROFILE]->(p)
|
|
677
|
-
SET p.scope = $scope,
|
|
678
|
-
p.styleCard = $styleCard,
|
|
679
|
-
p.generatedAt = $now,
|
|
680
|
-
p.feedbackEntries = $feedbackEntries,
|
|
681
|
-
p.updatedAt = $now
|
|
682
|
-
WITH p
|
|
683
|
-
UNWIND $amendIds AS sid
|
|
684
|
-
MATCH (s) WHERE elementId(s) = sid
|
|
685
|
-
MERGE (p)-[:LEARNED_FROM]->(s)
|
|
686
|
-
WITH p
|
|
687
|
-
RETURN elementId(p) AS profileId, p.corpusSize AS corpusSize`,
|
|
688
|
-
{
|
|
689
|
-
accountId,
|
|
690
|
-
profileUserId,
|
|
691
|
-
format,
|
|
692
|
-
scope,
|
|
693
|
-
styleCard: styleCardYaml,
|
|
694
|
-
now: nowIso,
|
|
695
|
-
feedbackEntries,
|
|
696
|
-
amendIds: resolvedAmendIds,
|
|
697
|
-
},
|
|
698
|
-
);
|
|
699
|
-
if (result.records.length === 0) {
|
|
700
|
-
throw new Error(
|
|
701
|
-
scope === "org"
|
|
702
|
-
? `voice-mirror: :LocalBusiness {accountId='${accountId}'} not found. The account org node must exist before an org amend-write.`
|
|
703
|
-
: `voice-mirror: :AdminUser {accountId='${accountId}', userId='${userId}'} not found. ` +
|
|
704
|
-
`Onboarding must promote the operator to :AdminUser before distillation.`,
|
|
705
|
-
);
|
|
706
|
-
}
|
|
707
|
-
const profileId = result.records[0].get("profileId") as string;
|
|
708
|
-
const corpusSize = toJsNumber(result.records[0].get("corpusSize")) ?? 0;
|
|
709
|
-
|
|
710
|
-
process.stderr.write(
|
|
711
|
-
`[voice-distil] scope=${scope} mode=write userId=${profileUserId} anchor=${anchorLabel} format=${format} amended=true ` +
|
|
712
|
-
`amendedFromNodeIds=${amendedFromNodeIds.length} corpusSize=${corpusSize} ` +
|
|
713
|
-
`generatedAt=${nowIso} feedbackEntries=${feedbackEntries}\n`,
|
|
714
|
-
);
|
|
715
|
-
|
|
716
|
-
return {
|
|
717
|
-
profileId,
|
|
718
|
-
corpusSize,
|
|
719
|
-
generatedAt: nowIso,
|
|
720
|
-
feedbackEntries,
|
|
721
|
-
skipped: false,
|
|
722
|
-
};
|
|
723
|
-
} finally {
|
|
724
|
-
await session.close();
|
|
725
|
-
}
|
|
726
|
-
}
|
|
727
|
-
|
|
728
|
-
export async function voiceDistilProfile(
|
|
729
|
-
params: VoiceDistilProfileParams,
|
|
730
|
-
): Promise<VoiceDistilProfileResult | VoiceDistilProfileResult[]> {
|
|
731
|
-
const { accountId, userId, force = false } = params;
|
|
732
|
-
const scope: VoiceScope = params.scope ?? "personal";
|
|
733
|
-
if (!accountId || !userId) {
|
|
734
|
-
throw new Error("voice-distil-profile: accountId and userId required");
|
|
735
|
-
}
|
|
736
|
-
|
|
737
|
-
// Amend sample (Task 472): operator-initiated single-document update.
|
|
738
|
-
if (params.mode === "amend") {
|
|
739
|
-
if (!params.format) {
|
|
740
|
-
throw new Error("voice-distil-profile: mode='amend' requires format");
|
|
741
|
-
}
|
|
742
|
-
const nodeIds = params.nodeIds ?? [];
|
|
743
|
-
if (nodeIds.length === 0) {
|
|
744
|
-
throw new Error(
|
|
745
|
-
"voice-distil-profile: mode='amend' requires nodeIds (at least one)",
|
|
746
|
-
);
|
|
747
|
-
}
|
|
748
|
-
return amendForFormat({
|
|
749
|
-
accountId,
|
|
750
|
-
userId,
|
|
751
|
-
format: params.format,
|
|
752
|
-
nodeIds,
|
|
753
|
-
scope,
|
|
754
|
-
});
|
|
755
|
-
}
|
|
756
|
-
|
|
757
|
-
// Amend write (Task 472): persist after the agent composed from an amend
|
|
758
|
-
// sample. Triggered by `mode='write'` + non-empty `amendedFromNodeIds`.
|
|
759
|
-
// Distinct from the full-corpus write — bypasses cadence + corpus walk.
|
|
760
|
-
if (
|
|
761
|
-
params.mode === "write" &&
|
|
762
|
-
params.amendedFromNodeIds &&
|
|
763
|
-
params.amendedFromNodeIds.length > 0
|
|
764
|
-
) {
|
|
765
|
-
if (!params.format) {
|
|
766
|
-
throw new Error(
|
|
767
|
-
"voice-distil-profile: mode='write' with amendedFromNodeIds requires format",
|
|
768
|
-
);
|
|
769
|
-
}
|
|
770
|
-
const styleCardYaml = (params.styleCardYaml ?? "").trim();
|
|
771
|
-
if (!styleCardYaml) {
|
|
772
|
-
throw new Error(
|
|
773
|
-
"voice-distil-profile: mode='write' requires styleCardYaml (the YAML you composed from the amend-sample response).",
|
|
774
|
-
);
|
|
775
|
-
}
|
|
776
|
-
return amendWriteForFormat({
|
|
777
|
-
accountId,
|
|
778
|
-
userId,
|
|
779
|
-
format: params.format,
|
|
780
|
-
styleCardYaml,
|
|
781
|
-
amendedFromNodeIds: params.amendedFromNodeIds,
|
|
782
|
-
scope,
|
|
783
|
-
});
|
|
784
|
-
}
|
|
785
|
-
|
|
786
|
-
// Single-format path.
|
|
787
|
-
if (params.format !== undefined) {
|
|
788
|
-
return distilForFormat({ ...params, format: params.format, force });
|
|
789
|
-
}
|
|
790
|
-
|
|
791
|
-
// Multi-format path: enumerate distinct format values present in the corpus.
|
|
792
|
-
// Scope-aware: personal enumerates only the operator's authored content, org
|
|
793
|
-
// enumerates the whole account.
|
|
794
|
-
const session = getSession();
|
|
795
|
-
let formats: VoiceFormat[] = [];
|
|
796
|
-
try {
|
|
797
|
-
const enumResult = await session.run(
|
|
798
|
-
`MATCH (n)
|
|
799
|
-
WHERE ${VOICE_CORPUS_WHERE} AND n.format IS NOT NULL${scope === "personal" ? " AND n.voiceAuthor = $voiceAuthor" : ""}
|
|
800
|
-
RETURN DISTINCT n.format AS fmt`,
|
|
801
|
-
scope === "personal" ? { accountId, voiceAuthor: userId } : { accountId },
|
|
802
|
-
);
|
|
803
|
-
formats = enumResult.records
|
|
804
|
-
.map((r) => r.get("fmt") as string)
|
|
805
|
-
.filter((f): f is VoiceFormat =>
|
|
806
|
-
(FORMAT_VALUES as readonly string[]).includes(f),
|
|
807
|
-
);
|
|
808
|
-
} finally {
|
|
809
|
-
await session.close();
|
|
810
|
-
}
|
|
811
|
-
|
|
812
|
-
if (formats.length === 0) {
|
|
813
|
-
process.stderr.write(
|
|
814
|
-
`[voice-distil] scope=${scope} userId=${profileUserIdForScope(scope, userId)} skip reason=no-format-tagged-content\n`,
|
|
815
|
-
);
|
|
816
|
-
return {
|
|
817
|
-
profileId: null,
|
|
818
|
-
corpusSize: 0,
|
|
819
|
-
generatedAt: null,
|
|
820
|
-
feedbackEntries: 0,
|
|
821
|
-
skipped: true,
|
|
822
|
-
skipReason: "no-format-tagged-content",
|
|
823
|
-
};
|
|
824
|
-
}
|
|
825
|
-
|
|
826
|
-
// Distil each discovered format sequentially.
|
|
827
|
-
const results: VoiceDistilProfileResult[] = [];
|
|
828
|
-
for (const format of formats) {
|
|
829
|
-
const result = await distilForFormat({ ...params, format, force });
|
|
830
|
-
results.push({ ...result, format });
|
|
831
|
-
}
|
|
832
|
-
return results;
|
|
833
|
-
}
|