@nimbalyst/extension-sdk 0.2.0 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +20 -0
- package/README.md +32 -0
- package/dist/__tests__/createTextCollabContentAdapter.test.d.ts +2 -0
- package/dist/__tests__/createTextCollabContentAdapter.test.d.ts.map +1 -0
- package/dist/__tests__/createTextCollabContentAdapter.test.js +60 -0
- package/dist/__tests__/externalsPlugin.test.d.ts +2 -0
- package/dist/__tests__/externalsPlugin.test.d.ts.map +1 -0
- package/dist/__tests__/externalsPlugin.test.js +16 -0
- package/dist/__tests__/fileDirectoryTree.test.d.ts +2 -0
- package/dist/__tests__/fileDirectoryTree.test.d.ts.map +1 -0
- package/dist/__tests__/fileDirectoryTree.test.js +54 -0
- package/dist/__tests__/hasSeedableContent.test.d.ts +2 -0
- package/dist/__tests__/hasSeedableContent.test.d.ts.map +1 -0
- package/dist/__tests__/hasSeedableContent.test.js +25 -0
- package/dist/__tests__/manifestValidation.agentProviders.test.d.ts +2 -0
- package/dist/__tests__/manifestValidation.agentProviders.test.d.ts.map +1 -0
- package/dist/__tests__/manifestValidation.agentProviders.test.js +44 -0
- package/dist/agents/AgentProtocol.d.ts +233 -0
- package/dist/agents/AgentProtocol.d.ts.map +1 -0
- package/dist/agents/AgentProtocol.js +23 -0
- package/dist/agents/AgentProtocolHost.d.ts +190 -0
- package/dist/agents/AgentProtocolHost.d.ts.map +1 -0
- package/dist/agents/AgentProtocolHost.js +42 -0
- package/dist/agents/index.d.ts +26 -0
- package/dist/agents/index.d.ts.map +1 -0
- package/dist/agents/index.js +24 -0
- package/dist/collab/createTextCollabContentAdapter.d.ts +26 -0
- package/dist/collab/createTextCollabContentAdapter.d.ts.map +1 -0
- package/dist/collab/createTextCollabContentAdapter.js +79 -0
- package/dist/externalsPlugin.js +10 -0
- package/dist/fileDirectoryTree.d.ts +19 -0
- package/dist/fileDirectoryTree.d.ts.map +1 -0
- package/dist/fileDirectoryTree.js +98 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -0
- package/dist/manifestValidation.d.ts +118 -0
- package/dist/manifestValidation.d.ts.map +1 -0
- package/dist/manifestValidation.js +475 -0
- package/dist/trackerReferences.d.ts +32 -0
- package/dist/trackerReferences.d.ts.map +1 -0
- package/dist/trackerReferences.js +7 -0
- package/dist/types/collab.d.ts +138 -0
- package/dist/types/collab.d.ts.map +1 -0
- package/dist/types/collab.js +1 -0
- package/dist/types/editor.d.ts +81 -0
- package/dist/types/editor.d.ts.map +1 -1
- package/dist/types/editors.d.ts +4 -0
- package/dist/types/editors.d.ts.map +1 -1
- package/dist/types/extension.d.ts +364 -5
- package/dist/types/extension.d.ts.map +1 -1
- package/dist/types/extension.js +11 -1
- package/dist/types/index.d.ts +3 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +3 -0
- package/dist/types/panel.d.ts +50 -0
- package/dist/types/panel.d.ts.map +1 -1
- package/dist/types/permissions.d.ts +119 -0
- package/dist/types/permissions.d.ts.map +1 -0
- package/dist/types/permissions.js +33 -0
- package/dist/types/theme.d.ts +50 -0
- package/dist/types/theme.d.ts.map +1 -1
- package/dist/types/theme.js +7 -1
- package/dist/types/trackerImporter.d.ts +147 -0
- package/dist/types/trackerImporter.d.ts.map +1 -0
- package/dist/types/trackerImporter.js +33 -0
- package/dist/useCollaborativeEditor.d.ts +84 -30
- package/dist/useCollaborativeEditor.d.ts.map +1 -1
- package/dist/useCollaborativeEditor.js +98 -7
- package/dist/validate.browser.d.ts +5 -0
- package/dist/validate.browser.d.ts.map +1 -0
- package/dist/validate.browser.js +27 -0
- package/dist/validate.d.ts +2 -8
- package/dist/validate.d.ts.map +1 -1
- package/dist/validate.js +117 -0
- package/dist/validationTypes.d.ts +9 -0
- package/dist/validationTypes.d.ts.map +1 -0
- package/dist/validationTypes.js +1 -0
- package/package.json +8 -1
|
@@ -55,11 +55,53 @@ function defaultIsEmpty(yDoc) {
|
|
|
55
55
|
// A fully empty Y.Doc encodes to ~2 bytes (header only).
|
|
56
56
|
return Y.encodeStateAsUpdate(yDoc).byteLength <= 2;
|
|
57
57
|
}
|
|
58
|
+
/**
|
|
59
|
+
* Normalize the config to a single internal shape. `codec` (preferred) takes
|
|
60
|
+
* its `isEmpty`/`seed` from the pure codec; the legacy shape keeps the
|
|
61
|
+
* hand-rolled `isEmpty`/`initializeFromContent`. Content is normalized to
|
|
62
|
+
* `string | Uint8Array` for the codec path (the host's `loadInitialContent`
|
|
63
|
+
* still yields `string | ArrayBuffer`).
|
|
64
|
+
*/
|
|
65
|
+
function resolveConfig(config) {
|
|
66
|
+
if ('codec' in config) {
|
|
67
|
+
const { codec, bind, onSeedOutcome } = config;
|
|
68
|
+
return {
|
|
69
|
+
bind,
|
|
70
|
+
isEmpty: (yDoc) => codec.isEmpty(yDoc),
|
|
71
|
+
seed: (yDoc, content) => codec.seedFromFile(yDoc, toCodecSource(content)),
|
|
72
|
+
onSeedOutcome,
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
return {
|
|
76
|
+
bind: config.createBinding,
|
|
77
|
+
isEmpty: config.isEmpty ?? defaultIsEmpty,
|
|
78
|
+
seed: config.initializeFromContent,
|
|
79
|
+
onSeedOutcome: config.onSeedOutcome,
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
function toCodecSource(content) {
|
|
83
|
+
return typeof content === 'string' ? content : new Uint8Array(content);
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* True when `content` can legitimately seed a first-open collaborative doc.
|
|
87
|
+
* Empty/whitespace content must never seed: the host returns '' when it has
|
|
88
|
+
* no bytes for the document (e.g. reopening an already-shared doc), and
|
|
89
|
+
* seeding from that writes a DEFAULT document into the shared room —
|
|
90
|
+
* clobbering the room's real content for every client. Exported for tests.
|
|
91
|
+
*/
|
|
92
|
+
export function hasSeedableContent(content) {
|
|
93
|
+
if (content == null)
|
|
94
|
+
return false;
|
|
95
|
+
if (typeof content === 'string')
|
|
96
|
+
return content.trim().length > 0;
|
|
97
|
+
return content.byteLength > 0;
|
|
98
|
+
}
|
|
58
99
|
export function useCollaborativeEditor(host, config) {
|
|
59
100
|
const isCollaborative = !!host.collaboration;
|
|
60
101
|
const [status, setStatus] = useState(host.collaboration?.getStatus() ?? 'disconnected');
|
|
61
102
|
const [collaborators, setCollaborators] = useState(() => new Map());
|
|
62
103
|
const [binding, setBinding] = useState(null);
|
|
104
|
+
const [seedError, setSeedError] = useState(null);
|
|
63
105
|
// Keep config in a ref so the binding-creation effect doesn't tear down on
|
|
64
106
|
// every render. Hosts pass fresh config objects each render, but the
|
|
65
107
|
// intent is "wire once, keep until the host changes".
|
|
@@ -114,37 +156,86 @@ export function useCollaborativeEditor(host, config) {
|
|
|
114
156
|
return;
|
|
115
157
|
if (collab.getStatus() !== 'connected')
|
|
116
158
|
return;
|
|
117
|
-
const cfg = configRef.current;
|
|
118
|
-
|
|
119
|
-
|
|
159
|
+
const cfg = resolveConfig(configRef.current);
|
|
160
|
+
// NEVER seed when the transport skipped payloads it could not decode:
|
|
161
|
+
// the Y.Doc looking empty then means "content exists but is unreadable
|
|
162
|
+
// on this client", and seeding would write a default document over the
|
|
163
|
+
// real content for every client (the "Untitled map" clobber).
|
|
164
|
+
const undecoded = collab.hasUndecodedContent?.() === true;
|
|
165
|
+
if (!undecoded && cfg.isEmpty(collab.yDoc)) {
|
|
120
166
|
try {
|
|
121
167
|
const content = await collab.loadInitialContent();
|
|
122
168
|
if (cancelled)
|
|
123
169
|
return;
|
|
170
|
+
// NEVER seed from empty content. A host that has no bytes for this
|
|
171
|
+
// document (reopen of an already-shared doc: no in-memory share
|
|
172
|
+
// payload, no file) returns ''/empty -- seeding from that writes a
|
|
173
|
+
// default document into the shared room and clobbers whatever the
|
|
174
|
+
// room's real content is for every client. Fall through to bind:
|
|
175
|
+
// the room content (or a teammate's seed) will populate the doc.
|
|
176
|
+
if (!hasSeedableContent(content)) {
|
|
177
|
+
console.warn('[useCollaborativeEditor] Skipping first-open seed: host returned empty initial content.');
|
|
178
|
+
}
|
|
124
179
|
// Re-check emptiness in case another client seeded while we were
|
|
125
180
|
// awaiting -- they would have raced through the WebSocket and
|
|
126
181
|
// applied their update during our await gap. Avoid double-seeding
|
|
127
182
|
// in that case; CRDT merge would otherwise insert duplicate
|
|
128
183
|
// content unless the seed is fully deterministic.
|
|
129
|
-
if (
|
|
184
|
+
else if (cfg.isEmpty(collab.yDoc)) {
|
|
130
185
|
collab.yDoc.transact(() => {
|
|
131
|
-
cfg.
|
|
186
|
+
cfg.seed(collab.yDoc, content);
|
|
132
187
|
}, COLLAB_INIT_ORIGIN);
|
|
188
|
+
// Durability: the seed the user sees locally must reach the server
|
|
189
|
+
// before this provider can tear down. flushWithAck resolves only
|
|
190
|
+
// after a server-persisted ack; flushLocalState is the deprecated
|
|
191
|
+
// fire-and-forget fallback for older hosts.
|
|
192
|
+
const flushed = collab.flushWithAck
|
|
193
|
+
? await collab.flushWithAck()
|
|
194
|
+
: (await collab.flushLocalState?.(), true);
|
|
195
|
+
if (!flushed) {
|
|
196
|
+
const err = new Error('Seed flush was not confirmed by the server before timeout; content may not have persisted.');
|
|
197
|
+
console.warn('[useCollaborativeEditor]', err.message);
|
|
198
|
+
setSeedError(err);
|
|
199
|
+
collab.reportSeedOutcome?.({ ok: false, error: err });
|
|
200
|
+
cfg.onSeedOutcome?.({ ok: false, error: err });
|
|
201
|
+
}
|
|
202
|
+
else {
|
|
203
|
+
setSeedError(null);
|
|
204
|
+
collab.reportSeedOutcome?.({ ok: true });
|
|
205
|
+
cfg.onSeedOutcome?.({ ok: true });
|
|
206
|
+
}
|
|
133
207
|
}
|
|
134
208
|
}
|
|
135
209
|
catch (err) {
|
|
136
210
|
console.error('[useCollaborativeEditor] Failed to load/seed initial content:', err);
|
|
211
|
+
setSeedError(err);
|
|
212
|
+
collab.reportSeedOutcome?.({ ok: false, error: err });
|
|
213
|
+
cfg.onSeedOutcome?.({ ok: false, error: err });
|
|
137
214
|
// Continue with bind -- the doc may still be usable once another
|
|
138
215
|
// client seeds it.
|
|
139
216
|
}
|
|
140
217
|
}
|
|
141
218
|
if (cancelled)
|
|
142
219
|
return;
|
|
143
|
-
|
|
220
|
+
const created = cfg.bind({
|
|
144
221
|
yDoc: collab.yDoc,
|
|
145
222
|
awareness: collab.awareness,
|
|
146
223
|
user: collab.user,
|
|
147
224
|
});
|
|
225
|
+
const resolved = created instanceof Promise ? await created : created;
|
|
226
|
+
if (cancelled) {
|
|
227
|
+
// Effect unmounted while we were awaiting the extension's
|
|
228
|
+
// imperative API. Destroy the freshly-built handle so any
|
|
229
|
+
// observers/awareness subscriptions inside it get cleaned up.
|
|
230
|
+
try {
|
|
231
|
+
resolved.destroy();
|
|
232
|
+
}
|
|
233
|
+
catch (err) {
|
|
234
|
+
console.error('[useCollaborativeEditor] post-cancel destroy failed:', err);
|
|
235
|
+
}
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
handle = resolved;
|
|
148
239
|
setBinding(handle);
|
|
149
240
|
};
|
|
150
241
|
void tryStart();
|
|
@@ -161,5 +252,5 @@ export function useCollaborativeEditor(host, config) {
|
|
|
161
252
|
setBinding(null);
|
|
162
253
|
};
|
|
163
254
|
}, [host]);
|
|
164
|
-
return { isCollaborative, status, collaborators, binding };
|
|
255
|
+
return { isCollaborative, status, collaborators, binding, seedError };
|
|
165
256
|
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { ValidationResult } from './validationTypes.js';
|
|
2
|
+
export declare function validateExtensionBundle(_distPath: string, _bundleName?: string): Promise<ValidationResult>;
|
|
3
|
+
export declare function printValidationResult(result: ValidationResult): void;
|
|
4
|
+
export type { ValidationResult } from './validationTypes.js';
|
|
5
|
+
//# sourceMappingURL=validate.browser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validate.browser.d.ts","sourceRoot":"","sources":["../src/validate.browser.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAM7D,wBAAsB,uBAAuB,CAC3C,SAAS,EAAE,MAAM,EACjB,WAAW,SAAa,GACvB,OAAO,CAAC,gBAAgB,CAAC,CAM3B;AAED,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,gBAAgB,GAAG,IAAI,CAmBpE;AAED,YAAY,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
const BROWSER_VALIDATION_ERROR = 'validateExtensionBundle() is only available in Node.js build tooling. ' +
|
|
2
|
+
'Import it from a Vite config, build script, or other Node runtime.';
|
|
3
|
+
export async function validateExtensionBundle(_distPath, _bundleName = 'index.js') {
|
|
4
|
+
return {
|
|
5
|
+
valid: false,
|
|
6
|
+
errors: [BROWSER_VALIDATION_ERROR],
|
|
7
|
+
warnings: [],
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
export function printValidationResult(result) {
|
|
11
|
+
if (result.errors.length === 0 && result.warnings.length === 0) {
|
|
12
|
+
console.warn(BROWSER_VALIDATION_ERROR);
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
if (result.errors.length > 0) {
|
|
16
|
+
console.error('Extension bundle validation errors:');
|
|
17
|
+
for (const error of result.errors) {
|
|
18
|
+
console.error(` - ${error}`);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
if (result.warnings.length > 0) {
|
|
22
|
+
console.warn('Extension bundle validation warnings:');
|
|
23
|
+
for (const warning of result.warnings) {
|
|
24
|
+
console.warn(` - ${warning}`);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
package/dist/validate.d.ts
CHANGED
|
@@ -1,11 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
valid: boolean;
|
|
4
|
-
/** Critical errors that will cause runtime failures */
|
|
5
|
-
errors: string[];
|
|
6
|
-
/** Warnings that may cause issues */
|
|
7
|
-
warnings: string[];
|
|
8
|
-
}
|
|
1
|
+
import type { ValidationResult } from './validationTypes.js';
|
|
2
|
+
export type { ValidationResult } from './validationTypes.js';
|
|
9
3
|
/**
|
|
10
4
|
* Validates an extension bundle for common issues.
|
|
11
5
|
*
|
package/dist/validate.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../src/validate.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../src/validate.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAC7D,YAAY,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAE7D;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAsB,uBAAuB,CAC3C,QAAQ,EAAE,MAAM,EAChB,UAAU,SAAa,GACtB,OAAO,CAAC,gBAAgB,CAAC,CAsP3B;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,gBAAgB,GAAG,IAAI,CAmBpE"}
|
package/dist/validate.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import * as fs from 'fs';
|
|
5
5
|
import * as path from 'path';
|
|
6
|
+
import { validateAgentProviders, validateBackendModules, } from './manifestValidation.js';
|
|
6
7
|
/**
|
|
7
8
|
* Validates an extension bundle for common issues.
|
|
8
9
|
*
|
|
@@ -94,6 +95,122 @@ export async function validateExtensionBundle(distPath, bundleName = 'index.js')
|
|
|
94
95
|
warnings.push(`manifest.json "styles" points to ${manifest.styles} but file does not exist`);
|
|
95
96
|
}
|
|
96
97
|
}
|
|
98
|
+
// Validate backendModules if present. These run outside the renderer
|
|
99
|
+
// under a host-managed permission system; malformed declarations would
|
|
100
|
+
// either fail to load at runtime or, worse, declare unknown permission
|
|
101
|
+
// ids the consent prompt can't render. Catch both at build time.
|
|
102
|
+
const backendModulesIssues = validateBackendModules(manifest?.contributions?.backendModules);
|
|
103
|
+
for (const issue of backendModulesIssues) {
|
|
104
|
+
errors.push(issue.message);
|
|
105
|
+
}
|
|
106
|
+
// Also check the declared entry files exist on disk.
|
|
107
|
+
if (Array.isArray(manifest?.contributions?.backendModules)) {
|
|
108
|
+
for (const module of manifest.contributions.backendModules) {
|
|
109
|
+
if (typeof module?.entry === 'string') {
|
|
110
|
+
const entryPath = path.join(path.dirname(manifestPath), module.entry);
|
|
111
|
+
if (!fs.existsSync(entryPath)) {
|
|
112
|
+
errors.push(`backendModules[${module.id ?? '?'}].entry points to ${module.entry} but file does not exist`);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
// Validate aiAgentProviders contributions: id/name/backendModuleId
|
|
118
|
+
// shape, uniqueness, model fields, toolFileLinks keys, and provider
|
|
119
|
+
// count cap. Cross-references contributions.backendModules so a typo
|
|
120
|
+
// in backendModuleId fails the build instead of erroring at runtime.
|
|
121
|
+
const agentProviderIssues = validateAgentProviders(manifest?.contributions?.aiAgentProviders, manifest?.contributions?.backendModules);
|
|
122
|
+
for (const issue of agentProviderIssues) {
|
|
123
|
+
if (issue.severity === 'warning') {
|
|
124
|
+
warnings.push(issue.message);
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
errors.push(issue.message);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
// For each agent provider, verify that the backend module it points at
|
|
131
|
+
// actually exports a usable entry point in the built bundle. The
|
|
132
|
+
// privileged host will either call `activate(context)` (the generic
|
|
133
|
+
// BackendModule contract) or `createAgentProvider(context)` (the
|
|
134
|
+
// agent-provider factory) -- catching missing exports here keeps a
|
|
135
|
+
// broken contribution from reaching the consent prompt.
|
|
136
|
+
if (Array.isArray(manifest?.contributions?.aiAgentProviders)) {
|
|
137
|
+
// Build a quick lookup so the per-provider check below can find the
|
|
138
|
+
// corresponding backend-module entry path without re-scanning the
|
|
139
|
+
// array each time.
|
|
140
|
+
const moduleEntries = new Map();
|
|
141
|
+
if (Array.isArray(manifest?.contributions?.backendModules)) {
|
|
142
|
+
for (const moduleRaw of manifest.contributions.backendModules) {
|
|
143
|
+
const id = moduleRaw?.id;
|
|
144
|
+
const entry = moduleRaw?.entry;
|
|
145
|
+
if (typeof id === 'string' && typeof entry === 'string') {
|
|
146
|
+
moduleEntries.set(id, entry);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
for (const providerRaw of manifest.contributions.aiAgentProviders) {
|
|
151
|
+
const providerId = typeof providerRaw?.id === 'string' ? providerRaw.id : '?';
|
|
152
|
+
const backendModuleId = typeof providerRaw?.backendModuleId === 'string'
|
|
153
|
+
? providerRaw.backendModuleId
|
|
154
|
+
: undefined;
|
|
155
|
+
if (!backendModuleId) {
|
|
156
|
+
// Already reported by validateAgentProviders above; don't
|
|
157
|
+
// duplicate the error here.
|
|
158
|
+
continue;
|
|
159
|
+
}
|
|
160
|
+
const entryRel = moduleEntries.get(backendModuleId);
|
|
161
|
+
if (!entryRel) {
|
|
162
|
+
// Cross-reference error already reported by
|
|
163
|
+
// validateAgentProviders; skip the bundle scan.
|
|
164
|
+
continue;
|
|
165
|
+
}
|
|
166
|
+
const entryAbs = path.join(path.dirname(manifestPath), entryRel);
|
|
167
|
+
if (!fs.existsSync(entryAbs)) {
|
|
168
|
+
// The missing-file error is already raised by the backendModules
|
|
169
|
+
// entry check above; don't pile on with a confusingly worded
|
|
170
|
+
// duplicate. Skip the export scan.
|
|
171
|
+
continue;
|
|
172
|
+
}
|
|
173
|
+
// We deliberately do a textual scan rather than executing the
|
|
174
|
+
// module. The backend module is meant to run inside a privileged
|
|
175
|
+
// worker; loading it inside the build script could trigger side
|
|
176
|
+
// effects (open ports, spawn processes, write disk) that have no
|
|
177
|
+
// business firing during `vite build`. A string check for the
|
|
178
|
+
// known export shapes is enough to catch typos and forgotten
|
|
179
|
+
// exports, which is the failure mode users actually hit.
|
|
180
|
+
let entrySource;
|
|
181
|
+
try {
|
|
182
|
+
entrySource = fs.readFileSync(entryAbs, 'utf8');
|
|
183
|
+
}
|
|
184
|
+
catch (readErr) {
|
|
185
|
+
errors.push(`aiAgentProviders[${providerId}].backendModuleId "${backendModuleId}" ` +
|
|
186
|
+
`points at entry ${entryRel} which exists but could not be read (${String(readErr)}). ` +
|
|
187
|
+
'The validator needs to scan the entry for an activate / createAgentProvider export.');
|
|
188
|
+
continue;
|
|
189
|
+
}
|
|
190
|
+
// Look for either a top-level `export function activate` /
|
|
191
|
+
// `export const activate` / `export { activate }`, or the same
|
|
192
|
+
// shapes for `createAgentProvider`. Bundlers normalize these in
|
|
193
|
+
// varied ways; the union of these patterns covers Vite, esbuild,
|
|
194
|
+
// and tsc output. We do NOT match `exports.activate =` because
|
|
195
|
+
// backend modules ship as ESM; CJS output would have been flagged
|
|
196
|
+
// by the `require(` check earlier in this function anyway.
|
|
197
|
+
const exportPatterns = [
|
|
198
|
+
/export\s+(?:async\s+)?function\s+activate\b/,
|
|
199
|
+
/export\s+(?:const|let|var)\s+activate\b/,
|
|
200
|
+
/export\s*\{[^}]*\bactivate\b[^}]*\}/,
|
|
201
|
+
/export\s+(?:async\s+)?function\s+createAgentProvider\b/,
|
|
202
|
+
/export\s+(?:const|let|var)\s+createAgentProvider\b/,
|
|
203
|
+
/export\s*\{[^}]*\bcreateAgentProvider\b[^}]*\}/,
|
|
204
|
+
];
|
|
205
|
+
const hasExport = exportPatterns.some((p) => p.test(entrySource));
|
|
206
|
+
if (!hasExport) {
|
|
207
|
+
errors.push(`aiAgentProviders[${providerId}].backendModuleId "${backendModuleId}" ` +
|
|
208
|
+
`resolves to ${entryRel}, but the entry file does not appear to export ` +
|
|
209
|
+
'an `activate` or `createAgentProvider` function. The privileged host calls one ' +
|
|
210
|
+
'of these to bring the provider online.');
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
}
|
|
97
214
|
}
|
|
98
215
|
catch (e) {
|
|
99
216
|
errors.push(`Failed to parse manifest.json: ${e}`);
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export interface ValidationResult {
|
|
2
|
+
/** Whether the bundle passed validation */
|
|
3
|
+
valid: boolean;
|
|
4
|
+
/** Critical errors that will cause runtime failures */
|
|
5
|
+
errors: string[];
|
|
6
|
+
/** Warnings that may cause issues */
|
|
7
|
+
warnings: string[];
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=validationTypes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validationTypes.d.ts","sourceRoot":"","sources":["../src/validationTypes.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,gBAAgB;IAC/B,2CAA2C;IAC3C,KAAK,EAAE,OAAO,CAAC;IAEf,uDAAuD;IACvD,MAAM,EAAE,MAAM,EAAE,CAAC;IAEjB,qCAAqC;IACrC,QAAQ,EAAE,MAAM,EAAE,CAAC;CACpB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nimbalyst/extension-sdk",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"description": "SDK for building Nimbalyst extensions",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -13,6 +13,9 @@
|
|
|
13
13
|
},
|
|
14
14
|
"type": "module",
|
|
15
15
|
"sideEffects": false,
|
|
16
|
+
"browser": {
|
|
17
|
+
"./dist/validate.js": "./dist/validate.browser.js"
|
|
18
|
+
},
|
|
16
19
|
"nimbalyst": {
|
|
17
20
|
"minAppVersion": "0.58.5"
|
|
18
21
|
},
|
|
@@ -37,6 +40,10 @@
|
|
|
37
40
|
"./testing": {
|
|
38
41
|
"types": "./dist/testing.d.ts",
|
|
39
42
|
"import": "./dist/testing.js"
|
|
43
|
+
},
|
|
44
|
+
"./file-tree": {
|
|
45
|
+
"types": "./dist/fileDirectoryTree.d.ts",
|
|
46
|
+
"import": "./dist/fileDirectoryTree.js"
|
|
40
47
|
}
|
|
41
48
|
},
|
|
42
49
|
"files": [
|