@peers-app/peers-sdk 0.16.4 → 0.16.6
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.js +6 -0
- package/dist/contracts/__tests__/builder.test.d.ts +1 -0
- package/dist/contracts/__tests__/builder.test.js +411 -0
- package/dist/contracts/__tests__/extract.test.d.ts +1 -0
- package/dist/contracts/__tests__/extract.test.js +145 -0
- package/dist/contracts/__tests__/integration.test.d.ts +1 -0
- package/dist/contracts/__tests__/integration.test.js +348 -0
- package/dist/contracts/__tests__/registry.test.d.ts +1 -0
- package/dist/contracts/__tests__/registry.test.js +324 -0
- package/dist/contracts/__tests__/validate.test.d.ts +1 -0
- package/dist/contracts/__tests__/validate.test.js +699 -0
- package/dist/contracts/builder.d.ts +97 -0
- package/dist/contracts/builder.js +211 -0
- package/dist/contracts/contract-providers.table.d.ts +40 -0
- package/dist/contracts/contract-providers.table.js +41 -0
- package/dist/contracts/contracts.table.d.ts +44 -0
- package/dist/contracts/contracts.table.js +44 -0
- package/dist/contracts/extract.d.ts +46 -0
- package/dist/contracts/extract.js +51 -0
- package/dist/contracts/index.d.ts +9 -0
- package/dist/contracts/index.js +31 -0
- package/dist/contracts/persistent-registry.d.ts +32 -0
- package/dist/contracts/persistent-registry.js +138 -0
- package/dist/contracts/registry.d.ts +58 -0
- package/dist/contracts/registry.js +155 -0
- package/dist/contracts/types.d.ts +108 -0
- package/dist/contracts/types.js +10 -0
- package/dist/contracts/validate.d.ts +24 -0
- package/dist/contracts/validate.js +274 -0
- package/dist/data/assistants.d.ts +5 -0
- package/dist/data/assistants.js +1 -0
- package/dist/data/package-versions.d.ts +2 -2
- package/dist/data/persistent-vars.d.ts +3 -0
- package/dist/data/persistent-vars.js +17 -2
- package/dist/data/tools.d.ts +4 -0
- package/dist/data/tools.js +1 -0
- package/dist/data/workflows.d.ts +1 -0
- package/dist/events.d.ts +13 -0
- package/dist/events.js +218 -34
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/package-loader/contract-package-loader.d.ts +23 -0
- package/dist/package-loader/contract-package-loader.js +65 -0
- package/dist/package-loader/index.d.ts +1 -0
- package/dist/package-loader/index.js +1 -0
- package/dist/package-loader/package-loader.d.ts +11 -0
- package/dist/package-loader/package-loader.js +59 -8
- package/dist/rpc-types.d.ts +4 -0
- package/dist/rpc-types.js +5 -4
- package/dist/types/workflow.d.ts +3 -0
- package/dist/types/workflow.js +1 -0
- package/dist/utils.d.ts +15 -0
- package/dist/utils.js +39 -0
- package/package.json +1 -1
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateProviderSatisfiesContract = validateProviderSatisfiesContract;
|
|
4
|
+
exports.validateImmutability = validateImmutability;
|
|
5
|
+
exports.validateAlsoImplements = validateAlsoImplements;
|
|
6
|
+
const types_1 = require("./types");
|
|
7
|
+
function ok() {
|
|
8
|
+
return { valid: true, errors: [] };
|
|
9
|
+
}
|
|
10
|
+
function fail(errors) {
|
|
11
|
+
return { valid: false, errors };
|
|
12
|
+
}
|
|
13
|
+
function merge(results) {
|
|
14
|
+
const errors = results.flatMap((r) => r.errors);
|
|
15
|
+
return { valid: errors.length === 0, errors };
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Check whether `implField` satisfies the contract's `contractField`.
|
|
19
|
+
* - Types must match exactly.
|
|
20
|
+
* - If the contract field is required, the implementation must also be required.
|
|
21
|
+
* - `isArray` must match.
|
|
22
|
+
*/
|
|
23
|
+
function isFieldCompatible(contractField, implField) {
|
|
24
|
+
if (contractField.type !== implField.type) {
|
|
25
|
+
return `type mismatch: contract requires '${contractField.type}', implementation has '${implField.type}'`;
|
|
26
|
+
}
|
|
27
|
+
if (contractField.isArray && !implField.isArray) {
|
|
28
|
+
return "contract requires array, implementation is not an array";
|
|
29
|
+
}
|
|
30
|
+
if (!contractField.isArray && implField.isArray) {
|
|
31
|
+
return "contract requires scalar, implementation is an array";
|
|
32
|
+
}
|
|
33
|
+
if (!contractField.optional && implField.optional) {
|
|
34
|
+
return "contract requires a required field, implementation marks it optional";
|
|
35
|
+
}
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
function validateTableFields(contractTable, implTable) {
|
|
39
|
+
const errors = [];
|
|
40
|
+
const implFieldMap = new Map(implTable.fields.map((f) => [f.name, f]));
|
|
41
|
+
for (const contractField of contractTable.fields) {
|
|
42
|
+
const implField = implFieldMap.get(contractField.name);
|
|
43
|
+
if (!implField) {
|
|
44
|
+
if (!contractField.optional) {
|
|
45
|
+
errors.push({
|
|
46
|
+
kind: "field",
|
|
47
|
+
name: `${contractTable.name}.${contractField.name}`,
|
|
48
|
+
message: `Required field '${contractField.name}' missing from implementation table '${implTable.name}'`,
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
const compat = isFieldCompatible(contractField, implField);
|
|
54
|
+
if (compat) {
|
|
55
|
+
errors.push({
|
|
56
|
+
kind: "field",
|
|
57
|
+
name: `${contractTable.name}.${contractField.name}`,
|
|
58
|
+
message: `Field '${contractField.name}' in table '${implTable.name}': ${compat}`,
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
// Extra fields in the implementation are allowed only if optional
|
|
63
|
+
for (const implField of implTable.fields) {
|
|
64
|
+
const inContract = contractTable.fields.some((f) => f.name === implField.name);
|
|
65
|
+
if (!inContract && !implField.optional) {
|
|
66
|
+
errors.push({
|
|
67
|
+
kind: "field",
|
|
68
|
+
name: `${implTable.name}.${implField.name}`,
|
|
69
|
+
message: `Implementation table '${implTable.name}' has extra required field '${implField.name}' not in contract (must be optional)`,
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return errors;
|
|
74
|
+
}
|
|
75
|
+
function validateToolFields(contractTool, implTool, direction) {
|
|
76
|
+
const errors = [];
|
|
77
|
+
const contractFields = direction === "input" ? contractTool.inputFields : contractTool.outputFields;
|
|
78
|
+
const implFields = direction === "input" ? implTool.inputFields : implTool.outputFields;
|
|
79
|
+
const implFieldMap = new Map(implFields.map((f) => [f.name, f]));
|
|
80
|
+
for (const contractField of contractFields) {
|
|
81
|
+
const implField = implFieldMap.get(contractField.name);
|
|
82
|
+
if (!implField) {
|
|
83
|
+
if (!contractField.optional) {
|
|
84
|
+
errors.push({
|
|
85
|
+
kind: "field",
|
|
86
|
+
name: `${contractTool.name}.${direction}.${contractField.name}`,
|
|
87
|
+
message: `Required ${direction} field '${contractField.name}' missing from tool '${implTool.name}'`,
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
const compat = isFieldCompatible(contractField, implField);
|
|
93
|
+
if (compat) {
|
|
94
|
+
errors.push({
|
|
95
|
+
kind: "field",
|
|
96
|
+
name: `${contractTool.name}.${direction}.${contractField.name}`,
|
|
97
|
+
message: `Field '${contractField.name}' in tool '${implTool.name}' ${direction}: ${compat}`,
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
// For inputs: extra optional fields in the implementation are OK (the impl accepts more)
|
|
102
|
+
// For outputs: extra fields in the implementation are OK (the impl returns more)
|
|
103
|
+
if (direction === "input") {
|
|
104
|
+
for (const implField of implFields) {
|
|
105
|
+
const inContract = contractFields.some((f) => f.name === implField.name);
|
|
106
|
+
if (!inContract && !implField.optional) {
|
|
107
|
+
errors.push({
|
|
108
|
+
kind: "field",
|
|
109
|
+
name: `${implTool.name}.${direction}.${implField.name}`,
|
|
110
|
+
message: `Implementation tool '${implTool.name}' has extra required input field '${implField.name}' not in contract (must be optional)`,
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return errors;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Validate that an implementation contract satisfies a target contract shape.
|
|
119
|
+
* The implementation must be a superset: all contract tables, tools, and
|
|
120
|
+
* observables must be present with compatible shapes.
|
|
121
|
+
*/
|
|
122
|
+
function validateProviderSatisfiesContract(impl, contract) {
|
|
123
|
+
const errors = [];
|
|
124
|
+
// Tables
|
|
125
|
+
const implTableMap = new Map(impl.tables.map((t) => [t.name, t]));
|
|
126
|
+
for (const contractTable of contract.tables) {
|
|
127
|
+
const implTable = implTableMap.get(contractTable.name);
|
|
128
|
+
if (!implTable) {
|
|
129
|
+
errors.push({
|
|
130
|
+
kind: "table",
|
|
131
|
+
name: contractTable.name,
|
|
132
|
+
message: `Table '${contractTable.name}' required by contract but not provided by implementation`,
|
|
133
|
+
});
|
|
134
|
+
continue;
|
|
135
|
+
}
|
|
136
|
+
if (implTable.primaryKeyName !== contractTable.primaryKeyName) {
|
|
137
|
+
errors.push({
|
|
138
|
+
kind: "table",
|
|
139
|
+
name: contractTable.name,
|
|
140
|
+
message: `Table '${contractTable.name}': primary key mismatch — contract expects '${contractTable.primaryKeyName}', implementation has '${implTable.primaryKeyName}'`,
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
errors.push(...validateTableFields(contractTable, implTable));
|
|
144
|
+
}
|
|
145
|
+
// Tools
|
|
146
|
+
const implToolMap = new Map(impl.tools.map((t) => [t.name, t]));
|
|
147
|
+
for (const contractTool of contract.tools) {
|
|
148
|
+
const implTool = implToolMap.get(contractTool.name);
|
|
149
|
+
if (!implTool) {
|
|
150
|
+
errors.push({
|
|
151
|
+
kind: "tool",
|
|
152
|
+
name: contractTool.name,
|
|
153
|
+
message: `Tool '${contractTool.name}' required by contract but not provided by implementation`,
|
|
154
|
+
});
|
|
155
|
+
continue;
|
|
156
|
+
}
|
|
157
|
+
errors.push(...validateToolFields(contractTool, implTool, "input"));
|
|
158
|
+
errors.push(...validateToolFields(contractTool, implTool, "output"));
|
|
159
|
+
}
|
|
160
|
+
// Observables
|
|
161
|
+
const implObsMap = new Map(impl.observables.map((o) => [o.name, o]));
|
|
162
|
+
for (const contractObs of contract.observables) {
|
|
163
|
+
const implObs = implObsMap.get(contractObs.name);
|
|
164
|
+
if (!implObs) {
|
|
165
|
+
errors.push({
|
|
166
|
+
kind: "observable",
|
|
167
|
+
name: contractObs.name,
|
|
168
|
+
message: `Observable '${contractObs.name}' required by contract but not provided by implementation`,
|
|
169
|
+
});
|
|
170
|
+
continue;
|
|
171
|
+
}
|
|
172
|
+
if (contractObs.valueType !== implObs.valueType) {
|
|
173
|
+
errors.push({
|
|
174
|
+
kind: "observable",
|
|
175
|
+
name: contractObs.name,
|
|
176
|
+
message: `Observable '${contractObs.name}': type mismatch — contract expects '${contractObs.valueType}', implementation has '${implObs.valueType}'`,
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
if (contractObs.writable && !implObs.writable) {
|
|
180
|
+
errors.push({
|
|
181
|
+
kind: "observable",
|
|
182
|
+
name: contractObs.name,
|
|
183
|
+
message: `Observable '${contractObs.name}' must be writable per contract, but implementation is read-only`,
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
return errors.length === 0 ? ok() : fail(errors);
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Validate that a frozen (stable) contract definition has not been modified.
|
|
191
|
+
* If the existing definition has no `devTag` it is frozen; the incoming
|
|
192
|
+
* definition must be structurally identical and also stable.
|
|
193
|
+
* Dev contracts (`devTag: "dev"`) may change freely but cannot be registered
|
|
194
|
+
* once a stable version exists for that contract+version.
|
|
195
|
+
*/
|
|
196
|
+
function validateImmutability(existing, incoming) {
|
|
197
|
+
if (existing.devTag === "dev") {
|
|
198
|
+
return ok();
|
|
199
|
+
}
|
|
200
|
+
// Existing is stable/frozen — reject any attempt to register a dev version
|
|
201
|
+
if (incoming.devTag === "dev") {
|
|
202
|
+
return fail([
|
|
203
|
+
{
|
|
204
|
+
kind: "contract",
|
|
205
|
+
name: (0, types_1.contractKey)(existing.contractId, existing.version),
|
|
206
|
+
message: `Cannot register a dev version for stable contract ${existing.name} v${existing.version} — contract is already frozen`,
|
|
207
|
+
},
|
|
208
|
+
]);
|
|
209
|
+
}
|
|
210
|
+
// Deep-compare the shapes. We serialize to JSON for a simple structural comparison.
|
|
211
|
+
const existingShape = JSON.stringify({
|
|
212
|
+
tables: existing.tables,
|
|
213
|
+
tools: existing.tools,
|
|
214
|
+
observables: existing.observables,
|
|
215
|
+
});
|
|
216
|
+
const incomingShape = JSON.stringify({
|
|
217
|
+
tables: incoming.tables,
|
|
218
|
+
tools: incoming.tools,
|
|
219
|
+
observables: incoming.observables,
|
|
220
|
+
});
|
|
221
|
+
if (existingShape !== incomingShape) {
|
|
222
|
+
return fail([
|
|
223
|
+
{
|
|
224
|
+
kind: "contract",
|
|
225
|
+
name: (0, types_1.contractKey)(existing.contractId, existing.version),
|
|
226
|
+
message: `Stable contract ${existing.name} v${existing.version} is frozen and cannot be modified`,
|
|
227
|
+
},
|
|
228
|
+
]);
|
|
229
|
+
}
|
|
230
|
+
return ok();
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Validate that an implementation satisfies all contracts referenced by its
|
|
234
|
+
* `alsoImplements` declarations.
|
|
235
|
+
*
|
|
236
|
+
* @param impl The implementation's extracted contract definition.
|
|
237
|
+
* @param declarations The `alsoImplements` declarations for this contract.
|
|
238
|
+
* @param getContract Callback to look up an existing contract definition.
|
|
239
|
+
*/
|
|
240
|
+
function validateAlsoImplements(impl, declarations, getContract) {
|
|
241
|
+
const results = [];
|
|
242
|
+
for (const decl of declarations) {
|
|
243
|
+
const versions = [];
|
|
244
|
+
if (typeof decl.version === "number") {
|
|
245
|
+
versions.push(decl.version);
|
|
246
|
+
}
|
|
247
|
+
else {
|
|
248
|
+
for (let v = decl.version.from; v <= decl.version.to; v++) {
|
|
249
|
+
versions.push(v);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
for (const ver of versions) {
|
|
253
|
+
const target = getContract(decl.contractId, ver);
|
|
254
|
+
if (!target) {
|
|
255
|
+
results.push(fail([
|
|
256
|
+
{
|
|
257
|
+
kind: "contract",
|
|
258
|
+
name: (0, types_1.contractKey)(decl.contractId, ver),
|
|
259
|
+
message: `alsoImplements references contract ${decl.contractId} v${ver}, but that contract was not found`,
|
|
260
|
+
},
|
|
261
|
+
]));
|
|
262
|
+
continue;
|
|
263
|
+
}
|
|
264
|
+
const result = validateProviderSatisfiesContract(impl, target);
|
|
265
|
+
if (!result.valid) {
|
|
266
|
+
for (const error of result.errors) {
|
|
267
|
+
error.message = `[alsoImplements ${decl.contractId} v${ver}] ${error.message}`;
|
|
268
|
+
}
|
|
269
|
+
results.push(result);
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
return merge(results);
|
|
274
|
+
}
|
|
@@ -15,6 +15,7 @@ export declare const assistantSchema: z.ZodObject<{
|
|
|
15
15
|
assistantRunnerConfig: z.ZodDefault<z.ZodObject<{}, "strip", z.ZodAny, z.objectOutputType<{}, z.ZodAny, "strip">, z.objectInputType<{}, z.ZodAny, "strip">>>;
|
|
16
16
|
toolsToInclude: z.ZodDefault<z.ZodString>;
|
|
17
17
|
toolInclusionStrategy: z.ZodDefault<z.ZodNativeEnum<typeof ToolInclusionStrategy>>;
|
|
18
|
+
packageId: z.ZodOptional<z.ZodEffects<z.ZodString, string, string>>;
|
|
18
19
|
}, "strip", z.ZodTypeAny, {
|
|
19
20
|
name: string;
|
|
20
21
|
createdAt: Date;
|
|
@@ -26,11 +27,13 @@ export declare const assistantSchema: z.ZodObject<{
|
|
|
26
27
|
toolsToInclude: string;
|
|
27
28
|
toolInclusionStrategy: ToolInclusionStrategy;
|
|
28
29
|
description?: string | undefined;
|
|
30
|
+
packageId?: string | undefined;
|
|
29
31
|
updatedAt?: Date | undefined;
|
|
30
32
|
}, {
|
|
31
33
|
name: string;
|
|
32
34
|
assistantId: string;
|
|
33
35
|
description?: string | undefined;
|
|
36
|
+
packageId?: string | undefined;
|
|
34
37
|
createdAt?: Date | undefined;
|
|
35
38
|
updatedAt?: Date | undefined;
|
|
36
39
|
assistantRunnerToolId?: string | undefined;
|
|
@@ -50,6 +53,7 @@ export declare function Assistants(dataContext?: DataContext): import("./orm").T
|
|
|
50
53
|
toolsToInclude: string;
|
|
51
54
|
toolInclusionStrategy: ToolInclusionStrategy;
|
|
52
55
|
description?: string | undefined;
|
|
56
|
+
packageId?: string | undefined;
|
|
53
57
|
updatedAt?: Date | undefined;
|
|
54
58
|
}>;
|
|
55
59
|
/**
|
|
@@ -73,6 +77,7 @@ export declare const getPrimaryAssistant: (dataContext?: DataContext) => Promise
|
|
|
73
77
|
toolsToInclude: string;
|
|
74
78
|
toolInclusionStrategy: ToolInclusionStrategy;
|
|
75
79
|
description?: string | undefined;
|
|
80
|
+
packageId?: string | undefined;
|
|
76
81
|
updatedAt?: Date | undefined;
|
|
77
82
|
}>;
|
|
78
83
|
export declare function getAllAssistantIdsMentioned(message: string): Promise<string[]>;
|
package/dist/data/assistants.js
CHANGED
|
@@ -46,6 +46,7 @@ exports.assistantSchema = zod_1.z.object({
|
|
|
46
46
|
"- **Linked** - `Fixed` plus tools linked in the message or chat history of the assistant's current conversation.",
|
|
47
47
|
"- **Relevant** - `Linked` plus tools matching the context of the conversation determined via vector search (embeddings) of the tools descriptions.",
|
|
48
48
|
].join("\n")),
|
|
49
|
+
packageId: zod_types_1.zodPeerId.optional().describe("The package that installed this assistant, if any"),
|
|
49
50
|
});
|
|
50
51
|
const metaData = {
|
|
51
52
|
name: "Assistants",
|
|
@@ -36,8 +36,8 @@ declare const schema: z.ZodObject<{
|
|
|
36
36
|
}, "strip", z.ZodTypeAny, {
|
|
37
37
|
version: string;
|
|
38
38
|
signature: string;
|
|
39
|
-
packageVersionId: string;
|
|
40
39
|
packageId: string;
|
|
40
|
+
packageVersionId: string;
|
|
41
41
|
packageVersionHash: string;
|
|
42
42
|
packageBundleFileId: string;
|
|
43
43
|
packageBundleFileHash: string;
|
|
@@ -57,8 +57,8 @@ declare const schema: z.ZodObject<{
|
|
|
57
57
|
}, {
|
|
58
58
|
version: string;
|
|
59
59
|
signature: string;
|
|
60
|
-
packageVersionId: string;
|
|
61
60
|
packageId: string;
|
|
61
|
+
packageVersionId: string;
|
|
62
62
|
packageVersionHash: string;
|
|
63
63
|
packageBundleFileId: string;
|
|
64
64
|
packageBundleFileHash: string;
|
|
@@ -26,6 +26,7 @@ declare const schema: z.ZodObject<{
|
|
|
26
26
|
userCreated: z.ZodOptional<z.ZodBoolean>;
|
|
27
27
|
isSecret: z.ZodOptional<z.ZodBoolean>;
|
|
28
28
|
modifiedAt: z.ZodOptional<z.ZodNumber>;
|
|
29
|
+
packageId: z.ZodOptional<z.ZodEffects<z.ZodString, string, string>>;
|
|
29
30
|
}, "strip", z.ZodTypeAny, {
|
|
30
31
|
name: string;
|
|
31
32
|
value: {
|
|
@@ -37,6 +38,7 @@ declare const schema: z.ZodObject<{
|
|
|
37
38
|
userCreated?: boolean | undefined;
|
|
38
39
|
isSecret?: boolean | undefined;
|
|
39
40
|
modifiedAt?: number | undefined;
|
|
41
|
+
packageId?: string | undefined;
|
|
40
42
|
}, {
|
|
41
43
|
name: string;
|
|
42
44
|
value: {
|
|
@@ -48,6 +50,7 @@ declare const schema: z.ZodObject<{
|
|
|
48
50
|
userCreated?: boolean | undefined;
|
|
49
51
|
isSecret?: boolean | undefined;
|
|
50
52
|
modifiedAt?: number | undefined;
|
|
53
|
+
packageId?: string | undefined;
|
|
51
54
|
}>;
|
|
52
55
|
export declare const persistentVarsMetaData: ITableMetaData;
|
|
53
56
|
export type IPersistentVar = z.infer<typeof schema>;
|
|
@@ -40,6 +40,9 @@ const schema = zod_1.z.object({
|
|
|
40
40
|
.number()
|
|
41
41
|
.optional()
|
|
42
42
|
.describe("Timestamp of when this pvar was last modified (Date.now())"),
|
|
43
|
+
packageId: zod_types_1.zodPeerId
|
|
44
|
+
.optional()
|
|
45
|
+
.describe("The package that owns this persistent variable, if any"),
|
|
43
46
|
});
|
|
44
47
|
exports.persistentVarsMetaData = {
|
|
45
48
|
name: "PersistentVars",
|
|
@@ -58,10 +61,12 @@ class PersistentVarsTable extends table_1.Table {
|
|
|
58
61
|
}
|
|
59
62
|
async save(persistentVar, opts) {
|
|
60
63
|
if (!persistentVar.persistentVarId) {
|
|
61
|
-
persistentVar.persistentVarId = (0, utils_1.
|
|
64
|
+
persistentVar.persistentVarId = (0, utils_1.deterministicPvarId)(persistentVar.name);
|
|
62
65
|
}
|
|
63
66
|
const dbVar = await this.get(persistentVar.persistentVarId);
|
|
64
|
-
if (persistentVar.isSecret &&
|
|
67
|
+
if (persistentVar.isSecret &&
|
|
68
|
+
persistentVar.value.value !== undefined &&
|
|
69
|
+
(!rpc_types_1.isClient || (0, rpc_types_1.isSingleProcessClient)())) {
|
|
65
70
|
if (!dbVar ||
|
|
66
71
|
dbVar.value.value !== persistentVar.value.value ||
|
|
67
72
|
dbVar.isSecret !== persistentVar.isSecret) {
|
|
@@ -204,6 +209,12 @@ function persistentVarFactory(name, opts) {
|
|
|
204
209
|
dbRec = undefined;
|
|
205
210
|
}
|
|
206
211
|
}
|
|
212
|
+
if (dbRec && !(0, utils_1.isDeterministicPvarId)(dbRec.persistentVarId)) {
|
|
213
|
+
const newId = (0, utils_1.deterministicPvarId)(name);
|
|
214
|
+
await table.delete(dbRec);
|
|
215
|
+
dbRec.persistentVarId = newId;
|
|
216
|
+
dbRec = await table.save(dbRec);
|
|
217
|
+
}
|
|
207
218
|
if (!dbRec) {
|
|
208
219
|
dbRec = {
|
|
209
220
|
persistentVarId: "",
|
|
@@ -271,6 +282,10 @@ function persistentVarFactory(name, opts) {
|
|
|
271
282
|
};
|
|
272
283
|
// subscribe to db changes
|
|
273
284
|
userContext.subscribeToDataChangedAcrossAllGroups(exports.persistentVarsMetaData.name, async (evt) => {
|
|
285
|
+
const dc = getDataContext();
|
|
286
|
+
if (dc && evt.dataContext && evt.dataContext.dataContextId !== dc.dataContextId) {
|
|
287
|
+
return;
|
|
288
|
+
}
|
|
274
289
|
const dbRec = evt.data.dataObject;
|
|
275
290
|
const dbName = getVarNameInDb();
|
|
276
291
|
if (!rec?.persistentVarId && dbRec.name === dbName) {
|
package/dist/data/tools.d.ts
CHANGED
|
@@ -215,6 +215,7 @@ export declare const toolSchema: z.ZodObject<{
|
|
|
215
215
|
code: z.ZodDefault<z.ZodString>;
|
|
216
216
|
codeRepository: z.ZodOptional<z.ZodString>;
|
|
217
217
|
isAssistantRunner: z.ZodOptional<z.ZodBoolean>;
|
|
218
|
+
packageId: z.ZodOptional<z.ZodEffects<z.ZodString, string, string>>;
|
|
218
219
|
}, "strip", z.ZodTypeAny, {
|
|
219
220
|
code: string;
|
|
220
221
|
name: string;
|
|
@@ -244,6 +245,7 @@ export declare const toolSchema: z.ZodObject<{
|
|
|
244
245
|
subType?: string | undefined;
|
|
245
246
|
}[];
|
|
246
247
|
};
|
|
248
|
+
packageId?: string | undefined;
|
|
247
249
|
detailedDescription?: string | undefined;
|
|
248
250
|
configSchema?: {
|
|
249
251
|
type: IOSchemaType;
|
|
@@ -288,6 +290,7 @@ export declare const toolSchema: z.ZodObject<{
|
|
|
288
290
|
}[] | undefined;
|
|
289
291
|
};
|
|
290
292
|
code?: string | undefined;
|
|
293
|
+
packageId?: string | undefined;
|
|
291
294
|
detailedDescription?: string | undefined;
|
|
292
295
|
configSchema?: {
|
|
293
296
|
type: IOSchemaType;
|
|
@@ -340,6 +343,7 @@ export declare function Tools(dataContext?: DataContext): import("./orm").Table<
|
|
|
340
343
|
subType?: string | undefined;
|
|
341
344
|
}[];
|
|
342
345
|
};
|
|
346
|
+
packageId?: string | undefined;
|
|
343
347
|
detailedDescription?: string | undefined;
|
|
344
348
|
configSchema?: {
|
|
345
349
|
type: IOSchemaType;
|
package/dist/data/tools.js
CHANGED
|
@@ -44,6 +44,7 @@ exports.toolSchema = zod_1.z.object({
|
|
|
44
44
|
.boolean()
|
|
45
45
|
.optional()
|
|
46
46
|
.describe("Whether this tool is a model that can be used to run an assistant"),
|
|
47
|
+
packageId: zod_types_1.zodPeerId.optional().describe("The package that installed this tool, if any"),
|
|
47
48
|
});
|
|
48
49
|
const metaData = {
|
|
49
50
|
name: "Tools",
|
package/dist/data/workflows.d.ts
CHANGED
package/dist/events.d.ts
CHANGED
|
@@ -4,10 +4,23 @@ export type IEventHandler<T = any> = (eventData: IEventData<T>) => boolean | voi
|
|
|
4
4
|
export interface ISubscription {
|
|
5
5
|
filter: IEventFilter;
|
|
6
6
|
handler: IEventHandler;
|
|
7
|
+
/** When set, this subscription matches only events with this exact name (fast-path via Map lookup). */
|
|
8
|
+
eventName?: string;
|
|
7
9
|
}
|
|
8
10
|
export interface ISubscriptionResult {
|
|
9
11
|
unsubscribe: () => boolean;
|
|
10
12
|
}
|
|
13
|
+
/**
|
|
14
|
+
* Notify the events system that the client connection is ready.
|
|
15
|
+
* Flushes any subscriptions that were registered before the connection.
|
|
16
|
+
*/
|
|
17
|
+
export declare function notifyClientConnected(): void;
|
|
18
|
+
/**
|
|
19
|
+
* Register a prefix-based event subscription with the server.
|
|
20
|
+
* Events whose name starts with this prefix will be forwarded to the client.
|
|
21
|
+
* Returns an unsubscribe function that decrements the refcount.
|
|
22
|
+
*/
|
|
23
|
+
export declare function subscribePrefix(prefix: string): () => void;
|
|
11
24
|
export declare function subscribe<T = any>(nameOrFilter: string | IEventFilter, handler: IEventHandler<T>): ISubscriptionResult;
|
|
12
25
|
export declare function subscribeDebounce<T = any>(nameOrFilter: string | IEventFilter, handler: IEventHandler<T>, debounceMs: number): ISubscriptionResult;
|
|
13
26
|
export declare function emit(event: IEventData, dontPropagate?: boolean): Promise<boolean>;
|