@eloxiv/client 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/LICENSE +21 -0
- package/README.md +6 -2
- package/dist/Account.d.ts +131 -0
- package/dist/Account.d.ts.map +1 -0
- package/dist/Account.js +169 -0
- package/dist/Account.js.map +1 -0
- package/dist/Agent.d.ts +496 -0
- package/dist/Agent.d.ts.map +1 -0
- package/dist/Agent.js +228 -0
- package/dist/Agent.js.map +1 -0
- package/dist/AgentSync.d.ts +990 -0
- package/dist/AgentSync.d.ts.map +1 -0
- package/dist/AgentSync.js +46 -0
- package/dist/AgentSync.js.map +1 -0
- package/dist/AppState.d.ts +127 -0
- package/dist/AppState.d.ts.map +1 -0
- package/dist/AppState.js +145 -0
- package/dist/AppState.js.map +1 -0
- package/dist/AppStateSync.d.ts +193 -0
- package/dist/AppStateSync.d.ts.map +1 -0
- package/dist/AppStateSync.js +23 -0
- package/dist/AppStateSync.js.map +1 -0
- package/dist/Auth.d.ts +95 -0
- package/dist/Auth.d.ts.map +1 -0
- package/dist/Auth.js +139 -0
- package/dist/Auth.js.map +1 -0
- package/dist/Avatars.d.ts +53 -0
- package/dist/Avatars.d.ts.map +1 -0
- package/dist/Avatars.js +121 -0
- package/dist/Avatars.js.map +1 -0
- package/dist/BrowserAnalytics.d.ts +56 -0
- package/dist/BrowserAnalytics.d.ts.map +1 -0
- package/dist/BrowserAnalytics.js +94 -0
- package/dist/BrowserAnalytics.js.map +1 -0
- package/dist/Chat.d.ts +712 -0
- package/dist/Chat.d.ts.map +1 -0
- package/dist/Chat.js +883 -0
- package/dist/Chat.js.map +1 -0
- package/dist/ChatIntegrity.d.ts +63 -0
- package/dist/ChatIntegrity.d.ts.map +1 -0
- package/dist/ChatIntegrity.js +89 -0
- package/dist/ChatIntegrity.js.map +1 -0
- package/dist/ChatSends.d.ts +103 -0
- package/dist/ChatSends.d.ts.map +1 -0
- package/dist/ChatSends.js +157 -0
- package/dist/ChatSends.js.map +1 -0
- package/dist/Client.d.ts +113 -0
- package/dist/Client.d.ts.map +1 -0
- package/dist/Client.js +189 -0
- package/dist/Client.js.map +1 -0
- package/dist/Collab.d.ts +138 -0
- package/dist/Collab.d.ts.map +1 -0
- package/dist/Collab.js +454 -0
- package/dist/Collab.js.map +1 -0
- package/dist/CollabTools.d.ts +129 -0
- package/dist/CollabTools.d.ts.map +1 -0
- package/dist/CollabTools.js +277 -0
- package/dist/CollabTools.js.map +1 -0
- package/dist/Connections.d.ts +288 -0
- package/dist/Connections.d.ts.map +1 -0
- package/dist/Connections.js +316 -0
- package/dist/Connections.js.map +1 -0
- package/dist/Consent.d.ts +338 -0
- package/dist/Consent.d.ts.map +1 -0
- package/dist/Consent.js +142 -0
- package/dist/Consent.js.map +1 -0
- package/dist/Desktop.d.ts +61 -0
- package/dist/Desktop.d.ts.map +1 -0
- package/dist/Desktop.js +101 -0
- package/dist/Desktop.js.map +1 -0
- package/dist/Directory.d.ts +36 -0
- package/dist/Directory.d.ts.map +1 -0
- package/dist/Directory.js +42 -0
- package/dist/Directory.js.map +1 -0
- package/dist/ErrorReporter.d.ts +48 -0
- package/dist/ErrorReporter.d.ts.map +1 -0
- package/dist/ErrorReporter.js +70 -0
- package/dist/ErrorReporter.js.map +1 -0
- package/dist/ExpoSqlite.d.ts +7 -0
- package/dist/ExpoSqlite.d.ts.map +1 -0
- package/dist/ExpoSqlite.js +7 -0
- package/dist/ExpoSqlite.js.map +1 -0
- package/dist/FileSync.d.ts +265 -0
- package/dist/FileSync.d.ts.map +1 -0
- package/dist/FileSync.js +29 -0
- package/dist/FileSync.js.map +1 -0
- package/dist/FileTables.gen.d.ts +109 -0
- package/dist/FileTables.gen.d.ts.map +1 -0
- package/dist/FileTables.gen.js +23 -0
- package/dist/FileTables.gen.js.map +1 -0
- package/dist/Foldkit.d.ts +487 -0
- package/dist/Foldkit.d.ts.map +1 -0
- package/dist/Foldkit.js +617 -0
- package/dist/Foldkit.js.map +1 -0
- package/dist/History.d.ts +133 -0
- package/dist/History.d.ts.map +1 -0
- package/dist/History.js +210 -0
- package/dist/History.js.map +1 -0
- package/dist/InboxSync.d.ts +428 -0
- package/dist/InboxSync.d.ts.map +1 -0
- package/dist/InboxSync.js +37 -0
- package/dist/InboxSync.js.map +1 -0
- package/dist/KernelTables.gen.d.ts +1522 -0
- package/dist/KernelTables.gen.d.ts.map +1 -0
- package/dist/KernelTables.gen.js +307 -0
- package/dist/KernelTables.gen.js.map +1 -0
- package/dist/Make.d.ts +75 -0
- package/dist/Make.d.ts.map +1 -0
- package/dist/Make.js +70 -0
- package/dist/Make.js.map +1 -0
- package/dist/Models.d.ts +88 -0
- package/dist/Models.d.ts.map +1 -0
- package/dist/Models.js +80 -0
- package/dist/Models.js.map +1 -0
- package/dist/Optimistic.d.ts +120 -0
- package/dist/Optimistic.d.ts.map +1 -0
- package/dist/Optimistic.js +231 -0
- package/dist/Optimistic.js.map +1 -0
- package/dist/PlatformSync.d.ts +273 -0
- package/dist/PlatformSync.d.ts.map +1 -0
- package/dist/PlatformSync.js +92 -0
- package/dist/PlatformSync.js.map +1 -0
- package/dist/Poll.d.ts +113 -0
- package/dist/Poll.d.ts.map +1 -0
- package/dist/Poll.js +179 -0
- package/dist/Poll.js.map +1 -0
- package/dist/Preferences.d.ts +18 -0
- package/dist/Preferences.d.ts.map +1 -0
- package/dist/Preferences.js +22 -0
- package/dist/Preferences.js.map +1 -0
- package/dist/Proposals.d.ts +29 -0
- package/dist/Proposals.d.ts.map +1 -0
- package/dist/Proposals.js +41 -0
- package/dist/Proposals.js.map +1 -0
- package/dist/React.d.ts +17 -0
- package/dist/React.d.ts.map +1 -0
- package/dist/React.js +17 -0
- package/dist/React.js.map +1 -0
- package/dist/Reader.d.ts +35 -0
- package/dist/Reader.d.ts.map +1 -0
- package/dist/Reader.js +136 -0
- package/dist/Reader.js.map +1 -0
- package/dist/Resources.d.ts +98 -0
- package/dist/Resources.d.ts.map +1 -0
- package/dist/Resources.js +161 -0
- package/dist/Resources.js.map +1 -0
- package/dist/Rows.d.ts +4 -0
- package/dist/Rows.d.ts.map +1 -0
- package/dist/Rows.js +16 -0
- package/dist/Rows.js.map +1 -0
- package/dist/Runtime.d.ts +254 -0
- package/dist/Runtime.d.ts.map +1 -0
- package/dist/Runtime.js +1249 -0
- package/dist/Runtime.js.map +1 -0
- package/dist/RuntimeRuns.d.ts +74 -0
- package/dist/RuntimeRuns.d.ts.map +1 -0
- package/dist/RuntimeRuns.js +118 -0
- package/dist/RuntimeRuns.js.map +1 -0
- package/dist/ServicesSync.d.ts +286 -0
- package/dist/ServicesSync.d.ts.map +1 -0
- package/dist/ServicesSync.js +40 -0
- package/dist/ServicesSync.js.map +1 -0
- package/dist/Session.d.ts +226 -0
- package/dist/Session.d.ts.map +1 -0
- package/dist/Session.js +763 -0
- package/dist/Session.js.map +1 -0
- package/dist/ShareGrant.d.ts +47 -0
- package/dist/ShareGrant.d.ts.map +1 -0
- package/dist/ShareGrant.js +20 -0
- package/dist/ShareGrant.js.map +1 -0
- package/dist/Sharing.d.ts +203 -0
- package/dist/Sharing.d.ts.map +1 -0
- package/dist/Sharing.js +520 -0
- package/dist/Sharing.js.map +1 -0
- package/dist/Skew.d.ts +52 -0
- package/dist/Skew.d.ts.map +1 -0
- package/dist/Skew.js +77 -0
- package/dist/Skew.js.map +1 -0
- package/dist/SpacesSync.d.ts +247 -0
- package/dist/SpacesSync.d.ts.map +1 -0
- package/dist/SpacesSync.js +30 -0
- package/dist/SpacesSync.js.map +1 -0
- package/dist/Storage.d.ts +51 -0
- package/dist/Storage.d.ts.map +1 -0
- package/dist/Storage.js +107 -0
- package/dist/Storage.js.map +1 -0
- package/dist/Sync.d.ts +48 -0
- package/dist/Sync.d.ts.map +1 -0
- package/dist/Sync.js +48 -0
- package/dist/Sync.js.map +1 -0
- package/dist/SyncTables.d.ts +13 -0
- package/dist/SyncTables.d.ts.map +1 -0
- package/dist/SyncTables.js +13 -0
- package/dist/SyncTables.js.map +1 -0
- package/dist/Tab.d.ts +36 -0
- package/dist/Tab.d.ts.map +1 -0
- package/dist/Tab.js +44 -0
- package/dist/Tab.js.map +1 -0
- package/dist/Transport.d.ts +139 -0
- package/dist/Transport.d.ts.map +1 -0
- package/dist/Transport.js +232 -0
- package/dist/Transport.js.map +1 -0
- package/dist/Upload.d.ts +41 -0
- package/dist/Upload.d.ts.map +1 -0
- package/dist/Upload.js +93 -0
- package/dist/Upload.js.map +1 -0
- package/dist/WebMcp.d.ts +78 -0
- package/dist/WebMcp.d.ts.map +1 -0
- package/dist/WebMcp.js +204 -0
- package/dist/WebMcp.js.map +1 -0
- package/dist/index.d.ts +27 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +27 -0
- package/dist/index.js.map +1 -0
- package/package.json +97 -3
- package/src/Account.ts +249 -0
- package/src/Agent.ts +387 -0
- package/src/AgentSync.ts +59 -0
- package/src/AppState.ts +222 -0
- package/src/AppStateSync.ts +26 -0
- package/src/Auth.ts +225 -0
- package/src/Avatars.ts +144 -0
- package/src/BrowserAnalytics.ts +133 -0
- package/src/Chat.ts +1150 -0
- package/src/ChatIntegrity.ts +130 -0
- package/src/ChatSends.ts +209 -0
- package/src/Client.ts +319 -0
- package/src/Collab.ts +524 -0
- package/src/CollabTools.ts +381 -0
- package/src/Connections.ts +517 -0
- package/src/Consent.ts +176 -0
- package/src/Desktop.ts +139 -0
- package/src/Directory.ts +71 -0
- package/src/ErrorReporter.ts +112 -0
- package/src/ExpoSqlite.ts +6 -0
- package/src/FileSync.ts +34 -0
- package/src/FileTables.gen.ts +23 -0
- package/src/Foldkit.ts +960 -0
- package/src/History.ts +337 -0
- package/src/InboxSync.ts +47 -0
- package/src/KernelTables.gen.ts +329 -0
- package/src/Make.ts +120 -0
- package/src/Models.ts +134 -0
- package/src/Optimistic.ts +364 -0
- package/src/PlatformSync.ts +156 -0
- package/src/Poll.ts +227 -0
- package/src/Preferences.ts +42 -0
- package/src/Proposals.ts +57 -0
- package/src/React.ts +26 -0
- package/src/Reader.ts +180 -0
- package/src/Resources.ts +257 -0
- package/src/Rows.ts +16 -0
- package/src/Runtime.ts +1409 -0
- package/src/RuntimeRuns.ts +180 -0
- package/src/ServicesSync.ts +58 -0
- package/src/Session.ts +814 -0
- package/src/ShareGrant.ts +20 -0
- package/src/Sharing.ts +696 -0
- package/src/Skew.ts +97 -0
- package/src/SpacesSync.ts +61 -0
- package/src/Storage.ts +167 -0
- package/src/Sync.ts +125 -0
- package/src/SyncTables.ts +12 -0
- package/src/Tab.ts +59 -0
- package/src/Transport.ts +321 -0
- package/src/Upload.ts +125 -0
- package/src/WebMcp.ts +279 -0
- package/src/index.ts +26 -0
- package/src/web-globals.d.ts +103 -0
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The agent's resources in the client (`@eloxiv/client/resources`, the AgentResources and Memory contracts): what a
|
|
3
|
+
* person's agent is given (instructions, skills and files in personal, organisation and app scopes, and memory), as a
|
|
4
|
+
* headless controller an app's settings screen or a registry UI item draws: the layered effective view, each scope's
|
|
5
|
+
* own resources as a folder tree, which scope wins for each path and what it overrides, and the changes (put,
|
|
6
|
+
* remove, remember, forget, resource packs) through the kernel's actions. It renders nothing.
|
|
7
|
+
*
|
|
8
|
+
* Every change is an action on the one invocation path (the organisation's scope needs `eloxiv.agent.manage`; an
|
|
9
|
+
* agent's changes wait for its person's consent; all audited); the controller only reads and shows what the kernel
|
|
10
|
+
* says the person may read.
|
|
11
|
+
*/
|
|
12
|
+
import type { AgentResource, MemoryEntry, ResourceKind, ResourcePack } from "@eloxiv/contracts";
|
|
13
|
+
import { type ActionCall } from "./Sharing.ts";
|
|
14
|
+
/** An `EloxivClient`'s `call` as the controller takes it (the same as `@eloxiv/client/sharing`'s). */
|
|
15
|
+
export { actionCall, type ActionCall } from "./Sharing.ts";
|
|
16
|
+
export type ResourceScope = AgentResource["scope"];
|
|
17
|
+
/** One path's resources across the scopes: which scope's is in effect, and which it overrides. */
|
|
18
|
+
export interface LayeredResource {
|
|
19
|
+
readonly kind: ResourceKind;
|
|
20
|
+
readonly path: string;
|
|
21
|
+
/** The resource in effect (the nearest scope: personal, then organisation, then app). */
|
|
22
|
+
readonly effective: AgentResource;
|
|
23
|
+
/** The farther scopes' resources at the same kind and path, nearest first. */
|
|
24
|
+
readonly overridden: ReadonlyArray<AgentResource>;
|
|
25
|
+
}
|
|
26
|
+
/** A folder of resource paths (split on `/`), with the layered resources directly in it. */
|
|
27
|
+
export interface ResourceFolder {
|
|
28
|
+
readonly name: string;
|
|
29
|
+
/** The folder's path (`""` for the root). */
|
|
30
|
+
readonly path: string;
|
|
31
|
+
readonly folders: ReadonlyArray<ResourceFolder>;
|
|
32
|
+
readonly resources: ReadonlyArray<LayeredResource>;
|
|
33
|
+
}
|
|
34
|
+
/** Every (kind, path) across the scopes, layered by precedence (personal > the team in context > organisation > app). */
|
|
35
|
+
export declare const layerResources: (resources: ReadonlyArray<AgentResource>) => ReadonlyArray<LayeredResource>;
|
|
36
|
+
/** Layered resources as a folder tree by their paths' `/` segments (a path's last segment is its name). */
|
|
37
|
+
export declare const resourceTree: (layered: ReadonlyArray<LayeredResource>) => ResourceFolder;
|
|
38
|
+
export interface ResourcesState {
|
|
39
|
+
readonly status: "loading" | "ready" | "failed";
|
|
40
|
+
/** What the agent is given: one per (kind, path), from the nearest scope. */
|
|
41
|
+
readonly effective: ReadonlyArray<AgentResource>;
|
|
42
|
+
/** Every resource of each scope the person may read, overridden or not. */
|
|
43
|
+
readonly scopes: Readonly<Record<ResourceScope, ReadonlyArray<AgentResource>>>;
|
|
44
|
+
/** Every scope's resources layered by precedence. */
|
|
45
|
+
readonly layered: ReadonlyArray<LayeredResource>;
|
|
46
|
+
/** The memory the person's agent reads: their own and the organisation's, newest first. */
|
|
47
|
+
readonly memory: ReadonlyArray<MemoryEntry>;
|
|
48
|
+
readonly busy: boolean;
|
|
49
|
+
readonly error: unknown;
|
|
50
|
+
}
|
|
51
|
+
export interface ResourcesController {
|
|
52
|
+
readonly state: ResourcesState;
|
|
53
|
+
readonly refresh: () => Promise<void>;
|
|
54
|
+
/** The layered resources (of one kind, or all) as a folder tree. */
|
|
55
|
+
readonly tree: (kind?: ResourceKind) => ResourceFolder;
|
|
56
|
+
readonly put: (resource: {
|
|
57
|
+
readonly scope: "personal" | "org";
|
|
58
|
+
readonly kind: ResourceKind;
|
|
59
|
+
readonly path: string;
|
|
60
|
+
readonly description: string;
|
|
61
|
+
readonly content: string;
|
|
62
|
+
}) => Promise<{
|
|
63
|
+
readonly id: string;
|
|
64
|
+
}>;
|
|
65
|
+
readonly remove: (id: string) => Promise<void>;
|
|
66
|
+
/** Rename a folder (`from` and everything under `from/`) to `to`, all or nothing (`agent.moveResources`). */
|
|
67
|
+
readonly moveFolder: (scope: "personal" | "org", from: string, to: string) => Promise<void>;
|
|
68
|
+
/**
|
|
69
|
+
* Remove a folder (`path` and everything under `path/`) of a scope, as the person sees it now: every resource in it,
|
|
70
|
+
* all or nothing (`agent.removeResources`). An empty folder removes nothing.
|
|
71
|
+
*/
|
|
72
|
+
readonly removeFolder: (scope: "personal" | "org", path: string) => Promise<ReadonlyArray<string>>;
|
|
73
|
+
readonly remember: (entry: {
|
|
74
|
+
readonly scope: "user" | "org";
|
|
75
|
+
readonly key: string;
|
|
76
|
+
readonly content: string;
|
|
77
|
+
}) => Promise<{
|
|
78
|
+
readonly id: string;
|
|
79
|
+
}>;
|
|
80
|
+
readonly forget: (id: string) => Promise<void>;
|
|
81
|
+
readonly exportPack: (scope: "personal" | "org") => Promise<ResourcePack>;
|
|
82
|
+
readonly importPack: (scope: "personal" | "org", pack: ResourcePack, onConflict?: "fail" | "skip" | "replace") => Promise<unknown>;
|
|
83
|
+
readonly subscribe: (listener: () => void) => () => void;
|
|
84
|
+
readonly dispose: () => void;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* The person's agent resources and memory, read from the kernel (`GET /agent/resources`, `GET /agent/memory`, as the
|
|
88
|
+
* person) and changed through its actions (`call`: an `EloxivClient`'s, as `actionCall(client)` gives it). A load
|
|
89
|
+
* that started earlier never overwrites a later one; each change loads again.
|
|
90
|
+
*/
|
|
91
|
+
export declare const agentResources: (options: {
|
|
92
|
+
readonly baseUrl: string;
|
|
93
|
+
readonly token: string | (() => string | undefined);
|
|
94
|
+
readonly orgId?: string | undefined;
|
|
95
|
+
readonly call: ActionCall;
|
|
96
|
+
readonly fetch?: typeof fetch | undefined;
|
|
97
|
+
}) => ResourcesController;
|
|
98
|
+
//# sourceMappingURL=Resources.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Resources.d.ts","sourceRoot":"","sources":["../src/Resources.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAC/F,OAAO,EAAW,KAAK,UAAU,EAAE,MAAM,cAAc,CAAA;AAEvD,sGAAsG;AACtG,OAAO,EAAE,UAAU,EAAE,KAAK,UAAU,EAAE,MAAM,cAAc,CAAA;AAE1D,MAAM,MAAM,aAAa,GAAG,aAAa,CAAC,OAAO,CAAC,CAAA;AAElD,kGAAkG;AAClG,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,IAAI,EAAE,YAAY,CAAA;IAC3B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,yFAAyF;IACzF,QAAQ,CAAC,SAAS,EAAE,aAAa,CAAA;IACjC,8EAA8E;IAC9E,QAAQ,CAAC,UAAU,EAAE,aAAa,CAAC,aAAa,CAAC,CAAA;CAClD;AAED,4FAA4F;AAC5F,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,6CAA6C;IAC7C,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,OAAO,EAAE,aAAa,CAAC,cAAc,CAAC,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CAAC,OAAO,CAAC,CAAA;IACrB,QAAQ,CAAC,SAAS,EAAE,CAAC,QAAQ,EAAE,MAAM,IAAI,KAAK,MAAM,IAAI,CAAA;IACxD,QAAQ,CAAC,OAAO,EAAE,MAAM,IAAI,CAAA;CAC7B;AAED;;;;GAIG;AACH,eAAO,MAAM,cAAc,YAAa;IACtC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;IACxB,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,CAAC,MAAM,MAAM,GAAG,SAAS,CAAC,CAAA;IACnD,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IACnC,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAA;IACzB,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,KAAK,GAAG,SAAS,CAAA;CAC1C,KAAG,mBAwGH,CAAA"}
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import { outputs } from "./Sharing.js";
|
|
2
|
+
/** An `EloxivClient`'s `call` as the controller takes it (the same as `@eloxiv/client/sharing`'s). */
|
|
3
|
+
export { actionCall } from "./Sharing.js";
|
|
4
|
+
const RANK = { personal: 0, team: 1, org: 2, app: 3 };
|
|
5
|
+
/** Every (kind, path) across the scopes, layered by precedence (personal > the team in context > organisation > app). */
|
|
6
|
+
export const layerResources = (resources) => {
|
|
7
|
+
const byKey = new Map();
|
|
8
|
+
for (const resource of resources) {
|
|
9
|
+
const key = `${resource.kind}\u0000${resource.path}`;
|
|
10
|
+
byKey.set(key, [...(byKey.get(key) ?? []), resource]);
|
|
11
|
+
}
|
|
12
|
+
return [...byKey.values()]
|
|
13
|
+
.map((group) => {
|
|
14
|
+
const sorted = [...group].sort((a, b) => RANK[a.scope] - RANK[b.scope]);
|
|
15
|
+
return { kind: sorted[0].kind, path: sorted[0].path, effective: sorted[0], overridden: sorted.slice(1) };
|
|
16
|
+
})
|
|
17
|
+
.sort((a, b) => a.kind.localeCompare(b.kind) || a.path.localeCompare(b.path));
|
|
18
|
+
};
|
|
19
|
+
/** Layered resources as a folder tree by their paths' `/` segments (a path's last segment is its name). */
|
|
20
|
+
export const resourceTree = (layered) => {
|
|
21
|
+
const root = { name: "", path: "", folders: new Map(), resources: [] };
|
|
22
|
+
for (const resource of layered) {
|
|
23
|
+
const segments = resource.path.split("/").filter((s) => s !== "");
|
|
24
|
+
let folder = root;
|
|
25
|
+
for (const segment of segments.slice(0, -1)) {
|
|
26
|
+
let next = folder.folders.get(segment);
|
|
27
|
+
if (next === undefined) {
|
|
28
|
+
next = {
|
|
29
|
+
name: segment,
|
|
30
|
+
path: folder.path === "" ? segment : `${folder.path}/${segment}`,
|
|
31
|
+
folders: new Map(),
|
|
32
|
+
resources: [],
|
|
33
|
+
};
|
|
34
|
+
folder.folders.set(segment, next);
|
|
35
|
+
}
|
|
36
|
+
folder = next;
|
|
37
|
+
}
|
|
38
|
+
folder.resources.push(resource);
|
|
39
|
+
}
|
|
40
|
+
const freeze = (folder) => ({
|
|
41
|
+
name: folder.name,
|
|
42
|
+
path: folder.path,
|
|
43
|
+
folders: [...folder.folders.values()].sort((a, b) => a.name.localeCompare(b.name)).map(freeze),
|
|
44
|
+
resources: folder.resources,
|
|
45
|
+
});
|
|
46
|
+
return freeze(root);
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* The person's agent resources and memory, read from the kernel (`GET /agent/resources`, `GET /agent/memory`, as the
|
|
50
|
+
* person) and changed through its actions (`call`: an `EloxivClient`'s, as `actionCall(client)` gives it). A load
|
|
51
|
+
* that started earlier never overwrites a later one; each change loads again.
|
|
52
|
+
*/
|
|
53
|
+
export const agentResources = (options) => {
|
|
54
|
+
const call = outputs(options.call);
|
|
55
|
+
const fetchFn = options.fetch ?? fetch;
|
|
56
|
+
const listeners = new Set();
|
|
57
|
+
let state = {
|
|
58
|
+
status: "loading",
|
|
59
|
+
effective: [],
|
|
60
|
+
scopes: { personal: [], team: [], org: [], app: [] },
|
|
61
|
+
layered: [],
|
|
62
|
+
memory: [],
|
|
63
|
+
busy: false,
|
|
64
|
+
error: undefined,
|
|
65
|
+
};
|
|
66
|
+
let loads = 0;
|
|
67
|
+
let disposed = false;
|
|
68
|
+
const set = (next) => {
|
|
69
|
+
state = { ...state, ...next };
|
|
70
|
+
for (const listener of listeners)
|
|
71
|
+
listener();
|
|
72
|
+
};
|
|
73
|
+
const get = async (path) => {
|
|
74
|
+
const token = typeof options.token === "function" ? options.token() : options.token;
|
|
75
|
+
const headers = {};
|
|
76
|
+
if (token !== undefined)
|
|
77
|
+
headers["authorization"] = `Bearer ${token}`;
|
|
78
|
+
if (options.orgId !== undefined)
|
|
79
|
+
headers["x-eloxiv-org"] = options.orgId;
|
|
80
|
+
const response = await fetchFn(`${options.baseUrl.replace(/\/$/u, "")}${path}`, { headers });
|
|
81
|
+
const body = await response.json();
|
|
82
|
+
if (!response.ok)
|
|
83
|
+
throw body;
|
|
84
|
+
return body;
|
|
85
|
+
};
|
|
86
|
+
const refresh = async () => {
|
|
87
|
+
if (disposed)
|
|
88
|
+
return;
|
|
89
|
+
const mine = ++loads;
|
|
90
|
+
try {
|
|
91
|
+
const [effective, personal, team, org, app, memory] = await Promise.all([
|
|
92
|
+
get("/agent/resources"),
|
|
93
|
+
get("/agent/resources?scope=personal"),
|
|
94
|
+
get("/agent/resources?scope=team"),
|
|
95
|
+
get("/agent/resources?scope=org"),
|
|
96
|
+
get("/agent/resources?scope=app"),
|
|
97
|
+
get("/agent/memory"),
|
|
98
|
+
]);
|
|
99
|
+
if (mine !== loads || disposed)
|
|
100
|
+
return;
|
|
101
|
+
set({
|
|
102
|
+
status: "ready",
|
|
103
|
+
effective,
|
|
104
|
+
scopes: { personal, team, org, app },
|
|
105
|
+
layered: layerResources([...personal, ...team, ...org, ...app]),
|
|
106
|
+
memory,
|
|
107
|
+
error: undefined,
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
catch (failure) {
|
|
111
|
+
if (mine !== loads || disposed)
|
|
112
|
+
return;
|
|
113
|
+
set({ status: "failed", error: failure });
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
const change = async (run) => {
|
|
117
|
+
set({ busy: true, error: undefined });
|
|
118
|
+
try {
|
|
119
|
+
const result = await run();
|
|
120
|
+
set({ busy: false });
|
|
121
|
+
await refresh();
|
|
122
|
+
return result;
|
|
123
|
+
}
|
|
124
|
+
catch (failure) {
|
|
125
|
+
set({ busy: false, error: failure });
|
|
126
|
+
throw failure;
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
return {
|
|
130
|
+
get state() {
|
|
131
|
+
return state;
|
|
132
|
+
},
|
|
133
|
+
refresh,
|
|
134
|
+
tree: (kind) => resourceTree(kind === undefined ? state.layered : state.layered.filter((r) => r.kind === kind)),
|
|
135
|
+
put: (resource) => change(async () => (await call("agent.putResource", resource))),
|
|
136
|
+
remove: (id) => change(async () => void (await call("agent.removeResource", { id }))),
|
|
137
|
+
moveFolder: (scope, from, to) => change(async () => void (await call("agent.moveResources", { scope, from, to }))),
|
|
138
|
+
removeFolder: (scope, path) => change(async () => {
|
|
139
|
+
const folder = path.replace(/\/+$/u, "");
|
|
140
|
+
const ids = state.scopes[scope]
|
|
141
|
+
.filter((r) => r.path === folder || r.path.startsWith(`${folder}/`))
|
|
142
|
+
.flatMap((r) => (r.id === null ? [] : [r.id]));
|
|
143
|
+
if (ids.length > 0)
|
|
144
|
+
await call("agent.removeResources", { ids });
|
|
145
|
+
return ids;
|
|
146
|
+
}),
|
|
147
|
+
remember: (entry) => change(async () => (await call("agent.remember", entry))),
|
|
148
|
+
forget: (id) => change(async () => void (await call("agent.forget", { id }))),
|
|
149
|
+
exportPack: async (scope) => (await call("agent.exportResources", { scope })),
|
|
150
|
+
importPack: (scope, pack, onConflict) => change(async () => call("agent.importResources", { scope, pack, ...(onConflict === undefined ? {} : { onConflict }) })),
|
|
151
|
+
subscribe: (listener) => {
|
|
152
|
+
listeners.add(listener);
|
|
153
|
+
return () => listeners.delete(listener);
|
|
154
|
+
},
|
|
155
|
+
dispose: () => {
|
|
156
|
+
disposed = true;
|
|
157
|
+
listeners.clear();
|
|
158
|
+
},
|
|
159
|
+
};
|
|
160
|
+
};
|
|
161
|
+
//# sourceMappingURL=Resources.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Resources.js","sourceRoot":"","sources":["../src/Resources.ts"],"names":[],"mappings":"AAYA,OAAO,EAAE,OAAO,EAAmB,MAAM,cAAc,CAAA;AAEvD,sGAAsG;AACtG,OAAO,EAAE,UAAU,EAAmB,MAAM,cAAc,CAAA;AAuB1D,MAAM,IAAI,GAAkC,EAAE,QAAQ,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,CAAA;AAEpF,yHAAyH;AACzH,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,SAAuC,EAAkC,EAAE;IACxG,MAAM,KAAK,GAAG,IAAI,GAAG,EAAgC,CAAA;IACrD,KAAK,MAAM,QAAQ,IAAI,SAAS,EAAE,CAAC;QACjC,MAAM,GAAG,GAAG,GAAG,QAAQ,CAAC,IAAI,SAAS,QAAQ,CAAC,IAAI,EAAE,CAAA;QACpD,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,EAAE,QAAQ,CAAC,CAAC,CAAA;IACvD,CAAC;IACD,OAAO,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC;SACvB,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE;QACb,MAAM,MAAM,GAAG,CAAC,GAAG,KAAK,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAA;QACvE,OAAO,EAAE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,EAAE,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,CAAC,EAAE,CAAC,CACpG;QACH,SAAS,EAAE,CAAC,QAAQ,EAAE,EAAE;YACtB,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAA;YACvB,OAAO,GAAG,EAAE,CAAC,SAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAA;QACzC,CAAC;QACD,OAAO,EAAE,GAAG,EAAE;YACZ,QAAQ,GAAG,IAAI,CAAA;YACf,SAAS,CAAC,KAAK,EAAE,CAAA;QACnB,CAAC;KACF,CAAA;AACH,CAAC,CAAA"}
|
package/dist/Rows.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/** Copies of a live view's rows: Zero's data is valid only until its next change, and no holder may alias it. */
|
|
2
|
+
/** The rows of a view's data (an array, one row, or none), each a deep JSON copy. */
|
|
3
|
+
export declare const copyRows: (data: unknown) => Array<unknown>;
|
|
4
|
+
//# sourceMappingURL=Rows.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Rows.d.ts","sourceRoot":"","sources":["../src/Rows.ts"],"names":[],"mappings":"AAAA,iHAAiH;AAEjH,qFAAqF;AACrF,eAAO,MAAM,QAAQ,SAAU,OAAO,KAAG,KAAK,CAAC,OAAO,CACmC,CAAA"}
|
package/dist/Rows.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/** Copies of a live view's rows: Zero's data is valid only until its next change, and no holder may alias it. */
|
|
2
|
+
/** The rows of a view's data (an array, one row, or none), each a deep JSON copy. */
|
|
3
|
+
export const copyRows = (data) => Array.isArray(data) ? data.map(copyValue) : data === undefined ? [] : [copyValue(data)];
|
|
4
|
+
/** A deep copy of a row: JSON values, with related rows as nested objects and arrays. */
|
|
5
|
+
const copyValue = (value) => {
|
|
6
|
+
if (Array.isArray(value))
|
|
7
|
+
return value.map(copyValue);
|
|
8
|
+
if (typeof value === "object" && value !== null) {
|
|
9
|
+
const copy = {};
|
|
10
|
+
for (const [name, field] of Object.entries(value))
|
|
11
|
+
copy[name] = copyValue(field);
|
|
12
|
+
return copy;
|
|
13
|
+
}
|
|
14
|
+
return value;
|
|
15
|
+
};
|
|
16
|
+
//# sourceMappingURL=Rows.js.map
|
package/dist/Rows.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Rows.js","sourceRoot":"","sources":["../src/Rows.ts"],"names":[],"mappings":"AAAA,iHAAiH;AAEjH,qFAAqF;AACrF,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,IAAa,EAAkB,EAAE,CACxD,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAA;AAEzF,yFAAyF;AACzF,MAAM,SAAS,GAAG,CAAC,KAAc,EAAW,EAAE;IAC5C,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC,GAAG,CAAC,SAAS,CAAC,CAAA;IACrD,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;QAChD,MAAM,IAAI,GAA4B,EAAE,CAAA;QACxC,KAAK,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC;YAAE,IAAI,CAAC,IAAI,CAAC,GAAG,SAAS,CAAC,KAAK,CAAC,CAAA;QAChF,OAAO,IAAI,CAAA;IACb,CAAC;IACD,OAAO,KAAK,CAAA;AACd,CAAC,CAAA"}
|
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The client core (decision 14): one portable, framework-free runtime that owns the guarantees every client needs
|
|
3
|
+
* and none should implement twice. It holds the person's session (the shared `sessionController`), the selected
|
|
4
|
+
* organisation with a **generation**, the replica of `{ person, organisation, session }` (`connectSync`, its storage
|
|
5
|
+
* injected), live named queries (`materialize` and listeners, snapshots copied out and tagged with their
|
|
6
|
+
* generation), optimistic writes (the app's generated mutators through `write`: predicted, then confirmed, rejected
|
|
7
|
+
* after the rollback, or not confirmed), non-optimistic action calls (`makeClient`), and teardown: an organisation
|
|
8
|
+
* change, a sign-out or `needs-auth` destroys every view and closes the replica before anything of the next context
|
|
9
|
+
* is emitted, and late results of an older generation are dropped.
|
|
10
|
+
*
|
|
11
|
+
* Its events are the LocalClient contract's (`Event`, without the per-stream `seq`), so the daemon serves it as
|
|
12
|
+
* LocalClient v1 unchanged; an in-process client (a JavaScript host) can listen to it directly. Runs wherever the
|
|
13
|
+
* root SDK runs: no DOM, no Node built-ins (the portable rule pack covers it).
|
|
14
|
+
*
|
|
15
|
+
* const runtime = makeClientRuntime({ kernelUrl, zeroUrl, schema, queries, mutators, modules, sessionStore })
|
|
16
|
+
* runtime.onEvent((event) => ...)
|
|
17
|
+
* await runtime.start()
|
|
18
|
+
* const { id } = await runtime.subscribe({ query: "hello.greetings" }, "window-1")
|
|
19
|
+
* await runtime.write({ mutator: "hello.greet", input: { message: "Hi", visibility: "org" } }, "window-1")
|
|
20
|
+
*/
|
|
21
|
+
import { InvocationError, type AnyModuleContract, type EngineReadiness, type LocalClientEvent, type LocalClientSessionState } from "@eloxiv/contracts";
|
|
22
|
+
import { type verifyTwoFactor } from "./Account.ts";
|
|
23
|
+
import { type OrganizationMembership } from "./Auth.ts";
|
|
24
|
+
import { type DesktopSignIn } from "./Desktop.ts";
|
|
25
|
+
import { type RevocationStatus, type RevocationStore, type SessionState, type SessionStore } from "./Session.ts";
|
|
26
|
+
import { type SyncSchema, type SyncStorage } from "./Sync.ts";
|
|
27
|
+
/** A LocalClient event without its stream's `seq`, and the client it is for (`undefined`: every client). */
|
|
28
|
+
export type RuntimeEvent = (LocalClientEvent extends infer E ? (E extends unknown ? Omit<E, "seq"> : never) : never) & {
|
|
29
|
+
readonly owner?: string | undefined;
|
|
30
|
+
};
|
|
31
|
+
export interface ClientRuntimeOptions<S extends SyncSchema = SyncSchema> {
|
|
32
|
+
/** The kernel's base URL (`http://localhost:4100`). */
|
|
33
|
+
readonly kernelUrl: string;
|
|
34
|
+
/** zero-cache's URL (`http://localhost:4848`). */
|
|
35
|
+
readonly zeroUrl: string;
|
|
36
|
+
/** The app's sync schema, named queries and mutators (`eloxiv.sync.ts`). */
|
|
37
|
+
readonly schema: S;
|
|
38
|
+
readonly queries: object;
|
|
39
|
+
readonly mutators?: object | undefined;
|
|
40
|
+
/** The app's module contracts (`eloxiv.modules.ts`): its typed actions. */
|
|
41
|
+
readonly modules: ReadonlyArray<AnyModuleContract>;
|
|
42
|
+
/** Where the person's session token is kept between launches (the daemon's secret store). */
|
|
43
|
+
readonly sessionStore: SessionStore;
|
|
44
|
+
/** Replica storage (default memory): one store per person and organisation (`sqliteStorage` on desktop). */
|
|
45
|
+
readonly storage?: SyncStorage | undefined;
|
|
46
|
+
/** The app build's version, sent with calls and writes. */
|
|
47
|
+
readonly clientVersion?: string | undefined;
|
|
48
|
+
/** Retries of the session's checks and revocation (`sessionController`). */
|
|
49
|
+
readonly retry?: {
|
|
50
|
+
readonly attempts?: number;
|
|
51
|
+
readonly baseMs?: number;
|
|
52
|
+
} | undefined;
|
|
53
|
+
/** How often to check a session the kernel could not be reached to check (ms, default 5 s). */
|
|
54
|
+
readonly recheckMs?: number | undefined;
|
|
55
|
+
/**
|
|
56
|
+
* How long the launch's check of a stored session with a remembered context waits before the remembered replica is
|
|
57
|
+
* opened offline (ms, default 3 s; `sessionController`'s `offlineProbeMs`). The check goes on in the background.
|
|
58
|
+
* The same deadline bounds the listing of that session's organisations once the kernel accepted it: unanswered by
|
|
59
|
+
* then, the remembered organisation opens, and the listing reconciles it when it comes.
|
|
60
|
+
*/
|
|
61
|
+
readonly offlineProbeMs?: number | undefined;
|
|
62
|
+
readonly log?: ((line: string) => void) | undefined;
|
|
63
|
+
/** How a followed run's event stream reconnects to the kernel (ms; the chat SDK's default 500, doubling to 10 000). */
|
|
64
|
+
readonly runReconnect?: {
|
|
65
|
+
readonly base: number;
|
|
66
|
+
readonly max: number;
|
|
67
|
+
} | undefined;
|
|
68
|
+
/**
|
|
69
|
+
* A durable sign-out (a browser's storage, `sessionController`'s `revocations`): a sign-out keeps its revocation
|
|
70
|
+
* here before the person is signed out, and pending ones are retried at start, every `revocationRetryMs` (15 s)
|
|
71
|
+
* and on `retryRevocations`, each attempt waiting `revocationTimeoutMs` (10 s), until the kernel confirms them.
|
|
72
|
+
*/
|
|
73
|
+
readonly revocations?: RevocationStore | undefined;
|
|
74
|
+
readonly revocationTimeoutMs?: number | undefined;
|
|
75
|
+
readonly revocationRetryMs?: number | undefined;
|
|
76
|
+
/**
|
|
77
|
+
* Which organisation a newly adopted session starts in (default: `previous`, the organisation selected before when
|
|
78
|
+
* the same person's session is adopted again, while they still belong to it; else their first).
|
|
79
|
+
*/
|
|
80
|
+
readonly initialOrg?: ((context: InitialOrgContext) => string | null) | undefined;
|
|
81
|
+
}
|
|
82
|
+
/** What `initialOrg` chooses from: the person, their organisations, and the one selected before (same person). */
|
|
83
|
+
export interface InitialOrgContext {
|
|
84
|
+
readonly user: {
|
|
85
|
+
readonly id: string;
|
|
86
|
+
readonly email: string;
|
|
87
|
+
readonly name: string;
|
|
88
|
+
};
|
|
89
|
+
readonly organizations: ReadonlyArray<OrganizationMembership>;
|
|
90
|
+
readonly previous: string | null;
|
|
91
|
+
}
|
|
92
|
+
/** The kernel's typed error, as it travels (`{ _tag, message, ... }`), or `ActionFailed` for anything else. */
|
|
93
|
+
export declare const invocationErrorOf: (action: string, error: unknown) => InvocationError;
|
|
94
|
+
export declare const makeClientRuntime: <const S extends SyncSchema>(options: ClientRuntimeOptions<S>) => {
|
|
95
|
+
/** The protocol-facing app description: its named queries, mutators and actions. */
|
|
96
|
+
app: {
|
|
97
|
+
queries: string[];
|
|
98
|
+
mutators: string[];
|
|
99
|
+
actions: string[];
|
|
100
|
+
};
|
|
101
|
+
/**
|
|
102
|
+
* Check a stored session (once at start): when it holds, the first organisation is selected. Called again, it
|
|
103
|
+
* also lists the person's organisations again when they could not be listed (`organizationsStatus`).
|
|
104
|
+
*/
|
|
105
|
+
start: () => Promise<LocalClientSessionState>;
|
|
106
|
+
session: () => LocalClientSessionState;
|
|
107
|
+
/**
|
|
108
|
+
* Whether the signed-in person's organisations were listed (`listed`), or could not be (`unavailable`, and why):
|
|
109
|
+
* then the session's empty `organizations` are unknown, not none, and they are listed again on a timer
|
|
110
|
+
* (`recheckMs`) and by `start`; once they come, an organisation is selected in a new context.
|
|
111
|
+
*/
|
|
112
|
+
organizationsStatus: () => {
|
|
113
|
+
readonly status: "listed";
|
|
114
|
+
} | {
|
|
115
|
+
readonly status: "unavailable";
|
|
116
|
+
readonly reason: string;
|
|
117
|
+
};
|
|
118
|
+
generation: () => number;
|
|
119
|
+
onEvent: (listener: (event: RuntimeEvent) => void) => (() => void);
|
|
120
|
+
/** Start a desktop sign-in for `redirectUri`: the login to keep (its verifier never leaves the caller). */
|
|
121
|
+
beginSignIn: (redirectUri: string) => Promise<DesktopSignIn>;
|
|
122
|
+
/** The browser came back with a code for `login`: redeem it and adopt the session. */
|
|
123
|
+
completeSignIn: (login: DesktopSignIn, received: {
|
|
124
|
+
readonly code: string;
|
|
125
|
+
readonly state: string;
|
|
126
|
+
}) => Promise<void>;
|
|
127
|
+
/** A started sign-in was abandoned (expired, refused). */
|
|
128
|
+
cancelSignIn: () => void;
|
|
129
|
+
/**
|
|
130
|
+
* Select an organisation the person belongs to: a new generation (its `context` and `session` events sent). One
|
|
131
|
+
* whose session ended while it ran (a sign-out, another person's sign-in, `close`) changes nothing and is refused
|
|
132
|
+
* with `StaleGeneration`.
|
|
133
|
+
*/
|
|
134
|
+
selectOrg: (next: string) => Promise<number>;
|
|
135
|
+
/**
|
|
136
|
+
* Sign out: reads stop at once (`signingOut`), the context is reset (every view destroyed, the replica closed),
|
|
137
|
+
* and the revocation is sent and retried; resolves once the kernel confirmed it.
|
|
138
|
+
*/
|
|
139
|
+
signOut: () => Promise<void>;
|
|
140
|
+
/** Run a named query live for `owner`; its snapshots arrive as `rows` events of the current generation. */
|
|
141
|
+
subscribe: (request: {
|
|
142
|
+
readonly query: string;
|
|
143
|
+
readonly args?: unknown;
|
|
144
|
+
readonly id?: string | undefined;
|
|
145
|
+
/** In process: refused (`StaleGeneration`) unless the context is still this generation. */
|
|
146
|
+
readonly generation?: number | undefined;
|
|
147
|
+
}, owner: string) => Promise<{
|
|
148
|
+
readonly id: string;
|
|
149
|
+
readonly generation: number;
|
|
150
|
+
}>;
|
|
151
|
+
/** Stop one of `owner`'s subscriptions. */
|
|
152
|
+
unsubscribe: (id: string, owner: string) => void;
|
|
153
|
+
/** Stop every subscription of `owner` (its stream closed). */
|
|
154
|
+
unsubscribeAll: (owner: string) => void;
|
|
155
|
+
/** The subscriptions `owner` holds (diagnostics and tests). */
|
|
156
|
+
subscriptionsOf: (owner: string) => ReadonlyArray<string>;
|
|
157
|
+
/**
|
|
158
|
+
* An optimistic write through the app's mutator: resolves once the prediction is in the replica (`predicted`
|
|
159
|
+
* sent); its outcome follows as a `write` event. An input the action refuses is refused here (`InvalidInput`),
|
|
160
|
+
* with nothing predicted or sent.
|
|
161
|
+
*/
|
|
162
|
+
write: (request: {
|
|
163
|
+
readonly mutator: string;
|
|
164
|
+
readonly input: unknown;
|
|
165
|
+
readonly id?: string | undefined;
|
|
166
|
+
/** Refused (`StaleGeneration`), nothing predicted or sent, unless the context is still this generation. */
|
|
167
|
+
readonly generation?: number | undefined;
|
|
168
|
+
}, owner: string) => Promise<{
|
|
169
|
+
readonly id: string;
|
|
170
|
+
readonly generation: number;
|
|
171
|
+
}>;
|
|
172
|
+
/**
|
|
173
|
+
* Call an action (not optimistically) as the person in the selected organisation: its result envelope as it
|
|
174
|
+
* travels. An app action goes through the typed client; `make.*` and MAKE modules' actions over HTTP. A call
|
|
175
|
+
* whose context changed while it ran is answered `StaleGeneration` naming its own generation (it may have run).
|
|
176
|
+
* Made for generation `expected` while another is current, it is refused with `StaleGeneration` naming the current
|
|
177
|
+
* one, and nothing is run.
|
|
178
|
+
*/
|
|
179
|
+
call: (action: string, input: unknown, idempotencyKey?: string, expected?: number) => Promise<unknown>;
|
|
180
|
+
/**
|
|
181
|
+
* Follow an agent run's events for `owner` (LocalClient 1.1.0), as the person in the selected organisation: they
|
|
182
|
+
* arrive as `run` events of the current generation (each stored event once, streamed text as it comes), ending
|
|
183
|
+
* after `run-finished`, or with the kernel's refusal (`error`). The stream reconnects to the kernel by itself; a
|
|
184
|
+
* context reset ends it.
|
|
185
|
+
*/
|
|
186
|
+
followRun: (request: {
|
|
187
|
+
readonly runId: string;
|
|
188
|
+
readonly after?: number | undefined;
|
|
189
|
+
readonly id?: string | undefined;
|
|
190
|
+
}, owner: string) => Promise<{
|
|
191
|
+
readonly id: string;
|
|
192
|
+
readonly generation: number;
|
|
193
|
+
}>;
|
|
194
|
+
/** Stop following one of `owner`'s runs. */
|
|
195
|
+
unfollowRun: (id: string, owner: string) => void;
|
|
196
|
+
/** Stop following every run of `owner` (its stream closed). */
|
|
197
|
+
unfollowAll: (owner: string) => void;
|
|
198
|
+
/** The runs `owner` follows (diagnostics and tests). */
|
|
199
|
+
runsOf: (owner: string) => ReadonlyArray<string>;
|
|
200
|
+
/**
|
|
201
|
+
* Whether the person's agent can answer in the selected organisation (the kernel's readiness, as the chat SDK
|
|
202
|
+
* asks it): `unknown` when the kernel could not be asked; a refusal of the caller is its typed error.
|
|
203
|
+
*/
|
|
204
|
+
agentReadiness: () => Promise<EngineReadiness>;
|
|
205
|
+
/**
|
|
206
|
+
* Sign in with email and password and adopt the session (its organisations listed and one selected before this
|
|
207
|
+
* resolves). Rejects with the kernel's error as it is: `AuthError` (wrong credentials), `TwoFactorRequired` (finish
|
|
208
|
+
* with `completeTwoFactor`), `UnsavedSignOut` (a durable sign-out's revocation only memory holds); `SignInFailed`
|
|
209
|
+
* when a person is already signed in or the attempt was abandoned while it completed.
|
|
210
|
+
*/
|
|
211
|
+
signInWithPassword: (credentials: {
|
|
212
|
+
readonly email: string;
|
|
213
|
+
readonly password: string;
|
|
214
|
+
}) => Promise<void>;
|
|
215
|
+
/** Finish a password sign-in that `TwoFactorRequired` interrupted (its challenge and a code). */
|
|
216
|
+
completeTwoFactor: (input: Parameters<typeof verifyTwoFactor>[1]) => Promise<void>;
|
|
217
|
+
/**
|
|
218
|
+
* Change the signed-in person's password. When the kernel rotates the session, the new token is adopted (the
|
|
219
|
+
* same person's, so their organisation stays selected, in a new generation); the old one is never reported again.
|
|
220
|
+
* A rotation answered after the session it rotates ended (a sign-out, `close`) is not adopted: it rejects with
|
|
221
|
+
* `SignInFailed`, and the rotated session is revoked.
|
|
222
|
+
*/
|
|
223
|
+
changePassword: (input: {
|
|
224
|
+
readonly currentPassword: string;
|
|
225
|
+
readonly newPassword: string;
|
|
226
|
+
readonly revokeOtherSessions?: boolean;
|
|
227
|
+
}) => Promise<void>;
|
|
228
|
+
/**
|
|
229
|
+
* The session's bearer token, for an in-process host's own requests (a screen's HTTP calls): never sent in an
|
|
230
|
+
* event, and `undefined` while nobody is signed in.
|
|
231
|
+
*/
|
|
232
|
+
token: () => string | undefined;
|
|
233
|
+
/**
|
|
234
|
+
* The session check's own state: `loading` before the stored session is checked, `unavailable` (and why), and
|
|
235
|
+
* `signing-out` with `error` while a sign-out that failed waits to be tried again (`signOut`).
|
|
236
|
+
*/
|
|
237
|
+
sessionStatus: () => {
|
|
238
|
+
readonly status: SessionState["status"];
|
|
239
|
+
readonly reason?: string | undefined;
|
|
240
|
+
readonly error?: string | undefined;
|
|
241
|
+
};
|
|
242
|
+
/** Where the last durable sign-out's revocation stands (`revocations`). */
|
|
243
|
+
revocation: () => RevocationStatus;
|
|
244
|
+
onRevocation: (listener: (status: RevocationStatus) => void) => (() => void);
|
|
245
|
+
/** Try every pending revocation once more now (the network came back). */
|
|
246
|
+
retryRevocations: () => Promise<{
|
|
247
|
+
readonly revoked: boolean;
|
|
248
|
+
readonly stillPending: boolean;
|
|
249
|
+
}>;
|
|
250
|
+
/** Stop: every view destroyed, the replica closed, nothing more emitted. */
|
|
251
|
+
close: () => Promise<void>;
|
|
252
|
+
};
|
|
253
|
+
export type ClientRuntime = ReturnType<typeof makeClientRuntime>;
|
|
254
|
+
//# sourceMappingURL=Runtime.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Runtime.d.ts","sourceRoot":"","sources":["../src/Runtime.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,OAAO,EAQL,eAAe,EASf,KAAK,iBAAiB,EACtB,KAAK,eAAe,EACpB,KAAK,gBAAgB,EACrB,KAAK,uBAAuB,EAC7B,MAAM,mBAAmB,CAAA;AAE1B,OAAO,EAA2C,KAAK,eAAe,EAAE,MAAM,cAAc,CAAA;AAC5F,OAAO,EAA0D,KAAK,sBAAsB,EAAE,MAAM,WAAW,CAAA;AAG/G,OAAO,EAA6C,KAAK,aAAa,EAAE,MAAM,cAAc,CAAA;AAG5F,OAAO,EAGL,KAAK,gBAAgB,EACrB,KAAK,eAAe,EACpB,KAAK,YAAY,EACjB,KAAK,YAAY,EAClB,MAAM,cAAc,CAAA;AACrB,OAAO,EAA4C,KAAK,UAAU,EAAE,KAAK,WAAW,EAAE,MAAM,WAAW,CAAA;AAEvG,4GAA4G;AAC5G,MAAM,MAAM,YAAY,GAAG,CAAC,gBAAgB,SAAS,MAAM,CAAC,GAAG,CAAC,CAAC,SAAS,OAAO,GAAG,IAAI,CAAC,CAAC,EAAE,KAAK,CAAC,GAAG,KAAK,CAAC,GAAG,KAAK,CAAC,GAAG;IACrH,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CACpC,CAAA;AAED,MAAM,WAAW,oBAAoB,CAAC,CAAC,SAAS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