Sessions
The 12 operations under sessions, as typed calls on the generated REST client.
Sessions
Available from @codespar/sdk 0.12.0, which is not on npm yet. The published version today is 0.11.0, and it has no cs.api; 0.12.0 is on the main branch of codespar-core. The examples below are not compiled against the installed package for that reason.
Every call below is cs.api reaching one operation of the OpenAPI document this page was generated from; the REST client overview explains request, response, the option bag and the errors. The values are placeholders shaped by the document.
import { CodeSpar } from "@codespar/sdk";
const cs = new CodeSpar({ apiKey: process.env.CODESPAR_API_KEY });GET /v1/sessions
/v1/sessionsList sessions
const result = await cs.api.get("/v1/sessions");Parameters, body and every documented response: GET /v1/sessions in the HTTP reference.
POST /v1/sessions
/v1/sessionsOpen a session
const r = await cs.api.response("post", "/v1/sessions", {
body: {
servers: [
"string"
],
user_id: "user_0000000000000000",
mocks: {},
chaos: {}
}
});
// r.status is one of the documented statuses (200, 403),
// each with its own body shape in r.data; nothing here throws on 403.
if (r.ok) {
console.log(r.data);
}Parameters, body and every documented response: POST /v1/sessions in the HTTP reference.
GET /v1/sessions/{id}
/v1/sessions/{id}Read one session
const result = await cs.api.get("/v1/sessions/{id}", {
path: {
id: "ses_0000000000000000"
}
});Parameters, body and every documented response: GET /v1/sessions/{id} in the HTTP reference.
DELETE /v1/sessions/{id}
/v1/sessions/{id}Close a session
const result = await cs.api.delete("/v1/sessions/{id}", {
path: {
id: "ses_0000000000000000"
}
});Parameters, body and every documented response: DELETE /v1/sessions/{id} in the HTTP reference.
GET /v1/sessions/{id}/connections
/v1/sessions/{id}/connectionsList a session's servers and the tools it can call
const result = await cs.api.get("/v1/sessions/{id}/connections", {
path: {
id: "ses_0000000000000000"
}
});Parameters, body and every documented response: GET /v1/sessions/{id}/connections in the HTTP reference.
POST /v1/sessions/{id}/execute
/v1/sessions/{id}/executeResolves `tool` as a CodeSpar meta-tool first, then as a catalog tool
Run one tool in the session
const r = await cs.api.response("post", "/v1/sessions/{id}/execute", {
path: {
id: "ses_0000000000000000"
},
body: {
tool: "string",
params: {},
input: {},
estimatedCost: 0
}
});
// r.status is one of the documented statuses (200, 403, 422),
// each with its own body shape in r.data; nothing here throws on 403.
if (r.ok) {
console.log(r.data);
}Parameters, body and every documented response: POST /v1/sessions/{id}/execute in the HTTP reference.
GET /v1/sessions/{id}/mocks
/v1/sessions/{id}/mocksRead a session's declared mocks and their consume counters
const result = await cs.api.get("/v1/sessions/{id}/mocks", {
path: {
id: "ses_0000000000000000"
}
});Parameters, body and every documented response: GET /v1/sessions/{id}/mocks in the HTTP reference.
POST /v1/sessions/{id}/proxy_execute
/v1/sessions/{id}/proxy_execute`method` + `endpoint` are forwarded to the server's upstream with credentials injected server-side
Make one raw HTTP call to a connected server
const r = await cs.api.response("post", "/v1/sessions/{id}/proxy_execute", {
path: {
id: "ses_0000000000000000"
},
body: {
server: "string",
endpoint: "https://example.com/hook",
method: "GET",
params: {},
headers: {},
estimatedCost: 0
}
});
// r.status is one of the documented statuses (200, 403),
// each with its own body shape in r.data; nothing here throws on 403.
if (r.ok) {
console.log(r.data);
}Parameters, body and every documented response: POST /v1/sessions/{id}/proxy_execute in the HTTP reference.
POST /v1/sessions/{id}/send
/v1/sessions/{id}/senda payment that settled on turn one is still visible when turn two died
Drive a model loop that may call tools
const r = await cs.api.response("post", "/v1/sessions/{id}/send", {
path: {
id: "ses_0000000000000000"
},
body: {
message: "string"
}
});
// r.status is one of the documented statuses (200, 403),
// each with its own body shape in r.data; nothing here throws on 403.
if (r.ok) {
console.log(r.data);
}Parameters, body and every documented response: POST /v1/sessions/{id}/send in the HTTP reference.
GET /v1/sessions/{id}/tool-calls
/v1/sessions/{id}/tool-callsList one session's tool calls
const result = await cs.api.get("/v1/sessions/{id}/tool-calls", {
path: {
id: "ses_0000000000000000"
}
});Parameters, body and every documented response: GET /v1/sessions/{id}/tool-calls in the HTTP reference.
POST /v1/sessions/{id}/tool-calls
/v1/sessions/{id}/tool-callsRecord a tool call the client executed
const result = await cs.api.post("/v1/sessions/{id}/tool-calls", {
path: {
id: "ses_0000000000000000"
},
body: {
server_id: "srv_0000000000000000",
tool_name: "Example",
status: "running",
duration_ms: 0,
error_code: "string"
}
});Parameters, body and every documented response: POST /v1/sessions/{id}/tool-calls in the HTTP reference.
PATCH /v1/sessions/{id}/tool-calls/{tc_id}
/v1/sessions/{id}/tool-calls/{tc_id}Finalize a recorded tool call
const result = await cs.api.patch("/v1/sessions/{id}/tool-calls/{tc_id}", {
path: {
id: "ses_0000000000000000",
tc_id: "tc_0000000000000000"
},
body: {
status: "success",
duration_ms: 0
}
});Parameters, body and every documented response: PATCH /v1/sessions/{id}/tool-calls/{tc_id} in the HTTP reference.