@acontext/acontext 0.1.12 → 0.1.14

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/dist/errors.d.ts CHANGED
@@ -30,3 +30,9 @@ export declare class APIError extends AcontextError {
30
30
  export declare class TransportError extends AcontextError {
31
31
  constructor(message: string);
32
32
  }
33
+ /**
34
+ * Raised when a polling operation exceeds the configured timeout.
35
+ */
36
+ export declare class TimeoutError extends AcontextError {
37
+ constructor(message?: string);
38
+ }
package/dist/errors.js CHANGED
@@ -3,7 +3,7 @@
3
3
  * Custom exceptions raised by the acontext TypeScript client.
4
4
  */
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.TransportError = exports.APIError = exports.AcontextError = void 0;
6
+ exports.TimeoutError = exports.TransportError = exports.APIError = exports.AcontextError = void 0;
7
7
  /**
8
8
  * Base exception for all errors raised by `acontext`.
9
9
  */
@@ -43,3 +43,14 @@ class TransportError extends AcontextError {
43
43
  }
44
44
  }
45
45
  exports.TransportError = TransportError;
46
+ /**
47
+ * Raised when a polling operation exceeds the configured timeout.
48
+ */
49
+ class TimeoutError extends AcontextError {
50
+ constructor(message = 'operation timed out') {
51
+ super(message);
52
+ this.name = 'TimeoutError';
53
+ Object.setPrototypeOf(this, TimeoutError.prototype);
54
+ }
55
+ }
56
+ exports.TimeoutError = TimeoutError;
package/dist/index.d.ts CHANGED
@@ -5,7 +5,7 @@ export { AcontextClient } from './client';
5
5
  export type { AcontextClientOptions } from './client';
6
6
  export { FileUpload } from './uploads';
7
7
  export { MessagePart, AcontextMessage, buildAcontextMessage } from './messages';
8
- export { APIError, TransportError, AcontextError } from './errors';
8
+ export { APIError, TransportError, AcontextError, TimeoutError } from './errors';
9
9
  export * from './types';
10
10
  export * from './resources';
11
11
  export * from './agent';
package/dist/index.js CHANGED
@@ -17,7 +17,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
17
17
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
18
18
  };
19
19
  Object.defineProperty(exports, "__esModule", { value: true });
20
- exports.AcontextError = exports.TransportError = exports.APIError = exports.buildAcontextMessage = exports.AcontextMessage = exports.MessagePart = exports.FileUpload = exports.AcontextClient = void 0;
20
+ exports.TimeoutError = exports.AcontextError = exports.TransportError = exports.APIError = exports.buildAcontextMessage = exports.AcontextMessage = exports.MessagePart = exports.FileUpload = exports.AcontextClient = void 0;
21
21
  var client_1 = require("./client");
22
22
  Object.defineProperty(exports, "AcontextClient", { enumerable: true, get: function () { return client_1.AcontextClient; } });
23
23
  var uploads_1 = require("./uploads");
@@ -30,6 +30,7 @@ var errors_1 = require("./errors");
30
30
  Object.defineProperty(exports, "APIError", { enumerable: true, get: function () { return errors_1.APIError; } });
31
31
  Object.defineProperty(exports, "TransportError", { enumerable: true, get: function () { return errors_1.TransportError; } });
32
32
  Object.defineProperty(exports, "AcontextError", { enumerable: true, get: function () { return errors_1.AcontextError; } });
33
+ Object.defineProperty(exports, "TimeoutError", { enumerable: true, get: function () { return errors_1.TimeoutError; } });
33
34
  __exportStar(require("./types"), exports);
34
35
  __exportStar(require("./resources"), exports);
35
36
  __exportStar(require("./agent"), exports);
@@ -44,6 +44,22 @@ export declare class LearningSpacesAPI {
44
44
  spaceId: string;
45
45
  sessionId: string;
46
46
  }): Promise<LearningSpaceSession>;
47
+ /**
48
+ * Get a single learning session record by session ID.
49
+ */
50
+ getSession(options: {
51
+ spaceId: string;
52
+ sessionId: string;
53
+ }): Promise<LearningSpaceSession>;
54
+ /**
55
+ * Poll until a learning session reaches a terminal status.
56
+ */
57
+ waitForLearning(options: {
58
+ spaceId: string;
59
+ sessionId: string;
60
+ timeout?: number;
61
+ pollInterval?: number;
62
+ }): Promise<LearningSpaceSession>;
47
63
  /**
48
64
  * List all learning session records for a space.
49
65
  */
@@ -4,6 +4,7 @@
4
4
  */
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.LearningSpacesAPI = void 0;
7
+ const errors_1 = require("../errors");
7
8
  const utils_1 = require("../utils");
8
9
  const types_1 = require("../types");
9
10
  class LearningSpacesAPI {
@@ -74,6 +75,36 @@ class LearningSpacesAPI {
74
75
  const data = await this.requester.request('POST', `/learning_spaces/${options.spaceId}/learn`, { jsonData: { session_id: options.sessionId } });
75
76
  return types_1.LearningSpaceSessionSchema.parse(data);
76
77
  }
78
+ /**
79
+ * Get a single learning session record by session ID.
80
+ */
81
+ async getSession(options) {
82
+ const data = await this.requester.request('GET', `/learning_spaces/${options.spaceId}/sessions/${options.sessionId}`);
83
+ return types_1.LearningSpaceSessionSchema.parse(data);
84
+ }
85
+ /**
86
+ * Poll until a learning session reaches a terminal status.
87
+ */
88
+ async waitForLearning(options) {
89
+ const timeout = options.timeout ?? 120;
90
+ const pollInterval = options.pollInterval ?? 1;
91
+ const terminal = new Set(['completed', 'failed']);
92
+ const deadline = Date.now() + timeout * 1000;
93
+ while (true) {
94
+ const session = await this.getSession({
95
+ spaceId: options.spaceId,
96
+ sessionId: options.sessionId,
97
+ });
98
+ if (terminal.has(session.status)) {
99
+ return session;
100
+ }
101
+ if (Date.now() >= deadline) {
102
+ throw new errors_1.TimeoutError(`learning session ${options.sessionId} did not complete within ${timeout}s ` +
103
+ `(last status: ${session.status})`);
104
+ }
105
+ await new Promise((resolve) => setTimeout(resolve, pollInterval * 1000));
106
+ }
107
+ }
77
108
  /**
78
109
  * List all learning session records for a space.
79
110
  */
@@ -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.12",
3
+ "version": "0.1.14",
4
4
  "description": "TypeScript SDK for the Acontext API",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",