@eworkbase/sdk 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/ui/index.css ADDED
@@ -0,0 +1,348 @@
1
+ :root {
2
+ --color-foreground: #342f28;
3
+ --color-muted: #6c675f;
4
+ --color-border: #e2dfd6;
5
+ --color-surface: #fff;
6
+ --color-surface-muted: #f3f2ed;
7
+ --color-brand: #8a5000;
8
+ --color-primary: #ffde39;
9
+ --color-primary-hover: #ffca00;
10
+ --color-primary-foreground: #322d16;
11
+ --color-accent: #0969da;
12
+ --color-danger: #b9360a;
13
+ --color-success: #087c75;
14
+ --color-warning: #9a5600;
15
+ color: var(--color-foreground);
16
+ background: transparent;
17
+ font-family:
18
+ Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
19
+ font-synthesis: none;
20
+ }
21
+
22
+ * {
23
+ box-sizing: border-box;
24
+ }
25
+
26
+ body {
27
+ min-width: 320px;
28
+ margin: 0;
29
+ background: transparent;
30
+ }
31
+
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
+ h1,
47
+ h2,
48
+ p {
49
+ margin-top: 0;
50
+ }
51
+
52
+ h1 {
53
+ margin-bottom: 4px;
54
+ font-size: 22px;
55
+ letter-spacing: -0.02em;
56
+ }
57
+
58
+ h2 {
59
+ margin-bottom: 4px;
60
+ font-size: 15px;
61
+ }
62
+
63
+ .app-shell {
64
+ display: grid;
65
+ width: 100%;
66
+ gap: 12px;
67
+ padding: 16px;
68
+ }
69
+
70
+ .page-header,
71
+ .panel-heading,
72
+ .form-actions,
73
+ .button-row,
74
+ .checkbox-row {
75
+ display: flex;
76
+ align-items: center;
77
+ }
78
+
79
+ .page-header,
80
+ .panel-heading,
81
+ .form-actions {
82
+ justify-content: space-between;
83
+ gap: 12px;
84
+ }
85
+
86
+ .eyebrow {
87
+ margin-bottom: 3px;
88
+ color: var(--color-brand);
89
+ font-size: 12px;
90
+ font-weight: 700;
91
+ }
92
+
93
+ .page-description,
94
+ .panel-heading p {
95
+ margin-bottom: 0;
96
+ color: var(--color-muted);
97
+ font-size: 13px;
98
+ line-height: 1.5;
99
+ }
100
+
101
+ .summary-grid {
102
+ display: grid;
103
+ grid-template-columns: repeat(3, minmax(0, 1fr));
104
+ gap: 8px;
105
+ }
106
+
107
+ .summary-card,
108
+ .panel {
109
+ border: 1px solid var(--color-border);
110
+ border-radius: 8px;
111
+ background: var(--color-surface);
112
+ }
113
+
114
+ .summary-card {
115
+ display: grid;
116
+ gap: 5px;
117
+ min-width: 0;
118
+ padding: 12px;
119
+ }
120
+
121
+ .summary-card span {
122
+ color: var(--color-muted);
123
+ font-size: 12px;
124
+ }
125
+
126
+ .summary-card strong {
127
+ overflow: hidden;
128
+ font-size: 14px;
129
+ text-overflow: ellipsis;
130
+ white-space: nowrap;
131
+ }
132
+
133
+ .panel {
134
+ padding: 14px;
135
+ }
136
+
137
+ .two-column-layout {
138
+ display: grid;
139
+ grid-template-columns: minmax(0, 2fr) minmax(240px, 1fr);
140
+ gap: 12px;
141
+ }
142
+
143
+ .button-row {
144
+ flex-wrap: wrap;
145
+ justify-content: flex-end;
146
+ gap: 8px;
147
+ }
148
+
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
+ .form-grid,
180
+ .stack-form {
181
+ display: grid;
182
+ gap: 12px;
183
+ margin-top: 14px;
184
+ }
185
+
186
+ .form-grid {
187
+ grid-template-columns: repeat(2, minmax(0, 1fr));
188
+ }
189
+
190
+ .form-grid label,
191
+ .stack-form label {
192
+ display: grid;
193
+ gap: 6px;
194
+ color: var(--color-muted);
195
+ font-size: 12px;
196
+ font-weight: 700;
197
+ }
198
+
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
+ .form-span {
212
+ grid-column: 1 / -1;
213
+ }
214
+
215
+ .form-grid .checkbox-row,
216
+ .target-form .checkbox-row {
217
+ display: flex;
218
+ gap: 8px;
219
+ color: var(--color-foreground);
220
+ font-weight: 500;
221
+ }
222
+
223
+ .checkbox-row input {
224
+ width: 16px;
225
+ min-height: 16px;
226
+ margin: 0;
227
+ }
228
+
229
+ .form-actions {
230
+ min-height: 36px;
231
+ color: var(--color-muted);
232
+ font-size: 12px;
233
+ }
234
+
235
+ .form-actions a {
236
+ color: var(--color-accent);
237
+ font-weight: 700;
238
+ text-decoration: none;
239
+ }
240
+
241
+ .panel-actions {
242
+ margin-top: 24px;
243
+ }
244
+
245
+ .target-form {
246
+ display: flex;
247
+ flex-wrap: wrap;
248
+ align-items: center;
249
+ gap: 10px 18px;
250
+ margin-top: 14px;
251
+ }
252
+
253
+ .target-form .button {
254
+ margin-left: auto;
255
+ }
256
+
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
+ .output-panel[data-status="failed"] {
311
+ border-color: color-mix(in srgb, var(--color-danger) 35%, var(--color-border));
312
+ }
313
+
314
+ .output-panel pre {
315
+ max-height: 220px;
316
+ padding: 10px;
317
+ margin: 12px 0 0;
318
+ overflow: auto;
319
+ border-radius: 7px;
320
+ color: var(--color-foreground);
321
+ background: var(--color-surface-muted);
322
+ font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
323
+ font-size: 12px;
324
+ line-height: 1.55;
325
+ white-space: pre-wrap;
326
+ }
327
+
328
+ @media (max-width: 760px) {
329
+ .summary-grid,
330
+ .two-column-layout,
331
+ .form-grid {
332
+ grid-template-columns: 1fr;
333
+ }
334
+
335
+ .form-span {
336
+ grid-column: auto;
337
+ }
338
+
339
+ .page-header,
340
+ .panel-heading {
341
+ align-items: flex-start;
342
+ flex-direction: column;
343
+ }
344
+
345
+ .button-row {
346
+ justify-content: flex-start;
347
+ }
348
+ }
package/ui/index.d.ts ADDED
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Penpal browser entry for trusted Workbase plugin views.
3
+ */
4
+ import type { WorkbasePluginUi, WorkbasePluginUiDefinition } from './types.js';
5
+ export declare function defineWorkbasePluginUi(definition: WorkbasePluginUiDefinition): WorkbasePluginUi;
6
+ export { createPluginUiController } from './controller.js';
7
+ export type { PluginUiClientMethods, PluginUiCommandExecuteOptions, PluginUiCommands, PluginUiContextIdentity, PluginUiControllerOptions, PluginUiFileFilter, PluginUiFileSelectionItemType, PluginUiFileSelectionScope, PluginUiFileSelectOptions, PluginUiHostError, PluginUiHostMethods, PluginUiInitializationPayload, PluginUiNavigateOptions, PluginUiOutputOptions, PluginUiPromptChoice, PluginUiPromptOptions, PluginUiPromptType, PluginUiStatus, PluginUiToastOptions, PluginUiTransportConnection, PluginUiView, PluginUiViewIdentity, WorkbasePluginUi, WorkbasePluginUiDefinition, } from './types.js';
package/ui/index.js ADDED
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Penpal browser entry for trusted Workbase plugin views.
3
+ */
4
+ import { connect, WindowMessenger } from 'penpal';
5
+ import { createPluginUiController } from './controller.js';
6
+ const BRIDGE_CHANNEL = 'workbase-plugin-ui-v1';
7
+ const HOST_ORIGIN_PARAMETER = '__workbaseHostOrigin';
8
+ // ─── Public API ──────────────────────────────────────────────
9
+ export function defineWorkbasePluginUi(definition) {
10
+ const targetWindow = window;
11
+ return createPluginUiController(definition, {
12
+ connectToHost: (methods) => createPenpalConnection(targetWindow, methods),
13
+ targetWindow,
14
+ });
15
+ }
16
+ export { createPluginUiController } from './controller.js';
17
+ // ─── Transport ───────────────────────────────────────────────
18
+ function createPenpalConnection(targetWindow, methods) {
19
+ const connection = connect({
20
+ channel: BRIDGE_CHANNEL,
21
+ messenger: new WindowMessenger({
22
+ allowedOrigins: resolveParentOrigins(targetWindow),
23
+ remoteWindow: targetWindow.parent,
24
+ }),
25
+ methods: methods,
26
+ });
27
+ return {
28
+ destroy: connection.destroy,
29
+ promise: connection.promise,
30
+ };
31
+ }
32
+ function resolveParentOrigins(targetWindow) {
33
+ const hostOrigin = new URL(targetWindow.location.href).searchParams.get(HOST_ORIGIN_PARAMETER);
34
+ return hostOrigin && hostOrigin !== 'null' ? [hostOrigin] : ['*'];
35
+ }
package/ui/model.d.ts ADDED
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Formats command results and recent Host log entries for built-in plugin views.
3
+ */
4
+ export interface PluginActionOutput {
5
+ readonly content: string;
6
+ readonly status: "completed" | "failed";
7
+ readonly title: string;
8
+ }
9
+ export declare function formatActionOutput(title: string, result: unknown, logs: unknown): PluginActionOutput;
10
+ export declare function formatActionError(title: string, error: unknown): PluginActionOutput;
11
+ export declare function readableError(error: unknown, fallback: string): string;
package/ui/model.js ADDED
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Formats command results and recent Host log entries for built-in plugin views.
3
+ */
4
+ export function formatActionOutput(title, result, logs) {
5
+ const logText = formatLogEntries(logs);
6
+ const resultText = formatResult(result);
7
+ return {
8
+ content: logText || resultText || `${title}已完成。`,
9
+ status: "completed",
10
+ title,
11
+ };
12
+ }
13
+ export function formatActionError(title, error) {
14
+ return {
15
+ content: readableError(error, `${title}失败。`),
16
+ status: "failed",
17
+ title,
18
+ };
19
+ }
20
+ export function readableError(error, fallback) {
21
+ return error instanceof Error && error.message.trim().length > 0
22
+ ? error.message
23
+ : fallback;
24
+ }
25
+ function formatLogEntries(value) {
26
+ if (!Array.isArray(value)) {
27
+ return "";
28
+ }
29
+ return value
30
+ .filter(isRecord)
31
+ .map((entry) => {
32
+ const level = typeof entry.level === "string" ? entry.level : "log";
33
+ const message = typeof entry.message === "string" ? entry.message : "";
34
+ return message ? `[${level}] ${message}` : "";
35
+ })
36
+ .filter(Boolean)
37
+ .join("\n");
38
+ }
39
+ function formatResult(value) {
40
+ if (value === null || value === undefined) {
41
+ return "";
42
+ }
43
+ if (typeof value === "string") {
44
+ return value;
45
+ }
46
+ return JSON.stringify(value, null, 2);
47
+ }
48
+ function isRecord(value) {
49
+ return value !== null && typeof value === "object" && !Array.isArray(value);
50
+ }
package/ui/types.d.ts ADDED
@@ -0,0 +1,108 @@
1
+ /**
2
+ * Browser authoring API and transport contracts for Workbase plugin views.
3
+ */
4
+ export type PluginUiPromptType = 'confirm' | 'multi-select' | 'select' | 'text';
5
+ export type PluginUiFileSelectionScope = 'project' | 'workspace';
6
+ export type PluginUiFileSelectionItemType = 'any' | 'directory' | 'file';
7
+ export interface PluginUiContextIdentity {
8
+ readonly id: string;
9
+ }
10
+ export interface PluginUiViewIdentity extends PluginUiContextIdentity {
11
+ readonly pluginId: string;
12
+ readonly title: string;
13
+ }
14
+ export interface PluginUiInitializationPayload {
15
+ readonly locale: string;
16
+ readonly params: Readonly<Record<string, unknown>>;
17
+ readonly project: PluginUiContextIdentity;
18
+ readonly route: string | null;
19
+ readonly theme: string;
20
+ readonly view: PluginUiViewIdentity;
21
+ readonly workspace: PluginUiContextIdentity;
22
+ }
23
+ export interface WorkbasePluginUiDefinition {
24
+ readonly onInit: (payload: PluginUiInitializationPayload) => void | Promise<void>;
25
+ }
26
+ export interface PluginUiCommandExecuteOptions {
27
+ readonly executionId?: string;
28
+ }
29
+ export interface PluginUiNavigateOptions {
30
+ readonly replace?: boolean;
31
+ }
32
+ export interface PluginUiToastOptions {
33
+ readonly description: string;
34
+ readonly title: string;
35
+ }
36
+ export interface PluginUiPromptChoice<Value = unknown> {
37
+ readonly label: string;
38
+ readonly value: Value;
39
+ }
40
+ export interface PluginUiPromptOptions<Value = unknown> {
41
+ readonly choices?: readonly PluginUiPromptChoice<Value>[];
42
+ readonly defaultValue?: Value | readonly Value[] | null;
43
+ readonly message: string;
44
+ readonly searchable?: boolean;
45
+ readonly submitLabel?: string;
46
+ readonly title: string;
47
+ readonly type: PluginUiPromptType;
48
+ }
49
+ export interface PluginUiFileFilter {
50
+ readonly extensions: readonly string[];
51
+ readonly name: string;
52
+ }
53
+ export interface PluginUiFileSelectOptions {
54
+ readonly filters?: readonly PluginUiFileFilter[];
55
+ readonly itemType?: PluginUiFileSelectionItemType;
56
+ readonly multiple?: boolean;
57
+ readonly rootPath?: string | null;
58
+ readonly scope?: PluginUiFileSelectionScope;
59
+ readonly title?: string;
60
+ }
61
+ export interface PluginUiOutputOptions {
62
+ readonly content: string;
63
+ readonly description?: string | null;
64
+ readonly id: string;
65
+ readonly status?: string | null;
66
+ readonly title: string;
67
+ }
68
+ export interface PluginUiCommands {
69
+ readonly cancel: <Result = unknown>(executionId: string) => Promise<Result>;
70
+ readonly execute: <Result = unknown>(commandId: string, input: unknown, options?: PluginUiCommandExecuteOptions) => Promise<Result>;
71
+ }
72
+ export interface PluginUiStatus {
73
+ readonly resolve: <Result = unknown>(statusId: string, input: unknown) => Promise<Result>;
74
+ }
75
+ export interface PluginUiView {
76
+ readonly call: <Result = unknown>(method: string, input: unknown) => Promise<Result>;
77
+ }
78
+ export interface WorkbasePluginUi {
79
+ readonly closeOutput: <Result = unknown>(id: string) => Promise<Result>;
80
+ readonly commands: PluginUiCommands;
81
+ readonly navigate: <Result = unknown>(to: string, options?: PluginUiNavigateOptions) => Promise<Result>;
82
+ readonly openOutput: <Result = unknown>(options: PluginUiOutputOptions) => Promise<Result>;
83
+ readonly selectFiles: (options?: PluginUiFileSelectOptions) => Promise<string | readonly string[] | null>;
84
+ readonly showPrompt: <Value = unknown>(options: PluginUiPromptOptions<Value>) => Promise<Value | readonly Value[] | null>;
85
+ readonly showToast: <Result = unknown>(options: PluginUiToastOptions) => Promise<Result>;
86
+ readonly status: PluginUiStatus;
87
+ readonly updateOutput: <Result = unknown>(options: PluginUiOutputOptions) => Promise<Result>;
88
+ readonly view: PluginUiView;
89
+ }
90
+ export interface PluginUiHostError extends Error {
91
+ readonly code: string;
92
+ }
93
+ export interface PluginUiHostMethods {
94
+ readonly call: (method: string, params: unknown) => Promise<unknown>;
95
+ readonly reportContentHeight: (height: number) => Promise<void>;
96
+ readonly reportFatal: (message: string) => Promise<void>;
97
+ }
98
+ export interface PluginUiClientMethods {
99
+ readonly initialize: (payload: unknown) => Promise<void>;
100
+ }
101
+ export interface PluginUiTransportConnection {
102
+ readonly destroy: () => void;
103
+ readonly promise: Promise<PluginUiHostMethods>;
104
+ }
105
+ export interface PluginUiControllerOptions {
106
+ readonly connectToHost: (methods: PluginUiClientMethods) => PluginUiTransportConnection;
107
+ readonly targetWindow: Window & typeof globalThis;
108
+ }
package/ui/types.js ADDED
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Browser authoring API and transport contracts for Workbase plugin views.
3
+ */
4
+ export {};