@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/utils.js
CHANGED
|
@@ -21,9 +21,9 @@ exports.getFullTableName = getFullTableName;
|
|
|
21
21
|
const _ = require("lodash");
|
|
22
22
|
const nacl = require("tweetnacl");
|
|
23
23
|
const peer_device_1 = require("./types/peer-device");
|
|
24
|
-
const stableStringify = require(
|
|
24
|
+
const stableStringify = require("fast-json-stable-stringify");
|
|
25
25
|
function cryptoRandomString(length) {
|
|
26
|
-
let s =
|
|
26
|
+
let s = "";
|
|
27
27
|
let r = nacl.randomBytes(length + 6);
|
|
28
28
|
let i = 0;
|
|
29
29
|
while (s.length < length) {
|
|
@@ -44,7 +44,7 @@ function cryptoRandomString(length) {
|
|
|
44
44
|
}
|
|
45
45
|
function newid() {
|
|
46
46
|
// modeled after mongo ids, timestamp + counter + random but we're going to skip counter and have bigger random
|
|
47
|
-
// people can switch to using a counter + random later if they want (or do something else with the random part).
|
|
47
|
+
// people can switch to using a counter + random later if they want (or do something else with the random part).
|
|
48
48
|
// This id is going to be a 128 bit number so it fits naturally into memory.
|
|
49
49
|
// 2 ** 128 ~= 3.4e38 is the maximum it can be
|
|
50
50
|
// For efficient transmission, storage, presentation, and usage we're going to represent this number with base 36 [0-9a-z]
|
|
@@ -53,31 +53,29 @@ function newid() {
|
|
|
53
53
|
// but we're dealing in base 36 not base 10
|
|
54
54
|
// (1625282091498).toString(36) == "kqn6zrvu" (length 8)
|
|
55
55
|
// Number.parseInt("zzzzzzzz", 36) == 2821109907455 == year 2059. Way too soon so going up to 9 characters
|
|
56
|
-
// Number.parseInt("zzzzzzzzz", 36) == 101559956668415 == year 5188.
|
|
56
|
+
// Number.parseInt("zzzzzzzzz", 36) == 101559956668415 == year 5188.
|
|
57
57
|
// but the max size of 9 left most can only be "f55n5nmuu" == 42720753566838 == year 3323. That could still work but only ~ 1300 years
|
|
58
58
|
// that leaves 16 characters to represent a random number to prevent collisions each millisecond, 36 ** 16 ~= 8e24
|
|
59
59
|
// Allocating one more character to the time and one less to the random number to avoid hitting max time in any conceivable future
|
|
60
60
|
// now our max time is new Date(Number.parseInt('f55n5nmuua',36)) == +050705-08-09T23:40:06.178Z. 50k years from now.
|
|
61
61
|
// We still have 15 chars for our random number. 36 ** 15 ~= 2e23
|
|
62
|
-
// That is still a very large number and the chance of a collision should be so small as to be effectively globally unique
|
|
62
|
+
// That is still a very large number and the chance of a collision should be so small as to be effectively globally unique
|
|
63
63
|
// and certainly unique in any group's database.
|
|
64
|
-
const time = Date.now().toString(36).padStart(10,
|
|
64
|
+
const time = Date.now().toString(36).padStart(10, "0"); // e.g: "00kq6xh45f", length == 10
|
|
65
65
|
return time + cryptoRandomString(15);
|
|
66
66
|
}
|
|
67
|
-
exports.MIN_ID =
|
|
68
|
-
|
|
69
|
-
exports.MAX_ID = 'f55n5nmuua' + 'z'.repeat(15); // 50k years from now
|
|
67
|
+
exports.MIN_ID = "0".repeat(25); // 1970
|
|
68
|
+
exports.MAX_ID = `f55n5nmuua${"z".repeat(15)}`; // 50k years from now
|
|
70
69
|
function isid(id) {
|
|
71
70
|
id = String(id);
|
|
72
71
|
const idMatch = Boolean(/^[0-9a-z]{25}$/i.exec(id));
|
|
73
72
|
if (idMatch) {
|
|
74
73
|
// only consider ids valid if they are less than current time (with 5 min buffer)
|
|
75
74
|
// This is to prevent people from making ids with times in the future to get them to always show up as the "newest" item and/or prematurely claim ids
|
|
76
|
-
return idTime(id) <
|
|
75
|
+
return idTime(id) < Date.now() + 300000;
|
|
77
76
|
}
|
|
78
77
|
return false;
|
|
79
78
|
}
|
|
80
|
-
;
|
|
81
79
|
function idTime(id) {
|
|
82
80
|
const time36 = id.substr(0, 10);
|
|
83
81
|
return Number.parseInt(time36, 36);
|
|
@@ -106,22 +104,22 @@ function simpleObjectHash(obj) {
|
|
|
106
104
|
return simpleHash(stableStringify(obj));
|
|
107
105
|
}
|
|
108
106
|
function sleep(ms = 0) {
|
|
109
|
-
return new Promise(resolve => setTimeout(resolve, ms));
|
|
107
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
110
108
|
}
|
|
111
|
-
function camelCaseToSpaces(s =
|
|
112
|
-
s = s.replace(/([a-z])([A-Z])/g,
|
|
113
|
-
// s = s.replace(/(GL)([A-Z])/g, '$1 $2'); // anything like GLAccounts, GLBatches, etc.
|
|
109
|
+
function camelCaseToSpaces(s = "") {
|
|
110
|
+
s = s.replace(/([a-z])([A-Z])/g, "$1 $2");
|
|
111
|
+
// s = s.replace(/(GL)([A-Z])/g, '$1 $2'); // anything like GLAccounts, GLBatches, etc.
|
|
114
112
|
s = s.replace("_", " ");
|
|
115
113
|
s = s[0]?.toUpperCase() + s.substr(1);
|
|
116
114
|
return s;
|
|
117
115
|
}
|
|
118
|
-
function camelCaseToHyphens(s =
|
|
116
|
+
function camelCaseToHyphens(s = "") {
|
|
119
117
|
s = camelCaseToSpaces(s);
|
|
120
|
-
return s.split(
|
|
118
|
+
return s.split(" ").join("-").toLowerCase();
|
|
121
119
|
}
|
|
122
|
-
exports.moneyFormatter = new Intl.NumberFormat(
|
|
123
|
-
style:
|
|
124
|
-
currency:
|
|
120
|
+
exports.moneyFormatter = new Intl.NumberFormat("en-US", {
|
|
121
|
+
style: "currency",
|
|
122
|
+
currency: "USD",
|
|
125
123
|
minimumFractionDigits: 2,
|
|
126
124
|
maximumFractionDigits: 2,
|
|
127
125
|
});
|
|
@@ -129,9 +127,9 @@ function formatMoney(value, precision = 2) {
|
|
|
129
127
|
if (precision === 2) {
|
|
130
128
|
return exports.moneyFormatter.format(value);
|
|
131
129
|
}
|
|
132
|
-
const _moneyFormatter = new Intl.NumberFormat(
|
|
133
|
-
style:
|
|
134
|
-
currency:
|
|
130
|
+
const _moneyFormatter = new Intl.NumberFormat("en-US", {
|
|
131
|
+
style: "currency",
|
|
132
|
+
currency: "USD",
|
|
135
133
|
minimumFractionDigits: precision,
|
|
136
134
|
maximumFractionDigits: precision,
|
|
137
135
|
});
|
|
@@ -166,13 +164,17 @@ function debounceByArgs(fn, wait = 300) {
|
|
|
166
164
|
const debouncedFn = _.debounce(fn, wait);
|
|
167
165
|
debouncedFunctions.set(key, debouncedFn);
|
|
168
166
|
}
|
|
169
|
-
|
|
167
|
+
const debouncedFn = debouncedFunctions.get(key);
|
|
168
|
+
if (debouncedFn === undefined) {
|
|
169
|
+
throw new Error("debounceByArgs: missing debounced function for key");
|
|
170
|
+
}
|
|
171
|
+
return debouncedFn(...args);
|
|
170
172
|
};
|
|
171
173
|
return debounced;
|
|
172
174
|
}
|
|
173
175
|
function getTimestamp() {
|
|
174
176
|
// check if in node.js environment
|
|
175
|
-
if (typeof performance ===
|
|
177
|
+
if (typeof performance === "undefined" || !performance.timeOrigin) {
|
|
176
178
|
// Fallback for environments without performance API
|
|
177
179
|
return Date.now();
|
|
178
180
|
}
|
|
@@ -193,13 +195,13 @@ async function retryOnErrorOrTimeout({ fn, connection, opts = {}, }) {
|
|
|
193
195
|
while (errorCount <= retriesOnError && timeoutCount <= retriesOnTimeout) {
|
|
194
196
|
try {
|
|
195
197
|
let sleepTimeout = null;
|
|
196
|
-
const sleepPromise = new Promise(resolve => {
|
|
198
|
+
const sleepPromise = new Promise((resolve) => {
|
|
197
199
|
sleepTimeout = setTimeout(() => {
|
|
198
200
|
resolve();
|
|
199
201
|
}, timeout);
|
|
200
202
|
});
|
|
201
203
|
await Promise.race([
|
|
202
|
-
fn().then(r => {
|
|
204
|
+
fn().then((r) => {
|
|
203
205
|
result = r;
|
|
204
206
|
resultSet = true;
|
|
205
207
|
}),
|
|
@@ -209,7 +211,7 @@ async function retryOnErrorOrTimeout({ fn, connection, opts = {}, }) {
|
|
|
209
211
|
if (resultSet) {
|
|
210
212
|
const totalTime = Date.now() - startTime;
|
|
211
213
|
connection.latencyMs = totalTime * 0.1 + connection.latencyMs * 0.9;
|
|
212
|
-
connection.errorRate =
|
|
214
|
+
connection.errorRate = connection.errorRate * 0.9;
|
|
213
215
|
return result;
|
|
214
216
|
}
|
|
215
217
|
// timeout *= 2; // double the timeout for the next attempt
|
|
@@ -221,7 +223,7 @@ async function retryOnErrorOrTimeout({ fn, connection, opts = {}, }) {
|
|
|
221
223
|
}
|
|
222
224
|
catch (error) {
|
|
223
225
|
finalError = error;
|
|
224
|
-
connection.errorRate =
|
|
226
|
+
connection.errorRate = connection.errorRate * 0.9 + 0.1;
|
|
225
227
|
errorCount++;
|
|
226
228
|
if (connection.closed) {
|
|
227
229
|
throw new Error(`connection has been closed`);
|
|
@@ -236,8 +238,8 @@ async function retryOnErrorOrTimeout({ fn, connection, opts = {}, }) {
|
|
|
236
238
|
else {
|
|
237
239
|
const weightedTimeout = timeoutCount * 0.1;
|
|
238
240
|
const weightedInverse = 1 - weightedTimeout;
|
|
239
|
-
connection.errorRate =
|
|
240
|
-
connection.latencyMs =
|
|
241
|
+
connection.errorRate = connection.errorRate * weightedInverse + weightedTimeout;
|
|
242
|
+
connection.latencyMs = weightedTimeout * timeout + connection.latencyMs * weightedInverse;
|
|
241
243
|
throw new Error(`Timeout after ${timeoutCount} retries waiting for ${timeout}ms`);
|
|
242
244
|
}
|
|
243
245
|
}
|
|
@@ -245,5 +247,5 @@ async function retryOnErrorOrTimeout({ fn, connection, opts = {}, }) {
|
|
|
245
247
|
* Table name is "name_id" if `id` is present, otherwise just "name"
|
|
246
248
|
*/
|
|
247
249
|
function getFullTableName(metaData) {
|
|
248
|
-
return [metaData.name, metaData.tableId].filter(v => v && v.length > 0).join(
|
|
250
|
+
return [metaData.name, metaData.tableId].filter((v) => v && v.length > 0).join("_");
|
|
249
251
|
}
|
package/dist/utils.test.js
CHANGED
|
@@ -33,7 +33,7 @@ describe("newid", () => {
|
|
|
33
33
|
}
|
|
34
34
|
average /= counts.length;
|
|
35
35
|
const maxDeviation = Math.max(max - average, average - min);
|
|
36
|
-
const maxDeviationPercent = maxDeviation / average * 100;
|
|
36
|
+
const maxDeviationPercent = (maxDeviation / average) * 100;
|
|
37
37
|
console.log({ average, max, min, maxDeviation, maxDeviationPercent });
|
|
38
38
|
// expect all values to be within 0.5% of the average
|
|
39
39
|
expect(maxDeviationPercent).toBeLessThan(0.5);
|
|
@@ -45,18 +45,22 @@ describe("newid", () => {
|
|
|
45
45
|
expect(randomPart.length).toBe(15);
|
|
46
46
|
for (let j = 0; j < randomPart.length; j++) {
|
|
47
47
|
const c = randomPart[j];
|
|
48
|
-
const k = `${c},${String(j).padStart(2,
|
|
48
|
+
const k = `${c},${String(j).padStart(2, "0")}`;
|
|
49
49
|
buckets[k] = (buckets[k] || 0) + 1;
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
52
|
const orderedKeys = {};
|
|
53
|
-
let keys = (0, lodash_1.sortBy)(Object.keys(buckets), key => Number(key.split(
|
|
54
|
-
keys = (0, lodash_1.sortBy)(keys, key => key.split(
|
|
55
|
-
keys.forEach(key =>
|
|
53
|
+
let keys = (0, lodash_1.sortBy)(Object.keys(buckets), (key) => Number(key.split(",")[1]));
|
|
54
|
+
keys = (0, lodash_1.sortBy)(keys, (key) => key.split(",")[0]);
|
|
55
|
+
keys.forEach((key) => {
|
|
56
|
+
orderedKeys[key] = buckets[key];
|
|
57
|
+
});
|
|
56
58
|
console.log(orderedKeys);
|
|
57
59
|
const orderedValues = {};
|
|
58
|
-
|
|
59
|
-
values.forEach(([key, value]) =>
|
|
60
|
+
const values = (0, lodash_1.sortBy)(Object.entries(buckets), ([, value]) => value);
|
|
61
|
+
values.forEach(([key, value]) => {
|
|
62
|
+
orderedValues[key] = value;
|
|
63
|
+
});
|
|
60
64
|
console.log(orderedValues);
|
|
61
65
|
const counts = Object.values(buckets);
|
|
62
66
|
let average = 0;
|
|
@@ -69,7 +73,7 @@ describe("newid", () => {
|
|
|
69
73
|
}
|
|
70
74
|
average /= counts.length;
|
|
71
75
|
const maxDeviation = Math.max(max - average, average - min);
|
|
72
|
-
const maxDeviationPercent = maxDeviation / average * 100;
|
|
76
|
+
const maxDeviationPercent = (maxDeviation / average) * 100;
|
|
73
77
|
console.log({ average, max, min, maxDeviation, maxDeviationPercent });
|
|
74
78
|
// expect all values to be within 2% of the average
|
|
75
79
|
expect(maxDeviationPercent).toBeLessThan(2);
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Shared utility for formatting workflow logs into readable text.
|
|
5
5
|
* Used by both the CLI and UI to display log information consistently.
|
|
6
6
|
*/
|
|
7
|
-
import { IWorkflowLog } from
|
|
7
|
+
import type { IWorkflowLog } from "./data/workflow-logs";
|
|
8
8
|
export interface FormattedLog {
|
|
9
9
|
/** The original log object */
|
|
10
10
|
log: IWorkflowLog;
|
|
@@ -8,9 +8,9 @@
|
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.formatWorkflowLogDetailed = formatWorkflowLogDetailed;
|
|
10
10
|
exports.formatWorkflowLogOneLine = formatWorkflowLogOneLine;
|
|
11
|
+
const assistants_1 = require("./data/assistants");
|
|
11
12
|
const tools_1 = require("./data/tools");
|
|
12
13
|
const workflows_1 = require("./data/workflows");
|
|
13
|
-
const assistants_1 = require("./data/assistants");
|
|
14
14
|
const mentions_1 = require("./mentions");
|
|
15
15
|
const system_ids_1 = require("./system-ids");
|
|
16
16
|
/**
|
|
@@ -19,21 +19,22 @@ const system_ids_1 = require("./system-ids");
|
|
|
19
19
|
async function formatWorkflowLogDetailed(log) {
|
|
20
20
|
const lines = [];
|
|
21
21
|
// Build the title line
|
|
22
|
-
let title =
|
|
22
|
+
let title = "";
|
|
23
23
|
if (log.toolId) {
|
|
24
24
|
try {
|
|
25
25
|
const tool = await (0, tools_1.Tools)().get(log.toolId);
|
|
26
26
|
// Check if it's running an assistant
|
|
27
|
-
if ((tool?.isAssistantRunner || log.toolId === system_ids_1.defaultAssistantRunnerToolId) &&
|
|
27
|
+
if ((tool?.isAssistantRunner || log.toolId === system_ids_1.defaultAssistantRunnerToolId) &&
|
|
28
|
+
log.toolArgs?.assistantId) {
|
|
28
29
|
const assistant = await (0, assistants_1.Assistants)().get(log.toolArgs.assistantId);
|
|
29
30
|
const assistantMention = (0, mentions_1.formatMention)({
|
|
30
|
-
kind:
|
|
31
|
-
name: assistant?.name ||
|
|
31
|
+
kind: "assistant",
|
|
32
|
+
name: assistant?.name || "Assistant",
|
|
32
33
|
id: log.toolArgs.assistantId,
|
|
33
34
|
});
|
|
34
35
|
const toolMention = (0, mentions_1.formatMention)({
|
|
35
|
-
kind:
|
|
36
|
-
name: tool?.name ||
|
|
36
|
+
kind: "tool",
|
|
37
|
+
name: tool?.name || "assistant_runner",
|
|
37
38
|
id: log.toolId,
|
|
38
39
|
});
|
|
39
40
|
title = `${assistantMention} via ${toolMention}`;
|
|
@@ -42,24 +43,24 @@ async function formatWorkflowLogDetailed(log) {
|
|
|
42
43
|
else if (log.toolId === system_ids_1.runWorkflowToolId && log.toolArgs?.workflowId) {
|
|
43
44
|
const workflow = await (0, workflows_1.Workflows)().get(log.toolArgs.workflowId);
|
|
44
45
|
title = (0, mentions_1.formatMention)({
|
|
45
|
-
kind:
|
|
46
|
-
name: workflow?.name ||
|
|
46
|
+
kind: "workflow",
|
|
47
|
+
name: workflow?.name || "workflow",
|
|
47
48
|
id: log.toolArgs.workflowId,
|
|
48
49
|
});
|
|
49
50
|
}
|
|
50
51
|
// Regular tool
|
|
51
52
|
else {
|
|
52
53
|
title = (0, mentions_1.formatMention)({
|
|
53
|
-
kind:
|
|
54
|
+
kind: "tool",
|
|
54
55
|
name: tool?.name || log.toolId,
|
|
55
56
|
id: log.toolId,
|
|
56
57
|
});
|
|
57
58
|
}
|
|
58
59
|
}
|
|
59
|
-
catch (
|
|
60
|
+
catch (_e) {
|
|
60
61
|
// Fallback to mention with system name or ID
|
|
61
62
|
title = (0, mentions_1.formatMention)({
|
|
62
|
-
kind:
|
|
63
|
+
kind: "tool",
|
|
63
64
|
name: log.toolId,
|
|
64
65
|
id: log.toolId,
|
|
65
66
|
});
|
|
@@ -73,7 +74,7 @@ async function formatWorkflowLogDetailed(log) {
|
|
|
73
74
|
title = log.logText;
|
|
74
75
|
}
|
|
75
76
|
else {
|
|
76
|
-
title =
|
|
77
|
+
title = "Log entry";
|
|
77
78
|
}
|
|
78
79
|
lines.push(title);
|
|
79
80
|
// Always show args (excluding IDs we've already incorporated into the title)
|
|
@@ -85,15 +86,13 @@ async function formatWorkflowLogDetailed(log) {
|
|
|
85
86
|
}
|
|
86
87
|
// Show result
|
|
87
88
|
if (log.resultObject) {
|
|
88
|
-
const resultStr = typeof log.resultObject ===
|
|
89
|
-
? log.resultObject
|
|
90
|
-
: JSON.stringify(log.resultObject);
|
|
89
|
+
const resultStr = typeof log.resultObject === "string" ? log.resultObject : JSON.stringify(log.resultObject);
|
|
91
90
|
lines.push(`Result: ${resultStr}`);
|
|
92
91
|
}
|
|
93
92
|
else if (log.result) {
|
|
94
93
|
lines.push(`Result: ${log.result}`);
|
|
95
94
|
}
|
|
96
|
-
return lines.join(
|
|
95
|
+
return lines.join("\n");
|
|
97
96
|
}
|
|
98
97
|
/**
|
|
99
98
|
* Format a workflow log into a single-line summary
|
|
@@ -105,5 +104,5 @@ async function formatWorkflowLogOneLine(log) {
|
|
|
105
104
|
}
|
|
106
105
|
const detailed = await formatWorkflowLogDetailed(log);
|
|
107
106
|
// Return just the first line (the title)
|
|
108
|
-
return detailed.split(
|
|
107
|
+
return detailed.split("\n")[0];
|
|
109
108
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@peers-app/peers-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.15.0",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/peers-app/peers-sdk.git"
|
|
@@ -21,15 +21,20 @@
|
|
|
21
21
|
},
|
|
22
22
|
"scripts": {
|
|
23
23
|
"clean": "rm -rf dist",
|
|
24
|
-
"
|
|
24
|
+
"lint": "node -e \"console.warn('[peers-sdk] Biome lint temporarily disabled; use npm run lint:biome'); process.exit(0);\"",
|
|
25
|
+
"lint:fix": "node -e \"console.warn('[peers-sdk] Biome lint:fix temporarily disabled; use npm run lint:biome:fix'); process.exit(0);\"",
|
|
26
|
+
"lint:biome": "biome check .",
|
|
27
|
+
"lint:biome:fix": "biome check --write .",
|
|
28
|
+
"build": "npm run clean && tsc",
|
|
25
29
|
"dev": "tsc -w",
|
|
26
30
|
"test": "jest",
|
|
27
|
-
"release:patch": "
|
|
28
|
-
"release:minor": "
|
|
29
|
-
"release:major": "
|
|
30
|
-
"release": "
|
|
31
|
+
"release:patch": "npm run build && npm version patch && git push && git push --tags",
|
|
32
|
+
"release:minor": "npm run build && npm version minor && git push && git push --tags",
|
|
33
|
+
"release:major": "npm run build && npm version major && git push && git push --tags",
|
|
34
|
+
"release": "npm run release:patch"
|
|
31
35
|
},
|
|
32
36
|
"dependencies": {
|
|
37
|
+
"buffer": "^6.0.3",
|
|
33
38
|
"@msgpack/msgpack": "^3.1.2",
|
|
34
39
|
"@noble/hashes": "^1.8.0",
|
|
35
40
|
"ed2curve": "^0.3.0",
|
|
@@ -40,9 +45,10 @@
|
|
|
40
45
|
"moment-timezone": "^0.5.46",
|
|
41
46
|
"tweetnacl": "^1.0.3",
|
|
42
47
|
"tweetnacl-util": "^0.15.1",
|
|
43
|
-
"zod": "3.
|
|
48
|
+
"zod": "3.25.76"
|
|
44
49
|
},
|
|
45
50
|
"devDependencies": {
|
|
51
|
+
"@biomejs/biome": "2.3.11",
|
|
46
52
|
"@types/better-sqlite3": "^7.6.12",
|
|
47
53
|
"@types/ed2curve": "^0.2.4",
|
|
48
54
|
"@types/jest": "^29.5.13",
|
|
@@ -53,6 +59,6 @@
|
|
|
53
59
|
"better-sqlite3": "^11.8.1",
|
|
54
60
|
"jest": "^29.7.0",
|
|
55
61
|
"ts-jest": "^29.2.5",
|
|
56
|
-
"typescript": "^5.
|
|
62
|
+
"typescript": "^5.8.3"
|
|
57
63
|
}
|
|
58
64
|
}
|