@dobby.ai/dobby 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (136) hide show
  1. package/README.md +20 -7
  2. package/dist/src/agent/event-forwarder.js +185 -16
  3. package/dist/src/cli/commands/cron.js +39 -35
  4. package/dist/src/cli/program.js +0 -6
  5. package/dist/src/core/types.js +2 -0
  6. package/dist/src/cron/config.js +2 -2
  7. package/dist/src/cron/service.js +87 -23
  8. package/dist/src/cron/store.js +1 -1
  9. package/package.json +9 -3
  10. package/.env.example +0 -8
  11. package/AGENTS.md +0 -267
  12. package/ROADMAP.md +0 -34
  13. package/config/cron.example.json +0 -9
  14. package/config/gateway.example.json +0 -132
  15. package/dist/plugins/connector-discord/src/mapper.js +0 -75
  16. package/dist/src/cli/tests/config-command.test.js +0 -42
  17. package/dist/src/cli/tests/config-io.test.js +0 -64
  18. package/dist/src/cli/tests/config-mutators.test.js +0 -47
  19. package/dist/src/cli/tests/discord-mapper.test.js +0 -90
  20. package/dist/src/cli/tests/doctor.test.js +0 -252
  21. package/dist/src/cli/tests/init-catalog.test.js +0 -134
  22. package/dist/src/cli/tests/program-options.test.js +0 -78
  23. package/dist/src/cli/tests/routing-config.test.js +0 -254
  24. package/dist/src/core/tests/control-command.test.js +0 -17
  25. package/dist/src/core/tests/runtime-registry.test.js +0 -116
  26. package/dist/src/core/tests/typing-controller.test.js +0 -103
  27. package/docs/BOXLITE_SANDBOX_FEASIBILITY.md +0 -175
  28. package/docs/CRON_SCHEDULER_DESIGN.md +0 -374
  29. package/docs/DOCKER_SANDBOX_vs_BOXLITE.md +0 -77
  30. package/docs/EXTENSION_SYSTEM_ARCHITECTURE.md +0 -119
  31. package/docs/MVP.md +0 -135
  32. package/docs/RUNBOOK.md +0 -243
  33. package/docs/TEAMWORK_HANDOFF_DESIGN.md +0 -440
  34. package/plugins/connector-discord/dobby.manifest.json +0 -18
  35. package/plugins/connector-discord/index.js +0 -1
  36. package/plugins/connector-discord/package-lock.json +0 -360
  37. package/plugins/connector-discord/package.json +0 -38
  38. package/plugins/connector-discord/src/connector.ts +0 -345
  39. package/plugins/connector-discord/src/contribution.ts +0 -21
  40. package/plugins/connector-discord/src/mapper.ts +0 -101
  41. package/plugins/connector-discord/tsconfig.json +0 -19
  42. package/plugins/connector-feishu/dobby.manifest.json +0 -18
  43. package/plugins/connector-feishu/index.js +0 -1
  44. package/plugins/connector-feishu/package-lock.json +0 -618
  45. package/plugins/connector-feishu/package.json +0 -38
  46. package/plugins/connector-feishu/src/connector.ts +0 -343
  47. package/plugins/connector-feishu/src/contribution.ts +0 -26
  48. package/plugins/connector-feishu/src/mapper.ts +0 -401
  49. package/plugins/connector-feishu/tsconfig.json +0 -19
  50. package/plugins/plugin-sdk/index.d.ts +0 -261
  51. package/plugins/plugin-sdk/index.js +0 -1
  52. package/plugins/plugin-sdk/package-lock.json +0 -12
  53. package/plugins/plugin-sdk/package.json +0 -22
  54. package/plugins/provider-claude/dobby.manifest.json +0 -17
  55. package/plugins/provider-claude/index.js +0 -1
  56. package/plugins/provider-claude/package-lock.json +0 -3398
  57. package/plugins/provider-claude/package.json +0 -39
  58. package/plugins/provider-claude/src/contribution.ts +0 -1018
  59. package/plugins/provider-claude/tsconfig.json +0 -19
  60. package/plugins/provider-claude-cli/dobby.manifest.json +0 -17
  61. package/plugins/provider-claude-cli/index.js +0 -1
  62. package/plugins/provider-claude-cli/package-lock.json +0 -2898
  63. package/plugins/provider-claude-cli/package.json +0 -38
  64. package/plugins/provider-claude-cli/src/contribution.ts +0 -1673
  65. package/plugins/provider-claude-cli/tsconfig.json +0 -19
  66. package/plugins/provider-pi/dobby.manifest.json +0 -17
  67. package/plugins/provider-pi/index.js +0 -1
  68. package/plugins/provider-pi/package-lock.json +0 -3877
  69. package/plugins/provider-pi/package.json +0 -40
  70. package/plugins/provider-pi/src/contribution.ts +0 -606
  71. package/plugins/provider-pi/tsconfig.json +0 -19
  72. package/plugins/sandbox-core/boxlite.js +0 -1
  73. package/plugins/sandbox-core/dobby.manifest.json +0 -17
  74. package/plugins/sandbox-core/docker.js +0 -1
  75. package/plugins/sandbox-core/package-lock.json +0 -136
  76. package/plugins/sandbox-core/package.json +0 -39
  77. package/plugins/sandbox-core/src/boxlite-context.ts +0 -2
  78. package/plugins/sandbox-core/src/boxlite-contribution.ts +0 -53
  79. package/plugins/sandbox-core/src/boxlite-executor.ts +0 -911
  80. package/plugins/sandbox-core/src/docker-contribution.ts +0 -43
  81. package/plugins/sandbox-core/src/docker-executor.ts +0 -217
  82. package/plugins/sandbox-core/tsconfig.json +0 -19
  83. package/scripts/local-extensions.mjs +0 -168
  84. package/src/agent/event-forwarder.ts +0 -414
  85. package/src/cli/commands/config.ts +0 -328
  86. package/src/cli/commands/configure.ts +0 -92
  87. package/src/cli/commands/cron.ts +0 -410
  88. package/src/cli/commands/doctor.ts +0 -331
  89. package/src/cli/commands/extension.ts +0 -207
  90. package/src/cli/commands/init.ts +0 -211
  91. package/src/cli/commands/start.ts +0 -223
  92. package/src/cli/commands/topology.ts +0 -415
  93. package/src/cli/index.ts +0 -9
  94. package/src/cli/program.ts +0 -314
  95. package/src/cli/shared/config-io.ts +0 -245
  96. package/src/cli/shared/config-mutators.ts +0 -470
  97. package/src/cli/shared/config-schema.ts +0 -228
  98. package/src/cli/shared/config-types.ts +0 -129
  99. package/src/cli/shared/configure-sections.ts +0 -595
  100. package/src/cli/shared/discord-config.ts +0 -14
  101. package/src/cli/shared/init-catalog.ts +0 -249
  102. package/src/cli/shared/local-extension-specs.ts +0 -108
  103. package/src/cli/shared/runtime.ts +0 -33
  104. package/src/cli/shared/schema-prompts.ts +0 -443
  105. package/src/cli/tests/config-command.test.ts +0 -56
  106. package/src/cli/tests/config-io.test.ts +0 -92
  107. package/src/cli/tests/config-mutators.test.ts +0 -59
  108. package/src/cli/tests/discord-mapper.test.ts +0 -128
  109. package/src/cli/tests/doctor.test.ts +0 -269
  110. package/src/cli/tests/init-catalog.test.ts +0 -144
  111. package/src/cli/tests/program-options.test.ts +0 -95
  112. package/src/cli/tests/routing-config.test.ts +0 -281
  113. package/src/core/control-command.ts +0 -12
  114. package/src/core/dedup-store.ts +0 -103
  115. package/src/core/gateway.ts +0 -609
  116. package/src/core/routing.ts +0 -404
  117. package/src/core/runtime-registry.ts +0 -141
  118. package/src/core/tests/control-command.test.ts +0 -20
  119. package/src/core/tests/runtime-registry.test.ts +0 -140
  120. package/src/core/tests/typing-controller.test.ts +0 -129
  121. package/src/core/types.ts +0 -324
  122. package/src/core/typing-controller.ts +0 -119
  123. package/src/cron/config.ts +0 -154
  124. package/src/cron/schedule.ts +0 -61
  125. package/src/cron/service.ts +0 -249
  126. package/src/cron/store.ts +0 -155
  127. package/src/cron/types.ts +0 -60
  128. package/src/extension/loader.ts +0 -145
  129. package/src/extension/manager.ts +0 -355
  130. package/src/extension/manifest.ts +0 -26
  131. package/src/extension/registry.ts +0 -229
  132. package/src/main.ts +0 -8
  133. package/src/sandbox/executor.ts +0 -44
  134. package/src/sandbox/host-executor.ts +0 -118
  135. package/src/shared/dobby-repo.ts +0 -48
  136. package/tsconfig.json +0 -18
@@ -1,443 +0,0 @@
1
- import {
2
- cancel,
3
- confirm,
4
- isCancel,
5
- multiselect,
6
- note,
7
- password,
8
- select,
9
- text,
10
- } from "@clack/prompts";
11
- import JSON5 from "json5";
12
-
13
- interface PromptConfigFromSchemaOptions {
14
- title?: string;
15
- promptDefaultedFields?: boolean;
16
- }
17
-
18
- interface FieldPromptDescriptor {
19
- key: string;
20
- schema: Record<string, unknown>;
21
- required: boolean;
22
- hasDefault: boolean;
23
- existingValue: unknown;
24
- initialValue: unknown;
25
- }
26
-
27
- function isRecord(value: unknown): value is Record<string, unknown> {
28
- return Boolean(value) && typeof value === "object" && !Array.isArray(value);
29
- }
30
-
31
- function isPrimitive(value: unknown): value is string | number | boolean {
32
- return typeof value === "string" || typeof value === "number" || typeof value === "boolean";
33
- }
34
-
35
- function stringifyPreview(value: unknown): string {
36
- if (typeof value === "string") {
37
- return value;
38
- }
39
- if (isPrimitive(value)) {
40
- return String(value);
41
- }
42
- if (value === undefined) {
43
- return "";
44
- }
45
- return JSON.stringify(value);
46
- }
47
-
48
- function schemaType(schema: Record<string, unknown>): string | undefined {
49
- const raw = schema.type;
50
- if (typeof raw === "string") {
51
- return raw;
52
- }
53
- if (Array.isArray(raw)) {
54
- const firstStringType = raw.find((item) => typeof item === "string");
55
- return typeof firstStringType === "string" ? firstStringType : undefined;
56
- }
57
- return undefined;
58
- }
59
-
60
- function schemaEnum(schema: Record<string, unknown>): Array<string | number | boolean> | null {
61
- if (!Array.isArray(schema.enum)) {
62
- return null;
63
- }
64
-
65
- const normalized = schema.enum.filter((item) => isPrimitive(item)) as Array<string | number | boolean>;
66
- return normalized.length > 0 ? normalized : null;
67
- }
68
-
69
- function schemaRequiredSet(schema: Record<string, unknown>): Set<string> {
70
- if (!Array.isArray(schema.required)) {
71
- return new Set<string>();
72
- }
73
- return new Set(schema.required.filter((item) => typeof item === "string"));
74
- }
75
-
76
- function schemaProperties(schema: Record<string, unknown>): Record<string, Record<string, unknown>> {
77
- if (!isRecord(schema.properties)) {
78
- return {};
79
- }
80
-
81
- const result: Record<string, Record<string, unknown>> = {};
82
- for (const [key, value] of Object.entries(schema.properties)) {
83
- if (isRecord(value)) {
84
- result[key] = value;
85
- }
86
- }
87
- return result;
88
- }
89
-
90
- function hasSchemaDefault(schema: Record<string, unknown>): boolean {
91
- return Object.prototype.hasOwnProperty.call(schema, "default");
92
- }
93
-
94
- function shouldPromptInMinimalMode(field: FieldPromptDescriptor): boolean {
95
- if (!field.hasDefault && field.required) {
96
- return true;
97
- }
98
-
99
- if (field.existingValue !== undefined) {
100
- return true;
101
- }
102
-
103
- return false;
104
- }
105
-
106
- function isSensitiveStringField(key: string): boolean {
107
- return /(token|secret|api[-_]?key)$/i.test(key);
108
- }
109
-
110
- async function promptNumberField(params: {
111
- message: string;
112
- required: boolean;
113
- initialValue: unknown;
114
- integer: boolean;
115
- existingValue: unknown;
116
- }): Promise<number | undefined> {
117
- while (true) {
118
- const result = await text({
119
- message: params.message,
120
- initialValue: stringifyPreview(params.initialValue),
121
- placeholder: params.integer ? "integer" : "number",
122
- });
123
- if (isCancel(result)) {
124
- cancel("Configuration cancelled.");
125
- throw new Error("Configuration cancelled.");
126
- }
127
-
128
- const raw = String(result ?? "").trim();
129
- if (raw.length === 0) {
130
- if (params.required && params.existingValue === undefined) {
131
- await note("This field is required.", "Validation");
132
- continue;
133
- }
134
- return typeof params.existingValue === "number" ? params.existingValue : undefined;
135
- }
136
-
137
- const parsed = Number(raw);
138
- if (!Number.isFinite(parsed)) {
139
- await note("Please enter a valid number.", "Validation");
140
- continue;
141
- }
142
- if (params.integer && !Number.isInteger(parsed)) {
143
- await note("Please enter an integer.", "Validation");
144
- continue;
145
- }
146
- return parsed;
147
- }
148
- }
149
-
150
- async function promptJsonField(params: {
151
- message: string;
152
- required: boolean;
153
- initialValue: unknown;
154
- expected: "object" | "array";
155
- existingValue: unknown;
156
- }): Promise<unknown> {
157
- while (true) {
158
- const result = await text({
159
- message: params.message,
160
- initialValue: stringifyPreview(params.initialValue),
161
- placeholder: params.expected === "object" ? '{"key":"value"}' : '["value"]',
162
- });
163
- if (isCancel(result)) {
164
- cancel("Configuration cancelled.");
165
- throw new Error("Configuration cancelled.");
166
- }
167
-
168
- const raw = String(result ?? "").trim();
169
- if (raw.length === 0) {
170
- if (params.required && params.existingValue === undefined) {
171
- await note("This field is required.", "Validation");
172
- continue;
173
- }
174
- return params.existingValue;
175
- }
176
-
177
- try {
178
- const parsed = JSON5.parse(raw);
179
- if (params.expected === "object" && (!parsed || typeof parsed !== "object" || Array.isArray(parsed))) {
180
- await note("Please enter a JSON object.", "Validation");
181
- continue;
182
- }
183
- if (params.expected === "array" && !Array.isArray(parsed)) {
184
- await note("Please enter a JSON array.", "Validation");
185
- continue;
186
- }
187
- return parsed;
188
- } catch (error) {
189
- await note(`Invalid JSON: ${error instanceof Error ? error.message : String(error)}`, "Validation");
190
- }
191
- }
192
- }
193
-
194
- async function promptArrayField(params: {
195
- key: string;
196
- schema: Record<string, unknown>;
197
- required: boolean;
198
- initialValue: unknown;
199
- existingValue: unknown;
200
- }): Promise<unknown> {
201
- const itemSchema = isRecord(params.schema.items) ? params.schema.items : {};
202
- const itemEnum = schemaEnum(itemSchema);
203
- if (itemEnum && itemEnum.length > 0) {
204
- const current = Array.isArray(params.initialValue) ? params.initialValue : [];
205
- const initialValues = current.filter((item) => itemEnum.includes(item as string | number | boolean))
206
- .map((item) => String(item));
207
- const result = await multiselect({
208
- message: `${params.key}${params.required ? " (required)" : ""}`,
209
- options: itemEnum.map((item) => ({
210
- value: String(item),
211
- label: String(item),
212
- })),
213
- initialValues,
214
- required: params.required,
215
- });
216
- if (isCancel(result)) {
217
- cancel("Configuration cancelled.");
218
- throw new Error("Configuration cancelled.");
219
- }
220
-
221
- return (result as string[]).map((value) => itemEnum.find((candidate) => String(candidate) === value) ?? value);
222
- }
223
-
224
- return promptJsonField({
225
- message: `${params.key}${params.required ? " (required)" : ""} (JSON array)`,
226
- required: params.required,
227
- initialValue: params.initialValue,
228
- expected: "array",
229
- existingValue: params.existingValue,
230
- });
231
- }
232
-
233
- async function promptFieldValue(params: {
234
- key: string;
235
- schema: Record<string, unknown>;
236
- required: boolean;
237
- initialValue: unknown;
238
- existingValue: unknown;
239
- }): Promise<unknown> {
240
- const { key, schema, required, initialValue, existingValue } = params;
241
- const enumValues = schemaEnum(schema);
242
- const type = schemaType(schema);
243
- const description = typeof schema.description === "string" ? schema.description.trim() : "";
244
- const message = `${key}${required ? " (required)" : ""}${description ? ` - ${description}` : ""}`;
245
-
246
- if (enumValues && enumValues.length > 0) {
247
- const fallback = enumValues[0]!;
248
- const initialCandidate = enumValues.includes(initialValue as string | number | boolean)
249
- ? (initialValue as string | number | boolean)
250
- : enumValues.includes(existingValue as string | number | boolean)
251
- ? (existingValue as string | number | boolean)
252
- : fallback;
253
- const result = await select({
254
- message,
255
- options: enumValues.map((value) => ({
256
- value: String(value),
257
- label: String(value),
258
- })),
259
- initialValue: String(initialCandidate),
260
- });
261
- if (isCancel(result)) {
262
- cancel("Configuration cancelled.");
263
- throw new Error("Configuration cancelled.");
264
- }
265
- return enumValues.find((value) => String(value) === String(result)) ?? result;
266
- }
267
-
268
- if (type === "boolean") {
269
- const result = await confirm({
270
- message,
271
- initialValue: typeof initialValue === "boolean"
272
- ? initialValue
273
- : typeof existingValue === "boolean"
274
- ? existingValue
275
- : false,
276
- });
277
- if (isCancel(result)) {
278
- cancel("Configuration cancelled.");
279
- throw new Error("Configuration cancelled.");
280
- }
281
- return result === true;
282
- }
283
-
284
- if (type === "integer" || type === "number") {
285
- return promptNumberField({
286
- message,
287
- required,
288
- initialValue,
289
- integer: type === "integer",
290
- existingValue,
291
- });
292
- }
293
-
294
- if (type === "array") {
295
- return promptArrayField({
296
- key,
297
- schema,
298
- required,
299
- initialValue,
300
- existingValue,
301
- });
302
- }
303
-
304
- if (type === "object") {
305
- return promptJsonField({
306
- message: `${message} (JSON object)`,
307
- required,
308
- initialValue,
309
- expected: "object",
310
- existingValue,
311
- });
312
- }
313
-
314
- if (isSensitiveStringField(key)) {
315
- while (true) {
316
- const result = await password({
317
- message,
318
- mask: "*",
319
- });
320
- if (isCancel(result)) {
321
- cancel("Configuration cancelled.");
322
- throw new Error("Configuration cancelled.");
323
- }
324
-
325
- const raw = String(result ?? "").trim();
326
- if (raw.length === 0) {
327
- if (required && existingValue === undefined) {
328
- await note("This field is required.", "Validation");
329
- continue;
330
- }
331
- return existingValue;
332
- }
333
-
334
- return raw;
335
- }
336
- }
337
-
338
- while (true) {
339
- const result = await text({
340
- message,
341
- initialValue: stringifyPreview(initialValue),
342
- });
343
- if (isCancel(result)) {
344
- cancel("Configuration cancelled.");
345
- throw new Error("Configuration cancelled.");
346
- }
347
-
348
- const raw = String(result ?? "").trim();
349
- if (raw.length === 0) {
350
- if (required && existingValue === undefined) {
351
- await note("This field is required.", "Validation");
352
- continue;
353
- }
354
- return existingValue;
355
- }
356
-
357
- return raw;
358
- }
359
- }
360
-
361
- /**
362
- * Prompts one extension config object from a contribution JSON Schema.
363
- * Currently supports top-level schema properties and falls back to JSON input for complex fields.
364
- */
365
- export async function promptConfigFromSchema(
366
- schema: Record<string, unknown>,
367
- currentConfig: Record<string, unknown>,
368
- options?: PromptConfigFromSchemaOptions,
369
- ): Promise<Record<string, unknown>> {
370
- const properties = schemaProperties(schema);
371
- const required = schemaRequiredSet(schema);
372
-
373
- if (options?.title) {
374
- await note(options.title, "Configure");
375
- }
376
-
377
- if (Object.keys(properties).length === 0) {
378
- return structuredClone(currentConfig);
379
- }
380
-
381
- const next = structuredClone(currentConfig);
382
- const fieldDescriptors: FieldPromptDescriptor[] = Object.entries(properties).map(([key, fieldSchema]) => {
383
- const existingValue = next[key];
384
- const defaultValue = fieldSchema.default;
385
- const initialValue = existingValue !== undefined ? existingValue : defaultValue;
386
- return {
387
- key,
388
- schema: fieldSchema,
389
- required: required.has(key),
390
- hasDefault: hasSchemaDefault(fieldSchema),
391
- existingValue,
392
- initialValue,
393
- };
394
- });
395
-
396
- const minimalFields = fieldDescriptors.filter((field) => shouldPromptInMinimalMode(field));
397
- const advancedFields = fieldDescriptors.filter((field) => !minimalFields.includes(field));
398
-
399
- for (const field of minimalFields) {
400
- const value = await promptFieldValue({
401
- key: field.key,
402
- schema: field.schema,
403
- required: field.required,
404
- initialValue: field.initialValue,
405
- existingValue: field.existingValue,
406
- });
407
- if (value === undefined) {
408
- continue;
409
- }
410
- next[field.key] = value;
411
- }
412
-
413
- if (advancedFields.length > 0) {
414
- const shouldPromptAdvanced = options?.promptDefaultedFields === true
415
- ? true
416
- : await confirm({
417
- message: "Configure advanced options (defaults can be kept)?",
418
- initialValue: false,
419
- });
420
- if (isCancel(shouldPromptAdvanced)) {
421
- cancel("Configuration cancelled.");
422
- throw new Error("Configuration cancelled.");
423
- }
424
-
425
- if (shouldPromptAdvanced === true) {
426
- for (const field of advancedFields) {
427
- const value = await promptFieldValue({
428
- key: field.key,
429
- schema: field.schema,
430
- required: field.required,
431
- initialValue: field.initialValue,
432
- existingValue: field.existingValue,
433
- });
434
- if (value === undefined) {
435
- continue;
436
- }
437
- next[field.key] = value;
438
- }
439
- }
440
- }
441
-
442
- return next;
443
- }
@@ -1,56 +0,0 @@
1
- import assert from "node:assert/strict";
2
- import test from "node:test";
3
- import {
4
- buildConfigListEntries,
5
- CONFIG_SECTION_VALUES,
6
- isConfigSection,
7
- previewConfigValue,
8
- } from "../commands/config.js";
9
-
10
- test("isConfigSection accepts only supported top-level config sections", () => {
11
- for (const section of CONFIG_SECTION_VALUES) {
12
- assert.equal(isConfigSection(section), true);
13
- }
14
-
15
- assert.equal(isConfigSection("provider"), false);
16
- assert.equal(isConfigSection("bot"), false);
17
- });
18
-
19
- test("previewConfigValue returns stable compact previews", () => {
20
- assert.equal(previewConfigValue("abc"), "\"abc\"");
21
- assert.equal(previewConfigValue(123), "123");
22
- assert.equal(previewConfigValue(true), "true");
23
- assert.equal(previewConfigValue(null), "null");
24
- assert.equal(previewConfigValue({ a: 1, b: 2, c: 3, d: 4 }), "{a, b, c, ...}");
25
- });
26
-
27
- test("buildConfigListEntries summarizes object values with type and child counts", () => {
28
- const entries = buildConfigListEntries({
29
- providers: {
30
- default: "pi.main",
31
- items: {
32
- "pi.main": { type: "provider.pi" },
33
- },
34
- },
35
- featureFlag: true,
36
- });
37
-
38
- assert.deepEqual(
39
- entries.map((entry) => ({ key: entry.key, type: entry.type, children: entry.children })),
40
- [
41
- { key: "featureFlag", type: "boolean", children: undefined },
42
- { key: "providers", type: "object", children: 2 },
43
- ],
44
- );
45
- });
46
-
47
- test("buildConfigListEntries handles primitive roots", () => {
48
- const entries = buildConfigListEntries("plain");
49
- assert.deepEqual(entries, [
50
- {
51
- key: "(value)",
52
- type: "string",
53
- preview: "\"plain\"",
54
- },
55
- ]);
56
- });
@@ -1,92 +0,0 @@
1
- import assert from "node:assert/strict";
2
- import { mkdir, mkdtemp, writeFile } from "node:fs/promises";
3
- import { homedir } from "node:os";
4
- import { tmpdir } from "node:os";
5
- import { resolve } from "node:path";
6
- import test from "node:test";
7
- import { DEFAULT_CONFIG_PATH, resolveConfigPath, resolveDataRootDir } from "../shared/config-io.js";
8
-
9
- test("resolveConfigPath defaults to $HOME/.dobby/gateway.json", () => {
10
- assert.equal(DEFAULT_CONFIG_PATH, resolve(homedir(), ".dobby", "gateway.json"));
11
- });
12
-
13
- test("resolveConfigPath falls back to default path outside dobby repository", async () => {
14
- const cwd = await mkdtemp(resolve(tmpdir(), "dobby-config-path-default-"));
15
- assert.equal(resolveConfigPath({ cwd, env: {} }), DEFAULT_CONFIG_PATH);
16
- });
17
-
18
- test("resolveConfigPath detects local dobby repository config path", async () => {
19
- const repoRoot = await mkdtemp(resolve(tmpdir(), "dobby-config-path-repo-"));
20
- await mkdir(resolve(repoRoot, "config"), { recursive: true });
21
- await mkdir(resolve(repoRoot, "scripts"), { recursive: true });
22
- await mkdir(resolve(repoRoot, "src", "cli"), { recursive: true });
23
-
24
- await writeFile(resolve(repoRoot, "package.json"), JSON.stringify({ name: "@dobby.ai/dobby" }), "utf-8");
25
- await writeFile(resolve(repoRoot, "config", "gateway.example.json"), "{}\n", "utf-8");
26
- await writeFile(resolve(repoRoot, "scripts", "local-extensions.mjs"), "#!/usr/bin/env node\n", "utf-8");
27
-
28
- assert.equal(
29
- resolveConfigPath({
30
- cwd: resolve(repoRoot, "src", "cli"),
31
- env: {},
32
- }),
33
- resolve(repoRoot, "config", "gateway.json"),
34
- );
35
- });
36
-
37
- test("resolveConfigPath prioritizes DOBBY_CONFIG_PATH over repository detection", async () => {
38
- const repoRoot = await mkdtemp(resolve(tmpdir(), "dobby-config-path-env-priority-"));
39
- await mkdir(resolve(repoRoot, "config"), { recursive: true });
40
- await mkdir(resolve(repoRoot, "scripts"), { recursive: true });
41
- await writeFile(resolve(repoRoot, "package.json"), JSON.stringify({ name: "@dobby.ai/dobby" }), "utf-8");
42
- await writeFile(resolve(repoRoot, "config", "gateway.example.json"), "{}\n", "utf-8");
43
- await writeFile(resolve(repoRoot, "scripts", "local-extensions.mjs"), "#!/usr/bin/env node\n", "utf-8");
44
-
45
- const customPath = resolve(tmpdir(), "dobby-custom-gateway.json");
46
- assert.equal(
47
- resolveConfigPath({
48
- cwd: repoRoot,
49
- env: { DOBBY_CONFIG_PATH: customPath },
50
- }),
51
- customPath,
52
- );
53
- });
54
-
55
- test("resolveConfigPath supports relative and home-prefixed DOBBY_CONFIG_PATH", async () => {
56
- const cwd = await mkdtemp(resolve(tmpdir(), "dobby-config-path-env-expand-"));
57
-
58
- assert.equal(
59
- resolveConfigPath({
60
- cwd,
61
- env: { DOBBY_CONFIG_PATH: "config/local-gateway.json" },
62
- }),
63
- resolve(cwd, "config/local-gateway.json"),
64
- );
65
-
66
- assert.equal(
67
- resolveConfigPath({
68
- cwd,
69
- env: { DOBBY_CONFIG_PATH: "~/custom-gateway.json" },
70
- }),
71
- resolve(homedir(), "custom-gateway.json"),
72
- );
73
- });
74
-
75
- test("resolveDataRootDir uses repo root for repo-local config/gateway.json", async () => {
76
- const repoRoot = await mkdtemp(resolve(tmpdir(), "dobby-data-root-repo-"));
77
- await mkdir(resolve(repoRoot, "config"), { recursive: true });
78
- await mkdir(resolve(repoRoot, "scripts"), { recursive: true });
79
-
80
- await writeFile(resolve(repoRoot, "package.json"), JSON.stringify({ name: "@dobby.ai/dobby" }), "utf-8");
81
- await writeFile(resolve(repoRoot, "config", "gateway.json"), "{}", "utf-8");
82
- await writeFile(resolve(repoRoot, "scripts", "local-extensions.mjs"), "#!/usr/bin/env node\n", "utf-8");
83
-
84
- assert.equal(
85
- resolveDataRootDir(resolve(repoRoot, "config", "gateway.json"), {
86
- data: {
87
- rootDir: "./data",
88
- },
89
- }),
90
- resolve(repoRoot, "data"),
91
- );
92
- });
@@ -1,59 +0,0 @@
1
- import test from "node:test";
2
- import assert from "node:assert/strict";
3
- import {
4
- applyContributionTemplates,
5
- ensureGatewayConfigShape,
6
- setDefaultProviderIfMissingOrInvalid,
7
- upsertAllowListPackage,
8
- } from "../shared/config-mutators.js";
9
-
10
- test("upsertAllowListPackage is idempotent", () => {
11
- const config = ensureGatewayConfigShape({});
12
- upsertAllowListPackage(config, "@dobby.ai/provider-pi", true);
13
- upsertAllowListPackage(config, "@dobby.ai/provider-pi", true);
14
-
15
- assert.equal(config.extensions?.allowList?.length, 1);
16
- assert.equal(config.extensions?.allowList?.[0]?.package, "@dobby.ai/provider-pi");
17
- assert.equal(config.extensions?.allowList?.[0]?.enabled, true);
18
- });
19
-
20
- test("applyContributionTemplates allocates new instance IDs when needed", () => {
21
- const config = ensureGatewayConfigShape({
22
- providers: {
23
- default: "pi.main",
24
- items: {
25
- "pi.main": {
26
- type: "provider.pi",
27
- },
28
- },
29
- },
30
- });
31
-
32
- const added = applyContributionTemplates(config, {
33
- providers: [
34
- { id: "pi.main", type: "provider.another", config: {} },
35
- { id: "pi.main", type: "provider.third", config: {} },
36
- ],
37
- connectors: [],
38
- sandboxes: [],
39
- });
40
-
41
- assert.deepEqual(added.providers, ["pi.main-2", "pi.main-3"]);
42
- assert.equal(config.providers.items["pi.main-2"]?.type, "provider.another");
43
- assert.equal(config.providers.items["pi.main-3"]?.type, "provider.third");
44
- });
45
-
46
- test("setDefaultProviderIfMissingOrInvalid picks lexicographically first provider", () => {
47
- const config = ensureGatewayConfigShape({
48
- providers: {
49
- default: "missing",
50
- items: {
51
- "z.main": { type: "provider.z" },
52
- "a.main": { type: "provider.a" },
53
- },
54
- },
55
- });
56
-
57
- setDefaultProviderIfMissingOrInvalid(config);
58
- assert.equal(config.providers.default, "a.main");
59
- });