agent-swarm-kit 1.1.115 → 1.1.117
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/build/index.cjs +125 -45
- package/build/index.mjs +125 -45
- package/package.json +1 -1
- package/types.d.ts +716 -661
package/build/index.cjs
CHANGED
|
@@ -3829,7 +3829,12 @@ const RUN_FN = async (incoming, self) => {
|
|
|
3829
3829
|
mode: "user",
|
|
3830
3830
|
tools: [],
|
|
3831
3831
|
};
|
|
3832
|
-
const
|
|
3832
|
+
const completionMessage = await self.params.completion.getCompletion(args);
|
|
3833
|
+
const rawMessage = {
|
|
3834
|
+
agentName: self.params.agentName,
|
|
3835
|
+
mode: "tool",
|
|
3836
|
+
...completionMessage,
|
|
3837
|
+
};
|
|
3833
3838
|
self.params.completion.callbacks?.onComplete &&
|
|
3834
3839
|
self.params.completion.callbacks?.onComplete(args, rawMessage);
|
|
3835
3840
|
const message = await self.params.map(rawMessage, self.params.clientId, self.params.agentName);
|
|
@@ -4376,7 +4381,12 @@ class ClientAgent {
|
|
|
4376
4381
|
mode,
|
|
4377
4382
|
tools: await resolveTools(this.params.clientId, this.params.agentName, tools),
|
|
4378
4383
|
};
|
|
4379
|
-
const
|
|
4384
|
+
const rawMessage = await this.params.completion.getCompletion(args);
|
|
4385
|
+
const output = {
|
|
4386
|
+
agentName: this.params.agentName,
|
|
4387
|
+
mode: "tool",
|
|
4388
|
+
...rawMessage,
|
|
4389
|
+
};
|
|
4380
4390
|
if (GLOBAL_CONFIG.CC_RESQUE_STRATEGY === "flush") {
|
|
4381
4391
|
this.params.completion.callbacks?.onComplete &&
|
|
4382
4392
|
this.params.completion.callbacks?.onComplete(args, output);
|
|
@@ -4423,7 +4433,12 @@ class ClientAgent {
|
|
|
4423
4433
|
mode,
|
|
4424
4434
|
tools: await resolveTools(this.params.clientId, this.params.agentName, tools),
|
|
4425
4435
|
};
|
|
4426
|
-
const
|
|
4436
|
+
const rawMessage = await this.params.completion.getCompletion(args);
|
|
4437
|
+
const output = {
|
|
4438
|
+
agentName: this.params.agentName,
|
|
4439
|
+
mode: "tool",
|
|
4440
|
+
...rawMessage,
|
|
4441
|
+
};
|
|
4427
4442
|
this.params.completion.callbacks?.onComplete &&
|
|
4428
4443
|
this.params.completion.callbacks?.onComplete(args, output);
|
|
4429
4444
|
return {
|
|
@@ -9737,6 +9752,15 @@ class AgentValidationService {
|
|
|
9737
9752
|
* @readonly
|
|
9738
9753
|
*/
|
|
9739
9754
|
this.loggerService = inject(TYPES.loggerService);
|
|
9755
|
+
/**
|
|
9756
|
+
* Completion schema service instance for managing completion schemas.
|
|
9757
|
+
* Injected via DI, used in validate method to check agent completions.
|
|
9758
|
+
* Provides a registry of completion schemas for the swarm.
|
|
9759
|
+
* @type {CompletionSchemaService}
|
|
9760
|
+
* @private
|
|
9761
|
+
* @readonly
|
|
9762
|
+
*/
|
|
9763
|
+
this.completionSchemaService = inject(TYPES.completionSchemaService);
|
|
9740
9764
|
/**
|
|
9741
9765
|
* Tool validation service instance for validating tools associated with agents.
|
|
9742
9766
|
* Injected via DI, used in validate method to check agent tools.
|
|
@@ -9984,6 +10008,10 @@ class AgentValidationService {
|
|
|
9984
10008
|
if (!agent) {
|
|
9985
10009
|
throw new Error(`agent-swarm agent ${agentName} not found source=${source}`);
|
|
9986
10010
|
}
|
|
10011
|
+
const completionSchema = this.completionSchemaService.get(agent.completion);
|
|
10012
|
+
if (completionSchema.json) {
|
|
10013
|
+
throw new Error(`agent-swarm agent ${agentName} completion schema is JSON source=${source}`);
|
|
10014
|
+
}
|
|
9987
10015
|
if (!agent.operator) {
|
|
9988
10016
|
this.completionValidationService.validate(agent.completion, source);
|
|
9989
10017
|
}
|
|
@@ -13448,6 +13476,10 @@ class DocService {
|
|
|
13448
13476
|
}
|
|
13449
13477
|
result.push("");
|
|
13450
13478
|
}
|
|
13479
|
+
if (outlineSchema.completion) {
|
|
13480
|
+
result.push(`**Completion:** \`${sanitizeMarkdown(outlineSchema.completion)}\``);
|
|
13481
|
+
result.push("");
|
|
13482
|
+
}
|
|
13451
13483
|
const getPrompt = async () => {
|
|
13452
13484
|
try {
|
|
13453
13485
|
if (typeof outlineSchema.prompt === "string") {
|
|
@@ -18227,7 +18259,7 @@ class OutlineSchemaService {
|
|
|
18227
18259
|
this._registry = new functoolsKit.ToolRegistry("outlineSchemaService");
|
|
18228
18260
|
/**
|
|
18229
18261
|
* Validates an outline schema for required properties and correct types.
|
|
18230
|
-
* Ensures `outlineName` is a string, `
|
|
18262
|
+
* Ensures `outlineName` is a string, `getOutlineHistory` is a function, and `validations` (if present) is an array of valid validation functions or objects.
|
|
18231
18263
|
* Logs validation attempts if `CC_LOGGER_ENABLE_INFO` is enabled.
|
|
18232
18264
|
* @private
|
|
18233
18265
|
* @param {IOutlineSchema} outlineSchema - The outline schema to validate.
|
|
@@ -18241,13 +18273,18 @@ class OutlineSchemaService {
|
|
|
18241
18273
|
if (typeof outlineSchema.outlineName !== "string") {
|
|
18242
18274
|
throw new Error(`agent-swarm outline schema validation failed: missing outlineName`);
|
|
18243
18275
|
}
|
|
18244
|
-
if (typeof outlineSchema.
|
|
18245
|
-
throw new Error(`agent-swarm outline schema validation failed: missing
|
|
18276
|
+
if (typeof outlineSchema.completion !== "string") {
|
|
18277
|
+
throw new Error(`agent-swarm outline schema validation failed: missing completion for outlineName=${outlineSchema.outlineName}`);
|
|
18278
|
+
}
|
|
18279
|
+
if (typeof outlineSchema.getOutlineHistory !== "function") {
|
|
18280
|
+
throw new Error(`agent-swarm outline schema validation failed: missing getOutlineHistory for outlineName=${outlineSchema.outlineName}`);
|
|
18246
18281
|
}
|
|
18247
|
-
if (outlineSchema.validations &&
|
|
18282
|
+
if (outlineSchema.validations &&
|
|
18283
|
+
!Array.isArray(outlineSchema.validations)) {
|
|
18248
18284
|
throw new Error(`agent-swarm outline schema validation failed: validations is not an array for outlineName=${outlineSchema.outlineName}`);
|
|
18249
18285
|
}
|
|
18250
|
-
if (outlineSchema.validations &&
|
|
18286
|
+
if (outlineSchema.validations &&
|
|
18287
|
+
outlineSchema.validations?.some((validation) => typeof validation !== "function" && !functoolsKit.isObject(validation))) {
|
|
18251
18288
|
throw new Error(`agent-swarm outline schema validation failed: invalid validations for outlineName=${outlineSchema.outlineName}`);
|
|
18252
18289
|
}
|
|
18253
18290
|
};
|
|
@@ -18330,6 +18367,22 @@ class OutlineValidationService {
|
|
|
18330
18367
|
* @type {LoggerService}
|
|
18331
18368
|
*/
|
|
18332
18369
|
this.loggerService = inject(TYPES.loggerService);
|
|
18370
|
+
/**
|
|
18371
|
+
* Completion schema service instance for managing completion schemas.
|
|
18372
|
+
* Injected via DI, used in validate method to check outline completions.
|
|
18373
|
+
* Provides a registry of completion schemas for the swarm.
|
|
18374
|
+
* @type {CompletionSchemaService}
|
|
18375
|
+
* @private
|
|
18376
|
+
*/
|
|
18377
|
+
this.completionSchemaService = inject(TYPES.completionSchemaService);
|
|
18378
|
+
/**
|
|
18379
|
+
* Completion validation service instance for validating completion configurations of outlines.
|
|
18380
|
+
* Injected via DI, used in validate method to check outline completion.
|
|
18381
|
+
* @type {CompletionValidationService}
|
|
18382
|
+
* @private
|
|
18383
|
+
* @readonly
|
|
18384
|
+
*/
|
|
18385
|
+
this.completionValidationService = inject(TYPES.completionValidationService);
|
|
18333
18386
|
/**
|
|
18334
18387
|
* A map storing outline schemas, keyed by their unique outline names.
|
|
18335
18388
|
* Used to manage registered outlines and retrieve them for validation.
|
|
@@ -18383,6 +18436,11 @@ class OutlineValidationService {
|
|
|
18383
18436
|
if (!outline) {
|
|
18384
18437
|
throw new Error(`agent-swarm outline ${outlineName} not found source=${source}`);
|
|
18385
18438
|
}
|
|
18439
|
+
const completionSchema = this.completionSchemaService.get(outline.completion);
|
|
18440
|
+
if (!completionSchema.json) {
|
|
18441
|
+
throw new Error(`agent-swarm outline ${outlineName} completion schema is not JSON source=${source}`);
|
|
18442
|
+
}
|
|
18443
|
+
this.completionValidationService.validate(outline.completion, source);
|
|
18386
18444
|
return true;
|
|
18387
18445
|
});
|
|
18388
18446
|
}
|
|
@@ -21133,10 +21191,11 @@ class OutlineHistory {
|
|
|
21133
21191
|
constructor(prompt) {
|
|
21134
21192
|
/** @private */
|
|
21135
21193
|
this.messages = [];
|
|
21136
|
-
prompt &&
|
|
21137
|
-
|
|
21138
|
-
|
|
21139
|
-
|
|
21194
|
+
prompt &&
|
|
21195
|
+
this.messages.push({
|
|
21196
|
+
role: "system",
|
|
21197
|
+
content: prompt,
|
|
21198
|
+
});
|
|
21140
21199
|
}
|
|
21141
21200
|
/**
|
|
21142
21201
|
* Appends one or more messages to the history.
|
|
@@ -21179,7 +21238,9 @@ const jsonInternal = beginContext(async (outlineName, param) => {
|
|
|
21179
21238
|
swarm$1.loggerService.log(METHOD_NAME$D, {});
|
|
21180
21239
|
swarm$1.outlineValidationService.validate(outlineName, METHOD_NAME$D);
|
|
21181
21240
|
const resultId = functoolsKit.randomString();
|
|
21182
|
-
const {
|
|
21241
|
+
const { getOutlineHistory, completion, validations = [], maxAttempts = MAX_ATTEMPTS, format, prompt, callbacks: outlineCallbacks, } = swarm$1.outlineSchemaService.get(outlineName);
|
|
21242
|
+
swarm$1.completionValidationService.validate(completion, METHOD_NAME$D);
|
|
21243
|
+
const { getCompletion, callbacks: completionCallbacks } = swarm$1.completionSchemaService.get(completion);
|
|
21183
21244
|
let errorMessage = "";
|
|
21184
21245
|
let history;
|
|
21185
21246
|
const systemPrompt = functoolsKit.str.newline(typeof prompt === "function" ? await prompt(outlineName) : prompt);
|
|
@@ -21191,41 +21252,60 @@ const jsonInternal = beginContext(async (outlineName, param) => {
|
|
|
21191
21252
|
param,
|
|
21192
21253
|
history,
|
|
21193
21254
|
};
|
|
21194
|
-
if (
|
|
21195
|
-
|
|
21255
|
+
if (outlineCallbacks?.onAttempt) {
|
|
21256
|
+
outlineCallbacks.onAttempt(inputArgs);
|
|
21196
21257
|
}
|
|
21197
|
-
|
|
21198
|
-
const
|
|
21199
|
-
|
|
21200
|
-
|
|
21201
|
-
|
|
21202
|
-
|
|
21203
|
-
|
|
21204
|
-
|
|
21205
|
-
|
|
21206
|
-
|
|
21258
|
+
await getOutlineHistory(inputArgs);
|
|
21259
|
+
const messages = await history.list();
|
|
21260
|
+
try {
|
|
21261
|
+
const output = await getCompletion({
|
|
21262
|
+
messages: await history.list(),
|
|
21263
|
+
mode: "tool",
|
|
21264
|
+
outlineName,
|
|
21265
|
+
});
|
|
21266
|
+
if (completionCallbacks?.onComplete) {
|
|
21267
|
+
completionCallbacks.onComplete({
|
|
21268
|
+
messages,
|
|
21269
|
+
mode: "tool",
|
|
21270
|
+
outlineName,
|
|
21271
|
+
}, output);
|
|
21207
21272
|
}
|
|
21208
|
-
|
|
21209
|
-
|
|
21210
|
-
|
|
21211
|
-
|
|
21273
|
+
const data = JSON.parse(output.content);
|
|
21274
|
+
const validationArgs = {
|
|
21275
|
+
...inputArgs,
|
|
21276
|
+
data,
|
|
21277
|
+
};
|
|
21278
|
+
let isValid = true;
|
|
21279
|
+
for (const validation of validations) {
|
|
21280
|
+
const validate = typeof validation === "object" ? validation.validate : validation;
|
|
21281
|
+
try {
|
|
21282
|
+
await validate(validationArgs);
|
|
21283
|
+
}
|
|
21284
|
+
catch (error) {
|
|
21285
|
+
isValid = false;
|
|
21286
|
+
errorMessage = functoolsKit.getErrorMessage(error);
|
|
21287
|
+
break;
|
|
21288
|
+
}
|
|
21212
21289
|
}
|
|
21290
|
+
if (!isValid) {
|
|
21291
|
+
continue;
|
|
21292
|
+
}
|
|
21293
|
+
const result = {
|
|
21294
|
+
isValid: true,
|
|
21295
|
+
attempt,
|
|
21296
|
+
param,
|
|
21297
|
+
history: await history.list(),
|
|
21298
|
+
data,
|
|
21299
|
+
resultId,
|
|
21300
|
+
};
|
|
21301
|
+
if (outlineCallbacks?.onValidDocument) {
|
|
21302
|
+
outlineCallbacks.onValidDocument(result);
|
|
21303
|
+
}
|
|
21304
|
+
return result;
|
|
21213
21305
|
}
|
|
21214
|
-
|
|
21215
|
-
|
|
21216
|
-
}
|
|
21217
|
-
const result = {
|
|
21218
|
-
isValid: true,
|
|
21219
|
-
attempt,
|
|
21220
|
-
param,
|
|
21221
|
-
history: await history.list(),
|
|
21222
|
-
data,
|
|
21223
|
-
resultId,
|
|
21224
|
-
};
|
|
21225
|
-
if (callbacks?.onValidDocument) {
|
|
21226
|
-
callbacks.onValidDocument(result);
|
|
21306
|
+
catch (error) {
|
|
21307
|
+
errorMessage = functoolsKit.getErrorMessage(error);
|
|
21227
21308
|
}
|
|
21228
|
-
return result;
|
|
21229
21309
|
}
|
|
21230
21310
|
const result = {
|
|
21231
21311
|
isValid: false,
|
|
@@ -21236,8 +21316,8 @@ const jsonInternal = beginContext(async (outlineName, param) => {
|
|
|
21236
21316
|
data: null,
|
|
21237
21317
|
resultId,
|
|
21238
21318
|
};
|
|
21239
|
-
if (
|
|
21240
|
-
|
|
21319
|
+
if (outlineCallbacks?.onInvalidDocument) {
|
|
21320
|
+
outlineCallbacks.onInvalidDocument(result);
|
|
21241
21321
|
}
|
|
21242
21322
|
return result;
|
|
21243
21323
|
});
|
package/build/index.mjs
CHANGED
|
@@ -3827,7 +3827,12 @@ const RUN_FN = async (incoming, self) => {
|
|
|
3827
3827
|
mode: "user",
|
|
3828
3828
|
tools: [],
|
|
3829
3829
|
};
|
|
3830
|
-
const
|
|
3830
|
+
const completionMessage = await self.params.completion.getCompletion(args);
|
|
3831
|
+
const rawMessage = {
|
|
3832
|
+
agentName: self.params.agentName,
|
|
3833
|
+
mode: "tool",
|
|
3834
|
+
...completionMessage,
|
|
3835
|
+
};
|
|
3831
3836
|
self.params.completion.callbacks?.onComplete &&
|
|
3832
3837
|
self.params.completion.callbacks?.onComplete(args, rawMessage);
|
|
3833
3838
|
const message = await self.params.map(rawMessage, self.params.clientId, self.params.agentName);
|
|
@@ -4374,7 +4379,12 @@ class ClientAgent {
|
|
|
4374
4379
|
mode,
|
|
4375
4380
|
tools: await resolveTools(this.params.clientId, this.params.agentName, tools),
|
|
4376
4381
|
};
|
|
4377
|
-
const
|
|
4382
|
+
const rawMessage = await this.params.completion.getCompletion(args);
|
|
4383
|
+
const output = {
|
|
4384
|
+
agentName: this.params.agentName,
|
|
4385
|
+
mode: "tool",
|
|
4386
|
+
...rawMessage,
|
|
4387
|
+
};
|
|
4378
4388
|
if (GLOBAL_CONFIG.CC_RESQUE_STRATEGY === "flush") {
|
|
4379
4389
|
this.params.completion.callbacks?.onComplete &&
|
|
4380
4390
|
this.params.completion.callbacks?.onComplete(args, output);
|
|
@@ -4421,7 +4431,12 @@ class ClientAgent {
|
|
|
4421
4431
|
mode,
|
|
4422
4432
|
tools: await resolveTools(this.params.clientId, this.params.agentName, tools),
|
|
4423
4433
|
};
|
|
4424
|
-
const
|
|
4434
|
+
const rawMessage = await this.params.completion.getCompletion(args);
|
|
4435
|
+
const output = {
|
|
4436
|
+
agentName: this.params.agentName,
|
|
4437
|
+
mode: "tool",
|
|
4438
|
+
...rawMessage,
|
|
4439
|
+
};
|
|
4425
4440
|
this.params.completion.callbacks?.onComplete &&
|
|
4426
4441
|
this.params.completion.callbacks?.onComplete(args, output);
|
|
4427
4442
|
return {
|
|
@@ -9735,6 +9750,15 @@ class AgentValidationService {
|
|
|
9735
9750
|
* @readonly
|
|
9736
9751
|
*/
|
|
9737
9752
|
this.loggerService = inject(TYPES.loggerService);
|
|
9753
|
+
/**
|
|
9754
|
+
* Completion schema service instance for managing completion schemas.
|
|
9755
|
+
* Injected via DI, used in validate method to check agent completions.
|
|
9756
|
+
* Provides a registry of completion schemas for the swarm.
|
|
9757
|
+
* @type {CompletionSchemaService}
|
|
9758
|
+
* @private
|
|
9759
|
+
* @readonly
|
|
9760
|
+
*/
|
|
9761
|
+
this.completionSchemaService = inject(TYPES.completionSchemaService);
|
|
9738
9762
|
/**
|
|
9739
9763
|
* Tool validation service instance for validating tools associated with agents.
|
|
9740
9764
|
* Injected via DI, used in validate method to check agent tools.
|
|
@@ -9982,6 +10006,10 @@ class AgentValidationService {
|
|
|
9982
10006
|
if (!agent) {
|
|
9983
10007
|
throw new Error(`agent-swarm agent ${agentName} not found source=${source}`);
|
|
9984
10008
|
}
|
|
10009
|
+
const completionSchema = this.completionSchemaService.get(agent.completion);
|
|
10010
|
+
if (completionSchema.json) {
|
|
10011
|
+
throw new Error(`agent-swarm agent ${agentName} completion schema is JSON source=${source}`);
|
|
10012
|
+
}
|
|
9985
10013
|
if (!agent.operator) {
|
|
9986
10014
|
this.completionValidationService.validate(agent.completion, source);
|
|
9987
10015
|
}
|
|
@@ -13446,6 +13474,10 @@ class DocService {
|
|
|
13446
13474
|
}
|
|
13447
13475
|
result.push("");
|
|
13448
13476
|
}
|
|
13477
|
+
if (outlineSchema.completion) {
|
|
13478
|
+
result.push(`**Completion:** \`${sanitizeMarkdown(outlineSchema.completion)}\``);
|
|
13479
|
+
result.push("");
|
|
13480
|
+
}
|
|
13449
13481
|
const getPrompt = async () => {
|
|
13450
13482
|
try {
|
|
13451
13483
|
if (typeof outlineSchema.prompt === "string") {
|
|
@@ -18225,7 +18257,7 @@ class OutlineSchemaService {
|
|
|
18225
18257
|
this._registry = new ToolRegistry("outlineSchemaService");
|
|
18226
18258
|
/**
|
|
18227
18259
|
* Validates an outline schema for required properties and correct types.
|
|
18228
|
-
* Ensures `outlineName` is a string, `
|
|
18260
|
+
* Ensures `outlineName` is a string, `getOutlineHistory` is a function, and `validations` (if present) is an array of valid validation functions or objects.
|
|
18229
18261
|
* Logs validation attempts if `CC_LOGGER_ENABLE_INFO` is enabled.
|
|
18230
18262
|
* @private
|
|
18231
18263
|
* @param {IOutlineSchema} outlineSchema - The outline schema to validate.
|
|
@@ -18239,13 +18271,18 @@ class OutlineSchemaService {
|
|
|
18239
18271
|
if (typeof outlineSchema.outlineName !== "string") {
|
|
18240
18272
|
throw new Error(`agent-swarm outline schema validation failed: missing outlineName`);
|
|
18241
18273
|
}
|
|
18242
|
-
if (typeof outlineSchema.
|
|
18243
|
-
throw new Error(`agent-swarm outline schema validation failed: missing
|
|
18274
|
+
if (typeof outlineSchema.completion !== "string") {
|
|
18275
|
+
throw new Error(`agent-swarm outline schema validation failed: missing completion for outlineName=${outlineSchema.outlineName}`);
|
|
18276
|
+
}
|
|
18277
|
+
if (typeof outlineSchema.getOutlineHistory !== "function") {
|
|
18278
|
+
throw new Error(`agent-swarm outline schema validation failed: missing getOutlineHistory for outlineName=${outlineSchema.outlineName}`);
|
|
18244
18279
|
}
|
|
18245
|
-
if (outlineSchema.validations &&
|
|
18280
|
+
if (outlineSchema.validations &&
|
|
18281
|
+
!Array.isArray(outlineSchema.validations)) {
|
|
18246
18282
|
throw new Error(`agent-swarm outline schema validation failed: validations is not an array for outlineName=${outlineSchema.outlineName}`);
|
|
18247
18283
|
}
|
|
18248
|
-
if (outlineSchema.validations &&
|
|
18284
|
+
if (outlineSchema.validations &&
|
|
18285
|
+
outlineSchema.validations?.some((validation) => typeof validation !== "function" && !isObject$1(validation))) {
|
|
18249
18286
|
throw new Error(`agent-swarm outline schema validation failed: invalid validations for outlineName=${outlineSchema.outlineName}`);
|
|
18250
18287
|
}
|
|
18251
18288
|
};
|
|
@@ -18328,6 +18365,22 @@ class OutlineValidationService {
|
|
|
18328
18365
|
* @type {LoggerService}
|
|
18329
18366
|
*/
|
|
18330
18367
|
this.loggerService = inject(TYPES.loggerService);
|
|
18368
|
+
/**
|
|
18369
|
+
* Completion schema service instance for managing completion schemas.
|
|
18370
|
+
* Injected via DI, used in validate method to check outline completions.
|
|
18371
|
+
* Provides a registry of completion schemas for the swarm.
|
|
18372
|
+
* @type {CompletionSchemaService}
|
|
18373
|
+
* @private
|
|
18374
|
+
*/
|
|
18375
|
+
this.completionSchemaService = inject(TYPES.completionSchemaService);
|
|
18376
|
+
/**
|
|
18377
|
+
* Completion validation service instance for validating completion configurations of outlines.
|
|
18378
|
+
* Injected via DI, used in validate method to check outline completion.
|
|
18379
|
+
* @type {CompletionValidationService}
|
|
18380
|
+
* @private
|
|
18381
|
+
* @readonly
|
|
18382
|
+
*/
|
|
18383
|
+
this.completionValidationService = inject(TYPES.completionValidationService);
|
|
18331
18384
|
/**
|
|
18332
18385
|
* A map storing outline schemas, keyed by their unique outline names.
|
|
18333
18386
|
* Used to manage registered outlines and retrieve them for validation.
|
|
@@ -18381,6 +18434,11 @@ class OutlineValidationService {
|
|
|
18381
18434
|
if (!outline) {
|
|
18382
18435
|
throw new Error(`agent-swarm outline ${outlineName} not found source=${source}`);
|
|
18383
18436
|
}
|
|
18437
|
+
const completionSchema = this.completionSchemaService.get(outline.completion);
|
|
18438
|
+
if (!completionSchema.json) {
|
|
18439
|
+
throw new Error(`agent-swarm outline ${outlineName} completion schema is not JSON source=${source}`);
|
|
18440
|
+
}
|
|
18441
|
+
this.completionValidationService.validate(outline.completion, source);
|
|
18384
18442
|
return true;
|
|
18385
18443
|
});
|
|
18386
18444
|
}
|
|
@@ -21131,10 +21189,11 @@ class OutlineHistory {
|
|
|
21131
21189
|
constructor(prompt) {
|
|
21132
21190
|
/** @private */
|
|
21133
21191
|
this.messages = [];
|
|
21134
|
-
prompt &&
|
|
21135
|
-
|
|
21136
|
-
|
|
21137
|
-
|
|
21192
|
+
prompt &&
|
|
21193
|
+
this.messages.push({
|
|
21194
|
+
role: "system",
|
|
21195
|
+
content: prompt,
|
|
21196
|
+
});
|
|
21138
21197
|
}
|
|
21139
21198
|
/**
|
|
21140
21199
|
* Appends one or more messages to the history.
|
|
@@ -21177,7 +21236,9 @@ const jsonInternal = beginContext(async (outlineName, param) => {
|
|
|
21177
21236
|
swarm$1.loggerService.log(METHOD_NAME$D, {});
|
|
21178
21237
|
swarm$1.outlineValidationService.validate(outlineName, METHOD_NAME$D);
|
|
21179
21238
|
const resultId = randomString();
|
|
21180
|
-
const {
|
|
21239
|
+
const { getOutlineHistory, completion, validations = [], maxAttempts = MAX_ATTEMPTS, format, prompt, callbacks: outlineCallbacks, } = swarm$1.outlineSchemaService.get(outlineName);
|
|
21240
|
+
swarm$1.completionValidationService.validate(completion, METHOD_NAME$D);
|
|
21241
|
+
const { getCompletion, callbacks: completionCallbacks } = swarm$1.completionSchemaService.get(completion);
|
|
21181
21242
|
let errorMessage = "";
|
|
21182
21243
|
let history;
|
|
21183
21244
|
const systemPrompt = str.newline(typeof prompt === "function" ? await prompt(outlineName) : prompt);
|
|
@@ -21189,41 +21250,60 @@ const jsonInternal = beginContext(async (outlineName, param) => {
|
|
|
21189
21250
|
param,
|
|
21190
21251
|
history,
|
|
21191
21252
|
};
|
|
21192
|
-
if (
|
|
21193
|
-
|
|
21253
|
+
if (outlineCallbacks?.onAttempt) {
|
|
21254
|
+
outlineCallbacks.onAttempt(inputArgs);
|
|
21194
21255
|
}
|
|
21195
|
-
|
|
21196
|
-
const
|
|
21197
|
-
|
|
21198
|
-
|
|
21199
|
-
|
|
21200
|
-
|
|
21201
|
-
|
|
21202
|
-
|
|
21203
|
-
|
|
21204
|
-
|
|
21256
|
+
await getOutlineHistory(inputArgs);
|
|
21257
|
+
const messages = await history.list();
|
|
21258
|
+
try {
|
|
21259
|
+
const output = await getCompletion({
|
|
21260
|
+
messages: await history.list(),
|
|
21261
|
+
mode: "tool",
|
|
21262
|
+
outlineName,
|
|
21263
|
+
});
|
|
21264
|
+
if (completionCallbacks?.onComplete) {
|
|
21265
|
+
completionCallbacks.onComplete({
|
|
21266
|
+
messages,
|
|
21267
|
+
mode: "tool",
|
|
21268
|
+
outlineName,
|
|
21269
|
+
}, output);
|
|
21205
21270
|
}
|
|
21206
|
-
|
|
21207
|
-
|
|
21208
|
-
|
|
21209
|
-
|
|
21271
|
+
const data = JSON.parse(output.content);
|
|
21272
|
+
const validationArgs = {
|
|
21273
|
+
...inputArgs,
|
|
21274
|
+
data,
|
|
21275
|
+
};
|
|
21276
|
+
let isValid = true;
|
|
21277
|
+
for (const validation of validations) {
|
|
21278
|
+
const validate = typeof validation === "object" ? validation.validate : validation;
|
|
21279
|
+
try {
|
|
21280
|
+
await validate(validationArgs);
|
|
21281
|
+
}
|
|
21282
|
+
catch (error) {
|
|
21283
|
+
isValid = false;
|
|
21284
|
+
errorMessage = getErrorMessage(error);
|
|
21285
|
+
break;
|
|
21286
|
+
}
|
|
21210
21287
|
}
|
|
21288
|
+
if (!isValid) {
|
|
21289
|
+
continue;
|
|
21290
|
+
}
|
|
21291
|
+
const result = {
|
|
21292
|
+
isValid: true,
|
|
21293
|
+
attempt,
|
|
21294
|
+
param,
|
|
21295
|
+
history: await history.list(),
|
|
21296
|
+
data,
|
|
21297
|
+
resultId,
|
|
21298
|
+
};
|
|
21299
|
+
if (outlineCallbacks?.onValidDocument) {
|
|
21300
|
+
outlineCallbacks.onValidDocument(result);
|
|
21301
|
+
}
|
|
21302
|
+
return result;
|
|
21211
21303
|
}
|
|
21212
|
-
|
|
21213
|
-
|
|
21214
|
-
}
|
|
21215
|
-
const result = {
|
|
21216
|
-
isValid: true,
|
|
21217
|
-
attempt,
|
|
21218
|
-
param,
|
|
21219
|
-
history: await history.list(),
|
|
21220
|
-
data,
|
|
21221
|
-
resultId,
|
|
21222
|
-
};
|
|
21223
|
-
if (callbacks?.onValidDocument) {
|
|
21224
|
-
callbacks.onValidDocument(result);
|
|
21304
|
+
catch (error) {
|
|
21305
|
+
errorMessage = getErrorMessage(error);
|
|
21225
21306
|
}
|
|
21226
|
-
return result;
|
|
21227
21307
|
}
|
|
21228
21308
|
const result = {
|
|
21229
21309
|
isValid: false,
|
|
@@ -21234,8 +21314,8 @@ const jsonInternal = beginContext(async (outlineName, param) => {
|
|
|
21234
21314
|
data: null,
|
|
21235
21315
|
resultId,
|
|
21236
21316
|
};
|
|
21237
|
-
if (
|
|
21238
|
-
|
|
21317
|
+
if (outlineCallbacks?.onInvalidDocument) {
|
|
21318
|
+
outlineCallbacks.onInvalidDocument(result);
|
|
21239
21319
|
}
|
|
21240
21320
|
return result;
|
|
21241
21321
|
});
|