Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 0 additions & 23 deletions .devcontainer/Dockerfile

This file was deleted.

27 changes: 12 additions & 15 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/debian
{
"name": "Debian",
"build": {
"dockerfile": "Dockerfile"
"name": "Development",
"image": "mcr.microsoft.com/devcontainers/typescript-node:latest",
"features": {
"ghcr.io/devcontainers/features/node:1": {}
},
"postCreateCommand": "yarn install",
"customizations": {
"vscode": {
"extensions": [
"esbenp.prettier-vscode"
]
}
}

// Features to add to the dev container. More info: https://containers.dev/features.
// "features": {},

// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],

// Configure tool-specific properties.
// "customizations": {},

// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
// "remoteUser": "root"
}
2 changes: 1 addition & 1 deletion .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
".": "0.2.0"
".": "0.3.0"
}
4 changes: 2 additions & 2 deletions .stats.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
configured_endpoints: 35
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/contextual-ai%2Fsunrise-d79ccb778953ad5c2ae4b99115429c8b3f68b3b23d9b6d90b1b40393f11a4383.yml
configured_endpoints: 46
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/contextual-ai%2Fsunrise-5298551c424bb999f258bdd6c311e96c80c70701ad59bbce19b46c788ee13bd4.yml
21 changes: 21 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,26 @@
# Changelog

## 0.3.0 (2025-02-26)

Full Changelog: [v0.2.0...v0.3.0](https://github.com/ContextualAI/contextual-client-node/compare/v0.2.0...v0.3.0)

### Features

* **api:** update via SDK Studio ([#20](https://github.com/ContextualAI/contextual-client-node/issues/20)) ([ca5487d](https://github.com/ContextualAI/contextual-client-node/commit/ca5487db83e2aea688b31413e9c594ff3f463f63))
* **api:** update via SDK Studio ([#25](https://github.com/ContextualAI/contextual-client-node/issues/25)) ([366e7bc](https://github.com/ContextualAI/contextual-client-node/commit/366e7bc974e79509e2627d764523f5156ff6d5bb))
* **api:** update via SDK Studio ([#26](https://github.com/ContextualAI/contextual-client-node/issues/26)) ([87470ef](https://github.com/ContextualAI/contextual-client-node/commit/87470ef70c3a84cf8873f2cac7f705305fd9dde8))


### Bug Fixes

* **client:** fix export map for index exports ([#22](https://github.com/ContextualAI/contextual-client-node/issues/22)) ([9775826](https://github.com/ContextualAI/contextual-client-node/commit/977582624e283aac91c128e9b0f004e2e40f3562))


### Chores

* **internal:** codegen related update ([#23](https://github.com/ContextualAI/contextual-client-node/issues/23)) ([1643590](https://github.com/ContextualAI/contextual-client-node/commit/16435904607828ebae0559d90397c7a15dca2619))
* **internal:** fix devcontainers setup ([#24](https://github.com/ContextualAI/contextual-client-node/issues/24)) ([ecf1652](https://github.com/ContextualAI/contextual-client-node/commit/ecf16521a46c1265811ca2d66cad02b172eda636))

## 0.2.0 (2025-02-08)

Full Changelog: [v0.1.0...v0.2.0](https://github.com/ContextualAI/contextual-client-node/compare/v0.1.0...v0.2.0)
Expand Down
58 changes: 50 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const client = new ContextualAI({
});

async function main() {
const createAgentOutput = await client.agents.create({ name: 'xxx' });
const createAgentOutput = await client.agents.create({ name: 'Example' });

console.log(createAgentOutput.id);
}
Expand All @@ -46,7 +46,7 @@ const client = new ContextualAI({
});

async function main() {
const params: ContextualAI.AgentCreateParams = { name: 'xxx' };
const params: ContextualAI.AgentCreateParams = { name: 'Example' };
const createAgentOutput: ContextualAI.CreateAgentOutput = await client.agents.create(params);
}

Expand All @@ -55,6 +55,46 @@ main();

Documentation for each method, request param, and response field are available in docstrings and will appear on hover in most modern editors.

## File uploads

Request parameters that correspond to file uploads can be passed in many different forms:

- `File` (or an object with the same structure)
- a `fetch` `Response` (or an object with the same structure)
- an `fs.ReadStream`
- the return value of our `toFile` helper

```ts
import fs from 'fs';
import fetch from 'node-fetch';
import ContextualAI, { toFile } from 'contextual-client';

const client = new ContextualAI();

// If you have access to Node `fs` we recommend using `fs.createReadStream()`:
await client.datastores.documents.ingest('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', {
file: fs.createReadStream('/path/to/file'),
});

// Or if you have the web `File` API you can pass a `File` instance:
await client.datastores.documents.ingest('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', {
file: new File(['my bytes'], 'file'),
});

// You can also pass a `fetch` `Response`:
await client.datastores.documents.ingest('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', {
file: await fetch('https://somesite/file'),
});

// Finally, if none of the above are convenient, you can use our `toFile` helper:
await client.datastores.documents.ingest('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', {
file: await toFile(Buffer.from('my bytes'), 'file'),
});
await client.datastores.documents.ingest('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', {
file: await toFile(new Uint8Array([0, 1, 2]), 'file'),
});
```

## Handling errors

When the library is unable to connect to the API,
Expand All @@ -64,7 +104,7 @@ a subclass of `APIError` will be thrown:
<!-- prettier-ignore -->
```ts
async function main() {
const createAgentOutput = await client.agents.create({ name: 'xxx' }).catch(async (err) => {
const createAgentOutput = await client.agents.create({ name: 'Example' }).catch(async (err) => {
if (err instanceof ContextualAI.APIError) {
console.log(err.status); // 400
console.log(err.name); // BadRequestError
Expand Down Expand Up @@ -107,7 +147,7 @@ const client = new ContextualAI({
});

// Or, configure per-request:
await client.agents.create({ name: 'xxx' }, {
await client.agents.create({ name: 'Example' }, {
maxRetries: 5,
});
```
Expand All @@ -124,7 +164,7 @@ const client = new ContextualAI({
});

// Override per-request:
await client.agents.create({ name: 'xxx' }, {
await client.agents.create({ name: 'Example' }, {
timeout: 5 * 1000,
});
```
Expand Down Expand Up @@ -176,11 +216,13 @@ You can also use the `.withResponse()` method to get the raw `Response` along wi
```ts
const client = new ContextualAI();

const response = await client.agents.create({ name: 'xxx' }).asResponse();
const response = await client.agents.create({ name: 'Example' }).asResponse();
console.log(response.headers.get('X-My-Header'));
console.log(response.statusText); // access the underlying Response object

const { data: createAgentOutput, response: raw } = await client.agents.create({ name: 'xxx' }).withResponse();
const { data: createAgentOutput, response: raw } = await client.agents
.create({ name: 'Example' })
.withResponse();
console.log(raw.headers.get('X-My-Header'));
console.log(createAgentOutput.id);
```
Expand Down Expand Up @@ -287,7 +329,7 @@ const client = new ContextualAI({

// Override per-request:
await client.agents.create(
{ name: 'xxx' },
{ name: 'Example' },
{
httpAgent: new http.Agent({ keepAlive: false }),
},
Expand Down
33 changes: 33 additions & 0 deletions api.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ Methods:
- <code title="delete /datastores/{datastore_id}/documents/{document_id}">client.datastores.documents.<a href="./src/resources/datastores/documents.ts">delete</a>(datastoreId, documentId) -> unknown</code>
- <code title="post /datastores/{datastore_id}/documents">client.datastores.documents.<a href="./src/resources/datastores/documents.ts">ingest</a>(datastoreId, { ...params }) -> IngestionResponse</code>
- <code title="get /datastores/{datastore_id}/documents/{document_id}/metadata">client.datastores.documents.<a href="./src/resources/datastores/documents.ts">metadata</a>(datastoreId, documentId) -> DocumentMetadata</code>
- <code title="post /datastores/{datastore_id}/documents/{document_id}/metadata">client.datastores.documents.<a href="./src/resources/datastores/documents.ts">setMetadata</a>(datastoreId, documentId, { ...params }) -> DocumentMetadata</code>

# Agents

Expand Down Expand Up @@ -98,6 +99,21 @@ Types:
- <code><a href="./src/resources/agents/datasets/datasets.ts">DatasetMetadata</a></code>
- <code><a href="./src/resources/agents/datasets/datasets.ts">ListDatasetsResponse</a></code>

### Tune

Types:

- <code><a href="./src/resources/agents/datasets/tune.ts">TuneDeleteResponse</a></code>

Methods:

- <code title="post /agents/{agent_id}/datasets/tune">client.agents.datasets.tune.<a href="./src/resources/agents/datasets/tune.ts">create</a>(agentId, { ...params }) -> CreateDatasetResponse</code>
- <code title="get /agents/{agent_id}/datasets/tune/{dataset_name}">client.agents.datasets.tune.<a href="./src/resources/agents/datasets/tune.ts">retrieve</a>(agentId, datasetName, { ...params }) -> Response</code>
- <code title="put /agents/{agent_id}/datasets/tune/{dataset_name}">client.agents.datasets.tune.<a href="./src/resources/agents/datasets/tune.ts">update</a>(agentId, datasetName, { ...params }) -> CreateDatasetResponse</code>
- <code title="get /agents/{agent_id}/datasets/tune">client.agents.datasets.tune.<a href="./src/resources/agents/datasets/tune.ts">list</a>(agentId, { ...params }) -> ListDatasetsResponse</code>
- <code title="delete /agents/{agent_id}/datasets/tune/{dataset_name}">client.agents.datasets.tune.<a href="./src/resources/agents/datasets/tune.ts">delete</a>(agentId, datasetName) -> unknown</code>
- <code title="get /agents/{agent_id}/datasets/tune/{dataset_name}/metadata">client.agents.datasets.tune.<a href="./src/resources/agents/datasets/tune.ts">metadata</a>(agentId, datasetName, { ...params }) -> DatasetMetadata</code>

### Evaluate

Types:
Expand Down Expand Up @@ -147,6 +163,23 @@ Methods:

- <code title="get /agents/{agent_id}/tune/models">client.agents.tune.models.<a href="./src/resources/agents/tune/models.ts">list</a>(agentId) -> ListTuneModelsResponse</code>

# Users

Types:

- <code><a href="./src/resources/users.ts">InviteUsersResponse</a></code>
- <code><a href="./src/resources/users.ts">ListUsersResponse</a></code>
- <code><a href="./src/resources/users.ts">NewUser</a></code>
- <code><a href="./src/resources/users.ts">UserUpdateResponse</a></code>
- <code><a href="./src/resources/users.ts">UserDeactivateResponse</a></code>

Methods:

- <code title="put /users">client.users.<a href="./src/resources/users.ts">update</a>({ ...params }) -> unknown</code>
- <code title="get /users">client.users.<a href="./src/resources/users.ts">list</a>({ ...params }) -> ListUsersResponseUsersUsersPage</code>
- <code title="delete /users">client.users.<a href="./src/resources/users.ts">deactivate</a>({ ...params }) -> unknown</code>
- <code title="post /users">client.users.<a href="./src/resources/users.ts">invite</a>({ ...params }) -> InviteUsersResponse</code>

# LMUnit

Types:
Expand Down
37 changes: 29 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "contextual-client",
"version": "0.2.0",
"version": "0.3.0",
"description": "The official TypeScript library for the Contextual AI API",
"author": "Contextual AI <support@contextual.ai>",
"types": "dist/index.d.ts",
Expand Down Expand Up @@ -107,17 +107,38 @@
"default": "./dist/index.mjs"
},
"./*.mjs": {
"types": "./dist/*.d.ts",
"default": "./dist/*.mjs"
"types": [
"./dist/*.d.ts",
"./dist/*/index.d.ts"
],
"default": [
"./dist/*.mjs",
"./dist/*/index.mjs"
]
},
"./*.js": {
"types": "./dist/*.d.ts",
"default": "./dist/*.js"
"types": [
"./dist/*.d.ts",
"./dist/*/index.d.ts"
],
"default": [
"./dist/*.js",
"./dist/*/index.js"
]
},
"./*": {
"types": "./dist/*.d.ts",
"require": "./dist/*.js",
"default": "./dist/*.mjs"
"types": [
"./dist/*.d.ts",
"./dist/*/index.d.ts"
],
"require": [
"./dist/*.js",
"./dist/*/index.js"
],
"default": [
"./dist/*.mjs",
"./dist/*/index.mjs"
]
}
}
}
35 changes: 35 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,27 @@ import {
DocumentsPageResponse,
type PageParams,
PageResponse,
type UsersPageParams,
UsersPageResponse,
} from './pagination';
import * as Uploads from './uploads';
import * as API from './resources/index';
import { Generate, GenerateCreateParams, GenerateCreateResponse } from './resources/generate';
import { LMUnit, LMUnitCreateParams, LMUnitCreateResponse } from './resources/lmunit';
import { Rerank, RerankCreateParams, RerankCreateResponse } from './resources/rerank';
import {
InviteUsersResponse,
ListUsersResponse,
ListUsersResponseUsersUsersPage,
NewUser,
UserDeactivateParams,
UserDeactivateResponse,
UserInviteParams,
UserListParams,
UserUpdateParams,
UserUpdateResponse,
Users,
} from './resources/users';
import {
Agent as AgentsAPIAgent,
AgentCreateParams,
Expand Down Expand Up @@ -158,6 +173,7 @@ export class ContextualAI extends Core.APIClient {

datastores: API.Datastores = new API.Datastores(this);
agents: API.Agents = new API.Agents(this);
users: API.Users = new API.Users(this);
lmUnit: API.LMUnit = new API.LMUnit(this);
rerank: API.Rerank = new API.Rerank(this);
generate: API.Generate = new API.Generate(this);
Expand Down Expand Up @@ -206,6 +222,8 @@ ContextualAI.Datastores = Datastores;
ContextualAI.DatastoresDatastoresPage = DatastoresDatastoresPage;
ContextualAI.Agents = Agents;
ContextualAI.AgentsPage = AgentsPage;
ContextualAI.Users = Users;
ContextualAI.ListUsersResponseUsersUsersPage = ListUsersResponseUsersUsersPage;
ContextualAI.LMUnit = LMUnit;
ContextualAI.Rerank = Rerank;
ContextualAI.Generate = Generate;
Expand All @@ -224,6 +242,9 @@ export declare namespace ContextualAI {
type DocumentsPageResponse as DocumentsPageResponse,
};

export import UsersPage = Pagination.UsersPage;
export { type UsersPageParams as UsersPageParams, type UsersPageResponse as UsersPageResponse };

export import Page = Pagination.Page;
export { type PageParams as PageParams, type PageResponse as PageResponse };

Expand Down Expand Up @@ -253,6 +274,20 @@ export declare namespace ContextualAI {
type AgentListParams as AgentListParams,
};

export {
Users as Users,
type InviteUsersResponse as InviteUsersResponse,
type ListUsersResponse as ListUsersResponse,
type NewUser as NewUser,
type UserUpdateResponse as UserUpdateResponse,
type UserDeactivateResponse as UserDeactivateResponse,
ListUsersResponseUsersUsersPage as ListUsersResponseUsersUsersPage,
type UserUpdateParams as UserUpdateParams,
type UserListParams as UserListParams,
type UserDeactivateParams as UserDeactivateParams,
type UserInviteParams as UserInviteParams,
};

export {
LMUnit as LMUnit,
type LMUnitCreateResponse as LMUnitCreateResponse,
Expand Down
Loading