Skip to content

Commit aad9635

Browse files
sararobcopybara-github
authored andcommitted
chore: Add AE session events module
PiperOrigin-RevId: 885561202
1 parent 97b509c commit aad9635

File tree

5 files changed

+422
-0
lines changed

5 files changed

+422
-0
lines changed
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
/**
2+
* @license
3+
* Copyright 2025 Google LLC
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
// Code generated by the Google Gen AI SDK generator DO NOT EDIT.
8+
9+
import type * as genaiTypes from '@google/genai';
10+
import * as common from '@google/genai/vertex_internal';
11+
import * as types from '../types.js';
12+
13+
export function appendAgentEngineSessionEventConfigToVertex(
14+
fromObject: types.AppendAgentEngineSessionEventConfig,
15+
parentObject: Record<string, unknown>,
16+
): Record<string, unknown> {
17+
const toObject: Record<string, unknown> = {};
18+
19+
const fromContent = common.getValueByPath(fromObject, ['content']);
20+
if (parentObject !== undefined && fromContent != null) {
21+
common.setValueByPath(parentObject, ['content'], fromContent);
22+
}
23+
24+
const fromActions = common.getValueByPath(fromObject, ['actions']);
25+
if (parentObject !== undefined && fromActions != null) {
26+
common.setValueByPath(parentObject, ['actions'], fromActions);
27+
}
28+
29+
const fromErrorCode = common.getValueByPath(fromObject, ['errorCode']);
30+
if (parentObject !== undefined && fromErrorCode != null) {
31+
common.setValueByPath(parentObject, ['errorCode'], fromErrorCode);
32+
}
33+
34+
const fromErrorMessage = common.getValueByPath(fromObject, ['errorMessage']);
35+
if (parentObject !== undefined && fromErrorMessage != null) {
36+
common.setValueByPath(parentObject, ['errorMessage'], fromErrorMessage);
37+
}
38+
39+
const fromEventMetadata = common.getValueByPath(fromObject, [
40+
'eventMetadata',
41+
]);
42+
if (parentObject !== undefined && fromEventMetadata != null) {
43+
common.setValueByPath(parentObject, ['eventMetadata'], fromEventMetadata);
44+
}
45+
46+
return toObject;
47+
}
48+
49+
export function appendAgentEngineSessionEventRequestParametersToVertex(
50+
fromObject: types.AppendAgentEngineSessionEventRequestParameters,
51+
): Record<string, unknown> {
52+
const toObject: Record<string, unknown> = {};
53+
54+
const fromName = common.getValueByPath(fromObject, ['name']);
55+
if (fromName != null) {
56+
common.setValueByPath(toObject, ['_url', 'name'], fromName);
57+
}
58+
59+
const fromAuthor = common.getValueByPath(fromObject, ['author']);
60+
if (fromAuthor != null) {
61+
common.setValueByPath(toObject, ['author'], fromAuthor);
62+
}
63+
64+
const fromInvocationId = common.getValueByPath(fromObject, ['invocationId']);
65+
if (fromInvocationId != null) {
66+
common.setValueByPath(toObject, ['invocationId'], fromInvocationId);
67+
}
68+
69+
const fromTimestamp = common.getValueByPath(fromObject, ['timestamp']);
70+
if (fromTimestamp != null) {
71+
common.setValueByPath(toObject, ['timestamp'], fromTimestamp);
72+
}
73+
74+
const fromConfig = common.getValueByPath(fromObject, ['config']);
75+
if (fromConfig != null) {
76+
appendAgentEngineSessionEventConfigToVertex(fromConfig, toObject);
77+
}
78+
79+
return toObject;
80+
}
81+
82+
export function listAgentEngineSessionEventsConfigToVertex(
83+
fromObject: types.ListAgentEngineSessionEventsConfig,
84+
parentObject: Record<string, unknown>,
85+
): Record<string, unknown> {
86+
const toObject: Record<string, unknown> = {};
87+
88+
const fromPageSize = common.getValueByPath(fromObject, ['pageSize']);
89+
if (parentObject !== undefined && fromPageSize != null) {
90+
common.setValueByPath(parentObject, ['_query', 'pageSize'], fromPageSize);
91+
}
92+
93+
const fromPageToken = common.getValueByPath(fromObject, ['pageToken']);
94+
if (parentObject !== undefined && fromPageToken != null) {
95+
common.setValueByPath(parentObject, ['_query', 'pageToken'], fromPageToken);
96+
}
97+
98+
const fromFilter = common.getValueByPath(fromObject, ['filter']);
99+
if (parentObject !== undefined && fromFilter != null) {
100+
common.setValueByPath(parentObject, ['_query', 'filter'], fromFilter);
101+
}
102+
103+
return toObject;
104+
}
105+
106+
export function listAgentEngineSessionEventsRequestParametersToVertex(
107+
fromObject: types.ListAgentEngineSessionEventsRequestParameters,
108+
): Record<string, unknown> {
109+
const toObject: Record<string, unknown> = {};
110+
111+
const fromName = common.getValueByPath(fromObject, ['name']);
112+
if (fromName != null) {
113+
common.setValueByPath(toObject, ['_url', 'name'], fromName);
114+
}
115+
116+
const fromConfig = common.getValueByPath(fromObject, ['config']);
117+
if (fromConfig != null) {
118+
listAgentEngineSessionEventsConfigToVertex(fromConfig, toObject);
119+
}
120+
121+
return toObject;
122+
}

src/genai/sessionevents.ts

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
/**
2+
* @license
3+
* Copyright 2025 Google LLC
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
// Code generated by the Google Gen AI SDK generator DO NOT EDIT.
8+
9+
import * as genaiTypes from '@google/genai';
10+
import {PagedItem, Pager} from '@google/genai';
11+
import * as common from '@google/genai/vertex_internal';
12+
import {
13+
ApiClient,
14+
BaseModule,
15+
NodeAuth,
16+
NodeDownloader,
17+
NodeUploader,
18+
} from '@google/genai/vertex_internal';
19+
import * as converters from './converters/_sessionevents_converters.js';
20+
import * as types from './types.js';
21+
22+
export class SessionEvents extends BaseModule {
23+
constructor(private readonly apiClient: ApiClient) {
24+
super();
25+
}
26+
27+
async append(
28+
params: types.AppendAgentEngineSessionEventRequestParameters,
29+
): Promise<types.AppendAgentEngineSessionEventResponse> {
30+
let response: Promise<types.AppendAgentEngineSessionEventResponse>;
31+
32+
let path: string = '';
33+
let queryParams: Record<string, string> = {};
34+
if (this.apiClient.isVertexAI()) {
35+
const body =
36+
converters.appendAgentEngineSessionEventRequestParametersToVertex(
37+
params,
38+
);
39+
path = common.formatMap(
40+
'{name}:appendEvent',
41+
body['_url'] as Record<string, unknown>,
42+
);
43+
queryParams = body['_query'] as Record<string, string>;
44+
delete body['_url'];
45+
delete body['_query'];
46+
delete body['config'];
47+
48+
response = this.apiClient
49+
.request({
50+
path: path,
51+
queryParams: queryParams,
52+
body: JSON.stringify(body),
53+
httpMethod: 'POST',
54+
httpOptions: params.config?.httpOptions,
55+
abortSignal: params.config?.abortSignal,
56+
})
57+
.then((httpResponse) => {
58+
return httpResponse.json();
59+
}) as Promise<types.AppendAgentEngineSessionEventResponse>;
60+
61+
return response.then((resp) => {
62+
const typedResp = new types.AppendAgentEngineSessionEventResponse();
63+
Object.assign(typedResp, resp);
64+
return typedResp;
65+
});
66+
} else {
67+
throw new Error('This method is only supported by the Vertex AI.');
68+
}
69+
}
70+
71+
private async listInternal(
72+
params: types.ListAgentEngineSessionEventsRequestParameters,
73+
): Promise<types.ListAgentEngineSessionEventsResponse> {
74+
let response: Promise<types.ListAgentEngineSessionEventsResponse>;
75+
76+
let path: string = '';
77+
let queryParams: Record<string, string> = {};
78+
if (this.apiClient.isVertexAI()) {
79+
const body =
80+
converters.listAgentEngineSessionEventsRequestParametersToVertex(
81+
params,
82+
);
83+
path = common.formatMap(
84+
'{name}/events',
85+
body['_url'] as Record<string, unknown>,
86+
);
87+
queryParams = body['_query'] as Record<string, string>;
88+
delete body['_url'];
89+
delete body['_query'];
90+
delete body['config'];
91+
92+
response = this.apiClient
93+
.request({
94+
path: path,
95+
queryParams: queryParams,
96+
body: JSON.stringify(body),
97+
httpMethod: 'GET',
98+
httpOptions: params.config?.httpOptions,
99+
abortSignal: params.config?.abortSignal,
100+
})
101+
.then((httpResponse) => {
102+
return httpResponse.json();
103+
}) as Promise<types.ListAgentEngineSessionEventsResponse>;
104+
105+
return response.then((resp) => {
106+
const typedResp = new types.ListAgentEngineSessionEventsResponse();
107+
Object.assign(typedResp, resp);
108+
return typedResp;
109+
});
110+
} else {
111+
throw new Error('This method is only supported by the Vertex AI.');
112+
}
113+
}
114+
}

src/genai/sessions.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,15 @@ import {
1717
NodeUploader,
1818
} from '@google/genai/vertex_internal';
1919
import * as converters from './converters/_sessions_converters.js';
20+
import {SessionEvents} from './sessionevents.js';
2021
import * as types from './types.js';
2122

2223
export class Sessions extends BaseModule {
24+
public readonly events: SessionEvents;
25+
2326
constructor(private readonly apiClient: ApiClient) {
2427
super();
28+
this.events = new SessionEvents(apiClient);
2529
}
2630

2731
private async createInternal(

src/genai/types/common.ts

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,6 +1005,135 @@ export declare interface UpdateAgentEngineSessionRequestParameters {
10051005
config?: UpdateAgentEngineSessionConfig;
10061006
}
10071007

1008+
/** Actions are parts of events that are executed by the agent. */
1009+
export declare interface EventActions {
1010+
/** Optional. Indicates that the event is updating an artifact. key is the filename, value is the version. */
1011+
artifactDelta?: Record<string, number>;
1012+
/** Optional. The agent is escalating to a higher level agent. */
1013+
escalate?: boolean;
1014+
/** Optional. Will only be set by a tool response indicating tool request euc. Struct key is the function call id since one function call response (from model) could correspond to multiple function calls. Struct value is the required auth config, which can be another struct. */
1015+
requestedAuthConfigs?: Record<string, unknown>;
1016+
/** Optional. If true, it won't call model to summarize function response. Only used for function_response event. */
1017+
skipSummarization?: boolean;
1018+
/** Optional. Indicates that the event is updating the state with the given delta. */
1019+
stateDelta?: Record<string, unknown>;
1020+
/** Optional. If set, the event transfers to the specified agent. */
1021+
transferAgent?: string;
1022+
}
1023+
1024+
/** Metadata relating to a LLM response event. */
1025+
export declare interface EventMetadata {
1026+
/** Optional. Metadata returned to client when grounding is enabled. */
1027+
groundingMetadata?: genaiTypes.GroundingMetadata;
1028+
/** Optional. The branch of the event. The format is like agent_1.agent_2.agent_3, where agent_1 is the parent of agent_2, and agent_2 is the parent of agent_3. Branch is used when multiple child agents shouldn't see their siblings' conversation history. */
1029+
branch?: string;
1030+
/** The custom metadata of the LlmResponse. */
1031+
customMetadata?: Record<string, unknown>;
1032+
/** Optional. Flag indicating that LLM was interrupted when generating the content. Usually it's due to user interruption during a bidi streaming. */
1033+
interrupted?: boolean;
1034+
/** Optional. Set of ids of the long running function calls. Agent client will know from this field about which function call is long running. Only valid for function call event. */
1035+
longRunningToolIds?: string[];
1036+
/** Optional. Indicates whether the text content is part of a unfinished text stream. Only used for streaming mode and when the content is plain text. */
1037+
partial?: boolean;
1038+
/** Optional. Indicates whether the response from the model is complete. Only used for streaming mode. */
1039+
turnComplete?: boolean;
1040+
}
1041+
1042+
/** Config for appending agent engine session event. */
1043+
export declare interface AppendAgentEngineSessionEventConfig {
1044+
/** Used to override HTTP request options. */
1045+
httpOptions?: genaiTypes.HttpOptions;
1046+
/** Abort signal which can be used to cancel the request.
1047+
1048+
NOTE: AbortSignal is a client-only operation. Using it to cancel an
1049+
operation will not cancel the request in the service. You will still
1050+
be charged usage for any applicable operations.
1051+
*/
1052+
abortSignal?: AbortSignal;
1053+
/** The content of the session event. */
1054+
content?: genaiTypes.Content;
1055+
/** Actions are parts of events that are related to the session event. */
1056+
actions?: EventActions;
1057+
/** The error code of the session event. */
1058+
errorCode?: string;
1059+
/** The error message of the session event. */
1060+
errorMessage?: string;
1061+
/** Metadata relating to the session event. */
1062+
eventMetadata?: EventMetadata;
1063+
}
1064+
1065+
/** Parameters for appending agent engines. */
1066+
export declare interface AppendAgentEngineSessionEventRequestParameters {
1067+
/** Name of the agent engine session. */
1068+
name: string;
1069+
/** Author of the agent engine session event. */
1070+
author: string;
1071+
/** Invocation ID of the agent engine. */
1072+
invocationId: string;
1073+
/** Timestamp indicating when the event was created. */
1074+
timestamp: string;
1075+
config?: AppendAgentEngineSessionEventConfig;
1076+
}
1077+
1078+
/** Response for appending agent engine session event. */
1079+
export class AppendAgentEngineSessionEventResponse {}
1080+
1081+
/** Config for listing agent engine session events. */
1082+
export declare interface ListAgentEngineSessionEventsConfig {
1083+
/** Used to override HTTP request options. */
1084+
httpOptions?: genaiTypes.HttpOptions;
1085+
/** Abort signal which can be used to cancel the request.
1086+
1087+
NOTE: AbortSignal is a client-only operation. Using it to cancel an
1088+
operation will not cancel the request in the service. You will still
1089+
be charged usage for any applicable operations.
1090+
*/
1091+
abortSignal?: AbortSignal;
1092+
pageSize?: number;
1093+
pageToken?: string;
1094+
/** An expression for filtering the results of the request.
1095+
For field names both snake_case and camelCase are supported. */
1096+
filter?: string;
1097+
}
1098+
1099+
/** Parameters for listing agent engine session events. */
1100+
export declare interface ListAgentEngineSessionEventsRequestParameters {
1101+
/** Name of the agent engine session. */
1102+
name: string;
1103+
config?: ListAgentEngineSessionEventsConfig;
1104+
}
1105+
1106+
/** A session event. */
1107+
export declare interface SessionEvent {
1108+
/** Optional. Content of the event provided by the author. */
1109+
content?: genaiTypes.Content;
1110+
/** Optional. Actions executed by the agent. */
1111+
actions?: EventActions;
1112+
/** Required. The name of the agent that sent the event, or user. */
1113+
author?: string;
1114+
/** Optional. Error code if the response is an error. Code varies by model. */
1115+
errorCode?: string;
1116+
/** Optional. Error message if the response is an error. */
1117+
errorMessage?: string;
1118+
/** Optional. Metadata relating to this event. */
1119+
eventMetadata?: EventMetadata;
1120+
/** Required. The invocation id of the event, multiple events can have the same invocation id. */
1121+
invocationId?: string;
1122+
/** Identifier. The resource name of the event. Format:`projects/{project}/locations/{location}/reasoningEngines/{reasoning_engine}/sessions/{session}/events/{event}`. */
1123+
name?: string;
1124+
/** Required. Timestamp when the event was created on client side. */
1125+
timestamp?: string;
1126+
}
1127+
1128+
/** Response for listing agent engine session events. */
1129+
export class ListAgentEngineSessionEventsResponse {
1130+
/** Used to retain the full HTTP response. */
1131+
sdkHttpResponse?: genaiTypes.HttpResponse;
1132+
nextPageToken?: string;
1133+
/** List of session events. */
1134+
sessionEvents?: SessionEvent[];
1135+
}
1136+
10081137
/** An agent engine instance. */
10091138
export declare interface AgentEngine {
10101139
/** The underlying API client. */

0 commit comments

Comments
 (0)