@oxy.so/contracts 4.11.0-oxy-one.0 → 4.11.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 (98) hide show
  1. package/dist/cjs/.tsbuildinfo +1 -1
  2. package/dist/cjs/accountGraph.js +5 -3
  3. package/dist/cjs/agency.js +178 -96
  4. package/dist/cjs/agentKeys.js +80 -26
  5. package/dist/cjs/capabilityBindings.js +2 -2
  6. package/dist/cjs/capabilityInvocation.js +3 -1
  7. package/dist/cjs/commonsSignIn.js +2 -2
  8. package/dist/cjs/deviceSession.js +5 -1
  9. package/dist/cjs/email/messages.js +70 -4
  10. package/dist/cjs/emailAgentContext.js +16 -8
  11. package/dist/cjs/externalIdentity.js +30 -12
  12. package/dist/cjs/identity.js +14 -6
  13. package/dist/cjs/identityLink.js +7 -2
  14. package/dist/cjs/identityProof.js +2 -1
  15. package/dist/cjs/index.js +5 -3
  16. package/dist/cjs/inference/catalogue.js +2 -12
  17. package/dist/cjs/inference/decisions.js +102 -83
  18. package/dist/cjs/inference/economics.js +15 -5
  19. package/dist/cjs/inference/embeddings.js +44 -6
  20. package/dist/cjs/inference/inbox.js +33 -2
  21. package/dist/cjs/inference/providerConnection.js +21 -6
  22. package/dist/cjs/inference/realtime.js +114 -107
  23. package/dist/cjs/inference/scopedExecution.js +12 -12
  24. package/dist/cjs/inference/usage.js +2 -9
  25. package/dist/cjs/notifications.js +25 -5
  26. package/dist/cjs/oauth.js +30 -14
  27. package/dist/cjs/oxyRecordTypes.js +2 -2
  28. package/dist/cjs/products/access.js +146 -57
  29. package/dist/cjs/products/billing.js +71 -17
  30. package/dist/cjs/products/checkout.js +24 -6
  31. package/dist/cjs/products/plans.js +22 -7
  32. package/dist/cjs/recommendations.js +4 -6
  33. package/dist/cjs/reputation.js +3 -6
  34. package/dist/cjs/sessionStatus.js +1 -6
  35. package/dist/cjs/signIn.js +17 -4
  36. package/dist/cjs/transparency.js +3 -1
  37. package/dist/cjs/updates.js +2 -4
  38. package/dist/cjs/userResponse.js +27 -7
  39. package/dist/cjs/username.js +3 -1
  40. package/dist/esm/.tsbuildinfo +1 -1
  41. package/dist/esm/accountGraph.js +5 -3
  42. package/dist/esm/agency.js +178 -96
  43. package/dist/esm/agentKeys.js +80 -26
  44. package/dist/esm/capabilityBindings.js +2 -2
  45. package/dist/esm/capabilityInvocation.js +3 -1
  46. package/dist/esm/commonsSignIn.js +2 -2
  47. package/dist/esm/deviceSession.js +5 -1
  48. package/dist/esm/email/messages.js +69 -3
  49. package/dist/esm/emailAgentContext.js +16 -8
  50. package/dist/esm/externalIdentity.js +30 -12
  51. package/dist/esm/identity.js +14 -6
  52. package/dist/esm/identityLink.js +7 -2
  53. package/dist/esm/identityProof.js +2 -1
  54. package/dist/esm/index.js +7 -7
  55. package/dist/esm/inference/aliaModelRelease.js +1 -1
  56. package/dist/esm/inference/catalogue.js +3 -13
  57. package/dist/esm/inference/decisions.js +108 -89
  58. package/dist/esm/inference/economics.js +16 -6
  59. package/dist/esm/inference/embeddings.js +44 -6
  60. package/dist/esm/inference/inbox.js +32 -1
  61. package/dist/esm/inference/providerConnection.js +21 -6
  62. package/dist/esm/inference/realtime.js +123 -116
  63. package/dist/esm/inference/scopedExecution.js +15 -15
  64. package/dist/esm/inference/usage.js +2 -9
  65. package/dist/esm/notifications.js +25 -5
  66. package/dist/esm/oauth.js +30 -14
  67. package/dist/esm/oxyRecordTypes.js +2 -2
  68. package/dist/esm/products/access.js +146 -57
  69. package/dist/esm/products/billing.js +71 -17
  70. package/dist/esm/products/checkout.js +24 -6
  71. package/dist/esm/products/plans.js +22 -7
  72. package/dist/esm/recommendations.js +4 -6
  73. package/dist/esm/reputation.js +3 -6
  74. package/dist/esm/sessionStatus.js +1 -6
  75. package/dist/esm/signIn.js +17 -4
  76. package/dist/esm/transparency.js +3 -1
  77. package/dist/esm/updates.js +2 -4
  78. package/dist/esm/userResponse.js +27 -7
  79. package/dist/esm/username.js +3 -1
  80. package/dist/types/.tsbuildinfo +1 -1
  81. package/dist/types/accountGraph.d.ts +1 -1
  82. package/dist/types/commonsSignIn.d.ts +2 -2
  83. package/dist/types/email/messages.d.ts +208 -2
  84. package/dist/types/identity.d.ts +1 -1
  85. package/dist/types/index.d.ts +8 -8
  86. package/dist/types/inference/decisions.d.ts +1 -1
  87. package/dist/types/inference/inbox.d.ts +129 -5
  88. package/dist/types/inference/realtime.d.ts +1 -1
  89. package/dist/types/inference/scopedExecution.d.ts +1 -1
  90. package/dist/types/moderationReputation.d.ts +1 -1
  91. package/dist/types/oxyRecordTypes.d.ts +2 -2
  92. package/dist/types/products/access.d.ts +102 -102
  93. package/dist/types/products/checkout.d.ts +3 -3
  94. package/dist/types/products/plans.d.ts +40 -40
  95. package/dist/types/reputation.d.ts +4 -4
  96. package/dist/types/updates.d.ts +1 -1
  97. package/dist/types/userResponse.d.ts +22 -23
  98. package/package.json +1 -2
@@ -1,37 +1,31 @@
1
- import { z } from "zod";
2
- import { inferenceErrorSchema } from "./errors.js";
3
- import { modelReferenceSchema, requestIdSchema } from "./identifiers.js";
4
- import { usageQuantitySchema } from "./money.js";
5
- import { routingPolicyReferenceSchema } from "./routingPolicy.js";
6
- import { normalizedUsageReportSchema } from "./usage.js";
1
+ import { z } from 'zod';
2
+ import { inferenceErrorSchema } from './errors.js';
3
+ import { modelReferenceSchema, requestIdSchema } from './identifiers.js';
4
+ import { usageQuantitySchema } from './money.js';
5
+ import { routingPolicyReferenceSchema } from './routingPolicy.js';
6
+ import { normalizedUsageReportSchema } from './usage.js';
7
7
  const probability = z.number().finite().min(0).max(1);
8
8
  const text = z.string().min(1).max(65536);
9
9
  const id = z.string().min(1).max(128);
10
10
  const tolerance = 1e-6;
11
- export const decisionEffortSchema = z.enum([
12
- "instant",
13
- "low",
14
- "medium",
15
- "high",
16
- "xhigh",
17
- ]);
11
+ export const decisionEffortSchema = z.enum(['instant', 'low', 'medium', 'high', 'xhigh']);
18
12
  const common = { id, question: text, criteria: text.optional() };
19
- export const decisionQuestionSchema = z.discriminatedUnion("kind", [
13
+ export const decisionQuestionSchema = z.discriminatedUnion('kind', [
20
14
  z
21
15
  .object({
22
16
  ...common,
23
- kind: z.literal("choice"),
17
+ kind: z.literal('choice'),
24
18
  options: z.array(text).min(2).max(255),
25
19
  })
26
20
  .strict(),
27
21
  z
28
22
  .object({
29
23
  ...common,
30
- kind: z.literal("score"),
24
+ kind: z.literal('score'),
31
25
  levels: z.array(text).min(2).max(10),
32
26
  })
33
27
  .strict(),
34
- z.object({ ...common, kind: z.literal("noul") }).strict(),
28
+ z.object({ ...common, kind: z.literal('noul') }).strict(),
35
29
  ]);
36
30
  const payloadFields = {
37
31
  state: z.string().max(65536),
@@ -47,23 +41,38 @@ const payloadFields = {
47
41
  * Kaana must also check its final serialized body before sending it.
48
42
  */
49
43
  export function decisionInputBudget(payload) {
50
- const bytes = (value) => new TextEncoder().encode(JSON.stringify(value).replace(/[<>&\u2028\u2029]/g, (char) => `\\u${char.charCodeAt(0).toString(16).padStart(4, "0")}`)).length;
51
- const model = "x".repeat(255);
44
+ const bytes = (value) => new TextEncoder().encode(JSON.stringify(value).replace(/[<>&\u2028\u2029]/g, (char) => `\\u${char.charCodeAt(0).toString(16).padStart(4, '0')}`)).length;
45
+ const model = 'x'.repeat(255);
52
46
  const measure = (questions) => {
53
- const wireQuestions = Object.fromEntries(questions.map((q) => [q.id, {
47
+ const wireQuestions = Object.fromEntries(questions.map((q) => [
48
+ q.id,
49
+ {
54
50
  type: q.kind,
55
51
  instructions: {
56
52
  question: q.question,
57
53
  ...(payload.instructions === undefined ? {} : { instructions: payload.instructions }),
58
54
  ...(q.criteria === undefined ? {} : { criteria: q.criteria }),
59
55
  },
60
- ...(q.kind === "choice" ? { criteria: Object.fromEntries(q.options.map((label) => [label, null])) } :
61
- q.kind === "score" ? { criteria: q.levels } : {}),
62
- }]));
63
- return Math.max(bytes({ ...payload, model, questions }), bytes({ model, state: payload.state, questions: wireQuestions, ...(payload.effort === undefined ? {} : { effort: payload.effort }) }));
56
+ ...(q.kind === 'choice'
57
+ ? { criteria: Object.fromEntries(q.options.map((label) => [label, null])) }
58
+ : q.kind === 'score'
59
+ ? { criteria: q.levels }
60
+ : {}),
61
+ },
62
+ ]));
63
+ return Math.max(bytes({ ...payload, model, questions }), bytes({
64
+ model,
65
+ state: payload.state,
66
+ questions: wireQuestions,
67
+ ...(payload.effort === undefined ? {} : { effort: payload.effort }),
68
+ }));
64
69
  };
65
70
  const total = measure(payload.questions);
66
- return { total, context: Math.max(...payload.questions.map((q) => measure([q]))), gateway: total + 4096 };
71
+ return {
72
+ total,
73
+ context: Math.max(...payload.questions.map((q) => measure([q]))),
74
+ gateway: total + 4096,
75
+ };
67
76
  }
68
77
  /** OpenRouter's TOTAL limit is separate from direct state-plus-longest context. */
69
78
  export function decisionFitsGateway(payload) {
@@ -86,18 +95,18 @@ function hasUnpairedSurrogate(value) {
86
95
  }
87
96
  function validateInput(payload, ctx) {
88
97
  const fields = [
89
- { value: payload.state, path: ["state"] },
90
- { value: payload.instructions, path: ["instructions"] },
98
+ { value: payload.state, path: ['state'] },
99
+ { value: payload.instructions, path: ['instructions'] },
91
100
  ];
92
101
  for (const [index, question] of payload.questions.entries()) {
93
- for (const field of ["id", "question", "criteria"]) {
94
- fields.push({ value: question[field], path: ["questions", index, field] });
102
+ for (const field of ['id', 'question', 'criteria']) {
103
+ fields.push({ value: question[field], path: ['questions', index, field] });
95
104
  }
96
- if (question.kind === "choice" || question.kind === "score") {
97
- const field = question.kind === "choice" ? "options" : "levels";
98
- const labels = question.kind === "choice" ? question.options : question.levels;
105
+ if (question.kind === 'choice' || question.kind === 'score') {
106
+ const field = question.kind === 'choice' ? 'options' : 'levels';
107
+ const labels = question.kind === 'choice' ? question.options : question.levels;
99
108
  for (const [labelIndex, value] of labels.entries()) {
100
- fields.push({ value, path: ["questions", index, field, labelIndex] });
109
+ fields.push({ value, path: ['questions', index, field, labelIndex] });
101
110
  }
102
111
  }
103
112
  }
@@ -105,57 +114,57 @@ function validateInput(payload, ctx) {
105
114
  for (const { value, path } of fields) {
106
115
  if (value !== undefined && hasUnpairedSurrogate(value)) {
107
116
  invalidUnicode = true;
108
- ctx.addIssue({ code: "custom", path, message: "Decisions require paired UTF-16 surrogates." });
117
+ ctx.addIssue({
118
+ code: 'custom',
119
+ path,
120
+ message: 'Decisions require paired UTF-16 surrogates.',
121
+ });
109
122
  }
110
123
  }
111
124
  // Reject before measuring/reserving text that the execution runtime would change.
112
125
  if (invalidUnicode)
113
126
  return;
114
- if (new Set(payload.questions.map((q) => q.id)).size !==
115
- payload.questions.length)
127
+ if (new Set(payload.questions.map((q) => q.id)).size !== payload.questions.length)
116
128
  ctx.addIssue({
117
- code: "custom",
118
- path: ["questions"],
119
- message: "Question IDs must be unique.",
129
+ code: 'custom',
130
+ path: ['questions'],
131
+ message: 'Question IDs must be unique.',
120
132
  });
121
133
  for (const [index, question] of payload.questions.entries()) {
122
- const labels = question.kind === "choice"
134
+ const labels = question.kind === 'choice'
123
135
  ? question.options
124
- : question.kind === "score"
136
+ : question.kind === 'score'
125
137
  ? question.levels
126
138
  : [];
127
139
  if (new Set(labels).size !== labels.length)
128
140
  ctx.addIssue({
129
- code: "custom",
130
- path: ["questions", index],
131
- message: "Options and levels must be unique.",
141
+ code: 'custom',
142
+ path: ['questions', index],
143
+ message: 'Options and levels must be unique.',
132
144
  });
133
145
  }
134
146
  const budget = decisionInputBudget(payload);
135
147
  if (budget.total > 64000 || budget.context > 32000)
136
148
  ctx.addIssue({
137
- code: "custom",
138
- path: ["state"],
139
- message: "Decisions exceed the serialized 64000-byte total or 32000-byte per-question context budget.",
149
+ code: 'custom',
150
+ path: ['state'],
151
+ message: 'Decisions exceed the serialized 64000-byte total or 32000-byte per-question context budget.',
140
152
  });
141
153
  }
142
- export const decisionInputSchema = z
143
- .object(payloadFields)
144
- .strict()
145
- .superRefine(validateInput);
154
+ export const decisionInputSchema = z.object(payloadFields).strict().superRefine(validateInput);
146
155
  export const decisionRequestSchema = z
147
156
  .object({
148
- model: modelReferenceSchema.refine((model) => model.includes("@"), "Decisions require a revision-pinned model."),
157
+ model: modelReferenceSchema.refine((model) => model.includes('@'), 'Decisions require a revision-pinned model.'),
149
158
  ...payloadFields,
150
159
  })
151
160
  .strict()
152
161
  .superRefine(validateInput);
153
162
  export const decisionAnswerSchema = z
154
- .discriminatedUnion("kind", [
163
+ .discriminatedUnion('kind', [
155
164
  z
156
165
  .object({
157
166
  id,
158
- kind: z.literal("choice"),
167
+ kind: z.literal('choice'),
159
168
  /** Actual provider-selected option. Never reconstructed from probabilities. */
160
169
  reply: text,
161
170
  /** Provider-returned confidence, not a correctness probability. */
@@ -166,7 +175,7 @@ export const decisionAnswerSchema = z
166
175
  z
167
176
  .object({
168
177
  id,
169
- kind: z.literal("score"),
178
+ kind: z.literal('score'),
170
179
  /** Actual provider score. Kept separate from the validated expected index. */
171
180
  reply: z.number().finite().min(0).max(9),
172
181
  confidence: probability,
@@ -174,42 +183,45 @@ export const decisionAnswerSchema = z
174
183
  distribution: z.array(probability).min(2).max(10),
175
184
  })
176
185
  .strict(),
177
- z.object({ id, kind: z.literal("noul"), probability }).strict(),
186
+ z.object({ id, kind: z.literal('noul'), probability }).strict(),
178
187
  ])
179
188
  .superRefine((answer, ctx) => {
180
- if (answer.kind === "noul")
189
+ if (answer.kind === 'noul')
181
190
  return;
182
- if (answer.kind === "score" && Math.abs(answer.reply - answer.mean) > tolerance) {
183
- ctx.addIssue({ code: "custom", path: ["reply"], message: "Provider score must match the expected level index." });
191
+ if (answer.kind === 'score' && Math.abs(answer.reply - answer.mean) > tolerance) {
192
+ ctx.addIssue({
193
+ code: 'custom',
194
+ path: ['reply'],
195
+ message: 'Provider score must match the expected level index.',
196
+ });
184
197
  }
185
- const distribution = answer.kind === "choice" ? answer.probabilities : answer.distribution;
186
- if (Math.abs(distribution.reduce((sum, value) => sum + value, 0) - 1) >
187
- tolerance)
198
+ const distribution = answer.kind === 'choice' ? answer.probabilities : answer.distribution;
199
+ if (Math.abs(distribution.reduce((sum, value) => sum + value, 0) - 1) > tolerance)
188
200
  ctx.addIssue({
189
- code: "custom",
190
- message: "Probabilities must sum to one.",
201
+ code: 'custom',
202
+ message: 'Probabilities must sum to one.',
191
203
  });
192
- if (answer.kind === "score" &&
193
- Math.abs(distribution.reduce((sum, value, index) => sum + index * value, 0) -
194
- answer.mean) > tolerance)
204
+ if (answer.kind === 'score' &&
205
+ Math.abs(distribution.reduce((sum, value, index) => sum + index * value, 0) - answer.mean) >
206
+ tolerance)
195
207
  ctx.addIssue({
196
- code: "custom",
197
- path: ["mean"],
198
- message: "Mean must equal the expected zero-based level index.",
208
+ code: 'custom',
209
+ path: ['mean'],
210
+ message: 'Mean must equal the expected zero-based level index.',
199
211
  });
200
212
  });
201
213
  const resultFields = {
202
214
  schemaVersion: z.literal(1),
203
215
  requestId: requestIdSchema,
204
- model: modelReferenceSchema.refine((model) => model.includes("@"), "Decisions require an immutable model revision."),
216
+ model: modelReferenceSchema.refine((model) => model.includes('@'), 'Decisions require an immutable model revision.'),
205
217
  data: z.array(decisionAnswerSchema).min(1).max(255),
206
218
  };
207
219
  function uniqueAnswers(result, ctx) {
208
220
  if (new Set(result.data.map((answer) => answer.id)).size !== result.data.length)
209
221
  ctx.addIssue({
210
- code: "custom",
211
- path: ["data"],
212
- message: "Answer IDs must be unique.",
222
+ code: 'custom',
223
+ path: ['data'],
224
+ message: 'Answer IDs must be unique.',
213
225
  });
214
226
  }
215
227
  export const decisionResultSchema = z
@@ -219,11 +231,11 @@ export const decisionResultSchema = z
219
231
  .superRefine((result, ctx) => {
220
232
  if (result.usage.requestId !== result.requestId ||
221
233
  result.usage.resolvedModelReference !== result.model ||
222
- result.usage.outcome !== "completed") {
234
+ result.usage.outcome !== 'completed') {
223
235
  ctx.addIssue({
224
- code: "custom",
225
- path: ["usage"],
226
- message: "Decision usage must describe this completed request and immutable model.",
236
+ code: 'custom',
237
+ path: ['usage'],
238
+ message: 'Decision usage must describe this completed request and immutable model.',
227
239
  });
228
240
  }
229
241
  });
@@ -242,11 +254,19 @@ export const decisionFailureSchema = z
242
254
  .strict()
243
255
  .superRefine((failure, ctx) => {
244
256
  if (failure.error.requestId !== failure.requestId) {
245
- ctx.addIssue({ code: "custom", path: ["error", "requestId"], message: "The error must answer this request." });
257
+ ctx.addIssue({
258
+ code: 'custom',
259
+ path: ['error', 'requestId'],
260
+ message: 'The error must answer this request.',
261
+ });
246
262
  }
247
263
  if (failure.usage !== undefined &&
248
- (failure.usage.requestId !== failure.requestId || failure.usage.outcome === "completed")) {
249
- ctx.addIssue({ code: "custom", path: ["usage"], message: "Failure usage must describe this request and an incomplete outcome." });
264
+ (failure.usage.requestId !== failure.requestId || failure.usage.outcome === 'completed')) {
265
+ ctx.addIssue({
266
+ code: 'custom',
267
+ path: ['usage'],
268
+ message: 'Failure usage must describe this request and an incomplete outcome.',
269
+ });
250
270
  }
251
271
  });
252
272
  export const decisionSuccessSchema = z
@@ -264,17 +284,16 @@ export function decisionAnswersMatch(input, answers) {
264
284
  return false;
265
285
  return input.questions.every((question) => {
266
286
  const answer = answers.find((candidate) => candidate.id === question.id);
267
- if (!answer ||
268
- !decisionAnswerSchema.safeParse(answer).success ||
269
- answer.kind !== question.kind)
287
+ if (!answer || !decisionAnswerSchema.safeParse(answer).success || answer.kind !== question.kind)
270
288
  return false;
271
- if (question.kind === "choice" && answer.kind === "choice") {
289
+ if (question.kind === 'choice' && answer.kind === 'choice') {
272
290
  const index = question.options.indexOf(answer.reply);
273
- return question.options.length === answer.probabilities.length && index >= 0 &&
274
- answer.probabilities[index] + tolerance >= Math.max(...answer.probabilities);
291
+ return (question.options.length === answer.probabilities.length &&
292
+ index >= 0 &&
293
+ answer.probabilities[index] + tolerance >= Math.max(...answer.probabilities));
275
294
  }
276
- if (question.kind === "score" && answer.kind === "score")
295
+ if (question.kind === 'score' && answer.kind === 'score')
277
296
  return question.levels.length === answer.distribution.length;
278
- return question.kind === "noul";
297
+ return question.kind === 'noul';
279
298
  });
280
299
  }
@@ -28,7 +28,7 @@
28
28
  */
29
29
  import { z } from 'zod';
30
30
  import { costCenterSchema } from './entitlement.js';
31
- import { currencyCodeSchema, exactDecimalSchema, usageSourceSchema, usageQuantitySchema } from './money.js';
31
+ import { currencyCodeSchema, exactDecimalSchema, usageSourceSchema, usageQuantitySchema, } from './money.js';
32
32
  import { inferenceEnvironmentSchema, modelReferenceSchema } from './identifiers.js';
33
33
  import { inferenceRequestOutcomeSchema } from './usage.js';
34
34
  /** How a request is treated economically. The first entry is the default. */
@@ -104,7 +104,8 @@ export const costCenterUsageSchema = z
104
104
  })
105
105
  .strict();
106
106
  /** A technical generation record for an internal request, never a financial receipt. */
107
- export const meteredGenerationSchema = z.object({
107
+ export const meteredGenerationSchema = z
108
+ .object({
108
109
  schemaVersion: z.literal(2),
109
110
  kind: z.literal('metered_usage'),
110
111
  meteredUsageId: z.string().min(1),
@@ -123,10 +124,19 @@ export const meteredGenerationSchema = z.object({
123
124
  resolvedModelReference: modelReferenceSchema,
124
125
  servingProvider: z.string().min(1),
125
126
  tariff: z.discriminatedUnion('status', [
126
- z.object({ status: z.literal('quoted'), amount: exactDecimalSchema, currency: currencyCodeSchema,
127
- priceVersionId: z.string().min(1) }).strict(),
128
- z.object({ status: z.literal('unpriced'), priceVersionId: z.string().min(1).nullable() }).strict(),
127
+ z
128
+ .object({
129
+ status: z.literal('quoted'),
130
+ amount: exactDecimalSchema,
131
+ currency: currencyCodeSchema,
132
+ priceVersionId: z.string().min(1),
133
+ })
134
+ .strict(),
135
+ z
136
+ .object({ status: z.literal('unpriced'), priceVersionId: z.string().min(1).nullable() })
137
+ .strict(),
129
138
  ]),
130
139
  customerCharge: z.object({ status: z.literal('not_charged') }).strict(),
131
140
  settledAt: z.string().datetime(),
132
- }).strict();
141
+ })
142
+ .strict();
@@ -1,16 +1,54 @@
1
1
  import { z } from 'zod';
2
2
  import { inferenceErrorSchema } from './errors.js';
3
- export const embeddingVectorSchema = z.object({ index: z.number().int().nonnegative(), embedding: z.array(z.number().finite()).min(1).max(1024) }).strict();
4
- export const embeddingUsageSchema = z.object({ inputTokens: z.number().int().nonnegative(), totalTokens: z.number().int().nonnegative() }).strict().refine((usage) => usage.totalTokens >= usage.inputTokens, { message: 'totalTokens must be greater than or equal to inputTokens', path: ['totalTokens'] });
5
- export const embeddingSuccessSchema = z.object({ schemaVersion: z.literal(1), requestId: z.string().min(1).max(128), model: z.string().min(1).max(255), dimension: z.number().int().positive().max(1024), data: z.array(embeddingVectorSchema).min(1).max(2048), usage: embeddingUsageSchema }).strict().superRefine((result, context) => {
3
+ export const embeddingVectorSchema = z
4
+ .object({
5
+ index: z.number().int().nonnegative(),
6
+ embedding: z.array(z.number().finite()).min(1).max(1024),
7
+ })
8
+ .strict();
9
+ export const embeddingUsageSchema = z
10
+ .object({
11
+ inputTokens: z.number().int().nonnegative(),
12
+ totalTokens: z.number().int().nonnegative(),
13
+ })
14
+ .strict()
15
+ .refine((usage) => usage.totalTokens >= usage.inputTokens, {
16
+ message: 'totalTokens must be greater than or equal to inputTokens',
17
+ path: ['totalTokens'],
18
+ });
19
+ export const embeddingSuccessSchema = z
20
+ .object({
21
+ schemaVersion: z.literal(1),
22
+ requestId: z.string().min(1).max(128),
23
+ model: z.string().min(1).max(255),
24
+ dimension: z.number().int().positive().max(1024),
25
+ data: z.array(embeddingVectorSchema).min(1).max(2048),
26
+ usage: embeddingUsageSchema,
27
+ })
28
+ .strict()
29
+ .superRefine((result, context) => {
6
30
  const indexes = new Set();
7
31
  for (const [position, vector] of result.data.entries()) {
8
32
  if (vector.embedding.length !== result.dimension)
9
- context.addIssue({ code: z.ZodIssueCode.custom, path: ['data', position, 'embedding'], message: 'embedding length must equal dimension' });
33
+ context.addIssue({
34
+ code: z.ZodIssueCode.custom,
35
+ path: ['data', position, 'embedding'],
36
+ message: 'embedding length must equal dimension',
37
+ });
10
38
  if (indexes.has(vector.index))
11
- context.addIssue({ code: z.ZodIssueCode.custom, path: ['data', position, 'index'], message: 'embedding indexes must be unique' });
39
+ context.addIssue({
40
+ code: z.ZodIssueCode.custom,
41
+ path: ['data', position, 'index'],
42
+ message: 'embedding indexes must be unique',
43
+ });
12
44
  indexes.add(vector.index);
13
45
  }
14
46
  });
15
- export const embeddingFailureSchema = z.object({ schemaVersion: z.literal(1), requestId: z.string().min(1).max(128), error: inferenceErrorSchema }).strict();
47
+ export const embeddingFailureSchema = z
48
+ .object({
49
+ schemaVersion: z.literal(1),
50
+ requestId: z.string().min(1).max(128),
51
+ error: inferenceErrorSchema,
52
+ })
53
+ .strict();
16
54
  export const embeddingResponseSchema = z.union([embeddingSuccessSchema, embeddingFailureSchema]);
@@ -37,7 +37,8 @@ export const inboxComposeRequestSchema = z.discriminatedUnion('operation', [
37
37
  export const inboxDailyBriefRequestSchema = z.object({
38
38
  startAt: inboxUtcTimestampSchema,
39
39
  endAt: inboxUtcTimestampSchema,
40
- stream: z.boolean().optional(),
40
+ /** BCP 47 tag of the language the brief is written in; English when absent. */
41
+ locale: z.string().regex(/^[A-Za-z]{2,3}(?:-[A-Za-z0-9]{2,8})*$/).max(35).optional(),
41
42
  }).strict().superRefine((value, context) => {
42
43
  const durationMs = Date.parse(value.endAt) - Date.parse(value.startAt);
43
44
  if (!Number.isFinite(durationMs) || durationMs <= 0) {
@@ -79,6 +80,36 @@ export const inboxNaturalSearchResponseSchema = z.object({
79
80
  }).strict(),
80
81
  interpretation: z.string().max(1000),
81
82
  }).strict();
83
+ /** Where the brief puts a message: it asks something of the owner, it is today's news, or it is still unread from before. */
84
+ export const INBOX_DAILY_BRIEF_SECTIONS = ['needs_you', 'today', 'earlier'];
85
+ /**
86
+ * The Daily Brief as data, so a client draws it rather than printing a wall of
87
+ * text: a short summary, then the messages it mentions — each with the
88
+ * server's own copy of its sender, subject, time and unread state, so a client
89
+ * can show and open it, and a one-line note of why it matters.
90
+ */
91
+ export const inboxDailyBriefResponseSchema = z.object({
92
+ schemaVersion: z.literal(1),
93
+ requestId: z.string().min(1).max(128),
94
+ generationId: z.string().min(1).max(128).optional(),
95
+ summary: z.string().max(400),
96
+ counts: z.object({
97
+ received: z.number().int().nonnegative(),
98
+ unread: z.number().int().nonnegative(),
99
+ starred: z.number().int().nonnegative(),
100
+ earlierUnread: z.number().int().nonnegative(),
101
+ }).strict(),
102
+ items: z.array(z.object({
103
+ messageId: inboxMessageIdSchema,
104
+ section: z.enum(INBOX_DAILY_BRIEF_SECTIONS),
105
+ note: z.string().max(200),
106
+ from: z.object({ name: z.string().max(998).nullable(), address: z.string().max(320) }).strict(),
107
+ subject: z.string().max(998),
108
+ receivedAt: z.string().datetime(),
109
+ unread: z.boolean(),
110
+ hasAttachments: z.boolean(),
111
+ }).strict()).max(20),
112
+ }).strict();
82
113
  export const inboxSmartRepliesResponseSchema = z.object({
83
114
  replies: z.array(z.string().trim().min(1).max(500)).max(3),
84
115
  }).strict();
@@ -92,8 +92,7 @@ function isVisibleASCIIProviderCredential(value) {
92
92
  return false;
93
93
  const finalQuartet = offset + 4 === value.length;
94
94
  if (finalQuartet &&
95
- ((padding === 2 && (second & 0x0f) !== 0) ||
96
- (padding === 1 && (third & 0x03) !== 0))) {
95
+ ((padding === 2 && (second & 0x0f) !== 0) || (padding === 1 && (third & 0x03) !== 0))) {
97
96
  return false;
98
97
  }
99
98
  const packed = (first << 18) | (second << 12) | (third << 6) | fourth;
@@ -131,7 +130,11 @@ export const kaanaCredentialRotateMutationSchema = kaanaCredentialIdentitySchema
131
130
  operationId: kaanaCredentialOperationIdSchema,
132
131
  operationActor: kaanaCredentialOperationActorSchema,
133
132
  credentialHandle: kaanaCredentialHandleSchema,
134
- expectedRevision: z.number().int().positive().max(Number.MAX_SAFE_INTEGER - 1),
133
+ expectedRevision: z
134
+ .number()
135
+ .int()
136
+ .positive()
137
+ .max(Number.MAX_SAFE_INTEGER - 1),
135
138
  secretBase64: kaanaCredentialSecretBase64Schema,
136
139
  })
137
140
  .strict();
@@ -142,7 +145,11 @@ export const kaanaCredentialRevokeMutationSchema = kaanaCredentialIdentitySchema
142
145
  operationId: kaanaCredentialOperationIdSchema,
143
146
  operationActor: kaanaCredentialOperationActorSchema,
144
147
  credentialHandle: kaanaCredentialHandleSchema,
145
- expectedRevision: z.number().int().positive().max(Number.MAX_SAFE_INTEGER - 1),
148
+ expectedRevision: z
149
+ .number()
150
+ .int()
151
+ .positive()
152
+ .max(Number.MAX_SAFE_INTEGER - 1),
146
153
  })
147
154
  .strict();
148
155
  export const kaanaCredentialMutationSchema = z.discriminatedUnion('action', [
@@ -163,7 +170,11 @@ export const kaanaCredentialRotateOutcomeRequestSchema = kaanaCredentialIdentity
163
170
  action: z.literal('rotate'),
164
171
  operationId: kaanaCredentialOperationIdSchema,
165
172
  credentialHandle: kaanaCredentialHandleSchema,
166
- expectedRevision: z.number().int().positive().max(Number.MAX_SAFE_INTEGER - 1),
173
+ expectedRevision: z
174
+ .number()
175
+ .int()
176
+ .positive()
177
+ .max(Number.MAX_SAFE_INTEGER - 1),
167
178
  })
168
179
  .strict();
169
180
  export const kaanaCredentialRevokeOutcomeRequestSchema = kaanaCredentialIdentitySchema
@@ -172,7 +183,11 @@ export const kaanaCredentialRevokeOutcomeRequestSchema = kaanaCredentialIdentity
172
183
  action: z.literal('revoke'),
173
184
  operationId: kaanaCredentialOperationIdSchema,
174
185
  credentialHandle: kaanaCredentialHandleSchema,
175
- expectedRevision: z.number().int().positive().max(Number.MAX_SAFE_INTEGER - 1),
186
+ expectedRevision: z
187
+ .number()
188
+ .int()
189
+ .positive()
190
+ .max(Number.MAX_SAFE_INTEGER - 1),
176
191
  })
177
192
  .strict();
178
193
  export const kaanaCredentialOutcomeRequestSchema = z.discriminatedUnion('action', [