@originatedev/run-sdk 0.0.0-stage → 0.1.1

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/README.md CHANGED
@@ -1,3 +1,216 @@
1
- # Temporary Holding Version
1
+ # @originatedev/run-sdk
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ The backend SDK for Run, Originate's managed service. It reports what Originate needs to operate your application (request metrics, AI call telemetry, health, deploys, metered external calls, audit events) and reads the policies and consent decisions you configured in the Originate dashboard.
4
+
5
+ It never sends prompts, completions, request bodies, headers or user content. See "What is sent" below.
6
+
7
+ Node 18 or newer. No runtime dependencies. ESM.
8
+
9
+ ## Install
10
+
11
+ ```bash
12
+ npm install @originatedev/run-sdk
13
+ ```
14
+
15
+ ## Init
16
+
17
+ ```ts
18
+ import { init } from '@originatedev/run-sdk';
19
+
20
+ const run = init({
21
+ key: process.env.ORIGINATE_RUN_KEY!, // the application's public key (opk_...)
22
+ release: process.env.GIT_SHA, // or ORIGINATE_RUN_RELEASE
23
+ service: 'api', // optional, when you run several processes
24
+ onError: (e) => logger.warn(e), // delivery problems; the SDK itself never throws
25
+ });
26
+
27
+ process.on('SIGTERM', () => run.shutdown());
28
+ ```
29
+
30
+ Options: `apiBase` (defaults to `https://api.platform.originatetech.com`, or `ORIGINATE_API_BASE`), `flushIntervalMs` (5000), `heartbeatIntervalMs` (60000, `0` disables heartbeats), `disabled` (every call becomes a no-op), `requestTimeoutMs` (10000).
31
+
32
+ `init()` returns the client and also makes it the module-level singleton, so the same functions can be imported anywhere:
33
+
34
+ ```ts
35
+ import { track, meter, ai, health, deploy, audit, policy, consent } from '@originatedev/run-sdk';
36
+ ```
37
+
38
+ Before `init()` ran the singleton is a disabled client: calls are no-ops and nothing throws.
39
+
40
+ Timers are unref'd, so the SDK never keeps your process alive. Queues are bounded (oldest dropped on a long outage) and every delivery is retried three times with backoff; 4xx answers are not retried.
41
+
42
+ ## Request metrics
43
+
44
+ Every response is counted per minute and per route (`METHOD route`), with 5xx errors and p50, p95 and p99 latency. Finished minutes go to the api on the next flush. Only the route template and timings are sent: no URLs with ids, no query strings, no headers.
45
+
46
+ ### Express
47
+
48
+ ```ts
49
+ import express from 'express';
50
+ import { middleware } from '@originatedev/run-sdk/express';
51
+
52
+ const app = express();
53
+ app.use(middleware({ ignore: ['/health'] }));
54
+ ```
55
+
56
+ The route is Express's matched template (`/users/:id`) when the router exposes one, otherwise the path with UUIDs, numbers and long hex ids replaced by `:id`.
57
+
58
+ ### Fastify
59
+
60
+ ```ts
61
+ import Fastify from 'fastify';
62
+ import { plugin as originateRun } from '@originatedev/run-sdk/fastify';
63
+
64
+ const app = Fastify();
65
+ await app.register(originateRun, { ignore: ['/health'] });
66
+ ```
67
+
68
+ Uses `request.routeOptions.url` and `reply.elapsedTime`. The plugin carries the skip-override marker, so it applies to the whole server without `fastify-plugin`.
69
+
70
+ ### Anything else
71
+
72
+ ```ts
73
+ run.metrics.record('GET', '/users/:id', 200, durationMs, true); // true: already a template
74
+ ```
75
+
76
+ ## AI calls
77
+
78
+ ### OpenAI
79
+
80
+ ```ts
81
+ import OpenAI from 'openai';
82
+ import { ai } from '@originatedev/run-sdk';
83
+
84
+ const openai = ai.wrapOpenAI(new OpenAI(), { feature: 'support_chat' });
85
+ ```
86
+
87
+ `chat.completions.create`, `responses.create` and `embeddings.create` are patched in place. Each call records duration, the model from the response, input, cached and output tokens from `usage`, the finish reason, and the error type (HTTP status or error class) when the call throws. Streams are observed through their async iterator: time to first token is measured at the first chunk and the row is recorded when the stream completes. For OpenAI chat streams pass `stream_options: { include_usage: true }` so the final chunk carries token counts.
88
+
89
+ Return values are untouched: the same promise, the same stream object. The wrapper reads `usage`, `model`, `choices[].finish_reason` and `status`; it never reads messages, input or output.
90
+
91
+ ### Anthropic
92
+
93
+ ```ts
94
+ import Anthropic from '@anthropic-ai/sdk';
95
+
96
+ const anthropic = ai.wrapAnthropic(new Anthropic(), { feature: 'summaries' });
97
+ ```
98
+
99
+ Patches `messages.create`, including `stream: true` (usage from `message_start` and `message_delta`, stop reason from the delta). `messages.stream()` (the helper that returns a `MessageStream`) is not patched; record those calls with `ai.record` from its `finalMessage()`.
100
+
101
+ ### Direct
102
+
103
+ ```ts
104
+ ai.record({
105
+ provider: 'google',
106
+ model: 'gemini-2.5-flash',
107
+ operation: 'generate_content',
108
+ inputTokens: 1200,
109
+ cachedTokens: 0,
110
+ outputTokens: 310,
111
+ durationMs: 840,
112
+ finishReason: 'STOP',
113
+ feature: 'lead_summary',
114
+ accountId: 'acct_123', // your own id, never an email
115
+ });
116
+ ```
117
+
118
+ Fields match the Run AI call row: `operation`, `provider`, `model`, `inputTokens`, `cachedTokens`, `outputTokens`, `durationMs`, `ttftMs`, `finishReason`, `errorType`, `costUsd`, `feature`, `accountId`, `source`, `guardrailMode`, `guardrailDecision`, `guardrailCategories`, `batch`, `schemaVersion`.
119
+
120
+ ### OpenTelemetry bridge
121
+
122
+ If your application already emits GenAI semantic-convention spans (through the OpenAI, Anthropic, Vercel AI or LangChain instrumentations), add the span processor and no further code changes are needed:
123
+
124
+ ```ts
125
+ import { NodeTracerProvider } from '@opentelemetry/sdk-trace-node';
126
+ import { otelSpanProcessor } from '@originatedev/run-sdk/otel';
127
+
128
+ const provider = new NodeTracerProvider({ spanProcessors: [otelSpanProcessor()] });
129
+ ```
130
+
131
+ On span end it reads `gen_ai.operation.name`, `gen_ai.provider.name` (or `gen_ai.system`), `gen_ai.request.model`, `gen_ai.response.model`, `gen_ai.usage.input_tokens`, `gen_ai.usage.output_tokens`, `gen_ai.usage.cache_read.input_tokens`, `gen_ai.response.finish_reasons` and `error.type`, and records the call with `schemaVersion: '1.37-dev'`. Span events, where some instrumentations put prompts, are never read. The processor is typed structurally, so the OTel packages are optional peers.
132
+
133
+ ## Events, metering and audit
134
+
135
+ ```ts
136
+ track('order_placed', { total_cents: 4200, channel: 'web' }, { accountId: 'acct_123', sessionId: 'sess_9' });
137
+
138
+ meter('twilio_sms', 1, 'message', { costUsd: 0.0079 }); // an external_call event
139
+ meter('deepgram', 2.5, 'minute', { costUsd: 0.0108, props: { tier: 'nova' } });
140
+
141
+ audit.log('export_requested', 'account:acct_123', { by: 'admin:42' }); // an audit_event
142
+ ```
143
+
144
+ Event names are lower snake case (`^[a-z][a-z0-9_]{1,63}$`). Properties are dimensions, not content: strings, numbers, booleans and null; anything else is JSON-serialized and truncated. Never put emails, names or message text in properties.
145
+
146
+ ## Health
147
+
148
+ ```ts
149
+ health.register('postgres', async () => { await db.query('select 1'); return true; });
150
+ health.register('redis', () => redis.status === 'ready', { critical: false });
151
+
152
+ app.get('/health', async (req, res) => {
153
+ const { statusCode, body } = await health.handler();
154
+ res.status(statusCode).json(body);
155
+ });
156
+ ```
157
+
158
+ A check returns `true`, `false`, a status (`'ok' | 'degraded' | 'down'`) or `{ status, detail }`; a throw or a timeout (3 s by default) counts as down. A critical check (the default) that is down takes the service down (HTTP 503); a non-critical one degrades it. The body is `{ status, checks, release, service, uptimeSeconds }`.
159
+
160
+ The same results ride on every heartbeat, which is sent on init and then every `heartbeatIntervalMs` as `{ version, release, service, health }`, so Originate sees your dependencies without probing them.
161
+
162
+ ## Deploy reports
163
+
164
+ From code:
165
+
166
+ ```ts
167
+ await deploy.report({ version: '1.4.0', commit: process.env.GIT_SHA, summary: 'Checkout fixes', prUrl, deployer: 'github-actions', outcome: 'success' });
168
+ ```
169
+
170
+ From CI, without touching the application:
171
+
172
+ ```yaml
173
+ - run: npx @originatedev/run-sdk deploy --version ${{ github.ref_name }} --commit ${{ github.sha }} --summary "${{ github.event.head_commit.message }}" --pr-url "$PR_URL" --deployer github-actions --outcome success
174
+ env:
175
+ ORIGINATE_RUN_KEY: ${{ secrets.ORIGINATE_RUN_KEY }}
176
+ # ORIGINATE_API_BASE: https://api.platform.originatetech.com
177
+ ```
178
+
179
+ Each report becomes a change record and, when a version is given, a release in your Run pages.
180
+
181
+ ## Policies and consent
182
+
183
+ ```ts
184
+ const decision = await policy.check({ dataClasses: ['pii'], purpose: 'marketing', region: 'eu', feature: 'newsletter' });
185
+ // { allowed, effect: 'allow' | 'deny' | 'mask' | null, policyKey, reason }
186
+
187
+ const ok = await consent.allows('analytics', account.id);
188
+ // { allowed, reason: 'implicit' | 'granted' | 'withdrawn' | 'unknown' | 'no_policy' | 'unavailable' }
189
+ ```
190
+
191
+ Policies are the ones you manage in the dashboard. A policy matches when every dimension its rule lists intersects the input; deny wins over mask, mask over allow; no matching policy allows. The subject id passed to `consent.allows` is SHA-256 hashed before it leaves the process. Results are cached for five minutes; `policy.refresh()` clears the cache.
192
+
193
+ Both read `GET {apiBase}/api/v1/run/sdk/policies?key=opk_...` (with `&subject=<sha256>` for consent). This endpoint is still to be added to the api; until it exists the api answers 404 and the SDK returns `{ allowed: true, reason: 'no_policy' }`, so it is safe to ship the calls now. Expected response: `{ policies: [{ key, effect, enabled, rule: { dataClasses?, regions?, purposes?, features?, providers?, models?, actions? } }], consentMode, consent?: { purposes, state } }`. A network failure returns `reason: 'unavailable'`: allowed for `policy.check` (fail open on your own rules), not allowed for `consent.allows` (fail closed on a person's choice).
194
+
195
+ ## What is sent, and what is not
196
+
197
+ Sent:
198
+
199
+ - Request metrics: route template, method, count, 5xx count, latency percentiles, per minute.
200
+ - AI calls: provider, model, operation, token counts, duration, time to first token, finish reason, error type, feature, your account id when you pass one.
201
+ - Events: the name, timestamp, your account and session ids when you pass them, and the properties you give.
202
+ - Heartbeats: SDK version, release, service name, health status per check.
203
+ - Deploy reports: what you put in them.
204
+
205
+ Never sent: prompts, completions, embeddings input, messages, request or response bodies, headers, cookies, IP addresses, emails, full URLs with ids. The wrappers read usage and metadata fields only, and the metrics middleware strips query strings and ids.
206
+
207
+ ## No-gateway mode
208
+
209
+ Customers who decline an AI gateway (deployment with `gatewayMode: 'none'`) have this SDK as the visibility path: the wrappers or the OpenTelemetry bridge report usage, cost and model inventory, and spend caps are advisory (Originate alerts, it cannot block). When the application runs behind the Originate gateway the gateway reports the same rows itself and the wrappers are not needed, though they do no harm: rows are stamped with `source: 'sdk'` and `source: 'gateway'` respectively.
210
+
211
+ ## Development
212
+
213
+ ```bash
214
+ npm run build --workspace=@originatedev/run-sdk
215
+ npm run test --workspace=@originatedev/run-sdk
216
+ ```
package/dist/ai.d.ts ADDED
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Provider client wrappers. They patch the create methods in place to time
3
+ * the call and read token usage, model and finish reason from the response
4
+ * or from the stream. Return values are passed through untouched: the same
5
+ * promise, the same stream object (its async iterator is observed, not
6
+ * replaced by a different object). Prompts and completions are never read.
7
+ */
8
+ import type { AiCall, AiWrapOptions } from './types.js';
9
+ export type RecordFn = (call: AiCall) => void;
10
+ export type ErrorFn = (error: unknown) => void;
11
+ export declare function wrapOpenAI<T extends object>(client: T, record: RecordFn, onError: ErrorFn, options?: AiWrapOptions): T;
12
+ export declare function wrapAnthropic<T extends object>(client: T, record: RecordFn, onError: ErrorFn, options?: AiWrapOptions): T;
13
+ export declare function errorTypeOf(error: unknown): string;
14
+ //# sourceMappingURL=ai.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ai.d.ts","sourceRoot":"","sources":["../src/ai.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAe,aAAa,EAAE,MAAM,YAAY,CAAC;AAErE,MAAM,MAAM,QAAQ,GAAG,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;AAC9C,MAAM,MAAM,OAAO,GAAG,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAAC;AAwB/C,wBAAgB,UAAU,CAAC,CAAC,SAAS,MAAM,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,GAAE,aAAkB,GAAG,CAAC,CAQ1H;AAED,wBAAgB,aAAa,CAAC,CAAC,SAAS,MAAM,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,GAAE,aAAkB,GAAG,CAAC,CAG7H;AAsPD,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAQlD"}
package/dist/ai.js ADDED
@@ -0,0 +1,303 @@
1
+ /**
2
+ * Provider client wrappers. They patch the create methods in place to time
3
+ * the call and read token usage, model and finish reason from the response
4
+ * or from the stream. Return values are passed through untouched: the same
5
+ * promise, the same stream object (its async iterator is observed, not
6
+ * replaced by a different object). Prompts and completions are never read.
7
+ */
8
+ const WRAPPED = Symbol.for('originate.run.wrapped');
9
+ export function wrapOpenAI(client, record, onError, options = {}) {
10
+ const specs = [
11
+ { path: ['chat', 'completions', 'create'], operation: 'chat', absorb: absorbOpenAIChat },
12
+ { path: ['responses', 'create'], operation: 'chat', absorb: absorbOpenAIResponses },
13
+ { path: ['embeddings', 'create'], operation: 'embeddings', absorb: absorbOpenAIEmbeddings },
14
+ ];
15
+ for (const spec of specs)
16
+ patchMethod(client, spec, 'openai', record, onError, options);
17
+ return client;
18
+ }
19
+ export function wrapAnthropic(client, record, onError, options = {}) {
20
+ patchMethod(client, { path: ['messages', 'create'], operation: 'chat', absorb: absorbAnthropicMessage }, 'anthropic', record, onError, options);
21
+ return client;
22
+ }
23
+ function patchMethod(client, spec, provider, record, onError, options) {
24
+ const methodName = spec.path[spec.path.length - 1];
25
+ if (!methodName)
26
+ return;
27
+ let target = client;
28
+ for (const segment of spec.path.slice(0, -1)) {
29
+ if (!isObject(target))
30
+ return;
31
+ target = target[segment];
32
+ }
33
+ if (!isObject(target))
34
+ return;
35
+ const original = target[methodName];
36
+ if (typeof original !== 'function')
37
+ return;
38
+ if (original[WRAPPED])
39
+ return;
40
+ const wrapped = function (...args) {
41
+ const started = performance.now();
42
+ const params = isObject(args[0]) ? args[0] : {};
43
+ const requestModel = typeof params.model === 'string' ? params.model : 'unknown';
44
+ const streaming = params.stream === true;
45
+ const base = {
46
+ operation: spec.operation,
47
+ provider,
48
+ requestModel,
49
+ started,
50
+ feature: options.feature ?? null,
51
+ accountId: options.accountId ?? null,
52
+ record,
53
+ onError,
54
+ absorb: spec.absorb,
55
+ };
56
+ let result;
57
+ try {
58
+ result = original.apply(this, args);
59
+ }
60
+ catch (error) {
61
+ safeRecord(base, { finishReason: undefined }, null, error);
62
+ throw error;
63
+ }
64
+ if (!isThenable(result)) {
65
+ if (streaming && isAsyncIterable(result))
66
+ observeStream(result, base);
67
+ else
68
+ safeRecord(base, absorbSafe(spec.absorb, result), null, null);
69
+ return result;
70
+ }
71
+ // Observe the same promise the caller receives. Handlers never throw, so
72
+ // this derived promise never rejects and the original is returned as is.
73
+ result.then((value) => {
74
+ if (streaming && isAsyncIterable(value))
75
+ observeStream(value, base);
76
+ else
77
+ safeRecord(base, absorbSafe(spec.absorb, value), null, null);
78
+ }, (error) => {
79
+ safeRecord(base, {}, null, error);
80
+ });
81
+ return result;
82
+ };
83
+ Object.defineProperty(wrapped, WRAPPED, { value: true });
84
+ Object.defineProperty(wrapped, 'name', { value: original.name ?? methodName });
85
+ target[methodName] = wrapped;
86
+ }
87
+ function safeRecord(base, state, ttftMs, error) {
88
+ try {
89
+ base.record({
90
+ occurredAt: new Date().toISOString(),
91
+ operation: base.operation,
92
+ provider: base.provider,
93
+ model: state.model ?? base.requestModel,
94
+ inputTokens: state.inputTokens ?? 0,
95
+ cachedTokens: state.cachedTokens ?? 0,
96
+ outputTokens: state.outputTokens ?? 0,
97
+ durationMs: Math.round(performance.now() - base.started),
98
+ ttftMs: ttftMs === null ? undefined : Math.round(ttftMs),
99
+ finishReason: state.finishReason ?? null,
100
+ errorType: error === null ? null : errorTypeOf(error),
101
+ feature: base.feature,
102
+ accountId: base.accountId,
103
+ source: 'sdk',
104
+ batch: 0,
105
+ });
106
+ }
107
+ catch (e) {
108
+ try {
109
+ base.onError(e);
110
+ }
111
+ catch {
112
+ // Nothing left to report to.
113
+ }
114
+ }
115
+ }
116
+ function absorbSafe(absorb, value) {
117
+ const state = {};
118
+ try {
119
+ absorb(state, value);
120
+ }
121
+ catch {
122
+ // A shape we do not know; the call is still counted.
123
+ }
124
+ return state;
125
+ }
126
+ /**
127
+ * Patches the stream's async iterator in place so iteration is observed.
128
+ * The stream object the caller holds is unchanged in identity and API.
129
+ */
130
+ function observeStream(stream, base) {
131
+ const holder = stream;
132
+ const originalIterator = holder[Symbol.asyncIterator];
133
+ if (typeof originalIterator !== 'function')
134
+ return;
135
+ const state = {};
136
+ let ttftMs = null;
137
+ let recorded = false;
138
+ const finish = (error) => {
139
+ if (recorded)
140
+ return;
141
+ recorded = true;
142
+ safeRecord(base, state, ttftMs, error);
143
+ };
144
+ holder[Symbol.asyncIterator] = function () {
145
+ const inner = originalIterator.call(this);
146
+ const observed = {
147
+ async next(...args) {
148
+ let step;
149
+ try {
150
+ step = await inner.next(...args);
151
+ }
152
+ catch (error) {
153
+ finish(error);
154
+ throw error;
155
+ }
156
+ if (step.done) {
157
+ finish(null);
158
+ }
159
+ else {
160
+ if (ttftMs === null)
161
+ ttftMs = performance.now() - base.started;
162
+ try {
163
+ base.absorb(state, step.value);
164
+ }
165
+ catch {
166
+ // Unknown chunk shape; keep streaming.
167
+ }
168
+ }
169
+ return step;
170
+ },
171
+ async return(value) {
172
+ finish(null);
173
+ if (typeof inner.return === 'function')
174
+ return inner.return(value);
175
+ return { done: true, value };
176
+ },
177
+ async throw(error) {
178
+ finish(error ?? new Error('stream aborted'));
179
+ if (typeof inner.throw === 'function')
180
+ return inner.throw(error);
181
+ throw error;
182
+ },
183
+ [Symbol.asyncIterator]() {
184
+ return observed;
185
+ },
186
+ };
187
+ return observed;
188
+ };
189
+ }
190
+ // ── Shape readers ────────────────────────────────────────────────────────
191
+ function absorbOpenAIChat(state, value) {
192
+ if (!isObject(value))
193
+ return;
194
+ if (typeof value.model === 'string')
195
+ state.model = value.model;
196
+ readOpenAIUsage(state, value.usage);
197
+ const choices = value.choices;
198
+ if (Array.isArray(choices)) {
199
+ for (const choice of choices) {
200
+ if (isObject(choice) && typeof choice.finish_reason === 'string')
201
+ state.finishReason = choice.finish_reason;
202
+ }
203
+ }
204
+ }
205
+ function absorbOpenAIResponses(state, value) {
206
+ if (!isObject(value))
207
+ return;
208
+ // Stream events carry the response under `response`; a plain call is the response.
209
+ const response = isObject(value.response) ? value.response : value;
210
+ if (typeof response.model === 'string')
211
+ state.model = response.model;
212
+ readOpenAIUsage(state, response.usage);
213
+ if (typeof response.status === 'string') {
214
+ if (response.status === 'completed')
215
+ state.finishReason = 'stop';
216
+ else if (isObject(response.incomplete_details) && typeof response.incomplete_details.reason === 'string') {
217
+ state.finishReason = response.incomplete_details.reason;
218
+ }
219
+ else if (response.status !== 'in_progress' && response.status !== 'queued') {
220
+ state.finishReason = response.status;
221
+ }
222
+ }
223
+ }
224
+ function absorbOpenAIEmbeddings(state, value) {
225
+ if (!isObject(value))
226
+ return;
227
+ if (typeof value.model === 'string')
228
+ state.model = value.model;
229
+ readOpenAIUsage(state, value.usage);
230
+ }
231
+ function readOpenAIUsage(state, usage) {
232
+ if (!isObject(usage))
233
+ return;
234
+ const input = numberOf(usage.prompt_tokens) ?? numberOf(usage.input_tokens);
235
+ const output = numberOf(usage.completion_tokens) ?? numberOf(usage.output_tokens);
236
+ if (input !== undefined)
237
+ state.inputTokens = input;
238
+ if (output !== undefined)
239
+ state.outputTokens = output;
240
+ const details = isObject(usage.prompt_tokens_details)
241
+ ? usage.prompt_tokens_details
242
+ : isObject(usage.input_tokens_details)
243
+ ? usage.input_tokens_details
244
+ : null;
245
+ const cached = details ? numberOf(details.cached_tokens) : undefined;
246
+ if (cached !== undefined)
247
+ state.cachedTokens = cached;
248
+ }
249
+ function absorbAnthropicMessage(state, value) {
250
+ if (!isObject(value))
251
+ return;
252
+ // Stream: message_start carries the message; message_delta carries usage and the stop reason.
253
+ const message = isObject(value.message) ? value.message : value;
254
+ if (typeof message.model === 'string')
255
+ state.model = message.model;
256
+ readAnthropicUsage(state, message.usage);
257
+ if (message !== value)
258
+ readAnthropicUsage(state, value.usage);
259
+ if (typeof message.stop_reason === 'string')
260
+ state.finishReason = message.stop_reason;
261
+ if (isObject(value.delta) && typeof value.delta.stop_reason === 'string')
262
+ state.finishReason = value.delta.stop_reason;
263
+ }
264
+ function readAnthropicUsage(state, usage) {
265
+ if (!isObject(usage))
266
+ return;
267
+ const input = numberOf(usage.input_tokens);
268
+ const output = numberOf(usage.output_tokens);
269
+ const cached = numberOf(usage.cache_read_input_tokens);
270
+ if (input !== undefined)
271
+ state.inputTokens = input;
272
+ if (output !== undefined)
273
+ state.outputTokens = output;
274
+ if (cached !== undefined)
275
+ state.cachedTokens = cached;
276
+ }
277
+ // ── Small helpers ────────────────────────────────────────────────────────
278
+ export function errorTypeOf(error) {
279
+ if (isObject(error)) {
280
+ if (typeof error.status === 'number')
281
+ return String(error.status);
282
+ if (typeof error.code === 'string' && error.code)
283
+ return error.code;
284
+ if (typeof error.name === 'string' && error.name)
285
+ return error.name;
286
+ }
287
+ if (error instanceof Error)
288
+ return error.name || 'Error';
289
+ return 'Error';
290
+ }
291
+ function isObject(value) {
292
+ return typeof value === 'object' && value !== null;
293
+ }
294
+ function isThenable(value) {
295
+ return isObject(value) && typeof value.then === 'function';
296
+ }
297
+ function isAsyncIterable(value) {
298
+ return isObject(value) && typeof value[Symbol.asyncIterator] === 'function';
299
+ }
300
+ function numberOf(value) {
301
+ return typeof value === 'number' && Number.isFinite(value) ? value : undefined;
302
+ }
303
+ //# sourceMappingURL=ai.js.map
package/dist/ai.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ai.js","sourceRoot":"","sources":["../src/ai.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAOH,MAAM,OAAO,GAAG,MAAM,CAAC,GAAG,CAAC,uBAAuB,CAAC,CAAC;AAsBpD,MAAM,UAAU,UAAU,CAAmB,MAAS,EAAE,MAAgB,EAAE,OAAgB,EAAE,OAAO,GAAkB,EAAE;IACr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ixes" \
6
+ * --pr-url https://github.com/org/repo/pull/12 --deployer ci --outcome success
7
+ * npx @originatedev/run-sdk backup --datastore "Primary database" --status ok --size-bytes 18500000000
8
+ *
9
+ * Reads ORIGINATE_RUN_KEY (the application's opk_ key) and ORIGINATE_API_BASE
10
+ * (defaults to the production api) from the environment.
11
+ */
12
+ import type { BackupReport, DeployReport } from './types.js';
13
+ export declare function parseArgs(argv: string[]): {
14
+ command: string | undefined;
15
+ flags: Record<string, string>;
16
+ };
17
+ export declare function deployReportFromFlags(flags: Record<string, string>): DeployReport;
18
+ export declare function backupReportFromFlags(flags: Record<string, string>): BackupReport | string;
19
+ //# sourceMappingURL=cli.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AACA;;;;;;;;;GASG;AAGH,OAAO,KAAK,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAS7D,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG;IAAE,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAAE,CAoBxG;AAED,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,YAAY,CAUjF;AAED,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,YAAY,GAAG,MAAM,CAwB1F"}