@peers-app/peers-sdk 0.25.21 → 0.26.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/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 +924 -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 +96 -0
- package/dist/contracts/tool-catalog.js +542 -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-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-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 +674 -1
- 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);
|
|
@@ -1,18 +1,27 @@
|
|
|
1
1
|
import type { DataContext } from "../context/data-context";
|
|
2
|
-
import
|
|
2
|
+
import { ContractRegistry } from "../contracts/registry";
|
|
3
3
|
import type { IPackageDefinitionResult } from "../contracts/types";
|
|
4
4
|
/**
|
|
5
5
|
* Installs a contract-based package into a DataContext.
|
|
6
6
|
*
|
|
7
7
|
* Handles packages that export an `IPackageDefinitionResult` from `definePackage()`.
|
|
8
|
-
*
|
|
9
|
-
*
|
|
8
|
+
* Materializes catalog identities and supplemental metadata, publishes contract providers,
|
|
9
|
+
* saves package assistants and registers table definitions after successful preparation.
|
|
10
10
|
*
|
|
11
11
|
* When a contract version was previously frozen (promoted to stable), the
|
|
12
12
|
* installer preserves its stable status rather than re-registering it as dev.
|
|
13
|
+
* Without `opts.registry` or the context's PackageLoader registry, catalog rows
|
|
14
|
+
* are still written but no provider is published.
|
|
13
15
|
*/
|
|
14
16
|
export declare function installContractPackage(dataContext: DataContext, packageDefinition: IPackageDefinitionResult, opts?: {
|
|
17
|
+
/** Registry to publish into; defaults to the context's PackageLoader registry. */
|
|
15
18
|
registry?: ContractRegistry;
|
|
19
|
+
/** Complete fallible loader bookkeeping before provider publication. */
|
|
20
|
+
prepare?: () => Promise<void>;
|
|
21
|
+
/** Publish in-memory loader state in the same serialized activation turn. */
|
|
22
|
+
onActivated?: () => void;
|
|
23
|
+
/** Reject a load invalidated by unload, including after asynchronous preparation. */
|
|
24
|
+
assertCurrent?: () => void;
|
|
16
25
|
}): Promise<void>;
|
|
17
26
|
/**
|
|
18
27
|
* Attempts to extract an `IPackageDefinitionResult` from a bundle's module exports.
|
|
@@ -4,68 +4,72 @@ exports.installContractPackage = installContractPackage;
|
|
|
4
4
|
exports.extractPackageDefinition = extractPackageDefinition;
|
|
5
5
|
exports.hasPackageDefinition = hasPackageDefinition;
|
|
6
6
|
exports.finalizeContractsForPromotion = finalizeContractsForPromotion;
|
|
7
|
-
const
|
|
8
|
-
const
|
|
7
|
+
const registry_1 = require("../contracts/registry");
|
|
8
|
+
const tool_catalog_1 = require("../contracts/tool-catalog");
|
|
9
9
|
/**
|
|
10
10
|
* Installs a contract-based package into a DataContext.
|
|
11
11
|
*
|
|
12
12
|
* Handles packages that export an `IPackageDefinitionResult` from `definePackage()`.
|
|
13
|
-
*
|
|
14
|
-
*
|
|
13
|
+
* Materializes catalog identities and supplemental metadata, publishes contract providers,
|
|
14
|
+
* saves package assistants and registers table definitions after successful preparation.
|
|
15
15
|
*
|
|
16
16
|
* When a contract version was previously frozen (promoted to stable), the
|
|
17
17
|
* installer preserves its stable status rather than re-registering it as dev.
|
|
18
|
+
* Without `opts.registry` or the context's PackageLoader registry, catalog rows
|
|
19
|
+
* are still written but no provider is published.
|
|
18
20
|
*/
|
|
19
21
|
async function installContractPackage(dataContext, packageDefinition, opts) {
|
|
20
22
|
const { packageId } = packageDefinition;
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
23
|
+
const sharedRegistry = opts?.registry ?? dataContext.packageLoader?.contractRegistry;
|
|
24
|
+
// Without a context registry, providers go to a throwaway registry (none are
|
|
25
|
+
// published, as before) whose catalog is disposed with this call.
|
|
26
|
+
const registry = sharedRegistry ?? new registry_1.ContractRegistry();
|
|
27
|
+
const registrations = packageDefinition.contracts.map((contract) => {
|
|
28
|
+
const key = `${contract.contractId}@${contract.version}`;
|
|
29
|
+
const existing = registry.getDefinition(contract.contractId, contract.version);
|
|
30
|
+
const definition = existing && !existing.devTag && contract.devTag === "dev"
|
|
31
|
+
? { ...contract, devTag: undefined }
|
|
32
|
+
: contract;
|
|
33
|
+
return { definition, alsoImplements: packageDefinition.alsoImplements.get(key) ?? [] };
|
|
34
|
+
});
|
|
35
|
+
const catalog = registry.toolCatalog ?? new tool_catalog_1.ToolCatalog(dataContext, registry);
|
|
36
|
+
const prepare = async () => {
|
|
37
|
+
opts?.assertCurrent?.();
|
|
38
|
+
// Install assistants with packageId
|
|
39
|
+
const { Assistants } = await Promise.resolve().then(() => require("../data/assistants"));
|
|
40
|
+
for (const assistant of packageDefinition.assistants) {
|
|
41
|
+
const assistantWithPackageId = { ...assistant, packageId };
|
|
42
|
+
await Assistants(dataContext).save(assistantWithPackageId);
|
|
43
|
+
}
|
|
44
|
+
await opts?.prepare?.();
|
|
45
|
+
};
|
|
46
|
+
const activate = () => {
|
|
47
|
+
opts?.assertCurrent?.();
|
|
48
|
+
// Publish table definitions in the guarded activation turn, after the
|
|
49
|
+
// coordinator's final catalog writes. Preparation must leave live tables alone.
|
|
50
|
+
if (packageDefinition.tableDefinitions.length) {
|
|
51
|
+
dataContext.tableContainer.registerTableDefinitions(packageDefinition.tableDefinitions, {
|
|
52
|
+
overwrite: true,
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
// Activate the new provider only after all fallible package-owned persistence
|
|
56
|
+
// has succeeded, so a failed update leaves the previous provider routable.
|
|
57
|
+
{
|
|
58
|
+
const result = registry.replaceBatch(packageId, registrations);
|
|
59
|
+
if (!result.valid) {
|
|
60
|
+
throw new Error(`Atomic contract registration failed for package ${packageId}: ${result.errors
|
|
61
|
+
.map((error) => error.message)
|
|
62
|
+
.join("; ")}`);
|
|
32
63
|
}
|
|
33
|
-
return { definition: effectiveContract, alsoImplements: alsoImpl };
|
|
34
|
-
})
|
|
35
|
-
: undefined;
|
|
36
|
-
const validation = registrations ? registry?.validateBatch(packageId, registrations) : undefined;
|
|
37
|
-
if (validation && !validation.valid) {
|
|
38
|
-
throw new Error(`Atomic contract registration failed for package ${packageId}: ${validation.errors
|
|
39
|
-
.map((error) => error.message)
|
|
40
|
-
.join("; ")}`);
|
|
41
|
-
}
|
|
42
|
-
// Install tool instances with packageId
|
|
43
|
-
for (const toolInstance of packageDefinition.toolInstances) {
|
|
44
|
-
(0, tools_2.registerTool)(toolInstance);
|
|
45
|
-
const toolWithPackageId = { ...toolInstance.tool, packageId };
|
|
46
|
-
await (0, tools_1.Tools)(dataContext).save(toolWithPackageId);
|
|
47
|
-
}
|
|
48
|
-
// Install table definitions
|
|
49
|
-
for (const tableDefinition of packageDefinition.tableDefinitions) {
|
|
50
|
-
dataContext.tableContainer.registerTableDefinition(tableDefinition, {
|
|
51
|
-
overwrite: true,
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
// Install assistants with packageId
|
|
55
|
-
const { Assistants } = await Promise.resolve().then(() => require("../data/assistants"));
|
|
56
|
-
for (const assistant of packageDefinition.assistants) {
|
|
57
|
-
const assistantWithPackageId = { ...assistant, packageId };
|
|
58
|
-
await Assistants(dataContext).save(assistantWithPackageId);
|
|
59
|
-
}
|
|
60
|
-
// Activate the new provider only after all fallible package-owned persistence
|
|
61
|
-
// has succeeded, so a failed update leaves the previous provider routable.
|
|
62
|
-
if (registry && registrations) {
|
|
63
|
-
const result = registry.replaceBatch(packageId, registrations);
|
|
64
|
-
if (!result.valid) {
|
|
65
|
-
throw new Error(`Atomic contract registration failed for package ${packageId}: ${result.errors
|
|
66
|
-
.map((error) => error.message)
|
|
67
|
-
.join("; ")}`);
|
|
68
64
|
}
|
|
65
|
+
opts?.onActivated?.();
|
|
66
|
+
};
|
|
67
|
+
try {
|
|
68
|
+
await catalog.publish(packageId, registrations, prepare, activate, packageDefinition.toolMetadata ?? []);
|
|
69
|
+
}
|
|
70
|
+
finally {
|
|
71
|
+
if (!sharedRegistry)
|
|
72
|
+
await catalog.dispose();
|
|
69
73
|
}
|
|
70
74
|
}
|
|
71
75
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
import "../index";
|