apps 0.0.1-beta.7 → 0.0.1-beta.73

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 (178) hide show
  1. package/README.md +25 -22
  2. package/framework-reference.json +1 -1
  3. package/js/{chunk-RJDDBDSN.js → chunk-3CVQ3VPP.js} +762 -171
  4. package/js/chunk-3R3KFCDU.js +426 -0
  5. package/js/chunk-5FHWNLCI.js +88 -0
  6. package/js/{chunk-M3B3DE4K.js → chunk-74YVXBKY.js} +463 -218
  7. package/js/chunk-7LMU3ER3.js +274 -0
  8. package/js/chunk-CDXQDN7W.js +92 -0
  9. package/js/{chunk-RFVIONFX.js → chunk-ECCWT5GJ.js} +79 -41
  10. package/js/{chunk-UK573G7W.js → chunk-EOPQ727L.js} +87 -51
  11. package/js/{chunk-CMYUWAX7.js → chunk-G7L5DHQX.js} +126 -31
  12. package/js/{chunk-27F7W2LG.js → chunk-H2CJWXA3.js} +2 -2
  13. package/js/{chunk-JU7VHODU.js → chunk-H72MEDMN.js} +65 -10
  14. package/js/{chunk-CDL5PM2Q.js → chunk-IFJU5SYQ.js} +19082 -18402
  15. package/js/{chunk-VFZKSM3T.js → chunk-JPEUKEV4.js} +3 -3
  16. package/js/{chunk-WLE7WX2U.js → chunk-JW5LYSER.js} +2262 -474
  17. package/js/{chunk-5T57N25Q.js → chunk-KGCTYL2S.js} +511 -63
  18. package/js/{chunk-KUMBKVJD.js → chunk-KLYSEHUD.js} +2 -2
  19. package/js/chunk-LTF4TLMO.js +347 -0
  20. package/js/chunk-MHB7IFG7.js +49 -0
  21. package/js/{chunk-FL2QR3XW.js → chunk-OBYMFSWA.js} +333 -69
  22. package/js/chunk-OD3KFKZD.js +1617 -0
  23. package/js/{chunk-57RKNWL2.js → chunk-PD6I2SDG.js} +4 -4
  24. package/js/{chunk-72JNVHPK.js → chunk-QGHGYH5V.js} +4 -3
  25. package/js/{chunk-NKLWZJLE.js → chunk-RUP4JMKO.js} +25 -14
  26. package/js/{chunk-IJX4CYZO.js → chunk-TUMGL2OC.js} +228 -264
  27. package/js/{chunk-UESPOTUI.js → chunk-WCVV4PPS.js} +899 -190
  28. package/js/{chunk-IPI4MFSN.js → chunk-XBG7HHXC.js} +2 -2
  29. package/js/{chunk-Z5M2LQOZ.js → chunk-ZEJ3IKEC.js} +67 -55
  30. package/js/chunk-ZR7QAG67.js +171 -0
  31. package/js/client.js +142 -94
  32. package/js/contracts.js +125 -26
  33. package/js/effect.js +19 -19
  34. package/js/{es-APDZKREY.js → es-DIULA3ZF.js} +62 -1659
  35. package/js/graphql.js +50 -40
  36. package/js/host.js +83 -58
  37. package/js/index.js +131 -46
  38. package/js/mcp/effect.js +23 -21
  39. package/js/mcp/stdio.js +44 -34
  40. package/js/mcp.js +76 -53
  41. package/js/openapi.js +4071 -1357
  42. package/js/react.js +2 -3
  43. package/js/skills/effect.js +6 -3
  44. package/js/skills.js +208 -81
  45. package/js/storage/facet.js +1 -540
  46. package/js/ui/auth/contracts.js +2 -2
  47. package/js/ui/auth.js +5 -5
  48. package/js/ui/contracts.js +5 -4
  49. package/js/ui/serving.js +8517 -214
  50. package/package.json +3 -4
  51. package/runtime.json +1 -1
  52. package/types/app-cache/src/contracts/cache.d.ts +2 -0
  53. package/types/app-cache/src/index.d.ts +10 -1
  54. package/types/apps/src/contracts/api-response-error.d.ts +4 -0
  55. package/types/apps/src/contracts/app.d.ts +7 -3
  56. package/types/apps/src/contracts/cache.d.ts +20 -0
  57. package/types/apps/src/contracts/context.d.ts +19 -11
  58. package/types/apps/src/contracts/elicitation.d.ts +6 -6
  59. package/types/apps/src/contracts/events.d.ts +93 -0
  60. package/types/apps/src/contracts/failure.d.ts +30 -1
  61. package/types/apps/src/contracts/graphql.d.ts +2 -1
  62. package/types/apps/src/contracts/host.d.ts +641 -16
  63. package/types/apps/src/contracts/live.d.ts +2 -0
  64. package/types/apps/src/contracts/mcp.d.ts +80 -10
  65. package/types/apps/src/contracts/network.d.ts +120 -0
  66. package/types/apps/src/contracts/openapi-compile.d.ts +82 -3
  67. package/types/apps/src/contracts/openapi.d.ts +41 -9
  68. package/types/apps/src/contracts/operations.d.ts +8 -4
  69. package/types/apps/src/contracts/placement.d.ts +102 -0
  70. package/types/apps/src/contracts/protocol-version.d.ts +2 -2
  71. package/types/apps/src/contracts/protocols/1.d.ts +733 -81
  72. package/types/apps/src/contracts/protocols/10.d.ts +1450 -0
  73. package/types/apps/src/contracts/protocols/2.d.ts +69 -26
  74. package/types/apps/src/contracts/protocols/3.d.ts +133 -33
  75. package/types/apps/src/contracts/protocols/4.d.ts +122 -45
  76. package/types/apps/src/contracts/protocols/5.d.ts +157 -47
  77. package/types/apps/src/contracts/protocols/6.d.ts +1629 -0
  78. package/types/apps/src/contracts/protocols/7.d.ts +1785 -0
  79. package/types/apps/src/contracts/protocols/8.d.ts +1182 -0
  80. package/types/apps/src/contracts/protocols/9.d.ts +1104 -0
  81. package/types/apps/src/contracts/protocols/current.d.ts +3842 -0
  82. package/types/apps/src/contracts/protocols/oauth-6.d.ts +74 -0
  83. package/types/apps/src/contracts/protocols/oauth.d.ts +134 -0
  84. package/types/apps/src/contracts/provider-error.d.ts +9 -0
  85. package/types/apps/src/contracts/provider.d.ts +90 -6
  86. package/types/apps/src/contracts/skills.d.ts +50 -13
  87. package/types/apps/src/contracts/sql.d.ts +63 -0
  88. package/types/apps/src/contracts/ui.d.ts +19 -1
  89. package/types/apps/src/contracts/workflows.d.ts +6 -0
  90. package/types/apps/src/facet.d.ts +4 -5
  91. package/types/apps/src/host.d.ts +5 -0
  92. package/types/apps/src/implementation/account-router.d.ts +4 -3
  93. package/types/apps/src/implementation/authoring.d.ts +25 -5
  94. package/types/apps/src/implementation/browser-scripts.gen.d.ts +6 -0
  95. package/types/apps/src/implementation/cache.d.ts +4 -0
  96. package/types/apps/src/implementation/catalog-cache.d.ts +35 -4
  97. package/types/apps/src/implementation/elicitation.d.ts +18 -15
  98. package/types/apps/src/implementation/events.d.ts +59 -0
  99. package/types/apps/src/implementation/failure-detail.d.ts +25 -3
  100. package/types/apps/src/implementation/graphql-catalog.d.ts +3 -3
  101. package/types/apps/src/implementation/graphql.d.ts +4 -3
  102. package/types/apps/src/implementation/input-problems.d.ts +6 -2
  103. package/types/apps/src/implementation/invocation-timing.d.ts +16 -0
  104. package/types/apps/src/implementation/live.d.ts +2 -2
  105. package/types/apps/src/implementation/mcp-call.d.ts +6 -5
  106. package/types/apps/src/implementation/mcp-catalog.d.ts +6 -4
  107. package/types/apps/src/implementation/mcp-client.d.ts +17 -9
  108. package/types/apps/src/implementation/mcp-stdio.d.ts +1 -1
  109. package/types/apps/src/implementation/mcp-tools.d.ts +2 -1
  110. package/types/apps/src/implementation/mcp.d.ts +20 -9
  111. package/types/apps/src/implementation/network.d.ts +16 -0
  112. package/types/apps/src/implementation/openapi-compile.d.ts +26 -6
  113. package/types/apps/src/implementation/openapi-document.d.ts +46 -19
  114. package/types/apps/src/implementation/openapi-names.d.ts +9 -4
  115. package/types/apps/src/implementation/openapi-request.d.ts +10 -2
  116. package/types/apps/src/implementation/openapi-source.d.ts +18 -0
  117. package/types/apps/src/implementation/openapi-upgrade.d.ts +4 -0
  118. package/types/apps/src/implementation/operations.d.ts +17 -2
  119. package/types/apps/src/implementation/optimistic.d.ts +1 -1
  120. package/types/apps/src/implementation/placement.d.ts +60 -0
  121. package/types/apps/src/implementation/protocol-operations.d.ts +3 -0
  122. package/types/apps/src/implementation/provider-error.d.ts +28 -1
  123. package/types/apps/src/implementation/provider.d.ts +18 -3
  124. package/types/apps/src/implementation/query-commit.d.ts +1 -1
  125. package/types/apps/src/implementation/router-catalog.d.ts +11 -13
  126. package/types/apps/src/implementation/router.d.ts +16 -5
  127. package/types/apps/src/implementation/runtime-yield.d.ts +7 -0
  128. package/types/apps/src/implementation/schema.d.ts +90 -10
  129. package/types/apps/src/implementation/skills.d.ts +18 -24
  130. package/types/apps/src/implementation/sql.d.ts +71 -0
  131. package/types/apps/src/implementation/ui-account-notice.d.ts +9 -0
  132. package/types/apps/src/implementation/ui-auth.d.ts +1 -1
  133. package/types/apps/src/implementation/ui-client.d.ts +2 -2
  134. package/types/apps/src/implementation/ui-document.d.ts +5 -0
  135. package/types/apps/src/implementation/ui-errors.d.ts +1 -1
  136. package/types/apps/src/implementation/ui-serving.d.ts +11 -5
  137. package/types/apps/src/implementation/ui-watch.d.ts +1 -1
  138. package/types/apps/src/implementation/upstream-error.d.ts +7 -0
  139. package/types/apps/src/implementation/webhooks.d.ts +1 -1
  140. package/types/apps/src/implementation/workflows.d.ts +1 -1
  141. package/types/apps/src/index.d.ts +55 -13
  142. package/types/apps/src/mcp.d.ts +20 -1
  143. package/types/apps/src/openapi.d.ts +1 -1
  144. package/types/apps/src/react.d.ts +1 -1
  145. package/types/apps/src/skills.d.ts +10 -8
  146. package/types/telemetry/src/app-records.d.ts +42 -0
  147. package/types/telemetry/src/browser-operations.d.ts +7 -4
  148. package/types/telemetry/src/browser.d.ts +8 -3
  149. package/types/telemetry/src/config.d.ts +2 -2
  150. package/types/telemetry/src/index.d.ts +2 -1
  151. package/types/telemetry/src/layer.d.ts +2 -2
  152. package/types/telemetry/src/measurements.d.ts +1 -1
  153. package/types/telemetry/src/ownership.d.ts +56 -0
  154. package/types/telemetry/src/recorded-failure.d.ts +29 -0
  155. package/types/telemetry/src/relay.d.ts +16 -6
  156. package/types/telemetry/src/span-attributes.d.ts +17 -1
  157. package/types/telemetry/src/transport.d.ts +8 -1
  158. package/types/utils/src/api-error.d.ts +55 -0
  159. package/types/utils/src/connection-failure.d.ts +33 -0
  160. package/types/utils/src/recorded-message.d.ts +18 -0
  161. package/types/utils/src/user-facing-error.d.ts +83 -0
  162. package/js/chunk-MKWZPDR6.js +0 -63
  163. package/js/chunk-N7YDVXYJ.js +0 -186
  164. package/js/chunk-OCYUEU47.js +0 -224
  165. package/js/chunk-PJJ24GU7.js +0 -877
  166. package/js/chunk-PZB6T6KU.js +0 -19
  167. package/js/chunk-R3EV5FTO.js +0 -97
  168. package/js/chunk-YXQHV65J.js +0 -242
  169. package/js/chunk-ZQINWV4W.js +0 -630
  170. package/types/app-data/src/implementation/cursor.d.ts +0 -10
  171. package/types/app-data/src/implementation/index-key.d.ts +0 -7
  172. package/types/app-data/src/implementation/promise.d.ts +0 -68
  173. package/types/app-data/src/implementation/range.d.ts +0 -8
  174. package/types/app-data/src/implementation/schema.d.ts +0 -18
  175. package/types/app-data/src/implementation/sqlite.d.ts +0 -11
  176. package/types/app-data/src/index.d.ts +0 -4
  177. package/types/apps/src/contracts/storage.d.ts +0 -68
  178. package/types/apps/src/implementation/storage.d.ts +0 -15
@@ -0,0 +1,274 @@
1
+ import {
2
+ AccountId
3
+ } from "./chunk-H2CJWXA3.js";
4
+ import {
5
+ Schema_exports
6
+ } from "./chunk-IFJU5SYQ.js";
7
+
8
+ // src/contracts/failure.ts
9
+ var maxFailureMessageLength = 2048;
10
+ var FailureSource = Schema_exports.Literals(["app", "storage", "service"]);
11
+ var FailureName = Schema_exports.String.check(Schema_exports.isMaxLength(128));
12
+ var FailureCode = Schema_exports.String.check(Schema_exports.isMaxLength(128));
13
+ var FailureMessage = Schema_exports.String.check(Schema_exports.isMaxLength(maxFailureMessageLength));
14
+ var maxFailureFields = 8;
15
+ var maxFailureFieldLength = 256;
16
+ var FailureFieldName = Schema_exports.String.check(
17
+ Schema_exports.isPattern(/^[A-Za-z_$][A-Za-z0-9_$]{0,63}$/)
18
+ );
19
+ var FailureFieldValue = Schema_exports.Union([
20
+ Schema_exports.String.check(Schema_exports.isMaxLength(maxFailureFieldLength)),
21
+ Schema_exports.Finite,
22
+ Schema_exports.Boolean
23
+ ]);
24
+ var FailureFields = Schema_exports.Record(FailureFieldName, FailureFieldValue).check(
25
+ Schema_exports.isMaxProperties(maxFailureFields)
26
+ );
27
+ var FailureDetail = {
28
+ source: Schema_exports.optionalKey(FailureSource),
29
+ errorName: Schema_exports.optionalKey(FailureName),
30
+ code: Schema_exports.optionalKey(FailureCode),
31
+ message: Schema_exports.optionalKey(FailureMessage),
32
+ fields: Schema_exports.optionalKey(FailureFields)
33
+ };
34
+ var maxUpstreamMessageLength = 1024;
35
+ var UpstreamError = Schema_exports.Struct({
36
+ code: Schema_exports.Union([
37
+ Schema_exports.Int,
38
+ Schema_exports.String.check(Schema_exports.isMinLength(1), Schema_exports.isMaxLength(128))
39
+ ]),
40
+ message: Schema_exports.optionalKey(Schema_exports.String.check(Schema_exports.isMaxLength(maxUpstreamMessageLength)))
41
+ });
42
+ var FailurePhase = Schema_exports.Literals(["connect", "discover", "call"]);
43
+
44
+ // src/contracts/provider-error.ts
45
+ var ProviderError = class extends Schema_exports.TaggedError()("ProviderError", {
46
+ reason: Schema_exports.Literals(["unauthorized", "forbidden", "rate_limited", "unavailable", "rejected"]),
47
+ status: Schema_exports.optional(Schema_exports.Int.check(Schema_exports.isBetween({ minimum: 100, maximum: 599 }))),
48
+ accountId: Schema_exports.optional(AccountId),
49
+ phase: Schema_exports.optional(FailurePhase),
50
+ upstream: Schema_exports.optional(UpstreamError)
51
+ }) {
52
+ };
53
+
54
+ // src/contracts/network.ts
55
+ var NetworkRefusal = Schema_exports.Union([
56
+ Schema_exports.Struct({ reason: Schema_exports.Literal("private_address") }),
57
+ Schema_exports.Struct({
58
+ reason: Schema_exports.Literal("credential_host"),
59
+ /** The provider of the credential handle the request carried. */
60
+ provider: Schema_exports.String,
61
+ /** The hosts that provider's credentials may reach; empty when it declares none. */
62
+ allowedHosts: Schema_exports.Array(Schema_exports.String)
63
+ }),
64
+ Schema_exports.Struct({ reason: Schema_exports.Literal("credential_app") }),
65
+ Schema_exports.Struct({
66
+ reason: Schema_exports.Literal("credential_expired"),
67
+ /** The provider of the expired credential handle. */
68
+ provider: Schema_exports.String
69
+ }),
70
+ Schema_exports.Struct({
71
+ reason: Schema_exports.Literal("credential_placement"),
72
+ /** The provider of the misplaced credential handle. */
73
+ provider: Schema_exports.String,
74
+ /** Where the handle was found, such as `body` or `header x-note`. */
75
+ location: Schema_exports.String
76
+ }),
77
+ Schema_exports.Struct({
78
+ reason: Schema_exports.Literal("credential_transport"),
79
+ /** The provider of the credential handle the request carried. */
80
+ provider: Schema_exports.String
81
+ }),
82
+ Schema_exports.Struct({
83
+ reason: Schema_exports.Literal("credential_method"),
84
+ /** The refused HTTP method. */
85
+ method: Schema_exports.String
86
+ })
87
+ ]);
88
+ var NetworkRefused = class extends Schema_exports.TaggedError()("NetworkRefused", {
89
+ /** The refused destination, with its port when the URL names one. */
90
+ host: Schema_exports.String,
91
+ refusal: NetworkRefusal
92
+ }) {
93
+ get message() {
94
+ const refusal = this.refusal;
95
+ switch (refusal.reason) {
96
+ case "private_address":
97
+ return `Executor refused a request to ${this.host}: apps on this instance can reach only public addresses, and ${this.host} is a private, loopback or internal address. The request was not sent.`;
98
+ case "credential_host":
99
+ return refusal.allowedHosts.length === 0 ? `Executor refused this request: ${refusal.provider} credentials cannot be sent to ${this.host}: the provider declares no hosts.` : `Executor refused this request: ${refusal.provider} credentials cannot be sent to ${this.host}. The provider allows: ${refusal.allowedHosts.join(", ")}.`;
100
+ case "credential_app":
101
+ return "Executor refused this request: it carries a credential handle that is not valid for this app. Use the account fields this invocation received.";
102
+ case "credential_expired":
103
+ return `Executor refused this request: it carries an expired ${refusal.provider} credential handle. Use the account fields this invocation received.`;
104
+ case "credential_placement":
105
+ return `Executor refused this request: it carries a ${refusal.provider} credential handle in the ${refusal.location}, where the provider does not place it. Send credentials only as the provider's request declares, for example with the account's headers() and url().`;
106
+ case "credential_transport":
107
+ return `Executor refused this request: ${refusal.provider} credentials are sent only over HTTPS, and ${this.host} was requested over plain HTTP.`;
108
+ case "credential_method":
109
+ return `Executor refused this request: credential handles are never sent with ${refusal.method}, which asks the service to echo the request back.`;
110
+ }
111
+ }
112
+ };
113
+ var networkRefusalStatus = 421;
114
+ var networkRefusalHeader = "x-executor-refused";
115
+ var NetworkRefusedHeader = Schema_exports.StringFromUriComponent.pipe(
116
+ Schema_exports.decodeTo(Schema_exports.fromJsonString(NetworkRefused))
117
+ );
118
+ var encodeRefusal = Schema_exports.encodeSync(NetworkRefused);
119
+ var encodeRefusalHeader = Schema_exports.encodeSync(NetworkRefusedHeader);
120
+ var networkRefusalResponse = (refused) => new Response(JSON.stringify({ ...encodeRefusal(refused), message: refused.message }), {
121
+ status: networkRefusalStatus,
122
+ statusText: "Refused by Executor",
123
+ headers: {
124
+ "content-type": "application/json; charset=utf-8",
125
+ [networkRefusalHeader]: encodeRefusalHeader(refused)
126
+ }
127
+ });
128
+ var RestrictedFetchOption = Schema_exports.Literals(["redirect", "cache", "integrity"]);
129
+ var supportedFetchOptions = {
130
+ redirect: ["follow", "manual"],
131
+ cache: ["no-store", "no-cache"],
132
+ integrity: [""]
133
+ };
134
+ var FetchOptionUnsupported = class extends Schema_exports.TaggedError()(
135
+ "FetchOptionUnsupported",
136
+ {
137
+ option: RestrictedFetchOption,
138
+ value: Schema_exports.String,
139
+ supported: Schema_exports.Array(Schema_exports.String)
140
+ }
141
+ ) {
142
+ get message() {
143
+ const supported = this.supported.map((value) => JSON.stringify(value)).join(" or ");
144
+ return `fetch option ${this.option}: ${JSON.stringify(this.value)} is not supported by Executor's app runtime. Use ${supported}, or omit ${this.option}.${this.advice}`;
145
+ }
146
+ /** What to do instead, when the standard value has an equivalent the runtime supports. */
147
+ get advice() {
148
+ switch (this.option) {
149
+ case "redirect":
150
+ return this.value === "error" ? ` To reject redirects, send redirect: "manual" and treat a 3xx response as the error.` : "";
151
+ case "cache":
152
+ return "";
153
+ case "integrity":
154
+ return " To check a digest, read the body and hash it with crypto.subtle.digest.";
155
+ }
156
+ }
157
+ };
158
+
159
+ // ../app-cache/src/contracts/cache.ts
160
+ var CacheError = class extends Schema_exports.TaggedError()("CacheError", {
161
+ reason: Schema_exports.Literals(["unavailable", "storage", "invalid", "capacity", "timeout"]),
162
+ /** Which of `cacheLimits` the request exceeded, when one did. */
163
+ limit: Schema_exports.optionalKey(
164
+ Schema_exports.Literals([
165
+ "keyBytes",
166
+ "entryBytes",
167
+ "batchBytes",
168
+ "batchEntries",
169
+ "totalBytes",
170
+ "totalEntries"
171
+ ])
172
+ )
173
+ }) {
174
+ };
175
+ var cacheLimits = {
176
+ keyBytes: 8192,
177
+ entryBytes: 2e6,
178
+ batchBytes: 8e6,
179
+ batchEntries: 128,
180
+ totalBytes: 128e6,
181
+ totalEntries: 1e5,
182
+ retentionMs: 7 * 24 * 60 * 60 * 1e3,
183
+ loadTimeoutMs: 9e4,
184
+ /**
185
+ * A loader's lease lapses this long after its host last renewed it. Hosts renew every
186
+ * `renewMs` while the invocation that claimed it runs, so a stalled or lost holder frees the
187
+ * key well inside an MCP execute budget.
188
+ */
189
+ leaseMs: 15e3,
190
+ renewMs: 5e3,
191
+ /** The longest a caller waits on another loader before loading for itself without publishing. */
192
+ waitMs: 1e4,
193
+ /** Bound for one command to a host store; a lost reply fails instead of holding its caller. */
194
+ commandTimeoutMs: 1e4
195
+ };
196
+ var Key = Schema_exports.String.check(Schema_exports.isPattern(/^[a-f0-9]{64}$/));
197
+ var Time = Schema_exports.Finite.check(Schema_exports.isGreaterThanOrEqualTo(0));
198
+ var CacheEntry = Schema_exports.Struct({
199
+ value: Schema_exports.Json,
200
+ version: Schema_exports.String,
201
+ freshUntil: Time,
202
+ staleUntil: Time
203
+ });
204
+ var CacheAcquired = Schema_exports.Struct({
205
+ entry: Schema_exports.NullOr(CacheEntry),
206
+ lease: Schema_exports.NullOr(Schema_exports.String)
207
+ });
208
+ var CacheCommand = Schema_exports.Union([
209
+ Schema_exports.Struct({ operation: Schema_exports.Literal("read"), keys: Schema_exports.Array(Key) }),
210
+ Schema_exports.Struct({
211
+ operation: Schema_exports.Literal("acquire"),
212
+ key: Key,
213
+ /** Claim even a fresh entry, as an explicit refresh does. */
214
+ refresh: Schema_exports.Boolean,
215
+ /** Claim only while the entry still has this version. Absent accepts the current one. */
216
+ version: Schema_exports.optionalKey(Schema_exports.NullOr(Schema_exports.String))
217
+ }),
218
+ Schema_exports.Struct({
219
+ operation: Schema_exports.Literal("claim"),
220
+ key: Key,
221
+ version: Schema_exports.NullOr(Schema_exports.String)
222
+ }),
223
+ Schema_exports.Struct({
224
+ operation: Schema_exports.Literal("publish"),
225
+ key: Key,
226
+ lease: Schema_exports.String,
227
+ entry: CacheEntry
228
+ }),
229
+ Schema_exports.Struct({ operation: Schema_exports.Literal("release"), key: Key, lease: Schema_exports.String }),
230
+ /** Extend a lease its holder still owns. Replies false once the lease lapsed or was replaced. */
231
+ Schema_exports.Struct({ operation: Schema_exports.Literal("renew"), key: Key, lease: Schema_exports.String }),
232
+ Schema_exports.Struct({
233
+ operation: Schema_exports.Literal("write"),
234
+ entries: Schema_exports.Array(Schema_exports.Struct({ key: Key, entry: CacheEntry }))
235
+ }),
236
+ Schema_exports.Struct({ operation: Schema_exports.Literal("invalidate"), key: Key })
237
+ ]);
238
+ var CacheReply = Schema_exports.Union([
239
+ Schema_exports.Struct({ ok: Schema_exports.Literal(true), value: Schema_exports.Json }),
240
+ Schema_exports.Struct({ ok: Schema_exports.Literal(false), error: CacheError })
241
+ ]);
242
+
243
+ export {
244
+ maxFailureMessageLength,
245
+ FailureSource,
246
+ FailureName,
247
+ FailureCode,
248
+ FailureMessage,
249
+ maxFailureFields,
250
+ maxFailureFieldLength,
251
+ FailureFieldName,
252
+ FailureFieldValue,
253
+ FailureFields,
254
+ FailureDetail,
255
+ maxUpstreamMessageLength,
256
+ UpstreamError,
257
+ FailurePhase,
258
+ ProviderError,
259
+ NetworkRefusal,
260
+ NetworkRefused,
261
+ networkRefusalStatus,
262
+ networkRefusalHeader,
263
+ NetworkRefusedHeader,
264
+ networkRefusalResponse,
265
+ RestrictedFetchOption,
266
+ supportedFetchOptions,
267
+ FetchOptionUnsupported,
268
+ CacheError,
269
+ cacheLimits,
270
+ CacheEntry,
271
+ CacheAcquired,
272
+ CacheCommand,
273
+ CacheReply
274
+ };
@@ -0,0 +1,92 @@
1
+ import {
2
+ JsonValue
3
+ } from "./chunk-H2CJWXA3.js";
4
+ import {
5
+ HttpApiEndpoint_exports,
6
+ HttpApiGroup_exports,
7
+ HttpApiSchema_exports,
8
+ HttpApi_exports
9
+ } from "./chunk-TUMGL2OC.js";
10
+ import {
11
+ Schema_exports
12
+ } from "./chunk-IFJU5SYQ.js";
13
+
14
+ // src/contracts/ui.ts
15
+ var UiContext = Schema_exports.Struct({
16
+ deployment: Schema_exports.NonEmptyString,
17
+ profile: Schema_exports.optional(Schema_exports.NonEmptyString),
18
+ expectedProfileRevision: Schema_exports.optional(Schema_exports.Int)
19
+ });
20
+ var UiOperation = Schema_exports.Struct({
21
+ ...UiContext.fields,
22
+ name: Schema_exports.NonEmptyString,
23
+ input: JsonValue
24
+ });
25
+ var UiUnauthorized = class extends Schema_exports.TaggedError()(
26
+ "UiUnauthorized",
27
+ {},
28
+ { httpApiStatus: 401 }
29
+ ) {
30
+ };
31
+ var UiForbidden = class extends Schema_exports.TaggedError()(
32
+ "UiForbidden",
33
+ {},
34
+ { httpApiStatus: 403 }
35
+ ) {
36
+ };
37
+ var UiDeploymentChanged = class extends Schema_exports.TaggedError()(
38
+ "UiDeploymentChanged",
39
+ {},
40
+ { httpApiStatus: 409 }
41
+ ) {
42
+ };
43
+ var UiFailed = class extends Schema_exports.TaggedError()(
44
+ "UiFailed",
45
+ {
46
+ reason: Schema_exports.Literals(["unavailable", "operation_failed", "account_required"])
47
+ },
48
+ { httpApiStatus: 422 }
49
+ ) {
50
+ };
51
+ var UiSnapshot = Schema_exports.Union([
52
+ Schema_exports.Struct({
53
+ type: Schema_exports.Literal("snapshot"),
54
+ value: JsonValue,
55
+ trace: Schema_exports.optional(Schema_exports.Unknown)
56
+ }),
57
+ Schema_exports.Struct({ type: Schema_exports.Literal("failure"), error: UiFailed }),
58
+ Schema_exports.Struct({ type: Schema_exports.Literal("heartbeat") })
59
+ ]);
60
+ var errors = [UiUnauthorized, UiForbidden, UiDeploymentChanged, UiFailed];
61
+ var AppUiApi = HttpApi_exports.make("app-ui").add(
62
+ HttpApiGroup_exports.make("ui").add(
63
+ HttpApiEndpoint_exports.post("query", "/_executor/api/query", {
64
+ payload: UiOperation,
65
+ success: JsonValue,
66
+ error: errors
67
+ })
68
+ ).add(
69
+ HttpApiEndpoint_exports.post("mutate", "/_executor/api/mutate", {
70
+ payload: UiOperation,
71
+ success: JsonValue,
72
+ error: errors
73
+ })
74
+ ).add(
75
+ HttpApiEndpoint_exports.post("subscribe", "/_executor/api/subscribe", {
76
+ payload: UiOperation,
77
+ success: HttpApiSchema_exports.StreamSse({ data: UiSnapshot, error: Schema_exports.Union(errors) }),
78
+ error: errors
79
+ })
80
+ )
81
+ );
82
+
83
+ export {
84
+ UiContext,
85
+ UiOperation,
86
+ UiUnauthorized,
87
+ UiForbidden,
88
+ UiDeploymentChanged,
89
+ UiFailed,
90
+ UiSnapshot,
91
+ AppUiApi
92
+ };
@@ -1,19 +1,35 @@
1
+ import {
2
+ fromPromise,
3
+ method,
4
+ toPromise
5
+ } from "./chunk-ZR7QAG67.js";
1
6
  import {
2
7
  CacheError
3
- } from "./chunk-R3EV5FTO.js";
8
+ } from "./chunk-7LMU3ER3.js";
4
9
  import {
5
10
  wrap
6
- } from "./chunk-5T57N25Q.js";
11
+ } from "./chunk-KGCTYL2S.js";
7
12
  import {
8
13
  JsonObject
9
- } from "./chunk-27F7W2LG.js";
14
+ } from "./chunk-H2CJWXA3.js";
10
15
  import {
16
+ Deferred_exports,
11
17
  Duration_exports,
12
18
  Effect_exports,
13
19
  Schema_exports
14
- } from "./chunk-CDL5PM2Q.js";
20
+ } from "./chunk-IFJU5SYQ.js";
15
21
 
16
22
  // src/implementation/catalog-cache.ts
23
+ var catalogScope = (options, credential, invalid) => {
24
+ const { account, cache } = options;
25
+ if (account === void 0)
26
+ return credential === void 0 ? Effect_exports.succeed(cache) : Effect_exports.fail(invalid("missing-account"));
27
+ if (cache === void 0) return Effect_exports.succeed(void 0);
28
+ return Effect_exports.try({
29
+ try: () => cache.forAccount(account),
30
+ catch: () => invalid("unselected-account")
31
+ });
32
+ };
17
33
  var schema = (decoder) => wrap(decoder, false);
18
34
  var Manifest = Schema_exports.Struct({
19
35
  revision: Schema_exports.String,
@@ -21,7 +37,6 @@ var Manifest = Schema_exports.Struct({
21
37
  summaries: Schema_exports.Int,
22
38
  header: Schema_exports.optionalKey(JsonObject)
23
39
  });
24
- var invoke = (work) => Effect_exports.tryPromise({ try: work, catch: (error) => error });
25
40
  var catalogCache = (options) => Effect_exports.gen(function* () {
26
41
  const cache = options.cache;
27
42
  const key = [...options.prefix, "current"];
@@ -35,14 +50,42 @@ var catalogCache = (options) => Effect_exports.gen(function* () {
35
50
  const staleFor = options.staleFor ?? "1 day";
36
51
  const retention = Duration_exports.toMillis(Duration_exports.fromInputUnsafe(freshFor)) + Duration_exports.toMillis(Duration_exports.fromInputUnsafe(staleFor)) + 3e5;
37
52
  const local = yield* Effect_exports.cached(options.load());
53
+ const pages = (cache2, revision, kind, count, decoder) => Effect_exports.gen(function* () {
54
+ const batches = yield* Effect_exports.forEach(
55
+ Array.from({ length: Math.ceil(count / 4) }, (_, batch) => batch * 4),
56
+ (offset) => fromPromise(method(cache2, "readMany"), "cache")(
57
+ Array.from(
58
+ { length: Math.min(4, count - offset) },
59
+ (_, index) => part(revision, kind, offset + index)
60
+ ),
61
+ schema(Schema_exports.Array(decoder))
62
+ ),
63
+ { concurrency: "unbounded" }
64
+ );
65
+ const values = [];
66
+ for (const page of batches.flat()) {
67
+ if (page === void 0) return yield* new CacheError({ reason: "unavailable" });
68
+ values.push(...page);
69
+ }
70
+ return values;
71
+ });
72
+ const kept = (cache2) => fromPromise(method(cache2, "read"), "cache")(key, schema(Manifest)).pipe(
73
+ Effect_exports.map(
74
+ (manifest) => manifest === void 0 ? void 0 : {
75
+ header: manifest.header,
76
+ tools: pages(cache2, manifest.revision, "page", manifest.pages, options.schema)
77
+ }
78
+ )
79
+ );
38
80
  const refresh = (context) => Effect_exports.gen(function* () {
39
- const { tools, header } = yield* options.load(context);
40
- const digest = yield* invoke(
41
- () => crypto.subtle.digest(
81
+ const { tools, header } = yield* options.load(context, kept(context.cache));
82
+ const digest = yield* Effect_exports.tryPromise({
83
+ try: () => crypto.subtle.digest(
42
84
  "SHA-256",
43
85
  new TextEncoder().encode(JSON.stringify({ tools, header: header ?? null }))
44
- )
45
- );
86
+ ),
87
+ catch: (error) => error
88
+ });
46
89
  const revision = Array.from(
47
90
  new Uint8Array(digest),
48
91
  (byte) => byte.toString(16).padStart(2, "0")
@@ -62,7 +105,7 @@ var catalogCache = (options) => Effect_exports.gen(function* () {
62
105
  batch = [];
63
106
  batchBytes = 0;
64
107
  if (!entries.length) return Effect_exports.void;
65
- return invoke(() => context.cache.write(entries, retention)).pipe(
108
+ return fromPromise(method(context.cache, "write"), "cache")(entries, retention).pipe(
66
109
  Effect_exports.withSpan("app.cache.flush", {
67
110
  attributes: {
68
111
  "cache.flush.index": flushes++,
@@ -120,39 +163,32 @@ var catalogCache = (options) => Effect_exports.gen(function* () {
120
163
  schema: schema(Manifest),
121
164
  freshFor,
122
165
  staleFor,
123
- load: (context) => Effect_exports.runPromise(refresh(context), { signal: context.signal })
166
+ ...options.stale === void 0 ? {} : { stale: options.stale },
167
+ // A cache may call the loader as a Promise; its own signal cancels that load.
168
+ load: toPromise(refresh, (context) => context.signal)
124
169
  };
125
170
  let reading;
126
- const current = () => cache === void 0 ? Effect_exports.fail(new CacheError({ reason: "unavailable" })) : invoke(
127
- () => reading ??= cache.get(getOptions).finally(() => {
128
- reading = void 0;
129
- })
130
- );
171
+ const current = () => Effect_exports.suspend(() => {
172
+ if (cache === void 0) return Effect_exports.fail(new CacheError({ reason: "unavailable" }));
173
+ const shared = reading;
174
+ if (shared !== void 0) return Deferred_exports.await(shared);
175
+ const deferred = Deferred_exports.makeUnsafe();
176
+ reading = deferred;
177
+ return fromPromise(
178
+ method(cache, "get"),
179
+ "cache"
180
+ )(getOptions).pipe(
181
+ Effect_exports.onExit(
182
+ (exit) => Effect_exports.sync(() => {
183
+ if (reading === deferred) reading = void 0;
184
+ }).pipe(Effect_exports.andThen(Deferred_exports.done(deferred, exit)))
185
+ )
186
+ );
187
+ });
131
188
  if (options.revalidate) {
132
189
  if (cache === void 0) yield* local;
133
- else yield* invoke(() => cache.revalidate(getOptions));
190
+ else yield* fromPromise(method(cache, "revalidate"), "cache")(getOptions);
134
191
  }
135
- const pages = (cache2, revision, kind, count, decoder) => Effect_exports.gen(function* () {
136
- const batches = yield* Effect_exports.forEach(
137
- Array.from({ length: Math.ceil(count / 4) }, (_, batch) => batch * 4),
138
- (offset) => invoke(
139
- () => cache2.readMany(
140
- Array.from(
141
- { length: Math.min(4, count - offset) },
142
- (_, index) => part(revision, kind, offset + index)
143
- ),
144
- schema(Schema_exports.Array(decoder))
145
- )
146
- ),
147
- { concurrency: "unbounded" }
148
- );
149
- const values = [];
150
- for (const page of batches.flat()) {
151
- if (page === void 0) return yield* new CacheError({ reason: "unavailable" });
152
- values.push(...page);
153
- }
154
- return values;
155
- });
156
192
  const metadata = () => Effect_exports.gen(function* () {
157
193
  if (cache === void 0) return (yield* local).tools;
158
194
  const manifest = yield* current();
@@ -176,8 +212,9 @@ var catalogCache = (options) => Effect_exports.gen(function* () {
176
212
  }),
177
213
  resolve: (name) => cache === void 0 ? local.pipe(Effect_exports.map(({ tools }) => tools.find((tool) => tool.name === name))) : current().pipe(
178
214
  Effect_exports.flatMap(
179
- (manifest) => invoke(
180
- () => cache.read(part(manifest.revision, "tool", name), schema(options.schema))
215
+ (manifest) => fromPromise(method(cache, "read"), "cache")(
216
+ part(manifest.revision, "tool", name),
217
+ schema(options.schema)
181
218
  )
182
219
  )
183
220
  )
@@ -185,5 +222,6 @@ var catalogCache = (options) => Effect_exports.gen(function* () {
185
222
  });
186
223
 
187
224
  export {
225
+ catalogScope,
188
226
  catalogCache
189
227
  };