@introspection-sdk/introspection-browser 0.5.5 → 0.5.6
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/.turbo/turbo-build.log +1 -1
- package/README.md +39 -46
- package/dist/api/client.d.ts +15 -27
- package/dist/api/client.d.ts.map +1 -1
- package/dist/api/client.js +30 -73
- package/dist/api/client.js.map +1 -1
- package/dist/api/http.d.ts +0 -23
- package/dist/api/http.d.ts.map +1 -1
- package/dist/api/http.js +0 -38
- package/dist/api/http.js.map +1 -1
- package/dist/api/index.d.ts +18 -12
- package/dist/api/index.d.ts.map +1 -1
- package/dist/api/index.js +17 -11
- package/dist/api/index.js.map +1 -1
- package/package.json +3 -3
- package/src/api/client.ts +34 -106
- package/src/api/http.ts +0 -56
- package/src/api/index.ts +17 -38
- package/dist/api/runner.d.ts +0 -45
- package/dist/api/runner.d.ts.map +0 -1
- package/dist/api/runner.js +0 -87
- package/dist/api/runner.js.map +0 -1
- package/dist/api/runtimes.d.ts +0 -12
- package/dist/api/runtimes.d.ts.map +0 -1
- package/dist/api/runtimes.js +0 -14
- package/dist/api/runtimes.js.map +0 -1
- package/src/api/runner.ts +0 -127
- package/src/api/runtimes.ts +0 -32
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@introspection-sdk/introspection-browser",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.6",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"description": "Introspection observability SDK for the browser",
|
|
6
6
|
"engines": {
|
|
@@ -31,8 +31,8 @@
|
|
|
31
31
|
"@opentelemetry/api-logs": "^0.219.0",
|
|
32
32
|
"@opentelemetry/sdk-logs": "^0.219.0",
|
|
33
33
|
"@opentelemetry/exporter-logs-otlp-http": "^0.219.0",
|
|
34
|
-
"@introspection-sdk/types": "0.5.
|
|
35
|
-
"@introspection-sdk/http": "0.5.
|
|
34
|
+
"@introspection-sdk/types": "0.5.6",
|
|
35
|
+
"@introspection-sdk/http": "0.5.6"
|
|
36
36
|
},
|
|
37
37
|
"scripts": {
|
|
38
38
|
"lint": "eslint . --max-warnings 0",
|
package/src/api/client.ts
CHANGED
|
@@ -2,42 +2,35 @@
|
|
|
2
2
|
* Browser-side Introspection API client.
|
|
3
3
|
*
|
|
4
4
|
* Lets a single-page app create and stream Introspection tasks directly
|
|
5
|
-
* from the browser, with no API key in JavaScript. The
|
|
5
|
+
* from the browser, with no API key in JavaScript. The browser talks only
|
|
6
|
+
* to the Data Plane — runtime resolution and any other Control Plane work
|
|
7
|
+
* stays on the app's backend, so the CP never needs to serve CORS to
|
|
8
|
+
* customer web origins. The auth boundary:
|
|
6
9
|
*
|
|
7
|
-
* 1. The SPA's own backend ("broker") mints
|
|
8
|
-
* token — via RFC 8693 token-exchange of the partner IdP
|
|
9
|
-
* PKCE `authorization_code`, or `client_credentials
|
|
10
|
-
* secret never leaves the backend
|
|
11
|
-
*
|
|
10
|
+
* 1. The SPA's own backend ("broker") mints a short-lived Introspection
|
|
11
|
+
* access token — via RFC 8693 token-exchange of the partner IdP
|
|
12
|
+
* token, a PKCE `authorization_code`, or `client_credentials` (the
|
|
13
|
+
* IdP secret never leaves the backend) — and, when a specific runtime
|
|
14
|
+
* is needed, resolves its `runtime_id` server-side. The SPA fetches
|
|
15
|
+
* the token through the `getToken` callback.
|
|
12
16
|
* 2. `connect()` redeems the token at the DP `POST /v1/oauth/exchange`
|
|
13
17
|
* for the HttpOnly `intro_dp_session` cookie.
|
|
14
18
|
* 3. Every subsequent call rides that cookie (`credentials: "include"`)
|
|
15
|
-
* — `client.tasks.start(
|
|
19
|
+
* — `client.tasks.start({ runtime_id })`, `.get(...)`, run streaming,
|
|
20
|
+
* etc.
|
|
16
21
|
*
|
|
17
22
|
* When the session cookie expires, an in-flight request gets a 401, and
|
|
18
23
|
* the client transparently re-runs `getToken` + the DP exchange once
|
|
19
24
|
* before retrying.
|
|
20
25
|
*/
|
|
21
26
|
|
|
22
|
-
import {
|
|
23
|
-
BrowserBearerHttpClient,
|
|
24
|
-
BrowserHttpClient,
|
|
25
|
-
stripTrailingSlash,
|
|
26
|
-
toApiError,
|
|
27
|
-
} from "./http.js";
|
|
27
|
+
import { BrowserHttpClient, stripTrailingSlash, toApiError } from "./http.js";
|
|
28
28
|
import {
|
|
29
29
|
ConversationsClient,
|
|
30
30
|
FilesClient,
|
|
31
31
|
SharesClient,
|
|
32
32
|
} from "@introspection-sdk/http";
|
|
33
33
|
import { TasksClient } from "./tasks.js";
|
|
34
|
-
import {
|
|
35
|
-
attachBrowserRuntimes,
|
|
36
|
-
type BrowserRuntimeHandleFactory,
|
|
37
|
-
type BrowserRuntimesClient,
|
|
38
|
-
} from "./runtimes.js";
|
|
39
|
-
import type { BrowserRunnerSource } from "./runner.js";
|
|
40
|
-
import type { RunnerSpec } from "@introspection-sdk/types";
|
|
41
34
|
|
|
42
35
|
type CookieClients = {
|
|
43
36
|
tasks: TasksClient;
|
|
@@ -47,19 +40,12 @@ type CookieClients = {
|
|
|
47
40
|
};
|
|
48
41
|
|
|
49
42
|
export interface IntrospectionApiClientOptions {
|
|
50
|
-
/**
|
|
51
|
-
* Control Plane REST base URL. Used by `client.runtimes(name).run()` to
|
|
52
|
-
* resolve runtimes and mint runner specs. Defaults to
|
|
53
|
-
* `https://api.introspection.dev`.
|
|
54
|
-
*/
|
|
55
|
-
cpUrl?: string;
|
|
56
43
|
/**
|
|
57
44
|
* Data Plane REST base URL for the cookie-session APIs (`connect()` and
|
|
58
|
-
*
|
|
59
|
-
* `client.shares`).
|
|
60
|
-
* not require this option.
|
|
45
|
+
* `client.tasks` / `client.files` / `client.conversations` /
|
|
46
|
+
* `client.shares`). Required — the browser only talks to the DP.
|
|
61
47
|
*/
|
|
62
|
-
dpUrl
|
|
48
|
+
dpUrl: string;
|
|
63
49
|
/**
|
|
64
50
|
* Returns a fresh Introspection access token from the app's broker
|
|
65
51
|
* (its own backend). Called on `connect()` and again whenever the DP
|
|
@@ -75,15 +61,8 @@ export interface IntrospectionApiClientOptions {
|
|
|
75
61
|
}
|
|
76
62
|
|
|
77
63
|
export class IntrospectionApiClient {
|
|
78
|
-
/**
|
|
79
|
-
* CRUD on CP `/v1/runtimes` and the `(idOrName) => RuntimeHandle` factory.
|
|
80
|
-
* Call as `client.runtimes("customer-agent").run()`.
|
|
81
|
-
*/
|
|
82
|
-
readonly runtimes: BrowserRuntimesClient & BrowserRuntimeHandleFactory;
|
|
83
|
-
|
|
84
64
|
private readonly fetchImpl: typeof fetch;
|
|
85
|
-
private readonly
|
|
86
|
-
private readonly cookieClients: CookieClients | null;
|
|
65
|
+
private readonly cookieClients: CookieClients;
|
|
87
66
|
|
|
88
67
|
constructor(private readonly opts: IntrospectionApiClientOptions) {
|
|
89
68
|
this.fetchImpl = opts.fetch ?? globalThis.fetch;
|
|
@@ -92,53 +71,41 @@ export class IntrospectionApiClient {
|
|
|
92
71
|
"global fetch is unavailable; pass `fetch` or run in a modern browser",
|
|
93
72
|
);
|
|
94
73
|
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
});
|
|
101
|
-
this.runtimes = attachBrowserRuntimes(this.cpHttp, {
|
|
74
|
+
if (!opts.dpUrl) {
|
|
75
|
+
throw new Error("IntrospectionApiClient requires a dpUrl");
|
|
76
|
+
}
|
|
77
|
+
const http = new BrowserHttpClient({
|
|
78
|
+
apiUrl: opts.dpUrl,
|
|
102
79
|
additionalHeaders: opts.additionalHeaders,
|
|
103
80
|
fetch: opts.fetch,
|
|
104
|
-
|
|
81
|
+
onUnauthorized: () => this.reexchange(),
|
|
105
82
|
});
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
});
|
|
113
|
-
this.cookieClients = {
|
|
114
|
-
tasks: new TasksClient(http),
|
|
115
|
-
files: new FilesClient(http),
|
|
116
|
-
conversations: new ConversationsClient(http),
|
|
117
|
-
shares: new SharesClient(http),
|
|
118
|
-
};
|
|
119
|
-
} else {
|
|
120
|
-
this.cookieClients = null;
|
|
121
|
-
}
|
|
83
|
+
this.cookieClients = {
|
|
84
|
+
tasks: new TasksClient(http),
|
|
85
|
+
files: new FilesClient(http),
|
|
86
|
+
conversations: new ConversationsClient(http),
|
|
87
|
+
shares: new SharesClient(http),
|
|
88
|
+
};
|
|
122
89
|
}
|
|
123
90
|
|
|
124
91
|
/** `/v1/tasks` operations bound to the DP session cookie. */
|
|
125
92
|
get tasks(): TasksClient {
|
|
126
|
-
return this.
|
|
93
|
+
return this.cookieClients.tasks;
|
|
127
94
|
}
|
|
128
95
|
|
|
129
96
|
/** `/v1/files` operations bound to the DP session cookie. */
|
|
130
97
|
get files(): FilesClient {
|
|
131
|
-
return this.
|
|
98
|
+
return this.cookieClients.files;
|
|
132
99
|
}
|
|
133
100
|
|
|
134
101
|
/** Read-only `/v1/conversations` projection bound to the session cookie. */
|
|
135
102
|
get conversations(): ConversationsClient {
|
|
136
|
-
return this.
|
|
103
|
+
return this.cookieClients.conversations;
|
|
137
104
|
}
|
|
138
105
|
|
|
139
106
|
/** `/v1/shares` read-sharing grants bound to the session cookie. */
|
|
140
107
|
get shares(): SharesClient {
|
|
141
|
-
return this.
|
|
108
|
+
return this.cookieClients.shares;
|
|
142
109
|
}
|
|
143
110
|
|
|
144
111
|
/**
|
|
@@ -146,15 +113,13 @@ export class IntrospectionApiClient {
|
|
|
146
113
|
* `intro_dp_session` cookie. Call once before issuing task requests.
|
|
147
114
|
*/
|
|
148
115
|
async connect(): Promise<void> {
|
|
149
|
-
this.requireDpUrl();
|
|
150
116
|
await this.exchange();
|
|
151
117
|
}
|
|
152
118
|
|
|
153
119
|
private async exchange(): Promise<void> {
|
|
154
|
-
const dpUrl = this.requireDpUrl();
|
|
155
120
|
const token = await this.opts.getToken();
|
|
156
121
|
const res = await this.fetchImpl(
|
|
157
|
-
`${stripTrailingSlash(dpUrl)}/v1/oauth/exchange`,
|
|
122
|
+
`${stripTrailingSlash(this.opts.dpUrl)}/v1/oauth/exchange`,
|
|
158
123
|
{
|
|
159
124
|
method: "POST",
|
|
160
125
|
headers: {
|
|
@@ -177,41 +142,4 @@ export class IntrospectionApiClient {
|
|
|
177
142
|
return false;
|
|
178
143
|
}
|
|
179
144
|
}
|
|
180
|
-
|
|
181
|
-
private requireCookieClient<K extends keyof CookieClients>(
|
|
182
|
-
key: K,
|
|
183
|
-
): CookieClients[K] {
|
|
184
|
-
if (!this.cookieClients) {
|
|
185
|
-
throw new Error(
|
|
186
|
-
`IntrospectionApiClient.${key} requires dpUrl; use client.runtimes(...).run() for runner-bound APIs or pass dpUrl for cookie-session APIs`,
|
|
187
|
-
);
|
|
188
|
-
}
|
|
189
|
-
return this.cookieClients[key];
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
private requireDpUrl(): string {
|
|
193
|
-
if (!this.opts.dpUrl) {
|
|
194
|
-
throw new Error(
|
|
195
|
-
"IntrospectionApiClient.connect() requires dpUrl; use client.runtimes(...).run() for runner-bound APIs or pass dpUrl for cookie-session APIs",
|
|
196
|
-
);
|
|
197
|
-
}
|
|
198
|
-
return this.opts.dpUrl;
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
private async requestFreshRunnerSpec(
|
|
202
|
-
source: BrowserRunnerSource,
|
|
203
|
-
): Promise<RunnerSpec> {
|
|
204
|
-
if (source.kind === "runtime") {
|
|
205
|
-
return this.cpHttp.request<RunnerSpec>({
|
|
206
|
-
method: "POST",
|
|
207
|
-
path: `/v1/runtimes/${encodeURIComponent(source.id)}/run`,
|
|
208
|
-
body: source.options ?? {},
|
|
209
|
-
});
|
|
210
|
-
}
|
|
211
|
-
return this.cpHttp.request<RunnerSpec>({
|
|
212
|
-
method: "POST",
|
|
213
|
-
path: `/v1/experiments/${encodeURIComponent(source.id)}/run`,
|
|
214
|
-
body: source.options ?? {},
|
|
215
|
-
});
|
|
216
|
-
}
|
|
217
145
|
}
|
package/src/api/http.ts
CHANGED
|
@@ -35,8 +35,6 @@ export interface BrowserHttpConfig {
|
|
|
35
35
|
onUnauthorized?: () => Promise<boolean>;
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
export type BrowserApiHttpClient = Pick<BaseHttpClient, "request" | "stream">;
|
|
39
|
-
|
|
40
38
|
/**
|
|
41
39
|
* Cookie-authenticated HTTP wrapper bound to one DP endpoint. Has no
|
|
42
40
|
* opinion about which resource it serves — the caller picks the path.
|
|
@@ -55,57 +53,3 @@ export class BrowserHttpClient extends BaseHttpClient {
|
|
|
55
53
|
});
|
|
56
54
|
}
|
|
57
55
|
}
|
|
58
|
-
|
|
59
|
-
export interface BrowserBearerHttpConfig {
|
|
60
|
-
/** REST base URL every request is prefixed with. */
|
|
61
|
-
apiUrl: string;
|
|
62
|
-
/** Bearer token, or a provider returning the latest token before each request. */
|
|
63
|
-
token: string | (() => string | Promise<string>);
|
|
64
|
-
/** Extra headers merged into every request. */
|
|
65
|
-
additionalHeaders?: Record<string, string>;
|
|
66
|
-
/** Custom `fetch` (for tests or non-standard runtimes). */
|
|
67
|
-
fetch?: typeof fetch;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* Bearer-authenticated browser HTTP wrapper. Used for CP runtime calls with
|
|
72
|
-
* brokered access tokens and for DP runner calls with CP-minted runner tokens.
|
|
73
|
-
*/
|
|
74
|
-
export class BrowserBearerHttpClient extends BaseHttpClient {
|
|
75
|
-
private readonly tokenBox: { value: string };
|
|
76
|
-
private readonly getToken?: () => string | Promise<string>;
|
|
77
|
-
|
|
78
|
-
constructor(cfg: BrowserBearerHttpConfig) {
|
|
79
|
-
const tokenBox = { value: typeof cfg.token === "string" ? cfg.token : "" };
|
|
80
|
-
super({
|
|
81
|
-
apiUrl: cfg.apiUrl,
|
|
82
|
-
additionalHeaders: cfg.additionalHeaders,
|
|
83
|
-
fetch: cfg.fetch,
|
|
84
|
-
transport: {
|
|
85
|
-
authHeaders: (): Record<string, string> => {
|
|
86
|
-
if (!tokenBox.value) return {};
|
|
87
|
-
return { Authorization: `Bearer ${tokenBox.value}` };
|
|
88
|
-
},
|
|
89
|
-
},
|
|
90
|
-
});
|
|
91
|
-
this.tokenBox = tokenBox;
|
|
92
|
-
this.getToken = typeof cfg.token === "function" ? cfg.token : undefined;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
private async refreshToken(): Promise<void> {
|
|
96
|
-
if (!this.getToken) return;
|
|
97
|
-
this.tokenBox.value = await this.getToken();
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
async request<T>(opts: Parameters<BaseHttpClient["request"]>[0]): Promise<T> {
|
|
101
|
-
await this.refreshToken();
|
|
102
|
-
return super.request<T>(opts);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
async stream(
|
|
106
|
-
opts: Parameters<BaseHttpClient["stream"]>[0],
|
|
107
|
-
): Promise<Response> {
|
|
108
|
-
await this.refreshToken();
|
|
109
|
-
return super.stream(opts);
|
|
110
|
-
}
|
|
111
|
-
}
|
package/src/api/index.ts
CHANGED
|
@@ -6,22 +6,30 @@
|
|
|
6
6
|
* Separate from the package's default telemetry export so apps only pull
|
|
7
7
|
* in what they use.
|
|
8
8
|
*
|
|
9
|
+
* The browser talks only to the Data Plane. Resolving a runtime by name
|
|
10
|
+
* (a Control Plane call) stays on your backend, which hands the browser a
|
|
11
|
+
* short-lived access token plus the resolved `runtime_id`.
|
|
12
|
+
*
|
|
9
13
|
* @example
|
|
10
14
|
* ```typescript
|
|
11
15
|
* import { IntrospectionApiClient } from "@introspection-sdk/introspection-browser/api";
|
|
12
16
|
*
|
|
17
|
+
* // Your backend returns { token, runtimeId, dpUrl } — it mints the access
|
|
18
|
+
* // token, resolves the runtime id, and surfaces the DP URL (e.g. from the
|
|
19
|
+
* // Node SDK's serviceAccountToken response), so the browser never calls the CP.
|
|
20
|
+
* const { token, runtimeId, dpUrl } = await fetch(
|
|
21
|
+
* "/api/introspection/session",
|
|
22
|
+
* ).then((r) => r.json());
|
|
23
|
+
*
|
|
13
24
|
* const client = new IntrospectionApiClient({
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
* // project is derived from its claims — no projectId option needed)
|
|
17
|
-
* getToken: () => fetch("/api/introspection/token").then((r) => r.text()),
|
|
25
|
+
* dpUrl,
|
|
26
|
+
* getToken: () => token,
|
|
18
27
|
* });
|
|
19
28
|
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
* });
|
|
23
|
-
* const run = await runner.tasks.start({
|
|
29
|
+
* await client.connect(); // -> intro_dp_session cookie
|
|
30
|
+
* const run = await client.tasks.start({
|
|
24
31
|
* prompt: "Summarize my latest order",
|
|
32
|
+
* runtime_id: runtimeId,
|
|
25
33
|
* });
|
|
26
34
|
* for await (const ev of run.stream()) console.log(ev.event, ev.data);
|
|
27
35
|
* ```
|
|
@@ -31,20 +39,6 @@ export {
|
|
|
31
39
|
IntrospectionApiClient,
|
|
32
40
|
type IntrospectionApiClientOptions,
|
|
33
41
|
} from "./client.js";
|
|
34
|
-
export {
|
|
35
|
-
BrowserRunner,
|
|
36
|
-
Runner,
|
|
37
|
-
type BrowserRunnerOwner,
|
|
38
|
-
type BrowserRunnerSource,
|
|
39
|
-
} from "./runner.js";
|
|
40
|
-
export {
|
|
41
|
-
BrowserRuntimesClient,
|
|
42
|
-
BrowserRuntimeHandle,
|
|
43
|
-
attachBrowserRuntimes,
|
|
44
|
-
isUuid,
|
|
45
|
-
type BrowserRuntimeHandleFactory,
|
|
46
|
-
type BrowserRuntimeRunRequestBody,
|
|
47
|
-
} from "./runtimes.js";
|
|
48
42
|
export {
|
|
49
43
|
TasksClient,
|
|
50
44
|
TaskRunsClient,
|
|
@@ -60,13 +54,7 @@ export {
|
|
|
60
54
|
SharesClient,
|
|
61
55
|
type FileUploadBody,
|
|
62
56
|
} from "@introspection-sdk/http";
|
|
63
|
-
export {
|
|
64
|
-
BrowserBearerHttpClient,
|
|
65
|
-
BrowserHttpClient,
|
|
66
|
-
type BrowserApiHttpClient,
|
|
67
|
-
type BrowserBearerHttpConfig,
|
|
68
|
-
type BrowserHttpConfig,
|
|
69
|
-
} from "./http.js";
|
|
57
|
+
export { BrowserHttpClient, type BrowserHttpConfig } from "./http.js";
|
|
70
58
|
export { parseSse } from "./sse.js";
|
|
71
59
|
export {
|
|
72
60
|
Paginator,
|
|
@@ -104,15 +92,6 @@ export type {
|
|
|
104
92
|
ShareResourceType,
|
|
105
93
|
ShareCreateParams,
|
|
106
94
|
ShareListParams,
|
|
107
|
-
Recipe,
|
|
108
|
-
RunRequest,
|
|
109
|
-
RunnerContext,
|
|
110
|
-
RunnerDeployment,
|
|
111
|
-
RunnerSpec,
|
|
112
|
-
Runtime,
|
|
113
|
-
RuntimeCreate,
|
|
114
|
-
RuntimeListParams,
|
|
115
|
-
RuntimeUpdate,
|
|
116
95
|
} from "@introspection-sdk/types";
|
|
117
96
|
export {
|
|
118
97
|
IntrospectionAPIError,
|
package/dist/api/runner.d.ts
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { type RunnerContext, type RunnerDeployment, type RunnerSpec, type RunRequest, type Uuid } from "@introspection-sdk/types";
|
|
2
|
-
import { ConversationsClient, FilesClient, SharesClient, TasksClient } from "@introspection-sdk/http";
|
|
3
|
-
export type BrowserRunnerSource = {
|
|
4
|
-
kind: "runtime";
|
|
5
|
-
id: Uuid;
|
|
6
|
-
options?: RunRequest;
|
|
7
|
-
} | {
|
|
8
|
-
kind: "experiment";
|
|
9
|
-
id: Uuid;
|
|
10
|
-
options?: RunRequest;
|
|
11
|
-
};
|
|
12
|
-
export interface BrowserRunnerOwner {
|
|
13
|
-
readonly additionalHeaders?: Record<string, string>;
|
|
14
|
-
readonly fetch?: typeof fetch;
|
|
15
|
-
requestFreshRunnerSpec(source: BrowserRunnerSource): Promise<RunnerSpec>;
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* Browser-side live handle to a Data Plane runner. Mirrors the Node Runner
|
|
19
|
-
* shape but uses browser-safe fetch transport and CP-minted bearer tokens.
|
|
20
|
-
*/
|
|
21
|
-
export declare class BrowserRunner {
|
|
22
|
-
private readonly owner;
|
|
23
|
-
private readonly source;
|
|
24
|
-
private spec;
|
|
25
|
-
private http;
|
|
26
|
-
private closed;
|
|
27
|
-
readonly tasks: TasksClient;
|
|
28
|
-
readonly files: FilesClient;
|
|
29
|
-
readonly conversations: ConversationsClient;
|
|
30
|
-
readonly shares: SharesClient;
|
|
31
|
-
constructor(owner: BrowserRunnerOwner, source: BrowserRunnerSource, spec: RunnerSpec);
|
|
32
|
-
get dpEndpoint(): string;
|
|
33
|
-
get deployment(): Readonly<RunnerDeployment>;
|
|
34
|
-
get expires_at(): string;
|
|
35
|
-
get session_id(): string;
|
|
36
|
-
get context(): Readonly<RunnerContext>;
|
|
37
|
-
get isClosed(): boolean;
|
|
38
|
-
refresh(): Promise<void>;
|
|
39
|
-
close(): Promise<void>;
|
|
40
|
-
private buildHttp;
|
|
41
|
-
private guardedHttp;
|
|
42
|
-
private assertOpen;
|
|
43
|
-
}
|
|
44
|
-
export { BrowserRunner as Runner };
|
|
45
|
-
//# sourceMappingURL=runner.d.ts.map
|
package/dist/api/runner.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"runner.d.ts","sourceRoot":"","sources":["../../src/api/runner.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,aAAa,EAClB,KAAK,gBAAgB,EACrB,KAAK,UAAU,EACf,KAAK,UAAU,EACf,KAAK,IAAI,EACV,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACL,mBAAmB,EACnB,WAAW,EACX,YAAY,EACZ,WAAW,EACZ,MAAM,yBAAyB,CAAC;AAGjC,MAAM,MAAM,mBAAmB,GAC3B;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,EAAE,EAAE,IAAI,CAAC;IAAC,OAAO,CAAC,EAAE,UAAU,CA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BnB,OAAO,CAAC,UAAU;CASnB;AAED,OAAO,EAAE,aAAa,IAAI,MAAM,EAAE,CAAC"}
|
package/dist/api/runner.js
DELETED
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
import { RunnerExpiredError, } from "@introspection-sdk/types";
|
|
2
|
-
import { ConversationsClient, FilesClient, SharesClient, TasksClient, } from "@introspection-sdk/http";
|
|
3
|
-
import { BrowserBearerHttpClient } from "./http.js";
|
|
4
|
-
/**
|
|
5
|
-
* Browser-side live handle to a Data Plane runner. Mirrors the Node Runner
|
|
6
|
-
* shape but uses browser-safe fetch transport and CP-minted bearer tokens.
|
|
7
|
-
*/
|
|
8
|
-
export class BrowserRunner {
|
|
9
|
-
owner;
|
|
10
|
-
source;
|
|
11
|
-
spec;
|
|
12
|
-
http;
|
|
13
|
-
closed = false;
|
|
14
|
-
tasks;
|
|
15
|
-
files;
|
|
16
|
-
conversations;
|
|
17
|
-
shares;
|
|
18
|
-
constructor(owner, source, spec) {
|
|
19
|
-
this.owner = owner;
|
|
20
|
-
this.source = source;
|
|
21
|
-
this.spec = spec;
|
|
22
|
-
this.http = this.buildHttp(spec);
|
|
23
|
-
const guarded = this.guardedHttp();
|
|
24
|
-
this.tasks = new TasksClient(guarded);
|
|
25
|
-
this.files = new FilesClient(guarded);
|
|
26
|
-
this.conversations = new ConversationsClient(guarded);
|
|
27
|
-
this.shares = new SharesClient(guarded);
|
|
28
|
-
}
|
|
29
|
-
get dpEndpoint() {
|
|
30
|
-
return this.spec.deployment.endpoint;
|
|
31
|
-
}
|
|
32
|
-
get deployment() {
|
|
33
|
-
return Object.freeze({ ...this.spec.deployment });
|
|
34
|
-
}
|
|
35
|
-
get expires_at() {
|
|
36
|
-
return this.spec.expires_at;
|
|
37
|
-
}
|
|
38
|
-
get session_id() {
|
|
39
|
-
return this.spec.session_id;
|
|
40
|
-
}
|
|
41
|
-
get context() {
|
|
42
|
-
return Object.freeze({ ...this.spec.runtime_context });
|
|
43
|
-
}
|
|
44
|
-
get isClosed() {
|
|
45
|
-
return this.closed;
|
|
46
|
-
}
|
|
47
|
-
async refresh() {
|
|
48
|
-
this.assertOpen();
|
|
49
|
-
const fresh = await this.owner.requestFreshRunnerSpec(this.source);
|
|
50
|
-
this.spec = fresh;
|
|
51
|
-
this.http = this.buildHttp(fresh);
|
|
52
|
-
}
|
|
53
|
-
async close() {
|
|
54
|
-
this.closed = true;
|
|
55
|
-
}
|
|
56
|
-
buildHttp(spec) {
|
|
57
|
-
return new BrowserBearerHttpClient({
|
|
58
|
-
apiUrl: spec.deployment.endpoint,
|
|
59
|
-
token: spec.session_token,
|
|
60
|
-
additionalHeaders: this.owner.additionalHeaders,
|
|
61
|
-
fetch: this.owner.fetch,
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
guardedHttp() {
|
|
65
|
-
const proxy = Object.create(this.http);
|
|
66
|
-
proxy.request = async (opts) => {
|
|
67
|
-
this.assertOpen();
|
|
68
|
-
return this.http.request(opts);
|
|
69
|
-
};
|
|
70
|
-
proxy.stream = async (opts) => {
|
|
71
|
-
this.assertOpen();
|
|
72
|
-
return this.http.stream(opts);
|
|
73
|
-
};
|
|
74
|
-
return proxy;
|
|
75
|
-
}
|
|
76
|
-
assertOpen() {
|
|
77
|
-
if (this.closed) {
|
|
78
|
-
throw new RunnerExpiredError({
|
|
79
|
-
message: "Runner has been closed",
|
|
80
|
-
status: 401,
|
|
81
|
-
code: "runner_expired",
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
export { BrowserRunner as Runner };
|
|
87
|
-
//# sourceMappingURL=runner.js.map
|
package/dist/api/runner.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"runner.js","sourceRoot":"","sources":["../../src/api/runner.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,GAMnB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACL,mBAAmB,EACnB,WAAW,EACX,YAAY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,CAAC;QAChC,CAAC,CAAC;QACF,OAAO,KAAK,CAAC;IACf,CAAC;IAEO,UAAU;QAChB,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;YAChB,MAAM,IAAI,kBAAkB,CAAC;gBAC3B,OAAO,EAAE,wBAAwB;gBACjC,MAAM,EAAE,GAAG;gBACX,IAAI,EAAE,gBAAgB;aACvB,CAAC,CAAC;QACL,CAAC;IACH,CAAC;CACF;AAED,OAAO,EAAE,aAAa,IAAI,MAAM,EAAE,CAAC"}
|
package/dist/api/runtimes.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { RuntimeHandle, RuntimesClient, isUuid, type RuntimeHandleFactory, type RuntimeRunRequestBody } from "@introspection-sdk/http";
|
|
2
|
-
import type { BrowserApiHttpClient } from "./http.js";
|
|
3
|
-
import { BrowserRunner, type BrowserRunnerOwner } from "./runner.js";
|
|
4
|
-
export { isUuid };
|
|
5
|
-
export type { RuntimeRunRequestBody as BrowserRuntimeRunRequestBody };
|
|
6
|
-
export declare class BrowserRuntimesClient extends RuntimesClient<BrowserRunner> {
|
|
7
|
-
constructor(http: BrowserApiHttpClient, owner: BrowserRunnerOwner);
|
|
8
|
-
}
|
|
9
|
-
export { RuntimeHandle as BrowserRuntimeHandle };
|
|
10
|
-
export type BrowserRuntimeHandleFactory = RuntimeHandleFactory<BrowserRunner>;
|
|
11
|
-
export declare function attachBrowserRuntimes(http: BrowserApiHttpClient, owner: BrowserRunnerOwner): BrowserRuntimesClient & BrowserRuntimeHandleFactory;
|
|
12
|
-
//# sourceMappingURL=runtimes.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"runtimes.d.ts","sourceRoot":"","sources":["../../src/api/runtimes.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,cAAc,EAEd,MAAM,EACN,KAAK,oBAAoB,EACzB,KAAK,qBAAqB,EAC3B,MAAM,yBAAyB,CAAC;AACjC,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;AACtD,OAAO,EAAE,aAAa,EAAE,KAAK,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAErE,OAAO,EAAE,MAAM,EAAE,CAAC;AAClB,YAAY,EAAE,qBAAqB,IAAI,4BAA4B,EAAE,CAAC;AAEtE,qBAAa,qBAAsB,SAAQ,cAAc,CAAC,aAAa,CAAC;gBAC1D,IAAI,EAAE,oBAAoB,EAAE,KAAK,EAAE,kBAAkB;CAGlE;AAED,OAAO,EAAE,aAAa,IAAI,oBAAoB,EAAE,CAAC;AAEjD,MAAM,MAAM,2BAA2B,GAAG,oBAAoB,CAAC,aAAa,CAAC,CAAC;AAE9E,wBAAgB,qBAAqB,CACnC,IAAI,EAAE,oBAAoB,EAC1B,KAAK,EAAE,kBAAkB,GACxB,qBAAqB,GAAG,2BAA2B,CAIrD"}
|
package/dist/api/runtimes.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { RuntimeHandle, RuntimesClient, attachRuntimes, isUuid, } from "@introspection-sdk/http";
|
|
2
|
-
import { BrowserRunner } from "./runner.js";
|
|
3
|
-
export { isUuid };
|
|
4
|
-
export class BrowserRuntimesClient extends RuntimesClient {
|
|
5
|
-
constructor(http, owner) {
|
|
6
|
-
super(http, (source, spec) => new BrowserRunner(owner, source, spec));
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
|
-
export { RuntimeHandle as BrowserRuntimeHandle };
|
|
10
|
-
export function attachBrowserRuntimes(http, owner) {
|
|
11
|
-
const api = new BrowserRuntimesClient(http, owner);
|
|
12
|
-
return attachRuntimes(api);
|
|
13
|
-
}
|
|
14
|
-
//# sourceMappingURL=runtimes.js.map
|
package/dist/api/runtimes.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"runtimes.js","sourceRoot":"","sources":["../../src/api/runtimes.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,cAAc,EACd,cAAc,EACd,MAAM,GAGP,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EAAE,aAAa,EAA2B,MAAM,aAAa,CAAC;AAErE,OAAO,EAAE,MAAM,EAAE,CAAC;AAGlB,MAAM,OAAO,qBAAsB,SAAQ,cAA6B;IACtE,YAAY,IAA0B,EAAE,KAAyB;QAC/D,KAAK,CAAC,IAAI,EAAE,CAAC,MAAM,EAAE,IAAI,EAAE,EAAE,CAAC,IAAI,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC,CAAC;IACxE,CAAC;CACF;AAED,OAAO,EAAE,aAAa,IAAI,oBAAoB,EAAE,CAAC;AAIjD,MAAM,UAAU,qBAAqB,CACnC,IAA0B,EAC1B,KAAyB;IAEzB,MAAM,GAAG,GAAG,IAAI,qBAAqB,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IACnD,OAAO,cAAc,CAAC,GAAG,CACI,CAAC;AAChC,CAAC"}
|