skytells 1.0.2 → 1.0.4

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.
Files changed (47) hide show
  1. package/README.md +332 -121
  2. package/dist/chat.cjs +33 -0
  3. package/dist/chat.d.ts +82 -0
  4. package/dist/chat.js +33 -0
  5. package/dist/client.cjs +1151 -35
  6. package/dist/client.d.ts +776 -27
  7. package/dist/client.js +1151 -35
  8. package/dist/embeddings.cjs +40 -0
  9. package/dist/embeddings.d.ts +38 -0
  10. package/dist/embeddings.js +40 -0
  11. package/dist/endpoints.cjs +25 -7
  12. package/dist/endpoints.d.ts +18 -0
  13. package/dist/endpoints.js +25 -7
  14. package/dist/http.cjs +638 -53
  15. package/dist/http.d.ts +136 -2
  16. package/dist/http.js +638 -53
  17. package/dist/index.cjs +52 -6
  18. package/dist/index.d.ts +46 -7
  19. package/dist/index.js +52 -6
  20. package/dist/orchestrator.cjs +202 -0
  21. package/dist/orchestrator.d.ts +142 -0
  22. package/dist/orchestrator.js +202 -0
  23. package/dist/prediction-urls.cjs +38 -0
  24. package/dist/prediction-urls.d.ts +18 -0
  25. package/dist/prediction-urls.js +38 -0
  26. package/dist/responses.cjs +23 -0
  27. package/dist/responses.d.ts +60 -0
  28. package/dist/responses.js +23 -0
  29. package/dist/safety.cjs +323 -0
  30. package/dist/safety.d.ts +91 -0
  31. package/dist/safety.js +323 -0
  32. package/dist/types/index.d.ts +2 -0
  33. package/dist/types/index.js +2 -0
  34. package/dist/types/inference.types.d.ts +583 -0
  35. package/dist/types/inference.types.js +65 -0
  36. package/dist/types/model.types.d.ts +58 -4
  37. package/dist/types/model.types.js +13 -0
  38. package/dist/types/orchestrator.types.d.ts +61 -0
  39. package/dist/types/orchestrator.types.js +7 -0
  40. package/dist/types/predict.types.d.ts +258 -16
  41. package/dist/types/predict.types.js +22 -0
  42. package/dist/types/shared.types.d.ts +156 -3
  43. package/dist/types/shared.types.js +73 -2
  44. package/dist/webhooks.cjs +310 -0
  45. package/dist/webhooks.d.ts +171 -0
  46. package/dist/webhooks.js +310 -0
  47. package/package.json +26 -2
package/dist/http.d.ts CHANGED
@@ -1,7 +1,141 @@
1
+ /**
2
+ * Internal HTTP transport: JSON REST, retries, per-request timeouts, SSE chat streams, NDJSON, raw text/binary.
3
+ *
4
+ * **Not a public import** — use {@link SkytellsClient} (`Skytells()` factory). This module documents behavior for
5
+ * maintainers, LLMs, and IDE hover.
6
+ *
7
+ * | Concern | Behavior |
8
+ * |--------|------------|
9
+ * | **Timeouts** | `AbortController` + `clearTimeout` in `finally` (no orphaned timers). |
10
+ * | **Retries** | Only non-streaming JSON/text/buffer helpers; linear delay `retryDelay * (attempt + 1)`. |
11
+ * | **Streams** | `ReadableStream` reader `cancel()` in `finally`; body `cancel()` if `getReader()` missing. |
12
+ * | **Auth** | `skytells`: `x-api-key` + `Authorization`. `orchestrator`: Bearer only (see `transport`). |
13
+ * | **Errors** | Throws {@link SkytellsError} (`errorId`, `httpStatus`, optional `requestId`). |
14
+ *
15
+ * @see docs/Reliability.md — resource and option clamping.
16
+ * @module http
17
+ */
18
+ import type { RetryOptions } from './types/shared.types.js';
19
+ /** Default request timeout (ms) for JSON and SSE requests. */
20
+ export declare const HTTP_DEFAULT_REQUEST_TIMEOUT_MS = 60000;
21
+ /**
22
+ * Which product this {@link HTTP} instance calls. Set only by {@link SkytellsClient} — app code uses
23
+ * `Skytells('sk-…', { orchestratorApiKey: 'wfb_…' })`; the client wires the correct transport per API.
24
+ *
25
+ * - **`skytells`** — platform API (`sk-…`): `x-api-key` + `Authorization: Bearer`
26
+ * - **`orchestrator`** — Orchestrator (`wfb_…`): `Authorization: Bearer` only (no `x-api-key`)
27
+ *
28
+ * @internal
29
+ */
30
+ type HttpTransport = 'skytells' | 'orchestrator';
31
+ type HttpJsonMethod = 'GET' | 'POST' | 'DELETE' | 'PATCH' | 'PUT';
32
+ /**
33
+ * Fetch-based client for one API origin (`baseUrl`) and one auth policy (`transport`).
34
+ *
35
+ * @internal Constructed only by {@link SkytellsClient} (and Orchestrator sub-client).
36
+ */
1
37
  export declare class HTTP {
2
38
  private apiKey?;
3
39
  private baseUrl;
4
40
  private timeout;
5
- constructor(apiKey?: string, baseUrl?: string, timeout?: number);
6
- request<T>(method: 'GET' | 'POST' | 'DELETE', path: string, data?: Record<string, unknown>): Promise<T>;
41
+ private customHeaders;
42
+ private retry;
43
+ private fetchFn;
44
+ private transport;
45
+ /**
46
+ * @param apiKey - Platform `sk-…` or Orchestrator `wfb_…` depending on `transport`.
47
+ * @param baseUrl - API origin (`api.skytells.ai/v1` or `orchestrator.skytells.ai`).
48
+ * @param timeout - Per-request/stream abort time in ms.
49
+ * @param headers - Merged into every request (JSON and SSE).
50
+ * @param retry - Retries only for non-streaming {@link HTTP.request}.
51
+ * @param fetchFn - Inject mock/proxy/`cache: 'no-store'` fetch.
52
+ * @param transport - **`orchestrator`** for `client.orchestrator` only; default **`skytells`** for predictions/inference.
53
+ */
54
+ constructor(apiKey?: string, baseUrl?: string, timeout?: number, headers?: Record<string, string>, retry?: RetryOptions, fetchFn?: typeof fetch, transport?: HttpTransport);
55
+ /**
56
+ * Orchestrator transport must not send `x-api-key` — only `Authorization: Bearer wfb_…` per
57
+ * [Orchestrator webhooks](https://learn.skytells.ai/docs/products/orchestrator/webhooks). Strip any
58
+ * `x-api-key` copied from shared **`ClientOptions.headers`** so the Skytells `sk-…` key is never
59
+ * forwarded to `orchestrator.skytells.ai`.
60
+ */
61
+ private applyAuthHeaders;
62
+ /**
63
+ * Resolved API origin (no trailing slash), e.g. `https://api.skytells.ai/v1`.
64
+ *
65
+ * @returns Same string passed to the constructor (or default {@link API_BASE_URL}).
66
+ */
67
+ getBaseUrl(): string;
68
+ /**
69
+ * API key for this instance (`sk-…` or `wfb_…`), if any.
70
+ *
71
+ * @returns `undefined` for unauthenticated clients. Used by {@link SkytellsClient.webhookListener} for General HMAC.
72
+ */
73
+ getApiKey(): string | undefined;
74
+ /**
75
+ * Non-streaming JSON `fetch`: read `response.text()` once, `JSON.parse`, map API errors to {@link SkytellsError}.
76
+ *
77
+ * @typeParam T - Expected successful JSON body shape (caller-supplied; not validated at runtime).
78
+ * @param method - HTTP verb. Body sent only for `POST`, `PATCH`, `PUT`.
79
+ * @param path - Relative to `baseUrl`, or absolute `http(s)://…`.
80
+ * @param data - Serializable JSON object. **Circular references** → `SDK_ERROR`. Omit for GET/DELETE.
81
+ * @returns Parsed response JSON.
82
+ * @throws {SkytellsError} `REQUEST_TIMEOUT`, `NETWORK_ERROR`, `INVALID_JSON`, `SERVER_ERROR`, or API `error.error_id`.
83
+ * @remarks Retries when `httpStatus` is in `retry.retryOn` and attempts remain. Skytells prediction “queued” envelopes are normalized inside the internal fetch path.
84
+ */
85
+ request<T>(method: HttpJsonMethod, path: string, data?: Record<string, unknown>): Promise<T>;
86
+ private delay;
87
+ private executeRequest;
88
+ /**
89
+ * **SSE** streaming `POST`: parses `data: …` lines as JSON (chat completions when `stream: true`).
90
+ *
91
+ * @typeParam T - Usually {@link ChatCompletionChunk} from inference types.
92
+ * @param path - e.g. `/chat/completions`.
93
+ * @param data - Must include `stream: true`. Must be JSON-serializable or throws `SDK_ERROR`.
94
+ * @returns Async iterable; consume with `for await`. Malformed lines skipped; `[DONE]` ignored.
95
+ * @throws {SkytellsError} Non-OK HTTP, timeout (`REQUEST_TIMEOUT`), or missing body reader.
96
+ * @remarks **Not retried.** Abandoning the loop still runs `reader.cancel()` in `finally`. Timeout cleared in outer `finally`.
97
+ */
98
+ requestStream<T>(path: string, data: Record<string, unknown>): AsyncIterable<T>;
99
+ /**
100
+ * Successful response read as **plain text** (not JSON-validated). Used for code export, etc.
101
+ *
102
+ * @param method - Currently **`GET`** only in SDK call sites.
103
+ * @param path - Relative or absolute URL.
104
+ * @returns Full response body string.
105
+ * @throws {SkytellsError} Same families as {@link HTTP.request} for HTTP/network/timeout errors.
106
+ * @remarks Uses same **retry** policy as {@link HTTP.request}.
107
+ */
108
+ requestText(method: 'GET', path: string): Promise<string>;
109
+ /**
110
+ * Successful response as **binary** (`arrayBuffer()`), e.g. ZIP downloads.
111
+ *
112
+ * @param method - **`GET`** in practice.
113
+ * @param path - Relative or absolute URL.
114
+ * @returns Raw bytes.
115
+ * @throws {SkytellsError} On HTTP error, timeout, or network failure.
116
+ * @remarks Same **retry** policy as {@link HTTP.request}.
117
+ */
118
+ requestBuffer(method: 'GET', path: string): Promise<ArrayBuffer>;
119
+ /**
120
+ * Fire **`OPTIONS`** (CORS preflight for Orchestrator webhooks). **No retries.**
121
+ *
122
+ * @param path - Full path under `baseUrl`.
123
+ * @throws {SkytellsError} If `!response.ok`, timeout, or network error.
124
+ */
125
+ requestOptions(path: string): Promise<void>;
126
+ /**
127
+ * **NDJSON / JSONL** `POST`: one JSON object per line (Orchestrator AI workflow generation).
128
+ *
129
+ * @typeParam T - Line shape; default `Record<string, unknown>`.
130
+ * @param path - e.g. `/api/ai/generate`.
131
+ * @param data - Serialized as JSON body; circular data → `SDK_ERROR`.
132
+ * @returns Async iterable of parsed lines; invalid JSON lines skipped.
133
+ * @throws {SkytellsError} HTTP error, timeout, or missing stream body.
134
+ * @remarks **Not retried** after bytes flow. Reader/body cleanup same as {@link HTTP.requestStream}.
135
+ */
136
+ requestNdjsonStream<T = Record<string, unknown>>(path: string, data: Record<string, unknown>): AsyncIterable<T>;
137
+ private executeRequestRawText;
138
+ private executeRequestRawBuffer;
139
+ private throwFromTextErrorResponse;
7
140
  }
141
+ export {};