Reduce server console polling load
This commit is contained in:
@@ -311,12 +311,21 @@ describe("PlatformApiClient AI providers", () => {
|
||||
if (url.endsWith("/api/v1/run/endpoints")) {
|
||||
return jsonResponse({ items: [endpoint], count: 1 });
|
||||
}
|
||||
if (url.endsWith("/api/v1/run/endpoints?status=online")) {
|
||||
return jsonResponse({ items: [endpoint], count: 1 });
|
||||
}
|
||||
if (url.endsWith("/api/v1/jobs")) {
|
||||
return jsonResponse({ items: [job], count: 1 });
|
||||
}
|
||||
if (url.endsWith("/api/v1/jobs?serverInstanceId=server-1")) {
|
||||
return jsonResponse({ items: [job], count: 1 });
|
||||
}
|
||||
if (url.endsWith("/api/v1/jobs?states=queued%2Crunning%2Cfailed")) {
|
||||
return jsonResponse({ items: [job], count: 1 });
|
||||
}
|
||||
if (url.endsWith("/api/v1/jobs?serverInstanceId=server-1&states=queued%2Crunning%2Cfailed")) {
|
||||
return jsonResponse({ items: [job], count: 1 });
|
||||
}
|
||||
if (url.endsWith("/api/v1/artifacts?ownerKind=job&ownerId=job-1&state=available")) {
|
||||
return jsonResponse({ items: [artifact], count: 1 });
|
||||
}
|
||||
@@ -571,8 +580,11 @@ describe("PlatformApiClient AI providers", () => {
|
||||
await expect(client.uploadServerFile(server.id, { directoryKey: "configs", file: new File(["server.name=Example\n"], "server.properties", { type: "text/plain" }), idempotencyKey: "idem-file-upload" })).resolves.toMatchObject({ inputRef: "artifact://artifact-upload-1", job: { capability: "files.write" } });
|
||||
await expect(client.prepareServerFileDownload(server.id, { key: "config/server.properties", idempotencyKey: "idem-file-download" })).resolves.toMatchObject({ status: "ready", filename: "server.properties", content: "server.name=Example\n" });
|
||||
await expect(client.listRunEndpoints()).resolves.toMatchObject({ count: 1 });
|
||||
await expect(client.listRunEndpoints({ status: "online" })).resolves.toMatchObject({ count: 1 });
|
||||
await expect(client.listJobs()).resolves.toMatchObject({ count: 1 });
|
||||
await expect(client.listJobs(server.id)).resolves.toMatchObject({ count: 1 });
|
||||
await expect(client.listJobs(undefined, { states: ["queued", "running", "failed"] })).resolves.toMatchObject({ count: 1 });
|
||||
await expect(client.listJobs(server.id, { states: ["queued", "running", "failed"] })).resolves.toMatchObject({ count: 1 });
|
||||
await expect(client.listArtifacts({ ownerKind: "job", ownerId: job.id, state: "available" })).resolves.toMatchObject({ count: 1, items: [{ id: artifact.id }] });
|
||||
await expect(client.openArtifactDownload(artifact.id)).resolves.toMatchObject({ downloadUrl: "/api/v1/artifacts/artifact-1/content", rangeSupported: true });
|
||||
await expect(client.readArtifactContent(artifact.id, 0, 8)).resolves.toMatchObject({ contentLength: 8, contentRange: "bytes 0-7/18", checksum: artifact.checksum });
|
||||
@@ -613,7 +625,7 @@ describe("PlatformApiClient AI providers", () => {
|
||||
client.invokeAI({ requestId: "ai-1", serverInstanceId: server.id, purpose: "config.suggest", prompt: "Tune PVP safely", currentConfig: "server.name=Example Survival #1\n" })
|
||||
).resolves.toMatchObject({ status: "ok", usage: { mocked: true }, configRecommendation: { diffSummary: "review required" } });
|
||||
|
||||
expect(fetchMock).toHaveBeenCalledTimes(43);
|
||||
expect(fetchMock).toHaveBeenCalledTimes(46);
|
||||
});
|
||||
|
||||
it("normalizes server file workspace null arrays from older platform responses", async () => {
|
||||
|
||||
@@ -37,6 +37,7 @@ import type {
|
||||
JobCreateRequest,
|
||||
JobListResponse,
|
||||
JobResponse,
|
||||
JobState,
|
||||
LlmConfigSuggestionRequest,
|
||||
LlmConfigSuggestionResponse,
|
||||
LogStreamCursorRequest,
|
||||
@@ -59,6 +60,7 @@ import type {
|
||||
RunDistributionGenerateRequest,
|
||||
RunDistributionResponse,
|
||||
RunEndpointListResponse,
|
||||
RunEndpointStatus,
|
||||
RunUpdateJobResponse,
|
||||
RunUpdateJobListResponse,
|
||||
RunUpdateRequest,
|
||||
@@ -142,6 +144,16 @@ export interface PlatformEventStream {
|
||||
close(): void;
|
||||
}
|
||||
|
||||
interface RunEndpointListFilter {
|
||||
status?: RunEndpointStatus;
|
||||
}
|
||||
|
||||
interface JobListFilter {
|
||||
runEndpointId?: string;
|
||||
state?: JobState;
|
||||
states?: JobState[];
|
||||
}
|
||||
|
||||
export class PlatformApiClient {
|
||||
constructor(private readonly baseUrl = "/api/v1", private readonly sessionTokenProvider: () => string | null = () => platformApiSessionToken) {}
|
||||
|
||||
@@ -241,13 +253,12 @@ export class PlatformApiClient {
|
||||
});
|
||||
}
|
||||
|
||||
async listRunEndpoints(): Promise<RunEndpointListResponse> {
|
||||
return this.request<RunEndpointListResponse>("/run/endpoints");
|
||||
async listRunEndpoints(filter: RunEndpointListFilter = {}): Promise<RunEndpointListResponse> {
|
||||
return this.request<RunEndpointListResponse>(`/run/endpoints${runEndpointQuery(filter)}`);
|
||||
}
|
||||
|
||||
async listJobs(serverInstanceId?: string): Promise<JobListResponse> {
|
||||
const params = serverInstanceId ? `?serverInstanceId=${encodeURIComponent(serverInstanceId)}` : "";
|
||||
return this.request<JobListResponse>(`/jobs${params}`);
|
||||
async listJobs(serverInstanceId?: string, filter: JobListFilter = {}): Promise<JobListResponse> {
|
||||
return this.request<JobListResponse>(`/jobs${jobListQuery(serverInstanceId, filter)}`);
|
||||
}
|
||||
|
||||
async listArtifacts(filter: ArtifactFilterRequest = {}): Promise<ArtifactListResponse> {
|
||||
@@ -901,6 +912,23 @@ function artifactQuery(filter: ArtifactFilterRequest): string {
|
||||
return query ? `?${query}` : "";
|
||||
}
|
||||
|
||||
function runEndpointQuery(filter: RunEndpointListFilter): string {
|
||||
const params = new URLSearchParams();
|
||||
if (filter.status) params.set("status", filter.status);
|
||||
const query = params.toString();
|
||||
return query ? `?${query}` : "";
|
||||
}
|
||||
|
||||
function jobListQuery(serverInstanceId: string | undefined, filter: JobListFilter): string {
|
||||
const params = new URLSearchParams();
|
||||
if (serverInstanceId) params.set("serverInstanceId", serverInstanceId);
|
||||
if (filter.runEndpointId) params.set("runEndpointId", filter.runEndpointId);
|
||||
if (filter.state) params.set("state", filter.state);
|
||||
if (filter.states?.length) params.set("states", filter.states.join(","));
|
||||
const query = params.toString();
|
||||
return query ? `?${query}` : "";
|
||||
}
|
||||
|
||||
function serverFileListQuery(request: Partial<ServerFileListRequest>): string {
|
||||
const params = new URLSearchParams();
|
||||
if (request.directoryKey) params.set("directoryKey", request.directoryKey);
|
||||
|
||||
Reference in New Issue
Block a user