@acontext/acontext 0.1.13 → 0.1.15

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/README.md CHANGED
@@ -10,4 +10,4 @@ npm install @acontext/acontext
10
10
 
11
11
  # 🔍 Document
12
12
 
13
- To understand more about this SDK, please view [our docs](https://docs.acontext.app/) and [api references](https://docs.acontext.app/api-reference/introduction)
13
+ To understand more about this SDK, please view [our docs](https://docs.acontext.io/) and [api references](https://docs.acontext.io/api-reference/introduction)
@@ -3,7 +3,7 @@
3
3
  */
4
4
  import { RequesterProtocol } from '../client-types';
5
5
  import { FileUpload } from '../uploads';
6
- import { DownloadSkillToSandboxResp, GetSkillFileResp, ListSkillsOutput, Skill } from '../types';
6
+ import { DownloadSkillResp, DownloadSkillToSandboxResp, GetSkillFileResp, ListSkillsOutput, Skill } from '../types';
7
7
  export declare class SkillsAPI {
8
8
  private requester;
9
9
  constructor(requester: RequesterProtocol);
@@ -54,6 +54,20 @@ export declare class SkillsAPI {
54
54
  filePath: string;
55
55
  expire?: number | null;
56
56
  }): Promise<GetSkillFileResp>;
57
+ /**
58
+ * Download all files from a skill to a local directory.
59
+ *
60
+ * Recursively downloads every file in the skill's file_index,
61
+ * preserving the directory structure.
62
+ *
63
+ * @param skillId - The UUID of the skill
64
+ * @param options - Download options
65
+ * @param options.path - Local directory path to download files into
66
+ * @returns DownloadSkillResp with skill name, description, resolved dirPath, and list of downloaded file paths
67
+ */
68
+ download(skillId: string, options: {
69
+ path: string;
70
+ }): Promise<DownloadSkillResp>;
57
71
  /**
58
72
  * Download all files from a skill to a sandbox environment.
59
73
  *
@@ -2,8 +2,43 @@
2
2
  /**
3
3
  * Skills endpoints.
4
4
  */
5
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ var desc = Object.getOwnPropertyDescriptor(m, k);
8
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
9
+ desc = { enumerable: true, get: function() { return m[k]; } };
10
+ }
11
+ Object.defineProperty(o, k2, desc);
12
+ }) : (function(o, m, k, k2) {
13
+ if (k2 === undefined) k2 = k;
14
+ o[k2] = m[k];
15
+ }));
16
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
17
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
18
+ }) : function(o, v) {
19
+ o["default"] = v;
20
+ });
21
+ var __importStar = (this && this.__importStar) || (function () {
22
+ var ownKeys = function(o) {
23
+ ownKeys = Object.getOwnPropertyNames || function (o) {
24
+ var ar = [];
25
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
26
+ return ar;
27
+ };
28
+ return ownKeys(o);
29
+ };
30
+ return function (mod) {
31
+ if (mod && mod.__esModule) return mod;
32
+ var result = {};
33
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
34
+ __setModuleDefault(result, mod);
35
+ return result;
36
+ };
37
+ })();
5
38
  Object.defineProperty(exports, "__esModule", { value: true });
6
39
  exports.SkillsAPI = void 0;
40
+ const fs = __importStar(require("fs/promises"));
41
+ const path = __importStar(require("path"));
7
42
  const uploads_1 = require("../uploads");
8
43
  const utils_1 = require("../utils");
9
44
  const types_1 = require("../types");
@@ -93,6 +128,46 @@ class SkillsAPI {
93
128
  });
94
129
  return types_1.GetSkillFileRespSchema.parse(data);
95
130
  }
131
+ /**
132
+ * Download all files from a skill to a local directory.
133
+ *
134
+ * Recursively downloads every file in the skill's file_index,
135
+ * preserving the directory structure.
136
+ *
137
+ * @param skillId - The UUID of the skill
138
+ * @param options - Download options
139
+ * @param options.path - Local directory path to download files into
140
+ * @returns DownloadSkillResp with skill name, description, resolved dirPath, and list of downloaded file paths
141
+ */
142
+ async download(skillId, options) {
143
+ const skill = await this.get(skillId);
144
+ const dest = path.resolve(options.path);
145
+ await fs.mkdir(dest, { recursive: true });
146
+ const downloaded = [];
147
+ for (const fi of skill.file_index) {
148
+ const resp = await this.getFile({ skillId, filePath: fi.path });
149
+ const fileDest = path.join(dest, fi.path);
150
+ await fs.mkdir(path.dirname(fileDest), { recursive: true });
151
+ if (resp.content) {
152
+ await fs.writeFile(fileDest, resp.content.raw, 'utf-8');
153
+ }
154
+ else if (resp.url) {
155
+ const r = await fetch(resp.url);
156
+ if (!r.ok) {
157
+ throw new Error(`Failed to download ${fi.path}: ${r.status} ${r.statusText}`);
158
+ }
159
+ const buffer = Buffer.from(await r.arrayBuffer());
160
+ await fs.writeFile(fileDest, buffer);
161
+ }
162
+ downloaded.push(fi.path);
163
+ }
164
+ return {
165
+ name: skill.name,
166
+ description: skill.description,
167
+ dirPath: dest,
168
+ files: downloaded,
169
+ };
170
+ }
96
171
  /**
97
172
  * Download all files from a skill to a sandbox environment.
98
173
  *
@@ -53,3 +53,10 @@ export declare const DownloadSkillToSandboxRespSchema: z.ZodObject<{
53
53
  description: z.ZodString;
54
54
  }, z.core.$strip>;
55
55
  export type DownloadSkillToSandboxResp = z.infer<typeof DownloadSkillToSandboxRespSchema>;
56
+ export declare const DownloadSkillRespSchema: z.ZodObject<{
57
+ name: z.ZodString;
58
+ description: z.ZodString;
59
+ dirPath: z.ZodString;
60
+ files: z.ZodArray<z.ZodString>;
61
+ }, z.core.$strip>;
62
+ export type DownloadSkillResp = z.infer<typeof DownloadSkillRespSchema>;
@@ -3,7 +3,7 @@
3
3
  * Type definitions for skill resources.
4
4
  */
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.DownloadSkillToSandboxRespSchema = exports.GetSkillFileRespSchema = exports.ListSkillsOutputSchema = exports.SkillCatalogItemSchema = exports.SkillSchema = exports.FileInfoSchema = void 0;
6
+ exports.DownloadSkillRespSchema = exports.DownloadSkillToSandboxRespSchema = exports.GetSkillFileRespSchema = exports.ListSkillsOutputSchema = exports.SkillCatalogItemSchema = exports.SkillSchema = exports.FileInfoSchema = void 0;
7
7
  const zod_1 = require("zod");
8
8
  const common_1 = require("./common");
9
9
  exports.FileInfoSchema = zod_1.z.object({
@@ -42,3 +42,9 @@ exports.DownloadSkillToSandboxRespSchema = zod_1.z.object({
42
42
  name: zod_1.z.string(),
43
43
  description: zod_1.z.string(),
44
44
  });
45
+ exports.DownloadSkillRespSchema = zod_1.z.object({
46
+ name: zod_1.z.string(),
47
+ description: zod_1.z.string(),
48
+ dirPath: zod_1.z.string(),
49
+ files: zod_1.z.array(zod_1.z.string()),
50
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@acontext/acontext",
3
- "version": "0.1.13",
3
+ "version": "0.1.15",
4
4
  "description": "TypeScript SDK for the Acontext API",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",