@krizaka/orazaka-client 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 +201 -0
- package/README.md +19 -2
- package/dist/index.d.ts +172 -0
- package/dist/index.js +257 -0
- package/dist/index.js.map +1 -0
- package/package.json +56 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,20 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @krizaka/orazaka-client
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
One client of Orazaka's edge for every Krizaka TypeScript product, instead of one copy per product (Yomizaka, Orochia, soon Akinaza): start a Studio run, read its status and its outputs, wait for it. The base URL, the key and the clock are **parameters** — this package reads no environment and no wall clock.
|
|
4
|
+
|
|
5
|
+
```ts
|
|
6
|
+
import { createOrazakaClient, outputOf } from "@krizaka/orazaka-client";
|
|
7
|
+
|
|
8
|
+
const orazaka = createOrazakaClient({ baseUrl: "https://api.orazaka.com", apiKey: env.AI_API_KEY, clock: { now: () => new Date() } });
|
|
9
|
+
|
|
10
|
+
const { run } = await orazaka.startRun("compliance-check", { document: text }, { idempotencyKey: `doc-${documentId}-v${version}` });
|
|
11
|
+
const done = await orazaka.waitForRun(run.id); // or poll `getRun` yourself
|
|
12
|
+
if (done.status === "SUCCEEDED") use(outputOf(done, "report"));
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
- **Safe to retry.** `startRun` with an `idempotencyKey` answers the run already started for the same key and inputs (`replayed: true`) instead of paying for a second one; the same key for other inputs is `ORAZAKA_KEY_REUSED`.
|
|
16
|
+
- **Typed errors.** Every failure is an `OrazakaError` with a stable `code` (`ORAZAKA_KEY`, `ORAZAKA_CREDITS`, `ORAZAKA_LOCKED`, `ORAZAKA_INPUT`, `ORAZAKA_NOT_FOUND`, `ORAZAKA_BUSY` with `retryAfterSeconds`, `ORAZAKA_UNAVAILABLE`, `ORAZAKA_TIMEOUT`, `ORAZAKA_SHAPE`, `ORAZAKA_CIRCUIT_OPEN`…) and the `status` a product answers its own caller with. A product translates the codes; none is a sentence. A failed *run* is not an error: `waitForRun` gives it back with its `errorMessage`.
|
|
17
|
+
- **A time limit and a circuit breaker**, as options: `timeoutMs` (20 s by default) on every call; five failures in a row (no answer, timeout, 5xx) open the circuit for 30 s — it refuses at once, then lets one call probe. A refusal (401, 402, 404, 429…) is an answer and never opens it. `circuit: false` turns it off.
|
|
18
|
+
- **Contract-tested** against the edge's answers kept as fixtures (`test/fixtures`): when the edge changes a shape, the fixture changes first.
|
|
19
|
+
|
|
20
|
+
Run events as a stream (Server-Sent Events, `GET /api/v1/studios/runs/{id}/events`) come in a later minor; `waitForRun` polls until then.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
interface Clock {
|
|
2
|
+
now(): Date;
|
|
3
|
+
}
|
|
4
|
+
interface CircuitOptions {
|
|
5
|
+
/** Consecutive failures (no answer, timeout, 5xx) that open the circuit. */
|
|
6
|
+
failureThreshold: number;
|
|
7
|
+
/** How long it stays open before one call is let through to probe. */
|
|
8
|
+
openSeconds: number;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* A circuit breaker over a dependency that may be down: after `failureThreshold` failures in a row it refuses at once (no waiting on
|
|
12
|
+
* a timeout, no load on a struggling service) for `openSeconds`, then lets ONE call through; its success closes the circuit, its
|
|
13
|
+
* failure opens it again. A refusal of the edge (401, 402, 404…) is an answer, not a failure: only the caller reports failures.
|
|
14
|
+
*/
|
|
15
|
+
declare function createCircuit(options: CircuitOptions, clock: Clock): {
|
|
16
|
+
/** Throws `ORAZAKA_CIRCUIT_OPEN` while the circuit is open (or its probe is in flight). */
|
|
17
|
+
check(): void;
|
|
18
|
+
success(): void;
|
|
19
|
+
failure(): void;
|
|
20
|
+
/** Test and diagnostics: is it refusing now? */
|
|
21
|
+
readonly isOpen: boolean;
|
|
22
|
+
};
|
|
23
|
+
type Circuit = ReturnType<typeof createCircuit>;
|
|
24
|
+
|
|
25
|
+
/** One output of a run (orazaka-studio `RunArtefactResponse`): `type` is a rendering hint (`TEXT`, `IMAGE`, `VIDEO`…). */
|
|
26
|
+
interface RunOutput {
|
|
27
|
+
key: string;
|
|
28
|
+
label: string | null;
|
|
29
|
+
type: string;
|
|
30
|
+
value: string | null;
|
|
31
|
+
}
|
|
32
|
+
/** Where a run sits (orazaka-studio `RunStatus`). The client keeps the string the edge sent, so a new status is not a failure. */
|
|
33
|
+
declare const RUN_STATUS: {
|
|
34
|
+
readonly pendingApproval: "PENDING_APPROVAL";
|
|
35
|
+
readonly running: "RUNNING";
|
|
36
|
+
readonly awaitingInput: "AWAITING_INPUT";
|
|
37
|
+
readonly succeeded: "SUCCEEDED";
|
|
38
|
+
readonly failed: "FAILED";
|
|
39
|
+
readonly cancelled: "CANCELLED";
|
|
40
|
+
readonly compensating: "COMPENSATING";
|
|
41
|
+
};
|
|
42
|
+
/** A run, as the edge answers it (`GET /api/v1/studios/runs/{id}`). Only what a product reads. */
|
|
43
|
+
interface OrazakaRun {
|
|
44
|
+
id: string;
|
|
45
|
+
studioKey: string;
|
|
46
|
+
blueprintVersion: string | null;
|
|
47
|
+
status: string;
|
|
48
|
+
outputs: RunOutput[];
|
|
49
|
+
errorMessage: string | null;
|
|
50
|
+
startedAt: string | null;
|
|
51
|
+
finishedAt: string | null;
|
|
52
|
+
}
|
|
53
|
+
/** The run is over, green or not: nothing more will change. */
|
|
54
|
+
declare const isTerminal: (run: Pick<OrazakaRun, "status">) => boolean;
|
|
55
|
+
/** The value of one output, or null when the run did not produce it (yet). */
|
|
56
|
+
declare const outputOf: (run: Pick<OrazakaRun, "outputs">, key: string) => string | null;
|
|
57
|
+
/** Reads a run from the edge's JSON; anything else is `ORAZAKA_SHAPE`. */
|
|
58
|
+
declare function parseRun(body: unknown): OrazakaRun;
|
|
59
|
+
/** The Studios an account installed: `GET /api/v1/studios/installations`. */
|
|
60
|
+
declare function parseInstallations(body: unknown): string[];
|
|
61
|
+
|
|
62
|
+
type Fetch = typeof fetch;
|
|
63
|
+
interface OrazakaClientOptions {
|
|
64
|
+
/** `https://api.orazaka.com` — the edge. A parameter: this package reads no environment. */
|
|
65
|
+
baseUrl: string;
|
|
66
|
+
/** The product's service key (`oz_…`). Without one every call throws `ORAZAKA_NOT_CONFIGURED`. */
|
|
67
|
+
apiKey: string | undefined;
|
|
68
|
+
/** Time is injected: the circuit and `waitForRun` read it from here. */
|
|
69
|
+
clock: Clock;
|
|
70
|
+
fetch?: Fetch;
|
|
71
|
+
/** One call's time limit, in milliseconds (default 20 000). */
|
|
72
|
+
timeoutMs?: number;
|
|
73
|
+
/** The breaker: `false` for none; default 5 failures in a row open it for 30 seconds. */
|
|
74
|
+
circuit?: CircuitOptions | false;
|
|
75
|
+
/** Install the Studio on the account before its first run (default true: the edge asks for it). */
|
|
76
|
+
autoInstall?: boolean;
|
|
77
|
+
/** How `waitForRun` waits between two reads (default `setTimeout`); tests give their own. */
|
|
78
|
+
sleep?: (milliseconds: number) => Promise<void>;
|
|
79
|
+
}
|
|
80
|
+
interface StartRunOptions {
|
|
81
|
+
/** Retrying with the same key (and the same inputs) answers the run already started instead of paying for a second one. */
|
|
82
|
+
idempotencyKey?: string;
|
|
83
|
+
}
|
|
84
|
+
interface StartedRun {
|
|
85
|
+
run: OrazakaRun;
|
|
86
|
+
/** The edge answered a run it had already started for this key (`Idempotent-Replayed`). */
|
|
87
|
+
replayed: boolean;
|
|
88
|
+
}
|
|
89
|
+
interface WaitOptions {
|
|
90
|
+
/** Between two reads, in milliseconds (default 2 000). */
|
|
91
|
+
intervalMs?: number;
|
|
92
|
+
/** Give up after this long, in milliseconds (default 120 000): `ORAZAKA_WAIT_EXPIRED`. */
|
|
93
|
+
timeoutMs?: number;
|
|
94
|
+
}
|
|
95
|
+
interface OrazakaClient {
|
|
96
|
+
/** Starts a Studio run (`POST /api/v1/studios/{studio}/runs`, 202). Pass an idempotency key to make the retry safe. */
|
|
97
|
+
startRun(studio: string, inputs: Record<string, unknown>, options?: StartRunOptions): Promise<StartedRun>;
|
|
98
|
+
/** The run, its status and its outputs (`GET /api/v1/studios/runs/{id}`). */
|
|
99
|
+
getRun(runId: string): Promise<OrazakaRun>;
|
|
100
|
+
/** Reads the run until it is over (succeeded, failed or cancelled) and answers it; a failed run is returned, not thrown. */
|
|
101
|
+
waitForRun(runId: string, options?: WaitOptions): Promise<OrazakaRun>;
|
|
102
|
+
/** The Studios this key has installed — also the cheapest call that proves the key and the connection. */
|
|
103
|
+
studios(): Promise<string[]>;
|
|
104
|
+
/** The circuit breaker, for diagnostics. */
|
|
105
|
+
readonly circuit: Circuit | null;
|
|
106
|
+
}
|
|
107
|
+
/** Orazaka's edge, for every TypeScript product: one client instead of one copy per product. */
|
|
108
|
+
declare function createOrazakaClient(options: OrazakaClientOptions): OrazakaClient;
|
|
109
|
+
|
|
110
|
+
/** The stable codes of a refusal or a failure of Orazaka's edge — a product translates them; none is a sentence. */
|
|
111
|
+
declare const ORAZAKA_CODE: {
|
|
112
|
+
/** No API key was given. */
|
|
113
|
+
readonly notConfigured: "ORAZAKA_NOT_CONFIGURED";
|
|
114
|
+
/** 401/403: the key is wrong, revoked or lacks the right. */
|
|
115
|
+
readonly key: "ORAZAKA_KEY";
|
|
116
|
+
/** 402: the run is not affordable now. */
|
|
117
|
+
readonly credits: "ORAZAKA_CREDITS";
|
|
118
|
+
/** 409: the Studio is locked (to buy, or already installed). */
|
|
119
|
+
readonly locked: "ORAZAKA_LOCKED";
|
|
120
|
+
/** 400/422: the inputs are not what the Studio asks for. */
|
|
121
|
+
readonly input: "ORAZAKA_INPUT";
|
|
122
|
+
/** 404: no such Studio or run (or not the caller's). */
|
|
123
|
+
readonly notFound: "ORAZAKA_NOT_FOUND";
|
|
124
|
+
/** 429: too many runs at once; `retryAfterSeconds` says when to come back. Not a failure of the document. */
|
|
125
|
+
readonly busy: "ORAZAKA_BUSY";
|
|
126
|
+
/** 422 `idempotency_key_reused`: the key already started a different request. */
|
|
127
|
+
readonly keyReused: "ORAZAKA_KEY_REUSED";
|
|
128
|
+
/** 451: a consent is to be agreed to first. */
|
|
129
|
+
readonly consent: "ORAZAKA_CONSENT";
|
|
130
|
+
/** The edge did not answer, or answered 5xx. */
|
|
131
|
+
readonly unavailable: "ORAZAKA_UNAVAILABLE";
|
|
132
|
+
/** The edge did not answer within the time given. */
|
|
133
|
+
readonly timeout: "ORAZAKA_TIMEOUT";
|
|
134
|
+
/** The edge answered something that is not a run (or a list of installations). */
|
|
135
|
+
readonly shape: "ORAZAKA_SHAPE";
|
|
136
|
+
/** Too many failures in a row: the client does not call until the pause is over. */
|
|
137
|
+
readonly circuitOpen: "ORAZAKA_CIRCUIT_OPEN";
|
|
138
|
+
/** A run id that is not one: refused before any call. */
|
|
139
|
+
readonly badRun: "ORAZAKA_BAD_RUN";
|
|
140
|
+
/** `waitForRun` gave up: the run was still going. */
|
|
141
|
+
readonly waitExpired: "ORAZAKA_WAIT_EXPIRED";
|
|
142
|
+
};
|
|
143
|
+
type OrazakaCode = (typeof ORAZAKA_CODE)[keyof typeof ORAZAKA_CODE];
|
|
144
|
+
/** What the edge's status means for a product that answers its own caller: the status to send back and the code. */
|
|
145
|
+
declare function orazakaRefusal(status: number): {
|
|
146
|
+
status: number;
|
|
147
|
+
code: OrazakaCode;
|
|
148
|
+
};
|
|
149
|
+
declare class OrazakaError extends Error {
|
|
150
|
+
readonly code: OrazakaCode;
|
|
151
|
+
readonly details: {
|
|
152
|
+
/** What the edge answered, when it answered. */
|
|
153
|
+
upstreamStatus?: number;
|
|
154
|
+
/** The status a product should answer its own caller with. */
|
|
155
|
+
status?: number;
|
|
156
|
+
/** For `ORAZAKA_BUSY` and `ORAZAKA_CIRCUIT_OPEN`: seconds to wait. */
|
|
157
|
+
retryAfterSeconds?: number;
|
|
158
|
+
};
|
|
159
|
+
constructor(code: OrazakaCode, message: string, details?: {
|
|
160
|
+
/** What the edge answered, when it answered. */
|
|
161
|
+
upstreamStatus?: number;
|
|
162
|
+
/** The status a product should answer its own caller with. */
|
|
163
|
+
status?: number;
|
|
164
|
+
/** For `ORAZAKA_BUSY` and `ORAZAKA_CIRCUIT_OPEN`: seconds to wait. */
|
|
165
|
+
retryAfterSeconds?: number;
|
|
166
|
+
});
|
|
167
|
+
/** The HTTP status a product answers its own caller with (502 for a failure upstream, 429 when busy). */
|
|
168
|
+
get status(): number;
|
|
169
|
+
get retryAfterSeconds(): number | undefined;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
export { type Circuit, type CircuitOptions, type Clock, ORAZAKA_CODE, type OrazakaClient, type OrazakaClientOptions, type OrazakaCode, OrazakaError, type OrazakaRun, RUN_STATUS, type RunOutput, type StartRunOptions, type StartedRun, type WaitOptions, createCircuit, createOrazakaClient, isTerminal, orazakaRefusal, outputOf, parseInstallations, parseRun };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
// src/circuit.ts
|
|
2
|
+
import { addSeconds, differenceInSeconds, isBefore } from "date-fns";
|
|
3
|
+
|
|
4
|
+
// src/errors.ts
|
|
5
|
+
var ORAZAKA_CODE = {
|
|
6
|
+
/** No API key was given. */
|
|
7
|
+
notConfigured: "ORAZAKA_NOT_CONFIGURED",
|
|
8
|
+
/** 401/403: the key is wrong, revoked or lacks the right. */
|
|
9
|
+
key: "ORAZAKA_KEY",
|
|
10
|
+
/** 402: the run is not affordable now. */
|
|
11
|
+
credits: "ORAZAKA_CREDITS",
|
|
12
|
+
/** 409: the Studio is locked (to buy, or already installed). */
|
|
13
|
+
locked: "ORAZAKA_LOCKED",
|
|
14
|
+
/** 400/422: the inputs are not what the Studio asks for. */
|
|
15
|
+
input: "ORAZAKA_INPUT",
|
|
16
|
+
/** 404: no such Studio or run (or not the caller's). */
|
|
17
|
+
notFound: "ORAZAKA_NOT_FOUND",
|
|
18
|
+
/** 429: too many runs at once; `retryAfterSeconds` says when to come back. Not a failure of the document. */
|
|
19
|
+
busy: "ORAZAKA_BUSY",
|
|
20
|
+
/** 422 `idempotency_key_reused`: the key already started a different request. */
|
|
21
|
+
keyReused: "ORAZAKA_KEY_REUSED",
|
|
22
|
+
/** 451: a consent is to be agreed to first. */
|
|
23
|
+
consent: "ORAZAKA_CONSENT",
|
|
24
|
+
/** The edge did not answer, or answered 5xx. */
|
|
25
|
+
unavailable: "ORAZAKA_UNAVAILABLE",
|
|
26
|
+
/** The edge did not answer within the time given. */
|
|
27
|
+
timeout: "ORAZAKA_TIMEOUT",
|
|
28
|
+
/** The edge answered something that is not a run (or a list of installations). */
|
|
29
|
+
shape: "ORAZAKA_SHAPE",
|
|
30
|
+
/** Too many failures in a row: the client does not call until the pause is over. */
|
|
31
|
+
circuitOpen: "ORAZAKA_CIRCUIT_OPEN",
|
|
32
|
+
/** A run id that is not one: refused before any call. */
|
|
33
|
+
badRun: "ORAZAKA_BAD_RUN",
|
|
34
|
+
/** `waitForRun` gave up: the run was still going. */
|
|
35
|
+
waitExpired: "ORAZAKA_WAIT_EXPIRED"
|
|
36
|
+
};
|
|
37
|
+
function orazakaRefusal(status) {
|
|
38
|
+
if (status === 401 || status === 403) return { status: 502, code: ORAZAKA_CODE.key };
|
|
39
|
+
if (status === 402) return { status: 502, code: ORAZAKA_CODE.credits };
|
|
40
|
+
if (status === 409) return { status: 502, code: ORAZAKA_CODE.locked };
|
|
41
|
+
if (status === 400 || status === 422) return { status: 422, code: ORAZAKA_CODE.input };
|
|
42
|
+
if (status === 404) return { status: 502, code: ORAZAKA_CODE.notFound };
|
|
43
|
+
if (status === 429) return { status: 429, code: ORAZAKA_CODE.busy };
|
|
44
|
+
if (status === 451) return { status: 502, code: ORAZAKA_CODE.consent };
|
|
45
|
+
return { status: 502, code: ORAZAKA_CODE.unavailable };
|
|
46
|
+
}
|
|
47
|
+
var OrazakaError = class extends Error {
|
|
48
|
+
constructor(code, message, details = {}) {
|
|
49
|
+
super(message);
|
|
50
|
+
this.code = code;
|
|
51
|
+
this.details = details;
|
|
52
|
+
this.name = "OrazakaError";
|
|
53
|
+
}
|
|
54
|
+
code;
|
|
55
|
+
details;
|
|
56
|
+
/** The HTTP status a product answers its own caller with (502 for a failure upstream, 429 when busy). */
|
|
57
|
+
get status() {
|
|
58
|
+
return this.details.status ?? 502;
|
|
59
|
+
}
|
|
60
|
+
get retryAfterSeconds() {
|
|
61
|
+
return this.details.retryAfterSeconds;
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
// src/circuit.ts
|
|
66
|
+
function createCircuit(options, clock) {
|
|
67
|
+
let failures = 0;
|
|
68
|
+
let openUntil = null;
|
|
69
|
+
let probing = false;
|
|
70
|
+
return {
|
|
71
|
+
/** Throws `ORAZAKA_CIRCUIT_OPEN` while the circuit is open (or its probe is in flight). */
|
|
72
|
+
check() {
|
|
73
|
+
if (openUntil === null) return;
|
|
74
|
+
const now = clock.now();
|
|
75
|
+
if (isBefore(now, openUntil)) throw open(Math.max(1, differenceInSeconds(openUntil, now)));
|
|
76
|
+
if (probing) throw open(1);
|
|
77
|
+
probing = true;
|
|
78
|
+
},
|
|
79
|
+
success() {
|
|
80
|
+
failures = 0;
|
|
81
|
+
openUntil = null;
|
|
82
|
+
probing = false;
|
|
83
|
+
},
|
|
84
|
+
failure() {
|
|
85
|
+
failures += 1;
|
|
86
|
+
if (probing || failures >= options.failureThreshold) {
|
|
87
|
+
openUntil = addSeconds(clock.now(), options.openSeconds);
|
|
88
|
+
probing = false;
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
/** Test and diagnostics: is it refusing now? */
|
|
92
|
+
get isOpen() {
|
|
93
|
+
return openUntil !== null;
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
var open = (retryAfterSeconds) => new OrazakaError(ORAZAKA_CODE.circuitOpen, "Orazaka failed several times in a row: not calling it for a moment", { retryAfterSeconds, status: 502 });
|
|
98
|
+
|
|
99
|
+
// src/client.ts
|
|
100
|
+
import { addMilliseconds, isAfter } from "date-fns";
|
|
101
|
+
|
|
102
|
+
// src/run.ts
|
|
103
|
+
var RUN_STATUS = {
|
|
104
|
+
pendingApproval: "PENDING_APPROVAL",
|
|
105
|
+
running: "RUNNING",
|
|
106
|
+
awaitingInput: "AWAITING_INPUT",
|
|
107
|
+
succeeded: "SUCCEEDED",
|
|
108
|
+
failed: "FAILED",
|
|
109
|
+
cancelled: "CANCELLED",
|
|
110
|
+
compensating: "COMPENSATING"
|
|
111
|
+
};
|
|
112
|
+
var TERMINAL = [RUN_STATUS.succeeded, RUN_STATUS.failed, RUN_STATUS.cancelled];
|
|
113
|
+
var isTerminal = (run) => TERMINAL.includes(run.status);
|
|
114
|
+
var outputOf = (run, key) => run.outputs.find((o) => o.key === key)?.value ?? null;
|
|
115
|
+
var shape = (what) => new OrazakaError(ORAZAKA_CODE.shape, `Orazaka's answer has an unexpected shape: ${what}`);
|
|
116
|
+
var text = (v) => typeof v === "string" ? v : null;
|
|
117
|
+
var parseOutput = (raw) => {
|
|
118
|
+
const o = raw ?? {};
|
|
119
|
+
if (typeof o.key !== "string" || typeof o.type !== "string") throw shape("an output without key and type");
|
|
120
|
+
return { key: o.key, label: text(o.label), type: o.type, value: text(o.value) };
|
|
121
|
+
};
|
|
122
|
+
function parseRun(body) {
|
|
123
|
+
const o = body ?? {};
|
|
124
|
+
if (typeof o.id !== "string" || typeof o.studioKey !== "string" || typeof o.status !== "string") throw shape("a run needs id, studioKey and status");
|
|
125
|
+
if (o.outputs !== void 0 && o.outputs !== null && !Array.isArray(o.outputs)) throw shape("outputs is not a list");
|
|
126
|
+
return {
|
|
127
|
+
id: o.id,
|
|
128
|
+
studioKey: o.studioKey,
|
|
129
|
+
blueprintVersion: text(o.blueprintVersion),
|
|
130
|
+
status: o.status,
|
|
131
|
+
outputs: (o.outputs ?? []).map(parseOutput),
|
|
132
|
+
errorMessage: text(o.errorMessage),
|
|
133
|
+
startedAt: text(o.startedAt),
|
|
134
|
+
finishedAt: text(o.finishedAt)
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
function parseInstallations(body) {
|
|
138
|
+
if (!Array.isArray(body)) throw shape("installations is not a list");
|
|
139
|
+
return body.map((i) => {
|
|
140
|
+
const key = i?.studioKey;
|
|
141
|
+
if (typeof key !== "string") throw shape("an installation without studioKey");
|
|
142
|
+
return key;
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// src/client.ts
|
|
147
|
+
var STUDIO_KEY = /^[a-z0-9][a-z0-9-]{0,79}$/i;
|
|
148
|
+
var RUN_ID = /^[0-9a-f-]{36}$/i;
|
|
149
|
+
var IDEMPOTENCY_KEY = /^[!-~]{1,255}$/;
|
|
150
|
+
var KEY_REUSED = "idempotency_key_reused";
|
|
151
|
+
var DEFAULT_TIMEOUT_MS = 2e4;
|
|
152
|
+
var DEFAULT_CIRCUIT = { failureThreshold: 5, openSeconds: 30 };
|
|
153
|
+
var DEFAULT_WAIT_INTERVAL_MS = 2e3;
|
|
154
|
+
var DEFAULT_WAIT_TIMEOUT_MS = 12e4;
|
|
155
|
+
var BUSY_MIN_SECONDS = 1;
|
|
156
|
+
var BUSY_MAX_SECONDS = 300;
|
|
157
|
+
var BUSY_DEFAULT_SECONDS = 15;
|
|
158
|
+
var NO_STORE = { cache: "no-store" };
|
|
159
|
+
var sleepFor = (milliseconds) => new Promise((resolve) => setTimeout(resolve, milliseconds));
|
|
160
|
+
function createOrazakaClient(options) {
|
|
161
|
+
const doFetch = options.fetch ?? fetch;
|
|
162
|
+
const base = options.baseUrl.replace(/\/+$/, "");
|
|
163
|
+
const timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;
|
|
164
|
+
const circuit = options.circuit === false ? null : createCircuit(options.circuit ?? DEFAULT_CIRCUIT, options.clock);
|
|
165
|
+
const sleep = options.sleep ?? sleepFor;
|
|
166
|
+
const installed = /* @__PURE__ */ new Set();
|
|
167
|
+
async function refusal(res, method, path) {
|
|
168
|
+
const where = `${method} ${path.split("?")[0]}`;
|
|
169
|
+
const body = await res.json().catch(() => null);
|
|
170
|
+
if (res.status === 429) {
|
|
171
|
+
const asked = Number(res.headers.get("retry-after") ?? body?.retryAfterSeconds);
|
|
172
|
+
const wait = Math.min(BUSY_MAX_SECONDS, Math.max(BUSY_MIN_SECONDS, asked || BUSY_DEFAULT_SECONDS));
|
|
173
|
+
return new OrazakaError(ORAZAKA_CODE.busy, `Orazaka is busy on ${where}`, { upstreamStatus: 429, status: 429, retryAfterSeconds: wait });
|
|
174
|
+
}
|
|
175
|
+
if (res.status === 422 && (body?.status === KEY_REUSED || body?.code === KEY_REUSED)) {
|
|
176
|
+
return new OrazakaError(ORAZAKA_CODE.keyReused, `The idempotency key already started a different request on ${where}`, { upstreamStatus: 422, status: 409 });
|
|
177
|
+
}
|
|
178
|
+
const { status, code } = orazakaRefusal(res.status);
|
|
179
|
+
return new OrazakaError(code, `Orazaka answered ${res.status} on ${where}`, { upstreamStatus: res.status, status });
|
|
180
|
+
}
|
|
181
|
+
async function call(path, init = {}) {
|
|
182
|
+
if (!options.apiKey) throw new OrazakaError(ORAZAKA_CODE.notConfigured, "The Orazaka API key is not set", { status: 503 });
|
|
183
|
+
circuit?.check();
|
|
184
|
+
const method = init.method ?? "GET";
|
|
185
|
+
let res;
|
|
186
|
+
try {
|
|
187
|
+
res = await doFetch(`${base}${path}`, {
|
|
188
|
+
method,
|
|
189
|
+
headers: { authorization: `Bearer ${options.apiKey}`, accept: "application/json", ...init.body === void 0 ? {} : { "content-type": "application/json" }, ...init.headers },
|
|
190
|
+
body: init.body === void 0 ? void 0 : JSON.stringify(init.body),
|
|
191
|
+
signal: AbortSignal.timeout(timeoutMs),
|
|
192
|
+
...NO_STORE
|
|
193
|
+
});
|
|
194
|
+
} catch (cause) {
|
|
195
|
+
circuit?.failure();
|
|
196
|
+
const timedOut = cause instanceof Error && (cause.name === "TimeoutError" || cause.name === "AbortError");
|
|
197
|
+
throw new OrazakaError(timedOut ? ORAZAKA_CODE.timeout : ORAZAKA_CODE.unavailable, timedOut ? "Orazaka did not answer in time" : "Orazaka did not answer", { status: 502 });
|
|
198
|
+
}
|
|
199
|
+
if (res.status >= 500) {
|
|
200
|
+
circuit?.failure();
|
|
201
|
+
throw new OrazakaError(ORAZAKA_CODE.unavailable, `Orazaka answered ${res.status} on ${method} ${path.split("?")[0]}`, { upstreamStatus: res.status, status: 502 });
|
|
202
|
+
}
|
|
203
|
+
circuit?.success();
|
|
204
|
+
if (!res.ok) throw await refusal(res, method, path);
|
|
205
|
+
return res;
|
|
206
|
+
}
|
|
207
|
+
const json = (res) => res.json().catch(() => void 0);
|
|
208
|
+
async function studios() {
|
|
209
|
+
return parseInstallations(await json(await call("/api/v1/studios/installations")));
|
|
210
|
+
}
|
|
211
|
+
async function ensureInstalled(studio) {
|
|
212
|
+
if (installed.has(studio)) return;
|
|
213
|
+
if (!(await studios()).includes(studio)) await call(`/api/v1/studios/${studio}/installations?locale=en`, { method: "POST", body: { config: {} } });
|
|
214
|
+
installed.add(studio);
|
|
215
|
+
}
|
|
216
|
+
const checkRunId = (runId) => {
|
|
217
|
+
if (!RUN_ID.test(runId)) throw new OrazakaError(ORAZAKA_CODE.badRun, "Not a run id", { status: 400 });
|
|
218
|
+
};
|
|
219
|
+
async function getRun(runId) {
|
|
220
|
+
checkRunId(runId);
|
|
221
|
+
return parseRun(await json(await call(`/api/v1/studios/runs/${runId}`)));
|
|
222
|
+
}
|
|
223
|
+
return {
|
|
224
|
+
circuit,
|
|
225
|
+
studios,
|
|
226
|
+
getRun,
|
|
227
|
+
async startRun(studio, inputs, { idempotencyKey } = {}) {
|
|
228
|
+
if (!STUDIO_KEY.test(studio)) throw new OrazakaError(ORAZAKA_CODE.input, "Not a Studio key", { status: 422 });
|
|
229
|
+
if (idempotencyKey !== void 0 && !IDEMPOTENCY_KEY.test(idempotencyKey)) throw new OrazakaError(ORAZAKA_CODE.input, "An idempotency key is 1 to 255 printable characters", { status: 422 });
|
|
230
|
+
if (options.autoInstall !== false) await ensureInstalled(studio);
|
|
231
|
+
const res = await call(`/api/v1/studios/${studio}/runs`, { method: "POST", body: { inputs }, headers: idempotencyKey ? { "idempotency-key": idempotencyKey } : {} });
|
|
232
|
+
return { run: parseRun(await json(res)), replayed: res.headers.get("idempotent-replayed") === "true" };
|
|
233
|
+
},
|
|
234
|
+
async waitForRun(runId, { intervalMs = DEFAULT_WAIT_INTERVAL_MS, timeoutMs: waitMs = DEFAULT_WAIT_TIMEOUT_MS } = {}) {
|
|
235
|
+
const deadline = addMilliseconds(options.clock.now(), waitMs);
|
|
236
|
+
for (; ; ) {
|
|
237
|
+
const run = await getRun(runId);
|
|
238
|
+
if (isTerminal(run)) return run;
|
|
239
|
+
if (isAfter(options.clock.now(), deadline)) throw new OrazakaError(ORAZAKA_CODE.waitExpired, `The run is still ${run.status} after ${waitMs} ms`, { status: 504 });
|
|
240
|
+
await sleep(intervalMs);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
export {
|
|
246
|
+
ORAZAKA_CODE,
|
|
247
|
+
OrazakaError,
|
|
248
|
+
RUN_STATUS,
|
|
249
|
+
createCircuit,
|
|
250
|
+
createOrazakaClient,
|
|
251
|
+
isTerminal,
|
|
252
|
+
orazakaRefusal,
|
|
253
|
+
outputOf,
|
|
254
|
+
parseInstallations,
|
|
255
|
+
parseRun
|
|
256
|
+
};
|
|
257
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/circuit.ts","../src/errors.ts","../src/client.ts","../src/run.ts"],"sourcesContent":["import { addSeconds, differenceInSeconds, isBefore } from \"date-fns\";\n\nimport { ORAZAKA_CODE, OrazakaError } from \"./errors\";\n\nexport interface Clock {\n now(): Date;\n}\n\nexport interface CircuitOptions {\n /** Consecutive failures (no answer, timeout, 5xx) that open the circuit. */\n failureThreshold: number;\n /** How long it stays open before one call is let through to probe. */\n openSeconds: number;\n}\n\n/**\n * A circuit breaker over a dependency that may be down: after `failureThreshold` failures in a row it refuses at once (no waiting on\n * a timeout, no load on a struggling service) for `openSeconds`, then lets ONE call through; its success closes the circuit, its\n * failure opens it again. A refusal of the edge (401, 402, 404…) is an answer, not a failure: only the caller reports failures.\n */\nexport function createCircuit(options: CircuitOptions, clock: Clock) {\n let failures = 0;\n let openUntil: Date | null = null;\n let probing = false;\n return {\n /** Throws `ORAZAKA_CIRCUIT_OPEN` while the circuit is open (or its probe is in flight). */\n check(): void {\n if (openUntil === null) return;\n const now = clock.now();\n if (isBefore(now, openUntil)) throw open(Math.max(1, differenceInSeconds(openUntil, now)));\n if (probing) throw open(1);\n probing = true;\n },\n success(): void {\n failures = 0;\n openUntil = null;\n probing = false;\n },\n failure(): void {\n failures += 1;\n if (probing || failures >= options.failureThreshold) {\n openUntil = addSeconds(clock.now(), options.openSeconds);\n probing = false;\n }\n },\n /** Test and diagnostics: is it refusing now? */\n get isOpen(): boolean {\n return openUntil !== null;\n },\n };\n}\n\nexport type Circuit = ReturnType<typeof createCircuit>;\n\nconst open = (retryAfterSeconds: number) => new OrazakaError(ORAZAKA_CODE.circuitOpen, \"Orazaka failed several times in a row: not calling it for a moment\", { retryAfterSeconds, status: 502 });\n","/** The stable codes of a refusal or a failure of Orazaka's edge — a product translates them; none is a sentence. */\nexport const ORAZAKA_CODE = {\n /** No API key was given. */\n notConfigured: \"ORAZAKA_NOT_CONFIGURED\",\n /** 401/403: the key is wrong, revoked or lacks the right. */\n key: \"ORAZAKA_KEY\",\n /** 402: the run is not affordable now. */\n credits: \"ORAZAKA_CREDITS\",\n /** 409: the Studio is locked (to buy, or already installed). */\n locked: \"ORAZAKA_LOCKED\",\n /** 400/422: the inputs are not what the Studio asks for. */\n input: \"ORAZAKA_INPUT\",\n /** 404: no such Studio or run (or not the caller's). */\n notFound: \"ORAZAKA_NOT_FOUND\",\n /** 429: too many runs at once; `retryAfterSeconds` says when to come back. Not a failure of the document. */\n busy: \"ORAZAKA_BUSY\",\n /** 422 `idempotency_key_reused`: the key already started a different request. */\n keyReused: \"ORAZAKA_KEY_REUSED\",\n /** 451: a consent is to be agreed to first. */\n consent: \"ORAZAKA_CONSENT\",\n /** The edge did not answer, or answered 5xx. */\n unavailable: \"ORAZAKA_UNAVAILABLE\",\n /** The edge did not answer within the time given. */\n timeout: \"ORAZAKA_TIMEOUT\",\n /** The edge answered something that is not a run (or a list of installations). */\n shape: \"ORAZAKA_SHAPE\",\n /** Too many failures in a row: the client does not call until the pause is over. */\n circuitOpen: \"ORAZAKA_CIRCUIT_OPEN\",\n /** A run id that is not one: refused before any call. */\n badRun: \"ORAZAKA_BAD_RUN\",\n /** `waitForRun` gave up: the run was still going. */\n waitExpired: \"ORAZAKA_WAIT_EXPIRED\",\n} as const;\nexport type OrazakaCode = (typeof ORAZAKA_CODE)[keyof typeof ORAZAKA_CODE];\n\n/** What the edge's status means for a product that answers its own caller: the status to send back and the code. */\nexport function orazakaRefusal(status: number): { status: number; code: OrazakaCode } {\n if (status === 401 || status === 403) return { status: 502, code: ORAZAKA_CODE.key };\n if (status === 402) return { status: 502, code: ORAZAKA_CODE.credits };\n if (status === 409) return { status: 502, code: ORAZAKA_CODE.locked };\n if (status === 400 || status === 422) return { status: 422, code: ORAZAKA_CODE.input };\n if (status === 404) return { status: 502, code: ORAZAKA_CODE.notFound };\n if (status === 429) return { status: 429, code: ORAZAKA_CODE.busy };\n if (status === 451) return { status: 502, code: ORAZAKA_CODE.consent };\n return { status: 502, code: ORAZAKA_CODE.unavailable };\n}\n\nexport class OrazakaError extends Error {\n constructor(\n readonly code: OrazakaCode,\n message: string,\n readonly details: {\n /** What the edge answered, when it answered. */\n upstreamStatus?: number;\n /** The status a product should answer its own caller with. */\n status?: number;\n /** For `ORAZAKA_BUSY` and `ORAZAKA_CIRCUIT_OPEN`: seconds to wait. */\n retryAfterSeconds?: number;\n } = {},\n ) {\n super(message);\n this.name = \"OrazakaError\";\n }\n\n /** The HTTP status a product answers its own caller with (502 for a failure upstream, 429 when busy). */\n get status(): number {\n return this.details.status ?? 502;\n }\n\n get retryAfterSeconds(): number | undefined {\n return this.details.retryAfterSeconds;\n }\n}\n","import { addMilliseconds, isAfter } from \"date-fns\";\n\nimport { type Circuit, type CircuitOptions, type Clock, createCircuit } from \"./circuit\";\nimport { ORAZAKA_CODE, OrazakaError, orazakaRefusal } from \"./errors\";\nimport { isTerminal, type OrazakaRun, parseInstallations, parseRun } from \"./run\";\n\ntype Fetch = typeof fetch;\n\nexport interface OrazakaClientOptions {\n /** `https://api.orazaka.com` — the edge. A parameter: this package reads no environment. */\n baseUrl: string;\n /** The product's service key (`oz_…`). Without one every call throws `ORAZAKA_NOT_CONFIGURED`. */\n apiKey: string | undefined;\n /** Time is injected: the circuit and `waitForRun` read it from here. */\n clock: Clock;\n fetch?: Fetch;\n /** One call's time limit, in milliseconds (default 20 000). */\n timeoutMs?: number;\n /** The breaker: `false` for none; default 5 failures in a row open it for 30 seconds. */\n circuit?: CircuitOptions | false;\n /** Install the Studio on the account before its first run (default true: the edge asks for it). */\n autoInstall?: boolean;\n /** How `waitForRun` waits between two reads (default `setTimeout`); tests give their own. */\n sleep?: (milliseconds: number) => Promise<void>;\n}\n\nexport interface StartRunOptions {\n /** Retrying with the same key (and the same inputs) answers the run already started instead of paying for a second one. */\n idempotencyKey?: string;\n}\n\nexport interface StartedRun {\n run: OrazakaRun;\n /** The edge answered a run it had already started for this key (`Idempotent-Replayed`). */\n replayed: boolean;\n}\n\nexport interface WaitOptions {\n /** Between two reads, in milliseconds (default 2 000). */\n intervalMs?: number;\n /** Give up after this long, in milliseconds (default 120 000): `ORAZAKA_WAIT_EXPIRED`. */\n timeoutMs?: number;\n}\n\nexport interface OrazakaClient {\n /** Starts a Studio run (`POST /api/v1/studios/{studio}/runs`, 202). Pass an idempotency key to make the retry safe. */\n startRun(studio: string, inputs: Record<string, unknown>, options?: StartRunOptions): Promise<StartedRun>;\n /** The run, its status and its outputs (`GET /api/v1/studios/runs/{id}`). */\n getRun(runId: string): Promise<OrazakaRun>;\n /** Reads the run until it is over (succeeded, failed or cancelled) and answers it; a failed run is returned, not thrown. */\n waitForRun(runId: string, options?: WaitOptions): Promise<OrazakaRun>;\n /** The Studios this key has installed — also the cheapest call that proves the key and the connection. */\n studios(): Promise<string[]>;\n /** The circuit breaker, for diagnostics. */\n readonly circuit: Circuit | null;\n}\n\nconst STUDIO_KEY = /^[a-z0-9][a-z0-9-]{0,79}$/i;\nconst RUN_ID = /^[0-9a-f-]{36}$/i;\nconst IDEMPOTENCY_KEY = /^[!-~]{1,255}$/;\n/** The stable code the edge answers (HTTP 422) when an idempotency key already started a different request. */\nconst KEY_REUSED = \"idempotency_key_reused\";\nconst DEFAULT_TIMEOUT_MS = 20_000;\nconst DEFAULT_CIRCUIT: CircuitOptions = { failureThreshold: 5, openSeconds: 30 };\nconst DEFAULT_WAIT_INTERVAL_MS = 2000;\nconst DEFAULT_WAIT_TIMEOUT_MS = 120_000;\nconst BUSY_MIN_SECONDS = 1;\nconst BUSY_MAX_SECONDS = 300;\nconst BUSY_DEFAULT_SECONDS = 15;\n\n/** Never served from a framework's fetch cache: a run's status changes. (`cache` is a runtime option the Node typings do not list.) */\nconst NO_STORE = { cache: \"no-store\" } as RequestInit;\n\nconst sleepFor = (milliseconds: number) => new Promise<void>((resolve) => setTimeout(resolve, milliseconds));\n\ninterface Call {\n method?: \"GET\" | \"POST\";\n body?: unknown;\n headers?: Record<string, string>;\n}\n\n/** Orazaka's edge, for every TypeScript product: one client instead of one copy per product. */\nexport function createOrazakaClient(options: OrazakaClientOptions): OrazakaClient {\n const doFetch = options.fetch ?? fetch;\n const base = options.baseUrl.replace(/\\/+$/, \"\");\n const timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;\n const circuit = options.circuit === false ? null : createCircuit(options.circuit ?? DEFAULT_CIRCUIT, options.clock);\n const sleep = options.sleep ?? sleepFor;\n const installed = new Set<string>();\n\n /** The edge answered with a refusal: a stable error. A refusal is an answer, so the circuit stays closed. */\n async function refusal(res: Response, method: string, path: string): Promise<OrazakaError> {\n const where = `${method} ${path.split(\"?\")[0]}`;\n const body = (await res.json().catch(() => null)) as { status?: unknown; code?: unknown; retryAfterSeconds?: unknown } | null;\n if (res.status === 429) {\n const asked = Number(res.headers.get(\"retry-after\") ?? body?.retryAfterSeconds);\n const wait = Math.min(BUSY_MAX_SECONDS, Math.max(BUSY_MIN_SECONDS, asked || BUSY_DEFAULT_SECONDS));\n return new OrazakaError(ORAZAKA_CODE.busy, `Orazaka is busy on ${where}`, { upstreamStatus: 429, status: 429, retryAfterSeconds: wait });\n }\n if (res.status === 422 && (body?.status === KEY_REUSED || body?.code === KEY_REUSED)) {\n return new OrazakaError(ORAZAKA_CODE.keyReused, `The idempotency key already started a different request on ${where}`, { upstreamStatus: 422, status: 409 });\n }\n const { status, code } = orazakaRefusal(res.status);\n return new OrazakaError(code, `Orazaka answered ${res.status} on ${where}`, { upstreamStatus: res.status, status });\n }\n\n async function call(path: string, init: Call = {}): Promise<Response> {\n if (!options.apiKey) throw new OrazakaError(ORAZAKA_CODE.notConfigured, \"The Orazaka API key is not set\", { status: 503 });\n circuit?.check();\n const method = init.method ?? \"GET\";\n let res: Response;\n try {\n res = await doFetch(`${base}${path}`, {\n method,\n headers: { authorization: `Bearer ${options.apiKey}`, accept: \"application/json\", ...(init.body === undefined ? {} : { \"content-type\": \"application/json\" }), ...init.headers },\n body: init.body === undefined ? undefined : JSON.stringify(init.body),\n signal: AbortSignal.timeout(timeoutMs),\n ...NO_STORE,\n });\n } catch (cause) {\n circuit?.failure();\n const timedOut = cause instanceof Error && (cause.name === \"TimeoutError\" || cause.name === \"AbortError\");\n throw new OrazakaError(timedOut ? ORAZAKA_CODE.timeout : ORAZAKA_CODE.unavailable, timedOut ? \"Orazaka did not answer in time\" : \"Orazaka did not answer\", { status: 502 });\n }\n if (res.status >= 500) {\n circuit?.failure();\n throw new OrazakaError(ORAZAKA_CODE.unavailable, `Orazaka answered ${res.status} on ${method} ${path.split(\"?\")[0]}`, { upstreamStatus: res.status, status: 502 });\n }\n circuit?.success();\n if (!res.ok) throw await refusal(res, method, path);\n return res;\n }\n\n const json = (res: Response): Promise<unknown> => res.json().catch(() => undefined);\n\n async function studios(): Promise<string[]> {\n return parseInstallations(await json(await call(\"/api/v1/studios/installations\")));\n }\n\n async function ensureInstalled(studio: string): Promise<void> {\n if (installed.has(studio)) return;\n if (!(await studios()).includes(studio)) await call(`/api/v1/studios/${studio}/installations?locale=en`, { method: \"POST\", body: { config: {} } });\n installed.add(studio);\n }\n\n const checkRunId = (runId: string) => {\n if (!RUN_ID.test(runId)) throw new OrazakaError(ORAZAKA_CODE.badRun, \"Not a run id\", { status: 400 });\n };\n\n async function getRun(runId: string): Promise<OrazakaRun> {\n checkRunId(runId);\n return parseRun(await json(await call(`/api/v1/studios/runs/${runId}`)));\n }\n\n return {\n circuit,\n studios,\n getRun,\n async startRun(studio, inputs, { idempotencyKey } = {}) {\n if (!STUDIO_KEY.test(studio)) throw new OrazakaError(ORAZAKA_CODE.input, \"Not a Studio key\", { status: 422 });\n if (idempotencyKey !== undefined && !IDEMPOTENCY_KEY.test(idempotencyKey)) throw new OrazakaError(ORAZAKA_CODE.input, \"An idempotency key is 1 to 255 printable characters\", { status: 422 });\n if (options.autoInstall !== false) await ensureInstalled(studio);\n const res = await call(`/api/v1/studios/${studio}/runs`, { method: \"POST\", body: { inputs }, headers: idempotencyKey ? { \"idempotency-key\": idempotencyKey } : {} });\n return { run: parseRun(await json(res)), replayed: res.headers.get(\"idempotent-replayed\") === \"true\" };\n },\n async waitForRun(runId, { intervalMs = DEFAULT_WAIT_INTERVAL_MS, timeoutMs: waitMs = DEFAULT_WAIT_TIMEOUT_MS } = {}) {\n const deadline = addMilliseconds(options.clock.now(), waitMs);\n for (;;) {\n const run = await getRun(runId);\n if (isTerminal(run)) return run;\n if (isAfter(options.clock.now(), deadline)) throw new OrazakaError(ORAZAKA_CODE.waitExpired, `The run is still ${run.status} after ${waitMs} ms`, { status: 504 });\n await sleep(intervalMs);\n }\n },\n };\n}\n","import { ORAZAKA_CODE, OrazakaError } from \"./errors\";\n\n/** One output of a run (orazaka-studio `RunArtefactResponse`): `type` is a rendering hint (`TEXT`, `IMAGE`, `VIDEO`…). */\nexport interface RunOutput {\n key: string;\n label: string | null;\n type: string;\n value: string | null;\n}\n\n/** Where a run sits (orazaka-studio `RunStatus`). The client keeps the string the edge sent, so a new status is not a failure. */\nexport const RUN_STATUS = {\n pendingApproval: \"PENDING_APPROVAL\",\n running: \"RUNNING\",\n awaitingInput: \"AWAITING_INPUT\",\n succeeded: \"SUCCEEDED\",\n failed: \"FAILED\",\n cancelled: \"CANCELLED\",\n compensating: \"COMPENSATING\",\n} as const;\n\nconst TERMINAL: readonly string[] = [RUN_STATUS.succeeded, RUN_STATUS.failed, RUN_STATUS.cancelled];\n\n/** A run, as the edge answers it (`GET /api/v1/studios/runs/{id}`). Only what a product reads. */\nexport interface OrazakaRun {\n id: string;\n studioKey: string;\n blueprintVersion: string | null;\n status: string;\n outputs: RunOutput[];\n errorMessage: string | null;\n startedAt: string | null;\n finishedAt: string | null;\n}\n\n/** The run is over, green or not: nothing more will change. */\nexport const isTerminal = (run: Pick<OrazakaRun, \"status\">): boolean => TERMINAL.includes(run.status);\n\n/** The value of one output, or null when the run did not produce it (yet). */\nexport const outputOf = (run: Pick<OrazakaRun, \"outputs\">, key: string): string | null => run.outputs.find((o) => o.key === key)?.value ?? null;\n\nconst shape = (what: string) => new OrazakaError(ORAZAKA_CODE.shape, `Orazaka's answer has an unexpected shape: ${what}`);\nconst text = (v: unknown): string | null => (typeof v === \"string\" ? v : null);\n\nconst parseOutput = (raw: unknown): RunOutput => {\n const o = (raw ?? {}) as Record<string, unknown>;\n if (typeof o.key !== \"string\" || typeof o.type !== \"string\") throw shape(\"an output without key and type\");\n return { key: o.key, label: text(o.label), type: o.type, value: text(o.value) };\n};\n\n/** Reads a run from the edge's JSON; anything else is `ORAZAKA_SHAPE`. */\nexport function parseRun(body: unknown): OrazakaRun {\n const o = (body ?? {}) as Record<string, unknown>;\n if (typeof o.id !== \"string\" || typeof o.studioKey !== \"string\" || typeof o.status !== \"string\") throw shape(\"a run needs id, studioKey and status\");\n if (o.outputs !== undefined && o.outputs !== null && !Array.isArray(o.outputs)) throw shape(\"outputs is not a list\");\n return {\n id: o.id,\n studioKey: o.studioKey,\n blueprintVersion: text(o.blueprintVersion),\n status: o.status,\n outputs: ((o.outputs as unknown[] | null | undefined) ?? []).map(parseOutput),\n errorMessage: text(o.errorMessage),\n startedAt: text(o.startedAt),\n finishedAt: text(o.finishedAt),\n };\n}\n\n/** The Studios an account installed: `GET /api/v1/studios/installations`. */\nexport function parseInstallations(body: unknown): string[] {\n if (!Array.isArray(body)) throw shape(\"installations is not a list\");\n return body.map((i) => {\n const key = (i as Record<string, unknown> | null)?.studioKey;\n if (typeof key !== \"string\") throw shape(\"an installation without studioKey\");\n return key;\n });\n}\n"],"mappings":";AAAA,SAAS,YAAY,qBAAqB,gBAAgB;;;ACCnD,IAAM,eAAe;AAAA;AAAA,EAE1B,eAAe;AAAA;AAAA,EAEf,KAAK;AAAA;AAAA,EAEL,SAAS;AAAA;AAAA,EAET,QAAQ;AAAA;AAAA,EAER,OAAO;AAAA;AAAA,EAEP,UAAU;AAAA;AAAA,EAEV,MAAM;AAAA;AAAA,EAEN,WAAW;AAAA;AAAA,EAEX,SAAS;AAAA;AAAA,EAET,aAAa;AAAA;AAAA,EAEb,SAAS;AAAA;AAAA,EAET,OAA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wB,IAAI,CAAC,GAAG;AACnH,YAAM,WAAW,gBAAgB,QAAQ,MAAM,IAAI,GAAG,MAAM;AAC5D,iBAAS;AACP,cAAM,MAAM,MAAM,OAAO,KAAK;AAC9B,YAAI,WAAW,GAAG,EAAG,QAAO;AAC5B,YAAI,QAAQ,QAAQ,MAAM,IAAI,GAAG,QAAQ,EAAG,OAAM,IAAI,aAAa,aAAa,aAAa,oBAAoB,IAAI,MAAM,UAAU,MAAM,OAAO,EAAE,QAAQ,IAAI,CAAC;AACjK,cAAM,MAAM,UAAU;AAAA,MACxB;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,59 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@krizaka/orazaka-client",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "One Orazaka client for the TypeScript products: start a Studio run (safe to retry with an idempotency key), read its status and outputs, wait for it, with typed errors with stable codes, a time limit and a circuit breaker. Base URL, key and clock are parameters; no environment, no framework.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"krizaka",
|
|
7
|
+
"orazaka",
|
|
8
|
+
"client",
|
|
9
|
+
"studio",
|
|
10
|
+
"runs"
|
|
11
|
+
],
|
|
12
|
+
"homepage": "https://github.com/krizaka/krizaka-ts/tree/main/packages/orazaka-client",
|
|
13
|
+
"bugs": "https://github.com/krizaka/krizaka-ts/issues",
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "git+https://github.com/krizaka/krizaka-ts.git",
|
|
17
|
+
"directory": "packages/orazaka-client"
|
|
18
|
+
},
|
|
19
|
+
"license": "Apache-2.0",
|
|
20
|
+
"author": "Krizaka (https://www.krizaka.com)",
|
|
21
|
+
"type": "module",
|
|
22
|
+
"main": "./dist/index.js",
|
|
23
|
+
"module": "./dist/index.js",
|
|
24
|
+
"types": "./dist/index.d.ts",
|
|
25
|
+
"exports": {
|
|
26
|
+
".": {
|
|
27
|
+
"types": "./dist/index.d.ts",
|
|
28
|
+
"import": "./dist/index.js"
|
|
29
|
+
},
|
|
30
|
+
"./package.json": "./package.json"
|
|
31
|
+
},
|
|
32
|
+
"files": [
|
|
33
|
+
"dist",
|
|
34
|
+
"README.md",
|
|
35
|
+
"LICENSE"
|
|
36
|
+
],
|
|
37
|
+
"sideEffects": false,
|
|
38
|
+
"engines": {
|
|
39
|
+
"node": ">=22"
|
|
40
|
+
},
|
|
41
|
+
"dependencies": {
|
|
42
|
+
"date-fns": "^4.4.0"
|
|
43
|
+
},
|
|
44
|
+
"devDependencies": {
|
|
45
|
+
"@types/node": "^22.10.0",
|
|
46
|
+
"eslint": "^9.39.0",
|
|
47
|
+
"tsup": "^8.5.0",
|
|
48
|
+
"typescript": "^5.9.3",
|
|
49
|
+
"vitest": "^4.1.11",
|
|
50
|
+
"@krizaka/config": "^0.8.0"
|
|
51
|
+
},
|
|
52
|
+
"scripts": {
|
|
53
|
+
"build": "node -e \"require('node:fs').rmSync('dist',{recursive:true,force:true})\" && tsup",
|
|
54
|
+
"lint": "eslint . --max-warnings 0 && tsc --noEmit",
|
|
55
|
+
"typecheck": "tsc --noEmit",
|
|
56
|
+
"test": "vitest run",
|
|
57
|
+
"check": "pnpm run lint && pnpm run test && pnpm run build"
|
|
58
|
+
}
|
|
6
59
|
}
|