@my-life-buddies/cli-refinewidget 0.0.0-stage → 0.37.0-dev.2
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 +19 -2
- package/dist/bin/buddy.js +821 -0
- package/dist/bin/buddy.js.map +7 -0
- package/dist/bin/command-runner.js +640 -0
- package/dist/bin/command-runner.js.map +7 -0
- package/dist/bin/core.js +12379 -0
- package/dist/bin/core.js.map +7 -0
- package/dist/bin/platform.js +597 -0
- package/dist/bin/platform.js.map +7 -0
- package/dist/bin/preview.js +6246 -0
- package/dist/bin/preview.js.map +7 -0
- package/dist/bin/resources/widget-document.js +176 -0
- package/dist/bin/runtime-preflight.js +212 -0
- package/dist/bin/runtime-preflight.js.map +7 -0
- package/install/windows-bin.cjs +108 -0
- package/package.json +66 -4
- package/resources/README.md +10 -0
- package/resources/agent-template/buddy-dev-control.mjs +51 -0
- package/resources/agent-template/buddy-dev-preload.mjs +47 -0
- package/resources/agent-template/package-lock.json +23 -0
- package/resources/agent-template/package.json +14 -0
- package/resources/widget-template/index.html +209 -0
- package/resources/widget-template/schema.json +15 -0
- package/resources/windows-job/win32-arm64/buddy_windows_job.node +0 -0
- package/resources/windows-job/win32-arm64/manifest.json +40 -0
- package/resources/windows-job/win32-x64/buddy_windows_job.node +0 -0
- package/resources/windows-job/win32-x64/manifest.json +41 -0
|
@@ -0,0 +1,640 @@
|
|
|
1
|
+
// apps/cli/src/command-runner.ts
|
|
2
|
+
import { stdin, stderr, stdout } from "node:process";
|
|
3
|
+
import { createInterface } from "node:readline/promises";
|
|
4
|
+
import { PromptCancelledError, resolvePlatformUrl as resolvePlatformUrl2, runBuddyCli } from "./core.js";
|
|
5
|
+
|
|
6
|
+
// apps/cli/src/platform-host.ts
|
|
7
|
+
import { CLI_COMMAND_NAME, RUNTIME_SOURCE_LABEL } from "./platform.js";
|
|
8
|
+
import { resolve } from "node:path";
|
|
9
|
+
import { createHash } from "node:crypto";
|
|
10
|
+
import { readBuddyProjectManifest } from "./core.js";
|
|
11
|
+
import { openExternalTarget } from "./platform.js";
|
|
12
|
+
|
|
13
|
+
// apps/cli/src/runtime-logs.ts
|
|
14
|
+
import { splitModelInputPreview } from "./preview.js";
|
|
15
|
+
import { stripVTControlCharacters } from "node:util";
|
|
16
|
+
var MAX_LOG_LINE = 98304;
|
|
17
|
+
function createRuntimeLogForwarder(onLog, secrets) {
|
|
18
|
+
const streams = /* @__PURE__ */ new Map();
|
|
19
|
+
const frames = /* @__PURE__ */ new Map();
|
|
20
|
+
const redact = (text) => {
|
|
21
|
+
for (const secret of secrets) if (secret) text = text.split(secret).join("[REDACTED]");
|
|
22
|
+
return text.replace(/\bBearer\s+[^\s,'"}]+/giu, "Bearer [REDACTED]").replace(/\b(?:[\w-]*(?:token|secret|password|api[_-]?key)|authorization)["']?\s*[:=]\s*(?:"[^"]*"|'[^']*'|[^\s,"'}]+)/giu, "[REDACTED]");
|
|
23
|
+
};
|
|
24
|
+
const emit = (source) => {
|
|
25
|
+
const pending = streams.get(source);
|
|
26
|
+
if (!pending) return;
|
|
27
|
+
streams.delete(source);
|
|
28
|
+
let text = stripVTControlCharacters(pending.text);
|
|
29
|
+
if (text.startsWith("BUDDY_DEV_LOG_V1 ")) {
|
|
30
|
+
try {
|
|
31
|
+
const frame = JSON.parse(text.slice(17));
|
|
32
|
+
if (typeof frame.recordId !== "string" || typeof frame.text !== "string" || !Number.isSafeInteger(frame.part) || !Number.isSafeInteger(frame.total) || frame.total < 1 || frame.total > 512 || frame.part < 0 || frame.part >= frame.total) return;
|
|
33
|
+
const key = `${source}:${frame.recordId}`;
|
|
34
|
+
const identity = JSON.stringify([frame.v, frame.buddyId, frame.scope, frame.convoKey, frame.runtimeRunId, frame.sourceMessageId, frame.level, frame.timestamp, frame.title, frame.truncated, frame.modelInputPreviewVersion]);
|
|
35
|
+
const item = frame.part === 0 ? { next: 0, total: frame.total, text: "", identity } : frames.get(key);
|
|
36
|
+
if (!item || item.next !== frame.part || item.total !== frame.total || item.identity !== identity) {
|
|
37
|
+
frames.delete(key);
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
item.next++;
|
|
41
|
+
item.text += frame.text;
|
|
42
|
+
if (Buffer.byteLength(item.text) > 128 * 1024) {
|
|
43
|
+
frames.delete(key);
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
if (item.next < item.total) {
|
|
47
|
+
frames.set(key, item);
|
|
48
|
+
while (frames.size > 32) frames.delete(frames.keys().next().value);
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
frames.delete(key);
|
|
52
|
+
let body = item.text;
|
|
53
|
+
if (frame.modelInputPreviewVersion === 1 && frame.truncated === true && frame.title === "\u6A21\u578B\u8BF7\u6C42\u4F53") {
|
|
54
|
+
const { raw, inputPreview } = splitModelInputPreview(body, redact);
|
|
55
|
+
body = redact(raw);
|
|
56
|
+
if (inputPreview) body = JSON.stringify(inputPreview) + "\n" + body;
|
|
57
|
+
else delete frame.modelInputPreviewVersion;
|
|
58
|
+
} else body = redact(body);
|
|
59
|
+
onLog({ source, text: "BUDDY_DEV_LOG_V1 " + JSON.stringify({ ...frame, part: 0, total: 1, title: redact(String(frame.title ?? "")), text: body }) });
|
|
60
|
+
} catch {
|
|
61
|
+
}
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
for (const secret of secrets) if (secret) text = text.split(secret).join("[REDACTED]");
|
|
65
|
+
if (pending.truncated) {
|
|
66
|
+
for (const secret of secrets) {
|
|
67
|
+
for (let size = Math.min(secret.length - 1, text.length); size > 0; size--) {
|
|
68
|
+
if (text.endsWith(secret.slice(0, size))) {
|
|
69
|
+
text = text.slice(0, -size) + "[REDACTED]";
|
|
70
|
+
break;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
text = text.replace(/[\u0000-\u0008\u000b-\u001f\u007f]/gu, "").trimEnd();
|
|
76
|
+
if (!text) return;
|
|
77
|
+
text = text.slice(0, MAX_LOG_LINE) + (pending.truncated || text.length > MAX_LOG_LINE ? " \u2026[truncated]" : "");
|
|
78
|
+
text = redact(text);
|
|
79
|
+
try {
|
|
80
|
+
onLog({ source, text });
|
|
81
|
+
} catch {
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
return {
|
|
85
|
+
write({ source, text }) {
|
|
86
|
+
const limit = MAX_LOG_LINE + Math.max(0, ...[...secrets].map((secret) => secret.length));
|
|
87
|
+
for (const part of text.split(/(?<=\n)/u)) {
|
|
88
|
+
const pending = streams.get(source) ?? { text: "", truncated: false };
|
|
89
|
+
const available = Math.max(0, limit - pending.text.length);
|
|
90
|
+
pending.text += part.slice(0, available);
|
|
91
|
+
pending.truncated ||= part.length > available;
|
|
92
|
+
streams.set(source, pending);
|
|
93
|
+
if (part.endsWith("\n")) emit(source);
|
|
94
|
+
}
|
|
95
|
+
},
|
|
96
|
+
flush() {
|
|
97
|
+
for (const source of streams.keys()) emit(source);
|
|
98
|
+
frames.clear();
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// apps/cli/src/platform-host.ts
|
|
104
|
+
import {
|
|
105
|
+
CloudAuthenticator,
|
|
106
|
+
BuddyDevError,
|
|
107
|
+
checkRuntimeUpdate,
|
|
108
|
+
checkProjectGateway,
|
|
109
|
+
DEFAULT_MLB_TEST_URL,
|
|
110
|
+
HttpDeveloperPlatformClient,
|
|
111
|
+
HttpClinicClient,
|
|
112
|
+
LoopbackBrowserLoginAdapter,
|
|
113
|
+
MlbDevRegistrationClient,
|
|
114
|
+
MockDeveloperPlatformClient,
|
|
115
|
+
SystemCloudTokenStore,
|
|
116
|
+
SystemBuddyTokenStore,
|
|
117
|
+
createBuddyDevStarter,
|
|
118
|
+
findLocalPreviewInstance,
|
|
119
|
+
stopLocalDev,
|
|
120
|
+
createPushPreflight,
|
|
121
|
+
createPushSourceBundle,
|
|
122
|
+
resolvePlatformUrl,
|
|
123
|
+
resolveDeveloperWebUrl,
|
|
124
|
+
requireBuddyAgentProjectRoot
|
|
125
|
+
} from "./core.js";
|
|
126
|
+
import {
|
|
127
|
+
PreviewController,
|
|
128
|
+
DiagnosticsJournal,
|
|
129
|
+
MlbSimulatorClient,
|
|
130
|
+
createBuddyPreviewUrl,
|
|
131
|
+
connectPreviewBridge
|
|
132
|
+
} from "./preview.js";
|
|
133
|
+
var PREVIEW_COMMAND_HELP = `\u7528\u6CD5:
|
|
134
|
+
${CLI_COMMAND_NAME} preview [--directory <\u9879\u76EE\u76EE\u5F55>] [--buddy-id <\u642D\u5B50 ID>] [--developer-web <\u540E\u53F0 URL>] [--app-server <App Server URL>] [--no-open]
|
|
135
|
+
|
|
136
|
+
\u8BF4\u660E:
|
|
137
|
+
\u9ED8\u8BA4\u6253\u5F00\u5F53\u524D\u642D\u5B50\u7684\u521B\u9020\u8005\u540E\u53F0\u300C\u5F00\u53D1\u8C03\u8BD5\u300D\uFF0C\u8FDE\u63A5\u672C\u5730\u5DE5\u7A0B\uFF1B\u5728\u540E\u53F0\u542F\u52A8/\u505C\u6B62 DEV\u3001\u8BD5\u804A\u3001\u67E5\u770B Widget\u3001\u65F6\u95F4\u7EBF\u4E0E\u534F\u8BAE\u65E5\u5FD7\u3001\u771F\u673A\u9884\u89C8\u3002
|
|
138
|
+
\u771F\u673A\u9884\u89C8\u7A7A\u95F2\u65F6\u4E5F\u4F1A\u540C\u6B65\u624B\u673A\u53D1\u6765\u7684\u6D88\u606F\uFF0C\u6062\u590D\u8FDE\u63A5\u540E\u4F1A\u8865\u8BFB\u804A\u5929\u8BB0\u5F55\u3002
|
|
139
|
+
\u624B\u673A\u6216\u7F51\u9875\u5220\u9664\u804A\u5929\u540E\uFF0C\u6A21\u62DF\u5668\u663E\u793A\u300C\u6B64\u5BF9\u8BDD\u5DF2\u5220\u9664\u300D\u3002\u53EF\u5728\u7F51\u9875\u70B9\u51FB\u300C\u65B0\u5EFA\u5BF9\u8BDD\u300D\uFF0C\u6216\u5728\u624B\u673A\u5F00\u804A\u540E\u7EE7\u7EED\u540C\u6B65\u3002
|
|
140
|
+
--buddy-id \u6821\u9A8C\u5F53\u524D\u5DE5\u7A0B\u8EAB\u4EFD\uFF1B\u540E\u53F0\u300C\u83B7\u53D6\u8FDE\u63A5\u6307\u4EE4\u300D\u63D0\u4F9B\u642D\u5B50\u548C\u73AF\u5883\u5B8C\u6574\u53C2\u6570\u3002
|
|
141
|
+
\u540E\u53F0\u590D\u5236\u7684\u547D\u4EE4\u5E26 --no-open\uFF0C\u53EA\u8FDE\u63A5\u5DE5\u7A0B\uFF0C\u539F\u8C03\u8BD5\u9875\u81EA\u52A8\u63A5\u5165\uFF0C\u4E0D\u91CD\u590D\u6253\u5F00\u7F51\u9875\uFF1B\u9875\u9762\u5173\u95ED\u540E\u53EF\u6253\u5F00\u7EC8\u7AEF\u4E2D\u7684\u5730\u5740\u3002
|
|
142
|
+
\u91CD\u65B0\u6267\u884C preview \u4F1A\u5148\u65AD\u5F00\u5F53\u524D\u8D26\u53F7\u4E0B\u8FD9\u4E2A\u642D\u5B50\u7684\u65E7\u9884\u89C8\uFF0C\u518D\u8FDE\u63A5\u5F53\u524D\u5DE5\u7A0B\u3002\u4FDD\u6301\u5F53\u524D\u7EC8\u7AEF\u6253\u5F00\uFF0C\u5728\u7F51\u9875\u70B9\u51FB\u300C\u5F00\u59CB\u8C03\u8BD5\u300D\u3002
|
|
143
|
+
\u8FDE\u63A5\u540E\u5373\u53EF\u67E5\u770B\u5DE5\u7A0B\u6A21\u578B\u548C\u5DE5\u5177\u5217\u8868\uFF0C\u65E0\u9700\u53D1\u9001\u6D88\u606F\uFF1BCLI \u53EA\u8BFB\u73B0\u6709\u6E90\u4EE3\u7801\uFF0C\u52A8\u6001\u914D\u7F6E\u6807\u6CE8\u5F85\u786E\u8BA4\uFF0C\u4FDD\u5B58\u540E\u81EA\u52A8\u5237\u65B0\u3002
|
|
144
|
+
\u4E0D\u6267\u884C\u4E1A\u52A1\u5DE5\u5382\u6765\u63A2\u6D4B\u914D\u7F6E\uFF0C\u4E0D\u65B0\u589E\u5DE5\u7A0B\u914D\u7F6E\u6587\u4EF6\uFF0C\u4E5F\u4E0D\u8981\u6C42\u4E3A\u6B64\u5347\u7EA7 Runtime\u3002\u6BCF\u6B21\u8C03\u7528\u7684\u5B9E\u9645\u6A21\u578B\u4E0E\u5DE5\u5177\u4EE5\u6A21\u578B\u8C03\u7528\u65E5\u5FD7\u4E3A\u51C6\u3002
|
|
145
|
+
\u8C03\u8BD5\u9875\u9762\u7531\u521B\u9020\u8005\u540E\u53F0\u63D0\u4F9B\uFF1BCLI \u53EA\u8FDE\u63A5\u548C\u8FD0\u884C\u672C\u5730\u5DE5\u7A0B\uFF0C\u4E0D\u63D0\u4F9B\u72EC\u7ACB\u672C\u5730\u7F51\u9875\u3002
|
|
146
|
+
\u4FDD\u6301\u7EC8\u7AEF\u8FD0\u884C\uFF1BCtrl+C \u6216\u5173\u95ED\u7EC8\u7AEF\u4F1A\u505C\u6B62 DEV \u5E76\u65AD\u5F00\u8FDE\u63A5\uFF0C\u5237\u65B0\u540E\u53F0\u4E0D\u4F1A\u81EA\u52A8\u542F\u52A8 DEV\u3002
|
|
147
|
+
\u8FDE\u63A5\u6301\u7EED\u4E2D\u65AD\u4F1A\u4FDD\u62A4\u6027\u505C\u6B62 DEV\uFF1B\u505C\u6B62\u5E76\u6062\u590D\u8FDE\u63A5\u540E\u8BF7\u624B\u52A8\u542F\u52A8\uFF0C\u8FDE\u63A5\u5931\u6548\u4E0D\u4F1A\u81EA\u52A8\u63A5\u56DE\u3002
|
|
148
|
+
\u65B0\u7248\u540E\u53F0\u5C06\u5FC3\u8DF3\u4E0E\u8C03\u8BD5\u7ED3\u679C\u5206\u5F00\u4F20\u8F93\uFF0C\u65E5\u5FD7\u52A0\u8F7D\u5931\u8D25\u4E0D\u4F1A\u5360\u7528\u5FC3\u8DF3\u3002\u65E5\u5FD7\u6309\u9700\u5206\u9875\uFF0C\u91CD\u8FDE\u4E0D\u4F1A\u5168\u91CF\u4E0A\u4F20\u672C\u5730\u5386\u53F2\u3002
|
|
149
|
+
\u8FD0\u884C\u6982\u51B5\u9ED8\u8BA4\u663E\u793A\u4ECA\u5929\u5728\u7F51\u9875\u548C\u771F\u673A\u9884\u89C8\u7684\u79C1\u804A\u8F6E\u6B21\u3002\u91CD\u65B0\u8FDE\u63A5\u540C\u4E00\u5DE5\u7A0B\u540E\uFF0C\u53EF\u6309\u65E5\u671F\u67E5\u770B\u672C\u673A\u6700\u8FD1 72 \u5C0F\u65F6\u5185\u4FDD\u7559\u7684\u79C1\u804A\u8F6E\u6B21\u4E0E\u5173\u952E\u4E8B\u4EF6\u3002\u8F6E\u6B21\u6309\u5F00\u59CB\u65E5\u671F\u7F16\u53F7\u3002\u53EF\u67E5\u770B\u5E73\u53F0\u8BB0\u5F55\u7684\u771F\u673A\u56DE\u590D\u548C CLI \u89C2\u5BDF\u5230\u7684\u8017\u65F6\u3002
|
|
150
|
+
\u53EF\u9760\u5F52\u5C5E\u7684\u8C03\u8BD5\u65E5\u5FD7\u5B58\u4E8E ~/.buddy-cli/diagnostics\uFF0C\u6700\u591A\u53EF\u8BFB\u53D6 72 \u5C0F\u65F6\uFF1B\u4E0B\u6B21\u542F\u52A8\u540E\u53F0\u6E05\u7406\u8FC7\u671F\u6587\u4EF6\uFF0C\u5199\u5165\u65F6\u6309\u5DE5\u7A0B 100 MiB\u3001\u5168\u5C40 500 MiB \u6EDA\u52A8\u3002
|
|
151
|
+
\u786E\u8BA4\u804A\u5929\u5220\u9664\u540E\u6E05\u7406\u8BE5\u804A\u5929\u65E5\u5FD7\u5E76\u62D2\u7EDD\u8FDF\u5230\u8F93\u51FA\uFF1B\u672A\u5F52\u5C5E console \u53EA\u5728\u672C\u6B21\u8FDB\u7A0B\u4E2D\u67E5\u770B\uFF0C\u4E0D\u4F5C\u4E3A\u4F1A\u8BDD\u5386\u53F2\u6301\u4E45\u5316\u3002
|
|
152
|
+
\u7F51\u9875\u9884\u89C8\u652F\u6301\u7981\u6B62\u76D1\u542C\u672C\u673A\u7AEF\u53E3\u7684\u73AF\u5883\uFF1B\u8BF7\u786E\u4FDD\u5DE5\u7A0B\u548C\u5F53\u524D\u7528\u6237\u7684\u8FD0\u884C\u76EE\u5F55\u53EF\u5199\u3002
|
|
153
|
+
\u6587\u4EF6\u76D1\u542C\u4E0D\u53EF\u7528\u65F6\uFF0C\u7EC8\u7AEF\u548C\u540E\u53F0\u300C\u8FD0\u884C\u65E5\u5FD7\u300D\u4F1A\u63D0\u793A\u624B\u52A8\u91CD\u542F\u3002\u4FEE\u6539\u6587\u4EF6\u540E\u8BF7\u505C\u6B62\u5E76\u91CD\u65B0\u5F00\u59CB\u8C03\u8BD5\u3002
|
|
154
|
+
DEV \u5931\u8D25\u5148\u67E5\u770B\u5177\u4F53\u9519\u8BEF\u548C\u8FD0\u884C\u65E5\u5FD7\uFF1B\u5347\u7EA7 CLI \u540E\u9000\u51FA\u65E7 preview \u8FDB\u7A0B\u5E76\u91CD\u65B0\u8FDE\u63A5\uFF0C\u518D\u542F\u52A8 DEV\u3002
|
|
155
|
+
\u540E\u53F0\u53EF\u901A\u8FC7\u300C\u65AD\u5F00\u9879\u76EE\u8FDE\u63A5\u300D\u64A4\u9500\u8FDE\u63A5\uFF1B\u672C\u673A\u505C\u6B62\u672A\u786E\u8BA4\u65F6\uFF0C\u5728\u539F\u5DE5\u7A0B\u76EE\u5F55\u6267\u884C ${CLI_COMMAND_NAME} dev stop\u3002\u8BE5\u547D\u4EE4\u4E0D\u91CD\u8FDE\u3001\u4E0D\u91CD\u542F\u3002
|
|
156
|
+
\u672A\u914D\u7F6E\u5730\u5740\u65F6\u8FDE\u63A5 MLB \u6D4B\u8BD5\u73AF\u5883 ${DEFAULT_MLB_TEST_URL}\uFF08HTTPS\uFF09\u3002
|
|
157
|
+
SIT \u5305\u56FA\u5B9A\u8FDE\u63A5 SIT\uFF1B\u5730\u5740\u53C2\u6570\u53EA\u6821\u9A8C\u56FA\u5B9A\u76EE\u6807\uFF0C\u4E0D\u80FD\u5207\u6362\u5E73\u53F0\u3002Runtime \u7F51\u5173\u7531 CLI \u6CE8\u5165\u3002
|
|
158
|
+
CLI \u7EDF\u4E00\u542F\u52A8\u5E76\u7BA1\u7406\u5DE5\u7A0B\u4E2D\u7684\u5B98\u65B9 Runtime\uFF1B\u6BCF\u6B21\u542F\u52A8\u6216\u91CD\u8F7D\u68C0\u67E5\u5DE5\u7A0B Runtime \u7684\u51C6\u786E\u7248\u672C\u3001\u5B89\u88C5\u548C\u9501\u6587\u4EF6\u4E0E ${RUNTIME_SOURCE_LABEL} \u6700\u65B0\u7248\u672C\u4E00\u81F4\u3002
|
|
159
|
+
\u8EAB\u4EFD\u8BFB\u53D6 package.json.buddyId\uFF1B.env \u4FDD\u5B58 Token\uFF0C\u542F\u52A8\u524D\u5411 Server \u6821\u9A8C\u6240\u5C5E\u642D\u5B50\u3002
|
|
160
|
+
\u8FDE\u63A5\u524D\u81EA\u68C0 .env \u7F51\u5173\uFF1B\u53D1\u73B0\u5176\u4ED6\u73AF\u5883\u5730\u5740\u65F6\u505C\u6B62\uFF1B\u8BF7\u4F7F\u7528\u5BF9\u5E94 CLI\uFF0C\u8FC1\u79FB\u65F6\u65B0\u5EFA\u8EAB\u4EFD\u4E14\u4E0D\u590D\u5236\u51ED\u636E\u3002
|
|
161
|
+
--refresh-token \u91CD\u65B0\u9886\u53D6\u5DF2\u6709\u5F00\u53D1 Token\uFF0C\u66F4\u65B0\u540C\u4E00\u73AF\u5883\u7684\u5DE5\u7A0B .env\uFF1B\u4E0D\u80FD\u5207\u6362\u5E73\u53F0\uFF0C\u4E0D\u4F1A\u751F\u6210\u65B0\u5BC6\u94A5\u3002
|
|
162
|
+
Widget \u6D88\u606F\u5361\u7247\u4FDD\u7559\u6307\u5B9A\u8BB0\u5F55\u7684\u6253\u5F00\u76EE\u6807\uFF0C\u5C0F\u6302\u4EF6\u5217\u8868\u6253\u5F00\u9ED8\u8BA4\u89C6\u56FE\u3002
|
|
163
|
+
Widget \u9875\u9762\u5199\u64CD\u4F5C\u987B\u7531 operations.userUI \u663E\u5F0F\u6388\u6743\uFF0C\u7F3A\u7701\u53EA\u8BFB\uFF1B\u540E\u53F0\u7F16\u8F91\u8FD8\u9700\u914D\u5957 Server\u3001Web \u548C window.dadaWidget \u6865\u63A5\u3002
|
|
164
|
+
409 \u51B2\u7A81\u9700\u91CD\u8BFB\u6838\u5BF9\uFF0C\u4E0D\u81EA\u52A8\u8986\u76D6\uFF1B\u771F\u673A\u7F16\u8F91\u4F9D\u8D56\u76EE\u6807 App \u6865\u63A5\u5E76\u5355\u72EC\u9A8C\u6536\uFF0C\u540E\u53F0\u901A\u8FC7\u4E0D\u4EE3\u8868\u624B\u673A\u7AEF\u652F\u6301\u3002
|
|
165
|
+
Creator \u53EF\u6309\u9700\u6C42\u6F14\u793A\u5C55\u793A\u6216\u7F16\u8F91\u4EA4\u4E92\uFF0C\u793A\u4F8B\u64CD\u4F5C\u4E0D\u4EE3\u8868\u771F\u5B9E\u6570\u636E\u63A5\u5165\u5B8C\u6210\uFF1B\u8BB0\u5F55\u7F16\u8F91\u4E0D\u7B49\u4E8E\u591A\u4EBA\u5B9E\u65F6\u540C\u6B65\u3001\u73A9\u5BB6\u8BA4\u8BC1\u6216\u73A9\u5BB6\u79C1\u6709\u6570\u636E\u9694\u79BB\u3002
|
|
166
|
+
\u6A21\u62DF\u5668\u4F7F\u7528\u5F53\u524D\u5F00\u53D1\u8005\u8D26\u53F7\u8BBF\u95EE <buddyId>-dev \u8C03\u8BD5\u5206\u8EAB\u3002`;
|
|
167
|
+
function valueAfter(args, index, flag) {
|
|
168
|
+
const value = args[index + 1];
|
|
169
|
+
if (value === void 0 || !value.trim()) throw new Error(`${flag} \u7F3A\u5C11\u503C`);
|
|
170
|
+
return value;
|
|
171
|
+
}
|
|
172
|
+
function setOnce(current, value, flag) {
|
|
173
|
+
if (current !== void 0) throw new Error(`${flag} \u4E0D\u80FD\u91CD\u590D`);
|
|
174
|
+
return value;
|
|
175
|
+
}
|
|
176
|
+
function parsePreviewArguments(args) {
|
|
177
|
+
let directory = ".";
|
|
178
|
+
let directorySet = false;
|
|
179
|
+
let appServer;
|
|
180
|
+
let help = false;
|
|
181
|
+
let noOpen = false;
|
|
182
|
+
let refreshToken = false;
|
|
183
|
+
let buddyId;
|
|
184
|
+
let developerWeb;
|
|
185
|
+
for (let index = 0; index < args.length; index += 1) {
|
|
186
|
+
const flag = args[index];
|
|
187
|
+
if (flag === "--refresh-token") {
|
|
188
|
+
if (refreshToken) throw new Error("--refresh-token \u4E0D\u80FD\u91CD\u590D");
|
|
189
|
+
refreshToken = true;
|
|
190
|
+
continue;
|
|
191
|
+
}
|
|
192
|
+
if (flag === "--help" || flag === "-h") {
|
|
193
|
+
if (args.length !== 1) throw new Error("--help \u4E0D\u80FD\u548C\u5176\u4ED6 preview \u53C2\u6570\u4E00\u8D77\u4F7F\u7528");
|
|
194
|
+
help = true;
|
|
195
|
+
continue;
|
|
196
|
+
}
|
|
197
|
+
if (flag === "--local" || flag === "--port") throw new Error(`${flag} \u5DF2\u505C\u7528\uFF1B\u8BF7\u8FD0\u884C ${CLI_COMMAND_NAME} preview\uFF0C\u5728\u521B\u9020\u8005\u540E\u53F0\u5F00\u53D1\u8C03\u8BD5\u3002`);
|
|
198
|
+
if (flag === "--no-open") {
|
|
199
|
+
if (noOpen) throw new Error("--no-open \u4E0D\u80FD\u91CD\u590D");
|
|
200
|
+
noOpen = true;
|
|
201
|
+
continue;
|
|
202
|
+
}
|
|
203
|
+
const value = valueAfter(args, index, flag ?? "\u53C2\u6570");
|
|
204
|
+
index += 1;
|
|
205
|
+
switch (flag) {
|
|
206
|
+
case "--buddy-id":
|
|
207
|
+
buddyId = setOnce(buddyId, value, flag);
|
|
208
|
+
if (!/^[A-Za-z0-9_-]{1,128}$/u.test(buddyId)) throw new Error("--buddy-id \u65E0\u6548");
|
|
209
|
+
break;
|
|
210
|
+
case "--developer-web":
|
|
211
|
+
developerWeb = setOnce(developerWeb, value, flag);
|
|
212
|
+
break;
|
|
213
|
+
case "--directory":
|
|
214
|
+
if (directorySet) throw new Error("--directory \u4E0D\u80FD\u91CD\u590D");
|
|
215
|
+
directory = value;
|
|
216
|
+
directorySet = true;
|
|
217
|
+
break;
|
|
218
|
+
case "--app-server":
|
|
219
|
+
appServer = setOnce(appServer, value, flag);
|
|
220
|
+
break;
|
|
221
|
+
default:
|
|
222
|
+
throw new Error(`\u672A\u77E5 preview \u53C2\u6570 ${flag ?? ""}`);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
return Object.freeze({ directory, appServer, help, buddyId, developerWeb, ...refreshToken ? { refreshToken: true } : {}, ...noOpen ? { noOpen: true } : {} });
|
|
226
|
+
}
|
|
227
|
+
function previewHandle(handle) {
|
|
228
|
+
return Object.freeze({
|
|
229
|
+
closed: handle.completion.then((completion) => {
|
|
230
|
+
if (completion.state === "failed") throw completion.error ?? new Error("DEV \u4F1A\u8BDD\u5F02\u5E38\u7ED3\u675F");
|
|
231
|
+
}),
|
|
232
|
+
close: () => handle.stop()
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
var BuddyPlatformHost = class {
|
|
236
|
+
#runtimeUpdate;
|
|
237
|
+
#env;
|
|
238
|
+
#signal;
|
|
239
|
+
#openUrl;
|
|
240
|
+
#sessions = /* @__PURE__ */ new Map();
|
|
241
|
+
#credentialCommandRunner;
|
|
242
|
+
#mockClient = new MockDeveloperPlatformClient();
|
|
243
|
+
constructor(options = {}) {
|
|
244
|
+
this.#runtimeUpdate = options.runtimeUpdate;
|
|
245
|
+
this.#env = options.env ?? process.env;
|
|
246
|
+
this.#signal = options.signal;
|
|
247
|
+
this.#openUrl = options.openUrl ?? ((url) => openExternalTarget(url, { env: this.#env }));
|
|
248
|
+
this.#credentialCommandRunner = options.credentialCommandRunner;
|
|
249
|
+
}
|
|
250
|
+
clinicOptions() {
|
|
251
|
+
const baseUrl = this.#configuredServer();
|
|
252
|
+
return {
|
|
253
|
+
platformUrl: baseUrl,
|
|
254
|
+
session: this.#session(baseUrl),
|
|
255
|
+
signal: this.#signal,
|
|
256
|
+
createClient: (token, signal) => new HttpClinicClient({ baseUrl, token, signal })
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
cloudOptions() {
|
|
260
|
+
const preparePush = async (projectRoot, _config, expectedRuntimeVersion) => {
|
|
261
|
+
const plan = await createPushPreflight({ projectRoot, expectedRuntimeVersion });
|
|
262
|
+
return createPushSourceBundle(plan);
|
|
263
|
+
};
|
|
264
|
+
if (this.#env.BUDDY_CLI_MOCK_CLOUD === "1") {
|
|
265
|
+
const mockToken = {
|
|
266
|
+
accessToken: "local-mock-access-token",
|
|
267
|
+
subject: "account_local_mock",
|
|
268
|
+
expiresAt: Date.now() + 60 * 6e4
|
|
269
|
+
};
|
|
270
|
+
return {
|
|
271
|
+
mode: "local-mock",
|
|
272
|
+
signal: this.#signal,
|
|
273
|
+
session: {
|
|
274
|
+
async token() {
|
|
275
|
+
return mockToken;
|
|
276
|
+
},
|
|
277
|
+
async currentToken() {
|
|
278
|
+
return mockToken;
|
|
279
|
+
},
|
|
280
|
+
async clear() {
|
|
281
|
+
}
|
|
282
|
+
},
|
|
283
|
+
client: this.#mockClient,
|
|
284
|
+
preparePush
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
const baseUrl = this.#configuredServer();
|
|
288
|
+
const session = this.#session(baseUrl);
|
|
289
|
+
return {
|
|
290
|
+
mode: "cloud",
|
|
291
|
+
session,
|
|
292
|
+
signal: this.#signal,
|
|
293
|
+
client: new HttpDeveloperPlatformClient({
|
|
294
|
+
baseUrl,
|
|
295
|
+
token: async () => (await session.token({ signal: this.#signal })).accessToken
|
|
296
|
+
}),
|
|
297
|
+
runtimeUpdate: { ...this.#runtimeUpdate, env: this.#env },
|
|
298
|
+
preparePush
|
|
299
|
+
};
|
|
300
|
+
}
|
|
301
|
+
devOptions() {
|
|
302
|
+
return {
|
|
303
|
+
signal: this.#signal,
|
|
304
|
+
env: this.#env,
|
|
305
|
+
authorize: async ({ appServerUrl: baseUrl }) => {
|
|
306
|
+
await this.#session(baseUrl).token({ signal: this.#signal });
|
|
307
|
+
},
|
|
308
|
+
createRegistrationClient: async ({ appServerUrl: baseUrl, refreshToken }) => {
|
|
309
|
+
const token = await this.#session(baseUrl).token({ signal: this.#signal });
|
|
310
|
+
return new MlbDevRegistrationClient({
|
|
311
|
+
baseUrl,
|
|
312
|
+
developerToken: token.accessToken,
|
|
313
|
+
refreshToken,
|
|
314
|
+
tokenStoreFor: (id) => this.#buddyTokenStore(baseUrl, token.subject, id)
|
|
315
|
+
});
|
|
316
|
+
}
|
|
317
|
+
};
|
|
318
|
+
}
|
|
319
|
+
async runPreview(args, io) {
|
|
320
|
+
const parsed = parsePreviewArguments(args);
|
|
321
|
+
if (parsed.help) {
|
|
322
|
+
io.write(PREVIEW_COMMAND_HELP);
|
|
323
|
+
return { exitCode: 0, route: "preview" };
|
|
324
|
+
}
|
|
325
|
+
const projectRoot = await requireBuddyAgentProjectRoot(resolve(process.cwd(), parsed.directory)).catch((cause) => {
|
|
326
|
+
if (cause?.code === "PROJECT_DIRECTORY_NOT_FOUND" || cause?.code === "PROJECT_DIRECTORY_INVALID" || cause?.code === "PROJECT_NOT_FOUND" && !cause.cause) {
|
|
327
|
+
throw new Error(`\u5F53\u524D\u76EE\u5F55\u4E0E\u8981\u8C03\u8BD5\u7684\u642D\u5B50\u4E0D\u5339\u914D\u3002\u8BF7\u5207\u6362\u5230\u8FD9\u4E2A\u642D\u5B50\u7684\u9879\u76EE\u76EE\u5F55\uFF0C\u518D\u8FD0\u884C\u8FDE\u63A5\u547D\u4EE4\u3002
|
|
328
|
+
${cause.message}`, { cause });
|
|
329
|
+
}
|
|
330
|
+
throw cause;
|
|
331
|
+
});
|
|
332
|
+
let baseUrl, webUrl;
|
|
333
|
+
try {
|
|
334
|
+
baseUrl = resolvePlatformUrl({ env: this.#env, override: parsed.appServer });
|
|
335
|
+
webUrl = resolveDeveloperWebUrl(baseUrl, parsed.developerWeb ?? this.#env.BUDDY_DEVELOPER_WEB_URL);
|
|
336
|
+
} catch (cause) {
|
|
337
|
+
throw new Error(`\u8FDE\u63A5\u547D\u4EE4\u4E0E\u5F53\u524D\u5E73\u53F0\u4E0D\u5339\u914D\u3002\u8BF7\u4ECE\u5F53\u524D\u540E\u53F0\u7684\u300C\u8FDE\u63A5\u8BF4\u660E\u300D\u91CD\u65B0\u590D\u5236\u547D\u4EE4\u3002
|
|
338
|
+
${cause instanceof Error ? cause.message : ""}`, { cause });
|
|
339
|
+
}
|
|
340
|
+
const manifest = await readBuddyProjectManifest(projectRoot);
|
|
341
|
+
if (parsed.buddyId && parsed.buddyId !== manifest.buddyId) throw new Error(`\u5F53\u524D\u76EE\u5F55\u4E0E\u8981\u8C03\u8BD5\u7684\u642D\u5B50\u4E0D\u5339\u914D\u3002\u8BF7\u5207\u6362\u5230\u8FD9\u4E2A\u642D\u5B50\u7684\u9879\u76EE\u76EE\u5F55\uFF0C\u518D\u8FD0\u884C\u8FDE\u63A5\u547D\u4EE4\u3002
|
|
342
|
+
\u5F53\u524D\u5DE5\u7A0B\u5C5E\u4E8E ${manifest.buddyId}\uFF0C\u8FDE\u63A5\u6307\u4EE4\u8981\u6C42 ${parsed.buddyId}\u3002`);
|
|
343
|
+
const signal = this.#signal ?? new AbortController().signal;
|
|
344
|
+
await checkProjectGateway(projectRoot, baseUrl, { report: (message) => io.write(message) });
|
|
345
|
+
await checkRuntimeUpdate(projectRoot, (message) => io.writeError(message), { ...this.#runtimeUpdate, signal, env: this.#env });
|
|
346
|
+
const session = this.#session(baseUrl, webUrl);
|
|
347
|
+
const developer = await session.token({ signal });
|
|
348
|
+
const scope = createHash("sha256").update(JSON.stringify([baseUrl.origin, developer.subject, manifest.buddyId])).digest("hex");
|
|
349
|
+
const location = { gatewayUrl: baseUrl, devAgentId: manifest.buddyId, projectRoot };
|
|
350
|
+
const observedInstance = await findLocalPreviewInstance(location, scope);
|
|
351
|
+
let previewOwner;
|
|
352
|
+
const diagnosticsJournal = new DiagnosticsJournal({ identity: JSON.stringify([baseUrl.origin, developer.subject, manifest.buddyId, projectRoot]) });
|
|
353
|
+
await diagnosticsJournal.initialize();
|
|
354
|
+
const starter = this.#previewStarter(baseUrl, manifest.buddyId, session, parsed.refreshToken ?? false, (message) => io.writeError(message), () => previewOwner);
|
|
355
|
+
const controller = new PreviewController({
|
|
356
|
+
projectRoot,
|
|
357
|
+
diagnosticsJournal,
|
|
358
|
+
devStarter: starter,
|
|
359
|
+
readBuddyDetails: async (buddyId) => {
|
|
360
|
+
const token = await this.#session(baseUrl).token({ signal });
|
|
361
|
+
return new MlbSimulatorClient({
|
|
362
|
+
baseUrl,
|
|
363
|
+
buddyId: `${buddyId}-dev`,
|
|
364
|
+
auth: { developerAccessToken: token.accessToken }
|
|
365
|
+
}).details({ signal });
|
|
366
|
+
}
|
|
367
|
+
});
|
|
368
|
+
await controller.refreshInspection();
|
|
369
|
+
let bridge;
|
|
370
|
+
try {
|
|
371
|
+
const pageUrl = new URL(webUrl);
|
|
372
|
+
pageUrl.hash = `/buddy/${encodeURIComponent(manifest.buddyId)}/debug`;
|
|
373
|
+
bridge = await connectPreviewBridge({
|
|
374
|
+
webUrl,
|
|
375
|
+
platformOrigin: baseUrl.origin,
|
|
376
|
+
buddyId: manifest.buddyId,
|
|
377
|
+
async prepareInstance(instanceId, previousInstanceId) {
|
|
378
|
+
previewOwner = { scope, instanceId };
|
|
379
|
+
if (previousInstanceId && previousInstanceId !== instanceId) {
|
|
380
|
+
await stopLocalDev({ ...location, confirmedPreviewInstance: previousInstanceId });
|
|
381
|
+
}
|
|
382
|
+
if (observedInstance && observedInstance !== instanceId && observedInstance !== previousInstanceId) {
|
|
383
|
+
await stopLocalDev({ ...location, previewOwner: { scope, instanceIds: [observedInstance] } });
|
|
384
|
+
}
|
|
385
|
+
},
|
|
386
|
+
controller,
|
|
387
|
+
token: async () => (await session.token({ signal })).accessToken,
|
|
388
|
+
signal,
|
|
389
|
+
onStatus: (message) => io.write(message),
|
|
390
|
+
stopLocalDev: () => stopLocalDev({
|
|
391
|
+
...location,
|
|
392
|
+
...previewOwner && { previewOwner: { scope, instanceIds: [previewOwner.instanceId], includeUnscoped: true } }
|
|
393
|
+
})
|
|
394
|
+
});
|
|
395
|
+
if (parsed.noOpen) io.write(`\u8BF7\u8FD4\u56DE\u539F\u540E\u53F0\u8C03\u8BD5\u9875\uFF0C\u9875\u9762\u4F1A\u81EA\u52A8\u63A5\u5165\u672C\u5730\u5DE5\u7A0B\u3002\u9875\u9762\u5730\u5740\uFF1A${pageUrl.href}`);
|
|
396
|
+
else {
|
|
397
|
+
try {
|
|
398
|
+
await this.#openUrl(pageUrl);
|
|
399
|
+
io.write(`\u642D\u642D\u540E\u53F0\u5F00\u53D1\u8C03\u8BD5\u9875\u9762\u5DF2\u6253\u5F00\uFF1A${pageUrl.href}`);
|
|
400
|
+
} catch {
|
|
401
|
+
io.write(`\u65E0\u6CD5\u81EA\u52A8\u6253\u5F00\u6D4F\u89C8\u5668\uFF0C\u8BF7\u624B\u52A8\u6253\u5F00\u540E\u53F0\u8C03\u8BD5\u9875\u9762\uFF1A${pageUrl.href}`);
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
io.write(`\u5DF2\u8FDE\u63A5\u672C\u5730\u5DE5\u7A0B\uFF1A${projectRoot}\uFF08${manifest.buddyId}\uFF09\u3002`);
|
|
405
|
+
io.write(bridge.disconnectedPrevious ? "\u65E7\u9884\u89C8\u5DF2\u65AD\u5F00\uFF0C\u8BF7\u5728\u7F51\u9875\u70B9\u51FB\u300C\u5F00\u59CB\u8C03\u8BD5\u300D\u3002" : "\u8BF7\u5728\u7F51\u9875\u70B9\u51FB\u300C\u5F00\u59CB\u8C03\u8BD5\u300D\u3002");
|
|
406
|
+
io.write("\u4FDD\u6301\u7EC8\u7AEF\u8FD0\u884C\uFF1BCtrl+C \u505C\u6B62 DEV \u5E76\u65AD\u5F00\u8FDE\u63A5\u3002");
|
|
407
|
+
if (signal.aborted) return { exitCode: 130, route: "preview" };
|
|
408
|
+
await bridge.completion;
|
|
409
|
+
return { exitCode: 130, route: "preview" };
|
|
410
|
+
} finally {
|
|
411
|
+
await bridge?.close().catch(() => void 0);
|
|
412
|
+
await controller.close();
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
#previewStarter(baseUrl, buddyId, session, refreshToken, warn, getPreviewOwner) {
|
|
416
|
+
const starter = createBuddyDevStarter();
|
|
417
|
+
return Object.freeze({
|
|
418
|
+
start: async ({ projectRoot, signal, onLog, onLifecycle, onWatchUnavailable }) => {
|
|
419
|
+
const manifest = await readBuddyProjectManifest(projectRoot).catch((cause) => {
|
|
420
|
+
if (cause?.code === "ENOENT") throw new BuddyDevError({
|
|
421
|
+
code: "DEV_CONFIG_INVALID",
|
|
422
|
+
phase: "config",
|
|
423
|
+
message: "\u5DE5\u7A0B\u7F3A\u5C11\u6587\u4EF6 package.json\u3002",
|
|
424
|
+
publicMessage: "\u5DE5\u7A0B\u7F3A\u5C11\u6587\u4EF6 package.json\u3002",
|
|
425
|
+
cause
|
|
426
|
+
});
|
|
427
|
+
throw cause;
|
|
428
|
+
});
|
|
429
|
+
if (manifest.buddyId !== buddyId) {
|
|
430
|
+
const message = "\u5DE5\u7A0B buddyId \u5DF2\u6539\u53D8\uFF0C\u8BF7\u9000\u51FA CLI \u540E\u5728\u6B63\u786E\u642D\u5B50\u7684\u5DE5\u7A0B\u91CD\u65B0\u8FDE\u63A5\u3002";
|
|
431
|
+
throw new BuddyDevError({ code: "DEV_AGENT_ID_INVALID", phase: "config", message, publicMessage: message });
|
|
432
|
+
}
|
|
433
|
+
const token = await session.token({ signal });
|
|
434
|
+
const secrets = /* @__PURE__ */ new Set([token.accessToken]);
|
|
435
|
+
const logs = createRuntimeLogForwarder((event) => onLog?.(event), secrets);
|
|
436
|
+
const registrationClient = new MlbDevRegistrationClient({
|
|
437
|
+
baseUrl,
|
|
438
|
+
developerToken: token.accessToken,
|
|
439
|
+
refreshToken,
|
|
440
|
+
tokenStoreFor: (id) => this.#buddyTokenStore(baseUrl, token.subject, id)
|
|
441
|
+
});
|
|
442
|
+
let reloadError;
|
|
443
|
+
const handle = await starter.start({
|
|
444
|
+
projectRoot,
|
|
445
|
+
signal,
|
|
446
|
+
runtimeUpdate: { ...this.#runtimeUpdate, env: this.#env },
|
|
447
|
+
previewOwner: getPreviewOwner(),
|
|
448
|
+
devDiagnostics: true,
|
|
449
|
+
onWatchUnavailable(message) {
|
|
450
|
+
warn(message);
|
|
451
|
+
onWatchUnavailable?.(message);
|
|
452
|
+
},
|
|
453
|
+
onLogSecrets: (values) => {
|
|
454
|
+
for (const value of values) if (value) secrets.add(value);
|
|
455
|
+
},
|
|
456
|
+
onError(error) {
|
|
457
|
+
logs.flush();
|
|
458
|
+
let message = error.publicMessage ?? error.message;
|
|
459
|
+
for (const secret of secrets) if (secret) message = message.split(secret).join("[REDACTED]");
|
|
460
|
+
reloadError = { code: error.code, message: message.replace(/[\u0000-\u001f\u007f]/gu, " ").slice(0, 512) };
|
|
461
|
+
},
|
|
462
|
+
onStateChange(phase) {
|
|
463
|
+
if (phase === "reloading") reloadError = void 0;
|
|
464
|
+
if (phase === "reloading" || phase === "reload_failed" || phase === "ready") onLifecycle?.({ phase, ...phase === "reload_failed" && reloadError ? { error: reloadError } : {} });
|
|
465
|
+
},
|
|
466
|
+
registrationClient: {
|
|
467
|
+
async register(request, options) {
|
|
468
|
+
const registered = await registrationClient.register(request, options);
|
|
469
|
+
secrets.add(registered.agentToken);
|
|
470
|
+
return registered;
|
|
471
|
+
},
|
|
472
|
+
listOnline: (options) => registrationClient.listOnline(options)
|
|
473
|
+
},
|
|
474
|
+
onLog: logs.write
|
|
475
|
+
}).catch((cause) => {
|
|
476
|
+
logs.flush();
|
|
477
|
+
if (cause instanceof BuddyDevError && cause.code.startsWith("DEV_RUNTIME_")) {
|
|
478
|
+
let message = cause.message;
|
|
479
|
+
for (const secret of secrets) if (secret) message = message.split(secret).join("[REDACTED]");
|
|
480
|
+
Object.assign(cause, { publicMessage: message.replace(/[\u0000-\u001f\u007f]/gu, " ").slice(0, 512) });
|
|
481
|
+
}
|
|
482
|
+
throw cause;
|
|
483
|
+
});
|
|
484
|
+
const preview = previewHandle(handle);
|
|
485
|
+
void preview.closed.then(() => logs.flush(), () => logs.flush());
|
|
486
|
+
const devBuddyId = `${handle.devAgentId}-dev`;
|
|
487
|
+
const simulator = new MlbSimulatorClient({
|
|
488
|
+
baseUrl,
|
|
489
|
+
buddyId: devBuddyId,
|
|
490
|
+
auth: { developerAccessToken: token.accessToken }
|
|
491
|
+
});
|
|
492
|
+
let buddy;
|
|
493
|
+
let previewUrl;
|
|
494
|
+
try {
|
|
495
|
+
buddy = await simulator.details({ signal });
|
|
496
|
+
previewUrl = createBuddyPreviewUrl(devBuddyId);
|
|
497
|
+
signal.throwIfAborted();
|
|
498
|
+
} catch (cause) {
|
|
499
|
+
await handle.stop();
|
|
500
|
+
throw Object.assign(new Error("\u5F00\u53D1\u7248\u642D\u5B50\u8D44\u6599\u52A0\u8F7D\u5931\u8D25\u3002", { cause }), {
|
|
501
|
+
code: "DEV_BUDDY_DETAILS_FAILED",
|
|
502
|
+
phase: "registration",
|
|
503
|
+
publicMessage: "\u5F00\u53D1\u7248\u642D\u5B50\u8D44\u6599\u52A0\u8F7D\u5931\u8D25\uFF0C\u672C\u6B21\u8C03\u8BD5\u5DF2\u505C\u6B62\u3002",
|
|
504
|
+
status: cause?.status
|
|
505
|
+
});
|
|
506
|
+
}
|
|
507
|
+
return Object.freeze({
|
|
508
|
+
handle: preview,
|
|
509
|
+
ready: Object.freeze({
|
|
510
|
+
agentId: devBuddyId,
|
|
511
|
+
buddy,
|
|
512
|
+
devicePairing: Object.freeze({ url: previewUrl }),
|
|
513
|
+
simulatorUrl: baseUrl.href
|
|
514
|
+
}),
|
|
515
|
+
simulator
|
|
516
|
+
});
|
|
517
|
+
}
|
|
518
|
+
});
|
|
519
|
+
}
|
|
520
|
+
#buddyTokenStore(baseUrl, subject, buddyId) {
|
|
521
|
+
return new SystemBuddyTokenStore({ platformUrl: baseUrl, subject, buddyId, commandRunner: this.#credentialCommandRunner });
|
|
522
|
+
}
|
|
523
|
+
#configuredServer() {
|
|
524
|
+
return resolvePlatformUrl({ env: this.#env });
|
|
525
|
+
}
|
|
526
|
+
#session(baseUrl, webUrl) {
|
|
527
|
+
resolvePlatformUrl({ env: this.#env, override: baseUrl.href });
|
|
528
|
+
const developerWebUrl = resolveDeveloperWebUrl(baseUrl, webUrl ?? this.#env.BUDDY_DEVELOPER_WEB_URL);
|
|
529
|
+
const key = baseUrl.origin;
|
|
530
|
+
let session = this.#sessions.get(key);
|
|
531
|
+
if (!session) {
|
|
532
|
+
session = new CloudAuthenticator(
|
|
533
|
+
new LoopbackBrowserLoginAdapter({
|
|
534
|
+
platformUrl: baseUrl,
|
|
535
|
+
developerWebUrl,
|
|
536
|
+
openBrowser: this.#openUrl,
|
|
537
|
+
onLoginUrl: (url) => process.stderr.write(`\u82E5\u6D4F\u89C8\u5668\u672A\u81EA\u52A8\u6253\u5F00\uFF0C\u8BF7\u624B\u52A8\u6253\u5F00\u4EE5\u4E0B\u5730\u5740\u5B8C\u6210\u6388\u6743\uFF1A
|
|
538
|
+
${url.href}
|
|
539
|
+
`)
|
|
540
|
+
}),
|
|
541
|
+
new SystemCloudTokenStore({
|
|
542
|
+
account: `developer-session:${createHash("sha256").update(key).digest("hex")}`,
|
|
543
|
+
commandRunner: this.#credentialCommandRunner
|
|
544
|
+
})
|
|
545
|
+
);
|
|
546
|
+
this.#sessions.set(key, session);
|
|
547
|
+
}
|
|
548
|
+
return session;
|
|
549
|
+
}
|
|
550
|
+
};
|
|
551
|
+
|
|
552
|
+
// apps/cli/src/command-runner.ts
|
|
553
|
+
var TerminalIO = class {
|
|
554
|
+
canPrompt = Boolean(stdin.isTTY && stdout.isTTY);
|
|
555
|
+
readline;
|
|
556
|
+
activeQuestion;
|
|
557
|
+
cancelled = false;
|
|
558
|
+
write(message) {
|
|
559
|
+
stdout.write(`${message}
|
|
560
|
+
`);
|
|
561
|
+
}
|
|
562
|
+
writeError(message) {
|
|
563
|
+
stderr.write(`${message}
|
|
564
|
+
`);
|
|
565
|
+
}
|
|
566
|
+
async select(question, choices, options = {}) {
|
|
567
|
+
while (true) {
|
|
568
|
+
this.write(`
|
|
569
|
+
${question}`);
|
|
570
|
+
choices.forEach((choice2, index) => {
|
|
571
|
+
this.write(` ${index + 1}. ${choice2.label}`);
|
|
572
|
+
if (choice2.description) this.write(` ${choice2.description}`);
|
|
573
|
+
});
|
|
574
|
+
const defaultIndex = options.defaultValue === void 0 ? void 0 : choices.findIndex((choice2) => choice2.value === options.defaultValue);
|
|
575
|
+
const prompt = defaultIndex === void 0 || defaultIndex < 0 ? "\u8BF7\u8F93\u5165\u5E8F\u53F7\uFF1A" : `\u8BF7\u8F93\u5165\u5E8F\u53F7\uFF08\u9ED8\u8BA4\uFF1A${defaultIndex + 1}\uFF09\uFF1A`;
|
|
576
|
+
const answer = (await this.question(prompt)).trim();
|
|
577
|
+
if (!answer && defaultIndex !== void 0 && defaultIndex >= 0) return choices[defaultIndex].value;
|
|
578
|
+
const selected = Number(answer) - 1;
|
|
579
|
+
const choice = choices[selected];
|
|
580
|
+
if (choice) return choice.value;
|
|
581
|
+
this.writeError(`\u8BF7\u8F93\u5165 1 \u5230 ${choices.length} \u4E4B\u95F4\u7684\u5E8F\u53F7\u3002`);
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
async input(question, options = {}) {
|
|
585
|
+
const defaultHint = options.defaultValue === void 0 ? "" : `\uFF08\u9ED8\u8BA4\uFF1A${options.defaultValue}\uFF09`;
|
|
586
|
+
const answer = (await this.question(`${question}${defaultHint}\uFF1A`)).trim();
|
|
587
|
+
return answer || options.defaultValue || "";
|
|
588
|
+
}
|
|
589
|
+
close() {
|
|
590
|
+
this.readline?.close();
|
|
591
|
+
}
|
|
592
|
+
getReadline() {
|
|
593
|
+
if (this.readline) return this.readline;
|
|
594
|
+
this.readline = createInterface({ input: stdin, output: stdout });
|
|
595
|
+
this.readline.on("SIGINT", () => {
|
|
596
|
+
this.cancelled = true;
|
|
597
|
+
this.activeQuestion?.abort();
|
|
598
|
+
});
|
|
599
|
+
return this.readline;
|
|
600
|
+
}
|
|
601
|
+
async question(prompt) {
|
|
602
|
+
const controller = new AbortController();
|
|
603
|
+
this.activeQuestion = controller;
|
|
604
|
+
try {
|
|
605
|
+
return await this.getReadline().question(prompt, { signal: controller.signal });
|
|
606
|
+
} catch (cause) {
|
|
607
|
+
if (this.cancelled) throw new PromptCancelledError();
|
|
608
|
+
throw cause;
|
|
609
|
+
} finally {
|
|
610
|
+
if (this.activeQuestion === controller) this.activeQuestion = void 0;
|
|
611
|
+
}
|
|
612
|
+
}
|
|
613
|
+
};
|
|
614
|
+
async function runCommand(args, signal) {
|
|
615
|
+
const terminal = new TerminalIO();
|
|
616
|
+
try {
|
|
617
|
+
const command = args[0];
|
|
618
|
+
let platformHost;
|
|
619
|
+
const host = () => platformHost ??= new BuddyPlatformHost({ signal });
|
|
620
|
+
const offlineHelp = command && (["help", "--help", "-h"].includes(command) || args.includes("--help") || args.includes("-h"));
|
|
621
|
+
if (!offlineHelp && command !== "preview") resolvePlatformUrl2();
|
|
622
|
+
return await runBuddyCli(args, terminal, {
|
|
623
|
+
runtimeCatalog: { signal },
|
|
624
|
+
...command === "dev" ? { dev: host().devOptions() } : {},
|
|
625
|
+
get cloud() {
|
|
626
|
+
return host().cloudOptions();
|
|
627
|
+
},
|
|
628
|
+
get clinic() {
|
|
629
|
+
return host().clinicOptions();
|
|
630
|
+
},
|
|
631
|
+
preview: (previewArgs, io) => host().runPreview(previewArgs, io)
|
|
632
|
+
});
|
|
633
|
+
} finally {
|
|
634
|
+
terminal.close();
|
|
635
|
+
}
|
|
636
|
+
}
|
|
637
|
+
export {
|
|
638
|
+
runCommand
|
|
639
|
+
};
|
|
640
|
+
//# sourceMappingURL=command-runner.js.map
|