bazis 0.98.34 → 0.99.1
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 +2 -60
- package/cli/templates/passport.ts +13 -17
- package/core/agent/AgentContextBuilder.ts +4 -98
- package/core/agent/AgentRegistry.ts +79 -473
- package/core/agent/AgentRuntime.ts +56 -19
- package/core/agent/AgentToolExecutor.ts +3 -3
- package/core/agent/README.md +90 -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/generatedRuntime.ts +0 -31
- 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/scripts/di-generate.ts +28 -42
- package/core/scripts/tool-codegen.ts +122 -0
- package/index.ts +3 -22
- package/library/openapi/codegen.ts +16 -5
- 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
|
@@ -39,10 +39,8 @@ const issuedCheckpoints = new WeakSet<object>();
|
|
|
39
39
|
export type AgentExecutionPhase = "ready-model" | "pending-tools" | "terminal";
|
|
40
40
|
|
|
41
41
|
export interface AgentExecutionInvocationState {
|
|
42
|
-
readonly kind: "agent" | "task";
|
|
43
42
|
readonly invocationId: string;
|
|
44
43
|
readonly agentName: string;
|
|
45
|
-
readonly taskName?: string;
|
|
46
44
|
readonly input: JsonValue;
|
|
47
45
|
readonly metadata: JsonObject;
|
|
48
46
|
/** Resolved Session data only; never classes, callbacks, DI or policies. */
|
|
@@ -239,14 +237,10 @@ function checkpointFromBoundary(value: BoundaryJsonValue): AgentExecutionCheckpo
|
|
|
239
237
|
}
|
|
240
238
|
|
|
241
239
|
function parseInvocation(value: BoundaryJsonValue): AgentExecutionInvocationState {
|
|
242
|
-
const record = closed(value, ["
|
|
243
|
-
if (record.kind !== "agent" && record.kind !== "task") throw invalid();
|
|
244
|
-
if ((record.kind === "agent" && record.taskName !== null) || (record.kind === "task" && typeof record.taskName !== "string")) throw invalid();
|
|
240
|
+
const record = closed(value, ["invocationId", "agentName", "input", "metadata", "options"]);
|
|
245
241
|
return Object.freeze({
|
|
246
|
-
kind: record.kind,
|
|
247
242
|
invocationId: requiredString(record.invocationId),
|
|
248
243
|
agentName: requiredString(record.agentName),
|
|
249
|
-
taskName: record.taskName === null ? undefined : requiredString(record.taskName),
|
|
250
244
|
input: asJsonValue(record.input),
|
|
251
245
|
metadata: asJsonObject(record.metadata),
|
|
252
246
|
options: parseResolvedOptions(record.options),
|
|
@@ -610,10 +604,8 @@ function checkpointRecord(checkpoint: AgentExecutionCheckpointV1): Record<string
|
|
|
610
604
|
return {
|
|
611
605
|
version: checkpoint.version,
|
|
612
606
|
invocation: {
|
|
613
|
-
kind: checkpoint.invocation.kind,
|
|
614
607
|
invocationId: checkpoint.invocation.invocationId,
|
|
615
608
|
agentName: checkpoint.invocation.agentName,
|
|
616
|
-
taskName: checkpoint.invocation.taskName ?? null,
|
|
617
609
|
input: checkpoint.invocation.input,
|
|
618
610
|
metadata: checkpoint.invocation.metadata,
|
|
619
611
|
options: checkpoint.invocation.options,
|
package/core/agent/metadata.ts
CHANGED
|
@@ -5,77 +5,10 @@ import { AgentSetupError } from "./errors";
|
|
|
5
5
|
// the runtime. Keep the same tiny polyfill used by HTTP/background metadata.
|
|
6
6
|
(Symbol as { metadata?: symbol }).metadata ??= Symbol.for("Symbol.metadata");
|
|
7
7
|
|
|
8
|
-
const AGENT_META = Symbol.for("bazis:agent:agent");
|
|
9
8
|
const TOOL_META = Symbol.for("bazis:agent:tool");
|
|
10
|
-
const PROMPT_META = Symbol.for("bazis:agent:prompt");
|
|
11
|
-
const TASK_META = Symbol.for("bazis:agent:task");
|
|
12
9
|
|
|
13
10
|
export type ToolSideEffect = "none" | "read" | "write" | "external";
|
|
14
11
|
export type ToolApproval = "never" | "policy" | "required";
|
|
15
|
-
export type PromptSectionKind =
|
|
16
|
-
| "system"
|
|
17
|
-
| "developer"
|
|
18
|
-
| "role"
|
|
19
|
-
| "task"
|
|
20
|
-
| "instructions"
|
|
21
|
-
| "constraints"
|
|
22
|
-
| "examples"
|
|
23
|
-
| "output"
|
|
24
|
-
| "tool-policy"
|
|
25
|
-
| "memory"
|
|
26
|
-
| "knowledge";
|
|
27
|
-
|
|
28
|
-
export interface AgentOptions {
|
|
29
|
-
readonly name?: string;
|
|
30
|
-
readonly description?: string;
|
|
31
|
-
readonly role?: string;
|
|
32
|
-
readonly goal?: string;
|
|
33
|
-
readonly instructions?: readonly string[];
|
|
34
|
-
readonly constraints?: readonly string[];
|
|
35
|
-
readonly sections?: readonly PromptSectionOptions[];
|
|
36
|
-
readonly prompt?: Class<object>;
|
|
37
|
-
readonly tools?: readonly Class<object>[];
|
|
38
|
-
readonly input?: Class<object>;
|
|
39
|
-
readonly output?: Class<object>;
|
|
40
|
-
readonly modelProfile?: string;
|
|
41
|
-
readonly maxSteps?: number;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export interface AgentMetadata {
|
|
45
|
-
readonly name: string;
|
|
46
|
-
readonly description?: string;
|
|
47
|
-
readonly role?: string;
|
|
48
|
-
readonly goal?: string;
|
|
49
|
-
readonly instructions: readonly string[];
|
|
50
|
-
readonly constraints: readonly string[];
|
|
51
|
-
readonly sections: readonly PromptSectionMetadata[];
|
|
52
|
-
readonly prompt?: Class<object>;
|
|
53
|
-
readonly tools: readonly Class<object>[];
|
|
54
|
-
readonly input?: Class<object>;
|
|
55
|
-
readonly output?: Class<object>;
|
|
56
|
-
readonly modelProfile?: string;
|
|
57
|
-
readonly maxSteps?: number;
|
|
58
|
-
readonly tasks: readonly AgentTaskMetadata[];
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
export interface AgentTaskOptions {
|
|
62
|
-
readonly name?: string;
|
|
63
|
-
readonly description?: string;
|
|
64
|
-
readonly input?: Class<object>;
|
|
65
|
-
readonly output?: Class<object>;
|
|
66
|
-
readonly modelProfile?: string;
|
|
67
|
-
readonly maxSteps?: number;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
export interface AgentTaskMetadata {
|
|
71
|
-
readonly name: string;
|
|
72
|
-
readonly methodName: string;
|
|
73
|
-
readonly description?: string;
|
|
74
|
-
readonly input?: Class<object>;
|
|
75
|
-
readonly output?: Class<object>;
|
|
76
|
-
readonly modelProfile?: string;
|
|
77
|
-
readonly maxSteps?: number;
|
|
78
|
-
}
|
|
79
12
|
|
|
80
13
|
export interface ToolOptions {
|
|
81
14
|
readonly name: string;
|
|
@@ -99,155 +32,23 @@ export interface ToolMetadata {
|
|
|
99
32
|
readonly tags: readonly string[];
|
|
100
33
|
}
|
|
101
34
|
|
|
102
|
-
export interface PromptOptions {
|
|
103
|
-
readonly name?: string;
|
|
104
|
-
readonly description?: string;
|
|
105
|
-
readonly version?: string;
|
|
106
|
-
readonly role?: string;
|
|
107
|
-
readonly goal?: string;
|
|
108
|
-
readonly instructions?: readonly string[];
|
|
109
|
-
readonly constraints?: readonly string[];
|
|
110
|
-
readonly sections?: readonly PromptSectionOptions[];
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
export interface PromptMetadata {
|
|
114
|
-
readonly name: string;
|
|
115
|
-
readonly description?: string;
|
|
116
|
-
readonly version?: string;
|
|
117
|
-
readonly role?: string;
|
|
118
|
-
readonly goal?: string;
|
|
119
|
-
readonly instructions: readonly string[];
|
|
120
|
-
readonly constraints: readonly string[];
|
|
121
|
-
readonly sections: readonly PromptSectionMetadata[];
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
export interface PromptSectionOptions {
|
|
125
|
-
readonly kind: PromptSectionKind;
|
|
126
|
-
readonly title?: string;
|
|
127
|
-
readonly content: string | readonly string[];
|
|
128
|
-
readonly priority?: number;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
export interface PromptSectionMetadata {
|
|
132
|
-
readonly kind: PromptSectionKind;
|
|
133
|
-
readonly title?: string;
|
|
134
|
-
readonly content: readonly string[];
|
|
135
|
-
readonly priority?: number;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
35
|
interface MetadataCarrier {
|
|
139
|
-
[AGENT_META]?: AgentMetadata;
|
|
140
36
|
[TOOL_META]?: ToolMetadata;
|
|
141
|
-
[PROMPT_META]?: PromptMetadata;
|
|
142
|
-
[TASK_META]?: readonly AgentTaskMetadata[];
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
interface NamedConstructor {
|
|
146
|
-
readonly name?: string;
|
|
147
37
|
}
|
|
148
38
|
|
|
149
|
-
function
|
|
150
|
-
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
function text(value: string | undefined, fallback: string, field: string): string {
|
|
154
|
-
const resolved = value ?? fallback;
|
|
155
|
-
const trimmed = resolved.trim();
|
|
39
|
+
function text(value: string | undefined, field: string): string {
|
|
40
|
+
const trimmed = (value ?? "").trim();
|
|
156
41
|
if (trimmed.length === 0) {
|
|
157
42
|
throw new AgentSetupError(`${field} must be a non-empty string.`);
|
|
158
43
|
}
|
|
159
44
|
return trimmed;
|
|
160
45
|
}
|
|
161
46
|
|
|
162
|
-
function optionalText(value: string | undefined, field: string): string | undefined {
|
|
163
|
-
if (value === undefined) {
|
|
164
|
-
return undefined;
|
|
165
|
-
}
|
|
166
|
-
const trimmed = value.trim();
|
|
167
|
-
if (trimmed.length === 0) {
|
|
168
|
-
throw new AgentSetupError(`${field} must be a non-empty string when provided.`);
|
|
169
|
-
}
|
|
170
|
-
return trimmed;
|
|
171
|
-
}
|
|
172
|
-
|
|
173
47
|
function readonlyTextList(values: readonly string[] | undefined, field: string): readonly string[] {
|
|
174
48
|
if (values === undefined) {
|
|
175
49
|
return Object.freeze([]);
|
|
176
50
|
}
|
|
177
|
-
|
|
178
|
-
for (let index = 0; index < values.length; index += 1) {
|
|
179
|
-
normalized.push(text(values[index] as string, "", field));
|
|
180
|
-
}
|
|
181
|
-
return Object.freeze(normalized);
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
function promptSectionKind(value: string, field: string): PromptSectionKind {
|
|
185
|
-
if (
|
|
186
|
-
value !== "system" &&
|
|
187
|
-
value !== "developer" &&
|
|
188
|
-
value !== "role" &&
|
|
189
|
-
value !== "task" &&
|
|
190
|
-
value !== "instructions" &&
|
|
191
|
-
value !== "constraints" &&
|
|
192
|
-
value !== "examples" &&
|
|
193
|
-
value !== "output" &&
|
|
194
|
-
value !== "tool-policy" &&
|
|
195
|
-
value !== "memory" &&
|
|
196
|
-
value !== "knowledge"
|
|
197
|
-
) {
|
|
198
|
-
throw new AgentSetupError(
|
|
199
|
-
`${field} must be system, developer, role, task, instructions, constraints, examples, output, tool-policy, memory or knowledge.`,
|
|
200
|
-
);
|
|
201
|
-
}
|
|
202
|
-
return value;
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
function readonlyPromptSectionContent(value: string | readonly string[], field: string): readonly string[] {
|
|
206
|
-
if (typeof value === "string") {
|
|
207
|
-
return Object.freeze([text(value, "", field)]);
|
|
208
|
-
}
|
|
209
|
-
if (!Array.isArray(value)) {
|
|
210
|
-
throw new AgentSetupError(`${field} must be a string or an array of strings.`);
|
|
211
|
-
}
|
|
212
|
-
return readonlyTextList(value, field);
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
function readonlyPromptSections(
|
|
216
|
-
values: readonly PromptSectionOptions[] | undefined,
|
|
217
|
-
field: string,
|
|
218
|
-
): readonly PromptSectionMetadata[] {
|
|
219
|
-
if (values === undefined) {
|
|
220
|
-
return Object.freeze([]);
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
const normalized: PromptSectionMetadata[] = [];
|
|
224
|
-
for (let index = 0; index < values.length; index += 1) {
|
|
225
|
-
const value = values[index] as PromptSectionOptions;
|
|
226
|
-
if (!value || typeof value !== "object") {
|
|
227
|
-
throw new AgentSetupError(`${field}[${index}] must be a prompt section object.`);
|
|
228
|
-
}
|
|
229
|
-
normalized.push(freezeWithoutUndefined({
|
|
230
|
-
kind: promptSectionKind(value.kind, `${field}[${index}].kind`),
|
|
231
|
-
title: optionalText(value.title, `${field}[${index}].title`),
|
|
232
|
-
content: readonlyPromptSectionContent(value.content, `${field}[${index}].content`),
|
|
233
|
-
priority: positiveInteger(value.priority, `${field}[${index}].priority`),
|
|
234
|
-
}));
|
|
235
|
-
}
|
|
236
|
-
return Object.freeze(normalized);
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
function readonlyClassList(values: readonly Class<object>[] | undefined): readonly Class<object>[] {
|
|
240
|
-
if (values === undefined) {
|
|
241
|
-
return Object.freeze([]);
|
|
242
|
-
}
|
|
243
|
-
return Object.freeze([...values]);
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
function readonlyTaskList(values: readonly AgentTaskMetadata[] | undefined): readonly AgentTaskMetadata[] {
|
|
247
|
-
if (values === undefined) {
|
|
248
|
-
return Object.freeze([]);
|
|
249
|
-
}
|
|
250
|
-
return Object.freeze([...values]);
|
|
51
|
+
return Object.freeze(values.map((value) => text(value, field)));
|
|
251
52
|
}
|
|
252
53
|
|
|
253
54
|
function positiveInteger(value: number | undefined, field: string): number | undefined {
|
|
@@ -260,16 +61,6 @@ function positiveInteger(value: number | undefined, field: string): number | und
|
|
|
260
61
|
return value;
|
|
261
62
|
}
|
|
262
63
|
|
|
263
|
-
function freezeWithoutUndefined<T extends Record<string, unknown>>(value: T): T {
|
|
264
|
-
const copy: Record<string, unknown> = {};
|
|
265
|
-
for (const [key, item] of Object.entries(value)) {
|
|
266
|
-
if (item !== undefined) {
|
|
267
|
-
copy[key] = item;
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
return Object.freeze(copy) as T;
|
|
271
|
-
}
|
|
272
|
-
|
|
273
64
|
function approvalFor(sideEffect: ToolSideEffect, requested: ToolApproval | undefined): ToolApproval {
|
|
274
65
|
if (requested === undefined) {
|
|
275
66
|
return sideEffect === "write" || sideEffect === "external" ? "required" : "policy";
|
|
@@ -282,57 +73,6 @@ function approvalFor(sideEffect: ToolSideEffect, requested: ToolApproval | undef
|
|
|
282
73
|
return requested;
|
|
283
74
|
}
|
|
284
75
|
|
|
285
|
-
function ownCarrier(metadata: object): MetadataCarrier {
|
|
286
|
-
return metadata as MetadataCarrier;
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
function readCarrier(ctor: object): MetadataCarrier | undefined {
|
|
290
|
-
return (ctor as { [key: symbol]: unknown })[Symbol.metadata as unknown as symbol] as MetadataCarrier | undefined;
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
function hasOwnMeta(carrier: MetadataCarrier, key: symbol): boolean {
|
|
294
|
-
return Object.prototype.hasOwnProperty.call(carrier, key);
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
export function defineAgentMetadata(target: object, metadata: object, options: AgentOptions): void {
|
|
298
|
-
const carrier = ownCarrier(metadata);
|
|
299
|
-
const normalized: AgentMetadata = Object.freeze({
|
|
300
|
-
name: text(options.name, classNameOf(target), "@Agent.name"),
|
|
301
|
-
description: optionalText(options.description, "@Agent.description"),
|
|
302
|
-
role: optionalText(options.role, "@Agent.role"),
|
|
303
|
-
goal: optionalText(options.goal, "@Agent.goal"),
|
|
304
|
-
instructions: readonlyTextList(options.instructions, "@Agent.instructions"),
|
|
305
|
-
constraints: readonlyTextList(options.constraints, "@Agent.constraints"),
|
|
306
|
-
sections: readonlyPromptSections(options.sections, "@Agent.sections"),
|
|
307
|
-
prompt: options.prompt,
|
|
308
|
-
tools: readonlyClassList(options.tools),
|
|
309
|
-
input: options.input,
|
|
310
|
-
output: options.output,
|
|
311
|
-
modelProfile: optionalText(options.modelProfile, "@Agent.modelProfile"),
|
|
312
|
-
maxSteps: positiveInteger(options.maxSteps, "@Agent.maxSteps"),
|
|
313
|
-
tasks: readonlyTaskList(carrier[TASK_META]),
|
|
314
|
-
});
|
|
315
|
-
carrier[AGENT_META] = normalized;
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
export function defineAgentTaskMetadata(methodName: string | symbol, metadata: object, options: AgentTaskOptions): void {
|
|
319
|
-
if (typeof methodName !== "string") {
|
|
320
|
-
throw new AgentSetupError("@Task supports string method names only.");
|
|
321
|
-
}
|
|
322
|
-
const normalized: AgentTaskMetadata = freezeWithoutUndefined({
|
|
323
|
-
name: text(options.name, methodName, "@Task.name"),
|
|
324
|
-
methodName,
|
|
325
|
-
description: optionalText(options.description, "@Task.description"),
|
|
326
|
-
input: options.input,
|
|
327
|
-
output: options.output,
|
|
328
|
-
modelProfile: optionalText(options.modelProfile, "@Task.modelProfile"),
|
|
329
|
-
maxSteps: positiveInteger(options.maxSteps, "@Task.maxSteps"),
|
|
330
|
-
});
|
|
331
|
-
const carrier = ownCarrier(metadata);
|
|
332
|
-
const existing = carrier[TASK_META] ?? Object.freeze([]);
|
|
333
|
-
carrier[TASK_META] = Object.freeze([...existing, normalized]);
|
|
334
|
-
}
|
|
335
|
-
|
|
336
76
|
export function defineToolMetadata(_target: object, metadata: object, options: ToolOptions): void {
|
|
337
77
|
const sideEffect = options.sideEffect ?? "none";
|
|
338
78
|
if (sideEffect !== "none" && sideEffect !== "read" && sideEffect !== "write" && sideEffect !== "external") {
|
|
@@ -342,8 +82,8 @@ export function defineToolMetadata(_target: object, metadata: object, options: T
|
|
|
342
82
|
throw new AgentSetupError("@Tool.approval must be never, policy or required.");
|
|
343
83
|
}
|
|
344
84
|
const normalized: ToolMetadata = Object.freeze({
|
|
345
|
-
name: text(options.name, "
|
|
346
|
-
description: text(options.description, "
|
|
85
|
+
name: text(options.name, "@Tool.name"),
|
|
86
|
+
description: text(options.description, "@Tool.description"),
|
|
347
87
|
input: options.input,
|
|
348
88
|
output: options.output,
|
|
349
89
|
sideEffect,
|
|
@@ -351,48 +91,13 @@ export function defineToolMetadata(_target: object, metadata: object, options: T
|
|
|
351
91
|
timeoutMs: positiveInteger(options.timeoutMs, "@Tool.timeoutMs"),
|
|
352
92
|
tags: readonlyTextList(options.tags, "@Tool.tags"),
|
|
353
93
|
});
|
|
354
|
-
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
export function definePromptMetadata(target: object, metadata: object, options: PromptOptions): void {
|
|
358
|
-
const normalized: PromptMetadata = Object.freeze({
|
|
359
|
-
name: text(options.name, classNameOf(target), "@Prompt.name"),
|
|
360
|
-
description: optionalText(options.description, "@Prompt.description"),
|
|
361
|
-
version: optionalText(options.version, "@Prompt.version"),
|
|
362
|
-
role: optionalText(options.role, "@Prompt.role"),
|
|
363
|
-
goal: optionalText(options.goal, "@Prompt.goal"),
|
|
364
|
-
instructions: readonlyTextList(options.instructions, "@Prompt.instructions"),
|
|
365
|
-
constraints: readonlyTextList(options.constraints, "@Prompt.constraints"),
|
|
366
|
-
sections: readonlyPromptSections(options.sections, "@Prompt.sections"),
|
|
367
|
-
});
|
|
368
|
-
ownCarrier(metadata)[PROMPT_META] = normalized;
|
|
369
|
-
}
|
|
370
|
-
|
|
371
|
-
export function agentMetadataOf(ctor: object): AgentMetadata | undefined {
|
|
372
|
-
const metadata = readCarrier(ctor);
|
|
373
|
-
if (!metadata || !hasOwnMeta(metadata, AGENT_META)) {
|
|
374
|
-
return undefined;
|
|
375
|
-
}
|
|
376
|
-
return metadata[AGENT_META];
|
|
377
|
-
}
|
|
378
|
-
|
|
379
|
-
export function agentTaskMetadataOf(ctor: object): readonly AgentTaskMetadata[] {
|
|
380
|
-
const metadata = readCarrier(ctor);
|
|
381
|
-
return metadata?.[TASK_META] ?? Object.freeze([]);
|
|
94
|
+
(metadata as MetadataCarrier)[TOOL_META] = normalized;
|
|
382
95
|
}
|
|
383
96
|
|
|
384
97
|
export function toolMetadataOf(ctor: object): ToolMetadata | undefined {
|
|
385
|
-
const metadata =
|
|
386
|
-
if (!metadata || !
|
|
98
|
+
const metadata = (ctor as { [key: symbol]: unknown })[Symbol.metadata as unknown as symbol] as MetadataCarrier | undefined;
|
|
99
|
+
if (!metadata || !Object.prototype.hasOwnProperty.call(metadata, TOOL_META)) {
|
|
387
100
|
return undefined;
|
|
388
101
|
}
|
|
389
102
|
return metadata[TOOL_META];
|
|
390
103
|
}
|
|
391
|
-
|
|
392
|
-
export function promptMetadataOf(ctor: object): PromptMetadata | undefined {
|
|
393
|
-
const metadata = readCarrier(ctor);
|
|
394
|
-
if (!metadata || !hasOwnMeta(metadata, PROMPT_META)) {
|
|
395
|
-
return undefined;
|
|
396
|
-
}
|
|
397
|
-
return metadata[PROMPT_META];
|
|
398
|
-
}
|
package/core/agent/semantic.ts
CHANGED
|
@@ -368,10 +368,6 @@ export function normalizeJsonValue(value: unknown, field = "value"): JsonValue {
|
|
|
368
368
|
throw new AgentSemanticError(`${field} must be JSON-serializable.`);
|
|
369
369
|
}
|
|
370
370
|
|
|
371
|
-
export function agentOutput<T = never>(): T {
|
|
372
|
-
throw new AgentSemanticError("agentOutput() is an agent task marker and must not be called directly.");
|
|
373
|
-
}
|
|
374
|
-
|
|
375
371
|
export function agentText(text: string): AgentTextPart {
|
|
376
372
|
const value = requiredContentText(text, "text");
|
|
377
373
|
return Object.freeze({ kind: "text", text: value });
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Secret } from "../../kernel";
|
|
2
2
|
import type { BazisModuleRef } from "../../di";
|
|
3
|
-
import type { AgentToolExecutorOptions
|
|
3
|
+
import type { AgentToolExecutorOptions } from "../AgentToolExecutor";
|
|
4
4
|
import { normalizeJsonValue, type JsonObject, type JsonValue } from "../semantic";
|
|
5
5
|
import { Validator } from "../../../library/validation";
|
|
6
6
|
|
|
@@ -16,8 +16,6 @@ export class CreateAgentSessionRequestV1 {
|
|
|
16
16
|
requestId!: string;
|
|
17
17
|
@Validator({ required: true, minLength: 1, maxLength: 128 })
|
|
18
18
|
agentName!: string;
|
|
19
|
-
@Validator({ minLength: 1, maxLength: 128 })
|
|
20
|
-
taskName?: string;
|
|
21
19
|
@Validator({
|
|
22
20
|
required: true,
|
|
23
21
|
// JsonValue deliberately includes null. Keep absence invalid while
|
|
@@ -55,7 +53,7 @@ export type AgentSessionStateV1 = "created" | "running" | "stop-requested" | "st
|
|
|
55
53
|
export type AgentSessionCursorV1 = string;
|
|
56
54
|
export interface AgentSessionOutcomeV1 { readonly status: "completed" | "failed" | "outcome-unknown"; readonly finalText?: string; readonly output?: JsonValue; readonly error?: { readonly code: string; readonly message: string }; }
|
|
57
55
|
export interface AgentSessionViewV1 {
|
|
58
|
-
readonly version: 1; readonly sessionId: string; readonly invocationId: string; readonly agentName: string;
|
|
56
|
+
readonly version: 1; readonly sessionId: string; readonly invocationId: string; readonly agentName: string;
|
|
59
57
|
readonly tenant?: string; readonly state: AgentSessionStateV1; readonly revision: number; readonly steps: number; readonly stopRequested: boolean;
|
|
60
58
|
readonly resumeAllowed: boolean; readonly createdAt: string; readonly updatedAt: string; readonly outcome?: AgentSessionOutcomeV1;
|
|
61
59
|
}
|
|
@@ -74,7 +72,7 @@ export abstract class AgentSessions {
|
|
|
74
72
|
abstract readEvents(request: ReadAgentSessionEventsRequestV1, context: AgentSessionCallContextV1): Promise<AgentSessionEventPageV1>;
|
|
75
73
|
}
|
|
76
74
|
|
|
77
|
-
export interface AgentSessionAuthorizationTargetV1 { readonly sessionId: string; readonly ownerSubject: string; readonly tenant?: string; readonly agentName: string;
|
|
75
|
+
export interface AgentSessionAuthorizationTargetV1 { readonly sessionId: string; readonly ownerSubject: string; readonly tenant?: string; readonly agentName: string; }
|
|
78
76
|
export type AgentSessionAuthorizationRequestV1 =
|
|
79
77
|
| { readonly action: "create"; readonly principal: AgentSessionPrincipalV1; readonly candidate: AgentSessionAuthorizationTargetV1 }
|
|
80
78
|
| { readonly action: "run" | "read" | "read-events" | "stop" | "resume"; readonly principal: AgentSessionPrincipalV1; readonly session: AgentSessionAuthorizationTargetV1 & { readonly state: AgentSessionStateV1 } };
|
|
@@ -87,9 +85,9 @@ export interface AgentSessionOpenRequestV1 { readonly expectedSessionId: string;
|
|
|
87
85
|
export abstract class AgentSessionCheckpointProtectorV1 { abstract seal(request: AgentSessionSealRequestV1): Promise<AgentSessionSealedCheckpointV1>; abstract open(request: AgentSessionOpenRequestV1): Promise<string>; }
|
|
88
86
|
|
|
89
87
|
export interface AgentSessionModuleOptionsV1 {
|
|
90
|
-
readonly imports?: readonly BazisModuleRef[]; readonly
|
|
88
|
+
readonly imports?: readonly BazisModuleRef[]; readonly implementationVersion: string;
|
|
91
89
|
readonly admission: { readonly bucket: string; readonly maxActiveRuns?: number };
|
|
92
|
-
readonly execution?: { readonly providerCallTimeoutMs?: number; readonly
|
|
90
|
+
readonly execution?: { readonly providerCallTimeoutMs?: number; readonly toolExecutorOptions?: Pick<AgentToolExecutorOptions, "approvalPolicy" | "schemaValidator" | "auditSink" | "defaultTimeoutMs" | "scopeDisposeTimeoutMs" | "requiredPlatformHooks" | "hookRedaction">; };
|
|
93
91
|
readonly limits?: { readonly runTimeoutMs?: number; readonly maxSessionSteps?: number; readonly maxToolCallsPerStep?: number; readonly ownerLeaseMs?: number; readonly ownerHeartbeatMs?: number; readonly ownerStopGraceMs?: number; readonly authorizationTimeoutMs?: number; readonly checkpointProtectionTimeoutMs?: number; readonly databaseLockTimeoutMs?: number; readonly databaseStatementTimeoutMs?: number; readonly databaseWaitTimeoutMs?: number; readonly stopCheckIntervalMs?: number; readonly maxInputBytes?: number; readonly maxCheckpointBytes?: number; readonly maxJournalPayloadBytes?: number; readonly maxJournalEntries?: number; readonly reservedControlJournalEntries?: number; readonly defaultJournalPageSize?: number; readonly maxJournalPageSize?: number; };
|
|
94
92
|
}
|
|
95
93
|
export type AgentSessionErrorCodeV1 = `AGENT_SESSION_${"INVALID_REQUEST" | "FORBIDDEN" | "NOT_FOUND" | "CONFLICT" | "OWNER_ACTIVE" | "ADMISSION_UNAVAILABLE" | "NOT_RESUMABLE" | "DEADLINE_EXCEEDED" | "LIMIT_EXCEEDED" | "AMBIENT_TRANSACTION_FORBIDDEN" | "BINDING_MISMATCH" | "CHECKPOINT_UNAVAILABLE" | "CHECKPOINT_CORRUPT" | "OUTCOME_UNKNOWN" | "STORE_CORRUPT" | "STORE_UNAVAILABLE" | "AUTHORIZATION_UNAVAILABLE" | "HOST_STOPPING" | "UNSUPPORTED_VERSION" | "IDEMPOTENCY_CONFLICT" | "COMMIT_OUTCOME_UNKNOWN" | "CONFIG_MISMATCH"}`;
|
|
@@ -13,7 +13,6 @@ export class AgentSessionRowV1 {
|
|
|
13
13
|
@Column({ type: "text" }) ownerSubject = "";
|
|
14
14
|
@Column({ type: "text", nullable: true }) tenant?: string;
|
|
15
15
|
@Column({ type: "text" }) agentName = "";
|
|
16
|
-
@Column({ type: "text", nullable: true }) taskName?: string;
|
|
17
16
|
@Column({ type: "text" }) implementationVersion = "";
|
|
18
17
|
@Column({ type: "text" }) bindingHash = "";
|
|
19
18
|
@Column({ type: "text" }) state = "created";
|
package/core/generatedRuntime.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
|
-
import type { AgentMetadataIndex } from "./agent/AgentRegistry";
|
|
3
2
|
import { registerGeneratedClassDeps, restoreGeneratedClassDeps, snapshotGeneratedClassDeps, type GeneratedClassDependency } from "./di/module/autoDeps";
|
|
4
3
|
import { registerGeneratedBindings, restoreGeneratedBindings, snapshotGeneratedBindings } from "./http/Binding/autoBindings";
|
|
5
4
|
import { registerRequestModelShape, restoreRequestModelRegistry, snapshotRequestModelRegistry, type RequestModelClass, type RequestModelShape } from "./http/Binding/requestModelRegistry";
|
|
@@ -27,10 +26,6 @@ type GeneratedRuntimeModule = {
|
|
|
27
26
|
readonly registerBazisGeneratedRuntime?: () => void | Promise<void>;
|
|
28
27
|
};
|
|
29
28
|
|
|
30
|
-
type GeneratedAgentCatalogModule = {
|
|
31
|
-
readonly GENERATED_AGENT_METADATA?: AgentMetadataIndex;
|
|
32
|
-
};
|
|
33
|
-
|
|
34
29
|
let runtimeLoad: Promise<void> | undefined;
|
|
35
30
|
|
|
36
31
|
export interface BazisGeneratedTargetDescriptor {
|
|
@@ -42,15 +37,12 @@ export interface BazisGeneratedTargetDescriptor {
|
|
|
42
37
|
readonly listModels: readonly ListModelClass[];
|
|
43
38
|
readonly openApi: GeneratedOpenApiMetadata;
|
|
44
39
|
readonly openApiSchemaModels: readonly (readonly [GeneratedOpenApiSchemaModel, string])[];
|
|
45
|
-
/** Target-local generated Agent/Tool/Prompt metadata. */
|
|
46
|
-
readonly agentMetadata?: AgentMetadataIndex;
|
|
47
40
|
/** Package-internal exact-class metadata attached atomically with this target. */
|
|
48
41
|
readonly providerAttachments?: readonly GeneratedProviderAttachmentV1[];
|
|
49
42
|
}
|
|
50
43
|
|
|
51
44
|
const committedTargetDescriptors = new Set<string>();
|
|
52
45
|
const targetDescriptorLoads = new Map<string, Promise<void>>();
|
|
53
|
-
const committedTargetDescriptorsById = new Map<string, BazisGeneratedTargetDescriptor>();
|
|
54
46
|
const explicitlyActivatedTargetIds = new Set<string>();
|
|
55
47
|
|
|
56
48
|
/**
|
|
@@ -87,7 +79,6 @@ export function registerBazisGeneratedTargetDescriptor(descriptor: BazisGenerate
|
|
|
87
79
|
for (const [model, name] of descriptor.openApiSchemaModels) registerGeneratedOpenApiSchemaModel(model, name);
|
|
88
80
|
commitGeneratedProviderAttachments(preparedAttachments);
|
|
89
81
|
committedTargetDescriptors.add(descriptor.id);
|
|
90
|
-
committedTargetDescriptorsById.set(descriptor.id, descriptor);
|
|
91
82
|
explicitlyActivatedTargetIds.add(descriptor.id);
|
|
92
83
|
} catch (error) {
|
|
93
84
|
restoreGeneratedClassDeps(snapshots.classDeps);
|
|
@@ -136,28 +127,6 @@ export function loadBazisGeneratedRuntime(): Promise<void> {
|
|
|
136
127
|
return runtimeLoad;
|
|
137
128
|
}
|
|
138
129
|
|
|
139
|
-
export async function loadBazisGeneratedAgentMetadata(
|
|
140
|
-
targets: readonly Class<object>[] = [],
|
|
141
|
-
): Promise<AgentMetadataIndex | undefined> {
|
|
142
|
-
const registered = selectRegisteredAgentMetadata(targets);
|
|
143
|
-
if (registered !== undefined || explicitlyActivatedTargetIds.size > 0) return registered;
|
|
144
|
-
const module = await importGeneratedModule<GeneratedAgentCatalogModule>("agentCatalog");
|
|
145
|
-
return module?.GENERATED_AGENT_METADATA;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
function selectRegisteredAgentMetadata(targets: readonly Class<object>[]): AgentMetadataIndex | undefined {
|
|
149
|
-
const candidates = [...committedTargetDescriptorsById.values()]
|
|
150
|
-
.map((descriptor) => descriptor.agentMetadata)
|
|
151
|
-
.filter((metadata): metadata is AgentMetadataIndex => metadata !== undefined);
|
|
152
|
-
if (candidates.length === 0) return undefined;
|
|
153
|
-
for (const metadata of candidates) {
|
|
154
|
-
for (const target of targets) {
|
|
155
|
-
if (metadata.agents.has(target) || metadata.tools.has(target) || metadata.prompts.has(target)) return metadata;
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
return candidates.length === 1 ? candidates[0] : undefined;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
130
|
async function loadRuntimeOnce(): Promise<void> {
|
|
162
131
|
const module = await importGeneratedModule<GeneratedRuntimeModule>("runtime");
|
|
163
132
|
await module?.registerBazisGeneratedRuntime?.();
|
|
@@ -232,7 +232,7 @@ export class CodexAppServerClient implements CodexClient {
|
|
|
232
232
|
if (method === "account/updated") this.modelCache = undefined;
|
|
233
233
|
}, () => { this.clearLogin(); this.modelCache = undefined; });
|
|
234
234
|
const initialized = await client.request("initialize", {
|
|
235
|
-
clientInfo: { name: "bazis", title: "Bazis", version: "0.
|
|
235
|
+
clientInfo: { name: "bazis", title: "Bazis", version: "0.99.1" }, capabilities: { experimentalApi: true },
|
|
236
236
|
}, 15_000, signal);
|
|
237
237
|
if (resolve(text(initialized.codexHome, 4096)) !== this.paths.home) throw new CodexError("PROTOCOL_ERROR");
|
|
238
238
|
client.notify("initialized");
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { AppConfig, ConfigRegistry, Secret } from "../../kernel";
|
|
2
|
-
import { AGENT_MODEL_PROVIDER, type AgentModelProvider } from "../../agent";
|
|
2
|
+
import { AGENT_MODEL_PROVIDER, AGENT_RUNTIME_OPTIONS, AgentRuntime, type AgentModelProvider } from "../../agent";
|
|
3
|
+
import { DI, SERVICE_PROVIDER, type ProviderDefinition } from "../../di";
|
|
3
4
|
import { reader, requireValue } from "../connectorConfig";
|
|
4
5
|
import { InfraError, type InfraConnector } from "../InfraConnector";
|
|
5
6
|
import { identifyConnector } from "../connectorIdentity";
|
|
@@ -54,6 +55,17 @@ export function resolveLlmConnectionOptions<T extends LlmConfigShape>(
|
|
|
54
55
|
};
|
|
55
56
|
}
|
|
56
57
|
|
|
58
|
+
/**
|
|
59
|
+
* `AgentRuntime` on top of the connector's model provider, injectable by type.
|
|
60
|
+
* Options come from `AGENT_RUNTIME_OPTIONS` when the application registers it.
|
|
61
|
+
*/
|
|
62
|
+
export const agentRuntimeProviders: readonly ProviderDefinition[] = Object.freeze([
|
|
63
|
+
DI.singleton(DI.factoryProviderWithResolver(AgentRuntime, [AGENT_MODEL_PROVIDER], (resolver, model: AgentModelProvider) => {
|
|
64
|
+
const services = resolver.resolve(SERVICE_PROVIDER);
|
|
65
|
+
return new AgentRuntime(services, model, services.has(AGENT_RUNTIME_OPTIONS) ? services.resolve(AGENT_RUNTIME_OPTIONS) : {});
|
|
66
|
+
})),
|
|
67
|
+
]);
|
|
68
|
+
|
|
57
69
|
export function llmConnect<T extends LlmConfigShape>(
|
|
58
70
|
config: AppConfig<T>,
|
|
59
71
|
adapter: LlmProviderAdapter,
|
|
@@ -62,6 +74,8 @@ export function llmConnect<T extends LlmConfigShape>(
|
|
|
62
74
|
return identifyConnector({
|
|
63
75
|
token: AGENT_MODEL_PROVIDER,
|
|
64
76
|
config,
|
|
77
|
+
providers: agentRuntimeProviders,
|
|
78
|
+
exports: [AgentRuntime],
|
|
65
79
|
create(configs) {
|
|
66
80
|
return adapter.create(resolveLlmConnectionOptions(config, options, configs));
|
|
67
81
|
},
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { AppConfig } from "../../kernel";
|
|
2
2
|
import {
|
|
3
3
|
AGENT_MODEL_PROVIDER,
|
|
4
|
+
AgentRuntime,
|
|
4
5
|
agentModelRequest,
|
|
5
6
|
type AgentModelProvider,
|
|
6
7
|
type AgentModelProviderContext,
|
|
@@ -11,6 +12,7 @@ import { InfraError, type InfraConnector } from "../InfraConnector";
|
|
|
11
12
|
import { redactSensitiveText } from "../../../library/redaction";
|
|
12
13
|
import { awaitAbortable } from "../../kernel/internal/awaitAbortable";
|
|
13
14
|
import {
|
|
15
|
+
agentRuntimeProviders,
|
|
14
16
|
resolveLlmConnectionOptions,
|
|
15
17
|
type LlmConfigShape,
|
|
16
18
|
type LlmConnectionOptions,
|
|
@@ -408,6 +410,8 @@ export function llmRouter(
|
|
|
408
410
|
return {
|
|
409
411
|
token: AGENT_MODEL_PROVIDER,
|
|
410
412
|
config: configs,
|
|
413
|
+
providers: agentRuntimeProviders,
|
|
414
|
+
exports: [AgentRuntime],
|
|
411
415
|
create(configs) {
|
|
412
416
|
// The router must have an owner before adapters allocate resources.
|
|
413
417
|
// Initialization happens inside an awaited operation, so rollback can
|