@tuturuuu/internal-api 0.0.2 → 0.2.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/dist/ai-memory.d.ts +76 -0
- package/dist/ai-memory.d.ts.map +1 -0
- package/dist/ai-memory.js +59 -0
- package/dist/ai.d.ts +67 -3
- package/dist/ai.d.ts.map +1 -1
- package/dist/ai.js +121 -0
- package/dist/auth.d.ts +143 -1
- package/dist/auth.d.ts.map +1 -1
- package/dist/auth.js +143 -0
- package/dist/calendar.d.ts +60 -1
- package/dist/calendar.d.ts.map +1 -1
- package/dist/calendar.js +27 -0
- package/dist/chat-conversations.d.ts +81 -0
- package/dist/chat-conversations.d.ts.map +1 -0
- package/dist/chat-conversations.js +384 -0
- package/dist/chat-internal.d.ts +11 -0
- package/dist/chat-internal.d.ts.map +1 -0
- package/dist/chat-internal.js +39 -0
- package/dist/chat-legacy.d.ts +23 -0
- package/dist/chat-legacy.d.ts.map +1 -0
- package/dist/chat-legacy.js +68 -0
- package/dist/chat-types.d.ts +262 -0
- package/dist/chat-types.d.ts.map +1 -0
- package/dist/chat-types.js +2 -0
- package/dist/chat.d.ts +3 -45
- package/dist/chat.d.ts.map +1 -1
- package/dist/chat.js +17 -65
- package/dist/client.d.ts +5 -0
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +109 -8
- package/dist/education.d.ts +288 -2
- package/dist/education.d.ts.map +1 -1
- package/dist/education.js +176 -0
- package/dist/external-project-team.d.ts +51 -0
- package/dist/external-project-team.d.ts.map +1 -0
- package/dist/external-project-team.js +137 -0
- package/dist/external-projects.d.ts +89 -9
- package/dist/external-projects.d.ts.map +1 -1
- package/dist/external-projects.js +80 -31
- package/dist/finance.d.ts +491 -3
- package/dist/finance.d.ts.map +1 -1
- package/dist/finance.js +611 -1
- package/dist/hive.d.ts +739 -0
- package/dist/hive.d.ts.map +1 -0
- package/dist/hive.js +333 -0
- package/dist/index.d.ts +33 -19
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +361 -8
- package/dist/infrastructure.d.ts +1085 -1
- package/dist/infrastructure.d.ts.map +1 -1
- package/dist/infrastructure.js +652 -0
- package/dist/inventory.d.ts +355 -0
- package/dist/inventory.d.ts.map +1 -0
- package/dist/inventory.js +268 -0
- package/dist/mail.d.ts +125 -0
- package/dist/mail.d.ts.map +1 -1
- package/dist/mail.js +112 -1
- package/dist/meet.d.ts +54 -0
- package/dist/meet.d.ts.map +1 -0
- package/dist/meet.js +37 -0
- package/dist/mind.d.ts +55 -0
- package/dist/mind.d.ts.map +1 -0
- package/dist/mind.js +84 -0
- package/dist/posts.d.ts +33 -0
- package/dist/posts.d.ts.map +1 -1
- package/dist/posts.js +42 -0
- package/dist/promotions.d.ts +54 -0
- package/dist/promotions.d.ts.map +1 -1
- package/dist/promotions.js +52 -0
- package/dist/settings.d.ts +28 -1
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js +68 -0
- package/dist/storage.d.ts +33 -21
- package/dist/storage.d.ts.map +1 -1
- package/dist/storage.js +53 -32
- package/dist/tasks-scheduling.d.ts +29 -0
- package/dist/tasks-scheduling.d.ts.map +1 -1
- package/dist/tasks-scheduling.js +20 -0
- package/dist/tasks.d.ts +239 -4
- package/dist/tasks.d.ts.map +1 -1
- package/dist/tasks.js +213 -0
- package/dist/teach.d.ts +130 -0
- package/dist/teach.d.ts.map +1 -0
- package/dist/teach.js +110 -0
- package/dist/topic-announcements.d.ts +235 -0
- package/dist/topic-announcements.d.ts.map +1 -0
- package/dist/topic-announcements.js +182 -0
- package/dist/tulearn.d.ts +223 -0
- package/dist/tulearn.d.ts.map +1 -0
- package/dist/tulearn.js +97 -0
- package/dist/tutoring.d.ts +152 -0
- package/dist/tutoring.d.ts.map +1 -0
- package/dist/tutoring.js +58 -0
- package/dist/user-group-activity.d.ts +54 -0
- package/dist/user-group-activity.d.ts.map +1 -0
- package/dist/user-group-activity.js +11 -0
- package/dist/user-groups.d.ts +35 -0
- package/dist/user-groups.d.ts.map +1 -0
- package/dist/user-groups.js +84 -0
- package/dist/users.d.ts +101 -1
- package/dist/users.d.ts.map +1 -1
- package/dist/users.js +178 -0
- package/dist/workspace-config-ids.d.ts +9 -0
- package/dist/workspace-config-ids.d.ts.map +1 -0
- package/dist/workspace-config-ids.js +11 -0
- package/dist/workspace-configs.d.ts +1 -7
- package/dist/workspace-configs.d.ts.map +1 -1
- package/dist/workspace-configs.js +14 -10
- package/dist/workspace-user-audit.d.ts +1 -0
- package/dist/workspace-user-audit.d.ts.map +1 -1
- package/dist/workspaces.d.ts +57 -0
- package/dist/workspaces.d.ts.map +1 -1
- package/dist/workspaces.js +58 -1
- package/package.json +65 -7
|
@@ -0,0 +1,384 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.listWorkspaceChatConversations = listWorkspaceChatConversations;
|
|
4
|
+
exports.listWorkspaceChatConversationsPage = listWorkspaceChatConversationsPage;
|
|
5
|
+
exports.createWorkspaceChatConversation = createWorkspaceChatConversation;
|
|
6
|
+
exports.deleteWorkspaceChatConversation = deleteWorkspaceChatConversation;
|
|
7
|
+
exports.updateWorkspaceChatConversation = updateWorkspaceChatConversation;
|
|
8
|
+
exports.generateWorkspaceChatConversationTitle = generateWorkspaceChatConversationTitle;
|
|
9
|
+
exports.listWorkspaceChatConversationMessages = listWorkspaceChatConversationMessages;
|
|
10
|
+
exports.sendWorkspaceChatMessage = sendWorkspaceChatMessage;
|
|
11
|
+
exports.sendWorkspaceChatMessageStream = sendWorkspaceChatMessageStream;
|
|
12
|
+
exports.editWorkspaceChatMessage = editWorkspaceChatMessage;
|
|
13
|
+
exports.deleteWorkspaceChatMessage = deleteWorkspaceChatMessage;
|
|
14
|
+
exports.markWorkspaceChatConversationRead = markWorkspaceChatConversationRead;
|
|
15
|
+
exports.toggleWorkspaceChatReaction = toggleWorkspaceChatReaction;
|
|
16
|
+
exports.getWorkspaceChatLinkPreviews = getWorkspaceChatLinkPreviews;
|
|
17
|
+
exports.getWorkspaceChatSharedContent = getWorkspaceChatSharedContent;
|
|
18
|
+
exports.getWorkspaceChatAiSettings = getWorkspaceChatAiSettings;
|
|
19
|
+
exports.updateWorkspaceChatAiSettings = updateWorkspaceChatAiSettings;
|
|
20
|
+
exports.getWorkspaceChatAiObservability = getWorkspaceChatAiObservability;
|
|
21
|
+
exports.searchWorkspaceChatDirectory = searchWorkspaceChatDirectory;
|
|
22
|
+
exports.searchWorkspaceChatMessages = searchWorkspaceChatMessages;
|
|
23
|
+
exports.listWorkspaceChatFriendRequests = listWorkspaceChatFriendRequests;
|
|
24
|
+
exports.createWorkspaceChatFriendRequest = createWorkspaceChatFriendRequest;
|
|
25
|
+
exports.respondWorkspaceChatFriendRequest = respondWorkspaceChatFriendRequest;
|
|
26
|
+
exports.revokeWorkspaceChatFriendRequest = revokeWorkspaceChatFriendRequest;
|
|
27
|
+
exports.uploadWorkspaceChatAttachment = uploadWorkspaceChatAttachment;
|
|
28
|
+
exports.getWorkspaceChatAttachmentSignedUrl = getWorkspaceChatAttachmentSignedUrl;
|
|
29
|
+
const ai_1 = require("./ai");
|
|
30
|
+
const chat_internal_1 = require("./chat-internal");
|
|
31
|
+
const client_1 = require("./client");
|
|
32
|
+
const AI_CHAT_CONVERSATION_PREFIXES = ['ai-chat-', 'legacy-ai-'];
|
|
33
|
+
const AI_CHAT_FILE_ATTACHMENT_PREFIX = 'ai-file:';
|
|
34
|
+
async function listWorkspaceChatConversations(workspaceId, params, options) {
|
|
35
|
+
const page = await listWorkspaceChatConversationsPage(workspaceId, params, options);
|
|
36
|
+
return page.conversations;
|
|
37
|
+
}
|
|
38
|
+
async function listWorkspaceChatConversationsPage(workspaceId, params, options) {
|
|
39
|
+
const client = (0, client_1.getInternalApiClient)(options);
|
|
40
|
+
const payload = await client.json(`${(0, chat_internal_1.chatBasePath)(workspaceId)}/conversations`, {
|
|
41
|
+
cache: 'no-store',
|
|
42
|
+
query: {
|
|
43
|
+
archived: params?.archived,
|
|
44
|
+
limit: params?.limit,
|
|
45
|
+
offset: params?.offset,
|
|
46
|
+
},
|
|
47
|
+
});
|
|
48
|
+
const conversations = (payload.conversations ?? []).filter((conversation) => Boolean(conversation?.id && conversation.type));
|
|
49
|
+
return {
|
|
50
|
+
conversations,
|
|
51
|
+
nextOffset: typeof payload.nextOffset === 'number' ? payload.nextOffset : null,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
async function createWorkspaceChatConversation(workspaceId, payload, options) {
|
|
55
|
+
const client = (0, client_1.getInternalApiClient)(options);
|
|
56
|
+
return client.json(`${(0, chat_internal_1.chatBasePath)(workspaceId)}/conversations`, {
|
|
57
|
+
body: JSON.stringify(payload),
|
|
58
|
+
cache: 'no-store',
|
|
59
|
+
headers: { 'Content-Type': 'application/json' },
|
|
60
|
+
method: 'POST',
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
async function deleteWorkspaceChatConversation(workspaceId, conversationId, options) {
|
|
64
|
+
const client = (0, client_1.getInternalApiClient)(options);
|
|
65
|
+
return client.json(`${(0, chat_internal_1.chatBasePath)(workspaceId)}/conversations/${(0, client_1.encodePathSegment)(conversationId)}`, {
|
|
66
|
+
cache: 'no-store',
|
|
67
|
+
method: 'DELETE',
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
async function updateWorkspaceChatConversation(workspaceId, conversationId, payload, options) {
|
|
71
|
+
const client = (0, client_1.getInternalApiClient)(options);
|
|
72
|
+
return client.json(`${(0, chat_internal_1.chatBasePath)(workspaceId)}/conversations/${(0, client_1.encodePathSegment)(conversationId)}`, {
|
|
73
|
+
body: JSON.stringify(payload),
|
|
74
|
+
cache: 'no-store',
|
|
75
|
+
headers: { 'Content-Type': 'application/json' },
|
|
76
|
+
method: 'PATCH',
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
async function generateWorkspaceChatConversationTitle(workspaceId, conversationId, options) {
|
|
80
|
+
const client = (0, client_1.getInternalApiClient)(options);
|
|
81
|
+
return client.json(`${(0, chat_internal_1.chatBasePath)(workspaceId)}/conversations/${(0, client_1.encodePathSegment)(conversationId)}/title`, {
|
|
82
|
+
cache: 'no-store',
|
|
83
|
+
method: 'POST',
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
async function listWorkspaceChatConversationMessages(workspaceId, conversationId, options, clientOptions) {
|
|
87
|
+
const client = (0, client_1.getInternalApiClient)(clientOptions);
|
|
88
|
+
const payload = await client.json(`${(0, chat_internal_1.chatBasePath)(workspaceId)}/conversations/${(0, client_1.encodePathSegment)(conversationId)}/messages`, {
|
|
89
|
+
cache: 'no-store',
|
|
90
|
+
query: {
|
|
91
|
+
before: options?.before,
|
|
92
|
+
limit: options?.limit,
|
|
93
|
+
},
|
|
94
|
+
});
|
|
95
|
+
return payload.messages ?? [];
|
|
96
|
+
}
|
|
97
|
+
async function sendWorkspaceChatMessage(workspaceId, conversationId, payload, options) {
|
|
98
|
+
const client = (0, client_1.getInternalApiClient)(options);
|
|
99
|
+
return client.json(`${(0, chat_internal_1.chatBasePath)(workspaceId)}/conversations/${(0, client_1.encodePathSegment)(conversationId)}/messages`, {
|
|
100
|
+
body: JSON.stringify(payload),
|
|
101
|
+
cache: 'no-store',
|
|
102
|
+
headers: { 'Content-Type': 'application/json' },
|
|
103
|
+
method: 'POST',
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
async function sendWorkspaceChatMessageStream(workspaceId, conversationId, payload, handlers = {}, options) {
|
|
107
|
+
const client = (0, client_1.getInternalApiClient)(options);
|
|
108
|
+
const response = await client.fetch(`${(0, chat_internal_1.chatBasePath)(workspaceId)}/conversations/${(0, client_1.encodePathSegment)(conversationId)}/messages`, {
|
|
109
|
+
body: JSON.stringify(payload),
|
|
110
|
+
cache: 'no-store',
|
|
111
|
+
headers: {
|
|
112
|
+
Accept: 'application/x-ndjson',
|
|
113
|
+
'Content-Type': 'application/json',
|
|
114
|
+
},
|
|
115
|
+
method: 'POST',
|
|
116
|
+
});
|
|
117
|
+
if (!response.ok) {
|
|
118
|
+
throw new Error(await readInternalApiErrorMessage(response));
|
|
119
|
+
}
|
|
120
|
+
if (!response.body) {
|
|
121
|
+
return response.json();
|
|
122
|
+
}
|
|
123
|
+
const contentType = response.headers.get('content-type') ?? '';
|
|
124
|
+
if (!contentType.includes('application/x-ndjson')) {
|
|
125
|
+
return response.json();
|
|
126
|
+
}
|
|
127
|
+
const messages = [];
|
|
128
|
+
const decoder = new TextDecoder();
|
|
129
|
+
const reader = response.body.getReader();
|
|
130
|
+
let buffer = '';
|
|
131
|
+
let assistantError;
|
|
132
|
+
const processEvent = (event) => {
|
|
133
|
+
if (!event)
|
|
134
|
+
return;
|
|
135
|
+
if (event.type === 'error') {
|
|
136
|
+
if (messages.length > 0) {
|
|
137
|
+
assistantError = event.message || 'Assistant response failed';
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
throw new Error(event.message);
|
|
141
|
+
}
|
|
142
|
+
if (event.type === 'message') {
|
|
143
|
+
messages.push(event.message);
|
|
144
|
+
handlers.onMessage?.(event.message);
|
|
145
|
+
}
|
|
146
|
+
else if (event.type === 'assistant_delta') {
|
|
147
|
+
handlers.onAssistantDelta?.(event.delta);
|
|
148
|
+
}
|
|
149
|
+
else if (event.type === 'assistant_part') {
|
|
150
|
+
handlers.onAssistantPart?.(event.part);
|
|
151
|
+
}
|
|
152
|
+
else if (event.type === 'messages') {
|
|
153
|
+
messages.push(...event.messages);
|
|
154
|
+
handlers.onMessages?.(event.messages);
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
while (true) {
|
|
158
|
+
const { done, value } = await reader.read();
|
|
159
|
+
if (value) {
|
|
160
|
+
buffer += decoder.decode(value, { stream: !done });
|
|
161
|
+
const lines = buffer.split('\n');
|
|
162
|
+
buffer = lines.pop() ?? '';
|
|
163
|
+
for (const line of lines) {
|
|
164
|
+
processEvent(parseChatMessageStreamEvent(line));
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
if (done)
|
|
168
|
+
break;
|
|
169
|
+
}
|
|
170
|
+
processEvent(parseChatMessageStreamEvent(buffer));
|
|
171
|
+
const message = messages.at(-1);
|
|
172
|
+
if (!message) {
|
|
173
|
+
throw new Error('No message was returned');
|
|
174
|
+
}
|
|
175
|
+
return assistantError
|
|
176
|
+
? { assistantError, message, messages }
|
|
177
|
+
: { message, messages };
|
|
178
|
+
}
|
|
179
|
+
async function editWorkspaceChatMessage(workspaceId, conversationId, messageId, payload, options) {
|
|
180
|
+
const client = (0, client_1.getInternalApiClient)(options);
|
|
181
|
+
return client.json(`${(0, chat_internal_1.chatBasePath)(workspaceId)}/conversations/${(0, client_1.encodePathSegment)(conversationId)}/messages/${(0, client_1.encodePathSegment)(messageId)}`, {
|
|
182
|
+
body: JSON.stringify(payload),
|
|
183
|
+
cache: 'no-store',
|
|
184
|
+
headers: { 'Content-Type': 'application/json' },
|
|
185
|
+
method: 'PATCH',
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
async function deleteWorkspaceChatMessage(workspaceId, conversationId, messageId, options) {
|
|
189
|
+
const client = (0, client_1.getInternalApiClient)(options);
|
|
190
|
+
return client.json(`${(0, chat_internal_1.chatBasePath)(workspaceId)}/conversations/${(0, client_1.encodePathSegment)(conversationId)}/messages/${(0, client_1.encodePathSegment)(messageId)}`, {
|
|
191
|
+
cache: 'no-store',
|
|
192
|
+
method: 'DELETE',
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
async function markWorkspaceChatConversationRead(workspaceId, conversationId, payload, options) {
|
|
196
|
+
const client = (0, client_1.getInternalApiClient)(options);
|
|
197
|
+
return client.json(`${(0, chat_internal_1.chatBasePath)(workspaceId)}/conversations/${(0, client_1.encodePathSegment)(conversationId)}/read`, {
|
|
198
|
+
body: JSON.stringify(payload ?? {}),
|
|
199
|
+
cache: 'no-store',
|
|
200
|
+
headers: { 'Content-Type': 'application/json' },
|
|
201
|
+
method: 'POST',
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
async function toggleWorkspaceChatReaction(workspaceId, conversationId, payload, options) {
|
|
205
|
+
const client = (0, client_1.getInternalApiClient)(options);
|
|
206
|
+
return client.json(`${(0, chat_internal_1.chatBasePath)(workspaceId)}/conversations/${(0, client_1.encodePathSegment)(conversationId)}/reactions`, {
|
|
207
|
+
body: JSON.stringify(payload),
|
|
208
|
+
cache: 'no-store',
|
|
209
|
+
headers: { 'Content-Type': 'application/json' },
|
|
210
|
+
method: 'POST',
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
async function getWorkspaceChatLinkPreviews(workspaceId, conversationId, urls, options) {
|
|
214
|
+
const client = (0, client_1.getInternalApiClient)(options);
|
|
215
|
+
const payload = await client.json(`${(0, chat_internal_1.chatBasePath)(workspaceId)}/conversations/${(0, client_1.encodePathSegment)(conversationId)}/link-previews`, {
|
|
216
|
+
body: JSON.stringify({ urls }),
|
|
217
|
+
cache: 'no-store',
|
|
218
|
+
headers: { 'Content-Type': 'application/json' },
|
|
219
|
+
method: 'POST',
|
|
220
|
+
});
|
|
221
|
+
return payload.previews ?? [];
|
|
222
|
+
}
|
|
223
|
+
async function getWorkspaceChatSharedContent(workspaceId, conversationId, options) {
|
|
224
|
+
const client = (0, client_1.getInternalApiClient)(options);
|
|
225
|
+
const payload = await client.json(`${(0, chat_internal_1.chatBasePath)(workspaceId)}/conversations/${(0, client_1.encodePathSegment)(conversationId)}/shared-content`, { cache: 'no-store' });
|
|
226
|
+
return {
|
|
227
|
+
files: payload.sharedContent?.files ?? [],
|
|
228
|
+
links: payload.sharedContent?.links ?? [],
|
|
229
|
+
photos: payload.sharedContent?.photos ?? [],
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
async function getWorkspaceChatAiSettings(workspaceId, conversationId, options) {
|
|
233
|
+
const client = (0, client_1.getInternalApiClient)(options);
|
|
234
|
+
const payload = await client.json(`${(0, chat_internal_1.chatBasePath)(workspaceId)}/conversations/${(0, client_1.encodePathSegment)(conversationId)}/ai-settings`, { cache: 'no-store' });
|
|
235
|
+
return payload.settings;
|
|
236
|
+
}
|
|
237
|
+
async function updateWorkspaceChatAiSettings(workspaceId, conversationId, payload, options) {
|
|
238
|
+
const client = (0, client_1.getInternalApiClient)(options);
|
|
239
|
+
return client.json(`${(0, chat_internal_1.chatBasePath)(workspaceId)}/conversations/${(0, client_1.encodePathSegment)(conversationId)}/ai-settings`, {
|
|
240
|
+
body: JSON.stringify(payload),
|
|
241
|
+
cache: 'no-store',
|
|
242
|
+
headers: { 'Content-Type': 'application/json' },
|
|
243
|
+
method: 'PATCH',
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
async function getWorkspaceChatAiObservability(workspaceId, conversationId, options) {
|
|
247
|
+
const client = (0, client_1.getInternalApiClient)(options);
|
|
248
|
+
const payload = await client.json(`${(0, chat_internal_1.chatBasePath)(workspaceId)}/conversations/${(0, client_1.encodePathSegment)(conversationId)}/ai-observability`, { cache: 'no-store' });
|
|
249
|
+
return payload.observability;
|
|
250
|
+
}
|
|
251
|
+
async function searchWorkspaceChatDirectory(workspaceId, query, options) {
|
|
252
|
+
const client = (0, client_1.getInternalApiClient)(options);
|
|
253
|
+
const payload = await client.json(`${(0, chat_internal_1.chatBasePath)(workspaceId)}/directory`, {
|
|
254
|
+
cache: 'no-store',
|
|
255
|
+
query: { q: query },
|
|
256
|
+
});
|
|
257
|
+
return payload.users ?? [];
|
|
258
|
+
}
|
|
259
|
+
async function searchWorkspaceChatMessages(workspaceId, query, options) {
|
|
260
|
+
const client = (0, client_1.getInternalApiClient)(options);
|
|
261
|
+
const payload = await client.json(`${(0, chat_internal_1.chatBasePath)(workspaceId)}/search`, {
|
|
262
|
+
cache: 'no-store',
|
|
263
|
+
query: { q: query },
|
|
264
|
+
});
|
|
265
|
+
return payload.messages ?? [];
|
|
266
|
+
}
|
|
267
|
+
async function readInternalApiErrorMessage(response) {
|
|
268
|
+
const fallbackMessage = `Internal API request failed: ${response.status}`;
|
|
269
|
+
const text = await response.text().catch(() => '');
|
|
270
|
+
try {
|
|
271
|
+
const data = JSON.parse(text);
|
|
272
|
+
return data.message || data.error || fallbackMessage;
|
|
273
|
+
}
|
|
274
|
+
catch {
|
|
275
|
+
return text || fallbackMessage;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
function parseChatMessageStreamEvent(line) {
|
|
279
|
+
const trimmed = line.trim();
|
|
280
|
+
if (!trimmed)
|
|
281
|
+
return null;
|
|
282
|
+
try {
|
|
283
|
+
const event = JSON.parse(trimmed);
|
|
284
|
+
return typeof event?.type === 'string' ? event : null;
|
|
285
|
+
}
|
|
286
|
+
catch {
|
|
287
|
+
return null;
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
async function listWorkspaceChatFriendRequests(workspaceId, options) {
|
|
291
|
+
const client = (0, client_1.getInternalApiClient)(options);
|
|
292
|
+
const payload = await client.json(`${(0, chat_internal_1.chatBasePath)(workspaceId)}/friend-requests`, { cache: 'no-store' });
|
|
293
|
+
return {
|
|
294
|
+
accepted: payload.accepted ?? [],
|
|
295
|
+
incoming: payload.incoming ?? [],
|
|
296
|
+
outgoing: payload.outgoing ?? [],
|
|
297
|
+
};
|
|
298
|
+
}
|
|
299
|
+
async function createWorkspaceChatFriendRequest(workspaceId, payload, options) {
|
|
300
|
+
const client = (0, client_1.getInternalApiClient)(options);
|
|
301
|
+
return client.json(`${(0, chat_internal_1.chatBasePath)(workspaceId)}/friend-requests`, {
|
|
302
|
+
body: JSON.stringify(payload),
|
|
303
|
+
cache: 'no-store',
|
|
304
|
+
headers: { 'Content-Type': 'application/json' },
|
|
305
|
+
method: 'POST',
|
|
306
|
+
});
|
|
307
|
+
}
|
|
308
|
+
async function respondWorkspaceChatFriendRequest(workspaceId, requestId, payload, options) {
|
|
309
|
+
const client = (0, client_1.getInternalApiClient)(options);
|
|
310
|
+
return client.json(`${(0, chat_internal_1.chatBasePath)(workspaceId)}/friend-requests/${(0, client_1.encodePathSegment)(requestId)}`, {
|
|
311
|
+
body: JSON.stringify(payload),
|
|
312
|
+
cache: 'no-store',
|
|
313
|
+
headers: { 'Content-Type': 'application/json' },
|
|
314
|
+
method: 'PATCH',
|
|
315
|
+
});
|
|
316
|
+
}
|
|
317
|
+
async function revokeWorkspaceChatFriendRequest(workspaceId, requestId, options) {
|
|
318
|
+
const client = (0, client_1.getInternalApiClient)(options);
|
|
319
|
+
return client.json(`${(0, chat_internal_1.chatBasePath)(workspaceId)}/friend-requests/${(0, client_1.encodePathSegment)(requestId)}`, {
|
|
320
|
+
cache: 'no-store',
|
|
321
|
+
method: 'DELETE',
|
|
322
|
+
});
|
|
323
|
+
}
|
|
324
|
+
async function uploadWorkspaceChatAttachment(workspaceId, conversationId, file, options) {
|
|
325
|
+
const aiChatId = getAiChatResourceIdFromConversationId(conversationId);
|
|
326
|
+
if (aiChatId) {
|
|
327
|
+
return (0, ai_1.uploadAiChatFile)({
|
|
328
|
+
chatId: aiChatId,
|
|
329
|
+
file,
|
|
330
|
+
workspaceId,
|
|
331
|
+
}, options);
|
|
332
|
+
}
|
|
333
|
+
const client = (0, client_1.getInternalApiClient)(options);
|
|
334
|
+
const fetchImpl = options?.fetch ?? globalThis.fetch;
|
|
335
|
+
const uploadPayload = await client.json(`${(0, chat_internal_1.chatBasePath)(workspaceId)}/conversations/${(0, client_1.encodePathSegment)(conversationId)}/attachments/upload-url`, {
|
|
336
|
+
body: JSON.stringify({
|
|
337
|
+
contentType: file.type || 'application/octet-stream',
|
|
338
|
+
filename: file.name,
|
|
339
|
+
sizeBytes: file.size,
|
|
340
|
+
}),
|
|
341
|
+
cache: 'no-store',
|
|
342
|
+
headers: { 'Content-Type': 'application/json' },
|
|
343
|
+
method: 'POST',
|
|
344
|
+
});
|
|
345
|
+
await (0, chat_internal_1.uploadFileWithSignedUrl)(file, uploadPayload, fetchImpl);
|
|
346
|
+
return uploadPayload.attachment;
|
|
347
|
+
}
|
|
348
|
+
function getAiChatResourceIdFromConversationId(conversationId) {
|
|
349
|
+
for (const prefix of AI_CHAT_CONVERSATION_PREFIXES) {
|
|
350
|
+
if (conversationId.startsWith(prefix)) {
|
|
351
|
+
return conversationId.slice(prefix.length);
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
return null;
|
|
355
|
+
}
|
|
356
|
+
async function getWorkspaceChatAttachmentSignedUrl(workspaceId, conversationId, attachmentId, options) {
|
|
357
|
+
const client = (0, client_1.getInternalApiClient)(options);
|
|
358
|
+
const aiChatFilePath = decodeAiChatFileAttachmentPath(attachmentId);
|
|
359
|
+
if (getAiChatResourceIdFromConversationId(conversationId) && aiChatFilePath) {
|
|
360
|
+
const payload = await client.json('/api/ai/chat/signed-read-url', {
|
|
361
|
+
body: JSON.stringify({ paths: [aiChatFilePath] }),
|
|
362
|
+
cache: 'no-store',
|
|
363
|
+
headers: { 'Content-Type': 'application/json' },
|
|
364
|
+
method: 'POST',
|
|
365
|
+
});
|
|
366
|
+
const signedUrl = payload.urls?.[0]?.signedUrl;
|
|
367
|
+
if (!signedUrl) {
|
|
368
|
+
throw new Error('Attachment URL is unavailable');
|
|
369
|
+
}
|
|
370
|
+
return signedUrl;
|
|
371
|
+
}
|
|
372
|
+
const payload = await client.json(`${(0, chat_internal_1.chatBasePath)(workspaceId)}/conversations/${(0, client_1.encodePathSegment)(conversationId)}/attachments/${(0, client_1.encodePathSegment)(attachmentId)}`, { cache: 'no-store' });
|
|
373
|
+
return payload.signedUrl;
|
|
374
|
+
}
|
|
375
|
+
function decodeAiChatFileAttachmentPath(attachmentId) {
|
|
376
|
+
if (!attachmentId.startsWith(AI_CHAT_FILE_ATTACHMENT_PREFIX))
|
|
377
|
+
return null;
|
|
378
|
+
try {
|
|
379
|
+
return decodeURIComponent(attachmentId.slice(AI_CHAT_FILE_ATTACHMENT_PREFIX.length));
|
|
380
|
+
}
|
|
381
|
+
catch {
|
|
382
|
+
return null;
|
|
383
|
+
}
|
|
384
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ChatAttachmentDraft } from './chat-types';
|
|
2
|
+
export interface ChatUploadUrlResponse {
|
|
3
|
+
attachment: ChatAttachmentDraft;
|
|
4
|
+
headers?: Record<string, string>;
|
|
5
|
+
maxSizeBytes: number;
|
|
6
|
+
signedUrl: string;
|
|
7
|
+
token?: string;
|
|
8
|
+
}
|
|
9
|
+
export declare function chatBasePath(workspaceId: string): string;
|
|
10
|
+
export declare function uploadFileWithSignedUrl(file: File, payload: ChatUploadUrlResponse, fetchImpl: typeof fetch): Promise<void>;
|
|
11
|
+
//# sourceMappingURL=chat-internal.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chat-internal.d.ts","sourceRoot":"","sources":["../src/chat-internal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAGxD,MAAM,WAAW,qBAAqB;IACpC,UAAU,EAAE,mBAAmB,CAAC;IAChC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,wBAAgB,YAAY,CAAC,WAAW,EAAE,MAAM,UAE/C;AAED,wBAAsB,uBAAuB,CAC3C,IAAI,EAAE,IAAI,EACV,OAAO,EAAE,qBAAqB,EAC9B,SAAS,EAAE,OAAO,KAAK,iBAsCxB"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.chatBasePath = chatBasePath;
|
|
4
|
+
exports.uploadFileWithSignedUrl = uploadFileWithSignedUrl;
|
|
5
|
+
const client_1 = require("./client");
|
|
6
|
+
function chatBasePath(workspaceId) {
|
|
7
|
+
return `/api/v1/workspaces/${(0, client_1.encodePathSegment)(workspaceId)}/chat`;
|
|
8
|
+
}
|
|
9
|
+
async function uploadFileWithSignedUrl(file, payload, fetchImpl) {
|
|
10
|
+
const headers = {
|
|
11
|
+
...(payload.headers ?? {}),
|
|
12
|
+
};
|
|
13
|
+
if (!headers['Content-Type']) {
|
|
14
|
+
headers['Content-Type'] = file.type || 'application/octet-stream';
|
|
15
|
+
}
|
|
16
|
+
if (payload.token) {
|
|
17
|
+
headers.Authorization = `Bearer ${payload.token}`;
|
|
18
|
+
}
|
|
19
|
+
let response = await fetchImpl(payload.signedUrl, {
|
|
20
|
+
body: file,
|
|
21
|
+
cache: 'no-store',
|
|
22
|
+
headers,
|
|
23
|
+
method: 'PUT',
|
|
24
|
+
});
|
|
25
|
+
if (!response.ok && headers['Content-Type']) {
|
|
26
|
+
const fallbackHeaders = { ...headers };
|
|
27
|
+
delete fallbackHeaders['Content-Type'];
|
|
28
|
+
response = await fetchImpl(payload.signedUrl, {
|
|
29
|
+
body: file,
|
|
30
|
+
cache: 'no-store',
|
|
31
|
+
headers: fallbackHeaders,
|
|
32
|
+
method: 'PUT',
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
if (!response.ok) {
|
|
36
|
+
const message = await response.text().catch(() => '');
|
|
37
|
+
throw new Error(`Failed to upload file (${response.status})${message ? `: ${message}` : ''}`);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { WorkspaceChatChannel, WorkspaceChatMessage, WorkspaceChatParticipant } from './chat-types';
|
|
2
|
+
import { type InternalApiClientOptions } from './client';
|
|
3
|
+
export declare function listWorkspaceChatChannels(workspaceId: string, options?: InternalApiClientOptions): Promise<WorkspaceChatChannel[]>;
|
|
4
|
+
export declare function createWorkspaceChatChannel(workspaceId: string, name: string, options?: InternalApiClientOptions): Promise<{
|
|
5
|
+
channel: WorkspaceChatChannel;
|
|
6
|
+
}>;
|
|
7
|
+
export declare function listWorkspaceChatMessages(workspaceId: string, channelId: string, options?: InternalApiClientOptions): Promise<WorkspaceChatMessage[]>;
|
|
8
|
+
export declare function createWorkspaceChatMessage(workspaceId: string, channelId: string, content: string, options?: InternalApiClientOptions): Promise<{
|
|
9
|
+
message: WorkspaceChatMessage;
|
|
10
|
+
}>;
|
|
11
|
+
export declare function listWorkspaceChatParticipants(workspaceId: string, channelId: string, options?: InternalApiClientOptions): Promise<WorkspaceChatParticipant[]>;
|
|
12
|
+
export declare function upsertWorkspaceChatParticipant(workspaceId: string, channelId: string, payload: {
|
|
13
|
+
last_read_at?: string;
|
|
14
|
+
}, options?: InternalApiClientOptions): Promise<{
|
|
15
|
+
success: true;
|
|
16
|
+
}>;
|
|
17
|
+
export declare function upsertWorkspaceChatTyping(workspaceId: string, channelId: string, options?: InternalApiClientOptions): Promise<{
|
|
18
|
+
success: true;
|
|
19
|
+
}>;
|
|
20
|
+
export declare function deleteWorkspaceChatTyping(workspaceId: string, channelId: string, options?: InternalApiClientOptions): Promise<{
|
|
21
|
+
success: true;
|
|
22
|
+
}>;
|
|
23
|
+
//# sourceMappingURL=chat-legacy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chat-legacy.d.ts","sourceRoot":"","sources":["../src/chat-legacy.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,oBAAoB,EACpB,oBAAoB,EACpB,wBAAwB,EACzB,MAAM,cAAc,CAAC;AACtB,OAAO,EAGL,KAAK,wBAAwB,EAC9B,MAAM,UAAU,CAAC;AAElB,wBAAsB,yBAAyB,CAC7C,WAAW,EAAE,MAAM,EACnB,OAAO,CAAC,EAAE,wBAAwB,mCAQnC;AAED,wBAAsB,0BAA0B,CAC9C,WAAW,EAAE,MAAM,EACnB,IAAI,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE,wBAAwB;aAGJ,oBAAoB;GASnD;AAED,wBAAsB,yBAAyB,CAC7C,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,MAAM,EACjB,OAAO,CAAC,EAAE,wBAAwB,mCAUnC;AAED,wBAAsB,0BAA0B,CAC9C,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE,wBAAwB;aAGJ,oBAAoB;GAWnD;AAED,wBAAsB,6BAA6B,CACjD,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,MAAM,EACjB,OAAO,CAAC,EAAE,wBAAwB,uCAYnC;AAED,wBAAsB,8BAA8B,CAClD,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE;IAAE,YAAY,CAAC,EAAE,MAAM,CAAA;CAAE,EAClC,OAAO,CAAC,EAAE,wBAAwB;aAGJ,IAAI;GAWnC;AAED,wBAAsB,yBAAyB,CAC7C,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,MAAM,EACjB,OAAO,CAAC,EAAE,wBAAwB;aAGJ,IAAI;GASnC;AAED,wBAAsB,yBAAyB,CAC7C,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,MAAM,EACjB,OAAO,CAAC,EAAE,wBAAwB;aAGJ,IAAI;GASnC"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.listWorkspaceChatChannels = listWorkspaceChatChannels;
|
|
4
|
+
exports.createWorkspaceChatChannel = createWorkspaceChatChannel;
|
|
5
|
+
exports.listWorkspaceChatMessages = listWorkspaceChatMessages;
|
|
6
|
+
exports.createWorkspaceChatMessage = createWorkspaceChatMessage;
|
|
7
|
+
exports.listWorkspaceChatParticipants = listWorkspaceChatParticipants;
|
|
8
|
+
exports.upsertWorkspaceChatParticipant = upsertWorkspaceChatParticipant;
|
|
9
|
+
exports.upsertWorkspaceChatTyping = upsertWorkspaceChatTyping;
|
|
10
|
+
exports.deleteWorkspaceChatTyping = deleteWorkspaceChatTyping;
|
|
11
|
+
const chat_internal_1 = require("./chat-internal");
|
|
12
|
+
const client_1 = require("./client");
|
|
13
|
+
async function listWorkspaceChatChannels(workspaceId, options) {
|
|
14
|
+
const client = (0, client_1.getInternalApiClient)(options);
|
|
15
|
+
const payload = await client.json(`${(0, chat_internal_1.chatBasePath)(workspaceId)}/channels`, { cache: 'no-store' });
|
|
16
|
+
return payload.channels ?? [];
|
|
17
|
+
}
|
|
18
|
+
async function createWorkspaceChatChannel(workspaceId, name, options) {
|
|
19
|
+
const client = (0, client_1.getInternalApiClient)(options);
|
|
20
|
+
return client.json(`${(0, chat_internal_1.chatBasePath)(workspaceId)}/channels`, {
|
|
21
|
+
body: JSON.stringify({ name }),
|
|
22
|
+
cache: 'no-store',
|
|
23
|
+
headers: { 'Content-Type': 'application/json' },
|
|
24
|
+
method: 'POST',
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
async function listWorkspaceChatMessages(workspaceId, channelId, options) {
|
|
28
|
+
const client = (0, client_1.getInternalApiClient)(options);
|
|
29
|
+
const payload = await client.json(`${(0, chat_internal_1.chatBasePath)(workspaceId)}/channels/${(0, client_1.encodePathSegment)(channelId)}/messages`, { cache: 'no-store' });
|
|
30
|
+
return payload.messages ?? [];
|
|
31
|
+
}
|
|
32
|
+
async function createWorkspaceChatMessage(workspaceId, channelId, content, options) {
|
|
33
|
+
const client = (0, client_1.getInternalApiClient)(options);
|
|
34
|
+
return client.json(`${(0, chat_internal_1.chatBasePath)(workspaceId)}/channels/${(0, client_1.encodePathSegment)(channelId)}/messages`, {
|
|
35
|
+
body: JSON.stringify({ content }),
|
|
36
|
+
cache: 'no-store',
|
|
37
|
+
headers: { 'Content-Type': 'application/json' },
|
|
38
|
+
method: 'POST',
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
async function listWorkspaceChatParticipants(workspaceId, channelId, options) {
|
|
42
|
+
const client = (0, client_1.getInternalApiClient)(options);
|
|
43
|
+
const payload = await client.json(`${(0, chat_internal_1.chatBasePath)(workspaceId)}/channels/${(0, client_1.encodePathSegment)(channelId)}/participants`, { cache: 'no-store' });
|
|
44
|
+
return payload.participants ?? [];
|
|
45
|
+
}
|
|
46
|
+
async function upsertWorkspaceChatParticipant(workspaceId, channelId, payload, options) {
|
|
47
|
+
const client = (0, client_1.getInternalApiClient)(options);
|
|
48
|
+
return client.json(`${(0, chat_internal_1.chatBasePath)(workspaceId)}/channels/${(0, client_1.encodePathSegment)(channelId)}/participants`, {
|
|
49
|
+
body: JSON.stringify(payload),
|
|
50
|
+
cache: 'no-store',
|
|
51
|
+
headers: { 'Content-Type': 'application/json' },
|
|
52
|
+
method: 'POST',
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
async function upsertWorkspaceChatTyping(workspaceId, channelId, options) {
|
|
56
|
+
const client = (0, client_1.getInternalApiClient)(options);
|
|
57
|
+
return client.json(`${(0, chat_internal_1.chatBasePath)(workspaceId)}/channels/${(0, client_1.encodePathSegment)(channelId)}/typing`, {
|
|
58
|
+
cache: 'no-store',
|
|
59
|
+
method: 'POST',
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
async function deleteWorkspaceChatTyping(workspaceId, channelId, options) {
|
|
63
|
+
const client = (0, client_1.getInternalApiClient)(options);
|
|
64
|
+
return client.json(`${(0, chat_internal_1.chatBasePath)(workspaceId)}/channels/${(0, client_1.encodePathSegment)(channelId)}/typing`, {
|
|
65
|
+
cache: 'no-store',
|
|
66
|
+
method: 'DELETE',
|
|
67
|
+
});
|
|
68
|
+
}
|