@things-factory/ai-assistant 10.1.271 → 10.1.272

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. package/client/components/assistant-chat.ts +18 -6
  2. package/client/components/assistant-dock.ts +15 -1
  3. package/client/components/proposal-request.test.ts +12 -1
  4. package/client/utils/addressed-draft.test.ts +31 -0
  5. package/client/utils/assistant-ask.ts +7 -0
  6. package/client/utils/assistant-request-context.ts +10 -0
  7. package/dist-client/components/assistant-chat.d.ts +6 -0
  8. package/dist-client/components/assistant-chat.js +23 -6
  9. package/dist-client/components/assistant-chat.js.map +1 -1
  10. package/dist-client/components/assistant-dock.js +15 -0
  11. package/dist-client/components/assistant-dock.js.map +1 -1
  12. package/dist-client/components/proposal-request.test.js +11 -1
  13. package/dist-client/components/proposal-request.test.js.map +1 -1
  14. package/dist-client/tsconfig.tsbuildinfo +1 -1
  15. package/dist-client/utils/addressed-draft.test.d.ts +1 -0
  16. package/dist-client/utils/addressed-draft.test.js +27 -0
  17. package/dist-client/utils/addressed-draft.test.js.map +1 -0
  18. package/dist-client/utils/assistant-ask.d.ts +10 -0
  19. package/dist-client/utils/assistant-ask.js.map +1 -1
  20. package/dist-client/utils/assistant-request-context.d.ts +12 -0
  21. package/dist-client/utils/assistant-request-context.js +11 -0
  22. package/dist-client/utils/assistant-request-context.js.map +1 -1
  23. package/dist-server/service/assistant-chat-resolver.js +4 -1
  24. package/dist-server/service/assistant-chat-resolver.js.map +1 -1
  25. package/dist-server/service/assistant-mode/index.d.ts +1 -0
  26. package/dist-server/service/assistant-mode/index.js +4 -1
  27. package/dist-server/service/assistant-mode/index.js.map +1 -1
  28. package/dist-server/service/assistant-mode/turn-lines.d.ts +12 -0
  29. package/dist-server/service/assistant-mode/turn-lines.js +38 -0
  30. package/dist-server/service/assistant-mode/turn-lines.js.map +1 -0
  31. package/dist-server/service/chat-message/index.d.ts +1 -0
  32. package/dist-server/service/chat-message/index.js +3 -1
  33. package/dist-server/service/chat-message/index.js.map +1 -1
  34. package/dist-server/service/chat-message/room-turn.d.ts +31 -0
  35. package/dist-server/service/chat-message/room-turn.js +30 -0
  36. package/dist-server/service/chat-message/room-turn.js.map +1 -0
  37. package/dist-server/service/chat-session-participant/mention-invite.d.ts +2 -0
  38. package/dist-server/service/chat-session-participant/mention-invite.js +5 -0
  39. package/dist-server/service/chat-session-participant/mention-invite.js.map +1 -1
  40. package/dist-server/service/chat-session-resolver.d.ts +5 -0
  41. package/dist-server/service/chat-session-resolver.js +55 -2
  42. package/dist-server/service/chat-session-resolver.js.map +1 -1
  43. package/dist-server/service/data-entry/entry-apply.d.ts +2 -0
  44. package/dist-server/service/data-entry/entry-apply.js +1 -1
  45. package/dist-server/service/data-entry/entry-apply.js.map +1 -1
  46. package/dist-server/service/data-entry/entry-resolver.js +2 -1
  47. package/dist-server/service/data-entry/entry-resolver.js.map +1 -1
  48. package/dist-server/service/data-entry/entry-target.d.ts +7 -2
  49. package/dist-server/service/data-entry/entry-target.js.map +1 -1
  50. package/dist-server/service/people/index.d.ts +2 -0
  51. package/dist-server/service/people/index.js +9 -1
  52. package/dist-server/service/people/index.js.map +1 -1
  53. package/dist-server/service/people/person-subject.d.ts +34 -0
  54. package/dist-server/service/people/person-subject.js +89 -0
  55. package/dist-server/service/people/person-subject.js.map +1 -0
  56. package/dist-server/tsconfig.tsbuildinfo +1 -1
  57. package/package.json +3 -3
  58. package/server/service/assistant-chat-resolver.ts +4 -1
  59. package/server/service/assistant-mode/index.ts +1 -0
  60. package/server/service/assistant-mode/open-subject-door.test.ts +7 -2
  61. package/server/service/assistant-mode/turn-lines.ts +43 -0
  62. package/server/service/chat-message/index.ts +1 -0
  63. package/server/service/chat-message/room-turn.ts +42 -0
  64. package/server/service/chat-session-participant/mention-invite.ts +5 -0
  65. package/server/service/chat-session-resolver.ts +49 -2
  66. package/server/service/data-entry/entry-apply.ts +3 -1
  67. package/server/service/data-entry/entry-resolver.ts +2 -1
  68. package/server/service/data-entry/entry-target.ts +5 -2
  69. package/server/service/people/index.ts +2 -0
  70. package/server/service/people/person-subject.test.ts +163 -0
  71. package/server/service/people/person-subject.ts +88 -0
  72. package/test/assistant-request-context.test.ts +1 -1
  73. package/test/open-doors.test.ts +3 -1
  74. package/translations/en.json +2 -0
  75. package/translations/es.json +2 -0
  76. package/translations/ja.json +2 -0
  77. package/translations/ko.json +2 -0
  78. package/translations/ms.json +2 -0
  79. package/translations/zh.json +2 -0
@@ -0,0 +1,34 @@
1
+ import { entersDomainAsAssignee } from '@things-factory/auth-base/dist-server/utils/get-domain-users.js';
2
+ import { type AssistantSubjectDescriber } from '@things-factory/ai-client-base';
3
+ /** The 360 kind of a person - auth-ui's `person`. */
4
+ export declare const PERSON_AXIS = "person";
5
+ /** The confirmation card that hands a question to the person as a to-do - worklist declares it (ADR-0200 decision 3). */
6
+ export declare const PERSON_QUESTION_KEY = "worklist.person-question";
7
+ /** The person a conversation is about, by its anchor - `undefined` when it is about no one. */
8
+ export declare function personOfAnchor(anchorType: string | null | undefined, anchorId: string | null | undefined): string | undefined;
9
+ /**
10
+ * Who sits in a new conversation besides the one starting it - the person it is about, unless that is themself.
11
+ * The conversation is then a group (`visibility`): a private one seats nobody, an open one the whole domain reads.
12
+ */
13
+ export declare function personSeatOf(anchorType: string | null | undefined, anchorId: string | null | undefined, starter: {
14
+ id?: string;
15
+ } | null | undefined): {
16
+ userId: string;
17
+ visibility: 'group';
18
+ } | undefined;
19
+ /** Why this change is refused in a conversation about someone - or nothing when it is not about anyone else. */
20
+ export declare function personRoomRefusal(session: {
21
+ anchorType?: string | null;
22
+ anchorId?: string | null;
23
+ creatorId?: string | null;
24
+ }, change: {
25
+ visibility?: string;
26
+ removing?: string;
27
+ }): 'person-room-group-only' | 'person-room-keeps-person' | undefined;
28
+ /** The words of a refusal above. */
29
+ export declare const PERSON_ROOM_REFUSALS: Record<string, string>;
30
+ /**
31
+ * How a conversation about someone is held - said to the model after the person's name, every turn.
32
+ */
33
+ export declare const PERSON_GUIDANCE: string;
34
+ export declare function personSubjectDescriber(entersDomain?: typeof entersDomainAsAssignee): AssistantSubjectDescriber;
@@ -0,0 +1,89 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PERSON_GUIDANCE = exports.PERSON_ROOM_REFUSALS = exports.PERSON_QUESTION_KEY = exports.PERSON_AXIS = void 0;
4
+ exports.personOfAnchor = personOfAnchor;
5
+ exports.personSeatOf = personSeatOf;
6
+ exports.personRoomRefusal = personRoomRefusal;
7
+ exports.personSubjectDescriber = personSubjectDescriber;
8
+ /*
9
+ * A conversation about a person (ADR-0200). The person 360 anchors its conversation to `subject` · `person:<user id>`
10
+ * (the 360 kind is the axis, as every 360's - record-subject.ts). Three things follow from that anchor, and each is
11
+ * asked here so no door keeps a rule of its own:
12
+ *
13
+ * · the model is told the person's name and how such a conversation is held - their records answer, with where and
14
+ * when each was written; their character, intent, mood and ability are never guessed; nobody speaks as them; what
15
+ * binds them goes to them as a to-do (`guidance`).
16
+ * · the person sits in it. A conversation about someone is a group the person always reads - nothing is asked of
17
+ * their records out of their sight (`personSeatOf`, the doors that open a conversation).
18
+ * · it stays a group with them in it - neither open to the whole domain nor private, and they are not sent out
19
+ * (`personRoomRefusal`).
20
+ *
21
+ * Asking about oneself is an ordinary conversation: nobody else is seated and the rules about speaking for someone do
22
+ * not apply.
23
+ */
24
+ const auth_base_1 = require("@things-factory/auth-base");
25
+ const get_domain_users_js_1 = require("@things-factory/auth-base/dist-server/utils/get-domain-users.js");
26
+ const ai_client_base_1 = require("@things-factory/ai-client-base");
27
+ const shell_1 = require("@things-factory/shell");
28
+ const entry_target_js_1 = require("../data-entry/entry-target.js");
29
+ /** The 360 kind of a person - auth-ui's `person`. */
30
+ exports.PERSON_AXIS = 'person';
31
+ /** The confirmation card that hands a question to the person as a to-do - worklist declares it (ADR-0200 decision 3). */
32
+ exports.PERSON_QUESTION_KEY = 'worklist.person-question';
33
+ /** The person a conversation is about, by its anchor - `undefined` when it is about no one. */
34
+ function personOfAnchor(anchorType, anchorId) {
35
+ if (anchorType !== 'subject' || typeof anchorId !== 'string' || !anchorId.startsWith(`${exports.PERSON_AXIS}:`))
36
+ return undefined;
37
+ return anchorId.slice(exports.PERSON_AXIS.length + 1) || undefined;
38
+ }
39
+ /**
40
+ * Who sits in a new conversation besides the one starting it - the person it is about, unless that is themself.
41
+ * The conversation is then a group (`visibility`): a private one seats nobody, an open one the whole domain reads.
42
+ */
43
+ function personSeatOf(anchorType, anchorId, starter) {
44
+ const userId = personOfAnchor(anchorType, anchorId);
45
+ return userId && userId !== starter?.id ? { userId, visibility: 'group' } : undefined;
46
+ }
47
+ /** Why this change is refused in a conversation about someone - or nothing when it is not about anyone else. */
48
+ function personRoomRefusal(session, change) {
49
+ const userId = personOfAnchor(session.anchorType, session.anchorId);
50
+ if (!userId || userId === session.creatorId)
51
+ return undefined;
52
+ if (change.visibility && change.visibility !== 'group')
53
+ return 'person-room-group-only';
54
+ if (change.removing && change.removing === userId)
55
+ return 'person-room-keeps-person';
56
+ return undefined;
57
+ }
58
+ /** The words of a refusal above. */
59
+ exports.PERSON_ROOM_REFUSALS = {
60
+ 'person-room-group-only': 'a conversation about someone stays a group they read - it cannot be opened to everyone or made private.',
61
+ 'person-room-keeps-person': 'the person this conversation is about always reads it - they cannot be sent out. they can hide it from their own list.'
62
+ };
63
+ /**
64
+ * How a conversation about someone is held - said to the model after the person's name, every turn.
65
+ */
66
+ exports.PERSON_GUIDANCE = [
67
+ 'This conversation is about that person, and they read it. Rules:',
68
+ "- Answer from the records the read tools return about them. Say which record each fact comes from and when it was last changed; when a record is missing or old, say so.",
69
+ '- Never guess their character, intent, mood or ability, never judge their performance, and never speak as them - say "their weekly report says", never "I".',
70
+ `- What would bind them - whether something can be done, a deadline, an agreement, a refusal, their opinion - is theirs to say. Say it needs their confirmation and offer the confirmation card (${(0, entry_target_js_1.entryToolName)(exports.PERSON_QUESTION_KEY)}): the question, what the records already answered, what they must decide, and a draft answer drawn only from their records.`
71
+ ].join('\n');
72
+ function personSubjectDescriber(entersDomain = get_domain_users_js_1.entersDomainAsAssignee) {
73
+ return {
74
+ anchorType: 'subject',
75
+ axis: exports.PERSON_AXIS,
76
+ async describe({ anchorId, domain }) {
77
+ const userId = personOfAnchor('subject', anchorId);
78
+ if (!userId)
79
+ return undefined;
80
+ const user = await (0, shell_1.getRepository)(auth_base_1.User).findOne({ where: { id: userId } });
81
+ if (!user || !(await entersDomain(domain, user)))
82
+ return undefined;
83
+ const name = user.name || user.email || '';
84
+ return name ? { noun: 'person', name, guidance: exports.PERSON_GUIDANCE } : undefined;
85
+ }
86
+ };
87
+ }
88
+ (0, ai_client_base_1.registerAssistantSubject)(personSubjectDescriber());
89
+ //# sourceMappingURL=person-subject.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"person-subject.js","sourceRoot":"","sources":["../../../server/service/people/person-subject.ts"],"names":[],"mappings":";;;AA8BA,wCAGC;AAMD,oCAGC;AAGD,8CASC;AAkBD,wDAaC;AArFD;;;;;;;;;;;;;;;GAeG;AACH,yDAAgD;AAChD,yGAAwG;AACxG,mEAAyG;AACzG,iDAAqD;AAErD,mEAA6D;AAE7D,qDAAqD;AACxC,QAAA,WAAW,GAAG,QAAQ,CAAA;AAEnC,yHAAyH;AAC5G,QAAA,mBAAmB,GAAG,0BAA0B,CAAA;AAE7D,+FAA+F;AAC/F,SAAgB,cAAc,CAAC,UAAqC,EAAE,QAAmC;IACvG,IAAI,UAAU,KAAK,SAAS,IAAI,OAAO,QAAQ,KAAK,QAAQ,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,GAAG,mBAAW,GAAG,CAAC;QAAE,OAAO,SAAS,CAAA;IACzH,OAAO,QAAQ,CAAC,KAAK,CAAC,mBAAW,CAAC,MAAM,GAAG,CAAC,CAAC,IAAI,SAAS,CAAA;AAC5D,CAAC;AAED;;;GAGG;AACH,SAAgB,YAAY,CAAC,UAAqC,EAAE,QAAmC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CAAA;YAClD,IAAI,CAAC,MAAM;gBAAE,OAAO,SAAS,CAAA;YAC7B,MAAM,IAAI,GAAG,MAAM,IAAA,qBAAa,EAAC,gBAAI,CAAC,CAAC,OAAO,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,CAAC,CAAA;YACzE,IAAI,CAAC,IAAI,IAAI,CAAC,CAAC,MAAM,YAAY,CAAC,MAAa,EAAE,IAAI,CAAC,CAAC;gBAAE,OAAO,SAAS,CAAA;YACzE,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,KAAK,IAAI,EAAE,CAAA;YAC1C,OAAO,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,QAAQ,EAAE,uBAAe,EAAE,CAAC,CAAC,CAAC,SAAS,CAAA;QAC/E,CAAC;KACF,CAAA;AACH,CAAC;AAED,IAAA,yCAAwB,EAAC,sBAAsB,EAAE,CAAC,CAAA","sourcesContent":["/*\n * A conversation about a person (ADR-0200). The person 360 anchors its conversation to `subject` · `person:<user id>`\n * (the 360 kind is the axis, as every 360's - record-subject.ts). Three things follow from that anchor, and each is\n * asked here so no door keeps a rule of its own:\n *\n * · the model is told the person's name and how such a conversation is held - their records answer, with where and\n * when each was written; their character, intent, mood and ability are never guessed; nobody speaks as them; what\n * binds them goes to them as a to-do (`guidance`).\n * · the person sits in it. A conversation about someone is a group the person always reads - nothing is asked of\n * their records out of their sight (`personSeatOf`, the doors that open a conversation).\n * · it stays a group with them in it - neither open to the whole domain nor private, and they are not sent out\n * (`personRoomRefusal`).\n *\n * Asking about oneself is an ordinary conversation: nobody else is seated and the rules about speaking for someone do\n * not apply.\n */\nimport { User } from '@things-factory/auth-base'\nimport { entersDomainAsAssignee } from '@things-factory/auth-base/dist-server/utils/get-domain-users.js'\nimport { registerAssistantSubject, type AssistantSubjectDescriber } from '@things-factory/ai-client-base'\nimport { getRepository } from '@things-factory/shell'\n\nimport { entryToolName } from '../data-entry/entry-target.js'\n\n/** The 360 kind of a person - auth-ui's `person`. */\nexport const PERSON_AXIS = 'person'\n\n/** The confirmation card that hands a question to the person as a to-do - worklist declares it (ADR-0200 decision 3). */\nexport const PERSON_QUESTION_KEY = 'worklist.person-question'\n\n/** The person a conversation is about, by its anchor - `undefined` when it is about no one. */\nexport function personOfAnchor(anchorType: string | null | undefined, anchorId: string | null | undefined): string | undefined {\n if (anchorType !== 'subject' || typeof anchorId !== 'string' || !anchorId.startsWith(`${PERSON_AXIS}:`)) return undefined\n return anchorId.slice(PERSON_AXIS.length + 1) || undefined\n}\n\n/**\n * Who sits in a new conversation besides the one starting it - the person it is about, unless that is themself.\n * The conversation is then a group (`visibility`): a private one seats nobody, an open one the whole domain reads.\n */\nexport function personSeatOf(anchorType: string | null | undefined, anchorId: string | null | undefined, starter: { id?: string } | null | undefined): { userId: string; visibility: 'group' } | undefined {\n const userId = personOfAnchor(anchorType, anchorId)\n return userId && userId !== starter?.id ? { userId, visibility: 'group' } : undefined\n}\n\n/** Why this change is refused in a conversation about someone - or nothing when it is not about anyone else. */\nexport function personRoomRefusal(\n session: { anchorType?: string | null; anchorId?: string | null; creatorId?: string | null },\n change: { visibility?: string; removing?: string }\n): 'person-room-group-only' | 'person-room-keeps-person' | undefined {\n const userId = personOfAnchor(session.anchorType, session.anchorId)\n if (!userId || userId === session.creatorId) return undefined\n if (change.visibility && change.visibility !== 'group') return 'person-room-group-only'\n if (change.removing && change.removing === userId) return 'person-room-keeps-person'\n return undefined\n}\n\n/** The words of a refusal above. */\nexport const PERSON_ROOM_REFUSALS: Record<string, string> = {\n 'person-room-group-only': 'a conversation about someone stays a group they read - it cannot be opened to everyone or made private.',\n 'person-room-keeps-person': 'the person this conversation is about always reads it - they cannot be sent out. they can hide it from their own list.'\n}\n\n/**\n * How a conversation about someone is held - said to the model after the person's name, every turn.\n */\nexport const PERSON_GUIDANCE = [\n 'This conversation is about that person, and they read it. Rules:',\n \"- Answer from the records the read tools return about them. Say which record each fact comes from and when it was last changed; when a record is missing or old, say so.\",\n '- Never guess their character, intent, mood or ability, never judge their performance, and never speak as them - say \"their weekly report says\", never \"I\".',\n `- What would bind them - whether something can be done, a deadline, an agreement, a refusal, their opinion - is theirs to say. Say it needs their confirmation and offer the confirmation card (${entryToolName(PERSON_QUESTION_KEY)}): the question, what the records already answered, what they must decide, and a draft answer drawn only from their records.`\n].join('\\n')\n\nexport function personSubjectDescriber(entersDomain = entersDomainAsAssignee): AssistantSubjectDescriber {\n return {\n anchorType: 'subject',\n axis: PERSON_AXIS,\n async describe({ anchorId, domain }) {\n const userId = personOfAnchor('subject', anchorId)\n if (!userId) return undefined\n const user = await getRepository(User).findOne({ where: { id: userId } })\n if (!user || !(await entersDomain(domain as any, user))) return undefined\n const name = user.name || user.email || ''\n return name ? { noun: 'person', name, guidance: PERSON_GUIDANCE } : undefined\n }\n }\n}\n\nregisterAssistantSubject(personSubjectDescriber())\n"]}