Skip to content

Commit a804f5d

Browse files
stainless-app[bot]stainless-bot
authored andcommitted
feat(api): add files endpoints (#136)
1 parent a7f9867 commit a804f5d

File tree

6 files changed

+146
-1
lines changed

6 files changed

+146
-1
lines changed

.stats.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
configured_endpoints: 50
1+
configured_endpoints: 53
22
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/julep-ai-inc-dash%2Fjulep-88cc6342d69fe97f2a853ea6603be32f004effeb54c78bdaeabada214bba8e5d.yml

api.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,18 @@ Methods:
4949
- <code title="delete /agents/{agent_id}/docs/{doc_id}">client.agents.docs.<a href="./src/resources/agents/docs.ts">delete</a>(agentId, docId) -> ResourceDeleted</code>
5050
- <code title="post /agents/{agent_id}/search">client.agents.docs.<a href="./src/resources/agents/docs.ts">search</a>(agentId, { ...params }) -> DocSearchResponse</code>
5151

52+
# Files
53+
54+
Types:
55+
56+
- <code><a href="./src/resources/files.ts">File</a></code>
57+
58+
Methods:
59+
60+
- <code title="post /files">client.files.<a href="./src/resources/files.ts">create</a>({ ...params }) -> ResourceCreated</code>
61+
- <code title="delete /files/{file_id}">client.files.<a href="./src/resources/files.ts">delete</a>(fileId) -> ResourceDeleted</code>
62+
- <code title="get /files/{file_id}">client.files.<a href="./src/resources/files.ts">get</a>(fileId) -> File</code>
63+
5264
# Sessions
5365

5466
Types:

src/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { type OffsetPaginationParams, OffsetPaginationResponse } from './paginat
99
import * as Uploads from './uploads';
1010
import * as API from './resources/index';
1111
import { Doc, DocEmbedParams, Docs, EmbedQueryResponse, Snippet } from './resources/docs';
12+
import { File, FileCreateParams, Files } from './resources/files';
1213
import { JobStatus, Jobs } from './resources/jobs';
1314
import {
1415
ChatInput,
@@ -208,6 +209,7 @@ export class Julep extends Core.APIClient {
208209
}
209210

210211
agents: API.Agents = new API.Agents(this);
212+
files: API.Files = new API.Files(this);
211213
sessions: API.Sessions = new API.Sessions(this);
212214
users: API.Users = new API.Users(this);
213215
jobs: API.Jobs = new API.Jobs(this);
@@ -257,6 +259,7 @@ export class Julep extends Core.APIClient {
257259

258260
Julep.Agents = Agents;
259261
Julep.AgentsOffsetPagination = AgentsOffsetPagination;
262+
Julep.Files = Files;
260263
Julep.Sessions = Sessions;
261264
Julep.SessionsOffsetPagination = SessionsOffsetPagination;
262265
Julep.Users = Users;
@@ -287,6 +290,8 @@ export declare namespace Julep {
287290
type AgentPatchParams as AgentPatchParams,
288291
};
289292

293+
export { Files as Files, type File as File, type FileCreateParams as FileCreateParams };
294+
290295
export {
291296
Sessions as Sessions,
292297
type ChatInput as ChatInput,

src/resources/files.ts

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2+
3+
import { APIResource } from '../resource';
4+
import * as Core from '../core';
5+
import * as Shared from './shared';
6+
7+
export class Files extends APIResource {
8+
/**
9+
* Create File
10+
*/
11+
create(body: FileCreateParams, options?: Core.RequestOptions): Core.APIPromise<Shared.ResourceCreated> {
12+
return this._client.post('/files', { body, ...options });
13+
}
14+
15+
/**
16+
* Delete File
17+
*/
18+
delete(fileId: string, options?: Core.RequestOptions): Core.APIPromise<Shared.ResourceDeleted> {
19+
return this._client.delete(`/files/${fileId}`, options);
20+
}
21+
22+
/**
23+
* Get File
24+
*/
25+
get(fileId: string, options?: Core.RequestOptions): Core.APIPromise<File> {
26+
return this._client.get(`/files/${fileId}`, options);
27+
}
28+
}
29+
30+
export interface File {
31+
id: string;
32+
33+
content: string;
34+
35+
created_at: string;
36+
37+
hash: string;
38+
39+
name: string;
40+
41+
size: number;
42+
43+
description?: string;
44+
45+
mime_type?: string | null;
46+
}
47+
48+
export interface FileCreateParams {
49+
content: string;
50+
51+
name: string;
52+
53+
description?: string;
54+
55+
mime_type?: string | null;
56+
}
57+
58+
export declare namespace Files {
59+
export { type File as File, type FileCreateParams as FileCreateParams };
60+
}

src/resources/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export {
1919
type Snippet,
2020
type DocEmbedParams,
2121
} from './docs';
22+
export { Files, type File, type FileCreateParams } from './files';
2223
export { Jobs, type JobStatus } from './jobs';
2324
export {
2425
SessionsOffsetPagination,

tests/api-resources/files.test.ts

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2+
3+
import Julep from '@julep/sdk';
4+
import { Response } from 'node-fetch';
5+
6+
const client = new Julep({
7+
apiKey: 'My API Key',
8+
baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',
9+
});
10+
11+
describe('resource files', () => {
12+
test('create: only required params', async () => {
13+
const responsePromise = client.files.create({ content: 'content', name: 'name' });
14+
const rawResponse = await responsePromise.asResponse();
15+
expect(rawResponse).toBeInstanceOf(Response);
16+
const response = await responsePromise;
17+
expect(response).not.toBeInstanceOf(Response);
18+
const dataAndResponse = await responsePromise.withResponse();
19+
expect(dataAndResponse.data).toBe(response);
20+
expect(dataAndResponse.response).toBe(rawResponse);
21+
});
22+
23+
test('create: required and optional params', async () => {
24+
const response = await client.files.create({
25+
content: 'content',
26+
name: 'name',
27+
description: 'description',
28+
mime_type: 'mime_type',
29+
});
30+
});
31+
32+
test('delete', async () => {
33+
const responsePromise = client.files.delete('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e');
34+
const rawResponse = await responsePromise.asResponse();
35+
expect(rawResponse).toBeInstanceOf(Response);
36+
const response = await responsePromise;
37+
expect(response).not.toBeInstanceOf(Response);
38+
const dataAndResponse = await responsePromise.withResponse();
39+
expect(dataAndResponse.data).toBe(response);
40+
expect(dataAndResponse.response).toBe(rawResponse);
41+
});
42+
43+
test('delete: request options instead of params are passed correctly', async () => {
44+
// ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error
45+
await expect(
46+
client.files.delete('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', { path: '/_stainless_unknown_path' }),
47+
).rejects.toThrow(Julep.NotFoundError);
48+
});
49+
50+
test('get', async () => {
51+
const responsePromise = client.files.get('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e');
52+
const rawResponse = await responsePromise.asResponse();
53+
expect(rawResponse).toBeInstanceOf(Response);
54+
const response = await responsePromise;
55+
expect(response).not.toBeInstanceOf(Response);
56+
const dataAndResponse = await responsePromise.withResponse();
57+
expect(dataAndResponse.data).toBe(response);
58+
expect(dataAndResponse.response).toBe(rawResponse);
59+
});
60+
61+
test('get: request options instead of params are passed correctly', async () => {
62+
// ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error
63+
await expect(
64+
client.files.get('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', { path: '/_stainless_unknown_path' }),
65+
).rejects.toThrow(Julep.NotFoundError);
66+
});
67+
});

0 commit comments

Comments
 (0)