diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 491db96..d791adb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -6,6 +6,7 @@ on: pull_request: branches: - main + - next jobs: lint: diff --git a/.github/workflows/release-doctor.yml b/.github/workflows/release-doctor.yml index dd03026..1e6c440 100644 --- a/.github/workflows/release-doctor.yml +++ b/.github/workflows/release-doctor.yml @@ -1,6 +1,8 @@ name: Release Doctor on: pull_request: + branches: + - main workflow_dispatch: jobs: diff --git a/.gitignore b/.gitignore index 9a5858a..3eed6dd 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +.prism.log node_modules yarn-error.log codegen.log diff --git a/.release-please-manifest.json b/.release-please-manifest.json index 63c033c..466df71 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "0.0.4" + ".": "0.1.0" } diff --git a/.stats.yml b/.stats.yml index a479c92..4bb711f 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,2 +1,2 @@ configured_endpoints: 38 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/plastic-labs%2Fhoncho-7967581df14089cda98ce7bd258102d5da5ec541dc5b17aa918f96be11a2bde8.yml +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/plastic-labs%2Fhoncho-9b368f4c227f4695fb1b16d44996ca0dcaab52c7ee1433491ce2989fee846115.yml diff --git a/CHANGELOG.md b/CHANGELOG.md index 6836dce..ea7c3eb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,28 @@ # Changelog +## 0.1.0 (2024-08-01) + +Full Changelog: [v0.0.4...v0.1.0](https://github.com/plastic-labs/honcho-node/compare/v0.0.4...v0.1.0) + +### Features + +* **api:** OpenAPI spec update via Stainless API ([#24](https://github.com/plastic-labs/honcho-node/issues/24)) ([f1760b0](https://github.com/plastic-labs/honcho-node/commit/f1760b014808b25acacea1dbe58d0e67e78b0709)) +* **api:** update via SDK Studio ([#19](https://github.com/plastic-labs/honcho-node/issues/19)) ([d58ce64](https://github.com/plastic-labs/honcho-node/commit/d58ce641232a10967d41d45be9ff159f3c6f1583)) +* **api:** update via SDK Studio ([#25](https://github.com/plastic-labs/honcho-node/issues/25)) ([d2b2c76](https://github.com/plastic-labs/honcho-node/commit/d2b2c76c4a28c3f2452492aedb240d563f33238c)) + + +### Bug Fixes + +* **compat:** remove ReadableStream polyfill redundant since node v16 ([#21](https://github.com/plastic-labs/honcho-node/issues/21)) ([697784b](https://github.com/plastic-labs/honcho-node/commit/697784bdd6d64b700cdc6ab1572a4ad130725d6b)) + + +### Chores + +* **docs:** fix incorrect client var names ([#22](https://github.com/plastic-labs/honcho-node/issues/22)) ([b19d486](https://github.com/plastic-labs/honcho-node/commit/b19d4865708dee7c6f5ac0af9ad74487709554e7)) +* **internal:** add constant for default timeout ([#23](https://github.com/plastic-labs/honcho-node/issues/23)) ([67519e0](https://github.com/plastic-labs/honcho-node/commit/67519e0ebfbf52350f0dcbfd4b699285d5b765ec)) +* **internal:** codegen related update ([#16](https://github.com/plastic-labs/honcho-node/issues/16)) ([8fd8961](https://github.com/plastic-labs/honcho-node/commit/8fd89613e59d87ecd9bf6822d69dc01e17cba411)) +* **tests:** update prism version ([#18](https://github.com/plastic-labs/honcho-node/issues/18)) ([09748fe](https://github.com/plastic-labs/honcho-node/commit/09748fe2cec34eb7c7d7ed1f839212e4c65642ea)) + ## 0.0.4 (2024-05-23) Full Changelog: [v0.0.3...v0.0.4](https://github.com/plastic-labs/honcho-node/compare/v0.0.3...v0.0.4) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 6c5fd6a..d4a307c 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -55,12 +55,12 @@ cd honcho-node # With yarn yarn link cd ../my-package -yarn link honcho-ai +yarn link honcho # With pnpm pnpm link --global cd ../my-package -pnpm link -—global honcho-ai +pnpm link -—global honcho ``` ## Running tests diff --git a/README.md b/README.md index 6b69237..96b9490 100644 --- a/README.md +++ b/README.md @@ -1,17 +1,17 @@ -# Honcho Node API Library +# honcho-ai API Library -[![NPM version](https://img.shields.io/npm/v/honcho-ai.svg)](https://npmjs.org/package/honcho-ai) +[![NPM version](https://img.shields.io/npm/v/honcho.svg)](https://npmjs.org/package/honcho) ![npm bundle size](https://img.shields.io/bundlephobia/minzip/honcho) This library provides convenient access to the Honcho REST API from server-side TypeScript or JavaScript. -The REST API documentation can be found [on docs.honcho.dev](https://docs.honcho.dev). The full API of this library can be found in [api.md](api.md). +The REST API documentation can be found on [docs.honcho.dev](https://docs.honcho.dev). The full API of this library can be found in [api.md](api.md). It is generated with [Stainless](https://www.stainlessapi.com/). ## Installation ```sh -npm install honcho-ai +npm install honcho ``` ## Usage @@ -20,15 +20,15 @@ The full API of this library can be found in [api.md](api.md). ```js -import Honcho from 'honcho-ai'; +import Honcho from 'honcho'; -const honcho = new Honcho({ +const client = new Honcho({ apiKey: process.env['HONCHO_API_KEY'], // This is the default and can be omitted - environment: 'demo', // defaults to 'local' + environment: 'local', // defaults to 'demo' }); async function main() { - const app = await honcho.apps.create({ name: 'string' }); + const app = await client.apps.create({ name: 'name' }); console.log(app.id); } @@ -42,16 +42,16 @@ This library includes TypeScript definitions for all request params and response ```ts -import Honcho from 'honcho-ai'; +import Honcho from 'honcho'; -const honcho = new Honcho({ +const client = new Honcho({ apiKey: process.env['HONCHO_API_KEY'], // This is the default and can be omitted - environment: 'demo', // defaults to 'local' + environment: 'local', // defaults to 'demo' }); async function main() { - const params: Honcho.AppCreateParams = { name: 'string' }; - const app: Honcho.App = await honcho.apps.create(params); + const params: Honcho.AppCreateParams = { name: 'name' }; + const app: Honcho.App = await client.apps.create(params); } main(); @@ -68,7 +68,7 @@ a subclass of `APIError` will be thrown: ```ts async function main() { - const app = await honcho.apps.create({ name: 'string' }).catch(async (err) => { + const app = await client.apps.create({ name: 'name' }).catch(async (err) => { if (err instanceof Honcho.APIError) { console.log(err.status); // 400 console.log(err.name); // BadRequestError @@ -106,12 +106,12 @@ You can use the `maxRetries` option to configure or disable this: ```js // Configure the default for all requests: -const honcho = new Honcho({ +const client = new Honcho({ maxRetries: 0, // default is 2 }); // Or, configure per-request: -await honcho.apps.create({ name: 'string' }, { +await client.apps.create({ name: 'name' }, { maxRetries: 5, }); ``` @@ -123,12 +123,12 @@ Requests time out after 1 minute by default. You can configure this with a `time ```ts // Configure the default for all requests: -const honcho = new Honcho({ +const client = new Honcho({ timeout: 20 * 1000, // 20 seconds (default is 1 minute) }); // Override per-request: -await honcho.apps.create({ name: 'string' }, { +await client.apps.create({ name: 'name' }, { timeout: 5 * 1000, }); ``` @@ -146,7 +146,7 @@ You can use `for await … of` syntax to iterate through items across all pages: async function fetchAllAppsUsers(params) { const allAppsUsers = []; // Automatically fetches more pages as needed. - for await (const user of honcho.apps.users.list('REPLACE_ME')) { + for await (const user of client.apps.users.list('REPLACE_ME')) { allAppsUsers.push(user); } return allAppsUsers; @@ -156,7 +156,7 @@ async function fetchAllAppsUsers(params) { Alternatively, you can make request a single page at a time: ```ts -let page = await honcho.apps.users.list('REPLACE_ME'); +let page = await client.apps.users.list('REPLACE_ME'); for (const user of page.items) { console.log(user); } @@ -178,13 +178,13 @@ You can also use the `.withResponse()` method to get the raw `Response` along wi ```ts -const honcho = new Honcho(); +const client = new Honcho(); -const response = await honcho.apps.create({ name: 'string' }).asResponse(); +const response = await client.apps.create({ name: 'name' }).asResponse(); console.log(response.headers.get('X-My-Header')); console.log(response.statusText); // access the underlying Response object -const { data: app, response: raw } = await honcho.apps.create({ name: 'string' }).withResponse(); +const { data: app, response: raw } = await client.apps.create({ name: 'name' }).withResponse(); console.log(raw.headers.get('X-My-Header')); console.log(app.id); ``` @@ -244,11 +244,11 @@ add the following import before your first import `from "Honcho"`: ```ts // Tell TypeScript and the package to use the global web fetch instead of node-fetch. // Note, despite the name, this does not add any polyfills, but expects them to be provided if needed. -import 'honcho-ai/shims/web'; -import Honcho from 'honcho-ai'; +import 'honcho/shims/web'; +import Honcho from 'honcho'; ``` -To do the inverse, add `import "honcho-ai/shims/node"` (which does import polyfills). +To do the inverse, add `import "honcho/shims/node"` (which does import polyfills). This can also be useful if you are getting the wrong TypeScript types for `Response` ([more details](https://github.com/plastic-labs/honcho-node/tree/main/src/_shims#readme)). ### Logging and middleware @@ -258,7 +258,7 @@ which can be used to inspect or alter the `Request` or `Response` before/after e ```ts import { fetch } from 'undici'; // as one example -import Honcho from 'honcho-ai'; +import Honcho from 'honcho'; const client = new Honcho({ fetch: async (url: RequestInfo, init?: RequestInit): Promise => { @@ -285,13 +285,13 @@ import http from 'http'; import { HttpsProxyAgent } from 'https-proxy-agent'; // Configure the default for all requests: -const honcho = new Honcho({ +const client = new Honcho({ httpAgent: new HttpsProxyAgent(process.env.PROXY_URL), }); // Override per-request: -await honcho.apps.create( - { name: 'string' }, +await client.apps.create( + { name: 'name' }, { httpAgent: new http.Agent({ keepAlive: false }), }, @@ -316,14 +316,6 @@ TypeScript >= 4.5 is supported. The following runtimes are supported: -- Node.js 18 LTS or later ([non-EOL](https://endoflife.date/nodejs)) versions. -- Deno v1.28.0 or higher, using `import Honcho from "npm:honcho-ai"`. -- Bun 1.0 or later. -- Cloudflare Workers. -- Vercel Edge Runtime. -- Jest 28 or greater with the `"node"` environment (`"jsdom"` is not supported at this time). -- Nitro v2.6 or greater. - Note that React Native is not supported at this time. If you are interested in other runtime environments, please open or upvote an issue on GitHub. diff --git a/jest.config.ts b/jest.config.ts index 751cc62..0b5e735 100644 --- a/jest.config.ts +++ b/jest.config.ts @@ -7,9 +7,9 @@ const config: JestConfigWithTsJest = { '^.+\\.(t|j)sx?$': ['@swc/jest', { sourceMaps: 'inline' }], }, moduleNameMapper: { - '^honcho-ai$': '/src/index.ts', - '^honcho-ai/_shims/auto/(.*)$': '/src/_shims/auto/$1-node', - '^honcho-ai/(.*)$': '/src/$1', + '^honcho$': '/src/index.ts', + '^honcho/_shims/auto/(.*)$': '/src/_shims/auto/$1-node', + '^honcho/(.*)$': '/src/$1', }, modulePathIgnorePatterns: [ '/ecosystem-tests/', diff --git a/package.json b/package.json index 2eb5b2e..ed63f6d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { - "name": "honcho-ai", - "version": "0.0.4", + "name": "honcho", + "version": "0.1.0", "description": "The official TypeScript library for the Honcho API", "author": "Honcho ", "types": "dist/index.d.ts", @@ -16,7 +16,6 @@ "scripts": { "test": "./scripts/test", "build": "./scripts/build", - "prepack": "echo 'to pack, run yarn build && (cd dist; yarn pack)' && exit 1", "prepublishOnly": "echo 'to publish, run yarn build && (cd dist; yarn publish)' && exit 1", "format": "prettier --write --cache --cache-strategy metadata . !dist", "prepare": "if ./scripts/utils/check-is-in-git-install.sh; then ./scripts/build; fi", @@ -31,8 +30,7 @@ "agentkeepalive": "^4.2.1", "form-data-encoder": "1.7.2", "formdata-node": "^4.3.2", - "node-fetch": "^2.6.7", - "web-streams-polyfill": "^3.2.1" + "node-fetch": "^2.6.7" }, "devDependencies": { "@swc/core": "^1.3.102", @@ -61,8 +59,8 @@ "./shims/web.mjs" ], "imports": { - "honcho-ai": ".", - "honcho-ai/*": "./src/*" + "honcho": ".", + "honcho/*": "./src/*" }, "exports": { "./_shims/auto/*": { diff --git a/scripts/build b/scripts/build index 4c05d10..a60d4e7 100755 --- a/scripts/build +++ b/scripts/build @@ -8,7 +8,7 @@ node scripts/utils/check-version.cjs # Build into dist and will publish the package from there, # so that src/resources/foo.ts becomes /resources/foo.js -# This way importing from `"honcho-ai/resources/foo"` works +# This way importing from `"honcho/resources/foo"` works # even with `"moduleResolution": "node"` rm -rf dist; mkdir dist @@ -32,7 +32,7 @@ npm exec tsc-multi # copy over handwritten .js/.mjs/.d.ts files cp src/_shims/*.{d.ts,js,mjs,md} dist/_shims cp src/_shims/auto/*.{d.ts,js,mjs} dist/_shims/auto -# we need to add exports = module.exports = Honcho Node to index.js; +# we need to add exports = module.exports = honcho-ai to index.js; # No way to get that from index.ts because it would cause compile errors # when building .mjs node scripts/utils/fix-index-exports.cjs @@ -47,8 +47,8 @@ node scripts/utils/postprocess-files.cjs # make sure that nothing crashes when we require the output CJS or # import the output ESM -(cd dist && node -e 'require("honcho-ai")') -(cd dist && node -e 'import("honcho-ai")' --input-type=module) +(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 ] then diff --git a/scripts/mock b/scripts/mock index fe89a1d..f586157 100755 --- a/scripts/mock +++ b/scripts/mock @@ -21,7 +21,7 @@ echo "==> Starting mock server with URL ${URL}" # Run prism mock on the given spec if [ "$1" == "--daemon" ]; then - npm exec --package=@stoplight/prism-cli@~5.8 -- prism mock "$URL" &> .prism.log & + npm exec --package=@stainless-api/prism-cli@5.8.4 -- prism mock "$URL" &> .prism.log & # Wait for server to come online echo -n "Waiting for server" @@ -37,5 +37,5 @@ if [ "$1" == "--daemon" ]; then echo else - npm exec --package=@stoplight/prism-cli@~5.8 -- prism mock "$URL" + npm exec --package=@stainless-api/prism-cli@5.8.4 -- prism mock "$URL" fi diff --git a/scripts/utils/postprocess-files.cjs b/scripts/utils/postprocess-files.cjs index 1c79e83..d8e0c91 100644 --- a/scripts/utils/postprocess-files.cjs +++ b/scripts/utils/postprocess-files.cjs @@ -2,7 +2,7 @@ const fs = require('fs'); const path = require('path'); const { parse } = require('@typescript-eslint/parser'); -const pkgImportPath = process.env['PKG_IMPORT_PATH'] ?? 'honcho-ai/'; +const pkgImportPath = process.env['PKG_IMPORT_PATH'] ?? 'honcho/'; const distDir = process.env['DIST_PATH'] ? @@ -142,7 +142,7 @@ async function postprocess() { if (file.endsWith('.d.ts')) { // work around bad tsc behavior - // if we have `import { type Readable } from 'honcho-ai/_shims/index'`, + // if we have `import { type Readable } from 'honcho/_shims/index'`, // tsc sometimes replaces `Readable` with `import("stream").Readable` inline // in the output .d.ts transformed = transformed.replace(/import\("stream"\).Readable/g, 'Readable'); diff --git a/src/_shims/README.md b/src/_shims/README.md index ef0d8c2..5ff23fe 100644 --- a/src/_shims/README.md +++ b/src/_shims/README.md @@ -1,9 +1,9 @@ # 👋 Wondering what everything in here does? -`honcho-ai` supports a wide variety of runtime environments like Node.js, Deno, Bun, browsers, and various +`honcho` supports a wide variety of runtime environments like Node.js, Deno, Bun, browsers, and various edge runtimes, as well as both CommonJS (CJS) and EcmaScript Modules (ESM). -To do this, `honcho-ai` provides shims for either using `node-fetch` when in Node (because `fetch` is still experimental there) or the global `fetch` API built into the environment when not in Node. +To do this, `honcho` provides shims for either using `node-fetch` when in Node (because `fetch` is still experimental there) or the global `fetch` API built into the environment when not in Node. It uses [conditional exports](https://nodejs.org/api/packages.html#conditional-exports) to automatically select the correct shims for each environment. However, conditional exports are a fairly new @@ -15,32 +15,32 @@ getting the wrong raw `Response` type from `.asResponse()`, for example. The user can work around these issues by manually importing one of: -- `import 'honcho-ai/shims/node'` -- `import 'honcho-ai/shims/web'` +- `import 'honcho/shims/node'` +- `import 'honcho/shims/web'` All of the code here in `_shims` handles selecting the automatic default shims or manual overrides. ### How it works - Runtime -Runtime shims get installed by calling `setShims` exported by `honcho-ai/_shims/registry`. +Runtime shims get installed by calling `setShims` exported by `honcho/_shims/registry`. -Manually importing `honcho-ai/shims/node` or `honcho-ai/shims/web`, calls `setShims` with the respective runtime shims. +Manually importing `honcho/shims/node` or `honcho/shims/web`, calls `setShims` with the respective runtime shims. -All client code imports shims from `honcho-ai/_shims/index`, which: +All client code imports shims from `honcho/_shims/index`, which: - checks if shims have been set manually -- if not, calls `setShims` with the shims from `honcho-ai/_shims/auto/runtime` -- re-exports the installed shims from `honcho-ai/_shims/registry`. +- if not, calls `setShims` with the shims from `honcho/_shims/auto/runtime` +- re-exports the installed shims from `honcho/_shims/registry`. -`honcho-ai/_shims/auto/runtime` exports web runtime shims. -If the `node` export condition is set, the export map replaces it with `honcho-ai/_shims/auto/runtime-node`. +`honcho/_shims/auto/runtime` exports web runtime shims. +If the `node` export condition is set, the export map replaces it with `honcho/_shims/auto/runtime-node`. ### How it works - Type time -All client code imports shim types from `honcho-ai/_shims/index`, which selects the manual types from `honcho-ai/_shims/manual-types` if they have been declared, otherwise it exports the auto types from `honcho-ai/_shims/auto/types`. +All client code imports shim types from `honcho/_shims/index`, which selects the manual types from `honcho/_shims/manual-types` if they have been declared, otherwise it exports the auto types from `honcho/_shims/auto/types`. -`honcho-ai/_shims/manual-types` exports an empty namespace. -Manually importing `honcho-ai/shims/node` or `honcho-ai/shims/web` merges declarations into this empty namespace, so they get picked up by `honcho-ai/_shims/index`. +`honcho/_shims/manual-types` exports an empty namespace. +Manually importing `honcho/shims/node` or `honcho/shims/web` merges declarations into this empty namespace, so they get picked up by `honcho/_shims/index`. -`honcho-ai/_shims/auto/types` exports web type definitions. -If the `node` export condition is set, the export map replaces it with `honcho-ai/_shims/auto/types-node`, though TS only picks this up if `"moduleResolution": "nodenext"` or `"moduleResolution": "bundler"`. +`honcho/_shims/auto/types` exports web type definitions. +If the `node` export condition is set, the export map replaces it with `honcho/_shims/auto/types-node`, though TS only picks this up if `"moduleResolution": "nodenext"` or `"moduleResolution": "bundler"`. diff --git a/src/_shims/index.d.ts b/src/_shims/index.d.ts index e0a4587..13f102a 100644 --- a/src/_shims/index.d.ts +++ b/src/_shims/index.d.ts @@ -2,7 +2,7 @@ * Disclaimer: modules in _shims aren't intended to be imported by SDK users. */ import { manual } from './manual-types'; -import * as auto from 'honcho-ai/_shims/auto/types'; +import * as auto from 'honcho/_shims/auto/types'; import { type RequestOptions } from '../core'; type SelectType = unknown extends Manual ? Auto : Manual; diff --git a/src/_shims/index.js b/src/_shims/index.js index 017f781..dc692ed 100644 --- a/src/_shims/index.js +++ b/src/_shims/index.js @@ -2,7 +2,7 @@ * Disclaimer: modules in _shims aren't intended to be imported by SDK users. */ const shims = require('./registry'); -const auto = require('honcho-ai/_shims/auto/runtime'); +const auto = require('honcho/_shims/auto/runtime'); if (!shims.kind) shims.setShims(auto.getRuntime(), { auto: true }); for (const property of Object.keys(shims)) { Object.defineProperty(exports, property, { diff --git a/src/_shims/index.mjs b/src/_shims/index.mjs index a1391a4..8442380 100644 --- a/src/_shims/index.mjs +++ b/src/_shims/index.mjs @@ -2,6 +2,6 @@ * Disclaimer: modules in _shims aren't intended to be imported by SDK users. */ import * as shims from './registry.mjs'; -import * as auto from 'honcho-ai/_shims/auto/runtime'; +import * as auto from 'honcho/_shims/auto/runtime'; if (!shims.kind) shims.setShims(auto.getRuntime(), { auto: true }); export * from './registry.mjs'; diff --git a/src/_shims/manual-types.d.ts b/src/_shims/manual-types.d.ts index 1501772..32a4ba3 100644 --- a/src/_shims/manual-types.d.ts +++ b/src/_shims/manual-types.d.ts @@ -4,8 +4,8 @@ /** * Types will get added to this namespace when you import one of the following: * - * import 'honcho-ai/shims/node' - * import 'honcho-ai/shims/web' + * import 'honcho/shims/node' + * import 'honcho/shims/web' * * Importing more than one will cause type and runtime errors. */ diff --git a/src/_shims/node-runtime.ts b/src/_shims/node-runtime.ts index a9c42eb..ab9f2ab 100644 --- a/src/_shims/node-runtime.ts +++ b/src/_shims/node-runtime.ts @@ -13,9 +13,7 @@ import { Readable } from 'node:stream'; import { type RequestOptions } from '../core'; import { MultipartBody } from './MultipartBody'; import { type Shims } from './registry'; - -// @ts-ignore (this package does not have proper export maps for this export) -import { ReadableStream } from 'web-streams-polyfill/dist/ponyfill.es2018.js'; +import { ReadableStream } from 'node:stream/web'; type FileFromPathOptions = Omit; diff --git a/src/_shims/registry.ts b/src/_shims/registry.ts index ebea666..ced84aa 100644 --- a/src/_shims/registry.ts +++ b/src/_shims/registry.ts @@ -42,13 +42,11 @@ export let isFsReadStream: Shims['isFsReadStream'] | undefined = undefined; export function setShims(shims: Shims, options: { auto: boolean } = { auto: false }) { if (auto) { throw new Error( - `you must \`import 'honcho-ai/shims/${shims.kind}'\` before importing anything else from honcho-ai`, + `you must \`import 'honcho/shims/${shims.kind}'\` before importing anything else from honcho`, ); } if (kind) { - throw new Error( - `can't \`import 'honcho-ai/shims/${shims.kind}'\` after \`import 'honcho-ai/shims/${kind}'\``, - ); + throw new Error(`can't \`import 'honcho/shims/${shims.kind}'\` after \`import 'honcho/shims/${kind}'\``); } auto = options.auto; kind = shims.kind; diff --git a/src/_shims/web-runtime.ts b/src/_shims/web-runtime.ts index afe73a5..e02b68a 100644 --- a/src/_shims/web-runtime.ts +++ b/src/_shims/web-runtime.ts @@ -9,9 +9,9 @@ export function getRuntime({ manuallyImported }: { manuallyImported?: boolean } const recommendation = manuallyImported ? `You may need to use polyfills` - : `Add one of these imports before your first \`import … from 'honcho-ai'\`: -- \`import 'honcho-ai/shims/node'\` (if you're running on Node) -- \`import 'honcho-ai/shims/web'\` (otherwise) + : `Add one of these imports before your first \`import … from 'honcho'\`: +- \`import 'honcho/shims/node'\` (if you're running on Node) +- \`import 'honcho/shims/web'\` (otherwise) `; let _fetch, _Request, _Response, _Headers; diff --git a/src/core.ts b/src/core.ts index bed42d6..8c73891 100644 --- a/src/core.ts +++ b/src/core.ts @@ -18,7 +18,7 @@ import { type HeadersInit, } from './_shims/index'; export { type Response }; -import { isMultipartBody } from './uploads'; +import { BlobLike, isBlobLike, isMultipartBody } from './uploads'; export { maybeMultipartFormRequestOptions, multipartFormRequestOptions, @@ -97,9 +97,9 @@ export class APIPromise extends Promise { * * 👋 Getting the wrong TypeScript type for `Response`? * Try setting `"moduleResolution": "NodeNext"` if you can, - * or add one of these imports before your first `import … from 'honcho-ai'`: - * - `import 'honcho-ai/shims/node'` (if you're running on Node) - * - `import 'honcho-ai/shims/web'` (otherwise) + * or add one of these imports before your first `import … from 'honcho'`: + * - `import 'honcho/shims/node'` (if you're running on Node) + * - `import 'honcho/shims/web'` (otherwise) */ asResponse(): Promise { return this.responsePromise.then((p) => p.response); @@ -113,9 +113,9 @@ export class APIPromise extends Promise { * * 👋 Getting the wrong TypeScript type for `Response`? * Try setting `"moduleResolution": "NodeNext"` if you can, - * or add one of these imports before your first `import … from 'honcho-ai'`: - * - `import 'honcho-ai/shims/node'` (if you're running on Node) - * - `import 'honcho-ai/shims/web'` (otherwise) + * or add one of these imports before your first `import … from 'honcho'`: + * - `import 'honcho/shims/node'` (if you're running on Node) + * - `import 'honcho/shims/web'` (otherwise) */ async withResponse(): Promise<{ data: T; response: Response }> { const [data, response] = await Promise.all([this.parse(), this.asResponse()]); @@ -235,7 +235,17 @@ export abstract class APIClient { path: string, opts?: PromiseOrValue>, ): APIPromise { - return this.request(Promise.resolve(opts).then((opts) => ({ method, path, ...opts }))); + return this.request( + Promise.resolve(opts).then(async (opts) => { + const body = + opts && isBlobLike(opts?.body) ? new DataView(await opts.body.arrayBuffer()) + : opts?.body instanceof DataView ? opts.body + : opts?.body instanceof ArrayBuffer ? new DataView(opts.body) + : opts && ArrayBuffer.isView(opts?.body) ? new DataView(opts.body.buffer) + : opts?.body; + return { method, path, ...opts, body }; + }), + ); } getAPIList = AbstractPage>( @@ -257,6 +267,8 @@ export abstract class APIClient { const encoded = encoder.encode(body); return encoded.length.toString(); } + } else if (ArrayBuffer.isView(body)) { + return body.byteLength.toString(); } return null; @@ -266,7 +278,9 @@ export abstract class APIClient { const { method, path, query, headers: headers = {} } = options; const body = - isMultipartBody(options.body) ? options.body.body + ArrayBuffer.isView(options.body) || (options.__binaryRequest && typeof options.body === 'string') ? + options.body + : isMultipartBody(options.body) ? options.body.body : options.body ? JSON.stringify(options.body, null, 2) : null; const contentLength = this.calculateContentLength(body); @@ -721,7 +735,9 @@ export type Headers = Record; export type DefaultQuery = Record; export type KeysEnum = { [P in keyof Required]: true }; -export type RequestOptions | Readable> = { +export type RequestOptions< + Req = unknown | Record | Readable | BlobLike | ArrayBufferView | ArrayBuffer, +> = { method?: HTTPMethod; path?: string; query?: Req | undefined; @@ -735,6 +751,7 @@ export type RequestOptions | Readable> = signal?: AbortSignal | undefined | null; idempotencyKey?: string; + __binaryRequest?: boolean | undefined; __binaryResponse?: boolean | undefined; }; @@ -755,6 +772,7 @@ const requestOptionsKeys: KeysEnum = { signal: true, idempotencyKey: true, + __binaryRequest: true, __binaryResponse: true, }; @@ -767,10 +785,11 @@ export const isRequestOptions = (obj: unknown): obj is RequestOptions => { ); }; -export type FinalRequestOptions | Readable> = RequestOptions & { - method: HTTPMethod; - path: string; -}; +export type FinalRequestOptions | Readable | DataView> = + RequestOptions & { + method: HTTPMethod; + path: string; + }; declare const Deno: any; declare const EdgeRuntime: any; diff --git a/src/index.ts b/src/index.ts index 0c0325f..3e6c217 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,15 +1,15 @@ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. -import * as Core from './core'; import * as Errors from './error'; -import { type Agent } from './_shims/index'; import * as Uploads from './uploads'; +import { type Agent } from './_shims/index'; +import * as Core from './core'; import * as Pagination from './pagination'; import * as API from './resources/index'; const environments = { - local: 'http://localhost:8000', demo: 'https://demo.honcho.dev', + local: 'http://localhost:8000', }; type Environment = keyof typeof environments; @@ -23,8 +23,8 @@ export interface ClientOptions { * Specifies the environment to use for the API. * * Each environment maps to a different base URL: - * - `local` corresponds to `http://localhost:8000` * - `demo` corresponds to `https://demo.honcho.dev` + * - `local` corresponds to `http://localhost:8000` */ environment?: Environment; @@ -85,7 +85,9 @@ export interface ClientOptions { defaultQuery?: Core.DefaultQuery; } -/** API Client for interfacing with the Honcho API. */ +/** + * API Client for interfacing with the Honcho API. + */ export class Honcho extends Core.APIClient { apiKey: string | null; @@ -95,8 +97,8 @@ export class Honcho extends Core.APIClient { * API Client for interfacing with the Honcho API. * * @param {string | null | undefined} [opts.apiKey=process.env['HONCHO_API_KEY'] ?? null] - * @param {Environment} [opts.environment=local] - Specifies the environment URL to use for the API. - * @param {string} [opts.baseURL=process.env['HONCHO_BASE_URL'] ?? http://localhost:8000] - Override the default base URL for the API. + * @param {Environment} [opts.environment=demo] - Specifies the environment URL to use for the API. + * @param {string} [opts.baseURL=process.env['HONCHO_BASE_URL'] ?? https://demo.honcho.dev] - Override the default base URL for the API. * @param {number} [opts.timeout=1 minute] - The maximum amount of time (in milliseconds) the client will wait for a response before timing out. * @param {number} [opts.httpAgent] - An HTTP agent used to manage HTTP(s) connections. * @param {Core.Fetch} [opts.fetch] - Specify a custom `fetch` function implementation. @@ -113,7 +115,7 @@ export class Honcho extends Core.APIClient { apiKey, ...opts, baseURL, - environment: opts.environment ?? 'local', + environment: opts.environment ?? 'demo', }; if (baseURL && opts.environment) { @@ -123,12 +125,13 @@ export class Honcho extends Core.APIClient { } super({ - baseURL: options.baseURL || environments[options.environment || 'local'], + baseURL: options.baseURL || environments[options.environment || 'demo'], timeout: options.timeout ?? 60000 /* 1 minute */, httpAgent: options.httpAgent, maxRetries: options.maxRetries, fetch: options.fetch, }); + this._options = options; this.apiKey = apiKey; @@ -147,6 +150,19 @@ export class Honcho extends Core.APIClient { }; } + protected override validateHeaders(headers: Core.Headers, customHeaders: Core.Headers) { + if (this.apiKey && headers['authorization']) { + return; + } + if (customHeaders['authorization'] === null) { + return; + } + + throw new Error( + 'Could not resolve authentication method. Expected the apiKey to be set. Or for the "Authorization" headers to be explicitly omitted', + ); + } + protected override authHeaders(opts: Core.FinalRequestOptions): Core.Headers { if (this.apiKey == null) { return {}; @@ -155,6 +171,7 @@ export class Honcho extends Core.APIClient { } static Honcho = this; + static DEFAULT_TIMEOUT = 60000; // 1 minute static HonchoError = Errors.HonchoError; static APIError = Errors.APIError; diff --git a/src/resources/apps/apps.ts b/src/resources/apps/apps.ts index 46b2282..4a2e929 100644 --- a/src/resources/apps/apps.ts +++ b/src/resources/apps/apps.ts @@ -1,7 +1,7 @@ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. -import * as Core from '../../core'; import { APIResource } from '../../resource'; +import * as Core from '../../core'; import * as AppsAPI from './apps'; import * as UsersAPI from './users/users'; diff --git a/src/resources/apps/users/collections/collections.ts b/src/resources/apps/users/collections/collections.ts index 64ddf4a..35f1e3b 100644 --- a/src/resources/apps/users/collections/collections.ts +++ b/src/resources/apps/users/collections/collections.ts @@ -1,8 +1,8 @@ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. -import * as Core from '../../../../core'; import { APIResource } from '../../../../resource'; import { isRequestOptions } from '../../../../core'; +import * as Core from '../../../../core'; import * as CollectionsAPI from './collections'; import * as DocumentsAPI from './documents'; import { Page, type PageParams } from '../../../../pagination'; @@ -163,9 +163,9 @@ export interface CollectionCreateParams { } export interface CollectionUpdateParams { - name: string; - metadata?: Record | null; + + name?: string | null; } export interface CollectionListParams extends PageParams { diff --git a/src/resources/apps/users/collections/documents.ts b/src/resources/apps/users/collections/documents.ts index c7e7180..a89863f 100644 --- a/src/resources/apps/users/collections/documents.ts +++ b/src/resources/apps/users/collections/documents.ts @@ -1,8 +1,8 @@ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. -import * as Core from '../../../../core'; import { APIResource } from '../../../../resource'; import { isRequestOptions } from '../../../../core'; +import * as Core from '../../../../core'; import * as DocumentsAPI from './documents'; import { Page, type PageParams } from '../../../../pagination'; diff --git a/src/resources/apps/users/sessions/messages.ts b/src/resources/apps/users/sessions/messages.ts index 5395388..8387161 100644 --- a/src/resources/apps/users/sessions/messages.ts +++ b/src/resources/apps/users/sessions/messages.ts @@ -1,8 +1,8 @@ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. -import * as Core from '../../../../core'; import { APIResource } from '../../../../resource'; import { isRequestOptions } from '../../../../core'; +import * as Core from '../../../../core'; import * as MessagesAPI from './messages'; import { Page, type PageParams } from '../../../../pagination'; diff --git a/src/resources/apps/users/sessions/metamessages.ts b/src/resources/apps/users/sessions/metamessages.ts index 916ab4d..156dd4e 100644 --- a/src/resources/apps/users/sessions/metamessages.ts +++ b/src/resources/apps/users/sessions/metamessages.ts @@ -1,22 +1,22 @@ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. -import * as Core from '../../../../core'; import { APIResource } from '../../../../resource'; import { isRequestOptions } from '../../../../core'; +import * as Core from '../../../../core'; import * as MetamessagesAPI from './metamessages'; import { Page, type PageParams } from '../../../../pagination'; export class Metamessages extends APIResource { /** - * Adds a message to a session + * Adds a metamessage to a session * * Args: app_id (uuid.UUID): The ID of the app representing the client application * using honcho user_id (str): The User ID representing the user, managed by the - * user session_id (int): The ID of the Session to add the message to message - * (schemas.MessageCreate): The Message object to add containing the message - * content and type + * user session_id (int): The ID of the Session to add the metamessage to + * metamessage (schemas.MetamessageCreate): The Metamessage object to add + * containing the metamessage content and type * - * Returns: schemas.Message: The Message object of the added message + * Returns: schemas.Metamessage: The Metamessage object of the added metamessage * * Raises: HTTPException: If the session is not found */ diff --git a/src/resources/apps/users/sessions/sessions.ts b/src/resources/apps/users/sessions/sessions.ts index 1f6429c..f697aeb 100644 --- a/src/resources/apps/users/sessions/sessions.ts +++ b/src/resources/apps/users/sessions/sessions.ts @@ -1,8 +1,8 @@ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. -import * as Core from '../../../../core'; import { APIResource } from '../../../../resource'; import { isRequestOptions } from '../../../../core'; +import * as Core from '../../../../core'; import * as SessionsAPI from './sessions'; import * as MessagesAPI from './messages'; import * as MetamessagesAPI from './metamessages'; @@ -18,7 +18,7 @@ export class Sessions extends APIResource { * Args: app_id (uuid.UUID): The ID of the app representing the client application * using honcho user_id (uuid.UUID): The User ID representing the user, managed by * the user session (schemas.SessionCreate): The Session object containing any - * metadata and a location ID + * metadata * * Returns: schemas.Session: The Session object of the new Session */ @@ -56,8 +56,7 @@ export class Sessions extends APIResource { * * Args: app_id (uuid.UUID): The ID of the app representing the client application * using honcho user_id (uuid.UUID): The User ID representing the user, managed by - * the user location_id (str, optional): Optional Location ID representing the - * location of a session + * the user * * Returns: list[schemas.Session]: List of Session objects */ @@ -181,8 +180,6 @@ export interface Session { is_active: boolean; - location_id: string; - metadata: Record; user_id: string; @@ -193,8 +190,6 @@ export type SessionDeleteResponse = unknown; export type SessionStreamResponse = unknown; export interface SessionCreateParams { - location_id: string; - metadata?: Record | null; } @@ -207,8 +202,6 @@ export interface SessionListParams extends PageParams { is_active?: boolean | null; - location_id?: string | null; - reverse?: boolean | null; } diff --git a/src/resources/apps/users/users.ts b/src/resources/apps/users/users.ts index 1fca410..97c4641 100644 --- a/src/resources/apps/users/users.ts +++ b/src/resources/apps/users/users.ts @@ -1,8 +1,8 @@ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. -import * as Core from '../../../core'; import { APIResource } from '../../../resource'; import { isRequestOptions } from '../../../core'; +import * as Core from '../../../core'; import * as UsersAPI from './users'; import * as CollectionsAPI from './collections/collections'; import * as SessionsAPI from './sessions/sessions'; diff --git a/src/version.ts b/src/version.ts index 79eabb0..1baa228 100644 --- a/src/version.ts +++ b/src/version.ts @@ -1 +1 @@ -export const VERSION = '0.0.4'; // x-release-please-version +export const VERSION = '0.1.0'; // x-release-please-version diff --git a/tests/api-resources/apps/apps.test.ts b/tests/api-resources/apps/apps.test.ts index bebd006..a8f7e1b 100644 --- a/tests/api-resources/apps/apps.test.ts +++ b/tests/api-resources/apps/apps.test.ts @@ -1,16 +1,16 @@ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. -import Honcho from 'honcho-ai'; +import Honcho from 'honcho'; import { Response } from 'node-fetch'; -const honcho = new Honcho({ +const client = new Honcho({ apiKey: 'My API Key', baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010', }); describe('resource apps', () => { test('create: only required params', async () => { - const responsePromise = honcho.apps.create({ name: 'string' }); + const responsePromise = client.apps.create({ name: 'name' }); const rawResponse = await responsePromise.asResponse(); expect(rawResponse).toBeInstanceOf(Response); const response = await responsePromise; @@ -21,11 +21,11 @@ describe('resource apps', () => { }); test('create: required and optional params', async () => { - const response = await honcho.apps.create({ name: 'string', metadata: { foo: 'bar' } }); + const response = await client.apps.create({ name: 'name', metadata: { foo: 'bar' } }); }); test('update', async () => { - const responsePromise = honcho.apps.update('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', {}); + const responsePromise = client.apps.update('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', {}); const rawResponse = await responsePromise.asResponse(); expect(rawResponse).toBeInstanceOf(Response); const response = await responsePromise; @@ -36,7 +36,7 @@ describe('resource apps', () => { }); test('get', async () => { - const responsePromise = honcho.apps.get('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e'); + const responsePromise = client.apps.get('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e'); const rawResponse = await responsePromise.asResponse(); expect(rawResponse).toBeInstanceOf(Response); const response = await responsePromise; @@ -49,12 +49,12 @@ describe('resource apps', () => { test('get: request options instead of params are passed correctly', async () => { // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error await expect( - honcho.apps.get('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', { path: '/_stainless_unknown_path' }), + client.apps.get('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', { path: '/_stainless_unknown_path' }), ).rejects.toThrow(Honcho.NotFoundError); }); test('getByName', async () => { - const responsePromise = honcho.apps.getByName('string'); + const responsePromise = client.apps.getByName('name'); const rawResponse = await responsePromise.asResponse(); expect(rawResponse).toBeInstanceOf(Response); const response = await responsePromise; @@ -66,13 +66,13 @@ describe('resource apps', () => { test('getByName: request options instead of params are passed correctly', async () => { // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error - await expect(honcho.apps.getByName('string', { path: '/_stainless_unknown_path' })).rejects.toThrow( + await expect(client.apps.getByName('name', { path: '/_stainless_unknown_path' })).rejects.toThrow( Honcho.NotFoundError, ); }); test('getOrCreate', async () => { - const responsePromise = honcho.apps.getOrCreate('string'); + const responsePromise = client.apps.getOrCreate('name'); const rawResponse = await responsePromise.asResponse(); expect(rawResponse).toBeInstanceOf(Response); const response = await responsePromise; @@ -84,7 +84,7 @@ describe('resource apps', () => { test('getOrCreate: request options instead of params are passed correctly', async () => { // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error - await expect(honcho.apps.getOrCreate('string', { path: '/_stainless_unknown_path' })).rejects.toThrow( + await expect(client.apps.getOrCreate('name', { path: '/_stainless_unknown_path' })).rejects.toThrow( Honcho.NotFoundError, ); }); diff --git a/tests/api-resources/apps/users/collections/collections.test.ts b/tests/api-resources/apps/users/collections/collections.test.ts index 21c043c..9efe7e6 100644 --- a/tests/api-resources/apps/users/collections/collections.test.ts +++ b/tests/api-resources/apps/users/collections/collections.test.ts @@ -1,19 +1,19 @@ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. -import Honcho from 'honcho-ai'; +import Honcho from 'honcho'; import { Response } from 'node-fetch'; -const honcho = new Honcho({ +const client = new Honcho({ apiKey: 'My API Key', baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010', }); describe('resource collections', () => { test('create: only required params', async () => { - const responsePromise = honcho.apps.users.collections.create( + const responsePromise = client.apps.users.collections.create( '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - { name: 'string' }, + { name: 'name' }, ); const rawResponse = await responsePromise.asResponse(); expect(rawResponse).toBeInstanceOf(Response); @@ -25,19 +25,19 @@ describe('resource collections', () => { }); test('create: required and optional params', async () => { - const response = await honcho.apps.users.collections.create( + const response = await client.apps.users.collections.create( '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - { name: 'string', metadata: { foo: 'bar' } }, + { name: 'name', metadata: { foo: 'bar' } }, ); }); - test('update: only required params', async () => { - const responsePromise = honcho.apps.users.collections.update( + test('update', async () => { + const responsePromise = client.apps.users.collections.update( '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - { name: 'string' }, + {}, ); const rawResponse = await responsePromise.asResponse(); expect(rawResponse).toBeInstanceOf(Response); @@ -48,17 +48,8 @@ describe('resource collections', () => { expect(dataAndResponse.response).toBe(rawResponse); }); - test('update: required and optional params', async () => { - const response = await honcho.apps.users.collections.update( - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - { name: 'string', metadata: { foo: 'bar' } }, - ); - }); - test('list', async () => { - const responsePromise = honcho.apps.users.collections.list( + const responsePromise = client.apps.users.collections.list( '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', ); @@ -74,7 +65,7 @@ describe('resource collections', () => { test('list: request options instead of params are passed correctly', async () => { // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error await expect( - honcho.apps.users.collections.list( + client.apps.users.collections.list( '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', { path: '/_stainless_unknown_path' }, @@ -85,17 +76,17 @@ describe('resource collections', () => { test('list: request options and params are passed correctly', async () => { // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error await expect( - honcho.apps.users.collections.list( + client.apps.users.collections.list( '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - { filter: 'string', page: 1, reverse: true, size: 1 }, + { filter: 'filter', page: 1, reverse: true, size: 1 }, { path: '/_stainless_unknown_path' }, ), ).rejects.toThrow(Honcho.NotFoundError); }); test('delete', async () => { - const responsePromise = honcho.apps.users.collections.delete( + const responsePromise = client.apps.users.collections.delete( '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', @@ -112,7 +103,7 @@ describe('resource collections', () => { test('delete: request options instead of params are passed correctly', async () => { // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error await expect( - honcho.apps.users.collections.delete( + client.apps.users.collections.delete( '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', @@ -122,7 +113,7 @@ describe('resource collections', () => { }); test('get', async () => { - const responsePromise = honcho.apps.users.collections.get( + const responsePromise = client.apps.users.collections.get( '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', @@ -139,7 +130,7 @@ describe('resource collections', () => { test('get: request options instead of params are passed correctly', async () => { // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error await expect( - honcho.apps.users.collections.get( + client.apps.users.collections.get( '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', @@ -149,10 +140,10 @@ describe('resource collections', () => { }); test('getByName', async () => { - const responsePromise = honcho.apps.users.collections.getByName( + const responsePromise = client.apps.users.collections.getByName( '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - 'string', + 'name', ); const rawResponse = await responsePromise.asResponse(); expect(rawResponse).toBeInstanceOf(Response); @@ -166,21 +157,21 @@ describe('resource collections', () => { test('getByName: request options instead of params are passed correctly', async () => { // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error await expect( - honcho.apps.users.collections.getByName( + client.apps.users.collections.getByName( '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - 'string', + 'name', { path: '/_stainless_unknown_path' }, ), ).rejects.toThrow(Honcho.NotFoundError); }); test('query: only required params', async () => { - const responsePromise = honcho.apps.users.collections.query( + const responsePromise = client.apps.users.collections.query( '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - { query: 'string' }, + { query: 'query' }, ); const rawResponse = await responsePromise.asResponse(); expect(rawResponse).toBeInstanceOf(Response); @@ -192,11 +183,11 @@ describe('resource collections', () => { }); test('query: required and optional params', async () => { - const response = await honcho.apps.users.collections.query( + const response = await client.apps.users.collections.query( '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - { query: 'string', filter: 'string', top_k: 0 }, + { query: 'query', filter: 'filter', top_k: 0 }, ); }); }); diff --git a/tests/api-resources/apps/users/collections/documents.test.ts b/tests/api-resources/apps/users/collections/documents.test.ts index 403dee6..db6c165 100644 --- a/tests/api-resources/apps/users/collections/documents.test.ts +++ b/tests/api-resources/apps/users/collections/documents.test.ts @@ -1,20 +1,20 @@ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. -import Honcho from 'honcho-ai'; +import Honcho from 'honcho'; import { Response } from 'node-fetch'; -const honcho = new Honcho({ +const client = new Honcho({ apiKey: 'My API Key', baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010', }); describe('resource documents', () => { test('create: only required params', async () => { - const responsePromise = honcho.apps.users.collections.documents.create( + const responsePromise = client.apps.users.collections.documents.create( '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - { content: 'string' }, + { content: 'content' }, ); const rawResponse = await responsePromise.asResponse(); expect(rawResponse).toBeInstanceOf(Response); @@ -26,16 +26,16 @@ describe('resource documents', () => { }); test('create: required and optional params', async () => { - const response = await honcho.apps.users.collections.documents.create( + const response = await client.apps.users.collections.documents.create( '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - { content: 'string', metadata: { foo: 'bar' } }, + { content: 'content', metadata: { foo: 'bar' } }, ); }); test('update', async () => { - const responsePromise = honcho.apps.users.collections.documents.update( + const responsePromise = client.apps.users.collections.documents.update( '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', @@ -52,7 +52,7 @@ describe('resource documents', () => { }); test('list', async () => { - const responsePromise = honcho.apps.users.collections.documents.list( + const responsePromise = client.apps.users.collections.documents.list( '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', @@ -69,7 +69,7 @@ describe('resource documents', () => { test('list: request options instead of params are passed correctly', async () => { // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error await expect( - honcho.apps.users.collections.documents.list( + client.apps.users.collections.documents.list( '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', @@ -81,18 +81,18 @@ describe('resource documents', () => { test('list: request options and params are passed correctly', async () => { // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error await expect( - honcho.apps.users.collections.documents.list( + client.apps.users.collections.documents.list( '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - { filter: 'string', page: 1, reverse: true, size: 1 }, + { filter: 'filter', page: 1, reverse: true, size: 1 }, { path: '/_stainless_unknown_path' }, ), ).rejects.toThrow(Honcho.NotFoundError); }); test('delete', async () => { - const responsePromise = honcho.apps.users.collections.documents.delete( + const responsePromise = client.apps.users.collections.documents.delete( '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', @@ -110,7 +110,7 @@ describe('resource documents', () => { test('delete: request options instead of params are passed correctly', async () => { // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error await expect( - honcho.apps.users.collections.documents.delete( + client.apps.users.collections.documents.delete( '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', @@ -121,7 +121,7 @@ describe('resource documents', () => { }); test('get', async () => { - const responsePromise = honcho.apps.users.collections.documents.get( + const responsePromise = client.apps.users.collections.documents.get( '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', @@ -139,7 +139,7 @@ describe('resource documents', () => { test('get: request options instead of params are passed correctly', async () => { // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error await expect( - honcho.apps.users.collections.documents.get( + client.apps.users.collections.documents.get( '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', diff --git a/tests/api-resources/apps/users/sessions/messages.test.ts b/tests/api-resources/apps/users/sessions/messages.test.ts index 4253e41..d8702be 100644 --- a/tests/api-resources/apps/users/sessions/messages.test.ts +++ b/tests/api-resources/apps/users/sessions/messages.test.ts @@ -1,20 +1,20 @@ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. -import Honcho from 'honcho-ai'; +import Honcho from 'honcho'; import { Response } from 'node-fetch'; -const honcho = new Honcho({ +const client = new Honcho({ apiKey: 'My API Key', baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010', }); describe('resource messages', () => { test('create: only required params', async () => { - const responsePromise = honcho.apps.users.sessions.messages.create( + const responsePromise = client.apps.users.sessions.messages.create( '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - { content: 'string', is_user: true }, + { content: 'content', is_user: true }, ); const rawResponse = await responsePromise.asResponse(); expect(rawResponse).toBeInstanceOf(Response); @@ -26,16 +26,16 @@ describe('resource messages', () => { }); test('create: required and optional params', async () => { - const response = await honcho.apps.users.sessions.messages.create( + const response = await client.apps.users.sessions.messages.create( '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - { content: 'string', is_user: true, metadata: { foo: 'bar' } }, + { content: 'content', is_user: true, metadata: { foo: 'bar' } }, ); }); test('update', async () => { - const responsePromise = honcho.apps.users.sessions.messages.update( + const responsePromise = client.apps.users.sessions.messages.update( '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', @@ -52,7 +52,7 @@ describe('resource messages', () => { }); test('list', async () => { - const responsePromise = honcho.apps.users.sessions.messages.list( + const responsePromise = client.apps.users.sessions.messages.list( '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', @@ -69,7 +69,7 @@ describe('resource messages', () => { test('list: request options instead of params are passed correctly', async () => { // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error await expect( - honcho.apps.users.sessions.messages.list( + client.apps.users.sessions.messages.list( '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', @@ -81,18 +81,18 @@ describe('resource messages', () => { test('list: request options and params are passed correctly', async () => { // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error await expect( - honcho.apps.users.sessions.messages.list( + client.apps.users.sessions.messages.list( '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - { filter: 'string', page: 1, reverse: true, size: 1 }, + { filter: 'filter', page: 1, reverse: true, size: 1 }, { path: '/_stainless_unknown_path' }, ), ).rejects.toThrow(Honcho.NotFoundError); }); test('get', async () => { - const responsePromise = honcho.apps.users.sessions.messages.get( + const responsePromise = client.apps.users.sessions.messages.get( '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', @@ -110,7 +110,7 @@ describe('resource messages', () => { test('get: request options instead of params are passed correctly', async () => { // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error await expect( - honcho.apps.users.sessions.messages.get( + client.apps.users.sessions.messages.get( '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', diff --git a/tests/api-resources/apps/users/sessions/metamessages.test.ts b/tests/api-resources/apps/users/sessions/metamessages.test.ts index 9bd8c06..faa2a1b 100644 --- a/tests/api-resources/apps/users/sessions/metamessages.test.ts +++ b/tests/api-resources/apps/users/sessions/metamessages.test.ts @@ -1,20 +1,24 @@ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. -import Honcho from 'honcho-ai'; +import Honcho from 'honcho'; import { Response } from 'node-fetch'; -const honcho = new Honcho({ +const client = new Honcho({ apiKey: 'My API Key', baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010', }); describe('resource metamessages', () => { test('create: only required params', async () => { - const responsePromise = honcho.apps.users.sessions.metamessages.create( + const responsePromise = client.apps.users.sessions.metamessages.create( '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - { content: 'string', message_id: '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', metamessage_type: 'string' }, + { + content: 'content', + message_id: '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', + metamessage_type: 'metamessage_type', + }, ); const rawResponse = await responsePromise.asResponse(); expect(rawResponse).toBeInstanceOf(Response); @@ -26,21 +30,21 @@ describe('resource metamessages', () => { }); test('create: required and optional params', async () => { - const response = await honcho.apps.users.sessions.metamessages.create( + const response = await client.apps.users.sessions.metamessages.create( '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', { - content: 'string', + content: 'content', message_id: '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - metamessage_type: 'string', + metamessage_type: 'metamessage_type', metadata: { foo: 'bar' }, }, ); }); test('update: only required params', async () => { - const responsePromise = honcho.apps.users.sessions.metamessages.update( + const responsePromise = client.apps.users.sessions.metamessages.update( '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', @@ -57,7 +61,7 @@ describe('resource metamessages', () => { }); test('update: required and optional params', async () => { - const response = await honcho.apps.users.sessions.metamessages.update( + const response = await client.apps.users.sessions.metamessages.update( '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', @@ -65,13 +69,13 @@ describe('resource metamessages', () => { { message_id: '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', metadata: { foo: 'bar' }, - metamessage_type: 'string', + metamessage_type: 'metamessage_type', }, ); }); test('list', async () => { - const responsePromise = honcho.apps.users.sessions.metamessages.list( + const responsePromise = client.apps.users.sessions.metamessages.list( '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', @@ -88,7 +92,7 @@ describe('resource metamessages', () => { test('list: request options instead of params are passed correctly', async () => { // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error await expect( - honcho.apps.users.sessions.metamessages.list( + client.apps.users.sessions.metamessages.list( '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', @@ -100,14 +104,14 @@ describe('resource metamessages', () => { test('list: request options and params are passed correctly', async () => { // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error await expect( - honcho.apps.users.sessions.metamessages.list( + client.apps.users.sessions.metamessages.list( '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', { - filter: 'string', + filter: 'filter', message_id: '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - metamessage_type: 'string', + metamessage_type: 'metamessage_type', page: 1, reverse: true, size: 1, @@ -118,7 +122,7 @@ describe('resource metamessages', () => { }); test('get: only required params', async () => { - const responsePromise = honcho.apps.users.sessions.metamessages.get( + const responsePromise = client.apps.users.sessions.metamessages.get( '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', @@ -135,7 +139,7 @@ describe('resource metamessages', () => { }); test('get: required and optional params', async () => { - const response = await honcho.apps.users.sessions.metamessages.get( + const response = await client.apps.users.sessions.metamessages.get( '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', diff --git a/tests/api-resources/apps/users/sessions/sessions.test.ts b/tests/api-resources/apps/users/sessions/sessions.test.ts index 4c40b52..be02671 100644 --- a/tests/api-resources/apps/users/sessions/sessions.test.ts +++ b/tests/api-resources/apps/users/sessions/sessions.test.ts @@ -1,19 +1,19 @@ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. -import Honcho from 'honcho-ai'; +import Honcho from 'honcho'; import { Response } from 'node-fetch'; -const honcho = new Honcho({ +const client = new Honcho({ apiKey: 'My API Key', baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010', }); describe('resource sessions', () => { - test('create: only required params', async () => { - const responsePromise = honcho.apps.users.sessions.create( + test('create', async () => { + const responsePromise = client.apps.users.sessions.create( '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - { location_id: 'string' }, + {}, ); const rawResponse = await responsePromise.asResponse(); expect(rawResponse).toBeInstanceOf(Response); @@ -24,16 +24,8 @@ describe('resource sessions', () => { expect(dataAndResponse.response).toBe(rawResponse); }); - test('create: required and optional params', async () => { - const response = await honcho.apps.users.sessions.create( - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - { location_id: 'string', metadata: { foo: 'bar' } }, - ); - }); - test('update', async () => { - const responsePromise = honcho.apps.users.sessions.update( + const responsePromise = client.apps.users.sessions.update( '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', @@ -49,7 +41,7 @@ describe('resource sessions', () => { }); test('list', async () => { - const responsePromise = honcho.apps.users.sessions.list( + const responsePromise = client.apps.users.sessions.list( '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', ); @@ -65,7 +57,7 @@ describe('resource sessions', () => { test('list: request options instead of params are passed correctly', async () => { // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error await expect( - honcho.apps.users.sessions.list( + client.apps.users.sessions.list( '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', { path: '/_stainless_unknown_path' }, @@ -76,17 +68,17 @@ describe('resource sessions', () => { test('list: request options and params are passed correctly', async () => { // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error await expect( - honcho.apps.users.sessions.list( + client.apps.users.sessions.list( '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - { filter: 'string', is_active: true, location_id: 'string', page: 1, reverse: true, size: 1 }, + { filter: 'filter', is_active: true, page: 1, reverse: true, size: 1 }, { path: '/_stainless_unknown_path' }, ), ).rejects.toThrow(Honcho.NotFoundError); }); test('delete', async () => { - const responsePromise = honcho.apps.users.sessions.delete( + const responsePromise = client.apps.users.sessions.delete( '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', @@ -103,7 +95,7 @@ describe('resource sessions', () => { test('delete: request options instead of params are passed correctly', async () => { // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error await expect( - honcho.apps.users.sessions.delete( + client.apps.users.sessions.delete( '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', @@ -113,11 +105,11 @@ describe('resource sessions', () => { }); test('chat: only required params', async () => { - const responsePromise = honcho.apps.users.sessions.chat( + const responsePromise = client.apps.users.sessions.chat( '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - { query: 'string' }, + { query: 'query' }, ); const rawResponse = await responsePromise.asResponse(); expect(rawResponse).toBeInstanceOf(Response); @@ -129,16 +121,16 @@ describe('resource sessions', () => { }); test('chat: required and optional params', async () => { - const response = await honcho.apps.users.sessions.chat( + const response = await client.apps.users.sessions.chat( '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - { query: 'string' }, + { query: 'query' }, ); }); test('get', async () => { - const responsePromise = honcho.apps.users.sessions.get( + const responsePromise = client.apps.users.sessions.get( '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', @@ -155,7 +147,7 @@ describe('resource sessions', () => { test('get: request options instead of params are passed correctly', async () => { // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error await expect( - honcho.apps.users.sessions.get( + client.apps.users.sessions.get( '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', @@ -165,11 +157,11 @@ describe('resource sessions', () => { }); test('stream: only required params', async () => { - const responsePromise = honcho.apps.users.sessions.stream( + const responsePromise = client.apps.users.sessions.stream( '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - { query: 'string' }, + { query: 'query' }, ); const rawResponse = await responsePromise.asResponse(); expect(rawResponse).toBeInstanceOf(Response); @@ -181,11 +173,11 @@ describe('resource sessions', () => { }); test('stream: required and optional params', async () => { - const response = await honcho.apps.users.sessions.stream( + const response = await client.apps.users.sessions.stream( '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - { query: 'string' }, + { query: 'query' }, ); }); }); diff --git a/tests/api-resources/apps/users/users.test.ts b/tests/api-resources/apps/users/users.test.ts index 97150b3..a67db27 100644 --- a/tests/api-resources/apps/users/users.test.ts +++ b/tests/api-resources/apps/users/users.test.ts @@ -1,17 +1,17 @@ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. -import Honcho from 'honcho-ai'; +import Honcho from 'honcho'; import { Response } from 'node-fetch'; -const honcho = new Honcho({ +const client = new Honcho({ apiKey: 'My API Key', baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010', }); describe('resource users', () => { test('create: only required params', async () => { - const responsePromise = honcho.apps.users.create('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', { - name: 'string', + const responsePromise = client.apps.users.create('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', { + name: 'name', }); const rawResponse = await responsePromise.asResponse(); expect(rawResponse).toBeInstanceOf(Response); @@ -23,14 +23,14 @@ describe('resource users', () => { }); test('create: required and optional params', async () => { - const response = await honcho.apps.users.create('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', { - name: 'string', + const response = await client.apps.users.create('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', { + name: 'name', metadata: { foo: 'bar' }, }); }); test('update', async () => { - const responsePromise = honcho.apps.users.update( + const responsePromise = client.apps.users.update( '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', {}, @@ -45,7 +45,7 @@ describe('resource users', () => { }); test('list', async () => { - const responsePromise = honcho.apps.users.list('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e'); + const responsePromise = client.apps.users.list('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e'); const rawResponse = await responsePromise.asResponse(); expect(rawResponse).toBeInstanceOf(Response); const response = await responsePromise; @@ -58,23 +58,23 @@ describe('resource users', () => { test('list: request options instead of params are passed correctly', async () => { // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error await expect( - honcho.apps.users.list('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', { path: '/_stainless_unknown_path' }), + client.apps.users.list('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', { path: '/_stainless_unknown_path' }), ).rejects.toThrow(Honcho.NotFoundError); }); test('list: request options and params are passed correctly', async () => { // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error await expect( - honcho.apps.users.list( + client.apps.users.list( '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - { filter: 'string', page: 1, reverse: true, size: 1 }, + { filter: 'filter', page: 1, reverse: true, size: 1 }, { path: '/_stainless_unknown_path' }, ), ).rejects.toThrow(Honcho.NotFoundError); }); test('get', async () => { - const responsePromise = honcho.apps.users.get( + const responsePromise = client.apps.users.get( '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', ); @@ -90,14 +90,14 @@ describe('resource users', () => { test('get: request options instead of params are passed correctly', async () => { // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error await expect( - honcho.apps.users.get('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', { + client.apps.users.get('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', { path: '/_stainless_unknown_path', }), ).rejects.toThrow(Honcho.NotFoundError); }); test('getByName', async () => { - const responsePromise = honcho.apps.users.getByName('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', 'string'); + const responsePromise = client.apps.users.getByName('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', 'name'); const rawResponse = await responsePromise.asResponse(); expect(rawResponse).toBeInstanceOf(Response); const response = await responsePromise; @@ -110,14 +110,14 @@ describe('resource users', () => { test('getByName: request options instead of params are passed correctly', async () => { // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error await expect( - honcho.apps.users.getByName('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', 'string', { + client.apps.users.getByName('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', 'name', { path: '/_stainless_unknown_path', }), ).rejects.toThrow(Honcho.NotFoundError); }); test('getOrCreate', async () => { - const responsePromise = honcho.apps.users.getOrCreate('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', 'string'); + const responsePromise = client.apps.users.getOrCreate('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', 'name'); const rawResponse = await responsePromise.asResponse(); expect(rawResponse).toBeInstanceOf(Response); const response = await responsePromise; @@ -130,7 +130,7 @@ describe('resource users', () => { test('getOrCreate: request options instead of params are passed correctly', async () => { // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error await expect( - honcho.apps.users.getOrCreate('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', 'string', { + client.apps.users.getOrCreate('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', 'name', { path: '/_stainless_unknown_path', }), ).rejects.toThrow(Honcho.NotFoundError); diff --git a/tests/form.test.ts b/tests/form.test.ts index 2f922e0..d0412be 100644 --- a/tests/form.test.ts +++ b/tests/form.test.ts @@ -1,6 +1,6 @@ -import { multipartFormRequestOptions, createForm } from 'honcho-ai/core'; -import { Blob } from 'honcho-ai/_shims/index'; -import { toFile } from 'honcho-ai'; +import { multipartFormRequestOptions, createForm } from 'honcho/core'; +import { Blob } from 'honcho/_shims/index'; +import { toFile } from 'honcho'; describe('form data validation', () => { test('valid values do not error', async () => { diff --git a/tests/index.test.ts b/tests/index.test.ts index 1f9ec62..f263c9d 100644 --- a/tests/index.test.ts +++ b/tests/index.test.ts @@ -1,8 +1,8 @@ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. -import Honcho from 'honcho-ai'; -import { APIUserAbortError } from 'honcho-ai'; -import { Headers } from 'honcho-ai/core'; +import Honcho from 'honcho'; +import { APIUserAbortError } from 'honcho'; +import { Headers } from 'honcho/core'; import defaultFetch, { Response, type RequestInit, type RequestInfo } from 'node-fetch'; describe('instantiate client', () => { @@ -151,26 +151,26 @@ describe('instantiate client', () => { test('empty env variable', () => { process.env['HONCHO_BASE_URL'] = ''; // empty const client = new Honcho({ apiKey: 'My API Key' }); - expect(client.baseURL).toEqual('http://localhost:8000'); + expect(client.baseURL).toEqual('https://demo.honcho.dev'); }); test('blank env variable', () => { process.env['HONCHO_BASE_URL'] = ' '; // blank const client = new Honcho({ apiKey: 'My API Key' }); - expect(client.baseURL).toEqual('http://localhost:8000'); + expect(client.baseURL).toEqual('https://demo.honcho.dev'); }); test('env variable with environment', () => { process.env['HONCHO_BASE_URL'] = 'https://example.com/from_env'; expect( - () => new Honcho({ apiKey: 'My API Key', environment: 'local' }), + () => new Honcho({ apiKey: 'My API Key', environment: 'demo' }), ).toThrowErrorMatchingInlineSnapshot( `"Ambiguous URL; The \`baseURL\` option (or HONCHO_BASE_URL env var) and the \`environment\` option are given. If you want to use the environment you must pass baseURL: null"`, ); - const client = new Honcho({ apiKey: 'My API Key', baseURL: null, environment: 'local' }); - expect(client.baseURL).toEqual('http://localhost:8000'); + const client = new Honcho({ apiKey: 'My API Key', baseURL: null, environment: 'demo' }); + expect(client.baseURL).toEqual('https://demo.honcho.dev'); }); }); diff --git a/tests/responses.test.ts b/tests/responses.test.ts index d037c23..cc29ab0 100644 --- a/tests/responses.test.ts +++ b/tests/responses.test.ts @@ -1,5 +1,5 @@ -import { createResponseHeaders } from 'honcho-ai/core'; -import { Headers } from 'honcho-ai/_shims/index'; +import { createResponseHeaders } from 'honcho/core'; +import { Headers } from 'honcho/_shims/index'; describe('response parsing', () => { // TODO: test unicode characters diff --git a/tests/stringifyQuery.test.ts b/tests/stringifyQuery.test.ts index bee9edc..d951599 100644 --- a/tests/stringifyQuery.test.ts +++ b/tests/stringifyQuery.test.ts @@ -1,8 +1,10 @@ -import { APIClient } from 'honcho-ai/core'; +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. -const { stringifyQuery } = APIClient.prototype as any; +import { Honcho } from 'honcho'; -describe('APIClient.stringifyQuery', () => { +const { stringifyQuery } = Honcho.prototype as any; + +describe(stringifyQuery, () => { for (const [input, expected] of [ [{ a: '1', b: 2, c: true }, 'a=1&b=2&c=true'], [{ a: null, b: false, c: undefined }, 'a=&b=false'], @@ -18,6 +20,7 @@ describe('APIClient.stringifyQuery', () => { expect(stringifyQuery(input)).toEqual(expected); }); } + for (const value of [[], {}, new Date()]) { it(`${JSON.stringify(value)} -> `, () => { expect(() => stringifyQuery({ value })).toThrow(`Cannot stringify type ${typeof value}`); diff --git a/tests/uploads.test.ts b/tests/uploads.test.ts index 6bda430..d2f2415 100644 --- a/tests/uploads.test.ts +++ b/tests/uploads.test.ts @@ -1,6 +1,6 @@ import fs from 'fs'; -import { toFile, type ResponseLike } from 'honcho-ai/uploads'; -import { File } from 'honcho-ai/_shims/index'; +import { toFile, type ResponseLike } from 'honcho/uploads'; +import { File } from 'honcho/_shims/index'; class MyClass { name: string = 'foo'; diff --git a/tsconfig.build.json b/tsconfig.build.json index 17390a4..1837cdb 100644 --- a/tsconfig.build.json +++ b/tsconfig.build.json @@ -5,8 +5,8 @@ "compilerOptions": { "rootDir": "./dist/src", "paths": { - "honcho-ai/*": ["dist/src/*"], - "honcho-ai": ["dist/src/index.ts"], + "honcho/*": ["dist/src/*"], + "honcho": ["dist/src/index.ts"], }, "noEmit": false, "declaration": true, diff --git a/tsconfig.deno.json b/tsconfig.deno.json index ea3e86c..5c37192 100644 --- a/tsconfig.deno.json +++ b/tsconfig.deno.json @@ -6,9 +6,9 @@ "rootDir": "./deno", "lib": ["es2020", "DOM"], "paths": { - "honcho-ai/_shims/auto/*": ["deno/_shims/auto/*-deno"], - "honcho-ai/*": ["deno/*"], - "honcho-ai": ["deno/index.ts"], + "honcho/_shims/auto/*": ["deno/_shims/auto/*-deno"], + "honcho/*": ["deno/*"], + "honcho": ["deno/index.ts"], }, "noEmit": true, "declaration": true, diff --git a/tsconfig.json b/tsconfig.json index 2665dd2..de575dc 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -9,9 +9,9 @@ "esModuleInterop": true, "baseUrl": "./", "paths": { - "honcho-ai/_shims/auto/*": ["src/_shims/auto/*-node"], - "honcho-ai/*": ["src/*"], - "honcho-ai": ["src/index.ts"], + "honcho/_shims/auto/*": ["src/_shims/auto/*-node"], + "honcho/*": ["src/*"], + "honcho": ["src/index.ts"], }, "noEmit": true, diff --git a/yarn.lock b/yarn.lock index dda4d2e..358dbf2 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3412,11 +3412,6 @@ web-streams-polyfill@4.0.0-beta.1: resolved "https://registry.yarnpkg.com/web-streams-polyfill/-/web-streams-polyfill-4.0.0-beta.1.tgz#3b19b9817374b7cee06d374ba7eeb3aeb80e8c95" integrity sha512-3ux37gEX670UUphBF9AMCq8XM6iQ8Ac6A+DSRRjDoRBm1ufCkaCDdNVbaqq60PsEkdNlLKrGtv/YBP4EJXqNtQ== -web-streams-polyfill@^3.2.1: - version "3.2.1" - resolved "https://registry.yarnpkg.com/web-streams-polyfill/-/web-streams-polyfill-3.2.1.tgz#71c2718c52b45fd49dbeee88634b3a60ceab42a6" - integrity sha512-e0MO3wdXWKrLbL0DgGnUV7WHVuw9OUvL4hjgnPkIeEvESk74gAITi5G606JtZPp39cd8HA9VQzCIvA49LpPN5Q== - webidl-conversions@^3.0.0: version "3.0.1" resolved "https://registry.yarnpkg.com/webidl-conversions/-/webidl-conversions-3.0.1.tgz#24534275e2a7bc6be7bc86611cc16ae0a5654871"