@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/src/api/runner.ts DELETED
@@ -1,127 +0,0 @@
1
- import {
2
- RunnerExpiredError,
3
- type RunnerContext,
4
- type RunnerDeployment,
5
- type RunnerSpec,
6
- type RunRequest,
7
- type Uuid,
8
- } from "@introspection-sdk/types";
9
- import {
10
- ConversationsClient,
11
- FilesClient,
12
- SharesClient,
13
- TasksClient,
14
- } from "@introspection-sdk/http";
15
- import { BrowserBearerHttpClient } from "./http.js";
16
-
17
- export type BrowserRunnerSource =
18
- | { kind: "runtime"; id: Uuid; options?: RunRequest }
19
- | { kind: "experiment"; id: Uuid; options?: RunRequest };
20
-
21
- export interface BrowserRunnerOwner {
22
- readonly additionalHeaders?: Record<string, string>;
23
- readonly fetch?: typeof fetch;
24
- requestFreshRunnerSpec(source: BrowserRunnerSource): Promise<RunnerSpec>;
25
- }
26
-
27
- /**
28
- * Browser-side live handle to a Data Plane runner. Mirrors the Node Runner
29
- * shape but uses browser-safe fetch transport and CP-minted bearer tokens.
30
- */
31
- export class BrowserRunner {
32
- private spec: RunnerSpec;
33
- private http: BrowserBearerHttpClient;
34
- private closed = false;
35
-
36
- readonly tasks: TasksClient;
37
- readonly files: FilesClient;
38
- readonly conversations: ConversationsClient;
39
- readonly shares: SharesClient;
40
-
41
- constructor(
42
- private readonly owner: BrowserRunnerOwner,
43
- private readonly source: BrowserRunnerSource,
44
- spec: RunnerSpec,
45
- ) {
46
- this.spec = spec;
47
- this.http = this.buildHttp(spec);
48
- const guarded = this.guardedHttp();
49
- this.tasks = new TasksClient(guarded);
50
- this.files = new FilesClient(guarded);
51
- this.conversations = new ConversationsClient(guarded);
52
- this.shares = new SharesClient(guarded);
53
- }
54
-
55
- get dpEndpoint(): string {
56
- return this.spec.deployment.endpoint;
57
- }
58
-
59
- get deployment(): Readonly<RunnerDeployment> {
60
- return Object.freeze({ ...this.spec.deployment });
61
- }
62
-
63
- get expires_at(): string {
64
- return this.spec.expires_at;
65
- }
66
-
67
- get session_id(): string {
68
- return this.spec.session_id;
69
- }
70
-
71
- get context(): Readonly<RunnerContext> {
72
- return Object.freeze({ ...this.spec.runtime_context });
73
- }
74
-
75
- get isClosed(): boolean {
76
- return this.closed;
77
- }
78
-
79
- async refresh(): Promise<void> {
80
- this.assertOpen();
81
- const fresh = await this.owner.requestFreshRunnerSpec(this.source);
82
- this.spec = fresh;
83
- this.http = this.buildHttp(fresh);
84
- }
85
-
86
- async close(): Promise<void> {
87
- this.closed = true;
88
- }
89
-
90
- private buildHttp(spec: RunnerSpec): BrowserBearerHttpClient {
91
- return new BrowserBearerHttpClient({
92
- apiUrl: spec.deployment.endpoint,
93
- token: spec.session_token,
94
- additionalHeaders: this.owner.additionalHeaders,
95
- fetch: this.owner.fetch,
96
- });
97
- }
98
-
99
- private guardedHttp(): BrowserBearerHttpClient {
100
- const proxy: BrowserBearerHttpClient = Object.create(this.http);
101
- proxy.request = async <T>(
102
- opts: Parameters<BrowserBearerHttpClient["request"]>[0],
103
- ): Promise<T> => {
104
- this.assertOpen();
105
- return this.http.request<T>(opts);
106
- };
107
- proxy.stream = async (
108
- opts: Parameters<BrowserBearerHttpClient["stream"]>[0],
109
- ): Promise<Response> => {
110
- this.assertOpen();
111
- return this.http.stream(opts);
112
- };
113
- return proxy;
114
- }
115
-
116
- private assertOpen(): void {
117
- if (this.closed) {
118
- throw new RunnerExpiredError({
119
- message: "Runner has been closed",
120
- status: 401,
121
- code: "runner_expired",
122
- });
123
- }
124
- }
125
- }
126
-
127
- export { BrowserRunner as Runner };
@@ -1,32 +0,0 @@
1
- import {
2
- RuntimeHandle,
3
- RuntimesClient,
4
- attachRuntimes,
5
- isUuid,
6
- type RuntimeHandleFactory,
7
- type RuntimeRunRequestBody,
8
- } from "@introspection-sdk/http";
9
- import type { BrowserApiHttpClient } from "./http.js";
10
- import { BrowserRunner, type BrowserRunnerOwner } from "./runner.js";
11
-
12
- export { isUuid };
13
- export type { RuntimeRunRequestBody as BrowserRuntimeRunRequestBody };
14
-
15
- export class BrowserRuntimesClient extends RuntimesClient<BrowserRunner> {
16
- constructor(http: BrowserApiHttpClient, owner: BrowserRunnerOwner) {
17
- super(http, (source, spec) => new BrowserRunner(owner, source, spec));
18
- }
19
- }
20
-
21
- export { RuntimeHandle as BrowserRuntimeHandle };
22
-
23
- export type BrowserRuntimeHandleFactory = RuntimeHandleFactory<BrowserRunner>;
24
-
25
- export function attachBrowserRuntimes(
26
- http: BrowserApiHttpClient,
27
- owner: BrowserRunnerOwner,
28
- ): BrowserRuntimesClient & BrowserRuntimeHandleFactory {
29
- const api = new BrowserRuntimesClient(http, owner);
30
- return attachRuntimes(api) as BrowserRuntimesClient &
31
- BrowserRuntimeHandleFactory;
32
- }