@keelapi/sdk 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +196 -0
- package/dist/examples/express.d.ts +1 -0
- package/dist/examples/express.js +33 -0
- package/dist/examples/next-route.d.ts +6 -0
- package/dist/examples/next-route.js +29 -0
- package/dist/examples/permit.d.ts +1 -0
- package/dist/examples/permit.js +49 -0
- package/dist/src/client.d.ts +28 -0
- package/dist/src/client.js +48 -0
- package/dist/src/clients/execute.d.ts +8 -0
- package/dist/src/clients/execute.js +15 -0
- package/dist/src/clients/executions.d.ts +9 -0
- package/dist/src/clients/executions.js +22 -0
- package/dist/src/clients/jobs.d.ts +8 -0
- package/dist/src/clients/jobs.js +15 -0
- package/dist/src/clients/permits.d.ts +18 -0
- package/dist/src/clients/permits.js +72 -0
- package/dist/src/clients/proxy.d.ts +10 -0
- package/dist/src/clients/proxy.js +24 -0
- package/dist/src/clients/requests.d.ts +7 -0
- package/dist/src/clients/requests.js +12 -0
- package/dist/src/errors.d.ts +7 -0
- package/dist/src/errors.js +14 -0
- package/dist/src/http.d.ts +48 -0
- package/dist/src/http.js +303 -0
- package/dist/src/index.d.ts +15 -0
- package/dist/src/index.js +25 -0
- package/dist/src/middleware/express.d.ts +4 -0
- package/dist/src/middleware/express.js +26 -0
- package/dist/src/middleware/next.d.ts +10 -0
- package/dist/src/middleware/next.js +26 -0
- package/dist/src/middleware/shared.d.ts +40 -0
- package/dist/src/middleware/shared.js +122 -0
- package/dist/src/streaming.d.ts +2 -0
- package/dist/src/streaming.js +82 -0
- package/dist/src/types.d.ts +622 -0
- package/dist/src/types.js +5 -0
- package/package.json +41 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Keel
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
# @keelapi/sdk
|
|
2
|
+
|
|
3
|
+
TypeScript SDK for the [Keel](https://keel.so) AI governance API.
|
|
4
|
+
|
|
5
|
+
Keel lets you issue permits before AI calls, enforce policies, track usage, and audit decisions — across any provider.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @keelapi/sdk
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Setup
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import { KeelClient } from "@keelapi/sdk";
|
|
17
|
+
|
|
18
|
+
const client = new KeelClient({
|
|
19
|
+
baseUrl: process.env.KEEL_BASE_URL!,
|
|
20
|
+
apiKey: process.env.KEEL_API_KEY!,
|
|
21
|
+
});
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Permits
|
|
25
|
+
|
|
26
|
+
Request a permit before making an AI call:
|
|
27
|
+
|
|
28
|
+
```ts
|
|
29
|
+
const permit = await client.permits.create({
|
|
30
|
+
project_id: "proj_123",
|
|
31
|
+
idempotency_key: crypto.randomUUID(),
|
|
32
|
+
subject: { type: "user", id: "usr_123" },
|
|
33
|
+
action: { name: "ai.generate" },
|
|
34
|
+
resource: {
|
|
35
|
+
type: "request",
|
|
36
|
+
id: "req_123",
|
|
37
|
+
attributes: {
|
|
38
|
+
provider: "openai",
|
|
39
|
+
model: "gpt-4o-mini",
|
|
40
|
+
estimated_input_tokens: 200,
|
|
41
|
+
estimated_output_tokens: 500,
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
if (permit.decision === "allow") {
|
|
47
|
+
// proceed with AI call
|
|
48
|
+
}
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### Dry run
|
|
52
|
+
|
|
53
|
+
```ts
|
|
54
|
+
const result = await client.permits.dryRun(permitRequest);
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### List and get
|
|
58
|
+
|
|
59
|
+
```ts
|
|
60
|
+
const list = await client.permits.list({ project_id: "proj_123", limit: 50 });
|
|
61
|
+
const permit = await client.permits.get("permit_id");
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### Report usage
|
|
65
|
+
|
|
66
|
+
```ts
|
|
67
|
+
await client.permits.reportUsage("permit_id", {
|
|
68
|
+
input_tokens: 180,
|
|
69
|
+
output_tokens: 420,
|
|
70
|
+
});
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### Attestation, evidence, lineage
|
|
74
|
+
|
|
75
|
+
```ts
|
|
76
|
+
await client.permits.attest("permit_id", { outcome: "success" });
|
|
77
|
+
await client.permits.addEvidence("permit_id", { label: "response_hash", value: "abc123" });
|
|
78
|
+
const evidence = await client.permits.listEvidence("permit_id");
|
|
79
|
+
const lineage = await client.permits.lineage("permit_id");
|
|
80
|
+
const bundle = await client.permits.bundle("permit_id");
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
## Executions
|
|
84
|
+
|
|
85
|
+
Run a model synchronously:
|
|
86
|
+
|
|
87
|
+
```ts
|
|
88
|
+
const result = await client.executions.create({
|
|
89
|
+
provider: "openai",
|
|
90
|
+
model: "gpt-4o-mini",
|
|
91
|
+
messages: [{ role: "user", content: "Summarize this document." }],
|
|
92
|
+
permit_id: permit.id,
|
|
93
|
+
});
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
Stream tokens as they arrive:
|
|
97
|
+
|
|
98
|
+
```ts
|
|
99
|
+
for await (const event of client.executions.stream({
|
|
100
|
+
provider: "openai",
|
|
101
|
+
model: "gpt-4o-mini",
|
|
102
|
+
messages: [{ role: "user", content: "Write a poem." }],
|
|
103
|
+
permit_id: permit.id,
|
|
104
|
+
})) {
|
|
105
|
+
if (event.type === "content_delta") process.stdout.write(event.delta);
|
|
106
|
+
if (event.type === "done") console.log("\nFinished.");
|
|
107
|
+
}
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
## Execute (unified)
|
|
111
|
+
|
|
112
|
+
```ts
|
|
113
|
+
const result = await client.execute.run({
|
|
114
|
+
model: "gpt-4o-mini",
|
|
115
|
+
input: "Translate to Spanish: Hello world",
|
|
116
|
+
provider: "openai",
|
|
117
|
+
});
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
## Proxy
|
|
121
|
+
|
|
122
|
+
Pass requests through to providers with Keel governance applied:
|
|
123
|
+
|
|
124
|
+
```ts
|
|
125
|
+
const response = await client.proxy.openai({
|
|
126
|
+
model: "gpt-4o-mini",
|
|
127
|
+
messages: [{ role: "user", content: "Hello" }],
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
// Also: client.proxy.anthropic(), .google(), .xai(), .meta()
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
## Jobs
|
|
134
|
+
|
|
135
|
+
Submit async jobs and poll for results:
|
|
136
|
+
|
|
137
|
+
```ts
|
|
138
|
+
const job = await client.jobs.create({
|
|
139
|
+
provider: "openai",
|
|
140
|
+
model: "gpt-4o-mini",
|
|
141
|
+
messages: [{ role: "user", content: "Analyze this dataset." }],
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
const status = await client.jobs.get(job.job_id);
|
|
145
|
+
// status.status: "pending" | "running" | "completed" | "failed"
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
## API Keys
|
|
149
|
+
|
|
150
|
+
```ts
|
|
151
|
+
const key = await client.apiKeys.create();
|
|
152
|
+
const keys = await client.apiKeys.list();
|
|
153
|
+
const single = await client.apiKeys.get(key.id);
|
|
154
|
+
await client.apiKeys.revoke(key.id);
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
## Request Timeline
|
|
158
|
+
|
|
159
|
+
```ts
|
|
160
|
+
const timeline = await client.requests.timeline("request_id");
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
## Error Handling
|
|
164
|
+
|
|
165
|
+
```ts
|
|
166
|
+
import { KeelError } from "@keelapi/sdk";
|
|
167
|
+
|
|
168
|
+
try {
|
|
169
|
+
await client.permits.create(request);
|
|
170
|
+
} catch (err) {
|
|
171
|
+
if (err instanceof KeelError) {
|
|
172
|
+
console.error(err.status); // HTTP status code
|
|
173
|
+
console.error(err.code); // e.g. "permit_denied"
|
|
174
|
+
console.error(err.message); // human-readable message
|
|
175
|
+
console.error(err.field); // field that caused the error, if any
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
## Freshness Headers
|
|
181
|
+
|
|
182
|
+
For replay-protected endpoints, enable freshness headers:
|
|
183
|
+
|
|
184
|
+
```ts
|
|
185
|
+
const client = new KeelClient({
|
|
186
|
+
baseUrl: process.env.KEEL_BASE_URL!,
|
|
187
|
+
apiKey: process.env.KEEL_API_KEY!,
|
|
188
|
+
requestFreshness: { enabled: true },
|
|
189
|
+
});
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
This adds `X-Keel-Timestamp` and `X-Keel-Nonce` to every request.
|
|
193
|
+
|
|
194
|
+
## License
|
|
195
|
+
|
|
196
|
+
MIT
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const express_1 = __importDefault(require("express"));
|
|
7
|
+
const src_1 = require("../src");
|
|
8
|
+
const app = (0, express_1.default)();
|
|
9
|
+
app.use(express_1.default.json());
|
|
10
|
+
app.get("/protected", (0, src_1.keelExpress)({
|
|
11
|
+
projectId: "prj_demo",
|
|
12
|
+
getSubject: (req) => ({
|
|
13
|
+
type: "user",
|
|
14
|
+
id: String(req.header("x-user-id") || "anonymous"),
|
|
15
|
+
attributes: {},
|
|
16
|
+
}),
|
|
17
|
+
getResource: (req) => ({
|
|
18
|
+
type: "request",
|
|
19
|
+
id: `${req.method}:${req.path}`,
|
|
20
|
+
attributes: {
|
|
21
|
+
provider: "openai",
|
|
22
|
+
model: "gpt-4o-mini",
|
|
23
|
+
estimated_input_tokens: 16,
|
|
24
|
+
estimated_output_tokens: 32,
|
|
25
|
+
max_output_tokens_requested: 128,
|
|
26
|
+
},
|
|
27
|
+
}),
|
|
28
|
+
}), (_req, res) => {
|
|
29
|
+
res.json({ ok: true });
|
|
30
|
+
});
|
|
31
|
+
app.listen(3000, () => {
|
|
32
|
+
console.log("Express example listening on http://localhost:3000");
|
|
33
|
+
});
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type NextApiRequestLike, type NextApiResponseLike } from "../src";
|
|
2
|
+
type Req = NextApiRequestLike & {
|
|
3
|
+
headers?: Record<string, string | string[] | undefined>;
|
|
4
|
+
};
|
|
5
|
+
declare const _default: import("../src").NextApiHandler<Req, NextApiResponseLike>;
|
|
6
|
+
export default _default;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const src_1 = require("../src");
|
|
4
|
+
async function handler(_req, res) {
|
|
5
|
+
res.status(200).json({ ok: true });
|
|
6
|
+
}
|
|
7
|
+
exports.default = (0, src_1.withKeel)(handler, {
|
|
8
|
+
projectId: "prj_demo",
|
|
9
|
+
getSubject: (req) => {
|
|
10
|
+
const rawHeader = req.headers?.["x-user-id"];
|
|
11
|
+
const id = Array.isArray(rawHeader) ? rawHeader[0] : rawHeader;
|
|
12
|
+
return {
|
|
13
|
+
type: "user",
|
|
14
|
+
id: id || "anonymous",
|
|
15
|
+
attributes: {},
|
|
16
|
+
};
|
|
17
|
+
},
|
|
18
|
+
getResource: (req) => ({
|
|
19
|
+
type: "request",
|
|
20
|
+
id: `${req.method || "GET"}:${req.url || ""}`,
|
|
21
|
+
attributes: {
|
|
22
|
+
provider: "openai",
|
|
23
|
+
model: "gpt-4o-mini",
|
|
24
|
+
estimated_input_tokens: 16,
|
|
25
|
+
estimated_output_tokens: 32,
|
|
26
|
+
max_output_tokens_requested: 128,
|
|
27
|
+
},
|
|
28
|
+
}),
|
|
29
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const src_1 = require("../src");
|
|
4
|
+
async function main() {
|
|
5
|
+
const baseUrl = process.env.KEEL_BASE_URL;
|
|
6
|
+
const apiKey = process.env.KEEL_API_KEY;
|
|
7
|
+
if (!baseUrl) {
|
|
8
|
+
throw new Error("KEEL_BASE_URL is required");
|
|
9
|
+
}
|
|
10
|
+
if (!apiKey) {
|
|
11
|
+
throw new Error("KEEL_API_KEY is required");
|
|
12
|
+
}
|
|
13
|
+
const client = new src_1.KeelClient({ baseUrl, apiKey });
|
|
14
|
+
const request = {
|
|
15
|
+
project_id: "prj_demo",
|
|
16
|
+
idempotency_key: `idem_example_${Date.now()}`,
|
|
17
|
+
subject: {
|
|
18
|
+
type: "user",
|
|
19
|
+
id: "usr_example",
|
|
20
|
+
attributes: {},
|
|
21
|
+
},
|
|
22
|
+
action: {
|
|
23
|
+
name: "ai.generate.summary",
|
|
24
|
+
attributes: {},
|
|
25
|
+
},
|
|
26
|
+
resource: {
|
|
27
|
+
type: "request",
|
|
28
|
+
id: "req_example",
|
|
29
|
+
attributes: {
|
|
30
|
+
provider: "openai",
|
|
31
|
+
model: "gpt-4o-mini",
|
|
32
|
+
estimated_input_tokens: 10,
|
|
33
|
+
estimated_output_tokens: 20,
|
|
34
|
+
max_output_tokens_requested: 64,
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
const permit = await client.createPermit(request);
|
|
39
|
+
console.log(`decision=${permit.decision} reason=${permit.reason}`);
|
|
40
|
+
}
|
|
41
|
+
main().catch((error) => {
|
|
42
|
+
if (error instanceof Error) {
|
|
43
|
+
console.error(error.message);
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
console.error(error);
|
|
47
|
+
}
|
|
48
|
+
process.exit(1);
|
|
49
|
+
});
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { PermitsClient } from "./clients/permits";
|
|
2
|
+
import { ExecutionsClient } from "./clients/executions";
|
|
3
|
+
import { ExecuteClient } from "./clients/execute";
|
|
4
|
+
import { ProxyClient } from "./clients/proxy";
|
|
5
|
+
import { JobsClient } from "./clients/jobs";
|
|
6
|
+
import { RequestsClient } from "./clients/requests";
|
|
7
|
+
import { type HttpTransportOptions, type RequestFreshnessOptions, type RequestIdProvider } from "./http";
|
|
8
|
+
import type { AuthedHealthResponse, CreateApiKeyResponse, HealthResponse, ListApiKeysResponse, PermitRequest, PermitResponse, PermitWithMetaResponse } from "./types";
|
|
9
|
+
export type { RequestIdProvider, RequestFreshnessOptions };
|
|
10
|
+
export interface KeelClientOptions extends HttpTransportOptions {
|
|
11
|
+
}
|
|
12
|
+
export declare class KeelClient {
|
|
13
|
+
readonly permits: PermitsClient;
|
|
14
|
+
readonly executions: ExecutionsClient;
|
|
15
|
+
readonly execute: ExecuteClient;
|
|
16
|
+
readonly proxy: ProxyClient;
|
|
17
|
+
readonly jobs: JobsClient;
|
|
18
|
+
readonly requests: RequestsClient;
|
|
19
|
+
private readonly http;
|
|
20
|
+
constructor(options: KeelClientOptions);
|
|
21
|
+
createPermit(request: PermitRequest): Promise<PermitResponse>;
|
|
22
|
+
createPermitWithMeta(request: PermitRequest): Promise<PermitWithMetaResponse>;
|
|
23
|
+
createApiKey(): Promise<CreateApiKeyResponse>;
|
|
24
|
+
listApiKeys(): Promise<ListApiKeysResponse>;
|
|
25
|
+
revokeApiKey(keyId: string): Promise<void>;
|
|
26
|
+
getHealth(): Promise<HealthResponse>;
|
|
27
|
+
getAuthedHealth(): Promise<AuthedHealthResponse>;
|
|
28
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.KeelClient = void 0;
|
|
4
|
+
const permits_1 = require("./clients/permits");
|
|
5
|
+
const executions_1 = require("./clients/executions");
|
|
6
|
+
const execute_1 = require("./clients/execute");
|
|
7
|
+
const proxy_1 = require("./clients/proxy");
|
|
8
|
+
const jobs_1 = require("./clients/jobs");
|
|
9
|
+
const requests_1 = require("./clients/requests");
|
|
10
|
+
const http_1 = require("./http");
|
|
11
|
+
class KeelClient {
|
|
12
|
+
constructor(options) {
|
|
13
|
+
this.http = new http_1.HttpTransport(options);
|
|
14
|
+
this.permits = new permits_1.PermitsClient(this.http);
|
|
15
|
+
this.executions = new executions_1.ExecutionsClient(this.http);
|
|
16
|
+
this.execute = new execute_1.ExecuteClient(this.http);
|
|
17
|
+
this.proxy = new proxy_1.ProxyClient(this.http);
|
|
18
|
+
this.jobs = new jobs_1.JobsClient(this.http);
|
|
19
|
+
this.requests = new requests_1.RequestsClient(this.http);
|
|
20
|
+
}
|
|
21
|
+
async createPermit(request) {
|
|
22
|
+
return this.permits.create(request);
|
|
23
|
+
}
|
|
24
|
+
async createPermitWithMeta(request) {
|
|
25
|
+
return this.permits.createWithMeta(request);
|
|
26
|
+
}
|
|
27
|
+
async createApiKey() {
|
|
28
|
+
const { payload, request_id } = await this.http.postWithMeta("/v1/api-keys");
|
|
29
|
+
return { ...payload, request_id };
|
|
30
|
+
}
|
|
31
|
+
async listApiKeys() {
|
|
32
|
+
const { payload, request_id } = await this.http.getWithMeta("/v1/api-keys");
|
|
33
|
+
return { ...payload, request_id };
|
|
34
|
+
}
|
|
35
|
+
async revokeApiKey(keyId) {
|
|
36
|
+
if (!keyId || !keyId.trim()) {
|
|
37
|
+
throw new Error("keyId is required");
|
|
38
|
+
}
|
|
39
|
+
await this.http.delete(`/v1/api-keys/${encodeURIComponent(keyId)}`);
|
|
40
|
+
}
|
|
41
|
+
async getHealth() {
|
|
42
|
+
return this.http.get("/health");
|
|
43
|
+
}
|
|
44
|
+
async getAuthedHealth() {
|
|
45
|
+
return this.http.get("/v1/health");
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
exports.KeelClient = KeelClient;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { HttpTransport } from "../http";
|
|
2
|
+
import type { ExecuteRequest, ExecutionResponse, RoutingProvider } from "../types";
|
|
3
|
+
export declare class ExecuteClient {
|
|
4
|
+
private readonly http;
|
|
5
|
+
constructor(http: HttpTransport);
|
|
6
|
+
run(request: ExecuteRequest): Promise<ExecutionResponse>;
|
|
7
|
+
run(model: string, input: Record<string, unknown>, provider?: RoutingProvider): Promise<ExecutionResponse>;
|
|
8
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ExecuteClient = void 0;
|
|
4
|
+
class ExecuteClient {
|
|
5
|
+
constructor(http) {
|
|
6
|
+
this.http = http;
|
|
7
|
+
}
|
|
8
|
+
async run(requestOrModel, input, provider) {
|
|
9
|
+
const body = typeof requestOrModel === "string"
|
|
10
|
+
? { model: requestOrModel, input: input, provider }
|
|
11
|
+
: requestOrModel;
|
|
12
|
+
return this.http.post("/v1/execute", body);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
exports.ExecuteClient = ExecuteClient;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { HttpTransport } from "../http";
|
|
2
|
+
import type { ExecutionCreateRequest, ExecutionResponse, ExecutionStreamEvent, ExecutionTimelineResponse } from "../types";
|
|
3
|
+
export declare class ExecutionsClient {
|
|
4
|
+
private readonly http;
|
|
5
|
+
constructor(http: HttpTransport);
|
|
6
|
+
create(request: ExecutionCreateRequest): Promise<ExecutionResponse>;
|
|
7
|
+
stream(request: ExecutionCreateRequest): Promise<AsyncGenerator<ExecutionStreamEvent>>;
|
|
8
|
+
get(requestId: string): Promise<ExecutionTimelineResponse>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ExecutionsClient = void 0;
|
|
4
|
+
const streaming_1 = require("../streaming");
|
|
5
|
+
class ExecutionsClient {
|
|
6
|
+
constructor(http) {
|
|
7
|
+
this.http = http;
|
|
8
|
+
}
|
|
9
|
+
async create(request) {
|
|
10
|
+
const body = { ...request, mode: "sync" };
|
|
11
|
+
return this.http.post("/v1/executions", body);
|
|
12
|
+
}
|
|
13
|
+
async stream(request) {
|
|
14
|
+
const body = { ...request, mode: "stream" };
|
|
15
|
+
const response = await this.http.postStream("/v1/executions", body);
|
|
16
|
+
return (0, streaming_1.parseSSEStream)(response);
|
|
17
|
+
}
|
|
18
|
+
async get(requestId) {
|
|
19
|
+
return this.http.get(`/v1/executions/${encodeURIComponent(requestId)}`);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
exports.ExecutionsClient = ExecutionsClient;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { HttpTransport } from "../http";
|
|
2
|
+
import type { JobCreateResponse, JobStatusResponse, JobSubmitRequest } from "../types";
|
|
3
|
+
export declare class JobsClient {
|
|
4
|
+
private readonly http;
|
|
5
|
+
constructor(http: HttpTransport);
|
|
6
|
+
create(request: JobSubmitRequest): Promise<JobCreateResponse>;
|
|
7
|
+
get(jobId: string): Promise<JobStatusResponse>;
|
|
8
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.JobsClient = void 0;
|
|
4
|
+
class JobsClient {
|
|
5
|
+
constructor(http) {
|
|
6
|
+
this.http = http;
|
|
7
|
+
}
|
|
8
|
+
async create(request) {
|
|
9
|
+
return this.http.post("/v1/jobs", request);
|
|
10
|
+
}
|
|
11
|
+
async get(jobId) {
|
|
12
|
+
return this.http.get(`/v1/jobs/${encodeURIComponent(jobId)}`);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
exports.JobsClient = JobsClient;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { HttpTransport } from "../http";
|
|
2
|
+
import type { PermitAttestationRequest, PermitAuditBundle, PermitAuditItem, PermitAuditListResponse, PermitDryRunResponse, PermitEvidenceCreateRequest, PermitEvidenceListResponse, PermitEvidenceOut, PermitExportFormat, PermitLineageResponse, PermitListParams, PermitRequest, PermitResponse, PermitUsageReportRequest, PermitUsageReportResponse, PermitWithMetaResponse } from "../types";
|
|
3
|
+
export declare class PermitsClient {
|
|
4
|
+
private readonly http;
|
|
5
|
+
constructor(http: HttpTransport);
|
|
6
|
+
create(request: PermitRequest): Promise<PermitResponse>;
|
|
7
|
+
createWithMeta(request: PermitRequest): Promise<PermitWithMetaResponse>;
|
|
8
|
+
dryRun(request: PermitRequest): Promise<PermitDryRunResponse>;
|
|
9
|
+
list(params?: PermitListParams): Promise<PermitAuditListResponse>;
|
|
10
|
+
get(permitId: string): Promise<PermitAuditItem>;
|
|
11
|
+
export(from: string, to: string, format?: PermitExportFormat): Promise<unknown>;
|
|
12
|
+
reportUsage(permitId: string, request: PermitUsageReportRequest): Promise<PermitUsageReportResponse>;
|
|
13
|
+
attest(permitId: string, request: PermitAttestationRequest): Promise<PermitResponse>;
|
|
14
|
+
addEvidence(permitId: string, request: PermitEvidenceCreateRequest): Promise<PermitEvidenceOut>;
|
|
15
|
+
listEvidence(permitId: string): Promise<PermitEvidenceListResponse>;
|
|
16
|
+
lineage(permitId: string): Promise<PermitLineageResponse>;
|
|
17
|
+
bundle(permitId: string): Promise<PermitAuditBundle>;
|
|
18
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PermitsClient = void 0;
|
|
4
|
+
class PermitsClient {
|
|
5
|
+
constructor(http) {
|
|
6
|
+
this.http = http;
|
|
7
|
+
}
|
|
8
|
+
async create(request) {
|
|
9
|
+
return this.http.post("/v1/permits", request);
|
|
10
|
+
}
|
|
11
|
+
async createWithMeta(request) {
|
|
12
|
+
const { payload, request_id } = await this.http.postWithMeta("/v1/permits", request);
|
|
13
|
+
return { permit: payload, request_id };
|
|
14
|
+
}
|
|
15
|
+
async dryRun(request) {
|
|
16
|
+
return this.http.post("/v1/permits/dry-run", request);
|
|
17
|
+
}
|
|
18
|
+
async list(params) {
|
|
19
|
+
const query = {};
|
|
20
|
+
if (params) {
|
|
21
|
+
if (params.limit !== undefined)
|
|
22
|
+
query.limit = String(params.limit);
|
|
23
|
+
if (params.project_id)
|
|
24
|
+
query.project_id = params.project_id;
|
|
25
|
+
if (params.before)
|
|
26
|
+
query.before = params.before;
|
|
27
|
+
if (params.subject_id)
|
|
28
|
+
query.subject_id = params.subject_id;
|
|
29
|
+
if (params.subject_type)
|
|
30
|
+
query.subject_type = params.subject_type;
|
|
31
|
+
if (params.action_name)
|
|
32
|
+
query.action_name = params.action_name;
|
|
33
|
+
if (params.start_date)
|
|
34
|
+
query.start_date = params.start_date;
|
|
35
|
+
if (params.end_date)
|
|
36
|
+
query.end_date = params.end_date;
|
|
37
|
+
if (params.decision)
|
|
38
|
+
query.decision = params.decision;
|
|
39
|
+
}
|
|
40
|
+
return this.http.get("/v1/permits", query);
|
|
41
|
+
}
|
|
42
|
+
async get(permitId) {
|
|
43
|
+
return this.http.get(`/v1/permits/${encodeURIComponent(permitId)}`);
|
|
44
|
+
}
|
|
45
|
+
async export(from, to, format = "json") {
|
|
46
|
+
const query = { from, to, format };
|
|
47
|
+
if (format === "csv") {
|
|
48
|
+
const response = await this.http.getRaw("/v1/permits/export", query);
|
|
49
|
+
return response.text();
|
|
50
|
+
}
|
|
51
|
+
return this.http.get("/v1/permits/export", query);
|
|
52
|
+
}
|
|
53
|
+
async reportUsage(permitId, request) {
|
|
54
|
+
return this.http.post(`/v1/permits/${encodeURIComponent(permitId)}/usage`, request);
|
|
55
|
+
}
|
|
56
|
+
async attest(permitId, request) {
|
|
57
|
+
return this.http.post(`/v1/permits/${encodeURIComponent(permitId)}/attest`, request);
|
|
58
|
+
}
|
|
59
|
+
async addEvidence(permitId, request) {
|
|
60
|
+
return this.http.post(`/v1/permits/${encodeURIComponent(permitId)}/evidence`, request);
|
|
61
|
+
}
|
|
62
|
+
async listEvidence(permitId) {
|
|
63
|
+
return this.http.get(`/v1/permits/${encodeURIComponent(permitId)}/evidence`);
|
|
64
|
+
}
|
|
65
|
+
async lineage(permitId) {
|
|
66
|
+
return this.http.get(`/v1/permits/${encodeURIComponent(permitId)}/lineage`);
|
|
67
|
+
}
|
|
68
|
+
async bundle(permitId) {
|
|
69
|
+
return this.http.get(`/v1/permits/${encodeURIComponent(permitId)}/bundle`);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
exports.PermitsClient = PermitsClient;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { HttpTransport } from "../http";
|
|
2
|
+
export declare class ProxyClient {
|
|
3
|
+
private readonly http;
|
|
4
|
+
constructor(http: HttpTransport);
|
|
5
|
+
openai<T = unknown>(payload: Record<string, unknown>): Promise<T>;
|
|
6
|
+
anthropic<T = unknown>(payload: Record<string, unknown>): Promise<T>;
|
|
7
|
+
google<T = unknown>(payload: Record<string, unknown>): Promise<T>;
|
|
8
|
+
xai<T = unknown>(payload: Record<string, unknown>): Promise<T>;
|
|
9
|
+
meta<T = unknown>(payload: Record<string, unknown>): Promise<T>;
|
|
10
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ProxyClient = void 0;
|
|
4
|
+
class ProxyClient {
|
|
5
|
+
constructor(http) {
|
|
6
|
+
this.http = http;
|
|
7
|
+
}
|
|
8
|
+
async openai(payload) {
|
|
9
|
+
return this.http.post("/v1/proxy/openai", payload);
|
|
10
|
+
}
|
|
11
|
+
async anthropic(payload) {
|
|
12
|
+
return this.http.post("/v1/proxy/anthropic", payload);
|
|
13
|
+
}
|
|
14
|
+
async google(payload) {
|
|
15
|
+
return this.http.post("/v1/proxy/google", payload);
|
|
16
|
+
}
|
|
17
|
+
async xai(payload) {
|
|
18
|
+
return this.http.post("/v1/proxy/xai", payload);
|
|
19
|
+
}
|
|
20
|
+
async meta(payload) {
|
|
21
|
+
return this.http.post("/v1/proxy/meta", payload);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
exports.ProxyClient = ProxyClient;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { HttpTransport } from "../http";
|
|
2
|
+
import type { RequestTimelineResponse } from "../types";
|
|
3
|
+
export declare class RequestsClient {
|
|
4
|
+
private readonly http;
|
|
5
|
+
constructor(http: HttpTransport);
|
|
6
|
+
timeline(requestId: string): Promise<RequestTimelineResponse>;
|
|
7
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RequestsClient = void 0;
|
|
4
|
+
class RequestsClient {
|
|
5
|
+
constructor(http) {
|
|
6
|
+
this.http = http;
|
|
7
|
+
}
|
|
8
|
+
async timeline(requestId) {
|
|
9
|
+
return this.http.get(`/v1/requests/${encodeURIComponent(requestId)}/timeline`);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
exports.RequestsClient = RequestsClient;
|