apps 0.0.1-beta.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 (135) hide show
  1. package/README.md +191 -0
  2. package/check-publish.mjs +10 -0
  3. package/framework-reference.json +1 -0
  4. package/js/chunk-22WRQZT7.js +389 -0
  5. package/js/chunk-2OTCEKL2.js +29480 -0
  6. package/js/chunk-36DNRFZQ.js +34 -0
  7. package/js/chunk-3ANFZFCV.js +1799 -0
  8. package/js/chunk-7JXHF5IF.js +138 -0
  9. package/js/chunk-BCSNKUAC.js +0 -0
  10. package/js/chunk-BKVL7XAJ.js +47 -0
  11. package/js/chunk-BPEFS4YF.js +1323 -0
  12. package/js/chunk-C24KEZXR.js +59 -0
  13. package/js/chunk-D6BKYP2L.js +877 -0
  14. package/js/chunk-EP6AEUZO.js +19 -0
  15. package/js/chunk-HP7E42X6.js +1719 -0
  16. package/js/chunk-KWTCHVLT.js +284 -0
  17. package/js/chunk-LOKGDT6B.js +28 -0
  18. package/js/chunk-MLKGABMK.js +9 -0
  19. package/js/chunk-OWD2YICM.js +2486 -0
  20. package/js/chunk-Q2FD5IBM.js +899 -0
  21. package/js/chunk-R6JMJSVT.js +590 -0
  22. package/js/chunk-SBKHUC5L.js +56 -0
  23. package/js/chunk-VFUZI3NY.js +75 -0
  24. package/js/chunk-W7Q5EOTS.js +4375 -0
  25. package/js/chunk-WIDTG42X.js +171 -0
  26. package/js/chunk-X3YBZCJW.js +246 -0
  27. package/js/chunk-YDR4CPJA.js +2357 -0
  28. package/js/client.js +1023 -0
  29. package/js/contracts.js +163 -0
  30. package/js/effect.js +44 -0
  31. package/js/graphql.js +392 -0
  32. package/js/host.js +193 -0
  33. package/js/index.js +284 -0
  34. package/js/mcp/effect.js +23 -0
  35. package/js/mcp/stdio.js +123 -0
  36. package/js/mcp.js +37 -0
  37. package/js/openapi.js +246 -0
  38. package/js/operations/approval.js +9 -0
  39. package/js/react.js +37 -0
  40. package/js/storage/facet.js +546 -0
  41. package/js/ui/auth/contracts.js +19 -0
  42. package/js/ui/auth.js +28 -0
  43. package/js/ui/contracts.js +24 -0
  44. package/js/ui/serving.js +286 -0
  45. package/package.json +116 -0
  46. package/runtime.json +1 -0
  47. package/types/app-data/src/contracts/database.d.ts +193 -0
  48. package/types/app-data/src/implementation/cursor.d.ts +10 -0
  49. package/types/app-data/src/implementation/index-key.d.ts +7 -0
  50. package/types/app-data/src/implementation/promise.d.ts +68 -0
  51. package/types/app-data/src/implementation/range.d.ts +8 -0
  52. package/types/app-data/src/implementation/schema.d.ts +33 -0
  53. package/types/app-data/src/implementation/sqlite.d.ts +11 -0
  54. package/types/app-data/src/index.d.ts +4 -0
  55. package/types/apps/src/approval.d.ts +10 -0
  56. package/types/apps/src/client.d.ts +5 -0
  57. package/types/apps/src/contracts/app.d.ts +58 -0
  58. package/types/apps/src/contracts/approval.d.ts +14 -0
  59. package/types/apps/src/contracts/context.d.ts +25 -0
  60. package/types/apps/src/contracts/elicitation.d.ts +86 -0
  61. package/types/apps/src/contracts/graphql.d.ts +102 -0
  62. package/types/apps/src/contracts/host.d.ts +568 -0
  63. package/types/apps/src/contracts/http.d.ts +20 -0
  64. package/types/apps/src/contracts/live.d.ts +26 -0
  65. package/types/apps/src/contracts/mcp.d.ts +93 -0
  66. package/types/apps/src/contracts/openapi.d.ts +105 -0
  67. package/types/apps/src/contracts/operations.d.ts +30 -0
  68. package/types/apps/src/contracts/optimistic.d.ts +22 -0
  69. package/types/apps/src/contracts/provider.d.ts +96 -0
  70. package/types/apps/src/contracts/schedules.d.ts +51 -0
  71. package/types/apps/src/contracts/schema.d.ts +20 -0
  72. package/types/apps/src/contracts/storage.d.ts +68 -0
  73. package/types/apps/src/contracts/tools.d.ts +11 -0
  74. package/types/apps/src/contracts/ui-auth.d.ts +28 -0
  75. package/types/apps/src/contracts/ui.d.ts +90 -0
  76. package/types/apps/src/contracts/webhook-protocol.d.ts +102 -0
  77. package/types/apps/src/contracts/webhooks.d.ts +53 -0
  78. package/types/apps/src/contracts/workflows.d.ts +277 -0
  79. package/types/apps/src/effect.d.ts +10 -0
  80. package/types/apps/src/facet.d.ts +5 -0
  81. package/types/apps/src/graphql.d.ts +10 -0
  82. package/types/apps/src/host.d.ts +16 -0
  83. package/types/apps/src/implementation/account-operations.d.ts +32 -0
  84. package/types/apps/src/implementation/app.d.ts +40 -0
  85. package/types/apps/src/implementation/authoring.d.ts +12 -0
  86. package/types/apps/src/implementation/elicitation.d.ts +103 -0
  87. package/types/apps/src/implementation/graphql.d.ts +5 -0
  88. package/types/apps/src/implementation/host.d.ts +3 -0
  89. package/types/apps/src/implementation/http.d.ts +5 -0
  90. package/types/apps/src/implementation/live.d.ts +18 -0
  91. package/types/apps/src/implementation/mcp-call.d.ts +19 -0
  92. package/types/apps/src/implementation/mcp-client.d.ts +50 -0
  93. package/types/apps/src/implementation/mcp-stdio.d.ts +4 -0
  94. package/types/apps/src/implementation/mcp-tools.d.ts +6 -0
  95. package/types/apps/src/implementation/mcp.d.ts +4 -0
  96. package/types/apps/src/implementation/openapi-request.d.ts +11 -0
  97. package/types/apps/src/implementation/openapi.d.ts +5 -0
  98. package/types/apps/src/implementation/operations.d.ts +65 -0
  99. package/types/apps/src/implementation/optimistic.d.ts +30 -0
  100. package/types/apps/src/implementation/protocol-operations.d.ts +24 -0
  101. package/types/apps/src/implementation/provider.d.ts +16 -0
  102. package/types/apps/src/implementation/query-commit.d.ts +10 -0
  103. package/types/apps/src/implementation/schedules.d.ts +16 -0
  104. package/types/apps/src/implementation/schema.d.ts +93 -0
  105. package/types/apps/src/implementation/storage.d.ts +13 -0
  106. package/types/apps/src/implementation/ui-auth.d.ts +13 -0
  107. package/types/apps/src/implementation/ui-client.d.ts +16 -0
  108. package/types/apps/src/implementation/ui-errors.d.ts +2 -0
  109. package/types/apps/src/implementation/ui-serving.d.ts +16 -0
  110. package/types/apps/src/implementation/ui-watch.d.ts +2 -0
  111. package/types/apps/src/implementation/webhooks.d.ts +29 -0
  112. package/types/apps/src/implementation/workflow-context.d.ts +8 -0
  113. package/types/apps/src/implementation/workflow-rpc.d.ts +5 -0
  114. package/types/apps/src/implementation/workflows.d.ts +27 -0
  115. package/types/apps/src/index.d.ts +58 -0
  116. package/types/apps/src/mcp-stdio.d.ts +8 -0
  117. package/types/apps/src/mcp.d.ts +10 -0
  118. package/types/apps/src/openapi.d.ts +10 -0
  119. package/types/apps/src/react.d.ts +7 -0
  120. package/types/apps/src/ui-auth.d.ts +3 -0
  121. package/types/apps/src/ui-serving.d.ts +3 -0
  122. package/types/telemetry/src/browser-operations.d.ts +16 -0
  123. package/types/telemetry/src/browser-performance.d.ts +11 -0
  124. package/types/telemetry/src/browser-request-timing.d.ts +2 -0
  125. package/types/telemetry/src/browser.d.ts +27 -0
  126. package/types/telemetry/src/config.d.ts +83 -0
  127. package/types/telemetry/src/context.d.ts +14 -0
  128. package/types/telemetry/src/index.d.ts +9 -0
  129. package/types/telemetry/src/layer.d.ts +7 -0
  130. package/types/telemetry/src/measurements.d.ts +8 -0
  131. package/types/telemetry/src/pending-span.d.ts +7 -0
  132. package/types/telemetry/src/relay.d.ts +28 -0
  133. package/types/telemetry/src/span-attributes.d.ts +29 -0
  134. package/types/telemetry/src/trace-context.d.ts +20 -0
  135. package/types/telemetry/src/transport.d.ts +6 -0
package/js/openapi.js ADDED
@@ -0,0 +1,246 @@
1
+ import {
2
+ protocolOperations
3
+ } from "./chunk-LOKGDT6B.js";
4
+ import "./chunk-C24KEZXR.js";
5
+ import {
6
+ FetchHttpClient_exports
7
+ } from "./chunk-VFUZI3NY.js";
8
+ import {
9
+ HttpClientRequest_exports,
10
+ HttpClient_exports
11
+ } from "./chunk-W7Q5EOTS.js";
12
+ import {
13
+ jsonSchemaDecoder
14
+ } from "./chunk-BPEFS4YF.js";
15
+ import {
16
+ HttpUrl,
17
+ JsonObject
18
+ } from "./chunk-36DNRFZQ.js";
19
+ import {
20
+ Effect_exports,
21
+ Schema_exports
22
+ } from "./chunk-2OTCEKL2.js";
23
+ import "./chunk-MLKGABMK.js";
24
+
25
+ // src/contracts/openapi.ts
26
+ var RequestParameter = Schema_exports.Struct({
27
+ name: Schema_exports.String,
28
+ in: Schema_exports.Literals(["path", "query", "header"]),
29
+ style: Schema_exports.String,
30
+ explode: Schema_exports.Boolean
31
+ });
32
+ var OpenapiOperation = Schema_exports.Struct({
33
+ name: Schema_exports.NonEmptyString,
34
+ description: Schema_exports.String,
35
+ method: Schema_exports.Literals(["GET", "POST", "PUT", "PATCH", "DELETE", "HEAD", "OPTIONS"]),
36
+ path: Schema_exports.String,
37
+ baseUrl: HttpUrl,
38
+ parameters: Schema_exports.Array(RequestParameter),
39
+ body: Schema_exports.Literals(["json", "base64", "none"]),
40
+ /** Streams remain in the metadata but cannot run through a single-result tool call. */
41
+ streaming: Schema_exports.optionalKey(Schema_exports.Literal(true)),
42
+ security: Schema_exports.Array(Schema_exports.Array(Schema_exports.String)),
43
+ input: JsonObject,
44
+ outputSchema: Schema_exports.optionalKey(JsonObject)
45
+ });
46
+ var CredentialBinding = Schema_exports.Struct({
47
+ scheme: Schema_exports.String,
48
+ field: Schema_exports.String,
49
+ in: Schema_exports.Literals(["header", "query"]),
50
+ name: Schema_exports.String,
51
+ prefix: Schema_exports.String
52
+ });
53
+ var OpenapiAccount = Schema_exports.Struct({
54
+ method: Schema_exports.String,
55
+ fields: Schema_exports.Record(Schema_exports.String, Schema_exports.Unknown)
56
+ });
57
+ var OpenapiToolsOptions = Schema_exports.Struct({
58
+ operations: Schema_exports.Array(OpenapiOperation),
59
+ methods: Schema_exports.Record(Schema_exports.String, Schema_exports.Array(CredentialBinding)),
60
+ oauth: Schema_exports.Array(Schema_exports.String),
61
+ account: Schema_exports.optional(OpenapiAccount),
62
+ signal: Schema_exports.optional(Schema_exports.instanceOf(AbortSignal)),
63
+ fetch: Schema_exports.optional(
64
+ Schema_exports.declare((value) => typeof value === "function")
65
+ )
66
+ });
67
+ var OpenapiError = class extends Schema_exports.TaggedError()("OpenapiError", {
68
+ reason: Schema_exports.Literals(["invalid_definition", "invalid_input", "request"]),
69
+ status: Schema_exports.optional(Schema_exports.Number)
70
+ }) {
71
+ };
72
+
73
+ // src/implementation/openapi-request.ts
74
+ var object = Schema_exports.decodeUnknownSync(Schema_exports.Record(Schema_exports.String, Schema_exports.Unknown));
75
+ function scalar(value) {
76
+ if (typeof value === "string" || typeof value === "number" || typeof value === "boolean")
77
+ return String(value);
78
+ throw new Error("This parameter requires scalar values");
79
+ }
80
+ function pairs(value) {
81
+ return Object.entries(object(value)).map(([key, item]) => [key, scalar(item)]);
82
+ }
83
+ function simple(value, explode, encode) {
84
+ const token = (value2) => encode ? encodeURIComponent(scalar(value2)) : scalar(value2);
85
+ if (Array.isArray(value)) return value.map(token).join(",");
86
+ if (typeof value === "object" && value !== null)
87
+ return pairs(value).map(([key, item]) => token(key) + (explode ? "=" : ",") + token(item)).join(",");
88
+ return token(value);
89
+ }
90
+ function createRequest(config) {
91
+ const { methods, oauth } = config;
92
+ function schemes(method) {
93
+ if (method === void 0) return [];
94
+ if (oauth.includes(method)) return [method];
95
+ const bindings = Object.hasOwn(methods, method) ? methods[method] : void 0;
96
+ return bindings?.map((binding) => binding.scheme) ?? [];
97
+ }
98
+ function selectedSecurity(op, method) {
99
+ if (op.streaming === true) return void 0;
100
+ if (!op.security.length) return [];
101
+ const supported = schemes(method);
102
+ return op.security.find((keys) => keys.every((key) => supported.includes(key)));
103
+ }
104
+ const call = (op, input, account) => Effect_exports.scoped(
105
+ Effect_exports.gen(function* () {
106
+ const prepared = yield* Effect_exports.try({
107
+ try: () => {
108
+ const args = object(input);
109
+ const security = selectedSecurity(op, account?.method);
110
+ if (security === void 0)
111
+ throw new Error("The selected account cannot call this tool");
112
+ let path = op.path;
113
+ const query = new URLSearchParams();
114
+ const headers = new Headers();
115
+ for (const p of op.parameters) {
116
+ const group = args[p.in === "header" ? "headers" : p.in];
117
+ const value = group === void 0 ? void 0 : object(group)[p.name];
118
+ if (value === void 0) continue;
119
+ if (p.in === "path")
120
+ path = path.replaceAll("{" + p.name + "}", simple(value, p.explode, true));
121
+ else if (p.in === "header") headers.set(p.name, simple(value, p.explode, false));
122
+ else if (p.style === "deepObject") {
123
+ for (const [key, item] of pairs(value))
124
+ query.append(p.name + "[" + key + "]", item);
125
+ } else if (Array.isArray(value)) {
126
+ if (p.explode && p.style === "form")
127
+ for (const item of value) query.append(p.name, scalar(item));
128
+ else
129
+ query.append(
130
+ p.name,
131
+ value.map(scalar).join(
132
+ p.style === "spaceDelimited" ? " " : p.style === "pipeDelimited" ? "|" : ","
133
+ )
134
+ );
135
+ } else if (typeof value === "object" && value !== null) {
136
+ if (p.style !== "form") throw new Error("Unsupported object parameter style");
137
+ if (p.explode) for (const [key, item] of pairs(value)) query.append(key, item);
138
+ else query.append(p.name, pairs(value).flat().join(","));
139
+ } else query.append(p.name, scalar(value));
140
+ }
141
+ if (/{[^}]+}/.test(path)) throw new Error("A required path parameter is missing");
142
+ const url = new URL(op.baseUrl + path);
143
+ if (account && Object.hasOwn(methods, account.method)) {
144
+ for (const binding of methods[account.method] ?? []) {
145
+ if (!security.includes(binding.scheme)) continue;
146
+ const credential = binding.prefix + scalar(account.fields[binding.field]);
147
+ if (binding.in === "header") headers.set(binding.name, credential);
148
+ else query.set(binding.name, credential);
149
+ }
150
+ } else if (account && oauth.includes(account.method) && security.includes(account.method)) {
151
+ headers.set("Authorization", "Bearer " + scalar(account.fields.access_token));
152
+ }
153
+ url.search = query.toString();
154
+ let body;
155
+ if (args.body !== void 0) {
156
+ if (op.body === "json") {
157
+ headers.set("Content-Type", "application/json");
158
+ body = JSON.stringify(args.body);
159
+ } else if (op.body === "base64") {
160
+ headers.set("Content-Type", "application/octet-stream");
161
+ body = Uint8Array.from(atob(scalar(args.body)), (char) => char.charCodeAt(0));
162
+ }
163
+ }
164
+ return { url, headers, body, method: op.method };
165
+ },
166
+ catch: () => new OpenapiError({ reason: "invalid_input" })
167
+ });
168
+ const client = yield* HttpClient_exports.HttpClient;
169
+ const request = yield* Effect_exports.try({
170
+ try: () => HttpClientRequest_exports.fromWeb(
171
+ new Request(prepared.url, {
172
+ method: prepared.method,
173
+ headers: prepared.headers,
174
+ ...prepared.body === void 0 ? {} : { body: prepared.body }
175
+ })
176
+ ),
177
+ catch: () => new OpenapiError({ reason: "invalid_input" })
178
+ });
179
+ const response = yield* HttpClient_exports.withScope(client).execute(request);
180
+ if (response.status < 200 || response.status >= 300)
181
+ return yield* new OpenapiError({ reason: "request", status: response.status });
182
+ if (response.status === 204 || prepared.method === "HEAD") return null;
183
+ return yield* (response.headers["content-type"]?.includes("json") ? response.json : response.text).pipe(Effect_exports.withSpan("provider.http.response.read"));
184
+ })
185
+ ).pipe(
186
+ Effect_exports.withSpan("provider.openapi.call", {
187
+ attributes: { "executor.tool.name": op.name, "http.request.method": op.method }
188
+ }),
189
+ Effect_exports.provideService(FetchHttpClient_exports.RequestInit, { redirect: "manual" }),
190
+ Effect_exports.provide(FetchHttpClient_exports.layer),
191
+ Effect_exports.mapError(
192
+ (error) => error instanceof OpenapiError ? error : new OpenapiError({ reason: "request" })
193
+ )
194
+ );
195
+ return {
196
+ available: (op, method) => selectedSecurity(op, method) !== void 0,
197
+ call
198
+ };
199
+ }
200
+
201
+ // src/implementation/openapi.ts
202
+ var openapiToolsEffect = (options) => Effect_exports.gen(function* () {
203
+ const config = yield* Schema_exports.decodeUnknownEffect(OpenapiToolsOptions)(options).pipe(
204
+ Effect_exports.mapError(() => new OpenapiError({ reason: "invalid_definition" }))
205
+ );
206
+ const request = createRequest(config);
207
+ const entries = yield* Effect_exports.forEach(
208
+ config.operations.filter((op) => request.available(op, config.account?.method)),
209
+ (op) => Effect_exports.gen(function* () {
210
+ const input = yield* jsonSchemaDecoder(op.input).pipe(
211
+ Effect_exports.mapError(() => new OpenapiError({ reason: "invalid_definition" }))
212
+ );
213
+ const tool = {
214
+ description: op.description,
215
+ readOnly: ["GET", "HEAD", "OPTIONS"].includes(op.method),
216
+ input,
217
+ ...op.outputSchema === void 0 ? {} : { outputSchema: op.outputSchema },
218
+ run: (_context, value) => Schema_exports.decodeUnknownEffect(input)(value).pipe(
219
+ Effect_exports.mapError(() => new OpenapiError({ reason: "invalid_input" })),
220
+ Effect_exports.flatMap(
221
+ (parsed) => request.call(op, parsed, config.account).pipe(
222
+ Effect_exports.provideService(
223
+ FetchHttpClient_exports.Fetch,
224
+ config.fetch ?? globalThis.fetch
225
+ )
226
+ )
227
+ )
228
+ )
229
+ };
230
+ return [op.name, tool];
231
+ })
232
+ );
233
+ return Object.fromEntries(entries);
234
+ });
235
+
236
+ // src/openapi.ts
237
+ var openapiOperations = (options, kinds = {}) => Effect_exports.runPromise(
238
+ openapiToolsEffect(options).pipe(
239
+ Effect_exports.map((operations) => protocolOperations(operations, kinds))
240
+ ),
241
+ options.signal === void 0 ? {} : { signal: options.signal }
242
+ );
243
+ export {
244
+ OpenapiError,
245
+ openapiOperations
246
+ };
@@ -0,0 +1,9 @@
1
+ import "../chunk-MLKGABMK.js";
2
+
3
+ // src/approval.ts
4
+ var always = () => () => "user-approval";
5
+ var never = () => () => "approved";
6
+ export {
7
+ always,
8
+ never
9
+ };
package/js/react.js ADDED
@@ -0,0 +1,37 @@
1
+ import {
2
+ AsyncResult_exports,
3
+ AtomRegistry_exports,
4
+ queryCommitted
5
+ } from "./chunk-YDR4CPJA.js";
6
+ import "./chunk-D6BKYP2L.js";
7
+ import {
8
+ Option_exports
9
+ } from "./chunk-2OTCEKL2.js";
10
+ import "./chunk-MLKGABMK.js";
11
+
12
+ // src/react.ts
13
+ import { useEffect, useLayoutEffect, useState } from "react";
14
+ var useAppQuery = (atom) => {
15
+ const [state, setState] = useState();
16
+ useEffect(() => {
17
+ const registry = AtomRegistry_exports.make();
18
+ const stop = registry.subscribe(atom, (result2) => setState({ atom, result: result2 }), {
19
+ immediate: true
20
+ });
21
+ return () => {
22
+ stop();
23
+ registry.dispose();
24
+ };
25
+ }, [atom]);
26
+ const result = state?.atom === atom ? state.result : AsyncResult_exports.initial();
27
+ useLayoutEffect(() => queryCommitted(result), [result]);
28
+ const value = AsyncResult_exports.value(result);
29
+ return {
30
+ data: Option_exports.getOrUndefined(value),
31
+ pending: result._tag === "Initial",
32
+ error: result._tag === "Failure" ? "Could not load app data." : void 0
33
+ };
34
+ };
35
+ export {
36
+ useAppQuery
37
+ };