@openforge-app/plugin-sdk 0.1.0 → 0.2.3
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/LICENSE +21 -0
- package/README.md +32 -0
- package/dist/browserSurfaces.d.ts +78 -0
- package/dist/browserSurfaces.js +17 -0
- package/dist/browserSurfacesTesting.d.ts +60 -0
- package/dist/browserSurfacesTesting.js +240 -0
- package/dist/domain.d.ts +74 -15
- package/dist/domain.js +5 -1
- package/dist/fileIcons.d.ts +6 -0
- package/dist/fileIcons.js +84 -0
- package/dist/frontend.d.ts +5 -2
- package/dist/frontend.js +1 -0
- package/dist/index.d.ts +5 -3
- package/dist/index.js +2 -1
- package/dist/manifest.d.ts +29 -0
- package/dist/manifest.js +37 -0
- package/dist/markdown.d.ts +5 -1
- package/dist/markdown.js +67 -18
- package/dist/openforgePackageMetadataSchema.json +40 -1
- package/dist/pluginIcons.d.ts +7 -0
- package/dist/pluginIcons.js +104 -0
- package/dist/publicUiExports.d.mts +16 -0
- package/dist/publicUiExports.mjs +59 -0
- package/dist/svelteHostRuntimeContract.d.mts +1 -0
- package/dist/svelteHostRuntimeContract.mjs +16 -0
- package/dist/testing/backendServicesFake.d.ts +19 -0
- package/dist/testing/backendServicesFake.js +87 -0
- package/dist/testing/commonApiFake.d.ts +22 -0
- package/dist/testing/commonApiFake.js +274 -0
- package/dist/testing/contracts.d.ts +231 -0
- package/dist/testing/contracts.js +1 -0
- package/dist/testing/frontendContributionFake.d.ts +36 -0
- package/dist/testing/frontendContributionFake.js +195 -0
- package/dist/testing/registryFake.d.ts +40 -0
- package/dist/testing/registryFake.js +124 -0
- package/dist/testing/support.d.ts +40 -0
- package/dist/testing/support.js +242 -0
- package/dist/testing.d.ts +3 -223
- package/dist/testing.js +2 -625
- package/dist/types.d.ts +193 -7
- package/dist/types.js +8 -0
- package/dist/ui/Button.svelte +49 -0
- package/dist/ui/Checkbox.svelte +137 -0
- package/dist/ui/FileTypeIcon.svelte +37 -0
- package/dist/ui/MarkdownContent.svelte +71 -11
- package/dist/ui/Modal.svelte +157 -0
- package/dist/ui/PluginPageHeader.svelte +26 -0
- package/dist/ui/PluginViewState.svelte +76 -0
- package/dist/ui/ResizablePanel.svelte +10 -0
- package/dist/ui/icons/README.md +9 -0
- package/dist/ui/icons/c.svg +1 -0
- package/dist/ui/icons/console.svg +1 -0
- package/dist/ui/icons/cpp.svg +1 -0
- package/dist/ui/icons/csharp.svg +1 -0
- package/dist/ui/icons/css.svg +3 -0
- package/dist/ui/icons/database.svg +1 -0
- package/dist/ui/icons/docker.svg +1 -0
- package/dist/ui/icons/document.svg +4 -0
- package/dist/ui/icons/file.svg +1 -0
- package/dist/ui/icons/folder-open.svg +1 -0
- package/dist/ui/icons/folder.svg +1 -0
- package/dist/ui/icons/git.svg +3 -0
- package/dist/ui/icons/go.svg +1 -0
- package/dist/ui/icons/graphql.svg +20 -0
- package/dist/ui/icons/h.svg +3 -0
- package/dist/ui/icons/html.svg +3 -0
- package/dist/ui/icons/image.svg +3 -0
- package/dist/ui/icons/java.svg +6 -0
- package/dist/ui/icons/javascript.svg +3 -0
- package/dist/ui/icons/json.svg +3 -0
- package/dist/ui/icons/kotlin.svg +1 -0
- package/dist/ui/icons/lock.svg +3 -0
- package/dist/ui/icons/markdown.svg +6 -0
- package/dist/ui/icons/nodejs.svg +6 -0
- package/dist/ui/icons/npm.svg +3 -0
- package/dist/ui/icons/pdf.svg +1 -0
- package/dist/ui/icons/php.svg +1 -0
- package/dist/ui/icons/python.svg +1 -0
- package/dist/ui/icons/react.svg +8 -0
- package/dist/ui/icons/react_ts.svg +8 -0
- package/dist/ui/icons/readme.svg +4 -0
- package/dist/ui/icons/ruby.svg +1 -0
- package/dist/ui/icons/rust.svg +1 -0
- package/dist/ui/icons/sass.svg +3 -0
- package/dist/ui/icons/settings.svg +4 -0
- package/dist/ui/icons/svelte.svg +1 -0
- package/dist/ui/icons/svg.svg +3 -0
- package/dist/ui/icons/swift.svg +1 -0
- package/dist/ui/icons/tune.svg +11 -0
- package/dist/ui/icons/typescript-def.svg +6 -0
- package/dist/ui/icons/typescript.svg +3 -0
- package/dist/ui/icons/vue.svg +1 -0
- package/dist/ui/icons/xml.svg +1 -0
- package/dist/ui/icons/yaml.svg +3 -0
- package/dist/ui/icons/zip.svg +3 -0
- package/dist/vite.js +5 -2
- package/package.json +34 -7
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { type TaskBrowserSurfaceState } from '../browserSurfaces';
|
|
2
|
+
import type { FrontendOpenForgeAPI } from '../types';
|
|
3
|
+
import { type TestingRegistryServices } from './support';
|
|
4
|
+
import type { TestingInjectionPointContribution, TestingTaskStartPrefixProviderContribution, TestingSettingsSectionContribution, TestingTaskPaneTabContribution, TestingTaskUISectionContribution, TestingViewContribution } from './contracts';
|
|
5
|
+
type TestingFrontendContributionApi = Pick<FrontendOpenForgeAPI, 'browserSurfaces' | 'taskLinks' | 'views' | 'taskUI' | 'taskPane' | 'settings' | 'backend' | 'injectionPoints' | 'taskStart'>;
|
|
6
|
+
export declare class TestingFrontendContributionFake {
|
|
7
|
+
private readonly services;
|
|
8
|
+
private readonly invokeBackendMethod;
|
|
9
|
+
private readonly views;
|
|
10
|
+
private readonly taskPaneTabs;
|
|
11
|
+
private readonly taskUISections;
|
|
12
|
+
private readonly settingsSections;
|
|
13
|
+
private readonly injectionPoints;
|
|
14
|
+
private readonly taskStartPrefixProviders;
|
|
15
|
+
private readonly browserSurfaces;
|
|
16
|
+
private taskLinkHandler;
|
|
17
|
+
private api;
|
|
18
|
+
constructor(services: TestingRegistryServices, invokeBackendMethod: (method: string, payload?: unknown) => Promise<unknown>);
|
|
19
|
+
createApi(): TestingFrontendContributionApi;
|
|
20
|
+
setBrowserSurfaceState(taskId: string, id: string, patch: Partial<TaskBrowserSurfaceState>): void;
|
|
21
|
+
getSnapshot(): {
|
|
22
|
+
views: TestingViewContribution[];
|
|
23
|
+
taskPaneTabs: TestingTaskPaneTabContribution[];
|
|
24
|
+
taskUISections: TestingTaskUISectionContribution[];
|
|
25
|
+
settingsSections: TestingSettingsSectionContribution[];
|
|
26
|
+
injectionPoints: TestingInjectionPointContribution[];
|
|
27
|
+
taskStartPrefixProviders: TestingTaskStartPrefixProviderContribution[];
|
|
28
|
+
};
|
|
29
|
+
private registerView;
|
|
30
|
+
private registerTaskPaneTab;
|
|
31
|
+
private registerTaskUISection;
|
|
32
|
+
private registerSettingsSection;
|
|
33
|
+
private registerTaskStartPrefixProvider;
|
|
34
|
+
private registerInjectionPoint;
|
|
35
|
+
}
|
|
36
|
+
export {};
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
import { createTestingBrowserSurfaces } from '../browserSurfacesTesting';
|
|
2
|
+
import { isAllowedBrowserSurfaceUrl } from '../browserSurfaces';
|
|
3
|
+
import { assertFunction, assertTitle, createDisposable, } from './support';
|
|
4
|
+
export class TestingFrontendContributionFake {
|
|
5
|
+
services;
|
|
6
|
+
invokeBackendMethod;
|
|
7
|
+
views = new Map();
|
|
8
|
+
taskPaneTabs = new Map();
|
|
9
|
+
taskUISections = new Map();
|
|
10
|
+
settingsSections = new Map();
|
|
11
|
+
injectionPoints = new Map();
|
|
12
|
+
taskStartPrefixProviders = new Map();
|
|
13
|
+
browserSurfaces;
|
|
14
|
+
taskLinkHandler = null;
|
|
15
|
+
api = null;
|
|
16
|
+
constructor(services, invokeBackendMethod) {
|
|
17
|
+
this.services = services;
|
|
18
|
+
this.invokeBackendMethod = invokeBackendMethod;
|
|
19
|
+
this.browserSurfaces = createTestingBrowserSurfaces(services.calls);
|
|
20
|
+
}
|
|
21
|
+
createApi() {
|
|
22
|
+
if (this.api)
|
|
23
|
+
return this.api;
|
|
24
|
+
const api = {
|
|
25
|
+
browserSurfaces: this.browserSurfaces.api,
|
|
26
|
+
taskLinks: {
|
|
27
|
+
open: async (request) => {
|
|
28
|
+
this.services.calls.taskLinkOpenRequests.push(request);
|
|
29
|
+
if (!isAllowedBrowserSurfaceUrl(request.url)) {
|
|
30
|
+
throw new Error('Task links must use a valid HTTP(S) URL');
|
|
31
|
+
}
|
|
32
|
+
if (this.taskLinkHandler === null) {
|
|
33
|
+
this.services.calls.openUrl.push(request.url);
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
const result = await this.taskLinkHandler(request);
|
|
37
|
+
if (result === 'declined') {
|
|
38
|
+
this.services.calls.openUrl.push(request.url);
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
if (result !== 'handled') {
|
|
42
|
+
throw new Error(`Task link handler returned an invalid result: ${String(result)}`);
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
registerHandler: (handler) => {
|
|
46
|
+
if (this.taskLinkHandler !== null) {
|
|
47
|
+
throw new Error('A Task link handler is already registered');
|
|
48
|
+
}
|
|
49
|
+
this.taskLinkHandler = handler;
|
|
50
|
+
return createDisposable(() => {
|
|
51
|
+
if (this.taskLinkHandler === handler)
|
|
52
|
+
this.taskLinkHandler = null;
|
|
53
|
+
});
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
views: {
|
|
57
|
+
register: (registration) => this.registerView(registration),
|
|
58
|
+
},
|
|
59
|
+
taskUI: {
|
|
60
|
+
registerTab: (registration) => this.registerTaskPaneTab(registration),
|
|
61
|
+
registerSection: (registration) => this.registerTaskUISection(registration),
|
|
62
|
+
},
|
|
63
|
+
taskPane: {
|
|
64
|
+
registerTab: (registration) => this.registerTaskPaneTab(registration),
|
|
65
|
+
},
|
|
66
|
+
settings: {
|
|
67
|
+
registerSection: (registration) => this.registerSettingsSection(registration),
|
|
68
|
+
},
|
|
69
|
+
backend: {
|
|
70
|
+
state: 'ready',
|
|
71
|
+
whenReady: async () => undefined,
|
|
72
|
+
onReady: (handler) => {
|
|
73
|
+
handler();
|
|
74
|
+
return createDisposable(() => undefined);
|
|
75
|
+
},
|
|
76
|
+
invoke: async (method, payload) => this.invokeBackendMethod(method, payload),
|
|
77
|
+
},
|
|
78
|
+
injectionPoints: {
|
|
79
|
+
register: (registration) => this.registerInjectionPoint(registration),
|
|
80
|
+
},
|
|
81
|
+
taskStart: {
|
|
82
|
+
registerPrefixProvider: (registration) => this.registerTaskStartPrefixProvider(registration),
|
|
83
|
+
},
|
|
84
|
+
};
|
|
85
|
+
this.api = api;
|
|
86
|
+
return api;
|
|
87
|
+
}
|
|
88
|
+
setBrowserSurfaceState(taskId, id, patch) {
|
|
89
|
+
this.browserSurfaces.setState(taskId, id, patch);
|
|
90
|
+
}
|
|
91
|
+
getSnapshot() {
|
|
92
|
+
return {
|
|
93
|
+
views: Array.from(this.views.values()),
|
|
94
|
+
taskPaneTabs: Array.from(this.taskPaneTabs.values()),
|
|
95
|
+
taskUISections: Array.from(this.taskUISections.values()),
|
|
96
|
+
settingsSections: Array.from(this.settingsSections.values()),
|
|
97
|
+
injectionPoints: Array.from(this.injectionPoints.values()),
|
|
98
|
+
taskStartPrefixProviders: Array.from(this.taskStartPrefixProviders.values()).sort((left, right) => left.order - right.order || left.id.localeCompare(right.id)),
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
registerView(registration) {
|
|
102
|
+
const qualifiedId = this.services.localQualifiedId('views', registration.id);
|
|
103
|
+
assertTitle('views', registration.title);
|
|
104
|
+
assertFunction('views', 'component', registration.component);
|
|
105
|
+
this.services.claims.claim('views', qualifiedId);
|
|
106
|
+
const contribution = {
|
|
107
|
+
...registration,
|
|
108
|
+
id: registration.id.trim(),
|
|
109
|
+
title: registration.title.trim(),
|
|
110
|
+
qualifiedId,
|
|
111
|
+
pluginId: this.services.pluginId,
|
|
112
|
+
projectId: this.services.projectId,
|
|
113
|
+
};
|
|
114
|
+
this.views.set(qualifiedId, contribution);
|
|
115
|
+
return createDisposable(() => {
|
|
116
|
+
this.views.delete(qualifiedId);
|
|
117
|
+
this.services.claims.release('views', qualifiedId);
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
registerTaskPaneTab(registration) {
|
|
121
|
+
const qualifiedId = this.services.localQualifiedId('taskPane', registration.id);
|
|
122
|
+
assertTitle('taskPane', registration.title);
|
|
123
|
+
assertFunction('taskPane', 'component', registration.component);
|
|
124
|
+
this.services.claims.claim('taskPane', qualifiedId);
|
|
125
|
+
const contribution = {
|
|
126
|
+
...registration,
|
|
127
|
+
id: registration.id.trim(),
|
|
128
|
+
title: registration.title.trim(),
|
|
129
|
+
qualifiedId,
|
|
130
|
+
pluginId: this.services.pluginId,
|
|
131
|
+
projectId: this.services.projectId,
|
|
132
|
+
};
|
|
133
|
+
this.taskPaneTabs.set(qualifiedId, contribution);
|
|
134
|
+
return createDisposable(() => {
|
|
135
|
+
this.taskPaneTabs.delete(qualifiedId);
|
|
136
|
+
this.services.claims.release('taskPane', qualifiedId);
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
registerTaskUISection(registration) {
|
|
140
|
+
const qualifiedId = this.services.localQualifiedId('taskUI', registration.id);
|
|
141
|
+
assertFunction('taskUI', 'component', registration.component);
|
|
142
|
+
this.services.claims.claim('taskUI', qualifiedId);
|
|
143
|
+
const contribution = {
|
|
144
|
+
...registration,
|
|
145
|
+
id: registration.id.trim(),
|
|
146
|
+
qualifiedId,
|
|
147
|
+
pluginId: this.services.pluginId,
|
|
148
|
+
projectId: this.services.projectId,
|
|
149
|
+
};
|
|
150
|
+
this.taskUISections.set(qualifiedId, contribution);
|
|
151
|
+
return createDisposable(() => {
|
|
152
|
+
this.taskUISections.delete(qualifiedId);
|
|
153
|
+
this.services.claims.release('taskUI', qualifiedId);
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
registerSettingsSection(registration) {
|
|
157
|
+
const qualifiedId = this.services.localQualifiedId('settings', registration.id);
|
|
158
|
+
assertTitle('settings', registration.title);
|
|
159
|
+
assertFunction('settings', 'component', registration.component);
|
|
160
|
+
this.services.claims.claim('settings', qualifiedId);
|
|
161
|
+
const contribution = {
|
|
162
|
+
...registration,
|
|
163
|
+
id: registration.id.trim(),
|
|
164
|
+
title: registration.title.trim(),
|
|
165
|
+
qualifiedId,
|
|
166
|
+
pluginId: this.services.pluginId,
|
|
167
|
+
projectId: this.services.projectId,
|
|
168
|
+
};
|
|
169
|
+
this.settingsSections.set(qualifiedId, contribution);
|
|
170
|
+
return createDisposable(() => {
|
|
171
|
+
this.settingsSections.delete(qualifiedId);
|
|
172
|
+
this.services.claims.release('settings', qualifiedId);
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
registerTaskStartPrefixProvider(registration) {
|
|
176
|
+
this.taskStartPrefixProviders.set(registration.id, {
|
|
177
|
+
id: registration.id,
|
|
178
|
+
title: registration.title,
|
|
179
|
+
order: registration.order ?? 0,
|
|
180
|
+
provide: (context) => registration.provide(context),
|
|
181
|
+
});
|
|
182
|
+
return createDisposable(() => {
|
|
183
|
+
this.taskStartPrefixProviders.delete(registration.id);
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
registerInjectionPoint(registration) {
|
|
187
|
+
this.injectionPoints.set(registration.id, {
|
|
188
|
+
id: registration.id,
|
|
189
|
+
location: registration.location,
|
|
190
|
+
});
|
|
191
|
+
return createDisposable(() => {
|
|
192
|
+
this.injectionPoints.delete(registration.id);
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { TaskBrowserSurfaceState } from '../browserSurfaces';
|
|
2
|
+
import type { BackendPlugin, BackendPluginContext, FrontendPlugin, FrontendPluginContext, OpenForgePackageMetadata, PluginStorage } from '../types';
|
|
3
|
+
import type { MockBackendOpenForgeAPI, MockFrontendOpenForgeAPI, TestingOpenForgeApiCalls, TestingOpenForgeApiOptions, TestingOpenForgeRegistrySnapshot } from './contracts';
|
|
4
|
+
import { TestingSubscriptionSink } from './support';
|
|
5
|
+
export declare class TestingOpenForgeRegistryFake {
|
|
6
|
+
readonly pluginId: string;
|
|
7
|
+
readonly projectId: string | null;
|
|
8
|
+
readonly taskId: string | null;
|
|
9
|
+
readonly viewId: string;
|
|
10
|
+
readonly packageMetadata: OpenForgePackageMetadata;
|
|
11
|
+
readonly calls: TestingOpenForgeApiCalls;
|
|
12
|
+
readonly storage: PluginStorage;
|
|
13
|
+
readonly frontendSubscriptions: TestingSubscriptionSink;
|
|
14
|
+
readonly backendSubscriptions: TestingSubscriptionSink;
|
|
15
|
+
private readonly services;
|
|
16
|
+
private readonly commonApi;
|
|
17
|
+
private readonly frontendContributions;
|
|
18
|
+
private readonly backendServices;
|
|
19
|
+
private cachedFrontendApi;
|
|
20
|
+
private cachedBackendApi;
|
|
21
|
+
constructor(options?: TestingOpenForgeApiOptions);
|
|
22
|
+
get frontendApi(): MockFrontendOpenForgeAPI;
|
|
23
|
+
get backendApi(): MockBackendOpenForgeAPI;
|
|
24
|
+
get snapshot(): TestingOpenForgeRegistrySnapshot;
|
|
25
|
+
createFrontendApi(): MockFrontendOpenForgeAPI;
|
|
26
|
+
createBackendApi(): MockBackendOpenForgeAPI;
|
|
27
|
+
createFrontendContext(): FrontendPluginContext;
|
|
28
|
+
createBackendContext(): BackendPluginContext;
|
|
29
|
+
activateFrontend(plugin: FrontendPlugin): Promise<void>;
|
|
30
|
+
activateBackend(plugin: BackendPlugin): Promise<void>;
|
|
31
|
+
setBrowserSurfaceState(taskId: string, id: string, patch: Partial<TaskBrowserSurfaceState>): void;
|
|
32
|
+
disposeAll(): Promise<void>;
|
|
33
|
+
getSnapshot(): TestingOpenForgeRegistrySnapshot;
|
|
34
|
+
private createContext;
|
|
35
|
+
}
|
|
36
|
+
export declare function createOpenForgeRegistryFake(options?: TestingOpenForgeApiOptions): TestingOpenForgeRegistryFake;
|
|
37
|
+
export declare function createMockOpenForgeApi(options?: TestingOpenForgeApiOptions): MockFrontendOpenForgeAPI;
|
|
38
|
+
export declare function createMockFrontendOpenForgeApi(options?: TestingOpenForgeApiOptions): MockFrontendOpenForgeAPI;
|
|
39
|
+
export declare function createMockBackendOpenForgeApi(options?: TestingOpenForgeApiOptions): MockBackendOpenForgeAPI;
|
|
40
|
+
export declare function createMockPluginContext(options?: TestingOpenForgeApiOptions): FrontendPluginContext;
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { TestingBackendServicesFake } from './backendServicesFake';
|
|
2
|
+
import { TestingCommonApiFake } from './commonApiFake';
|
|
3
|
+
import { TestingFrontendContributionFake } from './frontendContributionFake';
|
|
4
|
+
import { TestingRegistryServices, TestingSubscriptionSink, } from './support';
|
|
5
|
+
export class TestingOpenForgeRegistryFake {
|
|
6
|
+
pluginId;
|
|
7
|
+
projectId;
|
|
8
|
+
taskId;
|
|
9
|
+
viewId;
|
|
10
|
+
packageMetadata;
|
|
11
|
+
calls;
|
|
12
|
+
storage;
|
|
13
|
+
frontendSubscriptions = new TestingSubscriptionSink();
|
|
14
|
+
backendSubscriptions = new TestingSubscriptionSink();
|
|
15
|
+
services;
|
|
16
|
+
commonApi;
|
|
17
|
+
frontendContributions;
|
|
18
|
+
backendServices;
|
|
19
|
+
cachedFrontendApi = null;
|
|
20
|
+
cachedBackendApi = null;
|
|
21
|
+
constructor(options = {}) {
|
|
22
|
+
this.services = new TestingRegistryServices(options);
|
|
23
|
+
this.pluginId = this.services.pluginId;
|
|
24
|
+
this.projectId = this.services.projectId;
|
|
25
|
+
this.taskId = this.services.taskId;
|
|
26
|
+
this.viewId = this.services.viewId;
|
|
27
|
+
this.packageMetadata = this.services.packageMetadata;
|
|
28
|
+
this.calls = this.services.calls;
|
|
29
|
+
this.storage = this.services.storage;
|
|
30
|
+
this.commonApi = new TestingCommonApiFake(this.services);
|
|
31
|
+
this.backendServices = new TestingBackendServicesFake(this.services);
|
|
32
|
+
this.frontendContributions = new TestingFrontendContributionFake(this.services, (method, payload) => this.backendServices.invokeMethod(method, payload));
|
|
33
|
+
}
|
|
34
|
+
get frontendApi() {
|
|
35
|
+
return this.createFrontendApi();
|
|
36
|
+
}
|
|
37
|
+
get backendApi() {
|
|
38
|
+
return this.createBackendApi();
|
|
39
|
+
}
|
|
40
|
+
get snapshot() {
|
|
41
|
+
return this.getSnapshot();
|
|
42
|
+
}
|
|
43
|
+
createFrontendApi() {
|
|
44
|
+
if (this.cachedFrontendApi)
|
|
45
|
+
return this.cachedFrontendApi;
|
|
46
|
+
const api = {
|
|
47
|
+
...this.commonApi.createApi(),
|
|
48
|
+
...this.frontendContributions.createApi(),
|
|
49
|
+
__testing: {
|
|
50
|
+
calls: this.calls,
|
|
51
|
+
registry: this,
|
|
52
|
+
},
|
|
53
|
+
};
|
|
54
|
+
this.cachedFrontendApi = api;
|
|
55
|
+
return api;
|
|
56
|
+
}
|
|
57
|
+
createBackendApi() {
|
|
58
|
+
if (this.cachedBackendApi)
|
|
59
|
+
return this.cachedBackendApi;
|
|
60
|
+
const api = {
|
|
61
|
+
...this.commonApi.createApi(),
|
|
62
|
+
...this.backendServices.createApi(),
|
|
63
|
+
__testing: {
|
|
64
|
+
calls: this.calls,
|
|
65
|
+
registry: this,
|
|
66
|
+
},
|
|
67
|
+
};
|
|
68
|
+
this.cachedBackendApi = api;
|
|
69
|
+
return api;
|
|
70
|
+
}
|
|
71
|
+
createFrontendContext() {
|
|
72
|
+
return this.createContext(this.frontendSubscriptions);
|
|
73
|
+
}
|
|
74
|
+
createBackendContext() {
|
|
75
|
+
return this.createContext(this.backendSubscriptions);
|
|
76
|
+
}
|
|
77
|
+
async activateFrontend(plugin) {
|
|
78
|
+
await plugin.activate(this.frontendApi, this.createFrontendContext());
|
|
79
|
+
}
|
|
80
|
+
async activateBackend(plugin) {
|
|
81
|
+
const existingServices = this.backendServices.captureBackgroundServiceIds();
|
|
82
|
+
await plugin.activate(this.backendApi, this.createBackendContext());
|
|
83
|
+
await this.backendServices.startNewBackgroundServices(existingServices);
|
|
84
|
+
}
|
|
85
|
+
setBrowserSurfaceState(taskId, id, patch) {
|
|
86
|
+
this.frontendContributions.setBrowserSurfaceState(taskId, id, patch);
|
|
87
|
+
}
|
|
88
|
+
async disposeAll() {
|
|
89
|
+
await this.backendSubscriptions.disposeAll();
|
|
90
|
+
await this.frontendSubscriptions.disposeAll();
|
|
91
|
+
}
|
|
92
|
+
getSnapshot() {
|
|
93
|
+
return {
|
|
94
|
+
pluginId: this.pluginId,
|
|
95
|
+
projectId: this.projectId,
|
|
96
|
+
...this.frontendContributions.getSnapshot(),
|
|
97
|
+
...this.commonApi.getSnapshot(),
|
|
98
|
+
...this.backendServices.getSnapshot(),
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
createContext(subscriptions) {
|
|
102
|
+
return {
|
|
103
|
+
pluginId: this.pluginId,
|
|
104
|
+
apiVersion: 1,
|
|
105
|
+
packageMetadata: this.packageMetadata,
|
|
106
|
+
subscriptions,
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
export function createOpenForgeRegistryFake(options = {}) {
|
|
111
|
+
return new TestingOpenForgeRegistryFake(options);
|
|
112
|
+
}
|
|
113
|
+
export function createMockOpenForgeApi(options = {}) {
|
|
114
|
+
return createMockFrontendOpenForgeApi(options);
|
|
115
|
+
}
|
|
116
|
+
export function createMockFrontendOpenForgeApi(options = {}) {
|
|
117
|
+
return createOpenForgeRegistryFake(options).frontendApi;
|
|
118
|
+
}
|
|
119
|
+
export function createMockBackendOpenForgeApi(options = {}) {
|
|
120
|
+
return createOpenForgeRegistryFake(options).backendApi;
|
|
121
|
+
}
|
|
122
|
+
export function createMockPluginContext(options = {}) {
|
|
123
|
+
return createOpenForgeRegistryFake(options).createFrontendContext();
|
|
124
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { AgentCommandMetadata, CommandDescriptor, Disposable, JsonValue, OpenForgeContextSnapshot, OpenForgeNavigationRequest, OpenForgeNavigationSnapshot, OpenForgePackageMetadata, PluginStorage, StartPromptContribution, SubscriptionSink } from '../types';
|
|
2
|
+
import type { Task } from '../domain';
|
|
3
|
+
import type { TestingCommandContribution, TestingMaybePromise, TestingOpenForgeApiCalls, TestingOpenForgeApiOptions, TestingRuntimeKind } from './contracts';
|
|
4
|
+
export declare function createDisposable(dispose: () => TestingMaybePromise<void>): Disposable;
|
|
5
|
+
export declare class TestingSubscriptionSink implements SubscriptionSink {
|
|
6
|
+
readonly subscriptions: Disposable[];
|
|
7
|
+
add(subscription: Disposable | (() => void)): void;
|
|
8
|
+
disposeAll(): Promise<void>;
|
|
9
|
+
}
|
|
10
|
+
export declare function createTestingCalls(): TestingOpenForgeApiCalls;
|
|
11
|
+
export declare function createMemoryPluginStorage(calls?: TestingOpenForgeApiCalls): PluginStorage;
|
|
12
|
+
export declare function commandDescriptor(command: TestingCommandContribution): CommandDescriptor;
|
|
13
|
+
export declare function normalizeAgentCommandMetadata(metadata: unknown): AgentCommandMetadata | undefined;
|
|
14
|
+
export declare function isJsonValue(value: unknown, seen?: Set<object>): value is JsonValue;
|
|
15
|
+
export declare function assertLocalId(kind: TestingRuntimeKind, id: string): void;
|
|
16
|
+
export declare function assertTitle(kind: TestingRuntimeKind, title: string): void;
|
|
17
|
+
export declare function assertFunction(kind: TestingRuntimeKind, field: string, value: unknown): void;
|
|
18
|
+
export declare class TestingContributionClaims {
|
|
19
|
+
private readonly ids;
|
|
20
|
+
claim(kind: TestingRuntimeKind, qualifiedId: string): void;
|
|
21
|
+
release(kind: TestingRuntimeKind, qualifiedId: string): void;
|
|
22
|
+
private key;
|
|
23
|
+
}
|
|
24
|
+
export declare class TestingRegistryServices {
|
|
25
|
+
readonly pluginId: string;
|
|
26
|
+
readonly projectId: string | null;
|
|
27
|
+
readonly taskId: string | null;
|
|
28
|
+
readonly viewId: string;
|
|
29
|
+
readonly packageMetadata: OpenForgePackageMetadata;
|
|
30
|
+
readonly calls: TestingOpenForgeApiCalls;
|
|
31
|
+
readonly storage: PluginStorage;
|
|
32
|
+
readonly config: Map<string, JsonValue>;
|
|
33
|
+
readonly seededTasks: Task[];
|
|
34
|
+
readonly claims: TestingContributionClaims;
|
|
35
|
+
constructor(options?: TestingOpenForgeApiOptions);
|
|
36
|
+
localQualifiedId(kind: TestingRuntimeKind, id: string): string;
|
|
37
|
+
getContextSnapshot(): OpenForgeContextSnapshot;
|
|
38
|
+
getNavigationSnapshot(overrides?: OpenForgeNavigationRequest): OpenForgeNavigationSnapshot;
|
|
39
|
+
startPromptContributions(projectId: string): StartPromptContribution[];
|
|
40
|
+
}
|
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
export function createDisposable(dispose) {
|
|
2
|
+
let disposed = false;
|
|
3
|
+
return {
|
|
4
|
+
async dispose() {
|
|
5
|
+
if (disposed)
|
|
6
|
+
return;
|
|
7
|
+
disposed = true;
|
|
8
|
+
await dispose();
|
|
9
|
+
},
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
export class TestingSubscriptionSink {
|
|
13
|
+
subscriptions = [];
|
|
14
|
+
add(subscription) {
|
|
15
|
+
if (typeof subscription === 'function') {
|
|
16
|
+
this.subscriptions.push(createDisposable(subscription));
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
if (!subscription || typeof subscription.dispose !== 'function') {
|
|
20
|
+
throw new Error('context.subscriptions.add requires a disposable or cleanup function');
|
|
21
|
+
}
|
|
22
|
+
this.subscriptions.push(subscription);
|
|
23
|
+
}
|
|
24
|
+
async disposeAll() {
|
|
25
|
+
const subscriptions = this.subscriptions.splice(0).reverse();
|
|
26
|
+
for (const subscription of subscriptions)
|
|
27
|
+
await subscription.dispose();
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
export function createTestingCalls() {
|
|
31
|
+
return {
|
|
32
|
+
commandInvocations: [],
|
|
33
|
+
globalCommandInvocations: [],
|
|
34
|
+
backendInvocations: [],
|
|
35
|
+
emittedEvents: [],
|
|
36
|
+
emittedGlobalEvents: [],
|
|
37
|
+
openUrl: [],
|
|
38
|
+
clipboardWrites: [],
|
|
39
|
+
taskLinkOpenRequests: [],
|
|
40
|
+
navigationRequests: [],
|
|
41
|
+
notify: [],
|
|
42
|
+
taskCreations: [],
|
|
43
|
+
taskComposes: [],
|
|
44
|
+
startPromptContributionConfigurations: [],
|
|
45
|
+
taskImplementationStarts: [],
|
|
46
|
+
taskFollowUps: [],
|
|
47
|
+
taskListRequests: [],
|
|
48
|
+
taskStatusUpdates: [],
|
|
49
|
+
configWrites: [],
|
|
50
|
+
fsWrites: [],
|
|
51
|
+
shellSpawns: [],
|
|
52
|
+
shellWrites: [],
|
|
53
|
+
shellResizes: [],
|
|
54
|
+
shellKills: [],
|
|
55
|
+
shellBuffers: [],
|
|
56
|
+
browserSurfaceGetOrCreate: [],
|
|
57
|
+
browserSurfaceAttachments: [],
|
|
58
|
+
browserSurfaceDetaches: [],
|
|
59
|
+
browserSurfaceDestroys: [],
|
|
60
|
+
browserSurfaceNavigations: [],
|
|
61
|
+
browserSurfaceControls: [],
|
|
62
|
+
browserSurfaceSelections: [],
|
|
63
|
+
browserSurfaceFeedbackClears: [],
|
|
64
|
+
browserSurfaceFeedbackReplacements: [],
|
|
65
|
+
browserSurfaceCaptureChecks: [],
|
|
66
|
+
browserSurfaceCaptures: [],
|
|
67
|
+
browserSurfaceCaptureDiscards: [],
|
|
68
|
+
browserSurfaceSessionResets: [],
|
|
69
|
+
storageGets: [],
|
|
70
|
+
storageSets: [],
|
|
71
|
+
storageDeletes: [],
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
export function createMemoryPluginStorage(calls = createTestingCalls()) {
|
|
75
|
+
const values = new Map();
|
|
76
|
+
function scope(scopeKind, scopeId) {
|
|
77
|
+
const prefix = `${scopeKind}:${scopeId ?? ''}:`;
|
|
78
|
+
return {
|
|
79
|
+
async get(key) {
|
|
80
|
+
calls.storageGets.push({ scope: scopeKind, scopeId, key });
|
|
81
|
+
return values.has(`${prefix}${key}`) ? values.get(`${prefix}${key}`) : null;
|
|
82
|
+
},
|
|
83
|
+
async set(key, value) {
|
|
84
|
+
values.set(`${prefix}${key}`, value);
|
|
85
|
+
calls.storageSets.push({ scope: scopeKind, scopeId, key, value });
|
|
86
|
+
},
|
|
87
|
+
async delete(key) {
|
|
88
|
+
values.delete(`${prefix}${key}`);
|
|
89
|
+
calls.storageDeletes.push({ scope: scopeKind, scopeId, key });
|
|
90
|
+
},
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
return {
|
|
94
|
+
global: scope('global', null),
|
|
95
|
+
project: (projectId) => scope('project', projectId),
|
|
96
|
+
task: (taskId) => scope('task', taskId),
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
export function commandDescriptor(command) {
|
|
100
|
+
return {
|
|
101
|
+
id: command.id,
|
|
102
|
+
qualifiedId: command.qualifiedId,
|
|
103
|
+
pluginId: command.pluginId,
|
|
104
|
+
projectId: command.projectId,
|
|
105
|
+
title: command.title,
|
|
106
|
+
icon: command.icon,
|
|
107
|
+
shortcut: command.shortcut,
|
|
108
|
+
discoverable: command.discoverable ?? true,
|
|
109
|
+
input: command.input,
|
|
110
|
+
output: command.output,
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
export function normalizeAgentCommandMetadata(metadata) {
|
|
114
|
+
if (metadata === undefined)
|
|
115
|
+
return undefined;
|
|
116
|
+
if (metadata === null || typeof metadata !== 'object' || Array.isArray(metadata)) {
|
|
117
|
+
throw new Error('commands registration agent metadata must be an object');
|
|
118
|
+
}
|
|
119
|
+
const candidate = metadata;
|
|
120
|
+
if (typeof candidate.description !== 'string' || candidate.description.trim().length === 0) {
|
|
121
|
+
throw new Error('commands registration agent metadata requires a non-empty description');
|
|
122
|
+
}
|
|
123
|
+
if (candidate.examples !== undefined && (!Array.isArray(candidate.examples) || !candidate.examples.every(example => isJsonValue(example)))) {
|
|
124
|
+
throw new Error('commands registration agent metadata examples must contain only JSON values');
|
|
125
|
+
}
|
|
126
|
+
if (candidate.discoverable !== undefined && typeof candidate.discoverable !== 'boolean') {
|
|
127
|
+
throw new Error('commands registration agent metadata discoverable must be a boolean');
|
|
128
|
+
}
|
|
129
|
+
return {
|
|
130
|
+
description: candidate.description.trim(),
|
|
131
|
+
examples: candidate.examples ? [...candidate.examples] : [],
|
|
132
|
+
discoverable: candidate.discoverable ?? true,
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
export function isJsonValue(value, seen = new Set()) {
|
|
136
|
+
if (value === null || typeof value === 'string' || typeof value === 'boolean')
|
|
137
|
+
return true;
|
|
138
|
+
if (typeof value === 'number')
|
|
139
|
+
return Number.isFinite(value);
|
|
140
|
+
if (typeof value !== 'object')
|
|
141
|
+
return false;
|
|
142
|
+
if (seen.has(value))
|
|
143
|
+
return false;
|
|
144
|
+
seen.add(value);
|
|
145
|
+
const valid = Array.isArray(value)
|
|
146
|
+
? value.every(entry => isJsonValue(entry, seen))
|
|
147
|
+
: Object.values(value).every(entry => isJsonValue(entry, seen));
|
|
148
|
+
seen.delete(value);
|
|
149
|
+
return valid;
|
|
150
|
+
}
|
|
151
|
+
export function assertLocalId(kind, id) {
|
|
152
|
+
if (typeof id !== 'string' || id.trim().length === 0) {
|
|
153
|
+
throw new Error(`${kind} registration requires a non-empty id`);
|
|
154
|
+
}
|
|
155
|
+
const trimmed = id.trim();
|
|
156
|
+
if (trimmed.startsWith('openforge.')) {
|
|
157
|
+
throw new Error(`${kind} registration cannot use openforge.* reserved namespace`);
|
|
158
|
+
}
|
|
159
|
+
if (trimmed.includes(':') || trimmed.startsWith('.') || trimmed.endsWith('.') || trimmed.includes('..')) {
|
|
160
|
+
throw new Error(`${kind} registration has invalid id "${trimmed}"`);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
export function assertTitle(kind, title) {
|
|
164
|
+
if (typeof title !== 'string' || title.trim().length === 0) {
|
|
165
|
+
throw new Error(`${kind} registration requires a non-empty title`);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
export function assertFunction(kind, field, value) {
|
|
169
|
+
if (typeof value !== 'function') {
|
|
170
|
+
throw new Error(`${kind} registration requires a ${field} function`);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
export class TestingContributionClaims {
|
|
174
|
+
ids = new Set();
|
|
175
|
+
claim(kind, qualifiedId) {
|
|
176
|
+
const key = this.key(kind, qualifiedId);
|
|
177
|
+
if (this.ids.has(key)) {
|
|
178
|
+
throw new Error(`Duplicate runtime contribution id: ${qualifiedId}`);
|
|
179
|
+
}
|
|
180
|
+
this.ids.add(key);
|
|
181
|
+
}
|
|
182
|
+
release(kind, qualifiedId) {
|
|
183
|
+
this.ids.delete(this.key(kind, qualifiedId));
|
|
184
|
+
}
|
|
185
|
+
key(kind, qualifiedId) {
|
|
186
|
+
return kind === 'commands' ? `commands:${qualifiedId}` : `${kind}:${qualifiedId}`;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
export class TestingRegistryServices {
|
|
190
|
+
pluginId;
|
|
191
|
+
projectId;
|
|
192
|
+
taskId;
|
|
193
|
+
viewId;
|
|
194
|
+
packageMetadata;
|
|
195
|
+
calls;
|
|
196
|
+
storage;
|
|
197
|
+
config = new Map();
|
|
198
|
+
seededTasks;
|
|
199
|
+
claims = new TestingContributionClaims();
|
|
200
|
+
constructor(options = {}) {
|
|
201
|
+
this.pluginId = options.pluginId ?? 'test-plugin';
|
|
202
|
+
this.projectId = options.projectId ?? null;
|
|
203
|
+
this.taskId = options.taskId ?? null;
|
|
204
|
+
this.viewId = options.viewId ?? 'board';
|
|
205
|
+
this.packageMetadata = options.packageMetadata ?? {
|
|
206
|
+
id: this.pluginId,
|
|
207
|
+
apiVersion: 1,
|
|
208
|
+
displayName: this.pluginId,
|
|
209
|
+
description: '',
|
|
210
|
+
};
|
|
211
|
+
this.calls = createTestingCalls();
|
|
212
|
+
this.storage = options.storage ?? createMemoryPluginStorage(this.calls);
|
|
213
|
+
this.seededTasks = options.tasks ?? [];
|
|
214
|
+
}
|
|
215
|
+
localQualifiedId(kind, id) {
|
|
216
|
+
assertLocalId(kind, id);
|
|
217
|
+
return `${this.pluginId}.${id.trim()}`;
|
|
218
|
+
}
|
|
219
|
+
getContextSnapshot() {
|
|
220
|
+
return {
|
|
221
|
+
pluginId: this.pluginId,
|
|
222
|
+
projectId: this.projectId,
|
|
223
|
+
...(this.taskId === null ? {} : { taskId: this.taskId }),
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
getNavigationSnapshot(overrides = {}) {
|
|
227
|
+
return {
|
|
228
|
+
activeProjectId: overrides.projectId ?? this.projectId,
|
|
229
|
+
currentView: overrides.viewId ?? this.viewId,
|
|
230
|
+
selectedTaskId: overrides.taskId ?? this.taskId,
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
startPromptContributions(projectId) {
|
|
234
|
+
const raw = this.config.get(`project:${projectId}:start_prompt_contributions`);
|
|
235
|
+
return Array.isArray(raw)
|
|
236
|
+
? raw.filter((entry) => Boolean(entry)
|
|
237
|
+
&& typeof entry === 'object'
|
|
238
|
+
&& typeof entry.id === 'string'
|
|
239
|
+
&& typeof entry.content === 'string')
|
|
240
|
+
: [];
|
|
241
|
+
}
|
|
242
|
+
}
|