Skip to content

Commit 956f5db

Browse files
MarkDaoustcopybara-github
authored andcommitted
feat: implement listInteractions for Vertex.
PiperOrigin-RevId: 960446774
1 parent dec2d3c commit 956f5db

11 files changed

Lines changed: 427 additions & 0 deletions

File tree

sdk-samples/interactions_list.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/**
2+
* @license
3+
* Copyright 2026 Google LLC
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
import {GoogleGenAI} from '@google/genai';
7+
8+
const GOOGLE_GENAI_USE_VERTEXAI = process.env.GOOGLE_GENAI_USE_VERTEXAI;
9+
10+
async function listInteractionsFromVertexAI() {
11+
const ai = new GoogleGenAI({});
12+
console.log('Calling interactions.list()...');
13+
const response = await ai.interactions.list();
14+
const interactions =
15+
'interaction_metadatas' in response && response.interaction_metadatas
16+
? response.interaction_metadatas
17+
: [];
18+
console.log(`Found ${interactions.length} interaction(s):`);
19+
for (const item of interactions) {
20+
console.log(
21+
`- ID: ${item.id}, Status: ${item.status}, Created: ${item.created}`,
22+
);
23+
}
24+
}
25+
26+
async function main() {
27+
if (
28+
!GOOGLE_GENAI_USE_VERTEXAI ||
29+
GOOGLE_GENAI_USE_VERTEXAI.toLowerCase() !== 'true'
30+
) {
31+
console.log(
32+
'Interactions list is only supported on Vertex AI. ' +
33+
'Please set GOOGLE_GENAI_USE_VERTEXAI=true.',
34+
);
35+
return;
36+
}
37+
38+
try {
39+
await listInteractionsFromVertexAI();
40+
} catch (e) {
41+
console.error('Failed:', e);
42+
}
43+
}
44+
45+
main();
Lines changed: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
/**
2+
* @license
3+
* Copyright 2026 Google LLC
4+
* SPDX-License-Identifier: Apache-2.0
5+
*
6+
* g3-prettier-ignore-file
7+
*/
8+
9+
/*
10+
* Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
11+
*/
12+
13+
import { GoogleGenAICore } from "../core.js";
14+
import { encodeFormQuery, encodeSimple } from "../lib/encodings.js";
15+
import { matchStatusCode } from "../lib/http.js";
16+
import * as M from "../lib/matchers.js";
17+
import { compactMap } from "../lib/primitives.js";
18+
import { RequestOptions } from "../lib/sdks.js";
19+
import { extractSecurity, resolveGlobalSecurity } from "../lib/security.js";
20+
import { pathToFunc } from "../lib/url.js";
21+
import { GoogleGenAiError } from "../models/errors/google-gen-ai-error.js";
22+
import {
23+
ConnectionError,
24+
InvalidRequestError,
25+
RequestAbortedError,
26+
RequestTimeoutError,
27+
UnexpectedClientError,
28+
} from "../models/errors/http-client-errors.js";
29+
import * as operations from "../models/operations/index.js";
30+
import { APICall, APIPromise } from "../types/async.js";
31+
import { Result } from "../types/fp.js";
32+
33+
/**
34+
* List interactions.
35+
*/
36+
export function interactionsList(
37+
client: GoogleGenAICore,
38+
page_size?: number | undefined,
39+
page_token?: string | undefined,
40+
api_version?: string | undefined,
41+
options?: Omit<RequestOptions, "extra_body">,
42+
): APIPromise<
43+
Result<
44+
operations.ListInteractionsResponse,
45+
| GoogleGenAiError
46+
| ConnectionError
47+
| RequestAbortedError
48+
| RequestTimeoutError
49+
| InvalidRequestError
50+
| UnexpectedClientError
51+
>
52+
> {
53+
return new APIPromise($do(
54+
client,
55+
page_size,
56+
page_token,
57+
api_version,
58+
options,
59+
));
60+
}
61+
62+
async function $do(
63+
client: GoogleGenAICore,
64+
page_size?: number | undefined,
65+
page_token?: string | undefined,
66+
api_version?: string | undefined,
67+
options?: Omit<RequestOptions, "extra_body">,
68+
): Promise<
69+
[
70+
Result<
71+
operations.ListInteractionsResponse,
72+
| GoogleGenAiError
73+
| ConnectionError
74+
| RequestAbortedError
75+
| RequestTimeoutError
76+
| InvalidRequestError
77+
| UnexpectedClientError
78+
>,
79+
APICall,
80+
]
81+
> {
82+
const input: operations.ListInteractionsRequest | undefined = {
83+
page_size: page_size,
84+
page_token: page_token,
85+
api_version: api_version,
86+
};
87+
88+
const payload = input;
89+
const body = null;
90+
91+
const pathParams = {
92+
api_version: encodeSimple(
93+
"api_version",
94+
payload?.api_version ?? client._options.api_version,
95+
{ explode: false, charEncoding: "percent" },
96+
),
97+
};
98+
const path = pathToFunc("/{api_version}/interactions:list")(pathParams);
99+
100+
const query = encodeFormQuery({
101+
"page_size": payload?.page_size,
102+
"page_token": payload?.page_token,
103+
});
104+
105+
const headers = new Headers(compactMap({
106+
Accept: "application/json",
107+
}));
108+
109+
const securityInput = await extractSecurity(client._options.security);
110+
const requestSecurity = resolveGlobalSecurity(securityInput);
111+
112+
const context = {
113+
options: client._options,
114+
base_url: options?.server_url ?? client._baseURL ?? "",
115+
operation_id: "listInteractions",
116+
o_auth2_scopes: null,
117+
118+
resolved_security: requestSecurity,
119+
120+
security_source: client._options.security,
121+
retry_config: options?.retries
122+
|| client._options.retry_config
123+
|| {
124+
strategy: "attempt-count-backoff",
125+
backoff: {
126+
initialInterval: 500,
127+
maxInterval: 8000,
128+
exponent: 2,
129+
maxElapsedTime: 30000,
130+
},
131+
retryConnectionErrors: true,
132+
maxRetries: 4,
133+
}
134+
|| { strategy: "none" },
135+
retry_codes: options?.retry_codes || ["408", "409", "429", "5XX"],
136+
};
137+
138+
const requestRes = client._createRequest(context, {
139+
security: requestSecurity,
140+
method: "GET",
141+
baseURL: options?.server_url,
142+
path: path,
143+
headers: headers,
144+
query: query,
145+
body: body,
146+
userAgent: client._options.user_agent,
147+
timeout_ms: options?.timeout_ms || client._options.timeout_ms || -1,
148+
}, options);
149+
if (!requestRes.ok) {
150+
return [requestRes, { status: "invalid" }];
151+
}
152+
const req = requestRes.value;
153+
154+
const doResult = await client._do(req, {
155+
context,
156+
isErrorStatusCode: (statusCode: number) =>
157+
matchStatusCode({ status: statusCode } as Response, ["4XX", "5XX"]),
158+
retryConfig: context.retry_config,
159+
retryCodes: context.retry_codes,
160+
});
161+
if (!doResult.ok) {
162+
return [doResult, { status: "request-error", request: req }];
163+
}
164+
const response = doResult.value;
165+
166+
const [result] = await M.match<
167+
operations.ListInteractionsResponse,
168+
| GoogleGenAiError
169+
| ConnectionError
170+
| RequestAbortedError
171+
| RequestTimeoutError
172+
| InvalidRequestError
173+
| UnexpectedClientError
174+
>(
175+
M.json<operations.ListInteractionsResponse>(200),
176+
M.fail("4XX"),
177+
M.fail("5XX"),
178+
M.json<operations.ListInteractionsResponse>("default"),
179+
)(response, req);
180+
if (!result.ok) {
181+
return [result, { status: "complete", request: req, response }];
182+
}
183+
184+
return [result, { status: "complete", request: req, response }];
185+
}

src/gaos/google-genai.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ import { agentsList } from "./funcs/agents-list.js";
5353
import { interactionsCancel } from "./funcs/interactions-cancel.js";
5454
import { interactionsCreate } from "./funcs/interactions-create.js";
5555
import { interactionsGet } from "./funcs/interactions-get.js";
56+
import { interactionsList } from "./funcs/interactions-list.js";
5657
import { triggersCreate } from "./funcs/triggers-create.js";
5758
import { triggersDelete } from "./funcs/triggers-delete.js";
5859
import { triggersGet } from "./funcs/triggers-get.js";
@@ -181,6 +182,12 @@ export type InteractionGetParamsNonStreaming =
181182

182183
export type InteractionGetParamsStreaming = GetInteractionByIdParamsStreaming;
183184

185+
export type ListInteractionsParams = {
186+
api_version?: string;
187+
page_size?: number;
188+
page_token?: string;
189+
};
190+
184191
export type ListAgentsParams = {
185192
api_version?: string;
186193
pageSize?: number;
@@ -342,6 +349,22 @@ export class GeminiNextGenInteractions {
342349
return addOutputPropertiesIfInteraction(response) as GoogleGenAIInteraction;
343350
}
344351

352+
async list(
353+
params: ListInteractionsParams | null | undefined = {},
354+
options?: GoogleGenAIRequestOptions,
355+
): Promise<operations.ListInteractionsResponse> {
356+
const { api_version, page_size, page_token } = params ?? {};
357+
return unwrapWithSdkHttpResponse(
358+
interactionsList(
359+
this.getClient(api_version),
360+
page_size,
361+
page_token,
362+
api_version,
363+
toGoogleGenAIRequestOptions(options),
364+
),
365+
);
366+
}
367+
345368
async delete(
346369
id: string,
347370
params: { api_version?: string } | null | undefined = {},

src/gaos/models/interactions/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,14 @@ export * from "./image-delta.js";
8181
export * from "./image-response-format.js";
8282
export * from "./interaction-completed-event.js";
8383
export * from "./interaction-created-event.js";
84+
export * from "./interaction-metadata.js";
8485
export * from "./interaction-sse-event-interaction.js";
8586
export * from "./interaction-sse-event.js";
8687
export * from "./interaction-sse-stream-event.js";
8788
export * from "./interaction-status-update.js";
8889
export * from "./interaction.js";
8990
export * from "./interactions-input.js";
91+
export * from "./list-interactions-response.js";
9092
export * from "./mcp-server-tool-call-delta.js";
9193
export * from "./mcp-server-tool-call-step.js";
9294
export * from "./mcp-server-tool-result-delta.js";
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/**
2+
* @license
3+
* Copyright 2026 Google LLC
4+
* SPDX-License-Identifier: Apache-2.0
5+
*
6+
* g3-prettier-ignore-file
7+
*/
8+
9+
/*
10+
* Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
11+
*/
12+
13+
/**
14+
* Output only. The status of the interaction.
15+
*/
16+
export type InteractionMetadataStatus =
17+
| "in_progress"
18+
| "requires_action"
19+
| "completed"
20+
| "failed"
21+
| "cancelled"
22+
| "incomplete"
23+
| "budget_exceeded"
24+
| "queued"
25+
| (string & {});
26+
27+
/**
28+
* Metadata for an interaction, used for listing interactions.
29+
*/
30+
export type InteractionMetadata = {
31+
/**
32+
* Output only. The time at which the response was created in ISO 8601 format
33+
*
34+
* @remarks
35+
* (YYYY-MM-DDThh:mm:ssZ).
36+
*/
37+
created?: string | undefined;
38+
/**
39+
* Output only. A unique identifier for the interaction completion.
40+
*/
41+
id?: string | undefined;
42+
/**
43+
* Output only. The status of the interaction.
44+
*/
45+
status?: InteractionMetadataStatus | undefined;
46+
/**
47+
* Output only. The time at which the response was last updated in ISO 8601 format
48+
*
49+
* @remarks
50+
* (YYYY-MM-DDThh:mm:ssZ).
51+
*/
52+
updated?: string | undefined;
53+
};
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* @license
3+
* Copyright 2026 Google LLC
4+
* SPDX-License-Identifier: Apache-2.0
5+
*
6+
* g3-prettier-ignore-file
7+
*/
8+
9+
/*
10+
* Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
11+
*/
12+
13+
import { InteractionMetadata } from "./interaction-metadata.js";
14+
15+
export type ListInteractionsResponse = {
16+
/**
17+
* The `InteractionMetadata` from the specified collection.
18+
*/
19+
interaction_metadatas?: Array<InteractionMetadata> | undefined;
20+
/**
21+
* A token, which can be sent as `page_token` to retrieve the next page.
22+
*
23+
* @remarks
24+
* If this field is omitted, there are no subsequent pages.
25+
*/
26+
next_page_token?: string | undefined;
27+
};

src/gaos/models/operations/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export * from "./get-trigger.js";
2828
export * from "./get-webhook.js";
2929
export * from "./list-agents.js";
3030
export * from "./list-environments.js";
31+
export * from "./list-interactions.js";
3132
export * from "./list-trigger-executions.js";
3233
export * from "./list-triggers.js";
3334
export * from "./list-webhooks.js";

0 commit comments

Comments
 (0)