Skip to main content
REST client

Sessions

The 12 operations under sessions, as typed calls on the generated REST client.

2 min read
View MarkdownEdit on GitHub

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

GET/v1/sessions

List 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

POST/v1/sessions

Open 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}

GET/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}

DELETE/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

GET/v1/sessions/{id}/connections

List 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

POST/v1/sessions/{id}/execute
Can move money

Resolves `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

GET/v1/sessions/{id}/mocks

Read 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

POST/v1/sessions/{id}/proxy_execute
Can move money

`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

POST/v1/sessions/{id}/send
Can move money

a 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

GET/v1/sessions/{id}/tool-calls

List 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

POST/v1/sessions/{id}/tool-calls

Record 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}

PATCH/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.

Sessions | CodeSpar