@peers-app/peers-sdk 0.25.20 → 0.26.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.
- package/dist/contracts/__tests__/builder.test.js +0 -2
- package/dist/contracts/__tests__/contract-provider-router.test.js +51 -0
- package/dist/contracts/__tests__/contract-proxy.test.js +21 -0
- package/dist/contracts/__tests__/contract-resolvers.test.js +84 -0
- package/dist/contracts/__tests__/legacy-removal.test.d.ts +1 -0
- package/dist/contracts/__tests__/legacy-removal.test.js +90 -0
- package/dist/contracts/__tests__/system-contracts.test.js +88 -0
- package/dist/contracts/__tests__/tool-catalog-inventory.test.d.ts +1 -0
- package/dist/contracts/__tests__/tool-catalog-inventory.test.js +44 -0
- package/dist/contracts/__tests__/tool-catalog-service.test.d.ts +1 -0
- package/dist/contracts/__tests__/tool-catalog-service.test.js +446 -0
- package/dist/contracts/__tests__/tool-catalog.test.d.ts +1 -0
- package/dist/contracts/__tests__/tool-catalog.test.js +649 -0
- package/dist/contracts/__tests__/workflow-context.test.d.ts +1 -0
- package/dist/contracts/__tests__/workflow-context.test.js +61 -0
- package/dist/contracts/builder.d.ts +9 -8
- package/dist/contracts/builder.js +34 -16
- package/dist/contracts/contract-provider-router.d.ts +12 -1
- package/dist/contracts/contract-provider-router.js +40 -2
- package/dist/contracts/contract-proxy.d.ts +20 -6
- package/dist/contracts/contract-proxy.js +23 -12
- package/dist/contracts/contract-resolvers.d.ts +22 -3
- package/dist/contracts/contract-resolvers.js +86 -7
- package/dist/contracts/extract.d.ts +7 -0
- package/dist/contracts/extract.js +3 -0
- package/dist/contracts/index.d.ts +11 -4
- package/dist/contracts/index.js +14 -2
- package/dist/contracts/registry.d.ts +3 -0
- package/dist/contracts/registry.js +2 -0
- package/dist/contracts/system/desktop-tools-contract.d.ts +5 -0
- package/dist/contracts/system/desktop-tools-contract.js +88 -0
- package/dist/contracts/system/host-tools-contract.d.ts +5 -0
- package/dist/contracts/system/host-tools-contract.js +76 -0
- package/dist/contracts/system/index.d.ts +3 -0
- package/dist/contracts/system/index.js +3 -0
- package/dist/contracts/system/tool-catalog-contract.d.ts +73 -0
- package/dist/contracts/system/tool-catalog-contract.js +70 -0
- package/dist/contracts/system-contracts.d.ts +3 -1
- package/dist/contracts/system-contracts.js +20 -6
- package/dist/contracts/tool-catalog-identity.d.ts +35 -0
- package/dist/contracts/tool-catalog-identity.js +88 -0
- package/dist/contracts/tool-catalog-migrations.d.ts +12 -0
- package/dist/contracts/tool-catalog-migrations.js +179 -0
- package/dist/contracts/tool-catalog-service.d.ts +30 -0
- package/dist/contracts/tool-catalog-service.js +287 -0
- package/dist/contracts/tool-catalog.d.ts +91 -0
- package/dist/contracts/tool-catalog.js +490 -0
- package/dist/contracts/types.d.ts +7 -5
- package/dist/data/messages.d.ts +3 -3
- package/dist/data/orm/sql.data-source.d.ts +5 -0
- package/dist/data/orm/sql.data-source.js +28 -10
- package/dist/data/orm/sql.data-source.test.d.ts +1 -1
- package/dist/data/orm/sql.data-source.test.js +160 -0
- package/dist/data/orm/table-container.d.ts +14 -0
- package/dist/data/orm/table-container.js +20 -0
- package/dist/data/tool-access-approvals.d.ts +6 -6
- package/dist/data/tool-catalog-fields.d.ts +31 -0
- package/dist/data/tool-catalog-fields.js +67 -0
- package/dist/data/tools.d.ts +38 -10
- package/dist/data/tools.js +31 -8
- package/dist/data/workflow-logs.d.ts +6 -2
- package/dist/data/workflow-logs.js +7 -5
- package/dist/data/workflow-runs.d.ts +6 -6
- package/dist/index.d.ts +0 -2
- package/dist/index.js +1 -3
- package/dist/package-installer/package-creator.d.ts +14 -5
- package/dist/package-installer/package-creator.js +92 -37
- package/dist/package-installer/package-creator.test.js +308 -23
- package/dist/package-installer/types.d.ts +8 -0
- package/dist/package-loader/contract-package-loader.d.ts +12 -3
- package/dist/package-loader/contract-package-loader.js +54 -50
- package/dist/package-loader/contract-package-loader.test.d.ts +1 -1
- package/dist/package-loader/contract-package-loader.test.js +172 -13
- package/dist/package-loader/host-authority-loading.test.js +16 -3
- package/dist/package-loader/isolated-artifact.d.ts +14 -2
- package/dist/package-loader/isolated-artifact.js +6 -0
- package/dist/package-loader/isolated-artifact.test.js +34 -0
- package/dist/package-loader/isolated-runtime.d.ts +14 -2
- package/dist/package-loader/isolated-table-gateway.d.ts +3 -1
- package/dist/package-loader/isolated-table-gateway.js +54 -5
- package/dist/package-loader/isolated-table-gateway.test.js +123 -0
- package/dist/package-loader/package-loader.d.ts +14 -2
- package/dist/package-loader/package-loader.js +184 -62
- package/dist/package-loader/package-loader.test.js +695 -2
- package/dist/package-loader/resolve-consumed-contracts.js +1 -1
- package/dist/system-ids.d.ts +6 -0
- package/dist/system-ids.js +7 -1
- package/dist/types/peers-package.d.ts +3 -2
- package/dist/types/workflow-run-context.d.ts +12 -2
- package/package.json +1 -1
- package/dist/tools/index.d.ts +0 -1
- package/dist/tools/index.js +0 -17
- package/dist/tools/tools-factory.d.ts +0 -5
- package/dist/tools/tools-factory.js +0 -34
package/dist/data/tools.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import type { DataContext } from "../context/data-context";
|
|
3
|
+
export { isToolCatalogPatch, toolCatalogContractDescriptiveFields, toolCatalogIdentityFields, toolCatalogPatch, toolCatalogPatchFields, toolCatalogSupplementalFields, } from "./tool-catalog-fields";
|
|
3
4
|
/** Shape of a tool input, output, or config schema. */
|
|
4
5
|
export declare enum IOSchemaType {
|
|
5
6
|
none = "none",
|
|
@@ -62,6 +63,12 @@ export type IOSchema = z.infer<typeof ioSchema>;
|
|
|
62
63
|
/** Zod schema for a persisted {@link ITool} row. */
|
|
63
64
|
export declare const toolSchema: z.ZodObject<{
|
|
64
65
|
toolId: z.ZodEffects<z.ZodString, string, string>;
|
|
66
|
+
contractId: z.ZodOptional<z.ZodEffects<z.ZodString, string, string>>;
|
|
67
|
+
contractVersion: z.ZodOptional<z.ZodNumber>;
|
|
68
|
+
toolName: z.ZodOptional<z.ZodString>;
|
|
69
|
+
catalogIdentity: z.ZodOptional<z.ZodEnum<["deterministic", "legacy-alias"]>>;
|
|
70
|
+
catalogState: z.ZodOptional<z.ZodEnum<["resolved", "unresolved", "quarantined"]>>;
|
|
71
|
+
catalogReason: z.ZodOptional<z.ZodString>;
|
|
65
72
|
name: z.ZodString;
|
|
66
73
|
usageDescription: z.ZodString;
|
|
67
74
|
detailedDescription: z.ZodOptional<z.ZodString>;
|
|
@@ -225,7 +232,6 @@ export declare const toolSchema: z.ZodObject<{
|
|
|
225
232
|
}, "strip", z.ZodTypeAny, {
|
|
226
233
|
code: string;
|
|
227
234
|
name: string;
|
|
228
|
-
toolId: string;
|
|
229
235
|
usageDescription: string;
|
|
230
236
|
inputSchema: {
|
|
231
237
|
type: IOSchemaType;
|
|
@@ -251,7 +257,13 @@ export declare const toolSchema: z.ZodObject<{
|
|
|
251
257
|
subType?: string | undefined;
|
|
252
258
|
}[];
|
|
253
259
|
};
|
|
254
|
-
|
|
260
|
+
toolId: string;
|
|
261
|
+
contractId?: string | undefined;
|
|
262
|
+
contractVersion?: number | undefined;
|
|
263
|
+
toolName?: string | undefined;
|
|
264
|
+
catalogIdentity?: "deterministic" | "legacy-alias" | undefined;
|
|
265
|
+
catalogState?: "resolved" | "unresolved" | "quarantined" | undefined;
|
|
266
|
+
catalogReason?: string | undefined;
|
|
255
267
|
configSchema?: {
|
|
256
268
|
type: IOSchemaType;
|
|
257
269
|
fields: {
|
|
@@ -264,15 +276,15 @@ export declare const toolSchema: z.ZodObject<{
|
|
|
264
276
|
subType?: string | undefined;
|
|
265
277
|
}[];
|
|
266
278
|
} | undefined;
|
|
267
|
-
codeRepository?: string | undefined;
|
|
268
279
|
isAssistantRunner?: boolean | undefined;
|
|
280
|
+
detailedDescription?: string | undefined;
|
|
281
|
+
codeRepository?: string | undefined;
|
|
269
282
|
packageId?: string | undefined;
|
|
270
283
|
authorityPropagation?: "preserve" | "cap" | undefined;
|
|
271
284
|
accessLevel?: number | undefined;
|
|
272
285
|
remoteAccessLevel?: number | undefined;
|
|
273
286
|
}, {
|
|
274
287
|
name: string;
|
|
275
|
-
toolId: string;
|
|
276
288
|
usageDescription: string;
|
|
277
289
|
inputSchema: {
|
|
278
290
|
type: IOSchemaType;
|
|
@@ -298,8 +310,14 @@ export declare const toolSchema: z.ZodObject<{
|
|
|
298
310
|
subType?: string | undefined;
|
|
299
311
|
}[] | undefined;
|
|
300
312
|
};
|
|
313
|
+
toolId: string;
|
|
301
314
|
code?: string | undefined;
|
|
302
|
-
|
|
315
|
+
contractId?: string | undefined;
|
|
316
|
+
contractVersion?: number | undefined;
|
|
317
|
+
toolName?: string | undefined;
|
|
318
|
+
catalogIdentity?: "deterministic" | "legacy-alias" | undefined;
|
|
319
|
+
catalogState?: "resolved" | "unresolved" | "quarantined" | undefined;
|
|
320
|
+
catalogReason?: string | undefined;
|
|
303
321
|
configSchema?: {
|
|
304
322
|
type: IOSchemaType;
|
|
305
323
|
fields?: {
|
|
@@ -312,8 +330,9 @@ export declare const toolSchema: z.ZodObject<{
|
|
|
312
330
|
subType?: string | undefined;
|
|
313
331
|
}[] | undefined;
|
|
314
332
|
} | undefined;
|
|
315
|
-
codeRepository?: string | undefined;
|
|
316
333
|
isAssistantRunner?: boolean | undefined;
|
|
334
|
+
detailedDescription?: string | undefined;
|
|
335
|
+
codeRepository?: string | undefined;
|
|
317
336
|
packageId?: string | undefined;
|
|
318
337
|
authorityPropagation?: "preserve" | "cap" | undefined;
|
|
319
338
|
accessLevel?: number | undefined;
|
|
@@ -321,7 +340,10 @@ export declare const toolSchema: z.ZodObject<{
|
|
|
321
340
|
}>;
|
|
322
341
|
/** A tool definition stored in the Tools table. */
|
|
323
342
|
export type ITool = z.infer<typeof toolSchema>;
|
|
324
|
-
/**
|
|
343
|
+
/**
|
|
344
|
+
* Historical tool instance shape used by older packages.
|
|
345
|
+
* @deprecated Use IContractToolImplementation with a contract resolver.
|
|
346
|
+
*/
|
|
325
347
|
export interface IToolInstance {
|
|
326
348
|
tool: ITool;
|
|
327
349
|
toolFn: (...args: any[]) => any;
|
|
@@ -336,7 +358,6 @@ export interface IToolInstance {
|
|
|
336
358
|
export declare function Tools(dataContext?: DataContext): import("..").Table<{
|
|
337
359
|
code: string;
|
|
338
360
|
name: string;
|
|
339
|
-
toolId: string;
|
|
340
361
|
usageDescription: string;
|
|
341
362
|
inputSchema: {
|
|
342
363
|
type: IOSchemaType;
|
|
@@ -362,7 +383,13 @@ export declare function Tools(dataContext?: DataContext): import("..").Table<{
|
|
|
362
383
|
subType?: string | undefined;
|
|
363
384
|
}[];
|
|
364
385
|
};
|
|
365
|
-
|
|
386
|
+
toolId: string;
|
|
387
|
+
contractId?: string | undefined;
|
|
388
|
+
contractVersion?: number | undefined;
|
|
389
|
+
toolName?: string | undefined;
|
|
390
|
+
catalogIdentity?: "deterministic" | "legacy-alias" | undefined;
|
|
391
|
+
catalogState?: "resolved" | "unresolved" | "quarantined" | undefined;
|
|
392
|
+
catalogReason?: string | undefined;
|
|
366
393
|
configSchema?: {
|
|
367
394
|
type: IOSchemaType;
|
|
368
395
|
fields: {
|
|
@@ -375,8 +402,9 @@ export declare function Tools(dataContext?: DataContext): import("..").Table<{
|
|
|
375
402
|
subType?: string | undefined;
|
|
376
403
|
}[];
|
|
377
404
|
} | undefined;
|
|
378
|
-
codeRepository?: string | undefined;
|
|
379
405
|
isAssistantRunner?: boolean | undefined;
|
|
406
|
+
detailedDescription?: string | undefined;
|
|
407
|
+
codeRepository?: string | undefined;
|
|
380
408
|
packageId?: string | undefined;
|
|
381
409
|
authorityPropagation?: "preserve" | "cap" | undefined;
|
|
382
410
|
accessLevel?: number | undefined;
|
package/dist/data/tools.js
CHANGED
|
@@ -1,14 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.toolSchema = exports.ioSchema = exports.IOSchemaType = void 0;
|
|
3
|
+
exports.toolSchema = exports.ioSchema = exports.IOSchemaType = exports.toolCatalogSupplementalFields = exports.toolCatalogPatchFields = exports.toolCatalogPatch = exports.toolCatalogIdentityFields = exports.toolCatalogContractDescriptiveFields = exports.isToolCatalogPatch = void 0;
|
|
4
4
|
exports.Tools = Tools;
|
|
5
5
|
const zod_1 = require("zod");
|
|
6
6
|
const user_context_singleton_1 = require("../context/user-context-singleton");
|
|
7
|
+
const tool_catalog_identity_1 = require("../contracts/tool-catalog-identity");
|
|
7
8
|
const field_type_1 = require("../types/field-type");
|
|
8
9
|
const zod_types_1 = require("../types/zod-types");
|
|
9
10
|
const access_level_1 = require("./access-level");
|
|
10
11
|
const table_definitions_system_1 = require("./orm/table-definitions.system");
|
|
11
12
|
const types_1 = require("./orm/types");
|
|
13
|
+
var tool_catalog_fields_1 = require("./tool-catalog-fields");
|
|
14
|
+
Object.defineProperty(exports, "isToolCatalogPatch", { enumerable: true, get: function () { return tool_catalog_fields_1.isToolCatalogPatch; } });
|
|
15
|
+
Object.defineProperty(exports, "toolCatalogContractDescriptiveFields", { enumerable: true, get: function () { return tool_catalog_fields_1.toolCatalogContractDescriptiveFields; } });
|
|
16
|
+
Object.defineProperty(exports, "toolCatalogIdentityFields", { enumerable: true, get: function () { return tool_catalog_fields_1.toolCatalogIdentityFields; } });
|
|
17
|
+
Object.defineProperty(exports, "toolCatalogPatch", { enumerable: true, get: function () { return tool_catalog_fields_1.toolCatalogPatch; } });
|
|
18
|
+
Object.defineProperty(exports, "toolCatalogPatchFields", { enumerable: true, get: function () { return tool_catalog_fields_1.toolCatalogPatchFields; } });
|
|
19
|
+
Object.defineProperty(exports, "toolCatalogSupplementalFields", { enumerable: true, get: function () { return tool_catalog_fields_1.toolCatalogSupplementalFields; } });
|
|
12
20
|
/** Shape of a tool input, output, or config schema. */
|
|
13
21
|
var IOSchemaType;
|
|
14
22
|
(function (IOSchemaType) {
|
|
@@ -23,7 +31,13 @@ exports.ioSchema = zod_1.z.object({
|
|
|
23
31
|
});
|
|
24
32
|
/** Zod schema for a persisted {@link ITool} row. */
|
|
25
33
|
exports.toolSchema = zod_1.z.object({
|
|
26
|
-
toolId:
|
|
34
|
+
toolId: zod_1.z.string().refine(tool_catalog_identity_1.isCatalogToolId, "Invalid tool ID"),
|
|
35
|
+
contractId: zod_1.z.string().refine(tool_catalog_identity_1.isCatalogContractId, "Invalid catalog contract ID").optional(),
|
|
36
|
+
contractVersion: zod_1.z.number().int().positive().max(Number.MAX_SAFE_INTEGER).optional(),
|
|
37
|
+
toolName: zod_1.z.string().optional(),
|
|
38
|
+
catalogIdentity: zod_1.z.enum(["deterministic", "legacy-alias"]).optional(),
|
|
39
|
+
catalogState: zod_1.z.enum(["resolved", "unresolved", "quarantined"]).optional(),
|
|
40
|
+
catalogReason: zod_1.z.string().optional(),
|
|
27
41
|
name: zod_1.z.string().describe("The name of the tool"),
|
|
28
42
|
usageDescription: zod_1.z
|
|
29
43
|
.string()
|
|
@@ -37,17 +51,22 @@ exports.toolSchema = zod_1.z.object({
|
|
|
37
51
|
configSchema: exports.ioSchema
|
|
38
52
|
.optional()
|
|
39
53
|
.describe("The schema of any configuration values that the tool may need"),
|
|
40
|
-
code: zod_1.z
|
|
54
|
+
code: zod_1.z
|
|
55
|
+
.string()
|
|
56
|
+
.default("")
|
|
57
|
+
.describe("Historical tool source; this runtime never writes or executes it"),
|
|
41
58
|
codeRepository: zod_1.z
|
|
42
59
|
.string()
|
|
43
60
|
.optional()
|
|
44
|
-
.describe("
|
|
61
|
+
.describe("Historical source repository; this runtime never writes or executes it"),
|
|
45
62
|
// TODO versioning somehow, maybe a git tag or branch
|
|
46
63
|
isAssistantRunner: zod_1.z
|
|
47
64
|
.boolean()
|
|
48
65
|
.optional()
|
|
49
66
|
.describe("Whether this tool is a model that can be used to run an assistant"),
|
|
50
|
-
packageId: zod_types_1.zodPeerId
|
|
67
|
+
packageId: zod_types_1.zodPeerId
|
|
68
|
+
.optional()
|
|
69
|
+
.describe("Historical package provenance; not ownership, availability or permission"),
|
|
51
70
|
authorityPropagation: zod_1.z
|
|
52
71
|
.enum(["cap", "preserve"])
|
|
53
72
|
.optional()
|
|
@@ -65,12 +84,16 @@ exports.toolSchema = zod_1.z.object({
|
|
|
65
84
|
});
|
|
66
85
|
const metaData = {
|
|
67
86
|
name: "Tools",
|
|
68
|
-
description: "
|
|
87
|
+
description: "Permanent public contract tool catalog and preserved legacy tools.",
|
|
69
88
|
primaryKeyName: "toolId",
|
|
70
89
|
fields: (0, types_1.schemaToFields)(exports.toolSchema),
|
|
71
90
|
iconClassName: "bi bi-tools",
|
|
72
|
-
indexes: [
|
|
73
|
-
|
|
91
|
+
indexes: [
|
|
92
|
+
{ fields: ["name"] },
|
|
93
|
+
{ fields: ["isAssistantRunner"] },
|
|
94
|
+
{ fields: ["contractId", "contractVersion", "toolName"] },
|
|
95
|
+
],
|
|
96
|
+
versionNumber: 2,
|
|
74
97
|
};
|
|
75
98
|
(0, table_definitions_system_1.registerSystemTableDefinition)(metaData, exports.toolSchema);
|
|
76
99
|
/**
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import type { DataContext } from "../context/data-context";
|
|
3
|
+
/** Persisted execution logs and tool results for one workflow. */
|
|
3
4
|
export declare const workflowLogSchema: z.ZodObject<{
|
|
4
5
|
workflowLogId: z.ZodEffects<z.ZodString, string, string>;
|
|
5
6
|
workflowRunId: z.ZodEffects<z.ZodString, string, string>;
|
|
@@ -52,8 +53,8 @@ export declare const workflowLogSchema: z.ZodObject<{
|
|
|
52
53
|
contextId: string;
|
|
53
54
|
logText: string;
|
|
54
55
|
toolId?: string | undefined;
|
|
55
|
-
result?: string | undefined;
|
|
56
56
|
logDT?: Date | undefined;
|
|
57
|
+
result?: string | undefined;
|
|
57
58
|
instruction?: {
|
|
58
59
|
markdown?: string | undefined;
|
|
59
60
|
onError?: string | undefined;
|
|
@@ -65,7 +66,9 @@ export declare const workflowLogSchema: z.ZodObject<{
|
|
|
65
66
|
resultObject?: any[] | z.objectInputType<{}, z.ZodAny, "strip"> | undefined;
|
|
66
67
|
isError?: boolean | undefined;
|
|
67
68
|
}>;
|
|
69
|
+
/** A persisted workflow execution log record. */
|
|
68
70
|
export type IWorkflowLog = z.infer<typeof workflowLogSchema>;
|
|
71
|
+
/** Read or write workflow logs in the specified context. */
|
|
69
72
|
export declare function WorkflowLogs(dataContext?: DataContext): import("..").Table<{
|
|
70
73
|
workflowRunId: string;
|
|
71
74
|
workflowLogId: string;
|
|
@@ -85,7 +88,8 @@ export declare function WorkflowLogs(dataContext?: DataContext): import("..").Ta
|
|
|
85
88
|
resultObject?: any[] | z.objectOutputType<{}, z.ZodAny, "strip"> | undefined;
|
|
86
89
|
isError?: boolean | undefined;
|
|
87
90
|
}>;
|
|
88
|
-
|
|
91
|
+
/** Bind a logger to its run and owning context, independent of the active group. */
|
|
92
|
+
export declare const getLogger: (workflowRunId: string, contextId: string, dataContext?: DataContext) => (logData: string | Omit<Partial<IWorkflowLog>, "workflowRunId" | "workflowLogId">) => Promise<{
|
|
89
93
|
workflowRunId: string;
|
|
90
94
|
workflowLogId: string;
|
|
91
95
|
contextId: string;
|
|
@@ -9,6 +9,7 @@ const zod_types_1 = require("../types/zod-types");
|
|
|
9
9
|
const utils_1 = require("../utils");
|
|
10
10
|
const table_definitions_system_1 = require("./orm/table-definitions.system");
|
|
11
11
|
const types_1 = require("./orm/types");
|
|
12
|
+
/** Persisted execution logs and tool results for one workflow. */
|
|
12
13
|
exports.workflowLogSchema = zod_1.z.object({
|
|
13
14
|
workflowLogId: zod_types_1.zodPeerId,
|
|
14
15
|
workflowRunId: zod_types_1.zodPeerId.describe("The workflow run that this log entry is associated with"),
|
|
@@ -39,22 +40,24 @@ const metaData = {
|
|
|
39
40
|
localOnly: true,
|
|
40
41
|
};
|
|
41
42
|
(0, table_definitions_system_1.registerSystemTableDefinition)(metaData, exports.workflowLogSchema);
|
|
43
|
+
/** Read or write workflow logs in the specified context. */
|
|
42
44
|
function WorkflowLogs(dataContext) {
|
|
43
45
|
return (0, user_context_singleton_1.getTableContainer)(dataContext).getTable(metaData, exports.workflowLogSchema);
|
|
44
46
|
}
|
|
45
|
-
|
|
47
|
+
/** Bind a logger to its run and owning context, independent of the active group. */
|
|
48
|
+
const getLogger = (workflowRunId, contextId, dataContext) => {
|
|
46
49
|
return async (logData) => {
|
|
47
50
|
try {
|
|
48
51
|
let logRecord;
|
|
49
52
|
if (typeof logData === "string") {
|
|
50
|
-
logRecord = WorkflowLogs().initRecord({
|
|
53
|
+
logRecord = WorkflowLogs(dataContext).initRecord({
|
|
51
54
|
workflowRunId,
|
|
52
55
|
workflowLogId: (0, utils_1.newid)(),
|
|
53
56
|
logText: logData,
|
|
54
57
|
});
|
|
55
58
|
}
|
|
56
59
|
else {
|
|
57
|
-
logRecord = WorkflowLogs().initRecord({
|
|
60
|
+
logRecord = WorkflowLogs(dataContext).initRecord({
|
|
58
61
|
workflowRunId,
|
|
59
62
|
workflowLogId: (0, utils_1.newid)(),
|
|
60
63
|
...logData,
|
|
@@ -63,7 +66,7 @@ const getLogger = (workflowRunId, contextId) => {
|
|
|
63
66
|
logRecord.workflowRunId = workflowRunId;
|
|
64
67
|
logRecord.logText = logRecord.logText || "";
|
|
65
68
|
logRecord.contextId = contextId;
|
|
66
|
-
return await WorkflowLogs().insert(logRecord);
|
|
69
|
+
return await WorkflowLogs(dataContext).insert(logRecord);
|
|
67
70
|
}
|
|
68
71
|
catch (err) {
|
|
69
72
|
// console.error(`Error recording log for assistant run - assistantId: ${assistantId}, messageId: ${messageId}, logData: ${logData}`, err);
|
|
@@ -73,4 +76,3 @@ const getLogger = (workflowRunId, contextId) => {
|
|
|
73
76
|
};
|
|
74
77
|
};
|
|
75
78
|
exports.getLogger = getLogger;
|
|
76
|
-
// export type IWorkflowLogger = ReturnType<typeof getLogger>;
|
|
@@ -33,7 +33,6 @@ export declare const workflowRunSchema: z.ZodObject<{
|
|
|
33
33
|
defaultAssistantId: z.ZodEffects<z.ZodString, string, string>;
|
|
34
34
|
}, "strip", z.ZodTypeAny, {
|
|
35
35
|
createdAt: Date;
|
|
36
|
-
workflowRunId: string;
|
|
37
36
|
defaultAssistantId: string;
|
|
38
37
|
instructions: {
|
|
39
38
|
markdown?: string | undefined;
|
|
@@ -41,12 +40,13 @@ export declare const workflowRunSchema: z.ZodObject<{
|
|
|
41
40
|
directCallToolId?: string | undefined;
|
|
42
41
|
subWorkflowId?: string | undefined;
|
|
43
42
|
}[];
|
|
44
|
-
parentMessageId: string;
|
|
45
|
-
currentInstructionIndex: number;
|
|
46
|
-
instructionResults: any[];
|
|
47
43
|
vars: {} & {
|
|
48
44
|
[k: string]: any;
|
|
49
45
|
};
|
|
46
|
+
workflowRunId: string;
|
|
47
|
+
parentMessageId: string;
|
|
48
|
+
currentInstructionIndex: number;
|
|
49
|
+
instructionResults: any[];
|
|
50
50
|
workflowId?: string | undefined;
|
|
51
51
|
scheduleDT?: Date | undefined;
|
|
52
52
|
inErrorState?: boolean | undefined;
|
|
@@ -54,8 +54,8 @@ export declare const workflowRunSchema: z.ZodObject<{
|
|
|
54
54
|
completedAt?: Date | undefined;
|
|
55
55
|
parentWorkflowRunId?: string | undefined;
|
|
56
56
|
}, {
|
|
57
|
-
workflowRunId: string;
|
|
58
57
|
defaultAssistantId: string;
|
|
58
|
+
workflowRunId: string;
|
|
59
59
|
parentMessageId: string;
|
|
60
60
|
createdAt?: Date | undefined;
|
|
61
61
|
workflowId?: string | undefined;
|
|
@@ -65,13 +65,13 @@ export declare const workflowRunSchema: z.ZodObject<{
|
|
|
65
65
|
directCallToolId?: string | undefined;
|
|
66
66
|
subWorkflowId?: string | undefined;
|
|
67
67
|
}[] | undefined;
|
|
68
|
+
vars?: z.objectInputType<{}, z.ZodAny, "strip"> | undefined;
|
|
68
69
|
scheduleDT?: Date | undefined;
|
|
69
70
|
currentInstructionIndex?: number | undefined;
|
|
70
71
|
instructionResults?: any[] | undefined;
|
|
71
72
|
inErrorState?: boolean | undefined;
|
|
72
73
|
startedAt?: Date | undefined;
|
|
73
74
|
completedAt?: Date | undefined;
|
|
74
|
-
vars?: z.objectInputType<{}, z.ZodAny, "strip"> | undefined;
|
|
75
75
|
parentWorkflowRunId?: string | undefined;
|
|
76
76
|
}>;
|
|
77
77
|
export type IWorkflowRun = z.infer<typeof workflowRunSchema>;
|
package/dist/index.d.ts
CHANGED
|
@@ -38,8 +38,6 @@ export * from "./peers-ui/peers-ui.types";
|
|
|
38
38
|
export * from "./rpc-types";
|
|
39
39
|
export * from "./serial-json";
|
|
40
40
|
export * from "./system-ids";
|
|
41
|
-
export * from "./tools";
|
|
42
|
-
export * as tools from "./tools";
|
|
43
41
|
export * from "./types/app-nav";
|
|
44
42
|
export * from "./types/assistant-runner-args";
|
|
45
43
|
export * from "./types/field-type";
|
package/dist/index.js
CHANGED
|
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.
|
|
17
|
+
exports.workflowLogSchema = exports.WorkflowLogs = exports.getLogger = exports.orm = exports.data = void 0;
|
|
18
18
|
__exportStar(require("./context"), exports);
|
|
19
19
|
__exportStar(require("./contracts"), exports);
|
|
20
20
|
__exportStar(require("./data"), exports);
|
|
@@ -59,8 +59,6 @@ __exportStar(require("./peers-ui/peers-ui.types"), exports);
|
|
|
59
59
|
__exportStar(require("./rpc-types"), exports);
|
|
60
60
|
__exportStar(require("./serial-json"), exports);
|
|
61
61
|
__exportStar(require("./system-ids"), exports);
|
|
62
|
-
__exportStar(require("./tools"), exports);
|
|
63
|
-
exports.tools = require("./tools");
|
|
64
62
|
__exportStar(require("./types/app-nav"), exports);
|
|
65
63
|
__exportStar(require("./types/assistant-runner-args"), exports);
|
|
66
64
|
__exportStar(require("./types/field-type"), exports);
|
|
@@ -27,30 +27,39 @@ export declare function ensureTemplateCache(deps: IPackageInstallerDeps, templat
|
|
|
27
27
|
/**
|
|
28
28
|
* Resolve (or create) the Ed25519 publish public key for a package.
|
|
29
29
|
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
30
|
+
* Never rotates an established identity. Checks the Packages key, the public key
|
|
31
|
+
* cached in the personal signing pvar's description, and any key recoverable from
|
|
32
|
+
* its secret for agreement before writing. Hosts may decrypt legacy secrets via
|
|
33
|
+
* `resolveSigningPublicKey`; plaintext secrets never need to leave the host.
|
|
34
|
+
* Lazily caches recovered public keys without changing the stored secret value.
|
|
35
|
+
* Generates keys only when both the secret and every public-key source are missing.
|
|
33
36
|
*
|
|
34
|
-
* @throws When
|
|
37
|
+
* @throws When recovered public keys disagree, or a secret has no recoverable public key.
|
|
35
38
|
*/
|
|
36
39
|
export declare function ensurePackageSigningKey(opts: {
|
|
37
40
|
personalContext?: DataContext;
|
|
38
41
|
packageId: string;
|
|
39
42
|
packageName: string;
|
|
40
43
|
existingPublishPublicKey?: string;
|
|
44
|
+
/** Host-only recovery of a public key from an encrypted personal signing secret. */
|
|
45
|
+
resolveSigningPublicKey?: ICreatePackageOpts["resolveSigningPublicKey"];
|
|
41
46
|
}): Promise<string>;
|
|
42
47
|
/**
|
|
43
48
|
* Import an existing on-disk Peers package directory into the current data context.
|
|
44
49
|
*
|
|
45
50
|
* Validates the manifest packageId, creates/updates the Packages record, persists
|
|
46
51
|
* `packageLocalPath_*`, provisions a signing key when missing, then installs the
|
|
47
|
-
* local dev bundles.
|
|
52
|
+
* local dev bundles. When the target Packages row is absent, reuses the first
|
|
53
|
+
* nonblank public key for the same packageId from the user's personal context
|
|
54
|
+
* or groups. Other contexts' package metadata is not copied.
|
|
48
55
|
*/
|
|
49
56
|
export declare function importExistingPackage(dataContext: DataContext, deps: IPackageInstallerDeps, opts: {
|
|
50
57
|
location: string;
|
|
51
58
|
personalContext?: DataContext;
|
|
52
59
|
/** Display name fallback when the manifest name is a slug. */
|
|
53
60
|
displayName?: string;
|
|
61
|
+
/** Host-only recovery of a public key from an encrypted personal signing secret. */
|
|
62
|
+
resolveSigningPublicKey?: ICreatePackageOpts["resolveSigningPublicKey"];
|
|
54
63
|
}): Promise<ICreatePackageResult>;
|
|
55
64
|
/**
|
|
56
65
|
* Create a new Peers package from the package template.
|
|
@@ -106,63 +106,96 @@ async function ensureTemplateCache(deps, templateRepo) {
|
|
|
106
106
|
await deps.shell.exec(`git clone ${templateRepo} ${cachePath}`);
|
|
107
107
|
return { cachePath };
|
|
108
108
|
}
|
|
109
|
+
const SIGNING_KEY_MARKER_PREFIX = "peers-package-signing-key:";
|
|
110
|
+
function validSigningPublicKey(value) {
|
|
111
|
+
return typeof value === "string" && (0, keys_1.derivePublicBoxKey)(value) ? value : undefined;
|
|
112
|
+
}
|
|
113
|
+
function cachedSigningPublicKey(description, packageId) {
|
|
114
|
+
const markers = (description || "")
|
|
115
|
+
.split(/\r?\n/)
|
|
116
|
+
.filter((line) => line.startsWith(SIGNING_KEY_MARKER_PREFIX));
|
|
117
|
+
if (markers.length !== 1)
|
|
118
|
+
return undefined;
|
|
119
|
+
const match = /^peers-package-signing-key:v1:([^:]+):([^:]+)$/.exec(markers[0]);
|
|
120
|
+
return match?.[1] === packageId ? validSigningPublicKey(match[2]) : undefined;
|
|
121
|
+
}
|
|
122
|
+
function signingKeyDescription(description, packageId, publicKey) {
|
|
123
|
+
const text = description
|
|
124
|
+
.split(/\r?\n/)
|
|
125
|
+
.filter((line) => !line.startsWith(SIGNING_KEY_MARKER_PREFIX))
|
|
126
|
+
.join("\n");
|
|
127
|
+
return `${text}${text ? "\n" : ""}${SIGNING_KEY_MARKER_PREFIX}v1:${packageId}:${publicKey}`;
|
|
128
|
+
}
|
|
109
129
|
/**
|
|
110
130
|
* Resolve (or create) the Ed25519 publish public key for a package.
|
|
111
131
|
*
|
|
112
|
-
*
|
|
113
|
-
*
|
|
114
|
-
*
|
|
132
|
+
* Never rotates an established identity. Checks the Packages key, the public key
|
|
133
|
+
* cached in the personal signing pvar's description, and any key recoverable from
|
|
134
|
+
* its secret for agreement before writing. Hosts may decrypt legacy secrets via
|
|
135
|
+
* `resolveSigningPublicKey`; plaintext secrets never need to leave the host.
|
|
136
|
+
* Lazily caches recovered public keys without changing the stored secret value.
|
|
137
|
+
* Generates keys only when both the secret and every public-key source are missing.
|
|
115
138
|
*
|
|
116
|
-
* @throws When
|
|
139
|
+
* @throws When recovered public keys disagree, or a secret has no recoverable public key.
|
|
117
140
|
*/
|
|
118
141
|
async function ensurePackageSigningKey(opts) {
|
|
119
142
|
const { personalContext, packageId, packageName, existingPublishPublicKey } = opts;
|
|
120
143
|
const establishedKey = existingPublishPublicKey?.trim() || "";
|
|
121
|
-
if (personalContext)
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
144
|
+
if (!personalContext)
|
|
145
|
+
return establishedKey;
|
|
146
|
+
const keyName = `${package_author_signing_1.PACKAGE_SIGNING_KEY_PREFIX}${packageId}`;
|
|
147
|
+
const table = (0, persistent_vars_1.PersistentVars)(personalContext);
|
|
148
|
+
const existingKey = await table.findOne({ name: keyName });
|
|
149
|
+
const rawSecret = existingKey?.value?.value;
|
|
150
|
+
const cachedKey = cachedSigningPublicKey(existingKey?.description, packageId);
|
|
151
|
+
let derivedKey;
|
|
152
|
+
if (typeof rawSecret === "string" && rawSecret.length > 0) {
|
|
153
|
+
try {
|
|
154
|
+
derivedKey = validSigningPublicKey((0, keys_1.hydrateKeys)(rawSecret).publicKey);
|
|
155
|
+
}
|
|
156
|
+
catch {
|
|
157
|
+
// Encrypted-at-rest secrets cannot be hydrated directly by the SDK.
|
|
158
|
+
}
|
|
159
|
+
if (!derivedKey && opts.resolveSigningPublicKey) {
|
|
126
160
|
try {
|
|
127
|
-
|
|
128
|
-
if (establishedKey && derivedPublicKey !== establishedKey) {
|
|
129
|
-
throw new Error(`Package signing key mismatch for "${packageName}" (${packageId}): ` +
|
|
130
|
-
"stored secret does not match Packages.publishPublicKey. " +
|
|
131
|
-
"Refusing to rotate the established key.");
|
|
132
|
-
}
|
|
133
|
-
return establishedKey || derivedPublicKey;
|
|
161
|
+
derivedKey = validSigningPublicKey(await opts.resolveSigningPublicKey(rawSecret));
|
|
134
162
|
}
|
|
135
|
-
catch
|
|
136
|
-
|
|
137
|
-
throw err;
|
|
138
|
-
}
|
|
139
|
-
// Secret is likely encrypted at rest — cannot derive here without the user key.
|
|
140
|
-
if (establishedKey) {
|
|
141
|
-
return establishedKey;
|
|
142
|
-
}
|
|
143
|
-
throw new Error(`Package "${packageName}" (${packageId}) has a signing secret pvar but no ` +
|
|
144
|
-
"publishPublicKey, and the secret could not be hydrated. " +
|
|
145
|
-
"Restore publishPublicKey or replace the unreadable key before importing.");
|
|
163
|
+
catch {
|
|
164
|
+
// Decryption is best-effort. Never expose ciphertext, plaintext, or host errors.
|
|
146
165
|
}
|
|
147
166
|
}
|
|
148
167
|
}
|
|
149
|
-
|
|
150
|
-
|
|
168
|
+
const publicKey = establishedKey || cachedKey || derivedKey;
|
|
169
|
+
if ([establishedKey, cachedKey, derivedKey].some((key) => key && key !== publicKey)) {
|
|
170
|
+
throw new Error(`Package signing key mismatch for "${packageName}" (${packageId}): ` +
|
|
171
|
+
"Packages.publishPublicKey, cached public key, and stored secret must agree. " +
|
|
172
|
+
"Refusing to rotate the established key.");
|
|
151
173
|
}
|
|
152
|
-
if (
|
|
153
|
-
|
|
174
|
+
if (publicKey) {
|
|
175
|
+
if (existingKey && validSigningPublicKey(publicKey)) {
|
|
176
|
+
const description = signingKeyDescription(existingKey.description || "", packageId, publicKey);
|
|
177
|
+
if (description !== existingKey.description) {
|
|
178
|
+
// Keep the ciphertext identical so PersistentVarsTable.save does not encrypt it again.
|
|
179
|
+
await table.save({ ...existingKey, description });
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
return publicKey;
|
|
183
|
+
}
|
|
184
|
+
if (rawSecret !== undefined && rawSecret !== null && rawSecret !== "") {
|
|
185
|
+
throw new Error(`Package "${packageName}" (${packageId}) has a signing secret pvar but no ` +
|
|
186
|
+
"recoverable publishPublicKey, and the secret could not be hydrated. " +
|
|
187
|
+
"Restore publishPublicKey or unlock the signing secret before importing.");
|
|
154
188
|
}
|
|
155
189
|
const keys = (0, keys_1.newKeys)();
|
|
156
|
-
|
|
157
|
-
await (0, persistent_vars_1.PersistentVars)(personalContext).save({
|
|
190
|
+
await table.save({
|
|
158
191
|
persistentVarId: (0, utils_1.deterministicPvarId)(keyName),
|
|
159
192
|
name: keyName,
|
|
160
193
|
scope: "user",
|
|
161
194
|
value: { value: keys.secretKey },
|
|
162
195
|
isSecret: true,
|
|
163
|
-
description: `Signing key for package "${packageName}"`,
|
|
196
|
+
description: signingKeyDescription(`Signing key for package "${packageName}"`, packageId, keys.publicKey),
|
|
164
197
|
modifiedAt: Date.now(),
|
|
165
|
-
});
|
|
198
|
+
}, { restoreIfDeleted: true });
|
|
166
199
|
return keys.publicKey;
|
|
167
200
|
}
|
|
168
201
|
async function registerPackageRecord(dataContext, opts) {
|
|
@@ -195,7 +228,9 @@ async function persistPackageLocalPath(dataContext, deps, packageId, location) {
|
|
|
195
228
|
*
|
|
196
229
|
* Validates the manifest packageId, creates/updates the Packages record, persists
|
|
197
230
|
* `packageLocalPath_*`, provisions a signing key when missing, then installs the
|
|
198
|
-
* local dev bundles.
|
|
231
|
+
* local dev bundles. When the target Packages row is absent, reuses the first
|
|
232
|
+
* nonblank public key for the same packageId from the user's personal context
|
|
233
|
+
* or groups. Other contexts' package metadata is not copied.
|
|
199
234
|
*/
|
|
200
235
|
async function importExistingPackage(dataContext, deps, opts) {
|
|
201
236
|
const info = await (0, package_installer_1.getPackageInfo)(deps, opts.location);
|
|
@@ -204,12 +239,30 @@ async function importExistingPackage(dataContext, deps, opts) {
|
|
|
204
239
|
}
|
|
205
240
|
const packageId = info.packageId;
|
|
206
241
|
const existing = await (0, packages_1.Packages)(dataContext).get(packageId);
|
|
242
|
+
let existingPublishPublicKey = existing?.publishPublicKey;
|
|
243
|
+
const userContext = dataContext.userContext;
|
|
244
|
+
if (!existing && userContext) {
|
|
245
|
+
for (const sourceContext of [
|
|
246
|
+
userContext.userDataContext,
|
|
247
|
+
...userContext.groupDataContexts.values(),
|
|
248
|
+
]) {
|
|
249
|
+
if (sourceContext.dataContextId === dataContext.dataContextId)
|
|
250
|
+
continue;
|
|
251
|
+
const sourcePackage = await (0, packages_1.Packages)(sourceContext).get(packageId);
|
|
252
|
+
const sourcePublicKey = sourcePackage?.publishPublicKey?.trim();
|
|
253
|
+
if (sourcePublicKey) {
|
|
254
|
+
existingPublishPublicKey = sourcePublicKey;
|
|
255
|
+
break;
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
}
|
|
207
259
|
const packageName = opts.displayName || info.name || packageId;
|
|
208
260
|
const publishPublicKey = await ensurePackageSigningKey({
|
|
209
261
|
personalContext: opts.personalContext,
|
|
210
262
|
packageId,
|
|
211
263
|
packageName,
|
|
212
|
-
existingPublishPublicKey
|
|
264
|
+
existingPublishPublicKey,
|
|
265
|
+
resolveSigningPublicKey: opts.resolveSigningPublicKey,
|
|
213
266
|
});
|
|
214
267
|
await registerPackageRecord(dataContext, {
|
|
215
268
|
packageId,
|
|
@@ -248,6 +301,7 @@ async function createPackage(dataContext, deps, opts) {
|
|
|
248
301
|
location,
|
|
249
302
|
personalContext: opts.personalContext,
|
|
250
303
|
displayName: opts.name,
|
|
304
|
+
resolveSigningPublicKey: opts.resolveSigningPublicKey,
|
|
251
305
|
});
|
|
252
306
|
}
|
|
253
307
|
await (0, package_dev_tools_1.assertPackageDevTools)(deps);
|
|
@@ -313,6 +367,7 @@ async function createPackage(dataContext, deps, opts) {
|
|
|
313
367
|
personalContext: opts.personalContext,
|
|
314
368
|
packageId,
|
|
315
369
|
packageName: opts.name,
|
|
370
|
+
resolveSigningPublicKey: opts.resolveSigningPublicKey,
|
|
316
371
|
});
|
|
317
372
|
await registerPackageRecord(dataContext, {
|
|
318
373
|
packageId,
|