@steerable/agent-shell-web 0.12.2 → 0.12.4
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/package.json +4 -4
- package/src/lib/host-bridge.ts +21 -0
- package/src/lib/http-bridge.ts +35 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@steerable/agent-shell-web",
|
|
3
|
-
"version": "0.12.
|
|
3
|
+
"version": "0.12.4",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Steerable framework — product-neutral renderer SPA source for @steerable/agent-shell (React + Vite). Consumed by product web entry points via the `@/` alias (anchored at this package's src/) and the createProductViteConfig factory. Published as a source package (src/), plus the compiled vite.base config factory (vite.base.js + .d.ts) for Node-side config loading.",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -45,8 +45,8 @@
|
|
|
45
45
|
"react-router-dom": "^6.30.0",
|
|
46
46
|
"rehype-raw": "^7.0.0",
|
|
47
47
|
"remark-gfm": "^4.0.1",
|
|
48
|
-
"@steerable/agent-protocol": "0.12.
|
|
49
|
-
"@steerable/agent-ui": "0.12.
|
|
48
|
+
"@steerable/agent-protocol": "0.12.4",
|
|
49
|
+
"@steerable/agent-ui": "0.12.4"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
52
|
"@tailwindcss/vite": "^4.3.0",
|
|
@@ -59,7 +59,7 @@
|
|
|
59
59
|
"typescript": "^5.8.3",
|
|
60
60
|
"vite": "^5.4.21",
|
|
61
61
|
"vitest": "^3.2.4",
|
|
62
|
-
"@steerable/pack-sdk": "0.12.
|
|
62
|
+
"@steerable/pack-sdk": "0.12.4"
|
|
63
63
|
},
|
|
64
64
|
"scripts": {
|
|
65
65
|
"gen": "echo agent-shell-web",
|
package/src/lib/host-bridge.ts
CHANGED
|
@@ -16,6 +16,20 @@ export type LocalBackendRequestInput = {
|
|
|
16
16
|
body?: unknown;
|
|
17
17
|
};
|
|
18
18
|
|
|
19
|
+
export type LocalBackendBinaryRequestInput = {
|
|
20
|
+
method?: 'GET' | 'POST';
|
|
21
|
+
path: string;
|
|
22
|
+
body?: unknown;
|
|
23
|
+
signal?: AbortSignal;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export interface LocalBackendBinaryResponse {
|
|
27
|
+
status: number;
|
|
28
|
+
headers: Headers;
|
|
29
|
+
arrayBuffer: () => Promise<ArrayBuffer>;
|
|
30
|
+
blob: () => Promise<Blob>;
|
|
31
|
+
}
|
|
32
|
+
|
|
19
33
|
export type LocalBackendStreamEvent =
|
|
20
34
|
| { type: 'data'; chunk: string; parsed?: SSEEvent }
|
|
21
35
|
| { type: 'end'; status: number }
|
|
@@ -180,6 +194,13 @@ export interface HostBridge {
|
|
|
180
194
|
};
|
|
181
195
|
localBackend: {
|
|
182
196
|
request: <T>(input: LocalBackendRequestInput) => Promise<T>;
|
|
197
|
+
requestBinary?: (
|
|
198
|
+
input: LocalBackendBinaryRequestInput,
|
|
199
|
+
) => Promise<LocalBackendBinaryResponse>;
|
|
200
|
+
resolveAuthorizedFetch?: (path: string) => {
|
|
201
|
+
url: string;
|
|
202
|
+
headers: Record<string, string>;
|
|
203
|
+
};
|
|
183
204
|
startStream: (
|
|
184
205
|
input: LocalBackendRequestInput,
|
|
185
206
|
onEvent: (payload: LocalBackendStreamEvent) => void,
|
package/src/lib/http-bridge.ts
CHANGED
|
@@ -18,6 +18,8 @@ import type {
|
|
|
18
18
|
ApprovalPromptRequest,
|
|
19
19
|
AskUserPromptRequest,
|
|
20
20
|
HostBridge,
|
|
21
|
+
LocalBackendBinaryRequestInput,
|
|
22
|
+
LocalBackendBinaryResponse,
|
|
21
23
|
LocalBackendRequestInput,
|
|
22
24
|
LocalBackendStreamEvent,
|
|
23
25
|
TerminalSession,
|
|
@@ -73,6 +75,34 @@ async function http<T>(method: string, path: string, body?: unknown): Promise<T>
|
|
|
73
75
|
return data;
|
|
74
76
|
}
|
|
75
77
|
|
|
78
|
+
async function httpBinary(
|
|
79
|
+
input: LocalBackendBinaryRequestInput,
|
|
80
|
+
): Promise<LocalBackendBinaryResponse> {
|
|
81
|
+
const method = input.method ?? 'GET';
|
|
82
|
+
const res = await fetch(input.path, {
|
|
83
|
+
method,
|
|
84
|
+
headers: {
|
|
85
|
+
...(input.body !== undefined ? { 'Content-Type': 'application/json' } : {}),
|
|
86
|
+
...authHeaders(),
|
|
87
|
+
},
|
|
88
|
+
body: input.body !== undefined ? JSON.stringify(input.body) : undefined,
|
|
89
|
+
signal: input.signal,
|
|
90
|
+
});
|
|
91
|
+
if (!res.ok) {
|
|
92
|
+
const data = await res.json().catch(() => null);
|
|
93
|
+
const err = new Error(httpErrorMessage(data, res.status)) as Error & { status?: number; data?: unknown };
|
|
94
|
+
err.status = res.status;
|
|
95
|
+
err.data = data;
|
|
96
|
+
throw err;
|
|
97
|
+
}
|
|
98
|
+
return {
|
|
99
|
+
status: res.status,
|
|
100
|
+
headers: res.headers,
|
|
101
|
+
arrayBuffer: () => res.arrayBuffer(),
|
|
102
|
+
blob: () => res.blob(),
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
|
|
76
106
|
// ---------------------------------------------------------------------------
|
|
77
107
|
// 事件总线:一条 EventSource 承载所有 channel(channel 名与 IPC 通道一致)。
|
|
78
108
|
// ---------------------------------------------------------------------------
|
|
@@ -256,6 +286,11 @@ export function createHttpBridge(): HostBridge {
|
|
|
256
286
|
localBackend: {
|
|
257
287
|
request: <T>(input: LocalBackendRequestInput) =>
|
|
258
288
|
http<T>(input.method, input.path, input.body),
|
|
289
|
+
requestBinary: (input: LocalBackendBinaryRequestInput) => httpBinary(input),
|
|
290
|
+
resolveAuthorizedFetch: (path: string) => ({
|
|
291
|
+
url: path,
|
|
292
|
+
headers: authHeaders(),
|
|
293
|
+
}),
|
|
259
294
|
startStream,
|
|
260
295
|
cancelStream,
|
|
261
296
|
steerChat: async (chatId, content, options) => {
|