@pmate/chat-sdk 0.14.0-seq.2 → 0.14.0-seq.4
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/README.md +1 -3
- package/lib/chatTypes.d.ts +1 -0
- package/lib/internal/chatEngine.d.ts +2 -0
- package/lib/runtime/botAuth.d.ts +1 -0
- package/lib/runtime/botAuth.js +1 -0
- package/lib/runtime/chatClient.d.ts +1 -0
- package/lib/runtime/chatClient.js +36 -5
- package/lib/runtime/chatSession.d.ts +1 -0
- package/lib/runtime/groupClient.d.ts +1 -0
- package/lib/runtime/groupClient.js +3 -1
- package/lib/runtime/inboxGroup.js +4 -2
- package/lib/runtime/outgoingContent.d.ts +1 -0
- package/lib/runtime/outgoingContent.js +4 -2
- package/lib/runtime/profileChat.d.ts +1 -0
- package/lib/runtime/profileChat.js +2 -2
- package/lib/runtime/socialReadClient.d.ts +13 -11
- package/lib/runtime/socialReadClient.js +35 -34
- package/package.json +6 -7
package/README.md
CHANGED
|
@@ -29,9 +29,7 @@ If overriding `onKeyDown`, call `picker.inputProps.onKeyDown(event)` first and r
|
|
|
29
29
|
when `event.defaultPrevented`. Hosts supply only valid current group candidates and
|
|
30
30
|
must preserve the text offsets if transforming the message before transport.
|
|
31
31
|
|
|
32
|
-
|
|
33
|
-
production components, include duplicate names and scrolling, and support empty
|
|
34
|
-
results by typing an unmatched query.
|
|
32
|
+
For a local component preview, run `pnpm preview:component --component src/components/icons.tsx --export MicOutlineIcon --headed` in this package. For mention interactions, supply candidates through the host component, then test duplicate names, scrolling and an unmatched query.
|
|
35
33
|
|
|
36
34
|
## Connection recovery
|
|
37
35
|
|
package/lib/chatTypes.d.ts
CHANGED
|
@@ -31,6 +31,7 @@ export type GroupChanges = {
|
|
|
31
31
|
removeMembers?: readonly string[];
|
|
32
32
|
title?: string;
|
|
33
33
|
avatar?: string;
|
|
34
|
+
description?: string;
|
|
34
35
|
};
|
|
35
36
|
export type SendOptions = {
|
|
36
37
|
waitFor?: "accepted" | "delivered";
|
|
@@ -111,6 +112,7 @@ export declare class ChatEngine {
|
|
|
111
112
|
status: "active";
|
|
112
113
|
title: string;
|
|
113
114
|
avatar?: string;
|
|
115
|
+
description?: string;
|
|
114
116
|
memberIds: readonly string[];
|
|
115
117
|
} | {
|
|
116
118
|
threadId: string;
|
package/lib/runtime/botAuth.d.ts
CHANGED
|
@@ -26,6 +26,7 @@ export type BotLoginSession = {
|
|
|
26
26
|
};
|
|
27
27
|
};
|
|
28
28
|
};
|
|
29
|
+
/** Authenticate the Bot Account. Always exchange this token for the target App before business requests. */
|
|
29
30
|
export declare function loginPmateBot(input: {
|
|
30
31
|
botKey: PmateBotKeyFile;
|
|
31
32
|
authBaseUrl?: string;
|
package/lib/runtime/botAuth.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
const DEFAULT_AUTH_API_BASE_URL = "https://auth-api-v2.pmate.chat";
|
|
2
|
+
/** Authenticate the Bot Account. Always exchange this token for the target App before business requests. */
|
|
2
3
|
export async function loginPmateBot(input) {
|
|
3
4
|
const fetcher = input.fetchImpl ?? fetch;
|
|
4
5
|
const baseUrl = (input.authBaseUrl ?? DEFAULT_AUTH_API_BASE_URL).replace(/\/+$/, "");
|
|
@@ -68,11 +68,22 @@ export class ChatClient {
|
|
|
68
68
|
if (!this.botKey) {
|
|
69
69
|
throw new Error("ChatClient requires either session or PMate bot key JSON");
|
|
70
70
|
}
|
|
71
|
-
|
|
71
|
+
const account = await loginPmateBot({
|
|
72
72
|
botKey: this.botKey,
|
|
73
73
|
authBaseUrl: this.options.authBaseUrl,
|
|
74
74
|
fetchImpl: this.options.fetchImpl,
|
|
75
75
|
});
|
|
76
|
+
const identity = account.session?.identity ?? account.identity;
|
|
77
|
+
if (identity?.kind !== "bot" || identity.app || !identity.accountId)
|
|
78
|
+
throw new Error("Bot Account session required");
|
|
79
|
+
const response = await (this.options.fetchImpl ?? fetch)(`${(this.options.authBaseUrl ?? DEFAULT_AUTH_API_BASE_URL).replace(/\/+$/, "")}/session/exchange`, {
|
|
80
|
+
method: "POST", redirect: "error", headers: { authorization: `Bearer ${account.token}`, "content-type": "application/json" },
|
|
81
|
+
body: JSON.stringify({ app: this.options.appId }),
|
|
82
|
+
});
|
|
83
|
+
const payload = await response.json();
|
|
84
|
+
if (!response.ok || !payload.success || !payload.data?.token || payload.data.identity?.app !== this.options.appId || payload.data.identity?.accountId !== identity.accountId)
|
|
85
|
+
throw new Error("Bot App session exchange failed");
|
|
86
|
+
this.session = payload.data;
|
|
76
87
|
}
|
|
77
88
|
const profileId = await this.resolveProfileId();
|
|
78
89
|
if (generation !== this.generation)
|
|
@@ -250,7 +261,7 @@ export class ChatClient {
|
|
|
250
261
|
return this.sendChat(input.groupId, {
|
|
251
262
|
kind: "group", threadKind: "group", action: "groupUpdate",
|
|
252
263
|
payload: { appId: this.options.appId, groupId: input.groupId, ...(input.teamId !== undefined ? { teamId: input.teamId } : {}), expectedRevision: input.expectedRevision,
|
|
253
|
-
addMembers: input.addMembers ?? [], removeMembers: input.removeMembers ?? [], ...(input.title !== undefined ? { title: input.title } : {}), ...(input.avatar !== undefined ? { avatar: input.avatar } : {}) },
|
|
264
|
+
addMembers: input.addMembers ?? [], removeMembers: input.removeMembers ?? [], ...(input.title !== undefined ? { title: input.title } : {}), ...(input.description !== undefined ? { description: input.description } : {}), ...(input.avatar !== undefined ? { avatar: input.avatar } : {}) },
|
|
254
265
|
});
|
|
255
266
|
}
|
|
256
267
|
async dissolveGroup(input) {
|
|
@@ -322,7 +333,7 @@ export class ChatClient {
|
|
|
322
333
|
}, ChatMsgKind.DM);
|
|
323
334
|
await this.sendAndWaitForAck(auth);
|
|
324
335
|
}
|
|
325
|
-
async sendAndWaitForAck(msg) {
|
|
336
|
+
async sendAndWaitForAck(msg, recoverAuth = true) {
|
|
326
337
|
const client = this.requireClient();
|
|
327
338
|
if (msg.opcode !== ChatMsgOp.AUTH && this.connection !== "connected") {
|
|
328
339
|
throw new Error(this.connection === "authentication_required" ? "登录已失效,请重新登录" : "聊天连接正在恢复,请稍后重试");
|
|
@@ -345,7 +356,22 @@ export class ChatClient {
|
|
|
345
356
|
pending.reject(error instanceof Error ? error : new Error("Send failed"));
|
|
346
357
|
}
|
|
347
358
|
}
|
|
348
|
-
|
|
359
|
+
try {
|
|
360
|
+
return await ack;
|
|
361
|
+
}
|
|
362
|
+
catch (error) {
|
|
363
|
+
// This ACK explicitly guarantees that Hub rejected the write before
|
|
364
|
+
// processing it. Re-authenticate, then retry the exact envelope once.
|
|
365
|
+
// Disconnects/timeouts have uncertain delivery and must not be replayed here.
|
|
366
|
+
if (!recoverAuth || msg.opcode === ChatMsgOp.AUTH || !(error instanceof ChatAckError)
|
|
367
|
+
|| error.code !== "CHAT_CONNECTION_AUTH_REQUIRED" || this.client !== client
|
|
368
|
+
|| this.connection === "closed" || this.connection === "authentication_required")
|
|
369
|
+
throw error;
|
|
370
|
+
if (this.connection === "connected")
|
|
371
|
+
client.close(false);
|
|
372
|
+
await this.waitUntilReady();
|
|
373
|
+
return this.sendAndWaitForAck(msg, false);
|
|
374
|
+
}
|
|
349
375
|
}
|
|
350
376
|
handleIncoming(message) {
|
|
351
377
|
if (message.opcode === ChatMsgOp.NOTIFICATION) {
|
|
@@ -369,7 +395,7 @@ export class ChatClient {
|
|
|
369
395
|
pending.resolve(ack);
|
|
370
396
|
}
|
|
371
397
|
else {
|
|
372
|
-
pending.reject(new ChatAckError(ack.message || ack.code || "Ack failed"));
|
|
398
|
+
pending.reject(new ChatAckError(ack.message || ack.code || "Ack failed", ack.code));
|
|
373
399
|
}
|
|
374
400
|
}
|
|
375
401
|
return;
|
|
@@ -469,6 +495,11 @@ export class ChatClient {
|
|
|
469
495
|
}
|
|
470
496
|
}
|
|
471
497
|
class ChatAckError extends Error {
|
|
498
|
+
code;
|
|
499
|
+
constructor(message, code) {
|
|
500
|
+
super(message);
|
|
501
|
+
this.code = code;
|
|
502
|
+
}
|
|
472
503
|
}
|
|
473
504
|
export function createChatClient(options) {
|
|
474
505
|
return new ChatClient(options);
|
|
@@ -156,6 +156,7 @@ export declare class ChatSession<T extends StoredMessage> {
|
|
|
156
156
|
removeMembers?: readonly string[];
|
|
157
157
|
title?: string;
|
|
158
158
|
avatar?: string;
|
|
159
|
+
description?: string;
|
|
159
160
|
}): Promise<ChatGroup>;
|
|
160
161
|
dissolveGroup(target: ChatConversation | string, options?: {
|
|
161
162
|
expectedRevision?: string;
|
|
@@ -115,9 +115,11 @@ export class GroupClient {
|
|
|
115
115
|
throw new Error("INVALID_GROUP_METADATA");
|
|
116
116
|
return Object.freeze({ groupId: value.groupId, teamId: scope.teamId, ownerId: value.ownerId, revision: value.revision, versionNumber: value.versionNumber, status: "dissolved", ...(value.dissolvedBy ? { dissolvedBy: value.dissolvedBy } : {}), ...(value.dissolvedAt === undefined ? {} : { dissolvedAt: value.dissolvedAt }) });
|
|
117
117
|
}
|
|
118
|
+
if (value.description != null && (typeof value.description !== "string" || [...value.description].length > 500))
|
|
119
|
+
throw new Error("INVALID_GROUP_METADATA");
|
|
118
120
|
if (value.status !== undefined && value.status !== "active" || !Array.isArray(value.members) || !value.members.length || value.members.length > 256 || !value.members.every(validMessageIdentifier) || !value.members.includes(value.ownerId) || !value.members.includes(scope.profileId) || typeof value.title !== "string" || value.avatar !== undefined && value.avatar !== null && typeof value.avatar !== "string")
|
|
119
121
|
throw new Error("INVALID_GROUP_METADATA");
|
|
120
|
-
return Object.freeze({ groupId: value.groupId, teamId: scope.teamId, ownerId: value.ownerId, title: value.title, ...(value.avatar ? { avatar: value.avatar } : {}), memberIds: Object.freeze([...new Set(value.members)].sort()), revision: value.revision, versionNumber: value.versionNumber, status: "active" });
|
|
122
|
+
return Object.freeze({ groupId: value.groupId, teamId: scope.teamId, ownerId: value.ownerId, title: value.title, ...(value.description == null ? {} : { description: value.description }), ...(value.avatar ? { avatar: value.avatar } : {}), memberIds: Object.freeze([...new Set(value.members)].sort()), revision: value.revision, versionNumber: value.versionNumber, status: "active" });
|
|
121
123
|
}
|
|
122
124
|
cached(value, entry) {
|
|
123
125
|
return this.normalize(value.status === "dissolved" ? { appId: this.options.scope.appId, ...value } : { appId: this.options.scope.appId, ...value, members: value.memberIds }, entry);
|
|
@@ -42,10 +42,12 @@ export function projectInboxGroup(appId, groupId, teamId, events) {
|
|
|
42
42
|
const ids = members(payload.members);
|
|
43
43
|
if (!ids || !ids.includes(owner) || !group.members?.includes(actor))
|
|
44
44
|
return;
|
|
45
|
-
if (actor !== owner && (group.members.some(id => !ids.includes(id)) || typeof payload.avatar === "string" && payload.avatar !== group.avatar || typeof payload.title === "string" && payload.title !== group.title))
|
|
45
|
+
if (actor !== owner && (group.members.some(id => !ids.includes(id)) || typeof payload.avatar === "string" && payload.avatar !== group.avatar || typeof payload.description === "string" && payload.description !== group.description || typeof payload.title === "string" && payload.title !== group.title))
|
|
46
|
+
return;
|
|
47
|
+
if (payload.description != null && (typeof payload.description !== "string" || [...payload.description].length > 500))
|
|
46
48
|
return;
|
|
47
49
|
group = { ...group, members: ids, revision: event.messageId, versionNumber: group.versionNumber + 1,
|
|
48
|
-
...(typeof payload.title === "string" ? { title: payload.title } : {}), ...(typeof payload.avatar === "string" ? { avatar: payload.avatar } : {}) };
|
|
50
|
+
...(typeof payload.description === "string" ? { description: payload.description } : {}), ...(typeof payload.title === "string" ? { title: payload.title } : {}), ...(typeof payload.avatar === "string" ? { avatar: payload.avatar } : {}) };
|
|
49
51
|
}
|
|
50
52
|
}
|
|
51
53
|
}
|
|
@@ -58,13 +58,15 @@ export function outgoingContent(scope, thread, input) {
|
|
|
58
58
|
}
|
|
59
59
|
if (input.groupUpdate) {
|
|
60
60
|
const update = input.groupUpdate, add = members(update.addMembers ?? []), remove = members(update.removeMembers ?? []);
|
|
61
|
-
if (thread.kind !== "group" || !validMessageIdentifier(update.expectedRevision) || Number(add.length > 0) + Number(remove.length > 0) + Number(update.title !== undefined) + Number(update.avatar !== undefined) !== 1)
|
|
61
|
+
if (thread.kind !== "group" || !validMessageIdentifier(update.expectedRevision) || Number(add.length > 0) + Number(remove.length > 0) + Number(update.title !== undefined) + Number(update.avatar !== undefined) + Number(update.description !== undefined) !== 1)
|
|
62
62
|
throw new Error("INVALID_GROUP_UPDATE");
|
|
63
63
|
if (update.title !== undefined && (typeof update.title !== "string" || !update.title.trim() || [...update.title.trim()].length > 120))
|
|
64
64
|
throw new Error("INVALID_GROUP_TITLE");
|
|
65
|
+
if (update.description !== undefined && (typeof update.description !== "string" || [...update.description.trim()].length > 500))
|
|
66
|
+
throw new Error("INVALID_GROUP_DESCRIPTION");
|
|
65
67
|
if (update.avatar !== undefined && (typeof update.avatar !== "string" || !update.avatar.startsWith("https://") || update.avatar.length > 2048 || /\s/u.test(update.avatar)))
|
|
66
68
|
throw new Error("INVALID_GROUP_AVATAR");
|
|
67
|
-
return { to: thread.targetId, body: { kind: "group", threadKind: "group", action: "groupUpdate", payload: { ...identity, groupId: thread.targetId, expectedRevision: update.expectedRevision, addMembers: add, removeMembers: remove, ...(update.title === undefined ? {} : { title: update.title.trim() }), ...(update.avatar === undefined ? {} : { avatar: update.avatar }) } } };
|
|
69
|
+
return { to: thread.targetId, body: { kind: "group", threadKind: "group", action: "groupUpdate", payload: { ...identity, groupId: thread.targetId, expectedRevision: update.expectedRevision, addMembers: add, removeMembers: remove, ...(update.title === undefined ? {} : { title: update.title.trim() }), ...(update.description === undefined ? {} : { description: update.description.trim() }), ...(update.avatar === undefined ? {} : { avatar: update.avatar }) } } };
|
|
68
70
|
}
|
|
69
71
|
if (input.groupDissolve) {
|
|
70
72
|
if (thread.kind !== "group" || !validMessageIdentifier(input.groupDissolve.expectedRevision))
|
|
@@ -84,7 +84,7 @@ export class ProfileChat {
|
|
|
84
84
|
return;
|
|
85
85
|
const base = { groupId: group.groupId, teamId: group.teamId ?? this.teamId, ownerId: group.ownerId, revision: group.revision };
|
|
86
86
|
return group.status === "dissolved" ? { ...base, status: "dissolved", dissolvedBy: group.dissolvedBy, dissolvedAt: group.dissolvedAt }
|
|
87
|
-
: { ...base, status: "active", title: group.title ?? "", avatar: group.avatar ?? undefined, memberIds: group.members ?? [] };
|
|
87
|
+
: { ...base, status: "active", title: group.title ?? "", avatar: group.avatar ?? undefined, ...(group.description == null ? {} : { description: group.description }), memberIds: group.members ?? [] };
|
|
88
88
|
}
|
|
89
89
|
empty(id) {
|
|
90
90
|
return { threadId: id, messages: [], hasEarlier: false, unread: undefined, group: undefined, readCounts: undefined, status: "pending", ready: false };
|
|
@@ -379,7 +379,7 @@ export class ProfileChat {
|
|
|
379
379
|
throw Error("INVALID_GROUP_METADATA");
|
|
380
380
|
if (value.status === "active" && (!Array.isArray(value.members) || !value.members.length || value.members.length > 256 ||
|
|
381
381
|
!value.members.every(validMessageIdentifier) || !value.members.includes(value.ownerId) || !value.members.includes(this.host.identity.profileId) ||
|
|
382
|
-
typeof value.title !== "string" || value.avatar != null && typeof value.avatar !== "string"))
|
|
382
|
+
typeof value.title !== "string" || value.description != null && (typeof value.description !== "string" || [...value.description].length > 500) || value.avatar != null && typeof value.avatar !== "string"))
|
|
383
383
|
throw Error("INVALID_GROUP_METADATA");
|
|
384
384
|
try {
|
|
385
385
|
await this.host.submit({ type: "groupSnapshot", threadId: id, group: value, expectedAccessRevision, expectedControlRevision }, true);
|
|
@@ -22,14 +22,15 @@ export type MessageThreadSummary = {
|
|
|
22
22
|
lastReplyAt: number | null;
|
|
23
23
|
participantProfileIds: string[];
|
|
24
24
|
};
|
|
25
|
-
export type
|
|
25
|
+
export type TeamTask = {
|
|
26
26
|
id: string;
|
|
27
27
|
teamId: string;
|
|
28
28
|
discussionId: string;
|
|
29
29
|
threadId: string;
|
|
30
30
|
title: string;
|
|
31
31
|
description: string;
|
|
32
|
-
|
|
32
|
+
kind: "standard" | "flow";
|
|
33
|
+
status: "todo" | "inProgress" | "done";
|
|
33
34
|
assigneeId: string | null;
|
|
34
35
|
revision: number;
|
|
35
36
|
createdBy: string;
|
|
@@ -37,8 +38,8 @@ export type TeamIssue = {
|
|
|
37
38
|
updatedBy: string;
|
|
38
39
|
updatedAt: number;
|
|
39
40
|
};
|
|
40
|
-
export type
|
|
41
|
-
|
|
41
|
+
export type TeamTaskPage = {
|
|
42
|
+
tasks: TeamTask[];
|
|
42
43
|
nextAfterId: string | null;
|
|
43
44
|
};
|
|
44
45
|
export type SocialGroup = {
|
|
@@ -48,6 +49,7 @@ export type SocialGroup = {
|
|
|
48
49
|
ownerId: string;
|
|
49
50
|
members?: readonly string[];
|
|
50
51
|
title?: string;
|
|
52
|
+
description?: string | null;
|
|
51
53
|
avatar?: string | null;
|
|
52
54
|
revision: string;
|
|
53
55
|
versionNumber?: number;
|
|
@@ -104,18 +106,18 @@ export declare class SocialReadClient {
|
|
|
104
106
|
revision: number;
|
|
105
107
|
items: MessageThreadSummary[];
|
|
106
108
|
}>;
|
|
107
|
-
|
|
109
|
+
teamTasks(input: {
|
|
108
110
|
teamId: string;
|
|
109
111
|
afterId?: string;
|
|
110
112
|
limit?: number;
|
|
111
|
-
}, signal?: AbortSignal): Promise<
|
|
112
|
-
|
|
113
|
+
}, signal?: AbortSignal): Promise<TeamTaskPage>;
|
|
114
|
+
teamTask(input: {
|
|
113
115
|
teamId: string;
|
|
114
116
|
id: string;
|
|
115
|
-
}, signal?: AbortSignal): Promise<
|
|
116
|
-
|
|
117
|
+
}, signal?: AbortSignal): Promise<TeamTask>;
|
|
118
|
+
taskMessagePage(input: {
|
|
117
119
|
teamId: string;
|
|
118
|
-
|
|
120
|
+
taskId: string;
|
|
119
121
|
limit?: number;
|
|
120
122
|
before?: string;
|
|
121
123
|
after?: string;
|
|
@@ -128,7 +130,7 @@ export declare class SocialReadClient {
|
|
|
128
130
|
peerId: string;
|
|
129
131
|
teamId?: string;
|
|
130
132
|
}): Promise<SocialRelationship | null>;
|
|
131
|
-
private
|
|
133
|
+
private requireMerryTaskTeam;
|
|
132
134
|
private teamQuery;
|
|
133
135
|
private requireTeam;
|
|
134
136
|
private list;
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import { messageThreadRoot, validMessageThreadRoot } from "./messageThread.js";
|
|
2
2
|
import { groupThreadId, isValidChatTeamId } from "./thread.js";
|
|
3
|
-
const
|
|
4
|
-
function
|
|
3
|
+
const taskId = (value) => typeof value === "string" && /^(?:iss|tsk)_[a-f0-9]{64}$/.test(value);
|
|
4
|
+
function teamTask(value, teamId) {
|
|
5
5
|
if (!value || typeof value !== "object")
|
|
6
6
|
return false;
|
|
7
7
|
const row = value;
|
|
8
|
-
return row.teamId === teamId &&
|
|
8
|
+
return row.teamId === teamId && taskId(row.id) && row.discussionId === row.id &&
|
|
9
9
|
row.threadId === groupThreadId("pmate:merry", row.discussionId, teamId) &&
|
|
10
10
|
typeof row.title === "string" && typeof row.description === "string" &&
|
|
11
|
-
(row.
|
|
11
|
+
(row.kind === "standard" || row.kind === "flow") &&
|
|
12
|
+
(row.status === "todo" || row.status === "inProgress" || row.status === "done") &&
|
|
12
13
|
(row.assigneeId === null || typeof row.assigneeId === "string") &&
|
|
13
14
|
typeof row.revision === "number" && Number.isSafeInteger(row.revision) && row.revision > 0 &&
|
|
14
15
|
typeof row.createdBy === "string" && Number.isSafeInteger(row.createdAt) &&
|
|
@@ -84,53 +85,53 @@ export class SocialReadClient {
|
|
|
84
85
|
throw new SocialReadError(502, "INVALID_MESSAGE_THREAD_SUMMARY_RESPONSE");
|
|
85
86
|
return value;
|
|
86
87
|
}
|
|
87
|
-
async
|
|
88
|
-
this.
|
|
88
|
+
async teamTasks(input, signal) {
|
|
89
|
+
this.requireMerryTaskTeam(input.teamId);
|
|
89
90
|
const limit = input.limit ?? 50;
|
|
90
91
|
if (!Number.isSafeInteger(limit) || limit < 1 || limit > 100 ||
|
|
91
|
-
(input.afterId !== undefined && !
|
|
92
|
-
throw new SocialReadError(400, "
|
|
92
|
+
(input.afterId !== undefined && !taskId(input.afterId))) {
|
|
93
|
+
throw new SocialReadError(400, "INVALID_TASK_QUERY");
|
|
93
94
|
}
|
|
94
|
-
const page = await this.request("
|
|
95
|
+
const page = await this.request("v2/tasks", {
|
|
95
96
|
teamId: input.teamId,
|
|
96
97
|
limit: String(limit),
|
|
97
98
|
...(input.afterId === undefined ? {} : { afterId: input.afterId }),
|
|
98
99
|
}, signal);
|
|
99
|
-
if (!page || !Array.isArray(page.
|
|
100
|
-
page.
|
|
101
|
-
const prior = index === 0 ? input.afterId : page.
|
|
102
|
-
return !
|
|
103
|
-
}) || (page.nextAfterId !== null && (!
|
|
104
|
-
page.
|
|
105
|
-
throw new SocialReadError(502, "
|
|
100
|
+
if (!page || !Array.isArray(page.tasks) || page.tasks.length > limit ||
|
|
101
|
+
page.tasks.some((row, index) => {
|
|
102
|
+
const prior = index === 0 ? input.afterId : page.tasks[index - 1]?.id;
|
|
103
|
+
return !teamTask(row, input.teamId) || (prior !== undefined && row.id <= prior);
|
|
104
|
+
}) || (page.nextAfterId !== null && (!taskId(page.nextAfterId) ||
|
|
105
|
+
page.tasks.length !== limit || page.tasks.at(-1)?.id !== page.nextAfterId))) {
|
|
106
|
+
throw new SocialReadError(502, "INVALID_TASK_PAGE_RESPONSE");
|
|
106
107
|
}
|
|
107
108
|
return page;
|
|
108
109
|
}
|
|
109
|
-
async
|
|
110
|
-
this.
|
|
111
|
-
if (!
|
|
112
|
-
throw new SocialReadError(400, "
|
|
113
|
-
const data = await this.request("
|
|
114
|
-
if (!
|
|
115
|
-
throw new SocialReadError(502, "
|
|
110
|
+
async teamTask(input, signal) {
|
|
111
|
+
this.requireMerryTaskTeam(input.teamId);
|
|
112
|
+
if (!taskId(input.id))
|
|
113
|
+
throw new SocialReadError(400, "INVALID_TASK_ID");
|
|
114
|
+
const data = await this.request("v2/tasks", { teamId: input.teamId, id: input.id }, signal);
|
|
115
|
+
if (!teamTask(data?.task, input.teamId) || data.task.id !== input.id) {
|
|
116
|
+
throw new SocialReadError(502, "INVALID_TASK_RESPONSE");
|
|
116
117
|
}
|
|
117
|
-
return data.
|
|
118
|
+
return data.task;
|
|
118
119
|
}
|
|
119
|
-
async
|
|
120
|
-
const { teamId,
|
|
121
|
-
this.
|
|
122
|
-
if (!
|
|
123
|
-
throw new SocialReadError(400, "
|
|
120
|
+
async taskMessagePage(input, signal) {
|
|
121
|
+
const { teamId, taskId: id, before, after, limit = 50 } = input;
|
|
122
|
+
this.requireMerryTaskTeam(teamId);
|
|
123
|
+
if (!taskId(id))
|
|
124
|
+
throw new SocialReadError(400, "INVALID_TASK_ID");
|
|
124
125
|
if (!Number.isSafeInteger(limit) || limit < 1 || limit > 500 || (before !== undefined && after !== undefined)) {
|
|
125
126
|
throw new SocialReadError(400, "INVALID_MESSAGE_PAGE");
|
|
126
127
|
}
|
|
127
|
-
const page = await this.request("
|
|
128
|
-
|
|
128
|
+
const page = await this.request("v2/tasks/messages", {
|
|
129
|
+
taskId: id, teamId, limit: String(limit),
|
|
129
130
|
...(before === undefined ? {} : { before }), ...(after === undefined ? {} : { after }),
|
|
130
131
|
}, signal);
|
|
131
132
|
this.validateMessagePage(page, { teamId, threadId: groupThreadId("pmate:merry", id, teamId) }, limit);
|
|
132
133
|
if (page.messages.some(row => row.threadKind !== "group" || row.to !== id)) {
|
|
133
|
-
throw new SocialReadError(502, "
|
|
134
|
+
throw new SocialReadError(502, "INVALID_TASK_MESSAGE_PAGE_RESPONSE");
|
|
134
135
|
}
|
|
135
136
|
return page;
|
|
136
137
|
}
|
|
@@ -141,9 +142,9 @@ export class SocialReadClient {
|
|
|
141
142
|
this.requireTeam(input.teamId);
|
|
142
143
|
return this.request("relationship", { peerId: input.peerId, ...this.teamQuery(input.teamId) });
|
|
143
144
|
}
|
|
144
|
-
|
|
145
|
+
requireMerryTaskTeam(teamId) {
|
|
145
146
|
if (this.options.appId !== "pmate:merry" || !isValidChatTeamId(teamId)) {
|
|
146
|
-
throw new SocialReadError(400, "
|
|
147
|
+
throw new SocialReadError(400, "MERRY_TASK_TEAM_REQUIRED");
|
|
147
148
|
}
|
|
148
149
|
}
|
|
149
150
|
teamQuery(teamId) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pmate/chat-sdk",
|
|
3
|
-
"version": "0.14.0-seq.
|
|
3
|
+
"version": "0.14.0-seq.4",
|
|
4
4
|
"description": "Local-first chat SDK, message subscriptions, reading state, and shared chat UI primitives",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./lib/index.js",
|
|
@@ -81,8 +81,9 @@
|
|
|
81
81
|
"react-dom": "*"
|
|
82
82
|
},
|
|
83
83
|
"devDependencies": {
|
|
84
|
-
"
|
|
85
|
-
"@
|
|
84
|
+
"esbuild": "0.25.12",
|
|
85
|
+
"@tailwindcss/node": "4.1.18",
|
|
86
|
+
"@tailwindcss/oxide": "4.1.18",
|
|
86
87
|
"@tailwindcss/vite": "^4.1.3",
|
|
87
88
|
"@types/react": "^19.2.7",
|
|
88
89
|
"@types/react-dom": "^19.2.3",
|
|
@@ -90,17 +91,15 @@
|
|
|
90
91
|
"react": "^19.1.1",
|
|
91
92
|
"react-dom": "^19.1.1",
|
|
92
93
|
"rimraf": "^6.1.2",
|
|
93
|
-
"storybook": "^9.0.17",
|
|
94
94
|
"tailwindcss": "^4.0.14",
|
|
95
95
|
"typescript": "5.9.2",
|
|
96
96
|
"vitest": "^4.0.17"
|
|
97
97
|
},
|
|
98
98
|
"scripts": {
|
|
99
|
+
"preview:component": "merry-plugin browser open --plugin react-preview",
|
|
99
100
|
"clean": "rimraf lib",
|
|
100
101
|
"build": "pnpm run clean && tsc -p tsconfig.build.json && cp src/voice/recorder-processor.js lib/voice/recorder-processor.js",
|
|
101
102
|
"npm:publish": "pnpm publish --access public --registry https://registry.npmjs.org/",
|
|
102
|
-
"test": "vitest run"
|
|
103
|
-
"storybook": "storybook dev -p 6009",
|
|
104
|
-
"build-storybook": "storybook build --output-dir dist"
|
|
103
|
+
"test": "vitest run"
|
|
105
104
|
}
|
|
106
105
|
}
|