arkflow-magpie-plugins 0.0.0-stage → 2.0.19

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.
@@ -0,0 +1,59 @@
1
+ (() => {
2
+ const status = document.getElementById("status")
3
+ const fallback = document.getElementById("fallback")
4
+ let waiting = false
5
+ fallback.textContent = "重新连接"
6
+ fallback.onclick = event => { event.preventDefault(); location.reload() }
7
+ async function connect() {
8
+ if (waiting) return
9
+ waiting = true
10
+ fallback.hidden = true
11
+ status.textContent = "正在连接 Magpie…"
12
+ let timer, bridge, loaded, failed
13
+ try {
14
+ const ready = globalThis.magpie?.ready || new Promise((resolve, reject) => {
15
+ bridge = document.querySelector?.('script[src="_magpie/bridge.js"]')
16
+ if (!bridge) { reject(new Error("bridge unavailable")); return }
17
+ loaded = () => globalThis.magpie?.ready ? resolve(globalThis.magpie.ready) : reject(new Error("bridge unavailable"))
18
+ failed = () => reject(new Error("bridge unavailable"))
19
+ bridge.addEventListener("load", loaded, { once: true })
20
+ bridge.addEventListener("error", failed, { once: true })
21
+ })
22
+ await Promise.race([ready, new Promise((_, reject) => {
23
+ timer = setTimeout(() => reject(new Error("bridge timeout")), 10_000)
24
+ })])
25
+ let options = {}
26
+ if (!globalThis.magpie.service && globalThis.magpie.options?.get) {
27
+ clearTimeout(timer)
28
+ options = await Promise.race([globalThis.magpie.options.get(), new Promise((_, reject) => {
29
+ timer = setTimeout(() => reject(new Error("options timeout")), 3000)
30
+ })])
31
+ }
32
+ const port = globalThis.NovaFlowConnection.port(options?.servicePort)
33
+ const target = new URL(globalThis.magpie.service || `http://127.0.0.1:${port}/`, location.href)
34
+ if (!/^https?:$/.test(target.protocol) || target.username || target.password || (!globalThis.magpie.service && target.origin !== `http://127.0.0.1:${port}`)) throw new Error("unexpected service")
35
+ // Keep the official entry immediately behind this service document.
36
+ // Returning there asks Magpie to warm a replacement plugin host.
37
+ const entry = new URL(location.href)
38
+ const hash = new URLSearchParams(entry.hash.slice(1))
39
+ const attempts = Math.min(3, Math.max(0, Number(hash.get("nf_host_attempt")) || 0) + 1)
40
+ hash.set("nf_host_attempt", String(attempts))
41
+ entry.hash = hash.toString()
42
+ try { history.replaceState(null, "", entry.href) } catch { location.replace(entry.href) }
43
+ target.searchParams.set("nf_host_entry", "1")
44
+ target.searchParams.set("nf_host_attempt", String(attempts))
45
+ status.textContent = "正在读取 ArkFlow…"
46
+ location.assign(target.href)
47
+ } catch {
48
+ status.textContent = "连接 Magpie 超时,请重新连接;若仍无法打开,请关闭并重新进入 ArkFlow 插件页。"
49
+ fallback.hidden = false
50
+ } finally {
51
+ clearTimeout(timer)
52
+ bridge?.removeEventListener("load", loaded)
53
+ bridge?.removeEventListener("error", failed)
54
+ waiting = false
55
+ }
56
+ }
57
+ addEventListener("pageshow", event => { if (event.persisted) location.reload() })
58
+ void connect()
59
+ })()
@@ -0,0 +1,24 @@
1
+ // Shared by the package entry and its loopback document. No credentials or
2
+ // host page URLs are persisted in service URLs or browser storage.
3
+ globalThis.NovaFlowConnection = {
4
+ recovering: false,
5
+ port(value = 3488) {
6
+ if (!Number.isSafeInteger(value) || value < 1024 || value > 65535) throw new Error("Magpie 服务端口无效,请重新打开插件")
7
+ return value
8
+ },
9
+ recover({ manual = false, location = globalThis.location, history = globalThis.history, framed = globalThis.parent !== globalThis.window, onStalled = () => {}, setTimer = globalThis.setTimeout, clearTimer = globalThis.clearTimeout } = {}) {
10
+ const url = new URL(location.href)
11
+ const attempts = Number(url.searchParams.get("nf_host_attempt")) || 0
12
+ if (!framed || url.searchParams.get("nf_host_entry") !== "1" || !history || history.length < 2 || (!manual && attempts >= 3)) return false
13
+ if (this.recovering) return true
14
+ try {
15
+ this.recovering = true
16
+ history.back()
17
+ // Some WebViews refuse history navigation silently. Always return to
18
+ // an actionable state instead of leaving another infinite spinner.
19
+ const timer = setTimer?.(() => { this.recovering = false; onStalled() }, 3000)
20
+ globalThis.addEventListener?.("pagehide", () => { clearTimer?.(timer); this.recovering = false }, { once: true })
21
+ return true
22
+ } catch { this.recovering = false; return false }
23
+ },
24
+ }
package/page/icon.svg ADDED
@@ -0,0 +1,3 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" width="1024" height="1024" viewBox="0 0 1024 1024"><title>ArkFlow 黑底应用图标</title><path d="M300 0H724C820 0 866 0 917 27C951 45 979 73 997 107C1024 158 1024 204 1024 300V724C1024 820 1024 866 997 917C979 951 951 979 917 997C866 1024 820 1024 724 1024H300C204 1024 158 1024 107 997C73 979 45 951 27 917C0 866 0 820 0 724V300C0 204 0 158 27 107C45 73 73 45 107 27C158 0 204 0 300 0Z" fill="#000000"/><g fill="#FFFFFF" transform="matrix(1.09486781 0 0 1.09486781 -79.499222 -87.163297)"><path id="upper-sail" d="M 560.22837007 473.06636974 C 635.46164365 408.89907691 730.81516604 334.13094072 820.86361943 272.97819458 C 824.11721103 270.76865012 828.32550716 270.53811483 831.80098775 272.37903301 C 835.27646833 274.21995119 837.45000000 277.83086006 837.45000000 281.76379091 L 837.45000000 376.58653544 C 837.45000000 381.87582662 833.55774700 386.35886482 828.32083170 387.10137357 C 740.25606136 399.58751458 645.13704746 430.56951755 563.76552067 478.05051434 C 562.39329966 478.85121728 560.63681046 478.47187630 559.71732541 477.17624404 C 558.79784036 475.88061178 559.01957977 474.09736039 560.22837007 473.06636974 Z"/>
2
+ <path id="middle-sail" d="M 347.29161523 625.00491449 C 407.31896148 592.48912760 444.00576556 561.61231724 514.53465533 522.93238430 C 524.61021101 517.40667959 535.32643341 511.62170719 547.00000000 505.85000000 C 556.39108859 501.20680779 566.11568739 496.78089689 576.05780171 492.34780891 C 645.65260196 461.31619305 727.84222968 433.89239986 823.50841355 416.23669483 C 826.95465632 415.60067233 830.50530475 416.52935724 833.19881712 418.77125486 C 835.89232950 421.01315248 837.45000000 424.33628692 837.45000000 427.84072894 L 837.45000000 536.08814949 C 837.45000000 542.52466861 832.29187801 547.77379174 825.85634306 547.88634522 C 737.69781908 549.42818268 661.16170439 557.16045177 581.41632017 571.47235684 C 570.02412243 573.51691470 558.57605823 575.74440654 547.00000000 578.01000000 C 545.98400873 578.20884343 543.33033828 578.75839036 539.31592895 579.62721578 C 511.21506367 585.70899370 416.39746419 607.22599878 349.00253957 629.00165704 C 347.92920818 629.34845609 346.76841195 628.82043775 346.32451474 627.78348783 C 345.88061754 626.74653792 346.29980954 625.54215870 347.29161523 625.00491449 Z"/>
3
+ <path id="hull" d="M 201.09627624 671.05204790 C 255.68399263 666.37996822 358.88860258 643.04783866 490.10799248 616.62024967 C 508.85361961 612.84487982 528.13401771 608.81118026 548.00000000 605.15000000 C 557.34352041 603.42804576 566.37281250 601.99062500 575.03457031 600.55625000 C 627.00511719 591.95000000 666.33769531 586.76375000 692.19699219 583.78250000 C 696.50687500 583.28562500 700.44100727 582.83575534 704.00000000 582.47000000 C 709.32602794 581.92264762 714.34910880 581.45371929 719.16062676 580.99618732 C 752.84125247 577.79346354 776.26057354 576.19412988 822.97419221 575.15202571 C 826.78346218 575.06704715 830.46623794 576.52081543 833.19034751 579.18483234 C 835.91445708 581.84884926 837.45000000 585.49828585 837.45000000 589.30850357 L 837.45000000 742.99879225 C 837.45000000 749.89201265 832.48611413 755.78368851 825.69286752 756.95342689 C 774.01753595 765.85147252 729.17906346 769.08994083 710.39775818 770.47083345 C 707.71471457 770.66810382 705.56437603 770.83888502 704.00000000 770.96000000 C 695.87062926 771.58938102 687.42593750 772.03078125 678.87060547 772.47058594 C 627.53861328 775.10941406 572.06591797 775.55308594 553.82580078 775.58191406 C 550.78578125 775.58671875 548.78001302 775.57892706 548.00000000 775.57000000 C 531.35121167 775.37945866 515.00045468 775.05706833 498.93277553 774.42716103 C 386.45902144 770.01780993 287.84400976 751.66229920 197.70518878 682.67211976 C 195.57677904 681.04308392 194.66873066 678.27322109 195.41959595 675.70026810 C 196.17046124 673.12731511 198.42576249 671.28061312 201.09627624 671.05204790 Z"/></g></svg>
@@ -0,0 +1,28 @@
1
+ <!doctype html>
2
+ <html lang="zh-CN">
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1">
6
+ <title>ArkFlow</title>
7
+ <script src="_magpie/bridge.js" async></script>
8
+ <script src="theme.js"></script>
9
+ <link rel="stylesheet" href="app.css">
10
+ <script src="connection.js" defer></script>
11
+ <script src="bootstrap.js" defer></script>
12
+ <style>
13
+ html,body{height:100%;margin:0;background:var(--bg);color:var(--fg)}
14
+ body{display:grid;place-items:center;font:13px/1.45 var(--font)}
15
+ main{max-width:36rem;padding:2rem;text-align:center}
16
+ h1{font:600 20px/1.2 var(--font);margin:0 0 8px}
17
+ p{margin:0;color:var(--muted)}
18
+ a{color:var(--accent)}
19
+ </style>
20
+ </head>
21
+ <body>
22
+ <main>
23
+ <h1>ArkFlow</h1>
24
+ <p id="status">正在打开 ArkFlow…</p>
25
+ <p><a id="fallback" href="http://127.0.0.1:3488/" hidden>重新打开 ArkFlow</a></p>
26
+ </main>
27
+ </body>
28
+ </html>
package/page/logo.png ADDED
Binary file
@@ -0,0 +1,131 @@
1
+ /*
2
+ * Magpie component CSS, copied verbatim from the official Magpie source.
3
+ * Copyright (c) 2026 yetone. MIT License: ../docs/MAGPIE-LICENSE.
4
+ * Source: internal/gui/assets/{app.css,plugins.css}
5
+ * Baseline: 0.1.2058, commit 2d11cde056d6307f74b2b4318430d80bb394517d.
6
+ * Plugin-specific adaptations belong in app.css, not in these excerpts.
7
+ */
8
+
9
+ /* Magpie app.css:157-159 (verbatim). */
10
+ button { font: inherit; color: inherit; background: none; border: 0; cursor: default; appearance: none; -webkit-appearance: none; text-align: center; }
11
+ button:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
12
+ input { font: inherit; color: var(--fg); }
13
+
14
+ /* Magpie app.css:2044-2050 (verbatim). */
15
+ .text { font-size: 12px; color: var(--ctl-fg); padding: 3px 7px; border-radius: 6px; transition: background .12s, color .12s; white-space: nowrap; }
16
+ .text:hover { color: var(--fg); background: var(--pill); }
17
+ .text.action { height: 27px; padding: 0 10px; border: 1px solid var(--line); background: var(--card); color: var(--fg-2); box-shadow: 0 1px 1px rgba(0, 0, 0, .04); display: inline-flex; align-items: center; justify-content: center; }
18
+ .text.action:hover { border-color: var(--muted); background: var(--card-2); color: var(--fg); }
19
+ .text.primary { color: var(--accent-fg); background: var(--accent); font-weight: 500; }
20
+ .text.primary:hover { filter: brightness(1.08); }
21
+ .text.danger:hover { color: var(--red); background: var(--red-soft); }
22
+
23
+ /* Magpie app.css:3070-3072 (verbatim). */
24
+ .segs { position: relative; display: inline-flex; padding: 2px; border-radius: 7px; background: var(--pill); align-self: flex-start; }
25
+ .opt { position: relative; z-index: 1; white-space: nowrap; height: 22px; padding: 0 10px; border-radius: 5px; font-size: 12px; color: var(--muted); transition: color .18s var(--ease), transform .14s var(--ease); }
26
+ .opt.on { color: var(--fg); }
27
+
28
+ /* Magpie app.css:3085-3092 (verbatim). */
29
+ .opt:hover:not(.on) { color: var(--fg-2); }
30
+ .thumb {
31
+ position: absolute; top: 2px; bottom: 2px; left: 0; width: 0; border-radius: 6px;
32
+ background: var(--card); box-shadow: 0 1px 2px rgba(0, 0, 0, .12), 0 0 0 .5px rgba(0, 0, 0, .06);
33
+ transition: opacity .15s; /* the glide is slide()'s, which only it starts */
34
+ pointer-events: none;
35
+ }
36
+ .segs .thumb { border-radius: 5px; }
37
+
38
+ /* Magpie plugins.css:10-19 (verbatim). */
39
+ .pm-find {
40
+ display: flex; align-items: center; gap: 6px; height: 28px; padding: 0 10px; width: min(280px, 46%);
41
+ border-radius: 8px; background: var(--pill); color: var(--muted);
42
+ box-shadow: inset 0 0 0 1px transparent; transition: box-shadow .14s var(--ease), background .14s var(--ease);
43
+ }
44
+ .pm-find:focus-within { background: var(--card); box-shadow: inset 0 0 0 1px var(--accent), 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent); }
45
+ .pm-find svg { flex: none; }
46
+ .pm-find input { flex: 1; min-width: 0; border: 0; outline: none; background: none; color: var(--fg); font: inherit; font-size: 12.5px; }
47
+ .pm-find input::placeholder { color: var(--faint); }
48
+ .pm-find input::-webkit-search-cancel-button { cursor: default; }
49
+
50
+ /* Magpie plugins.css:40-54 (verbatim). */
51
+ /* sections of cards */
52
+ .pm-sec { display: flex; flex-direction: column; gap: 9px; }
53
+ .pm-sechead { display: flex; align-items: baseline; gap: 8px; padding: 0 2px; flex-wrap: wrap; }
54
+ .pm-sechead h3 { margin: 0; font-size: 12.5px; font-weight: 650; }
55
+ .pm-sechead span { font-size: 11.5px; color: var(--muted); }
56
+ .pm-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(262px, 1fr)); gap: 10px; }
57
+ /* the GitHub section's kinds, what's installed and its own field, on one
58
+ line while they fit; the field goes under them, the whole width, when
59
+ they don't */
60
+ .pm-ghbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
61
+ .pm-ghbar .segs { flex: none; max-width: 100%; }
62
+ /* it takes a share of the room the strips leave, up to what its
63
+ placeholder needs, so "Filter by name, author or description" isn't cut */
64
+ .pm-ghfind { flex: 4 0 auto; width: min(240px, 100%); max-width: min(320px, 100%); }
65
+ .pm-ghnone { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 22px 12px; border-radius: 12px; border: 1px dashed var(--line); font-size: 12px; color: var(--muted); text-align: center; }
66
+
67
+ /* Magpie plugins.css:63-93 (verbatim). */
68
+ .pm-logo { flex: none; width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; background: var(--pill); color: var(--fg-2); }
69
+ .pm-logo .ic { width: 20px; height: 20px; }
70
+ .pm-logo.big { width: 44px; height: 44px; border-radius: 12px; }
71
+ .pm-logo.big .ic { width: 25px; height: 25px; }
72
+
73
+ .pm-card {
74
+ display: flex; flex-direction: column; gap: 8px; min-width: 0; padding: 12px 12px 11px 13px;
75
+ border-radius: 12px; border: 1px solid var(--line); background: var(--card); cursor: default; outline: none;
76
+ transition: border-color .16s var(--ease), box-shadow .16s var(--ease), transform .16s var(--ease);
77
+ }
78
+ .pm-card:hover { border-color: color-mix(in srgb, var(--fg) 16%, var(--line)); box-shadow: 0 4px 14px rgba(20, 22, 30, .07); }
79
+ .pm-card:focus-visible { box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 28%, transparent); border-color: var(--accent); }
80
+ .pm-top { display: flex; align-items: center; gap: 10px; min-width: 0; }
81
+ .pm-who { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
82
+ .pm-name { display: flex; align-items: center; gap: 6px; min-width: 0; }
83
+ .pm-name b { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
84
+ .pm-by { display: flex; align-items: center; gap: 4px; min-width: 0; font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
85
+ .pm-by > span { overflow: hidden; text-overflow: ellipsis; }
86
+ .pm-verified { display: inline-flex; align-items: center; gap: 3px; color: var(--green); font-weight: 500; }
87
+ .pm-sum {
88
+ margin: 0; font-size: 12px; line-height: 1.45; color: var(--fg-2); min-height: 2.9em;
89
+ display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
90
+ }
91
+ .pm-meta { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; min-height: 18px; }
92
+ .pm-dl { display: inline-flex; align-items: center; gap: 3px; }
93
+ .pm-ver { font: var(--code-style, normal) var(--code-weight, 400) 10.5px var(--code-font, var(--code)); font-stretch: var(--code-stretch, 100%); color: var(--muted); }
94
+ .pm-chip { display: inline-flex; align-items: center; height: 17px; padding: 0 6px; border-radius: 5px; font-size: 10.5px; font-weight: 500; background: var(--pill); color: var(--fg-2); }
95
+ .pm-chip.up { background: var(--accent-soft); color: var(--accent); }
96
+ button.pm-chip { border: 0; font-family: inherit; cursor: pointer; }
97
+ button.pm-chip.up:hover:not(:disabled) { background: var(--accent); color: var(--accent-fg); }
98
+ button.pm-chip:disabled { cursor: default; opacity: .6; }
99
+
100
+ /* Magpie plugins.css:125-150 (verbatim). */
101
+ .pm-chip.soft { background: none; box-shadow: inset 0 0 0 1px var(--line); color: var(--muted); }
102
+
103
+ /* a plugin's one button */
104
+ .pm-act {
105
+ flex: none; display: inline-flex; align-items: center; justify-content: center; gap: 5px;
106
+ height: 26px; min-width: 64px; padding: 0 12px; border-radius: 13px;
107
+ font-size: 12px; font-weight: 600; white-space: nowrap;
108
+ background: var(--pill); color: var(--fg-2); transition: background .14s var(--ease), color .14s var(--ease), filter .14s;
109
+ }
110
+ .pm-act:hover:not(:disabled) { background: var(--pill-hover); color: var(--fg); }
111
+ .pm-act.get { background: var(--accent-soft); color: var(--accent); }
112
+ .pm-act.get:hover:not(:disabled) { background: var(--accent); color: var(--accent-fg); }
113
+ /* an update out: Install's size, green for its own (#1587) */
114
+ .pm-act.pm-up { background: var(--green-soft); color: var(--green); }
115
+ .pm-act.pm-up:hover:not(:disabled) { background: var(--green); color: var(--card); }
116
+ /* Sign in, in a list of cards or rows, is Install's tinted capsule: one
117
+ style for a row's action, so no card shouts over its neighbours (HIG's
118
+ one filled button is a sheet's own); a plugin's page fills it */
119
+ .pm-act.go { background: var(--accent-soft); color: var(--accent); }
120
+ .pm-act.go:hover:not(:disabled), .pm-dact .pm-act.go { background: var(--accent); color: var(--accent-fg); }
121
+ .pm-dact .pm-act.go:hover:not(:disabled) { filter: brightness(1.08); }
122
+ .pm-act.done { background: none; color: var(--green); padding: 0 8px; min-width: 0; }
123
+ .pm-act.done:hover:not(:disabled) { background: var(--green-soft); color: var(--green); }
124
+ .pm-act.busy { color: var(--muted); font-weight: 500; }
125
+ .pm-act:disabled:not(.busy):not(.done) { opacity: .55; }
126
+ .pm-act .spin { width: 10px; height: 10px; border-radius: 50%; border: 1.5px solid currentColor; border-right-color: transparent; animation: spin .7s linear infinite; }
127
+
128
+ /* Magpie plugins.css:116-117,121 (verbatim). */
129
+ .pm-chip.kind { gap: 4px; flex: none; padding: 0; background: none; color: var(--fg-2); font-weight: 400; }
130
+ .pm-chip.kind svg { flex: none; }
131
+ .pm-chip.kind.pv { color: color-mix(in srgb, var(--accent) 80%, var(--fg-2)); }
@@ -0,0 +1,101 @@
1
+ // Classic script: Magpie's opaque sandbox cannot import cross-origin modules.
2
+ globalThis.createNovaFlowPageRequest = ({ token, fetch: send = globalThis.fetch, location: page = globalThis.location, now = Date.now, timeoutMs = 10_000, writeTimeoutMs = 120_000 }) => {
3
+ let reconnecting = false
4
+ const recoveryParam = "nf_page_recovered_at"
5
+ return async function request(path, body, { signal } = {}) {
6
+ if (reconnecting) throw new Error("本机服务已更新,正在重新连接…")
7
+ const controller = new AbortController()
8
+ const abort = () => controller.abort(signal.reason)
9
+ signal?.addEventListener("abort", abort, { once: true })
10
+ if (signal?.aborted) abort()
11
+ let timer
12
+ try {
13
+ const deadline = new Promise((_, reject) => {
14
+ const cancel = () => reject(controller.signal.reason || new Error("请求已取消"))
15
+ controller.signal.addEventListener("abort", cancel, { once: true })
16
+ if (controller.signal.aborted) cancel()
17
+ timer = setTimeout(() => {
18
+ controller.abort(Object.assign(new Error(body === undefined ? "读取 ArkFlow 超时,请重新连接" : "操作等待超时,结果可能已保存,请刷新状态后再确认"), { code: "PAGE_REQUEST_TIMEOUT" }))
19
+ }, body === undefined ? timeoutMs : writeTimeoutMs)
20
+ })
21
+ const work = async () => {
22
+ const response = await send(path, {
23
+ method: body === undefined ? "GET" : "POST",
24
+ signal: controller.signal,
25
+ headers: { "x-novaflow-page-token": token, ...(body === undefined ? {} : { "content-type": "application/json" }) },
26
+ ...(body === undefined ? {} : { body: JSON.stringify(body) }),
27
+ })
28
+ let result
29
+ try { result = await response.json() }
30
+ catch { throw Object.assign(new Error("ArkFlow 返回内容异常,请重新连接"), { code: "PAGE_RESPONSE_INVALID" }) }
31
+ if (!result || typeof result !== "object") throw Object.assign(new Error("ArkFlow 返回内容异常,请重新连接"), { code: "PAGE_RESPONSE_INVALID" })
32
+ if (!response.ok) {
33
+ if (response.status === 403 && (result.code === "PAGE_TOKEN_INVALID" || result.error === "Missing page command token")) {
34
+ if (reconnecting) throw new Error("本机服务已更新,正在重新连接…")
35
+ const url = new URL(page.href)
36
+ const last = Number(url.searchParams.get(recoveryParam))
37
+ const count = Number(url.searchParams.get("nf_page_recoveries")) || 0
38
+ const timestamp = now()
39
+ // Only counters are persisted. No credential ever enters a URL.
40
+ if ((!last || timestamp - last >= 60_000) && count < 2) {
41
+ reconnecting = true
42
+ url.searchParams.set(recoveryParam, String(timestamp))
43
+ url.searchParams.set("nf_page_recoveries", String(count + 1))
44
+ page.replace(url.href)
45
+ throw new Error("本机服务已更新,正在重新连接…")
46
+ }
47
+ throw new Error("页面连接未恢复,请关闭并重新打开 ArkFlow 插件页。无需退出账户。")
48
+ }
49
+ throw Object.assign(new Error(result.error || "操作失败,请重试"), { code: result.code || "", requestId: result.requestId || "" })
50
+ }
51
+ return result
52
+ }
53
+ return await Promise.race([work(), deadline])
54
+ } finally {
55
+ clearTimeout(timer)
56
+ signal?.removeEventListener("abort", abort)
57
+ }
58
+ }
59
+ }
60
+
61
+ // One visible/online polling chain, with bounded read-only retries. Stopping
62
+ // aborts both pending reads and backoff; mutations never enter this scheduler.
63
+ globalThis.createNovaFlowStatePolling = ({ read, active, onError, setTimer = setTimeout, clearTimer = clearTimeout, interval = 15_000, backoffs = [1000, 2000, 4000] }) => {
64
+ let timer, current, stopped = true, rerun = false
65
+ const clear = () => { clearTimer(timer); timer = undefined }
66
+ const tick = async () => {
67
+ if (stopped || !active()) return
68
+ clear()
69
+ if (current) { rerun = true; return }
70
+ const controller = new AbortController()
71
+ current = controller
72
+ let failed = false
73
+ try {
74
+ for (let attempt = 0; attempt <= backoffs.length; attempt++) {
75
+ if (controller.signal.aborted || stopped || !active()) return
76
+ try { await read(controller.signal); failed = false; break }
77
+ catch (error) {
78
+ if (controller.signal.aborted) return
79
+ failed = true
80
+ if (attempt === backoffs.length) { onError(error); break }
81
+ await new Promise(resolve => {
82
+ const finish = () => { clear(); controller.signal.removeEventListener("abort", finish); resolve() }
83
+ controller.signal.addEventListener("abort", finish, { once: true })
84
+ timer = setTimer(finish, backoffs[attempt])
85
+ })
86
+ }
87
+ }
88
+ } finally {
89
+ current = null
90
+ if (!stopped && active()) {
91
+ if (rerun) { rerun = false; void tick() }
92
+ else if (!failed) timer = setTimer(tick, typeof interval === "function" ? interval() : interval)
93
+ }
94
+ }
95
+ }
96
+ return {
97
+ start() { stopped = false; void tick() },
98
+ retry() { stopped = false; rerun = !!current; current?.abort(); void tick() },
99
+ stop() { stopped = true; rerun = false; clear(); current?.abort() },
100
+ }
101
+ }
@@ -0,0 +1,3 @@
1
+ <!doctype html>
2
+ <html lang="zh-CN"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><meta name="novaflow-page-token" content="__CSRF_TOKEN__"><title>ArkFlow · 账户与技能同步</title><script src="connection.js"></script><script src="theme.js"></script><link rel="stylesheet" href="app.css"><link rel="stylesheet" href="magpie-components.css"><script src="store-model.mjs" defer></script><script src="request.js" defer></script><script src="app.js" defer></script></head>
3
+ <body><main id="app" aria-busy="true"><p class="empty">正在读取 ArkFlow…</p></main><div id="toast" role="status" aria-live="polite"></div><dialog id="login-setup" closedby="none" aria-labelledby="setup-title"></dialog><dialog id="detail" aria-label="技能详情"></dialog><footer><button id="website" data-origin="__NOVAFLOW_ORIGIN__" type="button">ArkFlow 官网 ↗</button><span>ArkFlow for Magpie</span></footer></body></html>
@@ -0,0 +1,107 @@
1
+ // This file also runs as a classic script inside Magpie's opaque sandbox.
2
+ // Keep it dependency-free so static assets never need cross-origin credentials.
3
+ globalThis.NovaFlowStore = (() => {
4
+ const list = (value) => Array.isArray(value) ? value : []
5
+ const text = (value) => String(value ?? "")
6
+ const enterprise = (state) => state?.session?.accountMode === "enterprise"
7
+ const companyVisible = (state) => enterprise(state) && state?.session?.capabilities?.company_skills === true
8
+
9
+ function localSkills(value) {
10
+ const source = Array.isArray(value) ? value : Array.isArray(value?.skills) ? value.skills : value?.skills?.skills
11
+ if (!Array.isArray(source)) throw new Error("Magpie 本机技能列表格式异常")
12
+ const seen = new Set()
13
+ return source.filter((item) => {
14
+ if (!item || !text(item.name).trim() || seen.has(item.name)) return false
15
+ seen.add(item.name)
16
+ return true
17
+ }).map((item) => ({ ...item, name: text(item.name), agents: list(item.agents).map(text) }))
18
+ }
19
+
20
+ function items(state) {
21
+ const company = companyVisible(state) ? list(state?.skills?.store?.company) : []
22
+ return [...list(state?.bundledSkills), ...company.filter((item) => !item.status || item.status === "published").map((item) => ({ ...item, source_kind: "company" }))]
23
+ }
24
+
25
+ function retainedItems(state) {
26
+ if (!companyVisible(state)) return []
27
+ const current = items(state)
28
+ return list(state?.skills?.entries).filter((entry) => !current.some((item) => text(item.skill_id) === text(entry.skillId) && item.source_kind === (entry.sourceKind || "company"))).map((entry) => ({
29
+ skill_id: entry.skillId, source_kind: entry.sourceKind || "company", slug: entry.slug,
30
+ display_name: entry.displayName || entry.slug || entry.alias, description: entry.description,
31
+ publisher: entry.publisher, category_id: entry.categoryId, category_name: entry.categoryName,
32
+ current_version: entry.version, unavailable: true,
33
+ }))
34
+ }
35
+
36
+ function categoryName(item, state) {
37
+ const category = list(state?.skills?.store?.categories).find((value) => text(value.id) === text(item.category_id))
38
+ return text(category?.name || item.category_name || "未分类")
39
+ }
40
+
41
+ function publisherName(item) {
42
+ if (item.source_kind === "platform" || item.source_kind === "builtin") {
43
+ if (!item.publisher || /^nova[ -]?flow$/i.test(text(item.publisher).trim())) return "ArkFlow"
44
+ }
45
+ return item.publisher || "公司成员"
46
+ }
47
+
48
+ function categories(state) {
49
+ const result = [{ id: "all", name: "全部分类" }], seen = new Set()
50
+ const add = (id, name) => {
51
+ if (!id || seen.has(id)) return
52
+ seen.add(id)
53
+ result.push({ id: `category:${id}`, name: text(name || "未命名分类") })
54
+ }
55
+ for (const item of [...(companyVisible(state) ? list(state?.skills?.store?.categories) : [])].sort((a, b) => (Number(a.sort_order) || 0) - (Number(b.sort_order) || 0))) {
56
+ add(text(item.id), item.name)
57
+ }
58
+ const company = items(state)
59
+ for (const item of company) if (item.category_id) add(text(item.category_id), item.category_name)
60
+ if (company.some((item) => !item.category_id)) result.push({ id: "uncategorized", name: "未分类" })
61
+ return result
62
+ }
63
+
64
+ function installation(item, state, local) {
65
+ const entry = list(state?.skills?.entries).find((value) => text(value.skillId) === text(item.skill_id) && (value.sourceKind || "company") === item.source_kind)
66
+ const registered = entry?.registration === "registered"
67
+ const isInstalled = registered && Array.isArray(local) && local.some((value) => value.name === entry.alias)
68
+ return {
69
+ entry,
70
+ isInstalled,
71
+ unknown: registered && !Array.isArray(local),
72
+ downloaded: entry?.download === "installed" && !isInstalled,
73
+ updateAvailable: !item.unavailable && isInstalled && Number(entry.version) < Number(item.current_version),
74
+ }
75
+ }
76
+
77
+ function matchesCategory(item, category) {
78
+ if (category === "all") return true
79
+ if (category === "uncategorized") return !item.category_id
80
+ return category === `category:${text(item.category_id)}`
81
+ }
82
+
83
+ function filterItems(state, local, { category = "all", installation: selection = "all", query = "" } = {}) {
84
+ const search = text(query).trim().toLocaleLowerCase()
85
+ const available = items(state)
86
+ const source = selection === "installed" ? [...available, ...retainedItems(state)] : available
87
+ return source.filter((item) => {
88
+ const status = installation(item, state, local)
89
+ if (!matchesCategory(item, category) || selection === "installed" && !status.isInstalled || selection === "uninstalled" && (status.isInstalled || status.unknown)) return false
90
+ return [item.display_name, item.description, publisherName(item), categoryName(item, state), ...list(item.tags)].map(text).join(" ").toLocaleLowerCase().includes(search)
91
+ })
92
+ }
93
+
94
+ function otherLocalSkills(state, local, query = "") {
95
+ const registered = new Set([...items(state), ...retainedItems(state)].map((item) => installation(item, state, local)).filter((value) => value.isInstalled).map((value) => value.entry.alias))
96
+ const search = text(query).trim().toLocaleLowerCase()
97
+ return list(local).filter((item) => !registered.has(item.name) && [item.name, ...list(item.agents)].join(" ").toLocaleLowerCase().includes(search))
98
+ }
99
+
100
+ function syncLabel(state) {
101
+ const value = state?.sync || {}
102
+ if (value.stale || value.status === "stale") return "使用上次同步结果"
103
+ return ({ ready: "已同步", partial: "部分同步失败", syncing: "正在同步", refreshing: "正在更新", failed: "同步失败", error: "同步失败", wait_connection: "等待连接" })[value.status] || "等待同步"
104
+ }
105
+
106
+ return { enterprise, companyVisible, localSkills, items, retainedItems, categoryName, publisherName, categories, installation, filterItems, otherLocalSkills, syncLabel }
107
+ })()
package/page/theme.js ADDED
@@ -0,0 +1,51 @@
1
+ // Magpie 0.1.2058 pagebridge.js / assets/pluginpages.js theme protocol.
2
+ // The local-service navigation keeps the same sandbox WindowProxy, so its
3
+ // document must say hello again to receive the official theme and updates.
4
+ // This adapter reads theme and visibility only; it never asks for options or host APIs.
5
+ (() => {
6
+ const tokens = ["bg", "card", "fg", "fg-2", "muted", "faint", "line", "accent", "accent-soft", "accent-fg", "green", "red", "amber", "font", "code"]
7
+ const root = document.documentElement
8
+ const listeners = []
9
+ const lifecycle = globalThis.NovaFlowHost = {
10
+ visible: true,
11
+ onVisibility(fn) { listeners.push(fn) },
12
+ }
13
+ function visibility(visible) {
14
+ if (typeof visible !== "boolean") return
15
+ lifecycle.visible = visible
16
+ for (const fn of listeners) fn(visible)
17
+ }
18
+ function paint(theme) {
19
+ if (!theme || typeof theme.dark !== "boolean" || !theme.tokens || typeof theme.tokens !== "object" || Array.isArray(theme.tokens)) return
20
+ root.dataset.theme = theme.dark ? "dark" : "light"
21
+ root.style.colorScheme = theme.dark ? "dark" : "light"
22
+ for (const name of tokens) {
23
+ const value = theme.tokens[name]
24
+ if (typeof value === "string" && value.trim() && value.length <= 1024) root.style.setProperty("--magpie-" + name, value)
25
+ else root.style.removeProperty("--magpie-" + name)
26
+ }
27
+ }
28
+ // On the initial package page the official bridge is already available.
29
+ if (window.magpie?.ready && typeof window.magpie.onTheme === "function") {
30
+ window.magpie.onTheme(paint)
31
+ window.magpie.onVisibility?.(visibility)
32
+ Promise.resolve(window.magpie.ready).then(() => visibility(window.magpie.visible !== false)).catch(() => {})
33
+ Promise.resolve(window.magpie.ready).then(paint).catch(() => {})
34
+ return
35
+ }
36
+ // A separately opened local page uses the stylesheet's system fallback.
37
+ if (window.parent === window) return
38
+ const helloId = "novaflow-theme-hello"
39
+ addEventListener("message", (event) => {
40
+ if (event.source !== window.parent) return
41
+ const message = event.data
42
+ if (!message || message.magpie !== 1) return
43
+ if (message.event === "visibility") visibility(message.data?.visible)
44
+ else if (message.event === "theme") paint(message.data)
45
+ else if (message.id === helloId && !message.error) {
46
+ paint(message.result)
47
+ visibility(message.result?.visible !== false)
48
+ }
49
+ })
50
+ window.parent.postMessage({ magpie: 1, id: helloId, method: "hello" }, "*")
51
+ })()
@@ -0,0 +1,124 @@
1
+ import { stableId } from "./state-store.mjs"
2
+
3
+ function keyId(value) {
4
+ return String(value)
5
+ }
6
+
7
+ function validKey(item) {
8
+ return item
9
+ && item.key_id !== undefined
10
+ && item.key_id !== null
11
+ && item.group_id !== undefined
12
+ && typeof item.key === "string"
13
+ && item.key.length > 0
14
+ && item.status === "active"
15
+ }
16
+
17
+ export class AccountManager {
18
+ constructor({ onChange = () => {}, store = null } = {}) {
19
+ this.onChange = onChange
20
+ this.store = store
21
+ this.revision = ""
22
+ this.ownedKeyIds = new Set()
23
+ this.rows = new Map()
24
+ this.native = { providers: [], failures: [], migrationRequired: false }
25
+ this.rejected = []
26
+ this.updatedAt = ""
27
+ if (store) {
28
+ const saved = store.read()
29
+ this.revision = String(saved.revision ?? "")
30
+ this.ownedKeyIds = new Set(Array.isArray(saved.ownedKeyIds) ? saved.ownedKeyIds.map(String) : [])
31
+ this.rows = new Map((Array.isArray(saved.rows) ? saved.rows : []).map(({ models, ...row }) => [keyId(row.key_id), row]))
32
+ this.native = saved.native || { providers: [], failures: [], migrationRequired: saved.rows?.some(row => row.models?.length) === true }
33
+ }
34
+ }
35
+
36
+ persist() {
37
+ this.store?.write({
38
+ revision: this.revision,
39
+ ownedKeyIds: [...this.ownedKeyIds],
40
+ rows: [...this.rows.values()],
41
+ native: this.native,
42
+ updatedAt: this.updatedAt,
43
+ })
44
+ }
45
+
46
+ reconcile(payload, { now = new Date().toISOString() } = {}) {
47
+ const items = Array.isArray(payload?.items) ? payload.items.filter(validKey) : []
48
+ const nextIds = new Set(items.map((item) => keyId(item.key_id)))
49
+ for (const previous of this.ownedKeyIds) {
50
+ if (!nextIds.has(previous)) this.rows.delete(previous)
51
+ }
52
+ this.ownedKeyIds = nextIds
53
+ this.rejected = Array.isArray(payload?.rejected) ? payload.rejected : []
54
+ for (const item of items) {
55
+ this.rows.set(keyId(item.key_id), {
56
+ ...item,
57
+ key_id: item.key_id,
58
+ group_id: item.group_id,
59
+ stable_account_id: `nfk_${stableId("key", item.key_id, item.group_id).slice(0, 24)}`,
60
+ })
61
+ }
62
+ this.revision = String(payload?.revision ?? this.revision)
63
+ this.updatedAt = now
64
+ this.persist()
65
+ this.onChange()
66
+ return this.projection()
67
+ }
68
+
69
+ setNativeState(value) {
70
+ this.native = structuredClone(value)
71
+ this.persist()
72
+ }
73
+
74
+ rowsForDisplay() {
75
+ return [...this.rows.values()].map((row) => ({
76
+ keyId: String(row.key_id),
77
+ groupId: String(row.group_id),
78
+ groupName: String(row.group_name ?? ""),
79
+ platform: String(row.platform ?? ""),
80
+ displayName: String(row.display_name ?? ""),
81
+ status: String(row.status ?? ""),
82
+ expiresAt: row.expires_at ?? null,
83
+ modelCount: this.native.providers.find(item => item.keyId === String(row.key_id))?.modelCount ?? 0,
84
+ stableAccountId: row.stable_account_id,
85
+ }))
86
+ }
87
+
88
+ projection() {
89
+ const modelRoutes = this.native.providers.flatMap(provider => (provider.models || []).map(model => ({
90
+ id: provider.id + "/" + model.id,
91
+ providerId: provider.id,
92
+ keyId: provider.keyId,
93
+ groupName: provider.groupName,
94
+ upstreamModelId: model.id,
95
+ displayName: model.name || model.id,
96
+ imageGeneration: model.draws === true,
97
+ videoGeneration: model.films === true,
98
+ })))
99
+ return {
100
+ revision: this.revision,
101
+ keyCount: this.rows.size,
102
+ routeCount: modelRoutes.length,
103
+ rejectedCount: this.rejected.length,
104
+ keys: this.rowsForDisplay(),
105
+ modelRoutes,
106
+ native: structuredClone(this.native),
107
+ updatedAt: this.updatedAt,
108
+ }
109
+ }
110
+
111
+ disposeOwnedOnly() {
112
+ this.rows.clear()
113
+ this.ownedKeyIds.clear()
114
+ this.native = { providers: [], failures: [], migrationRequired: this.native.migrationRequired }
115
+ this.store?.write({
116
+ revision: this.revision,
117
+ ownedKeyIds: [],
118
+ rows: [],
119
+ native: this.native,
120
+ updatedAt: new Date().toISOString(),
121
+ })
122
+ this.onChange()
123
+ }
124
+ }