@avow-finance/spec 0.0.0-stage → 0.2.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 (179) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +119 -2
  3. package/dist/agent-connect.d.ts +90 -0
  4. package/dist/agent-connect.d.ts.map +1 -0
  5. package/dist/agent-connect.js +102 -0
  6. package/dist/agent-connect.js.map +1 -0
  7. package/dist/agent-session.d.ts +791 -0
  8. package/dist/agent-session.d.ts.map +1 -0
  9. package/dist/agent-session.js +176 -0
  10. package/dist/agent-session.js.map +1 -0
  11. package/dist/ap2.d.ts +79 -0
  12. package/dist/ap2.d.ts.map +1 -0
  13. package/dist/ap2.js +151 -0
  14. package/dist/ap2.js.map +1 -0
  15. package/dist/api-request.d.ts +144 -0
  16. package/dist/api-request.d.ts.map +1 -0
  17. package/dist/api-request.js +246 -0
  18. package/dist/api-request.js.map +1 -0
  19. package/dist/api.d.ts +288 -0
  20. package/dist/api.d.ts.map +1 -0
  21. package/dist/api.js +332 -0
  22. package/dist/api.js.map +1 -0
  23. package/dist/canonical.d.ts +22 -0
  24. package/dist/canonical.d.ts.map +1 -0
  25. package/dist/canonical.js +66 -0
  26. package/dist/canonical.js.map +1 -0
  27. package/dist/commitment-card.d.ts +78 -0
  28. package/dist/commitment-card.d.ts.map +1 -0
  29. package/dist/commitment-card.js +224 -0
  30. package/dist/commitment-card.js.map +1 -0
  31. package/dist/commitment.d.ts +185 -0
  32. package/dist/commitment.d.ts.map +1 -0
  33. package/dist/commitment.js +148 -0
  34. package/dist/commitment.js.map +1 -0
  35. package/dist/compute-offers.d.ts +128 -0
  36. package/dist/compute-offers.d.ts.map +1 -0
  37. package/dist/compute-offers.js +111 -0
  38. package/dist/compute-offers.js.map +1 -0
  39. package/dist/contest.d.ts +88 -0
  40. package/dist/contest.d.ts.map +1 -0
  41. package/dist/contest.js +131 -0
  42. package/dist/contest.js.map +1 -0
  43. package/dist/demo.d.ts +69 -0
  44. package/dist/demo.d.ts.map +1 -0
  45. package/dist/demo.js +152 -0
  46. package/dist/demo.js.map +1 -0
  47. package/dist/dependencies.d.ts +308 -0
  48. package/dist/dependencies.d.ts.map +1 -0
  49. package/dist/dependencies.js +133 -0
  50. package/dist/dependencies.js.map +1 -0
  51. package/dist/eip712.d.ts +1569 -0
  52. package/dist/eip712.d.ts.map +1 -0
  53. package/dist/eip712.js +550 -0
  54. package/dist/eip712.js.map +1 -0
  55. package/dist/elided-terms.d.ts +37 -0
  56. package/dist/elided-terms.d.ts.map +1 -0
  57. package/dist/elided-terms.js +48 -0
  58. package/dist/elided-terms.js.map +1 -0
  59. package/dist/erc8183.d.ts +78 -0
  60. package/dist/erc8183.d.ts.map +1 -0
  61. package/dist/erc8183.js +88 -0
  62. package/dist/erc8183.js.map +1 -0
  63. package/dist/facts.d.ts +70 -0
  64. package/dist/facts.d.ts.map +1 -0
  65. package/dist/facts.js +33 -0
  66. package/dist/facts.js.map +1 -0
  67. package/dist/gpu-reservation.d.ts +79 -0
  68. package/dist/gpu-reservation.d.ts.map +1 -0
  69. package/dist/gpu-reservation.js +135 -0
  70. package/dist/gpu-reservation.js.map +1 -0
  71. package/dist/index.d.ts +49 -0
  72. package/dist/index.d.ts.map +1 -0
  73. package/dist/index.js +49 -0
  74. package/dist/index.js.map +1 -0
  75. package/dist/job-session.d.ts +981 -0
  76. package/dist/job-session.d.ts.map +1 -0
  77. package/dist/job-session.js +170 -0
  78. package/dist/job-session.js.map +1 -0
  79. package/dist/job-verification.d.ts +244 -0
  80. package/dist/job-verification.d.ts.map +1 -0
  81. package/dist/job-verification.js +89 -0
  82. package/dist/job-verification.js.map +1 -0
  83. package/dist/job-wording.d.ts +48 -0
  84. package/dist/job-wording.d.ts.map +1 -0
  85. package/dist/job-wording.js +134 -0
  86. package/dist/job-wording.js.map +1 -0
  87. package/dist/job.d.ts +117 -0
  88. package/dist/job.d.ts.map +1 -0
  89. package/dist/job.js +166 -0
  90. package/dist/job.js.map +1 -0
  91. package/dist/json-fields.d.ts +13 -0
  92. package/dist/json-fields.d.ts.map +1 -0
  93. package/dist/json-fields.js +30 -0
  94. package/dist/json-fields.js.map +1 -0
  95. package/dist/keychain.d.ts +51 -0
  96. package/dist/keychain.d.ts.map +1 -0
  97. package/dist/keychain.js +133 -0
  98. package/dist/keychain.js.map +1 -0
  99. package/dist/mailbox.d.ts +1650 -0
  100. package/dist/mailbox.d.ts.map +1 -0
  101. package/dist/mailbox.js +87 -0
  102. package/dist/mailbox.js.map +1 -0
  103. package/dist/mandate.d.ts +53 -0
  104. package/dist/mandate.d.ts.map +1 -0
  105. package/dist/mandate.js +97 -0
  106. package/dist/mandate.js.map +1 -0
  107. package/dist/networks.d.ts +18 -0
  108. package/dist/networks.d.ts.map +1 -0
  109. package/dist/networks.js +24 -0
  110. package/dist/networks.js.map +1 -0
  111. package/dist/profiles.d.ts +31 -0
  112. package/dist/profiles.d.ts.map +1 -0
  113. package/dist/profiles.js +33 -0
  114. package/dist/profiles.js.map +1 -0
  115. package/dist/rail.d.ts +48 -0
  116. package/dist/rail.d.ts.map +1 -0
  117. package/dist/rail.js +28 -0
  118. package/dist/rail.js.map +1 -0
  119. package/dist/reasons.d.ts +173 -0
  120. package/dist/reasons.d.ts.map +1 -0
  121. package/dist/reasons.js +174 -0
  122. package/dist/reasons.js.map +1 -0
  123. package/dist/reference-link.d.ts +23 -0
  124. package/dist/reference-link.d.ts.map +1 -0
  125. package/dist/reference-link.js +56 -0
  126. package/dist/reference-link.js.map +1 -0
  127. package/dist/references.d.ts +125 -0
  128. package/dist/references.d.ts.map +1 -0
  129. package/dist/references.js +108 -0
  130. package/dist/references.js.map +1 -0
  131. package/dist/replay.d.ts +30 -0
  132. package/dist/replay.d.ts.map +1 -0
  133. package/dist/replay.js +27 -0
  134. package/dist/replay.js.map +1 -0
  135. package/dist/sandbox-registration.d.ts +200 -0
  136. package/dist/sandbox-registration.d.ts.map +1 -0
  137. package/dist/sandbox-registration.js +172 -0
  138. package/dist/sandbox-registration.js.map +1 -0
  139. package/dist/sandbox.d.ts +3478 -0
  140. package/dist/sandbox.d.ts.map +1 -0
  141. package/dist/sandbox.js +316 -0
  142. package/dist/sandbox.js.map +1 -0
  143. package/dist/session-fields.d.ts +203 -0
  144. package/dist/session-fields.d.ts.map +1 -0
  145. package/dist/session-fields.js +43 -0
  146. package/dist/session-fields.js.map +1 -0
  147. package/dist/supplier-adapter.d.ts +65 -0
  148. package/dist/supplier-adapter.d.ts.map +1 -0
  149. package/dist/supplier-adapter.js +91 -0
  150. package/dist/supplier-adapter.js.map +1 -0
  151. package/dist/terms-v1.d.ts +74 -0
  152. package/dist/terms-v1.d.ts.map +1 -0
  153. package/dist/terms-v1.js +156 -0
  154. package/dist/terms-v1.js.map +1 -0
  155. package/dist/terms.d.ts +341 -0
  156. package/dist/terms.d.ts.map +1 -0
  157. package/dist/terms.js +715 -0
  158. package/dist/terms.js.map +1 -0
  159. package/dist/test-customer.d.ts +1525 -0
  160. package/dist/test-customer.d.ts.map +1 -0
  161. package/dist/test-customer.js +260 -0
  162. package/dist/test-customer.js.map +1 -0
  163. package/dist/types.d.ts +272 -0
  164. package/dist/types.d.ts.map +1 -0
  165. package/dist/types.js +32 -0
  166. package/dist/types.js.map +1 -0
  167. package/dist/version.d.ts +51 -0
  168. package/dist/version.d.ts.map +1 -0
  169. package/dist/version.js +66 -0
  170. package/dist/version.js.map +1 -0
  171. package/dist/wire.d.ts +2698 -0
  172. package/dist/wire.d.ts.map +1 -0
  173. package/dist/wire.js +678 -0
  174. package/dist/wire.js.map +1 -0
  175. package/package.json +37 -3
  176. package/vectors/api-request-v1.json +53 -0
  177. package/vectors/contest-statement-v1.json +42 -0
  178. package/vectors/terms-v2.json +398 -0
  179. package/vectors/terms-v3.json +2103 -0
@@ -0,0 +1,134 @@
1
+ import { describeReason } from './reasons.js';
2
+ import { formatUsd } from './sandbox.js';
3
+ import { TEST_CUSTOMER_LABEL } from './test-customer.js';
4
+ /**
5
+ * The words a job's terminal and its screen both say, so the two never tell the story
6
+ * differently. Every statement matches a check that ran, and a check's statement names the block
7
+ * it read and says nothing beyond it.
8
+ */
9
+ /**
10
+ * The decisive moment. The customer made its reserve, the developer's code checked it, and the
11
+ * customer accepted only after it verified the compute booking. Work waits for the job's start,
12
+ * when the customer's free cancellation ends.
13
+ */
14
+ export const DECISIVE_SENTENCE = "Your code verified the customer's commitment and checked its reserve. The customer accepted after verifying your compute booking. Work starts when the customer's free cancellation ends.";
15
+ /**
16
+ * The decisive sentence when the lock already showed the acceptance an earlier attempt sent. This
17
+ * run read the commitment, its reserve and the compute booking again, and it didn't ask Avow for
18
+ * its authorization again, so the sentence says the acceptance rests on the earlier attempt.
19
+ */
20
+ export const RECOVERED_DECISIVE_SENTENCE = "Your code verified the customer's commitment and checked its reserve. The acceptance on the customer's lock came from an earlier attempt's checks. The customer accepted after verifying your compute booking. Work starts when the customer's free cancellation ends.";
21
+ /** What a compute booking proves, and what it doesn't. */
22
+ export const COMPUTE_PROVES = "Your compute booking proves a required input is committed. It doesn't prove your agent will finish the job.";
23
+ /** The two reserves stay apart. */
24
+ export const SEPARATE_RESERVES = "The customer's reserve backs the job, and your reserve backs the compute. Naming a booking moves no money and compensates nobody automatically. Nothing backs your own delivery promise with money in v1.";
25
+ /** What a check of a booking relied on proves. */
26
+ export const CHECK_BOUNDARY = 'Each check proves the state at the block it read. Nothing makes the steps atomic, and nothing in Avow stops your business cancelling its compute after the customer accepted.';
27
+ /** What holds when the compute goes away after the customer accepted. */
28
+ export const AFTER_ACCEPTANCE = "If your compute is cancelled or fails after the customer accepted, the job commitment stands, and your business still answers to the customer under the job's own terms. It finds other capacity or releases the job with the reason supplier failed.";
29
+ /** What's simulated and what's real, said in one plain line wherever the work appears. */
30
+ export const SIMULATED_LINE = 'The GPUs and the training are simulated. Every commitment, reserve, check and payment is a real testnet operation.';
31
+ /** The first challenge, which the prescribed edit answers. */
32
+ export const REFUSAL_CHALLENGE = 'Remove the compute booking. Would the customer still accept?';
33
+ /** The file and the flag beside the one line that books the compute. */
34
+ export const REFUSAL_EDIT = { file: 'service.ts', flag: 'bookCompute' };
35
+ /** How to make the prescribed refusal. */
36
+ export const REFUSAL_INSTRUCTION = `Delete the marked line in ${REFUSAL_EDIT.file} that books the compute, or set ${REFUSAL_EDIT.flag} to false beside it, then run npm run job again.`;
37
+ /** Each charge kind as the job's words name it, with its cap. */
38
+ const CHARGE_WORDS = {
39
+ lateCancellation: (cap) => `a late cancellation after work has started, up to ${cap}`,
40
+ noShow: (cap) => `a no-show, up to ${cap}, if the customer doesn't hand over the work's inputs in time`,
41
+ };
42
+ /**
43
+ * What the customer's reserve backs. It backs only what the job's terms let the developer charge
44
+ * if the customer walks away, and never the price, which arrives as its own transfer.
45
+ */
46
+ export function reserveLine(charges) {
47
+ const named = charges.map((c) => CHARGE_WORDS[c.kind](formatUsd(c.amount)));
48
+ return `The customer's reserve backs what the job's terms let you charge if the customer walks away. That's ${named.join(', or ')}. The job's price arrives as a separate transfer on delivery, and the reserve doesn't secure it.`;
49
+ }
50
+ /** A block as a statement names it. */
51
+ export const atBlock = (block) => `at block ${block.number}`;
52
+ const CUSTOMER_WHO = {
53
+ customer: 'The customer refused your quote',
54
+ supplier: "Your business didn't accept the customer's reserve in time",
55
+ avow: "Avow refused to approve the customer's reserve",
56
+ relay: "Avow's relay refused to send the customer's reserve",
57
+ lock: "The customer's lock refused its reserve",
58
+ keychain: "The customer's keychain refused its reserve",
59
+ unknown: "The customer's reserve never landed",
60
+ };
61
+ const SUPPLIER_WHO = {
62
+ service: "Your code refused the customer's commitment",
63
+ avow: "Avow didn't authorize the customer's commitment for your business",
64
+ relay: "Avow's relay refused to send your acceptance",
65
+ lock: "The customer's lock refused your acceptance",
66
+ };
67
+ const RELEASED = {
68
+ consent: "by its supplier's consent",
69
+ free_cancellation: 'by free cancellation',
70
+ release_date: 'at its release date',
71
+ unaccepted: 'in full, since nobody accepted it',
72
+ };
73
+ function released(release) {
74
+ if (release.way !== 'consent')
75
+ return RELEASED[release.way];
76
+ const reason = release.reason === 'kept' ? 'kept' : 'supplier failed';
77
+ return `${RELEASED.consent}, which gave the reason ${reason}`;
78
+ }
79
+ const CHARGE_NAMES_PLAIN = {
80
+ lateCancellation: 'late-cancellation',
81
+ noShow: 'no-show',
82
+ };
83
+ const PAUSED = {
84
+ contested: 'The customer contested the charge.',
85
+ referred: "Avow's records didn't support the report, so Avow referred it.",
86
+ unanswered: "Avow didn't answer the report before its deadline.",
87
+ };
88
+ const refusalTail = (code, block) => `${describeReason(code)}${block ? `, ${atBlock(block)}` : ''}.`;
89
+ /** The one sentence the terminal prints and the screen shows for a job's event. */
90
+ export function jobEventSentence(event) {
91
+ switch (event.type) {
92
+ case 'job_order_received':
93
+ return `${TEST_CUSTOMER_LABEL} offered a job for ${formatUsd(event.price)}. Before it accepts, it needs to verify the compute your quote relies on.`;
94
+ case 'job_compute_secured':
95
+ return `Your agent booked compute from ${event.supplier}, which accepted it. Your business reserved ${formatUsd(event.amount)} for it in its own lock.`;
96
+ case 'job_quote_sent':
97
+ return event.compute
98
+ ? 'Your code quoted the job, naming your compute booking.'
99
+ : 'Your code quoted the job without naming any compute booking.';
100
+ case 'job_customer_verifying':
101
+ return 'The customer is verifying the compute booking your quote names.';
102
+ case 'job_customer_verified': {
103
+ const blocks = [...new Set(event.checks.map((c) => c.block.number))];
104
+ return `${TEST_CUSTOMER_LABEL} says it verified your compute booking at block ${blocks.join(' and ')}.`;
105
+ }
106
+ case 'job_customer_refused':
107
+ return `${CUSTOMER_WHO[event.refusal.layer]}. ${refusalTail(event.refusal.code, event.refusal.block)}`;
108
+ case 'job_commitment_checked':
109
+ return event.acceptedIn === null ? RECOVERED_DECISIVE_SENTENCE : DECISIVE_SENTENCE;
110
+ case 'job_commitment_refused':
111
+ return `${SUPPLIER_WHO[event.layer]}. ${refusalTail(event.code, event.block)}`;
112
+ case 'job_work_started':
113
+ return "Work started, and the customer's free cancellation has ended.";
114
+ case 'job_delivered':
115
+ return 'Your code reported delivery to the customer and handed over a placeholder result, since the training is simulated.';
116
+ case 'job_paid':
117
+ return "The customer paid the job's price by a transfer whose memo names the job commitment. Anyone can check it on chain as a payment reference.";
118
+ case 'job_customer_cancelled':
119
+ return "The customer told your code it cancelled after work started, and your code stopped the work. Avow confirms a charge for that only from its own record of the customer's signed cancellation.";
120
+ case 'job_charge_reported':
121
+ return `Your code reported a ${formatUsd(event.amount)} ${CHARGE_NAMES_PLAIN[event.kind]} charge on the customer's reserve, signed by your supplier signing key. Nothing has moved yet.`;
122
+ case 'job_charge_confirmed':
123
+ return `Avow confirmed the ${formatUsd(event.amount)} charge against its record of the cancellation. The customer can still contest it, and it becomes payable once that window closes.`;
124
+ case 'job_charge_paused':
125
+ return `${PAUSED[event.cause]} The charge waits for a ruling, and nothing pays until one is posted.`;
126
+ case 'job_charge_paid':
127
+ return `The contest window closed with no contest, and the customer's lock paid your business ${formatUsd(event.amount)}.`;
128
+ case 'job_reserve_released':
129
+ return event.role === 'job'
130
+ ? `The customer's reserve came back to it ${released(event.release)}.`
131
+ : `Your compute reserve came back to your business ${released(event.release)}.`;
132
+ }
133
+ }
134
+ //# sourceMappingURL=job-wording.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"job-wording.js","sourceRoot":"","sources":["../src/job-wording.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,cAAc,EAAmB,MAAM,cAAc,CAAA;AAC9D,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AACxC,OAAO,EAA6B,mBAAmB,EAAE,MAAM,oBAAoB,CAAA;AAEnF;;;;GAIG;AAEH;;;;GAIG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAC5B,2LAA2L,CAAA;AAE7L;;;;GAIG;AACH,MAAM,CAAC,MAAM,2BAA2B,GACtC,wQAAwQ,CAAA;AAE1Q,0DAA0D;AAC1D,MAAM,CAAC,MAAM,cAAc,GACzB,6GAA6G,CAAA;AAE/G,mCAAmC;AACnC,MAAM,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ACrB,OAAO,+DAA+D,CAAA;QACxE,KAAK,eAAe;YAClB,OAAO,oHAAoH,CAAA;QAC7H,KAAK,UAAU;YACb,OAAO,2IAA2I,CAAA;QACpJ,KAAK,wBAAwB;YAC3B,OAAO,8LAA8L,CAAA;QACvM,KAAK,qBAAqB;YACxB,OAAO,wBAAwB,SAAS,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,kBAAkB,CAAC,KAAK,CAAC,IAAI,CAAC,gGAAgG,CAAA;QAC1L,KAAK,sBAAsB;YACzB,OAAO,sBAAsB,SAAS,CAAC,KAAK,CAAC,MAAM,CAAC,oIAAoI,CAAA;QAC1L,KAAK,mBAAmB;YACtB,OAAO,GAAG,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,uEAAuE,CAAA;QACtG,KAAK,iBAAiB;YACpB,OAAO,yFAAyF,SAAS,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAA;QAC5H,KAAK,sBAAsB;YACzB,OAAO,KAAK,CAAC,IAAI,KAAK,KAAK;gBACzB,CAAC,CAAC,0CAA0C,QAAQ,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG;gBACtE,CAAC,CAAC,mDAAmD,QAAQ,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAA;IACrF,CAAC;AACH,CAAC"}
package/dist/job.d.ts ADDED
@@ -0,0 +1,117 @@
1
+ import type { Address } from 'viem';
2
+ import type { Dependencies } from './dependencies.js';
3
+ import { type GpuSubject } from './gpu-reservation.js';
4
+ import type { ReasonCode } from './reasons.js';
5
+ import { type ChainedTermsOf, type Currency, type DependencyChecksOf, type TermsOf } from './types.js';
6
+ /**
7
+ * A job, a piece of work a supplier does for a customer by a deadline, on GPU capacity it booked
8
+ * from someone else. Its meaning is fixed, and a change of meaning would be `job/2`.
9
+ *
10
+ * A job always relies on a booking of that capacity, so its terms are version 3 and name it in
11
+ * their dependencies section. Version 2 terms under this template are refused as
12
+ * `dependency.required`, by the customer and by Avow alike.
13
+ *
14
+ * The customer's reserve backs only what the customer owes if it walks away, which the lock's two
15
+ * charge kinds express. A late cancellation is chargeable once work has started, and a no-show
16
+ * once the customer hasn't handed over the work's inputs by the end of the grace period. The job's
17
+ * price is the consideration, which the lock never reads. It arrives as a separate transfer on
18
+ * delivery, and the reserve doesn't secure it.
19
+ */
20
+ export declare const JOB: 'job/1';
21
+ /**
22
+ * The mandate category every job falls under, which its terms agreement and reserve request name.
23
+ * A customer's mandate allows jobs by naming it, and job terms under any other category are refused
24
+ * as `terms.category_mismatch`.
25
+ */
26
+ export declare const JOB_CATEGORY: 'compute-job';
27
+ /** The longest `work.kind` a job names. */
28
+ export declare const JOB_KIND_MAX = 64;
29
+ /** The longest `work.summary` a job names. */
30
+ export declare const JOB_SUMMARY_MAX = 280;
31
+ /** What a job promises: the work, the GPU capacity it runs on, and when it runs. */
32
+ export interface JobSubject {
33
+ /** The work, with a short name such as `fine-tuning` and one sentence on what gets done. */
34
+ work: {
35
+ kind: string;
36
+ summary: string;
37
+ };
38
+ /** The GPU capacity the work runs on, which a booking the job relies on has to hold. */
39
+ compute: {
40
+ gpu: string;
41
+ count: number;
42
+ region: string;
43
+ };
44
+ /** When work starts. The customer's free cancellation ends here, and its inputs are due. */
45
+ startsAt: bigint;
46
+ /** When the result is delivered by. The booking relied on has to hold the capacity until then. */
47
+ deliverBy: bigint;
48
+ }
49
+ /** Job terms as version 2 shapes them, the form a customer proposes before compute is named. */
50
+ export type JobTerms = TermsOf<JobSubject, typeof JOB>;
51
+ /**
52
+ * Version 3 job terms, which name the booking of the compute the job runs on. The customer checks
53
+ * that booking itself, so a job's terms always say `buyer` checks. The `avow` setting promises to
54
+ * hide the booking from the buyer, which a job can't keep, since the customer gets its terms in
55
+ * full and a link to verify a job shows the booking.
56
+ */
57
+ export type ChainedJobTerms = Omit<ChainedTermsOf<JobSubject, typeof JOB>, 'dependencyCheck'> & {
58
+ dependencyCheck: JobDependencyCheck;
59
+ };
60
+ /** Who checks a job's compute, the one setting `DEPENDENCY_CHECKS_ALLOWED` gives a job. */
61
+ export type JobDependencyCheck = DependencyChecksOf<typeof JOB>;
62
+ /** What a job states, in micros and unix seconds, before the template builds its terms. */
63
+ export interface JobInput {
64
+ work: JobSubject['work'];
65
+ compute: JobSubject['compute'];
66
+ currency: Currency;
67
+ startsAt: bigint;
68
+ deliverBy: bigint;
69
+ /** The last moment the supplier can accept the customer's reserve, the start when left out. */
70
+ acceptBy?: bigint;
71
+ /** The job's price, paid by a separate transfer on delivery. The reserve doesn't secure it. */
72
+ price: bigint;
73
+ /** The most the supplier can charge when the customer cancels after work has started. */
74
+ lateCancellation: bigint;
75
+ /** The most the supplier can charge when the customer doesn't hand over the work's inputs. */
76
+ noShow: bigint;
77
+ /** How long after the start the customer can still hand over the inputs before it's a no-show. */
78
+ gracePeriod: bigint;
79
+ chargeDeadline: bigint;
80
+ contestWindow: bigint;
81
+ releaseDate: bigint;
82
+ arbiter: Address;
83
+ day90SupplierShareBps: number;
84
+ }
85
+ /**
86
+ * Builds job terms in version 2's shape, which `chainedTerms` turns into version 3 terms naming
87
+ * the compute booking. Free cancellation ends when work starts, a late cancellation is chargeable
88
+ * from then, and a no-show once the grace period after the start has passed. A charge set to zero
89
+ * is left out, and the reserve is the largest charge.
90
+ */
91
+ export declare function jobTerms(input: JobInput): JobTerms;
92
+ /** Version 3 job terms that rely on the compute bookings given, which the customer checks. */
93
+ export declare function chainedJobTerms(terms: JobTerms, dependencies: Dependencies): ChainedJobTerms;
94
+ /**
95
+ * What's wrong with a job's subject on its own, or null when nothing is. The work has a kind and a
96
+ * summary of bounded length, the compute names a GPU, a positive count and a region, and the start
97
+ * and deadline are whole numbers (`terms.template_invalid`). Work starts before its deadline
98
+ * (`terms.deadlines_out_of_order`). A subject of any other shape is refused here, so nothing that
99
+ * reads it after this throws.
100
+ */
101
+ export declare function jobSubjectProblem(s: JobSubject): ReasonCode | null;
102
+ /**
103
+ * The template's own rules, which a reader checks after the core's. The subject passes
104
+ * `jobSubjectProblem` and the consideration is one fixed price above zero. Free cancellation ends
105
+ * exactly when work starts, the supplier accepts by then, and the deadline falls by the charge
106
+ * deadline. A late cancellation is chargeable from the start, and a no-show from the start or
107
+ * later.
108
+ */
109
+ export declare function validateJob(t: Pick<JobTerms, 'subject' | 'consideration' | 'remedies'>): ReasonCode | null;
110
+ /**
111
+ * Whether a job fits inside a GPU reservation it relies on. The reservation holds the same GPU in
112
+ * the same region, at least as many of them, from the job's start until its deadline. Each pair is
113
+ * judged on its own, so two jobs that each fit inside the same reservation both pass. A subject
114
+ * either template refuses fits nowhere.
115
+ */
116
+ export declare function jobFitsReservation(job: JobSubject, reservation: GpuSubject): boolean;
117
+ //# sourceMappingURL=job.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"job.d.ts","sourceRoot":"","sources":["../src/job.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAA;AACnC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AACrD,OAAO,EAAE,KAAK,UAAU,EAAqB,MAAM,sBAAsB,CAAA;AACzE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AAC9C,OAAO,EAGL,KAAK,cAAc,EACnB,KAAK,QAAQ,EAEb,KAAK,kBAAkB,EAGvB,KAAK,OAAO,EACb,MAAM,YAAY,CAAA;AAEnB;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,GAAG,EAAG,OAAgB,CAAA;AAEnC;;;;GAIG;AACH,eAAO,MAAM,YAAY,EAAG,aAAsB,CAAA;AAElD,2CAA2C;AAC3C,eAAO,MAAM,YAAY,KAAK,CAAA;AAE9B,8CAA8C;AAC9C,eAAO,MAAM,eAAe,MAAM,CAAA;AAElC,oFAAoF;AACpF,MAAM,WAAW,UAAU;IACzB,4FAA4F;IAC5F,IAAI,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAA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,wBAAgB,QAAQ,CAAC,KAAK,EAAE,QAAQ,GAAG,QAAQ,CA0ClD;AAED,8FAA8F;AAC9F,wBAAgB,eAAe,CAAC,KAAK,EAAE,QAAQ,EAAE,YAAY,EAAE,YAAY,GAAG,eAAe,CAO5F;AAKD;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,UAAU,GAAG,UAAU,GAAG,IAAI,CAmBlE;AAED;;;;;;GAMG;AACH,wBAAgB,WAAW,CACzB,CAAC,EAAE,IAAI,CAAC,QAAQ,EAAE,SAAS,GAAG,eAAe,GAAG,UAAU,CAAC,GAC1D,UAAU,GAAG,IAAI,CAmBnB;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,UAAU,EAAE,WAAW,EAAE,UAAU,GAAG,OAAO,CAWpF"}
package/dist/job.js ADDED
@@ -0,0 +1,166 @@
1
+ import { gpuSubjectProblem } from './gpu-reservation.js';
2
+ import { AMOUNT_DECIMALS, CHAINED_TERMS_VERSION, DEPENDENCY_CHECKS_ALLOWED, TERMS_VERSION, } from './types.js';
3
+ /**
4
+ * A job, a piece of work a supplier does for a customer by a deadline, on GPU capacity it booked
5
+ * from someone else. Its meaning is fixed, and a change of meaning would be `job/2`.
6
+ *
7
+ * A job always relies on a booking of that capacity, so its terms are version 3 and name it in
8
+ * their dependencies section. Version 2 terms under this template are refused as
9
+ * `dependency.required`, by the customer and by Avow alike.
10
+ *
11
+ * The customer's reserve backs only what the customer owes if it walks away, which the lock's two
12
+ * charge kinds express. A late cancellation is chargeable once work has started, and a no-show
13
+ * once the customer hasn't handed over the work's inputs by the end of the grace period. The job's
14
+ * price is the consideration, which the lock never reads. It arrives as a separate transfer on
15
+ * delivery, and the reserve doesn't secure it.
16
+ */
17
+ export const JOB = 'job/1';
18
+ /**
19
+ * The mandate category every job falls under, which its terms agreement and reserve request name.
20
+ * A customer's mandate allows jobs by naming it, and job terms under any other category are refused
21
+ * as `terms.category_mismatch`.
22
+ */
23
+ export const JOB_CATEGORY = 'compute-job';
24
+ /** The longest `work.kind` a job names. */
25
+ export const JOB_KIND_MAX = 64;
26
+ /** The longest `work.summary` a job names. */
27
+ export const JOB_SUMMARY_MAX = 280;
28
+ const [JOB_DEPENDENCY_CHECK] = DEPENDENCY_CHECKS_ALLOWED[JOB];
29
+ /**
30
+ * Builds job terms in version 2's shape, which `chainedTerms` turns into version 3 terms naming
31
+ * the compute booking. Free cancellation ends when work starts, a late cancellation is chargeable
32
+ * from then, and a no-show once the grace period after the start has passed. A charge set to zero
33
+ * is left out, and the reserve is the largest charge.
34
+ */
35
+ export function jobTerms(input) {
36
+ const charges = [];
37
+ if (input.lateCancellation > 0n) {
38
+ charges.push({
39
+ kind: 'lateCancellation',
40
+ amount: input.lateCancellation,
41
+ earliest: input.startsAt,
42
+ });
43
+ }
44
+ if (input.noShow > 0n) {
45
+ charges.push({
46
+ kind: 'noShow',
47
+ amount: input.noShow,
48
+ earliest: input.startsAt + input.gracePeriod,
49
+ });
50
+ }
51
+ const reserve = input.lateCancellation > input.noShow ? input.lateCancellation : input.noShow;
52
+ return {
53
+ version: TERMS_VERSION,
54
+ template: JOB,
55
+ currency: input.currency,
56
+ amountDecimals: AMOUNT_DECIMALS,
57
+ subject: {
58
+ work: { ...input.work },
59
+ compute: { ...input.compute },
60
+ startsAt: input.startsAt,
61
+ deliverBy: input.deliverBy,
62
+ },
63
+ consideration: { kind: 'fixed', amount: input.price },
64
+ remedies: {
65
+ acceptBy: input.acceptBy ?? input.startsAt,
66
+ freeCancelBy: input.startsAt,
67
+ charges,
68
+ chargeDeadline: input.chargeDeadline,
69
+ },
70
+ resolution: {
71
+ contestWindow: input.contestWindow,
72
+ arbiter: input.arbiter,
73
+ day90SupplierShareBps: input.day90SupplierShareBps,
74
+ },
75
+ backing: { kind: 'reserve', side: 'buyer', amount: reserve, releaseDate: input.releaseDate },
76
+ };
77
+ }
78
+ /** Version 3 job terms that rely on the compute bookings given, which the customer checks. */
79
+ export function chainedJobTerms(terms, dependencies) {
80
+ return {
81
+ ...terms,
82
+ version: CHAINED_TERMS_VERSION,
83
+ dependencyCheck: JOB_DEPENDENCY_CHECK,
84
+ dependencies,
85
+ };
86
+ }
87
+ const isText = (v, max) => typeof v === 'string' && v.length > 0 && v.length <= max;
88
+ /**
89
+ * What's wrong with a job's subject on its own, or null when nothing is. The work has a kind and a
90
+ * summary of bounded length, the compute names a GPU, a positive count and a region, and the start
91
+ * and deadline are whole numbers (`terms.template_invalid`). Work starts before its deadline
92
+ * (`terms.deadlines_out_of_order`). A subject of any other shape is refused here, so nothing that
93
+ * reads it after this throws.
94
+ */
95
+ export function jobSubjectProblem(s) {
96
+ if (typeof s !== 'object' || s === null)
97
+ return 'terms.template_invalid';
98
+ const work = s.work;
99
+ const compute = s.compute;
100
+ if (typeof work !== 'object' || work === null)
101
+ return 'terms.template_invalid';
102
+ if (typeof compute !== 'object' || compute === null)
103
+ return 'terms.template_invalid';
104
+ if (!isText(work.kind, JOB_KIND_MAX) || !isText(work.summary, JOB_SUMMARY_MAX)) {
105
+ return 'terms.template_invalid';
106
+ }
107
+ if (!isText(compute.gpu, JOB_KIND_MAX) || !isText(compute.region, JOB_KIND_MAX)) {
108
+ return 'terms.template_invalid';
109
+ }
110
+ if (!Number.isSafeInteger(compute.count) || compute.count <= 0) {
111
+ return 'terms.template_invalid';
112
+ }
113
+ if (typeof s.startsAt !== 'bigint' || typeof s.deliverBy !== 'bigint') {
114
+ return 'terms.template_invalid';
115
+ }
116
+ return s.startsAt < s.deliverBy ? null : 'terms.deadlines_out_of_order';
117
+ }
118
+ /**
119
+ * The template's own rules, which a reader checks after the core's. The subject passes
120
+ * `jobSubjectProblem` and the consideration is one fixed price above zero. Free cancellation ends
121
+ * exactly when work starts, the supplier accepts by then, and the deadline falls by the charge
122
+ * deadline. A late cancellation is chargeable from the start, and a no-show from the start or
123
+ * later.
124
+ */
125
+ export function validateJob(t) {
126
+ const { subject: s, remedies: r, consideration: c } = t;
127
+ const subject = jobSubjectProblem(s);
128
+ if (subject === 'terms.template_invalid')
129
+ return subject;
130
+ if (c.kind !== 'fixed' || c.amount <= 0n)
131
+ return 'terms.template_invalid';
132
+ if (subject)
133
+ return subject;
134
+ if (r.freeCancelBy !== s.startsAt)
135
+ return 'terms.template_invalid';
136
+ if (r.acceptBy > s.startsAt || s.deliverBy > r.chargeDeadline) {
137
+ return 'terms.deadlines_out_of_order';
138
+ }
139
+ for (const charge of r.charges) {
140
+ if (charge.kind === 'lateCancellation' && charge.earliest !== s.startsAt) {
141
+ return 'terms.template_invalid';
142
+ }
143
+ if (charge.kind === 'noShow' && charge.earliest < s.startsAt) {
144
+ return 'terms.deadlines_out_of_order';
145
+ }
146
+ }
147
+ return null;
148
+ }
149
+ /**
150
+ * Whether a job fits inside a GPU reservation it relies on. The reservation holds the same GPU in
151
+ * the same region, at least as many of them, from the job's start until its deadline. Each pair is
152
+ * judged on its own, so two jobs that each fit inside the same reservation both pass. A subject
153
+ * either template refuses fits nowhere.
154
+ */
155
+ export function jobFitsReservation(job, reservation) {
156
+ if (jobSubjectProblem(job) || gpuSubjectProblem(reservation))
157
+ return false;
158
+ const need = job.compute;
159
+ const held = reservation.resource;
160
+ return (need.gpu === held.gpu &&
161
+ need.region === held.region &&
162
+ need.count <= held.count &&
163
+ job.startsAt >= reservation.windowStart &&
164
+ job.deliverBy <= reservation.windowStart + reservation.windowDuration);
165
+ }
166
+ //# sourceMappingURL=job.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"job.js","sourceRoot":"","sources":["../src/job.ts"],"names":[],"mappings":"AAEA,OAAO,EAAmB,iBAAiB,EAAE,MAAM,sBAAsB,CAAA;AAEzE,OAAO,EACL,eAAe,EACf,qBAAqB,EAGrB,yBAAyB,EAGzB,aAAa,GAEd,MAAM,YAAY,CAAA;AAEnB;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,MAAM,GAAG,GAAG,OAAgB,CAAA;AAEnC;;;;GAIG;AACH,MAAM,CAA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AAG,WAAW,CAAC,cAAc,CACtE,CAAA;AACH,CAAC"}
@@ -0,0 +1,13 @@
1
+ import { z } from 'zod';
2
+ /** Times, durations and expiries, which signed messages carry as uint64. */
3
+ export declare const u64: z.ZodPipe<z.ZodString, z.ZodTransform<bigint, string>>;
4
+ /** Amounts and nonces. */
5
+ export declare const u256: z.ZodPipe<z.ZodString, z.ZodTransform<bigint, string>>;
6
+ export declare const address: z.ZodPipe<z.ZodString, z.ZodTransform<`0x${string}`, string>>;
7
+ export declare const bytes32: z.ZodPipe<z.ZodString, z.ZodTransform<`0x${string}`, string>>;
8
+ export declare const hexBytes: z.ZodPipe<z.ZodString, z.ZodTransform<`0x${string}`, string>>;
9
+ export declare const side: z.ZodEnum<{
10
+ buyer: "buyer";
11
+ supplier: "supplier";
12
+ }>;
13
+ //# sourceMappingURL=json-fields.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"json-fields.d.ts","sourceRoot":"","sources":["../src/json-fields.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAevB,4EAA4E;AAC5E,eAAO,MAAM,GAAG,wDAAW,CAAA;AAC3B,0BAA0B;AAC1B,eAAO,MAAM,IAAI,wDAAY,CAAA;AAC7B,eAAO,MAAM,OAAO,+DAG2B,CAAA;AAC/C,eAAO,MAAM,OAAO,+DAGuB,CAAA;AAC3C,eAAO,MAAM,QAAQ,+DAGsB,CAAA;AAC3C,eAAO,MAAM,IAAI;;;EAAgC,CAAA"}
@@ -0,0 +1,30 @@
1
+ import { z } from 'zod';
2
+ /**
3
+ * The JSON field forms every parser in this package shares. JSON has no bigint, so amounts and
4
+ * times travel as decimal strings and parse into bigints here. Hex parses to lower case, so a relay
5
+ * that changes letter case can't make two equal values compare as different, and a mixed-case
6
+ * address with a bad checksum can't make a check throw.
7
+ */
8
+ const uint = (bits) => z
9
+ .string()
10
+ .regex(/^(0|[1-9][0-9]*)$/, 'a whole number as a decimal string')
11
+ .transform((s) => BigInt(s))
12
+ .refine((v) => v < 2n ** BigInt(bits), `a whole number below 2^${bits}`);
13
+ /** Times, durations and expiries, which signed messages carry as uint64. */
14
+ export const u64 = uint(64);
15
+ /** Amounts and nonces. */
16
+ export const u256 = uint(256);
17
+ export const address = z
18
+ .string()
19
+ .regex(/^0x[0-9a-fA-F]{40}$/)
20
+ .transform((s) => s.toLowerCase());
21
+ export const bytes32 = z
22
+ .string()
23
+ .regex(/^0x[0-9a-fA-F]{64}$/)
24
+ .transform((s) => s.toLowerCase());
25
+ export const hexBytes = z
26
+ .string()
27
+ .regex(/^0x([0-9a-fA-F]{2})*$/)
28
+ .transform((s) => s.toLowerCase());
29
+ export const side = z.enum(['buyer', 'supplier']);
30
+ //# sourceMappingURL=json-fields.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"json-fields.js","sourceRoot":"","sources":["../src/json-fields.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB;;;;;GAKG;AACH,MAAM,IAAI,GAAG,CAAC,IAAY,EAAE,EAAE,CAC5B,CAAC;KACE,MAAM,EAAE;KACR,KAAK,CAAC,mBAAmB,EAAE,oCAAoC,CAAC;KAChE,SAAS,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;KAC3B,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,EAAE,IAAI,MAAM,CAAC,IAAI,CAAC,EAAE,0BAA0B,IAAI,EAAE,CAAC,CAAA;AAE5E,4EAA4E;AAC5E,MAAM,CAAC,MAAM,GAAG,GAAG,IAAI,CAAC,EAAE,CAAC,CAAA;AAC3B,0BAA0B;AAC1B,MAAM,CAAC,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,CAAA;AAC7B,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC;KACrB,MAAM,EAAE;KACR,KAAK,CAAC,qBAAqB,CAAC;KAC5B,SAAS,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,WAAW,EAAa,CAAC,CAAA;AAC/C,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC;KACrB,MAAM,EAAE;KACR,KAAK,CAAC,qBAAqB,CAAC;KAC5B,SAAS,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,WAAW,EAAS,CAAC,CAAA;AAC3C,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC;KACtB,MAAM,EAAE;KACR,KAAK,CAAC,uBAAuB,CAAC;KAC9B,SAAS,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,WAAW,EAAS,CAAC,CAAA;AAC3C,MAAM,CAAC,MAAM,IAAI,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC,CAAA"}
@@ -0,0 +1,51 @@
1
+ import { type Address, type Client, type Hex } from 'viem';
2
+ import type { SignatureCheck } from './eip712.js';
3
+ /**
4
+ * Tempo's keychain V2 envelope. When a business account's root key or one of its admin keys signs
5
+ * for the account, Tempo's `verifyKeychainAdmin` accepts the signature only inside this envelope:
6
+ * the byte `0x04`, the account's address, then the key's own signature over
7
+ * `keccak256(0x04 || digest || account)`. Tempo refuses a bare signature, and it refuses an
8
+ * envelope that names another account.
9
+ */
10
+ /** The hash a root or admin key signs, which binds the signature to one account. */
11
+ export declare function keychainV2Hash(digest: Hex, account: Address): Hex;
12
+ /** Wraps a key's serialized signature (secp256k1, P-256 or WebAuthn) for an account. */
13
+ export declare function wrapKeychainV2(account: Address, inner: Hex): Hex;
14
+ /** Anything that signs a 32-byte hash as it is: a viem account, a P-256 key or a passkey. */
15
+ export interface HashSigner {
16
+ sign(args: {
17
+ hash: Hex;
18
+ }): Promise<Hex>;
19
+ }
20
+ /** Signs a digest for an account with its root key or an admin key, ready for the lock. */
21
+ export declare function signForAccount(account: Address, digest: Hex, key: HashSigner): Promise<Hex>;
22
+ /** Reads a keychain envelope, or returns null when the signature isn't one. */
23
+ export declare function readKeychainEnvelope(signature: Hex): {
24
+ version: 'v1' | 'v2';
25
+ account: Address;
26
+ inner: Hex;
27
+ } | null;
28
+ /**
29
+ * The same rule as `verifyKeychainAdmin`, checked without a node: a V2 envelope naming the
30
+ * account, around a valid signature by the account's root key or one of its admin keys. Avow's
31
+ * tests use it, and `tempoKeychainCheck` asks the chain itself.
32
+ */
33
+ export declare function keychainSignatureCheck(isAdminKey: (account: Address, key: Address) => boolean | Promise<boolean>): SignatureCheck;
34
+ /**
35
+ * Whether a signature has the form of one key's own signature that Tempo's verifier reads for a
36
+ * single key, secp256k1, P-256 or WebAuthn, outside any keychain envelope. `isKeySignature` reads
37
+ * a signature the same way before it checks who signed, so every signature it accepts passes.
38
+ */
39
+ export declare function isKeySignatureForm(signature: Hex): boolean;
40
+ /**
41
+ * Whether a key's own signature, outside any keychain envelope, signed the digest. It reads the
42
+ * kinds of signature Tempo's verifier reads for a single key, secp256k1, P-256 and WebAuthn, so it
43
+ * answers as the lock's check of a supplier's signing key does.
44
+ */
45
+ export declare function isKeySignature(digest: Hex, signature: Hex, key: Address): boolean;
46
+ /**
47
+ * Asks Tempo's signature verifier precompile, the same check the lock makes. A refusal returns
48
+ * false, and a network failure throws, so an outage never reads as a forged signature.
49
+ */
50
+ export declare function tempoKeychainCheck(client: Client): SignatureCheck;
51
+ //# sourceMappingURL=keychain.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"keychain.d.ts","sourceRoot":"","sources":["../src/keychain.ts"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,OAAO,EAEZ,KAAK,MAAM,EAGX,KAAK,GAAG,EAGT,MAAM,MAAM,CAAA;AAGb,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAEjD;;;;;;GAMG;AAEH,oFAAoF;AACpF,wBAAgB,cAAc,CAAC,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,OAAO,GAAG,GAAG,CA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