@pmate/chat-sdk 0.14.0-seq.3 → 0.14.0-seq.5

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 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
- Storybook: `GroupMentions`, `MobileGroupMentions`, and `DarkGroupMentions` use the
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
 
@@ -66,6 +66,8 @@ export type ChatGroup = Readonly<{
66
66
  status: "active";
67
67
  title: string;
68
68
  avatar?: string;
69
+ background?: string;
70
+ description?: string;
69
71
  memberIds: readonly string[];
70
72
  } | {
71
73
  status: "dissolved";
@@ -31,6 +31,8 @@ export type GroupChanges = {
31
31
  removeMembers?: readonly string[];
32
32
  title?: string;
33
33
  avatar?: string;
34
+ background?: string;
35
+ description?: string;
34
36
  };
35
37
  export type SendOptions = {
36
38
  waitFor?: "accepted" | "delivered";
@@ -111,6 +113,8 @@ export declare class ChatEngine {
111
113
  status: "active";
112
114
  title: string;
113
115
  avatar?: string;
116
+ background?: string;
117
+ description?: string;
114
118
  memberIds: readonly string[];
115
119
  } | {
116
120
  threadId: string;
@@ -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;
@@ -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(/\/+$/, "");
@@ -122,6 +122,8 @@ export declare class ChatClient {
122
122
  removeMembers?: string[];
123
123
  title?: string;
124
124
  avatar?: string;
125
+ background?: string;
126
+ description?: string;
125
127
  }): Promise<ChatRuntimeMessage>;
126
128
  dissolveGroup(input: {
127
129
  groupId: string;
@@ -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
- this.session = await loginPmateBot({
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.background !== undefined ? { background: input.background } : {}), ...(input.description !== undefined ? { description: input.description } : {}), ...(input.avatar !== undefined ? { avatar: input.avatar } : {}) },
254
265
  });
255
266
  }
256
267
  async dissolveGroup(input) {
@@ -156,6 +156,8 @@ export declare class ChatSession<T extends StoredMessage> {
156
156
  removeMembers?: readonly string[];
157
157
  title?: string;
158
158
  avatar?: string;
159
+ background?: string;
160
+ description?: string;
159
161
  }): Promise<ChatGroup>;
160
162
  dissolveGroup(target: ChatConversation | string, options?: {
161
163
  expectedRevision?: string;
@@ -8,6 +8,8 @@ export type ActiveChatGroup = {
8
8
  ownerId: string;
9
9
  title: string;
10
10
  avatar?: string;
11
+ background?: string;
12
+ description?: string;
11
13
  memberIds: readonly string[];
12
14
  revision: string;
13
15
  versionNumber: number;
@@ -115,9 +115,13 @@ 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.background != null && typeof value.background !== "string")
119
+ throw new Error("INVALID_GROUP_METADATA");
120
+ if (value.description != null && (typeof value.description !== "string" || [...value.description].length > 500))
121
+ throw new Error("INVALID_GROUP_METADATA");
118
122
  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
123
  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" });
124
+ return Object.freeze({ groupId: value.groupId, teamId: scope.teamId, ownerId: value.ownerId, title: value.title, ...(value.background == null ? {} : { background: value.background }), ...(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
125
  }
122
126
  cached(value, entry) {
123
127
  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,14 @@ 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.background === "string" && payload.background !== group.background || typeof payload.description === "string" && payload.description !== group.description || typeof payload.title === "string" && payload.title !== group.title))
46
+ return;
47
+ if (payload.background != null && typeof payload.background !== "string")
48
+ return;
49
+ if (payload.description != null && (typeof payload.description !== "string" || [...payload.description].length > 500))
46
50
  return;
47
51
  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 } : {}) };
52
+ ...(typeof payload.background === "string" ? { background: payload.background } : {}), ...(typeof payload.description === "string" ? { description: payload.description } : {}), ...(typeof payload.title === "string" ? { title: payload.title } : {}), ...(typeof payload.avatar === "string" ? { avatar: payload.avatar } : {}) };
49
53
  }
50
54
  }
51
55
  }
@@ -72,6 +72,8 @@ type ContentChoices = {
72
72
  removeMembers?: readonly string[];
73
73
  title?: string;
74
74
  avatar?: string;
75
+ background?: string;
76
+ description?: string;
75
77
  };
76
78
  };
77
79
  groupDissolve: {
@@ -58,13 +58,17 @@ 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) + Number(update.background !== 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.background !== undefined && !["default", "mist", "cream", "apricot", "sage", "aqua", "blue", "lavender", "rose"].includes(update.background))
66
+ throw new Error("INVALID_GROUP_BACKGROUND");
67
+ if (update.description !== undefined && (typeof update.description !== "string" || [...update.description.trim()].length > 500))
68
+ throw new Error("INVALID_GROUP_DESCRIPTION");
65
69
  if (update.avatar !== undefined && (typeof update.avatar !== "string" || !update.avatar.startsWith("https://") || update.avatar.length > 2048 || /\s/u.test(update.avatar)))
66
70
  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 }) } } };
71
+ 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.background === undefined ? {} : { background: update.background }), ...(update.description === undefined ? {} : { description: update.description.trim() }), ...(update.avatar === undefined ? {} : { avatar: update.avatar }) } } };
68
72
  }
69
73
  if (input.groupDissolve) {
70
74
  if (thread.kind !== "group" || !validMessageIdentifier(input.groupDissolve.expectedRevision))
@@ -123,6 +123,8 @@ export declare class ProfileChat implements Chat {
123
123
  status: "active";
124
124
  title: string;
125
125
  avatar?: string;
126
+ background?: string;
127
+ description?: string;
126
128
  memberIds: readonly string[];
127
129
  } | {
128
130
  threadId: string;
@@ -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.background == null ? {} : { background: group.background }), ...(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.background != null && typeof value.background !== "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);
@@ -49,6 +49,8 @@ export type SocialGroup = {
49
49
  ownerId: string;
50
50
  members?: readonly string[];
51
51
  title?: string;
52
+ background?: string | null;
53
+ description?: string | null;
52
54
  avatar?: string | null;
53
55
  revision: string;
54
56
  versionNumber?: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pmate/chat-sdk",
3
- "version": "0.14.0-seq.3",
3
+ "version": "0.14.0-seq.5",
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
- "@storybook/addon-docs": "^9.0.17",
85
- "@storybook/react-vite": "9.0.17",
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
  }