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
package/js/skills.js ADDED
@@ -0,0 +1,894 @@
1
+ import {
2
+ catalogCache
3
+ } from "./chunk-5MQZEB6Y.js";
4
+ import "./chunk-D47C7KG5.js";
5
+ import {
6
+ folderSkillsEffect,
7
+ skillFromFiles
8
+ } from "./chunk-FDNTX5QJ.js";
9
+ import {
10
+ httpProviderError
11
+ } from "./chunk-ZJWDMTE3.js";
12
+ import "./chunk-LGIYBDWA.js";
13
+ import {
14
+ AppSkillMetadata,
15
+ AppSkillSource,
16
+ AppSkills,
17
+ SkillDefinitionInvalid,
18
+ SkillFilePath,
19
+ SkillLoadFailed,
20
+ SkillServiceName,
21
+ skillLoadLimits
22
+ } from "./chunk-YEJOQEII.js";
23
+ import "./chunk-W7D7WVSY.js";
24
+ import {
25
+ FetchHttpClient_exports
26
+ } from "./chunk-HDJH3RPR.js";
27
+ import {
28
+ HttpBody_exports,
29
+ HttpClient_exports
30
+ } from "./chunk-QKHR7BMF.js";
31
+ import {
32
+ wrap
33
+ } from "./chunk-WFSQXYUT.js";
34
+ import "./chunk-SATWJKN6.js";
35
+ import {
36
+ Effect_exports,
37
+ Ref_exports,
38
+ Schema_exports,
39
+ Stream_exports
40
+ } from "./chunk-FW5HBOIK.js";
41
+ import "./chunk-CZ7CSFO4.js";
42
+
43
+ // src/implementation/inflate.ts
44
+ var InflateError = class extends Error {
45
+ };
46
+ var InflateLimitExceeded = class extends Error {
47
+ };
48
+ var huffman = (lengths, offset, count) => {
49
+ const counts = new Uint16Array(16);
50
+ const symbols = new Uint16Array(count);
51
+ for (let index = 0; index < count; index++) counts[lengths[offset + index]]++;
52
+ counts[0] = 0;
53
+ const offsets = new Uint16Array(16);
54
+ for (let length = 1; length < 16; length++)
55
+ offsets[length] = offsets[length - 1] + counts[length - 1];
56
+ for (let index = 0; index < count; index++) {
57
+ const length = lengths[offset + index];
58
+ if (length !== 0) symbols[offsets[length]++] = index;
59
+ }
60
+ return { counts, symbols };
61
+ };
62
+ var lengthBase = [
63
+ 3,
64
+ 4,
65
+ 5,
66
+ 6,
67
+ 7,
68
+ 8,
69
+ 9,
70
+ 10,
71
+ 11,
72
+ 13,
73
+ 15,
74
+ 17,
75
+ 19,
76
+ 23,
77
+ 27,
78
+ 31,
79
+ 35,
80
+ 43,
81
+ 51,
82
+ 59,
83
+ 67,
84
+ 83,
85
+ 99,
86
+ 115,
87
+ 131,
88
+ 163,
89
+ 195,
90
+ 227,
91
+ 258
92
+ ];
93
+ var lengthExtra = [
94
+ 0,
95
+ 0,
96
+ 0,
97
+ 0,
98
+ 0,
99
+ 0,
100
+ 0,
101
+ 0,
102
+ 1,
103
+ 1,
104
+ 1,
105
+ 1,
106
+ 2,
107
+ 2,
108
+ 2,
109
+ 2,
110
+ 3,
111
+ 3,
112
+ 3,
113
+ 3,
114
+ 4,
115
+ 4,
116
+ 4,
117
+ 4,
118
+ 5,
119
+ 5,
120
+ 5,
121
+ 5,
122
+ 0
123
+ ];
124
+ var distanceBase = [
125
+ 1,
126
+ 2,
127
+ 3,
128
+ 4,
129
+ 5,
130
+ 7,
131
+ 9,
132
+ 13,
133
+ 17,
134
+ 25,
135
+ 33,
136
+ 49,
137
+ 65,
138
+ 97,
139
+ 129,
140
+ 193,
141
+ 257,
142
+ 385,
143
+ 513,
144
+ 769,
145
+ 1025,
146
+ 1537,
147
+ 2049,
148
+ 3073,
149
+ 4097,
150
+ 6145,
151
+ 8193,
152
+ 12289,
153
+ 16385,
154
+ 24577
155
+ ];
156
+ var distanceExtra = [
157
+ 0,
158
+ 0,
159
+ 0,
160
+ 0,
161
+ 1,
162
+ 1,
163
+ 2,
164
+ 2,
165
+ 3,
166
+ 3,
167
+ 4,
168
+ 4,
169
+ 5,
170
+ 5,
171
+ 6,
172
+ 6,
173
+ 7,
174
+ 7,
175
+ 8,
176
+ 8,
177
+ 9,
178
+ 9,
179
+ 10,
180
+ 10,
181
+ 11,
182
+ 11,
183
+ 12,
184
+ 12,
185
+ 13,
186
+ 13
187
+ ];
188
+ var codeLengthOrder = [16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15];
189
+ var fixedLengths = new Uint8Array(288 + 30);
190
+ fixedLengths.fill(8, 0, 144);
191
+ fixedLengths.fill(9, 144, 256);
192
+ fixedLengths.fill(7, 256, 280);
193
+ fixedLengths.fill(8, 280, 288);
194
+ fixedLengths.fill(5, 288, 318);
195
+ var fixedLiteral = huffman(fixedLengths, 0, 288);
196
+ var fixedDistance = huffman(fixedLengths, 288, 30);
197
+ var inflateZlib = (input, start, limit) => {
198
+ if (start + 2 > input.byteLength) throw new InflateError("truncated header");
199
+ const cmf = input[start];
200
+ const flags = input[start + 1];
201
+ if ((cmf & 15) !== 8 || (cmf << 8 | flags) % 31 !== 0 || flags & 32)
202
+ throw new InflateError("invalid zlib header");
203
+ let position = start + 2;
204
+ let bitBuffer = 0;
205
+ let bitCount = 0;
206
+ let output = new Uint8Array(Math.min(limit, 1024));
207
+ let length = 0;
208
+ const bits = (count) => {
209
+ while (bitCount < count) {
210
+ if (position >= input.byteLength) throw new InflateError("truncated stream");
211
+ bitBuffer |= input[position++] << bitCount;
212
+ bitCount += 8;
213
+ }
214
+ const value = bitBuffer & (1 << count) - 1;
215
+ bitBuffer >>>= count;
216
+ bitCount -= count;
217
+ return value;
218
+ };
219
+ const decode = ({ counts, symbols }) => {
220
+ let code = 0;
221
+ let first = 0;
222
+ let index = 0;
223
+ for (let bitLength = 1; bitLength < 16; bitLength++) {
224
+ code |= bits(1);
225
+ const count = counts[bitLength];
226
+ if (code - count < first) return symbols[index + (code - first)];
227
+ index += count;
228
+ first += count;
229
+ first <<= 1;
230
+ code <<= 1;
231
+ }
232
+ throw new InflateError("invalid code");
233
+ };
234
+ const reserve = (extra) => {
235
+ if (length + extra > limit) throw new InflateLimitExceeded();
236
+ if (length + extra <= output.byteLength) return;
237
+ const next = new Uint8Array(Math.min(limit, Math.max(output.byteLength * 2, length + extra)));
238
+ next.set(output.subarray(0, length));
239
+ output = next;
240
+ };
241
+ const codes = (literal, distance) => {
242
+ for (; ; ) {
243
+ const symbol = decode(literal);
244
+ if (symbol < 256) {
245
+ reserve(1);
246
+ output[length++] = symbol;
247
+ } else if (symbol === 256) {
248
+ return;
249
+ } else {
250
+ const lengthIndex = symbol - 257;
251
+ if (lengthIndex >= 29) throw new InflateError("invalid length symbol");
252
+ const size = lengthBase[lengthIndex] + bits(lengthExtra[lengthIndex]);
253
+ const distanceIndex = decode(distance);
254
+ if (distanceIndex >= 30) throw new InflateError("invalid distance symbol");
255
+ const back = distanceBase[distanceIndex] + bits(distanceExtra[distanceIndex]);
256
+ if (back > length) throw new InflateError("distance too far back");
257
+ reserve(size);
258
+ for (let copied = 0; copied < size; copied++, length++)
259
+ output[length] = output[length - back];
260
+ }
261
+ }
262
+ };
263
+ let last = 0;
264
+ while (!last) {
265
+ last = bits(1);
266
+ const type = bits(2);
267
+ if (type === 0) {
268
+ bitBuffer = 0;
269
+ bitCount = 0;
270
+ if (position + 4 > input.byteLength) throw new InflateError("truncated stored block");
271
+ const size = input[position] | input[position + 1] << 8;
272
+ const complement = input[position + 2] | input[position + 3] << 8;
273
+ if ((size ^ 65535) !== complement) throw new InflateError("invalid stored block");
274
+ position += 4;
275
+ if (position + size > input.byteLength) throw new InflateError("truncated stored block");
276
+ reserve(size);
277
+ output.set(input.subarray(position, position + size), length);
278
+ length += size;
279
+ position += size;
280
+ } else if (type === 1) {
281
+ codes(fixedLiteral, fixedDistance);
282
+ } else if (type === 2) {
283
+ const literalCount = bits(5) + 257;
284
+ const distanceCount = bits(5) + 1;
285
+ const codeLengthCount = bits(4) + 4;
286
+ const codeLengths = new Uint8Array(19);
287
+ for (let index = 0; index < codeLengthCount; index++)
288
+ codeLengths[codeLengthOrder[index]] = bits(3);
289
+ const codeLengthCode = huffman(codeLengths, 0, 19);
290
+ const lengths = new Uint8Array(literalCount + distanceCount);
291
+ for (let index = 0; index < lengths.byteLength; ) {
292
+ const symbol = decode(codeLengthCode);
293
+ if (symbol < 16) {
294
+ lengths[index++] = symbol;
295
+ continue;
296
+ }
297
+ let repeat;
298
+ let value = 0;
299
+ if (symbol === 16) {
300
+ if (index === 0) throw new InflateError("repeat without length");
301
+ value = lengths[index - 1];
302
+ repeat = 3 + bits(2);
303
+ } else if (symbol === 17) repeat = 3 + bits(3);
304
+ else repeat = 11 + bits(7);
305
+ if (index + repeat > lengths.byteLength) throw new InflateError("too many lengths");
306
+ lengths.fill(value, index, index + repeat);
307
+ index += repeat;
308
+ }
309
+ codes(huffman(lengths, 0, literalCount), huffman(lengths, literalCount, distanceCount));
310
+ } else {
311
+ throw new InflateError("invalid block type");
312
+ }
313
+ }
314
+ if (position + 4 > input.byteLength) throw new InflateError("truncated checksum");
315
+ const data = output.subarray(0, length);
316
+ let a = 1;
317
+ let b = 0;
318
+ for (let index = 0; index < data.byteLength; index++) {
319
+ a = (a + data[index]) % 65521;
320
+ b = (b + a) % 65521;
321
+ }
322
+ const expected = (input[position] << 24 | input[position + 1] << 16 | input[position + 2] << 8 | input[position + 3]) >>> 0;
323
+ if ((b << 16 | a) >>> 0 !== expected) throw new InflateError("checksum mismatch");
324
+ return { data, end: position + 4 };
325
+ };
326
+
327
+ // src/implementation/git.ts
328
+ var encoder = new TextEncoder();
329
+ var decoder = new TextDecoder();
330
+ var GitProtocolError = class extends Error {
331
+ };
332
+ var pkt = (line) => {
333
+ const bytes = encoder.encode(line);
334
+ return [...encoder.encode((bytes.byteLength + 4).toString(16).padStart(4, "0")), ...bytes];
335
+ };
336
+ var flush = [...encoder.encode("0000")];
337
+ var delimiter = [...encoder.encode("0001")];
338
+ var packets = (bytes) => {
339
+ const lines = [];
340
+ for (let at = 0; at < bytes.byteLength; ) {
341
+ if (at + 4 > bytes.byteLength) throw new GitProtocolError("truncated packet");
342
+ const size = Number.parseInt(decoder.decode(bytes.subarray(at, at + 4)), 16);
343
+ if (!Number.isInteger(size) || size === 3 || at + Math.max(size, 4) > bytes.byteLength)
344
+ throw new GitProtocolError("invalid packet length");
345
+ if (size < 4) {
346
+ lines.push("boundary");
347
+ at += 4;
348
+ continue;
349
+ }
350
+ lines.push(bytes.subarray(at + 4, at + size));
351
+ at += size;
352
+ }
353
+ return lines;
354
+ };
355
+ var gitRequestHeaders = {
356
+ "Content-Type": "application/x-git-upload-pack-request",
357
+ "Git-Protocol": "version=2"
358
+ };
359
+ var refCandidates = (ref) => ref === void 0 || ref === "HEAD" ? ["HEAD"] : [`refs/heads/${ref}`, `refs/tags/${ref}`];
360
+ var lsRefsRequest = (names) => new Uint8Array([
361
+ ...pkt("command=ls-refs\n"),
362
+ ...delimiter,
363
+ ...pkt("peel\n"),
364
+ ...names.flatMap((name) => pkt(`ref-prefix ${name}
365
+ `)),
366
+ ...flush
367
+ ]);
368
+ var parseLsRefs = (bytes) => {
369
+ const refs = /* @__PURE__ */ new Map();
370
+ for (const line of packets(bytes)) {
371
+ if (line === "boundary") continue;
372
+ const match = /^([a-f0-9]{40}) (\S+)(?: .*?peeled:([a-f0-9]{40}))?/.exec(decoder.decode(line));
373
+ if (match !== null) refs.set(match[2], match[3] ?? match[1]);
374
+ }
375
+ return refs;
376
+ };
377
+ var treeFetchRequest = (commit) => new Uint8Array([
378
+ ...pkt("command=fetch\n"),
379
+ ...delimiter,
380
+ ...pkt("no-progress\n"),
381
+ ...pkt("ofs-delta\n"),
382
+ ...pkt("deepen 1\n"),
383
+ ...pkt("filter blob:none\n"),
384
+ ...pkt(`want ${commit}
385
+ `),
386
+ ...pkt("done\n"),
387
+ ...flush
388
+ ]);
389
+ var packfile = (bytes) => {
390
+ const chunks = [];
391
+ let inPack = false;
392
+ for (const line of packets(bytes)) {
393
+ if (line === "boundary") continue;
394
+ if (!inPack) {
395
+ inPack = decoder.decode(line) === "packfile\n";
396
+ continue;
397
+ }
398
+ if (line[0] === 1) chunks.push(line.subarray(1));
399
+ else if (line[0] === 3) throw new GitProtocolError("remote error");
400
+ }
401
+ if (!inPack) throw new GitProtocolError("missing packfile");
402
+ const pack = new Uint8Array(chunks.reduce((size, chunk) => size + chunk.byteLength, 0));
403
+ let offset = 0;
404
+ for (const chunk of chunks) {
405
+ pack.set(chunk, offset);
406
+ offset += chunk.byteLength;
407
+ }
408
+ return pack;
409
+ };
410
+ var objectTypes = { 1: "commit", 2: "tree", 3: "blob", 4: "tag" };
411
+ var applyDelta = (base, delta) => {
412
+ let at = 0;
413
+ const size = () => {
414
+ let value = 0;
415
+ let shift = 0;
416
+ let byte;
417
+ do {
418
+ if (at >= delta.byteLength) throw new GitProtocolError("truncated delta");
419
+ byte = delta[at++];
420
+ value += (byte & 127) * 2 ** shift;
421
+ shift += 7;
422
+ } while (byte & 128);
423
+ return value;
424
+ };
425
+ if (size() !== base.byteLength) throw new GitProtocolError("delta base size mismatch");
426
+ const result = new Uint8Array(size());
427
+ let length = 0;
428
+ while (at < delta.byteLength) {
429
+ const op = delta[at++];
430
+ if (op & 128) {
431
+ let offset = 0;
432
+ let count = 0;
433
+ for (let bit = 0; bit < 4; bit++)
434
+ if (op & 1 << bit) offset += delta[at++] * 2 ** (8 * bit);
435
+ for (let bit = 0; bit < 3; bit++)
436
+ if (op & 1 << 4 + bit) count += delta[at++] * 2 ** (8 * bit);
437
+ if (count === 0) count = 65536;
438
+ if (offset + count > base.byteLength || length + count > result.byteLength)
439
+ throw new GitProtocolError("invalid delta copy");
440
+ result.set(base.subarray(offset, offset + count), length);
441
+ length += count;
442
+ } else if (op !== 0) {
443
+ if (at + op > delta.byteLength || length + op > result.byteLength)
444
+ throw new GitProtocolError("invalid delta insert");
445
+ result.set(delta.subarray(at, at + op), length);
446
+ length += op;
447
+ at += op;
448
+ } else {
449
+ throw new GitProtocolError("reserved delta opcode");
450
+ }
451
+ }
452
+ if (length !== result.byteLength) throw new GitProtocolError("delta size mismatch");
453
+ return result;
454
+ };
455
+ var hex = (bytes) => Array.from(bytes, (byte) => byte.toString(16).padStart(2, "0")).join("");
456
+ var objectId = async (type, data) => {
457
+ const header = encoder.encode(`${type} ${data.byteLength}\0`);
458
+ const whole = new Uint8Array(header.byteLength + data.byteLength);
459
+ whole.set(header);
460
+ whole.set(data, header.byteLength);
461
+ return hex(new Uint8Array(await crypto.subtle.digest("SHA-1", whole)));
462
+ };
463
+ var unpack = async (pack, limits) => {
464
+ if (decoder.decode(pack.subarray(0, 4)) !== "PACK" || pack.byteLength < 32)
465
+ throw new GitProtocolError("invalid packfile");
466
+ const view = new DataView(pack.buffer, pack.byteOffset, pack.byteLength);
467
+ const version = view.getUint32(4);
468
+ if (version !== 2 && version !== 3) throw new GitProtocolError("unsupported packfile version");
469
+ const count = view.getUint32(8);
470
+ const entries = /* @__PURE__ */ new Map();
471
+ let at = 12;
472
+ for (let index = 0; index < count; index++) {
473
+ const start = at;
474
+ let byte = pack[at++];
475
+ const code = byte >> 4 & 7;
476
+ while (byte & 128) byte = pack[at++];
477
+ if (code === 6) {
478
+ byte = pack[at++];
479
+ let back = byte & 127;
480
+ while (byte & 128) {
481
+ byte = pack[at++];
482
+ back = (back + 1) * 128 + (byte & 127);
483
+ }
484
+ const { data, end } = inflateZlib(pack, at, limits.objectBytes);
485
+ entries.set(start, { kind: "offset", base: start - back, delta: data });
486
+ at = end;
487
+ } else if (code === 7) {
488
+ const base = hex(pack.subarray(at, at + 20));
489
+ const { data, end } = inflateZlib(pack, at + 20, limits.objectBytes);
490
+ entries.set(start, { kind: "reference", base, delta: data });
491
+ at = end;
492
+ } else {
493
+ const type = objectTypes[code];
494
+ if (type === void 0) throw new GitProtocolError("invalid object type");
495
+ const { data, end } = inflateZlib(pack, at, limits.objectBytes);
496
+ entries.set(start, { kind: "whole", type, data });
497
+ at = end;
498
+ }
499
+ if (at > pack.byteLength) throw new GitProtocolError("truncated packfile");
500
+ }
501
+ const objects = /* @__PURE__ */ new Map();
502
+ const resolved = /* @__PURE__ */ new Map();
503
+ const pending = new Set(entries.keys());
504
+ while (pending.size > 0) {
505
+ let progressed = false;
506
+ for (const offset of pending) {
507
+ const entry = entries.get(offset);
508
+ let object;
509
+ if (entry.kind === "whole") object = entry;
510
+ else {
511
+ const base = entry.kind === "offset" ? resolved.get(entry.base) : objects.get(entry.base);
512
+ if (base !== void 0)
513
+ object = { type: base.type, data: applyDelta(base.data, entry.delta) };
514
+ }
515
+ if (object === void 0) continue;
516
+ resolved.set(offset, object);
517
+ objects.set(await objectId(object.type, object.data), object);
518
+ pending.delete(offset);
519
+ progressed = true;
520
+ }
521
+ if (!progressed) throw new GitProtocolError("unresolved delta base");
522
+ }
523
+ return objects;
524
+ };
525
+ var parseTreeFetch = async (bytes, commit, path, limits) => {
526
+ const objects = await unpack(packfile(bytes), limits);
527
+ const head = objects.get(commit);
528
+ if (head?.type !== "commit") throw new GitProtocolError("missing commit");
529
+ const root = /^tree ([a-f0-9]{40})$/m.exec(decoder.decode(head.data))?.[1];
530
+ if (root === void 0) throw new GitProtocolError("commit without tree");
531
+ const entries = (tree) => {
532
+ const object = objects.get(tree);
533
+ if (object?.type !== "tree") throw new GitProtocolError("missing tree");
534
+ const result = [];
535
+ for (let at = 0; at < object.data.byteLength; ) {
536
+ const space = object.data.indexOf(32, at);
537
+ const nul = object.data.indexOf(0, space);
538
+ if (space < 0 || nul < 0 || nul + 21 > object.data.byteLength)
539
+ throw new GitProtocolError("invalid tree entry");
540
+ result.push({
541
+ mode: decoder.decode(object.data.subarray(at, space)).padStart(6, "0"),
542
+ name: decoder.decode(object.data.subarray(space + 1, nul)),
543
+ id: hex(object.data.subarray(nul + 1, nul + 21))
544
+ });
545
+ at = nul + 21;
546
+ }
547
+ return result;
548
+ };
549
+ let start = root;
550
+ const prefix = path === void 0 ? [] : path.split("/");
551
+ for (const name of prefix) {
552
+ const next = entries(start).find((entry) => entry.name === name && entry.mode === "040000");
553
+ if (next === void 0) return [];
554
+ start = next.id;
555
+ }
556
+ const files = [];
557
+ const walk = (tree, directory) => {
558
+ for (const entry of entries(tree)) {
559
+ const entryPath = `${directory}${entry.name}`;
560
+ if (entry.mode === "040000") walk(entry.id, `${entryPath}/`);
561
+ else if (entry.mode !== "160000") {
562
+ files.push({ path: entryPath, mode: entry.mode });
563
+ }
564
+ }
565
+ };
566
+ walk(start, prefix.length === 0 ? "" : `${prefix.join("/")}/`);
567
+ return files;
568
+ };
569
+
570
+ // src/implementation/skills.ts
571
+ var failed = (reason) => new SkillLoadFailed({ reason });
572
+ var rejected = (status, headers) => new SkillLoadFailed({
573
+ reason: httpProviderError(status, headers)?.reason === "rate_limited" ? "rate_limited" : "request",
574
+ status
575
+ });
576
+ var describe = (service, { reason, status }) => {
577
+ switch (reason) {
578
+ case "rate_limited":
579
+ return `${service} is rate limiting skill requests (HTTP ${status}).`;
580
+ case "request":
581
+ return status === void 0 ? `Could not reach ${service} to load skills.` : `${service} returned HTTP ${status} while loading skills.`;
582
+ case "source":
583
+ return `The ${service} skill source settings are not valid.`;
584
+ case "document":
585
+ return `A skill from ${service} is not a valid skill document.`;
586
+ case "limit":
587
+ return `The skills from ${service} exceed Executor\u2019s file or size limits.`;
588
+ case "changed":
589
+ return `The skills on ${service} changed while they were being read.`;
590
+ case "encoding":
591
+ return `A skill file from ${service} is not valid UTF-8 text.`;
592
+ }
593
+ };
594
+ var withService = (service) => (effect) => service === void 0 || !Schema_exports.is(SkillServiceName)(service) ? effect : effect.pipe(
595
+ Effect_exports.mapError(
596
+ (error) => !error.message ? new SkillLoadFailed({
597
+ reason: error.reason,
598
+ message: describe(service, error),
599
+ ...error.status === void 0 ? {} : { status: error.status }
600
+ }) : error
601
+ )
602
+ );
603
+ var parse = (schema, input) => Schema_exports.decodeUnknownEffect(schema)(input).pipe(Effect_exports.mapError(() => failed("document")));
604
+ var resourcePath = (path) => {
605
+ if (!Schema_exports.is(SkillFilePath)(path)) return false;
606
+ try {
607
+ return path.split("/").every((part) => {
608
+ const decoded = decodeURIComponent(part);
609
+ return decoded !== "." && decoded !== ".." && !/[\\/]/.test(decoded) && !decoded.includes("\0");
610
+ });
611
+ } catch {
612
+ return false;
613
+ }
614
+ };
615
+ var pathUrl = (base, path) => new URL(path.split("/").map(encodeURIComponent).join("/"), base).href;
616
+ var reader = (transport) => Effect_exports.gen(function* () {
617
+ const budget = yield* Ref_exports.make(0);
618
+ const fetchBytes = (url, post) => Effect_exports.gen(function* () {
619
+ const parsed = yield* Effect_exports.try({
620
+ try: () => new URL(url),
621
+ catch: () => failed("source")
622
+ });
623
+ if (!["https:", "http:"].includes(parsed.protocol) || parsed.username || parsed.password || parsed.hash)
624
+ return yield* failed("source");
625
+ const client = HttpClient_exports.withScope(yield* HttpClient_exports.HttpClient);
626
+ const headers = {
627
+ "User-Agent": "executor-skills",
628
+ Accept: "application/json, text/plain",
629
+ "Cache-Control": "no-cache"
630
+ };
631
+ const response = yield* (post === void 0 ? client.get(parsed, { headers }) : client.post(parsed, {
632
+ headers: { ...headers, ...post.headers },
633
+ body: HttpBody_exports.uint8Array(post.body, post.headers["Content-Type"])
634
+ })).pipe(Effect_exports.mapError(() => failed("request")));
635
+ if (response.status < 200 || response.status >= 300)
636
+ return yield* rejected(response.status, response.headers);
637
+ const chunks = [];
638
+ let size = 0;
639
+ yield* response.stream.pipe(
640
+ Stream_exports.mapError(() => failed("request")),
641
+ Stream_exports.runForEach(
642
+ (chunk) => Effect_exports.gen(function* () {
643
+ size += chunk.byteLength;
644
+ const total = yield* Ref_exports.updateAndGet(budget, (total2) => total2 + chunk.byteLength);
645
+ if (size > skillLoadLimits.fileBytes || total > skillLoadLimits.totalBytes)
646
+ return yield* failed("limit");
647
+ chunks.push(chunk);
648
+ })
649
+ )
650
+ );
651
+ const result = new Uint8Array(size);
652
+ let offset = 0;
653
+ for (const chunk of chunks) {
654
+ result.set(chunk, offset);
655
+ offset += chunk.byteLength;
656
+ }
657
+ return result;
658
+ }).pipe(
659
+ Effect_exports.scoped,
660
+ Effect_exports.provide(FetchHttpClient_exports.layer),
661
+ Effect_exports.provideService(FetchHttpClient_exports.RequestInit, { redirect: "manual" }),
662
+ Effect_exports.provideService(FetchHttpClient_exports.Fetch, transport.fetch ?? globalThis.fetch)
663
+ );
664
+ const read = (url) => fetchBytes(url).pipe(
665
+ Effect_exports.flatMap(
666
+ (result) => Effect_exports.try({
667
+ try: () => new TextDecoder("utf-8", { fatal: true }).decode(result),
668
+ catch: () => failed("encoding")
669
+ })
670
+ )
671
+ );
672
+ const json = (url) => read(url).pipe(Effect_exports.flatMap((text) => parse(Schema_exports.fromJsonString(Schema_exports.Unknown), text)));
673
+ return { fetchBytes, read, json };
674
+ });
675
+ var unreadable = () => new SkillLoadFailed({
676
+ reason: "request",
677
+ message: "GitHub returned a git response Executor could not read."
678
+ });
679
+ var git = (run) => Effect_exports.tryPromise({
680
+ try: async () => run(),
681
+ catch: (error) => error instanceof InflateLimitExceeded ? failed("limit") : unreadable()
682
+ });
683
+ var resolveCommit = (remote, repo, ref) => Effect_exports.gen(function* () {
684
+ if (ref !== void 0 && /^[a-f0-9]{40}$/.test(ref)) return ref;
685
+ const names = refCandidates(ref);
686
+ const response = yield* remote.fetchBytes(`https://github.com/${repo}.git/git-upload-pack`, {
687
+ body: lsRefsRequest(names),
688
+ headers: gitRequestHeaders
689
+ }).pipe(
690
+ // GitHub asks for credentials when a repository is missing or private.
691
+ Effect_exports.mapError(
692
+ (error) => error.status === 401 || error.status === 404 ? new SkillLoadFailed({
693
+ reason: "source",
694
+ message: `GitHub has no public repository named ${repo}.`,
695
+ status: error.status
696
+ }) : error
697
+ )
698
+ );
699
+ const refs = yield* git(() => parseLsRefs(response));
700
+ const commit = names.map((name) => refs.get(name)).find((sha) => sha !== void 0);
701
+ if (commit === void 0)
702
+ return yield* new SkillLoadFailed({
703
+ reason: "source",
704
+ message: `GitHub repository ${repo} has no branch or tag named ${ref}.`
705
+ });
706
+ return commit;
707
+ });
708
+ var listFiles = (remote, repo, commit, path) => remote.fetchBytes(`https://github.com/${repo}.git/git-upload-pack`, {
709
+ body: treeFetchRequest(commit),
710
+ headers: gitRequestHeaders
711
+ }).pipe(
712
+ Effect_exports.flatMap(
713
+ (response) => git(
714
+ () => parseTreeFetch(response, commit, path, { objectBytes: skillLoadLimits.fileBytes })
715
+ )
716
+ )
717
+ );
718
+ var SkillDirectories = Schema_exports.Array(
719
+ Schema_exports.Struct({
720
+ directory: Schema_exports.String,
721
+ files: Schema_exports.Array(Schema_exports.Struct({ path: Schema_exports.String, mode: Schema_exports.String }))
722
+ })
723
+ );
724
+ var skillDirectories = (remote, repo, commit, path) => Effect_exports.gen(function* () {
725
+ const files = yield* listFiles(remote, repo, commit, path);
726
+ const documents = files.filter(
727
+ (file) => file.path === "SKILL.md" || file.path.endsWith("/SKILL.md")
728
+ );
729
+ const directories = documents.map((document) => {
730
+ const directory = document.path.slice(0, -"SKILL.md".length);
731
+ return { directory, files: files.filter((file) => file.path.startsWith(directory)) };
732
+ });
733
+ if (directories.reduce((count, item) => count + item.files.length, 0) > skillLoadLimits.files)
734
+ return yield* failed("limit");
735
+ return directories;
736
+ });
737
+ var cachedSkillDirectories = (cache, transport, repo, commit, path) => Effect_exports.tryPromise({
738
+ try: () => cache.get({
739
+ key: ["apps/githubSkills/directories", 1, repo, commit, path ?? null],
740
+ schema: wrap(SkillDirectories, false),
741
+ freshFor: "7 days",
742
+ load: (context) => Effect_exports.runPromise(
743
+ // Keep the author's fetch, as every other read in this load does.
744
+ reader({ fetch: transport.fetch, signal: context.signal }).pipe(
745
+ Effect_exports.flatMap((remote) => skillDirectories(remote, repo, commit, path))
746
+ ),
747
+ { signal: context.signal }
748
+ )
749
+ }),
750
+ catch: (error) => Schema_exports.is(SkillLoadFailed)(error) ? error : new SkillLoadFailed({
751
+ reason: "request",
752
+ message: "Executor could not read or update the app cache for skills."
753
+ })
754
+ });
755
+ var cachedCatalog = (options, prefix, load) => options.cache === void 0 ? load(options, void 0) : catalogCache({
756
+ cache: options.cache,
757
+ ...options.freshFor === void 0 ? {} : { freshFor: options.freshFor },
758
+ ...options.staleFor === void 0 ? {} : { staleFor: options.staleFor },
759
+ prefix,
760
+ schema: AppSkillSource,
761
+ summary: { schema: AppSkillMetadata, of: ({ files: _files, ...metadata }) => metadata },
762
+ load: (context) => context === void 0 ? load(options, options.cache) : load({ fetch: options.fetch, signal: context.signal }, context.cache)
763
+ }).pipe(
764
+ Effect_exports.flatMap((catalog) => catalog.list()),
765
+ Effect_exports.mapError(
766
+ (error) => Schema_exports.is(SkillLoadFailed)(error) ? error : new SkillLoadFailed({
767
+ reason: "request",
768
+ message: "Executor could not read or update the app cache for skills."
769
+ })
770
+ )
771
+ );
772
+ var githubSkillsEffect = (options) => Effect_exports.gen(function* () {
773
+ if (!/^[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+$/.test(options.repo) || options.path !== void 0 && !resourcePath(options.path))
774
+ return yield* failed("source");
775
+ return yield* cachedCatalog(
776
+ options,
777
+ ["apps/githubSkills/catalog", 1, options.repo, options.ref ?? null, options.path ?? null],
778
+ (transport, cache) => githubCatalog(options, transport, cache)
779
+ );
780
+ }).pipe(withService("GitHub"));
781
+ var githubCatalog = (options, transport, cache) => Effect_exports.gen(function* () {
782
+ const remote = yield* reader(transport);
783
+ const commit = yield* resolveCommit(remote, options.repo, options.ref);
784
+ const resources = yield* cache === void 0 ? skillDirectories(remote, options.repo, commit, options.path) : cachedSkillDirectories(cache, transport, options.repo, commit, options.path);
785
+ const base = `https://raw.githubusercontent.com/${options.repo}/${commit}/`;
786
+ const skills = yield* Effect_exports.forEach(
787
+ resources,
788
+ ({ directory, files }) => Effect_exports.gen(function* () {
789
+ const sources = yield* Effect_exports.forEach(
790
+ files,
791
+ (file) => Effect_exports.gen(function* () {
792
+ const path = file.path.slice(directory.length);
793
+ if (!resourcePath(file.path) || !resourcePath(path) || file.mode === "120000")
794
+ return yield* failed("source");
795
+ return { path, content: yield* remote.read(pathUrl(base, file.path)) };
796
+ }),
797
+ { concurrency: skillLoadLimits.concurrency }
798
+ );
799
+ const name = directory.slice(0, -1).split("/").at(-1);
800
+ return yield* skillFromFiles(
801
+ sources,
802
+ directory === "" || name === void 0 ? {} : { name }
803
+ ).pipe(Effect_exports.mapError(() => failed("document")));
804
+ }),
805
+ { concurrency: 1 }
806
+ );
807
+ return yield* parse(AppSkills, skills);
808
+ });
809
+ var Index = Schema_exports.Struct({
810
+ skills: Schema_exports.Array(
811
+ Schema_exports.Struct({
812
+ name: AppSkillMetadata.fields.name,
813
+ version: Schema_exports.optionalKey(Schema_exports.String),
814
+ files: Schema_exports.Array(Schema_exports.String)
815
+ })
816
+ )
817
+ });
818
+ var wellKnownSkillsEffect = (options) => Effect_exports.gen(function* () {
819
+ const url = yield* Effect_exports.try({
820
+ try: () => new URL(options.url),
821
+ catch: () => failed("source")
822
+ });
823
+ if (url.pathname === "/") url.pathname = "/.well-known/agent-skills/index.json";
824
+ else if (!url.pathname.endsWith("index.json"))
825
+ url.pathname = `${url.pathname.replace(/\/$/, "")}/index.json`;
826
+ return yield* cachedCatalog(
827
+ options,
828
+ ["apps/wellKnownSkills/catalog", 1, url.href],
829
+ (transport) => wellKnownCatalog(url, transport)
830
+ );
831
+ }).pipe(withService(URL.canParse(options.url) ? new URL(options.url).hostname : void 0));
832
+ var wellKnownCatalog = (url, transport) => Effect_exports.gen(function* () {
833
+ const remote = yield* reader(transport);
834
+ const first = yield* remote.read(url.href);
835
+ const index = yield* parse(Schema_exports.fromJsonString(Index), first);
836
+ if (index.skills.reduce((count, skill) => count + skill.files.length, 0) > skillLoadLimits.files)
837
+ return yield* failed("limit");
838
+ const skills = yield* Effect_exports.forEach(
839
+ index.skills,
840
+ (entry) => Effect_exports.gen(function* () {
841
+ const base = new URL(`${encodeURIComponent(entry.name)}/`, url).href;
842
+ const files = yield* Effect_exports.forEach(
843
+ entry.files,
844
+ (path) => Effect_exports.gen(function* () {
845
+ if (!resourcePath(path)) return yield* failed("source");
846
+ return { path, content: yield* remote.read(pathUrl(base, path)) };
847
+ }),
848
+ { concurrency: skillLoadLimits.concurrency }
849
+ );
850
+ return yield* skillFromFiles(files, { name: entry.name }).pipe(
851
+ Effect_exports.mapError(() => failed("document"))
852
+ );
853
+ }),
854
+ { concurrency: 1 }
855
+ );
856
+ if ((yield* remote.read(url.href)) !== first) return yield* failed("changed");
857
+ return yield* parse(AppSkills, skills);
858
+ });
859
+
860
+ // src/skills.ts
861
+ var githubSkills = (options) => Effect_exports.runPromise(
862
+ githubSkillsEffect(options),
863
+ options.signal === void 0 ? {} : { signal: options.signal }
864
+ );
865
+ var wellKnownSkills = (options) => Effect_exports.runPromise(
866
+ wellKnownSkillsEffect(options),
867
+ options.signal === void 0 ? {} : { signal: options.signal }
868
+ );
869
+ var fileSkill = (files) => Effect_exports.runPromise(skillFromFiles(files));
870
+ var folderSkills = (options) => Effect_exports.runPromise(folderSkillsEffect(options));
871
+ var skillReader = (options) => {
872
+ const service = Schema_exports.decodeUnknownSync(SkillServiceName)(options.service);
873
+ const remote = Effect_exports.runSync(reader(options));
874
+ const run = (effect) => Effect_exports.runPromise(
875
+ effect.pipe(withService(service)),
876
+ options.signal === void 0 ? {} : { signal: options.signal }
877
+ );
878
+ return {
879
+ /** Fetch one UTF-8 text file. */
880
+ text: (url) => run(remote.read(url)),
881
+ /** Fetch and parse one JSON document. */
882
+ json: (url) => run(remote.json(url))
883
+ };
884
+ };
885
+ export {
886
+ SkillDefinitionInvalid,
887
+ SkillLoadFailed,
888
+ SkillServiceName,
889
+ fileSkill,
890
+ folderSkills,
891
+ githubSkills,
892
+ skillReader,
893
+ wellKnownSkills
894
+ };