apps 0.0.1-beta.0 → 0.0.1-beta.2

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 (114) hide show
  1. package/README.md +97 -4
  2. package/framework-reference.json +1 -1
  3. package/js/browser-XIPJGLH2.js +65 -0
  4. package/js/{chunk-SBKHUC5L.js → chunk-4LPG6RCH.js} +2 -2
  5. package/js/chunk-5MQZEB6Y.js +172 -0
  6. package/js/{chunk-7JXHF5IF.js → chunk-BMOIAIVR.js} +1 -1
  7. package/js/chunk-CZ7CSFO4.js +39 -0
  8. package/js/chunk-D47C7KG5.js +172 -0
  9. package/js/{chunk-YDR4CPJA.js → chunk-EVJUVWN2.js} +8 -8
  10. package/js/chunk-FDNTX5QJ.js +78 -0
  11. package/js/{chunk-2OTCEKL2.js → chunk-FW5HBOIK.js} +2352 -1493
  12. package/js/{chunk-EP6AEUZO.js → chunk-FZJOYIZO.js} +1 -1
  13. package/js/{chunk-VFUZI3NY.js → chunk-HDJH3RPR.js} +4 -4
  14. package/js/{chunk-WIDTG42X.js → chunk-HDTGZWP2.js} +79 -26
  15. package/js/{chunk-Q2FD5IBM.js → chunk-J7O55ZV7.js} +298 -37
  16. package/js/{chunk-X3YBZCJW.js → chunk-JN55AYQH.js} +8 -41
  17. package/js/chunk-LGIYBDWA.js +85 -0
  18. package/js/{chunk-D6BKYP2L.js → chunk-M6ZRRIBI.js} +4 -4
  19. package/js/{chunk-HP7E42X6.js → chunk-MYYEW3RA.js} +767 -249
  20. package/js/{chunk-3ANFZFCV.js → chunk-OHRT55C4.js} +15 -15
  21. package/js/{chunk-R6JMJSVT.js → chunk-PLCMJREA.js} +2 -2
  22. package/js/{chunk-C24KEZXR.js → chunk-PYUYJRSK.js} +36 -2
  23. package/js/{chunk-W7Q5EOTS.js → chunk-QKHR7BMF.js} +32 -32
  24. package/js/{chunk-KWTCHVLT.js → chunk-RN2MXB4R.js} +47 -51
  25. package/js/{chunk-36DNRFZQ.js → chunk-SATWJKN6.js} +1 -1
  26. package/js/chunk-SWPD52J7.js +35 -0
  27. package/js/{chunk-BKVL7XAJ.js → chunk-TE4KO4HI.js} +1 -1
  28. package/js/chunk-UVL56Z6E.js +6641 -0
  29. package/js/chunk-W7D7WVSY.js +18 -0
  30. package/js/{chunk-BPEFS4YF.js → chunk-WFSQXYUT.js} +109 -17
  31. package/js/chunk-YEJOQEII.js +104 -0
  32. package/js/{chunk-LOKGDT6B.js → chunk-Z5NMEGJN.js} +5 -4
  33. package/js/{chunk-OWD2YICM.js → chunk-ZCAMUXSG.js} +116 -87
  34. package/js/chunk-ZJWDMTE3.js +63 -0
  35. package/js/client.js +11 -11
  36. package/js/contracts.js +88 -25
  37. package/js/effect.js +21 -15
  38. package/js/es-APDZKREY.js +40968 -0
  39. package/js/graphql.js +224 -121
  40. package/js/host.js +76 -19
  41. package/js/index.js +193 -51
  42. package/js/mcp/effect.js +25 -17
  43. package/js/mcp/stdio.js +23 -17
  44. package/js/mcp.js +110 -24
  45. package/js/openapi.js +3045 -105
  46. package/js/operations/approval.js +1 -1
  47. package/js/react.js +4 -4
  48. package/js/skills/effect.js +11 -0
  49. package/js/skills.js +894 -0
  50. package/js/storage/facet.js +7 -7
  51. package/js/ui/auth/contracts.js +6 -6
  52. package/js/ui/auth.js +8 -8
  53. package/js/ui/contracts.js +5 -5
  54. package/js/ui/serving.js +12 -12
  55. package/package.json +9 -1
  56. package/runtime.json +1 -1
  57. package/types/app-cache/src/contracts/cache.d.ts +119 -0
  58. package/types/app-cache/src/index.d.ts +93 -0
  59. package/types/apps/src/contracts/api-response-error.d.ts +43 -0
  60. package/types/apps/src/contracts/app.d.ts +11 -0
  61. package/types/apps/src/contracts/cache.d.ts +44 -0
  62. package/types/apps/src/contracts/dynamic-skills.d.ts +10 -0
  63. package/types/apps/src/contracts/dynamic-tools.d.ts +13 -0
  64. package/types/apps/src/contracts/graphql.d.ts +18 -1
  65. package/types/apps/src/contracts/host.d.ts +54 -525
  66. package/types/apps/src/contracts/mcp.d.ts +3 -1
  67. package/types/apps/src/contracts/openapi-compile.d.ts +11 -0
  68. package/types/apps/src/contracts/openapi-document.d.ts +53 -0
  69. package/types/apps/src/contracts/openapi.d.ts +156 -30
  70. package/types/apps/src/contracts/protocol-version.d.ts +6 -0
  71. package/types/apps/src/contracts/protocols/1.d.ts +1575 -0
  72. package/types/apps/src/contracts/provider-error.d.ts +15 -0
  73. package/types/apps/src/contracts/provider.d.ts +18 -1
  74. package/types/apps/src/contracts/skills.d.ts +122 -0
  75. package/types/apps/src/contracts/swagger-client.d.ts +29 -0
  76. package/types/apps/src/graphql.d.ts +6 -6
  77. package/types/apps/src/host.d.ts +1 -0
  78. package/types/apps/src/implementation/account-operations.d.ts +122 -3
  79. package/types/apps/src/implementation/app.d.ts +1 -1
  80. package/types/apps/src/implementation/cache-session.d.ts +7 -0
  81. package/types/apps/src/implementation/cache.d.ts +8 -0
  82. package/types/apps/src/implementation/catalog-cache.d.ts +29 -0
  83. package/types/apps/src/implementation/dynamic-skills.d.ts +7 -0
  84. package/types/apps/src/implementation/dynamic-tools.d.ts +8 -0
  85. package/types/apps/src/implementation/elicitation.d.ts +12 -12
  86. package/types/apps/src/implementation/git.d.ts +25 -0
  87. package/types/apps/src/implementation/graphql-catalog.d.ts +10 -0
  88. package/types/apps/src/implementation/graphql.d.ts +81 -3
  89. package/types/apps/src/implementation/inflate.d.ts +16 -0
  90. package/types/apps/src/implementation/input-problems.d.ts +3 -0
  91. package/types/apps/src/implementation/mcp-call.d.ts +3 -2
  92. package/types/apps/src/implementation/mcp-catalog.d.ts +12 -0
  93. package/types/apps/src/implementation/mcp-client.d.ts +9 -8
  94. package/types/apps/src/implementation/mcp-stdio.d.ts +1 -1
  95. package/types/apps/src/implementation/mcp-tools.d.ts +6 -3
  96. package/types/apps/src/implementation/mcp.d.ts +39 -2
  97. package/types/apps/src/implementation/openapi-compile.d.ts +119 -0
  98. package/types/apps/src/implementation/openapi-document.d.ts +51 -0
  99. package/types/apps/src/implementation/openapi-names.d.ts +18 -0
  100. package/types/apps/src/implementation/openapi-request.d.ts +10 -4
  101. package/types/apps/src/implementation/openapi-source.d.ts +40 -0
  102. package/types/apps/src/implementation/openapi.d.ts +39 -3
  103. package/types/apps/src/implementation/provider-error.d.ts +10 -0
  104. package/types/apps/src/implementation/schema.d.ts +6 -5
  105. package/types/apps/src/implementation/skill-files.d.ts +10 -0
  106. package/types/apps/src/implementation/skills.d.ts +43 -0
  107. package/types/apps/src/implementation/swagger-client.d.ts +28 -0
  108. package/types/apps/src/index.d.ts +7 -0
  109. package/types/apps/src/mcp.d.ts +5 -5
  110. package/types/apps/src/openapi.d.ts +3 -1
  111. package/types/apps/src/skills.d.ts +75 -0
  112. package/types/telemetry/src/config.d.ts +2 -0
  113. package/js/chunk-22WRQZT7.js +0 -389
  114. package/js/chunk-MLKGABMK.js +0 -9
@@ -0,0 +1,65 @@
1
+ import {
2
+ Alias,
3
+ Composer,
4
+ Document,
5
+ Lexer,
6
+ LineCounter,
7
+ Pair,
8
+ Parser,
9
+ Scalar,
10
+ Schema,
11
+ YAMLError,
12
+ YAMLMap,
13
+ YAMLParseError,
14
+ YAMLSeq,
15
+ YAMLWarning,
16
+ browser_default,
17
+ cst_exports,
18
+ isAlias,
19
+ isCollection,
20
+ isDocument,
21
+ isMap,
22
+ isNode,
23
+ isPair,
24
+ isScalar,
25
+ isSeq,
26
+ parse,
27
+ parseAllDocuments,
28
+ parseDocument,
29
+ stringify,
30
+ visit,
31
+ visitAsync
32
+ } from "./chunk-UVL56Z6E.js";
33
+ import "./chunk-CZ7CSFO4.js";
34
+ export {
35
+ Alias,
36
+ cst_exports as CST,
37
+ Composer,
38
+ Document,
39
+ Lexer,
40
+ LineCounter,
41
+ Pair,
42
+ Parser,
43
+ Scalar,
44
+ Schema,
45
+ YAMLError,
46
+ YAMLMap,
47
+ YAMLParseError,
48
+ YAMLSeq,
49
+ YAMLWarning,
50
+ browser_default as default,
51
+ isAlias,
52
+ isCollection,
53
+ isDocument,
54
+ isMap,
55
+ isNode,
56
+ isPair,
57
+ isScalar,
58
+ isSeq,
59
+ parse,
60
+ parseAllDocuments,
61
+ parseDocument,
62
+ stringify,
63
+ visit,
64
+ visitAsync
65
+ };
@@ -5,10 +5,10 @@ import {
5
5
  UiFailed,
6
6
  UiForbidden,
7
7
  UiUnauthorized
8
- } from "./chunk-3ANFZFCV.js";
8
+ } from "./chunk-OHRT55C4.js";
9
9
  import {
10
10
  Schema_exports
11
- } from "./chunk-2OTCEKL2.js";
11
+ } from "./chunk-FW5HBOIK.js";
12
12
 
13
13
  // src/contracts/ui-auth.ts
14
14
  var AppSignInId = Schema_exports.String.check(Schema_exports.isPattern(/^[a-f0-9]{64}$/)).pipe(
@@ -0,0 +1,172 @@
1
+ import {
2
+ CacheError
3
+ } from "./chunk-LGIYBDWA.js";
4
+ import {
5
+ wrap
6
+ } from "./chunk-WFSQXYUT.js";
7
+ import {
8
+ JsonObject
9
+ } from "./chunk-SATWJKN6.js";
10
+ import {
11
+ Duration_exports,
12
+ Effect_exports,
13
+ Schema_exports
14
+ } from "./chunk-FW5HBOIK.js";
15
+
16
+ // src/implementation/catalog-cache.ts
17
+ var schema = (decoder) => wrap(decoder, false);
18
+ var Manifest = Schema_exports.Struct({
19
+ revision: Schema_exports.String,
20
+ pages: Schema_exports.Int,
21
+ summaries: Schema_exports.Int
22
+ });
23
+ var invoke = (work) => Effect_exports.tryPromise({ try: work, catch: (error) => error });
24
+ var catalogCache = (options) => Effect_exports.gen(function* () {
25
+ const cache = options.cache;
26
+ const key = [...options.prefix, "current"];
27
+ const part = (revision, kind, name) => [
28
+ ...options.prefix,
29
+ revision,
30
+ kind,
31
+ name
32
+ ];
33
+ const freshFor = options.freshFor ?? "5 minutes";
34
+ const staleFor = options.staleFor ?? "1 day";
35
+ const retention = Duration_exports.toMillis(Duration_exports.fromInputUnsafe(freshFor)) + Duration_exports.toMillis(Duration_exports.fromInputUnsafe(staleFor)) + 3e5;
36
+ const local = yield* Effect_exports.cached(options.load());
37
+ const refresh = (context) => Effect_exports.gen(function* () {
38
+ const tools = yield* options.load(context);
39
+ const digest = yield* invoke(
40
+ () => crypto.subtle.digest("SHA-256", new TextEncoder().encode(JSON.stringify(tools)))
41
+ );
42
+ const revision = Array.from(
43
+ new Uint8Array(digest),
44
+ (byte) => byte.toString(16).padStart(2, "0")
45
+ ).join("");
46
+ let pages2 = 0;
47
+ let page = [];
48
+ let pageBytes = 0;
49
+ let summaries = 0;
50
+ let summary = [];
51
+ let summaryBytes = 0;
52
+ let batch = [];
53
+ let batchBytes = 0;
54
+ let flushes = 0;
55
+ const flush = () => Effect_exports.suspend(() => {
56
+ const entries = batch;
57
+ const bytes = batchBytes;
58
+ batch = [];
59
+ batchBytes = 0;
60
+ if (!entries.length) return Effect_exports.void;
61
+ return invoke(() => context.cache.write(entries, retention)).pipe(
62
+ Effect_exports.withSpan("app.cache.flush", {
63
+ attributes: {
64
+ "cache.flush.index": flushes++,
65
+ "cache.flush.entries": entries.length,
66
+ "cache.flush.bytes": bytes
67
+ }
68
+ })
69
+ );
70
+ });
71
+ const append = (entry) => Effect_exports.gen(function* () {
72
+ const bytes = new TextEncoder().encode(JSON.stringify(entry)).byteLength;
73
+ if (batch.length && (batch.length >= 64 || batchBytes + bytes > 4e6))
74
+ yield* flush();
75
+ batch.push(entry);
76
+ batchBytes += bytes;
77
+ });
78
+ const pageOut = () => Effect_exports.gen(function* () {
79
+ if (!page.length) return;
80
+ yield* append({ key: part(revision, "page", pages2++), value: page });
81
+ page = [];
82
+ pageBytes = 0;
83
+ });
84
+ const summaryOut = () => Effect_exports.gen(function* () {
85
+ if (!summary.length) return;
86
+ yield* append({ key: part(revision, "summary", summaries++), value: summary });
87
+ summary = [];
88
+ summaryBytes = 0;
89
+ });
90
+ const json = (value) => Schema_exports.decodeUnknownEffect(Schema_exports.fromJsonString(JsonObject))(JSON.stringify(value));
91
+ for (const tool of tools) {
92
+ const value = yield* json(tool);
93
+ const bytes = new TextEncoder().encode(JSON.stringify(value)).byteLength;
94
+ if (page.length && (page.length >= 64 || pageBytes + bytes > 5e5)) yield* pageOut();
95
+ yield* append({ key: part(revision, "tool", tool.name), value });
96
+ page.push(value);
97
+ pageBytes += bytes;
98
+ const brief = yield* json(options.summary.of(tool));
99
+ const briefBytes = new TextEncoder().encode(JSON.stringify(brief)).byteLength;
100
+ if (summary.length && summaryBytes + briefBytes > 5e5) yield* summaryOut();
101
+ summary.push(brief);
102
+ summaryBytes += briefBytes;
103
+ }
104
+ yield* pageOut();
105
+ yield* summaryOut();
106
+ yield* flush();
107
+ return { revision, pages: pages2, summaries };
108
+ });
109
+ const getOptions = {
110
+ key,
111
+ schema: schema(Manifest),
112
+ freshFor,
113
+ staleFor,
114
+ load: (context) => Effect_exports.runPromise(refresh(context), { signal: context.signal })
115
+ };
116
+ const current = () => cache === void 0 ? Effect_exports.fail(new CacheError({ reason: "unavailable" })) : invoke(() => cache.get(getOptions));
117
+ if (options.revalidate) {
118
+ if (cache === void 0) yield* local;
119
+ else yield* invoke(() => cache.revalidate(getOptions));
120
+ }
121
+ const pages = (cache2, revision, kind, count, decoder) => Effect_exports.gen(function* () {
122
+ const batches = yield* Effect_exports.forEach(
123
+ Array.from({ length: Math.ceil(count / 4) }, (_, batch) => batch * 4),
124
+ (offset) => invoke(
125
+ () => cache2.readMany(
126
+ Array.from(
127
+ { length: Math.min(4, count - offset) },
128
+ (_, index) => part(revision, kind, offset + index)
129
+ ),
130
+ schema(Schema_exports.Array(decoder))
131
+ )
132
+ ),
133
+ { concurrency: "unbounded" }
134
+ );
135
+ const values = [];
136
+ for (const page of batches.flat()) {
137
+ if (page === void 0) return yield* new CacheError({ reason: "unavailable" });
138
+ values.push(...page);
139
+ }
140
+ return values;
141
+ });
142
+ const metadata = () => Effect_exports.gen(function* () {
143
+ if (cache === void 0) return yield* local;
144
+ const manifest = yield* current();
145
+ return yield* pages(cache, manifest.revision, "page", manifest.pages, options.schema);
146
+ });
147
+ return {
148
+ list: metadata,
149
+ summaries: () => Effect_exports.gen(function* () {
150
+ if (cache === void 0) return (yield* local).map((tool) => options.summary.of(tool));
151
+ const manifest = yield* current();
152
+ return yield* pages(
153
+ cache,
154
+ manifest.revision,
155
+ "summary",
156
+ manifest.summaries,
157
+ options.summary.schema
158
+ );
159
+ }),
160
+ resolve: (name) => cache === void 0 ? local.pipe(Effect_exports.map((tools) => tools.find((tool) => tool.name === name))) : current().pipe(
161
+ Effect_exports.flatMap(
162
+ (manifest) => invoke(
163
+ () => cache.read(part(manifest.revision, "tool", name), schema(options.schema))
164
+ )
165
+ )
166
+ )
167
+ };
168
+ });
169
+
170
+ export {
171
+ catalogCache
172
+ };
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  Schema_exports
3
- } from "./chunk-2OTCEKL2.js";
3
+ } from "./chunk-FW5HBOIK.js";
4
4
 
5
5
  // ../app-data/src/contracts/database.ts
6
6
  var DataName = Schema_exports.String.check(
@@ -0,0 +1,39 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __commonJS = (cb, mod) => function __require() {
8
+ try {
9
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
10
+ } catch (e) {
11
+ throw mod = 0, e;
12
+ }
13
+ };
14
+ var __export = (target, all) => {
15
+ for (var name in all)
16
+ __defProp(target, name, { get: all[name], enumerable: true });
17
+ };
18
+ var __copyProps = (to, from, except, desc) => {
19
+ if (from && typeof from === "object" || typeof from === "function") {
20
+ for (let key of __getOwnPropNames(from))
21
+ if (!__hasOwnProp.call(to, key) && key !== except)
22
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
23
+ }
24
+ return to;
25
+ };
26
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
27
+ // If the importer is in node compatibility mode or this is not an ESM
28
+ // file that has been converted to a CommonJS file using a Babel-
29
+ // compatible transform (i.e. "__esModule" has not been set), then set
30
+ // "default" to the CommonJS "module.exports" for node compatibility.
31
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
32
+ mod
33
+ ));
34
+
35
+ export {
36
+ __commonJS,
37
+ __export,
38
+ __toESM
39
+ };
@@ -0,0 +1,172 @@
1
+ import {
2
+ CacheAcquired,
3
+ CacheEntry,
4
+ CacheError,
5
+ cacheLimits
6
+ } from "./chunk-LGIYBDWA.js";
7
+ import {
8
+ Clock_exports,
9
+ Duration_exports,
10
+ Effect_exports,
11
+ Exit_exports,
12
+ Schema_exports
13
+ } from "./chunk-FW5HBOIK.js";
14
+
15
+ // ../app-cache/src/index.ts
16
+ var canonical = (value) => {
17
+ if (Array.isArray(value)) return `[${value.map(canonical).join(",")}]`;
18
+ if (value !== null && typeof value === "object")
19
+ return `{${Object.entries(value).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0).map(([key, item]) => `${JSON.stringify(key)}:${canonical(item)}`).join(",")}}`;
20
+ return JSON.stringify(value);
21
+ };
22
+ var cacheKey = (key) => Effect_exports.gen(function* () {
23
+ const parsed = yield* Schema_exports.decodeUnknownEffect(Schema_exports.Json)(key).pipe(
24
+ Effect_exports.mapError(() => new CacheError({ reason: "invalid" }))
25
+ );
26
+ const bytes = new TextEncoder().encode(canonical(parsed));
27
+ if (bytes.byteLength > cacheLimits.keyBytes)
28
+ return yield* new CacheError({ reason: "capacity" });
29
+ const hash = yield* Effect_exports.tryPromise({
30
+ try: () => crypto.subtle.digest("SHA-256", bytes),
31
+ catch: () => new CacheError({ reason: "invalid" })
32
+ });
33
+ return [...new Uint8Array(hash)].map((byte) => byte.toString(16).padStart(2, "0")).join("");
34
+ });
35
+ var makeCache = (host, background, scope = "shared", deadline) => {
36
+ const transport = (command) => host(command).pipe(
37
+ Effect_exports.withSpan("app.cache.command", {
38
+ attributes: { "cache.operation": command.operation }
39
+ })
40
+ );
41
+ const keyOf = (key) => cacheKey([scope, key]);
42
+ const readKeys = (keys) => transport({ operation: "read", keys }).pipe(
43
+ Effect_exports.flatMap(Schema_exports.decodeUnknownEffect(Schema_exports.Array(Schema_exports.NullOr(CacheEntry)))),
44
+ Effect_exports.mapError(() => new CacheError({ reason: "storage" }))
45
+ );
46
+ const durations = (freshFor, staleFor = 0) => Effect_exports.try({
47
+ try: () => {
48
+ const fresh = Duration_exports.toMillis(Duration_exports.fromInputUnsafe(freshFor));
49
+ const stale = Duration_exports.toMillis(Duration_exports.fromInputUnsafe(staleFor));
50
+ if (![fresh, stale].every((value) => Number.isFinite(value) && value >= 0) || fresh + stale > cacheLimits.retentionMs)
51
+ throw new CacheError({ reason: "invalid" });
52
+ return { fresh, stale };
53
+ },
54
+ catch: () => new CacheError({ reason: "invalid" })
55
+ });
56
+ const get = (options, refresh) => Effect_exports.gen(function* () {
57
+ const key = yield* keyOf(options.key);
58
+ const { fresh, stale } = yield* durations(options.freshFor, options.staleFor);
59
+ const decode = (value) => Schema_exports.decodeUnknownEffect(options.schema)(value);
60
+ const load = (lease) => Effect_exports.gen(function* () {
61
+ const value = yield* options.load.pipe(Effect_exports.flatMap(decode));
62
+ const json = yield* Schema_exports.decodeUnknownEffect(Schema_exports.Json)(value).pipe(
63
+ Effect_exports.mapError(() => new CacheError({ reason: "invalid" }))
64
+ );
65
+ const now = yield* Clock_exports.currentTimeMillis;
66
+ const published = yield* transport({
67
+ operation: "publish",
68
+ key,
69
+ lease,
70
+ entry: {
71
+ value: json,
72
+ version: crypto.randomUUID(),
73
+ freshUntil: now + fresh,
74
+ staleUntil: now + fresh + stale
75
+ }
76
+ }).pipe(Effect_exports.withSpan("app.cache.publish"));
77
+ if (published !== true) return yield* new CacheError({ reason: "unavailable" });
78
+ return value;
79
+ }).pipe(
80
+ Effect_exports.withSpan("app.cache.load"),
81
+ Effect_exports.timeout(cacheLimits.loadTimeoutMs),
82
+ // Publishing clears the lease in the same transaction. Only an unpublished load releases it.
83
+ Effect_exports.onExit(
84
+ (exit) => Exit_exports.isSuccess(exit) ? Effect_exports.void : transport({ operation: "release", key, lease }).pipe(
85
+ Effect_exports.catch(() => Effect_exports.void)
86
+ )
87
+ )
88
+ );
89
+ const waitUntil = Math.min(
90
+ (yield* Clock_exports.currentTimeMillis) + cacheLimits.waitMs,
91
+ deadline ?? Number.POSITIVE_INFINITY
92
+ );
93
+ let initialVersion;
94
+ while (true) {
95
+ const { entry, lease } = yield* transport({
96
+ operation: "acquire",
97
+ key,
98
+ refresh,
99
+ ...initialVersion === void 0 ? {} : { version: initialVersion }
100
+ }).pipe(
101
+ Effect_exports.flatMap(
102
+ (reply) => Schema_exports.decodeUnknownEffect(CacheAcquired)(reply).pipe(
103
+ Effect_exports.mapError(() => new CacheError({ reason: "storage" }))
104
+ )
105
+ )
106
+ );
107
+ const now = yield* Clock_exports.currentTimeMillis;
108
+ if (initialVersion === void 0) initialVersion = entry?.version ?? null;
109
+ const refreshed = refresh && entry !== null && entry.version !== initialVersion;
110
+ if (entry !== null && (refreshed || !refresh && lease === null && now < entry.freshUntil)) {
111
+ yield* Effect_exports.annotateCurrentSpan("cache.result", "fresh");
112
+ return yield* decode(entry.value);
113
+ }
114
+ if (!refresh && entry !== null && now < entry.staleUntil) {
115
+ yield* Effect_exports.annotateCurrentSpan("cache.result", "stale");
116
+ if (lease !== null) yield* background(load(lease).pipe(Effect_exports.asVoid));
117
+ return yield* decode(entry.value);
118
+ }
119
+ if (lease !== null) {
120
+ yield* Effect_exports.annotateCurrentSpan("cache.result", "miss");
121
+ return yield* load(lease);
122
+ }
123
+ if (now >= waitUntil) {
124
+ yield* Effect_exports.annotateCurrentSpan("cache.result", "local");
125
+ return yield* options.load.pipe(
126
+ Effect_exports.flatMap(decode),
127
+ Effect_exports.timeout(cacheLimits.loadTimeoutMs),
128
+ Effect_exports.withSpan("app.cache.load", { attributes: { "cache.load.leased": false } })
129
+ );
130
+ }
131
+ yield* Effect_exports.sleep("100 millis");
132
+ }
133
+ }).pipe(Effect_exports.withSpan("app.cache.get"));
134
+ return {
135
+ /** Read arbitrary retained JSON entries without initiating a refresh. Missing and null are distinct. */
136
+ read: (keys) => Effect_exports.forEach(keys, keyOf).pipe(Effect_exports.flatMap(readKeys)),
137
+ /** Publish bounded immutable parts before publishing the manifest that references them. */
138
+ write: (entries, retention) => Effect_exports.gen(function* () {
139
+ const { fresh } = yield* durations(retention);
140
+ const now = yield* Clock_exports.currentTimeMillis;
141
+ const values = yield* Effect_exports.forEach(
142
+ entries,
143
+ ({ key, value }) => Effect_exports.gen(function* () {
144
+ return {
145
+ key: yield* keyOf(key),
146
+ entry: {
147
+ value,
148
+ version: crypto.randomUUID(),
149
+ freshUntil: now + fresh,
150
+ staleUntil: now + fresh
151
+ }
152
+ };
153
+ })
154
+ );
155
+ yield* transport({ operation: "write", entries: values });
156
+ }),
157
+ /** Revoke retained data and any loader's right to publish its in-flight result. */
158
+ invalidate: (key) => keyOf(key).pipe(
159
+ Effect_exports.flatMap((key2) => transport({ operation: "invalidate", key: key2 })),
160
+ Effect_exports.asVoid
161
+ ),
162
+ /** Read fresh data, refresh stale data in the background, or wait for the lease owner. */
163
+ get: (options) => get(options, false),
164
+ /** Force one awaited refresh without removing the retained value. Concurrent refreshes share a load. */
165
+ revalidate: (options) => get(options, true)
166
+ };
167
+ };
168
+
169
+ export {
170
+ cacheKey,
171
+ makeCache
172
+ };
@@ -3,7 +3,7 @@ import {
3
3
  invalidate,
4
4
  layer,
5
5
  mutation
6
- } from "./chunk-D6BKYP2L.js";
6
+ } from "./chunk-M6ZRRIBI.js";
7
7
  import {
8
8
  Boolean,
9
9
  Cause,
@@ -158,12 +158,12 @@ import {
158
158
  void_2,
159
159
  whileLoop,
160
160
  zipRight
161
- } from "./chunk-2OTCEKL2.js";
161
+ } from "./chunk-FW5HBOIK.js";
162
162
  import {
163
163
  __export
164
- } from "./chunk-MLKGABMK.js";
164
+ } from "./chunk-CZ7CSFO4.js";
165
165
 
166
- // ../../node_modules/.bun/effect@https+++pkg.pr.new+Effect-TS+effect+effect@c7d1ffff31a3e2ae0b0b0796b742bddeb797269d/node_modules/effect/dist/unstable/reactivity/AsyncResult.js
166
+ // ../../node_modules/.bun/effect@https+++pkg.pr.new+Effect-TS+effect+effect@c7d1ffff31a3e2ae0b0b+a654a55b752bdb24/node_modules/effect/dist/unstable/reactivity/AsyncResult.js
167
167
  var AsyncResult_exports = {};
168
168
  __export(AsyncResult_exports, {
169
169
  Schema: () => Schema,
@@ -600,7 +600,7 @@ var Schema = (options) => {
600
600
  });
601
601
  };
602
602
 
603
- // ../../node_modules/.bun/effect@https+++pkg.pr.new+Effect-TS+effect+effect@c7d1ffff31a3e2ae0b0b0796b742bddeb797269d/node_modules/effect/dist/unstable/reactivity/AtomRegistry.js
603
+ // ../../node_modules/.bun/effect@https+++pkg.pr.new+Effect-TS+effect+effect@c7d1ffff31a3e2ae0b0b+a654a55b752bdb24/node_modules/effect/dist/unstable/reactivity/AtomRegistry.js
604
604
  var AtomRegistry_exports = {};
605
605
  __export(AtomRegistry_exports, {
606
606
  AtomRegistry: () => AtomRegistry,
@@ -1340,7 +1340,7 @@ function batchRebuildNode(node) {
1340
1340
  }
1341
1341
  }
1342
1342
 
1343
- // ../../node_modules/.bun/effect@https+++pkg.pr.new+Effect-TS+effect+effect@c7d1ffff31a3e2ae0b0b0796b742bddeb797269d/node_modules/effect/dist/unstable/reactivity/Atom.js
1343
+ // ../../node_modules/.bun/effect@https+++pkg.pr.new+Effect-TS+effect+effect@c7d1ffff31a3e2ae0b0b+a654a55b752bdb24/node_modules/effect/dist/unstable/reactivity/Atom.js
1344
1344
  var Atom_exports = {};
1345
1345
  __export(Atom_exports, {
1346
1346
  Interrupt: () => Interrupt,
@@ -1400,7 +1400,7 @@ __export(Atom_exports, {
1400
1400
  writable: () => writable
1401
1401
  });
1402
1402
 
1403
- // ../../node_modules/.bun/effect@https+++pkg.pr.new+Effect-TS+effect+effect@c7d1ffff31a3e2ae0b0b0796b742bddeb797269d/node_modules/effect/dist/unstable/persistence/KeyValueStore.js
1403
+ // ../../node_modules/.bun/effect@https+++pkg.pr.new+Effect-TS+effect+effect@c7d1ffff31a3e2ae0b0b+a654a55b752bdb24/node_modules/effect/dist/unstable/persistence/KeyValueStore.js
1404
1404
  var ErrorTypeId = "~effect/persistence/KeyValueStore/KeyValueStoreError";
1405
1405
  var KeyValueStoreError = class extends (/* @__PURE__ */ TaggedError("KeyValueStoreError")) {
1406
1406
  /**
@@ -1442,7 +1442,7 @@ var toSchemaStore = (self, schema) => {
1442
1442
  };
1443
1443
  };
1444
1444
 
1445
- // ../../node_modules/.bun/effect@https+++pkg.pr.new+Effect-TS+effect+effect@c7d1ffff31a3e2ae0b0b0796b742bddeb797269d/node_modules/effect/dist/unstable/reactivity/Atom.js
1445
+ // ../../node_modules/.bun/effect@https+++pkg.pr.new+Effect-TS+effect+effect@c7d1ffff31a3e2ae0b0b+a654a55b752bdb24/node_modules/effect/dist/unstable/reactivity/Atom.js
1446
1446
  var TypeId3 = "~effect/reactivity/Atom";
1447
1447
  var isAtom = (u) => hasProperty(u, TypeId3);
1448
1448
  var WritableTypeId = "~effect/reactivity/Atom/Writable";
@@ -0,0 +1,78 @@
1
+ import {
2
+ AppSkillMetadata,
3
+ AppSkillName,
4
+ AppSkillSource,
5
+ SkillDefinitionInvalid,
6
+ SkillFile,
7
+ SkillFilePath
8
+ } from "./chunk-YEJOQEII.js";
9
+ import {
10
+ Effect_exports,
11
+ Schema_exports
12
+ } from "./chunk-FW5HBOIK.js";
13
+
14
+ // src/implementation/skill-files.ts
15
+ var skillFromFiles = (input, source = {}) => Effect_exports.gen(function* () {
16
+ const file = `${source.directory === void 0 ? "" : `${source.directory}/`}SKILL.md`;
17
+ const invalid = (reason) => new SkillDefinitionInvalid({ file, reason });
18
+ const files = yield* Schema_exports.decodeUnknownEffect(Schema_exports.Array(SkillFile))(input).pipe(
19
+ Effect_exports.mapError(() => invalid("files"))
20
+ );
21
+ const document = files.find((file2) => file2.path === "SKILL.md");
22
+ if (document === void 0) return yield* invalid("missing-document");
23
+ const match = /^\uFEFF?---[ \t]*\r?\n([\s\S]*?)\r?\n---(?:[ \t]*\r?\n|[ \t]*$)/.exec(
24
+ document.content
25
+ );
26
+ if (match?.[1] === void 0) return yield* invalid("frontmatter");
27
+ const frontmatter = match[1];
28
+ const { parseDocument } = (yield* Effect_exports.promise(() => import("./browser-XIPJGLH2.js"))).default;
29
+ const value = yield* Effect_exports.try({
30
+ try: () => {
31
+ const yaml = parseDocument(frontmatter);
32
+ if (yaml.errors.length) throw yaml.errors[0];
33
+ return yaml.toJS();
34
+ },
35
+ catch: () => invalid("frontmatter")
36
+ });
37
+ const metadata = yield* Schema_exports.decodeUnknownEffect(AppSkillMetadata)(value).pipe(
38
+ Effect_exports.mapError(() => invalid("metadata"))
39
+ );
40
+ if (source.name !== void 0 && metadata.name !== source.name)
41
+ return yield* invalid("name-mismatch");
42
+ return yield* Schema_exports.decodeUnknownEffect(AppSkillSource)({ ...metadata, files }).pipe(
43
+ Effect_exports.mapError(() => invalid("files"))
44
+ );
45
+ });
46
+ var folderSkillsEffect = (options) => Effect_exports.gen(function* () {
47
+ const path = options.path ?? "skills";
48
+ if (!Schema_exports.is(SkillFilePath)(path))
49
+ return yield* new SkillDefinitionInvalid({ file: "SKILL.md", reason: "directory" });
50
+ const files = yield* Schema_exports.decodeUnknownEffect(Schema_exports.Array(SkillFile))(options.files).pipe(
51
+ Effect_exports.mapError(() => new SkillDefinitionInvalid({ file: path, reason: "files" }))
52
+ );
53
+ const prefix = `${path}/`;
54
+ const directories = /* @__PURE__ */ new Map();
55
+ for (const file of files) {
56
+ if (!file.path.startsWith(prefix)) continue;
57
+ const [name, ...relative] = file.path.slice(prefix.length).split("/");
58
+ if (relative.length === 0) continue;
59
+ if (name === void 0 || !Schema_exports.is(AppSkillName)(name))
60
+ return yield* new SkillDefinitionInvalid({ file: file.path, reason: "directory" });
61
+ const resource = { path: relative.join("/"), content: file.content };
62
+ const existing = directories.get(name);
63
+ if (existing === void 0) directories.set(name, [resource]);
64
+ else existing.push(resource);
65
+ }
66
+ return yield* Effect_exports.forEach(
67
+ [...directories].sort(([a], [b]) => a.localeCompare(b)),
68
+ ([name, files2]) => skillFromFiles(
69
+ files2.sort((a, b) => a.path.localeCompare(b.path)),
70
+ { name, directory: `${path}/${name}` }
71
+ )
72
+ );
73
+ });
74
+
75
+ export {
76
+ skillFromFiles,
77
+ folderSkillsEffect
78
+ };