@eworkbase/sdk 0.1.1 → 0.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.
@@ -1,10 +1,21 @@
1
+ @layer base, mantine, components;
2
+ @import "./theme.css";
3
+
4
+ @layer base {
1
5
  :root {
2
6
  --color-foreground: #342f28;
3
7
  --color-muted: #6c675f;
8
+ --color-tertiary: #756f66;
4
9
  --color-border: #e2dfd6;
10
+ --color-border-strong: #c9c4b8;
5
11
  --color-surface: #fff;
6
12
  --color-surface-muted: #f3f2ed;
13
+ --color-surface-raised: #faf9f5;
14
+ --color-table-row: #fcfbf7;
7
15
  --color-brand: #8a5000;
16
+ --color-brand-deep: #502e00;
17
+ --color-brand-gold: #ca8818;
18
+ --color-brand-weak: #fffee5;
8
19
  --color-primary: #ffde39;
9
20
  --color-primary-hover: #ffca00;
10
21
  --color-primary-foreground: #322d16;
@@ -29,20 +40,6 @@ body {
29
40
  background: transparent;
30
41
  }
31
42
 
32
- button,
33
- input,
34
- select {
35
- font: inherit;
36
- }
37
-
38
- button:focus-visible,
39
- input:focus-visible,
40
- select:focus-visible,
41
- a:focus-visible {
42
- outline: 2px solid color-mix(in srgb, var(--color-accent) 25%, transparent);
43
- outline-offset: 2px;
44
- }
45
-
46
43
  h1,
47
44
  h2,
48
45
  p {
@@ -146,36 +143,6 @@ h2 {
146
143
  gap: 8px;
147
144
  }
148
145
 
149
- .button {
150
- min-height: 34px;
151
- padding: 7px 12px;
152
- border: 1px solid transparent;
153
- border-radius: 7px;
154
- cursor: pointer;
155
- font-size: 13px;
156
- font-weight: 700;
157
- }
158
-
159
- .button:disabled {
160
- cursor: not-allowed;
161
- opacity: 0.55;
162
- }
163
-
164
- .button-primary {
165
- color: var(--color-primary-foreground);
166
- background: var(--color-primary);
167
- }
168
-
169
- .button-primary:hover:not(:disabled) {
170
- background: var(--color-primary-hover);
171
- }
172
-
173
- .button-secondary {
174
- border-color: var(--color-border);
175
- color: var(--color-foreground);
176
- background: var(--color-surface);
177
- }
178
-
179
146
  .form-grid,
180
147
  .stack-form {
181
148
  display: grid;
@@ -196,18 +163,6 @@ h2 {
196
163
  font-weight: 700;
197
164
  }
198
165
 
199
- .form-grid input,
200
- .form-grid select,
201
- .stack-form select {
202
- width: 100%;
203
- min-height: 38px;
204
- padding: 7px 9px;
205
- border: 1px solid var(--color-border);
206
- border-radius: 7px;
207
- color: var(--color-foreground);
208
- background: var(--color-surface);
209
- }
210
-
211
166
  .form-span {
212
167
  grid-column: 1 / -1;
213
168
  }
@@ -220,12 +175,6 @@ h2 {
220
175
  font-weight: 500;
221
176
  }
222
177
 
223
- .checkbox-row input {
224
- width: 16px;
225
- min-height: 16px;
226
- margin: 0;
227
- }
228
-
229
178
  .form-actions {
230
179
  min-height: 36px;
231
180
  color: var(--color-muted);
@@ -254,59 +203,6 @@ h2 {
254
203
  margin-left: auto;
255
204
  }
256
205
 
257
- .status-pill {
258
- display: inline-flex;
259
- flex: none;
260
- align-items: center;
261
- gap: 6px;
262
- min-height: 24px;
263
- padding: 3px 9px;
264
- border-radius: 999px;
265
- color: var(--color-foreground);
266
- background: var(--color-surface-muted);
267
- box-shadow: inset 0 0 0 1px var(--color-border);
268
- font-size: 12px;
269
- font-weight: 700;
270
- white-space: nowrap;
271
- }
272
-
273
- .status-pill::before {
274
- width: 6px;
275
- height: 6px;
276
- border-radius: 50%;
277
- background: currentColor;
278
- content: "";
279
- }
280
-
281
- .status-pill[data-status="success"],
282
- .status-pill[data-status="running"] {
283
- color: var(--color-success);
284
- background: color-mix(in srgb, var(--color-success) 10%, transparent);
285
- }
286
-
287
- .status-pill[data-status="pending"],
288
- .status-pill[data-status="warning"] {
289
- color: var(--color-warning);
290
- background: color-mix(in srgb, var(--color-warning) 10%, transparent);
291
- }
292
-
293
- .status-pill[data-status="failed"],
294
- .status-pill[data-status="error"] {
295
- color: var(--color-danger);
296
- background: color-mix(in srgb, var(--color-danger) 10%, transparent);
297
- }
298
-
299
- .error-message {
300
- padding: 10px 12px;
301
- margin-bottom: 0;
302
- border: 1px solid color-mix(in srgb, var(--color-danger) 25%, transparent);
303
- border-radius: 7px;
304
- color: var(--color-danger);
305
- background: color-mix(in srgb, var(--color-danger) 8%, transparent);
306
- font-size: 13px;
307
- line-height: 1.5;
308
- }
309
-
310
206
  .output-panel[data-status="failed"] {
311
207
  border-color: color-mix(in srgb, var(--color-danger) 35%, var(--color-border));
312
208
  }
@@ -328,9 +224,7 @@ h2 {
328
224
  @media (max-width: 760px) {
329
225
  .summary-grid,
330
226
  .two-column-layout,
331
- .form-grid {
332
- grid-template-columns: 1fr;
333
- }
227
+ .form-grid { grid-template-columns: 1fr; }
334
228
 
335
229
  .form-span {
336
230
  grid-column: auto;
@@ -346,3 +240,10 @@ h2 {
346
240
  justify-content: flex-start;
347
241
  }
348
242
  }
243
+
244
+ }
245
+
246
+ @layer components {
247
+ .maintenance-panel .mantine-Accordion-control { padding: 11px 14px; font-size: 13px; }
248
+ .error-message, .notice-card { margin: 12px 0 0; }
249
+ }
@@ -0,0 +1,2 @@
1
+ /** Declares the shared stylesheet side-effect import. */
2
+ export {};
@@ -0,0 +1,136 @@
1
+ import { d as PluginCommandExecutionResult, v as PluginExecutionSnapshot } from "../types-Cb_oPC5D.js";
2
+ //#region src/ui/types.d.ts
3
+ /**
4
+ * Browser authoring API and transport contracts for Workbase plugin views.
5
+ */
6
+ type PluginUiPromptType = 'confirm' | 'multi-select' | 'select' | 'text';
7
+ type PluginUiFileSelectionScope = 'project' | 'workspace';
8
+ type PluginUiFileSelectionItemType = 'any' | 'directory' | 'file';
9
+ interface PluginUiContextIdentity {
10
+ readonly id: string;
11
+ }
12
+ interface PluginUiViewIdentity extends PluginUiContextIdentity {
13
+ readonly pluginId: string;
14
+ readonly title: string;
15
+ }
16
+ interface PluginUiInitializationPayload {
17
+ readonly locale: string;
18
+ readonly params: Readonly<Record<string, unknown>>;
19
+ readonly project: PluginUiContextIdentity;
20
+ readonly route: string | null;
21
+ readonly theme: string;
22
+ readonly view: PluginUiViewIdentity;
23
+ readonly workspace: PluginUiContextIdentity;
24
+ }
25
+ interface WorkbasePluginUiDefinition {
26
+ readonly onInit: (payload: PluginUiInitializationPayload) => void | Promise<void>;
27
+ }
28
+ interface PluginUiCommandExecuteOptions {
29
+ readonly executionId?: string;
30
+ }
31
+ interface PluginUiNavigateOptions {
32
+ readonly replace?: boolean;
33
+ }
34
+ interface PluginUiToastOptions {
35
+ readonly description: string;
36
+ readonly title: string;
37
+ }
38
+ interface PluginUiPromptChoice<Value = unknown> {
39
+ readonly label: string;
40
+ readonly value: Value;
41
+ }
42
+ interface PluginUiPromptOptions<Value = unknown> {
43
+ readonly choices?: readonly PluginUiPromptChoice<Value>[];
44
+ readonly defaultValue?: Value | readonly Value[] | null;
45
+ readonly message: string;
46
+ readonly searchable?: boolean;
47
+ readonly submitLabel?: string;
48
+ readonly title: string;
49
+ readonly type: PluginUiPromptType;
50
+ }
51
+ interface PluginUiFileFilter {
52
+ readonly extensions: readonly string[];
53
+ readonly name: string;
54
+ }
55
+ interface PluginUiFileSelectOptions {
56
+ readonly filters?: readonly PluginUiFileFilter[];
57
+ readonly itemType?: PluginUiFileSelectionItemType;
58
+ readonly multiple?: boolean;
59
+ readonly rootPath?: string | null;
60
+ readonly scope?: PluginUiFileSelectionScope;
61
+ readonly title?: string;
62
+ }
63
+ interface PluginUiOutputOptions {
64
+ readonly content: string;
65
+ readonly description?: string | null;
66
+ readonly id: string;
67
+ readonly status?: string | null;
68
+ readonly title: string;
69
+ }
70
+ /** A single authoritative execution update; removal retains its identity and revision. */
71
+ interface PluginUiExecutionChange {
72
+ readonly snapshot: PluginExecutionSnapshot;
73
+ readonly removed: boolean;
74
+ }
75
+ interface PluginUiCommands {
76
+ /** Subscribe before querying snapshots. Dispose when the view no longer consumes events. */
77
+ readonly subscribe: (onChange: (change: PluginUiExecutionChange) => void) => Promise<() => Promise<void>>;
78
+ /** Reveal the existing host question; does not create or answer a prompt. */
79
+ readonly reply: (executionId: string) => Promise<void>;
80
+ /** Clear one ended execution, or all when omitted; active runs, logs and Agent sessions are retained. */
81
+ readonly clear: (executionId?: string) => Promise<void>;
82
+ readonly start: (commandId: string, input: unknown, options?: PluginUiCommandExecuteOptions) => Promise<PluginExecutionSnapshot>;
83
+ readonly query: (executionId?: string) => Promise<readonly PluginExecutionSnapshot[]>;
84
+ readonly cancel: <Result = unknown>(executionId: string) => Promise<Result>;
85
+ readonly execute: <Result = unknown>(commandId: string, input: unknown, options?: PluginUiCommandExecuteOptions) => Promise<PluginCommandExecutionResult<Result>>;
86
+ }
87
+ interface PluginUiStatus {
88
+ readonly resolve: <Result = unknown>(statusId: string, input: unknown) => Promise<Result>;
89
+ }
90
+ interface PluginUiView {
91
+ readonly call: <Result = unknown>(method: string, input: unknown) => Promise<Result>;
92
+ }
93
+ interface WorkbasePluginUi {
94
+ /** Hides a resumable interaction without answering or cancelling it. */
95
+ readonly dismiss: () => Promise<void>;
96
+ /** Answers only the interaction currently hosted in this frame. Null cancels it. */
97
+ readonly respond: (value: unknown | null) => Promise<void>;
98
+ readonly closeOutput: <Result = unknown>(id: string) => Promise<Result>;
99
+ readonly commands: PluginUiCommands;
100
+ readonly navigate: <Result = unknown>(to: string, options?: PluginUiNavigateOptions) => Promise<Result>;
101
+ readonly openOutput: <Result = unknown>(options: PluginUiOutputOptions) => Promise<Result>;
102
+ readonly selectFiles: (options?: PluginUiFileSelectOptions) => Promise<string | readonly string[] | null>;
103
+ readonly showPrompt: <Value = unknown>(options: PluginUiPromptOptions<Value>) => Promise<Value | readonly Value[] | null>;
104
+ readonly showToast: <Result = unknown>(options: PluginUiToastOptions) => Promise<Result>;
105
+ readonly status: PluginUiStatus;
106
+ readonly updateOutput: <Result = unknown>(options: PluginUiOutputOptions) => Promise<Result>;
107
+ readonly view: PluginUiView;
108
+ }
109
+ interface PluginUiHostError extends Error {
110
+ readonly code: string;
111
+ }
112
+ interface PluginUiHostMethods {
113
+ readonly call: (method: string, params: unknown) => Promise<unknown>;
114
+ readonly reportContentHeight: (height: number) => Promise<void>;
115
+ readonly reportFatal: (message: string) => Promise<void>;
116
+ }
117
+ interface PluginUiClientMethods {
118
+ readonly executionChanged: (change: PluginUiExecutionChange) => Promise<void>;
119
+ readonly initialize: (payload: unknown) => Promise<void>;
120
+ }
121
+ interface PluginUiTransportConnection {
122
+ readonly destroy: () => void;
123
+ readonly promise: Promise<PluginUiHostMethods>;
124
+ }
125
+ interface PluginUiControllerOptions {
126
+ readonly connectToHost: (methods: PluginUiClientMethods) => PluginUiTransportConnection;
127
+ readonly targetWindow: Window & typeof globalThis;
128
+ }
129
+ //#endregion
130
+ //#region src/ui/controller.d.ts
131
+ export declare function createPluginUiController(definition: WorkbasePluginUiDefinition, options: PluginUiControllerOptions): WorkbasePluginUi;
132
+ //#endregion
133
+ //#region src/ui/index.d.ts
134
+ export declare function defineWorkbasePluginUi(definition: WorkbasePluginUiDefinition): WorkbasePluginUi;
135
+ //#endregion
136
+ export type { PluginUiClientMethods, PluginUiCommandExecuteOptions, PluginUiCommands, PluginUiContextIdentity, PluginUiControllerOptions, PluginUiExecutionChange, PluginUiFileFilter, PluginUiFileSelectOptions, PluginUiFileSelectionItemType, PluginUiFileSelectionScope, PluginUiHostError, PluginUiHostMethods, PluginUiInitializationPayload, PluginUiNavigateOptions, PluginUiOutputOptions, PluginUiPromptChoice, PluginUiPromptOptions, PluginUiPromptType, PluginUiStatus, PluginUiToastOptions, PluginUiTransportConnection, PluginUiView, PluginUiViewIdentity, WorkbasePluginUi, WorkbasePluginUiDefinition };
@@ -0,0 +1,245 @@
1
+ import { WindowMessenger, connect } from "penpal";
2
+ //#region src/ui/controller.ts
3
+ const MAX_CONTENT_HEIGHT = 1e4;
4
+ const MAX_FATAL_MESSAGE_LENGTH = 1e3;
5
+ const MIN_CONTENT_HEIGHT = 1;
6
+ function createPluginUiController(definition, options) {
7
+ const onInit = definition?.onInit;
8
+ const connectToHost = options?.connectToHost;
9
+ const targetWindow = options?.targetWindow;
10
+ if (typeof onInit !== "function") throw new TypeError("defineWorkbasePluginUi requires an onInit callback.");
11
+ if (!targetWindow || typeof connectToHost !== "function") throw new TypeError("Plugin UI transport is unavailable.");
12
+ const state = {
13
+ fatalReportPromise: null,
14
+ isInitialized: false,
15
+ contentHeight: null,
16
+ recoverableHostErrors: /* @__PURE__ */ new WeakSet()
17
+ };
18
+ const executionListeners = /* @__PURE__ */ new Set();
19
+ const connection = connectToHost({
20
+ executionChanged: async (change) => {
21
+ if (state.isInitialized) [...executionListeners].forEach((listener) => listener(change));
22
+ },
23
+ initialize: async (payload) => {
24
+ assertInitializationPayload(payload);
25
+ state.isInitialized = true;
26
+ await onInit(payload);
27
+ await waitForPluginUiPaint(targetWindow);
28
+ await reportContentHeight(hostPromise, {
29
+ targetWindow,
30
+ state
31
+ });
32
+ }
33
+ });
34
+ const hostPromise = connection.promise;
35
+ const request = createHostRequest(hostPromise, state);
36
+ bindPluginUiLifecycle({
37
+ connection,
38
+ state,
39
+ targetWindow
40
+ });
41
+ const subscribe = async (onChange) => {
42
+ const listener = (change) => onChange(change);
43
+ executionListeners.add(listener);
44
+ try {
45
+ await request("command.subscribe", { enabled: true });
46
+ } catch (error) {
47
+ executionListeners.delete(listener);
48
+ throw error;
49
+ }
50
+ return async () => {
51
+ if (!executionListeners.delete(listener) || executionListeners.size) return;
52
+ await request("command.subscribe", { enabled: false });
53
+ };
54
+ };
55
+ return createPluginUiApi(request, {
56
+ targetWindow,
57
+ subscribe
58
+ });
59
+ }
60
+ function createHostRequest(hostPromise, state) {
61
+ return async (method, params) => {
62
+ if (!state.isInitialized) throw new Error("Plugin UI is not initialized.");
63
+ const response = await (await hostPromise).call(method, params);
64
+ if (isRecord(response) && response.ok === true) return response.result;
65
+ const error = createHostError(response);
66
+ state.recoverableHostErrors.add(error);
67
+ throw error;
68
+ };
69
+ }
70
+ function createHostError(response) {
71
+ const responseError = isRecord(response) && isRecord(response.error) ? response.error : null;
72
+ const message = typeof responseError?.message === "string" ? responseError.message : "Host action failed.";
73
+ const code = typeof responseError?.code === "string" ? responseError.code : "host_error";
74
+ return Object.assign(new Error(message), { code });
75
+ }
76
+ function createPluginUiApi(request, { targetWindow, subscribe }) {
77
+ const commands = Object.freeze({
78
+ subscribe,
79
+ reply: (executionId) => request("command.reply", { executionId }),
80
+ clear: (executionId) => request("command.clear", executionId === void 0 ? {} : { executionId }),
81
+ start: (commandId, input, options = {}) => request("command.start", {
82
+ commandId,
83
+ input,
84
+ executionId: options.executionId ?? targetWindow.crypto.randomUUID()
85
+ }),
86
+ query: (executionId) => request("command.query", { executionId: executionId ?? null }),
87
+ cancel: (executionId) => request("command.cancel", { executionId }),
88
+ execute: (commandId, input, options = {}) => {
89
+ return request("command.execute", {
90
+ commandId,
91
+ executionId: options.executionId ?? targetWindow.crypto.randomUUID(),
92
+ input
93
+ });
94
+ }
95
+ });
96
+ const status = Object.freeze({ resolve: (statusId, input) => request("status.resolve", {
97
+ input,
98
+ statusId
99
+ }) });
100
+ const view = Object.freeze({ call: (method, input) => request("view.call", {
101
+ input,
102
+ method
103
+ }) });
104
+ return Object.freeze({
105
+ dismiss: () => request("interaction.dismiss", {}),
106
+ respond: (value) => request("interaction.respond", { value }),
107
+ closeOutput: (id) => request("output.close", { id }),
108
+ commands,
109
+ navigate: (to, { replace = false } = {}) => request("navigate", {
110
+ replace,
111
+ to
112
+ }),
113
+ openOutput: (options) => request("output.open", options),
114
+ selectFiles: (options = {}) => request("file.select", options),
115
+ showPrompt: (options) => request("dialog.prompt", options),
116
+ showToast: (options) => request("toast.show", options),
117
+ status,
118
+ updateOutput: (options) => request("output.update", options),
119
+ view
120
+ });
121
+ }
122
+ function bindPluginUiLifecycle({ connection, state, targetWindow }) {
123
+ let resizeFrame = null;
124
+ const handleWindowError = (event) => {
125
+ if (!event.error && (event.message === "ResizeObserver loop completed with undelivered notifications." || event.message === "ResizeObserver loop limit exceeded")) return;
126
+ reportFirstFatal(connection.promise, state, event.error ?? event.message);
127
+ };
128
+ const handleUnhandledRejection = (event) => {
129
+ if (event.reason instanceof Error && state.recoverableHostErrors.has(event.reason)) return;
130
+ reportFirstFatal(connection.promise, state, event.reason);
131
+ };
132
+ const resizeObserver = new targetWindow.ResizeObserver(() => {
133
+ if (resizeFrame !== null) return;
134
+ resizeFrame = targetWindow.requestAnimationFrame(() => {
135
+ resizeFrame = null;
136
+ if (state.isInitialized) reportContentHeight(connection.promise, {
137
+ targetWindow,
138
+ state
139
+ });
140
+ });
141
+ });
142
+ const cleanup = () => {
143
+ targetWindow.removeEventListener("error", handleWindowError, true);
144
+ targetWindow.removeEventListener("unhandledrejection", handleUnhandledRejection);
145
+ targetWindow.removeEventListener("beforeunload", cleanup);
146
+ resizeObserver.disconnect();
147
+ if (resizeFrame !== null) targetWindow.cancelAnimationFrame(resizeFrame);
148
+ connection.destroy();
149
+ state.fatalReportPromise = null;
150
+ state.isInitialized = false;
151
+ };
152
+ ignoreConnectionFailure(connection.promise);
153
+ resizeObserver.observe(targetWindow.document.body ?? targetWindow.document.documentElement);
154
+ targetWindow.addEventListener("error", handleWindowError, true);
155
+ targetWindow.addEventListener("unhandledrejection", handleUnhandledRejection);
156
+ targetWindow.addEventListener("beforeunload", cleanup, { once: true });
157
+ }
158
+ async function ignoreConnectionFailure(hostPromise) {
159
+ try {
160
+ await hostPromise;
161
+ } catch {}
162
+ }
163
+ async function waitForPluginUiPaint(targetWindow) {
164
+ await new Promise((resolve) => {
165
+ targetWindow.requestAnimationFrame(() => {
166
+ targetWindow.requestAnimationFrame(() => resolve());
167
+ });
168
+ });
169
+ }
170
+ async function reportFirstFatal(hostPromise, state, error) {
171
+ if (!state.fatalReportPromise) state.fatalReportPromise = sendFatalReport(hostPromise, getFatalMessage(error).slice(0, MAX_FATAL_MESSAGE_LENGTH));
172
+ await state.fatalReportPromise;
173
+ }
174
+ async function sendFatalReport(hostPromise, message) {
175
+ try {
176
+ await (await hostPromise).reportFatal(message);
177
+ } catch {}
178
+ }
179
+ async function reportContentHeight(hostPromise, { targetWindow, state }) {
180
+ const contentElement = targetWindow.document.body ?? targetWindow.document.documentElement;
181
+ const height = Math.max(contentElement.offsetHeight, contentElement.scrollHeight);
182
+ if (!Number.isFinite(height)) return;
183
+ try {
184
+ const host = await hostPromise;
185
+ const contentHeight = Math.min(Math.max(Math.ceil(height), MIN_CONTENT_HEIGHT), MAX_CONTENT_HEIGHT);
186
+ if (!state.isInitialized || state.contentHeight === contentHeight) return;
187
+ state.contentHeight = contentHeight;
188
+ await host.reportContentHeight(contentHeight);
189
+ } catch {}
190
+ }
191
+ function assertInitializationPayload(value) {
192
+ if (!isInitializationPayload(value)) throw new TypeError("Plugin UI initialization payload is invalid.");
193
+ }
194
+ function isInitializationPayload(value) {
195
+ if (!isRecord(value)) return false;
196
+ return isContextIdentity(value.project) && isContextIdentity(value.workspace) && isViewIdentity(value.view);
197
+ }
198
+ function isContextIdentity(value) {
199
+ return isRecord(value) && typeof value.id === "string" && value.id.length > 0;
200
+ }
201
+ function isViewIdentity(value) {
202
+ return isContextIdentity(value) && isRecord(value) && typeof value.pluginId === "string" && value.pluginId.length > 0 && typeof value.title === "string" && value.title.length > 0;
203
+ }
204
+ function isRecord(value) {
205
+ return value !== null && typeof value === "object" && !Array.isArray(value);
206
+ }
207
+ function getFatalMessage(error) {
208
+ if (error instanceof Error) return error.message;
209
+ if (typeof error === "string" && error.trim().length > 0) return error;
210
+ return "Plugin UI failed.";
211
+ }
212
+ //#endregion
213
+ //#region src/ui/index.ts
214
+ /**
215
+ * Penpal browser entry for trusted Workbase plugin views.
216
+ */
217
+ const BRIDGE_CHANNEL = "workbase-plugin-ui-v1";
218
+ const HOST_ORIGIN_PARAMETER = "__workbaseHostOrigin";
219
+ function defineWorkbasePluginUi(definition) {
220
+ const targetWindow = window;
221
+ return createPluginUiController(definition, {
222
+ connectToHost: (methods) => createPenpalConnection(targetWindow, methods),
223
+ targetWindow
224
+ });
225
+ }
226
+ function createPenpalConnection(targetWindow, methods) {
227
+ const connection = connect({
228
+ channel: BRIDGE_CHANNEL,
229
+ messenger: new WindowMessenger({
230
+ allowedOrigins: resolveParentOrigins(targetWindow),
231
+ remoteWindow: targetWindow.parent
232
+ }),
233
+ methods
234
+ });
235
+ return {
236
+ destroy: connection.destroy,
237
+ promise: connection.promise
238
+ };
239
+ }
240
+ function resolveParentOrigins(targetWindow) {
241
+ const hostOrigin = new URL(targetWindow.location.href).searchParams.get(HOST_ORIGIN_PARAMETER);
242
+ return hostOrigin && hostOrigin !== "null" ? [hostOrigin] : ["*"];
243
+ }
244
+ //#endregion
245
+ export { createPluginUiController, defineWorkbasePluginUi };
@@ -1,11 +1,13 @@
1
+ //#region src/ui/model.d.ts
1
2
  /**
2
3
  * Formats command results and recent Host log entries for built-in plugin views.
3
4
  */
4
5
  export interface PluginActionOutput {
5
- readonly content: string;
6
- readonly status: "completed" | "failed";
7
- readonly title: string;
6
+ readonly content: string;
7
+ readonly status: "completed" | "failed";
8
+ readonly title: string;
8
9
  }
9
10
  export declare function formatActionOutput(title: string, result: unknown, logs: unknown): PluginActionOutput;
10
11
  export declare function formatActionError(title: string, error: unknown): PluginActionOutput;
11
12
  export declare function readableError(error: unknown, fallback: string): string;
13
+ //#endregion
@@ -0,0 +1,38 @@
1
+ //#region src/ui/model.ts
2
+ function formatActionOutput(title, result, logs) {
3
+ const logText = formatLogEntries(logs);
4
+ const resultText = formatResult(result);
5
+ return {
6
+ content: logText || resultText || `${title}已完成。`,
7
+ status: "completed",
8
+ title
9
+ };
10
+ }
11
+ function formatActionError(title, error) {
12
+ return {
13
+ content: readableError(error, `${title}失败。`),
14
+ status: "failed",
15
+ title
16
+ };
17
+ }
18
+ function readableError(error, fallback) {
19
+ return error instanceof Error && error.message.trim().length > 0 ? error.message : fallback;
20
+ }
21
+ function formatLogEntries(value) {
22
+ if (!Array.isArray(value)) return "";
23
+ return value.filter(isRecord).map((entry) => {
24
+ const level = typeof entry.level === "string" ? entry.level : "log";
25
+ const message = typeof entry.message === "string" ? entry.message : "";
26
+ return message ? `[${level}] ${message}` : "";
27
+ }).filter(Boolean).join("\n");
28
+ }
29
+ function formatResult(value) {
30
+ if (value === null || value === void 0) return "";
31
+ if (typeof value === "string") return value;
32
+ return JSON.stringify(value, null, 2);
33
+ }
34
+ function isRecord(value) {
35
+ return value !== null && typeof value === "object" && !Array.isArray(value);
36
+ }
37
+ //#endregion
38
+ export { formatActionError, formatActionOutput, readableError };