@adminide-stack/yantra-mobile 12.0.173 → 12.0.174-alpha.0

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 (130) hide show
  1. package/lib/compute.js +54 -1
  2. package/lib/compute.js.map +1 -1
  3. package/lib/features/apps/AppsCatalog.js +10 -0
  4. package/lib/features/apps/AppsCatalog.js.map +1 -1
  5. package/lib/features/apps/mobileAppCatalog.js +6 -1
  6. package/lib/features/apps/mobileAppCatalog.js.map +1 -1
  7. package/lib/features/apps/nativeAppHandoff.js +4 -1
  8. package/lib/features/apps/nativeAppHandoff.js.map +1 -1
  9. package/lib/features/apps/nativeSurfaceTwin.js +2 -1
  10. package/lib/features/apps/nativeSurfaceTwin.js.map +1 -1
  11. package/lib/features/channels/ChannelIcon.js +13 -3
  12. package/lib/features/channels/ChannelIcon.js.map +1 -1
  13. package/lib/features/channels/ConnectAppsSheet.js +5 -5
  14. package/lib/features/channels/ConnectAppsSheet.js.map +1 -1
  15. package/lib/features/channels/HomeImessage.js +5 -3
  16. package/lib/features/channels/HomeImessage.js.map +1 -1
  17. package/lib/features/channels/channelLinks.js +13 -1
  18. package/lib/features/channels/channelLinks.js.map +1 -1
  19. package/lib/features/computer/ComputerAgentChatPane.js +45 -0
  20. package/lib/features/computer/ComputerAgentChatPane.js.map +1 -0
  21. package/lib/features/computer/ComputerDesktop.js +164 -0
  22. package/lib/features/computer/ComputerDesktop.js.map +1 -0
  23. package/lib/features/computer/ComputerExperience.js +79 -0
  24. package/lib/features/computer/ComputerExperience.js.map +1 -0
  25. package/lib/features/computer/ComputerHandoff.js +142 -0
  26. package/lib/features/computer/ComputerHandoff.js.map +1 -0
  27. package/lib/features/computer/FilesPane.js +179 -0
  28. package/lib/features/computer/FilesPane.js.map +1 -0
  29. package/lib/features/computer/LivePage.js +1093 -0
  30. package/lib/features/computer/LivePage.js.map +1 -0
  31. package/lib/features/computer/TerminalPane.js +139 -0
  32. package/lib/features/computer/TerminalPane.js.map +1 -0
  33. package/lib/features/computer/computerApi.js +819 -0
  34. package/lib/features/computer/computerApi.js.map +1 -0
  35. package/lib/features/computer/computerChat.js +42 -0
  36. package/lib/features/computer/computerChat.js.map +1 -0
  37. package/lib/features/computer/computerControls.js +227 -0
  38. package/lib/features/computer/computerControls.js.map +1 -0
  39. package/lib/features/computer/computerStyles.js +384 -0
  40. package/lib/features/computer/computerStyles.js.map +1 -0
  41. package/lib/features/computer/computerTheme.js +133 -0
  42. package/lib/features/computer/computerTheme.js.map +1 -0
  43. package/lib/features/computer/handoff.js +73 -0
  44. package/lib/features/computer/handoff.js.map +1 -0
  45. package/lib/features/computer/inputLane.js +171 -0
  46. package/lib/features/computer/inputLane.js.map +1 -0
  47. package/lib/features/computer/inputPump.js +77 -0
  48. package/lib/features/computer/inputPump.js.map +1 -0
  49. package/lib/features/computer/inputSocket.js +148 -0
  50. package/lib/features/computer/inputSocket.js.map +1 -0
  51. package/lib/features/computer/keyboardBridge.js +176 -0
  52. package/lib/features/computer/keyboardBridge.js.map +1 -0
  53. package/lib/features/computer/pageCoordinates.js +19 -0
  54. package/lib/features/computer/pageCoordinates.js.map +1 -0
  55. package/lib/features/computer/pageZoom.js +12 -0
  56. package/lib/features/computer/pageZoom.js.map +1 -0
  57. package/lib/features/computer/pictureGeometry.js +68 -0
  58. package/lib/features/computer/pictureGeometry.js.map +1 -0
  59. package/lib/features/computer/tabsState.js +7 -0
  60. package/lib/features/computer/tabsState.js.map +1 -0
  61. package/lib/features/computer/useComputerHooks.js +146 -0
  62. package/lib/features/computer/useComputerHooks.js.map +1 -0
  63. package/lib/features/links/openInApp.js +10 -1
  64. package/lib/features/links/openInApp.js.map +1 -1
  65. package/lib/features/webbuilder/WebBuilderExperience.js +180 -44
  66. package/lib/features/webbuilder/WebBuilderExperience.js.map +1 -1
  67. package/lib/features/webbuilder/buildFragments.js +16 -3
  68. package/lib/features/webbuilder/buildFragments.js.map +1 -1
  69. package/lib/features/webbuilder/codezenHandoff.js +29 -1
  70. package/lib/features/webbuilder/codezenHandoff.js.map +1 -1
  71. package/lib/features/webbuilder/components/CodeView.js +69 -23
  72. package/lib/features/webbuilder/components/CodeView.js.map +1 -1
  73. package/lib/features/webbuilder/components/PreviewFrame.js +62 -2
  74. package/lib/features/webbuilder/components/PreviewFrame.js.map +1 -1
  75. package/lib/features/webbuilder/components/PreviewScreen.js +37 -2
  76. package/lib/features/webbuilder/components/PreviewScreen.js.map +1 -1
  77. package/lib/features/webbuilder/components/ProjectChat.js +2 -1
  78. package/lib/features/webbuilder/components/ProjectChat.js.map +1 -1
  79. package/lib/features/webbuilder/components/ProjectSheets.js +147 -57
  80. package/lib/features/webbuilder/components/ProjectSheets.js.map +1 -1
  81. package/lib/features/webbuilder/components/PublishSheet.js +106 -2
  82. package/lib/features/webbuilder/components/PublishSheet.js.map +1 -1
  83. package/lib/features/webbuilder/components/ReferenceModeChoice.js +105 -0
  84. package/lib/features/webbuilder/components/ReferenceModeChoice.js.map +1 -0
  85. package/lib/features/webbuilder/components/RetentionBanner.js +17 -6
  86. package/lib/features/webbuilder/components/RetentionBanner.js.map +1 -1
  87. package/lib/features/webbuilder/components/SiteUploadSheet.js +327 -0
  88. package/lib/features/webbuilder/components/SiteUploadSheet.js.map +1 -0
  89. package/lib/features/webbuilder/components/StreamStallNote.js +38 -0
  90. package/lib/features/webbuilder/components/StreamStallNote.js.map +1 -0
  91. package/lib/features/webbuilder/components/StudioHome.js +18 -8
  92. package/lib/features/webbuilder/components/StudioHome.js.map +1 -1
  93. package/lib/features/webbuilder/previewRoutes.js +30 -1
  94. package/lib/features/webbuilder/previewRoutes.js.map +1 -1
  95. package/lib/features/webbuilder/studioCatalog.js +9 -2
  96. package/lib/features/webbuilder/studioCatalog.js.map +1 -1
  97. package/lib/features/webbuilder/web/chat/referenceMode.js +11 -0
  98. package/lib/features/webbuilder/web/chat/referenceMode.js.map +1 -0
  99. package/lib/features/webbuilder/web/chat/siteCopy.js +5 -2
  100. package/lib/features/webbuilder/web/chat/siteCopy.js.map +1 -1
  101. package/lib/features/webbuilder/web/chat/streamStall.js +6 -0
  102. package/lib/features/webbuilder/web/chat/streamStall.js.map +1 -0
  103. package/lib/features/webbuilder/web/code/savedCode.js +7 -0
  104. package/lib/features/webbuilder/web/code/savedCode.js.map +1 -0
  105. package/lib/features/webbuilder/web/design/directions.js.map +1 -1
  106. package/lib/features/webbuilder/web/history/versions.js.map +1 -1
  107. package/lib/features/webbuilder/web/import/websiteImport.js +27 -0
  108. package/lib/features/webbuilder/web/import/websiteImport.js.map +1 -0
  109. package/lib/features/webbuilder/web/preview/setupPhase.js +31 -0
  110. package/lib/features/webbuilder/web/preview/setupPhase.js.map +1 -0
  111. package/lib/features/webbuilder/web/publish/siteInsights.js +23 -1
  112. package/lib/features/webbuilder/web/publish/siteInsights.js.map +1 -1
  113. package/lib/features/webbuilder/web/upload/sitePhotos.js +102 -0
  114. package/lib/features/webbuilder/web/upload/sitePhotos.js.map +1 -0
  115. package/lib/routes.json +54 -0
  116. package/lib/screens/ComputerNative/index.js +124 -0
  117. package/lib/screens/ComputerNative/index.js.map +1 -0
  118. package/lib/screens/ComputerNative/useComputerHostChat.js +83 -0
  119. package/lib/screens/ComputerNative/useComputerHostChat.js.map +1 -0
  120. package/lib/screens/Home/components/homeCatalog.js +2 -1
  121. package/lib/screens/Home/components/homeCatalog.js.map +1 -1
  122. package/lib/screens/WebBuilder/nativeWebBuilderRedirect.js +6 -2
  123. package/lib/screens/WebBuilder/nativeWebBuilderRedirect.js.map +1 -1
  124. package/lib/screens/WebBuilderNative/index.js +15 -3
  125. package/lib/screens/WebBuilderNative/index.js.map +1 -1
  126. package/lib/screens/WebBuilderNative/useWebBuilderHost.js +18 -3
  127. package/lib/screens/WebBuilderNative/useWebBuilderHost.js.map +1 -1
  128. package/lib/screens/WebBuilderNative/webbuilderTransport.js +16 -7
  129. package/lib/screens/WebBuilderNative/webbuilderTransport.js.map +1 -1
  130. package/package.json +4 -4
@@ -0,0 +1,819 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defProps = Object.defineProperties;
3
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
+ var __spreadValues = (a, b) => {
9
+ for (var prop in b || (b = {}))
10
+ if (__hasOwnProp.call(b, prop))
11
+ __defNormalProp(a, prop, b[prop]);
12
+ if (__getOwnPropSymbols)
13
+ for (var prop of __getOwnPropSymbols(b)) {
14
+ if (__propIsEnum.call(b, prop))
15
+ __defNormalProp(a, prop, b[prop]);
16
+ }
17
+ return a;
18
+ };
19
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
21
+ const CONNECTOR = "yantra-computer";
22
+ const MEDIA_ARRAY_KEYS = ["artifacts", "samples", "outputs", "files", "results"];
23
+ function extractMediaUrl(result, keys) {
24
+ var _a;
25
+ const obj = (_a = result.data) != null ? _a : result;
26
+ const pick = (src) => {
27
+ if (!src) return null;
28
+ for (const k of keys) {
29
+ const v = src[k];
30
+ if (typeof v === "string" && v) return v;
31
+ if (Array.isArray(v) && typeof v[0] === "string" && v[0]) return v[0];
32
+ }
33
+ return null;
34
+ };
35
+ const direct = pick(obj);
36
+ if (direct) return direct;
37
+ for (const arrKey of MEDIA_ARRAY_KEYS) {
38
+ const arr = obj[arrKey];
39
+ if (Array.isArray(arr) && arr.length > 0) {
40
+ const fromArr = pick(arr[0]);
41
+ if (fromArr) return fromArr;
42
+ }
43
+ }
44
+ return null;
45
+ }
46
+ const NO_EXEC_MESSAGE = "Yantra is not connected yet. Try again in a moment.";
47
+ let hostExec = null;
48
+ const lentExecs = [];
49
+ function provideExec(exec2) {
50
+ lentExecs.push(exec2);
51
+ return () => {
52
+ const at = lentExecs.lastIndexOf(exec2);
53
+ if (at >= 0) lentExecs.splice(at, 1);
54
+ };
55
+ }
56
+ function unwrapHostResult(result) {
57
+ var _a;
58
+ if (result && typeof result === "object") {
59
+ const envelope = result;
60
+ if (envelope.success === false || envelope.successful === false) {
61
+ throw new Error(String((_a = envelope.error) != null ? _a : "the connector action failed"));
62
+ }
63
+ if ("data" in envelope && envelope.data && typeof envelope.data === "object") {
64
+ return envelope.data;
65
+ }
66
+ }
67
+ return result != null ? result : {};
68
+ }
69
+ const run = async (action, params, timeoutMs) => {
70
+ var _a;
71
+ const exec2 = (_a = lentExecs[lentExecs.length - 1]) != null ? _a : hostExec;
72
+ if (!exec2) throw new Error(NO_EXEC_MESSAGE);
73
+ return unwrapHostResult(await exec2(CONNECTOR, action, params, {
74
+ timeoutMs
75
+ }));
76
+ };
77
+ async function resolveWorkspace(userId) {
78
+ var _a, _b, _c;
79
+ const r = await run("YANTRA_COMPUTER_RESOLVE", {
80
+ userId
81
+ }, 6e4);
82
+ return {
83
+ workspaceId: String((_a = r.workspaceId) != null ? _a : ""),
84
+ exists: r.exists === true,
85
+ state: (_b = r.state) != null ? _b : null,
86
+ lastActiveAt: (_c = r.lastActiveAt) != null ? _c : null
87
+ };
88
+ }
89
+ async function createWorkspace(userId) {
90
+ var _a, _b, _c;
91
+ const r = await run("YANTRA_COMPUTER_CREATE", {
92
+ userId
93
+ }, 18e4);
94
+ const workspaceId = String((_b = (_a = r.workspaceId) != null ? _a : r.sandboxId) != null ? _b : "");
95
+ if (!workspaceId) throw new Error("the connector returned no workspace id");
96
+ return {
97
+ workspaceId,
98
+ exists: true,
99
+ state: (_c = r.state) != null ? _c : "running"
100
+ };
101
+ }
102
+ const ONE_WINDOW_MESSAGE = "This Computer has one window. Update the Computer to open more.";
103
+ function isMissingAction(error, action) {
104
+ const message = error instanceof Error ? error.message : String(error);
105
+ if (/unknown action/i.test(message)) return true;
106
+ if (/not found in (?:connector|registry)/i.test(message)) return true;
107
+ return message.includes(action) && /not found/i.test(message);
108
+ }
109
+ let tabsAction = "unknown";
110
+ const TABS_ACTION = "YANTRA_COMPUTER_TABS";
111
+ const windowless = /* @__PURE__ */ new Set();
112
+ const windowsListeners = /* @__PURE__ */ new Set();
113
+ function windowsAvailable(workspaceId) {
114
+ return !windowless.has(workspaceId);
115
+ }
116
+ function subscribeWindows(listener) {
117
+ windowsListeners.add(listener);
118
+ return () => {
119
+ windowsListeners.delete(listener);
120
+ };
121
+ }
122
+ function setWindowsAvailable(workspaceId, available) {
123
+ if (available === !windowless.has(workspaceId)) return;
124
+ if (available) windowless.delete(workspaceId);
125
+ else windowless.add(workspaceId);
126
+ for (const listener of [...windowsListeners]) listener(workspaceId, available);
127
+ }
128
+ function dropToOneWindow(workspaceId) {
129
+ if (windowless.has(workspaceId)) return;
130
+ console.warn("[computer] this Computer cannot show windows yet (it needs a restart); showing one window");
131
+ setWindowsAvailable(workspaceId, false);
132
+ }
133
+ function isTabsRefusal(body) {
134
+ if (!body || typeof body !== "object") return false;
135
+ const b = body;
136
+ return b.code === "tabs_unsupported" || b.needsRestart === true;
137
+ }
138
+ function isTabsRefusalError(error) {
139
+ const message = error instanceof Error ? error.message : String(error);
140
+ return /tabs_unsupported|needs_?restart|has one window/i.test(message);
141
+ }
142
+ const TAB_GONE_MESSAGE = "This window closed";
143
+ class TabGoneError extends Error {
144
+ constructor(workspaceId, tab) {
145
+ super(TAB_GONE_MESSAGE);
146
+ __publicField(this, "workspaceId");
147
+ __publicField(this, "tab");
148
+ this.name = "TabGoneError";
149
+ this.workspaceId = workspaceId;
150
+ this.tab = tab;
151
+ }
152
+ }
153
+ const TAB_GONE_MEMORY_MS = 3e4;
154
+ const goneTabs = /* @__PURE__ */ new Map();
155
+ const goneListeners = /* @__PURE__ */ new Set();
156
+ function subscribeTabsGone(listener) {
157
+ goneListeners.add(listener);
158
+ return () => {
159
+ goneListeners.delete(listener);
160
+ };
161
+ }
162
+ function isTabGone(workspaceId, tab, now = Date.now()) {
163
+ var _a;
164
+ const at = (_a = goneTabs.get(workspaceId)) == null ? void 0 : _a.get(tab);
165
+ return at !== void 0 && now - at < TAB_GONE_MEMORY_MS;
166
+ }
167
+ function markTabGone(workspaceId, tab) {
168
+ if (!workspaceId || !tab) return;
169
+ const now = Date.now();
170
+ const news = !isTabGone(workspaceId, tab, now);
171
+ let byTab = goneTabs.get(workspaceId);
172
+ if (!byTab) {
173
+ byTab = /* @__PURE__ */ new Map();
174
+ goneTabs.set(workspaceId, byTab);
175
+ }
176
+ for (const [id, at] of byTab) if (now - at >= TAB_GONE_MEMORY_MS) byTab.delete(id);
177
+ byTab.set(tab, now);
178
+ if (!news) return;
179
+ for (const listener of [...goneListeners]) listener(workspaceId, tab);
180
+ }
181
+ function withoutGoneTabs(workspaceId, tabs) {
182
+ var _a;
183
+ if (!((_a = goneTabs.get(workspaceId)) == null ? void 0 : _a.size)) return tabs;
184
+ const now = Date.now();
185
+ return tabs.filter((tab) => !isTabGone(workspaceId, tab.id, now));
186
+ }
187
+ const TAB_ID_CHAR = /[A-Za-z0-9._-]/;
188
+ function saysTabGone(text, tab) {
189
+ if (!text || !tab) return false;
190
+ const said = `no tab ${tab}`;
191
+ for (let at = text.indexOf(said); at >= 0; at = text.indexOf(said, at + 1)) {
192
+ const before = at > 0 ? text.charAt(at - 1) : "";
193
+ const after = text.charAt(at + said.length);
194
+ if (!TAB_ID_CHAR.test(before) && !TAB_ID_CHAR.test(after)) return true;
195
+ }
196
+ return false;
197
+ }
198
+ function isTabGoneAnswer(answer, tab) {
199
+ if (!answer || typeof answer !== "object") return false;
200
+ const a = answer;
201
+ return a.ok === false && typeof a.error === "string" && saysTabGone(a.error, tab);
202
+ }
203
+ function isTabGoneError(error, tab) {
204
+ if (error instanceof TabGoneError) return error.tab === tab;
205
+ return saysTabGone(error instanceof Error ? error.message : String(error != null ? error : ""), tab);
206
+ }
207
+ function tabGoneNow(workspaceId, tab) {
208
+ markTabGone(workspaceId, tab);
209
+ return new TabGoneError(workspaceId, tab);
210
+ }
211
+ function pageTab(workspaceId, tab) {
212
+ return tab && !windowless.has(workspaceId) ? tab : void 0;
213
+ }
214
+ function onTab(params, tab) {
215
+ return tab ? __spreadProps(__spreadValues({}, params), {
216
+ tab
217
+ }) : params;
218
+ }
219
+ async function onPage(workspaceId, action, params, tab, timeoutMs, {
220
+ readOnly = false
221
+ } = {}) {
222
+ const named = pageTab(workspaceId, tab);
223
+ let r;
224
+ try {
225
+ r = await run(action, onTab(params, named), timeoutMs);
226
+ } catch (error) {
227
+ if (named && isTabGoneError(error, named)) throw tabGoneNow(workspaceId, named);
228
+ if (!named || !isTabsRefusalError(error)) throw error;
229
+ dropToOneWindow(workspaceId);
230
+ if (!readOnly) throw error;
231
+ return run(action, params, timeoutMs);
232
+ }
233
+ if (named && isTabGoneAnswer(r, named)) throw tabGoneNow(workspaceId, named);
234
+ return r;
235
+ }
236
+ function readTab(value) {
237
+ if (!value || typeof value !== "object") return null;
238
+ const t = value;
239
+ const id = typeof t.id === "string" ? t.id.trim() : "";
240
+ if (!id) return null;
241
+ return {
242
+ id,
243
+ title: typeof t.title === "string" ? t.title : "",
244
+ url: typeof t.url === "string" ? t.url : "",
245
+ active: t.active === true
246
+ };
247
+ }
248
+ function readTabs(r) {
249
+ if (!Array.isArray(r.tabs)) return [];
250
+ const seen = /* @__PURE__ */ new Set();
251
+ const tabs = [];
252
+ for (const row of r.tabs) {
253
+ const tab = readTab(row);
254
+ if (!tab || seen.has(tab.id)) continue;
255
+ seen.add(tab.id);
256
+ tabs.push(tab);
257
+ }
258
+ return tabs;
259
+ }
260
+ function siteOf(url) {
261
+ const match = /^https?:\/\/(?:[^@/?#]*@)?([^:/?#]+)/i.exec((url != null ? url : "").trim());
262
+ return match ? match[1].toLowerCase().replace(/^www\./i, "") : "";
263
+ }
264
+ async function tabsCall(workspaceId, params) {
265
+ var _a;
266
+ const r = await run(TABS_ACTION, __spreadValues({
267
+ workspaceId
268
+ }, params), 6e4);
269
+ if (r.ok === false) throw new Error(String((_a = r.error) != null ? _a : "the browser could not do that"));
270
+ return r;
271
+ }
272
+ async function listTabs(workspaceId) {
273
+ if (tabsAction === "missing") return {
274
+ supported: false,
275
+ tabs: []
276
+ };
277
+ try {
278
+ const r = await tabsCall(workspaceId, {
279
+ op: "list"
280
+ });
281
+ tabsAction = "present";
282
+ if (r.windows === false) {
283
+ setWindowsAvailable(workspaceId, false);
284
+ return {
285
+ supported: false,
286
+ tabs: []
287
+ };
288
+ }
289
+ setWindowsAvailable(workspaceId, true);
290
+ return {
291
+ supported: true,
292
+ tabs: withoutGoneTabs(workspaceId, readTabs(r))
293
+ };
294
+ } catch (error) {
295
+ if (tabsAction !== "present" && isMissingAction(error, TABS_ACTION)) {
296
+ tabsAction = "missing";
297
+ console.warn("[computer] YANTRA_COMPUTER_TABS unavailable, showing one browser window", error);
298
+ return {
299
+ supported: false,
300
+ tabs: []
301
+ };
302
+ }
303
+ throw error;
304
+ }
305
+ }
306
+ async function changeTabs(workspaceId, params) {
307
+ if (tabsAction === "missing" || windowless.has(workspaceId)) throw new Error(ONE_WINDOW_MESSAGE);
308
+ try {
309
+ const r = await tabsCall(workspaceId, params);
310
+ tabsAction = "present";
311
+ if (r.windows === false) {
312
+ setWindowsAvailable(workspaceId, false);
313
+ throw new Error(ONE_WINDOW_MESSAGE);
314
+ }
315
+ return r;
316
+ } catch (error) {
317
+ if (tabsAction !== "present" && isMissingAction(error, TABS_ACTION)) {
318
+ tabsAction = "missing";
319
+ throw new Error(ONE_WINDOW_MESSAGE);
320
+ }
321
+ throw error;
322
+ }
323
+ }
324
+ async function openTab(workspaceId, url = "about:blank", background = false) {
325
+ var _a, _b;
326
+ const r = await changeTabs(workspaceId, __spreadValues({
327
+ op: "open",
328
+ url
329
+ }, background ? {
330
+ background: true
331
+ } : {}));
332
+ const tab = (_b = (_a = readTab(r.tab)) != null ? _a : readTabs(r).find((row) => row.url === url)) != null ? _b : null;
333
+ if (!tab) throw new Error("the browser opened no window");
334
+ return tab;
335
+ }
336
+ async function closeTab(workspaceId, tab) {
337
+ return withoutGoneTabs(workspaceId, readTabs(await changeTabs(workspaceId, {
338
+ op: "close",
339
+ tab: addressable(tab)
340
+ })));
341
+ }
342
+ async function focusTab(workspaceId, tab) {
343
+ try {
344
+ await changeTabs(workspaceId, {
345
+ op: "focus",
346
+ tab: addressable(tab)
347
+ });
348
+ } catch (error) {
349
+ if (isTabGoneError(error, tab)) throw tabGoneNow(workspaceId, tab);
350
+ throw error;
351
+ }
352
+ }
353
+ function addressable(tab) {
354
+ if (!tab) throw new Error("that page has no tab id to close or focus");
355
+ return tab;
356
+ }
357
+ function withTab(url, tab) {
358
+ if (!tab || !/^(?:https?|wss?):\/\//i.test(url)) return url;
359
+ const hashAt = url.indexOf("#");
360
+ const hash = hashAt >= 0 ? url.slice(hashAt) : "";
361
+ const beforeHash = hashAt >= 0 ? url.slice(0, hashAt) : url;
362
+ const queryAt = beforeHash.indexOf("?");
363
+ const path = queryAt >= 0 ? beforeHash.slice(0, queryAt) : beforeHash;
364
+ const kept = queryAt >= 0 ? beforeHash.slice(queryAt + 1).split("&").filter((part) => part && !/^tab(?:=|$)/.test(part)) : [];
365
+ return `${path}?${[...kept, `tab=${encodeURIComponent(tab)}`].join("&")}${hash}`;
366
+ }
367
+ async function navigate(workspaceId, url, tab) {
368
+ await onPage(workspaceId, "YANTRA_COMPUTER_BROWSE", {
369
+ workspaceId,
370
+ url
371
+ }, tab, 9e4);
372
+ }
373
+ const BROWSER_CTL = "/opt/yantra/browser-ctl.mjs";
374
+ function tabFlag(tab) {
375
+ return tab ? ` --tab '${tab.replace(/'/g, `'\\''`)}'` : "";
376
+ }
377
+ async function evalInPage(workspaceId, expression, tab) {
378
+ try {
379
+ await onPage(workspaceId, "YANTRA_COMPUTER_ACT", {
380
+ workspaceId,
381
+ op: "eval",
382
+ expression
383
+ }, tab, 3e4);
384
+ return;
385
+ } catch (error) {
386
+ if (isTabsRefusalError(error) || !/not found|unknown action/i.test(String(error))) throw error;
387
+ }
388
+ await run("YANTRA_COMPUTER_EXEC", {
389
+ workspaceId,
390
+ cmd: `node ${BROWSER_CTL} eval ${JSON.stringify(expression)}${tabFlag(pageTab(workspaceId, tab))}`,
391
+ timeoutSec: 30
392
+ }, 6e4);
393
+ }
394
+ function goBack(workspaceId, tab) {
395
+ return evalInPage(workspaceId, "history.back(); 'ok'", tab);
396
+ }
397
+ function goForward(workspaceId, tab) {
398
+ return evalInPage(workspaceId, "history.forward(); 'ok'", tab);
399
+ }
400
+ let inputAction = "unknown";
401
+ async function sendInput(workspaceId, events, tab) {
402
+ var _a;
403
+ if (!events.length) return;
404
+ if (inputAction !== "missing") {
405
+ try {
406
+ await onPage(workspaceId, "YANTRA_COMPUTER_INPUT", {
407
+ workspaceId,
408
+ events
409
+ }, tab, 6e4);
410
+ inputAction = "present";
411
+ return;
412
+ } catch (error) {
413
+ if (isTabsRefusalError(error) || error instanceof TabGoneError) throw error;
414
+ if (inputAction === "present") throw error;
415
+ inputAction = "missing";
416
+ console.warn("[computer] YANTRA_COMPUTER_INPUT unavailable, using the in-workspace dispatcher", error);
417
+ }
418
+ }
419
+ const payload = base64(JSON.stringify(events));
420
+ const named = pageTab(workspaceId, tab);
421
+ const result = await exec(workspaceId, `node ${BROWSER_CTL} input "$(printf %s '${payload}' | base64 -d)"${tabFlag(named)}`, 90, 12e4);
422
+ if (result.exitCode !== 0) {
423
+ let message = (result.stderr || result.stdout || "").trim();
424
+ try {
425
+ const parsed = JSON.parse((_a = result.stdout) != null ? _a : "{}");
426
+ if (parsed.error) message = parsed.error;
427
+ } catch (e) {
428
+ }
429
+ if (named && saysTabGone(message, named)) throw tabGoneNow(workspaceId, named);
430
+ throw new Error(message || `input failed (exit ${result.exitCode})`);
431
+ }
432
+ }
433
+ function base64(value) {
434
+ const bytes = new TextEncoder().encode(value);
435
+ let binary = "";
436
+ for (const byte of bytes) binary += String.fromCharCode(byte);
437
+ return btoa(binary);
438
+ }
439
+ const LIVE_RENEW_MARGIN_MS = 6e4;
440
+ const LIVE_DEFAULT_TTL_MS = 10 * 6e4;
441
+ let liveAction = "unknown";
442
+ const liveSessions = /* @__PURE__ */ new Map();
443
+ const liveOpening = /* @__PURE__ */ new Map();
444
+ const liveInputUnreachable = /* @__PURE__ */ new WeakSet();
445
+ const tabSessions = /* @__PURE__ */ new WeakMap();
446
+ const mintedOf = /* @__PURE__ */ new WeakMap();
447
+ function sessionForTab(minted, tab) {
448
+ let byTab = tabSessions.get(minted);
449
+ if (!byTab) {
450
+ byTab = /* @__PURE__ */ new Map();
451
+ tabSessions.set(minted, byTab);
452
+ }
453
+ const known = byTab.get(tab);
454
+ if (known) return known;
455
+ const session = __spreadProps(__spreadValues({}, minted), {
456
+ tab,
457
+ streamUrl: withTab(minted.streamUrl, tab),
458
+ inputUrl: minted.inputUrl ? withTab(minted.inputUrl, tab) : void 0,
459
+ inputSocketUrl: minted.inputSocketUrl ? withTab(minted.inputSocketUrl, tab) : void 0,
460
+ screenshotUrl: minted.screenshotUrl ? withTab(minted.screenshotUrl, tab) : void 0,
461
+ statusUrl: minted.statusUrl ? withTab(minted.statusUrl, tab) : void 0
462
+ });
463
+ byTab.set(tab, session);
464
+ mintedOf.set(session, minted);
465
+ return session;
466
+ }
467
+ function liveFresh(session) {
468
+ const expiresAt = Date.parse(session.expiresAt);
469
+ return Number.isFinite(expiresAt) && expiresAt - LIVE_RENEW_MARGIN_MS > Date.now();
470
+ }
471
+ function liveRenewAt(session) {
472
+ const expiresAt = Date.parse(session.expiresAt);
473
+ return Number.isFinite(expiresAt) ? expiresAt - LIVE_RENEW_MARGIN_MS : Date.now() + LIVE_DEFAULT_TTL_MS;
474
+ }
475
+ function toLiveSession(workspaceId, r) {
476
+ var _a, _b, _c, _d;
477
+ if (r.ok === false) throw new Error(String((_a = r.error) != null ? _a : "the live session could not be opened"));
478
+ const streamUrl = typeof r.streamUrl === "string" && r.streamUrl ? r.streamUrl : null;
479
+ if (!streamUrl) return null;
480
+ const viewport = r.viewport;
481
+ const width = Number(viewport == null ? void 0 : viewport.width);
482
+ const height = Number(viewport == null ? void 0 : viewport.height);
483
+ return {
484
+ workspaceId: String((_b = r.workspaceId) != null ? _b : workspaceId),
485
+ token: String((_c = r.token) != null ? _c : ""),
486
+ expiresAt: typeof r.expiresAt === "string" && r.expiresAt ? r.expiresAt : new Date(Date.now() + LIVE_DEFAULT_TTL_MS).toISOString(),
487
+ streamUrl,
488
+ inputUrl: typeof r.inputUrl === "string" && r.inputUrl ? r.inputUrl : void 0,
489
+ inputSocketUrl: typeof r.inputSocketUrl === "string" && /^wss?:\/\//i.test(r.inputSocketUrl) ? r.inputSocketUrl : void 0,
490
+ screenshotUrl: typeof r.screenshotUrl === "string" && r.screenshotUrl ? r.screenshotUrl : void 0,
491
+ statusUrl: typeof r.statusUrl === "string" && r.statusUrl ? r.statusUrl : void 0,
492
+ viewport: width > 0 && height > 0 ? {
493
+ width,
494
+ height
495
+ } : void 0,
496
+ mode: typeof r.mode === "string" && r.mode ? r.mode : String((_d = r.provider) != null ? _d : "cloudflare")
497
+ };
498
+ }
499
+ async function openLive(workspaceId, tab) {
500
+ const minted = await mintLive(workspaceId);
501
+ const named = pageTab(workspaceId, tab);
502
+ return minted && named ? sessionForTab(minted, named) : minted;
503
+ }
504
+ async function mintLive(workspaceId) {
505
+ if (liveAction === "missing") return null;
506
+ const cached = liveSessions.get(workspaceId);
507
+ if (cached && liveFresh(cached)) return cached;
508
+ const pending = liveOpening.get(workspaceId);
509
+ if (pending) return pending;
510
+ const opening = (async () => {
511
+ try {
512
+ const r = await run("YANTRA_COMPUTER_LIVE", {
513
+ workspaceId
514
+ }, 6e4);
515
+ liveAction = "present";
516
+ const session = toLiveSession(workspaceId, r);
517
+ if (session) liveSessions.set(workspaceId, session);
518
+ else liveSessions.delete(workspaceId);
519
+ return session;
520
+ } catch (error) {
521
+ if (liveAction !== "present" && /not found|unknown action/i.test(String(error))) {
522
+ liveAction = "missing";
523
+ console.warn("[computer] YANTRA_COMPUTER_LIVE unavailable, taking control through the exec lane", error);
524
+ return null;
525
+ }
526
+ throw error;
527
+ } finally {
528
+ liveOpening.delete(workspaceId);
529
+ }
530
+ })();
531
+ liveOpening.set(workspaceId, opening);
532
+ return opening;
533
+ }
534
+ function dropLive(workspaceId, only) {
535
+ var _a;
536
+ const minted = only ? (_a = mintedOf.get(only)) != null ? _a : only : null;
537
+ if (minted && liveSessions.get(workspaceId) !== minted) return;
538
+ liveSessions.delete(workspaceId);
539
+ }
540
+ function liveInputIsFast(session) {
541
+ if (!(session == null ? void 0 : session.inputUrl) || liveInputUnreachable.has(session)) return false;
542
+ const minted = mintedOf.get(session);
543
+ return !minted || !liveInputUnreachable.has(minted);
544
+ }
545
+ async function postLiveInput(session, inputUrl, events) {
546
+ return fetch(inputUrl, {
547
+ method: "POST",
548
+ headers: {
549
+ "content-type": "application/json",
550
+ "x-computer-viewer": session.token
551
+ },
552
+ body: JSON.stringify({
553
+ events
554
+ })
555
+ });
556
+ }
557
+ async function sendLiveInput(session, events, onAnswer) {
558
+ var _a, _b;
559
+ if (!events.length) return session;
560
+ if (!liveInputIsFast(session)) {
561
+ await sendInput(session.workspaceId, events, session.tab);
562
+ return session;
563
+ }
564
+ let response;
565
+ let used = session;
566
+ try {
567
+ response = await postLiveInput(session, session.inputUrl, events);
568
+ } catch (error) {
569
+ liveInputUnreachable.add(session);
570
+ const minted = mintedOf.get(session);
571
+ if (minted) liveInputUnreachable.add(minted);
572
+ console.warn("[computer] the live input route is unreachable, using the exec lane", error);
573
+ await sendInput(session.workspaceId, events, session.tab);
574
+ return session;
575
+ }
576
+ if (response.status === 401 || response.status === 403) {
577
+ dropLive(session.workspaceId, session);
578
+ const renewed = await openLive(session.workspaceId, session.tab);
579
+ if (!(renewed == null ? void 0 : renewed.inputUrl)) {
580
+ await sendInput(session.workspaceId, events, session.tab);
581
+ return renewed != null ? renewed : session;
582
+ }
583
+ used = renewed;
584
+ response = await postLiveInput(renewed, renewed.inputUrl, events);
585
+ }
586
+ if (response.status === 410 && used.tab) {
587
+ await ((_a = response.body) == null ? void 0 : _a.cancel().catch(() => void 0));
588
+ throw tabGoneNow(used.workspaceId, used.tab);
589
+ }
590
+ if (response.status === 409 && used.tab) {
591
+ const body = (await response.text().catch(() => "")).trim();
592
+ let parsed = null;
593
+ try {
594
+ parsed = JSON.parse(body);
595
+ } catch (e) {
596
+ }
597
+ if (isTabsRefusal(parsed)) {
598
+ dropToOneWindow(used.workspaceId);
599
+ return (_b = await openLive(used.workspaceId)) != null ? _b : used;
600
+ }
601
+ throw new Error(body || `live input failed (${response.status})`);
602
+ }
603
+ if (!response.ok) {
604
+ const body = (await response.text().catch(() => "")).trim();
605
+ throw new Error(body || `live input failed (${response.status})`);
606
+ }
607
+ if ((onAnswer || used.tab) && response.status !== 204) {
608
+ const answer = await response.json().catch(() => null);
609
+ if (used.tab && isTabGoneAnswer(answer, used.tab)) throw tabGoneNow(used.workspaceId, used.tab);
610
+ if (onAnswer && answer && typeof answer === "object") onAnswer(answer);
611
+ }
612
+ return used;
613
+ }
614
+ function readBrowserStatus(r) {
615
+ var _a, _b;
616
+ if (!("challenge" in r)) return {
617
+ known: false,
618
+ challenge: null
619
+ };
620
+ const c = r.challenge;
621
+ if (!c || typeof c !== "object") return {
622
+ known: true,
623
+ challenge: null
624
+ };
625
+ return {
626
+ known: true,
627
+ challenge: __spreadValues({
628
+ kind: String((_a = c.kind) != null ? _a : "captcha"),
629
+ provider: String((_b = c.provider) != null ? _b : "unknown"),
630
+ solved: c.solved === true
631
+ }, typeof c.hint === "string" && c.hint ? {
632
+ hint: c.hint
633
+ } : {})
634
+ };
635
+ }
636
+ function challengeCleared(status) {
637
+ return !status.challenge || status.challenge.solved;
638
+ }
639
+ async function browserStatus(workspaceId, session, tab = session == null ? void 0 : session.tab) {
640
+ if ((session == null ? void 0 : session.statusUrl) && session.token && liveFresh(session)) {
641
+ let answer = null;
642
+ try {
643
+ const response = await fetch(session.statusUrl, {
644
+ headers: {
645
+ "x-computer-viewer": session.token
646
+ }
647
+ });
648
+ if (response.status === 410 && session.tab) {
649
+ markTabGone(workspaceId, session.tab);
650
+ } else if (response.ok) {
651
+ answer = await response.json();
652
+ } else if (response.status === 409 && session.tab && isTabsRefusal(await response.json().catch(() => null))) {
653
+ dropToOneWindow(workspaceId);
654
+ }
655
+ } catch (e) {
656
+ }
657
+ if (session.tab && (isTabGone(workspaceId, session.tab) || isTabGoneAnswer(answer, session.tab))) {
658
+ throw tabGoneNow(workspaceId, session.tab);
659
+ }
660
+ if (answer) return readBrowserStatus(answer);
661
+ }
662
+ return readBrowserStatus(await onPage(workspaceId, "YANTRA_COMPUTER_BROWSE", {
663
+ workspaceId,
664
+ action: "status"
665
+ }, tab, 3e4, {
666
+ readOnly: true
667
+ }));
668
+ }
669
+ const EDITABLE_KINDS = /* @__PURE__ */ new Set(["text", "email", "password", "number", "tel", "url", "search", "otp", "textarea", "contenteditable", "frame"]);
670
+ const MAX_EDITABLES = 50;
671
+ function shortWord(value) {
672
+ return typeof value === "string" && value.length <= 64 ? value.trim() || void 0 : void 0;
673
+ }
674
+ function readEditable(value) {
675
+ if (!value || typeof value !== "object") return null;
676
+ const row = value;
677
+ const [x, y, w, h] = [row.x, row.y, row.w, row.h].map(Number);
678
+ if (![x, y, w, h].every(Number.isFinite) || w <= 0 || h <= 0) return null;
679
+ const kind = typeof row.kind === "string" && EDITABLE_KINDS.has(row.kind) ? row.kind : null;
680
+ if (!kind) return null;
681
+ const maxLength = Number(row.maxLength);
682
+ return __spreadValues(__spreadValues(__spreadValues(__spreadValues({
683
+ x,
684
+ y,
685
+ w,
686
+ h,
687
+ kind
688
+ }, shortWord(row.autocomplete) ? {
689
+ autocomplete: shortWord(row.autocomplete)
690
+ } : {}), shortWord(row.inputmode) ? {
691
+ inputmode: shortWord(row.inputmode)
692
+ } : {}), row.focused === true ? {
693
+ focused: true
694
+ } : {}), Number.isInteger(maxLength) && maxLength > 0 ? {
695
+ maxLength
696
+ } : {});
697
+ }
698
+ function readPageFields(r) {
699
+ var _a;
700
+ if (!Array.isArray(r.editables)) return null;
701
+ const editables = r.editables.slice(0, MAX_EDITABLES).map(readEditable).filter((row) => row !== null);
702
+ const named = typeof r.focusedEditable === "number" ? editables[r.focusedEditable] : r.focusedEditable && typeof r.focusedEditable === "object" ? readEditable(r.focusedEditable) : null;
703
+ return {
704
+ editables,
705
+ focused: (_a = named != null ? named : editables.find((row) => row.focused)) != null ? _a : null
706
+ };
707
+ }
708
+ async function liveFrame(session, stamp) {
709
+ var _a, _b;
710
+ if (!session.screenshotUrl) throw new Error("this live session has no still-frame route");
711
+ const base = session.screenshotUrl;
712
+ const url = `${base}${base.includes("?") ? "&" : "?"}_f=${stamp}`;
713
+ const headers = {
714
+ "x-computer-viewer": session.token
715
+ };
716
+ const response = await fetch(url, {
717
+ headers
718
+ });
719
+ const {
720
+ tab
721
+ } = session;
722
+ if (response.status === 410 && tab) throw tabGoneNow(session.workspaceId, tab);
723
+ if (response.status === 409 && tab && isTabsRefusal(await response.json().catch(() => null))) {
724
+ dropToOneWindow(session.workspaceId);
725
+ throw new Error(ONE_WINDOW_MESSAGE);
726
+ }
727
+ if (!response.ok) throw new Error(`the live frame failed (${response.status})`);
728
+ const type = (_a = response.headers.get("content-type")) != null ? _a : "";
729
+ if (/^image\//i.test(type)) return {
730
+ src: url,
731
+ headers,
732
+ title: null,
733
+ pageUrl: null
734
+ };
735
+ const answer = await response.json();
736
+ if (tab && isTabGoneAnswer(answer, tab)) throw tabGoneNow(session.workspaceId, tab);
737
+ const data = typeof answer.dataBase64 === "string" ? answer.dataBase64 : "";
738
+ if (answer.ok === false || !data) throw new Error(String((_b = answer.error) != null ? _b : "the live frame had no picture"));
739
+ const format = typeof answer.format === "string" && /^(jpeg|jpg|png|webp)$/i.test(answer.format) ? answer.format : "jpeg";
740
+ return {
741
+ src: `data:image/${format.toLowerCase() === "jpg" ? "jpeg" : format.toLowerCase()};base64,${data}`,
742
+ title: typeof answer.title === "string" ? answer.title : null,
743
+ pageUrl: typeof answer.url === "string" ? answer.url : null
744
+ };
745
+ }
746
+ async function livePageFields(session) {
747
+ if (!(session == null ? void 0 : session.statusUrl) || !session.token || !liveFresh(session)) return null;
748
+ try {
749
+ const response = await fetch(session.statusUrl, {
750
+ headers: {
751
+ "x-computer-viewer": session.token
752
+ }
753
+ });
754
+ if (response.status === 410 && session.tab) markTabGone(session.workspaceId, session.tab);
755
+ if (!response.ok) return null;
756
+ const answer = await response.json();
757
+ if (session.tab && isTabGoneAnswer(answer, session.tab)) {
758
+ markTabGone(session.workspaceId, session.tab);
759
+ return null;
760
+ }
761
+ return readPageFields(answer);
762
+ } catch (e) {
763
+ return null;
764
+ }
765
+ }
766
+ async function screenshot(workspaceId, tab) {
767
+ var _a, _b, _c, _d;
768
+ const r = await onPage(workspaceId, "YANTRA_COMPUTER_SCREENSHOT", {
769
+ workspaceId,
770
+ format: "jpeg",
771
+ quality: 70
772
+ }, tab, 12e4, {
773
+ readOnly: true
774
+ });
775
+ const inline = typeof r.dataBase64 === "string" && r.dataBase64 ? String(r.dataBase64) : null;
776
+ return {
777
+ src: inline ? `data:image/jpeg;base64,${inline}` : extractMediaUrl(r, ["url", "mediaUrl"]),
778
+ title: (_a = r.title) != null ? _a : null,
779
+ pageUrl: (_b = r.pageUrl) != null ? _b : null,
780
+ error: (_c = r.error) != null ? _c : null,
781
+ // Which page it is of, when the connector says: the one asked for, or the active one.
782
+ tab: typeof r.tab === "string" && r.tab ? r.tab : (_d = pageTab(workspaceId, tab)) != null ? _d : null
783
+ };
784
+ }
785
+ async function exec(workspaceId, cmd, timeoutSec = 120, timeoutMs = 18e4) {
786
+ var _a, _b, _c, _d, _e;
787
+ const r = await run("YANTRA_COMPUTER_EXEC", {
788
+ workspaceId,
789
+ cmd,
790
+ timeoutSec
791
+ }, timeoutMs);
792
+ return {
793
+ exitCode: Number((_a = r.exitCode) != null ? _a : -1),
794
+ stdout: String((_b = r.stdout) != null ? _b : ""),
795
+ stderr: String((_c = r.stderr) != null ? _c : ""),
796
+ durationMs: Number((_d = r.durationMs) != null ? _d : 0),
797
+ error: (_e = r.error) != null ? _e : void 0
798
+ };
799
+ }
800
+ async function readFile(workspaceId, path) {
801
+ var _a;
802
+ const r = await run("YANTRA_COMPUTER_READ_FILE", {
803
+ workspaceId,
804
+ path
805
+ }, 9e4);
806
+ const b64 = String((_a = r.contentBase64) != null ? _a : "");
807
+ if (!b64) return "";
808
+ let bytes;
809
+ try {
810
+ bytes = atob(b64);
811
+ } catch (e) {
812
+ return "(binary file)";
813
+ }
814
+ try {
815
+ return decodeURIComponent(Array.from(bytes, (c) => `%${c.charCodeAt(0).toString(16).padStart(2, "0")}`).join(""));
816
+ } catch (e) {
817
+ return bytes;
818
+ }
819
+ }export{MAX_EDITABLES,NO_EXEC_MESSAGE,ONE_WINDOW_MESSAGE,TAB_GONE_MEMORY_MS,TAB_GONE_MESSAGE,TabGoneError,browserStatus,challengeCleared,closeTab,createWorkspace,dropLive,dropToOneWindow,exec,extractMediaUrl,focusTab,goBack,goForward,isTabGone,isTabGoneAnswer,isTabGoneError,listTabs,liveFrame,liveInputIsFast,livePageFields,liveRenewAt,markTabGone,navigate,openLive,openTab,provideExec,readFile,readPageFields,readTabs,resolveWorkspace,saysTabGone,screenshot,sendInput,sendLiveInput,siteOf,subscribeTabsGone,subscribeWindows,windowsAvailable,withTab,withoutGoneTabs};//# sourceMappingURL=computerApi.js.map