@botpress/adk 1.19.0-beta.14 → 1.19.0-beta.16
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/agent-project/agent-project.d.ts.map +1 -1
- package/dist/agent-project/config-writer.d.ts +1 -1
- package/dist/agent-project/lock-to-dependencies.d.ts +11 -0
- package/dist/agent-project/lock-to-dependencies.d.ts.map +1 -0
- package/dist/agent-project/types.d.ts +0 -5
- package/dist/agent-project/types.d.ts.map +1 -1
- package/dist/agent0/index.js +13 -26
- package/dist/agent0/index.js.map +5 -5
- package/dist/agent0/runtime/client.d.ts.map +1 -1
- package/dist/bot-generator/generator.d.ts +0 -22
- package/dist/bot-generator/generator.d.ts.map +1 -1
- package/dist/bot-generator/plugin-sync.d.ts.map +1 -1
- package/dist/commands/bp-dev-stderr.d.ts +0 -9
- package/dist/commands/bp-dev-stderr.d.ts.map +1 -1
- package/dist/commands/index.d.ts +0 -1
- package/dist/commands/index.d.ts.map +1 -1
- package/dist/dependencies/dependency-manager.d.ts +16 -31
- package/dist/dependencies/dependency-manager.d.ts.map +1 -1
- package/dist/dependencies/errors.d.ts +2 -2
- package/dist/dependencies/errors.d.ts.map +1 -1
- package/dist/dependencies/index.d.ts +4 -5
- package/dist/dependencies/index.d.ts.map +1 -1
- package/dist/dependencies/index.js +1560 -2081
- package/dist/dependencies/index.js.map +26 -34
- package/dist/dependencies/lock-file.d.ts +15 -0
- package/dist/dependencies/lock-file.d.ts.map +1 -0
- package/dist/dependencies/migration.d.ts +0 -19
- package/dist/dependencies/migration.d.ts.map +1 -1
- package/dist/dependencies/resolvers/integration-resolver.d.ts +3 -4
- package/dist/dependencies/resolvers/integration-resolver.d.ts.map +1 -1
- package/dist/dependencies/resolvers/plugin-resolver.d.ts +4 -4
- package/dist/dependencies/resolvers/plugin-resolver.d.ts.map +1 -1
- package/dist/dependencies/types.d.ts +29 -379
- package/dist/dependencies/types.d.ts.map +1 -1
- package/dist/file-watcher/watcher.d.ts.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1764 -2558
- package/dist/index.js.map +36 -44
- package/dist/integrations/config-utils.d.ts +7 -11
- package/dist/integrations/config-utils.d.ts.map +1 -1
- package/dist/integrations/enhanced-cache.d.ts +53 -0
- package/dist/integrations/enhanced-cache.d.ts.map +1 -0
- package/dist/integrations/index.d.ts +2 -1
- package/dist/integrations/index.d.ts.map +1 -1
- package/dist/integrations/manager.d.ts +53 -19
- package/dist/integrations/manager.d.ts.map +1 -1
- package/dist/interfaces/enhanced-cache.d.ts +7 -7
- package/dist/interfaces/enhanced-cache.d.ts.map +1 -1
- package/dist/interfaces/manager.d.ts +17 -11
- package/dist/interfaces/manager.d.ts.map +1 -1
- package/dist/plugins/enhanced-cache.d.ts +53 -0
- package/dist/plugins/enhanced-cache.d.ts.map +1 -0
- package/dist/plugins/index.d.ts +1 -0
- package/dist/plugins/index.d.ts.map +1 -1
- package/dist/plugins/manager.d.ts +53 -16
- package/dist/plugins/manager.d.ts.map +1 -1
- package/dist/preflight/checker.d.ts.map +1 -1
- package/dist/preflight/index.d.ts +0 -1
- package/dist/preflight/index.d.ts.map +1 -1
- package/dist/preflight/types.d.ts +0 -10
- package/dist/preflight/types.d.ts.map +1 -1
- package/dist/runner/script-runner.d.ts.map +1 -1
- package/dist/templates/botpress-desk/evals/index.eval.ts +1 -1
- package/dist/templates/template.config.json +3 -3
- package/dist/utils/ids.d.ts +0 -10
- package/dist/utils/ids.d.ts.map +1 -1
- package/package.json +2 -2
- package/dist/agent-project/dependency-state-to-dependencies.d.ts +0 -11
- package/dist/agent-project/dependency-state-to-dependencies.d.ts.map +0 -1
- package/dist/dependencies/catalog/catalog-service.d.ts +0 -53
- package/dist/dependencies/catalog/catalog-service.d.ts.map +0 -1
- package/dist/dependencies/catalog/client-factory.d.ts +0 -33
- package/dist/dependencies/catalog/client-factory.d.ts.map +0 -1
- package/dist/dependencies/catalog/integration-source.d.ts +0 -34
- package/dist/dependencies/catalog/integration-source.d.ts.map +0 -1
- package/dist/dependencies/catalog/interface-source.d.ts +0 -23
- package/dist/dependencies/catalog/interface-source.d.ts.map +0 -1
- package/dist/dependencies/catalog/plugin-source.d.ts +0 -49
- package/dist/dependencies/catalog/plugin-source.d.ts.map +0 -1
- package/dist/dependencies/catalog/resolution-cache.d.ts +0 -76
- package/dist/dependencies/catalog/resolution-cache.d.ts.map +0 -1
- package/dist/dependencies/legacy-lock-file.d.ts +0 -15
- package/dist/dependencies/legacy-lock-file.d.ts.map +0 -1
- package/dist/dependencies/snapshot-store.d.ts +0 -59
- package/dist/dependencies/snapshot-store.d.ts.map +0 -1
- package/dist/dependencies/status-resolver.d.ts +0 -36
- package/dist/dependencies/status-resolver.d.ts.map +0 -1
- package/dist/dependencies/status.d.ts +0 -214
- package/dist/dependencies/status.d.ts.map +0 -1
- package/dist/preflight/dependency-gate.d.ts +0 -36
- package/dist/preflight/dependency-gate.d.ts.map +0 -1
|
@@ -46,80 +46,32 @@ var __export = (target, all) => {
|
|
|
46
46
|
var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
|
|
47
47
|
var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
48
48
|
|
|
49
|
-
// src/dependencies/json-utils.ts
|
|
50
|
-
function sortKeysDeep(value) {
|
|
51
|
-
if (Array.isArray(value))
|
|
52
|
-
return value.map(sortKeysDeep);
|
|
53
|
-
if (value && typeof value === "object") {
|
|
54
|
-
const obj = value;
|
|
55
|
-
const sorted = {};
|
|
56
|
-
for (const key of Object.keys(obj).sort()) {
|
|
57
|
-
sorted[key] = sortKeysDeep(obj[key]);
|
|
58
|
-
}
|
|
59
|
-
return sorted;
|
|
60
|
-
}
|
|
61
|
-
return value;
|
|
62
|
-
}
|
|
63
|
-
function jsonEqual(a, b) {
|
|
64
|
-
return JSON.stringify(sortKeysDeep(a)) === JSON.stringify(sortKeysDeep(b));
|
|
65
|
-
}
|
|
66
|
-
|
|
67
49
|
// src/dependencies/types.ts
|
|
68
50
|
import { z } from "@botpress/sdk";
|
|
69
|
-
var
|
|
51
|
+
var integrationLockEntrySchema, pluginDependencyMappingSchema, pluginLockEntrySchema, lockFileSchema;
|
|
70
52
|
var init_types = __esm(() => {
|
|
71
|
-
|
|
53
|
+
integrationLockEntrySchema = z.object({
|
|
72
54
|
name: z.string(),
|
|
73
55
|
version: z.string(),
|
|
74
56
|
enabled: z.boolean(),
|
|
75
|
-
config: z.record(z.any()).default({})
|
|
76
|
-
configurationType: z.string().optional(),
|
|
77
|
-
missingFields: z.array(z.string()).optional(),
|
|
78
|
-
authorizationPending: z.boolean().optional()
|
|
57
|
+
config: z.record(z.any()).default({})
|
|
79
58
|
});
|
|
80
59
|
pluginDependencyMappingSchema = z.object({
|
|
81
60
|
integrationAlias: z.string()
|
|
82
61
|
});
|
|
83
|
-
|
|
62
|
+
pluginLockEntrySchema = z.object({
|
|
84
63
|
name: z.string(),
|
|
85
64
|
version: z.string(),
|
|
86
65
|
enabled: z.boolean().default(true),
|
|
87
66
|
config: z.record(z.any()).default({}),
|
|
88
|
-
dependencies: z.record(pluginDependencyMappingSchema).default({})
|
|
89
|
-
missingFields: z.array(z.string()).optional()
|
|
90
|
-
});
|
|
91
|
-
integrationSnapshotEntrySchema = integrationDependencyEntrySchema.extend({
|
|
92
|
-
cloudAlias: z.string().optional(),
|
|
93
|
-
cloudId: z.string().optional(),
|
|
94
|
-
updatedAt: z.string().optional()
|
|
95
|
-
});
|
|
96
|
-
pluginSnapshotEntrySchema = pluginDependencyEntrySchema.extend({
|
|
97
|
-
cloudAlias: z.string().optional(),
|
|
98
|
-
cloudId: z.string().optional(),
|
|
99
|
-
updatedAt: z.string().optional()
|
|
100
|
-
});
|
|
101
|
-
dependencyStateSchema = z.object({
|
|
102
|
-
$schema: z.string().optional(),
|
|
103
|
-
version: z.literal(1),
|
|
104
|
-
env: z.enum(["dev", "prod"]),
|
|
105
|
-
integrations: z.record(integrationDependencyEntrySchema).default({}),
|
|
106
|
-
plugins: z.record(pluginDependencyEntrySchema).default({})
|
|
67
|
+
dependencies: z.record(pluginDependencyMappingSchema).default({})
|
|
107
68
|
});
|
|
108
|
-
|
|
69
|
+
lockFileSchema = z.object({
|
|
109
70
|
$schema: z.string().optional(),
|
|
110
71
|
version: z.literal(1),
|
|
111
72
|
env: z.enum(["dev", "prod"]),
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
botUpdatedAt: z.string().optional(),
|
|
115
|
-
stale: z.boolean().optional(),
|
|
116
|
-
integrations: z.record(integrationSnapshotEntrySchema).default({}),
|
|
117
|
-
plugins: z.record(pluginSnapshotEntrySchema).default({})
|
|
118
|
-
});
|
|
119
|
-
dependencyMigrationMarkerSchema = z.object({
|
|
120
|
-
version: z.literal(1),
|
|
121
|
-
migratedAt: z.string(),
|
|
122
|
-
sources: z.array(z.enum(["lock", "agentConfig", "cloud"]))
|
|
73
|
+
integrations: z.record(integrationLockEntrySchema).default({}),
|
|
74
|
+
plugins: z.record(pluginLockEntrySchema).default({})
|
|
123
75
|
});
|
|
124
76
|
});
|
|
125
77
|
|
|
@@ -173,198 +125,109 @@ var init_errors2 = __esm(() => {
|
|
|
173
125
|
"MISSING_DEPENDENCY",
|
|
174
126
|
"AMBIGUOUS_DEPENDENCY",
|
|
175
127
|
"INTERFACE_NOT_IMPLEMENTED",
|
|
176
|
-
"
|
|
128
|
+
"LOCK_DRIFT",
|
|
177
129
|
"UNINSTALL_REQUIRES_CONFIRMATION",
|
|
178
130
|
"SAME_SOURCE_TARGET",
|
|
179
|
-
"
|
|
131
|
+
"SOURCE_LOCK_MISSING",
|
|
180
132
|
"MIGRATION_CONFLICT",
|
|
181
133
|
"INVALID_CONFIG",
|
|
182
134
|
"BOT_NOT_FOUND",
|
|
183
135
|
"BUILTIN_INTERFACE_IMMUTABLE",
|
|
184
|
-
"PROD_CONFIRMATION_REQUIRED"
|
|
185
|
-
"UNCONFIGURED_DEPENDENCIES"
|
|
136
|
+
"PROD_CONFIRMATION_REQUIRED"
|
|
186
137
|
];
|
|
187
138
|
DependencyError = class DependencyError extends AdkError {
|
|
188
139
|
constructor(opts) {
|
|
189
140
|
super({ ...opts, expected: true });
|
|
190
141
|
}
|
|
191
142
|
};
|
|
192
|
-
DEPENDENCY_WARNING_CODES = [
|
|
143
|
+
DEPENDENCY_WARNING_CODES = [
|
|
144
|
+
"DEPRECATED_COMMAND",
|
|
145
|
+
"MIGRATED_DEPENDENCIES",
|
|
146
|
+
"CLOUD_FETCH_PARTIAL",
|
|
147
|
+
"NO_PROD_BOT"
|
|
148
|
+
];
|
|
193
149
|
});
|
|
194
150
|
|
|
195
|
-
// src/dependencies/
|
|
196
|
-
function
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
return
|
|
208
|
-
}
|
|
209
|
-
function configGatesOnAuthorization(config) {
|
|
210
|
-
return !!(config?.identifier?.required || config?.identifier?.linkTemplateScript);
|
|
211
|
-
}
|
|
212
|
-
function missingRequiredFields(config, values) {
|
|
213
|
-
return schemaRequiredFields(config).filter((field) => values[field] === undefined);
|
|
214
|
-
}
|
|
215
|
-
function unconfigured(missingFields) {
|
|
216
|
-
if (missingFields.length > 0)
|
|
217
|
-
return { state: "unconfigured", missingFields };
|
|
218
|
-
return {
|
|
219
|
-
state: "unconfigured",
|
|
220
|
-
missingFields: [],
|
|
221
|
-
reason: "requires authorization or credentials (configure it in the Control Panel)"
|
|
222
|
-
};
|
|
223
|
-
}
|
|
224
|
-
function authorizationPendingVerdict() {
|
|
225
|
-
return {
|
|
226
|
-
state: "unconfigured",
|
|
227
|
-
missingFields: [],
|
|
228
|
-
reason: "requires authorization — connect it in the Control Panel, then re-deploy"
|
|
229
|
-
};
|
|
230
|
-
}
|
|
231
|
-
function snapshotOnlyVerdict(enabled, persistedMissingFields) {
|
|
232
|
-
if (persistedMissingFields.length > 0)
|
|
233
|
-
return unconfigured(persistedMissingFields);
|
|
234
|
-
if (!enabled)
|
|
235
|
-
return { state: "disabled" };
|
|
236
|
-
return { state: "available" };
|
|
237
|
-
}
|
|
238
|
-
function integrationRequiresConfiguration(definition) {
|
|
239
|
-
const config = definition.configuration;
|
|
240
|
-
if (!config)
|
|
241
|
-
return true;
|
|
242
|
-
return configurationRequiresInput(config);
|
|
243
|
-
}
|
|
244
|
-
function pluginRequiresConfiguration(definition) {
|
|
245
|
-
return schemaRequiredFields(definition.configuration).length > 0;
|
|
246
|
-
}
|
|
247
|
-
function integrationRequiresAuthorization(definition, configurationType) {
|
|
248
|
-
const { config } = resolveActiveConfiguration(definition, configurationType);
|
|
249
|
-
return configGatesOnAuthorization(config);
|
|
250
|
-
}
|
|
251
|
-
function resolveActiveConfiguration(spec, configurationType) {
|
|
252
|
-
if (configurationType && configurationType !== "default") {
|
|
253
|
-
const variant = spec.configurations?.[configurationType];
|
|
254
|
-
if (variant)
|
|
255
|
-
return { config: variant, isDefault: false, variantMissing: false };
|
|
256
|
-
return { config: undefined, isDefault: false, variantMissing: true };
|
|
257
|
-
}
|
|
258
|
-
return { config: spec.configuration, isDefault: true, variantMissing: false };
|
|
259
|
-
}
|
|
260
|
-
function computeIntegrationStatus(input) {
|
|
261
|
-
if (!input.installed)
|
|
262
|
-
return { state: "not_installed" };
|
|
263
|
-
if (!input.spec)
|
|
264
|
-
return { state: "unresolved", reason: "integration definition could not be resolved" };
|
|
265
|
-
const {
|
|
266
|
-
config: activeConfig,
|
|
267
|
-
isDefault,
|
|
268
|
-
variantMissing
|
|
269
|
-
} = resolveActiveConfiguration(input.spec, input.configurationType);
|
|
270
|
-
if (variantMissing) {
|
|
271
|
-
return { state: "unresolved", reason: `configuration variant '${input.configurationType}' not found in spec` };
|
|
272
|
-
}
|
|
273
|
-
const requiresConfig = isDefault ? integrationRequiresConfiguration(input.spec) : configurationRequiresInput(activeConfig);
|
|
274
|
-
const values = input.config ?? {};
|
|
275
|
-
const schemaMissing = requiresConfig ? missingRequiredFields(activeConfig, values) : [];
|
|
276
|
-
let configIncomplete = false;
|
|
277
|
-
if (input.persistedMissingFields !== undefined) {
|
|
278
|
-
configIncomplete = input.persistedMissingFields.length > 0;
|
|
279
|
-
} else if (requiresConfig) {
|
|
280
|
-
if (schemaMissing.length > 0) {
|
|
281
|
-
configIncomplete = true;
|
|
282
|
-
} else if (input.cloudEnabled === false && configGatesOnAuthorization(activeConfig)) {
|
|
283
|
-
configIncomplete = true;
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
if (configIncomplete) {
|
|
287
|
-
const missingFields = input.persistedMissingFields && input.persistedMissingFields.length > 0 ? input.persistedMissingFields : schemaMissing;
|
|
288
|
-
return unconfigured(missingFields);
|
|
289
|
-
}
|
|
290
|
-
if (input.authorizationPending)
|
|
291
|
-
return authorizationPendingVerdict();
|
|
292
|
-
if (!input.enabled || input.cloudEnabled === false)
|
|
293
|
-
return { state: "disabled" };
|
|
294
|
-
return { state: "available" };
|
|
295
|
-
}
|
|
296
|
-
function isAuthorizationPending(input) {
|
|
297
|
-
if (input.cloudFetchErrored)
|
|
298
|
-
return false;
|
|
299
|
-
if (!input.requiresAuthorization)
|
|
300
|
-
return false;
|
|
301
|
-
return !input.cloudAuthorized;
|
|
302
|
-
}
|
|
303
|
-
function transitiveDependencyVerdict(dependencyStatuses) {
|
|
304
|
-
const broken = (dependencyStatuses ?? []).find((dep) => dep.verdict.state !== "available");
|
|
305
|
-
if (!broken)
|
|
306
|
-
return null;
|
|
307
|
-
const state = broken.verdict.state === "disabled" ? "disabled" : "unresolved";
|
|
308
|
-
return { state, reason: `dependency '${broken.alias}' is ${broken.verdict.state}` };
|
|
309
|
-
}
|
|
310
|
-
function mapPluginDependencyStatuses(dependencies, verdictFor) {
|
|
311
|
-
return Object.values(dependencies ?? {}).map((dep) => dep.integrationAlias).filter((alias) => !!alias).map((alias) => ({
|
|
312
|
-
alias,
|
|
313
|
-
verdict: verdictFor(alias) ?? {
|
|
314
|
-
state: "unresolved",
|
|
315
|
-
reason: `backing integration '${alias}' is not declared in the project`
|
|
316
|
-
}
|
|
317
|
-
}));
|
|
318
|
-
}
|
|
319
|
-
function computePluginStatus(input) {
|
|
320
|
-
if (!input.installed)
|
|
321
|
-
return { state: "not_installed" };
|
|
322
|
-
if (!input.spec)
|
|
323
|
-
return { state: "unresolved", reason: "plugin definition could not be resolved" };
|
|
324
|
-
const transitive = transitiveDependencyVerdict(input.dependencyStatuses);
|
|
325
|
-
if (transitive)
|
|
326
|
-
return transitive;
|
|
327
|
-
const requiresConfig = pluginRequiresConfiguration(input.spec);
|
|
328
|
-
const values = input.config ?? {};
|
|
329
|
-
const schemaMissing = requiresConfig ? missingRequiredFields(input.spec.configuration, values) : [];
|
|
330
|
-
let configIncomplete = false;
|
|
331
|
-
if (input.persistedMissingFields !== undefined) {
|
|
332
|
-
configIncomplete = input.persistedMissingFields.length > 0;
|
|
333
|
-
} else if (requiresConfig) {
|
|
334
|
-
configIncomplete = schemaMissing.length > 0;
|
|
335
|
-
}
|
|
336
|
-
if (configIncomplete) {
|
|
337
|
-
const missingFields = input.persistedMissingFields && input.persistedMissingFields.length > 0 ? input.persistedMissingFields : schemaMissing;
|
|
338
|
-
return unconfigured(missingFields);
|
|
339
|
-
}
|
|
340
|
-
if (!input.enabled)
|
|
341
|
-
return { state: "disabled" };
|
|
342
|
-
return { state: "available" };
|
|
343
|
-
}
|
|
344
|
-
function computePluginCarrierStatus(input) {
|
|
345
|
-
if (!input.installed)
|
|
346
|
-
return { state: "not_installed" };
|
|
347
|
-
const transitive = transitiveDependencyVerdict(input.dependencyStatuses);
|
|
348
|
-
if (transitive)
|
|
349
|
-
return transitive;
|
|
350
|
-
if (input.persistedMissingFields && input.persistedMissingFields.length > 0) {
|
|
351
|
-
return unconfigured(input.persistedMissingFields);
|
|
352
|
-
}
|
|
353
|
-
return { state: "available" };
|
|
151
|
+
// src/dependencies/json-utils.ts
|
|
152
|
+
function sortKeysDeep(value) {
|
|
153
|
+
if (Array.isArray(value))
|
|
154
|
+
return value.map(sortKeysDeep);
|
|
155
|
+
if (value && typeof value === "object") {
|
|
156
|
+
const obj = value;
|
|
157
|
+
const sorted = {};
|
|
158
|
+
for (const key of Object.keys(obj).sort()) {
|
|
159
|
+
sorted[key] = sortKeysDeep(obj[key]);
|
|
160
|
+
}
|
|
161
|
+
return sorted;
|
|
162
|
+
}
|
|
163
|
+
return value;
|
|
354
164
|
}
|
|
355
|
-
function
|
|
356
|
-
|
|
357
|
-
return { state: "not_installed" };
|
|
358
|
-
const verdict = snapshotOnlyVerdict(input.enabled, input.missingFields ?? []);
|
|
359
|
-
if (verdict.state === "available" || verdict.state === "disabled") {
|
|
360
|
-
if (input.authorizationPending)
|
|
361
|
-
return authorizationPendingVerdict();
|
|
362
|
-
}
|
|
363
|
-
return verdict;
|
|
165
|
+
function jsonEqual(a, b) {
|
|
166
|
+
return JSON.stringify(sortKeysDeep(a)) === JSON.stringify(sortKeysDeep(b));
|
|
364
167
|
}
|
|
365
|
-
|
|
366
|
-
|
|
168
|
+
|
|
169
|
+
// src/dependencies/lock-file.ts
|
|
170
|
+
import * as path from "path";
|
|
171
|
+
import * as fs from "fs/promises";
|
|
172
|
+
|
|
173
|
+
class LockFile {
|
|
174
|
+
filePath;
|
|
175
|
+
env;
|
|
176
|
+
constructor(opts) {
|
|
177
|
+
this.env = opts.env;
|
|
178
|
+
this.filePath = path.join(opts.projectPath, `dependencies.${opts.env}.lock.json`);
|
|
179
|
+
}
|
|
180
|
+
async read() {
|
|
181
|
+
let raw;
|
|
182
|
+
try {
|
|
183
|
+
raw = await fs.readFile(this.filePath, "utf8");
|
|
184
|
+
} catch (err) {
|
|
185
|
+
if (err.code === "ENOENT") {
|
|
186
|
+
return lockFileSchema.parse({ version: 1, env: this.env });
|
|
187
|
+
}
|
|
188
|
+
throw err;
|
|
189
|
+
}
|
|
190
|
+
const parsed = JSON.parse(raw);
|
|
191
|
+
try {
|
|
192
|
+
return lockFileSchema.parse(parsed);
|
|
193
|
+
} catch (err) {
|
|
194
|
+
throw new DependencyError({
|
|
195
|
+
code: "INVALID_CONFIG",
|
|
196
|
+
message: `Lock file at ${this.filePath} failed schema validation`,
|
|
197
|
+
details: { issues: err.issues ?? String(err) }
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
async write(data) {
|
|
202
|
+
const validated = lockFileSchema.parse(data);
|
|
203
|
+
const serialized = JSON.stringify(sortKeysDeep(validated), null, 2) + `
|
|
204
|
+
`;
|
|
205
|
+
const tmp = `${this.filePath}.tmp-${process.pid}-${Date.now()}`;
|
|
206
|
+
await fs.writeFile(tmp, serialized, "utf8");
|
|
207
|
+
await fs.rename(tmp, this.filePath);
|
|
208
|
+
}
|
|
209
|
+
async exists() {
|
|
210
|
+
try {
|
|
211
|
+
await fs.access(this.filePath);
|
|
212
|
+
return true;
|
|
213
|
+
} catch {
|
|
214
|
+
return false;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
async delete() {
|
|
218
|
+
try {
|
|
219
|
+
await fs.unlink(this.filePath);
|
|
220
|
+
} catch (err) {
|
|
221
|
+
if (err.code === "ENOENT")
|
|
222
|
+
return;
|
|
223
|
+
throw err;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
367
226
|
}
|
|
227
|
+
var init_lock_file = __esm(() => {
|
|
228
|
+
init_types();
|
|
229
|
+
init_errors2();
|
|
230
|
+
});
|
|
368
231
|
|
|
369
232
|
// src/agent-project/types.ts
|
|
370
233
|
import { z as z2 } from "@botpress/sdk";
|
|
@@ -387,8 +250,7 @@ var init_types2 = __esm(() => {
|
|
|
387
250
|
plugins: z2.record(z2.object({
|
|
388
251
|
version: z2.string(),
|
|
389
252
|
config: z2.record(z2.any()).optional(),
|
|
390
|
-
dependencies: z2.record(pluginDependencyMappingSchema2).optional()
|
|
391
|
-
missingFields: z2.array(z2.string()).optional()
|
|
253
|
+
dependencies: z2.record(pluginDependencyMappingSchema2).optional()
|
|
392
254
|
})).optional()
|
|
393
255
|
});
|
|
394
256
|
agentInfoSchema = z2.object({
|
|
@@ -454,24 +316,24 @@ class ValidationErrors {
|
|
|
454
316
|
static isValidationError(error) {
|
|
455
317
|
return error !== null && typeof error === "object" && "$type" in error && error.$type === "ValidationError";
|
|
456
318
|
}
|
|
457
|
-
static directoryNotFound(
|
|
319
|
+
static directoryNotFound(path2) {
|
|
458
320
|
return {
|
|
459
321
|
$type: ValidationErrors.$type,
|
|
460
322
|
code: "DIRECTORY_NOT_FOUND" /* DIRECTORY_NOT_FOUND */,
|
|
461
323
|
severity: "error" /* ERROR */,
|
|
462
|
-
message: `Project directory not found: ${
|
|
324
|
+
message: `Project directory not found: ${path2}`,
|
|
463
325
|
hint: "Ensure the directory exists and you have permission to access it",
|
|
464
|
-
context: { path }
|
|
326
|
+
context: { path: path2 }
|
|
465
327
|
};
|
|
466
328
|
}
|
|
467
|
-
static directoryAccessError(
|
|
329
|
+
static directoryAccessError(path2, error) {
|
|
468
330
|
return {
|
|
469
331
|
$type: ValidationErrors.$type,
|
|
470
332
|
code: "DIRECTORY_ACCESS_ERROR" /* DIRECTORY_ACCESS_ERROR */,
|
|
471
333
|
severity: "error" /* ERROR */,
|
|
472
334
|
message: `Cannot access project directory: ${error}`,
|
|
473
335
|
hint: "Check file system permissions",
|
|
474
|
-
context: { path, error }
|
|
336
|
+
context: { path: path2, error }
|
|
475
337
|
};
|
|
476
338
|
}
|
|
477
339
|
static requiredFileMissing(file) {
|
|
@@ -829,293 +691,66 @@ var init_validation_errors = __esm(() => {
|
|
|
829
691
|
init_types2();
|
|
830
692
|
});
|
|
831
693
|
|
|
832
|
-
// src/
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
694
|
+
// src/constants.ts
|
|
695
|
+
var DEFAULT_API_URL = "https://api.botpress.cloud", BUILTIN_INTERFACES, MAX_TABLE_COLUMNS = 20;
|
|
696
|
+
var init_constants = __esm(() => {
|
|
697
|
+
BUILTIN_INTERFACES = {
|
|
698
|
+
"typing-indicator": "typing-indicator@0.0.3",
|
|
699
|
+
llm: "llm@9.0.0",
|
|
700
|
+
listable: "listable@0.0.2"
|
|
701
|
+
};
|
|
702
|
+
});
|
|
837
703
|
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
static parseIntegrations(dependencies) {
|
|
851
|
-
const integrations = [];
|
|
852
|
-
const errors = [];
|
|
853
|
-
if (!dependencies.integrations) {
|
|
854
|
-
return { integrations, errors };
|
|
855
|
-
}
|
|
856
|
-
for (const [alias, value] of Object.entries(dependencies.integrations)) {
|
|
857
|
-
try {
|
|
858
|
-
if (!isIntegrationAliasValid(alias)) {
|
|
859
|
-
errors.push(ValidationErrors.invalidIntegrationAlias(alias));
|
|
860
|
-
continue;
|
|
861
|
-
}
|
|
862
|
-
const normalized = typeof value === "string" ? { version: value } : value;
|
|
863
|
-
const ref = this.parseIntegrationRef(normalized.version);
|
|
864
|
-
const versionResult = versionSchema.safeParse(ref.version);
|
|
865
|
-
if (!versionResult.success) {
|
|
866
|
-
errors.push(ValidationErrors.invalidVersionFormat(alias, ref.version));
|
|
867
|
-
}
|
|
868
|
-
integrations.push({
|
|
869
|
-
alias,
|
|
870
|
-
ref,
|
|
871
|
-
enabled: "enabled" in normalized ? normalized.enabled : undefined,
|
|
872
|
-
configurationType: "configurationType" in normalized ? normalized.configurationType : undefined,
|
|
873
|
-
config: "config" in normalized ? normalized.config : undefined
|
|
874
|
-
});
|
|
875
|
-
} catch (error) {
|
|
876
|
-
errors.push(ValidationErrors.invalidDependenciesSyntax(`Invalid integration '${alias}': ${error instanceof Error ? error.message : String(error)}`));
|
|
877
|
-
}
|
|
704
|
+
// src/agent-project/agent-resolver.ts
|
|
705
|
+
import fs2 from "fs/promises";
|
|
706
|
+
import path2 from "path";
|
|
707
|
+
async function readLocalInfo(agentPath) {
|
|
708
|
+
const localPath = path2.join(agentPath, "agent.local.json");
|
|
709
|
+
try {
|
|
710
|
+
const localContent = await fs2.readFile(localPath, "utf-8");
|
|
711
|
+
const localData = JSON.parse(localContent);
|
|
712
|
+
const localResult = agentLocalInfoSchema.safeParse(localData);
|
|
713
|
+
if (!localResult.success) {
|
|
714
|
+
const issue = localResult.error.errors[0];
|
|
715
|
+
throw ValidationErrors.warning(`agent.local.json has an invalid field: ${issue?.path.join(".")} — ${issue?.message}`, "agent.local.json");
|
|
878
716
|
}
|
|
879
|
-
return
|
|
880
|
-
}
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
const seen = new Map;
|
|
884
|
-
for (const integration of integrations) {
|
|
885
|
-
const key = integration.ref.fullName;
|
|
886
|
-
const group = seen.get(key) || [];
|
|
887
|
-
group.push(integration);
|
|
888
|
-
seen.set(key, group);
|
|
717
|
+
return localResult.data;
|
|
718
|
+
} catch (error) {
|
|
719
|
+
if (error.code === "ENOENT") {
|
|
720
|
+
return null;
|
|
889
721
|
}
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
const duplicateConfigs = [];
|
|
893
|
-
for (let i = 0;i < group.length; i++) {
|
|
894
|
-
for (let j = i + 1;j < group.length; j++) {
|
|
895
|
-
const configA = JSON.stringify(group[i].config ?? {});
|
|
896
|
-
const configB = JSON.stringify(group[j].config ?? {});
|
|
897
|
-
if (configA === configB) {
|
|
898
|
-
if (!duplicateConfigs.includes(group[i].alias)) {
|
|
899
|
-
duplicateConfigs.push(group[i].alias);
|
|
900
|
-
}
|
|
901
|
-
if (!duplicateConfigs.includes(group[j].alias)) {
|
|
902
|
-
duplicateConfigs.push(group[j].alias);
|
|
903
|
-
}
|
|
904
|
-
}
|
|
905
|
-
}
|
|
906
|
-
}
|
|
907
|
-
if (duplicateConfigs.length > 0) {
|
|
908
|
-
errors.push(ValidationErrors.warning(`Integration '${integrationName}' has aliases with identical configurations: ${duplicateConfigs.join(", ")}. Consider using different configs or removing duplicates.`, "agent.config.ts"));
|
|
909
|
-
}
|
|
910
|
-
}
|
|
722
|
+
if (ValidationErrors.isValidationError(error)) {
|
|
723
|
+
throw error;
|
|
911
724
|
}
|
|
912
|
-
|
|
725
|
+
throw ValidationErrors.warning(`Failed to read agent.local.json: ${error.message}`, "agent.local.json");
|
|
913
726
|
}
|
|
914
727
|
}
|
|
915
|
-
function
|
|
916
|
-
|
|
728
|
+
function applyLocalOverrides(agentInfo, localInfo) {
|
|
729
|
+
if (localInfo.botId) {
|
|
730
|
+
agentInfo.botId = localInfo.botId;
|
|
731
|
+
}
|
|
732
|
+
if (localInfo.workspaceId) {
|
|
733
|
+
agentInfo.workspaceId = localInfo.workspaceId;
|
|
734
|
+
}
|
|
735
|
+
if (localInfo.apiUrl) {
|
|
736
|
+
agentInfo.apiUrl = localInfo.apiUrl;
|
|
737
|
+
}
|
|
738
|
+
if (localInfo.devId) {
|
|
739
|
+
agentInfo.devId = localInfo.devId;
|
|
740
|
+
}
|
|
917
741
|
}
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
}
|
|
929
|
-
|
|
930
|
-
}
|
|
931
|
-
static parsePlugins(dependencies) {
|
|
932
|
-
const plugins = [];
|
|
933
|
-
const errors = [];
|
|
934
|
-
if (!dependencies.plugins) {
|
|
935
|
-
return { plugins, errors };
|
|
936
|
-
}
|
|
937
|
-
for (const [alias, value] of Object.entries(dependencies.plugins)) {
|
|
938
|
-
try {
|
|
939
|
-
if (!isPluginAliasValid(alias)) {
|
|
940
|
-
errors.push(ValidationErrors.invalidPluginAlias(alias));
|
|
941
|
-
continue;
|
|
942
|
-
}
|
|
943
|
-
const ref = this.parsePluginRef(value.version);
|
|
944
|
-
const versionResult = versionSchema.safeParse(ref.version);
|
|
945
|
-
if (!versionResult.success) {
|
|
946
|
-
errors.push(ValidationErrors.invalidPluginVersionFormat(alias, ref.version));
|
|
947
|
-
}
|
|
948
|
-
plugins.push({
|
|
949
|
-
alias,
|
|
950
|
-
ref,
|
|
951
|
-
config: value.config,
|
|
952
|
-
dependencies: value.dependencies
|
|
953
|
-
});
|
|
954
|
-
} catch (error) {
|
|
955
|
-
errors.push(ValidationErrors.invalidDependenciesSyntax(`Invalid plugin '${alias}': ${error instanceof Error ? error.message : String(error)}`));
|
|
956
|
-
}
|
|
957
|
-
}
|
|
958
|
-
return { plugins, errors };
|
|
959
|
-
}
|
|
960
|
-
static validateDependencyReferences(dependencies) {
|
|
961
|
-
const errors = [];
|
|
962
|
-
if (!dependencies.plugins) {
|
|
963
|
-
return errors;
|
|
964
|
-
}
|
|
965
|
-
const integrationAliases = Object.keys(dependencies.integrations || {});
|
|
966
|
-
for (const [alias, pluginConfig] of Object.entries(dependencies.plugins)) {
|
|
967
|
-
if (!pluginConfig.dependencies) {
|
|
968
|
-
continue;
|
|
969
|
-
}
|
|
970
|
-
for (const [_depAlias, depMapping] of Object.entries(pluginConfig.dependencies)) {
|
|
971
|
-
if (!integrationAliases.includes(depMapping.integrationAlias)) {
|
|
972
|
-
errors.push(ValidationErrors.invalidPluginDependency(alias, depMapping.integrationAlias, integrationAliases));
|
|
973
|
-
}
|
|
974
|
-
}
|
|
975
|
-
}
|
|
976
|
-
return errors;
|
|
977
|
-
}
|
|
978
|
-
static checkDuplicates(plugins) {
|
|
979
|
-
const errors = [];
|
|
980
|
-
const seen = new Map;
|
|
981
|
-
for (const plugin of plugins) {
|
|
982
|
-
const key = plugin.ref.fullName;
|
|
983
|
-
const group = seen.get(key) || [];
|
|
984
|
-
group.push(plugin);
|
|
985
|
-
seen.set(key, group);
|
|
986
|
-
}
|
|
987
|
-
for (const [pluginName, group] of seen.entries()) {
|
|
988
|
-
if (group.length > 1) {
|
|
989
|
-
const duplicateConfigs = [];
|
|
990
|
-
for (let i = 0;i < group.length; i++) {
|
|
991
|
-
for (let j = i + 1;j < group.length; j++) {
|
|
992
|
-
const configA = JSON.stringify(group[i].config ?? {});
|
|
993
|
-
const configB = JSON.stringify(group[j].config ?? {});
|
|
994
|
-
if (configA === configB) {
|
|
995
|
-
if (!duplicateConfigs.includes(group[i].alias)) {
|
|
996
|
-
duplicateConfigs.push(group[i].alias);
|
|
997
|
-
}
|
|
998
|
-
if (!duplicateConfigs.includes(group[j].alias)) {
|
|
999
|
-
duplicateConfigs.push(group[j].alias);
|
|
1000
|
-
}
|
|
1001
|
-
}
|
|
1002
|
-
}
|
|
1003
|
-
}
|
|
1004
|
-
if (duplicateConfigs.length > 0) {
|
|
1005
|
-
errors.push(ValidationErrors.warning(`Plugin '${pluginName}' has aliases with identical configurations: ${duplicateConfigs.join(", ")}. Consider using different configs or removing duplicates.`, "agent.config.ts"));
|
|
1006
|
-
}
|
|
1007
|
-
}
|
|
1008
|
-
}
|
|
1009
|
-
return errors;
|
|
1010
|
-
}
|
|
1011
|
-
}
|
|
1012
|
-
var INTEGRATION_ALIAS_MIN_LENGTH = 2, INTEGRATION_ALIAS_MAX_LENGTH = 100, INTEGRATION_ALIAS_REGEX, integrationRefSchema, versionSchema, PLUGIN_ALIAS_MIN_LENGTH = 2, PLUGIN_ALIAS_MAX_LENGTH = 100, PLUGIN_ALIAS_REGEX, pluginRefSchema;
|
|
1013
|
-
var init_dependencies_parser = __esm(() => {
|
|
1014
|
-
init_src();
|
|
1015
|
-
init_validation_errors();
|
|
1016
|
-
INTEGRATION_ALIAS_REGEX = /^(?:[a-z][a-z0-9_-]*\/)?[a-z][a-z0-9_-]*$/;
|
|
1017
|
-
integrationRefSchema = z3.string().transform((val, ctx) => {
|
|
1018
|
-
const match = val.match(/^(?:([^/]+)\/)?([^@]+)@(.+)$/);
|
|
1019
|
-
if (!match) {
|
|
1020
|
-
ctx.addIssue({
|
|
1021
|
-
code: "custom",
|
|
1022
|
-
message: `Invalid integration version format: ${val}. Expected format: 'name@version' or 'workspace/name@version'`
|
|
1023
|
-
});
|
|
1024
|
-
return;
|
|
1025
|
-
}
|
|
1026
|
-
const [, workspace, name, version] = match;
|
|
1027
|
-
return {
|
|
1028
|
-
workspace: workspace || undefined,
|
|
1029
|
-
name,
|
|
1030
|
-
version,
|
|
1031
|
-
fullName: workspace ? `${workspace}/${name}` : name
|
|
1032
|
-
};
|
|
1033
|
-
});
|
|
1034
|
-
versionSchema = z3.string().refine((version) => {
|
|
1035
|
-
if (version === "latest")
|
|
1036
|
-
return true;
|
|
1037
|
-
const semverPattern = /^(\d+)\.(\d+)\.(\d+)(-[\w.]+)?(\+[\w.]+)?$/;
|
|
1038
|
-
return semverPattern.test(version);
|
|
1039
|
-
}, { message: "Version must be exact semver (e.g., 1.2.3) or 'latest'" });
|
|
1040
|
-
PLUGIN_ALIAS_REGEX = /^[a-z][a-z0-9_-]*$/;
|
|
1041
|
-
pluginRefSchema = z3.string().transform((val, ctx) => {
|
|
1042
|
-
const match = val.match(/^([^/@]+)@(.+)$/);
|
|
1043
|
-
if (!match) {
|
|
1044
|
-
ctx.addIssue({
|
|
1045
|
-
code: "custom",
|
|
1046
|
-
message: `Invalid plugin version format: ${val}. Expected format: 'name@version' (no workspace prefix)`
|
|
1047
|
-
});
|
|
1048
|
-
return;
|
|
1049
|
-
}
|
|
1050
|
-
const [, name, version] = match;
|
|
1051
|
-
return {
|
|
1052
|
-
name,
|
|
1053
|
-
version,
|
|
1054
|
-
fullName: name
|
|
1055
|
-
};
|
|
1056
|
-
});
|
|
1057
|
-
});
|
|
1058
|
-
|
|
1059
|
-
// src/constants.ts
|
|
1060
|
-
var DEFAULT_API_URL = "https://api.botpress.cloud", BUILTIN_INTERFACES, MAX_TABLE_COLUMNS = 20;
|
|
1061
|
-
var init_constants = __esm(() => {
|
|
1062
|
-
BUILTIN_INTERFACES = {
|
|
1063
|
-
"typing-indicator": "typing-indicator@0.0.3",
|
|
1064
|
-
llm: "llm@9.0.0",
|
|
1065
|
-
listable: "listable@0.0.2"
|
|
1066
|
-
};
|
|
1067
|
-
});
|
|
1068
|
-
|
|
1069
|
-
// src/agent-project/agent-resolver.ts
|
|
1070
|
-
import fs from "fs/promises";
|
|
1071
|
-
import path from "path";
|
|
1072
|
-
async function readLocalInfo(agentPath) {
|
|
1073
|
-
const localPath = path.join(agentPath, "agent.local.json");
|
|
1074
|
-
try {
|
|
1075
|
-
const localContent = await fs.readFile(localPath, "utf-8");
|
|
1076
|
-
const localData = JSON.parse(localContent);
|
|
1077
|
-
const localResult = agentLocalInfoSchema.safeParse(localData);
|
|
1078
|
-
if (!localResult.success) {
|
|
1079
|
-
const issue = localResult.error.errors[0];
|
|
1080
|
-
throw ValidationErrors.warning(`agent.local.json has an invalid field: ${issue?.path.join(".")} — ${issue?.message}`, "agent.local.json");
|
|
1081
|
-
}
|
|
1082
|
-
return localResult.data;
|
|
1083
|
-
} catch (error) {
|
|
1084
|
-
if (error.code === "ENOENT") {
|
|
1085
|
-
return null;
|
|
1086
|
-
}
|
|
1087
|
-
if (ValidationErrors.isValidationError(error)) {
|
|
1088
|
-
throw error;
|
|
1089
|
-
}
|
|
1090
|
-
throw ValidationErrors.warning(`Failed to read agent.local.json: ${error.message}`, "agent.local.json");
|
|
1091
|
-
}
|
|
1092
|
-
}
|
|
1093
|
-
function applyLocalOverrides(agentInfo, localInfo) {
|
|
1094
|
-
if (localInfo.botId) {
|
|
1095
|
-
agentInfo.botId = localInfo.botId;
|
|
1096
|
-
}
|
|
1097
|
-
if (localInfo.workspaceId) {
|
|
1098
|
-
agentInfo.workspaceId = localInfo.workspaceId;
|
|
1099
|
-
}
|
|
1100
|
-
if (localInfo.apiUrl) {
|
|
1101
|
-
agentInfo.apiUrl = localInfo.apiUrl;
|
|
1102
|
-
}
|
|
1103
|
-
if (localInfo.devId) {
|
|
1104
|
-
agentInfo.devId = localInfo.devId;
|
|
1105
|
-
}
|
|
1106
|
-
}
|
|
1107
|
-
async function resolveAgent(agentPath, options = {}) {
|
|
1108
|
-
const { required = false, requireWorkspace = false, requireBot = false } = options;
|
|
1109
|
-
const agentJsonPath = path.join(agentPath, "agent.json");
|
|
1110
|
-
const localInfo = await readLocalInfo(agentPath);
|
|
1111
|
-
let agentInfo = null;
|
|
1112
|
-
try {
|
|
1113
|
-
const agentJsonContent = await fs.readFile(agentJsonPath, "utf-8");
|
|
1114
|
-
let agentData;
|
|
1115
|
-
try {
|
|
1116
|
-
agentData = JSON.parse(agentJsonContent);
|
|
1117
|
-
} catch (parseError) {
|
|
1118
|
-
throw ValidationErrors.invalidConfigSyntax("agent.json", parseError.message);
|
|
742
|
+
async function resolveAgent(agentPath, options = {}) {
|
|
743
|
+
const { required = false, requireWorkspace = false, requireBot = false } = options;
|
|
744
|
+
const agentJsonPath = path2.join(agentPath, "agent.json");
|
|
745
|
+
const localInfo = await readLocalInfo(agentPath);
|
|
746
|
+
let agentInfo = null;
|
|
747
|
+
try {
|
|
748
|
+
const agentJsonContent = await fs2.readFile(agentJsonPath, "utf-8");
|
|
749
|
+
let agentData;
|
|
750
|
+
try {
|
|
751
|
+
agentData = JSON.parse(agentJsonContent);
|
|
752
|
+
} catch (parseError) {
|
|
753
|
+
throw ValidationErrors.invalidConfigSyntax("agent.json", parseError.message);
|
|
1119
754
|
}
|
|
1120
755
|
const validationResult = agentInfoSchema.safeParse(agentData);
|
|
1121
756
|
if (!validationResult.success) {
|
|
@@ -1170,8 +805,8 @@ var exports_credentials = {};
|
|
|
1170
805
|
__export(exports_credentials, {
|
|
1171
806
|
CredentialsManager: () => CredentialsManager
|
|
1172
807
|
});
|
|
1173
|
-
import
|
|
1174
|
-
import
|
|
808
|
+
import fs3 from "fs/promises";
|
|
809
|
+
import path3 from "path";
|
|
1175
810
|
import os from "os";
|
|
1176
811
|
|
|
1177
812
|
class CredentialsManager {
|
|
@@ -1179,20 +814,20 @@ class CredentialsManager {
|
|
|
1179
814
|
configDir;
|
|
1180
815
|
profileOverride;
|
|
1181
816
|
constructor() {
|
|
1182
|
-
this.configDir =
|
|
1183
|
-
this.credentialsPath =
|
|
817
|
+
this.configDir = path3.join(os.homedir(), ".adk");
|
|
818
|
+
this.credentialsPath = path3.join(this.configDir, "credentials");
|
|
1184
819
|
}
|
|
1185
820
|
setProfileOverride(profile) {
|
|
1186
821
|
this.profileOverride = profile;
|
|
1187
822
|
}
|
|
1188
823
|
async ensureConfigDir() {
|
|
1189
824
|
try {
|
|
1190
|
-
await
|
|
825
|
+
await fs3.mkdir(this.configDir, { recursive: true });
|
|
1191
826
|
} catch {}
|
|
1192
827
|
}
|
|
1193
828
|
async readCredentials() {
|
|
1194
829
|
try {
|
|
1195
|
-
const data = await
|
|
830
|
+
const data = await fs3.readFile(this.credentialsPath, "utf-8");
|
|
1196
831
|
return JSON.parse(data);
|
|
1197
832
|
} catch {
|
|
1198
833
|
return {
|
|
@@ -1204,8 +839,8 @@ class CredentialsManager {
|
|
|
1204
839
|
}
|
|
1205
840
|
async writeCredentials(store) {
|
|
1206
841
|
await this.ensureConfigDir();
|
|
1207
|
-
await
|
|
1208
|
-
await
|
|
842
|
+
await fs3.writeFile(this.credentialsPath, JSON.stringify(store, null, 2));
|
|
843
|
+
await fs3.chmod(this.credentialsPath, 384);
|
|
1209
844
|
}
|
|
1210
845
|
async saveCredentials(profileName, credentials, userInfo) {
|
|
1211
846
|
const store = await this.readCredentials();
|
|
@@ -1447,18 +1082,18 @@ var init_service = __esm(() => {
|
|
|
1447
1082
|
});
|
|
1448
1083
|
|
|
1449
1084
|
// src/auth/bp-cli-import.ts
|
|
1450
|
-
import
|
|
1451
|
-
import
|
|
1085
|
+
import fs4 from "fs/promises";
|
|
1086
|
+
import path4 from "path";
|
|
1452
1087
|
import os2 from "os";
|
|
1453
1088
|
|
|
1454
1089
|
class BpCliImporter {
|
|
1455
1090
|
bpCachePath;
|
|
1456
1091
|
constructor() {
|
|
1457
|
-
this.bpCachePath =
|
|
1092
|
+
this.bpCachePath = path4.join(os2.homedir(), ".botpress", "global.cache.json");
|
|
1458
1093
|
}
|
|
1459
1094
|
async hasBpCliCredentials() {
|
|
1460
1095
|
try {
|
|
1461
|
-
await
|
|
1096
|
+
await fs4.access(this.bpCachePath);
|
|
1462
1097
|
return true;
|
|
1463
1098
|
} catch {
|
|
1464
1099
|
return false;
|
|
@@ -1466,7 +1101,7 @@ class BpCliImporter {
|
|
|
1466
1101
|
}
|
|
1467
1102
|
async getBpCliCredentials() {
|
|
1468
1103
|
try {
|
|
1469
|
-
const data = await
|
|
1104
|
+
const data = await fs4.readFile(this.bpCachePath, "utf-8");
|
|
1470
1105
|
const credentials = JSON.parse(data);
|
|
1471
1106
|
if (!credentials.token || !credentials.workspaceId || !credentials.apiUrl) {
|
|
1472
1107
|
return null;
|
|
@@ -1719,148 +1354,102 @@ var init_auth = __esm(() => {
|
|
|
1719
1354
|
projectClientCache = new Map;
|
|
1720
1355
|
});
|
|
1721
1356
|
|
|
1722
|
-
// src/
|
|
1723
|
-
import
|
|
1724
|
-
|
|
1725
|
-
class CatalogClientFactory {
|
|
1726
|
-
options;
|
|
1727
|
-
client;
|
|
1728
|
-
constructor(options = {}) {
|
|
1729
|
-
this.options = options;
|
|
1730
|
-
}
|
|
1731
|
-
async getClient() {
|
|
1732
|
-
if (this.client)
|
|
1733
|
-
return this.client;
|
|
1734
|
-
const { project, workspaceId, credentials, apiUrl } = this.options;
|
|
1735
|
-
const hasProjectScope = !!(project || workspaceId);
|
|
1736
|
-
if (hasProjectScope) {
|
|
1737
|
-
this.client = await getProjectClient({
|
|
1738
|
-
project,
|
|
1739
|
-
credentials,
|
|
1740
|
-
apiUrl,
|
|
1741
|
-
workspaceId,
|
|
1742
|
-
headers: { ...CATALOG_HEADERS }
|
|
1743
|
-
});
|
|
1744
|
-
} else if (credentials) {
|
|
1745
|
-
this.client = new Client3({
|
|
1746
|
-
token: credentials.token,
|
|
1747
|
-
apiUrl: apiUrl || credentials.apiUrl,
|
|
1748
|
-
...credentials.workspaceId ? { workspaceId: credentials.workspaceId } : {},
|
|
1749
|
-
headers: { ...CATALOG_HEADERS }
|
|
1750
|
-
});
|
|
1751
|
-
} else {
|
|
1752
|
-
this.client = await getProjectClient({ headers: { ...CATALOG_HEADERS } });
|
|
1753
|
-
}
|
|
1754
|
-
return this.client;
|
|
1755
|
-
}
|
|
1756
|
-
}
|
|
1757
|
-
var CATALOG_HEADERS;
|
|
1758
|
-
var init_client_factory = __esm(() => {
|
|
1759
|
-
init_auth();
|
|
1760
|
-
CATALOG_HEADERS = { "x-multiple-integrations": "true" };
|
|
1761
|
-
});
|
|
1762
|
-
|
|
1763
|
-
// src/dependencies/catalog/resolution-cache.ts
|
|
1764
|
-
import fs4 from "fs/promises";
|
|
1765
|
-
import path4 from "path";
|
|
1357
|
+
// src/integrations/enhanced-cache.ts
|
|
1358
|
+
import fs5 from "fs/promises";
|
|
1359
|
+
import path5 from "path";
|
|
1766
1360
|
import os3 from "os";
|
|
1767
1361
|
|
|
1768
|
-
class
|
|
1362
|
+
class EnhancedIntegrationCache {
|
|
1769
1363
|
cacheDir;
|
|
1770
1364
|
resolutionsDir;
|
|
1771
1365
|
definitionsDir;
|
|
1772
|
-
idField;
|
|
1773
1366
|
noCache;
|
|
1774
|
-
constructor(
|
|
1775
|
-
this.idField = config.idField;
|
|
1367
|
+
constructor(noCache = false) {
|
|
1776
1368
|
this.noCache = noCache;
|
|
1777
|
-
|
|
1778
|
-
this.
|
|
1779
|
-
this.
|
|
1780
|
-
this.definitionsDir = path4.join(this.cacheDir, "definitions");
|
|
1369
|
+
this.cacheDir = path5.join(os3.homedir(), ".adk", "cache", "integrations");
|
|
1370
|
+
this.resolutionsDir = path5.join(this.cacheDir, "resolutions");
|
|
1371
|
+
this.definitionsDir = path5.join(this.cacheDir, "definitions");
|
|
1781
1372
|
}
|
|
1782
1373
|
async ensureCacheDirs() {
|
|
1783
|
-
await
|
|
1784
|
-
await
|
|
1374
|
+
await fs5.mkdir(this.resolutionsDir, { recursive: true });
|
|
1375
|
+
await fs5.mkdir(this.definitionsDir, { recursive: true });
|
|
1785
1376
|
}
|
|
1786
|
-
async getResolution(name, version, workspace
|
|
1377
|
+
async getResolution(name, version, workspace) {
|
|
1787
1378
|
if (this.noCache) {
|
|
1788
1379
|
return null;
|
|
1789
1380
|
}
|
|
1790
1381
|
try {
|
|
1791
1382
|
const key = this.getResolutionKey(name, version, workspace);
|
|
1792
|
-
const cachePath =
|
|
1793
|
-
const data = await
|
|
1794
|
-
const
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
return null;
|
|
1800
|
-
}
|
|
1801
|
-
}
|
|
1802
|
-
const id = raw[this.idField];
|
|
1803
|
-
if (!id) {
|
|
1383
|
+
const cachePath = path5.join(this.resolutionsDir, `${key}.json`);
|
|
1384
|
+
const data = await fs5.readFile(cachePath, "utf-8");
|
|
1385
|
+
const resolution = JSON.parse(data);
|
|
1386
|
+
const cachedAt = new Date(resolution.cachedAt);
|
|
1387
|
+
const now = new Date;
|
|
1388
|
+
const ageMinutes = (now.getTime() - cachedAt.getTime()) / (1000 * 60);
|
|
1389
|
+
if (ageMinutes > 5) {
|
|
1804
1390
|
return null;
|
|
1805
1391
|
}
|
|
1806
|
-
return
|
|
1392
|
+
return resolution;
|
|
1807
1393
|
} catch {
|
|
1808
1394
|
return null;
|
|
1809
1395
|
}
|
|
1810
1396
|
}
|
|
1811
|
-
async setResolution(name, version, workspace,
|
|
1397
|
+
async setResolution(name, version, workspace, integrationId, updatedAt) {
|
|
1812
1398
|
await this.ensureCacheDirs();
|
|
1813
1399
|
const key = this.getResolutionKey(name, version, workspace);
|
|
1814
|
-
const cachePath =
|
|
1400
|
+
const cachePath = path5.join(this.resolutionsDir, `${key}.json`);
|
|
1815
1401
|
const resolution = {
|
|
1816
|
-
|
|
1402
|
+
integrationId,
|
|
1817
1403
|
updatedAt,
|
|
1818
1404
|
cachedAt: new Date().toISOString()
|
|
1819
1405
|
};
|
|
1820
|
-
await
|
|
1406
|
+
await fs5.writeFile(cachePath, JSON.stringify(resolution));
|
|
1821
1407
|
}
|
|
1822
|
-
async getDefinition(
|
|
1408
|
+
async getDefinition(integrationId, updatedAt) {
|
|
1823
1409
|
if (this.noCache) {
|
|
1824
1410
|
return null;
|
|
1825
1411
|
}
|
|
1826
1412
|
try {
|
|
1827
|
-
const key = this.getDefinitionKey(
|
|
1828
|
-
const cachePath =
|
|
1829
|
-
const data = await
|
|
1413
|
+
const key = this.getDefinitionKey(integrationId, updatedAt);
|
|
1414
|
+
const cachePath = path5.join(this.definitionsDir, `${key}.json`);
|
|
1415
|
+
const data = await fs5.readFile(cachePath, "utf-8");
|
|
1830
1416
|
const cached = JSON.parse(data);
|
|
1831
1417
|
return cached.definition;
|
|
1832
1418
|
} catch {
|
|
1833
1419
|
return null;
|
|
1834
1420
|
}
|
|
1835
1421
|
}
|
|
1836
|
-
async setDefinition(
|
|
1422
|
+
async setDefinition(integrationId, updatedAt, definition) {
|
|
1837
1423
|
await this.ensureCacheDirs();
|
|
1838
|
-
const key = this.getDefinitionKey(
|
|
1839
|
-
const cachePath =
|
|
1424
|
+
const key = this.getDefinitionKey(integrationId, updatedAt);
|
|
1425
|
+
const cachePath = path5.join(this.definitionsDir, `${key}.json`);
|
|
1840
1426
|
const cached = {
|
|
1841
1427
|
definition,
|
|
1842
1428
|
cachedAt: new Date().toISOString()
|
|
1843
1429
|
};
|
|
1844
|
-
await
|
|
1430
|
+
await fs5.writeFile(cachePath, JSON.stringify(cached));
|
|
1845
1431
|
}
|
|
1846
1432
|
async clear() {
|
|
1847
1433
|
try {
|
|
1848
|
-
const resolutionFiles = await
|
|
1849
|
-
await Promise.all(resolutionFiles.map((file) =>
|
|
1850
|
-
const definitionFiles = await
|
|
1851
|
-
await Promise.all(definitionFiles.map((file) =>
|
|
1434
|
+
const resolutionFiles = await fs5.readdir(this.resolutionsDir);
|
|
1435
|
+
await Promise.all(resolutionFiles.map((file) => fs5.unlink(path5.join(this.resolutionsDir, file))));
|
|
1436
|
+
const definitionFiles = await fs5.readdir(this.definitionsDir);
|
|
1437
|
+
await Promise.all(definitionFiles.map((file) => fs5.unlink(path5.join(this.definitionsDir, file))));
|
|
1852
1438
|
} catch {}
|
|
1853
1439
|
}
|
|
1854
1440
|
async getStats() {
|
|
1855
1441
|
const getDirectoryStats = async (dir) => {
|
|
1856
1442
|
try {
|
|
1857
|
-
const files = await
|
|
1443
|
+
const files = await fs5.readdir(dir);
|
|
1858
1444
|
let totalSize = 0;
|
|
1859
1445
|
for (const file of files) {
|
|
1860
|
-
const stats = await
|
|
1446
|
+
const stats = await fs5.stat(path5.join(dir, file));
|
|
1861
1447
|
totalSize += stats.size;
|
|
1862
1448
|
}
|
|
1863
|
-
return {
|
|
1449
|
+
return {
|
|
1450
|
+
count: files.length,
|
|
1451
|
+
sizeBytes: totalSize
|
|
1452
|
+
};
|
|
1864
1453
|
} catch {
|
|
1865
1454
|
return { count: 0, sizeBytes: 0 };
|
|
1866
1455
|
}
|
|
@@ -1876,65 +1465,238 @@ class ResolutionCache {
|
|
|
1876
1465
|
const key = `${prefix}${name}_${version}`;
|
|
1877
1466
|
return key.replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
1878
1467
|
}
|
|
1879
|
-
getDefinitionKey(
|
|
1880
|
-
const key = `${
|
|
1468
|
+
getDefinitionKey(integrationId, updatedAt) {
|
|
1469
|
+
const key = `${integrationId}_${updatedAt}`;
|
|
1881
1470
|
return key.replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
1882
1471
|
}
|
|
1883
1472
|
}
|
|
1884
|
-
var
|
|
1885
|
-
var init_resolution_cache = () => {};
|
|
1473
|
+
var init_enhanced_cache = () => {};
|
|
1886
1474
|
|
|
1887
|
-
// src/dependencies
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1475
|
+
// src/agent-project/dependencies-parser.ts
|
|
1476
|
+
import { z as z3 } from "@botpress/sdk";
|
|
1477
|
+
function isIntegrationAliasValid(alias) {
|
|
1478
|
+
return alias.length >= INTEGRATION_ALIAS_MIN_LENGTH && alias.length <= INTEGRATION_ALIAS_MAX_LENGTH && INTEGRATION_ALIAS_REGEX.test(alias);
|
|
1479
|
+
}
|
|
1480
|
+
|
|
1481
|
+
class IntegrationParser {
|
|
1482
|
+
static parseIntegrationRef(versionString) {
|
|
1483
|
+
const result = integrationRefSchema.safeParse(versionString);
|
|
1484
|
+
if (!result.success) {
|
|
1485
|
+
throw new AdkError({
|
|
1486
|
+
code: "INVALID_VERSION_FORMAT",
|
|
1487
|
+
expected: true,
|
|
1488
|
+
message: result.error.errors[0]?.message || "Invalid integration version format"
|
|
1489
|
+
});
|
|
1490
|
+
}
|
|
1491
|
+
return result.data;
|
|
1894
1492
|
}
|
|
1895
|
-
|
|
1896
|
-
const
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
return cachedDefinition;
|
|
1901
|
-
}
|
|
1493
|
+
static parseIntegrations(dependencies) {
|
|
1494
|
+
const integrations = [];
|
|
1495
|
+
const errors = [];
|
|
1496
|
+
if (!dependencies.integrations) {
|
|
1497
|
+
return { integrations, errors };
|
|
1902
1498
|
}
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
} catch (err) {
|
|
1909
|
-
if (!(err instanceof AdkError && err.expected)) {
|
|
1910
|
-
const stale = await this.getStaleDefinition(ref);
|
|
1911
|
-
if (stale !== null) {
|
|
1912
|
-
return stale;
|
|
1499
|
+
for (const [alias, value] of Object.entries(dependencies.integrations)) {
|
|
1500
|
+
try {
|
|
1501
|
+
if (!isIntegrationAliasValid(alias)) {
|
|
1502
|
+
errors.push(ValidationErrors.invalidIntegrationAlias(alias));
|
|
1503
|
+
continue;
|
|
1913
1504
|
}
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1505
|
+
const normalized = typeof value === "string" ? { version: value } : value;
|
|
1506
|
+
const ref = this.parseIntegrationRef(normalized.version);
|
|
1507
|
+
const versionResult = versionSchema.safeParse(ref.version);
|
|
1508
|
+
if (!versionResult.success) {
|
|
1509
|
+
errors.push(ValidationErrors.invalidVersionFormat(alias, ref.version));
|
|
1510
|
+
}
|
|
1511
|
+
integrations.push({
|
|
1512
|
+
alias,
|
|
1513
|
+
ref,
|
|
1514
|
+
enabled: "enabled" in normalized ? normalized.enabled : undefined,
|
|
1515
|
+
configurationType: "configurationType" in normalized ? normalized.configurationType : undefined,
|
|
1516
|
+
config: "config" in normalized ? normalized.config : undefined
|
|
1517
|
+
});
|
|
1518
|
+
} catch (error) {
|
|
1519
|
+
errors.push(ValidationErrors.invalidDependenciesSyntax(`Invalid integration '${alias}': ${error instanceof Error ? error.message : String(error)}`));
|
|
1520
|
+
}
|
|
1521
|
+
}
|
|
1522
|
+
return { integrations, errors };
|
|
1917
1523
|
}
|
|
1918
|
-
|
|
1919
|
-
const
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1524
|
+
static checkDuplicates(integrations) {
|
|
1525
|
+
const errors = [];
|
|
1526
|
+
const seen = new Map;
|
|
1527
|
+
for (const integration of integrations) {
|
|
1528
|
+
const key = integration.ref.fullName;
|
|
1529
|
+
const group = seen.get(key) || [];
|
|
1530
|
+
group.push(integration);
|
|
1531
|
+
seen.set(key, group);
|
|
1532
|
+
}
|
|
1533
|
+
for (const [integrationName, group] of seen.entries()) {
|
|
1534
|
+
if (group.length > 1) {
|
|
1535
|
+
const duplicateConfigs = [];
|
|
1536
|
+
for (let i = 0;i < group.length; i++) {
|
|
1537
|
+
for (let j = i + 1;j < group.length; j++) {
|
|
1538
|
+
const configA = JSON.stringify(group[i].config ?? {});
|
|
1539
|
+
const configB = JSON.stringify(group[j].config ?? {});
|
|
1540
|
+
if (configA === configB) {
|
|
1541
|
+
if (!duplicateConfigs.includes(group[i].alias)) {
|
|
1542
|
+
duplicateConfigs.push(group[i].alias);
|
|
1543
|
+
}
|
|
1544
|
+
if (!duplicateConfigs.includes(group[j].alias)) {
|
|
1545
|
+
duplicateConfigs.push(group[j].alias);
|
|
1546
|
+
}
|
|
1547
|
+
}
|
|
1548
|
+
}
|
|
1549
|
+
}
|
|
1550
|
+
if (duplicateConfigs.length > 0) {
|
|
1551
|
+
errors.push(ValidationErrors.warning(`Integration '${integrationName}' has aliases with identical configurations: ${duplicateConfigs.join(", ")}. Consider using different configs or removing duplicates.`, "agent.config.ts"));
|
|
1552
|
+
}
|
|
1553
|
+
}
|
|
1554
|
+
}
|
|
1555
|
+
return errors;
|
|
1923
1556
|
}
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
|
|
1929
|
-
|
|
1557
|
+
}
|
|
1558
|
+
function isPluginAliasValid(alias) {
|
|
1559
|
+
return alias.length >= PLUGIN_ALIAS_MIN_LENGTH && alias.length <= PLUGIN_ALIAS_MAX_LENGTH && PLUGIN_ALIAS_REGEX.test(alias);
|
|
1560
|
+
}
|
|
1561
|
+
|
|
1562
|
+
class PluginParser {
|
|
1563
|
+
static parsePluginRef(versionString) {
|
|
1564
|
+
const result = pluginRefSchema.safeParse(versionString);
|
|
1565
|
+
if (!result.success) {
|
|
1566
|
+
throw new AdkError({
|
|
1567
|
+
code: "INVALID_VERSION_FORMAT",
|
|
1568
|
+
expected: true,
|
|
1569
|
+
message: result.error.errors[0]?.message || "Invalid plugin version format"
|
|
1570
|
+
});
|
|
1571
|
+
}
|
|
1572
|
+
return result.data;
|
|
1930
1573
|
}
|
|
1931
|
-
|
|
1932
|
-
|
|
1574
|
+
static parsePlugins(dependencies) {
|
|
1575
|
+
const plugins = [];
|
|
1576
|
+
const errors = [];
|
|
1577
|
+
if (!dependencies.plugins) {
|
|
1578
|
+
return { plugins, errors };
|
|
1579
|
+
}
|
|
1580
|
+
for (const [alias, value] of Object.entries(dependencies.plugins)) {
|
|
1581
|
+
try {
|
|
1582
|
+
if (!isPluginAliasValid(alias)) {
|
|
1583
|
+
errors.push(ValidationErrors.invalidPluginAlias(alias));
|
|
1584
|
+
continue;
|
|
1585
|
+
}
|
|
1586
|
+
const ref = this.parsePluginRef(value.version);
|
|
1587
|
+
const versionResult = versionSchema.safeParse(ref.version);
|
|
1588
|
+
if (!versionResult.success) {
|
|
1589
|
+
errors.push(ValidationErrors.invalidPluginVersionFormat(alias, ref.version));
|
|
1590
|
+
}
|
|
1591
|
+
plugins.push({
|
|
1592
|
+
alias,
|
|
1593
|
+
ref,
|
|
1594
|
+
config: value.config,
|
|
1595
|
+
dependencies: value.dependencies
|
|
1596
|
+
});
|
|
1597
|
+
} catch (error) {
|
|
1598
|
+
errors.push(ValidationErrors.invalidDependenciesSyntax(`Invalid plugin '${alias}': ${error instanceof Error ? error.message : String(error)}`));
|
|
1599
|
+
}
|
|
1600
|
+
}
|
|
1601
|
+
return { plugins, errors };
|
|
1602
|
+
}
|
|
1603
|
+
static validateDependencyReferences(dependencies) {
|
|
1604
|
+
const errors = [];
|
|
1605
|
+
if (!dependencies.plugins) {
|
|
1606
|
+
return errors;
|
|
1607
|
+
}
|
|
1608
|
+
const integrationAliases = Object.keys(dependencies.integrations || {});
|
|
1609
|
+
for (const [alias, pluginConfig] of Object.entries(dependencies.plugins)) {
|
|
1610
|
+
if (!pluginConfig.dependencies) {
|
|
1611
|
+
continue;
|
|
1612
|
+
}
|
|
1613
|
+
for (const [_depAlias, depMapping] of Object.entries(pluginConfig.dependencies)) {
|
|
1614
|
+
if (!integrationAliases.includes(depMapping.integrationAlias)) {
|
|
1615
|
+
errors.push(ValidationErrors.invalidPluginDependency(alias, depMapping.integrationAlias, integrationAliases));
|
|
1616
|
+
}
|
|
1617
|
+
}
|
|
1618
|
+
}
|
|
1619
|
+
return errors;
|
|
1620
|
+
}
|
|
1621
|
+
static checkDuplicates(plugins) {
|
|
1622
|
+
const errors = [];
|
|
1623
|
+
const seen = new Map;
|
|
1624
|
+
for (const plugin of plugins) {
|
|
1625
|
+
const key = plugin.ref.fullName;
|
|
1626
|
+
const group = seen.get(key) || [];
|
|
1627
|
+
group.push(plugin);
|
|
1628
|
+
seen.set(key, group);
|
|
1629
|
+
}
|
|
1630
|
+
for (const [pluginName, group] of seen.entries()) {
|
|
1631
|
+
if (group.length > 1) {
|
|
1632
|
+
const duplicateConfigs = [];
|
|
1633
|
+
for (let i = 0;i < group.length; i++) {
|
|
1634
|
+
for (let j = i + 1;j < group.length; j++) {
|
|
1635
|
+
const configA = JSON.stringify(group[i].config ?? {});
|
|
1636
|
+
const configB = JSON.stringify(group[j].config ?? {});
|
|
1637
|
+
if (configA === configB) {
|
|
1638
|
+
if (!duplicateConfigs.includes(group[i].alias)) {
|
|
1639
|
+
duplicateConfigs.push(group[i].alias);
|
|
1640
|
+
}
|
|
1641
|
+
if (!duplicateConfigs.includes(group[j].alias)) {
|
|
1642
|
+
duplicateConfigs.push(group[j].alias);
|
|
1643
|
+
}
|
|
1644
|
+
}
|
|
1645
|
+
}
|
|
1646
|
+
}
|
|
1647
|
+
if (duplicateConfigs.length > 0) {
|
|
1648
|
+
errors.push(ValidationErrors.warning(`Plugin '${pluginName}' has aliases with identical configurations: ${duplicateConfigs.join(", ")}. Consider using different configs or removing duplicates.`, "agent.config.ts"));
|
|
1649
|
+
}
|
|
1650
|
+
}
|
|
1651
|
+
}
|
|
1652
|
+
return errors;
|
|
1933
1653
|
}
|
|
1934
1654
|
}
|
|
1935
|
-
var
|
|
1655
|
+
var INTEGRATION_ALIAS_MIN_LENGTH = 2, INTEGRATION_ALIAS_MAX_LENGTH = 100, INTEGRATION_ALIAS_REGEX, integrationRefSchema, versionSchema, PLUGIN_ALIAS_MIN_LENGTH = 2, PLUGIN_ALIAS_MAX_LENGTH = 100, PLUGIN_ALIAS_REGEX, pluginRefSchema;
|
|
1656
|
+
var init_dependencies_parser = __esm(() => {
|
|
1936
1657
|
init_src();
|
|
1937
|
-
|
|
1658
|
+
init_validation_errors();
|
|
1659
|
+
INTEGRATION_ALIAS_REGEX = /^(?:[a-z][a-z0-9_-]*\/)?[a-z][a-z0-9_-]*$/;
|
|
1660
|
+
integrationRefSchema = z3.string().transform((val, ctx) => {
|
|
1661
|
+
const match = val.match(/^(?:([^/]+)\/)?([^@]+)@(.+)$/);
|
|
1662
|
+
if (!match) {
|
|
1663
|
+
ctx.addIssue({
|
|
1664
|
+
code: "custom",
|
|
1665
|
+
message: `Invalid integration version format: ${val}. Expected format: 'name@version' or 'workspace/name@version'`
|
|
1666
|
+
});
|
|
1667
|
+
return;
|
|
1668
|
+
}
|
|
1669
|
+
const [, workspace, name, version] = match;
|
|
1670
|
+
return {
|
|
1671
|
+
workspace: workspace || undefined,
|
|
1672
|
+
name,
|
|
1673
|
+
version,
|
|
1674
|
+
fullName: workspace ? `${workspace}/${name}` : name
|
|
1675
|
+
};
|
|
1676
|
+
});
|
|
1677
|
+
versionSchema = z3.string().refine((version) => {
|
|
1678
|
+
if (version === "latest")
|
|
1679
|
+
return true;
|
|
1680
|
+
const semverPattern = /^(\d+)\.(\d+)\.(\d+)(-[\w.]+)?(\+[\w.]+)?$/;
|
|
1681
|
+
return semverPattern.test(version);
|
|
1682
|
+
}, { message: "Version must be exact semver (e.g., 1.2.3) or 'latest'" });
|
|
1683
|
+
PLUGIN_ALIAS_REGEX = /^[a-z][a-z0-9_-]*$/;
|
|
1684
|
+
pluginRefSchema = z3.string().transform((val, ctx) => {
|
|
1685
|
+
const match = val.match(/^([^/@]+)@(.+)$/);
|
|
1686
|
+
if (!match) {
|
|
1687
|
+
ctx.addIssue({
|
|
1688
|
+
code: "custom",
|
|
1689
|
+
message: `Invalid plugin version format: ${val}. Expected format: 'name@version' (no workspace prefix)`
|
|
1690
|
+
});
|
|
1691
|
+
return;
|
|
1692
|
+
}
|
|
1693
|
+
const [, name, version] = match;
|
|
1694
|
+
return {
|
|
1695
|
+
name,
|
|
1696
|
+
version,
|
|
1697
|
+
fullName: name
|
|
1698
|
+
};
|
|
1699
|
+
});
|
|
1938
1700
|
});
|
|
1939
1701
|
|
|
1940
1702
|
// src/utils/search-ranking.ts
|
|
@@ -2003,23 +1765,109 @@ function normalize(value) {
|
|
|
2003
1765
|
}
|
|
2004
1766
|
var init_search_ranking = () => {};
|
|
2005
1767
|
|
|
2006
|
-
// src/
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
1768
|
+
// src/integrations/manager.ts
|
|
1769
|
+
import { Client as Client3 } from "@botpress/client";
|
|
1770
|
+
|
|
1771
|
+
class IntegrationManager {
|
|
1772
|
+
cache;
|
|
1773
|
+
options;
|
|
1774
|
+
client;
|
|
1775
|
+
constructor(options = {}) {
|
|
1776
|
+
this.options = options;
|
|
1777
|
+
this.cache = new EnhancedIntegrationCache(options.noCache || false);
|
|
1778
|
+
}
|
|
1779
|
+
async getClient() {
|
|
1780
|
+
if (!this.client) {
|
|
1781
|
+
const hasProjectScope = !!(this.options.project || this.options.workspaceId);
|
|
1782
|
+
if (hasProjectScope) {
|
|
1783
|
+
this.client = await getProjectClient({
|
|
1784
|
+
project: this.options.project,
|
|
1785
|
+
credentials: this.options.credentials,
|
|
1786
|
+
apiUrl: this.options.apiUrl,
|
|
1787
|
+
workspaceId: this.options.workspaceId,
|
|
1788
|
+
headers: {
|
|
1789
|
+
"x-multiple-integrations": "true"
|
|
1790
|
+
}
|
|
1791
|
+
});
|
|
1792
|
+
} else if (this.options.credentials) {
|
|
1793
|
+
this.client = new Client3({
|
|
1794
|
+
token: this.options.credentials.token,
|
|
1795
|
+
apiUrl: this.options.apiUrl || this.options.credentials.apiUrl,
|
|
1796
|
+
...this.options.credentials.workspaceId ? { workspaceId: this.options.credentials.workspaceId } : {},
|
|
1797
|
+
headers: {
|
|
1798
|
+
"x-multiple-integrations": "true"
|
|
1799
|
+
}
|
|
1800
|
+
});
|
|
1801
|
+
} else {
|
|
1802
|
+
this.client = await getProjectClient({
|
|
1803
|
+
headers: {
|
|
1804
|
+
"x-multiple-integrations": "true"
|
|
1805
|
+
}
|
|
1806
|
+
});
|
|
1807
|
+
}
|
|
1808
|
+
}
|
|
1809
|
+
return this.client;
|
|
1810
|
+
}
|
|
1811
|
+
async loadIntegrations(dependencies) {
|
|
1812
|
+
const errors = [];
|
|
1813
|
+
const warnings = [];
|
|
1814
|
+
const parseResult = IntegrationParser.parseIntegrations(dependencies);
|
|
1815
|
+
const integrations = parseResult.integrations;
|
|
1816
|
+
errors.push(...parseResult.errors);
|
|
1817
|
+
const duplicateWarnings = IntegrationParser.checkDuplicates(integrations);
|
|
1818
|
+
warnings.push(...duplicateWarnings);
|
|
1819
|
+
const fetchPromises = integrations.map(async (integration) => {
|
|
1820
|
+
try {
|
|
1821
|
+
const definition = await this.fetchIntegration(integration.ref);
|
|
1822
|
+
integration.definition = definition;
|
|
1823
|
+
const validation = this.validateIntegration(integration);
|
|
1824
|
+
integration.validationResult = validation;
|
|
1825
|
+
if (!validation.valid) {
|
|
1826
|
+
validation.errors.forEach(() => {
|
|
1827
|
+
errors.push(ValidationErrors.unknownIntegration(integration.alias, integration.ref.fullName));
|
|
1828
|
+
});
|
|
1829
|
+
}
|
|
1830
|
+
if (validation.warnings.length > 0) {
|
|
1831
|
+
validation.warnings.forEach((warn) => {
|
|
1832
|
+
warnings.push(ValidationErrors.warning(warn, "agent.config.ts"));
|
|
1833
|
+
});
|
|
1834
|
+
}
|
|
1835
|
+
} catch (error) {
|
|
1836
|
+
if (error instanceof Error && error.message.includes("version")) {
|
|
1837
|
+
errors.push(ValidationErrors.integrationVersionError(integration.alias, error.message));
|
|
1838
|
+
} else {
|
|
1839
|
+
const errorMessage = error instanceof Error ? error.message : undefined;
|
|
1840
|
+
errors.push(ValidationErrors.unknownIntegration(integration.alias, integration.ref.fullName, errorMessage));
|
|
1841
|
+
}
|
|
1842
|
+
}
|
|
1843
|
+
});
|
|
1844
|
+
await Promise.all(fetchPromises);
|
|
1845
|
+
const hasChannels = integrations.some((i) => i.definition?.channels && Object.keys(i.definition.channels).length > 0);
|
|
1846
|
+
if (!hasChannels && integrations.length > 0) {
|
|
1847
|
+
warnings.push(ValidationErrors.warning("No integrations with channels found. Your agent may not be able to receive messages.", "agent.config.ts", "Add an integration with channels (e.g., slack, webchat) to enable conversations"));
|
|
1848
|
+
}
|
|
1849
|
+
return { integrations, errors, warnings };
|
|
1850
|
+
}
|
|
1851
|
+
async fetchIntegration(ref) {
|
|
1852
|
+
const cachedResolution = await this.cache.getResolution(ref.name, ref.version, ref.workspace);
|
|
1853
|
+
if (cachedResolution) {
|
|
1854
|
+
const cachedDefinition = await this.cache.getDefinition(cachedResolution.integrationId, cachedResolution.updatedAt);
|
|
1855
|
+
if (cachedDefinition) {
|
|
1856
|
+
return cachedDefinition;
|
|
1857
|
+
}
|
|
1858
|
+
}
|
|
1859
|
+
const client = await this.getClient();
|
|
2015
1860
|
const integration = await this._findPrivateOrPublicIntegration(client, ref);
|
|
2016
1861
|
if (!integration) {
|
|
2017
1862
|
throw await this._buildIntegrationNotFoundError(client, ref);
|
|
2018
1863
|
}
|
|
2019
|
-
|
|
1864
|
+
await this.cache.setResolution(ref.name, ref.version, ref.workspace, integration.id, integration.updatedAt);
|
|
1865
|
+
const definition = integration;
|
|
1866
|
+
await this.cache.setDefinition(integration.id, integration.updatedAt, definition);
|
|
1867
|
+
return definition;
|
|
2020
1868
|
}
|
|
2021
|
-
async
|
|
2022
|
-
const client = await this.
|
|
1869
|
+
async searchIntegrations(query, limit = 20) {
|
|
1870
|
+
const client = await this.getClient();
|
|
2023
1871
|
const results = new Map;
|
|
2024
1872
|
const scanLimit = Math.max(limit * 5, 50);
|
|
2025
1873
|
for await (const integration of client.list.publicIntegrations({
|
|
@@ -2044,7 +1892,7 @@ class IntegrationCatalogSource {
|
|
|
2044
1892
|
return getSortedCatalogSearchResults(results, limit);
|
|
2045
1893
|
}
|
|
2046
1894
|
async findImplementersOfInterface(interfaceName, limit = 10) {
|
|
2047
|
-
const client = await this.
|
|
1895
|
+
const client = await this.getClient();
|
|
2048
1896
|
const seen = new Map;
|
|
2049
1897
|
for await (const integration of client.list.publicIntegrations({
|
|
2050
1898
|
interfaceName,
|
|
@@ -2060,8 +1908,8 @@ class IntegrationCatalogSource {
|
|
|
2060
1908
|
}
|
|
2061
1909
|
return [...seen.values()];
|
|
2062
1910
|
}
|
|
2063
|
-
async
|
|
2064
|
-
const client = await this.
|
|
1911
|
+
async listIntegrationVersions(name) {
|
|
1912
|
+
const client = await this.getClient();
|
|
2065
1913
|
const versions = new Set;
|
|
2066
1914
|
for await (const integration of client.list.publicIntegrations({
|
|
2067
1915
|
name,
|
|
@@ -2098,169 +1946,79 @@ class IntegrationCatalogSource {
|
|
|
2098
1946
|
throw error;
|
|
2099
1947
|
}
|
|
2100
1948
|
}
|
|
2101
|
-
async _findPublicIntegration(client, ref) {
|
|
2102
|
-
try {
|
|
2103
|
-
const response = await client.getPublicIntegration({
|
|
2104
|
-
name: ref.fullName,
|
|
2105
|
-
version: ref.version
|
|
2106
|
-
});
|
|
2107
|
-
return response.integration;
|
|
2108
|
-
} catch (error) {
|
|
2109
|
-
if (this._isResourceNotFoundError(error)) {
|
|
2110
|
-
return;
|
|
2111
|
-
}
|
|
2112
|
-
throw error;
|
|
2113
|
-
}
|
|
2114
|
-
}
|
|
2115
|
-
_isResourceNotFoundError(error) {
|
|
2116
|
-
if (error && typeof error === "object" && "type" in error) {
|
|
2117
|
-
return error.type === "ResourceNotFound";
|
|
2118
|
-
}
|
|
2119
|
-
return false;
|
|
2120
|
-
}
|
|
2121
|
-
async _buildIntegrationNotFoundError(client, ref) {
|
|
2122
|
-
if (ref.version !== "latest") {
|
|
2123
|
-
const latestExists = await this._findPrivateOrPublicIntegration(client, { ...ref, version: "latest" });
|
|
2124
|
-
if (latestExists) {
|
|
2125
|
-
const scope = ref.workspace ? `workspace "${ref.workspace}"` : "the official Botpress hub";
|
|
2126
|
-
return new AdkError({
|
|
2127
|
-
code: "INTEGRATION_NOT_FOUND",
|
|
2128
|
-
message: `Integration "${ref.name}" version "${ref.version}" not found in ${scope} ` + `(latest is ${latestExists.version}). Run 'adk integrations info ${ref.fullName}' to see available versions.`,
|
|
2129
|
-
expected: true
|
|
2130
|
-
});
|
|
2131
|
-
}
|
|
2132
|
-
}
|
|
2133
|
-
if (!ref.workspace) {
|
|
2134
|
-
return new AdkError({
|
|
2135
|
-
code: "INTEGRATION_NOT_FOUND",
|
|
2136
|
-
message: `Integration "${ref.name}" not found in the official Botpress hub`,
|
|
2137
|
-
expected: true
|
|
2138
|
-
});
|
|
2139
|
-
}
|
|
2140
|
-
let currentWorkspaceHandle;
|
|
2141
|
-
let workspaceId;
|
|
2142
|
-
try {
|
|
2143
|
-
const credentials = await resolveWorkspaceCredentials({
|
|
2144
|
-
project: this.clientFactory.options.project,
|
|
2145
|
-
credentials: this.clientFactory.options.credentials,
|
|
2146
|
-
apiUrl: this.clientFactory.options.apiUrl,
|
|
2147
|
-
workspaceId: this.clientFactory.options.workspaceId
|
|
2148
|
-
});
|
|
2149
|
-
workspaceId = credentials.workspaceId;
|
|
2150
|
-
if (workspaceId) {
|
|
2151
|
-
const currentWorkspace = await client.getWorkspace({ id: workspaceId });
|
|
2152
|
-
currentWorkspaceHandle = currentWorkspace?.handle;
|
|
2153
|
-
}
|
|
2154
|
-
} catch {
|
|
2155
|
-
return new AdkError({
|
|
2156
|
-
code: "INTEGRATION_NOT_FOUND",
|
|
2157
|
-
message: `Integration "${ref.name}" not found in workspace "${ref.workspace}"`,
|
|
2158
|
-
expected: true
|
|
2159
|
-
});
|
|
2160
|
-
}
|
|
2161
|
-
if (currentWorkspaceHandle === ref.workspace) {
|
|
2162
|
-
return new AdkError({
|
|
2163
|
-
code: "INTEGRATION_NOT_FOUND",
|
|
2164
|
-
message: `Integration "${ref.name}" not found in workspace "${ref.workspace}" (workspaceId: ${workspaceId}). ` + `Are you sure you published the integration? ` + `Run 'adk deploy' to publish it to your workspace.`,
|
|
2165
|
-
expected: true,
|
|
2166
|
-
suggestion: "Are you sure you published the integration? Run 'adk deploy' to publish it to your workspace."
|
|
2167
|
-
});
|
|
2168
|
-
}
|
|
2169
|
-
return new AdkError({
|
|
2170
|
-
code: "INTEGRATION_NOT_FOUND",
|
|
2171
|
-
message: `Integration "${ref.name}" not found in workspace "${ref.workspace}" (current workspaceId: ${workspaceId}). ` + `This integration may be private. Private integrations can only be installed in the same workspace. ` + `If you want to share this integration with other workspaces, deploy it with --visibility="unlisted" or --visibility="public".`,
|
|
2172
|
-
expected: true
|
|
2173
|
-
});
|
|
2174
|
-
}
|
|
2175
|
-
}
|
|
2176
|
-
function toHubCacheEntry(integration) {
|
|
2177
|
-
return {
|
|
2178
|
-
id: integration.id,
|
|
2179
|
-
name: integration.name,
|
|
2180
|
-
version: integration.version,
|
|
2181
|
-
updatedAt: integration.updatedAt,
|
|
2182
|
-
createdAt: integration.createdAt,
|
|
2183
|
-
title: integration.title,
|
|
2184
|
-
description: integration.description,
|
|
2185
|
-
iconUrl: integration.iconUrl,
|
|
2186
|
-
public: integration.public,
|
|
2187
|
-
visibility: integration.visibility,
|
|
2188
|
-
ownerWorkspace: integration.ownerWorkspace ? { id: integration.ownerWorkspace.id, name: integration.ownerWorkspace.name } : undefined,
|
|
2189
|
-
verificationStatus: integration.verificationStatus
|
|
2190
|
-
};
|
|
2191
|
-
}
|
|
2192
|
-
var init_integration_source = __esm(() => {
|
|
2193
|
-
init_src();
|
|
2194
|
-
init_auth();
|
|
2195
|
-
init_search_ranking();
|
|
2196
|
-
});
|
|
2197
|
-
|
|
2198
|
-
// src/integrations/manager.ts
|
|
2199
|
-
class IntegrationManager {
|
|
2200
|
-
source;
|
|
2201
|
-
service;
|
|
2202
|
-
constructor(options = {}) {
|
|
2203
|
-
const { noCache, ...clientOptions } = options;
|
|
2204
|
-
this.source = new IntegrationCatalogSource(new CatalogClientFactory(clientOptions));
|
|
2205
|
-
this.service = new CatalogService(this.source, noCache || false);
|
|
2206
|
-
}
|
|
2207
|
-
async loadIntegrations(dependencies) {
|
|
2208
|
-
const errors = [];
|
|
2209
|
-
const warnings = [];
|
|
2210
|
-
const parseResult = IntegrationParser.parseIntegrations(dependencies);
|
|
2211
|
-
const integrations = parseResult.integrations;
|
|
2212
|
-
errors.push(...parseResult.errors);
|
|
2213
|
-
const duplicateWarnings = IntegrationParser.checkDuplicates(integrations);
|
|
2214
|
-
warnings.push(...duplicateWarnings);
|
|
2215
|
-
const fetchPromises = integrations.map(async (integration) => {
|
|
2216
|
-
try {
|
|
2217
|
-
const definition = await this.fetchIntegration(integration.ref);
|
|
2218
|
-
integration.definition = definition;
|
|
2219
|
-
const validation = this.validateIntegration(integration);
|
|
2220
|
-
integration.validationResult = validation;
|
|
2221
|
-
if (!validation.valid) {
|
|
2222
|
-
validation.errors.forEach(() => {
|
|
2223
|
-
errors.push(ValidationErrors.unknownIntegration(integration.alias, integration.ref.fullName));
|
|
2224
|
-
});
|
|
2225
|
-
}
|
|
2226
|
-
if (validation.warnings.length > 0) {
|
|
2227
|
-
validation.warnings.forEach((warn) => {
|
|
2228
|
-
warnings.push(ValidationErrors.warning(warn, "agent.config.ts"));
|
|
2229
|
-
});
|
|
2230
|
-
}
|
|
2231
|
-
} catch (error) {
|
|
2232
|
-
if (error instanceof Error && error.message.includes("version")) {
|
|
2233
|
-
errors.push(ValidationErrors.integrationVersionError(integration.alias, error.message));
|
|
2234
|
-
} else {
|
|
2235
|
-
const errorMessage = error instanceof Error ? error.message : undefined;
|
|
2236
|
-
errors.push(ValidationErrors.unknownIntegration(integration.alias, integration.ref.fullName, errorMessage));
|
|
2237
|
-
}
|
|
2238
|
-
}
|
|
2239
|
-
});
|
|
2240
|
-
await Promise.all(fetchPromises);
|
|
2241
|
-
const hasChannels = integrations.some((i) => i.definition?.channels && Object.keys(i.definition.channels).length > 0);
|
|
2242
|
-
if (!hasChannels && integrations.length > 0) {
|
|
2243
|
-
warnings.push(ValidationErrors.warning("No integrations with channels found. Your agent may not be able to receive messages.", "agent.config.ts", "Add an integration with channels (e.g., slack, webchat) to enable conversations"));
|
|
2244
|
-
}
|
|
2245
|
-
return { integrations, errors, warnings };
|
|
2246
|
-
}
|
|
2247
|
-
async fetchIntegration(ref) {
|
|
2248
|
-
return this.service.getDefinition(ref);
|
|
2249
|
-
}
|
|
2250
|
-
async searchIntegrations(query, limit = 20) {
|
|
2251
|
-
return this.source.search(query, limit);
|
|
2252
|
-
}
|
|
2253
|
-
async findImplementersOfInterface(interfaceName, limit = 10) {
|
|
2254
|
-
return this.source.findImplementersOfInterface(interfaceName, limit);
|
|
2255
|
-
}
|
|
2256
|
-
async listIntegrationVersions(name) {
|
|
2257
|
-
return this.source.listVersions(name);
|
|
1949
|
+
async _findPublicIntegration(client, ref) {
|
|
1950
|
+
try {
|
|
1951
|
+
const response = await client.getPublicIntegration({
|
|
1952
|
+
name: ref.fullName,
|
|
1953
|
+
version: ref.version
|
|
1954
|
+
});
|
|
1955
|
+
return response.integration;
|
|
1956
|
+
} catch (error) {
|
|
1957
|
+
if (this._isResourceNotFoundError(error)) {
|
|
1958
|
+
return;
|
|
1959
|
+
}
|
|
1960
|
+
throw error;
|
|
1961
|
+
}
|
|
2258
1962
|
}
|
|
2259
|
-
|
|
2260
|
-
|
|
1963
|
+
_isResourceNotFoundError(error) {
|
|
1964
|
+
if (error && typeof error === "object" && "type" in error) {
|
|
1965
|
+
return error.type === "ResourceNotFound";
|
|
1966
|
+
}
|
|
1967
|
+
return false;
|
|
2261
1968
|
}
|
|
2262
|
-
async
|
|
2263
|
-
|
|
1969
|
+
async _buildIntegrationNotFoundError(client, ref) {
|
|
1970
|
+
if (ref.version !== "latest") {
|
|
1971
|
+
const latestExists = await this._findPrivateOrPublicIntegration(client, { ...ref, version: "latest" });
|
|
1972
|
+
if (latestExists) {
|
|
1973
|
+
const scope = ref.workspace ? `workspace "${ref.workspace}"` : "the official Botpress hub";
|
|
1974
|
+
return new AdkError({
|
|
1975
|
+
code: "INTEGRATION_NOT_FOUND",
|
|
1976
|
+
message: `Integration "${ref.name}" version "${ref.version}" not found in ${scope} ` + `(latest is ${latestExists.version}). Run 'adk info ${ref.fullName}' to see available versions.`,
|
|
1977
|
+
expected: true
|
|
1978
|
+
});
|
|
1979
|
+
}
|
|
1980
|
+
}
|
|
1981
|
+
if (!ref.workspace) {
|
|
1982
|
+
return new AdkError({
|
|
1983
|
+
code: "INTEGRATION_NOT_FOUND",
|
|
1984
|
+
message: `Integration "${ref.name}" not found in the official Botpress hub`,
|
|
1985
|
+
expected: true
|
|
1986
|
+
});
|
|
1987
|
+
}
|
|
1988
|
+
let currentWorkspaceHandle;
|
|
1989
|
+
let workspaceId;
|
|
1990
|
+
try {
|
|
1991
|
+
const credentials = await resolveWorkspaceCredentials({
|
|
1992
|
+
project: this.options.project,
|
|
1993
|
+
credentials: this.options.credentials,
|
|
1994
|
+
apiUrl: this.options.apiUrl,
|
|
1995
|
+
workspaceId: this.options.workspaceId
|
|
1996
|
+
});
|
|
1997
|
+
workspaceId = credentials.workspaceId;
|
|
1998
|
+
if (workspaceId) {
|
|
1999
|
+
const currentWorkspace = await client.getWorkspace({ id: workspaceId });
|
|
2000
|
+
currentWorkspaceHandle = currentWorkspace?.handle;
|
|
2001
|
+
}
|
|
2002
|
+
} catch {
|
|
2003
|
+
return new AdkError({
|
|
2004
|
+
code: "INTEGRATION_NOT_FOUND",
|
|
2005
|
+
message: `Integration "${ref.name}" not found in workspace "${ref.workspace}"`,
|
|
2006
|
+
expected: true
|
|
2007
|
+
});
|
|
2008
|
+
}
|
|
2009
|
+
if (currentWorkspaceHandle === ref.workspace) {
|
|
2010
|
+
return new AdkError({
|
|
2011
|
+
code: "INTEGRATION_NOT_FOUND",
|
|
2012
|
+
message: `Integration "${ref.name}" not found in workspace "${ref.workspace}" (workspaceId: ${workspaceId}). ` + `Are you sure you published the integration? ` + `Run 'adk deploy' to publish it to your workspace.`,
|
|
2013
|
+
expected: true,
|
|
2014
|
+
suggestion: "Are you sure you published the integration? Run 'adk deploy' to publish it to your workspace."
|
|
2015
|
+
});
|
|
2016
|
+
}
|
|
2017
|
+
return new AdkError({
|
|
2018
|
+
code: "INTEGRATION_NOT_FOUND",
|
|
2019
|
+
message: `Integration "${ref.name}" not found in workspace "${ref.workspace}" (current workspaceId: ${workspaceId}). ` + `This integration may be private. Private integrations can only be installed in the same workspace. ` + `If you want to share this integration with other workspaces, deploy it with --visibility="unlisted" or --visibility="public".`,
|
|
2020
|
+
expected: true
|
|
2021
|
+
});
|
|
2264
2022
|
}
|
|
2265
2023
|
validateIntegration(integration) {
|
|
2266
2024
|
const errors = [];
|
|
@@ -2291,13 +2049,40 @@ class IntegrationManager {
|
|
|
2291
2049
|
missingChannels: !hasChannels
|
|
2292
2050
|
};
|
|
2293
2051
|
}
|
|
2052
|
+
async getCacheStats() {
|
|
2053
|
+
const stats = await this.cache.getStats();
|
|
2054
|
+
return {
|
|
2055
|
+
count: stats.resolutions.count + stats.definitions.count,
|
|
2056
|
+
sizeBytes: stats.resolutions.sizeBytes + stats.definitions.sizeBytes
|
|
2057
|
+
};
|
|
2058
|
+
}
|
|
2059
|
+
async clearCache() {
|
|
2060
|
+
await this.cache.clear();
|
|
2061
|
+
}
|
|
2062
|
+
}
|
|
2063
|
+
function toHubCacheEntry(integration) {
|
|
2064
|
+
return {
|
|
2065
|
+
id: integration.id,
|
|
2066
|
+
name: integration.name,
|
|
2067
|
+
version: integration.version,
|
|
2068
|
+
updatedAt: integration.updatedAt,
|
|
2069
|
+
createdAt: integration.createdAt,
|
|
2070
|
+
title: integration.title,
|
|
2071
|
+
description: integration.description,
|
|
2072
|
+
iconUrl: integration.iconUrl,
|
|
2073
|
+
public: integration.public,
|
|
2074
|
+
visibility: integration.visibility,
|
|
2075
|
+
ownerWorkspace: integration.ownerWorkspace ? { id: integration.ownerWorkspace.id, name: integration.ownerWorkspace.name } : undefined,
|
|
2076
|
+
verificationStatus: integration.verificationStatus
|
|
2077
|
+
};
|
|
2294
2078
|
}
|
|
2295
2079
|
var init_manager = __esm(() => {
|
|
2080
|
+
init_src();
|
|
2081
|
+
init_auth();
|
|
2082
|
+
init_enhanced_cache();
|
|
2296
2083
|
init_dependencies_parser();
|
|
2297
2084
|
init_validation_errors();
|
|
2298
|
-
|
|
2299
|
-
init_catalog_service();
|
|
2300
|
-
init_integration_source();
|
|
2085
|
+
init_search_ranking();
|
|
2301
2086
|
});
|
|
2302
2087
|
|
|
2303
2088
|
// src/assets/types.ts
|
|
@@ -2307,8 +2092,8 @@ var init_types3 = () => {};
|
|
|
2307
2092
|
var defaultAdkFolder = ".adk";
|
|
2308
2093
|
|
|
2309
2094
|
// src/assets/cache.ts
|
|
2310
|
-
import
|
|
2311
|
-
import
|
|
2095
|
+
import fs7 from "fs/promises";
|
|
2096
|
+
import path7 from "path";
|
|
2312
2097
|
|
|
2313
2098
|
class AssetsCacheManager {
|
|
2314
2099
|
projectPath;
|
|
@@ -2316,14 +2101,14 @@ class AssetsCacheManager {
|
|
|
2316
2101
|
cache = null;
|
|
2317
2102
|
constructor(projectPath) {
|
|
2318
2103
|
this.projectPath = projectPath;
|
|
2319
|
-
this.cachePath =
|
|
2104
|
+
this.cachePath = path7.join(projectPath, defaultAdkFolder, "assets-cache.json");
|
|
2320
2105
|
}
|
|
2321
2106
|
async load() {
|
|
2322
2107
|
if (this.cache) {
|
|
2323
2108
|
return this.cache;
|
|
2324
2109
|
}
|
|
2325
2110
|
try {
|
|
2326
|
-
const content = await
|
|
2111
|
+
const content = await fs7.readFile(this.cachePath, "utf-8");
|
|
2327
2112
|
this.cache = JSON.parse(content);
|
|
2328
2113
|
return this.cache;
|
|
2329
2114
|
} catch {
|
|
@@ -2338,9 +2123,9 @@ class AssetsCacheManager {
|
|
|
2338
2123
|
if (!this.cache) {
|
|
2339
2124
|
return;
|
|
2340
2125
|
}
|
|
2341
|
-
const cacheDir =
|
|
2342
|
-
await
|
|
2343
|
-
await
|
|
2126
|
+
const cacheDir = path7.dirname(this.cachePath);
|
|
2127
|
+
await fs7.mkdir(cacheDir, { recursive: true });
|
|
2128
|
+
await fs7.writeFile(this.cachePath, JSON.stringify(this.cache, null, 2), "utf-8");
|
|
2344
2129
|
}
|
|
2345
2130
|
async getEntry(assetPath) {
|
|
2346
2131
|
const cache = await this.load();
|
|
@@ -2383,8 +2168,8 @@ class AssetsCacheManager {
|
|
|
2383
2168
|
var init_cache = () => {};
|
|
2384
2169
|
|
|
2385
2170
|
// src/assets/manager.ts
|
|
2386
|
-
import
|
|
2387
|
-
import
|
|
2171
|
+
import fs8 from "fs/promises";
|
|
2172
|
+
import path8 from "path";
|
|
2388
2173
|
import crypto from "crypto";
|
|
2389
2174
|
|
|
2390
2175
|
class AssetsManager {
|
|
@@ -2396,7 +2181,7 @@ class AssetsManager {
|
|
|
2396
2181
|
cacheManager;
|
|
2397
2182
|
constructor(options) {
|
|
2398
2183
|
this.projectPath = options.projectPath;
|
|
2399
|
-
this.assetsPath =
|
|
2184
|
+
this.assetsPath = path8.join(this.projectPath, "assets");
|
|
2400
2185
|
this.botId = options.botId;
|
|
2401
2186
|
this.credentials = options.credentials;
|
|
2402
2187
|
this.cacheManager = new AssetsCacheManager(this.projectPath);
|
|
@@ -2434,7 +2219,7 @@ class AssetsManager {
|
|
|
2434
2219
|
}
|
|
2435
2220
|
async hasAssetsDirectory() {
|
|
2436
2221
|
try {
|
|
2437
|
-
const stats = await
|
|
2222
|
+
const stats = await fs8.stat(this.assetsPath);
|
|
2438
2223
|
return stats.isDirectory();
|
|
2439
2224
|
} catch {
|
|
2440
2225
|
return false;
|
|
@@ -2448,16 +2233,16 @@ class AssetsManager {
|
|
|
2448
2233
|
const assets = [];
|
|
2449
2234
|
for (const filePath of files) {
|
|
2450
2235
|
try {
|
|
2451
|
-
const stats = await
|
|
2236
|
+
const stats = await fs8.stat(filePath);
|
|
2452
2237
|
if (stats.isFile()) {
|
|
2453
|
-
const relativePath =
|
|
2454
|
-
const content = await
|
|
2238
|
+
const relativePath = path8.relative(this.assetsPath, filePath);
|
|
2239
|
+
const content = await fs8.readFile(filePath);
|
|
2455
2240
|
const hash = this.calculateHash(content);
|
|
2456
2241
|
const mime = this.getMimeType(filePath);
|
|
2457
2242
|
assets.push({
|
|
2458
2243
|
relativePath,
|
|
2459
2244
|
absolutePath: filePath,
|
|
2460
|
-
name:
|
|
2245
|
+
name: path8.basename(filePath),
|
|
2461
2246
|
size: stats.size,
|
|
2462
2247
|
mime,
|
|
2463
2248
|
hash,
|
|
@@ -2485,7 +2270,7 @@ class AssetsManager {
|
|
|
2485
2270
|
});
|
|
2486
2271
|
return response.files.map((file) => ({
|
|
2487
2272
|
path: file.tags?.path || file.key,
|
|
2488
|
-
name:
|
|
2273
|
+
name: path8.basename(file.tags?.path || file.key),
|
|
2489
2274
|
size: file.size || 0,
|
|
2490
2275
|
mime: file.contentType,
|
|
2491
2276
|
hash: file.tags?.hash || "",
|
|
@@ -2623,7 +2408,7 @@ class AssetsManager {
|
|
|
2623
2408
|
};
|
|
2624
2409
|
}
|
|
2625
2410
|
async uploadAsset(client, localFile) {
|
|
2626
|
-
const content = await
|
|
2411
|
+
const content = await fs8.readFile(localFile.absolutePath);
|
|
2627
2412
|
await client.uploadFile({
|
|
2628
2413
|
key: localFile.relativePath,
|
|
2629
2414
|
content,
|
|
@@ -2716,10 +2501,10 @@ declare global {
|
|
|
2716
2501
|
return enrichedAssets;
|
|
2717
2502
|
}
|
|
2718
2503
|
async scanDirectory(dir, files = []) {
|
|
2719
|
-
const items = await
|
|
2504
|
+
const items = await fs8.readdir(dir);
|
|
2720
2505
|
for (const item of items) {
|
|
2721
|
-
const fullPath =
|
|
2722
|
-
const stats = await
|
|
2506
|
+
const fullPath = path8.join(dir, item);
|
|
2507
|
+
const stats = await fs8.stat(fullPath);
|
|
2723
2508
|
if (stats.isDirectory()) {
|
|
2724
2509
|
await this.scanDirectory(fullPath, files);
|
|
2725
2510
|
} else {
|
|
@@ -2732,7 +2517,7 @@ declare global {
|
|
|
2732
2517
|
return crypto.createHash("sha256").update(content).digest("hex");
|
|
2733
2518
|
}
|
|
2734
2519
|
getMimeType(filePath) {
|
|
2735
|
-
const ext =
|
|
2520
|
+
const ext = path8.extname(filePath).toLowerCase();
|
|
2736
2521
|
const mimeTypes = {
|
|
2737
2522
|
".png": "image/png",
|
|
2738
2523
|
".jpg": "image/jpeg",
|
|
@@ -2766,12 +2551,12 @@ var init_manager2 = __esm(() => {
|
|
|
2766
2551
|
});
|
|
2767
2552
|
|
|
2768
2553
|
// src/utils/fs.ts
|
|
2769
|
-
import { mkdir, writeFile } from "fs/promises";
|
|
2554
|
+
import { mkdir, writeFile as writeFile2 } from "fs/promises";
|
|
2770
2555
|
import { parse } from "path";
|
|
2771
|
-
var createFile = async (
|
|
2772
|
-
const file = parse(
|
|
2556
|
+
var createFile = async (path9, content) => {
|
|
2557
|
+
const file = parse(path9);
|
|
2773
2558
|
await mkdir(file.dir, { recursive: true });
|
|
2774
|
-
await
|
|
2559
|
+
await writeFile2(path9, content);
|
|
2775
2560
|
};
|
|
2776
2561
|
var init_fs = () => {};
|
|
2777
2562
|
|
|
@@ -2789,19 +2574,19 @@ var init_assets = __esm(() => {
|
|
|
2789
2574
|
});
|
|
2790
2575
|
|
|
2791
2576
|
// src/integrations/cache.ts
|
|
2792
|
-
import
|
|
2793
|
-
import
|
|
2794
|
-
import
|
|
2577
|
+
import fs9 from "fs/promises";
|
|
2578
|
+
import path9 from "path";
|
|
2579
|
+
import os5 from "os";
|
|
2795
2580
|
|
|
2796
2581
|
class IntegrationCache {
|
|
2797
2582
|
cacheDir;
|
|
2798
2583
|
integrationsDir;
|
|
2799
2584
|
constructor() {
|
|
2800
|
-
this.cacheDir =
|
|
2801
|
-
this.integrationsDir =
|
|
2585
|
+
this.cacheDir = path9.join(os5.homedir(), ".adk", "cache");
|
|
2586
|
+
this.integrationsDir = path9.join(this.cacheDir, "integrations");
|
|
2802
2587
|
}
|
|
2803
2588
|
async ensureCacheDir() {
|
|
2804
|
-
await
|
|
2589
|
+
await fs9.mkdir(this.integrationsDir, { recursive: true });
|
|
2805
2590
|
}
|
|
2806
2591
|
getCacheKey(integrationId, updatedAt) {
|
|
2807
2592
|
const sanitizedId = integrationId.replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
@@ -2811,8 +2596,8 @@ class IntegrationCache {
|
|
|
2811
2596
|
async get(integrationId, updatedAt) {
|
|
2812
2597
|
try {
|
|
2813
2598
|
const cacheKey = this.getCacheKey(integrationId, updatedAt);
|
|
2814
|
-
const cachePath =
|
|
2815
|
-
const data = await
|
|
2599
|
+
const cachePath = path9.join(this.integrationsDir, cacheKey);
|
|
2600
|
+
const data = await fs9.readFile(cachePath, "utf-8");
|
|
2816
2601
|
const cached = JSON.parse(data);
|
|
2817
2602
|
if (cached.expiresAt) {
|
|
2818
2603
|
const expiryDate = new Date(cached.expiresAt);
|
|
@@ -2829,7 +2614,7 @@ class IntegrationCache {
|
|
|
2829
2614
|
async set(integrationId, updatedAt, definition, ttlHours = 24 * 7) {
|
|
2830
2615
|
await this.ensureCacheDir();
|
|
2831
2616
|
const cacheKey = this.getCacheKey(integrationId, updatedAt);
|
|
2832
|
-
const cachePath =
|
|
2617
|
+
const cachePath = path9.join(this.integrationsDir, cacheKey);
|
|
2833
2618
|
const expiresAt = new Date;
|
|
2834
2619
|
expiresAt.setHours(expiresAt.getHours() + ttlHours);
|
|
2835
2620
|
const cacheEntry = {
|
|
@@ -2837,27 +2622,27 @@ class IntegrationCache {
|
|
|
2837
2622
|
cachedAt: new Date().toISOString(),
|
|
2838
2623
|
expiresAt: expiresAt.toISOString()
|
|
2839
2624
|
};
|
|
2840
|
-
await
|
|
2625
|
+
await fs9.writeFile(cachePath, JSON.stringify(cacheEntry, null, 2));
|
|
2841
2626
|
}
|
|
2842
2627
|
async remove(integrationId, updatedAt) {
|
|
2843
2628
|
try {
|
|
2844
2629
|
const cacheKey = this.getCacheKey(integrationId, updatedAt);
|
|
2845
|
-
const cachePath =
|
|
2846
|
-
await
|
|
2630
|
+
const cachePath = path9.join(this.integrationsDir, cacheKey);
|
|
2631
|
+
await fs9.unlink(cachePath);
|
|
2847
2632
|
} catch {}
|
|
2848
2633
|
}
|
|
2849
2634
|
async clear() {
|
|
2850
2635
|
try {
|
|
2851
|
-
const files = await
|
|
2852
|
-
await Promise.all(files.map((file) =>
|
|
2636
|
+
const files = await fs9.readdir(this.integrationsDir);
|
|
2637
|
+
await Promise.all(files.map((file) => fs9.unlink(path9.join(this.integrationsDir, file))));
|
|
2853
2638
|
} catch {}
|
|
2854
2639
|
}
|
|
2855
2640
|
async getStats() {
|
|
2856
2641
|
try {
|
|
2857
|
-
const files = await
|
|
2642
|
+
const files = await fs9.readdir(this.integrationsDir);
|
|
2858
2643
|
let totalSize = 0;
|
|
2859
2644
|
for (const file of files) {
|
|
2860
|
-
const stats = await
|
|
2645
|
+
const stats = await fs9.stat(path9.join(this.integrationsDir, file));
|
|
2861
2646
|
totalSize += stats.size;
|
|
2862
2647
|
}
|
|
2863
2648
|
return {
|
|
@@ -2882,7 +2667,7 @@ async function fetchServerIntegrationConfigs(project, targetBotId) {
|
|
|
2882
2667
|
const { devId, botId } = project.agentInfo ?? {};
|
|
2883
2668
|
const targetId = targetBotId || devId || botId;
|
|
2884
2669
|
if (!targetId) {
|
|
2885
|
-
return { configs: {}, enabledStates: {},
|
|
2670
|
+
return { configs: {}, enabledStates: {}, fetched: false, skipped: true };
|
|
2886
2671
|
}
|
|
2887
2672
|
try {
|
|
2888
2673
|
const client = await getProjectClient({
|
|
@@ -2905,7 +2690,6 @@ async function fetchServerIntegrationConfigs(project, targetBotId) {
|
|
|
2905
2690
|
return {
|
|
2906
2691
|
configs: {},
|
|
2907
2692
|
enabledStates: {},
|
|
2908
|
-
authorizedStates: {},
|
|
2909
2693
|
fetched: false,
|
|
2910
2694
|
skipped: false,
|
|
2911
2695
|
error: message
|
|
@@ -2916,15 +2700,13 @@ async function fetchBotConfigs(client, botId) {
|
|
|
2916
2700
|
const { bot } = await client.getBot({ id: botId });
|
|
2917
2701
|
const configs = {};
|
|
2918
2702
|
const enabledStates = {};
|
|
2919
|
-
const authorizedStates = {};
|
|
2920
2703
|
for (const [alias, integration] of Object.entries(bot.integrations || {})) {
|
|
2921
2704
|
if (integration.configuration && Object.keys(integration.configuration).length > 0) {
|
|
2922
2705
|
configs[alias] = integration.configuration;
|
|
2923
2706
|
}
|
|
2924
2707
|
enabledStates[alias] = integration.enabled;
|
|
2925
|
-
authorizedStates[alias] = !!integration.identifier;
|
|
2926
2708
|
}
|
|
2927
|
-
return { configs, enabledStates,
|
|
2709
|
+
return { configs, enabledStates, fetched: true, skipped: false };
|
|
2928
2710
|
}
|
|
2929
2711
|
async function fetchServerPluginConfigs(project, targetBotId) {
|
|
2930
2712
|
const { devId, botId } = project.agentInfo ?? {};
|
|
@@ -2971,9 +2753,121 @@ var init_integrations = __esm(() => {
|
|
|
2971
2753
|
init_manager();
|
|
2972
2754
|
init_dependencies_parser();
|
|
2973
2755
|
init_cache2();
|
|
2756
|
+
init_enhanced_cache();
|
|
2974
2757
|
init_config_utils();
|
|
2975
2758
|
});
|
|
2976
2759
|
|
|
2760
|
+
// src/interfaces/enhanced-cache.ts
|
|
2761
|
+
import fs10 from "fs/promises";
|
|
2762
|
+
import path10 from "path";
|
|
2763
|
+
import os6 from "os";
|
|
2764
|
+
|
|
2765
|
+
class EnhancedInterfaceCache {
|
|
2766
|
+
cacheDir;
|
|
2767
|
+
resolutionsDir;
|
|
2768
|
+
definitionsDir;
|
|
2769
|
+
noCache;
|
|
2770
|
+
constructor(noCache = false) {
|
|
2771
|
+
this.noCache = noCache;
|
|
2772
|
+
this.cacheDir = path10.join(os6.homedir(), ".adk", "cache", "interfaces");
|
|
2773
|
+
this.resolutionsDir = path10.join(this.cacheDir, "resolutions");
|
|
2774
|
+
this.definitionsDir = path10.join(this.cacheDir, "definitions");
|
|
2775
|
+
}
|
|
2776
|
+
async ensureCacheDirs() {
|
|
2777
|
+
await fs10.mkdir(this.resolutionsDir, { recursive: true });
|
|
2778
|
+
await fs10.mkdir(this.definitionsDir, { recursive: true });
|
|
2779
|
+
}
|
|
2780
|
+
async getResolution(name, version, workspace) {
|
|
2781
|
+
if (this.noCache)
|
|
2782
|
+
return null;
|
|
2783
|
+
try {
|
|
2784
|
+
const key = this.getResolutionKey(name, version, workspace);
|
|
2785
|
+
const cachePath = path10.join(this.resolutionsDir, `${key}.json`);
|
|
2786
|
+
const data = await fs10.readFile(cachePath, "utf-8");
|
|
2787
|
+
const resolution = JSON.parse(data);
|
|
2788
|
+
const cachedAt = new Date(resolution.cachedAt);
|
|
2789
|
+
const ageMinutes = (Date.now() - cachedAt.getTime()) / (1000 * 60);
|
|
2790
|
+
if (ageMinutes > 5)
|
|
2791
|
+
return null;
|
|
2792
|
+
return resolution;
|
|
2793
|
+
} catch {
|
|
2794
|
+
return null;
|
|
2795
|
+
}
|
|
2796
|
+
}
|
|
2797
|
+
async setResolution(name, version, workspace, interfaceId, updatedAt) {
|
|
2798
|
+
await this.ensureCacheDirs();
|
|
2799
|
+
const key = this.getResolutionKey(name, version, workspace);
|
|
2800
|
+
const cachePath = path10.join(this.resolutionsDir, `${key}.json`);
|
|
2801
|
+
const resolution = {
|
|
2802
|
+
interfaceId,
|
|
2803
|
+
updatedAt,
|
|
2804
|
+
cachedAt: new Date().toISOString()
|
|
2805
|
+
};
|
|
2806
|
+
await fs10.writeFile(cachePath, JSON.stringify(resolution));
|
|
2807
|
+
}
|
|
2808
|
+
async getDefinition(interfaceId, updatedAt) {
|
|
2809
|
+
if (this.noCache)
|
|
2810
|
+
return null;
|
|
2811
|
+
try {
|
|
2812
|
+
const key = this.getDefinitionKey(interfaceId, updatedAt);
|
|
2813
|
+
const cachePath = path10.join(this.definitionsDir, `${key}.json`);
|
|
2814
|
+
const data = await fs10.readFile(cachePath, "utf-8");
|
|
2815
|
+
const cached = JSON.parse(data);
|
|
2816
|
+
return cached.definition;
|
|
2817
|
+
} catch {
|
|
2818
|
+
return null;
|
|
2819
|
+
}
|
|
2820
|
+
}
|
|
2821
|
+
async setDefinition(interfaceId, updatedAt, definition) {
|
|
2822
|
+
await this.ensureCacheDirs();
|
|
2823
|
+
const key = this.getDefinitionKey(interfaceId, updatedAt);
|
|
2824
|
+
const cachePath = path10.join(this.definitionsDir, `${key}.json`);
|
|
2825
|
+
const cached = {
|
|
2826
|
+
definition,
|
|
2827
|
+
cachedAt: new Date().toISOString()
|
|
2828
|
+
};
|
|
2829
|
+
await fs10.writeFile(cachePath, JSON.stringify(cached));
|
|
2830
|
+
}
|
|
2831
|
+
async clear() {
|
|
2832
|
+
try {
|
|
2833
|
+
const resolutionFiles = await fs10.readdir(this.resolutionsDir);
|
|
2834
|
+
await Promise.all(resolutionFiles.map((f) => fs10.unlink(path10.join(this.resolutionsDir, f))));
|
|
2835
|
+
const definitionFiles = await fs10.readdir(this.definitionsDir);
|
|
2836
|
+
await Promise.all(definitionFiles.map((f) => fs10.unlink(path10.join(this.definitionsDir, f))));
|
|
2837
|
+
} catch {}
|
|
2838
|
+
}
|
|
2839
|
+
async getStats() {
|
|
2840
|
+
const getDirectoryStats = async (dir) => {
|
|
2841
|
+
try {
|
|
2842
|
+
const files = await fs10.readdir(dir);
|
|
2843
|
+
let totalSize = 0;
|
|
2844
|
+
for (const file of files) {
|
|
2845
|
+
const stats = await fs10.stat(path10.join(dir, file));
|
|
2846
|
+
totalSize += stats.size;
|
|
2847
|
+
}
|
|
2848
|
+
return { count: files.length, sizeBytes: totalSize };
|
|
2849
|
+
} catch {
|
|
2850
|
+
return { count: 0, sizeBytes: 0 };
|
|
2851
|
+
}
|
|
2852
|
+
};
|
|
2853
|
+
const [resolutions, definitions] = await Promise.all([
|
|
2854
|
+
getDirectoryStats(this.resolutionsDir),
|
|
2855
|
+
getDirectoryStats(this.definitionsDir)
|
|
2856
|
+
]);
|
|
2857
|
+
return { resolutions, definitions };
|
|
2858
|
+
}
|
|
2859
|
+
getResolutionKey(name, version, workspace) {
|
|
2860
|
+
const prefix = workspace ? `${workspace}_` : "";
|
|
2861
|
+
const key = `${prefix}${name}_${version}`;
|
|
2862
|
+
return key.replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
2863
|
+
}
|
|
2864
|
+
getDefinitionKey(interfaceId, updatedAt) {
|
|
2865
|
+
const key = `${interfaceId}_${updatedAt}`;
|
|
2866
|
+
return key.replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
2867
|
+
}
|
|
2868
|
+
}
|
|
2869
|
+
var init_enhanced_cache2 = () => {};
|
|
2870
|
+
|
|
2977
2871
|
// src/interfaces/parser.ts
|
|
2978
2872
|
class InterfaceParser {
|
|
2979
2873
|
static parseInterfaceRef(versionString) {
|
|
@@ -3022,15 +2916,66 @@ var init_parser = __esm(() => {
|
|
|
3022
2916
|
init_constants();
|
|
3023
2917
|
});
|
|
3024
2918
|
|
|
3025
|
-
// src/
|
|
3026
|
-
class
|
|
3027
|
-
|
|
3028
|
-
|
|
3029
|
-
|
|
3030
|
-
|
|
3031
|
-
|
|
3032
|
-
|
|
3033
|
-
|
|
2919
|
+
// src/interfaces/manager.ts
|
|
2920
|
+
class InterfaceManager {
|
|
2921
|
+
cache;
|
|
2922
|
+
options;
|
|
2923
|
+
client;
|
|
2924
|
+
constructor(options = {}) {
|
|
2925
|
+
this.options = options;
|
|
2926
|
+
this.cache = new EnhancedInterfaceCache(options.noCache || false);
|
|
2927
|
+
}
|
|
2928
|
+
async getClient() {
|
|
2929
|
+
if (!this.client) {
|
|
2930
|
+
this.client = await getProjectClient({
|
|
2931
|
+
project: this.options.project,
|
|
2932
|
+
credentials: this.options.credentials,
|
|
2933
|
+
apiUrl: this.options.apiUrl,
|
|
2934
|
+
workspaceId: this.options.workspaceId,
|
|
2935
|
+
headers: {
|
|
2936
|
+
"x-multiple-integrations": "true"
|
|
2937
|
+
}
|
|
2938
|
+
});
|
|
2939
|
+
}
|
|
2940
|
+
return this.client;
|
|
2941
|
+
}
|
|
2942
|
+
async loadInterfaces(dependencies) {
|
|
2943
|
+
const errors = [];
|
|
2944
|
+
const warnings = [];
|
|
2945
|
+
const parseResult = InterfaceParser.parseInterfaces(dependencies);
|
|
2946
|
+
const interfaces = parseResult.interfaces;
|
|
2947
|
+
errors.push(...parseResult.errors);
|
|
2948
|
+
const fetchPromises = interfaces.map(async (intf) => {
|
|
2949
|
+
try {
|
|
2950
|
+
const definition = await this.fetchInterface(intf.ref);
|
|
2951
|
+
intf.definition = definition;
|
|
2952
|
+
const validation = this.validateInterface(intf);
|
|
2953
|
+
intf.validationResult = validation;
|
|
2954
|
+
if (!validation.valid) {
|
|
2955
|
+
validation.errors.forEach((msg) => {
|
|
2956
|
+
errors.push(ValidationErrors.warning(msg, "agent.config.ts"));
|
|
2957
|
+
});
|
|
2958
|
+
}
|
|
2959
|
+
} catch (error) {
|
|
2960
|
+
if (error instanceof Error && error.message.includes("version")) {
|
|
2961
|
+
errors.push(ValidationErrors.unknownInterface(error.message));
|
|
2962
|
+
} else {
|
|
2963
|
+
errors.push(ValidationErrors.invalidDependenciesSyntax(`Unknown interface '${intf.alias}' (${intf.ref.fullName})`));
|
|
2964
|
+
}
|
|
2965
|
+
}
|
|
2966
|
+
});
|
|
2967
|
+
await Promise.all(fetchPromises);
|
|
2968
|
+
return { interfaces, errors, warnings };
|
|
2969
|
+
}
|
|
2970
|
+
async fetchInterface(ref) {
|
|
2971
|
+
const cachedResolution = await this.cache.getResolution(ref.name, ref.version, ref.workspace);
|
|
2972
|
+
if (cachedResolution) {
|
|
2973
|
+
const cachedDefinition = await this.cache.getDefinition(cachedResolution.interfaceId, cachedResolution.updatedAt);
|
|
2974
|
+
if (cachedDefinition) {
|
|
2975
|
+
return cachedDefinition;
|
|
2976
|
+
}
|
|
2977
|
+
}
|
|
2978
|
+
const client = await this.getClient();
|
|
3034
2979
|
let interfaceResponse;
|
|
3035
2980
|
let versionError = null;
|
|
3036
2981
|
try {
|
|
@@ -3074,56 +3019,32 @@ class InterfaceCatalogSource {
|
|
|
3074
3019
|
}
|
|
3075
3020
|
const location = ref.workspace ? `workspace "${ref.workspace}"` : "Botpress";
|
|
3076
3021
|
throw new AdkError({
|
|
3077
|
-
code: "
|
|
3078
|
-
message: `Interface "${ref.name}" version "${ref.version}" not found in ${location}. Latest available version is "${latestVersion}"`,
|
|
3022
|
+
code: "INTERFACE_VERSION_NOT_FOUND",
|
|
3023
|
+
message: `Interface "${ref.name}" version "${ref.version}" not found in ${location}. Latest available version is "${latestVersion}"`,
|
|
3024
|
+
expected: true
|
|
3025
|
+
});
|
|
3026
|
+
}
|
|
3027
|
+
const intf = interfaceResponse.interface;
|
|
3028
|
+
await this.cache.setResolution(ref.name, ref.version, ref.workspace, intf.id, intf.updatedAt);
|
|
3029
|
+
await this.cache.setDefinition(intf.id, intf.updatedAt, intf);
|
|
3030
|
+
return intf;
|
|
3031
|
+
}
|
|
3032
|
+
async getByDependencyString(dep) {
|
|
3033
|
+
const match = dep.match(/^(?:([^/]+)\/)?([^@]+)@(.+)$/);
|
|
3034
|
+
if (!match) {
|
|
3035
|
+
throw new AdkError({
|
|
3036
|
+
code: "INVALID_VERSION_FORMAT",
|
|
3037
|
+
message: `Invalid interface dependency string: ${dep}. Expected 'name@version' or 'workspace/name@version'`,
|
|
3079
3038
|
expected: true
|
|
3080
3039
|
});
|
|
3081
3040
|
}
|
|
3082
|
-
const
|
|
3083
|
-
return {
|
|
3084
|
-
|
|
3085
|
-
|
|
3086
|
-
|
|
3087
|
-
|
|
3088
|
-
});
|
|
3089
|
-
|
|
3090
|
-
// src/interfaces/manager.ts
|
|
3091
|
-
class InterfaceManager {
|
|
3092
|
-
service;
|
|
3093
|
-
constructor(options = {}) {
|
|
3094
|
-
const { noCache, ...clientOptions } = options;
|
|
3095
|
-
this.service = new CatalogService(new InterfaceCatalogSource(new CatalogClientFactory(clientOptions)), noCache || false);
|
|
3096
|
-
}
|
|
3097
|
-
async loadInterfaces(dependencies) {
|
|
3098
|
-
const errors = [];
|
|
3099
|
-
const warnings = [];
|
|
3100
|
-
const parseResult = InterfaceParser.parseInterfaces(dependencies);
|
|
3101
|
-
const interfaces = parseResult.interfaces;
|
|
3102
|
-
errors.push(...parseResult.errors);
|
|
3103
|
-
const fetchPromises = interfaces.map(async (intf) => {
|
|
3104
|
-
try {
|
|
3105
|
-
const definition = await this.fetchInterface(intf.ref);
|
|
3106
|
-
intf.definition = definition;
|
|
3107
|
-
const validation = this.validateInterface(intf);
|
|
3108
|
-
intf.validationResult = validation;
|
|
3109
|
-
if (!validation.valid) {
|
|
3110
|
-
validation.errors.forEach((msg) => {
|
|
3111
|
-
errors.push(ValidationErrors.warning(msg, "agent.config.ts"));
|
|
3112
|
-
});
|
|
3113
|
-
}
|
|
3114
|
-
} catch (error) {
|
|
3115
|
-
if (error instanceof Error && error.message.includes("version")) {
|
|
3116
|
-
errors.push(ValidationErrors.unknownInterface(error.message));
|
|
3117
|
-
} else {
|
|
3118
|
-
errors.push(ValidationErrors.invalidDependenciesSyntax(`Unknown interface '${intf.alias}' (${intf.ref.fullName})`));
|
|
3119
|
-
}
|
|
3120
|
-
}
|
|
3041
|
+
const [, workspace, name, version] = match;
|
|
3042
|
+
return this.fetchInterface({
|
|
3043
|
+
workspace: workspace || undefined,
|
|
3044
|
+
name,
|
|
3045
|
+
version,
|
|
3046
|
+
fullName: workspace ? `${workspace}/${name}` : name
|
|
3121
3047
|
});
|
|
3122
|
-
await Promise.all(fetchPromises);
|
|
3123
|
-
return { interfaces, errors, warnings };
|
|
3124
|
-
}
|
|
3125
|
-
async fetchInterface(ref) {
|
|
3126
|
-
return this.service.getDefinition(ref);
|
|
3127
3048
|
}
|
|
3128
3049
|
validateInterface(intf) {
|
|
3129
3050
|
const errors = [];
|
|
@@ -3135,56 +3056,28 @@ class InterfaceManager {
|
|
|
3135
3056
|
return { valid: errors.length === 0, errors, warnings };
|
|
3136
3057
|
}
|
|
3137
3058
|
async getCacheStats() {
|
|
3138
|
-
|
|
3059
|
+
const stats = await this.cache.getStats();
|
|
3060
|
+
return {
|
|
3061
|
+
count: stats.resolutions.count + stats.definitions.count,
|
|
3062
|
+
sizeBytes: stats.resolutions.sizeBytes + stats.definitions.sizeBytes
|
|
3063
|
+
};
|
|
3139
3064
|
}
|
|
3140
3065
|
async clearCache() {
|
|
3141
|
-
await this.
|
|
3066
|
+
await this.cache.clear();
|
|
3142
3067
|
}
|
|
3143
3068
|
}
|
|
3144
3069
|
var init_manager3 = __esm(() => {
|
|
3070
|
+
init_src();
|
|
3071
|
+
init_auth();
|
|
3072
|
+
init_enhanced_cache2();
|
|
3145
3073
|
init_parser();
|
|
3146
3074
|
init_validation_errors();
|
|
3147
|
-
init_client_factory();
|
|
3148
|
-
init_catalog_service();
|
|
3149
|
-
init_interface_source();
|
|
3150
|
-
});
|
|
3151
|
-
|
|
3152
|
-
// src/interfaces/enhanced-cache.ts
|
|
3153
|
-
class EnhancedInterfaceCache {
|
|
3154
|
-
cache;
|
|
3155
|
-
constructor(noCache = false) {
|
|
3156
|
-
this.cache = new ResolutionCache({ cacheType: "interfaces", idField: "interfaceId" }, noCache);
|
|
3157
|
-
}
|
|
3158
|
-
async getResolution(name, version, workspace) {
|
|
3159
|
-
const resolution = await this.cache.getResolution(name, version, workspace);
|
|
3160
|
-
if (!resolution)
|
|
3161
|
-
return null;
|
|
3162
|
-
return { interfaceId: resolution.id, updatedAt: resolution.updatedAt, cachedAt: resolution.cachedAt };
|
|
3163
|
-
}
|
|
3164
|
-
async setResolution(name, version, workspace, interfaceId, updatedAt) {
|
|
3165
|
-
await this.cache.setResolution(name, version, workspace, interfaceId, updatedAt);
|
|
3166
|
-
}
|
|
3167
|
-
async getDefinition(interfaceId, updatedAt) {
|
|
3168
|
-
return this.cache.getDefinition(interfaceId, updatedAt);
|
|
3169
|
-
}
|
|
3170
|
-
async setDefinition(interfaceId, updatedAt, definition) {
|
|
3171
|
-
await this.cache.setDefinition(interfaceId, updatedAt, definition);
|
|
3172
|
-
}
|
|
3173
|
-
async clear() {
|
|
3174
|
-
await this.cache.clear();
|
|
3175
|
-
}
|
|
3176
|
-
async getStats() {
|
|
3177
|
-
return this.cache.getStats();
|
|
3178
|
-
}
|
|
3179
|
-
}
|
|
3180
|
-
var init_enhanced_cache = __esm(() => {
|
|
3181
|
-
init_resolution_cache();
|
|
3182
3075
|
});
|
|
3183
3076
|
// src/interfaces/index.ts
|
|
3184
3077
|
var init_interfaces = __esm(() => {
|
|
3185
3078
|
init_manager3();
|
|
3186
3079
|
init_parser();
|
|
3187
|
-
|
|
3080
|
+
init_enhanced_cache2();
|
|
3188
3081
|
});
|
|
3189
3082
|
|
|
3190
3083
|
// src/utils/json-ordering.ts
|
|
@@ -3346,7 +3239,7 @@ var init_component_files = __esm(() => {
|
|
|
3346
3239
|
// src/agent-project/component-source-resolver.ts
|
|
3347
3240
|
import { Project, SyntaxKind } from "ts-morph";
|
|
3348
3241
|
import { readFileSync } from "fs";
|
|
3349
|
-
import * as
|
|
3242
|
+
import * as path11 from "path";
|
|
3350
3243
|
function resolveComponentSources(absolutePath) {
|
|
3351
3244
|
const project = new Project({ useInMemoryFileSystem: false, skipAddingFilesFromTsConfig: true });
|
|
3352
3245
|
const sourceFile = project.createSourceFile(absolutePath, readFileSync(absolutePath, "utf-8"), { overwrite: true });
|
|
@@ -3359,12 +3252,12 @@ function resolveComponentSources(absolutePath) {
|
|
|
3359
3252
|
}
|
|
3360
3253
|
function collectBpTsxImports(sourceFile, absolutePath) {
|
|
3361
3254
|
const imports = new Map;
|
|
3362
|
-
const dir =
|
|
3255
|
+
const dir = path11.dirname(absolutePath);
|
|
3363
3256
|
for (const decl of sourceFile.getImportDeclarations()) {
|
|
3364
3257
|
const specifier = decl.getModuleSpecifierValue();
|
|
3365
3258
|
if (!specifier.endsWith(BP_TSX_SUFFIX))
|
|
3366
3259
|
continue;
|
|
3367
|
-
const resolved =
|
|
3260
|
+
const resolved = path11.resolve(dir, specifier);
|
|
3368
3261
|
const defaultImport = decl.getDefaultImport();
|
|
3369
3262
|
if (defaultImport) {
|
|
3370
3263
|
imports.set(defaultImport.getText(), resolved);
|
|
@@ -3402,385 +3295,84 @@ function resolveExports(sourceFile, localToSource, importBindings) {
|
|
|
3402
3295
|
exportMap.set(decl.getName(), source);
|
|
3403
3296
|
}
|
|
3404
3297
|
}
|
|
3405
|
-
for (const assignment of sourceFile.getExportAssignments()) {
|
|
3406
|
-
if (assignment.isExportEquals())
|
|
3407
|
-
continue;
|
|
3408
|
-
const expr = assignment.getExpression();
|
|
3409
|
-
const direct = sourceFromCustomComponentExpr(expr, importBindings);
|
|
3410
|
-
if (direct) {
|
|
3411
|
-
exportMap.set("default", direct);
|
|
3412
|
-
continue;
|
|
3413
|
-
}
|
|
3414
|
-
if (expr.getKind() === SyntaxKind.Identifier) {
|
|
3415
|
-
const fromLocal = localToSource.get(expr.getText());
|
|
3416
|
-
if (fromLocal)
|
|
3417
|
-
exportMap.set("default", fromLocal);
|
|
3418
|
-
}
|
|
3419
|
-
}
|
|
3420
|
-
for (const decl of sourceFile.getExportDeclarations()) {
|
|
3421
|
-
if (decl.getModuleSpecifier())
|
|
3422
|
-
continue;
|
|
3423
|
-
for (const named of decl.getNamedExports()) {
|
|
3424
|
-
const localName = named.getNameNode().getText();
|
|
3425
|
-
const aliasNode = named.getAliasNode();
|
|
3426
|
-
const exportName = aliasNode ? aliasNode.getText() : localName;
|
|
3427
|
-
const source = localToSource.get(localName);
|
|
3428
|
-
if (source)
|
|
3429
|
-
exportMap.set(exportName, source);
|
|
3430
|
-
}
|
|
3431
|
-
}
|
|
3432
|
-
return exportMap;
|
|
3433
|
-
}
|
|
3434
|
-
function sourceFromCustomComponentExpr(expr, importBindings) {
|
|
3435
|
-
if (expr.getKind() !== SyntaxKind.NewExpression)
|
|
3436
|
-
return;
|
|
3437
|
-
const newExpr = expr.asKindOrThrow(SyntaxKind.NewExpression);
|
|
3438
|
-
if (newExpr.getExpression().getText() !== CUSTOM_COMPONENT_CLASS)
|
|
3439
|
-
return;
|
|
3440
|
-
const args = newExpr.getArguments();
|
|
3441
|
-
const firstArg = args[0];
|
|
3442
|
-
if (!firstArg || firstArg.getKind() !== SyntaxKind.Identifier)
|
|
3443
|
-
return;
|
|
3444
|
-
return importBindings.get(firstArg.getText());
|
|
3445
|
-
}
|
|
3446
|
-
var CUSTOM_COMPONENT_CLASS = "CustomComponent";
|
|
3447
|
-
var init_component_source_resolver = __esm(() => {
|
|
3448
|
-
init_component_files();
|
|
3449
|
-
});
|
|
3450
|
-
|
|
3451
|
-
// src/bot-generator/table-validation.ts
|
|
3452
|
-
function getColumnCount(table) {
|
|
3453
|
-
const properties = table.definition.schema?.properties;
|
|
3454
|
-
return properties ? Object.keys(properties).length : 0;
|
|
3455
|
-
}
|
|
3456
|
-
function findTableColumnViolations(tables, max = MAX_TABLE_COLUMNS) {
|
|
3457
|
-
return tables.map((table) => ({
|
|
3458
|
-
name: table.definition.name,
|
|
3459
|
-
path: table.path,
|
|
3460
|
-
columnCount: getColumnCount(table)
|
|
3461
|
-
})).filter((t) => t.columnCount > max);
|
|
3462
|
-
}
|
|
3463
|
-
var init_table_validation = __esm(() => {
|
|
3464
|
-
init_constants();
|
|
3465
|
-
});
|
|
3466
|
-
|
|
3467
|
-
// src/dependencies/alias-utils.ts
|
|
3468
|
-
function isBotpressInternalId(alias) {
|
|
3469
|
-
return BP_INTERNAL_ID_PREFIXES.some((prefix) => alias.startsWith(prefix));
|
|
3470
|
-
}
|
|
3471
|
-
function isFriendlyAlias(alias) {
|
|
3472
|
-
return FRIENDLY_ALIAS_RE.test(alias) && !isBotpressInternalId(alias);
|
|
3473
|
-
}
|
|
3474
|
-
function generateFriendlyAlias(cloudName, cloudAlias, used) {
|
|
3475
|
-
if (isFriendlyAlias(cloudAlias) && !used.has(cloudAlias))
|
|
3476
|
-
return cloudAlias;
|
|
3477
|
-
const base = cloudName?.split("/").at(-1) ?? cloudAlias;
|
|
3478
|
-
const sanitized = base.toLowerCase().replace(/[^a-z0-9_-]/g, "-");
|
|
3479
|
-
let candidate = sanitized;
|
|
3480
|
-
let n = 2;
|
|
3481
|
-
while (used.has(candidate)) {
|
|
3482
|
-
candidate = `${sanitized}-${n}`;
|
|
3483
|
-
n++;
|
|
3484
|
-
}
|
|
3485
|
-
return candidate;
|
|
3486
|
-
}
|
|
3487
|
-
var FRIENDLY_ALIAS_RE, BP_INTERNAL_ID_PREFIXES;
|
|
3488
|
-
var init_alias_utils = __esm(() => {
|
|
3489
|
-
FRIENDLY_ALIAS_RE = /^[a-z0-9_-]{2,100}$/;
|
|
3490
|
-
BP_INTERNAL_ID_PREFIXES = ["intver_", "plgver_", "int_", "plg_"];
|
|
3491
|
-
});
|
|
3492
|
-
|
|
3493
|
-
// src/dependencies/snapshot-store.ts
|
|
3494
|
-
import * as fs8 from "fs/promises";
|
|
3495
|
-
import * as path9 from "path";
|
|
3496
|
-
|
|
3497
|
-
class DependencySnapshotStore {
|
|
3498
|
-
projectPath;
|
|
3499
|
-
dirPath;
|
|
3500
|
-
constructor(opts) {
|
|
3501
|
-
this.projectPath = opts.projectPath;
|
|
3502
|
-
this.dirPath = path9.join(opts.projectPath, ".adk", "dependencies");
|
|
3503
|
-
}
|
|
3504
|
-
getSnapshotPath(env) {
|
|
3505
|
-
return path9.join(this.dirPath, `${env}.json`);
|
|
3506
|
-
}
|
|
3507
|
-
getMigrationMarkerPath() {
|
|
3508
|
-
return path9.join(this.dirPath, "migration.json");
|
|
3509
|
-
}
|
|
3510
|
-
async exists(env) {
|
|
3511
|
-
try {
|
|
3512
|
-
await fs8.access(this.getSnapshotPath(env));
|
|
3513
|
-
return true;
|
|
3514
|
-
} catch {
|
|
3515
|
-
return false;
|
|
3516
|
-
}
|
|
3517
|
-
}
|
|
3518
|
-
async read(env, options) {
|
|
3519
|
-
const filePath = this.getSnapshotPath(env);
|
|
3520
|
-
let raw;
|
|
3521
|
-
try {
|
|
3522
|
-
raw = await fs8.readFile(filePath, "utf8");
|
|
3523
|
-
} catch (err) {
|
|
3524
|
-
if (err.code === "ENOENT")
|
|
3525
|
-
return null;
|
|
3526
|
-
throw err;
|
|
3527
|
-
}
|
|
3528
|
-
try {
|
|
3529
|
-
return dependencySnapshotSchema.parse(JSON.parse(raw));
|
|
3530
|
-
} catch (err) {
|
|
3531
|
-
if (options?.tolerant)
|
|
3532
|
-
return null;
|
|
3533
|
-
throw new DependencyError({
|
|
3534
|
-
code: "INVALID_CONFIG",
|
|
3535
|
-
message: `Dependency snapshot at ${filePath} failed schema validation`,
|
|
3536
|
-
details: { issues: err.issues ?? String(err) }
|
|
3537
|
-
});
|
|
3538
|
-
}
|
|
3539
|
-
}
|
|
3540
|
-
async readOrEmpty(env, options) {
|
|
3541
|
-
const snapshot = await this.read(env, options);
|
|
3542
|
-
return snapshot ?? emptyDependencySnapshot(env, options?.botId, options?.fetchedAt);
|
|
3543
|
-
}
|
|
3544
|
-
async write(snapshot) {
|
|
3545
|
-
const validated = dependencySnapshotSchema.parse(snapshot);
|
|
3546
|
-
await fs8.mkdir(this.dirPath, { recursive: true });
|
|
3547
|
-
const filePath = this.getSnapshotPath(validated.env);
|
|
3548
|
-
const tmp = `${filePath}.tmp-${process.pid}-${Date.now()}`;
|
|
3549
|
-
await fs8.writeFile(tmp, JSON.stringify(sortKeysDeep(validated), null, 2) + `
|
|
3550
|
-
`, "utf8");
|
|
3551
|
-
await fs8.rename(tmp, filePath);
|
|
3552
|
-
}
|
|
3553
|
-
async delete(env) {
|
|
3554
|
-
try {
|
|
3555
|
-
await fs8.unlink(this.getSnapshotPath(env));
|
|
3556
|
-
} catch (err) {
|
|
3557
|
-
if (err.code !== "ENOENT")
|
|
3558
|
-
throw err;
|
|
3559
|
-
}
|
|
3560
|
-
}
|
|
3561
|
-
async hasMigrationMarker() {
|
|
3562
|
-
try {
|
|
3563
|
-
await fs8.access(this.getMigrationMarkerPath());
|
|
3564
|
-
return true;
|
|
3565
|
-
} catch {
|
|
3566
|
-
return false;
|
|
3567
|
-
}
|
|
3568
|
-
}
|
|
3569
|
-
async writeMigrationMarker(marker) {
|
|
3570
|
-
const validated = dependencyMigrationMarkerSchema.parse(marker);
|
|
3571
|
-
await fs8.mkdir(this.dirPath, { recursive: true });
|
|
3572
|
-
const filePath = this.getMigrationMarkerPath();
|
|
3573
|
-
const tmp = `${filePath}.tmp-${process.pid}-${Date.now()}`;
|
|
3574
|
-
await fs8.writeFile(tmp, JSON.stringify(sortKeysDeep(validated), null, 2) + `
|
|
3575
|
-
`, "utf8");
|
|
3576
|
-
await fs8.rename(tmp, filePath);
|
|
3577
|
-
}
|
|
3578
|
-
async refreshFromCloud(opts) {
|
|
3579
|
-
const previous = await this.readForRefresh(opts.env, opts.onWarning);
|
|
3580
|
-
const { bot } = await opts.client.getBot({ id: opts.botId });
|
|
3581
|
-
const snapshot = dependencySnapshotFromBot({
|
|
3582
|
-
bot,
|
|
3583
|
-
botId: opts.botId,
|
|
3584
|
-
env: opts.env,
|
|
3585
|
-
fetchedAt: opts.fetchedAt ?? new Date,
|
|
3586
|
-
previous
|
|
3587
|
-
});
|
|
3588
|
-
await annotateAuthorizationPending({
|
|
3589
|
-
snapshot,
|
|
3590
|
-
bot,
|
|
3591
|
-
integrationRegistry: opts.integrationRegistry
|
|
3592
|
-
});
|
|
3593
|
-
if (previous && cloudSnapshotUnchanged(previous, snapshot)) {
|
|
3594
|
-
return previous;
|
|
3595
|
-
}
|
|
3596
|
-
await this.write(snapshot);
|
|
3597
|
-
return snapshot;
|
|
3598
|
-
}
|
|
3599
|
-
async readForRefresh(env, onWarning) {
|
|
3600
|
-
try {
|
|
3601
|
-
return await this.read(env);
|
|
3602
|
-
} catch (err) {
|
|
3603
|
-
if (!(err instanceof DependencyError) || err.code !== "INVALID_CONFIG")
|
|
3604
|
-
throw err;
|
|
3605
|
-
const filePath = this.getSnapshotPath(env);
|
|
3606
|
-
await this.delete(env);
|
|
3607
|
-
onWarning?.({
|
|
3608
|
-
code: "SNAPSHOT_CORRUPT",
|
|
3609
|
-
message: `Removed corrupt dependency snapshot at ${filePath}; refreshing from Cloud.`,
|
|
3610
|
-
env,
|
|
3611
|
-
path: filePath
|
|
3612
|
-
});
|
|
3613
|
-
return null;
|
|
3614
|
-
}
|
|
3615
|
-
}
|
|
3616
|
-
}
|
|
3617
|
-
function emptyDependencySnapshot(env, botId = "local", fetchedAt = new Date(0)) {
|
|
3618
|
-
return {
|
|
3619
|
-
version: 1,
|
|
3620
|
-
env,
|
|
3621
|
-
botId,
|
|
3622
|
-
fetchedAt: fetchedAt.toISOString(),
|
|
3623
|
-
integrations: {},
|
|
3624
|
-
plugins: {}
|
|
3625
|
-
};
|
|
3626
|
-
}
|
|
3627
|
-
function cloudSnapshotUnchanged(previous, next) {
|
|
3628
|
-
if (previous.botId !== next.botId || previous.env !== next.env)
|
|
3629
|
-
return false;
|
|
3630
|
-
if (previous.botUpdatedAt !== next.botUpdatedAt)
|
|
3631
|
-
return false;
|
|
3632
|
-
return jsonEqual({ integrations: previous.integrations, plugins: previous.plugins }, { integrations: next.integrations, plugins: next.plugins });
|
|
3633
|
-
}
|
|
3634
|
-
async function annotateAuthorizationPending(opts) {
|
|
3635
|
-
const registry = opts.integrationRegistry;
|
|
3636
|
-
if (!registry)
|
|
3637
|
-
return;
|
|
3638
|
-
const cloudIntegrations = opts.bot.integrations ?? {};
|
|
3639
|
-
const specCache = new Map;
|
|
3640
|
-
const getSpec = (name, version) => {
|
|
3641
|
-
const key = `${name}@${version}`;
|
|
3642
|
-
const cached = specCache.get(key);
|
|
3643
|
-
if (cached)
|
|
3644
|
-
return cached;
|
|
3645
|
-
const promise = registry.getSpec(name, version).catch(() => null);
|
|
3646
|
-
specCache.set(key, promise);
|
|
3647
|
-
return promise;
|
|
3648
|
-
};
|
|
3649
|
-
await Promise.all(Object.entries(opts.snapshot.integrations).map(async ([alias, entry]) => {
|
|
3650
|
-
const cloudAlias = entry.cloudAlias ?? alias;
|
|
3651
|
-
const cloud = cloudIntegrations[cloudAlias];
|
|
3652
|
-
if (!cloud)
|
|
3653
|
-
return;
|
|
3654
|
-
if (cloud.identifier) {
|
|
3655
|
-
delete entry.authorizationPending;
|
|
3656
|
-
return;
|
|
3657
|
-
}
|
|
3658
|
-
const spec = await getSpec(entry.name, entry.version);
|
|
3659
|
-
if (!spec)
|
|
3660
|
-
return;
|
|
3661
|
-
const requiresAuthorization = integrationRequiresAuthorization(spec, entry.configurationType);
|
|
3662
|
-
if (requiresAuthorization) {
|
|
3663
|
-
entry.authorizationPending = true;
|
|
3664
|
-
} else {
|
|
3665
|
-
delete entry.authorizationPending;
|
|
3666
|
-
}
|
|
3667
|
-
}));
|
|
3668
|
-
}
|
|
3669
|
-
function dependencySnapshotFromBot(opts) {
|
|
3670
|
-
const integrations = {};
|
|
3671
|
-
const usedIntegrationAliases = new Set;
|
|
3672
|
-
for (const [cloudAlias, cloud] of Object.entries(opts.bot.integrations ?? {})) {
|
|
3673
|
-
const cloudName = typeof cloud.name === "string" ? cloud.name : undefined;
|
|
3674
|
-
const config = cloud.configuration ?? {};
|
|
3675
|
-
const version = cloud.version ?? "0.0.0";
|
|
3676
|
-
const configurationType = typeof cloud.configurationType === "string" && cloud.configurationType && cloud.configurationType !== "default" ? cloud.configurationType : undefined;
|
|
3677
|
-
const alias = chooseCloudAlias({
|
|
3678
|
-
cloudAlias,
|
|
3679
|
-
cloudName,
|
|
3680
|
-
previous: opts.previous?.integrations ?? {},
|
|
3681
|
-
used: usedIntegrationAliases,
|
|
3682
|
-
matches: (entry) => entry.version === version && entry.configurationType === configurationType && jsonEqual(entry.config, config)
|
|
3683
|
-
});
|
|
3684
|
-
usedIntegrationAliases.add(alias);
|
|
3685
|
-
const previousEntry = opts.previous?.integrations[alias];
|
|
3686
|
-
const previousMissingFields = previousEntry?.missingFields?.length && !cloud.enabled && previousEntry.version === version && previousEntry.configurationType === configurationType && jsonEqual(previousEntry.config, config) ? previousEntry.missingFields : undefined;
|
|
3687
|
-
integrations[alias] = {
|
|
3688
|
-
name: cloud.name ?? "",
|
|
3689
|
-
version,
|
|
3690
|
-
enabled: Boolean(cloud.enabled),
|
|
3691
|
-
config,
|
|
3692
|
-
...configurationType ? { configurationType } : {},
|
|
3693
|
-
...previousMissingFields ? { missingFields: previousMissingFields } : {},
|
|
3694
|
-
...!cloud.identifier && previousEntry?.authorizationPending ? { authorizationPending: true } : {},
|
|
3695
|
-
...typeof cloud.id === "string" ? { cloudId: cloud.id } : {},
|
|
3696
|
-
cloudAlias,
|
|
3697
|
-
...typeof cloud.updatedAt === "string" ? { updatedAt: cloud.updatedAt } : {}
|
|
3698
|
-
};
|
|
3699
|
-
}
|
|
3700
|
-
const plugins = {};
|
|
3701
|
-
const usedPluginAliases = new Set;
|
|
3702
|
-
for (const [cloudAlias, cloud] of Object.entries(opts.bot.plugins ?? {})) {
|
|
3703
|
-
const cloudName = typeof cloud.name === "string" ? cloud.name : undefined;
|
|
3704
|
-
const config = cloud.configuration ?? {};
|
|
3705
|
-
const version = cloud.version ?? "0.0.0";
|
|
3706
|
-
const dependencies = {};
|
|
3707
|
-
for (const [ifaceAlias, dep] of Object.entries(cloud.interfaces ?? {})) {
|
|
3708
|
-
if (typeof dep.integrationAlias === "string") {
|
|
3709
|
-
dependencies[ifaceAlias] = { integrationAlias: dep.integrationAlias };
|
|
3710
|
-
}
|
|
3711
|
-
}
|
|
3712
|
-
const alias = chooseCloudAlias({
|
|
3713
|
-
cloudAlias,
|
|
3714
|
-
cloudName,
|
|
3715
|
-
previous: opts.previous?.plugins ?? {},
|
|
3716
|
-
used: usedPluginAliases,
|
|
3717
|
-
matches: (entry) => entry.version === version && jsonEqual(entry.config, config)
|
|
3718
|
-
});
|
|
3719
|
-
usedPluginAliases.add(alias);
|
|
3720
|
-
const previousEntry = opts.previous?.plugins[alias];
|
|
3721
|
-
const previousMissingFields = previousEntry?.missingFields?.length && !(cloud.enabled ?? true) && previousEntry.version === version && jsonEqual(previousEntry.config, config) ? previousEntry.missingFields : undefined;
|
|
3722
|
-
plugins[alias] = {
|
|
3723
|
-
name: cloud.name ?? "",
|
|
3724
|
-
version,
|
|
3725
|
-
enabled: cloud.enabled ?? true,
|
|
3726
|
-
config,
|
|
3727
|
-
dependencies,
|
|
3728
|
-
...previousMissingFields ? { missingFields: previousMissingFields } : {},
|
|
3729
|
-
...typeof cloud.id === "string" ? { cloudId: cloud.id } : {},
|
|
3730
|
-
cloudAlias,
|
|
3731
|
-
...typeof cloud.updatedAt === "string" ? { updatedAt: cloud.updatedAt } : {}
|
|
3732
|
-
};
|
|
3733
|
-
}
|
|
3734
|
-
return {
|
|
3735
|
-
version: 1,
|
|
3736
|
-
env: opts.env,
|
|
3737
|
-
botId: opts.botId,
|
|
3738
|
-
fetchedAt: opts.fetchedAt.toISOString(),
|
|
3739
|
-
...typeof opts.bot.updatedAt === "string" ? { botUpdatedAt: opts.bot.updatedAt } : {},
|
|
3740
|
-
integrations,
|
|
3741
|
-
plugins
|
|
3742
|
-
};
|
|
3743
|
-
}
|
|
3744
|
-
function chooseCloudAlias(opts) {
|
|
3745
|
-
if (isFriendlyAlias(opts.cloudAlias) && opts.previous[opts.cloudAlias] && !opts.used.has(opts.cloudAlias)) {
|
|
3746
|
-
return opts.cloudAlias;
|
|
3298
|
+
for (const assignment of sourceFile.getExportAssignments()) {
|
|
3299
|
+
if (assignment.isExportEquals())
|
|
3300
|
+
continue;
|
|
3301
|
+
const expr = assignment.getExpression();
|
|
3302
|
+
const direct = sourceFromCustomComponentExpr(expr, importBindings);
|
|
3303
|
+
if (direct) {
|
|
3304
|
+
exportMap.set("default", direct);
|
|
3305
|
+
continue;
|
|
3306
|
+
}
|
|
3307
|
+
if (expr.getKind() === SyntaxKind.Identifier) {
|
|
3308
|
+
const fromLocal = localToSource.get(expr.getText());
|
|
3309
|
+
if (fromLocal)
|
|
3310
|
+
exportMap.set("default", fromLocal);
|
|
3311
|
+
}
|
|
3747
3312
|
}
|
|
3748
|
-
|
|
3749
|
-
if (
|
|
3750
|
-
|
|
3751
|
-
|
|
3752
|
-
|
|
3313
|
+
for (const decl of sourceFile.getExportDeclarations()) {
|
|
3314
|
+
if (decl.getModuleSpecifier())
|
|
3315
|
+
continue;
|
|
3316
|
+
for (const named of decl.getNamedExports()) {
|
|
3317
|
+
const localName = named.getNameNode().getText();
|
|
3318
|
+
const aliasNode = named.getAliasNode();
|
|
3319
|
+
const exportName = aliasNode ? aliasNode.getText() : localName;
|
|
3320
|
+
const source = localToSource.get(localName);
|
|
3321
|
+
if (source)
|
|
3322
|
+
exportMap.set(exportName, source);
|
|
3753
3323
|
}
|
|
3754
|
-
const match = Object.entries(opts.previous).find(([alias, entry]) => !opts.used.has(alias) && entry.name === opts.cloudName);
|
|
3755
|
-
if (match)
|
|
3756
|
-
return match[0];
|
|
3757
3324
|
}
|
|
3758
|
-
return
|
|
3325
|
+
return exportMap;
|
|
3759
3326
|
}
|
|
3760
|
-
|
|
3761
|
-
|
|
3762
|
-
|
|
3763
|
-
|
|
3327
|
+
function sourceFromCustomComponentExpr(expr, importBindings) {
|
|
3328
|
+
if (expr.getKind() !== SyntaxKind.NewExpression)
|
|
3329
|
+
return;
|
|
3330
|
+
const newExpr = expr.asKindOrThrow(SyntaxKind.NewExpression);
|
|
3331
|
+
if (newExpr.getExpression().getText() !== CUSTOM_COMPONENT_CLASS)
|
|
3332
|
+
return;
|
|
3333
|
+
const args = newExpr.getArguments();
|
|
3334
|
+
const firstArg = args[0];
|
|
3335
|
+
if (!firstArg || firstArg.getKind() !== SyntaxKind.Identifier)
|
|
3336
|
+
return;
|
|
3337
|
+
return importBindings.get(firstArg.getText());
|
|
3338
|
+
}
|
|
3339
|
+
var CUSTOM_COMPONENT_CLASS = "CustomComponent";
|
|
3340
|
+
var init_component_source_resolver = __esm(() => {
|
|
3341
|
+
init_component_files();
|
|
3342
|
+
});
|
|
3343
|
+
|
|
3344
|
+
// src/bot-generator/table-validation.ts
|
|
3345
|
+
function getColumnCount(table) {
|
|
3346
|
+
const properties = table.definition.schema?.properties;
|
|
3347
|
+
return properties ? Object.keys(properties).length : 0;
|
|
3348
|
+
}
|
|
3349
|
+
function findTableColumnViolations(tables, max = MAX_TABLE_COLUMNS) {
|
|
3350
|
+
return tables.map((table) => ({
|
|
3351
|
+
name: table.definition.name,
|
|
3352
|
+
path: table.path,
|
|
3353
|
+
columnCount: getColumnCount(table)
|
|
3354
|
+
})).filter((t) => t.columnCount > max);
|
|
3355
|
+
}
|
|
3356
|
+
var init_table_validation = __esm(() => {
|
|
3357
|
+
init_constants();
|
|
3764
3358
|
});
|
|
3765
3359
|
|
|
3766
|
-
// src/agent-project/
|
|
3767
|
-
function
|
|
3360
|
+
// src/agent-project/lock-to-dependencies.ts
|
|
3361
|
+
function lockToDependencies(lock) {
|
|
3768
3362
|
const integrations = {};
|
|
3769
|
-
for (const [alias, entry] of Object.entries(
|
|
3363
|
+
for (const [alias, entry] of Object.entries(lock.integrations)) {
|
|
3770
3364
|
integrations[alias] = {
|
|
3771
3365
|
version: `${entry.name}@${entry.version}`,
|
|
3772
3366
|
enabled: entry.enabled,
|
|
3773
|
-
config: entry.config
|
|
3774
|
-
...entry.configurationType ? { configurationType: entry.configurationType } : {}
|
|
3367
|
+
config: entry.config
|
|
3775
3368
|
};
|
|
3776
3369
|
}
|
|
3777
3370
|
const plugins = {};
|
|
3778
|
-
for (const [alias, entry] of Object.entries(
|
|
3371
|
+
for (const [alias, entry] of Object.entries(lock.plugins)) {
|
|
3779
3372
|
plugins[alias] = {
|
|
3780
3373
|
version: `${entry.name}@${entry.version}`,
|
|
3781
3374
|
config: entry.config,
|
|
3782
|
-
dependencies: entry.dependencies
|
|
3783
|
-
...entry.missingFields !== undefined ? { missingFields: entry.missingFields } : {}
|
|
3375
|
+
dependencies: entry.dependencies
|
|
3784
3376
|
};
|
|
3785
3377
|
}
|
|
3786
3378
|
return { integrations, plugins };
|
|
@@ -3791,8 +3383,8 @@ import { BuiltInActions, BuiltInWorkflows, Errors as Errors2, Primitives as Prim
|
|
|
3791
3383
|
import { Autonomous } from "@botpress/runtime";
|
|
3792
3384
|
import createDebug from "debug";
|
|
3793
3385
|
import { createRequire as createRequire2 } from "module";
|
|
3794
|
-
import
|
|
3795
|
-
import
|
|
3386
|
+
import fs11 from "fs/promises";
|
|
3387
|
+
import path12 from "path";
|
|
3796
3388
|
function getToolDefinition(value) {
|
|
3797
3389
|
if (typeof value !== "object" || value === null) {
|
|
3798
3390
|
return;
|
|
@@ -3823,7 +3415,7 @@ var init_agent_project = __esm(() => {
|
|
|
3823
3415
|
init_validation_errors();
|
|
3824
3416
|
init_table_validation();
|
|
3825
3417
|
init_constants();
|
|
3826
|
-
|
|
3418
|
+
init_lock_file();
|
|
3827
3419
|
debug = createDebug("adk:agent-project");
|
|
3828
3420
|
AgentProject = class AgentProject {
|
|
3829
3421
|
static _projectCache = new Map;
|
|
@@ -3851,7 +3443,7 @@ var init_agent_project = __esm(() => {
|
|
|
3851
3443
|
_tools = [];
|
|
3852
3444
|
constructor(projectPath, options = {}) {
|
|
3853
3445
|
this._options = options;
|
|
3854
|
-
this._path =
|
|
3446
|
+
this._path = path12.resolve(projectPath);
|
|
3855
3447
|
this._integrationManager = new IntegrationManager({
|
|
3856
3448
|
noCache: options.noCache
|
|
3857
3449
|
});
|
|
@@ -3863,7 +3455,7 @@ var init_agent_project = __esm(() => {
|
|
|
3863
3455
|
});
|
|
3864
3456
|
}
|
|
3865
3457
|
static async load(projectPath, options = {}) {
|
|
3866
|
-
const resolvedPath =
|
|
3458
|
+
const resolvedPath = path12.resolve(projectPath);
|
|
3867
3459
|
if (!options.noCache) {
|
|
3868
3460
|
const cached = AgentProject._projectCache.get(resolvedPath);
|
|
3869
3461
|
if (cached) {
|
|
@@ -3881,7 +3473,7 @@ var init_agent_project = __esm(() => {
|
|
|
3881
3473
|
AgentProject._projectCache.clear();
|
|
3882
3474
|
}
|
|
3883
3475
|
static clearCacheForPath(projectPath) {
|
|
3884
|
-
const resolvedPath =
|
|
3476
|
+
const resolvedPath = path12.resolve(projectPath);
|
|
3885
3477
|
AgentProject._projectCache.delete(resolvedPath);
|
|
3886
3478
|
}
|
|
3887
3479
|
get path() {
|
|
@@ -3997,17 +3589,17 @@ var init_agent_project = __esm(() => {
|
|
|
3997
3589
|
const warnings = [];
|
|
3998
3590
|
const info = [];
|
|
3999
3591
|
try {
|
|
4000
|
-
await
|
|
3592
|
+
await fs11.access(this._path);
|
|
4001
3593
|
const requiredFiles = ["agent.config.ts"];
|
|
4002
3594
|
for (const file of requiredFiles) {
|
|
4003
3595
|
try {
|
|
4004
|
-
await
|
|
3596
|
+
await fs11.access(path12.join(this._path, file));
|
|
4005
3597
|
} catch {
|
|
4006
3598
|
errors.push(ValidationErrors.requiredFileMissing(file));
|
|
4007
3599
|
}
|
|
4008
3600
|
}
|
|
4009
3601
|
try {
|
|
4010
|
-
await
|
|
3602
|
+
await fs11.access(path12.join(this._path, "agent.json"));
|
|
4011
3603
|
} catch {
|
|
4012
3604
|
info.push({
|
|
4013
3605
|
$type: "ValidationError",
|
|
@@ -4021,7 +3613,7 @@ var init_agent_project = __esm(() => {
|
|
|
4021
3613
|
const expectedDirs = ["actions", "workflows", "conversations", "assets"];
|
|
4022
3614
|
for (const dir of expectedDirs) {
|
|
4023
3615
|
try {
|
|
4024
|
-
const stats = await
|
|
3616
|
+
const stats = await fs11.stat(path12.join(this._path, dir));
|
|
4025
3617
|
if (!stats.isDirectory()) {
|
|
4026
3618
|
warnings.push(ValidationErrors.invalidStructure(dir, "directory"));
|
|
4027
3619
|
}
|
|
@@ -4105,9 +3697,9 @@ var init_agent_project = __esm(() => {
|
|
|
4105
3697
|
}
|
|
4106
3698
|
async createAgentInfo(info) {
|
|
4107
3699
|
const { devId, ...agentJsonInfo } = info;
|
|
4108
|
-
const agentPath =
|
|
3700
|
+
const agentPath = path12.join(this._path, "agent.json");
|
|
4109
3701
|
const agentContent = stringifyWithOrder(agentJsonInfo, agentInfoKeyOrder);
|
|
4110
|
-
await
|
|
3702
|
+
await fs11.writeFile(agentPath, agentContent);
|
|
4111
3703
|
this._agentInfo = info;
|
|
4112
3704
|
if (devId) {
|
|
4113
3705
|
await this.createAgentLocalInfo({ devId });
|
|
@@ -4124,24 +3716,24 @@ var init_agent_project = __esm(() => {
|
|
|
4124
3716
|
const { devId, ...agentJsonUpdates } = updates;
|
|
4125
3717
|
const updatedInfo = { ...this._agentInfo, ...agentJsonUpdates };
|
|
4126
3718
|
const { devId: _devId, ...agentJsonData } = updatedInfo;
|
|
4127
|
-
const agentPath =
|
|
3719
|
+
const agentPath = path12.join(this._path, "agent.json");
|
|
4128
3720
|
const agentContent = stringifyWithOrder(agentJsonData, agentInfoKeyOrder);
|
|
4129
|
-
await
|
|
3721
|
+
await fs11.writeFile(agentPath, agentContent);
|
|
4130
3722
|
this._agentInfo = updatedInfo;
|
|
4131
3723
|
if (devId !== undefined) {
|
|
4132
3724
|
await this.updateAgentLocalInfo({ devId });
|
|
4133
3725
|
}
|
|
4134
3726
|
}
|
|
4135
3727
|
async createAgentLocalInfo(info) {
|
|
4136
|
-
const localPath =
|
|
3728
|
+
const localPath = path12.join(this._path, "agent.local.json");
|
|
4137
3729
|
let existing = {};
|
|
4138
3730
|
try {
|
|
4139
|
-
const content2 = await
|
|
3731
|
+
const content2 = await fs11.readFile(localPath, "utf-8");
|
|
4140
3732
|
existing = JSON.parse(content2);
|
|
4141
3733
|
} catch {}
|
|
4142
3734
|
const merged = { ...existing, ...info };
|
|
4143
3735
|
const content = stringifyWithOrder(merged, agentLocalInfoKeyOrder);
|
|
4144
|
-
await
|
|
3736
|
+
await fs11.writeFile(localPath, content);
|
|
4145
3737
|
if (this._agentInfo) {
|
|
4146
3738
|
if (merged.botId)
|
|
4147
3739
|
this._agentInfo.botId = merged.botId;
|
|
@@ -4161,10 +3753,10 @@ var init_agent_project = __esm(() => {
|
|
|
4161
3753
|
}
|
|
4162
3754
|
}
|
|
4163
3755
|
async updateAgentLocalInfo(updates) {
|
|
4164
|
-
const localPath =
|
|
3756
|
+
const localPath = path12.join(this._path, "agent.local.json");
|
|
4165
3757
|
let existing = {};
|
|
4166
3758
|
try {
|
|
4167
|
-
const content = await
|
|
3759
|
+
const content = await fs11.readFile(localPath, "utf-8");
|
|
4168
3760
|
existing = JSON.parse(content);
|
|
4169
3761
|
} catch {}
|
|
4170
3762
|
const updated = { ...existing, ...updates };
|
|
@@ -4175,21 +3767,21 @@ var init_agent_project = __esm(() => {
|
|
|
4175
3767
|
}
|
|
4176
3768
|
if (Object.keys(updated).length === 0) {
|
|
4177
3769
|
try {
|
|
4178
|
-
await
|
|
3770
|
+
await fs11.unlink(localPath);
|
|
4179
3771
|
} catch {}
|
|
4180
3772
|
} else {
|
|
4181
3773
|
const content = stringifyWithOrder(updated, agentLocalInfoKeyOrder);
|
|
4182
|
-
await
|
|
3774
|
+
await fs11.writeFile(localPath, content);
|
|
4183
3775
|
}
|
|
4184
3776
|
if (this._agentInfo) {
|
|
4185
|
-
const agentJsonPath =
|
|
3777
|
+
const agentJsonPath = path12.join(this._path, "agent.json");
|
|
4186
3778
|
let base = {
|
|
4187
3779
|
botId: this._agentInfo.botId,
|
|
4188
3780
|
workspaceId: this._agentInfo.workspaceId,
|
|
4189
3781
|
apiUrl: this._agentInfo.apiUrl
|
|
4190
3782
|
};
|
|
4191
3783
|
try {
|
|
4192
|
-
const agentJsonContent = await
|
|
3784
|
+
const agentJsonContent = await fs11.readFile(agentJsonPath, "utf-8");
|
|
4193
3785
|
const parsed = JSON.parse(agentJsonContent);
|
|
4194
3786
|
base = {
|
|
4195
3787
|
botId: parsed.botId ?? this._agentInfo.botId,
|
|
@@ -4221,10 +3813,10 @@ var init_agent_project = __esm(() => {
|
|
|
4221
3813
|
this._integrations = [];
|
|
4222
3814
|
this._interfaces = [];
|
|
4223
3815
|
try {
|
|
4224
|
-
const configPath =
|
|
3816
|
+
const configPath = path12.join(this._path, "agent.config.ts");
|
|
4225
3817
|
debug("loading agent.config.ts from %s", configPath);
|
|
4226
|
-
const projectRequire = createRequire2(
|
|
4227
|
-
debug("created projectRequire from %s",
|
|
3818
|
+
const projectRequire = createRequire2(path12.join(this._path, "package.json"));
|
|
3819
|
+
debug("created projectRequire from %s", path12.join(this._path, "package.json"));
|
|
4228
3820
|
try {
|
|
4229
3821
|
const resolvedPath = projectRequire.resolve(configPath);
|
|
4230
3822
|
debug("resolved config path: %s", resolvedPath);
|
|
@@ -4268,29 +3860,49 @@ var init_agent_project = __esm(() => {
|
|
|
4268
3860
|
return;
|
|
4269
3861
|
}
|
|
4270
3862
|
this._config = configModule.default;
|
|
4271
|
-
const
|
|
4272
|
-
|
|
4273
|
-
let snapshotBasedDependencies;
|
|
4274
|
-
let dependencySnapshotReadFailed = false;
|
|
3863
|
+
const lockFile = new LockFile({ projectPath: this._path, env: "dev" });
|
|
3864
|
+
let lockBasedDependencies;
|
|
4275
3865
|
try {
|
|
4276
|
-
const
|
|
4277
|
-
const
|
|
4278
|
-
const hasDependencies = Object.keys(state.integrations).length > 0 || Object.keys(state.plugins).length > 0;
|
|
3866
|
+
const lockData = await lockFile.read();
|
|
3867
|
+
const hasDependencies = Object.keys(lockData.integrations).length > 0 || Object.keys(lockData.plugins).length > 0;
|
|
4279
3868
|
if (hasDependencies) {
|
|
4280
|
-
|
|
3869
|
+
lockBasedDependencies = lockToDependencies(lockData);
|
|
4281
3870
|
}
|
|
4282
3871
|
} catch (err) {
|
|
4283
3872
|
this._warnings.push({
|
|
4284
3873
|
$type: "ValidationError",
|
|
4285
3874
|
code: "INVALID_DEPENDENCIES_SCHEMA" /* INVALID_DEPENDENCIES_SCHEMA */,
|
|
4286
3875
|
severity: "warning" /* WARNING */,
|
|
4287
|
-
message: `Could not read
|
|
4288
|
-
file:
|
|
3876
|
+
message: `Could not read dependencies.dev.lock.json: ${err.message}. Falling back to agent.config.ts dependencies.`,
|
|
3877
|
+
file: "dependencies.dev.lock.json"
|
|
4289
3878
|
});
|
|
4290
|
-
dependencySnapshotReadFailed = true;
|
|
4291
3879
|
}
|
|
4292
|
-
|
|
4293
|
-
|
|
3880
|
+
const config = configModule.default;
|
|
3881
|
+
let configBasedDependencies;
|
|
3882
|
+
if (!lockBasedDependencies && config.dependencies) {
|
|
3883
|
+
const validationResult = dependenciesSchema.safeParse(config.dependencies);
|
|
3884
|
+
if (!validationResult.success) {
|
|
3885
|
+
const errors = validationResult.error.errors;
|
|
3886
|
+
for (const error of errors) {
|
|
3887
|
+
this._errors.push({
|
|
3888
|
+
$type: "ValidationError",
|
|
3889
|
+
code: "INVALID_DEPENDENCIES_SCHEMA" /* INVALID_DEPENDENCIES_SCHEMA */,
|
|
3890
|
+
severity: "error" /* ERROR */,
|
|
3891
|
+
message: `Invalid dependencies in agent.config.ts: ${error.path.join(".")} - ${error.message}`,
|
|
3892
|
+
file: "agent.config.ts",
|
|
3893
|
+
hint: error.code === "invalid_type" ? `Expected ${error.expected}, but got ${error.received}` : undefined
|
|
3894
|
+
});
|
|
3895
|
+
}
|
|
3896
|
+
this._dependencies = { integrations: {} };
|
|
3897
|
+
this._integrations = [];
|
|
3898
|
+
this._interfaces = [];
|
|
3899
|
+
return;
|
|
3900
|
+
}
|
|
3901
|
+
configBasedDependencies = validationResult.data;
|
|
3902
|
+
}
|
|
3903
|
+
const depsToLoad = lockBasedDependencies ?? configBasedDependencies;
|
|
3904
|
+
if (depsToLoad) {
|
|
3905
|
+
this._dependencies = depsToLoad;
|
|
4294
3906
|
if (!this._options.offline) {
|
|
4295
3907
|
const [intRes, ifRes] = await Promise.all([
|
|
4296
3908
|
this._integrationManager.loadIntegrations(this._dependencies),
|
|
@@ -4401,8 +4013,8 @@ ${err.stack?.split(`
|
|
|
4401
4013
|
}
|
|
4402
4014
|
}
|
|
4403
4015
|
isBarrelReexport(existing, newPath, newExport, newDefinition) {
|
|
4404
|
-
const isNewBarrel = /^index\.[tj]s$/i.test(
|
|
4405
|
-
const isExistingBarrel = /^index\.[tj]s$/i.test(
|
|
4016
|
+
const isNewBarrel = /^index\.[tj]s$/i.test(path12.basename(newPath));
|
|
4017
|
+
const isExistingBarrel = /^index\.[tj]s$/i.test(path12.basename(existing.path));
|
|
4406
4018
|
if (!isNewBarrel && !isExistingBarrel) {
|
|
4407
4019
|
return false;
|
|
4408
4020
|
}
|
|
@@ -4414,16 +4026,16 @@ ${err.stack?.split(`
|
|
|
4414
4026
|
return true;
|
|
4415
4027
|
}
|
|
4416
4028
|
isToolBarrelReexport(existingPath, newPath) {
|
|
4417
|
-
const isNewBarrel = /^index\.[tj]s$/i.test(
|
|
4418
|
-
const isExistingBarrel = /^index\.[tj]s$/i.test(
|
|
4029
|
+
const isNewBarrel = /^index\.[tj]s$/i.test(path12.basename(newPath));
|
|
4030
|
+
const isExistingBarrel = /^index\.[tj]s$/i.test(path12.basename(existingPath));
|
|
4419
4031
|
if (!isNewBarrel && !isExistingBarrel) {
|
|
4420
4032
|
return false;
|
|
4421
4033
|
}
|
|
4422
4034
|
return true;
|
|
4423
4035
|
}
|
|
4424
4036
|
shouldPreferToolDefinition(existingPath, newPath) {
|
|
4425
|
-
const isNewBarrel = /^index\.[tj]s$/i.test(
|
|
4426
|
-
const isExistingBarrel = /^index\.[tj]s$/i.test(
|
|
4037
|
+
const isNewBarrel = /^index\.[tj]s$/i.test(path12.basename(newPath));
|
|
4038
|
+
const isExistingBarrel = /^index\.[tj]s$/i.test(path12.basename(existingPath));
|
|
4427
4039
|
return isExistingBarrel && !isNewBarrel;
|
|
4428
4040
|
}
|
|
4429
4041
|
getChannelsList(channelSpec) {
|
|
@@ -4439,8 +4051,8 @@ ${err.stack?.split(`
|
|
|
4439
4051
|
if (this._options.adkCommand) {
|
|
4440
4052
|
setAdkCommand(this._options.adkCommand);
|
|
4441
4053
|
}
|
|
4442
|
-
const src =
|
|
4443
|
-
if (!await
|
|
4054
|
+
const src = path12.join(this._path, "src");
|
|
4055
|
+
if (!await fs11.stat(src).catch(() => false)) {
|
|
4444
4056
|
this._errors.push({
|
|
4445
4057
|
$type: "ValidationError",
|
|
4446
4058
|
code: "INVALID_STRUCTURE" /* INVALID_STRUCTURE */,
|
|
@@ -4449,14 +4061,14 @@ ${err.stack?.split(`
|
|
|
4449
4061
|
});
|
|
4450
4062
|
return;
|
|
4451
4063
|
}
|
|
4452
|
-
const allFiles = await
|
|
4064
|
+
const allFiles = await fs11.readdir(src, {
|
|
4453
4065
|
withFileTypes: true,
|
|
4454
4066
|
recursive: true
|
|
4455
4067
|
});
|
|
4456
4068
|
for (const file of allFiles.filter((x) => x.isFile())) {
|
|
4457
4069
|
const filename = file.name;
|
|
4458
|
-
const absolutePath =
|
|
4459
|
-
const relPath =
|
|
4070
|
+
const absolutePath = path12.join(file.parentPath, file.name);
|
|
4071
|
+
const relPath = path12.relative(this.path, absolutePath);
|
|
4460
4072
|
if (filename.toLowerCase().endsWith(".d.ts")) {
|
|
4461
4073
|
continue;
|
|
4462
4074
|
}
|
|
@@ -4791,7 +4403,7 @@ var _format = null, _formatLoaded = false, formatCode = async (code, filepath) =
|
|
|
4791
4403
|
`));
|
|
4792
4404
|
return code;
|
|
4793
4405
|
}
|
|
4794
|
-
}, ADK_VERSION = "1.19.0-beta.
|
|
4406
|
+
}, ADK_VERSION = "1.19.0-beta.16", relative = (from, to) => {
|
|
4795
4407
|
const fromDir = path13.dirname(from);
|
|
4796
4408
|
const relative2 = path13.relative(fromDir, to);
|
|
4797
4409
|
return relative2.startsWith(".") ? relative2 : `./${relative2}`;
|
|
@@ -4802,22 +4414,14 @@ var init_utils = () => {};
|
|
|
4802
4414
|
var exports_dependencies = {};
|
|
4803
4415
|
__export(exports_dependencies, {
|
|
4804
4416
|
sortKeysDeep: () => sortKeysDeep,
|
|
4805
|
-
resolveDependencyStatuses: () => resolveDependencyStatuses,
|
|
4806
4417
|
migrateFromConfig: () => migrateFromConfig,
|
|
4807
4418
|
jsonEqual: () => jsonEqual,
|
|
4808
|
-
isCallable: () => isCallable,
|
|
4809
|
-
emptyDependencySnapshot: () => emptyDependencySnapshot,
|
|
4810
|
-
dependencyStateSchema: () => dependencyStateSchema,
|
|
4811
|
-
dependencySnapshotFromBot: () => dependencySnapshotFromBot,
|
|
4812
|
-
computePluginStatus: () => computePluginStatus,
|
|
4813
|
-
computeIntegrationStatus: () => computeIntegrationStatus,
|
|
4814
4419
|
PluginResolver: () => PluginResolver,
|
|
4815
4420
|
PluginRegistry: () => PluginRegistry,
|
|
4421
|
+
LockFile: () => LockFile,
|
|
4816
4422
|
InterfaceRegistry: () => InterfaceRegistry,
|
|
4817
4423
|
IntegrationResolver: () => IntegrationResolver,
|
|
4818
4424
|
IntegrationRegistry: () => IntegrationRegistry,
|
|
4819
|
-
DependencySnapshotStore: () => DependencySnapshotStore,
|
|
4820
|
-
DependencyMigrationManager: () => DependencyMigrationManager,
|
|
4821
4425
|
DependencyManager: () => DependencyManager,
|
|
4822
4426
|
DependencyError: () => DependencyError,
|
|
4823
4427
|
DEPENDENCY_WARNING_CODES: () => DEPENDENCY_WARNING_CODES,
|
|
@@ -4825,10 +4429,34 @@ __export(exports_dependencies, {
|
|
|
4825
4429
|
});
|
|
4826
4430
|
|
|
4827
4431
|
// src/dependencies/dependency-manager.ts
|
|
4828
|
-
|
|
4829
|
-
init_errors2();
|
|
4432
|
+
init_lock_file();
|
|
4830
4433
|
import * as semver2 from "semver";
|
|
4831
|
-
|
|
4434
|
+
|
|
4435
|
+
// src/dependencies/alias-utils.ts
|
|
4436
|
+
var FRIENDLY_ALIAS_RE = /^[a-z0-9_-]{2,100}$/;
|
|
4437
|
+
var BP_INTERNAL_ID_PREFIXES = ["intver_", "plgver_", "int_", "plg_"];
|
|
4438
|
+
function isBotpressInternalId(alias) {
|
|
4439
|
+
return BP_INTERNAL_ID_PREFIXES.some((prefix) => alias.startsWith(prefix));
|
|
4440
|
+
}
|
|
4441
|
+
function isFriendlyAlias(alias) {
|
|
4442
|
+
return FRIENDLY_ALIAS_RE.test(alias) && !isBotpressInternalId(alias);
|
|
4443
|
+
}
|
|
4444
|
+
function generateFriendlyAlias(cloudName, cloudAlias, used) {
|
|
4445
|
+
if (isFriendlyAlias(cloudAlias) && !used.has(cloudAlias))
|
|
4446
|
+
return cloudAlias;
|
|
4447
|
+
const base = cloudName?.split("/").at(-1) ?? cloudAlias;
|
|
4448
|
+
const sanitized = base.toLowerCase().replace(/[^a-z0-9_-]/g, "-");
|
|
4449
|
+
let candidate = sanitized;
|
|
4450
|
+
let n = 2;
|
|
4451
|
+
while (used.has(candidate)) {
|
|
4452
|
+
candidate = `${sanitized}-${n}`;
|
|
4453
|
+
n++;
|
|
4454
|
+
}
|
|
4455
|
+
return candidate;
|
|
4456
|
+
}
|
|
4457
|
+
|
|
4458
|
+
// src/dependencies/dependency-manager.ts
|
|
4459
|
+
init_errors2();
|
|
4832
4460
|
|
|
4833
4461
|
// src/dependencies/resolvers/integration-resolver.ts
|
|
4834
4462
|
init_errors2();
|
|
@@ -4840,17 +4468,13 @@ class IntegrationResolver {
|
|
|
4840
4468
|
this.registry = opts.registry;
|
|
4841
4469
|
this.client = opts.client;
|
|
4842
4470
|
}
|
|
4843
|
-
|
|
4844
|
-
|
|
4471
|
+
toLockEntry(cloud) {
|
|
4472
|
+
return {
|
|
4845
4473
|
name: cloud.name ?? "",
|
|
4846
4474
|
version: cloud.version ?? "0.0.0",
|
|
4847
4475
|
enabled: Boolean(cloud.enabled),
|
|
4848
4476
|
config: cloud.configuration ?? {}
|
|
4849
4477
|
};
|
|
4850
|
-
if (typeof cloud.configurationType === "string" && cloud.configurationType && cloud.configurationType !== "default") {
|
|
4851
|
-
entry.configurationType = cloud.configurationType;
|
|
4852
|
-
}
|
|
4853
|
-
return entry;
|
|
4854
4478
|
}
|
|
4855
4479
|
async applyToCloud(opts) {
|
|
4856
4480
|
const spec = await this.registry.getSpec(opts.entry.name, opts.entry.version);
|
|
@@ -4892,7 +4516,7 @@ class PluginResolver {
|
|
|
4892
4516
|
this.integrationRegistry = opts.integrationRegistry;
|
|
4893
4517
|
this.client = opts.client;
|
|
4894
4518
|
}
|
|
4895
|
-
|
|
4519
|
+
toLockEntry(cloud) {
|
|
4896
4520
|
const dependencies = {};
|
|
4897
4521
|
for (const [ifaceAlias, dep] of Object.entries(cloud.interfaces ?? {})) {
|
|
4898
4522
|
if (dep.integrationAlias) {
|
|
@@ -4920,7 +4544,7 @@ class PluginResolver {
|
|
|
4920
4544
|
details: { plugin: opts.alias, pluginInterfaceAlias: pluginIfaceAlias, interfaceName: requirement.name }
|
|
4921
4545
|
});
|
|
4922
4546
|
}
|
|
4923
|
-
const integration = opts.
|
|
4547
|
+
const integration = opts.lock.integrations[dep.integrationAlias];
|
|
4924
4548
|
if (!integration) {
|
|
4925
4549
|
throw new DependencyError({
|
|
4926
4550
|
code: "MISSING_DEPENDENCY",
|
|
@@ -4995,24 +4619,199 @@ class IntegrationRegistry {
|
|
|
4995
4619
|
}
|
|
4996
4620
|
}
|
|
4997
4621
|
|
|
4622
|
+
// src/plugins/manager.ts
|
|
4623
|
+
init_src();
|
|
4624
|
+
init_auth();
|
|
4625
|
+
import { Client as Client4 } from "@botpress/client";
|
|
4626
|
+
|
|
4627
|
+
// src/plugins/enhanced-cache.ts
|
|
4628
|
+
import fs6 from "fs/promises";
|
|
4629
|
+
import path6 from "path";
|
|
4630
|
+
import os4 from "os";
|
|
4631
|
+
|
|
4632
|
+
class EnhancedPluginCache {
|
|
4633
|
+
cacheDir;
|
|
4634
|
+
resolutionsDir;
|
|
4635
|
+
definitionsDir;
|
|
4636
|
+
noCache;
|
|
4637
|
+
constructor(noCache = false) {
|
|
4638
|
+
this.noCache = noCache;
|
|
4639
|
+
this.cacheDir = path6.join(os4.homedir(), ".adk", "cache", "plugins");
|
|
4640
|
+
this.resolutionsDir = path6.join(this.cacheDir, "resolutions");
|
|
4641
|
+
this.definitionsDir = path6.join(this.cacheDir, "definitions");
|
|
4642
|
+
}
|
|
4643
|
+
async ensureCacheDirs() {
|
|
4644
|
+
await fs6.mkdir(this.resolutionsDir, { recursive: true });
|
|
4645
|
+
await fs6.mkdir(this.definitionsDir, { recursive: true });
|
|
4646
|
+
}
|
|
4647
|
+
async getResolution(name, version) {
|
|
4648
|
+
if (this.noCache) {
|
|
4649
|
+
return null;
|
|
4650
|
+
}
|
|
4651
|
+
try {
|
|
4652
|
+
const key = this.getResolutionKey(name, version);
|
|
4653
|
+
const cachePath = path6.join(this.resolutionsDir, `${key}.json`);
|
|
4654
|
+
const data = await fs6.readFile(cachePath, "utf-8");
|
|
4655
|
+
const resolution = JSON.parse(data);
|
|
4656
|
+
const cachedAt = new Date(resolution.cachedAt);
|
|
4657
|
+
const now = new Date;
|
|
4658
|
+
const ageMinutes = (now.getTime() - cachedAt.getTime()) / (1000 * 60);
|
|
4659
|
+
if (ageMinutes > 5) {
|
|
4660
|
+
return null;
|
|
4661
|
+
}
|
|
4662
|
+
return resolution;
|
|
4663
|
+
} catch {
|
|
4664
|
+
return null;
|
|
4665
|
+
}
|
|
4666
|
+
}
|
|
4667
|
+
async setResolution(name, version, pluginId, updatedAt) {
|
|
4668
|
+
await this.ensureCacheDirs();
|
|
4669
|
+
const key = this.getResolutionKey(name, version);
|
|
4670
|
+
const cachePath = path6.join(this.resolutionsDir, `${key}.json`);
|
|
4671
|
+
const resolution = {
|
|
4672
|
+
pluginId,
|
|
4673
|
+
updatedAt,
|
|
4674
|
+
cachedAt: new Date().toISOString()
|
|
4675
|
+
};
|
|
4676
|
+
await fs6.writeFile(cachePath, JSON.stringify(resolution));
|
|
4677
|
+
}
|
|
4678
|
+
async getDefinition(pluginId, updatedAt) {
|
|
4679
|
+
if (this.noCache) {
|
|
4680
|
+
return null;
|
|
4681
|
+
}
|
|
4682
|
+
try {
|
|
4683
|
+
const key = this.getDefinitionKey(pluginId, updatedAt);
|
|
4684
|
+
const cachePath = path6.join(this.definitionsDir, `${key}.json`);
|
|
4685
|
+
const data = await fs6.readFile(cachePath, "utf-8");
|
|
4686
|
+
const cached = JSON.parse(data);
|
|
4687
|
+
return cached.definition;
|
|
4688
|
+
} catch {
|
|
4689
|
+
return null;
|
|
4690
|
+
}
|
|
4691
|
+
}
|
|
4692
|
+
async setDefinition(pluginId, updatedAt, definition) {
|
|
4693
|
+
await this.ensureCacheDirs();
|
|
4694
|
+
const key = this.getDefinitionKey(pluginId, updatedAt);
|
|
4695
|
+
const cachePath = path6.join(this.definitionsDir, `${key}.json`);
|
|
4696
|
+
const cached = {
|
|
4697
|
+
definition,
|
|
4698
|
+
cachedAt: new Date().toISOString()
|
|
4699
|
+
};
|
|
4700
|
+
await fs6.writeFile(cachePath, JSON.stringify(cached));
|
|
4701
|
+
}
|
|
4702
|
+
async clear() {
|
|
4703
|
+
try {
|
|
4704
|
+
const resolutionFiles = await fs6.readdir(this.resolutionsDir);
|
|
4705
|
+
await Promise.all(resolutionFiles.map((file) => fs6.unlink(path6.join(this.resolutionsDir, file))));
|
|
4706
|
+
const definitionFiles = await fs6.readdir(this.definitionsDir);
|
|
4707
|
+
await Promise.all(definitionFiles.map((file) => fs6.unlink(path6.join(this.definitionsDir, file))));
|
|
4708
|
+
} catch {}
|
|
4709
|
+
}
|
|
4710
|
+
async getStats() {
|
|
4711
|
+
const getDirectoryStats = async (dir) => {
|
|
4712
|
+
try {
|
|
4713
|
+
const files = await fs6.readdir(dir);
|
|
4714
|
+
let totalSize = 0;
|
|
4715
|
+
for (const file of files) {
|
|
4716
|
+
const stats = await fs6.stat(path6.join(dir, file));
|
|
4717
|
+
totalSize += stats.size;
|
|
4718
|
+
}
|
|
4719
|
+
return {
|
|
4720
|
+
count: files.length,
|
|
4721
|
+
sizeBytes: totalSize
|
|
4722
|
+
};
|
|
4723
|
+
} catch {
|
|
4724
|
+
return { count: 0, sizeBytes: 0 };
|
|
4725
|
+
}
|
|
4726
|
+
};
|
|
4727
|
+
const [resolutions, definitions] = await Promise.all([
|
|
4728
|
+
getDirectoryStats(this.resolutionsDir),
|
|
4729
|
+
getDirectoryStats(this.definitionsDir)
|
|
4730
|
+
]);
|
|
4731
|
+
return { resolutions, definitions };
|
|
4732
|
+
}
|
|
4733
|
+
getResolutionKey(name, version) {
|
|
4734
|
+
const key = `${name}_${version}`;
|
|
4735
|
+
return key.replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
4736
|
+
}
|
|
4737
|
+
getDefinitionKey(pluginId, updatedAt) {
|
|
4738
|
+
const key = `${pluginId}_${updatedAt}`;
|
|
4739
|
+
return key.replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
4740
|
+
}
|
|
4741
|
+
}
|
|
4742
|
+
|
|
4998
4743
|
// src/plugins/manager.ts
|
|
4999
4744
|
init_dependencies_parser();
|
|
5000
4745
|
init_validation_errors();
|
|
5001
|
-
init_client_factory();
|
|
5002
|
-
init_catalog_service();
|
|
5003
|
-
|
|
5004
|
-
// src/dependencies/catalog/plugin-source.ts
|
|
5005
|
-
init_src();
|
|
5006
4746
|
init_search_ranking();
|
|
5007
4747
|
|
|
5008
|
-
class
|
|
5009
|
-
|
|
5010
|
-
|
|
5011
|
-
|
|
5012
|
-
|
|
5013
|
-
|
|
5014
|
-
|
|
5015
|
-
|
|
4748
|
+
class PluginManager {
|
|
4749
|
+
cache;
|
|
4750
|
+
options;
|
|
4751
|
+
client;
|
|
4752
|
+
constructor(options = {}) {
|
|
4753
|
+
this.options = options;
|
|
4754
|
+
this.cache = new EnhancedPluginCache(options.noCache || false);
|
|
4755
|
+
}
|
|
4756
|
+
async getClient() {
|
|
4757
|
+
if (!this.client) {
|
|
4758
|
+
const hasProjectScope = !!(this.options.project || this.options.workspaceId);
|
|
4759
|
+
if (hasProjectScope) {
|
|
4760
|
+
this.client = await getProjectClient({
|
|
4761
|
+
project: this.options.project,
|
|
4762
|
+
credentials: this.options.credentials,
|
|
4763
|
+
apiUrl: this.options.apiUrl,
|
|
4764
|
+
workspaceId: this.options.workspaceId,
|
|
4765
|
+
headers: {
|
|
4766
|
+
"x-multiple-integrations": "true"
|
|
4767
|
+
}
|
|
4768
|
+
});
|
|
4769
|
+
} else if (this.options.credentials) {
|
|
4770
|
+
this.client = new Client4({
|
|
4771
|
+
token: this.options.credentials.token,
|
|
4772
|
+
apiUrl: this.options.apiUrl || this.options.credentials.apiUrl,
|
|
4773
|
+
...this.options.credentials.workspaceId ? { workspaceId: this.options.credentials.workspaceId } : {},
|
|
4774
|
+
headers: {
|
|
4775
|
+
"x-multiple-integrations": "true"
|
|
4776
|
+
}
|
|
4777
|
+
});
|
|
4778
|
+
} else {
|
|
4779
|
+
this.client = await getProjectClient({
|
|
4780
|
+
headers: {
|
|
4781
|
+
"x-multiple-integrations": "true"
|
|
4782
|
+
}
|
|
4783
|
+
});
|
|
4784
|
+
}
|
|
4785
|
+
}
|
|
4786
|
+
return this.client;
|
|
4787
|
+
}
|
|
4788
|
+
async loadPlugins(dependencies) {
|
|
4789
|
+
const errors = [];
|
|
4790
|
+
const warnings = [];
|
|
4791
|
+
const parseResult = PluginParser.parsePlugins(dependencies);
|
|
4792
|
+
const plugins = parseResult.plugins;
|
|
4793
|
+
errors.push(...parseResult.errors);
|
|
4794
|
+
const duplicateWarnings = PluginParser.checkDuplicates(plugins);
|
|
4795
|
+
warnings.push(...duplicateWarnings);
|
|
4796
|
+
const fetchPromises = plugins.map(async (plugin) => {
|
|
4797
|
+
try {
|
|
4798
|
+
plugin.definition = await this.fetchPlugin(plugin.ref);
|
|
4799
|
+
} catch {
|
|
4800
|
+
errors.push(ValidationErrors.unknownPlugin(plugin.alias, plugin.ref.fullName));
|
|
4801
|
+
}
|
|
4802
|
+
});
|
|
4803
|
+
await Promise.all(fetchPromises);
|
|
4804
|
+
return { plugins, errors, warnings };
|
|
4805
|
+
}
|
|
4806
|
+
async fetchPlugin(ref) {
|
|
4807
|
+
const cachedResolution = await this.cache.getResolution(ref.name, ref.version);
|
|
4808
|
+
if (cachedResolution) {
|
|
4809
|
+
const cachedDefinition = await this.cache.getDefinition(cachedResolution.pluginId, cachedResolution.updatedAt);
|
|
4810
|
+
if (cachedDefinition) {
|
|
4811
|
+
return cachedDefinition;
|
|
4812
|
+
}
|
|
4813
|
+
}
|
|
4814
|
+
const client = await this.getClient();
|
|
5016
4815
|
const plugin = await this._findPublicPlugin(client, ref);
|
|
5017
4816
|
if (!plugin) {
|
|
5018
4817
|
throw new AdkError({
|
|
@@ -5021,18 +4820,20 @@ class PluginCatalogSource {
|
|
|
5021
4820
|
message: await this._buildPluginNotFoundMessage(client, ref)
|
|
5022
4821
|
});
|
|
5023
4822
|
}
|
|
5024
|
-
|
|
4823
|
+
await this.cache.setResolution(ref.name, ref.version, plugin.id, plugin.updatedAt);
|
|
4824
|
+
await this.cache.setDefinition(plugin.id, plugin.updatedAt, plugin);
|
|
4825
|
+
return plugin;
|
|
5025
4826
|
}
|
|
5026
|
-
async
|
|
5027
|
-
const client = await this.
|
|
4827
|
+
async searchPlugins(query, limit = 20) {
|
|
4828
|
+
const client = await this.getClient();
|
|
5028
4829
|
const results = new Map;
|
|
5029
4830
|
for await (const plugin of client.list.publicPlugins({})) {
|
|
5030
4831
|
collectCatalogSearchResult(results, plugin, query);
|
|
5031
4832
|
}
|
|
5032
4833
|
return getSortedCatalogSearchResults(results, limit);
|
|
5033
4834
|
}
|
|
5034
|
-
async
|
|
5035
|
-
const client = await this.
|
|
4835
|
+
async listPluginVersions(name) {
|
|
4836
|
+
const client = await this.getClient();
|
|
5036
4837
|
const versions = new Set;
|
|
5037
4838
|
for await (const plugin of client.list.publicPlugins({ name })) {
|
|
5038
4839
|
versions.add(plugin.version);
|
|
@@ -5068,49 +4869,15 @@ class PluginCatalogSource {
|
|
|
5068
4869
|
}
|
|
5069
4870
|
return false;
|
|
5070
4871
|
}
|
|
5071
|
-
}
|
|
5072
|
-
|
|
5073
|
-
// src/plugins/manager.ts
|
|
5074
|
-
class PluginManager {
|
|
5075
|
-
source;
|
|
5076
|
-
service;
|
|
5077
|
-
constructor(options = {}) {
|
|
5078
|
-
const { noCache, ...clientOptions } = options;
|
|
5079
|
-
this.source = new PluginCatalogSource(new CatalogClientFactory(clientOptions));
|
|
5080
|
-
this.service = new CatalogService(this.source, noCache || false);
|
|
5081
|
-
}
|
|
5082
|
-
async loadPlugins(dependencies) {
|
|
5083
|
-
const errors = [];
|
|
5084
|
-
const warnings = [];
|
|
5085
|
-
const parseResult = PluginParser.parsePlugins(dependencies);
|
|
5086
|
-
const plugins = parseResult.plugins;
|
|
5087
|
-
errors.push(...parseResult.errors);
|
|
5088
|
-
const duplicateWarnings = PluginParser.checkDuplicates(plugins);
|
|
5089
|
-
warnings.push(...duplicateWarnings);
|
|
5090
|
-
const fetchPromises = plugins.map(async (plugin) => {
|
|
5091
|
-
try {
|
|
5092
|
-
plugin.definition = await this.fetchPlugin(plugin.ref);
|
|
5093
|
-
} catch {
|
|
5094
|
-
errors.push(ValidationErrors.unknownPlugin(plugin.alias, plugin.ref.fullName));
|
|
5095
|
-
}
|
|
5096
|
-
});
|
|
5097
|
-
await Promise.all(fetchPromises);
|
|
5098
|
-
return { plugins, errors, warnings };
|
|
5099
|
-
}
|
|
5100
|
-
async fetchPlugin(ref) {
|
|
5101
|
-
return this.service.getDefinition(ref);
|
|
5102
|
-
}
|
|
5103
|
-
async searchPlugins(query, limit = 20) {
|
|
5104
|
-
return this.source.search(query, limit);
|
|
5105
|
-
}
|
|
5106
|
-
async listPluginVersions(name) {
|
|
5107
|
-
return this.source.listVersions(name);
|
|
5108
|
-
}
|
|
5109
4872
|
async getCacheStats() {
|
|
5110
|
-
|
|
4873
|
+
const stats = await this.cache.getStats();
|
|
4874
|
+
return {
|
|
4875
|
+
count: stats.resolutions.count + stats.definitions.count,
|
|
4876
|
+
sizeBytes: stats.resolutions.sizeBytes + stats.definitions.sizeBytes
|
|
4877
|
+
};
|
|
5111
4878
|
}
|
|
5112
4879
|
async clearCache() {
|
|
5113
|
-
await this.
|
|
4880
|
+
await this.cache.clear();
|
|
5114
4881
|
}
|
|
5115
4882
|
}
|
|
5116
4883
|
|
|
@@ -5138,10 +4905,9 @@ class PluginRegistry {
|
|
|
5138
4905
|
|
|
5139
4906
|
// src/dependencies/dependency-manager.ts
|
|
5140
4907
|
init_agent_project();
|
|
5141
|
-
init_snapshot_store();
|
|
5142
4908
|
|
|
5143
4909
|
class DependencyManager {
|
|
5144
|
-
|
|
4910
|
+
lockFile;
|
|
5145
4911
|
env;
|
|
5146
4912
|
client;
|
|
5147
4913
|
projectPath;
|
|
@@ -5154,8 +4920,8 @@ class DependencyManager {
|
|
|
5154
4920
|
this.projectPath = opts.projectPath;
|
|
5155
4921
|
this.env = opts.env;
|
|
5156
4922
|
this.client = opts.client;
|
|
4923
|
+
this.lockFile = new LockFile({ projectPath: opts.projectPath, env: opts.env });
|
|
5157
4924
|
this.botId = opts.botId;
|
|
5158
|
-
this.snapshotStore = new DependencySnapshotStore({ projectPath: opts.projectPath });
|
|
5159
4925
|
this.integrationRegistry = opts.integrationRegistry ?? new IntegrationRegistry;
|
|
5160
4926
|
this.pluginRegistry = opts.pluginRegistry ?? new PluginRegistry;
|
|
5161
4927
|
this.integrationResolver = opts.integrationResolver ?? new IntegrationResolver({ registry: this.integrationRegistry, client: this.client });
|
|
@@ -5167,13 +4933,14 @@ class DependencyManager {
|
|
|
5167
4933
|
}
|
|
5168
4934
|
static async fromProject(opts) {
|
|
5169
4935
|
const project = await AgentProject.load(opts.projectPath);
|
|
5170
|
-
const
|
|
5171
|
-
if (!
|
|
4936
|
+
const info = project.agentInfo;
|
|
4937
|
+
if (!info) {
|
|
5172
4938
|
throw new DependencyError({
|
|
5173
4939
|
code: "BOT_NOT_FOUND",
|
|
5174
|
-
message: `No
|
|
4940
|
+
message: `No agent.json found in ${opts.projectPath}. Run 'adk init' or 'adk login' to set up the project.`
|
|
5175
4941
|
});
|
|
5176
4942
|
}
|
|
4943
|
+
const botId = opts.env === "dev" ? info.devId ?? info.botId : info.botId;
|
|
5177
4944
|
return new DependencyManager({
|
|
5178
4945
|
projectPath: project.path,
|
|
5179
4946
|
env: opts.env,
|
|
@@ -5185,68 +4952,8 @@ class DependencyManager {
|
|
|
5185
4952
|
pluginResolver: opts.pluginResolver
|
|
5186
4953
|
});
|
|
5187
4954
|
}
|
|
5188
|
-
static getProjectBotId(project, env) {
|
|
5189
|
-
const info = project.agentInfo;
|
|
5190
|
-
if (!info)
|
|
5191
|
-
return;
|
|
5192
|
-
return env === "dev" ? info.devId ?? info.botId : info.botId;
|
|
5193
|
-
}
|
|
5194
|
-
async getProjectBotId(env) {
|
|
5195
|
-
const project = await AgentProject.load(this.projectPath);
|
|
5196
|
-
const botId = DependencyManager.getProjectBotId(project, env);
|
|
5197
|
-
if (!botId) {
|
|
5198
|
-
throw new DependencyError({
|
|
5199
|
-
code: "BOT_NOT_FOUND",
|
|
5200
|
-
message: `No ${env} bot ID found in ${this.projectPath}. Run 'adk link' to link the project to a bot.`
|
|
5201
|
-
});
|
|
5202
|
-
}
|
|
5203
|
-
return botId;
|
|
5204
|
-
}
|
|
5205
|
-
async readSnapshot(options) {
|
|
5206
|
-
return this.snapshotStore.readOrEmpty(this.env, {
|
|
5207
|
-
tolerant: options?.tolerant,
|
|
5208
|
-
botId: this.botId
|
|
5209
|
-
});
|
|
5210
|
-
}
|
|
5211
|
-
async writeSnapshot(snapshot) {
|
|
5212
|
-
await this.snapshotStore.write({
|
|
5213
|
-
...snapshot,
|
|
5214
|
-
botId: snapshot.botId || this.botId,
|
|
5215
|
-
fetchedAt: new Date().toISOString()
|
|
5216
|
-
});
|
|
5217
|
-
}
|
|
5218
|
-
async readCloudSnapshot(previous) {
|
|
5219
|
-
const { bot } = await this.client.getBot({ id: this.botId });
|
|
5220
|
-
return dependencySnapshotFromBot({
|
|
5221
|
-
bot,
|
|
5222
|
-
botId: this.botId,
|
|
5223
|
-
env: this.env,
|
|
5224
|
-
fetchedAt: new Date,
|
|
5225
|
-
previous
|
|
5226
|
-
});
|
|
5227
|
-
}
|
|
5228
|
-
async snapshotStateFromCloud() {
|
|
5229
|
-
const previous = await this.readSnapshot({ tolerant: true });
|
|
5230
|
-
const cloud = await this.readCloudSnapshot(previous);
|
|
5231
|
-
return dependencySnapshotToState(cloud);
|
|
5232
|
-
}
|
|
5233
|
-
async applyState(state, opts) {
|
|
5234
|
-
const parsed = dependencyStateSchema.parse({
|
|
5235
|
-
...state,
|
|
5236
|
-
env: this.env
|
|
5237
|
-
});
|
|
5238
|
-
await this.writeSnapshot({
|
|
5239
|
-
version: 1,
|
|
5240
|
-
env: this.env,
|
|
5241
|
-
botId: this.botId,
|
|
5242
|
-
fetchedAt: new Date().toISOString(),
|
|
5243
|
-
integrations: parsed.integrations,
|
|
5244
|
-
plugins: parsed.plugins
|
|
5245
|
-
});
|
|
5246
|
-
return await this.apply(opts);
|
|
5247
|
-
}
|
|
5248
4955
|
async list(type) {
|
|
5249
|
-
const data = await this.
|
|
4956
|
+
const data = await this.lockFile.read();
|
|
5250
4957
|
const out = [];
|
|
5251
4958
|
if (!type || type === "integration") {
|
|
5252
4959
|
for (const [alias, e] of Object.entries(data.integrations)) {
|
|
@@ -5273,9 +4980,9 @@ class DependencyManager {
|
|
|
5273
4980
|
}
|
|
5274
4981
|
const alias = spec.alias ?? spec.name;
|
|
5275
4982
|
const version = spec.version ?? "latest";
|
|
5276
|
-
const
|
|
5277
|
-
if (type === "integration" &&
|
|
5278
|
-
const existing =
|
|
4983
|
+
const lock = await this.lockFile.read();
|
|
4984
|
+
if (type === "integration" && lock.integrations[alias]) {
|
|
4985
|
+
const existing = lock.integrations[alias];
|
|
5279
4986
|
const versionMatch = version === "latest" || existing.version === version;
|
|
5280
4987
|
if (existing.enabled && versionMatch && jsonEqual(existing.config, spec.config ?? {})) {
|
|
5281
4988
|
return {
|
|
@@ -5285,8 +4992,8 @@ class DependencyManager {
|
|
|
5285
4992
|
};
|
|
5286
4993
|
}
|
|
5287
4994
|
}
|
|
5288
|
-
if (type === "plugin" &&
|
|
5289
|
-
const existing =
|
|
4995
|
+
if (type === "plugin" && lock.plugins[alias]) {
|
|
4996
|
+
const existing = lock.plugins[alias];
|
|
5290
4997
|
const versionMatch = version === "latest" || existing.version === version;
|
|
5291
4998
|
if (existing.enabled && versionMatch && jsonEqual(existing.config, spec.config ?? {})) {
|
|
5292
4999
|
return {
|
|
@@ -5304,54 +5011,28 @@ class DependencyManager {
|
|
|
5304
5011
|
config: spec.config ?? {}
|
|
5305
5012
|
};
|
|
5306
5013
|
let installedDisabled;
|
|
5307
|
-
let authorizationPending = false;
|
|
5308
5014
|
try {
|
|
5309
5015
|
await this.integrationResolver.applyToCloud({ botId: this.botId, alias, entry: desired });
|
|
5310
5016
|
} catch (err) {
|
|
5311
5017
|
const missingFields = extractMissingRequiredFields(err);
|
|
5312
|
-
if (missingFields)
|
|
5313
|
-
await this.integrationResolver.applyToCloud({
|
|
5314
|
-
botId: this.botId,
|
|
5315
|
-
alias,
|
|
5316
|
-
entry: { ...desired, enabled: false }
|
|
5317
|
-
});
|
|
5318
|
-
installedDisabled = { missingFields };
|
|
5319
|
-
} else if (await this.specRequiresAuthorization(spec.name, spec.version)) {
|
|
5320
|
-
await this.integrationResolver.applyToCloud({
|
|
5321
|
-
botId: this.botId,
|
|
5322
|
-
alias,
|
|
5323
|
-
entry: { ...desired, enabled: false }
|
|
5324
|
-
});
|
|
5325
|
-
authorizationPending = true;
|
|
5326
|
-
} else {
|
|
5018
|
+
if (!missingFields)
|
|
5327
5019
|
throw err;
|
|
5328
|
-
|
|
5329
|
-
|
|
5330
|
-
|
|
5331
|
-
|
|
5332
|
-
|
|
5333
|
-
|
|
5334
|
-
refreshed.integrations[snapshotAlias] = {
|
|
5335
|
-
...refreshed.integrations[snapshotAlias],
|
|
5336
|
-
...installedDisabled ? { missingFields: installedDisabled.missingFields } : {},
|
|
5337
|
-
...authorizationPending ? { authorizationPending: true } : {}
|
|
5338
|
-
};
|
|
5339
|
-
await this.writeSnapshot(refreshed);
|
|
5340
|
-
}
|
|
5020
|
+
await this.integrationResolver.applyToCloud({
|
|
5021
|
+
botId: this.botId,
|
|
5022
|
+
alias,
|
|
5023
|
+
entry: { ...desired, enabled: false }
|
|
5024
|
+
});
|
|
5025
|
+
installedDisabled = { missingFields };
|
|
5341
5026
|
}
|
|
5027
|
+
const refreshed = await this.refreshLockFromCloud();
|
|
5342
5028
|
const resolvedVersion = refreshed.integrations[alias]?.version ?? version;
|
|
5343
|
-
return {
|
|
5344
|
-
ok: true,
|
|
5345
|
-
resource: { type, alias, name: spec.name, version: resolvedVersion },
|
|
5346
|
-
installedDisabled,
|
|
5347
|
-
...authorizationPending ? { installedAwaitingAuthorization: true } : {}
|
|
5348
|
-
};
|
|
5029
|
+
return { ok: true, resource: { type, alias, name: spec.name, version: resolvedVersion }, installedDisabled };
|
|
5349
5030
|
} else {
|
|
5350
5031
|
const { dependencies: resolvedDeps, autoResolved } = await this.resolvePluginDependencies({
|
|
5351
5032
|
pluginName: spec.name,
|
|
5352
5033
|
pluginVersion: version,
|
|
5353
5034
|
userDeps: spec.dependencies ?? {},
|
|
5354
|
-
|
|
5035
|
+
lock
|
|
5355
5036
|
});
|
|
5356
5037
|
const desired = {
|
|
5357
5038
|
name: spec.name,
|
|
@@ -5360,47 +5041,18 @@ class DependencyManager {
|
|
|
5360
5041
|
config: spec.config ?? {},
|
|
5361
5042
|
dependencies: resolvedDeps
|
|
5362
5043
|
};
|
|
5363
|
-
|
|
5364
|
-
|
|
5365
|
-
await this.pluginResolver.applyToCloud({ botId: this.botId, alias, entry: desired, state: snapshot });
|
|
5366
|
-
} catch (err) {
|
|
5367
|
-
const missingFields = extractMissingRequiredFields(err);
|
|
5368
|
-
if (!missingFields)
|
|
5369
|
-
throw err;
|
|
5370
|
-
await this.pluginResolver.applyToCloud({
|
|
5371
|
-
botId: this.botId,
|
|
5372
|
-
alias,
|
|
5373
|
-
entry: { ...desired, enabled: false },
|
|
5374
|
-
state: snapshot
|
|
5375
|
-
});
|
|
5376
|
-
installedDisabled = { missingFields };
|
|
5377
|
-
}
|
|
5378
|
-
const refreshed = await this.refreshSnapshotFromCloud();
|
|
5379
|
-
if (installedDisabled) {
|
|
5380
|
-
const snapshotAlias = refreshed.plugins[alias] ? alias : Object.keys(refreshed.plugins).find((k) => !snapshot.plugins[k] && !refreshed.plugins[k].enabled && refreshed.plugins[k].name === spec.name);
|
|
5381
|
-
if (snapshotAlias && refreshed.plugins[snapshotAlias]) {
|
|
5382
|
-
refreshed.plugins[snapshotAlias] = {
|
|
5383
|
-
...refreshed.plugins[snapshotAlias],
|
|
5384
|
-
missingFields: installedDisabled.missingFields
|
|
5385
|
-
};
|
|
5386
|
-
await this.writeSnapshot(refreshed);
|
|
5387
|
-
}
|
|
5388
|
-
}
|
|
5044
|
+
await this.pluginResolver.applyToCloud({ botId: this.botId, alias, entry: desired, lock });
|
|
5045
|
+
const refreshed = await this.refreshLockFromCloud();
|
|
5389
5046
|
const resolvedVersion = refreshed.plugins[alias]?.version ?? version;
|
|
5390
|
-
return {
|
|
5391
|
-
ok: true,
|
|
5392
|
-
resource: { type, alias, name: spec.name, version: resolvedVersion },
|
|
5393
|
-
autoResolved,
|
|
5394
|
-
installedDisabled
|
|
5395
|
-
};
|
|
5047
|
+
return { ok: true, resource: { type, alias, name: spec.name, version: resolvedVersion }, autoResolved };
|
|
5396
5048
|
}
|
|
5397
5049
|
}
|
|
5398
5050
|
async remove(type, alias) {
|
|
5399
5051
|
if (type === "interface") {
|
|
5400
5052
|
throw new DependencyError({ code: "BUILTIN_INTERFACE_IMMUTABLE", message: "Interfaces cannot be removed." });
|
|
5401
5053
|
}
|
|
5402
|
-
const
|
|
5403
|
-
const exists = type === "integration" ? !!
|
|
5054
|
+
const lock = await this.lockFile.read();
|
|
5055
|
+
const exists = type === "integration" ? !!lock.integrations[alias] : !!lock.plugins[alias];
|
|
5404
5056
|
if (!exists)
|
|
5405
5057
|
return { ok: true, noop: true };
|
|
5406
5058
|
if (type === "integration") {
|
|
@@ -5408,15 +5060,15 @@ class DependencyManager {
|
|
|
5408
5060
|
} else {
|
|
5409
5061
|
await this.pluginResolver.removeFromCloud({ botId: this.botId, alias });
|
|
5410
5062
|
}
|
|
5411
|
-
await this.
|
|
5063
|
+
await this.refreshLockFromCloud();
|
|
5412
5064
|
return { ok: true };
|
|
5413
5065
|
}
|
|
5414
5066
|
async upgrade(type, alias, version) {
|
|
5415
5067
|
if (type === "interface") {
|
|
5416
5068
|
throw new DependencyError({ code: "BUILTIN_INTERFACE_IMMUTABLE", message: "Interfaces cannot be upgraded." });
|
|
5417
5069
|
}
|
|
5418
|
-
const
|
|
5419
|
-
const existing = type === "integration" ?
|
|
5070
|
+
const lock = await this.lockFile.read();
|
|
5071
|
+
const existing = type === "integration" ? lock.integrations[alias] : lock.plugins[alias];
|
|
5420
5072
|
if (!existing) {
|
|
5421
5073
|
throw new DependencyError({
|
|
5422
5074
|
code: type === "integration" ? "INTEGRATION_NOT_FOUND" : "PLUGIN_NOT_FOUND",
|
|
@@ -5428,8 +5080,8 @@ class DependencyManager {
|
|
|
5428
5080
|
return { ok: true, noop: true, resource: { type, alias, name: existing.name, version: existing.version } };
|
|
5429
5081
|
}
|
|
5430
5082
|
const next = { ...existing, version: targetVersion };
|
|
5431
|
-
await this.applyEntry(type, alias, next,
|
|
5432
|
-
await this.
|
|
5083
|
+
await this.applyEntry(type, alias, next, lock);
|
|
5084
|
+
await this.refreshLockFromCloud();
|
|
5433
5085
|
return { ok: true, resource: { type, alias, name: existing.name, version: next.version } };
|
|
5434
5086
|
}
|
|
5435
5087
|
async enable(type, alias) {
|
|
@@ -5445,8 +5097,8 @@ class DependencyManager {
|
|
|
5445
5097
|
message: "Interfaces cannot be enabled/disabled."
|
|
5446
5098
|
});
|
|
5447
5099
|
}
|
|
5448
|
-
const
|
|
5449
|
-
const existing = type === "integration" ?
|
|
5100
|
+
const lock = await this.lockFile.read();
|
|
5101
|
+
const existing = type === "integration" ? lock.integrations[alias] : lock.plugins[alias];
|
|
5450
5102
|
if (!existing) {
|
|
5451
5103
|
throw new DependencyError({
|
|
5452
5104
|
code: type === "integration" ? "INTEGRATION_NOT_FOUND" : "PLUGIN_NOT_FOUND",
|
|
@@ -5455,12 +5107,12 @@ class DependencyManager {
|
|
|
5455
5107
|
}
|
|
5456
5108
|
if (existing.enabled === enabled)
|
|
5457
5109
|
return { ok: true, noop: true };
|
|
5458
|
-
await this.applyEntry(type, alias, { ...existing, enabled },
|
|
5459
|
-
const
|
|
5460
|
-
const refreshedEntry = type === "integration" ?
|
|
5110
|
+
await this.applyEntry(type, alias, { ...existing, enabled }, lock);
|
|
5111
|
+
const refreshedLock = await this.refreshLockFromCloud();
|
|
5112
|
+
const refreshedEntry = type === "integration" ? refreshedLock.integrations[alias] : refreshedLock.plugins[alias];
|
|
5461
5113
|
if (!refreshedEntry || refreshedEntry.enabled !== enabled) {
|
|
5462
5114
|
throw new DependencyError({
|
|
5463
|
-
code: "
|
|
5115
|
+
code: "LOCK_DRIFT",
|
|
5464
5116
|
message: `Cloud did not persist ${type} '${alias}' as ${enabled ? "enabled" : "disabled"}.`,
|
|
5465
5117
|
details: {
|
|
5466
5118
|
type,
|
|
@@ -5476,8 +5128,8 @@ class DependencyManager {
|
|
|
5476
5128
|
if (type === "interface") {
|
|
5477
5129
|
throw new DependencyError({ code: "BUILTIN_INTERFACE_IMMUTABLE", message: "Interfaces cannot be configured." });
|
|
5478
5130
|
}
|
|
5479
|
-
const
|
|
5480
|
-
const existing = type === "integration" ?
|
|
5131
|
+
const lock = await this.lockFile.read();
|
|
5132
|
+
const existing = type === "integration" ? lock.integrations[alias] : lock.plugins[alias];
|
|
5481
5133
|
if (!existing) {
|
|
5482
5134
|
throw new DependencyError({
|
|
5483
5135
|
code: type === "integration" ? "INTEGRATION_NOT_FOUND" : "PLUGIN_NOT_FOUND",
|
|
@@ -5494,11 +5146,11 @@ class DependencyManager {
|
|
|
5494
5146
|
if (jsonEqual(next, existing)) {
|
|
5495
5147
|
return { ok: true, noop: true, resource: { type, alias, name: existing.name, version: existing.version } };
|
|
5496
5148
|
}
|
|
5497
|
-
await this.applyEntry(type, alias, next,
|
|
5498
|
-
await this.
|
|
5149
|
+
await this.applyEntry(type, alias, next, lock);
|
|
5150
|
+
await this.refreshLockFromCloud();
|
|
5499
5151
|
return { ok: true, resource: { type, alias, name: existing.name, version: existing.version } };
|
|
5500
5152
|
}
|
|
5501
|
-
async applyEntry(type, alias, entry,
|
|
5153
|
+
async applyEntry(type, alias, entry, lock) {
|
|
5502
5154
|
if (type === "integration") {
|
|
5503
5155
|
await this.integrationResolver.applyToCloud({
|
|
5504
5156
|
botId: this.botId,
|
|
@@ -5510,7 +5162,7 @@ class DependencyManager {
|
|
|
5510
5162
|
botId: this.botId,
|
|
5511
5163
|
alias,
|
|
5512
5164
|
entry,
|
|
5513
|
-
|
|
5165
|
+
lock
|
|
5514
5166
|
});
|
|
5515
5167
|
}
|
|
5516
5168
|
}
|
|
@@ -5524,7 +5176,7 @@ class DependencyManager {
|
|
|
5524
5176
|
continue;
|
|
5525
5177
|
}
|
|
5526
5178
|
const candidates = [];
|
|
5527
|
-
for (const [integrationAlias, integrationEntry] of Object.entries(opts.
|
|
5179
|
+
for (const [integrationAlias, integrationEntry] of Object.entries(opts.lock.integrations)) {
|
|
5528
5180
|
let integrationSpec;
|
|
5529
5181
|
try {
|
|
5530
5182
|
integrationSpec = await this.integrationRegistry.getSpec(integrationEntry.name, integrationEntry.version);
|
|
@@ -5583,67 +5235,85 @@ class DependencyManager {
|
|
|
5583
5235
|
return [];
|
|
5584
5236
|
}
|
|
5585
5237
|
}
|
|
5586
|
-
async
|
|
5587
|
-
|
|
5588
|
-
|
|
5589
|
-
|
|
5590
|
-
|
|
5591
|
-
|
|
5592
|
-
}
|
|
5593
|
-
}
|
|
5594
|
-
async refreshSnapshotFromCloud() {
|
|
5595
|
-
return this.snapshotStore.refreshFromCloud({
|
|
5596
|
-
client: this.client,
|
|
5597
|
-
botId: this.botId,
|
|
5598
|
-
env: this.env,
|
|
5599
|
-
integrationRegistry: this.integrationRegistry
|
|
5600
|
-
});
|
|
5601
|
-
}
|
|
5602
|
-
integrationEntriesMatch(a, b) {
|
|
5603
|
-
return jsonEqual(stripSnapshotMetadata(a), stripSnapshotMetadata(b));
|
|
5604
|
-
}
|
|
5605
|
-
pluginEntriesMatch(a, b) {
|
|
5606
|
-
return jsonEqual(stripSnapshotMetadata(a), stripSnapshotMetadata(b));
|
|
5238
|
+
async refreshLockFromCloud() {
|
|
5239
|
+
const { bot } = await this.client.getBot({ id: this.botId });
|
|
5240
|
+
const previous = await this.lockFile.read();
|
|
5241
|
+
const updated = { ...previous, ...this.cloudToLockShape(bot, previous) };
|
|
5242
|
+
await this.lockFile.write(updated);
|
|
5243
|
+
return updated;
|
|
5607
5244
|
}
|
|
5608
5245
|
async diff() {
|
|
5609
|
-
const
|
|
5610
|
-
const cloud = await this.
|
|
5611
|
-
const delta = {
|
|
5612
|
-
for (const [alias, entry] of Object.entries(
|
|
5246
|
+
const lock = await this.lockFile.read();
|
|
5247
|
+
const cloud = await this.readCloudAsLockShape(lock);
|
|
5248
|
+
const delta = { addedInLock: [], removedInLock: [], changedInLock: [] };
|
|
5249
|
+
for (const [alias, entry] of Object.entries(lock.integrations)) {
|
|
5613
5250
|
const cloudEntry = cloud.integrations[alias];
|
|
5614
5251
|
if (!cloudEntry) {
|
|
5615
|
-
delta.
|
|
5616
|
-
} else if (!
|
|
5617
|
-
delta.
|
|
5252
|
+
delta.addedInLock.push({ type: "integration", alias, name: entry.name, version: entry.version });
|
|
5253
|
+
} else if (!jsonEqual(entry, cloudEntry)) {
|
|
5254
|
+
delta.changedInLock.push({ type: "integration", alias, field: "unspecified" });
|
|
5618
5255
|
}
|
|
5619
5256
|
}
|
|
5620
5257
|
for (const [alias, entry] of Object.entries(cloud.integrations)) {
|
|
5621
|
-
if (!
|
|
5622
|
-
delta.
|
|
5258
|
+
if (!lock.integrations[alias]) {
|
|
5259
|
+
delta.removedInLock.push({ type: "integration", alias, name: entry.name, version: entry.version });
|
|
5623
5260
|
}
|
|
5624
5261
|
}
|
|
5625
|
-
for (const [alias, entry] of Object.entries(
|
|
5262
|
+
for (const [alias, entry] of Object.entries(lock.plugins)) {
|
|
5626
5263
|
const cloudEntry = cloud.plugins[alias];
|
|
5627
5264
|
if (!cloudEntry) {
|
|
5628
|
-
delta.
|
|
5629
|
-
} else if (!
|
|
5630
|
-
delta.
|
|
5265
|
+
delta.addedInLock.push({ type: "plugin", alias, name: entry.name, version: entry.version });
|
|
5266
|
+
} else if (!jsonEqual(entry, cloudEntry)) {
|
|
5267
|
+
delta.changedInLock.push({ type: "plugin", alias, field: "unspecified" });
|
|
5631
5268
|
}
|
|
5632
5269
|
}
|
|
5633
5270
|
for (const [alias, entry] of Object.entries(cloud.plugins)) {
|
|
5634
|
-
if (!
|
|
5635
|
-
delta.
|
|
5271
|
+
if (!lock.plugins[alias]) {
|
|
5272
|
+
delta.removedInLock.push({ type: "plugin", alias, name: entry.name, version: entry.version });
|
|
5636
5273
|
}
|
|
5637
5274
|
}
|
|
5638
|
-
const
|
|
5639
|
-
return { target: this.env,
|
|
5275
|
+
const lockReflectsCloud = delta.addedInLock.length === 0 && delta.removedInLock.length === 0 && delta.changedInLock.length === 0;
|
|
5276
|
+
return { target: this.env, lockReflectsCloud, delta };
|
|
5277
|
+
}
|
|
5278
|
+
async sync(opts) {
|
|
5279
|
+
const previous = await this.lockFile.read();
|
|
5280
|
+
const cloud = await this.readCloudAsLockShape(previous);
|
|
5281
|
+
const added = [];
|
|
5282
|
+
const removed = [];
|
|
5283
|
+
const updated = [];
|
|
5284
|
+
for (const [alias, entry] of Object.entries(cloud.integrations)) {
|
|
5285
|
+
const prev = previous.integrations[alias];
|
|
5286
|
+
if (!prev)
|
|
5287
|
+
added.push({ type: "integration", alias });
|
|
5288
|
+
else if (!jsonEqual(prev, entry))
|
|
5289
|
+
updated.push({ type: "integration", alias });
|
|
5290
|
+
}
|
|
5291
|
+
for (const alias of Object.keys(previous.integrations)) {
|
|
5292
|
+
if (!cloud.integrations[alias])
|
|
5293
|
+
removed.push({ type: "integration", alias });
|
|
5294
|
+
}
|
|
5295
|
+
for (const [alias, entry] of Object.entries(cloud.plugins)) {
|
|
5296
|
+
const prev = previous.plugins[alias];
|
|
5297
|
+
if (!prev)
|
|
5298
|
+
added.push({ type: "plugin", alias });
|
|
5299
|
+
else if (!jsonEqual(prev, entry))
|
|
5300
|
+
updated.push({ type: "plugin", alias });
|
|
5301
|
+
}
|
|
5302
|
+
for (const alias of Object.keys(previous.plugins)) {
|
|
5303
|
+
if (!cloud.plugins[alias])
|
|
5304
|
+
removed.push({ type: "plugin", alias });
|
|
5305
|
+
}
|
|
5306
|
+
if (!opts?.dryRun) {
|
|
5307
|
+
await this.lockFile.write({ ...previous, integrations: cloud.integrations, plugins: cloud.plugins });
|
|
5308
|
+
}
|
|
5309
|
+
return { target: this.env, added, removed, updated, dryRun: opts?.dryRun ?? false };
|
|
5640
5310
|
}
|
|
5641
5311
|
async apply(opts) {
|
|
5642
|
-
const
|
|
5643
|
-
const cloud = await this.
|
|
5312
|
+
const lock = await this.lockFile.read();
|
|
5313
|
+
const cloud = await this.readCloudAsLockShape(lock);
|
|
5644
5314
|
const actions = [];
|
|
5645
5315
|
const errors = [];
|
|
5646
|
-
for (const [alias, entry] of Object.entries(
|
|
5316
|
+
for (const [alias, entry] of Object.entries(lock.integrations)) {
|
|
5647
5317
|
const c = cloud.integrations[alias];
|
|
5648
5318
|
if (!c) {
|
|
5649
5319
|
actions.push({
|
|
@@ -5678,7 +5348,7 @@ class DependencyManager {
|
|
|
5678
5348
|
}
|
|
5679
5349
|
}
|
|
5680
5350
|
for (const alias of Object.keys(cloud.integrations)) {
|
|
5681
|
-
if (!
|
|
5351
|
+
if (!lock.integrations[alias]) {
|
|
5682
5352
|
const c = cloud.integrations[alias];
|
|
5683
5353
|
actions.push({
|
|
5684
5354
|
type: "integration",
|
|
@@ -5688,7 +5358,7 @@ class DependencyManager {
|
|
|
5688
5358
|
});
|
|
5689
5359
|
}
|
|
5690
5360
|
}
|
|
5691
|
-
for (const [alias, entry] of Object.entries(
|
|
5361
|
+
for (const [alias, entry] of Object.entries(lock.plugins)) {
|
|
5692
5362
|
const c = cloud.plugins[alias];
|
|
5693
5363
|
if (!c) {
|
|
5694
5364
|
actions.push({
|
|
@@ -5731,7 +5401,7 @@ class DependencyManager {
|
|
|
5731
5401
|
}
|
|
5732
5402
|
}
|
|
5733
5403
|
for (const alias of Object.keys(cloud.plugins)) {
|
|
5734
|
-
if (!
|
|
5404
|
+
if (!lock.plugins[alias]) {
|
|
5735
5405
|
const c = cloud.plugins[alias];
|
|
5736
5406
|
actions.push({
|
|
5737
5407
|
type: "plugin",
|
|
@@ -5784,8 +5454,8 @@ class DependencyManager {
|
|
|
5784
5454
|
else
|
|
5785
5455
|
await this.pluginResolver.removeFromCloud({ botId: this.botId, alias: a.alias });
|
|
5786
5456
|
} else if (!appliedKeys.has(key)) {
|
|
5787
|
-
const entry = a.type === "integration" ?
|
|
5788
|
-
await this.applyEntry(a.type, a.alias, entry,
|
|
5457
|
+
const entry = a.type === "integration" ? lock.integrations[a.alias] : lock.plugins[a.alias];
|
|
5458
|
+
await this.applyEntry(a.type, a.alias, entry, lock);
|
|
5789
5459
|
appliedKeys.add(key);
|
|
5790
5460
|
}
|
|
5791
5461
|
applied.push(a);
|
|
@@ -5798,7 +5468,7 @@ class DependencyManager {
|
|
|
5798
5468
|
});
|
|
5799
5469
|
}
|
|
5800
5470
|
}
|
|
5801
|
-
await this.
|
|
5471
|
+
await this.refreshLockFromCloud();
|
|
5802
5472
|
return { target: this.env, applied, skipped: [], errors, dryRun: false };
|
|
5803
5473
|
}
|
|
5804
5474
|
async copy(opts) {
|
|
@@ -5811,44 +5481,85 @@ class DependencyManager {
|
|
|
5811
5481
|
message: `DependencyManager constructed with env='${this.env}' but copy targets '${opts.to}'`
|
|
5812
5482
|
});
|
|
5813
5483
|
}
|
|
5814
|
-
const
|
|
5815
|
-
if (
|
|
5484
|
+
const sourceLock = new LockFile({ projectPath: this.projectPath, env: opts.from });
|
|
5485
|
+
if (!await sourceLock.exists()) {
|
|
5816
5486
|
throw new DependencyError({
|
|
5817
|
-
code: "
|
|
5818
|
-
message:
|
|
5487
|
+
code: "SOURCE_LOCK_MISSING",
|
|
5488
|
+
message: `Source lock file dependencies.${opts.from}.lock.json does not exist`
|
|
5819
5489
|
});
|
|
5820
5490
|
}
|
|
5821
|
-
const
|
|
5822
|
-
const
|
|
5823
|
-
|
|
5824
|
-
|
|
5825
|
-
|
|
5826
|
-
|
|
5827
|
-
});
|
|
5828
|
-
const targetSnapshotExists = await this.snapshotStore.exists(this.env);
|
|
5829
|
-
const targetSnapshot = await this.readSnapshot();
|
|
5830
|
-
const originalSnapshot = JSON.stringify(targetSnapshot);
|
|
5831
|
-
const merged = { ...targetSnapshot, integrations: sourceData.integrations, plugins: sourceData.plugins };
|
|
5832
|
-
await this.writeSnapshot(merged);
|
|
5491
|
+
const sourceData = await sourceLock.read();
|
|
5492
|
+
const targetLockExists = await this.lockFile.exists();
|
|
5493
|
+
const targetLock = await this.lockFile.read();
|
|
5494
|
+
const snapshot = JSON.stringify(targetLock);
|
|
5495
|
+
const merged = { ...targetLock, integrations: sourceData.integrations, plugins: sourceData.plugins };
|
|
5496
|
+
await this.lockFile.write(merged);
|
|
5833
5497
|
try {
|
|
5834
5498
|
const result = await this.apply({ dryRun: opts.dryRun, yes: opts.yes });
|
|
5835
5499
|
if (opts.dryRun) {
|
|
5836
|
-
if (
|
|
5837
|
-
await this.
|
|
5500
|
+
if (targetLockExists) {
|
|
5501
|
+
await this.lockFile.write(JSON.parse(snapshot));
|
|
5838
5502
|
} else {
|
|
5839
|
-
await this.
|
|
5503
|
+
await this.lockFile.delete();
|
|
5840
5504
|
}
|
|
5841
5505
|
}
|
|
5842
5506
|
return result;
|
|
5843
5507
|
} catch (err) {
|
|
5844
|
-
if (
|
|
5845
|
-
await this.
|
|
5508
|
+
if (targetLockExists) {
|
|
5509
|
+
await this.lockFile.write(JSON.parse(snapshot)).catch(() => {});
|
|
5846
5510
|
} else {
|
|
5847
|
-
await this.
|
|
5511
|
+
await this.lockFile.delete().catch(() => {});
|
|
5848
5512
|
}
|
|
5849
5513
|
throw err;
|
|
5850
5514
|
}
|
|
5851
5515
|
}
|
|
5516
|
+
async readCloudAsLockShape(previousLock) {
|
|
5517
|
+
const { bot } = await this.client.getBot({ id: this.botId });
|
|
5518
|
+
const previous = previousLock ?? await this.lockFile.read();
|
|
5519
|
+
return this.cloudToLockShape(bot, previous);
|
|
5520
|
+
}
|
|
5521
|
+
cloudToLockShape(bot, previous) {
|
|
5522
|
+
const integrations = {};
|
|
5523
|
+
const usedIntegrationAliases = new Set;
|
|
5524
|
+
for (const [cloudAlias, c] of Object.entries(bot.integrations ?? {})) {
|
|
5525
|
+
const cloudName = typeof c.name === "string" ? c.name : undefined;
|
|
5526
|
+
const alias = this.chooseCloudAlias({
|
|
5527
|
+
cloudAlias,
|
|
5528
|
+
cloudName,
|
|
5529
|
+
previous: previous.integrations,
|
|
5530
|
+
used: usedIntegrationAliases
|
|
5531
|
+
});
|
|
5532
|
+
usedIntegrationAliases.add(alias);
|
|
5533
|
+
const entry = this.integrationResolver.toLockEntry(c);
|
|
5534
|
+
integrations[alias] = entry;
|
|
5535
|
+
}
|
|
5536
|
+
const plugins = {};
|
|
5537
|
+
const usedPluginAliases = new Set;
|
|
5538
|
+
for (const [cloudAlias, c] of Object.entries(bot.plugins ?? {})) {
|
|
5539
|
+
const cloudName = typeof c.name === "string" ? c.name : undefined;
|
|
5540
|
+
const alias = this.chooseCloudAlias({
|
|
5541
|
+
cloudAlias,
|
|
5542
|
+
cloudName,
|
|
5543
|
+
previous: previous.plugins,
|
|
5544
|
+
used: usedPluginAliases
|
|
5545
|
+
});
|
|
5546
|
+
usedPluginAliases.add(alias);
|
|
5547
|
+
const entry = this.pluginResolver.toLockEntry(c);
|
|
5548
|
+
plugins[alias] = entry;
|
|
5549
|
+
}
|
|
5550
|
+
return { integrations, plugins };
|
|
5551
|
+
}
|
|
5552
|
+
chooseCloudAlias(opts) {
|
|
5553
|
+
if (isFriendlyAlias(opts.cloudAlias) && opts.previous[opts.cloudAlias] && !opts.used.has(opts.cloudAlias)) {
|
|
5554
|
+
return opts.cloudAlias;
|
|
5555
|
+
}
|
|
5556
|
+
if (opts.cloudName) {
|
|
5557
|
+
const match = Object.entries(opts.previous).find(([alias, entry]) => !opts.used.has(alias) && entry.name === opts.cloudName);
|
|
5558
|
+
if (match)
|
|
5559
|
+
return match[0];
|
|
5560
|
+
}
|
|
5561
|
+
return generateFriendlyAlias(opts.cloudName, opts.cloudAlias, opts.used);
|
|
5562
|
+
}
|
|
5852
5563
|
}
|
|
5853
5564
|
function formatMissingDependencySuggestion(opts) {
|
|
5854
5565
|
if (opts.implementers.length === 0) {
|
|
@@ -5865,119 +5576,22 @@ function formatMissingDependencySuggestion(opts) {
|
|
|
5865
5576
|
return lines.join(`
|
|
5866
5577
|
`);
|
|
5867
5578
|
}
|
|
5868
|
-
function
|
|
5869
|
-
const
|
|
5870
|
-
|
|
5871
|
-
cloudId: _cloudId,
|
|
5872
|
-
updatedAt: _updatedAt,
|
|
5873
|
-
...semantic
|
|
5874
|
-
} = entry;
|
|
5875
|
-
return semantic;
|
|
5876
|
-
}
|
|
5877
|
-
function dependencySnapshotToState(snapshot) {
|
|
5878
|
-
const integrations = {};
|
|
5879
|
-
for (const [alias, entry] of Object.entries(snapshot.integrations)) {
|
|
5880
|
-
integrations[alias] = stripSnapshotMetadata(entry);
|
|
5881
|
-
}
|
|
5882
|
-
const plugins = {};
|
|
5883
|
-
for (const [alias, entry] of Object.entries(snapshot.plugins)) {
|
|
5884
|
-
plugins[alias] = stripSnapshotMetadata(entry);
|
|
5885
|
-
}
|
|
5886
|
-
return dependencyStateSchema.parse({
|
|
5887
|
-
version: 1,
|
|
5888
|
-
env: snapshot.env,
|
|
5889
|
-
integrations,
|
|
5890
|
-
plugins
|
|
5891
|
-
});
|
|
5892
|
-
}
|
|
5893
|
-
|
|
5894
|
-
// src/dependencies/index.ts
|
|
5895
|
-
init_types();
|
|
5896
|
-
|
|
5897
|
-
// src/dependencies/status-resolver.ts
|
|
5898
|
-
import { existsSync } from "fs";
|
|
5899
|
-
import * as path11 from "path";
|
|
5900
|
-
|
|
5901
|
-
// src/utils/ids.ts
|
|
5902
|
-
function getIntegrationAlias(integrationName) {
|
|
5903
|
-
return integrationName.replace(/\//g, "__").replace(/-/g, "_").toLowerCase();
|
|
5904
|
-
}
|
|
5905
|
-
function getPluginAlias(pluginName) {
|
|
5906
|
-
return pluginName.replace(/-/g, "_").toLowerCase();
|
|
5907
|
-
}
|
|
5908
|
-
function bpModuleDirName(kind, alias) {
|
|
5909
|
-
return kind === "integration" ? `integration_${getIntegrationAlias(alias)}` : `plugin_${alias}`;
|
|
5910
|
-
}
|
|
5911
|
-
|
|
5912
|
-
// src/dependencies/status-resolver.ts
|
|
5913
|
-
async function resolveDependencyStatuses(input) {
|
|
5914
|
-
const out = [];
|
|
5915
|
-
const integrationVerdicts = new Map;
|
|
5916
|
-
for (const [alias, entry] of Object.entries(input.snapshot.integrations)) {
|
|
5917
|
-
const installed = input.bpModulesDir ? existsSync(path11.join(input.bpModulesDir, bpModuleDirName("integration", alias))) : true;
|
|
5918
|
-
const spec = await tryGetSpec(input.integrationRegistry, entry.name, entry.version);
|
|
5919
|
-
const verdict = spec ? computeIntegrationStatus({
|
|
5920
|
-
installed,
|
|
5921
|
-
spec,
|
|
5922
|
-
enabled: entry.enabled,
|
|
5923
|
-
config: entry.config,
|
|
5924
|
-
...entry.configurationType ? { configurationType: entry.configurationType } : {},
|
|
5925
|
-
...entry.missingFields !== undefined ? { persistedMissingFields: entry.missingFields } : {},
|
|
5926
|
-
...entry.authorizationPending !== undefined ? { authorizationPending: entry.authorizationPending } : {}
|
|
5927
|
-
}) : computeSnapshotOnlyStatus({
|
|
5928
|
-
installed,
|
|
5929
|
-
enabled: entry.enabled,
|
|
5930
|
-
...entry.missingFields !== undefined ? { missingFields: entry.missingFields } : {},
|
|
5931
|
-
...entry.authorizationPending !== undefined ? { authorizationPending: entry.authorizationPending } : {}
|
|
5932
|
-
});
|
|
5933
|
-
integrationVerdicts.set(alias, verdict);
|
|
5934
|
-
out.push({
|
|
5935
|
-
type: "integration",
|
|
5936
|
-
alias,
|
|
5937
|
-
name: entry.name,
|
|
5938
|
-
version: entry.version,
|
|
5939
|
-
enabled: entry.enabled,
|
|
5940
|
-
...verdict
|
|
5941
|
-
});
|
|
5942
|
-
}
|
|
5943
|
-
for (const [alias, entry] of Object.entries(input.snapshot.plugins)) {
|
|
5944
|
-
const installed = input.bpModulesDir ? existsSync(path11.join(input.bpModulesDir, bpModuleDirName("plugin", alias))) : true;
|
|
5945
|
-
const spec = await tryGetSpec(input.pluginRegistry, entry.name, entry.version);
|
|
5946
|
-
const dependencyStatuses = mapPluginDependencyStatuses(entry.dependencies, (intAlias) => integrationVerdicts.get(intAlias));
|
|
5947
|
-
let verdict;
|
|
5948
|
-
if (spec) {
|
|
5949
|
-
verdict = computePluginStatus({
|
|
5950
|
-
installed,
|
|
5951
|
-
spec,
|
|
5952
|
-
enabled: entry.enabled,
|
|
5953
|
-
config: entry.config,
|
|
5954
|
-
dependencyStatuses,
|
|
5955
|
-
...entry.missingFields !== undefined ? { persistedMissingFields: entry.missingFields } : {}
|
|
5956
|
-
});
|
|
5957
|
-
} else if (!installed) {
|
|
5958
|
-
verdict = { state: "not_installed" };
|
|
5959
|
-
} else {
|
|
5960
|
-
verdict = transitiveDependencyVerdict(dependencyStatuses) ?? computeSnapshotOnlyStatus({
|
|
5961
|
-
installed: true,
|
|
5962
|
-
enabled: entry.enabled,
|
|
5963
|
-
...entry.missingFields !== undefined ? { missingFields: entry.missingFields } : {}
|
|
5964
|
-
});
|
|
5965
|
-
}
|
|
5966
|
-
out.push({ type: "plugin", alias, name: entry.name, version: entry.version, enabled: entry.enabled, ...verdict });
|
|
5967
|
-
}
|
|
5968
|
-
return out;
|
|
5969
|
-
}
|
|
5970
|
-
async function tryGetSpec(source, name, version) {
|
|
5971
|
-
if (!source)
|
|
5972
|
-
return null;
|
|
5973
|
-
try {
|
|
5974
|
-
return await source.getSpec(name, version);
|
|
5975
|
-
} catch {
|
|
5579
|
+
function extractMissingRequiredFields(err) {
|
|
5580
|
+
const message = err instanceof Error ? err.message : typeof err === "string" ? err : "";
|
|
5581
|
+
if (!message.includes("required property"))
|
|
5976
5582
|
return null;
|
|
5977
|
-
|
|
5583
|
+
const fields = new Set;
|
|
5584
|
+
const re = /required property ['"]([^'"]+)['"]/g;
|
|
5585
|
+
let match;
|
|
5586
|
+
while ((match = re.exec(message)) !== null) {
|
|
5587
|
+
if (match[1])
|
|
5588
|
+
fields.add(match[1]);
|
|
5589
|
+
}
|
|
5590
|
+
return fields.size > 0 ? [...fields] : null;
|
|
5978
5591
|
}
|
|
5979
5592
|
|
|
5980
5593
|
// src/dependencies/index.ts
|
|
5594
|
+
init_lock_file();
|
|
5981
5595
|
init_errors2();
|
|
5982
5596
|
|
|
5983
5597
|
// src/dependencies/registry/interface-registry.ts
|
|
@@ -5995,69 +5609,12 @@ class InterfaceRegistry {
|
|
|
5995
5609
|
return all.find((i) => i.alias === alias);
|
|
5996
5610
|
}
|
|
5997
5611
|
}
|
|
5998
|
-
|
|
5999
|
-
// src/dependencies/index.ts
|
|
6000
|
-
init_snapshot_store();
|
|
6001
|
-
|
|
6002
5612
|
// src/dependencies/migration.ts
|
|
6003
|
-
|
|
5613
|
+
init_lock_file();
|
|
5614
|
+
import * as fs12 from "fs/promises";
|
|
6004
5615
|
import * as path15 from "path";
|
|
6005
5616
|
import { Project as Project3, SyntaxKind as SyntaxKind3 } from "ts-morph";
|
|
6006
5617
|
|
|
6007
|
-
// src/dependencies/legacy-lock-file.ts
|
|
6008
|
-
init_types();
|
|
6009
|
-
init_errors2();
|
|
6010
|
-
import * as fs10 from "fs/promises";
|
|
6011
|
-
import * as path12 from "path";
|
|
6012
|
-
|
|
6013
|
-
class LegacyDependencyLockFile {
|
|
6014
|
-
filePath;
|
|
6015
|
-
env;
|
|
6016
|
-
constructor(opts) {
|
|
6017
|
-
this.env = opts.env;
|
|
6018
|
-
this.filePath = path12.join(opts.projectPath, `dependencies.${opts.env}.lock.json`);
|
|
6019
|
-
}
|
|
6020
|
-
async exists() {
|
|
6021
|
-
try {
|
|
6022
|
-
await fs10.access(this.filePath);
|
|
6023
|
-
return true;
|
|
6024
|
-
} catch {
|
|
6025
|
-
return false;
|
|
6026
|
-
}
|
|
6027
|
-
}
|
|
6028
|
-
async read(options) {
|
|
6029
|
-
let raw;
|
|
6030
|
-
try {
|
|
6031
|
-
raw = await fs10.readFile(this.filePath, "utf8");
|
|
6032
|
-
} catch (err) {
|
|
6033
|
-
if (err.code === "ENOENT") {
|
|
6034
|
-
return dependencyStateSchema.parse({ version: 1, env: this.env });
|
|
6035
|
-
}
|
|
6036
|
-
throw err;
|
|
6037
|
-
}
|
|
6038
|
-
try {
|
|
6039
|
-
return dependencyStateSchema.parse(JSON.parse(raw));
|
|
6040
|
-
} catch (err) {
|
|
6041
|
-
if (options?.tolerant) {
|
|
6042
|
-
return dependencyStateSchema.parse({ version: 1, env: this.env });
|
|
6043
|
-
}
|
|
6044
|
-
throw new DependencyError({
|
|
6045
|
-
code: "INVALID_CONFIG",
|
|
6046
|
-
message: `Legacy dependency lock at ${this.filePath} failed schema validation`,
|
|
6047
|
-
details: { issues: err.issues ?? String(err) }
|
|
6048
|
-
});
|
|
6049
|
-
}
|
|
6050
|
-
}
|
|
6051
|
-
async delete() {
|
|
6052
|
-
try {
|
|
6053
|
-
await fs10.unlink(this.filePath);
|
|
6054
|
-
} catch (err) {
|
|
6055
|
-
if (err.code !== "ENOENT")
|
|
6056
|
-
throw err;
|
|
6057
|
-
}
|
|
6058
|
-
}
|
|
6059
|
-
}
|
|
6060
|
-
|
|
6061
5618
|
// src/agent-project/config-writer.ts
|
|
6062
5619
|
init_utils();
|
|
6063
5620
|
init_src();
|
|
@@ -6372,259 +5929,181 @@ class ConfigWriter {
|
|
|
6372
5929
|
}
|
|
6373
5930
|
|
|
6374
5931
|
// src/dependencies/migration.ts
|
|
5932
|
+
init_errors2();
|
|
6375
5933
|
init_agent_project();
|
|
6376
|
-
|
|
6377
|
-
|
|
6378
|
-
|
|
6379
|
-
|
|
6380
|
-
|
|
6381
|
-
|
|
6382
|
-
|
|
6383
|
-
|
|
6384
|
-
|
|
6385
|
-
|
|
6386
|
-
|
|
6387
|
-
|
|
6388
|
-
|
|
6389
|
-
|
|
6390
|
-
|
|
6391
|
-
this.integrationResolver = opts.integrationResolver ?? new IntegrationResolver({ registry: this.integrationRegistry, client: this.client });
|
|
6392
|
-
this.pluginResolver = opts.pluginResolver ?? new PluginResolver({
|
|
6393
|
-
registry: this.pluginRegistry,
|
|
6394
|
-
integrationRegistry: this.integrationRegistry,
|
|
6395
|
-
client: this.client
|
|
5934
|
+
async function migrateFromConfig(opts) {
|
|
5935
|
+
const result = {
|
|
5936
|
+
migrated: [],
|
|
5937
|
+
warnings: [],
|
|
5938
|
+
skipped: []
|
|
5939
|
+
};
|
|
5940
|
+
const project = await AgentProject.load(opts.projectPath);
|
|
5941
|
+
const info = project.agentInfo;
|
|
5942
|
+
const declaredAliasesForConflictCheck = await readAliasesFromConfig(opts.projectPath);
|
|
5943
|
+
const agentConfigHasDependencies = Object.keys(declaredAliasesForConflictCheck.integrations).length > 0 || Object.keys(declaredAliasesForConflictCheck.plugins).length > 0;
|
|
5944
|
+
const envs = ["dev", "prod"];
|
|
5945
|
+
if (!info) {
|
|
5946
|
+
result.warnings.push({
|
|
5947
|
+
code: "CLOUD_FETCH_PARTIAL",
|
|
5948
|
+
message: "No agent.json found; cannot fetch cloud state for migration."
|
|
6396
5949
|
});
|
|
6397
|
-
|
|
6398
|
-
|
|
6399
|
-
const result = {
|
|
6400
|
-
migrated: [],
|
|
6401
|
-
warnings: [],
|
|
6402
|
-
skipped: [],
|
|
6403
|
-
legacySources: [],
|
|
6404
|
-
snapshotWrites: [],
|
|
6405
|
-
cloudWrites: []
|
|
6406
|
-
};
|
|
6407
|
-
if (await this.snapshotStore.hasMigrationMarker()) {
|
|
6408
|
-
for (const env of ["dev", "prod"]) {
|
|
6409
|
-
await this.deleteLegacyLock(env, result);
|
|
6410
|
-
result.skipped.push({ env, reason: "migration already completed" });
|
|
6411
|
-
}
|
|
6412
|
-
return result;
|
|
6413
|
-
}
|
|
6414
|
-
const project = await AgentProject.load(this.projectPath);
|
|
6415
|
-
const info = project.agentInfo;
|
|
6416
|
-
const agentConfigDependencies = await readDependenciesFromConfig(this.projectPath);
|
|
6417
|
-
const hasAgentConfigDependencies = hasDependencies(agentConfigDependencies);
|
|
6418
|
-
if (hasAgentConfigDependencies) {
|
|
6419
|
-
result.legacySources?.push("agentConfig");
|
|
5950
|
+
for (const env of envs) {
|
|
5951
|
+
result.skipped.push({ env, reason: "no agent.json" });
|
|
6420
5952
|
}
|
|
6421
|
-
|
|
6422
|
-
|
|
6423
|
-
|
|
6424
|
-
|
|
6425
|
-
|
|
6426
|
-
|
|
6427
|
-
|
|
5953
|
+
} else {
|
|
5954
|
+
for (const env of envs) {
|
|
5955
|
+
const lockFile = new LockFile({ projectPath: opts.projectPath, env });
|
|
5956
|
+
if (await lockFile.exists()) {
|
|
5957
|
+
if (agentConfigHasDependencies) {
|
|
5958
|
+
throw new DependencyError({
|
|
5959
|
+
code: "MIGRATION_CONFLICT",
|
|
5960
|
+
message: `Cannot migrate: a lock file (dependencies.${env}.lock.json) already exists alongside the 'dependencies' field in agent.config.ts. Remove one of them before running migration.`
|
|
5961
|
+
});
|
|
5962
|
+
}
|
|
5963
|
+
result.skipped.push({ env, reason: "lock file already exists" });
|
|
5964
|
+
continue;
|
|
6428
5965
|
}
|
|
6429
|
-
return result;
|
|
6430
|
-
}
|
|
6431
|
-
const markerSources = new Set;
|
|
6432
|
-
for (const env of ["dev", "prod"]) {
|
|
6433
5966
|
const botId = env === "dev" ? info.devId ?? info.botId : info.botId;
|
|
6434
|
-
if (!botId) {
|
|
5967
|
+
if (env === "prod" && !botId) {
|
|
6435
5968
|
result.warnings.push({
|
|
6436
5969
|
code: "NO_PROD_BOT",
|
|
6437
|
-
message: "No prod bot configured in agent.json.
|
|
5970
|
+
message: "No prod bot configured in agent.json. Only dependencies.dev.lock.json was generated. Use `adk deploy` to create a prod bot."
|
|
6438
5971
|
});
|
|
6439
5972
|
result.skipped.push({ env, reason: "no prod bot configured" });
|
|
6440
5973
|
continue;
|
|
6441
5974
|
}
|
|
6442
|
-
|
|
6443
|
-
|
|
6444
|
-
|
|
6445
|
-
|
|
6446
|
-
|
|
6447
|
-
|
|
5975
|
+
let bot;
|
|
5976
|
+
try {
|
|
5977
|
+
const r = await opts.client.getBot({ id: botId });
|
|
5978
|
+
bot = r.bot;
|
|
5979
|
+
} catch (err) {
|
|
5980
|
+
result.warnings.push({
|
|
5981
|
+
code: "CLOUD_FETCH_PARTIAL",
|
|
5982
|
+
message: `Could not fetch cloud state for ${env}: ${err.message}`
|
|
5983
|
+
});
|
|
5984
|
+
result.skipped.push({ env, reason: "cloud fetch failed" });
|
|
6448
5985
|
continue;
|
|
6449
|
-
if (!cloudHasDependencies(bot) && legacy) {
|
|
6450
|
-
await this.importLegacyToCloud({ botId, legacy: legacy.data });
|
|
6451
|
-
result.cloudWrites?.push(env);
|
|
6452
|
-
markerSources.add(legacy.source);
|
|
6453
|
-
bot = await this.fetchBot(botId, env, result);
|
|
6454
|
-
if (!bot)
|
|
6455
|
-
continue;
|
|
6456
|
-
} else {
|
|
6457
|
-
markerSources.add("cloud");
|
|
6458
5986
|
}
|
|
6459
|
-
|
|
6460
|
-
|
|
6461
|
-
botId,
|
|
5987
|
+
const lockData = {
|
|
5988
|
+
version: 1,
|
|
6462
5989
|
env,
|
|
6463
|
-
|
|
6464
|
-
|
|
6465
|
-
}
|
|
6466
|
-
|
|
5990
|
+
integrations: {},
|
|
5991
|
+
plugins: {}
|
|
5992
|
+
};
|
|
5993
|
+
const declaredAliases = declaredAliasesForConflictCheck;
|
|
5994
|
+
const usedIntegrationAliases = new Set(Object.keys(declaredAliases.integrations));
|
|
5995
|
+
for (const [cloudAlias, cloud] of Object.entries(bot.integrations ?? {})) {
|
|
5996
|
+
const declaredAlias = Object.entries(declaredAliases.integrations).find(([, decl]) => decl.name === cloud.name)?.[0];
|
|
5997
|
+
const alias = declaredAlias ?? generateFriendlyAlias(cloud.name, cloudAlias, usedIntegrationAliases);
|
|
5998
|
+
usedIntegrationAliases.add(alias);
|
|
5999
|
+
lockData.integrations[alias] = {
|
|
6000
|
+
name: cloud.name,
|
|
6001
|
+
version: cloud.version,
|
|
6002
|
+
enabled: cloud.enabled ?? false,
|
|
6003
|
+
config: cloud.configuration ?? {}
|
|
6004
|
+
};
|
|
6005
|
+
}
|
|
6006
|
+
const usedPluginAliases = new Set(Object.keys(declaredAliases.plugins));
|
|
6007
|
+
for (const [cloudAlias, cloud] of Object.entries(bot.plugins ?? {})) {
|
|
6008
|
+
const declaredAlias = Object.entries(declaredAliases.plugins).find(([, decl]) => decl.name === cloud.name)?.[0];
|
|
6009
|
+
const alias = declaredAlias ?? generateFriendlyAlias(cloud.name, cloudAlias, usedPluginAliases);
|
|
6010
|
+
usedPluginAliases.add(alias);
|
|
6011
|
+
lockData.plugins[alias] = {
|
|
6012
|
+
name: cloud.name,
|
|
6013
|
+
version: cloud.version,
|
|
6014
|
+
enabled: cloud.enabled ?? true,
|
|
6015
|
+
config: cloud.configuration ?? {},
|
|
6016
|
+
dependencies: Object.fromEntries(Object.entries(cloud.interfaces ?? {}).map(([k, v]) => [
|
|
6017
|
+
k,
|
|
6018
|
+
{ integrationAlias: v.integrationAlias }
|
|
6019
|
+
]))
|
|
6020
|
+
};
|
|
6021
|
+
}
|
|
6022
|
+
await lockFile.write(lockData);
|
|
6467
6023
|
result.migrated.push(env);
|
|
6468
|
-
await this.deleteLegacyLock(env, result);
|
|
6469
|
-
}
|
|
6470
|
-
if (hasAgentConfigDependencies && result.migrated.length > 0) {
|
|
6471
|
-
const writer = new ConfigWriter(this.projectPath);
|
|
6472
|
-
await writer.removeDependenciesField();
|
|
6473
|
-
}
|
|
6474
|
-
if (result.migrated.length > 0) {
|
|
6475
|
-
await this.snapshotStore.writeMigrationMarker({
|
|
6476
|
-
version: 1,
|
|
6477
|
-
migratedAt: new Date().toISOString(),
|
|
6478
|
-
sources: [...markerSources]
|
|
6479
|
-
});
|
|
6480
|
-
result.warnings.push({
|
|
6481
|
-
code: "MIGRATED_DEPENDENCIES",
|
|
6482
|
-
message: `Migrated dependencies to .adk snapshots for ${result.migrated.join(", ")}. Cloud is now the source of truth.`
|
|
6483
|
-
});
|
|
6484
|
-
}
|
|
6485
|
-
return result;
|
|
6486
|
-
}
|
|
6487
|
-
async deleteLegacyLock(env, result) {
|
|
6488
|
-
try {
|
|
6489
|
-
await new LegacyDependencyLockFile({ projectPath: this.projectPath, env }).delete();
|
|
6490
|
-
} catch (err) {
|
|
6491
|
-
result.warnings.push({
|
|
6492
|
-
code: "LEGACY_LOCK_DELETE_FAILED",
|
|
6493
|
-
message: `Migrated ${env} dependencies, but could not delete dependencies.${env}.lock.json: ${err.message}`
|
|
6494
|
-
});
|
|
6495
|
-
}
|
|
6496
|
-
}
|
|
6497
|
-
async readLegacyState(env, agentConfigDependencies) {
|
|
6498
|
-
const legacyLock = new LegacyDependencyLockFile({ projectPath: this.projectPath, env });
|
|
6499
|
-
if (await legacyLock.exists()) {
|
|
6500
|
-
return { source: "lock", data: await legacyLock.read() };
|
|
6501
|
-
}
|
|
6502
|
-
if (hasDependencies(agentConfigDependencies)) {
|
|
6503
|
-
return { source: "agentConfig", data: { ...agentConfigDependencies, env } };
|
|
6504
|
-
}
|
|
6505
|
-
return null;
|
|
6506
|
-
}
|
|
6507
|
-
async fetchBot(botId, env, result) {
|
|
6508
|
-
try {
|
|
6509
|
-
const { bot } = await this.client.getBot({ id: botId });
|
|
6510
|
-
return bot;
|
|
6511
|
-
} catch (err) {
|
|
6512
|
-
result.warnings.push({
|
|
6513
|
-
code: "CLOUD_FETCH_PARTIAL",
|
|
6514
|
-
message: `Could not fetch cloud state for ${env}: ${err.message}`
|
|
6515
|
-
});
|
|
6516
|
-
result.skipped.push({ env, reason: "cloud fetch failed" });
|
|
6517
|
-
return null;
|
|
6518
6024
|
}
|
|
6519
6025
|
}
|
|
6520
|
-
|
|
6521
|
-
|
|
6522
|
-
|
|
6523
|
-
|
|
6524
|
-
|
|
6525
|
-
|
|
6526
|
-
}
|
|
6026
|
+
if (result.migrated.length > 0) {
|
|
6027
|
+
const writer = new ConfigWriter(opts.projectPath);
|
|
6028
|
+
await writer.removeDependenciesField();
|
|
6029
|
+
result.warnings.push({
|
|
6030
|
+
code: "MIGRATED_DEPENDENCIES",
|
|
6031
|
+
message: `Migrated dependencies to ${result.migrated.map((e) => `dependencies.${e}.lock.json`).join(", ")}. Review the diff and commit.`
|
|
6032
|
+
});
|
|
6527
6033
|
}
|
|
6034
|
+
return result;
|
|
6528
6035
|
}
|
|
6529
|
-
async function
|
|
6530
|
-
return new DependencyMigrationManager(opts).run();
|
|
6531
|
-
}
|
|
6532
|
-
async function readDependenciesFromConfig(projectPath) {
|
|
6036
|
+
async function readAliasesFromConfig(projectPath) {
|
|
6533
6037
|
const configPath = path15.join(projectPath, "agent.config.ts");
|
|
6534
|
-
const empty = { version: 1, env: "dev", integrations: {}, plugins: {} };
|
|
6535
6038
|
try {
|
|
6536
|
-
await
|
|
6039
|
+
await fs12.access(configPath);
|
|
6537
6040
|
} catch {
|
|
6538
|
-
return
|
|
6041
|
+
return { integrations: {}, plugins: {} };
|
|
6539
6042
|
}
|
|
6043
|
+
const integrations = {};
|
|
6044
|
+
const plugins = {};
|
|
6540
6045
|
try {
|
|
6541
6046
|
const project = new Project3({ useInMemoryFileSystem: false });
|
|
6542
6047
|
const sourceFile = project.addSourceFileAtPath(configPath);
|
|
6543
6048
|
const callExpr = sourceFile.getDescendantsOfKind(SyntaxKind3.CallExpression).find((c) => c.getExpression().getText() === "defineConfig");
|
|
6544
6049
|
const obj = callExpr?.getArguments()[0]?.asKind(SyntaxKind3.ObjectLiteralExpression);
|
|
6545
6050
|
if (!obj)
|
|
6546
|
-
return
|
|
6051
|
+
return { integrations, plugins };
|
|
6547
6052
|
const depsProp = obj.getProperty("dependencies");
|
|
6548
|
-
if (!depsProp
|
|
6549
|
-
return
|
|
6053
|
+
if (!depsProp || !depsProp.isKind(SyntaxKind3.PropertyAssignment))
|
|
6054
|
+
return { integrations, plugins };
|
|
6550
6055
|
const depsObj = depsProp.getInitializer()?.asKind(SyntaxKind3.ObjectLiteralExpression);
|
|
6551
6056
|
if (!depsObj)
|
|
6552
|
-
return
|
|
6553
|
-
|
|
6554
|
-
|
|
6555
|
-
|
|
6556
|
-
|
|
6557
|
-
|
|
6558
|
-
|
|
6559
|
-
|
|
6560
|
-
|
|
6561
|
-
|
|
6562
|
-
|
|
6563
|
-
|
|
6564
|
-
|
|
6565
|
-
|
|
6566
|
-
|
|
6567
|
-
|
|
6568
|
-
|
|
6569
|
-
|
|
6570
|
-
|
|
6571
|
-
|
|
6572
|
-
|
|
6573
|
-
|
|
6574
|
-
|
|
6575
|
-
|
|
6576
|
-
|
|
6577
|
-
|
|
6578
|
-
|
|
6579
|
-
|
|
6580
|
-
|
|
6581
|
-
|
|
6582
|
-
|
|
6583
|
-
|
|
6584
|
-
}
|
|
6585
|
-
}
|
|
6586
|
-
function readVersionLiteral(node) {
|
|
6587
|
-
if (node?.isKind(SyntaxKind3.StringLiteral)) {
|
|
6588
|
-
return node.getLiteralText();
|
|
6589
|
-
}
|
|
6590
|
-
if (node?.isKind(SyntaxKind3.ObjectLiteralExpression)) {
|
|
6591
|
-
const versionProp = node.getProperty("version");
|
|
6592
|
-
if (versionProp?.isKind(SyntaxKind3.PropertyAssignment)) {
|
|
6593
|
-
const value = versionProp.getInitializer();
|
|
6594
|
-
if (value?.isKind(SyntaxKind3.StringLiteral))
|
|
6595
|
-
return value.getLiteralText();
|
|
6057
|
+
return { integrations, plugins };
|
|
6058
|
+
for (const field of ["integrations", "plugins"]) {
|
|
6059
|
+
const target = field === "integrations" ? integrations : plugins;
|
|
6060
|
+
const innerProp = depsObj.getProperty(field);
|
|
6061
|
+
if (!innerProp || !innerProp.isKind(SyntaxKind3.PropertyAssignment))
|
|
6062
|
+
continue;
|
|
6063
|
+
const inner = innerProp.getInitializer()?.asKind(SyntaxKind3.ObjectLiteralExpression);
|
|
6064
|
+
if (!inner)
|
|
6065
|
+
continue;
|
|
6066
|
+
for (const aliasProp of inner.getProperties()) {
|
|
6067
|
+
if (!aliasProp.isKind(SyntaxKind3.PropertyAssignment))
|
|
6068
|
+
continue;
|
|
6069
|
+
const alias = aliasProp.getName().replace(/['"]/g, "");
|
|
6070
|
+
const initializer = aliasProp.getInitializer();
|
|
6071
|
+
let nameVersion = "";
|
|
6072
|
+
if (initializer?.isKind(SyntaxKind3.StringLiteral)) {
|
|
6073
|
+
nameVersion = initializer.getLiteralText();
|
|
6074
|
+
} else if (initializer?.isKind(SyntaxKind3.ObjectLiteralExpression)) {
|
|
6075
|
+
const versionProp = initializer.getProperty("version");
|
|
6076
|
+
if (versionProp?.isKind(SyntaxKind3.PropertyAssignment)) {
|
|
6077
|
+
const v = versionProp.getInitializer();
|
|
6078
|
+
if (v?.isKind(SyntaxKind3.StringLiteral))
|
|
6079
|
+
nameVersion = v.getLiteralText();
|
|
6080
|
+
}
|
|
6081
|
+
}
|
|
6082
|
+
const at = nameVersion.indexOf("@");
|
|
6083
|
+
if (at < 0)
|
|
6084
|
+
continue;
|
|
6085
|
+
const name = nameVersion.slice(0, at);
|
|
6086
|
+
const version = nameVersion.slice(at + 1);
|
|
6087
|
+
target[alias] = { name, version };
|
|
6088
|
+
}
|
|
6596
6089
|
}
|
|
6597
|
-
}
|
|
6598
|
-
return
|
|
6599
|
-
}
|
|
6600
|
-
function hasDependencies(data) {
|
|
6601
|
-
return Object.keys(data.integrations).length > 0 || Object.keys(data.plugins).length > 0;
|
|
6602
|
-
}
|
|
6603
|
-
function cloudHasDependencies(bot) {
|
|
6604
|
-
return Object.keys(bot.integrations ?? {}).length > 0 || Object.keys(bot.plugins ?? {}).length > 0;
|
|
6090
|
+
} catch {}
|
|
6091
|
+
return { integrations, plugins };
|
|
6605
6092
|
}
|
|
6606
6093
|
export {
|
|
6607
6094
|
sortKeysDeep,
|
|
6608
|
-
resolveDependencyStatuses,
|
|
6609
6095
|
migrateFromConfig,
|
|
6610
6096
|
jsonEqual,
|
|
6611
|
-
isCallable,
|
|
6612
|
-
emptyDependencySnapshot,
|
|
6613
|
-
dependencyStateSchema,
|
|
6614
|
-
dependencySnapshotFromBot,
|
|
6615
|
-
computePluginStatus,
|
|
6616
|
-
computeIntegrationStatus,
|
|
6617
6097
|
PluginResolver,
|
|
6618
6098
|
PluginRegistry,
|
|
6099
|
+
LockFile,
|
|
6619
6100
|
InterfaceRegistry,
|
|
6620
6101
|
IntegrationResolver,
|
|
6621
6102
|
IntegrationRegistry,
|
|
6622
|
-
DependencySnapshotStore,
|
|
6623
|
-
DependencyMigrationManager,
|
|
6624
6103
|
DependencyManager,
|
|
6625
6104
|
DependencyError,
|
|
6626
6105
|
DEPENDENCY_WARNING_CODES,
|
|
6627
6106
|
DEPENDENCY_ERROR_CODES
|
|
6628
6107
|
};
|
|
6629
6108
|
|
|
6630
|
-
//# debugId=
|
|
6109
|
+
//# debugId=497600913EA6E06564756E2164756E21
|