@base44-preview/cli 0.0.34-pr.279.558a4e6 → 0.0.34-pr.279.622bfdf
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/cli/index.js +95 -64
- package/dist/cli/index.js.map +8 -8
- package/package.json +1 -1
package/dist/cli/index.js
CHANGED
|
@@ -215342,18 +215342,16 @@ async function fetchAgents() {
|
|
|
215342
215342
|
}
|
|
215343
215343
|
// src/core/resources/agent/config.ts
|
|
215344
215344
|
import { join as join3 } from "node:path";
|
|
215345
|
-
|
|
215346
|
-
return name2.toLowerCase().replace(/[^a-z0-9_]/g, "_").replace(/_+/g, "_").replace(/^_|_$/g, "");
|
|
215347
|
-
}
|
|
215345
|
+
import { isDeepStrictEqual } from "node:util";
|
|
215348
215346
|
async function readAgentFile(agentPath) {
|
|
215349
|
-
const
|
|
215350
|
-
const result = AgentConfigSchema.safeParse(
|
|
215347
|
+
const raw2 = await readJsonFile(agentPath);
|
|
215348
|
+
const result = AgentConfigSchema.safeParse(raw2);
|
|
215351
215349
|
if (!result.success) {
|
|
215352
215350
|
throw new SchemaValidationError("Invalid agent file", result.error, agentPath);
|
|
215353
215351
|
}
|
|
215354
|
-
return result.data;
|
|
215352
|
+
return { data: result.data, raw: raw2 };
|
|
215355
215353
|
}
|
|
215356
|
-
async function
|
|
215354
|
+
async function readAgentFiles(agentsDir) {
|
|
215357
215355
|
if (!await pathExists(agentsDir)) {
|
|
215358
215356
|
return [];
|
|
215359
215357
|
}
|
|
@@ -215361,37 +215359,72 @@ async function readAllAgents(agentsDir) {
|
|
|
215361
215359
|
cwd: agentsDir,
|
|
215362
215360
|
absolute: true
|
|
215363
215361
|
});
|
|
215364
|
-
|
|
215365
|
-
|
|
215366
|
-
|
|
215367
|
-
|
|
215368
|
-
|
|
215362
|
+
return await Promise.all(files.map(async (filePath) => {
|
|
215363
|
+
const { data, raw: raw2 } = await readAgentFile(filePath);
|
|
215364
|
+
return { data, raw: raw2, filePath };
|
|
215365
|
+
}));
|
|
215366
|
+
}
|
|
215367
|
+
function buildNameToEntryMap(entries) {
|
|
215368
|
+
const nameToEntry = new Map;
|
|
215369
|
+
for (const entry of entries) {
|
|
215370
|
+
if (nameToEntry.has(entry.data.name)) {
|
|
215371
|
+
throw new InvalidInputError(`Duplicate agent name "${entry.data.name}"`, {
|
|
215372
|
+
hints: [
|
|
215373
|
+
{
|
|
215374
|
+
message: `Remove duplicate agents with name "${entry.data.name}" - only one agent per name is allowed`
|
|
215375
|
+
}
|
|
215376
|
+
]
|
|
215377
|
+
});
|
|
215378
|
+
}
|
|
215379
|
+
nameToEntry.set(entry.data.name, entry);
|
|
215380
|
+
}
|
|
215381
|
+
return nameToEntry;
|
|
215382
|
+
}
|
|
215383
|
+
async function readAllAgents(agentsDir) {
|
|
215384
|
+
const entries = await readAgentFiles(agentsDir);
|
|
215385
|
+
const nameToEntry = buildNameToEntryMap(entries);
|
|
215386
|
+
return [...nameToEntry.values()].map((e2) => e2.data);
|
|
215387
|
+
}
|
|
215388
|
+
function findAvailablePath(agentsDir, name2, claimedPaths) {
|
|
215389
|
+
const base = join3(agentsDir, `${name2}.${CONFIG_FILE_EXTENSION}`);
|
|
215390
|
+
if (!claimedPaths.has(base)) {
|
|
215391
|
+
return base;
|
|
215392
|
+
}
|
|
215393
|
+
for (let i = 1;; i++) {
|
|
215394
|
+
const candidate = join3(agentsDir, `${name2}_${i}.${CONFIG_FILE_EXTENSION}`);
|
|
215395
|
+
if (!claimedPaths.has(candidate)) {
|
|
215396
|
+
return candidate;
|
|
215369
215397
|
}
|
|
215370
|
-
names.add(agent.name);
|
|
215371
215398
|
}
|
|
215372
|
-
return agents;
|
|
215373
215399
|
}
|
|
215374
215400
|
async function writeAgents(agentsDir, remoteAgents) {
|
|
215375
|
-
const
|
|
215401
|
+
const entries = await readAgentFiles(agentsDir);
|
|
215402
|
+
const nameToEntry = buildNameToEntryMap(entries);
|
|
215376
215403
|
const newNames = new Set(remoteAgents.map((a) => a.name));
|
|
215377
|
-
const
|
|
215378
|
-
for (const
|
|
215379
|
-
|
|
215380
|
-
|
|
215381
|
-
|
|
215382
|
-
absolute: true
|
|
215383
|
-
});
|
|
215384
|
-
for (const filePath of files) {
|
|
215385
|
-
await deleteFile(filePath);
|
|
215404
|
+
const deleted = [];
|
|
215405
|
+
for (const [name2, entry] of nameToEntry) {
|
|
215406
|
+
if (!newNames.has(name2)) {
|
|
215407
|
+
await deleteFile(entry.filePath);
|
|
215408
|
+
deleted.push(name2);
|
|
215386
215409
|
}
|
|
215387
215410
|
}
|
|
215411
|
+
const claimedPaths = new Set;
|
|
215412
|
+
for (const [name2, entry] of nameToEntry) {
|
|
215413
|
+
if (newNames.has(name2)) {
|
|
215414
|
+
claimedPaths.add(entry.filePath);
|
|
215415
|
+
}
|
|
215416
|
+
}
|
|
215417
|
+
const written = [];
|
|
215388
215418
|
for (const agent of remoteAgents) {
|
|
215389
|
-
const
|
|
215390
|
-
|
|
215419
|
+
const existing = nameToEntry.get(agent.name);
|
|
215420
|
+
if (existing && isDeepStrictEqual(existing.raw, agent)) {
|
|
215421
|
+
continue;
|
|
215422
|
+
}
|
|
215423
|
+
const filePath = existing?.filePath ?? findAvailablePath(agentsDir, agent.name, claimedPaths);
|
|
215424
|
+
claimedPaths.add(filePath);
|
|
215391
215425
|
await writeJsonFile(filePath, agent);
|
|
215426
|
+
written.push(agent.name);
|
|
215392
215427
|
}
|
|
215393
|
-
const written = remoteAgents.map((a) => a.name);
|
|
215394
|
-
const deleted = toDelete.map((a) => a.name);
|
|
215395
215428
|
return { written, deleted };
|
|
215396
215429
|
}
|
|
215397
215430
|
// src/core/resources/agent/resource.ts
|
|
@@ -215608,7 +215641,7 @@ async function removeConnector(integrationType) {
|
|
|
215608
215641
|
}
|
|
215609
215642
|
// src/core/resources/connector/config.ts
|
|
215610
215643
|
import { join as join4 } from "node:path";
|
|
215611
|
-
import { isDeepStrictEqual } from "node:util";
|
|
215644
|
+
import { isDeepStrictEqual as isDeepStrictEqual2 } from "node:util";
|
|
215612
215645
|
async function readConnectorFile(connectorPath) {
|
|
215613
215646
|
const parsed = await readJsonFile(connectorPath);
|
|
215614
215647
|
const result = ConnectorResourceSchema.safeParse(parsed);
|
|
@@ -215669,7 +215702,7 @@ async function writeConnectors(connectorsDir, remoteConnectors) {
|
|
|
215669
215702
|
type: connector.integrationType,
|
|
215670
215703
|
scopes: connector.scopes
|
|
215671
215704
|
};
|
|
215672
|
-
if (existing &&
|
|
215705
|
+
if (existing && isDeepStrictEqual2(existing.data, localConnector)) {
|
|
215673
215706
|
continue;
|
|
215674
215707
|
}
|
|
215675
215708
|
const filePath = existing?.filePath ?? join4(connectorsDir, `${connector.integrationType}.${CONFIG_FILE_EXTENSION}`);
|
|
@@ -224085,14 +224118,11 @@ async function pullAgentsAction() {
|
|
|
224085
224118
|
successMessage: "Agents fetched successfully",
|
|
224086
224119
|
errorMessage: "Failed to fetch agents"
|
|
224087
224120
|
});
|
|
224088
|
-
|
|
224089
|
-
return { outroMessage: "No agents found on Base44" };
|
|
224090
|
-
}
|
|
224091
|
-
const { written, deleted } = await runTask("Writing agent files", async () => {
|
|
224121
|
+
const { written, deleted } = await runTask("Syncing agent files", async () => {
|
|
224092
224122
|
return await writeAgents(agentsDir, remoteAgents.items);
|
|
224093
224123
|
}, {
|
|
224094
|
-
successMessage: "Agent files
|
|
224095
|
-
errorMessage: "Failed to
|
|
224124
|
+
successMessage: "Agent files synced successfully",
|
|
224125
|
+
errorMessage: "Failed to sync agent files"
|
|
224096
224126
|
});
|
|
224097
224127
|
if (written.length > 0) {
|
|
224098
224128
|
R2.success(`Written: ${written.join(", ")}`);
|
|
@@ -224100,6 +224130,9 @@ async function pullAgentsAction() {
|
|
|
224100
224130
|
if (deleted.length > 0) {
|
|
224101
224131
|
R2.warn(`Deleted: ${deleted.join(", ")}`);
|
|
224102
224132
|
}
|
|
224133
|
+
if (written.length === 0 && deleted.length === 0) {
|
|
224134
|
+
R2.info("All agents are already up to date");
|
|
224135
|
+
}
|
|
224103
224136
|
return {
|
|
224104
224137
|
outroMessage: `Pulled ${remoteAgents.total} agents to ${agentsDir}`
|
|
224105
224138
|
};
|
|
@@ -226116,12 +226149,6 @@ class Database {
|
|
|
226116
226149
|
getCollection(name2) {
|
|
226117
226150
|
return this.collections.get(name2);
|
|
226118
226151
|
}
|
|
226119
|
-
hasCollection(name2) {
|
|
226120
|
-
return this.collections.has(name2);
|
|
226121
|
-
}
|
|
226122
|
-
getEntityNames() {
|
|
226123
|
-
return [...this.collections.keys()];
|
|
226124
|
-
}
|
|
226125
226152
|
}
|
|
226126
226153
|
|
|
226127
226154
|
// node_modules/socket.io/wrapper.mjs
|
|
@@ -226212,16 +226239,27 @@ function parseFields(fields) {
|
|
|
226212
226239
|
}
|
|
226213
226240
|
return Object.keys(projection).length > 0 ? projection : undefined;
|
|
226214
226241
|
}
|
|
226242
|
+
function stripInternalFields(doc2) {
|
|
226243
|
+
const { _id, ...rest } = doc2;
|
|
226244
|
+
return rest;
|
|
226245
|
+
}
|
|
226215
226246
|
function createEntityRoutes(db2, logger, remoteProxy, broadcast) {
|
|
226216
226247
|
const router = import_express2.Router({ mergeParams: true });
|
|
226217
226248
|
const parseBody = import_express2.json();
|
|
226218
226249
|
function emit(appId, entityName, type, data) {
|
|
226219
|
-
|
|
226250
|
+
const createData = (item) => ({
|
|
226220
226251
|
type,
|
|
226221
|
-
data,
|
|
226222
|
-
id:
|
|
226252
|
+
data: item,
|
|
226253
|
+
id: item.id,
|
|
226223
226254
|
timestamp: new Date().toISOString()
|
|
226224
226255
|
});
|
|
226256
|
+
if (Array.isArray(data)) {
|
|
226257
|
+
for (const item of data) {
|
|
226258
|
+
broadcast(appId, entityName, createData(item));
|
|
226259
|
+
}
|
|
226260
|
+
return;
|
|
226261
|
+
}
|
|
226262
|
+
broadcast(appId, entityName, createData(data));
|
|
226225
226263
|
}
|
|
226226
226264
|
router.get("/User/me", (req, res, next) => {
|
|
226227
226265
|
req.url = req.originalUrl;
|
|
@@ -226240,7 +226278,7 @@ function createEntityRoutes(db2, logger, remoteProxy, broadcast) {
|
|
|
226240
226278
|
res.status(404).json({ error: `Record with id "${id2}" not found` });
|
|
226241
226279
|
return;
|
|
226242
226280
|
}
|
|
226243
|
-
res.json(doc2);
|
|
226281
|
+
res.json(stripInternalFields(doc2));
|
|
226244
226282
|
} catch (error48) {
|
|
226245
226283
|
logger.error(`Error in GET /${entityName}/${id2}:`, error48);
|
|
226246
226284
|
res.status(500).json({ error: "Internal server error" });
|
|
@@ -226286,7 +226324,7 @@ function createEntityRoutes(db2, logger, remoteProxy, broadcast) {
|
|
|
226286
226324
|
cursor3 = cursor3.projection(projection);
|
|
226287
226325
|
}
|
|
226288
226326
|
const docs = await cursor3;
|
|
226289
|
-
res.json(docs);
|
|
226327
|
+
res.json(docs.map(stripInternalFields));
|
|
226290
226328
|
} catch (error48) {
|
|
226291
226329
|
logger.error(`Error in GET /${entityName}:`, error48);
|
|
226292
226330
|
res.status(500).json({ error: "Internal server error" });
|
|
@@ -226309,7 +226347,7 @@ function createEntityRoutes(db2, logger, remoteProxy, broadcast) {
|
|
|
226309
226347
|
};
|
|
226310
226348
|
const inserted = await collection.insertAsync(record2);
|
|
226311
226349
|
emit(appId, entityName, "create", inserted);
|
|
226312
|
-
res.status(201).json(inserted);
|
|
226350
|
+
res.status(201).json(stripInternalFields(inserted));
|
|
226313
226351
|
} catch (error48) {
|
|
226314
226352
|
logger.error(`Error in POST /${entityName}:`, error48);
|
|
226315
226353
|
res.status(500).json({ error: "Internal server error" });
|
|
@@ -226334,14 +226372,8 @@ function createEntityRoutes(db2, logger, remoteProxy, broadcast) {
|
|
|
226334
226372
|
created_date: now,
|
|
226335
226373
|
updated_date: now
|
|
226336
226374
|
}));
|
|
226337
|
-
const inserted =
|
|
226338
|
-
|
|
226339
|
-
const doc2 = await collection.insertAsync(record2);
|
|
226340
|
-
inserted.push(doc2);
|
|
226341
|
-
}
|
|
226342
|
-
for (const doc2 of inserted) {
|
|
226343
|
-
emit(appId, entityName, "create", doc2);
|
|
226344
|
-
}
|
|
226375
|
+
const inserted = (await collection.insertAsync(records)).map(stripInternalFields);
|
|
226376
|
+
emit(appId, entityName, "create", inserted);
|
|
226345
226377
|
res.status(201).json(inserted);
|
|
226346
226378
|
} catch (error48) {
|
|
226347
226379
|
logger.error(`Error in POST /${entityName}/bulk:`, error48);
|
|
@@ -226355,20 +226387,19 @@ function createEntityRoutes(db2, logger, remoteProxy, broadcast) {
|
|
|
226355
226387
|
res.status(404).json({ error: `Entity "${entityName}" not found` });
|
|
226356
226388
|
return;
|
|
226357
226389
|
}
|
|
226390
|
+
const { id: _id, ...body } = req.body;
|
|
226358
226391
|
try {
|
|
226359
226392
|
const updateData = {
|
|
226360
|
-
...
|
|
226393
|
+
...body,
|
|
226361
226394
|
updated_date: new Date().toISOString()
|
|
226362
226395
|
};
|
|
226363
|
-
const result = await collection.updateAsync({ id: id2 }, { $set: updateData }, { returnUpdatedDocs:
|
|
226364
|
-
if (result.numAffected === 0) {
|
|
226396
|
+
const result = await collection.updateAsync({ id: id2 }, { $set: updateData }, { returnUpdatedDocs: true });
|
|
226397
|
+
if (result.numAffected === 0 || !result.affectedDocuments) {
|
|
226365
226398
|
res.status(404).json({ error: `Record with id "${id2}" not found` });
|
|
226366
226399
|
return;
|
|
226367
226400
|
}
|
|
226368
|
-
const updated =
|
|
226369
|
-
|
|
226370
|
-
emit(appId, entityName, "update", updated);
|
|
226371
|
-
}
|
|
226401
|
+
const updated = Array.isArray(result.affectedDocuments) ? result.affectedDocuments.map(stripInternalFields) : stripInternalFields(result.affectedDocuments);
|
|
226402
|
+
emit(appId, entityName, "update", updated);
|
|
226372
226403
|
res.json(updated);
|
|
226373
226404
|
} catch (error48) {
|
|
226374
226405
|
logger.error(`Error in PUT /${entityName}/${id2}:`, error48);
|
|
@@ -230861,4 +230892,4 @@ export {
|
|
|
230861
230892
|
CLIExitError
|
|
230862
230893
|
};
|
|
230863
230894
|
|
|
230864
|
-
//# debugId=
|
|
230895
|
+
//# debugId=4A9C27B9C6E48A4D64756E2164756E21
|