@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.
Files changed (210) hide show
  1. package/dist/context/data-context.d.ts +4 -4
  2. package/dist/context/data-context.js +1 -1
  3. package/dist/context/index.d.ts +3 -3
  4. package/dist/context/index.js +4 -0
  5. package/dist/context/user-context-singleton.js +13 -14
  6. package/dist/context/user-context.d.ts +4 -4
  7. package/dist/context/user-context.js +48 -31
  8. package/dist/data/assistants.d.ts +1 -1
  9. package/dist/data/assistants.js +35 -24
  10. package/dist/data/change-tracking.d.ts +8 -8
  11. package/dist/data/change-tracking.js +45 -39
  12. package/dist/data/channels.js +5 -5
  13. package/dist/data/data-locks.d.ts +2 -2
  14. package/dist/data/data-locks.js +21 -23
  15. package/dist/data/data-locks.test.js +73 -75
  16. package/dist/data/device-sync-info.d.ts +1 -1
  17. package/dist/data/device-sync-info.js +4 -4
  18. package/dist/data/devices.d.ts +1 -1
  19. package/dist/data/devices.js +9 -12
  20. package/dist/data/embeddings.js +14 -11
  21. package/dist/data/files/file-read-stream.d.ts +2 -2
  22. package/dist/data/files/file-read-stream.js +23 -14
  23. package/dist/data/files/file-write-stream.d.ts +2 -2
  24. package/dist/data/files/file-write-stream.js +8 -8
  25. package/dist/data/files/file.types.d.ts +2 -2
  26. package/dist/data/files/file.types.js +17 -11
  27. package/dist/data/files/files.d.ts +6 -6
  28. package/dist/data/files/files.js +17 -19
  29. package/dist/data/files/files.test.js +213 -214
  30. package/dist/data/files/index.d.ts +4 -4
  31. package/dist/data/files/index.js +4 -4
  32. package/dist/data/group-member-roles.js +2 -2
  33. package/dist/data/group-members.d.ts +5 -5
  34. package/dist/data/group-members.js +27 -18
  35. package/dist/data/group-members.test.js +73 -73
  36. package/dist/data/group-permissions.d.ts +3 -3
  37. package/dist/data/group-permissions.js +13 -11
  38. package/dist/data/group-share.d.ts +2 -2
  39. package/dist/data/group-share.js +29 -24
  40. package/dist/data/groups.d.ts +4 -4
  41. package/dist/data/groups.js +27 -19
  42. package/dist/data/groups.test.js +44 -44
  43. package/dist/data/index.d.ts +6 -6
  44. package/dist/data/index.js +6 -6
  45. package/dist/data/knowledge/peer-types.js +9 -9
  46. package/dist/data/messages.d.ts +5 -5
  47. package/dist/data/messages.js +43 -30
  48. package/dist/data/orm/client-proxy.data-source.d.ts +4 -4
  49. package/dist/data/orm/client-proxy.data-source.js +10 -12
  50. package/dist/data/orm/cursor.d.ts +1 -1
  51. package/dist/data/orm/cursor.js +2 -2
  52. package/dist/data/orm/cursor.test.js +92 -93
  53. package/dist/data/orm/data-query.d.ts +3 -3
  54. package/dist/data/orm/data-query.js +24 -18
  55. package/dist/data/orm/data-query.mongo.d.ts +1 -1
  56. package/dist/data/orm/data-query.mongo.js +49 -51
  57. package/dist/data/orm/data-query.mongo.test.js +173 -204
  58. package/dist/data/orm/data-query.sqlite.d.ts +1 -1
  59. package/dist/data/orm/data-query.sqlite.js +84 -73
  60. package/dist/data/orm/data-query.sqlite.test.js +164 -176
  61. package/dist/data/orm/data-query.test.js +216 -224
  62. package/dist/data/orm/decorators.js +3 -3
  63. package/dist/data/orm/dependency-injection.test.js +53 -56
  64. package/dist/data/orm/doc.d.ts +4 -4
  65. package/dist/data/orm/doc.js +17 -21
  66. package/dist/data/orm/event-registry.d.ts +1 -1
  67. package/dist/data/orm/event-registry.test.js +16 -16
  68. package/dist/data/orm/factory.d.ts +2 -2
  69. package/dist/data/orm/factory.js +33 -33
  70. package/dist/data/orm/index.d.ts +10 -10
  71. package/dist/data/orm/index.js +10 -10
  72. package/dist/data/orm/multi-cursors.d.ts +1 -1
  73. package/dist/data/orm/multi-cursors.js +6 -6
  74. package/dist/data/orm/multi-cursors.test.js +152 -144
  75. package/dist/data/orm/sql.data-source.d.ts +7 -7
  76. package/dist/data/orm/sql.data-source.js +88 -93
  77. package/dist/data/orm/sql.data-source.test.js +109 -101
  78. package/dist/data/orm/subscribable.data-source.d.ts +4 -4
  79. package/dist/data/orm/subscribable.data-source.js +5 -5
  80. package/dist/data/orm/table-container-events.test.js +34 -26
  81. package/dist/data/orm/table-container.d.ts +6 -6
  82. package/dist/data/orm/table-container.js +33 -21
  83. package/dist/data/orm/table-container.test.js +64 -53
  84. package/dist/data/orm/table-definitions.system.d.ts +3 -3
  85. package/dist/data/orm/table-definitions.system.js +3 -3
  86. package/dist/data/orm/table-definitions.type.d.ts +5 -5
  87. package/dist/data/orm/table-dependencies.d.ts +2 -2
  88. package/dist/data/orm/table.d.ts +5 -5
  89. package/dist/data/orm/table.event-source.test.js +105 -115
  90. package/dist/data/orm/table.js +35 -34
  91. package/dist/data/orm/types.d.ts +3 -3
  92. package/dist/data/orm/types.js +26 -25
  93. package/dist/data/orm/types.test.js +166 -92
  94. package/dist/data/package-permissions.d.ts +1 -1
  95. package/dist/data/package-permissions.js +2 -2
  96. package/dist/data/package-version-permissions.d.ts +1 -1
  97. package/dist/data/package-version-permissions.js +2 -2
  98. package/dist/data/package-versions.d.ts +9 -9
  99. package/dist/data/package-versions.js +47 -33
  100. package/dist/data/packages.d.ts +2 -2
  101. package/dist/data/packages.js +36 -18
  102. package/dist/data/packages.utils.d.ts +2 -2
  103. package/dist/data/packages.utils.js +4 -4
  104. package/dist/data/persistent-vars.d.ts +15 -15
  105. package/dist/data/persistent-vars.js +165 -154
  106. package/dist/data/table-definitions-table.d.ts +5 -5
  107. package/dist/data/table-definitions-table.js +13 -12
  108. package/dist/data/tool-tests.js +6 -6
  109. package/dist/data/tools.js +29 -19
  110. package/dist/data/user-permissions.d.ts +1 -1
  111. package/dist/data/user-permissions.js +5 -5
  112. package/dist/data/user-permissions.test.js +90 -88
  113. package/dist/data/user-trust-levels.js +10 -10
  114. package/dist/data/users.d.ts +4 -4
  115. package/dist/data/users.js +16 -15
  116. package/dist/data/voice-messages.d.ts +2 -2
  117. package/dist/data/voice-messages.js +13 -13
  118. package/dist/data/welcome-modal.pvar.js +3 -1
  119. package/dist/data/workflow-logs.js +26 -18
  120. package/dist/data/workflow-runs.d.ts +6 -6
  121. package/dist/data/workflow-runs.js +70 -44
  122. package/dist/data/workflows.d.ts +2 -2
  123. package/dist/data/workflows.js +7 -9
  124. package/dist/device/binary-peer-connection-v2.d.ts +7 -7
  125. package/dist/device/binary-peer-connection-v2.js +32 -28
  126. package/dist/device/binary-peer-connection-v2.test.js +80 -67
  127. package/dist/device/binary-peer-connection.d.ts +7 -7
  128. package/dist/device/binary-peer-connection.js +29 -28
  129. package/dist/device/binary-peer-connection.test.js +35 -31
  130. package/dist/device/connection.d.ts +5 -5
  131. package/dist/device/connection.js +59 -48
  132. package/dist/device/connection.test.js +74 -68
  133. package/dist/device/device-election.d.ts +2 -2
  134. package/dist/device/device-election.js +25 -20
  135. package/dist/device/device-election.test.js +35 -36
  136. package/dist/device/device.d.ts +2 -2
  137. package/dist/device/device.js +10 -4
  138. package/dist/device/device.test.js +16 -17
  139. package/dist/device/get-trust-level-fn.d.ts +2 -2
  140. package/dist/device/get-trust-level-fn.js +22 -11
  141. package/dist/device/get-trust-level-fn.test.js +58 -58
  142. package/dist/device/socket-io-binary-peer.d.ts +1 -1
  143. package/dist/device/socket-io-binary-peer.js +16 -13
  144. package/dist/device/socket.type.d.ts +2 -2
  145. package/dist/device/streamed-socket.d.ts +2 -2
  146. package/dist/device/streamed-socket.js +8 -8
  147. package/dist/device/streamed-socket.test.js +40 -40
  148. package/dist/device/tx-encoding.test.js +77 -77
  149. package/dist/events.d.ts +1 -1
  150. package/dist/events.js +5 -2
  151. package/dist/group-invite/group-invite.js +110 -19
  152. package/dist/group-invite/group-invite.pvars.d.ts +2 -2
  153. package/dist/group-invite/group-invite.pvars.js +21 -13
  154. package/dist/group-invite/group-invite.types.d.ts +1 -1
  155. package/dist/group-invite/index.d.ts +3 -3
  156. package/dist/group-invite/index.js +1 -1
  157. package/dist/index.d.ts +25 -24
  158. package/dist/index.js +30 -25
  159. package/dist/keys.d.ts +3 -3
  160. package/dist/keys.js +31 -30
  161. package/dist/keys.test.js +69 -61
  162. package/dist/logging/console-logger.d.ts +1 -1
  163. package/dist/logging/console-logger.js +35 -40
  164. package/dist/logging/console-logger.test.js +115 -115
  165. package/dist/logging/console-logs.table.d.ts +3 -3
  166. package/dist/logging/console-logs.table.js +28 -23
  167. package/dist/mentions.js +16 -12
  168. package/dist/observable.d.ts +2 -2
  169. package/dist/observable.js +15 -9
  170. package/dist/observable.test.js +47 -47
  171. package/dist/package-loader/get-require.js +3 -4
  172. package/dist/package-loader/package-loader.d.ts +2 -2
  173. package/dist/package-loader/package-loader.js +52 -34
  174. package/dist/peers-ui/peers-ui.d.ts +2 -2
  175. package/dist/peers-ui/peers-ui.js +2 -4
  176. package/dist/peers-ui/peers-ui.types.d.ts +3 -3
  177. package/dist/peers-ui/peers-ui.types.js +0 -1
  178. package/dist/rpc-types.d.ts +61 -59
  179. package/dist/rpc-types.js +61 -55
  180. package/dist/serial-json.d.ts +1 -1
  181. package/dist/serial-json.js +50 -43
  182. package/dist/serial-json.test.js +22 -22
  183. package/dist/system-ids.js +8 -8
  184. package/dist/tools/index.d.ts +1 -1
  185. package/dist/tools/tools-factory.d.ts +1 -1
  186. package/dist/tools/tools-factory.js +2 -2
  187. package/dist/types/assistant-runner-args.d.ts +3 -3
  188. package/dist/types/peer-device.d.ts +1 -1
  189. package/dist/types/peers-package.d.ts +3 -3
  190. package/dist/types/workflow-logger.d.ts +1 -1
  191. package/dist/types/workflow-run-context.d.ts +4 -4
  192. package/dist/types/workflow.d.ts +4 -4
  193. package/dist/types/workflow.js +27 -14
  194. package/dist/types/zod-types.d.ts +2 -1
  195. package/dist/types/zod-types.js +9 -3
  196. package/dist/user-connect/connection-code.d.ts +1 -1
  197. package/dist/user-connect/connection-code.js +7 -7
  198. package/dist/user-connect/connection-code.test.js +106 -106
  199. package/dist/user-connect/index.d.ts +3 -3
  200. package/dist/user-connect/index.js +1 -1
  201. package/dist/user-connect/user-connect.pvars.js +13 -11
  202. package/dist/user-connect/user-connect.types.d.ts +3 -3
  203. package/dist/users.query.d.ts +2 -2
  204. package/dist/users.query.js +40 -30
  205. package/dist/utils.d.ts +2 -2
  206. package/dist/utils.js +34 -32
  207. package/dist/utils.test.js +12 -8
  208. package/dist/workflow-log-formatter.d.ts +1 -1
  209. package/dist/workflow-log-formatter.js +17 -18
  210. package/package.json +14 -8
@@ -27,72 +27,75 @@ function toJSON(obj) {
27
27
  if (obj === Infinity)
28
28
  return "__INFINITY";
29
29
  if (obj instanceof RegExp)
30
- return ("__REGEXP " + obj.toString());
30
+ return `__REGEXP ${obj.toString()}`;
31
31
  // if(isDate(obj))
32
32
  // return "__DATE " + obj.toISOString();
33
33
  if (_.isDate(obj)) {
34
- return "__DATE " + obj.toISOString();
34
+ return `__DATE ${obj.toISOString()}`;
35
35
  }
36
36
  if (_.isFunction(obj))
37
- return '__FUNCTION ' + obj.toString();
37
+ return `__FUNCTION ${obj.toString()}`;
38
38
  if (_.isElement(obj)) {
39
- return "__HTML " + obj.outerHTML;
39
+ return `__HTML ${obj.outerHTML}`;
40
40
  }
41
- if (typeof window !== 'undefined' && window && obj === window) {
41
+ if (typeof window !== "undefined" && window && obj === window) {
42
42
  return "__WINDOW";
43
43
  }
44
44
  if (_.isError(obj)) {
45
- return "__ERROR " + obj.stack;
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 "__BUFFER " + obj.toString('base64');
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 "__UINT8ARRAY " + Buffer.from(obj).toString('base64');
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
- var iObj = knownObjs.indexOf(obj);
60
+ const iObj = knownObjs.indexOf(obj);
61
61
  if (iObj >= 0) {
62
- var ref = objRefs[iObj];
63
- var nObj = newObjs[iObj];
64
- if (_.isArray(nObj) && (!_.isString(nObj[0]) || !nObj[0].match(/^__this_ref:/)))
65
- nObj.unshift("__this_ref:" + ref);
66
- else if (isObject(nObj) && !nObj.__this_ref)
67
- nObj.__this_ref = ref;
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
- var newRef = "__duplicate_ref_" + (_.isArray(obj) ? "ary_" : "obj_") + refCount;
73
- var nObj = _.isArray(obj) ? [] : {};
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 (var i = 0; i < obj.length; i++)
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
- else
82
- for (var key in obj) {
83
- if (!(obj && obj.hasOwnProperty && obj.hasOwnProperty(key)))
84
- continue;
85
- var value = recurse(obj[key]);
86
- if (key[0] == '$') // escape leading dollar signs
87
- key = '__DOLLAR_' + key.substring(1);
88
- nObj[key] = value;
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, externalReferences) {
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
- var m = obj.split("__REGEXP ")[1].match(/\/(.*)\/(.*)?/);
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-ignore
122
- if (typeof $ !== 'undefined')
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
- let error = new Error();
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), 'base64'));
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), 'base64');
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
- var dup_ref = null;
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(':')[1];
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
- var mObj = _.isArray(obj) ? [] : {};
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 (var key in obj) {
169
- if (!obj.hasOwnProperty(key))
174
+ for (const key of Object.keys(obj)) {
175
+ if (!Object.hasOwn(obj, key))
170
176
  continue;
171
- var value = recurse(obj[key]);
172
- if (key.match(/^__DOLLAR_/))
173
- key = '$' + key.substring(9);
174
- mObj[key] = value;
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
  }
@@ -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('serial-json', () => {
5
- describe('Uint8Array serialization', () => {
6
- it('should serialize and deserialize Uint8Array correctly', () => {
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: 'test',
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('test');
19
+ expect(deserialized.name).toBe("test");
20
20
  expect(deserialized.number).toBe(42);
21
21
  });
22
- it('should serialize and deserialize nested Uint8Array correctly', () => {
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('should work with JSON string serialization', () => {
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('string');
48
- expect(jsonString).toContain('__UINT8ARRAY');
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('Buffer backward compatibility', () => {
55
- it('should serialize and deserialize Buffer correctly', () => {
56
- const originalBuffer = Buffer.from('Hello Buffer');
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('existing functionality', () => {
66
- it('should still handle other special types', () => {
65
+ describe("existing functionality", () => {
66
+ it("should still handle other special types", () => {
67
67
  const testObj = {
68
- date: new Date('2023-01-01T00:00:00.000Z'),
68
+ date: new Date("2023-01-01T00:00:00.000Z"),
69
69
  regex: /test/gi,
70
- error: new Error('test 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('2023-01-01T00:00:00.000Z');
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('/test/gi');
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);
@@ -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 = '000peers0user000000000001';
5
- exports.defaultAssistantId = '000peers0bot00000000shell';
4
+ exports.peersRootUserId = "000peers0user000000000001";
5
+ exports.defaultAssistantId = "000peers0bot00000000shell";
6
6
  // export const defaultAssistantId = '000peers0bot000000000bot1';
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';
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";
@@ -1 +1 @@
1
- export * from './tools-factory';
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,4 +1,4 @@
1
- import type { IChangeRecord, GroupMemberRole } from "../data";
1
+ import type { GroupMemberRole, IChangeRecord } from "../data";
2
2
  import type { DataFilter, IDataQueryParams } from "../data/orm";
3
3
  export interface IPeerDevice {
4
4
  deviceId: string;
@@ -1,10 +1,10 @@
1
1
  import type { IAssistant } from "../data";
2
- import type { IAppNav } from "./app-nav";
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 { ITableDefinition } from "../data/orm/table-definitions.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 { IAssistantRunnerArgs } from "./assistant-runner-args";
2
- import { IToolInstance } from "../data/tools";
3
- import { IWorkflowLogger } from "./workflow-logger";
4
- import { IWorkflowRun } from "../data/workflow-runs";
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;
@@ -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
- createdBy: string;
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>;
@@ -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('The instruction in markdown format'),
8
- onError: zod_1.z.string().optional().describe('The instruction to run if there is an error while running this instruction'),
9
- directCallToolId: zod_types_1.zodPeerId.optional().describe('The tool to call directly with the tool id'),
10
- subWorkflowId: zod_types_1.zodPeerId.optional().describe('The sub workflow to run with the workflow id'),
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('The name of the workflow'),
15
- description: zod_1.z.string().describe('A detailed description of the workflow that can be used to help users and assistants understand what the workflow does'),
16
- defaultAssistantId: zod_types_1.zodPeerId.describe('The default assistant to handle instructions when the workflow is run'),
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().describe([
19
- 'The instructions for the workflow. This should be written in markdown and can include special links to other workflows, tools, etc. via mentions',
20
- 'The instructions should be broken down into discrete steps and should be as clear as possible.',
21
- ].join(' ')).default([]),
22
- createdBy: zod_types_1.zodPeerId.describe('The user who created the workflow'),
23
- createdAt: zod_1.z.date().default(() => new Date()).describe('The date the workflow was created'),
24
- updatedAt: zod_1.z.date().default(() => new Date()).describe('The date the workflow was last updated'),
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 'zod';
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>;
@@ -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",
@@ -7,7 +7,7 @@
7
7
  *
8
8
  * Displayed format: XXXX-YYYY-ZZZZ
9
9
  */
10
- import type { IUserConnectInfo } from './user-connect.types';
10
+ import type { IUserConnectInfo } from "./user-connect.types";
11
11
  export interface IConnectionCode {
12
12
  /** Full 12-character code */
13
13
  code: 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 = '0123456789ABCDEFGHJKMNPQRSTVWXYZ';
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('Decryption failed - invalid secret or corrupted data');
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