Skip to content

Commit e90c408

Browse files
stainless-app[bot]stainless-bot
authored andcommitted
feat(api): update via SDK Studio (#9)
1 parent 01cddec commit e90c408

35 files changed

+797
-251
lines changed

CONTRIBUTING.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,12 @@ cd typescript-sdk
5555
# With yarn
5656
yarn link
5757
cd ../my-package
58-
yarn link @@@@prompt-foundry/typescript-sdk
58+
yarn link @prompt-foundry/typescript-sdk
5959

6060
# With pnpm
6161
pnpm link --global
6262
cd ../my-package
63-
pnpm link -—global @@@@prompt-foundry/typescript-sdk
63+
pnpm link -—global @prompt-foundry/typescript-sdk
6464
```
6565

6666
## Running tests

README.md

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Prompt Foundry Node API Library
22

3-
[![NPM version](https://img.shields.io/npm/v/@@@@prompt-foundry/typescript-sdk.svg)](https://npmjs.org/package/@@@@prompt-foundry/typescript-sdk) ![npm bundle size](https://img.shields.io/bundlephobia/minzip/@@@@prompt-foundry/typescript-sdk)
3+
[![NPM version](https://img.shields.io/npm/v/@prompt-foundry/typescript-sdk.svg)](https://npmjs.org/package/@prompt-foundry/typescript-sdk) ![npm bundle size](https://img.shields.io/bundlephobia/minzip/@prompt-foundry/typescript-sdk)
44

55
This library provides convenient access to the Prompt Foundry REST API from server-side TypeScript or JavaScript.
66

@@ -11,7 +11,7 @@ It is generated with [Stainless](https://www.stainlessapi.com/).
1111
## Installation
1212

1313
```sh
14-
npm install @@@@prompt-foundry/typescript-sdk
14+
npm install @prompt-foundry/typescript-sdk
1515
```
1616

1717
## Usage
@@ -20,7 +20,7 @@ The full API of this library can be found in [api.md](api.md).
2020

2121
<!-- prettier-ignore -->
2222
```js
23-
import PromptFoundry from '@@@@prompt-foundry/typescript-sdk';
23+
import PromptFoundry from '@prompt-foundry/typescript-sdk';
2424

2525
const promptFoundry = new PromptFoundry({
2626
apiKey: process.env['PROMPT_FOUNDRY_API_KEY'], // This is the default and can be omitted
@@ -41,7 +41,7 @@ This library includes TypeScript definitions for all request params and response
4141

4242
<!-- prettier-ignore -->
4343
```ts
44-
import PromptFoundry from '@@@@prompt-foundry/typescript-sdk';
44+
import PromptFoundry from '@prompt-foundry/typescript-sdk';
4545

4646
const promptFoundry = new PromptFoundry({
4747
apiKey: process.env['PROMPT_FOUNDRY_API_KEY'], // This is the default and can be omitted
@@ -212,11 +212,11 @@ add the following import before your first import `from "PromptFoundry"`:
212212
```ts
213213
// Tell TypeScript and the package to use the global web fetch instead of node-fetch.
214214
// Note, despite the name, this does not add any polyfills, but expects them to be provided if needed.
215-
import '@@@@prompt-foundry/typescript-sdk/shims/web';
216-
import PromptFoundry from '@@@@prompt-foundry/typescript-sdk';
215+
import '@prompt-foundry/typescript-sdk/shims/web';
216+
import PromptFoundry from '@prompt-foundry/typescript-sdk';
217217
```
218218

219-
To do the inverse, add `import "@@@@prompt-foundry/typescript-sdk/shims/node"` (which does import polyfills).
219+
To do the inverse, add `import "@prompt-foundry/typescript-sdk/shims/node"` (which does import polyfills).
220220
This can also be useful if you are getting the wrong TypeScript types for `Response` ([more details](https://github.com/prompt-foundry/typescript-sdk/tree/main/src/_shims#readme)).
221221

222222
### Logging and middleware
@@ -226,7 +226,7 @@ which can be used to inspect or alter the `Request` or `Response` before/after e
226226

227227
```ts
228228
import { fetch } from 'undici'; // as one example
229-
import PromptFoundry from '@@@@prompt-foundry/typescript-sdk';
229+
import PromptFoundry from '@prompt-foundry/typescript-sdk';
230230

231231
const client = new PromptFoundry({
232232
fetch: async (url: RequestInfo, init?: RequestInit): Promise<Response> => {
@@ -282,7 +282,7 @@ TypeScript >= 4.5 is supported.
282282
The following runtimes are supported:
283283

284284
- Node.js 18 LTS or later ([non-EOL](https://endoflife.date/nodejs)) versions.
285-
- Deno v1.28.0 or higher, using `import PromptFoundry from "npm:@@@@prompt-foundry/typescript-sdk"`.
285+
- Deno v1.28.0 or higher, using `import PromptFoundry from "npm:@prompt-foundry/typescript-sdk"`.
286286
- Bun 1.0 or later.
287287
- Cloudflare Workers.
288288
- Vercel Edge Runtime.

jest.config.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ const config: JestConfigWithTsJest = {
77
'^.+\\.(t|j)sx?$': ['@swc/jest', { sourceMaps: 'inline' }],
88
},
99
moduleNameMapper: {
10-
'^@@@@prompt-foundry/typescript-sdk$': '<rootDir>/src/index.ts',
11-
'^@@@@prompt-foundry/typescript-sdk/_shims/auto/(.*)$': '<rootDir>/src/_shims/auto/$1-node',
12-
'^@@@@prompt-foundry/typescript-sdk/(.*)$': '<rootDir>/src/$1',
10+
'^@prompt-foundry/typescript-sdk$': '<rootDir>/src/index.ts',
11+
'^@prompt-foundry/typescript-sdk/_shims/auto/(.*)$': '<rootDir>/src/_shims/auto/$1-node',
12+
'^@prompt-foundry/typescript-sdk/(.*)$': '<rootDir>/src/$1',
1313
},
1414
modulePathIgnorePatterns: [
1515
'<rootDir>/ecosystem-tests/',

package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "@@@@prompt-foundry/typescript-sdk",
2+
"name": "@prompt-foundry/typescript-sdk",
33
"version": "1.0.0",
44
"description": "The official TypeScript library for the Prompt Foundry API",
55
"author": "Prompt Foundry <[email protected]>",
@@ -60,8 +60,8 @@
6060
"./shims/web.mjs"
6161
],
6262
"imports": {
63-
"@@@@prompt-foundry/typescript-sdk": ".",
64-
"@@@@prompt-foundry/typescript-sdk/*": "./src/*"
63+
"@prompt-foundry/typescript-sdk": ".",
64+
"@prompt-foundry/typescript-sdk/*": "./src/*"
6565
},
6666
"exports": {
6767
"./_shims/auto/*": {

scripts/build

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ node scripts/utils/check-version.cjs
88

99
# Build into dist and will publish the package from there,
1010
# so that src/resources/foo.ts becomes <package root>/resources/foo.js
11-
# This way importing from `"@@@@prompt-foundry/typescript-sdk/resources/foo"` works
11+
# This way importing from `"@prompt-foundry/typescript-sdk/resources/foo"` works
1212
# even with `"moduleResolution": "node"`
1313

1414
rm -rf dist; mkdir dist
@@ -47,8 +47,8 @@ node scripts/utils/postprocess-files.cjs
4747

4848
# make sure that nothing crashes when we require the output CJS or
4949
# import the output ESM
50-
(cd dist && node -e 'require("@@@@prompt-foundry/typescript-sdk")')
51-
(cd dist && node -e 'import("@@@@prompt-foundry/typescript-sdk")' --input-type=module)
50+
(cd dist && node -e 'require("@prompt-foundry/typescript-sdk")')
51+
(cd dist && node -e 'import("@prompt-foundry/typescript-sdk")' --input-type=module)
5252

5353
if command -v deno &> /dev/null && [ -e ./scripts/build-deno ]
5454
then

scripts/utils/postprocess-files.cjs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const fs = require('fs');
22
const path = require('path');
33
const { parse } = require('@typescript-eslint/parser');
44

5-
const pkgImportPath = process.env['PKG_IMPORT_PATH'] ?? '@@@@prompt-foundry/typescript-sdk/';
5+
const pkgImportPath = process.env['PKG_IMPORT_PATH'] ?? '@prompt-foundry/typescript-sdk/';
66

77
const distDir =
88
process.env['DIST_PATH'] ?
@@ -142,7 +142,7 @@ async function postprocess() {
142142

143143
if (file.endsWith('.d.ts')) {
144144
// work around bad tsc behavior
145-
// if we have `import { type Readable } from '@@@@prompt-foundry/typescript-sdk/_shims/index'`,
145+
// if we have `import { type Readable } from '@prompt-foundry/typescript-sdk/_shims/index'`,
146146
// tsc sometimes replaces `Readable` with `import("stream").Readable` inline
147147
// in the output .d.ts
148148
transformed = transformed.replace(/import\("stream"\).Readable/g, 'Readable');

src/_shims/README.md

+16-16
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# 👋 Wondering what everything in here does?
22

3-
`@@@@prompt-foundry/typescript-sdk` supports a wide variety of runtime environments like Node.js, Deno, Bun, browsers, and various
3+
`@prompt-foundry/typescript-sdk` supports a wide variety of runtime environments like Node.js, Deno, Bun, browsers, and various
44
edge runtimes, as well as both CommonJS (CJS) and EcmaScript Modules (ESM).
55

6-
To do this, `@@@@prompt-foundry/typescript-sdk` 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.
6+
To do this, `@prompt-foundry/typescript-sdk` 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.
77

88
It uses [conditional exports](https://nodejs.org/api/packages.html#conditional-exports) to
99
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.
1515

1616
The user can work around these issues by manually importing one of:
1717

18-
- `import '@@@@prompt-foundry/typescript-sdk/shims/node'`
19-
- `import '@@@@prompt-foundry/typescript-sdk/shims/web'`
18+
- `import '@prompt-foundry/typescript-sdk/shims/node'`
19+
- `import '@prompt-foundry/typescript-sdk/shims/web'`
2020

2121
All of the code here in `_shims` handles selecting the automatic default shims or manual overrides.
2222

2323
### How it works - Runtime
2424

25-
Runtime shims get installed by calling `setShims` exported by `@@@@prompt-foundry/typescript-sdk/_shims/registry`.
25+
Runtime shims get installed by calling `setShims` exported by `@prompt-foundry/typescript-sdk/_shims/registry`.
2626

27-
Manually importing `@@@@prompt-foundry/typescript-sdk/shims/node` or `@@@@prompt-foundry/typescript-sdk/shims/web`, calls `setShims` with the respective runtime shims.
27+
Manually importing `@prompt-foundry/typescript-sdk/shims/node` or `@prompt-foundry/typescript-sdk/shims/web`, calls `setShims` with the respective runtime shims.
2828

29-
All client code imports shims from `@@@@prompt-foundry/typescript-sdk/_shims/index`, which:
29+
All client code imports shims from `@prompt-foundry/typescript-sdk/_shims/index`, which:
3030

3131
- checks if shims have been set manually
32-
- if not, calls `setShims` with the shims from `@@@@prompt-foundry/typescript-sdk/_shims/auto/runtime`
33-
- re-exports the installed shims from `@@@@prompt-foundry/typescript-sdk/_shims/registry`.
32+
- if not, calls `setShims` with the shims from `@prompt-foundry/typescript-sdk/_shims/auto/runtime`
33+
- re-exports the installed shims from `@prompt-foundry/typescript-sdk/_shims/registry`.
3434

35-
`@@@@prompt-foundry/typescript-sdk/_shims/auto/runtime` exports web runtime shims.
36-
If the `node` export condition is set, the export map replaces it with `@@@@prompt-foundry/typescript-sdk/_shims/auto/runtime-node`.
35+
`@prompt-foundry/typescript-sdk/_shims/auto/runtime` exports web runtime shims.
36+
If the `node` export condition is set, the export map replaces it with `@prompt-foundry/typescript-sdk/_shims/auto/runtime-node`.
3737

3838
### How it works - Type time
3939

40-
All client code imports shim types from `@@@@prompt-foundry/typescript-sdk/_shims/index`, which selects the manual types from `@@@@prompt-foundry/typescript-sdk/_shims/manual-types` if they have been declared, otherwise it exports the auto types from `@@@@prompt-foundry/typescript-sdk/_shims/auto/types`.
40+
All client code imports shim types from `@prompt-foundry/typescript-sdk/_shims/index`, which selects the manual types from `@prompt-foundry/typescript-sdk/_shims/manual-types` if they have been declared, otherwise it exports the auto types from `@prompt-foundry/typescript-sdk/_shims/auto/types`.
4141

42-
`@@@@prompt-foundry/typescript-sdk/_shims/manual-types` exports an empty namespace.
43-
Manually importing `@@@@prompt-foundry/typescript-sdk/shims/node` or `@@@@prompt-foundry/typescript-sdk/shims/web` merges declarations into this empty namespace, so they get picked up by `@@@@prompt-foundry/typescript-sdk/_shims/index`.
42+
`@prompt-foundry/typescript-sdk/_shims/manual-types` exports an empty namespace.
43+
Manually importing `@prompt-foundry/typescript-sdk/shims/node` or `@prompt-foundry/typescript-sdk/shims/web` merges declarations into this empty namespace, so they get picked up by `@prompt-foundry/typescript-sdk/_shims/index`.
4444

45-
`@@@@prompt-foundry/typescript-sdk/_shims/auto/types` exports web type definitions.
46-
If the `node` export condition is set, the export map replaces it with `@@@@prompt-foundry/typescript-sdk/_shims/auto/types-node`, though TS only picks this up if `"moduleResolution": "nodenext"` or `"moduleResolution": "bundler"`.
45+
`@prompt-foundry/typescript-sdk/_shims/auto/types` exports web type definitions.
46+
If the `node` export condition is set, the export map replaces it with `@prompt-foundry/typescript-sdk/_shims/auto/types-node`, though TS only picks this up if `"moduleResolution": "nodenext"` or `"moduleResolution": "bundler"`.

src/_shims/index.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Disclaimer: modules in _shims aren't intended to be imported by SDK users.
33
*/
44
import { manual } from './manual-types';
5-
import * as auto from '@@@@prompt-foundry/typescript-sdk/_shims/auto/types';
5+
import * as auto from '@prompt-foundry/typescript-sdk/_shims/auto/types';
66
import { type RequestOptions } from '../core';
77

88
type SelectType<Manual, Auto> = unknown extends Manual ? Auto : Manual;

src/_shims/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Disclaimer: modules in _shims aren't intended to be imported by SDK users.
33
*/
44
const shims = require('./registry');
5-
const auto = require('@@@@prompt-foundry/typescript-sdk/_shims/auto/runtime');
5+
const auto = require('@prompt-foundry/typescript-sdk/_shims/auto/runtime');
66
if (!shims.kind) shims.setShims(auto.getRuntime(), { auto: true });
77
for (const property of Object.keys(shims)) {
88
Object.defineProperty(exports, property, {

src/_shims/index.mjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
* Disclaimer: modules in _shims aren't intended to be imported by SDK users.
33
*/
44
import * as shims from './registry.mjs';
5-
import * as auto from '@@@@prompt-foundry/typescript-sdk/_shims/auto/runtime';
5+
import * as auto from '@prompt-foundry/typescript-sdk/_shims/auto/runtime';
66
if (!shims.kind) shims.setShims(auto.getRuntime(), { auto: true });
77
export * from './registry.mjs';

src/_shims/manual-types.d.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
/**
55
* Types will get added to this namespace when you import one of the following:
66
*
7-
* import '@@@@prompt-foundry/typescript-sdk/shims/node'
8-
* import '@@@@prompt-foundry/typescript-sdk/shims/web'
7+
* import '@prompt-foundry/typescript-sdk/shims/node'
8+
* import '@prompt-foundry/typescript-sdk/shims/web'
99
*
1010
* Importing more than one will cause type and runtime errors.
1111
*/

src/_shims/registry.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@ export let isFsReadStream: Shims['isFsReadStream'] | undefined = undefined;
4242
export function setShims(shims: Shims, options: { auto: boolean } = { auto: false }) {
4343
if (auto) {
4444
throw new Error(
45-
`you must \`import '@@@@prompt-foundry/typescript-sdk/shims/${shims.kind}'\` before importing anything else from @@@@prompt-foundry/typescript-sdk`,
45+
`you must \`import '@prompt-foundry/typescript-sdk/shims/${shims.kind}'\` before importing anything else from @prompt-foundry/typescript-sdk`,
4646
);
4747
}
4848
if (kind) {
4949
throw new Error(
50-
`can't \`import '@@@@prompt-foundry/typescript-sdk/shims/${shims.kind}'\` after \`import '@@@@prompt-foundry/typescript-sdk/shims/${kind}'\``,
50+
`can't \`import '@prompt-foundry/typescript-sdk/shims/${shims.kind}'\` after \`import '@prompt-foundry/typescript-sdk/shims/${kind}'\``,
5151
);
5252
}
5353
auto = options.auto;

src/_shims/web-runtime.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ export function getRuntime({ manuallyImported }: { manuallyImported?: boolean }
99
const recommendation =
1010
manuallyImported ?
1111
`You may need to use polyfills`
12-
: `Add one of these imports before your first \`import … from '@@@@prompt-foundry/typescript-sdk'\`:
13-
- \`import '@@@@prompt-foundry/typescript-sdk/shims/node'\` (if you're running on Node)
14-
- \`import '@@@@prompt-foundry/typescript-sdk/shims/web'\` (otherwise)
12+
: `Add one of these imports before your first \`import … from '@prompt-foundry/typescript-sdk'\`:
13+
- \`import '@prompt-foundry/typescript-sdk/shims/node'\` (if you're running on Node)
14+
- \`import '@prompt-foundry/typescript-sdk/shims/web'\` (otherwise)
1515
`;
1616

1717
let _fetch, _Request, _Response, _Headers;

src/core.ts

+7-16
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { VERSION } from './version';
2-
;
32
import {
43
PromptFoundryError,
54
APIError,
@@ -39,8 +38,6 @@ type APIResponseProps = {
3938

4039
async function defaultParseResponse<T>(props: APIResponseProps): Promise<T> {
4140
const { response } = props;
42-
;
43-
4441
// fetch refuses to read the body when the status code is 204.
4542
if (response.status === 204) {
4643
return null as T;
@@ -100,9 +97,9 @@ export class APIPromise<T> extends Promise<T> {
10097
*
10198
* 👋 Getting the wrong TypeScript type for `Response`?
10299
* Try setting `"moduleResolution": "NodeNext"` if you can,
103-
* or add one of these imports before your first `import … from '@@@@prompt-foundry/typescript-sdk'`:
104-
* - `import '@@@@prompt-foundry/typescript-sdk/shims/node'` (if you're running on Node)
105-
* - `import '@@@@prompt-foundry/typescript-sdk/shims/web'` (otherwise)
100+
* or add one of these imports before your first `import … from '@prompt-foundry/typescript-sdk'`:
101+
* - `import '@prompt-foundry/typescript-sdk/shims/node'` (if you're running on Node)
102+
* - `import '@prompt-foundry/typescript-sdk/shims/web'` (otherwise)
106103
*/
107104
asResponse(): Promise<Response> {
108105
return this.responsePromise.then((p) => p.response);
@@ -116,9 +113,9 @@ export class APIPromise<T> extends Promise<T> {
116113
*
117114
* 👋 Getting the wrong TypeScript type for `Response`?
118115
* Try setting `"moduleResolution": "NodeNext"` if you can,
119-
* or add one of these imports before your first `import … from '@@@@prompt-foundry/typescript-sdk'`:
120-
* - `import '@@@@prompt-foundry/typescript-sdk/shims/node'` (if you're running on Node)
121-
* - `import '@@@@prompt-foundry/typescript-sdk/shims/web'` (otherwise)
116+
* or add one of these imports before your first `import … from '@prompt-foundry/typescript-sdk'`:
117+
* - `import '@prompt-foundry/typescript-sdk/shims/node'` (if you're running on Node)
118+
* - `import '@prompt-foundry/typescript-sdk/shims/web'` (otherwise)
122119
*/
123120
async withResponse(): Promise<{ data: T; response: Response }> {
124121
const [data, response] = await Promise.all([this.parse(), this.asResponse()]);
@@ -197,7 +194,7 @@ export abstract class APIClient {
197194
Accept: 'application/json',
198195
'Content-Type': 'application/json',
199196
'User-Agent': this.getUserAgent(),
200-
...getPlatformHeaders(),
197+
...getPlatformHeaders(),
201198
...this.authHeaders(opts),
202199
};
203200
}
@@ -754,11 +751,8 @@ export type RequestOptions<
754751
signal?: AbortSignal | undefined | null;
755752
idempotencyKey?: string;
756753

757-
758-
759754
__binaryRequest?: boolean | undefined;
760755
__binaryResponse?: boolean | undefined;
761-
762756
};
763757

764758
// This is required so that we can determine if a given object matches the RequestOptions
@@ -778,11 +772,8 @@ const requestOptionsKeys: KeysEnum<RequestOptions> = {
778772
signal: true,
779773
idempotencyKey: true,
780774

781-
782-
783775
__binaryRequest: true,
784776
__binaryResponse: true,
785-
786777
};
787778

788779
export const isRequestOptions = (obj: unknown): obj is RequestOptions => {

0 commit comments

Comments
 (0)