@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,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.appNavSchema = void 0;
4
+ const zod_1 = require("zod");
5
+ exports.appNavSchema = zod_1.z.object({
6
+ name: zod_1.z.string(),
7
+ displayName: zod_1.z.string().optional(),
8
+ iconClassName: zod_1.z.string(),
9
+ navigationPath: zod_1.z.string(),
10
+ });
@@ -0,0 +1,9 @@
1
+ import { IAssistant } from "../data/assistants";
2
+ import { IMessage } from "../data/messages";
3
+ import { IWorkflowLog } from "../data/workflow-logs";
4
+ export interface IAssistantRunnerArgs {
5
+ assistant: IAssistant;
6
+ message: IMessage;
7
+ threadHistory: Readonly<IMessage[]>;
8
+ messageLogs: Readonly<IWorkflowLog[]>;
9
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,37 @@
1
+ import { z } from "zod";
2
+ export declare enum FieldType {
3
+ id = "id",
4
+ string = "string",
5
+ number = "number",
6
+ boolean = "boolean",
7
+ Date = "Date",
8
+ object = "object",
9
+ blob = "blob",
10
+ any = "any"
11
+ }
12
+ export declare const fieldSchema: z.ZodObject<{
13
+ name: z.ZodString;
14
+ description: z.ZodOptional<z.ZodString>;
15
+ type: z.ZodNativeEnum<typeof FieldType>;
16
+ defaultValue: z.ZodOptional<z.ZodAny>;
17
+ optional: z.ZodOptional<z.ZodBoolean>;
18
+ isArray: z.ZodOptional<z.ZodBoolean>;
19
+ subType: z.ZodOptional<z.ZodString>;
20
+ }, "strip", z.ZodTypeAny, {
21
+ name: string;
22
+ type: FieldType;
23
+ optional?: boolean | undefined;
24
+ description?: string | undefined;
25
+ defaultValue?: any;
26
+ isArray?: boolean | undefined;
27
+ subType?: string | undefined;
28
+ }, {
29
+ name: string;
30
+ type: FieldType;
31
+ optional?: boolean | undefined;
32
+ description?: string | undefined;
33
+ defaultValue?: any;
34
+ isArray?: boolean | undefined;
35
+ subType?: string | undefined;
36
+ }>;
37
+ export type IField = z.infer<typeof fieldSchema>;
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.fieldSchema = exports.FieldType = void 0;
4
+ const zod_1 = require("zod");
5
+ //export type FieldType = 'id' | 'string' | 'number' | 'boolean' | 'Date' | 'object' | 'blob' | 'any';
6
+ var FieldType;
7
+ (function (FieldType) {
8
+ FieldType["id"] = "id";
9
+ FieldType["string"] = "string";
10
+ FieldType["number"] = "number";
11
+ FieldType["boolean"] = "boolean";
12
+ FieldType["Date"] = "Date";
13
+ FieldType["object"] = "object";
14
+ FieldType["blob"] = "blob";
15
+ FieldType["any"] = "any";
16
+ })(FieldType || (exports.FieldType = FieldType = {}));
17
+ exports.fieldSchema = zod_1.z.object({
18
+ name: zod_1.z.string(),
19
+ description: zod_1.z.string().optional(),
20
+ type: zod_1.z.nativeEnum(FieldType),
21
+ defaultValue: zod_1.z.any().optional(),
22
+ optional: zod_1.z.boolean().optional(),
23
+ isArray: zod_1.z.boolean().optional(),
24
+ // enumValues: z.array(z.string()).optional(),
25
+ subType: zod_1.z.string().optional(),
26
+ });
@@ -0,0 +1,40 @@
1
+ import type { IChange, GroupMemberRole } from "../data";
2
+ import type { DataFilter, IDataQueryParams } from "../data/orm";
3
+ export interface IPeerDevice {
4
+ deviceId: string;
5
+ userId: string;
6
+ role: GroupMemberRole;
7
+ listChanges(filter?: DataFilter<IChange>, opts?: IDataQueryParams<IChange>): Promise<IChange[]>;
8
+ getNetworkInfo(): Promise<INetworkInfo>;
9
+ notifyOfChanges(deviceId: string, timestampLastApplied: number): Promise<void>;
10
+ }
11
+ export interface INetworkInfo {
12
+ deviceId: string;
13
+ timestampLastApplied: number;
14
+ connections: IDeviceConnection[];
15
+ preferredDeviceIds: string[];
16
+ }
17
+ export interface IDeviceConnection {
18
+ deviceId: string;
19
+ latencyMs: number;
20
+ errorRate: number;
21
+ timestampLastApplied: number;
22
+ onClose?(): Promise<void>;
23
+ }
24
+ export declare const PeerDeviceConsts: Readonly<{
25
+ MAX_CONNECTIONS: 30;
26
+ RESYNC_INTERVAL: number;
27
+ NOTIFY_CHANGE_DELAY: 100;
28
+ CHANGES_PAGE_SIZE: 100;
29
+ RETRY_COUNT: 2;
30
+ TIMEOUT_MIN: number;
31
+ TIMEOUT_MAX: number;
32
+ NETWORK_INFO_CACHE_TIME: 1000;
33
+ }>;
34
+ export type IFileChunkInfo = {
35
+ hasChunk: false;
36
+ } | {
37
+ hasChunk: true;
38
+ downloadQueueSize: number;
39
+ estimatedWaitMs: number;
40
+ };
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PeerDeviceConsts = void 0;
4
+ exports.PeerDeviceConsts = Object.freeze({
5
+ // TODO set this based on device type (desktops and servers should be able to handle 100 connections)
6
+ MAX_CONNECTIONS: 30,
7
+ RESYNC_INTERVAL: 1 * 60 * 1000, // play with this to find the right balance
8
+ NOTIFY_CHANGE_DELAY: 100,
9
+ CHANGES_PAGE_SIZE: 100,
10
+ RETRY_COUNT: 2,
11
+ TIMEOUT_MIN: 3 * 1000,
12
+ TIMEOUT_MAX: 30 * 1000,
13
+ NETWORK_INFO_CACHE_TIME: 1000,
14
+ });
@@ -0,0 +1,23 @@
1
+ import type { IAssistant } from "../data";
2
+ import type { IAppNav } from "./app-nav";
3
+ import type { IPeerEventType } from "../data/peer-events/peer-event-types";
4
+ import type { IToolInstance } from "../data/tools";
5
+ import type { IWorkflow } from "./workflow";
6
+ import type { IPeersUI } from "../peers-ui/peers-ui";
7
+ import type { IPeersUIRoute } from "../peers-ui/peers-ui.types";
8
+ import type { ITableDefinition } from "../data/orm/table-definitions.type";
9
+ export interface IPeersPackage {
10
+ packageId: string;
11
+ toolInstances?: IToolInstance[];
12
+ assistants?: IAssistant[];
13
+ workflows?: IWorkflow[];
14
+ events?: IPeerEventType[];
15
+ appNavs?: IAppNav[];
16
+ tableDefinitions?: ITableDefinition[];
17
+ }
18
+ export interface IPeersPackageRoutes {
19
+ routes: IPeersUIRoute[];
20
+ }
21
+ export interface IPeersPackageUIs {
22
+ uis: IPeersUI[];
23
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ import { IWorkflowLog } from "../data/workflow-logs";
2
+ export type IWorkflowLogger = (logData: string | Omit<Partial<IWorkflowLog>, "workflowRunId" | "workflowLogId">) => Promise<IWorkflowLog>;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,12 @@
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";
5
+ export interface IWorkflowRunContext {
6
+ contextId: string;
7
+ workflowRun: IWorkflowRun;
8
+ logger: IWorkflowLogger;
9
+ getAssistantRunnerArgs: (assistantId: string) => Promise<IAssistantRunnerArgs>;
10
+ getAvailableTools: (args: IAssistantRunnerArgs, similarityText?: string) => Promise<IToolInstance[]>;
11
+ getVariable: (variableName: string, toolId?: string) => Promise<string>;
12
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,72 @@
1
+ import { z } from "zod";
2
+ export declare const workflowInstructionSchema: z.ZodObject<{
3
+ markdown: z.ZodOptional<z.ZodString>;
4
+ onError: z.ZodOptional<z.ZodString>;
5
+ directCallToolId: z.ZodOptional<z.ZodString>;
6
+ subWorkflowId: z.ZodOptional<z.ZodString>;
7
+ }, "strip", z.ZodTypeAny, {
8
+ markdown?: string | undefined;
9
+ onError?: string | undefined;
10
+ directCallToolId?: string | undefined;
11
+ subWorkflowId?: string | undefined;
12
+ }, {
13
+ markdown?: string | undefined;
14
+ onError?: string | undefined;
15
+ directCallToolId?: string | undefined;
16
+ subWorkflowId?: string | undefined;
17
+ }>;
18
+ export type IWorkflowInstruction = z.infer<typeof workflowInstructionSchema>;
19
+ export declare const workflowSchema: z.ZodObject<{
20
+ workflowId: z.ZodString;
21
+ name: z.ZodString;
22
+ description: z.ZodString;
23
+ defaultAssistantId: z.ZodString;
24
+ instructions: z.ZodDefault<z.ZodArray<z.ZodObject<{
25
+ markdown: z.ZodOptional<z.ZodString>;
26
+ onError: z.ZodOptional<z.ZodString>;
27
+ directCallToolId: z.ZodOptional<z.ZodString>;
28
+ subWorkflowId: z.ZodOptional<z.ZodString>;
29
+ }, "strip", z.ZodTypeAny, {
30
+ markdown?: string | undefined;
31
+ onError?: string | undefined;
32
+ directCallToolId?: string | undefined;
33
+ subWorkflowId?: string | undefined;
34
+ }, {
35
+ markdown?: string | undefined;
36
+ onError?: string | undefined;
37
+ directCallToolId?: string | undefined;
38
+ subWorkflowId?: string | undefined;
39
+ }>, "many">>;
40
+ createdBy: z.ZodString;
41
+ createdAt: z.ZodDefault<z.ZodDate>;
42
+ updatedAt: z.ZodDefault<z.ZodDate>;
43
+ }, "strip", z.ZodTypeAny, {
44
+ name: string;
45
+ description: string;
46
+ createdAt: Date;
47
+ workflowId: string;
48
+ defaultAssistantId: string;
49
+ instructions: {
50
+ markdown?: string | undefined;
51
+ onError?: string | undefined;
52
+ directCallToolId?: string | undefined;
53
+ subWorkflowId?: string | undefined;
54
+ }[];
55
+ createdBy: string;
56
+ updatedAt: Date;
57
+ }, {
58
+ name: string;
59
+ description: string;
60
+ workflowId: string;
61
+ defaultAssistantId: string;
62
+ createdBy: string;
63
+ createdAt?: Date | undefined;
64
+ instructions?: {
65
+ markdown?: string | undefined;
66
+ onError?: string | undefined;
67
+ directCallToolId?: string | undefined;
68
+ subWorkflowId?: string | undefined;
69
+ }[] | undefined;
70
+ updatedAt?: Date | undefined;
71
+ }>;
72
+ export type IWorkflow = z.infer<typeof workflowSchema>;
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.workflowSchema = exports.workflowInstructionSchema = void 0;
4
+ const zod_1 = require("zod");
5
+ exports.workflowInstructionSchema = zod_1.z.object({
6
+ markdown: zod_1.z.string().optional().describe('The instruction in markdown format'),
7
+ onError: zod_1.z.string().optional().describe('The instruction to run if there is an error while running this instruction'),
8
+ directCallToolId: zod_1.z.string().optional().describe('The tool to call directly with the tool id'),
9
+ subWorkflowId: zod_1.z.string().optional().describe('The sub workflow to run with the workflow id'),
10
+ });
11
+ exports.workflowSchema = zod_1.z.object({
12
+ workflowId: zod_1.z.string(),
13
+ name: zod_1.z.string().describe('The name of the workflow'),
14
+ 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'),
15
+ defaultAssistantId: zod_1.z.string().describe('The default assistant to handle instructions when the workflow is run'),
16
+ instructions: exports.workflowInstructionSchema
17
+ .array().describe([
18
+ 'The instructions for the workflow. This should be written in markdown and can include special links to other workflows, tools, etc. via mentions',
19
+ 'The instructions should be broken down into discrete steps and should be as clear as possible.',
20
+ ].join(' ')).default([]),
21
+ createdBy: zod_1.z.string().describe('The user who created the workflow'),
22
+ createdAt: zod_1.z.date().default(() => new Date()).describe('The date the workflow was created'),
23
+ updatedAt: zod_1.z.date().default(() => new Date()).describe('The date the workflow was last updated'),
24
+ });
@@ -0,0 +1,7 @@
1
+ import { z } from 'zod';
2
+ export declare const zodAnyObject: z.ZodObject<{}, "strip", z.ZodAny, z.objectOutputType<{}, z.ZodAny, "strip">, z.objectInputType<{}, z.ZodAny, "strip">>;
3
+ 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
+ export declare const zodPeerId: z.ZodEffects<z.ZodString, string, string>;
5
+ export type ZodObjectType = z.ZodObject<any>;
6
+ export type ZodArrayType = z.ZodArray<any>;
7
+ export type ZodAnyObjectOrArrayType = ZodArrayType | ZodObjectType;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.zodPeerId = exports.zodAnyObjectOrArray = exports.zodAnyObject = void 0;
4
+ const zod_1 = require("zod");
5
+ const utils_1 = require("../utils");
6
+ exports.zodAnyObject = zod_1.z.object({}).catchall(zod_1.z.any());
7
+ exports.zodAnyObjectOrArray = zod_1.z.union([exports.zodAnyObject, zod_1.z.array(zod_1.z.any())]);
8
+ exports.zodPeerId = zod_1.z.string().refine(value => {
9
+ return (0, utils_1.isid)(value);
10
+ }, {
11
+ message: "Invalid peer id, it must be a 25 character alphanumeric string",
12
+ });
@@ -0,0 +1,13 @@
1
+ import { DataContext, DataFilter, ICursorIterable, IUser } from "./index";
2
+ export interface IUsersQueryOpts {
3
+ currentDataContext?: DataContext;
4
+ includeCurrentDataContext?: boolean;
5
+ includeUserDataContext?: boolean;
6
+ includeOtherDataContexts?: boolean;
7
+ }
8
+ export type IUserSource = 'currentDataContext' | 'userDataContext' | 'otherDataContexts';
9
+ export interface IUserWithSource extends IUser {
10
+ source: IUserSource;
11
+ }
12
+ export declare function usersCursor(filter: DataFilter<IUser>, opts?: IUsersQueryOpts): Promise<ICursorIterable<IUserWithSource>>;
13
+ export declare function getUserById(userId: string, opts?: IUsersQueryOpts): Promise<IUserWithSource | undefined>;
@@ -0,0 +1,134 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.usersCursor = usersCursor;
4
+ exports.getUserById = getUserById;
5
+ const index_1 = require("./index");
6
+ async function usersCursor(filter, opts = {}) {
7
+ const { currentDataContext, includeCurrentDataContext = true, includeUserDataContext = true, includeOtherDataContexts = true } = opts;
8
+ const userContext = await (0, index_1.getUserContext)();
9
+ const contextToUse = currentDataContext || userContext.defaultDataContext();
10
+ let finalCursor = null;
11
+ // Include current data context
12
+ if (includeCurrentDataContext) {
13
+ const primaryTable = (0, index_1.Users)(contextToUse);
14
+ const primarySource = (contextToUse === userContext.userDataContext) ? 'userDataContext' : 'currentDataContext';
15
+ const primaryCursor = index_1.Cursor.fromDataSource(primaryTable, filter)
16
+ .map(user => {
17
+ const userWithSource = {
18
+ ...user,
19
+ source: primarySource,
20
+ };
21
+ return userWithSource;
22
+ });
23
+ finalCursor = primaryCursor;
24
+ }
25
+ // Include user data context (if different from current and requested)
26
+ if (includeUserDataContext && contextToUse !== userContext.userDataContext) {
27
+ const userDataContextTable = (0, index_1.Users)(userContext.userDataContext);
28
+ const userDataContextCursor = index_1.Cursor.fromDataSource(userDataContextTable, filter)
29
+ .map(user => {
30
+ const userWithSource = {
31
+ ...user,
32
+ source: 'userDataContext'
33
+ };
34
+ return userWithSource;
35
+ });
36
+ finalCursor = finalCursor ? finalCursor.union(userDataContextCursor) : userDataContextCursor;
37
+ }
38
+ // Include other data contexts (group contexts)
39
+ if (includeOtherDataContexts) {
40
+ const otherDataContexts = [];
41
+ for (const [, dataContext] of userContext.groupDataContexts) {
42
+ if (contextToUse !== dataContext) {
43
+ otherDataContexts.push(dataContext);
44
+ }
45
+ }
46
+ if (otherDataContexts.length > 0) {
47
+ const otherDataContextTables = otherDataContexts.map(dataContext => (0, index_1.Users)(dataContext));
48
+ const otherDataContextsCursor = index_1.Cursor.fromDataSources(otherDataContextTables, filter)
49
+ .map(user => {
50
+ const userWithSource = {
51
+ ...user,
52
+ source: 'otherDataContexts'
53
+ };
54
+ return userWithSource;
55
+ });
56
+ finalCursor = finalCursor ? finalCursor.union(otherDataContextsCursor) : otherDataContextsCursor;
57
+ }
58
+ }
59
+ // If no cursor was created, return empty cursor
60
+ if (!finalCursor) {
61
+ return index_1.Cursor.fromDataSource((0, index_1.Users)(contextToUse), { userId: { $eq: '__non_existent__' } })
62
+ .map(user => ({ ...user, source: 'userDataContext' }));
63
+ }
64
+ // Deduplication by userId
65
+ // TODO: Push deduplication logic down into the queries for better performance
66
+ const userIdsSeen = new Set();
67
+ return finalCursor.filter(user => {
68
+ if (userIdsSeen.has(user.userId)) {
69
+ return false;
70
+ }
71
+ userIdsSeen.add(user.userId);
72
+ return true;
73
+ });
74
+ }
75
+ async function getUserById(userId, opts = {}) {
76
+ const { currentDataContext, includeCurrentDataContext = true, includeUserDataContext = true, includeOtherDataContexts = true } = opts;
77
+ const userContext = await (0, index_1.getUserContext)();
78
+ const contextToUse = currentDataContext || userContext.defaultDataContext();
79
+ // Try current data context first
80
+ if (includeCurrentDataContext) {
81
+ try {
82
+ const primaryTable = (0, index_1.Users)(contextToUse);
83
+ const user = await primaryTable.get(userId);
84
+ if (user) {
85
+ const source = (contextToUse === userContext.userDataContext) ? 'userDataContext' : 'currentDataContext';
86
+ return {
87
+ ...user,
88
+ source
89
+ };
90
+ }
91
+ }
92
+ catch (error) {
93
+ // User not found in this context, continue to next
94
+ }
95
+ }
96
+ // Try user data context (if different from current and requested)
97
+ if (includeUserDataContext && contextToUse !== userContext.userDataContext) {
98
+ try {
99
+ const userDataContextTable = (0, index_1.Users)(userContext.userDataContext);
100
+ const user = await userDataContextTable.get(userId);
101
+ if (user) {
102
+ return {
103
+ ...user,
104
+ source: 'userDataContext'
105
+ };
106
+ }
107
+ }
108
+ catch (error) {
109
+ // User not found in this context, continue to next
110
+ }
111
+ }
112
+ // Try other data contexts (group contexts)
113
+ if (includeOtherDataContexts) {
114
+ for (const [, dataContext] of userContext.groupDataContexts) {
115
+ if (contextToUse !== dataContext) {
116
+ try {
117
+ const table = (0, index_1.Users)(dataContext);
118
+ const user = await table.get(userId);
119
+ if (user) {
120
+ return {
121
+ ...user,
122
+ source: 'otherDataContexts'
123
+ };
124
+ }
125
+ }
126
+ catch (error) {
127
+ // User not found in this context, continue to next
128
+ }
129
+ }
130
+ }
131
+ }
132
+ // User not found in any context
133
+ return undefined;
134
+ }
@@ -0,0 +1,39 @@
1
+ import { IDeviceConnection } from './types/peer-device';
2
+ import type { ITableMetaData } from './data/orm';
3
+ export declare function cryptoRandomString(length: number): string;
4
+ export declare function newid(): string;
5
+ export declare const MIN_ID: string;
6
+ export declare const MAX_ID: string;
7
+ export declare function isid(id: any): boolean;
8
+ export declare function idTime(id: string): number;
9
+ export declare function idDate(id: string): Date;
10
+ /**
11
+ * This returns the random number as two parts to prevent loss of precision when converting to large numbers
12
+ */
13
+ export declare function idRandNums(id: string): [number, number];
14
+ export declare function simpleHash(str: string): number;
15
+ export type Optional<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
16
+ export declare function simpleObjectHash(obj: any): number;
17
+ export declare function sleep(ms?: number): Promise<void>;
18
+ export declare function camelCaseToSpaces(s: string): string;
19
+ export declare function camelCaseToHyphens(s: string): string;
20
+ export declare const moneyFormatter: Intl.NumberFormat;
21
+ export declare function formatMoney(value: number, precision?: number): string;
22
+ export declare function memoizePromise<F extends (...args: any[]) => Promise<any>>(fn: F, opts?: {
23
+ cacheTtl?: number;
24
+ }): F;
25
+ export declare function debounceByArgs<F extends (...args: any[]) => any>(fn: F, wait?: number): F;
26
+ export declare function getTimestamp(): number;
27
+ export declare function retryOnErrorOrTimeout<T>({ fn, connection, opts, }: {
28
+ fn: () => Promise<T>;
29
+ connection: IDeviceConnection;
30
+ opts?: {
31
+ timeout?: number;
32
+ retriesOnError?: number;
33
+ retriesOnTimeout?: number;
34
+ };
35
+ }): Promise<T>;
36
+ /**
37
+ * Table name is "name_id" if `id` is present, otherwise just "name"
38
+ */
39
+ export declare function getFullTableName(metaData: ITableMetaData): string;