@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.
Files changed (143) hide show
  1. package/dist/agents.d.ts +9 -0
  2. package/dist/agents.d.ts.map +1 -0
  3. package/dist/agents.js +13 -0
  4. package/dist/agents.js.map +1 -0
  5. package/dist/assets.d.ts +35 -0
  6. package/dist/assets.d.ts.map +1 -0
  7. package/dist/assets.js +66 -0
  8. package/dist/assets.js.map +1 -0
  9. package/dist/assistant.d.ts +76 -0
  10. package/dist/assistant.d.ts.map +1 -0
  11. package/dist/assistant.js +161 -0
  12. package/dist/assistant.js.map +1 -0
  13. package/dist/audio.d.ts +55 -0
  14. package/dist/audio.d.ts.map +1 -0
  15. package/dist/audio.js +82 -0
  16. package/dist/audio.js.map +1 -0
  17. package/dist/bridge.d.ts +51 -0
  18. package/dist/bridge.d.ts.map +1 -0
  19. package/dist/bridge.js +78 -0
  20. package/dist/bridge.js.map +1 -0
  21. package/dist/calendar.d.ts +33 -0
  22. package/dist/calendar.d.ts.map +1 -0
  23. package/dist/calendar.js +63 -0
  24. package/dist/calendar.js.map +1 -0
  25. package/dist/context.d.ts +19 -0
  26. package/dist/context.d.ts.map +1 -0
  27. package/dist/context.js +25 -0
  28. package/dist/context.js.map +1 -0
  29. package/dist/errors.d.ts +74 -0
  30. package/dist/errors.d.ts.map +1 -0
  31. package/dist/errors.js +111 -0
  32. package/dist/errors.js.map +1 -0
  33. package/dist/events.d.ts +36 -0
  34. package/dist/events.d.ts.map +1 -0
  35. package/dist/events.js +81 -0
  36. package/dist/events.js.map +1 -0
  37. package/dist/files.d.ts +29 -0
  38. package/dist/files.d.ts.map +1 -0
  39. package/dist/files.js +43 -0
  40. package/dist/files.js.map +1 -0
  41. package/dist/index.d.ts +84 -0
  42. package/dist/index.d.ts.map +1 -0
  43. package/dist/index.js +78 -0
  44. package/dist/index.js.map +1 -0
  45. package/dist/mock/index.d.ts +4 -0
  46. package/dist/mock/index.d.ts.map +1 -0
  47. package/dist/mock/index.js +3 -0
  48. package/dist/mock/index.js.map +1 -0
  49. package/dist/mock/mock-host.d.ts +255 -0
  50. package/dist/mock/mock-host.d.ts.map +1 -0
  51. package/dist/mock/mock-host.js +1274 -0
  52. package/dist/mock/mock-host.js.map +1 -0
  53. package/dist/mock/samples.d.ts +56 -0
  54. package/dist/mock/samples.d.ts.map +1 -0
  55. package/dist/mock/samples.js +283 -0
  56. package/dist/mock/samples.js.map +1 -0
  57. package/dist/mock/toolbar.d.ts +95 -0
  58. package/dist/mock/toolbar.d.ts.map +1 -0
  59. package/dist/mock/toolbar.js +279 -0
  60. package/dist/mock/toolbar.js.map +1 -0
  61. package/dist/net.d.ts +13 -0
  62. package/dist/net.d.ts.map +1 -0
  63. package/dist/net.js +26 -0
  64. package/dist/net.js.map +1 -0
  65. package/dist/plugin.d.ts +11 -0
  66. package/dist/plugin.d.ts.map +1 -0
  67. package/dist/plugin.js +13 -0
  68. package/dist/plugin.js.map +1 -0
  69. package/dist/raven.d.ts +51 -0
  70. package/dist/raven.d.ts.map +1 -0
  71. package/dist/raven.js +100 -0
  72. package/dist/raven.js.map +1 -0
  73. package/dist/segment-display.d.ts +93 -0
  74. package/dist/segment-display.d.ts.map +1 -0
  75. package/dist/segment-display.js +324 -0
  76. package/dist/segment-display.js.map +1 -0
  77. package/dist/settings.d.ts +19 -0
  78. package/dist/settings.d.ts.map +1 -0
  79. package/dist/settings.js +27 -0
  80. package/dist/settings.js.map +1 -0
  81. package/dist/storage.d.ts +28 -0
  82. package/dist/storage.d.ts.map +1 -0
  83. package/dist/storage.js +54 -0
  84. package/dist/storage.js.map +1 -0
  85. package/dist/system.d.ts +19 -0
  86. package/dist/system.d.ts.map +1 -0
  87. package/dist/system.js +24 -0
  88. package/dist/system.js.map +1 -0
  89. package/dist/theme.d.ts +51 -0
  90. package/dist/theme.d.ts.map +1 -0
  91. package/dist/theme.js +85 -0
  92. package/dist/theme.js.map +1 -0
  93. package/dist/types.d.ts +278 -0
  94. package/dist/types.d.ts.map +1 -0
  95. package/dist/types.js +2 -0
  96. package/dist/types.js.map +1 -0
  97. package/dist/ui.d.ts +57 -0
  98. package/dist/ui.d.ts.map +1 -0
  99. package/dist/ui.js +78 -0
  100. package/dist/ui.js.map +1 -0
  101. package/dist/usage.d.ts +14 -0
  102. package/dist/usage.d.ts.map +1 -0
  103. package/dist/usage.js +19 -0
  104. package/dist/usage.js.map +1 -0
  105. package/dist/video.d.ts +11 -0
  106. package/dist/video.d.ts.map +1 -0
  107. package/dist/video.js +17 -0
  108. package/dist/video.js.map +1 -0
  109. package/dist/wire.d.ts +214 -0
  110. package/dist/wire.d.ts.map +1 -0
  111. package/dist/wire.js +538 -0
  112. package/dist/wire.js.map +1 -0
  113. package/package.json +39 -4
  114. package/src/agents.ts +14 -0
  115. package/src/assets.ts +80 -0
  116. package/src/assistant.ts +185 -0
  117. package/src/audio.ts +90 -0
  118. package/src/bridge.ts +96 -0
  119. package/src/calendar.ts +68 -0
  120. package/src/context.ts +28 -0
  121. package/src/errors.ts +131 -0
  122. package/src/events.ts +90 -0
  123. package/src/files.ts +47 -0
  124. package/src/index.ts +152 -0
  125. package/src/mock/index.ts +3 -0
  126. package/src/mock/mock-host.ts +1408 -0
  127. package/src/mock/samples.ts +300 -0
  128. package/src/mock/toolbar.ts +321 -0
  129. package/src/net.ts +27 -0
  130. package/src/plugin.ts +14 -0
  131. package/src/raven.ts +116 -0
  132. package/src/segment-display.ts +377 -0
  133. package/src/settings.ts +29 -0
  134. package/src/storage.ts +59 -0
  135. package/src/system.ts +26 -0
  136. package/src/theme.ts +97 -0
  137. package/src/types.ts +327 -0
  138. package/src/ui.ts +88 -0
  139. package/src/usage.ts +21 -0
  140. package/src/video.ts +17 -0
  141. package/src/wire.ts +608 -0
  142. package/theme.css +407 -0
  143. package/README.md +0 -3
package/src/events.ts ADDED
@@ -0,0 +1,90 @@
1
+ import type { EventMap, EventName } from "./types.js";
2
+ import { Wire } from "./wire.js";
3
+
4
+ /** A function that removes the handler it was returned for. */
5
+ export type Unsubscribe = () => void;
6
+
7
+ /**
8
+ * The events RollRook delivers by calling `window.__rollrookEvent(name, payload)`.
9
+ * The SDK installs the receiver as it loads, since RollRook sends events only
10
+ * after the page has loaded.
11
+ */
12
+ export class Events {
13
+ /** The global function RollRook calls to deliver an event. */
14
+ static readonly RECEIVER_NAME = "__rollrookEvent";
15
+
16
+ private static readonly map_parsers: { [K in EventName]: (raw: unknown) => EventMap[K] } = {
17
+ "theme": (raw: unknown) => Wire.theme(raw),
18
+ "visibility": (raw: unknown) => Wire.visibility(raw),
19
+ "settings.changed": (raw: unknown) => Wire.setting_values(raw),
20
+ "message": (raw: unknown) => Wire.plugin_message(raw),
21
+ "raven.turn": (raw: unknown) => Wire.raven_turn(raw),
22
+ "usage.changed": (raw: unknown) => Wire.usage_snapshot(raw),
23
+ "audio.tracks": (raw: unknown) => Wire.audio_tracks(raw),
24
+ "audio.levels": (raw: unknown) => Wire.audio_levels(raw),
25
+ "calendar.open": (raw: unknown) => Wire.calendar_open(raw),
26
+ "calendar.move": (raw: unknown) => Wire.calendar_move(raw),
27
+ };
28
+
29
+ private readonly map_listeners = new Map<string, Set<(raw: unknown) => void>>();
30
+
31
+ private readonly receiver = (name: unknown, payload: unknown): void => {
32
+ if (typeof name === "string") {
33
+ this.dispatch(name, payload);
34
+ }
35
+ };
36
+
37
+ /**
38
+ * Subscribe to an event.
39
+ *
40
+ * @param name - the event's name
41
+ * @param handler - called with each delivery's payload
42
+ * @returns a function that unsubscribes the handler
43
+ */
44
+ on<K extends EventName>(name: K, handler: (payload: EventMap[K]) => void): Unsubscribe {
45
+ this.install();
46
+ const parse = Events.map_parsers[name];
47
+ const listener = (raw: unknown): void => handler(parse(raw));
48
+ let set_listeners = this.map_listeners.get(name);
49
+ if (set_listeners === undefined) {
50
+ set_listeners = new Set();
51
+ this.map_listeners.set(name, set_listeners);
52
+ }
53
+ set_listeners.add(listener);
54
+ return () => {
55
+ this.map_listeners.get(name)?.delete(listener);
56
+ };
57
+ }
58
+
59
+ /**
60
+ * Deliver an event to its handlers, as RollRook does through
61
+ * `window.__rollrookEvent`. Events the SDK does not know are ignored. A
62
+ * handler that throws does not stop the others; its error is reported as
63
+ * uncaught.
64
+ *
65
+ * @param name - the event's name
66
+ * @param payload - the payload in wire form
67
+ */
68
+ dispatch(name: string, payload: unknown): void {
69
+ const set_listeners = this.map_listeners.get(name);
70
+ if (set_listeners === undefined) {
71
+ return;
72
+ }
73
+ for (const listener of [...set_listeners]) {
74
+ try {
75
+ listener(payload);
76
+ } catch (err: unknown) {
77
+ queueMicrotask(() => {
78
+ throw err;
79
+ });
80
+ }
81
+ }
82
+ }
83
+
84
+ /** Define `window.__rollrookEvent` so RollRook's deliveries reach this object. */
85
+ install(): void {
86
+ if (Reflect.get(globalThis, Events.RECEIVER_NAME) !== this.receiver) {
87
+ Reflect.set(globalThis, Events.RECEIVER_NAME, this.receiver);
88
+ }
89
+ }
90
+ }
package/src/files.ts ADDED
@@ -0,0 +1,47 @@
1
+ import { Bridge } from "./bridge.js";
2
+ import type { FileEntry } from "./types.js";
3
+ import { Wire } from "./wire.js";
4
+
5
+ /**
6
+ * Text files in the plugin's own data folder. Paths are relative to that
7
+ * folder; `..`, absolute paths and links out of it are refused.
8
+ */
9
+ export class FilesApi {
10
+ /**
11
+ * @param path - the file's path
12
+ * @returns the file's text
13
+ */
14
+ async read(path: string): Promise<string> {
15
+ const record = Wire.record(await Bridge.call("files.read", { path }), "files.read reply");
16
+ return Wire.string(record, "text", "files.read reply");
17
+ }
18
+
19
+ /**
20
+ * Write a file, replacing what it held.
21
+ *
22
+ * @param path - the file's path
23
+ * @param text - the file's new text
24
+ */
25
+ async write(path: string, text: string): Promise<void> {
26
+ await Bridge.call("files.write", {
27
+ path,
28
+ text,
29
+ });
30
+ }
31
+
32
+ /**
33
+ * @param path - the folder's path, `""` for the data folder itself
34
+ * @returns the folder's entries
35
+ */
36
+ async list(path = ""): Promise<FileEntry[]> {
37
+ const record = Wire.record(await Bridge.call("files.list", { path }), "files.list reply");
38
+ return Wire.array(record, "entries", "files.list reply").map((entry: unknown) => Wire.file_entry(entry));
39
+ }
40
+
41
+ /**
42
+ * @param path - the path to delete
43
+ */
44
+ async delete(path: string): Promise<void> {
45
+ await Bridge.call("files.delete", { path });
46
+ }
47
+ }
package/src/index.ts ADDED
@@ -0,0 +1,152 @@
1
+ import { AgentsApi } from "./agents.js";
2
+ import { AssetsApi } from "./assets.js";
3
+ import { AssistantApi } from "./assistant.js";
4
+ import { AudioApi } from "./audio.js";
5
+ import { CalendarApi } from "./calendar.js";
6
+ import { ContextApi } from "./context.js";
7
+ import { Events } from "./events.js";
8
+ import { FilesApi } from "./files.js";
9
+ import { NetApi } from "./net.js";
10
+ import { PluginApi } from "./plugin.js";
11
+ import { RavenApi } from "./raven.js";
12
+ import { SettingsApi } from "./settings.js";
13
+ import { StorageApi } from "./storage.js";
14
+ import { SystemApi } from "./system.js";
15
+ import { ThemeApi } from "./theme.js";
16
+ import { UiApi } from "./ui.js";
17
+ import { UsageApi } from "./usage.js";
18
+ import { VideoApi } from "./video.js";
19
+
20
+ export { AgentsApi } from "./agents.js";
21
+ export { AssetsApi } from "./assets.js";
22
+ export { AssistantApi } from "./assistant.js";
23
+ export type { ToolHandler, ToolPreviewer, ToolRun } from "./assistant.js";
24
+ export { AudioApi } from "./audio.js";
25
+ export { Bridge } from "./bridge.js";
26
+ export type { BridgeHandler, BridgeMessage } from "./bridge.js";
27
+ export { CalendarApi } from "./calendar.js";
28
+ export { ContextApi } from "./context.js";
29
+ export {
30
+ BridgeUnavailableError,
31
+ FailedError,
32
+ InvalidParamsError,
33
+ PermissionError,
34
+ RollRookError,
35
+ UnknownMethodError,
36
+ } from "./errors.js";
37
+ export type { ErrorCode } from "./errors.js";
38
+ export { Events } from "./events.js";
39
+ export type { Unsubscribe } from "./events.js";
40
+ export { FilesApi } from "./files.js";
41
+ export { NetApi } from "./net.js";
42
+ export { PluginApi } from "./plugin.js";
43
+ export { RavenApi } from "./raven.js";
44
+ export type { RavenWaitOptions } from "./raven.js";
45
+ export { SegmentDisplay } from "./segment-display.js";
46
+ export type { Segment, SegmentDisplayOptions, SegmentPoint } from "./segment-display.js";
47
+ export { SettingsApi } from "./settings.js";
48
+ export { StorageApi } from "./storage.js";
49
+ export { SystemApi } from "./system.js";
50
+ export { ThemeApi } from "./theme.js";
51
+ export type {
52
+ AgentHarness,
53
+ AgentSession,
54
+ AudioLevel,
55
+ AudioLevels,
56
+ AudioSettings,
57
+ AudioStatus,
58
+ AudioTarget,
59
+ AudioTrack,
60
+ AudioTracksChange,
61
+ CalendarItem,
62
+ CalendarMove,
63
+ CalendarOpen,
64
+ City,
65
+ EventMap,
66
+ EventName,
67
+ FetchRequest,
68
+ FetchResponse,
69
+ FileEntry,
70
+ JsonObject,
71
+ JsonValue,
72
+ KnownAgentState,
73
+ PluginContext,
74
+ PluginMessage,
75
+ RavenAnswer,
76
+ RavenTurn,
77
+ ReverbRoom,
78
+ SettingValues,
79
+ SettingsPane,
80
+ Theme,
81
+ ThemeColors,
82
+ ToolPhase,
83
+ ToolPreview,
84
+ ToolResult,
85
+ ToolUndo,
86
+ UsageAccount,
87
+ UsageLimit,
88
+ UsageSeverity,
89
+ UsageSnapshot,
90
+ ViewSlot,
91
+ VisibilityChange,
92
+ } from "./types.js";
93
+ export { UiApi } from "./ui.js";
94
+ export { UsageApi } from "./usage.js";
95
+ export { VideoApi } from "./video.js";
96
+ export { Wire } from "./wire.js";
97
+
98
+ /** RollRook's events: `events.on(name, handler)` returns an unsubscribe. */
99
+ export const events = new Events();
100
+
101
+ events.install();
102
+
103
+ /** The plugin's identity and the app it runs in. */
104
+ export const context = new ContextApi();
105
+
106
+ /** The settings the manifest declares. */
107
+ export const settings = new SettingsApi();
108
+
109
+ /** Small JSON values by key. */
110
+ export const storage = new StorageApi();
111
+
112
+ /** Text files in the plugin's data folder. */
113
+ export const files = new FilesApi();
114
+
115
+ /** Ask Raven, RollRook's assistant. Needs `raven`. */
116
+ export const raven = new RavenApi(events);
117
+
118
+ /** Code agent sessions. Needs `agents.read`. */
119
+ export const agents = new AgentsApi();
120
+
121
+ /** Code agent plan limits. Needs `agents.read`. */
122
+ export const usage = new UsageApi();
123
+
124
+ /** The mixer. Needs `audio`. */
125
+ export const audio = new AudioApi();
126
+
127
+ /** Chrome tabs' videos in the sidebar. Needs `video`. */
128
+ export const video = new VideoApi();
129
+
130
+ /** The user's browser. */
131
+ export const system = new SystemApi();
132
+
133
+ /** The plugin's other running views. */
134
+ export const plugin = new PluginApi();
135
+
136
+ /** RollRook's shared pictures. */
137
+ export const assets = new AssetsApi();
138
+
139
+ /** Fetch through RollRook. Needs `net:<host>`. */
140
+ export const net = new NetApi();
141
+
142
+ /** Toasts, badges, captions, widths, views, popovers and Settings. */
143
+ export const ui = new UiApi();
144
+
145
+ /** The plugin's items in RollRook's calendar (`contributes.calendar`). */
146
+ export const calendar = new CalendarApi();
147
+
148
+ /** The plugin's tools for RollRook's assistant (`contributes.raven`), answered in the background view. */
149
+ export const assistant = new AssistantApi();
150
+
151
+ /** RollRook's theme as CSS variables. */
152
+ export const theme = new ThemeApi(context, events);
@@ -0,0 +1,3 @@
1
+ export { MockHost } from "./mock-host.js";
2
+ export type { MockHostOptions } from "./mock-host.js";
3
+ export { MockSamples } from "./samples.js";