Skip to content

Commit 78cc8b8

Browse files
feat: Make conversation/session redirects public
1 parent 70285d6 commit 78cc8b8

9 files changed

Lines changed: 110 additions & 6 deletions

File tree

.stats.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
configured_endpoints: 21
1+
configured_endpoints: 22
22
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/warp-bnavetta%2Fwarp-api-348bf98eecccd80255fdcee166b5eb385d8d9743811d080f94a1ec33337abc48.yml
3-
openapi_spec_hash: 5da1dccadb70219c6dfdda1a440b9ad2
4-
config_hash: b893614299dd99b07446072ade3737d1
3+
openapi_spec_hash: 1952fae99172f1adaf35d800b0d63936
4+
config_hash: 44a1e8f98607a5cf03815a63bae63453

api.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,13 @@ Types:
8989
Methods:
9090

9191
- <code title="get /agent/sessions/{sessionUuid}/redirect">client.agent.sessions.<a href="./src/resources/agent/sessions.ts">checkRedirect</a>(sessionUuid) -> SessionCheckRedirectResponse</code>
92+
93+
## Conversations
94+
95+
Types:
96+
97+
- <code><a href="./src/resources/agent/conversations.ts">ConversationCheckRedirectResponse</a></code>
98+
99+
Methods:
100+
101+
- <code title="get /agent/conversations/{conversationId}/redirect">client.agent.conversations.<a href="./src/resources/agent/conversations.ts">checkRedirect</a>(conversationID) -> ConversationCheckRedirectResponse</code>

src/client.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,14 @@ export class OzAPI {
242242
return;
243243
}
244244

245-
protected async authHeaders(opts: FinalRequestOptions): Promise<NullableHeaders | undefined> {
245+
protected async authHeaders(
246+
opts: FinalRequestOptions,
247+
schemes: { bearerAuth?: boolean },
248+
): Promise<NullableHeaders | undefined> {
249+
return buildHeaders([schemes.bearerAuth ? await this.bearerAuth(opts) : null]);
250+
}
251+
252+
protected async bearerAuth(opts: FinalRequestOptions): Promise<NullableHeaders | undefined> {
246253
return buildHeaders([{ Authorization: `Bearer ${this.apiKey}` }]);
247254
}
248255

@@ -693,7 +700,7 @@ export class OzAPI {
693700
...(options.timeout ? { 'X-Stainless-Timeout': String(Math.trunc(options.timeout / 1000)) } : {}),
694701
...getPlatformHeaders(),
695702
},
696-
await this.authHeaders(options),
703+
await this.authHeaders(options, options.__security ?? { bearerAuth: true }),
697704
this._options.defaultHeaders,
698705
bodyHeaders,
699706
options.headers,

src/internal/request-options.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ export type RequestOptions = {
7575
*/
7676
defaultBaseURL?: string | undefined;
7777

78+
__security?: { bearerAuth?: boolean };
79+
7880
__binaryResponse?: boolean | undefined;
7981
};
8082

src/resources/agent/agent.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import {
1212
ListAgentIdentitiesResponse,
1313
UpdateAgentRequest,
1414
} from './agent_';
15+
import * as ConversationsAPI from './conversations';
16+
import { ConversationCheckRedirectResponse, Conversations } from './conversations';
1517
import * as RunsAPI from './runs';
1618
import {
1719
ArtifactItem,
@@ -50,6 +52,7 @@ export class Agent extends APIResource {
5052
schedules: SchedulesAPI.Schedules = new SchedulesAPI.Schedules(this._client);
5153
agent: AgentAgentAPI.Agent = new AgentAgentAPI.Agent(this._client);
5254
sessions: SessionsAPI.Sessions = new SessionsAPI.Sessions(this._client);
55+
conversations: ConversationsAPI.Conversations = new ConversationsAPI.Conversations(this._client);
5356

5457
/**
5558
* Retrieve a list of available agents (skills) that can be used to run tasks.
@@ -1067,6 +1070,7 @@ Agent.Runs = Runs;
10671070
Agent.Schedules = Schedules;
10681071
Agent.Agent = AgentAPIAgent;
10691072
Agent.Sessions = Sessions;
1073+
Agent.Conversations = Conversations;
10701074

10711075
export declare namespace Agent {
10721076
export {
@@ -1125,4 +1129,9 @@ export declare namespace Agent {
11251129
};
11261130

11271131
export { Sessions as Sessions, type SessionCheckRedirectResponse as SessionCheckRedirectResponse };
1132+
1133+
export {
1134+
Conversations as Conversations,
1135+
type ConversationCheckRedirectResponse as ConversationCheckRedirectResponse,
1136+
};
11281137
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2+
3+
import { APIResource } from '../../core/resource';
4+
import { APIPromise } from '../../core/api-promise';
5+
import { RequestOptions } from '../../internal/request-options';
6+
import { path } from '../../internal/utils/path';
7+
8+
/**
9+
* Operations for running and managing cloud agents
10+
*/
11+
export class Conversations extends APIResource {
12+
/**
13+
* Check whether a conversation should redirect to a live shared session. Returns a
14+
* session_id if the underlying ambient agent task still has a live shared session,
15+
* or an empty object if no redirect is needed.
16+
*
17+
* This endpoint is public (no authentication required) so that anonymous viewers
18+
* can resolve a publicly-shared conversation link before signing in. Access to the
19+
* underlying live session is still gated by the session-sharing service ACLs.
20+
*
21+
* @example
22+
* ```ts
23+
* const response =
24+
* await client.agent.conversations.checkRedirect(
25+
* 'conversationId',
26+
* );
27+
* ```
28+
*/
29+
checkRedirect(
30+
conversationID: string,
31+
options?: RequestOptions,
32+
): APIPromise<ConversationCheckRedirectResponse> {
33+
return this._client.get(path`/agent/conversations/${conversationID}/redirect`, {
34+
...options,
35+
__security: {},
36+
});
37+
}
38+
}
39+
40+
export interface ConversationCheckRedirectResponse {
41+
/**
42+
* The shared session UUID to redirect to (only present when redirect is needed)
43+
*/
44+
session_id?: string;
45+
}
46+
47+
export declare namespace Conversations {
48+
export { type ConversationCheckRedirectResponse as ConversationCheckRedirectResponse };
49+
}

src/resources/agent/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export {
2121
type AgentListEnvironmentsParams,
2222
type AgentRunParams,
2323
} from './agent';
24+
export { Conversations, type ConversationCheckRedirectResponse } from './conversations';
2425
export {
2526
Runs,
2627
type ArtifactItem,

src/resources/agent/sessions.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ export class Sessions extends APIResource {
1414
* Returns a conversation_id if the agent sandbox has finished and conversation
1515
* data is available, or an empty object if no redirect is needed.
1616
*
17+
* This endpoint is public (no authentication required) so that anonymous viewers
18+
* can resolve a publicly-shared session link before signing in. Access to the
19+
* underlying conversation transcript is still gated by conversation link-sharing.
20+
*
1721
* @example
1822
* ```ts
1923
* const response = await client.agent.sessions.checkRedirect(
@@ -22,7 +26,7 @@ export class Sessions extends APIResource {
2226
* ```
2327
*/
2428
checkRedirect(sessionUuid: string, options?: RequestOptions): APIPromise<SessionCheckRedirectResponse> {
25-
return this._client.get(path`/agent/sessions/${sessionUuid}/redirect`, options);
29+
return this._client.get(path`/agent/sessions/${sessionUuid}/redirect`, { ...options, __security: {} });
2630
}
2731
}
2832

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2+
3+
import OzAPI from 'oz-agent-sdk';
4+
5+
const client = new OzAPI({
6+
apiKey: 'My API Key',
7+
baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',
8+
});
9+
10+
describe('resource conversations', () => {
11+
// Mock server tests are disabled
12+
test.skip('checkRedirect', async () => {
13+
const responsePromise = client.agent.conversations.checkRedirect('conversationId');
14+
const rawResponse = await responsePromise.asResponse();
15+
expect(rawResponse).toBeInstanceOf(Response);
16+
const response = await responsePromise;
17+
expect(response).not.toBeInstanceOf(Response);
18+
const dataAndResponse = await responsePromise.withResponse();
19+
expect(dataAndResponse.data).toBe(response);
20+
expect(dataAndResponse.response).toBe(rawResponse);
21+
});
22+
});

0 commit comments

Comments
 (0)