@botpress/adk 1.19.0-beta.9 → 2.0.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agent-init/agent-project-generator.d.ts +5 -1
- package/dist/agent-init/agent-project-generator.d.ts.map +1 -1
- package/dist/agent-project/agent-project.d.ts +3 -3
- package/dist/agent-project/agent-project.d.ts.map +1 -1
- package/dist/agent-project/agent-resolver.d.ts.map +1 -1
- package/dist/agent-project/config-writer.d.ts +1 -1
- package/dist/agent-project/dependency-state-to-dependencies.d.ts +11 -0
- package/dist/agent-project/dependency-state-to-dependencies.d.ts.map +1 -0
- package/dist/agent-project/types.d.ts +9 -4
- package/dist/agent-project/types.d.ts.map +1 -1
- package/dist/agent0/capabilities/commands/adk-build.md +6 -5
- package/dist/agent0/capabilities/commands/adk-debug.md +1 -1
- package/dist/agent0/capabilities/commands/adk-dev-console.md +1 -1
- package/dist/agent0/capabilities/commands/adk-document.md +10 -2
- package/dist/agent0/capabilities/commands/adk-eval.md +1 -1
- package/dist/agent0/capabilities/commands/adk-explain.md +2 -2
- package/dist/agent0/capabilities/commands/adk-init.md +2 -2
- package/dist/agent0/capabilities/commands/adk-ship.md +1 -1
- package/dist/agent0/capabilities/commands/adk-test.md +3 -3
- package/dist/agent0/capabilities/commands/adk-validate.md +3 -3
- package/dist/agent0/capabilities/skills/adk/SKILL.md +21 -21
- package/dist/agent0/capabilities/skills/adk/references/actions.md +245 -239
- package/dist/agent0/capabilities/skills/adk/references/advanced-patterns.md +185 -218
- package/dist/agent0/capabilities/skills/adk/references/agent-config.md +74 -71
- package/dist/agent0/capabilities/skills/adk/references/assets.md +45 -48
- package/dist/agent0/capabilities/skills/adk/references/autonomous-execution.md +40 -46
- package/dist/agent0/capabilities/skills/adk/references/cli.md +17 -7
- package/dist/agent0/capabilities/skills/adk/references/context-api.md +98 -94
- package/dist/agent0/capabilities/skills/adk/references/conversation-lifecycle.md +65 -62
- package/dist/agent0/capabilities/skills/adk/references/conversations.md +395 -385
- package/dist/agent0/capabilities/skills/adk/references/custom-components.md +1 -1
- package/dist/agent0/capabilities/skills/adk/references/desk.md +236 -234
- package/dist/agent0/capabilities/skills/adk/references/explain-config.md +54 -37
- package/dist/agent0/capabilities/skills/adk/references/files.md +301 -306
- package/dist/agent0/capabilities/skills/adk/references/integration-actions.md +211 -214
- package/dist/agent0/capabilities/skills/adk/references/integrations.md +33 -31
- package/dist/agent0/capabilities/skills/adk/references/interfaces.md +13 -12
- package/dist/agent0/capabilities/skills/adk/references/knowledge-bases.md +98 -111
- package/dist/agent0/capabilities/skills/adk/references/mcp-server.md +6 -0
- package/dist/agent0/capabilities/skills/adk/references/messages.md +280 -256
- package/dist/agent0/capabilities/skills/adk/references/model-configuration.md +52 -49
- package/dist/agent0/capabilities/skills/adk/references/patterns-mistakes.md +102 -101
- package/dist/agent0/capabilities/skills/adk/references/plugins.md +15 -15
- package/dist/agent0/capabilities/skills/adk/references/tables.md +204 -210
- package/dist/agent0/capabilities/skills/adk/references/tags.md +141 -143
- package/dist/agent0/capabilities/skills/adk/references/tools.md +191 -199
- package/dist/agent0/capabilities/skills/adk/references/triggers.md +331 -336
- package/dist/agent0/capabilities/skills/adk/references/workflow-steps.md +132 -96
- package/dist/agent0/capabilities/skills/adk/references/workflows.md +479 -464
- package/dist/agent0/capabilities/skills/adk/references/zai-agent-reference.md +127 -129
- package/dist/agent0/capabilities/skills/adk/references/zai-complete-guide.md +255 -276
- package/dist/agent0/capabilities/skills/adk-debugger/SKILL.md +21 -17
- package/dist/agent0/capabilities/skills/adk-debugger/references/common-failures.md +25 -25
- package/dist/agent0/capabilities/skills/adk-debugger/references/conversation-analysis.md +49 -41
- package/dist/agent0/capabilities/skills/adk-debugger/references/debug-workflow.md +20 -14
- package/dist/agent0/capabilities/skills/adk-debugger/references/llm-debugging.md +13 -13
- package/dist/agent0/capabilities/skills/adk-debugger/references/trace-summarization.md +18 -18
- package/dist/agent0/capabilities/skills/adk-debugger/references/traces-and-logs.md +67 -67
- package/dist/agent0/capabilities/skills/adk-dev-console/SKILL.md +36 -36
- package/dist/agent0/capabilities/skills/adk-dev-console/references/agent-steps.md +14 -6
- package/dist/agent0/capabilities/skills/adk-dev-console/references/multi-agent-dashboard.md +13 -13
- package/dist/agent0/capabilities/skills/adk-dev-console/references/pages.md +18 -0
- package/dist/agent0/capabilities/skills/adk-docs/SKILL.md +13 -13
- package/dist/agent0/capabilities/skills/adk-docs/references/doc-standards.md +15 -0
- package/dist/agent0/capabilities/skills/adk-evals/SKILL.md +29 -23
- package/dist/agent0/capabilities/skills/adk-evals/references/eval-format.md +31 -23
- package/dist/agent0/capabilities/skills/adk-evals/references/test-patterns.md +25 -36
- package/dist/agent0/capabilities/skills/adk-evals/references/testing-workflow.md +6 -4
- package/dist/agent0/index.js +41 -19
- package/dist/agent0/index.js.map +7 -7
- package/dist/agent0/runtime/client.d.ts +2 -0
- package/dist/agent0/runtime/client.d.ts.map +1 -1
- package/dist/agent0/runtime/engine.d.ts +2 -1
- package/dist/agent0/runtime/engine.d.ts.map +1 -1
- package/dist/agent0/runtime/process.d.ts +1 -0
- package/dist/agent0/runtime/process.d.ts.map +1 -1
- package/dist/assets/manager.d.ts +3 -0
- package/dist/assets/manager.d.ts.map +1 -1
- package/dist/auth/credentials.d.ts +1 -1
- package/dist/bot-generator/generator.d.ts +22 -0
- package/dist/bot-generator/generator.d.ts.map +1 -1
- package/dist/bot-generator/plugin-sync.d.ts.map +1 -1
- package/dist/commands/base-command.d.ts +1 -0
- package/dist/commands/base-command.d.ts.map +1 -1
- package/dist/commands/bp-dev-command.d.ts +1 -1
- package/dist/commands/bp-dev-command.d.ts.map +1 -1
- package/dist/commands/bp-dev-stderr.d.ts +9 -0
- package/dist/commands/bp-dev-stderr.d.ts.map +1 -1
- package/dist/commands/index.d.ts +1 -0
- package/dist/commands/index.d.ts.map +1 -1
- package/dist/dependencies/catalog/catalog-service.d.ts +53 -0
- package/dist/dependencies/catalog/catalog-service.d.ts.map +1 -0
- package/dist/dependencies/catalog/client-factory.d.ts +33 -0
- package/dist/dependencies/catalog/client-factory.d.ts.map +1 -0
- package/dist/dependencies/catalog/integration-source.d.ts +34 -0
- package/dist/dependencies/catalog/integration-source.d.ts.map +1 -0
- package/dist/dependencies/catalog/interface-source.d.ts +23 -0
- package/dist/dependencies/catalog/interface-source.d.ts.map +1 -0
- package/dist/dependencies/catalog/plugin-source.d.ts +49 -0
- package/dist/dependencies/catalog/plugin-source.d.ts.map +1 -0
- package/dist/dependencies/catalog/resolution-cache.d.ts +76 -0
- package/dist/dependencies/catalog/resolution-cache.d.ts.map +1 -0
- package/dist/dependencies/dependency-manager.d.ts +31 -16
- 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 +5 -4
- package/dist/dependencies/index.d.ts.map +1 -1
- package/dist/dependencies/index.js +2089 -1670
- package/dist/dependencies/index.js.map +37 -30
- package/dist/dependencies/legacy-lock-file.d.ts +15 -0
- package/dist/dependencies/legacy-lock-file.d.ts.map +1 -0
- package/dist/dependencies/migration.d.ts +19 -0
- package/dist/dependencies/migration.d.ts.map +1 -1
- package/dist/dependencies/resolvers/integration-resolver.d.ts +4 -3
- 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/snapshot-store.d.ts +59 -0
- package/dist/dependencies/snapshot-store.d.ts.map +1 -0
- package/dist/dependencies/status-resolver.d.ts +36 -0
- package/dist/dependencies/status-resolver.d.ts.map +1 -0
- package/dist/dependencies/status.d.ts +214 -0
- package/dist/dependencies/status.d.ts.map +1 -0
- package/dist/dependencies/types.d.ts +380 -29
- package/dist/dependencies/types.d.ts.map +1 -1
- package/dist/file-watcher/watcher.d.ts +21 -5
- package/dist/file-watcher/watcher.d.ts.map +1 -1
- package/dist/generators/action-types.d.ts.map +1 -1
- package/dist/generators/client-wrapper.d.ts.map +1 -1
- package/dist/index.d.ts +4 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3134 -2226
- package/dist/index.js.map +55 -48
- package/dist/integrations/config-utils.d.ts +11 -7
- package/dist/integrations/config-utils.d.ts.map +1 -1
- package/dist/integrations/hub-cache.d.ts +0 -58
- package/dist/integrations/hub-cache.d.ts.map +1 -1
- package/dist/integrations/index.d.ts +1 -3
- package/dist/integrations/index.d.ts.map +1 -1
- package/dist/integrations/manager.d.ts +19 -53
- 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 +11 -17
- package/dist/interfaces/manager.d.ts.map +1 -1
- package/dist/knowledge/manager.d.ts +3 -0
- package/dist/knowledge/manager.d.ts.map +1 -1
- package/dist/plugins/index.d.ts +0 -1
- package/dist/plugins/index.d.ts.map +1 -1
- package/dist/plugins/manager.d.ts +16 -48
- package/dist/plugins/manager.d.ts.map +1 -1
- package/dist/preflight/checker.d.ts +6 -1
- package/dist/preflight/checker.d.ts.map +1 -1
- package/dist/preflight/dependency-gate.d.ts +37 -0
- package/dist/preflight/dependency-gate.d.ts.map +1 -0
- package/dist/preflight/index.d.ts +2 -1
- package/dist/preflight/index.d.ts.map +1 -1
- package/dist/preflight/types.d.ts +18 -0
- package/dist/preflight/types.d.ts.map +1 -1
- package/dist/runner/script-runner.d.ts.map +1 -1
- package/dist/tables/table-manager.d.ts +3 -0
- package/dist/tables/table-manager.d.ts.map +1 -1
- package/dist/templates/README.md +23 -13
- package/dist/templates/blank/agent.config.ts +3 -3
- package/dist/templates/blank/src/triggers/index.ts +1 -1
- package/dist/templates/botpress-desk/evals/index.eval.ts +1 -1
- package/dist/templates/botpress-desk/src/triggers/index.ts +1 -1
- package/dist/templates/crm-enrichment/README.md +3 -3
- package/dist/templates/crm-enrichment/agent.config.ts +2 -2
- package/dist/templates/crm-enrichment/src/conversations/index.ts +1 -1
- package/dist/templates/hello-world/agent.config.ts +3 -3
- package/dist/templates/hello-world/src/triggers/index.ts +1 -1
- package/dist/templates/knowledge-assistant/src/triggers/index.ts +1 -1
- package/dist/templates/template.config.json +3 -3
- package/dist/utils/ids.d.ts +10 -0
- package/dist/utils/ids.d.ts.map +1 -1
- package/dist/workspace/workspace-cache.d.ts +2 -1
- package/dist/workspace/workspace-cache.d.ts.map +1 -1
- package/package.json +3 -3
- package/dist/agent-project/lock-to-dependencies.d.ts +0 -11
- package/dist/agent-project/lock-to-dependencies.d.ts.map +0 -1
- package/dist/dependencies/lock-file.d.ts +0 -15
- package/dist/dependencies/lock-file.d.ts.map +0 -1
- package/dist/integrations/enhanced-cache.d.ts +0 -53
- package/dist/integrations/enhanced-cache.d.ts.map +0 -1
- package/dist/plugins/enhanced-cache.d.ts +0 -53
- package/dist/plugins/enhanced-cache.d.ts.map +0 -1
- package/dist/templates/blank/package.json +0 -17
- package/dist/templates/blank/tsconfig.json +0 -25
- package/dist/templates/botpress-desk/package.json +0 -17
- package/dist/templates/crm-enrichment/package.json +0 -18
- package/dist/templates/crm-enrichment/tsconfig.json +0 -25
- package/dist/templates/hello-world/package.json +0 -18
- package/dist/templates/hello-world/tsconfig.json +0 -25
- package/dist/templates/knowledge-assistant/package.json +0 -18
- package/dist/templates/knowledge-assistant/tsconfig.json +0 -25
- package/dist/templates/slack-triage/package.json +0 -18
- package/dist/templates/slack-triage/tsconfig.json +0 -25
|
@@ -46,32 +46,80 @@ 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
|
+
|
|
49
67
|
// src/dependencies/types.ts
|
|
50
68
|
import { z } from "@botpress/sdk";
|
|
51
|
-
var
|
|
69
|
+
var integrationDependencyEntrySchema, pluginDependencyMappingSchema, pluginDependencyEntrySchema, integrationSnapshotEntrySchema, pluginSnapshotEntrySchema, dependencyStateSchema, dependencySnapshotSchema, dependencyMigrationMarkerSchema;
|
|
52
70
|
var init_types = __esm(() => {
|
|
53
|
-
|
|
71
|
+
integrationDependencyEntrySchema = z.object({
|
|
54
72
|
name: z.string(),
|
|
55
73
|
version: z.string(),
|
|
56
74
|
enabled: z.boolean(),
|
|
57
|
-
config: z.record(z.any()).default({})
|
|
75
|
+
config: z.record(z.any()).default({}),
|
|
76
|
+
configurationType: z.string().optional(),
|
|
77
|
+
missingFields: z.array(z.string()).optional(),
|
|
78
|
+
authorizationPending: z.boolean().optional()
|
|
58
79
|
});
|
|
59
80
|
pluginDependencyMappingSchema = z.object({
|
|
60
81
|
integrationAlias: z.string()
|
|
61
82
|
});
|
|
62
|
-
|
|
83
|
+
pluginDependencyEntrySchema = z.object({
|
|
63
84
|
name: z.string(),
|
|
64
85
|
version: z.string(),
|
|
65
86
|
enabled: z.boolean().default(true),
|
|
66
87
|
config: z.record(z.any()).default({}),
|
|
67
|
-
dependencies: z.record(pluginDependencyMappingSchema).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({})
|
|
68
107
|
});
|
|
69
|
-
|
|
108
|
+
dependencySnapshotSchema = z.object({
|
|
70
109
|
$schema: z.string().optional(),
|
|
71
110
|
version: z.literal(1),
|
|
72
111
|
env: z.enum(["dev", "prod"]),
|
|
73
|
-
|
|
74
|
-
|
|
112
|
+
botId: z.string(),
|
|
113
|
+
fetchedAt: z.string(),
|
|
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"]))
|
|
75
123
|
});
|
|
76
124
|
});
|
|
77
125
|
|
|
@@ -125,109 +173,198 @@ var init_errors2 = __esm(() => {
|
|
|
125
173
|
"MISSING_DEPENDENCY",
|
|
126
174
|
"AMBIGUOUS_DEPENDENCY",
|
|
127
175
|
"INTERFACE_NOT_IMPLEMENTED",
|
|
128
|
-
"
|
|
176
|
+
"SNAPSHOT_DRIFT",
|
|
129
177
|
"UNINSTALL_REQUIRES_CONFIRMATION",
|
|
130
178
|
"SAME_SOURCE_TARGET",
|
|
131
|
-
"
|
|
179
|
+
"SOURCE_SNAPSHOT_MISSING",
|
|
132
180
|
"MIGRATION_CONFLICT",
|
|
133
181
|
"INVALID_CONFIG",
|
|
134
182
|
"BOT_NOT_FOUND",
|
|
135
183
|
"BUILTIN_INTERFACE_IMMUTABLE",
|
|
136
|
-
"PROD_CONFIRMATION_REQUIRED"
|
|
184
|
+
"PROD_CONFIRMATION_REQUIRED",
|
|
185
|
+
"UNCONFIGURED_DEPENDENCIES"
|
|
137
186
|
];
|
|
138
187
|
DependencyError = class DependencyError extends AdkError {
|
|
139
188
|
constructor(opts) {
|
|
140
189
|
super({ ...opts, expected: true });
|
|
141
190
|
}
|
|
142
191
|
};
|
|
143
|
-
DEPENDENCY_WARNING_CODES = [
|
|
144
|
-
"DEPRECATED_COMMAND",
|
|
145
|
-
"MIGRATED_DEPENDENCIES",
|
|
146
|
-
"CLOUD_FETCH_PARTIAL",
|
|
147
|
-
"NO_PROD_BOT"
|
|
148
|
-
];
|
|
192
|
+
DEPENDENCY_WARNING_CODES = ["MIGRATED_DEPENDENCIES", "CLOUD_FETCH_PARTIAL", "NO_PROD_BOT"];
|
|
149
193
|
});
|
|
150
194
|
|
|
151
|
-
// src/dependencies/
|
|
152
|
-
function
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
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;
|
|
195
|
+
// src/dependencies/status.ts
|
|
196
|
+
function schemaRequiredFields(config) {
|
|
197
|
+
const required = config?.schema?.required;
|
|
198
|
+
if (!Array.isArray(required))
|
|
199
|
+
return [];
|
|
200
|
+
return required.filter((field) => typeof field === "string");
|
|
164
201
|
}
|
|
165
|
-
function
|
|
166
|
-
|
|
202
|
+
function configurationRequiresInput(config) {
|
|
203
|
+
if (!config)
|
|
204
|
+
return false;
|
|
205
|
+
if (configGatesOnAuthorization(config))
|
|
206
|
+
return true;
|
|
207
|
+
return schemaRequiredFields(config).length > 0;
|
|
167
208
|
}
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
return false;
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
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" };
|
|
354
|
+
}
|
|
355
|
+
function computeSnapshotOnlyStatus(input) {
|
|
356
|
+
if (!input.installed)
|
|
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;
|
|
364
|
+
}
|
|
365
|
+
function isCallable(state) {
|
|
366
|
+
return state === "available";
|
|
226
367
|
}
|
|
227
|
-
var init_lock_file = __esm(() => {
|
|
228
|
-
init_types();
|
|
229
|
-
init_errors2();
|
|
230
|
-
});
|
|
231
368
|
|
|
232
369
|
// src/agent-project/types.ts
|
|
233
370
|
import { z as z2 } from "@botpress/sdk";
|
|
@@ -250,14 +387,14 @@ var init_types2 = __esm(() => {
|
|
|
250
387
|
plugins: z2.record(z2.object({
|
|
251
388
|
version: z2.string(),
|
|
252
389
|
config: z2.record(z2.any()).optional(),
|
|
253
|
-
dependencies: z2.record(pluginDependencyMappingSchema2).optional()
|
|
390
|
+
dependencies: z2.record(pluginDependencyMappingSchema2).optional(),
|
|
391
|
+
missingFields: z2.array(z2.string()).optional()
|
|
254
392
|
})).optional()
|
|
255
393
|
});
|
|
256
394
|
agentInfoSchema = z2.object({
|
|
257
395
|
botId: z2.string().describe("The bot ID from Botpress deployment"),
|
|
258
396
|
workspaceId: z2.string().describe("The workspace ID where the bot is deployed"),
|
|
259
|
-
apiUrl: z2.string().optional().describe("The Botpress API URL (e.g., https://api.botpress.cloud)")
|
|
260
|
-
devId: z2.string().optional().describe("The development ID used during local development")
|
|
397
|
+
apiUrl: z2.string().optional().describe("The Botpress API URL (e.g., https://api.botpress.cloud)")
|
|
261
398
|
});
|
|
262
399
|
agentLocalInfoSchema = z2.object({
|
|
263
400
|
botId: z2.string().optional().describe("The bot ID (overrides agent.json for local development)"),
|
|
@@ -316,24 +453,24 @@ class ValidationErrors {
|
|
|
316
453
|
static isValidationError(error) {
|
|
317
454
|
return error !== null && typeof error === "object" && "$type" in error && error.$type === "ValidationError";
|
|
318
455
|
}
|
|
319
|
-
static directoryNotFound(
|
|
456
|
+
static directoryNotFound(path) {
|
|
320
457
|
return {
|
|
321
458
|
$type: ValidationErrors.$type,
|
|
322
459
|
code: "DIRECTORY_NOT_FOUND" /* DIRECTORY_NOT_FOUND */,
|
|
323
460
|
severity: "error" /* ERROR */,
|
|
324
|
-
message: `Project directory not found: ${
|
|
461
|
+
message: `Project directory not found: ${path}`,
|
|
325
462
|
hint: "Ensure the directory exists and you have permission to access it",
|
|
326
|
-
context: { path
|
|
463
|
+
context: { path }
|
|
327
464
|
};
|
|
328
465
|
}
|
|
329
|
-
static directoryAccessError(
|
|
466
|
+
static directoryAccessError(path, error) {
|
|
330
467
|
return {
|
|
331
468
|
$type: ValidationErrors.$type,
|
|
332
469
|
code: "DIRECTORY_ACCESS_ERROR" /* DIRECTORY_ACCESS_ERROR */,
|
|
333
470
|
severity: "error" /* ERROR */,
|
|
334
471
|
message: `Cannot access project directory: ${error}`,
|
|
335
472
|
hint: "Check file system permissions",
|
|
336
|
-
context: { path
|
|
473
|
+
context: { path, error }
|
|
337
474
|
};
|
|
338
475
|
}
|
|
339
476
|
static requiredFileMissing(file) {
|
|
@@ -691,90 +828,322 @@ var init_validation_errors = __esm(() => {
|
|
|
691
828
|
init_types2();
|
|
692
829
|
});
|
|
693
830
|
|
|
694
|
-
// src/
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
llm: "llm@9.0.0",
|
|
700
|
-
listable: "listable@0.0.2"
|
|
701
|
-
};
|
|
702
|
-
});
|
|
831
|
+
// src/agent-project/dependencies-parser.ts
|
|
832
|
+
import { z as z3 } from "@botpress/sdk";
|
|
833
|
+
function isIntegrationAliasValid(alias) {
|
|
834
|
+
return alias.length >= INTEGRATION_ALIAS_MIN_LENGTH && alias.length <= INTEGRATION_ALIAS_MAX_LENGTH && INTEGRATION_ALIAS_REGEX.test(alias);
|
|
835
|
+
}
|
|
703
836
|
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
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");
|
|
837
|
+
class IntegrationParser {
|
|
838
|
+
static parseIntegrationRef(versionString) {
|
|
839
|
+
const result = integrationRefSchema.safeParse(versionString);
|
|
840
|
+
if (!result.success) {
|
|
841
|
+
throw new AdkError({
|
|
842
|
+
code: "INVALID_VERSION_FORMAT",
|
|
843
|
+
expected: true,
|
|
844
|
+
message: result.error.errors[0]?.message || "Invalid integration version format"
|
|
845
|
+
});
|
|
716
846
|
}
|
|
717
|
-
return
|
|
718
|
-
}
|
|
719
|
-
|
|
720
|
-
|
|
847
|
+
return result.data;
|
|
848
|
+
}
|
|
849
|
+
static parseIntegrations(dependencies) {
|
|
850
|
+
const integrations = [];
|
|
851
|
+
const errors = [];
|
|
852
|
+
if (!dependencies.integrations) {
|
|
853
|
+
return { integrations, errors };
|
|
721
854
|
}
|
|
722
|
-
|
|
723
|
-
|
|
855
|
+
for (const [alias, value] of Object.entries(dependencies.integrations)) {
|
|
856
|
+
try {
|
|
857
|
+
if (!isIntegrationAliasValid(alias)) {
|
|
858
|
+
errors.push(ValidationErrors.invalidIntegrationAlias(alias));
|
|
859
|
+
continue;
|
|
860
|
+
}
|
|
861
|
+
const normalized = typeof value === "string" ? { version: value } : value;
|
|
862
|
+
const ref = this.parseIntegrationRef(normalized.version);
|
|
863
|
+
const versionResult = versionSchema.safeParse(ref.version);
|
|
864
|
+
if (!versionResult.success) {
|
|
865
|
+
errors.push(ValidationErrors.invalidVersionFormat(alias, ref.version));
|
|
866
|
+
}
|
|
867
|
+
integrations.push({
|
|
868
|
+
alias,
|
|
869
|
+
ref,
|
|
870
|
+
enabled: "enabled" in normalized ? normalized.enabled : undefined,
|
|
871
|
+
configurationType: "configurationType" in normalized ? normalized.configurationType : undefined,
|
|
872
|
+
config: "config" in normalized ? normalized.config : undefined
|
|
873
|
+
});
|
|
874
|
+
} catch (error) {
|
|
875
|
+
errors.push(ValidationErrors.invalidDependenciesSyntax(`Invalid integration '${alias}': ${error instanceof Error ? error.message : String(error)}`));
|
|
876
|
+
}
|
|
724
877
|
}
|
|
725
|
-
|
|
726
|
-
}
|
|
727
|
-
}
|
|
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;
|
|
878
|
+
return { integrations, errors };
|
|
740
879
|
}
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
let agentData;
|
|
750
|
-
try {
|
|
751
|
-
agentData = JSON.parse(agentJsonContent);
|
|
752
|
-
} catch (parseError) {
|
|
753
|
-
throw ValidationErrors.invalidConfigSyntax("agent.json", parseError.message);
|
|
754
|
-
}
|
|
755
|
-
const validationResult = agentInfoSchema.safeParse(agentData);
|
|
756
|
-
if (!validationResult.success) {
|
|
757
|
-
const zodError = validationResult.error.errors[0];
|
|
758
|
-
throw ValidationErrors.invalidConfigSchema("agent.json", zodError?.path.join(".") || "unknown", zodError?.message || "Invalid schema");
|
|
880
|
+
static checkDuplicates(integrations) {
|
|
881
|
+
const errors = [];
|
|
882
|
+
const seen = new Map;
|
|
883
|
+
for (const integration of integrations) {
|
|
884
|
+
const key = integration.ref.fullName;
|
|
885
|
+
const group = seen.get(key) || [];
|
|
886
|
+
group.push(integration);
|
|
887
|
+
seen.set(key, group);
|
|
759
888
|
}
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
889
|
+
for (const [integrationName, group] of seen.entries()) {
|
|
890
|
+
if (group.length > 1) {
|
|
891
|
+
const duplicateConfigs = [];
|
|
892
|
+
for (let i = 0;i < group.length; i++) {
|
|
893
|
+
for (let j = i + 1;j < group.length; j++) {
|
|
894
|
+
const configA = JSON.stringify(group[i].config ?? {});
|
|
895
|
+
const configB = JSON.stringify(group[j].config ?? {});
|
|
896
|
+
if (configA === configB) {
|
|
897
|
+
if (!duplicateConfigs.includes(group[i].alias)) {
|
|
898
|
+
duplicateConfigs.push(group[i].alias);
|
|
899
|
+
}
|
|
900
|
+
if (!duplicateConfigs.includes(group[j].alias)) {
|
|
901
|
+
duplicateConfigs.push(group[j].alias);
|
|
902
|
+
}
|
|
903
|
+
}
|
|
904
|
+
}
|
|
905
|
+
}
|
|
906
|
+
if (duplicateConfigs.length > 0) {
|
|
907
|
+
errors.push(ValidationErrors.warning(`Integration '${integrationName}' has aliases with identical configurations: ${duplicateConfigs.join(", ")}. Consider using different configs or removing duplicates.`, "agent.config.ts"));
|
|
908
|
+
}
|
|
909
|
+
}
|
|
766
910
|
}
|
|
911
|
+
return errors;
|
|
767
912
|
}
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
throw
|
|
913
|
+
}
|
|
914
|
+
function isPluginAliasValid(alias) {
|
|
915
|
+
return alias.length >= PLUGIN_ALIAS_MIN_LENGTH && alias.length <= PLUGIN_ALIAS_MAX_LENGTH && PLUGIN_ALIAS_REGEX.test(alias);
|
|
916
|
+
}
|
|
917
|
+
|
|
918
|
+
class PluginParser {
|
|
919
|
+
static parsePluginRef(versionString) {
|
|
920
|
+
const result = pluginRefSchema.safeParse(versionString);
|
|
921
|
+
if (!result.success) {
|
|
922
|
+
throw new AdkError({
|
|
923
|
+
code: "INVALID_VERSION_FORMAT",
|
|
924
|
+
expected: true,
|
|
925
|
+
message: result.error.errors[0]?.message || "Invalid plugin version format"
|
|
926
|
+
});
|
|
927
|
+
}
|
|
928
|
+
return result.data;
|
|
929
|
+
}
|
|
930
|
+
static parsePlugins(dependencies) {
|
|
931
|
+
const plugins = [];
|
|
932
|
+
const errors = [];
|
|
933
|
+
if (!dependencies.plugins) {
|
|
934
|
+
return { plugins, errors };
|
|
935
|
+
}
|
|
936
|
+
for (const [alias, value] of Object.entries(dependencies.plugins)) {
|
|
937
|
+
try {
|
|
938
|
+
if (!isPluginAliasValid(alias)) {
|
|
939
|
+
errors.push(ValidationErrors.invalidPluginAlias(alias));
|
|
940
|
+
continue;
|
|
941
|
+
}
|
|
942
|
+
const ref = this.parsePluginRef(value.version);
|
|
943
|
+
const versionResult = versionSchema.safeParse(ref.version);
|
|
944
|
+
if (!versionResult.success) {
|
|
945
|
+
errors.push(ValidationErrors.invalidPluginVersionFormat(alias, ref.version));
|
|
946
|
+
}
|
|
947
|
+
plugins.push({
|
|
948
|
+
alias,
|
|
949
|
+
ref,
|
|
950
|
+
config: value.config,
|
|
951
|
+
dependencies: value.dependencies
|
|
952
|
+
});
|
|
953
|
+
} catch (error) {
|
|
954
|
+
errors.push(ValidationErrors.invalidDependenciesSyntax(`Invalid plugin '${alias}': ${error instanceof Error ? error.message : String(error)}`));
|
|
955
|
+
}
|
|
956
|
+
}
|
|
957
|
+
return { plugins, errors };
|
|
958
|
+
}
|
|
959
|
+
static validateDependencyReferences(dependencies) {
|
|
960
|
+
const errors = [];
|
|
961
|
+
if (!dependencies.plugins) {
|
|
962
|
+
return errors;
|
|
963
|
+
}
|
|
964
|
+
const integrationAliases = Object.keys(dependencies.integrations || {});
|
|
965
|
+
for (const [alias, pluginConfig] of Object.entries(dependencies.plugins)) {
|
|
966
|
+
if (!pluginConfig.dependencies) {
|
|
967
|
+
continue;
|
|
968
|
+
}
|
|
969
|
+
for (const [_depAlias, depMapping] of Object.entries(pluginConfig.dependencies)) {
|
|
970
|
+
if (!integrationAliases.includes(depMapping.integrationAlias)) {
|
|
971
|
+
errors.push(ValidationErrors.invalidPluginDependency(alias, depMapping.integrationAlias, integrationAliases));
|
|
972
|
+
}
|
|
973
|
+
}
|
|
974
|
+
}
|
|
975
|
+
return errors;
|
|
976
|
+
}
|
|
977
|
+
static checkDuplicates(plugins) {
|
|
978
|
+
const errors = [];
|
|
979
|
+
const seen = new Map;
|
|
980
|
+
for (const plugin of plugins) {
|
|
981
|
+
const key = plugin.ref.fullName;
|
|
982
|
+
const group = seen.get(key) || [];
|
|
983
|
+
group.push(plugin);
|
|
984
|
+
seen.set(key, group);
|
|
985
|
+
}
|
|
986
|
+
for (const [pluginName, group] of seen.entries()) {
|
|
987
|
+
if (group.length > 1) {
|
|
988
|
+
const duplicateConfigs = [];
|
|
989
|
+
for (let i = 0;i < group.length; i++) {
|
|
990
|
+
for (let j = i + 1;j < group.length; j++) {
|
|
991
|
+
const configA = JSON.stringify(group[i].config ?? {});
|
|
992
|
+
const configB = JSON.stringify(group[j].config ?? {});
|
|
993
|
+
if (configA === configB) {
|
|
994
|
+
if (!duplicateConfigs.includes(group[i].alias)) {
|
|
995
|
+
duplicateConfigs.push(group[i].alias);
|
|
996
|
+
}
|
|
997
|
+
if (!duplicateConfigs.includes(group[j].alias)) {
|
|
998
|
+
duplicateConfigs.push(group[j].alias);
|
|
999
|
+
}
|
|
1000
|
+
}
|
|
1001
|
+
}
|
|
1002
|
+
}
|
|
1003
|
+
if (duplicateConfigs.length > 0) {
|
|
1004
|
+
errors.push(ValidationErrors.warning(`Plugin '${pluginName}' has aliases with identical configurations: ${duplicateConfigs.join(", ")}. Consider using different configs or removing duplicates.`, "agent.config.ts"));
|
|
1005
|
+
}
|
|
1006
|
+
}
|
|
1007
|
+
}
|
|
1008
|
+
return errors;
|
|
1009
|
+
}
|
|
1010
|
+
}
|
|
1011
|
+
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;
|
|
1012
|
+
var init_dependencies_parser = __esm(() => {
|
|
1013
|
+
init_src();
|
|
1014
|
+
init_validation_errors();
|
|
1015
|
+
INTEGRATION_ALIAS_REGEX = /^(?:[a-z][a-z0-9_-]*\/)?[a-z][a-z0-9_-]*$/;
|
|
1016
|
+
integrationRefSchema = z3.string().transform((val, ctx) => {
|
|
1017
|
+
const match = val.match(/^(?:([^/]+)\/)?([^@]+)@(.+)$/);
|
|
1018
|
+
if (!match) {
|
|
1019
|
+
ctx.addIssue({
|
|
1020
|
+
code: "custom",
|
|
1021
|
+
message: `Invalid integration version format: ${val}. Expected format: 'name@version' or 'workspace/name@version'`
|
|
1022
|
+
});
|
|
1023
|
+
return;
|
|
1024
|
+
}
|
|
1025
|
+
const [, workspace, name, version] = match;
|
|
1026
|
+
return {
|
|
1027
|
+
workspace: workspace || undefined,
|
|
1028
|
+
name,
|
|
1029
|
+
version,
|
|
1030
|
+
fullName: workspace ? `${workspace}/${name}` : name
|
|
1031
|
+
};
|
|
1032
|
+
});
|
|
1033
|
+
versionSchema = z3.string().refine((version) => {
|
|
1034
|
+
if (version === "latest")
|
|
1035
|
+
return true;
|
|
1036
|
+
const semverPattern = /^(\d+)\.(\d+)\.(\d+)(-[\w.]+)?(\+[\w.]+)?$/;
|
|
1037
|
+
return semverPattern.test(version);
|
|
1038
|
+
}, { message: "Version must be exact semver (e.g., 1.2.3) or 'latest'" });
|
|
1039
|
+
PLUGIN_ALIAS_REGEX = /^[a-z][a-z0-9_-]*$/;
|
|
1040
|
+
pluginRefSchema = z3.string().transform((val, ctx) => {
|
|
1041
|
+
const match = val.match(/^([^/@]+)@(.+)$/);
|
|
1042
|
+
if (!match) {
|
|
1043
|
+
ctx.addIssue({
|
|
1044
|
+
code: "custom",
|
|
1045
|
+
message: `Invalid plugin version format: ${val}. Expected format: 'name@version' (no workspace prefix)`
|
|
1046
|
+
});
|
|
1047
|
+
return;
|
|
1048
|
+
}
|
|
1049
|
+
const [, name, version] = match;
|
|
1050
|
+
return {
|
|
1051
|
+
name,
|
|
1052
|
+
version,
|
|
1053
|
+
fullName: name
|
|
1054
|
+
};
|
|
1055
|
+
});
|
|
1056
|
+
});
|
|
1057
|
+
|
|
1058
|
+
// src/constants.ts
|
|
1059
|
+
var DEFAULT_API_URL = "https://api.botpress.cloud", BUILTIN_INTERFACES, MAX_TABLE_COLUMNS = 20;
|
|
1060
|
+
var init_constants = __esm(() => {
|
|
1061
|
+
BUILTIN_INTERFACES = {
|
|
1062
|
+
"typing-indicator": "typing-indicator@0.0.3",
|
|
1063
|
+
llm: "llm@9.0.0",
|
|
1064
|
+
listable: "listable@0.0.2"
|
|
1065
|
+
};
|
|
1066
|
+
});
|
|
1067
|
+
|
|
1068
|
+
// src/agent-project/agent-resolver.ts
|
|
1069
|
+
import fs from "fs/promises";
|
|
1070
|
+
import path from "path";
|
|
1071
|
+
async function readLocalInfo(agentPath) {
|
|
1072
|
+
const localPath = path.join(agentPath, "agent.local.json");
|
|
1073
|
+
try {
|
|
1074
|
+
const localContent = await fs.readFile(localPath, "utf-8");
|
|
1075
|
+
const localData = JSON.parse(localContent);
|
|
1076
|
+
const localResult = agentLocalInfoSchema.safeParse(localData);
|
|
1077
|
+
if (!localResult.success) {
|
|
1078
|
+
const issue = localResult.error.errors[0];
|
|
1079
|
+
throw ValidationErrors.warning(`agent.local.json has an invalid field: ${issue?.path.join(".")} — ${issue?.message}`, "agent.local.json");
|
|
1080
|
+
}
|
|
1081
|
+
return localResult.data;
|
|
1082
|
+
} catch (error) {
|
|
1083
|
+
if (error.code === "ENOENT") {
|
|
1084
|
+
return null;
|
|
1085
|
+
}
|
|
1086
|
+
if (ValidationErrors.isValidationError(error)) {
|
|
1087
|
+
throw error;
|
|
1088
|
+
}
|
|
1089
|
+
throw ValidationErrors.warning(`Failed to read agent.local.json: ${error.message}`, "agent.local.json");
|
|
1090
|
+
}
|
|
1091
|
+
}
|
|
1092
|
+
function applyLocalOverrides(agentInfo, localInfo) {
|
|
1093
|
+
if (localInfo.botId) {
|
|
1094
|
+
agentInfo.botId = localInfo.botId;
|
|
1095
|
+
}
|
|
1096
|
+
if (localInfo.workspaceId) {
|
|
1097
|
+
agentInfo.workspaceId = localInfo.workspaceId;
|
|
1098
|
+
}
|
|
1099
|
+
if (localInfo.apiUrl) {
|
|
1100
|
+
agentInfo.apiUrl = localInfo.apiUrl;
|
|
1101
|
+
}
|
|
1102
|
+
if (localInfo.devId) {
|
|
1103
|
+
agentInfo.devId = localInfo.devId;
|
|
1104
|
+
}
|
|
1105
|
+
}
|
|
1106
|
+
async function resolveAgent(agentPath, options = {}) {
|
|
1107
|
+
const { required = false, requireWorkspace = false, requireBot = false } = options;
|
|
1108
|
+
const agentJsonPath = path.join(agentPath, "agent.json");
|
|
1109
|
+
const localInfo = await readLocalInfo(agentPath);
|
|
1110
|
+
let agentInfo = null;
|
|
1111
|
+
try {
|
|
1112
|
+
const agentJsonContent = await fs.readFile(agentJsonPath, "utf-8");
|
|
1113
|
+
let agentData;
|
|
1114
|
+
try {
|
|
1115
|
+
agentData = JSON.parse(agentJsonContent);
|
|
1116
|
+
} catch (parseError) {
|
|
1117
|
+
throw ValidationErrors.invalidConfigSyntax("agent.json", parseError.message);
|
|
1118
|
+
}
|
|
1119
|
+
const validationResult = agentInfoSchema.safeParse(agentData);
|
|
1120
|
+
if (!validationResult.success) {
|
|
1121
|
+
const zodError = validationResult.error.errors[0];
|
|
1122
|
+
throw ValidationErrors.invalidConfigSchema("agent.json", zodError?.path.join(".") || "unknown", zodError?.message || "Invalid schema");
|
|
1123
|
+
}
|
|
1124
|
+
const parsed = validationResult.data;
|
|
1125
|
+
agentInfo = {
|
|
1126
|
+
botId: parsed.botId,
|
|
1127
|
+
workspaceId: parsed.workspaceId,
|
|
1128
|
+
apiUrl: parsed.apiUrl
|
|
1129
|
+
};
|
|
1130
|
+
} catch (error) {
|
|
1131
|
+
if (error.code === "ENOENT") {} else if (ValidationErrors.isValidationError(error)) {
|
|
1132
|
+
throw error;
|
|
1133
|
+
} else {
|
|
1134
|
+
throw ValidationErrors.warning(`Failed to read agent.json: ${error.message}`, "agent.json");
|
|
1135
|
+
}
|
|
1136
|
+
}
|
|
1137
|
+
if (!agentInfo) {
|
|
1138
|
+
if (localInfo?.botId && localInfo?.workspaceId) {
|
|
1139
|
+
agentInfo = {
|
|
1140
|
+
botId: localInfo.botId,
|
|
1141
|
+
workspaceId: localInfo.workspaceId,
|
|
1142
|
+
apiUrl: localInfo.apiUrl,
|
|
1143
|
+
devId: localInfo.devId
|
|
1144
|
+
};
|
|
1145
|
+
} else if (required || requireWorkspace || requireBot) {
|
|
1146
|
+
throw ValidationErrors.requiredFileMissing("agent.json or agent.local.json");
|
|
778
1147
|
} else {
|
|
779
1148
|
return null;
|
|
780
1149
|
}
|
|
@@ -805,8 +1174,8 @@ var exports_credentials = {};
|
|
|
805
1174
|
__export(exports_credentials, {
|
|
806
1175
|
CredentialsManager: () => CredentialsManager
|
|
807
1176
|
});
|
|
808
|
-
import
|
|
809
|
-
import
|
|
1177
|
+
import fs2 from "fs/promises";
|
|
1178
|
+
import path2 from "path";
|
|
810
1179
|
import os from "os";
|
|
811
1180
|
|
|
812
1181
|
class CredentialsManager {
|
|
@@ -814,20 +1183,20 @@ class CredentialsManager {
|
|
|
814
1183
|
configDir;
|
|
815
1184
|
profileOverride;
|
|
816
1185
|
constructor() {
|
|
817
|
-
this.configDir =
|
|
818
|
-
this.credentialsPath =
|
|
1186
|
+
this.configDir = path2.join(os.homedir(), ".adk");
|
|
1187
|
+
this.credentialsPath = path2.join(this.configDir, "credentials");
|
|
819
1188
|
}
|
|
820
1189
|
setProfileOverride(profile) {
|
|
821
1190
|
this.profileOverride = profile;
|
|
822
1191
|
}
|
|
823
1192
|
async ensureConfigDir() {
|
|
824
1193
|
try {
|
|
825
|
-
await
|
|
1194
|
+
await fs2.mkdir(this.configDir, { recursive: true });
|
|
826
1195
|
} catch {}
|
|
827
1196
|
}
|
|
828
1197
|
async readCredentials() {
|
|
829
1198
|
try {
|
|
830
|
-
const data = await
|
|
1199
|
+
const data = await fs2.readFile(this.credentialsPath, "utf-8");
|
|
831
1200
|
return JSON.parse(data);
|
|
832
1201
|
} catch {
|
|
833
1202
|
return {
|
|
@@ -839,8 +1208,8 @@ class CredentialsManager {
|
|
|
839
1208
|
}
|
|
840
1209
|
async writeCredentials(store) {
|
|
841
1210
|
await this.ensureConfigDir();
|
|
842
|
-
await
|
|
843
|
-
await
|
|
1211
|
+
await fs2.writeFile(this.credentialsPath, JSON.stringify(store, null, 2));
|
|
1212
|
+
await fs2.chmod(this.credentialsPath, 384);
|
|
844
1213
|
}
|
|
845
1214
|
async saveCredentials(profileName, credentials, userInfo) {
|
|
846
1215
|
const store = await this.readCredentials();
|
|
@@ -944,7 +1313,7 @@ class CredentialsManager {
|
|
|
944
1313
|
await this.writeCredentials(store);
|
|
945
1314
|
}
|
|
946
1315
|
async getActiveCredentials() {
|
|
947
|
-
const profileName = this.profileOverride
|
|
1316
|
+
const profileName = this.profileOverride;
|
|
948
1317
|
const credentials = await this.getCredentials(profileName);
|
|
949
1318
|
if (!credentials) {
|
|
950
1319
|
const displayName = profileName || "default";
|
|
@@ -976,7 +1345,7 @@ class CredentialsManager {
|
|
|
976
1345
|
});
|
|
977
1346
|
const agentApiUrl = agentInfo.apiUrl;
|
|
978
1347
|
let baseCredentials;
|
|
979
|
-
const hasExplicitProfile = !!
|
|
1348
|
+
const hasExplicitProfile = !!this.profileOverride;
|
|
980
1349
|
if (hasExplicitProfile) {
|
|
981
1350
|
baseCredentials = await this.getActiveCredentials();
|
|
982
1351
|
} else {
|
|
@@ -1082,18 +1451,18 @@ var init_service = __esm(() => {
|
|
|
1082
1451
|
});
|
|
1083
1452
|
|
|
1084
1453
|
// src/auth/bp-cli-import.ts
|
|
1085
|
-
import
|
|
1086
|
-
import
|
|
1454
|
+
import fs3 from "fs/promises";
|
|
1455
|
+
import path3 from "path";
|
|
1087
1456
|
import os2 from "os";
|
|
1088
1457
|
|
|
1089
1458
|
class BpCliImporter {
|
|
1090
1459
|
bpCachePath;
|
|
1091
1460
|
constructor() {
|
|
1092
|
-
this.bpCachePath =
|
|
1461
|
+
this.bpCachePath = path3.join(os2.homedir(), ".botpress", "global.cache.json");
|
|
1093
1462
|
}
|
|
1094
1463
|
async hasBpCliCredentials() {
|
|
1095
1464
|
try {
|
|
1096
|
-
await
|
|
1465
|
+
await fs3.access(this.bpCachePath);
|
|
1097
1466
|
return true;
|
|
1098
1467
|
} catch {
|
|
1099
1468
|
return false;
|
|
@@ -1101,7 +1470,7 @@ class BpCliImporter {
|
|
|
1101
1470
|
}
|
|
1102
1471
|
async getBpCliCredentials() {
|
|
1103
1472
|
try {
|
|
1104
|
-
const data = await
|
|
1473
|
+
const data = await fs3.readFile(this.bpCachePath, "utf-8");
|
|
1105
1474
|
const credentials = JSON.parse(data);
|
|
1106
1475
|
if (!credentials.token || !credentials.workspaceId || !credentials.apiUrl) {
|
|
1107
1476
|
return null;
|
|
@@ -1354,102 +1723,148 @@ var init_auth = __esm(() => {
|
|
|
1354
1723
|
projectClientCache = new Map;
|
|
1355
1724
|
});
|
|
1356
1725
|
|
|
1357
|
-
// src/
|
|
1358
|
-
import
|
|
1359
|
-
|
|
1726
|
+
// src/dependencies/catalog/client-factory.ts
|
|
1727
|
+
import { Client as Client3 } from "@botpress/client";
|
|
1728
|
+
|
|
1729
|
+
class CatalogClientFactory {
|
|
1730
|
+
options;
|
|
1731
|
+
client;
|
|
1732
|
+
constructor(options = {}) {
|
|
1733
|
+
this.options = options;
|
|
1734
|
+
}
|
|
1735
|
+
async getClient() {
|
|
1736
|
+
if (this.client)
|
|
1737
|
+
return this.client;
|
|
1738
|
+
const { project, workspaceId, credentials, apiUrl } = this.options;
|
|
1739
|
+
const hasProjectScope = !!(project || workspaceId);
|
|
1740
|
+
if (hasProjectScope) {
|
|
1741
|
+
this.client = await getProjectClient({
|
|
1742
|
+
project,
|
|
1743
|
+
credentials,
|
|
1744
|
+
apiUrl,
|
|
1745
|
+
workspaceId,
|
|
1746
|
+
headers: { ...CATALOG_HEADERS }
|
|
1747
|
+
});
|
|
1748
|
+
} else if (credentials) {
|
|
1749
|
+
this.client = new Client3({
|
|
1750
|
+
token: credentials.token,
|
|
1751
|
+
apiUrl: apiUrl || credentials.apiUrl,
|
|
1752
|
+
...credentials.workspaceId ? { workspaceId: credentials.workspaceId } : {},
|
|
1753
|
+
headers: { ...CATALOG_HEADERS }
|
|
1754
|
+
});
|
|
1755
|
+
} else {
|
|
1756
|
+
this.client = await getProjectClient({ headers: { ...CATALOG_HEADERS } });
|
|
1757
|
+
}
|
|
1758
|
+
return this.client;
|
|
1759
|
+
}
|
|
1760
|
+
}
|
|
1761
|
+
var CATALOG_HEADERS;
|
|
1762
|
+
var init_client_factory = __esm(() => {
|
|
1763
|
+
init_auth();
|
|
1764
|
+
CATALOG_HEADERS = { "x-multiple-integrations": "true" };
|
|
1765
|
+
});
|
|
1766
|
+
|
|
1767
|
+
// src/dependencies/catalog/resolution-cache.ts
|
|
1768
|
+
import fs4 from "fs/promises";
|
|
1769
|
+
import path4 from "path";
|
|
1360
1770
|
import os3 from "os";
|
|
1361
1771
|
|
|
1362
|
-
class
|
|
1772
|
+
class ResolutionCache {
|
|
1363
1773
|
cacheDir;
|
|
1364
1774
|
resolutionsDir;
|
|
1365
1775
|
definitionsDir;
|
|
1776
|
+
idField;
|
|
1366
1777
|
noCache;
|
|
1367
|
-
constructor(noCache = false) {
|
|
1778
|
+
constructor(config, noCache = false) {
|
|
1779
|
+
this.idField = config.idField;
|
|
1368
1780
|
this.noCache = noCache;
|
|
1369
|
-
|
|
1370
|
-
this.
|
|
1371
|
-
this.
|
|
1781
|
+
const cacheRoot = config.cacheRoot ?? path4.join(os3.homedir(), ".adk", "cache");
|
|
1782
|
+
this.cacheDir = path4.join(cacheRoot, config.cacheType);
|
|
1783
|
+
this.resolutionsDir = path4.join(this.cacheDir, "resolutions");
|
|
1784
|
+
this.definitionsDir = path4.join(this.cacheDir, "definitions");
|
|
1372
1785
|
}
|
|
1373
1786
|
async ensureCacheDirs() {
|
|
1374
|
-
await
|
|
1375
|
-
await
|
|
1787
|
+
await fs4.mkdir(this.resolutionsDir, { recursive: true });
|
|
1788
|
+
await fs4.mkdir(this.definitionsDir, { recursive: true });
|
|
1376
1789
|
}
|
|
1377
|
-
async getResolution(name, version, workspace) {
|
|
1790
|
+
async getResolution(name, version, workspace, options) {
|
|
1378
1791
|
if (this.noCache) {
|
|
1379
1792
|
return null;
|
|
1380
1793
|
}
|
|
1381
1794
|
try {
|
|
1382
1795
|
const key = this.getResolutionKey(name, version, workspace);
|
|
1383
|
-
const cachePath =
|
|
1384
|
-
const data = await
|
|
1385
|
-
const
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1796
|
+
const cachePath = path4.join(this.resolutionsDir, `${key}.json`);
|
|
1797
|
+
const data = await fs4.readFile(cachePath, "utf-8");
|
|
1798
|
+
const raw = JSON.parse(data);
|
|
1799
|
+
if (!options?.allowStale) {
|
|
1800
|
+
const cachedAt = new Date(raw.cachedAt);
|
|
1801
|
+
const ageMinutes = (Date.now() - cachedAt.getTime()) / (1000 * 60);
|
|
1802
|
+
if (ageMinutes > RESOLUTION_TTL_MINUTES) {
|
|
1803
|
+
return null;
|
|
1804
|
+
}
|
|
1805
|
+
}
|
|
1806
|
+
const id = raw[this.idField];
|
|
1807
|
+
if (!id) {
|
|
1390
1808
|
return null;
|
|
1391
1809
|
}
|
|
1392
|
-
return
|
|
1810
|
+
return { id, updatedAt: raw.updatedAt, cachedAt: raw.cachedAt };
|
|
1393
1811
|
} catch {
|
|
1394
1812
|
return null;
|
|
1395
1813
|
}
|
|
1396
1814
|
}
|
|
1397
|
-
async setResolution(name, version, workspace,
|
|
1815
|
+
async setResolution(name, version, workspace, id, updatedAt) {
|
|
1398
1816
|
await this.ensureCacheDirs();
|
|
1399
1817
|
const key = this.getResolutionKey(name, version, workspace);
|
|
1400
|
-
const cachePath =
|
|
1818
|
+
const cachePath = path4.join(this.resolutionsDir, `${key}.json`);
|
|
1401
1819
|
const resolution = {
|
|
1402
|
-
|
|
1820
|
+
[this.idField]: id,
|
|
1403
1821
|
updatedAt,
|
|
1404
1822
|
cachedAt: new Date().toISOString()
|
|
1405
1823
|
};
|
|
1406
|
-
await
|
|
1824
|
+
await fs4.writeFile(cachePath, JSON.stringify(resolution));
|
|
1407
1825
|
}
|
|
1408
|
-
async getDefinition(
|
|
1826
|
+
async getDefinition(id, updatedAt) {
|
|
1409
1827
|
if (this.noCache) {
|
|
1410
1828
|
return null;
|
|
1411
1829
|
}
|
|
1412
1830
|
try {
|
|
1413
|
-
const key = this.getDefinitionKey(
|
|
1414
|
-
const cachePath =
|
|
1415
|
-
const data = await
|
|
1831
|
+
const key = this.getDefinitionKey(id, updatedAt);
|
|
1832
|
+
const cachePath = path4.join(this.definitionsDir, `${key}.json`);
|
|
1833
|
+
const data = await fs4.readFile(cachePath, "utf-8");
|
|
1416
1834
|
const cached = JSON.parse(data);
|
|
1417
1835
|
return cached.definition;
|
|
1418
1836
|
} catch {
|
|
1419
1837
|
return null;
|
|
1420
1838
|
}
|
|
1421
1839
|
}
|
|
1422
|
-
async setDefinition(
|
|
1840
|
+
async setDefinition(id, updatedAt, definition) {
|
|
1423
1841
|
await this.ensureCacheDirs();
|
|
1424
|
-
const key = this.getDefinitionKey(
|
|
1425
|
-
const cachePath =
|
|
1842
|
+
const key = this.getDefinitionKey(id, updatedAt);
|
|
1843
|
+
const cachePath = path4.join(this.definitionsDir, `${key}.json`);
|
|
1426
1844
|
const cached = {
|
|
1427
1845
|
definition,
|
|
1428
1846
|
cachedAt: new Date().toISOString()
|
|
1429
1847
|
};
|
|
1430
|
-
await
|
|
1848
|
+
await fs4.writeFile(cachePath, JSON.stringify(cached));
|
|
1431
1849
|
}
|
|
1432
1850
|
async clear() {
|
|
1433
1851
|
try {
|
|
1434
|
-
const resolutionFiles = await
|
|
1435
|
-
await Promise.all(resolutionFiles.map((file) =>
|
|
1436
|
-
const definitionFiles = await
|
|
1437
|
-
await Promise.all(definitionFiles.map((file) =>
|
|
1852
|
+
const resolutionFiles = await fs4.readdir(this.resolutionsDir);
|
|
1853
|
+
await Promise.all(resolutionFiles.map((file) => fs4.unlink(path4.join(this.resolutionsDir, file))));
|
|
1854
|
+
const definitionFiles = await fs4.readdir(this.definitionsDir);
|
|
1855
|
+
await Promise.all(definitionFiles.map((file) => fs4.unlink(path4.join(this.definitionsDir, file))));
|
|
1438
1856
|
} catch {}
|
|
1439
1857
|
}
|
|
1440
1858
|
async getStats() {
|
|
1441
1859
|
const getDirectoryStats = async (dir) => {
|
|
1442
1860
|
try {
|
|
1443
|
-
const files = await
|
|
1861
|
+
const files = await fs4.readdir(dir);
|
|
1444
1862
|
let totalSize = 0;
|
|
1445
1863
|
for (const file of files) {
|
|
1446
|
-
const stats = await
|
|
1864
|
+
const stats = await fs4.stat(path4.join(dir, file));
|
|
1447
1865
|
totalSize += stats.size;
|
|
1448
1866
|
}
|
|
1449
|
-
return {
|
|
1450
|
-
count: files.length,
|
|
1451
|
-
sizeBytes: totalSize
|
|
1452
|
-
};
|
|
1867
|
+
return { count: files.length, sizeBytes: totalSize };
|
|
1453
1868
|
} catch {
|
|
1454
1869
|
return { count: 0, sizeBytes: 0 };
|
|
1455
1870
|
}
|
|
@@ -1465,238 +1880,65 @@ class EnhancedIntegrationCache {
|
|
|
1465
1880
|
const key = `${prefix}${name}_${version}`;
|
|
1466
1881
|
return key.replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
1467
1882
|
}
|
|
1468
|
-
getDefinitionKey(
|
|
1469
|
-
const key = `${
|
|
1883
|
+
getDefinitionKey(id, updatedAt) {
|
|
1884
|
+
const key = `${id}_${updatedAt}`;
|
|
1470
1885
|
return key.replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
1471
1886
|
}
|
|
1472
1887
|
}
|
|
1473
|
-
var
|
|
1474
|
-
|
|
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
|
-
}
|
|
1888
|
+
var RESOLUTION_TTL_MINUTES = 5;
|
|
1889
|
+
var init_resolution_cache = () => {};
|
|
1480
1890
|
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
message: result.error.errors[0]?.message || "Invalid integration version format"
|
|
1489
|
-
});
|
|
1490
|
-
}
|
|
1491
|
-
return result.data;
|
|
1891
|
+
// src/dependencies/catalog/catalog-service.ts
|
|
1892
|
+
class CatalogService {
|
|
1893
|
+
source;
|
|
1894
|
+
cache;
|
|
1895
|
+
constructor(source, noCache = false) {
|
|
1896
|
+
this.source = source;
|
|
1897
|
+
this.cache = new ResolutionCache(source.cacheConfig, noCache);
|
|
1492
1898
|
}
|
|
1493
|
-
|
|
1494
|
-
const
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
for (const [alias, value] of Object.entries(dependencies.integrations)) {
|
|
1500
|
-
try {
|
|
1501
|
-
if (!isIntegrationAliasValid(alias)) {
|
|
1502
|
-
errors.push(ValidationErrors.invalidIntegrationAlias(alias));
|
|
1503
|
-
continue;
|
|
1504
|
-
}
|
|
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)}`));
|
|
1899
|
+
async getDefinition(ref) {
|
|
1900
|
+
const cachedResolution = await this.cache.getResolution(ref.name, ref.version, ref.workspace);
|
|
1901
|
+
if (cachedResolution) {
|
|
1902
|
+
const cachedDefinition = await this.cache.getDefinition(cachedResolution.id, cachedResolution.updatedAt);
|
|
1903
|
+
if (cachedDefinition) {
|
|
1904
|
+
return cachedDefinition;
|
|
1520
1905
|
}
|
|
1521
1906
|
}
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
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"));
|
|
1907
|
+
try {
|
|
1908
|
+
const { id, updatedAt, definition } = await this.source.fetchByRef(ref);
|
|
1909
|
+
await this.cache.setResolution(ref.name, ref.version, ref.workspace, id, updatedAt);
|
|
1910
|
+
await this.cache.setDefinition(id, updatedAt, definition);
|
|
1911
|
+
return definition;
|
|
1912
|
+
} catch (err) {
|
|
1913
|
+
if (!(err instanceof AdkError && err.expected)) {
|
|
1914
|
+
const stale = await this.getStaleDefinition(ref);
|
|
1915
|
+
if (stale !== null) {
|
|
1916
|
+
return stale;
|
|
1552
1917
|
}
|
|
1553
1918
|
}
|
|
1919
|
+
throw err;
|
|
1554
1920
|
}
|
|
1555
|
-
return errors;
|
|
1556
|
-
}
|
|
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;
|
|
1573
1921
|
}
|
|
1574
|
-
|
|
1575
|
-
const
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
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 };
|
|
1922
|
+
async getStaleDefinition(ref) {
|
|
1923
|
+
const stale = await this.cache.getResolution(ref.name, ref.version, ref.workspace, { allowStale: true });
|
|
1924
|
+
if (!stale)
|
|
1925
|
+
return null;
|
|
1926
|
+
return this.cache.getDefinition(stale.id, stale.updatedAt);
|
|
1602
1927
|
}
|
|
1603
|
-
|
|
1604
|
-
const
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
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;
|
|
1928
|
+
async getCacheStats() {
|
|
1929
|
+
const stats = await this.cache.getStats();
|
|
1930
|
+
return {
|
|
1931
|
+
count: stats.resolutions.count + stats.definitions.count,
|
|
1932
|
+
sizeBytes: stats.resolutions.sizeBytes + stats.definitions.sizeBytes
|
|
1933
|
+
};
|
|
1620
1934
|
}
|
|
1621
|
-
|
|
1622
|
-
|
|
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;
|
|
1935
|
+
async clearCache() {
|
|
1936
|
+
await this.cache.clear();
|
|
1653
1937
|
}
|
|
1654
1938
|
}
|
|
1655
|
-
var
|
|
1656
|
-
var init_dependencies_parser = __esm(() => {
|
|
1939
|
+
var init_catalog_service = __esm(() => {
|
|
1657
1940
|
init_src();
|
|
1658
|
-
|
|
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
|
-
});
|
|
1941
|
+
init_resolution_cache();
|
|
1700
1942
|
});
|
|
1701
1943
|
|
|
1702
1944
|
// src/utils/search-ranking.ts
|
|
@@ -1765,89 +2007,23 @@ function normalize(value) {
|
|
|
1765
2007
|
}
|
|
1766
2008
|
var init_search_ranking = () => {};
|
|
1767
2009
|
|
|
1768
|
-
// src/
|
|
1769
|
-
class
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
async getClient() {
|
|
1778
|
-
if (!this.client) {
|
|
1779
|
-
this.client = await getProjectClient({
|
|
1780
|
-
project: this.options.project,
|
|
1781
|
-
credentials: this.options.credentials,
|
|
1782
|
-
apiUrl: this.options.apiUrl,
|
|
1783
|
-
workspaceId: this.options.workspaceId,
|
|
1784
|
-
headers: {
|
|
1785
|
-
"x-multiple-integrations": "true"
|
|
1786
|
-
}
|
|
1787
|
-
});
|
|
1788
|
-
}
|
|
1789
|
-
return this.client;
|
|
1790
|
-
}
|
|
1791
|
-
async loadIntegrations(dependencies) {
|
|
1792
|
-
const errors = [];
|
|
1793
|
-
const warnings = [];
|
|
1794
|
-
const parseResult = IntegrationParser.parseIntegrations(dependencies);
|
|
1795
|
-
const integrations = parseResult.integrations;
|
|
1796
|
-
errors.push(...parseResult.errors);
|
|
1797
|
-
const duplicateWarnings = IntegrationParser.checkDuplicates(integrations);
|
|
1798
|
-
warnings.push(...duplicateWarnings);
|
|
1799
|
-
const fetchPromises = integrations.map(async (integration) => {
|
|
1800
|
-
try {
|
|
1801
|
-
const definition = await this.fetchIntegration(integration.ref);
|
|
1802
|
-
integration.definition = definition;
|
|
1803
|
-
const validation = this.validateIntegration(integration);
|
|
1804
|
-
integration.validationResult = validation;
|
|
1805
|
-
if (!validation.valid) {
|
|
1806
|
-
validation.errors.forEach(() => {
|
|
1807
|
-
errors.push(ValidationErrors.unknownIntegration(integration.alias, integration.ref.fullName));
|
|
1808
|
-
});
|
|
1809
|
-
}
|
|
1810
|
-
if (validation.warnings.length > 0) {
|
|
1811
|
-
validation.warnings.forEach((warn) => {
|
|
1812
|
-
warnings.push(ValidationErrors.warning(warn, "agent.config.ts"));
|
|
1813
|
-
});
|
|
1814
|
-
}
|
|
1815
|
-
} catch (error) {
|
|
1816
|
-
if (error instanceof Error && error.message.includes("version")) {
|
|
1817
|
-
errors.push(ValidationErrors.integrationVersionError(integration.alias, error.message));
|
|
1818
|
-
} else {
|
|
1819
|
-
const errorMessage = error instanceof Error ? error.message : undefined;
|
|
1820
|
-
errors.push(ValidationErrors.unknownIntegration(integration.alias, integration.ref.fullName, errorMessage));
|
|
1821
|
-
}
|
|
1822
|
-
}
|
|
1823
|
-
});
|
|
1824
|
-
await Promise.all(fetchPromises);
|
|
1825
|
-
const hasChannels = integrations.some((i) => i.definition?.channels && Object.keys(i.definition.channels).length > 0);
|
|
1826
|
-
if (!hasChannels && integrations.length > 0) {
|
|
1827
|
-
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"));
|
|
1828
|
-
}
|
|
1829
|
-
return { integrations, errors, warnings };
|
|
1830
|
-
}
|
|
1831
|
-
async fetchIntegration(ref) {
|
|
1832
|
-
const cachedResolution = await this.cache.getResolution(ref.name, ref.version, ref.workspace);
|
|
1833
|
-
if (cachedResolution) {
|
|
1834
|
-
const cachedDefinition = await this.cache.getDefinition(cachedResolution.integrationId, cachedResolution.updatedAt);
|
|
1835
|
-
if (cachedDefinition) {
|
|
1836
|
-
return cachedDefinition;
|
|
1837
|
-
}
|
|
1838
|
-
}
|
|
1839
|
-
const client = await this.getClient();
|
|
2010
|
+
// src/dependencies/catalog/integration-source.ts
|
|
2011
|
+
class IntegrationCatalogSource {
|
|
2012
|
+
clientFactory;
|
|
2013
|
+
cacheConfig = { cacheType: "integrations", idField: "integrationId" };
|
|
2014
|
+
constructor(clientFactory) {
|
|
2015
|
+
this.clientFactory = clientFactory;
|
|
2016
|
+
}
|
|
2017
|
+
async fetchByRef(ref) {
|
|
2018
|
+
const client = await this.clientFactory.getClient();
|
|
1840
2019
|
const integration = await this._findPrivateOrPublicIntegration(client, ref);
|
|
1841
2020
|
if (!integration) {
|
|
1842
2021
|
throw await this._buildIntegrationNotFoundError(client, ref);
|
|
1843
2022
|
}
|
|
1844
|
-
|
|
1845
|
-
const definition = integration;
|
|
1846
|
-
await this.cache.setDefinition(integration.id, integration.updatedAt, definition);
|
|
1847
|
-
return definition;
|
|
2023
|
+
return { id: integration.id, updatedAt: integration.updatedAt, definition: integration };
|
|
1848
2024
|
}
|
|
1849
|
-
async
|
|
1850
|
-
const client = await this.getClient();
|
|
2025
|
+
async search(query, limit = 20) {
|
|
2026
|
+
const client = await this.clientFactory.getClient();
|
|
1851
2027
|
const results = new Map;
|
|
1852
2028
|
const scanLimit = Math.max(limit * 5, 50);
|
|
1853
2029
|
for await (const integration of client.list.publicIntegrations({
|
|
@@ -1872,7 +2048,7 @@ class IntegrationManager {
|
|
|
1872
2048
|
return getSortedCatalogSearchResults(results, limit);
|
|
1873
2049
|
}
|
|
1874
2050
|
async findImplementersOfInterface(interfaceName, limit = 10) {
|
|
1875
|
-
const client = await this.getClient();
|
|
2051
|
+
const client = await this.clientFactory.getClient();
|
|
1876
2052
|
const seen = new Map;
|
|
1877
2053
|
for await (const integration of client.list.publicIntegrations({
|
|
1878
2054
|
interfaceName,
|
|
@@ -1888,8 +2064,8 @@ class IntegrationManager {
|
|
|
1888
2064
|
}
|
|
1889
2065
|
return [...seen.values()];
|
|
1890
2066
|
}
|
|
1891
|
-
async
|
|
1892
|
-
const client = await this.getClient();
|
|
2067
|
+
async listVersions(name) {
|
|
2068
|
+
const client = await this.clientFactory.getClient();
|
|
1893
2069
|
const versions = new Set;
|
|
1894
2070
|
for await (const integration of client.list.publicIntegrations({
|
|
1895
2071
|
name,
|
|
@@ -1953,7 +2129,7 @@ class IntegrationManager {
|
|
|
1953
2129
|
const scope = ref.workspace ? `workspace "${ref.workspace}"` : "the official Botpress hub";
|
|
1954
2130
|
return new AdkError({
|
|
1955
2131
|
code: "INTEGRATION_NOT_FOUND",
|
|
1956
|
-
message: `Integration "${ref.name}" version "${ref.version}" not found in ${scope} ` + `(latest is ${latestExists.version}). Run 'adk info ${ref.fullName}' to see available versions.`,
|
|
2132
|
+
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.`,
|
|
1957
2133
|
expected: true
|
|
1958
2134
|
});
|
|
1959
2135
|
}
|
|
@@ -1969,10 +2145,10 @@ class IntegrationManager {
|
|
|
1969
2145
|
let workspaceId;
|
|
1970
2146
|
try {
|
|
1971
2147
|
const credentials = await resolveWorkspaceCredentials({
|
|
1972
|
-
project: this.options.project,
|
|
1973
|
-
credentials: this.options.credentials,
|
|
1974
|
-
apiUrl: this.options.apiUrl,
|
|
1975
|
-
workspaceId: this.options.workspaceId
|
|
2148
|
+
project: this.clientFactory.options.project,
|
|
2149
|
+
credentials: this.clientFactory.options.credentials,
|
|
2150
|
+
apiUrl: this.clientFactory.options.apiUrl,
|
|
2151
|
+
workspaceId: this.clientFactory.options.workspaceId
|
|
1976
2152
|
});
|
|
1977
2153
|
workspaceId = credentials.workspaceId;
|
|
1978
2154
|
if (workspaceId) {
|
|
@@ -2000,6 +2176,96 @@ class IntegrationManager {
|
|
|
2000
2176
|
expected: true
|
|
2001
2177
|
});
|
|
2002
2178
|
}
|
|
2179
|
+
}
|
|
2180
|
+
function toHubCacheEntry(integration) {
|
|
2181
|
+
return {
|
|
2182
|
+
id: integration.id,
|
|
2183
|
+
name: integration.name,
|
|
2184
|
+
version: integration.version,
|
|
2185
|
+
updatedAt: integration.updatedAt,
|
|
2186
|
+
createdAt: integration.createdAt,
|
|
2187
|
+
title: integration.title,
|
|
2188
|
+
description: integration.description,
|
|
2189
|
+
iconUrl: integration.iconUrl,
|
|
2190
|
+
public: integration.public,
|
|
2191
|
+
visibility: integration.visibility,
|
|
2192
|
+
ownerWorkspace: integration.ownerWorkspace ? { id: integration.ownerWorkspace.id, name: integration.ownerWorkspace.name } : undefined,
|
|
2193
|
+
verificationStatus: integration.verificationStatus
|
|
2194
|
+
};
|
|
2195
|
+
}
|
|
2196
|
+
var init_integration_source = __esm(() => {
|
|
2197
|
+
init_src();
|
|
2198
|
+
init_auth();
|
|
2199
|
+
init_search_ranking();
|
|
2200
|
+
});
|
|
2201
|
+
|
|
2202
|
+
// src/integrations/manager.ts
|
|
2203
|
+
class IntegrationManager {
|
|
2204
|
+
source;
|
|
2205
|
+
service;
|
|
2206
|
+
constructor(options = {}) {
|
|
2207
|
+
const { noCache, ...clientOptions } = options;
|
|
2208
|
+
this.source = new IntegrationCatalogSource(new CatalogClientFactory(clientOptions));
|
|
2209
|
+
this.service = new CatalogService(this.source, noCache || false);
|
|
2210
|
+
}
|
|
2211
|
+
async loadIntegrations(dependencies) {
|
|
2212
|
+
const errors = [];
|
|
2213
|
+
const warnings = [];
|
|
2214
|
+
const parseResult = IntegrationParser.parseIntegrations(dependencies);
|
|
2215
|
+
const integrations = parseResult.integrations;
|
|
2216
|
+
errors.push(...parseResult.errors);
|
|
2217
|
+
const duplicateWarnings = IntegrationParser.checkDuplicates(integrations);
|
|
2218
|
+
warnings.push(...duplicateWarnings);
|
|
2219
|
+
const fetchPromises = integrations.map(async (integration) => {
|
|
2220
|
+
try {
|
|
2221
|
+
const definition = await this.fetchIntegration(integration.ref);
|
|
2222
|
+
integration.definition = definition;
|
|
2223
|
+
const validation = this.validateIntegration(integration);
|
|
2224
|
+
integration.validationResult = validation;
|
|
2225
|
+
if (!validation.valid) {
|
|
2226
|
+
validation.errors.forEach(() => {
|
|
2227
|
+
errors.push(ValidationErrors.unknownIntegration(integration.alias, integration.ref.fullName));
|
|
2228
|
+
});
|
|
2229
|
+
}
|
|
2230
|
+
if (validation.warnings.length > 0) {
|
|
2231
|
+
validation.warnings.forEach((warn) => {
|
|
2232
|
+
warnings.push(ValidationErrors.warning(warn, "agent.config.ts"));
|
|
2233
|
+
});
|
|
2234
|
+
}
|
|
2235
|
+
} catch (error) {
|
|
2236
|
+
if (error instanceof Error && error.message.includes("version")) {
|
|
2237
|
+
errors.push(ValidationErrors.integrationVersionError(integration.alias, error.message));
|
|
2238
|
+
} else {
|
|
2239
|
+
const errorMessage = error instanceof Error ? error.message : undefined;
|
|
2240
|
+
errors.push(ValidationErrors.unknownIntegration(integration.alias, integration.ref.fullName, errorMessage));
|
|
2241
|
+
}
|
|
2242
|
+
}
|
|
2243
|
+
});
|
|
2244
|
+
await Promise.all(fetchPromises);
|
|
2245
|
+
const hasChannels = integrations.some((i) => i.definition?.channels && Object.keys(i.definition.channels).length > 0);
|
|
2246
|
+
if (!hasChannels && integrations.length > 0) {
|
|
2247
|
+
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"));
|
|
2248
|
+
}
|
|
2249
|
+
return { integrations, errors, warnings };
|
|
2250
|
+
}
|
|
2251
|
+
async fetchIntegration(ref) {
|
|
2252
|
+
return this.service.getDefinition(ref);
|
|
2253
|
+
}
|
|
2254
|
+
async searchIntegrations(query, limit = 20) {
|
|
2255
|
+
return this.source.search(query, limit);
|
|
2256
|
+
}
|
|
2257
|
+
async findImplementersOfInterface(interfaceName, limit = 10) {
|
|
2258
|
+
return this.source.findImplementersOfInterface(interfaceName, limit);
|
|
2259
|
+
}
|
|
2260
|
+
async listIntegrationVersions(name) {
|
|
2261
|
+
return this.source.listVersions(name);
|
|
2262
|
+
}
|
|
2263
|
+
async getCacheStats() {
|
|
2264
|
+
return this.service.getCacheStats();
|
|
2265
|
+
}
|
|
2266
|
+
async clearCache() {
|
|
2267
|
+
await this.service.clearCache();
|
|
2268
|
+
}
|
|
2003
2269
|
validateIntegration(integration) {
|
|
2004
2270
|
const errors = [];
|
|
2005
2271
|
const warnings = [];
|
|
@@ -2029,40 +2295,13 @@ class IntegrationManager {
|
|
|
2029
2295
|
missingChannels: !hasChannels
|
|
2030
2296
|
};
|
|
2031
2297
|
}
|
|
2032
|
-
async getCacheStats() {
|
|
2033
|
-
const stats = await this.cache.getStats();
|
|
2034
|
-
return {
|
|
2035
|
-
count: stats.resolutions.count + stats.definitions.count,
|
|
2036
|
-
sizeBytes: stats.resolutions.sizeBytes + stats.definitions.sizeBytes
|
|
2037
|
-
};
|
|
2038
|
-
}
|
|
2039
|
-
async clearCache() {
|
|
2040
|
-
await this.cache.clear();
|
|
2041
|
-
}
|
|
2042
|
-
}
|
|
2043
|
-
function toHubCacheEntry(integration) {
|
|
2044
|
-
return {
|
|
2045
|
-
id: integration.id,
|
|
2046
|
-
name: integration.name,
|
|
2047
|
-
version: integration.version,
|
|
2048
|
-
updatedAt: integration.updatedAt,
|
|
2049
|
-
createdAt: integration.createdAt,
|
|
2050
|
-
title: integration.title,
|
|
2051
|
-
description: integration.description,
|
|
2052
|
-
iconUrl: integration.iconUrl,
|
|
2053
|
-
public: integration.public,
|
|
2054
|
-
visibility: integration.visibility,
|
|
2055
|
-
ownerWorkspace: integration.ownerWorkspace ? { id: integration.ownerWorkspace.id, name: integration.ownerWorkspace.name } : undefined,
|
|
2056
|
-
verificationStatus: integration.verificationStatus
|
|
2057
|
-
};
|
|
2058
2298
|
}
|
|
2059
2299
|
var init_manager = __esm(() => {
|
|
2060
|
-
init_src();
|
|
2061
|
-
init_auth();
|
|
2062
|
-
init_enhanced_cache();
|
|
2063
2300
|
init_dependencies_parser();
|
|
2064
2301
|
init_validation_errors();
|
|
2065
|
-
|
|
2302
|
+
init_client_factory();
|
|
2303
|
+
init_catalog_service();
|
|
2304
|
+
init_integration_source();
|
|
2066
2305
|
});
|
|
2067
2306
|
|
|
2068
2307
|
// src/assets/types.ts
|
|
@@ -2072,8 +2311,8 @@ var init_types3 = () => {};
|
|
|
2072
2311
|
var defaultAdkFolder = ".adk";
|
|
2073
2312
|
|
|
2074
2313
|
// src/assets/cache.ts
|
|
2075
|
-
import
|
|
2076
|
-
import
|
|
2314
|
+
import fs5 from "fs/promises";
|
|
2315
|
+
import path5 from "path";
|
|
2077
2316
|
|
|
2078
2317
|
class AssetsCacheManager {
|
|
2079
2318
|
projectPath;
|
|
@@ -2081,14 +2320,14 @@ class AssetsCacheManager {
|
|
|
2081
2320
|
cache = null;
|
|
2082
2321
|
constructor(projectPath) {
|
|
2083
2322
|
this.projectPath = projectPath;
|
|
2084
|
-
this.cachePath =
|
|
2323
|
+
this.cachePath = path5.join(projectPath, defaultAdkFolder, "assets-cache.json");
|
|
2085
2324
|
}
|
|
2086
2325
|
async load() {
|
|
2087
2326
|
if (this.cache) {
|
|
2088
2327
|
return this.cache;
|
|
2089
2328
|
}
|
|
2090
2329
|
try {
|
|
2091
|
-
const content = await
|
|
2330
|
+
const content = await fs5.readFile(this.cachePath, "utf-8");
|
|
2092
2331
|
this.cache = JSON.parse(content);
|
|
2093
2332
|
return this.cache;
|
|
2094
2333
|
} catch {
|
|
@@ -2103,9 +2342,9 @@ class AssetsCacheManager {
|
|
|
2103
2342
|
if (!this.cache) {
|
|
2104
2343
|
return;
|
|
2105
2344
|
}
|
|
2106
|
-
const cacheDir =
|
|
2107
|
-
await
|
|
2108
|
-
await
|
|
2345
|
+
const cacheDir = path5.dirname(this.cachePath);
|
|
2346
|
+
await fs5.mkdir(cacheDir, { recursive: true });
|
|
2347
|
+
await fs5.writeFile(this.cachePath, JSON.stringify(this.cache, null, 2), "utf-8");
|
|
2109
2348
|
}
|
|
2110
2349
|
async getEntry(assetPath) {
|
|
2111
2350
|
const cache = await this.load();
|
|
@@ -2148,8 +2387,8 @@ class AssetsCacheManager {
|
|
|
2148
2387
|
var init_cache = () => {};
|
|
2149
2388
|
|
|
2150
2389
|
// src/assets/manager.ts
|
|
2151
|
-
import
|
|
2152
|
-
import
|
|
2390
|
+
import fs6 from "fs/promises";
|
|
2391
|
+
import path6 from "path";
|
|
2153
2392
|
import crypto from "crypto";
|
|
2154
2393
|
|
|
2155
2394
|
class AssetsManager {
|
|
@@ -2157,11 +2396,13 @@ class AssetsManager {
|
|
|
2157
2396
|
assetsPath;
|
|
2158
2397
|
client;
|
|
2159
2398
|
botId;
|
|
2399
|
+
credentials;
|
|
2160
2400
|
cacheManager;
|
|
2161
2401
|
constructor(options) {
|
|
2162
2402
|
this.projectPath = options.projectPath;
|
|
2163
|
-
this.assetsPath =
|
|
2403
|
+
this.assetsPath = path6.join(this.projectPath, "assets");
|
|
2164
2404
|
this.botId = options.botId;
|
|
2405
|
+
this.credentials = options.credentials;
|
|
2165
2406
|
this.cacheManager = new AssetsCacheManager(this.projectPath);
|
|
2166
2407
|
}
|
|
2167
2408
|
async getClient() {
|
|
@@ -2176,6 +2417,7 @@ class AssetsManager {
|
|
|
2176
2417
|
}
|
|
2177
2418
|
this.client = await getProjectClient({
|
|
2178
2419
|
project: { path: this.projectPath },
|
|
2420
|
+
credentials: this.credentials,
|
|
2179
2421
|
botId: this.botId,
|
|
2180
2422
|
headers: {
|
|
2181
2423
|
"x-multiple-integrations": "true"
|
|
@@ -2196,7 +2438,7 @@ class AssetsManager {
|
|
|
2196
2438
|
}
|
|
2197
2439
|
async hasAssetsDirectory() {
|
|
2198
2440
|
try {
|
|
2199
|
-
const stats = await
|
|
2441
|
+
const stats = await fs6.stat(this.assetsPath);
|
|
2200
2442
|
return stats.isDirectory();
|
|
2201
2443
|
} catch {
|
|
2202
2444
|
return false;
|
|
@@ -2210,16 +2452,16 @@ class AssetsManager {
|
|
|
2210
2452
|
const assets = [];
|
|
2211
2453
|
for (const filePath of files) {
|
|
2212
2454
|
try {
|
|
2213
|
-
const stats = await
|
|
2455
|
+
const stats = await fs6.stat(filePath);
|
|
2214
2456
|
if (stats.isFile()) {
|
|
2215
|
-
const relativePath =
|
|
2216
|
-
const content = await
|
|
2457
|
+
const relativePath = path6.relative(this.assetsPath, filePath);
|
|
2458
|
+
const content = await fs6.readFile(filePath);
|
|
2217
2459
|
const hash = this.calculateHash(content);
|
|
2218
2460
|
const mime = this.getMimeType(filePath);
|
|
2219
2461
|
assets.push({
|
|
2220
2462
|
relativePath,
|
|
2221
2463
|
absolutePath: filePath,
|
|
2222
|
-
name:
|
|
2464
|
+
name: path6.basename(filePath),
|
|
2223
2465
|
size: stats.size,
|
|
2224
2466
|
mime,
|
|
2225
2467
|
hash,
|
|
@@ -2247,7 +2489,7 @@ class AssetsManager {
|
|
|
2247
2489
|
});
|
|
2248
2490
|
return response.files.map((file) => ({
|
|
2249
2491
|
path: file.tags?.path || file.key,
|
|
2250
|
-
name:
|
|
2492
|
+
name: path6.basename(file.tags?.path || file.key),
|
|
2251
2493
|
size: file.size || 0,
|
|
2252
2494
|
mime: file.contentType,
|
|
2253
2495
|
hash: file.tags?.hash || "",
|
|
@@ -2385,7 +2627,7 @@ class AssetsManager {
|
|
|
2385
2627
|
};
|
|
2386
2628
|
}
|
|
2387
2629
|
async uploadAsset(client, localFile) {
|
|
2388
|
-
const content = await
|
|
2630
|
+
const content = await fs6.readFile(localFile.absolutePath);
|
|
2389
2631
|
await client.uploadFile({
|
|
2390
2632
|
key: localFile.relativePath,
|
|
2391
2633
|
content,
|
|
@@ -2478,10 +2720,10 @@ declare global {
|
|
|
2478
2720
|
return enrichedAssets;
|
|
2479
2721
|
}
|
|
2480
2722
|
async scanDirectory(dir, files = []) {
|
|
2481
|
-
const items = await
|
|
2723
|
+
const items = await fs6.readdir(dir);
|
|
2482
2724
|
for (const item of items) {
|
|
2483
|
-
const fullPath =
|
|
2484
|
-
const stats = await
|
|
2725
|
+
const fullPath = path6.join(dir, item);
|
|
2726
|
+
const stats = await fs6.stat(fullPath);
|
|
2485
2727
|
if (stats.isDirectory()) {
|
|
2486
2728
|
await this.scanDirectory(fullPath, files);
|
|
2487
2729
|
} else {
|
|
@@ -2494,7 +2736,7 @@ declare global {
|
|
|
2494
2736
|
return crypto.createHash("sha256").update(content).digest("hex");
|
|
2495
2737
|
}
|
|
2496
2738
|
getMimeType(filePath) {
|
|
2497
|
-
const ext =
|
|
2739
|
+
const ext = path6.extname(filePath).toLowerCase();
|
|
2498
2740
|
const mimeTypes = {
|
|
2499
2741
|
".png": "image/png",
|
|
2500
2742
|
".jpg": "image/jpeg",
|
|
@@ -2528,12 +2770,12 @@ var init_manager2 = __esm(() => {
|
|
|
2528
2770
|
});
|
|
2529
2771
|
|
|
2530
2772
|
// src/utils/fs.ts
|
|
2531
|
-
import { mkdir, writeFile
|
|
2773
|
+
import { mkdir, writeFile } from "fs/promises";
|
|
2532
2774
|
import { parse } from "path";
|
|
2533
|
-
var createFile = async (
|
|
2534
|
-
const file = parse(
|
|
2775
|
+
var createFile = async (path7, content) => {
|
|
2776
|
+
const file = parse(path7);
|
|
2535
2777
|
await mkdir(file.dir, { recursive: true });
|
|
2536
|
-
await
|
|
2778
|
+
await writeFile(path7, content);
|
|
2537
2779
|
};
|
|
2538
2780
|
var init_fs = () => {};
|
|
2539
2781
|
|
|
@@ -2551,19 +2793,19 @@ var init_assets = __esm(() => {
|
|
|
2551
2793
|
});
|
|
2552
2794
|
|
|
2553
2795
|
// src/integrations/cache.ts
|
|
2554
|
-
import
|
|
2555
|
-
import
|
|
2556
|
-
import
|
|
2796
|
+
import fs7 from "fs/promises";
|
|
2797
|
+
import path7 from "path";
|
|
2798
|
+
import os4 from "os";
|
|
2557
2799
|
|
|
2558
2800
|
class IntegrationCache {
|
|
2559
2801
|
cacheDir;
|
|
2560
2802
|
integrationsDir;
|
|
2561
2803
|
constructor() {
|
|
2562
|
-
this.cacheDir =
|
|
2563
|
-
this.integrationsDir =
|
|
2804
|
+
this.cacheDir = path7.join(os4.homedir(), ".adk", "cache");
|
|
2805
|
+
this.integrationsDir = path7.join(this.cacheDir, "integrations");
|
|
2564
2806
|
}
|
|
2565
2807
|
async ensureCacheDir() {
|
|
2566
|
-
await
|
|
2808
|
+
await fs7.mkdir(this.integrationsDir, { recursive: true });
|
|
2567
2809
|
}
|
|
2568
2810
|
getCacheKey(integrationId, updatedAt) {
|
|
2569
2811
|
const sanitizedId = integrationId.replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
@@ -2573,8 +2815,8 @@ class IntegrationCache {
|
|
|
2573
2815
|
async get(integrationId, updatedAt) {
|
|
2574
2816
|
try {
|
|
2575
2817
|
const cacheKey = this.getCacheKey(integrationId, updatedAt);
|
|
2576
|
-
const cachePath =
|
|
2577
|
-
const data = await
|
|
2818
|
+
const cachePath = path7.join(this.integrationsDir, cacheKey);
|
|
2819
|
+
const data = await fs7.readFile(cachePath, "utf-8");
|
|
2578
2820
|
const cached = JSON.parse(data);
|
|
2579
2821
|
if (cached.expiresAt) {
|
|
2580
2822
|
const expiryDate = new Date(cached.expiresAt);
|
|
@@ -2591,7 +2833,7 @@ class IntegrationCache {
|
|
|
2591
2833
|
async set(integrationId, updatedAt, definition, ttlHours = 24 * 7) {
|
|
2592
2834
|
await this.ensureCacheDir();
|
|
2593
2835
|
const cacheKey = this.getCacheKey(integrationId, updatedAt);
|
|
2594
|
-
const cachePath =
|
|
2836
|
+
const cachePath = path7.join(this.integrationsDir, cacheKey);
|
|
2595
2837
|
const expiresAt = new Date;
|
|
2596
2838
|
expiresAt.setHours(expiresAt.getHours() + ttlHours);
|
|
2597
2839
|
const cacheEntry = {
|
|
@@ -2599,27 +2841,27 @@ class IntegrationCache {
|
|
|
2599
2841
|
cachedAt: new Date().toISOString(),
|
|
2600
2842
|
expiresAt: expiresAt.toISOString()
|
|
2601
2843
|
};
|
|
2602
|
-
await
|
|
2844
|
+
await fs7.writeFile(cachePath, JSON.stringify(cacheEntry, null, 2));
|
|
2603
2845
|
}
|
|
2604
2846
|
async remove(integrationId, updatedAt) {
|
|
2605
2847
|
try {
|
|
2606
2848
|
const cacheKey = this.getCacheKey(integrationId, updatedAt);
|
|
2607
|
-
const cachePath =
|
|
2608
|
-
await
|
|
2849
|
+
const cachePath = path7.join(this.integrationsDir, cacheKey);
|
|
2850
|
+
await fs7.unlink(cachePath);
|
|
2609
2851
|
} catch {}
|
|
2610
2852
|
}
|
|
2611
2853
|
async clear() {
|
|
2612
2854
|
try {
|
|
2613
|
-
const files = await
|
|
2614
|
-
await Promise.all(files.map((file) =>
|
|
2855
|
+
const files = await fs7.readdir(this.integrationsDir);
|
|
2856
|
+
await Promise.all(files.map((file) => fs7.unlink(path7.join(this.integrationsDir, file))));
|
|
2615
2857
|
} catch {}
|
|
2616
2858
|
}
|
|
2617
2859
|
async getStats() {
|
|
2618
2860
|
try {
|
|
2619
|
-
const files = await
|
|
2861
|
+
const files = await fs7.readdir(this.integrationsDir);
|
|
2620
2862
|
let totalSize = 0;
|
|
2621
2863
|
for (const file of files) {
|
|
2622
|
-
const stats = await
|
|
2864
|
+
const stats = await fs7.stat(path7.join(this.integrationsDir, file));
|
|
2623
2865
|
totalSize += stats.size;
|
|
2624
2866
|
}
|
|
2625
2867
|
return {
|
|
@@ -2633,171 +2875,6 @@ class IntegrationCache {
|
|
|
2633
2875
|
}
|
|
2634
2876
|
var init_cache2 = () => {};
|
|
2635
2877
|
|
|
2636
|
-
// src/integrations/hub-cache.ts
|
|
2637
|
-
import { Client as Client3 } from "@botpress/client";
|
|
2638
|
-
import * as fs10 from "fs/promises";
|
|
2639
|
-
import * as path10 from "path";
|
|
2640
|
-
import * as os6 from "os";
|
|
2641
|
-
var HubCache;
|
|
2642
|
-
var init_hub_cache = __esm(() => {
|
|
2643
|
-
init_src();
|
|
2644
|
-
init_auth();
|
|
2645
|
-
HubCache = class HubCache {
|
|
2646
|
-
static CACHE_FILE = "botpress-hub-cache.json";
|
|
2647
|
-
static CACHE_DIR = path10.join(os6.homedir(), ".adk", "cache");
|
|
2648
|
-
static CACHE_PATH = path10.join(HubCache.CACHE_DIR, HubCache.CACHE_FILE);
|
|
2649
|
-
static CACHE_DURATION = 30 * 60 * 1000;
|
|
2650
|
-
client;
|
|
2651
|
-
constructor() {}
|
|
2652
|
-
async getClient() {
|
|
2653
|
-
if (!this.client) {
|
|
2654
|
-
const credentials = await auth.getActiveCredentials();
|
|
2655
|
-
if (!credentials.workspaceId) {
|
|
2656
|
-
throw new AdkError({
|
|
2657
|
-
code: "WORKSPACE_ID_MISSING",
|
|
2658
|
-
message: 'No workspace ID found in current profile. Please login again with "adk login"',
|
|
2659
|
-
expected: true,
|
|
2660
|
-
suggestion: 'Please login again with "adk login".'
|
|
2661
|
-
});
|
|
2662
|
-
}
|
|
2663
|
-
this.client = new Client3({
|
|
2664
|
-
token: credentials.token,
|
|
2665
|
-
apiUrl: credentials.apiUrl,
|
|
2666
|
-
workspaceId: credentials.workspaceId,
|
|
2667
|
-
headers: {
|
|
2668
|
-
"x-multiple-integrations": "true"
|
|
2669
|
-
}
|
|
2670
|
-
});
|
|
2671
|
-
}
|
|
2672
|
-
return this.client;
|
|
2673
|
-
}
|
|
2674
|
-
async ensureCacheDir() {
|
|
2675
|
-
try {
|
|
2676
|
-
await fs10.mkdir(HubCache.CACHE_DIR, { recursive: true });
|
|
2677
|
-
} catch {}
|
|
2678
|
-
}
|
|
2679
|
-
async loadCache() {
|
|
2680
|
-
try {
|
|
2681
|
-
const data = await fs10.readFile(HubCache.CACHE_PATH, "utf-8");
|
|
2682
|
-
return JSON.parse(data);
|
|
2683
|
-
} catch {
|
|
2684
|
-
return null;
|
|
2685
|
-
}
|
|
2686
|
-
}
|
|
2687
|
-
async saveCache(data) {
|
|
2688
|
-
await this.ensureCacheDir();
|
|
2689
|
-
await fs10.writeFile(HubCache.CACHE_PATH, JSON.stringify(data, null, 2));
|
|
2690
|
-
}
|
|
2691
|
-
async needsRefresh() {
|
|
2692
|
-
const cache2 = await this.loadCache();
|
|
2693
|
-
if (!cache2)
|
|
2694
|
-
return true;
|
|
2695
|
-
const lastUpdated = new Date(cache2.lastUpdated);
|
|
2696
|
-
const now = new Date;
|
|
2697
|
-
const diff = now.getTime() - lastUpdated.getTime();
|
|
2698
|
-
return diff > HubCache.CACHE_DURATION;
|
|
2699
|
-
}
|
|
2700
|
-
async refresh(force = false) {
|
|
2701
|
-
if (!force && !await this.needsRefresh()) {
|
|
2702
|
-
return;
|
|
2703
|
-
}
|
|
2704
|
-
const client = await this.getClient();
|
|
2705
|
-
const cache2 = await this.loadCache();
|
|
2706
|
-
const latestByName = new Map;
|
|
2707
|
-
if (cache2) {
|
|
2708
|
-
for (const entry of cache2.integrations) {
|
|
2709
|
-
latestByName.set(entry.name, entry);
|
|
2710
|
-
}
|
|
2711
|
-
}
|
|
2712
|
-
try {
|
|
2713
|
-
for await (const integration of client.list.publicIntegrations({
|
|
2714
|
-
sortBy: "updatedAt",
|
|
2715
|
-
direction: "desc"
|
|
2716
|
-
})) {
|
|
2717
|
-
const existing = latestByName.get(integration.name);
|
|
2718
|
-
if (existing && integration.id === existing.id && integration.updatedAt === existing.updatedAt) {
|
|
2719
|
-
break;
|
|
2720
|
-
}
|
|
2721
|
-
if (!existing || integration.version.localeCompare(existing.version, undefined, {
|
|
2722
|
-
numeric: true
|
|
2723
|
-
}) > 0) {
|
|
2724
|
-
latestByName.set(integration.name, {
|
|
2725
|
-
id: integration.id,
|
|
2726
|
-
name: integration.name,
|
|
2727
|
-
version: integration.version,
|
|
2728
|
-
updatedAt: integration.updatedAt,
|
|
2729
|
-
createdAt: integration.createdAt,
|
|
2730
|
-
title: integration.title,
|
|
2731
|
-
description: integration.description,
|
|
2732
|
-
iconUrl: integration.iconUrl,
|
|
2733
|
-
public: integration.public,
|
|
2734
|
-
visibility: integration.visibility,
|
|
2735
|
-
ownerWorkspace: integration.ownerWorkspace ? {
|
|
2736
|
-
id: integration.ownerWorkspace.id,
|
|
2737
|
-
name: integration.ownerWorkspace.name
|
|
2738
|
-
} : undefined,
|
|
2739
|
-
verificationStatus: integration.verificationStatus
|
|
2740
|
-
});
|
|
2741
|
-
}
|
|
2742
|
-
}
|
|
2743
|
-
const integrations = Array.from(latestByName.values()).sort((a, b) => b.updatedAt.localeCompare(a.updatedAt));
|
|
2744
|
-
const newCache = {
|
|
2745
|
-
lastUpdated: new Date().toISOString(),
|
|
2746
|
-
integrations
|
|
2747
|
-
};
|
|
2748
|
-
await this.saveCache(newCache);
|
|
2749
|
-
} catch (error) {
|
|
2750
|
-
throw new AdkError({
|
|
2751
|
-
code: "HUB_CACHE_REFRESH_FAILED",
|
|
2752
|
-
message: `Failed to refresh hub cache: ${error instanceof Error ? error.message : String(error)}`,
|
|
2753
|
-
expected: true,
|
|
2754
|
-
cause: error
|
|
2755
|
-
});
|
|
2756
|
-
}
|
|
2757
|
-
}
|
|
2758
|
-
async getAllIntegrations() {
|
|
2759
|
-
await this.refresh();
|
|
2760
|
-
const cache2 = await this.loadCache();
|
|
2761
|
-
return cache2?.integrations || [];
|
|
2762
|
-
}
|
|
2763
|
-
async searchIntegrations(query) {
|
|
2764
|
-
const integrations = await this.getAllIntegrations();
|
|
2765
|
-
const lowerQuery = query.toLowerCase();
|
|
2766
|
-
return integrations.filter((integration) => integration.name.toLowerCase().includes(lowerQuery) || integration.title?.toLowerCase().includes(lowerQuery) || integration.description?.toLowerCase().includes(lowerQuery));
|
|
2767
|
-
}
|
|
2768
|
-
async getIntegrationByName(name) {
|
|
2769
|
-
const integrations = await this.getAllIntegrations();
|
|
2770
|
-
return integrations.find((i) => i.name === name) || null;
|
|
2771
|
-
}
|
|
2772
|
-
async getIntegrationVersions(name) {
|
|
2773
|
-
const integration = await this.getIntegrationByName(name);
|
|
2774
|
-
return integration ? [integration.version] : [];
|
|
2775
|
-
}
|
|
2776
|
-
async getStats() {
|
|
2777
|
-
const cache2 = await this.loadCache();
|
|
2778
|
-
try {
|
|
2779
|
-
const stats = await fs10.stat(HubCache.CACHE_PATH);
|
|
2780
|
-
return {
|
|
2781
|
-
lastUpdated: cache2 ? new Date(cache2.lastUpdated) : null,
|
|
2782
|
-
integrationCount: cache2?.integrations.length || 0,
|
|
2783
|
-
cacheSize: stats.size
|
|
2784
|
-
};
|
|
2785
|
-
} catch {
|
|
2786
|
-
return {
|
|
2787
|
-
lastUpdated: null,
|
|
2788
|
-
integrationCount: 0,
|
|
2789
|
-
cacheSize: 0
|
|
2790
|
-
};
|
|
2791
|
-
}
|
|
2792
|
-
}
|
|
2793
|
-
async clear() {
|
|
2794
|
-
try {
|
|
2795
|
-
await fs10.unlink(HubCache.CACHE_PATH);
|
|
2796
|
-
} catch {}
|
|
2797
|
-
}
|
|
2798
|
-
};
|
|
2799
|
-
});
|
|
2800
|
-
|
|
2801
2878
|
// src/integrations/config-utils.ts
|
|
2802
2879
|
function mergeIntegrationConfig(current, desired) {
|
|
2803
2880
|
if (desired === undefined) {
|
|
@@ -2809,7 +2886,7 @@ async function fetchServerIntegrationConfigs(project, targetBotId) {
|
|
|
2809
2886
|
const { devId, botId } = project.agentInfo ?? {};
|
|
2810
2887
|
const targetId = targetBotId || devId || botId;
|
|
2811
2888
|
if (!targetId) {
|
|
2812
|
-
return { configs: {}, enabledStates: {}, fetched: false, skipped: true };
|
|
2889
|
+
return { configs: {}, enabledStates: {}, authorizedStates: {}, fetched: false, skipped: true };
|
|
2813
2890
|
}
|
|
2814
2891
|
try {
|
|
2815
2892
|
const client = await getProjectClient({
|
|
@@ -2832,6 +2909,7 @@ async function fetchServerIntegrationConfigs(project, targetBotId) {
|
|
|
2832
2909
|
return {
|
|
2833
2910
|
configs: {},
|
|
2834
2911
|
enabledStates: {},
|
|
2912
|
+
authorizedStates: {},
|
|
2835
2913
|
fetched: false,
|
|
2836
2914
|
skipped: false,
|
|
2837
2915
|
error: message
|
|
@@ -2842,13 +2920,15 @@ async function fetchBotConfigs(client, botId) {
|
|
|
2842
2920
|
const { bot } = await client.getBot({ id: botId });
|
|
2843
2921
|
const configs = {};
|
|
2844
2922
|
const enabledStates = {};
|
|
2923
|
+
const authorizedStates = {};
|
|
2845
2924
|
for (const [alias, integration] of Object.entries(bot.integrations || {})) {
|
|
2846
2925
|
if (integration.configuration && Object.keys(integration.configuration).length > 0) {
|
|
2847
2926
|
configs[alias] = integration.configuration;
|
|
2848
2927
|
}
|
|
2849
2928
|
enabledStates[alias] = integration.enabled;
|
|
2929
|
+
authorizedStates[alias] = !!integration.identifier;
|
|
2850
2930
|
}
|
|
2851
|
-
return { configs, enabledStates, fetched: true, skipped: false };
|
|
2931
|
+
return { configs, enabledStates, authorizedStates, fetched: true, skipped: false };
|
|
2852
2932
|
}
|
|
2853
2933
|
async function fetchServerPluginConfigs(project, targetBotId) {
|
|
2854
2934
|
const { devId, botId } = project.agentInfo ?? {};
|
|
@@ -2895,122 +2975,9 @@ var init_integrations = __esm(() => {
|
|
|
2895
2975
|
init_manager();
|
|
2896
2976
|
init_dependencies_parser();
|
|
2897
2977
|
init_cache2();
|
|
2898
|
-
init_enhanced_cache();
|
|
2899
|
-
init_hub_cache();
|
|
2900
2978
|
init_config_utils();
|
|
2901
2979
|
});
|
|
2902
2980
|
|
|
2903
|
-
// src/interfaces/enhanced-cache.ts
|
|
2904
|
-
import fs11 from "fs/promises";
|
|
2905
|
-
import path11 from "path";
|
|
2906
|
-
import os7 from "os";
|
|
2907
|
-
|
|
2908
|
-
class EnhancedInterfaceCache {
|
|
2909
|
-
cacheDir;
|
|
2910
|
-
resolutionsDir;
|
|
2911
|
-
definitionsDir;
|
|
2912
|
-
noCache;
|
|
2913
|
-
constructor(noCache = false) {
|
|
2914
|
-
this.noCache = noCache;
|
|
2915
|
-
this.cacheDir = path11.join(os7.homedir(), ".adk", "cache", "interfaces");
|
|
2916
|
-
this.resolutionsDir = path11.join(this.cacheDir, "resolutions");
|
|
2917
|
-
this.definitionsDir = path11.join(this.cacheDir, "definitions");
|
|
2918
|
-
}
|
|
2919
|
-
async ensureCacheDirs() {
|
|
2920
|
-
await fs11.mkdir(this.resolutionsDir, { recursive: true });
|
|
2921
|
-
await fs11.mkdir(this.definitionsDir, { recursive: true });
|
|
2922
|
-
}
|
|
2923
|
-
async getResolution(name, version, workspace) {
|
|
2924
|
-
if (this.noCache)
|
|
2925
|
-
return null;
|
|
2926
|
-
try {
|
|
2927
|
-
const key = this.getResolutionKey(name, version, workspace);
|
|
2928
|
-
const cachePath = path11.join(this.resolutionsDir, `${key}.json`);
|
|
2929
|
-
const data = await fs11.readFile(cachePath, "utf-8");
|
|
2930
|
-
const resolution = JSON.parse(data);
|
|
2931
|
-
const cachedAt = new Date(resolution.cachedAt);
|
|
2932
|
-
const ageMinutes = (Date.now() - cachedAt.getTime()) / (1000 * 60);
|
|
2933
|
-
if (ageMinutes > 5)
|
|
2934
|
-
return null;
|
|
2935
|
-
return resolution;
|
|
2936
|
-
} catch {
|
|
2937
|
-
return null;
|
|
2938
|
-
}
|
|
2939
|
-
}
|
|
2940
|
-
async setResolution(name, version, workspace, interfaceId, updatedAt) {
|
|
2941
|
-
await this.ensureCacheDirs();
|
|
2942
|
-
const key = this.getResolutionKey(name, version, workspace);
|
|
2943
|
-
const cachePath = path11.join(this.resolutionsDir, `${key}.json`);
|
|
2944
|
-
const resolution = {
|
|
2945
|
-
interfaceId,
|
|
2946
|
-
updatedAt,
|
|
2947
|
-
cachedAt: new Date().toISOString()
|
|
2948
|
-
};
|
|
2949
|
-
await fs11.writeFile(cachePath, JSON.stringify(resolution));
|
|
2950
|
-
}
|
|
2951
|
-
async getDefinition(interfaceId, updatedAt) {
|
|
2952
|
-
if (this.noCache)
|
|
2953
|
-
return null;
|
|
2954
|
-
try {
|
|
2955
|
-
const key = this.getDefinitionKey(interfaceId, updatedAt);
|
|
2956
|
-
const cachePath = path11.join(this.definitionsDir, `${key}.json`);
|
|
2957
|
-
const data = await fs11.readFile(cachePath, "utf-8");
|
|
2958
|
-
const cached = JSON.parse(data);
|
|
2959
|
-
return cached.definition;
|
|
2960
|
-
} catch {
|
|
2961
|
-
return null;
|
|
2962
|
-
}
|
|
2963
|
-
}
|
|
2964
|
-
async setDefinition(interfaceId, updatedAt, definition) {
|
|
2965
|
-
await this.ensureCacheDirs();
|
|
2966
|
-
const key = this.getDefinitionKey(interfaceId, updatedAt);
|
|
2967
|
-
const cachePath = path11.join(this.definitionsDir, `${key}.json`);
|
|
2968
|
-
const cached = {
|
|
2969
|
-
definition,
|
|
2970
|
-
cachedAt: new Date().toISOString()
|
|
2971
|
-
};
|
|
2972
|
-
await fs11.writeFile(cachePath, JSON.stringify(cached));
|
|
2973
|
-
}
|
|
2974
|
-
async clear() {
|
|
2975
|
-
try {
|
|
2976
|
-
const resolutionFiles = await fs11.readdir(this.resolutionsDir);
|
|
2977
|
-
await Promise.all(resolutionFiles.map((f) => fs11.unlink(path11.join(this.resolutionsDir, f))));
|
|
2978
|
-
const definitionFiles = await fs11.readdir(this.definitionsDir);
|
|
2979
|
-
await Promise.all(definitionFiles.map((f) => fs11.unlink(path11.join(this.definitionsDir, f))));
|
|
2980
|
-
} catch {}
|
|
2981
|
-
}
|
|
2982
|
-
async getStats() {
|
|
2983
|
-
const getDirectoryStats = async (dir) => {
|
|
2984
|
-
try {
|
|
2985
|
-
const files = await fs11.readdir(dir);
|
|
2986
|
-
let totalSize = 0;
|
|
2987
|
-
for (const file of files) {
|
|
2988
|
-
const stats = await fs11.stat(path11.join(dir, file));
|
|
2989
|
-
totalSize += stats.size;
|
|
2990
|
-
}
|
|
2991
|
-
return { count: files.length, sizeBytes: totalSize };
|
|
2992
|
-
} catch {
|
|
2993
|
-
return { count: 0, sizeBytes: 0 };
|
|
2994
|
-
}
|
|
2995
|
-
};
|
|
2996
|
-
const [resolutions, definitions] = await Promise.all([
|
|
2997
|
-
getDirectoryStats(this.resolutionsDir),
|
|
2998
|
-
getDirectoryStats(this.definitionsDir)
|
|
2999
|
-
]);
|
|
3000
|
-
return { resolutions, definitions };
|
|
3001
|
-
}
|
|
3002
|
-
getResolutionKey(name, version, workspace) {
|
|
3003
|
-
const prefix = workspace ? `${workspace}_` : "";
|
|
3004
|
-
const key = `${prefix}${name}_${version}`;
|
|
3005
|
-
return key.replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
3006
|
-
}
|
|
3007
|
-
getDefinitionKey(interfaceId, updatedAt) {
|
|
3008
|
-
const key = `${interfaceId}_${updatedAt}`;
|
|
3009
|
-
return key.replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
3010
|
-
}
|
|
3011
|
-
}
|
|
3012
|
-
var init_enhanced_cache2 = () => {};
|
|
3013
|
-
|
|
3014
2981
|
// src/interfaces/parser.ts
|
|
3015
2982
|
class InterfaceParser {
|
|
3016
2983
|
static parseInterfaceRef(versionString) {
|
|
@@ -3035,90 +3002,39 @@ class InterfaceParser {
|
|
|
3035
3002
|
const errors = [];
|
|
3036
3003
|
for (const [alias, versionString] of Object.entries(BUILTIN_INTERFACES)) {
|
|
3037
3004
|
try {
|
|
3038
|
-
const ref = this.parseInterfaceRef(versionString);
|
|
3039
|
-
if (!this.isValidVersion(ref.version)) {
|
|
3040
|
-
errors.push(ValidationErrors.invalidVersionFormat(alias, ref.version));
|
|
3041
|
-
}
|
|
3042
|
-
interfaces.push({ alias, ref, config: undefined });
|
|
3043
|
-
} catch (error) {
|
|
3044
|
-
errors.push(ValidationErrors.invalidDependenciesSyntax(`Invalid interface '${alias}': ${error instanceof Error ? error.message : String(error)}`));
|
|
3045
|
-
}
|
|
3046
|
-
}
|
|
3047
|
-
return { interfaces, errors };
|
|
3048
|
-
}
|
|
3049
|
-
static isValidVersion(version) {
|
|
3050
|
-
if (version === "latest")
|
|
3051
|
-
return true;
|
|
3052
|
-
const semverPattern = /^(\d+)\.(\d+)\.(\d+)(-[\w.]+)?(\+[\w.]+)?$/;
|
|
3053
|
-
return semverPattern.test(version);
|
|
3054
|
-
}
|
|
3055
|
-
}
|
|
3056
|
-
var init_parser = __esm(() => {
|
|
3057
|
-
init_src();
|
|
3058
|
-
init_validation_errors();
|
|
3059
|
-
init_constants();
|
|
3060
|
-
});
|
|
3061
|
-
|
|
3062
|
-
// src/interfaces/manager.ts
|
|
3063
|
-
class InterfaceManager {
|
|
3064
|
-
cache;
|
|
3065
|
-
options;
|
|
3066
|
-
client;
|
|
3067
|
-
constructor(options = {}) {
|
|
3068
|
-
this.options = options;
|
|
3069
|
-
this.cache = new EnhancedInterfaceCache(options.noCache || false);
|
|
3070
|
-
}
|
|
3071
|
-
async getClient() {
|
|
3072
|
-
if (!this.client) {
|
|
3073
|
-
this.client = await getProjectClient({
|
|
3074
|
-
project: this.options.project,
|
|
3075
|
-
credentials: this.options.credentials,
|
|
3076
|
-
apiUrl: this.options.apiUrl,
|
|
3077
|
-
workspaceId: this.options.workspaceId,
|
|
3078
|
-
headers: {
|
|
3079
|
-
"x-multiple-integrations": "true"
|
|
3080
|
-
}
|
|
3081
|
-
});
|
|
3082
|
-
}
|
|
3083
|
-
return this.client;
|
|
3084
|
-
}
|
|
3085
|
-
async loadInterfaces(dependencies) {
|
|
3086
|
-
const errors = [];
|
|
3087
|
-
const warnings = [];
|
|
3088
|
-
const parseResult = InterfaceParser.parseInterfaces(dependencies);
|
|
3089
|
-
const interfaces = parseResult.interfaces;
|
|
3090
|
-
errors.push(...parseResult.errors);
|
|
3091
|
-
const fetchPromises = interfaces.map(async (intf) => {
|
|
3092
|
-
try {
|
|
3093
|
-
const definition = await this.fetchInterface(intf.ref);
|
|
3094
|
-
intf.definition = definition;
|
|
3095
|
-
const validation = this.validateInterface(intf);
|
|
3096
|
-
intf.validationResult = validation;
|
|
3097
|
-
if (!validation.valid) {
|
|
3098
|
-
validation.errors.forEach((msg) => {
|
|
3099
|
-
errors.push(ValidationErrors.warning(msg, "agent.config.ts"));
|
|
3100
|
-
});
|
|
3101
|
-
}
|
|
3102
|
-
} catch (error) {
|
|
3103
|
-
if (error instanceof Error && error.message.includes("version")) {
|
|
3104
|
-
errors.push(ValidationErrors.unknownInterface(error.message));
|
|
3105
|
-
} else {
|
|
3106
|
-
errors.push(ValidationErrors.invalidDependenciesSyntax(`Unknown interface '${intf.alias}' (${intf.ref.fullName})`));
|
|
3005
|
+
const ref = this.parseInterfaceRef(versionString);
|
|
3006
|
+
if (!this.isValidVersion(ref.version)) {
|
|
3007
|
+
errors.push(ValidationErrors.invalidVersionFormat(alias, ref.version));
|
|
3107
3008
|
}
|
|
3108
|
-
|
|
3109
|
-
|
|
3110
|
-
|
|
3111
|
-
return { interfaces, errors, warnings };
|
|
3112
|
-
}
|
|
3113
|
-
async fetchInterface(ref) {
|
|
3114
|
-
const cachedResolution = await this.cache.getResolution(ref.name, ref.version, ref.workspace);
|
|
3115
|
-
if (cachedResolution) {
|
|
3116
|
-
const cachedDefinition = await this.cache.getDefinition(cachedResolution.interfaceId, cachedResolution.updatedAt);
|
|
3117
|
-
if (cachedDefinition) {
|
|
3118
|
-
return cachedDefinition;
|
|
3009
|
+
interfaces.push({ alias, ref, config: undefined });
|
|
3010
|
+
} catch (error) {
|
|
3011
|
+
errors.push(ValidationErrors.invalidDependenciesSyntax(`Invalid interface '${alias}': ${error instanceof Error ? error.message : String(error)}`));
|
|
3119
3012
|
}
|
|
3120
3013
|
}
|
|
3121
|
-
|
|
3014
|
+
return { interfaces, errors };
|
|
3015
|
+
}
|
|
3016
|
+
static isValidVersion(version) {
|
|
3017
|
+
if (version === "latest")
|
|
3018
|
+
return true;
|
|
3019
|
+
const semverPattern = /^(\d+)\.(\d+)\.(\d+)(-[\w.]+)?(\+[\w.]+)?$/;
|
|
3020
|
+
return semverPattern.test(version);
|
|
3021
|
+
}
|
|
3022
|
+
}
|
|
3023
|
+
var init_parser = __esm(() => {
|
|
3024
|
+
init_src();
|
|
3025
|
+
init_validation_errors();
|
|
3026
|
+
init_constants();
|
|
3027
|
+
});
|
|
3028
|
+
|
|
3029
|
+
// src/dependencies/catalog/interface-source.ts
|
|
3030
|
+
class InterfaceCatalogSource {
|
|
3031
|
+
clientFactory;
|
|
3032
|
+
cacheConfig = { cacheType: "interfaces", idField: "interfaceId" };
|
|
3033
|
+
constructor(clientFactory) {
|
|
3034
|
+
this.clientFactory = clientFactory;
|
|
3035
|
+
}
|
|
3036
|
+
async fetchByRef(ref) {
|
|
3037
|
+
const client = await this.clientFactory.getClient();
|
|
3122
3038
|
let interfaceResponse;
|
|
3123
3039
|
let versionError = null;
|
|
3124
3040
|
try {
|
|
@@ -3162,32 +3078,56 @@ class InterfaceManager {
|
|
|
3162
3078
|
}
|
|
3163
3079
|
const location = ref.workspace ? `workspace "${ref.workspace}"` : "Botpress";
|
|
3164
3080
|
throw new AdkError({
|
|
3165
|
-
code: "
|
|
3081
|
+
code: "VERSION_NOT_FOUND",
|
|
3166
3082
|
message: `Interface "${ref.name}" version "${ref.version}" not found in ${location}. Latest available version is "${latestVersion}"`,
|
|
3167
3083
|
expected: true
|
|
3168
3084
|
});
|
|
3169
3085
|
}
|
|
3170
3086
|
const intf = interfaceResponse.interface;
|
|
3171
|
-
|
|
3172
|
-
await this.cache.setDefinition(intf.id, intf.updatedAt, intf);
|
|
3173
|
-
return intf;
|
|
3087
|
+
return { id: intf.id, updatedAt: intf.updatedAt, definition: intf };
|
|
3174
3088
|
}
|
|
3175
|
-
|
|
3176
|
-
|
|
3177
|
-
|
|
3178
|
-
|
|
3179
|
-
|
|
3180
|
-
|
|
3181
|
-
|
|
3182
|
-
|
|
3183
|
-
|
|
3184
|
-
const
|
|
3185
|
-
|
|
3186
|
-
|
|
3187
|
-
|
|
3188
|
-
|
|
3189
|
-
|
|
3089
|
+
}
|
|
3090
|
+
var init_interface_source = __esm(() => {
|
|
3091
|
+
init_src();
|
|
3092
|
+
});
|
|
3093
|
+
|
|
3094
|
+
// src/interfaces/manager.ts
|
|
3095
|
+
class InterfaceManager {
|
|
3096
|
+
service;
|
|
3097
|
+
constructor(options = {}) {
|
|
3098
|
+
const { noCache, ...clientOptions } = options;
|
|
3099
|
+
this.service = new CatalogService(new InterfaceCatalogSource(new CatalogClientFactory(clientOptions)), noCache || false);
|
|
3100
|
+
}
|
|
3101
|
+
async loadInterfaces(dependencies) {
|
|
3102
|
+
const errors = [];
|
|
3103
|
+
const warnings = [];
|
|
3104
|
+
const parseResult = InterfaceParser.parseInterfaces(dependencies);
|
|
3105
|
+
const interfaces = parseResult.interfaces;
|
|
3106
|
+
errors.push(...parseResult.errors);
|
|
3107
|
+
const fetchPromises = interfaces.map(async (intf) => {
|
|
3108
|
+
try {
|
|
3109
|
+
const definition = await this.fetchInterface(intf.ref);
|
|
3110
|
+
intf.definition = definition;
|
|
3111
|
+
const validation = this.validateInterface(intf);
|
|
3112
|
+
intf.validationResult = validation;
|
|
3113
|
+
if (!validation.valid) {
|
|
3114
|
+
validation.errors.forEach((msg) => {
|
|
3115
|
+
errors.push(ValidationErrors.warning(msg, "agent.config.ts"));
|
|
3116
|
+
});
|
|
3117
|
+
}
|
|
3118
|
+
} catch (error) {
|
|
3119
|
+
if (error instanceof Error && error.message.includes("version")) {
|
|
3120
|
+
errors.push(ValidationErrors.unknownInterface(error.message));
|
|
3121
|
+
} else {
|
|
3122
|
+
errors.push(ValidationErrors.invalidDependenciesSyntax(`Unknown interface '${intf.alias}' (${intf.ref.fullName})`));
|
|
3123
|
+
}
|
|
3124
|
+
}
|
|
3190
3125
|
});
|
|
3126
|
+
await Promise.all(fetchPromises);
|
|
3127
|
+
return { interfaces, errors, warnings };
|
|
3128
|
+
}
|
|
3129
|
+
async fetchInterface(ref) {
|
|
3130
|
+
return this.service.getDefinition(ref);
|
|
3191
3131
|
}
|
|
3192
3132
|
validateInterface(intf) {
|
|
3193
3133
|
const errors = [];
|
|
@@ -3199,28 +3139,56 @@ class InterfaceManager {
|
|
|
3199
3139
|
return { valid: errors.length === 0, errors, warnings };
|
|
3200
3140
|
}
|
|
3201
3141
|
async getCacheStats() {
|
|
3202
|
-
|
|
3203
|
-
return {
|
|
3204
|
-
count: stats.resolutions.count + stats.definitions.count,
|
|
3205
|
-
sizeBytes: stats.resolutions.sizeBytes + stats.definitions.sizeBytes
|
|
3206
|
-
};
|
|
3142
|
+
return this.service.getCacheStats();
|
|
3207
3143
|
}
|
|
3208
3144
|
async clearCache() {
|
|
3209
|
-
await this.
|
|
3145
|
+
await this.service.clearCache();
|
|
3210
3146
|
}
|
|
3211
3147
|
}
|
|
3212
3148
|
var init_manager3 = __esm(() => {
|
|
3213
|
-
init_src();
|
|
3214
|
-
init_auth();
|
|
3215
|
-
init_enhanced_cache2();
|
|
3216
3149
|
init_parser();
|
|
3217
3150
|
init_validation_errors();
|
|
3151
|
+
init_client_factory();
|
|
3152
|
+
init_catalog_service();
|
|
3153
|
+
init_interface_source();
|
|
3154
|
+
});
|
|
3155
|
+
|
|
3156
|
+
// src/interfaces/enhanced-cache.ts
|
|
3157
|
+
class EnhancedInterfaceCache {
|
|
3158
|
+
cache;
|
|
3159
|
+
constructor(noCache = false) {
|
|
3160
|
+
this.cache = new ResolutionCache({ cacheType: "interfaces", idField: "interfaceId" }, noCache);
|
|
3161
|
+
}
|
|
3162
|
+
async getResolution(name, version, workspace) {
|
|
3163
|
+
const resolution = await this.cache.getResolution(name, version, workspace);
|
|
3164
|
+
if (!resolution)
|
|
3165
|
+
return null;
|
|
3166
|
+
return { interfaceId: resolution.id, updatedAt: resolution.updatedAt, cachedAt: resolution.cachedAt };
|
|
3167
|
+
}
|
|
3168
|
+
async setResolution(name, version, workspace, interfaceId, updatedAt) {
|
|
3169
|
+
await this.cache.setResolution(name, version, workspace, interfaceId, updatedAt);
|
|
3170
|
+
}
|
|
3171
|
+
async getDefinition(interfaceId, updatedAt) {
|
|
3172
|
+
return this.cache.getDefinition(interfaceId, updatedAt);
|
|
3173
|
+
}
|
|
3174
|
+
async setDefinition(interfaceId, updatedAt, definition) {
|
|
3175
|
+
await this.cache.setDefinition(interfaceId, updatedAt, definition);
|
|
3176
|
+
}
|
|
3177
|
+
async clear() {
|
|
3178
|
+
await this.cache.clear();
|
|
3179
|
+
}
|
|
3180
|
+
async getStats() {
|
|
3181
|
+
return this.cache.getStats();
|
|
3182
|
+
}
|
|
3183
|
+
}
|
|
3184
|
+
var init_enhanced_cache = __esm(() => {
|
|
3185
|
+
init_resolution_cache();
|
|
3218
3186
|
});
|
|
3219
3187
|
// src/interfaces/index.ts
|
|
3220
3188
|
var init_interfaces = __esm(() => {
|
|
3221
3189
|
init_manager3();
|
|
3222
3190
|
init_parser();
|
|
3223
|
-
|
|
3191
|
+
init_enhanced_cache();
|
|
3224
3192
|
});
|
|
3225
3193
|
|
|
3226
3194
|
// src/utils/json-ordering.ts
|
|
@@ -3382,7 +3350,7 @@ var init_component_files = __esm(() => {
|
|
|
3382
3350
|
// src/agent-project/component-source-resolver.ts
|
|
3383
3351
|
import { Project, SyntaxKind } from "ts-morph";
|
|
3384
3352
|
import { readFileSync } from "fs";
|
|
3385
|
-
import * as
|
|
3353
|
+
import * as path8 from "path";
|
|
3386
3354
|
function resolveComponentSources(absolutePath) {
|
|
3387
3355
|
const project = new Project({ useInMemoryFileSystem: false, skipAddingFilesFromTsConfig: true });
|
|
3388
3356
|
const sourceFile = project.createSourceFile(absolutePath, readFileSync(absolutePath, "utf-8"), { overwrite: true });
|
|
@@ -3395,12 +3363,12 @@ function resolveComponentSources(absolutePath) {
|
|
|
3395
3363
|
}
|
|
3396
3364
|
function collectBpTsxImports(sourceFile, absolutePath) {
|
|
3397
3365
|
const imports = new Map;
|
|
3398
|
-
const dir =
|
|
3366
|
+
const dir = path8.dirname(absolutePath);
|
|
3399
3367
|
for (const decl of sourceFile.getImportDeclarations()) {
|
|
3400
3368
|
const specifier = decl.getModuleSpecifierValue();
|
|
3401
3369
|
if (!specifier.endsWith(BP_TSX_SUFFIX))
|
|
3402
3370
|
continue;
|
|
3403
|
-
const resolved =
|
|
3371
|
+
const resolved = path8.resolve(dir, specifier);
|
|
3404
3372
|
const defaultImport = decl.getDefaultImport();
|
|
3405
3373
|
if (defaultImport) {
|
|
3406
3374
|
imports.set(defaultImport.getText(), resolved);
|
|
@@ -3465,57 +3433,358 @@ function resolveExports(sourceFile, localToSource, importBindings) {
|
|
|
3465
3433
|
exportMap.set(exportName, source);
|
|
3466
3434
|
}
|
|
3467
3435
|
}
|
|
3468
|
-
return exportMap;
|
|
3469
|
-
}
|
|
3470
|
-
function sourceFromCustomComponentExpr(expr, importBindings) {
|
|
3471
|
-
if (expr.getKind() !== SyntaxKind.NewExpression)
|
|
3472
|
-
return;
|
|
3473
|
-
const newExpr = expr.asKindOrThrow(SyntaxKind.NewExpression);
|
|
3474
|
-
if (newExpr.getExpression().getText() !== CUSTOM_COMPONENT_CLASS)
|
|
3475
|
-
return;
|
|
3476
|
-
const args = newExpr.getArguments();
|
|
3477
|
-
const firstArg = args[0];
|
|
3478
|
-
if (!firstArg || firstArg.getKind() !== SyntaxKind.Identifier)
|
|
3479
|
-
return;
|
|
3480
|
-
return importBindings.get(firstArg.getText());
|
|
3481
|
-
}
|
|
3482
|
-
var CUSTOM_COMPONENT_CLASS = "CustomComponent";
|
|
3483
|
-
var init_component_source_resolver = __esm(() => {
|
|
3484
|
-
init_component_files();
|
|
3485
|
-
});
|
|
3486
|
-
|
|
3487
|
-
// src/bot-generator/table-validation.ts
|
|
3488
|
-
function getColumnCount(table) {
|
|
3489
|
-
const properties = table.definition.schema?.properties;
|
|
3490
|
-
return properties ? Object.keys(properties).length : 0;
|
|
3436
|
+
return exportMap;
|
|
3437
|
+
}
|
|
3438
|
+
function sourceFromCustomComponentExpr(expr, importBindings) {
|
|
3439
|
+
if (expr.getKind() !== SyntaxKind.NewExpression)
|
|
3440
|
+
return;
|
|
3441
|
+
const newExpr = expr.asKindOrThrow(SyntaxKind.NewExpression);
|
|
3442
|
+
if (newExpr.getExpression().getText() !== CUSTOM_COMPONENT_CLASS)
|
|
3443
|
+
return;
|
|
3444
|
+
const args = newExpr.getArguments();
|
|
3445
|
+
const firstArg = args[0];
|
|
3446
|
+
if (!firstArg || firstArg.getKind() !== SyntaxKind.Identifier)
|
|
3447
|
+
return;
|
|
3448
|
+
return importBindings.get(firstArg.getText());
|
|
3449
|
+
}
|
|
3450
|
+
var CUSTOM_COMPONENT_CLASS = "CustomComponent";
|
|
3451
|
+
var init_component_source_resolver = __esm(() => {
|
|
3452
|
+
init_component_files();
|
|
3453
|
+
});
|
|
3454
|
+
|
|
3455
|
+
// src/bot-generator/table-validation.ts
|
|
3456
|
+
function getColumnCount(table) {
|
|
3457
|
+
const properties = table.definition.schema?.properties;
|
|
3458
|
+
return properties ? Object.keys(properties).length : 0;
|
|
3459
|
+
}
|
|
3460
|
+
function findTableColumnViolations(tables, max = MAX_TABLE_COLUMNS) {
|
|
3461
|
+
return tables.map((table) => ({
|
|
3462
|
+
name: table.definition.name,
|
|
3463
|
+
path: table.path,
|
|
3464
|
+
columnCount: getColumnCount(table)
|
|
3465
|
+
})).filter((t) => t.columnCount > max);
|
|
3466
|
+
}
|
|
3467
|
+
var init_table_validation = __esm(() => {
|
|
3468
|
+
init_constants();
|
|
3469
|
+
});
|
|
3470
|
+
|
|
3471
|
+
// src/dependencies/alias-utils.ts
|
|
3472
|
+
function isBotpressInternalId(alias) {
|
|
3473
|
+
return BP_INTERNAL_ID_PREFIXES.some((prefix) => alias.startsWith(prefix));
|
|
3474
|
+
}
|
|
3475
|
+
function isFriendlyAlias(alias) {
|
|
3476
|
+
return FRIENDLY_ALIAS_RE.test(alias) && !isBotpressInternalId(alias);
|
|
3477
|
+
}
|
|
3478
|
+
function generateFriendlyAlias(cloudName, cloudAlias, used) {
|
|
3479
|
+
if (isFriendlyAlias(cloudAlias) && !used.has(cloudAlias))
|
|
3480
|
+
return cloudAlias;
|
|
3481
|
+
const base = cloudName?.split("/").at(-1) ?? cloudAlias;
|
|
3482
|
+
const sanitized = base.toLowerCase().replace(/[^a-z0-9_-]/g, "-");
|
|
3483
|
+
let candidate = sanitized;
|
|
3484
|
+
let n = 2;
|
|
3485
|
+
while (used.has(candidate)) {
|
|
3486
|
+
candidate = `${sanitized}-${n}`;
|
|
3487
|
+
n++;
|
|
3488
|
+
}
|
|
3489
|
+
return candidate;
|
|
3490
|
+
}
|
|
3491
|
+
var FRIENDLY_ALIAS_RE, BP_INTERNAL_ID_PREFIXES;
|
|
3492
|
+
var init_alias_utils = __esm(() => {
|
|
3493
|
+
FRIENDLY_ALIAS_RE = /^[a-z0-9_-]{2,100}$/;
|
|
3494
|
+
BP_INTERNAL_ID_PREFIXES = ["intver_", "plgver_", "int_", "plg_"];
|
|
3495
|
+
});
|
|
3496
|
+
|
|
3497
|
+
// src/dependencies/snapshot-store.ts
|
|
3498
|
+
import * as fs8 from "fs/promises";
|
|
3499
|
+
import * as path9 from "path";
|
|
3500
|
+
|
|
3501
|
+
class DependencySnapshotStore {
|
|
3502
|
+
projectPath;
|
|
3503
|
+
dirPath;
|
|
3504
|
+
constructor(opts) {
|
|
3505
|
+
this.projectPath = opts.projectPath;
|
|
3506
|
+
this.dirPath = path9.join(opts.projectPath, ".adk", "dependencies");
|
|
3507
|
+
}
|
|
3508
|
+
getSnapshotPath(env) {
|
|
3509
|
+
return path9.join(this.dirPath, `${env}.json`);
|
|
3510
|
+
}
|
|
3511
|
+
getMigrationMarkerPath() {
|
|
3512
|
+
return path9.join(this.dirPath, "migration.json");
|
|
3513
|
+
}
|
|
3514
|
+
async exists(env) {
|
|
3515
|
+
try {
|
|
3516
|
+
await fs8.access(this.getSnapshotPath(env));
|
|
3517
|
+
return true;
|
|
3518
|
+
} catch {
|
|
3519
|
+
return false;
|
|
3520
|
+
}
|
|
3521
|
+
}
|
|
3522
|
+
async read(env, options) {
|
|
3523
|
+
const filePath = this.getSnapshotPath(env);
|
|
3524
|
+
let raw;
|
|
3525
|
+
try {
|
|
3526
|
+
raw = await fs8.readFile(filePath, "utf8");
|
|
3527
|
+
} catch (err) {
|
|
3528
|
+
if (err.code === "ENOENT")
|
|
3529
|
+
return null;
|
|
3530
|
+
throw err;
|
|
3531
|
+
}
|
|
3532
|
+
try {
|
|
3533
|
+
return dependencySnapshotSchema.parse(JSON.parse(raw));
|
|
3534
|
+
} catch (err) {
|
|
3535
|
+
if (options?.tolerant)
|
|
3536
|
+
return null;
|
|
3537
|
+
throw new DependencyError({
|
|
3538
|
+
code: "INVALID_CONFIG",
|
|
3539
|
+
message: `Dependency snapshot at ${filePath} failed schema validation`,
|
|
3540
|
+
details: { issues: err.issues ?? String(err) }
|
|
3541
|
+
});
|
|
3542
|
+
}
|
|
3543
|
+
}
|
|
3544
|
+
async readOrEmpty(env, options) {
|
|
3545
|
+
const snapshot = await this.read(env, options);
|
|
3546
|
+
return snapshot ?? emptyDependencySnapshot(env, options?.botId, options?.fetchedAt);
|
|
3547
|
+
}
|
|
3548
|
+
async write(snapshot) {
|
|
3549
|
+
const validated = dependencySnapshotSchema.parse(snapshot);
|
|
3550
|
+
await fs8.mkdir(this.dirPath, { recursive: true });
|
|
3551
|
+
const filePath = this.getSnapshotPath(validated.env);
|
|
3552
|
+
const tmp = `${filePath}.tmp-${process.pid}-${Date.now()}`;
|
|
3553
|
+
await fs8.writeFile(tmp, JSON.stringify(sortKeysDeep(validated), null, 2) + `
|
|
3554
|
+
`, "utf8");
|
|
3555
|
+
await fs8.rename(tmp, filePath);
|
|
3556
|
+
}
|
|
3557
|
+
async delete(env) {
|
|
3558
|
+
try {
|
|
3559
|
+
await fs8.unlink(this.getSnapshotPath(env));
|
|
3560
|
+
} catch (err) {
|
|
3561
|
+
if (err.code !== "ENOENT")
|
|
3562
|
+
throw err;
|
|
3563
|
+
}
|
|
3564
|
+
}
|
|
3565
|
+
async hasMigrationMarker() {
|
|
3566
|
+
try {
|
|
3567
|
+
await fs8.access(this.getMigrationMarkerPath());
|
|
3568
|
+
return true;
|
|
3569
|
+
} catch {
|
|
3570
|
+
return false;
|
|
3571
|
+
}
|
|
3572
|
+
}
|
|
3573
|
+
async writeMigrationMarker(marker) {
|
|
3574
|
+
const validated = dependencyMigrationMarkerSchema.parse(marker);
|
|
3575
|
+
await fs8.mkdir(this.dirPath, { recursive: true });
|
|
3576
|
+
const filePath = this.getMigrationMarkerPath();
|
|
3577
|
+
const tmp = `${filePath}.tmp-${process.pid}-${Date.now()}`;
|
|
3578
|
+
await fs8.writeFile(tmp, JSON.stringify(sortKeysDeep(validated), null, 2) + `
|
|
3579
|
+
`, "utf8");
|
|
3580
|
+
await fs8.rename(tmp, filePath);
|
|
3581
|
+
}
|
|
3582
|
+
async refreshFromCloud(opts) {
|
|
3583
|
+
const previous = await this.readForRefresh(opts.env, opts.onWarning);
|
|
3584
|
+
const { bot } = await opts.client.getBot({ id: opts.botId });
|
|
3585
|
+
const snapshot = dependencySnapshotFromBot({
|
|
3586
|
+
bot,
|
|
3587
|
+
botId: opts.botId,
|
|
3588
|
+
env: opts.env,
|
|
3589
|
+
fetchedAt: opts.fetchedAt ?? new Date,
|
|
3590
|
+
previous
|
|
3591
|
+
});
|
|
3592
|
+
await annotateAuthorizationPending({
|
|
3593
|
+
snapshot,
|
|
3594
|
+
bot,
|
|
3595
|
+
integrationRegistry: opts.integrationRegistry
|
|
3596
|
+
});
|
|
3597
|
+
if (previous && cloudSnapshotUnchanged(previous, snapshot)) {
|
|
3598
|
+
return previous;
|
|
3599
|
+
}
|
|
3600
|
+
await this.write(snapshot);
|
|
3601
|
+
return snapshot;
|
|
3602
|
+
}
|
|
3603
|
+
async readForRefresh(env, onWarning) {
|
|
3604
|
+
try {
|
|
3605
|
+
return await this.read(env);
|
|
3606
|
+
} catch (err) {
|
|
3607
|
+
if (!(err instanceof DependencyError) || err.code !== "INVALID_CONFIG")
|
|
3608
|
+
throw err;
|
|
3609
|
+
const filePath = this.getSnapshotPath(env);
|
|
3610
|
+
await this.delete(env);
|
|
3611
|
+
onWarning?.({
|
|
3612
|
+
code: "SNAPSHOT_CORRUPT",
|
|
3613
|
+
message: `Removed corrupt dependency snapshot at ${filePath}; refreshing from Cloud.`,
|
|
3614
|
+
env,
|
|
3615
|
+
path: filePath
|
|
3616
|
+
});
|
|
3617
|
+
return null;
|
|
3618
|
+
}
|
|
3619
|
+
}
|
|
3620
|
+
}
|
|
3621
|
+
function emptyDependencySnapshot(env, botId = "local", fetchedAt = new Date(0)) {
|
|
3622
|
+
return {
|
|
3623
|
+
version: 1,
|
|
3624
|
+
env,
|
|
3625
|
+
botId,
|
|
3626
|
+
fetchedAt: fetchedAt.toISOString(),
|
|
3627
|
+
integrations: {},
|
|
3628
|
+
plugins: {}
|
|
3629
|
+
};
|
|
3630
|
+
}
|
|
3631
|
+
function cloudSnapshotUnchanged(previous, next) {
|
|
3632
|
+
if (previous.botId !== next.botId || previous.env !== next.env)
|
|
3633
|
+
return false;
|
|
3634
|
+
if (previous.botUpdatedAt !== next.botUpdatedAt)
|
|
3635
|
+
return false;
|
|
3636
|
+
return jsonEqual({ integrations: previous.integrations, plugins: previous.plugins }, { integrations: next.integrations, plugins: next.plugins });
|
|
3637
|
+
}
|
|
3638
|
+
async function annotateAuthorizationPending(opts) {
|
|
3639
|
+
const registry = opts.integrationRegistry;
|
|
3640
|
+
if (!registry)
|
|
3641
|
+
return;
|
|
3642
|
+
const cloudIntegrations = opts.bot.integrations ?? {};
|
|
3643
|
+
const specCache = new Map;
|
|
3644
|
+
const getSpec = (name, version) => {
|
|
3645
|
+
const key = `${name}@${version}`;
|
|
3646
|
+
const cached = specCache.get(key);
|
|
3647
|
+
if (cached)
|
|
3648
|
+
return cached;
|
|
3649
|
+
const promise = registry.getSpec(name, version).catch(() => null);
|
|
3650
|
+
specCache.set(key, promise);
|
|
3651
|
+
return promise;
|
|
3652
|
+
};
|
|
3653
|
+
await Promise.all(Object.entries(opts.snapshot.integrations).map(async ([alias, entry]) => {
|
|
3654
|
+
const cloudAlias = entry.cloudAlias ?? alias;
|
|
3655
|
+
const cloud = cloudIntegrations[cloudAlias];
|
|
3656
|
+
if (!cloud)
|
|
3657
|
+
return;
|
|
3658
|
+
if (cloud.identifier) {
|
|
3659
|
+
delete entry.authorizationPending;
|
|
3660
|
+
return;
|
|
3661
|
+
}
|
|
3662
|
+
const spec = await getSpec(entry.name, entry.version);
|
|
3663
|
+
if (!spec)
|
|
3664
|
+
return;
|
|
3665
|
+
const requiresAuthorization = integrationRequiresAuthorization(spec, entry.configurationType);
|
|
3666
|
+
if (requiresAuthorization) {
|
|
3667
|
+
entry.authorizationPending = true;
|
|
3668
|
+
} else {
|
|
3669
|
+
delete entry.authorizationPending;
|
|
3670
|
+
}
|
|
3671
|
+
}));
|
|
3672
|
+
}
|
|
3673
|
+
function dependencySnapshotFromBot(opts) {
|
|
3674
|
+
const integrations = {};
|
|
3675
|
+
const usedIntegrationAliases = new Set;
|
|
3676
|
+
for (const [cloudAlias, cloud] of Object.entries(opts.bot.integrations ?? {})) {
|
|
3677
|
+
const cloudName = typeof cloud.name === "string" ? cloud.name : undefined;
|
|
3678
|
+
const config = cloud.configuration ?? {};
|
|
3679
|
+
const version = cloud.version ?? "0.0.0";
|
|
3680
|
+
const configurationType = typeof cloud.configurationType === "string" && cloud.configurationType && cloud.configurationType !== "default" ? cloud.configurationType : undefined;
|
|
3681
|
+
const alias = chooseCloudAlias({
|
|
3682
|
+
cloudAlias,
|
|
3683
|
+
cloudName,
|
|
3684
|
+
previous: opts.previous?.integrations ?? {},
|
|
3685
|
+
used: usedIntegrationAliases,
|
|
3686
|
+
matches: (entry) => entry.version === version && entry.configurationType === configurationType && jsonEqual(entry.config, config)
|
|
3687
|
+
});
|
|
3688
|
+
usedIntegrationAliases.add(alias);
|
|
3689
|
+
const previousEntry = opts.previous?.integrations[alias];
|
|
3690
|
+
const previousMissingFields = previousEntry?.missingFields?.length && !cloud.enabled && previousEntry.version === version && previousEntry.configurationType === configurationType && jsonEqual(previousEntry.config, config) ? previousEntry.missingFields : undefined;
|
|
3691
|
+
integrations[alias] = {
|
|
3692
|
+
name: cloud.name ?? "",
|
|
3693
|
+
version,
|
|
3694
|
+
enabled: Boolean(cloud.enabled),
|
|
3695
|
+
config,
|
|
3696
|
+
...configurationType ? { configurationType } : {},
|
|
3697
|
+
...previousMissingFields ? { missingFields: previousMissingFields } : {},
|
|
3698
|
+
...!cloud.identifier && previousEntry?.authorizationPending ? { authorizationPending: true } : {},
|
|
3699
|
+
...typeof cloud.id === "string" ? { cloudId: cloud.id } : {},
|
|
3700
|
+
cloudAlias,
|
|
3701
|
+
...typeof cloud.updatedAt === "string" ? { updatedAt: cloud.updatedAt } : {}
|
|
3702
|
+
};
|
|
3703
|
+
}
|
|
3704
|
+
const plugins = {};
|
|
3705
|
+
const usedPluginAliases = new Set;
|
|
3706
|
+
for (const [cloudAlias, cloud] of Object.entries(opts.bot.plugins ?? {})) {
|
|
3707
|
+
const cloudName = typeof cloud.name === "string" ? cloud.name : undefined;
|
|
3708
|
+
const config = cloud.configuration ?? {};
|
|
3709
|
+
const version = cloud.version ?? "0.0.0";
|
|
3710
|
+
const dependencies = {};
|
|
3711
|
+
for (const [ifaceAlias, dep] of Object.entries(cloud.interfaces ?? {})) {
|
|
3712
|
+
if (typeof dep.integrationAlias === "string") {
|
|
3713
|
+
dependencies[ifaceAlias] = { integrationAlias: dep.integrationAlias };
|
|
3714
|
+
}
|
|
3715
|
+
}
|
|
3716
|
+
const alias = chooseCloudAlias({
|
|
3717
|
+
cloudAlias,
|
|
3718
|
+
cloudName,
|
|
3719
|
+
previous: opts.previous?.plugins ?? {},
|
|
3720
|
+
used: usedPluginAliases,
|
|
3721
|
+
matches: (entry) => entry.version === version && jsonEqual(entry.config, config)
|
|
3722
|
+
});
|
|
3723
|
+
usedPluginAliases.add(alias);
|
|
3724
|
+
const previousEntry = opts.previous?.plugins[alias];
|
|
3725
|
+
const previousMissingFields = previousEntry?.missingFields?.length && !(cloud.enabled ?? true) && previousEntry.version === version && jsonEqual(previousEntry.config, config) ? previousEntry.missingFields : undefined;
|
|
3726
|
+
plugins[alias] = {
|
|
3727
|
+
name: cloud.name ?? "",
|
|
3728
|
+
version,
|
|
3729
|
+
enabled: cloud.enabled ?? true,
|
|
3730
|
+
config,
|
|
3731
|
+
dependencies,
|
|
3732
|
+
...previousMissingFields ? { missingFields: previousMissingFields } : {},
|
|
3733
|
+
...typeof cloud.id === "string" ? { cloudId: cloud.id } : {},
|
|
3734
|
+
cloudAlias,
|
|
3735
|
+
...typeof cloud.updatedAt === "string" ? { updatedAt: cloud.updatedAt } : {}
|
|
3736
|
+
};
|
|
3737
|
+
}
|
|
3738
|
+
return {
|
|
3739
|
+
version: 1,
|
|
3740
|
+
env: opts.env,
|
|
3741
|
+
botId: opts.botId,
|
|
3742
|
+
fetchedAt: opts.fetchedAt.toISOString(),
|
|
3743
|
+
...typeof opts.bot.updatedAt === "string" ? { botUpdatedAt: opts.bot.updatedAt } : {},
|
|
3744
|
+
integrations,
|
|
3745
|
+
plugins
|
|
3746
|
+
};
|
|
3491
3747
|
}
|
|
3492
|
-
function
|
|
3493
|
-
|
|
3494
|
-
|
|
3495
|
-
|
|
3496
|
-
|
|
3497
|
-
|
|
3748
|
+
function chooseCloudAlias(opts) {
|
|
3749
|
+
if (isFriendlyAlias(opts.cloudAlias) && opts.previous[opts.cloudAlias] && !opts.used.has(opts.cloudAlias)) {
|
|
3750
|
+
return opts.cloudAlias;
|
|
3751
|
+
}
|
|
3752
|
+
if (opts.cloudName) {
|
|
3753
|
+
if (opts.matches) {
|
|
3754
|
+
const exactMatch = Object.entries(opts.previous).find(([alias, entry]) => !opts.used.has(alias) && entry.name === opts.cloudName && opts.matches(entry));
|
|
3755
|
+
if (exactMatch)
|
|
3756
|
+
return exactMatch[0];
|
|
3757
|
+
}
|
|
3758
|
+
const match = Object.entries(opts.previous).find(([alias, entry]) => !opts.used.has(alias) && entry.name === opts.cloudName);
|
|
3759
|
+
if (match)
|
|
3760
|
+
return match[0];
|
|
3761
|
+
}
|
|
3762
|
+
return generateFriendlyAlias(opts.cloudName, opts.cloudAlias, opts.used);
|
|
3498
3763
|
}
|
|
3499
|
-
var
|
|
3500
|
-
|
|
3764
|
+
var init_snapshot_store = __esm(() => {
|
|
3765
|
+
init_alias_utils();
|
|
3766
|
+
init_errors2();
|
|
3767
|
+
init_types();
|
|
3501
3768
|
});
|
|
3502
3769
|
|
|
3503
|
-
// src/agent-project/
|
|
3504
|
-
function
|
|
3770
|
+
// src/agent-project/dependency-state-to-dependencies.ts
|
|
3771
|
+
function dependencyStateToDependencies(state) {
|
|
3505
3772
|
const integrations = {};
|
|
3506
|
-
for (const [alias, entry] of Object.entries(
|
|
3773
|
+
for (const [alias, entry] of Object.entries(state.integrations)) {
|
|
3507
3774
|
integrations[alias] = {
|
|
3508
3775
|
version: `${entry.name}@${entry.version}`,
|
|
3509
3776
|
enabled: entry.enabled,
|
|
3510
|
-
config: entry.config
|
|
3777
|
+
config: entry.config,
|
|
3778
|
+
...entry.configurationType ? { configurationType: entry.configurationType } : {}
|
|
3511
3779
|
};
|
|
3512
3780
|
}
|
|
3513
3781
|
const plugins = {};
|
|
3514
|
-
for (const [alias, entry] of Object.entries(
|
|
3782
|
+
for (const [alias, entry] of Object.entries(state.plugins)) {
|
|
3515
3783
|
plugins[alias] = {
|
|
3516
3784
|
version: `${entry.name}@${entry.version}`,
|
|
3517
3785
|
config: entry.config,
|
|
3518
|
-
dependencies: entry.dependencies
|
|
3786
|
+
dependencies: entry.dependencies,
|
|
3787
|
+
...entry.missingFields !== undefined ? { missingFields: entry.missingFields } : {}
|
|
3519
3788
|
};
|
|
3520
3789
|
}
|
|
3521
3790
|
return { integrations, plugins };
|
|
@@ -3526,8 +3795,8 @@ import { BuiltInActions, BuiltInWorkflows, Errors as Errors2, Primitives as Prim
|
|
|
3526
3795
|
import { Autonomous } from "@botpress/runtime";
|
|
3527
3796
|
import createDebug from "debug";
|
|
3528
3797
|
import { createRequire as createRequire2 } from "module";
|
|
3529
|
-
import
|
|
3530
|
-
import
|
|
3798
|
+
import fs9 from "fs/promises";
|
|
3799
|
+
import path10 from "path";
|
|
3531
3800
|
function getToolDefinition(value) {
|
|
3532
3801
|
if (typeof value !== "object" || value === null) {
|
|
3533
3802
|
return;
|
|
@@ -3558,7 +3827,7 @@ var init_agent_project = __esm(() => {
|
|
|
3558
3827
|
init_validation_errors();
|
|
3559
3828
|
init_table_validation();
|
|
3560
3829
|
init_constants();
|
|
3561
|
-
|
|
3830
|
+
init_snapshot_store();
|
|
3562
3831
|
debug = createDebug("adk:agent-project");
|
|
3563
3832
|
AgentProject = class AgentProject {
|
|
3564
3833
|
static _projectCache = new Map;
|
|
@@ -3586,7 +3855,7 @@ var init_agent_project = __esm(() => {
|
|
|
3586
3855
|
_tools = [];
|
|
3587
3856
|
constructor(projectPath, options = {}) {
|
|
3588
3857
|
this._options = options;
|
|
3589
|
-
this._path =
|
|
3858
|
+
this._path = path10.resolve(projectPath);
|
|
3590
3859
|
this._integrationManager = new IntegrationManager({
|
|
3591
3860
|
noCache: options.noCache
|
|
3592
3861
|
});
|
|
@@ -3598,7 +3867,7 @@ var init_agent_project = __esm(() => {
|
|
|
3598
3867
|
});
|
|
3599
3868
|
}
|
|
3600
3869
|
static async load(projectPath, options = {}) {
|
|
3601
|
-
const resolvedPath =
|
|
3870
|
+
const resolvedPath = path10.resolve(projectPath);
|
|
3602
3871
|
if (!options.noCache) {
|
|
3603
3872
|
const cached = AgentProject._projectCache.get(resolvedPath);
|
|
3604
3873
|
if (cached) {
|
|
@@ -3616,7 +3885,7 @@ var init_agent_project = __esm(() => {
|
|
|
3616
3885
|
AgentProject._projectCache.clear();
|
|
3617
3886
|
}
|
|
3618
3887
|
static clearCacheForPath(projectPath) {
|
|
3619
|
-
const resolvedPath =
|
|
3888
|
+
const resolvedPath = path10.resolve(projectPath);
|
|
3620
3889
|
AgentProject._projectCache.delete(resolvedPath);
|
|
3621
3890
|
}
|
|
3622
3891
|
get path() {
|
|
@@ -3732,17 +4001,17 @@ var init_agent_project = __esm(() => {
|
|
|
3732
4001
|
const warnings = [];
|
|
3733
4002
|
const info = [];
|
|
3734
4003
|
try {
|
|
3735
|
-
await
|
|
4004
|
+
await fs9.access(this._path);
|
|
3736
4005
|
const requiredFiles = ["agent.config.ts"];
|
|
3737
4006
|
for (const file of requiredFiles) {
|
|
3738
4007
|
try {
|
|
3739
|
-
await
|
|
4008
|
+
await fs9.access(path10.join(this._path, file));
|
|
3740
4009
|
} catch {
|
|
3741
4010
|
errors.push(ValidationErrors.requiredFileMissing(file));
|
|
3742
4011
|
}
|
|
3743
4012
|
}
|
|
3744
4013
|
try {
|
|
3745
|
-
await
|
|
4014
|
+
await fs9.access(path10.join(this._path, "agent.json"));
|
|
3746
4015
|
} catch {
|
|
3747
4016
|
info.push({
|
|
3748
4017
|
$type: "ValidationError",
|
|
@@ -3756,7 +4025,7 @@ var init_agent_project = __esm(() => {
|
|
|
3756
4025
|
const expectedDirs = ["actions", "workflows", "conversations", "assets"];
|
|
3757
4026
|
for (const dir of expectedDirs) {
|
|
3758
4027
|
try {
|
|
3759
|
-
const stats = await
|
|
4028
|
+
const stats = await fs9.stat(path10.join(this._path, dir));
|
|
3760
4029
|
if (!stats.isDirectory()) {
|
|
3761
4030
|
warnings.push(ValidationErrors.invalidStructure(dir, "directory"));
|
|
3762
4031
|
}
|
|
@@ -3839,14 +4108,15 @@ var init_agent_project = __esm(() => {
|
|
|
3839
4108
|
return this._assetsManager;
|
|
3840
4109
|
}
|
|
3841
4110
|
async createAgentInfo(info) {
|
|
3842
|
-
const
|
|
3843
|
-
|
|
3844
|
-
|
|
3845
|
-
|
|
3846
|
-
|
|
3847
|
-
|
|
3848
|
-
|
|
3849
|
-
|
|
4111
|
+
const agentJsonData = {
|
|
4112
|
+
botId: info.botId,
|
|
4113
|
+
workspaceId: info.workspaceId,
|
|
4114
|
+
apiUrl: info.apiUrl
|
|
4115
|
+
};
|
|
4116
|
+
const agentPath = path10.join(this._path, "agent.json");
|
|
4117
|
+
const agentContent = stringifyWithOrder(agentJsonData, agentInfoKeyOrder);
|
|
4118
|
+
await fs9.writeFile(agentPath, agentContent);
|
|
4119
|
+
this._agentInfo = agentJsonData;
|
|
3850
4120
|
}
|
|
3851
4121
|
async updateAgentInfo(updates) {
|
|
3852
4122
|
if (!this._agentInfo) {
|
|
@@ -3856,27 +4126,32 @@ var init_agent_project = __esm(() => {
|
|
|
3856
4126
|
message: "No agent.json found. Use createAgentInfo() first."
|
|
3857
4127
|
});
|
|
3858
4128
|
}
|
|
3859
|
-
const
|
|
3860
|
-
|
|
3861
|
-
|
|
3862
|
-
|
|
4129
|
+
const updatedInfo = {
|
|
4130
|
+
botId: updates.botId ?? this._agentInfo.botId,
|
|
4131
|
+
workspaceId: updates.workspaceId ?? this._agentInfo.workspaceId,
|
|
4132
|
+
apiUrl: "apiUrl" in updates ? updates.apiUrl : this._agentInfo.apiUrl,
|
|
4133
|
+
...this._agentInfo.devId ? { devId: this._agentInfo.devId } : {}
|
|
4134
|
+
};
|
|
4135
|
+
const agentJsonData = {
|
|
4136
|
+
botId: updatedInfo.botId,
|
|
4137
|
+
workspaceId: updatedInfo.workspaceId,
|
|
4138
|
+
apiUrl: updatedInfo.apiUrl
|
|
4139
|
+
};
|
|
4140
|
+
const agentPath = path10.join(this._path, "agent.json");
|
|
3863
4141
|
const agentContent = stringifyWithOrder(agentJsonData, agentInfoKeyOrder);
|
|
3864
|
-
await
|
|
4142
|
+
await fs9.writeFile(agentPath, agentContent);
|
|
3865
4143
|
this._agentInfo = updatedInfo;
|
|
3866
|
-
if (devId !== undefined) {
|
|
3867
|
-
await this.updateAgentLocalInfo({ devId });
|
|
3868
|
-
}
|
|
3869
4144
|
}
|
|
3870
4145
|
async createAgentLocalInfo(info) {
|
|
3871
|
-
const localPath =
|
|
4146
|
+
const localPath = path10.join(this._path, "agent.local.json");
|
|
3872
4147
|
let existing = {};
|
|
3873
4148
|
try {
|
|
3874
|
-
const content2 = await
|
|
4149
|
+
const content2 = await fs9.readFile(localPath, "utf-8");
|
|
3875
4150
|
existing = JSON.parse(content2);
|
|
3876
4151
|
} catch {}
|
|
3877
4152
|
const merged = { ...existing, ...info };
|
|
3878
4153
|
const content = stringifyWithOrder(merged, agentLocalInfoKeyOrder);
|
|
3879
|
-
await
|
|
4154
|
+
await fs9.writeFile(localPath, content);
|
|
3880
4155
|
if (this._agentInfo) {
|
|
3881
4156
|
if (merged.botId)
|
|
3882
4157
|
this._agentInfo.botId = merged.botId;
|
|
@@ -3896,10 +4171,10 @@ var init_agent_project = __esm(() => {
|
|
|
3896
4171
|
}
|
|
3897
4172
|
}
|
|
3898
4173
|
async updateAgentLocalInfo(updates) {
|
|
3899
|
-
const localPath =
|
|
4174
|
+
const localPath = path10.join(this._path, "agent.local.json");
|
|
3900
4175
|
let existing = {};
|
|
3901
4176
|
try {
|
|
3902
|
-
const content = await
|
|
4177
|
+
const content = await fs9.readFile(localPath, "utf-8");
|
|
3903
4178
|
existing = JSON.parse(content);
|
|
3904
4179
|
} catch {}
|
|
3905
4180
|
const updated = { ...existing, ...updates };
|
|
@@ -3910,26 +4185,26 @@ var init_agent_project = __esm(() => {
|
|
|
3910
4185
|
}
|
|
3911
4186
|
if (Object.keys(updated).length === 0) {
|
|
3912
4187
|
try {
|
|
3913
|
-
await
|
|
4188
|
+
await fs9.unlink(localPath);
|
|
3914
4189
|
} catch {}
|
|
3915
4190
|
} else {
|
|
3916
4191
|
const content = stringifyWithOrder(updated, agentLocalInfoKeyOrder);
|
|
3917
|
-
await
|
|
4192
|
+
await fs9.writeFile(localPath, content);
|
|
3918
4193
|
}
|
|
3919
4194
|
if (this._agentInfo) {
|
|
3920
|
-
const agentJsonPath =
|
|
4195
|
+
const agentJsonPath = path10.join(this._path, "agent.json");
|
|
3921
4196
|
let base = {
|
|
3922
4197
|
botId: this._agentInfo.botId,
|
|
3923
4198
|
workspaceId: this._agentInfo.workspaceId,
|
|
3924
4199
|
apiUrl: this._agentInfo.apiUrl
|
|
3925
4200
|
};
|
|
3926
4201
|
try {
|
|
3927
|
-
const agentJsonContent = await
|
|
3928
|
-
const parsed = JSON.parse(agentJsonContent);
|
|
4202
|
+
const agentJsonContent = await fs9.readFile(agentJsonPath, "utf-8");
|
|
4203
|
+
const parsed = agentInfoSchema.parse(JSON.parse(agentJsonContent));
|
|
3929
4204
|
base = {
|
|
3930
|
-
botId: parsed.botId
|
|
3931
|
-
workspaceId: parsed.workspaceId
|
|
3932
|
-
apiUrl: parsed.apiUrl
|
|
4205
|
+
botId: parsed.botId,
|
|
4206
|
+
workspaceId: parsed.workspaceId,
|
|
4207
|
+
apiUrl: parsed.apiUrl
|
|
3933
4208
|
};
|
|
3934
4209
|
} catch {}
|
|
3935
4210
|
const local = updated;
|
|
@@ -3956,10 +4231,10 @@ var init_agent_project = __esm(() => {
|
|
|
3956
4231
|
this._integrations = [];
|
|
3957
4232
|
this._interfaces = [];
|
|
3958
4233
|
try {
|
|
3959
|
-
const configPath =
|
|
4234
|
+
const configPath = path10.join(this._path, "agent.config.ts");
|
|
3960
4235
|
debug("loading agent.config.ts from %s", configPath);
|
|
3961
|
-
const projectRequire = createRequire2(
|
|
3962
|
-
debug("created projectRequire from %s",
|
|
4236
|
+
const projectRequire = createRequire2(path10.join(this._path, "package.json"));
|
|
4237
|
+
debug("created projectRequire from %s", path10.join(this._path, "package.json"));
|
|
3963
4238
|
try {
|
|
3964
4239
|
const resolvedPath = projectRequire.resolve(configPath);
|
|
3965
4240
|
debug("resolved config path: %s", resolvedPath);
|
|
@@ -4003,49 +4278,29 @@ var init_agent_project = __esm(() => {
|
|
|
4003
4278
|
return;
|
|
4004
4279
|
}
|
|
4005
4280
|
this._config = configModule.default;
|
|
4006
|
-
const
|
|
4007
|
-
|
|
4281
|
+
const dependencyEnv = this._options.adkCommand === "adk-deploy" ? "prod" : "dev";
|
|
4282
|
+
const snapshotStore = new DependencySnapshotStore({ projectPath: this._path });
|
|
4283
|
+
let snapshotBasedDependencies;
|
|
4284
|
+
let dependencySnapshotReadFailed = false;
|
|
4008
4285
|
try {
|
|
4009
|
-
const
|
|
4010
|
-
const
|
|
4286
|
+
const snapshot = await snapshotStore.read(dependencyEnv);
|
|
4287
|
+
const state = snapshot ?? { version: 1, env: dependencyEnv, integrations: {}, plugins: {} };
|
|
4288
|
+
const hasDependencies = Object.keys(state.integrations).length > 0 || Object.keys(state.plugins).length > 0;
|
|
4011
4289
|
if (hasDependencies) {
|
|
4012
|
-
|
|
4290
|
+
snapshotBasedDependencies = dependencyStateToDependencies(state);
|
|
4013
4291
|
}
|
|
4014
4292
|
} catch (err) {
|
|
4015
4293
|
this._warnings.push({
|
|
4016
4294
|
$type: "ValidationError",
|
|
4017
4295
|
code: "INVALID_DEPENDENCIES_SCHEMA" /* INVALID_DEPENDENCIES_SCHEMA */,
|
|
4018
4296
|
severity: "warning" /* WARNING */,
|
|
4019
|
-
message: `Could not read dependencies.
|
|
4020
|
-
file:
|
|
4297
|
+
message: `Could not read .adk/dependencies/${dependencyEnv}.json: ${err.message}. Refresh dependencies from Cloud; agent.config.ts dependencies is not used when a snapshot exists but is invalid.`,
|
|
4298
|
+
file: `.adk/dependencies/${dependencyEnv}.json`
|
|
4021
4299
|
});
|
|
4300
|
+
dependencySnapshotReadFailed = true;
|
|
4022
4301
|
}
|
|
4023
|
-
|
|
4024
|
-
|
|
4025
|
-
if (!lockBasedDependencies && config.dependencies) {
|
|
4026
|
-
const validationResult = dependenciesSchema.safeParse(config.dependencies);
|
|
4027
|
-
if (!validationResult.success) {
|
|
4028
|
-
const errors = validationResult.error.errors;
|
|
4029
|
-
for (const error of errors) {
|
|
4030
|
-
this._errors.push({
|
|
4031
|
-
$type: "ValidationError",
|
|
4032
|
-
code: "INVALID_DEPENDENCIES_SCHEMA" /* INVALID_DEPENDENCIES_SCHEMA */,
|
|
4033
|
-
severity: "error" /* ERROR */,
|
|
4034
|
-
message: `Invalid dependencies in agent.config.ts: ${error.path.join(".")} - ${error.message}`,
|
|
4035
|
-
file: "agent.config.ts",
|
|
4036
|
-
hint: error.code === "invalid_type" ? `Expected ${error.expected}, but got ${error.received}` : undefined
|
|
4037
|
-
});
|
|
4038
|
-
}
|
|
4039
|
-
this._dependencies = { integrations: {} };
|
|
4040
|
-
this._integrations = [];
|
|
4041
|
-
this._interfaces = [];
|
|
4042
|
-
return;
|
|
4043
|
-
}
|
|
4044
|
-
configBasedDependencies = validationResult.data;
|
|
4045
|
-
}
|
|
4046
|
-
const depsToLoad = lockBasedDependencies ?? configBasedDependencies;
|
|
4047
|
-
if (depsToLoad) {
|
|
4048
|
-
this._dependencies = depsToLoad;
|
|
4302
|
+
if (snapshotBasedDependencies) {
|
|
4303
|
+
this._dependencies = snapshotBasedDependencies;
|
|
4049
4304
|
if (!this._options.offline) {
|
|
4050
4305
|
const [intRes, ifRes] = await Promise.all([
|
|
4051
4306
|
this._integrationManager.loadIntegrations(this._dependencies),
|
|
@@ -4156,8 +4411,8 @@ ${err.stack?.split(`
|
|
|
4156
4411
|
}
|
|
4157
4412
|
}
|
|
4158
4413
|
isBarrelReexport(existing, newPath, newExport, newDefinition) {
|
|
4159
|
-
const isNewBarrel = /^index\.[tj]s$/i.test(
|
|
4160
|
-
const isExistingBarrel = /^index\.[tj]s$/i.test(
|
|
4414
|
+
const isNewBarrel = /^index\.[tj]s$/i.test(path10.basename(newPath));
|
|
4415
|
+
const isExistingBarrel = /^index\.[tj]s$/i.test(path10.basename(existing.path));
|
|
4161
4416
|
if (!isNewBarrel && !isExistingBarrel) {
|
|
4162
4417
|
return false;
|
|
4163
4418
|
}
|
|
@@ -4169,16 +4424,16 @@ ${err.stack?.split(`
|
|
|
4169
4424
|
return true;
|
|
4170
4425
|
}
|
|
4171
4426
|
isToolBarrelReexport(existingPath, newPath) {
|
|
4172
|
-
const isNewBarrel = /^index\.[tj]s$/i.test(
|
|
4173
|
-
const isExistingBarrel = /^index\.[tj]s$/i.test(
|
|
4427
|
+
const isNewBarrel = /^index\.[tj]s$/i.test(path10.basename(newPath));
|
|
4428
|
+
const isExistingBarrel = /^index\.[tj]s$/i.test(path10.basename(existingPath));
|
|
4174
4429
|
if (!isNewBarrel && !isExistingBarrel) {
|
|
4175
4430
|
return false;
|
|
4176
4431
|
}
|
|
4177
4432
|
return true;
|
|
4178
4433
|
}
|
|
4179
4434
|
shouldPreferToolDefinition(existingPath, newPath) {
|
|
4180
|
-
const isNewBarrel = /^index\.[tj]s$/i.test(
|
|
4181
|
-
const isExistingBarrel = /^index\.[tj]s$/i.test(
|
|
4435
|
+
const isNewBarrel = /^index\.[tj]s$/i.test(path10.basename(newPath));
|
|
4436
|
+
const isExistingBarrel = /^index\.[tj]s$/i.test(path10.basename(existingPath));
|
|
4182
4437
|
return isExistingBarrel && !isNewBarrel;
|
|
4183
4438
|
}
|
|
4184
4439
|
getChannelsList(channelSpec) {
|
|
@@ -4194,8 +4449,8 @@ ${err.stack?.split(`
|
|
|
4194
4449
|
if (this._options.adkCommand) {
|
|
4195
4450
|
setAdkCommand(this._options.adkCommand);
|
|
4196
4451
|
}
|
|
4197
|
-
const src =
|
|
4198
|
-
if (!await
|
|
4452
|
+
const src = path10.join(this._path, "src");
|
|
4453
|
+
if (!await fs9.stat(src).catch(() => false)) {
|
|
4199
4454
|
this._errors.push({
|
|
4200
4455
|
$type: "ValidationError",
|
|
4201
4456
|
code: "INVALID_STRUCTURE" /* INVALID_STRUCTURE */,
|
|
@@ -4204,14 +4459,14 @@ ${err.stack?.split(`
|
|
|
4204
4459
|
});
|
|
4205
4460
|
return;
|
|
4206
4461
|
}
|
|
4207
|
-
const allFiles = await
|
|
4462
|
+
const allFiles = await fs9.readdir(src, {
|
|
4208
4463
|
withFileTypes: true,
|
|
4209
4464
|
recursive: true
|
|
4210
4465
|
});
|
|
4211
4466
|
for (const file of allFiles.filter((x) => x.isFile())) {
|
|
4212
4467
|
const filename = file.name;
|
|
4213
|
-
const absolutePath =
|
|
4214
|
-
const relPath =
|
|
4468
|
+
const absolutePath = path10.join(file.parentPath, file.name);
|
|
4469
|
+
const relPath = path10.relative(this.path, absolutePath);
|
|
4215
4470
|
if (filename.toLowerCase().endsWith(".d.ts")) {
|
|
4216
4471
|
continue;
|
|
4217
4472
|
}
|
|
@@ -4498,7 +4753,7 @@ ${err.stack?.split(`
|
|
|
4498
4753
|
});
|
|
4499
4754
|
|
|
4500
4755
|
// src/generators/utils.ts
|
|
4501
|
-
import
|
|
4756
|
+
import path13 from "path";
|
|
4502
4757
|
async function getFormat() {
|
|
4503
4758
|
if (!_formatLoaded) {
|
|
4504
4759
|
_formatLoaded = true;
|
|
@@ -4546,9 +4801,9 @@ var _format = null, _formatLoaded = false, formatCode = async (code, filepath) =
|
|
|
4546
4801
|
`));
|
|
4547
4802
|
return code;
|
|
4548
4803
|
}
|
|
4549
|
-
}, ADK_VERSION = "
|
|
4550
|
-
const fromDir =
|
|
4551
|
-
const relative2 =
|
|
4804
|
+
}, ADK_VERSION = "2.0.0-alpha.0", relative = (from, to) => {
|
|
4805
|
+
const fromDir = path13.dirname(from);
|
|
4806
|
+
const relative2 = path13.relative(fromDir, to);
|
|
4552
4807
|
return relative2.startsWith(".") ? relative2 : `./${relative2}`;
|
|
4553
4808
|
};
|
|
4554
4809
|
var init_utils = () => {};
|
|
@@ -4557,14 +4812,22 @@ var init_utils = () => {};
|
|
|
4557
4812
|
var exports_dependencies = {};
|
|
4558
4813
|
__export(exports_dependencies, {
|
|
4559
4814
|
sortKeysDeep: () => sortKeysDeep,
|
|
4815
|
+
resolveDependencyStatuses: () => resolveDependencyStatuses,
|
|
4560
4816
|
migrateFromConfig: () => migrateFromConfig,
|
|
4561
4817
|
jsonEqual: () => jsonEqual,
|
|
4818
|
+
isCallable: () => isCallable,
|
|
4819
|
+
emptyDependencySnapshot: () => emptyDependencySnapshot,
|
|
4820
|
+
dependencyStateSchema: () => dependencyStateSchema,
|
|
4821
|
+
dependencySnapshotFromBot: () => dependencySnapshotFromBot,
|
|
4822
|
+
computePluginStatus: () => computePluginStatus,
|
|
4823
|
+
computeIntegrationStatus: () => computeIntegrationStatus,
|
|
4562
4824
|
PluginResolver: () => PluginResolver,
|
|
4563
4825
|
PluginRegistry: () => PluginRegistry,
|
|
4564
|
-
LockFile: () => LockFile,
|
|
4565
4826
|
InterfaceRegistry: () => InterfaceRegistry,
|
|
4566
4827
|
IntegrationResolver: () => IntegrationResolver,
|
|
4567
4828
|
IntegrationRegistry: () => IntegrationRegistry,
|
|
4829
|
+
DependencySnapshotStore: () => DependencySnapshotStore,
|
|
4830
|
+
DependencyMigrationManager: () => DependencyMigrationManager,
|
|
4568
4831
|
DependencyManager: () => DependencyManager,
|
|
4569
4832
|
DependencyError: () => DependencyError,
|
|
4570
4833
|
DEPENDENCY_WARNING_CODES: () => DEPENDENCY_WARNING_CODES,
|
|
@@ -4572,34 +4835,10 @@ __export(exports_dependencies, {
|
|
|
4572
4835
|
});
|
|
4573
4836
|
|
|
4574
4837
|
// src/dependencies/dependency-manager.ts
|
|
4575
|
-
|
|
4576
|
-
import * as semver2 from "semver";
|
|
4577
|
-
|
|
4578
|
-
// src/dependencies/alias-utils.ts
|
|
4579
|
-
var FRIENDLY_ALIAS_RE = /^[a-z0-9_-]{2,100}$/;
|
|
4580
|
-
var BP_INTERNAL_ID_PREFIXES = ["intver_", "plgver_", "int_", "plg_"];
|
|
4581
|
-
function isBotpressInternalId(alias) {
|
|
4582
|
-
return BP_INTERNAL_ID_PREFIXES.some((prefix) => alias.startsWith(prefix));
|
|
4583
|
-
}
|
|
4584
|
-
function isFriendlyAlias(alias) {
|
|
4585
|
-
return FRIENDLY_ALIAS_RE.test(alias) && !isBotpressInternalId(alias);
|
|
4586
|
-
}
|
|
4587
|
-
function generateFriendlyAlias(cloudName, cloudAlias, used) {
|
|
4588
|
-
if (isFriendlyAlias(cloudAlias) && !used.has(cloudAlias))
|
|
4589
|
-
return cloudAlias;
|
|
4590
|
-
const base = cloudName?.split("/").at(-1) ?? cloudAlias;
|
|
4591
|
-
const sanitized = base.toLowerCase().replace(/[^a-z0-9_-]/g, "-");
|
|
4592
|
-
let candidate = sanitized;
|
|
4593
|
-
let n = 2;
|
|
4594
|
-
while (used.has(candidate)) {
|
|
4595
|
-
candidate = `${sanitized}-${n}`;
|
|
4596
|
-
n++;
|
|
4597
|
-
}
|
|
4598
|
-
return candidate;
|
|
4599
|
-
}
|
|
4600
|
-
|
|
4601
|
-
// src/dependencies/dependency-manager.ts
|
|
4838
|
+
init_types();
|
|
4602
4839
|
init_errors2();
|
|
4840
|
+
import * as semver2 from "semver";
|
|
4841
|
+
import { extractMissingRequiredFields } from "@botpress/runtime";
|
|
4603
4842
|
|
|
4604
4843
|
// src/dependencies/resolvers/integration-resolver.ts
|
|
4605
4844
|
init_errors2();
|
|
@@ -4611,13 +4850,17 @@ class IntegrationResolver {
|
|
|
4611
4850
|
this.registry = opts.registry;
|
|
4612
4851
|
this.client = opts.client;
|
|
4613
4852
|
}
|
|
4614
|
-
|
|
4615
|
-
|
|
4853
|
+
toDependencyEntry(cloud) {
|
|
4854
|
+
const entry = {
|
|
4616
4855
|
name: cloud.name ?? "",
|
|
4617
4856
|
version: cloud.version ?? "0.0.0",
|
|
4618
4857
|
enabled: Boolean(cloud.enabled),
|
|
4619
4858
|
config: cloud.configuration ?? {}
|
|
4620
4859
|
};
|
|
4860
|
+
if (typeof cloud.configurationType === "string" && cloud.configurationType && cloud.configurationType !== "default") {
|
|
4861
|
+
entry.configurationType = cloud.configurationType;
|
|
4862
|
+
}
|
|
4863
|
+
return entry;
|
|
4621
4864
|
}
|
|
4622
4865
|
async applyToCloud(opts) {
|
|
4623
4866
|
const spec = await this.registry.getSpec(opts.entry.name, opts.entry.version);
|
|
@@ -4659,7 +4902,7 @@ class PluginResolver {
|
|
|
4659
4902
|
this.integrationRegistry = opts.integrationRegistry;
|
|
4660
4903
|
this.client = opts.client;
|
|
4661
4904
|
}
|
|
4662
|
-
|
|
4905
|
+
toDependencyEntry(cloud) {
|
|
4663
4906
|
const dependencies = {};
|
|
4664
4907
|
for (const [ifaceAlias, dep] of Object.entries(cloud.interfaces ?? {})) {
|
|
4665
4908
|
if (dep.integrationAlias) {
|
|
@@ -4687,7 +4930,7 @@ class PluginResolver {
|
|
|
4687
4930
|
details: { plugin: opts.alias, pluginInterfaceAlias: pluginIfaceAlias, interfaceName: requirement.name }
|
|
4688
4931
|
});
|
|
4689
4932
|
}
|
|
4690
|
-
const integration = opts.
|
|
4933
|
+
const integration = opts.state.integrations[dep.integrationAlias];
|
|
4691
4934
|
if (!integration) {
|
|
4692
4935
|
throw new DependencyError({
|
|
4693
4936
|
code: "MISSING_DEPENDENCY",
|
|
@@ -4762,213 +5005,59 @@ class IntegrationRegistry {
|
|
|
4762
5005
|
}
|
|
4763
5006
|
}
|
|
4764
5007
|
|
|
4765
|
-
// src/plugins/manager.ts
|
|
4766
|
-
init_src();
|
|
4767
|
-
init_auth();
|
|
4768
|
-
|
|
4769
|
-
// src/plugins/enhanced-cache.ts
|
|
4770
|
-
import fs6 from "fs/promises";
|
|
4771
|
-
import path6 from "path";
|
|
4772
|
-
import os4 from "os";
|
|
4773
|
-
|
|
4774
|
-
class EnhancedPluginCache {
|
|
4775
|
-
cacheDir;
|
|
4776
|
-
resolutionsDir;
|
|
4777
|
-
definitionsDir;
|
|
4778
|
-
noCache;
|
|
4779
|
-
constructor(noCache = false) {
|
|
4780
|
-
this.noCache = noCache;
|
|
4781
|
-
this.cacheDir = path6.join(os4.homedir(), ".adk", "cache", "plugins");
|
|
4782
|
-
this.resolutionsDir = path6.join(this.cacheDir, "resolutions");
|
|
4783
|
-
this.definitionsDir = path6.join(this.cacheDir, "definitions");
|
|
4784
|
-
}
|
|
4785
|
-
async ensureCacheDirs() {
|
|
4786
|
-
await fs6.mkdir(this.resolutionsDir, { recursive: true });
|
|
4787
|
-
await fs6.mkdir(this.definitionsDir, { recursive: true });
|
|
4788
|
-
}
|
|
4789
|
-
async getResolution(name, version) {
|
|
4790
|
-
if (this.noCache) {
|
|
4791
|
-
return null;
|
|
4792
|
-
}
|
|
4793
|
-
try {
|
|
4794
|
-
const key = this.getResolutionKey(name, version);
|
|
4795
|
-
const cachePath = path6.join(this.resolutionsDir, `${key}.json`);
|
|
4796
|
-
const data = await fs6.readFile(cachePath, "utf-8");
|
|
4797
|
-
const resolution = JSON.parse(data);
|
|
4798
|
-
const cachedAt = new Date(resolution.cachedAt);
|
|
4799
|
-
const now = new Date;
|
|
4800
|
-
const ageMinutes = (now.getTime() - cachedAt.getTime()) / (1000 * 60);
|
|
4801
|
-
if (ageMinutes > 5) {
|
|
4802
|
-
return null;
|
|
4803
|
-
}
|
|
4804
|
-
return resolution;
|
|
4805
|
-
} catch {
|
|
4806
|
-
return null;
|
|
4807
|
-
}
|
|
4808
|
-
}
|
|
4809
|
-
async setResolution(name, version, pluginId, updatedAt) {
|
|
4810
|
-
await this.ensureCacheDirs();
|
|
4811
|
-
const key = this.getResolutionKey(name, version);
|
|
4812
|
-
const cachePath = path6.join(this.resolutionsDir, `${key}.json`);
|
|
4813
|
-
const resolution = {
|
|
4814
|
-
pluginId,
|
|
4815
|
-
updatedAt,
|
|
4816
|
-
cachedAt: new Date().toISOString()
|
|
4817
|
-
};
|
|
4818
|
-
await fs6.writeFile(cachePath, JSON.stringify(resolution));
|
|
4819
|
-
}
|
|
4820
|
-
async getDefinition(pluginId, updatedAt) {
|
|
4821
|
-
if (this.noCache) {
|
|
4822
|
-
return null;
|
|
4823
|
-
}
|
|
4824
|
-
try {
|
|
4825
|
-
const key = this.getDefinitionKey(pluginId, updatedAt);
|
|
4826
|
-
const cachePath = path6.join(this.definitionsDir, `${key}.json`);
|
|
4827
|
-
const data = await fs6.readFile(cachePath, "utf-8");
|
|
4828
|
-
const cached = JSON.parse(data);
|
|
4829
|
-
return cached.definition;
|
|
4830
|
-
} catch {
|
|
4831
|
-
return null;
|
|
4832
|
-
}
|
|
4833
|
-
}
|
|
4834
|
-
async setDefinition(pluginId, updatedAt, definition) {
|
|
4835
|
-
await this.ensureCacheDirs();
|
|
4836
|
-
const key = this.getDefinitionKey(pluginId, updatedAt);
|
|
4837
|
-
const cachePath = path6.join(this.definitionsDir, `${key}.json`);
|
|
4838
|
-
const cached = {
|
|
4839
|
-
definition,
|
|
4840
|
-
cachedAt: new Date().toISOString()
|
|
4841
|
-
};
|
|
4842
|
-
await fs6.writeFile(cachePath, JSON.stringify(cached));
|
|
4843
|
-
}
|
|
4844
|
-
async clear() {
|
|
4845
|
-
try {
|
|
4846
|
-
const resolutionFiles = await fs6.readdir(this.resolutionsDir);
|
|
4847
|
-
await Promise.all(resolutionFiles.map((file) => fs6.unlink(path6.join(this.resolutionsDir, file))));
|
|
4848
|
-
const definitionFiles = await fs6.readdir(this.definitionsDir);
|
|
4849
|
-
await Promise.all(definitionFiles.map((file) => fs6.unlink(path6.join(this.definitionsDir, file))));
|
|
4850
|
-
} catch {}
|
|
4851
|
-
}
|
|
4852
|
-
async getStats() {
|
|
4853
|
-
const getDirectoryStats = async (dir) => {
|
|
4854
|
-
try {
|
|
4855
|
-
const files = await fs6.readdir(dir);
|
|
4856
|
-
let totalSize = 0;
|
|
4857
|
-
for (const file of files) {
|
|
4858
|
-
const stats = await fs6.stat(path6.join(dir, file));
|
|
4859
|
-
totalSize += stats.size;
|
|
4860
|
-
}
|
|
4861
|
-
return {
|
|
4862
|
-
count: files.length,
|
|
4863
|
-
sizeBytes: totalSize
|
|
4864
|
-
};
|
|
4865
|
-
} catch {
|
|
4866
|
-
return { count: 0, sizeBytes: 0 };
|
|
4867
|
-
}
|
|
4868
|
-
};
|
|
4869
|
-
const [resolutions, definitions] = await Promise.all([
|
|
4870
|
-
getDirectoryStats(this.resolutionsDir),
|
|
4871
|
-
getDirectoryStats(this.definitionsDir)
|
|
4872
|
-
]);
|
|
4873
|
-
return { resolutions, definitions };
|
|
4874
|
-
}
|
|
4875
|
-
getResolutionKey(name, version) {
|
|
4876
|
-
const key = `${name}_${version}`;
|
|
4877
|
-
return key.replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
4878
|
-
}
|
|
4879
|
-
getDefinitionKey(pluginId, updatedAt) {
|
|
4880
|
-
const key = `${pluginId}_${updatedAt}`;
|
|
4881
|
-
return key.replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
4882
|
-
}
|
|
4883
|
-
}
|
|
4884
|
-
|
|
4885
5008
|
// src/plugins/manager.ts
|
|
4886
5009
|
init_dependencies_parser();
|
|
4887
5010
|
init_validation_errors();
|
|
5011
|
+
init_client_factory();
|
|
5012
|
+
init_catalog_service();
|
|
5013
|
+
|
|
5014
|
+
// src/dependencies/catalog/plugin-source.ts
|
|
5015
|
+
init_src();
|
|
4888
5016
|
init_search_ranking();
|
|
4889
5017
|
|
|
4890
|
-
class
|
|
4891
|
-
|
|
4892
|
-
|
|
4893
|
-
|
|
4894
|
-
|
|
4895
|
-
|
|
4896
|
-
|
|
4897
|
-
|
|
4898
|
-
async getClient() {
|
|
4899
|
-
if (!this.client) {
|
|
4900
|
-
this.client = await getProjectClient({
|
|
4901
|
-
project: this.options.project,
|
|
4902
|
-
credentials: this.options.credentials,
|
|
4903
|
-
apiUrl: this.options.apiUrl,
|
|
4904
|
-
workspaceId: this.options.workspaceId,
|
|
4905
|
-
headers: {
|
|
4906
|
-
"x-multiple-integrations": "true"
|
|
4907
|
-
}
|
|
4908
|
-
});
|
|
4909
|
-
}
|
|
4910
|
-
return this.client;
|
|
4911
|
-
}
|
|
4912
|
-
async loadPlugins(dependencies) {
|
|
4913
|
-
const errors = [];
|
|
4914
|
-
const warnings = [];
|
|
4915
|
-
const parseResult = PluginParser.parsePlugins(dependencies);
|
|
4916
|
-
const plugins = parseResult.plugins;
|
|
4917
|
-
errors.push(...parseResult.errors);
|
|
4918
|
-
const duplicateWarnings = PluginParser.checkDuplicates(plugins);
|
|
4919
|
-
warnings.push(...duplicateWarnings);
|
|
4920
|
-
const fetchPromises = plugins.map(async (plugin) => {
|
|
4921
|
-
try {
|
|
4922
|
-
plugin.definition = await this.fetchPlugin(plugin.ref);
|
|
4923
|
-
} catch (error) {
|
|
4924
|
-
if (error instanceof Error && error.message.includes("version")) {
|
|
4925
|
-
errors.push(ValidationErrors.pluginVersionError(plugin.alias, error.message));
|
|
4926
|
-
} else {
|
|
4927
|
-
const errorMessage = error instanceof Error ? error.message : undefined;
|
|
4928
|
-
errors.push(ValidationErrors.unknownPlugin(plugin.alias, plugin.ref.fullName, errorMessage));
|
|
4929
|
-
}
|
|
4930
|
-
}
|
|
4931
|
-
});
|
|
4932
|
-
await Promise.all(fetchPromises);
|
|
4933
|
-
return { plugins, errors, warnings };
|
|
4934
|
-
}
|
|
4935
|
-
async fetchPlugin(ref) {
|
|
4936
|
-
const cachedResolution = await this.cache.getResolution(ref.name, ref.version);
|
|
4937
|
-
if (cachedResolution) {
|
|
4938
|
-
const cachedDefinition = await this.cache.getDefinition(cachedResolution.pluginId, cachedResolution.updatedAt);
|
|
4939
|
-
if (cachedDefinition) {
|
|
4940
|
-
return cachedDefinition;
|
|
4941
|
-
}
|
|
4942
|
-
}
|
|
4943
|
-
const client = await this.getClient();
|
|
5018
|
+
class PluginCatalogSource {
|
|
5019
|
+
clientFactory;
|
|
5020
|
+
cacheConfig = { cacheType: "plugins", idField: "pluginId" };
|
|
5021
|
+
constructor(clientFactory) {
|
|
5022
|
+
this.clientFactory = clientFactory;
|
|
5023
|
+
}
|
|
5024
|
+
async fetchByRef(ref) {
|
|
5025
|
+
const client = await this.clientFactory.getClient();
|
|
4944
5026
|
const plugin = await this._findPublicPlugin(client, ref);
|
|
4945
5027
|
if (!plugin) {
|
|
4946
5028
|
throw new AdkError({
|
|
4947
5029
|
code: "PLUGIN_NOT_FOUND",
|
|
4948
5030
|
expected: true,
|
|
4949
|
-
message:
|
|
5031
|
+
message: await this._buildPluginNotFoundMessage(client, ref)
|
|
4950
5032
|
});
|
|
4951
5033
|
}
|
|
4952
|
-
|
|
4953
|
-
await this.cache.setDefinition(plugin.id, plugin.updatedAt, plugin);
|
|
4954
|
-
return plugin;
|
|
5034
|
+
return { id: plugin.id, updatedAt: plugin.updatedAt, definition: plugin };
|
|
4955
5035
|
}
|
|
4956
|
-
async
|
|
4957
|
-
const client = await this.getClient();
|
|
5036
|
+
async search(query, limit = 20) {
|
|
5037
|
+
const client = await this.clientFactory.getClient();
|
|
4958
5038
|
const results = new Map;
|
|
4959
5039
|
for await (const plugin of client.list.publicPlugins({})) {
|
|
4960
5040
|
collectCatalogSearchResult(results, plugin, query);
|
|
4961
5041
|
}
|
|
4962
5042
|
return getSortedCatalogSearchResults(results, limit);
|
|
4963
5043
|
}
|
|
4964
|
-
async
|
|
4965
|
-
const client = await this.getClient();
|
|
5044
|
+
async listVersions(name) {
|
|
5045
|
+
const client = await this.clientFactory.getClient();
|
|
4966
5046
|
const versions = new Set;
|
|
4967
5047
|
for await (const plugin of client.list.publicPlugins({ name })) {
|
|
4968
5048
|
versions.add(plugin.version);
|
|
4969
5049
|
}
|
|
4970
5050
|
return getSortedVersions(versions);
|
|
4971
5051
|
}
|
|
5052
|
+
async _buildPluginNotFoundMessage(client, ref) {
|
|
5053
|
+
if (ref.version !== "latest") {
|
|
5054
|
+
const latest = await this._findPublicPlugin(client, { ...ref, version: "latest" });
|
|
5055
|
+
if (latest) {
|
|
5056
|
+
return `Plugin "${ref.name}" version "${ref.version}" not found on the Botpress Hub (latest is ${latest.version}).`;
|
|
5057
|
+
}
|
|
5058
|
+
}
|
|
5059
|
+
return `Plugin "${ref.name}" not found on the Botpress Hub`;
|
|
5060
|
+
}
|
|
4972
5061
|
async _findPublicPlugin(client, ref) {
|
|
4973
5062
|
try {
|
|
4974
5063
|
const response = await client.getPublicPlugin({
|
|
@@ -4989,15 +5078,49 @@ class PluginManager {
|
|
|
4989
5078
|
}
|
|
4990
5079
|
return false;
|
|
4991
5080
|
}
|
|
5081
|
+
}
|
|
5082
|
+
|
|
5083
|
+
// src/plugins/manager.ts
|
|
5084
|
+
class PluginManager {
|
|
5085
|
+
source;
|
|
5086
|
+
service;
|
|
5087
|
+
constructor(options = {}) {
|
|
5088
|
+
const { noCache, ...clientOptions } = options;
|
|
5089
|
+
this.source = new PluginCatalogSource(new CatalogClientFactory(clientOptions));
|
|
5090
|
+
this.service = new CatalogService(this.source, noCache || false);
|
|
5091
|
+
}
|
|
5092
|
+
async loadPlugins(dependencies) {
|
|
5093
|
+
const errors = [];
|
|
5094
|
+
const warnings = [];
|
|
5095
|
+
const parseResult = PluginParser.parsePlugins(dependencies);
|
|
5096
|
+
const plugins = parseResult.plugins;
|
|
5097
|
+
errors.push(...parseResult.errors);
|
|
5098
|
+
const duplicateWarnings = PluginParser.checkDuplicates(plugins);
|
|
5099
|
+
warnings.push(...duplicateWarnings);
|
|
5100
|
+
const fetchPromises = plugins.map(async (plugin) => {
|
|
5101
|
+
try {
|
|
5102
|
+
plugin.definition = await this.fetchPlugin(plugin.ref);
|
|
5103
|
+
} catch {
|
|
5104
|
+
errors.push(ValidationErrors.unknownPlugin(plugin.alias, plugin.ref.fullName));
|
|
5105
|
+
}
|
|
5106
|
+
});
|
|
5107
|
+
await Promise.all(fetchPromises);
|
|
5108
|
+
return { plugins, errors, warnings };
|
|
5109
|
+
}
|
|
5110
|
+
async fetchPlugin(ref) {
|
|
5111
|
+
return this.service.getDefinition(ref);
|
|
5112
|
+
}
|
|
5113
|
+
async searchPlugins(query, limit = 20) {
|
|
5114
|
+
return this.source.search(query, limit);
|
|
5115
|
+
}
|
|
5116
|
+
async listPluginVersions(name) {
|
|
5117
|
+
return this.source.listVersions(name);
|
|
5118
|
+
}
|
|
4992
5119
|
async getCacheStats() {
|
|
4993
|
-
|
|
4994
|
-
return {
|
|
4995
|
-
count: stats.resolutions.count + stats.definitions.count,
|
|
4996
|
-
sizeBytes: stats.resolutions.sizeBytes + stats.definitions.sizeBytes
|
|
4997
|
-
};
|
|
5120
|
+
return this.service.getCacheStats();
|
|
4998
5121
|
}
|
|
4999
5122
|
async clearCache() {
|
|
5000
|
-
await this.
|
|
5123
|
+
await this.service.clearCache();
|
|
5001
5124
|
}
|
|
5002
5125
|
}
|
|
5003
5126
|
|
|
@@ -5025,9 +5148,10 @@ class PluginRegistry {
|
|
|
5025
5148
|
|
|
5026
5149
|
// src/dependencies/dependency-manager.ts
|
|
5027
5150
|
init_agent_project();
|
|
5151
|
+
init_snapshot_store();
|
|
5028
5152
|
|
|
5029
5153
|
class DependencyManager {
|
|
5030
|
-
|
|
5154
|
+
snapshotStore;
|
|
5031
5155
|
env;
|
|
5032
5156
|
client;
|
|
5033
5157
|
projectPath;
|
|
@@ -5040,8 +5164,8 @@ class DependencyManager {
|
|
|
5040
5164
|
this.projectPath = opts.projectPath;
|
|
5041
5165
|
this.env = opts.env;
|
|
5042
5166
|
this.client = opts.client;
|
|
5043
|
-
this.lockFile = new LockFile({ projectPath: opts.projectPath, env: opts.env });
|
|
5044
5167
|
this.botId = opts.botId;
|
|
5168
|
+
this.snapshotStore = new DependencySnapshotStore({ projectPath: opts.projectPath });
|
|
5045
5169
|
this.integrationRegistry = opts.integrationRegistry ?? new IntegrationRegistry;
|
|
5046
5170
|
this.pluginRegistry = opts.pluginRegistry ?? new PluginRegistry;
|
|
5047
5171
|
this.integrationResolver = opts.integrationResolver ?? new IntegrationResolver({ registry: this.integrationRegistry, client: this.client });
|
|
@@ -5053,14 +5177,13 @@ class DependencyManager {
|
|
|
5053
5177
|
}
|
|
5054
5178
|
static async fromProject(opts) {
|
|
5055
5179
|
const project = await AgentProject.load(opts.projectPath);
|
|
5056
|
-
const
|
|
5057
|
-
if (!
|
|
5180
|
+
const botId = opts.botId ?? DependencyManager.getProjectBotId(project, opts.env);
|
|
5181
|
+
if (!botId) {
|
|
5058
5182
|
throw new DependencyError({
|
|
5059
5183
|
code: "BOT_NOT_FOUND",
|
|
5060
|
-
message: `No
|
|
5184
|
+
message: `No ${opts.env} bot ID found in ${opts.projectPath}. Run 'adk link' to link the project to a bot.`
|
|
5061
5185
|
});
|
|
5062
5186
|
}
|
|
5063
|
-
const botId = opts.env === "dev" ? info.devId ?? info.botId : info.botId;
|
|
5064
5187
|
return new DependencyManager({
|
|
5065
5188
|
projectPath: project.path,
|
|
5066
5189
|
env: opts.env,
|
|
@@ -5072,8 +5195,72 @@ class DependencyManager {
|
|
|
5072
5195
|
pluginResolver: opts.pluginResolver
|
|
5073
5196
|
});
|
|
5074
5197
|
}
|
|
5198
|
+
static getProjectBotId(project, env) {
|
|
5199
|
+
const info = project.agentInfo;
|
|
5200
|
+
if (!info)
|
|
5201
|
+
return;
|
|
5202
|
+
return env === "dev" ? info.devId ?? info.botId : info.botId;
|
|
5203
|
+
}
|
|
5204
|
+
async getProjectBotId(env) {
|
|
5205
|
+
const project = await AgentProject.load(this.projectPath);
|
|
5206
|
+
const botId = DependencyManager.getProjectBotId(project, env);
|
|
5207
|
+
if (!botId) {
|
|
5208
|
+
throw new DependencyError({
|
|
5209
|
+
code: "BOT_NOT_FOUND",
|
|
5210
|
+
message: `No ${env} bot ID found in ${this.projectPath}. Run 'adk link' to link the project to a bot.`
|
|
5211
|
+
});
|
|
5212
|
+
}
|
|
5213
|
+
return botId;
|
|
5214
|
+
}
|
|
5215
|
+
async readSnapshot(options) {
|
|
5216
|
+
return this.snapshotStore.readOrEmpty(this.env, {
|
|
5217
|
+
tolerant: options?.tolerant,
|
|
5218
|
+
botId: this.botId
|
|
5219
|
+
});
|
|
5220
|
+
}
|
|
5221
|
+
async writeSnapshot(snapshot) {
|
|
5222
|
+
await this.snapshotStore.write({
|
|
5223
|
+
...snapshot,
|
|
5224
|
+
botId: snapshot.botId || this.botId,
|
|
5225
|
+
fetchedAt: new Date().toISOString()
|
|
5226
|
+
});
|
|
5227
|
+
}
|
|
5228
|
+
async readCloudSnapshot(previous) {
|
|
5229
|
+
const { bot } = await this.client.getBot({ id: this.botId });
|
|
5230
|
+
return dependencySnapshotFromBot({
|
|
5231
|
+
bot,
|
|
5232
|
+
botId: this.botId,
|
|
5233
|
+
env: this.env,
|
|
5234
|
+
fetchedAt: new Date,
|
|
5235
|
+
previous
|
|
5236
|
+
});
|
|
5237
|
+
}
|
|
5238
|
+
async snapshotStateFromCloud() {
|
|
5239
|
+
const previous = await this.readSnapshot({ tolerant: true });
|
|
5240
|
+
const cloud = await this.readCloudSnapshot(previous);
|
|
5241
|
+
return dependencySnapshotToState(cloud);
|
|
5242
|
+
}
|
|
5243
|
+
async applyState(state, opts) {
|
|
5244
|
+
const parsed = dependencyStateSchema.parse({
|
|
5245
|
+
...state,
|
|
5246
|
+
env: this.env
|
|
5247
|
+
});
|
|
5248
|
+
await this.writeSnapshot({
|
|
5249
|
+
version: 1,
|
|
5250
|
+
env: this.env,
|
|
5251
|
+
botId: this.botId,
|
|
5252
|
+
fetchedAt: new Date().toISOString(),
|
|
5253
|
+
integrations: parsed.integrations,
|
|
5254
|
+
plugins: parsed.plugins
|
|
5255
|
+
});
|
|
5256
|
+
const result = await this.apply(opts);
|
|
5257
|
+
if (!result.dryRun && result.applied.length === 0 && result.skipped.length === 0 && result.errors.length === 0) {
|
|
5258
|
+
await this.refreshSnapshotFromCloud();
|
|
5259
|
+
}
|
|
5260
|
+
return result;
|
|
5261
|
+
}
|
|
5075
5262
|
async list(type) {
|
|
5076
|
-
const data = await this.
|
|
5263
|
+
const data = await this.readSnapshot({ tolerant: true });
|
|
5077
5264
|
const out = [];
|
|
5078
5265
|
if (!type || type === "integration") {
|
|
5079
5266
|
for (const [alias, e] of Object.entries(data.integrations)) {
|
|
@@ -5100,9 +5287,9 @@ class DependencyManager {
|
|
|
5100
5287
|
}
|
|
5101
5288
|
const alias = spec.alias ?? spec.name;
|
|
5102
5289
|
const version = spec.version ?? "latest";
|
|
5103
|
-
const
|
|
5104
|
-
if (type === "integration" &&
|
|
5105
|
-
const existing =
|
|
5290
|
+
const snapshot = await this.readSnapshot();
|
|
5291
|
+
if (type === "integration" && snapshot.integrations[alias]) {
|
|
5292
|
+
const existing = snapshot.integrations[alias];
|
|
5106
5293
|
const versionMatch = version === "latest" || existing.version === version;
|
|
5107
5294
|
if (existing.enabled && versionMatch && jsonEqual(existing.config, spec.config ?? {})) {
|
|
5108
5295
|
return {
|
|
@@ -5112,8 +5299,8 @@ class DependencyManager {
|
|
|
5112
5299
|
};
|
|
5113
5300
|
}
|
|
5114
5301
|
}
|
|
5115
|
-
if (type === "plugin" &&
|
|
5116
|
-
const existing =
|
|
5302
|
+
if (type === "plugin" && snapshot.plugins[alias]) {
|
|
5303
|
+
const existing = snapshot.plugins[alias];
|
|
5117
5304
|
const versionMatch = version === "latest" || existing.version === version;
|
|
5118
5305
|
if (existing.enabled && versionMatch && jsonEqual(existing.config, spec.config ?? {})) {
|
|
5119
5306
|
return {
|
|
@@ -5131,28 +5318,54 @@ class DependencyManager {
|
|
|
5131
5318
|
config: spec.config ?? {}
|
|
5132
5319
|
};
|
|
5133
5320
|
let installedDisabled;
|
|
5321
|
+
let authorizationPending = false;
|
|
5134
5322
|
try {
|
|
5135
5323
|
await this.integrationResolver.applyToCloud({ botId: this.botId, alias, entry: desired });
|
|
5136
5324
|
} catch (err) {
|
|
5137
5325
|
const missingFields = extractMissingRequiredFields(err);
|
|
5138
|
-
if (
|
|
5326
|
+
if (missingFields) {
|
|
5327
|
+
await this.integrationResolver.applyToCloud({
|
|
5328
|
+
botId: this.botId,
|
|
5329
|
+
alias,
|
|
5330
|
+
entry: { ...desired, enabled: false }
|
|
5331
|
+
});
|
|
5332
|
+
installedDisabled = { missingFields };
|
|
5333
|
+
} else if (await this.specRequiresAuthorization(spec.name, spec.version)) {
|
|
5334
|
+
await this.integrationResolver.applyToCloud({
|
|
5335
|
+
botId: this.botId,
|
|
5336
|
+
alias,
|
|
5337
|
+
entry: { ...desired, enabled: false }
|
|
5338
|
+
});
|
|
5339
|
+
authorizationPending = true;
|
|
5340
|
+
} else {
|
|
5139
5341
|
throw err;
|
|
5140
|
-
|
|
5141
|
-
|
|
5142
|
-
|
|
5143
|
-
|
|
5144
|
-
|
|
5145
|
-
|
|
5342
|
+
}
|
|
5343
|
+
}
|
|
5344
|
+
const refreshed = await this.refreshSnapshotFromCloud();
|
|
5345
|
+
if (installedDisabled || authorizationPending) {
|
|
5346
|
+
const snapshotAlias = refreshed.integrations[alias] ? alias : Object.keys(refreshed.integrations).find((k) => !snapshot.integrations[k] && !refreshed.integrations[k].enabled && refreshed.integrations[k].name === spec.name);
|
|
5347
|
+
if (snapshotAlias && refreshed.integrations[snapshotAlias]) {
|
|
5348
|
+
refreshed.integrations[snapshotAlias] = {
|
|
5349
|
+
...refreshed.integrations[snapshotAlias],
|
|
5350
|
+
...installedDisabled ? { missingFields: installedDisabled.missingFields } : {},
|
|
5351
|
+
...authorizationPending ? { authorizationPending: true } : {}
|
|
5352
|
+
};
|
|
5353
|
+
await this.writeSnapshot(refreshed);
|
|
5354
|
+
}
|
|
5146
5355
|
}
|
|
5147
|
-
const refreshed = await this.refreshLockFromCloud();
|
|
5148
5356
|
const resolvedVersion = refreshed.integrations[alias]?.version ?? version;
|
|
5149
|
-
return {
|
|
5357
|
+
return {
|
|
5358
|
+
ok: true,
|
|
5359
|
+
resource: { type, alias, name: spec.name, version: resolvedVersion },
|
|
5360
|
+
installedDisabled,
|
|
5361
|
+
...authorizationPending ? { installedAwaitingAuthorization: true } : {}
|
|
5362
|
+
};
|
|
5150
5363
|
} else {
|
|
5151
5364
|
const { dependencies: resolvedDeps, autoResolved } = await this.resolvePluginDependencies({
|
|
5152
5365
|
pluginName: spec.name,
|
|
5153
5366
|
pluginVersion: version,
|
|
5154
5367
|
userDeps: spec.dependencies ?? {},
|
|
5155
|
-
|
|
5368
|
+
state: snapshot
|
|
5156
5369
|
});
|
|
5157
5370
|
const desired = {
|
|
5158
5371
|
name: spec.name,
|
|
@@ -5161,18 +5374,47 @@ class DependencyManager {
|
|
|
5161
5374
|
config: spec.config ?? {},
|
|
5162
5375
|
dependencies: resolvedDeps
|
|
5163
5376
|
};
|
|
5164
|
-
|
|
5165
|
-
|
|
5377
|
+
let installedDisabled;
|
|
5378
|
+
try {
|
|
5379
|
+
await this.pluginResolver.applyToCloud({ botId: this.botId, alias, entry: desired, state: snapshot });
|
|
5380
|
+
} catch (err) {
|
|
5381
|
+
const missingFields = extractMissingRequiredFields(err);
|
|
5382
|
+
if (!missingFields)
|
|
5383
|
+
throw err;
|
|
5384
|
+
await this.pluginResolver.applyToCloud({
|
|
5385
|
+
botId: this.botId,
|
|
5386
|
+
alias,
|
|
5387
|
+
entry: { ...desired, enabled: false },
|
|
5388
|
+
state: snapshot
|
|
5389
|
+
});
|
|
5390
|
+
installedDisabled = { missingFields };
|
|
5391
|
+
}
|
|
5392
|
+
const refreshed = await this.refreshSnapshotFromCloud();
|
|
5393
|
+
if (installedDisabled) {
|
|
5394
|
+
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);
|
|
5395
|
+
if (snapshotAlias && refreshed.plugins[snapshotAlias]) {
|
|
5396
|
+
refreshed.plugins[snapshotAlias] = {
|
|
5397
|
+
...refreshed.plugins[snapshotAlias],
|
|
5398
|
+
missingFields: installedDisabled.missingFields
|
|
5399
|
+
};
|
|
5400
|
+
await this.writeSnapshot(refreshed);
|
|
5401
|
+
}
|
|
5402
|
+
}
|
|
5166
5403
|
const resolvedVersion = refreshed.plugins[alias]?.version ?? version;
|
|
5167
|
-
return {
|
|
5404
|
+
return {
|
|
5405
|
+
ok: true,
|
|
5406
|
+
resource: { type, alias, name: spec.name, version: resolvedVersion },
|
|
5407
|
+
autoResolved,
|
|
5408
|
+
installedDisabled
|
|
5409
|
+
};
|
|
5168
5410
|
}
|
|
5169
5411
|
}
|
|
5170
5412
|
async remove(type, alias) {
|
|
5171
5413
|
if (type === "interface") {
|
|
5172
5414
|
throw new DependencyError({ code: "BUILTIN_INTERFACE_IMMUTABLE", message: "Interfaces cannot be removed." });
|
|
5173
5415
|
}
|
|
5174
|
-
const
|
|
5175
|
-
const exists = type === "integration" ? !!
|
|
5416
|
+
const snapshot = await this.readSnapshot();
|
|
5417
|
+
const exists = type === "integration" ? !!snapshot.integrations[alias] : !!snapshot.plugins[alias];
|
|
5176
5418
|
if (!exists)
|
|
5177
5419
|
return { ok: true, noop: true };
|
|
5178
5420
|
if (type === "integration") {
|
|
@@ -5180,15 +5422,15 @@ class DependencyManager {
|
|
|
5180
5422
|
} else {
|
|
5181
5423
|
await this.pluginResolver.removeFromCloud({ botId: this.botId, alias });
|
|
5182
5424
|
}
|
|
5183
|
-
await this.
|
|
5425
|
+
await this.refreshSnapshotFromCloud();
|
|
5184
5426
|
return { ok: true };
|
|
5185
5427
|
}
|
|
5186
5428
|
async upgrade(type, alias, version) {
|
|
5187
5429
|
if (type === "interface") {
|
|
5188
5430
|
throw new DependencyError({ code: "BUILTIN_INTERFACE_IMMUTABLE", message: "Interfaces cannot be upgraded." });
|
|
5189
5431
|
}
|
|
5190
|
-
const
|
|
5191
|
-
const existing = type === "integration" ?
|
|
5432
|
+
const snapshot = await this.readSnapshot();
|
|
5433
|
+
const existing = type === "integration" ? snapshot.integrations[alias] : snapshot.plugins[alias];
|
|
5192
5434
|
if (!existing) {
|
|
5193
5435
|
throw new DependencyError({
|
|
5194
5436
|
code: type === "integration" ? "INTEGRATION_NOT_FOUND" : "PLUGIN_NOT_FOUND",
|
|
@@ -5200,8 +5442,8 @@ class DependencyManager {
|
|
|
5200
5442
|
return { ok: true, noop: true, resource: { type, alias, name: existing.name, version: existing.version } };
|
|
5201
5443
|
}
|
|
5202
5444
|
const next = { ...existing, version: targetVersion };
|
|
5203
|
-
await this.applyEntry(type, alias, next,
|
|
5204
|
-
await this.
|
|
5445
|
+
await this.applyEntry(type, alias, next, snapshot);
|
|
5446
|
+
await this.refreshSnapshotFromCloud();
|
|
5205
5447
|
return { ok: true, resource: { type, alias, name: existing.name, version: next.version } };
|
|
5206
5448
|
}
|
|
5207
5449
|
async enable(type, alias) {
|
|
@@ -5217,8 +5459,8 @@ class DependencyManager {
|
|
|
5217
5459
|
message: "Interfaces cannot be enabled/disabled."
|
|
5218
5460
|
});
|
|
5219
5461
|
}
|
|
5220
|
-
const
|
|
5221
|
-
const existing = type === "integration" ?
|
|
5462
|
+
const snapshot = await this.readSnapshot();
|
|
5463
|
+
const existing = type === "integration" ? snapshot.integrations[alias] : snapshot.plugins[alias];
|
|
5222
5464
|
if (!existing) {
|
|
5223
5465
|
throw new DependencyError({
|
|
5224
5466
|
code: type === "integration" ? "INTEGRATION_NOT_FOUND" : "PLUGIN_NOT_FOUND",
|
|
@@ -5227,12 +5469,12 @@ class DependencyManager {
|
|
|
5227
5469
|
}
|
|
5228
5470
|
if (existing.enabled === enabled)
|
|
5229
5471
|
return { ok: true, noop: true };
|
|
5230
|
-
await this.applyEntry(type, alias, { ...existing, enabled },
|
|
5231
|
-
const
|
|
5232
|
-
const refreshedEntry = type === "integration" ?
|
|
5472
|
+
await this.applyEntry(type, alias, { ...existing, enabled }, snapshot);
|
|
5473
|
+
const refreshedSnapshot = await this.refreshSnapshotFromCloud();
|
|
5474
|
+
const refreshedEntry = type === "integration" ? refreshedSnapshot.integrations[alias] : refreshedSnapshot.plugins[alias];
|
|
5233
5475
|
if (!refreshedEntry || refreshedEntry.enabled !== enabled) {
|
|
5234
5476
|
throw new DependencyError({
|
|
5235
|
-
code: "
|
|
5477
|
+
code: "SNAPSHOT_DRIFT",
|
|
5236
5478
|
message: `Cloud did not persist ${type} '${alias}' as ${enabled ? "enabled" : "disabled"}.`,
|
|
5237
5479
|
details: {
|
|
5238
5480
|
type,
|
|
@@ -5248,8 +5490,8 @@ class DependencyManager {
|
|
|
5248
5490
|
if (type === "interface") {
|
|
5249
5491
|
throw new DependencyError({ code: "BUILTIN_INTERFACE_IMMUTABLE", message: "Interfaces cannot be configured." });
|
|
5250
5492
|
}
|
|
5251
|
-
const
|
|
5252
|
-
const existing = type === "integration" ?
|
|
5493
|
+
const snapshot = await this.readSnapshot();
|
|
5494
|
+
const existing = type === "integration" ? snapshot.integrations[alias] : snapshot.plugins[alias];
|
|
5253
5495
|
if (!existing) {
|
|
5254
5496
|
throw new DependencyError({
|
|
5255
5497
|
code: type === "integration" ? "INTEGRATION_NOT_FOUND" : "PLUGIN_NOT_FOUND",
|
|
@@ -5266,11 +5508,11 @@ class DependencyManager {
|
|
|
5266
5508
|
if (jsonEqual(next, existing)) {
|
|
5267
5509
|
return { ok: true, noop: true, resource: { type, alias, name: existing.name, version: existing.version } };
|
|
5268
5510
|
}
|
|
5269
|
-
await this.applyEntry(type, alias, next,
|
|
5270
|
-
await this.
|
|
5511
|
+
await this.applyEntry(type, alias, next, snapshot);
|
|
5512
|
+
await this.refreshSnapshotFromCloud();
|
|
5271
5513
|
return { ok: true, resource: { type, alias, name: existing.name, version: existing.version } };
|
|
5272
5514
|
}
|
|
5273
|
-
async applyEntry(type, alias, entry,
|
|
5515
|
+
async applyEntry(type, alias, entry, state) {
|
|
5274
5516
|
if (type === "integration") {
|
|
5275
5517
|
await this.integrationResolver.applyToCloud({
|
|
5276
5518
|
botId: this.botId,
|
|
@@ -5282,7 +5524,7 @@ class DependencyManager {
|
|
|
5282
5524
|
botId: this.botId,
|
|
5283
5525
|
alias,
|
|
5284
5526
|
entry,
|
|
5285
|
-
|
|
5527
|
+
state
|
|
5286
5528
|
});
|
|
5287
5529
|
}
|
|
5288
5530
|
}
|
|
@@ -5296,7 +5538,7 @@ class DependencyManager {
|
|
|
5296
5538
|
continue;
|
|
5297
5539
|
}
|
|
5298
5540
|
const candidates = [];
|
|
5299
|
-
for (const [integrationAlias, integrationEntry] of Object.entries(opts.
|
|
5541
|
+
for (const [integrationAlias, integrationEntry] of Object.entries(opts.state.integrations)) {
|
|
5300
5542
|
let integrationSpec;
|
|
5301
5543
|
try {
|
|
5302
5544
|
integrationSpec = await this.integrationRegistry.getSpec(integrationEntry.name, integrationEntry.version);
|
|
@@ -5355,85 +5597,67 @@ class DependencyManager {
|
|
|
5355
5597
|
return [];
|
|
5356
5598
|
}
|
|
5357
5599
|
}
|
|
5358
|
-
async
|
|
5359
|
-
|
|
5360
|
-
|
|
5361
|
-
|
|
5362
|
-
|
|
5363
|
-
|
|
5600
|
+
async specRequiresAuthorization(name, version) {
|
|
5601
|
+
try {
|
|
5602
|
+
const spec = await this.integrationRegistry.getSpec(name, version);
|
|
5603
|
+
return integrationRequiresAuthorization(spec);
|
|
5604
|
+
} catch {
|
|
5605
|
+
return false;
|
|
5606
|
+
}
|
|
5607
|
+
}
|
|
5608
|
+
async refreshSnapshotFromCloud() {
|
|
5609
|
+
return this.snapshotStore.refreshFromCloud({
|
|
5610
|
+
client: this.client,
|
|
5611
|
+
botId: this.botId,
|
|
5612
|
+
env: this.env,
|
|
5613
|
+
integrationRegistry: this.integrationRegistry
|
|
5614
|
+
});
|
|
5615
|
+
}
|
|
5616
|
+
integrationEntriesMatch(a, b) {
|
|
5617
|
+
return jsonEqual(stripSnapshotMetadata(a), stripSnapshotMetadata(b));
|
|
5618
|
+
}
|
|
5619
|
+
pluginEntriesMatch(a, b) {
|
|
5620
|
+
return jsonEqual(stripSnapshotMetadata(a), stripSnapshotMetadata(b));
|
|
5364
5621
|
}
|
|
5365
5622
|
async diff() {
|
|
5366
|
-
const
|
|
5367
|
-
const cloud = await this.
|
|
5368
|
-
const delta = {
|
|
5369
|
-
for (const [alias, entry] of Object.entries(
|
|
5623
|
+
const snapshot = await this.readSnapshot();
|
|
5624
|
+
const cloud = await this.readCloudSnapshot(snapshot);
|
|
5625
|
+
const delta = { addedInSnapshot: [], removedInSnapshot: [], changedInSnapshot: [] };
|
|
5626
|
+
for (const [alias, entry] of Object.entries(snapshot.integrations)) {
|
|
5370
5627
|
const cloudEntry = cloud.integrations[alias];
|
|
5371
5628
|
if (!cloudEntry) {
|
|
5372
|
-
delta.
|
|
5373
|
-
} else if (!
|
|
5374
|
-
delta.
|
|
5629
|
+
delta.addedInSnapshot.push({ type: "integration", alias, name: entry.name, version: entry.version });
|
|
5630
|
+
} else if (!this.integrationEntriesMatch(entry, cloudEntry)) {
|
|
5631
|
+
delta.changedInSnapshot.push({ type: "integration", alias, field: "unspecified" });
|
|
5375
5632
|
}
|
|
5376
5633
|
}
|
|
5377
5634
|
for (const [alias, entry] of Object.entries(cloud.integrations)) {
|
|
5378
|
-
if (!
|
|
5379
|
-
delta.
|
|
5635
|
+
if (!snapshot.integrations[alias]) {
|
|
5636
|
+
delta.removedInSnapshot.push({ type: "integration", alias, name: entry.name, version: entry.version });
|
|
5380
5637
|
}
|
|
5381
5638
|
}
|
|
5382
|
-
for (const [alias, entry] of Object.entries(
|
|
5639
|
+
for (const [alias, entry] of Object.entries(snapshot.plugins)) {
|
|
5383
5640
|
const cloudEntry = cloud.plugins[alias];
|
|
5384
5641
|
if (!cloudEntry) {
|
|
5385
|
-
delta.
|
|
5386
|
-
} else if (!
|
|
5387
|
-
delta.
|
|
5642
|
+
delta.addedInSnapshot.push({ type: "plugin", alias, name: entry.name, version: entry.version });
|
|
5643
|
+
} else if (!this.pluginEntriesMatch(entry, cloudEntry)) {
|
|
5644
|
+
delta.changedInSnapshot.push({ type: "plugin", alias, field: "unspecified" });
|
|
5388
5645
|
}
|
|
5389
5646
|
}
|
|
5390
5647
|
for (const [alias, entry] of Object.entries(cloud.plugins)) {
|
|
5391
|
-
if (!
|
|
5392
|
-
delta.
|
|
5648
|
+
if (!snapshot.plugins[alias]) {
|
|
5649
|
+
delta.removedInSnapshot.push({ type: "plugin", alias, name: entry.name, version: entry.version });
|
|
5393
5650
|
}
|
|
5394
5651
|
}
|
|
5395
|
-
const
|
|
5396
|
-
return { target: this.env,
|
|
5397
|
-
}
|
|
5398
|
-
async sync(opts) {
|
|
5399
|
-
const previous = await this.lockFile.read();
|
|
5400
|
-
const cloud = await this.readCloudAsLockShape(previous);
|
|
5401
|
-
const added = [];
|
|
5402
|
-
const removed = [];
|
|
5403
|
-
const updated = [];
|
|
5404
|
-
for (const [alias, entry] of Object.entries(cloud.integrations)) {
|
|
5405
|
-
const prev = previous.integrations[alias];
|
|
5406
|
-
if (!prev)
|
|
5407
|
-
added.push({ type: "integration", alias });
|
|
5408
|
-
else if (!jsonEqual(prev, entry))
|
|
5409
|
-
updated.push({ type: "integration", alias });
|
|
5410
|
-
}
|
|
5411
|
-
for (const alias of Object.keys(previous.integrations)) {
|
|
5412
|
-
if (!cloud.integrations[alias])
|
|
5413
|
-
removed.push({ type: "integration", alias });
|
|
5414
|
-
}
|
|
5415
|
-
for (const [alias, entry] of Object.entries(cloud.plugins)) {
|
|
5416
|
-
const prev = previous.plugins[alias];
|
|
5417
|
-
if (!prev)
|
|
5418
|
-
added.push({ type: "plugin", alias });
|
|
5419
|
-
else if (!jsonEqual(prev, entry))
|
|
5420
|
-
updated.push({ type: "plugin", alias });
|
|
5421
|
-
}
|
|
5422
|
-
for (const alias of Object.keys(previous.plugins)) {
|
|
5423
|
-
if (!cloud.plugins[alias])
|
|
5424
|
-
removed.push({ type: "plugin", alias });
|
|
5425
|
-
}
|
|
5426
|
-
if (!opts?.dryRun) {
|
|
5427
|
-
await this.lockFile.write({ ...previous, integrations: cloud.integrations, plugins: cloud.plugins });
|
|
5428
|
-
}
|
|
5429
|
-
return { target: this.env, added, removed, updated, dryRun: opts?.dryRun ?? false };
|
|
5652
|
+
const snapshotReflectsCloud = delta.addedInSnapshot.length === 0 && delta.removedInSnapshot.length === 0 && delta.changedInSnapshot.length === 0;
|
|
5653
|
+
return { target: this.env, snapshotReflectsCloud, delta };
|
|
5430
5654
|
}
|
|
5431
5655
|
async apply(opts) {
|
|
5432
|
-
const
|
|
5433
|
-
const cloud = await this.
|
|
5656
|
+
const snapshot = await this.readSnapshot();
|
|
5657
|
+
const cloud = await this.readCloudSnapshot(snapshot);
|
|
5434
5658
|
const actions = [];
|
|
5435
5659
|
const errors = [];
|
|
5436
|
-
for (const [alias, entry] of Object.entries(
|
|
5660
|
+
for (const [alias, entry] of Object.entries(snapshot.integrations)) {
|
|
5437
5661
|
const c = cloud.integrations[alias];
|
|
5438
5662
|
if (!c) {
|
|
5439
5663
|
actions.push({
|
|
@@ -5468,7 +5692,7 @@ class DependencyManager {
|
|
|
5468
5692
|
}
|
|
5469
5693
|
}
|
|
5470
5694
|
for (const alias of Object.keys(cloud.integrations)) {
|
|
5471
|
-
if (!
|
|
5695
|
+
if (!snapshot.integrations[alias]) {
|
|
5472
5696
|
const c = cloud.integrations[alias];
|
|
5473
5697
|
actions.push({
|
|
5474
5698
|
type: "integration",
|
|
@@ -5478,7 +5702,7 @@ class DependencyManager {
|
|
|
5478
5702
|
});
|
|
5479
5703
|
}
|
|
5480
5704
|
}
|
|
5481
|
-
for (const [alias, entry] of Object.entries(
|
|
5705
|
+
for (const [alias, entry] of Object.entries(snapshot.plugins)) {
|
|
5482
5706
|
const c = cloud.plugins[alias];
|
|
5483
5707
|
if (!c) {
|
|
5484
5708
|
actions.push({
|
|
@@ -5521,7 +5745,7 @@ class DependencyManager {
|
|
|
5521
5745
|
}
|
|
5522
5746
|
}
|
|
5523
5747
|
for (const alias of Object.keys(cloud.plugins)) {
|
|
5524
|
-
if (!
|
|
5748
|
+
if (!snapshot.plugins[alias]) {
|
|
5525
5749
|
const c = cloud.plugins[alias];
|
|
5526
5750
|
actions.push({
|
|
5527
5751
|
type: "plugin",
|
|
@@ -5532,7 +5756,7 @@ class DependencyManager {
|
|
|
5532
5756
|
}
|
|
5533
5757
|
}
|
|
5534
5758
|
if (opts?.dryRun) {
|
|
5535
|
-
return { target: this.env, applied: [],
|
|
5759
|
+
return { target: this.env, applied: [], errors: [], skipped: actions, dryRun: true };
|
|
5536
5760
|
}
|
|
5537
5761
|
if (actions.length === 0) {
|
|
5538
5762
|
return { target: this.env, applied: [], skipped: [], errors, dryRun: false };
|
|
@@ -5574,17 +5798,21 @@ class DependencyManager {
|
|
|
5574
5798
|
else
|
|
5575
5799
|
await this.pluginResolver.removeFromCloud({ botId: this.botId, alias: a.alias });
|
|
5576
5800
|
} else if (!appliedKeys.has(key)) {
|
|
5577
|
-
const entry = a.type === "integration" ?
|
|
5578
|
-
await this.applyEntry(a.type, a.alias, entry,
|
|
5801
|
+
const entry = a.type === "integration" ? snapshot.integrations[a.alias] : snapshot.plugins[a.alias];
|
|
5802
|
+
await this.applyEntry(a.type, a.alias, entry, snapshot);
|
|
5579
5803
|
appliedKeys.add(key);
|
|
5580
5804
|
}
|
|
5581
5805
|
applied.push(a);
|
|
5582
5806
|
} catch (err) {
|
|
5583
|
-
|
|
5584
|
-
|
|
5807
|
+
errors.push({
|
|
5808
|
+
action: a,
|
|
5809
|
+
code: err.code ?? "INVALID_CONFIG",
|
|
5810
|
+
message: err.message,
|
|
5811
|
+
suggestion: err.suggestion
|
|
5812
|
+
});
|
|
5585
5813
|
}
|
|
5586
5814
|
}
|
|
5587
|
-
await this.
|
|
5815
|
+
await this.refreshSnapshotFromCloud();
|
|
5588
5816
|
return { target: this.env, applied, skipped: [], errors, dryRun: false };
|
|
5589
5817
|
}
|
|
5590
5818
|
async copy(opts) {
|
|
@@ -5597,85 +5825,44 @@ class DependencyManager {
|
|
|
5597
5825
|
message: `DependencyManager constructed with env='${this.env}' but copy targets '${opts.to}'`
|
|
5598
5826
|
});
|
|
5599
5827
|
}
|
|
5600
|
-
const
|
|
5601
|
-
if (
|
|
5828
|
+
const sourceBotId = opts.sourceBotId?.trim() || await this.getProjectBotId(opts.from);
|
|
5829
|
+
if (sourceBotId === this.botId) {
|
|
5602
5830
|
throw new DependencyError({
|
|
5603
|
-
code: "
|
|
5604
|
-
message:
|
|
5831
|
+
code: "SAME_SOURCE_TARGET",
|
|
5832
|
+
message: `${opts.from} and ${opts.to} resolve to the same Cloud bot (${sourceBotId}).`
|
|
5605
5833
|
});
|
|
5606
5834
|
}
|
|
5607
|
-
const
|
|
5608
|
-
const
|
|
5609
|
-
|
|
5610
|
-
|
|
5611
|
-
|
|
5612
|
-
|
|
5835
|
+
const sourceStore = new DependencySnapshotStore({ projectPath: this.projectPath });
|
|
5836
|
+
const sourceData = await sourceStore.refreshFromCloud({
|
|
5837
|
+
client: this.client,
|
|
5838
|
+
botId: sourceBotId,
|
|
5839
|
+
env: opts.from,
|
|
5840
|
+
integrationRegistry: this.integrationRegistry
|
|
5841
|
+
});
|
|
5842
|
+
const targetSnapshotExists = await this.snapshotStore.exists(this.env);
|
|
5843
|
+
const targetSnapshot = await this.readSnapshot();
|
|
5844
|
+
const originalSnapshot = JSON.stringify(targetSnapshot);
|
|
5845
|
+
const merged = { ...targetSnapshot, integrations: sourceData.integrations, plugins: sourceData.plugins };
|
|
5846
|
+
await this.writeSnapshot(merged);
|
|
5613
5847
|
try {
|
|
5614
5848
|
const result = await this.apply({ dryRun: opts.dryRun, yes: opts.yes });
|
|
5615
5849
|
if (opts.dryRun) {
|
|
5616
|
-
if (
|
|
5617
|
-
await this.
|
|
5850
|
+
if (targetSnapshotExists) {
|
|
5851
|
+
await this.writeSnapshot(JSON.parse(originalSnapshot));
|
|
5618
5852
|
} else {
|
|
5619
|
-
await this.
|
|
5853
|
+
await this.snapshotStore.delete(this.env);
|
|
5620
5854
|
}
|
|
5621
5855
|
}
|
|
5622
5856
|
return result;
|
|
5623
5857
|
} catch (err) {
|
|
5624
|
-
if (
|
|
5625
|
-
await this.
|
|
5858
|
+
if (targetSnapshotExists) {
|
|
5859
|
+
await this.writeSnapshot(JSON.parse(originalSnapshot)).catch(() => {});
|
|
5626
5860
|
} else {
|
|
5627
|
-
await this.
|
|
5861
|
+
await this.snapshotStore.delete(this.env).catch(() => {});
|
|
5628
5862
|
}
|
|
5629
5863
|
throw err;
|
|
5630
5864
|
}
|
|
5631
5865
|
}
|
|
5632
|
-
async readCloudAsLockShape(previousLock) {
|
|
5633
|
-
const { bot } = await this.client.getBot({ id: this.botId });
|
|
5634
|
-
const previous = previousLock ?? await this.lockFile.read();
|
|
5635
|
-
return this.cloudToLockShape(bot, previous);
|
|
5636
|
-
}
|
|
5637
|
-
cloudToLockShape(bot, previous) {
|
|
5638
|
-
const integrations = {};
|
|
5639
|
-
const usedIntegrationAliases = new Set;
|
|
5640
|
-
for (const [cloudAlias, c] of Object.entries(bot.integrations ?? {})) {
|
|
5641
|
-
const cloudName = typeof c.name === "string" ? c.name : undefined;
|
|
5642
|
-
const alias = this.chooseCloudAlias({
|
|
5643
|
-
cloudAlias,
|
|
5644
|
-
cloudName,
|
|
5645
|
-
previous: previous.integrations,
|
|
5646
|
-
used: usedIntegrationAliases
|
|
5647
|
-
});
|
|
5648
|
-
usedIntegrationAliases.add(alias);
|
|
5649
|
-
const entry = this.integrationResolver.toLockEntry(c);
|
|
5650
|
-
integrations[alias] = entry;
|
|
5651
|
-
}
|
|
5652
|
-
const plugins = {};
|
|
5653
|
-
const usedPluginAliases = new Set;
|
|
5654
|
-
for (const [cloudAlias, c] of Object.entries(bot.plugins ?? {})) {
|
|
5655
|
-
const cloudName = typeof c.name === "string" ? c.name : undefined;
|
|
5656
|
-
const alias = this.chooseCloudAlias({
|
|
5657
|
-
cloudAlias,
|
|
5658
|
-
cloudName,
|
|
5659
|
-
previous: previous.plugins,
|
|
5660
|
-
used: usedPluginAliases
|
|
5661
|
-
});
|
|
5662
|
-
usedPluginAliases.add(alias);
|
|
5663
|
-
const entry = this.pluginResolver.toLockEntry(c);
|
|
5664
|
-
plugins[alias] = entry;
|
|
5665
|
-
}
|
|
5666
|
-
return { integrations, plugins };
|
|
5667
|
-
}
|
|
5668
|
-
chooseCloudAlias(opts) {
|
|
5669
|
-
if (isFriendlyAlias(opts.cloudAlias) && opts.previous[opts.cloudAlias] && !opts.used.has(opts.cloudAlias)) {
|
|
5670
|
-
return opts.cloudAlias;
|
|
5671
|
-
}
|
|
5672
|
-
if (opts.cloudName) {
|
|
5673
|
-
const match = Object.entries(opts.previous).find(([alias, entry]) => !opts.used.has(alias) && entry.name === opts.cloudName);
|
|
5674
|
-
if (match)
|
|
5675
|
-
return match[0];
|
|
5676
|
-
}
|
|
5677
|
-
return generateFriendlyAlias(opts.cloudName, opts.cloudAlias, opts.used);
|
|
5678
|
-
}
|
|
5679
5866
|
}
|
|
5680
5867
|
function formatMissingDependencySuggestion(opts) {
|
|
5681
5868
|
if (opts.implementers.length === 0) {
|
|
@@ -5692,22 +5879,119 @@ function formatMissingDependencySuggestion(opts) {
|
|
|
5692
5879
|
return lines.join(`
|
|
5693
5880
|
`);
|
|
5694
5881
|
}
|
|
5695
|
-
function
|
|
5696
|
-
const
|
|
5697
|
-
|
|
5882
|
+
function stripSnapshotMetadata(entry) {
|
|
5883
|
+
const {
|
|
5884
|
+
cloudAlias: _cloudAlias,
|
|
5885
|
+
cloudId: _cloudId,
|
|
5886
|
+
updatedAt: _updatedAt,
|
|
5887
|
+
...semantic
|
|
5888
|
+
} = entry;
|
|
5889
|
+
return semantic;
|
|
5890
|
+
}
|
|
5891
|
+
function dependencySnapshotToState(snapshot) {
|
|
5892
|
+
const integrations = {};
|
|
5893
|
+
for (const [alias, entry] of Object.entries(snapshot.integrations)) {
|
|
5894
|
+
integrations[alias] = stripSnapshotMetadata(entry);
|
|
5895
|
+
}
|
|
5896
|
+
const plugins = {};
|
|
5897
|
+
for (const [alias, entry] of Object.entries(snapshot.plugins)) {
|
|
5898
|
+
plugins[alias] = stripSnapshotMetadata(entry);
|
|
5899
|
+
}
|
|
5900
|
+
return dependencyStateSchema.parse({
|
|
5901
|
+
version: 1,
|
|
5902
|
+
env: snapshot.env,
|
|
5903
|
+
integrations,
|
|
5904
|
+
plugins
|
|
5905
|
+
});
|
|
5906
|
+
}
|
|
5907
|
+
|
|
5908
|
+
// src/dependencies/index.ts
|
|
5909
|
+
init_types();
|
|
5910
|
+
|
|
5911
|
+
// src/dependencies/status-resolver.ts
|
|
5912
|
+
import { existsSync } from "fs";
|
|
5913
|
+
import * as path11 from "path";
|
|
5914
|
+
|
|
5915
|
+
// src/utils/ids.ts
|
|
5916
|
+
function getIntegrationAlias(integrationName) {
|
|
5917
|
+
return integrationName.replace(/\//g, "__").replace(/-/g, "_").toLowerCase();
|
|
5918
|
+
}
|
|
5919
|
+
function getPluginAlias(pluginName) {
|
|
5920
|
+
return pluginName.replace(/-/g, "_").toLowerCase();
|
|
5921
|
+
}
|
|
5922
|
+
function bpModuleDirName(kind, alias) {
|
|
5923
|
+
return kind === "integration" ? `integration_${getIntegrationAlias(alias)}` : `plugin_${alias}`;
|
|
5924
|
+
}
|
|
5925
|
+
|
|
5926
|
+
// src/dependencies/status-resolver.ts
|
|
5927
|
+
async function resolveDependencyStatuses(input) {
|
|
5928
|
+
const out = [];
|
|
5929
|
+
const integrationVerdicts = new Map;
|
|
5930
|
+
for (const [alias, entry] of Object.entries(input.snapshot.integrations)) {
|
|
5931
|
+
const installed = input.bpModulesDir ? existsSync(path11.join(input.bpModulesDir, bpModuleDirName("integration", alias))) : true;
|
|
5932
|
+
const spec = await tryGetSpec(input.integrationRegistry, entry.name, entry.version);
|
|
5933
|
+
const verdict = spec ? computeIntegrationStatus({
|
|
5934
|
+
installed,
|
|
5935
|
+
spec,
|
|
5936
|
+
enabled: entry.enabled,
|
|
5937
|
+
config: entry.config,
|
|
5938
|
+
...entry.configurationType ? { configurationType: entry.configurationType } : {},
|
|
5939
|
+
...entry.missingFields !== undefined ? { persistedMissingFields: entry.missingFields } : {},
|
|
5940
|
+
...entry.authorizationPending !== undefined ? { authorizationPending: entry.authorizationPending } : {}
|
|
5941
|
+
}) : computeSnapshotOnlyStatus({
|
|
5942
|
+
installed,
|
|
5943
|
+
enabled: entry.enabled,
|
|
5944
|
+
...entry.missingFields !== undefined ? { missingFields: entry.missingFields } : {},
|
|
5945
|
+
...entry.authorizationPending !== undefined ? { authorizationPending: entry.authorizationPending } : {}
|
|
5946
|
+
});
|
|
5947
|
+
integrationVerdicts.set(alias, verdict);
|
|
5948
|
+
out.push({
|
|
5949
|
+
type: "integration",
|
|
5950
|
+
alias,
|
|
5951
|
+
name: entry.name,
|
|
5952
|
+
version: entry.version,
|
|
5953
|
+
enabled: entry.enabled,
|
|
5954
|
+
...verdict
|
|
5955
|
+
});
|
|
5956
|
+
}
|
|
5957
|
+
for (const [alias, entry] of Object.entries(input.snapshot.plugins)) {
|
|
5958
|
+
const installed = input.bpModulesDir ? existsSync(path11.join(input.bpModulesDir, bpModuleDirName("plugin", alias))) : true;
|
|
5959
|
+
const spec = await tryGetSpec(input.pluginRegistry, entry.name, entry.version);
|
|
5960
|
+
const dependencyStatuses = mapPluginDependencyStatuses(entry.dependencies, (intAlias) => integrationVerdicts.get(intAlias));
|
|
5961
|
+
let verdict;
|
|
5962
|
+
if (spec) {
|
|
5963
|
+
verdict = computePluginStatus({
|
|
5964
|
+
installed,
|
|
5965
|
+
spec,
|
|
5966
|
+
enabled: entry.enabled,
|
|
5967
|
+
config: entry.config,
|
|
5968
|
+
dependencyStatuses,
|
|
5969
|
+
...entry.missingFields !== undefined ? { persistedMissingFields: entry.missingFields } : {}
|
|
5970
|
+
});
|
|
5971
|
+
} else if (!installed) {
|
|
5972
|
+
verdict = { state: "not_installed" };
|
|
5973
|
+
} else {
|
|
5974
|
+
verdict = transitiveDependencyVerdict(dependencyStatuses) ?? computeSnapshotOnlyStatus({
|
|
5975
|
+
installed: true,
|
|
5976
|
+
enabled: entry.enabled,
|
|
5977
|
+
...entry.missingFields !== undefined ? { missingFields: entry.missingFields } : {}
|
|
5978
|
+
});
|
|
5979
|
+
}
|
|
5980
|
+
out.push({ type: "plugin", alias, name: entry.name, version: entry.version, enabled: entry.enabled, ...verdict });
|
|
5981
|
+
}
|
|
5982
|
+
return out;
|
|
5983
|
+
}
|
|
5984
|
+
async function tryGetSpec(source, name, version) {
|
|
5985
|
+
if (!source)
|
|
5986
|
+
return null;
|
|
5987
|
+
try {
|
|
5988
|
+
return await source.getSpec(name, version);
|
|
5989
|
+
} catch {
|
|
5698
5990
|
return null;
|
|
5699
|
-
|
|
5700
|
-
const re = /required property ['"]([^'"]+)['"]/g;
|
|
5701
|
-
let match;
|
|
5702
|
-
while ((match = re.exec(message)) !== null) {
|
|
5703
|
-
if (match[1])
|
|
5704
|
-
fields.add(match[1]);
|
|
5705
|
-
}
|
|
5706
|
-
return fields.size > 0 ? [...fields] : null;
|
|
5991
|
+
}
|
|
5707
5992
|
}
|
|
5708
5993
|
|
|
5709
5994
|
// src/dependencies/index.ts
|
|
5710
|
-
init_lock_file();
|
|
5711
5995
|
init_errors2();
|
|
5712
5996
|
|
|
5713
5997
|
// src/dependencies/registry/interface-registry.ts
|
|
@@ -5725,23 +6009,80 @@ class InterfaceRegistry {
|
|
|
5725
6009
|
return all.find((i) => i.alias === alias);
|
|
5726
6010
|
}
|
|
5727
6011
|
}
|
|
6012
|
+
|
|
6013
|
+
// src/dependencies/index.ts
|
|
6014
|
+
init_snapshot_store();
|
|
6015
|
+
|
|
5728
6016
|
// src/dependencies/migration.ts
|
|
5729
|
-
|
|
5730
|
-
import * as
|
|
5731
|
-
import * as path16 from "path";
|
|
6017
|
+
import * as fs11 from "fs/promises";
|
|
6018
|
+
import * as path15 from "path";
|
|
5732
6019
|
import { Project as Project3, SyntaxKind as SyntaxKind3 } from "ts-morph";
|
|
5733
6020
|
|
|
6021
|
+
// src/dependencies/legacy-lock-file.ts
|
|
6022
|
+
init_types();
|
|
6023
|
+
init_errors2();
|
|
6024
|
+
import * as fs10 from "fs/promises";
|
|
6025
|
+
import * as path12 from "path";
|
|
6026
|
+
|
|
6027
|
+
class LegacyDependencyLockFile {
|
|
6028
|
+
filePath;
|
|
6029
|
+
env;
|
|
6030
|
+
constructor(opts) {
|
|
6031
|
+
this.env = opts.env;
|
|
6032
|
+
this.filePath = path12.join(opts.projectPath, `dependencies.${opts.env}.lock.json`);
|
|
6033
|
+
}
|
|
6034
|
+
async exists() {
|
|
6035
|
+
try {
|
|
6036
|
+
await fs10.access(this.filePath);
|
|
6037
|
+
return true;
|
|
6038
|
+
} catch {
|
|
6039
|
+
return false;
|
|
6040
|
+
}
|
|
6041
|
+
}
|
|
6042
|
+
async read(options) {
|
|
6043
|
+
let raw;
|
|
6044
|
+
try {
|
|
6045
|
+
raw = await fs10.readFile(this.filePath, "utf8");
|
|
6046
|
+
} catch (err) {
|
|
6047
|
+
if (err.code === "ENOENT") {
|
|
6048
|
+
return dependencyStateSchema.parse({ version: 1, env: this.env });
|
|
6049
|
+
}
|
|
6050
|
+
throw err;
|
|
6051
|
+
}
|
|
6052
|
+
try {
|
|
6053
|
+
return dependencyStateSchema.parse(JSON.parse(raw));
|
|
6054
|
+
} catch (err) {
|
|
6055
|
+
if (options?.tolerant) {
|
|
6056
|
+
return dependencyStateSchema.parse({ version: 1, env: this.env });
|
|
6057
|
+
}
|
|
6058
|
+
throw new DependencyError({
|
|
6059
|
+
code: "INVALID_CONFIG",
|
|
6060
|
+
message: `Legacy dependency lock at ${this.filePath} failed schema validation`,
|
|
6061
|
+
details: { issues: err.issues ?? String(err) }
|
|
6062
|
+
});
|
|
6063
|
+
}
|
|
6064
|
+
}
|
|
6065
|
+
async delete() {
|
|
6066
|
+
try {
|
|
6067
|
+
await fs10.unlink(this.filePath);
|
|
6068
|
+
} catch (err) {
|
|
6069
|
+
if (err.code !== "ENOENT")
|
|
6070
|
+
throw err;
|
|
6071
|
+
}
|
|
6072
|
+
}
|
|
6073
|
+
}
|
|
6074
|
+
|
|
5734
6075
|
// src/agent-project/config-writer.ts
|
|
5735
6076
|
init_utils();
|
|
5736
6077
|
init_src();
|
|
5737
6078
|
import { Project as Project2, SyntaxKind as SyntaxKind2 } from "ts-morph";
|
|
5738
6079
|
import { readFileSync as readFileSync2 } from "fs";
|
|
5739
|
-
import * as
|
|
6080
|
+
import * as path14 from "path";
|
|
5740
6081
|
|
|
5741
6082
|
class ConfigWriter {
|
|
5742
6083
|
configPath;
|
|
5743
6084
|
constructor(projectPath) {
|
|
5744
|
-
this.configPath =
|
|
6085
|
+
this.configPath = path14.join(projectPath, "agent.config.ts");
|
|
5745
6086
|
}
|
|
5746
6087
|
loadConfig() {
|
|
5747
6088
|
const project = new Project2;
|
|
@@ -6045,181 +6386,259 @@ class ConfigWriter {
|
|
|
6045
6386
|
}
|
|
6046
6387
|
|
|
6047
6388
|
// src/dependencies/migration.ts
|
|
6048
|
-
init_errors2();
|
|
6049
6389
|
init_agent_project();
|
|
6050
|
-
|
|
6051
|
-
|
|
6052
|
-
|
|
6053
|
-
|
|
6054
|
-
|
|
6055
|
-
|
|
6056
|
-
|
|
6057
|
-
|
|
6058
|
-
|
|
6059
|
-
|
|
6060
|
-
|
|
6061
|
-
|
|
6062
|
-
|
|
6063
|
-
|
|
6064
|
-
|
|
6390
|
+
init_snapshot_store();
|
|
6391
|
+
class DependencyMigrationManager {
|
|
6392
|
+
projectPath;
|
|
6393
|
+
client;
|
|
6394
|
+
snapshotStore;
|
|
6395
|
+
integrationRegistry;
|
|
6396
|
+
pluginRegistry;
|
|
6397
|
+
integrationResolver;
|
|
6398
|
+
pluginResolver;
|
|
6399
|
+
constructor(opts) {
|
|
6400
|
+
this.projectPath = opts.projectPath;
|
|
6401
|
+
this.client = opts.client;
|
|
6402
|
+
this.snapshotStore = new DependencySnapshotStore({ projectPath: opts.projectPath });
|
|
6403
|
+
this.integrationRegistry = new IntegrationRegistry;
|
|
6404
|
+
this.pluginRegistry = new PluginRegistry;
|
|
6405
|
+
this.integrationResolver = opts.integrationResolver ?? new IntegrationResolver({ registry: this.integrationRegistry, client: this.client });
|
|
6406
|
+
this.pluginResolver = opts.pluginResolver ?? new PluginResolver({
|
|
6407
|
+
registry: this.pluginRegistry,
|
|
6408
|
+
integrationRegistry: this.integrationRegistry,
|
|
6409
|
+
client: this.client
|
|
6065
6410
|
});
|
|
6066
|
-
|
|
6067
|
-
|
|
6411
|
+
}
|
|
6412
|
+
async run() {
|
|
6413
|
+
const result = {
|
|
6414
|
+
migrated: [],
|
|
6415
|
+
warnings: [],
|
|
6416
|
+
skipped: [],
|
|
6417
|
+
legacySources: [],
|
|
6418
|
+
snapshotWrites: [],
|
|
6419
|
+
cloudWrites: []
|
|
6420
|
+
};
|
|
6421
|
+
if (await this.snapshotStore.hasMigrationMarker()) {
|
|
6422
|
+
for (const env of ["dev", "prod"]) {
|
|
6423
|
+
await this.deleteLegacyLock(env, result);
|
|
6424
|
+
result.skipped.push({ env, reason: "migration already completed" });
|
|
6425
|
+
}
|
|
6426
|
+
return result;
|
|
6068
6427
|
}
|
|
6069
|
-
|
|
6070
|
-
|
|
6071
|
-
|
|
6072
|
-
|
|
6073
|
-
|
|
6074
|
-
|
|
6075
|
-
|
|
6076
|
-
|
|
6077
|
-
|
|
6078
|
-
|
|
6079
|
-
|
|
6080
|
-
|
|
6428
|
+
const project = await AgentProject.load(this.projectPath);
|
|
6429
|
+
const info = project.agentInfo;
|
|
6430
|
+
const agentConfigDependencies = await readDependenciesFromConfig(this.projectPath);
|
|
6431
|
+
const hasAgentConfigDependencies = hasDependencies(agentConfigDependencies);
|
|
6432
|
+
if (hasAgentConfigDependencies) {
|
|
6433
|
+
result.legacySources?.push("agentConfig");
|
|
6434
|
+
}
|
|
6435
|
+
if (!info) {
|
|
6436
|
+
result.warnings.push({
|
|
6437
|
+
code: "CLOUD_FETCH_PARTIAL",
|
|
6438
|
+
message: "No agent.json found; cannot migrate dependencies to Cloud-backed snapshots."
|
|
6439
|
+
});
|
|
6440
|
+
for (const env of ["dev", "prod"]) {
|
|
6441
|
+
result.skipped.push({ env, reason: "no agent.json" });
|
|
6081
6442
|
}
|
|
6443
|
+
return result;
|
|
6444
|
+
}
|
|
6445
|
+
const markerSources = new Set;
|
|
6446
|
+
for (const env of ["dev", "prod"]) {
|
|
6082
6447
|
const botId = env === "dev" ? info.devId ?? info.botId : info.botId;
|
|
6083
|
-
if (
|
|
6448
|
+
if (!botId) {
|
|
6084
6449
|
result.warnings.push({
|
|
6085
6450
|
code: "NO_PROD_BOT",
|
|
6086
|
-
message: "No prod bot configured in agent.json.
|
|
6451
|
+
message: "No prod bot configured in agent.json. Prod dependency snapshot was not written."
|
|
6087
6452
|
});
|
|
6088
6453
|
result.skipped.push({ env, reason: "no prod bot configured" });
|
|
6089
6454
|
continue;
|
|
6090
6455
|
}
|
|
6091
|
-
|
|
6092
|
-
|
|
6093
|
-
|
|
6094
|
-
|
|
6095
|
-
|
|
6096
|
-
|
|
6097
|
-
code: "CLOUD_FETCH_PARTIAL",
|
|
6098
|
-
message: `Could not fetch cloud state for ${env}: ${err.message}`
|
|
6099
|
-
});
|
|
6100
|
-
result.skipped.push({ env, reason: "cloud fetch failed" });
|
|
6456
|
+
const legacy = await this.readLegacyState(env, agentConfigDependencies);
|
|
6457
|
+
if (legacy?.source === "lock" && !result.legacySources?.includes("lock")) {
|
|
6458
|
+
result.legacySources?.push("lock");
|
|
6459
|
+
}
|
|
6460
|
+
let bot = await this.fetchBot(botId, env, result);
|
|
6461
|
+
if (!bot)
|
|
6101
6462
|
continue;
|
|
6463
|
+
if (!cloudHasDependencies(bot) && legacy) {
|
|
6464
|
+
await this.importLegacyToCloud({ botId, legacy: legacy.data });
|
|
6465
|
+
result.cloudWrites?.push(env);
|
|
6466
|
+
markerSources.add(legacy.source);
|
|
6467
|
+
bot = await this.fetchBot(botId, env, result);
|
|
6468
|
+
if (!bot)
|
|
6469
|
+
continue;
|
|
6470
|
+
} else {
|
|
6471
|
+
markerSources.add("cloud");
|
|
6102
6472
|
}
|
|
6103
|
-
|
|
6104
|
-
|
|
6473
|
+
await this.snapshotStore.write(dependencySnapshotFromBot({
|
|
6474
|
+
bot,
|
|
6475
|
+
botId,
|
|
6105
6476
|
env,
|
|
6106
|
-
|
|
6107
|
-
|
|
6108
|
-
};
|
|
6109
|
-
|
|
6110
|
-
const usedIntegrationAliases = new Set(Object.keys(declaredAliases.integrations));
|
|
6111
|
-
for (const [cloudAlias, cloud] of Object.entries(bot.integrations ?? {})) {
|
|
6112
|
-
const declaredAlias = Object.entries(declaredAliases.integrations).find(([, decl]) => decl.name === cloud.name)?.[0];
|
|
6113
|
-
const alias = declaredAlias ?? generateFriendlyAlias(cloud.name, cloudAlias, usedIntegrationAliases);
|
|
6114
|
-
usedIntegrationAliases.add(alias);
|
|
6115
|
-
lockData.integrations[alias] = {
|
|
6116
|
-
name: cloud.name,
|
|
6117
|
-
version: cloud.version,
|
|
6118
|
-
enabled: cloud.enabled ?? false,
|
|
6119
|
-
config: cloud.configuration ?? {}
|
|
6120
|
-
};
|
|
6121
|
-
}
|
|
6122
|
-
const usedPluginAliases = new Set(Object.keys(declaredAliases.plugins));
|
|
6123
|
-
for (const [cloudAlias, cloud] of Object.entries(bot.plugins ?? {})) {
|
|
6124
|
-
const declaredAlias = Object.entries(declaredAliases.plugins).find(([, decl]) => decl.name === cloud.name)?.[0];
|
|
6125
|
-
const alias = declaredAlias ?? generateFriendlyAlias(cloud.name, cloudAlias, usedPluginAliases);
|
|
6126
|
-
usedPluginAliases.add(alias);
|
|
6127
|
-
lockData.plugins[alias] = {
|
|
6128
|
-
name: cloud.name,
|
|
6129
|
-
version: cloud.version,
|
|
6130
|
-
enabled: cloud.enabled ?? true,
|
|
6131
|
-
config: cloud.configuration ?? {},
|
|
6132
|
-
dependencies: Object.fromEntries(Object.entries(cloud.interfaces ?? {}).map(([k, v]) => [
|
|
6133
|
-
k,
|
|
6134
|
-
{ integrationAlias: v.integrationAlias }
|
|
6135
|
-
]))
|
|
6136
|
-
};
|
|
6137
|
-
}
|
|
6138
|
-
await lockFile.write(lockData);
|
|
6477
|
+
fetchedAt: new Date,
|
|
6478
|
+
previous: await this.snapshotStore.read(env, { tolerant: true })
|
|
6479
|
+
}));
|
|
6480
|
+
result.snapshotWrites?.push(env);
|
|
6139
6481
|
result.migrated.push(env);
|
|
6482
|
+
await this.deleteLegacyLock(env, result);
|
|
6483
|
+
}
|
|
6484
|
+
if (hasAgentConfigDependencies && result.migrated.length > 0) {
|
|
6485
|
+
const writer = new ConfigWriter(this.projectPath);
|
|
6486
|
+
await writer.removeDependenciesField();
|
|
6487
|
+
}
|
|
6488
|
+
if (result.migrated.length > 0) {
|
|
6489
|
+
await this.snapshotStore.writeMigrationMarker({
|
|
6490
|
+
version: 1,
|
|
6491
|
+
migratedAt: new Date().toISOString(),
|
|
6492
|
+
sources: [...markerSources]
|
|
6493
|
+
});
|
|
6494
|
+
result.warnings.push({
|
|
6495
|
+
code: "MIGRATED_DEPENDENCIES",
|
|
6496
|
+
message: `Migrated dependencies to .adk snapshots for ${result.migrated.join(", ")}. Cloud is now the source of truth.`
|
|
6497
|
+
});
|
|
6140
6498
|
}
|
|
6499
|
+
return result;
|
|
6141
6500
|
}
|
|
6142
|
-
|
|
6143
|
-
|
|
6144
|
-
|
|
6145
|
-
|
|
6146
|
-
|
|
6147
|
-
|
|
6148
|
-
|
|
6501
|
+
async deleteLegacyLock(env, result) {
|
|
6502
|
+
try {
|
|
6503
|
+
await new LegacyDependencyLockFile({ projectPath: this.projectPath, env }).delete();
|
|
6504
|
+
} catch (err) {
|
|
6505
|
+
result.warnings.push({
|
|
6506
|
+
code: "LEGACY_LOCK_DELETE_FAILED",
|
|
6507
|
+
message: `Migrated ${env} dependencies, but could not delete dependencies.${env}.lock.json: ${err.message}`
|
|
6508
|
+
});
|
|
6509
|
+
}
|
|
6510
|
+
}
|
|
6511
|
+
async readLegacyState(env, agentConfigDependencies) {
|
|
6512
|
+
const legacyLock = new LegacyDependencyLockFile({ projectPath: this.projectPath, env });
|
|
6513
|
+
if (await legacyLock.exists()) {
|
|
6514
|
+
return { source: "lock", data: await legacyLock.read() };
|
|
6515
|
+
}
|
|
6516
|
+
if (hasDependencies(agentConfigDependencies)) {
|
|
6517
|
+
return { source: "agentConfig", data: { ...agentConfigDependencies, env } };
|
|
6518
|
+
}
|
|
6519
|
+
return null;
|
|
6520
|
+
}
|
|
6521
|
+
async fetchBot(botId, env, result) {
|
|
6522
|
+
try {
|
|
6523
|
+
const { bot } = await this.client.getBot({ id: botId });
|
|
6524
|
+
return bot;
|
|
6525
|
+
} catch (err) {
|
|
6526
|
+
result.warnings.push({
|
|
6527
|
+
code: "CLOUD_FETCH_PARTIAL",
|
|
6528
|
+
message: `Could not fetch cloud state for ${env}: ${err.message}`
|
|
6529
|
+
});
|
|
6530
|
+
result.skipped.push({ env, reason: "cloud fetch failed" });
|
|
6531
|
+
return null;
|
|
6532
|
+
}
|
|
6533
|
+
}
|
|
6534
|
+
async importLegacyToCloud(opts) {
|
|
6535
|
+
for (const [alias, entry] of Object.entries(opts.legacy.integrations)) {
|
|
6536
|
+
await this.integrationResolver.applyToCloud({ botId: opts.botId, alias, entry });
|
|
6537
|
+
}
|
|
6538
|
+
for (const [alias, entry] of Object.entries(opts.legacy.plugins)) {
|
|
6539
|
+
await this.pluginResolver.applyToCloud({ botId: opts.botId, alias, entry, state: opts.legacy });
|
|
6540
|
+
}
|
|
6149
6541
|
}
|
|
6150
|
-
return result;
|
|
6151
6542
|
}
|
|
6152
|
-
async function
|
|
6153
|
-
|
|
6543
|
+
async function migrateFromConfig(opts) {
|
|
6544
|
+
return new DependencyMigrationManager(opts).run();
|
|
6545
|
+
}
|
|
6546
|
+
async function readDependenciesFromConfig(projectPath) {
|
|
6547
|
+
const configPath = path15.join(projectPath, "agent.config.ts");
|
|
6548
|
+
const empty = { version: 1, env: "dev", integrations: {}, plugins: {} };
|
|
6154
6549
|
try {
|
|
6155
|
-
await
|
|
6550
|
+
await fs11.access(configPath);
|
|
6156
6551
|
} catch {
|
|
6157
|
-
return
|
|
6552
|
+
return empty;
|
|
6158
6553
|
}
|
|
6159
|
-
const integrations = {};
|
|
6160
|
-
const plugins = {};
|
|
6161
6554
|
try {
|
|
6162
6555
|
const project = new Project3({ useInMemoryFileSystem: false });
|
|
6163
6556
|
const sourceFile = project.addSourceFileAtPath(configPath);
|
|
6164
6557
|
const callExpr = sourceFile.getDescendantsOfKind(SyntaxKind3.CallExpression).find((c) => c.getExpression().getText() === "defineConfig");
|
|
6165
6558
|
const obj = callExpr?.getArguments()[0]?.asKind(SyntaxKind3.ObjectLiteralExpression);
|
|
6166
6559
|
if (!obj)
|
|
6167
|
-
return
|
|
6560
|
+
return empty;
|
|
6168
6561
|
const depsProp = obj.getProperty("dependencies");
|
|
6169
|
-
if (!depsProp
|
|
6170
|
-
return
|
|
6562
|
+
if (!depsProp?.isKind(SyntaxKind3.PropertyAssignment))
|
|
6563
|
+
return empty;
|
|
6171
6564
|
const depsObj = depsProp.getInitializer()?.asKind(SyntaxKind3.ObjectLiteralExpression);
|
|
6172
6565
|
if (!depsObj)
|
|
6173
|
-
return
|
|
6174
|
-
|
|
6175
|
-
|
|
6176
|
-
|
|
6177
|
-
|
|
6178
|
-
|
|
6179
|
-
|
|
6180
|
-
|
|
6181
|
-
|
|
6182
|
-
|
|
6183
|
-
|
|
6184
|
-
|
|
6185
|
-
|
|
6186
|
-
|
|
6187
|
-
|
|
6188
|
-
|
|
6189
|
-
|
|
6190
|
-
|
|
6191
|
-
|
|
6192
|
-
|
|
6193
|
-
|
|
6194
|
-
|
|
6195
|
-
|
|
6196
|
-
|
|
6197
|
-
|
|
6198
|
-
|
|
6199
|
-
|
|
6200
|
-
|
|
6201
|
-
|
|
6202
|
-
|
|
6203
|
-
|
|
6204
|
-
}
|
|
6566
|
+
return empty;
|
|
6567
|
+
readDependencyField(depsObj, "integrations", empty);
|
|
6568
|
+
readDependencyField(depsObj, "plugins", empty);
|
|
6569
|
+
} catch {
|
|
6570
|
+
return empty;
|
|
6571
|
+
}
|
|
6572
|
+
return empty;
|
|
6573
|
+
}
|
|
6574
|
+
function readDependencyField(depsObj, field, data) {
|
|
6575
|
+
const innerProp = depsObj.getProperty(field);
|
|
6576
|
+
if (!innerProp?.isKind(SyntaxKind3.PropertyAssignment))
|
|
6577
|
+
return;
|
|
6578
|
+
const inner = innerProp.getInitializer()?.asKind(SyntaxKind3.ObjectLiteralExpression);
|
|
6579
|
+
if (!inner)
|
|
6580
|
+
return;
|
|
6581
|
+
for (const aliasProp of inner.getProperties()) {
|
|
6582
|
+
if (!aliasProp.isKind(SyntaxKind3.PropertyAssignment))
|
|
6583
|
+
continue;
|
|
6584
|
+
const alias = aliasProp.getName().replace(/['"]/g, "");
|
|
6585
|
+
const version = readVersionLiteral(aliasProp.getInitializer());
|
|
6586
|
+
if (!version)
|
|
6587
|
+
continue;
|
|
6588
|
+
const at = version.indexOf("@");
|
|
6589
|
+
if (at < 0)
|
|
6590
|
+
continue;
|
|
6591
|
+
const name = version.slice(0, at);
|
|
6592
|
+
const semver3 = version.slice(at + 1);
|
|
6593
|
+
if (field === "integrations") {
|
|
6594
|
+
data.integrations[alias] = { name, version: semver3, enabled: true, config: {} };
|
|
6595
|
+
} else {
|
|
6596
|
+
data.plugins[alias] = { name, version: semver3, enabled: true, config: {}, dependencies: {} };
|
|
6205
6597
|
}
|
|
6206
|
-
}
|
|
6207
|
-
|
|
6598
|
+
}
|
|
6599
|
+
}
|
|
6600
|
+
function readVersionLiteral(node) {
|
|
6601
|
+
if (node?.isKind(SyntaxKind3.StringLiteral)) {
|
|
6602
|
+
return node.getLiteralText();
|
|
6603
|
+
}
|
|
6604
|
+
if (node?.isKind(SyntaxKind3.ObjectLiteralExpression)) {
|
|
6605
|
+
const versionProp = node.getProperty("version");
|
|
6606
|
+
if (versionProp?.isKind(SyntaxKind3.PropertyAssignment)) {
|
|
6607
|
+
const value = versionProp.getInitializer();
|
|
6608
|
+
if (value?.isKind(SyntaxKind3.StringLiteral))
|
|
6609
|
+
return value.getLiteralText();
|
|
6610
|
+
}
|
|
6611
|
+
}
|
|
6612
|
+
return null;
|
|
6613
|
+
}
|
|
6614
|
+
function hasDependencies(data) {
|
|
6615
|
+
return Object.keys(data.integrations).length > 0 || Object.keys(data.plugins).length > 0;
|
|
6616
|
+
}
|
|
6617
|
+
function cloudHasDependencies(bot) {
|
|
6618
|
+
return Object.keys(bot.integrations ?? {}).length > 0 || Object.keys(bot.plugins ?? {}).length > 0;
|
|
6208
6619
|
}
|
|
6209
6620
|
export {
|
|
6210
6621
|
sortKeysDeep,
|
|
6622
|
+
resolveDependencyStatuses,
|
|
6211
6623
|
migrateFromConfig,
|
|
6212
6624
|
jsonEqual,
|
|
6625
|
+
isCallable,
|
|
6626
|
+
emptyDependencySnapshot,
|
|
6627
|
+
dependencyStateSchema,
|
|
6628
|
+
dependencySnapshotFromBot,
|
|
6629
|
+
computePluginStatus,
|
|
6630
|
+
computeIntegrationStatus,
|
|
6213
6631
|
PluginResolver,
|
|
6214
6632
|
PluginRegistry,
|
|
6215
|
-
LockFile,
|
|
6216
6633
|
InterfaceRegistry,
|
|
6217
6634
|
IntegrationResolver,
|
|
6218
6635
|
IntegrationRegistry,
|
|
6636
|
+
DependencySnapshotStore,
|
|
6637
|
+
DependencyMigrationManager,
|
|
6219
6638
|
DependencyManager,
|
|
6220
6639
|
DependencyError,
|
|
6221
6640
|
DEPENDENCY_WARNING_CODES,
|
|
6222
6641
|
DEPENDENCY_ERROR_CODES
|
|
6223
6642
|
};
|
|
6224
6643
|
|
|
6225
|
-
//# debugId=
|
|
6644
|
+
//# debugId=023A4493C0E65DF164756E2164756E21
|