@google/gemini-cli-core 0.8.0-nightly.20250930.ddcbd0c2 → 0.8.0-preview.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/dist/src/agents/codebase-investigator.d.ts +11 -0
- package/dist/src/agents/codebase-investigator.js +73 -0
- package/dist/src/agents/codebase-investigator.js.map +1 -0
- package/dist/src/agents/executor.d.ts +88 -0
- package/dist/src/agents/executor.js +417 -0
- package/dist/src/agents/executor.js.map +1 -0
- package/dist/src/agents/executor.test.d.ts +6 -0
- package/dist/src/agents/executor.test.js +419 -0
- package/dist/src/agents/executor.test.js.map +1 -0
- package/dist/src/agents/invocation.d.ts +43 -0
- package/dist/src/agents/invocation.js +100 -0
- package/dist/src/agents/invocation.js.map +1 -0
- package/dist/src/agents/invocation.test.d.ts +6 -0
- package/dist/src/agents/invocation.test.js +206 -0
- package/dist/src/agents/invocation.test.js.map +1 -0
- package/dist/src/agents/registry.d.ts +35 -0
- package/dist/src/agents/registry.js +58 -0
- package/dist/src/agents/registry.js.map +1 -0
- package/dist/src/agents/registry.test.d.ts +6 -0
- package/dist/src/agents/registry.test.js +146 -0
- package/dist/src/agents/registry.test.js.map +1 -0
- package/dist/src/agents/schema-utils.d.ts +39 -0
- package/dist/src/agents/schema-utils.js +57 -0
- package/dist/src/agents/schema-utils.js.map +1 -0
- package/dist/src/agents/schema-utils.test.d.ts +6 -0
- package/dist/src/agents/schema-utils.test.js +144 -0
- package/dist/src/agents/schema-utils.test.js.map +1 -0
- package/dist/src/agents/subagent-tool-wrapper.d.ts +36 -0
- package/dist/src/agents/subagent-tool-wrapper.js +47 -0
- package/dist/src/agents/subagent-tool-wrapper.js.map +1 -0
- package/dist/src/agents/subagent-tool-wrapper.test.d.ts +6 -0
- package/dist/src/agents/subagent-tool-wrapper.test.js +105 -0
- package/dist/src/agents/subagent-tool-wrapper.test.js.map +1 -0
- package/dist/src/agents/types.d.ts +116 -0
- package/dist/src/agents/types.js +17 -0
- package/dist/src/agents/types.js.map +1 -0
- package/dist/src/agents/utils.d.ts +15 -0
- package/dist/src/agents/utils.js +29 -0
- package/dist/src/agents/utils.js.map +1 -0
- package/dist/src/agents/utils.test.d.ts +6 -0
- package/dist/src/agents/utils.test.js +87 -0
- package/dist/src/agents/utils.test.js.map +1 -0
- package/dist/src/generated/git-commit.d.ts +2 -2
- package/dist/src/generated/git-commit.js +2 -2
- package/dist/src/generated/git-commit.js.map +1 -1
- package/dist/src/ide/detect-ide.d.ts +1 -0
- package/dist/src/ide/detect-ide.js +4 -1
- package/dist/src/ide/detect-ide.js.map +1 -1
- package/dist/src/services/shellExecutionService.d.ts +2 -0
- package/dist/src/services/shellExecutionService.js +48 -7
- package/dist/src/services/shellExecutionService.js.map +1 -1
- package/dist/src/services/shellExecutionService.test.js +13 -4
- package/dist/src/services/shellExecutionService.test.js.map +1 -1
- package/dist/src/telemetry/clearcut-logger/clearcut-logger.js +4 -1
- package/dist/src/telemetry/clearcut-logger/clearcut-logger.js.map +1 -1
- package/dist/src/telemetry/clearcut-logger/clearcut-logger.test.js +18 -0
- package/dist/src/telemetry/clearcut-logger/clearcut-logger.test.js.map +1 -1
- package/dist/src/telemetry/constants.d.ts +0 -24
- package/dist/src/telemetry/constants.js +0 -25
- package/dist/src/telemetry/constants.js.map +1 -1
- package/dist/src/telemetry/loggers.js +42 -9
- package/dist/src/telemetry/loggers.js.map +1 -1
- package/dist/src/telemetry/loggers.test.js +39 -8
- package/dist/src/telemetry/loggers.test.js.map +1 -1
- package/dist/src/telemetry/metrics.d.ts +278 -19
- package/dist/src/telemetry/metrics.js +303 -235
- package/dist/src/telemetry/metrics.js.map +1 -1
- package/dist/src/telemetry/metrics.test.js +191 -54
- package/dist/src/telemetry/metrics.test.js.map +1 -1
- package/dist/src/tools/smart-edit.js +56 -0
- package/dist/src/tools/smart-edit.js.map +1 -1
- package/dist/src/tools/smart-edit.test.js +19 -0
- package/dist/src/tools/smart-edit.test.js.map +1 -1
- package/dist/src/utils/llm-edit-fixer.js +10 -1
- package/dist/src/utils/llm-edit-fixer.js.map +1 -1
- package/dist/src/utils/llm-edit-fixer.test.js +81 -0
- package/dist/src/utils/llm-edit-fixer.test.js.map +1 -1
- package/dist/src/utils/memoryImportProcessor.js +13 -20
- package/dist/src/utils/memoryImportProcessor.js.map +1 -1
- package/dist/src/utils/memoryImportProcessor.test.js +14 -0
- package/dist/src/utils/memoryImportProcessor.test.js.map +1 -1
- package/dist/src/utils/terminalSerializer.d.ts +1 -4
- package/dist/src/utils/terminalSerializer.js +3 -3
- package/dist/src/utils/terminalSerializer.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import { describe, it, expect } from 'vitest';
|
|
7
|
+
import { convertInputConfigToJsonSchema } from './schema-utils.js';
|
|
8
|
+
const PRIMITIVE_TYPES_CONFIG = {
|
|
9
|
+
inputs: {
|
|
10
|
+
goal: {
|
|
11
|
+
type: 'string',
|
|
12
|
+
description: 'The primary objective',
|
|
13
|
+
required: true,
|
|
14
|
+
},
|
|
15
|
+
max_retries: {
|
|
16
|
+
type: 'integer',
|
|
17
|
+
description: 'Maximum number of retries',
|
|
18
|
+
required: false,
|
|
19
|
+
},
|
|
20
|
+
temperature: {
|
|
21
|
+
type: 'number',
|
|
22
|
+
description: 'The model temperature',
|
|
23
|
+
required: true,
|
|
24
|
+
},
|
|
25
|
+
verbose: {
|
|
26
|
+
type: 'boolean',
|
|
27
|
+
description: 'Enable verbose logging',
|
|
28
|
+
required: false,
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
const ARRAY_TYPES_CONFIG = {
|
|
33
|
+
inputs: {
|
|
34
|
+
filenames: {
|
|
35
|
+
type: 'string[]',
|
|
36
|
+
description: 'A list of file paths',
|
|
37
|
+
required: true,
|
|
38
|
+
},
|
|
39
|
+
scores: {
|
|
40
|
+
type: 'number[]',
|
|
41
|
+
description: 'A list of scores',
|
|
42
|
+
required: false,
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
const NO_REQUIRED_FIELDS_CONFIG = {
|
|
47
|
+
inputs: {
|
|
48
|
+
optional_param: {
|
|
49
|
+
type: 'string',
|
|
50
|
+
description: 'An optional parameter',
|
|
51
|
+
required: false,
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
const ALL_REQUIRED_FIELDS_CONFIG = {
|
|
56
|
+
inputs: {
|
|
57
|
+
paramA: { type: 'string', description: 'Parameter A', required: true },
|
|
58
|
+
paramB: { type: 'boolean', description: 'Parameter B', required: true },
|
|
59
|
+
},
|
|
60
|
+
};
|
|
61
|
+
const EMPTY_CONFIG = {
|
|
62
|
+
inputs: {},
|
|
63
|
+
};
|
|
64
|
+
const UNSUPPORTED_TYPE_CONFIG = {
|
|
65
|
+
inputs: {
|
|
66
|
+
invalid_param: {
|
|
67
|
+
// @ts-expect-error - Intentionally testing an invalid type
|
|
68
|
+
type: 'date',
|
|
69
|
+
description: 'This type is not supported',
|
|
70
|
+
required: true,
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
};
|
|
74
|
+
describe('convertInputConfigToJsonSchema', () => {
|
|
75
|
+
describe('type conversion', () => {
|
|
76
|
+
it('should correctly convert an InputConfig with various primitive types', () => {
|
|
77
|
+
const result = convertInputConfigToJsonSchema(PRIMITIVE_TYPES_CONFIG);
|
|
78
|
+
expect(result).toEqual({
|
|
79
|
+
type: 'object',
|
|
80
|
+
properties: {
|
|
81
|
+
goal: { type: 'string', description: 'The primary objective' },
|
|
82
|
+
max_retries: {
|
|
83
|
+
type: 'integer',
|
|
84
|
+
description: 'Maximum number of retries',
|
|
85
|
+
},
|
|
86
|
+
temperature: { type: 'number', description: 'The model temperature' },
|
|
87
|
+
verbose: { type: 'boolean', description: 'Enable verbose logging' },
|
|
88
|
+
},
|
|
89
|
+
required: ['goal', 'temperature'],
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
it('should correctly handle array types for strings and numbers', () => {
|
|
93
|
+
const result = convertInputConfigToJsonSchema(ARRAY_TYPES_CONFIG);
|
|
94
|
+
expect(result).toEqual({
|
|
95
|
+
type: 'object',
|
|
96
|
+
properties: {
|
|
97
|
+
filenames: {
|
|
98
|
+
type: 'array',
|
|
99
|
+
description: 'A list of file paths',
|
|
100
|
+
items: { type: 'string' },
|
|
101
|
+
},
|
|
102
|
+
scores: {
|
|
103
|
+
type: 'array',
|
|
104
|
+
description: 'A list of scores',
|
|
105
|
+
items: { type: 'number' },
|
|
106
|
+
},
|
|
107
|
+
},
|
|
108
|
+
required: ['filenames'],
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
describe('required field handling', () => {
|
|
113
|
+
it('should produce an undefined `required` field when no inputs are required', () => {
|
|
114
|
+
const result = convertInputConfigToJsonSchema(NO_REQUIRED_FIELDS_CONFIG);
|
|
115
|
+
expect(result.properties['optional_param']).toBeDefined();
|
|
116
|
+
// Per the implementation and JSON Schema spec, the `required` field
|
|
117
|
+
// should be omitted if no properties are required.
|
|
118
|
+
expect(result.required).toBeUndefined();
|
|
119
|
+
});
|
|
120
|
+
it('should list all properties in `required` when all are marked as required', () => {
|
|
121
|
+
const result = convertInputConfigToJsonSchema(ALL_REQUIRED_FIELDS_CONFIG);
|
|
122
|
+
expect(result.required).toHaveLength(2);
|
|
123
|
+
expect(result.required).toEqual(expect.arrayContaining(['paramA', 'paramB']));
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
describe('edge cases', () => {
|
|
127
|
+
it('should return a valid, empty schema for an empty input config', () => {
|
|
128
|
+
const result = convertInputConfigToJsonSchema(EMPTY_CONFIG);
|
|
129
|
+
expect(result).toEqual({
|
|
130
|
+
type: 'object',
|
|
131
|
+
properties: {},
|
|
132
|
+
required: undefined,
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
});
|
|
136
|
+
describe('error handling', () => {
|
|
137
|
+
it('should throw an informative error for an unsupported input type', () => {
|
|
138
|
+
const action = () => convertInputConfigToJsonSchema(UNSUPPORTED_TYPE_CONFIG);
|
|
139
|
+
expect(action).toThrow(/Unsupported input type 'date'/);
|
|
140
|
+
expect(action).toThrow(/parameter 'invalid_param'/);
|
|
141
|
+
});
|
|
142
|
+
});
|
|
143
|
+
});
|
|
144
|
+
//# sourceMappingURL=schema-utils.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema-utils.test.js","sourceRoot":"","sources":["../../../src/agents/schema-utils.test.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAE,8BAA8B,EAAE,MAAM,mBAAmB,CAAC;AAGnE,MAAM,sBAAsB,GAAgB;IAC1C,MAAM,EAAE;QACN,IAAI,EAAE;YACJ,IAAI,EAAE,QAAQ;YACd,WAAW,EAAE,uBAAuB;YACpC,QAAQ,EAAE,IAAI;SACf;QACD,WAAW,EAAE;YACX,IAAI,EAAE,SAAS;YACf,WAAW,EAAE,2BAA2B;YACxC,QAAQ,EAAE,KAAK;SAChB;QACD,WAAW,EAAE;YACX,IAAI,EAAE,QAAQ;YACd,WAAW,EAAE,uBAAuB;YACpC,QAAQ,EAAE,IAAI;SACf;QACD,OAAO,EAAE;YACP,IAAI,EAAE,SAAS;YACf,WAAW,EAAE,wBAAwB;YACrC,QAAQ,EAAE,KAAK;SAChB;KACF;CACF,CAAC;AAEF,MAAM,kBAAkB,GAAgB;IACtC,MAAM,EAAE;QACN,SAAS,EAAE;YACT,IAAI,EAAE,UAAU;YAChB,WAAW,EAAE,sBAAsB;YACnC,QAAQ,EAAE,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AA8B,CAAC,0BAA0B,CAAC,CAAC;YAC1E,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;YACxC,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,OAAO,CAC7B,MAAM,CAAC,eAAe,CAAC,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAC7C,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,QAAQ,CAAC,YAAY,EAAE,GAAG,EAAE;QAC1B,EAAE,CAAC,+DAA+D,EAAE,GAAG,EAAE;YACvE,MAAM,MAAM,GAAG,8BAA8B,CAAC,YAAY,CAAC,CAAC;YAE5D,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC;gBACrB,IAAI,EAAE,QAAQ;gBACd,UAAU,EAAE,EAAE;gBACd,QAAQ,EAAE,SAAS;aACpB,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,QAAQ,CAAC,gBAAgB,EAAE,GAAG,EAAE;QAC9B,EAAE,CAAC,iEAAiE,EAAE,GAAG,EAAE;YACzE,MAAM,MAAM,GAAG,GAAG,EAAE,CAClB,8BAA8B,CAAC,uBAAuB,CAAC,CAAC;YAE1D,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,+BAA+B,CAAC,CAAC;YACxD,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,2BAA2B,CAAC,CAAC;QACtD,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import { BaseDeclarativeTool, type ToolInvocation, type ToolResult } from '../tools/tools.js';
|
|
7
|
+
import type { Config } from '../config/config.js';
|
|
8
|
+
import type { AgentDefinition, AgentInputs } from './types.js';
|
|
9
|
+
/**
|
|
10
|
+
* A tool wrapper that dynamically exposes a subagent as a standard,
|
|
11
|
+
* strongly-typed `DeclarativeTool`.
|
|
12
|
+
*/
|
|
13
|
+
export declare class SubagentToolWrapper extends BaseDeclarativeTool<AgentInputs, ToolResult> {
|
|
14
|
+
private readonly definition;
|
|
15
|
+
private readonly config;
|
|
16
|
+
/**
|
|
17
|
+
* Constructs the tool wrapper.
|
|
18
|
+
*
|
|
19
|
+
* The constructor dynamically generates the JSON schema for the tool's
|
|
20
|
+
* parameters based on the subagent's input configuration.
|
|
21
|
+
*
|
|
22
|
+
* @param definition The `AgentDefinition` of the subagent to wrap.
|
|
23
|
+
* @param config The runtime configuration, passed down to the subagent.
|
|
24
|
+
*/
|
|
25
|
+
constructor(definition: AgentDefinition, config: Config);
|
|
26
|
+
/**
|
|
27
|
+
* Creates an invocation instance for executing the subagent.
|
|
28
|
+
*
|
|
29
|
+
* This method is called by the tool framework when the parent agent decides
|
|
30
|
+
* to use this tool.
|
|
31
|
+
*
|
|
32
|
+
* @param params The validated input parameters from the parent agent's call.
|
|
33
|
+
* @returns A `ToolInvocation` instance ready for execution.
|
|
34
|
+
*/
|
|
35
|
+
protected createInvocation(params: AgentInputs): ToolInvocation<AgentInputs, ToolResult>;
|
|
36
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import { BaseDeclarativeTool, Kind, } from '../tools/tools.js';
|
|
7
|
+
import { convertInputConfigToJsonSchema } from './schema-utils.js';
|
|
8
|
+
import { SubagentInvocation } from './invocation.js';
|
|
9
|
+
/**
|
|
10
|
+
* A tool wrapper that dynamically exposes a subagent as a standard,
|
|
11
|
+
* strongly-typed `DeclarativeTool`.
|
|
12
|
+
*/
|
|
13
|
+
export class SubagentToolWrapper extends BaseDeclarativeTool {
|
|
14
|
+
definition;
|
|
15
|
+
config;
|
|
16
|
+
/**
|
|
17
|
+
* Constructs the tool wrapper.
|
|
18
|
+
*
|
|
19
|
+
* The constructor dynamically generates the JSON schema for the tool's
|
|
20
|
+
* parameters based on the subagent's input configuration.
|
|
21
|
+
*
|
|
22
|
+
* @param definition The `AgentDefinition` of the subagent to wrap.
|
|
23
|
+
* @param config The runtime configuration, passed down to the subagent.
|
|
24
|
+
*/
|
|
25
|
+
constructor(definition, config) {
|
|
26
|
+
// Dynamically generate the JSON schema required for the tool definition.
|
|
27
|
+
const parameterSchema = convertInputConfigToJsonSchema(definition.inputConfig);
|
|
28
|
+
super(definition.name, definition.displayName ?? definition.name, definition.description, Kind.Think, parameterSchema,
|
|
29
|
+
/* isOutputMarkdown */ true,
|
|
30
|
+
/* canUpdateOutput */ true);
|
|
31
|
+
this.definition = definition;
|
|
32
|
+
this.config = config;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Creates an invocation instance for executing the subagent.
|
|
36
|
+
*
|
|
37
|
+
* This method is called by the tool framework when the parent agent decides
|
|
38
|
+
* to use this tool.
|
|
39
|
+
*
|
|
40
|
+
* @param params The validated input parameters from the parent agent's call.
|
|
41
|
+
* @returns A `ToolInvocation` instance ready for execution.
|
|
42
|
+
*/
|
|
43
|
+
createInvocation(params) {
|
|
44
|
+
return new SubagentInvocation(params, this.definition, this.config);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=subagent-tool-wrapper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"subagent-tool-wrapper.js","sourceRoot":"","sources":["../../../src/agents/subagent-tool-wrapper.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EACL,mBAAmB,EACnB,IAAI,GAGL,MAAM,mBAAmB,CAAC;AAG3B,OAAO,EAAE,8BAA8B,EAAE,MAAM,mBAAmB,CAAC;AACnE,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAErD;;;GAGG;AACH,MAAM,OAAO,mBAAoB,SAAQ,mBAGxC;IAWoB;IACA;IAXnB;;;;;;;;OAQG;IACH,YACmB,UAA2B,EAC3B,MAAc;QAE/B,yEAAyE;QACzE,MAAM,eAAe,GAAG,8BAA8B,CACpD,UAAU,CAAC,WAAW,CACvB,CAAC;QAEF,KAAK,CACH,UAAU,CAAC,IAAI,EACf,UAAU,CAAC,WAAW,IAAI,UAAU,CAAC,IAAI,EACzC,UAAU,CAAC,WAAW,EACtB,IAAI,CAAC,KAAK,EACV,eAAe;QACf,sBAAsB,CAAC,IAAI;QAC3B,qBAAqB,CAAC,IAAI,CAC3B,CAAC;QAhBe,eAAU,GAAV,UAAU,CAAiB;QAC3B,WAAM,GAAN,MAAM,CAAQ;IAgBjC,CAAC;IAED;;;;;;;;OAQG;IACO,gBAAgB,CACxB,MAAmB;QAEnB,OAAO,IAAI,kBAAkB,CAAC,MAAM,EAAE,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;IACtE,CAAC;CACF"}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
7
|
+
import { SubagentToolWrapper } from './subagent-tool-wrapper.js';
|
|
8
|
+
import { SubagentInvocation } from './invocation.js';
|
|
9
|
+
import { convertInputConfigToJsonSchema } from './schema-utils.js';
|
|
10
|
+
import { makeFakeConfig } from '../test-utils/config.js';
|
|
11
|
+
import { Kind } from '../tools/tools.js';
|
|
12
|
+
// Mock dependencies to isolate the SubagentToolWrapper class
|
|
13
|
+
vi.mock('./invocation.js');
|
|
14
|
+
vi.mock('./schema-utils.js');
|
|
15
|
+
const MockedSubagentInvocation = vi.mocked(SubagentInvocation);
|
|
16
|
+
const mockConvertInputConfigToJsonSchema = vi.mocked(convertInputConfigToJsonSchema);
|
|
17
|
+
// Define reusable test data
|
|
18
|
+
let mockConfig;
|
|
19
|
+
const mockDefinition = {
|
|
20
|
+
name: 'TestAgent',
|
|
21
|
+
displayName: 'Test Agent Display Name',
|
|
22
|
+
description: 'An agent for testing.',
|
|
23
|
+
inputConfig: {
|
|
24
|
+
inputs: {
|
|
25
|
+
goal: { type: 'string', required: true, description: 'The goal.' },
|
|
26
|
+
priority: {
|
|
27
|
+
type: 'number',
|
|
28
|
+
required: false,
|
|
29
|
+
description: 'The priority.',
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
modelConfig: { model: 'gemini-test-model', temp: 0, top_p: 1 },
|
|
34
|
+
runConfig: { max_time_minutes: 5 },
|
|
35
|
+
promptConfig: { systemPrompt: 'You are a test agent.' },
|
|
36
|
+
};
|
|
37
|
+
const mockSchema = {
|
|
38
|
+
type: 'object',
|
|
39
|
+
properties: {
|
|
40
|
+
goal: { type: 'string', description: 'The goal.' },
|
|
41
|
+
priority: { type: 'number', description: 'The priority.' },
|
|
42
|
+
},
|
|
43
|
+
required: ['goal'],
|
|
44
|
+
};
|
|
45
|
+
describe('SubagentToolWrapper', () => {
|
|
46
|
+
beforeEach(() => {
|
|
47
|
+
vi.clearAllMocks();
|
|
48
|
+
mockConfig = makeFakeConfig();
|
|
49
|
+
// Provide a mock implementation for the schema conversion utility
|
|
50
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
51
|
+
mockConvertInputConfigToJsonSchema.mockReturnValue(mockSchema);
|
|
52
|
+
});
|
|
53
|
+
describe('constructor', () => {
|
|
54
|
+
it('should call convertInputConfigToJsonSchema with the correct agent inputConfig', () => {
|
|
55
|
+
new SubagentToolWrapper(mockDefinition, mockConfig);
|
|
56
|
+
expect(convertInputConfigToJsonSchema).toHaveBeenCalledOnce();
|
|
57
|
+
expect(convertInputConfigToJsonSchema).toHaveBeenCalledWith(mockDefinition.inputConfig);
|
|
58
|
+
});
|
|
59
|
+
it('should correctly configure the tool properties from the agent definition', () => {
|
|
60
|
+
const wrapper = new SubagentToolWrapper(mockDefinition, mockConfig);
|
|
61
|
+
expect(wrapper.name).toBe(mockDefinition.name);
|
|
62
|
+
expect(wrapper.displayName).toBe(mockDefinition.displayName);
|
|
63
|
+
expect(wrapper.description).toBe(mockDefinition.description);
|
|
64
|
+
expect(wrapper.kind).toBe(Kind.Think);
|
|
65
|
+
expect(wrapper.isOutputMarkdown).toBe(true);
|
|
66
|
+
expect(wrapper.canUpdateOutput).toBe(true);
|
|
67
|
+
});
|
|
68
|
+
it('should fall back to the agent name for displayName if it is not provided', () => {
|
|
69
|
+
const definitionWithoutDisplayName = {
|
|
70
|
+
...mockDefinition,
|
|
71
|
+
displayName: undefined,
|
|
72
|
+
};
|
|
73
|
+
const wrapper = new SubagentToolWrapper(definitionWithoutDisplayName, mockConfig);
|
|
74
|
+
expect(wrapper.displayName).toBe(definitionWithoutDisplayName.name);
|
|
75
|
+
});
|
|
76
|
+
it('should generate a valid tool schema using the definition and converted schema', () => {
|
|
77
|
+
const wrapper = new SubagentToolWrapper(mockDefinition, mockConfig);
|
|
78
|
+
const schema = wrapper.schema;
|
|
79
|
+
expect(schema.name).toBe(mockDefinition.name);
|
|
80
|
+
expect(schema.description).toBe(mockDefinition.description);
|
|
81
|
+
expect(schema.parametersJsonSchema).toEqual(mockSchema);
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
describe('createInvocation', () => {
|
|
85
|
+
it('should create a SubagentInvocation with the correct parameters', () => {
|
|
86
|
+
const wrapper = new SubagentToolWrapper(mockDefinition, mockConfig);
|
|
87
|
+
const params = { goal: 'Test the invocation', priority: 1 };
|
|
88
|
+
// The public `build` method calls the protected `createInvocation` after validation
|
|
89
|
+
const invocation = wrapper.build(params);
|
|
90
|
+
expect(invocation).toBeInstanceOf(SubagentInvocation);
|
|
91
|
+
expect(MockedSubagentInvocation).toHaveBeenCalledOnce();
|
|
92
|
+
expect(MockedSubagentInvocation).toHaveBeenCalledWith(params, mockDefinition, mockConfig);
|
|
93
|
+
});
|
|
94
|
+
it('should throw a validation error for invalid parameters before creating an invocation', () => {
|
|
95
|
+
const wrapper = new SubagentToolWrapper(mockDefinition, mockConfig);
|
|
96
|
+
// Missing the required 'goal' parameter
|
|
97
|
+
const invalidParams = { priority: 1 };
|
|
98
|
+
// The `build` method in the base class performs JSON schema validation
|
|
99
|
+
// before calling the protected `createInvocation` method.
|
|
100
|
+
expect(() => wrapper.build(invalidParams)).toThrow("params must have required property 'goal'");
|
|
101
|
+
expect(MockedSubagentInvocation).not.toHaveBeenCalled();
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
//# sourceMappingURL=subagent-tool-wrapper.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"subagent-tool-wrapper.test.js","sourceRoot":"","sources":["../../../src/agents/subagent-tool-wrapper.test.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAC9D,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,EAAE,8BAA8B,EAAE,MAAM,mBAAmB,CAAC;AACnE,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAGzD,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAEzC,6DAA6D;AAC7D,EAAE,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC;AAC3B,EAAE,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC;AAE7B,MAAM,wBAAwB,GAAG,EAAE,CAAC,MAAM,CAAC,kBA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YACpE,wCAAwC;YACxC,MAAM,aAAa,GAAG,EAAE,QAAQ,EAAE,CAAC,EAAE,CAAC;YAEtC,uEAAuE;YACvE,0DAA0D;YAC1D,MAAM,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC,CAAC,OAAO,CAChD,2CAA2C,CAC5C,CAAC;YACF,MAAM,CAAC,wBAAwB,CAAC,CAAC,GAAG,CAAC,gBAAgB,EAAE,CAAC;QAC1D,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* @fileoverview Defines the core configuration interfaces and types for the agent architecture.
|
|
8
|
+
*/
|
|
9
|
+
import type { Content, FunctionDeclaration } from '@google/genai';
|
|
10
|
+
import type { AnyDeclarativeTool } from '../tools/tools.js';
|
|
11
|
+
/**
|
|
12
|
+
* Describes the possible termination modes for an agent.
|
|
13
|
+
*/
|
|
14
|
+
export declare enum AgentTerminateMode {
|
|
15
|
+
ERROR = "ERROR",
|
|
16
|
+
TIMEOUT = "TIMEOUT",
|
|
17
|
+
GOAL = "GOAL",
|
|
18
|
+
MAX_TURNS = "MAX_TURNS",
|
|
19
|
+
ABORTED = "ABORTED"
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Represents the output structure of an agent's execution.
|
|
23
|
+
*/
|
|
24
|
+
export interface OutputObject {
|
|
25
|
+
result: string;
|
|
26
|
+
terminate_reason: AgentTerminateMode;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Represents the validated input parameters passed to an agent upon invocation.
|
|
30
|
+
* Used primarily for templating the system prompt. (Replaces ContextState)
|
|
31
|
+
*/
|
|
32
|
+
export type AgentInputs = Record<string, unknown>;
|
|
33
|
+
/**
|
|
34
|
+
* Structured events emitted during subagent execution for user observability.
|
|
35
|
+
*/
|
|
36
|
+
export interface SubagentActivityEvent {
|
|
37
|
+
isSubagentActivityEvent: true;
|
|
38
|
+
agentName: string;
|
|
39
|
+
type: 'TOOL_CALL_START' | 'TOOL_CALL_END' | 'THOUGHT_CHUNK' | 'ERROR';
|
|
40
|
+
data: Record<string, unknown>;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* The definition for an agent.
|
|
44
|
+
*/
|
|
45
|
+
export interface AgentDefinition {
|
|
46
|
+
/** Unique identifier for the agent. */
|
|
47
|
+
name: string;
|
|
48
|
+
displayName?: string;
|
|
49
|
+
description: string;
|
|
50
|
+
promptConfig: PromptConfig;
|
|
51
|
+
modelConfig: ModelConfig;
|
|
52
|
+
runConfig: RunConfig;
|
|
53
|
+
toolConfig?: ToolConfig;
|
|
54
|
+
outputConfig?: OutputConfig;
|
|
55
|
+
inputConfig: InputConfig;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Configures the initial prompt for the agent.
|
|
59
|
+
*/
|
|
60
|
+
export interface PromptConfig {
|
|
61
|
+
/**
|
|
62
|
+
* A single system prompt string. Supports templating using `${input_name}` syntax.
|
|
63
|
+
*/
|
|
64
|
+
systemPrompt?: string;
|
|
65
|
+
/**
|
|
66
|
+
* An array of user/model content pairs for few-shot prompting.
|
|
67
|
+
*/
|
|
68
|
+
initialMessages?: Content[];
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Configures the tools available to the agent during its execution.
|
|
72
|
+
*/
|
|
73
|
+
export interface ToolConfig {
|
|
74
|
+
tools: Array<string | FunctionDeclaration | AnyDeclarativeTool>;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Configures the expected inputs (parameters) for the agent.
|
|
78
|
+
*/
|
|
79
|
+
export interface InputConfig {
|
|
80
|
+
/**
|
|
81
|
+
* Defines the parameters the agent accepts.
|
|
82
|
+
* This is vital for generating the tool wrapper schema.
|
|
83
|
+
*/
|
|
84
|
+
inputs: Record<string, {
|
|
85
|
+
description: string;
|
|
86
|
+
type: 'string' | 'number' | 'boolean' | 'integer' | 'string[]' | 'number[]';
|
|
87
|
+
required: boolean;
|
|
88
|
+
}>;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Configures the expected outputs for the agent.
|
|
92
|
+
*/
|
|
93
|
+
export interface OutputConfig {
|
|
94
|
+
/** Description of what the agent should return when finished. */
|
|
95
|
+
description: string;
|
|
96
|
+
/** Optional criteria that must be completed before the agent finishes. */
|
|
97
|
+
completion_criteria?: string[];
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Configures the generative model parameters for the agent.
|
|
101
|
+
*/
|
|
102
|
+
export interface ModelConfig {
|
|
103
|
+
model: string;
|
|
104
|
+
temp: number;
|
|
105
|
+
top_p: number;
|
|
106
|
+
thinkingBudget?: number;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Configures the execution environment and constraints for the agent.
|
|
110
|
+
*/
|
|
111
|
+
export interface RunConfig {
|
|
112
|
+
/** The maximum execution time for the agent in minutes. */
|
|
113
|
+
max_time_minutes: number;
|
|
114
|
+
/** The maximum number of conversational turns. */
|
|
115
|
+
max_turns?: number;
|
|
116
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Describes the possible termination modes for an agent.
|
|
8
|
+
*/
|
|
9
|
+
export var AgentTerminateMode;
|
|
10
|
+
(function (AgentTerminateMode) {
|
|
11
|
+
AgentTerminateMode["ERROR"] = "ERROR";
|
|
12
|
+
AgentTerminateMode["TIMEOUT"] = "TIMEOUT";
|
|
13
|
+
AgentTerminateMode["GOAL"] = "GOAL";
|
|
14
|
+
AgentTerminateMode["MAX_TURNS"] = "MAX_TURNS";
|
|
15
|
+
AgentTerminateMode["ABORTED"] = "ABORTED";
|
|
16
|
+
})(AgentTerminateMode || (AgentTerminateMode = {}));
|
|
17
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/agents/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AASH;;GAEG;AACH,MAAM,CAAN,IAAY,kBAMX;AAND,WAAY,kBAAkB;IAC5B,qCAAe,CAAA;IACf,yCAAmB,CAAA;IACnB,mCAAa,CAAA;IACb,6CAAuB,CAAA;IACvB,yCAAmB,CAAA;AACrB,CAAC,EANW,kBAAkB,KAAlB,kBAAkB,QAM7B"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import type { AgentInputs } from './types.js';
|
|
7
|
+
/**
|
|
8
|
+
* Replaces `${...}` placeholders in a template string with values from AgentInputs.
|
|
9
|
+
*
|
|
10
|
+
* @param template The template string containing placeholders.
|
|
11
|
+
* @param inputs The AgentInputs object providing placeholder values.
|
|
12
|
+
* @returns The populated string with all placeholders replaced.
|
|
13
|
+
* @throws {Error} if any placeholder key is not found in the inputs.
|
|
14
|
+
*/
|
|
15
|
+
export declare function templateString(template: string, inputs: AgentInputs): string;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Replaces `${...}` placeholders in a template string with values from AgentInputs.
|
|
8
|
+
*
|
|
9
|
+
* @param template The template string containing placeholders.
|
|
10
|
+
* @param inputs The AgentInputs object providing placeholder values.
|
|
11
|
+
* @returns The populated string with all placeholders replaced.
|
|
12
|
+
* @throws {Error} if any placeholder key is not found in the inputs.
|
|
13
|
+
*/
|
|
14
|
+
export function templateString(template, inputs) {
|
|
15
|
+
const placeholderRegex = /\$\{(\w+)\}/g;
|
|
16
|
+
// First, find all unique keys required by the template.
|
|
17
|
+
const requiredKeys = new Set(Array.from(template.matchAll(placeholderRegex), (match) => match[1]));
|
|
18
|
+
// Check if all required keys exist in the inputs.
|
|
19
|
+
const inputKeys = new Set(Object.keys(inputs));
|
|
20
|
+
const missingKeys = Array.from(requiredKeys).filter((key) => !inputKeys.has(key));
|
|
21
|
+
if (missingKeys.length > 0) {
|
|
22
|
+
// Enhanced error message showing both missing and available keys
|
|
23
|
+
throw new Error(`Template validation failed: Missing required input parameters: ${missingKeys.join(', ')}. ` +
|
|
24
|
+
`Available inputs: ${Object.keys(inputs).join(', ')}`);
|
|
25
|
+
}
|
|
26
|
+
// Perform the replacement using a replacer function.
|
|
27
|
+
return template.replace(placeholderRegex, (_match, key) => String(inputs[key]));
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/agents/utils.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH;;;;;;;GAOG;AACH,MAAM,UAAU,cAAc,CAAC,QAAgB,EAAE,MAAmB;IAClE,MAAM,gBAAgB,GAAG,cAAc,CAAC;IAExC,wDAAwD;IACxD,MAAM,YAAY,GAAG,IAAI,GAAG,CAC1B,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,gBAAgB,CAAC,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CACrE,CAAC;IAEF,kDAAkD;IAClD,MAAM,SAAS,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;IAC/C,MAAM,WAAW,GAAG,KAAK,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,MAAM,CACjD,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC,CAC7B,CAAC;IAEF,IAAI,WAAW,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC3B,iEAAiE;QACjE,MAAM,IAAI,KAAK,CACb,kEAAkE,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI;YAC1F,qBAAqB,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CACxD,CAAC;IACJ,CAAC;IAED,qDAAqD;IACrD,OAAO,QAAQ,CAAC,OAAO,CAAC,gBAAgB,EAAE,CAAC,MAAM,EAAE,GAAG,EAAE,EAAE,CACxD,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CACpB,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import { describe, it, expect } from 'vitest';
|
|
7
|
+
import { templateString } from './utils.js';
|
|
8
|
+
describe('templateString', () => {
|
|
9
|
+
it('should replace a single placeholder with a string value', () => {
|
|
10
|
+
const template = 'Hello, ${name}!';
|
|
11
|
+
const inputs = { name: 'World' };
|
|
12
|
+
const result = templateString(template, inputs);
|
|
13
|
+
expect(result).toBe('Hello, World!');
|
|
14
|
+
});
|
|
15
|
+
it('should replace multiple unique placeholders', () => {
|
|
16
|
+
const template = 'User: ${user}, Role: ${role}';
|
|
17
|
+
const inputs = { user: 'Alex', role: 'Admin' };
|
|
18
|
+
const result = templateString(template, inputs);
|
|
19
|
+
expect(result).toBe('User: Alex, Role: Admin');
|
|
20
|
+
});
|
|
21
|
+
it('should replace multiple instances of the same placeholder', () => {
|
|
22
|
+
const template = '${greeting}, ${user}. Welcome, ${user}!';
|
|
23
|
+
const inputs = { greeting: 'Hi', user: 'Sam' };
|
|
24
|
+
const result = templateString(template, inputs);
|
|
25
|
+
expect(result).toBe('Hi, Sam. Welcome, Sam!');
|
|
26
|
+
});
|
|
27
|
+
it('should handle various data types for input values', () => {
|
|
28
|
+
const template = 'Name: ${name}, Age: ${age}, Active: ${isActive}, Plan: ${plan}, Score: ${score}';
|
|
29
|
+
const inputs = {
|
|
30
|
+
name: 'Jo',
|
|
31
|
+
age: 30,
|
|
32
|
+
isActive: true,
|
|
33
|
+
plan: null,
|
|
34
|
+
score: undefined,
|
|
35
|
+
};
|
|
36
|
+
const result = templateString(template, inputs);
|
|
37
|
+
// All values are converted to their string representations
|
|
38
|
+
expect(result).toBe('Name: Jo, Age: 30, Active: true, Plan: null, Score: undefined');
|
|
39
|
+
});
|
|
40
|
+
it('should return the original string if no placeholders are present', () => {
|
|
41
|
+
const template = 'This is a plain string with no placeholders.';
|
|
42
|
+
const inputs = { key: 'value' };
|
|
43
|
+
const result = templateString(template, inputs);
|
|
44
|
+
expect(result).toBe('This is a plain string with no placeholders.');
|
|
45
|
+
});
|
|
46
|
+
it('should correctly handle an empty template string', () => {
|
|
47
|
+
const template = '';
|
|
48
|
+
const inputs = { key: 'value' };
|
|
49
|
+
const result = templateString(template, inputs);
|
|
50
|
+
expect(result).toBe('');
|
|
51
|
+
});
|
|
52
|
+
it('should ignore extra keys in the inputs object that are not in the template', () => {
|
|
53
|
+
const template = 'Hello, ${name}.';
|
|
54
|
+
const inputs = { name: 'Alice', extra: 'ignored' };
|
|
55
|
+
const result = templateString(template, inputs);
|
|
56
|
+
expect(result).toBe('Hello, Alice.');
|
|
57
|
+
});
|
|
58
|
+
it('should throw an error if a required key is missing from the inputs', () => {
|
|
59
|
+
const template = 'The goal is ${goal}.';
|
|
60
|
+
const inputs = { other_input: 'some value' };
|
|
61
|
+
expect(() => templateString(template, inputs)).toThrow('Template validation failed: Missing required input parameters: goal. Available inputs: other_input');
|
|
62
|
+
});
|
|
63
|
+
it('should throw an error listing all missing keys if multiple are missing', () => {
|
|
64
|
+
const template = 'Analyze ${file} with ${tool}.';
|
|
65
|
+
const inputs = { an_available_key: 'foo' };
|
|
66
|
+
// Using a regex to allow for any order of missing keys in the error message
|
|
67
|
+
expect(() => templateString(template, inputs)).toThrow(/Missing required input parameters: (file, tool|tool, file)/);
|
|
68
|
+
});
|
|
69
|
+
it('should be case-sensitive with placeholder keys', () => {
|
|
70
|
+
const template = 'Value: ${Key}';
|
|
71
|
+
const inputs = { key: 'some value' }; // 'key' is lowercase
|
|
72
|
+
expect(() => templateString(template, inputs)).toThrow('Template validation failed: Missing required input parameters: Key. Available inputs: key');
|
|
73
|
+
});
|
|
74
|
+
it('should not replace malformed or incomplete placeholders', () => {
|
|
75
|
+
const template = 'This is {not_a_placeholder} and this is $$escaped. Test: ${valid}';
|
|
76
|
+
const inputs = { valid: 'works' };
|
|
77
|
+
const result = templateString(template, inputs);
|
|
78
|
+
expect(result).toBe('This is {not_a_placeholder} and this is $$escaped. Test: works');
|
|
79
|
+
});
|
|
80
|
+
it('should work correctly with an empty inputs object if the template has no placeholders', () => {
|
|
81
|
+
const template = 'Static text.';
|
|
82
|
+
const inputs = {};
|
|
83
|
+
const result = templateString(template, inputs);
|
|
84
|
+
expect(result).toBe('Static text.');
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
//# sourceMappingURL=utils.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.test.js","sourceRoot":"","sources":["../../../src/agents/utils.test.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAG5C,QAAQ,CAAC,gBAAgB,EAAE,GAAG,EAAE;IAC9B,EAAE,CAAC,yDA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