Skip to content

Commit

Permalink
Merge pull request #29 from writer/release-please--branches--main--ch…
Browse files Browse the repository at this point in the history
…anges--next--components--writer-sdk

release: 0.4.0
  • Loading branch information
ramedina86 authored Aug 14, 2024
2 parents 2469eba + 03ca0c0 commit fcf89ed
Show file tree
Hide file tree
Showing 25 changed files with 255 additions and 131 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/release-doctor.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
name: Release Doctor
on:
pull_request:
branches:
- main
workflow_dispatch:

jobs:
Expand All @@ -17,3 +19,4 @@ jobs:
bash ./bin/check-release-environment
env:
NPM_TOKEN: ${{ secrets.WRITER_NPM_TOKEN || secrets.NPM_TOKEN }}

2 changes: 1 addition & 1 deletion .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
".": "0.3.0"
".": "0.4.0"
}
4 changes: 2 additions & 2 deletions .stats.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
configured_endpoints: 15
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/writerai%2Fwriter-9950942f4d28d7155ca24b353375665668ba7b19f6a381d42651dd4890a0027f.yml
configured_endpoints: 16
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/writerai%2Fwriter-29d74057f6277b8657539fbdda86e469e2d50765733bfc3db2578eb6fdb8d07e.yml
37 changes: 37 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,42 @@
# Changelog

## 0.4.0 (2024-08-14)

Full Changelog: [v0.3.0...v0.4.0](https://github.com/writer/writer-node/compare/v0.3.0...v0.4.0)

### Features

* **api:** added method to generate applications content ([#43](https://github.com/writer/writer-node/issues/43)) ([09b2657](https://github.com/writer/writer-node/commit/09b26572e0b66f490cb5fef0ee3f0c0250ae9142))
* **api:** update via SDK Studio ([#37](https://github.com/writer/writer-node/issues/37)) ([978cf26](https://github.com/writer/writer-node/commit/978cf26ddca6e10cccbb36fb0a7e0eaa44ae367b))
* **api:** update via SDK Studio ([#41](https://github.com/writer/writer-node/issues/41)) ([6e08bc0](https://github.com/writer/writer-node/commit/6e08bc0d85946bda11b397bb647f32595992d322))
* **api:** update via SDK Studio ([#42](https://github.com/writer/writer-node/issues/42)) ([2c54f4a](https://github.com/writer/writer-node/commit/2c54f4a8975a92d169beff5dbd9b096f7999e7b5))
* feat: joint method `uploadAndAddFileToGraph` ([49ae4ba](https://github.com/writer/writer-node/commit/49ae4ba238ca5791e9df5ef42998fffe33e5c121))
* fix: lint ([4a363dc](https://github.com/writer/writer-node/commit/4a363dc4869b1022e31367b6ddd42b4757ee479e))


### Bug Fixes

* **compat:** remove ReadableStream polyfill redundant since node v16 ([#33](https://github.com/writer/writer-node/issues/33)) ([2dac835](https://github.com/writer/writer-node/commit/2dac83558310169906d1057ad08f80ae9ec81272))


### Chores

* **ci:** bump prism mock server version ([#47](https://github.com/writer/writer-node/issues/47)) ([3b881e9](https://github.com/writer/writer-node/commit/3b881e99f6d06d964f6b3d5c2321b2731ad8f0b3))
* **ci:** minor changes ([#46](https://github.com/writer/writer-node/issues/46)) ([2cab651](https://github.com/writer/writer-node/commit/2cab65110b303808962dfa4f8378ca0d2e40aa0b))
* **docs:** fix incorrect client var names ([#34](https://github.com/writer/writer-node/issues/34)) ([186a9d9](https://github.com/writer/writer-node/commit/186a9d9816a8b1021203958aeaebc5954ce95c25))
* **internal:** add constant for default timeout ([#36](https://github.com/writer/writer-node/issues/36)) ([b4220e2](https://github.com/writer/writer-node/commit/b4220e2d2ad266040c753b4c42f1f0da1a51a166))
* **internal:** codegen related update ([#31](https://github.com/writer/writer-node/issues/31)) ([c3ba095](https://github.com/writer/writer-node/commit/c3ba0959665d5604bc963b16c6ab71f738686504))
* **internal:** codegen related update ([#45](https://github.com/writer/writer-node/issues/45)) ([5c54eb9](https://github.com/writer/writer-node/commit/5c54eb96d4bfcaa305990be63ef98839679ac56d))
* **internal:** codegen related update ([#48](https://github.com/writer/writer-node/issues/48)) ([d908809](https://github.com/writer/writer-node/commit/d9088094ecd095db6f598384dbda4bd1f01ce460))
* **internal:** codegen related update ([#49](https://github.com/writer/writer-node/issues/49)) ([d057479](https://github.com/writer/writer-node/commit/d05747974f065d73ffa6c19c792292fd626b87d8))
* **internal:** version bump ([#28](https://github.com/writer/writer-node/issues/28)) ([254dd3c](https://github.com/writer/writer-node/commit/254dd3cc6595271fc239b42e2a8d2ebb683f7a9a))
* **tests:** update prism version ([#32](https://github.com/writer/writer-node/issues/32)) ([6ea2f59](https://github.com/writer/writer-node/commit/6ea2f5920f53502b6ba5e0b7530aa22b0a1a620a))


### Documentation

* **api:** updates to API spec ([#44](https://github.com/writer/writer-node/issues/44)) ([5b3f183](https://github.com/writer/writer-node/commit/5b3f183754a6422212fba2175831ffcbb8470e8b))

## 0.3.0 (2024-07-16)

Full Changelog: [v0.2.0...v0.3.0](https://github.com/writer/writer-node/compare/v0.2.0...v0.3.0)
Expand Down
54 changes: 23 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

This library provides convenient access to the Writer REST API from server-side TypeScript or JavaScript.

The REST API documentation can be found [on dev.writer.com](https://dev.writer.com/api-guides/introduction). The full API of this library can be found in [api.md](api.md).
The REST API documentation can be found on [dev.writer.com](https://dev.writer.com/api-guides/introduction). The full API of this library can be found in [api.md](api.md).

It is generated with [Stainless](https://www.stainlessapi.com/).

Expand All @@ -22,13 +22,13 @@ The full API of this library can be found in [api.md](api.md).
```js
import Writer from 'writer-sdk';

const writer = new Writer({
const client = new Writer({
apiKey: process.env['WRITER_API_KEY'], // This is the default and can be omitted
});

async function main() {
const chat = await writer.chat.chat({
messages: [{ content: 'string', role: 'user' }],
const chat = await client.chat.chat({
messages: [{ content: 'content', role: 'user' }],
model: 'palmyra-x-002-32k',
});

Expand All @@ -45,9 +45,9 @@ We provide support for streaming responses using Server Sent Events (SSE).
```ts
import Writer from 'writer-sdk';

const writer = new Writer();
const client = new Writer();

const stream = await writer.completions.create({
const stream = await client.completions.create({
model: 'palmyra-x-002-instruct',
prompt: 'Hi, my name is',
stream: true,
Expand All @@ -68,16 +68,16 @@ This library includes TypeScript definitions for all request params and response
```ts
import Writer from 'writer-sdk';

const writer = new Writer({
const client = new Writer({
apiKey: process.env['WRITER_API_KEY'], // This is the default and can be omitted
});

async function main() {
const params: Writer.ChatChatParams = {
messages: [{ content: 'string', role: 'user' }],
messages: [{ content: 'content', role: 'user' }],
model: 'palmyra-x-002-32k',
};
const chat: Writer.Chat = await writer.chat.chat(params);
const chat: Writer.Chat = await client.chat.chat(params);
}

main();
Expand All @@ -94,8 +94,8 @@ a subclass of `APIError` will be thrown:
<!-- prettier-ignore -->
```ts
async function main() {
const chat = await writer.chat
.chat({ messages: [{ content: 'content', role: 'user' }], model: 'palmyra-x-32k' })
const chat = await client.chat
.chat({ messages: [{ content: 'content', role: 'user' }], model: 'palmyra-x-002-32k' })
.catch(async (err) => {
if (err instanceof Writer.APIError) {
console.log(err.status); // 400
Expand Down Expand Up @@ -134,12 +134,12 @@ You can use the `maxRetries` option to configure or disable this:
<!-- prettier-ignore -->
```js
// Configure the default for all requests:
const writer = new Writer({
const client = new Writer({
maxRetries: 0, // default is 2
});

// Or, configure per-request:
await writer.chat.chat({ messages: [{ content: 'string', role: 'user' }], model: 'palmyra-x-002-32k' }, {
await client.chat.chat({ messages: [{ content: 'content', role: 'user' }], model: 'palmyra-x-002-32k' }, {
maxRetries: 5,
});
```
Expand All @@ -151,12 +151,12 @@ Requests time out after 1 minute by default. You can configure this with a `time
<!-- prettier-ignore -->
```ts
// Configure the default for all requests:
const writer = new Writer({
const client = new Writer({
timeout: 20 * 1000, // 20 seconds (default is 1 minute)
});

// Override per-request:
await writer.chat.chat({ messages: [{ content: 'string', role: 'user' }], model: 'palmyra-x-002-32k' }, {
await client.chat.chat({ messages: [{ content: 'content', role: 'user' }], model: 'palmyra-x-002-32k' }, {
timeout: 5 * 1000,
});
```
Expand All @@ -175,16 +175,16 @@ You can also use the `.withResponse()` method to get the raw `Response` along wi

<!-- prettier-ignore -->
```ts
const writer = new Writer();
const client = new Writer();

const response = await writer.chat
.chat({ messages: [{ content: 'string', role: 'user' }], model: 'palmyra-x-002-32k' })
const response = await client.chat
.chat({ messages: [{ content: 'content', role: 'user' }], model: 'palmyra-x-002-32k' })
.asResponse();
console.log(response.headers.get('X-My-Header'));
console.log(response.statusText); // access the underlying Response object

const { data: chat, response: raw } = await writer.chat
.chat({ messages: [{ content: 'string', role: 'user' }], model: 'palmyra-x-002-32k' })
const { data: chat, response: raw } = await client.chat
.chat({ messages: [{ content: 'content', role: 'user' }], model: 'palmyra-x-002-32k' })
.withResponse();
console.log(raw.headers.get('X-My-Header'));
console.log(chat.id);
Expand Down Expand Up @@ -286,13 +286,13 @@ import http from 'http';
import { HttpsProxyAgent } from 'https-proxy-agent';

// Configure the default for all requests:
const writer = new Writer({
const client = new Writer({
httpAgent: new HttpsProxyAgent(process.env.PROXY_URL),
});

// Override per-request:
await writer.chat.chat(
{ messages: [{ content: 'string', role: 'user' }], model: 'palmyra-x-002-32k' },
await client.chat.chat(
{ messages: [{ content: 'content', role: 'user' }], model: 'palmyra-x-002-32k' },
{
httpAgent: new http.Agent({ keepAlive: false }),
},
Expand All @@ -317,14 +317,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 Writer from "npm:writer-sdk"`.
- 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.
10 changes: 10 additions & 0 deletions api.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
# Applications

Types:

- <code><a href="./src/resources/applications.ts">ApplicationGenerateContentResponse</a></code>

Methods:

- <code title="post /v1/applications/{application_id}">client.applications.<a href="./src/resources/applications.ts">generateContent</a>(applicationId, { ...params }) -> ApplicationGenerateContentResponse</code>

# Chat

Types:
Expand Down
1 change: 1 addition & 0 deletions bin/check-release-environment
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ if [[ lenErrors -gt 0 ]]; then
fi

echo "The environment is ready to push releases!"

7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "writer-sdk",
"version": "0.3.0",
"version": "0.4.0",
"description": "The official TypeScript library for the Writer API",
"author": "Writer <[email protected]>",
"types": "dist/index.d.ts",
Expand All @@ -21,7 +21,7 @@
"prepare": "if ./scripts/utils/check-is-in-git-install.sh; then ./scripts/build; fi",
"tsn": "ts-node -r tsconfig-paths/register",
"lint": "./scripts/lint",
"fix": "eslint --fix --ext ts,js ."
"fix": "./scripts/format"
},
"dependencies": {
"@types/node": "^18.11.18",
Expand All @@ -30,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",
Expand Down
2 changes: 1 addition & 1 deletion scripts/format
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ set -e
cd "$(dirname "$0")/.."

echo "==> Running eslint --fix"
./node_modules/.bin/eslint --fix --ext ts,js .
ESLINT_USE_FLAT_CONFIG="false" ./node_modules/.bin/eslint --fix --ext ts,js .
2 changes: 1 addition & 1 deletion scripts/lint
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ set -e
cd "$(dirname "$0")/.."

echo "==> Running eslint"
./node_modules/.bin/eslint --ext ts,js .
ESLINT_USE_FLAT_CONFIG="false" ./node_modules/.bin/eslint --ext ts,js .
4 changes: 2 additions & 2 deletions scripts/mock
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected].5 -- prism mock "$URL" &> .prism.log &

# Wait for server to come online
echo -n "Waiting for server"
Expand All @@ -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/[email protected].5 -- prism mock "$URL"
fi
4 changes: 1 addition & 3 deletions src/_shims/node-runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<FilePropertyBag, 'lastModified'>;

Expand Down
6 changes: 6 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ export class Writer extends Core.APIClient {
this.apiKey = apiKey;
}

applications: API.Applications = new API.Applications(this);
chat: API.ChatResource = new API.ChatResource(this);
completions: API.Completions = new API.Completions(this);
models: API.Models = new API.Models(this);
Expand All @@ -142,6 +143,7 @@ export class Writer extends Core.APIClient {
}

static Writer = this;
static DEFAULT_TIMEOUT = 60000; // 1 minute

static WriterError = Errors.WriterError;
static APIError = Errors.APIError;
Expand Down Expand Up @@ -187,6 +189,10 @@ export namespace Writer {
export import CursorPageParams = Pagination.CursorPageParams;
export import CursorPageResponse = Pagination.CursorPageResponse;

export import Applications = API.Applications;
export import ApplicationGenerateContentResponse = API.ApplicationGenerateContentResponse;
export import ApplicationGenerateContentParams = API.ApplicationGenerateContentParams;

export import ChatResource = API.ChatResource;
export import Chat = API.Chat;
export import ChatStreamingData = API.ChatStreamingData;
Expand Down
58 changes: 58 additions & 0 deletions src/resources/applications.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

import { APIResource } from '../resource';
import * as Core from '../core';
import * as ApplicationsAPI from './applications';

export class Applications extends APIResource {
/**
* Generate content from an existing application with inputs.
*/
generateContent(
applicationId: string,
body: ApplicationGenerateContentParams,
options?: Core.RequestOptions,
): Core.APIPromise<ApplicationGenerateContentResponse> {
return this._client.post(`/v1/applications/${applicationId}`, { body, ...options });
}
}

export interface ApplicationGenerateContentResponse {
/**
* The response from the model specified in the application.
*/
suggestion: string;

/**
* The name of the output field.
*/
title?: string;
}

export interface ApplicationGenerateContentParams {
inputs: Array<ApplicationGenerateContentParams.Input>;
}

export namespace ApplicationGenerateContentParams {
export interface Input {
/**
* The unique identifier for the input field from the application. All input types
* from the No-code application are supported (i.e. Text input, Dropdown, File
* upload, Image input). The identifier should be the name of the input type.
*/
id: string;

/**
* The value for the input field. If file is required you will need to pass a
* `file_id`. See
* [here](https://dev.writer.com/api-guides/api-reference/file-api/upload-files)
* for the Files API.
*/
value: Array<string>;
}
}

export namespace Applications {
export import ApplicationGenerateContentResponse = ApplicationsAPI.ApplicationGenerateContentResponse;
export import ApplicationGenerateContentParams = ApplicationsAPI.ApplicationGenerateContentParams;
}
Loading

0 comments on commit fcf89ed

Please sign in to comment.