@peers-app/peers-sdk 0.14.0 → 0.15.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/context/data-context.d.ts +4 -4
- package/dist/context/data-context.js +1 -1
- package/dist/context/index.d.ts +3 -3
- package/dist/context/index.js +4 -0
- package/dist/context/user-context-singleton.js +13 -14
- package/dist/context/user-context.d.ts +4 -4
- package/dist/context/user-context.js +48 -31
- package/dist/data/assistants.d.ts +1 -1
- package/dist/data/assistants.js +35 -24
- package/dist/data/change-tracking.d.ts +8 -8
- package/dist/data/change-tracking.js +45 -39
- package/dist/data/channels.js +5 -5
- package/dist/data/data-locks.d.ts +2 -2
- package/dist/data/data-locks.js +21 -23
- package/dist/data/data-locks.test.js +73 -75
- package/dist/data/device-sync-info.d.ts +1 -1
- package/dist/data/device-sync-info.js +4 -4
- package/dist/data/devices.d.ts +1 -1
- package/dist/data/devices.js +9 -12
- package/dist/data/embeddings.js +14 -11
- package/dist/data/files/file-read-stream.d.ts +2 -2
- package/dist/data/files/file-read-stream.js +23 -14
- package/dist/data/files/file-write-stream.d.ts +2 -2
- package/dist/data/files/file-write-stream.js +8 -8
- package/dist/data/files/file.types.d.ts +2 -2
- package/dist/data/files/file.types.js +17 -11
- package/dist/data/files/files.d.ts +6 -6
- package/dist/data/files/files.js +17 -19
- package/dist/data/files/files.test.js +213 -214
- package/dist/data/files/index.d.ts +4 -4
- package/dist/data/files/index.js +4 -4
- package/dist/data/group-member-roles.js +2 -2
- package/dist/data/group-members.d.ts +5 -5
- package/dist/data/group-members.js +27 -18
- package/dist/data/group-members.test.js +73 -73
- package/dist/data/group-permissions.d.ts +3 -3
- package/dist/data/group-permissions.js +13 -11
- package/dist/data/group-share.d.ts +2 -2
- package/dist/data/group-share.js +29 -24
- package/dist/data/groups.d.ts +4 -4
- package/dist/data/groups.js +27 -19
- package/dist/data/groups.test.js +44 -44
- package/dist/data/index.d.ts +6 -6
- package/dist/data/index.js +6 -6
- package/dist/data/knowledge/peer-types.js +9 -9
- package/dist/data/messages.d.ts +5 -5
- package/dist/data/messages.js +43 -30
- package/dist/data/orm/client-proxy.data-source.d.ts +4 -4
- package/dist/data/orm/client-proxy.data-source.js +10 -12
- package/dist/data/orm/cursor.d.ts +1 -1
- package/dist/data/orm/cursor.js +2 -2
- package/dist/data/orm/cursor.test.js +92 -93
- package/dist/data/orm/data-query.d.ts +3 -3
- package/dist/data/orm/data-query.js +24 -18
- package/dist/data/orm/data-query.mongo.d.ts +1 -1
- package/dist/data/orm/data-query.mongo.js +49 -51
- package/dist/data/orm/data-query.mongo.test.js +173 -204
- package/dist/data/orm/data-query.sqlite.d.ts +1 -1
- package/dist/data/orm/data-query.sqlite.js +84 -73
- package/dist/data/orm/data-query.sqlite.test.js +164 -176
- package/dist/data/orm/data-query.test.js +216 -224
- package/dist/data/orm/decorators.js +3 -3
- package/dist/data/orm/dependency-injection.test.js +53 -56
- package/dist/data/orm/doc.d.ts +4 -4
- package/dist/data/orm/doc.js +17 -21
- package/dist/data/orm/event-registry.d.ts +1 -1
- package/dist/data/orm/event-registry.test.js +16 -16
- package/dist/data/orm/factory.d.ts +2 -2
- package/dist/data/orm/factory.js +33 -33
- package/dist/data/orm/index.d.ts +10 -10
- package/dist/data/orm/index.js +10 -10
- package/dist/data/orm/multi-cursors.d.ts +1 -1
- package/dist/data/orm/multi-cursors.js +6 -6
- package/dist/data/orm/multi-cursors.test.js +152 -144
- package/dist/data/orm/sql.data-source.d.ts +7 -7
- package/dist/data/orm/sql.data-source.js +88 -93
- package/dist/data/orm/sql.data-source.test.js +109 -101
- package/dist/data/orm/subscribable.data-source.d.ts +4 -4
- package/dist/data/orm/subscribable.data-source.js +5 -5
- package/dist/data/orm/table-container-events.test.js +34 -26
- package/dist/data/orm/table-container.d.ts +6 -6
- package/dist/data/orm/table-container.js +33 -21
- package/dist/data/orm/table-container.test.js +64 -53
- package/dist/data/orm/table-definitions.system.d.ts +3 -3
- package/dist/data/orm/table-definitions.system.js +3 -3
- package/dist/data/orm/table-definitions.type.d.ts +5 -5
- package/dist/data/orm/table-dependencies.d.ts +2 -2
- package/dist/data/orm/table.d.ts +5 -5
- package/dist/data/orm/table.event-source.test.js +105 -115
- package/dist/data/orm/table.js +35 -34
- package/dist/data/orm/types.d.ts +3 -3
- package/dist/data/orm/types.js +26 -25
- package/dist/data/orm/types.test.js +166 -92
- package/dist/data/package-permissions.d.ts +1 -1
- package/dist/data/package-permissions.js +2 -2
- package/dist/data/package-version-permissions.d.ts +1 -1
- package/dist/data/package-version-permissions.js +2 -2
- package/dist/data/package-versions.d.ts +9 -9
- package/dist/data/package-versions.js +47 -33
- package/dist/data/packages.d.ts +2 -2
- package/dist/data/packages.js +36 -18
- package/dist/data/packages.utils.d.ts +2 -2
- package/dist/data/packages.utils.js +4 -4
- package/dist/data/persistent-vars.d.ts +15 -15
- package/dist/data/persistent-vars.js +165 -154
- package/dist/data/table-definitions-table.d.ts +5 -5
- package/dist/data/table-definitions-table.js +13 -12
- package/dist/data/tool-tests.js +6 -6
- package/dist/data/tools.js +29 -19
- package/dist/data/user-permissions.d.ts +1 -1
- package/dist/data/user-permissions.js +5 -5
- package/dist/data/user-permissions.test.js +90 -88
- package/dist/data/user-trust-levels.js +10 -10
- package/dist/data/users.d.ts +4 -4
- package/dist/data/users.js +16 -15
- package/dist/data/voice-messages.d.ts +2 -2
- package/dist/data/voice-messages.js +13 -13
- package/dist/data/welcome-modal.pvar.js +3 -1
- package/dist/data/workflow-logs.js +26 -18
- package/dist/data/workflow-runs.d.ts +6 -6
- package/dist/data/workflow-runs.js +70 -44
- package/dist/data/workflows.d.ts +2 -2
- package/dist/data/workflows.js +7 -9
- package/dist/device/binary-peer-connection-v2.d.ts +7 -7
- package/dist/device/binary-peer-connection-v2.js +32 -28
- package/dist/device/binary-peer-connection-v2.test.js +80 -67
- package/dist/device/binary-peer-connection.d.ts +7 -7
- package/dist/device/binary-peer-connection.js +29 -28
- package/dist/device/binary-peer-connection.test.js +35 -31
- package/dist/device/connection.d.ts +5 -5
- package/dist/device/connection.js +59 -48
- package/dist/device/connection.test.js +74 -68
- package/dist/device/device-election.d.ts +2 -2
- package/dist/device/device-election.js +25 -20
- package/dist/device/device-election.test.js +35 -36
- package/dist/device/device.d.ts +2 -2
- package/dist/device/device.js +10 -4
- package/dist/device/device.test.js +16 -17
- package/dist/device/get-trust-level-fn.d.ts +2 -2
- package/dist/device/get-trust-level-fn.js +22 -11
- package/dist/device/get-trust-level-fn.test.js +58 -58
- package/dist/device/socket-io-binary-peer.d.ts +1 -1
- package/dist/device/socket-io-binary-peer.js +16 -13
- package/dist/device/socket.type.d.ts +2 -2
- package/dist/device/streamed-socket.d.ts +2 -2
- package/dist/device/streamed-socket.js +8 -8
- package/dist/device/streamed-socket.test.js +40 -40
- package/dist/device/tx-encoding.test.js +77 -77
- package/dist/events.d.ts +1 -1
- package/dist/events.js +5 -2
- package/dist/group-invite/group-invite.js +110 -19
- package/dist/group-invite/group-invite.pvars.d.ts +2 -2
- package/dist/group-invite/group-invite.pvars.js +21 -13
- package/dist/group-invite/group-invite.types.d.ts +1 -1
- package/dist/group-invite/index.d.ts +3 -3
- package/dist/group-invite/index.js +1 -1
- package/dist/index.d.ts +25 -24
- package/dist/index.js +30 -25
- package/dist/keys.d.ts +3 -3
- package/dist/keys.js +31 -30
- package/dist/keys.test.js +69 -61
- package/dist/logging/console-logger.d.ts +1 -1
- package/dist/logging/console-logger.js +35 -40
- package/dist/logging/console-logger.test.js +115 -115
- package/dist/logging/console-logs.table.d.ts +3 -3
- package/dist/logging/console-logs.table.js +28 -23
- package/dist/mentions.js +16 -12
- package/dist/observable.d.ts +2 -2
- package/dist/observable.js +15 -9
- package/dist/observable.test.js +47 -47
- package/dist/package-loader/get-require.js +3 -4
- package/dist/package-loader/package-loader.d.ts +2 -2
- package/dist/package-loader/package-loader.js +52 -34
- package/dist/peers-ui/peers-ui.d.ts +2 -2
- package/dist/peers-ui/peers-ui.js +2 -4
- package/dist/peers-ui/peers-ui.types.d.ts +3 -3
- package/dist/peers-ui/peers-ui.types.js +0 -1
- package/dist/rpc-types.d.ts +61 -59
- package/dist/rpc-types.js +61 -55
- package/dist/serial-json.d.ts +1 -1
- package/dist/serial-json.js +50 -43
- package/dist/serial-json.test.js +22 -22
- package/dist/system-ids.js +8 -8
- package/dist/tools/index.d.ts +1 -1
- package/dist/tools/tools-factory.d.ts +1 -1
- package/dist/tools/tools-factory.js +2 -2
- package/dist/types/assistant-runner-args.d.ts +3 -3
- package/dist/types/peer-device.d.ts +1 -1
- package/dist/types/peers-package.d.ts +3 -3
- package/dist/types/workflow-logger.d.ts +1 -1
- package/dist/types/workflow-run-context.d.ts +4 -4
- package/dist/types/workflow.d.ts +4 -4
- package/dist/types/workflow.js +27 -14
- package/dist/types/zod-types.d.ts +2 -1
- package/dist/types/zod-types.js +9 -3
- package/dist/user-connect/connection-code.d.ts +1 -1
- package/dist/user-connect/connection-code.js +7 -7
- package/dist/user-connect/connection-code.test.js +106 -106
- package/dist/user-connect/index.d.ts +3 -3
- package/dist/user-connect/index.js +1 -1
- package/dist/user-connect/user-connect.pvars.js +13 -11
- package/dist/user-connect/user-connect.types.d.ts +3 -3
- package/dist/users.query.d.ts +2 -2
- package/dist/users.query.js +40 -30
- package/dist/utils.d.ts +2 -2
- package/dist/utils.js +34 -32
- package/dist/utils.test.js +12 -8
- package/dist/workflow-log-formatter.d.ts +1 -1
- package/dist/workflow-log-formatter.js +17 -18
- package/package.json +14 -8
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import type { z } from "zod";
|
|
2
|
+
import { EventRegistry, type ITableDependencies, type ITableMetaData, Table, TableContainer } from "../data/orm";
|
|
3
|
+
import type { DataSourceFactory } from "../data/orm/table-definitions.type";
|
|
3
4
|
import { PackageLoader } from "../package-loader/package-loader";
|
|
4
|
-
import { UserContext } from "./user-context";
|
|
5
|
-
import { z } from "zod";
|
|
5
|
+
import type { UserContext } from "./user-context";
|
|
6
6
|
export declare class DataContext {
|
|
7
7
|
readonly userContext: UserContext;
|
|
8
8
|
readonly groupId?: string | undefined;
|
package/dist/context/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
3
|
-
export * from
|
|
1
|
+
export * from "./user-context-singleton";
|
|
2
|
+
export * from "./data-context";
|
|
3
|
+
export * from "./user-context";
|
package/dist/context/index.js
CHANGED
|
@@ -14,6 +14,10 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
// Order matters: user-context-singleton must load first so the circular
|
|
18
|
+
// chain context → data-context → package-loader → data/files resolves
|
|
19
|
+
// before data/index.js is pulled in via user-context. Do not alphabetize.
|
|
20
|
+
// biome-ignore assist/source/organizeImports: export order is load-order-sensitive
|
|
17
21
|
__exportStar(require("./user-context-singleton"), exports);
|
|
18
22
|
__exportStar(require("./data-context"), exports);
|
|
19
23
|
__exportStar(require("./user-context"), exports);
|
|
@@ -9,11 +9,11 @@ exports.setDefaultClientUserContext = setDefaultClientUserContext;
|
|
|
9
9
|
exports.getAllTables = getAllTables;
|
|
10
10
|
const client_proxy_data_source_1 = require("../data/orm/client-proxy.data-source");
|
|
11
11
|
const rpc_types_1 = require("../rpc-types");
|
|
12
|
-
const user_context_1 = require("./user-context");
|
|
13
12
|
const utils_1 = require("../utils");
|
|
13
|
+
const user_context_1 = require("./user-context");
|
|
14
14
|
// This should be the only singleton pattern in the application
|
|
15
15
|
// everything should be driven off the UserContext instance
|
|
16
|
-
var userContextInstance
|
|
16
|
+
var userContextInstance;
|
|
17
17
|
var userContextResolved;
|
|
18
18
|
var userContextPromise;
|
|
19
19
|
async function getUserContext() {
|
|
@@ -21,7 +21,7 @@ async function getUserContext() {
|
|
|
21
21
|
return userContextInstance.loadingPromise;
|
|
22
22
|
}
|
|
23
23
|
if (!userContextPromise) {
|
|
24
|
-
userContextPromise = new Promise(resolve => {
|
|
24
|
+
userContextPromise = new Promise((resolve) => {
|
|
25
25
|
userContextResolved = resolve;
|
|
26
26
|
if (userContextInstance) {
|
|
27
27
|
resolve(userContextInstance.loadingPromise);
|
|
@@ -32,11 +32,11 @@ async function getUserContext() {
|
|
|
32
32
|
}
|
|
33
33
|
function setUserContext(userContext) {
|
|
34
34
|
if (userContextInstance) {
|
|
35
|
-
if (typeof window !==
|
|
35
|
+
if (typeof window !== "undefined") {
|
|
36
36
|
// In a browser/PWA context the module singleton persists across navigations
|
|
37
37
|
// and HMR re-runs. Allow replacing it — the new context is authoritative.
|
|
38
38
|
userContextInstance = userContext;
|
|
39
|
-
// @ts-
|
|
39
|
+
// @ts-expect-error
|
|
40
40
|
window.userContext = userContext;
|
|
41
41
|
return;
|
|
42
42
|
}
|
|
@@ -46,8 +46,8 @@ function setUserContext(userContext) {
|
|
|
46
46
|
if (userContextResolved) {
|
|
47
47
|
userContextResolved(userContext.loadingPromise);
|
|
48
48
|
}
|
|
49
|
-
if (typeof window !==
|
|
50
|
-
// @ts-
|
|
49
|
+
if (typeof window !== "undefined") {
|
|
50
|
+
// @ts-expect-error
|
|
51
51
|
window.userContext = userContext;
|
|
52
52
|
}
|
|
53
53
|
}
|
|
@@ -58,7 +58,7 @@ async function getDefaultDataContext() {
|
|
|
58
58
|
function getTableContainer(dataContext) {
|
|
59
59
|
dataContext ??= userContextInstance?.defaultDataContext();
|
|
60
60
|
if (!dataContext) {
|
|
61
|
-
throw new Error(
|
|
61
|
+
throw new Error("dataContext not provided and user context singleton not yet set");
|
|
62
62
|
}
|
|
63
63
|
return dataContext.tableContainer;
|
|
64
64
|
}
|
|
@@ -97,24 +97,23 @@ if (!rpc_types_1.isClient) {
|
|
|
97
97
|
const userContext = await getUserContext();
|
|
98
98
|
const table = userContext
|
|
99
99
|
.getDataContext(dataContextId || userContext.userId)
|
|
100
|
-
.tableContainer
|
|
101
|
-
.getTable(tableName);
|
|
100
|
+
.tableContainer.getTable(tableName);
|
|
102
101
|
return table;
|
|
103
102
|
}
|
|
104
103
|
// TODO: add check that client has permission to make this call
|
|
105
104
|
rpc_types_1.rpcServerCalls.tableMethodCall = async (dataContextId, tableName, methodName, ...args) => {
|
|
106
105
|
if (!tableName) {
|
|
107
|
-
throw new Error(
|
|
106
|
+
throw new Error("tableName is required for tableMethodCall");
|
|
108
107
|
}
|
|
109
108
|
if (!dataContextId) {
|
|
110
|
-
console.warn(
|
|
109
|
+
console.warn("dataContextId not provided to tableMethodCall - defaulting to user context. This is discouraged. If userDataContext was intended then pass it in explicitly.");
|
|
111
110
|
}
|
|
112
111
|
const table = await getTable(dataContextId, tableName);
|
|
113
112
|
const method = table[methodName];
|
|
114
|
-
if (typeof method !==
|
|
113
|
+
if (typeof method !== "function") {
|
|
115
114
|
throw new Error(`Method ${methodName} not found on table ${tableName}`);
|
|
116
115
|
}
|
|
117
|
-
// @ts-
|
|
116
|
+
// @ts-expect-error - call this way to ensure 'this' is correct
|
|
118
117
|
return table[methodName](...args);
|
|
119
118
|
};
|
|
120
119
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { DataContext } from "../context/data-context";
|
|
2
|
-
import { IUser } from "../data";
|
|
2
|
+
import { type IUser } from "../data";
|
|
3
3
|
import type { DataSourceFactory, IDataChangedEvent, Table } from "../data/orm";
|
|
4
|
-
import { IPublicPrivateKeys } from "../keys";
|
|
5
|
-
import { Observable } from "../observable";
|
|
4
|
+
import { type IPublicPrivateKeys } from "../keys";
|
|
5
|
+
import { type Observable } from "../observable";
|
|
6
6
|
export declare class UserContext {
|
|
7
7
|
readonly userId: string;
|
|
8
8
|
readonly dataSourceFactory: DataSourceFactory;
|
|
@@ -37,8 +37,8 @@ export declare class UserContext {
|
|
|
37
37
|
getMe(): Promise<{
|
|
38
38
|
name: string;
|
|
39
39
|
publicKey: string;
|
|
40
|
-
userId: string;
|
|
41
40
|
publicBoxKey: string;
|
|
41
|
+
userId: string;
|
|
42
42
|
signature?: string | undefined;
|
|
43
43
|
} | undefined>;
|
|
44
44
|
syncUserAndGroupObjects(userId: string, keys: IPublicPrivateKeys, me?: IUser): Promise<void>;
|
|
@@ -12,7 +12,7 @@ class UserContext {
|
|
|
12
12
|
userId;
|
|
13
13
|
dataSourceFactory;
|
|
14
14
|
ephemeral;
|
|
15
|
-
deviceId = (0, observable_1.observable)(
|
|
15
|
+
deviceId = (0, observable_1.observable)("");
|
|
16
16
|
currentlyActiveGroupId = (0, observable_1.observable)();
|
|
17
17
|
reloadPackagesOnPageRefresh = (0, observable_1.observable)(false);
|
|
18
18
|
groupIds = (0, observable_1.observable)([]);
|
|
@@ -26,7 +26,9 @@ class UserContext {
|
|
|
26
26
|
this.userId = userId;
|
|
27
27
|
this.dataSourceFactory = dataSourceFactory;
|
|
28
28
|
this.ephemeral = ephemeral;
|
|
29
|
-
if (ephemeral === undefined &&
|
|
29
|
+
if (ephemeral === undefined &&
|
|
30
|
+
typeof process !== "undefined" &&
|
|
31
|
+
process.env.NODE_ENV === "test") {
|
|
30
32
|
this.ephemeral = true;
|
|
31
33
|
}
|
|
32
34
|
this.userDataContext = new data_context_1.DataContext(this);
|
|
@@ -47,21 +49,23 @@ class UserContext {
|
|
|
47
49
|
* so any tables in packages have been registered are available at sync time
|
|
48
50
|
*/
|
|
49
51
|
loadAllPackages() {
|
|
50
|
-
this.userDataContext.packageLoader
|
|
51
|
-
.
|
|
52
|
+
this.userDataContext.packageLoader
|
|
53
|
+
.loadAllPackages()
|
|
54
|
+
.catch((err) => console.error("[UserContext] loadAllPackages failed for userDataContext:", err));
|
|
52
55
|
for (const groupContext of this.groupDataContexts.values()) {
|
|
53
|
-
groupContext.packageLoader
|
|
54
|
-
.
|
|
56
|
+
groupContext.packageLoader
|
|
57
|
+
.loadAllPackages()
|
|
58
|
+
.catch((err) => console.error("[UserContext] loadAllPackages failed for groupContext:", err));
|
|
55
59
|
}
|
|
56
60
|
}
|
|
57
61
|
async loadGroupContexts() {
|
|
58
62
|
const groupsTable = (0, data_1.Groups)(this.userDataContext);
|
|
59
63
|
const groups = await groupsTable.list({ disabled: { $ne: true } });
|
|
60
|
-
this.groupIds(groups.map(g => g.groupId));
|
|
61
|
-
groupsTable.dataChanged.subscribe(evt => {
|
|
64
|
+
this.groupIds(groups.map((g) => g.groupId));
|
|
65
|
+
groupsTable.dataChanged.subscribe((evt) => {
|
|
62
66
|
const groupId = evt.dataObject.groupId;
|
|
63
|
-
if (evt.op ===
|
|
64
|
-
this.groupIds(this.groupIds().filter(id => id !== groupId));
|
|
67
|
+
if (evt.op === "delete" || evt.dataObject.disabled) {
|
|
68
|
+
this.groupIds(this.groupIds().filter((id) => id !== groupId));
|
|
65
69
|
this.groupDataContexts.delete(groupId);
|
|
66
70
|
}
|
|
67
71
|
else {
|
|
@@ -127,20 +131,34 @@ class UserContext {
|
|
|
127
131
|
async loadUserContextObservablesFromDB() {
|
|
128
132
|
// const persistentVars: PersistentVarsTable = await this.userDataContext.tableContainer.getTableByName(persistentVarsMetaData.name) as PersistentVarsTable;
|
|
129
133
|
const persistentVars = (0, data_1.PersistentVars)(this.userDataContext);
|
|
130
|
-
const vars = await persistentVars.list({
|
|
134
|
+
const vars = await persistentVars.list({
|
|
135
|
+
name: { $in: ["thisDeviceId", "currentlyActiveGroupId", "reloadPackagesOnPageRefresh"] },
|
|
136
|
+
});
|
|
131
137
|
const varDbValues = vars.reduce((acc, curr) => {
|
|
132
138
|
acc[curr.name] = curr.value?.value;
|
|
133
139
|
return acc;
|
|
134
140
|
}, {});
|
|
135
|
-
const deviceIdDefaultValue = (typeof process !==
|
|
136
|
-
const deviceIdPVar = (0, data_1.deviceVar)(
|
|
141
|
+
const deviceIdDefaultValue = (typeof process !== "undefined" && process.env?.DEVICE_ID) || "";
|
|
142
|
+
const deviceIdPVar = (0, data_1.deviceVar)("thisDeviceId", {
|
|
143
|
+
defaultValue: deviceIdDefaultValue,
|
|
144
|
+
dbValue: varDbValues.thisDeviceId,
|
|
145
|
+
userContext: this,
|
|
146
|
+
});
|
|
137
147
|
this.deviceId(deviceIdPVar());
|
|
138
148
|
(0, observable_1.linkObservables)(deviceIdPVar, this.deviceId);
|
|
139
|
-
const currentlyActiveGroupIdPVar = (0, data_1.deviceVar)(
|
|
149
|
+
const currentlyActiveGroupIdPVar = (0, data_1.deviceVar)("currentlyActiveGroupId", {
|
|
150
|
+
dbValue: varDbValues.currentlyActiveGroupId,
|
|
151
|
+
defaultValue: "",
|
|
152
|
+
userContext: this,
|
|
153
|
+
});
|
|
140
154
|
this._currentlyActiveGroupIdPVar = currentlyActiveGroupIdPVar;
|
|
141
155
|
this.currentlyActiveGroupId(currentlyActiveGroupIdPVar());
|
|
142
156
|
(0, observable_1.linkObservables)(currentlyActiveGroupIdPVar, this.currentlyActiveGroupId);
|
|
143
|
-
const reloadPackagesOnPageRefreshPVar = (0, data_1.deviceVar)(
|
|
157
|
+
const reloadPackagesOnPageRefreshPVar = (0, data_1.deviceVar)("reloadPackagesOnPageRefresh", {
|
|
158
|
+
defaultValue: false,
|
|
159
|
+
dbValue: varDbValues.reloadPackagesOnPageRefresh,
|
|
160
|
+
userContext: this,
|
|
161
|
+
});
|
|
144
162
|
this.reloadPackagesOnPageRefresh(reloadPackagesOnPageRefreshPVar());
|
|
145
163
|
(0, observable_1.linkObservables)(reloadPackagesOnPageRefreshPVar, this.reloadPackagesOnPageRefresh);
|
|
146
164
|
await Promise.all([
|
|
@@ -150,20 +168,18 @@ class UserContext {
|
|
|
150
168
|
]);
|
|
151
169
|
}
|
|
152
170
|
async getMe() {
|
|
153
|
-
|
|
171
|
+
const dbMe = await (0, data_1.Users)(this.userDataContext).get(this.userId, { useCache: true });
|
|
154
172
|
return dbMe;
|
|
155
173
|
}
|
|
156
174
|
async syncUserAndGroupObjects(userId, keys, me) {
|
|
157
|
-
// update my user object for all contexts
|
|
158
|
-
const userContext = this;
|
|
159
175
|
me ??= await this.getMe();
|
|
160
176
|
if (!me) {
|
|
161
177
|
console.warn(`My user object was not in db, creating now`);
|
|
162
178
|
me = {
|
|
163
179
|
userId,
|
|
164
|
-
name:
|
|
165
|
-
publicKey:
|
|
166
|
-
publicBoxKey:
|
|
180
|
+
name: "",
|
|
181
|
+
publicKey: "",
|
|
182
|
+
publicBoxKey: "",
|
|
167
183
|
};
|
|
168
184
|
}
|
|
169
185
|
me.publicKey = keys.publicKey;
|
|
@@ -172,19 +188,19 @@ class UserContext {
|
|
|
172
188
|
// sync my user to personal db
|
|
173
189
|
if (!(0, lodash_1.isEqual)(me, meSigned)) {
|
|
174
190
|
(0, keys_1.verifyObjectSignature)(meSigned);
|
|
175
|
-
await (0, data_1.Users)(
|
|
191
|
+
await (0, data_1.Users)(this.userDataContext).save(meSigned, { weakInsert: true });
|
|
176
192
|
}
|
|
177
193
|
// sync my user to all my groups
|
|
178
|
-
for (const [, dataContext] of
|
|
179
|
-
|
|
194
|
+
for (const [, dataContext] of this.groupDataContexts) {
|
|
195
|
+
const groupMe = await (0, data_1.Users)(dataContext).get(me.userId);
|
|
180
196
|
if (!(0, lodash_1.isEqual)(groupMe, meSigned)) {
|
|
181
197
|
await (0, data_1.Users)(dataContext).save(meSigned, { weakInsert: true });
|
|
182
198
|
}
|
|
183
199
|
}
|
|
184
200
|
// sync group objects to my personal db
|
|
185
|
-
for (const [, dataContext] of
|
|
201
|
+
for (const [, dataContext] of this.groupDataContexts) {
|
|
186
202
|
if (!dataContext.groupId) {
|
|
187
|
-
console.error(
|
|
203
|
+
console.error("Group data context is missing group id. Something went wrong");
|
|
188
204
|
continue;
|
|
189
205
|
}
|
|
190
206
|
const groupObject = await (0, data_1.Groups)(dataContext).get(dataContext.groupId);
|
|
@@ -201,9 +217,10 @@ class UserContext {
|
|
|
201
217
|
}
|
|
202
218
|
}
|
|
203
219
|
if (!this.personalUserSubscription) {
|
|
204
|
-
this.personalUserSubscription = this.subscribeToDataChangedAcrossAllGroups(
|
|
220
|
+
this.personalUserSubscription = this.subscribeToDataChangedAcrossAllGroups("Users", async (evt) => {
|
|
205
221
|
const changedUser = evt.data.dataObject;
|
|
206
|
-
if (changedUser.userId !== this.userId &&
|
|
222
|
+
if (changedUser.userId !== this.userId &&
|
|
223
|
+
evt.dataContext.dataContextId !== this.userDataContext.dataContextId) {
|
|
207
224
|
// sync to my personal db if this is a user that I have there
|
|
208
225
|
const personalContact = await (0, data_1.Users)(this.userDataContext).get(changedUser.userId);
|
|
209
226
|
if (personalContact && !(0, lodash_1.isEqual)(personalContact, changedUser)) {
|
|
@@ -219,10 +236,10 @@ class UserContext {
|
|
|
219
236
|
}
|
|
220
237
|
}
|
|
221
238
|
subscribeToDataChangedAcrossAllGroups(table, handler) {
|
|
222
|
-
const tableName = typeof table ===
|
|
239
|
+
const tableName = typeof table === "string" ? table : table.tableName;
|
|
223
240
|
const tableEventPrefix = `${tableName}_DataChanged_`;
|
|
224
|
-
const subscription = (0, events_1.subscribe)(evt => evt.name.startsWith(tableEventPrefix), async (evt) => {
|
|
225
|
-
const dataContextId = evt.name.endsWith(
|
|
241
|
+
const subscription = (0, events_1.subscribe)((evt) => evt.name.startsWith(tableEventPrefix), async (evt) => {
|
|
242
|
+
const dataContextId = evt.name.endsWith("_") ? this.userId : evt.name.split("_").pop();
|
|
226
243
|
const dataContext = this.getDataContext(dataContextId);
|
|
227
244
|
handler({
|
|
228
245
|
name: evt.name,
|
package/dist/data/assistants.js
CHANGED
|
@@ -3,13 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.getPrimaryAssistant = exports.groupPrimaryAssistantVar = exports.userPrimaryAssistantVar = exports.assistantSchema = exports.ToolInclusionStrategy = void 0;
|
|
4
4
|
exports.Assistants = Assistants;
|
|
5
5
|
exports.getAllAssistantIdsMentioned = getAllAssistantIdsMentioned;
|
|
6
|
-
const mentions_1 = require("../mentions");
|
|
7
|
-
const types_1 = require("./orm/types");
|
|
8
|
-
const user_context_singleton_1 = require("../context/user-context-singleton");
|
|
9
|
-
const table_definitions_system_1 = require("./orm/table-definitions.system");
|
|
10
6
|
const zod_1 = require("zod");
|
|
7
|
+
const user_context_singleton_1 = require("../context/user-context-singleton");
|
|
8
|
+
const mentions_1 = require("../mentions");
|
|
11
9
|
const system_ids_1 = require("../system-ids");
|
|
12
10
|
const zod_types_1 = require("../types/zod-types");
|
|
11
|
+
const table_definitions_system_1 = require("./orm/table-definitions.system");
|
|
12
|
+
const types_1 = require("./orm/types");
|
|
13
13
|
const persistent_vars_1 = require("./persistent-vars");
|
|
14
14
|
var ToolInclusionStrategy;
|
|
15
15
|
(function (ToolInclusionStrategy) {
|
|
@@ -22,27 +22,38 @@ exports.assistantSchema = zod_1.z.object({
|
|
|
22
22
|
name: zod_1.z.string(),
|
|
23
23
|
createdAt: zod_1.z.date().default(() => new Date()),
|
|
24
24
|
updatedAt: zod_1.z.date().optional(),
|
|
25
|
-
description: zod_1.z
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
25
|
+
description: zod_1.z
|
|
26
|
+
.string()
|
|
27
|
+
.optional()
|
|
28
|
+
.describe(`Information about the assistant that won't be used in the interaction but can still be used to differentiate between assistants`),
|
|
29
|
+
assistantRunnerToolId: zod_types_1.zodPeerId
|
|
30
|
+
.default(system_ids_1.defaultAssistantRunnerToolId)
|
|
31
|
+
.describe("The tool id of the model to use to run the assistant"),
|
|
32
|
+
assistantRunnerConfig: zod_types_1.zodAnyObject
|
|
33
|
+
.default({})
|
|
34
|
+
.describe("The configuration to use when running the assistant"),
|
|
35
|
+
toolsToInclude: zod_1.z
|
|
36
|
+
.string()
|
|
37
|
+
.default("")
|
|
38
|
+
.describe("Link the tools that should always be available to this assistant. Only linked tools will be included. All other content will be ignored.\n\nex: `$hello-world-tool`"),
|
|
29
39
|
// toolsToExclude: z.string().optional().describe('Describe or link the tools that should never be available to this assistant'),
|
|
30
|
-
toolInclusionStrategy: zod_1.z
|
|
31
|
-
|
|
32
|
-
|
|
40
|
+
toolInclusionStrategy: zod_1.z
|
|
41
|
+
.nativeEnum(ToolInclusionStrategy)
|
|
42
|
+
.default(ToolInclusionStrategy.Linked)
|
|
43
|
+
.describe([
|
|
44
|
+
"Describe if and how additional tools should be included on each run of the assistant.",
|
|
45
|
+
"- **Fixed** - Only include the tools specified in `toolsToInclude`.",
|
|
33
46
|
"- **Linked** - `Fixed` plus tools linked in the message or chat history of the assistant's current conversation.",
|
|
34
|
-
|
|
35
|
-
].join(
|
|
47
|
+
"- **Relevant** - `Linked` plus tools matching the context of the conversation determined via vector search (embeddings) of the tools descriptions.",
|
|
48
|
+
].join("\n")),
|
|
36
49
|
});
|
|
37
50
|
const metaData = {
|
|
38
|
-
name:
|
|
39
|
-
description:
|
|
40
|
-
primaryKeyName:
|
|
51
|
+
name: "Assistants",
|
|
52
|
+
description: "The assistants that are available to help users",
|
|
53
|
+
primaryKeyName: "assistantId",
|
|
41
54
|
fields: (0, types_1.schemaToFields)(exports.assistantSchema),
|
|
42
|
-
iconClassName:
|
|
43
|
-
indexes: [
|
|
44
|
-
{ fields: ['name'], },
|
|
45
|
-
],
|
|
55
|
+
iconClassName: "bi bi-person-fill-gear",
|
|
56
|
+
indexes: [{ fields: ["name"] }],
|
|
46
57
|
};
|
|
47
58
|
(0, table_definitions_system_1.registerSystemTableDefinition)(metaData, exports.assistantSchema);
|
|
48
59
|
function Assistants(dataContext) {
|
|
@@ -52,12 +63,12 @@ function Assistants(dataContext) {
|
|
|
52
63
|
* Per-user primary assistant preference for the current group.
|
|
53
64
|
* Overrides the group default when set. Synced across the user's devices.
|
|
54
65
|
*/
|
|
55
|
-
exports.userPrimaryAssistantVar = (0, persistent_vars_1.groupUserVar)(
|
|
66
|
+
exports.userPrimaryAssistantVar = (0, persistent_vars_1.groupUserVar)("userPrimaryAssistantId");
|
|
56
67
|
/**
|
|
57
68
|
* Group-wide default primary assistant. Applies to all members who haven't set
|
|
58
69
|
* their own preference. Can be set by group admins. Synced to all group members.
|
|
59
70
|
*/
|
|
60
|
-
exports.groupPrimaryAssistantVar = (0, persistent_vars_1.groupVar)(
|
|
71
|
+
exports.groupPrimaryAssistantVar = (0, persistent_vars_1.groupVar)("groupPrimaryAssistantId");
|
|
61
72
|
const getPrimaryAssistant = async (dataContext) => {
|
|
62
73
|
await exports.userPrimaryAssistantVar.loadingPromise;
|
|
63
74
|
const userAssistantId = (0, exports.userPrimaryAssistantVar)();
|
|
@@ -75,11 +86,11 @@ const getPrimaryAssistant = async (dataContext) => {
|
|
|
75
86
|
}
|
|
76
87
|
const fallback = await Assistants(dataContext).get(system_ids_1.openCodeAssistantId);
|
|
77
88
|
if (!fallback)
|
|
78
|
-
throw new Error(
|
|
89
|
+
throw new Error("Primary assistant not found");
|
|
79
90
|
return fallback;
|
|
80
91
|
};
|
|
81
92
|
exports.getPrimaryAssistant = getPrimaryAssistant;
|
|
82
93
|
async function getAllAssistantIdsMentioned(message) {
|
|
83
94
|
const mentions = (0, mentions_1.getAllMentions)(message);
|
|
84
|
-
return mentions.filter(m => m.kind ===
|
|
95
|
+
return mentions.filter((m) => m.kind === "assistant").map((m) => m.id);
|
|
85
96
|
}
|
|
@@ -5,9 +5,9 @@
|
|
|
5
5
|
* Unlike V1, each JSON patch operation gets its own record, enabling
|
|
6
6
|
* path-based superseding and more efficient cleanup.
|
|
7
7
|
*/
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
8
|
+
import { z } from "zod";
|
|
9
|
+
import { Emitter, type Event } from "../events";
|
|
10
|
+
import { type DataFilter, type IDataQueryParams, type ISqlDb, type ITableMetaData, SQLDataSource } from "./orm";
|
|
11
11
|
export declare const changeRecordSchema: z.ZodObject<{
|
|
12
12
|
changeId: z.ZodEffects<z.ZodString, string, string>;
|
|
13
13
|
transactionId: z.ZodOptional<z.ZodString>;
|
|
@@ -73,11 +73,11 @@ export declare class ChangeTrackingTable extends SQLDataSource<IChangeRecord> {
|
|
|
73
73
|
*/
|
|
74
74
|
filterToMissingIds(recordIds: string[]): Promise<string[]>;
|
|
75
75
|
/**
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
76
|
+
* Find changeIds that we do not have
|
|
77
|
+
*
|
|
78
|
+
* @param changeIds - Array of changeIds to check
|
|
79
|
+
* @returns Array of changeIds with no change records
|
|
80
|
+
*/
|
|
81
81
|
filterToMissingChangeIds(changeIds: string[]): Promise<string[]>;
|
|
82
82
|
markAllPriorChangesSuperseded(tableName: string, recordId: string, supersededAt: number): Promise<void>;
|
|
83
83
|
/**
|