mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-23 00:41:40 +00:00
fix: target /v2/ agent-session API
This commit is contained in:
parent
49e30b020d
commit
1a9fbc63e6
5 changed files with 22 additions and 22 deletions
|
|
@ -33,7 +33,7 @@ export class AgentHandle {
|
|||
async createSession(options: CreateSessionOptions = {}): Promise<SessionHandle> {
|
||||
const info = await requestJson<SessionInfo>(this._client, {
|
||||
method: "POST",
|
||||
path: `/v1/agents/${encodeURIComponent(this.id)}/sessions`,
|
||||
path: `/v2/agents/${encodeURIComponent(this.id)}/sessions`,
|
||||
body: {
|
||||
repos: options.repos ?? [],
|
||||
envVars: options.envVars ?? {},
|
||||
|
|
@ -47,7 +47,7 @@ export class AgentHandle {
|
|||
async getSession(sessionId: string): Promise<SessionHandle> {
|
||||
const info = await requestJson<SessionInfo>(this._client, {
|
||||
method: "GET",
|
||||
path: `/v1/agents/${encodeURIComponent(this.id)}/sessions/${encodeURIComponent(sessionId)}`,
|
||||
path: `/v2/agents/${encodeURIComponent(this.id)}/sessions/${encodeURIComponent(sessionId)}`,
|
||||
});
|
||||
return new SessionHandle(info, this._client);
|
||||
}
|
||||
|
|
@ -58,7 +58,7 @@ export class AgentHandle {
|
|||
this._client,
|
||||
{
|
||||
method: "GET",
|
||||
path: `/v1/agents/${encodeURIComponent(this.id)}/sessions`,
|
||||
path: `/v2/agents/${encodeURIComponent(this.id)}/sessions`,
|
||||
query: { limit: options.limit, cursor: options.cursor },
|
||||
}
|
||||
);
|
||||
|
|
@ -69,7 +69,7 @@ export class AgentHandle {
|
|||
async update(patch: Partial<AgentCreateOptions>): Promise<void> {
|
||||
await requestJson<void>(this._client, {
|
||||
method: "PATCH",
|
||||
path: `/v1/agents/${encodeURIComponent(this.id)}`,
|
||||
path: `/v2/agents/${encodeURIComponent(this.id)}`,
|
||||
body: stripClientOptions(patch),
|
||||
});
|
||||
}
|
||||
|
|
@ -78,7 +78,7 @@ export class AgentHandle {
|
|||
async delete(): Promise<void> {
|
||||
await requestJson<void>(this._client, {
|
||||
method: "DELETE",
|
||||
path: `/v1/agents/${encodeURIComponent(this.id)}`,
|
||||
path: `/v2/agents/${encodeURIComponent(this.id)}`,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -89,7 +89,7 @@ export class Agent {
|
|||
const client = resolveClient(options);
|
||||
const info = await requestJson<AgentInfo>(client, {
|
||||
method: "POST",
|
||||
path: "/v1/agents",
|
||||
path: "/v2/agents",
|
||||
body: stripClientOptions(options),
|
||||
});
|
||||
return new AgentHandle(info, client);
|
||||
|
|
@ -100,7 +100,7 @@ export class Agent {
|
|||
const client = resolveClient(options);
|
||||
const info = await requestJson<AgentInfo>(client, {
|
||||
method: "GET",
|
||||
path: `/v1/agents/${encodeURIComponent(agentId)}`,
|
||||
path: `/v2/agents/${encodeURIComponent(agentId)}`,
|
||||
});
|
||||
return new AgentHandle(info, client);
|
||||
}
|
||||
|
|
@ -114,7 +114,7 @@ export class Agent {
|
|||
client,
|
||||
{
|
||||
method: "GET",
|
||||
path: "/v1/agents",
|
||||
path: "/v2/agents",
|
||||
query: { limit: options.limit, cursor: options.cursor },
|
||||
}
|
||||
);
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ export interface StreamRunOptions {
|
|||
}
|
||||
|
||||
/**
|
||||
* Stream events from `GET /v1/sessions/{sid}/runs/{rid}/events`.
|
||||
* Stream events from `GET /v2/sessions/{sid}/runs/{rid}/events`.
|
||||
*
|
||||
* Resume contract:
|
||||
* - On every event, we record `seq`.
|
||||
|
|
@ -41,7 +41,7 @@ export async function* streamRunEvents(
|
|||
try {
|
||||
res = await request(client, {
|
||||
method: "GET",
|
||||
path: `/v1/sessions/${encodeURIComponent(sessionId)}/runs/${encodeURIComponent(runId)}/events`,
|
||||
path: `/v2/sessions/${encodeURIComponent(sessionId)}/runs/${encodeURIComponent(runId)}/events`,
|
||||
query: startingSeq !== undefined ? { starting_seq: startingSeq } : undefined,
|
||||
headers:
|
||||
startingSeq !== undefined
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ export class Run {
|
|||
while (!TERMINAL_STATES.includes(this._status)) {
|
||||
const info = await requestJson<RunInfo>(this._client, {
|
||||
method: "GET",
|
||||
path: `/v1/sessions/${encodeURIComponent(this.sessionId)}/runs/${encodeURIComponent(this.id)}`,
|
||||
path: `/v2/sessions/${encodeURIComponent(this.sessionId)}/runs/${encodeURIComponent(this.id)}`,
|
||||
});
|
||||
this._status = info.status;
|
||||
this._result = info.result;
|
||||
|
|
@ -76,7 +76,7 @@ export class Run {
|
|||
async conversation(): Promise<ConversationTurn[]> {
|
||||
const data = await requestJson<{ turns: ConversationTurn[] }>(this._client, {
|
||||
method: "GET",
|
||||
path: `/v1/sessions/${encodeURIComponent(this.sessionId)}/runs/${encodeURIComponent(this.id)}/conversation`,
|
||||
path: `/v2/sessions/${encodeURIComponent(this.sessionId)}/runs/${encodeURIComponent(this.id)}/conversation`,
|
||||
});
|
||||
return data.turns ?? [];
|
||||
}
|
||||
|
|
@ -86,7 +86,7 @@ export class Run {
|
|||
if (TERMINAL_STATES.includes(this._status)) return;
|
||||
await requestJson<void>(this._client, {
|
||||
method: "POST",
|
||||
path: `/v1/sessions/${encodeURIComponent(this.sessionId)}/runs/${encodeURIComponent(this.id)}/cancel`,
|
||||
path: `/v2/sessions/${encodeURIComponent(this.sessionId)}/runs/${encodeURIComponent(this.id)}/cancel`,
|
||||
});
|
||||
this._status = "cancelled";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ export class SessionHandle {
|
|||
const body = normalizeSendInput(input);
|
||||
const info = await requestJson<RunInfo>(this._client, {
|
||||
method: "POST",
|
||||
path: `/v1/sessions/${encodeURIComponent(this.id)}/runs`,
|
||||
path: `/v2/sessions/${encodeURIComponent(this.id)}/runs`,
|
||||
body,
|
||||
});
|
||||
return new Run(info, this._client);
|
||||
|
|
@ -56,7 +56,7 @@ export class SessionHandle {
|
|||
async followup(message: string): Promise<void> {
|
||||
await requestJson<void>(this._client, {
|
||||
method: "POST",
|
||||
path: `/v1/sessions/${encodeURIComponent(this.id)}/followup`,
|
||||
path: `/v2/sessions/${encodeURIComponent(this.id)}/followup`,
|
||||
body: { message },
|
||||
});
|
||||
}
|
||||
|
|
@ -65,7 +65,7 @@ export class SessionHandle {
|
|||
async getRun(runId: string): Promise<Run> {
|
||||
const info = await requestJson<RunInfo>(this._client, {
|
||||
method: "GET",
|
||||
path: `/v1/sessions/${encodeURIComponent(this.id)}/runs/${encodeURIComponent(runId)}`,
|
||||
path: `/v2/sessions/${encodeURIComponent(this.id)}/runs/${encodeURIComponent(runId)}`,
|
||||
});
|
||||
return new Run(info, this._client);
|
||||
}
|
||||
|
|
@ -76,7 +76,7 @@ export class SessionHandle {
|
|||
this._client,
|
||||
{
|
||||
method: "GET",
|
||||
path: `/v1/sessions/${encodeURIComponent(this.id)}/runs`,
|
||||
path: `/v2/sessions/${encodeURIComponent(this.id)}/runs`,
|
||||
query: { limit: options.limit, cursor: options.cursor },
|
||||
}
|
||||
);
|
||||
|
|
@ -90,7 +90,7 @@ export class SessionHandle {
|
|||
async conversation(): Promise<ConversationTurn[]> {
|
||||
const data = await requestJson<{ turns: ConversationTurn[] }>(this._client, {
|
||||
method: "GET",
|
||||
path: `/v1/sessions/${encodeURIComponent(this.id)}/conversation`,
|
||||
path: `/v2/sessions/${encodeURIComponent(this.id)}/conversation`,
|
||||
});
|
||||
return data.turns ?? [];
|
||||
}
|
||||
|
|
@ -99,7 +99,7 @@ export class SessionHandle {
|
|||
async delete(): Promise<void> {
|
||||
await requestJson<void>(this._client, {
|
||||
method: "DELETE",
|
||||
path: `/v1/sessions/${encodeURIComponent(this.id)}`,
|
||||
path: `/v2/sessions/${encodeURIComponent(this.id)}`,
|
||||
});
|
||||
this._status = "terminated";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -157,10 +157,10 @@ export class MockProxy {
|
|||
const segments = url.pathname.split("/").filter(Boolean);
|
||||
|
||||
try {
|
||||
if (segments[0] !== "v1") {
|
||||
if (segments[0] !== "v2") {
|
||||
return notFound(res);
|
||||
}
|
||||
// /v1/agents
|
||||
// /v2/agents
|
||||
if (segments.length === 2 && segments[1] === "agents") {
|
||||
if (method === "POST") return this.createAgent(req, res);
|
||||
if (method === "GET") return this.listAgents(res);
|
||||
|
|
@ -189,7 +189,7 @@ export class MockProxy {
|
|||
if (!session) return notFound(res);
|
||||
if (method === "GET") return ok(res, serializeSession(session));
|
||||
}
|
||||
// /v1/sessions/{sid}/...
|
||||
// /v2/sessions/{sid}/...
|
||||
if (segments[1] === "sessions" && segments.length >= 3) {
|
||||
const session = this.findSession(segments[2]);
|
||||
if (!session) return notFound(res);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue