@oxy.so/contracts 5.8.0 → 6.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (219) hide show
  1. package/dist/cjs/accountAccess.js +6 -5
  2. package/dist/cjs/accountEmail.js +13 -5
  3. package/dist/cjs/accountGraph.js +10 -9
  4. package/dist/cjs/accountName.js +3 -2
  5. package/dist/cjs/agency.js +91 -34
  6. package/dist/cjs/agentKeys.js +21 -17
  7. package/dist/cjs/appAssertions.js +14 -13
  8. package/dist/cjs/applicationRoles.js +19 -12
  9. package/dist/cjs/civic.js +10 -9
  10. package/dist/cjs/client/check.js +61 -53
  11. package/dist/cjs/consoleOnboarding.js +9 -4
  12. package/dist/cjs/contentClaims.js +23 -14
  13. package/dist/cjs/deviceDirectory.js +11 -9
  14. package/dist/cjs/deviceSession.js +27 -25
  15. package/dist/cjs/email/messages.js +20 -18
  16. package/dist/cjs/emailAgentContext.js +11 -9
  17. package/dist/cjs/externalIdentity.js +15 -11
  18. package/dist/cjs/federationInstanceFetch.js +12 -7
  19. package/dist/cjs/identity.js +19 -17
  20. package/dist/cjs/identityLink.js +6 -4
  21. package/dist/cjs/identityProof.js +6 -4
  22. package/dist/cjs/inboxPush.js +5 -4
  23. package/dist/cjs/index.js +15 -6
  24. package/dist/cjs/inference/accountBilling.js +35 -33
  25. package/dist/cjs/inference/aliaModelRelease.js +9 -7
  26. package/dist/cjs/inference/attribution.js +14 -12
  27. package/dist/cjs/inference/catalogue.js +35 -29
  28. package/dist/cjs/inference/economics.js +24 -19
  29. package/dist/cjs/inference/embeddings.js +9 -7
  30. package/dist/cjs/inference/entitlement.js +17 -15
  31. package/dist/cjs/inference/errors.js +15 -8
  32. package/dist/cjs/inference/identifiers.js +33 -21
  33. package/dist/cjs/inference/inbox.js +37 -35
  34. package/dist/cjs/inference/modelDocumentation.js +16 -14
  35. package/dist/cjs/inference/money.js +5 -4
  36. package/dist/cjs/inference/priceVersion.js +10 -5
  37. package/dist/cjs/inference/providerConnection.js +21 -14
  38. package/dist/cjs/inference/realtime.js +88 -47
  39. package/dist/cjs/inference/request.js +27 -25
  40. package/dist/cjs/inference/routingPolicy.js +12 -10
  41. package/dist/cjs/inference/streamEvents.js +22 -16
  42. package/dist/cjs/inference/usage.js +32 -15
  43. package/dist/cjs/keyRecovery.js +8 -6
  44. package/dist/cjs/keyRotation.js +5 -4
  45. package/dist/cjs/linkedAccounts.js +22 -18
  46. package/dist/cjs/moderationReputation.js +29 -27
  47. package/dist/cjs/notifications.js +25 -9
  48. package/dist/cjs/numberChecks.js +45 -0
  49. package/dist/cjs/oauth.js +14 -12
  50. package/dist/cjs/organizations.js +23 -21
  51. package/dist/cjs/products/access.js +10 -8
  52. package/dist/cjs/products/billing.js +10 -8
  53. package/dist/cjs/products/checkout.js +22 -10
  54. package/dist/cjs/products/plans.js +15 -10
  55. package/dist/cjs/protocol.js +6 -5
  56. package/dist/cjs/recommendations.js +27 -19
  57. package/dist/cjs/reputation.js +15 -13
  58. package/dist/cjs/safety.js +43 -27
  59. package/dist/cjs/serviceToken.js +81 -2
  60. package/dist/cjs/sessionRevocation.js +8 -6
  61. package/dist/cjs/signIn.js +42 -24
  62. package/dist/cjs/stickers.js +19 -15
  63. package/dist/cjs/stringChecks.js +70 -0
  64. package/dist/cjs/transparency.js +14 -12
  65. package/dist/cjs/updates.js +24 -22
  66. package/dist/cjs/userInvalidation.js +7 -5
  67. package/dist/cjs/userResponse.js +8 -7
  68. package/dist/cjs/username.js +7 -6
  69. package/dist/esm/accountAccess.js +4 -3
  70. package/dist/esm/accountEmail.js +13 -5
  71. package/dist/esm/accountGraph.js +8 -7
  72. package/dist/esm/accountName.js +3 -2
  73. package/dist/esm/agency.js +90 -33
  74. package/dist/esm/agentKeys.js +21 -17
  75. package/dist/esm/appAssertions.js +11 -10
  76. package/dist/esm/applicationRoles.js +16 -9
  77. package/dist/esm/civic.js +8 -7
  78. package/dist/esm/client/check.js +61 -53
  79. package/dist/esm/consoleOnboarding.js +7 -2
  80. package/dist/esm/contentClaims.js +23 -14
  81. package/dist/esm/deviceDirectory.js +11 -9
  82. package/dist/esm/deviceSession.js +27 -25
  83. package/dist/esm/email/messages.js +18 -16
  84. package/dist/esm/emailAgentContext.js +11 -9
  85. package/dist/esm/externalIdentity.js +15 -11
  86. package/dist/esm/federationInstanceFetch.js +10 -5
  87. package/dist/esm/identity.js +17 -15
  88. package/dist/esm/identityLink.js +6 -4
  89. package/dist/esm/identityProof.js +6 -4
  90. package/dist/esm/inboxPush.js +3 -2
  91. package/dist/esm/index.js +4 -2
  92. package/dist/esm/inference/accountBilling.js +33 -31
  93. package/dist/esm/inference/aliaModelRelease.js +7 -5
  94. package/dist/esm/inference/attribution.js +14 -12
  95. package/dist/esm/inference/catalogue.js +33 -27
  96. package/dist/esm/inference/economics.js +22 -17
  97. package/dist/esm/inference/embeddings.js +9 -7
  98. package/dist/esm/inference/entitlement.js +15 -13
  99. package/dist/esm/inference/errors.js +13 -6
  100. package/dist/esm/inference/identifiers.js +31 -19
  101. package/dist/esm/inference/inbox.js +37 -35
  102. package/dist/esm/inference/modelDocumentation.js +14 -12
  103. package/dist/esm/inference/money.js +3 -2
  104. package/dist/esm/inference/priceVersion.js +8 -3
  105. package/dist/esm/inference/providerConnection.js +19 -12
  106. package/dist/esm/inference/realtime.js +85 -44
  107. package/dist/esm/inference/request.js +25 -23
  108. package/dist/esm/inference/routingPolicy.js +9 -7
  109. package/dist/esm/inference/streamEvents.js +20 -14
  110. package/dist/esm/inference/usage.js +30 -13
  111. package/dist/esm/keyRecovery.js +8 -6
  112. package/dist/esm/keyRotation.js +5 -4
  113. package/dist/esm/linkedAccounts.js +20 -16
  114. package/dist/esm/moderationReputation.js +27 -25
  115. package/dist/esm/notifications.js +23 -7
  116. package/dist/esm/numberChecks.js +41 -0
  117. package/dist/esm/oauth.js +14 -12
  118. package/dist/esm/organizations.js +23 -21
  119. package/dist/esm/products/access.js +10 -8
  120. package/dist/esm/products/billing.js +10 -8
  121. package/dist/esm/products/checkout.js +22 -10
  122. package/dist/esm/products/plans.js +15 -10
  123. package/dist/esm/protocol.js +4 -3
  124. package/dist/esm/recommendations.js +25 -17
  125. package/dist/esm/reputation.js +13 -11
  126. package/dist/esm/safety.js +43 -27
  127. package/dist/esm/serviceToken.js +80 -1
  128. package/dist/esm/sessionRevocation.js +6 -4
  129. package/dist/esm/signIn.js +42 -24
  130. package/dist/esm/stickers.js +17 -13
  131. package/dist/esm/stringChecks.js +63 -0
  132. package/dist/esm/transparency.js +14 -12
  133. package/dist/esm/updates.js +22 -20
  134. package/dist/esm/userInvalidation.js +4 -2
  135. package/dist/esm/userResponse.js +4 -3
  136. package/dist/esm/username.js +3 -2
  137. package/dist/types/accountAccess.d.ts +29 -70
  138. package/dist/types/accountEmail.d.ts +2 -14
  139. package/dist/types/accountGraph.d.ts +179 -171
  140. package/dist/types/accountName.d.ts +1 -1
  141. package/dist/types/accountSubject.d.ts +20 -93
  142. package/dist/types/agency.d.ts +528 -2924
  143. package/dist/types/agentKeys.d.ts +48 -421
  144. package/dist/types/appAssertions.d.ts +56 -210
  145. package/dist/types/applicationRoles.d.ts +30 -276
  146. package/dist/types/avatarCharacter.d.ts +1 -1
  147. package/dist/types/civic.d.ts +1 -13
  148. package/dist/types/client/agentKeys.d.ts +18 -18
  149. package/dist/types/client/appAssertions.d.ts +3 -3
  150. package/dist/types/client/check.d.ts +13 -13
  151. package/dist/types/client/deviceDirectory.d.ts +51 -51
  152. package/dist/types/client/deviceSession.d.ts +14 -14
  153. package/dist/types/client/organizations.d.ts +25 -25
  154. package/dist/types/client/products.d.ts +33 -33
  155. package/dist/types/client/recommendations.d.ts +2 -2
  156. package/dist/types/client/safety.d.ts +45 -45
  157. package/dist/types/client/sessionStatus.d.ts +4 -4
  158. package/dist/types/client/signIn.d.ts +1 -1
  159. package/dist/types/commonsSignIn.d.ts +4 -1
  160. package/dist/types/consoleOnboarding.d.ts +24 -44
  161. package/dist/types/contentClaims.d.ts +24 -180
  162. package/dist/types/deviceDirectory.d.ts +109 -1040
  163. package/dist/types/deviceSession.d.ts +36 -298
  164. package/dist/types/email/messages.d.ts +212 -1793
  165. package/dist/types/emailAgentContext.d.ts +10 -194
  166. package/dist/types/externalIdentity.d.ts +121 -615
  167. package/dist/types/federationInstanceFetch.d.ts +3 -32
  168. package/dist/types/identity.d.ts +15 -92
  169. package/dist/types/identityLink.d.ts +6 -84
  170. package/dist/types/identityProof.d.ts +5 -17
  171. package/dist/types/inboxPush.d.ts +1 -9
  172. package/dist/types/index.d.ts +5 -3
  173. package/dist/types/inference/accountBilling.d.ts +151 -488
  174. package/dist/types/inference/aliaModelRelease.d.ts +42 -439
  175. package/dist/types/inference/attribution.d.ts +75 -104
  176. package/dist/types/inference/catalogue.d.ts +417 -1599
  177. package/dist/types/inference/economics.d.ts +69 -276
  178. package/dist/types/inference/embeddings.d.ts +110 -406
  179. package/dist/types/inference/entitlement.d.ts +80 -335
  180. package/dist/types/inference/errors.d.ts +90 -102
  181. package/dist/types/inference/identifiers.d.ts +12 -4
  182. package/dist/types/inference/inbox.d.ts +105 -420
  183. package/dist/types/inference/modelDocumentation.d.ts +201 -1390
  184. package/dist/types/inference/money.d.ts +65 -32
  185. package/dist/types/inference/priceVersion.d.ts +53 -120
  186. package/dist/types/inference/providerConnection.d.ts +253 -710
  187. package/dist/types/inference/realtime.d.ts +954 -6825
  188. package/dist/types/inference/request.d.ts +300 -2572
  189. package/dist/types/inference/routingPolicy.d.ts +95 -503
  190. package/dist/types/inference/streamEvents.d.ts +253 -721
  191. package/dist/types/inference/usage.d.ts +317 -950
  192. package/dist/types/keyRecovery.d.ts +3 -51
  193. package/dist/types/keyRotation.d.ts +3 -38
  194. package/dist/types/linkedAccounts.d.ts +50 -236
  195. package/dist/types/moderationReputation.d.ts +81 -14
  196. package/dist/types/notifications.d.ts +19 -51
  197. package/dist/types/numberChecks.d.ts +9 -0
  198. package/dist/types/oauth.d.ts +101 -809
  199. package/dist/types/organizations.d.ts +268 -921
  200. package/dist/types/oxyRecordTypes.d.ts +11 -1
  201. package/dist/types/products/access.d.ts +125 -775
  202. package/dist/types/products/billing.d.ts +67 -503
  203. package/dist/types/products/checkout.d.ts +16 -69
  204. package/dist/types/products/plans.d.ts +33 -366
  205. package/dist/types/recommendations.d.ts +76 -389
  206. package/dist/types/reputation.d.ts +37 -5
  207. package/dist/types/safety.d.ts +408 -2048
  208. package/dist/types/serviceToken.d.ts +247 -7
  209. package/dist/types/sessionRevocation.d.ts +2 -17
  210. package/dist/types/sessionStatus.d.ts +27 -115
  211. package/dist/types/signIn.d.ts +53 -553
  212. package/dist/types/stickers.d.ts +67 -819
  213. package/dist/types/stringChecks.d.ts +16 -0
  214. package/dist/types/transparency.d.ts +14 -302
  215. package/dist/types/updates.d.ts +60 -316
  216. package/dist/types/userInvalidation.d.ts +4 -13
  217. package/dist/types/userResponse.d.ts +302 -2400
  218. package/dist/types/username.d.ts +3 -3
  219. package/package.json +2 -2
@@ -1,3 +1,4 @@
1
+ import { utf16MinLength } from './stringChecks.js';
1
2
  /**
2
3
  * Wire contract for `GET /internal/accounts/:accountId/access/:userId`: Oxy
3
4
  * answers a trusted first-party service's question "may this person act FOR
@@ -49,15 +50,15 @@ export const accountAccessSourceSchema = z.enum(ACCOUNT_ACCESS_SOURCES);
49
50
  * revokes), never on `role`.
50
51
  */
51
52
  export const accountAccessGrantSchema = z.object({
52
- role: z.string().min(1),
53
- permissions: z.array(z.string().min(1)),
53
+ role: z.string().check(utf16MinLength(1)),
54
+ permissions: z.array(z.string().check(utf16MinLength(1))),
54
55
  /** Only an active membership grants access, so this is the one value. */
55
56
  status: z.literal('active'),
56
57
  source: accountAccessSourceSchema,
57
58
  });
58
59
  export const accountAccessVerdictSchema = z
59
60
  .object({
60
- accountId: z.string().min(1),
61
+ accountId: z.string().check(utf16MinLength(1)),
61
62
  /** `null` when no such account exists. */
62
63
  kind: accountKindSchema.nullable(),
63
64
  /** `null` means: this person may not act for this account. */
@@ -1,3 +1,5 @@
1
+ import { integerCheck } from './numberChecks.js';
2
+ import { utf16MaxLength, utf16MinLength } from './stringChecks.js';
1
3
  /**
2
4
  * Email codes and tickets (ADR 0030).
3
5
  *
@@ -18,7 +20,13 @@ import { z } from 'zod';
18
20
  import { EMAIL_CODE_LENGTH } from './client/accountEmail.js';
19
21
  export { EMAIL_VERIFICATION_PURPOSES, EMAIL_CODE_LENGTH, EMAIL_CODE_TTL_MS, EMAIL_CODE_MAX_ATTEMPTS, EMAIL_TICKET_TTL_MS, EMAIL_VERIFICATION_ERROR_CODES, } from './client/accountEmail.js';
20
22
  /** An email address as the API stores it: trimmed and lowercase. */
21
- export const emailAddressSchema = z.string().trim().toLowerCase().min(3).max(254).email();
23
+ export const emailAddressSchema = z
24
+ .string()
25
+ .trim()
26
+ .toLowerCase()
27
+ .check(utf16MinLength(3))
28
+ .check(utf16MaxLength(254))
29
+ .email();
22
30
  /** An opaque one-use ticket (32 random bytes, base64url). */
23
31
  export const emailTicketSchema = z
24
32
  .string()
@@ -29,13 +37,13 @@ export const emailVerificationStartRequestSchema = z
29
37
  .object({ purpose: z.literal('signup'), email: emailAddressSchema })
30
38
  .strict();
31
39
  export const emailVerificationStartResponseSchema = z.object({
32
- verificationId: z.string().min(1).max(64),
33
- expiresAt: z.number().int().positive(),
40
+ verificationId: z.string().check(utf16MinLength(1)).check(utf16MaxLength(64)),
41
+ expiresAt: z.number().check(integerCheck()).positive(),
34
42
  });
35
43
  /** `POST /auth/email/verify/confirm` */
36
44
  export const emailVerificationConfirmRequestSchema = z
37
45
  .object({
38
- verificationId: z.string().trim().min(1).max(64),
46
+ verificationId: z.string().trim().check(utf16MinLength(1)).check(utf16MaxLength(64)),
39
47
  code: z
40
48
  .string()
41
49
  .trim()
@@ -44,5 +52,5 @@ export const emailVerificationConfirmRequestSchema = z
44
52
  .strict();
45
53
  export const emailVerificationConfirmResponseSchema = z.object({
46
54
  ticket: emailTicketSchema,
47
- expiresAt: z.number().int().positive(),
55
+ expiresAt: z.number().check(integerCheck()).positive(),
48
56
  });
@@ -1,3 +1,4 @@
1
+ import { utf16MaxLength, utf16MinLength } from './stringChecks.js';
1
2
  /**
2
3
  * Account graph wire contracts — the account-kind vocabulary, the account
3
4
  * category taxonomy, and the create-account input.
@@ -69,9 +70,9 @@ export const accountCategoriesSchema = z
69
70
  */
70
71
  export const accountNameSchema = z
71
72
  .object({
72
- first: z.string().trim().max(100).optional(),
73
- last: z.string().trim().max(100).optional(),
74
- displayName: z.string().trim().max(ACCOUNT_TITLE_MAX_LENGTH).optional(),
73
+ first: z.string().trim().check(utf16MaxLength(100)).optional(),
74
+ last: z.string().trim().check(utf16MaxLength(100)).optional(),
75
+ displayName: z.string().trim().check(utf16MaxLength(ACCOUNT_TITLE_MAX_LENGTH)).optional(),
75
76
  })
76
77
  .optional();
77
78
  /**
@@ -87,7 +88,7 @@ export const accountNameSchema = z
87
88
  */
88
89
  export const createAccountRequestSchema = z
89
90
  .object({
90
- parentAccountId: z.string().trim().min(1).optional(),
91
+ parentAccountId: z.string().trim().check(utf16MinLength(1)).optional(),
91
92
  kind: childAccountKindSchema,
92
93
  /**
93
94
  * The SAME policy a person's handle is held to. `users.username` is one unique
@@ -102,9 +103,9 @@ export const createAccountRequestSchema = z
102
103
  */
103
104
  username: usernameSchema,
104
105
  name: accountNameSchema,
105
- bio: z.string().trim().max(500).optional(),
106
+ bio: z.string().trim().check(utf16MaxLength(500)).optional(),
106
107
  avatar: z.string().optional(),
107
- description: z.string().trim().max(1000).optional(),
108
+ description: z.string().trim().check(utf16MaxLength(1000)).optional(),
108
109
  /**
109
110
  * A named color preset KEY (`"blue"`, `"mint"`, …), never a hex value.
110
111
  *
@@ -121,7 +122,7 @@ export const createAccountRequestSchema = z
121
122
  * would drift apart silently. What this shape does is keep an over-long or
122
123
  * non-string value from reaching the service at all.
123
124
  */
124
- color: z.string().trim().max(32).optional(),
125
+ color: z.string().trim().check(utf16MaxLength(32)).optional(),
125
126
  /** Ordered, PRIMARY FIRST — see rule 2 above {@link ACCOUNT_CATEGORY_IDS}. */
126
127
  accountCategories: accountCategoriesSchema.optional(),
127
128
  organizationType: z.enum(ORGANIZATION_TYPES).optional(),
@@ -1,3 +1,4 @@
1
+ import { utf16MaxLength, utf16MinLength } from './stringChecks.js';
1
2
  import { z } from 'zod';
2
3
  // The Zod-free half of this contract lives in `./client/` (`@oxy.so/contracts/client`);
3
4
  // it is re-exported here so the root entry carries the whole policy.
@@ -7,6 +8,6 @@ export { ACCOUNT_NAME_POLICY_BY_KIND, ACCOUNT_TITLE_DISALLOWED_SOURCE, ACCOUNT_T
7
8
  export const accountTitleSchema = z
8
9
  .string()
9
10
  .trim()
10
- .min(1)
11
- .max(ACCOUNT_TITLE_MAX_LENGTH)
11
+ .check(utf16MinLength(1))
12
+ .check(utf16MaxLength(ACCOUNT_TITLE_MAX_LENGTH))
12
13
  .refine(isPlainTextTitle, 'Name must be plain text');
@@ -1,11 +1,13 @@
1
+ import { integerCheck } from './numberChecks.js';
2
+ import { isoDateTime, urlCheck, utf16MaxLength, utf16MinLength } from './stringChecks.js';
1
3
  import { z } from 'zod';
2
4
  import { catalogInvocationPathParameters, findOverlappingCatalogInvocations, } from './capabilityInvocation.js';
3
- const nonEmptyStringSchema = z.string().trim().min(1);
4
- const identifierSchema = z.string().trim().min(1).max(255);
5
+ const nonEmptyStringSchema = z.string().trim().check(utf16MinLength(1));
6
+ const identifierSchema = z.string().trim().check(utf16MinLength(1)).check(utf16MaxLength(255));
5
7
  const limitKeySchema = z
6
8
  .string()
7
9
  .regex(/^[A-Za-z][A-Za-z0-9_]*(?:\.[A-Za-z][A-Za-z0-9_]*)*$/, 'limit keys must be dot-separated input property names')
8
- .max(255);
10
+ .check(utf16MaxLength(255));
9
11
  const auditCodeSchema = z.string().regex(/^[A-Za-z0-9_.:-]{1,128}$/);
10
12
  const sha256HexSchema = z.string().regex(/^[a-f0-9]{64}$/);
11
13
  const invocationPathSchema = z
@@ -57,7 +59,7 @@ export const foregroundExecutionAuthorizationInputSchema = z
57
59
  .strict(),
58
60
  runId: identifierSchema,
59
61
  stepId: identifierSchema.optional(),
60
- expiresAt: z.string().datetime(),
62
+ expiresAt: z.string().check(isoDateTime()),
61
63
  })
62
64
  .strict();
63
65
  export const resourceRefSchema = z
@@ -68,6 +70,50 @@ export const resourceRefSchema = z
68
70
  resourceId: identifierSchema,
69
71
  })
70
72
  .strict();
73
+ export const firstPartyTaskInputSchema = z
74
+ .object({
75
+ origin: z
76
+ .object({ kind: z.enum(['request', 'goal', 'automation']), id: identifierSchema })
77
+ .strict(),
78
+ actor: executionActorRefSchema,
79
+ effectiveAccountId: identifierSchema,
80
+ expiresAt: z.string().check(isoDateTime()),
81
+ })
82
+ .strict();
83
+ /** Oxy-owned tools use the authenticated requester's task, never per-app grants. */
84
+ export const firstPartyExecutionAuthorizationInputSchema = z
85
+ .object({
86
+ authority: z.literal('first_party'),
87
+ kind: z.enum(['direct_request', 'automation']).default('direct_request'),
88
+ actor: executionActorRefSchema,
89
+ resource: resourceRefSchema,
90
+ tool: identifierSchema,
91
+ expectedCatalog: foregroundExecutionAuthorizationInputSchema.shape.expectedCatalog,
92
+ runId: identifierSchema.optional(),
93
+ stepId: identifierSchema.optional(),
94
+ automationId: identifierSchema.optional(),
95
+ limits: z
96
+ .array(z
97
+ .object({
98
+ tool: identifierSchema,
99
+ key: limitKeySchema,
100
+ value: z.union([z.number().finite(), z.boolean()]),
101
+ })
102
+ .strict())
103
+ .default([]),
104
+ expiresAt: z.string().check(isoDateTime()),
105
+ })
106
+ .strict()
107
+ .superRefine((input, context) => {
108
+ if (input.kind === 'direct_request'
109
+ ? !input.runId || input.automationId !== undefined
110
+ : !input.automationId || input.runId !== undefined || input.stepId !== undefined) {
111
+ context.addIssue({
112
+ code: z.ZodIssueCode.custom,
113
+ message: 'Bind either a direct run or an automation identity.',
114
+ });
115
+ }
116
+ });
71
117
  export const toolGrantOverrideSchema = z
72
118
  .object({
73
119
  tool: identifierSchema,
@@ -115,9 +161,9 @@ export const capabilityCoordinatorSchema = z
115
161
  /** Opt-in catalogue pin; legacy issuance omits expectedCatalog and its claim. */
116
162
  export const capabilityTicketRequestSchema = z
117
163
  .object({
118
- executionAuthorizationId: z.string().min(1),
119
- runId: z.string().min(1).optional(),
120
- stepId: z.string().min(1).optional(),
164
+ executionAuthorizationId: z.string().check(utf16MinLength(1)),
165
+ runId: z.string().check(utf16MinLength(1)).optional(),
166
+ stepId: z.string().check(utf16MinLength(1)).optional(),
121
167
  expectedCatalog: capabilityCatalogBindingSchema.optional(),
122
168
  })
123
169
  .strict();
@@ -134,10 +180,10 @@ export const delegationGrantSchema = z
134
180
  limits: z.array(grantLimitSchema).default([]),
135
181
  maximumAutonomy: autonomyLevelSchema,
136
182
  canRedelegate: z.boolean().default(false),
137
- expiresAt: z.string().datetime().nullable(),
138
- revokedAt: z.string().datetime().nullable().default(null),
139
- createdAt: z.string().datetime(),
140
- updatedAt: z.string().datetime(),
183
+ expiresAt: z.string().check(isoDateTime()).nullable(),
184
+ revokedAt: z.string().check(isoDateTime()).nullable().default(null),
185
+ createdAt: z.string().check(isoDateTime()),
186
+ updatedAt: z.string().check(isoDateTime()),
141
187
  })
142
188
  .strict();
143
189
  /**
@@ -163,10 +209,10 @@ export const agentRequesterCeilingSchema = agentRequesterCeilingWriteSchema
163
209
  agentAccountId: identifierSchema,
164
210
  appId: identifierSchema,
165
211
  catalog: capabilityCatalogBindingSchema,
166
- version: z.number().int().positive(),
167
- revokedAt: z.string().datetime().nullable(),
168
- createdAt: z.string().datetime(),
169
- updatedAt: z.string().datetime(),
212
+ version: z.number().check(integerCheck()).positive(),
213
+ revokedAt: z.string().check(isoDateTime()).nullable(),
214
+ createdAt: z.string().check(isoDateTime()),
215
+ updatedAt: z.string().check(isoDateTime()),
170
216
  })
171
217
  .strict();
172
218
  /**
@@ -186,8 +232,8 @@ export const applicationAgentSchema = applicationAgentWriteSchema
186
232
  applicationId: identifierSchema,
187
233
  agentAccountId: identifierSchema,
188
234
  createdByUserId: identifierSchema.nullable(),
189
- createdAt: z.string().datetime(),
190
- updatedAt: z.string().datetime(),
235
+ createdAt: z.string().check(isoDateTime()),
236
+ updatedAt: z.string().check(isoDateTime()),
191
237
  })
192
238
  .strict();
193
239
  /**
@@ -236,14 +282,14 @@ export const automationDefinitionSchema = z
236
282
  objective: nonEmptyStringSchema,
237
283
  trigger: automationTriggerSchema,
238
284
  actorSelection: automationActorSelectionSchema,
239
- inputs: z.record(z.unknown()),
285
+ inputs: z.record(z.string(), z.unknown()),
240
286
  resources: z.array(resourceRefSchema),
241
287
  dataFlow: automationDataFlowSchema,
242
288
  maximumAutonomy: autonomyLevelSchema,
243
289
  limits: z.array(grantLimitSchema).default([]),
244
290
  enabled: z.boolean(),
245
- createdAt: z.string().datetime(),
246
- updatedAt: z.string().datetime(),
291
+ createdAt: z.string().check(isoDateTime()),
292
+ updatedAt: z.string().check(isoDateTime()),
247
293
  })
248
294
  .strict();
249
295
  export const capabilityTicketClaimsSchema = z
@@ -252,12 +298,14 @@ export const capabilityTicketClaimsSchema = z
252
298
  aud: identifierSchema,
253
299
  sub: identifierSchema,
254
300
  jti: identifierSchema,
255
- iat: z.number().int().nonnegative(),
256
- exp: z.number().int().positive(),
301
+ iat: z.number().check(integerCheck()).nonnegative(),
302
+ exp: z.number().check(integerCheck()).positive(),
257
303
  runId: identifierSchema,
258
304
  stepId: identifierSchema.optional(),
259
305
  automationId: identifierSchema.optional(),
260
306
  executionAuthorization: executionAuthorizationRefSchema,
307
+ authority: z.enum(['first_party', 'external']).optional(),
308
+ taskId: identifierSchema.optional(),
261
309
  coordinator: capabilityCoordinatorSchema,
262
310
  /** Signed only for callers that explicitly requested a pinned catalogue. */
263
311
  catalog: capabilityCatalogBindingSchema.optional(),
@@ -291,6 +339,7 @@ export const capabilityTicketClaimsSchema = z
291
339
  });
292
340
  }
293
341
  if (claims.actor.type === 'requester' &&
342
+ claims.authority !== 'first_party' &&
294
343
  (claims.actor.accountId !== claims.requesterAccountId ||
295
344
  claims.executionAuthorization.kind !== 'direct_request' ||
296
345
  claims.autonomy !== 'read_only' ||
@@ -302,6 +351,14 @@ export const capabilityTicketClaimsSchema = z
302
351
  message: 'requester actors require their exact principal and direct read-only authority without standing grants',
303
352
  });
304
353
  }
354
+ if (claims.authority === 'first_party' &&
355
+ (claims.grantId !== undefined || claims.ceilingId !== undefined)) {
356
+ context.addIssue({
357
+ code: z.ZodIssueCode.custom,
358
+ message: 'Own tool tasks cannot carry external grants or ceilings',
359
+ path: ['authority'],
360
+ });
361
+ }
305
362
  if (claims.ceilingId !== undefined) {
306
363
  if (claims.grantId !== undefined) {
307
364
  context.addIssue({
@@ -363,7 +420,7 @@ export const invocationPrincipalSchema = z.discriminatedUnion('kind', [
363
420
  originAccountId: identifierSchema,
364
421
  activeAccountId: identifierSchema,
365
422
  scopes: z.array(identifierSchema),
366
- resource: z.string().url(),
423
+ resource: z.string().check(urlCheck()),
367
424
  })
368
425
  .strict(),
369
426
  z
@@ -393,7 +450,7 @@ export const auditResultSchema = z
393
450
  export const auditEventSchema = z
394
451
  .object({
395
452
  eventId: identifierSchema,
396
- occurredAt: z.string().datetime(),
453
+ occurredAt: z.string().check(isoDateTime()),
397
454
  requesterAccountId: identifierSchema,
398
455
  coordinator: capabilityCoordinatorSchema,
399
456
  executor: executionActorRefSchema,
@@ -440,8 +497,8 @@ export const catalogToolSchema = z
440
497
  name: identifierSchema,
441
498
  version: identifierSchema,
442
499
  description: nonEmptyStringSchema,
443
- inputSchema: z.record(z.unknown()),
444
- outputSchema: z.record(z.unknown()).optional(),
500
+ inputSchema: z.record(z.string(), z.unknown()),
501
+ outputSchema: z.record(z.string(), z.unknown()).optional(),
445
502
  capabilityPackage: capabilityPackageSchema,
446
503
  requiredCapabilities: z.array(identifierSchema).min(1),
447
504
  resourceTypes: z.array(identifierSchema).min(1),
@@ -618,7 +675,7 @@ export const catalogEventSchema = z
618
675
  type: identifierSchema,
619
676
  version: identifierSchema,
620
677
  description: nonEmptyStringSchema,
621
- dataSchema: z.record(z.unknown()),
678
+ dataSchema: z.record(z.string(), z.unknown()),
622
679
  resourceTypes: z.array(identifierSchema).min(1),
623
680
  })
624
681
  .strict();
@@ -632,7 +689,7 @@ export const catalogFeatureSchema = z
632
689
  key: z
633
690
  .string()
634
691
  .regex(/^[a-z][a-z0-9_-]*(?:\.[a-z][a-z0-9_-]*)*$/, 'feature keys are dot-separated slugs')
635
- .max(128),
692
+ .check(utf16MaxLength(128)),
636
693
  description: nonEmptyStringSchema,
637
694
  checkTool: identifierSchema,
638
695
  consumeTool: identifierSchema.optional(),
@@ -649,7 +706,7 @@ export const appCapabilityCatalogSchema = z
649
706
  /** HTTPS origin that serves the catalog's internal invocation paths. */
650
707
  internalBaseUrl: z
651
708
  .string()
652
- .url()
709
+ .check(urlCheck())
653
710
  .superRefine((value, context) => {
654
711
  const url = new URL(value);
655
712
  const localDevelopment = url.hostname === 'localhost' || url.hostname === '127.0.0.1';
@@ -673,7 +730,7 @@ export const appCapabilityCatalogSchema = z
673
730
  .object({
674
731
  resource: z
675
732
  .string()
676
- .url()
733
+ .check(urlCheck())
677
734
  .superRefine((value, context) => {
678
735
  const url = new URL(value);
679
736
  const localDevelopment = url.hostname === 'localhost' ||
@@ -783,7 +840,7 @@ export const catalogRegistrationSchema = z
783
840
  catalog: appCapabilityCatalogSchema,
784
841
  digest: z.string().regex(/^[a-f0-9]{64}$/),
785
842
  signature: nonEmptyStringSchema,
786
- deployedAt: z.string().datetime(),
843
+ deployedAt: z.string().check(isoDateTime()),
787
844
  })
788
845
  .strict();
789
846
  export const normalizedAppEventSchema = z
@@ -793,8 +850,8 @@ export const normalizedAppEventSchema = z
793
850
  accountId: identifierSchema,
794
851
  resource: resourceRefSchema,
795
852
  type: identifierSchema,
796
- occurredAt: z.string().datetime(),
797
- data: z.record(z.unknown()),
853
+ occurredAt: z.string().check(isoDateTime()),
854
+ data: z.record(z.string(), z.unknown()),
798
855
  })
799
856
  .strict();
800
857
  /** The actor types that may execute `tool`: the one reading of an absent `actors`. */
@@ -1,3 +1,5 @@
1
+ import { integerCheck } from './numberChecks.js';
2
+ import { isoDateTime, utf16MaxLength, utf16MinLength } from './stringChecks.js';
1
3
  /** Autonomous runtime proof. No private key crosses this contract. */
2
4
  import { z } from 'zod';
3
5
  import { reauthProofSchema } from './signIn.js';
@@ -11,13 +13,13 @@ export const agentProofClaimsSchema = z
11
13
  version: z.literal(1),
12
14
  audience: z.literal(AGENT_PROOF_AUDIENCE),
13
15
  action: z.enum(AGENT_PROOF_ACTIONS),
14
- accountId: z.string().min(1),
15
- actorId: z.string().min(1),
16
+ accountId: z.string().check(utf16MinLength(1)),
17
+ actorId: z.string().check(utf16MinLength(1)),
16
18
  authMethodId: z.string().nullable(),
17
- publicKey: z.string().min(1),
19
+ publicKey: z.string().check(utf16MinLength(1)),
18
20
  payloadDigest: z.string().regex(/^[0-9a-f]{64}$/),
19
21
  challenge: z.string().regex(/^[0-9a-f]{64}$/),
20
- expiresAt: z.number().int().positive(),
22
+ expiresAt: z.number().check(integerCheck()).positive(),
21
23
  })
22
24
  .strict();
23
25
  /** Different proof roles cannot substitute for one another on the same operation. */
@@ -35,19 +37,19 @@ export const agentSignatureSchema = z
35
37
  signature: z
36
38
  .string()
37
39
  .regex(/^[0-9a-f]+$/i)
38
- .max(160),
39
- timestamp: z.number().int().positive(),
40
+ .check(utf16MaxLength(160)),
41
+ timestamp: z.number().check(integerCheck()).positive(),
40
42
  })
41
43
  .strict();
42
44
  export const agentChallengeRequestSchema = z
43
- .object({ publicKey: z.string().trim().min(1).max(130) })
45
+ .object({ publicKey: z.string().trim().check(utf16MinLength(1)).check(utf16MaxLength(130)) })
44
46
  .strict();
45
47
  export const agentVerifyRequestSchema = agentSignatureSchema
46
- .extend({ publicKey: z.string().trim().min(1).max(130) })
48
+ .extend({ publicKey: z.string().trim().check(utf16MinLength(1)).check(utf16MaxLength(130)) })
47
49
  .strict();
48
50
  const newKey = {
49
- publicKey: z.string().trim().min(1).max(130),
50
- label: z.string().trim().min(1).max(120),
51
+ publicKey: z.string().trim().check(utf16MinLength(1)).check(utf16MaxLength(130)),
52
+ label: z.string().trim().check(utf16MinLength(1)).check(utf16MaxLength(120)),
51
53
  };
52
54
  export const agentKeyOperationSchema = z.discriminatedUnion('operation', [
53
55
  z.object({ operation: z.literal('enroll'), ...newKey }).strict(),
@@ -55,21 +57,23 @@ export const agentKeyOperationSchema = z.discriminatedUnion('operation', [
55
57
  z
56
58
  .object({ operation: z.literal('rotate'), ...newKey, retireCurrent: z.boolean().optional() })
57
59
  .strict(),
58
- z.object({ operation: z.literal('revoke'), methodId: z.string().min(1) }).strict(),
60
+ z
61
+ .object({ operation: z.literal('revoke'), methodId: z.string().check(utf16MinLength(1)) })
62
+ .strict(),
59
63
  ]);
60
64
  export const agentKeyOperationProofSchema = z
61
65
  .object({
62
66
  challenge: z.string().regex(/^[0-9a-f]{64}$/),
63
- timestamp: z.number().int().positive(),
67
+ timestamp: z.number().check(integerCheck()).positive(),
64
68
  keySignature: z
65
69
  .string()
66
70
  .regex(/^[0-9a-f]+$/i)
67
- .max(160)
71
+ .check(utf16MaxLength(160))
68
72
  .optional(),
69
73
  governorSignature: z
70
74
  .string()
71
75
  .regex(/^[0-9a-f]+$/i)
72
- .max(160)
76
+ .check(utf16MaxLength(160))
73
77
  .optional(),
74
78
  reauth: reauthProofSchema.optional(),
75
79
  })
@@ -102,9 +106,9 @@ export const agentKeyListResponseSchema = z
102
106
  label: z.string(),
103
107
  enrolledByUserId: z.string().nullable(),
104
108
  enrollmentMethod: z.enum(['governor', 'rotation', 'recovery']),
105
- linkedAt: z.string().datetime(),
106
- lastUsedAt: z.string().datetime().nullable(),
107
- revokedAt: z.string().datetime().nullable(),
109
+ linkedAt: z.string().check(isoDateTime()),
110
+ lastUsedAt: z.string().check(isoDateTime()).nullable(),
111
+ revokedAt: z.string().check(isoDateTime()).nullable(),
108
112
  })
109
113
  .strict()),
110
114
  })
@@ -1,3 +1,4 @@
1
+ import { isoDateTime, utf16MaxLength, utf16MinLength } from './stringChecks.js';
1
2
  /**
2
3
  * App assertions (ADR 0045): how an Oxy app proves which app it is.
3
4
  *
@@ -25,12 +26,12 @@
25
26
  import { z } from 'zod';
26
27
  import { APP_ASSERTION_CHALLENGE_PURPOSES, APP_ASSERTION_ERROR_CODES, APP_ASSERTION_PLATFORMS, OXY_APP_ASSERTION_AUDIENCE, OXY_APP_ASSERTION_HEADER, OXY_APP_ASSERTION_TTL_SECONDS, OXY_APP_ASSERTION_TYPE, } from './client/appAssertions.js';
27
28
  export { APP_ASSERTION_CHALLENGE_PURPOSES, APP_ASSERTION_ERROR_CODES, APP_ASSERTION_PLATFORMS, OXY_APP_ASSERTION_AUDIENCE, OXY_APP_ASSERTION_HEADER, OXY_APP_ASSERTION_TTL_SECONDS, OXY_APP_ASSERTION_TYPE, };
28
- const applicationIdSchema = z.string().trim().min(1).max(255);
29
+ const applicationIdSchema = z.string().trim().check(utf16MinLength(1)).check(utf16MaxLength(255));
29
30
  const base64Url32Schema = z.string().regex(/^[A-Za-z0-9_-]{43}$/);
30
31
  const base64Schema = (max) => z
31
32
  .string()
32
- .min(4)
33
- .max(max)
33
+ .check(utf16MinLength(4))
34
+ .check(utf16MaxLength(max))
34
35
  .regex(/^[A-Za-z0-9+/]+={0,2}$/);
35
36
  export const appAssertionPlatformSchema = z.enum(APP_ASSERTION_PLATFORMS);
36
37
  export const appAssertionErrorCodeSchema = z.enum(APP_ASSERTION_ERROR_CODES);
@@ -50,12 +51,12 @@ export function isExactHttpsOrigin(value) {
50
51
  /** An exact `https://` origin, in the form a browser sends in `Origin` (`https://mention.earth`). */
51
52
  export const applicationWebOriginSchema = z
52
53
  .string()
53
- .max(255)
54
+ .check(utf16MaxLength(255))
54
55
  .refine(isExactHttpsOrigin, 'Must be an exact https origin, as a browser sends it');
55
56
  /** A Java-style Android application id, at least two segments. */
56
57
  export const androidPackageNameSchema = z
57
58
  .string()
58
- .max(255)
59
+ .check(utf16MaxLength(255))
59
60
  .regex(/^[A-Za-z][A-Za-z0-9_]*(?:\.[A-Za-z][A-Za-z0-9_]*)+$/, 'Must be an Android package name');
60
61
  /** A signing certificate's SHA-256, 64 lowercase hex characters (keytool's digest without colons). */
61
62
  export const signingCertSha256Schema = z
@@ -66,7 +67,7 @@ export const appleTeamIdSchema = z.string().regex(/^[A-Z0-9]{10}$/, 'Must be an
66
67
  /** An Apple bundle id. */
67
68
  export const appleBundleIdSchema = z
68
69
  .string()
69
- .max(255)
70
+ .check(utf16MaxLength(255))
70
71
  .regex(/^[A-Za-z0-9-]+(?:\.[A-Za-z0-9-]+)+$/, 'Must be an Apple bundle id');
71
72
  const unique = (values) => new Set(values).size === values.length;
72
73
  export const applicationAndroidRecognitionSchema = z
@@ -100,7 +101,7 @@ export const applicationRecognitionWriteSchema = z
100
101
  export const applicationRecognitionSchema = applicationRecognitionWriteSchema
101
102
  .extend({
102
103
  applicationId: applicationIdSchema,
103
- updatedAt: z.string().datetime().nullable(),
104
+ updatedAt: z.string().check(isoDateTime()).nullable(),
104
105
  })
105
106
  .strict();
106
107
  // ---------------------------------------------------------------------------
@@ -127,7 +128,7 @@ export const appAssertionChallengeResponseSchema = z
127
128
  .object({
128
129
  challenge: base64Url32Schema,
129
130
  requestHash: base64Url32Schema,
130
- expiresAt: z.string().datetime(),
131
+ expiresAt: z.string().check(isoDateTime()),
131
132
  cloudProjectNumber: z
132
133
  .string()
133
134
  .regex(/^[0-9]{1,20}$/)
@@ -161,7 +162,7 @@ export const appAssertionRequestSchema = z.discriminatedUnion('platform', [
161
162
  proof: z
162
163
  .object({
163
164
  challenge: base64Url32Schema,
164
- integrityToken: z.string().min(1).max(16384),
165
+ integrityToken: z.string().check(utf16MinLength(1)).check(utf16MaxLength(16384)),
165
166
  })
166
167
  .strict(),
167
168
  })
@@ -186,6 +187,6 @@ export const appAssertionResponseSchema = z
186
187
  assertion: z.string().regex(/^[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+$/),
187
188
  applicationId: z.string().regex(/^\S{1,255}$/),
188
189
  platform: appAssertionPlatformSchema,
189
- expiresAt: z.string().datetime(),
190
+ expiresAt: z.string().check(isoDateTime()),
190
191
  })
191
192
  .strict();
@@ -1,3 +1,5 @@
1
+ import { integerCheck } from './numberChecks.js';
2
+ import { utf16MaxLength, utf16MinLength } from './stringChecks.js';
1
3
  /**
2
4
  * Application roles — the wire contract for permissions an APPLICATION declares
3
5
  * about its own users, and for the grants that give them to Oxy users.
@@ -68,22 +70,22 @@ export function isApplicationPermissionKey(value) {
68
70
  }
69
71
  export const applicationPermissionKeySchema = z
70
72
  .string()
71
- .max(APPLICATION_PERMISSION_KEY_MAX_LENGTH)
73
+ .check(utf16MaxLength(APPLICATION_PERMISSION_KEY_MAX_LENGTH))
72
74
  .regex(APPLICATION_PERMISSION_KEY_PATTERN, 'A permission key is 2-4 dot-separated lowercase segments, e.g. payments.operate');
73
75
  /** Plain text: no control characters other than a newline or a tab. */
74
76
  function plainText(max) {
75
77
  return z
76
78
  .string()
77
79
  .trim()
78
- .min(1)
79
- .max(max)
80
+ .check(utf16MinLength(1))
81
+ .check(utf16MaxLength(max))
80
82
  .refine((value) => Array.from(value).every((character) => {
81
83
  const code = character.charCodeAt(0);
82
84
  return (code >= 32 && code !== 127) || character === '\n' || character === '\t';
83
85
  }), 'Must be plain text');
84
86
  }
85
- const id = z.string().min(1).max(128);
86
- const isoTimestamp = z.string().min(1);
87
+ const id = z.string().check(utf16MinLength(1)).check(utf16MaxLength(128));
88
+ const isoTimestamp = z.string().check(utf16MinLength(1));
87
89
  const reasonSchema = plainText(APPLICATION_ROLE_REASON_MAX_LENGTH);
88
90
  /** One key as the application's owners declare it. */
89
91
  export const applicationPermissionDeclarationSchema = z
@@ -140,7 +142,7 @@ export const declareApplicationPermissionsResponseSchema = applicationPermission
140
142
  /** Live keys whose description changed. */
141
143
  described: z.array(applicationPermissionKeySchema),
142
144
  /** Live grants revoked because their key was retired. */
143
- revokedGrants: z.number().int().nonnegative(),
145
+ revokedGrants: z.number().check(integerCheck()).nonnegative(),
144
146
  });
145
147
  /** One grant of one key to one Oxy user. Revocation is a stamp, never a delete. */
146
148
  export const applicationRoleGrantSchema = z.object({
@@ -166,7 +168,7 @@ export const applicationRoleGrantListSchema = z.object({
166
168
  export const createApplicationRoleGrantRequestSchema = z
167
169
  .object({
168
170
  userId: id.optional(),
169
- username: z.string().trim().min(1).max(64).optional(),
171
+ username: z.string().trim().check(utf16MinLength(1)).check(utf16MaxLength(64)).optional(),
170
172
  permission: applicationPermissionKeySchema,
171
173
  reason: reasonSchema.optional(),
172
174
  })
@@ -190,8 +192,13 @@ export const listApplicationRoleGrantsQuerySchema = z
190
192
  .enum(['true', 'false'])
191
193
  .transform((value) => value === 'true')
192
194
  .optional(),
193
- limit: z.coerce.number().int().min(1).max(APPLICATION_ROLE_GRANTS_PAGE_MAX).optional(),
194
- cursor: z.string().min(1).max(512).optional(),
195
+ limit: z.coerce
196
+ .number()
197
+ .check(integerCheck())
198
+ .min(1)
199
+ .max(APPLICATION_ROLE_GRANTS_PAGE_MAX)
200
+ .optional(),
201
+ cursor: z.string().check(utf16MinLength(1)).check(utf16MaxLength(512)).optional(),
195
202
  })
196
203
  .strict();
197
204
  /**