Skip to content

Commit 9d2c794

Browse files
fix: name sparsekernel request schemas
1 parent 030228a commit 9d2c794

3 files changed

Lines changed: 94 additions & 40 deletions

File tree

packages/sparsekernel-client/src/index.ts

Lines changed: 49 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,11 @@ export type SparseKernelAppendTranscriptEventInput = {
149149
created_at?: string | null;
150150
};
151151

152+
export type SparseKernelListTranscriptEventsInput = {
153+
session_id: string;
154+
limit?: number;
155+
};
156+
152157
export type SparseKernelToolCall = {
153158
id: string;
154159
task_id?: string | null;
@@ -300,6 +305,10 @@ export type SparseKernelAcquireBrowserContextInput = {
300305
allowed_origins?: unknown;
301306
};
302307

308+
export type SparseKernelReleaseBrowserContextInput = {
309+
context_id: string;
310+
};
311+
303312
export type SparseKernelBrowserObservationInput = {
304313
context_id: string;
305314
target_id?: string | null;
@@ -425,6 +434,10 @@ export type SparseKernelAllocateSandboxInput = {
425434
max_bytes_out?: number | null;
426435
};
427436

437+
export type SparseKernelReleaseSandboxInput = {
438+
allocation_id: string;
439+
};
440+
428441
export type SparseKernelCreateToolCallInput = {
429442
id?: string;
430443
task_id?: string | null;
@@ -440,6 +453,15 @@ export type SparseKernelCompleteToolCallInput = {
440453
artifact_ids?: string[];
441454
};
442455

456+
export type SparseKernelToolCallIdInput = {
457+
id: string;
458+
};
459+
460+
export type SparseKernelFailToolCallInput = {
461+
id: string;
462+
error: string;
463+
};
464+
443465
export type SparseKernelCapability = {
444466
id: string;
445467
subject_type: string;
@@ -472,6 +494,15 @@ export type SparseKernelCapabilityCheckInput = {
472494
audit_denied?: boolean;
473495
};
474496

497+
export type SparseKernelCapabilityIdInput = {
498+
id: string;
499+
};
500+
501+
export type SparseKernelListCapabilitiesInput = {
502+
subject_type: string;
503+
subject_id: string;
504+
};
505+
475506
function protocolMajor(version: string): string {
476507
const trimmed = version.trim();
477508
const match = /(?:^|[._-])v?(\d+)$/i.exec(trimmed);
@@ -578,10 +609,9 @@ export class SparseKernelClient {
578609
return await this.postJson<SparseKernelTranscriptEvent>("/transcript-events/append", input);
579610
}
580611

581-
async transcriptEvents(input: {
582-
session_id: string;
583-
limit?: number;
584-
}): Promise<SparseKernelTranscriptEvent[]> {
612+
async transcriptEvents(
613+
input: SparseKernelListTranscriptEventsInput,
614+
): Promise<SparseKernelTranscriptEvent[]> {
585615
return await this.postJson<SparseKernelTranscriptEvent[]>("/transcript-events/list", input);
586616
}
587617

@@ -643,9 +673,10 @@ export class SparseKernelClient {
643673
}
644674

645675
async releaseBrowserContext(contextId: string): Promise<boolean> {
646-
const response = await this.postJson<{ released: boolean }>("/browser/contexts/release", {
676+
const input: SparseKernelReleaseBrowserContextInput = {
647677
context_id: contextId,
648-
});
678+
};
679+
const response = await this.postJson<{ released: boolean }>("/browser/contexts/release", input);
649680
return response.released;
650681
}
651682

@@ -723,9 +754,10 @@ export class SparseKernelClient {
723754
}
724755

725756
async releaseSandbox(allocationId: string): Promise<boolean> {
726-
const response = await this.postJson<{ released: boolean }>("/sandbox/release", {
757+
const input: SparseKernelReleaseSandboxInput = {
727758
allocation_id: allocationId,
728-
});
759+
};
760+
const response = await this.postJson<{ released: boolean }>("/sandbox/release", input);
729761
return response.released;
730762
}
731763

@@ -738,15 +770,17 @@ export class SparseKernelClient {
738770
}
739771

740772
async startToolCall(id: string): Promise<SparseKernelToolCall> {
741-
return await this.postJson<SparseKernelToolCall>("/tool-calls/start", { id });
773+
const input: SparseKernelToolCallIdInput = { id };
774+
return await this.postJson<SparseKernelToolCall>("/tool-calls/start", input);
742775
}
743776

744777
async completeToolCall(input: SparseKernelCompleteToolCallInput): Promise<SparseKernelToolCall> {
745778
return await this.postJson<SparseKernelToolCall>("/tool-calls/complete", input);
746779
}
747780

748781
async failToolCall(id: string, error: string): Promise<SparseKernelToolCall> {
749-
return await this.postJson<SparseKernelToolCall>("/tool-calls/fail", { id, error });
782+
const input: SparseKernelFailToolCallInput = { id, error };
783+
return await this.postJson<SparseKernelToolCall>("/tool-calls/fail", input);
750784
}
751785

752786
async grantCapability(input: SparseKernelGrantCapabilityInput): Promise<SparseKernelCapability> {
@@ -759,14 +793,14 @@ export class SparseKernelClient {
759793
}
760794

761795
async revokeCapability(id: string): Promise<boolean> {
762-
const response = await this.postJson<{ revoked: boolean }>("/capabilities/revoke", { id });
796+
const input: SparseKernelCapabilityIdInput = { id };
797+
const response = await this.postJson<{ revoked: boolean }>("/capabilities/revoke", input);
763798
return response.revoked;
764799
}
765800

766-
async listCapabilities(subject: {
767-
subject_type: string;
768-
subject_id: string;
769-
}): Promise<SparseKernelCapability[]> {
801+
async listCapabilities(
802+
subject: SparseKernelListCapabilitiesInput,
803+
): Promise<SparseKernelCapability[]> {
770804
return await this.postJson<SparseKernelCapability[]>("/capabilities/list", subject);
771805
}
772806

schemas/sparsekernel.openapi.yaml

Lines changed: 37 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -224,11 +224,7 @@ paths:
224224
content:
225225
application/json:
226226
schema:
227-
type: object
228-
required: [session_id]
229-
properties:
230-
session_id: { type: string }
231-
limit: { type: integer }
227+
$ref: "#/components/schemas/ListTranscriptEventsInput"
232228
responses:
233229
"200":
234230
description: Session transcript events
@@ -483,10 +479,7 @@ paths:
483479
content:
484480
application/json:
485481
schema:
486-
type: object
487-
required: [context_id]
488-
properties:
489-
context_id: { type: string }
482+
$ref: "#/components/schemas/ReleaseBrowserContextInput"
490483
responses:
491484
"200":
492485
description: Release result
@@ -614,10 +607,7 @@ paths:
614607
content:
615608
application/json:
616609
schema:
617-
type: object
618-
required: [allocation_id]
619-
properties:
620-
allocation_id: { type: string }
610+
$ref: "#/components/schemas/ReleaseSandboxInput"
621611
responses:
622612
"200":
623613
description: Release result
@@ -649,9 +639,7 @@ paths:
649639
content:
650640
application/json:
651641
schema:
652-
type: object
653-
properties:
654-
now: { type: string }
642+
$ref: "#/components/schemas/ReleaseExpiredLeasesInput"
655643
responses:
656644
"200":
657645
description: Expired lease release counts
@@ -702,10 +690,7 @@ paths:
702690
content:
703691
application/json:
704692
schema:
705-
type: object
706-
required: [id]
707-
properties:
708-
id: { type: string }
693+
$ref: "#/components/schemas/CapabilityIdInput"
709694
responses:
710695
"200":
711696
description: Revoke result
@@ -724,11 +709,7 @@ paths:
724709
content:
725710
application/json:
726711
schema:
727-
type: object
728-
required: [subject_type, subject_id]
729-
properties:
730-
subject_type: { type: string }
731-
subject_id: { type: string }
712+
$ref: "#/components/schemas/ListCapabilitiesInput"
732713
responses:
733714
"200":
734715
description: Subject capabilities
@@ -1049,6 +1030,12 @@ components:
10491030
tool_call_id: { type: [string, "null"] }
10501031
token_count: { type: [integer, "null"] }
10511032
created_at: { type: [string, "null"] }
1033+
ListTranscriptEventsInput:
1034+
type: object
1035+
required: [session_id]
1036+
properties:
1037+
session_id: { type: string }
1038+
limit: { type: integer }
10521039
ToolCall:
10531040
type: object
10541041
required: [id, tool_name, status, created_at]
@@ -1200,6 +1187,11 @@ components:
12001187
max_contexts: { type: integer }
12011188
cdp_endpoint: { type: [string, "null"] }
12021189
allowed_origins: true
1190+
ReleaseBrowserContextInput:
1191+
type: object
1192+
required: [context_id]
1193+
properties:
1194+
context_id: { type: string }
12031195
BrowserObservationInput:
12041196
type: object
12051197
required: [context_id, observation_type]
@@ -1253,6 +1245,10 @@ components:
12531245
properties:
12541246
tasks: { type: integer }
12551247
resources: { type: integer }
1248+
ReleaseExpiredLeasesInput:
1249+
type: object
1250+
properties:
1251+
now: { type: string }
12561252
SandboxAllocation:
12571253
type: object
12581254
required: [id, trust_zone_id, backend, status, created_at]
@@ -1290,6 +1286,11 @@ components:
12901286
docker_image: { type: [string, "null"] }
12911287
max_runtime_ms: { type: [integer, "null"] }
12921288
max_bytes_out: { type: [integer, "null"] }
1289+
ReleaseSandboxInput:
1290+
type: object
1291+
required: [allocation_id]
1292+
properties:
1293+
allocation_id: { type: string }
12931294
Capability:
12941295
type: object
12951296
required: [id, subject_type, subject_id, resource_type, action, created_at]
@@ -1325,6 +1326,17 @@ components:
13251326
action: { type: string }
13261327
context: true
13271328
audit_denied: { type: boolean }
1329+
CapabilityIdInput:
1330+
type: object
1331+
required: [id]
1332+
properties:
1333+
id: { type: string }
1334+
ListCapabilitiesInput:
1335+
type: object
1336+
required: [subject_type, subject_id]
1337+
properties:
1338+
subject_type: { type: string }
1339+
subject_id: { type: string }
13281340
Artifact:
13291341
type: object
13301342
required: [id, sha256, size_bytes, storage_ref, created_at]

scripts/check-sparsekernel-openapi.mjs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ const CLIENT_SCHEMA_MAPPINGS = [
1919
mapping("SparseKernelTranscriptEvent", "TranscriptEvent"),
2020
mapping("SparseKernelUpsertSessionInput", "UpsertSessionInput"),
2121
mapping("SparseKernelAppendTranscriptEventInput", "AppendTranscriptEventInput"),
22+
mapping("SparseKernelListTranscriptEventsInput", "ListTranscriptEventsInput"),
2223
mapping("SparseKernelToolCall", "ToolCall"),
2324
mapping("SparseKernelAuditEvent", "AuditEvent"),
2425
mapping("SparseKernelArtifact", "Artifact"),
@@ -38,6 +39,7 @@ const CLIENT_SCHEMA_MAPPINGS = [
3839
mapping("SparseKernelBrowserTarget", "BrowserTarget"),
3940
mapping("SparseKernelBrowserObservation", "BrowserObservation"),
4041
mapping("SparseKernelAcquireBrowserContextInput", "AcquireBrowserContextInput"),
42+
mapping("SparseKernelReleaseBrowserContextInput", "ReleaseBrowserContextInput"),
4143
mapping("SparseKernelBrowserObservationInput", "BrowserObservationInput"),
4244
mapping("SparseKernelRecordBrowserTargetInput", "RecordBrowserTargetInput"),
4345
mapping("SparseKernelCloseBrowserTargetInput", "CloseBrowserTargetInput"),
@@ -49,15 +51,21 @@ const CLIENT_SCHEMA_MAPPINGS = [
4951
mapping("SparseKernelHeartbeatTaskInput", "HeartbeatTaskInput"),
5052
mapping("SparseKernelCompleteTaskInput", "CompleteTaskInput"),
5153
mapping("SparseKernelFailTaskInput", "FailTaskInput"),
54+
mapping("SparseKernelReleaseExpiredLeasesInput", "ReleaseExpiredLeasesInput"),
5255
mapping("SparseKernelReleaseExpiredLeasesResult", "ReleaseExpiredLeasesResult"),
5356
mapping("SparseKernelSandboxAllocation", "SandboxAllocation"),
5457
mapping("SparseKernelSandboxBackendProbe", "SandboxBackendProbe"),
5558
mapping("SparseKernelAllocateSandboxInput", "AllocateSandboxInput"),
59+
mapping("SparseKernelReleaseSandboxInput", "ReleaseSandboxInput"),
5660
mapping("SparseKernelCreateToolCallInput", "CreateToolCallInput"),
61+
mapping("SparseKernelToolCallIdInput", "ToolCallIdInput"),
5762
mapping("SparseKernelCompleteToolCallInput", "CompleteToolCallInput"),
63+
mapping("SparseKernelFailToolCallInput", "FailToolCallInput"),
5864
mapping("SparseKernelCapability", "Capability"),
5965
mapping("SparseKernelGrantCapabilityInput", "GrantCapabilityInput"),
6066
mapping("SparseKernelCapabilityCheckInput", "CapabilityCheckInput"),
67+
mapping("SparseKernelCapabilityIdInput", "CapabilityIdInput"),
68+
mapping("SparseKernelListCapabilitiesInput", "ListCapabilitiesInput"),
6169
];
6270

6371
function mapping(clientType, schemaName, options = {}) {

0 commit comments

Comments
 (0)