apps 0.0.1-beta.4 → 0.0.1-beta.6

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 (96) hide show
  1. package/README.md +65 -43
  2. package/framework-reference.json +1 -1
  3. package/js/{chunk-SATWJKN6.js → chunk-27F7W2LG.js} +1 -1
  4. package/js/{chunk-HDJH3RPR.js → chunk-57RKNWL2.js} +2 -2
  5. package/js/{chunk-WFSQXYUT.js → chunk-5T57N25Q.js} +15 -3
  6. package/js/{chunk-EQB7JMAL.js → chunk-6BSSI67S.js} +8 -8
  7. package/js/{chunk-3M2MEDNL.js → chunk-B3EOZTK3.js} +351 -33
  8. package/js/{chunk-FW5HBOIK.js → chunk-CDL5PM2Q.js} +307 -169
  9. package/js/{chunk-Z5NMEGJN.js → chunk-ECQFRCH4.js} +21 -9
  10. package/js/{chunk-G7ZIRKMK.js → chunk-IJX4CYZO.js} +3 -3
  11. package/js/{chunk-FDNTX5QJ.js → chunk-IPI4MFSN.js} +2 -2
  12. package/js/{chunk-2VPJHFOU.js → chunk-ITM77QPO.js} +28 -9
  13. package/js/{chunk-YEJOQEII.js → chunk-JU7VHODU.js} +1 -1
  14. package/js/{chunk-NQ3OMCA5.js → chunk-KUMBKVJD.js} +2 -2
  15. package/js/{chunk-EVJUVWN2.js → chunk-M3B3DE4K.js} +2 -2
  16. package/js/{chunk-ZJWDMTE3.js → chunk-MKWZPDR6.js} +3 -3
  17. package/js/chunk-MNMNLXBL.js +507 -0
  18. package/js/{chunk-BMOIAIVR.js → chunk-N7YDVXYJ.js} +49 -1
  19. package/js/{chunk-D47C7KG5.js → chunk-NKLWZJLE.js} +2 -2
  20. package/js/{chunk-DHUDODG5.js → chunk-OE3QQTSB.js} +41 -32
  21. package/js/{chunk-M6ZRRIBI.js → chunk-PJJ24GU7.js} +1 -1
  22. package/js/{chunk-FZJOYIZO.js → chunk-PZB6T6KU.js} +1 -1
  23. package/js/{chunk-LGIYBDWA.js → chunk-R3EV5FTO.js} +13 -1
  24. package/js/{chunk-5MQZEB6Y.js → chunk-RFVIONFX.js} +29 -12
  25. package/js/{chunk-ZCAMUXSG.js → chunk-RJDDBDSN.js} +3 -3
  26. package/js/{chunk-6VRYO2BG.js → chunk-SB4HEPNJ.js} +191 -170
  27. package/js/chunk-T7GKZBLP.js +209 -0
  28. package/js/{chunk-QKHR7BMF.js → chunk-UK573G7W.js} +1 -1
  29. package/js/{chunk-T2LAZCAD.js → chunk-VFZKSM3T.js} +1 -1
  30. package/js/{chunk-PLCMJREA.js → chunk-ZQINWV4W.js} +60 -20
  31. package/js/client.js +10 -10
  32. package/js/contracts.js +52 -16
  33. package/js/effect.js +19 -20
  34. package/js/graphql.js +34 -40
  35. package/js/host.js +19 -20
  36. package/js/index.js +189 -178
  37. package/js/mcp/effect.js +21 -22
  38. package/js/mcp/stdio.js +25 -26
  39. package/js/mcp.js +60 -45
  40. package/js/openapi.js +182 -224
  41. package/js/react.js +3 -3
  42. package/js/skills/effect.js +3 -3
  43. package/js/skills.js +12 -13
  44. package/js/storage/facet.js +4 -4
  45. package/js/ui/auth/contracts.js +2 -2
  46. package/js/ui/auth.js +5 -5
  47. package/js/ui/contracts.js +4 -4
  48. package/js/ui/serving.js +8 -8
  49. package/package.json +1 -1
  50. package/runtime.json +1 -1
  51. package/types/app-data/src/contracts/database.d.ts +33 -6
  52. package/types/app-data/src/implementation/schema.d.ts +2 -17
  53. package/types/apps/src/contracts/app.d.ts +2 -5
  54. package/types/apps/src/contracts/failure.d.ts +25 -0
  55. package/types/apps/src/contracts/host.d.ts +18 -9
  56. package/types/apps/src/contracts/mcp.d.ts +16 -0
  57. package/types/apps/src/contracts/openapi.d.ts +5 -1
  58. package/types/apps/src/contracts/operations.d.ts +0 -5
  59. package/types/apps/src/contracts/protocol-version.d.ts +2 -2
  60. package/types/apps/src/contracts/protocols/1.d.ts +15 -1
  61. package/types/apps/src/contracts/protocols/2.d.ts +2 -2
  62. package/types/apps/src/contracts/protocols/3.d.ts +676 -0
  63. package/types/apps/src/contracts/protocols/4.d.ts +1229 -0
  64. package/types/apps/src/contracts/router.d.ts +59 -0
  65. package/types/apps/src/contracts/storage.d.ts +3 -3
  66. package/types/apps/src/contracts/workflows.d.ts +34 -3
  67. package/types/apps/src/graphql.d.ts +1 -3
  68. package/types/apps/src/implementation/account-router.d.ts +12 -0
  69. package/types/apps/src/implementation/app.d.ts +5 -4
  70. package/types/apps/src/implementation/catalog-cache.d.ts +9 -2
  71. package/types/apps/src/implementation/elicitation.d.ts +1 -1
  72. package/types/apps/src/implementation/failure-detail.d.ts +25 -0
  73. package/types/apps/src/implementation/graphql-catalog.d.ts +1 -4
  74. package/types/apps/src/implementation/mcp-catalog.d.ts +1 -4
  75. package/types/apps/src/implementation/mcp-client.d.ts +35 -19
  76. package/types/apps/src/implementation/mcp.d.ts +35 -19
  77. package/types/apps/src/implementation/openapi-compile.d.ts +2 -1
  78. package/types/apps/src/implementation/openapi-source.d.ts +2 -6
  79. package/types/apps/src/implementation/operations.d.ts +26 -3
  80. package/types/apps/src/implementation/protocol-operations.d.ts +3 -4
  81. package/types/apps/src/implementation/router-catalog.d.ts +225 -0
  82. package/types/apps/src/implementation/router.d.ts +59 -0
  83. package/types/apps/src/implementation/schema.d.ts +5 -1
  84. package/types/apps/src/implementation/storage.d.ts +5 -3
  85. package/types/apps/src/implementation/webhooks.d.ts +1 -1
  86. package/types/apps/src/implementation/workflow-context.d.ts +11 -3
  87. package/types/apps/src/index.d.ts +3 -2
  88. package/types/apps/src/mcp-stdio.d.ts +2 -5
  89. package/types/apps/src/mcp.d.ts +5 -4
  90. package/types/apps/src/openapi.d.ts +6 -6
  91. package/js/chunk-PYUYJRSK.js +0 -93
  92. package/js/chunk-SWPD52J7.js +0 -35
  93. package/js/chunk-W7D7WVSY.js +0 -18
  94. package/types/apps/src/contracts/dynamic-tools.d.ts +0 -13
  95. package/types/apps/src/implementation/account-operations.d.ts +0 -151
  96. package/types/apps/src/implementation/dynamic-tools.d.ts +0 -8
@@ -0,0 +1,209 @@
1
+ import {
2
+ HostedTool,
3
+ RouterKey,
4
+ RouterMeta,
5
+ reservedRouterKeys
6
+ } from "./chunk-B3EOZTK3.js";
7
+ import {
8
+ decoderOf
9
+ } from "./chunk-5T57N25Q.js";
10
+ import {
11
+ Effect_exports,
12
+ Schema_exports
13
+ } from "./chunk-CDL5PM2Q.js";
14
+
15
+ // src/implementation/authoring.ts
16
+ var NativeCallback = /* @__PURE__ */ Symbol("apps.NativeCallback");
17
+ var fromPromise = (callback) => (...args) => {
18
+ if (NativeCallback in callback) {
19
+ const native = callback[NativeCallback];
20
+ return native(...args);
21
+ }
22
+ return Effect_exports.tryPromise({ try: () => callback(...args), catch: (error) => error });
23
+ };
24
+ var toPromise = (operation, signal) => {
25
+ const native = (...args) => Effect_exports.suspend(() => {
26
+ if (signal === void 0) return operation(...args);
27
+ if (signal.aborted) return Effect_exports.interrupt;
28
+ const cancelled = Effect_exports.callback((resume) => {
29
+ if (signal.aborted) {
30
+ resume(Effect_exports.interrupt);
31
+ return;
32
+ }
33
+ const abort = () => resume(Effect_exports.interrupt);
34
+ signal.addEventListener("abort", abort, { once: true });
35
+ return Effect_exports.sync(() => signal.removeEventListener("abort", abort));
36
+ });
37
+ return Effect_exports.raceFirst(
38
+ cancelled,
39
+ Effect_exports.suspend(() => operation(...args))
40
+ );
41
+ });
42
+ return Object.assign((...args) => Effect_exports.runPromise(native(...args)), {
43
+ [NativeCallback]: native
44
+ });
45
+ };
46
+
47
+ // src/implementation/operations.ts
48
+ var NativeOperation = /* @__PURE__ */ Symbol("apps.Operation");
49
+ var NativeRouterKey = /* @__PURE__ */ Symbol("apps.Router");
50
+ var operationDeclaration = (operation) => ({
51
+ kind: operation.kind,
52
+ [NativeOperation]: operation
53
+ });
54
+ var nativeOperation = (value) => {
55
+ if (typeof value !== "object" || value === null || !(NativeOperation in value)) return void 0;
56
+ return value[NativeOperation];
57
+ };
58
+ var operationOptions = (options) => {
59
+ const approval = options.approval;
60
+ return {
61
+ ...options.description === void 0 ? {} : { description: options.description },
62
+ ...options.title === void 0 ? {} : { title: options.title },
63
+ ...options.annotations === void 0 ? {} : { annotations: options.annotations },
64
+ ...options._meta === void 0 ? {} : { _meta: options._meta },
65
+ input: decoderOf(options.input),
66
+ ...approval === void 0 ? {} : {
67
+ approval: (context) => Effect_exports.tryPromise({ try: async () => approval(context), catch: (error) => error })
68
+ }
69
+ };
70
+ };
71
+ var withApproval = (operation, approval) => ({
72
+ ...operation,
73
+ [NativeOperation]: {
74
+ ...operation[NativeOperation],
75
+ approval: (context) => Effect_exports.tryPromise({ try: async () => approval(context), catch: (error) => error })
76
+ }
77
+ });
78
+ var make = (kind, options, run) => operationDeclaration({
79
+ ...operationOptions(options),
80
+ kind,
81
+ // The host always validates JSON serialization, even without a stronger output declaration.
82
+ ...options.output === void 0 ? {} : { output: decoderOf(options.output) },
83
+ run: (context, input) => Effect_exports.tryPromise({
84
+ // SAFETY: defineApp checks the handler context against its requirements.
85
+ // The host validates account bindings and creates the matching storage facade.
86
+ try: () => run(context, input),
87
+ catch: (error) => error
88
+ })
89
+ });
90
+ var query = (options, run) => make("query", options, run);
91
+ var mutation = (options, run) => make("mutation", options, run);
92
+
93
+ // src/implementation/router.ts
94
+ var routerDeclaration = (node) => ({
95
+ [NativeRouterKey]: node
96
+ });
97
+ var nativeRouter = (value) => {
98
+ if (typeof value !== "object" || value === null || !(NativeRouterKey in value)) return void 0;
99
+ return value[NativeRouterKey];
100
+ };
101
+ var nativeNode = (value) => nativeOperation(value) ?? nativeRouter(value);
102
+ var metaOf = (options) => {
103
+ if (options === void 0) return void 0;
104
+ const defined = Object.fromEntries(
105
+ Object.entries(options).filter(([, value]) => value !== void 0)
106
+ );
107
+ return Object.keys(defined).length === 0 ? void 0 : Schema_exports.decodeUnknownSync(RouterMeta)(defined);
108
+ };
109
+ var mergeMeta = (base, override) => base === void 0 ? override : override === void 0 ? base : { ...base, ...override };
110
+ function router(children, options) {
111
+ const meta = metaOf(options);
112
+ const existing = nativeRouter(children);
113
+ if (existing !== void 0)
114
+ return routerDeclaration(
115
+ existing.kind === "router" ? { ...existing, ...withMeta(mergeMeta(existing.meta, meta)) } : { ...existing, ...withOverrides(mergeMeta(existing.overrides, meta)) }
116
+ );
117
+ const nodes = {};
118
+ for (const [key, value] of Object.entries(children)) {
119
+ if (reservedRouterKeys.has(key)) throw new Error(`Router key "${key}" is reserved`);
120
+ if (!Schema_exports.is(RouterKey)(key))
121
+ throw new Error(`Router key "${key}" must start with a letter or _ and contain no dots`);
122
+ const node = nativeNode(value);
123
+ if (node === void 0)
124
+ throw new Error(`Router key "${key}" must be a query, mutation or router`);
125
+ nodes[key] = node;
126
+ }
127
+ return routerDeclaration({ kind: "router", ...withMeta(meta), children: nodes });
128
+ }
129
+ var withMeta = (meta) => meta === void 0 ? {} : { meta };
130
+ var withOverrides = (overrides) => overrides === void 0 ? {} : { overrides };
131
+ var dynamicRouter = (source) => {
132
+ const meta = source.meta;
133
+ return routerDeclaration({
134
+ kind: "dynamic",
135
+ ...meta === void 0 ? {} : {
136
+ meta: () => fromPromise(async () => meta())().pipe(
137
+ Effect_exports.flatMap((options) => Schema_exports.decodeUnknownEffect(RouterMeta)(options))
138
+ )
139
+ },
140
+ list: () => fromPromise(async () => source.list())().pipe(
141
+ Effect_exports.flatMap(Schema_exports.decodeUnknownEffect(Schema_exports.Array(HostedTool)))
142
+ ),
143
+ resolve: (name) => fromPromise(async () => source.resolve(name))().pipe(
144
+ Effect_exports.map((value) => {
145
+ if (value === void 0) return void 0;
146
+ const operation = nativeOperation(value);
147
+ if (operation === void 0) throw new Error("Expected an operation declaration");
148
+ return operation;
149
+ })
150
+ )
151
+ });
152
+ };
153
+ var joinPath = (path, name) => path === "" ? name : `${path}.${name}`;
154
+ var locate = (root, name) => {
155
+ if (root?.kind === "dynamic") return { kind: "dynamic", source: root, router: "", name };
156
+ let current = root;
157
+ let path = "";
158
+ let rest = name;
159
+ while (current !== void 0) {
160
+ const dot = rest.indexOf(".");
161
+ const key = dot < 0 ? rest : rest.slice(0, dot);
162
+ const child = Object.hasOwn(current.children, key) ? current.children[key] : void 0;
163
+ if (child === void 0) return void 0;
164
+ const remaining = dot < 0 ? void 0 : rest.slice(dot + 1);
165
+ switch (child.kind) {
166
+ case "query":
167
+ case "mutation":
168
+ return remaining === void 0 ? { kind: "operation", operation: child, router: path } : void 0;
169
+ case "dynamic":
170
+ return remaining === void 0 || remaining === "" ? void 0 : { kind: "dynamic", source: child, router: joinPath(path, key), name: remaining };
171
+ case "router":
172
+ if (remaining === void 0) return void 0;
173
+ current = child;
174
+ path = joinPath(path, key);
175
+ rest = remaining;
176
+ }
177
+ }
178
+ return void 0;
179
+ };
180
+ var declaredOperations = (root, path = "") => Object.entries(root?.children ?? {}).flatMap(([key, child]) => {
181
+ const name = joinPath(path, key);
182
+ switch (child.kind) {
183
+ case "query":
184
+ case "mutation":
185
+ return [{ name, router: path, operation: child }];
186
+ case "router":
187
+ return declaredOperations(child, name);
188
+ case "dynamic":
189
+ return [];
190
+ }
191
+ });
192
+
193
+ export {
194
+ fromPromise,
195
+ toPromise,
196
+ operationDeclaration,
197
+ nativeOperation,
198
+ withApproval,
199
+ query,
200
+ mutation,
201
+ routerDeclaration,
202
+ nativeRouter,
203
+ mergeMeta,
204
+ router,
205
+ dynamicRouter,
206
+ joinPath,
207
+ locate,
208
+ declaredOperations
209
+ };
@@ -211,7 +211,7 @@ import {
211
211
  withFiber,
212
212
  withParentSpan,
213
213
  zero2 as zero
214
- } from "./chunk-FW5HBOIK.js";
214
+ } from "./chunk-CDL5PM2Q.js";
215
215
  import {
216
216
  __export
217
217
  } from "./chunk-CZ7CSFO4.js";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  Schema_exports
3
- } from "./chunk-FW5HBOIK.js";
3
+ } from "./chunk-CDL5PM2Q.js";
4
4
 
5
5
  // src/contracts/ui-auth.ts
6
6
  var AppSignInId = Schema_exports.String.check(Schema_exports.isPattern(/^[a-f0-9]{64}$/)).pipe(
@@ -1,5 +1,7 @@
1
1
  import {
2
2
  AppDatabaseError,
3
+ DatabaseFieldReserved,
4
+ DatabaseLimitExceeded,
3
5
  DatabaseLimits,
4
6
  DatabaseOperation,
5
7
  DatabaseSchema,
@@ -8,18 +10,21 @@ import {
8
10
  Row,
9
11
  RowMetadata,
10
12
  defaultDatabaseLimits,
11
- defaultDatabaseRuntimeLimits
12
- } from "./chunk-BMOIAIVR.js";
13
+ defaultDatabaseRuntimeLimits,
14
+ reservedFieldNames
15
+ } from "./chunk-N7YDVXYJ.js";
13
16
  import {
17
+ Cause_exports,
14
18
  Clock_exports,
15
19
  Effect_exports,
16
20
  Encoding_exports,
17
21
  Schema_exports,
18
22
  Semaphore_exports
19
- } from "./chunk-FW5HBOIK.js";
23
+ } from "./chunk-CDL5PM2Q.js";
20
24
 
21
25
  // ../app-data/src/implementation/schema.ts
22
- var metadata = /* @__PURE__ */ new Set(["id", "createdAt", "updatedAt"]);
26
+ var metadata = new Set(reservedFieldNames);
27
+ var reserved = (name) => metadata.has(name);
23
28
  var indexesFor = (table) => [{ name: "by_creation", fields: [] }, ...table.indexes].map((index) => ({
24
29
  name: index.name,
25
30
  fields: [
@@ -33,23 +38,25 @@ var validScalar = (field, value) => field.kind === "number" ? typeof value === "
33
38
  return point !== void 0 && point >= 55296 && point <= 57343;
34
39
  });
35
40
  var parseDatabaseSchema = (input) => Schema_exports.decodeUnknownEffect(DatabaseSchema)(input).pipe(
41
+ Effect_exports.mapError(() => new AppDatabaseError({ reason: "schema" })),
36
42
  Effect_exports.flatMap(
37
43
  (schema) => Effect_exports.gen(function* () {
38
- for (const table of Object.values(schema)) {
39
- if (Object.keys(table.fields).some((name) => metadata.has(name)) || new Set(table.indexes.map((index) => index.name)).size !== table.indexes.length)
44
+ for (const [name, table] of Object.entries(schema)) {
45
+ const field = Object.keys(table.fields).find(reserved);
46
+ if (field !== void 0) return yield* new DatabaseFieldReserved({ table: name, field });
47
+ if (new Set(table.indexes.map((index) => index.name)).size !== table.indexes.length)
40
48
  return yield* new AppDatabaseError({ reason: "schema" });
41
- for (const field of Object.values(table.fields)) {
42
- if ((field.kind === "id" ? field.references === void 0 : field.references !== void 0) || field.default !== void 0 && !validScalar(field, field.default) || field.references !== void 0 && !Object.hasOwn(schema, field.references))
49
+ for (const field2 of Object.values(table.fields)) {
50
+ if ((field2.kind === "id" ? field2.references === void 0 : field2.references !== void 0) || field2.default !== void 0 && !validScalar(field2, field2.default) || field2.references !== void 0 && !Object.hasOwn(schema, field2.references))
43
51
  return yield* new AppDatabaseError({ reason: "schema" });
44
52
  }
45
53
  for (const index of table.indexes)
46
- if (index.name === "by_creation" || new Set(index.fields).size !== index.fields.length || index.fields.some((name) => fieldFor(table, name) === void 0))
54
+ if (index.name === "by_creation" || new Set(index.fields).size !== index.fields.length || index.fields.some((name2) => fieldFor(table, name2) === void 0))
47
55
  return yield* new AppDatabaseError({ reason: "schema" });
48
56
  }
49
57
  return schema;
50
58
  })
51
- ),
52
- Effect_exports.mapError(() => new AppDatabaseError({ reason: "schema" }))
59
+ )
53
60
  );
54
61
  var canonicalSchema = (schema) => JSON.stringify(
55
62
  Object.fromEntries(
@@ -248,7 +255,12 @@ var decodeBody = Schema_exports.decodeUnknownEffect(Schema_exports.fromJsonStrin
248
255
  var storageError = () => new AppDatabaseError({ reason: "storage" });
249
256
  var makeSqliteDatabase = (options) => Effect_exports.gen(function* () {
250
257
  const { sql, crypto } = options;
251
- const schema = yield* parseDatabaseSchema(options.schema);
258
+ const schema = yield* parseDatabaseSchema(options.schema).pipe(
259
+ Effect_exports.catchTag(
260
+ "DatabaseFieldReserved",
261
+ () => Effect_exports.fail(new AppDatabaseError({ reason: "schema" }))
262
+ )
263
+ );
252
264
  const limits = yield* Schema_exports.decodeUnknownEffect(DatabaseLimits)(
253
265
  options.limits ?? defaultDatabaseLimits
254
266
  ).pipe(Effect_exports.mapError(() => new AppDatabaseError({ reason: "limit" })));
@@ -295,7 +307,13 @@ var makeSqliteDatabase = (options) => Effect_exports.gen(function* () {
295
307
  };
296
308
  const charge = (name, amount) => Effect_exports.suspend(() => {
297
309
  used[name] += amount;
298
- return used[name] > limits[name] ? Effect_exports.fail(new AppDatabaseError({ reason: "limit" })) : Effect_exports.void;
310
+ return used[name] > limits[name] ? Effect_exports.fail(
311
+ new DatabaseLimitExceeded({
312
+ limit: name,
313
+ maximum: limits[name],
314
+ requested: used[name]
315
+ })
316
+ ) : Effect_exports.void;
299
317
  });
300
318
  const get = (table, id) => Effect_exports.gen(function* () {
301
319
  yield* charge("directGets", 1);
@@ -312,8 +330,13 @@ var makeSqliteDatabase = (options) => Effect_exports.gen(function* () {
312
330
  const store = (tableName, table, row) => Effect_exports.gen(function* () {
313
331
  const meta = yield* Schema_exports.decodeUnknownEffect(RowMetadata)(row);
314
332
  const body = JSON.stringify(row);
315
- if (new TextEncoder().encode(body).length > limits.valueBytes)
316
- return yield* new AppDatabaseError({ reason: "limit" });
333
+ const bytes = new TextEncoder().encode(body).length;
334
+ if (bytes > limits.valueBytes)
335
+ return yield* new DatabaseLimitExceeded({
336
+ limit: "valueBytes",
337
+ maximum: limits.valueBytes,
338
+ requested: bytes
339
+ });
317
340
  const keys = yield* Effect_exports.forEach(
318
341
  indexesFor(table),
319
342
  (index) => encodeIndexKey(
@@ -384,9 +407,14 @@ var makeSqliteDatabase = (options) => Effect_exports.gen(function* () {
384
407
  const bounds = yield* queryBounds(table, plan, limits.indexBytes);
385
408
  reads.add(tableName);
386
409
  yield* charge("scanCalls", 1);
387
- const maximum = terminal.kind === "count" ? limits.rowsRead - used.rowsRead : limits.rowsReturned - used.rowsReturned;
388
- const count = terminal.kind === "first" ? 1 : terminal.kind === "take" ? terminal.count : terminal.kind === "paginate" ? terminal.numItems : maximum;
389
- if (count > maximum) return yield* new AppDatabaseError({ reason: "limit" });
410
+ const remaining = terminal.kind === "count" ? limits.rowsRead - used.rowsRead : limits.rowsReturned - used.rowsReturned;
411
+ const count = terminal.kind === "first" ? 1 : terminal.kind === "take" ? terminal.count : terminal.kind === "paginate" ? terminal.numItems : remaining;
412
+ if ((terminal.kind === "take" || terminal.kind === "paginate") && count > limits.rowsReturned)
413
+ return yield* new DatabaseLimitExceeded({
414
+ limit: "pageSize",
415
+ maximum: limits.rowsReturned,
416
+ requested: count
417
+ });
390
418
  if (count === 0 && terminal.kind === "take") return [];
391
419
  const query = yield* fingerprint(
392
420
  crypto,
@@ -412,7 +440,10 @@ var makeSqliteDatabase = (options) => Effect_exports.gen(function* () {
412
440
  plan.order === "asc" ? sql`i.sort_key > ${position}` : sql`i.sort_key < ${position}`
413
441
  );
414
442
  const direction = plan.order === "asc" ? sql.literal("ASC") : sql.literal("DESC");
415
- const limit = terminal.kind === "first" || terminal.kind === "take" ? count : count + 1;
443
+ const limit = Math.min(
444
+ terminal.kind === "first" || terminal.kind === "take" ? count : count + 1,
445
+ remaining + 1
446
+ );
416
447
  if (terminal.kind === "count") {
417
448
  const rows2 = yield* sql`SELECT i.sort_key FROM app_indexes i WHERE ${sql.and(predicates)} ORDER BY i.sort_key ${direction} LIMIT ${limit}`.pipe(
418
449
  Effect_exports.flatMap(Schema_exports.decodeUnknownEffect(Schema_exports.Array(CountRow)))
@@ -436,7 +467,11 @@ var makeSqliteDatabase = (options) => Effect_exports.gen(function* () {
436
467
  )
437
468
  );
438
469
  if (terminal.kind === "collect" && rows.length > count)
439
- return yield* new AppDatabaseError({ reason: "limit" });
470
+ return yield* new DatabaseLimitExceeded({
471
+ limit: "rowsReturned",
472
+ maximum: limits.rowsReturned,
473
+ requested: used.rowsReturned + rows.length
474
+ });
440
475
  const page = rows.slice(0, count);
441
476
  yield* charge("rowsReturned", page.length);
442
477
  const values = yield* Effect_exports.forEach(page, (row) => decodeBody(row.body));
@@ -502,6 +537,11 @@ var makeSqliteDatabase = (options) => Effect_exports.gen(function* () {
502
537
  })
503
538
  };
504
539
  return yield* Effect_exports.suspend(() => work(session)).pipe(
540
+ // A failed database call poisons the session. Report that failure even when
541
+ // authored code caught it or threw something else in its place.
542
+ Effect_exports.catchCause(
543
+ (cause) => failed === void 0 || Cause_exports.hasInterrupts(cause) ? Effect_exports.failCause(cause) : Effect_exports.fail(failed)
544
+ ),
505
545
  Effect_exports.tap(
506
546
  () => gate.withPermits(1)(
507
547
  Effect_exports.suspend(() => failed === void 0 ? Effect_exports.void : Effect_exports.fail(failed))
package/js/client.js CHANGED
@@ -4,14 +4,14 @@ import {
4
4
  UiContext,
5
5
  UiDeploymentChanged,
6
6
  UiFailed
7
- } from "./chunk-G7ZIRKMK.js";
7
+ } from "./chunk-IJX4CYZO.js";
8
8
  import {
9
9
  AsyncResult_exports,
10
10
  AtomRegistry_exports,
11
11
  Atom_exports,
12
12
  queryResult
13
- } from "./chunk-EVJUVWN2.js";
14
- import "./chunk-M6ZRRIBI.js";
13
+ } from "./chunk-M3B3DE4K.js";
14
+ import "./chunk-PJJ24GU7.js";
15
15
  import {
16
16
  OtlpExporter_exports,
17
17
  TraceContext,
@@ -19,22 +19,22 @@ import {
19
19
  pendingSpan,
20
20
  telemetryLayer,
21
21
  traceLinks
22
- } from "./chunk-ZCAMUXSG.js";
22
+ } from "./chunk-RJDDBDSN.js";
23
23
  import {
24
24
  FetchHttpClient_exports
25
- } from "./chunk-HDJH3RPR.js";
25
+ } from "./chunk-57RKNWL2.js";
26
26
  import {
27
27
  HttpClientError_exports
28
- } from "./chunk-QKHR7BMF.js";
28
+ } from "./chunk-UK573G7W.js";
29
29
  import {
30
30
  decoderOf
31
- } from "./chunk-WFSQXYUT.js";
31
+ } from "./chunk-5T57N25Q.js";
32
32
  import {
33
33
  StorageName
34
- } from "./chunk-FZJOYIZO.js";
34
+ } from "./chunk-PZB6T6KU.js";
35
35
  import {
36
36
  JsonValue
37
- } from "./chunk-SATWJKN6.js";
37
+ } from "./chunk-27F7W2LG.js";
38
38
  import {
39
39
  Cause_exports,
40
40
  Clock_exports,
@@ -52,7 +52,7 @@ import {
52
52
  Semaphore_exports,
53
53
  Stream_exports,
54
54
  Tracer_exports
55
- } from "./chunk-FW5HBOIK.js";
55
+ } from "./chunk-CDL5PM2Q.js";
56
56
  import "./chunk-CZ7CSFO4.js";
57
57
 
58
58
  // src/contracts/live.ts
package/js/contracts.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import {
2
+ ApiErrorResponse,
2
3
  ApprovalElicitation,
3
4
  ApprovalResponse,
4
5
  CalendarSchedule,
@@ -9,6 +10,11 @@ import {
9
10
  ElicitationLimits,
10
11
  ElicitationReply,
11
12
  ElicitationResponse,
13
+ FailureCode,
14
+ FailureDetail,
15
+ FailureMessage,
16
+ FailureName,
17
+ FailureSource,
12
18
  FormElicitation,
13
19
  HostAccountsInvalid,
14
20
  HostCallError,
@@ -19,6 +25,7 @@ import {
19
25
  HostInputInvalid,
20
26
  HostInspectError,
21
27
  HostInvocation,
28
+ HostKindMismatch,
22
29
  HostOperationFailed,
23
30
  HostOperationNotFound,
24
31
  HostOutputInvalid,
@@ -26,10 +33,14 @@ import {
26
33
  HostRequestInvalid,
27
34
  HostRequirementsError,
28
35
  HostResponse,
36
+ HostRouterError,
29
37
  HostToolApprovalRequired,
30
38
  HostToolBlocked,
31
39
  HostToolNotFound,
32
40
  HostToolPolicyFailed,
41
+ HostedCatalog,
42
+ HostedCatalogSummary,
43
+ HostedRouter,
33
44
  HostedTool,
34
45
  HostedToolSummary,
35
46
  HostedWebhook,
@@ -44,10 +55,13 @@ import {
44
55
  NonRetryableError,
45
56
  OAuthClientAuth,
46
57
  OAuthSecretClientAuth,
58
+ OpenapiResponseError,
47
59
  OperationSchedule,
48
- OperationToolPrefixes,
49
60
  ResolvedAccount,
50
61
  ResolvedAccounts,
62
+ RouterIcon,
63
+ RouterKey,
64
+ RouterMeta,
51
65
  ScheduleTiming,
52
66
  SkillCatalogResponse,
53
67
  SkillSources,
@@ -61,11 +75,13 @@ import {
61
75
  WorkflowControlCommand,
62
76
  WorkflowDuration,
63
77
  WorkflowFailure,
78
+ WorkflowFailureDetail,
64
79
  WorkflowName,
65
80
  WorkflowReplay,
66
81
  WorkflowRpcCommand,
67
82
  WorkflowRpcResult,
68
83
  WorkflowRun,
84
+ WorkflowRunFailure,
69
85
  WorkflowRunId,
70
86
  WorkflowRunPage,
71
87
  WorkflowStepOptions,
@@ -77,17 +93,25 @@ import {
77
93
  frameworkProtocol,
78
94
  indexCommand,
79
95
  inspectCommand,
96
+ maxFailureMessageLength,
80
97
  maxInputProblems,
81
98
  minimumIntervalMilliseconds,
82
99
  protocol1,
83
100
  protocol2,
101
+ protocol3,
102
+ protocol4,
84
103
  selectTools,
85
104
  skillCatalog,
86
105
  skillsCommand,
87
106
  workflowDurationMillis
88
- } from "./chunk-3M2MEDNL.js";
89
- import "./chunk-BMOIAIVR.js";
90
- import "./chunk-LGIYBDWA.js";
107
+ } from "./chunk-B3EOZTK3.js";
108
+ import {
109
+ DatabaseFieldReserved,
110
+ DatabaseLimitExceeded
111
+ } from "./chunk-N7YDVXYJ.js";
112
+ import {
113
+ ProviderError
114
+ } from "./chunk-R3EV5FTO.js";
91
115
  import {
92
116
  AppSkillMetadata,
93
117
  AppSkillName,
@@ -100,24 +124,17 @@ import {
100
124
  SkillServiceName,
101
125
  skillFormatLimits,
102
126
  skillLoadLimits
103
- } from "./chunk-YEJOQEII.js";
104
- import {
105
- ApiErrorResponse,
106
- OpenapiResponseError
107
- } from "./chunk-SWPD52J7.js";
108
- import {
109
- ProviderError
110
- } from "./chunk-W7D7WVSY.js";
127
+ } from "./chunk-JU7VHODU.js";
111
128
  import {
112
129
  AppStorageError,
113
130
  AppStorageUnavailable,
114
131
  StorageName
115
- } from "./chunk-FZJOYIZO.js";
132
+ } from "./chunk-PZB6T6KU.js";
116
133
  import {
117
134
  AccountId,
118
135
  HttpUrl
119
- } from "./chunk-SATWJKN6.js";
120
- import "./chunk-FW5HBOIK.js";
136
+ } from "./chunk-27F7W2LG.js";
137
+ import "./chunk-CDL5PM2Q.js";
121
138
  import "./chunk-CZ7CSFO4.js";
122
139
  export {
123
140
  AccountId,
@@ -131,6 +148,8 @@ export {
131
148
  ApprovalElicitation,
132
149
  ApprovalResponse,
133
150
  CalendarSchedule,
151
+ DatabaseFieldReserved,
152
+ DatabaseLimitExceeded,
134
153
  DeclaredAuthMethod,
135
154
  DeclaredProvider,
136
155
  DeclaredRequirements,
@@ -138,6 +157,11 @@ export {
138
157
  ElicitationLimits,
139
158
  ElicitationReply,
140
159
  ElicitationResponse,
160
+ FailureCode,
161
+ FailureDetail,
162
+ FailureMessage,
163
+ FailureName,
164
+ FailureSource,
141
165
  FormElicitation,
142
166
  HostAccountsInvalid,
143
167
  HostCallError,
@@ -148,6 +172,7 @@ export {
148
172
  HostInputInvalid,
149
173
  HostInspectError,
150
174
  HostInvocation,
175
+ HostKindMismatch,
151
176
  HostOperationFailed,
152
177
  HostOperationNotFound,
153
178
  HostOutputInvalid,
@@ -155,10 +180,14 @@ export {
155
180
  HostRequestInvalid,
156
181
  HostRequirementsError,
157
182
  HostResponse,
183
+ HostRouterError,
158
184
  HostToolApprovalRequired,
159
185
  HostToolBlocked,
160
186
  HostToolNotFound,
161
187
  HostToolPolicyFailed,
188
+ HostedCatalog,
189
+ HostedCatalogSummary,
190
+ HostedRouter,
162
191
  HostedTool,
163
192
  HostedToolSummary,
164
193
  HostedWebhook,
@@ -176,10 +205,12 @@ export {
176
205
  OAuthSecretClientAuth,
177
206
  OpenapiResponseError,
178
207
  OperationSchedule,
179
- OperationToolPrefixes,
180
208
  ProviderError,
181
209
  ResolvedAccount,
182
210
  ResolvedAccounts,
211
+ RouterIcon,
212
+ RouterKey,
213
+ RouterMeta,
183
214
  ScheduleTiming,
184
215
  SkillCatalogResponse,
185
216
  SkillDefinitionInvalid,
@@ -199,11 +230,13 @@ export {
199
230
  WorkflowControlCommand,
200
231
  WorkflowDuration,
201
232
  WorkflowFailure,
233
+ WorkflowFailureDetail,
202
234
  WorkflowName,
203
235
  WorkflowReplay,
204
236
  WorkflowRpcCommand,
205
237
  WorkflowRpcResult,
206
238
  WorkflowRun,
239
+ WorkflowRunFailure,
207
240
  WorkflowRunId,
208
241
  WorkflowRunPage,
209
242
  WorkflowStepOptions,
@@ -215,10 +248,13 @@ export {
215
248
  frameworkProtocol,
216
249
  indexCommand,
217
250
  inspectCommand,
251
+ maxFailureMessageLength,
218
252
  maxInputProblems,
219
253
  minimumIntervalMilliseconds,
220
254
  protocol1,
221
255
  protocol2,
256
+ protocol3,
257
+ protocol4,
222
258
  selectTools,
223
259
  skillCatalog,
224
260
  skillFormatLimits,