wtt-connect 0.2.49 → 0.2.51

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wtt-connect",
3
- "version": "0.2.49",
3
+ "version": "0.2.51",
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/main.js CHANGED
@@ -138,7 +138,7 @@ Commands:
138
138
  opendesign-upload --dir <path>
139
139
  Alias for upload-artifact
140
140
  preview-port --port <port> [--topic-id <id>] [--snapshot-dir <dir>]
141
- Create a Cloud Sandbox preview URL and optional persistent snapshot
141
+ Create a Cloud Sandbox live preview URL; snapshots are opt-in
142
142
  cleanup-previews Stop preview servers previously registered by this agent
143
143
  help Show this help
144
144
  `);
@@ -149,6 +149,7 @@ async function previewPort(config, argv) {
149
149
  if (!Number.isInteger(port) || port < 1024 || port > 65535 || port === 3000) {
150
150
  throw new Error('preview-port requires --port <1024-65535>, excluding 3000');
151
151
  }
152
+ await assertLocalPreviewPort(port, Number(argv.portCheckTimeout || argv.timeout || 5000));
152
153
  const keepLast = previewKeepLast(config, argv);
153
154
  const cleanup = cleanupOldPreviews(config, {
154
155
  currentPort: port,
@@ -162,7 +163,8 @@ async function previewPort(config, argv) {
162
163
  const url = preview.preview_url || preview.url;
163
164
  if (!url) throw new Error('Cloud Sandbox preview API returned no URL');
164
165
  const title = String(argv.title || argv.previewName || preview.name || 'Cloud Sandbox Preview').trim();
165
- const snapshot = argv.noSnapshot ? null : await createPreviewSnapshot(config, argv, { title });
166
+ const wantsSnapshot = Boolean(String(argv.snapshotDir || '').trim()) && !argv.noSnapshot;
167
+ const snapshot = wantsSnapshot ? await createPreviewSnapshot(config, argv, { title }) : null;
166
168
  const snapshotUrl = snapshot?.snapshot_url || '';
167
169
  const markdown = JSON.stringify({
168
170
  type: 'cloud_sandbox_preview',
@@ -195,6 +197,19 @@ async function previewPort(config, argv) {
195
197
  console.log(JSON.stringify({ ok: true, port, url, preview_url: url, snapshot, markdown, cleanup, published }, null, 2));
196
198
  }
197
199
 
200
+ async function assertLocalPreviewPort(port, timeoutMs = 5000) {
201
+ const url = `http://127.0.0.1:${port}/`;
202
+ try {
203
+ await fetch(url, {
204
+ method: 'GET',
205
+ signal: AbortSignal.timeout(Math.max(1000, Math.min(Number(timeoutMs || 5000), 15000))),
206
+ });
207
+ } catch (error) {
208
+ const message = error instanceof Error ? error.message : String(error);
209
+ throw new Error(`preview-port local server is not reachable at ${url}: ${message}`);
210
+ }
211
+ }
212
+
198
213
  async function createPreviewSnapshot(config, argv, { title = 'Cloud Sandbox Preview' } = {}) {
199
214
  const dir = String(argv.snapshotDir || '').trim();
200
215
  if (!dir) return null;
package/src/runner.js CHANGED
@@ -943,11 +943,12 @@ function renderCloudSandboxStorageInstruction(config, topicId = '') {
943
943
  '- Before publishing a preview URL, verify the server is actually listening and serving content with `curl -fsS http://127.0.0.1:<port>/ >/dev/null`.',
944
944
  '- If local curl fails, fix or restart the web server first. Never publish a preview URL for a dead port.',
945
945
  '- `wtt-connect preview-port` automatically keeps the most recent preview servers for this agent and stops older registered previews beyond the retention limit. Default retention is 3 live previews; use `--keep-last <n>` only when the user asks.',
946
- '- For static pages, animations, charts, dashboards, and HTML demos, pass the generated static directory to `wtt-connect preview-port --snapshot-dir <dir> --snapshot-entry index.html` so WTT stores a persistent snapshot fallback. Live preview URLs are for recent interactive previews; snapshots/artifacts preserve history after cleanup.',
946
+ '- 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.',
947
+ '- 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.',
947
948
  '- If you start a web server in the sandbox and the user should preview it, call the Cloudflare Sandbox outbound Worker directly with curl and include the returned `preview_url` in your reply as `[preview_url:Short Title](<preview_url>)`.',
948
949
  '- Preview ports must be 1024-65535 and cannot be 3000. For Vite/Next-style dev servers prefer 5173, 4173, or 8080.',
949
950
  `- 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>}'`,
950
- `- 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" --snapshot-dir <static_dir> --snapshot-entry index.html. This publishes a cloud_sandbox_preview card with live and snapshot URLs.`,
951
+ `- 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.`,
951
952
  );
952
953
  return lines.join('\n');
953
954
  }