@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.
Files changed (258) hide show
  1. package/dist/contracts/contract-proxy.d.ts +7 -0
  2. package/dist/contracts/contract-proxy.js +19 -2
  3. package/dist/contracts/create-local-consumer.js +16 -1
  4. package/dist/contracts/index.d.ts +2 -0
  5. package/dist/contracts/index.js +2 -0
  6. package/dist/contracts/system/index.d.ts +2 -0
  7. package/dist/contracts/system/index.js +2 -0
  8. package/dist/contracts/system/invites-contract.js +2 -1
  9. package/dist/contracts/system/sync-check-contract.d.ts +97 -0
  10. package/dist/contracts/system/sync-check-contract.js +115 -0
  11. package/dist/contracts/tool-arguments.d.ts +15 -0
  12. package/dist/contracts/tool-arguments.js +41 -0
  13. package/dist/contracts/tool-catalog-service.js +2 -12
  14. package/dist/data/change-tracking.d.ts +40 -0
  15. package/dist/data/change-tracking.js +89 -0
  16. package/dist/data/orm/types.d.ts +24 -7
  17. package/dist/data/orm/types.js +97 -24
  18. package/dist/define/manifest.js +6 -34
  19. package/dist/package-loader/package-loader.js +27 -22
  20. package/dist/system-ids.d.ts +5 -0
  21. package/dist/system-ids.js +6 -1
  22. package/package.json +4 -2
  23. package/dist/context/user-context-identity.test.d.ts +0 -1
  24. package/dist/context/user-context-identity.test.js +0 -220
  25. package/dist/contracts/__tests__/action-dispatch.test.d.ts +0 -1
  26. package/dist/contracts/__tests__/action-dispatch.test.js +0 -319
  27. package/dist/contracts/__tests__/also-implements.test.d.ts +0 -1
  28. package/dist/contracts/__tests__/also-implements.test.js +0 -110
  29. package/dist/contracts/__tests__/builder.test.d.ts +0 -1
  30. package/dist/contracts/__tests__/builder.test.js +0 -669
  31. package/dist/contracts/__tests__/contract-events.test.d.ts +0 -1
  32. package/dist/contracts/__tests__/contract-events.test.js +0 -199
  33. package/dist/contracts/__tests__/contract-observables.test.d.ts +0 -1
  34. package/dist/contracts/__tests__/contract-observables.test.js +0 -290
  35. package/dist/contracts/__tests__/contract-provider-router.test.d.ts +0 -1
  36. package/dist/contracts/__tests__/contract-provider-router.test.js +0 -315
  37. package/dist/contracts/__tests__/contract-proxy.test.d.ts +0 -1
  38. package/dist/contracts/__tests__/contract-proxy.test.js +0 -657
  39. package/dist/contracts/__tests__/contract-resolvers.test.d.ts +0 -1
  40. package/dist/contracts/__tests__/contract-resolvers.test.js +0 -758
  41. package/dist/contracts/__tests__/contract-subscription-lifecycle.test.d.ts +0 -1
  42. package/dist/contracts/__tests__/contract-subscription-lifecycle.test.js +0 -353
  43. package/dist/contracts/__tests__/contract-table-events.test.d.ts +0 -1
  44. package/dist/contracts/__tests__/contract-table-events.test.js +0 -209
  45. package/dist/contracts/__tests__/contract-transport.test.d.ts +0 -1
  46. package/dist/contracts/__tests__/contract-transport.test.js +0 -163
  47. package/dist/contracts/__tests__/extract.test.d.ts +0 -1
  48. package/dist/contracts/__tests__/extract.test.js +0 -145
  49. package/dist/contracts/__tests__/frozen-contracts.test.d.ts +0 -1
  50. package/dist/contracts/__tests__/frozen-contracts.test.js +0 -191
  51. package/dist/contracts/__tests__/generic-tool-dispatch.test.d.ts +0 -1
  52. package/dist/contracts/__tests__/generic-tool-dispatch.test.js +0 -130
  53. package/dist/contracts/__tests__/host-contract-client.test.d.ts +0 -1
  54. package/dist/contracts/__tests__/host-contract-client.test.js +0 -793
  55. package/dist/contracts/__tests__/host-contract-consumer.test.d.ts +0 -1
  56. package/dist/contracts/__tests__/host-contract-consumer.test.js +0 -163
  57. package/dist/contracts/__tests__/host-contract-transport.test.d.ts +0 -1
  58. package/dist/contracts/__tests__/host-contract-transport.test.js +0 -66
  59. package/dist/contracts/__tests__/integration.test.d.ts +0 -1
  60. package/dist/contracts/__tests__/integration.test.js +0 -348
  61. package/dist/contracts/__tests__/legacy-removal.test.d.ts +0 -1
  62. package/dist/contracts/__tests__/legacy-removal.test.js +0 -128
  63. package/dist/contracts/__tests__/persistent-registry.test.d.ts +0 -1
  64. package/dist/contracts/__tests__/persistent-registry.test.js +0 -109
  65. package/dist/contracts/__tests__/playground.test.d.ts +0 -1
  66. package/dist/contracts/__tests__/playground.test.js +0 -216
  67. package/dist/contracts/__tests__/registry.test.d.ts +0 -1
  68. package/dist/contracts/__tests__/registry.test.js +0 -238
  69. package/dist/contracts/__tests__/remote-contract-transport.test.d.ts +0 -1
  70. package/dist/contracts/__tests__/remote-contract-transport.test.js +0 -119
  71. package/dist/contracts/__tests__/system-contracts.test.d.ts +0 -1
  72. package/dist/contracts/__tests__/system-contracts.test.js +0 -247
  73. package/dist/contracts/__tests__/target-dispatch.d.ts +0 -11
  74. package/dist/contracts/__tests__/target-dispatch.js +0 -24
  75. package/dist/contracts/__tests__/tool-catalog-inventory.test.d.ts +0 -1
  76. package/dist/contracts/__tests__/tool-catalog-inventory.test.js +0 -44
  77. package/dist/contracts/__tests__/tool-catalog-service.test.d.ts +0 -1
  78. package/dist/contracts/__tests__/tool-catalog-service.test.js +0 -482
  79. package/dist/contracts/__tests__/tool-catalog.test.d.ts +0 -1
  80. package/dist/contracts/__tests__/tool-catalog.test.js +0 -1199
  81. package/dist/contracts/__tests__/validate.test.d.ts +0 -1
  82. package/dist/contracts/__tests__/validate.test.js +0 -991
  83. package/dist/contracts/__tests__/workflow-context.test.d.ts +0 -1
  84. package/dist/contracts/__tests__/workflow-context.test.js +0 -50
  85. package/dist/data/access-level.test.d.ts +0 -1
  86. package/dist/data/access-level.test.js +0 -53
  87. package/dist/data/change-tracking.test.d.ts +0 -1
  88. package/dist/data/change-tracking.test.js +0 -62
  89. package/dist/data/files/files.test.d.ts +0 -1
  90. package/dist/data/files/files.test.js +0 -770
  91. package/dist/data/group-members.test.d.ts +0 -1
  92. package/dist/data/group-members.test.js +0 -336
  93. package/dist/data/group-share.test.d.ts +0 -1
  94. package/dist/data/group-share.test.js +0 -110
  95. package/dist/data/groups.test.d.ts +0 -1
  96. package/dist/data/groups.test.js +0 -153
  97. package/dist/data/orm/cursor.test.d.ts +0 -1
  98. package/dist/data/orm/cursor.test.js +0 -314
  99. package/dist/data/orm/data-query.mongo.test.d.ts +0 -1
  100. package/dist/data/orm/data-query.mongo.test.js +0 -367
  101. package/dist/data/orm/data-query.sqlite.test.d.ts +0 -1
  102. package/dist/data/orm/data-query.sqlite.test.js +0 -365
  103. package/dist/data/orm/data-query.test.d.ts +0 -1
  104. package/dist/data/orm/data-query.test.js +0 -545
  105. package/dist/data/orm/dependency-injection.test.d.ts +0 -1
  106. package/dist/data/orm/dependency-injection.test.js +0 -171
  107. package/dist/data/orm/event-registry.test.d.ts +0 -1
  108. package/dist/data/orm/event-registry.test.js +0 -44
  109. package/dist/data/orm/multi-cursors.test.d.ts +0 -1
  110. package/dist/data/orm/multi-cursors.test.js +0 -463
  111. package/dist/data/orm/sql.data-source.test.d.ts +0 -1
  112. package/dist/data/orm/sql.data-source.test.js +0 -731
  113. package/dist/data/orm/table-container-events.test.d.ts +0 -1
  114. package/dist/data/orm/table-container-events.test.js +0 -101
  115. package/dist/data/orm/table-container.test.d.ts +0 -1
  116. package/dist/data/orm/table-container.test.js +0 -273
  117. package/dist/data/orm/table.event-source.test.d.ts +0 -1
  118. package/dist/data/orm/table.event-source.test.js +0 -331
  119. package/dist/data/orm/types.test.d.ts +0 -1
  120. package/dist/data/orm/types.test.js +0 -409
  121. package/dist/data/package-table-identity.test.d.ts +0 -1
  122. package/dist/data/package-table-identity.test.js +0 -46
  123. package/dist/data/package-version-permissions.test.d.ts +0 -1
  124. package/dist/data/package-version-permissions.test.js +0 -107
  125. package/dist/data/package-version-resolver.test.d.ts +0 -4
  126. package/dist/data/package-version-resolver.test.js +0 -543
  127. package/dist/data/package-versions.test.d.ts +0 -1
  128. package/dist/data/package-versions.test.js +0 -227
  129. package/dist/data/persistent-vars.conflict.test.d.ts +0 -1
  130. package/dist/data/persistent-vars.conflict.test.js +0 -126
  131. package/dist/data/persistent-vars.migration.test.d.ts +0 -1
  132. package/dist/data/persistent-vars.migration.test.js +0 -133
  133. package/dist/data/persistent-vars.package-scope.test.d.ts +0 -1
  134. package/dist/data/persistent-vars.package-scope.test.js +0 -27
  135. package/dist/data/sync-recovery-queue.test.d.ts +0 -1
  136. package/dist/data/sync-recovery-queue.test.js +0 -215
  137. package/dist/data/table-signing.test.d.ts +0 -1
  138. package/dist/data/table-signing.test.js +0 -118
  139. package/dist/data/tool-access.test.d.ts +0 -1
  140. package/dist/data/tool-access.test.js +0 -166
  141. package/dist/data/user-permissions.test.d.ts +0 -1
  142. package/dist/data/user-permissions.test.js +0 -305
  143. package/dist/data/user-trust-levels.test.d.ts +0 -1
  144. package/dist/data/user-trust-levels.test.js +0 -37
  145. package/dist/define/also-implements.test.d.ts +0 -1
  146. package/dist/define/also-implements.test.js +0 -123
  147. package/dist/define/declare-contract.test.d.ts +0 -1
  148. package/dist/define/declare-contract.test.js +0 -573
  149. package/dist/define/define.test.d.ts +0 -1
  150. package/dist/define/define.test.js +0 -1010
  151. package/dist/define/empty-fields.test.d.ts +0 -1
  152. package/dist/define/empty-fields.test.js +0 -55
  153. package/dist/define/events-observables.test.d.ts +0 -1
  154. package/dist/define/events-observables.test.js +0 -1013
  155. package/dist/define/serve-members.test.d.ts +0 -1
  156. package/dist/define/serve-members.test.js +0 -630
  157. package/dist/define/vars.test.d.ts +0 -1
  158. package/dist/define/vars.test.js +0 -39
  159. package/dist/device/binary-peer-connection-v2.test.d.ts +0 -1
  160. package/dist/device/binary-peer-connection-v2.test.js +0 -730
  161. package/dist/device/binary-peer-connection.test.d.ts +0 -1
  162. package/dist/device/binary-peer-connection.test.js +0 -184
  163. package/dist/device/connection.test.d.ts +0 -1
  164. package/dist/device/connection.test.js +0 -613
  165. package/dist/device/device-election.test.d.ts +0 -1
  166. package/dist/device/device-election.test.js +0 -516
  167. package/dist/device/device.test.d.ts +0 -1
  168. package/dist/device/device.test.js +0 -243
  169. package/dist/device/frame-cipher.test.d.ts +0 -1
  170. package/dist/device/frame-cipher.test.js +0 -219
  171. package/dist/device/get-trust-level-fn.test.d.ts +0 -1
  172. package/dist/device/get-trust-level-fn.test.js +0 -685
  173. package/dist/device/streamed-socket.test.d.ts +0 -1
  174. package/dist/device/streamed-socket.test.js +0 -216
  175. package/dist/device/tx-encoding.test.d.ts +0 -1
  176. package/dist/device/tx-encoding.test.js +0 -295
  177. package/dist/device-pairing/cpace.test.d.ts +0 -1
  178. package/dist/device-pairing/cpace.test.js +0 -116
  179. package/dist/device-pairing/device-pairing.test.d.ts +0 -1
  180. package/dist/device-pairing/device-pairing.test.js +0 -211
  181. package/dist/hlc.test.d.ts +0 -1
  182. package/dist/hlc.test.js +0 -45
  183. package/dist/host-credentials.test.d.ts +0 -1
  184. package/dist/host-credentials.test.js +0 -88
  185. package/dist/identity/account-email.test.d.ts +0 -1
  186. package/dist/identity/account-email.test.js +0 -59
  187. package/dist/identity/anchor-document.test.d.ts +0 -1
  188. package/dist/identity/anchor-document.test.js +0 -16
  189. package/dist/identity/anchor-resolution.test.d.ts +0 -1
  190. package/dist/identity/anchor-resolution.test.js +0 -130
  191. package/dist/identity/key-change.test.d.ts +0 -1
  192. package/dist/identity/key-change.test.js +0 -811
  193. package/dist/invites/group-approval.test.d.ts +0 -1
  194. package/dist/invites/group-approval.test.js +0 -223
  195. package/dist/invites/invite-token.test.d.ts +0 -1
  196. package/dist/invites/invite-token.test.js +0 -123
  197. package/dist/keys.test.d.ts +0 -1
  198. package/dist/keys.test.js +0 -336
  199. package/dist/logging/console-logger.test.d.ts +0 -1
  200. package/dist/logging/console-logger.test.js +0 -300
  201. package/dist/logging/console-logs.table.test.d.ts +0 -1
  202. package/dist/logging/console-logs.table.test.js +0 -156
  203. package/dist/observable.test.d.ts +0 -1
  204. package/dist/observable.test.js +0 -309
  205. package/dist/package-build/build-package.test.d.ts +0 -1
  206. package/dist/package-build/build-package.test.js +0 -204
  207. package/dist/package-build/contract-add.test.d.ts +0 -1
  208. package/dist/package-build/contract-add.test.js +0 -467
  209. package/dist/package-build/freeze-contracts.test.d.ts +0 -1
  210. package/dist/package-build/freeze-contracts.test.js +0 -355
  211. package/dist/package-installer/package-author-signing.test.d.ts +0 -1
  212. package/dist/package-installer/package-author-signing.test.js +0 -200
  213. package/dist/package-installer/package-cloner.test.d.ts +0 -1
  214. package/dist/package-installer/package-cloner.test.js +0 -278
  215. package/dist/package-installer/package-creator.test.d.ts +0 -1
  216. package/dist/package-installer/package-creator.test.js +0 -908
  217. package/dist/package-installer/package-dev-tools.test.d.ts +0 -1
  218. package/dist/package-installer/package-dev-tools.test.js +0 -64
  219. package/dist/package-installer/package-installer.test.d.ts +0 -1
  220. package/dist/package-installer/package-installer.test.js +0 -882
  221. package/dist/package-installer/package-propagation.test.d.ts +0 -1
  222. package/dist/package-installer/package-propagation.test.js +0 -1269
  223. package/dist/package-installer/package-publisher.test.d.ts +0 -1
  224. package/dist/package-installer/package-publisher.test.js +0 -153
  225. package/dist/package-installer/package-remote-checker.test.d.ts +0 -1
  226. package/dist/package-installer/package-remote-checker.test.js +0 -334
  227. package/dist/package-installer/package-seed-installer.test.d.ts +0 -1
  228. package/dist/package-installer/package-seed-installer.test.js +0 -123
  229. package/dist/package-installer/package-tarball.test.d.ts +0 -1
  230. package/dist/package-installer/package-tarball.test.js +0 -75
  231. package/dist/package-installer/peers-core-installer.test.d.ts +0 -1
  232. package/dist/package-installer/peers-core-installer.test.js +0 -49
  233. package/dist/package-installer/peers-core-trust-anchor.test.d.ts +0 -1
  234. package/dist/package-installer/peers-core-trust-anchor.test.js +0 -155
  235. package/dist/package-loader/contract-package-loader.test.d.ts +0 -1
  236. package/dist/package-loader/contract-package-loader.test.js +0 -274
  237. package/dist/package-loader/host-authority-loading.test.d.ts +0 -1
  238. package/dist/package-loader/host-authority-loading.test.js +0 -104
  239. package/dist/package-loader/host-dispatch-policy.test.d.ts +0 -1
  240. package/dist/package-loader/host-dispatch-policy.test.js +0 -56
  241. package/dist/package-loader/isolated-artifact.test.d.ts +0 -1
  242. package/dist/package-loader/isolated-artifact.test.js +0 -688
  243. package/dist/package-loader/isolated-persistent-var-gateway.test.d.ts +0 -1
  244. package/dist/package-loader/isolated-persistent-var-gateway.test.js +0 -56
  245. package/dist/package-loader/isolated-table-gateway.test.d.ts +0 -1
  246. package/dist/package-loader/isolated-table-gateway.test.js +0 -633
  247. package/dist/package-loader/package-loader.test.d.ts +0 -1
  248. package/dist/package-loader/package-loader.test.js +0 -1764
  249. package/dist/package-loader/resolve-consumed-contracts.test.d.ts +0 -1
  250. package/dist/package-loader/resolve-consumed-contracts.test.js +0 -166
  251. package/dist/serial-json.compat.test.d.ts +0 -1
  252. package/dist/serial-json.compat.test.js +0 -369
  253. package/dist/serial-json.test.d.ts +0 -1
  254. package/dist/serial-json.test.js +0 -401
  255. package/dist/testing/mock-host-contract.test.d.ts +0 -1
  256. package/dist/testing/mock-host-contract.test.js +0 -782
  257. package/dist/utils.test.d.ts +0 -1
  258. package/dist/utils.test.js +0 -232
@@ -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 with: table rows and
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 or call from a
34
- * package built against a newer shape isn't refused. {@link fieldsToShapeSchema} builds the full
35
- * shape. An optional field refuses `null`: remove empty fields first with
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 fieldsToSchema}.
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
  *
@@ -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 with: table rows and
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 or call from a
17
- * package built against a newer shape isn't refused. {@link fieldsToShapeSchema} builds the full
18
- * shape. An optional field refuses `null`: remove empty fields first with
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, false, codeSchema);
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 fieldsToSchema}.
44
+ * {@link fieldsToArgumentsSchema}.
32
45
  *
33
46
  * @param fields Serializable field definitions.
34
47
  */
35
48
  function fieldsToShapeSchema(fields) {
36
- return buildFieldsSchema(fields, true);
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, shapes, open) {
48
- if (shapes && field.enumValues?.length) {
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 ? buildFieldsSchema(field.fields, true) : zod_1.z.object({});
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, shapes, codeSchema) {
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, shapes, !shapeField);
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.innerType) {
213
- _def = _def.innerType._def;
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
- if (_def.type) {
221
- _def = _def.type._def;
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
- const newField = { name, type, isArray, optional, description, defaultValue };
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)
@@ -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 = enumValuesOf(current);
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
- const literal = schemaField.type === field_type_1.FieldType.any ? literalType(schema) : undefined;
194
- const field = literal ? { ...schemaField, type: literal } : schemaField;
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
- const guard = (instances) => instances &&
440
- Object.fromEntries(Object.entries(instances).map(([name, instance]) => [
441
- name,
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
- tools: guard(resolution.tools),
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
  /**
@@ -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.
@@ -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",
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";