@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
package/dist/serial-json.js
CHANGED
|
@@ -27,72 +27,75 @@ function toJSON(obj) {
|
|
|
27
27
|
if (obj === Infinity)
|
|
28
28
|
return "__INFINITY";
|
|
29
29
|
if (obj instanceof RegExp)
|
|
30
|
-
return
|
|
30
|
+
return `__REGEXP ${obj.toString()}`;
|
|
31
31
|
// if(isDate(obj))
|
|
32
32
|
// return "__DATE " + obj.toISOString();
|
|
33
33
|
if (_.isDate(obj)) {
|
|
34
|
-
return
|
|
34
|
+
return `__DATE ${obj.toISOString()}`;
|
|
35
35
|
}
|
|
36
36
|
if (_.isFunction(obj))
|
|
37
|
-
return
|
|
37
|
+
return `__FUNCTION ${obj.toString()}`;
|
|
38
38
|
if (_.isElement(obj)) {
|
|
39
|
-
return
|
|
39
|
+
return `__HTML ${obj.outerHTML}`;
|
|
40
40
|
}
|
|
41
|
-
if (typeof window !==
|
|
41
|
+
if (typeof window !== "undefined" && window && obj === window) {
|
|
42
42
|
return "__WINDOW";
|
|
43
43
|
}
|
|
44
44
|
if (_.isError(obj)) {
|
|
45
|
-
return
|
|
45
|
+
return `__ERROR ${obj.stack}`;
|
|
46
46
|
}
|
|
47
47
|
if (Buffer.isBuffer(obj)) {
|
|
48
48
|
// Convert Buffer to base64 string for JSON serialization (backward compatibility)
|
|
49
|
-
return
|
|
49
|
+
return `__BUFFER ${obj.toString("base64")}`;
|
|
50
50
|
}
|
|
51
51
|
if (obj instanceof Uint8Array) {
|
|
52
52
|
// Convert Uint8Array to base64 string for JSON serialization
|
|
53
|
-
return
|
|
53
|
+
return `__UINT8ARRAY ${Buffer.from(obj).toString("base64")}`;
|
|
54
54
|
}
|
|
55
55
|
// non-objects can just be returned at this point
|
|
56
56
|
if (!(isObject(obj) || _.isArray(obj))) {
|
|
57
57
|
return obj;
|
|
58
58
|
}
|
|
59
59
|
// if we've found a duplicate reference, deal with it
|
|
60
|
-
|
|
60
|
+
const iObj = knownObjs.indexOf(obj);
|
|
61
61
|
if (iObj >= 0) {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
if (_.isArray(
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
62
|
+
const ref = objRefs[iObj];
|
|
63
|
+
const duplicateTarget = newObjs[iObj];
|
|
64
|
+
if (_.isArray(duplicateTarget) &&
|
|
65
|
+
(!_.isString(duplicateTarget[0]) || !duplicateTarget[0].match(/^__this_ref:/)))
|
|
66
|
+
duplicateTarget.unshift(`__this_ref:${ref}`);
|
|
67
|
+
else if (isObject(duplicateTarget) && !duplicateTarget.__this_ref)
|
|
68
|
+
duplicateTarget.__this_ref = ref;
|
|
68
69
|
return ref;
|
|
69
70
|
}
|
|
70
71
|
// capture references in case we need them later
|
|
71
72
|
refCount++;
|
|
72
|
-
|
|
73
|
-
|
|
73
|
+
const newRef = `__duplicate_ref_${_.isArray(obj) ? "ary_" : "obj_"}${refCount}`;
|
|
74
|
+
const nObj = _.isArray(obj) ? [] : {};
|
|
74
75
|
knownObjs.push(obj);
|
|
75
76
|
objRefs.push(newRef);
|
|
76
77
|
newObjs.push(nObj);
|
|
77
78
|
// recurse on properties
|
|
78
|
-
if (_.isArray(obj))
|
|
79
|
-
for (
|
|
79
|
+
if (_.isArray(obj)) {
|
|
80
|
+
for (let i = 0; i < obj.length; i++)
|
|
80
81
|
nObj.push(recurse(obj[i])); // use push so offset from reference capture doesn't mess things up
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
if (
|
|
87
|
-
|
|
88
|
-
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
for (const key of Object.keys(obj)) {
|
|
85
|
+
let outKey = key;
|
|
86
|
+
const value = recurse(obj[key]);
|
|
87
|
+
if (outKey[0] === "$")
|
|
88
|
+
// escape leading dollar signs
|
|
89
|
+
outKey = `__DOLLAR_${outKey.substring(1)}`;
|
|
90
|
+
nObj[outKey] = value;
|
|
89
91
|
}
|
|
92
|
+
}
|
|
90
93
|
return nObj;
|
|
91
94
|
}
|
|
92
95
|
obj = recurse(obj);
|
|
93
96
|
return obj;
|
|
94
97
|
}
|
|
95
|
-
function fromJSON(obj,
|
|
98
|
+
function fromJSON(obj, _externalReferences) {
|
|
96
99
|
var dup_refs = {};
|
|
97
100
|
function recurse(obj) {
|
|
98
101
|
if (_.isString(obj)) {
|
|
@@ -104,7 +107,10 @@ function fromJSON(obj, externalReferences) {
|
|
|
104
107
|
if (obj === "__INFINITY")
|
|
105
108
|
return Infinity;
|
|
106
109
|
if (obj.match(/^__REGEXP /)) {
|
|
107
|
-
|
|
110
|
+
const m = obj.split("__REGEXP ")[1].match(/\/(.*)\/(.*)?/);
|
|
111
|
+
if (!m) {
|
|
112
|
+
return /(?:)/;
|
|
113
|
+
}
|
|
108
114
|
return new RegExp(m[1], m[2] || "");
|
|
109
115
|
}
|
|
110
116
|
if (obj.startsWith("__DATE ")) {
|
|
@@ -118,14 +124,14 @@ function fromJSON(obj, externalReferences) {
|
|
|
118
124
|
// return js(obj.substring(11), externalReferences);
|
|
119
125
|
// }
|
|
120
126
|
if (obj.match(/^__HTML /)) {
|
|
121
|
-
//@ts-
|
|
122
|
-
if (typeof $ !==
|
|
127
|
+
//@ts-expect-error
|
|
128
|
+
if (typeof $ !== "undefined")
|
|
123
129
|
return $(obj.substring(7))[0];
|
|
124
130
|
else
|
|
125
131
|
return obj;
|
|
126
132
|
}
|
|
127
133
|
if (obj.startsWith("__ERROR ")) {
|
|
128
|
-
|
|
134
|
+
const error = new Error();
|
|
129
135
|
error.stack = obj.substring(8);
|
|
130
136
|
return error;
|
|
131
137
|
}
|
|
@@ -134,11 +140,11 @@ function fromJSON(obj, externalReferences) {
|
|
|
134
140
|
}
|
|
135
141
|
if (obj.startsWith("__UINT8ARRAY ")) {
|
|
136
142
|
// Convert base64 string back to Uint8Array
|
|
137
|
-
return new Uint8Array(Buffer.from(obj.substring(13),
|
|
143
|
+
return new Uint8Array(Buffer.from(obj.substring(13), "base64"));
|
|
138
144
|
}
|
|
139
145
|
if (obj.startsWith("__BUFFER ")) {
|
|
140
146
|
// Convert base64 string back to Buffer (backward compatibility)
|
|
141
|
-
return Buffer.from(obj.substring(9),
|
|
147
|
+
return Buffer.from(obj.substring(9), "base64");
|
|
142
148
|
}
|
|
143
149
|
// deal with duplicate refs
|
|
144
150
|
if (obj.match(/^__duplicate_ref_/)) {
|
|
@@ -150,28 +156,29 @@ function fromJSON(obj, externalReferences) {
|
|
|
150
156
|
if (!(isObject(obj) || _.isArray(obj)))
|
|
151
157
|
return obj;
|
|
152
158
|
// deal with objects that have duplicate refs
|
|
153
|
-
|
|
159
|
+
let dup_ref = null;
|
|
154
160
|
obj = _.clone(obj); // don't mess up the original JSON object
|
|
155
161
|
if (_.isArray(obj) && _.isString(obj[0]) && obj[0].match(/^__this_ref:/))
|
|
156
|
-
dup_ref = obj.shift().split(
|
|
162
|
+
dup_ref = obj.shift().split(":")[1];
|
|
157
163
|
else if (obj.__this_ref) {
|
|
158
164
|
dup_ref = obj.__this_ref;
|
|
159
165
|
delete obj.__this_ref;
|
|
160
166
|
}
|
|
161
|
-
|
|
167
|
+
let mObj = _.isArray(obj) ? [] : {};
|
|
162
168
|
if (dup_ref)
|
|
163
169
|
if (!dup_refs[dup_ref])
|
|
164
170
|
dup_refs[dup_ref] = mObj;
|
|
165
171
|
else
|
|
166
172
|
mObj = dup_refs[dup_ref];
|
|
167
173
|
// restore keys and recurse on objects
|
|
168
|
-
for (
|
|
169
|
-
if (!
|
|
174
|
+
for (const key of Object.keys(obj)) {
|
|
175
|
+
if (!Object.hasOwn(obj, key))
|
|
170
176
|
continue;
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
177
|
+
let outKey = key;
|
|
178
|
+
const value = recurse(obj[outKey]);
|
|
179
|
+
if (outKey.match(/^__DOLLAR_/))
|
|
180
|
+
outKey = `$${outKey.substring(9)}`;
|
|
181
|
+
mObj[outKey] = value;
|
|
175
182
|
}
|
|
176
183
|
return mObj;
|
|
177
184
|
}
|
package/dist/serial-json.test.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const serial_json_1 = require("./serial-json");
|
|
4
|
-
describe(
|
|
5
|
-
describe(
|
|
6
|
-
it(
|
|
4
|
+
describe("serial-json", () => {
|
|
5
|
+
describe("Uint8Array serialization", () => {
|
|
6
|
+
it("should serialize and deserialize Uint8Array correctly", () => {
|
|
7
7
|
const originalData = new Uint8Array([72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100]); // "Hello World"
|
|
8
8
|
const testObj = {
|
|
9
9
|
data: originalData,
|
|
10
|
-
name:
|
|
11
|
-
number: 42
|
|
10
|
+
name: "test",
|
|
11
|
+
number: 42,
|
|
12
12
|
};
|
|
13
13
|
// Test toJSON/fromJSON
|
|
14
14
|
const serialized = (0, serial_json_1.toJSON)(testObj);
|
|
@@ -16,18 +16,18 @@ describe('serial-json', () => {
|
|
|
16
16
|
const deserialized = (0, serial_json_1.fromJSON)(serialized);
|
|
17
17
|
expect(deserialized.data).toBeInstanceOf(Uint8Array);
|
|
18
18
|
expect(deserialized.data).toEqual(originalData);
|
|
19
|
-
expect(deserialized.name).toBe(
|
|
19
|
+
expect(deserialized.name).toBe("test");
|
|
20
20
|
expect(deserialized.number).toBe(42);
|
|
21
21
|
});
|
|
22
|
-
it(
|
|
22
|
+
it("should serialize and deserialize nested Uint8Array correctly", () => {
|
|
23
23
|
const data1 = new Uint8Array([1, 2, 3]);
|
|
24
24
|
const data2 = new Uint8Array([4, 5, 6]);
|
|
25
25
|
const testObj = {
|
|
26
26
|
chunks: [data1, data2],
|
|
27
27
|
metadata: {
|
|
28
28
|
firstChunk: data1,
|
|
29
|
-
totalSize: 6
|
|
30
|
-
}
|
|
29
|
+
totalSize: 6,
|
|
30
|
+
},
|
|
31
31
|
};
|
|
32
32
|
const serialized = (0, serial_json_1.toJSON)(testObj);
|
|
33
33
|
const deserialized = (0, serial_json_1.fromJSON)(serialized);
|
|
@@ -40,20 +40,20 @@ describe('serial-json', () => {
|
|
|
40
40
|
expect(deserialized.metadata.firstChunk).toEqual(data1);
|
|
41
41
|
expect(deserialized.metadata.totalSize).toBe(6);
|
|
42
42
|
});
|
|
43
|
-
it(
|
|
43
|
+
it("should work with JSON string serialization", () => {
|
|
44
44
|
const originalData = new Uint8Array([255, 0, 128, 64]);
|
|
45
45
|
const testObj = { binaryData: originalData };
|
|
46
46
|
const jsonString = (0, serial_json_1.toJSONString)(testObj);
|
|
47
|
-
expect(typeof jsonString).toBe(
|
|
48
|
-
expect(jsonString).toContain(
|
|
47
|
+
expect(typeof jsonString).toBe("string");
|
|
48
|
+
expect(jsonString).toContain("__UINT8ARRAY");
|
|
49
49
|
const deserialized = (0, serial_json_1.fromJSONString)(jsonString);
|
|
50
50
|
expect(deserialized.binaryData).toBeInstanceOf(Uint8Array);
|
|
51
51
|
expect(deserialized.binaryData).toEqual(originalData);
|
|
52
52
|
});
|
|
53
53
|
});
|
|
54
|
-
describe(
|
|
55
|
-
it(
|
|
56
|
-
const originalBuffer = Buffer.from(
|
|
54
|
+
describe("Buffer backward compatibility", () => {
|
|
55
|
+
it("should serialize and deserialize Buffer correctly", () => {
|
|
56
|
+
const originalBuffer = Buffer.from("Hello Buffer");
|
|
57
57
|
const testObj = { bufferData: originalBuffer };
|
|
58
58
|
const serialized = (0, serial_json_1.toJSON)(testObj);
|
|
59
59
|
expect(serialized.bufferData).toMatch(/^__BUFFER /);
|
|
@@ -62,21 +62,21 @@ describe('serial-json', () => {
|
|
|
62
62
|
expect(deserialized.bufferData).toEqual(originalBuffer);
|
|
63
63
|
});
|
|
64
64
|
});
|
|
65
|
-
describe(
|
|
66
|
-
it(
|
|
65
|
+
describe("existing functionality", () => {
|
|
66
|
+
it("should still handle other special types", () => {
|
|
67
67
|
const testObj = {
|
|
68
|
-
date: new Date(
|
|
68
|
+
date: new Date("2023-01-01T00:00:00.000Z"),
|
|
69
69
|
regex: /test/gi,
|
|
70
|
-
error: new Error(
|
|
70
|
+
error: new Error("test error"),
|
|
71
71
|
nan: NaN,
|
|
72
72
|
infinity: Infinity,
|
|
73
|
-
undef: undefined
|
|
73
|
+
undef: undefined,
|
|
74
74
|
};
|
|
75
75
|
const deserialized = (0, serial_json_1.fromJSON)((0, serial_json_1.toJSON)(testObj));
|
|
76
76
|
expect(deserialized.date).toBeInstanceOf(Date);
|
|
77
|
-
expect(deserialized.date.toISOString()).toBe(
|
|
77
|
+
expect(deserialized.date.toISOString()).toBe("2023-01-01T00:00:00.000Z");
|
|
78
78
|
expect(deserialized.regex).toBeInstanceOf(RegExp);
|
|
79
|
-
expect(deserialized.regex.toString()).toBe(
|
|
79
|
+
expect(deserialized.regex.toString()).toBe("/test/gi");
|
|
80
80
|
expect(deserialized.error).toBeInstanceOf(Error);
|
|
81
81
|
expect(Number.isNaN(deserialized.nan)).toBe(true);
|
|
82
82
|
expect(deserialized.infinity).toBe(Infinity);
|
package/dist/system-ids.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.peersCorePackageRepoUrl = exports.peersCorePackageId = exports.runWorkflowToolId = exports.defaultSendMessageToolId = exports.defaultAssistantRunnerToolId = exports.openCodeAssistantId = exports.defaultAssistantId = exports.peersRootUserId = void 0;
|
|
4
|
-
exports.peersRootUserId =
|
|
5
|
-
exports.defaultAssistantId =
|
|
4
|
+
exports.peersRootUserId = "000peers0user000000000001";
|
|
5
|
+
exports.defaultAssistantId = "000peers0bot00000000shell";
|
|
6
6
|
// export const defaultAssistantId = '000peers0bot000000000bot1';
|
|
7
|
-
exports.openCodeAssistantId =
|
|
8
|
-
exports.defaultAssistantRunnerToolId =
|
|
9
|
-
exports.defaultSendMessageToolId =
|
|
10
|
-
exports.runWorkflowToolId =
|
|
11
|
-
exports.peersCorePackageId =
|
|
12
|
-
exports.peersCorePackageRepoUrl =
|
|
7
|
+
exports.openCodeAssistantId = "00mlwl2km2opencode0000001";
|
|
8
|
+
exports.defaultAssistantRunnerToolId = "000peers0tool00000runner1";
|
|
9
|
+
exports.defaultSendMessageToolId = "000peers0tool00000sendmsg";
|
|
10
|
+
exports.runWorkflowToolId = "000peers0tool0runworkflow";
|
|
11
|
+
exports.peersCorePackageId = "00mh0wlipjixk2gqmurbwee0o";
|
|
12
|
+
exports.peersCorePackageRepoUrl = "https://github.com/peers-app/peers-core";
|
package/dist/tools/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from
|
|
1
|
+
export * from "./tools-factory";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IToolInstance } from "../data";
|
|
1
|
+
import type { IToolInstance } from "../data";
|
|
2
2
|
export declare function registerTool(toolInstance: IToolInstance): void;
|
|
3
3
|
export declare function getRegisteredTool(toolId: string): IToolInstance | undefined;
|
|
4
4
|
export declare function getAllRegisteredTools(): IToolInstance[];
|
|
@@ -14,7 +14,7 @@ function registerTool(toolInstance) {
|
|
|
14
14
|
if (s1 !== s2) {
|
|
15
15
|
console.warn(`Attempt to register new tool with existing toolId ${toolId}, it will be ignored`, {
|
|
16
16
|
registered: registeredToolInstances[toolId].tool,
|
|
17
|
-
incoming: toolInstance.tool
|
|
17
|
+
incoming: toolInstance.tool,
|
|
18
18
|
});
|
|
19
19
|
}
|
|
20
20
|
return;
|
|
@@ -28,7 +28,7 @@ function getAllRegisteredTools() {
|
|
|
28
28
|
return Object.values(registeredToolInstances);
|
|
29
29
|
}
|
|
30
30
|
function clearRegisteredTools() {
|
|
31
|
-
Object.keys(registeredToolInstances).forEach(key => {
|
|
31
|
+
Object.keys(registeredToolInstances).forEach((key) => {
|
|
32
32
|
delete registeredToolInstances[key];
|
|
33
33
|
});
|
|
34
34
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { IAssistant } from "../data/assistants";
|
|
2
|
-
import { IMessage } from "../data/messages";
|
|
3
|
-
import { IWorkflowLog } from "../data/workflow-logs";
|
|
1
|
+
import type { IAssistant } from "../data/assistants";
|
|
2
|
+
import type { IMessage } from "../data/messages";
|
|
3
|
+
import type { IWorkflowLog } from "../data/workflow-logs";
|
|
4
4
|
export interface IAssistantRunnerArgs {
|
|
5
5
|
assistant: IAssistant;
|
|
6
6
|
message: IMessage;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import type { IAssistant } from "../data";
|
|
2
|
-
import type {
|
|
2
|
+
import type { ITableDefinition } from "../data/orm/table-definitions.type";
|
|
3
3
|
import type { IToolInstance } from "../data/tools";
|
|
4
|
-
import type { IWorkflow } from "./workflow";
|
|
5
4
|
import type { IPeersUI } from "../peers-ui/peers-ui";
|
|
6
5
|
import type { IPeersUIRoute } from "../peers-ui/peers-ui.types";
|
|
7
|
-
import type {
|
|
6
|
+
import type { IAppNav } from "./app-nav";
|
|
7
|
+
import type { IWorkflow } from "./workflow";
|
|
8
8
|
export interface IPeersPackage {
|
|
9
9
|
packageId: string;
|
|
10
10
|
toolInstances?: IToolInstance[];
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { IWorkflowLog } from "../data/workflow-logs";
|
|
1
|
+
import type { IWorkflowLog } from "../data/workflow-logs";
|
|
2
2
|
export type IWorkflowLogger = (logData: string | Omit<Partial<IWorkflowLog>, "workflowRunId" | "workflowLogId">) => Promise<IWorkflowLog>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import type { IToolInstance } from "../data/tools";
|
|
2
|
+
import type { IWorkflowRun } from "../data/workflow-runs";
|
|
3
|
+
import type { IAssistantRunnerArgs } from "./assistant-runner-args";
|
|
4
|
+
import type { IWorkflowLogger } from "./workflow-logger";
|
|
5
5
|
export interface IWorkflowRunContext {
|
|
6
6
|
contextId: string;
|
|
7
7
|
workflowRun: IWorkflowRun;
|
package/dist/types/workflow.d.ts
CHANGED
|
@@ -43,6 +43,8 @@ export declare const workflowSchema: z.ZodObject<{
|
|
|
43
43
|
}, "strip", z.ZodTypeAny, {
|
|
44
44
|
name: string;
|
|
45
45
|
description: string;
|
|
46
|
+
createdBy: string;
|
|
47
|
+
createdAt: Date;
|
|
46
48
|
workflowId: string;
|
|
47
49
|
defaultAssistantId: string;
|
|
48
50
|
instructions: {
|
|
@@ -51,22 +53,20 @@ export declare const workflowSchema: z.ZodObject<{
|
|
|
51
53
|
directCallToolId?: string | undefined;
|
|
52
54
|
subWorkflowId?: string | undefined;
|
|
53
55
|
}[];
|
|
54
|
-
createdBy: string;
|
|
55
|
-
createdAt: Date;
|
|
56
56
|
updatedAt: Date;
|
|
57
57
|
}, {
|
|
58
58
|
name: string;
|
|
59
59
|
description: string;
|
|
60
|
+
createdBy: string;
|
|
60
61
|
workflowId: string;
|
|
61
62
|
defaultAssistantId: string;
|
|
62
|
-
|
|
63
|
+
createdAt?: Date | undefined;
|
|
63
64
|
instructions?: {
|
|
64
65
|
markdown?: string | undefined;
|
|
65
66
|
onError?: string | undefined;
|
|
66
67
|
directCallToolId?: string | undefined;
|
|
67
68
|
subWorkflowId?: string | undefined;
|
|
68
69
|
}[] | undefined;
|
|
69
|
-
createdAt?: Date | undefined;
|
|
70
70
|
updatedAt?: Date | undefined;
|
|
71
71
|
}>;
|
|
72
72
|
export type IWorkflow = z.infer<typeof workflowSchema>;
|
package/dist/types/workflow.js
CHANGED
|
@@ -4,22 +4,35 @@ exports.workflowSchema = exports.workflowInstructionSchema = void 0;
|
|
|
4
4
|
const zod_1 = require("zod");
|
|
5
5
|
const zod_types_1 = require("./zod-types");
|
|
6
6
|
exports.workflowInstructionSchema = zod_1.z.object({
|
|
7
|
-
markdown: zod_1.z.string().optional().describe(
|
|
8
|
-
onError: zod_1.z
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
markdown: zod_1.z.string().optional().describe("The instruction in markdown format"),
|
|
8
|
+
onError: zod_1.z
|
|
9
|
+
.string()
|
|
10
|
+
.optional()
|
|
11
|
+
.describe("The instruction to run if there is an error while running this instruction"),
|
|
12
|
+
directCallToolId: zod_types_1.zodPeerId.optional().describe("The tool to call directly with the tool id"),
|
|
13
|
+
subWorkflowId: zod_types_1.zodPeerId.optional().describe("The sub workflow to run with the workflow id"),
|
|
11
14
|
});
|
|
12
15
|
exports.workflowSchema = zod_1.z.object({
|
|
13
16
|
workflowId: zod_types_1.zodPeerId,
|
|
14
|
-
name: zod_1.z.string().describe(
|
|
15
|
-
description: zod_1.z
|
|
16
|
-
|
|
17
|
+
name: zod_1.z.string().describe("The name of the workflow"),
|
|
18
|
+
description: zod_1.z
|
|
19
|
+
.string()
|
|
20
|
+
.describe("A detailed description of the workflow that can be used to help users and assistants understand what the workflow does"),
|
|
21
|
+
defaultAssistantId: zod_types_1.zodPeerId.describe("The default assistant to handle instructions when the workflow is run"),
|
|
17
22
|
instructions: exports.workflowInstructionSchema
|
|
18
|
-
.array()
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
.array()
|
|
24
|
+
.describe([
|
|
25
|
+
"The instructions for the workflow. This should be written in markdown and can include special links to other workflows, tools, etc. via mentions",
|
|
26
|
+
"The instructions should be broken down into discrete steps and should be as clear as possible.",
|
|
27
|
+
].join(" "))
|
|
28
|
+
.default([]),
|
|
29
|
+
createdBy: zod_types_1.zodPeerId.describe("The user who created the workflow"),
|
|
30
|
+
createdAt: zod_1.z
|
|
31
|
+
.date()
|
|
32
|
+
.default(() => new Date())
|
|
33
|
+
.describe("The date the workflow was created"),
|
|
34
|
+
updatedAt: zod_1.z
|
|
35
|
+
.date()
|
|
36
|
+
.default(() => new Date())
|
|
37
|
+
.describe("The date the workflow was last updated"),
|
|
25
38
|
});
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { z } from
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export { z } from "zod";
|
|
2
3
|
export declare const zodAnyObject: z.ZodObject<{}, "strip", z.ZodAny, z.objectOutputType<{}, z.ZodAny, "strip">, z.objectInputType<{}, z.ZodAny, "strip">>;
|
|
3
4
|
export declare const zodAnyObjectOrArray: z.ZodUnion<[z.ZodObject<{}, "strip", z.ZodAny, z.objectOutputType<{}, z.ZodAny, "strip">, z.objectInputType<{}, z.ZodAny, "strip">>, z.ZodArray<z.ZodAny, "many">]>;
|
|
4
5
|
export declare const zodPeerId: z.ZodEffects<z.ZodString, string, string>;
|
package/dist/types/zod-types.js
CHANGED
|
@@ -1,12 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.zodPeerId = exports.zodAnyObjectOrArray = exports.zodAnyObject = void 0;
|
|
3
|
+
exports.zodPeerId = exports.zodAnyObjectOrArray = exports.zodAnyObject = exports.z = void 0;
|
|
4
4
|
const zod_1 = require("zod");
|
|
5
|
-
const field_type_1 = require("./field-type");
|
|
6
5
|
const utils_1 = require("../utils");
|
|
6
|
+
const field_type_1 = require("./field-type");
|
|
7
|
+
// Re-export zod so consumers import it via peers-sdk. This guarantees every
|
|
8
|
+
// schema in the graph is built with the same zod instance that peers-sdk's
|
|
9
|
+
// schema utilities (fieldsToSchema, schemaToFields, etc.) unpack, which
|
|
10
|
+
// matters because those helpers reach into zod internals (`_def`, shape).
|
|
11
|
+
var zod_2 = require("zod");
|
|
12
|
+
Object.defineProperty(exports, "z", { enumerable: true, get: function () { return zod_2.z; } });
|
|
7
13
|
exports.zodAnyObject = zod_1.z.object({}).catchall(zod_1.z.any());
|
|
8
14
|
exports.zodAnyObjectOrArray = zod_1.z.union([exports.zodAnyObject, zod_1.z.array(zod_1.z.any())]);
|
|
9
|
-
exports.zodPeerId = zod_1.z.string().refine(value => {
|
|
15
|
+
exports.zodPeerId = zod_1.z.string().refine((value) => {
|
|
10
16
|
return (0, utils_1.isid)(value);
|
|
11
17
|
}, {
|
|
12
18
|
message: "Invalid peer id, it must be a 25 character alphanumeric string",
|
|
@@ -16,15 +16,15 @@ exports.encryptWithSecret = encryptWithSecret;
|
|
|
16
16
|
exports.decryptWithSecret = decryptWithSecret;
|
|
17
17
|
exports.generateConfirmationHash = generateConfirmationHash;
|
|
18
18
|
exports.isValidConnectionCode = isValidConnectionCode;
|
|
19
|
-
const nacl = require("tweetnacl");
|
|
20
19
|
const sha2_1 = require("@noble/hashes/sha2");
|
|
20
|
+
const nacl = require("tweetnacl");
|
|
21
21
|
const tx_encoding_1 = require("../device/tx-encoding");
|
|
22
22
|
const keys_1 = require("../keys");
|
|
23
23
|
/**
|
|
24
24
|
* Crockford Base32 alphabet.
|
|
25
25
|
* Excludes I, L, O, U to avoid confusion with 1, 1, 0, V respectively.
|
|
26
26
|
*/
|
|
27
|
-
const CROCKFORD_ALPHABET =
|
|
27
|
+
const CROCKFORD_ALPHABET = "0123456789ABCDEFGHJKMNPQRSTVWXYZ";
|
|
28
28
|
/**
|
|
29
29
|
* Generate random bytes using nacl.
|
|
30
30
|
*/
|
|
@@ -35,7 +35,7 @@ function randomBytes(length) {
|
|
|
35
35
|
* Encode bytes to Crockford Base32 string.
|
|
36
36
|
*/
|
|
37
37
|
function toCrockfordBase32(bytes, length) {
|
|
38
|
-
let result =
|
|
38
|
+
let result = "";
|
|
39
39
|
let i = 0;
|
|
40
40
|
while (result.length < length) {
|
|
41
41
|
if (i >= bytes.length) {
|
|
@@ -82,7 +82,7 @@ function generateConnectionCode() {
|
|
|
82
82
|
* @returns Formatted as "XXXX-YYYY-ZZZZ"
|
|
83
83
|
*/
|
|
84
84
|
function formatConnectionCode(code) {
|
|
85
|
-
const normalized = code.toUpperCase().replace(/[^0-9A-Z]/g,
|
|
85
|
+
const normalized = code.toUpperCase().replace(/[^0-9A-Z]/g, "");
|
|
86
86
|
if (normalized.length !== 12) {
|
|
87
87
|
throw new Error(`Connection code must be 12 characters, got ${normalized.length}`);
|
|
88
88
|
}
|
|
@@ -94,7 +94,7 @@ function formatConnectionCode(code) {
|
|
|
94
94
|
* @returns Object with alias and secret
|
|
95
95
|
*/
|
|
96
96
|
function parseConnectionCode(formatted) {
|
|
97
|
-
const normalized = formatted.toUpperCase().replace(/[^0-9A-Z]/g,
|
|
97
|
+
const normalized = formatted.toUpperCase().replace(/[^0-9A-Z]/g, "");
|
|
98
98
|
if (normalized.length !== 12) {
|
|
99
99
|
throw new Error(`Connection code must be 12 characters, got ${normalized.length}`);
|
|
100
100
|
}
|
|
@@ -134,7 +134,7 @@ function decryptWithSecret(encrypted, secret) {
|
|
|
134
134
|
const ciphertext = combined.slice(24);
|
|
135
135
|
const decrypted = nacl.secretbox.open(ciphertext, nonce, key);
|
|
136
136
|
if (!decrypted) {
|
|
137
|
-
throw new Error(
|
|
137
|
+
throw new Error("Decryption failed - invalid secret or corrupted data");
|
|
138
138
|
}
|
|
139
139
|
return (0, tx_encoding_1.txDecode)(decrypted);
|
|
140
140
|
}
|
|
@@ -160,7 +160,7 @@ function generateConfirmationHash(userA, userB) {
|
|
|
160
160
|
*/
|
|
161
161
|
function isValidConnectionCode(code) {
|
|
162
162
|
try {
|
|
163
|
-
const normalized = code.toUpperCase().replace(/[^0-9A-Z]/g,
|
|
163
|
+
const normalized = code.toUpperCase().replace(/[^0-9A-Z]/g, "");
|
|
164
164
|
if (normalized.length !== 12)
|
|
165
165
|
return false;
|
|
166
166
|
// Check all characters are valid Crockford Base32
|