@copilotkit/intelligence-langgraph 0.1.0
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.
- package/LICENSE +21 -0
- package/README.md +48 -0
- package/dist/index.cjs +9 -0
- package/dist/index.d.cts +5 -0
- package/dist/index.d.mts +6 -0
- package/dist/index.mjs +6 -0
- package/dist/intelligence-delivery-core/dist/archive.cjs +130 -0
- package/dist/intelligence-delivery-core/dist/archive.cjs.map +1 -0
- package/dist/intelligence-delivery-core/dist/archive.mjs +127 -0
- package/dist/intelligence-delivery-core/dist/archive.mjs.map +1 -0
- package/dist/intelligence-delivery-core/dist/config.cjs +47 -0
- package/dist/intelligence-delivery-core/dist/config.cjs.map +1 -0
- package/dist/intelligence-delivery-core/dist/config.d.cts +17 -0
- package/dist/intelligence-delivery-core/dist/config.d.cts.map +1 -0
- package/dist/intelligence-delivery-core/dist/config.d.mts +17 -0
- package/dist/intelligence-delivery-core/dist/config.d.mts.map +1 -0
- package/dist/intelligence-delivery-core/dist/config.mjs +47 -0
- package/dist/intelligence-delivery-core/dist/config.mjs.map +1 -0
- package/dist/intelligence-delivery-core/dist/errors.cjs +10 -0
- package/dist/intelligence-delivery-core/dist/errors.cjs.map +1 -0
- package/dist/intelligence-delivery-core/dist/errors.d.cts +2 -0
- package/dist/intelligence-delivery-core/dist/errors.d.mts +2 -0
- package/dist/intelligence-delivery-core/dist/errors.mjs +10 -0
- package/dist/intelligence-delivery-core/dist/errors.mjs.map +1 -0
- package/dist/intelligence-delivery-core/dist/index.cjs +7 -0
- package/dist/intelligence-delivery-core/dist/index.d.mts +5 -0
- package/dist/intelligence-delivery-core/dist/index.mjs +8 -0
- package/dist/intelligence-delivery-core/dist/registry.cjs +131 -0
- package/dist/intelligence-delivery-core/dist/registry.cjs.map +1 -0
- package/dist/intelligence-delivery-core/dist/registry.d.cts +31 -0
- package/dist/intelligence-delivery-core/dist/registry.d.cts.map +1 -0
- package/dist/intelligence-delivery-core/dist/registry.d.mts +31 -0
- package/dist/intelligence-delivery-core/dist/registry.d.mts.map +1 -0
- package/dist/intelligence-delivery-core/dist/registry.mjs +130 -0
- package/dist/intelligence-delivery-core/dist/registry.mjs.map +1 -0
- package/dist/intelligence-delivery-core/dist/skill-content.cjs +41 -0
- package/dist/intelligence-delivery-core/dist/skill-content.cjs.map +1 -0
- package/dist/intelligence-delivery-core/dist/skill-content.d.mts +1 -0
- package/dist/intelligence-delivery-core/dist/skill-content.mjs +38 -0
- package/dist/intelligence-delivery-core/dist/skill-content.mjs.map +1 -0
- package/dist/intelligence-delivery-core/dist/snapshot.cjs +91 -0
- package/dist/intelligence-delivery-core/dist/snapshot.cjs.map +1 -0
- package/dist/intelligence-delivery-core/dist/snapshot.d.cts +23 -0
- package/dist/intelligence-delivery-core/dist/snapshot.d.cts.map +1 -0
- package/dist/intelligence-delivery-core/dist/snapshot.d.mts +25 -0
- package/dist/intelligence-delivery-core/dist/snapshot.d.mts.map +1 -0
- package/dist/intelligence-delivery-core/dist/snapshot.mjs +90 -0
- package/dist/intelligence-delivery-core/dist/snapshot.mjs.map +1 -0
- package/dist/invocation.cjs +164 -0
- package/dist/invocation.cjs.map +1 -0
- package/dist/invocation.mjs +164 -0
- package/dist/invocation.mjs.map +1 -0
- package/dist/middleware.cjs +49 -0
- package/dist/middleware.cjs.map +1 -0
- package/dist/middleware.d.cts +45 -0
- package/dist/middleware.d.cts.map +1 -0
- package/dist/middleware.d.mts +46 -0
- package/dist/middleware.d.mts.map +1 -0
- package/dist/middleware.mjs +49 -0
- package/dist/middleware.mjs.map +1 -0
- package/dist/skill-tools.cjs +25 -0
- package/dist/skill-tools.cjs.map +1 -0
- package/dist/skill-tools.mjs +25 -0
- package/dist/skill-tools.mjs.map +1 -0
- package/package.json +85 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) Atai Barkai
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# CopilotKit Intelligence skills for LangGraph
|
|
2
|
+
|
|
3
|
+
Keep one Learning container's published skills available to native TypeScript LangChain agents. The adapter adds an alphabetical catalog and two read tools; the model decides when to use a skill.
|
|
4
|
+
|
|
5
|
+
Requires Node.js 20.19+, LangChain 1.5.11+, LangGraph 1.4.14+, and LangChain core 1.2.10+ within major version 1. The Intelligence server must expose the learned-snapshot API, and the canonical Runtime client must include that operation.
|
|
6
|
+
|
|
7
|
+
## Setup
|
|
8
|
+
|
|
9
|
+
```typescript
|
|
10
|
+
import { createAgent } from "langchain";
|
|
11
|
+
import {
|
|
12
|
+
SkillRegistry,
|
|
13
|
+
createSkillRegistryMiddleware,
|
|
14
|
+
} from "@copilotkit/intelligence-langgraph";
|
|
15
|
+
|
|
16
|
+
// CPK_INTELLIGENCE_API_KEY and CPK_INTELLIGENCE_LEARNING_CONTAINER_ID
|
|
17
|
+
// configure the registry. Set INTELLIGENCE_API_URL for self-hosting.
|
|
18
|
+
const registry = new SkillRegistry();
|
|
19
|
+
await registry.initialize();
|
|
20
|
+
const skills = createSkillRegistryMiddleware({ registry });
|
|
21
|
+
const agent = skills.wrapAgent(
|
|
22
|
+
createAgent({
|
|
23
|
+
model: "your-provider:your-model",
|
|
24
|
+
systemPrompt: "Follow our support policy.",
|
|
25
|
+
middleware: [skills],
|
|
26
|
+
}),
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
const result = await agent.invoke({
|
|
30
|
+
messages: [{ role: "user", content: "Help with a refund" }],
|
|
31
|
+
});
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
The wrapper is required for affected framework versions. It keeps one immutable snapshot outside checkpoints for each invocation, including streams and resumed runs. After a native framework fix passes the same lifecycle tests, middleware-only setup will become the default; the wrapper will be optional and existing wrapped agents will remain supported.
|
|
35
|
+
|
|
36
|
+
Use the wrapped agent's `invoke`, `stream`, or `streamEvents`, including native `Command` resumes. `withConfig` retains the wrapper. Apply default cancellation signals after wrapping, or pass a signal to the invocation. Native stream readers and cancellation remain available; graph batching is unsupported. Register and wrap each selected agent explicitly.
|
|
37
|
+
|
|
38
|
+
## Configuration and errors
|
|
39
|
+
|
|
40
|
+
Pass an existing `CopilotKitIntelligence` client from `@copilotkit/runtime/v2` as `new SkillRegistry({ client, containerId })` to reuse its credentials and transport. Your application retains ownership of that client. Explicit options override environment values; an injected client is authoritative for connection configuration.
|
|
41
|
+
|
|
42
|
+
`freshnessWindowMs` and `requestTimeoutMs` default to 5000; `debug` defaults to false. Set `revision` or `CPK_INTELLIGENCE_SKILLS_REVISION` for an exact whole-container pin. Startup initialization is optional: the first wrapped invocation initializes automatically. Initialization and invocation errors are catchable as `SkillDeliveryError`.
|
|
43
|
+
|
|
44
|
+
`registry.status` reports initialization, revision, last successful check, stale state, and a safe last error. Warm transient failures retain the prior snapshot; confirmed denial blocks new invocations. Running invocations finish with their captured snapshot. The adapter performs no retry, disk writes, or script execution.
|
|
45
|
+
|
|
46
|
+
Both `copilotkit_load_skill` and `copilotkit_read_skill_file` remain registered for an empty container. Developer instructions retain precedence over learned skills. Unsupported file content and unknown names or paths use native tool errors.
|
|
47
|
+
|
|
48
|
+
See the [learned skill delivery guide](https://docs.copilotkit.ai/intelligence/learned-skills) for managed/self-hosted setup, release prerequisites, and migration from CLI downloads.
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_registry = require('./intelligence-delivery-core/dist/registry.cjs');
|
|
3
|
+
require('./intelligence-delivery-core/dist/index.cjs');
|
|
4
|
+
const require_middleware = require('./middleware.cjs');
|
|
5
|
+
let _copilotkit_runtime_v2 = require("@copilotkit/runtime/v2");
|
|
6
|
+
|
|
7
|
+
exports.SkillDeliveryError = _copilotkit_runtime_v2.LearnedSkillsError;
|
|
8
|
+
exports.SkillRegistry = require_registry.SkillRegistry;
|
|
9
|
+
exports.createSkillRegistryMiddleware = require_middleware.createSkillRegistryMiddleware;
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { SkillRegistryOptions } from "./intelligence-delivery-core/dist/config.cjs";
|
|
2
|
+
import { SkillDeliveryError, SkillDeliveryErrorCode } from "./intelligence-delivery-core/dist/errors.cjs";
|
|
3
|
+
import { SkillRegistry, SkillRegistryStatus } from "./intelligence-delivery-core/dist/registry.cjs";
|
|
4
|
+
import { SkillRegistryMiddlewareOptions, createSkillRegistryMiddleware } from "./middleware.cjs";
|
|
5
|
+
export { SkillDeliveryError, type SkillDeliveryErrorCode, SkillRegistry, type SkillRegistryMiddlewareOptions, type SkillRegistryOptions, type SkillRegistryStatus, createSkillRegistryMiddleware };
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { SkillRegistryOptions } from "./intelligence-delivery-core/dist/config.mjs";
|
|
2
|
+
import { SkillDeliveryError, SkillDeliveryErrorCode } from "./intelligence-delivery-core/dist/errors.mjs";
|
|
3
|
+
import { SkillRegistry, SkillRegistryStatus } from "./intelligence-delivery-core/dist/registry.mjs";
|
|
4
|
+
import "./intelligence-delivery-core/dist/index.mjs";
|
|
5
|
+
import { SkillRegistryMiddlewareOptions, createSkillRegistryMiddleware } from "./middleware.mjs";
|
|
6
|
+
export { SkillDeliveryError, type SkillDeliveryErrorCode, SkillRegistry, type SkillRegistryMiddlewareOptions, type SkillRegistryOptions, type SkillRegistryStatus, createSkillRegistryMiddleware };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { SkillDeliveryError } from "./intelligence-delivery-core/dist/errors.mjs";
|
|
2
|
+
import { SkillRegistry } from "./intelligence-delivery-core/dist/registry.mjs";
|
|
3
|
+
import "./intelligence-delivery-core/dist/index.mjs";
|
|
4
|
+
import { createSkillRegistryMiddleware } from "./middleware.mjs";
|
|
5
|
+
|
|
6
|
+
export { SkillDeliveryError, SkillRegistry, createSkillRegistryMiddleware };
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
const require_errors = require('./errors.cjs');
|
|
2
|
+
let yauzl = require("yauzl");
|
|
3
|
+
|
|
4
|
+
//#region ../intelligence-delivery-core/dist/archive.mjs
|
|
5
|
+
/** Internal corruption bounds, including manifest and directory entries. */
|
|
6
|
+
const MAX_ARCHIVE_ENTRIES = 1e3;
|
|
7
|
+
const MAX_SNAPSHOT_BYTES = 32 * 1024 * 1024;
|
|
8
|
+
function safeRelativePath(path) {
|
|
9
|
+
return path.length > 0 && !/[\\\x00-\x1f\x7f]/.test(path) && !/^[a-z]:/i.test(path) && path.split("/").every((part) => part !== "" && part !== "." && part !== "..");
|
|
10
|
+
}
|
|
11
|
+
/** Decode only the listed ZIP namespace. No filesystem is involved. */
|
|
12
|
+
function readArchive(bytes, signal) {
|
|
13
|
+
return new Promise((resolve, reject) => {
|
|
14
|
+
let archive;
|
|
15
|
+
let stream;
|
|
16
|
+
let settled = false;
|
|
17
|
+
const finish = (error) => {
|
|
18
|
+
if (settled) return;
|
|
19
|
+
settled = true;
|
|
20
|
+
signal?.removeEventListener("abort", abort);
|
|
21
|
+
stream?.destroy();
|
|
22
|
+
archive?.close();
|
|
23
|
+
if (error !== void 0) reject(error);
|
|
24
|
+
else resolve(files);
|
|
25
|
+
};
|
|
26
|
+
const abort = () => finish(signal?.reason ?? require_errors.invalidSnapshot());
|
|
27
|
+
const files = /* @__PURE__ */ new Map();
|
|
28
|
+
const names = /* @__PURE__ */ new Set();
|
|
29
|
+
let decodedBytes = 0;
|
|
30
|
+
signal?.addEventListener("abort", abort, { once: true });
|
|
31
|
+
if (signal?.aborted) {
|
|
32
|
+
abort();
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
(0, yauzl.fromBuffer)(bytes, {
|
|
36
|
+
lazyEntries: true,
|
|
37
|
+
decodeStrings: false,
|
|
38
|
+
validateEntrySizes: true,
|
|
39
|
+
autoClose: false
|
|
40
|
+
}, (error, zip) => {
|
|
41
|
+
if (error) {
|
|
42
|
+
finish(require_errors.invalidSnapshot(error));
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
archive = zip;
|
|
46
|
+
if (settled) {
|
|
47
|
+
zip.close();
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
zip.on("error", (cause) => finish(require_errors.invalidSnapshot(cause)));
|
|
51
|
+
zip.on("end", () => finish());
|
|
52
|
+
if (zip.entryCount > MAX_ARCHIVE_ENTRIES) {
|
|
53
|
+
finish(require_errors.invalidSnapshot());
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
zip.on("entry", (entry) => {
|
|
57
|
+
try {
|
|
58
|
+
const rawName = entry.fileName;
|
|
59
|
+
if (!Buffer.isBuffer(rawName)) throw require_errors.invalidSnapshot();
|
|
60
|
+
const name = new TextDecoder("utf-8", {
|
|
61
|
+
fatal: true,
|
|
62
|
+
ignoreBOM: true
|
|
63
|
+
}).decode(rawName);
|
|
64
|
+
const directory = name.endsWith("/");
|
|
65
|
+
if (!safeRelativePath(directory ? name.slice(0, -1) : name) || names.has(name)) throw require_errors.invalidSnapshot();
|
|
66
|
+
names.add(name);
|
|
67
|
+
const fileType = entry.externalFileAttributes >>> 16 & 61440;
|
|
68
|
+
if (fileType !== 0 && fileType !== (directory ? 16384 : 32768)) throw require_errors.invalidSnapshot();
|
|
69
|
+
if (entry.isEncrypted() || ![0, 8].includes(entry.compressionMethod)) throw require_errors.invalidSnapshot();
|
|
70
|
+
if (!Number.isSafeInteger(entry.uncompressedSize) || entry.uncompressedSize < 0) throw require_errors.invalidSnapshot();
|
|
71
|
+
decodedBytes += entry.uncompressedSize;
|
|
72
|
+
if (decodedBytes > MAX_SNAPSHOT_BYTES || directory && entry.uncompressedSize !== 0) throw require_errors.invalidSnapshot();
|
|
73
|
+
const local = entry.relativeOffsetOfLocalHeader;
|
|
74
|
+
if (local < 0 || local + 30 > bytes.length || bytes.readUInt32LE(local) !== 67324752) throw require_errors.invalidSnapshot();
|
|
75
|
+
if (bytes.readUInt16LE(local + 6) !== entry.generalPurposeBitFlag || bytes.readUInt16LE(local + 8) !== entry.compressionMethod) throw require_errors.invalidSnapshot();
|
|
76
|
+
const localNameLength = bytes.readUInt16LE(local + 26);
|
|
77
|
+
const localExtraLength = bytes.readUInt16LE(local + 28);
|
|
78
|
+
if (local + 30 + localNameLength + localExtraLength + entry.compressedSize > bytes.length || !bytes.subarray(local + 30, local + 30 + localNameLength).equals(rawName)) throw require_errors.invalidSnapshot();
|
|
79
|
+
if (!(entry.generalPurposeBitFlag & 8) && (bytes.readUInt32LE(local + 18) !== entry.compressedSize || bytes.readUInt32LE(local + 22) !== entry.uncompressedSize)) throw require_errors.invalidSnapshot();
|
|
80
|
+
if (directory) {
|
|
81
|
+
zip.readEntry();
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
zip.openReadStream(entry, (readError, readStream) => {
|
|
85
|
+
if (readError) {
|
|
86
|
+
finish(require_errors.invalidSnapshot(readError));
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
stream = readStream;
|
|
90
|
+
if (settled) {
|
|
91
|
+
readStream.destroy();
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
const chunks = [];
|
|
95
|
+
let size = 0;
|
|
96
|
+
readStream.on("error", (cause) => finish(require_errors.invalidSnapshot(cause)));
|
|
97
|
+
readStream.on("data", (chunk) => {
|
|
98
|
+
size += chunk.length;
|
|
99
|
+
if (size > entry.uncompressedSize || size > MAX_SNAPSHOT_BYTES) {
|
|
100
|
+
finish(require_errors.invalidSnapshot());
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
chunks.push(chunk);
|
|
104
|
+
});
|
|
105
|
+
readStream.on("end", () => {
|
|
106
|
+
if (settled) return;
|
|
107
|
+
if (size !== entry.uncompressedSize) {
|
|
108
|
+
finish(require_errors.invalidSnapshot());
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
files.set(name, Buffer.concat(chunks, size));
|
|
112
|
+
stream = void 0;
|
|
113
|
+
zip.readEntry();
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
} catch (cause) {
|
|
117
|
+
finish(require_errors.invalidSnapshot(cause));
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
zip.readEntry();
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
//#endregion
|
|
126
|
+
exports.MAX_ARCHIVE_ENTRIES = MAX_ARCHIVE_ENTRIES;
|
|
127
|
+
exports.MAX_SNAPSHOT_BYTES = MAX_SNAPSHOT_BYTES;
|
|
128
|
+
exports.readArchive = readArchive;
|
|
129
|
+
exports.safeRelativePath = safeRelativePath;
|
|
130
|
+
//# sourceMappingURL=archive.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"archive.cjs","names":["invalidSnapshot"],"sources":["../../../../intelligence-delivery-core/dist/archive.mjs"],"sourcesContent":["import { invalidSnapshot } from \"./errors.mjs\";\nimport { fromBuffer } from \"yauzl\";\n\n//#region src/archive.ts\n/** Internal corruption bounds, including manifest and directory entries. */\nconst MAX_ARCHIVE_ENTRIES = 1e3;\nconst MAX_SNAPSHOT_BYTES = 32 * 1024 * 1024;\nfunction safeRelativePath(path) {\n\treturn path.length > 0 && !/[\\\\\\x00-\\x1f\\x7f]/.test(path) && !/^[a-z]:/i.test(path) && path.split(\"/\").every((part) => part !== \"\" && part !== \".\" && part !== \"..\");\n}\n/** Decode only the listed ZIP namespace. No filesystem is involved. */\nfunction readArchive(bytes, signal) {\n\treturn new Promise((resolve, reject) => {\n\t\tlet archive;\n\t\tlet stream;\n\t\tlet settled = false;\n\t\tconst finish = (error) => {\n\t\t\tif (settled) return;\n\t\t\tsettled = true;\n\t\t\tsignal?.removeEventListener(\"abort\", abort);\n\t\t\tstream?.destroy();\n\t\t\tarchive?.close();\n\t\t\tif (error !== void 0) reject(error);\n\t\t\telse resolve(files);\n\t\t};\n\t\tconst abort = () => finish(signal?.reason ?? invalidSnapshot());\n\t\tconst files = /* @__PURE__ */ new Map();\n\t\tconst names = /* @__PURE__ */ new Set();\n\t\tlet decodedBytes = 0;\n\t\tsignal?.addEventListener(\"abort\", abort, { once: true });\n\t\tif (signal?.aborted) {\n\t\t\tabort();\n\t\t\treturn;\n\t\t}\n\t\tfromBuffer(bytes, {\n\t\t\tlazyEntries: true,\n\t\t\tdecodeStrings: false,\n\t\t\tvalidateEntrySizes: true,\n\t\t\tautoClose: false\n\t\t}, (error, zip) => {\n\t\t\tif (error) {\n\t\t\t\tfinish(invalidSnapshot(error));\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tarchive = zip;\n\t\t\tif (settled) {\n\t\t\t\tzip.close();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tzip.on(\"error\", (cause) => finish(invalidSnapshot(cause)));\n\t\t\tzip.on(\"end\", () => finish());\n\t\t\tif (zip.entryCount > MAX_ARCHIVE_ENTRIES) {\n\t\t\t\tfinish(invalidSnapshot());\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tzip.on(\"entry\", (entry) => {\n\t\t\t\ttry {\n\t\t\t\t\tconst rawName = entry.fileName;\n\t\t\t\t\tif (!Buffer.isBuffer(rawName)) throw invalidSnapshot();\n\t\t\t\t\tconst name = new TextDecoder(\"utf-8\", {\n\t\t\t\t\t\tfatal: true,\n\t\t\t\t\t\tignoreBOM: true\n\t\t\t\t\t}).decode(rawName);\n\t\t\t\t\tconst directory = name.endsWith(\"/\");\n\t\t\t\t\tif (!safeRelativePath(directory ? name.slice(0, -1) : name) || names.has(name)) throw invalidSnapshot();\n\t\t\t\t\tnames.add(name);\n\t\t\t\t\tconst fileType = entry.externalFileAttributes >>> 16 & 61440;\n\t\t\t\t\tif (fileType !== 0 && fileType !== (directory ? 16384 : 32768)) throw invalidSnapshot();\n\t\t\t\t\tif (entry.isEncrypted() || ![0, 8].includes(entry.compressionMethod)) throw invalidSnapshot();\n\t\t\t\t\tif (!Number.isSafeInteger(entry.uncompressedSize) || entry.uncompressedSize < 0) throw invalidSnapshot();\n\t\t\t\t\tdecodedBytes += entry.uncompressedSize;\n\t\t\t\t\tif (decodedBytes > MAX_SNAPSHOT_BYTES || directory && entry.uncompressedSize !== 0) throw invalidSnapshot();\n\t\t\t\t\tconst local = entry.relativeOffsetOfLocalHeader;\n\t\t\t\t\tif (local < 0 || local + 30 > bytes.length || bytes.readUInt32LE(local) !== 67324752) throw invalidSnapshot();\n\t\t\t\t\tif (bytes.readUInt16LE(local + 6) !== entry.generalPurposeBitFlag || bytes.readUInt16LE(local + 8) !== entry.compressionMethod) throw invalidSnapshot();\n\t\t\t\t\tconst localNameLength = bytes.readUInt16LE(local + 26);\n\t\t\t\t\tconst localExtraLength = bytes.readUInt16LE(local + 28);\n\t\t\t\t\tif (local + 30 + localNameLength + localExtraLength + entry.compressedSize > bytes.length || !bytes.subarray(local + 30, local + 30 + localNameLength).equals(rawName)) throw invalidSnapshot();\n\t\t\t\t\tif (!(entry.generalPurposeBitFlag & 8) && (bytes.readUInt32LE(local + 18) !== entry.compressedSize || bytes.readUInt32LE(local + 22) !== entry.uncompressedSize)) throw invalidSnapshot();\n\t\t\t\t\tif (directory) {\n\t\t\t\t\t\tzip.readEntry();\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tzip.openReadStream(entry, (readError, readStream) => {\n\t\t\t\t\t\tif (readError) {\n\t\t\t\t\t\t\tfinish(invalidSnapshot(readError));\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tstream = readStream;\n\t\t\t\t\t\tif (settled) {\n\t\t\t\t\t\t\treadStream.destroy();\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tconst chunks = [];\n\t\t\t\t\t\tlet size = 0;\n\t\t\t\t\t\treadStream.on(\"error\", (cause) => finish(invalidSnapshot(cause)));\n\t\t\t\t\t\treadStream.on(\"data\", (chunk) => {\n\t\t\t\t\t\t\tsize += chunk.length;\n\t\t\t\t\t\t\tif (size > entry.uncompressedSize || size > MAX_SNAPSHOT_BYTES) {\n\t\t\t\t\t\t\t\tfinish(invalidSnapshot());\n\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tchunks.push(chunk);\n\t\t\t\t\t\t});\n\t\t\t\t\t\treadStream.on(\"end\", () => {\n\t\t\t\t\t\t\tif (settled) return;\n\t\t\t\t\t\t\tif (size !== entry.uncompressedSize) {\n\t\t\t\t\t\t\t\tfinish(invalidSnapshot());\n\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tfiles.set(name, Buffer.concat(chunks, size));\n\t\t\t\t\t\t\tstream = void 0;\n\t\t\t\t\t\t\tzip.readEntry();\n\t\t\t\t\t\t});\n\t\t\t\t\t});\n\t\t\t\t} catch (cause) {\n\t\t\t\t\tfinish(invalidSnapshot(cause));\n\t\t\t\t}\n\t\t\t});\n\t\t\tzip.readEntry();\n\t\t});\n\t});\n}\n\n//#endregion\nexport { MAX_ARCHIVE_ENTRIES, MAX_SNAPSHOT_BYTES, readArchive, safeRelativePath };\n//# sourceMappingURL=archive.mjs.map"],"mappings":";;;;;AAKA,MAAM,sBAAsB;AAC5B,MAAM,qBAAqB,KAAK,OAAO;AACvC,SAAS,iBAAiB,MAAM;AAC/B,QAAO,KAAK,SAAS,KAAK,CAAC,oBAAoB,KAAK,KAAK,IAAI,CAAC,WAAW,KAAK,KAAK,IAAI,KAAK,MAAM,IAAI,CAAC,OAAO,SAAS,SAAS,MAAM,SAAS,OAAO,SAAS,KAAK;;;AAGrK,SAAS,YAAY,OAAO,QAAQ;AACnC,QAAO,IAAI,SAAS,SAAS,WAAW;EACvC,IAAI;EACJ,IAAI;EACJ,IAAI,UAAU;EACd,MAAM,UAAU,UAAU;AACzB,OAAI,QAAS;AACb,aAAU;AACV,WAAQ,oBAAoB,SAAS,MAAM;AAC3C,WAAQ,SAAS;AACjB,YAAS,OAAO;AAChB,OAAI,UAAU,KAAK,EAAG,QAAO,MAAM;OAC9B,SAAQ,MAAM;;EAEpB,MAAM,cAAc,OAAO,QAAQ,UAAUA,gCAAiB,CAAC;EAC/D,MAAM,wBAAwB,IAAI,KAAK;EACvC,MAAM,wBAAwB,IAAI,KAAK;EACvC,IAAI,eAAe;AACnB,UAAQ,iBAAiB,SAAS,OAAO,EAAE,MAAM,MAAM,CAAC;AACxD,MAAI,QAAQ,SAAS;AACpB,UAAO;AACP;;AAED,wBAAW,OAAO;GACjB,aAAa;GACb,eAAe;GACf,oBAAoB;GACpB,WAAW;GACX,GAAG,OAAO,QAAQ;AAClB,OAAI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|
+
import { invalidSnapshot } from "./errors.mjs";
|
|
2
|
+
import { fromBuffer } from "yauzl";
|
|
3
|
+
|
|
4
|
+
//#region ../intelligence-delivery-core/dist/archive.mjs
|
|
5
|
+
/** Internal corruption bounds, including manifest and directory entries. */
|
|
6
|
+
const MAX_ARCHIVE_ENTRIES = 1e3;
|
|
7
|
+
const MAX_SNAPSHOT_BYTES = 32 * 1024 * 1024;
|
|
8
|
+
function safeRelativePath(path) {
|
|
9
|
+
return path.length > 0 && !/[\\\x00-\x1f\x7f]/.test(path) && !/^[a-z]:/i.test(path) && path.split("/").every((part) => part !== "" && part !== "." && part !== "..");
|
|
10
|
+
}
|
|
11
|
+
/** Decode only the listed ZIP namespace. No filesystem is involved. */
|
|
12
|
+
function readArchive(bytes, signal) {
|
|
13
|
+
return new Promise((resolve, reject) => {
|
|
14
|
+
let archive;
|
|
15
|
+
let stream;
|
|
16
|
+
let settled = false;
|
|
17
|
+
const finish = (error) => {
|
|
18
|
+
if (settled) return;
|
|
19
|
+
settled = true;
|
|
20
|
+
signal?.removeEventListener("abort", abort);
|
|
21
|
+
stream?.destroy();
|
|
22
|
+
archive?.close();
|
|
23
|
+
if (error !== void 0) reject(error);
|
|
24
|
+
else resolve(files);
|
|
25
|
+
};
|
|
26
|
+
const abort = () => finish(signal?.reason ?? invalidSnapshot());
|
|
27
|
+
const files = /* @__PURE__ */ new Map();
|
|
28
|
+
const names = /* @__PURE__ */ new Set();
|
|
29
|
+
let decodedBytes = 0;
|
|
30
|
+
signal?.addEventListener("abort", abort, { once: true });
|
|
31
|
+
if (signal?.aborted) {
|
|
32
|
+
abort();
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
fromBuffer(bytes, {
|
|
36
|
+
lazyEntries: true,
|
|
37
|
+
decodeStrings: false,
|
|
38
|
+
validateEntrySizes: true,
|
|
39
|
+
autoClose: false
|
|
40
|
+
}, (error, zip) => {
|
|
41
|
+
if (error) {
|
|
42
|
+
finish(invalidSnapshot(error));
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
archive = zip;
|
|
46
|
+
if (settled) {
|
|
47
|
+
zip.close();
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
zip.on("error", (cause) => finish(invalidSnapshot(cause)));
|
|
51
|
+
zip.on("end", () => finish());
|
|
52
|
+
if (zip.entryCount > MAX_ARCHIVE_ENTRIES) {
|
|
53
|
+
finish(invalidSnapshot());
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
zip.on("entry", (entry) => {
|
|
57
|
+
try {
|
|
58
|
+
const rawName = entry.fileName;
|
|
59
|
+
if (!Buffer.isBuffer(rawName)) throw invalidSnapshot();
|
|
60
|
+
const name = new TextDecoder("utf-8", {
|
|
61
|
+
fatal: true,
|
|
62
|
+
ignoreBOM: true
|
|
63
|
+
}).decode(rawName);
|
|
64
|
+
const directory = name.endsWith("/");
|
|
65
|
+
if (!safeRelativePath(directory ? name.slice(0, -1) : name) || names.has(name)) throw invalidSnapshot();
|
|
66
|
+
names.add(name);
|
|
67
|
+
const fileType = entry.externalFileAttributes >>> 16 & 61440;
|
|
68
|
+
if (fileType !== 0 && fileType !== (directory ? 16384 : 32768)) throw invalidSnapshot();
|
|
69
|
+
if (entry.isEncrypted() || ![0, 8].includes(entry.compressionMethod)) throw invalidSnapshot();
|
|
70
|
+
if (!Number.isSafeInteger(entry.uncompressedSize) || entry.uncompressedSize < 0) throw invalidSnapshot();
|
|
71
|
+
decodedBytes += entry.uncompressedSize;
|
|
72
|
+
if (decodedBytes > MAX_SNAPSHOT_BYTES || directory && entry.uncompressedSize !== 0) throw invalidSnapshot();
|
|
73
|
+
const local = entry.relativeOffsetOfLocalHeader;
|
|
74
|
+
if (local < 0 || local + 30 > bytes.length || bytes.readUInt32LE(local) !== 67324752) throw invalidSnapshot();
|
|
75
|
+
if (bytes.readUInt16LE(local + 6) !== entry.generalPurposeBitFlag || bytes.readUInt16LE(local + 8) !== entry.compressionMethod) throw invalidSnapshot();
|
|
76
|
+
const localNameLength = bytes.readUInt16LE(local + 26);
|
|
77
|
+
const localExtraLength = bytes.readUInt16LE(local + 28);
|
|
78
|
+
if (local + 30 + localNameLength + localExtraLength + entry.compressedSize > bytes.length || !bytes.subarray(local + 30, local + 30 + localNameLength).equals(rawName)) throw invalidSnapshot();
|
|
79
|
+
if (!(entry.generalPurposeBitFlag & 8) && (bytes.readUInt32LE(local + 18) !== entry.compressedSize || bytes.readUInt32LE(local + 22) !== entry.uncompressedSize)) throw invalidSnapshot();
|
|
80
|
+
if (directory) {
|
|
81
|
+
zip.readEntry();
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
zip.openReadStream(entry, (readError, readStream) => {
|
|
85
|
+
if (readError) {
|
|
86
|
+
finish(invalidSnapshot(readError));
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
stream = readStream;
|
|
90
|
+
if (settled) {
|
|
91
|
+
readStream.destroy();
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
const chunks = [];
|
|
95
|
+
let size = 0;
|
|
96
|
+
readStream.on("error", (cause) => finish(invalidSnapshot(cause)));
|
|
97
|
+
readStream.on("data", (chunk) => {
|
|
98
|
+
size += chunk.length;
|
|
99
|
+
if (size > entry.uncompressedSize || size > MAX_SNAPSHOT_BYTES) {
|
|
100
|
+
finish(invalidSnapshot());
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
chunks.push(chunk);
|
|
104
|
+
});
|
|
105
|
+
readStream.on("end", () => {
|
|
106
|
+
if (settled) return;
|
|
107
|
+
if (size !== entry.uncompressedSize) {
|
|
108
|
+
finish(invalidSnapshot());
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
files.set(name, Buffer.concat(chunks, size));
|
|
112
|
+
stream = void 0;
|
|
113
|
+
zip.readEntry();
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
} catch (cause) {
|
|
117
|
+
finish(invalidSnapshot(cause));
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
zip.readEntry();
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
//#endregion
|
|
126
|
+
export { MAX_ARCHIVE_ENTRIES, MAX_SNAPSHOT_BYTES, readArchive, safeRelativePath };
|
|
127
|
+
//# sourceMappingURL=archive.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"archive.mjs","names":[],"sources":["../../../../intelligence-delivery-core/dist/archive.mjs"],"sourcesContent":["import { invalidSnapshot } from \"./errors.mjs\";\nimport { fromBuffer } from \"yauzl\";\n\n//#region src/archive.ts\n/** Internal corruption bounds, including manifest and directory entries. */\nconst MAX_ARCHIVE_ENTRIES = 1e3;\nconst MAX_SNAPSHOT_BYTES = 32 * 1024 * 1024;\nfunction safeRelativePath(path) {\n\treturn path.length > 0 && !/[\\\\\\x00-\\x1f\\x7f]/.test(path) && !/^[a-z]:/i.test(path) && path.split(\"/\").every((part) => part !== \"\" && part !== \".\" && part !== \"..\");\n}\n/** Decode only the listed ZIP namespace. No filesystem is involved. */\nfunction readArchive(bytes, signal) {\n\treturn new Promise((resolve, reject) => {\n\t\tlet archive;\n\t\tlet stream;\n\t\tlet settled = false;\n\t\tconst finish = (error) => {\n\t\t\tif (settled) return;\n\t\t\tsettled = true;\n\t\t\tsignal?.removeEventListener(\"abort\", abort);\n\t\t\tstream?.destroy();\n\t\t\tarchive?.close();\n\t\t\tif (error !== void 0) reject(error);\n\t\t\telse resolve(files);\n\t\t};\n\t\tconst abort = () => finish(signal?.reason ?? invalidSnapshot());\n\t\tconst files = /* @__PURE__ */ new Map();\n\t\tconst names = /* @__PURE__ */ new Set();\n\t\tlet decodedBytes = 0;\n\t\tsignal?.addEventListener(\"abort\", abort, { once: true });\n\t\tif (signal?.aborted) {\n\t\t\tabort();\n\t\t\treturn;\n\t\t}\n\t\tfromBuffer(bytes, {\n\t\t\tlazyEntries: true,\n\t\t\tdecodeStrings: false,\n\t\t\tvalidateEntrySizes: true,\n\t\t\tautoClose: false\n\t\t}, (error, zip) => {\n\t\t\tif (error) {\n\t\t\t\tfinish(invalidSnapshot(error));\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tarchive = zip;\n\t\t\tif (settled) {\n\t\t\t\tzip.close();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tzip.on(\"error\", (cause) => finish(invalidSnapshot(cause)));\n\t\t\tzip.on(\"end\", () => finish());\n\t\t\tif (zip.entryCount > MAX_ARCHIVE_ENTRIES) {\n\t\t\t\tfinish(invalidSnapshot());\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tzip.on(\"entry\", (entry) => {\n\t\t\t\ttry {\n\t\t\t\t\tconst rawName = entry.fileName;\n\t\t\t\t\tif (!Buffer.isBuffer(rawName)) throw invalidSnapshot();\n\t\t\t\t\tconst name = new TextDecoder(\"utf-8\", {\n\t\t\t\t\t\tfatal: true,\n\t\t\t\t\t\tignoreBOM: true\n\t\t\t\t\t}).decode(rawName);\n\t\t\t\t\tconst directory = name.endsWith(\"/\");\n\t\t\t\t\tif (!safeRelativePath(directory ? name.slice(0, -1) : name) || names.has(name)) throw invalidSnapshot();\n\t\t\t\t\tnames.add(name);\n\t\t\t\t\tconst fileType = entry.externalFileAttributes >>> 16 & 61440;\n\t\t\t\t\tif (fileType !== 0 && fileType !== (directory ? 16384 : 32768)) throw invalidSnapshot();\n\t\t\t\t\tif (entry.isEncrypted() || ![0, 8].includes(entry.compressionMethod)) throw invalidSnapshot();\n\t\t\t\t\tif (!Number.isSafeInteger(entry.uncompressedSize) || entry.uncompressedSize < 0) throw invalidSnapshot();\n\t\t\t\t\tdecodedBytes += entry.uncompressedSize;\n\t\t\t\t\tif (decodedBytes > MAX_SNAPSHOT_BYTES || directory && entry.uncompressedSize !== 0) throw invalidSnapshot();\n\t\t\t\t\tconst local = entry.relativeOffsetOfLocalHeader;\n\t\t\t\t\tif (local < 0 || local + 30 > bytes.length || bytes.readUInt32LE(local) !== 67324752) throw invalidSnapshot();\n\t\t\t\t\tif (bytes.readUInt16LE(local + 6) !== entry.generalPurposeBitFlag || bytes.readUInt16LE(local + 8) !== entry.compressionMethod) throw invalidSnapshot();\n\t\t\t\t\tconst localNameLength = bytes.readUInt16LE(local + 26);\n\t\t\t\t\tconst localExtraLength = bytes.readUInt16LE(local + 28);\n\t\t\t\t\tif (local + 30 + localNameLength + localExtraLength + entry.compressedSize > bytes.length || !bytes.subarray(local + 30, local + 30 + localNameLength).equals(rawName)) throw invalidSnapshot();\n\t\t\t\t\tif (!(entry.generalPurposeBitFlag & 8) && (bytes.readUInt32LE(local + 18) !== entry.compressedSize || bytes.readUInt32LE(local + 22) !== entry.uncompressedSize)) throw invalidSnapshot();\n\t\t\t\t\tif (directory) {\n\t\t\t\t\t\tzip.readEntry();\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tzip.openReadStream(entry, (readError, readStream) => {\n\t\t\t\t\t\tif (readError) {\n\t\t\t\t\t\t\tfinish(invalidSnapshot(readError));\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tstream = readStream;\n\t\t\t\t\t\tif (settled) {\n\t\t\t\t\t\t\treadStream.destroy();\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tconst chunks = [];\n\t\t\t\t\t\tlet size = 0;\n\t\t\t\t\t\treadStream.on(\"error\", (cause) => finish(invalidSnapshot(cause)));\n\t\t\t\t\t\treadStream.on(\"data\", (chunk) => {\n\t\t\t\t\t\t\tsize += chunk.length;\n\t\t\t\t\t\t\tif (size > entry.uncompressedSize || size > MAX_SNAPSHOT_BYTES) {\n\t\t\t\t\t\t\t\tfinish(invalidSnapshot());\n\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tchunks.push(chunk);\n\t\t\t\t\t\t});\n\t\t\t\t\t\treadStream.on(\"end\", () => {\n\t\t\t\t\t\t\tif (settled) return;\n\t\t\t\t\t\t\tif (size !== entry.uncompressedSize) {\n\t\t\t\t\t\t\t\tfinish(invalidSnapshot());\n\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tfiles.set(name, Buffer.concat(chunks, size));\n\t\t\t\t\t\t\tstream = void 0;\n\t\t\t\t\t\t\tzip.readEntry();\n\t\t\t\t\t\t});\n\t\t\t\t\t});\n\t\t\t\t} catch (cause) {\n\t\t\t\t\tfinish(invalidSnapshot(cause));\n\t\t\t\t}\n\t\t\t});\n\t\t\tzip.readEntry();\n\t\t});\n\t});\n}\n\n//#endregion\nexport { MAX_ARCHIVE_ENTRIES, MAX_SNAPSHOT_BYTES, readArchive, safeRelativePath };\n//# sourceMappingURL=archive.mjs.map"],"mappings":";;;;;AAKA,MAAM,sBAAsB;AAC5B,MAAM,qBAAqB,KAAK,OAAO;AACvC,SAAS,iBAAiB,MAAM;AAC/B,QAAO,KAAK,SAAS,KAAK,CAAC,oBAAoB,KAAK,KAAK,IAAI,CAAC,WAAW,KAAK,KAAK,IAAI,KAAK,MAAM,IAAI,CAAC,OAAO,SAAS,SAAS,MAAM,SAAS,OAAO,SAAS,KAAK;;;AAGrK,SAAS,YAAY,OAAO,QAAQ;AACnC,QAAO,IAAI,SAAS,SAAS,WAAW;EACvC,IAAI;EACJ,IAAI;EACJ,IAAI,UAAU;EACd,MAAM,UAAU,UAAU;AACzB,OAAI,QAAS;AACb,aAAU;AACV,WAAQ,oBAAoB,SAAS,MAAM;AAC3C,WAAQ,SAAS;AACjB,YAAS,OAAO;AAChB,OAAI,UAAU,KAAK,EAAG,QAAO,MAAM;OAC9B,SAAQ,MAAM;;EAEpB,MAAM,cAAc,OAAO,QAAQ,UAAU,iBAAiB,CAAC;EAC/D,MAAM,wBAAwB,IAAI,KAAK;EACvC,MAAM,wBAAwB,IAAI,KAAK;EACvC,IAAI,eAAe;AACnB,UAAQ,iBAAiB,SAAS,OAAO,EAAE,MAAM,MAAM,CAA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;QACd;OACD;aACM,OAAO;AACf,YAAO,gBAAgB,MAAM,CAAC;;KAE9B;AACF,OAAI,WAAW;IACd;GACD"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
require('./errors.cjs');
|
|
2
|
+
let _copilotkit_runtime_v2 = require("@copilotkit/runtime/v2");
|
|
3
|
+
|
|
4
|
+
//#region ../intelligence-delivery-core/dist/config.mjs
|
|
5
|
+
/** Resolve once. Never retain the options object, environment, or a second key. */
|
|
6
|
+
function resolveRegistryConfig(options = {}, environment = process.env) {
|
|
7
|
+
try {
|
|
8
|
+
const containerId = options.containerId ?? environment.CPK_INTELLIGENCE_LEARNING_CONTAINER_ID;
|
|
9
|
+
const revision = options.revision ?? environment.CPK_INTELLIGENCE_SKILLS_REVISION;
|
|
10
|
+
const freshnessWindowMs = options.freshnessWindowMs ?? 5e3;
|
|
11
|
+
const requestTimeoutMs = options.requestTimeoutMs ?? 5e3;
|
|
12
|
+
const debug = options.debug ?? false;
|
|
13
|
+
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 _copilotkit_runtime_v2.LearnedSkillsError("INVALID_CONFIG", false);
|
|
14
|
+
let client = options.client;
|
|
15
|
+
if (client !== void 0) {
|
|
16
|
+
if (!client || typeof client.getLearnedSkillsSnapshot !== "function") throw new _copilotkit_runtime_v2.LearnedSkillsError("INVALID_CONFIG", false);
|
|
17
|
+
} else {
|
|
18
|
+
const apiKey = options.apiKey ?? environment.CPK_INTELLIGENCE_API_KEY;
|
|
19
|
+
const apiUrl = options.apiUrl ?? environment.INTELLIGENCE_API_URL;
|
|
20
|
+
if (typeof apiKey !== "string" || !apiKey.trim()) throw new _copilotkit_runtime_v2.LearnedSkillsError("INVALID_CONFIG", false);
|
|
21
|
+
if (apiUrl?.trim()) {
|
|
22
|
+
const url = new URL(apiUrl);
|
|
23
|
+
if (!["http:", "https:"].includes(url.protocol) || url.username || url.password || url.search || url.hash) throw new _copilotkit_runtime_v2.LearnedSkillsError("INVALID_CONFIG", false);
|
|
24
|
+
}
|
|
25
|
+
client = new _copilotkit_runtime_v2.CopilotKitIntelligence({
|
|
26
|
+
apiKey,
|
|
27
|
+
...apiUrl !== void 0 ? { apiUrl } : {},
|
|
28
|
+
...apiUrl?.trim() ? { wsUrl: "wss://realtime.intelligence.copilotkit.ai" } : {}
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
return Object.freeze({
|
|
32
|
+
client,
|
|
33
|
+
containerId,
|
|
34
|
+
...revision !== void 0 ? { revision } : {},
|
|
35
|
+
freshnessWindowMs,
|
|
36
|
+
requestTimeoutMs,
|
|
37
|
+
debug
|
|
38
|
+
});
|
|
39
|
+
} catch (error) {
|
|
40
|
+
if (error instanceof _copilotkit_runtime_v2.LearnedSkillsError) throw error;
|
|
41
|
+
throw new _copilotkit_runtime_v2.LearnedSkillsError("INVALID_CONFIG", false, error);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
//#endregion
|
|
46
|
+
exports.resolveRegistryConfig = resolveRegistryConfig;
|
|
47
|
+
//# sourceMappingURL=config.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.cjs","names":["SkillDeliveryError","CopilotKitIntelligence"],"sources":["../../../../intelligence-delivery-core/dist/config.mjs"],"sourcesContent":["import { SkillDeliveryError } from \"./errors.mjs\";\nimport { CopilotKitIntelligence } from \"@copilotkit/runtime/v2\";\n\n//#region src/config.ts\n/** Resolve once. Never retain the options object, environment, or a second key. */\nfunction resolveRegistryConfig(options = {}, environment = process.env) {\n\ttry {\n\t\tconst containerId = options.containerId ?? environment.CPK_INTELLIGENCE_LEARNING_CONTAINER_ID;\n\t\tconst revision = options.revision ?? environment.CPK_INTELLIGENCE_SKILLS_REVISION;\n\t\tconst freshnessWindowMs = options.freshnessWindowMs ?? 5e3;\n\t\tconst requestTimeoutMs = options.requestTimeoutMs ?? 5e3;\n\t\tconst debug = options.debug ?? false;\n\t\tif (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 SkillDeliveryError(\"INVALID_CONFIG\", false);\n\t\tlet client = options.client;\n\t\tif (client !== void 0) {\n\t\t\tif (!client || typeof client.getLearnedSkillsSnapshot !== \"function\") throw new SkillDeliveryError(\"INVALID_CONFIG\", false);\n\t\t} else {\n\t\t\tconst apiKey = options.apiKey ?? environment.CPK_INTELLIGENCE_API_KEY;\n\t\t\tconst apiUrl = options.apiUrl ?? environment.INTELLIGENCE_API_URL;\n\t\t\tif (typeof apiKey !== \"string\" || !apiKey.trim()) throw new SkillDeliveryError(\"INVALID_CONFIG\", false);\n\t\t\tif (apiUrl?.trim()) {\n\t\t\t\tconst url = new URL(apiUrl);\n\t\t\t\tif (![\"http:\", \"https:\"].includes(url.protocol) || url.username || url.password || url.search || url.hash) throw new SkillDeliveryError(\"INVALID_CONFIG\", false);\n\t\t\t}\n\t\t\tclient = new CopilotKitIntelligence({\n\t\t\t\tapiKey,\n\t\t\t\t...apiUrl !== void 0 ? { apiUrl } : {},\n\t\t\t\t...apiUrl?.trim() ? { wsUrl: \"wss://realtime.intelligence.copilotkit.ai\" } : {}\n\t\t\t});\n\t\t}\n\t\treturn Object.freeze({\n\t\t\tclient,\n\t\t\tcontainerId,\n\t\t\t...revision !== void 0 ? { revision } : {},\n\t\t\tfreshnessWindowMs,\n\t\t\trequestTimeoutMs,\n\t\t\tdebug\n\t\t});\n\t} catch (error) {\n\t\tif (error instanceof SkillDeliveryError) throw error;\n\t\tthrow new SkillDelivery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GAAG,EAAE;IACtC,GAAG,QAAQ,MAAM,GAAG,EAAE,OAAO,6CAA6C,GAAG,EAAE;IAC/E,CAAC;;AAEH,SAAO,OAAO,OAAO;GACpB;GACA;GACA,GAAG,aAAa,KAAK,IAAI,EAAE,UAAU,GAAG,EAAE;GAC1C;GACA;GACA;GACA,CAAC;UACM,OAAO;AACf,MAAI,iBAAiBD,0CAAoB,OAAM;AAC/C,QAAM,IAAIA,0CAAmB,kBAAkB,OAAO,MAAM"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { CopilotKitIntelligence } from "@copilotkit/runtime/v2";
|
|
2
|
+
|
|
3
|
+
//#region ../intelligence-delivery-core/dist/config.d.mts
|
|
4
|
+
//#region src/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
|
+
//#endregion
|
|
16
|
+
export { SkillRegistryOptions };
|
|
17
|
+
//# sourceMappingURL=config.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.cts","names":["CopilotKitIntelligence","SkillRegistryOptions","client","apiKey","apiUrl","containerId","revision","freshnessWindowMs","requestTimeoutMs","debug","RegistryConfig","resolveRegistryConfig","NodeJS","ProcessEnv","options","environment"],"sources":["../../../../intelligence-delivery-core/dist/config.d.mts"],"mappings":";;;;UAGUC,oBAAAA;EACRC,MAAAA,GAASF,sBAAAA;EACTG,MAAAA;EACAC,MAAAA;EACAC,WAAAA;EACAC,QAAAA;EACAC,iBAAAA;EACAC,gBAAAA;EACAC,KAAAA;AAAAA"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { CopilotKitIntelligence } from "@copilotkit/runtime/v2";
|
|
2
|
+
|
|
3
|
+
//#region ../intelligence-delivery-core/dist/config.d.mts
|
|
4
|
+
//#region src/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
|
+
//#endregion
|
|
16
|
+
export { SkillRegistryOptions };
|
|
17
|
+
//# sourceMappingURL=config.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.mts","names":["CopilotKitIntelligence","SkillRegistryOptions","client","apiKey","apiUrl","containerId","revision","freshnessWindowMs","requestTimeoutMs","debug","RegistryConfig","resolveRegistryConfig","NodeJS","ProcessEnv","options","environment"],"sources":["../../../../intelligence-delivery-core/dist/config.d.mts"],"mappings":";;;;UAGUC,oBAAAA;EACRC,MAAAA,GAASF,sBAAAA;EACTG,MAAAA;EACAC,MAAAA;EACAC,WAAAA;EACAC,QAAAA;EACAC,iBAAAA;EACAC,gBAAAA;EACAC,KAAAA;AAAAA"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { SkillDeliveryError } from "./errors.mjs";
|
|
2
|
+
import { CopilotKitIntelligence } from "@copilotkit/runtime/v2";
|
|
3
|
+
|
|
4
|
+
//#region ../intelligence-delivery-core/dist/config.mjs
|
|
5
|
+
/** Resolve once. Never retain the options object, environment, or a second key. */
|
|
6
|
+
function resolveRegistryConfig(options = {}, environment = process.env) {
|
|
7
|
+
try {
|
|
8
|
+
const containerId = options.containerId ?? environment.CPK_INTELLIGENCE_LEARNING_CONTAINER_ID;
|
|
9
|
+
const revision = options.revision ?? environment.CPK_INTELLIGENCE_SKILLS_REVISION;
|
|
10
|
+
const freshnessWindowMs = options.freshnessWindowMs ?? 5e3;
|
|
11
|
+
const requestTimeoutMs = options.requestTimeoutMs ?? 5e3;
|
|
12
|
+
const debug = options.debug ?? false;
|
|
13
|
+
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 SkillDeliveryError("INVALID_CONFIG", false);
|
|
14
|
+
let client = options.client;
|
|
15
|
+
if (client !== void 0) {
|
|
16
|
+
if (!client || typeof client.getLearnedSkillsSnapshot !== "function") throw new SkillDeliveryError("INVALID_CONFIG", false);
|
|
17
|
+
} else {
|
|
18
|
+
const apiKey = options.apiKey ?? environment.CPK_INTELLIGENCE_API_KEY;
|
|
19
|
+
const apiUrl = options.apiUrl ?? environment.INTELLIGENCE_API_URL;
|
|
20
|
+
if (typeof apiKey !== "string" || !apiKey.trim()) throw new SkillDeliveryError("INVALID_CONFIG", false);
|
|
21
|
+
if (apiUrl?.trim()) {
|
|
22
|
+
const url = new URL(apiUrl);
|
|
23
|
+
if (!["http:", "https:"].includes(url.protocol) || url.username || url.password || url.search || url.hash) throw new SkillDeliveryError("INVALID_CONFIG", false);
|
|
24
|
+
}
|
|
25
|
+
client = new CopilotKitIntelligence({
|
|
26
|
+
apiKey,
|
|
27
|
+
...apiUrl !== void 0 ? { apiUrl } : {},
|
|
28
|
+
...apiUrl?.trim() ? { wsUrl: "wss://realtime.intelligence.copilotkit.ai" } : {}
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
return Object.freeze({
|
|
32
|
+
client,
|
|
33
|
+
containerId,
|
|
34
|
+
...revision !== void 0 ? { revision } : {},
|
|
35
|
+
freshnessWindowMs,
|
|
36
|
+
requestTimeoutMs,
|
|
37
|
+
debug
|
|
38
|
+
});
|
|
39
|
+
} catch (error) {
|
|
40
|
+
if (error instanceof SkillDeliveryError) throw error;
|
|
41
|
+
throw new SkillDeliveryError("INVALID_CONFIG", false, error);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
//#endregion
|
|
46
|
+
export { resolveRegistryConfig };
|
|
47
|
+
//# sourceMappingURL=config.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.mjs","names":[],"sources":["../../../../intelligence-delivery-core/dist/config.mjs"],"sourcesContent":["import { SkillDeliveryError } from \"./errors.mjs\";\nimport { CopilotKitIntelligence } from \"@copilotkit/runtime/v2\";\n\n//#region src/config.ts\n/** Resolve once. Never retain the options object, environment, or a second key. */\nfunction resolveRegistryConfig(options = {}, environment = process.env) {\n\ttry {\n\t\tconst containerId = options.containerId ?? environment.CPK_INTELLIGENCE_LEARNING_CONTAINER_ID;\n\t\tconst revision = options.revision ?? environment.CPK_INTELLIGENCE_SKILLS_REVISION;\n\t\tconst freshnessWindowMs = options.freshnessWindowMs ?? 5e3;\n\t\tconst requestTimeoutMs = options.requestTimeoutMs ?? 5e3;\n\t\tconst debug = options.debug ?? false;\n\t\tif (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 SkillDeliveryError(\"INVALID_CONFIG\", false);\n\t\tlet client = options.client;\n\t\tif (client !== void 0) {\n\t\t\tif (!client || typeof client.getLearnedSkillsSnapshot !== \"function\") throw new SkillDeliveryError(\"INVALID_CONFIG\", false);\n\t\t} else {\n\t\t\tconst apiKey = options.apiKey ?? environment.CPK_INTELLIGENCE_API_KEY;\n\t\t\tconst apiUrl = options.apiUrl ?? environment.INTELLIGENCE_API_URL;\n\t\t\tif (typeof apiKey !== \"string\" || !apiKey.trim()) throw new SkillDeliveryError(\"INVALID_CONFIG\", false);\n\t\t\tif (apiUrl?.trim()) {\n\t\t\t\tconst url = new URL(apiUrl);\n\t\t\t\tif (![\"http:\", \"https:\"].includes(url.protocol) || url.username || url.password || url.search || url.hash) throw new SkillDeliveryError(\"INVALID_CONFIG\", false);\n\t\t\t}\n\t\t\tclient = new CopilotKitIntelligence({\n\t\t\t\tapiKey,\n\t\t\t\t...apiUrl !== void 0 ? { apiUrl } : {},\n\t\t\t\t...apiUrl?.trim() ? { wsUrl: \"wss://realtime.intelligence.copilotkit.ai\" } : {}\n\t\t\t});\n\t\t}\n\t\treturn Object.freeze({\n\t\t\tclient,\n\t\t\tcontainerId,\n\t\t\t...revision !== void 0 ? { revision } : {},\n\t\t\tfreshnessWindowMs,\n\t\t\trequestTimeoutMs,\n\t\t\tdebug\n\t\t});\n\t} catch (error) {\n\t\tif (error instanceof SkillDeliveryError) throw error;\n\t\tthrow new SkillDeliveryError(\"INVALID_CONFIG\", false, error);\n\t}\n}\n\n//#endregion\nexport { resolveRegistryConfig };\n//# sourceMappingURL=config.mjs.map"],"mappings":";;;;;AAKA,SAAS,sBAAsB,UAAU,EAAE,EAAE,cAAc,QAAQ,KAAK;AACvE,KAAI;EACH,MAAM,cAAc,QAAQ,eAAe,YAAY;EACvD,MAAM,WAAW,QAAQ,YAAY,YAAY;EACjD,MAAM,oBAAoB,QAAQ,qBAAqB;EACvD,MAAM,mBAAmB,QAAQ,oBAAoB;EACrD,MAAM,QAAQ,QAAQ,SAAS;AAC/B,MAAI,OAAO,gBAAgB,YAAY,CAAC,YAAY,MAAM,IAAI,aAAa,KAAK,MAAM,OAAO,aAAa,YAAY,SAAS,WAAW,MAAM,CAAC,OAAO,cAAc,kBAAkB,IAAI,oBAAoB,KAAK,CAAC,OAAO,cAAc,iBAAiB,IAAI,mBAAmB,KAAK,mBAAmB,cAAc,OAAO,UAAU,UAAW,OAAM,IAAI,mBAAmB,kBAAkB,MAAM;EAC1Y,IAAI,SAAS,QAAQ;AACrB,MAAI,WAAW,KAAK,GACnB;OAAI,CAAC,UAAU,OAAO,OAAO,6BAA6B,WAAY,OAAM,IAAI,mBAAmB,kBAAkB,MAAM;SACrH;GACN,MAAM,SAAS,QAAQ,UAAU,YAAY;GAC7C,MAAM,SAAS,QAAQ,UAAU,YAAY;AAC7C,OAAI,OAAO,WAAW,YAAY,CAAC,OAAO,MAAM,CAAE,OAAM,IAAI,mBAAmB,kBAAkB,MAAM;AACvG,OAAI,QAAQ,MAAM,EAAE;IACnB,MAAM,MAAM,IAAI,IAAI,OAAO;AAC3B,QAAI,CAAC,CAAC,SAAS,SAAS,CAAC,SAAS,IAAI,SAAS,IAAI,IAAI,YAAY,IAAI,YAAY,IAAI,UAAU,IAAI,KAAM,OAAM,IAAI,mBAAmB,kBAAkB,MAAM;;AAEjK,YAAS,IAAI,uBAAuB;IACnC;IACA,GAAG,WAAW,KAAK,IAAI,EAAE,QAAQ,GAAG,EAAE;IACtC,GAAG,QAAQ,MAAM,GAAG,EAAE,OAAO,6CAA6C,GAAG,EAAE;IAC/E,CAAC;;AAEH,SAAO,OAAO,OAAO;GACpB;GACA;GACA,GAAG,aAAa,KAAK,IAAI,EAAE,UAAU,GAAG,EAAE;GAC1C;GACA;GACA;GACA,CAAC;UACM,OAAO;AACf,MAAI,iBAAiB,mBAAoB,OAAM;AAC/C,QAAM,IAAI,mBAAmB,kBAAkB,OAAO,MAAM"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
let _copilotkit_runtime_v2 = require("@copilotkit/runtime/v2");
|
|
2
|
+
|
|
3
|
+
//#region ../intelligence-delivery-core/dist/errors.mjs
|
|
4
|
+
function invalidSnapshot(cause) {
|
|
5
|
+
return new _copilotkit_runtime_v2.LearnedSkillsError("INVALID_SNAPSHOT", false, cause);
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
//#endregion
|
|
9
|
+
exports.invalidSnapshot = invalidSnapshot;
|
|
10
|
+
//# sourceMappingURL=errors.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.cjs","names":["LearnedSkillsError"],"sources":["../../../../intelligence-delivery-core/dist/errors.mjs"],"sourcesContent":["import { LearnedSkillsError, LearnedSkillsError as SkillDeliveryError } from \"@copilotkit/runtime/v2\";\n\n//#region src/errors.ts\nfunction invalidSnapshot(cause) {\n\treturn new LearnedSkillsError(\"INVALID_SNAPSHOT\", false, cause);\n}\n\n//#endregion\nexport { SkillDeliveryError, invalidSnapshot };\n//# sourceMappingURL=errors.mjs.map"],"mappings":";;;AAGA,SAAS,gBAAgB,OAAO;AAC/B,QAAO,IAAIA,0CAAmB,oBAAoB,OAAO,MAAM"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { LearnedSkillsError, LearnedSkillsError as SkillDeliveryError } from "@copilotkit/runtime/v2";
|
|
2
|
+
|
|
3
|
+
//#region ../intelligence-delivery-core/dist/errors.mjs
|
|
4
|
+
function invalidSnapshot(cause) {
|
|
5
|
+
return new LearnedSkillsError("INVALID_SNAPSHOT", false, cause);
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
//#endregion
|
|
9
|
+
export { SkillDeliveryError, invalidSnapshot };
|
|
10
|
+
//# sourceMappingURL=errors.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.mjs","names":[],"sources":["../../../../intelligence-delivery-core/dist/errors.mjs"],"sourcesContent":["import { LearnedSkillsError, LearnedSkillsError as SkillDeliveryError } from \"@copilotkit/runtime/v2\";\n\n//#region src/errors.ts\nfunction invalidSnapshot(cause) {\n\treturn new LearnedSkillsError(\"INVALID_SNAPSHOT\", false, cause);\n}\n\n//#endregion\nexport { SkillDeliveryError, invalidSnapshot };\n//# sourceMappingURL=errors.mjs.map"],"mappings":";;;AAGA,SAAS,gBAAgB,OAAO;AAC/B,QAAO,IAAI,mBAAmB,oBAAoB,OAAO,MAAM"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
const require_errors = require('./errors.cjs');
|
|
2
|
+
const require_archive = require('./archive.cjs');
|
|
3
|
+
const require_config = require('./config.cjs');
|
|
4
|
+
const require_snapshot = require('./snapshot.cjs');
|
|
5
|
+
const require_registry = require('./registry.cjs');
|
|
6
|
+
const require_skill_content = require('./skill-content.cjs');
|
|
7
|
+
let _copilotkit_runtime_v2 = require("@copilotkit/runtime/v2");
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { SkillRegistryOptions } from "./config.mjs";
|
|
2
|
+
import { SkillDeliveryError, SkillDeliveryErrorCode } from "./errors.mjs";
|
|
3
|
+
import { SnapshotFile, SnapshotSkill, VerifiedSnapshot } from "./snapshot.mjs";
|
|
4
|
+
import { SkillRegistry, SkillRegistryStatus } from "./registry.mjs";
|
|
5
|
+
import "./skill-content.mjs";
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { SkillDeliveryError, invalidSnapshot } from "./errors.mjs";
|
|
2
|
+
import { MAX_ARCHIVE_ENTRIES, MAX_SNAPSHOT_BYTES, readArchive, safeRelativePath } from "./archive.mjs";
|
|
3
|
+
import { resolveRegistryConfig } from "./config.mjs";
|
|
4
|
+
import { validateSnapshot } from "./snapshot.mjs";
|
|
5
|
+
import { SkillRegistry } from "./registry.mjs";
|
|
6
|
+
import { formatSkillCatalog, loadSkill, readSkillFile } from "./skill-content.mjs";
|
|
7
|
+
|
|
8
|
+
export { };
|