@proveanything/smartlinks 2.1.19 → 2.1.20
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/api/aiGuide.d.ts +2 -0
- package/dist/api/aiGuide.js +1 -0
- package/dist/docs/API_SUMMARY.md +2 -1
- package/dist/live.d.ts +8 -0
- package/dist/live.js +50 -8
- package/docs/API_SUMMARY.md +2 -1
- package/package.json +1 -1
package/dist/api/aiGuide.d.ts
CHANGED
|
@@ -77,6 +77,8 @@ export interface GuideStartOptions {
|
|
|
77
77
|
onCaption?: (text: string) => void;
|
|
78
78
|
onReply?: (text: string) => void;
|
|
79
79
|
onError?: (message: string) => void;
|
|
80
|
+
/** The visitor turned the microphone off or on (handle.mute / unmute). */
|
|
81
|
+
onMuted?: (muted: boolean) => void;
|
|
80
82
|
}
|
|
81
83
|
export declare namespace guide {
|
|
82
84
|
/** Is the guide on for this surface, and how does it present itself? */
|
package/dist/api/aiGuide.js
CHANGED
package/dist/docs/API_SUMMARY.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Smartlinks API Summary
|
|
2
2
|
|
|
3
|
-
Version: 2.1.
|
|
3
|
+
Version: 2.1.20 | Generated: 2026-11-16T21:00:34.061Z
|
|
4
4
|
|
|
5
5
|
This is a concise summary of all available API functions and types.
|
|
6
6
|
|
|
@@ -12154,6 +12154,7 @@ interface GuideStartOptions {
|
|
|
12154
12154
|
onCaption?: (text: string) => void
|
|
12155
12155
|
onReply?: (text: string) => void
|
|
12156
12156
|
onError?: (message: string) => void
|
|
12157
|
+
onMuted?: (muted: boolean) => void
|
|
12157
12158
|
}
|
|
12158
12159
|
```
|
|
12159
12160
|
|
package/dist/live.d.ts
CHANGED
|
@@ -52,6 +52,8 @@ export interface LiveOptions {
|
|
|
52
52
|
/** A server tool's reply, for the page to act on (cards, screens to open…). */
|
|
53
53
|
onToolReply?: (name: string, reply: LiveToolReply) => void | Promise<void>;
|
|
54
54
|
onError?: (message: string) => void;
|
|
55
|
+
/** The microphone was muted or unmuted (mute / unmute). */
|
|
56
|
+
onMuted?: (muted: boolean) => void;
|
|
55
57
|
/** Names this client in the logs. */
|
|
56
58
|
build?: string;
|
|
57
59
|
}
|
|
@@ -60,6 +62,12 @@ export interface LiveHandle {
|
|
|
60
62
|
/** Stop listening and speaking without ending the session; anything it would say waits for `resume`. */
|
|
61
63
|
pause: () => void;
|
|
62
64
|
resume: () => void;
|
|
65
|
+
/** Stop listening, and only that: the assistant finishes what it is saying, keeps working, and still speaks. */
|
|
66
|
+
mute: () => void;
|
|
67
|
+
unmute: () => void;
|
|
68
|
+
muted: () => boolean;
|
|
69
|
+
/** Stop the sentence it is saying now; it keeps listening. */
|
|
70
|
+
hush: () => void;
|
|
63
71
|
/** Text mode (or voice): give the assistant the person's words and have it answer. */
|
|
64
72
|
send: (text: string) => void;
|
|
65
73
|
/** Tell the assistant something that happened in the page, and have it answer. */
|
package/dist/live.js
CHANGED
|
@@ -11,6 +11,8 @@
|
|
|
11
11
|
// Voice: microphone in, speech out, captions of what the assistant says. Text: no microphone, the person
|
|
12
12
|
// types (`send`), the assistant answers in text (captions carry it).
|
|
13
13
|
const CALLS_URL = 'https://api.openai.com/v1/realtime/calls';
|
|
14
|
+
/** The service's answers that mean "there was nothing to cancel or clear": not shown as errors. */
|
|
15
|
+
const HARMLESS = /response_cancel_not_active|no active response|output_audio_buffer|nothing to clear/i;
|
|
14
16
|
function meter(ctx, stream) {
|
|
15
17
|
const analyser = ctx.createAnalyser();
|
|
16
18
|
analyser.fftSize = 256;
|
|
@@ -42,6 +44,9 @@ export async function startLive(opts) {
|
|
|
42
44
|
let replyOwed = false;
|
|
43
45
|
let micTrack = null;
|
|
44
46
|
let micSender = null;
|
|
47
|
+
// A reply is being made (between response.created and response.done): only then is there one to cancel.
|
|
48
|
+
let responding = false;
|
|
49
|
+
let muted = false;
|
|
45
50
|
let micLevel = () => 0;
|
|
46
51
|
let voiceLevel = () => 0;
|
|
47
52
|
const log = (e) => {
|
|
@@ -119,12 +124,12 @@ export async function startLive(opts) {
|
|
|
119
124
|
send({ type: 'conversation.item.create', item: { type: 'function_call_output', call_id: call.call_id, output: JSON.stringify(output !== null && output !== void 0 ? output : {}) } });
|
|
120
125
|
}
|
|
121
126
|
dc.onmessage = (e) => {
|
|
122
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
127
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
123
128
|
let ev;
|
|
124
129
|
try {
|
|
125
130
|
ev = JSON.parse(String(e.data));
|
|
126
131
|
}
|
|
127
|
-
catch (
|
|
132
|
+
catch (_l) {
|
|
128
133
|
return;
|
|
129
134
|
}
|
|
130
135
|
const type = String((_a = ev['type']) !== null && _a !== void 0 ? _a : '');
|
|
@@ -133,6 +138,7 @@ export async function startLive(opts) {
|
|
|
133
138
|
else if (type === 'input_audio_buffer.speech_stopped')
|
|
134
139
|
setState('thinking');
|
|
135
140
|
else if (type === 'response.created') {
|
|
141
|
+
responding = true;
|
|
136
142
|
caption = '';
|
|
137
143
|
if (textMode)
|
|
138
144
|
setState('thinking');
|
|
@@ -148,6 +154,7 @@ export async function startLive(opts) {
|
|
|
148
154
|
(_c = opts.onCaption) === null || _c === void 0 ? void 0 : _c.call(opts, caption);
|
|
149
155
|
}
|
|
150
156
|
else if (type === 'response.done') {
|
|
157
|
+
responding = false;
|
|
151
158
|
if (caption.trim()) {
|
|
152
159
|
replies++;
|
|
153
160
|
(_d = opts.onReply) === null || _d === void 0 ? void 0 : _d.call(opts, caption.trim());
|
|
@@ -167,9 +174,13 @@ export async function startLive(opts) {
|
|
|
167
174
|
setState('listening');
|
|
168
175
|
}
|
|
169
176
|
else if (type === 'error') {
|
|
170
|
-
const
|
|
177
|
+
const err = ((_g = ev['error']) !== null && _g !== void 0 ? _g : {});
|
|
178
|
+
const message = String((_h = err['message']) !== null && _h !== void 0 ? _h : 'The assistant hit a problem');
|
|
179
|
+
// "Nothing to cancel" (a pause or a stop between replies) is not a problem: say nothing.
|
|
180
|
+
if (HARMLESS.test(String((_j = err['code']) !== null && _j !== void 0 ? _j : '')) || HARMLESS.test(message))
|
|
181
|
+
return;
|
|
171
182
|
log({ kind: 'error', error: message, detail: 'realtime service' });
|
|
172
|
-
(
|
|
183
|
+
(_k = opts.onError) === null || _k === void 0 ? void 0 : _k.call(opts, message);
|
|
173
184
|
}
|
|
174
185
|
};
|
|
175
186
|
pc.onconnectionstatechange = () => {
|
|
@@ -266,8 +277,9 @@ export async function startLive(opts) {
|
|
|
266
277
|
paused = true;
|
|
267
278
|
void (micSender === null || micSender === void 0 ? void 0 : micSender.replaceTrack(null).catch(() => undefined));
|
|
268
279
|
send({ type: 'input_audio_buffer.clear' });
|
|
269
|
-
|
|
270
|
-
|
|
280
|
+
if (responding)
|
|
281
|
+
send({ type: 'response.cancel' });
|
|
282
|
+
if (!textMode && state === 'speaking')
|
|
271
283
|
send({ type: 'output_audio_buffer.clear' });
|
|
272
284
|
if (audio)
|
|
273
285
|
audio.muted = true;
|
|
@@ -280,7 +292,8 @@ export async function startLive(opts) {
|
|
|
280
292
|
if (stopped || !paused)
|
|
281
293
|
return;
|
|
282
294
|
paused = false;
|
|
283
|
-
|
|
295
|
+
if (!muted)
|
|
296
|
+
void (micSender === null || micSender === void 0 ? void 0 : micSender.replaceTrack(micTrack).catch(() => undefined));
|
|
284
297
|
if (audio)
|
|
285
298
|
audio.muted = false;
|
|
286
299
|
state = 'listening';
|
|
@@ -293,6 +306,35 @@ export async function startLive(opts) {
|
|
|
293
306
|
replyOwed = false;
|
|
294
307
|
log({ kind: 'resume', detail: waiting.length ? `${waiting.length} message(s) held while paused` : '' });
|
|
295
308
|
},
|
|
309
|
+
mute: () => {
|
|
310
|
+
var _a;
|
|
311
|
+
if (stopped || muted || state === 'connecting' || textMode)
|
|
312
|
+
return;
|
|
313
|
+
muted = true;
|
|
314
|
+
void (micSender === null || micSender === void 0 ? void 0 : micSender.replaceTrack(null).catch(() => undefined));
|
|
315
|
+
send({ type: 'input_audio_buffer.clear' });
|
|
316
|
+
(_a = opts.onMuted) === null || _a === void 0 ? void 0 : _a.call(opts, true);
|
|
317
|
+
log({ kind: 'pause', detail: 'mic muted' });
|
|
318
|
+
},
|
|
319
|
+
unmute: () => {
|
|
320
|
+
var _a;
|
|
321
|
+
if (stopped || !muted)
|
|
322
|
+
return;
|
|
323
|
+
muted = false;
|
|
324
|
+
if (!paused)
|
|
325
|
+
void (micSender === null || micSender === void 0 ? void 0 : micSender.replaceTrack(micTrack).catch(() => undefined));
|
|
326
|
+
(_a = opts.onMuted) === null || _a === void 0 ? void 0 : _a.call(opts, false);
|
|
327
|
+
log({ kind: 'resume', detail: 'mic on' });
|
|
328
|
+
},
|
|
329
|
+
muted: () => muted,
|
|
330
|
+
hush: () => {
|
|
331
|
+
if (stopped)
|
|
332
|
+
return;
|
|
333
|
+
if (responding)
|
|
334
|
+
send({ type: 'response.cancel' });
|
|
335
|
+
if (!textMode && state === 'speaking')
|
|
336
|
+
send({ type: 'output_audio_buffer.clear' });
|
|
337
|
+
},
|
|
296
338
|
send: (text) => { if (text.trim())
|
|
297
339
|
answer(text.trim()); },
|
|
298
340
|
tell: (what) => answer(`[On screen] ${what}`),
|
|
@@ -308,7 +350,7 @@ export async function startLive(opts) {
|
|
|
308
350
|
},
|
|
309
351
|
session: () => sessionId,
|
|
310
352
|
state: () => state,
|
|
311
|
-
level: () => (state === 'speaking' ? voiceLevel() : state === 'hearing' || state === 'listening' ? micLevel() : 0),
|
|
353
|
+
level: () => (state === 'speaking' ? voiceLevel() : !muted && (state === 'hearing' || state === 'listening') ? micLevel() : 0),
|
|
312
354
|
};
|
|
313
355
|
}
|
|
314
356
|
return handle();
|
package/docs/API_SUMMARY.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Smartlinks API Summary
|
|
2
2
|
|
|
3
|
-
Version: 2.1.
|
|
3
|
+
Version: 2.1.20 | Generated: 2026-11-16T21:00:34.061Z
|
|
4
4
|
|
|
5
5
|
This is a concise summary of all available API functions and types.
|
|
6
6
|
|
|
@@ -12154,6 +12154,7 @@ interface GuideStartOptions {
|
|
|
12154
12154
|
onCaption?: (text: string) => void
|
|
12155
12155
|
onReply?: (text: string) => void
|
|
12156
12156
|
onError?: (message: string) => void
|
|
12157
|
+
onMuted?: (muted: boolean) => void
|
|
12157
12158
|
}
|
|
12158
12159
|
```
|
|
12159
12160
|
|