samuel-integrations-sdk 0.0.1 → 0.0.2
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 +109 -5
- package/dist/http-client.d.ts.map +1 -1
- package/dist/http-client.js +4 -4
- package/dist/http-client.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +11 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
# Samuel Agent Types SDK
|
|
2
2
|
|
|
3
|
-
A TypeScript SDK for
|
|
3
|
+
A TypeScript SDK for UPTIQ Integrations, auto-generated from OpenAPI specifications.
|
|
4
4
|
|
|
5
5
|
## Features
|
|
6
6
|
|
|
7
|
-
- 🎯 **TypeScript First**:
|
|
8
|
-
- 🔧 **
|
|
9
|
-
- 📦 **
|
|
10
|
-
- 🚀 **
|
|
7
|
+
- 🎯 **TypeScript First**: Fully typed with auto-generated types from OpenAPI specs
|
|
8
|
+
- 🔧 **Auto-generated**: SDK wrapper generated from OpenAPI spec
|
|
9
|
+
- 📦 **Integration-specific Config**: Each integration can have its own default settings
|
|
10
|
+
- 🚀 **Environment Variable Support**: Automatic fallback to environment variables
|
|
11
|
+
- 🔐 **Type-safe**: Full TypeScript support with strict type checking
|
|
11
12
|
|
|
12
13
|
## Installation
|
|
13
14
|
|
|
@@ -17,6 +18,66 @@ npm install samuel-agent-types-sdk
|
|
|
17
18
|
yarn add samuel-agent-types-sdk
|
|
18
19
|
```
|
|
19
20
|
|
|
21
|
+
## Usage
|
|
22
|
+
|
|
23
|
+
### Basic Usage with Environment Variables
|
|
24
|
+
|
|
25
|
+
Set environment variables:
|
|
26
|
+
```bash
|
|
27
|
+
export INTEGRATION_BASE_URL="https://api.example.com"
|
|
28
|
+
export PROJECT_ACCESS_KEY="your-access-key"
|
|
29
|
+
export DEFAULT_MODEL_ID="gpt-4"
|
|
30
|
+
export DEFAULT_PROVIDER="openai"
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Use the default instance:
|
|
34
|
+
```typescript
|
|
35
|
+
import { llm } from 'samuel-agent-types-sdk';
|
|
36
|
+
|
|
37
|
+
// ModelId and provider come from env vars
|
|
38
|
+
const response = await llm.generate({
|
|
39
|
+
messages: [
|
|
40
|
+
{ role: 'user', content: 'Hello!' }
|
|
41
|
+
]
|
|
42
|
+
});
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### Custom Instance with Config
|
|
46
|
+
|
|
47
|
+
```typescript
|
|
48
|
+
import { Llm } from 'samuel-agent-types-sdk';
|
|
49
|
+
|
|
50
|
+
const llm = new Llm({
|
|
51
|
+
accessKey: 'custom-access-key',
|
|
52
|
+
baseUrl: 'https://custom-api.example.com',
|
|
53
|
+
modelId: 'claude-3-opus-20240229',
|
|
54
|
+
provider: 'anthropic'
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
// Uses the config from constructor
|
|
58
|
+
const response = await llm.generate({
|
|
59
|
+
messages: [
|
|
60
|
+
{ role: 'user', content: 'Hello!' }
|
|
61
|
+
]
|
|
62
|
+
// model and provider will use defaults from constructor if not specified
|
|
63
|
+
});
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### Override Defaults Per Call
|
|
67
|
+
|
|
68
|
+
```typescript
|
|
69
|
+
import { llm } from 'samuel-agent-types-sdk';
|
|
70
|
+
|
|
71
|
+
// Override the default provider for this specific call
|
|
72
|
+
const response = await llm.generate({
|
|
73
|
+
messages: [
|
|
74
|
+
{ role: 'user', content: 'Hello!' }
|
|
75
|
+
],
|
|
76
|
+
provider: 'gemini', // Override default
|
|
77
|
+
model: 'gemini-pro' // Override default
|
|
78
|
+
});
|
|
79
|
+
```
|
|
80
|
+
|
|
20
81
|
## Development
|
|
21
82
|
|
|
22
83
|
### Prerequisites
|
|
@@ -41,6 +102,49 @@ yarn add samuel-agent-types-sdk
|
|
|
41
102
|
- `yarn format` - Format code with Prettier
|
|
42
103
|
- `yarn format:check` - Check code formatting
|
|
43
104
|
- `yarn clean` - Clean build artifacts
|
|
105
|
+
- `yarn download:swagger` - Download the latest OpenAPI spec
|
|
106
|
+
- `yarn generate` - Generate SDK wrapper from OpenAPI spec
|
|
107
|
+
- `yarn generate:types` - Generate TypeScript types from OpenAPI spec
|
|
108
|
+
|
|
109
|
+
### Adding Integration-Specific Defaults
|
|
110
|
+
|
|
111
|
+
To add default configuration for an integration, edit `sdk-config.json`:
|
|
112
|
+
|
|
113
|
+
```json
|
|
114
|
+
{
|
|
115
|
+
"llm": {
|
|
116
|
+
"defaults": {
|
|
117
|
+
"modelId": {
|
|
118
|
+
"envVar": "DEFAULT_MODEL_ID",
|
|
119
|
+
"type": "string",
|
|
120
|
+
"description": "Default model ID to use for LLM calls"
|
|
121
|
+
},
|
|
122
|
+
"provider": {
|
|
123
|
+
"envVar": "DEFAULT_PROVIDER",
|
|
124
|
+
"type": "string",
|
|
125
|
+
"description": "Default provider to use"
|
|
126
|
+
}
|
|
127
|
+
},
|
|
128
|
+
"applyDefaults": {
|
|
129
|
+
"generate": {
|
|
130
|
+
"model": "modelId",
|
|
131
|
+
"provider": "provider"
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
The `defaults` object defines:
|
|
139
|
+
- Configuration field name (e.g., `modelId`)
|
|
140
|
+
- Environment variable to use as fallback (e.g., `DEFAULT_MODEL_ID`)
|
|
141
|
+
- Type and description
|
|
142
|
+
|
|
143
|
+
The `applyDefaults` object maps operation names to parameter mappings:
|
|
144
|
+
- Key: operation name from OpenAPI (e.g., `generate`)
|
|
145
|
+
- Value: mapping of API parameter name to config field name
|
|
146
|
+
|
|
147
|
+
After modifying `sdk-config.json`, run `yarn generate` to regenerate the SDK wrapper.
|
|
44
148
|
|
|
45
149
|
### Project Structure
|
|
46
150
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http-client.d.ts","sourceRoot":"","sources":["../src/http-client.ts"],"names":[],"mappings":"AAAA,OAAc,EAAE,kBAAkB,EAAE,MAAM,OAAO,CAAC;AAClD,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAEhD,UAAU,UAAU;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,eAAO,MAAM,UAAU,+BAAsC,CAAC;
|
|
1
|
+
{"version":3,"file":"http-client.d.ts","sourceRoot":"","sources":["../src/http-client.ts"],"names":[],"mappings":"AAAA,OAAc,EAAE,kBAAkB,EAAE,MAAM,OAAO,CAAC;AAClD,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAEhD,UAAU,UAAU;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,eAAO,MAAM,UAAU,+BAAsC,CAAC;AA0B9D,eAAO,MAAM,WAAW,GAAU,CAAC,EACjC,QAAQ,kBAAkB,KACzB,OAAO,CAAC,CAAC,CAGX,CAAC"}
|
package/dist/http-client.js
CHANGED
|
@@ -8,14 +8,14 @@ const axios_1 = __importDefault(require("axios"));
|
|
|
8
8
|
const async_hooks_1 = require("async_hooks");
|
|
9
9
|
exports.sdkContext = new async_hooks_1.AsyncLocalStorage();
|
|
10
10
|
const axiosInstance = axios_1.default.create();
|
|
11
|
-
axiosInstance.interceptors.request.use(
|
|
11
|
+
axiosInstance.interceptors.request.use(config => {
|
|
12
12
|
const context = exports.sdkContext.getStore();
|
|
13
|
-
const baseURL = context?.baseUrl || process.env[
|
|
13
|
+
const baseURL = context?.baseUrl || process.env['INTEGRATION_BASE_URL'];
|
|
14
14
|
if (baseURL) {
|
|
15
15
|
config.baseURL = baseURL;
|
|
16
16
|
}
|
|
17
|
-
const accessKey = context?.accessKey || process.env[
|
|
18
|
-
const tenantId = process.env[
|
|
17
|
+
const accessKey = context?.accessKey || process.env['PROJECT_ACCESS_KEY'];
|
|
18
|
+
const tenantId = process.env['TENANT_ID'];
|
|
19
19
|
if (accessKey) {
|
|
20
20
|
config.headers = config.headers || {};
|
|
21
21
|
config.headers['x-project-access-key'] = accessKey;
|
package/dist/http-client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http-client.js","sourceRoot":"","sources":["../src/http-client.ts"],"names":[],"mappings":";;;;;;AAAA,kDAAkD;AAClD,6CAAgD;AAOnC,QAAA,UAAU,GAAG,IAAI,+BAAiB,EAAc,CAAC;AAE9D,MAAM,aAAa,GAAG,eAAK,CAAC,MAAM,EAAE,CAAC;AAErC,aAAa,CAAC,YAAY,CAAC,OAAO,CAAC,GAAG,CAAC,
|
|
1
|
+
{"version":3,"file":"http-client.js","sourceRoot":"","sources":["../src/http-client.ts"],"names":[],"mappings":";;;;;;AAAA,kDAAkD;AAClD,6CAAgD;AAOnC,QAAA,UAAU,GAAG,IAAI,+BAAiB,EAAc,CAAC;AAE9D,MAAM,aAAa,GAAG,eAAK,CAAC,MAAM,EAAE,CAAC;AAErC,aAAa,CAAC,YAAY,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE;IAC9C,MAAM,OAAO,GAAG,kBAAU,CAAC,QAAQ,EAAE,CAAC;IAEtC,MAAM,OAAO,GAAG,OAAO,EAAE,OAAO,IAAI,OAAO,CAAC,GAAG,CAAC,sBAAsB,CAAC,CAAC;IACxE,IAAI,OAAO,EAAE,CAAC;QACZ,MAAM,CAAC,OAAO,GAAG,OAAO,CAAC;IAC3B,CAAC;IAED,MAAM,SAAS,GAAG,OAAO,EAAE,SAAS,IAAI,OAAO,CAAC,GAAG,CAAC,oBAAoB,CAAC,CAAC;IAC1E,MAAM,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;IAE1C,IAAI,SAAS,EAAE,CAAC;QACd,MAAM,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO,IAAI,EAAE,CAAC;QACtC,MAAM,CAAC,OAAO,CAAC,sBAAsB,CAAC,GAAG,SAAS,CAAC;QACnD,IAAI,QAAQ,EAAE,CAAC;YACb,MAAM,CAAC,OAAO,CAAC,aAAa,CAAC,GAAG,QAAQ,CAAC;QAC3C,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC,CAAC;AAEI,MAAM,WAAW,GAAG,KAAK,EAC9B,MAA0B,EACd,EAAE;IACd,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,aAAa,CAAC,MAAM,CAAC,CAAC;IAC7C,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AALW,QAAA,WAAW,eAKtB"}
|
package/dist/index.d.ts
CHANGED
|
@@ -13,6 +13,8 @@ export declare class Llm {
|
|
|
13
13
|
constructor(options?: {
|
|
14
14
|
accessKey?: string;
|
|
15
15
|
baseUrl?: string;
|
|
16
|
+
modelId?: string;
|
|
17
|
+
provider?: string;
|
|
16
18
|
});
|
|
17
19
|
private withContext;
|
|
18
20
|
generate: (...args: Parameters<typeof this.api.generate>) => Promise<import("./generated-api").Generate200>;
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA;;;;;GAKG;AAEH;;GAEG;AACH,qBAAa,GAAG;IACd,OAAO,CAAC,MAAM,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA;;;;;GAKG;AAEH;;GAEG;AACH,qBAAa,GAAG;IACd,OAAO,CAAC,MAAM,CAES;IACvB,OAAO,CAAC,GAAG,CAAwC;gBAEvC,OAAO,CAAC,EAAE;QACpB,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;KACnB;IAaD,OAAO,CAAC,WAAW;IAInB,QAAQ,GAAI,GAAG,MAAM,UAAU,CAAC,OAAO,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,oDAKnD;CACP;AAED;;;;;GAKG;AACH,eAAO,MAAM,GAAG,KAAY,CAAC;AAG7B,cAAc,iBAAiB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -28,9 +28,18 @@ const http_client_1 = require("./http-client");
|
|
|
28
28
|
*/
|
|
29
29
|
class Llm {
|
|
30
30
|
constructor(options) {
|
|
31
|
-
this.generate = (...args) => this.withContext(() => this.api.generate(
|
|
31
|
+
this.generate = (...args) => this.withContext(() => this.api.generate({
|
|
32
|
+
...args[0],
|
|
33
|
+
...(args[0].model || this.config.modelId ? { model: args[0].model || this.config.modelId } : {}),
|
|
34
|
+
...(args[0].provider || this.config.provider ? { provider: args[0].provider || this.config.provider } : {})
|
|
35
|
+
}));
|
|
32
36
|
// Store config for this instance (uses env vars if not provided)
|
|
33
|
-
this.config =
|
|
37
|
+
this.config = {
|
|
38
|
+
...(options?.accessKey ? { accessKey: options.accessKey } : {}),
|
|
39
|
+
...(options?.baseUrl ? { baseUrl: options.baseUrl } : {}),
|
|
40
|
+
...(options?.modelId || process.env["LLM_MODEL"] ? { modelId: options?.modelId || process.env["LLM_MODEL"] } : {}),
|
|
41
|
+
...(options?.provider || process.env["LLM_PROVIDER"] ? { provider: options?.provider || process.env["LLM_PROVIDER"] } : {})
|
|
42
|
+
};
|
|
34
43
|
// Get the generated API methods
|
|
35
44
|
this.api = (0, generated_api_1.getIntegrationsAPI)();
|
|
36
45
|
}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,mDAAqD;AACrD,+CAA2C;AAE3C;;;;;GAKG;AAEH;;GAEG;AACH,MAA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