@pmate/chat-sdk 0.2.1 → 0.2.3

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/lib/index.d.ts CHANGED
@@ -15,6 +15,7 @@ export * from "./hooks/useChatInputState";
15
15
  export * from "./hooks/useTranscriptComposer";
16
16
  export * from "./hooks/useVoiceInputController";
17
17
  export * from "./services/functionASRClient";
18
+ export * from "./services/agentSdkASRClient";
18
19
  export * from "./services/authTokenResolver";
19
20
  export * from "./runtime/botAuth";
20
21
  export * from "./runtime/botKey";
package/lib/index.js CHANGED
@@ -15,6 +15,7 @@ export * from "./hooks/useChatInputState";
15
15
  export * from "./hooks/useTranscriptComposer";
16
16
  export * from "./hooks/useVoiceInputController";
17
17
  export * from "./services/functionASRClient";
18
+ export * from "./services/agentSdkASRClient";
18
19
  export * from "./services/authTokenResolver";
19
20
  export * from "./runtime/botAuth";
20
21
  export * from "./runtime/botKey";
@@ -1,3 +1,5 @@
1
+ import { blake3 } from "@noble/hashes/blake3.js";
2
+ import { bytesToHex } from "@noble/hashes/utils.js";
1
3
  export function pairId(appId, userA, userB) {
2
4
  const [left, right] = userA <= userB ? [userA, userB] : [userB, userA];
3
5
  return stableHash(`social:v1:pair:${appId}:${left}:${right}`);
@@ -9,10 +11,5 @@ export function groupThreadId(appId, groupId) {
9
11
  return stableHash(`social:v1:group:${appId}:${groupId}`);
10
12
  }
11
13
  function stableHash(value) {
12
- let hash = 0x811c9dc5;
13
- for (let index = 0; index < value.length; index += 1) {
14
- hash ^= value.charCodeAt(index);
15
- hash = Math.imul(hash, 0x01000193);
16
- }
17
- return `h${(hash >>> 0).toString(16).padStart(8, "0")}`;
14
+ return bytesToHex(blake3(new TextEncoder().encode(value)));
18
15
  }
@@ -0,0 +1,29 @@
1
+ import { AsyncStream } from "./AsyncStream";
2
+ export type AgentSdkStreamLike = {
3
+ stream<TFinal = unknown, TChunk = Blob>(request: {
4
+ agentId: string;
5
+ stream: AsyncStream<TChunk>;
6
+ params?: Record<string, unknown>;
7
+ minChunkSizeBytes?: number;
8
+ }): {
9
+ finish(): Promise<TFinal | null>;
10
+ };
11
+ };
12
+ export type AgentSdkASRClientOptions = {
13
+ client: AgentSdkStreamLike;
14
+ agentId: string;
15
+ tokenResolver?: {
16
+ getToken(): string;
17
+ };
18
+ minChunkSizeBytes?: number;
19
+ };
20
+ /** Compatibility adapter for streaming audio through @pmate/agent-sdk. */
21
+ export declare class AgentSdkASRClient {
22
+ private readonly options;
23
+ constructor(options: AgentSdkASRClientOptions);
24
+ transcribe(blob: Blob, input?: {
25
+ lang?: string;
26
+ }): Promise<{
27
+ text: string;
28
+ }>;
29
+ }
@@ -0,0 +1,21 @@
1
+ import { AsyncStream } from "./AsyncStream";
2
+ /** Compatibility adapter for streaming audio through @pmate/agent-sdk. */
3
+ export class AgentSdkASRClient {
4
+ options;
5
+ constructor(options) {
6
+ this.options = options;
7
+ }
8
+ async transcribe(blob, input) {
9
+ const token = this.options.tokenResolver?.getToken() ?? "";
10
+ const stream = new AsyncStream();
11
+ const task = this.options.client.stream({
12
+ agentId: this.options.agentId,
13
+ stream,
14
+ params: { lang: input?.lang ?? "auto", token },
15
+ minChunkSizeBytes: this.options.minChunkSizeBytes ?? 0,
16
+ });
17
+ stream.push(blob);
18
+ stream.end();
19
+ return { text: String((await task.finish()) ?? "").trim() };
20
+ }
21
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pmate/chat-sdk",
3
- "version": "0.2.1",
3
+ "version": "0.2.3",
4
4
  "description": "Cross-platform PMate chat input components, voice input primitives, and ASR helpers",
5
5
  "type": "module",
6
6
  "main": "./lib/index.js",
@@ -39,6 +39,7 @@
39
39
  "build-storybook": "storybook build --output-dir dist"
40
40
  },
41
41
  "dependencies": {
42
+ "@noble/hashes": "^2.4.0",
42
43
  "@emoji-mart/data": "^1.2.1",
43
44
  "@emoji-mart/react": "^1.1.1",
44
45
  "@msgpack/msgpack": "^3.1.2",