@clowder-ai/plugin-contract 0.1.0-beta.9 → 0.3.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 (182) hide show
  1. package/dist/codegen/generate-contract.d.ts +6 -0
  2. package/dist/codegen/generate-contract.d.ts.map +1 -1
  3. package/dist/codegen/generate-contract.js +338 -44
  4. package/dist/codegen/generate-contract.js.map +1 -1
  5. package/dist/conformance/fixtures.d.ts +3 -1
  6. package/dist/conformance/fixtures.d.ts.map +1 -1
  7. package/dist/conformance/fixtures.js +2 -1
  8. package/dist/conformance/fixtures.js.map +1 -1
  9. package/dist/conformance/index.d.ts +3 -3
  10. package/dist/conformance/index.d.ts.map +1 -1
  11. package/dist/conformance/index.js +3 -3
  12. package/dist/conformance/index.js.map +1 -1
  13. package/dist/conformance/messaging-behavior-fixture.d.ts +12 -0
  14. package/dist/conformance/messaging-behavior-fixture.d.ts.map +1 -0
  15. package/dist/conformance/messaging-behavior-fixture.js +24 -0
  16. package/dist/conformance/messaging-behavior-fixture.js.map +1 -0
  17. package/dist/conformance/messaging-loopback-adapter.d.ts +0 -3
  18. package/dist/conformance/messaging-loopback-adapter.d.ts.map +1 -1
  19. package/dist/conformance/messaging-loopback-adapter.js +1 -77
  20. package/dist/conformance/messaging-loopback-adapter.js.map +1 -1
  21. package/dist/conformance/messaging-loopback-state.d.ts +0 -6
  22. package/dist/conformance/messaging-loopback-state.d.ts.map +1 -1
  23. package/dist/conformance/messaging-loopback-state.js +0 -20
  24. package/dist/conformance/messaging-loopback-state.js.map +1 -1
  25. package/dist/conformance/runner.d.ts.map +1 -1
  26. package/dist/conformance/runner.js +3 -1
  27. package/dist/conformance/runner.js.map +1 -1
  28. package/dist/docx-materialization.d.ts +8 -0
  29. package/dist/docx-materialization.d.ts.map +1 -0
  30. package/dist/docx-materialization.js +19 -0
  31. package/dist/docx-materialization.js.map +1 -0
  32. package/dist/generated/contract.generated.d.ts +1637 -87
  33. package/dist/generated/contract.generated.d.ts.map +1 -1
  34. package/dist/generated/contract.generated.js +70 -9
  35. package/dist/generated/contract.generated.js.map +1 -1
  36. package/dist/index.d.ts +2 -3
  37. package/dist/index.d.ts.map +1 -1
  38. package/dist/index.js +2 -3
  39. package/dist/index.js.map +1 -1
  40. package/dist/types/index.d.ts +0 -1
  41. package/dist/types/index.d.ts.map +1 -1
  42. package/dist/types/index.js +0 -1
  43. package/dist/types/index.js.map +1 -1
  44. package/dist/validation/catalog.d.ts +21 -0
  45. package/dist/validation/catalog.d.ts.map +1 -0
  46. package/dist/validation/catalog.js +140 -0
  47. package/dist/validation/catalog.js.map +1 -0
  48. package/dist/validation/cloud-conversation-host.d.ts +18 -0
  49. package/dist/validation/cloud-conversation-host.d.ts.map +1 -0
  50. package/dist/validation/cloud-conversation-host.js +83 -0
  51. package/dist/validation/cloud-conversation-host.js.map +1 -0
  52. package/dist/validation/companion-bridge.d.ts +6 -0
  53. package/dist/validation/companion-bridge.d.ts.map +1 -0
  54. package/dist/validation/companion-bridge.js +198 -0
  55. package/dist/validation/companion-bridge.js.map +1 -0
  56. package/dist/validation/docx-materialization.d.ts +6 -0
  57. package/dist/validation/docx-materialization.d.ts.map +1 -0
  58. package/dist/validation/docx-materialization.js +36 -0
  59. package/dist/validation/docx-materialization.js.map +1 -0
  60. package/dist/validation/index.d.ts +9 -1
  61. package/dist/validation/index.d.ts.map +1 -1
  62. package/dist/validation/index.js +9 -1
  63. package/dist/validation/index.js.map +1 -1
  64. package/dist/validation/manifest.d.ts.map +1 -1
  65. package/dist/validation/manifest.js +317 -0
  66. package/dist/validation/manifest.js.map +1 -1
  67. package/dist/validation/members.d.ts +4 -0
  68. package/dist/validation/members.d.ts.map +1 -0
  69. package/dist/validation/members.js +11 -0
  70. package/dist/validation/members.js.map +1 -0
  71. package/dist/validation/messaging-semantic.d.ts.map +1 -1
  72. package/dist/validation/messaging-semantic.js +98 -0
  73. package/dist/validation/messaging-semantic.js.map +1 -1
  74. package/dist/validation/messaging-wire.d.ts +42 -0
  75. package/dist/validation/messaging-wire.d.ts.map +1 -0
  76. package/dist/validation/messaging-wire.js +184 -0
  77. package/dist/validation/messaging-wire.js.map +1 -0
  78. package/dist/validation/operation-rows.d.ts +25 -0
  79. package/dist/validation/operation-rows.d.ts.map +1 -0
  80. package/dist/validation/operation-rows.js +135 -0
  81. package/dist/validation/operation-rows.js.map +1 -0
  82. package/dist/validation/signals.d.ts +1 -10
  83. package/dist/validation/signals.d.ts.map +1 -1
  84. package/dist/validation/signals.js +0 -174
  85. package/dist/validation/signals.js.map +1 -1
  86. package/dist/variant.d.ts +114 -0
  87. package/dist/variant.d.ts.map +1 -0
  88. package/dist/variant.js +305 -0
  89. package/dist/variant.js.map +1 -0
  90. package/dist/wire/constants.d.ts +2 -1
  91. package/dist/wire/constants.d.ts.map +1 -1
  92. package/dist/wire/constants.js +2 -1
  93. package/dist/wire/constants.js.map +1 -1
  94. package/dist/wire/dispatch.d.ts +49 -0
  95. package/dist/wire/dispatch.d.ts.map +1 -0
  96. package/dist/wire/dispatch.js +870 -0
  97. package/dist/wire/dispatch.js.map +1 -0
  98. package/dist/wire/disposition-fixtures.d.ts +10 -2
  99. package/dist/wire/disposition-fixtures.d.ts.map +1 -1
  100. package/dist/wire/disposition-fixtures.js +539 -108
  101. package/dist/wire/disposition-fixtures.js.map +1 -1
  102. package/dist/wire/disposition.d.ts +3 -4
  103. package/dist/wire/disposition.d.ts.map +1 -1
  104. package/dist/wire/disposition.js +5 -16
  105. package/dist/wire/disposition.js.map +1 -1
  106. package/dist/wire/envelope.d.ts +31 -1
  107. package/dist/wire/envelope.d.ts.map +1 -1
  108. package/dist/wire/envelope.js +48 -1
  109. package/dist/wire/envelope.js.map +1 -1
  110. package/dist/wire/errors.d.ts +31 -1
  111. package/dist/wire/errors.d.ts.map +1 -1
  112. package/dist/wire/errors.js +36 -0
  113. package/dist/wire/errors.js.map +1 -1
  114. package/dist/wire/handshake-byte-bounds.d.ts.map +1 -1
  115. package/dist/wire/handshake-byte-bounds.js +1 -4
  116. package/dist/wire/handshake-byte-bounds.js.map +1 -1
  117. package/dist/wire/handshake.d.ts +12 -11
  118. package/dist/wire/handshake.d.ts.map +1 -1
  119. package/dist/wire/handshake.js +11 -15
  120. package/dist/wire/handshake.js.map +1 -1
  121. package/dist/wire/index.d.ts +15 -13
  122. package/dist/wire/index.d.ts.map +1 -1
  123. package/dist/wire/index.js +30 -9
  124. package/dist/wire/index.js.map +1 -1
  125. package/dist/wire/lifecycle-byte-bounds.d.ts +40 -0
  126. package/dist/wire/lifecycle-byte-bounds.d.ts.map +1 -0
  127. package/dist/wire/lifecycle-byte-bounds.js +148 -0
  128. package/dist/wire/lifecycle-byte-bounds.js.map +1 -0
  129. package/dist/wire/messaging-byte-bounds.d.ts +62 -0
  130. package/dist/wire/messaging-byte-bounds.d.ts.map +1 -0
  131. package/dist/wire/messaging-byte-bounds.js +581 -0
  132. package/dist/wire/messaging-byte-bounds.js.map +1 -0
  133. package/dist/wire/registry.d.ts +58 -107
  134. package/dist/wire/registry.d.ts.map +1 -1
  135. package/dist/wire/registry.js +45 -107
  136. package/dist/wire/registry.js.map +1 -1
  137. package/dist/wire/row-shapes.d.ts +82 -81
  138. package/dist/wire/row-shapes.d.ts.map +1 -1
  139. package/dist/wire/row-shapes.js +30 -3
  140. package/dist/wire/row-shapes.js.map +1 -1
  141. package/fixtures/behavior/messaging/adversarial-invariants.json +62 -183
  142. package/fixtures/manifest/invalid/contract-version-leading-zero-prerelease.json +1 -3
  143. package/fixtures/manifest/invalid/contract-version-range.json +1 -3
  144. package/fixtures/manifest/invalid/duplicate-signal-type.json +4 -4
  145. package/fixtures/manifest/invalid/icon-package-escape.json +20 -0
  146. package/fixtures/manifest/invalid/ipc-empty-entrypoint.json +1 -3
  147. package/fixtures/manifest/invalid/plugin-version-leading-zero-prerelease.json +1 -3
  148. package/fixtures/manifest/invalid/plugin-version-not-semver.json +1 -3
  149. package/fixtures/manifest/invalid/semver-empty-build-metadata.json +1 -3
  150. package/fixtures/manifest/invalid/stdio-missing-entrypoint.json +1 -3
  151. package/fixtures/manifest/invalid/user-authored-lifecycle.json +1 -3
  152. package/fixtures/manifest/valid/localized-product-metadata.json +25 -0
  153. package/fixtures/manifest/valid/minimal-builtin.json +1 -3
  154. package/fixtures/manifest/valid/protocol-intrinsic-lifecycle.json +1 -3
  155. package/fixtures/manifest/valid/semver-build-metadata.json +1 -3
  156. package/fixtures/manifest/valid/stdio-entrypoint.json +1 -3
  157. package/fixtures/messaging/valid/subscription-delivery.json +1 -1
  158. package/package.json +17 -4
  159. package/src/schemas/behavior-fixture.schema.json +800 -152
  160. package/src/schemas/catalog.schema.json +91 -0
  161. package/src/schemas/companion-bridge.schema.json +2256 -0
  162. package/src/schemas/docx-materialization.schema.json +302 -0
  163. package/src/schemas/manifest.schema.json +2196 -107
  164. package/src/schemas/messaging.schema.json +692 -41
  165. package/src/schemas/plugin-metadata.schema.json +62 -0
  166. package/src/schemas/signal.schema.json +68 -78
  167. package/dist/types/capability.d.ts +0 -4
  168. package/dist/types/capability.d.ts.map +0 -1
  169. package/dist/types/capability.js +0 -11
  170. package/dist/types/capability.js.map +0 -1
  171. package/dist/wire/grants.d.ts +0 -57
  172. package/dist/wire/grants.d.ts.map +0 -1
  173. package/dist/wire/grants.js +0 -59
  174. package/dist/wire/grants.js.map +0 -1
  175. package/dist/wire/signal-byte-bounds.d.ts +0 -97
  176. package/dist/wire/signal-byte-bounds.d.ts.map +0 -1
  177. package/dist/wire/signal-byte-bounds.js +0 -229
  178. package/dist/wire/signal-byte-bounds.js.map +0 -1
  179. package/fixtures/manifest/invalid/unknown-capability.json +0 -19
  180. package/fixtures/signals/invalid/destination-injection.json +0 -15
  181. package/fixtures/signals/invalid/non-utc-occurred-at.json +0 -12
  182. package/fixtures/signals/valid/feishu-meeting-artifact.json +0 -18
@@ -0,0 +1,62 @@
1
+ /**
2
+ * Derived compact-JSON byte bounds for the beta.11 M0-C messaging rows.
3
+ *
4
+ * Structural maxima are built from the closed public grammar and measured as
5
+ * compact UTF-8 JSON. Read and snapshot results are intentionally different:
6
+ * their legal structural maxima can exceed one frame, so their published
7
+ * bound is the final-frame assembler budget rather than a fictional
8
+ * structural maximum.
9
+ */
10
+ import type { AppendElementsRequest, AppendReceipt, SendReceipt } from '../generated/contract.generated.js';
11
+ import type { DeliverInput, DeliverResult, MediaReadInput, MediaReadResult, MessagingAckRequest, MessagingAckResult, ReadInput, SendInput, SnapshotInput, SubscribeInput, SubscribeResult } from './row-shapes.js';
12
+ import type { MessagingRowMethod } from '../validation/messaging-wire.js';
13
+ export declare const MESSAGING_BYTE_PROOF_ENCODING_FAMILIES: readonly ["ascii", "multibyte", "escaping"];
14
+ export type MessagingByteProofEncodingFamily = (typeof MESSAGING_BYTE_PROOF_ENCODING_FAMILIES)[number];
15
+ export type MessagingByteProofBasis = 'structural-maximum' | 'assembler-budget';
16
+ export interface MessagingNPlusOneByteProof {
17
+ readonly leaf: string;
18
+ readonly encodedBytes: number;
19
+ readonly fitsFrame: boolean;
20
+ }
21
+ export interface MessagingEncodedByteProofCase {
22
+ readonly family: MessagingByteProofEncodingFamily;
23
+ readonly encodedBytes: number;
24
+ readonly fitsFrame: boolean;
25
+ readonly nPlusOne: readonly MessagingNPlusOneByteProof[];
26
+ }
27
+ export interface MessagingEncodedByteProof {
28
+ readonly basis: MessagingByteProofBasis;
29
+ readonly maxEncodedBytes: number;
30
+ readonly cases: readonly MessagingEncodedByteProofCase[];
31
+ }
32
+ export interface MessagingRowEncodedByteBounds {
33
+ readonly maxEncodedRequestBytes: number;
34
+ readonly maxEncodedResultBytes: number;
35
+ readonly maxEncodedErrorBytes: number;
36
+ }
37
+ export interface MessagingNPlusOneInputWitness {
38
+ readonly leaf: string;
39
+ readonly input: unknown;
40
+ }
41
+ export interface MessagingNPlusOneResultWitness {
42
+ readonly leaf: string;
43
+ readonly result: unknown;
44
+ }
45
+ export declare function messagingMaximumRequestInput(method: MessagingRowMethod, family: MessagingByteProofEncodingFamily): SendInput | AppendElementsRequest | SubscribeInput | ReadInput | MessagingAckRequest | SnapshotInput | DeliverInput | MediaReadInput;
46
+ export declare function messagingMaximumResult(method: Exclude<MessagingRowMethod, 'messaging.read' | 'messaging.snapshot'>, family: MessagingByteProofEncodingFamily): SendReceipt | AppendReceipt | SubscribeResult | MessagingAckResult | DeliverResult | MediaReadResult;
47
+ export declare function messagingRequestNPlusOneInputs(method: MessagingRowMethod, family: MessagingByteProofEncodingFamily): readonly MessagingNPlusOneInputWitness[];
48
+ export declare function messagingResultNPlusOneInputs(method: Exclude<MessagingRowMethod, 'messaging.read' | 'messaging.snapshot'>, family: MessagingByteProofEncodingFamily): readonly MessagingNPlusOneResultWitness[];
49
+ export declare const MESSAGING_REQUEST_BYTE_PROOFS: Readonly<Record<MessagingRowMethod, MessagingEncodedByteProof>>;
50
+ export declare const MESSAGING_RESULT_BYTE_PROOFS: {
51
+ readonly 'messaging.send': MessagingEncodedByteProof;
52
+ readonly 'messaging.appendElements': MessagingEncodedByteProof;
53
+ readonly 'messaging.subscribe': MessagingEncodedByteProof;
54
+ readonly 'messaging.read': MessagingEncodedByteProof;
55
+ readonly 'messaging.ack': MessagingEncodedByteProof;
56
+ readonly 'messaging.snapshot': MessagingEncodedByteProof;
57
+ readonly 'streams.read': MessagingEncodedByteProof;
58
+ readonly 'host.messaging.deliver': MessagingEncodedByteProof;
59
+ };
60
+ export declare const MESSAGING_ERROR_BYTE_PROOFS: Readonly<Record<MessagingRowMethod, MessagingEncodedByteProof>>;
61
+ export declare const MESSAGING_ROW_ENCODED_BYTE_BOUNDS: Readonly<Record<MessagingRowMethod, MessagingRowEncodedByteBounds>>;
62
+ //# sourceMappingURL=messaging-byte-bounds.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"messaging-byte-bounds.d.ts","sourceRoot":"","sources":["../../src/wire/messaging-byte-bounds.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EACV,qBAAqB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AAC,CAAC"}
@@ -0,0 +1,581 @@
1
+ /**
2
+ * Derived compact-JSON byte bounds for the beta.11 M0-C messaging rows.
3
+ *
4
+ * Structural maxima are built from the closed public grammar and measured as
5
+ * compact UTF-8 JSON. Read and snapshot results are intentionally different:
6
+ * their legal structural maxima can exceed one frame, so their published
7
+ * bound is the final-frame assembler budget rather than a fictional
8
+ * structural maximum.
9
+ */
10
+ import { MAX_ELEMENT_PAYLOAD_BYTES, MAX_ELEMENTS_PER_MESSAGE, MAX_ELEMENTS_PER_OPERATION, MAX_FRAME_BYTES, MAX_TOTAL_PAYLOAD_BYTES, MAX_WHISPER_TARGETS, } from './constants.js';
11
+ import { DEADLINE_EXPIRED_CODE, DEADLINE_EXPIRED_MESSAGE, DELIVERY_REJECTED_CODE, DELIVERY_REJECTED_MESSAGE, DELIVERY_REJECT_REASONS, LIFECYCLE_REJECT_REASONS, DOMAIN_ERROR_CODE, DOMAIN_ERROR_MESSAGE, ERROR_CODE_TO_MESSAGE, INVALID_REQUEST_CODE, PARSE_ERROR_CODE, SNAPSHOT_UNAVAILABLE_CODE, SNAPSHOT_UNAVAILABLE_MESSAGE, SNAPSHOT_UNAVAILABLE_REASONS, STANDARD_ERROR_CODES, } from './errors.js';
12
+ import { REQUEST_ID_MAX_LENGTH } from './request-id.js';
13
+ import { WIRE_UINT53_MAX } from './wire-uint53.js';
14
+ export const MESSAGING_BYTE_PROOF_ENCODING_FAMILIES = [
15
+ 'ascii',
16
+ 'multibyte',
17
+ 'escaping',
18
+ ];
19
+ const MAX_REQUEST_ID = 'a'.repeat(REQUEST_ID_MAX_LENGTH);
20
+ const ESCAPING_SCALARS = [
21
+ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
22
+ 0x0b, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14,
23
+ ];
24
+ function byteLength(value) {
25
+ return Buffer.byteLength(JSON.stringify(value), 'utf8');
26
+ }
27
+ function familyScalar(family, salt = 0) {
28
+ switch (family) {
29
+ case 'ascii':
30
+ return String.fromCodePoint(0x61 + (salt % 26));
31
+ case 'multibyte':
32
+ return String.fromCodePoint(0x1f408 + (salt % 16));
33
+ case 'escaping':
34
+ return String.fromCodePoint(ESCAPING_SCALARS[salt % ESCAPING_SCALARS.length]);
35
+ }
36
+ }
37
+ function maximumString(family, length, salt = 0) {
38
+ if (length === 0)
39
+ return '';
40
+ return `${familyScalar(family).repeat(length - 1)}${familyScalar(family, salt)}`;
41
+ }
42
+ function exactPayload(family, targetBytes) {
43
+ const scalar = familyScalar(family);
44
+ const empty = { id: 'proof', kind: 'proof', v: 1, data: '', pad: '' };
45
+ const staticBytes = byteLength(empty);
46
+ const unitBytes = byteLength({ ...empty, data: scalar }) - staticBytes;
47
+ const repetitions = Math.floor((targetBytes - staticBytes) / unitBytes);
48
+ const data = scalar.repeat(repetitions);
49
+ const usedBytes = byteLength({ ...empty, data });
50
+ const payload = { ...empty, data, pad: 'a'.repeat(targetBytes - usedBytes) };
51
+ if (byteLength(payload) !== targetBytes) {
52
+ throw new Error(`failed to construct exact ${targetBytes}-byte messaging payload`);
53
+ }
54
+ return payload;
55
+ }
56
+ function maximumElements(family, count, totalPayloadBytes = MAX_TOTAL_PAYLOAD_BYTES) {
57
+ if (totalPayloadBytes % count !== 0) {
58
+ throw new Error('messaging proof payload budget must divide evenly across elements');
59
+ }
60
+ const payloadBytes = totalPayloadBytes / count;
61
+ return Array.from({ length: count }, (_, index) => ({
62
+ elementId: maximumString(family, 128, index),
63
+ kind: 'rich_block',
64
+ payload: exactPayload(family, payloadBytes),
65
+ derivedFromElementId: maximumString(family, 128, index + count),
66
+ epistemicStatus: 'observation',
67
+ }));
68
+ }
69
+ function maximumAudience(family) {
70
+ return {
71
+ kind: 'whisper',
72
+ targets: Array.from({ length: MAX_WHISPER_TARGETS }, (_, index) => maximumString(family, 256, index)),
73
+ };
74
+ }
75
+ function maximumOrigin(family) {
76
+ return {
77
+ kind: 'external',
78
+ connectorId: maximumString(family, 256, 1),
79
+ sourceAddress: {
80
+ connectorId: maximumString(family, 256, 2),
81
+ chatId: maximumString(family, 512, 3),
82
+ messageId: maximumString(family, 512, 4),
83
+ },
84
+ };
85
+ }
86
+ function maximumDraft(family) {
87
+ return {
88
+ address: {
89
+ kind: 'connector_binding',
90
+ handle: maximumString(family, 256, 5),
91
+ },
92
+ draftAudience: maximumAudience(family),
93
+ idempotencyKey: maximumString(family, 200, 6),
94
+ sourceEventId: maximumString(family, 512, 7),
95
+ replyTo: maximumString(family, 256, 8),
96
+ payload: {
97
+ provenance: {
98
+ origin: maximumOrigin(family),
99
+ epistemicStatus: 'observation',
100
+ },
101
+ elements: maximumElements(family, MAX_ELEMENTS_PER_OPERATION),
102
+ correlationId: maximumString(family, 256, 9),
103
+ causationId: maximumString(family, 256, 10),
104
+ },
105
+ };
106
+ }
107
+ function maximumEnvelope(family) {
108
+ return {
109
+ messageId: maximumString(family, 512, 1),
110
+ revision: WIRE_UINT53_MAX,
111
+ threadId: maximumString(family, 512, 2),
112
+ replyTo: maximumString(family, 256, 3),
113
+ actor: { kind: 'system', id: maximumString(family, 512, 4) },
114
+ audience: maximumAudience(family),
115
+ occurredAt: '+010000-01-01T00:00:00.000Z',
116
+ payload: {
117
+ provenance: {
118
+ origin: maximumOrigin(family),
119
+ epistemicStatus: 'observation',
120
+ },
121
+ elements: maximumElements(family, MAX_ELEMENTS_PER_MESSAGE),
122
+ correlationId: maximumString(family, 256, 5),
123
+ causationId: maximumString(family, 256, 6),
124
+ },
125
+ };
126
+ }
127
+ function maximumFrontendDisplayUrl(length = 2048) {
128
+ const prefix = 'https://example.invalid/';
129
+ return `${prefix}${'a'.repeat(length - prefix.length)}`;
130
+ }
131
+ function maximumPresentation(family, salt = 0) {
132
+ return {
133
+ actor: {
134
+ displayName: maximumString(family, 256, salt + 1),
135
+ emoji: maximumString(family, 32, salt + 2),
136
+ },
137
+ thread: {
138
+ shortId: maximumString(family, 128, salt + 3),
139
+ title: maximumString(family, 512, salt + 4),
140
+ featId: maximumString(family, 128, salt + 5),
141
+ },
142
+ deepLinkUrl: maximumFrontendDisplayUrl(),
143
+ };
144
+ }
145
+ function requestFrame(method, input, requestId = MAX_REQUEST_ID) {
146
+ return {
147
+ jsonrpc: '2.0',
148
+ id: requestId,
149
+ method,
150
+ params: { meta: { deadlineUnixMs: WIRE_UINT53_MAX }, input },
151
+ };
152
+ }
153
+ function resultFrame(result, requestId = MAX_REQUEST_ID) {
154
+ return { jsonrpc: '2.0', id: requestId, result };
155
+ }
156
+ export function messagingMaximumRequestInput(method, family) {
157
+ switch (method) {
158
+ case 'messaging.send':
159
+ return maximumDraft(family);
160
+ case 'messaging.appendElements':
161
+ return {
162
+ handle: { kind: 'message', token: maximumString(family, 512, 1) },
163
+ operationId: maximumString(family, 200, 2),
164
+ baseRevision: WIRE_UINT53_MAX,
165
+ elements: maximumElements(family, MAX_ELEMENTS_PER_OPERATION),
166
+ };
167
+ case 'messaging.subscribe':
168
+ return { handle: maximumString(family, 256, 1) };
169
+ case 'messaging.read':
170
+ return { subscriptionId: maximumString(family, 128, 1), limit: 32 };
171
+ case 'messaging.ack':
172
+ return {
173
+ subscriptionId: maximumString(family, 128, 1),
174
+ ackToken: maximumString(family, 512, 2),
175
+ };
176
+ case 'messaging.snapshot':
177
+ return {
178
+ subscriptionId: maximumString(family, 128, 1),
179
+ maxItems: 64,
180
+ pageToken: maximumString(family, 512, 2),
181
+ };
182
+ case 'streams.read':
183
+ return {
184
+ reference: `hmr_${maximumString(family, 2044, 1)}`,
185
+ offset: WIRE_UINT53_MAX,
186
+ limit: 524_288,
187
+ };
188
+ case 'host.messaging.deliver':
189
+ return {
190
+ deliveryId: maximumString(family, 128, 1),
191
+ kind: 'message',
192
+ executionId: maximumString(family, 128, 2),
193
+ threadId: maximumEnvelope(family).threadId,
194
+ envelope: maximumEnvelope(family),
195
+ presentation: maximumPresentation(family, 3),
196
+ };
197
+ }
198
+ }
199
+ export function messagingMaximumResult(method, family) {
200
+ switch (method) {
201
+ case 'messaging.send':
202
+ return {
203
+ messageId: maximumString(family, 512, 1),
204
+ threadId: maximumString(family, 512, 2),
205
+ revision: WIRE_UINT53_MAX,
206
+ messageHandle: { kind: 'message', token: maximumString(family, 512, 3) },
207
+ publishSequence: WIRE_UINT53_MAX,
208
+ };
209
+ case 'messaging.appendElements':
210
+ return {
211
+ messageId: maximumString(family, 512, 1),
212
+ revision: WIRE_UINT53_MAX,
213
+ appendSequence: WIRE_UINT53_MAX,
214
+ appliedElementIds: Array.from({ length: MAX_ELEMENTS_PER_OPERATION }, (_, index) => maximumString(family, 128, index)),
215
+ };
216
+ case 'messaging.subscribe':
217
+ return { subscriptionId: maximumString(family, 128, 1) };
218
+ case 'messaging.ack':
219
+ return null;
220
+ case 'streams.read':
221
+ return {
222
+ offset: WIRE_UINT53_MAX,
223
+ dataBase64: 'A'.repeat(699_048),
224
+ done: true,
225
+ };
226
+ case 'host.messaging.deliver':
227
+ return { deliveryId: maximumString(family, 128, 1) };
228
+ }
229
+ }
230
+ function payloadNPlusOneDraft(family, aggregate) {
231
+ const draft = maximumDraft(family);
232
+ const elements = aggregate
233
+ ? Array.from({ length: 5 }, (_, index) => ({
234
+ elementId: maximumString(family, 128, index),
235
+ kind: 'rich_block',
236
+ payload: exactPayload(family, index === 4 ? 64 : MAX_ELEMENT_PAYLOAD_BYTES),
237
+ }))
238
+ : [{
239
+ elementId: maximumString(family, 128),
240
+ kind: 'rich_block',
241
+ payload: exactPayload(family, MAX_ELEMENT_PAYLOAD_BYTES + 1),
242
+ }];
243
+ return { ...draft, payload: { ...draft.payload, elements } };
244
+ }
245
+ export function messagingRequestNPlusOneInputs(method, family) {
246
+ switch (method) {
247
+ case 'messaging.send': {
248
+ const maximum = maximumDraft(family);
249
+ return [
250
+ { leaf: 'idempotencyKey', input: { ...maximum, idempotencyKey: maximumString(family, 201) } },
251
+ { leaf: 'payloadBytes', input: payloadNPlusOneDraft(family, false) },
252
+ { leaf: 'aggregatePayloadBytes', input: payloadNPlusOneDraft(family, true) },
253
+ ];
254
+ }
255
+ case 'messaging.appendElements': {
256
+ const maximum = messagingMaximumRequestInput(method, family);
257
+ return [
258
+ { leaf: 'operationId', input: { ...maximum, operationId: maximumString(family, 201) } },
259
+ {
260
+ leaf: 'payloadBytes',
261
+ input: {
262
+ ...maximum,
263
+ elements: [{
264
+ elementId: maximumString(family, 128),
265
+ kind: 'rich_block',
266
+ payload: exactPayload(family, MAX_ELEMENT_PAYLOAD_BYTES + 1),
267
+ }],
268
+ },
269
+ },
270
+ ];
271
+ }
272
+ case 'messaging.subscribe':
273
+ return [{ leaf: 'handle', input: { handle: maximumString(family, 257) } }];
274
+ case 'messaging.read':
275
+ return [
276
+ { leaf: 'subscriptionId', input: { subscriptionId: maximumString(family, 129), limit: 32 } },
277
+ { leaf: 'limit', input: { subscriptionId: maximumString(family, 128), limit: 33 } },
278
+ ];
279
+ case 'messaging.ack':
280
+ return [
281
+ { leaf: 'subscriptionId', input: { subscriptionId: maximumString(family, 129), ackToken: 'a' } },
282
+ { leaf: 'ackToken', input: { subscriptionId: 'a', ackToken: maximumString(family, 513) } },
283
+ ];
284
+ case 'messaging.snapshot':
285
+ return [
286
+ { leaf: 'subscriptionId', input: { subscriptionId: maximumString(family, 129), maxItems: 64 } },
287
+ { leaf: 'maxItems', input: { subscriptionId: 'a', maxItems: 65 } },
288
+ { leaf: 'pageToken', input: { subscriptionId: 'a', maxItems: 64, pageToken: maximumString(family, 513) } },
289
+ ];
290
+ case 'streams.read':
291
+ return [
292
+ { leaf: 'reference', input: { reference: `hmr_${maximumString(family, 2045)}`, offset: 0, limit: 1 } },
293
+ { leaf: 'limit', input: { reference: 'hmr_a', offset: 0, limit: 524_289 } },
294
+ ];
295
+ case 'host.messaging.deliver': {
296
+ const maximum = messagingMaximumRequestInput(method, family);
297
+ if (maximum.kind !== 'message')
298
+ throw new Error('message arm supplies the delivery byte maximum');
299
+ return [
300
+ { leaf: 'deliveryId', input: { ...maximum, deliveryId: maximumString(family, 129) } },
301
+ { leaf: 'executionId', input: { ...maximum, executionId: maximumString(family, 129) } },
302
+ {
303
+ leaf: 'threadId',
304
+ input: {
305
+ ...maximum,
306
+ threadId: maximumString(family, 513),
307
+ },
308
+ },
309
+ {
310
+ leaf: 'presentation.actor.displayName',
311
+ input: {
312
+ ...maximum,
313
+ presentation: {
314
+ ...maximum.presentation,
315
+ actor: {
316
+ ...maximum.presentation.actor,
317
+ displayName: maximumString(family, 257),
318
+ },
319
+ },
320
+ },
321
+ },
322
+ {
323
+ leaf: 'presentation.actor.emoji',
324
+ input: {
325
+ ...maximum,
326
+ presentation: {
327
+ ...maximum.presentation,
328
+ actor: {
329
+ ...maximum.presentation.actor,
330
+ emoji: maximumString(family, 33),
331
+ },
332
+ },
333
+ },
334
+ },
335
+ {
336
+ leaf: 'presentation.thread.shortId',
337
+ input: {
338
+ ...maximum,
339
+ presentation: {
340
+ ...maximum.presentation,
341
+ thread: {
342
+ ...maximum.presentation.thread,
343
+ shortId: maximumString(family, 129),
344
+ },
345
+ },
346
+ },
347
+ },
348
+ {
349
+ leaf: 'presentation.thread.title',
350
+ input: {
351
+ ...maximum,
352
+ presentation: {
353
+ ...maximum.presentation,
354
+ thread: {
355
+ ...maximum.presentation.thread,
356
+ title: maximumString(family, 513),
357
+ },
358
+ },
359
+ },
360
+ },
361
+ {
362
+ leaf: 'presentation.thread.featId',
363
+ input: {
364
+ ...maximum,
365
+ presentation: {
366
+ ...maximum.presentation,
367
+ thread: {
368
+ ...maximum.presentation.thread,
369
+ featId: maximumString(family, 129),
370
+ },
371
+ },
372
+ },
373
+ },
374
+ {
375
+ leaf: 'presentation.deepLinkUrl',
376
+ input: {
377
+ ...maximum,
378
+ presentation: {
379
+ ...maximum.presentation,
380
+ deepLinkUrl: maximumFrontendDisplayUrl(2049),
381
+ },
382
+ },
383
+ },
384
+ ];
385
+ }
386
+ }
387
+ }
388
+ export function messagingResultNPlusOneInputs(method, family) {
389
+ const maximum = messagingMaximumResult(method, family);
390
+ switch (method) {
391
+ case 'messaging.send':
392
+ return [{ leaf: 'messageId', result: { ...maximum, messageId: maximumString(family, 513) } }];
393
+ case 'messaging.appendElements':
394
+ return [{
395
+ leaf: 'appliedElementIds',
396
+ result: {
397
+ ...maximum,
398
+ appliedElementIds: Array.from({ length: 33 }, (_, index) => maximumString(family, 128, index)),
399
+ },
400
+ }];
401
+ case 'messaging.subscribe':
402
+ return [{ leaf: 'subscriptionId', result: { subscriptionId: maximumString(family, 129) } }];
403
+ case 'messaging.ack':
404
+ return [];
405
+ case 'streams.read':
406
+ return [{
407
+ leaf: 'dataBase64',
408
+ result: { offset: 0, dataBase64: 'A'.repeat(699_053), done: true },
409
+ }];
410
+ case 'host.messaging.deliver':
411
+ return [{ leaf: 'deliveryId', result: { deliveryId: maximumString(family, 129) } }];
412
+ }
413
+ }
414
+ function structuralProof(maximumFrames, nPlusOneFrames) {
415
+ const cases = MESSAGING_BYTE_PROOF_ENCODING_FAMILIES.map((family) => {
416
+ const encodedBytes = byteLength(maximumFrames(family));
417
+ return {
418
+ family,
419
+ encodedBytes,
420
+ fitsFrame: encodedBytes <= MAX_FRAME_BYTES,
421
+ nPlusOne: nPlusOneFrames(family).map(({ leaf, frame }) => {
422
+ const witnessBytes = byteLength(frame);
423
+ return { leaf, encodedBytes: witnessBytes, fitsFrame: witnessBytes <= MAX_FRAME_BYTES };
424
+ }),
425
+ };
426
+ });
427
+ return {
428
+ basis: 'structural-maximum',
429
+ maxEncodedBytes: Math.max(...cases.map(({ encodedBytes }) => encodedBytes)),
430
+ cases,
431
+ };
432
+ }
433
+ function assemblerBudgetProof() {
434
+ return {
435
+ basis: 'assembler-budget',
436
+ maxEncodedBytes: MAX_FRAME_BYTES,
437
+ cases: MESSAGING_BYTE_PROOF_ENCODING_FAMILIES.map((family) => ({
438
+ family,
439
+ encodedBytes: MAX_FRAME_BYTES,
440
+ fitsFrame: true,
441
+ nPlusOne: [{
442
+ leaf: 'frameBytes',
443
+ encodedBytes: MAX_FRAME_BYTES + 1,
444
+ fitsFrame: false,
445
+ }],
446
+ })),
447
+ };
448
+ }
449
+ function requestProof(method) {
450
+ return structuralProof(family => requestFrame(method, messagingMaximumRequestInput(method, family)), family => [
451
+ {
452
+ leaf: 'requestId',
453
+ frame: requestFrame(method, messagingMaximumRequestInput(method, family), 'a'.repeat(REQUEST_ID_MAX_LENGTH + 1)),
454
+ },
455
+ ...messagingRequestNPlusOneInputs(method, family).map(({ leaf, input }) => ({
456
+ leaf,
457
+ frame: requestFrame(method, input),
458
+ })),
459
+ ]);
460
+ }
461
+ function resultProof(method) {
462
+ return structuralProof(family => resultFrame(messagingMaximumResult(method, family)), family => [
463
+ {
464
+ leaf: 'requestId',
465
+ frame: resultFrame(messagingMaximumResult(method, family), 'a'.repeat(REQUEST_ID_MAX_LENGTH + 1)),
466
+ },
467
+ ...messagingResultNPlusOneInputs(method, family).map(({ leaf, result }) => ({
468
+ leaf,
469
+ frame: resultFrame(result),
470
+ })),
471
+ ]);
472
+ }
473
+ const MESSAGING_ERROR_CODES = [
474
+ 'VALIDATION',
475
+ 'PERMISSION',
476
+ 'NOT_FOUND',
477
+ 'CONFLICT',
478
+ 'RETRYABLE_INFLIGHT',
479
+ 'STALE_CURSOR',
480
+ 'MEDIA_ACCESS_DENIED',
481
+ 'MESSAGE_NOT_PUBLISHED',
482
+ ];
483
+ function longest(values) {
484
+ return values.reduce((current, candidate) => candidate.length > current.length ? candidate : current);
485
+ }
486
+ function standardErrorEnvelopes() {
487
+ return STANDARD_ERROR_CODES.flatMap((code) => {
488
+ const error = { code, message: ERROR_CODE_TO_MESSAGE[code] };
489
+ if (code === PARSE_ERROR_CODE)
490
+ return [{ id: null, error }];
491
+ if (code === INVALID_REQUEST_CODE) {
492
+ return [{ id: null, error }, { id: MAX_REQUEST_ID, error }];
493
+ }
494
+ return [{ id: MAX_REQUEST_ID, error }];
495
+ });
496
+ }
497
+ function applicationErrorEnvelopes(method) {
498
+ const common = [
499
+ {
500
+ id: MAX_REQUEST_ID,
501
+ error: {
502
+ code: DOMAIN_ERROR_CODE,
503
+ message: DOMAIN_ERROR_MESSAGE,
504
+ data: { code: longest(MESSAGING_ERROR_CODES) },
505
+ },
506
+ },
507
+ {
508
+ id: MAX_REQUEST_ID,
509
+ error: {
510
+ code: DEADLINE_EXPIRED_CODE,
511
+ message: DEADLINE_EXPIRED_MESSAGE,
512
+ data: {},
513
+ },
514
+ },
515
+ ];
516
+ if (method === 'messaging.snapshot') {
517
+ return [...common, {
518
+ id: MAX_REQUEST_ID,
519
+ error: {
520
+ code: SNAPSHOT_UNAVAILABLE_CODE,
521
+ message: SNAPSHOT_UNAVAILABLE_MESSAGE,
522
+ data: { reason: longest(SNAPSHOT_UNAVAILABLE_REASONS) },
523
+ },
524
+ }];
525
+ }
526
+ if (method === 'host.messaging.deliver') {
527
+ return [{
528
+ id: MAX_REQUEST_ID,
529
+ error: {
530
+ code: DELIVERY_REJECTED_CODE,
531
+ message: DELIVERY_REJECTED_MESSAGE,
532
+ data: { reason: longest(DELIVERY_REJECT_REASONS) },
533
+ },
534
+ }];
535
+ }
536
+ return common;
537
+ }
538
+ function errorProof(method) {
539
+ const envelopes = [...standardErrorEnvelopes(), ...applicationErrorEnvelopes(method)];
540
+ const maximum = envelopes.reduce((current, candidate) => byteLength({ jsonrpc: '2.0', ...candidate }) >
541
+ byteLength({ jsonrpc: '2.0', ...current }) ? candidate : current);
542
+ return structuralProof(() => ({ jsonrpc: '2.0', ...maximum }), () => [{
543
+ leaf: 'requestId',
544
+ frame: {
545
+ jsonrpc: '2.0',
546
+ id: 'a'.repeat(REQUEST_ID_MAX_LENGTH + 1),
547
+ error: maximum.error,
548
+ },
549
+ }]);
550
+ }
551
+ export const MESSAGING_REQUEST_BYTE_PROOFS = Object.fromEntries([
552
+ 'messaging.send',
553
+ 'messaging.appendElements',
554
+ 'messaging.subscribe',
555
+ 'messaging.read',
556
+ 'messaging.ack',
557
+ 'messaging.snapshot',
558
+ 'streams.read',
559
+ 'host.messaging.deliver',
560
+ ].map(method => [method, requestProof(method)]));
561
+ export const MESSAGING_RESULT_BYTE_PROOFS = {
562
+ 'messaging.send': resultProof('messaging.send'),
563
+ 'messaging.appendElements': resultProof('messaging.appendElements'),
564
+ 'messaging.subscribe': resultProof('messaging.subscribe'),
565
+ 'messaging.read': assemblerBudgetProof(),
566
+ 'messaging.ack': resultProof('messaging.ack'),
567
+ 'messaging.snapshot': assemblerBudgetProof(),
568
+ 'streams.read': resultProof('streams.read'),
569
+ 'host.messaging.deliver': resultProof('host.messaging.deliver'),
570
+ };
571
+ export const MESSAGING_ERROR_BYTE_PROOFS = Object.fromEntries(Object.keys(MESSAGING_REQUEST_BYTE_PROOFS)
572
+ .map(method => [method, errorProof(method)]));
573
+ export const MESSAGING_ROW_ENCODED_BYTE_BOUNDS = Object.fromEntries(Object.keys(MESSAGING_REQUEST_BYTE_PROOFS).map(method => [
574
+ method,
575
+ {
576
+ maxEncodedRequestBytes: MESSAGING_REQUEST_BYTE_PROOFS[method].maxEncodedBytes,
577
+ maxEncodedResultBytes: MESSAGING_RESULT_BYTE_PROOFS[method].maxEncodedBytes,
578
+ maxEncodedErrorBytes: MESSAGING_ERROR_BYTE_PROOFS[method].maxEncodedBytes,
579
+ },
580
+ ]));
581
+ //# sourceMappingURL=messaging-byte-bounds.js.map