librebot-tools 0.0.0-stage → 0.4.5

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/src/index.d.ts ADDED
@@ -0,0 +1,271 @@
1
+ // Type definitions for librebot-tools (hand-written; no build step).
2
+ import type { ModelRoleId, RepoCapability, WhatsAppCapability } from "./contract.js";
3
+ export * from "./contract.js";
4
+
5
+ export interface SourceIssue {
6
+ file: string;
7
+ field: string;
8
+ message: string;
9
+ }
10
+
11
+ export interface ModelRequirements {
12
+ tools?: boolean;
13
+ vision?: boolean;
14
+ reasoning?: boolean;
15
+ minContextWindow?: number;
16
+ }
17
+
18
+ export interface BotModelRole {
19
+ role: ModelRoleId;
20
+ label: string;
21
+ requirements: ModelRequirements;
22
+ }
23
+
24
+ export interface BotKnowledge {
25
+ id: string;
26
+ name: string;
27
+ kind: "file" | "resource" | "repo";
28
+ content?: string;
29
+ url?: string;
30
+ ref?: string;
31
+ }
32
+ export interface BotSkill {
33
+ id: string;
34
+ name: string;
35
+ description: string;
36
+ content: string;
37
+ }
38
+
39
+ export interface BotConnector {
40
+ /** Deterministic parser-internal ID; not serialized or a platform UUID. */
41
+ id: string;
42
+ label: string;
43
+ description: string;
44
+ required: boolean;
45
+ tools: string[];
46
+ resources: Array<{ key: string; label: string; tools: string[] }>;
47
+ /** Remote MCP server identity (https URL). Local execution is unsupported. */
48
+ endpoint?: string;
49
+ }
50
+
51
+ export interface BotDraft {
52
+ name: string;
53
+ description: string;
54
+ botPrompt: string;
55
+ /** User-facing documentation from root README.md, separate from the prompt and knowledge. */
56
+ readme: string;
57
+ modelRoles: BotModelRole[];
58
+ knowledge: BotKnowledge[];
59
+ skills: BotSkill[];
60
+ connectors: BotConnector[];
61
+ triggers: Array<{ key: string; label: string; kind: "gitrepo" | "whatsapp"; eventTypes: string[]; description?: string; inputs?: Array<{ key: string; label?: string; type: "string" | "number" | "boolean" | "select"; required?: boolean; options?: string[]; help?: string }>; deciderRole?: ModelRoleId; deciderInstructions: string; enabledByDefault?: boolean }>;
62
+ workspace: Array<{ key: string; label?: string; path: string }>;
63
+ actions: Array<{ key: string; kind: "gitrepo"; label?: string; capabilities: RepoCapability[] } | { key: string; kind: "whatsapp"; label?: string; capabilities: WhatsAppCapability[] }>;
64
+ icon?: string;
65
+ }
66
+
67
+ export interface KnowledgeAsset {
68
+ knowledgeId: string;
69
+ path: string;
70
+ bytes: Uint8Array;
71
+ sha256: string;
72
+ size: number;
73
+ mime: string;
74
+ }
75
+
76
+ export interface SkillFile {
77
+ skillId: string;
78
+ path: string;
79
+ bytes: Uint8Array;
80
+ sha256: string;
81
+ size: number;
82
+ }
83
+
84
+ export interface SourceInventory {
85
+ botYaml: string;
86
+ instructions: string;
87
+ knowledgeFiles: string[];
88
+ skillDirs: string[];
89
+ lockPresent: boolean;
90
+ sourcesPresent: boolean;
91
+ }
92
+
93
+ export interface SkillLockEntry {
94
+ name: string;
95
+ repo: string;
96
+ resolvedSha?: string;
97
+ contentSha256?: string;
98
+ tarballSha256?: string;
99
+ skills: string[];
100
+ }
101
+
102
+ export interface SkillLock {
103
+ version: 1;
104
+ sourcesHash: string;
105
+ resolved: SkillLockEntry[];
106
+ vendorDirs: string[];
107
+ }
108
+
109
+ export interface IconAsset {
110
+ path: string;
111
+ bytes: Uint8Array;
112
+ mime: string;
113
+ sha256: string;
114
+ size: number;
115
+ width: number;
116
+ height: number;
117
+ }
118
+
119
+ export interface ParsedBotSource {
120
+ formatVersion: 1;
121
+ draft: BotDraft;
122
+ assets: KnowledgeAsset[];
123
+ icon?: IconAsset;
124
+ skillFiles: SkillFile[];
125
+ warnings: SourceIssue[];
126
+ source: SourceInventory;
127
+ lock: SkillLock | null;
128
+ }
129
+
130
+ export interface ValidationSuccess extends ParsedBotSource {
131
+ ok: true;
132
+ errors: SourceIssue[];
133
+ }
134
+
135
+ export interface ValidationFailure {
136
+ ok: false;
137
+ errors: SourceIssue[];
138
+ warnings: SourceIssue[];
139
+ }
140
+
141
+ export type ValidationResult = ValidationSuccess | ValidationFailure;
142
+
143
+ export class BotSourceError extends Error {
144
+ errors: SourceIssue[];
145
+ warnings: SourceIssue[];
146
+ constructor(errors: SourceIssue[], warnings?: SourceIssue[]);
147
+ }
148
+
149
+ export function parseBotFiles(
150
+ files: Record<string, Uint8Array | string>,
151
+ ): Promise<ParsedBotSource>;
152
+ export function parseBotSource(dir: string): Promise<ParsedBotSource>;
153
+ export function validateFiles(
154
+ files: Record<string, Uint8Array | string>,
155
+ ): Promise<ValidationResult>;
156
+ export function validateSource(dir: string): Promise<ValidationResult>;
157
+ export function readDirFiles(dir: string): Promise<Record<string, Uint8Array>>;
158
+ export function normalizeFileMap(
159
+ files: Record<string, Uint8Array | string>,
160
+ ): Map<string, Uint8Array>;
161
+ export function knowledgeIdFor(rel: string): string;
162
+ export function parseSkillFrontmatter(text: string): {
163
+ name?: string;
164
+ description?: string;
165
+ body: string;
166
+ };
167
+
168
+ export interface SkillRepo {
169
+ owner: string;
170
+ repo: string;
171
+ url: string;
172
+ source?: string;
173
+ }
174
+
175
+ export const LOCK_VERSION: 1;
176
+ export const SOURCES_VERSION: 1;
177
+ export const MAX_TARBALL_BYTES: number;
178
+ export const MAX_DECOMPRESSED_BYTES: number;
179
+
180
+ export function parseRepo(source: unknown): SkillRepo | null;
181
+ export function parseSourcesText(text: string): unknown;
182
+ export function serializeLock(lock: SkillLock): string;
183
+ export function sourcesHash(
184
+ sources: Array<{ name: string; repo: SkillRepo; ref?: string; skills: string[] }>,
185
+ ): string;
186
+ export function resolveSkillsLock(options: {
187
+ sources: {
188
+ sources: Array<{
189
+ name: string;
190
+ repo: SkillRepo;
191
+ ref?: string;
192
+ skills: string[];
193
+ }>;
194
+ };
195
+ existingLock?: SkillLock;
196
+ update?: boolean;
197
+ network?: boolean;
198
+ vendor?: boolean;
199
+ fetchImpl?: typeof fetch;
200
+ sourceBaseDir?: string;
201
+ currentFiles?: Record<string, Uint8Array>;
202
+ }): Promise<{
203
+ lock: SkillLock;
204
+ vendorFiles: Record<string, Uint8Array>;
205
+ errors: SourceIssue[];
206
+ warnings: SourceIssue[];
207
+ }>;
208
+ export function readTarEntries(buffer: Uint8Array): Array<{
209
+ name: string;
210
+ bytes: Uint8Array;
211
+ skipped: boolean;
212
+ }>;
213
+ export function fetchLockedSkills(
214
+ lock: SkillLock,
215
+ options?: { fetchImpl?: typeof fetch },
216
+ ): Promise<{ vendorFiles: Record<string, Uint8Array>; errors: SourceIssue[] }>;
217
+
218
+ export function scaffoldBotFiles(input: {
219
+ name: string;
220
+ description?: string;
221
+ }): Record<string, string>;
222
+ export function exportBotFiles(
223
+ draft: BotDraft,
224
+ options?: {
225
+ icon?: { bytes: Uint8Array };
226
+ assets?: KnowledgeAsset[];
227
+ skillFiles?: SkillFile[];
228
+ sourcesText?: string;
229
+ lockText?: string;
230
+ },
231
+ ): Record<string, string | Uint8Array>;
232
+ export function scaffoldBot(
233
+ dir: string,
234
+ input: { name: string; description?: string },
235
+ options?: { force?: boolean },
236
+ ): Promise<string[]>;
237
+ export function writeFiles(
238
+ dir: string,
239
+ files: Record<string, string | Uint8Array>,
240
+ ): Promise<string[]>;
241
+ export function exportKnowledgeFilename(item: {
242
+ id: string;
243
+ name?: string;
244
+ }): string;
245
+ export function sanitizePathSegment(segment: unknown, what: string): string;
246
+ export function sanitizeAssetRel(rel: unknown): string;
247
+ export function withSkillFrontmatter(skill: {
248
+ id: string;
249
+ name?: string;
250
+ description?: string;
251
+ content?: string;
252
+ }): string;
253
+
254
+ export const SCHEMA_VERSIONS: string[];
255
+ export function loadSchema(version?: string): Promise<Record<string, unknown>>;
256
+
257
+ export function toBytes(value: Uint8Array | string): Uint8Array;
258
+ export function sha256Hex(bytes: Uint8Array | string): string;
259
+ export function canonicalJson(value: unknown): string;
260
+
261
+ export function validateKnowledgeSources(
262
+ input: unknown,
263
+ sink: { errors: SourceIssue[]; warnings: SourceIssue[] },
264
+ file: string,
265
+ ): BotKnowledge[];
266
+ export function validateRequirements(
267
+ input: unknown,
268
+ field: string,
269
+ sink: { errors: SourceIssue[]; warnings: SourceIssue[] },
270
+ file: string,
271
+ ): ModelRequirements | undefined;
package/src/index.js ADDED
@@ -0,0 +1,57 @@
1
+ // Public entry point for librebot-tools.
2
+
3
+ export { BotSourceError } from "./errors.js";
4
+ export {
5
+ MAX_TEXT_KNOWLEDGE_BYTES,
6
+ MAX_SKILL_BYTES,
7
+ MAX_ASSET_BYTES,
8
+ MAX_DRAFT_BYTES,
9
+ MAX_FILES,
10
+ MAX_SKILL_FILES,
11
+ MAX_SKILL_FILE_BYTES,
12
+ knowledgeIdFor,
13
+ normalizeFileMap,
14
+ parseBotFiles,
15
+ parseBotSource,
16
+ parseSkillFrontmatter,
17
+ readDirFiles,
18
+ validateFiles,
19
+ validateSource,
20
+ } from "./parse.js";
21
+ export {
22
+ LOCK_VERSION,
23
+ SOURCES_VERSION,
24
+ MAX_TARBALL_BYTES,
25
+ MAX_DECOMPRESSED_BYTES,
26
+ checkSourcesLock,
27
+ extractVendorFiles,
28
+ fetchLockedSkills,
29
+ parseRepo,
30
+ parseSourcesText,
31
+ parseSourcesYaml,
32
+ readTarEntries,
33
+ resolveSkillsLock,
34
+ serializeLock,
35
+ sourcesHash,
36
+ } from "./skills-lock.js";
37
+ export {
38
+ exportBotFiles,
39
+ exportKnowledgeFilename,
40
+ sanitizeAssetRel,
41
+ sanitizePathSegment,
42
+ scaffoldBot,
43
+ scaffoldBotFiles,
44
+ withSkillFrontmatter,
45
+ writeFiles,
46
+ } from "./scaffold.js";
47
+ export { SCHEMA_VERSIONS, loadSchema } from "./schema.js";
48
+ export { canonicalJson, sha256Hex, toBytes } from "./util.js";
49
+ export {
50
+ FORMAT_VERSION,
51
+ MODEL_ROLES,
52
+ REPO_CAPABILITIES,
53
+ GITREPO_TRIGGER_EVENT_TYPES,
54
+ WHATSAPP_CAPABILITIES,
55
+ WHATSAPP_TRIGGER_EVENT_TYPES,
56
+ } from "./contract.js";
57
+ export { validateKnowledgeSources, validateRequirements } from "./validate.js";