@google/gemini-cli-core 0.9.0-nightly.20250926.1487841d → 0.9.0-nightly.20251001.14dbda91
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/README.md +43 -54
- package/dist/src/agents/codebase-investigator.d.ts +11 -0
- package/dist/src/agents/codebase-investigator.js +164 -0
- package/dist/src/agents/codebase-investigator.js.map +1 -0
- package/dist/src/agents/executor.d.ts +96 -0
- package/dist/src/agents/executor.js +438 -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 +492 -0
- package/dist/src/agents/executor.test.js.map +1 -0
- package/dist/src/agents/invocation.d.ts +45 -0
- package/dist/src/agents/invocation.js +101 -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 +214 -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 +38 -0
- package/dist/src/agents/subagent-tool-wrapper.js +48 -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 +112 -0
- package/dist/src/agents/subagent-tool-wrapper.test.js.map +1 -0
- package/dist/src/agents/types.d.ts +123 -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/config/config.d.ts +11 -2
- package/dist/src/config/config.js +49 -3
- package/dist/src/config/config.js.map +1 -1
- package/dist/src/config/config.test.js +63 -0
- package/dist/src/config/config.test.js.map +1 -1
- package/dist/src/core/baseLlmClient.js +19 -21
- package/dist/src/core/baseLlmClient.js.map +1 -1
- package/dist/src/core/baseLlmClient.test.js +57 -17
- package/dist/src/core/baseLlmClient.test.js.map +1 -1
- package/dist/src/core/client.js +8 -29
- package/dist/src/core/client.js.map +1 -1
- package/dist/src/core/client.test.js +223 -94
- package/dist/src/core/client.test.js.map +1 -1
- package/dist/src/core/coreToolScheduler.test.js +33 -23
- package/dist/src/core/coreToolScheduler.test.js.map +1 -1
- package/dist/src/core/geminiChat.js +1 -1
- package/dist/src/core/geminiChat.js.map +1 -1
- package/dist/src/core/geminiChat.test.js +2 -1
- package/dist/src/core/geminiChat.test.js.map +1 -1
- package/dist/src/core/nonInteractiveToolExecutor.test.js +11 -11
- package/dist/src/core/nonInteractiveToolExecutor.test.js.map +1 -1
- package/dist/src/generated/git-commit.d.ts +2 -2
- package/dist/src/generated/git-commit.js +2 -2
- 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/mcp/sa-impersonation-provider.d.ts +33 -0
- package/dist/src/mcp/sa-impersonation-provider.js +130 -0
- package/dist/src/mcp/sa-impersonation-provider.js.map +1 -0
- package/dist/src/mcp/sa-impersonation-provider.test.d.ts +6 -0
- package/dist/src/mcp/sa-impersonation-provider.test.js +117 -0
- package/dist/src/mcp/sa-impersonation-provider.test.js.map +1 -0
- package/dist/src/services/fileSystemService.d.ts +9 -0
- package/dist/src/services/fileSystemService.js +11 -0
- package/dist/src/services/fileSystemService.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.d.ts +4 -2
- package/dist/src/telemetry/clearcut-logger/clearcut-logger.js +15 -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/clearcut-logger/event-metadata-key.d.ts +2 -1
- package/dist/src/telemetry/clearcut-logger/event-metadata-key.js +2 -0
- package/dist/src/telemetry/clearcut-logger/event-metadata-key.js.map +1 -1
- package/dist/src/telemetry/constants.d.ts +1 -24
- package/dist/src/telemetry/constants.js +1 -25
- package/dist/src/telemetry/constants.js.map +1 -1
- package/dist/src/telemetry/index.d.ts +1 -1
- package/dist/src/telemetry/index.js +7 -1
- package/dist/src/telemetry/index.js.map +1 -1
- package/dist/src/telemetry/loggers.d.ts +2 -1
- package/dist/src/telemetry/loggers.js +66 -11
- package/dist/src/telemetry/loggers.js.map +1 -1
- package/dist/src/telemetry/loggers.test.circular.js +3 -3
- package/dist/src/telemetry/loggers.test.circular.js.map +1 -1
- package/dist/src/telemetry/loggers.test.js +76 -9
- package/dist/src/telemetry/loggers.test.js.map +1 -1
- package/dist/src/telemetry/metrics.d.ts +363 -19
- package/dist/src/telemetry/metrics.js +415 -235
- package/dist/src/telemetry/metrics.js.map +1 -1
- package/dist/src/telemetry/metrics.test.js +352 -54
- package/dist/src/telemetry/metrics.test.js.map +1 -1
- package/dist/src/telemetry/types.d.ts +6 -0
- package/dist/src/telemetry/types.js +10 -0
- package/dist/src/telemetry/types.js.map +1 -1
- package/dist/src/telemetry/uiTelemetry.test.js +2 -2
- package/dist/src/telemetry/uiTelemetry.test.js.map +1 -1
- package/dist/src/test-utils/mock-tool.d.ts +28 -3
- package/dist/src/test-utils/mock-tool.js +71 -1
- package/dist/src/test-utils/mock-tool.js.map +1 -1
- package/dist/src/tools/glob.js +2 -1
- package/dist/src/tools/glob.js.map +1 -1
- package/dist/src/tools/mcp-client.js +16 -0
- package/dist/src/tools/mcp-client.js.map +1 -1
- package/dist/src/tools/shell.js +1 -54
- package/dist/src/tools/shell.js.map +1 -1
- package/dist/src/tools/shell.test.js +0 -1
- package/dist/src/tools/shell.test.js.map +1 -1
- package/dist/src/tools/smart-edit.d.ts +20 -1
- package/dist/src/tools/smart-edit.js +114 -4
- package/dist/src/tools/smart-edit.js.map +1 -1
- package/dist/src/tools/smart-edit.test.js +90 -6
- package/dist/src/tools/smart-edit.test.js.map +1 -1
- package/dist/src/tools/tool-names.d.ts +6 -0
- package/dist/src/tools/tool-names.js +15 -0
- package/dist/src/tools/tool-names.js.map +1 -0
- package/dist/src/tools/tool-registry.test.js +10 -10
- package/dist/src/tools/tool-registry.test.js.map +1 -1
- package/dist/src/utils/flashFallback.test.js +2 -2
- package/dist/src/utils/flashFallback.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/retry.d.ts +3 -1
- package/dist/src/utils/retry.js +13 -4
- package/dist/src/utils/retry.js.map +1 -1
- package/dist/src/utils/retry.test.js +2 -2
- package/dist/src/utils/retry.test.js.map +1 -1
- package/dist/src/utils/shell-utils.d.ts +0 -1
- package/dist/src/utils/shell-utils.js +1 -1
- package/dist/src/utils/shell-utils.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/src/utils/tool-utils.js +2 -2
- package/dist/src/utils/tool-utils.js.map +1 -1
- package/dist/src/utils/tool-utils.test.js +0 -8
- package/dist/src/utils/tool-utils.test.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/dist/src/test-utils/tools.d.ts +0 -45
- package/dist/src/test-utils/tools.js +0 -105
- package/dist/src/test-utils/tools.js.map +0 -1
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Converts an internal `InputConfig` definition into a standard JSON Schema
|
|
8
|
+
* object suitable for a tool's `FunctionDeclaration`.
|
|
9
|
+
*
|
|
10
|
+
* This utility ensures that the configuration for a subagent's inputs is
|
|
11
|
+
* correctly translated into the format expected by the generative model.
|
|
12
|
+
*
|
|
13
|
+
* @param inputConfig The internal `InputConfig` to convert.
|
|
14
|
+
* @returns A JSON Schema object representing the inputs.
|
|
15
|
+
* @throws An `Error` if an unsupported input type is encountered, ensuring
|
|
16
|
+
* configuration errors are caught early.
|
|
17
|
+
*/
|
|
18
|
+
export function convertInputConfigToJsonSchema(inputConfig) {
|
|
19
|
+
const properties = {};
|
|
20
|
+
const required = [];
|
|
21
|
+
for (const [name, definition] of Object.entries(inputConfig.inputs)) {
|
|
22
|
+
const schemaProperty = {
|
|
23
|
+
description: definition.description,
|
|
24
|
+
};
|
|
25
|
+
switch (definition.type) {
|
|
26
|
+
case 'string':
|
|
27
|
+
case 'number':
|
|
28
|
+
case 'integer':
|
|
29
|
+
case 'boolean':
|
|
30
|
+
schemaProperty.type = definition.type;
|
|
31
|
+
break;
|
|
32
|
+
case 'string[]':
|
|
33
|
+
schemaProperty.type = 'array';
|
|
34
|
+
schemaProperty.items = { type: 'string' };
|
|
35
|
+
break;
|
|
36
|
+
case 'number[]':
|
|
37
|
+
schemaProperty.type = 'array';
|
|
38
|
+
schemaProperty.items = { type: 'number' };
|
|
39
|
+
break;
|
|
40
|
+
default: {
|
|
41
|
+
const exhaustiveCheck = definition.type;
|
|
42
|
+
throw new Error(`Unsupported input type '${exhaustiveCheck}' for parameter '${name}'. ` +
|
|
43
|
+
'Supported types: string, number, integer, boolean, string[], number[]');
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
properties[name] = schemaProperty;
|
|
47
|
+
if (definition.required) {
|
|
48
|
+
required.push(name);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return {
|
|
52
|
+
type: 'object',
|
|
53
|
+
properties,
|
|
54
|
+
required: required.length > 0 ? required : undefined,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=schema-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema-utils.js","sourceRoot":"","sources":["../../../src/agents/schema-utils.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAuBH;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,8BAA8B,CAC5C,WAAwB;IAExB,MAAM,UAAU,GAAuC,EAAE,CAAC;IAC1D,MAAM,QAAQ,GAAa,EAAE,CAAC;IAE9B,KAAK,MAAM,CAAC,IAAI,EAAE,UAAU,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC,MAAM,CAAC,EAAE,CAAC;QACpE,MAAM,cAAc,GAAgC;YAClD,WAAW,EAAE,UAAU,CAAC,WAAW;SACpC,CAAC;QAEF,QAAQ,UAAU,CAAC,IAAI,EAAE,CAAC;YACxB,KAAK,QAAQ,CAAC;YACd,KAAK,QAAQ,CAAC;YACd,KAAK,SAAS,CAAC;YACf,KAAK,SAAS;gBACZ,cAAc,CAAC,IAAI,GAAG,UAAU,CAAC,IAAI,CAAC;gBACtC,MAAM;YAER,KAAK,UAAU;gBACb,cAAc,CAAC,IAAI,GAAG,OAAO,CAAC;gBAC9B,cAAc,CAAC,KAAK,GAAG,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;gBAC1C,MAAM;YAER,KAAK,UAAU;gBACb,cAAc,CAAC,IAAI,GAAG,OAAO,CAAC;gBAC9B,cAAc,CAAC,KAAK,GAAG,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;gBAC1C,MAAM;YAER,OAAO,CAAC,CAAC,CAAC;gBACR,MAAM,eAAe,GAAU,UAAU,CAAC,IAAI,CAAC;gBAC/C,MAAM,IAAI,KAAK,CACb,2BAA2B,eAAe,oBAAoB,IAAI,KAAK;oBACrE,uEAAuE,CAC1E,CAAC;YACJ,CAAC;QACH,CAAC;QAED,UAAU,CAAC,IAAI,CAAC,GAAG,cAAoC,CAAC;QAExD,IAAI,UAAU,CAAC,QAAQ,EAAE,CAAC;YACxB,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACtB,CAAC;IACH,CAAC;IAED,OAAO;QACL,IAAI,EAAE,QAAQ;QACd,UAAU;QACV,QAAQ,EAAE,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS;KACrD,CAAC;AACJ,CAAC"}
|
|
@@ -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,IA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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,38 @@
|
|
|
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
|
+
import type { MessageBus } from '../confirmation-bus/message-bus.js';
|
|
10
|
+
/**
|
|
11
|
+
* A tool wrapper that dynamically exposes a subagent as a standard,
|
|
12
|
+
* strongly-typed `DeclarativeTool`.
|
|
13
|
+
*/
|
|
14
|
+
export declare class SubagentToolWrapper extends BaseDeclarativeTool<AgentInputs, ToolResult> {
|
|
15
|
+
private readonly definition;
|
|
16
|
+
private readonly config;
|
|
17
|
+
/**
|
|
18
|
+
* Constructs the tool wrapper.
|
|
19
|
+
*
|
|
20
|
+
* The constructor dynamically generates the JSON schema for the tool's
|
|
21
|
+
* parameters based on the subagent's input configuration.
|
|
22
|
+
*
|
|
23
|
+
* @param definition The `AgentDefinition` of the subagent to wrap.
|
|
24
|
+
* @param config The runtime configuration, passed down to the subagent.
|
|
25
|
+
* @param messageBus Optional message bus for policy enforcement.
|
|
26
|
+
*/
|
|
27
|
+
constructor(definition: AgentDefinition, config: Config, messageBus?: MessageBus);
|
|
28
|
+
/**
|
|
29
|
+
* Creates an invocation instance for executing the subagent.
|
|
30
|
+
*
|
|
31
|
+
* This method is called by the tool framework when the parent agent decides
|
|
32
|
+
* to use this tool.
|
|
33
|
+
*
|
|
34
|
+
* @param params The validated input parameters from the parent agent's call.
|
|
35
|
+
* @returns A `ToolInvocation` instance ready for execution.
|
|
36
|
+
*/
|
|
37
|
+
protected createInvocation(params: AgentInputs): ToolInvocation<AgentInputs, ToolResult>;
|
|
38
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
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
|
+
* @param messageBus Optional message bus for policy enforcement.
|
|
25
|
+
*/
|
|
26
|
+
constructor(definition, config, messageBus) {
|
|
27
|
+
// Dynamically generate the JSON schema required for the tool definition.
|
|
28
|
+
const parameterSchema = convertInputConfigToJsonSchema(definition.inputConfig);
|
|
29
|
+
super(definition.name, definition.displayName ?? definition.name, definition.description, Kind.Think, parameterSchema,
|
|
30
|
+
/* isOutputMarkdown */ true,
|
|
31
|
+
/* canUpdateOutput */ true, messageBus);
|
|
32
|
+
this.definition = definition;
|
|
33
|
+
this.config = config;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Creates an invocation instance for executing the subagent.
|
|
37
|
+
*
|
|
38
|
+
* This method is called by the tool framework when the parent agent decides
|
|
39
|
+
* to use this tool.
|
|
40
|
+
*
|
|
41
|
+
* @param params The validated input parameters from the parent agent's call.
|
|
42
|
+
* @returns A `ToolInvocation` instance ready for execution.
|
|
43
|
+
*/
|
|
44
|
+
createInvocation(params) {
|
|
45
|
+
return new SubagentInvocation(params, this.definition, this.config, this.messageBus);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
//# 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;AAGrD;;;GAGG;AACH,MAAM,OAAO,mBAAoB,SAAQ,mBAGxC;IAYoB;IACA;IAZnB;;;;;;;;;OASG;IACH,YACmB,UAA2B,EAC3B,MAAc,EAC/B,UAAuB;QAEvB,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,EAC1B,UAAU,CACX,CAAC;QAlBe,eAAU,GAAV,UAAU,CAAiB;QAC3B,WAAM,GAAN,MAAM,CAAQ;IAkBjC,CAAC;IAED;;;;;;;;OAQG;IACO,gBAAgB,CACxB,MAAmB;QAEnB,OAAO,IAAI,kBAAkB,CAC3B,MAAM,EACN,IAAI,CAAC,UAAU,EACf,IAAI,CAAC,MAAM,EACX,IAAI,CAAC,UAAU,CAChB,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -0,0 +1,112 @@
|
|
|
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, undefined);
|
|
93
|
+
});
|
|
94
|
+
it('should pass the messageBus to the SubagentInvocation constructor', () => {
|
|
95
|
+
const mockMessageBus = {};
|
|
96
|
+
const wrapper = new SubagentToolWrapper(mockDefinition, mockConfig, mockMessageBus);
|
|
97
|
+
const params = { goal: 'Test the invocation', priority: 1 };
|
|
98
|
+
wrapper.build(params);
|
|
99
|
+
expect(MockedSubagentInvocation).toHaveBeenCalledWith(params, mockDefinition, mockConfig, mockMessageBus);
|
|
100
|
+
});
|
|
101
|
+
it('should throw a validation error for invalid parameters before creating an invocation', () => {
|
|
102
|
+
const wrapper = new SubagentToolWrapper(mockDefinition, mockConfig);
|
|
103
|
+
// Missing the required 'goal' parameter
|
|
104
|
+
const invalidParams = { priority: 1 };
|
|
105
|
+
// The `build` method in the base class performs JSON schema validation
|
|
106
|
+
// before calling the protected `createInvocation` method.
|
|
107
|
+
expect(() => wrapper.build(invalidParams)).toThrow("params must have required property 'goal'");
|
|
108
|
+
expect(MockedSubagentInvocation).not.toHaveBeenCalled();
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
//# 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;AAGzC,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,kBAAkB,CAAC,CAAC;AAC/D,MAAM,kCAAkC,GAAG,EAAE,CAAC,MAAM,CAClD,8BAA8B,CAC/B,CAAC;AAEF,4BAA4B;AAC5B,IAAI,UAAkB,CAAC;AAEvB,MAAM,cAAc,GAAoB;IACtC,IAAI,EAAE,WAAW;IACjB,WAAW,EAAE,yBAAyB;I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AC,wBAAwB,CAAC,CAAC,oBAAoB,CACnD,MAAM,EACN,cAAc,EACd,UAAU,EACV,cAAc,CACf,CAAC;QACJ,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,sFAAsF,EAAE,GAAG,EAAE;YAC9F,MAAM,OAAO,GAAG,IAAI,mBAAmB,CAAC,cAAc,EAAE,UAAU,CAAC,CAAC;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,123 @@
|
|
|
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
|
+
* The specific task or question to trigger the agent's execution loop.
|
|
71
|
+
* This is sent as the first user message, distinct from the systemPrompt (identity/rules)
|
|
72
|
+
* and initialMessages (history/few-shots). Supports templating.
|
|
73
|
+
* If not provided, a generic "Get Started!" message is used.
|
|
74
|
+
*/
|
|
75
|
+
query?: string;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Configures the tools available to the agent during its execution.
|
|
79
|
+
*/
|
|
80
|
+
export interface ToolConfig {
|
|
81
|
+
tools: Array<string | FunctionDeclaration | AnyDeclarativeTool>;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Configures the expected inputs (parameters) for the agent.
|
|
85
|
+
*/
|
|
86
|
+
export interface InputConfig {
|
|
87
|
+
/**
|
|
88
|
+
* Defines the parameters the agent accepts.
|
|
89
|
+
* This is vital for generating the tool wrapper schema.
|
|
90
|
+
*/
|
|
91
|
+
inputs: Record<string, {
|
|
92
|
+
description: string;
|
|
93
|
+
type: 'string' | 'number' | 'boolean' | 'integer' | 'string[]' | 'number[]';
|
|
94
|
+
required: boolean;
|
|
95
|
+
}>;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Configures the expected outputs for the agent.
|
|
99
|
+
*/
|
|
100
|
+
export interface OutputConfig {
|
|
101
|
+
/** Description of what the agent should return when finished. */
|
|
102
|
+
description: string;
|
|
103
|
+
/** Optional criteria that must be completed before the agent finishes. */
|
|
104
|
+
completion_criteria?: string[];
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Configures the generative model parameters for the agent.
|
|
108
|
+
*/
|
|
109
|
+
export interface ModelConfig {
|
|
110
|
+
model: string;
|
|
111
|
+
temp: number;
|
|
112
|
+
top_p: number;
|
|
113
|
+
thinkingBudget?: number;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Configures the execution environment and constraints for the agent.
|
|
117
|
+
*/
|
|
118
|
+
export interface RunConfig {
|
|
119
|
+
/** The maximum execution time for the agent in minutes. */
|
|
120
|
+
max_time_minutes: number;
|
|
121
|
+
/** The maximum number of conversational turns. */
|
|
122
|
+
max_turns?: number;
|
|
123
|
+
}
|
|
@@ -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"}
|