wtt-connect 0.2.56 → 0.2.58
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/runner.js +7 -9
- package/src/wtt-client.js +47 -2
package/package.json
CHANGED
package/src/runner.js
CHANGED
|
@@ -939,17 +939,15 @@ function renderCloudSandboxStorageInstruction(config, topicId = '') {
|
|
|
939
939
|
'- If a generated user-facing file is stored in R2/persistent output storage and should appear in WTT chat, still publish it with `wtt-connect upload-file` or a WTT artifact marker.',
|
|
940
940
|
'- If the user asks for a visual page, HTML artifact, chart, dashboard, animation, or browser preview, build it in the workspace, start a local web server, create a Cloudflare Sandbox preview URL, and return that preview URL to WTT.',
|
|
941
941
|
'- The Cloud Sandbox preview URL feature is only for WTT Cloud Sandbox agents. Do not use WTT backend artifact/media preview flows for live sandbox web servers.',
|
|
942
|
-
'- Preview servers
|
|
943
|
-
'-
|
|
944
|
-
'-
|
|
945
|
-
'-
|
|
946
|
-
'-
|
|
942
|
+
'- Preview servers are managed by the Cloudflare Sandbox Worker, not by WTT backend and not by `wtt-connect preview-port`.',
|
|
943
|
+
'- Each sandbox has one fixed live preview slot on port 5173. To create or replace a preview, call the Worker outbox `/preview/start` with a command and cwd. The Worker stops the old port-5173 dev server, starts the new one, checks reachability, exposes it publicly, and returns `preview_url`.',
|
|
944
|
+
'- The preview start command must bind to `0.0.0.0`, not `127.0.0.1` or `localhost`. The Worker auto-adds common Vite/Next/Python host flags when safe, but you should still provide explicit host flags.',
|
|
945
|
+
'- For Vite use command `npm run dev -- --host 0.0.0.0 --port 5173`; for Next use `next dev -H 0.0.0.0 -p 5173`; for Python use `python3 -m http.server 5173 --bind 0.0.0.0`.',
|
|
946
|
+
'- Never start multiple preview dev servers. If you need a new preview, call `/preview/start` again and let the Worker replace the old one.',
|
|
947
947
|
'- Do not pass `--snapshot-dir` for normal live previews. Live Cloud Sandbox previews should render as inline WTT preview cards, not as ordinary index.html/document artifacts.',
|
|
948
948
|
'- If the user explicitly asks for a persistent static artifact or downloadable HTML, publish that separately with `wtt-connect upload-artifact --dir <dir> --title "Short Title"` instead of mixing it with the live preview URL.',
|
|
949
|
-
'- If
|
|
950
|
-
|
|
951
|
-
`- Preview curl rule: curl -sS -X POST "\${WTT_SANDBOX_OUTBOX_URL:-http://wtt.preview}/preview-port" -H 'content-type: application/json' -d '{"agent_id":"'\${WTT_AGENT_ID:-cloud-agent}'","port":<port>}'`,
|
|
952
|
-
`- Prefer automatic WTT publishing when topic id is available: wtt-connect preview-port --port <port>${topicId ? ` --topic-id ${topicId}` : ' --topic-id <topic_id>'} --title "Short Title". This publishes one cloud_sandbox_preview live card.`,
|
|
949
|
+
'- If a live preview is requested, call the Worker outbox directly and include the returned `preview_url` in your reply as `[preview_url:Short Title](<preview_url>)`.',
|
|
950
|
+
`- Preview start command: curl -sS -X POST "\${WTT_SANDBOX_OUTBOX_URL:-http://wtt.preview}/preview/start" -H 'content-type: application/json' -d '{"agent_id":"'\${WTT_AGENT_ID:-cloud-agent}'","title":"Short Title","cwd":"'\$(pwd)'","command":"npm run dev -- --host 0.0.0.0 --port 5173"}'`,
|
|
953
951
|
);
|
|
954
952
|
return lines.join('\n');
|
|
955
953
|
}
|
package/src/wtt-client.js
CHANGED
|
@@ -176,13 +176,23 @@ export class WTTClient {
|
|
|
176
176
|
log('info', 'dry-run publish', { topicId, semanticType, chars: content.length });
|
|
177
177
|
return null;
|
|
178
178
|
}
|
|
179
|
-
|
|
179
|
+
const payload = {
|
|
180
180
|
topic_id: topicId,
|
|
181
181
|
content,
|
|
182
182
|
content_type: 'text',
|
|
183
183
|
semantic_type: semanticType,
|
|
184
184
|
...(metadata && typeof metadata === 'object' ? { metadata } : {}),
|
|
185
|
-
}
|
|
185
|
+
};
|
|
186
|
+
try {
|
|
187
|
+
return await this.action('publish', payload, 60000);
|
|
188
|
+
} catch (err) {
|
|
189
|
+
log('warn', 'websocket publish failed; trying HTTP fallback', {
|
|
190
|
+
topicId,
|
|
191
|
+
semanticType,
|
|
192
|
+
error: err?.message || err,
|
|
193
|
+
});
|
|
194
|
+
return await this.httpPublish(payload, 60000);
|
|
195
|
+
}
|
|
186
196
|
}
|
|
187
197
|
|
|
188
198
|
async typing(topicId, state, options = {}) {
|
|
@@ -251,6 +261,41 @@ export class WTTClient {
|
|
|
251
261
|
clearTimeout(timer);
|
|
252
262
|
}
|
|
253
263
|
}
|
|
264
|
+
|
|
265
|
+
async httpPublish(payload, timeoutMs = 60000) {
|
|
266
|
+
const base = String(this.config.wttBaseUrl || '').replace(/\/$/, '');
|
|
267
|
+
if (!base || !this.config.agentId || !this.config.token) throw new Error('missing HTTP publish configuration');
|
|
268
|
+
const controller = new AbortController();
|
|
269
|
+
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
270
|
+
try {
|
|
271
|
+
const headers = { 'Content-Type': 'application/json' };
|
|
272
|
+
if (this.config.httpToken) headers.Authorization = `Bearer ${this.config.httpToken}`;
|
|
273
|
+
else headers['X-Agent-Token'] = this.config.token;
|
|
274
|
+
const response = await fetch(
|
|
275
|
+
`${base}/topics/${encodeURIComponent(payload.topic_id)}/messages?agent_id=${encodeURIComponent(this.config.agentId)}`,
|
|
276
|
+
{
|
|
277
|
+
method: 'POST',
|
|
278
|
+
headers,
|
|
279
|
+
body: JSON.stringify({
|
|
280
|
+
sender_id: this.config.agentId,
|
|
281
|
+
sender_type: 'AGENT',
|
|
282
|
+
content: payload.content,
|
|
283
|
+
content_type: payload.content_type || 'text',
|
|
284
|
+
semantic_type: payload.semantic_type || 'CHAT_REPLY',
|
|
285
|
+
...(payload.metadata ? { metadata: payload.metadata } : {}),
|
|
286
|
+
}),
|
|
287
|
+
signal: controller.signal,
|
|
288
|
+
},
|
|
289
|
+
);
|
|
290
|
+
if (!response.ok) {
|
|
291
|
+
const detail = await response.text().catch(() => '');
|
|
292
|
+
throw new Error(`HTTP publish failed: ${response.status}${detail ? ` ${detail.slice(0, 160)}` : ''}`);
|
|
293
|
+
}
|
|
294
|
+
return await response.json().catch(() => ({}));
|
|
295
|
+
} finally {
|
|
296
|
+
clearTimeout(timer);
|
|
297
|
+
}
|
|
298
|
+
}
|
|
254
299
|
}
|
|
255
300
|
|
|
256
301
|
function rid(prefix) {
|