@peers-app/peers-sdk 0.8.23 → 0.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/context/user-context-singleton.d.ts +1 -0
- package/dist/context/user-context-singleton.js +8 -0
- package/dist/context/user-context.js +3 -0
- package/dist/data/assistants.d.ts +1 -1
- package/dist/data/assistants.js +1 -1
- package/dist/data/change-tracking.d.ts +8 -0
- package/dist/data/change-tracking.js +18 -0
- package/dist/data/channels.d.ts +2 -2
- package/dist/data/channels.js +3 -2
- package/dist/data/data-locks.test.js +8 -4
- package/dist/data/devices.d.ts +2 -2
- package/dist/data/devices.js +3 -2
- package/dist/data/embeddings.d.ts +1 -1
- package/dist/data/embeddings.js +2 -1
- package/dist/data/files/file.types.d.ts +2 -2
- package/dist/data/files/file.types.js +3 -2
- package/dist/data/groups.d.ts +1 -1
- package/dist/data/groups.js +1 -1
- package/dist/data/index.d.ts +1 -0
- package/dist/data/index.js +1 -0
- package/dist/data/messages.d.ts +5 -5
- package/dist/data/messages.js +5 -5
- package/dist/data/orm/dependency-injection.test.js +5 -2
- package/dist/data/orm/sql-db.d.ts +3 -1
- package/dist/data/orm/sql.data-source.test.js +5 -3
- package/dist/data/orm/table-container.d.ts +33 -0
- package/dist/data/orm/table-container.js +202 -8
- package/dist/data/orm/table-container.test.d.ts +1 -0
- package/dist/data/orm/table-container.test.js +163 -0
- package/dist/data/orm/table.d.ts +1 -0
- package/dist/data/orm/table.js +14 -2
- package/dist/data/orm/types.d.ts +2 -1
- package/dist/data/orm/types.js +14 -5
- package/dist/data/orm/types.test.js +136 -1
- package/dist/data/packages.d.ts +5 -5
- package/dist/data/packages.js +6 -5
- package/dist/data/peer-events/peer-event-handlers.d.ts +3 -3
- package/dist/data/peer-events/peer-event-handlers.js +4 -3
- package/dist/data/peer-events/peer-event-types.d.ts +1 -1
- package/dist/data/peer-events/peer-event-types.js +2 -1
- package/dist/data/persistent-vars.d.ts +1 -1
- package/dist/data/persistent-vars.js +2 -1
- package/dist/data/table-definitions-table.d.ts +31 -0
- package/dist/data/table-definitions-table.js +28 -0
- package/dist/data/tool-tests.d.ts +2 -2
- package/dist/data/tool-tests.js +3 -2
- package/dist/data/tools.d.ts +1 -1
- package/dist/data/tools.js +2 -1
- package/dist/data/user-trust-levels.d.ts +1 -1
- package/dist/data/user-trust-levels.js +2 -1
- package/dist/data/users.d.ts +1 -2
- package/dist/data/users.js +3 -4
- package/dist/data/workflow-logs.d.ts +2 -2
- package/dist/data/workflow-runs.d.ts +2 -2
- package/dist/keys.js +7 -1
- package/dist/types/workflow.d.ts +7 -7
- package/dist/types/workflow.js +6 -5
- package/dist/types/zod-types.js +2 -0
- package/package.json +1 -1
|
@@ -4,6 +4,7 @@ const zod_1 = require("zod");
|
|
|
4
4
|
const types_1 = require("./types");
|
|
5
5
|
const field_type_1 = require("../../types/field-type");
|
|
6
6
|
const utils_1 = require("../../utils");
|
|
7
|
+
const zod_types_1 = require("../../types/zod-types");
|
|
7
8
|
describe('types', () => {
|
|
8
9
|
it('fieldsToSchema', () => {
|
|
9
10
|
const someDate = new Date();
|
|
@@ -57,7 +58,7 @@ describe('types', () => {
|
|
|
57
58
|
});
|
|
58
59
|
const groupFields = (0, types_1.schemaToFields)(groupSchema);
|
|
59
60
|
const groupFieldsExpected = [
|
|
60
|
-
{ name: 'groupId', description: 'The id of the group', type: field_type_1.FieldType.
|
|
61
|
+
{ name: 'groupId', description: 'The id of the group', type: field_type_1.FieldType.string },
|
|
61
62
|
{ name: 'groupName', description: 'The name of the group', type: field_type_1.FieldType.string },
|
|
62
63
|
{ name: 'groupDescription', description: 'The description of the group', type: field_type_1.FieldType.string },
|
|
63
64
|
{ name: 'createdAt', description: 'The date the group was created', type: field_type_1.FieldType.Date, }, //defaultValue: () => new Date() },
|
|
@@ -68,4 +69,138 @@ describe('types', () => {
|
|
|
68
69
|
];
|
|
69
70
|
expect(groupFields).toEqual(groupFieldsExpected);
|
|
70
71
|
});
|
|
72
|
+
it('schemaToFields should detect zodPeerId as FieldType.id', () => {
|
|
73
|
+
const schema = zod_1.z.object({
|
|
74
|
+
recordId: zod_types_1.zodPeerId.describe('A peer id field'),
|
|
75
|
+
optionalRef: zod_types_1.zodPeerId.optional().describe('An optional peer id'),
|
|
76
|
+
});
|
|
77
|
+
const fields = (0, types_1.schemaToFields)(schema);
|
|
78
|
+
expect(fields.find(f => f.name === 'recordId').type).toBe(field_type_1.FieldType.id);
|
|
79
|
+
expect(fields.find(f => f.name === 'optionalRef').type).toBe(field_type_1.FieldType.id);
|
|
80
|
+
});
|
|
81
|
+
it('schemaToFields should NOT classify plain z.string() as id just because name ends in Id', () => {
|
|
82
|
+
const schema = zod_1.z.object({
|
|
83
|
+
externalId: zod_1.z.string().describe('An external system identifier'),
|
|
84
|
+
channelId: zod_1.z.string().describe('A channel reference'),
|
|
85
|
+
name: zod_1.z.string().describe('A plain string'),
|
|
86
|
+
});
|
|
87
|
+
const fields = (0, types_1.schemaToFields)(schema);
|
|
88
|
+
expect(fields.find(f => f.name === 'externalId').type).toBe(field_type_1.FieldType.string);
|
|
89
|
+
expect(fields.find(f => f.name === 'channelId').type).toBe(field_type_1.FieldType.string);
|
|
90
|
+
expect(fields.find(f => f.name === 'name').type).toBe(field_type_1.FieldType.string);
|
|
91
|
+
});
|
|
92
|
+
it('schemaToFields should NOT classify a non-id string refinement as FieldType.id', () => {
|
|
93
|
+
const zodEmail = zod_1.z.string().refine(val => val.includes('@'), { message: 'Must be an email' });
|
|
94
|
+
const zodNonEmpty = zod_1.z.string().refine(val => val.length > 0, { message: 'Must not be empty' });
|
|
95
|
+
const schema = zod_1.z.object({
|
|
96
|
+
email: zodEmail.describe('An email address'),
|
|
97
|
+
requiredField: zodNonEmpty.describe('A non-empty string'),
|
|
98
|
+
peerId: zod_types_1.zodPeerId.describe('A real peer id'),
|
|
99
|
+
});
|
|
100
|
+
const fields = (0, types_1.schemaToFields)(schema);
|
|
101
|
+
expect(fields.find(f => f.name === 'email').type).toBe(field_type_1.FieldType.string);
|
|
102
|
+
expect(fields.find(f => f.name === 'requiredField').type).toBe(field_type_1.FieldType.string);
|
|
103
|
+
expect(fields.find(f => f.name === 'peerId').type).toBe(field_type_1.FieldType.id);
|
|
104
|
+
});
|
|
105
|
+
it('fieldsToSchema should merge with optional code schema for most-constrained validation', () => {
|
|
106
|
+
const codeSchema = zod_1.z.object({
|
|
107
|
+
recordId: zod_types_1.zodPeerId.describe('A peer id'),
|
|
108
|
+
label: zod_1.z.string().min(1).describe('Non-empty label'),
|
|
109
|
+
});
|
|
110
|
+
const fields = [
|
|
111
|
+
{ name: 'recordId', description: 'A peer id', type: field_type_1.FieldType.string },
|
|
112
|
+
{ name: 'label', description: 'Non-empty label', type: field_type_1.FieldType.string },
|
|
113
|
+
];
|
|
114
|
+
const mergedSchema = (0, types_1.fieldsToSchema)(fields, codeSchema);
|
|
115
|
+
const validId = (0, utils_1.newid)();
|
|
116
|
+
// Valid peer id should pass the merged schema
|
|
117
|
+
expect(() => mergedSchema.parse({ recordId: validId, label: 'hello' })).not.toThrow();
|
|
118
|
+
// Empty string should fail: the code schema's zodPeerId rejects it
|
|
119
|
+
expect(() => mergedSchema.parse({ recordId: '', label: 'hello' })).toThrow();
|
|
120
|
+
// Empty label should fail: the code schema's .min(1) rejects it
|
|
121
|
+
expect(() => mergedSchema.parse({ recordId: validId, label: '' })).toThrow();
|
|
122
|
+
});
|
|
123
|
+
it('round-trip: fieldsToSchema id fields should survive schemaToFields detection', () => {
|
|
124
|
+
// fieldsToSchema creates z.string().refine(isid) for FieldType.id fields.
|
|
125
|
+
// schemaToFields should detect that refinement as FieldType.id so round-trips are consistent.
|
|
126
|
+
const fields = [
|
|
127
|
+
{ name: 'recordId', description: 'A peer id', type: field_type_1.FieldType.id },
|
|
128
|
+
{ name: 'label', description: 'A label', type: field_type_1.FieldType.string },
|
|
129
|
+
];
|
|
130
|
+
const schema = (0, types_1.fieldsToSchema)(fields);
|
|
131
|
+
const roundTrippedFields = (0, types_1.schemaToFields)(schema);
|
|
132
|
+
expect(roundTrippedFields.find(f => f.name === 'recordId').type).toBe(field_type_1.FieldType.id);
|
|
133
|
+
expect(roundTrippedFields.find(f => f.name === 'label').type).toBe(field_type_1.FieldType.string);
|
|
134
|
+
});
|
|
135
|
+
it('fieldsToSchema merge should handle optional zodPeerId fields correctly', () => {
|
|
136
|
+
const codeSchema = zod_1.z.object({
|
|
137
|
+
ownerId: zod_types_1.zodPeerId.describe('The owner'),
|
|
138
|
+
referrerId: zod_types_1.zodPeerId.optional().describe('Optional referrer'),
|
|
139
|
+
});
|
|
140
|
+
const fields = [
|
|
141
|
+
{ name: 'ownerId', description: 'The owner', type: field_type_1.FieldType.string },
|
|
142
|
+
{ name: 'referrerId', description: 'Optional referrer', type: field_type_1.FieldType.string, optional: true },
|
|
143
|
+
];
|
|
144
|
+
const mergedSchema = (0, types_1.fieldsToSchema)(fields, codeSchema);
|
|
145
|
+
const validId = (0, utils_1.newid)();
|
|
146
|
+
const validId2 = (0, utils_1.newid)();
|
|
147
|
+
// Both provided and valid
|
|
148
|
+
expect(() => mergedSchema.parse({ ownerId: validId, referrerId: validId2 })).not.toThrow();
|
|
149
|
+
// Optional field omitted
|
|
150
|
+
expect(() => mergedSchema.parse({ ownerId: validId })).not.toThrow();
|
|
151
|
+
// Optional field present but invalid
|
|
152
|
+
expect(() => mergedSchema.parse({ ownerId: validId, referrerId: 'not-a-valid-id' })).toThrow();
|
|
153
|
+
// Required field missing
|
|
154
|
+
expect(() => mergedSchema.parse({ referrerId: validId })).toThrow();
|
|
155
|
+
// Required field invalid
|
|
156
|
+
expect(() => mergedSchema.parse({ ownerId: 'bad', referrerId: validId })).toThrow();
|
|
157
|
+
});
|
|
158
|
+
it('initRecord pattern: code schema defaults should work even after JSON round-trip of fields', () => {
|
|
159
|
+
const codeSchema = zod_1.z.object({
|
|
160
|
+
recordId: zod_types_1.zodPeerId.describe('A peer id'),
|
|
161
|
+
label: zod_1.z.string().default('untitled').describe('A label with default'),
|
|
162
|
+
createdAt: zod_1.z.date().default(() => new Date()).describe('Date with factory default'),
|
|
163
|
+
count: zod_1.z.number().default(0).describe('A count with default'),
|
|
164
|
+
});
|
|
165
|
+
// Simulate the real flow: code schema -> fields -> JSON (sync) -> parse back
|
|
166
|
+
const fields = (0, types_1.schemaToFields)(codeSchema);
|
|
167
|
+
const fieldsAfterJson = JSON.parse(JSON.stringify(fields));
|
|
168
|
+
// Function defaults like () => new Date() are lost through JSON
|
|
169
|
+
const mergedSchema = (0, types_1.fieldsToSchema)(fieldsAfterJson, codeSchema);
|
|
170
|
+
const validId = (0, utils_1.newid)();
|
|
171
|
+
const data = { recordId: validId };
|
|
172
|
+
// Simulate what Table.initRecord does: apply code schema first for defaults,
|
|
173
|
+
// then fall back to merged schema
|
|
174
|
+
const defaults = {};
|
|
175
|
+
const shape = codeSchema.shape;
|
|
176
|
+
for (const field of fieldsAfterJson) {
|
|
177
|
+
if (shape[field.name]) {
|
|
178
|
+
const codeValue = shape[field.name].safeParse(data[field.name]);
|
|
179
|
+
if (codeValue.success) {
|
|
180
|
+
defaults[field.name] = codeValue.data;
|
|
181
|
+
continue;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
const zodField = mergedSchema.shape[field.name];
|
|
185
|
+
const value = zodField.safeParse(data[field.name]);
|
|
186
|
+
if (value.success) {
|
|
187
|
+
defaults[field.name] = value.data;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
const result = { ...defaults, ...data };
|
|
191
|
+
expect(result.label).toBe('untitled');
|
|
192
|
+
expect(result.createdAt).toBeInstanceOf(Date);
|
|
193
|
+
expect(result.count).toBe(0);
|
|
194
|
+
expect(result.recordId).toBe(validId);
|
|
195
|
+
});
|
|
196
|
+
it('fieldsToSchema without code schema should work as before', () => {
|
|
197
|
+
const fields = [
|
|
198
|
+
{ name: 'recordId', description: 'A peer id', type: field_type_1.FieldType.id },
|
|
199
|
+
{ name: 'label', description: 'A label', type: field_type_1.FieldType.string },
|
|
200
|
+
];
|
|
201
|
+
const schema = (0, types_1.fieldsToSchema)(fields);
|
|
202
|
+
const validId = (0, utils_1.newid)();
|
|
203
|
+
expect(() => schema.parse({ recordId: validId, label: 'hello' })).not.toThrow();
|
|
204
|
+
expect(() => schema.parse({ recordId: '', label: 'hello' })).toThrow();
|
|
205
|
+
});
|
|
71
206
|
});
|
package/dist/data/packages.d.ts
CHANGED
|
@@ -3,10 +3,10 @@ import type { DataContext } from "../context/data-context";
|
|
|
3
3
|
import type { ISaveOptions } from "./orm/data-query";
|
|
4
4
|
import { Table } from "./orm/table";
|
|
5
5
|
declare const schema: z.ZodObject<{
|
|
6
|
-
packageId: z.ZodString
|
|
6
|
+
packageId: z.ZodEffects<z.ZodString, string, string>;
|
|
7
7
|
name: z.ZodString;
|
|
8
8
|
description: z.ZodString;
|
|
9
|
-
createdBy: z.ZodString
|
|
9
|
+
createdBy: z.ZodEffects<z.ZodString, string, string>;
|
|
10
10
|
localPath: z.ZodString;
|
|
11
11
|
disabled: z.ZodOptional<z.ZodBoolean>;
|
|
12
12
|
remoteRepo: z.ZodOptional<z.ZodString>;
|
|
@@ -26,11 +26,11 @@ declare const schema: z.ZodObject<{
|
|
|
26
26
|
navigationPath: string;
|
|
27
27
|
displayName?: string | undefined;
|
|
28
28
|
}>, "many">>;
|
|
29
|
-
packageBundleFileId: z.ZodString
|
|
29
|
+
packageBundleFileId: z.ZodEffects<z.ZodString, string, string>;
|
|
30
30
|
packageBundleFileHash: z.ZodString;
|
|
31
|
-
routesBundleFileId: z.ZodOptional<z.ZodString
|
|
31
|
+
routesBundleFileId: z.ZodOptional<z.ZodEffects<z.ZodString, string, string>>;
|
|
32
32
|
routesBundleFileHash: z.ZodOptional<z.ZodString>;
|
|
33
|
-
uiBundleFileId: z.ZodOptional<z.ZodString
|
|
33
|
+
uiBundleFileId: z.ZodOptional<z.ZodEffects<z.ZodString, string, string>>;
|
|
34
34
|
uiBundleFileHash: z.ZodOptional<z.ZodString>;
|
|
35
35
|
signature: z.ZodString;
|
|
36
36
|
}, "strip", z.ZodTypeAny, {
|
package/dist/data/packages.js
CHANGED
|
@@ -39,6 +39,7 @@ exports.Packages = Packages;
|
|
|
39
39
|
const zod_1 = require("zod");
|
|
40
40
|
const context_1 = require("../context");
|
|
41
41
|
const app_nav_1 = require("../types/app-nav");
|
|
42
|
+
const zod_types_1 = require("../types/zod-types");
|
|
42
43
|
const decorators_1 = require("./orm/decorators");
|
|
43
44
|
const table_1 = require("./orm/table");
|
|
44
45
|
const table_definitions_system_1 = require("./orm/table-definitions.system");
|
|
@@ -46,19 +47,19 @@ const types_1 = require("./orm/types");
|
|
|
46
47
|
const package_permissions_1 = require("./package-permissions");
|
|
47
48
|
const persistent_vars_1 = require("./persistent-vars");
|
|
48
49
|
const schema = zod_1.z.object({
|
|
49
|
-
packageId:
|
|
50
|
+
packageId: zod_types_1.zodPeerId,
|
|
50
51
|
name: zod_1.z.string(),
|
|
51
52
|
description: zod_1.z.string(),
|
|
52
|
-
createdBy:
|
|
53
|
+
createdBy: zod_types_1.zodPeerId.describe('The user who created the package'),
|
|
53
54
|
localPath: zod_1.z.string().describe('The local path where the package is stored'),
|
|
54
55
|
disabled: zod_1.z.boolean().optional().describe("Whether the package's components should be loaded and included in the app runtime"),
|
|
55
56
|
remoteRepo: zod_1.z.string().optional().describe('The remote repository where the package is stored'),
|
|
56
57
|
appNavs: app_nav_1.appNavSchema.array().optional().describe('The app navigation items that this package provides'),
|
|
57
|
-
packageBundleFileId:
|
|
58
|
+
packageBundleFileId: zod_types_1.zodPeerId.describe('File ID of the package bundle (required)'),
|
|
58
59
|
packageBundleFileHash: zod_1.z.string().describe('Hash of the package bundle file (required)'),
|
|
59
|
-
routesBundleFileId:
|
|
60
|
+
routesBundleFileId: zod_types_1.zodPeerId.optional().describe('File ID of the routes bundle (optional)'),
|
|
60
61
|
routesBundleFileHash: zod_1.z.string().optional().describe('Hash of the routes bundle (optional)'),
|
|
61
|
-
uiBundleFileId:
|
|
62
|
+
uiBundleFileId: zod_types_1.zodPeerId.optional().describe('File ID of the UI bundle (optional)'),
|
|
62
63
|
uiBundleFileHash: zod_1.z.string().optional().describe('Hash of the UI bundle (optional)'),
|
|
63
64
|
signature: zod_1.z.string().describe('The signed hash of this data excluding the signature itself'),
|
|
64
65
|
});
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import type { DataContext } from "../../context/data-context";
|
|
3
3
|
export declare const peerEventHandlerSchema: z.ZodObject<{
|
|
4
|
-
peerEventHandlerId: z.ZodString
|
|
5
|
-
peerEventTypeId: z.ZodString
|
|
6
|
-
handlerWorkflowId: z.ZodString
|
|
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
7
|
}, "strip", z.ZodTypeAny, {
|
|
8
8
|
peerEventTypeId: string;
|
|
9
9
|
peerEventHandlerId: string;
|
|
@@ -3,13 +3,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.peerEventHandlerSchema = void 0;
|
|
4
4
|
exports.PeerEventHandlers = PeerEventHandlers;
|
|
5
5
|
const zod_1 = require("zod");
|
|
6
|
+
const zod_types_1 = require("../../types/zod-types");
|
|
6
7
|
const types_1 = require("../orm/types");
|
|
7
8
|
const user_context_singleton_1 = require("../../context/user-context-singleton");
|
|
8
9
|
const table_definitions_system_1 = require("../orm/table-definitions.system");
|
|
9
10
|
exports.peerEventHandlerSchema = zod_1.z.object({
|
|
10
|
-
peerEventHandlerId:
|
|
11
|
-
peerEventTypeId:
|
|
12
|
-
handlerWorkflowId:
|
|
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'),
|
|
13
14
|
});
|
|
14
15
|
const metaData = {
|
|
15
16
|
name: 'PeerEventHandlers',
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import type { DataContext } from "../../context/data-context";
|
|
3
3
|
export declare const peerEventTypeSchema: z.ZodObject<{
|
|
4
|
-
peerEventTypeId: z.ZodString
|
|
4
|
+
peerEventTypeId: z.ZodEffects<z.ZodString, string, string>;
|
|
5
5
|
name: z.ZodString;
|
|
6
6
|
description: z.ZodString;
|
|
7
7
|
createdAt: z.ZodDefault<z.ZodDate>;
|
|
@@ -7,8 +7,9 @@ const user_context_singleton_1 = require("../../context/user-context-singleton")
|
|
|
7
7
|
const table_definitions_system_1 = require("../orm/table-definitions.system");
|
|
8
8
|
const zod_1 = require("zod");
|
|
9
9
|
const tools_1 = require("../tools");
|
|
10
|
+
const zod_types_1 = require("../../types/zod-types");
|
|
10
11
|
exports.peerEventTypeSchema = zod_1.z.object({
|
|
11
|
-
peerEventTypeId:
|
|
12
|
+
peerEventTypeId: zod_types_1.zodPeerId,
|
|
12
13
|
name: zod_1.z.string().describe('The name of the event'),
|
|
13
14
|
description: zod_1.z.string().describe('The description of the event type and what it represents'),
|
|
14
15
|
createdAt: zod_1.z.date().default(() => new Date()).describe('The date the event type was created'),
|
|
@@ -12,7 +12,7 @@ import { ISaveOptions } from "./orm";
|
|
|
12
12
|
import { Table } from "./orm/table";
|
|
13
13
|
import { ITableMetaData } from "./orm/types";
|
|
14
14
|
declare const schema: z.ZodObject<{
|
|
15
|
-
persistentVarId: z.ZodString
|
|
15
|
+
persistentVarId: z.ZodEffects<z.ZodString, string, string>;
|
|
16
16
|
name: z.ZodString;
|
|
17
17
|
scope: z.ZodEnum<["device", "user", "group", "groupDevice", "groupUser"]>;
|
|
18
18
|
value: z.ZodObject<{
|
|
@@ -19,12 +19,13 @@ const zod_1 = require("zod");
|
|
|
19
19
|
const user_context_singleton_1 = require("../context/user-context-singleton");
|
|
20
20
|
const observable_1 = require("../observable");
|
|
21
21
|
const rpc_types_1 = require("../rpc-types");
|
|
22
|
+
const zod_types_1 = require("../types/zod-types");
|
|
22
23
|
const utils_1 = require("../utils");
|
|
23
24
|
const table_1 = require("./orm/table");
|
|
24
25
|
const table_definitions_system_1 = require("./orm/table-definitions.system");
|
|
25
26
|
const types_1 = require("./orm/types");
|
|
26
27
|
const schema = zod_1.z.object({
|
|
27
|
-
persistentVarId:
|
|
28
|
+
persistentVarId: zod_types_1.zodPeerId,
|
|
28
29
|
name: zod_1.z.string(),
|
|
29
30
|
scope: zod_1.z.enum(['device', 'user', 'group', 'groupDevice', 'groupUser']),
|
|
30
31
|
value: zod_1.z.object({
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import type { DataContext } from '../context/data-context';
|
|
3
|
+
export declare const tableDefinitionRecordSchema: z.ZodObject<{
|
|
4
|
+
tableId: z.ZodString;
|
|
5
|
+
name: z.ZodString;
|
|
6
|
+
metaData: z.ZodObject<{}, "strip", z.ZodAny, z.objectOutputType<{}, z.ZodAny, "strip">, z.objectInputType<{}, z.ZodAny, "strip">>;
|
|
7
|
+
versionNumber: z.ZodDefault<z.ZodNumber>;
|
|
8
|
+
}, "strip", z.ZodTypeAny, {
|
|
9
|
+
name: string;
|
|
10
|
+
tableId: string;
|
|
11
|
+
metaData: {} & {
|
|
12
|
+
[k: string]: any;
|
|
13
|
+
};
|
|
14
|
+
versionNumber: number;
|
|
15
|
+
}, {
|
|
16
|
+
name: string;
|
|
17
|
+
tableId: string;
|
|
18
|
+
metaData: {} & {
|
|
19
|
+
[k: string]: any;
|
|
20
|
+
};
|
|
21
|
+
versionNumber?: number | undefined;
|
|
22
|
+
}>;
|
|
23
|
+
export type ITableDefinitionRecord = z.infer<typeof tableDefinitionRecordSchema>;
|
|
24
|
+
export declare function TableDefinitions(dataContext?: DataContext): import("./orm").Table<{
|
|
25
|
+
name: string;
|
|
26
|
+
tableId: string;
|
|
27
|
+
metaData: {} & {
|
|
28
|
+
[k: string]: any;
|
|
29
|
+
};
|
|
30
|
+
versionNumber: number;
|
|
31
|
+
}>;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.tableDefinitionRecordSchema = void 0;
|
|
4
|
+
exports.TableDefinitions = TableDefinitions;
|
|
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.tableDefinitionRecordSchema = zod_1.z.object({
|
|
11
|
+
tableId: zod_1.z.string().describe('Primary key - same as ITableMetaData.tableId'),
|
|
12
|
+
name: zod_1.z.string().describe('Table name'),
|
|
13
|
+
metaData: zod_types_1.zodAnyObject.describe('Full ITableMetaData object serialized as JSON'),
|
|
14
|
+
versionNumber: zod_1.z.number().default(0).describe('Version number set by the developer in the table definition; higher value wins during sync'),
|
|
15
|
+
});
|
|
16
|
+
const metaData = {
|
|
17
|
+
name: 'TableDefinitions',
|
|
18
|
+
description: 'Stores table schemas as tracked data so peers can learn about table definitions without needing the full package installed',
|
|
19
|
+
primaryKeyName: 'tableId',
|
|
20
|
+
fields: (0, types_1.schemaToFields)(exports.tableDefinitionRecordSchema),
|
|
21
|
+
indexes: [
|
|
22
|
+
{ fields: ['name'] },
|
|
23
|
+
],
|
|
24
|
+
};
|
|
25
|
+
(0, table_definitions_system_1.registerSystemTableDefinition)(metaData, exports.tableDefinitionRecordSchema);
|
|
26
|
+
function TableDefinitions(dataContext) {
|
|
27
|
+
return (0, user_context_singleton_1.getTableContainer)(dataContext).getTable(metaData, exports.tableDefinitionRecordSchema);
|
|
28
|
+
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import type { DataContext } from "../context/data-context";
|
|
3
3
|
export declare const toolTestSchema: z.ZodObject<{
|
|
4
|
-
toolTestId: z.ZodString
|
|
5
|
-
toolId: z.ZodString
|
|
4
|
+
toolTestId: z.ZodEffects<z.ZodString, string, string>;
|
|
5
|
+
toolId: z.ZodEffects<z.ZodString, string, string>;
|
|
6
6
|
description: z.ZodString;
|
|
7
7
|
code: z.ZodDefault<z.ZodString>;
|
|
8
8
|
input: z.ZodAny;
|
package/dist/data/tool-tests.js
CHANGED
|
@@ -3,12 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.toolTestSchema = void 0;
|
|
4
4
|
exports.ToolTests = ToolTests;
|
|
5
5
|
const zod_1 = require("zod");
|
|
6
|
+
const zod_types_1 = require("../types/zod-types");
|
|
6
7
|
const types_1 = require("./orm/types");
|
|
7
8
|
const user_context_singleton_1 = require("../context/user-context-singleton");
|
|
8
9
|
const table_definitions_system_1 = require("./orm/table-definitions.system");
|
|
9
10
|
exports.toolTestSchema = zod_1.z.object({
|
|
10
|
-
toolTestId:
|
|
11
|
-
toolId:
|
|
11
|
+
toolTestId: zod_types_1.zodPeerId,
|
|
12
|
+
toolId: zod_types_1.zodPeerId,
|
|
12
13
|
description: zod_1.z.string(),
|
|
13
14
|
code: zod_1.z.string().default(''),
|
|
14
15
|
input: zod_1.z.any(),
|
package/dist/data/tools.d.ts
CHANGED
|
@@ -58,7 +58,7 @@ export declare const ioSchema: z.ZodObject<{
|
|
|
58
58
|
}>;
|
|
59
59
|
export type IOSchema = z.infer<typeof ioSchema>;
|
|
60
60
|
export declare const toolSchema: z.ZodObject<{
|
|
61
|
-
toolId: z.ZodString
|
|
61
|
+
toolId: z.ZodEffects<z.ZodString, string, string>;
|
|
62
62
|
name: z.ZodString;
|
|
63
63
|
usageDescription: z.ZodString;
|
|
64
64
|
detailedDescription: z.ZodOptional<z.ZodString>;
|
package/dist/data/tools.js
CHANGED
|
@@ -4,6 +4,7 @@ exports.toolSchema = exports.ioSchema = exports.IOSchemaType = void 0;
|
|
|
4
4
|
exports.Tools = Tools;
|
|
5
5
|
const zod_1 = require("zod");
|
|
6
6
|
const field_type_1 = require("../types/field-type");
|
|
7
|
+
const zod_types_1 = require("../types/zod-types");
|
|
7
8
|
const types_1 = require("./orm/types");
|
|
8
9
|
const user_context_singleton_1 = require("../context/user-context-singleton");
|
|
9
10
|
const table_definitions_system_1 = require("./orm/table-definitions.system");
|
|
@@ -19,7 +20,7 @@ exports.ioSchema = zod_1.z.object({
|
|
|
19
20
|
fields: field_type_1.fieldSchema.array().default([]),
|
|
20
21
|
});
|
|
21
22
|
exports.toolSchema = zod_1.z.object({
|
|
22
|
-
toolId:
|
|
23
|
+
toolId: zod_types_1.zodPeerId,
|
|
23
24
|
name: zod_1.z.string().describe('The name of the tool'),
|
|
24
25
|
usageDescription: zod_1.z.string().describe('A description of the what the tool does and how to use it. This is used by the AI to reason about the tool at runtime and in the middle of performing tasks.'),
|
|
25
26
|
detailedDescription: zod_1.z.string().optional().describe('A full description of the tool which may include examples, references, screenshots, etc. This is intended for humans and AI to decide if this is a tool they want to include in their toolbox while preparing to work on tasks.'),
|
|
@@ -9,7 +9,7 @@ import { TrustLevel } from "../device/socket.type";
|
|
|
9
9
|
* Each context can maintain its own trust assessment of other users.
|
|
10
10
|
*/
|
|
11
11
|
export declare const userTrustLevelSchema: z.ZodObject<{
|
|
12
|
-
userId: z.ZodString
|
|
12
|
+
userId: z.ZodEffects<z.ZodString, string, string>;
|
|
13
13
|
trustLevel: z.ZodNativeEnum<typeof TrustLevel>;
|
|
14
14
|
assignedAt: z.ZodOptional<z.ZodDate>;
|
|
15
15
|
notes: z.ZodOptional<z.ZodString>;
|
|
@@ -7,6 +7,7 @@ exports.setUserTrustLevel = setUserTrustLevel;
|
|
|
7
7
|
const zod_1 = require("zod");
|
|
8
8
|
const user_context_singleton_1 = require("../context/user-context-singleton");
|
|
9
9
|
const socket_type_1 = require("../device/socket.type");
|
|
10
|
+
const zod_types_1 = require("../types/zod-types");
|
|
10
11
|
const table_definitions_system_1 = require("./orm/table-definitions.system");
|
|
11
12
|
const types_1 = require("./orm/types");
|
|
12
13
|
/**
|
|
@@ -17,7 +18,7 @@ const types_1 = require("./orm/types");
|
|
|
17
18
|
* Each context can maintain its own trust assessment of other users.
|
|
18
19
|
*/
|
|
19
20
|
exports.userTrustLevelSchema = zod_1.z.object({
|
|
20
|
-
userId:
|
|
21
|
+
userId: zod_types_1.zodPeerId.describe('The user being assigned a trust level'),
|
|
21
22
|
trustLevel: zod_1.z.nativeEnum(socket_type_1.TrustLevel).describe('The trust level assigned to this user in this context'),
|
|
22
23
|
assignedAt: zod_1.z.date().optional().describe('When the trust level was assigned'),
|
|
23
24
|
notes: zod_1.z.string().optional().describe('Optional notes about why this trust level was assigned'),
|
package/dist/data/users.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import type { DataContext } from "../context/data-context";
|
|
|
3
3
|
import type { ISaveOptions } from "./orm/data-query";
|
|
4
4
|
import { Table } from "./orm/table";
|
|
5
5
|
export declare const userSchema: z.ZodObject<{
|
|
6
|
-
userId: z.ZodString
|
|
6
|
+
userId: z.ZodEffects<z.ZodString, string, string>;
|
|
7
7
|
name: z.ZodString;
|
|
8
8
|
publicKey: z.ZodString;
|
|
9
9
|
publicBoxKey: z.ZodString;
|
|
@@ -34,5 +34,4 @@ export declare class UsersTable extends Table<IUser> {
|
|
|
34
34
|
update(..._args: Parameters<Table<IUser>['update']>): never;
|
|
35
35
|
}
|
|
36
36
|
export declare function Users(dataContext?: DataContext): UsersTable;
|
|
37
|
-
export declare const myUserId: import("./persistent-vars").PersistentVar<string>;
|
|
38
37
|
export declare function getMe(): Promise<IUser>;
|
package/dist/data/users.js
CHANGED
|
@@ -34,19 +34,19 @@ var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn,
|
|
|
34
34
|
done = true;
|
|
35
35
|
};
|
|
36
36
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
37
|
-
exports.
|
|
37
|
+
exports.UsersTable = exports.userSchema = void 0;
|
|
38
38
|
exports.Users = Users;
|
|
39
39
|
exports.getMe = getMe;
|
|
40
40
|
const zod_1 = require("zod");
|
|
41
41
|
const user_context_singleton_1 = require("../context/user-context-singleton");
|
|
42
|
+
const zod_types_1 = require("../types/zod-types");
|
|
42
43
|
const decorators_1 = require("./orm/decorators");
|
|
43
44
|
const table_1 = require("./orm/table");
|
|
44
45
|
const table_definitions_system_1 = require("./orm/table-definitions.system");
|
|
45
46
|
const types_1 = require("./orm/types");
|
|
46
|
-
const persistent_vars_1 = require("./persistent-vars");
|
|
47
47
|
const user_permissions_1 = require("./user-permissions");
|
|
48
48
|
exports.userSchema = zod_1.z.object({
|
|
49
|
-
userId:
|
|
49
|
+
userId: zod_types_1.zodPeerId,
|
|
50
50
|
name: zod_1.z.string(),
|
|
51
51
|
publicKey: zod_1.z.string().describe('The public key the user uses to sign messages'),
|
|
52
52
|
publicBoxKey: zod_1.z.string().describe('The public key to use to encrypt data that only this user can decrypt'),
|
|
@@ -122,7 +122,6 @@ exports.UsersTable = UsersTable;
|
|
|
122
122
|
function Users(dataContext) {
|
|
123
123
|
return (0, user_context_singleton_1.getTableContainer)(dataContext).getTable(metaData, exports.userSchema, UsersTable);
|
|
124
124
|
}
|
|
125
|
-
exports.myUserId = (0, persistent_vars_1.deviceVar)('myUserId', { defaultValue: '' });
|
|
126
125
|
// let me: IUser | undefined = undefined;
|
|
127
126
|
async function getMe() {
|
|
128
127
|
const userContext = await (0, user_context_singleton_1.getUserContext)();
|
|
@@ -10,8 +10,8 @@ export declare const workflowLogSchema: z.ZodObject<{
|
|
|
10
10
|
instruction: z.ZodOptional<z.ZodObject<{
|
|
11
11
|
markdown: z.ZodOptional<z.ZodString>;
|
|
12
12
|
onError: z.ZodOptional<z.ZodString>;
|
|
13
|
-
directCallToolId: z.ZodOptional<z.ZodString
|
|
14
|
-
subWorkflowId: z.ZodOptional<z.ZodString
|
|
13
|
+
directCallToolId: z.ZodOptional<z.ZodEffects<z.ZodString, string, string>>;
|
|
14
|
+
subWorkflowId: z.ZodOptional<z.ZodEffects<z.ZodString, string, string>>;
|
|
15
15
|
}, "strip", z.ZodTypeAny, {
|
|
16
16
|
markdown?: string | undefined;
|
|
17
17
|
onError?: string | undefined;
|
|
@@ -11,8 +11,8 @@ export declare const workflowRunSchema: z.ZodObject<{
|
|
|
11
11
|
instructions: z.ZodDefault<z.ZodArray<z.ZodObject<{
|
|
12
12
|
markdown: z.ZodOptional<z.ZodString>;
|
|
13
13
|
onError: z.ZodOptional<z.ZodString>;
|
|
14
|
-
directCallToolId: z.ZodOptional<z.ZodString
|
|
15
|
-
subWorkflowId: z.ZodOptional<z.ZodString
|
|
14
|
+
directCallToolId: z.ZodOptional<z.ZodEffects<z.ZodString, string, string>>;
|
|
15
|
+
subWorkflowId: z.ZodOptional<z.ZodEffects<z.ZodString, string, string>>;
|
|
16
16
|
}, "strip", z.ZodTypeAny, {
|
|
17
17
|
markdown?: string | undefined;
|
|
18
18
|
onError?: string | undefined;
|
package/dist/keys.js
CHANGED
|
@@ -63,6 +63,9 @@ function encodeBase64(data) {
|
|
|
63
63
|
return str.replace(/\+/g, '-').replace(/\//g, '_').replace(/=/g, '');
|
|
64
64
|
}
|
|
65
65
|
function decodeBase64(data) {
|
|
66
|
+
if (typeof data !== 'string') {
|
|
67
|
+
throw new TypeError(`decodeBase64 expected a string but received ${typeof data}`);
|
|
68
|
+
}
|
|
66
69
|
data = data.replace(/-/g, '+').replace(/_/g, '/');
|
|
67
70
|
while (data.length % 4 !== 0) {
|
|
68
71
|
data += '=';
|
|
@@ -211,9 +214,12 @@ function addSignatureToObject(obj, secretKey) {
|
|
|
211
214
|
* Will throw if the signature is invalid
|
|
212
215
|
*/
|
|
213
216
|
function verifyObjectSignature(objectWithSignature) {
|
|
217
|
+
if (!objectWithSignature.signature) {
|
|
218
|
+
throw new Error('Object has no signature to verify');
|
|
219
|
+
}
|
|
214
220
|
const objWithoutSignature = { ...objectWithSignature };
|
|
215
221
|
delete objWithoutSignature.signature;
|
|
216
|
-
const [objPublicKey, objSignature] = objectWithSignature.signature
|
|
222
|
+
const [objPublicKey, objSignature] = objectWithSignature.signature.split(':');
|
|
217
223
|
const signedObject = {
|
|
218
224
|
contents: objWithoutSignature,
|
|
219
225
|
signature: objSignature,
|
package/dist/types/workflow.d.ts
CHANGED
|
@@ -2,8 +2,8 @@ import { z } from "zod";
|
|
|
2
2
|
export declare const workflowInstructionSchema: z.ZodObject<{
|
|
3
3
|
markdown: z.ZodOptional<z.ZodString>;
|
|
4
4
|
onError: z.ZodOptional<z.ZodString>;
|
|
5
|
-
directCallToolId: z.ZodOptional<z.ZodString
|
|
6
|
-
subWorkflowId: z.ZodOptional<z.ZodString
|
|
5
|
+
directCallToolId: z.ZodOptional<z.ZodEffects<z.ZodString, string, string>>;
|
|
6
|
+
subWorkflowId: z.ZodOptional<z.ZodEffects<z.ZodString, string, string>>;
|
|
7
7
|
}, "strip", z.ZodTypeAny, {
|
|
8
8
|
markdown?: string | undefined;
|
|
9
9
|
onError?: string | undefined;
|
|
@@ -17,15 +17,15 @@ export declare const workflowInstructionSchema: z.ZodObject<{
|
|
|
17
17
|
}>;
|
|
18
18
|
export type IWorkflowInstruction = z.infer<typeof workflowInstructionSchema>;
|
|
19
19
|
export declare const workflowSchema: z.ZodObject<{
|
|
20
|
-
workflowId: z.ZodString
|
|
20
|
+
workflowId: z.ZodEffects<z.ZodString, string, string>;
|
|
21
21
|
name: z.ZodString;
|
|
22
22
|
description: z.ZodString;
|
|
23
|
-
defaultAssistantId: z.ZodString
|
|
23
|
+
defaultAssistantId: z.ZodEffects<z.ZodString, string, string>;
|
|
24
24
|
instructions: z.ZodDefault<z.ZodArray<z.ZodObject<{
|
|
25
25
|
markdown: z.ZodOptional<z.ZodString>;
|
|
26
26
|
onError: z.ZodOptional<z.ZodString>;
|
|
27
|
-
directCallToolId: z.ZodOptional<z.ZodString
|
|
28
|
-
subWorkflowId: z.ZodOptional<z.ZodString
|
|
27
|
+
directCallToolId: z.ZodOptional<z.ZodEffects<z.ZodString, string, string>>;
|
|
28
|
+
subWorkflowId: z.ZodOptional<z.ZodEffects<z.ZodString, string, string>>;
|
|
29
29
|
}, "strip", z.ZodTypeAny, {
|
|
30
30
|
markdown?: string | undefined;
|
|
31
31
|
onError?: string | undefined;
|
|
@@ -37,7 +37,7 @@ export declare const workflowSchema: z.ZodObject<{
|
|
|
37
37
|
directCallToolId?: string | undefined;
|
|
38
38
|
subWorkflowId?: string | undefined;
|
|
39
39
|
}>, "many">>;
|
|
40
|
-
createdBy: z.ZodString
|
|
40
|
+
createdBy: z.ZodEffects<z.ZodString, string, string>;
|
|
41
41
|
createdAt: z.ZodDefault<z.ZodDate>;
|
|
42
42
|
updatedAt: z.ZodDefault<z.ZodDate>;
|
|
43
43
|
}, "strip", z.ZodTypeAny, {
|
package/dist/types/workflow.js
CHANGED
|
@@ -2,23 +2,24 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.workflowSchema = exports.workflowInstructionSchema = void 0;
|
|
4
4
|
const zod_1 = require("zod");
|
|
5
|
+
const zod_types_1 = require("./zod-types");
|
|
5
6
|
exports.workflowInstructionSchema = zod_1.z.object({
|
|
6
7
|
markdown: zod_1.z.string().optional().describe('The instruction in markdown format'),
|
|
7
8
|
onError: zod_1.z.string().optional().describe('The instruction to run if there is an error while running this instruction'),
|
|
8
|
-
directCallToolId:
|
|
9
|
-
subWorkflowId:
|
|
9
|
+
directCallToolId: zod_types_1.zodPeerId.optional().describe('The tool to call directly with the tool id'),
|
|
10
|
+
subWorkflowId: zod_types_1.zodPeerId.optional().describe('The sub workflow to run with the workflow id'),
|
|
10
11
|
});
|
|
11
12
|
exports.workflowSchema = zod_1.z.object({
|
|
12
|
-
workflowId:
|
|
13
|
+
workflowId: zod_types_1.zodPeerId,
|
|
13
14
|
name: zod_1.z.string().describe('The name of the workflow'),
|
|
14
15
|
description: zod_1.z.string().describe('A detailed description of the workflow that can be used to help users and assistants understand what the workflow does'),
|
|
15
|
-
defaultAssistantId:
|
|
16
|
+
defaultAssistantId: zod_types_1.zodPeerId.describe('The default assistant to handle instructions when the workflow is run'),
|
|
16
17
|
instructions: exports.workflowInstructionSchema
|
|
17
18
|
.array().describe([
|
|
18
19
|
'The instructions for the workflow. This should be written in markdown and can include special links to other workflows, tools, etc. via mentions',
|
|
19
20
|
'The instructions should be broken down into discrete steps and should be as clear as possible.',
|
|
20
21
|
].join(' ')).default([]),
|
|
21
|
-
createdBy:
|
|
22
|
+
createdBy: zod_types_1.zodPeerId.describe('The user who created the workflow'),
|
|
22
23
|
createdAt: zod_1.z.date().default(() => new Date()).describe('The date the workflow was created'),
|
|
23
24
|
updatedAt: zod_1.z.date().default(() => new Date()).describe('The date the workflow was last updated'),
|
|
24
25
|
});
|
package/dist/types/zod-types.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.zodPeerId = exports.zodAnyObjectOrArray = exports.zodAnyObject = void 0;
|
|
4
4
|
const zod_1 = require("zod");
|
|
5
|
+
const field_type_1 = require("./field-type");
|
|
5
6
|
const utils_1 = require("../utils");
|
|
6
7
|
exports.zodAnyObject = zod_1.z.object({}).catchall(zod_1.z.any());
|
|
7
8
|
exports.zodAnyObjectOrArray = zod_1.z.union([exports.zodAnyObject, zod_1.z.array(zod_1.z.any())]);
|
|
@@ -10,3 +11,4 @@ exports.zodPeerId = zod_1.z.string().refine(value => {
|
|
|
10
11
|
}, {
|
|
11
12
|
message: "Invalid peer id, it must be a 25 character alphanumeric string",
|
|
12
13
|
});
|
|
14
|
+
exports.zodPeerId._def._fieldType = field_type_1.FieldType.id;
|