@agentshouse/app-bridge 0.1.0-alpha.6 → 0.1.0-alpha.8
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/README.md +19 -2
- package/client/src/bridge.d.ts +4 -1
- package/client/src/bridge.js +46 -0
- package/client/src/index.d.ts +1 -1
- package/client/src/test-host.d.ts +6 -1
- package/client/src/test-host.js +11 -0
- package/client/src/wire.d.ts +29 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
The renderer-side client of the agents.house App bridge. An App served by House
|
|
4
4
|
receives one message port before its own scripts run; this package is that
|
|
5
|
-
port's one listener. It carries
|
|
5
|
+
port's one listener. It carries six families:
|
|
6
6
|
|
|
7
7
|
- **Navigation** - the part of the shell's URL below the App's path, with its
|
|
8
8
|
query and fragment. The shell delivers it when the App starts and whenever the
|
|
@@ -29,6 +29,21 @@ port's one listener. It carries four families:
|
|
|
29
29
|
- **Site image read** - given a Published Room and an original attachment
|
|
30
30
|
reference, it answers the web copy's path and metadata, or `null` when no
|
|
31
31
|
copy exists. The original bytes never cross this bridge at a Site.
|
|
32
|
+
- **App release code** - `sourceTop(app, release)` answers the top level of
|
|
33
|
+
the latest successful release of an App the User may use: its folders, its
|
|
34
|
+
files with their sizes and its root README's text, or `null` for none;
|
|
35
|
+
`sourceDownload(app, release)` answers every file of that release with its
|
|
36
|
+
path, its size and its `text`, or its bytes as `base64`. The browser keeps
|
|
37
|
+
each answer per App and release: a read naming a release it holds answers
|
|
38
|
+
without asking House, and keeping a newer release drops the earlier one. A
|
|
39
|
+
refusal is House's `{ error: { code } }`, `app_release_not_found` for an
|
|
40
|
+
App with no release; a read House does not answer, or one that outlived
|
|
41
|
+
the browser's signed-in User, is `null`.
|
|
42
|
+
- **App screenshot read** - given an App reference, `readScreenshot(app)`
|
|
43
|
+
answers the image this browser captured of that App's screen the first time
|
|
44
|
+
it ran its current release, as a PNG `Blob` at most 1200 pixels wide, or
|
|
45
|
+
`null` when this browser holds none. The image stays in the browser; a Site
|
|
46
|
+
holds none.
|
|
32
47
|
|
|
33
48
|
The package carries no credential handling and no Runtime family. It surfaces
|
|
34
49
|
the dedicated Runtime port the worker transfers over the bridge as a plain
|
|
@@ -88,4 +103,6 @@ same-origin absolute path, publishes a status, its `service_mode` included,
|
|
|
88
103
|
records in `consents` each
|
|
89
104
|
`gaConsent` it takes while that status measures and publishes the status the
|
|
90
105
|
choice leaves, records in `tabs` each `setTab` the shell would take and ignores
|
|
91
|
-
any other,
|
|
106
|
+
any other, answers a release code read from the `sources` it was given, or
|
|
107
|
+
`null`, answers `readScreenshot` from the `screenshots` it was given by App
|
|
108
|
+
reference, and attaches a Runtime port.
|
package/client/src/bridge.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { HouseBridgePort, HouseGaChoice, HouseMessagePort, HouseStatus, HouseTab } from './wire.js';
|
|
1
|
+
import type { HouseBridgePort, HouseGaChoice, HouseMessagePort, HouseSourceDownload, HouseSourceRefusal, HouseSourceTop, HouseStatus, HouseTab } from './wire.js';
|
|
2
2
|
export declare class HouseCeremonyRefused extends Error {
|
|
3
3
|
readonly path: string | null;
|
|
4
4
|
constructor(path: string | null);
|
|
@@ -22,6 +22,9 @@ export interface HouseBridge {
|
|
|
22
22
|
ceremony(path: string): Promise<never>;
|
|
23
23
|
setTab(tab: HouseTab): void;
|
|
24
24
|
readAttachment(room: string, attachment: string): Promise<HouseImageCopy | null>;
|
|
25
|
+
sourceTop(app: string, release?: string): Promise<HouseSourceTop | HouseSourceRefusal | null>;
|
|
26
|
+
sourceDownload(app: string, release?: string): Promise<HouseSourceDownload | HouseSourceRefusal | null>;
|
|
27
|
+
readScreenshot(app: string): Promise<Blob | null>;
|
|
25
28
|
status(): HouseStatus | null;
|
|
26
29
|
onStatus(listener: (status: HouseStatus) => void): () => void;
|
|
27
30
|
gaConsent(choice: HouseGaChoice): void;
|
package/client/src/bridge.js
CHANGED
|
@@ -33,6 +33,10 @@ export function connectHouseBridge(source = heldBridge()) {
|
|
|
33
33
|
const navigations = [];
|
|
34
34
|
const attachments = new Map();
|
|
35
35
|
let nextAttachment = 0;
|
|
36
|
+
const sources = new Map();
|
|
37
|
+
let nextSource = 0;
|
|
38
|
+
const screenshots = new Map();
|
|
39
|
+
let nextScreenshot = 0;
|
|
36
40
|
const addressListeners = new Set();
|
|
37
41
|
const statusListeners = new Set();
|
|
38
42
|
let outbox = [];
|
|
@@ -88,6 +92,28 @@ export function connectHouseBridge(source = heldBridge()) {
|
|
|
88
92
|
pending.resolve(answer.image ?? null);
|
|
89
93
|
return;
|
|
90
94
|
}
|
|
95
|
+
if (data.house === 'source') {
|
|
96
|
+
const answer = data;
|
|
97
|
+
if (typeof answer.id !== 'number')
|
|
98
|
+
return;
|
|
99
|
+
const pending = sources.get(answer.id);
|
|
100
|
+
if (pending === undefined)
|
|
101
|
+
return;
|
|
102
|
+
sources.delete(answer.id);
|
|
103
|
+
pending.resolve(answer.answer ?? null);
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
if (data.house === 'screenshot') {
|
|
107
|
+
const answer = data;
|
|
108
|
+
if (typeof answer.id !== 'number')
|
|
109
|
+
return;
|
|
110
|
+
const pending = screenshots.get(answer.id);
|
|
111
|
+
if (pending === undefined)
|
|
112
|
+
return;
|
|
113
|
+
screenshots.delete(answer.id);
|
|
114
|
+
pending.resolve(answer.image ?? null);
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
91
117
|
if (data.house === 'ceremony-refused') {
|
|
92
118
|
const refused = data.path;
|
|
93
119
|
const named = typeof refused === 'string' ? refused : null;
|
|
@@ -105,6 +131,13 @@ export function connectHouseBridge(source = heldBridge()) {
|
|
|
105
131
|
for (const message of waiting)
|
|
106
132
|
port.postMessage(message);
|
|
107
133
|
});
|
|
134
|
+
function readSource(house, app, release) {
|
|
135
|
+
const pending = settled();
|
|
136
|
+
const id = ++nextSource;
|
|
137
|
+
sources.set(id, pending.settle);
|
|
138
|
+
send({ house, id, app, release });
|
|
139
|
+
return pending.promise;
|
|
140
|
+
}
|
|
108
141
|
function navigate(mode, asked) {
|
|
109
142
|
const pending = settled();
|
|
110
143
|
navigations.push({ address: asked, settle: pending.settle });
|
|
@@ -144,6 +177,19 @@ export function connectHouseBridge(source = heldBridge()) {
|
|
|
144
177
|
send({ house: 'attachment-read', id, room, attachment });
|
|
145
178
|
return pending.promise;
|
|
146
179
|
},
|
|
180
|
+
sourceTop(app, release) {
|
|
181
|
+
return readSource('source-top', app, release);
|
|
182
|
+
},
|
|
183
|
+
sourceDownload(app, release) {
|
|
184
|
+
return readSource('source-download', app, release);
|
|
185
|
+
},
|
|
186
|
+
readScreenshot(app) {
|
|
187
|
+
const pending = settled();
|
|
188
|
+
const id = ++nextScreenshot;
|
|
189
|
+
screenshots.set(id, pending.settle);
|
|
190
|
+
send({ house: 'screenshot-read', id, app });
|
|
191
|
+
return pending.promise;
|
|
192
|
+
},
|
|
147
193
|
status() {
|
|
148
194
|
return status;
|
|
149
195
|
},
|
package/client/src/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export { connectHouseBridge, HouseCeremonyRefused, HouseNavigationRefused, type HouseBridge, type HouseImageCopy, } from './bridge.js';
|
|
2
2
|
export { HOUSE_ADDRESS_MAX_CHARS } from './wire.js';
|
|
3
|
-
export type { HouseBridgeEvent, HouseBridgePort, HouseCredentialState, HouseGa, HouseGaChoice, HouseMessagePort, HouseNavigationMode, HouseStatus, HouseSyncState, } from './wire.js';
|
|
3
|
+
export type { HouseBridgeEvent, HouseBridgePort, HouseCredentialState, HouseGa, HouseGaChoice, HouseMessagePort, HouseNavigationMode, HouseSourceDownload, HouseSourceFile, HouseSourceRefusal, HouseSourceTop, HouseStatus, HouseSyncState, } from './wire.js';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { HouseImageCopy } from './bridge.js';
|
|
2
|
-
import type { HouseBridgePort, HouseGaChoice, HouseMessagePort, HouseNavigationMode, HouseStatus, HouseTab } from './wire.js';
|
|
2
|
+
import type { HouseBridgePort, HouseGaChoice, HouseMessagePort, HouseNavigationMode, HouseSourceDownload, HouseSourceTop, HouseStatus, HouseTab } from './wire.js';
|
|
3
3
|
export interface HouseBridgeNavigation {
|
|
4
4
|
readonly mode: HouseNavigationMode;
|
|
5
5
|
readonly address: string;
|
|
@@ -21,5 +21,10 @@ export interface HouseBridgeTestHostOptions {
|
|
|
21
21
|
readonly images?: readonly (HouseImageCopy & {
|
|
22
22
|
readonly room: string;
|
|
23
23
|
})[];
|
|
24
|
+
readonly sources?: readonly {
|
|
25
|
+
readonly top: HouseSourceTop;
|
|
26
|
+
readonly download: HouseSourceDownload;
|
|
27
|
+
}[];
|
|
28
|
+
readonly screenshots?: Readonly<Record<string, Blob>>;
|
|
24
29
|
}
|
|
25
30
|
export declare function createHouseBridgeTestHost(options?: HouseBridgeTestHostOptions): HouseBridgeTestHost;
|
package/client/src/test-host.js
CHANGED
|
@@ -87,6 +87,12 @@ export function createHouseBridgeTestHost(options = {}) {
|
|
|
87
87
|
else if (data.house === 'ga/consent') {
|
|
88
88
|
consent(data.choice);
|
|
89
89
|
}
|
|
90
|
+
else if (data.house === 'source-top' || data.house === 'source-download') {
|
|
91
|
+
const asked = data;
|
|
92
|
+
const source = options.sources?.find((entry) => entry.top.app_ref === asked.app);
|
|
93
|
+
const answer = source === undefined ? null : data.house === 'source-top' ? source.top : source.download;
|
|
94
|
+
deliver({ house: 'source', id: asked.id, answer });
|
|
95
|
+
}
|
|
90
96
|
else if (data.house === 'attachment-read') {
|
|
91
97
|
const asked = data;
|
|
92
98
|
const image = options.images?.find((entry) => entry.room === asked.room && entry.attachment === asked.attachment);
|
|
@@ -103,6 +109,11 @@ export function createHouseBridgeTestHost(options = {}) {
|
|
|
103
109
|
},
|
|
104
110
|
});
|
|
105
111
|
}
|
|
112
|
+
else if (data.house === 'screenshot-read') {
|
|
113
|
+
const asked = data;
|
|
114
|
+
const held = typeof asked.app === 'string' ? options.screenshots?.[asked.app] : undefined;
|
|
115
|
+
deliver({ house: 'screenshot', id: asked.id, image: held ?? null });
|
|
116
|
+
}
|
|
106
117
|
}
|
|
107
118
|
const port = {
|
|
108
119
|
postMessage(message) {
|
package/client/src/wire.d.ts
CHANGED
|
@@ -36,5 +36,34 @@ export interface HouseStatus {
|
|
|
36
36
|
readonly service_mode: 'open' | 'write-halted' | null;
|
|
37
37
|
}
|
|
38
38
|
export type HouseNavigationMode = 'push' | 'replace';
|
|
39
|
+
interface HouseRelease {
|
|
40
|
+
readonly app_ref: string;
|
|
41
|
+
readonly release: string;
|
|
42
|
+
}
|
|
43
|
+
export interface HouseSourceTop extends HouseRelease {
|
|
44
|
+
readonly folders: readonly string[];
|
|
45
|
+
readonly files: readonly {
|
|
46
|
+
readonly name: string;
|
|
47
|
+
readonly size: number;
|
|
48
|
+
}[];
|
|
49
|
+
readonly readme: string | null;
|
|
50
|
+
}
|
|
51
|
+
export type HouseSourceFile = {
|
|
52
|
+
readonly path: string;
|
|
53
|
+
readonly size: number;
|
|
54
|
+
} & ({
|
|
55
|
+
readonly text: string;
|
|
56
|
+
} | {
|
|
57
|
+
readonly base64: string;
|
|
58
|
+
});
|
|
59
|
+
export interface HouseSourceDownload extends HouseRelease {
|
|
60
|
+
readonly files: readonly HouseSourceFile[];
|
|
61
|
+
}
|
|
62
|
+
export interface HouseSourceRefusal {
|
|
63
|
+
readonly error: {
|
|
64
|
+
readonly code: string;
|
|
65
|
+
};
|
|
66
|
+
}
|
|
39
67
|
export type HouseTab = TabChange;
|
|
40
68
|
export declare const HOUSE_ADDRESS_MAX_CHARS = 1000;
|
|
69
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agentshouse/app-bridge",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
4
|
-
"description": "Renderer-side client of the agents.house App bridge: navigation, the tab title and icon, ceremonies, status
|
|
3
|
+
"version": "0.1.0-alpha.8",
|
|
4
|
+
"description": "Renderer-side client of the agents.house App bridge: navigation, the tab title and icon, ceremonies, status, Site image reads, App release code and App screenshot reads, with an in-page test host.",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"sideEffects": false,
|