@xmoxmo/bncr 0.0.5 → 0.0.7

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.
@@ -20,6 +20,17 @@ export const BncrConfigSchema = {
20
20
  type: 'array',
21
21
  items: { type: 'string' },
22
22
  },
23
+ debug: {
24
+ type: 'object',
25
+ additionalProperties: true,
26
+ properties: {
27
+ verbose: {
28
+ type: 'boolean',
29
+ default: false,
30
+ description: 'Enable verbose debug logs for bncr channel runtime.',
31
+ },
32
+ },
33
+ },
23
34
  requireMention: {
24
35
  type: 'boolean',
25
36
  default: false,
@@ -113,7 +113,7 @@ export async function handleBncrNativeCommand(params: {
113
113
  disableBlockStreaming: true,
114
114
  },
115
115
  dispatcherOptions: {
116
- deliver: async (payload: { text?: string; mediaUrl?: string; mediaUrls?: string[] }, info?: { kind?: 'tool' | 'block' | 'final' }) => {
116
+ deliver: async (payload: { text?: string; mediaUrl?: string; mediaUrls?: string[]; audioAsVoice?: boolean }, info?: { kind?: 'tool' | 'block' | 'final' }) => {
117
117
  if (info?.kind && info.kind !== 'final') return;
118
118
  const hasPayload = Boolean(payload?.text || payload?.mediaUrl || (Array.isArray(payload?.mediaUrls) && payload.mediaUrls.length > 0));
119
119
  if (!hasPayload) return;
@@ -151,7 +151,7 @@ export async function dispatchBncrInbound(params: {
151
151
  },
152
152
  dispatcherOptions: {
153
153
  deliver: async (
154
- payload: { text?: string; mediaUrl?: string; mediaUrls?: string[] },
154
+ payload: { text?: string; mediaUrl?: string; mediaUrls?: string[]; audioAsVoice?: boolean },
155
155
  info?: { kind?: 'tool' | 'block' | 'final' },
156
156
  ) => {
157
157
  if (info?.kind && info.kind !== 'final') return;
@@ -4,6 +4,11 @@ function asString(v: unknown, fallback = ''): string {
4
4
  return String(v);
5
5
  }
6
6
 
7
+ function isAudioMimeType(mimeType?: string): boolean {
8
+ const mt = asString(mimeType || '').toLowerCase();
9
+ return mt.startsWith('audio/');
10
+ }
11
+
7
12
  export function resolveBncrOutboundMessageType(params: { mimeType?: string; fileName?: string; hintedType?: string; hasPayload?: boolean }): 'text' | 'image' | 'video' | 'voice' | 'audio' | 'file' {
8
13
  const hinted = asString(params.hintedType || '').toLowerCase();
9
14
  const hasPayload = !!params.hasPayload;
@@ -12,6 +17,11 @@ export function resolveBncrOutboundMessageType(params: { mimeType?: string; file
12
17
  const isStandard = hinted === 'text' || hinted === 'image' || hinted === 'video' || hinted === 'voice' || hinted === 'audio' || hinted === 'file';
13
18
 
14
19
  if (hasPayload && major === 'text' && (hinted === 'text' || !isStandard)) return 'file';
20
+ if (hinted === 'voice') {
21
+ if (isAudioMimeType(mt)) return 'voice';
22
+ if (major === 'text' || major === 'image' || major === 'video' || major === 'audio') return major as any;
23
+ return 'file';
24
+ }
15
25
  if (isStandard) return hinted as any;
16
26
  if (major === 'text' || major === 'image' || major === 'video' || major === 'audio') return major as any;
17
27
  return 'file';
@@ -25,6 +35,7 @@ export function buildBncrMediaOutboundFrame(params: {
25
35
  mediaUrl: string;
26
36
  mediaMsg: string;
27
37
  fileName: string;
38
+ hintedType?: string;
28
39
  now: number;
29
40
  }) {
30
41
  return {
@@ -40,6 +51,7 @@ export function buildBncrMediaOutboundFrame(params: {
40
51
  mimeType: params.media.mimeType,
41
52
  fileName: params.media.fileName,
42
53
  hasPayload: !!(params.media.path || params.media.mediaBase64),
54
+ hintedType: params.hintedType,
43
55
  }),
44
56
  mimeType: params.media.mimeType || '',
45
57
  msg: params.mediaMsg,
@@ -37,6 +37,8 @@ export async function sendBncrMedia(params: {
37
37
  to: string;
38
38
  text?: string;
39
39
  mediaUrl?: string;
40
+ asVoice?: boolean;
41
+ audioAsVoice?: boolean;
40
42
  mediaLocalRoots?: readonly string[];
41
43
  resolveVerifiedTarget: (to: string, accountId: string) => { sessionKey: string; route: any; displayScope: string };
42
44
  rememberSessionRoute: (sessionKey: string, accountId: string, route: any) => void;
@@ -44,7 +46,7 @@ export async function sendBncrMedia(params: {
44
46
  accountId: string;
45
47
  sessionKey: string;
46
48
  route: any;
47
- payload: { text?: string; mediaUrl?: string; mediaUrls?: string[] };
49
+ payload: { text?: string; mediaUrl?: string; mediaUrls?: string[]; asVoice?: boolean; audioAsVoice?: boolean };
48
50
  mediaLocalRoots?: readonly string[];
49
51
  }) => Promise<void>;
50
52
  createMessageId: () => string;
@@ -59,6 +61,8 @@ export async function sendBncrMedia(params: {
59
61
  payload: {
60
62
  text: params.text || '',
61
63
  mediaUrl: params.mediaUrl || '',
64
+ asVoice: params.asVoice === true ? true : undefined,
65
+ audioAsVoice: params.audioAsVoice === true ? true : undefined,
62
66
  },
63
67
  mediaLocalRoots: params.mediaLocalRoots,
64
68
  });