@base44-preview/cli 0.0.34-pr.279.d7fb404 → 0.0.34-pr.279.ea8c0ac
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 -58
- package/dist/cli/index.js.map +7 -7
- 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
|
-
|
|
215383
|
-
|
|
215384
|
-
|
|
215385
|
-
|
|
215404
|
+
const deleted = [];
|
|
215405
|
+
for (const [name2, entry] of nameToEntry) {
|
|
215406
|
+
if (!newNames.has(name2)) {
|
|
215407
|
+
await deleteFile(entry.filePath);
|
|
215408
|
+
deleted.push(name2);
|
|
215409
|
+
}
|
|
215410
|
+
}
|
|
215411
|
+
const claimedPaths = new Set;
|
|
215412
|
+
for (const [name2, entry] of nameToEntry) {
|
|
215413
|
+
if (newNames.has(name2)) {
|
|
215414
|
+
claimedPaths.add(entry.filePath);
|
|
215386
215415
|
}
|
|
215387
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
|
};
|
|
@@ -226206,16 +226239,27 @@ function parseFields(fields) {
|
|
|
226206
226239
|
}
|
|
226207
226240
|
return Object.keys(projection).length > 0 ? projection : undefined;
|
|
226208
226241
|
}
|
|
226242
|
+
function stripInternalFields(doc2) {
|
|
226243
|
+
const { _id, ...rest } = doc2;
|
|
226244
|
+
return rest;
|
|
226245
|
+
}
|
|
226209
226246
|
function createEntityRoutes(db2, logger, remoteProxy, broadcast) {
|
|
226210
226247
|
const router = import_express2.Router({ mergeParams: true });
|
|
226211
226248
|
const parseBody = import_express2.json();
|
|
226212
226249
|
function emit(appId, entityName, type, data) {
|
|
226213
|
-
|
|
226250
|
+
const createData = (item) => ({
|
|
226214
226251
|
type,
|
|
226215
|
-
data,
|
|
226216
|
-
id:
|
|
226252
|
+
data: item,
|
|
226253
|
+
id: item.id,
|
|
226217
226254
|
timestamp: new Date().toISOString()
|
|
226218
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));
|
|
226219
226263
|
}
|
|
226220
226264
|
router.get("/User/me", (req, res, next) => {
|
|
226221
226265
|
req.url = req.originalUrl;
|
|
@@ -226234,7 +226278,7 @@ function createEntityRoutes(db2, logger, remoteProxy, broadcast) {
|
|
|
226234
226278
|
res.status(404).json({ error: `Record with id "${id2}" not found` });
|
|
226235
226279
|
return;
|
|
226236
226280
|
}
|
|
226237
|
-
res.json(doc2);
|
|
226281
|
+
res.json(stripInternalFields(doc2));
|
|
226238
226282
|
} catch (error48) {
|
|
226239
226283
|
logger.error(`Error in GET /${entityName}/${id2}:`, error48);
|
|
226240
226284
|
res.status(500).json({ error: "Internal server error" });
|
|
@@ -226280,7 +226324,7 @@ function createEntityRoutes(db2, logger, remoteProxy, broadcast) {
|
|
|
226280
226324
|
cursor3 = cursor3.projection(projection);
|
|
226281
226325
|
}
|
|
226282
226326
|
const docs = await cursor3;
|
|
226283
|
-
res.json(docs);
|
|
226327
|
+
res.json(docs.map(stripInternalFields));
|
|
226284
226328
|
} catch (error48) {
|
|
226285
226329
|
logger.error(`Error in GET /${entityName}:`, error48);
|
|
226286
226330
|
res.status(500).json({ error: "Internal server error" });
|
|
@@ -226303,7 +226347,7 @@ function createEntityRoutes(db2, logger, remoteProxy, broadcast) {
|
|
|
226303
226347
|
};
|
|
226304
226348
|
const inserted = await collection.insertAsync(record2);
|
|
226305
226349
|
emit(appId, entityName, "create", inserted);
|
|
226306
|
-
res.status(201).json(inserted);
|
|
226350
|
+
res.status(201).json(stripInternalFields(inserted));
|
|
226307
226351
|
} catch (error48) {
|
|
226308
226352
|
logger.error(`Error in POST /${entityName}:`, error48);
|
|
226309
226353
|
res.status(500).json({ error: "Internal server error" });
|
|
@@ -226328,14 +226372,8 @@ function createEntityRoutes(db2, logger, remoteProxy, broadcast) {
|
|
|
226328
226372
|
created_date: now,
|
|
226329
226373
|
updated_date: now
|
|
226330
226374
|
}));
|
|
226331
|
-
const inserted =
|
|
226332
|
-
|
|
226333
|
-
const doc2 = await collection.insertAsync(record2);
|
|
226334
|
-
inserted.push(doc2);
|
|
226335
|
-
}
|
|
226336
|
-
for (const doc2 of inserted) {
|
|
226337
|
-
emit(appId, entityName, "create", doc2);
|
|
226338
|
-
}
|
|
226375
|
+
const inserted = (await collection.insertAsync(records)).map(stripInternalFields);
|
|
226376
|
+
emit(appId, entityName, "create", inserted);
|
|
226339
226377
|
res.status(201).json(inserted);
|
|
226340
226378
|
} catch (error48) {
|
|
226341
226379
|
logger.error(`Error in POST /${entityName}/bulk:`, error48);
|
|
@@ -226349,20 +226387,19 @@ function createEntityRoutes(db2, logger, remoteProxy, broadcast) {
|
|
|
226349
226387
|
res.status(404).json({ error: `Entity "${entityName}" not found` });
|
|
226350
226388
|
return;
|
|
226351
226389
|
}
|
|
226390
|
+
const { id: _id, ...body } = req.body;
|
|
226352
226391
|
try {
|
|
226353
226392
|
const updateData = {
|
|
226354
|
-
...
|
|
226393
|
+
...body,
|
|
226355
226394
|
updated_date: new Date().toISOString()
|
|
226356
226395
|
};
|
|
226357
|
-
const result = await collection.updateAsync({ id: id2 }, { $set: updateData }, { returnUpdatedDocs:
|
|
226358
|
-
if (result.numAffected === 0) {
|
|
226396
|
+
const result = await collection.updateAsync({ id: id2 }, { $set: updateData }, { returnUpdatedDocs: true });
|
|
226397
|
+
if (result.numAffected === 0 || !result.affectedDocuments) {
|
|
226359
226398
|
res.status(404).json({ error: `Record with id "${id2}" not found` });
|
|
226360
226399
|
return;
|
|
226361
226400
|
}
|
|
226362
|
-
const updated =
|
|
226363
|
-
|
|
226364
|
-
emit(appId, entityName, "update", updated);
|
|
226365
|
-
}
|
|
226401
|
+
const updated = Array.isArray(result.affectedDocuments) ? result.affectedDocuments.map(stripInternalFields) : stripInternalFields(result.affectedDocuments);
|
|
226402
|
+
emit(appId, entityName, "update", updated);
|
|
226366
226403
|
res.json(updated);
|
|
226367
226404
|
} catch (error48) {
|
|
226368
226405
|
logger.error(`Error in PUT /${entityName}/${id2}:`, error48);
|
|
@@ -230855,4 +230892,4 @@ export {
|
|
|
230855
230892
|
CLIExitError
|
|
230856
230893
|
};
|
|
230857
230894
|
|
|
230858
|
-
//# debugId=
|
|
230895
|
+
//# debugId=4A9C27B9C6E48A4D64756E2164756E21
|