@mossbear/protocol 0.1.0-alpha.100

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 (143) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +7 -0
  3. package/dist/agentGuidancePaths.d.ts +101 -0
  4. package/dist/agentGuidancePaths.d.ts.map +1 -0
  5. package/dist/agentGuidancePaths.js +185 -0
  6. package/dist/agentGuidancePaths.js.map +1 -0
  7. package/dist/agentGuidancePaths.test.d.ts +2 -0
  8. package/dist/agentGuidancePaths.test.d.ts.map +1 -0
  9. package/dist/agentGuidancePaths.test.js +91 -0
  10. package/dist/agentGuidancePaths.test.js.map +1 -0
  11. package/dist/aliasPaths.d.ts +100 -0
  12. package/dist/aliasPaths.d.ts.map +1 -0
  13. package/dist/aliasPaths.js +148 -0
  14. package/dist/aliasPaths.js.map +1 -0
  15. package/dist/aliasPaths.test.d.ts +2 -0
  16. package/dist/aliasPaths.test.d.ts.map +1 -0
  17. package/dist/aliasPaths.test.js +80 -0
  18. package/dist/aliasPaths.test.js.map +1 -0
  19. package/dist/artifact.test.d.ts +2 -0
  20. package/dist/artifact.test.d.ts.map +1 -0
  21. package/dist/artifact.test.js +374 -0
  22. package/dist/artifact.test.js.map +1 -0
  23. package/dist/bundleSlug.d.ts +177 -0
  24. package/dist/bundleSlug.d.ts.map +1 -0
  25. package/dist/bundleSlug.js +233 -0
  26. package/dist/bundleSlug.js.map +1 -0
  27. package/dist/bundleSlug.test.d.ts +2 -0
  28. package/dist/bundleSlug.test.d.ts.map +1 -0
  29. package/dist/bundleSlug.test.js +197 -0
  30. package/dist/bundleSlug.test.js.map +1 -0
  31. package/dist/commentAnchor.d.ts +34 -0
  32. package/dist/commentAnchor.d.ts.map +1 -0
  33. package/dist/commentAnchor.js +122 -0
  34. package/dist/commentAnchor.js.map +1 -0
  35. package/dist/commentAnchor.test.d.ts +2 -0
  36. package/dist/commentAnchor.test.d.ts.map +1 -0
  37. package/dist/commentAnchor.test.js +48 -0
  38. package/dist/commentAnchor.test.js.map +1 -0
  39. package/dist/contextKinds.d.ts +165 -0
  40. package/dist/contextKinds.d.ts.map +1 -0
  41. package/dist/contextKinds.js +148 -0
  42. package/dist/contextKinds.js.map +1 -0
  43. package/dist/contextKinds.test.d.ts +2 -0
  44. package/dist/contextKinds.test.d.ts.map +1 -0
  45. package/dist/contextKinds.test.js +137 -0
  46. package/dist/contextKinds.test.js.map +1 -0
  47. package/dist/frameDocument.d.ts +71 -0
  48. package/dist/frameDocument.d.ts.map +1 -0
  49. package/dist/frameDocument.js +140 -0
  50. package/dist/frameDocument.js.map +1 -0
  51. package/dist/frameDocument.test.d.ts +2 -0
  52. package/dist/frameDocument.test.d.ts.map +1 -0
  53. package/dist/frameDocument.test.js +84 -0
  54. package/dist/frameDocument.test.js.map +1 -0
  55. package/dist/frameProtocol.d.ts +11 -0
  56. package/dist/frameProtocol.d.ts.map +1 -0
  57. package/dist/frameProtocol.js +11 -0
  58. package/dist/frameProtocol.js.map +1 -0
  59. package/dist/index.d.ts +24 -0
  60. package/dist/index.d.ts.map +1 -0
  61. package/dist/index.js +24 -0
  62. package/dist/index.js.map +1 -0
  63. package/dist/limits.d.ts +19 -0
  64. package/dist/limits.d.ts.map +1 -0
  65. package/dist/limits.js +19 -0
  66. package/dist/limits.js.map +1 -0
  67. package/dist/markdownSections.d.ts +58 -0
  68. package/dist/markdownSections.d.ts.map +1 -0
  69. package/dist/markdownSections.js +102 -0
  70. package/dist/markdownSections.js.map +1 -0
  71. package/dist/markdownSections.test.d.ts +2 -0
  72. package/dist/markdownSections.test.d.ts.map +1 -0
  73. package/dist/markdownSections.test.js +95 -0
  74. package/dist/markdownSections.test.js.map +1 -0
  75. package/dist/pairing.d.ts +183 -0
  76. package/dist/pairing.d.ts.map +1 -0
  77. package/dist/pairing.js +175 -0
  78. package/dist/pairing.js.map +1 -0
  79. package/dist/pairing.test.d.ts +2 -0
  80. package/dist/pairing.test.d.ts.map +1 -0
  81. package/dist/pairing.test.js +105 -0
  82. package/dist/pairing.test.js.map +1 -0
  83. package/dist/photos.d.ts +146 -0
  84. package/dist/photos.d.ts.map +1 -0
  85. package/dist/photos.js +127 -0
  86. package/dist/photos.js.map +1 -0
  87. package/dist/publicModelCatalog.d.ts +19 -0
  88. package/dist/publicModelCatalog.d.ts.map +1 -0
  89. package/dist/publicModelCatalog.generated.d.ts +2 -0
  90. package/dist/publicModelCatalog.generated.d.ts.map +1 -0
  91. package/dist/publicModelCatalog.generated.js +489 -0
  92. package/dist/publicModelCatalog.generated.js.map +1 -0
  93. package/dist/publicModelCatalog.js +68 -0
  94. package/dist/publicModelCatalog.js.map +1 -0
  95. package/dist/publicModelCatalog.test.d.ts +2 -0
  96. package/dist/publicModelCatalog.test.d.ts.map +1 -0
  97. package/dist/publicModelCatalog.test.js +88 -0
  98. package/dist/publicModelCatalog.test.js.map +1 -0
  99. package/dist/publicModelNativeAliases.d.ts +5 -0
  100. package/dist/publicModelNativeAliases.d.ts.map +1 -0
  101. package/dist/publicModelNativeAliases.js +8 -0
  102. package/dist/publicModelNativeAliases.js.map +1 -0
  103. package/dist/schemas.d.ts +10745 -0
  104. package/dist/schemas.d.ts.map +1 -0
  105. package/dist/schemas.js +4572 -0
  106. package/dist/schemas.js.map +1 -0
  107. package/dist/schemas.test.d.ts +2 -0
  108. package/dist/schemas.test.d.ts.map +1 -0
  109. package/dist/schemas.test.js +1617 -0
  110. package/dist/schemas.test.js.map +1 -0
  111. package/dist/steeringOverTime.d.ts +30 -0
  112. package/dist/steeringOverTime.d.ts.map +1 -0
  113. package/dist/steeringOverTime.js +19 -0
  114. package/dist/steeringOverTime.js.map +1 -0
  115. package/dist/types.d.ts +109 -0
  116. package/dist/types.d.ts.map +1 -0
  117. package/dist/types.js +12 -0
  118. package/dist/types.js.map +1 -0
  119. package/dist/usageOnly.d.ts +190 -0
  120. package/dist/usageOnly.d.ts.map +1 -0
  121. package/dist/usageOnly.js +53 -0
  122. package/dist/usageOnly.js.map +1 -0
  123. package/dist/usageOnly.test.d.ts +2 -0
  124. package/dist/usageOnly.test.d.ts.map +1 -0
  125. package/dist/usageOnly.test.js +203 -0
  126. package/dist/usageOnly.test.js.map +1 -0
  127. package/dist/version.d.ts +47 -0
  128. package/dist/version.d.ts.map +1 -0
  129. package/dist/version.js +125 -0
  130. package/dist/version.js.map +1 -0
  131. package/dist/version.test.d.ts +2 -0
  132. package/dist/version.test.d.ts.map +1 -0
  133. package/dist/version.test.js +86 -0
  134. package/dist/version.test.js.map +1 -0
  135. package/dist/whatSyncs.d.ts +62 -0
  136. package/dist/whatSyncs.d.ts.map +1 -0
  137. package/dist/whatSyncs.js +228 -0
  138. package/dist/whatSyncs.js.map +1 -0
  139. package/dist/whatSyncs.test.d.ts +2 -0
  140. package/dist/whatSyncs.test.d.ts.map +1 -0
  141. package/dist/whatSyncs.test.js +113 -0
  142. package/dist/whatSyncs.test.js.map +1 -0
  143. package/package.json +52 -0
@@ -0,0 +1,175 @@
1
+ /**
2
+ * Device-pairing transport contract — `mossbear login`.
3
+ *
4
+ * Shape is RFC 8628 (OAuth 2.0 Device Authorization Grant): the CLI asks for a
5
+ * pairing, gets back a long secret it keeps (`deviceCode`) and a short one the
6
+ * human retypes in a browser (`userCode`), then polls until a signed-in user
7
+ * approves or denies it.
8
+ *
9
+ * The two codes are deliberately asymmetric, and the asymmetry is the whole
10
+ * security argument:
11
+ *
12
+ * - `deviceCode` is the *credential*. It never leaves the machine that asked
13
+ * for the pairing, so it is sized like a credential (256 bits) and the
14
+ * server stores only its hash.
15
+ * - `userCode` is *typed by a human*, so it is sized for the smallest thing a
16
+ * human will retype without resenting it — {@link PAIRING_CODE_LENGTH}
17
+ * characters of {@link PAIRING_CODE_ALPHABET}, which is 38.4 bits. That is
18
+ * well above RFC 8628 §5.1's 20-bit floor, but it is still small enough that
19
+ * entropy alone is not the control: a per-pairing attempt budget enforced in
20
+ * the database is (`~/server/pairing/` in the dashboard).
21
+ *
22
+ * This file is the one home for the code's shape because three callers need
23
+ * it and must agree: the server generates it, the `/pair` page accepts it
24
+ * typed back in any casing or spacing, and the CLI prints it.
25
+ */
26
+ import * as v from 'valibot';
27
+ /**
28
+ * Symbols a pairing code may contain.
29
+ *
30
+ * Twenty consonants and eight digits. Every vowel is out, and so is `Y` — a
31
+ * code with no vowel in it cannot spell a word a user then reports as
32
+ * offensive. `0`, `1` and `I` are out on top of that, being the characters
33
+ * people mis-transcribe when reading a code off one screen and typing it into
34
+ * another. (`O` and `U` are already gone as vowels; `L` stays, since the two
35
+ * things it is confusable with are both excluded.)
36
+ */
37
+ export const PAIRING_CODE_ALPHABET = 'BCDFGHJKLMNPQRSTVWXZ23456789';
38
+ /** Characters in a pairing code, excluding the display hyphen. */
39
+ export const PAIRING_CODE_LENGTH = 8;
40
+ /** Where the hyphen goes when a code is shown to a human: `XXXX-XXXX`. */
41
+ export const PAIRING_CODE_GROUP_SIZE = 4;
42
+ /**
43
+ * Strip a user's typing back to the canonical form the server stores.
44
+ *
45
+ * Accepts what people actually type when copying a code off another screen:
46
+ * lowercase, spaces, hyphens anywhere (not only where we put one). Returns the
47
+ * uppercase, separator-free string — **which may still not be a valid code**;
48
+ * callers pair this with {@link isWellFormedUserCode} rather than trusting it.
49
+ */
50
+ export function normalizeUserCode(input) {
51
+ return input.replace(/[\s-]+/g, '').toUpperCase();
52
+ }
53
+ /**
54
+ * Insert the display hyphen: `7X2QBM4T` → `7X2Q-BM4T`.
55
+ *
56
+ * Input is normalized first, so this is safe to call on a code that has
57
+ * already been formatted (it will not accumulate hyphens).
58
+ */
59
+ export function formatUserCode(code) {
60
+ const normalized = normalizeUserCode(code);
61
+ const groups = [];
62
+ for (let i = 0; i < normalized.length; i += PAIRING_CODE_GROUP_SIZE) {
63
+ groups.push(normalized.slice(i, i + PAIRING_CODE_GROUP_SIZE));
64
+ }
65
+ return groups.join('-');
66
+ }
67
+ /**
68
+ * Whether a normalized code could have been generated by this server.
69
+ *
70
+ * A cheap shape check, not an authorization one — it exists so a typo costs a
71
+ * validation message rather than a database round trip and an attempt off the
72
+ * pairing's budget.
73
+ */
74
+ export function isWellFormedUserCode(code) {
75
+ if (code.length !== PAIRING_CODE_LENGTH)
76
+ return false;
77
+ for (const char of code) {
78
+ if (!PAIRING_CODE_ALPHABET.includes(char))
79
+ return false;
80
+ }
81
+ return true;
82
+ }
83
+ /**
84
+ * A pairing code as it arrives from a client. Normalized then shape-checked,
85
+ * so every consumer downstream of a parse holds the canonical form.
86
+ */
87
+ export const UserCodeSchema = v.pipe(v.string(), v.transform(normalizeUserCode), v.check(isWellFormedUserCode, 'not a pairing code'));
88
+ export const PairInitiateRequestSchema = v.object({
89
+ /**
90
+ * What the user will see on the approval page — a hostname, typically.
91
+ * Untrusted display text: the page renders it as text, never as markup.
92
+ */
93
+ deviceName: v.optional(v.pipe(v.string(), v.trim(), v.maxLength(64))),
94
+ cliVersion: v.optional(v.pipe(v.string(), v.trim(), v.maxLength(32))),
95
+ });
96
+ export const PairInitiateResponseSchema = v.object({
97
+ /** The CLI's secret. Sent once, never returned by any other endpoint. */
98
+ deviceCode: v.pipe(v.string(), v.minLength(1)),
99
+ /** Hyphenated for display — the CLI prints this verbatim. */
100
+ userCode: v.pipe(v.string(), v.minLength(1)),
101
+ verificationUri: v.pipe(v.string(), v.minLength(1)),
102
+ /** `verificationUri` with the code prefilled, for a clickable terminal link. */
103
+ verificationUriComplete: v.pipe(v.string(), v.minLength(1)),
104
+ /** Seconds until the pairing expires. */
105
+ expiresIn: v.pipe(v.number(), v.integer(), v.minValue(1)),
106
+ /** Seconds the CLI must wait between polls (RFC 8628 §3.2 `interval`). */
107
+ interval: v.pipe(v.number(), v.integer(), v.minValue(1)),
108
+ });
109
+ export const PairPollRequestSchema = v.object({
110
+ deviceCode: v.pipe(v.string(), v.minLength(1), v.maxLength(256)),
111
+ });
112
+ /**
113
+ * Poll outcomes.
114
+ *
115
+ * A variant rather than an HTTP status code per outcome: `denied` and
116
+ * `expired` are *protocol answers*, not transport failures, and the CLI has to
117
+ * tell them apart to say something useful. Transport failures stay transport
118
+ * failures — an unparseable body is 400, an unknown device code is 404, and
119
+ * polling faster than `interval` is 429.
120
+ */
121
+ export const PairPollResponseSchema = v.variant('status', [
122
+ v.object({
123
+ status: v.literal('pending'),
124
+ interval: v.pipe(v.number(), v.integer(), v.minValue(1)),
125
+ }),
126
+ v.object({
127
+ status: v.literal('complete'),
128
+ /**
129
+ * The CLI token, delivered exactly once. A second poll of the same
130
+ * pairing gets `expired`, because the pairing is consumed by this one.
131
+ */
132
+ token: v.pipe(v.string(), v.minLength(1)),
133
+ /** Who approved it, so the CLI can say "Paired as …". */
134
+ email: v.nullable(v.string()),
135
+ }),
136
+ v.object({ status: v.literal('denied') }),
137
+ v.object({ status: v.literal('expired') }),
138
+ ]);
139
+ /** What the `/pair` page shows before asking the user to decide. */
140
+ export const PairLookupResponseSchema = v.object({
141
+ userCode: v.pipe(v.string(), v.minLength(1)),
142
+ deviceName: v.nullable(v.string()),
143
+ cliVersion: v.nullable(v.string()),
144
+ /** ISO 8601. The page counts down against it. */
145
+ expiresAt: v.pipe(v.string(), v.minLength(1)),
146
+ });
147
+ export const PairDecisionRequestSchema = v.object({
148
+ userCode: UserCodeSchema,
149
+ decision: v.picklist(['approve', 'deny']),
150
+ });
151
+ export const PairDecisionResponseSchema = v.object({
152
+ status: v.picklist(['approved', 'denied']),
153
+ });
154
+ export function parsePairInitiateRequest(data) {
155
+ return v.parse(PairInitiateRequestSchema, data);
156
+ }
157
+ export function parsePairInitiateResponse(data) {
158
+ return v.parse(PairInitiateResponseSchema, data);
159
+ }
160
+ export function parsePairPollRequest(data) {
161
+ return v.parse(PairPollRequestSchema, data);
162
+ }
163
+ export function parsePairPollResponse(data) {
164
+ return v.parse(PairPollResponseSchema, data);
165
+ }
166
+ export function parsePairLookupResponse(data) {
167
+ return v.parse(PairLookupResponseSchema, data);
168
+ }
169
+ export function parsePairDecisionRequest(data) {
170
+ return v.parse(PairDecisionRequestSchema, data);
171
+ }
172
+ export function parsePairDecisionResponse(data) {
173
+ return v.parse(PairDecisionResponseSchema, data);
174
+ }
175
+ //# sourceMappingURL=pairing.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pairing.js","sourceRoot":"","sources":["../src/pairing.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,OAAO,KAAK,CAAC,MAAM,SAAS,CAAA;AAE5B;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,8BAA8B,CAAA;AAEnE,kEAAkE;AAClE,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,CAAA;AAEpC,0EAA0E;AAC1E,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,CAAA;AAExC;;;;;;;GAOG;AACH,MAAM,UAAU,iBAAiB,CAAC,KAAa;IAC7C,OAAO,KAAK,CAAC,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC,WAAW,EAAE,CAAA;AACnD,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,cAAc,CAAC,IAAY;IACzC,MAAM,UAAU,GAAG,iBAAiB,CAAC,IAAI,CAAC,CAAA;IAC1C,MAAM,MAAM,GAAa,EAAE,CAAA;IAC3B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,UAAU,CAAC,MAAM,EAAE,CAAC,IAAI,uBAAuB,EAAE,CAAC;QACpE,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,GAAG,uBAAuB,CAAC,CAAC,CAAA;IAC/D,CAAC;IACD,OAAO,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;AACzB,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,oBAAoB,CAAC,IAAY;IAC/C,IAAI,IAAI,CAAC,MAAM,KAAK,mBAAmB;QAAE,OAAO,KAAK,CAAA;IACrD,KAAK,MAAM,IAAI,IAAI,IAAI,EAA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AC,CAAC,KAAK,CAAC,yBAAyB,EAAE,IAAI,CAAC,CAAA;AACjD,CAAC;AAED,MAAM,UAAU,yBAAyB,CAAC,IAAa;IACrD,OAAO,CAAC,CAAC,KAAK,CAAC,0BAA0B,EAAE,IAAI,CAAC,CAAA;AAClD,CAAC;AAED,MAAM,UAAU,oBAAoB,CAAC,IAAa;IAChD,OAAO,CAAC,CAAC,KAAK,CAAC,qBAAqB,EAAE,IAAI,CAAC,CAAA;AAC7C,CAAC;AAED,MAAM,UAAU,qBAAqB,CAAC,IAAa;IACjD,OAAO,CAAC,CAAC,KAAK,CAAC,sBAAsB,EAAE,IAAI,CAAC,CAAA;AAC9C,CAAC;AAED,MAAM,UAAU,uBAAuB,CAAC,IAAa;IACnD,OAAO,CAAC,CAAC,KAAK,CAAC,wBAAwB,EAAE,IAAI,CAAC,CAAA;AAChD,CAAC;AAED,MAAM,UAAU,wBAAwB,CAAC,IAAa;IACpD,OAAO,CAAC,CAAC,KAAK,CAAC,yBAAyB,EAAE,IAAI,CAAC,CAAA;AACjD,CAAC;AAED,MAAM,UAAU,yBAAyB,CAAC,IAAa;IACrD,OAAO,CAAC,CAAC,KAAK,CAAC,0BAA0B,EAAE,IAAI,CAAC,CAAA;AAClD,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=pairing.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pairing.test.d.ts","sourceRoot":"","sources":["../src/pairing.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,105 @@
1
+ import * as v from 'valibot';
2
+ import { describe, expect, it } from 'vitest';
3
+ import { PAIRING_CODE_ALPHABET, PAIRING_CODE_LENGTH, PairDecisionRequestSchema, PairInitiateRequestSchema, PairPollResponseSchema, UserCodeSchema, formatUserCode, isWellFormedUserCode, normalizeUserCode, } from './pairing.js';
4
+ describe('pairing code alphabet', () => {
5
+ it('contains no vowels, so a generated code cannot spell a word', () => {
6
+ for (const vowel of 'AEIOU') {
7
+ expect(PAIRING_CODE_ALPHABET).not.toContain(vowel);
8
+ }
9
+ });
10
+ it('omits every character pair people mis-transcribe', () => {
11
+ // `L` stays: it is only confusable with `1` and `I`, and both are gone.
12
+ for (const ambiguous of '01IO') {
13
+ expect(PAIRING_CODE_ALPHABET).not.toContain(ambiguous);
14
+ }
15
+ });
16
+ it('carries more entropy than RFC 8628 §5.1 asks for', () => {
17
+ const bits = Math.log2(PAIRING_CODE_ALPHABET.length ** PAIRING_CODE_LENGTH);
18
+ expect(bits).toBeGreaterThan(20);
19
+ });
20
+ it('repeats no symbol, so every code is equally likely', () => {
21
+ expect(new Set(PAIRING_CODE_ALPHABET).size).toBe(PAIRING_CODE_ALPHABET.length);
22
+ });
23
+ });
24
+ describe('a code typed back by a human', () => {
25
+ it('is accepted lowercase', () => {
26
+ expect(normalizeUserCode('7x2qbm4t')).toBe('7X2QBM4T');
27
+ });
28
+ it('is accepted with the hyphen we printed', () => {
29
+ expect(normalizeUserCode('7X2Q-BM4T')).toBe('7X2QBM4T');
30
+ });
31
+ it('is accepted with spaces or hyphens the user added anywhere', () => {
32
+ expect(normalizeUserCode(' 7x2 q-b m4t ')).toBe('7X2QBM4T');
33
+ });
34
+ });
35
+ describe('formatUserCode', () => {
36
+ it('groups a code for display', () => {
37
+ expect(formatUserCode('7X2QBM4T')).toBe('7X2Q-BM4T');
38
+ });
39
+ it('does not accumulate hyphens when called on its own output', () => {
40
+ expect(formatUserCode(formatUserCode('7X2QBM4T'))).toBe('7X2Q-BM4T');
41
+ });
42
+ });
43
+ describe('isWellFormedUserCode', () => {
44
+ it('accepts a code of the right length drawn from the alphabet', () => {
45
+ expect(isWellFormedUserCode('7X2QBM4T')).toBe(true);
46
+ });
47
+ it('rejects a code containing a symbol the generator never emits', () => {
48
+ // `A` is a vowel, so no generated code can contain one.
49
+ expect(isWellFormedUserCode('AX2QBM4T')).toBe(false);
50
+ });
51
+ it('rejects a code of the wrong length', () => {
52
+ expect(isWellFormedUserCode('7X2QBM4')).toBe(false);
53
+ expect(isWellFormedUserCode('7X2QBM4TT')).toBe(false);
54
+ });
55
+ });
56
+ describe('UserCodeSchema', () => {
57
+ it('hands the canonical form to whatever parses it', () => {
58
+ expect(v.parse(UserCodeSchema, '7x2q-bm4t')).toBe('7X2QBM4T');
59
+ });
60
+ it('refuses a code that could not have been generated', () => {
61
+ expect(() => v.parse(UserCodeSchema, 'AAAAAAAA')).toThrow();
62
+ });
63
+ it('refuses the empty string rather than normalizing it to one', () => {
64
+ expect(() => v.parse(UserCodeSchema, '')).toThrow();
65
+ });
66
+ });
67
+ describe('PairInitiateRequestSchema', () => {
68
+ it('accepts a request with no device name at all', () => {
69
+ expect(v.parse(PairInitiateRequestSchema, {})).toEqual({});
70
+ });
71
+ it('bounds the device name, which is rendered on the approval page', () => {
72
+ expect(() => v.parse(PairInitiateRequestSchema, { deviceName: 'x'.repeat(65) })).toThrow();
73
+ });
74
+ });
75
+ describe('PairDecisionRequestSchema', () => {
76
+ it('normalizes the code the page submits', () => {
77
+ expect(v.parse(PairDecisionRequestSchema, { userCode: '7x2q-bm4t', decision: 'deny' })).toEqual({ userCode: '7X2QBM4T', decision: 'deny' });
78
+ });
79
+ it('refuses a decision that is neither approve nor deny', () => {
80
+ expect(() => v.parse(PairDecisionRequestSchema, { userCode: '7X2QBM4T', decision: 'maybe' })).toThrow();
81
+ });
82
+ });
83
+ describe('PairPollResponseSchema', () => {
84
+ it('parses each outcome the CLI has to tell apart', () => {
85
+ expect(v.parse(PairPollResponseSchema, { status: 'pending', interval: 5 }).status).toBe('pending');
86
+ expect(v.parse(PairPollResponseSchema, { status: 'denied' }).status).toBe('denied');
87
+ expect(v.parse(PairPollResponseSchema, { status: 'expired' }).status).toBe('expired');
88
+ });
89
+ it('carries the token only on the completing poll', () => {
90
+ const parsed = v.parse(PairPollResponseSchema, {
91
+ status: 'complete',
92
+ token: 'mossbear_abc',
93
+ email: 'someone@example.com',
94
+ });
95
+ expect(parsed).toEqual({
96
+ status: 'complete',
97
+ token: 'mossbear_abc',
98
+ email: 'someone@example.com',
99
+ });
100
+ });
101
+ it('refuses a completion with no token, which would look like success', () => {
102
+ expect(() => v.parse(PairPollResponseSchema, { status: 'complete', email: null })).toThrow();
103
+ });
104
+ });
105
+ //# sourceMappingURL=pairing.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pairing.test.js","sourceRoot":"","sources":["../src/pairing.test.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,SAAS,CAAA;AAC5B,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAA;AAE7C,OAAO,EACL,qBAAqB,EACrB,mBAAmB,EACnB,yBAAyB,EACzB,yBAAyB,EACzB,sBAAsB,EACtB,cAAc,EACd,cAAc,EACd,oBAAoB,EACpB,iBAAiB,GAClB,MAAM,cAAc,CAAA;AAErB,QAAQ,CAAC,uBAAuB,EAAE,GAAG,EAAE;IACrC,EAAE,CAAC,6DAA6D,EAAE,GAAG,EAAE;QACrE,KAAK,MAAM,KAAK,IAAI,OAAO,EAAE,CAAC;YAC5B,MAAM,CAAC,qBAAqB,CAAC,CAAC,GAAG,CAAC,SAAS,CAAC,KAAK,CAAC,CAAA;QACpD,CAAC;IACH,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,kDAAkD,EAAE,GAAG,EAAE;QAC1D,wEAAwE;QACxE,KAAK,MAAM,SAAS,IAAI,MAAM,EAAE,CAAC;YAC/B,MAAM,CAAC,qBAAqB,CAAC,CAAC,GAAG,CAAC,SAAS,CAAC,SAAS,CAAC,CAAA;QACxD,CAAC;IACH,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,kDAAkD,EAAE,GAAG,EAAE;QAC1D,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,qBAAqB,CAAC,MAAM,IAAI,mBAAmB,CAAC,CAAA;QAC3E,MAAM,CAAC,IAAI,CAAC,CAAC,eAAe,CAAC,EAAE,CAAC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CAAC,EAAE,CAAC,CAAC,MAAM,CAC3E,CAAC,IAAI,CAAC,SAAS,CAAC,CAAA;QACjB,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,sBAAsB,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;QACnF,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,sBAAsB,EAAE,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAA;IACvF,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,+CAA+C,EAAE,GAAG,EAAE;QACvD,MAAM,MAAM,GAAG,CAAC,CAAC,KAAK,CAAC,sBAAsB,EAAE;YAC7C,MAAM,EAAE,UAAU;YAClB,KAAK,EAAE,cAAc;YACrB,KAAK,EAAE,qBAAqB;SAC7B,CAAC,CAAA;QACF,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC;YACrB,MAAM,EAAE,UAAU;YAClB,KAAK,EAAE,cAAc;YACrB,KAAK,EAAE,qBAAqB;SAC7B,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,mEAAmE,EAAE,GAAG,EAAE;QAC3E,MAAM,CAAC,GAAG,EAAE,CACV,CAAC,CAAC,KAAK,CAAC,sBAAsB,EAAE,EAAE,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CACrE,CAAC,OAAO,EAAE,CAAA;IACb,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
@@ -0,0 +1,146 @@
1
+ /**
2
+ * The wire contract for photo capture: the three parts a captured photo is
3
+ * uploaded as, their limits, and the media description an item carries.
4
+ *
5
+ * A photo is one item stored as three blobs. `original` is the file exactly as
6
+ * the picker handed it over — never re-encoded, so it keeps whatever metadata
7
+ * it arrived with. `display` (≤3072px on the long edge) and `thumb` (≤512px)
8
+ * are re-encoded by the client and must carry no metadata at all; the server
9
+ * checks their bytes and refuses one that does. An item never substitutes the
10
+ * original for a missing variant, which is why all three parts are required.
11
+ *
12
+ * Imports nothing but valibot, so `schemas.ts` can depend on it without a
13
+ * cycle.
14
+ */
15
+ import * as v from 'valibot';
16
+ export declare const PHOTO_ROLES: readonly ["original", "display", "thumb"];
17
+ export type PhotoRole = (typeof PHOTO_ROLES)[number];
18
+ export declare const PhotoRoleSchema: v.PicklistSchema<readonly ["original", "display", "thumb"], undefined>;
19
+ /** Every format any part may be; which ones a role admits is {@link PHOTO_PART_LIMITS}. */
20
+ export declare const PHOTO_MEDIA_TYPES: readonly ["image/jpeg", "image/png", "image/webp", "image/gif", "image/heic", "image/heif"];
21
+ export type PhotoMediaType = (typeof PHOTO_MEDIA_TYPES)[number];
22
+ /** Formats a re-encoded variant may use: ones every browser renders. */
23
+ export declare const PHOTO_VARIANT_MEDIA_TYPES: readonly ["image/jpeg", "image/png", "image/webp"];
24
+ type PartLimit = {
25
+ maxBytes: number;
26
+ mediaTypes: readonly PhotoMediaType[];
27
+ /** Longest encoded edge, in pixels. */
28
+ maxEdge: number | null;
29
+ /** Encoded width × height. */
30
+ maxPixels: number;
31
+ };
32
+ /**
33
+ * Per-part limits. The byte caps bound one upload request each; the pixel caps
34
+ * bound what a reader is asked to decode. A 48-megapixel phone JPEG is about
35
+ * 12–20 MiB, so the original's cap leaves room without admitting RAW.
36
+ */
37
+ export declare const PHOTO_PART_LIMITS: Record<PhotoRole, PartLimit>;
38
+ /** What an item records about one part — checked against the bytes at upload. */
39
+ export declare const PhotoPartMediaSchema: v.ObjectSchema<{
40
+ readonly role: v.PicklistSchema<readonly ["original", "display", "thumb"], undefined>;
41
+ readonly mediaType: v.PicklistSchema<readonly ["image/jpeg", "image/png", "image/webp", "image/gif", "image/heic", "image/heif"], undefined>;
42
+ readonly bytes: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.SafeIntegerAction<number, undefined>, v.MinValueAction<number, 1, undefined>]>;
43
+ readonly width: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.SafeIntegerAction<number, undefined>, v.MinValueAction<number, 1, undefined>]>;
44
+ readonly height: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.SafeIntegerAction<number, undefined>, v.MinValueAction<number, 1, undefined>]>;
45
+ }, undefined>;
46
+ export type PhotoPartMedia = v.InferOutput<typeof PhotoPartMediaSchema>;
47
+ /** Why a declared part falls outside its role's limits, or `null` when it fits. */
48
+ export declare function photoPartLimitRefusal(part: PhotoPartMedia): string | null;
49
+ /** One declared part of a photo upload: its media plus the hash of its bytes. */
50
+ export declare const PhotoUploadPartSchema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
51
+ readonly sha256: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, undefined>]>;
52
+ readonly role: v.PicklistSchema<readonly ["original", "display", "thumb"], undefined>;
53
+ readonly mediaType: v.PicklistSchema<readonly ["image/jpeg", "image/png", "image/webp", "image/gif", "image/heic", "image/heif"], undefined>;
54
+ readonly bytes: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.SafeIntegerAction<number, undefined>, v.MinValueAction<number, 1, undefined>]>;
55
+ readonly width: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.SafeIntegerAction<number, undefined>, v.MinValueAction<number, 1, undefined>]>;
56
+ readonly height: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.SafeIntegerAction<number, undefined>, v.MinValueAction<number, 1, undefined>]>;
57
+ }, undefined>, v.CheckAction<{
58
+ sha256: string;
59
+ role: "original" | "display" | "thumb";
60
+ mediaType: "image/jpeg" | "image/png" | "image/webp" | "image/gif" | "image/heic" | "image/heif";
61
+ bytes: number;
62
+ width: number;
63
+ height: number;
64
+ }, "Part is outside its limits">]>;
65
+ export type PhotoUploadPart = v.InferOutput<typeof PhotoUploadPartSchema>;
66
+ /**
67
+ * `POST /api/v1/artifacts/captures/photos` — begin a photo upload.
68
+ *
69
+ * The idempotency key names this capture across retries: a begin replayed
70
+ * under it, with the same parts, resumes the same attempt or returns the item
71
+ * it already became. Different parts under a used key are refused.
72
+ */
73
+ export declare const BeginPhotoUploadRequestSchema: v.ObjectSchema<{
74
+ readonly idempotencyKey: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, undefined>]>;
75
+ readonly parts: v.SchemaWithPipe<readonly [v.ArraySchema<v.SchemaWithPipe<readonly [v.ObjectSchema<{
76
+ readonly sha256: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, undefined>]>;
77
+ readonly role: v.PicklistSchema<readonly ["original", "display", "thumb"], undefined>;
78
+ readonly mediaType: v.PicklistSchema<readonly ["image/jpeg", "image/png", "image/webp", "image/gif", "image/heic", "image/heif"], undefined>;
79
+ readonly bytes: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.SafeIntegerAction<number, undefined>, v.MinValueAction<number, 1, undefined>]>;
80
+ readonly width: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.SafeIntegerAction<number, undefined>, v.MinValueAction<number, 1, undefined>]>;
81
+ readonly height: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.SafeIntegerAction<number, undefined>, v.MinValueAction<number, 1, undefined>]>;
82
+ }, undefined>, v.CheckAction<{
83
+ sha256: string;
84
+ role: "original" | "display" | "thumb";
85
+ mediaType: "image/jpeg" | "image/png" | "image/webp" | "image/gif" | "image/heic" | "image/heif";
86
+ bytes: number;
87
+ width: number;
88
+ height: number;
89
+ }, "Part is outside its limits">]>, undefined>, v.LengthAction<{
90
+ sha256: string;
91
+ role: "original" | "display" | "thumb";
92
+ mediaType: "image/jpeg" | "image/png" | "image/webp" | "image/gif" | "image/heic" | "image/heif";
93
+ bytes: number;
94
+ width: number;
95
+ height: number;
96
+ }[], 3, undefined>, v.CheckAction<{
97
+ sha256: string;
98
+ role: "original" | "display" | "thumb";
99
+ mediaType: "image/jpeg" | "image/png" | "image/webp" | "image/gif" | "image/heic" | "image/heif";
100
+ bytes: number;
101
+ width: number;
102
+ height: number;
103
+ }[], "A photo needs an original, a display and a thumb part">]>;
104
+ }, undefined>;
105
+ export type BeginPhotoUploadRequest = v.InferInput<typeof BeginPhotoUploadRequestSchema>;
106
+ /**
107
+ * `POST /api/v1/artifacts/captures/photos/uploads/<attemptId>/commit` — publish the
108
+ * photo once every part has arrived. The name is the client's, typically the
109
+ * picked file's: the server writes no fallback name of its own into the row.
110
+ */
111
+ export declare const CommitPhotoUploadRequestSchema: v.ObjectSchema<{
112
+ readonly name: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TrimAction, v.MinLengthAction<string, 1, undefined>, v.MaxLengthAction<string, 200, undefined>]>;
113
+ /** Where it was captured from, as a text capture's `source` says; `app` when omitted. */
114
+ readonly source: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>, v.MaxLengthAction<string, 64, undefined>]>, undefined>;
115
+ }, undefined>;
116
+ export type CommitPhotoUploadRequest = v.InferInput<typeof CommitPhotoUploadRequestSchema>;
117
+ /**
118
+ * The media description an item carries when it is a photo: one entry per
119
+ * stored part, so a list can lay out a thumbnail and a viewer can size the
120
+ * display variant without fetching either.
121
+ */
122
+ export declare const PhotoAssetSchema: v.ObjectSchema<{
123
+ readonly parts: v.ArraySchema<v.ObjectSchema<{
124
+ readonly role: v.PicklistSchema<readonly ["original", "display", "thumb"], undefined>;
125
+ readonly mediaType: v.PicklistSchema<readonly ["image/jpeg", "image/png", "image/webp", "image/gif", "image/heic", "image/heif"], undefined>;
126
+ readonly bytes: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.SafeIntegerAction<number, undefined>, v.MinValueAction<number, 1, undefined>]>;
127
+ readonly width: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.SafeIntegerAction<number, undefined>, v.MinValueAction<number, 1, undefined>]>;
128
+ readonly height: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.SafeIntegerAction<number, undefined>, v.MinValueAction<number, 1, undefined>]>;
129
+ }, undefined>, undefined>;
130
+ }, undefined>;
131
+ export type PhotoAsset = v.InferOutput<typeof PhotoAssetSchema>;
132
+ /**
133
+ * `GET /api/v1/artifacts/captures/photos/storage` — whether photo capture is
134
+ * available, and the caller's storage when the caller is the one who pays for
135
+ * it (null otherwise, and when unavailable).
136
+ */
137
+ export declare const PhotoStorageResponseSchema: v.ObjectSchema<{
138
+ readonly available: v.BooleanSchema<undefined>;
139
+ readonly usage: v.NullableSchema<v.ObjectSchema<{
140
+ readonly usedBytes: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.MinValueAction<number, 0, undefined>]>;
141
+ readonly capBytes: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.MinValueAction<number, 0, undefined>]>;
142
+ }, undefined>, undefined>;
143
+ }, undefined>;
144
+ export type PhotoStorageResponse = v.InferOutput<typeof PhotoStorageResponseSchema>;
145
+ export {};
146
+ //# sourceMappingURL=photos.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"photos.d.ts","sourceRoot":"","sources":["../src/photos.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,CAAC,MAAM,SAAS,CAAA;AAE5B,eAAO,MAAM,WAAW,2CAA4C,CAAA;AACpE,MAAM,MAAM,SAAS,GAAG,CAAC,OAAO,WAAW,CAAC,CAAC,MAAM,CAAC,CAAA;AACpD,eAAO,MAAM,eAAe,wEAA0B,CAAA;AAEtD,2FAA2F;AAC3F,eAAO,MAAM,iBAAiB,6FAOpB,CAAA;AACV,MAAM,MAAM,cAAc,GAAG,CAAC,OAAO,iBAAiB,CAAC,CAAC,MAAM,CAAC,CAAA;AAE/D,wEAAwE;AACxE,eAAO,MAAM,yBAAyB,oDAI5B,CAAA;AAEV,KAAK,SAAS,GAAG;IACf,QAAQ,EAAE,MAAM,CAAA;IAChB,UAAU,EAAE,SAA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os.js ADDED
@@ -0,0 +1,127 @@
1
+ /**
2
+ * The wire contract for photo capture: the three parts a captured photo is
3
+ * uploaded as, their limits, and the media description an item carries.
4
+ *
5
+ * A photo is one item stored as three blobs. `original` is the file exactly as
6
+ * the picker handed it over — never re-encoded, so it keeps whatever metadata
7
+ * it arrived with. `display` (≤3072px on the long edge) and `thumb` (≤512px)
8
+ * are re-encoded by the client and must carry no metadata at all; the server
9
+ * checks their bytes and refuses one that does. An item never substitutes the
10
+ * original for a missing variant, which is why all three parts are required.
11
+ *
12
+ * Imports nothing but valibot, so `schemas.ts` can depend on it without a
13
+ * cycle.
14
+ */
15
+ import * as v from 'valibot';
16
+ export const PHOTO_ROLES = ['original', 'display', 'thumb'];
17
+ export const PhotoRoleSchema = v.picklist(PHOTO_ROLES);
18
+ /** Every format any part may be; which ones a role admits is {@link PHOTO_PART_LIMITS}. */
19
+ export const PHOTO_MEDIA_TYPES = [
20
+ 'image/jpeg',
21
+ 'image/png',
22
+ 'image/webp',
23
+ 'image/gif',
24
+ 'image/heic',
25
+ 'image/heif',
26
+ ];
27
+ /** Formats a re-encoded variant may use: ones every browser renders. */
28
+ export const PHOTO_VARIANT_MEDIA_TYPES = [
29
+ 'image/jpeg',
30
+ 'image/png',
31
+ 'image/webp',
32
+ ];
33
+ const MiB = 1024 * 1024;
34
+ /**
35
+ * Per-part limits. The byte caps bound one upload request each; the pixel caps
36
+ * bound what a reader is asked to decode. A 48-megapixel phone JPEG is about
37
+ * 12–20 MiB, so the original's cap leaves room without admitting RAW.
38
+ */
39
+ export const PHOTO_PART_LIMITS = {
40
+ original: {
41
+ maxBytes: 25 * MiB,
42
+ mediaTypes: PHOTO_MEDIA_TYPES,
43
+ maxEdge: null,
44
+ maxPixels: 100_000_000,
45
+ },
46
+ display: {
47
+ maxBytes: 10 * MiB,
48
+ mediaTypes: PHOTO_VARIANT_MEDIA_TYPES,
49
+ maxEdge: 3072,
50
+ maxPixels: 3072 * 3072,
51
+ },
52
+ thumb: {
53
+ maxBytes: 1 * MiB,
54
+ mediaTypes: PHOTO_VARIANT_MEDIA_TYPES,
55
+ maxEdge: 512,
56
+ maxPixels: 512 * 512,
57
+ },
58
+ };
59
+ const PixelsSchema = v.pipe(v.number(), v.safeInteger(), v.minValue(1));
60
+ /** What an item records about one part — checked against the bytes at upload. */
61
+ export const PhotoPartMediaSchema = v.object({
62
+ role: PhotoRoleSchema,
63
+ mediaType: v.picklist(PHOTO_MEDIA_TYPES),
64
+ bytes: v.pipe(v.number(), v.safeInteger(), v.minValue(1)),
65
+ width: PixelsSchema,
66
+ height: PixelsSchema,
67
+ });
68
+ /** Why a declared part falls outside its role's limits, or `null` when it fits. */
69
+ export function photoPartLimitRefusal(part) {
70
+ const limit = PHOTO_PART_LIMITS[part.role];
71
+ if (part.bytes > limit.maxBytes)
72
+ return `The ${part.role} part can be at most ${limit.maxBytes} bytes`;
73
+ if (!limit.mediaTypes.includes(part.mediaType))
74
+ return `The ${part.role} part can't be ${part.mediaType}`;
75
+ if (limit.maxEdge !== null && Math.max(part.width, part.height) > limit.maxEdge)
76
+ return `The ${part.role} part can be at most ${limit.maxEdge} pixels on its long edge`;
77
+ if (part.width * part.height > limit.maxPixels)
78
+ return `The ${part.role} part has too many pixels`;
79
+ return null;
80
+ }
81
+ /** One declared part of a photo upload: its media plus the hash of its bytes. */
82
+ export const PhotoUploadPartSchema = v.pipe(v.object({
83
+ ...PhotoPartMediaSchema.entries,
84
+ sha256: v.pipe(v.string(), v.regex(/^[0-9a-f]{64}$/)),
85
+ }), v.check((part) => photoPartLimitRefusal(part) === null, 'Part is outside its limits'));
86
+ /**
87
+ * `POST /api/v1/artifacts/captures/photos` — begin a photo upload.
88
+ *
89
+ * The idempotency key names this capture across retries: a begin replayed
90
+ * under it, with the same parts, resumes the same attempt or returns the item
91
+ * it already became. Different parts under a used key are refused.
92
+ */
93
+ export const BeginPhotoUploadRequestSchema = v.object({
94
+ idempotencyKey: v.pipe(v.string(), v.regex(/^[A-Za-z0-9_-]{16,128}$/)),
95
+ parts: v.pipe(v.array(PhotoUploadPartSchema), v.length(PHOTO_ROLES.length), v.check((parts) => PHOTO_ROLES.every((role) => parts.some((part) => part.role === role)), 'A photo needs an original, a display and a thumb part')),
96
+ });
97
+ /**
98
+ * `POST /api/v1/artifacts/captures/photos/uploads/<attemptId>/commit` — publish the
99
+ * photo once every part has arrived. The name is the client's, typically the
100
+ * picked file's: the server writes no fallback name of its own into the row.
101
+ */
102
+ export const CommitPhotoUploadRequestSchema = v.object({
103
+ name: v.pipe(v.string(), v.trim(), v.minLength(1), v.maxLength(200)),
104
+ /** Where it was captured from, as a text capture's `source` says; `app` when omitted. */
105
+ source: v.optional(v.pipe(v.string(), v.minLength(1), v.maxLength(64))),
106
+ });
107
+ /**
108
+ * The media description an item carries when it is a photo: one entry per
109
+ * stored part, so a list can lay out a thumbnail and a viewer can size the
110
+ * display variant without fetching either.
111
+ */
112
+ export const PhotoAssetSchema = v.object({
113
+ parts: v.array(PhotoPartMediaSchema),
114
+ });
115
+ /**
116
+ * `GET /api/v1/artifacts/captures/photos/storage` — whether photo capture is
117
+ * available, and the caller's storage when the caller is the one who pays for
118
+ * it (null otherwise, and when unavailable).
119
+ */
120
+ export const PhotoStorageResponseSchema = v.object({
121
+ available: v.boolean(),
122
+ usage: v.nullable(v.object({
123
+ usedBytes: v.pipe(v.number(), v.minValue(0)),
124
+ capBytes: v.pipe(v.number(), v.minValue(0)),
125
+ })),
126
+ });
127
+ //# sourceMappingURL=photos.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"photos.js","sourceRoot":"","sources":["../src/photos.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,CAAC,MAAM,SAAS,CAAA;AAE5B,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,UAAU,EAAE,SAAS,EAAE,OAAO,CAAU,CAAA;AAEpE,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,CAAC,QAAQ,CAAC,WAAW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AAC,oBAAoB,CAAC;CACrC,CAAC,CAAA;AAGF;;;;GAIG;AACH,MAAM,CAAC,MAAM,0BAA0B,GAAG,CAAC,CAAC,MAAM,CAAC;IACjD,SAAS,EAAE,CAAC,CAAC,OAAO,EAAE;IACtB,KAAK,EAAE,CAAC,CAAC,QAAQ,CACf,CAAC,CAAC,MAAM,CAAC;QACP,SAAS,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;QAC5C,QAAQ,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;KAC5C,CAAC,CACH;CACF,CAAC,CAAA"}
@@ -0,0 +1,19 @@
1
+ import * as v from 'valibot';
2
+ export declare const PublicModelIdSchema: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>, v.MaxLengthAction<string, 200, undefined>, v.RegexAction<string, undefined>]>;
3
+ export declare const PublicModelCatalogSchema: v.ObjectSchema<{
4
+ readonly ids: v.SchemaWithPipe<readonly [v.ArraySchema<v.SchemaWithPipe<readonly [v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>, v.MaxLengthAction<string, 200, undefined>, v.RegexAction<string, undefined>]>, v.CheckAction<string, undefined>]>, undefined>, v.MinLengthAction<string[], 1, undefined>, v.MaxLengthAction<string[], 10000, undefined>]>;
5
+ readonly nativeAliases: v.OptionalSchema<v.SchemaWithPipe<readonly [v.ArraySchema<v.StrictObjectSchema<{
6
+ readonly alias: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>, v.MaxLengthAction<string, 200, undefined>, v.RegexAction<string, undefined>]>;
7
+ readonly id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>, v.MaxLengthAction<string, 200, undefined>, v.RegexAction<string, undefined>]>;
8
+ }, undefined>, undefined>, v.MaxLengthAction<{
9
+ alias: string;
10
+ id: string;
11
+ }[], 10000, undefined>]>, undefined>;
12
+ }, undefined>;
13
+ export type PublicModelCatalog = v.InferOutput<typeof PublicModelCatalogSchema>;
14
+ /** Build one resolver per trusted public snapshot, never from transcript labels. */
15
+ export declare function createPublicModelResolver(catalog: PublicModelCatalog): (label: string) => string | null;
16
+ export declare function resolvePublicModel(label: string): string | null;
17
+ /** Validate only IDs; unavailable or malformed pricing does not drop a model. */
18
+ export declare function publicModelCatalogFromResponse(data: unknown): PublicModelCatalog;
19
+ //# sourceMappingURL=publicModelCatalog.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"publicModelCatalog.d.ts","sourceRoot":"","sources":["../src/publicModelCatalog.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,SAAS,CAAA;AAO5B,eAAO,MAAM,mBAAmB,8KAK/B,CAAA;AAED,eAAO,MAAM,wBAAwB;;;;;;;;;aAsBnC,CAAA;AACF,MAAM,MAAM,kBAAkB,GAAG,CAAC,CAAC,WAAW,CAAC,OAAO,wBAAwB,CAAC,CAAA;AAO/E,oFAAoF;AACpF,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,kBAAkB,IAuB3D,OAAO,MAAM,KAAG,MAAM,GAAG,IAAI,CAKtC;AAGD,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAG/D;AAED,iFAAiF;AACjF,wBAAgB,8BAA8B,CAAC,IAAI,EAAE,OAAO,GAAG,kBAAkB,CAYhF"}
@@ -0,0 +1,2 @@
1
+ export declare const PUBLIC_MODEL_IDS: readonly string[];
2
+ //# sourceMappingURL=publicModelCatalog.generated.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"publicModelCatalog.generated.d.ts","sourceRoot":"","sources":["../src/publicModelCatalog.generated.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,gBAAgB,EAAE,SAAS,MAAM,EAqe7C,CAAA"}