@copilotkit/runtime 1.72.1-canary.sp-longthread-perf → 1.73.1

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 (206) hide show
  1. package/dist/agent/index.cjs +49 -9
  2. package/dist/agent/index.cjs.map +1 -1
  3. package/dist/agent/index.d.cts +20 -7
  4. package/dist/agent/index.d.cts.map +1 -1
  5. package/dist/agent/index.d.mts +19 -6
  6. package/dist/agent/index.d.mts.map +1 -1
  7. package/dist/agent/index.mjs +49 -9
  8. package/dist/agent/index.mjs.map +1 -1
  9. package/dist/agent/learned-skills.cjs +77 -0
  10. package/dist/agent/learned-skills.cjs.map +1 -0
  11. package/dist/agent/learned-skills.d.cts +16 -0
  12. package/dist/agent/learned-skills.d.cts.map +1 -0
  13. package/dist/agent/learned-skills.d.mts +16 -0
  14. package/dist/agent/learned-skills.d.mts.map +1 -0
  15. package/dist/agent/learned-skills.mjs +75 -0
  16. package/dist/agent/learned-skills.mjs.map +1 -0
  17. package/dist/index.d.cts +4 -4
  18. package/dist/index.d.mts +4 -4
  19. package/dist/internal/learned-skills.cjs +22 -0
  20. package/dist/internal/learned-skills.d.cts +10 -0
  21. package/dist/internal/learned-skills.d.mts +10 -0
  22. package/dist/internal/learned-skills.mjs +10 -0
  23. package/dist/lib/index.d.cts +2 -2
  24. package/dist/lib/index.d.mts +2 -2
  25. package/dist/lib/integrations/nextjs/app-router.cjs +1 -1
  26. package/dist/lib/integrations/nextjs/app-router.cjs.map +1 -1
  27. package/dist/lib/integrations/nextjs/app-router.mjs +1 -1
  28. package/dist/lib/integrations/nextjs/app-router.mjs.map +1 -1
  29. package/dist/lib/integrations/node-http/index.cjs +1 -1
  30. package/dist/lib/integrations/node-http/index.cjs.map +1 -1
  31. package/dist/lib/integrations/node-http/index.d.cts.map +1 -1
  32. package/dist/lib/integrations/node-http/index.d.mts.map +1 -1
  33. package/dist/lib/integrations/node-http/index.mjs +1 -1
  34. package/dist/lib/integrations/node-http/index.mjs.map +1 -1
  35. package/dist/lib/integrations/shared.cjs.map +1 -1
  36. package/dist/lib/integrations/shared.d.cts +1 -1
  37. package/dist/lib/integrations/shared.d.cts.map +1 -1
  38. package/dist/lib/integrations/shared.d.mts +1 -1
  39. package/dist/lib/integrations/shared.d.mts.map +1 -1
  40. package/dist/lib/integrations/shared.mjs.map +1 -1
  41. package/dist/lib/runtime/agent-integrations/langgraph/agent.d.cts +1 -1
  42. package/dist/lib/runtime/copilot-runtime.cjs +79 -37
  43. package/dist/lib/runtime/copilot-runtime.cjs.map +1 -1
  44. package/dist/lib/runtime/copilot-runtime.d.cts +54 -4
  45. package/dist/lib/runtime/copilot-runtime.d.cts.map +1 -1
  46. package/dist/lib/runtime/copilot-runtime.d.mts +56 -6
  47. package/dist/lib/runtime/copilot-runtime.d.mts.map +1 -1
  48. package/dist/lib/runtime/copilot-runtime.mjs +79 -37
  49. package/dist/lib/runtime/copilot-runtime.mjs.map +1 -1
  50. package/dist/lib/runtime/mcp-client-cache.cjs +135 -0
  51. package/dist/lib/runtime/mcp-client-cache.cjs.map +1 -0
  52. package/dist/lib/runtime/mcp-client-cache.mjs +132 -0
  53. package/dist/lib/runtime/mcp-client-cache.mjs.map +1 -0
  54. package/dist/lib/runtime/telemetry-agent-runner.cjs.map +1 -1
  55. package/dist/lib/runtime/telemetry-agent-runner.d.cts +1 -1
  56. package/dist/lib/runtime/telemetry-agent-runner.d.mts +1 -1
  57. package/dist/lib/runtime/telemetry-agent-runner.mjs.map +1 -1
  58. package/dist/package.cjs +15 -7
  59. package/dist/package.mjs +15 -7
  60. package/dist/service-adapters/anthropic/anthropic-adapter.cjs.map +1 -1
  61. package/dist/service-adapters/anthropic/anthropic-adapter.d.cts.map +1 -1
  62. package/dist/service-adapters/anthropic/anthropic-adapter.d.mts.map +1 -1
  63. package/dist/service-adapters/anthropic/anthropic-adapter.mjs.map +1 -1
  64. package/dist/service-adapters/shared/sdk-client-utils.cjs.map +1 -1
  65. package/dist/service-adapters/shared/sdk-client-utils.d.cts.map +1 -1
  66. package/dist/service-adapters/shared/sdk-client-utils.d.mts.map +1 -1
  67. package/dist/service-adapters/shared/sdk-client-utils.mjs.map +1 -1
  68. package/dist/v2/index.cjs +9 -3
  69. package/dist/v2/index.d.cts +12 -11
  70. package/dist/v2/index.d.mts +12 -11
  71. package/dist/v2/index.mjs +5 -5
  72. package/dist/v2/runtime/core/channel-manager.cjs +1 -1
  73. package/dist/v2/runtime/core/channel-manager.d.cts +1 -1
  74. package/dist/v2/runtime/core/channel-manager.d.mts +1 -1
  75. package/dist/v2/runtime/core/channel-manager.mjs +1 -1
  76. package/dist/v2/runtime/core/fetch-handler.cjs +1 -0
  77. package/dist/v2/runtime/core/fetch-handler.cjs.map +1 -1
  78. package/dist/v2/runtime/core/fetch-handler.d.cts +2 -2
  79. package/dist/v2/runtime/core/fetch-handler.d.mts +2 -2
  80. package/dist/v2/runtime/core/fetch-handler.mjs +1 -0
  81. package/dist/v2/runtime/core/fetch-handler.mjs.map +1 -1
  82. package/dist/v2/runtime/core/runtime.cjs +5 -0
  83. package/dist/v2/runtime/core/runtime.cjs.map +1 -1
  84. package/dist/v2/runtime/core/runtime.d.cts +18 -3
  85. package/dist/v2/runtime/core/runtime.d.cts.map +1 -1
  86. package/dist/v2/runtime/core/runtime.d.mts +17 -2
  87. package/dist/v2/runtime/core/runtime.d.mts.map +1 -1
  88. package/dist/v2/runtime/core/runtime.mjs +5 -0
  89. package/dist/v2/runtime/core/runtime.mjs.map +1 -1
  90. package/dist/v2/runtime/endpoints/express-single.cjs.map +1 -1
  91. package/dist/v2/runtime/endpoints/express-single.d.cts +2 -2
  92. package/dist/v2/runtime/endpoints/express-single.d.cts.map +1 -1
  93. package/dist/v2/runtime/endpoints/express-single.d.mts +2 -2
  94. package/dist/v2/runtime/endpoints/express-single.d.mts.map +1 -1
  95. package/dist/v2/runtime/endpoints/express-single.mjs.map +1 -1
  96. package/dist/v2/runtime/endpoints/express.cjs +2 -3
  97. package/dist/v2/runtime/endpoints/express.cjs.map +1 -1
  98. package/dist/v2/runtime/endpoints/express.d.cts +26 -7
  99. package/dist/v2/runtime/endpoints/express.d.cts.map +1 -1
  100. package/dist/v2/runtime/endpoints/express.d.mts +26 -7
  101. package/dist/v2/runtime/endpoints/express.d.mts.map +1 -1
  102. package/dist/v2/runtime/endpoints/express.mjs +2 -2
  103. package/dist/v2/runtime/endpoints/express.mjs.map +1 -1
  104. package/dist/v2/runtime/endpoints/hono.d.cts +2 -2
  105. package/dist/v2/runtime/endpoints/hono.d.mts +2 -2
  106. package/dist/v2/runtime/endpoints/index.d.cts +3 -3
  107. package/dist/v2/runtime/endpoints/index.d.mts +3 -3
  108. package/dist/v2/runtime/endpoints/load-express.cjs +36 -0
  109. package/dist/v2/runtime/endpoints/load-express.cjs.map +1 -0
  110. package/dist/v2/runtime/endpoints/load-express.mjs +35 -0
  111. package/dist/v2/runtime/endpoints/load-express.mjs.map +1 -0
  112. package/dist/v2/runtime/handlers/handle-stop.cjs +18 -14
  113. package/dist/v2/runtime/handlers/handle-stop.cjs.map +1 -1
  114. package/dist/v2/runtime/handlers/handle-stop.mjs +18 -14
  115. package/dist/v2/runtime/handlers/handle-stop.mjs.map +1 -1
  116. package/dist/v2/runtime/handlers/handle-suggest.cjs +4 -3
  117. package/dist/v2/runtime/handlers/handle-suggest.cjs.map +1 -1
  118. package/dist/v2/runtime/handlers/handle-suggest.mjs +5 -4
  119. package/dist/v2/runtime/handlers/handle-suggest.mjs.map +1 -1
  120. package/dist/v2/runtime/handlers/shared/agent-utils.cjs +3 -4
  121. package/dist/v2/runtime/handlers/shared/agent-utils.cjs.map +1 -1
  122. package/dist/v2/runtime/handlers/shared/agent-utils.mjs +1 -2
  123. package/dist/v2/runtime/handlers/shared/agent-utils.mjs.map +1 -1
  124. package/dist/v2/runtime/handlers/shared/sse-keep-alive.cjs +69 -0
  125. package/dist/v2/runtime/handlers/shared/sse-keep-alive.cjs.map +1 -0
  126. package/dist/v2/runtime/handlers/shared/sse-keep-alive.mjs +67 -0
  127. package/dist/v2/runtime/handlers/shared/sse-keep-alive.mjs.map +1 -0
  128. package/dist/v2/runtime/handlers/shared/sse-response.cjs +5 -2
  129. package/dist/v2/runtime/handlers/shared/sse-response.cjs.map +1 -1
  130. package/dist/v2/runtime/handlers/shared/sse-response.mjs +5 -2
  131. package/dist/v2/runtime/handlers/shared/sse-response.mjs.map +1 -1
  132. package/dist/v2/runtime/handlers/sse/connect.cjs +1 -0
  133. package/dist/v2/runtime/handlers/sse/connect.cjs.map +1 -1
  134. package/dist/v2/runtime/handlers/sse/connect.mjs +1 -0
  135. package/dist/v2/runtime/handlers/sse/connect.mjs.map +1 -1
  136. package/dist/v2/runtime/handlers/sse/run.cjs +1 -0
  137. package/dist/v2/runtime/handlers/sse/run.cjs.map +1 -1
  138. package/dist/v2/runtime/handlers/sse/run.mjs +1 -0
  139. package/dist/v2/runtime/handlers/sse/run.mjs.map +1 -1
  140. package/dist/v2/runtime/index.d.cts +9 -9
  141. package/dist/v2/runtime/index.d.mts +9 -9
  142. package/dist/v2/runtime/intelligence-platform/client.cjs +1 -1
  143. package/dist/v2/runtime/intelligence-platform/client.d.cts +1 -1
  144. package/dist/v2/runtime/intelligence-platform/client.d.mts +1 -1
  145. package/dist/v2/runtime/intelligence-platform/client.mjs +1 -1
  146. package/dist/v2/runtime/intelligence-platform/skill-registry/archive.cjs +132 -0
  147. package/dist/v2/runtime/intelligence-platform/skill-registry/archive.cjs.map +1 -0
  148. package/dist/v2/runtime/intelligence-platform/skill-registry/archive.d.cts +11 -0
  149. package/dist/v2/runtime/intelligence-platform/skill-registry/archive.d.cts.map +1 -0
  150. package/dist/v2/runtime/intelligence-platform/skill-registry/archive.d.mts +11 -0
  151. package/dist/v2/runtime/intelligence-platform/skill-registry/archive.d.mts.map +1 -0
  152. package/dist/v2/runtime/intelligence-platform/skill-registry/archive.mjs +128 -0
  153. package/dist/v2/runtime/intelligence-platform/skill-registry/archive.mjs.map +1 -0
  154. package/dist/v2/runtime/intelligence-platform/skill-registry/config.cjs +48 -0
  155. package/dist/v2/runtime/intelligence-platform/skill-registry/config.cjs.map +1 -0
  156. package/dist/v2/runtime/intelligence-platform/skill-registry/config.d.cts +27 -0
  157. package/dist/v2/runtime/intelligence-platform/skill-registry/config.d.cts.map +1 -0
  158. package/dist/v2/runtime/intelligence-platform/skill-registry/config.d.mts +27 -0
  159. package/dist/v2/runtime/intelligence-platform/skill-registry/config.d.mts.map +1 -0
  160. package/dist/v2/runtime/intelligence-platform/skill-registry/config.mjs +48 -0
  161. package/dist/v2/runtime/intelligence-platform/skill-registry/config.mjs.map +1 -0
  162. package/dist/v2/runtime/intelligence-platform/skill-registry/errors.cjs +11 -0
  163. package/dist/v2/runtime/intelligence-platform/skill-registry/errors.cjs.map +1 -0
  164. package/dist/v2/runtime/intelligence-platform/skill-registry/errors.d.cts +8 -0
  165. package/dist/v2/runtime/intelligence-platform/skill-registry/errors.d.cts.map +1 -0
  166. package/dist/v2/runtime/intelligence-platform/skill-registry/errors.d.mts +8 -0
  167. package/dist/v2/runtime/intelligence-platform/skill-registry/errors.d.mts.map +1 -0
  168. package/dist/v2/runtime/intelligence-platform/skill-registry/errors.mjs +11 -0
  169. package/dist/v2/runtime/intelligence-platform/skill-registry/errors.mjs.map +1 -0
  170. package/dist/v2/runtime/intelligence-platform/skill-registry/index.d.cts +8 -0
  171. package/dist/v2/runtime/intelligence-platform/skill-registry/index.d.mts +8 -0
  172. package/dist/v2/runtime/intelligence-platform/skill-registry/registry.cjs +132 -0
  173. package/dist/v2/runtime/intelligence-platform/skill-registry/registry.cjs.map +1 -0
  174. package/dist/v2/runtime/intelligence-platform/skill-registry/registry.d.cts +31 -0
  175. package/dist/v2/runtime/intelligence-platform/skill-registry/registry.d.cts.map +1 -0
  176. package/dist/v2/runtime/intelligence-platform/skill-registry/registry.d.mts +31 -0
  177. package/dist/v2/runtime/intelligence-platform/skill-registry/registry.d.mts.map +1 -0
  178. package/dist/v2/runtime/intelligence-platform/skill-registry/registry.mjs +132 -0
  179. package/dist/v2/runtime/intelligence-platform/skill-registry/registry.mjs.map +1 -0
  180. package/dist/v2/runtime/intelligence-platform/skill-registry/skill-content.cjs +42 -0
  181. package/dist/v2/runtime/intelligence-platform/skill-registry/skill-content.cjs.map +1 -0
  182. package/dist/v2/runtime/intelligence-platform/skill-registry/skill-content.d.cts +13 -0
  183. package/dist/v2/runtime/intelligence-platform/skill-registry/skill-content.d.cts.map +1 -0
  184. package/dist/v2/runtime/intelligence-platform/skill-registry/skill-content.d.mts +13 -0
  185. package/dist/v2/runtime/intelligence-platform/skill-registry/skill-content.d.mts.map +1 -0
  186. package/dist/v2/runtime/intelligence-platform/skill-registry/skill-content.mjs +39 -0
  187. package/dist/v2/runtime/intelligence-platform/skill-registry/skill-content.mjs.map +1 -0
  188. package/dist/v2/runtime/intelligence-platform/skill-registry/snapshot.cjs +93 -0
  189. package/dist/v2/runtime/intelligence-platform/skill-registry/snapshot.cjs.map +1 -0
  190. package/dist/v2/runtime/intelligence-platform/skill-registry/snapshot.d.cts +28 -0
  191. package/dist/v2/runtime/intelligence-platform/skill-registry/snapshot.d.cts.map +1 -0
  192. package/dist/v2/runtime/intelligence-platform/skill-registry/snapshot.d.mts +28 -0
  193. package/dist/v2/runtime/intelligence-platform/skill-registry/snapshot.d.mts.map +1 -0
  194. package/dist/v2/runtime/intelligence-platform/skill-registry/snapshot.mjs +92 -0
  195. package/dist/v2/runtime/intelligence-platform/skill-registry/snapshot.mjs.map +1 -0
  196. package/dist/v2/runtime/runner/agent-runner.d.cts +1 -1
  197. package/dist/v2/runtime/runner/in-memory.d.cts +1 -1
  198. package/dist/v2/runtime/runner/index.d.cts +2 -2
  199. package/dist/v2/runtime/runner/index.d.mts +2 -2
  200. package/dist/v2/runtime/runner/index.mjs +2 -2
  201. package/dist/v2/runtime/runner/intelligence.d.cts +1 -1
  202. package/package.json +17 -7
  203. package/dist/v2/runtime/open-generative-ui-middleware.cjs +0 -286
  204. package/dist/v2/runtime/open-generative-ui-middleware.cjs.map +0 -1
  205. package/dist/v2/runtime/open-generative-ui-middleware.mjs +0 -284
  206. package/dist/v2/runtime/open-generative-ui-middleware.mjs.map +0 -1
@@ -0,0 +1,11 @@
1
+
2
+ //#region src/v2/runtime/intelligence-platform/skill-registry/archive.d.ts
3
+ /** Internal corruption bounds, including manifest and directory entries. */
4
+ declare const MAX_ARCHIVE_ENTRIES = 1000;
5
+ declare const MAX_SNAPSHOT_BYTES: number;
6
+ declare function safeRelativePath(path: string): boolean;
7
+ /** Decode only the listed ZIP namespace. No filesystem is involved. */
8
+ declare function readArchive(bytes: Buffer, signal?: AbortSignal): Promise<Map<string, Buffer>>;
9
+ //#endregion
10
+ export { MAX_ARCHIVE_ENTRIES, MAX_SNAPSHOT_BYTES, readArchive, safeRelativePath };
11
+ //# sourceMappingURL=archive.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"archive.d.cts","names":[],"sources":["../../../../../src/v2/runtime/intelligence-platform/skill-registry/archive.ts"],"mappings":";;;cAMa,mBAAA;AAAA,cACA,kBAAA;AAAA,iBAEG,gBAAA,CAAiB,IAAA;;iBAcjB,WAAA,CACd,KAAA,EAAO,MAAA,EACP,MAAA,GAAS,WAAA,GACR,OAAA,CAAQ,GAAA,SAAY,MAAA"}
@@ -0,0 +1,11 @@
1
+
2
+ //#region src/v2/runtime/intelligence-platform/skill-registry/archive.d.ts
3
+ /** Internal corruption bounds, including manifest and directory entries. */
4
+ declare const MAX_ARCHIVE_ENTRIES = 1000;
5
+ declare const MAX_SNAPSHOT_BYTES: number;
6
+ declare function safeRelativePath(path: string): boolean;
7
+ /** Decode only the listed ZIP namespace. No filesystem is involved. */
8
+ declare function readArchive(bytes: Buffer, signal?: AbortSignal): Promise<Map<string, Buffer>>;
9
+ //#endregion
10
+ export { MAX_ARCHIVE_ENTRIES, MAX_SNAPSHOT_BYTES, readArchive, safeRelativePath };
11
+ //# sourceMappingURL=archive.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"archive.d.mts","names":[],"sources":["../../../../../src/v2/runtime/intelligence-platform/skill-registry/archive.ts"],"mappings":";;;cAMa,mBAAA;AAAA,cACA,kBAAA;AAAA,iBAEG,gBAAA,CAAiB,IAAA;;iBAcjB,WAAA,CACd,KAAA,EAAO,MAAA,EACP,MAAA,GAAS,WAAA,GACR,OAAA,CAAQ,GAAA,SAAY,MAAA"}
@@ -0,0 +1,128 @@
1
+ import "reflect-metadata";
2
+ import { invalidSnapshot } from "./errors.mjs";
3
+ import { fromBuffer } from "yauzl";
4
+
5
+ //#region src/v2/runtime/intelligence-platform/skill-registry/archive.ts
6
+ /** Internal corruption bounds, including manifest and directory entries. */
7
+ const MAX_ARCHIVE_ENTRIES = 1e3;
8
+ const MAX_SNAPSHOT_BYTES = 32 * 1024 * 1024;
9
+ function safeRelativePath(path) {
10
+ return path.length > 0 && !/[\\\x00-\x1f\x7f]/.test(path) && !/^[a-z]:/i.test(path) && path.split("/").every((part) => part !== "" && part !== "." && part !== "..");
11
+ }
12
+ /** Decode only the listed ZIP namespace. No filesystem is involved. */
13
+ function readArchive(bytes, signal) {
14
+ return new Promise((resolve, reject) => {
15
+ let archive;
16
+ let stream;
17
+ let settled = false;
18
+ const finish = (error) => {
19
+ if (settled) return;
20
+ settled = true;
21
+ signal?.removeEventListener("abort", abort);
22
+ stream?.destroy();
23
+ archive?.close();
24
+ if (error !== void 0) reject(error);
25
+ else resolve(files);
26
+ };
27
+ const abort = () => finish(signal?.reason ?? invalidSnapshot());
28
+ const files = /* @__PURE__ */ new Map();
29
+ const names = /* @__PURE__ */ new Set();
30
+ let decodedBytes = 0;
31
+ signal?.addEventListener("abort", abort, { once: true });
32
+ if (signal?.aborted) {
33
+ abort();
34
+ return;
35
+ }
36
+ fromBuffer(bytes, {
37
+ lazyEntries: true,
38
+ decodeStrings: false,
39
+ validateEntrySizes: true,
40
+ autoClose: false
41
+ }, (error, zip) => {
42
+ if (error) {
43
+ finish(invalidSnapshot(error));
44
+ return;
45
+ }
46
+ archive = zip;
47
+ if (settled) {
48
+ zip.close();
49
+ return;
50
+ }
51
+ zip.on("error", (cause) => finish(invalidSnapshot(cause)));
52
+ zip.on("end", () => finish());
53
+ if (zip.entryCount > MAX_ARCHIVE_ENTRIES) {
54
+ finish(invalidSnapshot());
55
+ return;
56
+ }
57
+ zip.on("entry", (entry) => {
58
+ try {
59
+ const rawName = entry.fileName;
60
+ if (!Buffer.isBuffer(rawName)) throw invalidSnapshot();
61
+ const name = new TextDecoder("utf-8", {
62
+ fatal: true,
63
+ ignoreBOM: true
64
+ }).decode(rawName);
65
+ const directory = name.endsWith("/");
66
+ if (!safeRelativePath(directory ? name.slice(0, -1) : name) || names.has(name)) throw invalidSnapshot();
67
+ names.add(name);
68
+ const fileType = entry.externalFileAttributes >>> 16 & 61440;
69
+ if (fileType !== 0 && fileType !== (directory ? 16384 : 32768)) throw invalidSnapshot();
70
+ if (entry.isEncrypted() || ![0, 8].includes(entry.compressionMethod)) throw invalidSnapshot();
71
+ if (!Number.isSafeInteger(entry.uncompressedSize) || entry.uncompressedSize < 0) throw invalidSnapshot();
72
+ decodedBytes += entry.uncompressedSize;
73
+ if (decodedBytes > MAX_SNAPSHOT_BYTES || directory && entry.uncompressedSize !== 0) throw invalidSnapshot();
74
+ const local = entry.relativeOffsetOfLocalHeader;
75
+ if (local < 0 || local + 30 > bytes.length || bytes.readUInt32LE(local) !== 67324752) throw invalidSnapshot();
76
+ if (bytes.readUInt16LE(local + 6) !== entry.generalPurposeBitFlag || bytes.readUInt16LE(local + 8) !== entry.compressionMethod) throw invalidSnapshot();
77
+ const localNameLength = bytes.readUInt16LE(local + 26);
78
+ const localExtraLength = bytes.readUInt16LE(local + 28);
79
+ if (local + 30 + localNameLength + localExtraLength + entry.compressedSize > bytes.length || !bytes.subarray(local + 30, local + 30 + localNameLength).equals(rawName)) throw invalidSnapshot();
80
+ if (!(entry.generalPurposeBitFlag & 8) && (bytes.readUInt32LE(local + 18) !== entry.compressedSize || bytes.readUInt32LE(local + 22) !== entry.uncompressedSize)) throw invalidSnapshot();
81
+ if (directory) {
82
+ zip.readEntry();
83
+ return;
84
+ }
85
+ zip.openReadStream(entry, (readError, readStream) => {
86
+ if (readError) {
87
+ finish(invalidSnapshot(readError));
88
+ return;
89
+ }
90
+ stream = readStream;
91
+ if (settled) {
92
+ readStream.destroy();
93
+ return;
94
+ }
95
+ const chunks = [];
96
+ let size = 0;
97
+ readStream.on("error", (cause) => finish(invalidSnapshot(cause)));
98
+ readStream.on("data", (chunk) => {
99
+ size += chunk.length;
100
+ if (size > entry.uncompressedSize || size > MAX_SNAPSHOT_BYTES) {
101
+ finish(invalidSnapshot());
102
+ return;
103
+ }
104
+ chunks.push(chunk);
105
+ });
106
+ readStream.on("end", () => {
107
+ if (settled) return;
108
+ if (size !== entry.uncompressedSize) {
109
+ finish(invalidSnapshot());
110
+ return;
111
+ }
112
+ files.set(name, Buffer.concat(chunks, size));
113
+ stream = void 0;
114
+ zip.readEntry();
115
+ });
116
+ });
117
+ } catch (cause) {
118
+ finish(invalidSnapshot(cause));
119
+ }
120
+ });
121
+ zip.readEntry();
122
+ });
123
+ });
124
+ }
125
+
126
+ //#endregion
127
+ export { MAX_ARCHIVE_ENTRIES, MAX_SNAPSHOT_BYTES, readArchive, safeRelativePath };
128
+ //# sourceMappingURL=archive.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"archive.mjs","names":[],"sources":["../../../../../src/v2/runtime/intelligence-platform/skill-registry/archive.ts"],"sourcesContent":["import { fromBuffer } from \"yauzl\";\nimport type { Entry, ZipFile } from \"yauzl\";\nimport type { Readable } from \"node:stream\";\nimport { invalidSnapshot } from \"./errors\";\n\n/** Internal corruption bounds, including manifest and directory entries. */\nexport const MAX_ARCHIVE_ENTRIES = 1_000;\nexport const MAX_SNAPSHOT_BYTES = 32 * 1024 * 1024;\n\nexport function safeRelativePath(path: string): boolean {\n return (\n path.length > 0 &&\n // Reject control bytes in archive paths, including NUL and DEL.\n // eslint-disable-next-line no-control-regex\n !/[\\\\\\x00-\\x1f\\x7f]/.test(path) &&\n !/^[a-z]:/i.test(path) &&\n path\n .split(\"/\")\n .every((part) => part !== \"\" && part !== \".\" && part !== \"..\")\n );\n}\n\n/** Decode only the listed ZIP namespace. No filesystem is involved. */\nexport function readArchive(\n bytes: Buffer,\n signal?: AbortSignal,\n): Promise<Map<string, Buffer>> {\n return new Promise((resolve, reject) => {\n let archive: ZipFile | undefined;\n let stream: Readable | undefined;\n let settled = false;\n const finish = (error?: unknown) => {\n if (settled) return;\n settled = true;\n signal?.removeEventListener(\"abort\", abort);\n stream?.destroy();\n archive?.close();\n if (error !== undefined) reject(error);\n else resolve(files);\n };\n const abort = () => finish(signal?.reason ?? invalidSnapshot());\n const files = new Map<string, Buffer>();\n const names = new Set<string>();\n let decodedBytes = 0;\n signal?.addEventListener(\"abort\", abort, { once: true });\n if (signal?.aborted) {\n abort();\n return;\n }\n fromBuffer(\n bytes,\n {\n lazyEntries: true,\n decodeStrings: false,\n validateEntrySizes: true,\n autoClose: false,\n },\n (error, zip) => {\n if (error) {\n finish(invalidSnapshot(error));\n return;\n }\n archive = zip;\n if (settled) {\n zip.close();\n return;\n }\n zip.on(\"error\", (cause: unknown) => finish(invalidSnapshot(cause)));\n zip.on(\"end\", () => finish());\n if (zip.entryCount > MAX_ARCHIVE_ENTRIES) {\n finish(invalidSnapshot());\n return;\n }\n zip.on(\"entry\", (entry: Entry) => {\n try {\n // decodeStrings:false preserves raw UTF-8 names instead of normalizing\n // backslashes or consulting alternate Unicode-path extra fields.\n const rawName: unknown = entry.fileName;\n if (!Buffer.isBuffer(rawName)) throw invalidSnapshot();\n const name = new TextDecoder(\"utf-8\", {\n fatal: true,\n ignoreBOM: true,\n }).decode(rawName);\n const directory = name.endsWith(\"/\");\n if (\n !safeRelativePath(directory ? name.slice(0, -1) : name) ||\n names.has(name)\n )\n throw invalidSnapshot();\n names.add(name);\n const fileType = (entry.externalFileAttributes >>> 16) & 0o170000;\n if (\n fileType !== 0 &&\n fileType !== (directory ? 0o040000 : 0o100000)\n )\n throw invalidSnapshot();\n if (\n entry.isEncrypted() ||\n ![0, 8].includes(entry.compressionMethod)\n )\n throw invalidSnapshot();\n if (\n !Number.isSafeInteger(entry.uncompressedSize) ||\n entry.uncompressedSize < 0\n )\n throw invalidSnapshot();\n decodedBytes += entry.uncompressedSize;\n if (\n decodedBytes > MAX_SNAPSHOT_BYTES ||\n (directory && entry.uncompressedSize !== 0)\n )\n throw invalidSnapshot();\n // Require the central directory and the local entry to name the same\n // bytes. ZIP data descriptors may leave local sizes unset.\n const local = entry.relativeOffsetOfLocalHeader;\n if (\n local < 0 ||\n local + 30 > bytes.length ||\n bytes.readUInt32LE(local) !== 0x04034b50\n )\n throw invalidSnapshot();\n if (\n bytes.readUInt16LE(local + 6) !== entry.generalPurposeBitFlag ||\n bytes.readUInt16LE(local + 8) !== entry.compressionMethod\n )\n throw invalidSnapshot();\n const localNameLength = bytes.readUInt16LE(local + 26);\n const localExtraLength = bytes.readUInt16LE(local + 28);\n const dataStart = local + 30 + localNameLength + localExtraLength;\n if (\n dataStart + entry.compressedSize > bytes.length ||\n !bytes\n .subarray(local + 30, local + 30 + localNameLength)\n .equals(rawName)\n )\n throw invalidSnapshot();\n if (\n !(entry.generalPurposeBitFlag & 8) &&\n (bytes.readUInt32LE(local + 18) !== entry.compressedSize ||\n bytes.readUInt32LE(local + 22) !== entry.uncompressedSize)\n )\n throw invalidSnapshot();\n if (directory) {\n zip.readEntry();\n return;\n }\n zip.openReadStream(entry, (readError, readStream) => {\n if (readError) {\n finish(invalidSnapshot(readError));\n return;\n }\n stream = readStream;\n if (settled) {\n readStream.destroy();\n return;\n }\n const chunks: Buffer[] = [];\n let size = 0;\n readStream.on(\"error\", (cause: unknown) =>\n finish(invalidSnapshot(cause)),\n );\n readStream.on(\"data\", (chunk: Buffer) => {\n size += chunk.length;\n if (\n size > entry.uncompressedSize ||\n size > MAX_SNAPSHOT_BYTES\n ) {\n finish(invalidSnapshot());\n return;\n }\n chunks.push(chunk);\n });\n readStream.on(\"end\", () => {\n if (settled) return;\n if (size !== entry.uncompressedSize) {\n finish(invalidSnapshot());\n return;\n }\n files.set(name, Buffer.concat(chunks, size));\n stream = undefined;\n zip.readEntry();\n });\n });\n } catch (cause) {\n finish(invalidSnapshot(cause));\n }\n });\n zip.readEntry();\n },\n );\n });\n}\n"],"mappings":"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"}
@@ -0,0 +1,48 @@
1
+ require("reflect-metadata");
2
+ const require_learned_skills = require('../learned-skills.cjs');
3
+ const require_client = require('../client.cjs');
4
+
5
+ //#region src/v2/runtime/intelligence-platform/skill-registry/config.ts
6
+ /** Resolve once. Never retain the options object, environment, or a second key. */
7
+ function resolveRegistryConfig(options = {}, environment = process.env) {
8
+ try {
9
+ const containerId = options.containerId ?? environment.CPK_INTELLIGENCE_LEARNING_CONTAINER_ID;
10
+ const revision = options.revision ?? environment.CPK_INTELLIGENCE_SKILLS_REVISION;
11
+ const freshnessWindowMs = options.freshnessWindowMs ?? 5e3;
12
+ const requestTimeoutMs = options.requestTimeoutMs ?? 5e3;
13
+ const debug = options.debug ?? false;
14
+ if (typeof containerId !== "string" || !containerId.trim() || revision !== void 0 && (typeof revision !== "string" || revision.length === 0) || !Number.isSafeInteger(freshnessWindowMs) || freshnessWindowMs < 0 || !Number.isSafeInteger(requestTimeoutMs) || requestTimeoutMs < 1 || requestTimeoutMs > 2147483647 || typeof debug !== "boolean") throw new require_learned_skills.LearnedSkillsError("INVALID_CONFIG", false);
15
+ let client = options.client;
16
+ if (client !== void 0) {
17
+ if (!client || typeof client.getLearnedSkillsSnapshot !== "function") throw new require_learned_skills.LearnedSkillsError("INVALID_CONFIG", false);
18
+ } else {
19
+ const apiKey = options.apiKey ?? environment.CPK_INTELLIGENCE_API_KEY;
20
+ const apiUrl = options.apiUrl ?? environment.INTELLIGENCE_API_URL;
21
+ if (typeof apiKey !== "string" || !apiKey.trim()) throw new require_learned_skills.LearnedSkillsError("INVALID_CONFIG", false);
22
+ if (apiUrl?.trim()) {
23
+ const url = new URL(apiUrl);
24
+ if (!["http:", "https:"].includes(url.protocol) || url.username || url.password || url.search || url.hash) throw new require_learned_skills.LearnedSkillsError("INVALID_CONFIG", false);
25
+ }
26
+ client = new require_client.CopilotKitIntelligence({
27
+ apiKey,
28
+ ...apiUrl !== void 0 ? { apiUrl } : {},
29
+ ...apiUrl?.trim() ? { wsUrl: "wss://realtime.intelligence.copilotkit.ai" } : {}
30
+ });
31
+ }
32
+ return Object.freeze({
33
+ client,
34
+ containerId,
35
+ ...revision !== void 0 ? { revision } : {},
36
+ freshnessWindowMs,
37
+ requestTimeoutMs,
38
+ debug
39
+ });
40
+ } catch (error) {
41
+ if (error instanceof require_learned_skills.LearnedSkillsError) throw error;
42
+ throw new require_learned_skills.LearnedSkillsError("INVALID_CONFIG", false, error);
43
+ }
44
+ }
45
+
46
+ //#endregion
47
+ exports.resolveRegistryConfig = resolveRegistryConfig;
48
+ //# sourceMappingURL=config.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.cjs","names":["SkillDeliveryError","CopilotKitIntelligence"],"sources":["../../../../../src/v2/runtime/intelligence-platform/skill-registry/config.ts"],"sourcesContent":["import { CopilotKitIntelligence } from \"../client\";\nimport { SkillDeliveryError } from \"./errors\";\n\nexport interface SkillRegistryOptions {\n client?: CopilotKitIntelligence;\n apiKey?: string;\n apiUrl?: string;\n containerId?: string;\n revision?: string;\n freshnessWindowMs?: number;\n requestTimeoutMs?: number;\n debug?: boolean;\n}\nexport interface RegistryConfig {\n readonly client: CopilotKitIntelligence;\n readonly containerId: string;\n readonly revision?: string;\n readonly freshnessWindowMs: number;\n readonly requestTimeoutMs: number;\n readonly debug: boolean;\n}\n\n/** Resolve once. Never retain the options object, environment, or a second key. */\nexport function resolveRegistryConfig(\n options: SkillRegistryOptions = {},\n environment: NodeJS.ProcessEnv = process.env,\n): RegistryConfig {\n try {\n const containerId =\n options.containerId ?? environment.CPK_INTELLIGENCE_LEARNING_CONTAINER_ID;\n const revision =\n options.revision ?? environment.CPK_INTELLIGENCE_SKILLS_REVISION;\n const freshnessWindowMs = options.freshnessWindowMs ?? 5_000;\n const requestTimeoutMs = options.requestTimeoutMs ?? 5_000;\n const debug = options.debug ?? false;\n if (\n typeof containerId !== \"string\" ||\n !containerId.trim() ||\n (revision !== undefined &&\n (typeof revision !== \"string\" || revision.length === 0)) ||\n !Number.isSafeInteger(freshnessWindowMs) ||\n freshnessWindowMs < 0 ||\n !Number.isSafeInteger(requestTimeoutMs) ||\n requestTimeoutMs < 1 ||\n requestTimeoutMs > 2_147_483_647 ||\n typeof debug !== \"boolean\"\n )\n throw new SkillDeliveryError(\"INVALID_CONFIG\", false);\n let client = options.client;\n if (client !== undefined) {\n if (!client || typeof client.getLearnedSkillsSnapshot !== \"function\")\n throw new SkillDeliveryError(\"INVALID_CONFIG\", false);\n } else {\n const apiKey = options.apiKey ?? environment.CPK_INTELLIGENCE_API_KEY;\n const apiUrl = options.apiUrl ?? environment.INTELLIGENCE_API_URL;\n if (typeof apiKey !== \"string\" || !apiKey.trim())\n throw new SkillDeliveryError(\"INVALID_CONFIG\", false);\n if (apiUrl?.trim()) {\n const url = new URL(apiUrl);\n if (\n ![\"http:\", \"https:\"].includes(url.protocol) ||\n url.username ||\n url.password ||\n url.search ||\n url.hash\n )\n throw new SkillDeliveryError(\"INVALID_CONFIG\", false);\n }\n client = new CopilotKitIntelligence({\n apiKey,\n ...(apiUrl !== undefined ? { apiUrl } : {}),\n // This private helper client uses REST only. Explicitly retain the\n // canonical websocket default to prevent an irrelevant host warning.\n ...(apiUrl?.trim()\n ? { wsUrl: \"wss://realtime.intelligence.copilotkit.ai\" }\n : {}),\n });\n }\n return Object.freeze({\n client,\n containerId,\n ...(revision !== undefined ? { revision } : {}),\n freshnessWindowMs,\n requestTimeoutMs,\n debug,\n });\n } catch (error) {\n if (error instanceof SkillDeliveryError) throw error;\n throw new SkillDeliveryError(\"INVALID_CONFIG\", false, error);\n }\n}\n"],"mappings":";;;;;;AAuBA,SAAgB,sBACd,UAAgC,EAAE,EAClC,cAAiC,QAAQ,KACzB;AAChB,KAAI;EACF,MAAM,cACJ,QAAQ,eAAe,YAAY;EACrC,MAAM,WACJ,QAAQ,YAAY,YAAY;EAClC,MAAM,oBAAoB,QAAQ,qBAAqB;EACvD,MAAM,mBAAmB,QAAQ,oBAAoB;EACrD,MAAM,QAAQ,QAAQ,SAAS;AAC/B,MACE,OAAO,gBAAgB,YACvB,CAAC,YAAY,MAAM,IAClB,aAAa,WACX,OAAO,aAAa,YAAY,SAAS,WAAW,MACvD,CAAC,OAAO,cAAc,kBAAkB,IACxC,oBAAoB,KACpB,CAAC,OAAO,cAAc,iBAAiB,IACvC,mBAAmB,KACnB,mBAAmB,cACnB,OAAO,UAAU,UAEjB,OAAM,IAAIA,0CAAmB,kBAAkB,MAAM;EACvD,IAAI,SAAS,QAAQ;AACrB,MAAI,WAAW,QACb;OAAI,CAAC,UAAU,OAAO,OAAO,6BAA6B,WACxD,OAAM,IAAIA,0CAAmB,kBAAkB,MAAM;SAClD;GACL,MAAM,SAAS,QAAQ,UAAU,YAAY;GAC7C,MAAM,SAAS,QAAQ,UAAU,YAAY;AAC7C,OAAI,OAAO,WAAW,YAAY,CAAC,OAAO,MAAM,CAC9C,OAAM,IAAIA,0CAAmB,kBAAkB,MAAM;AACvD,OAAI,QAAQ,MAAM,EAAE;IAClB,MAAM,MAAM,IAAI,IAAI,OAAO;AAC3B,QACE,CAAC,CAAC,SAAS,SAAS,CAAC,SAAS,IAAI,SAAS,IAC3C,IAAI,YACJ,IAAI,YACJ,IAAI,UACJ,IAAI,KAEJ,OAAM,IAAIA,0CAAmB,kBAAkB,MAAM;;AAEzD,YAAS,IAAIC,sCAAuB;IAClC;IACA,GAAI,WAAW,SAAY,EAAE,QAAQ,GAAG,EAAE;IAG1C,GAAI,QAAQ,MAAM,GACd,EAAE,OAAO,6CAA6C,GACtD,EAAE;IACP,CAAC;;AAEJ,SAAO,OAAO,OAAO;GACnB;GACA;GACA,GAAI,aAAa,SAAY,EAAE,UAAU,GAAG,EAAE;GAC9C;GACA;GACA;GACD,CAAC;UACK,OAAO;AACd,MAAI,iBAAiBD,0CAAoB,OAAM;AAC/C,QAAM,IAAIA,0CAAmB,kBAAkB,OAAO,MAAM"}
@@ -0,0 +1,27 @@
1
+
2
+ import { CopilotKitIntelligence } from "../client.cjs";
3
+
4
+ //#region src/v2/runtime/intelligence-platform/skill-registry/config.d.ts
5
+ interface SkillRegistryOptions {
6
+ client?: CopilotKitIntelligence;
7
+ apiKey?: string;
8
+ apiUrl?: string;
9
+ containerId?: string;
10
+ revision?: string;
11
+ freshnessWindowMs?: number;
12
+ requestTimeoutMs?: number;
13
+ debug?: boolean;
14
+ }
15
+ interface RegistryConfig {
16
+ readonly client: CopilotKitIntelligence;
17
+ readonly containerId: string;
18
+ readonly revision?: string;
19
+ readonly freshnessWindowMs: number;
20
+ readonly requestTimeoutMs: number;
21
+ readonly debug: boolean;
22
+ }
23
+ /** Resolve once. Never retain the options object, environment, or a second key. */
24
+ declare function resolveRegistryConfig(options?: SkillRegistryOptions, environment?: NodeJS.ProcessEnv): RegistryConfig;
25
+ //#endregion
26
+ export { RegistryConfig, SkillRegistryOptions, resolveRegistryConfig };
27
+ //# sourceMappingURL=config.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.cts","names":[],"sources":["../../../../../src/v2/runtime/intelligence-platform/skill-registry/config.ts"],"mappings":";;;;UAGiB,oBAAA;EACf,MAAA,GAAS,sBAAA;EACT,MAAA;EACA,MAAA;EACA,WAAA;EACA,QAAA;EACA,iBAAA;EACA,gBAAA;EACA,KAAA;AAAA;AAAA,UAEe,cAAA;EAAA,SACN,MAAA,EAAQ,sBAAA;EAAA,SACR,WAAA;EAAA,SACA,QAAA;EAAA,SACA,iBAAA;EAAA,SACA,gBAAA;EAAA,SACA,KAAA;AAAA;;iBAIK,qBAAA,CACd,OAAA,GAAS,oBAAA,EACT,WAAA,GAAa,MAAA,CAAO,UAAA,GACnB,cAAA"}
@@ -0,0 +1,27 @@
1
+
2
+ import { CopilotKitIntelligence } from "../client.mjs";
3
+
4
+ //#region src/v2/runtime/intelligence-platform/skill-registry/config.d.ts
5
+ interface SkillRegistryOptions {
6
+ client?: CopilotKitIntelligence;
7
+ apiKey?: string;
8
+ apiUrl?: string;
9
+ containerId?: string;
10
+ revision?: string;
11
+ freshnessWindowMs?: number;
12
+ requestTimeoutMs?: number;
13
+ debug?: boolean;
14
+ }
15
+ interface RegistryConfig {
16
+ readonly client: CopilotKitIntelligence;
17
+ readonly containerId: string;
18
+ readonly revision?: string;
19
+ readonly freshnessWindowMs: number;
20
+ readonly requestTimeoutMs: number;
21
+ readonly debug: boolean;
22
+ }
23
+ /** Resolve once. Never retain the options object, environment, or a second key. */
24
+ declare function resolveRegistryConfig(options?: SkillRegistryOptions, environment?: NodeJS.ProcessEnv): RegistryConfig;
25
+ //#endregion
26
+ export { RegistryConfig, SkillRegistryOptions, resolveRegistryConfig };
27
+ //# sourceMappingURL=config.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.mts","names":[],"sources":["../../../../../src/v2/runtime/intelligence-platform/skill-registry/config.ts"],"mappings":";;;;UAGiB,oBAAA;EACf,MAAA,GAAS,sBAAA;EACT,MAAA;EACA,MAAA;EACA,WAAA;EACA,QAAA;EACA,iBAAA;EACA,gBAAA;EACA,KAAA;AAAA;AAAA,UAEe,cAAA;EAAA,SACN,MAAA,EAAQ,sBAAA;EAAA,SACR,WAAA;EAAA,SACA,QAAA;EAAA,SACA,iBAAA;EAAA,SACA,gBAAA;EAAA,SACA,KAAA;AAAA;;iBAIK,qBAAA,CACd,OAAA,GAAS,oBAAA,EACT,WAAA,GAAa,MAAA,CAAO,UAAA,GACnB,cAAA"}
@@ -0,0 +1,48 @@
1
+ import "reflect-metadata";
2
+ import { LearnedSkillsError } from "../learned-skills.mjs";
3
+ import { CopilotKitIntelligence } from "../client.mjs";
4
+
5
+ //#region src/v2/runtime/intelligence-platform/skill-registry/config.ts
6
+ /** Resolve once. Never retain the options object, environment, or a second key. */
7
+ function resolveRegistryConfig(options = {}, environment = process.env) {
8
+ try {
9
+ const containerId = options.containerId ?? environment.CPK_INTELLIGENCE_LEARNING_CONTAINER_ID;
10
+ const revision = options.revision ?? environment.CPK_INTELLIGENCE_SKILLS_REVISION;
11
+ const freshnessWindowMs = options.freshnessWindowMs ?? 5e3;
12
+ const requestTimeoutMs = options.requestTimeoutMs ?? 5e3;
13
+ const debug = options.debug ?? false;
14
+ if (typeof containerId !== "string" || !containerId.trim() || revision !== void 0 && (typeof revision !== "string" || revision.length === 0) || !Number.isSafeInteger(freshnessWindowMs) || freshnessWindowMs < 0 || !Number.isSafeInteger(requestTimeoutMs) || requestTimeoutMs < 1 || requestTimeoutMs > 2147483647 || typeof debug !== "boolean") throw new LearnedSkillsError("INVALID_CONFIG", false);
15
+ let client = options.client;
16
+ if (client !== void 0) {
17
+ if (!client || typeof client.getLearnedSkillsSnapshot !== "function") throw new LearnedSkillsError("INVALID_CONFIG", false);
18
+ } else {
19
+ const apiKey = options.apiKey ?? environment.CPK_INTELLIGENCE_API_KEY;
20
+ const apiUrl = options.apiUrl ?? environment.INTELLIGENCE_API_URL;
21
+ if (typeof apiKey !== "string" || !apiKey.trim()) throw new LearnedSkillsError("INVALID_CONFIG", false);
22
+ if (apiUrl?.trim()) {
23
+ const url = new URL(apiUrl);
24
+ if (!["http:", "https:"].includes(url.protocol) || url.username || url.password || url.search || url.hash) throw new LearnedSkillsError("INVALID_CONFIG", false);
25
+ }
26
+ client = new CopilotKitIntelligence({
27
+ apiKey,
28
+ ...apiUrl !== void 0 ? { apiUrl } : {},
29
+ ...apiUrl?.trim() ? { wsUrl: "wss://realtime.intelligence.copilotkit.ai" } : {}
30
+ });
31
+ }
32
+ return Object.freeze({
33
+ client,
34
+ containerId,
35
+ ...revision !== void 0 ? { revision } : {},
36
+ freshnessWindowMs,
37
+ requestTimeoutMs,
38
+ debug
39
+ });
40
+ } catch (error) {
41
+ if (error instanceof LearnedSkillsError) throw error;
42
+ throw new LearnedSkillsError("INVALID_CONFIG", false, error);
43
+ }
44
+ }
45
+
46
+ //#endregion
47
+ export { resolveRegistryConfig };
48
+ //# sourceMappingURL=config.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.mjs","names":["SkillDeliveryError"],"sources":["../../../../../src/v2/runtime/intelligence-platform/skill-registry/config.ts"],"sourcesContent":["import { CopilotKitIntelligence } from \"../client\";\nimport { SkillDeliveryError } from \"./errors\";\n\nexport interface SkillRegistryOptions {\n client?: CopilotKitIntelligence;\n apiKey?: string;\n apiUrl?: string;\n containerId?: string;\n revision?: string;\n freshnessWindowMs?: number;\n requestTimeoutMs?: number;\n debug?: boolean;\n}\nexport interface RegistryConfig {\n readonly client: CopilotKitIntelligence;\n readonly containerId: string;\n readonly revision?: string;\n readonly freshnessWindowMs: number;\n readonly requestTimeoutMs: number;\n readonly debug: boolean;\n}\n\n/** Resolve once. Never retain the options object, environment, or a second key. */\nexport function resolveRegistryConfig(\n options: SkillRegistryOptions = {},\n environment: NodeJS.ProcessEnv = process.env,\n): RegistryConfig {\n try {\n const containerId =\n options.containerId ?? environment.CPK_INTELLIGENCE_LEARNING_CONTAINER_ID;\n const revision =\n options.revision ?? environment.CPK_INTELLIGENCE_SKILLS_REVISION;\n const freshnessWindowMs = options.freshnessWindowMs ?? 5_000;\n const requestTimeoutMs = options.requestTimeoutMs ?? 5_000;\n const debug = options.debug ?? false;\n if (\n typeof containerId !== \"string\" ||\n !containerId.trim() ||\n (revision !== undefined &&\n (typeof revision !== \"string\" || revision.length === 0)) ||\n !Number.isSafeInteger(freshnessWindowMs) ||\n freshnessWindowMs < 0 ||\n !Number.isSafeInteger(requestTimeoutMs) ||\n requestTimeoutMs < 1 ||\n requestTimeoutMs > 2_147_483_647 ||\n typeof debug !== \"boolean\"\n )\n throw new SkillDeliveryError(\"INVALID_CONFIG\", false);\n let client = options.client;\n if (client !== undefined) {\n if (!client || typeof client.getLearnedSkillsSnapshot !== \"function\")\n throw new SkillDeliveryError(\"INVALID_CONFIG\", false);\n } else {\n const apiKey = options.apiKey ?? environment.CPK_INTELLIGENCE_API_KEY;\n const apiUrl = options.apiUrl ?? environment.INTELLIGENCE_API_URL;\n if (typeof apiKey !== \"string\" || !apiKey.trim())\n throw new SkillDeliveryError(\"INVALID_CONFIG\", false);\n if (apiUrl?.trim()) {\n const url = new URL(apiUrl);\n if (\n ![\"http:\", \"https:\"].includes(url.protocol) ||\n url.username ||\n url.password ||\n url.search ||\n url.hash\n )\n throw new SkillDeliveryError(\"INVALID_CONFIG\", false);\n }\n client = new CopilotKitIntelligence({\n apiKey,\n ...(apiUrl !== undefined ? { apiUrl } : {}),\n // This private helper client uses REST only. Explicitly retain the\n // canonical websocket default to prevent an irrelevant host warning.\n ...(apiUrl?.trim()\n ? { wsUrl: \"wss://realtime.intelligence.copilotkit.ai\" }\n : {}),\n });\n }\n return Object.freeze({\n client,\n containerId,\n ...(revision !== undefined ? { revision } : {}),\n freshnessWindowMs,\n requestTimeoutMs,\n debug,\n });\n } catch (error) {\n if (error instanceof SkillDeliveryError) throw error;\n throw new SkillDeliveryError(\"INVALID_CONFIG\", false, error);\n }\n}\n"],"mappings":";;;;;;AAuBA,SAAgB,sBACd,UAAgC,EAAE,EAClC,cAAiC,QAAQ,KACzB;AAChB,KAAI;EACF,MAAM,cACJ,QAAQ,eAAe,YAAY;EACrC,MAAM,WACJ,QAAQ,YAAY,YAAY;EAClC,MAAM,oBAAoB,QAAQ,qBAAqB;EACvD,MAAM,mBAAmB,QAAQ,oBAAoB;EACrD,MAAM,QAAQ,QAAQ,SAAS;AAC/B,MACE,OAAO,gBAAgB,YACvB,CAAC,YAAY,MAAM,IAClB,aAAa,WACX,OAAO,aAAa,YAAY,SAAS,WAAW,MACvD,CAAC,OAAO,cAAc,kBAAkB,IACxC,oBAAoB,KACpB,CAAC,OAAO,cAAc,iBAAiB,IACvC,mBAAmB,KACnB,mBAAmB,cACnB,OAAO,UAAU,UAEjB,OAAM,IAAIA,mBAAmB,kBAAkB,MAAM;EACvD,IAAI,SAAS,QAAQ;AACrB,MAAI,WAAW,QACb;OAAI,CAAC,UAAU,OAAO,OAAO,6BAA6B,WACxD,OAAM,IAAIA,mBAAmB,kBAAkB,MAAM;SAClD;GACL,MAAM,SAAS,QAAQ,UAAU,YAAY;GAC7C,MAAM,SAAS,QAAQ,UAAU,YAAY;AAC7C,OAAI,OAAO,WAAW,YAAY,CAAC,OAAO,MAAM,CAC9C,OAAM,IAAIA,mBAAmB,kBAAkB,MAAM;AACvD,OAAI,QAAQ,MAAM,EAAE;IAClB,MAAM,MAAM,IAAI,IAAI,OAAO;AAC3B,QACE,CAAC,CAAC,SAAS,SAAS,CAAC,SAAS,IAAI,SAAS,IAC3C,IAAI,YACJ,IAAI,YACJ,IAAI,UACJ,IAAI,KAEJ,OAAM,IAAIA,mBAAmB,kBAAkB,MAAM;;AAEzD,YAAS,IAAI,uBAAuB;IAClC;IACA,GAAI,WAAW,SAAY,EAAE,QAAQ,GAAG,EAAE;IAG1C,GAAI,QAAQ,MAAM,GACd,EAAE,OAAO,6CAA6C,GACtD,EAAE;IACP,CAAC;;AAEJ,SAAO,OAAO,OAAO;GACnB;GACA;GACA,GAAI,aAAa,SAAY,EAAE,UAAU,GAAG,EAAE;GAC9C;GACA;GACA;GACD,CAAC;UACK,OAAO;AACd,MAAI,iBAAiBA,mBAAoB,OAAM;AAC/C,QAAM,IAAIA,mBAAmB,kBAAkB,OAAO,MAAM"}
@@ -0,0 +1,11 @@
1
+ require("reflect-metadata");
2
+ const require_learned_skills = require('../learned-skills.cjs');
3
+
4
+ //#region src/v2/runtime/intelligence-platform/skill-registry/errors.ts
5
+ function invalidSnapshot(cause) {
6
+ return new require_learned_skills.LearnedSkillsError("INVALID_SNAPSHOT", false, cause);
7
+ }
8
+
9
+ //#endregion
10
+ exports.invalidSnapshot = invalidSnapshot;
11
+ //# sourceMappingURL=errors.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.cjs","names":["LearnedSkillsError"],"sources":["../../../../../src/v2/runtime/intelligence-platform/skill-registry/errors.ts"],"sourcesContent":["import { LearnedSkillsError } from \"../learned-skills\";\n\n// Reuse the canonical delivery error identity across transport and adapter code.\nexport { LearnedSkillsError as SkillDeliveryError } from \"../learned-skills\";\nexport type { LearnedSkillsErrorCode as SkillDeliveryErrorCode } from \"../learned-skills\";\n\nexport function invalidSnapshot(cause?: unknown): LearnedSkillsError {\n return new LearnedSkillsError(\"INVALID_SNAPSHOT\", false, cause);\n}\n"],"mappings":";;;;AAMA,SAAgB,gBAAgB,OAAqC;AACnE,QAAO,IAAIA,0CAAmB,oBAAoB,OAAO,MAAM"}
@@ -0,0 +1,8 @@
1
+
2
+ import { LearnedSkillsError, LearnedSkillsErrorCode } from "../learned-skills.cjs";
3
+
4
+ //#region src/v2/runtime/intelligence-platform/skill-registry/errors.d.ts
5
+ declare function invalidSnapshot(cause?: unknown): LearnedSkillsError;
6
+ //#endregion
7
+ export { invalidSnapshot };
8
+ //# sourceMappingURL=errors.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.cts","names":[],"sources":["../../../../../src/v2/runtime/intelligence-platform/skill-registry/errors.ts"],"mappings":";;;;iBAMgB,eAAA,CAAgB,KAAA,aAAkB,kBAAA"}
@@ -0,0 +1,8 @@
1
+
2
+ import { LearnedSkillsError, LearnedSkillsErrorCode } from "../learned-skills.mjs";
3
+
4
+ //#region src/v2/runtime/intelligence-platform/skill-registry/errors.d.ts
5
+ declare function invalidSnapshot(cause?: unknown): LearnedSkillsError;
6
+ //#endregion
7
+ export { invalidSnapshot };
8
+ //# sourceMappingURL=errors.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.mts","names":[],"sources":["../../../../../src/v2/runtime/intelligence-platform/skill-registry/errors.ts"],"mappings":";;;;iBAMgB,eAAA,CAAgB,KAAA,aAAkB,kBAAA"}
@@ -0,0 +1,11 @@
1
+ import "reflect-metadata";
2
+ import { LearnedSkillsError } from "../learned-skills.mjs";
3
+
4
+ //#region src/v2/runtime/intelligence-platform/skill-registry/errors.ts
5
+ function invalidSnapshot(cause) {
6
+ return new LearnedSkillsError("INVALID_SNAPSHOT", false, cause);
7
+ }
8
+
9
+ //#endregion
10
+ export { invalidSnapshot };
11
+ //# sourceMappingURL=errors.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.mjs","names":[],"sources":["../../../../../src/v2/runtime/intelligence-platform/skill-registry/errors.ts"],"sourcesContent":["import { LearnedSkillsError } from \"../learned-skills\";\n\n// Reuse the canonical delivery error identity across transport and adapter code.\nexport { LearnedSkillsError as SkillDeliveryError } from \"../learned-skills\";\nexport type { LearnedSkillsErrorCode as SkillDeliveryErrorCode } from \"../learned-skills\";\n\nexport function invalidSnapshot(cause?: unknown): LearnedSkillsError {\n return new LearnedSkillsError(\"INVALID_SNAPSHOT\", false, cause);\n}\n"],"mappings":";;;;AAMA,SAAgB,gBAAgB,OAAqC;AACnE,QAAO,IAAI,mBAAmB,oBAAoB,OAAO,MAAM"}
@@ -0,0 +1,8 @@
1
+
2
+ import { MAX_ARCHIVE_ENTRIES, MAX_SNAPSHOT_BYTES, readArchive, safeRelativePath } from "./archive.cjs";
3
+ import { LearnedSkillsError, LearnedSkillsErrorCode } from "../learned-skills.cjs";
4
+ import { RegistryConfig, SkillRegistryOptions, resolveRegistryConfig } from "./config.cjs";
5
+ import { invalidSnapshot } from "./errors.cjs";
6
+ import { SnapshotFile, SnapshotSkill, VerifiedSnapshot, validateSnapshot } from "./snapshot.cjs";
7
+ import { SkillRegistry, SkillRegistryStatus } from "./registry.cjs";
8
+ import { formatSkillCatalog, loadSkill, readSkillFile } from "./skill-content.cjs";
@@ -0,0 +1,8 @@
1
+
2
+ import { MAX_ARCHIVE_ENTRIES, MAX_SNAPSHOT_BYTES, readArchive, safeRelativePath } from "./archive.mjs";
3
+ import { LearnedSkillsError, LearnedSkillsErrorCode } from "../learned-skills.mjs";
4
+ import { RegistryConfig, SkillRegistryOptions, resolveRegistryConfig } from "./config.mjs";
5
+ import { invalidSnapshot } from "./errors.mjs";
6
+ import { SnapshotFile, SnapshotSkill, VerifiedSnapshot, validateSnapshot } from "./snapshot.mjs";
7
+ import { SkillRegistry, SkillRegistryStatus } from "./registry.mjs";
8
+ import { formatSkillCatalog, loadSkill, readSkillFile } from "./skill-content.mjs";
@@ -0,0 +1,132 @@
1
+ require("reflect-metadata");
2
+ const require_learned_skills = require('../learned-skills.cjs');
3
+ const require_errors = require('./errors.cjs');
4
+ const require_config = require('./config.cjs');
5
+ const require_snapshot = require('./snapshot.cjs');
6
+
7
+ //#region src/v2/runtime/intelligence-platform/skill-registry/registry.ts
8
+ function transient(error) {
9
+ return [
10
+ "NETWORK_ERROR",
11
+ "TIMEOUT",
12
+ "INVALID_SNAPSHOT",
13
+ "UNSUPPORTED_SERVER"
14
+ ].includes(error.code);
15
+ }
16
+ function deliveryError(error) {
17
+ if (error instanceof require_learned_skills.LearnedSkillsError) return error;
18
+ return new require_learned_skills.LearnedSkillsError(error instanceof Error && error.name === "TimeoutError" ? "TIMEOUT" : "NETWORK_ERROR", true, error);
19
+ }
20
+ /** Internal registry shared by framework adapters; public API is framework-native. */
21
+ var SkillRegistry = class {
22
+ #config;
23
+ #snapshot;
24
+ #inFlight;
25
+ #lastCheckedAt;
26
+ #stale = false;
27
+ #lastError;
28
+ #blocked;
29
+ constructor(options = {}) {
30
+ this.#config = require_config.resolveRegistryConfig(options);
31
+ }
32
+ async initialize() {
33
+ await this.acquireSnapshot();
34
+ }
35
+ /** Capture exactly one immutable snapshot before model work begins. */
36
+ acquireSnapshot() {
37
+ if (this.#inFlight) return this.#inFlight;
38
+ if (this.#snapshot && !this.#blocked && this.#lastCheckedAt !== void 0 && Date.now() - this.#lastCheckedAt < this.#config.freshnessWindowMs) return Promise.resolve(this.#snapshot);
39
+ this.#inFlight = Promise.resolve().then(() => this.#refresh()).finally(() => {
40
+ this.#inFlight = void 0;
41
+ });
42
+ return this.#inFlight;
43
+ }
44
+ get status() {
45
+ const error = this.#lastError;
46
+ return Object.freeze({
47
+ initialized: this.#snapshot !== void 0,
48
+ ...this.#snapshot ? { revision: this.#snapshot.revision } : {},
49
+ mode: this.#config.revision === void 0 ? "latest" : "pinned",
50
+ ...this.#lastCheckedAt !== void 0 ? { lastCheckedAt: new Date(this.#lastCheckedAt).toISOString() } : {},
51
+ stale: this.#stale,
52
+ ...error ? { lastError: Object.freeze({
53
+ code: error.code,
54
+ message: error.message,
55
+ retryable: error.retryable
56
+ }) } : {}
57
+ });
58
+ }
59
+ async #refresh() {
60
+ const startedAt = Date.now();
61
+ const controller = new AbortController();
62
+ let timer;
63
+ const deadline = new Promise((_, reject) => {
64
+ timer = setTimeout(() => {
65
+ const error = new require_learned_skills.LearnedSkillsError("TIMEOUT", true);
66
+ controller.abort(error);
67
+ timer = setTimeout(() => reject(error), 0);
68
+ }, this.#config.requestTimeoutMs);
69
+ });
70
+ const replacement = async () => {
71
+ const response = await this.#config.client.getLearnedSkillsSnapshot({
72
+ containerId: this.#config.containerId,
73
+ ...this.#config.revision !== void 0 ? { revision: this.#config.revision } : {},
74
+ ...this.#snapshot ? { ifNoneMatch: this.#snapshot.etag } : {},
75
+ signal: controller.signal
76
+ });
77
+ controller.signal.throwIfAborted();
78
+ if (!response || typeof response !== "object") throw require_errors.invalidSnapshot();
79
+ if (response.status === "unchanged") {
80
+ if (!this.#snapshot || response.etag !== this.#snapshot.etag || response.revision !== this.#snapshot.revision) throw require_errors.invalidSnapshot();
81
+ return this.#snapshot;
82
+ }
83
+ if (this.#config.revision !== void 0 && response.revision !== this.#config.revision) throw require_errors.invalidSnapshot();
84
+ return require_snapshot.validateSnapshot(response, controller.signal);
85
+ };
86
+ try {
87
+ const snapshot = await Promise.race([replacement(), deadline]);
88
+ this.#snapshot = snapshot;
89
+ this.#lastCheckedAt = Date.now();
90
+ this.#stale = false;
91
+ this.#lastError = void 0;
92
+ this.#blocked = void 0;
93
+ this.#debug("refresh-success", startedAt);
94
+ return snapshot;
95
+ } catch (cause) {
96
+ const error = deliveryError(cause);
97
+ if (!transient(error)) {
98
+ this.#blocked = error;
99
+ this.#stale = false;
100
+ this.#lastError = error;
101
+ this.#debug("refresh-denied", startedAt, error.code);
102
+ throw error;
103
+ }
104
+ if (this.#blocked) {
105
+ this.#lastError = this.#blocked;
106
+ this.#debug("refresh-failed", startedAt, error.code);
107
+ throw this.#blocked;
108
+ }
109
+ this.#lastError = error;
110
+ this.#stale = this.#snapshot !== void 0;
111
+ this.#debug("refresh-failed", startedAt, error.code);
112
+ if (this.#snapshot) return this.#snapshot;
113
+ throw error;
114
+ } finally {
115
+ if (timer !== void 0) clearTimeout(timer);
116
+ }
117
+ }
118
+ #debug(event, startedAt, errorCode) {
119
+ if (!this.#config.debug) return;
120
+ console.debug("CopilotKit learned skills", {
121
+ event,
122
+ containerId: this.#config.containerId,
123
+ revision: this.#snapshot?.revision,
124
+ durationMs: Date.now() - startedAt,
125
+ ...errorCode ? { errorCode } : {}
126
+ });
127
+ }
128
+ };
129
+
130
+ //#endregion
131
+ exports.SkillRegistry = SkillRegistry;
132
+ //# sourceMappingURL=registry.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registry.cjs","names":["SkillDeliveryError","#config","resolveRegistryConfig","#inFlight","#snapshot","#blocked","#lastCheckedAt","#refresh","#lastError","#stale","invalidSnapshot","validateSnapshot","#debug"],"sources":["../../../../../src/v2/runtime/intelligence-platform/skill-registry/registry.ts"],"sourcesContent":["import { resolveRegistryConfig } from \"./config\";\nimport type { RegistryConfig, SkillRegistryOptions } from \"./config\";\nimport { SkillDeliveryError, invalidSnapshot } from \"./errors\";\nimport type { SkillDeliveryErrorCode } from \"./errors\";\nimport { validateSnapshot } from \"./snapshot\";\nimport type { VerifiedSnapshot } from \"./snapshot\";\n\nexport interface SkillRegistryStatus {\n readonly initialized: boolean;\n readonly revision?: string;\n readonly mode: \"latest\" | \"pinned\";\n /** ISO 8601 timestamp of the last successful 200 or matching 304 check. */\n readonly lastCheckedAt?: string;\n readonly stale: boolean;\n readonly lastError?: Readonly<{\n code: SkillDeliveryErrorCode;\n message: string;\n retryable: boolean;\n }>;\n}\n\nfunction transient(error: SkillDeliveryError): boolean {\n return [\n \"NETWORK_ERROR\",\n \"TIMEOUT\",\n \"INVALID_SNAPSHOT\",\n \"UNSUPPORTED_SERVER\",\n ].includes(error.code);\n}\nfunction deliveryError(error: unknown): SkillDeliveryError {\n if (error instanceof SkillDeliveryError) return error;\n return new SkillDeliveryError(\n error instanceof Error && error.name === \"TimeoutError\"\n ? \"TIMEOUT\"\n : \"NETWORK_ERROR\",\n true,\n error,\n );\n}\n\n/** Internal registry shared by framework adapters; public API is framework-native. */\nexport class SkillRegistry {\n readonly #config: RegistryConfig;\n #snapshot?: VerifiedSnapshot;\n #inFlight?: Promise<VerifiedSnapshot>;\n #lastCheckedAt?: number;\n #stale = false;\n #lastError?: SkillDeliveryError;\n #blocked?: SkillDeliveryError;\n\n constructor(options: SkillRegistryOptions = {}) {\n this.#config = resolveRegistryConfig(options);\n }\n\n async initialize(): Promise<void> {\n await this.acquireSnapshot();\n }\n\n /** Capture exactly one immutable snapshot before model work begins. */\n acquireSnapshot(): Promise<VerifiedSnapshot> {\n if (this.#inFlight) return this.#inFlight;\n if (\n this.#snapshot &&\n !this.#blocked &&\n this.#lastCheckedAt !== undefined &&\n Date.now() - this.#lastCheckedAt < this.#config.freshnessWindowMs\n ) {\n return Promise.resolve(this.#snapshot);\n }\n // Defer work one microtask so reentrant and concurrent callers observe the\n // same promise before an injected client can start its request.\n this.#inFlight = Promise.resolve()\n .then(() => this.#refresh())\n .finally(() => {\n this.#inFlight = undefined;\n });\n return this.#inFlight;\n }\n\n get status(): SkillRegistryStatus {\n const error = this.#lastError;\n return Object.freeze({\n initialized: this.#snapshot !== undefined,\n ...(this.#snapshot ? { revision: this.#snapshot.revision } : {}),\n mode: this.#config.revision === undefined ? \"latest\" : \"pinned\",\n ...(this.#lastCheckedAt !== undefined\n ? { lastCheckedAt: new Date(this.#lastCheckedAt).toISOString() }\n : {}),\n stale: this.#stale,\n ...(error\n ? {\n lastError: Object.freeze({\n code: error.code,\n message: error.message,\n retryable: error.retryable,\n }),\n }\n : {}),\n });\n }\n\n async #refresh(): Promise<VerifiedSnapshot> {\n const startedAt = Date.now();\n const controller = new AbortController();\n let timer: ReturnType<typeof setTimeout> | undefined;\n const deadline = new Promise<never>((_, reject) => {\n timer = setTimeout(() => {\n const error = new SkillDeliveryError(\"TIMEOUT\", true);\n controller.abort(error);\n // Give a canonical client that already received denial headers one\n // event-loop turn to report that denial before the watchdog wins.\n timer = setTimeout(() => reject(error), 0);\n }, this.#config.requestTimeoutMs);\n });\n const replacement = async (): Promise<VerifiedSnapshot> => {\n const response = await this.#config.client.getLearnedSkillsSnapshot({\n containerId: this.#config.containerId,\n ...(this.#config.revision !== undefined\n ? { revision: this.#config.revision }\n : {}),\n ...(this.#snapshot ? { ifNoneMatch: this.#snapshot.etag } : {}),\n signal: controller.signal,\n });\n controller.signal.throwIfAborted();\n if (!response || typeof response !== \"object\") throw invalidSnapshot();\n if (response.status === \"unchanged\") {\n if (\n !this.#snapshot ||\n response.etag !== this.#snapshot.etag ||\n response.revision !== this.#snapshot.revision\n )\n throw invalidSnapshot();\n return this.#snapshot;\n }\n if (\n this.#config.revision !== undefined &&\n response.revision !== this.#config.revision\n )\n throw invalidSnapshot();\n return validateSnapshot(response, controller.signal);\n };\n try {\n const snapshot = await Promise.race([replacement(), deadline]);\n // An abandoned parse never writes registry state: only the winning\n // complete replacement reaches this assignment.\n this.#snapshot = snapshot;\n this.#lastCheckedAt = Date.now();\n this.#stale = false;\n this.#lastError = undefined;\n this.#blocked = undefined;\n this.#debug(\"refresh-success\", startedAt);\n return snapshot;\n } catch (cause) {\n const error = deliveryError(cause);\n if (!transient(error)) {\n this.#blocked = error;\n this.#stale = false;\n this.#lastError = error;\n this.#debug(\"refresh-denied\", startedAt, error.code);\n throw error;\n }\n // A later unreachable server cannot undo an already confirmed denial.\n if (this.#blocked) {\n this.#lastError = this.#blocked;\n this.#debug(\"refresh-failed\", startedAt, error.code);\n throw this.#blocked;\n }\n this.#lastError = error;\n this.#stale = this.#snapshot !== undefined;\n this.#debug(\"refresh-failed\", startedAt, error.code);\n if (this.#snapshot) return this.#snapshot;\n throw error;\n } finally {\n if (timer !== undefined) clearTimeout(timer);\n }\n }\n\n #debug(\n event: string,\n startedAt: number,\n errorCode?: SkillDeliveryErrorCode,\n ): void {\n if (!this.#config.debug) return;\n console.debug(\"CopilotKit learned skills\", {\n event,\n containerId: this.#config.containerId,\n revision: this.#snapshot?.revision,\n durationMs: Date.now() - startedAt,\n ...(errorCode ? { errorCode } : {}),\n });\n }\n}\n"],"mappings":"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"}