@openserv-labs/client 1.0.0
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/LICENSE +21 -0
- package/README.md +646 -0
- package/dist/agents-api.d.ts +139 -0
- package/dist/agents-api.d.ts.map +1 -0
- package/dist/agents-api.js +182 -0
- package/dist/client.d.ts +107 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +187 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +34 -0
- package/dist/integrations-api.d.ts +34 -0
- package/dist/integrations-api.d.ts.map +1 -0
- package/dist/integrations-api.js +46 -0
- package/dist/payments-api.d.ts +126 -0
- package/dist/payments-api.d.ts.map +1 -0
- package/dist/payments-api.js +155 -0
- package/dist/provision.d.ts +194 -0
- package/dist/provision.d.ts.map +1 -0
- package/dist/provision.js +541 -0
- package/dist/tasks-api.d.ts +103 -0
- package/dist/tasks-api.d.ts.map +1 -0
- package/dist/tasks-api.js +110 -0
- package/dist/triggers-api.d.ts +254 -0
- package/dist/triggers-api.d.ts.map +1 -0
- package/dist/triggers-api.js +309 -0
- package/dist/types.d.ts +219 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +5 -0
- package/dist/web3-api.d.ts +117 -0
- package/dist/web3-api.d.ts.map +1 -0
- package/dist/web3-api.js +185 -0
- package/dist/workflow.d.ts +27 -0
- package/dist/workflow.d.ts.map +1 -0
- package/dist/workflow.js +50 -0
- package/dist/workflows-api.d.ts +142 -0
- package/dist/workflows-api.d.ts.map +1 -0
- package/dist/workflows-api.js +357 -0
- package/package.json +70 -0
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import type { PlatformClient } from "./client";
|
|
2
|
+
import type { Agent, MarketplaceAgentsResponse } from "./types";
|
|
3
|
+
/**
|
|
4
|
+
* API for managing agents on the OpenServ platform.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```typescript
|
|
8
|
+
* const client = new PlatformClient({ apiKey: 'your-key' });
|
|
9
|
+
*
|
|
10
|
+
* // List your own agents
|
|
11
|
+
* const myAgents = await client.agents.list();
|
|
12
|
+
*
|
|
13
|
+
* // Search your own agents by name/description
|
|
14
|
+
* const myMatches = await client.agents.searchOwned({ query: 'data' });
|
|
15
|
+
*
|
|
16
|
+
* // List all public marketplace agents
|
|
17
|
+
* const marketplaceAgents = await client.agents.listMarketplace();
|
|
18
|
+
*
|
|
19
|
+
* // Search all marketplace agents (semantic search)
|
|
20
|
+
* const searchResults = await client.agents.listMarketplace({
|
|
21
|
+
* search: 'data processing',
|
|
22
|
+
* page: 1,
|
|
23
|
+
* pageSize: 20
|
|
24
|
+
* });
|
|
25
|
+
*
|
|
26
|
+
* // Create an agent
|
|
27
|
+
* const agent = await client.agents.create({
|
|
28
|
+
* name: 'My Agent',
|
|
29
|
+
* capabilities_description: 'Handles data processing',
|
|
30
|
+
* endpoint_url: 'https://my-agent.example.com'
|
|
31
|
+
* });
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
export declare class AgentsAPI {
|
|
35
|
+
private client;
|
|
36
|
+
constructor(client: PlatformClient);
|
|
37
|
+
/**
|
|
38
|
+
* List all agents owned by the authenticated user.
|
|
39
|
+
* @returns Array of agents
|
|
40
|
+
*/
|
|
41
|
+
list(): Promise<Agent[]>;
|
|
42
|
+
/**
|
|
43
|
+
* List all public agents from the marketplace.
|
|
44
|
+
* @param params - Optional parameters
|
|
45
|
+
* @param params.search - Search query to filter agents
|
|
46
|
+
* @param params.page - Page number (default: 1)
|
|
47
|
+
* @param params.pageSize - Number of items per page (default: 50)
|
|
48
|
+
* @param params.showPrivateAgents - Include private agents owned by the user (default: true)
|
|
49
|
+
* @returns Paginated marketplace agents response
|
|
50
|
+
*/
|
|
51
|
+
listMarketplace(params?: {
|
|
52
|
+
search?: string;
|
|
53
|
+
page?: number;
|
|
54
|
+
pageSize?: number;
|
|
55
|
+
showPrivateAgents?: boolean;
|
|
56
|
+
}): Promise<MarketplaceAgentsResponse>;
|
|
57
|
+
/**
|
|
58
|
+
* Get an agent by ID.
|
|
59
|
+
* @param params - Parameters object
|
|
60
|
+
* @param params.id - The agent ID
|
|
61
|
+
* @returns The agent
|
|
62
|
+
*/
|
|
63
|
+
get(params: {
|
|
64
|
+
id: number | string;
|
|
65
|
+
}): Promise<Agent>;
|
|
66
|
+
/**
|
|
67
|
+
* Search for agents owned by the authenticated user.
|
|
68
|
+
* Searches both name and capabilities_description fields.
|
|
69
|
+
* For marketplace-wide search, use listMarketplace({ search }) instead.
|
|
70
|
+
* @param params - Parameters object
|
|
71
|
+
* @param params.query - Search query to match against agent names and descriptions
|
|
72
|
+
* @returns Array of matching agents owned by the user
|
|
73
|
+
*/
|
|
74
|
+
searchOwned(params: {
|
|
75
|
+
query: string;
|
|
76
|
+
}): Promise<Agent[]>;
|
|
77
|
+
/**
|
|
78
|
+
* Create a new agent.
|
|
79
|
+
* @param params - Parameters object
|
|
80
|
+
* @param params.name - Unique name for the agent
|
|
81
|
+
* @param params.capabilities_description - Description of what the agent can do
|
|
82
|
+
* @param params.endpoint_url - URL where the agent is hosted
|
|
83
|
+
* @returns The created agent
|
|
84
|
+
*/
|
|
85
|
+
create(params: {
|
|
86
|
+
name: string;
|
|
87
|
+
capabilities_description: string;
|
|
88
|
+
endpoint_url: string;
|
|
89
|
+
}): Promise<Agent>;
|
|
90
|
+
/**
|
|
91
|
+
* Get the API key for an agent.
|
|
92
|
+
* @param params - Parameters object
|
|
93
|
+
* @param params.id - The agent ID
|
|
94
|
+
* @returns The agent's API key
|
|
95
|
+
*/
|
|
96
|
+
getApiKey(params: {
|
|
97
|
+
id: number | string;
|
|
98
|
+
}): Promise<string>;
|
|
99
|
+
/**
|
|
100
|
+
* Update an existing agent.
|
|
101
|
+
* @param params - Parameters object
|
|
102
|
+
* @param params.id - The agent ID to update
|
|
103
|
+
* @param params.endpoint_url - New endpoint URL (optional)
|
|
104
|
+
* @param params.name - New name (optional)
|
|
105
|
+
* @param params.capabilities_description - New description (optional)
|
|
106
|
+
* @returns The updated agent
|
|
107
|
+
*/
|
|
108
|
+
update(params: {
|
|
109
|
+
id: number | string;
|
|
110
|
+
endpoint_url?: string;
|
|
111
|
+
name?: string;
|
|
112
|
+
capabilities_description?: string;
|
|
113
|
+
}): Promise<Agent>;
|
|
114
|
+
/**
|
|
115
|
+
* Delete an agent.
|
|
116
|
+
* @param params - Parameters object
|
|
117
|
+
* @param params.id - The agent ID to delete
|
|
118
|
+
*/
|
|
119
|
+
delete(params: {
|
|
120
|
+
id: number | string;
|
|
121
|
+
}): Promise<void>;
|
|
122
|
+
/**
|
|
123
|
+
* Generate a new auth token for securing agent requests.
|
|
124
|
+
* Returns both the plaintext token (for the agent) and the hash (for the platform).
|
|
125
|
+
*/
|
|
126
|
+
generateAuthToken(): Promise<{
|
|
127
|
+
authToken: string;
|
|
128
|
+
authTokenHash: string;
|
|
129
|
+
}>;
|
|
130
|
+
/**
|
|
131
|
+
* Save the auth token hash to the platform for a specific agent.
|
|
132
|
+
* The platform will use this to verify requests to the agent.
|
|
133
|
+
*/
|
|
134
|
+
saveAuthToken(params: {
|
|
135
|
+
id: number | string;
|
|
136
|
+
authTokenHash: string;
|
|
137
|
+
}): Promise<void>;
|
|
138
|
+
}
|
|
139
|
+
//# sourceMappingURL=agents-api.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agents-api.d.ts","sourceRoot":"","sources":["../src/agents-api.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAC/C,OAAO,KAAK,EACV,KAAK,EAKL,yBAAyB,EAC1B,MAAM,SAAS,CAAC;AAEjB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,qBAAa,SAAS;IACR,OAAO,CAAC,MAAM;gBAAN,MAAM,EAAE,cAAc;IAE1C;;;OAGG;IACG,IAAI,IAAI,OAAO,CAAC,KAAK,EAAE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CAAC;QAClB,aAAa,EAAE,MAAM,CAAC;KACvB,CAAC;IAOF;;;OAGG;IACG,aAAa,CAAC,MAAM,EAAE;QAC1B,EAAE,EAAE,MAAM,GAAG,MAAM,CAAC;QACpB,aAAa,EAAE,MAAM,CAAC;KACvB,GAAG,OAAO,CAAC,IAAI,CAAC;CAKlB"}
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AgentsAPI = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* API for managing agents on the OpenServ platform.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* const client = new PlatformClient({ apiKey: 'your-key' });
|
|
10
|
+
*
|
|
11
|
+
* // List your own agents
|
|
12
|
+
* const myAgents = await client.agents.list();
|
|
13
|
+
*
|
|
14
|
+
* // Search your own agents by name/description
|
|
15
|
+
* const myMatches = await client.agents.searchOwned({ query: 'data' });
|
|
16
|
+
*
|
|
17
|
+
* // List all public marketplace agents
|
|
18
|
+
* const marketplaceAgents = await client.agents.listMarketplace();
|
|
19
|
+
*
|
|
20
|
+
* // Search all marketplace agents (semantic search)
|
|
21
|
+
* const searchResults = await client.agents.listMarketplace({
|
|
22
|
+
* search: 'data processing',
|
|
23
|
+
* page: 1,
|
|
24
|
+
* pageSize: 20
|
|
25
|
+
* });
|
|
26
|
+
*
|
|
27
|
+
* // Create an agent
|
|
28
|
+
* const agent = await client.agents.create({
|
|
29
|
+
* name: 'My Agent',
|
|
30
|
+
* capabilities_description: 'Handles data processing',
|
|
31
|
+
* endpoint_url: 'https://my-agent.example.com'
|
|
32
|
+
* });
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
class AgentsAPI {
|
|
36
|
+
client;
|
|
37
|
+
constructor(client) {
|
|
38
|
+
this.client = client;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* List all agents owned by the authenticated user.
|
|
42
|
+
* @returns Array of agents
|
|
43
|
+
*/
|
|
44
|
+
async list() {
|
|
45
|
+
const data = await this.client.get("/agents");
|
|
46
|
+
return data.items || data;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* List all public agents from the marketplace.
|
|
50
|
+
* @param params - Optional parameters
|
|
51
|
+
* @param params.search - Search query to filter agents
|
|
52
|
+
* @param params.page - Page number (default: 1)
|
|
53
|
+
* @param params.pageSize - Number of items per page (default: 50)
|
|
54
|
+
* @param params.showPrivateAgents - Include private agents owned by the user (default: true)
|
|
55
|
+
* @returns Paginated marketplace agents response
|
|
56
|
+
*/
|
|
57
|
+
async listMarketplace(params) {
|
|
58
|
+
return this.client.get("/marketplace/agents-classic", {
|
|
59
|
+
params: {
|
|
60
|
+
search: params?.search || "",
|
|
61
|
+
page: params?.page || 1,
|
|
62
|
+
pageSize: params?.pageSize || 50,
|
|
63
|
+
showPrivateAgents: params?.showPrivateAgents !== false ? "true" : "false",
|
|
64
|
+
},
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Get an agent by ID.
|
|
69
|
+
* @param params - Parameters object
|
|
70
|
+
* @param params.id - The agent ID
|
|
71
|
+
* @returns The agent
|
|
72
|
+
*/
|
|
73
|
+
async get(params) {
|
|
74
|
+
return this.client.get(`/agents/${params.id}`);
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Search for agents owned by the authenticated user.
|
|
78
|
+
* Searches both name and capabilities_description fields.
|
|
79
|
+
* For marketplace-wide search, use listMarketplace({ search }) instead.
|
|
80
|
+
* @param params - Parameters object
|
|
81
|
+
* @param params.query - Search query to match against agent names and descriptions
|
|
82
|
+
* @returns Array of matching agents owned by the user
|
|
83
|
+
*/
|
|
84
|
+
async searchOwned(params) {
|
|
85
|
+
const data = await this.client.get("/agents", {
|
|
86
|
+
params: { search: params.query },
|
|
87
|
+
});
|
|
88
|
+
return data.items || data;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Create a new agent.
|
|
92
|
+
* @param params - Parameters object
|
|
93
|
+
* @param params.name - Unique name for the agent
|
|
94
|
+
* @param params.capabilities_description - Description of what the agent can do
|
|
95
|
+
* @param params.endpoint_url - URL where the agent is hosted
|
|
96
|
+
* @returns The created agent
|
|
97
|
+
*/
|
|
98
|
+
async create(params) {
|
|
99
|
+
const data = await this.client.post("/agents", {
|
|
100
|
+
name: params.name,
|
|
101
|
+
capabilities_description: params.capabilities_description,
|
|
102
|
+
endpoint_url: params.endpoint_url,
|
|
103
|
+
kind: "external",
|
|
104
|
+
is_built_by_agent_builder: false,
|
|
105
|
+
});
|
|
106
|
+
return this.get({ id: data.id });
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Get the API key for an agent.
|
|
110
|
+
* @param params - Parameters object
|
|
111
|
+
* @param params.id - The agent ID
|
|
112
|
+
* @returns The agent's API key
|
|
113
|
+
*/
|
|
114
|
+
async getApiKey(params) {
|
|
115
|
+
const data = await this.client.post(`/agents/${params.id}/api-key`, {});
|
|
116
|
+
return data.apiKey;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Update an existing agent.
|
|
120
|
+
* @param params - Parameters object
|
|
121
|
+
* @param params.id - The agent ID to update
|
|
122
|
+
* @param params.endpoint_url - New endpoint URL (optional)
|
|
123
|
+
* @param params.name - New name (optional)
|
|
124
|
+
* @param params.capabilities_description - New description (optional)
|
|
125
|
+
* @returns The updated agent
|
|
126
|
+
*/
|
|
127
|
+
async update(params) {
|
|
128
|
+
const { id, endpoint_url, name, capabilities_description } = params;
|
|
129
|
+
// First get the current agent to preserve ALL required fields
|
|
130
|
+
const currentAgent = await this.get({ id });
|
|
131
|
+
// Build update payload - API uses PUT and requires ALL fields
|
|
132
|
+
// Note: scopes must be an object, not an array (API may return [] for empty scopes)
|
|
133
|
+
const scopes = currentAgent.scopes && !Array.isArray(currentAgent.scopes)
|
|
134
|
+
? currentAgent.scopes
|
|
135
|
+
: {};
|
|
136
|
+
const updatePayload = {
|
|
137
|
+
name: name ?? currentAgent.name,
|
|
138
|
+
capabilities_description: capabilities_description ?? currentAgent.capabilities_description,
|
|
139
|
+
endpoint_url: endpoint_url ?? currentAgent.endpoint_url,
|
|
140
|
+
kind: "external",
|
|
141
|
+
is_built_by_agent_builder: false,
|
|
142
|
+
// Required fields that must be preserved
|
|
143
|
+
approval_status: currentAgent.approval_status || "in-development",
|
|
144
|
+
is_listed_on_marketplace: currentAgent.is_listed_on_marketplace ?? false,
|
|
145
|
+
is_trading_agent: currentAgent.is_trading_agent ?? false,
|
|
146
|
+
scopes,
|
|
147
|
+
};
|
|
148
|
+
// Note: endpoint_url is required for external agents. The GET single agent
|
|
149
|
+
// endpoint doesn't return it, so it must be provided in the update params.
|
|
150
|
+
if (updatePayload.kind === "external" && !updatePayload.endpoint_url) {
|
|
151
|
+
throw new Error("endpoint_url is required when updating an external agent");
|
|
152
|
+
}
|
|
153
|
+
await this.client.put(`/agents/${id}`, updatePayload);
|
|
154
|
+
return this.get({ id });
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Delete an agent.
|
|
158
|
+
* @param params - Parameters object
|
|
159
|
+
* @param params.id - The agent ID to delete
|
|
160
|
+
*/
|
|
161
|
+
async delete(params) {
|
|
162
|
+
// Use developer endpoint - admin-only endpoint requires elevated permissions
|
|
163
|
+
await this.client.delete(`/agents/${params.id}/developer`);
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Generate a new auth token for securing agent requests.
|
|
167
|
+
* Returns both the plaintext token (for the agent) and the hash (for the platform).
|
|
168
|
+
*/
|
|
169
|
+
async generateAuthToken() {
|
|
170
|
+
return this.client.post("/agents/generate-auth-token", {});
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Save the auth token hash to the platform for a specific agent.
|
|
174
|
+
* The platform will use this to verify requests to the agent.
|
|
175
|
+
*/
|
|
176
|
+
async saveAuthToken(params) {
|
|
177
|
+
await this.client.post(`/agents/${params.id}/auth-token`, {
|
|
178
|
+
authTokenHash: params.authTokenHash,
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
exports.AgentsAPI = AgentsAPI;
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { type AxiosInstance, type AxiosRequestConfig } from "axios";
|
|
2
|
+
import { AgentsAPI } from "./agents-api";
|
|
3
|
+
import { IntegrationsAPI } from "./integrations-api";
|
|
4
|
+
import { TriggersAPI } from "./triggers-api";
|
|
5
|
+
import { TasksAPI } from "./tasks-api";
|
|
6
|
+
import { WorkflowsAPI } from "./workflows-api";
|
|
7
|
+
import { Web3API } from "./web3-api";
|
|
8
|
+
import { PaymentsAPI } from "./payments-api";
|
|
9
|
+
/**
|
|
10
|
+
* Client for interacting with the OpenServ Platform API.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* // Using API key authentication
|
|
15
|
+
* const client = new PlatformClient({ apiKey: 'your-api-key' });
|
|
16
|
+
*
|
|
17
|
+
* // Using environment variable
|
|
18
|
+
* const client = new PlatformClient(); // Uses OPENSERV_USER_API_KEY
|
|
19
|
+
*
|
|
20
|
+
* // Using wallet authentication
|
|
21
|
+
* const client = new PlatformClient();
|
|
22
|
+
* await client.authenticate(process.env.WALLET_PRIVATE_KEY);
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export declare class PlatformClient {
|
|
26
|
+
private _apiClient;
|
|
27
|
+
/** API for managing agents */
|
|
28
|
+
readonly agents: AgentsAPI;
|
|
29
|
+
/** API for managing integration connections */
|
|
30
|
+
readonly integrations: IntegrationsAPI;
|
|
31
|
+
/** API for managing workflow triggers */
|
|
32
|
+
readonly triggers: TriggersAPI;
|
|
33
|
+
/** API for managing workflow tasks */
|
|
34
|
+
readonly tasks: TasksAPI;
|
|
35
|
+
/** API for managing workflows */
|
|
36
|
+
readonly workflows: WorkflowsAPI;
|
|
37
|
+
/** API for Web3 operations (USDC top-up) */
|
|
38
|
+
readonly web3: Web3API;
|
|
39
|
+
/** API for x402 payments to access paid workflows */
|
|
40
|
+
readonly payments: PaymentsAPI;
|
|
41
|
+
/**
|
|
42
|
+
* Get the raw axios client for advanced use cases.
|
|
43
|
+
* @returns The underlying axios instance
|
|
44
|
+
*/
|
|
45
|
+
get rawClient(): AxiosInstance;
|
|
46
|
+
/**
|
|
47
|
+
* Make a GET request to the API.
|
|
48
|
+
* @param path - API endpoint path
|
|
49
|
+
* @param config - Optional Axios request config
|
|
50
|
+
* @returns Response data
|
|
51
|
+
*/
|
|
52
|
+
get<T>(path: string, config?: AxiosRequestConfig): Promise<T>;
|
|
53
|
+
/**
|
|
54
|
+
* Make a POST request to the API.
|
|
55
|
+
* @param path - API endpoint path
|
|
56
|
+
* @param data - Request body data
|
|
57
|
+
* @param config - Optional Axios request config
|
|
58
|
+
* @returns Response data
|
|
59
|
+
*/
|
|
60
|
+
post<T>(path: string, data?: unknown, config?: AxiosRequestConfig): Promise<T>;
|
|
61
|
+
/**
|
|
62
|
+
* Make a PUT request to the API.
|
|
63
|
+
* @param path - API endpoint path
|
|
64
|
+
* @param data - Request body data
|
|
65
|
+
* @param config - Optional Axios request config
|
|
66
|
+
* @returns Response data
|
|
67
|
+
*/
|
|
68
|
+
put<T>(path: string, data?: unknown, config?: AxiosRequestConfig): Promise<T>;
|
|
69
|
+
/**
|
|
70
|
+
* Make a DELETE request to the API.
|
|
71
|
+
* @param path - API endpoint path
|
|
72
|
+
* @param config - Optional Axios request config
|
|
73
|
+
* @returns Response data
|
|
74
|
+
*/
|
|
75
|
+
delete<T>(path: string, config?: AxiosRequestConfig): Promise<T>;
|
|
76
|
+
/**
|
|
77
|
+
* Creates a new PlatformClient instance.
|
|
78
|
+
*
|
|
79
|
+
* @param options - Configuration options
|
|
80
|
+
* @param options.apiKey - API key for authentication (defaults to OPENSERV_USER_API_KEY env var)
|
|
81
|
+
* @param options.baseUrl - Base URL for the API (defaults to https://api.openserv.ai)
|
|
82
|
+
*/
|
|
83
|
+
constructor(options?: {
|
|
84
|
+
apiKey?: string;
|
|
85
|
+
baseUrl?: string;
|
|
86
|
+
});
|
|
87
|
+
/**
|
|
88
|
+
* Authenticate using an Ethereum wallet (SIWE - EIP-4361).
|
|
89
|
+
*
|
|
90
|
+
* This method performs Sign-In with Ethereum authentication:
|
|
91
|
+
* 1. Gets a nonce from the platform
|
|
92
|
+
* 2. Signs the SIWE message with the wallet
|
|
93
|
+
* 3. Verifies the signature and receives an API key
|
|
94
|
+
*
|
|
95
|
+
* @param privateKey - Wallet private key (defaults to WALLET_PRIVATE_KEY env var)
|
|
96
|
+
* @returns The API key received from authentication
|
|
97
|
+
*
|
|
98
|
+
* @example
|
|
99
|
+
* ```typescript
|
|
100
|
+
* const client = new PlatformClient();
|
|
101
|
+
* const apiKey = await client.authenticate(process.env.WALLET_PRIVATE_KEY);
|
|
102
|
+
* // Client is now authenticated and ready to use
|
|
103
|
+
* ```
|
|
104
|
+
*/
|
|
105
|
+
authenticate(privateKey?: string): Promise<string>;
|
|
106
|
+
}
|
|
107
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAc,EAAE,KAAK,aAAa,EAAE,KAAK,kBAAkB,EAAE,MAAM,OAAO,CAAC;AAE3E,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACrC,OAAO,EAAE,WAAW,EAAE,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E,MAAM,CAAA;KAAE;IAqB3D;;;;;;;;;;;;;;;;;OAiBG;IACG,YAAY,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;CAiEzD"}
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.PlatformClient = void 0;
|
|
7
|
+
const axios_1 = __importDefault(require("axios"));
|
|
8
|
+
const ethers_1 = require("ethers");
|
|
9
|
+
const agents_api_1 = require("./agents-api");
|
|
10
|
+
const integrations_api_1 = require("./integrations-api");
|
|
11
|
+
const triggers_api_1 = require("./triggers-api");
|
|
12
|
+
const tasks_api_1 = require("./tasks-api");
|
|
13
|
+
const workflows_api_1 = require("./workflows-api");
|
|
14
|
+
const web3_api_1 = require("./web3-api");
|
|
15
|
+
const payments_api_1 = require("./payments-api");
|
|
16
|
+
const PLATFORM_URL = process.env.OPENSERV_API_URL || "https://api.openserv.ai";
|
|
17
|
+
/**
|
|
18
|
+
* Client for interacting with the OpenServ Platform API.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```typescript
|
|
22
|
+
* // Using API key authentication
|
|
23
|
+
* const client = new PlatformClient({ apiKey: 'your-api-key' });
|
|
24
|
+
*
|
|
25
|
+
* // Using environment variable
|
|
26
|
+
* const client = new PlatformClient(); // Uses OPENSERV_USER_API_KEY
|
|
27
|
+
*
|
|
28
|
+
* // Using wallet authentication
|
|
29
|
+
* const client = new PlatformClient();
|
|
30
|
+
* await client.authenticate(process.env.WALLET_PRIVATE_KEY);
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
class PlatformClient {
|
|
34
|
+
_apiClient;
|
|
35
|
+
/** API for managing agents */
|
|
36
|
+
agents;
|
|
37
|
+
/** API for managing integration connections */
|
|
38
|
+
integrations;
|
|
39
|
+
/** API for managing workflow triggers */
|
|
40
|
+
triggers;
|
|
41
|
+
/** API for managing workflow tasks */
|
|
42
|
+
tasks;
|
|
43
|
+
/** API for managing workflows */
|
|
44
|
+
workflows;
|
|
45
|
+
/** API for Web3 operations (USDC top-up) */
|
|
46
|
+
web3;
|
|
47
|
+
/** API for x402 payments to access paid workflows */
|
|
48
|
+
payments;
|
|
49
|
+
/**
|
|
50
|
+
* Get the raw axios client for advanced use cases.
|
|
51
|
+
* @returns The underlying axios instance
|
|
52
|
+
*/
|
|
53
|
+
get rawClient() {
|
|
54
|
+
return this._apiClient;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Make a GET request to the API.
|
|
58
|
+
* @param path - API endpoint path
|
|
59
|
+
* @param config - Optional Axios request config
|
|
60
|
+
* @returns Response data
|
|
61
|
+
*/
|
|
62
|
+
async get(path, config) {
|
|
63
|
+
const response = await this._apiClient.get(path, config);
|
|
64
|
+
return response.data;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Make a POST request to the API.
|
|
68
|
+
* @param path - API endpoint path
|
|
69
|
+
* @param data - Request body data
|
|
70
|
+
* @param config - Optional Axios request config
|
|
71
|
+
* @returns Response data
|
|
72
|
+
*/
|
|
73
|
+
async post(path, data, config) {
|
|
74
|
+
const response = await this._apiClient.post(path, data, config);
|
|
75
|
+
return response.data;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Make a PUT request to the API.
|
|
79
|
+
* @param path - API endpoint path
|
|
80
|
+
* @param data - Request body data
|
|
81
|
+
* @param config - Optional Axios request config
|
|
82
|
+
* @returns Response data
|
|
83
|
+
*/
|
|
84
|
+
async put(path, data, config) {
|
|
85
|
+
const response = await this._apiClient.put(path, data, config);
|
|
86
|
+
return response.data;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Make a DELETE request to the API.
|
|
90
|
+
* @param path - API endpoint path
|
|
91
|
+
* @param config - Optional Axios request config
|
|
92
|
+
* @returns Response data
|
|
93
|
+
*/
|
|
94
|
+
async delete(path, config) {
|
|
95
|
+
const response = await this._apiClient.delete(path, config);
|
|
96
|
+
return response.data;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Creates a new PlatformClient instance.
|
|
100
|
+
*
|
|
101
|
+
* @param options - Configuration options
|
|
102
|
+
* @param options.apiKey - API key for authentication (defaults to OPENSERV_USER_API_KEY env var)
|
|
103
|
+
* @param options.baseUrl - Base URL for the API (defaults to https://api.openserv.ai)
|
|
104
|
+
*/
|
|
105
|
+
constructor(options) {
|
|
106
|
+
const apiKey = options?.apiKey || process.env.OPENSERV_USER_API_KEY;
|
|
107
|
+
const baseUrl = options?.baseUrl || PLATFORM_URL;
|
|
108
|
+
this._apiClient = axios_1.default.create({
|
|
109
|
+
baseURL: baseUrl,
|
|
110
|
+
headers: {
|
|
111
|
+
"Content-Type": "application/json",
|
|
112
|
+
...(apiKey ? { "x-openserv-key": apiKey } : {}),
|
|
113
|
+
},
|
|
114
|
+
});
|
|
115
|
+
this.agents = new agents_api_1.AgentsAPI(this);
|
|
116
|
+
this.integrations = new integrations_api_1.IntegrationsAPI(this);
|
|
117
|
+
this.triggers = new triggers_api_1.TriggersAPI(this);
|
|
118
|
+
this.tasks = new tasks_api_1.TasksAPI(this);
|
|
119
|
+
this.workflows = new workflows_api_1.WorkflowsAPI(this);
|
|
120
|
+
this.web3 = new web3_api_1.Web3API(this);
|
|
121
|
+
this.payments = new payments_api_1.PaymentsAPI(this);
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Authenticate using an Ethereum wallet (SIWE - EIP-4361).
|
|
125
|
+
*
|
|
126
|
+
* This method performs Sign-In with Ethereum authentication:
|
|
127
|
+
* 1. Gets a nonce from the platform
|
|
128
|
+
* 2. Signs the SIWE message with the wallet
|
|
129
|
+
* 3. Verifies the signature and receives an API key
|
|
130
|
+
*
|
|
131
|
+
* @param privateKey - Wallet private key (defaults to WALLET_PRIVATE_KEY env var)
|
|
132
|
+
* @returns The API key received from authentication
|
|
133
|
+
*
|
|
134
|
+
* @example
|
|
135
|
+
* ```typescript
|
|
136
|
+
* const client = new PlatformClient();
|
|
137
|
+
* const apiKey = await client.authenticate(process.env.WALLET_PRIVATE_KEY);
|
|
138
|
+
* // Client is now authenticated and ready to use
|
|
139
|
+
* ```
|
|
140
|
+
*/
|
|
141
|
+
async authenticate(privateKey) {
|
|
142
|
+
const walletKey = privateKey || process.env.WALLET_PRIVATE_KEY;
|
|
143
|
+
if (!walletKey) {
|
|
144
|
+
// If no wallet key, assume API key auth is already set up
|
|
145
|
+
return "";
|
|
146
|
+
}
|
|
147
|
+
// Create wallet
|
|
148
|
+
const wallet = new ethers_1.ethers.Wallet(walletKey);
|
|
149
|
+
const walletAddress = wallet.address;
|
|
150
|
+
// Step 1: Get nonce from platform
|
|
151
|
+
const nonceResponse = await this._apiClient.post("/auth/wallet/nonce", {
|
|
152
|
+
walletAddress,
|
|
153
|
+
});
|
|
154
|
+
const { nonce, message: legacyMessage } = nonceResponse.data;
|
|
155
|
+
if (!nonce && !legacyMessage) {
|
|
156
|
+
throw new Error(`Nonce endpoint did not return nonce or message. Response: ${JSON.stringify(nonceResponse.data)}`);
|
|
157
|
+
}
|
|
158
|
+
// Construct SIWE-formatted message (EIP-4361)
|
|
159
|
+
const domain = "platform.openserv.ai";
|
|
160
|
+
const uri = "https://platform.openserv.ai";
|
|
161
|
+
const issuedAt = new Date().toISOString();
|
|
162
|
+
const message = legacyMessage ||
|
|
163
|
+
`${domain} wants you to sign in with your Ethereum account:
|
|
164
|
+
${walletAddress}
|
|
165
|
+
|
|
166
|
+
Sign in to OpenServ
|
|
167
|
+
|
|
168
|
+
URI: ${uri}
|
|
169
|
+
Version: 1
|
|
170
|
+
Chain ID: 1
|
|
171
|
+
Nonce: ${nonce}
|
|
172
|
+
Issued At: ${issuedAt}`;
|
|
173
|
+
// Step 2: Sign the message
|
|
174
|
+
const signature = await wallet.signMessage(message);
|
|
175
|
+
// Step 3: Verify signature and get API key
|
|
176
|
+
const verifyResponse = await this._apiClient.post("/auth/wallet/verify", {
|
|
177
|
+
walletAddress,
|
|
178
|
+
signature,
|
|
179
|
+
message,
|
|
180
|
+
});
|
|
181
|
+
const apiKey = verifyResponse.data.apiKey;
|
|
182
|
+
// Update client with API key header
|
|
183
|
+
this._apiClient.defaults.headers.common["x-openserv-key"] = apiKey;
|
|
184
|
+
return apiKey;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
exports.PlatformClient = PlatformClient;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export type { PaginatedResponse, IdResponse, ApiKeyResponse, NonceResponse, VerifyResponse, Agent, Category, MarketplaceAgent, MarketplaceAgentsResponse, TriggerDefinition, TaskDefinition, EdgeDefinition, WorkflowConfig, Trigger, Task, Edge, WorkflowData, UsdcTopupConfig, UsdcVerifyRequest, UsdcVerifyResponse, UsdcTopupResult, X402PaymentRequest, X402PaymentResult, } from "./types";
|
|
2
|
+
export type { InputSchemaProperty, InputSchema, WebhookTriggerConfig, X402TriggerConfig, CronTriggerConfig, ManualTriggerConfig, TriggerConfig, } from "./triggers-api";
|
|
3
|
+
export { triggers, inputSchemaToJsonSchema, triggerConfigToProps, } from "./triggers-api";
|
|
4
|
+
export { PlatformClient } from "./client";
|
|
5
|
+
export { Workflow } from "./workflow";
|
|
6
|
+
export { AgentsAPI } from "./agents-api";
|
|
7
|
+
export { IntegrationsAPI } from "./integrations-api";
|
|
8
|
+
export { TriggersAPI } from "./triggers-api";
|
|
9
|
+
export { TasksAPI } from "./tasks-api";
|
|
10
|
+
export { WorkflowsAPI } from "./workflows-api";
|
|
11
|
+
export { Web3API } from "./web3-api";
|
|
12
|
+
export { PaymentsAPI } from "./payments-api";
|
|
13
|
+
export type { IntegrationConnection } from "./integrations-api";
|
|
14
|
+
export type { ProvisionConfig, ProvisionResult, Logger } from "./provision";
|
|
15
|
+
export { provision, isProvisioned, getProvisionedInfo, clearProvisionedState, setLogger, } from "./provision";
|
|
16
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,YAAY,EAEV,iBAAiB,EACjB,UAAU,EACV,cAAc,EACd,aAAa,EACb,cAAc,EAEd,KAAK,EACL,QAAQ,EACR,gBAAgB,EAChB,yBAAyB,EACzB,iBAAiB,EACjB,cAAc,EACd,cAAc,EACd,cAAc,EACd,OAAO,EACP,IAAI,EACJ,IAAI,EACJ,YAAY,EAEZ,eAAe,EACf,iBAAiB,EACjB,kBAAkB,EAClB,eAAe,EAEf,kBAAkB,EAClB,iBAAiB,GAClB,MAAM,SAAS,CAAC;AAGjB,YAAY,EACV,mBAAmB,EACnB,WAAW,EACX,oBAAoB,EACpB,iBAAiB,EACjB,iBAAiB,EACjB,mBAAmB,EACnB,aAAa,GACd,MAAM,gBAAgB,CAAC;AAGxB,OAAO,EACL,QAAQ,EACR,uBAAuB,EACvB,oBAAoB,GACrB,MAAM,gBAAgB,CAAC;AAGxB,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAC1C,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACrC,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAG7C,YAAY,EAAE,qBAAqB,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