@coalex-ai/sdk 0.4.5 → 0.5.1
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/auto-instrument.d.ts +14 -0
- package/dist/auto-instrument.d.ts.map +1 -0
- package/dist/auto-instrument.js +129 -0
- package/dist/auto-instrument.js.map +1 -0
- package/dist/config.d.ts +5 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +2 -0
- package/dist/config.js.map +1 -0
- package/dist/context.d.ts +8 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +52 -0
- package/dist/context.js.map +1 -0
- package/dist/evaluate.d.ts +14 -0
- package/dist/evaluate.d.ts.map +1 -0
- package/dist/evaluate.js +45 -0
- package/dist/evaluate.js.map +1 -0
- package/dist/ext/base.d.ts +3 -0
- package/dist/ext/base.d.ts.map +1 -0
- package/dist/ext/base.js +5 -0
- package/dist/ext/base.js.map +1 -0
- package/dist/ext/embedding.d.ts +16 -0
- package/dist/ext/embedding.d.ts.map +1 -0
- package/dist/ext/embedding.js +62 -0
- package/dist/ext/embedding.js.map +1 -0
- package/dist/ext/guardrail.d.ts +6 -0
- package/dist/ext/guardrail.d.ts.map +1 -0
- package/dist/ext/guardrail.js +32 -0
- package/dist/ext/guardrail.js.map +1 -0
- package/dist/ext/index.d.ts +12 -0
- package/dist/ext/index.d.ts.map +1 -0
- package/dist/ext/index.js +7 -0
- package/dist/ext/index.js.map +1 -0
- package/dist/ext/reranker.d.ts +20 -0
- package/dist/ext/reranker.d.ts.map +1 -0
- package/dist/ext/reranker.js +72 -0
- package/dist/ext/reranker.js.map +1 -0
- package/dist/ext/retrieval.d.ts +22 -0
- package/dist/ext/retrieval.d.ts.map +1 -0
- package/dist/ext/retrieval.js +79 -0
- package/dist/ext/retrieval.js.map +1 -0
- package/dist/ext/tool.d.ts +6 -0
- package/dist/ext/tool.d.ts.map +1 -0
- package/dist/ext/tool.js +28 -0
- package/dist/ext/tool.js.map +1 -0
- package/dist/filtering-exporter.d.ts +18 -0
- package/dist/filtering-exporter.d.ts.map +1 -0
- package/dist/filtering-exporter.js +59 -0
- package/dist/filtering-exporter.js.map +1 -0
- package/dist/index.d.ts +23 -9
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +54 -26
- package/dist/index.js.map +1 -0
- package/dist/resolve.d.ts +21 -0
- package/dist/resolve.d.ts.map +1 -0
- package/dist/resolve.js +42 -0
- package/dist/resolve.js.map +1 -0
- package/dist/safe-exporter.d.ts +17 -0
- package/dist/safe-exporter.d.ts.map +1 -0
- package/dist/safe-exporter.js +64 -0
- package/dist/safe-exporter.js.map +1 -0
- package/dist/span-processor.d.ts +9 -0
- package/dist/span-processor.d.ts.map +1 -0
- package/dist/span-processor.js +31 -0
- package/dist/span-processor.js.map +1 -0
- package/package.json +44 -32
- package/LICENSE +0 -21
- package/README.md +0 -263
- package/dist/approve.d.ts +0 -95
- package/dist/approve.js +0 -170
- package/dist/metrics.d.ts +0 -101
- package/dist/metrics.js +0 -192
- package/dist/otel/register.d.ts +0 -98
- package/dist/otel/register.js +0 -200
package/package.json
CHANGED
|
@@ -1,47 +1,59 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@coalex-ai/sdk",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "TypeScript SDK for
|
|
5
|
-
"
|
|
6
|
-
"types": "dist/index.d.ts",
|
|
7
|
-
"scripts": {
|
|
8
|
-
"build": "tsc",
|
|
9
|
-
"dev": "tsc --watch",
|
|
10
|
-
"prepublishOnly": "npm run build",
|
|
11
|
-
"test": "jest"
|
|
12
|
-
},
|
|
13
|
-
"keywords": [
|
|
14
|
-
"coalex",
|
|
15
|
-
"opentelemetry",
|
|
16
|
-
"tracing",
|
|
17
|
-
"observability",
|
|
18
|
-
"monitoring",
|
|
19
|
-
"metrics"
|
|
20
|
-
],
|
|
21
|
-
"author": "Coalex.ai <support@coalex.ai>",
|
|
22
|
-
"license": "MIT",
|
|
3
|
+
"version": "0.5.1",
|
|
4
|
+
"description": "Coalex TypeScript SDK for AI governance observability",
|
|
5
|
+
"license": "Apache-2.0",
|
|
23
6
|
"repository": {
|
|
24
7
|
"type": "git",
|
|
25
|
-
"url": "git+https://github.com/
|
|
8
|
+
"url": "git+https://github.com/Coalex-ai/coalex.git",
|
|
9
|
+
"directory": "packages/sdk-typescript"
|
|
10
|
+
},
|
|
11
|
+
"publishConfig": {
|
|
12
|
+
"access": "public"
|
|
13
|
+
},
|
|
14
|
+
"type": "module",
|
|
15
|
+
"main": "./dist/index.js",
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"exports": {
|
|
18
|
+
".": {
|
|
19
|
+
"types": "./dist/index.d.ts",
|
|
20
|
+
"import": "./dist/index.js"
|
|
21
|
+
},
|
|
22
|
+
"./ext": {
|
|
23
|
+
"types": "./dist/ext/index.d.ts",
|
|
24
|
+
"import": "./dist/ext/index.js"
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
"files": [
|
|
28
|
+
"dist"
|
|
29
|
+
],
|
|
30
|
+
"scripts": {
|
|
31
|
+
"build": "tsc",
|
|
32
|
+
"test": "vitest run",
|
|
33
|
+
"lint": "eslint src/ tests/",
|
|
34
|
+
"typecheck": "tsc --noEmit"
|
|
26
35
|
},
|
|
27
36
|
"dependencies": {
|
|
28
37
|
"@opentelemetry/api": "^1.9.0",
|
|
29
|
-
"@opentelemetry/sdk-trace-base": "^1.28.0",
|
|
30
38
|
"@opentelemetry/sdk-trace-node": "^1.28.0",
|
|
39
|
+
"@opentelemetry/sdk-trace-base": "^1.28.0",
|
|
31
40
|
"@opentelemetry/exporter-trace-otlp-http": "^0.55.0",
|
|
32
41
|
"@opentelemetry/resources": "^1.28.0",
|
|
33
42
|
"@opentelemetry/semantic-conventions": "^1.28.0"
|
|
34
43
|
},
|
|
35
44
|
"devDependencies": {
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
"@
|
|
40
|
-
"
|
|
45
|
+
"typescript": "~5.7.0",
|
|
46
|
+
"vitest": "^2.0.0",
|
|
47
|
+
"eslint": "^9.0.0",
|
|
48
|
+
"@eslint/js": "^9.0.0",
|
|
49
|
+
"typescript-eslint": "^8.0.0"
|
|
41
50
|
},
|
|
42
|
-
"
|
|
43
|
-
"
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
51
|
+
"peerDependencies": {
|
|
52
|
+
"@opentelemetry/instrumentation": ">=0.50.0"
|
|
53
|
+
},
|
|
54
|
+
"peerDependenciesMeta": {
|
|
55
|
+
"@opentelemetry/instrumentation": {
|
|
56
|
+
"optional": true
|
|
57
|
+
}
|
|
58
|
+
}
|
|
47
59
|
}
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2024 Coalex.ai
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
package/README.md
DELETED
|
@@ -1,263 +0,0 @@
|
|
|
1
|
-
# Coalex SDK for TypeScript
|
|
2
|
-
|
|
3
|
-
A TypeScript package for OpenTelemetry integration with Coalex.ai observability platform.
|
|
4
|
-
|
|
5
|
-
## Installation
|
|
6
|
-
|
|
7
|
-
```bash
|
|
8
|
-
npm install @coalex-ai/sdk
|
|
9
|
-
```
|
|
10
|
-
|
|
11
|
-
## Quick Start
|
|
12
|
-
|
|
13
|
-
```typescript
|
|
14
|
-
import { register, coalexContext } from '@coalex-ai/sdk';
|
|
15
|
-
|
|
16
|
-
// Register Coalex tracing
|
|
17
|
-
const tracerProvider = register({
|
|
18
|
-
agentId: 'YOUR_AGENT_ID'
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
// Use coalexContext for proper span management and attribute propagation
|
|
22
|
-
await coalexContext(
|
|
23
|
-
{
|
|
24
|
-
requestId: 'req_001',
|
|
25
|
-
promptVersion: 'v1.0.0'
|
|
26
|
-
},
|
|
27
|
-
async () => {
|
|
28
|
-
// Your instrumented code here
|
|
29
|
-
// Any OpenTelemetry instrumented calls will be traced with proper context
|
|
30
|
-
const result = await someApiCall();
|
|
31
|
-
return result;
|
|
32
|
-
}
|
|
33
|
-
);
|
|
34
|
-
```
|
|
35
|
-
|
|
36
|
-
## Features
|
|
37
|
-
|
|
38
|
-
- **Simple Setup**: One-line registration with `register()`
|
|
39
|
-
- **Coalex Integration**: Default endpoint for Coalex observability platform
|
|
40
|
-
- **Context Management**: Use `coalexContext()` for proper span hierarchy and attribute propagation
|
|
41
|
-
- **OpenTelemetry Compatible**: Works with all OpenTelemetry instrumentations
|
|
42
|
-
- **Authentication**: Automatic authentication using agent_id
|
|
43
|
-
- **Human-in-the-Loop**: Approval workflow for human review
|
|
44
|
-
- **Metrics Tracking**: Submit and track performance metrics
|
|
45
|
-
|
|
46
|
-
## Configuration
|
|
47
|
-
|
|
48
|
-
### Register
|
|
49
|
-
|
|
50
|
-
```typescript
|
|
51
|
-
import { register } from '@coalex/sdk';
|
|
52
|
-
|
|
53
|
-
const tracerProvider = register({
|
|
54
|
-
agentId: 'YOUR_AGENT_ID', // Required: Your unique agent identifier
|
|
55
|
-
endpoint: 'https://custom-endpoint', // Optional: Custom OTLP endpoint
|
|
56
|
-
serviceName: 'my-service', // Optional: Service name (default: 'coalex-service')
|
|
57
|
-
serviceVersion: '1.0.0', // Optional: Service version
|
|
58
|
-
additionalAttributes: { // Optional: Additional resource attributes
|
|
59
|
-
environment: 'production'
|
|
60
|
-
}
|
|
61
|
-
});
|
|
62
|
-
```
|
|
63
|
-
|
|
64
|
-
## API Reference
|
|
65
|
-
|
|
66
|
-
### Tracing
|
|
67
|
-
|
|
68
|
-
#### `register(options: RegisterOptions)`
|
|
69
|
-
|
|
70
|
-
Register Coalex OpenTelemetry tracing with the Coalex platform.
|
|
71
|
-
|
|
72
|
-
**Parameters:**
|
|
73
|
-
- `agentId` (required): Your unique agent identifier for authentication
|
|
74
|
-
- `endpoint` (optional): OTLP endpoint URL (defaults to `https://traces.coalex.ai/v1/traces`)
|
|
75
|
-
- `serviceName` (optional): Name of your service (defaults to `'coalex-service'`)
|
|
76
|
-
- `serviceVersion` (optional): Version of your service (defaults to `'0.1.0'`)
|
|
77
|
-
- `additionalAttributes` (optional): Additional resource attributes to include
|
|
78
|
-
|
|
79
|
-
**Returns:** `NodeTracerProvider` - The configured tracer provider
|
|
80
|
-
|
|
81
|
-
#### `coalexContext(options, fn)`
|
|
82
|
-
|
|
83
|
-
Execute a function within a Coalex context that ensures attributes are propagated to child spans.
|
|
84
|
-
|
|
85
|
-
**Parameters:**
|
|
86
|
-
- `options.requestId` (required): Unique request identifier
|
|
87
|
-
- `options.promptVersion` (required): Version of the prompt being used
|
|
88
|
-
- `options.spanName` (optional): Name for the context span (defaults to `'coalex_operation'`)
|
|
89
|
-
- `fn`: The async function to execute within the context
|
|
90
|
-
|
|
91
|
-
**Returns:** `Promise<T>` - Promise that resolves with the function result
|
|
92
|
-
|
|
93
|
-
**Example:**
|
|
94
|
-
```typescript
|
|
95
|
-
await coalexContext(
|
|
96
|
-
{
|
|
97
|
-
requestId: 'req_12345',
|
|
98
|
-
promptVersion: 'v2.0.0'
|
|
99
|
-
},
|
|
100
|
-
async () => {
|
|
101
|
-
// Your code here
|
|
102
|
-
return await someOperation();
|
|
103
|
-
}
|
|
104
|
-
);
|
|
105
|
-
```
|
|
106
|
-
|
|
107
|
-
#### `coalexContextSync(options, fn)`
|
|
108
|
-
|
|
109
|
-
Synchronous version of `coalexContext` for non-async operations.
|
|
110
|
-
|
|
111
|
-
**Example:**
|
|
112
|
-
```typescript
|
|
113
|
-
const result = coalexContextSync(
|
|
114
|
-
{
|
|
115
|
-
requestId: 'req_12345',
|
|
116
|
-
promptVersion: 'v2.0.0'
|
|
117
|
-
},
|
|
118
|
-
() => {
|
|
119
|
-
// Your synchronous code here
|
|
120
|
-
return someValue;
|
|
121
|
-
}
|
|
122
|
-
);
|
|
123
|
-
```
|
|
124
|
-
|
|
125
|
-
#### `addRequestContext(requestId, promptVersion)`
|
|
126
|
-
|
|
127
|
-
Add request context to the current active span. For better attribute propagation, consider using `coalexContext()` instead.
|
|
128
|
-
|
|
129
|
-
### Approval
|
|
130
|
-
|
|
131
|
-
#### `approve(options: ApproveOptions)`
|
|
132
|
-
|
|
133
|
-
Submit an approval request for human-in-the-loop review.
|
|
134
|
-
|
|
135
|
-
**Parameters:**
|
|
136
|
-
- `requestId` (required): Unique identifier for this approval request
|
|
137
|
-
- `inputData` (optional): Input data provided to your AI system
|
|
138
|
-
- `outputData` (optional): Output data generated by your AI system
|
|
139
|
-
- `version` (optional): Version of your prompt/model (defaults to `'1.0.0'`)
|
|
140
|
-
- `slaSeconds` (optional): SLA in seconds for human review (defaults to 3600)
|
|
141
|
-
- `agentId` (optional): Agent ID for authentication (auto-detected if not provided)
|
|
142
|
-
- `urlParams` (optional): Additional URL parameters for the review interface
|
|
143
|
-
- `eval` (optional): Evaluation control - string (use provided eval_id), true (generate eval_id), false/null (skip eval)
|
|
144
|
-
- `endpoint` (optional): Creator service endpoint
|
|
145
|
-
|
|
146
|
-
**Returns:** `Promise<ApprovalResponse>` - The approval response
|
|
147
|
-
|
|
148
|
-
**Example:**
|
|
149
|
-
```typescript
|
|
150
|
-
import { approve } from '@coalex/sdk';
|
|
151
|
-
|
|
152
|
-
const response = await approve({
|
|
153
|
-
requestId: 'req_12345',
|
|
154
|
-
inputData: { userQuery: 'What is the weather?' },
|
|
155
|
-
outputData: { response: "It's sunny today" },
|
|
156
|
-
version: 'v1.2.0'
|
|
157
|
-
});
|
|
158
|
-
|
|
159
|
-
console.log(`Approval task created: ${response.taskId}`);
|
|
160
|
-
console.log(`Status: ${response.status}`);
|
|
161
|
-
|
|
162
|
-
if (response.isAutoApproved) {
|
|
163
|
-
console.log('Request was auto-approved');
|
|
164
|
-
} else if (response.needsHumanReview) {
|
|
165
|
-
console.log('Request needs human review');
|
|
166
|
-
}
|
|
167
|
-
```
|
|
168
|
-
|
|
169
|
-
### Metrics
|
|
170
|
-
|
|
171
|
-
#### `submitMetric(options: SubmitMetricOptions)`
|
|
172
|
-
|
|
173
|
-
Submit a metric for performance tracking and monitoring.
|
|
174
|
-
|
|
175
|
-
**Parameters:**
|
|
176
|
-
- `requestId` (required): Unique identifier for the request that generated this metric
|
|
177
|
-
- `metricId` (required): Identifier for the type/name of metric
|
|
178
|
-
- `value` (required): Numeric value for the metric
|
|
179
|
-
- `metricType` (optional): Type category of the metric (e.g., "precision", "recall")
|
|
180
|
-
- `metadata` (optional): Additional contextual data for the metric
|
|
181
|
-
- `agentId` (optional): Agent ID for authentication (auto-detected if not provided)
|
|
182
|
-
- `reviewingAgentId` (optional): ID of agent that reviewed/validated this metric
|
|
183
|
-
- `taskId` (optional): Associated task identifier if applicable
|
|
184
|
-
- `endpoint` (optional): Creator service endpoint
|
|
185
|
-
|
|
186
|
-
**Returns:** `Promise<MetricResponse>` - The metric response
|
|
187
|
-
|
|
188
|
-
**Example:**
|
|
189
|
-
```typescript
|
|
190
|
-
import { submitMetric } from '@coalex/sdk';
|
|
191
|
-
|
|
192
|
-
const response = await submitMetric({
|
|
193
|
-
requestId: 'req_12345',
|
|
194
|
-
metricId: 'model_precision',
|
|
195
|
-
value: 0.92,
|
|
196
|
-
metricType: 'precision',
|
|
197
|
-
metadata: {
|
|
198
|
-
modelVersion: 'v2.1.0',
|
|
199
|
-
dataset: 'test_set_v1'
|
|
200
|
-
}
|
|
201
|
-
});
|
|
202
|
-
|
|
203
|
-
console.log(`Metric stored with ID: ${response.id}`);
|
|
204
|
-
```
|
|
205
|
-
|
|
206
|
-
## Complete Example
|
|
207
|
-
|
|
208
|
-
```typescript
|
|
209
|
-
import { register, coalexContext, approve, submitMetric } from '@coalex-ai/sdk';
|
|
210
|
-
|
|
211
|
-
// 1. Register tracing
|
|
212
|
-
register({
|
|
213
|
-
agentId: 'YOUR_AGENT_ID',
|
|
214
|
-
serviceName: 'my-ai-service'
|
|
215
|
-
});
|
|
216
|
-
|
|
217
|
-
// 2. Use context for traced operations
|
|
218
|
-
await coalexContext(
|
|
219
|
-
{
|
|
220
|
-
requestId: 'req_001',
|
|
221
|
-
promptVersion: 'v1.0.0'
|
|
222
|
-
},
|
|
223
|
-
async () => {
|
|
224
|
-
// Your AI/LLM operations here
|
|
225
|
-
const result = await generateResponse('What is AI?');
|
|
226
|
-
|
|
227
|
-
// 3. Submit for approval
|
|
228
|
-
const approval = await approve({
|
|
229
|
-
requestId: 'req_001',
|
|
230
|
-
inputData: { query: 'What is AI?' },
|
|
231
|
-
outputData: { response: result },
|
|
232
|
-
version: 'v1.0.0'
|
|
233
|
-
});
|
|
234
|
-
|
|
235
|
-
// 4. Submit metrics
|
|
236
|
-
if (approval.isAutoApproved) {
|
|
237
|
-
await submitMetric({
|
|
238
|
-
requestId: 'req_001',
|
|
239
|
-
metricId: 'auto_approval_rate',
|
|
240
|
-
value: 1.0,
|
|
241
|
-
metricType: 'rate'
|
|
242
|
-
});
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
return result;
|
|
246
|
-
}
|
|
247
|
-
);
|
|
248
|
-
```
|
|
249
|
-
|
|
250
|
-
## TypeScript Support
|
|
251
|
-
|
|
252
|
-
This package is written in TypeScript and includes full type definitions. All functions and classes are fully typed for an excellent development experience.
|
|
253
|
-
|
|
254
|
-
## License
|
|
255
|
-
|
|
256
|
-
MIT
|
|
257
|
-
|
|
258
|
-
## Links
|
|
259
|
-
|
|
260
|
-
- [Homepage](https://coalex.ai)
|
|
261
|
-
- [Documentation](https://docs.coalex.ai)
|
|
262
|
-
- [GitHub](https://github.com/coalex-ai/coalex-ts)
|
|
263
|
-
- [PyPI (Python version)](https://pypi.org/project/coalex/)
|
package/dist/approve.d.ts
DELETED
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Coalex approval functionality for human-in-the-loop workflows.
|
|
3
|
-
*/
|
|
4
|
-
export interface ApprovalRequestData {
|
|
5
|
-
requestId: string;
|
|
6
|
-
inputData?: Record<string, any>;
|
|
7
|
-
outputData?: Record<string, any>;
|
|
8
|
-
version?: string;
|
|
9
|
-
slaSeconds?: number;
|
|
10
|
-
agentId?: string;
|
|
11
|
-
urlParams?: Record<string, any>;
|
|
12
|
-
eval?: string | boolean;
|
|
13
|
-
}
|
|
14
|
-
export interface ApprovalResponseData {
|
|
15
|
-
taskId: string;
|
|
16
|
-
requestId: string;
|
|
17
|
-
status: string;
|
|
18
|
-
slaTimestamp: Date;
|
|
19
|
-
evalId?: string;
|
|
20
|
-
tunedOutputData?: Record<string, any>;
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Request object for approval tasks.
|
|
24
|
-
*/
|
|
25
|
-
export declare class ApprovalRequest {
|
|
26
|
-
requestId: string;
|
|
27
|
-
inputData: Record<string, any>;
|
|
28
|
-
outputData: Record<string, any>;
|
|
29
|
-
version: string;
|
|
30
|
-
slaSeconds: number;
|
|
31
|
-
agentId?: string;
|
|
32
|
-
urlParams: Record<string, any>;
|
|
33
|
-
eval?: string | boolean;
|
|
34
|
-
constructor(data: ApprovalRequestData);
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Response object for approval requests.
|
|
38
|
-
*/
|
|
39
|
-
export declare class ApprovalResponse {
|
|
40
|
-
taskId: string;
|
|
41
|
-
requestId: string;
|
|
42
|
-
status: string;
|
|
43
|
-
slaTimestamp: Date;
|
|
44
|
-
evalId?: string;
|
|
45
|
-
tunedOutputData?: Record<string, any>;
|
|
46
|
-
constructor(data: ApprovalResponseData);
|
|
47
|
-
/**
|
|
48
|
-
* Check if this request was auto-approved.
|
|
49
|
-
*/
|
|
50
|
-
get isAutoApproved(): boolean;
|
|
51
|
-
/**
|
|
52
|
-
* Check if this request needs human review.
|
|
53
|
-
*/
|
|
54
|
-
get needsHumanReview(): boolean;
|
|
55
|
-
}
|
|
56
|
-
export interface ApproveOptions {
|
|
57
|
-
requestId: string;
|
|
58
|
-
inputData?: Record<string, any>;
|
|
59
|
-
outputData?: Record<string, any>;
|
|
60
|
-
version?: string;
|
|
61
|
-
slaSeconds?: number;
|
|
62
|
-
agentId?: string;
|
|
63
|
-
urlParams?: Record<string, any>;
|
|
64
|
-
eval?: string | boolean;
|
|
65
|
-
endpoint?: string;
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* Submit an approval request for human-in-the-loop review.
|
|
69
|
-
*
|
|
70
|
-
* This function sends a request to the coalex-ai-creator service to create
|
|
71
|
-
* an approval task that will be handled by a human reviewer.
|
|
72
|
-
*
|
|
73
|
-
* @param options - Approval request options
|
|
74
|
-
* @returns Promise that resolves to ApprovalResponse
|
|
75
|
-
* @throws Error if required parameters are missing or the request fails
|
|
76
|
-
*
|
|
77
|
-
* @example
|
|
78
|
-
* ```typescript
|
|
79
|
-
* import { register, approve } from '@coalex/sdk';
|
|
80
|
-
*
|
|
81
|
-
* // Register coalex first
|
|
82
|
-
* register({ agentId: 'your-agent-id' });
|
|
83
|
-
*
|
|
84
|
-
* // Submit approval request
|
|
85
|
-
* const response = await approve({
|
|
86
|
-
* requestId: 'req_12345',
|
|
87
|
-
* inputData: { userQuery: 'What is the weather?' },
|
|
88
|
-
* outputData: { response: "It's sunny today" },
|
|
89
|
-
* version: 'v1.2.0'
|
|
90
|
-
* });
|
|
91
|
-
*
|
|
92
|
-
* console.log(`Approval task created: ${response.taskId}`);
|
|
93
|
-
* ```
|
|
94
|
-
*/
|
|
95
|
-
export declare function approve(options: ApproveOptions): Promise<ApprovalResponse>;
|
package/dist/approve.js
DELETED
|
@@ -1,170 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Coalex approval functionality for human-in-the-loop workflows.
|
|
4
|
-
*/
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.ApprovalResponse = exports.ApprovalRequest = void 0;
|
|
7
|
-
exports.approve = approve;
|
|
8
|
-
const api_1 = require("@opentelemetry/api");
|
|
9
|
-
const DEFAULT_CREATOR_ENDPOINT = 'https://creator.coalex.ai';
|
|
10
|
-
/**
|
|
11
|
-
* Request object for approval tasks.
|
|
12
|
-
*/
|
|
13
|
-
class ApprovalRequest {
|
|
14
|
-
constructor(data) {
|
|
15
|
-
this.requestId = data.requestId;
|
|
16
|
-
this.inputData = data.inputData || {};
|
|
17
|
-
this.outputData = data.outputData || {};
|
|
18
|
-
this.version = data.version || '1.0.0';
|
|
19
|
-
this.slaSeconds = data.slaSeconds || 3600;
|
|
20
|
-
this.agentId = data.agentId;
|
|
21
|
-
this.urlParams = data.urlParams || {};
|
|
22
|
-
this.eval = data.eval;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
exports.ApprovalRequest = ApprovalRequest;
|
|
26
|
-
/**
|
|
27
|
-
* Response object for approval requests.
|
|
28
|
-
*/
|
|
29
|
-
class ApprovalResponse {
|
|
30
|
-
constructor(data) {
|
|
31
|
-
this.taskId = data.taskId;
|
|
32
|
-
this.requestId = data.requestId;
|
|
33
|
-
this.status = data.status;
|
|
34
|
-
this.slaTimestamp = data.slaTimestamp;
|
|
35
|
-
this.evalId = data.evalId;
|
|
36
|
-
this.tunedOutputData = data.tunedOutputData;
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Check if this request was auto-approved.
|
|
40
|
-
*/
|
|
41
|
-
get isAutoApproved() {
|
|
42
|
-
return this.status === 'auto_approved';
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Check if this request needs human review.
|
|
46
|
-
*/
|
|
47
|
-
get needsHumanReview() {
|
|
48
|
-
return this.status === 'pending';
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
exports.ApprovalResponse = ApprovalResponse;
|
|
52
|
-
/**
|
|
53
|
-
* Extract agent_id from the current tracer provider's resource.
|
|
54
|
-
*/
|
|
55
|
-
function getAgentIdFromTracer() {
|
|
56
|
-
try {
|
|
57
|
-
const tracerProvider = api_1.trace.getTracerProvider();
|
|
58
|
-
if (tracerProvider && tracerProvider.resource) {
|
|
59
|
-
const attributes = tracerProvider.resource.attributes;
|
|
60
|
-
return attributes['coalex.agent_id'];
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
catch (error) {
|
|
64
|
-
console.warn('Failed to get agent_id from tracer:', error);
|
|
65
|
-
}
|
|
66
|
-
return undefined;
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* Submit an approval request for human-in-the-loop review.
|
|
70
|
-
*
|
|
71
|
-
* This function sends a request to the coalex-ai-creator service to create
|
|
72
|
-
* an approval task that will be handled by a human reviewer.
|
|
73
|
-
*
|
|
74
|
-
* @param options - Approval request options
|
|
75
|
-
* @returns Promise that resolves to ApprovalResponse
|
|
76
|
-
* @throws Error if required parameters are missing or the request fails
|
|
77
|
-
*
|
|
78
|
-
* @example
|
|
79
|
-
* ```typescript
|
|
80
|
-
* import { register, approve } from '@coalex/sdk';
|
|
81
|
-
*
|
|
82
|
-
* // Register coalex first
|
|
83
|
-
* register({ agentId: 'your-agent-id' });
|
|
84
|
-
*
|
|
85
|
-
* // Submit approval request
|
|
86
|
-
* const response = await approve({
|
|
87
|
-
* requestId: 'req_12345',
|
|
88
|
-
* inputData: { userQuery: 'What is the weather?' },
|
|
89
|
-
* outputData: { response: "It's sunny today" },
|
|
90
|
-
* version: 'v1.2.0'
|
|
91
|
-
* });
|
|
92
|
-
*
|
|
93
|
-
* console.log(`Approval task created: ${response.taskId}`);
|
|
94
|
-
* ```
|
|
95
|
-
*/
|
|
96
|
-
async function approve(options) {
|
|
97
|
-
const { requestId, inputData, outputData, version = '1.0.0', slaSeconds = 3600, urlParams, eval: evalOption, endpoint = DEFAULT_CREATOR_ENDPOINT } = options;
|
|
98
|
-
if (!requestId) {
|
|
99
|
-
throw new Error('requestId is required');
|
|
100
|
-
}
|
|
101
|
-
// Auto-detect agent_id from tracer if not provided
|
|
102
|
-
let agentId = options.agentId;
|
|
103
|
-
if (!agentId) {
|
|
104
|
-
agentId = getAgentIdFromTracer();
|
|
105
|
-
if (!agentId) {
|
|
106
|
-
throw new Error('agentId is required. Either pass it explicitly or ensure register() was called first.');
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
// Create approval request
|
|
110
|
-
const approvalRequest = new ApprovalRequest({
|
|
111
|
-
requestId,
|
|
112
|
-
inputData,
|
|
113
|
-
outputData,
|
|
114
|
-
version,
|
|
115
|
-
slaSeconds,
|
|
116
|
-
agentId,
|
|
117
|
-
urlParams,
|
|
118
|
-
eval: evalOption
|
|
119
|
-
});
|
|
120
|
-
// Prepare request payload
|
|
121
|
-
const payload = {
|
|
122
|
-
request_id: approvalRequest.requestId,
|
|
123
|
-
input_data: approvalRequest.inputData,
|
|
124
|
-
output_data: approvalRequest.outputData,
|
|
125
|
-
version: approvalRequest.version,
|
|
126
|
-
sla_seconds: approvalRequest.slaSeconds,
|
|
127
|
-
agent_id: approvalRequest.agentId,
|
|
128
|
-
url_params: approvalRequest.urlParams,
|
|
129
|
-
eval: approvalRequest.eval
|
|
130
|
-
};
|
|
131
|
-
// Prepare headers for authentication
|
|
132
|
-
const headers = {
|
|
133
|
-
'Authorization': `Bearer ${agentId}`,
|
|
134
|
-
'Content-Type': 'application/json'
|
|
135
|
-
};
|
|
136
|
-
// Build URL
|
|
137
|
-
const url = `${endpoint}/approve`;
|
|
138
|
-
console.log(`Submitting approval request ${requestId} for agent ${agentId}`);
|
|
139
|
-
try {
|
|
140
|
-
// Make HTTP request
|
|
141
|
-
const response = await fetch(url, {
|
|
142
|
-
method: 'POST',
|
|
143
|
-
headers,
|
|
144
|
-
body: JSON.stringify(payload)
|
|
145
|
-
});
|
|
146
|
-
// Check response status
|
|
147
|
-
if (!response.ok) {
|
|
148
|
-
const errorText = await response.text();
|
|
149
|
-
throw new Error(`HTTP ${response.status}: ${errorText}`);
|
|
150
|
-
}
|
|
151
|
-
// Parse response
|
|
152
|
-
const responseData = await response.json();
|
|
153
|
-
// Convert sla_timestamp string to Date
|
|
154
|
-
const slaTimestamp = new Date(responseData.sla_timestamp);
|
|
155
|
-
const approvalResponse = new ApprovalResponse({
|
|
156
|
-
taskId: responseData.task_id,
|
|
157
|
-
requestId: responseData.request_id,
|
|
158
|
-
status: responseData.status,
|
|
159
|
-
slaTimestamp,
|
|
160
|
-
evalId: responseData.eval_id,
|
|
161
|
-
tunedOutputData: responseData.tuned_output_data
|
|
162
|
-
});
|
|
163
|
-
console.log(`Approval request ${requestId} submitted successfully. Task ID: ${approvalResponse.taskId}`);
|
|
164
|
-
return approvalResponse;
|
|
165
|
-
}
|
|
166
|
-
catch (error) {
|
|
167
|
-
console.error(`Failed to submit approval request ${requestId}:`, error);
|
|
168
|
-
throw error;
|
|
169
|
-
}
|
|
170
|
-
}
|