@eworkbase/sdk 0.4.4 → 0.8.1
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/dist/index.d.ts +13 -1
- package/dist/index.js +112 -31
- package/dist/markdown.d.ts +1 -1
- package/dist/{types-DoDWh0mS.d.ts → types-2X-_T_W_.d.ts} +12 -2
- package/dist/{types-DjPBTfWP.d.ts → types-DXhRV5dI.d.ts} +7 -4
- package/dist/ui/error-panel.d.ts +1 -0
- package/dist/ui/error-panel.js +27 -9
- package/dist/ui/execution-log.js +21 -6
- package/dist/ui/index.d.ts +1 -1
- package/dist/ui/index.js +44 -9
- package/dist/ui/markdown-editor.js +8 -5
- package/dist/ui/markdown-links.d.ts +1 -1
- package/dist/ui/markdown-links.js +14 -5
- package/dist/ui/model.d.ts +3 -3
- package/dist/ui/model.js +5 -1
- package/dist/ui/theme.css +6 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,18 @@
|
|
|
1
1
|
import { a as executionLogRecordSchema, i as executionLogEntrySchema, n as ExecutionLogEntryKind, r as ExecutionLogRecord, t as ExecutionLogEntry } from "./ExecutionLog.dto-ig9GUWhK.js";
|
|
2
|
-
import { $ as PluginViewDefinition, A as PluginLifecycleDispatchResult, At as PluginTaskResult, B as PluginProcessOutputMode, Bt as RoleToolEnvironment, C as PluginExecutionEvidence, Ct as PluginPromptQuestion, D as PluginHookId, Dt as PluginStoreApi, E as PluginFileChange, Et as PluginStatusCatalogEntry, F as PluginLogger, Ft as PluginViewCatalogEntry, G as PluginRepositoryStatus, Gt as roleToolsProposalSchema, H as PluginProcessRunOptions, Ht as RoleToolsProposal, I as PluginOverviewCardData, It as PluginWorkflowContribution, J as PluginSharedChanges, K as PluginSetupHooks, L as PluginOverviewCardDefinition, Lt as PluginWorkflowOutput, M as PluginLifecycleOutcome, Mt as PluginToastApi, N as PluginLifecyclePolicy, Nt as PluginToastLevel, O as PluginHookResult, Ot as PluginSystemContextService, P as PluginLifecycleStatus, Pt as PluginToastOptions, Q as PluginViewContribution, R as PluginOverviewCardStatus, Rt as workflowContributionSchema, S as PluginDisposable, St as PluginPromptChoice, T as PluginExecutionStatus, Tt as PluginPromptViewRequest, U as PluginProject, Ut as roleToolEnvironmentSchema, V as PluginProcessResult, Vt as RoleToolsApplied, W as PluginRepository, Wt as roleToolsAppliedSchema, X as PluginStatusDefinition, Y as PluginStatusContribution, Z as PluginToolContribution, _ as PluginCommandOption, _t as PluginLogEntry, a as PluginCapabilityReference, at as PluginAgentContextCatalogEntry, b as PluginContextExposure, bt as PluginLogService, c as PluginCommandCategory, ct as PluginCapabilityCommandRequest, d as PluginCommandDefinition, dt as PluginColoredMessage, et as PluginViewLayout, f as PluginCommandDetails, ft as PluginCommandCatalogEntry, g as PluginCommandLogPolicy, gt as PluginInteractiveLogger, h as PluginCommandExecutionResult, ht as PluginHostServices, i as PluginCapabilityKind, it as WorkbasePluginDefinition, j as PluginLifecycleHook, jt as PluginTaskService, k as PluginInvocationContext, kt as PluginTaskDescriptor, l as PluginCommandContext, lt as PluginCapabilityResolveRequest, m as PluginCommandExecutionMode, mt as PluginExecutionService, n as PluginAgentContextDefinition, nt as PluginViewRequest, o as PluginCardAction, ot as PluginAgentPolicy, p as PluginCommandEffect, pt as PluginConfigApi, q as PluginSharedChangeKind, r as PluginAgentScope, rt as PluginWorkspace, s as PluginCommandArgument, st as PluginCapabilityCatalog, t as PluginAgentContextContribution, tt as PluginViewMethod, u as PluginCommandContribution, ut as PluginCapabilityService, v as PluginCommandTransaction, vt as PluginLogQueryRequest, w as PluginExecutionSnapshot, wt as PluginPromptType, x as PluginContributionSnapshot, xt as PluginPromptApi, y as PluginContext, yt as PluginLogQueryResult, z as PluginProcessApi, zt as PluginToolsService } from "./types-
|
|
2
|
+
import { $ as PluginViewDefinition, A as PluginLifecycleDispatchResult, At as PluginTaskResult, B as PluginProcessOutputMode, Bt as RoleToolEnvironment, C as PluginExecutionEvidence, Ct as PluginPromptQuestion, D as PluginHookId, Dt as PluginStoreApi, E as PluginFileChange, Et as PluginStatusCatalogEntry, F as PluginLogger, Ft as PluginViewCatalogEntry, G as PluginRepositoryStatus, Gt as roleToolsProposalSchema, H as PluginProcessRunOptions, Ht as RoleToolsProposal, I as PluginOverviewCardData, It as PluginWorkflowContribution, J as PluginSharedChanges, K as PluginSetupHooks, L as PluginOverviewCardDefinition, Lt as PluginWorkflowOutput, M as PluginLifecycleOutcome, Mt as PluginToastApi, N as PluginLifecyclePolicy, Nt as PluginToastLevel, O as PluginHookResult, Ot as PluginSystemContextService, P as PluginLifecycleStatus, Pt as PluginToastOptions, Q as PluginViewContribution, R as PluginOverviewCardStatus, Rt as workflowContributionSchema, S as PluginDisposable, St as PluginPromptChoice, T as PluginExecutionStatus, Tt as PluginPromptViewRequest, U as PluginProject, Ut as roleToolEnvironmentSchema, V as PluginProcessResult, Vt as RoleToolsApplied, W as PluginRepository, Wt as roleToolsAppliedSchema, X as PluginStatusDefinition, Y as PluginStatusContribution, Z as PluginToolContribution, _ as PluginCommandOption, _t as PluginLogEntry, a as PluginCapabilityReference, at as PluginAgentContextCatalogEntry, b as PluginContextExposure, bt as PluginLogService, c as PluginCommandCategory, ct as PluginCapabilityCommandRequest, d as PluginCommandDefinition, dt as PluginColoredMessage, et as PluginViewLayout, f as PluginCommandDetails, ft as PluginCommandCatalogEntry, g as PluginCommandLogPolicy, gt as PluginInteractiveLogger, h as PluginCommandExecutionResult, ht as PluginHostServices, i as PluginCapabilityKind, it as WorkbasePluginDefinition, j as PluginLifecycleHook, jt as PluginTaskService, k as PluginInvocationContext, kt as PluginTaskDescriptor, l as PluginCommandContext, lt as PluginCapabilityResolveRequest, m as PluginCommandExecutionMode, mt as PluginExecutionService, n as PluginAgentContextDefinition, nt as PluginViewRequest, o as PluginCardAction, ot as PluginAgentPolicy, p as PluginCommandEffect, pt as PluginConfigApi, q as PluginSharedChangeKind, r as PluginAgentScope, rt as PluginWorkspace, s as PluginCommandArgument, st as PluginCapabilityCatalog, t as PluginAgentContextContribution, tt as PluginViewMethod, u as PluginCommandContribution, ut as PluginCapabilityService, v as PluginCommandTransaction, vt as PluginLogQueryRequest, w as PluginExecutionSnapshot, wt as PluginPromptType, x as PluginContributionSnapshot, xt as PluginPromptApi, y as PluginContext, yt as PluginLogQueryResult, z as PluginProcessApi, zt as PluginToolsService } from "./types-2X-_T_W_.js";
|
|
3
3
|
export * from "zod";
|
|
4
|
+
//#region src/publication.d.ts
|
|
5
|
+
interface PublicationContext {
|
|
6
|
+
readonly project: PluginProject;
|
|
7
|
+
readonly process: PluginProcessApi;
|
|
8
|
+
readonly signal?: AbortSignal;
|
|
9
|
+
}
|
|
10
|
+
export declare function readPublicationChanges({ project, process, signal }: PublicationContext, directory: string): Promise<{
|
|
11
|
+
files: string[];
|
|
12
|
+
working: Set<string>;
|
|
13
|
+
partiallyStaged: boolean;
|
|
14
|
+
}>;
|
|
15
|
+
//#endregion
|
|
4
16
|
//#region src/definition.d.ts
|
|
5
17
|
export declare const PLUGIN_API_VERSION = 2;
|
|
6
18
|
type DefinedWorkbasePlugin = Readonly<WorkbasePluginDefinition>;
|
package/dist/index.js
CHANGED
|
@@ -1,35 +1,5 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
export * from "zod";
|
|
3
|
-
//#region src/definition.ts
|
|
4
|
-
const PLUGIN_API_VERSION = 2;
|
|
5
|
-
const PLUGIN_ID_PATTERN = /^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/;
|
|
6
|
-
function definePlugin(definition) {
|
|
7
|
-
validateDefinition(definition);
|
|
8
|
-
return Object.freeze({
|
|
9
|
-
...definition,
|
|
10
|
-
dependencies: Object.freeze([...definition.dependencies ?? []])
|
|
11
|
-
});
|
|
12
|
-
}
|
|
13
|
-
function isDefinedPlugin(value) {
|
|
14
|
-
try {
|
|
15
|
-
validateDefinition(value);
|
|
16
|
-
return true;
|
|
17
|
-
} catch {
|
|
18
|
-
return false;
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
function validateDefinition(definition) {
|
|
22
|
-
if (!isRecord(definition)) throw new TypeError("definePlugin requires a plugin definition object.");
|
|
23
|
-
if (typeof definition.id !== "string" || !PLUGIN_ID_PATTERN.test(definition.id)) throw new TypeError("Plugin id must use lowercase kebab-case.");
|
|
24
|
-
if (typeof definition.setup !== "function") throw new TypeError("Plugin setup must be a function.");
|
|
25
|
-
if (typeof definition.title !== "string" || definition.title.trim() === "") throw new TypeError("Plugin title must be a non-empty string.");
|
|
26
|
-
const dependencies = definition.dependencies ?? [];
|
|
27
|
-
if (!Array.isArray(dependencies) || dependencies.some((id) => typeof id !== "string" || !PLUGIN_ID_PATTERN.test(id) || id === definition.id) || new Set(dependencies).size !== dependencies.length) throw new TypeError("Plugin dependencies must be unique plugin ids and cannot include itself.");
|
|
28
|
-
}
|
|
29
|
-
function isRecord(value) {
|
|
30
|
-
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
31
|
-
}
|
|
32
|
-
//#endregion
|
|
33
3
|
//#region src/types.ts
|
|
34
4
|
let PluginHookId = /* @__PURE__ */ function(PluginHookId) {
|
|
35
5
|
PluginHookId["ProjectReconcile"] = "project.reconcile";
|
|
@@ -121,6 +91,7 @@ let PluginProcessOutputMode = /* @__PURE__ */ function(PluginProcessOutputMode)
|
|
|
121
91
|
let PluginSharedChangeKind = /* @__PURE__ */ function(PluginSharedChangeKind) {
|
|
122
92
|
PluginSharedChangeKind["None"] = "none";
|
|
123
93
|
PluginSharedChangeKind["Files"] = "files";
|
|
94
|
+
PluginSharedChangeKind["Artifacts"] = "artifacts";
|
|
124
95
|
return PluginSharedChangeKind;
|
|
125
96
|
}({});
|
|
126
97
|
let PluginContextExposure = /* @__PURE__ */ function(PluginContextExposure) {
|
|
@@ -134,6 +105,116 @@ let PluginViewMethod = /* @__PURE__ */ function(PluginViewMethod) {
|
|
|
134
105
|
return PluginViewMethod;
|
|
135
106
|
}({});
|
|
136
107
|
//#endregion
|
|
108
|
+
//#region src/publication.ts
|
|
109
|
+
async function readPublicationChanges({ project, process, signal }, directory) {
|
|
110
|
+
const working = /* @__PURE__ */ new Set();
|
|
111
|
+
if (!project.publicationBranch) return {
|
|
112
|
+
files: [],
|
|
113
|
+
working,
|
|
114
|
+
partiallyStaged: false
|
|
115
|
+
};
|
|
116
|
+
const read = async (args, allowMissingAncestor = false) => {
|
|
117
|
+
const result = await process.run({
|
|
118
|
+
program: "git",
|
|
119
|
+
arguments: args,
|
|
120
|
+
currentDirectory: project.root,
|
|
121
|
+
outputMode: "content",
|
|
122
|
+
environment: {
|
|
123
|
+
GIT_OPTIONAL_LOCKS: "0",
|
|
124
|
+
GIT_LITERAL_PATHSPECS: "1",
|
|
125
|
+
GIT_TERMINAL_PROMPT: "0"
|
|
126
|
+
}
|
|
127
|
+
}, signal);
|
|
128
|
+
if (allowMissingAncestor && result.exitCode === 1 && !result.standardError && !result.timedOut && !result.wasCancelled) return "";
|
|
129
|
+
if (result.failed || result.timedOut || result.wasCancelled || result.standardOutputTruncated !== false) throw new Error("无法完整读取文件的发布状态。");
|
|
130
|
+
return result.standardOutput;
|
|
131
|
+
};
|
|
132
|
+
const names = async (args) => (await read([
|
|
133
|
+
...args,
|
|
134
|
+
"--",
|
|
135
|
+
directory
|
|
136
|
+
])).split("\0").filter((file) => file && !file.endsWith("/"));
|
|
137
|
+
const remote = "refs/remotes/origin/" + project.publicationBranch;
|
|
138
|
+
const common = (await read([
|
|
139
|
+
"merge-base",
|
|
140
|
+
"HEAD",
|
|
141
|
+
remote
|
|
142
|
+
], true)).trim();
|
|
143
|
+
const baseline = (await read([
|
|
144
|
+
"for-each-ref",
|
|
145
|
+
"--format=%(objectname)",
|
|
146
|
+
`refs/workbase/publications/${project.publicationBranch}/${common || "unrelated"}`
|
|
147
|
+
])).trim() || common;
|
|
148
|
+
if (!baseline) throw new Error("远端分支历史已更换,请先确认团队配置版本。");
|
|
149
|
+
const diff = [
|
|
150
|
+
"diff",
|
|
151
|
+
"--relative",
|
|
152
|
+
"--ignore-submodules=all",
|
|
153
|
+
"--no-renames",
|
|
154
|
+
"--name-only",
|
|
155
|
+
"-z"
|
|
156
|
+
];
|
|
157
|
+
const [unstaged, staged, committed, unequal, untracked] = await Promise.all([
|
|
158
|
+
names(diff),
|
|
159
|
+
names([...diff, "--cached"]),
|
|
160
|
+
names([
|
|
161
|
+
...diff,
|
|
162
|
+
baseline,
|
|
163
|
+
"HEAD"
|
|
164
|
+
]),
|
|
165
|
+
names([
|
|
166
|
+
...diff,
|
|
167
|
+
remote,
|
|
168
|
+
"HEAD"
|
|
169
|
+
]),
|
|
170
|
+
names([
|
|
171
|
+
"ls-files",
|
|
172
|
+
"--others",
|
|
173
|
+
"--exclude-standard",
|
|
174
|
+
"-z"
|
|
175
|
+
])
|
|
176
|
+
]);
|
|
177
|
+
[...unstaged, ...untracked].forEach((file) => working.add(file));
|
|
178
|
+
const partiallyStaged = staged.some((file) => working.has(file));
|
|
179
|
+
staged.forEach((file) => working.add(file));
|
|
180
|
+
const unpublished = new Set(unequal);
|
|
181
|
+
return {
|
|
182
|
+
files: [.../* @__PURE__ */ new Set([...working, ...committed.filter((file) => unpublished.has(file))])].sort(),
|
|
183
|
+
working,
|
|
184
|
+
partiallyStaged
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
//#endregion
|
|
188
|
+
//#region src/definition.ts
|
|
189
|
+
const PLUGIN_API_VERSION = 2;
|
|
190
|
+
const PLUGIN_ID_PATTERN = /^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/;
|
|
191
|
+
function definePlugin(definition) {
|
|
192
|
+
validateDefinition(definition);
|
|
193
|
+
return Object.freeze({
|
|
194
|
+
...definition,
|
|
195
|
+
dependencies: Object.freeze([...definition.dependencies ?? []])
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
function isDefinedPlugin(value) {
|
|
199
|
+
try {
|
|
200
|
+
validateDefinition(value);
|
|
201
|
+
return true;
|
|
202
|
+
} catch {
|
|
203
|
+
return false;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
function validateDefinition(definition) {
|
|
207
|
+
if (!isRecord(definition)) throw new TypeError("definePlugin requires a plugin definition object.");
|
|
208
|
+
if (typeof definition.id !== "string" || !PLUGIN_ID_PATTERN.test(definition.id)) throw new TypeError("Plugin id must use lowercase kebab-case.");
|
|
209
|
+
if (typeof definition.setup !== "function") throw new TypeError("Plugin setup must be a function.");
|
|
210
|
+
if (typeof definition.title !== "string" || definition.title.trim() === "") throw new TypeError("Plugin title must be a non-empty string.");
|
|
211
|
+
const dependencies = definition.dependencies ?? [];
|
|
212
|
+
if (!Array.isArray(dependencies) || dependencies.some((id) => typeof id !== "string" || !PLUGIN_ID_PATTERN.test(id) || id === definition.id) || new Set(dependencies).size !== dependencies.length) throw new TypeError("Plugin dependencies must be unique plugin ids and cannot include itself.");
|
|
213
|
+
}
|
|
214
|
+
function isRecord(value) {
|
|
215
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
216
|
+
}
|
|
217
|
+
//#endregion
|
|
137
218
|
//#region src/Tools.dto.ts
|
|
138
219
|
/** Typed tool-domain contracts shared by the SDK and host bridge. */
|
|
139
220
|
const identifier = z.string().min(1);
|
|
@@ -325,4 +406,4 @@ const outputField = z.discriminatedUnion("type", [
|
|
|
325
406
|
]);
|
|
326
407
|
const workflowContributionSchema = z.union([z.literal(true), z.object({ outputs: z.record(fieldKey, outputField).refine((fields) => Object.keys(fields).length <= 32) }).strict()]);
|
|
327
408
|
//#endregion
|
|
328
|
-
export { ExecutionLogEntryKind, PLUGIN_API_VERSION, PluginAgentScope, PluginCapabilityKind, PluginCommandCategory, PluginCommandEffect, PluginCommandExecutionMode, PluginCommandLogPolicy, PluginCommandTransaction, PluginContextExposure, PluginExecutionStatus, PluginHookId, PluginLifecyclePolicy, PluginLifecycleStatus, PluginProcessOutputMode, PluginRepositoryStatus, PluginSharedChangeKind, PluginViewLayout, PluginViewMethod, definePlugin, executionLogEntrySchema, executionLogRecordSchema, isDefinedPlugin, roleToolEnvironmentSchema, roleToolsAppliedSchema, roleToolsProposalSchema, workflowContributionSchema };
|
|
409
|
+
export { ExecutionLogEntryKind, PLUGIN_API_VERSION, PluginAgentScope, PluginCapabilityKind, PluginCommandCategory, PluginCommandEffect, PluginCommandExecutionMode, PluginCommandLogPolicy, PluginCommandTransaction, PluginContextExposure, PluginExecutionStatus, PluginHookId, PluginLifecyclePolicy, PluginLifecycleStatus, PluginProcessOutputMode, PluginRepositoryStatus, PluginSharedChangeKind, PluginViewLayout, PluginViewMethod, definePlugin, executionLogEntrySchema, executionLogRecordSchema, isDefinedPlugin, readPublicationChanges, roleToolEnvironmentSchema, roleToolsAppliedSchema, roleToolsProposalSchema, workflowContributionSchema };
|
package/dist/markdown.d.ts
CHANGED
|
@@ -357,6 +357,13 @@ interface PluginHostServices {
|
|
|
357
357
|
readonly tasks: PluginTaskService;
|
|
358
358
|
readonly tools: PluginToolsService;
|
|
359
359
|
readonly workspace: {
|
|
360
|
+
/** Observe plugin-owned inputs during activation. The optional plugin command runs through the host transaction before notifying views. */
|
|
361
|
+
readonly watchFiles?: (targets: readonly {
|
|
362
|
+
directory: string;
|
|
363
|
+
pattern?: string;
|
|
364
|
+
recursive?: boolean;
|
|
365
|
+
gitMetadata?: boolean;
|
|
366
|
+
}[], refreshCommandId?: string) => () => void;
|
|
360
367
|
/** Notifies the host to refresh one bound repository after local writes, including partial failures. */
|
|
361
368
|
readonly notifyRepositoryChanged: (repositoryId: string) => Promise<void>;
|
|
362
369
|
/** Checks committed code against the configured collaboration branches without closing the workspace. */
|
|
@@ -480,6 +487,8 @@ interface PluginDisposable {
|
|
|
480
487
|
readonly dispose: () => void;
|
|
481
488
|
}
|
|
482
489
|
interface PluginProject {
|
|
490
|
+
/** Configured team publication branch. Local projects have no publication destination. */
|
|
491
|
+
readonly publicationBranch?: string | null;
|
|
483
492
|
readonly id: string;
|
|
484
493
|
readonly root: string;
|
|
485
494
|
readonly workbaseRoot: string;
|
|
@@ -553,13 +562,14 @@ interface PluginInvocationContext {
|
|
|
553
562
|
}
|
|
554
563
|
declare enum PluginSharedChangeKind {
|
|
555
564
|
None = "none",
|
|
556
|
-
Files = "files"
|
|
565
|
+
Files = "files",
|
|
566
|
+
Artifacts = "artifacts"
|
|
557
567
|
}
|
|
558
568
|
/** Finite files relative to project.workbaseRoot; workspace files are local. */
|
|
559
569
|
type PluginSharedChanges = {
|
|
560
570
|
readonly kind: PluginSharedChangeKind.None;
|
|
561
571
|
} | {
|
|
562
|
-
readonly kind: PluginSharedChangeKind.Files;
|
|
572
|
+
readonly kind: PluginSharedChangeKind.Files | PluginSharedChangeKind.Artifacts;
|
|
563
573
|
readonly paths: readonly string[];
|
|
564
574
|
};
|
|
565
575
|
/** Explicit, sanitized business details for the command execution record. */
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
import { h as PluginCommandExecutionResult, w as PluginExecutionSnapshot } from "./types-
|
|
1
|
+
import { Nt as PluginToastLevel, h as PluginCommandExecutionResult, w as PluginExecutionSnapshot } from "./types-2X-_T_W_.js";
|
|
2
2
|
//#region src/ui/types.d.ts
|
|
3
|
-
/**
|
|
4
|
-
* Browser authoring API and transport contracts for Workbase plugin views.
|
|
5
|
-
*/
|
|
6
3
|
type PluginUiPromptType = 'confirm' | 'multi-select' | 'select' | 'text';
|
|
7
4
|
type PluginUiFileSelectionScope = 'project' | 'workspace';
|
|
8
5
|
type PluginUiFileSelectionItemType = 'any' | 'directory' | 'file';
|
|
@@ -38,6 +35,7 @@ interface PluginUiNavigateOptions {
|
|
|
38
35
|
interface PluginUiToastOptions {
|
|
39
36
|
readonly description: string;
|
|
40
37
|
readonly title: string;
|
|
38
|
+
readonly level?: PluginToastLevel;
|
|
41
39
|
}
|
|
42
40
|
interface PluginUiPromptChoice<Value = unknown> {
|
|
43
41
|
readonly label: string;
|
|
@@ -92,6 +90,10 @@ interface PluginUiStatus {
|
|
|
92
90
|
readonly resolve: <Result = unknown>(statusId: string, input: unknown) => Promise<Result>;
|
|
93
91
|
}
|
|
94
92
|
interface PluginUiView {
|
|
93
|
+
/** Report in-memory edits to the navigation for this view instance. */
|
|
94
|
+
readonly setModified: (modified: boolean) => Promise<void>;
|
|
95
|
+
/** Refresh retained data when this plugin's declared files change. */
|
|
96
|
+
readonly onFilesChanged: (refresh: () => void | Promise<unknown>) => () => void;
|
|
95
97
|
readonly call: <Result = unknown>(method: string, input: unknown) => Promise<Result>;
|
|
96
98
|
}
|
|
97
99
|
declare enum PluginDesktopTarget {
|
|
@@ -141,6 +143,7 @@ interface PluginUiHostMethods {
|
|
|
141
143
|
readonly reportFatal: (message: string) => Promise<void>;
|
|
142
144
|
}
|
|
143
145
|
interface PluginUiClientMethods {
|
|
146
|
+
readonly filesChanged: () => Promise<void>;
|
|
144
147
|
readonly executionChanged: (change: PluginUiExecutionChange) => Promise<void>;
|
|
145
148
|
readonly initialize: (payload: unknown) => Promise<void>;
|
|
146
149
|
}
|
package/dist/ui/error-panel.d.ts
CHANGED
package/dist/ui/error-panel.js
CHANGED
|
@@ -1,22 +1,40 @@
|
|
|
1
1
|
import { errorSummary } from "./model.js";
|
|
2
|
-
import { memo, useId } from "react";
|
|
3
|
-
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { memo, useId, useState } from "react";
|
|
3
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
4
4
|
//#region src/ui/PluginErrorPanel.tsx
|
|
5
5
|
/** 宿主与插件共用的错误展示,保留可见原因并折叠技术详情,不执行业务恢复。 */
|
|
6
|
-
const PluginErrorPanel = memo(function PluginErrorPanel(
|
|
6
|
+
const PluginErrorPanel = memo(function PluginErrorPanel(props) {
|
|
7
|
+
return /* @__PURE__ */ jsx(ErrorDetails, { ...props }, JSON.stringify([
|
|
8
|
+
props.title,
|
|
9
|
+
props.error,
|
|
10
|
+
props.technicalDetails
|
|
11
|
+
]));
|
|
12
|
+
});
|
|
13
|
+
function ErrorDetails({ title, error, scope, recovery, technicalDetails = error, isDismissible = false, children, className, ...attributes }) {
|
|
7
14
|
const headingId = useId();
|
|
15
|
+
const [closed, setClosed] = useState(false);
|
|
16
|
+
if (closed && isDismissible) return null;
|
|
8
17
|
return /* @__PURE__ */ jsxs("section", {
|
|
9
18
|
tabIndex: 0,
|
|
10
19
|
...attributes,
|
|
11
|
-
role: "alert",
|
|
20
|
+
role: closed ? void 0 : "alert",
|
|
12
21
|
"aria-labelledby": headingId,
|
|
13
22
|
className: ["workbase-plugin-error", className].filter(Boolean).join(" "),
|
|
14
|
-
children: [
|
|
15
|
-
|
|
23
|
+
children: [/* @__PURE__ */ jsxs("header", {
|
|
24
|
+
className: "workbase-error-header",
|
|
25
|
+
children: [/* @__PURE__ */ jsx("h3", {
|
|
16
26
|
className: "workbase-error-title",
|
|
17
27
|
id: headingId,
|
|
18
28
|
children: title
|
|
19
|
-
}),
|
|
29
|
+
}), /* @__PURE__ */ jsx("button", {
|
|
30
|
+
type: "button",
|
|
31
|
+
className: "workbase-error-toggle",
|
|
32
|
+
"aria-label": closed ? "查看错误详情" : "关闭错误提示",
|
|
33
|
+
"aria-expanded": isDismissible ? void 0 : !closed,
|
|
34
|
+
onClick: () => setClosed(!closed),
|
|
35
|
+
children: closed ? "查看错误详情" : "关闭"
|
|
36
|
+
})]
|
|
37
|
+
}), !closed && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
20
38
|
/* @__PURE__ */ jsx("p", {
|
|
21
39
|
className: "workbase-error-cause",
|
|
22
40
|
children: errorSummary(error)
|
|
@@ -37,8 +55,8 @@ const PluginErrorPanel = memo(function PluginErrorPanel({ title, error, scope, r
|
|
|
37
55
|
className: "workbase-error-actions",
|
|
38
56
|
children
|
|
39
57
|
}) : null
|
|
40
|
-
]
|
|
58
|
+
] })]
|
|
41
59
|
});
|
|
42
|
-
}
|
|
60
|
+
}
|
|
43
61
|
//#endregion
|
|
44
62
|
export { PluginErrorPanel };
|
package/dist/ui/execution-log.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { PluginErrorPanel } from "./error-panel.js";
|
|
1
2
|
import { memo, useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
2
3
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
4
|
import Markdown from "react-markdown";
|
|
@@ -222,6 +223,8 @@ const CLOCK = new Intl.DateTimeFormat("zh-CN", {
|
|
|
222
223
|
hour12: false
|
|
223
224
|
});
|
|
224
225
|
const RECENT_ENTRY_LIMIT = 20;
|
|
226
|
+
const COPY_SUCCESS_MESSAGE = "已复制";
|
|
227
|
+
const COPY_CONFIRMATION_MS = 2e3;
|
|
225
228
|
const LATEST_SCROLL_THRESHOLD = 24;
|
|
226
229
|
const LOG_KIND_LABELS = /* @__PURE__ */ new Map([["question", "提问"], ["answer", "回答"]]);
|
|
227
230
|
const ExecutionLogTimeline = memo(function ExecutionLogTimeline({ entries, record, relatedRecords, display = "full", executionId, limit = RECENT_ENTRY_LIMIT, isLoading, error, onOpenLog }) {
|
|
@@ -259,11 +262,12 @@ const ExecutionLogTimeline = memo(function ExecutionLogTimeline({ entries, recor
|
|
|
259
262
|
"data-display": display,
|
|
260
263
|
"aria-label": isCompact ? "最近执行动态" : "执行日志",
|
|
261
264
|
children: [
|
|
262
|
-
error ? /* @__PURE__ */ jsx(
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
265
|
+
error ? /* @__PURE__ */ jsx(PluginErrorPanel, {
|
|
266
|
+
title: "执行日志读取失败",
|
|
267
|
+
error,
|
|
268
|
+
scope: "当前执行的日志。",
|
|
269
|
+
recovery: "可重新打开日志查看。"
|
|
270
|
+
}, executionId) : null,
|
|
267
271
|
isLoading && !items.length ? /* @__PURE__ */ jsx("p", {
|
|
268
272
|
className: "workbase-log-note",
|
|
269
273
|
role: "status",
|
|
@@ -376,7 +380,7 @@ const LogEvidence = memo(function LogEvidence({ evidence }) {
|
|
|
376
380
|
const handleCopy = useCallback(async () => {
|
|
377
381
|
try {
|
|
378
382
|
await navigator.clipboard.writeText(evidence.map(({ content }) => content).join("\n\n"));
|
|
379
|
-
setCopyState(
|
|
383
|
+
setCopyState(COPY_SUCCESS_MESSAGE);
|
|
380
384
|
} catch {
|
|
381
385
|
setCopyState("复制失败,请选择文本复制");
|
|
382
386
|
}
|
|
@@ -384,6 +388,11 @@ const LogEvidence = memo(function LogEvidence({ evidence }) {
|
|
|
384
388
|
useEffect(() => {
|
|
385
389
|
setCopyState("");
|
|
386
390
|
}, [evidence]);
|
|
391
|
+
useEffect(() => {
|
|
392
|
+
if (copyState !== COPY_SUCCESS_MESSAGE) return;
|
|
393
|
+
const timeout = window.setTimeout(() => setCopyState(""), COPY_CONFIRMATION_MS);
|
|
394
|
+
return () => window.clearTimeout(timeout);
|
|
395
|
+
}, [copyState]);
|
|
387
396
|
return /* @__PURE__ */ jsxs("div", {
|
|
388
397
|
className: "workbase-log-terminal",
|
|
389
398
|
role: "group",
|
|
@@ -404,6 +413,12 @@ const LogEvidence = memo(function LogEvidence({ evidence }) {
|
|
|
404
413
|
role: "status",
|
|
405
414
|
children: copyState
|
|
406
415
|
}),
|
|
416
|
+
copyState && /* @__PURE__ */ jsx("button", {
|
|
417
|
+
type: "button",
|
|
418
|
+
"aria-label": "关闭复制提示",
|
|
419
|
+
onClick: () => setCopyState(""),
|
|
420
|
+
children: "关闭"
|
|
421
|
+
}),
|
|
407
422
|
/* @__PURE__ */ jsx("button", {
|
|
408
423
|
type: "button",
|
|
409
424
|
onClick: handleCopy,
|
package/dist/ui/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { C as PluginUiToastOptions, D as WorkbasePluginUi, E as PluginUiViewIdentity, O as WorkbasePluginUiDefinition, S as PluginUiStatus, T as PluginUiView, _ as PluginUiNavigateOptions, a as PluginUiContextIdentity, b as PluginUiPromptOptions, c as PluginUiDesktopOpenResult, d as PluginUiFileSelectOptions, f as PluginUiFileSelectionItemType, g as PluginUiInitializationPayload, h as PluginUiHostMethods, i as PluginUiCommands, l as PluginUiExecutionChange, m as PluginUiHostError, n as PluginUiClientMethods, o as PluginUiControllerOptions, p as PluginUiFileSelectionScope, r as PluginUiCommandExecuteOptions, s as PluginUiDesktopOpenOptions, t as PluginDesktopTarget, u as PluginUiFileFilter, v as PluginUiOutputOptions, w as PluginUiTransportConnection, x as PluginUiPromptType, y as PluginUiPromptChoice } from "../types-
|
|
1
|
+
import { C as PluginUiToastOptions, D as WorkbasePluginUi, E as PluginUiViewIdentity, O as WorkbasePluginUiDefinition, S as PluginUiStatus, T as PluginUiView, _ as PluginUiNavigateOptions, a as PluginUiContextIdentity, b as PluginUiPromptOptions, c as PluginUiDesktopOpenResult, d as PluginUiFileSelectOptions, f as PluginUiFileSelectionItemType, g as PluginUiInitializationPayload, h as PluginUiHostMethods, i as PluginUiCommands, l as PluginUiExecutionChange, m as PluginUiHostError, n as PluginUiClientMethods, o as PluginUiControllerOptions, p as PluginUiFileSelectionScope, r as PluginUiCommandExecuteOptions, s as PluginUiDesktopOpenOptions, t as PluginDesktopTarget, u as PluginUiFileFilter, v as PluginUiOutputOptions, w as PluginUiTransportConnection, x as PluginUiPromptType, y as PluginUiPromptChoice } from "../types-DXhRV5dI.js";
|
|
2
2
|
//#region src/ui/controller.d.ts
|
|
3
3
|
export declare function createPluginUiController(definition: WorkbasePluginUiDefinition, options: PluginUiControllerOptions): WorkbasePluginUi;
|
|
4
4
|
//#endregion
|
package/dist/ui/index.js
CHANGED
|
@@ -16,21 +16,45 @@ function createPluginUiController(definition, options) {
|
|
|
16
16
|
recoverableHostErrors: /* @__PURE__ */ new WeakSet()
|
|
17
17
|
};
|
|
18
18
|
const executionListeners = /* @__PURE__ */ new Set();
|
|
19
|
-
const
|
|
19
|
+
const fileListeners = /* @__PURE__ */ new Set();
|
|
20
|
+
let initialization = 0;
|
|
21
|
+
let refreshing = false;
|
|
22
|
+
let pending = false;
|
|
23
|
+
const clientMethods = {
|
|
24
|
+
filesChanged: async () => {
|
|
25
|
+
pending = true;
|
|
26
|
+
if (refreshing || initialization || !state.isInitialized) return;
|
|
27
|
+
refreshing = true;
|
|
28
|
+
try {
|
|
29
|
+
while (pending) {
|
|
30
|
+
pending = false;
|
|
31
|
+
await Promise.all([...fileListeners].map((refresh) => refresh()));
|
|
32
|
+
}
|
|
33
|
+
} finally {
|
|
34
|
+
refreshing = false;
|
|
35
|
+
}
|
|
36
|
+
},
|
|
20
37
|
executionChanged: async (change) => {
|
|
21
38
|
if (state.isInitialized) [...executionListeners].forEach((listener) => listener(change));
|
|
22
39
|
},
|
|
23
40
|
initialize: async (payload) => {
|
|
24
41
|
assertInitializationPayload(payload);
|
|
25
42
|
state.isInitialized = true;
|
|
26
|
-
|
|
43
|
+
initialization++;
|
|
44
|
+
try {
|
|
45
|
+
await onInit(payload);
|
|
46
|
+
} finally {
|
|
47
|
+
initialization--;
|
|
48
|
+
}
|
|
49
|
+
if (pending) await clientMethods.filesChanged();
|
|
27
50
|
await waitForPluginUiPaint(targetWindow);
|
|
28
51
|
await reportContentHeight(hostPromise, {
|
|
29
52
|
targetWindow,
|
|
30
53
|
state
|
|
31
54
|
});
|
|
32
55
|
}
|
|
33
|
-
}
|
|
56
|
+
};
|
|
57
|
+
const connection = connectToHost(clientMethods);
|
|
34
58
|
const hostPromise = connection.promise;
|
|
35
59
|
const request = createHostRequest(hostPromise, state);
|
|
36
60
|
bindPluginUiLifecycle({
|
|
@@ -52,9 +76,16 @@ function createPluginUiController(definition, options) {
|
|
|
52
76
|
await request("command.subscribe", { enabled: false });
|
|
53
77
|
};
|
|
54
78
|
};
|
|
79
|
+
const onFilesChanged = (refresh) => {
|
|
80
|
+
fileListeners.add(refresh);
|
|
81
|
+
return () => {
|
|
82
|
+
fileListeners.delete(refresh);
|
|
83
|
+
};
|
|
84
|
+
};
|
|
55
85
|
return createPluginUiApi(request, {
|
|
56
86
|
targetWindow,
|
|
57
|
-
subscribe
|
|
87
|
+
subscribe,
|
|
88
|
+
onFilesChanged
|
|
58
89
|
});
|
|
59
90
|
}
|
|
60
91
|
function createHostRequest(hostPromise, state) {
|
|
@@ -73,7 +104,7 @@ function createHostError(response) {
|
|
|
73
104
|
const code = typeof responseError?.code === "string" ? responseError.code : "host_error";
|
|
74
105
|
return Object.assign(new Error(message), { code });
|
|
75
106
|
}
|
|
76
|
-
function createPluginUiApi(request, { targetWindow, subscribe }) {
|
|
107
|
+
function createPluginUiApi(request, { targetWindow, subscribe, onFilesChanged }) {
|
|
77
108
|
const commands = Object.freeze({
|
|
78
109
|
subscribe,
|
|
79
110
|
reply: (executionId) => request("command.reply", { executionId }),
|
|
@@ -97,10 +128,14 @@ function createPluginUiApi(request, { targetWindow, subscribe }) {
|
|
|
97
128
|
input,
|
|
98
129
|
statusId
|
|
99
130
|
}) });
|
|
100
|
-
const view = Object.freeze({
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
131
|
+
const view = Object.freeze({
|
|
132
|
+
onFilesChanged,
|
|
133
|
+
setModified: (modified) => request("view.modified", modified),
|
|
134
|
+
call: (method, input) => request("view.call", {
|
|
135
|
+
input,
|
|
136
|
+
method
|
|
137
|
+
})
|
|
138
|
+
});
|
|
104
139
|
return Object.freeze({
|
|
105
140
|
dismiss: () => request("interaction.dismiss", {}),
|
|
106
141
|
respond: (value) => request("interaction.respond", { value }),
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { PluginErrorPanel } from "./error-panel.js";
|
|
1
2
|
import { memo, useCallback, useEffect, useId, useRef, useState } from "react";
|
|
2
3
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
4
|
//#region src/ui/MarkdownEditor.tsx
|
|
@@ -238,14 +239,16 @@ const MarkdownEditor = memo(function MarkdownEditor({ value, onChange, label, na
|
|
|
238
239
|
id: labelId,
|
|
239
240
|
children: label
|
|
240
241
|
}),
|
|
241
|
-
error ? /* @__PURE__ */
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
242
|
+
error ? /* @__PURE__ */ jsx(PluginErrorPanel, {
|
|
243
|
+
title: "编辑器加载失败",
|
|
244
|
+
error,
|
|
245
|
+
scope: "当前文档的富文本编辑。",
|
|
246
|
+
recovery: "可继续编辑源码,或重新加载编辑器。",
|
|
247
|
+
children: /* @__PURE__ */ jsx("button", {
|
|
245
248
|
type: "button",
|
|
246
249
|
onClick: handleRetry,
|
|
247
250
|
children: "重试"
|
|
248
|
-
})
|
|
251
|
+
})
|
|
249
252
|
}) : null,
|
|
250
253
|
validationError ? /* @__PURE__ */ jsx("p", {
|
|
251
254
|
role: "alert",
|
|
@@ -135,11 +135,20 @@ function MarkdownLinkBoundary({ host, children }) {
|
|
|
135
135
|
error ? /* @__PURE__ */ jsxs("p", {
|
|
136
136
|
role: "alert",
|
|
137
137
|
className: "markdown-link-error",
|
|
138
|
-
children: [
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
138
|
+
children: [
|
|
139
|
+
error,
|
|
140
|
+
request ? /* @__PURE__ */ jsx("button", {
|
|
141
|
+
type: "button",
|
|
142
|
+
onClick: handleRetry,
|
|
143
|
+
children: "重试打开"
|
|
144
|
+
}) : null,
|
|
145
|
+
/* @__PURE__ */ jsx("button", {
|
|
146
|
+
type: "button",
|
|
147
|
+
"aria-label": "关闭错误提示",
|
|
148
|
+
onClick: () => setError(""),
|
|
149
|
+
children: "关闭"
|
|
150
|
+
})
|
|
151
|
+
]
|
|
143
152
|
}) : null,
|
|
144
153
|
isOpeningWebsite ? /* @__PURE__ */ jsx("p", {
|
|
145
154
|
role: "status",
|
package/dist/ui/model.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import { C as PluginUiToastOptions, D as WorkbasePluginUi } from "../types-DXhRV5dI.js";
|
|
1
2
|
//#region src/ui/model.d.ts
|
|
2
|
-
/**
|
|
3
|
-
|
|
4
|
-
*/
|
|
3
|
+
/** A notification transport failure must not turn a completed operation into a failed one. */
|
|
4
|
+
export declare function showOperationToast(host: Pick<WorkbasePluginUi, "showToast">, options: PluginUiToastOptions): void;
|
|
5
5
|
export interface PluginActionOutput {
|
|
6
6
|
readonly content: string;
|
|
7
7
|
readonly status: "completed" | "failed";
|
package/dist/ui/model.js
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
//#region src/ui/model.ts
|
|
2
|
+
/** A notification transport failure must not turn a completed operation into a failed one. */
|
|
3
|
+
function showOperationToast(host, options) {
|
|
4
|
+
host.showToast(options).catch((error) => console.warn("无法显示插件通知。", error));
|
|
5
|
+
}
|
|
2
6
|
let ConfigurationMode = /* @__PURE__ */ function(ConfigurationMode) {
|
|
3
7
|
ConfigurationMode["View"] = "view";
|
|
4
8
|
ConfigurationMode["Edit"] = "edit";
|
|
@@ -50,4 +54,4 @@ function isRecord(value) {
|
|
|
50
54
|
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
51
55
|
}
|
|
52
56
|
//#endregion
|
|
53
|
-
export { ConfigurationMode, TEAM_CONFIGURATION_NOTICE, configurationSavedMessage, errorSummary, formatActionError, formatActionOutput, readableError };
|
|
57
|
+
export { ConfigurationMode, TEAM_CONFIGURATION_NOTICE, configurationSavedMessage, errorSummary, formatActionError, formatActionOutput, readableError, showOperationToast };
|
package/dist/ui/theme.css
CHANGED
|
@@ -241,7 +241,12 @@
|
|
|
241
241
|
scrollbar-width: thin;
|
|
242
242
|
}
|
|
243
243
|
.workbase-plugin-error:focus-visible { outline: 2px solid var(--color-accent); outline-offset: -2px; }
|
|
244
|
-
.workbase-
|
|
244
|
+
.workbase-error-header { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
|
|
245
|
+
.workbase-plugin-error .workbase-error-title { margin: 0; color: var(--color-danger); font-size: 14px; font-weight: 600; line-height: 1.5; }
|
|
246
|
+
.workbase-error-toggle { flex: none; min-height: 24px; padding: 0 4px; color: var(--color-muted); font: inherit; font-size: 12px; background: transparent; border: 0; border-radius: 4px; cursor: pointer; }
|
|
247
|
+
.workbase-error-toggle:hover { color: var(--color-foreground); text-decoration: underline; }
|
|
248
|
+
.workbase-error-toggle:focus-visible { outline: 2px solid var(--color-accent); outline-offset: 2px; }
|
|
249
|
+
.workbase-error-header + .workbase-error-cause { margin-top: 8px; }
|
|
245
250
|
.workbase-plugin-error .workbase-error-cause { margin: 0; color: var(--color-foreground); font-size: 14px; font-weight: 500; line-height: 1.65; white-space: pre-wrap; }
|
|
246
251
|
.workbase-plugin-error .workbase-error-context { margin: 8px 0 0; color: var(--color-foreground); font-size: 12px; font-weight: 400; line-height: 1.65; }
|
|
247
252
|
.workbase-error-context strong { margin-right: 8px; font-weight: 600; }
|