apps 0.0.1-beta.43 → 0.0.1-beta.46

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 (54) hide show
  1. package/framework-reference.json +1 -1
  2. package/js/{chunk-XSD3RZFX.js → chunk-3B2JAOSE.js} +23 -12
  3. package/js/{chunk-KTPKTBKZ.js → chunk-3UGDI2UI.js} +5 -5
  4. package/js/chunk-5FHWNLCI.js +88 -0
  5. package/js/{chunk-MSDGZ7FA.js → chunk-6QXPBJ5T.js} +14 -13
  6. package/js/{chunk-Z3S2IVI3.js → chunk-7LGRK7TP.js} +2 -2
  7. package/js/{chunk-T65AFHU3.js → chunk-7UUHJR2Q.js} +1 -1
  8. package/js/{chunk-4ZTVLEN6.js → chunk-CDXQDN7W.js} +1 -1
  9. package/js/{chunk-OBXHQNWC.js → chunk-CVAJ4F6O.js} +16 -3
  10. package/js/{chunk-KBIKBWSS.js → chunk-H72MEDMN.js} +4 -3
  11. package/js/{chunk-VU6GQ2SH.js → chunk-JM7LOD2W.js} +212 -22
  12. package/js/{chunk-EJUK2NK5.js → chunk-KLYSEHUD.js} +1 -1
  13. package/js/{chunk-ILYK7BQG.js → chunk-LHCGND3R.js} +12 -46
  14. package/js/{chunk-EMHFXFTJ.js → chunk-LTDHQJ2Z.js} +53 -0
  15. package/js/{chunk-47BLLMRQ.js → chunk-OJ47HQVJ.js} +143 -65
  16. package/js/{chunk-MZH4J2PO.js → chunk-PD6I2SDG.js} +1 -1
  17. package/js/{chunk-KSGYJV46.js → chunk-TUMGL2OC.js} +1 -1
  18. package/js/{chunk-5GLC42LK.js → chunk-UM62MBJQ.js} +42 -24
  19. package/js/{chunk-IN2WIN7I.js → chunk-XBG7HHXC.js} +1 -1
  20. package/js/{chunk-RIKH5H2X.js → chunk-XK5I2XOI.js} +39 -29
  21. package/js/client.js +9 -9
  22. package/js/contracts.js +9 -5
  23. package/js/effect.js +14 -14
  24. package/js/graphql.js +23 -21
  25. package/js/host.js +79 -54
  26. package/js/index.js +23 -18
  27. package/js/mcp/effect.js +16 -16
  28. package/js/mcp/stdio.js +30 -25
  29. package/js/mcp.js +23 -21
  30. package/js/openapi.js +106 -80
  31. package/js/skills/effect.js +5 -5
  32. package/js/skills.js +53 -36
  33. package/js/ui/auth.js +3 -3
  34. package/js/ui/contracts.js +3 -3
  35. package/js/ui/serving.js +7 -7
  36. package/package.json +1 -1
  37. package/runtime.json +1 -1
  38. package/types/apps/src/contracts/host.d.ts +15 -0
  39. package/types/apps/src/host.d.ts +5 -0
  40. package/types/apps/src/implementation/authoring.d.ts +25 -5
  41. package/types/apps/src/implementation/cache.d.ts +4 -0
  42. package/types/apps/src/implementation/elicitation.d.ts +6 -3
  43. package/types/apps/src/implementation/invocation-timing.d.ts +16 -0
  44. package/types/apps/src/implementation/operations.d.ts +2 -2
  45. package/types/apps/src/implementation/router-catalog.d.ts +4 -4
  46. package/types/apps/src/implementation/workflows.d.ts +1 -1
  47. package/types/telemetry/src/index.d.ts +1 -0
  48. package/types/telemetry/src/ownership.d.ts +56 -0
  49. package/types/telemetry/src/recorded-failure.d.ts +20 -11
  50. package/types/utils/src/api-error.d.ts +4 -2
  51. package/types/utils/src/recorded-message.d.ts +7 -4
  52. package/types/utils/src/user-facing-error.d.ts +4 -2
  53. package/js/chunk-EG72MSVK.js +0 -16
  54. package/js/{chunk-LNSVJS2Q.js → chunk-EOPQ727L.js} +2 -2
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  FetchHttpClient_exports
3
- } from "./chunk-MZH4J2PO.js";
3
+ } from "./chunk-PD6I2SDG.js";
4
4
  import {
5
5
  recordedMessage
6
- } from "./chunk-EG72MSVK.js";
6
+ } from "./chunk-5FHWNLCI.js";
7
7
  import {
8
8
  HttpBody_exports,
9
9
  HttpClient,
@@ -23,7 +23,7 @@ import {
23
23
  tapError,
24
24
  transformResponse,
25
25
  uint8Array
26
- } from "./chunk-LNSVJS2Q.js";
26
+ } from "./chunk-EOPQ727L.js";
27
27
  import {
28
28
  Array as Array2,
29
29
  Boolean2 as Boolean,
@@ -44,6 +44,7 @@ import {
44
44
  Logger_exports,
45
45
  Metric_exports,
46
46
  Option_exports,
47
+ Predicate_exports,
47
48
  Record2 as Record,
48
49
  Redacted_exports,
49
50
  Schedule_exports,
@@ -138,6 +139,145 @@ import {
138
139
  __export
139
140
  } from "./chunk-CZ7CSFO4.js";
140
141
 
142
+ // ../telemetry/src/ownership.ts
143
+ var ownerAttribute = "executor.owner";
144
+ var SpanOwner = Context_exports.Reference("@executor-js/telemetry/SpanOwner", {
145
+ defaultValue: () => void 0
146
+ });
147
+ var declaredOwner = (annotations) => Context_exports.get(annotations, SpanOwner);
148
+ var ownedBy = (owner, options = {}) => ({
149
+ ...options,
150
+ annotations: Context_exports.add(options.annotations ?? Context_exports.empty(), SpanOwner, owner)
151
+ });
152
+ var owned = (owner, name, options) => (effect2) => effect2.pipe(Effect_exports.withSpan(name, ownedBy(owner, options)));
153
+ var measuredSpan = (name, options, measure) => (effect2) => Effect_exports.useSpan(name, options, (span) => {
154
+ const inner = Effect_exports.withParentSpan(effect2, span);
155
+ if (span.status._tag === "Ended") return inner;
156
+ const { around, end } = measure(span.status.startTime);
157
+ return (around === void 0 ? inner : around(inner)).pipe(
158
+ Effect_exports.onExit(
159
+ (exit) => Effect_exports.flatMap(
160
+ Clock_exports.currentTimeNanos,
161
+ (now) => Effect_exports.sync(() => {
162
+ end(now, span);
163
+ span.end(now, exit);
164
+ })
165
+ )
166
+ )
167
+ );
168
+ });
169
+ var concurrent = ["executor", "person", "upstream", "app"];
170
+ var makeOwnershipAccounting = (origin, owner) => {
171
+ const totals = { executor: 0, app: 0, upstream: 0, person: 0 };
172
+ const innermost = { executor: 0, app: 0, upstream: 0, person: 0 };
173
+ const boundaries2 = /* @__PURE__ */ new WeakMap();
174
+ let reached = origin;
175
+ let done = false;
176
+ const advance = (time) => {
177
+ if (time <= reached) return;
178
+ const current = concurrent.find((candidate) => innermost[candidate] > 0) ?? owner;
179
+ totals[current] += Number(time - reached) / 1e6;
180
+ reached = time;
181
+ };
182
+ const enclosing = (boundary) => {
183
+ let found = boundary.parent;
184
+ while (found !== void 0 && !found.open) found = found.parent;
185
+ boundary.parent = found;
186
+ return found;
187
+ };
188
+ const opened = (boundary) => {
189
+ const parent = enclosing(boundary);
190
+ if (parent !== void 0 && parent.children++ === 0) innermost[parent.owner] -= 1;
191
+ innermost[boundary.owner] += 1;
192
+ };
193
+ const closed = (boundary) => {
194
+ boundary.open = false;
195
+ if (boundary.children === 0) innermost[boundary.owner] -= 1;
196
+ const parent = enclosing(boundary);
197
+ if (parent === void 0) return;
198
+ parent.children += boundary.children - 1;
199
+ if (parent.children === 0) innermost[parent.owner] += 1;
200
+ };
201
+ const observed = (tracer) => ({
202
+ ...tracer,
203
+ span: (options) => {
204
+ const span = tracer.span(options);
205
+ if (done) return span;
206
+ const parent = Option_exports.getOrUndefined(options.parent);
207
+ const enclosingBoundary = parent === void 0 ? void 0 : boundaries2.get(parent);
208
+ const boundary = {
209
+ owner: declaredOwner(options.annotations) ?? enclosingBoundary?.owner ?? owner,
210
+ parent: enclosingBoundary,
211
+ open: true,
212
+ children: 0
213
+ };
214
+ advance(options.startTime);
215
+ opened(boundary);
216
+ const tracked = {
217
+ _tag: "Span",
218
+ get name() {
219
+ return span.name;
220
+ },
221
+ get spanId() {
222
+ return span.spanId;
223
+ },
224
+ get traceId() {
225
+ return span.traceId;
226
+ },
227
+ get parent() {
228
+ return span.parent;
229
+ },
230
+ get annotations() {
231
+ return span.annotations;
232
+ },
233
+ get status() {
234
+ return span.status;
235
+ },
236
+ get attributes() {
237
+ return span.attributes;
238
+ },
239
+ get links() {
240
+ return span.links;
241
+ },
242
+ get sampled() {
243
+ return span.sampled;
244
+ },
245
+ get kind() {
246
+ return span.kind;
247
+ },
248
+ end: (endTime, exit) => {
249
+ if (boundary.open && !done) {
250
+ advance(endTime);
251
+ closed(boundary);
252
+ }
253
+ span.end(endTime, exit);
254
+ },
255
+ attribute: (key, value) => span.attribute(key, value),
256
+ event: (name, startTime, attributes2) => span.event(name, startTime, attributes2),
257
+ addLinks: (links) => span.addLinks(links)
258
+ };
259
+ boundaries2.set(tracked, boundary);
260
+ return tracked;
261
+ }
262
+ });
263
+ return {
264
+ /** Run `effect` with the spans it opens observed, including spans it hands to later work. */
265
+ observe: (effect2) => Effect_exports.gen(function* () {
266
+ const tracer = yield* Tracer_exports.Tracer;
267
+ return yield* effect2.pipe(Effect_exports.provideService(Tracer_exports.Tracer, observed(tracer)));
268
+ }),
269
+ /**
270
+ * Close the window at `end` and return its milliseconds by owner, each instant counted once.
271
+ * Spans still open count up to `end`; spans that open or end afterwards are ignored.
272
+ */
273
+ read: (end) => {
274
+ if (!done) advance(end);
275
+ done = true;
276
+ return totals;
277
+ }
278
+ };
279
+ };
280
+
141
281
  // ../telemetry/src/context.ts
142
282
  var captureTelemetry = Effect_exports.gen(function* () {
143
283
  let context2 = Context_exports.make(Tracer_exports.Tracer, yield* Tracer_exports.Tracer).pipe(
@@ -169,9 +309,10 @@ var invocationFetch = (signal) => Effect_exports.gen(function* () {
169
309
  const request = yield* Effect_exports.try(() => new Request(input, init));
170
310
  const client = yield* HttpClient_exports.HttpClient;
171
311
  const response = yield* client.execute(HttpClientRequest_exports.fromWeb(request)).pipe(
172
- Effect_exports.withSpan("provider.http.request", {
173
- attributes: { "http.request.method": request.method }
174
- }),
312
+ Effect_exports.withSpan(
313
+ "provider.http.request",
314
+ ownedBy("upstream", { attributes: { "http.request.method": request.method } })
315
+ ),
175
316
  Effect_exports.provideService(FetchHttpClient_exports.RequestInit, {
176
317
  cache: request.cache,
177
318
  credentials: request.credentials,
@@ -200,9 +341,12 @@ var invocationFetch = (signal) => Effect_exports.gen(function* () {
200
341
  streamed,
201
342
  HttpBody_exports.stream(
202
343
  body.stream.pipe(
203
- Stream_exports.withSpan("provider.http.response.read", {
204
- attributes: { "http.response.status_code": response.status }
205
- })
344
+ Stream_exports.withSpan(
345
+ "provider.http.response.read",
346
+ ownedBy("upstream", {
347
+ attributes: { "http.response.status_code": response.status }
348
+ })
349
+ )
206
350
  ),
207
351
  body.contentType,
208
352
  body.contentLength
@@ -882,18 +1026,29 @@ var retryTelemetryExport = (client) => client.pipe(
882
1026
  );
883
1027
 
884
1028
  // ../telemetry/src/recorded-failure.ts
1029
+ var tagOf = (error) => Predicate_exports.hasProperty(error, "_tag") && Predicate_exports.isString(error._tag) ? error._tag : void 0;
1030
+ var recorded = (name, message) => {
1031
+ const error = new Error(message);
1032
+ error.name = name;
1033
+ error.stack = message === "" ? name : `${name}: ${message}`;
1034
+ return error;
1035
+ };
885
1036
  var recordedError = (error) => {
886
- const message = recordedMessage(error);
887
- if (message === void 0 || !(error instanceof Error)) return error;
888
- const recorded = new Error(message);
889
- recorded.name = error.name;
890
- recorded.stack = `${error.name}: ${message}`;
891
- return recorded;
1037
+ const tag = tagOf(error);
1038
+ if (tag !== void 0) return recorded(tag, recordedMessage(error) ?? "");
1039
+ if (!(error instanceof Error)) return recorded("UnrecognizedFailure", "");
1040
+ if (error.cause === void 0) return error;
1041
+ const copy = new Error(error.message, { cause: recordedError(error.cause) });
1042
+ copy.name = error.name;
1043
+ if (error.stack !== void 0) copy.stack = error.stack;
1044
+ return copy;
892
1045
  };
893
1046
  var recordedCause = (cause) => Cause_exports.fromReasons(
894
- Cause_exports.map(cause, recordedError).reasons.flatMap(
895
- (reason) => Cause_exports.isDieReason(reason) && recordedMessage(reason.defect) !== void 0 ? Cause_exports.annotate(Cause_exports.die(recordedError(reason.defect)), Cause_exports.reasonAnnotations(reason)).reasons : [reason]
896
- )
1047
+ cause.reasons.flatMap((reason) => {
1048
+ if (Cause_exports.isInterruptReason(reason)) return [reason];
1049
+ const replaced = Cause_exports.isFailReason(reason) ? Cause_exports.fail(recordedError(reason.error)) : Cause_exports.die(recordedError(reason.defect));
1050
+ return Cause_exports.annotate(replaced, Cause_exports.reasonAnnotations(reason)).reasons;
1051
+ })
897
1052
  );
898
1053
 
899
1054
  // ../telemetry/src/span-attributes.ts
@@ -979,6 +1134,8 @@ var spanAttributes = (clock, recordAll = false) => Layer_exports.effect(Tracer_e
979
1134
  if (recordAll && Option_exports.isSome(options.parent) && options.parent.value._tag === "ExternalSpan")
980
1135
  span.attribute("executor.trace.parent_sampled", options.parent.value.sampled);
981
1136
  if (clock !== void 0) span.attribute("executor.clock.type", clock);
1137
+ const owner = declaredOwner(options.annotations);
1138
+ if (owner !== void 0) span.attribute(ownerAttribute, owner);
982
1139
  return span;
983
1140
  }
984
1141
  }))
@@ -2332,10 +2489,15 @@ var appSpanNames = /* @__PURE__ */ new Set([
2332
2489
  "app.catalog.read",
2333
2490
  "app.skills.load",
2334
2491
  "app.skills.routers",
2492
+ "app.tool.resolve",
2335
2493
  "app.tool.approval",
2336
2494
  "app.tool.elicitation",
2495
+ "app.elicitation.wait",
2496
+ "app.workflow.control",
2337
2497
  "app.operation.execute",
2338
2498
  "app.sql.migrate",
2499
+ "app.code",
2500
+ "app.cache.call",
2339
2501
  "app.cache.get",
2340
2502
  "app.cache.load",
2341
2503
  "app.cache.command",
@@ -2479,6 +2641,10 @@ var status = (value) => {
2479
2641
  const found = integer(value);
2480
2642
  return found !== void 0 && found >= 100 && found <= 599 ? { intValue: found } : void 0;
2481
2643
  };
2644
+ var duration = (value) => {
2645
+ const found = typeof value["doubleValue"] === "number" ? value["doubleValue"] : integer(value);
2646
+ return found !== void 0 && Number.isFinite(found) && found >= 0 ? { doubleValue: found } : void 0;
2647
+ };
2482
2648
  var spanAttributes2 = {
2483
2649
  "executor.operation": oneOf(...operations, "mutation", "discover"),
2484
2650
  "executor.outcome": oneOf("failed"),
@@ -2517,7 +2683,28 @@ var spanAttributes2 = {
2517
2683
  "url.scheme": oneOf("http", "https"),
2518
2684
  "span.label": oneOf("\u26A0\uFE0E Interrupted"),
2519
2685
  "status.interrupted": flag,
2520
- "executor.milestone.reached": flag
2686
+ "executor.milestone.reached": flag,
2687
+ "executor.owner": oneOf("executor", "app", "upstream", "person"),
2688
+ "executor.app.code": oneOf(
2689
+ "factory",
2690
+ "router",
2691
+ "approval",
2692
+ "handler",
2693
+ "loader",
2694
+ "cache",
2695
+ "webhook",
2696
+ "check",
2697
+ "skills",
2698
+ "elicitation",
2699
+ "workflow",
2700
+ "step"
2701
+ ),
2702
+ "executor.workflow.operation": oneOf("start", "get", "list", "terminate"),
2703
+ "cache.method": oneOf("get", "revalidate", "read", "readMany", "write", "invalidate"),
2704
+ "executor.upstream.wait_ms": duration,
2705
+ "executor.elicitation.wait_ms": duration,
2706
+ "executor.authored_ms": duration,
2707
+ "executor.overhead_ms": duration
2521
2708
  };
2522
2709
  var appSpanAttributeKeys = new Set(Object.keys(spanAttributes2));
2523
2710
  var logMessages = /* @__PURE__ */ new Set([
@@ -2543,15 +2730,15 @@ var exception = (event) => {
2543
2730
  (attribute) => isObject(attribute) && attribute["key"] === "exception.type"
2544
2731
  );
2545
2732
  const type = isObject(named) && isObject(named["value"]) ? text(named["value"]) : void 0;
2546
- const recorded = type !== void 0 && errorKinds.has(type) ? type : unrecognized;
2733
+ const recorded2 = type !== void 0 && errorKinds.has(type) ? type : unrecognized;
2547
2734
  const time = nanos(event["timeUnixNano"]);
2548
2735
  return {
2549
2736
  name: "exception",
2550
2737
  ...time === void 0 ? {} : { timeUnixNano: time },
2551
2738
  attributes: [
2552
- { key: "exception.type", value: { stringValue: recorded } },
2739
+ { key: "exception.type", value: { stringValue: recorded2 } },
2553
2740
  { key: "exception.message", value: { stringValue: appText } },
2554
- { key: "exception.stacktrace", value: { stringValue: `${recorded}: ${appText}` } }
2741
+ { key: "exception.stacktrace", value: { stringValue: `${recorded2}: ${appText}` } }
2555
2742
  ]
2556
2743
  };
2557
2744
  };
@@ -2856,6 +3043,9 @@ var pendingSpan = (name, options) => Effect_exports.gen(function* () {
2856
3043
 
2857
3044
  export {
2858
3045
  CurrentTelemetryConfig,
3046
+ owned,
3047
+ measuredSpan,
3048
+ makeOwnershipAccounting,
2859
3049
  OtlpExporter_exports,
2860
3050
  telemetryLayer,
2861
3051
  captureTelemetry,
@@ -3,7 +3,7 @@ import {
3
3
  } from "./chunk-JPEUKEV4.js";
4
4
  import {
5
5
  HttpServerResponse_exports
6
- } from "./chunk-LNSVJS2Q.js";
6
+ } from "./chunk-EOPQ727L.js";
7
7
 
8
8
  // src/implementation/ui-auth.ts
9
9
  var appPrivateHeaders = {
@@ -1,9 +1,12 @@
1
+ import {
2
+ fromPromise
3
+ } from "./chunk-LTDHQJ2Z.js";
1
4
  import {
2
5
  HostedTool,
3
6
  RouterKey,
4
7
  RouterMeta,
5
8
  reservedRouterKeys
6
- } from "./chunk-OBXHQNWC.js";
9
+ } from "./chunk-CVAJ4F6O.js";
7
10
  import {
8
11
  decoderOf,
9
12
  schemaArgument
@@ -13,38 +16,6 @@ import {
13
16
  Schema_exports
14
17
  } from "./chunk-IFJU5SYQ.js";
15
18
 
16
- // src/implementation/authoring.ts
17
- var NativeCallback = /* @__PURE__ */ Symbol("apps.NativeCallback");
18
- var fromPromise = (callback) => (...args) => {
19
- if (NativeCallback in callback) {
20
- const native = callback[NativeCallback];
21
- return native(...args);
22
- }
23
- return Effect_exports.tryPromise({ try: () => callback(...args), catch: (error) => error });
24
- };
25
- var toPromise = (operation, signal) => {
26
- const native = (...args) => Effect_exports.suspend(() => {
27
- if (signal === void 0) return operation(...args);
28
- if (signal.aborted) return Effect_exports.interrupt;
29
- const cancelled = Effect_exports.callback((resume) => {
30
- if (signal.aborted) {
31
- resume(Effect_exports.interrupt);
32
- return;
33
- }
34
- const abort = () => resume(Effect_exports.interrupt);
35
- signal.addEventListener("abort", abort, { once: true });
36
- return Effect_exports.sync(() => signal.removeEventListener("abort", abort));
37
- });
38
- return Effect_exports.raceFirst(
39
- cancelled,
40
- Effect_exports.suspend(() => operation(...args))
41
- );
42
- });
43
- return Object.assign((...args) => Effect_exports.runPromise(native(...args)), {
44
- [NativeCallback]: native
45
- });
46
- };
47
-
48
19
  // src/implementation/operations.ts
49
20
  var NativeOperation = /* @__PURE__ */ Symbol("apps.Operation");
50
21
  var NativeRouterKey = /* @__PURE__ */ Symbol("apps.Router");
@@ -65,7 +36,7 @@ var operationOptions = (options) => {
65
36
  ...options._meta === void 0 ? {} : { _meta: options._meta },
66
37
  input: decoderOf(options.input),
67
38
  ...approval === void 0 ? {} : {
68
- approval: (context) => Effect_exports.tryPromise({ try: async () => approval(context), catch: (error) => error })
39
+ approval: (context) => fromPromise(async () => approval(context), "approval")()
69
40
  }
70
41
  };
71
42
  };
@@ -73,7 +44,7 @@ var approvedOperation = (operation, approval) => {
73
44
  const copy = Object.defineProperties({}, Object.getOwnPropertyDescriptors(operation));
74
45
  return Object.defineProperty(copy, "approval", {
75
46
  enumerable: true,
76
- value: (context) => Effect_exports.tryPromise({ try: async () => approval(context), catch: (error) => error })
47
+ value: (context) => fromPromise(async () => approval(context), "approval")()
77
48
  });
78
49
  };
79
50
  var withApproval = (operation, approval) => ({
@@ -86,12 +57,9 @@ var make = (kind, options, run) => operationDeclaration({
86
57
  kind,
87
58
  // The host always validates JSON serialization, even without a stronger output declaration.
88
59
  ...options.output === void 0 ? {} : { output: decoderOf(schemaArgument(options.output, `The ${kind} output`)) },
89
- run: (context, input) => Effect_exports.tryPromise({
90
- // SAFETY: defineApp checks the handler context against its requirements.
91
- // The host validates account bindings and creates the matching storage facade.
92
- try: () => run(context, input),
93
- catch: (error) => error
94
- })
60
+ // SAFETY: defineApp checks the handler context against its requirements.
61
+ // The host validates account bindings and creates the matching storage facade.
62
+ run: (context, input) => fromPromise(run, "handler")(context, input)
95
63
  });
96
64
  var query = (options, run) => make("query", options, run);
97
65
  var mutation = (options, run) => make("mutation", options, run);
@@ -139,14 +107,14 @@ var dynamicRouter = (source) => {
139
107
  return routerDeclaration({
140
108
  kind: "dynamic",
141
109
  ...meta === void 0 ? {} : {
142
- meta: () => fromPromise(async () => meta())().pipe(
110
+ meta: () => fromPromise(async () => meta(), "router")().pipe(
143
111
  Effect_exports.flatMap((options) => Schema_exports.decodeUnknownEffect(RouterMeta)(options))
144
112
  )
145
113
  },
146
- list: () => fromPromise(async () => source.list())().pipe(
114
+ list: () => fromPromise(async () => source.list(), "router")().pipe(
147
115
  Effect_exports.flatMap(Schema_exports.decodeUnknownEffect(Schema_exports.Array(HostedTool)))
148
116
  ),
149
- resolve: (name) => fromPromise(async () => source.resolve(name))().pipe(
117
+ resolve: (name) => fromPromise(async () => source.resolve(name), "router")().pipe(
150
118
  Effect_exports.map((value) => {
151
119
  if (value === void 0) return void 0;
152
120
  const operation = nativeOperation(value);
@@ -235,8 +203,6 @@ var withApprovals = (source, policy) => {
235
203
  };
236
204
 
237
205
  export {
238
- fromPromise,
239
- toPromise,
240
206
  operationDeclaration,
241
207
  nativeOperation,
242
208
  withApproval,
@@ -2,14 +2,63 @@ import {
2
2
  ProviderError,
3
3
  maxUpstreamMessageLength
4
4
  } from "./chunk-MWKHKOTL.js";
5
+ import {
6
+ owned
7
+ } from "./chunk-JM7LOD2W.js";
5
8
  import {
6
9
  AccountId
7
10
  } from "./chunk-H2CJWXA3.js";
8
11
  import {
12
+ Effect_exports,
9
13
  Option_exports,
10
14
  Schema_exports
11
15
  } from "./chunk-IFJU5SYQ.js";
12
16
 
17
+ // src/implementation/authoring.ts
18
+ var NativeCallback = /* @__PURE__ */ Symbol("apps.NativeCallback");
19
+ var appCode = (code) => owned("app", "app.code", { attributes: { "executor.app.code": code } });
20
+ var fromPromise = (callback, code) => (...args) => {
21
+ if (NativeCallback in callback) {
22
+ const native = callback[NativeCallback];
23
+ return native(...args);
24
+ }
25
+ return Effect_exports.tryPromise({ try: () => callback(...args), catch: (error) => error }).pipe(
26
+ appCode(code)
27
+ );
28
+ };
29
+ var method = (target, key) => {
30
+ const value = target[key];
31
+ const call = (...args) => Reflect.apply(value, target, args);
32
+ if (NativeCallback in value) Object.assign(call, { [NativeCallback]: value[NativeCallback] });
33
+ return call;
34
+ };
35
+ var toPromise = (operation, signalOf, services) => {
36
+ const native = (...args) => Effect_exports.suspend(() => {
37
+ const signal = typeof signalOf === "function" ? signalOf(...args) : signalOf;
38
+ if (signal === void 0) return operation(...args);
39
+ if (signal.aborted) return Effect_exports.interrupt;
40
+ const cancelled = Effect_exports.callback((resume) => {
41
+ if (signal.aborted) {
42
+ resume(Effect_exports.interrupt);
43
+ return;
44
+ }
45
+ const abort = () => resume(Effect_exports.interrupt);
46
+ signal.addEventListener("abort", abort, { once: true });
47
+ return Effect_exports.sync(() => signal.removeEventListener("abort", abort));
48
+ });
49
+ return Effect_exports.raceFirst(
50
+ cancelled,
51
+ Effect_exports.suspend(() => operation(...args))
52
+ );
53
+ });
54
+ return Object.assign(
55
+ (...args) => services === void 0 ? Effect_exports.runPromise(native(...args)) : Effect_exports.runPromiseWith(services)(native(...args)),
56
+ {
57
+ [NativeCallback]: native
58
+ }
59
+ );
60
+ };
61
+
13
62
  // src/implementation/upstream-error.ts
14
63
  var ErrorToken = Schema_exports.String.check(Schema_exports.isPattern(/^[A-Za-z0-9._-]{1,128}$/u));
15
64
  var JsonRpcError = Schema_exports.Struct({
@@ -107,6 +156,10 @@ function graphqlProviderError(errors, status) {
107
156
  }
108
157
 
109
158
  export {
159
+ appCode,
160
+ fromPromise,
161
+ method,
162
+ toPromise,
110
163
  isShortenedUpstream,
111
164
  bodyUpstreamError,
112
165
  providerError,