bazis 0.98.33 → 0.99.0
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/cli/templates/module.ts +4 -64
- package/cli/templates/passport.ts +14 -18
- package/core/agent/AgentContextBuilder.ts +4 -98
- package/core/agent/AgentRegistry.ts +79 -473
- package/core/agent/AgentRuntime.ts +47 -19
- package/core/agent/AgentToolExecutor.ts +3 -3
- package/core/agent/README.md +89 -181
- package/core/agent/index.ts +3 -31
- package/core/agent/internal/AgentExecutionDriver.ts +37 -392
- package/core/agent/internal/AgentExecutionState.ts +1 -9
- package/core/agent/metadata.ts +8 -303
- package/core/agent/semantic.ts +0 -4
- package/core/agent/session/contracts.ts +5 -7
- package/core/agent/session/entities.ts +0 -1
- package/core/cache/COMPATIBILITY.md +4 -4
- package/core/cache/README.md +2 -2
- package/core/cache/SPEC.md +30 -48
- package/core/cache/decorators/Cacheable.ts +4 -3
- package/core/cache/decorators/CacheableRedis.ts +3 -4
- package/core/cache/di/classProviderHook.ts +31 -0
- package/core/cache/distributed/DistributedCache.ts +96 -25
- package/core/cache/distributed/IDistributedCache.ts +9 -0
- package/core/cache/distributed/codecs.ts +49 -2
- package/core/cache/distributed/index.ts +1 -1
- package/core/cache/errors/CacheError.ts +17 -2
- package/core/cache/http/outputRedisCacheMiddleware.ts +11 -2
- package/core/cache/index.ts +2 -6
- package/core/cache/services/cacheProxy.ts +6 -2
- package/core/generatedRuntime.ts +0 -31
- package/core/infra/cache/RedisDistributedCacheBackend.ts +3 -0
- package/core/infra/connectors/codex/CodexAppServerClient.ts +1 -1
- package/core/infra/connectors/llm.ts +15 -1
- package/core/infra/connectors/llmRouter.ts +4 -0
- package/core/infra/connectors/redis.ts +9 -1
- package/core/scripts/di-generate.ts +28 -42
- package/core/scripts/tool-codegen.ts +122 -0
- package/index.ts +3 -24
- package/package.json +1 -1
- package/core/agent/decorators/Agent.ts +0 -11
- package/core/agent/decorators/Prompt.ts +0 -11
- package/core/agent/decorators/Task.ts +0 -29
- package/core/agent/generated/catalog.ts +0 -26
- package/core/scripts/agent-codegen.ts +0 -1166
package/cli/templates/module.ts
CHANGED
|
@@ -49,30 +49,24 @@ export function buildModuleTemplates(
|
|
|
49
49
|
return [
|
|
50
50
|
...base,
|
|
51
51
|
{ relativePath: `background/${naming.module}.reporter.ts`, content: statsReporterFile(naming) },
|
|
52
|
-
{ relativePath: `ai/agents/${naming.module}Analyst.agent.ts`, content: agentFile(naming) },
|
|
53
|
-
{ relativePath: `ai/contracts/${naming.module}.brief.ts`, content: aiContractsFile(naming) },
|
|
54
52
|
{ relativePath: `ai/tools/${naming.module}Summary.tool.ts`, content: aiToolFile(naming) },
|
|
55
53
|
];
|
|
56
54
|
}
|
|
57
55
|
|
|
58
56
|
function moduleFile(n: ModuleNaming, profile: ModuleTemplateProfile): string {
|
|
59
|
-
const cacheImport = profile === "full" ? "import { cachedScoped } from \"bazis/core/cache\";\n" : "";
|
|
60
57
|
const moduleImport = "import { Module, scoped } from \"bazis/core/di\";";
|
|
61
|
-
const providerFactory = profile === "full" ? "cachedScoped" : "scoped";
|
|
62
58
|
const backgroundImport = profile === "full" ? `import { ${n.module}Reporter } from "./background/${n.module}.reporter";\n` : "";
|
|
63
59
|
const aiImports = profile === "full"
|
|
64
|
-
? `import { ${n.module}
|
|
65
|
-
import { ${n.module}SummaryTool } from "./ai/tools/${n.module}Summary.tool";
|
|
60
|
+
? `import { ${n.module}SummaryTool } from "./ai/tools/${n.module}Summary.tool";
|
|
66
61
|
`
|
|
67
62
|
: "";
|
|
68
63
|
const backgroundLine = profile === "full" ? ` background: [${n.module}Reporter],\n` : "";
|
|
69
64
|
const aiLines = profile === "full"
|
|
70
|
-
? `
|
|
71
|
-
tools: [${n.module}SummaryTool],
|
|
65
|
+
? ` tools: [${n.module}SummaryTool],
|
|
72
66
|
`
|
|
73
67
|
: "";
|
|
74
68
|
|
|
75
|
-
return `${
|
|
69
|
+
return `${moduleImport}
|
|
76
70
|
${aiImports}${backgroundImport}import { ${n.module}Controller } from "./http/${n.module}.controller";
|
|
77
71
|
import { ${n.entity} } from "./model/${n.module}.model";
|
|
78
72
|
import { ${n.module}DbContext } from "./model/${n.module}.dbContext";
|
|
@@ -86,7 +80,7 @@ import { ${n.module}Service } from "./services/${n.module}.service";
|
|
|
86
80
|
},
|
|
87
81
|
controllers: [${n.module}Controller],
|
|
88
82
|
providers: [
|
|
89
|
-
|
|
83
|
+
scoped(I${n.module}Service, ${n.module}Service),
|
|
90
84
|
],
|
|
91
85
|
${backgroundLine}${aiLines} exports: [I${n.module}Service],
|
|
92
86
|
})
|
|
@@ -402,23 +396,6 @@ export class ${n.module}Reporter extends PeriodicBackgroundService {
|
|
|
402
396
|
`;
|
|
403
397
|
}
|
|
404
398
|
|
|
405
|
-
function aiContractsFile(n: ModuleNaming): string {
|
|
406
|
-
return `import { Validator } from "bazis/library/validation";
|
|
407
|
-
|
|
408
|
-
export class Prepare${n.module}BriefRequest {
|
|
409
|
-
@Validator({ required: true, minLength: 3 })
|
|
410
|
-
topic!: string;
|
|
411
|
-
|
|
412
|
-
@Validator({ required: true, minLength: 3 })
|
|
413
|
-
audience = "operators";
|
|
414
|
-
}
|
|
415
|
-
|
|
416
|
-
export class ${n.module}BriefDocument {
|
|
417
|
-
title = "";
|
|
418
|
-
bullets: string[] = [];
|
|
419
|
-
}
|
|
420
|
-
`;
|
|
421
|
-
}
|
|
422
399
|
|
|
423
400
|
function aiToolFile(n: ModuleNaming): string {
|
|
424
401
|
return `import { Tool, type AgentToolExecutionContext } from "bazis/core/agent";
|
|
@@ -460,40 +437,3 @@ export class ${n.module}SummaryTool {
|
|
|
460
437
|
`;
|
|
461
438
|
}
|
|
462
439
|
|
|
463
|
-
function agentFile(n: ModuleNaming): string {
|
|
464
|
-
return `import { Agent, Task, agentOutput } from "bazis/core/agent";
|
|
465
|
-
import { Prepare${n.module}BriefRequest, ${n.module}BriefDocument } from "../contracts/${n.module}.brief";
|
|
466
|
-
import { ${n.module}SummaryTool } from "../tools/${n.module}Summary.tool";
|
|
467
|
-
|
|
468
|
-
@Agent({
|
|
469
|
-
name: "${n.route}-analyst",
|
|
470
|
-
role: "${n.route} analyst",
|
|
471
|
-
sections: [
|
|
472
|
-
{
|
|
473
|
-
kind: "developer",
|
|
474
|
-
content: "Write short, concrete operational summaries of the ${n.route} domain.",
|
|
475
|
-
},
|
|
476
|
-
{
|
|
477
|
-
kind: "tool-policy",
|
|
478
|
-
content: "Use read tools before the final summary. Do not make up data.",
|
|
479
|
-
},
|
|
480
|
-
],
|
|
481
|
-
tools: [${n.module}SummaryTool],
|
|
482
|
-
modelProfile: "reasoning",
|
|
483
|
-
maxSteps: 3,
|
|
484
|
-
})
|
|
485
|
-
export class ${n.module}AnalystAgent {
|
|
486
|
-
@Task({
|
|
487
|
-
name: "prepare-${n.route}-brief",
|
|
488
|
-
description: "Prepare a short ${n.route} summary from the current module data.",
|
|
489
|
-
input: Prepare${n.module}BriefRequest,
|
|
490
|
-
output: ${n.module}BriefDocument,
|
|
491
|
-
modelProfile: "reasoning",
|
|
492
|
-
maxSteps: 3,
|
|
493
|
-
})
|
|
494
|
-
prepareBrief(_input: Prepare${n.module}BriefRequest): ${n.module}BriefDocument {
|
|
495
|
-
return agentOutput();
|
|
496
|
-
}
|
|
497
|
-
}
|
|
498
|
-
`;
|
|
499
|
-
}
|
|
@@ -66,9 +66,7 @@ adapters that access it.
|
|
|
66
66
|
| ${e}Response / ${m}Summary / to${e}Response | [responses](http/contracts/${m}.responses.ts) | ORM entity | Public data projection |
|
|
67
67
|
| ${m}ListQuery | [list](http/contracts/${m}List.query.ts) | Query string | ListQuery, filters/sorting/pages |
|
|
68
68
|
${profile === "full" ? `| ${m}Reporter | [background](background/${m}.reporter.ts) | ServiceProvider, Logger, AbortSignal | Runs count and logs it |
|
|
69
|
-
| ${m}SummaryTool | [tool](ai/tools/${m}Summary.tool.ts) | I${m}Service, input, context | Summary for
|
|
70
|
-
| ${m}AnalystAgent | [agent](ai/agents/${m}Analyst.agent.ts) | Prepare${m}BriefRequest | ${m}BriefDocument via AgentRuntime |
|
|
71
|
-
| AI DTO | [contracts](ai/contracts/${m}.brief.ts) | topic, audience | title, bullets |
|
|
69
|
+
| ${m}SummaryTool | [tool](ai/tools/${m}Summary.tool.ts) | I${m}Service, input, context | Summary for an agent |
|
|
72
70
|
` : ""}
|
|
73
71
|
|
|
74
72
|
## Wiring, DI and data
|
|
@@ -78,10 +76,10 @@ exports: [I${m}Service]. TypeScript contract: services/I${e}.service.ts;
|
|
|
78
76
|
HTTP access is defined by the controller and the host policy, separately from DI exports.
|
|
79
77
|
I${m}Service → ${m}Service, scoped lifetime. The context and DbSet belong to the ORM.
|
|
80
78
|
${profile === "full" ? `${m}SummaryTool is listed in tools: [${m}SummaryTool]; the framework registers it as scoped, the tool is not exported.
|
|
81
|
-
The service
|
|
79
|
+
The service is scoped; its keyed @Cacheable works when the host installs the cache (runApp cache: memory()).
|
|
82
80
|
The background service gets its own scope per tick and disposes it in finally.
|
|
83
|
-
The host also provides auth from src/app/modules/auth (TokenKind.Admin/Client)
|
|
84
|
-
|
|
81
|
+
The host also provides auth from src/app/modules/auth (TokenKind.Admin/Client)
|
|
82
|
+
and an LLM connector, which registers AgentRuntime. The CLI does not create them.
|
|
85
83
|
` : ""}Constructor dependencies, including ${m}DbContext, are wired by codegen.
|
|
86
84
|
No manual deps arrays. UI, events and own configuration are not used.
|
|
87
85
|
|
|
@@ -167,21 +165,19 @@ AbortSignal from the runtime, creates a scope, runs count and logs it unless
|
|
|
167
165
|
the signal is aborted; dispose always runs. The SQL itself is not cancelled by
|
|
168
166
|
this signal.
|
|
169
167
|
|
|
170
|
-
Tool ${n.route}.summary: execute(input, context), sideEffect read.
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
for the runtime. Calling prepareBrief directly does not run the LLM.
|
|
168
|
+
Tool ${n.route}.summary: execute(input, context), sideEffect read. Agents are
|
|
169
|
+
data, not classes: an agent definition names the tool in toolNames and runs
|
|
170
|
+
with AgentRuntime.run(definition, { input }).
|
|
174
171
|
|
|
175
|
-
|
|
|
172
|
+
| Tool input field | Type / source | Required | null | Default | Check | Example |
|
|
176
173
|
| --- | --- | --- | --- | --- | --- | --- |
|
|
177
|
-
| topic | string / tool input
|
|
178
|
-
|
|
|
179
|
-
| context | AgentToolExecutionContext / runtime | For the tool | no | runtime | agentName comes from the server context | agentName: ${n.route}-analyst |
|
|
174
|
+
| topic | string / tool input | Yes | no | none | Validator required, minLength 3 | Daily summary |
|
|
175
|
+
| context | AgentToolExecutionContext / runtime | Yes | no | runtime | agentName comes from the running agent definition | agentName: ${n.route}-analyst |
|
|
180
176
|
|
|
181
177
|
Tool output: topic string, count number, names string[], agentName string
|
|
182
|
-
(empty when the context has no name).
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
178
|
+
(empty when the context has no name). AgentRuntime validates the tool input
|
|
179
|
+
and reports its errors to the model; the scaffold adds no own permission
|
|
180
|
+
checks. Which agents may call the tool is decided by their definitions'
|
|
181
|
+
toolNames. The scaffold does not retry the tool.
|
|
186
182
|
`;
|
|
187
183
|
}
|
|
@@ -463,105 +463,11 @@ export class DefaultAgentContextBuilder implements AgentContextBuilder {
|
|
|
463
463
|
return estimate;
|
|
464
464
|
}
|
|
465
465
|
|
|
466
|
+
/** The definition's instructions are the system prompt, sent as written. */
|
|
466
467
|
private promptMessage(agent: AgentDefinition): AgentMessage | undefined {
|
|
467
|
-
const
|
|
468
|
-
|
|
469
|
-
lines.push(`Role: ${agent.metadata.role}`);
|
|
470
|
-
}
|
|
471
|
-
if (agent.metadata.description !== undefined) {
|
|
472
|
-
lines.push(`Description: ${agent.metadata.description}`);
|
|
473
|
-
}
|
|
474
|
-
if (agent.metadata.goal !== undefined) {
|
|
475
|
-
lines.push(`Goal: ${agent.metadata.goal}`);
|
|
476
|
-
}
|
|
477
|
-
if (agent.metadata.instructions.length > 0) {
|
|
478
|
-
lines.push("Instructions:");
|
|
479
|
-
lines.push(...agent.metadata.instructions.map((item) => `- ${item}`));
|
|
480
|
-
}
|
|
481
|
-
if (agent.metadata.constraints.length > 0) {
|
|
482
|
-
lines.push("Constraints:");
|
|
483
|
-
lines.push(...agent.metadata.constraints.map((item) => `- ${item}`));
|
|
484
|
-
}
|
|
485
|
-
for (let index = 0; index < agent.metadata.sections.length; index += 1) {
|
|
486
|
-
appendPromptSection(lines, agent.metadata.sections[index] as (typeof agent.metadata.sections)[number]);
|
|
487
|
-
}
|
|
488
|
-
|
|
489
|
-
const prompt = agent.prompt?.metadata;
|
|
490
|
-
if (prompt !== undefined) {
|
|
491
|
-
if (prompt.description !== undefined) {
|
|
492
|
-
lines.push(`Prompt description: ${prompt.description}`);
|
|
493
|
-
}
|
|
494
|
-
if (prompt.version !== undefined) {
|
|
495
|
-
lines.push(`Prompt version: ${prompt.version}`);
|
|
496
|
-
}
|
|
497
|
-
if (prompt.role !== undefined) {
|
|
498
|
-
lines.push(`Prompt role: ${prompt.role}`);
|
|
499
|
-
}
|
|
500
|
-
if (prompt.goal !== undefined) {
|
|
501
|
-
lines.push(`Goal: ${prompt.goal}`);
|
|
502
|
-
}
|
|
503
|
-
if (prompt.instructions.length > 0) {
|
|
504
|
-
lines.push("Instructions:");
|
|
505
|
-
lines.push(...prompt.instructions.map((item) => `- ${item}`));
|
|
506
|
-
}
|
|
507
|
-
if (prompt.constraints.length > 0) {
|
|
508
|
-
lines.push("Constraints:");
|
|
509
|
-
lines.push(...prompt.constraints.map((item) => `- ${item}`));
|
|
510
|
-
}
|
|
511
|
-
for (let index = 0; index < prompt.sections.length; index += 1) {
|
|
512
|
-
appendPromptSection(lines, prompt.sections[index] as (typeof prompt.sections)[number]);
|
|
513
|
-
}
|
|
514
|
-
}
|
|
515
|
-
|
|
516
|
-
return lines.length === 0
|
|
468
|
+
const instructions = agent.instructions.trim();
|
|
469
|
+
return instructions.length === 0
|
|
517
470
|
? undefined
|
|
518
|
-
: agentMessage("system",
|
|
519
|
-
metadata: {
|
|
520
|
-
agentName: agent.metadata.name,
|
|
521
|
-
promptName: prompt?.name ?? null,
|
|
522
|
-
promptSectionKinds: prompt?.sections.map((section) => section.kind) ?? [],
|
|
523
|
-
},
|
|
524
|
-
});
|
|
525
|
-
}
|
|
526
|
-
}
|
|
527
|
-
|
|
528
|
-
function appendPromptSection(
|
|
529
|
-
lines: string[],
|
|
530
|
-
section: { readonly kind: string; readonly title?: string; readonly content: readonly string[] },
|
|
531
|
-
): void {
|
|
532
|
-
lines.push(`${section.title ?? promptSectionTitle(section.kind)}:`);
|
|
533
|
-
if (section.content.length === 1) {
|
|
534
|
-
lines.push(section.content[0] as string);
|
|
535
|
-
return;
|
|
536
|
-
}
|
|
537
|
-
lines.push(...section.content.map((item) => `- ${item}`));
|
|
538
|
-
}
|
|
539
|
-
|
|
540
|
-
function promptSectionTitle(kind: string): string {
|
|
541
|
-
switch (kind) {
|
|
542
|
-
case "system":
|
|
543
|
-
return "System";
|
|
544
|
-
case "developer":
|
|
545
|
-
return "Developer";
|
|
546
|
-
case "role":
|
|
547
|
-
return "Role";
|
|
548
|
-
case "task":
|
|
549
|
-
return "Task";
|
|
550
|
-
case "instructions":
|
|
551
|
-
return "Instructions";
|
|
552
|
-
case "constraints":
|
|
553
|
-
return "Constraints";
|
|
554
|
-
case "examples":
|
|
555
|
-
return "Examples";
|
|
556
|
-
case "output":
|
|
557
|
-
return "Output format";
|
|
558
|
-
case "tool-policy":
|
|
559
|
-
return "Tool policy";
|
|
560
|
-
case "memory":
|
|
561
|
-
return "Memory";
|
|
562
|
-
case "knowledge":
|
|
563
|
-
return "Knowledge";
|
|
564
|
-
default:
|
|
565
|
-
return "Prompt section";
|
|
471
|
+
: agentMessage("system", instructions, { metadata: { agentName: agent.name } });
|
|
566
472
|
}
|
|
567
473
|
}
|