wtt-connect 0.2.46 → 0.2.48

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/wtt-client.js +59 -9
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wtt-connect",
3
- "version": "0.2.46",
3
+ "version": "0.2.48",
4
4
  "private": false,
5
5
  "description": "WTT-native connector daemon for Codex, Claude Code, Cursor, Gemini, ACP, and other coding agent surfaces.",
6
6
  "type": "module",
package/src/wtt-client.js CHANGED
@@ -186,17 +186,67 @@ 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
+ const result = await this.httpTyping(payload, options.timeoutMs || 5000);
201
+ log('info', 'typing status sent via HTTP', {
202
+ topicId,
203
+ state,
204
+ kind: payload.status_kind || '',
205
+ broadcast: result?.broadcast ?? '',
206
+ text: payload.status_text ? String(payload.status_text).slice(0, 80) : '',
207
+ });
208
+ return;
209
+ } catch (err) {
210
+ log('warn', 'HTTP typing fallback failed; trying websocket action', { topicId, state, error: err?.message || err });
211
+ }
212
+ }
189
213
  try {
190
- await this.action('typing', {
191
- topic_id: topicId,
214
+ const result = await this.action('typing', payload, 5000);
215
+ log('info', 'typing status sent via websocket', {
216
+ topicId,
192
217
  state,
193
- ttl_ms: options.ttlMs || options.ttl_ms || 6000,
194
- ...(options.statusText ? { status_text: options.statusText } : {}),
195
- ...(options.statusKind ? { status_kind: options.statusKind } : {}),
196
- ...(options.adapter ? { adapter: options.adapter } : {}),
197
- ...(options.model ? { model: options.model } : {}),
198
- }, 5000);
199
- } catch {}
218
+ kind: payload.status_kind || '',
219
+ broadcast: result?.broadcast ?? '',
220
+ text: payload.status_text ? String(payload.status_text).slice(0, 80) : '',
221
+ });
222
+ } catch (err) {
223
+ log('warn', 'typing status dropped', { topicId, state, error: err?.message || err });
224
+ }
225
+ }
226
+
227
+ async httpTyping(payload, timeoutMs = 5000) {
228
+ const base = String(this.config.wttBaseUrl || '').replace(/\/$/, '');
229
+ if (!base || !this.config.agentId || !this.config.token) throw new Error('missing HTTP typing configuration');
230
+ const controller = new AbortController();
231
+ const timer = setTimeout(() => controller.abort(), timeoutMs);
232
+ try {
233
+ const response = await fetch(`${base}/ws/${encodeURIComponent(this.config.agentId)}/typing`, {
234
+ method: 'POST',
235
+ headers: {
236
+ 'Content-Type': 'application/json',
237
+ 'X-Agent-Token': this.config.token,
238
+ },
239
+ body: JSON.stringify(payload),
240
+ signal: controller.signal,
241
+ });
242
+ if (!response.ok) {
243
+ const detail = await response.text().catch(() => '');
244
+ throw new Error(`HTTP typing failed: ${response.status}${detail ? ` ${detail.slice(0, 160)}` : ''}`);
245
+ }
246
+ return await response.json().catch(() => ({}));
247
+ } finally {
248
+ clearTimeout(timer);
249
+ }
200
250
  }
201
251
  }
202
252