onin-sdk 1.3.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.
- package/README.md +117 -0
- package/dist/api/__tests__/clipboard-metadata.test.d.ts +4 -0
- package/dist/api/__tests__/lifecycle.test.d.ts +4 -0
- package/dist/api/ai.d.ts +124 -0
- package/dist/api/clipboard.d.ts +346 -0
- package/dist/api/command.d.ts +213 -0
- package/dist/api/dialog.d.ts +285 -0
- package/dist/api/fs.d.ts +198 -0
- package/dist/api/lifecycle.d.ts +139 -0
- package/dist/api/notification.d.ts +118 -0
- package/dist/api/request.d.ts +200 -0
- package/dist/api/scheduler.d.ts +142 -0
- package/dist/api/settings.d.ts +223 -0
- package/dist/api/storage.d.ts +379 -0
- package/dist/api/window.d.ts +74 -0
- package/dist/core/adapters/base.d.ts +75 -0
- package/dist/core/adapters/index.d.ts +10 -0
- package/dist/core/adapters/inline.d.ts +17 -0
- package/dist/core/adapters/postmessage.d.ts +47 -0
- package/dist/core/adapters/window.d.ts +37 -0
- package/dist/core/dispatch.d.ts +46 -0
- package/dist/core/environment.d.ts +26 -0
- package/dist/core/ipc.d.ts +66 -0
- package/dist/core/runtime.d.ts +64 -0
- package/dist/event-DiwgtsjL.js +29 -0
- package/dist/index.d.ts +67 -0
- package/dist/index.js +1538 -0
- package/dist/index.umd.cjs +1 -0
- package/dist/types/errors.d.ts +210 -0
- package/dist/types/permissions.d.ts +208 -0
- package/dist/utils/debug.d.ts +23 -0
- package/dist/utils/error-parser.d.ts +64 -0
- package/dist/utils/retry.d.ts +123 -0
- package/package.json +43 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,1538 @@
|
|
|
1
|
+
var fe = Object.defineProperty;
|
|
2
|
+
var ge = (e, t, r) => t in e ? fe(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
|
|
3
|
+
var u = (e, t, r) => ge(e, typeof t != "symbol" ? t + "" : t, r);
|
|
4
|
+
var _ = /* @__PURE__ */ ((e) => (e.Headless = "headless", e.Webview = "webview", e.Iframe = "iframe", e.Unknown = "unknown", e))(_ || {});
|
|
5
|
+
function R() {
|
|
6
|
+
return typeof window < "u" && window.__TAURI_INTERNALS__ ? "webview" : typeof window < "u" && window.self !== window.top ? "iframe" : typeof Deno < "u" && Deno.core ? "headless" : "unknown";
|
|
7
|
+
}
|
|
8
|
+
let A = null, me = 0;
|
|
9
|
+
const D = /* @__PURE__ */ new Map();
|
|
10
|
+
let X = !1;
|
|
11
|
+
function pe() {
|
|
12
|
+
X || (X = !0, window.addEventListener("message", (e) => {
|
|
13
|
+
const t = e.data;
|
|
14
|
+
if (!t || typeof t != "object" || !t.messageId || !D.has(t.messageId)) return;
|
|
15
|
+
const r = D.get(t.messageId);
|
|
16
|
+
D.delete(t.messageId), t.error ? r.reject(new Error(t.error)) : r.resolve(t.result);
|
|
17
|
+
}));
|
|
18
|
+
}
|
|
19
|
+
async function he() {
|
|
20
|
+
if (A)
|
|
21
|
+
return A;
|
|
22
|
+
const e = R();
|
|
23
|
+
if (e === _.Webview) {
|
|
24
|
+
const { invoke: t } = await import("@tauri-apps/api/core");
|
|
25
|
+
A = t;
|
|
26
|
+
} else if (e === _.Iframe)
|
|
27
|
+
pe(), A = async (t, r) => new Promise((n, s) => {
|
|
28
|
+
const i = `invoke_${++me}_${Date.now()}`;
|
|
29
|
+
D.set(i, { resolve: n, reject: s }), window.parent.postMessage({
|
|
30
|
+
type: "plugin-tauri-call",
|
|
31
|
+
messageId: i,
|
|
32
|
+
command: "invoke",
|
|
33
|
+
args: [t, r]
|
|
34
|
+
}, "*"), setTimeout(() => {
|
|
35
|
+
D.has(i) && (D.delete(i), s(new Error(`Invoke timeout for method: ${t}`)));
|
|
36
|
+
}, 3e4);
|
|
37
|
+
});
|
|
38
|
+
else if (e === _.Headless)
|
|
39
|
+
A = async (t, r) => {
|
|
40
|
+
const n = await Deno.core.ops.op_invoke(t, r);
|
|
41
|
+
if (n && typeof n == "object") {
|
|
42
|
+
if (n.type === "error")
|
|
43
|
+
throw new Error(n.error);
|
|
44
|
+
if (n.type === "ok")
|
|
45
|
+
return n.value;
|
|
46
|
+
}
|
|
47
|
+
if (n && typeof n == "object" && "error" in n)
|
|
48
|
+
throw new Error(n.error);
|
|
49
|
+
return n;
|
|
50
|
+
};
|
|
51
|
+
else
|
|
52
|
+
throw new Error("Unsupported runtime environment for invoke");
|
|
53
|
+
return A;
|
|
54
|
+
}
|
|
55
|
+
async function l(e, t) {
|
|
56
|
+
const r = await he();
|
|
57
|
+
if (!r)
|
|
58
|
+
throw new Error("Invoke function not loaded");
|
|
59
|
+
return r(e, t);
|
|
60
|
+
}
|
|
61
|
+
let k = null;
|
|
62
|
+
async function _e() {
|
|
63
|
+
if (k)
|
|
64
|
+
return k;
|
|
65
|
+
const e = R();
|
|
66
|
+
if (e === _.Webview) {
|
|
67
|
+
const { listen: t } = await import("./event-DiwgtsjL.js");
|
|
68
|
+
k = t;
|
|
69
|
+
} else if (e === _.Iframe) {
|
|
70
|
+
const t = /* @__PURE__ */ new Map();
|
|
71
|
+
window.addEventListener("message", (r) => {
|
|
72
|
+
const n = r.data;
|
|
73
|
+
if (!(!n || typeof n != "object") && n.type === "plugin-event" && n.eventName) {
|
|
74
|
+
const s = t.get(n.eventName);
|
|
75
|
+
s && s.forEach((i) => {
|
|
76
|
+
i({ payload: n.payload });
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
}), k = (r, n) => {
|
|
80
|
+
const s = r.toString();
|
|
81
|
+
return t.has(s) || t.set(s, /* @__PURE__ */ new Set()), t.get(s).add(n), Promise.resolve(() => {
|
|
82
|
+
const i = t.get(s);
|
|
83
|
+
i && i.delete(n);
|
|
84
|
+
});
|
|
85
|
+
};
|
|
86
|
+
} else if (e === _.Headless)
|
|
87
|
+
k = (t, r) => t === "plugin_command_execute" ? (globalThis.__ONIN_COMMAND_HANDLER__ = r, Promise.resolve(() => {
|
|
88
|
+
})) : (console.warn(
|
|
89
|
+
`Event listening for '${t.toString()}' is not supported in headless mode.`
|
|
90
|
+
), Promise.resolve(() => {
|
|
91
|
+
}));
|
|
92
|
+
else
|
|
93
|
+
throw new Error("Unsupported runtime environment for listen");
|
|
94
|
+
return k;
|
|
95
|
+
}
|
|
96
|
+
async function S(e, t) {
|
|
97
|
+
const r = await _e();
|
|
98
|
+
if (!r)
|
|
99
|
+
throw new Error("Listen function not loaded");
|
|
100
|
+
return r(e, t);
|
|
101
|
+
}
|
|
102
|
+
const o = {
|
|
103
|
+
/** Common errors */
|
|
104
|
+
common: {
|
|
105
|
+
UNKNOWN: "COMMON_UNKNOWN",
|
|
106
|
+
PERMISSION_DENIED: "COMMON_PERMISSION_DENIED",
|
|
107
|
+
INVALID_ARGUMENT: "COMMON_INVALID_ARGUMENT"
|
|
108
|
+
},
|
|
109
|
+
/** HTTP related errors */
|
|
110
|
+
http: {
|
|
111
|
+
NETWORK_ERROR: "HTTP_NETWORK_ERROR",
|
|
112
|
+
TIMEOUT: "HTTP_TIMEOUT",
|
|
113
|
+
HTTP_ERROR: "HTTP_HTTP_ERROR"
|
|
114
|
+
// Generic HTTP error with status code information
|
|
115
|
+
},
|
|
116
|
+
/** File system errors */
|
|
117
|
+
fs: {
|
|
118
|
+
FILE_NOT_FOUND: "FS_FILE_NOT_FOUND",
|
|
119
|
+
FILE_ACCESS_DENIED: "FS_FILE_ACCESS_DENIED",
|
|
120
|
+
DIRECTORY_NOT_FOUND: "FS_DIRECTORY_NOT_FOUND",
|
|
121
|
+
DISK_FULL: "FS_DISK_FULL",
|
|
122
|
+
FILE_ALREADY_EXISTS: "FS_FILE_ALREADY_EXISTS",
|
|
123
|
+
INVALID_PATH: "FS_INVALID_PATH",
|
|
124
|
+
READ_ONLY_FILESYSTEM: "FS_READ_ONLY_FILESYSTEM"
|
|
125
|
+
},
|
|
126
|
+
/** Clipboard errors */
|
|
127
|
+
clipboard: {
|
|
128
|
+
UNAVAILABLE: "CLIPBOARD_UNAVAILABLE",
|
|
129
|
+
FORMAT_UNSUPPORTED: "CLIPBOARD_FORMAT_UNSUPPORTED",
|
|
130
|
+
EMPTY: "CLIPBOARD_EMPTY",
|
|
131
|
+
ACCESS_DENIED: "CLIPBOARD_ACCESS_DENIED"
|
|
132
|
+
},
|
|
133
|
+
/** Dialog errors */
|
|
134
|
+
dialog: {
|
|
135
|
+
CANCELLED: "DIALOG_CANCELLED",
|
|
136
|
+
UNAVAILABLE: "DIALOG_UNAVAILABLE",
|
|
137
|
+
INVALID_OPTIONS: "DIALOG_INVALID_OPTIONS"
|
|
138
|
+
},
|
|
139
|
+
/** Storage errors */
|
|
140
|
+
storage: {
|
|
141
|
+
QUOTA_EXCEEDED: "STORAGE_QUOTA_EXCEEDED",
|
|
142
|
+
UNAVAILABLE: "STORAGE_UNAVAILABLE"
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
function c(e, t, r) {
|
|
146
|
+
const n = new Error(t);
|
|
147
|
+
return Object.defineProperty(n, "name", { value: "PluginError", writable: !1 }), n.code = e, n.context = r, n;
|
|
148
|
+
}
|
|
149
|
+
const a = {
|
|
150
|
+
/** Common error factories */
|
|
151
|
+
common: {
|
|
152
|
+
unknown: (e, t) => c(o.common.UNKNOWN, e, t),
|
|
153
|
+
permissionDenied: (e, t) => c(
|
|
154
|
+
o.common.PERMISSION_DENIED,
|
|
155
|
+
`Permission denied for ${e}`,
|
|
156
|
+
t
|
|
157
|
+
),
|
|
158
|
+
invalidArgument: (e, t) => c(
|
|
159
|
+
o.common.INVALID_ARGUMENT,
|
|
160
|
+
`Invalid argument: ${e}`,
|
|
161
|
+
t
|
|
162
|
+
)
|
|
163
|
+
},
|
|
164
|
+
/** HTTP error factories */
|
|
165
|
+
http: {
|
|
166
|
+
networkError: (e, t) => c(o.http.NETWORK_ERROR, e, t),
|
|
167
|
+
timeout: (e, t, r) => c(
|
|
168
|
+
o.http.TIMEOUT,
|
|
169
|
+
`Request to ${e} timed out after ${t}ms`,
|
|
170
|
+
{ url: e, timeout: t, ...r }
|
|
171
|
+
),
|
|
172
|
+
httpError: (e, t, r) => c(
|
|
173
|
+
o.http.HTTP_ERROR,
|
|
174
|
+
`HTTP ${e}: ${t}`,
|
|
175
|
+
{ status: e, statusText: t, ...r }
|
|
176
|
+
)
|
|
177
|
+
},
|
|
178
|
+
/** File system error factories */
|
|
179
|
+
fs: {
|
|
180
|
+
fileNotFound: (e, t) => c(
|
|
181
|
+
o.fs.FILE_NOT_FOUND,
|
|
182
|
+
`File not found: ${e}`,
|
|
183
|
+
{ path: e, ...t }
|
|
184
|
+
),
|
|
185
|
+
fileAccessDenied: (e, t) => c(
|
|
186
|
+
o.fs.FILE_ACCESS_DENIED,
|
|
187
|
+
`Access denied: ${e}`,
|
|
188
|
+
{ path: e, ...t }
|
|
189
|
+
),
|
|
190
|
+
diskFull: (e, t) => c(
|
|
191
|
+
o.fs.DISK_FULL,
|
|
192
|
+
`Disk full while accessing: ${e}`,
|
|
193
|
+
{ path: e, ...t }
|
|
194
|
+
),
|
|
195
|
+
fileAlreadyExists: (e, t) => c(
|
|
196
|
+
o.fs.FILE_ALREADY_EXISTS,
|
|
197
|
+
`File already exists: ${e}`,
|
|
198
|
+
{ path: e, ...t }
|
|
199
|
+
),
|
|
200
|
+
invalidPath: (e, t) => c(
|
|
201
|
+
o.fs.INVALID_PATH,
|
|
202
|
+
`Invalid path: ${e}`,
|
|
203
|
+
{ path: e, ...t }
|
|
204
|
+
)
|
|
205
|
+
},
|
|
206
|
+
/** Clipboard error factories */
|
|
207
|
+
clipboard: {
|
|
208
|
+
unavailable: (e) => c(
|
|
209
|
+
o.clipboard.UNAVAILABLE,
|
|
210
|
+
"Clipboard is not available",
|
|
211
|
+
e
|
|
212
|
+
),
|
|
213
|
+
formatUnsupported: (e, t) => c(
|
|
214
|
+
o.clipboard.FORMAT_UNSUPPORTED,
|
|
215
|
+
`Clipboard format not supported${e ? `: ${e}` : ""}`,
|
|
216
|
+
{ format: e, ...t }
|
|
217
|
+
),
|
|
218
|
+
empty: (e) => c(
|
|
219
|
+
o.clipboard.EMPTY,
|
|
220
|
+
"Clipboard is empty",
|
|
221
|
+
e
|
|
222
|
+
),
|
|
223
|
+
accessDenied: (e) => c(
|
|
224
|
+
o.clipboard.ACCESS_DENIED,
|
|
225
|
+
"Clipboard access denied",
|
|
226
|
+
e
|
|
227
|
+
)
|
|
228
|
+
},
|
|
229
|
+
/** Dialog error factories */
|
|
230
|
+
dialog: {
|
|
231
|
+
cancelled: (e) => c(
|
|
232
|
+
o.dialog.CANCELLED,
|
|
233
|
+
"Dialog was cancelled by user",
|
|
234
|
+
e
|
|
235
|
+
),
|
|
236
|
+
unavailable: (e) => c(
|
|
237
|
+
o.dialog.UNAVAILABLE,
|
|
238
|
+
"Dialog is not available",
|
|
239
|
+
e
|
|
240
|
+
),
|
|
241
|
+
invalidOptions: (e, t) => c(
|
|
242
|
+
o.dialog.INVALID_OPTIONS,
|
|
243
|
+
`Invalid dialog options${e ? `: ${e}` : ""}`,
|
|
244
|
+
{ reason: e, ...t }
|
|
245
|
+
)
|
|
246
|
+
},
|
|
247
|
+
/** Storage error factories */
|
|
248
|
+
storage: {
|
|
249
|
+
quotaExceeded: (e) => c(
|
|
250
|
+
o.storage.QUOTA_EXCEEDED,
|
|
251
|
+
"Storage quota exceeded",
|
|
252
|
+
e
|
|
253
|
+
),
|
|
254
|
+
unavailable: (e) => c(
|
|
255
|
+
o.storage.UNAVAILABLE,
|
|
256
|
+
"Storage is not available",
|
|
257
|
+
e
|
|
258
|
+
)
|
|
259
|
+
}
|
|
260
|
+
}, m = {
|
|
261
|
+
/**
|
|
262
|
+
* Checks if an error is a plugin error
|
|
263
|
+
* @param error - The error to check
|
|
264
|
+
* @returns True if the error is a PluginError
|
|
265
|
+
*/
|
|
266
|
+
isPluginError: (e) => e && e.name === "PluginError" && typeof e.code == "string",
|
|
267
|
+
/**
|
|
268
|
+
* Checks if an error is of a specific type
|
|
269
|
+
* @param error - The error to check
|
|
270
|
+
* @param code - The error code to match
|
|
271
|
+
* @returns True if the error matches the specified code
|
|
272
|
+
*/
|
|
273
|
+
isErrorCode: (e, t) => m.isPluginError(e) && e.code === t,
|
|
274
|
+
/**
|
|
275
|
+
* Checks if an error is one of the specified types
|
|
276
|
+
* @param error - The error to check
|
|
277
|
+
* @param codes - Array of error codes to match against
|
|
278
|
+
* @returns True if the error matches any of the specified codes
|
|
279
|
+
*/
|
|
280
|
+
isOneOfErrorCodes: (e, t) => m.isPluginError(e) && t.includes(e.code),
|
|
281
|
+
/**
|
|
282
|
+
* Gets detailed information about an error
|
|
283
|
+
* @param error - The error to analyze
|
|
284
|
+
* @returns Error information object or null if not a plugin error
|
|
285
|
+
*/
|
|
286
|
+
getErrorInfo: (e) => m.isPluginError(e) ? {
|
|
287
|
+
name: e.name,
|
|
288
|
+
code: e.code,
|
|
289
|
+
message: e.message,
|
|
290
|
+
context: e.context
|
|
291
|
+
} : null
|
|
292
|
+
}, qt = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
293
|
+
__proto__: null,
|
|
294
|
+
createError: a,
|
|
295
|
+
errorCode: o,
|
|
296
|
+
errorUtils: m
|
|
297
|
+
}, Symbol.toStringTag, { value: "Module" })), Ee = [
|
|
298
|
+
// Specific network errors (high priority)
|
|
299
|
+
{
|
|
300
|
+
patterns: ["timed out", "timeout", "TIMEOUT"],
|
|
301
|
+
createError: (e, t) => a.http.timeout(
|
|
302
|
+
(t == null ? void 0 : t.url) || "unknown",
|
|
303
|
+
(t == null ? void 0 : t.timeout) || 3e4,
|
|
304
|
+
{ originalError: e, ...t }
|
|
305
|
+
)
|
|
306
|
+
},
|
|
307
|
+
{
|
|
308
|
+
patterns: ["Network error", "network error", "NETWORK_ERROR", "connection refused", "connection failed"],
|
|
309
|
+
createError: (e, t) => a.http.networkError(e, { originalError: e, ...t })
|
|
310
|
+
},
|
|
311
|
+
// Generic permission errors (low priority, placed last)
|
|
312
|
+
{
|
|
313
|
+
patterns: ["Permission denied", "permission denied", "PERMISSION_DENIED"],
|
|
314
|
+
createError: (e, t) => a.common.permissionDenied(
|
|
315
|
+
`URL: ${(t == null ? void 0 : t.url) || "unknown"}`,
|
|
316
|
+
{ originalError: e, ...t }
|
|
317
|
+
)
|
|
318
|
+
}
|
|
319
|
+
], we = [
|
|
320
|
+
// Specific file system errors (high priority)
|
|
321
|
+
{
|
|
322
|
+
patterns: ["not found", "No such file", "FILE_NOT_FOUND", "does not exist"],
|
|
323
|
+
createError: (e, t) => a.fs.fileNotFound(
|
|
324
|
+
(t == null ? void 0 : t.path) || "unknown",
|
|
325
|
+
{ originalError: e, ...t }
|
|
326
|
+
)
|
|
327
|
+
},
|
|
328
|
+
{
|
|
329
|
+
patterns: ["Access denied", "access denied", "FILE_ACCESS_DENIED"],
|
|
330
|
+
createError: (e, t) => a.fs.fileAccessDenied(
|
|
331
|
+
(t == null ? void 0 : t.path) || "unknown",
|
|
332
|
+
{ originalError: e, ...t }
|
|
333
|
+
)
|
|
334
|
+
},
|
|
335
|
+
{
|
|
336
|
+
patterns: ["No space left", "disk full", "DISK_FULL", "insufficient space"],
|
|
337
|
+
createError: (e, t) => a.fs.diskFull(
|
|
338
|
+
(t == null ? void 0 : t.path) || "unknown",
|
|
339
|
+
{ originalError: e, ...t }
|
|
340
|
+
)
|
|
341
|
+
},
|
|
342
|
+
{
|
|
343
|
+
patterns: ["already exists", "file exists", "FILE_ALREADY_EXISTS"],
|
|
344
|
+
createError: (e, t) => a.fs.fileAlreadyExists(
|
|
345
|
+
(t == null ? void 0 : t.path) || "unknown",
|
|
346
|
+
{ originalError: e, ...t }
|
|
347
|
+
)
|
|
348
|
+
},
|
|
349
|
+
{
|
|
350
|
+
patterns: ["invalid path", "INVALID_PATH", "malformed path"],
|
|
351
|
+
createError: (e, t) => a.fs.invalidPath(
|
|
352
|
+
(t == null ? void 0 : t.path) || "unknown",
|
|
353
|
+
{ originalError: e, ...t }
|
|
354
|
+
)
|
|
355
|
+
},
|
|
356
|
+
// Generic permission errors (low priority, placed last)
|
|
357
|
+
{
|
|
358
|
+
patterns: ["Permission denied", "PERMISSION_DENIED"],
|
|
359
|
+
createError: (e, t) => a.common.permissionDenied(
|
|
360
|
+
`file system operation on ${(t == null ? void 0 : t.path) || "unknown"}`,
|
|
361
|
+
{ originalError: e, ...t }
|
|
362
|
+
)
|
|
363
|
+
}
|
|
364
|
+
], ye = [
|
|
365
|
+
// Specific clipboard errors (high priority)
|
|
366
|
+
{
|
|
367
|
+
patterns: ["format not supported", "unsupported format", "FORMAT_UNSUPPORTED"],
|
|
368
|
+
createError: (e, t) => a.clipboard.formatUnsupported(
|
|
369
|
+
t == null ? void 0 : t.format,
|
|
370
|
+
{ originalError: e, ...t }
|
|
371
|
+
)
|
|
372
|
+
},
|
|
373
|
+
{
|
|
374
|
+
patterns: ["empty", "no content", "CLIPBOARD_EMPTY"],
|
|
375
|
+
createError: (e, t) => a.clipboard.empty({ originalError: e, ...t })
|
|
376
|
+
},
|
|
377
|
+
{
|
|
378
|
+
patterns: ["clipboard access denied", "clipboard ACCESS_DENIED"],
|
|
379
|
+
createError: (e, t) => a.clipboard.accessDenied({ originalError: e, ...t })
|
|
380
|
+
},
|
|
381
|
+
{
|
|
382
|
+
patterns: ["unavailable", "not available", "CLIPBOARD_UNAVAILABLE", "clipboard not accessible"],
|
|
383
|
+
createError: (e, t) => a.clipboard.unavailable({ originalError: e, ...t })
|
|
384
|
+
},
|
|
385
|
+
// Generic permission errors (low priority, placed last)
|
|
386
|
+
{
|
|
387
|
+
patterns: ["Permission denied", "permission denied", "PERMISSION_DENIED"],
|
|
388
|
+
createError: (e, t) => a.common.permissionDenied(
|
|
389
|
+
"clipboard access",
|
|
390
|
+
{ originalError: e, ...t }
|
|
391
|
+
)
|
|
392
|
+
}
|
|
393
|
+
], be = [
|
|
394
|
+
{
|
|
395
|
+
patterns: ["cancelled", "canceled", "DIALOG_CANCELLED", "user cancelled"],
|
|
396
|
+
createError: (e, t) => a.dialog.cancelled({ originalError: e, ...t })
|
|
397
|
+
},
|
|
398
|
+
{
|
|
399
|
+
patterns: ["unavailable", "not available", "DIALOG_UNAVAILABLE", "dialog not supported"],
|
|
400
|
+
createError: (e, t) => a.dialog.unavailable({ originalError: e, ...t })
|
|
401
|
+
},
|
|
402
|
+
{
|
|
403
|
+
patterns: ["invalid options", "INVALID_OPTIONS", "malformed options"],
|
|
404
|
+
createError: (e, t) => a.dialog.invalidOptions(
|
|
405
|
+
t == null ? void 0 : t.reason,
|
|
406
|
+
{ originalError: e, ...t }
|
|
407
|
+
)
|
|
408
|
+
},
|
|
409
|
+
{
|
|
410
|
+
patterns: ["Permission denied", "permission denied", "PERMISSION_DENIED"],
|
|
411
|
+
createError: (e, t) => a.common.permissionDenied(
|
|
412
|
+
"dialog access",
|
|
413
|
+
{ originalError: e, ...t }
|
|
414
|
+
)
|
|
415
|
+
}
|
|
416
|
+
];
|
|
417
|
+
function Ie(e) {
|
|
418
|
+
if (typeof e == "string")
|
|
419
|
+
return e;
|
|
420
|
+
if (e && typeof e == "object") {
|
|
421
|
+
const t = e;
|
|
422
|
+
if (typeof t.message == "string")
|
|
423
|
+
return t.message;
|
|
424
|
+
if (typeof t.error == "string")
|
|
425
|
+
return t.error;
|
|
426
|
+
}
|
|
427
|
+
return "Unknown error";
|
|
428
|
+
}
|
|
429
|
+
function Ae(e, t) {
|
|
430
|
+
const r = e.toLowerCase();
|
|
431
|
+
for (const n of t)
|
|
432
|
+
for (const s of n.patterns)
|
|
433
|
+
if (r.includes(s.toLowerCase()))
|
|
434
|
+
return {
|
|
435
|
+
matched: !0,
|
|
436
|
+
pattern: n
|
|
437
|
+
};
|
|
438
|
+
return { matched: !1 };
|
|
439
|
+
}
|
|
440
|
+
function O(e, t, r) {
|
|
441
|
+
const n = Ie(e), s = Ae(n, t);
|
|
442
|
+
if (s.matched && s.pattern)
|
|
443
|
+
try {
|
|
444
|
+
return s.pattern.createError(n, r);
|
|
445
|
+
} catch (i) {
|
|
446
|
+
console.warn("Failed to create specific error, falling back to generic error:", i);
|
|
447
|
+
}
|
|
448
|
+
return a.common.unknown(n, {
|
|
449
|
+
originalError: n,
|
|
450
|
+
parseContext: "No pattern matched",
|
|
451
|
+
...r
|
|
452
|
+
});
|
|
453
|
+
}
|
|
454
|
+
function ke(e, t) {
|
|
455
|
+
return O(e, Ee, {
|
|
456
|
+
...t,
|
|
457
|
+
errorType: "http"
|
|
458
|
+
});
|
|
459
|
+
}
|
|
460
|
+
function De(e, t) {
|
|
461
|
+
return O(e, we, {
|
|
462
|
+
...t,
|
|
463
|
+
errorType: "filesystem"
|
|
464
|
+
});
|
|
465
|
+
}
|
|
466
|
+
function Z(e, t) {
|
|
467
|
+
return O(e, ye, {
|
|
468
|
+
...t,
|
|
469
|
+
errorType: "clipboard"
|
|
470
|
+
});
|
|
471
|
+
}
|
|
472
|
+
function ee(e, t) {
|
|
473
|
+
return O(e, be, {
|
|
474
|
+
...t,
|
|
475
|
+
errorType: "dialog"
|
|
476
|
+
});
|
|
477
|
+
}
|
|
478
|
+
async function N(e) {
|
|
479
|
+
try {
|
|
480
|
+
const t = await l("plugin_request", e);
|
|
481
|
+
if (e.responseType === "arraybuffer" && typeof t.body == "string") {
|
|
482
|
+
const r = atob(t.body), n = new Uint8Array(r.length);
|
|
483
|
+
for (let s = 0; s < r.length; s++)
|
|
484
|
+
n[s] = r.charCodeAt(s);
|
|
485
|
+
t.body = n.buffer;
|
|
486
|
+
}
|
|
487
|
+
if (t.status >= 200 && t.status < 300)
|
|
488
|
+
return t;
|
|
489
|
+
throw a.http.httpError(t.status, t.statusText, {
|
|
490
|
+
url: e.url,
|
|
491
|
+
method: e.method || "GET",
|
|
492
|
+
response: t
|
|
493
|
+
});
|
|
494
|
+
} catch (t) {
|
|
495
|
+
throw m.isPluginError(t) ? t : ke(t, {
|
|
496
|
+
url: e.url,
|
|
497
|
+
method: e.method || "GET",
|
|
498
|
+
options: e
|
|
499
|
+
});
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
async function Se(e, t) {
|
|
503
|
+
return N({ ...t, url: e, method: "GET" });
|
|
504
|
+
}
|
|
505
|
+
async function Le(e, t, r) {
|
|
506
|
+
return N({ ...r, url: e, method: "POST", body: t });
|
|
507
|
+
}
|
|
508
|
+
async function Ne(e, t, r) {
|
|
509
|
+
return N({ ...r, url: e, method: "PUT", body: t });
|
|
510
|
+
}
|
|
511
|
+
async function Te(e, t, r) {
|
|
512
|
+
return N({ ...r, url: e, method: "PATCH", body: t });
|
|
513
|
+
}
|
|
514
|
+
async function Ce(e, t) {
|
|
515
|
+
return N({ ...t, url: e, method: "DELETE" });
|
|
516
|
+
}
|
|
517
|
+
const Kt = {
|
|
518
|
+
request: N,
|
|
519
|
+
get: Se,
|
|
520
|
+
post: Le,
|
|
521
|
+
put: Ne,
|
|
522
|
+
patch: Te,
|
|
523
|
+
delete: Ce
|
|
524
|
+
// delete is a keyword, use del
|
|
525
|
+
};
|
|
526
|
+
function T(e) {
|
|
527
|
+
const t = R();
|
|
528
|
+
if (t === _.Webview)
|
|
529
|
+
return e.webview();
|
|
530
|
+
if (t === _.Headless)
|
|
531
|
+
return e.headless();
|
|
532
|
+
throw new Error(`Unsupported environment: ${t}`);
|
|
533
|
+
}
|
|
534
|
+
function E(e, t) {
|
|
535
|
+
return T({
|
|
536
|
+
webview: () => l(e, t),
|
|
537
|
+
headless: () => l(e, t)
|
|
538
|
+
});
|
|
539
|
+
}
|
|
540
|
+
function Pe(e, t) {
|
|
541
|
+
return E("plugin_storage_set", { key: e, value: t });
|
|
542
|
+
}
|
|
543
|
+
function ve(e) {
|
|
544
|
+
return E("plugin_storage_get", { key: e });
|
|
545
|
+
}
|
|
546
|
+
function Re(e) {
|
|
547
|
+
return E("plugin_storage_remove", { key: e });
|
|
548
|
+
}
|
|
549
|
+
function Oe() {
|
|
550
|
+
return E("plugin_storage_clear");
|
|
551
|
+
}
|
|
552
|
+
function Fe() {
|
|
553
|
+
return E("plugin_storage_keys");
|
|
554
|
+
}
|
|
555
|
+
function Me(e) {
|
|
556
|
+
return E("plugin_storage_set_items", { items: e });
|
|
557
|
+
}
|
|
558
|
+
function Ue(e) {
|
|
559
|
+
return E("plugin_storage_get_items", {
|
|
560
|
+
keys: e
|
|
561
|
+
});
|
|
562
|
+
}
|
|
563
|
+
function $e() {
|
|
564
|
+
return E("plugin_storage_get_all");
|
|
565
|
+
}
|
|
566
|
+
function He(e) {
|
|
567
|
+
return E("plugin_storage_set_all", { data: e });
|
|
568
|
+
}
|
|
569
|
+
const xt = {
|
|
570
|
+
setItem: Pe,
|
|
571
|
+
getItem: ve,
|
|
572
|
+
removeItem: Re,
|
|
573
|
+
clear: Oe,
|
|
574
|
+
keys: Fe,
|
|
575
|
+
setItems: Me,
|
|
576
|
+
getItems: Ue,
|
|
577
|
+
getAll: $e,
|
|
578
|
+
setAll: He
|
|
579
|
+
};
|
|
580
|
+
function Be(e) {
|
|
581
|
+
return T({
|
|
582
|
+
// Webview environment: Tauri expects parameter structure { options: { ... } }
|
|
583
|
+
webview: () => l("show_notification", { options: e }),
|
|
584
|
+
// Headless environment: pass options directly
|
|
585
|
+
headless: () => l("show_notification", e)
|
|
586
|
+
});
|
|
587
|
+
}
|
|
588
|
+
const Xt = {
|
|
589
|
+
show: Be
|
|
590
|
+
};
|
|
591
|
+
let Q = !1;
|
|
592
|
+
async function Ve(e) {
|
|
593
|
+
if (Q) {
|
|
594
|
+
console.warn(
|
|
595
|
+
"CommandHandler has already been registered. Ignoring subsequent calls."
|
|
596
|
+
);
|
|
597
|
+
return;
|
|
598
|
+
}
|
|
599
|
+
await T({
|
|
600
|
+
webview: () => S("plugin_command_execute", async (r) => {
|
|
601
|
+
const { command: n, args: s, requestId: i } = r.payload;
|
|
602
|
+
try {
|
|
603
|
+
const d = await e(n, s);
|
|
604
|
+
try {
|
|
605
|
+
await l("plugin_command_result", {
|
|
606
|
+
requestId: i,
|
|
607
|
+
success: !0,
|
|
608
|
+
result: d
|
|
609
|
+
});
|
|
610
|
+
} catch (w) {
|
|
611
|
+
console.error("Failed to send command result:", w);
|
|
612
|
+
}
|
|
613
|
+
} catch (d) {
|
|
614
|
+
try {
|
|
615
|
+
await l("plugin_command_result", {
|
|
616
|
+
requestId: i,
|
|
617
|
+
success: !1,
|
|
618
|
+
error: d instanceof Error ? d.message : String(d)
|
|
619
|
+
});
|
|
620
|
+
} catch (w) {
|
|
621
|
+
console.error("Failed to send command error:", w);
|
|
622
|
+
}
|
|
623
|
+
}
|
|
624
|
+
}),
|
|
625
|
+
headless: () => S("plugin_command_execute", e)
|
|
626
|
+
}), Q = !0;
|
|
627
|
+
}
|
|
628
|
+
async function We(e) {
|
|
629
|
+
if (!e.code)
|
|
630
|
+
throw new Error("Command code is required");
|
|
631
|
+
if (!e.name)
|
|
632
|
+
throw new Error("Command name is required");
|
|
633
|
+
await l("register_dynamic_command", {
|
|
634
|
+
command: e
|
|
635
|
+
});
|
|
636
|
+
}
|
|
637
|
+
async function ze(e) {
|
|
638
|
+
if (!e)
|
|
639
|
+
throw new Error("Command code is required");
|
|
640
|
+
await l("remove_dynamic_command", {
|
|
641
|
+
commandCode: e
|
|
642
|
+
});
|
|
643
|
+
}
|
|
644
|
+
const Qt = {
|
|
645
|
+
register: We,
|
|
646
|
+
handle: Ve,
|
|
647
|
+
remove: ze
|
|
648
|
+
};
|
|
649
|
+
async function h(e, t) {
|
|
650
|
+
try {
|
|
651
|
+
return await T({
|
|
652
|
+
webview: () => l(e, t),
|
|
653
|
+
headless: () => l(e, t)
|
|
654
|
+
});
|
|
655
|
+
} catch (r) {
|
|
656
|
+
throw m.isPluginError(r) ? r : De(r, {
|
|
657
|
+
path: (t == null ? void 0 : t.path) || (t == null ? void 0 : t.sourcePath),
|
|
658
|
+
method: e,
|
|
659
|
+
args: t
|
|
660
|
+
});
|
|
661
|
+
}
|
|
662
|
+
}
|
|
663
|
+
function Ge(e) {
|
|
664
|
+
return h("plugin_fs_read_file", { path: e });
|
|
665
|
+
}
|
|
666
|
+
function je(e, t) {
|
|
667
|
+
return h("plugin_fs_write_file", { path: e, content: t });
|
|
668
|
+
}
|
|
669
|
+
function Ye(e) {
|
|
670
|
+
return h("plugin_fs_exists", { path: e });
|
|
671
|
+
}
|
|
672
|
+
function qe(e, t = !0) {
|
|
673
|
+
return h("plugin_fs_create_dir", { path: e, recursive: t });
|
|
674
|
+
}
|
|
675
|
+
function Ke(e) {
|
|
676
|
+
return h("plugin_fs_list_dir", { path: e });
|
|
677
|
+
}
|
|
678
|
+
function xe(e) {
|
|
679
|
+
return h("plugin_fs_delete_file", { path: e });
|
|
680
|
+
}
|
|
681
|
+
function Xe(e, t = !1) {
|
|
682
|
+
return h("plugin_fs_delete_dir", { path: e, recursive: t });
|
|
683
|
+
}
|
|
684
|
+
function Qe(e) {
|
|
685
|
+
return h("plugin_fs_get_file_info", { path: e });
|
|
686
|
+
}
|
|
687
|
+
function Je(e, t) {
|
|
688
|
+
return h("plugin_fs_copy_file", { sourcePath: e, destPath: t });
|
|
689
|
+
}
|
|
690
|
+
function Ze(e, t) {
|
|
691
|
+
return h("plugin_fs_move_file", { sourcePath: e, destPath: t });
|
|
692
|
+
}
|
|
693
|
+
const Jt = {
|
|
694
|
+
readFile: Ge,
|
|
695
|
+
writeFile: je,
|
|
696
|
+
exists: Ye,
|
|
697
|
+
createDir: qe,
|
|
698
|
+
listDir: Ke,
|
|
699
|
+
deleteFile: xe,
|
|
700
|
+
deleteDir: Xe,
|
|
701
|
+
getFileInfo: Qe,
|
|
702
|
+
copyFile: Je,
|
|
703
|
+
moveFile: Ze
|
|
704
|
+
};
|
|
705
|
+
async function F(e, t) {
|
|
706
|
+
try {
|
|
707
|
+
return await T({
|
|
708
|
+
webview: () => l(e, t),
|
|
709
|
+
headless: () => l(e, t)
|
|
710
|
+
});
|
|
711
|
+
} catch (r) {
|
|
712
|
+
throw m.isPluginError(r) ? r : ee(r, {
|
|
713
|
+
method: e,
|
|
714
|
+
args: t
|
|
715
|
+
});
|
|
716
|
+
}
|
|
717
|
+
}
|
|
718
|
+
function M(e) {
|
|
719
|
+
return F("plugin_dialog_message", e);
|
|
720
|
+
}
|
|
721
|
+
function te(e) {
|
|
722
|
+
return F("plugin_dialog_confirm", e);
|
|
723
|
+
}
|
|
724
|
+
async function U(e) {
|
|
725
|
+
const t = await F("plugin_dialog_open", e || {});
|
|
726
|
+
return t == null ? null : Array.isArray(t) || typeof t == "string" ? t : null;
|
|
727
|
+
}
|
|
728
|
+
function re(e) {
|
|
729
|
+
return F("plugin_dialog_save", e || {});
|
|
730
|
+
}
|
|
731
|
+
function et(e, t) {
|
|
732
|
+
return M({
|
|
733
|
+
message: e,
|
|
734
|
+
title: t,
|
|
735
|
+
kind: "info"
|
|
736
|
+
});
|
|
737
|
+
}
|
|
738
|
+
function tt(e, t) {
|
|
739
|
+
return M({
|
|
740
|
+
message: e,
|
|
741
|
+
title: t,
|
|
742
|
+
kind: "warning"
|
|
743
|
+
});
|
|
744
|
+
}
|
|
745
|
+
function rt(e, t) {
|
|
746
|
+
return M({
|
|
747
|
+
message: e,
|
|
748
|
+
title: t,
|
|
749
|
+
kind: "error"
|
|
750
|
+
});
|
|
751
|
+
}
|
|
752
|
+
function nt(e, t) {
|
|
753
|
+
return te({
|
|
754
|
+
message: e,
|
|
755
|
+
title: t
|
|
756
|
+
});
|
|
757
|
+
}
|
|
758
|
+
function st(e, t) {
|
|
759
|
+
return U({
|
|
760
|
+
filters: e,
|
|
761
|
+
defaultPath: t,
|
|
762
|
+
multiple: !1,
|
|
763
|
+
directory: !1
|
|
764
|
+
});
|
|
765
|
+
}
|
|
766
|
+
function it(e, t) {
|
|
767
|
+
return U({
|
|
768
|
+
filters: e,
|
|
769
|
+
defaultPath: t,
|
|
770
|
+
multiple: !0,
|
|
771
|
+
directory: !1
|
|
772
|
+
});
|
|
773
|
+
}
|
|
774
|
+
function ot(e) {
|
|
775
|
+
return U({
|
|
776
|
+
defaultPath: e,
|
|
777
|
+
multiple: !1,
|
|
778
|
+
directory: !0
|
|
779
|
+
});
|
|
780
|
+
}
|
|
781
|
+
function at(e, t) {
|
|
782
|
+
return re({
|
|
783
|
+
defaultPath: e,
|
|
784
|
+
filters: t
|
|
785
|
+
});
|
|
786
|
+
}
|
|
787
|
+
const Zt = {
|
|
788
|
+
/** Core methods */
|
|
789
|
+
showMessage: M,
|
|
790
|
+
showConfirm: te,
|
|
791
|
+
showOpen: U,
|
|
792
|
+
showSave: re,
|
|
793
|
+
/** Convenience methods */
|
|
794
|
+
info: et,
|
|
795
|
+
warning: tt,
|
|
796
|
+
error: rt,
|
|
797
|
+
confirm: nt,
|
|
798
|
+
selectFile: st,
|
|
799
|
+
selectFiles: it,
|
|
800
|
+
selectFolder: ot,
|
|
801
|
+
saveFile: at,
|
|
802
|
+
/** Error handling tools */
|
|
803
|
+
parseDialogError: ee
|
|
804
|
+
};
|
|
805
|
+
async function C(e, t) {
|
|
806
|
+
try {
|
|
807
|
+
return await T({
|
|
808
|
+
webview: () => l(e, t),
|
|
809
|
+
headless: () => l(e, t)
|
|
810
|
+
});
|
|
811
|
+
} catch (r) {
|
|
812
|
+
throw m.isPluginError(r) ? r : Z(r, {
|
|
813
|
+
method: e,
|
|
814
|
+
args: t
|
|
815
|
+
});
|
|
816
|
+
}
|
|
817
|
+
}
|
|
818
|
+
function W() {
|
|
819
|
+
return C("plugin_clipboard_read_text");
|
|
820
|
+
}
|
|
821
|
+
function ne(e) {
|
|
822
|
+
return C("plugin_clipboard_write_text", { text: e });
|
|
823
|
+
}
|
|
824
|
+
function se() {
|
|
825
|
+
return C("plugin_clipboard_read_image");
|
|
826
|
+
}
|
|
827
|
+
function lt(e) {
|
|
828
|
+
const t = typeof e == "string" ? e : Array.from(e);
|
|
829
|
+
return C("plugin_clipboard_write_image", { imageData: t });
|
|
830
|
+
}
|
|
831
|
+
function ct() {
|
|
832
|
+
return C("plugin_clipboard_clear");
|
|
833
|
+
}
|
|
834
|
+
async function ut() {
|
|
835
|
+
const e = await W();
|
|
836
|
+
return e !== null && e.length > 0;
|
|
837
|
+
}
|
|
838
|
+
async function dt() {
|
|
839
|
+
return await se() !== null;
|
|
840
|
+
}
|
|
841
|
+
function ft(e) {
|
|
842
|
+
return ne(e);
|
|
843
|
+
}
|
|
844
|
+
function gt() {
|
|
845
|
+
return W();
|
|
846
|
+
}
|
|
847
|
+
function mt() {
|
|
848
|
+
return C("plugin_clipboard_get_metadata");
|
|
849
|
+
}
|
|
850
|
+
const er = {
|
|
851
|
+
/** Core methods */
|
|
852
|
+
readText: W,
|
|
853
|
+
writeText: ne,
|
|
854
|
+
readImage: se,
|
|
855
|
+
writeImage: lt,
|
|
856
|
+
clear: ct,
|
|
857
|
+
/** Check methods */
|
|
858
|
+
hasText: ut,
|
|
859
|
+
hasImage: dt,
|
|
860
|
+
/** Metadata methods */
|
|
861
|
+
getMetadata: mt,
|
|
862
|
+
/** Convenience methods */
|
|
863
|
+
copy: ft,
|
|
864
|
+
paste: gt,
|
|
865
|
+
/** Error handling tools */
|
|
866
|
+
parseClipboardError: Z
|
|
867
|
+
};
|
|
868
|
+
let z = [];
|
|
869
|
+
async function pt(e) {
|
|
870
|
+
z = e;
|
|
871
|
+
try {
|
|
872
|
+
const t = globalThis.__PLUGIN_ID__;
|
|
873
|
+
if (!t)
|
|
874
|
+
throw a.common.unknown("Plugin ID not found in global context");
|
|
875
|
+
await l("register_plugin_settings_schema", {
|
|
876
|
+
pluginId: t,
|
|
877
|
+
schema: ht(e)
|
|
878
|
+
});
|
|
879
|
+
} catch (t) {
|
|
880
|
+
if (t && typeof t == "object" && t !== null && "name" in t && t.name === "PluginError")
|
|
881
|
+
throw t;
|
|
882
|
+
const r = t instanceof Error ? t.message : String(t);
|
|
883
|
+
throw a.common.unknown(
|
|
884
|
+
`Failed to register settings schema: ${r}`
|
|
885
|
+
);
|
|
886
|
+
}
|
|
887
|
+
}
|
|
888
|
+
function ht(e) {
|
|
889
|
+
return {
|
|
890
|
+
fields: e
|
|
891
|
+
};
|
|
892
|
+
}
|
|
893
|
+
async function ie() {
|
|
894
|
+
try {
|
|
895
|
+
const e = globalThis.__PLUGIN_ID__;
|
|
896
|
+
if (!e)
|
|
897
|
+
throw a.common.unknown("Plugin ID not found in global context");
|
|
898
|
+
const r = { ...await l("get_plugin_settings", {
|
|
899
|
+
pluginId: e
|
|
900
|
+
}) };
|
|
901
|
+
for (const n of z)
|
|
902
|
+
r[n.key] === void 0 && "defaultValue" in n && n.defaultValue !== void 0 && (r[n.key] = n.defaultValue);
|
|
903
|
+
return r;
|
|
904
|
+
} catch (e) {
|
|
905
|
+
throw e && typeof e == "object" && e !== null && "name" in e && e.name === "PluginError" ? e : a.common.unknown(`Failed to get plugin settings: ${e}`);
|
|
906
|
+
}
|
|
907
|
+
}
|
|
908
|
+
async function _t(e, t) {
|
|
909
|
+
try {
|
|
910
|
+
const n = (await ie())[e];
|
|
911
|
+
return n !== void 0 ? n : t;
|
|
912
|
+
} catch (r) {
|
|
913
|
+
if (t !== void 0)
|
|
914
|
+
return t;
|
|
915
|
+
throw r;
|
|
916
|
+
}
|
|
917
|
+
}
|
|
918
|
+
function Et() {
|
|
919
|
+
return z;
|
|
920
|
+
}
|
|
921
|
+
const tr = {
|
|
922
|
+
useSettingsSchema: pt,
|
|
923
|
+
getAll: ie,
|
|
924
|
+
get: _t,
|
|
925
|
+
getSchema: Et
|
|
926
|
+
};
|
|
927
|
+
let G = [], j = [], B = !1;
|
|
928
|
+
function wt(e) {
|
|
929
|
+
G.push(e), B || (B = !0, queueMicrotask(() => {
|
|
930
|
+
bt().catch((t) => {
|
|
931
|
+
console.error("[Lifecycle] Failed to execute onLoad callbacks:", t);
|
|
932
|
+
});
|
|
933
|
+
}));
|
|
934
|
+
}
|
|
935
|
+
function yt(e) {
|
|
936
|
+
j.push(e);
|
|
937
|
+
}
|
|
938
|
+
async function bt() {
|
|
939
|
+
for (const e of G)
|
|
940
|
+
try {
|
|
941
|
+
await e();
|
|
942
|
+
} catch (t) {
|
|
943
|
+
const r = t instanceof Error ? t.message : String(t);
|
|
944
|
+
throw console.error("[Lifecycle] Error in onLoad callback:", r), a.common.unknown(
|
|
945
|
+
`onLoad callback failed: ${r}`
|
|
946
|
+
);
|
|
947
|
+
}
|
|
948
|
+
}
|
|
949
|
+
async function It() {
|
|
950
|
+
for (const e of j)
|
|
951
|
+
try {
|
|
952
|
+
await e();
|
|
953
|
+
} catch (t) {
|
|
954
|
+
console.error("[Lifecycle] Error in onUnload callback:", t);
|
|
955
|
+
}
|
|
956
|
+
}
|
|
957
|
+
function At() {
|
|
958
|
+
G = [], j = [], B = !1;
|
|
959
|
+
}
|
|
960
|
+
const rr = {
|
|
961
|
+
onLoad: wt,
|
|
962
|
+
onUnload: yt,
|
|
963
|
+
// Internal functions exposed for plugin system
|
|
964
|
+
_executeUnloadCallbacks: It,
|
|
965
|
+
_resetCallbacks: At
|
|
966
|
+
}, v = /* @__PURE__ */ new Map();
|
|
967
|
+
let J = !1;
|
|
968
|
+
function kt() {
|
|
969
|
+
J || (J = !0, S("scheduler:execute-task", (e) => {
|
|
970
|
+
const { taskId: t } = e.payload, r = v.get(t);
|
|
971
|
+
r ? Promise.resolve(r()).catch((n) => {
|
|
972
|
+
console.error(`[Scheduler] Task ${t} execution failed:`, n);
|
|
973
|
+
}) : console.warn(`[Scheduler] No callback found for task: ${t}`);
|
|
974
|
+
}));
|
|
975
|
+
}
|
|
976
|
+
kt();
|
|
977
|
+
function oe(e) {
|
|
978
|
+
if (!/^([0-1]?[0-9]|2[0-3]):([0-5][0-9])$/.test(e))
|
|
979
|
+
throw new Error(`Invalid time format: ${e}. Expected format: HH:MM (e.g., 08:30)`);
|
|
980
|
+
}
|
|
981
|
+
function Dt(e) {
|
|
982
|
+
if (e.split(/\s+/).length !== 5)
|
|
983
|
+
throw new Error(
|
|
984
|
+
`Invalid cron format: ${e}. Expected format: 'minute hour day month weekday'`
|
|
985
|
+
);
|
|
986
|
+
}
|
|
987
|
+
async function $(e, t, r) {
|
|
988
|
+
Dt(t), v.set(e, r);
|
|
989
|
+
try {
|
|
990
|
+
await l("schedule_task", {
|
|
991
|
+
options: { id: e, cron: t }
|
|
992
|
+
});
|
|
993
|
+
} catch (n) {
|
|
994
|
+
throw v.delete(e), n;
|
|
995
|
+
}
|
|
996
|
+
}
|
|
997
|
+
async function St(e, t, r) {
|
|
998
|
+
oe(t);
|
|
999
|
+
const [n, s] = t.split(":"), i = `${s} ${n} * * *`;
|
|
1000
|
+
return $(e, i, r);
|
|
1001
|
+
}
|
|
1002
|
+
async function Lt(e, t, r) {
|
|
1003
|
+
const n = `${t} * * * *`;
|
|
1004
|
+
return $(e, n, r);
|
|
1005
|
+
}
|
|
1006
|
+
async function Nt(e, t, r, n) {
|
|
1007
|
+
if (t < 0 || t > 6)
|
|
1008
|
+
throw new Error(`Invalid weekday: ${t}. Expected 0-6 (0=Sunday, 6=Saturday)`);
|
|
1009
|
+
oe(r);
|
|
1010
|
+
const [s, i] = r.split(":"), d = `${i} ${s} * * ${t}`;
|
|
1011
|
+
return $(e, d, n);
|
|
1012
|
+
}
|
|
1013
|
+
async function Tt(e) {
|
|
1014
|
+
await l("cancel_task", { taskId: e }), v.delete(e);
|
|
1015
|
+
}
|
|
1016
|
+
async function Ct() {
|
|
1017
|
+
return l("list_tasks", {});
|
|
1018
|
+
}
|
|
1019
|
+
const nr = {
|
|
1020
|
+
schedule: $,
|
|
1021
|
+
daily: St,
|
|
1022
|
+
hourly: Lt,
|
|
1023
|
+
weekly: Nt,
|
|
1024
|
+
cancel: Tt,
|
|
1025
|
+
list: Ct
|
|
1026
|
+
};
|
|
1027
|
+
function Pt() {
|
|
1028
|
+
const e = /* @__PURE__ */ new Date(), t = e.getHours().toString().padStart(2, "0"), r = e.getMinutes().toString().padStart(2, "0"), n = e.getSeconds().toString().padStart(2, "0"), s = e.getMilliseconds().toString().padStart(3, "0");
|
|
1029
|
+
return `${t}:${r}:${n}.${s}`;
|
|
1030
|
+
}
|
|
1031
|
+
const I = class I {
|
|
1032
|
+
constructor() {
|
|
1033
|
+
u(this, "showCallbacks", []);
|
|
1034
|
+
u(this, "hideCallbacks", []);
|
|
1035
|
+
u(this, "focusCallbacks", []);
|
|
1036
|
+
u(this, "blurCallbacks", []);
|
|
1037
|
+
u(this, "initialized", !1);
|
|
1038
|
+
// 状态跟踪:防止连续触发相同类型的事件
|
|
1039
|
+
u(this, "isVisible", !0);
|
|
1040
|
+
// 假设初始状态为可见
|
|
1041
|
+
u(this, "isFocused", !0);
|
|
1042
|
+
u(this, "lastShowTime", 0);
|
|
1043
|
+
u(this, "lastHideTime", 0);
|
|
1044
|
+
u(this, "lastFocusTime", 0);
|
|
1045
|
+
u(this, "lastBlurTime", 0);
|
|
1046
|
+
}
|
|
1047
|
+
/**
|
|
1048
|
+
* 获取带时间戳的日志前缀
|
|
1049
|
+
*/
|
|
1050
|
+
log(t) {
|
|
1051
|
+
console.log(`[${Pt()}] [Adapter] ${t}`);
|
|
1052
|
+
}
|
|
1053
|
+
onShow(t) {
|
|
1054
|
+
this.showCallbacks.includes(t) || this.showCallbacks.push(t), this.ensureInitialized();
|
|
1055
|
+
}
|
|
1056
|
+
onHide(t) {
|
|
1057
|
+
this.hideCallbacks.includes(t) || this.hideCallbacks.push(t), this.ensureInitialized();
|
|
1058
|
+
}
|
|
1059
|
+
onFocus(t) {
|
|
1060
|
+
this.focusCallbacks.includes(t) || this.focusCallbacks.push(t), this.ensureInitialized();
|
|
1061
|
+
}
|
|
1062
|
+
onBlur(t) {
|
|
1063
|
+
this.blurCallbacks.includes(t) || this.blurCallbacks.push(t), this.ensureInitialized();
|
|
1064
|
+
}
|
|
1065
|
+
ensureInitialized() {
|
|
1066
|
+
this.initialized || (this.initialize(), this.initialized = !0);
|
|
1067
|
+
}
|
|
1068
|
+
destroy() {
|
|
1069
|
+
this.showCallbacks = [], this.hideCallbacks = [], this.focusCallbacks = [], this.blurCallbacks = [], this.initialized = !1, this.isVisible = !0, this.isFocused = !0;
|
|
1070
|
+
}
|
|
1071
|
+
/**
|
|
1072
|
+
* 执行显示回调(带防抖和状态检查)
|
|
1073
|
+
*/
|
|
1074
|
+
async executeShowCallbacks() {
|
|
1075
|
+
if (this.isVisible)
|
|
1076
|
+
return;
|
|
1077
|
+
const t = Date.now();
|
|
1078
|
+
if (!(t - this.lastShowTime < I.DEBOUNCE_MS)) {
|
|
1079
|
+
this.lastShowTime = t, this.isVisible = !0;
|
|
1080
|
+
for (const r of this.showCallbacks)
|
|
1081
|
+
try {
|
|
1082
|
+
await r();
|
|
1083
|
+
} catch (n) {
|
|
1084
|
+
console.error("[WindowAdapter] Error in onShow callback:", n);
|
|
1085
|
+
}
|
|
1086
|
+
}
|
|
1087
|
+
}
|
|
1088
|
+
/**
|
|
1089
|
+
* 执行隐藏回调(带防抖和状态检查)
|
|
1090
|
+
*/
|
|
1091
|
+
async executeHideCallbacks() {
|
|
1092
|
+
if (!this.isVisible)
|
|
1093
|
+
return;
|
|
1094
|
+
const t = Date.now();
|
|
1095
|
+
if (!(t - this.lastHideTime < I.DEBOUNCE_MS)) {
|
|
1096
|
+
this.lastHideTime = t, this.isVisible = !1;
|
|
1097
|
+
for (const r of this.hideCallbacks)
|
|
1098
|
+
try {
|
|
1099
|
+
await r();
|
|
1100
|
+
} catch (n) {
|
|
1101
|
+
console.error("[WindowAdapter] Error in onHide callback:", n);
|
|
1102
|
+
}
|
|
1103
|
+
}
|
|
1104
|
+
}
|
|
1105
|
+
async executeFocusCallbacks() {
|
|
1106
|
+
if (this.log(`executeFocusCallbacks - isFocused: ${this.isFocused}`), this.isFocused) {
|
|
1107
|
+
this.log("Skipping focus - already focused");
|
|
1108
|
+
return;
|
|
1109
|
+
}
|
|
1110
|
+
const t = Date.now();
|
|
1111
|
+
if (!(t - this.lastFocusTime < I.DEBOUNCE_MS)) {
|
|
1112
|
+
this.lastFocusTime = t, this.isFocused = !0;
|
|
1113
|
+
for (const r of this.focusCallbacks)
|
|
1114
|
+
try {
|
|
1115
|
+
await r();
|
|
1116
|
+
} catch (n) {
|
|
1117
|
+
console.error("[WindowAdapter] Error in onFocus callback:", n);
|
|
1118
|
+
}
|
|
1119
|
+
}
|
|
1120
|
+
}
|
|
1121
|
+
async executeBlurCallbacks() {
|
|
1122
|
+
if (this.log(`executeBlurCallbacks - isFocused: ${this.isFocused}`), !this.isFocused) {
|
|
1123
|
+
this.log("Skipping blur - already blurred");
|
|
1124
|
+
return;
|
|
1125
|
+
}
|
|
1126
|
+
const t = Date.now();
|
|
1127
|
+
if (!(t - this.lastBlurTime < I.DEBOUNCE_MS)) {
|
|
1128
|
+
this.lastBlurTime = t, this.isFocused = !1;
|
|
1129
|
+
for (const r of this.blurCallbacks)
|
|
1130
|
+
try {
|
|
1131
|
+
await r();
|
|
1132
|
+
} catch (n) {
|
|
1133
|
+
console.error("[WindowAdapter] Error in onBlur callback:", n);
|
|
1134
|
+
}
|
|
1135
|
+
}
|
|
1136
|
+
}
|
|
1137
|
+
};
|
|
1138
|
+
// 假设初始状态为聚焦
|
|
1139
|
+
// 防抖时间(毫秒)
|
|
1140
|
+
u(I, "DEBOUNCE_MS", 100);
|
|
1141
|
+
let V = I;
|
|
1142
|
+
class vt extends V {
|
|
1143
|
+
constructor() {
|
|
1144
|
+
super();
|
|
1145
|
+
u(this, "messageHandler", null);
|
|
1146
|
+
u(this, "runtimeResolve", null);
|
|
1147
|
+
u(this, "runtimePromise");
|
|
1148
|
+
u(this, "_runtime", null);
|
|
1149
|
+
this.runtimePromise = new Promise((r) => {
|
|
1150
|
+
this.runtimeResolve = r;
|
|
1151
|
+
}), this.initializeNow();
|
|
1152
|
+
}
|
|
1153
|
+
/**
|
|
1154
|
+
* 立即初始化
|
|
1155
|
+
*/
|
|
1156
|
+
initializeNow() {
|
|
1157
|
+
console.log("[PostMessageAdapter] Initializing..."), console.log("[PostMessageAdapter] In iframe:", window.self !== window.top), this.trySetRuntimeFromUrl(), this.messageHandler = (r) => {
|
|
1158
|
+
r.data && typeof r.data == "object" && r.data.type && console.log(
|
|
1159
|
+
"[PostMessageAdapter] Received message:",
|
|
1160
|
+
r.data.type,
|
|
1161
|
+
r.data
|
|
1162
|
+
);
|
|
1163
|
+
const n = r.data;
|
|
1164
|
+
!n || typeof n != "object" || (n.type === "plugin-runtime-init" ? this.handleRuntimeInit(n.runtime) : n.type === "plugin-lifecycle-event" && this.handleLifecycleEvent(n.event));
|
|
1165
|
+
}, window.addEventListener("message", this.messageHandler), this.initialized = !0, console.log("[PostMessageAdapter] Initialized, listening for postMessage");
|
|
1166
|
+
}
|
|
1167
|
+
/**
|
|
1168
|
+
* 尝试从 URL 参数设置运行时信息(作为 fallback)
|
|
1169
|
+
*/
|
|
1170
|
+
trySetRuntimeFromUrl() {
|
|
1171
|
+
try {
|
|
1172
|
+
const r = new URLSearchParams(window.location.search), n = r.get("mode"), s = r.get("plugin_id") || "unknown";
|
|
1173
|
+
(n === "window" || n === "inline") && (console.log("[PostMessageAdapter] Setting runtime from URL params:", {
|
|
1174
|
+
mode: n,
|
|
1175
|
+
pluginId: s
|
|
1176
|
+
}), this._runtime = {
|
|
1177
|
+
mode: n,
|
|
1178
|
+
pluginId: s,
|
|
1179
|
+
version: "0.1.0",
|
|
1180
|
+
mainWindowLabel: "main"
|
|
1181
|
+
}, this.runtimeResolve && (this.runtimeResolve(this._runtime), this.runtimeResolve = null));
|
|
1182
|
+
} catch (r) {
|
|
1183
|
+
console.warn("[PostMessageAdapter] Failed to read URL params:", r);
|
|
1184
|
+
}
|
|
1185
|
+
}
|
|
1186
|
+
/**
|
|
1187
|
+
* 获取运行时信息(异步)
|
|
1188
|
+
*/
|
|
1189
|
+
async getRuntime() {
|
|
1190
|
+
return this._runtime ? this._runtime : this.runtimePromise;
|
|
1191
|
+
}
|
|
1192
|
+
/**
|
|
1193
|
+
* 获取运行时信息(同步,可能返回 null)
|
|
1194
|
+
*/
|
|
1195
|
+
getRuntimeSync() {
|
|
1196
|
+
return this._runtime;
|
|
1197
|
+
}
|
|
1198
|
+
initialize() {
|
|
1199
|
+
}
|
|
1200
|
+
/**
|
|
1201
|
+
* 处理运行时初始化
|
|
1202
|
+
*/
|
|
1203
|
+
handleRuntimeInit(r) {
|
|
1204
|
+
console.log("[PostMessageAdapter] Runtime init received:", r), this._runtime = r, this._stateUnknown = !0, this.runtimeResolve && (this.runtimeResolve(r), this.runtimeResolve = null);
|
|
1205
|
+
}
|
|
1206
|
+
/**
|
|
1207
|
+
* 处理生命周期事件
|
|
1208
|
+
*/
|
|
1209
|
+
handleLifecycleEvent(r) {
|
|
1210
|
+
switch (console.log("[PostMessageAdapter] Lifecycle event:", r), this._stateUnknown && (this._stateUnknown = !1, r === "show" ? this.isVisible = !1 : r === "hide" ? this.isVisible = !0 : r === "focus" ? this.isFocused = !1 : r === "blur" && (this.isFocused = !0)), r) {
|
|
1211
|
+
case "show":
|
|
1212
|
+
this.executeShowCallbacks();
|
|
1213
|
+
break;
|
|
1214
|
+
case "hide":
|
|
1215
|
+
this.executeHideCallbacks();
|
|
1216
|
+
break;
|
|
1217
|
+
case "focus":
|
|
1218
|
+
this.executeFocusCallbacks();
|
|
1219
|
+
break;
|
|
1220
|
+
case "blur":
|
|
1221
|
+
this.executeBlurCallbacks();
|
|
1222
|
+
break;
|
|
1223
|
+
}
|
|
1224
|
+
}
|
|
1225
|
+
destroy() {
|
|
1226
|
+
this.messageHandler && (window.removeEventListener("message", this.messageHandler), this.messageHandler = null), this.initialized = !1, this.showCallbacks = [], this.hideCallbacks = [], this.focusCallbacks = [], this.blurCallbacks = [], console.log("[PostMessageAdapter] Destroyed");
|
|
1227
|
+
}
|
|
1228
|
+
}
|
|
1229
|
+
let L = null;
|
|
1230
|
+
function y() {
|
|
1231
|
+
return L || (console.log("[pluginWindow] Creating PostMessageAdapter"), L = new vt()), L;
|
|
1232
|
+
}
|
|
1233
|
+
function Rt(e) {
|
|
1234
|
+
y().onShow(e);
|
|
1235
|
+
}
|
|
1236
|
+
function Ot(e) {
|
|
1237
|
+
y().onHide(e);
|
|
1238
|
+
}
|
|
1239
|
+
function Ft(e) {
|
|
1240
|
+
y().onFocus(e);
|
|
1241
|
+
}
|
|
1242
|
+
function Mt(e) {
|
|
1243
|
+
y().onBlur(e);
|
|
1244
|
+
}
|
|
1245
|
+
function Ut() {
|
|
1246
|
+
const e = y().getRuntimeSync();
|
|
1247
|
+
return (e == null ? void 0 : e.mode) ?? "unknown";
|
|
1248
|
+
}
|
|
1249
|
+
async function $t() {
|
|
1250
|
+
return (await y().getRuntime()).mode;
|
|
1251
|
+
}
|
|
1252
|
+
function Ht() {
|
|
1253
|
+
const e = y().getRuntimeSync();
|
|
1254
|
+
return (e == null ? void 0 : e.pluginId) ?? "unknown";
|
|
1255
|
+
}
|
|
1256
|
+
const sr = {
|
|
1257
|
+
onShow: Rt,
|
|
1258
|
+
onHide: Ot,
|
|
1259
|
+
onFocus: Ft,
|
|
1260
|
+
onBlur: Mt,
|
|
1261
|
+
getMode: Ut,
|
|
1262
|
+
getModeAsync: $t,
|
|
1263
|
+
getPluginId: Ht,
|
|
1264
|
+
// 内部函数,用于测试和高级用例
|
|
1265
|
+
_getAdapter: y,
|
|
1266
|
+
_resetAdapter: () => {
|
|
1267
|
+
L && (L.destroy(), L = null);
|
|
1268
|
+
}
|
|
1269
|
+
};
|
|
1270
|
+
function b(e, t) {
|
|
1271
|
+
return {
|
|
1272
|
+
role: e,
|
|
1273
|
+
content: [{ type: "text", text: t }]
|
|
1274
|
+
};
|
|
1275
|
+
}
|
|
1276
|
+
async function ae(e, t = {}) {
|
|
1277
|
+
let r;
|
|
1278
|
+
typeof e == "string" ? r = [b("user", e)] : r = e;
|
|
1279
|
+
const n = {
|
|
1280
|
+
messages: r,
|
|
1281
|
+
...t
|
|
1282
|
+
};
|
|
1283
|
+
return l("plugin_ai_ask", { request: n });
|
|
1284
|
+
}
|
|
1285
|
+
async function le(e, t, r = {}) {
|
|
1286
|
+
let n;
|
|
1287
|
+
typeof e == "string" ? n = [b("user", e)] : n = e;
|
|
1288
|
+
const s = {
|
|
1289
|
+
messages: n,
|
|
1290
|
+
...r
|
|
1291
|
+
}, i = `ai_stream_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
|
|
1292
|
+
return new Promise(async (d, w) => {
|
|
1293
|
+
const H = await S(i, (p) => {
|
|
1294
|
+
t(p.payload);
|
|
1295
|
+
}), P = await S(
|
|
1296
|
+
`${i}_error`,
|
|
1297
|
+
(p) => {
|
|
1298
|
+
f(), w(new Error(p.payload));
|
|
1299
|
+
}
|
|
1300
|
+
), g = await S(`${i}_done`, () => {
|
|
1301
|
+
f(), d();
|
|
1302
|
+
}), f = () => {
|
|
1303
|
+
H(), P(), g();
|
|
1304
|
+
};
|
|
1305
|
+
try {
|
|
1306
|
+
await l("plugin_ai_stream", { request: s, eventId: i });
|
|
1307
|
+
} catch (p) {
|
|
1308
|
+
f(), w(p);
|
|
1309
|
+
}
|
|
1310
|
+
});
|
|
1311
|
+
}
|
|
1312
|
+
async function Bt() {
|
|
1313
|
+
try {
|
|
1314
|
+
return await ce() !== null;
|
|
1315
|
+
} catch {
|
|
1316
|
+
return !1;
|
|
1317
|
+
}
|
|
1318
|
+
}
|
|
1319
|
+
async function ce() {
|
|
1320
|
+
return l("get_ai_capabilities", {});
|
|
1321
|
+
}
|
|
1322
|
+
async function Vt() {
|
|
1323
|
+
return l("list_ai_models", {});
|
|
1324
|
+
}
|
|
1325
|
+
async function Wt(e, t) {
|
|
1326
|
+
return l("validate_ai_provider", {
|
|
1327
|
+
base_url: e,
|
|
1328
|
+
api_key: t ?? null
|
|
1329
|
+
});
|
|
1330
|
+
}
|
|
1331
|
+
function zt(e) {
|
|
1332
|
+
return new Gt(e);
|
|
1333
|
+
}
|
|
1334
|
+
class Gt {
|
|
1335
|
+
constructor(t) {
|
|
1336
|
+
u(this, "messages", []);
|
|
1337
|
+
t && this.messages.push(b("system", t));
|
|
1338
|
+
}
|
|
1339
|
+
addMessage(t) {
|
|
1340
|
+
this.messages.push(t);
|
|
1341
|
+
}
|
|
1342
|
+
async ask(t, r) {
|
|
1343
|
+
const n = typeof t == "string" ? b("user", t) : t;
|
|
1344
|
+
this.messages.push(n);
|
|
1345
|
+
try {
|
|
1346
|
+
const s = await ae(this.messages, r || {});
|
|
1347
|
+
return this.messages.push(b("assistant", s)), s;
|
|
1348
|
+
} catch (s) {
|
|
1349
|
+
throw this.messages.pop(), s;
|
|
1350
|
+
}
|
|
1351
|
+
}
|
|
1352
|
+
async stream(t, r, n) {
|
|
1353
|
+
const s = typeof t == "string" ? b("user", t) : t;
|
|
1354
|
+
this.messages.push(s);
|
|
1355
|
+
let i = "";
|
|
1356
|
+
try {
|
|
1357
|
+
await le(
|
|
1358
|
+
this.messages,
|
|
1359
|
+
(d) => {
|
|
1360
|
+
i += d, r(d);
|
|
1361
|
+
},
|
|
1362
|
+
n || {}
|
|
1363
|
+
), this.messages.push(b("assistant", i));
|
|
1364
|
+
} catch (d) {
|
|
1365
|
+
throw this.messages.pop(), d;
|
|
1366
|
+
}
|
|
1367
|
+
}
|
|
1368
|
+
getHistory() {
|
|
1369
|
+
return [...this.messages];
|
|
1370
|
+
}
|
|
1371
|
+
clear() {
|
|
1372
|
+
const t = this.messages.find((r) => r.role === "system");
|
|
1373
|
+
this.messages = t ? [t] : [];
|
|
1374
|
+
}
|
|
1375
|
+
getLastResponse() {
|
|
1376
|
+
for (let t = this.messages.length - 1; t >= 0; t--)
|
|
1377
|
+
if (this.messages[t].role === "assistant") {
|
|
1378
|
+
const n = this.messages[t].content.find((s) => s.type === "text");
|
|
1379
|
+
if (n && n.type === "text") return n.text;
|
|
1380
|
+
}
|
|
1381
|
+
return null;
|
|
1382
|
+
}
|
|
1383
|
+
}
|
|
1384
|
+
const ir = {
|
|
1385
|
+
ask: ae,
|
|
1386
|
+
stream: le,
|
|
1387
|
+
isAvailable: Bt,
|
|
1388
|
+
getCapabilities: ce,
|
|
1389
|
+
listModels: Vt,
|
|
1390
|
+
validateProvider: Wt,
|
|
1391
|
+
createConversation: zt
|
|
1392
|
+
}, or = {
|
|
1393
|
+
version: "0.0.1",
|
|
1394
|
+
getEnvironment: R,
|
|
1395
|
+
getRuntimeInfo: () => ({
|
|
1396
|
+
timestamp: Date.now(),
|
|
1397
|
+
userAgent: typeof navigator < "u" ? navigator.userAgent : "Deno Runtime",
|
|
1398
|
+
platform: typeof navigator < "u" ? navigator.platform : "Unknown"
|
|
1399
|
+
}),
|
|
1400
|
+
async testConnection() {
|
|
1401
|
+
try {
|
|
1402
|
+
return { success: !0, result: await l("plugin_test_connection", {}) };
|
|
1403
|
+
} catch (e) {
|
|
1404
|
+
return { success: !1, error: e instanceof Error ? e.message : String(e) };
|
|
1405
|
+
}
|
|
1406
|
+
}
|
|
1407
|
+
};
|
|
1408
|
+
function Y(e) {
|
|
1409
|
+
var t;
|
|
1410
|
+
if (m.isPluginError(e))
|
|
1411
|
+
switch (e.code) {
|
|
1412
|
+
case o.http.NETWORK_ERROR:
|
|
1413
|
+
case o.http.TIMEOUT:
|
|
1414
|
+
return !0;
|
|
1415
|
+
case o.http.HTTP_ERROR:
|
|
1416
|
+
const r = (t = e.context) == null ? void 0 : t.status;
|
|
1417
|
+
return r === 429 || // Too Many Requests
|
|
1418
|
+
r === 500 || // Internal Server Error
|
|
1419
|
+
r === 502 || // Bad Gateway
|
|
1420
|
+
r === 503 || // Service Unavailable
|
|
1421
|
+
r === 504;
|
|
1422
|
+
case o.clipboard.UNAVAILABLE:
|
|
1423
|
+
return !0;
|
|
1424
|
+
default:
|
|
1425
|
+
return !1;
|
|
1426
|
+
}
|
|
1427
|
+
return !1;
|
|
1428
|
+
}
|
|
1429
|
+
function q(e, t = 1) {
|
|
1430
|
+
var r, n;
|
|
1431
|
+
if (m.isPluginError(e))
|
|
1432
|
+
switch (e.code) {
|
|
1433
|
+
case o.http.HTTP_ERROR:
|
|
1434
|
+
switch ((r = e.context) == null ? void 0 : r.status) {
|
|
1435
|
+
case 429:
|
|
1436
|
+
return (((n = e.context) == null ? void 0 : n.retryAfter) || 60) * 1e3;
|
|
1437
|
+
case 500:
|
|
1438
|
+
return Math.min(1e4 * t, 6e4);
|
|
1439
|
+
case 502:
|
|
1440
|
+
case 503:
|
|
1441
|
+
case 504:
|
|
1442
|
+
return Math.min(5e3 * t, 3e4);
|
|
1443
|
+
default:
|
|
1444
|
+
return Math.min(3e3 * t, 15e3);
|
|
1445
|
+
}
|
|
1446
|
+
case o.http.TIMEOUT:
|
|
1447
|
+
return Math.min(5e3 * t, 3e4);
|
|
1448
|
+
default:
|
|
1449
|
+
return Math.min(3e3 * t, 15e3);
|
|
1450
|
+
}
|
|
1451
|
+
return 3e3 * t;
|
|
1452
|
+
}
|
|
1453
|
+
function K(e, t, r = 3e4) {
|
|
1454
|
+
const n = e * Math.pow(2, t - 1);
|
|
1455
|
+
return Math.min(n, r);
|
|
1456
|
+
}
|
|
1457
|
+
async function x(e, t = {}) {
|
|
1458
|
+
const {
|
|
1459
|
+
maxRetries: r = 3,
|
|
1460
|
+
baseDelay: n = 1e3,
|
|
1461
|
+
exponentialBackoff: s = !1,
|
|
1462
|
+
maxDelay: i = 3e4,
|
|
1463
|
+
shouldRetry: d = Y,
|
|
1464
|
+
getDelay: w = (g, f) => s ? K(n, f, i) : q(g, f),
|
|
1465
|
+
onRetry: H = (g, f, p) => {
|
|
1466
|
+
console.log(
|
|
1467
|
+
`Operation failed, retrying in ${p}ms (${f}/${r})`
|
|
1468
|
+
), m.isPluginError(g) && console.log(`Error type: ${g.code}, message: ${g.message}`);
|
|
1469
|
+
}
|
|
1470
|
+
} = t;
|
|
1471
|
+
let P;
|
|
1472
|
+
for (let g = 1; g <= r; g++)
|
|
1473
|
+
try {
|
|
1474
|
+
return await e();
|
|
1475
|
+
} catch (f) {
|
|
1476
|
+
if (P = f, g === r || !d(f))
|
|
1477
|
+
throw f;
|
|
1478
|
+
const p = w(f, g);
|
|
1479
|
+
H(f, g, p), await new Promise((de) => setTimeout(de, p));
|
|
1480
|
+
}
|
|
1481
|
+
throw P;
|
|
1482
|
+
}
|
|
1483
|
+
function ue(e, t = {}) {
|
|
1484
|
+
return (...r) => x(() => e(...r), t);
|
|
1485
|
+
}
|
|
1486
|
+
const jt = {
|
|
1487
|
+
withRetry: x,
|
|
1488
|
+
createRetryWrapper: ue,
|
|
1489
|
+
isRetryableError: Y,
|
|
1490
|
+
getRetryDelay: q,
|
|
1491
|
+
calculateExponentialBackoff: K
|
|
1492
|
+
}, ar = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
1493
|
+
__proto__: null,
|
|
1494
|
+
calculateExponentialBackoff: K,
|
|
1495
|
+
createRetryWrapper: ue,
|
|
1496
|
+
getRetryDelay: q,
|
|
1497
|
+
isRetryableError: Y,
|
|
1498
|
+
retry: jt,
|
|
1499
|
+
withRetry: x
|
|
1500
|
+
}, Symbol.toStringTag, { value: "Module" }));
|
|
1501
|
+
if (typeof window < "u") {
|
|
1502
|
+
const t = new URLSearchParams(window.location.search).get("plugin_id");
|
|
1503
|
+
t && (window.__PLUGIN_ID__ = t, globalThis.__PLUGIN_ID__ = t), window.addEventListener("message", (r) => {
|
|
1504
|
+
var n;
|
|
1505
|
+
if (((n = r.data) == null ? void 0 : n.type) === "set-plugin-id") {
|
|
1506
|
+
const s = r.data.pluginId;
|
|
1507
|
+
window.__PLUGIN_ID__ = s, globalThis.__PLUGIN_ID__ = s;
|
|
1508
|
+
}
|
|
1509
|
+
});
|
|
1510
|
+
}
|
|
1511
|
+
const lr = {
|
|
1512
|
+
Permissions: {},
|
|
1513
|
+
Errors: {},
|
|
1514
|
+
Retry: {},
|
|
1515
|
+
Fs: {},
|
|
1516
|
+
Dialog: {},
|
|
1517
|
+
Settings: {}
|
|
1518
|
+
};
|
|
1519
|
+
export {
|
|
1520
|
+
ir as ai,
|
|
1521
|
+
er as clipboard,
|
|
1522
|
+
Qt as command,
|
|
1523
|
+
or as debug,
|
|
1524
|
+
Zt as dialog,
|
|
1525
|
+
qt as error,
|
|
1526
|
+
Jt as fs,
|
|
1527
|
+
Kt as http,
|
|
1528
|
+
l as invoke,
|
|
1529
|
+
rr as lifecycle,
|
|
1530
|
+
S as listen,
|
|
1531
|
+
Xt as notification,
|
|
1532
|
+
sr as pluginWindow,
|
|
1533
|
+
ar as retry,
|
|
1534
|
+
nr as scheduler,
|
|
1535
|
+
tr as settings,
|
|
1536
|
+
xt as storage,
|
|
1537
|
+
lr as types
|
|
1538
|
+
};
|