apps 0.0.1-beta.4 → 0.0.1-beta.40

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 (171) hide show
  1. package/README.md +68 -44
  2. package/framework-reference.json +1 -1
  3. package/js/{chunk-QKHR7BMF.js → chunk-3MMG2H6M.js} +89 -53
  4. package/js/chunk-4TLZGG4B.js +729 -0
  5. package/js/chunk-6KABJTDO.js +255 -0
  6. package/js/{chunk-FDNTX5QJ.js → chunk-CQD3WSYH.js} +2 -2
  7. package/js/{chunk-EQB7JMAL.js → chunk-DHX2OI2X.js} +146 -31
  8. package/js/{chunk-EVJUVWN2.js → chunk-DKUEYTYD.js} +463 -218
  9. package/js/chunk-EM4UL26F.js +118 -0
  10. package/js/{chunk-WFSQXYUT.js → chunk-GHXRRFZA.js} +418 -52
  11. package/js/{chunk-5MQZEB6Y.js → chunk-KANDIVIH.js} +40 -12
  12. package/js/chunk-KAQD3DTI.js +16 -0
  13. package/js/chunk-KIM5HXNK.js +49 -0
  14. package/js/{chunk-FW5HBOIK.js → chunk-MXDKXAY4.js} +19117 -18309
  15. package/js/{chunk-2VPJHFOU.js → chunk-MYF7KWUB.js} +128 -24
  16. package/js/{chunk-T2LAZCAD.js → chunk-NKWWPJYX.js} +3 -3
  17. package/js/chunk-OD3KFKZD.js +1617 -0
  18. package/js/{chunk-3M2MEDNL.js → chunk-OTCLXFLL.js} +1337 -188
  19. package/js/chunk-P7MGDPFD.js +240 -0
  20. package/js/chunk-PDS2E2OZ.js +42 -0
  21. package/js/{chunk-ZCAMUXSG.js → chunk-PNVCCB4L.js} +432 -79
  22. package/js/{chunk-D47C7KG5.js → chunk-RIXVGVA6.js} +2 -2
  23. package/js/{chunk-6VRYO2BG.js → chunk-SALJXSS3.js} +779 -251
  24. package/js/{chunk-NQ3OMCA5.js → chunk-TT6OU4UG.js} +2 -2
  25. package/js/{chunk-YEJOQEII.js → chunk-UOZMSUJ2.js} +61 -9
  26. package/js/{chunk-G7ZIRKMK.js → chunk-VIU2XXA7.js} +228 -264
  27. package/js/{chunk-HDJH3RPR.js → chunk-VJQXXOQ3.js} +4 -4
  28. package/js/chunk-XDGUGB2A.js +156 -0
  29. package/js/{chunk-SATWJKN6.js → chunk-YQ35E7KS.js} +2 -2
  30. package/js/chunk-ZUKBIHMK.js +92 -0
  31. package/js/client.js +122 -88
  32. package/js/contracts.js +116 -25
  33. package/js/effect.js +19 -20
  34. package/js/{es-APDZKREY.js → es-DIULA3ZF.js} +62 -1659
  35. package/js/graphql.js +57 -55
  36. package/js/host.js +19 -20
  37. package/js/index.js +245 -212
  38. package/js/mcp/effect.js +23 -22
  39. package/js/mcp/stdio.js +34 -30
  40. package/js/mcp.js +104 -68
  41. package/js/openapi.js +4087 -1503
  42. package/js/react.js +2 -3
  43. package/js/skills/effect.js +6 -3
  44. package/js/skills.js +147 -65
  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 +2 -3
  51. package/runtime.json +1 -1
  52. package/types/app-data/src/contracts/database.d.ts +33 -6
  53. package/types/apps/src/contracts/api-response-error.d.ts +4 -0
  54. package/types/apps/src/contracts/app.d.ts +7 -8
  55. package/types/apps/src/contracts/cache.d.ts +14 -0
  56. package/types/apps/src/contracts/context.d.ts +12 -11
  57. package/types/apps/src/contracts/elicitation.d.ts +6 -6
  58. package/types/apps/src/contracts/failure.d.ts +54 -0
  59. package/types/apps/src/contracts/graphql.d.ts +2 -1
  60. package/types/apps/src/contracts/host.d.ts +44 -17
  61. package/types/apps/src/contracts/live.d.ts +2 -0
  62. package/types/apps/src/contracts/mcp.d.ts +96 -10
  63. package/types/apps/src/contracts/network.d.ts +84 -0
  64. package/types/apps/src/contracts/openapi-compile.d.ts +32 -3
  65. package/types/apps/src/contracts/openapi.d.ts +45 -9
  66. package/types/apps/src/contracts/operations.d.ts +8 -9
  67. package/types/apps/src/contracts/protocol-version.d.ts +2 -2
  68. package/types/apps/src/contracts/protocols/1.d.ts +263 -74
  69. package/types/apps/src/contracts/protocols/10.d.ts +1450 -0
  70. package/types/apps/src/contracts/protocols/2.d.ts +66 -24
  71. package/types/apps/src/contracts/protocols/3.d.ts +715 -0
  72. package/types/apps/src/contracts/protocols/4.d.ts +1297 -0
  73. package/types/apps/src/contracts/protocols/5.d.ts +1174 -0
  74. package/types/apps/src/contracts/protocols/6.d.ts +1620 -0
  75. package/types/apps/src/contracts/protocols/7.d.ts +1784 -0
  76. package/types/apps/src/contracts/protocols/8.d.ts +1130 -0
  77. package/types/apps/src/contracts/protocols/9.d.ts +1106 -0
  78. package/types/apps/src/contracts/protocols/oauth.d.ts +89 -0
  79. package/types/apps/src/contracts/provider-error.d.ts +9 -0
  80. package/types/apps/src/contracts/provider.d.ts +115 -10
  81. package/types/apps/src/contracts/router.d.ts +59 -0
  82. package/types/apps/src/contracts/skills.d.ts +39 -9
  83. package/types/apps/src/contracts/sql.d.ts +58 -0
  84. package/types/apps/src/contracts/ui.d.ts +19 -1
  85. package/types/apps/src/contracts/workflows.d.ts +40 -3
  86. package/types/apps/src/facet.d.ts +4 -5
  87. package/types/apps/src/graphql.d.ts +1 -3
  88. package/types/apps/src/implementation/account-router.d.ts +12 -0
  89. package/types/apps/src/implementation/app.d.ts +5 -4
  90. package/types/apps/src/implementation/browser-scripts.gen.d.ts +6 -0
  91. package/types/apps/src/implementation/catalog-cache.d.ts +32 -5
  92. package/types/apps/src/implementation/elicitation.d.ts +9 -9
  93. package/types/apps/src/implementation/failure-detail.d.ts +47 -0
  94. package/types/apps/src/implementation/graphql-catalog.d.ts +4 -7
  95. package/types/apps/src/implementation/graphql.d.ts +4 -3
  96. package/types/apps/src/implementation/input-problems.d.ts +4 -1
  97. package/types/apps/src/implementation/live.d.ts +2 -2
  98. package/types/apps/src/implementation/mcp-call.d.ts +6 -5
  99. package/types/apps/src/implementation/mcp-catalog.d.ts +7 -8
  100. package/types/apps/src/implementation/mcp-client.d.ts +49 -25
  101. package/types/apps/src/implementation/mcp-stdio.d.ts +1 -1
  102. package/types/apps/src/implementation/mcp-tools.d.ts +2 -1
  103. package/types/apps/src/implementation/mcp.d.ts +52 -25
  104. package/types/apps/src/implementation/network.d.ts +16 -0
  105. package/types/apps/src/implementation/openapi-compile.d.ts +27 -6
  106. package/types/apps/src/implementation/openapi-document.d.ts +46 -19
  107. package/types/apps/src/implementation/openapi-names.d.ts +9 -4
  108. package/types/apps/src/implementation/openapi-request.d.ts +10 -2
  109. package/types/apps/src/implementation/openapi-source.d.ts +8 -6
  110. package/types/apps/src/implementation/openapi-upgrade.d.ts +4 -0
  111. package/types/apps/src/implementation/operations.d.ts +36 -3
  112. package/types/apps/src/implementation/optimistic.d.ts +1 -1
  113. package/types/apps/src/implementation/protocol-operations.d.ts +6 -4
  114. package/types/apps/src/implementation/provider-error.d.ts +28 -1
  115. package/types/apps/src/implementation/provider.d.ts +19 -5
  116. package/types/apps/src/implementation/query-commit.d.ts +1 -1
  117. package/types/apps/src/implementation/router-catalog.d.ts +223 -0
  118. package/types/apps/src/implementation/router.d.ts +68 -0
  119. package/types/apps/src/implementation/runtime-yield.d.ts +7 -0
  120. package/types/apps/src/implementation/schema.d.ts +86 -11
  121. package/types/apps/src/implementation/skills.d.ts +18 -24
  122. package/types/apps/src/implementation/sql.d.ts +66 -0
  123. package/types/apps/src/implementation/ui-account-notice.d.ts +9 -0
  124. package/types/apps/src/implementation/ui-auth.d.ts +1 -1
  125. package/types/apps/src/implementation/ui-client.d.ts +2 -2
  126. package/types/apps/src/implementation/ui-document.d.ts +5 -0
  127. package/types/apps/src/implementation/ui-errors.d.ts +1 -1
  128. package/types/apps/src/implementation/ui-serving.d.ts +11 -5
  129. package/types/apps/src/implementation/ui-watch.d.ts +1 -1
  130. package/types/apps/src/implementation/upstream-error.d.ts +7 -0
  131. package/types/apps/src/implementation/webhooks.d.ts +1 -1
  132. package/types/apps/src/implementation/workflow-context.d.ts +11 -3
  133. package/types/apps/src/index.d.ts +30 -13
  134. package/types/apps/src/mcp-stdio.d.ts +2 -5
  135. package/types/apps/src/mcp.d.ts +25 -5
  136. package/types/apps/src/openapi.d.ts +6 -6
  137. package/types/apps/src/react.d.ts +1 -1
  138. package/types/apps/src/skills.d.ts +10 -8
  139. package/types/telemetry/src/app-records.d.ts +42 -0
  140. package/types/telemetry/src/browser-operations.d.ts +6 -3
  141. package/types/telemetry/src/browser.d.ts +2 -2
  142. package/types/telemetry/src/config.d.ts +2 -2
  143. package/types/telemetry/src/layer.d.ts +2 -2
  144. package/types/telemetry/src/recorded-failure.d.ts +20 -0
  145. package/types/telemetry/src/relay.d.ts +2 -2
  146. package/types/telemetry/src/transport.d.ts +8 -1
  147. package/types/utils/src/api-error.d.ts +53 -0
  148. package/types/utils/src/recorded-message.d.ts +15 -0
  149. package/js/chunk-BMOIAIVR.js +0 -138
  150. package/js/chunk-DHUDODG5.js +0 -213
  151. package/js/chunk-FZJOYIZO.js +0 -19
  152. package/js/chunk-LGIYBDWA.js +0 -85
  153. package/js/chunk-M6ZRRIBI.js +0 -877
  154. package/js/chunk-PLCMJREA.js +0 -590
  155. package/js/chunk-PYUYJRSK.js +0 -93
  156. package/js/chunk-SWPD52J7.js +0 -35
  157. package/js/chunk-W7D7WVSY.js +0 -18
  158. package/js/chunk-Z5NMEGJN.js +0 -29
  159. package/js/chunk-ZJWDMTE3.js +0 -63
  160. package/types/app-data/src/implementation/cursor.d.ts +0 -10
  161. package/types/app-data/src/implementation/index-key.d.ts +0 -7
  162. package/types/app-data/src/implementation/promise.d.ts +0 -68
  163. package/types/app-data/src/implementation/range.d.ts +0 -8
  164. package/types/app-data/src/implementation/schema.d.ts +0 -33
  165. package/types/app-data/src/implementation/sqlite.d.ts +0 -11
  166. package/types/app-data/src/index.d.ts +0 -4
  167. package/types/apps/src/contracts/dynamic-tools.d.ts +0 -13
  168. package/types/apps/src/contracts/storage.d.ts +0 -68
  169. package/types/apps/src/implementation/account-operations.d.ts +0 -151
  170. package/types/apps/src/implementation/dynamic-tools.d.ts +0 -8
  171. package/types/apps/src/implementation/storage.d.ts +0 -13
@@ -4,7 +4,7 @@ import {
4
4
  fromWeb,
5
5
  layerMergedContext,
6
6
  make2 as make
7
- } from "./chunk-QKHR7BMF.js";
7
+ } from "./chunk-3MMG2H6M.js";
8
8
  import {
9
9
  Reference,
10
10
  Service,
@@ -13,16 +13,16 @@ import {
13
13
  getOrUndefined2 as getOrUndefined,
14
14
  map3 as map,
15
15
  merge3 as merge,
16
- remove3 as remove,
16
+ remove2 as remove,
17
17
  succeed4 as succeed,
18
18
  toReadableStreamEffect,
19
19
  tryPromise
20
- } from "./chunk-FW5HBOIK.js";
20
+ } from "./chunk-MXDKXAY4.js";
21
21
  import {
22
22
  __export
23
23
  } from "./chunk-CZ7CSFO4.js";
24
24
 
25
- // ../../node_modules/.bun/effect@https+++pkg.pr.new+Effect-TS+effect+effect@c7d1ffff31a3e2ae0b0b+a654a55b752bdb24/node_modules/effect/dist/unstable/http/FetchHttpClient.js
25
+ // ../../node_modules/.bun/effect@4.0.1/node_modules/effect/dist/http/FetchHttpClient.js
26
26
  var FetchHttpClient_exports = {};
27
27
  __export(FetchHttpClient_exports, {
28
28
  Fetch: () => Fetch,
@@ -0,0 +1,156 @@
1
+ import {
2
+ declaredOperations,
3
+ fromPromise,
4
+ nativeOperation,
5
+ nativeRouter
6
+ } from "./chunk-6KABJTDO.js";
7
+ import {
8
+ ScheduleTiming
9
+ } from "./chunk-OTCLXFLL.js";
10
+ import {
11
+ decoderOf,
12
+ isSchema,
13
+ schemaArgument
14
+ } from "./chunk-GHXRRFZA.js";
15
+ import {
16
+ JsonValue
17
+ } from "./chunk-YQ35E7KS.js";
18
+ import {
19
+ Effect_exports,
20
+ Schema_exports
21
+ } from "./chunk-MXDKXAY4.js";
22
+
23
+ // src/contracts/http.ts
24
+ var ResponseStatusError = class extends Schema_exports.TaggedError()(
25
+ "ResponseStatusError",
26
+ { status: Schema_exports.Number }
27
+ ) {
28
+ get message() {
29
+ return `Request failed with status ${this.status}`;
30
+ }
31
+ };
32
+ var ResponseDecodeError = class extends Schema_exports.TaggedError()(
33
+ "ResponseDecodeError",
34
+ {}
35
+ ) {
36
+ get message() {
37
+ return "Response body did not match the expected schema";
38
+ }
39
+ };
40
+
41
+ // src/implementation/workflows.ts
42
+ var NativeWorkflow = /* @__PURE__ */ Symbol("apps.Workflow");
43
+ var workflow = (options, run) => ({
44
+ [NativeWorkflow]: {
45
+ input: decoderOf(schemaArgument(options.input, "The workflow input")),
46
+ ...options.output === void 0 ? {} : { output: decoderOf(schemaArgument(options.output, "The workflow output")) },
47
+ ...options.description === void 0 ? {} : { description: options.description },
48
+ run: (context, input) => Effect_exports.tryPromise({
49
+ // SAFETY: defineApp checks required context; the host supplies the pinned run's capabilities.
50
+ try: () => run(context, input),
51
+ catch: (error) => error
52
+ })
53
+ }
54
+ });
55
+ var nativeWorkflow = (value) => {
56
+ if (typeof value !== "object" || value === null || !(NativeWorkflow in value)) return void 0;
57
+ return value[NativeWorkflow];
58
+ };
59
+
60
+ // src/implementation/app.ts
61
+ var InternalApp = /* @__PURE__ */ Symbol("apps.App");
62
+ var isApp = (value) => typeof value === "object" && value !== null && InternalApp in value;
63
+ var toEffectApp = (app) => app[InternalApp];
64
+ function rejectCatalogs(definition) {
65
+ if ("queries" in definition || "mutations" in definition)
66
+ throw new Error("Put queries and mutations in a router under tools");
67
+ }
68
+ function adaptDefinition(definition) {
69
+ rejectCatalogs(definition);
70
+ const webhooks = definition.webhooks === void 0 ? {} : {
71
+ webhooks: Object.fromEntries(
72
+ Object.entries(definition.webhooks).map(([name, webhook]) => [
73
+ name,
74
+ {
75
+ ...webhook,
76
+ ...webhook.register === void 0 ? {} : { register: fromPromise(webhook.register) },
77
+ handle: fromPromise(webhook.handle),
78
+ ...webhook.unregister === void 0 ? {} : { unregister: fromPromise(webhook.unregister) },
79
+ ..."config" in webhook && isSchema(webhook.config) ? { config: decoderOf(webhook.config) } : {},
80
+ ..."state" in webhook && isSchema(webhook.state) ? { state: decoderOf(webhook.state) } : {}
81
+ }
82
+ ])
83
+ )
84
+ };
85
+ const workflows = definition.workflows === void 0 ? {} : {
86
+ workflows: Object.fromEntries(
87
+ Object.entries(definition.workflows).map(([name, value]) => {
88
+ const declared2 = nativeWorkflow(value);
89
+ if (declared2 === void 0) throw new Error("Invalid workflow declaration");
90
+ return [name, declared2];
91
+ })
92
+ )
93
+ };
94
+ const root = definition.tools === void 0 ? void 0 : nativeRouter(definition.tools);
95
+ if (definition.tools !== void 0 && root === void 0)
96
+ throw new Error("tools must be a router");
97
+ const data = root === void 0 ? {} : { tools: root };
98
+ const declared = root?.kind === "router" ? declaredOperations(root) : [];
99
+ const mutations = /* @__PURE__ */ new Set();
100
+ for (const { operation } of declared) {
101
+ if (operation.kind !== "mutation") continue;
102
+ if (mutations.has(operation))
103
+ throw new Error("A mutation can be mounted at only one path in tools");
104
+ mutations.add(operation);
105
+ }
106
+ const schedules = definition.schedules === void 0 ? {} : {
107
+ schedules: Object.fromEntries(
108
+ Object.entries(definition.schedules).map(([name, schedule]) => {
109
+ const target = nativeOperation(schedule.operation);
110
+ const match = declared.find(
111
+ ({ operation }) => operation === target && operation.kind === "mutation"
112
+ );
113
+ if (match === void 0)
114
+ throw new Error("A schedule must reference a mutation in this app's tools");
115
+ return [
116
+ name,
117
+ {
118
+ timing: Schema_exports.decodeUnknownSync(ScheduleTiming)(schedule.timing),
119
+ input: Schema_exports.decodeUnknownSync(JsonValue)(schedule.input),
120
+ tool: match.name
121
+ }
122
+ ];
123
+ })
124
+ )
125
+ };
126
+ return {
127
+ ...definition,
128
+ ...webhooks,
129
+ ...workflows,
130
+ ...data,
131
+ ...schedules
132
+ };
133
+ }
134
+ var defineApp = (requirements, definition) => {
135
+ if (typeof definition !== "function") rejectCatalogs(definition);
136
+ const evaluate = typeof definition === "function" ? definition : async () => definition;
137
+ const factory = fromPromise(evaluate);
138
+ const native = {
139
+ accounts: requirements.accounts,
140
+ evaluate: (context) => factory(context).pipe(Effect_exports.map((value) => adaptDefinition(value)))
141
+ };
142
+ return {
143
+ [InternalApp]: native,
144
+ accounts: native.accounts,
145
+ evaluate: (context) => Effect_exports.runPromise(factory(context))
146
+ };
147
+ };
148
+
149
+ export {
150
+ ResponseStatusError,
151
+ ResponseDecodeError,
152
+ workflow,
153
+ isApp,
154
+ toEffectApp,
155
+ defineApp
156
+ };
@@ -1,12 +1,12 @@
1
1
  import {
2
2
  Schema_exports
3
- } from "./chunk-FW5HBOIK.js";
3
+ } from "./chunk-MXDKXAY4.js";
4
4
 
5
5
  // src/contracts/schema.ts
6
6
  var JsonValue = Schema_exports.Json;
7
7
  var JsonObject = Schema_exports.Record(Schema_exports.String, JsonValue);
8
8
  var AccountId = Schema_exports.String.pipe(
9
- Schema_exports.check(Schema_exports.isStartsWith("acc_"), Schema_exports.isMinLength(5)),
9
+ Schema_exports.check(Schema_exports.isStartingWith("acc_"), Schema_exports.isMinLength(5)),
10
10
  Schema_exports.brand("acc")
11
11
  );
12
12
  var HttpUrl = Schema_exports.String.check(
@@ -0,0 +1,92 @@
1
+ import {
2
+ JsonValue
3
+ } from "./chunk-YQ35E7KS.js";
4
+ import {
5
+ HttpApiEndpoint_exports,
6
+ HttpApiGroup_exports,
7
+ HttpApiSchema_exports,
8
+ HttpApi_exports
9
+ } from "./chunk-VIU2XXA7.js";
10
+ import {
11
+ Schema_exports
12
+ } from "./chunk-MXDKXAY4.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
+ };
package/js/client.js CHANGED
@@ -1,40 +1,38 @@
1
1
  import {
2
2
  AppUiApi,
3
- HttpApiClient_exports,
4
3
  UiContext,
5
4
  UiDeploymentChanged,
6
5
  UiFailed
7
- } from "./chunk-G7ZIRKMK.js";
6
+ } from "./chunk-ZUKBIHMK.js";
8
7
  import {
9
8
  AsyncResult_exports,
10
9
  AtomRegistry_exports,
11
10
  Atom_exports,
12
11
  queryResult
13
- } from "./chunk-EVJUVWN2.js";
14
- import "./chunk-M6ZRRIBI.js";
12
+ } from "./chunk-DKUEYTYD.js";
15
13
  import {
16
14
  OtlpExporter_exports,
17
- TraceContext,
18
15
  externalTrace,
19
16
  pendingSpan,
20
17
  telemetryLayer,
21
18
  traceLinks
22
- } from "./chunk-ZCAMUXSG.js";
19
+ } from "./chunk-PNVCCB4L.js";
23
20
  import {
24
21
  FetchHttpClient_exports
25
- } from "./chunk-HDJH3RPR.js";
26
- import {
27
- HttpClientError_exports
28
- } from "./chunk-QKHR7BMF.js";
22
+ } from "./chunk-VJQXXOQ3.js";
29
23
  import {
30
24
  decoderOf
31
- } from "./chunk-WFSQXYUT.js";
32
- import {
33
- StorageName
34
- } from "./chunk-FZJOYIZO.js";
25
+ } from "./chunk-GHXRRFZA.js";
26
+ import "./chunk-KAQD3DTI.js";
35
27
  import {
36
28
  JsonValue
37
- } from "./chunk-SATWJKN6.js";
29
+ } from "./chunk-YQ35E7KS.js";
30
+ import {
31
+ HttpApiClient_exports
32
+ } from "./chunk-VIU2XXA7.js";
33
+ import {
34
+ HttpClientError_exports
35
+ } from "./chunk-3MMG2H6M.js";
38
36
  import {
39
37
  Cause_exports,
40
38
  Clock_exports,
@@ -47,25 +45,27 @@ import {
47
45
  Logger_exports,
48
46
  ManagedRuntime_exports,
49
47
  Option_exports,
48
+ Queue_exports,
50
49
  Schedule_exports,
51
50
  Schema_exports,
52
51
  Semaphore_exports,
53
52
  Stream_exports,
54
53
  Tracer_exports
55
- } from "./chunk-FW5HBOIK.js";
54
+ } from "./chunk-MXDKXAY4.js";
56
55
  import "./chunk-CZ7CSFO4.js";
57
56
 
58
57
  // src/contracts/live.ts
58
+ var OperationName = Schema_exports.NonEmptyString.check(Schema_exports.isMaxLength(200));
59
59
  var AppQueryFailed = class extends Schema_exports.TaggedError()("AppQueryFailed", {}) {
60
60
  };
61
61
 
62
62
  // src/implementation/live.ts
63
63
  var queryReference = (name) => ({
64
- name: Schema_exports.decodeUnknownSync(StorageName)(name),
64
+ name: Schema_exports.decodeUnknownSync(OperationName)(name),
65
65
  kind: "query"
66
66
  });
67
67
  var mutationReference = (name) => ({
68
- name: Schema_exports.decodeUnknownSync(StorageName)(name),
68
+ name: Schema_exports.decodeUnknownSync(OperationName)(name),
69
69
  kind: "mutation"
70
70
  });
71
71
  var liveQueryAtom = (reference, input, options) => Atom_exports.make(
@@ -448,21 +448,6 @@ var observeBrowserPerformance = Effect_exports.gen(function* () {
448
448
  };
449
449
  });
450
450
 
451
- // ../telemetry/src/browser-operations.ts
452
- var BrowserOperationFailure = Schema_exports.Struct({
453
- error_type: Schema_exports.Literals([
454
- "BrowserDecodeFailed",
455
- "BrowserTransportFailed",
456
- "BrowserOperationFailed"
457
- ]),
458
- trace_id: TraceContext.fields.traceId,
459
- span_id: TraceContext.fields.spanId,
460
- page_id: Schema_exports.String
461
- });
462
- var ResponseTrace = Context_exports.Reference("telemetry/ResponseTrace", {
463
- defaultValue: () => void 0
464
- });
465
-
466
451
  // ../telemetry/src/browser.ts
467
452
  var BrowserTelemetry = class extends Context_exports.Service()("executor/BrowserTelemetry") {
468
453
  };
@@ -809,6 +794,33 @@ var makeOptimisticClient = (transport) => {
809
794
  };
810
795
 
811
796
  // src/implementation/ui-client.ts
797
+ var resubscribeDelay = Schedule_exports.min([
798
+ Schedule_exports.exponential("1 second"),
799
+ Schedule_exports.spaced("1 minute")
800
+ ]).pipe(Schedule_exports.jittered);
801
+ var appFailure = (error) => Schema_exports.is(UiFailed)(error) && error.reason === "operation_failed";
802
+ var resubscribes = (error) => HttpClientError_exports.isHttpClientError(error) || Cause_exports.isTimeoutError(error) || Schema_exports.is(UiFailed)(error) && error.reason !== "account_required";
803
+ var Retrying = class {
804
+ constructor(error, previous) {
805
+ this.error = error;
806
+ this.previous = previous;
807
+ }
808
+ error;
809
+ previous;
810
+ };
811
+ var visibleResult = (result) => {
812
+ const current = AsyncResult_exports.value(result);
813
+ if (Option_exports.isNone(current) || !(current.value instanceof Retrying)) {
814
+ return result;
815
+ }
816
+ const previous = Option_exports.map(
817
+ Option_exports.fromUndefinedOr(current.value.previous),
818
+ AsyncResult_exports.success
819
+ );
820
+ return AsyncResult_exports.isSuccess(result) ? AsyncResult_exports.failureWithPrevious(Cause_exports.fail(current.value.error), { previous, waiting: true }) : AsyncResult_exports.failureWithPrevious(AsyncResult_exports.isFailure(result) ? result.cause : Cause_exports.empty, {
821
+ previous
822
+ });
823
+ };
812
824
  var createAppClient = () => {
813
825
  const { runtime, atoms } = makeBrowserTelemetry(
814
826
  browserSettings("/_executor/api/telemetry", "executor-app-web")
@@ -863,7 +875,8 @@ var createAppClient = () => {
863
875
  Stream_exports.suspend(() => {
864
876
  let previous;
865
877
  let attempts = 0;
866
- return Stream_exports.unwrap(
878
+ let latest;
879
+ const subscription = Stream_exports.unwrap(
867
880
  Effect_exports.gen(function* () {
868
881
  const attempt = attempts++;
869
882
  const first = yield* pendingSpan("ui.app.first_result", {
@@ -911,53 +924,55 @@ var createAppClient = () => {
911
924
  Stream_exports.timeout("45 seconds"),
912
925
  Stream_exports.concat(Stream_exports.fail(new UiFailed({ reason: "unavailable" }))),
913
926
  Stream_exports.filter((frame) => frame.type !== "heartbeat"),
914
- Stream_exports.mapEffect((frame) => {
915
- if (frame.type === "failure") return Effect_exports.fail(frame.error);
916
- const server = externalTrace(frame.trace);
917
- return Effect_exports.gen(function* () {
918
- const value = yield* Schema_exports.decodeUnknownEffect(decoderOf(output))(
919
- frame.value
920
- ).pipe(Effect_exports.mapError(() => new UiFailed({ reason: "operation_failed" })));
921
- const received = yield* Effect_exports.currentSpan;
922
- const receivedAt = clock.currentTimeMillisUnsafe();
923
- const currentRevision = revision++;
924
- yield* Effect_exports.annotateCurrentSpan({
925
- "executor.operation.name": name,
926
- "executor.snapshot.revision": currentRevision,
927
- "browser.query.elapsed_ms": receivedAt - started,
928
- "executor.trace.context_valid": Option_exports.isSome(server)
929
- });
930
- yield* first.finish(Exit_exports.void);
931
- let committed = false;
932
- return {
933
- value,
934
- commit: () => {
935
- if (committed) return;
936
- committed = true;
937
- const committedAt = clock.currentTimeMillisUnsafe();
938
- runtime.runFork(
939
- Effect_exports.void.pipe(
940
- Effect_exports.withSpan("ui.app.result.commit", {
941
- parent: received,
942
- attributes: {
943
- "executor.operation.name": name,
944
- "executor.snapshot.revision": currentRevision,
945
- "browser.query.elapsed_ms": committedAt - started,
946
- "browser.query.receive_to_commit_ms": committedAt - receivedAt,
947
- "browser.page.hidden": document.visibilityState === "hidden"
948
- }
949
- })
950
- )
951
- );
952
- }
953
- };
954
- }).pipe(
955
- Effect_exports.withSpan("ui.app.result.receive", {
956
- parent: Option_exports.isSome(server) ? server.value : first.span,
957
- kind: "consumer"
958
- })
959
- );
960
- }),
927
+ Stream_exports.mapEffect(
928
+ (frame) => {
929
+ if (frame.type === "failure") return Effect_exports.fail(frame.error);
930
+ const server = externalTrace(frame.trace);
931
+ return Effect_exports.gen(function* () {
932
+ const value = yield* Schema_exports.decodeUnknownEffect(decoderOf(output))(
933
+ frame.value
934
+ ).pipe(Effect_exports.mapError(() => new AppQueryFailed()));
935
+ const received = yield* Effect_exports.currentSpan;
936
+ const receivedAt = clock.currentTimeMillisUnsafe();
937
+ const currentRevision = revision++;
938
+ yield* Effect_exports.annotateCurrentSpan({
939
+ "executor.operation.name": name,
940
+ "executor.snapshot.revision": currentRevision,
941
+ "browser.query.elapsed_ms": receivedAt - started,
942
+ "executor.trace.context_valid": Option_exports.isSome(server)
943
+ });
944
+ yield* first.finish(Exit_exports.void);
945
+ let committed = false;
946
+ return {
947
+ value,
948
+ commit: () => {
949
+ if (committed) return;
950
+ committed = true;
951
+ const committedAt = clock.currentTimeMillisUnsafe();
952
+ runtime.runFork(
953
+ Effect_exports.void.pipe(
954
+ Effect_exports.withSpan("ui.app.result.commit", {
955
+ parent: received,
956
+ attributes: {
957
+ "executor.operation.name": name,
958
+ "executor.snapshot.revision": currentRevision,
959
+ "browser.query.elapsed_ms": committedAt - started,
960
+ "browser.query.receive_to_commit_ms": committedAt - receivedAt,
961
+ "browser.page.hidden": document.visibilityState === "hidden"
962
+ }
963
+ })
964
+ )
965
+ );
966
+ }
967
+ };
968
+ }).pipe(
969
+ Effect_exports.withSpan("ui.app.result.receive", {
970
+ parent: Option_exports.isSome(server) ? server.value : first.span,
971
+ kind: "consumer"
972
+ })
973
+ );
974
+ }
975
+ ),
961
976
  Stream_exports.onExit(finish),
962
977
  Stream_exports.provideService(Tracer_exports.ParentSpan, first.span)
963
978
  );
@@ -968,16 +983,35 @@ var createAppClient = () => {
968
983
  Stream_exports.catch(
969
984
  (error) => Schema_exports.is(UiDeploymentChanged)(error) ? Stream_exports.unwrap(deploymentChanged.pipe(Effect_exports.as(Stream_exports.never))) : Stream_exports.fail(error)
970
985
  ),
971
- Stream_exports.retry(
972
- Schedule_exports.spaced("1 second").pipe(
973
- Schedule_exports.while(
974
- ({ input: input2 }) => HttpClientError_exports.isHttpClientError(input2) || Cause_exports.isTimeoutError(input2) || Schema_exports.is(UiFailed)(input2)
975
- )
976
- )
986
+ Stream_exports.tap(
987
+ (value) => Effect_exports.sync(() => {
988
+ latest = value;
989
+ })
977
990
  )
978
991
  );
992
+ return Stream_exports.unwrap(
993
+ Effect_exports.gen(function* () {
994
+ const retrying = yield* Queue_exports.unbounded();
995
+ return Stream_exports.merge(
996
+ subscription.pipe(
997
+ Stream_exports.retry(
998
+ resubscribeDelay.pipe(
999
+ Schedule_exports.while(
1000
+ ({ input: input2 }) => !resubscribes(input2) ? false : appFailure(input2) ? Queue_exports.offer(retrying, new Retrying(input2, latest)).pipe(
1001
+ Effect_exports.as(true)
1002
+ ) : true
1003
+ )
1004
+ )
1005
+ )
1006
+ ),
1007
+ // Shown outside the retried stream, so they do not reset its delay.
1008
+ Stream_exports.fromQueue(retrying),
1009
+ { haltStrategy: "left" }
1010
+ );
1011
+ })
1012
+ );
979
1013
  })
980
- ).pipe(Atom_exports.map(queryResult));
1014
+ ).pipe(Atom_exports.map((result) => queryResult(visibleResult(result))));
981
1015
  const optimistic = makeOptimisticClient({
982
1016
  source,
983
1017
  read: (name, input, output) => request("query", name, input, output),