@peers-app/peers-sdk 0.27.3 → 0.27.4
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/contract-proxy.d.ts +7 -0
- package/dist/contracts/contract-proxy.js +19 -2
- package/dist/contracts/create-local-consumer.js +16 -1
- package/dist/contracts/index.d.ts +2 -0
- package/dist/contracts/index.js +2 -0
- package/dist/contracts/system/index.d.ts +2 -0
- package/dist/contracts/system/index.js +2 -0
- package/dist/contracts/system/invites-contract.js +2 -1
- package/dist/contracts/system/sync-check-contract.d.ts +97 -0
- package/dist/contracts/system/sync-check-contract.js +115 -0
- package/dist/contracts/tool-arguments.d.ts +15 -0
- package/dist/contracts/tool-arguments.js +41 -0
- package/dist/contracts/tool-catalog-service.js +2 -12
- package/dist/data/change-tracking.d.ts +40 -0
- package/dist/data/change-tracking.js +89 -0
- package/dist/data/orm/types.d.ts +24 -7
- package/dist/data/orm/types.js +97 -24
- package/dist/define/manifest.js +6 -34
- package/dist/package-loader/package-loader.js +27 -22
- package/dist/system-ids.d.ts +5 -0
- package/dist/system-ids.js +6 -1
- package/package.json +4 -2
- package/dist/context/user-context-identity.test.d.ts +0 -1
- package/dist/context/user-context-identity.test.js +0 -220
- package/dist/contracts/__tests__/action-dispatch.test.d.ts +0 -1
- package/dist/contracts/__tests__/action-dispatch.test.js +0 -319
- package/dist/contracts/__tests__/also-implements.test.d.ts +0 -1
- package/dist/contracts/__tests__/also-implements.test.js +0 -110
- package/dist/contracts/__tests__/builder.test.d.ts +0 -1
- package/dist/contracts/__tests__/builder.test.js +0 -669
- package/dist/contracts/__tests__/contract-events.test.d.ts +0 -1
- package/dist/contracts/__tests__/contract-events.test.js +0 -199
- package/dist/contracts/__tests__/contract-observables.test.d.ts +0 -1
- package/dist/contracts/__tests__/contract-observables.test.js +0 -290
- package/dist/contracts/__tests__/contract-provider-router.test.d.ts +0 -1
- package/dist/contracts/__tests__/contract-provider-router.test.js +0 -315
- package/dist/contracts/__tests__/contract-proxy.test.d.ts +0 -1
- package/dist/contracts/__tests__/contract-proxy.test.js +0 -657
- package/dist/contracts/__tests__/contract-resolvers.test.d.ts +0 -1
- package/dist/contracts/__tests__/contract-resolvers.test.js +0 -758
- package/dist/contracts/__tests__/contract-subscription-lifecycle.test.d.ts +0 -1
- package/dist/contracts/__tests__/contract-subscription-lifecycle.test.js +0 -353
- package/dist/contracts/__tests__/contract-table-events.test.d.ts +0 -1
- package/dist/contracts/__tests__/contract-table-events.test.js +0 -209
- package/dist/contracts/__tests__/contract-transport.test.d.ts +0 -1
- package/dist/contracts/__tests__/contract-transport.test.js +0 -163
- package/dist/contracts/__tests__/extract.test.d.ts +0 -1
- package/dist/contracts/__tests__/extract.test.js +0 -145
- package/dist/contracts/__tests__/frozen-contracts.test.d.ts +0 -1
- package/dist/contracts/__tests__/frozen-contracts.test.js +0 -191
- package/dist/contracts/__tests__/generic-tool-dispatch.test.d.ts +0 -1
- package/dist/contracts/__tests__/generic-tool-dispatch.test.js +0 -130
- package/dist/contracts/__tests__/host-contract-client.test.d.ts +0 -1
- package/dist/contracts/__tests__/host-contract-client.test.js +0 -793
- package/dist/contracts/__tests__/host-contract-consumer.test.d.ts +0 -1
- package/dist/contracts/__tests__/host-contract-consumer.test.js +0 -163
- package/dist/contracts/__tests__/host-contract-transport.test.d.ts +0 -1
- package/dist/contracts/__tests__/host-contract-transport.test.js +0 -66
- package/dist/contracts/__tests__/integration.test.d.ts +0 -1
- package/dist/contracts/__tests__/integration.test.js +0 -348
- package/dist/contracts/__tests__/legacy-removal.test.d.ts +0 -1
- package/dist/contracts/__tests__/legacy-removal.test.js +0 -128
- package/dist/contracts/__tests__/persistent-registry.test.d.ts +0 -1
- package/dist/contracts/__tests__/persistent-registry.test.js +0 -109
- package/dist/contracts/__tests__/playground.test.d.ts +0 -1
- package/dist/contracts/__tests__/playground.test.js +0 -216
- package/dist/contracts/__tests__/registry.test.d.ts +0 -1
- package/dist/contracts/__tests__/registry.test.js +0 -238
- package/dist/contracts/__tests__/remote-contract-transport.test.d.ts +0 -1
- package/dist/contracts/__tests__/remote-contract-transport.test.js +0 -119
- package/dist/contracts/__tests__/system-contracts.test.d.ts +0 -1
- package/dist/contracts/__tests__/system-contracts.test.js +0 -247
- package/dist/contracts/__tests__/target-dispatch.d.ts +0 -11
- package/dist/contracts/__tests__/target-dispatch.js +0 -24
- package/dist/contracts/__tests__/tool-catalog-inventory.test.d.ts +0 -1
- package/dist/contracts/__tests__/tool-catalog-inventory.test.js +0 -44
- package/dist/contracts/__tests__/tool-catalog-service.test.d.ts +0 -1
- package/dist/contracts/__tests__/tool-catalog-service.test.js +0 -482
- package/dist/contracts/__tests__/tool-catalog.test.d.ts +0 -1
- package/dist/contracts/__tests__/tool-catalog.test.js +0 -1199
- package/dist/contracts/__tests__/validate.test.d.ts +0 -1
- package/dist/contracts/__tests__/validate.test.js +0 -991
- package/dist/contracts/__tests__/workflow-context.test.d.ts +0 -1
- package/dist/contracts/__tests__/workflow-context.test.js +0 -50
- package/dist/data/access-level.test.d.ts +0 -1
- package/dist/data/access-level.test.js +0 -53
- package/dist/data/change-tracking.test.d.ts +0 -1
- package/dist/data/change-tracking.test.js +0 -62
- package/dist/data/files/files.test.d.ts +0 -1
- package/dist/data/files/files.test.js +0 -770
- package/dist/data/group-members.test.d.ts +0 -1
- package/dist/data/group-members.test.js +0 -336
- package/dist/data/group-share.test.d.ts +0 -1
- package/dist/data/group-share.test.js +0 -110
- package/dist/data/groups.test.d.ts +0 -1
- package/dist/data/groups.test.js +0 -153
- package/dist/data/orm/cursor.test.d.ts +0 -1
- package/dist/data/orm/cursor.test.js +0 -314
- package/dist/data/orm/data-query.mongo.test.d.ts +0 -1
- package/dist/data/orm/data-query.mongo.test.js +0 -367
- package/dist/data/orm/data-query.sqlite.test.d.ts +0 -1
- package/dist/data/orm/data-query.sqlite.test.js +0 -365
- package/dist/data/orm/data-query.test.d.ts +0 -1
- package/dist/data/orm/data-query.test.js +0 -545
- package/dist/data/orm/dependency-injection.test.d.ts +0 -1
- package/dist/data/orm/dependency-injection.test.js +0 -171
- package/dist/data/orm/event-registry.test.d.ts +0 -1
- package/dist/data/orm/event-registry.test.js +0 -44
- package/dist/data/orm/multi-cursors.test.d.ts +0 -1
- package/dist/data/orm/multi-cursors.test.js +0 -463
- package/dist/data/orm/sql.data-source.test.d.ts +0 -1
- package/dist/data/orm/sql.data-source.test.js +0 -731
- package/dist/data/orm/table-container-events.test.d.ts +0 -1
- package/dist/data/orm/table-container-events.test.js +0 -101
- package/dist/data/orm/table-container.test.d.ts +0 -1
- package/dist/data/orm/table-container.test.js +0 -273
- package/dist/data/orm/table.event-source.test.d.ts +0 -1
- package/dist/data/orm/table.event-source.test.js +0 -331
- package/dist/data/orm/types.test.d.ts +0 -1
- package/dist/data/orm/types.test.js +0 -409
- package/dist/data/package-table-identity.test.d.ts +0 -1
- package/dist/data/package-table-identity.test.js +0 -46
- package/dist/data/package-version-permissions.test.d.ts +0 -1
- package/dist/data/package-version-permissions.test.js +0 -107
- package/dist/data/package-version-resolver.test.d.ts +0 -4
- package/dist/data/package-version-resolver.test.js +0 -543
- package/dist/data/package-versions.test.d.ts +0 -1
- package/dist/data/package-versions.test.js +0 -227
- package/dist/data/persistent-vars.conflict.test.d.ts +0 -1
- package/dist/data/persistent-vars.conflict.test.js +0 -126
- package/dist/data/persistent-vars.migration.test.d.ts +0 -1
- package/dist/data/persistent-vars.migration.test.js +0 -133
- package/dist/data/persistent-vars.package-scope.test.d.ts +0 -1
- package/dist/data/persistent-vars.package-scope.test.js +0 -27
- package/dist/data/sync-recovery-queue.test.d.ts +0 -1
- package/dist/data/sync-recovery-queue.test.js +0 -215
- package/dist/data/table-signing.test.d.ts +0 -1
- package/dist/data/table-signing.test.js +0 -118
- package/dist/data/tool-access.test.d.ts +0 -1
- package/dist/data/tool-access.test.js +0 -166
- package/dist/data/user-permissions.test.d.ts +0 -1
- package/dist/data/user-permissions.test.js +0 -305
- package/dist/data/user-trust-levels.test.d.ts +0 -1
- package/dist/data/user-trust-levels.test.js +0 -37
- package/dist/define/also-implements.test.d.ts +0 -1
- package/dist/define/also-implements.test.js +0 -123
- package/dist/define/declare-contract.test.d.ts +0 -1
- package/dist/define/declare-contract.test.js +0 -573
- package/dist/define/define.test.d.ts +0 -1
- package/dist/define/define.test.js +0 -1010
- package/dist/define/empty-fields.test.d.ts +0 -1
- package/dist/define/empty-fields.test.js +0 -55
- package/dist/define/events-observables.test.d.ts +0 -1
- package/dist/define/events-observables.test.js +0 -1013
- package/dist/define/serve-members.test.d.ts +0 -1
- package/dist/define/serve-members.test.js +0 -630
- package/dist/define/vars.test.d.ts +0 -1
- package/dist/define/vars.test.js +0 -39
- package/dist/device/binary-peer-connection-v2.test.d.ts +0 -1
- package/dist/device/binary-peer-connection-v2.test.js +0 -730
- package/dist/device/binary-peer-connection.test.d.ts +0 -1
- package/dist/device/binary-peer-connection.test.js +0 -184
- package/dist/device/connection.test.d.ts +0 -1
- package/dist/device/connection.test.js +0 -613
- package/dist/device/device-election.test.d.ts +0 -1
- package/dist/device/device-election.test.js +0 -516
- package/dist/device/device.test.d.ts +0 -1
- package/dist/device/device.test.js +0 -243
- package/dist/device/frame-cipher.test.d.ts +0 -1
- package/dist/device/frame-cipher.test.js +0 -219
- package/dist/device/get-trust-level-fn.test.d.ts +0 -1
- package/dist/device/get-trust-level-fn.test.js +0 -685
- package/dist/device/streamed-socket.test.d.ts +0 -1
- package/dist/device/streamed-socket.test.js +0 -216
- package/dist/device/tx-encoding.test.d.ts +0 -1
- package/dist/device/tx-encoding.test.js +0 -295
- package/dist/device-pairing/cpace.test.d.ts +0 -1
- package/dist/device-pairing/cpace.test.js +0 -116
- package/dist/device-pairing/device-pairing.test.d.ts +0 -1
- package/dist/device-pairing/device-pairing.test.js +0 -211
- package/dist/hlc.test.d.ts +0 -1
- package/dist/hlc.test.js +0 -45
- package/dist/host-credentials.test.d.ts +0 -1
- package/dist/host-credentials.test.js +0 -88
- package/dist/identity/account-email.test.d.ts +0 -1
- package/dist/identity/account-email.test.js +0 -59
- package/dist/identity/anchor-document.test.d.ts +0 -1
- package/dist/identity/anchor-document.test.js +0 -16
- package/dist/identity/anchor-resolution.test.d.ts +0 -1
- package/dist/identity/anchor-resolution.test.js +0 -130
- package/dist/identity/key-change.test.d.ts +0 -1
- package/dist/identity/key-change.test.js +0 -811
- package/dist/invites/group-approval.test.d.ts +0 -1
- package/dist/invites/group-approval.test.js +0 -223
- package/dist/invites/invite-token.test.d.ts +0 -1
- package/dist/invites/invite-token.test.js +0 -123
- package/dist/keys.test.d.ts +0 -1
- package/dist/keys.test.js +0 -336
- package/dist/logging/console-logger.test.d.ts +0 -1
- package/dist/logging/console-logger.test.js +0 -300
- package/dist/logging/console-logs.table.test.d.ts +0 -1
- package/dist/logging/console-logs.table.test.js +0 -156
- package/dist/observable.test.d.ts +0 -1
- package/dist/observable.test.js +0 -309
- package/dist/package-build/build-package.test.d.ts +0 -1
- package/dist/package-build/build-package.test.js +0 -204
- package/dist/package-build/contract-add.test.d.ts +0 -1
- package/dist/package-build/contract-add.test.js +0 -467
- package/dist/package-build/freeze-contracts.test.d.ts +0 -1
- package/dist/package-build/freeze-contracts.test.js +0 -355
- package/dist/package-installer/package-author-signing.test.d.ts +0 -1
- package/dist/package-installer/package-author-signing.test.js +0 -200
- package/dist/package-installer/package-cloner.test.d.ts +0 -1
- package/dist/package-installer/package-cloner.test.js +0 -278
- package/dist/package-installer/package-creator.test.d.ts +0 -1
- package/dist/package-installer/package-creator.test.js +0 -908
- package/dist/package-installer/package-dev-tools.test.d.ts +0 -1
- package/dist/package-installer/package-dev-tools.test.js +0 -64
- package/dist/package-installer/package-installer.test.d.ts +0 -1
- package/dist/package-installer/package-installer.test.js +0 -882
- package/dist/package-installer/package-propagation.test.d.ts +0 -1
- package/dist/package-installer/package-propagation.test.js +0 -1269
- package/dist/package-installer/package-publisher.test.d.ts +0 -1
- package/dist/package-installer/package-publisher.test.js +0 -153
- package/dist/package-installer/package-remote-checker.test.d.ts +0 -1
- package/dist/package-installer/package-remote-checker.test.js +0 -334
- package/dist/package-installer/package-seed-installer.test.d.ts +0 -1
- package/dist/package-installer/package-seed-installer.test.js +0 -123
- package/dist/package-installer/package-tarball.test.d.ts +0 -1
- package/dist/package-installer/package-tarball.test.js +0 -75
- package/dist/package-installer/peers-core-installer.test.d.ts +0 -1
- package/dist/package-installer/peers-core-installer.test.js +0 -49
- package/dist/package-installer/peers-core-trust-anchor.test.d.ts +0 -1
- package/dist/package-installer/peers-core-trust-anchor.test.js +0 -155
- package/dist/package-loader/contract-package-loader.test.d.ts +0 -1
- package/dist/package-loader/contract-package-loader.test.js +0 -274
- package/dist/package-loader/host-authority-loading.test.d.ts +0 -1
- package/dist/package-loader/host-authority-loading.test.js +0 -104
- package/dist/package-loader/host-dispatch-policy.test.d.ts +0 -1
- package/dist/package-loader/host-dispatch-policy.test.js +0 -56
- package/dist/package-loader/isolated-artifact.test.d.ts +0 -1
- package/dist/package-loader/isolated-artifact.test.js +0 -688
- package/dist/package-loader/isolated-persistent-var-gateway.test.d.ts +0 -1
- package/dist/package-loader/isolated-persistent-var-gateway.test.js +0 -56
- package/dist/package-loader/isolated-table-gateway.test.d.ts +0 -1
- package/dist/package-loader/isolated-table-gateway.test.js +0 -633
- package/dist/package-loader/package-loader.test.d.ts +0 -1
- package/dist/package-loader/package-loader.test.js +0 -1764
- package/dist/package-loader/resolve-consumed-contracts.test.d.ts +0 -1
- package/dist/package-loader/resolve-consumed-contracts.test.js +0 -166
- package/dist/serial-json.compat.test.d.ts +0 -1
- package/dist/serial-json.compat.test.js +0 -369
- package/dist/serial-json.test.d.ts +0 -1
- package/dist/serial-json.test.js +0 -401
- package/dist/testing/mock-host-contract.test.d.ts +0 -1
- package/dist/testing/mock-host-contract.test.js +0 -782
- package/dist/utils.test.d.ts +0 -1
- package/dist/utils.test.js +0 -232
package/dist/data/orm/types.d.ts
CHANGED
|
@@ -26,24 +26,33 @@ export interface ITableMetaData {
|
|
|
26
26
|
versionNumber?: number;
|
|
27
27
|
}
|
|
28
28
|
/**
|
|
29
|
-
* Convert field metadata to the runtime Zod schema the Runtime validates
|
|
30
|
-
* tool arguments.
|
|
29
|
+
* Convert field metadata to the runtime Zod schema the Runtime validates table rows with.
|
|
31
30
|
*
|
|
32
31
|
* It checks types only: `type`, `isArray`, and `optional`. An object field accepts any object
|
|
33
|
-
* and keeps its keys; nested `fields` and `enumValues` aren't checked, so a row
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
* {@link withoutEmptyFields}.
|
|
32
|
+
* and keeps its keys; nested `fields` and `enumValues` aren't checked, so a row from a package
|
|
33
|
+
* built against a newer shape isn't refused. A tool's arguments are checked with the stricter
|
|
34
|
+
* {@link fieldsToArgumentsSchema}, and {@link fieldsToShapeSchema} builds the full shape. An
|
|
35
|
+
* optional field refuses `null`: remove empty fields first with {@link withoutEmptyFields}.
|
|
37
36
|
*
|
|
38
37
|
* @param fields Serializable field definitions.
|
|
39
38
|
* @param codeSchema Optional author schema whose refinements are intersected.
|
|
40
39
|
*/
|
|
41
40
|
export declare function fieldsToSchema(fields: IField[], codeSchema?: z.AnyZodObject): z.AnyZodObject;
|
|
41
|
+
/**
|
|
42
|
+
* Convert a tool's input fields to the Zod schema the Runtime checks its arguments with before
|
|
43
|
+
* the provider runs. Like {@link fieldsToSchema}, and also: a required field must be present
|
|
44
|
+
* whatever its type (`any` included), and a field's `enumValues` are enforced. A contract
|
|
45
|
+
* version's fields don't change once it is stable, so a caller and its provider agree on them.
|
|
46
|
+
* Nested object `fields` still aren't checked, and keys no field names pass.
|
|
47
|
+
*
|
|
48
|
+
* @param fields A tool's input fields.
|
|
49
|
+
*/
|
|
50
|
+
export declare function fieldsToArgumentsSchema(fields: IField[]): z.AnyZodObject;
|
|
42
51
|
/**
|
|
43
52
|
* Convert field metadata to a Zod schema with every shape the IR carries: nested object
|
|
44
53
|
* `fields` and `enumValues`, as well as types. Objects keep keys their `fields` don't list. For
|
|
45
54
|
* describing a tool's arguments to an assistant's model; the Runtime validates with
|
|
46
|
-
* {@link
|
|
55
|
+
* {@link fieldsToArgumentsSchema}.
|
|
47
56
|
*
|
|
48
57
|
* @param fields Serializable field definitions.
|
|
49
58
|
*/
|
|
@@ -72,6 +81,14 @@ export declare function withoutEmptyFields<T>(fields: IField[], value: T): T;
|
|
|
72
81
|
* @param fields A table definition's fields.
|
|
73
82
|
*/
|
|
74
83
|
export declare function comparableTableFields(fields: IField[]): Partial<IField>[];
|
|
84
|
+
/**
|
|
85
|
+
* The scalar values an enum, a native enum, a literal, or a union of them allows; undefined for
|
|
86
|
+
* anything else.
|
|
87
|
+
*
|
|
88
|
+
* @internal
|
|
89
|
+
* @param schema A field's Zod schema, unwrapped to its value type.
|
|
90
|
+
*/
|
|
91
|
+
export declare function zodEnumValues(schema: z.ZodTypeAny): (string | number | boolean)[] | undefined;
|
|
75
92
|
/**
|
|
76
93
|
* Convert a Zod object schema to serializable field metadata.
|
|
77
94
|
*
|
package/dist/data/orm/types.js
CHANGED
|
@@ -1,39 +1,52 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.fieldsToSchema = fieldsToSchema;
|
|
4
|
+
exports.fieldsToArgumentsSchema = fieldsToArgumentsSchema;
|
|
4
5
|
exports.fieldsToShapeSchema = fieldsToShapeSchema;
|
|
5
6
|
exports.withoutEmptyFields = withoutEmptyFields;
|
|
6
7
|
exports.comparableTableFields = comparableTableFields;
|
|
8
|
+
exports.zodEnumValues = zodEnumValues;
|
|
7
9
|
exports.schemaToFields = schemaToFields;
|
|
8
10
|
const zod_1 = require("zod");
|
|
9
11
|
const field_type_1 = require("../../types/field-type");
|
|
10
12
|
const utils_1 = require("../../utils");
|
|
11
13
|
/**
|
|
12
|
-
* Convert field metadata to the runtime Zod schema the Runtime validates
|
|
13
|
-
* tool arguments.
|
|
14
|
+
* Convert field metadata to the runtime Zod schema the Runtime validates table rows with.
|
|
14
15
|
*
|
|
15
16
|
* It checks types only: `type`, `isArray`, and `optional`. An object field accepts any object
|
|
16
|
-
* and keeps its keys; nested `fields` and `enumValues` aren't checked, so a row
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
* {@link withoutEmptyFields}.
|
|
17
|
+
* and keeps its keys; nested `fields` and `enumValues` aren't checked, so a row from a package
|
|
18
|
+
* built against a newer shape isn't refused. A tool's arguments are checked with the stricter
|
|
19
|
+
* {@link fieldsToArgumentsSchema}, and {@link fieldsToShapeSchema} builds the full shape. An
|
|
20
|
+
* optional field refuses `null`: remove empty fields first with {@link withoutEmptyFields}.
|
|
20
21
|
*
|
|
21
22
|
* @param fields Serializable field definitions.
|
|
22
23
|
* @param codeSchema Optional author schema whose refinements are intersected.
|
|
23
24
|
*/
|
|
24
25
|
function fieldsToSchema(fields, codeSchema) {
|
|
25
|
-
return buildFieldsSchema(fields,
|
|
26
|
+
return buildFieldsSchema(fields, "rows", codeSchema);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Convert a tool's input fields to the Zod schema the Runtime checks its arguments with before
|
|
30
|
+
* the provider runs. Like {@link fieldsToSchema}, and also: a required field must be present
|
|
31
|
+
* whatever its type (`any` included), and a field's `enumValues` are enforced. A contract
|
|
32
|
+
* version's fields don't change once it is stable, so a caller and its provider agree on them.
|
|
33
|
+
* Nested object `fields` still aren't checked, and keys no field names pass.
|
|
34
|
+
*
|
|
35
|
+
* @param fields A tool's input fields.
|
|
36
|
+
*/
|
|
37
|
+
function fieldsToArgumentsSchema(fields) {
|
|
38
|
+
return buildFieldsSchema(fields, "arguments");
|
|
26
39
|
}
|
|
27
40
|
/**
|
|
28
41
|
* Convert field metadata to a Zod schema with every shape the IR carries: nested object
|
|
29
42
|
* `fields` and `enumValues`, as well as types. Objects keep keys their `fields` don't list. For
|
|
30
43
|
* describing a tool's arguments to an assistant's model; the Runtime validates with
|
|
31
|
-
* {@link
|
|
44
|
+
* {@link fieldsToArgumentsSchema}.
|
|
32
45
|
*
|
|
33
46
|
* @param fields Serializable field definitions.
|
|
34
47
|
*/
|
|
35
48
|
function fieldsToShapeSchema(fields) {
|
|
36
|
-
return buildFieldsSchema(fields,
|
|
49
|
+
return buildFieldsSchema(fields, "shapes");
|
|
37
50
|
}
|
|
38
51
|
function enumSchema(values) {
|
|
39
52
|
if (values.every((value) => typeof value === "string")) {
|
|
@@ -44,8 +57,8 @@ function enumSchema(values) {
|
|
|
44
57
|
? literals[0]
|
|
45
58
|
: zod_1.z.union(literals);
|
|
46
59
|
}
|
|
47
|
-
function fieldValueSchema(field,
|
|
48
|
-
if (
|
|
60
|
+
function fieldValueSchema(field, mode, open) {
|
|
61
|
+
if (mode !== "rows" && field.enumValues?.length) {
|
|
49
62
|
return enumSchema(field.enumValues);
|
|
50
63
|
}
|
|
51
64
|
switch (field.type) {
|
|
@@ -63,7 +76,9 @@ function fieldValueSchema(field, shapes, open) {
|
|
|
63
76
|
case "Date":
|
|
64
77
|
return zod_1.z.date();
|
|
65
78
|
case "object": {
|
|
66
|
-
const object = shapes && field.fields
|
|
79
|
+
const object = mode === "shapes" && field.fields
|
|
80
|
+
? buildFieldsSchema(field.fields, "shapes")
|
|
81
|
+
: zod_1.z.object({});
|
|
67
82
|
// An author schema intersected with this one parses the value itself; two parses of
|
|
68
83
|
// one object can't be merged, so only an open object keeps its keys.
|
|
69
84
|
return open ? object.passthrough() : object;
|
|
@@ -72,12 +87,12 @@ function fieldValueSchema(field, shapes, open) {
|
|
|
72
87
|
return zod_1.z.any();
|
|
73
88
|
}
|
|
74
89
|
}
|
|
75
|
-
function buildFieldsSchema(fields,
|
|
90
|
+
function buildFieldsSchema(fields, mode, codeSchema) {
|
|
76
91
|
let argsSchema = zod_1.z.object({});
|
|
77
92
|
for (const field of fields) {
|
|
78
93
|
const { name, description, isArray, defaultValue, optional } = field;
|
|
79
94
|
const shapeField = codeSchema?.shape?.[name];
|
|
80
|
-
let propertyType = fieldValueSchema(field,
|
|
95
|
+
let propertyType = fieldValueSchema(field, mode, !shapeField);
|
|
81
96
|
if (isArray) {
|
|
82
97
|
propertyType = propertyType.array();
|
|
83
98
|
}
|
|
@@ -87,6 +102,11 @@ function buildFieldsSchema(fields, shapes, codeSchema) {
|
|
|
87
102
|
if (defaultValue !== undefined) {
|
|
88
103
|
propertyType = propertyType.default(defaultValue);
|
|
89
104
|
}
|
|
105
|
+
else if (mode !== "rows" && !optional) {
|
|
106
|
+
// `z.any()` accepts a missing value; a required argument must be there, and a model
|
|
107
|
+
// describing it must see it listed as required.
|
|
108
|
+
propertyType = propertyType.refine((value) => value !== undefined, { message: "Required" });
|
|
109
|
+
}
|
|
90
110
|
propertyType = propertyType.describe(description ?? "");
|
|
91
111
|
if (shapeField) {
|
|
92
112
|
propertyType = zod_1.z.intersection(propertyType, shapeField);
|
|
@@ -189,6 +209,42 @@ function comparableTableFields(fields) {
|
|
|
189
209
|
return comparable;
|
|
190
210
|
});
|
|
191
211
|
}
|
|
212
|
+
/**
|
|
213
|
+
* The scalar values an enum, a native enum, a literal, or a union of them allows; undefined for
|
|
214
|
+
* anything else.
|
|
215
|
+
*
|
|
216
|
+
* @internal
|
|
217
|
+
* @param schema A field's Zod schema, unwrapped to its value type.
|
|
218
|
+
*/
|
|
219
|
+
function zodEnumValues(schema) {
|
|
220
|
+
const def = schema._def;
|
|
221
|
+
switch (def.typeName) {
|
|
222
|
+
case "ZodEnum":
|
|
223
|
+
return [...def.values];
|
|
224
|
+
case "ZodNativeEnum": {
|
|
225
|
+
// A numeric TypeScript enum maps each value back to its name too; skip those keys.
|
|
226
|
+
const values = def.values;
|
|
227
|
+
return Object.keys(values)
|
|
228
|
+
.filter((key) => typeof values[values[key]] !== "number")
|
|
229
|
+
.map((key) => values[key]);
|
|
230
|
+
}
|
|
231
|
+
case "ZodLiteral":
|
|
232
|
+
return ["string", "number", "boolean"].includes(typeof def.value) ? [def.value] : undefined;
|
|
233
|
+
case "ZodUnion": {
|
|
234
|
+
const values = [];
|
|
235
|
+
for (const option of def.options) {
|
|
236
|
+
const optionValues = zodEnumValues(option);
|
|
237
|
+
if (!optionValues) {
|
|
238
|
+
return undefined;
|
|
239
|
+
}
|
|
240
|
+
values.push(...optionValues);
|
|
241
|
+
}
|
|
242
|
+
return values;
|
|
243
|
+
}
|
|
244
|
+
default:
|
|
245
|
+
return undefined;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
192
248
|
/**
|
|
193
249
|
* Convert a Zod object schema to serializable field metadata.
|
|
194
250
|
*
|
|
@@ -199,26 +255,30 @@ function schemaToFields(schema) {
|
|
|
199
255
|
for (const name of Object.keys(schema.shape)) {
|
|
200
256
|
const field = schema.shape[name];
|
|
201
257
|
let type = field_type_1.FieldType.any;
|
|
258
|
+
let valueSchema = field;
|
|
259
|
+
let nullable = false;
|
|
260
|
+
let enumElements = true;
|
|
202
261
|
let _def = field._def;
|
|
203
262
|
let isArray;
|
|
204
263
|
let brandedFieldType;
|
|
205
264
|
while (true) {
|
|
206
265
|
if (_def.typeName === "ZodArray") {
|
|
266
|
+
if (isArray)
|
|
267
|
+
enumElements = false;
|
|
207
268
|
isArray = true;
|
|
208
269
|
}
|
|
270
|
+
if (isArray && (_def.typeName === "ZodOptional" || _def.typeName === "ZodDefault"))
|
|
271
|
+
enumElements = false;
|
|
209
272
|
if (_def._fieldType) {
|
|
210
273
|
brandedFieldType = _def._fieldType;
|
|
211
274
|
}
|
|
212
|
-
if (_def.
|
|
213
|
-
|
|
214
|
-
continue;
|
|
215
|
-
}
|
|
216
|
-
if (_def.schema) {
|
|
217
|
-
_def = _def.schema._def;
|
|
218
|
-
continue;
|
|
275
|
+
if (_def.typeName === "ZodNullable") {
|
|
276
|
+
nullable = true;
|
|
219
277
|
}
|
|
220
|
-
|
|
221
|
-
|
|
278
|
+
const inner = _def.innerType ?? _def.schema ?? _def.type;
|
|
279
|
+
if (inner) {
|
|
280
|
+
valueSchema = inner;
|
|
281
|
+
_def = inner._def;
|
|
222
282
|
continue;
|
|
223
283
|
}
|
|
224
284
|
break;
|
|
@@ -255,7 +315,20 @@ function schemaToFields(schema) {
|
|
|
255
315
|
const optional = field._def.typeName === "ZodOptional" || undefined;
|
|
256
316
|
const description = field._def.description;
|
|
257
317
|
const defaultValue = field._def.defaultValue;
|
|
258
|
-
|
|
318
|
+
// The type stays as it was (an enum is `any`) so stable contract shapes don't change. A
|
|
319
|
+
// nullable enum also allows null, which a list of values can't say. The same is true of
|
|
320
|
+
// optional/defaulted elements and nested arrays: enumValues describes each immediate element.
|
|
321
|
+
const values = nullable || !enumElements ? undefined : zodEnumValues(valueSchema);
|
|
322
|
+
const enumValues = values?.length ? [...new Set(values)] : undefined;
|
|
323
|
+
const newField = {
|
|
324
|
+
name,
|
|
325
|
+
type,
|
|
326
|
+
isArray,
|
|
327
|
+
optional,
|
|
328
|
+
description,
|
|
329
|
+
defaultValue,
|
|
330
|
+
enumValues,
|
|
331
|
+
};
|
|
259
332
|
Object.keys(newField).forEach((k) => {
|
|
260
333
|
// @ts-expect-error
|
|
261
334
|
if (newField[k] === undefined)
|
package/dist/define/manifest.js
CHANGED
|
@@ -49,36 +49,6 @@ function literalType(schema) {
|
|
|
49
49
|
return field_type_1.FieldType.boolean;
|
|
50
50
|
return undefined;
|
|
51
51
|
}
|
|
52
|
-
/** The scalar values an enum, a literal, or a union of them allows; undefined for anything else. */
|
|
53
|
-
function enumValuesOf(schema) {
|
|
54
|
-
const def = schema._def;
|
|
55
|
-
switch (def.typeName) {
|
|
56
|
-
case "ZodEnum":
|
|
57
|
-
return [...def.values];
|
|
58
|
-
case "ZodNativeEnum": {
|
|
59
|
-
// A numeric TypeScript enum maps each value back to its name too; skip those keys.
|
|
60
|
-
const values = def.values;
|
|
61
|
-
return Object.keys(values)
|
|
62
|
-
.filter((key) => typeof values[values[key]] !== "number")
|
|
63
|
-
.map((key) => values[key]);
|
|
64
|
-
}
|
|
65
|
-
case "ZodLiteral":
|
|
66
|
-
return ["string", "number", "boolean"].includes(typeof def.value) ? [def.value] : undefined;
|
|
67
|
-
case "ZodUnion": {
|
|
68
|
-
const values = [];
|
|
69
|
-
for (const option of def.options) {
|
|
70
|
-
const optionValues = enumValuesOf(option);
|
|
71
|
-
if (!optionValues) {
|
|
72
|
-
return undefined;
|
|
73
|
-
}
|
|
74
|
-
values.push(...optionValues);
|
|
75
|
-
}
|
|
76
|
-
return values;
|
|
77
|
-
}
|
|
78
|
-
default:
|
|
79
|
-
return undefined;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
52
|
/**
|
|
83
53
|
* What a field's schema says beyond its type: an object's own fields and the values an enum or
|
|
84
54
|
* literal allows. Walks the wrappers `schemaToFields` walks, into one array's elements, and
|
|
@@ -153,7 +123,7 @@ function fieldDetails(schema, shape, input, depth, path, event = false, wholeVal
|
|
|
153
123
|
? eventFields(current, depth + 1, path)
|
|
154
124
|
: irFields(current, input, depth + 1, path);
|
|
155
125
|
}
|
|
156
|
-
const values =
|
|
126
|
+
const values = (0, types_1.zodEnumValues)(current);
|
|
157
127
|
if (!emptyElement && values?.length && values.every((value) => (0, isolated_artifact_1.enumValueFits)(value, type))) {
|
|
158
128
|
details.enumValues = [...new Set(values)];
|
|
159
129
|
}
|
|
@@ -190,8 +160,10 @@ function irField(schema, schemaField, input, depth, path, wholeValue = false) {
|
|
|
190
160
|
const generated = (0, generated_field_1.generatedFieldMetadata)(schema);
|
|
191
161
|
if (generated)
|
|
192
162
|
return { name: schemaField.name, ...generated.shape };
|
|
193
|
-
|
|
194
|
-
const
|
|
163
|
+
// The IR records enum values itself (fieldDetails), only where they fit the field's type.
|
|
164
|
+
const { enumValues: _enumValues, ...plainField } = schemaField;
|
|
165
|
+
const literal = plainField.type === field_type_1.FieldType.any ? literalType(schema) : undefined;
|
|
166
|
+
const field = literal ? { ...plainField, type: literal } : plainField;
|
|
195
167
|
const { defaultValue: _default, ...rest } = field;
|
|
196
168
|
const result = typeof _default === "function" ? rest : field;
|
|
197
169
|
const details = fieldDetails(schema, field, input, depth, path, false, wholeValue);
|
|
@@ -500,7 +472,7 @@ function eventFields(schema, depth = 1, parent = "") {
|
|
|
500
472
|
const generated = (0, generated_field_1.generatedFieldMetadata)(schema.shape[field.name]);
|
|
501
473
|
if (generated)
|
|
502
474
|
return { name: field.name, ...generated.shape };
|
|
503
|
-
const { type: _type, optional: _optional, isArray: _array, defaultValue, ...metadata } = field;
|
|
475
|
+
const { type: _type, optional: _optional, isArray: _array, defaultValue, enumValues: _enumValues, ...metadata } = field;
|
|
504
476
|
const shape = eventValueShape(schema.shape[field.name]);
|
|
505
477
|
const path = parent ? `${parent}.${field.name}` : field.name;
|
|
506
478
|
return {
|
|
@@ -9,6 +9,7 @@ const contract_resolvers_1 = require("../contracts/contract-resolvers");
|
|
|
9
9
|
const contract_transport_1 = require("../contracts/contract-transport");
|
|
10
10
|
const registry_1 = require("../contracts/registry");
|
|
11
11
|
const remote_contract_transport_1 = require("../contracts/remote-contract-transport");
|
|
12
|
+
const tool_arguments_1 = require("../contracts/tool-arguments");
|
|
12
13
|
const tool_catalog_1 = require("../contracts/tool-catalog");
|
|
13
14
|
const files_1 = require("../data/files");
|
|
14
15
|
const package_version_resolver_1 = require("../data/package-version-resolver");
|
|
@@ -412,7 +413,7 @@ class PackageLoader {
|
|
|
412
413
|
(0, contract_resolvers_1.getContractResolver)(implementation.contractId, implementation.version, providerPackageId, this.dataContext) !== resolver)
|
|
413
414
|
throw new contract_provider_router_1.RetiredContractProviderEndpointError(guardedEndpoint);
|
|
414
415
|
};
|
|
415
|
-
const endpoint = (0, contract_proxy_1.createContractProviderEndpoint)(this.guardResolutionTools(localResolution, request, assertProviderCurrent), {
|
|
416
|
+
const endpoint = (0, contract_proxy_1.createContractProviderEndpoint)(this.guardResolutionTools(localResolution, request, assertProviderCurrent, providerPackageId), {
|
|
416
417
|
dispatchTool: (target, args, context) => this.dispatchToolFromProvider(providerPackageId, target, args, context),
|
|
417
418
|
context: request.context,
|
|
418
419
|
notify: (notification) => request.notify({
|
|
@@ -435,29 +436,33 @@ class PackageLoader {
|
|
|
435
436
|
};
|
|
436
437
|
return guardedEndpoint;
|
|
437
438
|
}
|
|
438
|
-
guardResolutionTools(resolution, request, assertProviderCurrent) {
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
...instance,
|
|
444
|
-
// The dispatcher awaits authorization before calling toolFn. Check again
|
|
445
|
-
// here so those awaits cannot retain old code. Once provider code has
|
|
446
|
-
// started, its nested action errors must not request a router replay.
|
|
447
|
-
toolFn: async (...args) => {
|
|
448
|
-
await this.toolCatalog.assertTargetUsable({
|
|
449
|
-
contractId: request.contractId,
|
|
450
|
-
version: request.version,
|
|
451
|
-
toolName: name,
|
|
452
|
-
});
|
|
453
|
-
assertProviderCurrent();
|
|
454
|
-
return instance.toolFn(...args);
|
|
455
|
-
},
|
|
456
|
-
},
|
|
457
|
-
]));
|
|
439
|
+
guardResolutionTools(resolution, request, assertProviderCurrent, providerPackageId) {
|
|
440
|
+
// The version the caller asked for: each run's arguments are checked against its tools.
|
|
441
|
+
const definition = (providerPackageId &&
|
|
442
|
+
this.contractRegistry.getProviderDefinition(request.contractId, request.version, providerPackageId)) ||
|
|
443
|
+
this.contractRegistry.getDefinition(request.contractId, request.version);
|
|
458
444
|
return {
|
|
459
445
|
...resolution,
|
|
460
|
-
|
|
446
|
+
invokeTool: async (name, args) => {
|
|
447
|
+
// Authorization may await; retire old code before checking its schema or running it.
|
|
448
|
+
// Nested action errors after this point must not request a router replay.
|
|
449
|
+
await this.toolCatalog.assertTargetUsable({
|
|
450
|
+
contractId: request.contractId,
|
|
451
|
+
version: request.version,
|
|
452
|
+
toolName: name,
|
|
453
|
+
});
|
|
454
|
+
assertProviderCurrent();
|
|
455
|
+
const tool = resolution.tools?.[name];
|
|
456
|
+
if (!tool)
|
|
457
|
+
throw new Error(`Contract ${request.contractId} does not provide tool '${name}'`);
|
|
458
|
+
const member = definition?.tools.find((tool) => tool.name === name);
|
|
459
|
+
if (definition && !member)
|
|
460
|
+
throw new Error(`Contract ${request.contractId} does not declare tool '${name}'`);
|
|
461
|
+
const inputFields = member?.inputFields ?? tool.tool.inputSchema?.fields;
|
|
462
|
+
if (inputFields?.length)
|
|
463
|
+
(0, tool_arguments_1.checkToolArguments)(inputFields, args[0], name);
|
|
464
|
+
return tool.toolFn(...args);
|
|
465
|
+
},
|
|
461
466
|
};
|
|
462
467
|
}
|
|
463
468
|
/**
|
package/dist/system-ids.d.ts
CHANGED
|
@@ -71,6 +71,11 @@ export declare const networkControlContractId = "00ms1yb50yj9w5qbytl69qfht";
|
|
|
71
71
|
* provide status and relay tools, while Electron also implements local updates.
|
|
72
72
|
*/
|
|
73
73
|
export declare const appUpdatesContractId = "00mvczoafequsatpfjaj3r4g8";
|
|
74
|
+
/**
|
|
75
|
+
* Contract id for **System Sync Check**: the daily check that finds changes another device has
|
|
76
|
+
* and this one is missing. `countChanges` is remotely callable by group Readers.
|
|
77
|
+
*/
|
|
78
|
+
export declare const syncCheckContractId = "00mvrnfgmc14ea0ktkr86vjd2";
|
|
74
79
|
/**
|
|
75
80
|
* Contract id for the local-only tool-access approval control surface.
|
|
76
81
|
* Not available over device-to-device connections.
|
package/dist/system-ids.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.hostShellContractId = exports.packagesContractId = exports.desktopToolsContractId = exports.hostToolsContractId = exports.toolCatalogContractId = exports.schedulerToolIds = exports.schedulerContractId = exports.contractCatalogToolIds = exports.contractCatalogContractId = exports.httpToolIds = exports.httpContractId = exports.localFoldersToolIds = exports.localFoldersContractId = exports.identityToolIds = exports.identityContractId = exports.invitesToolIds = exports.invitesContractId = exports.toolAccessControlToolIds = exports.toolAccessControlContractId = exports.appUpdatesContractId = exports.networkControlContractId = exports.networkDiagnosticsContractId = exports.deviceOperationsContractId = exports.logsContractId = exports.peersSystemPackageId = exports.peersCoreRevokedPublishPublicKeys = exports.peersCorePublishPublicKey = exports.peersCorePackageRepoUrl = exports.peersCorePackageId = exports.createGroupToolId = exports.queryDatabaseToolId = exports.runWorkflowToolId = exports.defaultSendMessageToolId = exports.defaultAssistantRunnerToolId = exports.adminAssistantId = exports.openCodeAssistantId = exports.defaultAssistantId = exports.peersRootUserId = void 0;
|
|
3
|
+
exports.hostShellContractId = exports.packagesContractId = exports.desktopToolsContractId = exports.hostToolsContractId = exports.toolCatalogContractId = exports.schedulerToolIds = exports.schedulerContractId = exports.contractCatalogToolIds = exports.contractCatalogContractId = exports.httpToolIds = exports.httpContractId = exports.localFoldersToolIds = exports.localFoldersContractId = exports.identityToolIds = exports.identityContractId = exports.invitesToolIds = exports.invitesContractId = exports.toolAccessControlToolIds = exports.toolAccessControlContractId = exports.syncCheckContractId = exports.appUpdatesContractId = exports.networkControlContractId = exports.networkDiagnosticsContractId = exports.deviceOperationsContractId = exports.logsContractId = exports.peersSystemPackageId = exports.peersCoreRevokedPublishPublicKeys = exports.peersCorePublishPublicKey = exports.peersCorePackageRepoUrl = exports.peersCorePackageId = exports.createGroupToolId = exports.queryDatabaseToolId = exports.runWorkflowToolId = exports.defaultSendMessageToolId = exports.defaultAssistantRunnerToolId = exports.adminAssistantId = exports.openCodeAssistantId = exports.defaultAssistantId = exports.peersRootUserId = void 0;
|
|
4
4
|
/** Stable user ID that owns built-in Peers system records. */
|
|
5
5
|
exports.peersRootUserId = "000peers0user000000000001";
|
|
6
6
|
/** Default assistant used when no user-selected assistant is available. */
|
|
@@ -78,6 +78,11 @@ exports.networkControlContractId = "00ms1yb50yj9w5qbytl69qfht";
|
|
|
78
78
|
* provide status and relay tools, while Electron also implements local updates.
|
|
79
79
|
*/
|
|
80
80
|
exports.appUpdatesContractId = "00mvczoafequsatpfjaj3r4g8";
|
|
81
|
+
/**
|
|
82
|
+
* Contract id for **System Sync Check**: the daily check that finds changes another device has
|
|
83
|
+
* and this one is missing. `countChanges` is remotely callable by group Readers.
|
|
84
|
+
*/
|
|
85
|
+
exports.syncCheckContractId = "00mvrnfgmc14ea0ktkr86vjd2";
|
|
81
86
|
/**
|
|
82
87
|
* Contract id for the local-only tool-access approval control surface.
|
|
83
88
|
* Not available over device-to-device connections.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@peers-app/peers-sdk",
|
|
3
|
-
"version": "0.27.
|
|
3
|
+
"version": "0.27.4",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/peers-app/peers-sdk.git"
|
|
@@ -16,7 +16,9 @@
|
|
|
16
16
|
"dist",
|
|
17
17
|
"define",
|
|
18
18
|
"testing",
|
|
19
|
-
"bin"
|
|
19
|
+
"bin",
|
|
20
|
+
"!dist/**/*.test.*",
|
|
21
|
+
"!dist/**/__tests__"
|
|
20
22
|
],
|
|
21
23
|
"publishConfig": {
|
|
22
24
|
"access": "public"
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import "../identity/user-row-change";
|