apps 0.0.1-beta.143 → 0.0.1-beta.148

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 (79) hide show
  1. package/README.md +14 -0
  2. package/check-publish.mjs +0 -1
  3. package/framework-reference.json +1 -1
  4. package/js/{chunk-IWLFLMIL.js → chunk-4XXHO5UG.js} +3966 -1760
  5. package/js/{chunk-NXUNFV44.js → chunk-63BS5GBH.js} +9 -14
  6. package/js/{chunk-2XEQYDQY.js → chunk-A6FRLRCN.js} +0 -1
  7. package/js/{chunk-PASOVDON.js → chunk-ALZDZ3ZT.js} +9 -30
  8. package/js/{chunk-H4JK7UTH.js → chunk-CQCY3OZS.js} +8 -49
  9. package/js/{chunk-V6OUBNL4.js → chunk-CWAPV2TN.js} +4 -6
  10. package/js/{chunk-RW5EXIO6.js → chunk-DX5DD6Z2.js} +8 -17
  11. package/js/{chunk-B54D6AN7.js → chunk-E2PVLAGK.js} +7 -15
  12. package/js/{chunk-LRXY54YF.js → chunk-EXL6F456.js} +1 -1
  13. package/js/{chunk-Y3QPWYHC.js → chunk-FWK2WTJB.js} +4 -5
  14. package/js/{chunk-2OGVSUNI.js → chunk-GWFQCQB5.js} +2 -2
  15. package/js/chunk-HEFJFDU4.js +87 -0
  16. package/js/{chunk-XRNSAU62.js → chunk-I7MYW7IK.js} +2 -2
  17. package/js/{chunk-ADG72XX3.js → chunk-JLHRRTRH.js} +6 -13
  18. package/js/{chunk-K24M6LZ7.js → chunk-MXFPSMNM.js} +2 -2
  19. package/js/{chunk-INQON4A2.js → chunk-OA4UYCJ4.js} +2 -2
  20. package/js/{chunk-3RIEA22Q.js → chunk-PUMGAWHB.js} +24 -43
  21. package/js/{chunk-W6V5OIHB.js → chunk-SEJXUMGT.js} +267 -1
  22. package/js/{chunk-RUSVGD5N.js → chunk-SXYFFXHM.js} +2 -2
  23. package/js/{chunk-BHSWVS3Q.js → chunk-UT2CBMW3.js} +4 -1
  24. package/js/{chunk-XAOJP46A.js → chunk-XR7KZNKD.js} +1 -1
  25. package/js/{chunk-TMYRAFMC.js → chunk-ZWFMEH2Y.js} +18 -1
  26. package/js/client.js +31 -14
  27. package/js/contracts.js +3 -4
  28. package/js/effect.js +14 -15
  29. package/js/graphql.js +16 -19
  30. package/js/host.js +14 -17
  31. package/js/index.js +10 -16
  32. package/js/mcp/effect.js +15 -16
  33. package/js/mcp.js +17 -18
  34. package/js/openapi.js +14 -22
  35. package/js/react.js +122 -3
  36. package/js/skills/effect.js +3 -4
  37. package/js/skills.js +17 -24
  38. package/js/ui/auth/contracts.js +5 -1
  39. package/js/ui/auth.js +7 -4
  40. package/js/ui/contracts.js +52 -5
  41. package/js/ui/serving.js +55 -17
  42. package/package.json +1 -1
  43. package/runtime.json +1 -1
  44. package/types/app-cache/src/index.d.ts +1 -40
  45. package/types/app-data/src/contracts/database.d.ts +0 -21
  46. package/types/apps/src/client.d.ts +3 -0
  47. package/types/apps/src/contracts/desktop-errors.d.ts +46 -0
  48. package/types/apps/src/contracts/desktop.d.ts +228 -0
  49. package/types/apps/src/contracts/ui-auth.d.ts +4 -1
  50. package/types/apps/src/contracts/ui.d.ts +43 -1
  51. package/types/apps/src/implementation/desktop.d.ts +85 -0
  52. package/types/apps/src/implementation/ui-serving.d.ts +13 -1
  53. package/types/apps/src/react.d.ts +29 -0
  54. package/types/apps/src/ui-serving.d.ts +1 -1
  55. package/types/telemetry/src/app-records.d.ts +0 -24
  56. package/types/telemetry/src/browser-operations.d.ts +0 -8
  57. package/types/telemetry/src/browser-performance.d.ts +0 -2
  58. package/types/telemetry/src/browser-request-timing.d.ts +0 -1
  59. package/types/telemetry/src/browser.d.ts +0 -10
  60. package/types/telemetry/src/config.d.ts +0 -8
  61. package/types/telemetry/src/context.d.ts +0 -6
  62. package/types/telemetry/src/index.d.ts +0 -1
  63. package/types/telemetry/src/keepalive.d.ts +0 -44
  64. package/types/telemetry/src/layer.d.ts +0 -8
  65. package/types/telemetry/src/measurements.d.ts +0 -8
  66. package/types/telemetry/src/ownership.d.ts +0 -45
  67. package/types/telemetry/src/pending-span.d.ts +0 -2
  68. package/types/telemetry/src/recorded-failure.d.ts +0 -26
  69. package/types/telemetry/src/relay.d.ts +0 -29
  70. package/types/telemetry/src/span-attributes.d.ts +0 -38
  71. package/types/telemetry/src/trace-context.d.ts +0 -6
  72. package/types/telemetry/src/transport.d.ts +0 -10
  73. package/types/utils/src/api-error.d.ts +0 -22
  74. package/types/utils/src/connection-failure.d.ts +0 -10
  75. package/types/utils/src/random-uuid.d.ts +0 -5
  76. package/types/utils/src/recorded-message.d.ts +0 -15
  77. package/types/utils/src/schema-definitions.d.ts +0 -6
  78. package/types/utils/src/user-facing-error.d.ts +0 -19
  79. package/js/chunk-QLUWYCOT.js +0 -2325
@@ -0,0 +1,87 @@
1
+ // src/contracts/desktop.ts
2
+ var desktopPermissions = [
3
+ "menuBar",
4
+ "shortcuts",
5
+ "floating",
6
+ "startAtLogin",
7
+ "microphone",
8
+ "camera",
9
+ "systemAudio",
10
+ "clipboardRead",
11
+ "notifications"
12
+ ];
13
+ var desktopMenuBarTitleMaxLength = 24;
14
+ var desktopBadgeMaximum = 99999;
15
+ var desktopMaximumWindows = 8;
16
+ var desktopWindowSize = { minimum: 200, maximum: 4096 };
17
+ var desktopAppBridgeGlobal = "__executorDesktop";
18
+ var desktopShortcutEvent = "executor:desktop-shortcut";
19
+ var desktopWindowEvent = "executor:desktop-window";
20
+ var desktopBridgeVersion = 1;
21
+ var desktopNotificationPathKey = "path";
22
+ var desktopHostBridgeGlobal = "__executorDesktopHost";
23
+ var executorServerIdentityPath = "/.well-known/executor";
24
+ var desktopLinkProtocol = "executor";
25
+ var installHost = "install";
26
+ var appIdPattern = /^app_[A-Za-z0-9_-]{1,124}$/u;
27
+ var organizationIdPattern = /^[A-Za-z0-9_-]{1,128}$/u;
28
+ var labelPattern = /^[^\p{Cc}\p{Cf}\p{Zl}\p{Zp}]{1,80}$/u;
29
+ var loopbackHostname = (hostname) => hostname === "localhost" || hostname.endsWith(".localhost") || hostname === "[::1]" || /^127\.\d{1,3}\.\d{1,3}\.\d{1,3}$/u.test(hostname);
30
+ var dashboardOrigin = (value) => {
31
+ const url = URL.parse(value);
32
+ if (url === null || url.origin !== value) return void 0;
33
+ if (url.protocol === "https:") return url.origin;
34
+ return url.protocol === "http:" && loopbackHostname(url.hostname) ? url.origin : void 0;
35
+ };
36
+ var desktopInstallLink = (link) => {
37
+ const params = new URLSearchParams({ server: link.server, app: link.app });
38
+ if (link.organization !== void 0) params.set("org", link.organization);
39
+ if (link.name !== void 0 && labelPattern.test(link.name)) params.set("name", link.name);
40
+ if (link.team !== void 0 && labelPattern.test(link.team)) params.set("team", link.team);
41
+ const value = `${desktopLinkProtocol}://${installHost}?${params.toString()}`;
42
+ return parseDesktopInstallLink(value) === void 0 ? void 0 : value;
43
+ };
44
+ var parseDesktopInstallLink = (value) => {
45
+ const url = URL.parse(value);
46
+ if (url === null || url.protocol !== `${desktopLinkProtocol}:` || url.hostname !== installHost || url.username !== "" || url.password !== "" || url.port !== "" || url.hash !== "" || url.pathname !== "" && url.pathname !== "/")
47
+ return void 0;
48
+ const keys = [...url.searchParams.keys()];
49
+ const allowed = ["server", "app", "org", "name", "team"];
50
+ if (new Set(keys).size !== keys.length || keys.some((key) => !allowed.includes(key)) || !keys.includes("server") || !keys.includes("app"))
51
+ return void 0;
52
+ const server = dashboardOrigin(url.searchParams.get("server") ?? "");
53
+ const app = url.searchParams.get("app") ?? "";
54
+ const organization = url.searchParams.get("org");
55
+ const name = url.searchParams.get("name");
56
+ const team = url.searchParams.get("team");
57
+ if (server === void 0 || !appIdPattern.test(app)) return void 0;
58
+ if (organization !== null && !organizationIdPattern.test(organization)) return void 0;
59
+ if (name !== null && !labelPattern.test(name) || team !== null && !labelPattern.test(team))
60
+ return void 0;
61
+ return {
62
+ server,
63
+ app,
64
+ ...organization === null ? {} : { organization },
65
+ ...name === null ? {} : { name },
66
+ ...team === null ? {} : { team }
67
+ };
68
+ };
69
+
70
+ export {
71
+ desktopPermissions,
72
+ desktopMenuBarTitleMaxLength,
73
+ desktopBadgeMaximum,
74
+ desktopMaximumWindows,
75
+ desktopWindowSize,
76
+ desktopAppBridgeGlobal,
77
+ desktopShortcutEvent,
78
+ desktopWindowEvent,
79
+ desktopBridgeVersion,
80
+ desktopNotificationPathKey,
81
+ desktopHostBridgeGlobal,
82
+ executorServerIdentityPath,
83
+ desktopLinkProtocol,
84
+ loopbackHostname,
85
+ desktopInstallLink,
86
+ parseDesktopInstallLink
87
+ };
@@ -1,11 +1,11 @@
1
1
  import {
2
2
  fixedRouter
3
- } from "./chunk-NXUNFV44.js";
3
+ } from "./chunk-63BS5GBH.js";
4
4
  import {
5
5
  nativeOperation,
6
6
  operationDeclaration,
7
7
  routerDeclaration
8
- } from "./chunk-B54D6AN7.js";
8
+ } from "./chunk-E2PVLAGK.js";
9
9
 
10
10
  // src/implementation/protocol-operations.ts
11
11
  var protocolOperations = (operations, kinds = {}) => {
@@ -1186,7 +1186,6 @@ function object(fields) {
1186
1186
  ]
1187
1187
  );
1188
1188
  const decoder = entries.length === 0 ? withJsonSchemaDocument(
1189
- // Native Struct({}) accepts every non-null value and retains undeclared fields.
1190
1189
  Schema_exports.Record(Schema_exports.String, Schema_exports.Unknown).pipe(
1191
1190
  Schema_exports.decodeTo(Schema_exports.Record(Schema_exports.String, Schema_exports.Never), {
1192
1191
  decode: SchemaGetter_exports.transform(() => ({})),
@@ -1199,15 +1198,12 @@ function object(fields) {
1199
1198
  }
1200
1199
  var Exposure = /* @__PURE__ */ Symbol("apps.FieldExposure");
1201
1200
  var exposureOf = (schema) => Exposure in schema && (schema[Exposure] === "plain" || schema[Exposure] === "raw") ? schema[Exposure] : void 0;
1202
- var expose = (schema, exposure) => (
1203
- // SAFETY: the copy keeps every member of S, and `optional` and `default` keep the marking.
1204
- {
1205
- ...schema,
1206
- [Exposure]: exposure,
1207
- optional: () => expose(schema.optional(), exposure),
1208
- default: (value) => expose(schema.default(value), exposure)
1209
- }
1210
- );
1201
+ var expose = (schema, exposure) => ({
1202
+ ...schema,
1203
+ [Exposure]: exposure,
1204
+ optional: () => expose(schema.optional(), exposure),
1205
+ default: (value) => expose(schema.default(value), exposure)
1206
+ });
1211
1207
  var plain = (schema) => expose(schema, "plain");
1212
1208
  var raw = (schema) => expose(schema, "raw");
1213
1209
  var fieldExposure = (fields) => Object.fromEntries(
@@ -1635,8 +1631,6 @@ var constraintProblem = (keyword, node) => {
1635
1631
  if (keyword === "uniqueItems") return "Expected an array without repeated items";
1636
1632
  if (typeof value !== "number") return void 0;
1637
1633
  switch (keyword) {
1638
- // Draft 4's boolean `exclusiveMinimum` is not applied: imported schemas validate as draft 7
1639
- // or 2020-12, where `minimum` and `maximum` always include their bound.
1640
1634
  case "minimum":
1641
1635
  return `Expected a number of at least ${value}`;
1642
1636
  case "maximum":
@@ -1952,7 +1946,6 @@ var lazyCompiledDecoder = (document) => {
1952
1946
  let compiled;
1953
1947
  const compile = Effect_exports.suspend(
1954
1948
  () => compiled ?? compileJsonSchemaDecoder(read()).pipe(
1955
- // An interrupted compilation is not a result; the next decode compiles again.
1956
1949
  Effect_exports.onExit(
1957
1950
  (exit) => Effect_exports.sync(() => {
1958
1951
  if (Exit_exports.isSuccess(exit) || !Cause_exports.hasInterrupts(exit.cause)) compiled = exit;
@@ -5,10 +5,10 @@ import {
5
5
  networkRefusalHeader,
6
6
  networkRefusalStatus,
7
7
  supportedFetchOptions
8
- } from "./chunk-LRXY54YF.js";
8
+ } from "./chunk-EXL6F456.js";
9
9
  import {
10
10
  invocationFetch
11
- } from "./chunk-H4JK7UTH.js";
11
+ } from "./chunk-CQCY3OZS.js";
12
12
  import {
13
13
  Effect_exports,
14
14
  Schema_exports
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  appSignInCallbackPath
3
- } from "./chunk-BHSWVS3Q.js";
3
+ } from "./chunk-UT2CBMW3.js";
4
4
  import {
5
5
  HttpServerResponse_exports
6
- } from "./chunk-IWLFLMIL.js";
6
+ } from "./chunk-4XXHO5UG.js";
7
7
 
8
8
  // src/implementation/ui-auth.ts
9
9
  var appPrivateHeaders = {
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  authorCache,
3
3
  unavailableCache
4
- } from "./chunk-PASOVDON.js";
4
+ } from "./chunk-ALZDZ3ZT.js";
5
5
  import {
6
6
  accountSecrets,
7
7
  boundFailureMessage,
@@ -12,13 +12,13 @@ import {
12
12
  parseSkillLoadFailed,
13
13
  readCatalog,
14
14
  routerSkills
15
- } from "./chunk-NXUNFV44.js";
15
+ } from "./chunk-63BS5GBH.js";
16
16
  import {
17
17
  appInvocationFetch
18
- } from "./chunk-K24M6LZ7.js";
18
+ } from "./chunk-MXFPSMNM.js";
19
19
  import {
20
20
  folderSkillsEffect
21
- } from "./chunk-XAOJP46A.js";
21
+ } from "./chunk-XR7KZNKD.js";
22
22
  import {
23
23
  ResponseStatusError,
24
24
  declaredEvents,
@@ -26,12 +26,12 @@ import {
26
26
  makeEmitter,
27
27
  toEffectApp,
28
28
  withPlacements
29
- } from "./chunk-V6OUBNL4.js";
29
+ } from "./chunk-CWAPV2TN.js";
30
30
  import {
31
31
  declaredOperations,
32
32
  locate,
33
33
  nativeOperation
34
- } from "./chunk-B54D6AN7.js";
34
+ } from "./chunk-E2PVLAGK.js";
35
35
  import {
36
36
  accountProviderError,
37
37
  appCode,
@@ -39,7 +39,7 @@ import {
39
39
  httpProviderError,
40
40
  parseProviderError,
41
41
  toPromise
42
- } from "./chunk-RUSVGD5N.js";
42
+ } from "./chunk-SXYFFXHM.js";
43
43
  import {
44
44
  AccountCheckResult,
45
45
  AfterReply,
@@ -96,11 +96,11 @@ import {
96
96
  sqlBindingsLimit,
97
97
  withoutHelp,
98
98
  workflowDurationMillis
99
- } from "./chunk-LRXY54YF.js";
99
+ } from "./chunk-EXL6F456.js";
100
100
  import {
101
101
  AppSkills,
102
102
  SkillFile
103
- } from "./chunk-2XEQYDQY.js";
103
+ } from "./chunk-A6FRLRCN.js";
104
104
  import {
105
105
  allowedValues,
106
106
  echoableKey,
@@ -113,13 +113,13 @@ import {
113
113
  missingKeyText,
114
114
  objectShape,
115
115
  unionShape
116
- } from "./chunk-ADG72XX3.js";
116
+ } from "./chunk-JLHRRTRH.js";
117
117
  import {
118
118
  captureTelemetry,
119
119
  makeOwnershipAccounting,
120
120
  measuredSpan,
121
121
  owned
122
- } from "./chunk-H4JK7UTH.js";
122
+ } from "./chunk-CQCY3OZS.js";
123
123
  import {
124
124
  JsonObject,
125
125
  JsonValue
@@ -266,11 +266,7 @@ var makeWorkflowContext = (execution, definition, fresh, signal) => Effect_expor
266
266
  Effect_exports.timeout(timeout),
267
267
  Effect_exports.catchTag(
268
268
  "TimeoutError",
269
- () => (
270
- // Both the capability deadline and the native engine deadline describe
271
- // the same cancellation, regardless of which timer fires first.
272
- Effect_exports.fail(new WorkflowFailure({ reason: "engine", retryable: true }))
273
- )
269
+ () => Effect_exports.fail(new WorkflowFailure({ reason: "engine", retryable: true }))
274
270
  )
275
271
  );
276
272
  };
@@ -914,7 +910,6 @@ var authorSql = (storage, options) => {
914
910
  }
915
911
  };
916
912
  const writer = {
917
- // A step's writes go through its one transaction, which also records its receipt.
918
913
  exec: (query, ...bindings) => run(query, bindings, options.step ? "read" : "write"),
919
914
  transaction
920
915
  };
@@ -1093,7 +1088,6 @@ var migrate = (storage, files) => Effect_exports.gen(function* () {
1093
1088
  }));
1094
1089
  })
1095
1090
  ).pipe(
1096
- // Both are thrown inside the transaction so that it rolls back; they are expected failures.
1097
1091
  Effect_exports.catchDefect(
1098
1092
  (defect) => Schema_exports.is(MigrationFailed)(defect) || Schema_exports.is(MigrationHistoryChanged)(defect) ? Effect_exports.fail(defect) : Effect_exports.die(defect)
1099
1093
  ),
@@ -1178,7 +1172,6 @@ function providerDeclaration(provider) {
1178
1172
  return yield* Schema_exports.decodeUnknownEffect(DeclaredProvider)({
1179
1173
  name: provider.name,
1180
1174
  auth: Object.fromEntries(auth),
1181
- // Order and repetition carry no meaning, so neither changes the provider's identity.
1182
1175
  ...provider.hosts === void 0 ? {} : { hosts: [...new Set(provider.hosts)].sort() }
1183
1176
  });
1184
1177
  }),
@@ -1425,7 +1418,6 @@ function dispatch(app, request, context, signal, emitted) {
1425
1418
  let running;
1426
1419
  const delivery = (request2, signal2) => Effect_exports.suspend(
1427
1420
  () => running !== void 0 && context.elicitation !== void 0 ? context.elicitation(request2, signal2).pipe(
1428
- // Delivering the question and waiting for its answer is the person's time.
1429
1421
  owned("person", "app.tool.elicitation"),
1430
1422
  Effect_exports.provideContext(running.context)
1431
1423
  ) : Effect_exports.fail(new ElicitationFailed({ reason: "unavailable" }))
@@ -1602,7 +1594,6 @@ function dispatch(app, request, context, signal, emitted) {
1602
1594
  stepId,
1603
1595
  idempotencyKey: stepId
1604
1596
  },
1605
- // The resolved values, not the app's decoded fields, which may be `Redacted`.
1606
1597
  secrets: accountSecrets(current.accounts)
1607
1598
  };
1608
1599
  }),
@@ -1740,10 +1731,7 @@ function dispatch(app, request, context, signal, emitted) {
1740
1731
  ...kind === "mutate" ? { events: emitter() } : {}
1741
1732
  },
1742
1733
  input
1743
- ).pipe(
1744
- // The cache session's background runner, which the host drains after the reply.
1745
- Effect_exports.provideService(AfterReply, context.cache?.background)
1746
- );
1734
+ ).pipe(Effect_exports.provideService(AfterReply, context.cache?.background));
1747
1735
  }).pipe(
1748
1736
  Effect_exports.ensuring(
1749
1737
  Effect_exports.sync(() => {
@@ -1889,8 +1877,6 @@ var createAppHandler = (app) => (request, context) => Effect_exports.gen(functio
1889
1877
  toolError = true;
1890
1878
  }
1891
1879
  }),
1892
- // Name what failed on the span; the bounded message stays in the reply only. The host
1893
- // records an app's own error names and codes as `unrecognized` (telemetry `app-records`).
1894
1880
  Effect_exports.tapError(
1895
1881
  (error) => (error._tag === "HostEvaluationFailed" || error._tag === "HostOperationFailed" || error._tag === "HostDeclarationInvalid") && error.errorName !== void 0 ? Effect_exports.annotateCurrentSpan({
1896
1882
  "error.type": error.errorName,
@@ -1898,8 +1884,6 @@ var createAppHandler = (app) => (request, context) => Effect_exports.gen(functio
1898
1884
  ...error.code === void 0 ? {} : { "executor.failure.code": error.code }
1899
1885
  }) : Effect_exports.void
1900
1886
  ),
1901
- // Tool operations time themselves, dividing their time by who owned the work in progress.
1902
- // Other operations do not.
1903
1887
  command.operation === "call" || command.operation === "query" || command.operation === "mutate" ? timedInvocation(command.operation) : Effect_exports.withSpan(`app.${command.operation}`)
1904
1888
  );
1905
1889
  if (toolError)
@@ -1923,21 +1907,18 @@ var createAppHandler = (app) => (request, context) => Effect_exports.gen(functio
1923
1907
  )
1924
1908
  ),
1925
1909
  Effect_exports.catchCause(
1926
- (cause) => Cause_exports.hasInterrupts(cause) ? Effect_exports.interrupt : (
1927
- // The cause can carry any text the app threw; its caller receives that, not the log.
1928
- Effect_exports.logError("The app's request failed unexpectedly").pipe(
1929
- Effect_exports.andThen(
1930
- Schema_exports.encodeEffect(HostError)(
1931
- declarationInvalid(
1932
- "The app failed while it was loaded",
1933
- Cause_exports.squash(cause),
1934
- accountSecrets(context.accounts)
1935
- )
1910
+ (cause) => Cause_exports.hasInterrupts(cause) ? Effect_exports.interrupt : Effect_exports.logError("The app's request failed unexpectedly").pipe(
1911
+ Effect_exports.andThen(
1912
+ Schema_exports.encodeEffect(HostError)(
1913
+ declarationInvalid(
1914
+ "The app failed while it was loaded",
1915
+ Cause_exports.squash(cause),
1916
+ accountSecrets(context.accounts)
1936
1917
  )
1937
- ),
1938
- Effect_exports.map((error) => Response.json({ ok: false, error }, { status: 500 })),
1939
- Effect_exports.orDie
1940
- )
1918
+ )
1919
+ ),
1920
+ Effect_exports.map((error) => Response.json({ ok: false, error }, { status: 500 })),
1921
+ Effect_exports.orDie
1941
1922
  )
1942
1923
  )
1943
1924
  );
@@ -1,3 +1,11 @@
1
+ import {
2
+ desktopAppBridgeGlobal,
3
+ desktopBadgeMaximum,
4
+ desktopBridgeVersion,
5
+ desktopMenuBarTitleMaxLength,
6
+ desktopShortcutEvent,
7
+ desktopWindowEvent
8
+ } from "./chunk-HEFJFDU4.js";
1
9
  import {
2
10
  Boolean,
3
11
  Cause,
@@ -5,6 +13,7 @@ import {
5
13
  Defect,
6
14
  Int,
7
15
  InvalidType,
16
+ Match_exports,
8
17
  MixedScheduler,
9
18
  Never2 as Never,
10
19
  NoSuchElementError,
@@ -13,6 +22,7 @@ import {
13
22
  PipeInspectableProto,
14
23
  Pointer,
15
24
  Scheduler,
25
+ Schema_exports,
16
26
  Scope,
17
27
  Service,
18
28
  TaggedError,
@@ -2714,10 +2724,266 @@ var queryCommitted = (result) => {
2714
2724
  commits.get(result)?.();
2715
2725
  };
2716
2726
 
2727
+ // src/contracts/desktop-errors.ts
2728
+ var DesktopPermissionName = Schema_exports.Literals([
2729
+ "menuBar",
2730
+ "shortcuts",
2731
+ "floating",
2732
+ "startAtLogin",
2733
+ "microphone",
2734
+ "camera",
2735
+ "systemAudio",
2736
+ "clipboardRead",
2737
+ "notifications"
2738
+ ]);
2739
+ var permissionDeniedFields = { permission: DesktopPermissionName };
2740
+ var shortcutTakenFields = { accelerator: Schema_exports.String };
2741
+ var invalidInputFields = { message: Schema_exports.String };
2742
+ var DesktopUnavailable = class extends Schema_exports.TaggedError()(
2743
+ "DesktopUnavailable",
2744
+ {}
2745
+ ) {
2746
+ };
2747
+ var DesktopPermissionDenied = class extends Schema_exports.TaggedError()(
2748
+ "DesktopPermissionDenied",
2749
+ permissionDeniedFields
2750
+ ) {
2751
+ };
2752
+ var ShortcutTaken = class extends Schema_exports.TaggedError()(
2753
+ "ShortcutTaken",
2754
+ shortcutTakenFields
2755
+ ) {
2756
+ };
2757
+ var DesktopInvalidInput = class extends Schema_exports.TaggedError()(
2758
+ "DesktopInvalidInput",
2759
+ invalidInputFields
2760
+ ) {
2761
+ };
2762
+ var SystemAudioBlocked = class extends Schema_exports.TaggedError()(
2763
+ "SystemAudioBlocked",
2764
+ {}
2765
+ ) {
2766
+ };
2767
+ var DesktopBridgeRejection = Schema_exports.Union([
2768
+ Schema_exports.TaggedStruct("DesktopUnavailable", {}),
2769
+ Schema_exports.TaggedStruct("DesktopPermissionDenied", permissionDeniedFields),
2770
+ Schema_exports.TaggedStruct("ShortcutTaken", shortcutTakenFields),
2771
+ Schema_exports.TaggedStruct("DesktopInvalidInput", invalidInputFields),
2772
+ Schema_exports.TaggedStruct("SystemAudioBlocked", {})
2773
+ ]);
2774
+
2775
+ // src/implementation/desktop.ts
2776
+ var bridgeMethods = [
2777
+ "permission",
2778
+ "requestPermission",
2779
+ "setMenuBarTitle",
2780
+ "registerShortcut",
2781
+ "unregisterShortcut",
2782
+ "setFloating",
2783
+ "windowAction",
2784
+ "openWindow",
2785
+ "setBadge",
2786
+ "systemAudio"
2787
+ ];
2788
+ var isBridge = (value2) => typeof value2 === "object" && value2 !== null && Reflect.get(value2, "version") === desktopBridgeVersion && bridgeMethods.every((method) => typeof Reflect.get(value2, method) === "function");
2789
+ var currentBridge = () => {
2790
+ const value2 = typeof window === "undefined" ? void 0 : Reflect.get(window, desktopAppBridgeGlobal);
2791
+ return isBridge(value2) ? value2 : void 0;
2792
+ };
2793
+ var decodeRejection = Schema_exports.decodeUnknownOption(DesktopBridgeRejection);
2794
+ var typedRejection = (reason) => Option_exports.match(decodeRejection(reason), {
2795
+ onNone: () => reason,
2796
+ onSome: Match_exports.valueTags({
2797
+ DesktopUnavailable: () => new DesktopUnavailable(),
2798
+ DesktopPermissionDenied: ({ permission }) => new DesktopPermissionDenied({ permission }),
2799
+ ShortcutTaken: ({ accelerator }) => new ShortcutTaken({ accelerator }),
2800
+ DesktopInvalidInput: ({ message }) => new DesktopInvalidInput({ message }),
2801
+ SystemAudioBlocked: () => new SystemAudioBlocked()
2802
+ })
2803
+ });
2804
+ var call = async (run) => {
2805
+ const bridge = currentBridge();
2806
+ if (bridge === void 0) throw new DesktopUnavailable();
2807
+ try {
2808
+ return await run(bridge);
2809
+ } catch (reason) {
2810
+ throw typedRejection(reason);
2811
+ }
2812
+ };
2813
+ var shortcutsByBridge = /* @__PURE__ */ new WeakMap();
2814
+ var heldShortcuts = (bridge) => {
2815
+ const held = shortcutsByBridge.get(bridge) ?? /* @__PURE__ */ new Set();
2816
+ shortcutsByBridge.set(bridge, held);
2817
+ return held;
2818
+ };
2819
+ var invalid = (message) => Promise.reject(new DesktopInvalidInput({ message }));
2820
+ var windowEventType = (event) => {
2821
+ if (!(event instanceof CustomEvent)) return void 0;
2822
+ const detail = event.detail;
2823
+ if (typeof detail !== "object" || detail === null) return void 0;
2824
+ const type = Reflect.get(detail, "type");
2825
+ return type === "focus" || type === "blur" ? type : void 0;
2826
+ };
2827
+ var onWindowEvent = (type, handler) => {
2828
+ if (currentBridge() === void 0) return () => void 0;
2829
+ const listener = (event) => {
2830
+ if (windowEventType(event) === type) handler();
2831
+ };
2832
+ window.addEventListener(desktopWindowEvent, listener);
2833
+ return () => window.removeEventListener(desktopWindowEvent, listener);
2834
+ };
2835
+ var displayAudio = async (bridge) => {
2836
+ await bridge.systemAudio();
2837
+ const stream2 = await navigator.mediaDevices.getDisplayMedia({ audio: true, video: true }).catch(async (reason) => {
2838
+ await bridge.systemAudio();
2839
+ throw reason;
2840
+ });
2841
+ for (const track of stream2.getVideoTracks()) {
2842
+ track.stop();
2843
+ stream2.removeTrack(track);
2844
+ }
2845
+ if (stream2.getAudioTracks().length === 0) throw new DesktopUnavailable();
2846
+ return stream2;
2847
+ };
2848
+ var shortcutId = (event) => {
2849
+ if (!(event instanceof CustomEvent)) return void 0;
2850
+ const detail = event.detail;
2851
+ if (typeof detail !== "object" || detail === null) return void 0;
2852
+ const id = Reflect.get(detail, "id");
2853
+ return typeof id === "string" ? id : void 0;
2854
+ };
2855
+ var desktop = {
2856
+ /** Whether this page is in an installed Executor desktop window. */
2857
+ get available() {
2858
+ return currentBridge() !== void 0;
2859
+ },
2860
+ /** The person's choice for one capability, without asking them. */
2861
+ permission: (name) => currentBridge() === void 0 ? Promise.resolve("unavailable") : call((bridge) => bridge.permission(name)),
2862
+ /**
2863
+ * Ask the person for one capability now, if they have not answered yet, and resolve their
2864
+ * choice; a refusal resolves `"denied"` rather than rejecting. Use it for `startAtLogin`, which
2865
+ * no other call asks for, or to ask for the microphone before a recording starts.
2866
+ */
2867
+ requestPermission: (name) => currentBridge() === void 0 ? Promise.resolve("unavailable") : call((bridge) => bridge.requestPermission(name)),
2868
+ menuBar: {
2869
+ /**
2870
+ * Show plain text for the app in the menu bar, at most `desktopMenuBarTitleMaxLength`
2871
+ * characters. `null` restores the app's name. Needs the `menuBar` permission.
2872
+ */
2873
+ setTitle: (text) => call(
2874
+ (bridge) => text !== null && text.length > desktopMenuBarTitleMaxLength ? Promise.reject(
2875
+ new DesktopInvalidInput({
2876
+ message: `A menu-bar title can be at most ${desktopMenuBarTitleMaxLength} characters.`
2877
+ })
2878
+ ) : bridge.setMenuBarTitle(text)
2879
+ )
2880
+ },
2881
+ shortcuts: {
2882
+ /**
2883
+ * Call `handler` whenever the person presses `accelerator` anywhere on their computer, in
2884
+ * Electron accelerator syntax such as `"CommandOrControl+Shift+K"`. Resolves a function that
2885
+ * removes the shortcut through the desktop window that registered it. The shortcut stays held,
2886
+ * and `handler` keeps running, until that function resolves; when it rejects, call it again.
2887
+ * Needs the `shortcuts` permission; rejects with `ShortcutTaken` when another program holds
2888
+ * the keys.
2889
+ */
2890
+ register: (accelerator, handler) => call(async (bridge) => {
2891
+ const { id } = await bridge.registerShortcut(accelerator);
2892
+ const held = heldShortcuts(bridge);
2893
+ if (held.has(id))
2894
+ throw new Error(
2895
+ `The desktop gave the shortcut ${accelerator} the ID ${id}, which another registration in this page already holds.`
2896
+ );
2897
+ held.add(id);
2898
+ const listener = (event) => {
2899
+ if (shortcutId(event) === id) handler();
2900
+ };
2901
+ window.addEventListener(desktopShortcutEvent, listener);
2902
+ let removal;
2903
+ let removed = false;
2904
+ const unregister = async () => {
2905
+ try {
2906
+ await bridge.unregisterShortcut(id);
2907
+ } catch (reason) {
2908
+ throw typedRejection(reason);
2909
+ } finally {
2910
+ removal = void 0;
2911
+ }
2912
+ removed = true;
2913
+ held.delete(id);
2914
+ window.removeEventListener(desktopShortcutEvent, listener);
2915
+ };
2916
+ return () => {
2917
+ if (removed) return Promise.resolve();
2918
+ removal ??= unregister();
2919
+ return removal;
2920
+ };
2921
+ })
2922
+ },
2923
+ window: {
2924
+ /** Keep the app's window above other windows, or stop. Needs the `floating` permission. */
2925
+ setFloating: (on) => call((bridge) => bridge.setFloating(on)),
2926
+ /** Make the window this page is in visible. */
2927
+ show: () => call((bridge) => bridge.windowAction("show")),
2928
+ /** Hide the window this page is in. The app keeps running, and its page keeps running. */
2929
+ hide: () => call((bridge) => bridge.windowAction("hide")),
2930
+ /**
2931
+ * Show the window this page is in and bring it in front of every other app's windows, such as
2932
+ * from a global shortcut's handler.
2933
+ */
2934
+ focus: () => call((bridge) => bridge.windowAction("focus")),
2935
+ /** Hide the window when it is visible and focused; otherwise show and focus it. */
2936
+ toggle: () => call((bridge) => bridge.windowAction("toggle")),
2937
+ /**
2938
+ * Open another window of this app at `path`, such as `"/compose?to=ada"`, on the app's own
2939
+ * origin, or focus the window that already shows that path. The window has `desktop` too, with
2940
+ * the same permissions, and closes when the app quits. At most `desktopMaximumWindows` are
2941
+ * open at once; `floating` needs the `floating` permission.
2942
+ */
2943
+ open: (path, options = {}) => call(
2944
+ (bridge) => path.startsWith("/") && !path.startsWith("//") ? bridge.openWindow(path, options) : invalid(`${path} is not a path on this app, such as /notes/42.`)
2945
+ ),
2946
+ /**
2947
+ * Call `handler` whenever the window this page is in loses focus, such as to hide a window a
2948
+ * shortcut summoned. Returns a function that stops listening. Does nothing outside an
2949
+ * installed Executor desktop window.
2950
+ */
2951
+ onBlur: (handler) => onWindowEvent("blur", handler),
2952
+ /** Call `handler` whenever the window this page is in gains focus. */
2953
+ onFocus: (handler) => onWindowEvent("focus", handler)
2954
+ },
2955
+ badge: {
2956
+ /**
2957
+ * Show a count on the app's icon: on Windows, on the app's own taskbar button; on macOS and
2958
+ * Linux, installed apps share Executor's Dock or launcher icon, which shows the sum of their
2959
+ * counts. `null` or 0 removes the app's count. Needs no permission.
2960
+ */
2961
+ set: (count) => call(
2962
+ (bridge) => count === null || Number.isInteger(count) && count >= 0 && count <= desktopBadgeMaximum ? bridge.setBadge(count) : invalid(`A badge is a whole number from 0 to ${desktopBadgeMaximum}.`)
2963
+ )
2964
+ },
2965
+ audio: {
2966
+ /**
2967
+ * Everything playing on this computer, such as the other people in a call, as an audio-only
2968
+ * `MediaStream`. Asks for the `systemAudio` permission the first time. Rejects with
2969
+ * `SystemAudioBlocked` when macOS has not allowed Executor to record the screen and system
2970
+ * audio, after offering to open System Settings, and with `DesktopUnavailable` where the
2971
+ * computer cannot capture system audio (Linux, macOS before 13). Stop its tracks when done.
2972
+ */
2973
+ system: () => call(displayAudio)
2974
+ }
2975
+ };
2976
+
2717
2977
  export {
2718
2978
  AsyncResult_exports,
2719
2979
  AtomRegistry_exports,
2720
2980
  Atom_exports,
2721
2981
  queryResult,
2722
- queryCommitted
2982
+ queryCommitted,
2983
+ DesktopUnavailable,
2984
+ DesktopPermissionDenied,
2985
+ ShortcutTaken,
2986
+ DesktopInvalidInput,
2987
+ SystemAudioBlocked,
2988
+ desktop
2723
2989
  };
@@ -1,10 +1,10 @@
1
1
  import {
2
2
  ProviderError,
3
3
  maxUpstreamMessageLength
4
- } from "./chunk-LRXY54YF.js";
4
+ } from "./chunk-EXL6F456.js";
5
5
  import {
6
6
  owned
7
- } from "./chunk-H4JK7UTH.js";
7
+ } from "./chunk-CQCY3OZS.js";
8
8
  import {
9
9
  AccountId
10
10
  } from "./chunk-7A4ZSEM3.js";