@dobby.ai/dobby 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.env.example +0 -1
- package/AGENTS.md +7 -7
- package/README.md +64 -32
- package/config/gateway.example.json +10 -6
- package/dist/plugins/connector-discord/src/mapper.js +75 -0
- package/dist/src/cli/commands/doctor.js +81 -2
- package/dist/src/cli/commands/extension.js +3 -1
- package/dist/src/cli/commands/init.js +43 -173
- package/dist/src/cli/commands/topology.js +38 -14
- package/dist/src/cli/program.js +15 -131
- package/dist/src/cli/shared/config-io.js +3 -31
- package/dist/src/cli/shared/config-mutators.js +33 -9
- package/dist/src/cli/shared/configure-sections.js +52 -12
- package/dist/src/cli/shared/init-catalog.js +89 -46
- package/dist/src/cli/shared/local-extension-specs.js +85 -0
- package/dist/src/cli/shared/schema-prompts.js +26 -2
- package/dist/src/cli/tests/config-io.test.js +5 -5
- package/dist/src/cli/tests/discord-mapper.test.js +90 -0
- package/dist/src/cli/tests/doctor.test.js +145 -0
- package/dist/src/cli/tests/init-catalog.test.js +108 -61
- package/dist/src/cli/tests/program-options.test.js +14 -28
- package/dist/src/cli/tests/routing-config.test.js +59 -4
- package/dist/src/core/gateway.js +3 -1
- package/dist/src/core/routing.js +53 -38
- package/dist/src/main.js +0 -0
- package/dist/src/shared/dobby-repo.js +40 -0
- package/docs/RUNBOOK.md +28 -27
- package/package.json +3 -2
- package/plugins/connector-discord/package-lock.json +2 -2
- package/plugins/connector-discord/package.json +1 -1
- package/plugins/connector-discord/src/connector.ts +0 -5
- package/plugins/connector-discord/src/mapper.ts +3 -4
- package/plugins/connector-feishu/package-lock.json +2 -2
- package/plugins/connector-feishu/package.json +1 -1
- package/plugins/plugin-sdk/package-lock.json +2 -2
- package/plugins/plugin-sdk/package.json +1 -1
- package/plugins/provider-claude/package-lock.json +2 -2
- package/plugins/provider-claude/package.json +1 -1
- package/plugins/provider-claude-cli/package-lock.json +2 -2
- package/plugins/provider-claude-cli/package.json +1 -1
- package/plugins/provider-pi/package-lock.json +2 -2
- package/plugins/provider-pi/package.json +1 -1
- package/plugins/provider-pi/src/contribution.ts +139 -9
- package/src/cli/commands/doctor.ts +103 -2
- package/src/cli/commands/extension.ts +3 -1
- package/src/cli/commands/init.ts +45 -230
- package/src/cli/commands/topology.ts +48 -16
- package/src/cli/program.ts +16 -167
- package/src/cli/shared/config-io.ts +3 -35
- package/src/cli/shared/config-mutators.ts +39 -9
- package/src/cli/shared/config-types.ts +10 -2
- package/src/cli/shared/configure-sections.ts +55 -11
- package/src/cli/shared/init-catalog.ts +126 -66
- package/src/cli/shared/local-extension-specs.ts +108 -0
- package/src/cli/shared/schema-prompts.ts +30 -1
- package/src/cli/tests/config-io.test.ts +5 -5
- package/src/cli/tests/discord-mapper.test.ts +128 -0
- package/src/cli/tests/doctor.test.ts +149 -0
- package/src/cli/tests/init-catalog.test.ts +112 -64
- package/src/cli/tests/program-options.test.ts +14 -32
- package/src/cli/tests/routing-config.test.ts +76 -4
- package/src/core/gateway.ts +3 -1
- package/src/core/routing.ts +70 -45
- package/src/core/types.ts +8 -2
- package/src/shared/dobby-repo.ts +48 -0
- package/config/models.custom.example.json +0 -27
- package/dist/src/agent/tests/event-forwarder.test.js +0 -113
- package/dist/src/cli/shared/config-path.js +0 -207
- package/dist/src/cli/shared/init-models-file.js +0 -65
- package/dist/src/cli/shared/presets.js +0 -86
- package/dist/src/cli/tests/config-path.test.js +0 -21
- package/dist/src/cli/tests/discord-config.test.js +0 -23
- package/dist/src/cli/tests/presets.test.js +0 -41
- package/dist/src/cli/tests/routing-legacy.test.js +0 -191
- package/dist/src/core/tests/gateway-update-strategy.test.js +0 -167
- package/src/cli/shared/init-models-file.ts +0 -77
|
@@ -1,37 +1,13 @@
|
|
|
1
|
-
import { cancel,
|
|
1
|
+
import { cancel, intro, isCancel, multiselect, outro, select, spinner, } from "@clack/prompts";
|
|
2
2
|
import { ExtensionStoreManager } from "../../extension/manager.js";
|
|
3
3
|
import { ensureGatewayConfigShape, upsertAllowListPackage, upsertBinding, upsertConnectorInstance, upsertProviderInstance, upsertRoute, } from "../shared/config-mutators.js";
|
|
4
|
-
import {
|
|
5
|
-
import { applyAndValidateContributionSchemas, loadContributionSchemaCatalog } from "../shared/config-schema.js";
|
|
4
|
+
import { applyAndValidateContributionSchemas } from "../shared/config-schema.js";
|
|
6
5
|
import { readRawConfig, resolveConfigPath, resolveDataRootDir, writeConfigWithValidation, } from "../shared/config-io.js";
|
|
7
6
|
import { createInitSelectionConfig, isInitConnectorChoiceId, isInitProviderChoiceId, listInitConnectorChoices, listInitProviderChoices, } from "../shared/init-catalog.js";
|
|
8
|
-
import {
|
|
7
|
+
import { resolveExtensionInstallSpecs } from "../shared/local-extension-specs.js";
|
|
9
8
|
import { createLogger } from "../shared/runtime.js";
|
|
10
|
-
import { promptConfigFromSchema } from "../shared/schema-prompts.js";
|
|
11
9
|
/**
|
|
12
|
-
*
|
|
13
|
-
*/
|
|
14
|
-
async function promptRequiredText(params) {
|
|
15
|
-
while (true) {
|
|
16
|
-
const promptOptions = {
|
|
17
|
-
message: params.message,
|
|
18
|
-
...(params.placeholder !== undefined ? { placeholder: params.placeholder } : {}),
|
|
19
|
-
...(params.initialValue !== undefined ? { initialValue: params.initialValue } : {}),
|
|
20
|
-
};
|
|
21
|
-
const result = await text(promptOptions);
|
|
22
|
-
if (isCancel(result)) {
|
|
23
|
-
cancel("Initialization cancelled.");
|
|
24
|
-
throw new Error("Initialization cancelled.");
|
|
25
|
-
}
|
|
26
|
-
const value = String(result ?? "").trim();
|
|
27
|
-
if (value.length > 0) {
|
|
28
|
-
return value;
|
|
29
|
-
}
|
|
30
|
-
await note("This field is required.", "Validation");
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Collects init inputs from interactive prompts.
|
|
10
|
+
* Collects high-level starter choices only; config values are written as templates.
|
|
35
11
|
*/
|
|
36
12
|
async function collectInitInput() {
|
|
37
13
|
intro("dobby init");
|
|
@@ -61,7 +37,7 @@ async function collectInitInput() {
|
|
|
61
37
|
let routeProviderChoiceId = providerChoiceIds[0];
|
|
62
38
|
if (providerChoiceIds.length > 1) {
|
|
63
39
|
const routeProviderChoiceResult = await select({
|
|
64
|
-
message: "Choose
|
|
40
|
+
message: "Choose default provider",
|
|
65
41
|
options: providerChoiceIds.map((providerChoiceId) => ({
|
|
66
42
|
value: providerChoiceId,
|
|
67
43
|
label: providerChoicesById.get(providerChoiceId)?.label ?? providerChoiceId,
|
|
@@ -79,101 +55,55 @@ async function collectInitInput() {
|
|
|
79
55
|
routeProviderChoiceId = routeProviderCandidate;
|
|
80
56
|
}
|
|
81
57
|
const connectorChoices = listInitConnectorChoices();
|
|
82
|
-
const connectorChoiceResult = await
|
|
83
|
-
message: "Choose connector",
|
|
58
|
+
const connectorChoiceResult = await multiselect({
|
|
59
|
+
message: "Choose connector(s) (space to select multiple)",
|
|
84
60
|
options: connectorChoices.map((item) => ({
|
|
85
61
|
value: item.id,
|
|
86
62
|
label: item.label,
|
|
87
63
|
})),
|
|
88
|
-
|
|
64
|
+
initialValues: ["connector.discord"],
|
|
65
|
+
required: true,
|
|
89
66
|
});
|
|
90
67
|
if (isCancel(connectorChoiceResult)) {
|
|
91
68
|
cancel("Initialization cancelled.");
|
|
92
69
|
throw new Error("Initialization cancelled.");
|
|
93
70
|
}
|
|
94
|
-
const
|
|
95
|
-
if (
|
|
96
|
-
throw new Error(
|
|
71
|
+
const connectorChoiceIds = connectorChoiceResult.map((value) => String(value));
|
|
72
|
+
if (connectorChoiceIds.length === 0) {
|
|
73
|
+
throw new Error("At least one connector must be selected");
|
|
97
74
|
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
});
|
|
102
|
-
const channelId = await promptRequiredText({
|
|
103
|
-
message: "Discord channel ID",
|
|
104
|
-
placeholder: "1234567890",
|
|
105
|
-
});
|
|
106
|
-
const routeIdResult = await text({
|
|
107
|
-
message: "Route ID",
|
|
108
|
-
initialValue: "main",
|
|
109
|
-
});
|
|
110
|
-
if (isCancel(routeIdResult)) {
|
|
111
|
-
cancel("Initialization cancelled.");
|
|
112
|
-
throw new Error("Initialization cancelled.");
|
|
113
|
-
}
|
|
114
|
-
const botNameResult = await text({
|
|
115
|
-
message: "Discord bot name",
|
|
116
|
-
initialValue: DEFAULT_DISCORD_BOT_NAME,
|
|
117
|
-
});
|
|
118
|
-
if (isCancel(botNameResult)) {
|
|
119
|
-
cancel("Initialization cancelled.");
|
|
120
|
-
throw new Error("Initialization cancelled.");
|
|
121
|
-
}
|
|
122
|
-
const botTokenResult = await password({
|
|
123
|
-
message: "Discord bot token",
|
|
124
|
-
mask: "*",
|
|
125
|
-
validate: (value) => (value.trim().length > 0 ? undefined : "Token is required"),
|
|
126
|
-
});
|
|
127
|
-
if (isCancel(botTokenResult)) {
|
|
128
|
-
cancel("Initialization cancelled.");
|
|
129
|
-
throw new Error("Initialization cancelled.");
|
|
130
|
-
}
|
|
131
|
-
const allowAllMessagesResult = await confirm({
|
|
132
|
-
message: "Allow all group messages (not mention-only)?",
|
|
133
|
-
initialValue: false,
|
|
134
|
-
});
|
|
135
|
-
if (isCancel(allowAllMessagesResult)) {
|
|
136
|
-
cancel("Initialization cancelled.");
|
|
137
|
-
throw new Error("Initialization cancelled.");
|
|
75
|
+
if (!connectorChoiceIds.every((connectorChoiceId) => isInitConnectorChoiceId(connectorChoiceId))) {
|
|
76
|
+
const invalidChoice = connectorChoiceIds.find((connectorChoiceId) => !isInitConnectorChoiceId(connectorChoiceId));
|
|
77
|
+
throw new Error(`Unsupported connector choice '${invalidChoice}'`);
|
|
138
78
|
}
|
|
139
79
|
return {
|
|
140
80
|
providerChoiceIds: providerChoiceIds,
|
|
141
81
|
routeProviderChoiceId,
|
|
142
|
-
|
|
143
|
-
projectRoot,
|
|
144
|
-
channelId,
|
|
145
|
-
routeId: String(routeIdResult ?? "").trim() || "main",
|
|
146
|
-
botName: String(botNameResult ?? "").trim() || DEFAULT_DISCORD_BOT_NAME,
|
|
147
|
-
botToken: String(botTokenResult ?? "").trim(),
|
|
148
|
-
allowAllMessages: allowAllMessagesResult === true,
|
|
82
|
+
connectorChoiceIds: connectorChoiceIds,
|
|
149
83
|
};
|
|
150
84
|
}
|
|
151
85
|
/**
|
|
152
|
-
* Executes first-time initialization
|
|
86
|
+
* Executes first-time initialization by installing starter extensions and writing template config.
|
|
153
87
|
*/
|
|
154
88
|
export async function runInitCommand() {
|
|
155
89
|
const configPath = resolveConfigPath();
|
|
156
90
|
const existingConfig = await readRawConfig(configPath);
|
|
157
91
|
if (existingConfig) {
|
|
158
|
-
throw new Error(`Config '${configPath}' already exists.
|
|
92
|
+
throw new Error(`Config '${configPath}' already exists. Edit the file directly to update existing values.`);
|
|
159
93
|
}
|
|
160
94
|
const input = await collectInitInput();
|
|
161
|
-
const selected = createInitSelectionConfig(input.providerChoiceIds, input.
|
|
162
|
-
routeId: input.routeId,
|
|
163
|
-
projectRoot: input.projectRoot,
|
|
164
|
-
allowAllMessages: input.allowAllMessages,
|
|
165
|
-
botName: input.botName,
|
|
166
|
-
botToken: input.botToken,
|
|
167
|
-
channelId: input.channelId,
|
|
95
|
+
const selected = createInitSelectionConfig(input.providerChoiceIds, input.connectorChoiceIds, {
|
|
168
96
|
routeProviderChoiceId: input.routeProviderChoiceId,
|
|
97
|
+
defaultProjectRoot: process.cwd(),
|
|
169
98
|
});
|
|
170
99
|
const next = ensureGatewayConfigShape({});
|
|
171
100
|
const rootDir = resolveDataRootDir(configPath, next);
|
|
172
101
|
const manager = new ExtensionStoreManager(createLogger(), `${rootDir}/extensions`);
|
|
102
|
+
const extensionInstallSpecs = await resolveExtensionInstallSpecs(selected.extensionPackages);
|
|
173
103
|
const installSpinner = spinner();
|
|
174
104
|
installSpinner.start(`Installing required extensions (${selected.extensionPackages.length} packages)`);
|
|
175
105
|
try {
|
|
176
|
-
const installedPackages = await manager.installMany(
|
|
106
|
+
const installedPackages = await manager.installMany(extensionInstallSpecs);
|
|
177
107
|
for (const installed of installedPackages) {
|
|
178
108
|
upsertAllowListPackage(next, installed.packageName, true);
|
|
179
109
|
}
|
|
@@ -183,52 +113,12 @@ export async function runInitCommand() {
|
|
|
183
113
|
installSpinner.stop("Extension installation failed");
|
|
184
114
|
throw error;
|
|
185
115
|
}
|
|
186
|
-
const catalog = await loadContributionSchemaCatalog(configPath, next);
|
|
187
|
-
const schemaByContributionId = new Map(catalog
|
|
188
|
-
.filter((item) => item.configSchema)
|
|
189
|
-
.map((item) => [item.contributionId, item.configSchema]));
|
|
190
|
-
const schemaStateByContributionId = new Map(catalog.map((item) => [item.contributionId, item.configSchema ? "with_schema" : "without_schema"]));
|
|
191
|
-
const warnedSchemaFallback = new Set();
|
|
192
|
-
const noteSchemaFallback = async (contributionId) => {
|
|
193
|
-
if (warnedSchemaFallback.has(contributionId)) {
|
|
194
|
-
const existingState = schemaStateByContributionId.get(contributionId);
|
|
195
|
-
return existingState === "without_schema" ? "without_schema" : "not_loaded";
|
|
196
|
-
}
|
|
197
|
-
warnedSchemaFallback.add(contributionId);
|
|
198
|
-
const state = schemaStateByContributionId.get(contributionId);
|
|
199
|
-
if (state === "without_schema") {
|
|
200
|
-
await note(`Contribution '${contributionId}' is loaded but does not expose configSchema. Falling back to built-in defaults/JSON.`, "Schema");
|
|
201
|
-
return "without_schema";
|
|
202
|
-
}
|
|
203
|
-
await note(`No loaded schema for contribution '${contributionId}'. The extension may be disabled or not installed.`, "Schema");
|
|
204
|
-
return "not_loaded";
|
|
205
|
-
};
|
|
206
|
-
const resolveFallbackConfig = async (kind, instanceId, contributionId, fallbackConfig) => {
|
|
207
|
-
const state = await noteSchemaFallback(contributionId);
|
|
208
|
-
if (state === "not_loaded") {
|
|
209
|
-
throw new Error(`Cannot initialize ${kind} '${instanceId}' because schema for contribution '${contributionId}' is not loaded. ` +
|
|
210
|
-
`Ensure the extension is installed and enabled, then retry.`);
|
|
211
|
-
}
|
|
212
|
-
return fallbackConfig;
|
|
213
|
-
};
|
|
214
116
|
for (const provider of selected.providerInstances) {
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
})
|
|
220
|
-
: await resolveFallbackConfig("provider", provider.instanceId, provider.contributionId, provider.config);
|
|
221
|
-
upsertProviderInstance(next, provider.instanceId, provider.contributionId, providerConfig);
|
|
117
|
+
upsertProviderInstance(next, provider.instanceId, provider.contributionId, provider.config);
|
|
118
|
+
}
|
|
119
|
+
for (const connector of selected.connectorInstances) {
|
|
120
|
+
upsertConnectorInstance(next, connector.instanceId, connector.contributionId, connector.config);
|
|
222
121
|
}
|
|
223
|
-
const connectorSchema = schemaByContributionId.get(selected.connectorContributionId);
|
|
224
|
-
const connectorConfig = selected.connectorContributionId === "connector.discord"
|
|
225
|
-
? selected.connectorConfig
|
|
226
|
-
: connectorSchema
|
|
227
|
-
? await promptConfigFromSchema(connectorSchema, selected.connectorConfig, {
|
|
228
|
-
title: `Connector '${selected.connectorInstanceId}' (${selected.connectorContributionId})`,
|
|
229
|
-
})
|
|
230
|
-
: await resolveFallbackConfig("connector", selected.connectorInstanceId, selected.connectorContributionId, selected.connectorConfig);
|
|
231
|
-
upsertConnectorInstance(next, selected.connectorInstanceId, selected.connectorContributionId, connectorConfig);
|
|
232
122
|
next.providers = {
|
|
233
123
|
...next.providers,
|
|
234
124
|
default: selected.providerInstanceId,
|
|
@@ -236,51 +126,31 @@ export async function runInitCommand() {
|
|
|
236
126
|
};
|
|
237
127
|
next.routes = {
|
|
238
128
|
...next.routes,
|
|
239
|
-
|
|
240
|
-
...next.routes.
|
|
241
|
-
|
|
129
|
+
default: {
|
|
130
|
+
...next.routes.default,
|
|
131
|
+
...selected.routeDefaults,
|
|
242
132
|
},
|
|
243
133
|
};
|
|
244
|
-
upsertRoute(next,
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
}
|
|
255
|
-
const resolvedProvider = validatedConfig.providers?.items?.[provider.instanceId];
|
|
256
|
-
const { type: _type, ...providerConfig } = resolvedProvider ?? {};
|
|
257
|
-
const ensured = await ensureProviderPiModelsFile(configPath, Object.keys(providerConfig).length > 0 ? providerConfig : provider.config);
|
|
258
|
-
if (ensured.created) {
|
|
259
|
-
createdModelsFiles.push(ensured.path);
|
|
260
|
-
}
|
|
134
|
+
upsertRoute(next, selected.routeId, selected.routeProfile);
|
|
135
|
+
if (selected.defaultBinding) {
|
|
136
|
+
next.bindings = {
|
|
137
|
+
...next.bindings,
|
|
138
|
+
default: selected.defaultBinding,
|
|
139
|
+
items: next.bindings.items,
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
for (const binding of selected.bindings) {
|
|
143
|
+
upsertBinding(next, binding.id, binding.config);
|
|
261
144
|
}
|
|
145
|
+
const validatedConfig = await applyAndValidateContributionSchemas(configPath, next);
|
|
262
146
|
await writeConfigWithValidation(configPath, validatedConfig, {
|
|
263
147
|
validate: true,
|
|
264
148
|
createBackup: false,
|
|
265
149
|
});
|
|
266
150
|
outro("Initialization completed.");
|
|
267
151
|
console.log(`Config written: ${configPath}`);
|
|
268
|
-
if (createdModelsFiles.length > 0) {
|
|
269
|
-
console.log("Generated model files:");
|
|
270
|
-
for (const path of createdModelsFiles) {
|
|
271
|
-
console.log(`- ${path}`);
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
152
|
console.log("Next steps:");
|
|
275
|
-
console.log("1.
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
initialValue: true,
|
|
279
|
-
});
|
|
280
|
-
if (!isCancel(showHint) && showHint) {
|
|
281
|
-
await note([
|
|
282
|
-
"dobby extension list",
|
|
283
|
-
"dobby doctor",
|
|
284
|
-
].join("\n"), "Validation");
|
|
285
|
-
}
|
|
153
|
+
console.log("1. Edit gateway.json and replace all REPLACE_WITH_* / YOUR_* placeholders");
|
|
154
|
+
console.log("2. Run 'dobby doctor' to validate the edited config");
|
|
155
|
+
console.log("3. Run 'dobby start' when the placeholders are replaced");
|
|
286
156
|
}
|
|
@@ -2,6 +2,13 @@ import { BUILTIN_HOST_SANDBOX_ID } from "../../core/types.js";
|
|
|
2
2
|
import { ensureGatewayConfigShape, upsertBinding, upsertRoute, } from "../shared/config-mutators.js";
|
|
3
3
|
import { DISCORD_CONNECTOR_CONTRIBUTION_ID } from "../shared/discord-config.js";
|
|
4
4
|
import { requireRawConfig, resolveConfigPath, writeConfigWithValidation } from "../shared/config-io.js";
|
|
5
|
+
function effectiveRouteProjectRoot(normalized, routeId) {
|
|
6
|
+
const route = normalized.routes.items[routeId];
|
|
7
|
+
if (!route) {
|
|
8
|
+
return undefined;
|
|
9
|
+
}
|
|
10
|
+
return route.projectRoot ?? normalized.routes.default.projectRoot;
|
|
11
|
+
}
|
|
5
12
|
function listDiscordConnectors(rawConfig) {
|
|
6
13
|
const normalized = ensureGatewayConfigShape(rawConfig);
|
|
7
14
|
const items = [];
|
|
@@ -36,11 +43,11 @@ function getDiscordConnectorOrThrow(rawConfig, connectorId) {
|
|
|
36
43
|
}
|
|
37
44
|
function listBindings(rawConfig, connectorFilter) {
|
|
38
45
|
const normalized = ensureGatewayConfigShape(rawConfig);
|
|
39
|
-
const
|
|
40
|
-
return Object.entries(normalized.bindings.items)
|
|
46
|
+
const bindings = Object.entries(normalized.bindings.items)
|
|
41
47
|
.filter(([, binding]) => !connectorFilter || binding.connector === connectorFilter)
|
|
42
48
|
.map(([bindingId, binding]) => {
|
|
43
|
-
const route = routes[binding.route];
|
|
49
|
+
const route = normalized.routes.items[binding.route];
|
|
50
|
+
const projectRoot = route ? effectiveRouteProjectRoot(normalized, binding.route) : undefined;
|
|
44
51
|
return {
|
|
45
52
|
bindingId,
|
|
46
53
|
connectorId: binding.connector,
|
|
@@ -48,14 +55,27 @@ function listBindings(rawConfig, connectorFilter) {
|
|
|
48
55
|
sourceId: binding.source.id,
|
|
49
56
|
routeId: binding.route,
|
|
50
57
|
routeExists: Boolean(route),
|
|
51
|
-
...(
|
|
58
|
+
...(projectRoot ? { projectRoot } : {}),
|
|
52
59
|
};
|
|
53
|
-
})
|
|
54
|
-
|
|
60
|
+
});
|
|
61
|
+
if (!connectorFilter && normalized.bindings.default) {
|
|
62
|
+
const projectRoot = effectiveRouteProjectRoot(normalized, normalized.bindings.default.route);
|
|
63
|
+
bindings.push({
|
|
64
|
+
bindingId: "bindings.default",
|
|
65
|
+
connectorId: "*",
|
|
66
|
+
sourceType: "direct_message",
|
|
67
|
+
sourceId: "*",
|
|
68
|
+
routeId: normalized.bindings.default.route,
|
|
69
|
+
routeExists: Boolean(normalized.routes.items[normalized.bindings.default.route]),
|
|
70
|
+
...(projectRoot ? { projectRoot } : {}),
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
return bindings.sort((a, b) => a.bindingId.localeCompare(b.bindingId));
|
|
55
74
|
}
|
|
56
75
|
function buildRouteBindingCounts(rawConfig) {
|
|
76
|
+
const normalized = ensureGatewayConfigShape(rawConfig);
|
|
57
77
|
const counts = new Map();
|
|
58
|
-
for (const binding of listBindings(
|
|
78
|
+
for (const binding of listBindings(normalized)) {
|
|
59
79
|
counts.set(binding.routeId, (counts.get(binding.routeId) ?? 0) + 1);
|
|
60
80
|
}
|
|
61
81
|
return counts;
|
|
@@ -66,7 +86,7 @@ function listRoutes(rawConfig) {
|
|
|
66
86
|
return Object.entries(normalized.routes.items)
|
|
67
87
|
.map(([routeId, route]) => ({
|
|
68
88
|
routeId,
|
|
69
|
-
projectRoot:
|
|
89
|
+
projectRoot: effectiveRouteProjectRoot(normalized, routeId) ?? "(unset)",
|
|
70
90
|
tools: route.tools === "readonly" ? "readonly" : "full",
|
|
71
91
|
mentions: route.mentions === "optional" ? "optional" : "required",
|
|
72
92
|
...(route.provider ? { provider: route.provider } : {}),
|
|
@@ -205,7 +225,7 @@ export async function runRouteSetCommand(options) {
|
|
|
205
225
|
const normalized = ensureGatewayConfigShape(structuredClone(rawConfig));
|
|
206
226
|
const existing = normalized.routes.items[options.routeId];
|
|
207
227
|
const projectRoot = options.projectRoot?.trim() || existing?.projectRoot;
|
|
208
|
-
if (!projectRoot) {
|
|
228
|
+
if (!projectRoot && !normalized.routes.default.projectRoot) {
|
|
209
229
|
throw new Error("--project-root is required when creating a new route");
|
|
210
230
|
}
|
|
211
231
|
const toolsRaw = options.tools ?? existing?.tools;
|
|
@@ -221,7 +241,7 @@ export async function runRouteSetCommand(options) {
|
|
|
221
241
|
throw new Error(`Sandbox '${sandbox}' does not exist`);
|
|
222
242
|
}
|
|
223
243
|
upsertRoute(normalized, options.routeId, {
|
|
224
|
-
projectRoot,
|
|
244
|
+
...(projectRoot ? { projectRoot } : {}),
|
|
225
245
|
...(toolsRaw ? { tools: toolsRaw } : {}),
|
|
226
246
|
...((options.mentions ?? existing?.mentions) ? { mentions: (options.mentions ?? existing?.mentions) } : {}),
|
|
227
247
|
...(provider ? { provider } : {}),
|
|
@@ -238,15 +258,19 @@ export async function runRouteRemoveCommand(options) {
|
|
|
238
258
|
if (!normalized.routes.items[options.routeId]) {
|
|
239
259
|
throw new Error(`Route '${options.routeId}' not found`);
|
|
240
260
|
}
|
|
241
|
-
const bindingRefs = listBindings(normalized).filter((binding) => binding.routeId === options.routeId);
|
|
242
|
-
|
|
261
|
+
const bindingRefs = listBindings(normalized).filter((binding) => binding.routeId === options.routeId && binding.bindingId !== "bindings.default");
|
|
262
|
+
const hasDefaultBindingRef = normalized.bindings.default?.route === options.routeId;
|
|
263
|
+
if ((bindingRefs.length > 0 || hasDefaultBindingRef) && !options.cascadeBindings) {
|
|
243
264
|
const refList = bindingRefs.map((binding) => binding.bindingId).join(", ");
|
|
244
|
-
throw new Error(`Route '${options.routeId}' is referenced by bindings (${refList}). Re-run with --cascade-bindings to remove these bindings automatically.`);
|
|
265
|
+
throw new Error(`Route '${options.routeId}' is referenced by bindings (${[refList, hasDefaultBindingRef ? "bindings.default" : ""].filter(Boolean).join(", ")}). Re-run with --cascade-bindings to remove these bindings automatically.`);
|
|
245
266
|
}
|
|
246
|
-
if (
|
|
267
|
+
if (options.cascadeBindings) {
|
|
247
268
|
for (const binding of bindingRefs) {
|
|
248
269
|
delete normalized.bindings.items[binding.bindingId];
|
|
249
270
|
}
|
|
271
|
+
if (hasDefaultBindingRef) {
|
|
272
|
+
delete normalized.bindings.default;
|
|
273
|
+
}
|
|
250
274
|
}
|
|
251
275
|
delete normalized.routes.items[options.routeId];
|
|
252
276
|
await saveConfig(configPath, normalized);
|
package/dist/src/cli/program.js
CHANGED
|
@@ -1,12 +1,22 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
2
|
+
import { fileURLToPath } from "node:url";
|
|
1
3
|
import { Command } from "commander";
|
|
2
|
-
import {
|
|
3
|
-
import { runConfigureCommand } from "./commands/configure.js";
|
|
4
|
+
import { runConfigListCommand, runConfigSchemaListCommand, runConfigSchemaShowCommand, runConfigShowCommand, } from "./commands/config.js";
|
|
4
5
|
import { runCronAddCommand, runCronListCommand, runCronPauseCommand, runCronRemoveCommand, runCronResumeCommand, runCronRunCommand, runCronStatusCommand, runCronUpdateCommand, } from "./commands/cron.js";
|
|
5
6
|
import { runDoctorCommand } from "./commands/doctor.js";
|
|
6
7
|
import { runExtensionInstallCommand, runExtensionListCommand, runExtensionUninstallCommand, } from "./commands/extension.js";
|
|
7
8
|
import { runInitCommand } from "./commands/init.js";
|
|
8
9
|
import { runStartCommand } from "./commands/start.js";
|
|
9
|
-
|
|
10
|
+
function loadCliVersion() {
|
|
11
|
+
const candidates = [
|
|
12
|
+
fileURLToPath(new URL("../../package.json", import.meta.url)),
|
|
13
|
+
fileURLToPath(new URL("../../../package.json", import.meta.url)),
|
|
14
|
+
];
|
|
15
|
+
const fallbackCandidate = fileURLToPath(new URL("../../package.json", import.meta.url));
|
|
16
|
+
const packageJsonPath = candidates.find((candidate) => existsSync(candidate)) ?? fallbackCandidate;
|
|
17
|
+
return JSON.parse(readFileSync(packageJsonPath, "utf-8")).version;
|
|
18
|
+
}
|
|
19
|
+
const CLI_VERSION = loadCliVersion();
|
|
10
20
|
/**
|
|
11
21
|
* Builds the top-level dobby CLI program and registers all subcommands.
|
|
12
22
|
*/
|
|
@@ -14,6 +24,7 @@ export function buildProgram() {
|
|
|
14
24
|
const program = new Command();
|
|
15
25
|
program
|
|
16
26
|
.name("dobby")
|
|
27
|
+
.version(CLI_VERSION)
|
|
17
28
|
.description("Discord-first local agent gateway")
|
|
18
29
|
.showHelpAfterError()
|
|
19
30
|
.action(async () => {
|
|
@@ -31,125 +42,7 @@ export function buildProgram() {
|
|
|
31
42
|
.action(async () => {
|
|
32
43
|
await runInitCommand();
|
|
33
44
|
});
|
|
34
|
-
program
|
|
35
|
-
.command("configure")
|
|
36
|
-
.description("Interactive configuration wizard")
|
|
37
|
-
.option("--section <section>", "Config section (repeatable): provider|connector|route|binding|sandbox|data", (value, previous) => [...previous, value], [])
|
|
38
|
-
.action(async (opts) => {
|
|
39
|
-
await runConfigureCommand({
|
|
40
|
-
sections: opts.section,
|
|
41
|
-
});
|
|
42
|
-
});
|
|
43
|
-
const botCommand = program.command("bot").description("Manage bot connector settings");
|
|
44
|
-
botCommand
|
|
45
|
-
.command("list")
|
|
46
|
-
.description("List configured bot connectors")
|
|
47
|
-
.option("--json", "Output JSON", false)
|
|
48
|
-
.action(async (opts) => {
|
|
49
|
-
await runBotListCommand({
|
|
50
|
-
json: Boolean(opts.json),
|
|
51
|
-
});
|
|
52
|
-
});
|
|
53
|
-
botCommand
|
|
54
|
-
.command("set")
|
|
55
|
-
.description("Update one bot connector")
|
|
56
|
-
.argument("<connectorId>", "Connector instance ID")
|
|
57
|
-
.option("--name <name>", "Discord botName")
|
|
58
|
-
.option("--token <token>", "Discord botToken")
|
|
59
|
-
.action(async (connectorId, opts) => {
|
|
60
|
-
await runBotSetCommand({
|
|
61
|
-
connectorId,
|
|
62
|
-
...(typeof opts.name === "string" ? { name: opts.name } : {}),
|
|
63
|
-
...(typeof opts.token === "string" ? { token: opts.token } : {}),
|
|
64
|
-
});
|
|
65
|
-
});
|
|
66
|
-
const bindingCommand = program.command("binding").description("Manage connector source-route bindings");
|
|
67
|
-
bindingCommand
|
|
68
|
-
.command("list")
|
|
69
|
-
.description("List bindings")
|
|
70
|
-
.option("--connector <id>", "Filter by connector instance ID")
|
|
71
|
-
.option("--json", "Output JSON", false)
|
|
72
|
-
.action(async (opts) => {
|
|
73
|
-
await runBindingListCommand({
|
|
74
|
-
...(typeof opts.connector === "string" ? { connectorId: opts.connector } : {}),
|
|
75
|
-
json: Boolean(opts.json),
|
|
76
|
-
});
|
|
77
|
-
});
|
|
78
|
-
bindingCommand
|
|
79
|
-
.command("set")
|
|
80
|
-
.description("Create or update one binding")
|
|
81
|
-
.argument("<bindingId>", "Binding ID")
|
|
82
|
-
.requiredOption("--connector <id>", "Connector instance ID")
|
|
83
|
-
.requiredOption("--source-type <type>", "Source type: channel|chat")
|
|
84
|
-
.requiredOption("--source-id <id>", "Source ID")
|
|
85
|
-
.requiredOption("--route <id>", "Route ID")
|
|
86
|
-
.action(async (bindingId, opts) => {
|
|
87
|
-
if (opts.sourceType !== "channel" && opts.sourceType !== "chat") {
|
|
88
|
-
throw new Error("--source-type must be channel or chat");
|
|
89
|
-
}
|
|
90
|
-
await runBindingSetCommand({
|
|
91
|
-
bindingId,
|
|
92
|
-
connectorId: opts.connector,
|
|
93
|
-
sourceType: opts.sourceType,
|
|
94
|
-
sourceId: opts.sourceId,
|
|
95
|
-
routeId: opts.route,
|
|
96
|
-
});
|
|
97
|
-
});
|
|
98
|
-
bindingCommand
|
|
99
|
-
.command("remove")
|
|
100
|
-
.description("Remove one binding")
|
|
101
|
-
.argument("<bindingId>", "Binding ID")
|
|
102
|
-
.action(async (bindingId) => {
|
|
103
|
-
await runBindingRemoveCommand({
|
|
104
|
-
bindingId,
|
|
105
|
-
});
|
|
106
|
-
});
|
|
107
|
-
const routeCommand = program.command("route").description("Manage route profiles");
|
|
108
|
-
routeCommand
|
|
109
|
-
.command("list")
|
|
110
|
-
.description("List route profiles")
|
|
111
|
-
.option("--json", "Output JSON", false)
|
|
112
|
-
.action(async (opts) => {
|
|
113
|
-
await runRouteListCommand({
|
|
114
|
-
json: Boolean(opts.json),
|
|
115
|
-
});
|
|
116
|
-
});
|
|
117
|
-
routeCommand
|
|
118
|
-
.command("set")
|
|
119
|
-
.description("Create or update one route")
|
|
120
|
-
.argument("<routeId>", "Route ID")
|
|
121
|
-
.option("--project-root <path>", "Route project root")
|
|
122
|
-
.option("--tools <profile>", "Route tools profile: full|readonly")
|
|
123
|
-
.option("--provider <id>", "Provider instance ID")
|
|
124
|
-
.option("--sandbox <id>", "Sandbox instance ID")
|
|
125
|
-
.option("--mentions <policy>", "Mention policy: required|optional")
|
|
126
|
-
.action(async (routeId, opts) => {
|
|
127
|
-
if (typeof opts.mentions === "string"
|
|
128
|
-
&& opts.mentions !== "required"
|
|
129
|
-
&& opts.mentions !== "optional") {
|
|
130
|
-
throw new Error("--mentions must be required or optional");
|
|
131
|
-
}
|
|
132
|
-
await runRouteSetCommand({
|
|
133
|
-
routeId,
|
|
134
|
-
...(typeof opts.projectRoot === "string" ? { projectRoot: opts.projectRoot } : {}),
|
|
135
|
-
...(typeof opts.tools === "string" ? { tools: opts.tools } : {}),
|
|
136
|
-
...(typeof opts.provider === "string" ? { providerId: opts.provider } : {}),
|
|
137
|
-
...(typeof opts.sandbox === "string" ? { sandboxId: opts.sandbox } : {}),
|
|
138
|
-
...(typeof opts.mentions === "string" ? { mentions: opts.mentions } : {}),
|
|
139
|
-
});
|
|
140
|
-
});
|
|
141
|
-
routeCommand
|
|
142
|
-
.command("remove")
|
|
143
|
-
.description("Remove one route")
|
|
144
|
-
.argument("<routeId>", "Route ID")
|
|
145
|
-
.option("--cascade-bindings", "Remove bindings that reference this route", false)
|
|
146
|
-
.action(async (routeId, opts) => {
|
|
147
|
-
await runRouteRemoveCommand({
|
|
148
|
-
routeId,
|
|
149
|
-
cascadeBindings: Boolean(opts.cascadeBindings),
|
|
150
|
-
});
|
|
151
|
-
});
|
|
152
|
-
const configCommand = program.command("config").description("Inspect and edit config");
|
|
45
|
+
const configCommand = program.command("config").description("Inspect config");
|
|
153
46
|
configCommand
|
|
154
47
|
.command("show")
|
|
155
48
|
.description("Show full config or one section")
|
|
@@ -172,15 +65,6 @@ export function buildProgram() {
|
|
|
172
65
|
json: Boolean(opts.json),
|
|
173
66
|
});
|
|
174
67
|
});
|
|
175
|
-
configCommand
|
|
176
|
-
.command("edit")
|
|
177
|
-
.description("Interactive edit for high-frequency sections")
|
|
178
|
-
.option("--section <section>", "Edit section (repeatable): provider|connector|route|binding", (value, previous) => [...previous, value], [])
|
|
179
|
-
.action(async (opts) => {
|
|
180
|
-
await runConfigEditCommand({
|
|
181
|
-
sections: opts.section,
|
|
182
|
-
});
|
|
183
|
-
});
|
|
184
68
|
const configSchemaCommand = configCommand.command("schema").description("Inspect extension config schemas");
|
|
185
69
|
configSchemaCommand
|
|
186
70
|
.command("list")
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { existsSync, readFileSync } from "node:fs";
|
|
2
1
|
import { access, mkdir, readFile, rename, rm, writeFile } from "node:fs/promises";
|
|
3
2
|
import { dirname, isAbsolute, resolve } from "node:path";
|
|
4
3
|
import { homedir } from "node:os";
|
|
5
4
|
import { loadGatewayConfig } from "../../core/routing.js";
|
|
5
|
+
import { findDobbyRepoRoot, isDobbyRepoRoot } from "../../shared/dobby-repo.js";
|
|
6
6
|
/**
|
|
7
7
|
* Default config file path used by all CLI commands.
|
|
8
8
|
*/
|
|
@@ -19,25 +19,6 @@ function expandHome(value) {
|
|
|
19
19
|
}
|
|
20
20
|
return value;
|
|
21
21
|
}
|
|
22
|
-
/**
|
|
23
|
-
* Returns true when a directory looks like the dobby repository root.
|
|
24
|
-
*/
|
|
25
|
-
function isDobbyRepoRoot(candidateDir) {
|
|
26
|
-
const packageJsonPath = resolve(candidateDir, "package.json");
|
|
27
|
-
const repoConfigPath = resolve(candidateDir, "config", "gateway.json");
|
|
28
|
-
const localExtensionsScriptPath = resolve(candidateDir, "scripts", "local-extensions.mjs");
|
|
29
|
-
if (!existsSync(packageJsonPath) || !existsSync(repoConfigPath) || !existsSync(localExtensionsScriptPath)) {
|
|
30
|
-
return false;
|
|
31
|
-
}
|
|
32
|
-
try {
|
|
33
|
-
const packageJsonRaw = readFileSync(packageJsonPath, "utf-8");
|
|
34
|
-
const parsed = JSON.parse(packageJsonRaw);
|
|
35
|
-
return parsed.name === "dobby";
|
|
36
|
-
}
|
|
37
|
-
catch {
|
|
38
|
-
return false;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
22
|
function resolveConfigBaseDir(configPath) {
|
|
42
23
|
const absoluteConfigPath = resolve(configPath);
|
|
43
24
|
const configDir = dirname(absoluteConfigPath);
|
|
@@ -51,17 +32,8 @@ function resolveConfigBaseDir(configPath) {
|
|
|
51
32
|
* Scans current directory and ancestors to find a local dobby repo config path.
|
|
52
33
|
*/
|
|
53
34
|
function findDobbyRepoConfigPath(startDir) {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
if (isDobbyRepoRoot(currentDir)) {
|
|
57
|
-
return resolve(currentDir, "config", "gateway.json");
|
|
58
|
-
}
|
|
59
|
-
const parentDir = dirname(currentDir);
|
|
60
|
-
if (parentDir === currentDir) {
|
|
61
|
-
return null;
|
|
62
|
-
}
|
|
63
|
-
currentDir = parentDir;
|
|
64
|
-
}
|
|
35
|
+
const repoRoot = findDobbyRepoRoot(startDir);
|
|
36
|
+
return repoRoot ? resolve(repoRoot, "config", "gateway.json") : null;
|
|
65
37
|
}
|
|
66
38
|
/**
|
|
67
39
|
* Resolves config path source by priority: env override -> local repo -> default home path.
|