@nimblebrain/mpak-sdk 0.1.0 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,292 @@
1
+ import { VersionDetail, DownloadInfo, VersionsResponse, PlatformInfo, FullProvenance, SkillSummary, SkillDetail, BundleSearchResponse, BundleDetail, SkillSearchResponse, SkillDownloadInfo } from '@nimblebrain/mpak-schemas';
2
+ export { Bundle, BundleDetail, BundleDetail as BundleDetailResponse, DownloadInfo as BundleDownloadResponse, BundleSearchResponse, VersionDetail as BundleVersionResponse, VersionsResponse as BundleVersionsResponse, Pagination, SkillDetail, SkillDetail as SkillDetailResponse, SkillDownloadInfo, SkillDownloadInfo as SkillDownloadResponse, SkillSearchResponse } from '@nimblebrain/mpak-schemas';
3
+
4
+ /**
5
+ * SDK-specific type definitions for mpak SDK
6
+ *
7
+ * API response types are re-exported from @nimblebrain/mpak-schemas.
8
+ * This file contains SDK-specific types (client config, skill references, etc.)
9
+ */
10
+
11
+ /** Version in versions listing */
12
+ type BundleVersion = VersionsResponse['versions'][number];
13
+ /** Artifact in version detail */
14
+ type BundleArtifact = VersionDetail['artifacts'][number];
15
+ /** Download info alias */
16
+ type BundleDownloadInfo = DownloadInfo;
17
+ /** Skill summary in search results */
18
+ type Skill = SkillSummary;
19
+
20
+ /** Skill version in detail */
21
+ type SkillVersion = SkillDetail['versions'][number];
22
+ /** Platform identifier (os + arch) */
23
+ type Platform = PlatformInfo;
24
+
25
+ /** Provenance information for verified packages */
26
+ type Provenance = FullProvenance;
27
+ /** Author information */
28
+ interface Author {
29
+ name: string;
30
+ url?: string;
31
+ email?: string;
32
+ }
33
+ /** Query parameters for bundle search */
34
+ interface BundleSearchParams {
35
+ q?: string;
36
+ type?: string;
37
+ sort?: 'downloads' | 'recent' | 'name';
38
+ limit?: number;
39
+ offset?: number;
40
+ }
41
+ /** Query parameters for skill search */
42
+ interface SkillSearchParams {
43
+ q?: string;
44
+ tags?: string;
45
+ category?: string;
46
+ surface?: string;
47
+ sort?: 'downloads' | 'recent' | 'name';
48
+ limit?: number;
49
+ offset?: number;
50
+ }
51
+ /**
52
+ * Configuration options for MpakClient
53
+ */
54
+ interface MpakClientConfig {
55
+ /**
56
+ * Base URL for the mpak registry API
57
+ * @default 'https://registry.mpak.dev'
58
+ */
59
+ registryUrl?: string;
60
+ /**
61
+ * Request timeout in milliseconds
62
+ * @default 30000
63
+ */
64
+ timeout?: number;
65
+ /**
66
+ * User-Agent string sent with every request
67
+ * @example 'mpak-cli/0.2.0'
68
+ */
69
+ userAgent?: string;
70
+ }
71
+ /**
72
+ * Base fields shared by all skill reference types
73
+ */
74
+ interface SkillReferenceBase {
75
+ /** Skill artifact identifier (e.g., '@nimbletools/folk-crm') */
76
+ name: string;
77
+ /** Semver version (e.g., '1.0.0') or 'latest' */
78
+ version: string;
79
+ /** SHA256 integrity hash (format: 'sha256-hexdigest') */
80
+ integrity?: string;
81
+ }
82
+ /**
83
+ * Skill reference from mpak registry
84
+ */
85
+ interface MpakSkillReference extends SkillReferenceBase {
86
+ source: 'mpak';
87
+ }
88
+ /**
89
+ * Skill reference from GitHub repository
90
+ */
91
+ interface GithubSkillReference extends SkillReferenceBase {
92
+ source: 'github';
93
+ /** GitHub repository (owner/repo) */
94
+ repo: string;
95
+ /** Path to skill file in repo */
96
+ path: string;
97
+ }
98
+ /**
99
+ * Skill reference from direct URL
100
+ */
101
+ interface UrlSkillReference extends SkillReferenceBase {
102
+ source: 'url';
103
+ /** Direct download URL */
104
+ url: string;
105
+ }
106
+ /**
107
+ * Discriminated union of skill reference types
108
+ */
109
+ type SkillReference = MpakSkillReference | GithubSkillReference | UrlSkillReference;
110
+ /**
111
+ * Result of resolving a skill reference
112
+ */
113
+ interface ResolvedSkill {
114
+ /** The markdown content of the skill */
115
+ content: string;
116
+ /** Version that was resolved */
117
+ version: string;
118
+ /** Source the skill was fetched from */
119
+ source: 'mpak' | 'github' | 'url';
120
+ /** Whether integrity was verified */
121
+ verified: boolean;
122
+ }
123
+
124
+ /**
125
+ * Client for interacting with the mpak registry
126
+ *
127
+ * Requires Node.js 18+ for native fetch support.
128
+ * Uses jszip for skill bundle extraction.
129
+ */
130
+ declare class MpakClient {
131
+ private readonly registryUrl;
132
+ private readonly timeout;
133
+ private readonly userAgent;
134
+ constructor(config?: MpakClientConfig);
135
+ /**
136
+ * Search for bundles
137
+ */
138
+ searchBundles(params?: BundleSearchParams): Promise<BundleSearchResponse>;
139
+ /**
140
+ * Get bundle details
141
+ */
142
+ getBundle(name: string): Promise<BundleDetail>;
143
+ /**
144
+ * Get all versions of a bundle
145
+ */
146
+ getBundleVersions(name: string): Promise<VersionsResponse>;
147
+ /**
148
+ * Get a specific version of a bundle
149
+ */
150
+ getBundleVersion(name: string, version: string): Promise<VersionDetail>;
151
+ /**
152
+ * Get download info for a bundle
153
+ */
154
+ getBundleDownload(name: string, version: string, platform?: Platform): Promise<DownloadInfo>;
155
+ /**
156
+ * Search for skills
157
+ */
158
+ searchSkills(params?: SkillSearchParams): Promise<SkillSearchResponse>;
159
+ /**
160
+ * Get skill details
161
+ */
162
+ getSkill(name: string): Promise<SkillDetail>;
163
+ /**
164
+ * Get download info for a skill (latest version)
165
+ */
166
+ getSkillDownload(name: string): Promise<SkillDownloadInfo>;
167
+ /**
168
+ * Get download info for a specific skill version
169
+ */
170
+ getSkillVersionDownload(name: string, version: string): Promise<SkillDownloadInfo>;
171
+ /**
172
+ * Download skill content and verify integrity
173
+ *
174
+ * @throws {MpakIntegrityError} If expectedSha256 is provided and doesn't match (fail-closed)
175
+ */
176
+ downloadSkillContent(downloadUrl: string, expectedSha256?: string): Promise<{
177
+ content: string;
178
+ verified: boolean;
179
+ }>;
180
+ /**
181
+ * Resolve a skill reference to actual content
182
+ *
183
+ * Supports mpak, github, and url sources. This is the main method for
184
+ * fetching skill content from any supported source.
185
+ *
186
+ * @throws {MpakNotFoundError} If skill not found
187
+ * @throws {MpakIntegrityError} If integrity check fails (fail-closed)
188
+ * @throws {MpakNetworkError} For network failures
189
+ *
190
+ * @example
191
+ * ```typescript
192
+ * // Resolve from mpak registry
193
+ * const skill = await client.resolveSkillRef({
194
+ * source: 'mpak',
195
+ * name: '@nimblebraininc/folk-crm',
196
+ * version: '1.3.0',
197
+ * });
198
+ *
199
+ * // Resolve from GitHub
200
+ * const skill = await client.resolveSkillRef({
201
+ * source: 'github',
202
+ * name: '@example/my-skill',
203
+ * version: 'v1.0.0',
204
+ * repo: 'owner/repo',
205
+ * path: 'skills/my-skill/SKILL.md',
206
+ * });
207
+ *
208
+ * // Resolve from URL
209
+ * const skill = await client.resolveSkillRef({
210
+ * source: 'url',
211
+ * name: '@example/custom',
212
+ * version: '1.0.0',
213
+ * url: 'https://example.com/skill.md',
214
+ * });
215
+ * ```
216
+ */
217
+ resolveSkillRef(ref: SkillReference): Promise<ResolvedSkill>;
218
+ /**
219
+ * Resolve a skill from mpak registry
220
+ *
221
+ * The API returns a ZIP bundle containing SKILL.md and metadata.
222
+ */
223
+ private resolveMpakSkill;
224
+ /**
225
+ * Resolve a skill from GitHub releases
226
+ */
227
+ private resolveGithubSkill;
228
+ /**
229
+ * Resolve a skill from a direct URL
230
+ */
231
+ private resolveUrlSkill;
232
+ /**
233
+ * Extract SKILL.md content from a skill bundle ZIP
234
+ */
235
+ private extractSkillFromZip;
236
+ /**
237
+ * Verify content integrity and throw if mismatch (fail-closed)
238
+ */
239
+ private verifyIntegrityOrThrow;
240
+ /**
241
+ * Extract hash from integrity string (removes prefix)
242
+ */
243
+ private extractHash;
244
+ /**
245
+ * Detect the current platform
246
+ */
247
+ static detectPlatform(): Platform;
248
+ /**
249
+ * Compute SHA256 hash of content
250
+ */
251
+ private computeSha256;
252
+ /**
253
+ * Validate that a name is scoped (@scope/name)
254
+ */
255
+ private validateScopedName;
256
+ /**
257
+ * Fetch with timeout support
258
+ */
259
+ private fetchWithTimeout;
260
+ }
261
+
262
+ /**
263
+ * Base error class for mpak SDK errors
264
+ */
265
+ declare class MpakError extends Error {
266
+ code: string;
267
+ statusCode: number | undefined;
268
+ constructor(message: string, code: string, statusCode?: number);
269
+ }
270
+ /**
271
+ * Thrown when a requested resource is not found (404)
272
+ */
273
+ declare class MpakNotFoundError extends MpakError {
274
+ constructor(resource: string);
275
+ }
276
+ /**
277
+ * Thrown when integrity verification fails (hash mismatch)
278
+ * This is a fail-closed error - content is NOT returned when this is thrown
279
+ */
280
+ declare class MpakIntegrityError extends MpakError {
281
+ expected: string;
282
+ actual: string;
283
+ constructor(expected: string, actual: string);
284
+ }
285
+ /**
286
+ * Thrown for network-related failures (timeouts, connection errors)
287
+ */
288
+ declare class MpakNetworkError extends MpakError {
289
+ constructor(message: string);
290
+ }
291
+
292
+ export { type Author, type BundleArtifact, type BundleDownloadInfo, type BundleSearchParams, type BundleVersion, type GithubSkillReference, MpakClient, type MpakClientConfig, MpakError, MpakIntegrityError, MpakNetworkError, MpakNotFoundError, type MpakSkillReference, type Platform, type Provenance, type ResolvedSkill, type Skill, type SkillReference, type SkillSearchParams, type SkillVersion, type UrlSkillReference };
package/dist/index.d.ts CHANGED
@@ -1,39 +1,292 @@
1
+ import { VersionDetail, DownloadInfo, VersionsResponse, PlatformInfo, FullProvenance, SkillSummary, SkillDetail, BundleSearchResponse, BundleDetail, SkillSearchResponse, SkillDownloadInfo } from '@nimblebrain/mpak-schemas';
2
+ export { Bundle, BundleDetail, BundleDetail as BundleDetailResponse, DownloadInfo as BundleDownloadResponse, BundleSearchResponse, VersionDetail as BundleVersionResponse, VersionsResponse as BundleVersionsResponse, Pagination, SkillDetail, SkillDetail as SkillDetailResponse, SkillDownloadInfo, SkillDownloadInfo as SkillDownloadResponse, SkillSearchResponse } from '@nimblebrain/mpak-schemas';
3
+
1
4
  /**
2
- * @nimblebrain/mpak-sdk
5
+ * SDK-specific type definitions for mpak SDK
3
6
  *
4
- * TypeScript SDK for mpak registry - MCPB bundles and Agent Skills
7
+ * API response types are re-exported from @nimblebrain/mpak-schemas.
8
+ * This file contains SDK-specific types (client config, skill references, etc.)
9
+ */
10
+
11
+ /** Version in versions listing */
12
+ type BundleVersion = VersionsResponse['versions'][number];
13
+ /** Artifact in version detail */
14
+ type BundleArtifact = VersionDetail['artifacts'][number];
15
+ /** Download info alias */
16
+ type BundleDownloadInfo = DownloadInfo;
17
+ /** Skill summary in search results */
18
+ type Skill = SkillSummary;
19
+
20
+ /** Skill version in detail */
21
+ type SkillVersion = SkillDetail['versions'][number];
22
+ /** Platform identifier (os + arch) */
23
+ type Platform = PlatformInfo;
24
+
25
+ /** Provenance information for verified packages */
26
+ type Provenance = FullProvenance;
27
+ /** Author information */
28
+ interface Author {
29
+ name: string;
30
+ url?: string;
31
+ email?: string;
32
+ }
33
+ /** Query parameters for bundle search */
34
+ interface BundleSearchParams {
35
+ q?: string;
36
+ type?: string;
37
+ sort?: 'downloads' | 'recent' | 'name';
38
+ limit?: number;
39
+ offset?: number;
40
+ }
41
+ /** Query parameters for skill search */
42
+ interface SkillSearchParams {
43
+ q?: string;
44
+ tags?: string;
45
+ category?: string;
46
+ surface?: string;
47
+ sort?: 'downloads' | 'recent' | 'name';
48
+ limit?: number;
49
+ offset?: number;
50
+ }
51
+ /**
52
+ * Configuration options for MpakClient
53
+ */
54
+ interface MpakClientConfig {
55
+ /**
56
+ * Base URL for the mpak registry API
57
+ * @default 'https://registry.mpak.dev'
58
+ */
59
+ registryUrl?: string;
60
+ /**
61
+ * Request timeout in milliseconds
62
+ * @default 30000
63
+ */
64
+ timeout?: number;
65
+ /**
66
+ * User-Agent string sent with every request
67
+ * @example 'mpak-cli/0.2.0'
68
+ */
69
+ userAgent?: string;
70
+ }
71
+ /**
72
+ * Base fields shared by all skill reference types
73
+ */
74
+ interface SkillReferenceBase {
75
+ /** Skill artifact identifier (e.g., '@nimbletools/folk-crm') */
76
+ name: string;
77
+ /** Semver version (e.g., '1.0.0') or 'latest' */
78
+ version: string;
79
+ /** SHA256 integrity hash (format: 'sha256-hexdigest') */
80
+ integrity?: string;
81
+ }
82
+ /**
83
+ * Skill reference from mpak registry
84
+ */
85
+ interface MpakSkillReference extends SkillReferenceBase {
86
+ source: 'mpak';
87
+ }
88
+ /**
89
+ * Skill reference from GitHub repository
90
+ */
91
+ interface GithubSkillReference extends SkillReferenceBase {
92
+ source: 'github';
93
+ /** GitHub repository (owner/repo) */
94
+ repo: string;
95
+ /** Path to skill file in repo */
96
+ path: string;
97
+ }
98
+ /**
99
+ * Skill reference from direct URL
100
+ */
101
+ interface UrlSkillReference extends SkillReferenceBase {
102
+ source: 'url';
103
+ /** Direct download URL */
104
+ url: string;
105
+ }
106
+ /**
107
+ * Discriminated union of skill reference types
108
+ */
109
+ type SkillReference = MpakSkillReference | GithubSkillReference | UrlSkillReference;
110
+ /**
111
+ * Result of resolving a skill reference
112
+ */
113
+ interface ResolvedSkill {
114
+ /** The markdown content of the skill */
115
+ content: string;
116
+ /** Version that was resolved */
117
+ version: string;
118
+ /** Source the skill was fetched from */
119
+ source: 'mpak' | 'github' | 'url';
120
+ /** Whether integrity was verified */
121
+ verified: boolean;
122
+ }
123
+
124
+ /**
125
+ * Client for interacting with the mpak registry
5
126
  *
6
127
  * Requires Node.js 18+ for native fetch support.
7
- *
8
- * @example
9
- * ```typescript
10
- * import { MpakClient, SkillReference } from '@nimblebrain/mpak-sdk';
11
- *
12
- * const client = new MpakClient();
13
- *
14
- * // Search for bundles
15
- * const bundles = await client.searchBundles({ q: 'mcp' });
16
- *
17
- * // Get bundle details
18
- * const bundle = await client.getBundle('@nimbletools/echo');
19
- *
20
- * // Search for skills
21
- * const skills = await client.searchSkills({ q: 'crm' });
22
- *
23
- * // Resolve a skill reference to content (recommended)
24
- * const ref: SkillReference = {
25
- * source: 'mpak',
26
- * name: '@nimblebraininc/folk-crm',
27
- * version: '1.3.0',
28
- * };
29
- * const resolved = await client.resolveSkillRef(ref);
30
- * console.log(resolved.content); // Skill markdown content
31
- * ```
32
- */
33
- export { MpakClient } from './client.js';
34
- export type { MpakClientConfig } from './types.js';
35
- export type { BundleSearchResponse, BundleDetailResponse, BundleVersionsResponse, BundleVersionResponse, BundleDownloadResponse, BundleIndexResponse, BundleSearchParams, Bundle, BundleDetail, BundleVersion, BundleArtifact, BundleDownloadInfo, } from './types.js';
36
- export type { SkillSearchResponse, SkillDetailResponse, SkillDownloadResponse, SkillSearchParams, Skill, SkillDetail, SkillDownloadInfo, SkillVersion, SkillReference, MpakSkillReference, GithubSkillReference, UrlSkillReference, ResolvedSkill, } from './types.js';
37
- export type { Platform, Pagination, Provenance, Author, } from './types.js';
38
- export { MpakError, MpakNotFoundError, MpakIntegrityError, MpakNetworkError, } from './errors.js';
39
- //# sourceMappingURL=index.d.ts.map
128
+ * Uses jszip for skill bundle extraction.
129
+ */
130
+ declare class MpakClient {
131
+ private readonly registryUrl;
132
+ private readonly timeout;
133
+ private readonly userAgent;
134
+ constructor(config?: MpakClientConfig);
135
+ /**
136
+ * Search for bundles
137
+ */
138
+ searchBundles(params?: BundleSearchParams): Promise<BundleSearchResponse>;
139
+ /**
140
+ * Get bundle details
141
+ */
142
+ getBundle(name: string): Promise<BundleDetail>;
143
+ /**
144
+ * Get all versions of a bundle
145
+ */
146
+ getBundleVersions(name: string): Promise<VersionsResponse>;
147
+ /**
148
+ * Get a specific version of a bundle
149
+ */
150
+ getBundleVersion(name: string, version: string): Promise<VersionDetail>;
151
+ /**
152
+ * Get download info for a bundle
153
+ */
154
+ getBundleDownload(name: string, version: string, platform?: Platform): Promise<DownloadInfo>;
155
+ /**
156
+ * Search for skills
157
+ */
158
+ searchSkills(params?: SkillSearchParams): Promise<SkillSearchResponse>;
159
+ /**
160
+ * Get skill details
161
+ */
162
+ getSkill(name: string): Promise<SkillDetail>;
163
+ /**
164
+ * Get download info for a skill (latest version)
165
+ */
166
+ getSkillDownload(name: string): Promise<SkillDownloadInfo>;
167
+ /**
168
+ * Get download info for a specific skill version
169
+ */
170
+ getSkillVersionDownload(name: string, version: string): Promise<SkillDownloadInfo>;
171
+ /**
172
+ * Download skill content and verify integrity
173
+ *
174
+ * @throws {MpakIntegrityError} If expectedSha256 is provided and doesn't match (fail-closed)
175
+ */
176
+ downloadSkillContent(downloadUrl: string, expectedSha256?: string): Promise<{
177
+ content: string;
178
+ verified: boolean;
179
+ }>;
180
+ /**
181
+ * Resolve a skill reference to actual content
182
+ *
183
+ * Supports mpak, github, and url sources. This is the main method for
184
+ * fetching skill content from any supported source.
185
+ *
186
+ * @throws {MpakNotFoundError} If skill not found
187
+ * @throws {MpakIntegrityError} If integrity check fails (fail-closed)
188
+ * @throws {MpakNetworkError} For network failures
189
+ *
190
+ * @example
191
+ * ```typescript
192
+ * // Resolve from mpak registry
193
+ * const skill = await client.resolveSkillRef({
194
+ * source: 'mpak',
195
+ * name: '@nimblebraininc/folk-crm',
196
+ * version: '1.3.0',
197
+ * });
198
+ *
199
+ * // Resolve from GitHub
200
+ * const skill = await client.resolveSkillRef({
201
+ * source: 'github',
202
+ * name: '@example/my-skill',
203
+ * version: 'v1.0.0',
204
+ * repo: 'owner/repo',
205
+ * path: 'skills/my-skill/SKILL.md',
206
+ * });
207
+ *
208
+ * // Resolve from URL
209
+ * const skill = await client.resolveSkillRef({
210
+ * source: 'url',
211
+ * name: '@example/custom',
212
+ * version: '1.0.0',
213
+ * url: 'https://example.com/skill.md',
214
+ * });
215
+ * ```
216
+ */
217
+ resolveSkillRef(ref: SkillReference): Promise<ResolvedSkill>;
218
+ /**
219
+ * Resolve a skill from mpak registry
220
+ *
221
+ * The API returns a ZIP bundle containing SKILL.md and metadata.
222
+ */
223
+ private resolveMpakSkill;
224
+ /**
225
+ * Resolve a skill from GitHub releases
226
+ */
227
+ private resolveGithubSkill;
228
+ /**
229
+ * Resolve a skill from a direct URL
230
+ */
231
+ private resolveUrlSkill;
232
+ /**
233
+ * Extract SKILL.md content from a skill bundle ZIP
234
+ */
235
+ private extractSkillFromZip;
236
+ /**
237
+ * Verify content integrity and throw if mismatch (fail-closed)
238
+ */
239
+ private verifyIntegrityOrThrow;
240
+ /**
241
+ * Extract hash from integrity string (removes prefix)
242
+ */
243
+ private extractHash;
244
+ /**
245
+ * Detect the current platform
246
+ */
247
+ static detectPlatform(): Platform;
248
+ /**
249
+ * Compute SHA256 hash of content
250
+ */
251
+ private computeSha256;
252
+ /**
253
+ * Validate that a name is scoped (@scope/name)
254
+ */
255
+ private validateScopedName;
256
+ /**
257
+ * Fetch with timeout support
258
+ */
259
+ private fetchWithTimeout;
260
+ }
261
+
262
+ /**
263
+ * Base error class for mpak SDK errors
264
+ */
265
+ declare class MpakError extends Error {
266
+ code: string;
267
+ statusCode: number | undefined;
268
+ constructor(message: string, code: string, statusCode?: number);
269
+ }
270
+ /**
271
+ * Thrown when a requested resource is not found (404)
272
+ */
273
+ declare class MpakNotFoundError extends MpakError {
274
+ constructor(resource: string);
275
+ }
276
+ /**
277
+ * Thrown when integrity verification fails (hash mismatch)
278
+ * This is a fail-closed error - content is NOT returned when this is thrown
279
+ */
280
+ declare class MpakIntegrityError extends MpakError {
281
+ expected: string;
282
+ actual: string;
283
+ constructor(expected: string, actual: string);
284
+ }
285
+ /**
286
+ * Thrown for network-related failures (timeouts, connection errors)
287
+ */
288
+ declare class MpakNetworkError extends MpakError {
289
+ constructor(message: string);
290
+ }
291
+
292
+ export { type Author, type BundleArtifact, type BundleDownloadInfo, type BundleSearchParams, type BundleVersion, type GithubSkillReference, MpakClient, type MpakClientConfig, MpakError, MpakIntegrityError, MpakNetworkError, MpakNotFoundError, type MpakSkillReference, type Platform, type Provenance, type ResolvedSkill, type Skill, type SkillReference, type SkillSearchParams, type SkillVersion, type UrlSkillReference };