@peers-app/peers-sdk 0.13.5 → 0.14.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.
@@ -16,6 +16,7 @@ export declare class UserContext {
16
16
  readonly defaultDataContext: Observable<DataContext>;
17
17
  readonly loadingPromise: Promise<UserContext>;
18
18
  private personalUserSubscription?;
19
+ private _currentlyActiveGroupIdPVar?;
19
20
  constructor(userId: string, dataSourceFactory: DataSourceFactory, ephemeral?: boolean | undefined);
20
21
  private init;
21
22
  /**
@@ -25,6 +26,8 @@ export declare class UserContext {
25
26
  private loadAllPackages;
26
27
  private loadGroupContexts;
27
28
  getDataContext(groupId: string): DataContext;
29
+ /** Wait for any pending `currentlyActiveGroupId` pvar write to be flushed to the DB. */
30
+ waitForActiveGroupPersistence(): Promise<void>;
28
31
  /**
29
32
  * Load observables from the database
30
33
  * This is pretty ugly but get's around guards on the default logic which is waiting
@@ -21,6 +21,7 @@ class UserContext {
21
21
  defaultDataContext;
22
22
  loadingPromise;
23
23
  personalUserSubscription;
24
+ _currentlyActiveGroupIdPVar;
24
25
  constructor(userId, dataSourceFactory, ephemeral) {
25
26
  this.userId = userId;
26
27
  this.dataSourceFactory = dataSourceFactory;
@@ -112,6 +113,12 @@ class UserContext {
112
113
  }
113
114
  return this.groupDataContexts.get(groupId);
114
115
  }
116
+ /** Wait for any pending `currentlyActiveGroupId` pvar write to be flushed to the DB. */
117
+ async waitForActiveGroupPersistence() {
118
+ if (this._currentlyActiveGroupIdPVar) {
119
+ await this._currentlyActiveGroupIdPVar.loadingPromise;
120
+ }
121
+ }
115
122
  /**
116
123
  * Load observables from the database
117
124
  * This is pretty ugly but get's around guards on the default logic which is waiting
@@ -130,6 +137,7 @@ class UserContext {
130
137
  this.deviceId(deviceIdPVar());
131
138
  (0, observable_1.linkObservables)(deviceIdPVar, this.deviceId);
132
139
  const currentlyActiveGroupIdPVar = (0, data_1.deviceVar)('currentlyActiveGroupId', { dbValue: varDbValues['currentlyActiveGroupId'], defaultValue: '', userContext: this });
140
+ this._currentlyActiveGroupIdPVar = currentlyActiveGroupIdPVar;
133
141
  this.currentlyActiveGroupId(currentlyActiveGroupIdPVar());
134
142
  (0, observable_1.linkObservables)(currentlyActiveGroupIdPVar, this.currentlyActiveGroupId);
135
143
  const reloadPackagesOnPageRefreshPVar = (0, data_1.deviceVar)('reloadPackagesOnPageRefresh', { defaultValue: false, dbValue: varDbValues['reloadPackagesOnPageRefresh'], userContext: this });
@@ -137,6 +145,7 @@ class UserContext {
137
145
  (0, observable_1.linkObservables)(reloadPackagesOnPageRefreshPVar, this.reloadPackagesOnPageRefresh);
138
146
  await Promise.all([
139
147
  deviceIdPVar.loadingPromise,
148
+ currentlyActiveGroupIdPVar.loadingPromise,
140
149
  reloadPackagesOnPageRefreshPVar.loadingPromise,
141
150
  ]);
142
151
  }
@@ -11,19 +11,12 @@ export * from "./groups";
11
11
  export * from "./group-members";
12
12
  export * from "./group-member-roles";
13
13
  export * from "./group-share";
14
- export * from "./knowledge/knowledge-frames";
15
- export * from "./knowledge/knowledge-links";
16
- export * from "./knowledge/knowledge-values";
17
14
  export * from "./knowledge/peer-types";
18
- export * from "./knowledge/predicates";
19
15
  export * from "./messages";
20
16
  export * from "./package-versions";
21
17
  export * from "./packages";
22
18
  export * from "./packages.utils";
23
19
  export * from "./table-definitions-table";
24
- export * from "./peer-events/peer-event-handlers";
25
- export * from "./peer-events/peer-event-types";
26
- export * from "./peer-events/peer-events";
27
20
  export * from "./persistent-vars";
28
21
  export * from "./tool-tests";
29
22
  export * from "./tools";
@@ -27,19 +27,12 @@ __exportStar(require("./groups"), exports);
27
27
  __exportStar(require("./group-members"), exports);
28
28
  __exportStar(require("./group-member-roles"), exports);
29
29
  __exportStar(require("./group-share"), exports);
30
- __exportStar(require("./knowledge/knowledge-frames"), exports);
31
- __exportStar(require("./knowledge/knowledge-links"), exports);
32
- __exportStar(require("./knowledge/knowledge-values"), exports);
33
30
  __exportStar(require("./knowledge/peer-types"), exports);
34
- __exportStar(require("./knowledge/predicates"), exports);
35
31
  __exportStar(require("./messages"), exports);
36
32
  __exportStar(require("./package-versions"), exports);
37
33
  __exportStar(require("./packages"), exports);
38
34
  __exportStar(require("./packages.utils"), exports);
39
35
  __exportStar(require("./table-definitions-table"), exports);
40
- __exportStar(require("./peer-events/peer-event-handlers"), exports);
41
- __exportStar(require("./peer-events/peer-event-types"), exports);
42
- __exportStar(require("./peer-events/peer-events"), exports);
43
36
  __exportStar(require("./persistent-vars"), exports);
44
37
  __exportStar(require("./tool-tests"), exports);
45
38
  __exportStar(require("./tools"), exports);
@@ -35,8 +35,8 @@ declare const schema: z.ZodObject<{
35
35
  createdAt: z.ZodString;
36
36
  }, "strip", z.ZodTypeAny, {
37
37
  signature: string;
38
- createdAt: string;
39
38
  createdBy: string;
39
+ createdAt: string;
40
40
  packageId: string;
41
41
  packageVersionId: string;
42
42
  version: string;
@@ -56,8 +56,8 @@ declare const schema: z.ZodObject<{
56
56
  }[] | undefined;
57
57
  }, {
58
58
  signature: string;
59
- createdAt: string;
60
59
  createdBy: string;
60
+ createdAt: string;
61
61
  packageId: string;
62
62
  packageVersionId: string;
63
63
  version: string;
@@ -33,7 +33,6 @@ export declare const workflowRunSchema: z.ZodObject<{
33
33
  parentWorkflowRunId: z.ZodOptional<z.ZodEffects<z.ZodString, string, string>>;
34
34
  defaultAssistantId: z.ZodEffects<z.ZodString, string, string>;
35
35
  }, "strip", z.ZodTypeAny, {
36
- createdAt: Date;
37
36
  defaultAssistantId: string;
38
37
  instructions: {
39
38
  markdown?: string | undefined;
@@ -41,6 +40,7 @@ export declare const workflowRunSchema: z.ZodObject<{
41
40
  directCallToolId?: string | undefined;
42
41
  subWorkflowId?: string | undefined;
43
42
  }[];
43
+ createdAt: Date;
44
44
  workflowRunId: string;
45
45
  parentMessageId: string;
46
46
  currentInstructionIndex: number;
@@ -58,7 +58,6 @@ export declare const workflowRunSchema: z.ZodObject<{
58
58
  defaultAssistantId: string;
59
59
  workflowRunId: string;
60
60
  parentMessageId: string;
61
- createdAt?: Date | undefined;
62
61
  workflowId?: string | undefined;
63
62
  instructions?: {
64
63
  markdown?: string | undefined;
@@ -66,6 +65,7 @@ export declare const workflowRunSchema: z.ZodObject<{
66
65
  directCallToolId?: string | undefined;
67
66
  subWorkflowId?: string | undefined;
68
67
  }[] | undefined;
68
+ createdAt?: Date | undefined;
69
69
  scheduleDT?: Date | undefined;
70
70
  currentInstructionIndex?: number | undefined;
71
71
  instructionResults?: any[] | undefined;
@@ -2,7 +2,6 @@ import type { DataContext } from "../context/data-context";
2
2
  export declare function Workflows(dataContext?: DataContext): import("./orm").Table<{
3
3
  name: string;
4
4
  description: string;
5
- createdAt: Date;
6
5
  workflowId: string;
7
6
  defaultAssistantId: string;
8
7
  instructions: {
@@ -12,5 +11,6 @@ export declare function Workflows(dataContext?: DataContext): import("./orm").Ta
12
11
  subWorkflowId?: string | undefined;
13
12
  }[];
14
13
  createdBy: string;
14
+ createdAt: Date;
15
15
  updatedAt: Date;
16
16
  }>;
@@ -112,6 +112,7 @@ export declare const rpcServerCalls: {
112
112
  voiceNotifyTextActivity: (() => Promise<void>);
113
113
  voiceDisable: (() => Promise<void>);
114
114
  voiceEnable: (() => Promise<void>);
115
+ flushDatabases: (() => Promise<void>);
115
116
  };
116
117
  export declare const rpcClientCalls: {
117
118
  ping: (msg: string) => Promise<string>;
package/dist/rpc-types.js CHANGED
@@ -59,6 +59,9 @@ exports.rpcServerCalls = {
59
59
  voiceNotifyTextActivity: rpcStub('voiceNotifyTextActivity'),
60
60
  voiceDisable: rpcStub('voiceDisable'),
61
61
  voiceEnable: rpcStub('voiceEnable'),
62
+ // Flush all in-memory database snapshots to durable storage (IndexedDB in PWA).
63
+ // No-op on Electron where better-sqlite3 writes are synchronous to disk.
64
+ flushDatabases: (async () => { }),
62
65
  // TODO try to get rid of this and rely on the client-side table and server-side table individually emitting events
63
66
  // TODO TODO before deleting this, check if we can stop client-side tables from emitting events and rely solely on server-side tables
64
67
  // propagating events with rpcClientCalls.emitEvent. It's very likely we're currently seeing two events for every one write originating from the UI
@@ -4,6 +4,5 @@ export declare const openCodeAssistantId = "00mlwl2km2opencode0000001";
4
4
  export declare const defaultAssistantRunnerToolId = "000peers0tool00000runner1";
5
5
  export declare const defaultSendMessageToolId = "000peers0tool00000sendmsg";
6
6
  export declare const runWorkflowToolId = "000peers0tool0runworkflow";
7
- export declare const emitEventToolId = "000peers0tool000emitevent";
8
7
  export declare const peersCorePackageId = "00mh0wlipjixk2gqmurbwee0o";
9
8
  export declare const peersCorePackageRepoUrl = "https://github.com/peers-app/peers-core";
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.peersCorePackageRepoUrl = exports.peersCorePackageId = exports.emitEventToolId = exports.runWorkflowToolId = exports.defaultSendMessageToolId = exports.defaultAssistantRunnerToolId = exports.openCodeAssistantId = exports.defaultAssistantId = exports.peersRootUserId = void 0;
3
+ exports.peersCorePackageRepoUrl = exports.peersCorePackageId = exports.runWorkflowToolId = exports.defaultSendMessageToolId = exports.defaultAssistantRunnerToolId = exports.openCodeAssistantId = exports.defaultAssistantId = exports.peersRootUserId = void 0;
4
4
  exports.peersRootUserId = '000peers0user000000000001';
5
5
  exports.defaultAssistantId = '000peers0bot00000000shell';
6
6
  // export const defaultAssistantId = '000peers0bot000000000bot1';
@@ -8,6 +8,5 @@ exports.openCodeAssistantId = '00mlwl2km2opencode0000001';
8
8
  exports.defaultAssistantRunnerToolId = '000peers0tool00000runner1';
9
9
  exports.defaultSendMessageToolId = '000peers0tool00000sendmsg';
10
10
  exports.runWorkflowToolId = '000peers0tool0runworkflow';
11
- exports.emitEventToolId = '000peers0tool000emitevent';
12
11
  exports.peersCorePackageId = '00mh0wlipjixk2gqmurbwee0o';
13
12
  exports.peersCorePackageRepoUrl = 'https://github.com/peers-app/peers-core';
@@ -1,6 +1,5 @@
1
1
  import type { IAssistant } from "../data";
2
2
  import type { IAppNav } from "./app-nav";
3
- import type { IPeerEventType } from "../data/peer-events/peer-event-types";
4
3
  import type { IToolInstance } from "../data/tools";
5
4
  import type { IWorkflow } from "./workflow";
6
5
  import type { IPeersUI } from "../peers-ui/peers-ui";
@@ -11,7 +10,6 @@ export interface IPeersPackage {
11
10
  toolInstances?: IToolInstance[];
12
11
  assistants?: IAssistant[];
13
12
  workflows?: IWorkflow[];
14
- events?: IPeerEventType[];
15
13
  appNavs?: IAppNav[];
16
14
  tableDefinitions?: ITableDefinition[];
17
15
  }
@@ -43,7 +43,6 @@ export declare const workflowSchema: z.ZodObject<{
43
43
  }, "strip", z.ZodTypeAny, {
44
44
  name: string;
45
45
  description: string;
46
- createdAt: Date;
47
46
  workflowId: string;
48
47
  defaultAssistantId: string;
49
48
  instructions: {
@@ -53,6 +52,7 @@ export declare const workflowSchema: z.ZodObject<{
53
52
  subWorkflowId?: string | undefined;
54
53
  }[];
55
54
  createdBy: string;
55
+ createdAt: Date;
56
56
  updatedAt: Date;
57
57
  }, {
58
58
  name: string;
@@ -60,13 +60,13 @@ export declare const workflowSchema: z.ZodObject<{
60
60
  workflowId: string;
61
61
  defaultAssistantId: string;
62
62
  createdBy: string;
63
- createdAt?: Date | undefined;
64
63
  instructions?: {
65
64
  markdown?: string | undefined;
66
65
  onError?: string | undefined;
67
66
  directCallToolId?: string | undefined;
68
67
  subWorkflowId?: string | undefined;
69
68
  }[] | undefined;
69
+ createdAt?: Date | undefined;
70
70
  updatedAt?: Date | undefined;
71
71
  }>;
72
72
  export type IWorkflow = z.infer<typeof workflowSchema>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@peers-app/peers-sdk",
3
- "version": "0.13.5",
3
+ "version": "0.14.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/peers-app/peers-sdk.git"
@@ -1,34 +0,0 @@
1
- import { z } from "zod";
2
- import type { DataContext } from "../../context/data-context";
3
- declare const knowledgeFrameSchema: z.ZodObject<{
4
- knowledgeFrameId: z.ZodEffects<z.ZodString, string, string>;
5
- name: z.ZodString;
6
- body: z.ZodString;
7
- conclusion: z.ZodOptional<z.ZodString>;
8
- knowledgeValueIds: z.ZodArray<z.ZodEffects<z.ZodString, string, string>, "many">;
9
- modified: z.ZodNumber;
10
- }, "strip", z.ZodTypeAny, {
11
- name: string;
12
- body: string;
13
- knowledgeFrameId: string;
14
- knowledgeValueIds: string[];
15
- modified: number;
16
- conclusion?: string | undefined;
17
- }, {
18
- name: string;
19
- body: string;
20
- knowledgeFrameId: string;
21
- knowledgeValueIds: string[];
22
- modified: number;
23
- conclusion?: string | undefined;
24
- }>;
25
- export type IKnowledgeFrame = z.infer<typeof knowledgeFrameSchema>;
26
- export declare function KnowledgeFrames(dataContext?: DataContext): import("../orm").Table<{
27
- name: string;
28
- body: string;
29
- knowledgeFrameId: string;
30
- knowledgeValueIds: string[];
31
- modified: number;
32
- conclusion?: string | undefined;
33
- }>;
34
- export {};
@@ -1,34 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.KnowledgeFrames = KnowledgeFrames;
4
- const zod_1 = require("zod");
5
- const types_1 = require("../orm/types");
6
- const user_context_singleton_1 = require("../../context/user-context-singleton");
7
- const table_definitions_system_1 = require("../orm/table-definitions.system");
8
- const zod_types_1 = require("../../types/zod-types");
9
- // Think of a knowledge frame as like a "hub note" in Roam Research
10
- // besides just linking content together with a central topic,
11
- // it is also a way to explore and idea by surfacing new links and generating new knowledge values
12
- const knowledgeFrameSchema = zod_1.z.object({
13
- knowledgeFrameId: zod_types_1.zodPeerId,
14
- name: zod_1.z.string().describe('The name or topic of the knowledge frame'),
15
- body: zod_1.z.string().describe('Describe the purpose / thesis / goal of the knowledge frame'),
16
- conclusion: zod_1.z.string().optional().describe('The conclusion of the knowledge frame'),
17
- knowledgeValueIds: zod_types_1.zodPeerId.array().describe('The knowledge values that are included in the frame'),
18
- // knowledgeLinkIds: zodPeerId.array().describe('The knowledge links that are allowed in the frame'),
19
- // excludedValueIds: zodPeerId.array().describe('The knowledge values that are explicitly excluded from the frame'),
20
- // allowedPredicateIds: zodPeerId.array().describe('The predicates that are allowed in the frame'),
21
- // allowedpeerTypeIds: zodPeerId.array().describe('The value types that are allowed in the frame'),
22
- modified: zod_1.z.number().describe('The last time the frame was modified'),
23
- });
24
- const metaData = {
25
- name: 'KnowledgeFrames',
26
- description: "The knowledge frames in the system",
27
- primaryKeyName: 'knowledgeFrameId',
28
- fields: (0, types_1.schemaToFields)(knowledgeFrameSchema),
29
- iconClassName: 'bi bi-window-dock',
30
- };
31
- (0, table_definitions_system_1.registerSystemTableDefinition)(metaData, knowledgeFrameSchema);
32
- function KnowledgeFrames(dataContext) {
33
- return (0, user_context_singleton_1.getTableContainer)(dataContext).getTable(metaData, knowledgeFrameSchema);
34
- }
@@ -1,30 +0,0 @@
1
- import { z } from "zod";
2
- import type { DataContext } from "../../context/data-context";
3
- declare const knowledgeLinkSchema: z.ZodObject<{
4
- knowledgeLinkId: z.ZodEffects<z.ZodString, string, string>;
5
- subjectValueId: z.ZodEffects<z.ZodString, string, string>;
6
- predicateId: z.ZodEffects<z.ZodString, string, string>;
7
- predicateValue: z.ZodAny;
8
- objectValueId: z.ZodOptional<z.ZodEffects<z.ZodString, string, string>>;
9
- }, "strip", z.ZodTypeAny, {
10
- knowledgeLinkId: string;
11
- subjectValueId: string;
12
- predicateId: string;
13
- predicateValue?: any;
14
- objectValueId?: string | undefined;
15
- }, {
16
- knowledgeLinkId: string;
17
- subjectValueId: string;
18
- predicateId: string;
19
- predicateValue?: any;
20
- objectValueId?: string | undefined;
21
- }>;
22
- export type IKnowledgeLink = z.infer<typeof knowledgeLinkSchema>;
23
- export declare function KnowledgeLinks(dataContext?: DataContext): import("../orm").Table<{
24
- knowledgeLinkId: string;
25
- subjectValueId: string;
26
- predicateId: string;
27
- predicateValue?: any;
28
- objectValueId?: string | undefined;
29
- }>;
30
- export {};
@@ -1,25 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.KnowledgeLinks = KnowledgeLinks;
4
- const zod_1 = require("zod");
5
- const types_1 = require("../orm/types");
6
- const user_context_singleton_1 = require("../../context/user-context-singleton");
7
- const table_definitions_system_1 = require("../orm/table-definitions.system");
8
- const zod_types_1 = require("../../types/zod-types");
9
- const knowledgeLinkSchema = zod_1.z.object({
10
- knowledgeLinkId: zod_types_1.zodPeerId,
11
- subjectValueId: zod_types_1.zodPeerId.describe('The knowledge entry that is the subject of the link'),
12
- predicateId: zod_types_1.zodPeerId.describe('The predicate of the knowledge link'),
13
- predicateValue: zod_1.z.any().describe('The value of the predicate'),
14
- objectValueId: zod_types_1.zodPeerId.optional().describe('The knowledge entry that is the object of the link'),
15
- });
16
- const metaData = {
17
- name: 'KnowledgeLinks',
18
- description: "The knowledge links in the system",
19
- primaryKeyName: 'knowledgeLinkId',
20
- fields: (0, types_1.schemaToFields)(knowledgeLinkSchema),
21
- };
22
- (0, table_definitions_system_1.registerSystemTableDefinition)(metaData, knowledgeLinkSchema);
23
- function KnowledgeLinks(dataContext) {
24
- return (0, user_context_singleton_1.getTableContainer)(dataContext).getTable(metaData, knowledgeLinkSchema);
25
- }
@@ -1,35 +0,0 @@
1
- import { z } from "zod";
2
- import type { DataContext } from "../../context/data-context";
3
- export declare const knowledgeValueSchema: z.ZodObject<{
4
- knowledgeValueId: z.ZodEffects<z.ZodString, string, string>;
5
- peerTypeId: z.ZodEffects<z.ZodString, string, string>;
6
- value: z.ZodObject<{}, "strip", z.ZodAny, z.objectOutputType<{}, z.ZodAny, "strip">, z.objectInputType<{}, z.ZodAny, "strip">>;
7
- name: z.ZodString;
8
- lastModified: z.ZodOptional<z.ZodDate>;
9
- }, "strip", z.ZodTypeAny, {
10
- name: string;
11
- value: {} & {
12
- [k: string]: any;
13
- };
14
- knowledgeValueId: string;
15
- peerTypeId: string;
16
- lastModified?: Date | undefined;
17
- }, {
18
- name: string;
19
- value: {} & {
20
- [k: string]: any;
21
- };
22
- knowledgeValueId: string;
23
- peerTypeId: string;
24
- lastModified?: Date | undefined;
25
- }>;
26
- export type IKnowledgeValue = z.infer<typeof knowledgeValueSchema>;
27
- export declare function KnowledgeValues(dataContext?: DataContext): import("../orm").Table<{
28
- name: string;
29
- value: {} & {
30
- [k: string]: any;
31
- };
32
- knowledgeValueId: string;
33
- peerTypeId: string;
34
- lastModified?: Date | undefined;
35
- }>;
@@ -1,35 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.knowledgeValueSchema = void 0;
4
- exports.KnowledgeValues = KnowledgeValues;
5
- const zod_1 = require("zod");
6
- const types_1 = require("../orm/types");
7
- const user_context_singleton_1 = require("../../context/user-context-singleton");
8
- const table_definitions_system_1 = require("../orm/table-definitions.system");
9
- const zod_types_1 = require("../../types/zod-types");
10
- exports.knowledgeValueSchema = zod_1.z.object({
11
- knowledgeValueId: zod_types_1.zodPeerId,
12
- peerTypeId: zod_types_1.zodPeerId.describe('The id of the peer type definition of the knowledge value.'),
13
- value: zod_types_1.zodAnyObject.describe('The knowledge value. It must conform to the value type schema'),
14
- // For several reasons (mostly UI and query related) it's useful to have an explicit, top-level name field for everything.
15
- // A disadvantage is that this can be redundant with the name field of the value type (if it exists).
16
- // An advantage is this gives us names for simple values
17
- // Something weird is names for knowledge values of type `none`. But a knowledge value of type `none` is weird by itself. (what is it?)
18
- name: zod_1.z.string().describe('The name of the knowledge value.'),
19
- lastModified: zod_1.z.date().optional().describe('The last time the knowledge value was modified.'),
20
- });
21
- const metaData = {
22
- name: 'KnowledgeValues',
23
- description: "The knowledge values in the system",
24
- primaryKeyName: 'knowledgeValueId',
25
- fields: (0, types_1.schemaToFields)(exports.knowledgeValueSchema),
26
- indexes: [
27
- { fields: ['peerTypeId'] },
28
- { fields: ['name'] },
29
- { fields: ['lastModified'] },
30
- ],
31
- };
32
- (0, table_definitions_system_1.registerSystemTableDefinition)(metaData, exports.knowledgeValueSchema);
33
- function KnowledgeValues(dataContext) {
34
- return (0, user_context_singleton_1.getTableContainer)(dataContext).getTable(metaData, exports.knowledgeValueSchema);
35
- }
@@ -1,34 +0,0 @@
1
- import { z } from "zod";
2
- import type { DataContext } from "../../context/data-context";
3
- declare const predicateSchema: z.ZodObject<{
4
- predicateId: z.ZodEffects<z.ZodString, string, string>;
5
- name: z.ZodString;
6
- description: z.ZodOptional<z.ZodString>;
7
- peerTypeId: z.ZodOptional<z.ZodEffects<z.ZodString, string, string>>;
8
- allowedSubjectValueTypes: z.ZodOptional<z.ZodArray<z.ZodEffects<z.ZodString, string, string>, "many">>;
9
- allowedObjectValueTypes: z.ZodOptional<z.ZodArray<z.ZodEffects<z.ZodString, string, string>, "many">>;
10
- }, "strip", z.ZodTypeAny, {
11
- name: string;
12
- predicateId: string;
13
- description?: string | undefined;
14
- peerTypeId?: string | undefined;
15
- allowedSubjectValueTypes?: string[] | undefined;
16
- allowedObjectValueTypes?: string[] | undefined;
17
- }, {
18
- name: string;
19
- predicateId: string;
20
- description?: string | undefined;
21
- peerTypeId?: string | undefined;
22
- allowedSubjectValueTypes?: string[] | undefined;
23
- allowedObjectValueTypes?: string[] | undefined;
24
- }>;
25
- export type IPredicate = z.infer<typeof predicateSchema>;
26
- export declare function Predicates(dataContext?: DataContext): import("../orm").Table<{
27
- name: string;
28
- predicateId: string;
29
- description?: string | undefined;
30
- peerTypeId?: string | undefined;
31
- allowedSubjectValueTypes?: string[] | undefined;
32
- allowedObjectValueTypes?: string[] | undefined;
33
- }>;
34
- export {};
@@ -1,27 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Predicates = Predicates;
4
- const zod_1 = require("zod");
5
- const types_1 = require("../orm/types");
6
- const user_context_singleton_1 = require("../../context/user-context-singleton");
7
- const table_definitions_system_1 = require("../orm/table-definitions.system");
8
- const zod_types_1 = require("../../types/zod-types");
9
- const predicateSchema = zod_1.z.object({
10
- predicateId: zod_types_1.zodPeerId,
11
- name: zod_1.z.string().describe('The name of the predicate'),
12
- description: zod_1.z.string().optional().describe('The description of the predicate'),
13
- peerTypeId: zod_types_1.zodPeerId.optional().describe('The id of the value type to be included with the predicate'),
14
- allowedSubjectValueTypes: zod_types_1.zodPeerId.array().optional().describe('The ids of the types that are allowed types of the subject of the predicate value.'),
15
- allowedObjectValueTypes: zod_types_1.zodPeerId.array().optional().describe('The ids of the types that are allowed types of the object of the predicate value.'),
16
- });
17
- const metaData = {
18
- name: 'Predicates',
19
- description: "The the predicates in the system",
20
- primaryKeyName: 'predicateId',
21
- fields: (0, types_1.schemaToFields)(predicateSchema),
22
- iconClassName: 'bi bi-node-plus-fill',
23
- };
24
- (0, table_definitions_system_1.registerSystemTableDefinition)(metaData, predicateSchema);
25
- function Predicates(dataContext) {
26
- return (0, user_context_singleton_1.getTableContainer)(dataContext).getTable(metaData, predicateSchema);
27
- }
@@ -1,21 +0,0 @@
1
- import { z } from "zod";
2
- import type { DataContext } from "../../context/data-context";
3
- export declare const peerEventHandlerSchema: z.ZodObject<{
4
- peerEventHandlerId: z.ZodEffects<z.ZodString, string, string>;
5
- peerEventTypeId: z.ZodEffects<z.ZodString, string, string>;
6
- handlerWorkflowId: z.ZodEffects<z.ZodString, string, string>;
7
- }, "strip", z.ZodTypeAny, {
8
- peerEventTypeId: string;
9
- peerEventHandlerId: string;
10
- handlerWorkflowId: string;
11
- }, {
12
- peerEventTypeId: string;
13
- peerEventHandlerId: string;
14
- handlerWorkflowId: string;
15
- }>;
16
- export type IPeerEventHandler = z.infer<typeof peerEventHandlerSchema>;
17
- export declare function PeerEventHandlers(dataContext?: DataContext): import("../orm").Table<{
18
- peerEventTypeId: string;
19
- peerEventHandlerId: string;
20
- handlerWorkflowId: string;
21
- }>;
@@ -1,29 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.peerEventHandlerSchema = void 0;
4
- exports.PeerEventHandlers = PeerEventHandlers;
5
- const zod_1 = require("zod");
6
- const zod_types_1 = require("../../types/zod-types");
7
- const types_1 = require("../orm/types");
8
- const user_context_singleton_1 = require("../../context/user-context-singleton");
9
- const table_definitions_system_1 = require("../orm/table-definitions.system");
10
- exports.peerEventHandlerSchema = zod_1.z.object({
11
- peerEventHandlerId: zod_types_1.zodPeerId,
12
- peerEventTypeId: zod_types_1.zodPeerId.describe('The event type that will be handled'),
13
- handlerWorkflowId: zod_types_1.zodPeerId.describe('The workflow that will be triggered when this event occurs'),
14
- });
15
- const metaData = {
16
- name: 'PeerEventHandlers',
17
- description: 'The handlers registered for peer events',
18
- primaryKeyName: 'peerEventHandlerId',
19
- fields: (0, types_1.schemaToFields)(exports.peerEventHandlerSchema),
20
- indexes: [
21
- {
22
- fields: ['peerEventTypeId'],
23
- },
24
- ],
25
- };
26
- (0, table_definitions_system_1.registerSystemTableDefinition)(metaData, exports.peerEventHandlerSchema);
27
- function PeerEventHandlers(dataContext) {
28
- return (0, user_context_singleton_1.getTableContainer)(dataContext).getTable(metaData, exports.peerEventHandlerSchema);
29
- }
@@ -1,119 +0,0 @@
1
- import { z } from "zod";
2
- import type { DataContext } from "../../context/data-context";
3
- export declare const peerEventTypeSchema: z.ZodObject<{
4
- peerEventTypeId: z.ZodEffects<z.ZodString, string, string>;
5
- name: z.ZodString;
6
- description: z.ZodString;
7
- createdAt: z.ZodDefault<z.ZodDate>;
8
- schema: z.ZodObject<{
9
- type: z.ZodNativeEnum<typeof import("../tools").IOSchemaType>;
10
- fields: z.ZodDefault<z.ZodArray<z.ZodObject<{
11
- name: z.ZodString;
12
- description: z.ZodOptional<z.ZodString>;
13
- type: z.ZodNativeEnum<typeof import("../..").FieldType>;
14
- defaultValue: z.ZodOptional<z.ZodAny>;
15
- optional: z.ZodOptional<z.ZodBoolean>;
16
- isArray: z.ZodOptional<z.ZodBoolean>;
17
- subType: z.ZodOptional<z.ZodString>;
18
- }, "strip", z.ZodTypeAny, {
19
- name: string;
20
- type: import("../..").FieldType;
21
- optional?: boolean | undefined;
22
- description?: string | undefined;
23
- defaultValue?: any;
24
- isArray?: boolean | undefined;
25
- subType?: string | undefined;
26
- }, {
27
- name: string;
28
- type: import("../..").FieldType;
29
- optional?: boolean | undefined;
30
- description?: string | undefined;
31
- defaultValue?: any;
32
- isArray?: boolean | undefined;
33
- subType?: string | undefined;
34
- }>, "many">>;
35
- }, "strip", z.ZodTypeAny, {
36
- type: import("../tools").IOSchemaType;
37
- fields: {
38
- name: string;
39
- type: import("../..").FieldType;
40
- optional?: boolean | undefined;
41
- description?: string | undefined;
42
- defaultValue?: any;
43
- isArray?: boolean | undefined;
44
- subType?: string | undefined;
45
- }[];
46
- }, {
47
- type: import("../tools").IOSchemaType;
48
- fields?: {
49
- name: string;
50
- type: import("../..").FieldType;
51
- optional?: boolean | undefined;
52
- description?: string | undefined;
53
- defaultValue?: any;
54
- isArray?: boolean | undefined;
55
- subType?: string | undefined;
56
- }[] | undefined;
57
- }>;
58
- cronSchedule: z.ZodOptional<z.ZodString>;
59
- nextScheduledTime: z.ZodOptional<z.ZodNumber>;
60
- }, "strip", z.ZodTypeAny, {
61
- name: string;
62
- description: string;
63
- schema: {
64
- type: import("../tools").IOSchemaType;
65
- fields: {
66
- name: string;
67
- type: import("../..").FieldType;
68
- optional?: boolean | undefined;
69
- description?: string | undefined;
70
- defaultValue?: any;
71
- isArray?: boolean | undefined;
72
- subType?: string | undefined;
73
- }[];
74
- };
75
- peerEventTypeId: string;
76
- createdAt: Date;
77
- cronSchedule?: string | undefined;
78
- nextScheduledTime?: number | undefined;
79
- }, {
80
- name: string;
81
- description: string;
82
- schema: {
83
- type: import("../tools").IOSchemaType;
84
- fields?: {
85
- name: string;
86
- type: import("../..").FieldType;
87
- optional?: boolean | undefined;
88
- description?: string | undefined;
89
- defaultValue?: any;
90
- isArray?: boolean | undefined;
91
- subType?: string | undefined;
92
- }[] | undefined;
93
- };
94
- peerEventTypeId: string;
95
- createdAt?: Date | undefined;
96
- cronSchedule?: string | undefined;
97
- nextScheduledTime?: number | undefined;
98
- }>;
99
- export type IPeerEventType = z.infer<typeof peerEventTypeSchema>;
100
- export declare function PeerEventTypes(dataContext?: DataContext): import("../orm").Table<{
101
- name: string;
102
- description: string;
103
- schema: {
104
- type: import("../tools").IOSchemaType;
105
- fields: {
106
- name: string;
107
- type: import("../..").FieldType;
108
- optional?: boolean | undefined;
109
- description?: string | undefined;
110
- defaultValue?: any;
111
- isArray?: boolean | undefined;
112
- subType?: string | undefined;
113
- }[];
114
- };
115
- peerEventTypeId: string;
116
- createdAt: Date;
117
- cronSchedule?: string | undefined;
118
- nextScheduledTime?: number | undefined;
119
- }>;
@@ -1,30 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.peerEventTypeSchema = void 0;
4
- exports.PeerEventTypes = PeerEventTypes;
5
- const types_1 = require("../orm/types");
6
- const user_context_singleton_1 = require("../../context/user-context-singleton");
7
- const table_definitions_system_1 = require("../orm/table-definitions.system");
8
- const zod_1 = require("zod");
9
- const tools_1 = require("../tools");
10
- const zod_types_1 = require("../../types/zod-types");
11
- exports.peerEventTypeSchema = zod_1.z.object({
12
- peerEventTypeId: zod_types_1.zodPeerId,
13
- name: zod_1.z.string().describe('The name of the event'),
14
- description: zod_1.z.string().describe('The description of the event type and what it represents'),
15
- createdAt: zod_1.z.date().default(() => new Date()).describe('The date the event type was created'),
16
- schema: tools_1.ioSchema.describe('The schema of the event data'),
17
- cronSchedule: zod_1.z.string().optional().describe('The cron schedule for this event'),
18
- nextScheduledTime: zod_1.z.number().optional().describe('The next time this event is scheduled to run based on the cron schedule'),
19
- });
20
- const metaData = {
21
- name: 'PeerEventTypes',
22
- description: 'The types of events that are possible in this Peers network, what their schemas are, and what tools will be triggered, etc.',
23
- primaryKeyName: 'peerEventTypeId',
24
- fields: (0, types_1.schemaToFields)(exports.peerEventTypeSchema),
25
- iconClassName: 'bi bi-lightning-charge-fill',
26
- };
27
- (0, table_definitions_system_1.registerSystemTableDefinition)(metaData, exports.peerEventTypeSchema);
28
- function PeerEventTypes(dataContext) {
29
- return (0, user_context_singleton_1.getTableContainer)(dataContext).getTable(metaData, exports.peerEventTypeSchema);
30
- }
@@ -1,41 +0,0 @@
1
- import { z } from "zod";
2
- import type { DataContext } from "../../context/data-context";
3
- export declare const peerEventSchema: z.ZodObject<{
4
- peerEventId: z.ZodEffects<z.ZodString, string, string>;
5
- peerEventTypeId: z.ZodEffects<z.ZodString, string, string>;
6
- parentMessageId: z.ZodEffects<z.ZodString, string, string>;
7
- eventData: z.ZodObject<{}, "strip", z.ZodAny, z.objectOutputType<{}, z.ZodAny, "strip">, z.objectInputType<{}, z.ZodAny, "strip">>;
8
- createdAt: z.ZodDefault<z.ZodDate>;
9
- workflowRunsTriggered: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
10
- }, "strip", z.ZodTypeAny, {
11
- peerEventTypeId: string;
12
- createdAt: Date;
13
- parentMessageId: string;
14
- peerEventId: string;
15
- eventData: {} & {
16
- [k: string]: any;
17
- };
18
- workflowRunsTriggered?: string[] | undefined;
19
- }, {
20
- peerEventTypeId: string;
21
- parentMessageId: string;
22
- peerEventId: string;
23
- eventData: {} & {
24
- [k: string]: any;
25
- };
26
- createdAt?: Date | undefined;
27
- workflowRunsTriggered?: string[] | undefined;
28
- }>;
29
- type _IEvent = z.infer<typeof peerEventSchema>;
30
- export interface IPeerEvent<T = Record<string, any>> extends Omit<_IEvent, "eventData"> {
31
- eventData: T;
32
- }
33
- export interface IEmitPeerEventArgs {
34
- peerEventTypeId: string;
35
- eventData: Record<string, any>;
36
- channelOrThreadId?: string;
37
- assistantId?: string;
38
- }
39
- export declare function PeerEvents(dataContext?: DataContext): import("../..").Table<IPeerEvent<Record<string, any>>>;
40
- export declare function emitPeerEvent<T extends Record<string, any>>(args: IEmitPeerEventArgs): Promise<IPeerEvent<T>>;
41
- export {};
@@ -1,102 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.peerEventSchema = void 0;
4
- exports.PeerEvents = PeerEvents;
5
- exports.emitPeerEvent = emitPeerEvent;
6
- const zod_1 = require("zod");
7
- const mentions_1 = require("../../mentions");
8
- const zod_types_1 = require("../../types/zod-types");
9
- const utils_1 = require("../../utils");
10
- const messages_1 = require("../messages");
11
- const types_1 = require("../orm/types");
12
- const user_context_singleton_1 = require("../../context/user-context-singleton");
13
- const table_definitions_system_1 = require("../orm/table-definitions.system");
14
- const users_1 = require("../users");
15
- const workflow_runs_1 = require("../workflow-runs");
16
- const peer_event_handlers_1 = require("./peer-event-handlers");
17
- const peer_event_types_1 = require("./peer-event-types");
18
- const __1 = require("../..");
19
- exports.peerEventSchema = zod_1.z.object({
20
- peerEventId: zod_types_1.zodPeerId,
21
- peerEventTypeId: zod_types_1.zodPeerId.describe('The type of event'),
22
- parentMessageId: zod_types_1.zodPeerId.describe('The message that this event will be emitted in the context of'),
23
- eventData: zod_types_1.zodAnyObject.describe('The data of the event as defined by the event type schema'),
24
- createdAt: zod_1.z.date().default(() => new Date()).describe('The date the event was created'),
25
- workflowRunsTriggered: zod_1.z.string().array().optional().describe('The workflows that were triggered by this event'),
26
- });
27
- const metaData = {
28
- name: 'PeerEvents',
29
- description: 'The events that have occurred in the Peers network',
30
- primaryKeyName: 'peerEventId',
31
- fields: (0, types_1.schemaToFields)(exports.peerEventSchema),
32
- };
33
- (0, table_definitions_system_1.registerSystemTableDefinition)(metaData, exports.peerEventSchema);
34
- function PeerEvents(dataContext) {
35
- return (0, user_context_singleton_1.getTableContainer)(dataContext).getTable(metaData, exports.peerEventSchema);
36
- }
37
- async function emitPeerEvent(args) {
38
- const { peerEventTypeId, channelOrThreadId: groupOrChannelId } = args;
39
- let { eventData } = args;
40
- const eventType = await (0, peer_event_types_1.PeerEventTypes)().get(peerEventTypeId);
41
- if (!eventType) {
42
- throw new Error(`Event type ${peerEventTypeId} not found`);
43
- }
44
- const schema = (0, types_1.fieldsToSchema)(eventType.schema.fields);
45
- const defaults = {};
46
- for (const field of eventType.schema.fields) {
47
- const zodField = schema.shape[field.name];
48
- const value = zodField.safeParse(eventData[field.name]);
49
- if (value.success) {
50
- defaults[field.name] = value.data;
51
- }
52
- }
53
- eventData = {
54
- ...defaults,
55
- ...eventData
56
- };
57
- schema.parse(eventData);
58
- const me = await (0, users_1.getMe)();
59
- const channelOrThreadId = groupOrChannelId || me.userId;
60
- const assistantId = args.assistantId
61
- || (await (0, __1.getPrimaryAssistant)()).assistantId
62
- || __1.defaultAssistantId;
63
- const peerEventId = (0, utils_1.newid)();
64
- const eventMention = (0, mentions_1.formatMention)({ kind: 'event', id: peerEventTypeId, name: eventType.name });
65
- // TODO get better link to event instance
66
- const eventLink = ''; //`[logs](#events/${peerEventTypeId})`;
67
- const handlers = await (0, peer_event_handlers_1.PeerEventHandlers)().list({ peerEventTypeId });
68
- let handlerStr = '';
69
- if (handlers.length === 0) {
70
- handlerStr = 'No handlers subscribed to this event type';
71
- }
72
- else if (handlers.length === 1) {
73
- handlerStr = `triggering 1 handler`;
74
- }
75
- else {
76
- handlerStr = `triggering ${handlers.length} handlers`;
77
- }
78
- const eventMessage = await (0, messages_1.sendMessage)({
79
- channelOrThreadIdOrWorkflowRunId: channelOrThreadId,
80
- messageContent: `Emitting ${eventMention} ${eventLink} - ${handlerStr}`,
81
- assistantId,
82
- });
83
- const event = {
84
- peerEventId,
85
- peerEventTypeId,
86
- eventData: eventData,
87
- createdAt: new Date(),
88
- parentMessageId: eventMessage.messageId,
89
- };
90
- await PeerEvents().insert(event);
91
- for (const handler of handlers) {
92
- const workflowId = handler.handlerWorkflowId;
93
- (0, workflow_runs_1.runWorkflow)({
94
- workflowId,
95
- parentMessageIdOrChannelIdOrGroupId: eventMessage.messageId,
96
- vars: {
97
- ...eventData
98
- }
99
- });
100
- }
101
- return event;
102
- }