wtt-connect 0.2.46 → 0.2.47
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/package.json +1 -1
- package/src/wtt-client.js +46 -10
package/package.json
CHANGED
package/src/wtt-client.js
CHANGED
|
@@ -186,17 +186,53 @@ export class WTTClient {
|
|
|
186
186
|
}
|
|
187
187
|
|
|
188
188
|
async typing(topicId, state, options = {}) {
|
|
189
|
+
const payload = {
|
|
190
|
+
topic_id: topicId,
|
|
191
|
+
state,
|
|
192
|
+
ttl_ms: options.ttlMs || options.ttl_ms || 6000,
|
|
193
|
+
...(options.statusText ? { status_text: options.statusText } : {}),
|
|
194
|
+
...(options.statusKind ? { status_kind: options.statusKind } : {}),
|
|
195
|
+
...(options.adapter ? { adapter: options.adapter } : {}),
|
|
196
|
+
...(options.model ? { model: options.model } : {}),
|
|
197
|
+
};
|
|
198
|
+
if (this.config.token) {
|
|
199
|
+
try {
|
|
200
|
+
await this.httpTyping(payload, options.timeoutMs || 5000);
|
|
201
|
+
return;
|
|
202
|
+
} catch (err) {
|
|
203
|
+
log('warn', 'HTTP typing fallback failed; trying websocket action', { topicId, state, error: err?.message || err });
|
|
204
|
+
}
|
|
205
|
+
}
|
|
189
206
|
try {
|
|
190
|
-
await this.action('typing',
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
207
|
+
await this.action('typing', payload, 5000);
|
|
208
|
+
} catch (err) {
|
|
209
|
+
log('warn', 'typing status dropped', { topicId, state, error: err?.message || err });
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
async httpTyping(payload, timeoutMs = 5000) {
|
|
214
|
+
const base = String(this.config.wttBaseUrl || '').replace(/\/$/, '');
|
|
215
|
+
if (!base || !this.config.agentId || !this.config.token) throw new Error('missing HTTP typing configuration');
|
|
216
|
+
const controller = new AbortController();
|
|
217
|
+
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
218
|
+
try {
|
|
219
|
+
const response = await fetch(`${base}/ws/${encodeURIComponent(this.config.agentId)}/typing`, {
|
|
220
|
+
method: 'POST',
|
|
221
|
+
headers: {
|
|
222
|
+
'Content-Type': 'application/json',
|
|
223
|
+
'X-Agent-Token': this.config.token,
|
|
224
|
+
},
|
|
225
|
+
body: JSON.stringify(payload),
|
|
226
|
+
signal: controller.signal,
|
|
227
|
+
});
|
|
228
|
+
if (!response.ok) {
|
|
229
|
+
const detail = await response.text().catch(() => '');
|
|
230
|
+
throw new Error(`HTTP typing failed: ${response.status}${detail ? ` ${detail.slice(0, 160)}` : ''}`);
|
|
231
|
+
}
|
|
232
|
+
return await response.json().catch(() => ({}));
|
|
233
|
+
} finally {
|
|
234
|
+
clearTimeout(timer);
|
|
235
|
+
}
|
|
200
236
|
}
|
|
201
237
|
}
|
|
202
238
|
|