@peers-app/peers-sdk 0.1.4

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 (234) hide show
  1. package/README.md +1 -0
  2. package/dist/context/data-context.d.ts +31 -0
  3. package/dist/context/data-context.js +56 -0
  4. package/dist/context/index.d.ts +3 -0
  5. package/dist/context/index.js +19 -0
  6. package/dist/context/user-context-singleton.d.ts +11 -0
  7. package/dist/context/user-context-singleton.js +121 -0
  8. package/dist/context/user-context.d.ts +55 -0
  9. package/dist/context/user-context.js +205 -0
  10. package/dist/data/assistants.d.ts +68 -0
  11. package/dist/data/assistants.js +64 -0
  12. package/dist/data/change-tracking.d.ts +219 -0
  13. package/dist/data/change-tracking.js +119 -0
  14. package/dist/data/channels.d.ts +29 -0
  15. package/dist/data/channels.js +25 -0
  16. package/dist/data/data-locks.d.ts +37 -0
  17. package/dist/data/data-locks.js +180 -0
  18. package/dist/data/data-locks.test.d.ts +1 -0
  19. package/dist/data/data-locks.test.js +456 -0
  20. package/dist/data/device-sync-info.d.ts +19 -0
  21. package/dist/data/device-sync-info.js +24 -0
  22. package/dist/data/devices.d.ts +51 -0
  23. package/dist/data/devices.js +36 -0
  24. package/dist/data/embeddings.d.ts +47 -0
  25. package/dist/data/embeddings.js +36 -0
  26. package/dist/data/files/file-read-stream.d.ts +27 -0
  27. package/dist/data/files/file-read-stream.js +195 -0
  28. package/dist/data/files/file-write-stream.d.ts +20 -0
  29. package/dist/data/files/file-write-stream.js +113 -0
  30. package/dist/data/files/file.types.d.ts +47 -0
  31. package/dist/data/files/file.types.js +55 -0
  32. package/dist/data/files/files.d.ts +28 -0
  33. package/dist/data/files/files.js +127 -0
  34. package/dist/data/files/files.test.d.ts +1 -0
  35. package/dist/data/files/files.test.js +728 -0
  36. package/dist/data/files/index.d.ts +4 -0
  37. package/dist/data/files/index.js +23 -0
  38. package/dist/data/group-member-roles.d.ts +9 -0
  39. package/dist/data/group-member-roles.js +25 -0
  40. package/dist/data/group-members.d.ts +39 -0
  41. package/dist/data/group-members.js +68 -0
  42. package/dist/data/group-members.test.d.ts +1 -0
  43. package/dist/data/group-members.test.js +287 -0
  44. package/dist/data/group-permissions.d.ts +8 -0
  45. package/dist/data/group-permissions.js +73 -0
  46. package/dist/data/group-share.d.ts +50 -0
  47. package/dist/data/group-share.js +196 -0
  48. package/dist/data/groups.d.ts +50 -0
  49. package/dist/data/groups.js +73 -0
  50. package/dist/data/groups.test.d.ts +1 -0
  51. package/dist/data/groups.test.js +153 -0
  52. package/dist/data/index.d.ts +31 -0
  53. package/dist/data/index.js +47 -0
  54. package/dist/data/knowledge/knowledge-frames.d.ts +34 -0
  55. package/dist/data/knowledge/knowledge-frames.js +34 -0
  56. package/dist/data/knowledge/knowledge-links.d.ts +30 -0
  57. package/dist/data/knowledge/knowledge-links.js +25 -0
  58. package/dist/data/knowledge/knowledge-values.d.ts +35 -0
  59. package/dist/data/knowledge/knowledge-values.js +35 -0
  60. package/dist/data/knowledge/peer-types.d.ts +112 -0
  61. package/dist/data/knowledge/peer-types.js +27 -0
  62. package/dist/data/knowledge/predicates.d.ts +34 -0
  63. package/dist/data/knowledge/predicates.js +27 -0
  64. package/dist/data/messages.d.ts +57 -0
  65. package/dist/data/messages.js +97 -0
  66. package/dist/data/orm/client-proxy.data-source.d.ts +27 -0
  67. package/dist/data/orm/client-proxy.data-source.js +65 -0
  68. package/dist/data/orm/cursor.d.ts +25 -0
  69. package/dist/data/orm/cursor.js +47 -0
  70. package/dist/data/orm/cursor.test.d.ts +1 -0
  71. package/dist/data/orm/cursor.test.js +315 -0
  72. package/dist/data/orm/data-query.d.ts +96 -0
  73. package/dist/data/orm/data-query.js +208 -0
  74. package/dist/data/orm/data-query.mongo.d.ts +17 -0
  75. package/dist/data/orm/data-query.mongo.js +267 -0
  76. package/dist/data/orm/data-query.mongo.test.d.ts +1 -0
  77. package/dist/data/orm/data-query.mongo.test.js +398 -0
  78. package/dist/data/orm/data-query.sqlite.d.ts +14 -0
  79. package/dist/data/orm/data-query.sqlite.js +297 -0
  80. package/dist/data/orm/data-query.sqlite.test.d.ts +1 -0
  81. package/dist/data/orm/data-query.sqlite.test.js +377 -0
  82. package/dist/data/orm/data-query.test.d.ts +1 -0
  83. package/dist/data/orm/data-query.test.js +553 -0
  84. package/dist/data/orm/decorators.d.ts +6 -0
  85. package/dist/data/orm/decorators.js +21 -0
  86. package/dist/data/orm/dependency-injection.test.d.ts +1 -0
  87. package/dist/data/orm/dependency-injection.test.js +171 -0
  88. package/dist/data/orm/doc.d.ts +26 -0
  89. package/dist/data/orm/doc.js +124 -0
  90. package/dist/data/orm/event-registry.d.ts +24 -0
  91. package/dist/data/orm/event-registry.js +40 -0
  92. package/dist/data/orm/event-registry.test.d.ts +1 -0
  93. package/dist/data/orm/event-registry.test.js +44 -0
  94. package/dist/data/orm/factory.d.ts +8 -0
  95. package/dist/data/orm/factory.js +147 -0
  96. package/dist/data/orm/index.d.ts +16 -0
  97. package/dist/data/orm/index.js +32 -0
  98. package/dist/data/orm/multi-cursors.d.ts +11 -0
  99. package/dist/data/orm/multi-cursors.js +146 -0
  100. package/dist/data/orm/multi-cursors.test.d.ts +1 -0
  101. package/dist/data/orm/multi-cursors.test.js +455 -0
  102. package/dist/data/orm/sql-db.d.ts +6 -0
  103. package/dist/data/orm/sql-db.js +2 -0
  104. package/dist/data/orm/sql.data-source.d.ts +38 -0
  105. package/dist/data/orm/sql.data-source.js +379 -0
  106. package/dist/data/orm/sql.data-source.test.d.ts +1 -0
  107. package/dist/data/orm/sql.data-source.test.js +406 -0
  108. package/dist/data/orm/subscribable.data-source.d.ts +25 -0
  109. package/dist/data/orm/subscribable.data-source.js +72 -0
  110. package/dist/data/orm/table-container-events.test.d.ts +1 -0
  111. package/dist/data/orm/table-container-events.test.js +93 -0
  112. package/dist/data/orm/table-container.d.ts +39 -0
  113. package/dist/data/orm/table-container.js +96 -0
  114. package/dist/data/orm/table-definitions.system.d.ts +9 -0
  115. package/dist/data/orm/table-definitions.system.js +29 -0
  116. package/dist/data/orm/table-definitions.type.d.ts +19 -0
  117. package/dist/data/orm/table-definitions.type.js +2 -0
  118. package/dist/data/orm/table-dependencies.d.ts +32 -0
  119. package/dist/data/orm/table-dependencies.js +2 -0
  120. package/dist/data/orm/table.d.ts +42 -0
  121. package/dist/data/orm/table.event-source.test.d.ts +1 -0
  122. package/dist/data/orm/table.event-source.test.js +341 -0
  123. package/dist/data/orm/table.js +244 -0
  124. package/dist/data/orm/types.d.ts +20 -0
  125. package/dist/data/orm/types.js +115 -0
  126. package/dist/data/orm/types.test.d.ts +1 -0
  127. package/dist/data/orm/types.test.js +71 -0
  128. package/dist/data/package-permissions.d.ts +7 -0
  129. package/dist/data/package-permissions.js +18 -0
  130. package/dist/data/packages.d.ts +92 -0
  131. package/dist/data/packages.js +90 -0
  132. package/dist/data/peer-events/peer-event-handlers.d.ts +21 -0
  133. package/dist/data/peer-events/peer-event-handlers.js +28 -0
  134. package/dist/data/peer-events/peer-event-types.d.ts +119 -0
  135. package/dist/data/peer-events/peer-event-types.js +29 -0
  136. package/dist/data/peer-events/peer-events.d.ts +41 -0
  137. package/dist/data/peer-events/peer-events.js +102 -0
  138. package/dist/data/persistent-vars.d.ts +87 -0
  139. package/dist/data/persistent-vars.js +230 -0
  140. package/dist/data/tool-tests.d.ts +37 -0
  141. package/dist/data/tool-tests.js +27 -0
  142. package/dist/data/tools.d.ts +358 -0
  143. package/dist/data/tools.js +48 -0
  144. package/dist/data/user-permissions.d.ts +15 -0
  145. package/dist/data/user-permissions.js +39 -0
  146. package/dist/data/user-permissions.test.d.ts +1 -0
  147. package/dist/data/user-permissions.test.js +252 -0
  148. package/dist/data/users.d.ts +38 -0
  149. package/dist/data/users.js +73 -0
  150. package/dist/data/workflow-logs.d.ts +106 -0
  151. package/dist/data/workflow-logs.js +67 -0
  152. package/dist/data/workflow-runs.d.ts +103 -0
  153. package/dist/data/workflow-runs.js +313 -0
  154. package/dist/data/workflows.d.ts +16 -0
  155. package/dist/data/workflows.js +21 -0
  156. package/dist/device/connection.d.ts +41 -0
  157. package/dist/device/connection.js +249 -0
  158. package/dist/device/connection.test.d.ts +1 -0
  159. package/dist/device/connection.test.js +292 -0
  160. package/dist/device/device-election.d.ts +36 -0
  161. package/dist/device/device-election.js +137 -0
  162. package/dist/device/device.d.ts +22 -0
  163. package/dist/device/device.js +110 -0
  164. package/dist/device/device.test.d.ts +1 -0
  165. package/dist/device/device.test.js +203 -0
  166. package/dist/device/get-trust-level.d.ts +3 -0
  167. package/dist/device/get-trust-level.js +87 -0
  168. package/dist/device/socket.type.d.ts +20 -0
  169. package/dist/device/socket.type.js +15 -0
  170. package/dist/device/streamed-socket.d.ts +27 -0
  171. package/dist/device/streamed-socket.js +154 -0
  172. package/dist/device/streamed-socket.test.d.ts +1 -0
  173. package/dist/device/streamed-socket.test.js +44 -0
  174. package/dist/events.d.ts +35 -0
  175. package/dist/events.js +128 -0
  176. package/dist/index.d.ts +33 -0
  177. package/dist/index.js +50 -0
  178. package/dist/keys.d.ts +51 -0
  179. package/dist/keys.js +234 -0
  180. package/dist/keys.test.d.ts +1 -0
  181. package/dist/keys.test.js +215 -0
  182. package/dist/mentions.d.ts +9 -0
  183. package/dist/mentions.js +46 -0
  184. package/dist/observable.d.ts +19 -0
  185. package/dist/observable.js +112 -0
  186. package/dist/observable.test.d.ts +1 -0
  187. package/dist/observable.test.js +183 -0
  188. package/dist/package-loader/get-require.d.ts +10 -0
  189. package/dist/package-loader/get-require.js +31 -0
  190. package/dist/package-loader/index.d.ts +1 -0
  191. package/dist/package-loader/index.js +17 -0
  192. package/dist/package-loader/package-loader.d.ts +16 -0
  193. package/dist/package-loader/package-loader.js +102 -0
  194. package/dist/peers-ui/peers-ui.d.ts +15 -0
  195. package/dist/peers-ui/peers-ui.js +23 -0
  196. package/dist/peers-ui/peers-ui.types.d.ts +35 -0
  197. package/dist/peers-ui/peers-ui.types.js +3 -0
  198. package/dist/rpc-types.d.ts +45 -0
  199. package/dist/rpc-types.js +47 -0
  200. package/dist/serial-json.d.ts +5 -0
  201. package/dist/serial-json.js +186 -0
  202. package/dist/serial-json.test.d.ts +1 -0
  203. package/dist/serial-json.test.js +86 -0
  204. package/dist/system-ids.d.ts +6 -0
  205. package/dist/system-ids.js +10 -0
  206. package/dist/tools/index.d.ts +1 -0
  207. package/dist/tools/index.js +17 -0
  208. package/dist/tools/tools-factory.d.ts +5 -0
  209. package/dist/tools/tools-factory.js +34 -0
  210. package/dist/types/app-nav.d.ts +18 -0
  211. package/dist/types/app-nav.js +10 -0
  212. package/dist/types/assistant-runner-args.d.ts +9 -0
  213. package/dist/types/assistant-runner-args.js +2 -0
  214. package/dist/types/field-type.d.ts +37 -0
  215. package/dist/types/field-type.js +26 -0
  216. package/dist/types/peer-device.d.ts +40 -0
  217. package/dist/types/peer-device.js +14 -0
  218. package/dist/types/peers-package.d.ts +23 -0
  219. package/dist/types/peers-package.js +2 -0
  220. package/dist/types/workflow-logger.d.ts +2 -0
  221. package/dist/types/workflow-logger.js +2 -0
  222. package/dist/types/workflow-run-context.d.ts +12 -0
  223. package/dist/types/workflow-run-context.js +2 -0
  224. package/dist/types/workflow.d.ts +72 -0
  225. package/dist/types/workflow.js +24 -0
  226. package/dist/types/zod-types.d.ts +7 -0
  227. package/dist/types/zod-types.js +12 -0
  228. package/dist/users.query.d.ts +13 -0
  229. package/dist/users.query.js +134 -0
  230. package/dist/utils.d.ts +39 -0
  231. package/dist/utils.js +240 -0
  232. package/dist/utils.test.d.ts +1 -0
  233. package/dist/utils.test.js +140 -0
  234. package/package.json +50 -0
@@ -0,0 +1,102 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PackageLoader = void 0;
4
+ exports.setDefaultRequire = setDefaultRequire;
5
+ const tools_1 = require("../tools");
6
+ const files_1 = require("../data/files");
7
+ const packages_1 = require("../data/packages");
8
+ const tools_2 = require("../data/tools");
9
+ class PackageLoader {
10
+ dataContext;
11
+ packageInstances = {};
12
+ require = undefined;
13
+ constructor(dataContext) {
14
+ this.dataContext = dataContext;
15
+ }
16
+ async loadAllPackages(opts) {
17
+ const packages = await (0, packages_1.Packages)(this.dataContext).list();
18
+ await Promise.all(packages.map(pkg => {
19
+ if (pkg.disabled) {
20
+ return;
21
+ }
22
+ return this.loadPackage(pkg, opts);
23
+ }));
24
+ }
25
+ async loadPackage(pkg, opts) {
26
+ if (this.packageInstances[pkg.packageId] && !opts?.force) {
27
+ return this.packageInstances[pkg.packageId];
28
+ }
29
+ // console.debug(`Loading package bundle for ${pkg.name} (${pkg.packageId})`);
30
+ try {
31
+ let bundleCode = '';
32
+ if (pkg.packageBundleFileId) {
33
+ const filesTable = (0, files_1.Files)(this.dataContext);
34
+ const bundleBuffer = await filesTable.getFile(pkg.packageBundleFileId);
35
+ if (bundleBuffer) {
36
+ bundleCode = Buffer.from(bundleBuffer).toString('utf8');
37
+ }
38
+ else {
39
+ console.warn(`Package bundle file not found for ${pkg.name} (fileId: ${pkg.packageBundleFileId})`);
40
+ return null;
41
+ }
42
+ }
43
+ else {
44
+ console.warn(`Package ${pkg.name} does not have a bundle file defined.`);
45
+ }
46
+ // Create a safe execution context
47
+ const moduleExports = {};
48
+ const module = { exports: moduleExports };
49
+ // Create a custom require function that provides necessary dependencies
50
+ const customRequire = (moduleId) => {
51
+ // const require = getRequire(this.require);
52
+ const _require = this.require ?? defaultRequire ?? typeof require === 'function' ? require : undefined;
53
+ if (!_require) {
54
+ throw new Error('You must set the `require` function in package loader before loading a package');
55
+ }
56
+ // console.debug(`Custom require for module: ${moduleId}`);
57
+ switch (moduleId) {
58
+ case 'peers-sdk':
59
+ case 'PeersSDK':
60
+ // Import all peers-sdk exports
61
+ // return _require('peers-sdk');
62
+ return _require('../index');
63
+ case 'zod':
64
+ return _require('zod');
65
+ default:
66
+ // For other modules, use the standard require
67
+ console.warn(`Package ${pkg.name} is requiring a module ${moduleId}, which is not provided by the package loader.`);
68
+ return _require(moduleId);
69
+ }
70
+ };
71
+ // Evaluate the bundle using Function (safer than eval)
72
+ const bundleFunction = new Function('module', 'exports', 'require', bundleCode);
73
+ bundleFunction(module, moduleExports, customRequire);
74
+ // Extract the package instance from the bundle exports
75
+ const bundleExports = module.exports;
76
+ const packageInstance = bundleExports?.exports || bundleExports?.package || bundleExports?.default || bundleExports;
77
+ this.packageInstances[pkg.packageId] = packageInstance;
78
+ if (packageInstance && typeof packageInstance === 'object') {
79
+ // Register tools centrally using the tools-factory
80
+ packageInstance.toolInstances?.forEach((toolInstance) => {
81
+ // Note that this isn't unregistering prior tools when force loading
82
+ (0, tools_1.registerTool)(toolInstance);
83
+ (0, tools_2.Tools)(this.dataContext).save(toolInstance.tool);
84
+ });
85
+ packageInstance.tableDefinitions?.forEach((tableDefinition) => {
86
+ this.dataContext.tableContainer.registerTableDefinition(tableDefinition, { overwrite: true });
87
+ });
88
+ return packageInstance;
89
+ }
90
+ return null;
91
+ }
92
+ catch (err) {
93
+ console.debug(`Could not load package bundle for ${pkg.name}`, err);
94
+ return null;
95
+ }
96
+ }
97
+ }
98
+ exports.PackageLoader = PackageLoader;
99
+ let defaultRequire = undefined;
100
+ function setDefaultRequire(require) {
101
+ defaultRequire = require;
102
+ }
@@ -0,0 +1,15 @@
1
+ import type { IPeersUIRoute } from "./peers-ui.types";
2
+ import type { ZodObject, ZodArray, ZodAny, ZodTypeAny } from "zod";
3
+ export interface IPeersUI {
4
+ peersUIId: string;
5
+ propsSchema: ZodObject<any> | ZodArray<any> | ZodAny | ZodTypeAny;
6
+ content: any;
7
+ }
8
+ export declare const PeersUI: (props: {
9
+ peersUIId?: string;
10
+ uiEditMode?: IPeersUIRoute["uiEditMode"];
11
+ uiCategory?: IPeersUIRoute["uiCategory"];
12
+ uiSubcategory?: IPeersUIRoute["uiSubcategory"];
13
+ children?: React.ReactNode;
14
+ props?: Record<string, any>;
15
+ }) => (React.ReactNode | undefined);
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PeersUI = void 0;
4
+ const PeersUI = (props
5
+ // @ts-ignore
6
+ ) => {
7
+ if (typeof window === 'undefined') {
8
+ throw new Error("PeersUI can only be used in the browser");
9
+ }
10
+ const _window = window;
11
+ let ui;
12
+ if (props.peersUIId) {
13
+ ui = _window.UILoader(props);
14
+ }
15
+ else {
16
+ ui = _window.UIRouter(props);
17
+ }
18
+ if (ui) {
19
+ return ui;
20
+ }
21
+ return props.children;
22
+ };
23
+ exports.PeersUI = PeersUI;
@@ -0,0 +1,35 @@
1
+ import type { ZodObject, ZodAny, ZodArray, ZodTypeAny } from "zod";
2
+ export type UICategory = 'field' | 'list' | 'details' | 'screen' | 'list-item' | 'other' | '*';
3
+ export type UIEditMode = 'view' | 'edit' | 'create' | '*';
4
+ export type UIContextPropsSchema = ZodObject<any> | ZodAny | ZodArray<any> | ZodTypeAny;
5
+ export interface UIContext {
6
+ /** The current screen path */
7
+ path?: string;
8
+ /** If this is specified, this route will only be considered when the caller specifies this value */
9
+ uiEditMode?: UIEditMode;
10
+ /** If this is specified, this route will only be considered when the caller specifies this value */
11
+ uiCategory?: UICategory;
12
+ /** If this is specified, this route will only be considered when the caller specifies this value */
13
+ uiSubcategory?: string;
14
+ propsSchema?: UIContextPropsSchema;
15
+ }
16
+ export interface IPeersUIRoute extends UIContext {
17
+ /**
18
+ * required to identify which package ui bundle contains the component
19
+ */
20
+ packageId: string;
21
+ /**
22
+ * required to identify which react component to render
23
+ */
24
+ peersUIId: string;
25
+ /**
26
+ * This should return true to indicate that this route should be used for the given data
27
+ */
28
+ isMatch?: (props: Record<string, any>, context: {
29
+ path: string;
30
+ } & UIContext) => boolean;
31
+ /**
32
+ * higher take precedent
33
+ */
34
+ priority?: number;
35
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ ;
@@ -0,0 +1,45 @@
1
+ import type { DataFilter, IDataQueryParams, ISaveOptions } from "./data/orm";
2
+ export interface IEventData<T = any> {
3
+ name: string;
4
+ data: T;
5
+ }
6
+ export declare const rpcServerCalls: {
7
+ ping: (msg: string) => Promise<string>;
8
+ openLinkInBrowser: ((url: string) => Promise<void>);
9
+ openPath: ((path: string) => Promise<void>);
10
+ openPackage: ((path: string) => Promise<void>);
11
+ createLocalPackage: ((packageName: string, packageLocation: string) => Promise<string>);
12
+ addRemotePackage: ((remoteRepo: string) => Promise<string>);
13
+ linkRemoteRepo: ((packageId: string) => Promise<void>);
14
+ installOrUpdatePackage: ((packageId: string) => Promise<void>);
15
+ updateUserSettings: ((settings: {
16
+ id: string;
17
+ name: string;
18
+ value: any;
19
+ }) => Promise<void>);
20
+ setSecretKey: ((secretKey: string) => Promise<void>);
21
+ encryptData: ((value: string, groupId?: string) => Promise<string>);
22
+ tableGet: (dataContextId: string, tableName: string, id: string, opts?: {
23
+ useCache?: boolean;
24
+ cacheTtlMs?: number;
25
+ }) => Promise<any>;
26
+ tableList: ((dataContextId: string, tableName: string, filter?: DataFilter<any>, opts?: IDataQueryParams<any>) => Promise<any[]>);
27
+ tableCount: ((dataContextId: string, tableName: string, filter?: DataFilter<any>) => Promise<number>);
28
+ tableSave: ((dataContextId: string, tableName: string, record: any, opts?: ISaveOptions) => Promise<any>);
29
+ tableInsert: ((dataContextId: string, tableName: string, record: any) => Promise<any>);
30
+ tableUpdate: ((dataContextId: string, tableName: string, record: any) => Promise<any>);
31
+ tableDelete: ((dataContextId: string, tableName: string, recordOrId: any) => Promise<any>);
32
+ tableMethodCall: ((dataContextId: string, tableName: string, methodName: string, ...args: any[]) => Promise<any>);
33
+ getFileContents: ((fileId: string, encoding?: BufferEncoding) => Promise<string>);
34
+ resetAllDeviceSyncInfo: (() => Promise<void>);
35
+ importGroupShare: ((groupShareJson: string) => Promise<string>);
36
+ };
37
+ export declare const rpcClientCalls: {
38
+ ping: (msg: string) => Promise<string>;
39
+ emitEvent: ((event: IEventData) => Promise<boolean>);
40
+ setClientPath: ((url: string) => Promise<void>);
41
+ openThread: ((threadId: string) => Promise<void>);
42
+ };
43
+ export type RpcServerNames = keyof typeof rpcServerCalls;
44
+ export type RpcClientNames = keyof typeof rpcClientCalls;
45
+ export declare const isClient: boolean;
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isClient = exports.rpcClientCalls = exports.rpcServerCalls = void 0;
4
+ function rpcStub(rpcName) {
5
+ return async () => {
6
+ console.warn(rpcName + ': rpc fn not set. This means that an RPC call is happening before the RPC function has been set. This is either a race condition or the RPC handler was never set.');
7
+ };
8
+ }
9
+ exports.rpcServerCalls = {
10
+ ping: async (msg) => `pong: ${msg}`,
11
+ openLinkInBrowser: rpcStub('openLinkInBrowser'),
12
+ openPath: rpcStub('openPath'),
13
+ openPackage: rpcStub('OpenPackage'),
14
+ createLocalPackage: rpcStub('createLocalPackage'),
15
+ addRemotePackage: rpcStub('addRemotePackage'),
16
+ linkRemoteRepo: rpcStub('linkRemoteRepo'),
17
+ installOrUpdatePackage: rpcStub('installOrUpdatePackage'),
18
+ updateUserSettings: rpcStub('updateUserSettings'),
19
+ setSecretKey: rpcStub('setSecretKey'),
20
+ encryptData: rpcStub('encryptData'),
21
+ tableGet: rpcStub('tableGet'),
22
+ tableList: rpcStub('tableList'),
23
+ tableCount: rpcStub('tableCount'),
24
+ tableSave: rpcStub('tableSave'),
25
+ tableInsert: rpcStub('tableInsert'),
26
+ tableUpdate: rpcStub('tableUpdate'),
27
+ tableDelete: rpcStub('tableDelete'),
28
+ tableMethodCall: rpcStub('tableMethodCall'),
29
+ // TODO lock this down so not all code can get any file contents
30
+ getFileContents: rpcStub('getFileContents'),
31
+ resetAllDeviceSyncInfo: rpcStub('resetAllDeviceSyncInfo'),
32
+ importGroupShare: rpcStub('importGroupShare'),
33
+ // TODO try to get rid of this and rely on the client-side table and server-side table individually emitting events
34
+ // emitEvent: _na as ((event: IEventData) => Promise<boolean>),
35
+ };
36
+ exports.rpcClientCalls = {
37
+ ping: async (msg) => `pong: ${msg}`,
38
+ emitEvent: rpcStub('emitEvent'),
39
+ setClientPath: rpcStub('setClientPath'),
40
+ openThread: rpcStub('openThread'),
41
+ };
42
+ exports.isClient = typeof window !== 'undefined';
43
+ if (exports.isClient) {
44
+ // @ts-ignore
45
+ const _window = window;
46
+ _window['rpc'] = exports.rpcServerCalls;
47
+ }
@@ -0,0 +1,5 @@
1
+ export declare function isObject(x: any): x is Record<string, any>;
2
+ export declare function toJSON(obj: any): any;
3
+ export declare function fromJSON(obj: any, externalReferences?: any): any;
4
+ export declare function toJSONString(obj: any): string;
5
+ export declare function fromJSONString(str: string): any;
@@ -0,0 +1,186 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isObject = isObject;
4
+ exports.toJSON = toJSON;
5
+ exports.fromJSON = fromJSON;
6
+ exports.toJSONString = toJSONString;
7
+ exports.fromJSONString = fromJSONString;
8
+ const _ = require("lodash");
9
+ function isObject(x) {
10
+ return _.isObject(x) && !_.isArray(x) && !_.isDate(x) && x !== null;
11
+ }
12
+ function toJSON(obj) {
13
+ if (!_.isObject(obj)) {
14
+ return obj;
15
+ }
16
+ //console.log('toJSON');
17
+ const knownObjs = [];
18
+ const objRefs = [];
19
+ const newObjs = [];
20
+ let refCount = 0;
21
+ function recurse(obj) {
22
+ // stringify values
23
+ if (Number.isNaN(obj))
24
+ return "__NAN";
25
+ if (obj === undefined)
26
+ return "__UNDEFINED";
27
+ if (obj === Infinity)
28
+ return "__INFINITY";
29
+ if (obj instanceof RegExp)
30
+ return ("__REGEXP " + obj.toString());
31
+ // if(isDate(obj))
32
+ // return "__DATE " + obj.toISOString();
33
+ if (_.isDate(obj)) {
34
+ return "__DATE " + obj.toISOString();
35
+ }
36
+ if (_.isFunction(obj))
37
+ return '__FUNCTION ' + obj.toString();
38
+ if (_.isElement(obj)) {
39
+ return "__HTML " + obj.outerHTML;
40
+ }
41
+ if (typeof window !== 'undefined' && window && obj === window) {
42
+ return "__WINDOW";
43
+ }
44
+ if (_.isError(obj)) {
45
+ return "__ERROR " + obj.stack;
46
+ }
47
+ if (Buffer.isBuffer(obj)) {
48
+ // Convert Buffer to base64 string for JSON serialization (backward compatibility)
49
+ return "__BUFFER " + obj.toString('base64');
50
+ }
51
+ if (obj instanceof Uint8Array) {
52
+ // Convert Uint8Array to base64 string for JSON serialization
53
+ return "__UINT8ARRAY " + Buffer.from(obj).toString('base64');
54
+ }
55
+ // non-objects can just be returned at this point
56
+ if (!(isObject(obj) || _.isArray(obj))) {
57
+ return obj;
58
+ }
59
+ // if we've found a duplicate reference, deal with it
60
+ var iObj = knownObjs.indexOf(obj);
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;
68
+ return ref;
69
+ }
70
+ // capture references in case we need them later
71
+ refCount++;
72
+ var newRef = "__duplicate_ref_" + (_.isArray(obj) ? "ary_" : "obj_") + refCount;
73
+ var nObj = _.isArray(obj) ? [] : {};
74
+ knownObjs.push(obj);
75
+ objRefs.push(newRef);
76
+ newObjs.push(nObj);
77
+ // recurse on properties
78
+ if (_.isArray(obj))
79
+ for (var i = 0; i < obj.length; i++)
80
+ 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;
89
+ }
90
+ return nObj;
91
+ }
92
+ obj = recurse(obj);
93
+ return obj;
94
+ }
95
+ function fromJSON(obj, externalReferences) {
96
+ var dup_refs = {};
97
+ function recurse(obj) {
98
+ if (_.isString(obj)) {
99
+ // restore values
100
+ if (obj === "__UNDEFINED")
101
+ return undefined;
102
+ if (obj === "__NAN")
103
+ return NaN;
104
+ if (obj === "__INFINITY")
105
+ return Infinity;
106
+ if (obj.match(/^__REGEXP /)) {
107
+ var m = obj.split("__REGEXP ")[1].match(/\/(.*)\/(.*)?/);
108
+ return new RegExp(m[1], m[2] || "");
109
+ }
110
+ if (obj.startsWith("__DATE ")) {
111
+ return new Date(obj.substring(7));
112
+ }
113
+ // // assuming strings like this should be dates
114
+ // if (obj.match(/^\d{4}-\d{2}-\d{2}T\d{2}\:\d{2}\:\d{2}\.\d{3}Z$/)) {
115
+ // return new Date(obj)
116
+ // }
117
+ // if (obj.match(/^__FUNCTION /)) {
118
+ // return js(obj.substring(11), externalReferences);
119
+ // }
120
+ if (obj.match(/^__HTML /)) {
121
+ //@ts-ignore
122
+ if (typeof $ !== 'undefined')
123
+ return $(obj.substring(7))[0];
124
+ else
125
+ return obj;
126
+ }
127
+ if (obj.startsWith("__ERROR ")) {
128
+ let error = new Error();
129
+ error.stack = obj.substring(8);
130
+ return error;
131
+ }
132
+ if (obj === "__WINDOW") {
133
+ return window;
134
+ }
135
+ if (obj.startsWith("__UINT8ARRAY ")) {
136
+ // Convert base64 string back to Uint8Array
137
+ return new Uint8Array(Buffer.from(obj.substring(13), 'base64'));
138
+ }
139
+ if (obj.startsWith("__BUFFER ")) {
140
+ // Convert base64 string back to Buffer (backward compatibility)
141
+ return Buffer.from(obj.substring(9), 'base64');
142
+ }
143
+ // deal with duplicate refs
144
+ if (obj.match(/^__duplicate_ref_/)) {
145
+ if (!dup_refs[obj])
146
+ dup_refs[obj] = obj.match(/_obj_/) ? {} : [];
147
+ return dup_refs[obj];
148
+ }
149
+ }
150
+ if (!(isObject(obj) || _.isArray(obj)))
151
+ return obj;
152
+ // deal with objects that have duplicate refs
153
+ var dup_ref = null;
154
+ obj = _.clone(obj); // don't mess up the original JSON object
155
+ if (_.isArray(obj) && _.isString(obj[0]) && obj[0].match(/^__this_ref:/))
156
+ dup_ref = obj.shift().split(':')[1];
157
+ else if (obj.__this_ref) {
158
+ dup_ref = obj.__this_ref;
159
+ delete obj.__this_ref;
160
+ }
161
+ var mObj = _.isArray(obj) ? [] : {};
162
+ if (dup_ref)
163
+ if (!dup_refs[dup_ref])
164
+ dup_refs[dup_ref] = mObj;
165
+ else
166
+ mObj = dup_refs[dup_ref];
167
+ // restore keys and recurse on objects
168
+ for (var key in obj) {
169
+ if (!obj.hasOwnProperty(key))
170
+ continue;
171
+ var value = recurse(obj[key]);
172
+ if (key.match(/^__DOLLAR_/))
173
+ key = '$' + key.substring(9);
174
+ mObj[key] = value;
175
+ }
176
+ return mObj;
177
+ }
178
+ obj = recurse(obj);
179
+ return obj;
180
+ }
181
+ function toJSONString(obj) {
182
+ return JSON.stringify(toJSON(obj));
183
+ }
184
+ function fromJSONString(str) {
185
+ return fromJSON(JSON.parse(str));
186
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,86 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const serial_json_1 = require("./serial-json");
4
+ describe('serial-json', () => {
5
+ describe('Uint8Array serialization', () => {
6
+ it('should serialize and deserialize Uint8Array correctly', () => {
7
+ const originalData = new Uint8Array([72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100]); // "Hello World"
8
+ const testObj = {
9
+ data: originalData,
10
+ name: 'test',
11
+ number: 42
12
+ };
13
+ // Test toJSON/fromJSON
14
+ const serialized = (0, serial_json_1.toJSON)(testObj);
15
+ expect(serialized.data).toMatch(/^__UINT8ARRAY /);
16
+ const deserialized = (0, serial_json_1.fromJSON)(serialized);
17
+ expect(deserialized.data).toBeInstanceOf(Uint8Array);
18
+ expect(deserialized.data).toEqual(originalData);
19
+ expect(deserialized.name).toBe('test');
20
+ expect(deserialized.number).toBe(42);
21
+ });
22
+ it('should serialize and deserialize nested Uint8Array correctly', () => {
23
+ const data1 = new Uint8Array([1, 2, 3]);
24
+ const data2 = new Uint8Array([4, 5, 6]);
25
+ const testObj = {
26
+ chunks: [data1, data2],
27
+ metadata: {
28
+ firstChunk: data1,
29
+ totalSize: 6
30
+ }
31
+ };
32
+ const serialized = (0, serial_json_1.toJSON)(testObj);
33
+ const deserialized = (0, serial_json_1.fromJSON)(serialized);
34
+ expect(deserialized.chunks).toHaveLength(2);
35
+ expect(deserialized.chunks[0]).toBeInstanceOf(Uint8Array);
36
+ expect(deserialized.chunks[1]).toBeInstanceOf(Uint8Array);
37
+ expect(deserialized.chunks[0]).toEqual(data1);
38
+ expect(deserialized.chunks[1]).toEqual(data2);
39
+ expect(deserialized.metadata.firstChunk).toBeInstanceOf(Uint8Array);
40
+ expect(deserialized.metadata.firstChunk).toEqual(data1);
41
+ expect(deserialized.metadata.totalSize).toBe(6);
42
+ });
43
+ it('should work with JSON string serialization', () => {
44
+ const originalData = new Uint8Array([255, 0, 128, 64]);
45
+ const testObj = { binaryData: originalData };
46
+ const jsonString = (0, serial_json_1.toJSONString)(testObj);
47
+ expect(typeof jsonString).toBe('string');
48
+ expect(jsonString).toContain('__UINT8ARRAY');
49
+ const deserialized = (0, serial_json_1.fromJSONString)(jsonString);
50
+ expect(deserialized.binaryData).toBeInstanceOf(Uint8Array);
51
+ expect(deserialized.binaryData).toEqual(originalData);
52
+ });
53
+ });
54
+ describe('Buffer backward compatibility', () => {
55
+ it('should serialize and deserialize Buffer correctly', () => {
56
+ const originalBuffer = Buffer.from('Hello Buffer');
57
+ const testObj = { bufferData: originalBuffer };
58
+ const serialized = (0, serial_json_1.toJSON)(testObj);
59
+ expect(serialized.bufferData).toMatch(/^__BUFFER /);
60
+ const deserialized = (0, serial_json_1.fromJSON)(serialized);
61
+ expect(Buffer.isBuffer(deserialized.bufferData)).toBe(true);
62
+ expect(deserialized.bufferData).toEqual(originalBuffer);
63
+ });
64
+ });
65
+ describe('existing functionality', () => {
66
+ it('should still handle other special types', () => {
67
+ const testObj = {
68
+ date: new Date('2023-01-01T00:00:00.000Z'),
69
+ regex: /test/gi,
70
+ error: new Error('test error'),
71
+ nan: NaN,
72
+ infinity: Infinity,
73
+ undef: undefined
74
+ };
75
+ const deserialized = (0, serial_json_1.fromJSON)((0, serial_json_1.toJSON)(testObj));
76
+ expect(deserialized.date).toBeInstanceOf(Date);
77
+ expect(deserialized.date.toISOString()).toBe('2023-01-01T00:00:00.000Z');
78
+ expect(deserialized.regex).toBeInstanceOf(RegExp);
79
+ expect(deserialized.regex.toString()).toBe('/test/gi');
80
+ expect(deserialized.error).toBeInstanceOf(Error);
81
+ expect(Number.isNaN(deserialized.nan)).toBe(true);
82
+ expect(deserialized.infinity).toBe(Infinity);
83
+ expect(deserialized.undef).toBeUndefined();
84
+ });
85
+ });
86
+ });
@@ -0,0 +1,6 @@
1
+ export declare const peersRootUserId = "000peers0user000000000001";
2
+ export declare const defaultAssistantId = "000peers0bot00000000shell";
3
+ export declare const defaultAssistantRunnerToolId = "000peers0tool00000runner1";
4
+ export declare const defaultSendMessageToolId = "000peers0tool00000sendmsg";
5
+ export declare const runWorkflowToolId = "000peers0tool0runworkflow";
6
+ export declare const emitEventToolId = "000peers0tool000emitevent";
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.emitEventToolId = exports.runWorkflowToolId = exports.defaultSendMessageToolId = exports.defaultAssistantRunnerToolId = exports.defaultAssistantId = exports.peersRootUserId = void 0;
4
+ exports.peersRootUserId = '000peers0user000000000001';
5
+ exports.defaultAssistantId = '000peers0bot00000000shell';
6
+ // export const defaultAssistantId = '000peers0bot000000000bot1';
7
+ exports.defaultAssistantRunnerToolId = '000peers0tool00000runner1';
8
+ exports.defaultSendMessageToolId = '000peers0tool00000sendmsg';
9
+ exports.runWorkflowToolId = '000peers0tool0runworkflow';
10
+ exports.emitEventToolId = '000peers0tool000emitevent';
@@ -0,0 +1 @@
1
+ export * from './tools-factory';
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./tools-factory"), exports);
@@ -0,0 +1,5 @@
1
+ import { IToolInstance } from "../data";
2
+ export declare function registerTool(toolInstance: IToolInstance): void;
3
+ export declare function getRegisteredTool(toolId: string): IToolInstance | undefined;
4
+ export declare function getAllRegisteredTools(): IToolInstance[];
5
+ export declare function clearRegisteredTools(): void;
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.registerTool = registerTool;
4
+ exports.getRegisteredTool = getRegisteredTool;
5
+ exports.getAllRegisteredTools = getAllRegisteredTools;
6
+ exports.clearRegisteredTools = clearRegisteredTools;
7
+ const keys_1 = require("../keys");
8
+ const registeredToolInstances = {};
9
+ function registerTool(toolInstance) {
10
+ const toolId = toolInstance.tool.toolId;
11
+ if (registeredToolInstances[toolId]) {
12
+ const s1 = (0, keys_1.stableStringify)(registeredToolInstances[toolId].tool);
13
+ const s2 = (0, keys_1.stableStringify)(toolInstance.tool);
14
+ if (s1 !== s2) {
15
+ console.warn(`Attempt to register new tool with existing toolId ${toolId}, it will be ignored`, {
16
+ registered: registeredToolInstances[toolId].tool,
17
+ incoming: toolInstance.tool
18
+ });
19
+ }
20
+ return;
21
+ }
22
+ registeredToolInstances[toolId] = toolInstance;
23
+ }
24
+ function getRegisteredTool(toolId) {
25
+ return registeredToolInstances[toolId];
26
+ }
27
+ function getAllRegisteredTools() {
28
+ return Object.values(registeredToolInstances);
29
+ }
30
+ function clearRegisteredTools() {
31
+ Object.keys(registeredToolInstances).forEach(key => {
32
+ delete registeredToolInstances[key];
33
+ });
34
+ }
@@ -0,0 +1,18 @@
1
+ import { z } from "zod";
2
+ export declare const appNavSchema: z.ZodObject<{
3
+ name: z.ZodString;
4
+ displayName: z.ZodOptional<z.ZodString>;
5
+ iconClassName: z.ZodString;
6
+ navigationPath: z.ZodString;
7
+ }, "strip", z.ZodTypeAny, {
8
+ name: string;
9
+ iconClassName: string;
10
+ navigationPath: string;
11
+ displayName?: string | undefined;
12
+ }, {
13
+ name: string;
14
+ iconClassName: string;
15
+ navigationPath: string;
16
+ displayName?: string | undefined;
17
+ }>;
18
+ export type IAppNav = z.infer<typeof appNavSchema>;