@yrpri/api 9.0.137 → 9.0.139
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/agents/controllers/policySynthAgents.d.ts +2 -0
- package/agents/controllers/policySynthAgents.js +31 -0
- package/agents/managers/newAiModelSetup.js +13 -89
- package/package.json +1 -1
- package/scripts/agents/changeModelForWorkflowGroupTemplate.js +25 -2
- package/scripts/agents/generateAgentWorkflowTemplateFromAgentClass.js +3 -3
|
@@ -41,6 +41,8 @@ export declare class PolicySynthAgentsController {
|
|
|
41
41
|
controlAgent: (req: express.Request, res: express.Response) => Promise<void>;
|
|
42
42
|
getAgentStatus: (req: express.Request, res: express.Response) => Promise<void>;
|
|
43
43
|
updateAgentStatus: (req: express.Request, res: express.Response) => Promise<void>;
|
|
44
|
+
private recursiveDeleteAgent;
|
|
45
|
+
deleteAgent: (req: YpRequest, res: express.Response) => Promise<void>;
|
|
44
46
|
startAgentProcessing: (req: express.Request, res: express.Response) => Promise<void>;
|
|
45
47
|
pauseAgentProcessing: (req: express.Request, res: express.Response) => Promise<void>;
|
|
46
48
|
getAgentCosts: (req: express.Request, res: express.Response) => Promise<void>;
|
|
@@ -6,6 +6,7 @@ import { AgentConnectorManager } from "@policysynth/agents/operations/agentConne
|
|
|
6
6
|
import { AgentRegistryManager } from "@policysynth/agents/operations/agentRegistryManager.js";
|
|
7
7
|
import { PsAiModel } from "@policysynth/agents/dbModels/aiModel.js";
|
|
8
8
|
import auth from "../../authorization.cjs";
|
|
9
|
+
import { PsAgent } from "@policysynth/agents/dbModels/agent.js";
|
|
9
10
|
import { NewAiModelSetup } from "../managers/newAiModelSetup.js";
|
|
10
11
|
export class PolicySynthAgentsController {
|
|
11
12
|
constructor(wsClients) {
|
|
@@ -315,6 +316,22 @@ export class PolicySynthAgentsController {
|
|
|
315
316
|
res.status(500).send("Internal Server Error");
|
|
316
317
|
}
|
|
317
318
|
};
|
|
319
|
+
this.deleteAgent = async (req, res) => {
|
|
320
|
+
try {
|
|
321
|
+
const agentId = parseInt(req.params.agentId);
|
|
322
|
+
await this.recursiveDeleteAgent(agentId);
|
|
323
|
+
res.json({ message: "Agent deleted" });
|
|
324
|
+
}
|
|
325
|
+
catch (error) {
|
|
326
|
+
console.error("Error deleting agent:", error);
|
|
327
|
+
if (error instanceof Error) {
|
|
328
|
+
res.status(500).json({ error: error.message });
|
|
329
|
+
}
|
|
330
|
+
else {
|
|
331
|
+
res.status(500).json({ error: "An unexpected error occurred" });
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
};
|
|
318
335
|
this.startAgentProcessing = async (req, res) => {
|
|
319
336
|
const agentId = parseInt(req.params.id);
|
|
320
337
|
try {
|
|
@@ -409,5 +426,19 @@ export class PolicySynthAgentsController {
|
|
|
409
426
|
this.router.get("/:groupId/:agentId/memory", auth.can("edit group"), this.getAgentMemory);
|
|
410
427
|
this.router.post("/:groupId/:agentId/inputConnectors/existing", auth.can("edit group"), this.addExistingConnector);
|
|
411
428
|
this.router.post("/:groupId/:agentId/outputConnectors/existing", auth.can("edit group"), this.addExistingConnector);
|
|
429
|
+
this.router.delete("/:groupId/:agentId", auth.can("edit group"), this.deleteAgent);
|
|
430
|
+
}
|
|
431
|
+
async recursiveDeleteAgent(agentId) {
|
|
432
|
+
const agent = await PsAgent.findByPk(agentId, {
|
|
433
|
+
include: [{ model: PsAgent, as: "SubAgents" }],
|
|
434
|
+
});
|
|
435
|
+
if (!agent)
|
|
436
|
+
return;
|
|
437
|
+
if (agent.SubAgents) {
|
|
438
|
+
for (const sub of agent.SubAgents) {
|
|
439
|
+
await this.recursiveDeleteAgent(sub.id);
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
await agent.destroy();
|
|
412
443
|
}
|
|
413
444
|
}
|
|
@@ -371,9 +371,9 @@ export class NewAiModelSetup {
|
|
|
371
371
|
modelSize: PsAiModelSize.Medium,
|
|
372
372
|
provider: "openai",
|
|
373
373
|
prices: {
|
|
374
|
-
costInTokensPerMillion:
|
|
375
|
-
costOutTokensPerMillion:
|
|
376
|
-
costInCachedContextTokensPerMillion:
|
|
374
|
+
costInTokensPerMillion: 2.0,
|
|
375
|
+
costOutTokensPerMillion: 8.0,
|
|
376
|
+
costInCachedContextTokensPerMillion: 0.5,
|
|
377
377
|
currency: "USD",
|
|
378
378
|
},
|
|
379
379
|
maxTokensOut: 100000,
|
|
@@ -570,45 +570,8 @@ export class NewAiModelSetup {
|
|
|
570
570
|
await gemini20Flash.save();
|
|
571
571
|
console.log("Google model already exists: Gemini 2.0 Flash");
|
|
572
572
|
}
|
|
573
|
-
const
|
|
574
|
-
where: { name: "Gemini 2.5 Pro
|
|
575
|
-
});
|
|
576
|
-
const gemini25ProPreview1Config = {
|
|
577
|
-
type: PsAiModelType.TextReasoning,
|
|
578
|
-
modelSize: PsAiModelSize.Large,
|
|
579
|
-
provider: "google",
|
|
580
|
-
prices: {
|
|
581
|
-
costInTokensPerMillion: 1.25,
|
|
582
|
-
costOutTokensPerMillion: 10,
|
|
583
|
-
costInCachedContextTokensPerMillion: 0.875,
|
|
584
|
-
longContextTokenThreshold: 200000,
|
|
585
|
-
longContextCostInTokensPerMillion: 2.5,
|
|
586
|
-
longContextCostInCachedContextTokensPerMillion: 1.75,
|
|
587
|
-
longContextCostOutTokensPerMillion: 15,
|
|
588
|
-
currency: "USD",
|
|
589
|
-
},
|
|
590
|
-
model: "gemini-2.5-pro-preview-04-17",
|
|
591
|
-
active: true,
|
|
592
|
-
maxTokensOut: 100000,
|
|
593
|
-
defaultTemperature: 0.0
|
|
594
|
-
};
|
|
595
|
-
if (!gemini25ProPreview1) {
|
|
596
|
-
await PsAiModel.create({
|
|
597
|
-
name: "Gemini 2.5 Pro Preview 1",
|
|
598
|
-
organization_id: 1,
|
|
599
|
-
user_id: userId,
|
|
600
|
-
configuration: gemini25ProPreview1Config,
|
|
601
|
-
});
|
|
602
|
-
console.log("Created Google model: Gemini 2.5 Pro Preview 1");
|
|
603
|
-
}
|
|
604
|
-
else {
|
|
605
|
-
gemini25ProPreview1.set("configuration", gemini25ProPreview1Config);
|
|
606
|
-
gemini25ProPreview1.changed("configuration", true);
|
|
607
|
-
await gemini25ProPreview1.save();
|
|
608
|
-
console.log("Google model already exists: Gemini 2.5 Pro Preview 1");
|
|
609
|
-
}
|
|
610
|
-
const gemini25ProPreview2 = await PsAiModel.findOne({
|
|
611
|
-
where: { name: "Gemini 2.5 Pro Preview 2" },
|
|
573
|
+
const gemini25Pro = await PsAiModel.findOne({
|
|
574
|
+
where: { name: "Gemini 2.5 Pro" },
|
|
612
575
|
});
|
|
613
576
|
const gemini25ProConfig = {
|
|
614
577
|
type: PsAiModelType.TextReasoning,
|
|
@@ -624,14 +587,14 @@ export class NewAiModelSetup {
|
|
|
624
587
|
longContextCostOutTokensPerMillion: 15,
|
|
625
588
|
currency: "USD",
|
|
626
589
|
},
|
|
627
|
-
model: "gemini-2.5-pro
|
|
590
|
+
model: "gemini-2.5-pro",
|
|
628
591
|
active: true,
|
|
629
592
|
maxTokensOut: 100000,
|
|
630
593
|
defaultTemperature: 0.0
|
|
631
594
|
};
|
|
632
|
-
if (!
|
|
595
|
+
if (!gemini25Pro) {
|
|
633
596
|
await PsAiModel.create({
|
|
634
|
-
name: "Gemini 2.5 Pro
|
|
597
|
+
name: "Gemini 2.5 Pro",
|
|
635
598
|
organization_id: 1,
|
|
636
599
|
user_id: userId,
|
|
637
600
|
configuration: gemini25ProConfig,
|
|
@@ -639,53 +602,16 @@ export class NewAiModelSetup {
|
|
|
639
602
|
console.log("Created Google model: Gemini 2.5 Pro");
|
|
640
603
|
}
|
|
641
604
|
else {
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
await
|
|
605
|
+
gemini25Pro.set("configuration", gemini25ProConfig);
|
|
606
|
+
gemini25Pro.changed("configuration", true);
|
|
607
|
+
await gemini25Pro.save();
|
|
645
608
|
console.log("Google model already exists: Gemini 2.5 Pro");
|
|
646
609
|
}
|
|
647
|
-
const gemini25ProFinalPreview = await PsAiModel.findOne({
|
|
648
|
-
where: { name: "Gemini 2.5 Pro Final Preview" },
|
|
649
|
-
});
|
|
650
|
-
const gemini25ProFinalConfig = {
|
|
651
|
-
type: PsAiModelType.TextReasoning,
|
|
652
|
-
modelSize: PsAiModelSize.Large,
|
|
653
|
-
provider: "google",
|
|
654
|
-
prices: {
|
|
655
|
-
costInTokensPerMillion: 1.25,
|
|
656
|
-
costOutTokensPerMillion: 10,
|
|
657
|
-
costInCachedContextTokensPerMillion: 0.875,
|
|
658
|
-
longContextTokenThreshold: 200000,
|
|
659
|
-
longContextCostInTokensPerMillion: 2.5,
|
|
660
|
-
longContextCostInCachedContextTokensPerMillion: 1.75,
|
|
661
|
-
longContextCostOutTokensPerMillion: 15,
|
|
662
|
-
currency: "USD",
|
|
663
|
-
},
|
|
664
|
-
model: "gemini-2.5-pro-preview-06-05",
|
|
665
|
-
active: true,
|
|
666
|
-
maxTokensOut: 100000,
|
|
667
|
-
defaultTemperature: 0.0,
|
|
668
|
-
};
|
|
669
|
-
if (!gemini25ProFinalPreview) {
|
|
670
|
-
await PsAiModel.create({
|
|
671
|
-
name: "Gemini 2.5 Pro Final Preview",
|
|
672
|
-
organization_id: 1,
|
|
673
|
-
user_id: userId,
|
|
674
|
-
configuration: gemini25ProFinalConfig,
|
|
675
|
-
});
|
|
676
|
-
console.log("Created Google model: Gemini 2.5 Pro Final Preview");
|
|
677
|
-
}
|
|
678
|
-
else {
|
|
679
|
-
gemini25ProFinalPreview.set("configuration", gemini25ProFinalConfig);
|
|
680
|
-
gemini25ProFinalPreview.changed("configuration", true);
|
|
681
|
-
await gemini25ProFinalPreview.save();
|
|
682
|
-
console.log("Google model already exists: Gemini 2.5 Pro Final Preview");
|
|
683
|
-
}
|
|
684
610
|
const gemini25FlashPreview1 = await PsAiModel.findOne({
|
|
685
611
|
where: { name: "Gemini 2.5 Flash Preview 1" },
|
|
686
612
|
});
|
|
687
613
|
const gemini25FlashPreview1Config = {
|
|
688
|
-
type: PsAiModelType.
|
|
614
|
+
type: PsAiModelType.Text,
|
|
689
615
|
modelSize: PsAiModelSize.Medium,
|
|
690
616
|
provider: "google",
|
|
691
617
|
prices: {
|
|
@@ -858,9 +784,7 @@ export class NewAiModelSetup {
|
|
|
858
784
|
{ name: "Gemini 1.5 Pro 2", envKey: "GEMINI_API_KEY" },
|
|
859
785
|
{ name: "Gemini 1.5 Flash 2", envKey: "GEMINI_API_KEY" },
|
|
860
786
|
{ name: "Gemini 2.0 Flash", envKey: "GEMINI_API_KEY" },
|
|
861
|
-
{ name: "Gemini 2.5 Pro
|
|
862
|
-
{ name: "Gemini 2.5 Pro Preview 2", envKey: "GEMINI_API_KEY" },
|
|
863
|
-
{ name: "Gemini 2.5 Pro Final Preview", envKey: "GEMINI_API_KEY" },
|
|
787
|
+
{ name: "Gemini 2.5 Pro", envKey: "GEMINI_API_KEY" },
|
|
864
788
|
{ name: "Gemini 2.5 Flash Preview 1", envKey: "GEMINI_API_KEY" },
|
|
865
789
|
{ name: "Gemini 2.5 Flash Preview", envKey: "GEMINI_API_KEY" },
|
|
866
790
|
{ name: "o1 24", envKey: "OPENAI_API_KEY" },
|
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { initializeModels, PsAgent, PsAiModel, } from "@policysynth/agents/dbModels/index.js";
|
|
2
|
-
import { PsAiModelSize, PsAiModelType } from "@policysynth/agents/aiModelTypes.js";
|
|
2
|
+
import { PsAiModelSize, PsAiModelType, } from "@policysynth/agents/aiModelTypes.js";
|
|
3
3
|
import models from "../../models/index.cjs";
|
|
4
|
+
import { NewAiModelSetup } from "../../agents/managers/newAiModelSetup.js";
|
|
4
5
|
(async () => {
|
|
5
6
|
const [groupIdArg, sizeArg, typeArg, modelNameArg] = process.argv.slice(2);
|
|
6
7
|
if (!groupIdArg || !sizeArg || !typeArg || !modelNameArg) {
|
|
@@ -53,16 +54,38 @@ import models from "../../models/index.cjs";
|
|
|
53
54
|
if (!newModel) {
|
|
54
55
|
throw new Error(`AI model with configuration.model ${modelNameArg} not found`);
|
|
55
56
|
}
|
|
57
|
+
if (newModel.configuration?.type !== modelType ||
|
|
58
|
+
newModel.configuration?.modelSize !== size) {
|
|
59
|
+
throw new Error(`Model '${modelNameArg}' exists, but its configuration is ` +
|
|
60
|
+
`type=${newModel.configuration?.type ?? "∅"}, ` +
|
|
61
|
+
`size=${newModel.configuration?.modelSize ?? "∅"} – expected ` +
|
|
62
|
+
`${modelType}/${size}.`);
|
|
63
|
+
}
|
|
64
|
+
await NewAiModelSetup.setupApiKeysForGroup(group);
|
|
56
65
|
const privateConfig = (group.private_access_configuration ?? []);
|
|
57
66
|
for (const agent of subAgents) {
|
|
67
|
+
console.log(`Updating agent ${agent.id} to use model ${newModel.name}`);
|
|
58
68
|
const currentModels = await agent.getAiModels();
|
|
69
|
+
console.log(`Current models: ${currentModels.length}`);
|
|
59
70
|
for (const current of currentModels) {
|
|
60
71
|
const cfg = current.configuration || {};
|
|
61
72
|
if (cfg.modelSize === size && cfg.type === modelType) {
|
|
62
73
|
await agent.removeAiModel(current);
|
|
63
74
|
const entry = privateConfig.find((p) => p.aiModelId === current.id);
|
|
64
|
-
if (entry)
|
|
75
|
+
if (entry) {
|
|
76
|
+
console.log(`Updating entry ${entry.id} to use model ${newModel.name}`);
|
|
65
77
|
entry.aiModelId = newModel.id;
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
console.log(`Adding entry for agent ${agent.id} to use model ${newModel.name}`);
|
|
81
|
+
privateConfig.push({
|
|
82
|
+
aiModelId: newModel.id,
|
|
83
|
+
agentId: agent.id,
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
console.log(`Skipping model ${current.name} for agent ${agent.id} because it does not match size ${size} and type ${modelType}`);
|
|
66
89
|
}
|
|
67
90
|
}
|
|
68
91
|
await agent.addAiModel(newModel);
|
|
@@ -75,15 +75,15 @@ import { NewAiModelSetup } from "../../agents/managers/newAiModelSetup.js";
|
|
|
75
75
|
parent_agent_id: topLevelAgent.id,
|
|
76
76
|
configuration: {},
|
|
77
77
|
});
|
|
78
|
-
// Add Gemini 2.5 Pro
|
|
78
|
+
// Add Gemini 2.5 Pro model
|
|
79
79
|
const geminiReasoning = await PsAiModel.findOne({
|
|
80
|
-
where: { name: "Gemini 2.5 Pro
|
|
80
|
+
where: { name: "Gemini 2.5 Pro" },
|
|
81
81
|
});
|
|
82
82
|
if (geminiReasoning) {
|
|
83
83
|
await psAgent.addAiModel(geminiReasoning);
|
|
84
84
|
}
|
|
85
85
|
else {
|
|
86
|
-
throw new Error("Gemini 2.5 Pro
|
|
86
|
+
throw new Error("Gemini 2.5 Pro model not found");
|
|
87
87
|
}
|
|
88
88
|
// Add Gemini 2.0 Flash model
|
|
89
89
|
const geminiFlash = await PsAiModel.findOne({
|