@google/gemini-cli-core 0.12.0-nightly.20251023.c4c0c0d1 → 0.12.0-preview.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -5
- package/dist/index.d.ts +3 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/src/agents/subagent-tool-wrapper.test.js +2 -4
- package/dist/src/agents/subagent-tool-wrapper.test.js.map +1 -1
- package/dist/src/code_assist/oauth2.d.ts +2 -2
- package/dist/src/code_assist/oauth2.js +53 -41
- package/dist/src/code_assist/oauth2.js.map +1 -1
- package/dist/src/code_assist/oauth2.test.js +65 -33
- package/dist/src/code_assist/oauth2.test.js.map +1 -1
- package/dist/src/code_assist/server.d.ts +3 -3
- package/dist/src/code_assist/server.js.map +1 -1
- package/dist/src/code_assist/setup.d.ts +2 -2
- package/dist/src/code_assist/setup.js.map +1 -1
- package/dist/src/config/config.d.ts +12 -3
- package/dist/src/config/config.js +35 -9
- package/dist/src/config/config.js.map +1 -1
- package/dist/src/config/config.test.js +58 -21
- package/dist/src/config/config.test.js.map +1 -1
- package/dist/src/config/storage.d.ts +1 -0
- package/dist/src/config/storage.js +3 -0
- package/dist/src/config/storage.js.map +1 -1
- package/dist/src/core/client.d.ts +1 -11
- package/dist/src/core/client.js +17 -165
- package/dist/src/core/client.js.map +1 -1
- package/dist/src/core/client.test.js +70 -405
- package/dist/src/core/client.test.js.map +1 -1
- package/dist/src/core/contentGenerator.js +39 -28
- package/dist/src/core/contentGenerator.js.map +1 -1
- package/dist/src/core/contentGenerator.test.js +28 -0
- package/dist/src/core/contentGenerator.test.js.map +1 -1
- package/dist/src/core/coreToolScheduler.d.ts +7 -7
- package/dist/src/core/coreToolScheduler.js +312 -183
- package/dist/src/core/coreToolScheduler.js.map +1 -1
- package/dist/src/core/coreToolScheduler.test.js +239 -9
- package/dist/src/core/coreToolScheduler.test.js.map +1 -1
- package/dist/src/core/fakeContentGenerator.d.ts +33 -0
- package/dist/src/core/fakeContentGenerator.js +58 -0
- package/dist/src/core/fakeContentGenerator.js.map +1 -0
- package/dist/src/core/fakeContentGenerator.test.d.ts +6 -0
- package/dist/src/core/fakeContentGenerator.test.js +127 -0
- package/dist/src/core/fakeContentGenerator.test.js.map +1 -0
- package/dist/src/core/loggingContentGenerator.d.ts +1 -0
- package/dist/src/core/loggingContentGenerator.js +113 -33
- package/dist/src/core/loggingContentGenerator.js.map +1 -1
- package/dist/src/core/nonInteractiveToolExecutor.js +5 -4
- package/dist/src/core/nonInteractiveToolExecutor.js.map +1 -1
- package/dist/src/core/prompts.test.js +30 -108
- package/dist/src/core/prompts.test.js.map +1 -1
- package/dist/src/core/recordingContentGenerator.d.ts +18 -0
- package/dist/src/core/recordingContentGenerator.js +77 -0
- package/dist/src/core/recordingContentGenerator.js.map +1 -0
- package/dist/src/core/recordingContentGenerator.test.d.ts +6 -0
- package/dist/src/core/recordingContentGenerator.test.js +101 -0
- package/dist/src/core/recordingContentGenerator.test.js.map +1 -0
- package/dist/src/fallback/handler.js +2 -0
- package/dist/src/fallback/handler.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/generated/git-commit.js.map +1 -1
- package/dist/src/index.d.ts +3 -0
- package/dist/src/index.js +3 -0
- package/dist/src/index.js.map +1 -1
- package/dist/src/mcp/google-auth-provider.d.ts +2 -0
- package/dist/src/mcp/google-auth-provider.js +19 -2
- package/dist/src/mcp/google-auth-provider.js.map +1 -1
- package/dist/src/mcp/google-auth-provider.test.js +42 -9
- package/dist/src/mcp/google-auth-provider.test.js.map +1 -1
- package/dist/src/mcp/oauth-provider.js +2 -2
- package/dist/src/mcp/oauth-provider.js.map +1 -1
- package/dist/src/mcp/oauth-provider.test.js +130 -0
- package/dist/src/mcp/oauth-provider.test.js.map +1 -1
- package/dist/src/mcp/oauth-token-storage.js +5 -4
- package/dist/src/mcp/oauth-token-storage.js.map +1 -1
- package/dist/src/mcp/oauth-token-storage.test.js +17 -11
- package/dist/src/mcp/oauth-token-storage.test.js.map +1 -1
- package/dist/src/mcp/oauth-utils.d.ts +7 -0
- package/dist/src/mcp/oauth-utils.js +19 -0
- package/dist/src/mcp/oauth-utils.js.map +1 -1
- package/dist/src/mcp/oauth-utils.test.js +32 -0
- package/dist/src/mcp/oauth-utils.test.js.map +1 -1
- package/dist/src/mcp/sa-impersonation-provider.d.ts +0 -6
- package/dist/src/mcp/sa-impersonation-provider.js +6 -23
- package/dist/src/mcp/sa-impersonation-provider.js.map +1 -1
- package/dist/src/mcp/token-storage/base-token-storage.test.js +75 -84
- package/dist/src/mcp/token-storage/base-token-storage.test.js.map +1 -1
- package/dist/src/mcp/token-storage/keychain-token-storage.d.ts +6 -2
- package/dist/src/mcp/token-storage/keychain-token-storage.js +62 -6
- package/dist/src/mcp/token-storage/keychain-token-storage.js.map +1 -1
- package/dist/src/mcp/token-storage/keychain-token-storage.test.js +54 -3
- package/dist/src/mcp/token-storage/keychain-token-storage.test.js.map +1 -1
- package/dist/src/mcp/token-storage/types.d.ts +6 -0
- package/dist/src/mcp/token-storage/types.js.map +1 -1
- package/dist/src/policy/policy-engine.js +4 -0
- package/dist/src/policy/policy-engine.js.map +1 -1
- package/dist/src/services/chatCompressionService.d.ts +32 -0
- package/dist/src/services/chatCompressionService.js +164 -0
- package/dist/src/services/chatCompressionService.js.map +1 -0
- package/dist/src/services/chatCompressionService.test.d.ts +6 -0
- package/dist/src/services/chatCompressionService.test.js +211 -0
- package/dist/src/services/chatCompressionService.test.js.map +1 -0
- package/dist/src/services/fileDiscoveryService.d.ts +0 -8
- package/dist/src/services/fileDiscoveryService.js +5 -33
- package/dist/src/services/fileDiscoveryService.js.map +1 -1
- package/dist/src/services/fileDiscoveryService.test.js +11 -11
- package/dist/src/services/fileDiscoveryService.test.js.map +1 -1
- package/dist/src/services/loopDetectionService.js +19 -9
- package/dist/src/services/loopDetectionService.js.map +1 -1
- package/dist/src/services/loopDetectionService.test.js +40 -11
- package/dist/src/services/loopDetectionService.test.js.map +1 -1
- package/dist/src/telemetry/clearcut-logger/clearcut-logger.d.ts +1 -0
- package/dist/src/telemetry/clearcut-logger/clearcut-logger.js +40 -33
- package/dist/src/telemetry/clearcut-logger/clearcut-logger.js.map +1 -1
- package/dist/src/telemetry/clearcut-logger/clearcut-logger.test.js +1 -1
- package/dist/src/telemetry/clearcut-logger/clearcut-logger.test.js.map +1 -1
- package/dist/src/telemetry/index.d.ts +1 -0
- package/dist/src/telemetry/index.js +1 -0
- package/dist/src/telemetry/index.js.map +1 -1
- package/dist/src/telemetry/loggers.js +10 -17
- package/dist/src/telemetry/loggers.js.map +1 -1
- package/dist/src/telemetry/loggers.test.js +173 -30
- package/dist/src/telemetry/loggers.test.js.map +1 -1
- package/dist/src/telemetry/metrics.d.ts +1 -1
- package/dist/src/telemetry/metrics.js +1 -1
- package/dist/src/telemetry/metrics.js.map +1 -1
- package/dist/src/telemetry/metrics.test.js +2 -2
- package/dist/src/telemetry/metrics.test.js.map +1 -1
- package/dist/src/telemetry/semantic.d.ts +82 -0
- package/dist/src/telemetry/semantic.js +269 -0
- package/dist/src/telemetry/semantic.js.map +1 -0
- package/dist/src/telemetry/semantic.test.d.ts +6 -0
- package/dist/src/telemetry/semantic.test.js +387 -0
- package/dist/src/telemetry/semantic.test.js.map +1 -0
- package/dist/src/telemetry/trace.d.ts +46 -0
- package/dist/src/telemetry/trace.js +121 -0
- package/dist/src/telemetry/trace.js.map +1 -0
- package/dist/src/telemetry/types.d.ts +37 -18
- package/dist/src/telemetry/types.js +107 -36
- package/dist/src/telemetry/types.js.map +1 -1
- package/dist/src/telemetry/uiTelemetry.js +6 -6
- package/dist/src/telemetry/uiTelemetry.js.map +1 -1
- package/dist/src/telemetry/uiTelemetry.test.js +88 -66
- package/dist/src/telemetry/uiTelemetry.test.js.map +1 -1
- package/dist/src/tools/edit.d.ts +3 -2
- package/dist/src/tools/edit.js +15 -11
- package/dist/src/tools/edit.js.map +1 -1
- package/dist/src/tools/edit.test.js +19 -0
- package/dist/src/tools/edit.test.js.map +1 -1
- package/dist/src/tools/glob.js +4 -2
- package/dist/src/tools/glob.js.map +1 -1
- package/dist/src/tools/glob.test.js +203 -199
- package/dist/src/tools/glob.test.js.map +1 -1
- package/dist/src/tools/grep.js +2 -2
- package/dist/src/tools/grep.js.map +1 -1
- package/dist/src/tools/ls.js +2 -1
- package/dist/src/tools/ls.js.map +1 -1
- package/dist/src/tools/ls.test.js +0 -7
- package/dist/src/tools/ls.test.js.map +1 -1
- package/dist/src/tools/mcp-client-manager.js +2 -1
- package/dist/src/tools/mcp-client-manager.js.map +1 -1
- package/dist/src/tools/mcp-client.d.ts +4 -1
- package/dist/src/tools/mcp-client.js +71 -92
- package/dist/src/tools/mcp-client.js.map +1 -1
- package/dist/src/tools/mcp-client.test.js +16 -6
- package/dist/src/tools/mcp-client.test.js.map +1 -1
- package/dist/src/tools/mcp-tool.d.ts +3 -2
- package/dist/src/tools/mcp-tool.js +12 -10
- package/dist/src/tools/mcp-tool.js.map +1 -1
- package/dist/src/tools/memoryTool.d.ts +5 -3
- package/dist/src/tools/memoryTool.js +9 -7
- package/dist/src/tools/memoryTool.js.map +1 -1
- package/dist/src/tools/read-file.js +7 -3
- package/dist/src/tools/read-file.js.map +1 -1
- package/dist/src/tools/read-file.test.js +25 -2
- package/dist/src/tools/read-file.test.js.map +1 -1
- package/dist/src/tools/shell.d.ts +6 -4
- package/dist/src/tools/shell.js +18 -12
- package/dist/src/tools/shell.js.map +1 -1
- package/dist/src/tools/shell.test.js +7 -0
- package/dist/src/tools/shell.test.js.map +1 -1
- package/dist/src/tools/smart-edit.d.ts +2 -1
- package/dist/src/tools/smart-edit.js +10 -9
- package/dist/src/tools/smart-edit.js.map +1 -1
- package/dist/src/tools/tool-registry.d.ts +5 -1
- package/dist/src/tools/tool-registry.js +10 -3
- package/dist/src/tools/tool-registry.js.map +1 -1
- package/dist/src/tools/tools.d.ts +6 -0
- package/dist/src/tools/tools.js +29 -17
- package/dist/src/tools/tools.js.map +1 -1
- package/dist/src/tools/web-fetch.js +1 -12
- package/dist/src/tools/web-fetch.js.map +1 -1
- package/dist/src/tools/web-fetch.test.js +2 -2
- package/dist/src/tools/web-fetch.test.js.map +1 -1
- package/dist/src/tools/write-file.d.ts +2 -1
- package/dist/src/tools/write-file.js +6 -6
- package/dist/src/tools/write-file.js.map +1 -1
- package/dist/src/tools/write-todos.d.ts +2 -1
- package/dist/src/tools/write-todos.js +5 -2
- package/dist/src/tools/write-todos.js.map +1 -1
- package/dist/src/utils/environmentContext.d.ts +2 -1
- package/dist/src/utils/environmentContext.js +18 -0
- package/dist/src/utils/environmentContext.js.map +1 -1
- package/dist/src/utils/errorParsing.d.ts +1 -1
- package/dist/src/utils/errorParsing.js +5 -33
- package/dist/src/utils/errorParsing.js.map +1 -1
- package/dist/src/utils/errorParsing.test.js +0 -88
- package/dist/src/utils/errorParsing.test.js.map +1 -1
- package/dist/src/utils/errors.d.ts +3 -0
- package/dist/src/utils/errors.js +6 -0
- package/dist/src/utils/errors.js.map +1 -1
- package/dist/src/utils/events.d.ts +19 -1
- package/dist/src/utils/events.js +9 -0
- package/dist/src/utils/events.js.map +1 -1
- package/dist/src/utils/extensionLoader.d.ts +38 -0
- package/dist/src/utils/extensionLoader.js +20 -0
- package/dist/src/utils/extensionLoader.js.map +1 -0
- package/dist/src/utils/flashFallback.test.js +26 -45
- package/dist/src/utils/flashFallback.test.js.map +1 -1
- package/dist/src/utils/getFolderStructure.js +7 -16
- package/dist/src/utils/getFolderStructure.js.map +1 -1
- package/dist/src/utils/googleErrors.d.ts +104 -0
- package/dist/src/utils/googleErrors.js +152 -0
- package/dist/src/utils/googleErrors.js.map +1 -0
- package/dist/src/utils/googleErrors.test.d.ts +6 -0
- package/dist/src/utils/googleErrors.test.js +301 -0
- package/dist/src/utils/googleErrors.test.js.map +1 -0
- package/dist/src/utils/googleQuotaErrors.d.ts +35 -0
- package/dist/src/utils/googleQuotaErrors.js +131 -0
- package/dist/src/utils/googleQuotaErrors.js.map +1 -0
- package/dist/src/utils/googleQuotaErrors.test.d.ts +6 -0
- package/dist/src/utils/googleQuotaErrors.test.js +281 -0
- package/dist/src/utils/googleQuotaErrors.test.js.map +1 -0
- package/dist/src/utils/ignorePatterns.test.js +26 -30
- package/dist/src/utils/ignorePatterns.test.js.map +1 -1
- package/dist/src/utils/memoryDiscovery.d.ts +2 -2
- package/dist/src/utils/memoryDiscovery.js +3 -2
- package/dist/src/utils/memoryDiscovery.js.map +1 -1
- package/dist/src/utils/memoryDiscovery.test.js +19 -35
- package/dist/src/utils/memoryDiscovery.test.js.map +1 -1
- package/dist/src/utils/paths.js +126 -26
- package/dist/src/utils/paths.js.map +1 -1
- package/dist/src/utils/paths.test.js +200 -68
- package/dist/src/utils/paths.test.js.map +1 -1
- package/dist/src/utils/quotaErrorDetection.d.ts +0 -2
- package/dist/src/utils/quotaErrorDetection.js +0 -46
- package/dist/src/utils/quotaErrorDetection.js.map +1 -1
- package/dist/src/utils/retry.js +41 -145
- package/dist/src/utils/retry.js.map +1 -1
- package/dist/src/utils/retry.test.js +31 -110
- package/dist/src/utils/retry.test.js.map +1 -1
- package/dist/src/utils/shell-utils.test.js +70 -0
- package/dist/src/utils/shell-utils.test.js.map +1 -1
- package/dist/src/utils/workspaceContext.js +1 -1
- package/dist/src/utils/workspaceContext.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/dist/google-gemini-cli-core-0.12.0-nightly.20251022.0542de95.tgz +0 -0
|
@@ -0,0 +1,387 @@
|
|
|
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 { toChatMessage, toInputMessages, toSystemInstruction, toOutputMessages, toFinishReasons, OTelFinishReason, toOutputType, OTelOutputType, } from './semantic.js';
|
|
8
|
+
import { Language, Outcome, FinishReason, } from '@google/genai';
|
|
9
|
+
describe('toChatMessage', () => {
|
|
10
|
+
it('should correctly handle text parts', () => {
|
|
11
|
+
const content = {
|
|
12
|
+
role: 'user',
|
|
13
|
+
parts: [{ text: 'Hello' }],
|
|
14
|
+
};
|
|
15
|
+
expect(toChatMessage(content)).toEqual({
|
|
16
|
+
role: 'user',
|
|
17
|
+
parts: [
|
|
18
|
+
{
|
|
19
|
+
type: 'text',
|
|
20
|
+
content: 'Hello',
|
|
21
|
+
},
|
|
22
|
+
],
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
it('should correctly handle function call parts', () => {
|
|
26
|
+
const content = {
|
|
27
|
+
role: 'model',
|
|
28
|
+
parts: [
|
|
29
|
+
{
|
|
30
|
+
functionCall: {
|
|
31
|
+
name: 'test-function',
|
|
32
|
+
args: {
|
|
33
|
+
arg1: 'test-value',
|
|
34
|
+
},
|
|
35
|
+
id: '12345',
|
|
36
|
+
},
|
|
37
|
+
// include field not specified in semantic specification that could be present
|
|
38
|
+
thoughtSignature: '1234',
|
|
39
|
+
},
|
|
40
|
+
],
|
|
41
|
+
};
|
|
42
|
+
expect(toChatMessage(content)).toEqual({
|
|
43
|
+
role: 'system',
|
|
44
|
+
parts: [
|
|
45
|
+
{
|
|
46
|
+
type: 'tool_call',
|
|
47
|
+
name: 'test-function',
|
|
48
|
+
arguments: '{"arg1":"test-value"}',
|
|
49
|
+
id: '12345',
|
|
50
|
+
},
|
|
51
|
+
],
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
it('should correctly handle function response parts', () => {
|
|
55
|
+
const content = {
|
|
56
|
+
role: 'user',
|
|
57
|
+
parts: [
|
|
58
|
+
{
|
|
59
|
+
functionResponse: {
|
|
60
|
+
name: 'test-function',
|
|
61
|
+
response: {
|
|
62
|
+
result: 'success',
|
|
63
|
+
},
|
|
64
|
+
id: '12345',
|
|
65
|
+
},
|
|
66
|
+
// include field not specified in semantic specification that could be present
|
|
67
|
+
fileData: {
|
|
68
|
+
displayName: 'greatfile',
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
],
|
|
72
|
+
};
|
|
73
|
+
expect(toChatMessage(content)).toEqual({
|
|
74
|
+
role: 'user',
|
|
75
|
+
parts: [
|
|
76
|
+
{
|
|
77
|
+
type: 'tool_call_response',
|
|
78
|
+
response: '{"result":"success"}',
|
|
79
|
+
id: '12345',
|
|
80
|
+
},
|
|
81
|
+
],
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
it('should correctly handle reasoning parts with text', () => {
|
|
85
|
+
const content = {
|
|
86
|
+
role: 'system',
|
|
87
|
+
parts: [{ text: 'Hmm', thought: true }],
|
|
88
|
+
};
|
|
89
|
+
expect(toChatMessage(content)).toEqual({
|
|
90
|
+
role: 'system',
|
|
91
|
+
parts: [
|
|
92
|
+
{
|
|
93
|
+
type: 'reasoning',
|
|
94
|
+
content: 'Hmm',
|
|
95
|
+
},
|
|
96
|
+
],
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
it('should correctly handle reasoning parts without text', () => {
|
|
100
|
+
const content = {
|
|
101
|
+
role: 'system',
|
|
102
|
+
parts: [
|
|
103
|
+
{
|
|
104
|
+
thought: true,
|
|
105
|
+
// include field not specified in semantic specification that could be present
|
|
106
|
+
inlineData: {
|
|
107
|
+
displayName: 'wowdata',
|
|
108
|
+
},
|
|
109
|
+
},
|
|
110
|
+
],
|
|
111
|
+
};
|
|
112
|
+
expect(toChatMessage(content)).toEqual({
|
|
113
|
+
role: 'system',
|
|
114
|
+
parts: [
|
|
115
|
+
{
|
|
116
|
+
type: 'reasoning',
|
|
117
|
+
content: '',
|
|
118
|
+
},
|
|
119
|
+
],
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
it('should correctly handle text parts that are not reasoning parts', () => {
|
|
123
|
+
const content = {
|
|
124
|
+
role: 'user',
|
|
125
|
+
parts: [{ text: 'what a nice day', thought: false }],
|
|
126
|
+
};
|
|
127
|
+
expect(toChatMessage(content)).toEqual({
|
|
128
|
+
role: 'user',
|
|
129
|
+
parts: [
|
|
130
|
+
{
|
|
131
|
+
type: 'text',
|
|
132
|
+
content: 'what a nice day',
|
|
133
|
+
},
|
|
134
|
+
],
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
it('should correctly handle "generic" parts', () => {
|
|
138
|
+
const content = {
|
|
139
|
+
role: 'model',
|
|
140
|
+
parts: [
|
|
141
|
+
{
|
|
142
|
+
executableCode: {
|
|
143
|
+
code: 'print("foo")',
|
|
144
|
+
language: Language.PYTHON,
|
|
145
|
+
},
|
|
146
|
+
},
|
|
147
|
+
{
|
|
148
|
+
codeExecutionResult: {
|
|
149
|
+
outcome: Outcome.OUTCOME_OK,
|
|
150
|
+
output: 'foo',
|
|
151
|
+
},
|
|
152
|
+
// include field not specified in semantic specification that could be present
|
|
153
|
+
videoMetadata: {
|
|
154
|
+
fps: 5,
|
|
155
|
+
},
|
|
156
|
+
},
|
|
157
|
+
],
|
|
158
|
+
};
|
|
159
|
+
expect(toChatMessage(content)).toEqual({
|
|
160
|
+
role: 'system',
|
|
161
|
+
parts: [
|
|
162
|
+
{
|
|
163
|
+
type: 'executableCode',
|
|
164
|
+
code: 'print("foo")',
|
|
165
|
+
language: 'PYTHON',
|
|
166
|
+
},
|
|
167
|
+
{
|
|
168
|
+
type: 'codeExecutionResult',
|
|
169
|
+
outcome: 'OUTCOME_OK',
|
|
170
|
+
output: 'foo',
|
|
171
|
+
videoMetadata: {
|
|
172
|
+
fps: 5,
|
|
173
|
+
},
|
|
174
|
+
},
|
|
175
|
+
],
|
|
176
|
+
});
|
|
177
|
+
});
|
|
178
|
+
it('should correctly handle unknown parts', () => {
|
|
179
|
+
const content = {
|
|
180
|
+
role: 'model',
|
|
181
|
+
parts: [
|
|
182
|
+
{
|
|
183
|
+
fileData: {
|
|
184
|
+
displayName: 'superfile',
|
|
185
|
+
},
|
|
186
|
+
},
|
|
187
|
+
],
|
|
188
|
+
};
|
|
189
|
+
expect(toChatMessage(content)).toEqual({
|
|
190
|
+
role: 'system',
|
|
191
|
+
parts: [
|
|
192
|
+
{
|
|
193
|
+
type: 'unknown',
|
|
194
|
+
fileData: {
|
|
195
|
+
displayName: 'superfile',
|
|
196
|
+
},
|
|
197
|
+
},
|
|
198
|
+
],
|
|
199
|
+
});
|
|
200
|
+
});
|
|
201
|
+
});
|
|
202
|
+
describe('toSystemInstruction', () => {
|
|
203
|
+
it('should correctly handle a string', () => {
|
|
204
|
+
const content = 'Hello';
|
|
205
|
+
expect(toSystemInstruction(content)).toEqual([
|
|
206
|
+
{
|
|
207
|
+
type: 'text',
|
|
208
|
+
content: 'Hello',
|
|
209
|
+
},
|
|
210
|
+
]);
|
|
211
|
+
});
|
|
212
|
+
it('should correctly handle a Content object with a text part', () => {
|
|
213
|
+
const content = {
|
|
214
|
+
role: 'user',
|
|
215
|
+
parts: [{ text: 'Hello' }],
|
|
216
|
+
};
|
|
217
|
+
expect(toSystemInstruction(content)).toEqual([
|
|
218
|
+
{
|
|
219
|
+
type: 'text',
|
|
220
|
+
content: 'Hello',
|
|
221
|
+
},
|
|
222
|
+
]);
|
|
223
|
+
});
|
|
224
|
+
it('should correctly handle a Content object with multiple parts', () => {
|
|
225
|
+
const content = {
|
|
226
|
+
role: 'user',
|
|
227
|
+
parts: [{ text: 'Hello' }, { text: 'Hmm', thought: true }],
|
|
228
|
+
};
|
|
229
|
+
expect(toSystemInstruction(content)).toEqual([
|
|
230
|
+
{
|
|
231
|
+
type: 'text',
|
|
232
|
+
content: 'Hello',
|
|
233
|
+
},
|
|
234
|
+
{
|
|
235
|
+
type: 'reasoning',
|
|
236
|
+
content: 'Hmm',
|
|
237
|
+
},
|
|
238
|
+
]);
|
|
239
|
+
});
|
|
240
|
+
});
|
|
241
|
+
describe('toInputMessages', () => {
|
|
242
|
+
it('should correctly convert an array of Content objects', () => {
|
|
243
|
+
const contents = [
|
|
244
|
+
{
|
|
245
|
+
role: 'user',
|
|
246
|
+
parts: [{ text: 'Hello' }],
|
|
247
|
+
},
|
|
248
|
+
{
|
|
249
|
+
role: 'model',
|
|
250
|
+
parts: [{ text: 'Hi there!' }],
|
|
251
|
+
},
|
|
252
|
+
];
|
|
253
|
+
expect(toInputMessages(contents)).toEqual([
|
|
254
|
+
{
|
|
255
|
+
role: 'user',
|
|
256
|
+
parts: [
|
|
257
|
+
{
|
|
258
|
+
type: 'text',
|
|
259
|
+
content: 'Hello',
|
|
260
|
+
},
|
|
261
|
+
],
|
|
262
|
+
},
|
|
263
|
+
{
|
|
264
|
+
role: 'system',
|
|
265
|
+
parts: [
|
|
266
|
+
{
|
|
267
|
+
type: 'text',
|
|
268
|
+
content: 'Hi there!',
|
|
269
|
+
},
|
|
270
|
+
],
|
|
271
|
+
},
|
|
272
|
+
]);
|
|
273
|
+
});
|
|
274
|
+
});
|
|
275
|
+
describe('toOutputMessages', () => {
|
|
276
|
+
it('should correctly convert an array of Candidate objects', () => {
|
|
277
|
+
const candidates = [
|
|
278
|
+
{
|
|
279
|
+
index: 0,
|
|
280
|
+
finishReason: FinishReason.STOP,
|
|
281
|
+
content: {
|
|
282
|
+
role: 'model',
|
|
283
|
+
parts: [{ text: 'This is the first candidate.' }],
|
|
284
|
+
},
|
|
285
|
+
},
|
|
286
|
+
{
|
|
287
|
+
index: 1,
|
|
288
|
+
finishReason: FinishReason.MAX_TOKENS,
|
|
289
|
+
content: {
|
|
290
|
+
role: 'model',
|
|
291
|
+
parts: [{ text: 'This is the second candidate.' }],
|
|
292
|
+
},
|
|
293
|
+
},
|
|
294
|
+
];
|
|
295
|
+
expect(toOutputMessages(candidates)).toEqual([
|
|
296
|
+
{
|
|
297
|
+
role: 'system',
|
|
298
|
+
finish_reason: 'stop',
|
|
299
|
+
parts: [
|
|
300
|
+
{
|
|
301
|
+
type: 'text',
|
|
302
|
+
content: 'This is the first candidate.',
|
|
303
|
+
},
|
|
304
|
+
],
|
|
305
|
+
},
|
|
306
|
+
{
|
|
307
|
+
role: 'system',
|
|
308
|
+
finish_reason: 'length',
|
|
309
|
+
parts: [
|
|
310
|
+
{
|
|
311
|
+
type: 'text',
|
|
312
|
+
content: 'This is the second candidate.',
|
|
313
|
+
},
|
|
314
|
+
],
|
|
315
|
+
},
|
|
316
|
+
]);
|
|
317
|
+
});
|
|
318
|
+
});
|
|
319
|
+
describe('toFinishReasons', () => {
|
|
320
|
+
it('should return an empty array if candidates is undefined', () => {
|
|
321
|
+
expect(toFinishReasons(undefined)).toEqual([]);
|
|
322
|
+
});
|
|
323
|
+
it('should return an empty array if candidates is an empty array', () => {
|
|
324
|
+
expect(toFinishReasons([])).toEqual([]);
|
|
325
|
+
});
|
|
326
|
+
it('should correctly convert a single candidate', () => {
|
|
327
|
+
const candidates = [
|
|
328
|
+
{
|
|
329
|
+
index: 0,
|
|
330
|
+
finishReason: FinishReason.STOP,
|
|
331
|
+
content: {
|
|
332
|
+
role: 'model',
|
|
333
|
+
parts: [{ text: 'This is the first candidate.' }],
|
|
334
|
+
},
|
|
335
|
+
},
|
|
336
|
+
];
|
|
337
|
+
expect(toFinishReasons(candidates)).toEqual([OTelFinishReason.STOP]);
|
|
338
|
+
});
|
|
339
|
+
it('should correctly convert multiple candidates', () => {
|
|
340
|
+
const candidates = [
|
|
341
|
+
{
|
|
342
|
+
index: 0,
|
|
343
|
+
finishReason: FinishReason.STOP,
|
|
344
|
+
content: {
|
|
345
|
+
role: 'model',
|
|
346
|
+
parts: [{ text: 'This is the first candidate.' }],
|
|
347
|
+
},
|
|
348
|
+
},
|
|
349
|
+
{
|
|
350
|
+
index: 1,
|
|
351
|
+
finishReason: FinishReason.MAX_TOKENS,
|
|
352
|
+
content: {
|
|
353
|
+
role: 'model',
|
|
354
|
+
parts: [{ text: 'This is the second candidate.' }],
|
|
355
|
+
},
|
|
356
|
+
},
|
|
357
|
+
{
|
|
358
|
+
index: 2,
|
|
359
|
+
finishReason: FinishReason.SAFETY,
|
|
360
|
+
content: {
|
|
361
|
+
role: 'model',
|
|
362
|
+
parts: [{ text: 'This is the third candidate.' }],
|
|
363
|
+
},
|
|
364
|
+
},
|
|
365
|
+
];
|
|
366
|
+
expect(toFinishReasons(candidates)).toEqual([
|
|
367
|
+
OTelFinishReason.STOP,
|
|
368
|
+
OTelFinishReason.LENGTH,
|
|
369
|
+
OTelFinishReason.CONTENT_FILTER,
|
|
370
|
+
]);
|
|
371
|
+
});
|
|
372
|
+
});
|
|
373
|
+
describe('toOutputType', () => {
|
|
374
|
+
it('should return TEXT for text/plain', () => {
|
|
375
|
+
expect(toOutputType('text/plain')).toBe(OTelOutputType.TEXT);
|
|
376
|
+
});
|
|
377
|
+
it('should return JSON for application/json', () => {
|
|
378
|
+
expect(toOutputType('application/json')).toBe(OTelOutputType.JSON);
|
|
379
|
+
});
|
|
380
|
+
it('should return the custom mime type for other strings', () => {
|
|
381
|
+
expect(toOutputType('application/vnd.custom-type')).toBe('application/vnd.custom-type');
|
|
382
|
+
});
|
|
383
|
+
it('should return undefined for undefined input', () => {
|
|
384
|
+
expect(toOutputType(undefined)).toBeUndefined();
|
|
385
|
+
});
|
|
386
|
+
});
|
|
387
|
+
//# sourceMappingURL=semantic.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"semantic.test.js","sourceRoot":"","sources":["../../../src/telemetry/semantic.test.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EACL,aAAa,EACb,eAAe,EACf,mBAAmB,EACnB,gBAAgB,EAChB,eAAe,EACf,gBAAgB,EAChB,YAAY,EACZ,cAAc,GACf,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,QAAQ,EAER,OAAO,EAEP,YAAY,GACb,MAAM,eAAe,CAAC;AAEvB,QAAQ,CAAC,eAAe,EAAE,GAAG,EAAE;IAC7B,EAAE,CAAC,oCAAoC,EAAE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CAAC,CAAC,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;IACrE,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,sDAAsD,EAAE,GAAG,EAAE;QAC9D,MAAM,CAAC,YAAY,CAAC,6BAA6B,CAAC,CAAC,CAAC,IAAI,CACtD,6BAA6B,CAC9B,CAAC;IACJ,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,6CAA6C,EAAE,GAAG,EAAE;QACrD,MAAM,CAAC,YAAY,CAAC,SAAS,CAAC,CAAC,CAAC,aAAa,EAAE,CAAC;IAClD,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import { type AttributeValue, type SpanOptions } from '@opentelemetry/api';
|
|
7
|
+
/**
|
|
8
|
+
* Metadata for a span.
|
|
9
|
+
*/
|
|
10
|
+
export interface SpanMetadata {
|
|
11
|
+
/** The name of the span. */
|
|
12
|
+
name: string;
|
|
13
|
+
/** The input to the span. */
|
|
14
|
+
input?: unknown;
|
|
15
|
+
/** The output of the span. */
|
|
16
|
+
output?: unknown;
|
|
17
|
+
error?: unknown;
|
|
18
|
+
/** Additional attributes for the span. */
|
|
19
|
+
attributes: Record<string, AttributeValue>;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Runs a function in a new OpenTelemetry span.
|
|
23
|
+
*
|
|
24
|
+
* The `meta` object will be automatically used to set the span's status and attributes upon completion.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```typescript
|
|
28
|
+
* runInDevTraceSpan({ name: 'my-operation' }, ({ metadata }) => {
|
|
29
|
+
* metadata.input = { foo: 'bar' };
|
|
30
|
+
* // ... do work ...
|
|
31
|
+
* metadata.output = { result: 'baz' };
|
|
32
|
+
* metadata.attributes['my.custom.attribute'] = 'some-value';
|
|
33
|
+
* });
|
|
34
|
+
* ```
|
|
35
|
+
*
|
|
36
|
+
* @param opts The options for the span.
|
|
37
|
+
* @param fn The function to run in the span.
|
|
38
|
+
* @returns The result of the function.
|
|
39
|
+
*/
|
|
40
|
+
export declare function runInDevTraceSpan<R>(opts: SpanOptions & {
|
|
41
|
+
name: string;
|
|
42
|
+
noAutoEnd?: boolean;
|
|
43
|
+
}, fn: ({ metadata, }: {
|
|
44
|
+
metadata: SpanMetadata;
|
|
45
|
+
endSpan: () => void;
|
|
46
|
+
}) => Promise<R>): Promise<R>;
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import { diag, SpanStatusCode, trace, } from '@opentelemetry/api';
|
|
7
|
+
import { safeJsonStringify } from '../utils/safeJsonStringify.js';
|
|
8
|
+
const TRACER_NAME = 'gemini-cli';
|
|
9
|
+
const TRACER_VERSION = 'v1';
|
|
10
|
+
/**
|
|
11
|
+
* Runs a function in a new OpenTelemetry span.
|
|
12
|
+
*
|
|
13
|
+
* The `meta` object will be automatically used to set the span's status and attributes upon completion.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* runInDevTraceSpan({ name: 'my-operation' }, ({ metadata }) => {
|
|
18
|
+
* metadata.input = { foo: 'bar' };
|
|
19
|
+
* // ... do work ...
|
|
20
|
+
* metadata.output = { result: 'baz' };
|
|
21
|
+
* metadata.attributes['my.custom.attribute'] = 'some-value';
|
|
22
|
+
* });
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* @param opts The options for the span.
|
|
26
|
+
* @param fn The function to run in the span.
|
|
27
|
+
* @returns The result of the function.
|
|
28
|
+
*/
|
|
29
|
+
export async function runInDevTraceSpan(opts, fn) {
|
|
30
|
+
const { name: spanName, noAutoEnd, ...restOfSpanOpts } = opts;
|
|
31
|
+
if (process.env['GEMINI_DEV_TRACING'] !== 'true') {
|
|
32
|
+
// If GEMINI_DEV_TRACING env var not set, we do not trace.
|
|
33
|
+
return await fn({
|
|
34
|
+
metadata: {
|
|
35
|
+
name: spanName,
|
|
36
|
+
attributes: {},
|
|
37
|
+
},
|
|
38
|
+
endSpan: () => {
|
|
39
|
+
// noop
|
|
40
|
+
},
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
const tracer = trace.getTracer(TRACER_NAME, TRACER_VERSION);
|
|
44
|
+
return await tracer.startActiveSpan(opts.name, restOfSpanOpts, async (span) => {
|
|
45
|
+
const meta = {
|
|
46
|
+
name: spanName,
|
|
47
|
+
attributes: {},
|
|
48
|
+
};
|
|
49
|
+
const endSpan = () => {
|
|
50
|
+
try {
|
|
51
|
+
if (meta.input !== undefined) {
|
|
52
|
+
span.setAttribute('input-json', safeJsonStringify(meta.input));
|
|
53
|
+
}
|
|
54
|
+
if (meta.output !== undefined) {
|
|
55
|
+
span.setAttribute('output-json', safeJsonStringify(meta.output));
|
|
56
|
+
}
|
|
57
|
+
for (const [key, value] of Object.entries(meta.attributes)) {
|
|
58
|
+
span.setAttribute(key, value);
|
|
59
|
+
}
|
|
60
|
+
if (meta.error) {
|
|
61
|
+
span.setStatus({
|
|
62
|
+
code: SpanStatusCode.ERROR,
|
|
63
|
+
message: getErrorMessage(meta.error),
|
|
64
|
+
});
|
|
65
|
+
if (meta.error instanceof Error) {
|
|
66
|
+
span.recordException(meta.error);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
span.setStatus({ code: SpanStatusCode.OK });
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
catch (e) {
|
|
74
|
+
// Log the error but don't rethrow, to ensure span.end() is called.
|
|
75
|
+
diag.error('Error setting span attributes in endSpan', e);
|
|
76
|
+
span.setStatus({
|
|
77
|
+
code: SpanStatusCode.ERROR,
|
|
78
|
+
message: `Error in endSpan: ${getErrorMessage(e)}`,
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
finally {
|
|
82
|
+
span.end();
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
try {
|
|
86
|
+
return await fn({ metadata: meta, endSpan });
|
|
87
|
+
}
|
|
88
|
+
catch (e) {
|
|
89
|
+
meta.error = e;
|
|
90
|
+
if (noAutoEnd) {
|
|
91
|
+
// For streaming operations, the delegated endSpan call will not be reached
|
|
92
|
+
// on an exception, so we must end the span here to prevent a leak.
|
|
93
|
+
endSpan();
|
|
94
|
+
}
|
|
95
|
+
throw e;
|
|
96
|
+
}
|
|
97
|
+
finally {
|
|
98
|
+
if (!noAutoEnd) {
|
|
99
|
+
// For non-streaming operations, this ensures the span is always closed,
|
|
100
|
+
// and if an error occurred, it will be recorded correctly by endSpan.
|
|
101
|
+
endSpan();
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Gets the error message from an error object.
|
|
108
|
+
*
|
|
109
|
+
* @param e The error object.
|
|
110
|
+
* @returns The error message.
|
|
111
|
+
*/
|
|
112
|
+
function getErrorMessage(e) {
|
|
113
|
+
if (e instanceof Error) {
|
|
114
|
+
return e.message;
|
|
115
|
+
}
|
|
116
|
+
if (typeof e === 'string') {
|
|
117
|
+
return e;
|
|
118
|
+
}
|
|
119
|
+
return safeJsonStringify(e);
|
|
120
|
+
}
|
|
121
|
+
//# sourceMappingURL=trace.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"trace.js","sourceRoot":"","sources":["../../../src/telemetry/trace.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EACL,IAAI,EACJ,cAAc,EACd,KAAK,GAGN,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAElE,MAAM,WA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AC;gBAAS,CAAC;YACT,IAAI,CAAC,SAAS,EAAE,CAAC;gBACf,wEAAwE;gBACxE,sEAAsE;gBACtE,OAAO,EAAE,CAAC;YACZ,CAAC;QACH,CAAC;IACH,CAAC,CACF,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACH,SAAS,eAAe,CAAC,CAAU;IACjC,IAAI,CAAC,YAAY,KAAK,EAAE,CAAC;QACvB,OAAO,CAAC,CAAC,OAAO,CAAC;IACnB,CAAC;IACD,IAAI,OAAO,CAAC,KAAK,QAAQ,EAAE,CAAC;QAC1B,OAAO,CAAC,CAAC;IACX,CAAC;IACD,OAAO,iBAAiB,CAAC,CAAC,CAAC,CAAC;AAC9B,CAAC"}
|
|
@@ -3,13 +3,13 @@
|
|
|
3
3
|
* Copyright 2025 Google LLC
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
|
-
import type { GenerateContentResponseUsageMetadata } from '@google/genai';
|
|
6
|
+
import type { Candidate, Content, GenerateContentConfig, GenerateContentResponseUsageMetadata } from '@google/genai';
|
|
7
7
|
import type { Config } from '../config/config.js';
|
|
8
8
|
import type { ApprovalMode } from '../config/config.js';
|
|
9
9
|
import type { CompletedToolCall } from '../core/coreToolScheduler.js';
|
|
10
|
-
import type { LogAttributes } from '@opentelemetry/api-logs';
|
|
10
|
+
import type { LogAttributes, LogRecord } from '@opentelemetry/api-logs';
|
|
11
11
|
import { ToolCallDecision } from './tool-call-decision.js';
|
|
12
|
-
import type
|
|
12
|
+
import { type FileOperation } from './metrics.js';
|
|
13
13
|
export { ToolCallDecision };
|
|
14
14
|
import type { ToolRegistry } from '../tools/tool-registry.js';
|
|
15
15
|
import type { OutputFormat } from '../output/types.js';
|
|
@@ -104,35 +104,54 @@ export declare class ApiErrorEvent implements BaseTelemetryEvent {
|
|
|
104
104
|
'event.name': 'api_error';
|
|
105
105
|
'event.timestamp': string;
|
|
106
106
|
model: string;
|
|
107
|
+
prompt: GenAIPromptDetails;
|
|
107
108
|
error: string;
|
|
108
109
|
error_type?: string;
|
|
109
110
|
status_code?: number | string;
|
|
110
111
|
duration_ms: number;
|
|
111
|
-
prompt_id: string;
|
|
112
112
|
auth_type?: string;
|
|
113
|
-
constructor(model: string, error: string, duration_ms: number,
|
|
114
|
-
|
|
115
|
-
|
|
113
|
+
constructor(model: string, error: string, duration_ms: number, prompt_details: GenAIPromptDetails, auth_type?: string, error_type?: string, status_code?: number | string);
|
|
114
|
+
toLogRecord(config: Config): LogRecord;
|
|
115
|
+
toSemanticLogRecord(config: Config): LogRecord;
|
|
116
116
|
}
|
|
117
|
-
export
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
117
|
+
export interface ServerDetails {
|
|
118
|
+
address: string;
|
|
119
|
+
port: number;
|
|
120
|
+
}
|
|
121
|
+
export interface GenAIPromptDetails {
|
|
122
|
+
prompt_id: string;
|
|
123
|
+
contents: Content[];
|
|
124
|
+
generate_content_config?: GenerateContentConfig;
|
|
125
|
+
server?: ServerDetails;
|
|
126
|
+
}
|
|
127
|
+
export interface GenAIResponseDetails {
|
|
128
|
+
response_id?: string;
|
|
129
|
+
candidates?: Candidate[];
|
|
130
|
+
}
|
|
131
|
+
export interface GenAIUsageDetails {
|
|
124
132
|
input_token_count: number;
|
|
125
133
|
output_token_count: number;
|
|
126
134
|
cached_content_token_count: number;
|
|
127
135
|
thoughts_token_count: number;
|
|
128
136
|
tool_token_count: number;
|
|
129
137
|
total_token_count: number;
|
|
138
|
+
}
|
|
139
|
+
export declare const EVENT_API_RESPONSE = "gemini_cli.api_response";
|
|
140
|
+
export declare const EVENT_GEN_AI_OPERATION_DETAILS = "gen_ai.client.inference.operation.details";
|
|
141
|
+
export declare class ApiResponseEvent implements BaseTelemetryEvent {
|
|
142
|
+
'event.name': 'api_response';
|
|
143
|
+
'event.timestamp': string;
|
|
144
|
+
status_code?: number | string;
|
|
145
|
+
duration_ms: number;
|
|
130
146
|
response_text?: string;
|
|
131
|
-
prompt_id: string;
|
|
132
147
|
auth_type?: string;
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
148
|
+
model: string;
|
|
149
|
+
prompt: GenAIPromptDetails;
|
|
150
|
+
response: GenAIResponseDetails;
|
|
151
|
+
usage: GenAIUsageDetails;
|
|
152
|
+
constructor(model: string, duration_ms: number, prompt_details: GenAIPromptDetails, response_details: GenAIResponseDetails, auth_type?: string, usage_data?: GenerateContentResponseUsageMetadata, response_text?: string);
|
|
153
|
+
toLogRecord(config: Config): LogRecord;
|
|
154
|
+
toSemanticLogRecord(config: Config): LogRecord;
|
|
136
155
|
}
|
|
137
156
|
export declare const EVENT_FLASH_FALLBACK = "gemini_cli.flash_fallback";
|
|
138
157
|
export declare class FlashFallbackEvent implements BaseTelemetryEvent {
|