gopher-orch 0.1.0-20260131-081911

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,118 @@
1
+ /**
2
+ * GopherAgent - Main entry point for the gopher-orch TypeScript SDK.
3
+ *
4
+ * Provides a clean, TypeScript-friendly interface to the gopher-orch agent functionality.
5
+ *
6
+ * @example
7
+ * ```typescript
8
+ * // Create an agent with API key
9
+ * const agent = GopherAgent.create(
10
+ * GopherAgentConfig.builder()
11
+ * .provider('AnthropicProvider')
12
+ * .model('claude-3-haiku-20240307')
13
+ * .apiKey('your-api-key')
14
+ * .build()
15
+ * );
16
+ *
17
+ * // Run a query
18
+ * const answer = agent.run('What time is it in Tokyo?');
19
+ * console.log(answer);
20
+ *
21
+ * // Cleanup
22
+ * agent.dispose();
23
+ * ```
24
+ *
25
+ * @example
26
+ * ```typescript
27
+ * // Use try-finally for automatic cleanup
28
+ * const agent = GopherAgent.create(config);
29
+ * try {
30
+ * const answer = agent.run('What time is it in Tokyo?');
31
+ * console.log(answer);
32
+ * } finally {
33
+ * agent.dispose();
34
+ * }
35
+ * ```
36
+ */
37
+ import { GopherAgentConfig } from './config';
38
+ import { AgentResult } from './result';
39
+ /**
40
+ * Main agent class for interacting with the gopher-orch native library.
41
+ */
42
+ export declare class GopherAgent {
43
+ private handle;
44
+ private disposed;
45
+ private constructor();
46
+ /**
47
+ * Initialize the gopher-orch library.
48
+ *
49
+ * Must be called before creating any agents. Called automatically by create() if not already
50
+ * initialized.
51
+ *
52
+ * @throws {AgentError} if initialization fails
53
+ */
54
+ static init(): void;
55
+ /**
56
+ * Shutdown the gopher-orch library.
57
+ *
58
+ * Called automatically on process exit, but can be called manually.
59
+ */
60
+ static shutdown(): void;
61
+ /**
62
+ * Check if the library is initialized.
63
+ */
64
+ static isInitialized(): boolean;
65
+ /**
66
+ * Create a new GopherAgent instance.
67
+ *
68
+ * @param config Agent configuration
69
+ * @returns GopherAgent instance
70
+ * @throws {AgentError} if agent creation fails
71
+ */
72
+ static create(config: GopherAgentConfig): GopherAgent;
73
+ /**
74
+ * Create a new GopherAgent with API key.
75
+ *
76
+ * @param provider Provider name (e.g., "AnthropicProvider")
77
+ * @param model Model name (e.g., "claude-3-haiku-20240307")
78
+ * @param apiKey API key for fetching remote server config
79
+ * @returns GopherAgent instance
80
+ */
81
+ static createWithApiKey(provider: string, model: string, apiKey: string): GopherAgent;
82
+ /**
83
+ * Create a new GopherAgent with JSON server config.
84
+ *
85
+ * @param provider Provider name (e.g., "AnthropicProvider")
86
+ * @param model Model name (e.g., "claude-3-haiku-20240307")
87
+ * @param serverConfig JSON server configuration
88
+ * @returns GopherAgent instance
89
+ */
90
+ static createWithServerConfig(provider: string, model: string, serverConfig: string): GopherAgent;
91
+ /**
92
+ * Run a query against the agent.
93
+ *
94
+ * @param query The user query to process
95
+ * @param timeoutMs Timeout in milliseconds (default: 60000)
96
+ * @returns The agent's response
97
+ * @throws {AgentError} if the query fails
98
+ */
99
+ run(query: string, timeoutMs?: number): string;
100
+ /**
101
+ * Run a query with detailed result information.
102
+ *
103
+ * @param query The user query to process
104
+ * @param timeoutMs Timeout in milliseconds (default: 60000)
105
+ * @returns AgentResult with response and metadata
106
+ */
107
+ runDetailed(query: string, timeoutMs?: number): AgentResult;
108
+ /**
109
+ * Dispose of the agent and free resources.
110
+ */
111
+ dispose(): void;
112
+ /**
113
+ * Check if agent is disposed.
114
+ */
115
+ isDisposed(): boolean;
116
+ private ensureNotDisposed;
117
+ }
118
+ //# sourceMappingURL=agent.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../src/agent.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAC7C,OAAO,EAAE,WAAW,EAAqB,MAAM,UAAU,CAAC;AAO1D;;GAEG;AACH,qBAAa,WAAW;IACtB,OAAO,CAAC,MAAM,CAAmB;IACjC,OAAO,CAAC,QAAQ,CAAS;IAEzB,OAAO;IAIP;;;;;;;OAOG;IACH,MAAM,CAAC,IAAI,IAAI,IAAI;IAcnB;;;;OAIG;IACH,MAAM,CAAC,QAAQ,IAAI,IAAI;IAIvB;;OAEG;IACH,MAAM,CAAC,aAAa,IAAI,OAAO;IAI/B;;;;;;OAMG;IACH,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,iBAAiB,GAAG,WAAW;IAsCrD;;;;;;;OAOG;IACH,MAAM,CAAC,gBAAgB,CACrB,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,GACb,WAAW;IAUd;;;;;;;OAOG;IACH,MAAM,CAAC,sBAAsB,CAC3B,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,MAAM,EACb,YAAY,EAAE,MAAM,GACnB,WAAW;IAUd;;;;;;;OAOG;IACH,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,SAAQ,GAAG,MAAM;IAmB7C;;;;;;OAMG;IACH,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,SAAQ,GAAG,WAAW;IAiB1D;;OAEG;IACH,OAAO,IAAI,IAAI;IAYf;;OAEG;IACH,UAAU,IAAI,OAAO;IAIrB,OAAO,CAAC,iBAAiB;CAK1B"}
package/dist/agent.js ADDED
@@ -0,0 +1,236 @@
1
+ "use strict";
2
+ /**
3
+ * GopherAgent - Main entry point for the gopher-orch TypeScript SDK.
4
+ *
5
+ * Provides a clean, TypeScript-friendly interface to the gopher-orch agent functionality.
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * // Create an agent with API key
10
+ * const agent = GopherAgent.create(
11
+ * GopherAgentConfig.builder()
12
+ * .provider('AnthropicProvider')
13
+ * .model('claude-3-haiku-20240307')
14
+ * .apiKey('your-api-key')
15
+ * .build()
16
+ * );
17
+ *
18
+ * // Run a query
19
+ * const answer = agent.run('What time is it in Tokyo?');
20
+ * console.log(answer);
21
+ *
22
+ * // Cleanup
23
+ * agent.dispose();
24
+ * ```
25
+ *
26
+ * @example
27
+ * ```typescript
28
+ * // Use try-finally for automatic cleanup
29
+ * const agent = GopherAgent.create(config);
30
+ * try {
31
+ * const answer = agent.run('What time is it in Tokyo?');
32
+ * console.log(answer);
33
+ * } finally {
34
+ * agent.dispose();
35
+ * }
36
+ * ```
37
+ */
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.GopherAgent = void 0;
40
+ const config_1 = require("./config");
41
+ const result_1 = require("./result");
42
+ const errors_1 = require("./errors");
43
+ const ffi_1 = require("./ffi");
44
+ let initialized = false;
45
+ let cleanupHandlerRegistered = false;
46
+ /**
47
+ * Main agent class for interacting with the gopher-orch native library.
48
+ */
49
+ class GopherAgent {
50
+ handle;
51
+ disposed = false;
52
+ constructor(handle) {
53
+ this.handle = handle;
54
+ }
55
+ /**
56
+ * Initialize the gopher-orch library.
57
+ *
58
+ * Must be called before creating any agents. Called automatically by create() if not already
59
+ * initialized.
60
+ *
61
+ * @throws {AgentError} if initialization fails
62
+ */
63
+ static init() {
64
+ if (initialized) {
65
+ return;
66
+ }
67
+ const lib = ffi_1.GopherOrchLibrary.getInstance();
68
+ if (lib === null) {
69
+ throw new errors_1.AgentError('Failed to load gopher-orch native library');
70
+ }
71
+ initialized = true;
72
+ setupCleanupHandler();
73
+ }
74
+ /**
75
+ * Shutdown the gopher-orch library.
76
+ *
77
+ * Called automatically on process exit, but can be called manually.
78
+ */
79
+ static shutdown() {
80
+ initialized = false;
81
+ }
82
+ /**
83
+ * Check if the library is initialized.
84
+ */
85
+ static isInitialized() {
86
+ return initialized;
87
+ }
88
+ /**
89
+ * Create a new GopherAgent instance.
90
+ *
91
+ * @param config Agent configuration
92
+ * @returns GopherAgent instance
93
+ * @throws {AgentError} if agent creation fails
94
+ */
95
+ static create(config) {
96
+ if (!initialized) {
97
+ GopherAgent.init();
98
+ }
99
+ const lib = ffi_1.GopherOrchLibrary.getInstance();
100
+ if (lib === null) {
101
+ throw new errors_1.AgentError('Native library not available');
102
+ }
103
+ let handle;
104
+ try {
105
+ if (config.hasApiKey()) {
106
+ handle = lib.agentCreateByApiKey(config.provider, config.model, config.apiKey);
107
+ }
108
+ else {
109
+ handle = lib.agentCreateByJson(config.provider, config.model, config.serverConfig);
110
+ }
111
+ }
112
+ catch (e) {
113
+ throw new errors_1.AgentError(`Failed to create agent: ${e.message}`);
114
+ }
115
+ if (handle === null) {
116
+ const error = lib.getLastErrorMessage();
117
+ lib.clearError();
118
+ throw new errors_1.AgentError(error ?? 'Failed to create agent');
119
+ }
120
+ return new GopherAgent(handle);
121
+ }
122
+ /**
123
+ * Create a new GopherAgent with API key.
124
+ *
125
+ * @param provider Provider name (e.g., "AnthropicProvider")
126
+ * @param model Model name (e.g., "claude-3-haiku-20240307")
127
+ * @param apiKey API key for fetching remote server config
128
+ * @returns GopherAgent instance
129
+ */
130
+ static createWithApiKey(provider, model, apiKey) {
131
+ return GopherAgent.create(config_1.GopherAgentConfig.builder()
132
+ .provider(provider)
133
+ .model(model)
134
+ .apiKey(apiKey)
135
+ .build());
136
+ }
137
+ /**
138
+ * Create a new GopherAgent with JSON server config.
139
+ *
140
+ * @param provider Provider name (e.g., "AnthropicProvider")
141
+ * @param model Model name (e.g., "claude-3-haiku-20240307")
142
+ * @param serverConfig JSON server configuration
143
+ * @returns GopherAgent instance
144
+ */
145
+ static createWithServerConfig(provider, model, serverConfig) {
146
+ return GopherAgent.create(config_1.GopherAgentConfig.builder()
147
+ .provider(provider)
148
+ .model(model)
149
+ .serverConfig(serverConfig)
150
+ .build());
151
+ }
152
+ /**
153
+ * Run a query against the agent.
154
+ *
155
+ * @param query The user query to process
156
+ * @param timeoutMs Timeout in milliseconds (default: 60000)
157
+ * @returns The agent's response
158
+ * @throws {AgentError} if the query fails
159
+ */
160
+ run(query, timeoutMs = 60000) {
161
+ this.ensureNotDisposed();
162
+ const lib = ffi_1.GopherOrchLibrary.getInstance();
163
+ if (lib === null) {
164
+ throw new errors_1.AgentError('Native library not available');
165
+ }
166
+ try {
167
+ const response = lib.agentRun(this.handle, query, timeoutMs);
168
+ if (response === null) {
169
+ return `No response for query: "${query}"`;
170
+ }
171
+ return response;
172
+ }
173
+ catch (e) {
174
+ throw new errors_1.AgentError(`Query execution failed: ${e.message}`);
175
+ }
176
+ }
177
+ /**
178
+ * Run a query with detailed result information.
179
+ *
180
+ * @param query The user query to process
181
+ * @param timeoutMs Timeout in milliseconds (default: 60000)
182
+ * @returns AgentResult with response and metadata
183
+ */
184
+ runDetailed(query, timeoutMs = 60000) {
185
+ try {
186
+ const response = this.run(query, timeoutMs);
187
+ return result_1.AgentResult.builder()
188
+ .response(response)
189
+ .status(result_1.AgentResultStatus.SUCCESS)
190
+ .iterationCount(1)
191
+ .tokensUsed(0)
192
+ .build();
193
+ }
194
+ catch (e) {
195
+ if (e instanceof errors_1.TimeoutError) {
196
+ return result_1.AgentResult.timeout(e.message);
197
+ }
198
+ return result_1.AgentResult.error(e.message);
199
+ }
200
+ }
201
+ /**
202
+ * Dispose of the agent and free resources.
203
+ */
204
+ dispose() {
205
+ if (this.disposed) {
206
+ return;
207
+ }
208
+ this.disposed = true;
209
+ const lib = ffi_1.GopherOrchLibrary.getInstance();
210
+ if (lib !== null && this.handle !== null) {
211
+ lib.agentRelease(this.handle);
212
+ }
213
+ }
214
+ /**
215
+ * Check if agent is disposed.
216
+ */
217
+ isDisposed() {
218
+ return this.disposed;
219
+ }
220
+ ensureNotDisposed() {
221
+ if (this.disposed) {
222
+ throw new errors_1.AgentError('Agent has been disposed');
223
+ }
224
+ }
225
+ }
226
+ exports.GopherAgent = GopherAgent;
227
+ function setupCleanupHandler() {
228
+ if (cleanupHandlerRegistered) {
229
+ return;
230
+ }
231
+ cleanupHandlerRegistered = true;
232
+ process.on('exit', () => {
233
+ GopherAgent.shutdown();
234
+ });
235
+ }
236
+ //# sourceMappingURL=agent.js.map
@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;YACnD,CAAC;YACD,OAAO,oBAAW,CAAC,KAAK,CAAE,CAAW,CAAC,OAAO,CAAC,CAAC;QACjD,CAAC;IACH,CAAC;IAED;;OAEG;IACH,OAAO;QACL,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;YAClB,OAAO;QACT,CAAC;QAED,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;QACrB,MAAM,GAAG,GAAG,uBAAiB,CAAC,WAAW,EAAE,CAAC;QAC5C,IAAI,GAAG,KAAK,IAAI,IAAI,IAAI,CAAC,MAAM,KAAK,IAAI,EAAE,CAAC;YACzC,GAAG,CAAC,YAAY,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAChC,CAAC;IACH,CAAC;IAED;;OAEG;IACH,UAAU;QACR,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;IAEO,iBAAiB;QACvB,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;YAClB,MAAM,IAAI,mBAAU,CAAC,yBAAyB,CAAC,CAAC;QAClD,CAAC;IACH,CAAC;CACF;AArND,kCAqNC;AAED,SAAS,mBAAmB;IAC1B,IAAI,wBAAwB,EAAE,CAAC;QAC7B,OAAO;IACT,CAAC;IAED,wBAAwB,GAAG,IAAI,CAAC;IAChC,OAAO,CAAC,EAAE,CAAC,MAAM,EAAE,GAAG,EAAE;QACtB,WAAW,CAAC,QAAQ,EAAE,CAAC;IACzB,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,63 @@
1
+ /**
2
+ * Configuration options for creating a GopherAgent.
3
+ */
4
+ export interface GopherAgentConfigOptions {
5
+ provider: string;
6
+ model: string;
7
+ apiKey?: string;
8
+ serverConfig?: string;
9
+ }
10
+ /**
11
+ * Configuration for creating a GopherAgent.
12
+ */
13
+ export declare class GopherAgentConfig {
14
+ readonly provider: string;
15
+ readonly model: string;
16
+ readonly apiKey?: string;
17
+ readonly serverConfig?: string;
18
+ private constructor();
19
+ /**
20
+ * Check if this config uses an API key.
21
+ */
22
+ hasApiKey(): boolean;
23
+ /**
24
+ * Check if this config uses a server config.
25
+ */
26
+ hasServerConfig(): boolean;
27
+ /**
28
+ * Create a new builder for GopherAgentConfig.
29
+ */
30
+ static builder(): GopherAgentConfigBuilder;
31
+ }
32
+ /**
33
+ * Builder for GopherAgentConfig.
34
+ */
35
+ export declare class GopherAgentConfigBuilder {
36
+ private _provider?;
37
+ private _model?;
38
+ private _apiKey?;
39
+ private _serverConfig?;
40
+ /**
41
+ * Set the LLM provider (e.g., "AnthropicProvider").
42
+ */
43
+ provider(provider: string): this;
44
+ /**
45
+ * Set the model name (e.g., "claude-3-haiku-20240307").
46
+ */
47
+ model(model: string): this;
48
+ /**
49
+ * Set the API key for fetching remote server config.
50
+ * Mutually exclusive with serverConfig.
51
+ */
52
+ apiKey(apiKey: string): this;
53
+ /**
54
+ * Set the JSON server configuration.
55
+ * Mutually exclusive with apiKey.
56
+ */
57
+ serverConfig(serverConfig: string): this;
58
+ /**
59
+ * Build the GopherAgentConfig.
60
+ */
61
+ build(): GopherAgentConfig;
62
+ }
63
+ //# sourceMappingURL=config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,wBAAwB;IACvC,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED;;GAEG;AACH,qBAAa,iBAAiB;IAC5B,SAAgB,QAAQ,EAAE,MAAM,CAAC;IACjC,SAAgB,KAAK,EAAE,MAAM,CAAC;IAC9B,SAAgB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChC,SAAgB,YAAY,CAAC,EAAE,MAAM,CAAC;IAEtC,OAAO;IAoBP;;OAEG;IACH,SAAS,IAAI,OAAO;IAIpB;;OAEG;IACH,eAAe,IAAI,OAAO;IAI1B;;OAEG;IACH,MAAM,CAAC,OAAO,IAAI,wBAAwB;CAG3C;AAED;;GAEG;AACH,qBAAa,wBAAwB;IACnC,OAAO,CAAC,SAAS,CAAC,CAAS;IAC3B,OAAO,CAAC,MAAM,CAAC,CAAS;IACxB,OAAO,CAAC,OAAO,CAAC,CAAS;IACzB,OAAO,CAAC,aAAa,CAAC,CAAS;IAE/B;;OAEG;IACH,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI;IAKhC;;OAEG;IACH,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAK1B;;;OAGG;IACH,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAK5B;;;OAGG;IACH,YAAY,CAAC,YAAY,EAAE,MAAM,GAAG,IAAI;IAKxC;;OAEG;IACH,KAAK,IAAI,iBAAiB;CAU3B"}
package/dist/config.js ADDED
@@ -0,0 +1,101 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GopherAgentConfigBuilder = exports.GopherAgentConfig = void 0;
4
+ /**
5
+ * Configuration for creating a GopherAgent.
6
+ */
7
+ class GopherAgentConfig {
8
+ provider;
9
+ model;
10
+ apiKey;
11
+ serverConfig;
12
+ constructor(options) {
13
+ if (!options.provider) {
14
+ throw new Error('Provider is required');
15
+ }
16
+ if (!options.model) {
17
+ throw new Error('Model is required');
18
+ }
19
+ if (!options.apiKey && !options.serverConfig) {
20
+ throw new Error('Either apiKey or serverConfig is required');
21
+ }
22
+ if (options.apiKey && options.serverConfig) {
23
+ throw new Error('Cannot specify both apiKey and serverConfig');
24
+ }
25
+ this.provider = options.provider;
26
+ this.model = options.model;
27
+ this.apiKey = options.apiKey;
28
+ this.serverConfig = options.serverConfig;
29
+ }
30
+ /**
31
+ * Check if this config uses an API key.
32
+ */
33
+ hasApiKey() {
34
+ return this.apiKey !== undefined;
35
+ }
36
+ /**
37
+ * Check if this config uses a server config.
38
+ */
39
+ hasServerConfig() {
40
+ return this.serverConfig !== undefined;
41
+ }
42
+ /**
43
+ * Create a new builder for GopherAgentConfig.
44
+ */
45
+ static builder() {
46
+ return new GopherAgentConfigBuilder();
47
+ }
48
+ }
49
+ exports.GopherAgentConfig = GopherAgentConfig;
50
+ /**
51
+ * Builder for GopherAgentConfig.
52
+ */
53
+ class GopherAgentConfigBuilder {
54
+ _provider;
55
+ _model;
56
+ _apiKey;
57
+ _serverConfig;
58
+ /**
59
+ * Set the LLM provider (e.g., "AnthropicProvider").
60
+ */
61
+ provider(provider) {
62
+ this._provider = provider;
63
+ return this;
64
+ }
65
+ /**
66
+ * Set the model name (e.g., "claude-3-haiku-20240307").
67
+ */
68
+ model(model) {
69
+ this._model = model;
70
+ return this;
71
+ }
72
+ /**
73
+ * Set the API key for fetching remote server config.
74
+ * Mutually exclusive with serverConfig.
75
+ */
76
+ apiKey(apiKey) {
77
+ this._apiKey = apiKey;
78
+ return this;
79
+ }
80
+ /**
81
+ * Set the JSON server configuration.
82
+ * Mutually exclusive with apiKey.
83
+ */
84
+ serverConfig(serverConfig) {
85
+ this._serverConfig = serverConfig;
86
+ return this;
87
+ }
88
+ /**
89
+ * Build the GopherAgentConfig.
90
+ */
91
+ build() {
92
+ return new GopherAgentConfig({
93
+ provider: this._provider ?? '',
94
+ model: this._model ?? '',
95
+ apiKey: this._apiKey,
96
+ serverConfig: this._serverConfig,
97
+ });
98
+ }
99
+ }
100
+ exports.GopherAgentConfigBuilder = GopherAgentConfigBuilder;
101
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":";;;AAUA;;GAEG;AACH,MAAa,iBAAiB;IACZ,QAAQ,CAAS;IACjB,KAAK,CAAS;IACd,MAAM,CAAU;IAChB,YAAY,CAAU;IAEtC,YAAoB,OAAiC;QACnD,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC;YACtB,MAAM,IAAI,KAAK,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AO,IAAI,CAAC;IACd,CAAC;IAED;;;OAGG;IACH,MAAM,CAAC,MAAc;QACnB,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;OAGG;IACH,YAAY,CAAC,YAAoB;QAC/B,IAAI,CAAC,aAAa,GAAG,YAAY,CAAC;QAClC,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;OAEG;IACH,KAAK;QACH,OAAO,IAAK,iBAEV,CAAC;YACD,QAAQ,EAAE,IAAI,CAAC,SAAS,IAAI,EAAE;YAC9B,KAAK,EAAE,IAAI,CAAC,MAAM,IAAI,EAAE;YACxB,MAAM,EAAE,IAAI,CAAC,OAAO;YACpB,YAAY,EAAE,IAAI,CAAC,aAAa;SACjC,CAAC,CAAC;IACL,CAAC;CACF;AArDD,4DAqDC"}
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Custom error classes for gopher-orch operations.
3
+ */
4
+ /**
5
+ * Base error class for agent operations.
6
+ */
7
+ export declare class AgentError extends Error {
8
+ readonly code?: string;
9
+ constructor(message: string, code?: string);
10
+ }
11
+ /**
12
+ * Error thrown when API key is invalid or missing.
13
+ */
14
+ export declare class ApiKeyError extends AgentError {
15
+ constructor(message: string);
16
+ }
17
+ /**
18
+ * Error thrown when connection fails.
19
+ */
20
+ export declare class ConnectionError extends AgentError {
21
+ constructor(message: string);
22
+ }
23
+ /**
24
+ * Error thrown when operation times out.
25
+ */
26
+ export declare class TimeoutError extends AgentError {
27
+ constructor(message: string);
28
+ }
29
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;GAEG;AACH,qBAAa,UAAW,SAAQ,KAAK;IACnC,SAAgB,IAAI,CAAC,EAAE,MAAM,CAAC;gBAElB,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM;CAM3C;AAED;;GAEG;AACH,qBAAa,WAAY,SAAQ,UAAU;gBAC7B,OAAO,EAAE,MAAM;CAK5B;AAED;;GAEG;AACH,qBAAa,eAAgB,SAAQ,UAAU;gBACjC,OAAO,EAAE,MAAM;CAK5B;AAED;;GAEG;AACH,qBAAa,YAAa,SAAQ,UAAU;gBAC9B,OAAO,EAAE,MAAM;CAK5B"}
package/dist/errors.js ADDED
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ /**
3
+ * Custom error classes for gopher-orch operations.
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.TimeoutError = exports.ConnectionError = exports.ApiKeyError = exports.AgentError = void 0;
7
+ /**
8
+ * Base error class for agent operations.
9
+ */
10
+ class AgentError extends Error {
11
+ code;
12
+ constructor(message, code) {
13
+ super(message);
14
+ this.name = 'AgentError';
15
+ this.code = code;
16
+ Object.setPrototypeOf(this, AgentError.prototype);
17
+ }
18
+ }
19
+ exports.AgentError = AgentError;
20
+ /**
21
+ * Error thrown when API key is invalid or missing.
22
+ */
23
+ class ApiKeyError extends AgentError {
24
+ constructor(message) {
25
+ super(message, 'API_KEY_ERROR');
26
+ this.name = 'ApiKeyError';
27
+ Object.setPrototypeOf(this, ApiKeyError.prototype);
28
+ }
29
+ }
30
+ exports.ApiKeyError = ApiKeyError;
31
+ /**
32
+ * Error thrown when connection fails.
33
+ */
34
+ class ConnectionError extends AgentError {
35
+ constructor(message) {
36
+ super(message, 'CONNECTION_ERROR');
37
+ this.name = 'ConnectionError';
38
+ Object.setPrototypeOf(this, ConnectionError.prototype);
39
+ }
40
+ }
41
+ exports.ConnectionError = ConnectionError;
42
+ /**
43
+ * Error thrown when operation times out.
44
+ */
45
+ class TimeoutError extends AgentError {
46
+ constructor(message) {
47
+ super(message, 'TIMEOUT_ERROR');
48
+ this.name = 'TimeoutError';
49
+ Object.setPrototypeOf(this, TimeoutError.prototype);
50
+ }
51
+ }
52
+ exports.TimeoutError = TimeoutError;
53
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH;;GAEG;AACH,MAAa,UAAW,SAAQ,KAAK;IACnB,IAAI,CAAU;IAE9B,YAAY,OAAe,EAAE,IAAa;QACxC,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,YAAY,CAAC;QACzB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,UAAU,CAAC,SAAS,CAAC,CAAC;IACpD,CAAC;CACF;AATD,gCASC;AAED;;GAEG;AACH,MAAa,WAAY,SAAQ,UAAU;IACzC,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,EAAE,eAAe,CAAC,CAAC;QAChC,IAAI,CAAC,IAAI,GAAG,aAAa,CAAC;QAC1B,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,WAAW,CAAC,SAAS,CAAC,CAAC;IACrD,CAAC;CACF;AAND,kCAMC;AAED;;GAEG;AACH,MAAa,eAAgB,SAAQ,UAAU;IAC7C,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,EAAE,kBAAkB,CAAC,CAAC;QACnC,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAC;QAC9B,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,eAAe,CAAC,SAAS,CAAC,CAAC;IACzD,CAAC;CACF;AAND,0CAMC;AAED;;GAEG;AACH,MAAa,YAAa,SAAQ,UAAU;IAC1C,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,EAAE,eAAe,CAAC,CAAC;QAChC,IAAI,CAAC,IAAI,GAAG,cAAc,CAAC;QAC3B,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,YAAY,CAAC,SAAS,CAAC,CAAC;IACtD,CAAC;CACF;AAND,oCAMC"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * FFI module exports.
3
+ */
4
+ export { GopherOrchLibrary } from './library';
5
+ export type { GopherOrchHandle, GopherOrchErrorInfoData } from './library';
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/ffi/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAC9C,YAAY,EAAE,gBAAgB,EAAE,uBAAuB,EAAE,MAAM,WAAW,CAAC"}
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ /**
3
+ * FFI module exports.
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.GopherOrchLibrary = void 0;
7
+ var library_1 = require("./library");
8
+ Object.defineProperty(exports, "GopherOrchLibrary", { enumerable: true, get: function () { return library_1.GopherOrchLibrary; } });
9
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/ffi/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH,qCAA8C;AAArC,4GAAA,iBAAiB,OAAA"}