@acontext/acontext 0.1.12 → 0.1.13

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
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@acontext/acontext",
3
- "version": "0.1.12",
3
+ "version": "0.1.13",
4
4
  "description": "TypeScript SDK for the Acontext API",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",