@originatedev/run-sdk 0.1.0 → 0.1.2
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 +202 -0
- package/README.md +35 -1
- package/dist/cjs/ai.d.ts +13 -0
- package/dist/cjs/ai.js +308 -0
- package/dist/cjs/ai.js.map +1 -0
- package/dist/cjs/cli.d.ts +18 -0
- package/dist/cjs/cli.js +162 -0
- package/dist/cjs/cli.js.map +1 -0
- package/dist/cjs/express.d.ts +30 -0
- package/dist/cjs/express.js +54 -0
- package/dist/cjs/express.js.map +1 -0
- package/dist/cjs/fastify.d.ts +32 -0
- package/dist/cjs/fastify.js +38 -0
- package/dist/cjs/fastify.js.map +1 -0
- package/dist/cjs/index.d.ts +139 -0
- package/dist/cjs/index.js +653 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/metrics.d.ts +33 -0
- package/dist/cjs/metrics.js +120 -0
- package/dist/cjs/metrics.js.map +1 -0
- package/dist/cjs/otel.d.ts +43 -0
- package/dist/cjs/otel.js +111 -0
- package/dist/cjs/otel.js.map +1 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/transport.d.ts +53 -0
- package/dist/cjs/transport.js +139 -0
- package/dist/cjs/transport.js.map +1 -0
- package/dist/cjs/types.d.ts +240 -0
- package/dist/cjs/types.js +18 -0
- package/dist/cjs/types.js.map +1 -0
- package/package.json +40 -18
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shapes shared by the Run SDK modules. These mirror the api's public Run
|
|
3
|
+
* types (packages/shared/src/types/run.ts) but are copied here on purpose:
|
|
4
|
+
* customers install this package outside the monorepo, so the SDK depends
|
|
5
|
+
* on nothing from the platform at runtime or at type level.
|
|
6
|
+
*/
|
|
7
|
+
export declare const SDK_VERSION = "0.1.0";
|
|
8
|
+
export declare const DEFAULT_API_BASE = "https://api.platform.originatetech.com";
|
|
9
|
+
/** Matches RUN_EVENT_NAME_PATTERN on the api. */
|
|
10
|
+
export declare const EVENT_NAME_PATTERN: RegExp;
|
|
11
|
+
/** Matches RUN_EVENT_BATCH_MAX on the api. */
|
|
12
|
+
export declare const EVENT_BATCH_MAX = 50;
|
|
13
|
+
export declare const AI_CALL_BATCH_MAX = 200;
|
|
14
|
+
export declare const METRIC_BATCH_MAX = 500;
|
|
15
|
+
export type EventPropValue = string | number | boolean | null;
|
|
16
|
+
export type EventProps = Record<string, EventPropValue>;
|
|
17
|
+
export interface RunInitOptions {
|
|
18
|
+
/** The application's public key (opk_...). */
|
|
19
|
+
key: string;
|
|
20
|
+
/** Base URL of the Originate api. Defaults to the production api. */
|
|
21
|
+
apiBase?: string;
|
|
22
|
+
/** The application's release or commit. Defaults to ORIGINATE_RUN_RELEASE. */
|
|
23
|
+
release?: string;
|
|
24
|
+
/** Name of this service when the application runs several processes. */
|
|
25
|
+
service?: string;
|
|
26
|
+
/** How often queued events, AI calls and metrics are sent. Default 5000. */
|
|
27
|
+
flushIntervalMs?: number;
|
|
28
|
+
/** How often a heartbeat is sent. Default 60000. 0 disables heartbeats. */
|
|
29
|
+
heartbeatIntervalMs?: number;
|
|
30
|
+
/** Called with every delivery or wrapper error. The SDK never throws into the host. */
|
|
31
|
+
onError?: (error: unknown) => void;
|
|
32
|
+
/** When true nothing is queued or sent; every method is a no-op. */
|
|
33
|
+
disabled?: boolean;
|
|
34
|
+
/** Replacement for the global fetch, mostly for tests. */
|
|
35
|
+
fetch?: typeof fetch;
|
|
36
|
+
/** Per-request timeout for deliveries. Default 10000. */
|
|
37
|
+
requestTimeoutMs?: number;
|
|
38
|
+
}
|
|
39
|
+
export interface TrackOptions {
|
|
40
|
+
accountId?: string;
|
|
41
|
+
sessionId?: string;
|
|
42
|
+
/** Client timestamp, ISO 8601. Defaults to now. */
|
|
43
|
+
ts?: string;
|
|
44
|
+
}
|
|
45
|
+
/** One event as sent to POST /api/v1/run/collect. */
|
|
46
|
+
export interface CollectEvent {
|
|
47
|
+
name: string;
|
|
48
|
+
ts?: string;
|
|
49
|
+
anonymousId?: string;
|
|
50
|
+
accountId?: string;
|
|
51
|
+
sessionId?: string;
|
|
52
|
+
url?: string;
|
|
53
|
+
referrer?: string;
|
|
54
|
+
props?: EventProps;
|
|
55
|
+
}
|
|
56
|
+
export interface CollectRequest {
|
|
57
|
+
key: string;
|
|
58
|
+
events: CollectEvent[];
|
|
59
|
+
release?: string;
|
|
60
|
+
}
|
|
61
|
+
export type AiOperation = 'chat' | 'embeddings' | 'text_completion' | 'generate_content' | (string & {});
|
|
62
|
+
/** One row of run_ai_calls as the SDK reports it. Never any content. */
|
|
63
|
+
export interface AiCall {
|
|
64
|
+
/** ISO 8601. Defaults to now. */
|
|
65
|
+
occurredAt?: string;
|
|
66
|
+
/** chat | embeddings | text_completion | generate_content. Defaults to chat. */
|
|
67
|
+
operation?: AiOperation;
|
|
68
|
+
provider: string;
|
|
69
|
+
model: string;
|
|
70
|
+
inputTokens?: number;
|
|
71
|
+
cachedTokens?: number;
|
|
72
|
+
outputTokens?: number;
|
|
73
|
+
durationMs?: number;
|
|
74
|
+
ttftMs?: number;
|
|
75
|
+
finishReason?: string | null;
|
|
76
|
+
errorType?: string | null;
|
|
77
|
+
costUsd?: number | null;
|
|
78
|
+
/** The feature or surface in the application that made the call. */
|
|
79
|
+
feature?: string | null;
|
|
80
|
+
accountId?: string | null;
|
|
81
|
+
/** sdk | gateway | platform. Defaults to sdk. */
|
|
82
|
+
source?: string;
|
|
83
|
+
guardrailMode?: 'off' | 'inspect' | 'block' | null;
|
|
84
|
+
guardrailDecision?: 'none' | 'flagged' | 'masked' | 'blocked' | null;
|
|
85
|
+
guardrailCategories?: string[];
|
|
86
|
+
/** 1 when the call went through a batch API. */
|
|
87
|
+
batch?: 0 | 1;
|
|
88
|
+
/** Version of the GenAI semantic conventions the attributes follow. */
|
|
89
|
+
schemaVersion?: string | null;
|
|
90
|
+
}
|
|
91
|
+
export interface AiWrapOptions {
|
|
92
|
+
/** Feature recorded on every call made through the wrapped client. */
|
|
93
|
+
feature?: string;
|
|
94
|
+
/** Account id recorded on every call made through the wrapped client. */
|
|
95
|
+
accountId?: string;
|
|
96
|
+
}
|
|
97
|
+
export interface MeterOptions {
|
|
98
|
+
costUsd?: number;
|
|
99
|
+
accountId?: string;
|
|
100
|
+
sessionId?: string;
|
|
101
|
+
/** Extra dimensions on the external_call event. */
|
|
102
|
+
props?: EventProps;
|
|
103
|
+
}
|
|
104
|
+
export interface DeployReport {
|
|
105
|
+
version?: string;
|
|
106
|
+
commit?: string;
|
|
107
|
+
summary?: string;
|
|
108
|
+
prUrl?: string;
|
|
109
|
+
deployer?: string;
|
|
110
|
+
outcome?: 'success' | 'rolled_back' | 'failed' | 'in_progress';
|
|
111
|
+
notes?: string;
|
|
112
|
+
}
|
|
113
|
+
/** A backup or restore test the application took; Run records that it happened. */
|
|
114
|
+
export interface BackupReport {
|
|
115
|
+
/** backup (default) or restore_test. */
|
|
116
|
+
kind?: 'backup' | 'restore_test';
|
|
117
|
+
/** The data store backed up ("Primary database", "Uploaded files"). */
|
|
118
|
+
datastore: string;
|
|
119
|
+
/** When it was taken; defaults to now. */
|
|
120
|
+
takenAt?: string | Date;
|
|
121
|
+
sizeBytes?: number;
|
|
122
|
+
/** ok (default), failed or partial. */
|
|
123
|
+
status?: 'ok' | 'failed' | 'partial';
|
|
124
|
+
/** How long it took; for a restore test this is the RTO figure. */
|
|
125
|
+
durationSeconds?: number;
|
|
126
|
+
detail?: string;
|
|
127
|
+
}
|
|
128
|
+
/** Daily counts of policy.check() outcomes per policy, as POST /sdk/policy-decisions takes them. */
|
|
129
|
+
export interface PolicyDecisionCount {
|
|
130
|
+
policyKey: string;
|
|
131
|
+
/** UTC day, YYYY-MM-DD. */
|
|
132
|
+
day: string;
|
|
133
|
+
allowed: number;
|
|
134
|
+
denied: number;
|
|
135
|
+
masked: number;
|
|
136
|
+
}
|
|
137
|
+
export type HealthStatus = 'ok' | 'degraded' | 'down';
|
|
138
|
+
export interface HealthCheckResult {
|
|
139
|
+
status: HealthStatus;
|
|
140
|
+
detail?: string;
|
|
141
|
+
}
|
|
142
|
+
/** A check returns true (ok), false (down), a status, or a result; a throw counts as down. */
|
|
143
|
+
export type HealthCheck = () => boolean | HealthStatus | HealthCheckResult | void | Promise<boolean | HealthStatus | HealthCheckResult | void>;
|
|
144
|
+
export interface HealthCheckOptions {
|
|
145
|
+
/** A critical check that is down takes the whole service down; a non-critical one only degrades it. Default true. */
|
|
146
|
+
critical?: boolean;
|
|
147
|
+
/** Milliseconds before the check is reported as down. Default 3000. */
|
|
148
|
+
timeoutMs?: number;
|
|
149
|
+
}
|
|
150
|
+
export interface HealthReport {
|
|
151
|
+
status: HealthStatus;
|
|
152
|
+
checks: Record<string, HealthCheckResult>;
|
|
153
|
+
release: string | null;
|
|
154
|
+
service: string | null;
|
|
155
|
+
uptimeSeconds: number;
|
|
156
|
+
}
|
|
157
|
+
export interface HeartbeatBody {
|
|
158
|
+
key: string;
|
|
159
|
+
version: string;
|
|
160
|
+
release: string | null;
|
|
161
|
+
service: string | null;
|
|
162
|
+
health?: {
|
|
163
|
+
status: HealthStatus;
|
|
164
|
+
checks: Record<string, HealthStatus>;
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
export interface MetricMinute {
|
|
168
|
+
/** ISO 8601 start of the minute. */
|
|
169
|
+
minute: string;
|
|
170
|
+
/** "METHOD route", with the framework's route template when it has one. */
|
|
171
|
+
route: string;
|
|
172
|
+
count: number;
|
|
173
|
+
/** Responses with a 5xx status. */
|
|
174
|
+
errors: number;
|
|
175
|
+
p50: number;
|
|
176
|
+
p95: number;
|
|
177
|
+
p99: number;
|
|
178
|
+
}
|
|
179
|
+
export interface MetricsRequest {
|
|
180
|
+
key: string;
|
|
181
|
+
service?: string;
|
|
182
|
+
minutes: MetricMinute[];
|
|
183
|
+
}
|
|
184
|
+
export type PolicyEffect = 'allow' | 'deny' | 'mask';
|
|
185
|
+
/**
|
|
186
|
+
* A policy as GET /api/v1/run/sdk/policies returns it. `rule` lists the
|
|
187
|
+
* dimensions the policy applies to; a dimension that is absent matches
|
|
188
|
+
* everything. A policy matches an input when every listed dimension
|
|
189
|
+
* intersects the input.
|
|
190
|
+
*/
|
|
191
|
+
export interface Policy {
|
|
192
|
+
key: string;
|
|
193
|
+
title?: string;
|
|
194
|
+
effect: PolicyEffect;
|
|
195
|
+
enforcedAt?: string[];
|
|
196
|
+
version?: number;
|
|
197
|
+
enabled?: boolean;
|
|
198
|
+
rule: {
|
|
199
|
+
dataClasses?: string[];
|
|
200
|
+
regions?: string[];
|
|
201
|
+
purposes?: string[];
|
|
202
|
+
features?: string[];
|
|
203
|
+
providers?: string[];
|
|
204
|
+
models?: string[];
|
|
205
|
+
actions?: string[];
|
|
206
|
+
[key: string]: unknown;
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
export interface PoliciesResponse {
|
|
210
|
+
policies: Policy[];
|
|
211
|
+
/** implicit | banner | external. */
|
|
212
|
+
consentMode?: 'implicit' | 'banner' | 'external';
|
|
213
|
+
/** Present when the request named a subject: the purposes that subject has granted. */
|
|
214
|
+
consent?: {
|
|
215
|
+
purposes: string[];
|
|
216
|
+
state: 'granted' | 'withdrawn';
|
|
217
|
+
} | null;
|
|
218
|
+
}
|
|
219
|
+
export interface PolicyCheckInput {
|
|
220
|
+
dataClasses?: string[];
|
|
221
|
+
region?: string;
|
|
222
|
+
purpose?: string;
|
|
223
|
+
feature?: string;
|
|
224
|
+
provider?: string;
|
|
225
|
+
model?: string;
|
|
226
|
+
action?: string;
|
|
227
|
+
}
|
|
228
|
+
export interface PolicyDecision {
|
|
229
|
+
allowed: boolean;
|
|
230
|
+
effect: PolicyEffect | null;
|
|
231
|
+
/** Key of the policy that decided, when one matched. */
|
|
232
|
+
policyKey: string | null;
|
|
233
|
+
/** no_policy | allow | deny | mask | unavailable */
|
|
234
|
+
reason: 'no_policy' | 'allow' | 'deny' | 'mask' | 'unavailable';
|
|
235
|
+
}
|
|
236
|
+
export interface ConsentDecision {
|
|
237
|
+
allowed: boolean;
|
|
238
|
+
/** implicit | granted | withdrawn | unknown | no_policy | unavailable */
|
|
239
|
+
reason: 'implicit' | 'granted' | 'withdrawn' | 'unknown' | 'no_policy' | 'unavailable';
|
|
240
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Shapes shared by the Run SDK modules. These mirror the api's public Run
|
|
4
|
+
* types (packages/shared/src/types/run.ts) but are copied here on purpose:
|
|
5
|
+
* customers install this package outside the monorepo, so the SDK depends
|
|
6
|
+
* on nothing from the platform at runtime or at type level.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.METRIC_BATCH_MAX = exports.AI_CALL_BATCH_MAX = exports.EVENT_BATCH_MAX = exports.EVENT_NAME_PATTERN = exports.DEFAULT_API_BASE = exports.SDK_VERSION = void 0;
|
|
10
|
+
exports.SDK_VERSION = '0.1.0';
|
|
11
|
+
exports.DEFAULT_API_BASE = 'https://api.platform.originatetech.com';
|
|
12
|
+
/** Matches RUN_EVENT_NAME_PATTERN on the api. */
|
|
13
|
+
exports.EVENT_NAME_PATTERN = /^[a-z][a-z0-9_]{1,63}$/;
|
|
14
|
+
/** Matches RUN_EVENT_BATCH_MAX on the api. */
|
|
15
|
+
exports.EVENT_BATCH_MAX = 50;
|
|
16
|
+
exports.AI_CALL_BATCH_MAX = 200;
|
|
17
|
+
exports.METRIC_BATCH_MAX = 500;
|
|
18
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEU,QAAA,WAAW,GAAG,OAAO,CAAC;AACtB,QAAA,gBAAgB,GAAG,wCAAwC,CAAC;AAEzE,iDAAiD;AACpC,QAAA,kBAAkB,GAAG,wBAAwB,CAAC;AAC3D,8CAA8C;AACjC,QAAA,eAAe,GAAG,EAAE,CAAC;AACrB,QAAA,iBAAiB,GAAG,GAAG,CAAC;AACxB,QAAA,gBAAgB,GAAG,GAAG,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,39 +1,66 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@originatedev/run-sdk",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Backend SDK for Run, Originate's managed service: request metrics, AI call telemetry, health, deploy reports, policies and consent. No prompts or completions ever leave the process.",
|
|
6
|
-
"license": "
|
|
6
|
+
"license": "Apache-2.0",
|
|
7
7
|
"engines": {
|
|
8
8
|
"node": ">=18"
|
|
9
9
|
},
|
|
10
|
+
"main": "./dist/cjs/index.js",
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
10
12
|
"exports": {
|
|
11
13
|
".": {
|
|
12
|
-
"
|
|
13
|
-
|
|
14
|
+
"import": {
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"default": "./dist/index.js"
|
|
17
|
+
},
|
|
18
|
+
"require": {
|
|
19
|
+
"types": "./dist/cjs/index.d.ts",
|
|
20
|
+
"default": "./dist/cjs/index.js"
|
|
21
|
+
}
|
|
14
22
|
},
|
|
15
23
|
"./otel": {
|
|
16
|
-
"
|
|
17
|
-
|
|
24
|
+
"import": {
|
|
25
|
+
"types": "./dist/otel.d.ts",
|
|
26
|
+
"default": "./dist/otel.js"
|
|
27
|
+
},
|
|
28
|
+
"require": {
|
|
29
|
+
"types": "./dist/cjs/otel.d.ts",
|
|
30
|
+
"default": "./dist/cjs/otel.js"
|
|
31
|
+
}
|
|
18
32
|
},
|
|
19
33
|
"./express": {
|
|
20
|
-
"
|
|
21
|
-
|
|
34
|
+
"import": {
|
|
35
|
+
"types": "./dist/express.d.ts",
|
|
36
|
+
"default": "./dist/express.js"
|
|
37
|
+
},
|
|
38
|
+
"require": {
|
|
39
|
+
"types": "./dist/cjs/express.d.ts",
|
|
40
|
+
"default": "./dist/cjs/express.js"
|
|
41
|
+
}
|
|
22
42
|
},
|
|
23
43
|
"./fastify": {
|
|
24
|
-
"
|
|
25
|
-
|
|
44
|
+
"import": {
|
|
45
|
+
"types": "./dist/fastify.d.ts",
|
|
46
|
+
"default": "./dist/fastify.js"
|
|
47
|
+
},
|
|
48
|
+
"require": {
|
|
49
|
+
"types": "./dist/cjs/fastify.d.ts",
|
|
50
|
+
"default": "./dist/cjs/fastify.js"
|
|
51
|
+
}
|
|
26
52
|
}
|
|
27
53
|
},
|
|
28
54
|
"bin": {
|
|
29
|
-
"originate-run": "
|
|
55
|
+
"originate-run": "dist/cli.js"
|
|
30
56
|
},
|
|
31
57
|
"files": [
|
|
32
58
|
"dist",
|
|
33
|
-
"README.md"
|
|
59
|
+
"README.md",
|
|
60
|
+
"LICENSE"
|
|
34
61
|
],
|
|
35
62
|
"scripts": {
|
|
36
|
-
"build": "tsc -p tsconfig.json",
|
|
63
|
+
"build": "tsc -p tsconfig.json && tsc -p tsconfig.cjs.json && node scripts/mark-cjs.mjs",
|
|
37
64
|
"typecheck": "tsc --noEmit -p tsconfig.json",
|
|
38
65
|
"test": "vitest run --passWithNoTests"
|
|
39
66
|
},
|
|
@@ -64,10 +91,5 @@
|
|
|
64
91
|
"publishConfig": {
|
|
65
92
|
"access": "public"
|
|
66
93
|
},
|
|
67
|
-
"repository": {
|
|
68
|
-
"type": "git",
|
|
69
|
-
"url": "git+https://github.com/labten/originate-platform.git",
|
|
70
|
-
"directory": "packages/run-sdk"
|
|
71
|
-
},
|
|
72
94
|
"homepage": "https://www.originatetech.com"
|
|
73
95
|
}
|