@happyvertical/smrt-chat 0.30.0
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/AGENTS.md +35 -0
- package/CLAUDE.md +1 -0
- package/LICENSE +7 -0
- package/README.md +163 -0
- package/dist/__smrt-register__.d.ts +2 -0
- package/dist/__smrt-register__.d.ts.map +1 -0
- package/dist/chunks/ChatService-Dpzc1Pa5.js +2044 -0
- package/dist/chunks/ChatService-Dpzc1Pa5.js.map +1 -0
- package/dist/collections/AgentSessionCollection.d.ts +57 -0
- package/dist/collections/AgentSessionCollection.d.ts.map +1 -0
- package/dist/collections/ChatMessageCollection.d.ts +79 -0
- package/dist/collections/ChatMessageCollection.d.ts.map +1 -0
- package/dist/collections/ChatParticipantCollection.d.ts +26 -0
- package/dist/collections/ChatParticipantCollection.d.ts.map +1 -0
- package/dist/collections/ChatReactionCollection.d.ts +23 -0
- package/dist/collections/ChatReactionCollection.d.ts.map +1 -0
- package/dist/collections/ChatRoomCollection.d.ts +43 -0
- package/dist/collections/ChatRoomCollection.d.ts.map +1 -0
- package/dist/collections/ChatThreadCollection.d.ts +9 -0
- package/dist/collections/ChatThreadCollection.d.ts.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +18 -0
- package/dist/index.js.map +1 -0
- package/dist/internal/agent-runtime.d.ts +16 -0
- package/dist/internal/agent-runtime.d.ts.map +1 -0
- package/dist/internal/agent-runtime.js +5 -0
- package/dist/internal/agent-runtime.js.map +1 -0
- package/dist/manifest.json +2811 -0
- package/dist/models/AgentSession.d.ts +70 -0
- package/dist/models/AgentSession.d.ts.map +1 -0
- package/dist/models/ChatMessage.d.ts +55 -0
- package/dist/models/ChatMessage.d.ts.map +1 -0
- package/dist/models/ChatParticipant.d.ts +32 -0
- package/dist/models/ChatParticipant.d.ts.map +1 -0
- package/dist/models/ChatReaction.d.ts +19 -0
- package/dist/models/ChatReaction.d.ts.map +1 -0
- package/dist/models/ChatRoom.d.ts +44 -0
- package/dist/models/ChatRoom.d.ts.map +1 -0
- package/dist/models/ChatThread.d.ts +24 -0
- package/dist/models/ChatThread.d.ts.map +1 -0
- package/dist/models/index.d.ts +7 -0
- package/dist/models/index.d.ts.map +1 -0
- package/dist/playground.d.ts +2 -0
- package/dist/playground.d.ts.map +1 -0
- package/dist/playground.js +166 -0
- package/dist/playground.js.map +1 -0
- package/dist/services/ChatService.d.ts +390 -0
- package/dist/services/ChatService.d.ts.map +1 -0
- package/dist/services/index.d.ts +2 -0
- package/dist/services/index.d.ts.map +1 -0
- package/dist/smrt-knowledge.json +1507 -0
- package/dist/svelte/components/agent/AgentChat.svelte +542 -0
- package/dist/svelte/components/agent/AgentChat.svelte.d.ts +21 -0
- package/dist/svelte/components/agent/AgentChat.svelte.d.ts.map +1 -0
- package/dist/svelte/components/agent/AgentSelector.svelte +175 -0
- package/dist/svelte/components/agent/AgentSelector.svelte.d.ts +11 -0
- package/dist/svelte/components/agent/AgentSelector.svelte.d.ts.map +1 -0
- package/dist/svelte/components/agent/AgentSessionPanel.svelte +322 -0
- package/dist/svelte/components/agent/AgentSessionPanel.svelte.d.ts +15 -0
- package/dist/svelte/components/agent/AgentSessionPanel.svelte.d.ts.map +1 -0
- package/dist/svelte/components/agent/ToolCallDisplay.svelte +335 -0
- package/dist/svelte/components/agent/ToolCallDisplay.svelte.d.ts +9 -0
- package/dist/svelte/components/agent/ToolCallDisplay.svelte.d.ts.map +1 -0
- package/dist/svelte/components/agent/message-blocks.d.ts +12 -0
- package/dist/svelte/components/agent/message-blocks.d.ts.map +1 -0
- package/dist/svelte/components/agent/message-blocks.js +41 -0
- package/dist/svelte/components/agent/message-blocks.test.js +31 -0
- package/dist/svelte/components/dialogs/RoomCreateDialog.svelte +403 -0
- package/dist/svelte/components/dialogs/RoomCreateDialog.svelte.d.ts +16 -0
- package/dist/svelte/components/dialogs/RoomCreateDialog.svelte.d.ts.map +1 -0
- package/dist/svelte/components/dialogs/SearchMessages.svelte +457 -0
- package/dist/svelte/components/dialogs/SearchMessages.svelte.d.ts +17 -0
- package/dist/svelte/components/dialogs/SearchMessages.svelte.d.ts.map +1 -0
- package/dist/svelte/components/layout/ChatLayout.svelte +150 -0
- package/dist/svelte/components/layout/ChatLayout.svelte.d.ts +18 -0
- package/dist/svelte/components/layout/ChatLayout.svelte.d.ts.map +1 -0
- package/dist/svelte/components/layout/MemberList.svelte +389 -0
- package/dist/svelte/components/layout/MemberList.svelte.d.ts +11 -0
- package/dist/svelte/components/layout/MemberList.svelte.d.ts.map +1 -0
- package/dist/svelte/components/layout/RoomHeader.svelte +241 -0
- package/dist/svelte/components/layout/RoomHeader.svelte.d.ts +15 -0
- package/dist/svelte/components/layout/RoomHeader.svelte.d.ts.map +1 -0
- package/dist/svelte/components/layout/RoomList.svelte +471 -0
- package/dist/svelte/components/layout/RoomList.svelte.d.ts +15 -0
- package/dist/svelte/components/layout/RoomList.svelte.d.ts.map +1 -0
- package/dist/svelte/components/messages/MessageInput.svelte +232 -0
- package/dist/svelte/components/messages/MessageInput.svelte.d.ts +20 -0
- package/dist/svelte/components/messages/MessageInput.svelte.d.ts.map +1 -0
- package/dist/svelte/components/messages/MessageItem.svelte +431 -0
- package/dist/svelte/components/messages/MessageItem.svelte.d.ts +19 -0
- package/dist/svelte/components/messages/MessageItem.svelte.d.ts.map +1 -0
- package/dist/svelte/components/messages/MessageList.svelte +129 -0
- package/dist/svelte/components/messages/MessageList.svelte.d.ts +17 -0
- package/dist/svelte/components/messages/MessageList.svelte.d.ts.map +1 -0
- package/dist/svelte/components/messages/ThreadPanel.svelte +156 -0
- package/dist/svelte/components/messages/ThreadPanel.svelte.d.ts +17 -0
- package/dist/svelte/components/messages/ThreadPanel.svelte.d.ts.map +1 -0
- package/dist/svelte/components/messages/__tests__/MessageInput.test.js +38 -0
- package/dist/svelte/components/shared/Avatar.svelte +30 -0
- package/dist/svelte/components/shared/Avatar.svelte.d.ts +14 -0
- package/dist/svelte/components/shared/Avatar.svelte.d.ts.map +1 -0
- package/dist/svelte/components/shared/FileUpload.svelte +382 -0
- package/dist/svelte/components/shared/FileUpload.svelte.d.ts +14 -0
- package/dist/svelte/components/shared/FileUpload.svelte.d.ts.map +1 -0
- package/dist/svelte/components/shared/LinkPreview.svelte +108 -0
- package/dist/svelte/components/shared/LinkPreview.svelte.d.ts +18 -0
- package/dist/svelte/components/shared/LinkPreview.svelte.d.ts.map +1 -0
- package/dist/svelte/components/shared/MentionAutocomplete.svelte +168 -0
- package/dist/svelte/components/shared/MentionAutocomplete.svelte.d.ts +18 -0
- package/dist/svelte/components/shared/MentionAutocomplete.svelte.d.ts.map +1 -0
- package/dist/svelte/components/shared/MessageBubble.svelte +81 -0
- package/dist/svelte/components/shared/MessageBubble.svelte.d.ts +16 -0
- package/dist/svelte/components/shared/MessageBubble.svelte.d.ts.map +1 -0
- package/dist/svelte/components/shared/ReactionPicker.svelte +103 -0
- package/dist/svelte/components/shared/ReactionPicker.svelte.d.ts +10 -0
- package/dist/svelte/components/shared/ReactionPicker.svelte.d.ts.map +1 -0
- package/dist/svelte/components/shared/ReadReceipts.svelte +127 -0
- package/dist/svelte/components/shared/ReadReceipts.svelte.d.ts +13 -0
- package/dist/svelte/components/shared/ReadReceipts.svelte.d.ts.map +1 -0
- package/dist/svelte/components/shared/TypingIndicator.svelte +90 -0
- package/dist/svelte/components/shared/TypingIndicator.svelte.d.ts +12 -0
- package/dist/svelte/components/shared/TypingIndicator.svelte.d.ts.map +1 -0
- package/dist/svelte/components/shared/UserPresence.svelte +65 -0
- package/dist/svelte/components/shared/UserPresence.svelte.d.ts +13 -0
- package/dist/svelte/components/shared/UserPresence.svelte.d.ts.map +1 -0
- package/dist/svelte/components/shared/__tests__/Avatar.test.js +20 -0
- package/dist/svelte/components/shared/__tests__/LinkPreview.test.js +29 -0
- package/dist/svelte/components/shared/__tests__/MessageBubble.test.js +21 -0
- package/dist/svelte/components/shared/__tests__/ReactionPicker.test.js +35 -0
- package/dist/svelte/components/shared/__tests__/ReadReceipts.test.js +28 -0
- package/dist/svelte/components/shared/__tests__/TypingIndicator.test.js +27 -0
- package/dist/svelte/components/shared/__tests__/UserPresence.test.js +23 -0
- package/dist/svelte/components/tabs/ChatTab.svelte +240 -0
- package/dist/svelte/components/tabs/ChatTab.svelte.d.ts +21 -0
- package/dist/svelte/components/tabs/ChatTab.svelte.d.ts.map +1 -0
- package/dist/svelte/components/tabs/ChatTabList.svelte +158 -0
- package/dist/svelte/components/tabs/ChatTabList.svelte.d.ts +13 -0
- package/dist/svelte/components/tabs/ChatTabList.svelte.d.ts.map +1 -0
- package/dist/svelte/components/tabs/ChatTabs.svelte +88 -0
- package/dist/svelte/components/tabs/ChatTabs.svelte.d.ts +21 -0
- package/dist/svelte/components/tabs/ChatTabs.svelte.d.ts.map +1 -0
- package/dist/svelte/components/tabs/MiniChat.svelte +253 -0
- package/dist/svelte/components/tabs/MiniChat.svelte.d.ts +15 -0
- package/dist/svelte/components/tabs/MiniChat.svelte.d.ts.map +1 -0
- package/dist/svelte/i18n.d.ts +51 -0
- package/dist/svelte/i18n.d.ts.map +1 -0
- package/dist/svelte/i18n.js +72 -0
- package/dist/svelte/i18n.messages.d.ts +50 -0
- package/dist/svelte/i18n.messages.d.ts.map +1 -0
- package/dist/svelte/i18n.messages.js +69 -0
- package/dist/svelte/index.d.ts +48 -0
- package/dist/svelte/index.d.ts.map +1 -0
- package/dist/svelte/index.js +117 -0
- package/dist/svelte/playground.d.ts +171 -0
- package/dist/svelte/playground.d.ts.map +1 -0
- package/dist/svelte/playground.js +161 -0
- package/dist/svelte/types.d.ts +116 -0
- package/dist/svelte/types.d.ts.map +1 -0
- package/dist/svelte/types.js +1 -0
- package/dist/types.d.ts +99 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/ui.d.ts +4 -0
- package/dist/ui.d.ts.map +1 -0
- package/dist/ui.js +92 -0
- package/dist/ui.js.map +1 -0
- package/package.json +95 -0
|
@@ -0,0 +1,390 @@
|
|
|
1
|
+
import { SmrtObjectOptions } from '@happyvertical/smrt-core';
|
|
2
|
+
import { AgentSession } from '../models/AgentSession.js';
|
|
3
|
+
import { ChatMessage } from '../models/ChatMessage.js';
|
|
4
|
+
import { ChatThread } from '../models/ChatThread.js';
|
|
5
|
+
import { ChatMessageType, ChatParticipantRole, ChatRoomStatus, ChatRoomType } from '../types.js';
|
|
6
|
+
/**
|
|
7
|
+
* Parameters for emitting an agent-authored (assistant/tool) message. Used only
|
|
8
|
+
* by the internal {@link sendAgentReply} bridge below — NOT a public surface.
|
|
9
|
+
*/
|
|
10
|
+
export interface AgentReplyParams {
|
|
11
|
+
tenantId: string;
|
|
12
|
+
agentSessionId: string;
|
|
13
|
+
content: string;
|
|
14
|
+
kind?: 'assistant' | 'tool';
|
|
15
|
+
messageType?: ChatMessageType;
|
|
16
|
+
toolCallData?: Record<string, unknown> | null;
|
|
17
|
+
/**
|
|
18
|
+
* Optional thread to attach the agent reply to. It MUST belong to the same
|
|
19
|
+
* room/tenant as the session (validated in {@link ChatService.writeMessage}).
|
|
20
|
+
*/
|
|
21
|
+
threadId?: string | null;
|
|
22
|
+
}
|
|
23
|
+
/** Tenant-bound agent session lookup descriptor for the read facade. */
|
|
24
|
+
export interface AgentSessionLookup {
|
|
25
|
+
agentSessionId: string;
|
|
26
|
+
tenantId: string | null;
|
|
27
|
+
}
|
|
28
|
+
/** Tenant-bound thread lookup descriptor for the read facade. */
|
|
29
|
+
export interface ThreadLookup {
|
|
30
|
+
threadId: string;
|
|
31
|
+
tenantId: string;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Module-private bridge key for the agent-reply path (S5 #1392).
|
|
35
|
+
*
|
|
36
|
+
* The agent-authoring path is reachable only through the {@link sendAgentReply}
|
|
37
|
+
* function (re-exported solely from `./internal/agent-runtime`). To let that
|
|
38
|
+
* module-local function reach the `private` {@link ChatService.emitAgentReply}
|
|
39
|
+
* without widening the class's PUBLIC surface, the class exposes a single
|
|
40
|
+
* symbol-keyed static. A symbol key is not a named member: it does not appear on
|
|
41
|
+
* the `ChatService` type, is not enumerable, and is callable only by code that
|
|
42
|
+
* holds this non-exported symbol. This replaces the previous public
|
|
43
|
+
* `_runAgentReply` static, which any consumer of the root-exported `ChatService`
|
|
44
|
+
* could call to author messages as the agent.
|
|
45
|
+
*/
|
|
46
|
+
declare const RUN_AGENT_REPLY: unique symbol;
|
|
47
|
+
export declare class ChatService {
|
|
48
|
+
#private;
|
|
49
|
+
private constructor();
|
|
50
|
+
static create(options: SmrtObjectOptions): Promise<ChatService>;
|
|
51
|
+
/** Initialize all underlying collections (table creation) */
|
|
52
|
+
initialize(): Promise<void>;
|
|
53
|
+
/**
|
|
54
|
+
* Create a room and add the creating actor as owner (S5 #1392).
|
|
55
|
+
*
|
|
56
|
+
* The acting identity is the server-supplied `actorProfileId` (the
|
|
57
|
+
* authenticated principal the route injects). The creator/owner is ALWAYS the
|
|
58
|
+
* actor — a caller cannot supply a `createdByProfileId` to attribute the room
|
|
59
|
+
* to (and enroll as owner) some other profile.
|
|
60
|
+
*/
|
|
61
|
+
createRoom(params: {
|
|
62
|
+
tenantId: string;
|
|
63
|
+
name: string;
|
|
64
|
+
roomType: ChatRoomType;
|
|
65
|
+
actorProfileId: string;
|
|
66
|
+
description?: string;
|
|
67
|
+
topic?: string;
|
|
68
|
+
}): Promise<import('../index.js').ChatRoom>;
|
|
69
|
+
/**
|
|
70
|
+
* Send a USER message to a room as the authenticated caller (S5 #1392).
|
|
71
|
+
*
|
|
72
|
+
* The acting identity is the server-supplied `actorProfileId` (the
|
|
73
|
+
* authenticated principal the route injects). The message is ALWAYS authored
|
|
74
|
+
* as `actorProfileId` with `role: 'user'` — the caller cannot supply a
|
|
75
|
+
* `senderProfileId` to impersonate another profile or the agent, and cannot
|
|
76
|
+
* supply a privileged `role` (assistant/system/tool). Agent-authored messages
|
|
77
|
+
* go exclusively through the internal {@link ChatService.sendAgentReply}.
|
|
78
|
+
*
|
|
79
|
+
* Authorization: `actorProfileId` must be an ACTIVE participant of the target
|
|
80
|
+
* room, preventing cross-room IDOR within a tenant. There is no public
|
|
81
|
+
* membership-skip parameter; system-authored writes use the internal
|
|
82
|
+
* {@link ChatService.writeMessage} path.
|
|
83
|
+
*/
|
|
84
|
+
sendMessage(params: {
|
|
85
|
+
tenantId: string;
|
|
86
|
+
roomId: string;
|
|
87
|
+
actorProfileId: string;
|
|
88
|
+
content: string;
|
|
89
|
+
messageType?: ChatMessageType;
|
|
90
|
+
threadId?: string | null;
|
|
91
|
+
agentSessionId?: string | null;
|
|
92
|
+
replyToMessageId?: string | null;
|
|
93
|
+
}): Promise<ChatMessage>;
|
|
94
|
+
/**
|
|
95
|
+
* Start a thread in a room (S5 #1392).
|
|
96
|
+
*
|
|
97
|
+
* The acting identity is the server-supplied `actorProfileId`, which must be
|
|
98
|
+
* an active member of the room. Generated thread `create` is disabled, so this
|
|
99
|
+
* is the only path to create a thread.
|
|
100
|
+
*
|
|
101
|
+
* When a `rootMessageId` is supplied it is bound to `{ id, roomId, tenantId }`
|
|
102
|
+
* and rejected unless it belongs to the SAME room and tenant — without this a
|
|
103
|
+
* member of one room could anchor a thread to a message from another
|
|
104
|
+
* room/tenant. `rootMessageId` is optional (a thread can be opened without a
|
|
105
|
+
* root message, e.g. an agent-editor thread).
|
|
106
|
+
*/
|
|
107
|
+
startThread(params: {
|
|
108
|
+
tenantId: string;
|
|
109
|
+
roomId: string;
|
|
110
|
+
actorProfileId: string;
|
|
111
|
+
rootMessageId?: string | null;
|
|
112
|
+
title?: string;
|
|
113
|
+
}): Promise<ChatThread>;
|
|
114
|
+
/**
|
|
115
|
+
* Add a participant to a room (S5 #1392).
|
|
116
|
+
*
|
|
117
|
+
* Authorization: the acting identity is the server-supplied `actorProfileId`,
|
|
118
|
+
* which MUST be an owner/admin of the target room. This prevents an arbitrary
|
|
119
|
+
* tenant member from adding anyone (or themselves) to any room with any role —
|
|
120
|
+
* a privilege-escalation / IDOR. System-bootstrap enrollment (room creation,
|
|
121
|
+
* DM/agent-session setup) uses the internal {@link ChatService.enrollParticipant}.
|
|
122
|
+
*/
|
|
123
|
+
addParticipant(params: {
|
|
124
|
+
tenantId: string;
|
|
125
|
+
roomId: string;
|
|
126
|
+
actorProfileId: string;
|
|
127
|
+
profileId: string;
|
|
128
|
+
role?: ChatParticipantRole;
|
|
129
|
+
}): Promise<import('../index.js').ChatParticipant>;
|
|
130
|
+
/**
|
|
131
|
+
* Remove (soft-leave) a participant from a room (S5 #1392).
|
|
132
|
+
*
|
|
133
|
+
* Authorization: the server-supplied `actorProfileId` may remove THEMSELVES
|
|
134
|
+
* (leave) at any time; removing ANOTHER profile requires the actor to be an
|
|
135
|
+
* owner/admin of the room. An admin who is not an owner cannot remove an owner.
|
|
136
|
+
*/
|
|
137
|
+
removeParticipant(params: {
|
|
138
|
+
tenantId: string;
|
|
139
|
+
roomId: string;
|
|
140
|
+
actorProfileId: string;
|
|
141
|
+
profileId: string;
|
|
142
|
+
}): Promise<void>;
|
|
143
|
+
/**
|
|
144
|
+
* Update mutable room fields, restricted to a room owner/admin (S5 #1392).
|
|
145
|
+
*
|
|
146
|
+
* Generated `update` on ChatRoom is disabled, so this owner-checked path is the
|
|
147
|
+
* only way to mutate room state. The acting identity is the server-supplied
|
|
148
|
+
* `actorProfileId`.
|
|
149
|
+
*/
|
|
150
|
+
updateRoom(params: {
|
|
151
|
+
tenantId: string;
|
|
152
|
+
roomId: string;
|
|
153
|
+
actorProfileId: string;
|
|
154
|
+
name?: string;
|
|
155
|
+
description?: string;
|
|
156
|
+
topic?: string;
|
|
157
|
+
avatarUrl?: string;
|
|
158
|
+
status?: ChatRoomStatus;
|
|
159
|
+
}): Promise<import('../index.js').ChatRoom>;
|
|
160
|
+
/**
|
|
161
|
+
* Add a reaction to a message as the authenticated caller (S5 #1392).
|
|
162
|
+
*
|
|
163
|
+
* Generated `create` on ChatReaction is disabled. The reaction is always
|
|
164
|
+
* authored as the server-supplied `actorProfileId` (no caller-supplied
|
|
165
|
+
* `profileId`), and the actor must be an active member of the room that owns
|
|
166
|
+
* the message. Idempotent: re-reacting with the same emoji returns the
|
|
167
|
+
* existing row.
|
|
168
|
+
*/
|
|
169
|
+
addReaction(params: {
|
|
170
|
+
tenantId: string;
|
|
171
|
+
messageId: string;
|
|
172
|
+
actorProfileId: string;
|
|
173
|
+
emoji: string;
|
|
174
|
+
}): Promise<import('../index.js').ChatReaction>;
|
|
175
|
+
/**
|
|
176
|
+
* Remove the caller's own reaction from a message (S5 #1392).
|
|
177
|
+
*
|
|
178
|
+
* Generated `delete` on ChatReaction is disabled. A caller may only delete
|
|
179
|
+
* THEIR OWN reaction (keyed on `actorProfileId`), so the route cannot remove
|
|
180
|
+
* another member's reaction.
|
|
181
|
+
*/
|
|
182
|
+
removeReaction(params: {
|
|
183
|
+
tenantId: string;
|
|
184
|
+
messageId: string;
|
|
185
|
+
actorProfileId: string;
|
|
186
|
+
emoji: string;
|
|
187
|
+
}): Promise<boolean>;
|
|
188
|
+
/**
|
|
189
|
+
* Get or create a DM room with auto-participant setup.
|
|
190
|
+
*
|
|
191
|
+
* The acting identity is the server-supplied `actorProfileId`, which must be
|
|
192
|
+
* one of the two DM participants — a caller cannot open a DM between two other
|
|
193
|
+
* profiles on their behalf (S5 #1392). Enrollment uses the internal system
|
|
194
|
+
* path (no owner check needed for a DM the actor is part of).
|
|
195
|
+
*/
|
|
196
|
+
getOrCreateDM(params: {
|
|
197
|
+
tenantId: string;
|
|
198
|
+
actorProfileId: string;
|
|
199
|
+
profileId1: string;
|
|
200
|
+
profileId2: string;
|
|
201
|
+
}): Promise<import('../index.js').ChatRoom>;
|
|
202
|
+
/**
|
|
203
|
+
* Create an agent conversation session with a linked chat room (S5 #1392).
|
|
204
|
+
*
|
|
205
|
+
* The acting identity is the server-supplied `actorProfileId`; the session is
|
|
206
|
+
* ALWAYS created for that actor as the owning participant. A caller cannot
|
|
207
|
+
* supply a `participantProfileId` to open (and own) a session on behalf of
|
|
208
|
+
* another profile.
|
|
209
|
+
*
|
|
210
|
+
* `sessionKey` scopes the session's identity to a conversation subject (e.g. a
|
|
211
|
+
* content id) (S5 #1392). The reuse lookup keys on `(agentId,
|
|
212
|
+
* participantProfileId, tenantId)`, which is too coarse for callers that open
|
|
213
|
+
* separate conversations for distinct subjects under one agent/profile/tenant:
|
|
214
|
+
* without a key, a session opened for subject A would be reused for a request
|
|
215
|
+
* about subject B, returning A's room/threads on B's route. When `sessionKey`
|
|
216
|
+
* is set, an existing session is reused ONLY if its key matches exactly, and a
|
|
217
|
+
* newly created session records the key; distinct keys therefore get distinct
|
|
218
|
+
* sessions and rooms. When omitted, behavior is unchanged (single session per
|
|
219
|
+
* agent/profile/tenant).
|
|
220
|
+
*/
|
|
221
|
+
createAgentSession(params: {
|
|
222
|
+
tenantId: string;
|
|
223
|
+
agentId: string;
|
|
224
|
+
actorProfileId: string;
|
|
225
|
+
allowedTools?: string[];
|
|
226
|
+
systemPrompt?: string;
|
|
227
|
+
maxTokens?: number;
|
|
228
|
+
maxMessages?: number;
|
|
229
|
+
sessionKey?: string | null;
|
|
230
|
+
}): Promise<{
|
|
231
|
+
session: AgentSession;
|
|
232
|
+
room: import('../index.js').ChatRoom;
|
|
233
|
+
}>;
|
|
234
|
+
/**
|
|
235
|
+
* Send a USER message within an agent session (S5 #1392).
|
|
236
|
+
*
|
|
237
|
+
* The authenticated caller (`actorProfileId`) must be the session's owning
|
|
238
|
+
* participant. The message is always authored as `session.participantProfileId`
|
|
239
|
+
* — the caller cannot supply a `senderProfileId`, a `role`, or tool-call data,
|
|
240
|
+
* so this path can never be used to post as the agent (`assistant`/`tool`) or
|
|
241
|
+
* to impersonate another profile. Agent replies go through the internal
|
|
242
|
+
* {@link ChatService.sendAgentReply}.
|
|
243
|
+
*/
|
|
244
|
+
sendAgentUserMessage(params: {
|
|
245
|
+
tenantId: string;
|
|
246
|
+
agentSessionId: string;
|
|
247
|
+
actorProfileId: string;
|
|
248
|
+
content: string;
|
|
249
|
+
messageType?: ChatMessageType;
|
|
250
|
+
}): Promise<ChatMessage>;
|
|
251
|
+
/**
|
|
252
|
+
* Read messages in a room, gated on the AUTHENTICATED CALLER's active
|
|
253
|
+
* membership (S5 #1392).
|
|
254
|
+
*
|
|
255
|
+
* The acting identity is the server-supplied `actorProfileId` (the
|
|
256
|
+
* authenticated principal the route injects), NOT a caller-controlled
|
|
257
|
+
* `profileId`. Authorizing a supplied `profileId` would make a route a
|
|
258
|
+
* confused deputy: any caller could read a room by smuggling some member's
|
|
259
|
+
* profile id. Throws if `actorProfileId` is not an active participant of
|
|
260
|
+
* `roomId`. `tenantId` is required so the membership gate is always
|
|
261
|
+
* tenant-scoped.
|
|
262
|
+
*/
|
|
263
|
+
getRoomMessages(params: {
|
|
264
|
+
roomId: string;
|
|
265
|
+
actorProfileId: string;
|
|
266
|
+
tenantId: string;
|
|
267
|
+
limit?: number;
|
|
268
|
+
before?: string;
|
|
269
|
+
}): Promise<ChatMessage[]>;
|
|
270
|
+
/**
|
|
271
|
+
* Load a room only if the AUTHENTICATED CALLER is an active member (S5 #1392).
|
|
272
|
+
*
|
|
273
|
+
* The acting identity is the server-supplied `actorProfileId`, never a
|
|
274
|
+
* caller-controlled `profileId` (confused-deputy avoidance — see
|
|
275
|
+
* {@link ChatService.getRoomMessages}). Returns null when the room does not
|
|
276
|
+
* exist; throws when the actor is not an active participant. `tenantId` is
|
|
277
|
+
* required so the lookup and the membership gate are always tenant-scoped.
|
|
278
|
+
*/
|
|
279
|
+
getRoomForMember(roomId: string, actorProfileId: string, tenantId: string): Promise<import('../index.js').ChatRoom | null>;
|
|
280
|
+
/**
|
|
281
|
+
* Tenant-bound read of a single agent session (S5 #1392).
|
|
282
|
+
*
|
|
283
|
+
* The lookup ALWAYS binds `tenantId` (including the `null`/untenanted scope),
|
|
284
|
+
* so a caller can never resolve a session belonging to another tenant by id.
|
|
285
|
+
* Returns `null` when no session matches the id within the tenant. Replaces
|
|
286
|
+
* direct `agentSessions.get(id)` reach-ins in package consumers; consumers
|
|
287
|
+
* still apply their own ownership/context authorization on the returned row.
|
|
288
|
+
*/
|
|
289
|
+
getAgentSession(lookup: AgentSessionLookup): Promise<AgentSession | null>;
|
|
290
|
+
/**
|
|
291
|
+
* Tenant-bound list of ACTIVE agent sessions for an (agent, participant) pair
|
|
292
|
+
* (S5 #1392).
|
|
293
|
+
*
|
|
294
|
+
* Binds `tenantId` into the query so the result can never include a session
|
|
295
|
+
* from another tenant. Replaces direct `agentSessions.list({ where })`
|
|
296
|
+
* reach-ins; consumers apply their own per-session context authorization.
|
|
297
|
+
*/
|
|
298
|
+
findActiveAgentSessions(params: {
|
|
299
|
+
tenantId: string | null;
|
|
300
|
+
agentId: string;
|
|
301
|
+
participantProfileId: string;
|
|
302
|
+
}): Promise<AgentSession[]>;
|
|
303
|
+
/**
|
|
304
|
+
* Tenant-bound read of a single thread (S5 #1392).
|
|
305
|
+
*
|
|
306
|
+
* Binds `tenantId` into the lookup so a thread from another tenant can never
|
|
307
|
+
* be resolved by id. Returns `null` when no thread matches within the tenant.
|
|
308
|
+
* Replaces direct `threads.get(id)` reach-ins.
|
|
309
|
+
*/
|
|
310
|
+
getThread(lookup: ThreadLookup): Promise<ChatThread | null>;
|
|
311
|
+
/**
|
|
312
|
+
* List a room's threads, gated on the caller's active membership (S5 #1392).
|
|
313
|
+
*
|
|
314
|
+
* Tenant- and membership-scoped: throws if `actorProfileId` is not an active
|
|
315
|
+
* participant of `roomId`. Replaces direct `threads.list({ where: { roomId } })`
|
|
316
|
+
* reach-ins that returned threads without a membership/tenant gate.
|
|
317
|
+
*/
|
|
318
|
+
listRoomThreads(params: {
|
|
319
|
+
roomId: string;
|
|
320
|
+
actorProfileId: string;
|
|
321
|
+
tenantId: string;
|
|
322
|
+
}): Promise<ChatThread[]>;
|
|
323
|
+
/**
|
|
324
|
+
* Read messages within a thread, tenant- and membership-bound (S5 #1392).
|
|
325
|
+
*
|
|
326
|
+
* The thread is resolved tenant-bound; the caller must be an active member of
|
|
327
|
+
* the thread's room. Messages are returned oldest-first (chronological).
|
|
328
|
+
* Replaces direct `messages.list({ where: { threadId } })` reach-ins that
|
|
329
|
+
* could read another tenant's/room's thread history by raw id.
|
|
330
|
+
*/
|
|
331
|
+
getThreadMessages(params: {
|
|
332
|
+
threadId: string;
|
|
333
|
+
actorProfileId: string;
|
|
334
|
+
tenantId: string;
|
|
335
|
+
limit?: number;
|
|
336
|
+
}): Promise<ChatMessage[]>;
|
|
337
|
+
/**
|
|
338
|
+
* Update the per-session agent configuration (allowedTools / systemPrompt),
|
|
339
|
+
* restricted to the session owner — the room owner participant (S5 #1392).
|
|
340
|
+
*
|
|
341
|
+
* Tool whitelist and system prompt govern what the agent may do, so only the
|
|
342
|
+
* owning participant (not arbitrary tenant members or the agent itself) may
|
|
343
|
+
* mutate them.
|
|
344
|
+
*/
|
|
345
|
+
updateAgentSessionConfig(params: {
|
|
346
|
+
agentSessionId: string;
|
|
347
|
+
actorProfileId: string;
|
|
348
|
+
tenantId: string | null;
|
|
349
|
+
allowedTools?: string[];
|
|
350
|
+
systemPrompt?: string;
|
|
351
|
+
}): Promise<AgentSession>;
|
|
352
|
+
/**
|
|
353
|
+
* Symbol-keyed bridge to the `private` {@link ChatService.emitAgentReply} for
|
|
354
|
+
* the module-local {@link sendAgentReply} function (S5 #1392). A static member
|
|
355
|
+
* may reach a private instance member of its own class, so this is the
|
|
356
|
+
* sanctioned "friend" access without widening the public instance surface.
|
|
357
|
+
*
|
|
358
|
+
* Keyed on the module-private {@link RUN_AGENT_REPLY} symbol — NOT a named
|
|
359
|
+
* static — so it does not appear on the `ChatService` type, is not enumerable,
|
|
360
|
+
* and is callable only by code holding the (non-exported) symbol. This is the
|
|
361
|
+
* sole path the agent-runtime bridge uses to author a message as the agent.
|
|
362
|
+
*/
|
|
363
|
+
static [RUN_AGENT_REPLY](service: AgentReplyService, params: AgentReplyParams): Promise<ChatMessage>;
|
|
364
|
+
}
|
|
365
|
+
/**
|
|
366
|
+
* Structural ChatService surface accepted by {@link sendAgentReply}. The chat
|
|
367
|
+
* collections are `#private`, so they cannot appear in a `Pick`; this opaque
|
|
368
|
+
* marker type keeps the agent-runtime bridge callable across module-instance
|
|
369
|
+
* boundaries (in a pnpm workspace a consumer's `ChatService` type may resolve to
|
|
370
|
+
* the package source while this function resolves to dist) without naming any
|
|
371
|
+
* private member. Any real ChatService instance satisfies it.
|
|
372
|
+
*/
|
|
373
|
+
export type AgentReplyService = Pick<ChatService, 'initialize'>;
|
|
374
|
+
/**
|
|
375
|
+
* Internal agent-runtime entry point: emit an ASSISTANT/TOOL message authored
|
|
376
|
+
* as the session's agent (S5 #1392).
|
|
377
|
+
*
|
|
378
|
+
* NOT re-exported from `src/index.ts`. Only in-process, trusted agent-runtime
|
|
379
|
+
* code that imports this module path directly can author messages as the agent;
|
|
380
|
+
* route handlers and package consumers (which import from the package index)
|
|
381
|
+
* cannot. The author is always `session.agentId`, never a caller-supplied
|
|
382
|
+
* sender/role, and tool calls are gated fail-closed against `allowedTools`.
|
|
383
|
+
*
|
|
384
|
+
* Because this lives in the same module as {@link ChatService}, reaching the
|
|
385
|
+
* symbol-keyed bridge (and through it the `private` method) is the owning
|
|
386
|
+
* module's sanctioned "friend" access, not an external private reach-in.
|
|
387
|
+
*/
|
|
388
|
+
export declare function sendAgentReply(service: AgentReplyService, params: AgentReplyParams): Promise<ChatMessage>;
|
|
389
|
+
export {};
|
|
390
|
+
//# sourceMappingURL=ChatService.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ChatService.d.ts","sourceRoot":"","sources":["../../src/services/ChatService.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,iBAAiB,EACvB,MAAM,0BAA0B,CAAC;AAOlC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAC5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