Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

release: 0.0.8 #47

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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ yarn-error.log
codegen.log
Brewfile.lock.json
dist
/deno
dist-deno
/*.tgz
.idea/

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.0.7"
".": "0.1.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: 39
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/plastic-labs%2Fhoncho-3b94ec668fd95755a2447237b113b61d5c82e62960832d065e8a6f06a1916286.yml
configured_endpoints: 40
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/plastic-labs%2Fhoncho-96679f6cf67d77d1e9587886a8cdbb6e2a132b9f8abd22c056e479fe3ff89a6f.yml
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
# Changelog

## 0.1.0 (2024-11-07)

Full Changelog: [v0.0.7...v0.1.0](https://github.com/plastic-labs/honcho-node/compare/v0.0.7...v0.1.0)

### Features

* **api:** Add cloning feature ([#48](https://github.com/plastic-labs/honcho-node/issues/48)) ([54d640b](https://github.com/plastic-labs/honcho-node/commit/54d640b19ca9609d80eb2061e7bb0d62eacee395))


### Chores

* rebuild project due to codegen change ([#46](https://github.com/plastic-labs/honcho-node/issues/46)) ([d4f3332](https://github.com/plastic-labs/honcho-node/commit/d4f3332230439cf63e6b4b90602c63c94f04820d))

## 0.0.7 (2024-10-21)

Full Changelog: [v0.0.6...v0.0.7](https://github.com/plastic-labs/honcho-node/compare/v0.0.6...v0.0.7)
Expand Down
31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,37 @@ On timeout, an `APIConnectionTimeoutError` is thrown.

Note that requests which time out will be [retried twice by default](#retries).

## Auto-pagination

List methods in the Honcho API are paginated.
You can use the `for await … of` syntax to iterate through items across all pages:

```ts
async function fetchAllAppsUsers(params) {
const allAppsUsers = [];
// Automatically fetches more pages as needed.
for await (const user of client.apps.users.list('REPLACE_ME')) {
allAppsUsers.push(user);
}
return allAppsUsers;
}
```

Alternatively, you can request a single page at a time:

```ts
let page = await client.apps.users.list('REPLACE_ME');
for (const user of page.items) {
console.log(user);
}

// Convenience methods are provided for manually paginating:
while (page.hasNextPage()) {
page = page.getNextPage();
// ...
}
```

## Advanced Usage

### Accessing raw Response data (e.g., headers)
Expand Down
1 change: 1 addition & 0 deletions api.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ Methods:
- <code title="post /v1/apps/{app_id}/users/{user_id}/sessions/list">client.apps.users.sessions.<a href="./src/resources/apps/users/sessions/sessions.ts">list</a>(appId, userId, { ...params }) -> SessionsPage</code>
- <code title="delete /v1/apps/{app_id}/users/{user_id}/sessions/{session_id}">client.apps.users.sessions.<a href="./src/resources/apps/users/sessions/sessions.ts">delete</a>(appId, userId, sessionId) -> unknown</code>
- <code title="post /v1/apps/{app_id}/users/{user_id}/sessions/{session_id}/chat">client.apps.users.sessions.<a href="./src/resources/apps/users/sessions/sessions.ts">chat</a>(appId, userId, sessionId, { ...params }) -> AgentChat</code>
- <code title="get /v1/apps/{app_id}/users/{user_id}/sessions/{session_id}/clone">client.apps.users.sessions.<a href="./src/resources/apps/users/sessions/sessions.ts">clone</a>(appId, userId, sessionId, { ...params }) -> Session</code>
- <code title="get /v1/apps/{app_id}/users/{user_id}/sessions/{session_id}">client.apps.users.sessions.<a href="./src/resources/apps/users/sessions/sessions.ts">get</a>(appId, userId, sessionId) -> Session</code>
- <code title="post /v1/apps/{app_id}/users/{user_id}/sessions/{session_id}/chat/stream">client.apps.users.sessions.<a href="./src/resources/apps/users/sessions/sessions.ts">stream</a>(appId, userId, sessionId, { ...params }) -> unknown</code>

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "honcho",
"version": "0.0.7",
"version": "0.1.0",
"description": "The official TypeScript library for the Honcho API",
"author": "Honcho <hello@plasticlabs.ai>",
"types": "dist/index.d.ts",
Expand All @@ -10,7 +10,7 @@
"license": "Apache-2.0",
"packageManager": "yarn@1.22.22",
"files": [
"*"
"**/*"
],
"private": false,
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion scripts/build
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ node scripts/utils/postprocess-files.cjs
(cd dist && node -e 'require("honcho")')
(cd dist && node -e 'import("honcho")' --input-type=module)

if command -v deno &> /dev/null && [ -e ./scripts/build-deno ]
if [ -e ./scripts/build-deno ]
then
./scripts/build-deno
fi
10 changes: 5 additions & 5 deletions src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ export abstract class APIClient {
error: Object | undefined,
message: string | undefined,
headers: Headers | undefined,
) {
): APIError {
return APIError.generate(status, error, message, headers);
}

Expand Down Expand Up @@ -668,17 +668,17 @@ export abstract class AbstractPage<Item> implements AsyncIterable<Item> {
return await this.#client.requestAPIList(this.constructor as any, nextOptions);
}

async *iterPages() {
async *iterPages(): AsyncGenerator<this> {
// eslint-disable-next-line @typescript-eslint/no-this-alias
let page: AbstractPage<Item> = this;
let page: this = this;
yield page;
while (page.hasNextPage()) {
page = await page.getNextPage();
yield page;
}
}

async *[Symbol.asyncIterator]() {
async *[Symbol.asyncIterator](): AsyncGenerator<Item> {
for await (const page of this.iterPages()) {
for (const item of page.getPaginatedItems()) {
yield item;
Expand Down Expand Up @@ -721,7 +721,7 @@ export class PagePromise<
* console.log(item)
* }
*/
async *[Symbol.asyncIterator]() {
async *[Symbol.asyncIterator](): AsyncGenerator<Item> {
const page = await this;
for await (const item of page) {
yield item;
Expand Down
2 changes: 1 addition & 1 deletion src/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export class APIError extends HonchoError {
errorResponse: Object | undefined,
message: string | undefined,
headers: Headers | undefined,
) {
): APIError {
if (!status) {
return new APIConnectionError({ message, cause: castToError(errorResponse) });
}
Expand Down
31 changes: 18 additions & 13 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

import * as Errors from './error';
import * as Uploads from './uploads';
import { type Agent } from './_shims/index';
import * as Core from './core';
import * as Errors from './error';
import * as Pagination from './pagination';
import { type PageParams, PageResponse } from './pagination';
import * as Uploads from './uploads';
import * as API from './resources/index';
import { App, AppCreateParams, AppUpdateParams, Apps } from './resources/apps/apps';

const environments = {
demo: 'https://demo.honcho.dev',
Expand Down Expand Up @@ -178,7 +180,7 @@ export class Honcho extends Core.APIClient {
static fileFromPath = Uploads.fileFromPath;
}

export const {
export {
HonchoError,
APIError,
APIConnectionError,
Expand All @@ -192,22 +194,25 @@ export const {
InternalServerError,
PermissionDeniedError,
UnprocessableEntityError,
} = Errors;
} from './error';

export import toFile = Uploads.toFile;
export import fileFromPath = Uploads.fileFromPath;

export namespace Honcho {
export import RequestOptions = Core.RequestOptions;
Honcho.Apps = Apps;

export import Page = Pagination.Page;
export import PageParams = Pagination.PageParams;
export import PageResponse = Pagination.PageResponse;
export declare namespace Honcho {
export type RequestOptions = Core.RequestOptions;

export import Apps = API.Apps;
export import App = API.App;
export import AppCreateParams = API.AppCreateParams;
export import AppUpdateParams = API.AppUpdateParams;
export import Page = Pagination.Page;
export { type PageParams as PageParams, type PageResponse as PageResponse };

export {
Apps as Apps,
type App as App,
type AppCreateParams as AppCreateParams,
type AppUpdateParams as AppUpdateParams,
};
}

export default Honcho;
40 changes: 28 additions & 12 deletions src/resources/apps/apps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,16 @@

import { APIResource } from '../../resource';
import * as Core from '../../core';
import * as AppsAPI from './apps';
import * as UsersAPI from './users/users';
import {
PageUser,
User,
UserCreateParams,
UserListParams,
UserUpdateParams,
Users,
UsersPage,
} from './users/users';

export class Apps extends APIResource {
users: UsersAPI.Users = new UsersAPI.Users(this._client);
Expand Down Expand Up @@ -87,15 +95,23 @@ export interface AppUpdateParams {
name?: string | null;
}

export namespace Apps {
export import App = AppsAPI.App;
export import AppCreateParams = AppsAPI.AppCreateParams;
export import AppUpdateParams = AppsAPI.AppUpdateParams;
export import Users = UsersAPI.Users;
export import PageUser = UsersAPI.PageUser;
export import User = UsersAPI.User;
export import UsersPage = UsersAPI.UsersPage;
export import UserCreateParams = UsersAPI.UserCreateParams;
export import UserUpdateParams = UsersAPI.UserUpdateParams;
export import UserListParams = UsersAPI.UserListParams;
Apps.Users = Users;
Apps.UsersPage = UsersPage;

export declare namespace Apps {
export {
type App as App,
type AppCreateParams as AppCreateParams,
type AppUpdateParams as AppUpdateParams,
};

export {
Users as Users,
type PageUser as PageUser,
type User as User,
UsersPage as UsersPage,
type UserCreateParams as UserCreateParams,
type UserUpdateParams as UserUpdateParams,
type UserListParams as UserListParams,
};
}
12 changes: 6 additions & 6 deletions src/resources/apps/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

export { App, AppCreateParams, AppUpdateParams, Apps } from './apps';
export { Apps, type App, type AppCreateParams, type AppUpdateParams } from './apps';
export {
PageUser,
User,
UserCreateParams,
UserUpdateParams,
UserListParams,
UsersPage,
Users,
type PageUser,
type User,
type UserCreateParams,
type UserUpdateParams,
type UserListParams,
} from './users/index';
58 changes: 39 additions & 19 deletions src/resources/apps/users/collections/collections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,19 @@

import { APIResource } from '../../../../resource';
import * as Core from '../../../../core';
import * as CollectionsAPI from './collections';
import * as DocumentsAPI from './documents';
import {
Document,
DocumentCreateParams,
DocumentDeleteResponse,
DocumentListParams,
DocumentQueryParams,
DocumentQueryResponse,
DocumentUpdateParams,
Documents,
DocumentsPage,
PageDocument,
} from './documents';
import { Page, type PageParams } from '../../../../pagination';

export class Collections extends APIResource {
Expand Down Expand Up @@ -149,22 +160,31 @@ export interface CollectionListParams extends PageParams {
filter?: Record<string, unknown> | null;
}

export namespace Collections {
export import Collection = CollectionsAPI.Collection;
export import PageCollection = CollectionsAPI.PageCollection;
export import CollectionDeleteResponse = CollectionsAPI.CollectionDeleteResponse;
export import CollectionsPage = CollectionsAPI.CollectionsPage;
export import CollectionCreateParams = CollectionsAPI.CollectionCreateParams;
export import CollectionUpdateParams = CollectionsAPI.CollectionUpdateParams;
export import CollectionListParams = CollectionsAPI.CollectionListParams;
export import Documents = DocumentsAPI.Documents;
export import Document = DocumentsAPI.Document;
export import PageDocument = DocumentsAPI.PageDocument;
export import DocumentDeleteResponse = DocumentsAPI.DocumentDeleteResponse;
export import DocumentQueryResponse = DocumentsAPI.DocumentQueryResponse;
export import DocumentsPage = DocumentsAPI.DocumentsPage;
export import DocumentCreateParams = DocumentsAPI.DocumentCreateParams;
export import DocumentUpdateParams = DocumentsAPI.DocumentUpdateParams;
export import DocumentListParams = DocumentsAPI.DocumentListParams;
export import DocumentQueryParams = DocumentsAPI.DocumentQueryParams;
Collections.CollectionsPage = CollectionsPage;
Collections.Documents = Documents;
Collections.DocumentsPage = DocumentsPage;

export declare namespace Collections {
export {
type Collection as Collection,
type PageCollection as PageCollection,
type CollectionDeleteResponse as CollectionDeleteResponse,
CollectionsPage as CollectionsPage,
type CollectionCreateParams as CollectionCreateParams,
type CollectionUpdateParams as CollectionUpdateParams,
type CollectionListParams as CollectionListParams,
};

export {
Documents as Documents,
type Document as Document,
type PageDocument as PageDocument,
type DocumentDeleteResponse as DocumentDeleteResponse,
type DocumentQueryResponse as DocumentQueryResponse,
DocumentsPage as DocumentsPage,
type DocumentCreateParams as DocumentCreateParams,
type DocumentUpdateParams as DocumentUpdateParams,
type DocumentListParams as DocumentListParams,
type DocumentQueryParams as DocumentQueryParams,
};
}
25 changes: 14 additions & 11 deletions src/resources/apps/users/collections/documents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import { APIResource } from '../../../../resource';
import * as Core from '../../../../core';
import * as DocumentsAPI from './documents';
import { Page, type PageParams } from '../../../../pagination';

export class Documents extends APIResource {
Expand Down Expand Up @@ -168,14 +167,18 @@ export interface DocumentQueryParams {
top_k?: number;
}

export namespace Documents {
export import Document = DocumentsAPI.Document;
export import PageDocument = DocumentsAPI.PageDocument;
export import DocumentDeleteResponse = DocumentsAPI.DocumentDeleteResponse;
export import DocumentQueryResponse = DocumentsAPI.DocumentQueryResponse;
export import DocumentsPage = DocumentsAPI.DocumentsPage;
export import DocumentCreateParams = DocumentsAPI.DocumentCreateParams;
export import DocumentUpdateParams = DocumentsAPI.DocumentUpdateParams;
export import DocumentListParams = DocumentsAPI.DocumentListParams;
export import DocumentQueryParams = DocumentsAPI.DocumentQueryParams;
Documents.DocumentsPage = DocumentsPage;

export declare namespace Documents {
export {
type Document as Document,
type PageDocument as PageDocument,
type DocumentDeleteResponse as DocumentDeleteResponse,
type DocumentQueryResponse as DocumentQueryResponse,
DocumentsPage as DocumentsPage,
type DocumentCreateParams as DocumentCreateParams,
type DocumentUpdateParams as DocumentUpdateParams,
type DocumentListParams as DocumentListParams,
type DocumentQueryParams as DocumentQueryParams,
};
}
Loading