@sinatra-dev/sdk 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +153 -2
- package/dist/index.cjs +1170 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +929 -0
- package/dist/index.d.ts +929 -0
- package/dist/index.js +1147 -0
- package/dist/index.js.map +1 -0
- package/package.json +71 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Sinatra
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,154 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @sinatra-dev/sdk
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A TypeScript client for the [Sinatra API](https://docs.sinatra.dev/docs/api-reference): start, follow and stop Sinatra tasks, and delegate Linear and GitHub issues.
|
|
4
|
+
|
|
5
|
+
It runs on Node.js 20 and later, ships ESM and CommonJS builds with types, and has no runtime dependencies. The client is generated from the API's [OpenAPI spec](https://api.sinatra.dev/openapi.json) and released automatically when the spec changes.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
npm install @sinatra-dev/sdk
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Quick start
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import { Sinatra } from "@sinatra-dev/sdk";
|
|
17
|
+
|
|
18
|
+
const sinatra = new Sinatra(); // reads SINATRA_TOKEN
|
|
19
|
+
const me = await sinatra.me.get();
|
|
20
|
+
const workspace = me.workspaces[0];
|
|
21
|
+
if (!workspace) throw new Error("The token's user isn't in any workspace yet.");
|
|
22
|
+
|
|
23
|
+
const { task } = await sinatra.tasks.create(
|
|
24
|
+
workspace.id,
|
|
25
|
+
{ prompt: "Fix the flaky login test", repo: "acme/web" },
|
|
26
|
+
{ idempotencyKey: "fix-flaky-login-1" },
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
// The turn is done when the task leaves these statuses (for example, it reaches replied or pr_open).
|
|
30
|
+
const WORKING = new Set(["pending", "investigating", "implementing", "rework"]);
|
|
31
|
+
let after: string | undefined;
|
|
32
|
+
for (;;) {
|
|
33
|
+
const { status } = await sinatra.tasks.get(workspace.id, task.id);
|
|
34
|
+
for await (const m of sinatra.messages.listAll(workspace.id, task.id, { after })) {
|
|
35
|
+
console.log(`${m.role}: ${m.body}`);
|
|
36
|
+
after = m.id;
|
|
37
|
+
}
|
|
38
|
+
if (!WORKING.has(status)) break;
|
|
39
|
+
await new Promise((r) => setTimeout(r, 3000));
|
|
40
|
+
}
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
The API has no streaming. To wait for a reply, read the conversation after the last entry you've seen, and check the task's `status`: the agent posts one reply per turn, and the turn is done when the task stops working. The loop reads the status before the conversation, so it never stops before printing the reply that ended the turn. An unknown status counts as done, so the loop can't wait forever on a status added after this was written. See [How replies work](https://docs.sinatra.dev/docs/cli-and-api#how-replies-work).
|
|
44
|
+
|
|
45
|
+
## Authentication
|
|
46
|
+
|
|
47
|
+
Create a personal access token on the [Access tokens](https://app.sinatra.dev/tokens) page (**CLI & API** in the dashboard). It starts with `sntr_` and acts as you in every workspace you belong to. The client reads it from the `SINATRA_TOKEN` environment variable, or you can pass it:
|
|
48
|
+
|
|
49
|
+
```ts
|
|
50
|
+
const sinatra = new Sinatra({ token: process.env.MY_TOKEN });
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
The constructor throws if it finds no token. Other options:
|
|
54
|
+
|
|
55
|
+
- `baseUrl`: defaults to `https://api.sinatra.dev`.
|
|
56
|
+
- `timeout`: how long each attempt may take, in milliseconds, before it's aborted with a `TimeoutError`. Defaults to 60 seconds; `0` turns it off. Values above 2^31−1 (about 24.8 days) are cut to that, the most `setTimeout` can wait.
|
|
57
|
+
- `fetch`: a `fetch` to use instead of the global one.
|
|
58
|
+
|
|
59
|
+
Every method takes `{ signal, timeout }` as its last argument: `signal` cancels the call, including a retry it's waiting to make, and `timeout` overrides the client's for that call.
|
|
60
|
+
|
|
61
|
+
```ts
|
|
62
|
+
await sinatra.tasks.get(workspaceId, taskId, { timeout: 5_000 });
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## Operations
|
|
66
|
+
|
|
67
|
+
The namespaces mirror the API's operation ids:
|
|
68
|
+
|
|
69
|
+
| Method | Request |
|
|
70
|
+
| --- | --- |
|
|
71
|
+
| `me.get()` | `GET /v1/me` |
|
|
72
|
+
| `me.revokeToken()` | `DELETE /v1/me/token` |
|
|
73
|
+
| `tasks.list(workspaceId, { status?, limit?, cursor? })` | `GET /v1/workspaces/{workspaceId}/tasks` |
|
|
74
|
+
| `tasks.get(workspaceId, taskId)` | `GET /v1/workspaces/{workspaceId}/tasks/{taskId}` |
|
|
75
|
+
| `tasks.create(workspaceId, { prompt, title?, repo? }, { idempotencyKey? })` | `POST /v1/workspaces/{workspaceId}/tasks` |
|
|
76
|
+
| `tasks.stop(workspaceId, taskId)` | `POST /v1/workspaces/{workspaceId}/tasks/{taskId}/stop` |
|
|
77
|
+
| `messages.create(workspaceId, taskId, { text }, { idempotencyKey? })` | `POST /v1/workspaces/{workspaceId}/tasks/{taskId}/messages` |
|
|
78
|
+
| `messages.list(workspaceId, taskId, { after?, limit? })` | `GET /v1/workspaces/{workspaceId}/tasks/{taskId}/messages` |
|
|
79
|
+
| `tickets.search(workspaceId, { q?, repo? })` | `GET /v1/workspaces/{workspaceId}/tickets` |
|
|
80
|
+
| `tickets.delegate(workspaceId, { source: "linear", id } \| { source: "github", repo, number })` | `POST /v1/workspaces/{workspaceId}/tickets/delegate` |
|
|
81
|
+
|
|
82
|
+
`tasks.listAll` and `messages.listAll` page through everything for you:
|
|
83
|
+
|
|
84
|
+
```ts
|
|
85
|
+
for await (const task of sinatra.tasks.listAll(workspaceId, { status: "pr_open" })) {
|
|
86
|
+
console.log(task.id, task.title);
|
|
87
|
+
}
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
Fields such as `status`, `source`, `role`, `kind` and the error `code` are plain strings, and the API adds new values over time. Handle values you don't recognise.
|
|
91
|
+
|
|
92
|
+
## Retries and idempotency
|
|
93
|
+
|
|
94
|
+
`tasks.create` and `messages.create` always send an `Idempotency-Key`. If you don't pass one, the client makes a random UUID. Every retry of a call sends the same key, so a retried start never starts a second task. Pass your own key to make a retry safe across process restarts too.
|
|
95
|
+
|
|
96
|
+
The client retries a request up to 3 times when it's safe to repeat:
|
|
97
|
+
|
|
98
|
+
- `429`: after the `Retry-After` the server sends, at most 60 seconds.
|
|
99
|
+
- `503`: after 0.5s, then 1s, then 2s.
|
|
100
|
+
|
|
101
|
+
GETs, `me.revokeToken`, `tasks.create` and `messages.create` retry on both. `tasks.stop` retries on `503` only. `tickets.delegate` takes no idempotency key and is never retried. Other errors, timeouts and network failures are never retried.
|
|
102
|
+
|
|
103
|
+
## Errors
|
|
104
|
+
|
|
105
|
+
An error response throws a `SinatraError`:
|
|
106
|
+
|
|
107
|
+
```ts
|
|
108
|
+
import { SinatraError } from "@sinatra-dev/sdk";
|
|
109
|
+
|
|
110
|
+
try {
|
|
111
|
+
await sinatra.tasks.stop(workspaceId, task.id);
|
|
112
|
+
} catch (err) {
|
|
113
|
+
if (err instanceof SinatraError && err.code === "not_running") {
|
|
114
|
+
// the task had already stopped
|
|
115
|
+
} else {
|
|
116
|
+
throw err;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
| Field | |
|
|
122
|
+
| --- | --- |
|
|
123
|
+
| `status` | The HTTP status. |
|
|
124
|
+
| `code` | The API's `error` code, such as `capacity_full`. `http_error` when the response carried none, such as an HTML error page from a proxy. |
|
|
125
|
+
| `reason` | A sentence for a person. Don't branch on it. |
|
|
126
|
+
| `requestId` | The request's id. Include it when you contact support. |
|
|
127
|
+
| `body` | The response body: the parsed JSON, or the text. Refusals carry extra fields here, such as `billingUrl`. |
|
|
128
|
+
| `headers` | The response headers. |
|
|
129
|
+
|
|
130
|
+
Network failures, timeouts and aborts are not wrapped: they reject with the error `fetch` threw, the `TimeoutError`, or your signal's reason.
|
|
131
|
+
|
|
132
|
+
The [API reference](https://docs.sinatra.dev/docs/api-reference) lists every operation's error codes.
|
|
133
|
+
|
|
134
|
+
## Versions
|
|
135
|
+
|
|
136
|
+
Releases follow semver. While the version is `0.x`, a breaking API change bumps the minor version and anything else bumps the patch. From `1.0`, breaking changes bump the major version and additions bump the minor.
|
|
137
|
+
|
|
138
|
+
## Development
|
|
139
|
+
|
|
140
|
+
```sh
|
|
141
|
+
npm ci
|
|
142
|
+
npm run tools # installs the pinned oasdiff into .tools/bin
|
|
143
|
+
npm run generate # regenerates src/generated from openapi.json
|
|
144
|
+
npm run typecheck && npm run build
|
|
145
|
+
npm test # wrapper tests against a local stub server
|
|
146
|
+
npm run test:contract # every operation against a Prism mock of openapi.json
|
|
147
|
+
npm run test:version # scripts/next-version.sh
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
`src/generated` is written by `@hey-api/openapi-ts` and never edited by hand; CI fails if it differs from what `openapi.json` generates. `openapi.json` is updated by the release workflow. See [RELEASING.md](RELEASING.md).
|
|
151
|
+
|
|
152
|
+
## License
|
|
153
|
+
|
|
154
|
+
MIT
|