@byollm/protocol 0.1.0-alpha.85 → 0.1.0-alpha.87
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.
- package/README.md +1 -1
- package/dist/index.d.ts +34 -1
- package/dist/index.js +87 -0
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -1828,6 +1828,39 @@ declare const MAX_ENVELOPE_BYTES: number;
|
|
|
1828
1828
|
* this function is that one number answers both questions.
|
|
1829
1829
|
*/
|
|
1830
1830
|
declare function envelopeBytes(envelope: unknown): number;
|
|
1831
|
+
/**
|
|
1832
|
+
* A size somebody can act on, rounded **up** and only ever up.
|
|
1833
|
+
*
|
|
1834
|
+
* The rounding rule, in one place, because it has now been got wrong twice —
|
|
1835
|
+
* B072. `toFixed` rounds to nearest, so a message one byte over the line
|
|
1836
|
+
* printed "this message is 10.5 MB and the limit is 10.5 MB": a refusal that
|
|
1837
|
+
* reads as a contradiction, given to somebody who now has no idea what to
|
|
1838
|
+
* change.
|
|
1839
|
+
*
|
|
1840
|
+
* The relay found that, fixed it, and wrote the reasoning down beside the
|
|
1841
|
+
* fix. The SDK's refusal then rediscovered the identical bug, because it
|
|
1842
|
+
* copied the SENTENCE rather than the function — which is the same shape as
|
|
1843
|
+
* `MAX_BODY_BYTES` diverging from `MAX_ENVELOPE_BYTES`, and the same answer:
|
|
1844
|
+
* neither side holds the rule.
|
|
1845
|
+
*
|
|
1846
|
+
* Up is also the honest direction. Understating how far over a message is
|
|
1847
|
+
* sends somebody to trim a hundred bytes off something that needs to lose a
|
|
1848
|
+
* megabyte; overstating by a tenth costs them nothing.
|
|
1849
|
+
*/
|
|
1850
|
+
declare function describeBytes(bytes: number): string;
|
|
1851
|
+
/**
|
|
1852
|
+
* What a message that is too big is told, minus anything about pricing.
|
|
1853
|
+
*
|
|
1854
|
+
* Shared because both planes refuse the same thing for the same reason. What
|
|
1855
|
+
* is NOT shared is the relay's "every plan has the same ceiling" — a hosted
|
|
1856
|
+
* sentence, and meaningless to somebody self-hosting the direct lane, where
|
|
1857
|
+
* there are no plans. One rule, two audiences: the rule travels, the words
|
|
1858
|
+
* about our billing do not.
|
|
1859
|
+
*/
|
|
1860
|
+
declare function tooLargeMessage(input: {
|
|
1861
|
+
readonly bytes: number;
|
|
1862
|
+
readonly limit: number;
|
|
1863
|
+
}): string;
|
|
1831
1864
|
/** Where the bucket boundaries sit, in characters of payload text. */
|
|
1832
1865
|
declare const SIZE_CLASS_LIMITS: Readonly<{
|
|
1833
1866
|
small: 4000;
|
|
@@ -2842,4 +2875,4 @@ declare const MUST_IDS: readonly ("PAIR_ONE_USER" | "PAIR_INTERACTIVE" | "PAIR_C
|
|
|
2842
2875
|
/** Every MUST verified a particular way. */
|
|
2843
2876
|
declare function mustsVerifiedBy(kind: MustVerification): MustId[];
|
|
2844
2877
|
|
|
2845
|
-
export { ABOUT, ABOUT_SHORT, ABOUT_SHORT_LEDE, ABOUT_SHORT_TAIL, AUDIENCES, Audience, BACKENDS, BACKEND_CLASSES, BACKEND_IDS, BackendClass, BackendCost, type BackendDescriptor, type BackendId, BackendIdSchema, CLOCK_ATTRIBUTION_MS, CLOCK_SKEW_WARN_MS, Capability, CapabilityMatrix, ChatMessage, ChatPayload, ClaimRequest, ClaimResponse, ClaimedJob, ClaimedStub, DeliveredResult, ENCRYPTION_KEY_CONTEXT, ENDPOINTS, ENVELOPE_MAX_AGE_MS, ERROR_STATUS, type Endpoint, type EnvelopeContext, EnvelopeDirection, type EnvelopeFailure, FetchRequest, FetchResponse, type FloorRefusal, GRANT_CONTEXT, GRANT_MAX_AGE_MS, GRANT_SIGNED_FIELDS, GeneratePayload, type GrantClaims, GrantRef, type GrantRefusal, HeartbeatRequest, HeartbeatResponse, JOB_KINDS, JobKind, JobOutcome, JobPayload, JobRefused, JobResultCanceled, JobResultError, JobResultOk, JobState, JobStub, KindedPayload, Lease, MAX_CLOCK_SKEW_MS, MAX_ENVELOPE_BYTES, MAX_PURPOSES, MAX_SUCCESSION_CHAIN, MIN_PROTOCOL_VERSION, MUSTS, MUST_IDS, Manifest, type MatchDaemon, type MatchJob, MatchRefusal, type MatchResult, type Must, type MustEnforcer, type MustId, type MustVerification, type MustVerifiedBy, OFFER_SCOPES, OfferScope, type OpenResult, PAYLOAD_LIMITS, PROTOCOL_PREFIX, PROTOCOL_VERSION, PairPollRequest, PairPollResponse, PairRequest, PairStartRequest, PairStartResponse, type PayloadFor, PublicIdentity, Purpose, REFUSAL_MESSAGES, RESERVED_PURPOSE, RETIREMENT_WINDOW_MS, RefusalReason, ReleaseRequest, ReleaseResponse, RequestSignature, ResultDisposition, ResultProvenance, ResultRequest, ResultResponse, RunMetadata, SIZE_CLASSES, SIZE_CLASS_LIMITS, SUCCESSION_CONTEXT, SUPPORTED_PROTOCOL_VERSIONS, SealedEnvelope, SealedOutcome, type SignatureFailure, SignedGrant, SizeClass, type SpendConsent, StoredKeys, Succession, type SuccessionFailure, type SuccessionWalk, TERMINAL_STATES, UPDATE_OFFER_SINCE, UPGRADE_COMMAND, type VersionRefusal, WireError, WireErrorCode, WithheldKind, backendDescriptor, backendName, canTransition, canonicalRequest, checkDaemonFloor, checkProtocolVersion, classifyCost, compareVersions, cryptoReady, declaredVersion, effectiveOfferScope, envelopeBytes, fingerprint, generateKeys, grantStatement, isBackendId, isCloudTaggedModel, isJobKind, isLocalHost, isTerminal, keyId, kindsOf, matchAudience, mayOfferUpdate, mentionsWireField, mustsVerifiedBy, open, payloadTextLength, provenanceFor, publicIdentityOf, resolveCost, seal, signGrant, signRequest, signSiteRequest, signSuccession, signWith, singlePurposeManifest, sizeClassCeiling, sizeClassOf, successionStatement, updateOfferFor, verifyGrant, verifyLink, verifyPublicIdentity, verifyRequest, verifySiteRequest, verifyWith, walkSuccession, withoutComments };
|
|
2878
|
+
export { ABOUT, ABOUT_SHORT, ABOUT_SHORT_LEDE, ABOUT_SHORT_TAIL, AUDIENCES, Audience, BACKENDS, BACKEND_CLASSES, BACKEND_IDS, BackendClass, BackendCost, type BackendDescriptor, type BackendId, BackendIdSchema, CLOCK_ATTRIBUTION_MS, CLOCK_SKEW_WARN_MS, Capability, CapabilityMatrix, ChatMessage, ChatPayload, ClaimRequest, ClaimResponse, ClaimedJob, ClaimedStub, DeliveredResult, ENCRYPTION_KEY_CONTEXT, ENDPOINTS, ENVELOPE_MAX_AGE_MS, ERROR_STATUS, type Endpoint, type EnvelopeContext, EnvelopeDirection, type EnvelopeFailure, FetchRequest, FetchResponse, type FloorRefusal, GRANT_CONTEXT, GRANT_MAX_AGE_MS, GRANT_SIGNED_FIELDS, GeneratePayload, type GrantClaims, GrantRef, type GrantRefusal, HeartbeatRequest, HeartbeatResponse, JOB_KINDS, JobKind, JobOutcome, JobPayload, JobRefused, JobResultCanceled, JobResultError, JobResultOk, JobState, JobStub, KindedPayload, Lease, MAX_CLOCK_SKEW_MS, MAX_ENVELOPE_BYTES, MAX_PURPOSES, MAX_SUCCESSION_CHAIN, MIN_PROTOCOL_VERSION, MUSTS, MUST_IDS, Manifest, type MatchDaemon, type MatchJob, MatchRefusal, type MatchResult, type Must, type MustEnforcer, type MustId, type MustVerification, type MustVerifiedBy, OFFER_SCOPES, OfferScope, type OpenResult, PAYLOAD_LIMITS, PROTOCOL_PREFIX, PROTOCOL_VERSION, PairPollRequest, PairPollResponse, PairRequest, PairStartRequest, PairStartResponse, type PayloadFor, PublicIdentity, Purpose, REFUSAL_MESSAGES, RESERVED_PURPOSE, RETIREMENT_WINDOW_MS, RefusalReason, ReleaseRequest, ReleaseResponse, RequestSignature, ResultDisposition, ResultProvenance, ResultRequest, ResultResponse, RunMetadata, SIZE_CLASSES, SIZE_CLASS_LIMITS, SUCCESSION_CONTEXT, SUPPORTED_PROTOCOL_VERSIONS, SealedEnvelope, SealedOutcome, type SignatureFailure, SignedGrant, SizeClass, type SpendConsent, StoredKeys, Succession, type SuccessionFailure, type SuccessionWalk, TERMINAL_STATES, UPDATE_OFFER_SINCE, UPGRADE_COMMAND, type VersionRefusal, WireError, WireErrorCode, WithheldKind, backendDescriptor, backendName, canTransition, canonicalRequest, checkDaemonFloor, checkProtocolVersion, classifyCost, compareVersions, cryptoReady, declaredVersion, describeBytes, effectiveOfferScope, envelopeBytes, fingerprint, generateKeys, grantStatement, isBackendId, isCloudTaggedModel, isJobKind, isLocalHost, isTerminal, keyId, kindsOf, matchAudience, mayOfferUpdate, mentionsWireField, mustsVerifiedBy, open, payloadTextLength, provenanceFor, publicIdentityOf, resolveCost, seal, signGrant, signRequest, signSiteRequest, signSuccession, signWith, singlePurposeManifest, sizeClassCeiling, sizeClassOf, successionStatement, tooLargeMessage, updateOfferFor, verifyGrant, verifyLink, verifyPublicIdentity, verifyRequest, verifySiteRequest, verifyWith, walkSuccession, withoutComments };
|
package/dist/index.js
CHANGED
|
@@ -632,6 +632,83 @@ function verifyGrant(input) {
|
|
|
632
632
|
) ? null : "bad-signature";
|
|
633
633
|
}
|
|
634
634
|
|
|
635
|
+
// src/json-size.ts
|
|
636
|
+
function jsonLength(value) {
|
|
637
|
+
try {
|
|
638
|
+
return count(value, /* @__PURE__ */ new Set());
|
|
639
|
+
} catch {
|
|
640
|
+
return void 0;
|
|
641
|
+
}
|
|
642
|
+
}
|
|
643
|
+
var OutOfDomain = class extends Error {
|
|
644
|
+
};
|
|
645
|
+
function bail() {
|
|
646
|
+
throw new OutOfDomain("not a JSON value");
|
|
647
|
+
}
|
|
648
|
+
function count(value, seen) {
|
|
649
|
+
if (value === null) return 4;
|
|
650
|
+
switch (typeof value) {
|
|
651
|
+
case "boolean":
|
|
652
|
+
return value ? 4 : 5;
|
|
653
|
+
// true / false
|
|
654
|
+
case "number":
|
|
655
|
+
return Number.isFinite(value) ? String(value).length : 4;
|
|
656
|
+
case "string":
|
|
657
|
+
return stringLength(value);
|
|
658
|
+
case "object":
|
|
659
|
+
break;
|
|
660
|
+
default:
|
|
661
|
+
return bail();
|
|
662
|
+
}
|
|
663
|
+
const object = value;
|
|
664
|
+
if (seen.has(object)) return bail();
|
|
665
|
+
seen.add(object);
|
|
666
|
+
try {
|
|
667
|
+
if (Array.isArray(object)) {
|
|
668
|
+
let total2 = 2 + Math.max(0, object.length - 1);
|
|
669
|
+
for (const element of object) {
|
|
670
|
+
total2 += element === void 0 || typeof element === "function" ? 4 : count(element, seen);
|
|
671
|
+
}
|
|
672
|
+
return total2;
|
|
673
|
+
}
|
|
674
|
+
if ("toJSON" in object) return bail();
|
|
675
|
+
const proto = Object.getPrototypeOf(object);
|
|
676
|
+
if (proto !== Object.prototype) return bail();
|
|
677
|
+
let total = 2;
|
|
678
|
+
let first = true;
|
|
679
|
+
for (const [key, entry] of Object.entries(object)) {
|
|
680
|
+
if (entry === void 0 || typeof entry === "function") continue;
|
|
681
|
+
total += (first ? 0 : 1) + stringLength(key) + 1 + count(entry, seen);
|
|
682
|
+
first = false;
|
|
683
|
+
}
|
|
684
|
+
return total;
|
|
685
|
+
} finally {
|
|
686
|
+
seen.delete(object);
|
|
687
|
+
}
|
|
688
|
+
}
|
|
689
|
+
function stringLength(text) {
|
|
690
|
+
let total = 2;
|
|
691
|
+
for (let index = 0; index < text.length; index += 1) {
|
|
692
|
+
const code = text.charCodeAt(index);
|
|
693
|
+
if (code === 34 || code === 92) {
|
|
694
|
+
total += 2;
|
|
695
|
+
} else if (code < 32) {
|
|
696
|
+
total += code === 8 || code === 9 || code === 10 || code === 12 || code === 13 ? 2 : 6;
|
|
697
|
+
} else if (code >= 55296 && code <= 57343) {
|
|
698
|
+
const paired = code <= 56319 && index + 1 < text.length && text.charCodeAt(index + 1) >= 56320 && text.charCodeAt(index + 1) <= 57343;
|
|
699
|
+
if (paired) {
|
|
700
|
+
total += 2;
|
|
701
|
+
index += 1;
|
|
702
|
+
} else {
|
|
703
|
+
total += 6;
|
|
704
|
+
}
|
|
705
|
+
} else {
|
|
706
|
+
total += 1;
|
|
707
|
+
}
|
|
708
|
+
}
|
|
709
|
+
return total;
|
|
710
|
+
}
|
|
711
|
+
|
|
635
712
|
// src/kinds.ts
|
|
636
713
|
import { z as z6 } from "zod";
|
|
637
714
|
var PAYLOAD_LIMITS = Object.freeze({
|
|
@@ -902,9 +979,17 @@ var SizeClass = z7.enum(["small", "medium", "large", "unbounded"]);
|
|
|
902
979
|
var SIZE_CLASSES = Object.freeze(SizeClass.options);
|
|
903
980
|
var MAX_ENVELOPE_BYTES = 10 * 1024 * 1024;
|
|
904
981
|
function envelopeBytes(envelope) {
|
|
982
|
+
const counted = jsonLength(envelope);
|
|
983
|
+
if (counted !== void 0) return counted;
|
|
905
984
|
const serialised = JSON.stringify(envelope);
|
|
906
985
|
return serialised === void 0 ? 0 : serialised.length;
|
|
907
986
|
}
|
|
987
|
+
function describeBytes(bytes) {
|
|
988
|
+
return `${(Math.ceil(bytes / (1024 * 1024) * 10) / 10).toFixed(1)} MB`;
|
|
989
|
+
}
|
|
990
|
+
function tooLargeMessage(input) {
|
|
991
|
+
return `this message is ${describeBytes(input.bytes)} and the limit is ${describeBytes(input.limit)} \u2014 it is a limit on one message rather than on how many you send. Split the work into smaller jobs and send them separately.`;
|
|
992
|
+
}
|
|
908
993
|
var SIZE_CLASS_LIMITS = Object.freeze({
|
|
909
994
|
small: 4e3,
|
|
910
995
|
medium: 64e3,
|
|
@@ -2627,6 +2712,7 @@ export {
|
|
|
2627
2712
|
compareVersions,
|
|
2628
2713
|
cryptoReady,
|
|
2629
2714
|
declaredVersion,
|
|
2715
|
+
describeBytes,
|
|
2630
2716
|
effectiveOfferScope,
|
|
2631
2717
|
envelopeBytes,
|
|
2632
2718
|
fingerprint,
|
|
@@ -2658,6 +2744,7 @@ export {
|
|
|
2658
2744
|
sizeClassCeiling,
|
|
2659
2745
|
sizeClassOf,
|
|
2660
2746
|
successionStatement,
|
|
2747
|
+
tooLargeMessage,
|
|
2661
2748
|
updateOfferFor,
|
|
2662
2749
|
verifyGrant,
|
|
2663
2750
|
verifyLink,
|