@rollrook-ai/sdk 0.0.0-stage → 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/dist/agents.d.ts +9 -0
- package/dist/agents.d.ts.map +1 -0
- package/dist/agents.js +13 -0
- package/dist/agents.js.map +1 -0
- package/dist/assets.d.ts +35 -0
- package/dist/assets.d.ts.map +1 -0
- package/dist/assets.js +66 -0
- package/dist/assets.js.map +1 -0
- package/dist/assistant.d.ts +76 -0
- package/dist/assistant.d.ts.map +1 -0
- package/dist/assistant.js +161 -0
- package/dist/assistant.js.map +1 -0
- package/dist/audio.d.ts +55 -0
- package/dist/audio.d.ts.map +1 -0
- package/dist/audio.js +82 -0
- package/dist/audio.js.map +1 -0
- package/dist/bridge.d.ts +51 -0
- package/dist/bridge.d.ts.map +1 -0
- package/dist/bridge.js +78 -0
- package/dist/bridge.js.map +1 -0
- package/dist/calendar.d.ts +33 -0
- package/dist/calendar.d.ts.map +1 -0
- package/dist/calendar.js +63 -0
- package/dist/calendar.js.map +1 -0
- package/dist/context.d.ts +19 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +25 -0
- package/dist/context.js.map +1 -0
- package/dist/errors.d.ts +74 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +111 -0
- package/dist/errors.js.map +1 -0
- package/dist/events.d.ts +36 -0
- package/dist/events.d.ts.map +1 -0
- package/dist/events.js +81 -0
- package/dist/events.js.map +1 -0
- package/dist/files.d.ts +29 -0
- package/dist/files.d.ts.map +1 -0
- package/dist/files.js +43 -0
- package/dist/files.js.map +1 -0
- package/dist/index.d.ts +84 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +78 -0
- package/dist/index.js.map +1 -0
- package/dist/mock/index.d.ts +4 -0
- package/dist/mock/index.d.ts.map +1 -0
- package/dist/mock/index.js +3 -0
- package/dist/mock/index.js.map +1 -0
- package/dist/mock/mock-host.d.ts +255 -0
- package/dist/mock/mock-host.d.ts.map +1 -0
- package/dist/mock/mock-host.js +1274 -0
- package/dist/mock/mock-host.js.map +1 -0
- package/dist/mock/samples.d.ts +56 -0
- package/dist/mock/samples.d.ts.map +1 -0
- package/dist/mock/samples.js +283 -0
- package/dist/mock/samples.js.map +1 -0
- package/dist/mock/toolbar.d.ts +95 -0
- package/dist/mock/toolbar.d.ts.map +1 -0
- package/dist/mock/toolbar.js +279 -0
- package/dist/mock/toolbar.js.map +1 -0
- package/dist/net.d.ts +13 -0
- package/dist/net.d.ts.map +1 -0
- package/dist/net.js +26 -0
- package/dist/net.js.map +1 -0
- package/dist/plugin.d.ts +11 -0
- package/dist/plugin.d.ts.map +1 -0
- package/dist/plugin.js +13 -0
- package/dist/plugin.js.map +1 -0
- package/dist/raven.d.ts +51 -0
- package/dist/raven.d.ts.map +1 -0
- package/dist/raven.js +100 -0
- package/dist/raven.js.map +1 -0
- package/dist/segment-display.d.ts +93 -0
- package/dist/segment-display.d.ts.map +1 -0
- package/dist/segment-display.js +324 -0
- package/dist/segment-display.js.map +1 -0
- package/dist/settings.d.ts +19 -0
- package/dist/settings.d.ts.map +1 -0
- package/dist/settings.js +27 -0
- package/dist/settings.js.map +1 -0
- package/dist/storage.d.ts +28 -0
- package/dist/storage.d.ts.map +1 -0
- package/dist/storage.js +54 -0
- package/dist/storage.js.map +1 -0
- package/dist/system.d.ts +19 -0
- package/dist/system.d.ts.map +1 -0
- package/dist/system.js +24 -0
- package/dist/system.js.map +1 -0
- package/dist/theme.d.ts +51 -0
- package/dist/theme.d.ts.map +1 -0
- package/dist/theme.js +85 -0
- package/dist/theme.js.map +1 -0
- package/dist/types.d.ts +278 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/ui.d.ts +57 -0
- package/dist/ui.d.ts.map +1 -0
- package/dist/ui.js +78 -0
- package/dist/ui.js.map +1 -0
- package/dist/usage.d.ts +14 -0
- package/dist/usage.d.ts.map +1 -0
- package/dist/usage.js +19 -0
- package/dist/usage.js.map +1 -0
- package/dist/video.d.ts +11 -0
- package/dist/video.d.ts.map +1 -0
- package/dist/video.js +17 -0
- package/dist/video.js.map +1 -0
- package/dist/wire.d.ts +214 -0
- package/dist/wire.d.ts.map +1 -0
- package/dist/wire.js +538 -0
- package/dist/wire.js.map +1 -0
- package/package.json +39 -4
- package/src/agents.ts +14 -0
- package/src/assets.ts +80 -0
- package/src/assistant.ts +185 -0
- package/src/audio.ts +90 -0
- package/src/bridge.ts +96 -0
- package/src/calendar.ts +68 -0
- package/src/context.ts +28 -0
- package/src/errors.ts +131 -0
- package/src/events.ts +90 -0
- package/src/files.ts +47 -0
- package/src/index.ts +152 -0
- package/src/mock/index.ts +3 -0
- package/src/mock/mock-host.ts +1408 -0
- package/src/mock/samples.ts +300 -0
- package/src/mock/toolbar.ts +321 -0
- package/src/net.ts +27 -0
- package/src/plugin.ts +14 -0
- package/src/raven.ts +116 -0
- package/src/segment-display.ts +377 -0
- package/src/settings.ts +29 -0
- package/src/storage.ts +59 -0
- package/src/system.ts +26 -0
- package/src/theme.ts +97 -0
- package/src/types.ts +327 -0
- package/src/ui.ts +88 -0
- package/src/usage.ts +21 -0
- package/src/video.ts +17 -0
- package/src/wire.ts +608 -0
- package/theme.css +407 -0
- package/README.md +0 -3
package/dist/agents.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { AgentSession } from "./types.js";
|
|
2
|
+
/** The code agent sessions RollRook watches. Needs the `agents.read` permission. */
|
|
3
|
+
export declare class AgentsApi {
|
|
4
|
+
/**
|
|
5
|
+
* @returns the sessions RollRook knows of
|
|
6
|
+
*/
|
|
7
|
+
list(): Promise<AgentSession[]>;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=agents.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agents.d.ts","sourceRoot":"","sources":["../src/agents.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAG/C,oFAAoF;AACpF,qBAAa,SAAS;IAClB;;OAEG;IACG,IAAI,IAAI,OAAO,CAAC,YAAY,EAAE,CAAC,CAGpC;CACJ"}
|
package/dist/agents.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Bridge } from "./bridge.js";
|
|
2
|
+
import { Wire } from "./wire.js";
|
|
3
|
+
/** The code agent sessions RollRook watches. Needs the `agents.read` permission. */
|
|
4
|
+
export class AgentsApi {
|
|
5
|
+
/**
|
|
6
|
+
* @returns the sessions RollRook knows of
|
|
7
|
+
*/
|
|
8
|
+
async list() {
|
|
9
|
+
const record = Wire.record(await Bridge.call("agents.list"), "agents.list reply");
|
|
10
|
+
return Wire.array(record, "agents", "agents.list reply").map((agent) => Wire.agent_session(agent));
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=agents.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agents.js","sourceRoot":"","sources":["../src/agents.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,oFAAoF;AACpF,MAAM,OAAO,SAAS;IAClB;;OAEG;IACH,KAAK,CAAC,IAAI;QACN,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM,MAAM,CAAC,IAAI,CAAC,aAAa,CAAC,EAAE,mBAAmB,CAAC,CAAC;QAClF,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,QAAQ,EAAE,mBAAmB,CAAC,CAAC,GAAG,CAAC,CAAC,KAAc,EAAE,EAAE,CAAC,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC,CAAC;IAChH,CAAC;CACJ"}
|
package/dist/assets.d.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { AgentHarness } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* URLs of the pictures RollRook shares with every plugin, served from
|
|
4
|
+
* `rollrook-asset://`. Outside RollRook, where that scheme does not exist,
|
|
5
|
+
* each helper returns a neutral placeholder as a `data:` URL instead.
|
|
6
|
+
*/
|
|
7
|
+
export declare class AssetsApi {
|
|
8
|
+
/** The scheme RollRook serves its shared pictures from. */
|
|
9
|
+
static readonly SCHEME = "rollrook-asset://";
|
|
10
|
+
/** The letter each code agent's placeholder mark shows. */
|
|
11
|
+
static readonly map_harness_letters: Record<AgentHarness, string>;
|
|
12
|
+
/** The color of each code agent's placeholder mark, near its own. */
|
|
13
|
+
static readonly map_harness_colors: Record<AgentHarness, string>;
|
|
14
|
+
/**
|
|
15
|
+
* @param name - the code agent
|
|
16
|
+
* @returns the URL of its mark, a PNG in its colors
|
|
17
|
+
*/
|
|
18
|
+
harness(name: AgentHarness): string;
|
|
19
|
+
/**
|
|
20
|
+
* An interface icon, drawn in `currentColor`. Show it as a CSS mask so it
|
|
21
|
+
* takes the text's color: an `<img>` draws `currentColor` as black.
|
|
22
|
+
*
|
|
23
|
+
* @param name - the icon's name, as Lucide names it, e.g. `clock`
|
|
24
|
+
* @returns the URL of its SVG
|
|
25
|
+
*/
|
|
26
|
+
icon(name: string): string;
|
|
27
|
+
/**
|
|
28
|
+
* @param bundle_id - an app's bundle identifier, e.g. `com.apple.Music`
|
|
29
|
+
* @returns the URL of the app's icon, a PNG
|
|
30
|
+
*/
|
|
31
|
+
app_icon(bundle_id: string): string;
|
|
32
|
+
private static data_url;
|
|
33
|
+
private static escape_xml;
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=assets.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assets.d.ts","sourceRoot":"","sources":["../src/assets.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE/C;;;;GAIG;AACH,qBAAa,SAAS;IAClB,2DAA2D;IAC3D,MAAM,CAAC,QAAQ,CAAC,MAAM,uBAAuB;IAE7C,2DAA2D;IAC3D,MAAM,CAAC,QAAQ,CAAC,mBAAmB,EAAE,MAAM,CAAC,YAAY,EAAE,MAAM,CAAC,CAI/D;IAEF,qEAAqE;IACrE,MAAM,CAAC,QAAQ,CAAC,kBAAkB,EAAE,MAAM,CAAC,YAAY,EAAE,MAAM,CAAC,CAI9D;IAEF;;;OAGG;IACH,OAAO,CAAC,IAAI,EAAE,YAAY,GAAG,MAAM,CAQlC;IAED;;;;;;OAMG;IACH,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAOzB;IAED;;;OAGG;IACH,QAAQ,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAUlC;IAED,OAAO,CAAC,MAAM,CAAC,QAAQ;IAIvB,OAAO,CAAC,MAAM,CAAC,UAAU;CAG5B"}
|
package/dist/assets.js
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { Bridge } from "./bridge.js";
|
|
2
|
+
/**
|
|
3
|
+
* URLs of the pictures RollRook shares with every plugin, served from
|
|
4
|
+
* `rollrook-asset://`. Outside RollRook, where that scheme does not exist,
|
|
5
|
+
* each helper returns a neutral placeholder as a `data:` URL instead.
|
|
6
|
+
*/
|
|
7
|
+
export class AssetsApi {
|
|
8
|
+
/** The scheme RollRook serves its shared pictures from. */
|
|
9
|
+
static SCHEME = "rollrook-asset://";
|
|
10
|
+
/** The letter each code agent's placeholder mark shows. */
|
|
11
|
+
static map_harness_letters = {
|
|
12
|
+
claude: "C",
|
|
13
|
+
codex: "X",
|
|
14
|
+
agy: "A",
|
|
15
|
+
};
|
|
16
|
+
/** The color of each code agent's placeholder mark, near its own. */
|
|
17
|
+
static map_harness_colors = {
|
|
18
|
+
claude: "#d97757",
|
|
19
|
+
codex: "#1c1c20",
|
|
20
|
+
agy: "#3b78e7",
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* @param name - the code agent
|
|
24
|
+
* @returns the URL of its mark, a PNG in its colors
|
|
25
|
+
*/
|
|
26
|
+
harness(name) {
|
|
27
|
+
if (Bridge.is_native()) {
|
|
28
|
+
return `${AssetsApi.SCHEME}harness/${name}.png`;
|
|
29
|
+
}
|
|
30
|
+
return AssetsApi.data_url(`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><rect width="16" height="16" fill="${AssetsApi.map_harness_colors[name]}"/>`
|
|
31
|
+
+ `<text x="8" y="11.4" font-family="-apple-system,sans-serif" font-size="9.5" font-weight="600" fill="#ffffff" text-anchor="middle">${AssetsApi.map_harness_letters[name]}</text></svg>`);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* An interface icon, drawn in `currentColor`. Show it as a CSS mask so it
|
|
35
|
+
* takes the text's color: an `<img>` draws `currentColor` as black.
|
|
36
|
+
*
|
|
37
|
+
* @param name - the icon's name, as Lucide names it, e.g. `clock`
|
|
38
|
+
* @returns the URL of its SVG
|
|
39
|
+
*/
|
|
40
|
+
icon(name) {
|
|
41
|
+
if (Bridge.is_native()) {
|
|
42
|
+
return `${AssetsApi.SCHEME}icon/${encodeURIComponent(name)}.svg`;
|
|
43
|
+
}
|
|
44
|
+
return AssetsApi.data_url(`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"><rect x="4" y="4" width="16" height="16" rx="4"/><circle cx="12" cy="12" r="2"/></svg>`);
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* @param bundle_id - an app's bundle identifier, e.g. `com.apple.Music`
|
|
48
|
+
* @returns the URL of the app's icon, a PNG
|
|
49
|
+
*/
|
|
50
|
+
app_icon(bundle_id) {
|
|
51
|
+
if (Bridge.is_native()) {
|
|
52
|
+
return `${AssetsApi.SCHEME}app-icon/${encodeURIComponent(bundle_id)}.png`;
|
|
53
|
+
}
|
|
54
|
+
const letter = (bundle_id.split(".").at(-1) ?? "?").charAt(0).toUpperCase();
|
|
55
|
+
return AssetsApi.data_url(`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32"><defs><linearGradient id="g" x1="0" y1="0" x2="0" y2="1"><stop offset="0" stop-color="#8e8e93"/><stop offset="1" stop-color="#636366"/></linearGradient></defs>`
|
|
56
|
+
+ `<rect x="2" y="2" width="28" height="28" rx="7" fill="url(#g)"/>`
|
|
57
|
+
+ `<text x="16" y="21.5" font-family="-apple-system,sans-serif" font-size="15" font-weight="600" fill="#fff" text-anchor="middle">${AssetsApi.escape_xml(letter)}</text></svg>`);
|
|
58
|
+
}
|
|
59
|
+
static data_url(svg) {
|
|
60
|
+
return `data:image/svg+xml,${encodeURIComponent(svg)}`;
|
|
61
|
+
}
|
|
62
|
+
static escape_xml(text) {
|
|
63
|
+
return text.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">");
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=assets.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assets.js","sourceRoot":"","sources":["../src/assets.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAGrC;;;;GAIG;AACH,MAAM,OAAO,SAAS;IAClB,2DAA2D;IAC3D,MAAM,CAAU,MAAM,GAAG,mBAAmB,CAAC;IAE7C,2DAA2D;IAC3D,MAAM,CAAU,mBAAmB,GAAiC;QAChE,MAAM,EAAE,GAAG;QACX,KAAK,EAAE,GAAG;QACV,GAAG,EAAE,GAAG;KACX,CAAC;IAEF,qEAAqE;IACrE,MAAM,CAAU,kBAAkB,GAAiC;QAC/D,MAAM,EAAE,SAAS;QACjB,KAAK,EAAE,SAAS;QAChB,GAAG,EAAE,SAAS;KACjB,CAAC;IAEF;;;OAGG;IACH,OAAO,CAAC,IAAkB;QACtB,IAAI,MAAM,CAAC,SAAS,EAAE,EAAE,CAAC;YACrB,OAAO,GAAG,SAAS,CAAC,MAAM,WAA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,CAAC,CAAC;IACzF,CAAC;CACJ"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import type { Unsubscribe } from "./events.js";
|
|
2
|
+
import type { JsonObject, ToolPhase, ToolPreview, ToolResult } from "./types.js";
|
|
3
|
+
/** A tool's run: does what the tool says and tells the assistant what came of it. */
|
|
4
|
+
export type ToolRun = (input: JsonObject) => ToolResult | Promise<ToolResult>;
|
|
5
|
+
/** A tool's preview: says in one line what the run would do, without doing it. */
|
|
6
|
+
export type ToolPreviewer = (input: JsonObject) => ToolPreview | Promise<ToolPreview>;
|
|
7
|
+
/**
|
|
8
|
+
* How a tool answers: one function taking the phase, or a run and, for a tool
|
|
9
|
+
* the manifest declares with `confirm: true`, a preview.
|
|
10
|
+
*/
|
|
11
|
+
export type ToolHandler = ((input: JsonObject, phase: ToolPhase) => ToolResult | ToolPreview | Promise<ToolResult | ToolPreview>) | {
|
|
12
|
+
run: ToolRun;
|
|
13
|
+
preview?: ToolPreviewer;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* The plugin's tools for RollRook's assistant. The manifest declares each
|
|
17
|
+
* under `contributes.raven.tools` with its name, description, input schema
|
|
18
|
+
* and whether it needs the user's approval; the background view answers
|
|
19
|
+
* them. RollRook calls `window.__rollrookTool(name, input, phase)` there and
|
|
20
|
+
* awaits the JSON it resolves with: for a tool declared with `confirm: true`
|
|
21
|
+
* first a `preview` (`{ summary }`, shown on a card), then a `run` once the
|
|
22
|
+
* user approves; for the others a `run` alone. A run's result may carry a
|
|
23
|
+
* `summary`, the line the conversation shows for the change, and
|
|
24
|
+
* `undo: { tool, input }`, which RollRook offers as Undo. RollRook names the
|
|
25
|
+
* tools to the assistant with a prefix (`tasks_add_task`); the page answers
|
|
26
|
+
* them by their own names.
|
|
27
|
+
*/
|
|
28
|
+
export declare class AssistantApi {
|
|
29
|
+
/** The global function RollRook calls to run a tool. */
|
|
30
|
+
static readonly RECEIVER_NAME = "__rollrookTool";
|
|
31
|
+
/** A tool's name, as the manifest takes it: snake_case words, a letter first. */
|
|
32
|
+
static readonly NAME_PATTERN: RegExp;
|
|
33
|
+
/** The longest a tool's name may be. */
|
|
34
|
+
static readonly NAME_MAX_LENGTH = 32;
|
|
35
|
+
private readonly map_handlers;
|
|
36
|
+
private readonly receiver;
|
|
37
|
+
/**
|
|
38
|
+
* Answer a tool the manifest declares.
|
|
39
|
+
*
|
|
40
|
+
* @param name - the tool's name, snake_case, as in `contributes.raven.tools`
|
|
41
|
+
* @param handler - the tool's run, and its preview when it asks for approval
|
|
42
|
+
* @returns a function that stops answering the tool
|
|
43
|
+
* @throws InvalidParamsError when the name is not snake_case
|
|
44
|
+
*/
|
|
45
|
+
tool(name: string, handler: ToolHandler): Unsubscribe;
|
|
46
|
+
/**
|
|
47
|
+
* Call a tool as RollRook does; `window.__rollrookTool` is this method.
|
|
48
|
+
*
|
|
49
|
+
* @param name - the tool's name
|
|
50
|
+
* @param input - its input, a JSON object (or its JSON text)
|
|
51
|
+
* @param phase - `preview` or `run`; `run` when not given
|
|
52
|
+
* @returns the preview's `{ summary }` or the run's result
|
|
53
|
+
* @throws UnknownMethodError for a tool the page does not answer, InvalidParamsError for bad input or a missing preview, FailedError for a result that is not a JSON object
|
|
54
|
+
*/
|
|
55
|
+
call(name: unknown, input: unknown, phase?: unknown): Promise<JsonObject>;
|
|
56
|
+
/**
|
|
57
|
+
* @returns the names of the tools this page answers
|
|
58
|
+
*/
|
|
59
|
+
list_tools(): string[];
|
|
60
|
+
/** Define `window.__rollrookTool` so RollRook's calls reach this object. */
|
|
61
|
+
install(): void;
|
|
62
|
+
private static input_record;
|
|
63
|
+
/**
|
|
64
|
+
* The error RollRook receives when a tool fails: its message begins with
|
|
65
|
+
* the code, as the bridge's own errors do (`invalid:`, `unknown:`,
|
|
66
|
+
* `failed:`), so the assistant can tell a bad input from a failure.
|
|
67
|
+
*
|
|
68
|
+
* @param err - what the tool threw
|
|
69
|
+
* @returns the error to reject with
|
|
70
|
+
*/
|
|
71
|
+
static rejection(err: unknown): Error;
|
|
72
|
+
private static preview_result;
|
|
73
|
+
private static run_result;
|
|
74
|
+
private static is_undo;
|
|
75
|
+
}
|
|
76
|
+
//# sourceMappingURL=assistant.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assistant.d.ts","sourceRoot":"","sources":["../src/assistant.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,KAAK,EAAE,UAAU,EAAa,SAAS,EAAE,WAAW,EAAE,UAAU,EAAY,MAAM,YAAY,CAAC;AAGtG,qFAAqF;AACrF,MAAM,MAAM,OAAO,GAAG,CAAC,KAAK,EAAE,UAAU,KAAK,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;AAE9E,kFAAkF;AAClF,MAAM,MAAM,aAAa,GAAG,CAAC,KAAK,EAAE,UAAU,KAAK,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;AAEtF;;;GAGG;AACH,MAAM,MAAM,WAAW,GACjB,CAAC,CAAC,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,SAAS,KAAK,UAAU,GAAG,WAAW,GAAG,OAAO,CAAC,UAAU,GAAG,WAAW,CAAC,CAAC,GACvG;IAAE,GAAG,EAAE,OAAO,CAAC;IAAC,OAAO,CAAC,EAAE,aAAa,CAAA;CAAE,CAAC;AAEhD;;;;;;;;;;;;GAYG;AACH,qBAAa,YAAY;IACrB,wDAAwD;IACxD,MAAM,CAAC,QAAQ,CAAC,aAAa,oBAAoB;IAEjD,iFAAiF;IACjF,MAAM,CAAC,QAAQ,CAAC,YAAY,SAAqC;IAEjE,wCAAwC;IACxC,MAAM,CAAC,QAAQ,CAAC,eAAe,MAAM;IAErC,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAkC;IAE/D,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAMvB;IAEF;;;;;;;OAOG;IACH,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,WAAW,GAAG,WAAW,CAWpD;IAED;;;;;;;;OAQG;IACG,IAAI,CAAC,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,GAAE,OAAe,GAAG,OAAO,CAAC,UAAU,CAAC,CAuBrF;IAED;;OAEG;IACH,UAAU,IAAI,MAAM,EAAE,CAErB;IAED,4EAA4E;IAC5E,OAAO,IAAI,IAAI,CAId;IAED,OAAO,CAAC,MAAM,CAAC,YAAY;IAkB3B;;;;;;;OAOG;IACH,MAAM,CAAC,SAAS,CAAC,GAAG,EAAE,OAAO,GAAG,KAAK,CAMpC;IAED,OAAO,CAAC,MAAM,CAAC,cAAc;IAQ7B,OAAO,CAAC,MAAM,CAAC,UAAU;IAezB,OAAO,CAAC,MAAM,CAAC,OAAO;CAMzB"}
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import { FailedError, InvalidParamsError, RollRookError, UnknownMethodError } from "./errors.js";
|
|
2
|
+
import { Wire } from "./wire.js";
|
|
3
|
+
/**
|
|
4
|
+
* The plugin's tools for RollRook's assistant. The manifest declares each
|
|
5
|
+
* under `contributes.raven.tools` with its name, description, input schema
|
|
6
|
+
* and whether it needs the user's approval; the background view answers
|
|
7
|
+
* them. RollRook calls `window.__rollrookTool(name, input, phase)` there and
|
|
8
|
+
* awaits the JSON it resolves with: for a tool declared with `confirm: true`
|
|
9
|
+
* first a `preview` (`{ summary }`, shown on a card), then a `run` once the
|
|
10
|
+
* user approves; for the others a `run` alone. A run's result may carry a
|
|
11
|
+
* `summary`, the line the conversation shows for the change, and
|
|
12
|
+
* `undo: { tool, input }`, which RollRook offers as Undo. RollRook names the
|
|
13
|
+
* tools to the assistant with a prefix (`tasks_add_task`); the page answers
|
|
14
|
+
* them by their own names.
|
|
15
|
+
*/
|
|
16
|
+
export class AssistantApi {
|
|
17
|
+
/** The global function RollRook calls to run a tool. */
|
|
18
|
+
static RECEIVER_NAME = "__rollrookTool";
|
|
19
|
+
/** A tool's name, as the manifest takes it: snake_case words, a letter first. */
|
|
20
|
+
static NAME_PATTERN = /^[a-z][a-z0-9]*(?:_[a-z0-9]+)*$/;
|
|
21
|
+
/** The longest a tool's name may be. */
|
|
22
|
+
static NAME_MAX_LENGTH = 32;
|
|
23
|
+
map_handlers = new Map();
|
|
24
|
+
receiver = async (name, input, phase) => {
|
|
25
|
+
try {
|
|
26
|
+
return await this.call(name, input, phase);
|
|
27
|
+
}
|
|
28
|
+
catch (err) {
|
|
29
|
+
throw AssistantApi.rejection(err);
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Answer a tool the manifest declares.
|
|
34
|
+
*
|
|
35
|
+
* @param name - the tool's name, snake_case, as in `contributes.raven.tools`
|
|
36
|
+
* @param handler - the tool's run, and its preview when it asks for approval
|
|
37
|
+
* @returns a function that stops answering the tool
|
|
38
|
+
* @throws InvalidParamsError when the name is not snake_case
|
|
39
|
+
*/
|
|
40
|
+
tool(name, handler) {
|
|
41
|
+
if (!AssistantApi.NAME_PATTERN.test(name) || name.length > AssistantApi.NAME_MAX_LENGTH) {
|
|
42
|
+
throw new InvalidParamsError(`${name} is not a tool name: snake_case, at most ${AssistantApi.NAME_MAX_LENGTH} characters`);
|
|
43
|
+
}
|
|
44
|
+
this.install();
|
|
45
|
+
this.map_handlers.set(name, handler);
|
|
46
|
+
return () => {
|
|
47
|
+
if (this.map_handlers.get(name) === handler) {
|
|
48
|
+
this.map_handlers.delete(name);
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Call a tool as RollRook does; `window.__rollrookTool` is this method.
|
|
54
|
+
*
|
|
55
|
+
* @param name - the tool's name
|
|
56
|
+
* @param input - its input, a JSON object (or its JSON text)
|
|
57
|
+
* @param phase - `preview` or `run`; `run` when not given
|
|
58
|
+
* @returns the preview's `{ summary }` or the run's result
|
|
59
|
+
* @throws UnknownMethodError for a tool the page does not answer, InvalidParamsError for bad input or a missing preview, FailedError for a result that is not a JSON object
|
|
60
|
+
*/
|
|
61
|
+
async call(name, input, phase = "run") {
|
|
62
|
+
if (typeof name !== "string") {
|
|
63
|
+
throw new InvalidParamsError("the tool's name is not a string");
|
|
64
|
+
}
|
|
65
|
+
const handler = this.map_handlers.get(name);
|
|
66
|
+
if (handler === undefined) {
|
|
67
|
+
throw new UnknownMethodError(`no tool ${name} in this page`);
|
|
68
|
+
}
|
|
69
|
+
if (phase !== "preview" && phase !== "run") {
|
|
70
|
+
throw new InvalidParamsError(`${String(phase)} is not a phase: preview or run`);
|
|
71
|
+
}
|
|
72
|
+
const record = AssistantApi.input_record(input);
|
|
73
|
+
let result;
|
|
74
|
+
if (typeof handler === "function") {
|
|
75
|
+
result = await handler(record, phase);
|
|
76
|
+
}
|
|
77
|
+
else if (phase === "run") {
|
|
78
|
+
result = await handler.run(record);
|
|
79
|
+
}
|
|
80
|
+
else if (handler.preview === undefined) {
|
|
81
|
+
throw new InvalidParamsError(`the tool ${name} has no preview`);
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
result = await handler.preview(record);
|
|
85
|
+
}
|
|
86
|
+
return phase === "preview" ? AssistantApi.preview_result(name, result) : AssistantApi.run_result(name, result);
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* @returns the names of the tools this page answers
|
|
90
|
+
*/
|
|
91
|
+
list_tools() {
|
|
92
|
+
return [...this.map_handlers.keys()].sort();
|
|
93
|
+
}
|
|
94
|
+
/** Define `window.__rollrookTool` so RollRook's calls reach this object. */
|
|
95
|
+
install() {
|
|
96
|
+
if (Reflect.get(globalThis, AssistantApi.RECEIVER_NAME) !== this.receiver) {
|
|
97
|
+
Reflect.set(globalThis, AssistantApi.RECEIVER_NAME, this.receiver);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
static input_record(input) {
|
|
101
|
+
let value = input ?? {};
|
|
102
|
+
if (typeof value === "string") {
|
|
103
|
+
try {
|
|
104
|
+
value = JSON.parse(value);
|
|
105
|
+
}
|
|
106
|
+
catch (err) {
|
|
107
|
+
if (err instanceof SyntaxError) {
|
|
108
|
+
throw new InvalidParamsError(`the tool's input is not JSON: ${err.message}`);
|
|
109
|
+
}
|
|
110
|
+
throw err;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
if (!Wire.is_record(value) || !Wire.is_json(value)) {
|
|
114
|
+
throw new InvalidParamsError("the tool's input is not a JSON object");
|
|
115
|
+
}
|
|
116
|
+
return value;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* The error RollRook receives when a tool fails: its message begins with
|
|
120
|
+
* the code, as the bridge's own errors do (`invalid:`, `unknown:`,
|
|
121
|
+
* `failed:`), so the assistant can tell a bad input from a failure.
|
|
122
|
+
*
|
|
123
|
+
* @param err - what the tool threw
|
|
124
|
+
* @returns the error to reject with
|
|
125
|
+
*/
|
|
126
|
+
static rejection(err) {
|
|
127
|
+
if (err instanceof RollRookError) {
|
|
128
|
+
return new Error(`${err.code}: ${err.message}`, { cause: err });
|
|
129
|
+
}
|
|
130
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
131
|
+
return new Error(`failed: ${message}`, { cause: err });
|
|
132
|
+
}
|
|
133
|
+
static preview_result(name, result) {
|
|
134
|
+
if (!Wire.is_record(result) || typeof result["summary"] !== "string" || result["summary"].trim() === "") {
|
|
135
|
+
throw new FailedError(`the preview of ${name} did not return { summary }`);
|
|
136
|
+
}
|
|
137
|
+
const preview = { summary: result["summary"] };
|
|
138
|
+
return { ...preview };
|
|
139
|
+
}
|
|
140
|
+
static run_result(name, result) {
|
|
141
|
+
if (!Wire.is_record(result) || !Wire.is_json(result)) {
|
|
142
|
+
throw new FailedError(`the tool ${name} did not return a JSON object`);
|
|
143
|
+
}
|
|
144
|
+
const undo = result["undo"];
|
|
145
|
+
if (undo !== undefined && !AssistantApi.is_undo(undo)) {
|
|
146
|
+
throw new FailedError(`the undo of ${name} is not { tool, input }`);
|
|
147
|
+
}
|
|
148
|
+
const summary = result["summary"];
|
|
149
|
+
if (summary !== undefined && typeof summary !== "string") {
|
|
150
|
+
throw new FailedError(`the summary of ${name} is not a string`);
|
|
151
|
+
}
|
|
152
|
+
return result;
|
|
153
|
+
}
|
|
154
|
+
static is_undo(value) {
|
|
155
|
+
return Wire.is_record(value)
|
|
156
|
+
&& typeof value["tool"] === "string"
|
|
157
|
+
&& AssistantApi.NAME_PATTERN.test(value["tool"])
|
|
158
|
+
&& Wire.is_record(value["input"]);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
//# sourceMappingURL=assistant.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assistant.js","sourceRoot":"","sources":["../src/assistant.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,kBAAkB,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAGjG,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAgBjC;;;;;;;;;;;;GAYG;AACH,MAAM,OAAO,YAAY;IACrB,wDAAwD;IACxD,MAAM,CAAU,aAAa,GAAG,gBAAgB,CAAC;IAEjD,iFAAiF;IACjF,MAAM,CAAU,YAAY,GAAG,iCAAiC,CAAC;IAEjE,wCAAwC;IACxC,MAAM,CAAU,eAAe,GAAG,EAAE,CAAC;IAEpB,YAAY,GAAG,IAAI,GAAG,EAAuB,CAAC;IAE9C,QAAQ,GAAG,KAAK,EAAE,IAAa,EAAE,KAAc,EAAE,KAAc,EAAuB,EAAE;QACrG,IAAI,CAAC;YACD,OAAO,MAAM,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;QAC/C,CAAC;QAAC,OAAO,GAAY,EAAE,CAAC;YACpB,MAAM,YAAY,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;QACtC,CAAC;IACL,CAAC,CAAC;IAEF;;;;;;;OAOG;IACH,IA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+
/**
|
|
3
|
+
* RollRook's mixer: the sound of each app and Chrome tab, and its meters.
|
|
4
|
+
* Needs the `audio` permission. Changes arrive as `audio.tracks`, meters as
|
|
5
|
+
* `audio.levels`.
|
|
6
|
+
*/
|
|
7
|
+
export declare class AudioApi {
|
|
8
|
+
/**
|
|
9
|
+
* @returns whether the mixer is on and may capture sound
|
|
10
|
+
*/
|
|
11
|
+
status(): Promise<AudioStatus>;
|
|
12
|
+
/**
|
|
13
|
+
* Turn the mixer on or off.
|
|
14
|
+
*
|
|
15
|
+
* @param is_enabled - whether it should be on
|
|
16
|
+
*/
|
|
17
|
+
enable(is_enabled: boolean): Promise<void>;
|
|
18
|
+
/**
|
|
19
|
+
* Ask macOS for permission to capture sound.
|
|
20
|
+
*
|
|
21
|
+
* @returns whether it is granted
|
|
22
|
+
*/
|
|
23
|
+
request_permission(): Promise<boolean>;
|
|
24
|
+
/**
|
|
25
|
+
* @returns the tracks the mixer shows
|
|
26
|
+
*/
|
|
27
|
+
list(): Promise<AudioTrack[]>;
|
|
28
|
+
/**
|
|
29
|
+
* Change some of a track's settings; RollRook clamps each value.
|
|
30
|
+
*
|
|
31
|
+
* @param target - the track
|
|
32
|
+
* @param settings - the settings to change
|
|
33
|
+
*/
|
|
34
|
+
update(target: AudioTarget, settings: Partial<AudioSettings>): Promise<void>;
|
|
35
|
+
/**
|
|
36
|
+
* Put a track's settings back as they were.
|
|
37
|
+
*
|
|
38
|
+
* @param target - the track
|
|
39
|
+
*/
|
|
40
|
+
reset(target: AudioTarget): Promise<void>;
|
|
41
|
+
/**
|
|
42
|
+
* Start or stop the meters: `audio.levels` arrives while they are on and the view shows.
|
|
43
|
+
*
|
|
44
|
+
* @param is_on - whether the meters run
|
|
45
|
+
*/
|
|
46
|
+
meters(is_on: boolean): Promise<void>;
|
|
47
|
+
/**
|
|
48
|
+
* The key a track's levels arrive under in `audio.levels`.
|
|
49
|
+
*
|
|
50
|
+
* @param target - the track
|
|
51
|
+
* @returns `app:<bundleId>` or `tab:<sessionId>:<tabId>`
|
|
52
|
+
*/
|
|
53
|
+
static level_key(target: AudioTarget): string;
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=audio.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"audio.d.ts","sourceRoot":"","sources":["../src/audio.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAGtF;;;;GAIG;AACH,qBAAa,QAAQ;IACjB;;OAEG;IACG,MAAM,IAAI,OAAO,CAAC,WAAW,CAAC,CAMnC;IAED;;;;OAIG;IACG,MAAM,CAAC,UAAU,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAE/C;IAED;;;;OAIG;IACG,kBAAkB,IAAI,OAAO,CAAC,OAAO,CAAC,CAG3C;IAED;;OAEG;IACG,IAAI,IAAI,OAAO,CAAC,UAAU,EAAE,CAAC,CAElC;IAED;;;;;OAKG;IACG,MAAM,CAAC,MAAM,EAAE,WAAW,EAAE,QAAQ,EAAE,OAAO,CAAC,aAAa,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAKjF;IAED;;;;OAIG;IACG,KAAK,CAAC,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAE9C;IAED;;;;OAIG;IACG,MAAM,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAE1C;IAED;;;;;OAKG;IACH,MAAM,CAAC,SAAS,CAAC,MAAM,EAAE,WAAW,GAAG,MAAM,CAI5C;CACJ"}
|
package/dist/audio.js
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { Bridge } from "./bridge.js";
|
|
2
|
+
import { Wire } from "./wire.js";
|
|
3
|
+
/**
|
|
4
|
+
* RollRook's mixer: the sound of each app and Chrome tab, and its meters.
|
|
5
|
+
* Needs the `audio` permission. Changes arrive as `audio.tracks`, meters as
|
|
6
|
+
* `audio.levels`.
|
|
7
|
+
*/
|
|
8
|
+
export class AudioApi {
|
|
9
|
+
/**
|
|
10
|
+
* @returns whether the mixer is on and may capture sound
|
|
11
|
+
*/
|
|
12
|
+
async status() {
|
|
13
|
+
const record = Wire.record(await Bridge.call("audio.status"), "audio.status reply");
|
|
14
|
+
return {
|
|
15
|
+
is_enabled: Wire.boolean(record, "isEnabled", "audio.status reply"),
|
|
16
|
+
is_permitted: Wire.boolean(record, "isPermitted", "audio.status reply"),
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Turn the mixer on or off.
|
|
21
|
+
*
|
|
22
|
+
* @param is_enabled - whether it should be on
|
|
23
|
+
*/
|
|
24
|
+
async enable(is_enabled) {
|
|
25
|
+
await Bridge.call("audio.enable", { isEnabled: is_enabled });
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Ask macOS for permission to capture sound.
|
|
29
|
+
*
|
|
30
|
+
* @returns whether it is granted
|
|
31
|
+
*/
|
|
32
|
+
async request_permission() {
|
|
33
|
+
const record = Wire.record(await Bridge.call("audio.requestPermission"), "audio.requestPermission reply");
|
|
34
|
+
return Wire.boolean(record, "isPermitted", "audio.requestPermission reply");
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* @returns the tracks the mixer shows
|
|
38
|
+
*/
|
|
39
|
+
async list() {
|
|
40
|
+
return Wire.audio_tracks(await Bridge.call("audio.list")).list_tracks;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Change some of a track's settings; RollRook clamps each value.
|
|
44
|
+
*
|
|
45
|
+
* @param target - the track
|
|
46
|
+
* @param settings - the settings to change
|
|
47
|
+
*/
|
|
48
|
+
async update(target, settings) {
|
|
49
|
+
await Bridge.call("audio.update", {
|
|
50
|
+
target: Wire.audio_target_to_wire(target),
|
|
51
|
+
settings: Wire.audio_settings_to_wire(settings),
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Put a track's settings back as they were.
|
|
56
|
+
*
|
|
57
|
+
* @param target - the track
|
|
58
|
+
*/
|
|
59
|
+
async reset(target) {
|
|
60
|
+
await Bridge.call("audio.reset", { target: Wire.audio_target_to_wire(target) });
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Start or stop the meters: `audio.levels` arrives while they are on and the view shows.
|
|
64
|
+
*
|
|
65
|
+
* @param is_on - whether the meters run
|
|
66
|
+
*/
|
|
67
|
+
async meters(is_on) {
|
|
68
|
+
await Bridge.call("audio.meters", { isOn: is_on });
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* The key a track's levels arrive under in `audio.levels`.
|
|
72
|
+
*
|
|
73
|
+
* @param target - the track
|
|
74
|
+
* @returns `app:<bundleId>` or `tab:<sessionId>:<tabId>`
|
|
75
|
+
*/
|
|
76
|
+
static level_key(target) {
|
|
77
|
+
return target.kind === "app"
|
|
78
|
+
? `app:${target.bundle_id}`
|
|
79
|
+
: `tab:${target.session_id}:${target.tab_id}`;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
//# sourceMappingURL=audio.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"audio.js","sourceRoot":"","sources":["../src/audio.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC;;;;GAIG;AACH,MAAM,OAAO,QAAQ;IACjB;;OAEG;IACH,KAAK,CAAC,MAAM;QACR,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC,EAAE,oBAAoB,CAAC,CAAC;QACpF,OAAO;YACH,UAAU,EAAE,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,WAAW,EAAE,oBAAoB,CAAC;YACnE,YAAY,EAAE,IAAI,CAAC,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;;;;;OAKG;IACH,MAAM,CAAC,SAAS,CAAC,MAAmB;QAChC,OAAO,MAAM,CAAC,IAAI,KAAK,KAAK;YACxB,CAAC,CAAC,OAAO,MAAM,CAAC,SAAS,EAAE;YAC3B,CAAC,CAAC,OAAO,MAAM,CAAC,UAAU,IAAI,MAAM,CAAC,MAAM,EAAE,CAAC;IACtD,CAAC;CACJ"}
|
package/dist/bridge.d.ts
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { JsonObject } from "./types.js";
|
|
2
|
+
/** What the page posts to RollRook's message handler. */
|
|
3
|
+
export interface BridgeMessage {
|
|
4
|
+
method: string;
|
|
5
|
+
params: JsonObject;
|
|
6
|
+
}
|
|
7
|
+
/** The message handler RollRook installs: `window.webkit.messageHandlers.rollrook`. */
|
|
8
|
+
export interface BridgeHandler {
|
|
9
|
+
postMessage(message: BridgeMessage): Promise<unknown>;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* The one channel between a plugin page and RollRook. Every module of the SDK
|
|
13
|
+
* calls through it; plugins rarely need it directly.
|
|
14
|
+
*/
|
|
15
|
+
export declare class Bridge {
|
|
16
|
+
/** The name of RollRook's script message handler. */
|
|
17
|
+
static readonly HANDLER_NAME = "rollrook";
|
|
18
|
+
/** The property a mock host sets on its handler, so the SDK can tell it from RollRook. */
|
|
19
|
+
static readonly MOCK_MARKER = "isMock";
|
|
20
|
+
/** The bridge protocol this SDK speaks. */
|
|
21
|
+
static readonly PROTOCOL = 1;
|
|
22
|
+
/**
|
|
23
|
+
* Find RollRook's message handler on the page.
|
|
24
|
+
*
|
|
25
|
+
* @returns the handler, or undefined outside RollRook and without a mock host
|
|
26
|
+
*/
|
|
27
|
+
static handler(): BridgeHandler | undefined;
|
|
28
|
+
/**
|
|
29
|
+
* Whether the page can reach a host, RollRook's or a mock's.
|
|
30
|
+
*
|
|
31
|
+
* @returns true when a handler is installed
|
|
32
|
+
*/
|
|
33
|
+
static is_available(): boolean;
|
|
34
|
+
/**
|
|
35
|
+
* Whether the page runs inside RollRook itself, not a mock host.
|
|
36
|
+
*
|
|
37
|
+
* @returns true when RollRook's own handler is installed
|
|
38
|
+
*/
|
|
39
|
+
static is_native(): boolean;
|
|
40
|
+
/**
|
|
41
|
+
* Call a bridge method.
|
|
42
|
+
*
|
|
43
|
+
* @param method - the method's name, e.g. `storage.get`
|
|
44
|
+
* @param params - the method's parameters
|
|
45
|
+
* @returns the method's result, unchecked
|
|
46
|
+
* @throws RollRookError, of the subclass matching the host's error code
|
|
47
|
+
*/
|
|
48
|
+
static call(method: string, params?: JsonObject): Promise<unknown>;
|
|
49
|
+
private static is_handler;
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=bridge.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bridge.d.ts","sourceRoot":"","sources":["../src/bridge.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAG7C,yDAAyD;AACzD,MAAM,WAAW,aAAa;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,UAAU,CAAC;CACtB;AAED,uFAAuF;AACvF,MAAM,WAAW,aAAa;IAC1B,WAAW,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CACzD;AAED;;;GAGG;AACH,qBAAa,MAAM;IACf,qDAAqD;IACrD,MAAM,CAAC,QAAQ,CAAC,YAAY,cAAc;IAE1C,0FAA0F;IAC1F,MAAM,CAAC,QAAQ,CAAC,WAAW,YAAY;IAEvC,2CAA2C;IAC3C,MAAM,CAAC,QAAQ,CAAC,QAAQ,KAAK;IAE7B;;;;OAIG;IACH,MAAM,CAAC,OAAO,IAAI,aAAa,GAAG,SAAS,CAW1C;IAED;;;;OAIG;IACH,MAAM,CAAC,YAAY,IAAI,OAAO,CAE7B;IAED;;;;OAIG;IACH,MAAM,CAAC,SAAS,IAAI,OAAO,CAG1B;IAED;;;;;;;OAOG;IACH,OAAa,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,GAAE,UAAe,GAAG,OAAO,CAAC,OAAO,CAAC,CAgB3E;IAED,OAAO,CAAC,MAAM,CAAC,UAAU;CAG5B"}
|