@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
package/dist/index.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.setLogger = exports.clearProvisionedState = exports.getProvisionedInfo = exports.isProvisioned = exports.provision = exports.PaymentsAPI = exports.Web3API = exports.WorkflowsAPI = exports.TasksAPI = exports.TriggersAPI = exports.IntegrationsAPI = exports.AgentsAPI = exports.Workflow = exports.PlatformClient = exports.triggerConfigToProps = exports.inputSchemaToJsonSchema = exports.triggers = void 0;
|
|
4
|
+
// Trigger factory and helpers
|
|
5
|
+
var triggers_api_1 = require("./triggers-api");
|
|
6
|
+
Object.defineProperty(exports, "triggers", { enumerable: true, get: function () { return triggers_api_1.triggers; } });
|
|
7
|
+
Object.defineProperty(exports, "inputSchemaToJsonSchema", { enumerable: true, get: function () { return triggers_api_1.inputSchemaToJsonSchema; } });
|
|
8
|
+
Object.defineProperty(exports, "triggerConfigToProps", { enumerable: true, get: function () { return triggers_api_1.triggerConfigToProps; } });
|
|
9
|
+
// Classes
|
|
10
|
+
var client_1 = require("./client");
|
|
11
|
+
Object.defineProperty(exports, "PlatformClient", { enumerable: true, get: function () { return client_1.PlatformClient; } });
|
|
12
|
+
var workflow_1 = require("./workflow");
|
|
13
|
+
Object.defineProperty(exports, "Workflow", { enumerable: true, get: function () { return workflow_1.Workflow; } });
|
|
14
|
+
var agents_api_1 = require("./agents-api");
|
|
15
|
+
Object.defineProperty(exports, "AgentsAPI", { enumerable: true, get: function () { return agents_api_1.AgentsAPI; } });
|
|
16
|
+
var integrations_api_1 = require("./integrations-api");
|
|
17
|
+
Object.defineProperty(exports, "IntegrationsAPI", { enumerable: true, get: function () { return integrations_api_1.IntegrationsAPI; } });
|
|
18
|
+
var triggers_api_2 = require("./triggers-api");
|
|
19
|
+
Object.defineProperty(exports, "TriggersAPI", { enumerable: true, get: function () { return triggers_api_2.TriggersAPI; } });
|
|
20
|
+
var tasks_api_1 = require("./tasks-api");
|
|
21
|
+
Object.defineProperty(exports, "TasksAPI", { enumerable: true, get: function () { return tasks_api_1.TasksAPI; } });
|
|
22
|
+
var workflows_api_1 = require("./workflows-api");
|
|
23
|
+
Object.defineProperty(exports, "WorkflowsAPI", { enumerable: true, get: function () { return workflows_api_1.WorkflowsAPI; } });
|
|
24
|
+
var web3_api_1 = require("./web3-api");
|
|
25
|
+
Object.defineProperty(exports, "Web3API", { enumerable: true, get: function () { return web3_api_1.Web3API; } });
|
|
26
|
+
var payments_api_1 = require("./payments-api");
|
|
27
|
+
Object.defineProperty(exports, "PaymentsAPI", { enumerable: true, get: function () { return payments_api_1.PaymentsAPI; } });
|
|
28
|
+
// Provision functions
|
|
29
|
+
var provision_1 = require("./provision");
|
|
30
|
+
Object.defineProperty(exports, "provision", { enumerable: true, get: function () { return provision_1.provision; } });
|
|
31
|
+
Object.defineProperty(exports, "isProvisioned", { enumerable: true, get: function () { return provision_1.isProvisioned; } });
|
|
32
|
+
Object.defineProperty(exports, "getProvisionedInfo", { enumerable: true, get: function () { return provision_1.getProvisionedInfo; } });
|
|
33
|
+
Object.defineProperty(exports, "clearProvisionedState", { enumerable: true, get: function () { return provision_1.clearProvisionedState; } });
|
|
34
|
+
Object.defineProperty(exports, "setLogger", { enumerable: true, get: function () { return provision_1.setLogger; } });
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { PlatformClient } from "./client";
|
|
2
|
+
export interface IntegrationConnection {
|
|
3
|
+
id: string;
|
|
4
|
+
name: string;
|
|
5
|
+
integrationId: string;
|
|
6
|
+
integrationName: string;
|
|
7
|
+
integrationDisplayName: string;
|
|
8
|
+
integrationDescription?: string | null;
|
|
9
|
+
integrationType: "nango" | "custom";
|
|
10
|
+
integrationLogo?: string | null;
|
|
11
|
+
}
|
|
12
|
+
export declare class IntegrationsAPI {
|
|
13
|
+
private client;
|
|
14
|
+
constructor(client: PlatformClient);
|
|
15
|
+
/**
|
|
16
|
+
* Get list of integration connections for the authenticated user
|
|
17
|
+
*/
|
|
18
|
+
listConnections(): Promise<IntegrationConnection[]>;
|
|
19
|
+
/**
|
|
20
|
+
* Create an integration connection for a custom integration (like manual-trigger, webhook-trigger, etc.)
|
|
21
|
+
*/
|
|
22
|
+
connect(params: {
|
|
23
|
+
identifier: string;
|
|
24
|
+
props?: Record<string, unknown>;
|
|
25
|
+
}): Promise<{
|
|
26
|
+
status: string;
|
|
27
|
+
}>;
|
|
28
|
+
/**
|
|
29
|
+
* Get the integration connection ID for a specific integration identifier.
|
|
30
|
+
* If no connection exists, creates one for custom integrations.
|
|
31
|
+
*/
|
|
32
|
+
getOrCreateConnection(identifier: string): Promise<string>;
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=integrations-api.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"integrations-api.d.ts","sourceRoot":"","sources":["../src/integrations-api.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAE/C,MAAM,WAAW,qBAAqB;IACpC,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,aAAa,EAAE,MAAM,CAAC;IACtB,eAAe,EAAE,MAAM,CAAC;IACxB,sBAAsB,EAAE,MAAM,CAAC;IAC/B,sBAAsB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACvC,eAAe,EAAE,OAAO,GAAG,QAAQ,CAAC;IACpC,eAAe,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACjC;AAED,qBAAa,eAAe;IACd,OAAO,CAAC,MAAM;gBAAN,MAAM,EAAE,cAAc;IAE1C;;OAEG;IACG,eAAe,IAAI,OAAO,CAAC,qBAAqB,EAAE,CAAC;IAIzD;;OAEG;IACG,OAAO,CAAC,MAAM,EAAE;QACpB,UAAU,EAAE,MAAM,CAAC;QACnB,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;KACjC,GAAG,OAAO,CAAC;QAAE,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC;IAQ/B;;;OAGG;IACG,qBAAqB,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;CAsBjE"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.IntegrationsAPI = void 0;
|
|
4
|
+
class IntegrationsAPI {
|
|
5
|
+
client;
|
|
6
|
+
constructor(client) {
|
|
7
|
+
this.client = client;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Get list of integration connections for the authenticated user
|
|
11
|
+
*/
|
|
12
|
+
async listConnections() {
|
|
13
|
+
return this.client.get("/integration/connections");
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Create an integration connection for a custom integration (like manual-trigger, webhook-trigger, etc.)
|
|
17
|
+
*/
|
|
18
|
+
async connect(params) {
|
|
19
|
+
return this.client.post("/integration/connection", {
|
|
20
|
+
type: "custom",
|
|
21
|
+
identifier: params.identifier,
|
|
22
|
+
props: params.props || {},
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Get the integration connection ID for a specific integration identifier.
|
|
27
|
+
* If no connection exists, creates one for custom integrations.
|
|
28
|
+
*/
|
|
29
|
+
async getOrCreateConnection(identifier) {
|
|
30
|
+
const connections = await this.listConnections();
|
|
31
|
+
const existing = connections.find((c) => c.integrationName === identifier);
|
|
32
|
+
if (existing) {
|
|
33
|
+
return existing.id;
|
|
34
|
+
}
|
|
35
|
+
// Create a new connection for custom integrations
|
|
36
|
+
await this.connect({ identifier });
|
|
37
|
+
// Fetch again to get the new connection ID
|
|
38
|
+
const updatedConnections = await this.listConnections();
|
|
39
|
+
const newConnection = updatedConnections.find((c) => c.integrationName === identifier);
|
|
40
|
+
if (!newConnection) {
|
|
41
|
+
throw new Error(`Failed to create integration connection for ${identifier}`);
|
|
42
|
+
}
|
|
43
|
+
return newConnection.id;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
exports.IntegrationsAPI = IntegrationsAPI;
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import type { PlatformClient } from "./client";
|
|
2
|
+
import type { X402PaymentRequest, X402PaymentResult } from "./types";
|
|
3
|
+
/**
|
|
4
|
+
* API for making x402 payments to access paid workflows.
|
|
5
|
+
*
|
|
6
|
+
* The x402 protocol allows workflows to be monetized - users pay to trigger them.
|
|
7
|
+
* This API provides methods to pay for and execute x402-protected workflows programmatically.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* const client = new PlatformClient();
|
|
12
|
+
*
|
|
13
|
+
* // Pay and execute an x402 workflow in one call - only wallet key needed!
|
|
14
|
+
* const result = await client.payments.payWorkflow({
|
|
15
|
+
* triggerUrl: 'https://api.openserv.ai/webhooks/x402/trigger/...',
|
|
16
|
+
* input: { query: 'Hello world' }
|
|
17
|
+
* });
|
|
18
|
+
*
|
|
19
|
+
* console.log(result.response); // Workflow response
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export declare class PaymentsAPI {
|
|
23
|
+
private client;
|
|
24
|
+
constructor(client: PlatformClient);
|
|
25
|
+
/**
|
|
26
|
+
* Pay for and execute an x402-protected workflow.
|
|
27
|
+
*
|
|
28
|
+
* This method handles the entire x402 payment flow automatically:
|
|
29
|
+
* 1. Creates a payment-enabled fetch wrapper using your wallet
|
|
30
|
+
* 2. Makes a request to the trigger URL
|
|
31
|
+
* 3. Automatically handles the 402 Payment Required response
|
|
32
|
+
* 4. Signs and submits the payment
|
|
33
|
+
* 5. Retries the request with payment proof
|
|
34
|
+
* 6. Returns the workflow response
|
|
35
|
+
*
|
|
36
|
+
* @param params - Payment parameters
|
|
37
|
+
* @param params.triggerUrl - The x402 trigger URL (webhookUrl from x402-services API or trigger.webhookUrl)
|
|
38
|
+
* @param params.privateKey - Wallet private key for payment (or uses WALLET_PRIVATE_KEY env var)
|
|
39
|
+
* @param params.input - Input data to pass to the workflow
|
|
40
|
+
* @returns Payment result with workflow response
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```typescript
|
|
44
|
+
* // Using environment variable for private key
|
|
45
|
+
* const result = await client.payments.payWorkflow({
|
|
46
|
+
* triggerUrl: 'https://api.openserv.ai/webhooks/x402/trigger/abc123',
|
|
47
|
+
* input: { prompt: 'Generate a summary' }
|
|
48
|
+
* });
|
|
49
|
+
*
|
|
50
|
+
* console.log(result.response); // Workflow execution result
|
|
51
|
+
* ```
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```typescript
|
|
55
|
+
* // Explicitly providing private key
|
|
56
|
+
* const result = await client.payments.payWorkflow({
|
|
57
|
+
* triggerUrl: workflow.triggers[0].webhookUrl,
|
|
58
|
+
* privateKey: '0x...',
|
|
59
|
+
* input: { query: 'What is the weather?' }
|
|
60
|
+
* });
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
payWorkflow(params: X402PaymentRequest): Promise<X402PaymentResult>;
|
|
64
|
+
/**
|
|
65
|
+
* Discover available x402 services from the platform.
|
|
66
|
+
*
|
|
67
|
+
* Lists all public x402-enabled workflows that can be paid for and executed.
|
|
68
|
+
* Each service includes pricing, input schema, and the webhook URL to call.
|
|
69
|
+
*
|
|
70
|
+
* @returns Array of available x402 services
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* ```typescript
|
|
74
|
+
* const services = await client.payments.discoverServices();
|
|
75
|
+
*
|
|
76
|
+
* for (const service of services) {
|
|
77
|
+
* console.log(`${service.name}: $${service.x402Pricing}`);
|
|
78
|
+
* console.log(`URL: ${service.webhookUrl}`);
|
|
79
|
+
* }
|
|
80
|
+
* ```
|
|
81
|
+
*/
|
|
82
|
+
discoverServices(): Promise<Array<{
|
|
83
|
+
id: string;
|
|
84
|
+
name: string;
|
|
85
|
+
description: string | null;
|
|
86
|
+
x402Pricing: string;
|
|
87
|
+
webhookUrl: string;
|
|
88
|
+
workspaceName: string;
|
|
89
|
+
ownerDisplayName: string;
|
|
90
|
+
}>>;
|
|
91
|
+
/**
|
|
92
|
+
* Get preflight information for an x402 trigger.
|
|
93
|
+
*
|
|
94
|
+
* Returns pricing, input schema, and wallet information for a trigger
|
|
95
|
+
* before making a payment. Useful for displaying payment UI.
|
|
96
|
+
*
|
|
97
|
+
* @param params - Parameters object
|
|
98
|
+
* @param params.token - The trigger token (from the webhook URL path)
|
|
99
|
+
* @returns Trigger preflight information including pricing and schema
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* ```typescript
|
|
103
|
+
* // Extract token from webhook URL: .../trigger/{token}
|
|
104
|
+
* const preflight = await client.payments.getTriggerPreflight({
|
|
105
|
+
* token: 'abc123def456'
|
|
106
|
+
* });
|
|
107
|
+
*
|
|
108
|
+
* console.log(`Price: ${preflight.x402Pricing}`);
|
|
109
|
+
* console.log(`Pay to: ${preflight.x402WalletAddress}`);
|
|
110
|
+
* ```
|
|
111
|
+
*/
|
|
112
|
+
getTriggerPreflight(params: {
|
|
113
|
+
token: string;
|
|
114
|
+
}): Promise<{
|
|
115
|
+
triggerId: string;
|
|
116
|
+
triggerName: string;
|
|
117
|
+
triggerDescription: string | null;
|
|
118
|
+
jsonSchema: Record<string, unknown>;
|
|
119
|
+
uiSchema: Record<string, unknown>;
|
|
120
|
+
x402Enabled: boolean;
|
|
121
|
+
x402Pricing: string;
|
|
122
|
+
x402WalletAddress: string;
|
|
123
|
+
erc8004AgentId: string | null;
|
|
124
|
+
}>;
|
|
125
|
+
}
|
|
126
|
+
//# sourceMappingURL=payments-api.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"payments-api.d.ts","sourceRoot":"","sources":["../src/payments-api.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAC/C,OAAO,KAAK,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAErE;;;;;;;;;;;;;;;;;;GAkBG;AACH,qBAAa,WAAW;IACV,OAAO,CAAC,MAAM;gBAAN,MAAM,EAAE,cAAc;IAE1C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAqCG;IACG,WAAW,CAAC,MAAM,EAAE,kBAAkB,GAAG,OAAO,CAAC,iBAAiB,CAAC;IA+CzE;;;;;;;;;;;;;;;;;OAiBG;IACG,gBAAgB,IAAI,OAAO,CAC/B,KAAK,CAAC;QACJ,EAAE,EAAE,MAAM,CAAC;QACX,IAAI,EAAE,MAAM,CAAC;QACb,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;QAC3B,WAAW,EAAE,MAAM,CAAC;QACpB,UAAU,EAAE,MAAM,CAAC;QACnB,aAAa,EAAE,MAAM,CAAC;QACtB,gBAAgB,EAAE,MAAM,CAAC;KAC1B,CAAC,CACH;IAmBD;;;;;;;;;;;;;;;;;;;;OAoBG;IACG,mBAAmB,CAAC,MAAM,EAAE;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC;QAC5D,SAAS,EAAE,MAAM,CAAC;QAClB,WAAW,EAAE,MAAM,CAAC;QACpB,kBAAkB,EAAE,MAAM,GAAG,IAAI,CAAC;QAClC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QACpC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QAClC,WAAW,EAAE,OAAO,CAAC;QACrB,WAAW,EAAE,MAAM,CAAC;QACpB,iBAAiB,EAAE,MAAM,CAAC;QAC1B,cAAc,EAAE,MAAM,GAAG,IAAI,CAAC;KAC/B,CAAC;CAeH"}
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PaymentsAPI = void 0;
|
|
4
|
+
const accounts_1 = require("viem/accounts");
|
|
5
|
+
const x402_fetch_1 = require("x402-fetch");
|
|
6
|
+
/**
|
|
7
|
+
* API for making x402 payments to access paid workflows.
|
|
8
|
+
*
|
|
9
|
+
* The x402 protocol allows workflows to be monetized - users pay to trigger them.
|
|
10
|
+
* This API provides methods to pay for and execute x402-protected workflows programmatically.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* const client = new PlatformClient();
|
|
15
|
+
*
|
|
16
|
+
* // Pay and execute an x402 workflow in one call - only wallet key needed!
|
|
17
|
+
* const result = await client.payments.payWorkflow({
|
|
18
|
+
* triggerUrl: 'https://api.openserv.ai/webhooks/x402/trigger/...',
|
|
19
|
+
* input: { query: 'Hello world' }
|
|
20
|
+
* });
|
|
21
|
+
*
|
|
22
|
+
* console.log(result.response); // Workflow response
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
class PaymentsAPI {
|
|
26
|
+
client;
|
|
27
|
+
constructor(client) {
|
|
28
|
+
this.client = client;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Pay for and execute an x402-protected workflow.
|
|
32
|
+
*
|
|
33
|
+
* This method handles the entire x402 payment flow automatically:
|
|
34
|
+
* 1. Creates a payment-enabled fetch wrapper using your wallet
|
|
35
|
+
* 2. Makes a request to the trigger URL
|
|
36
|
+
* 3. Automatically handles the 402 Payment Required response
|
|
37
|
+
* 4. Signs and submits the payment
|
|
38
|
+
* 5. Retries the request with payment proof
|
|
39
|
+
* 6. Returns the workflow response
|
|
40
|
+
*
|
|
41
|
+
* @param params - Payment parameters
|
|
42
|
+
* @param params.triggerUrl - The x402 trigger URL (webhookUrl from x402-services API or trigger.webhookUrl)
|
|
43
|
+
* @param params.privateKey - Wallet private key for payment (or uses WALLET_PRIVATE_KEY env var)
|
|
44
|
+
* @param params.input - Input data to pass to the workflow
|
|
45
|
+
* @returns Payment result with workflow response
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```typescript
|
|
49
|
+
* // Using environment variable for private key
|
|
50
|
+
* const result = await client.payments.payWorkflow({
|
|
51
|
+
* triggerUrl: 'https://api.openserv.ai/webhooks/x402/trigger/abc123',
|
|
52
|
+
* input: { prompt: 'Generate a summary' }
|
|
53
|
+
* });
|
|
54
|
+
*
|
|
55
|
+
* console.log(result.response); // Workflow execution result
|
|
56
|
+
* ```
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* ```typescript
|
|
60
|
+
* // Explicitly providing private key
|
|
61
|
+
* const result = await client.payments.payWorkflow({
|
|
62
|
+
* triggerUrl: workflow.triggers[0].webhookUrl,
|
|
63
|
+
* privateKey: '0x...',
|
|
64
|
+
* input: { query: 'What is the weather?' }
|
|
65
|
+
* });
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
async payWorkflow(params) {
|
|
69
|
+
const privateKey = params.privateKey || process.env.WALLET_PRIVATE_KEY;
|
|
70
|
+
if (!privateKey) {
|
|
71
|
+
throw new Error("Private key is required. Provide it as a parameter or set WALLET_PRIVATE_KEY env var.");
|
|
72
|
+
}
|
|
73
|
+
// Create account from private key (for getting address)
|
|
74
|
+
const account = (0, accounts_1.privateKeyToAccount)(privateKey);
|
|
75
|
+
// Create signer for x402 payments on Base network
|
|
76
|
+
const signer = await (0, x402_fetch_1.createSigner)("base", privateKey);
|
|
77
|
+
// Wrap fetch with x402 payment handling
|
|
78
|
+
const x402Fetch = (0, x402_fetch_1.wrapFetchWithPayment)(fetch, signer);
|
|
79
|
+
// Make the request - x402Fetch automatically handles 402 responses
|
|
80
|
+
const response = await x402Fetch(params.triggerUrl, {
|
|
81
|
+
method: "POST",
|
|
82
|
+
headers: { "Content-Type": "application/json" },
|
|
83
|
+
body: JSON.stringify({
|
|
84
|
+
buyerAddress: account.address,
|
|
85
|
+
payload: params.input || {},
|
|
86
|
+
}),
|
|
87
|
+
});
|
|
88
|
+
if (!response.ok) {
|
|
89
|
+
const errorData = await response.json().catch(() => ({}));
|
|
90
|
+
throw new Error(`Workflow execution failed: ${response.status} ${JSON.stringify(errorData)}`);
|
|
91
|
+
}
|
|
92
|
+
const responseData = await response.json();
|
|
93
|
+
return {
|
|
94
|
+
success: true,
|
|
95
|
+
txHash: "", // x402 handles this internally, tx hash not exposed
|
|
96
|
+
price: "", // Price is handled by x402 protocol
|
|
97
|
+
response: responseData,
|
|
98
|
+
network: "base",
|
|
99
|
+
chainId: 8453,
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Discover available x402 services from the platform.
|
|
104
|
+
*
|
|
105
|
+
* Lists all public x402-enabled workflows that can be paid for and executed.
|
|
106
|
+
* Each service includes pricing, input schema, and the webhook URL to call.
|
|
107
|
+
*
|
|
108
|
+
* @returns Array of available x402 services
|
|
109
|
+
*
|
|
110
|
+
* @example
|
|
111
|
+
* ```typescript
|
|
112
|
+
* const services = await client.payments.discoverServices();
|
|
113
|
+
*
|
|
114
|
+
* for (const service of services) {
|
|
115
|
+
* console.log(`${service.name}: $${service.x402Pricing}`);
|
|
116
|
+
* console.log(`URL: ${service.webhookUrl}`);
|
|
117
|
+
* }
|
|
118
|
+
* ```
|
|
119
|
+
*/
|
|
120
|
+
async discoverServices() {
|
|
121
|
+
const response = await this.client.get("/x402-services");
|
|
122
|
+
return response.services;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Get preflight information for an x402 trigger.
|
|
126
|
+
*
|
|
127
|
+
* Returns pricing, input schema, and wallet information for a trigger
|
|
128
|
+
* before making a payment. Useful for displaying payment UI.
|
|
129
|
+
*
|
|
130
|
+
* @param params - Parameters object
|
|
131
|
+
* @param params.token - The trigger token (from the webhook URL path)
|
|
132
|
+
* @returns Trigger preflight information including pricing and schema
|
|
133
|
+
*
|
|
134
|
+
* @example
|
|
135
|
+
* ```typescript
|
|
136
|
+
* // Extract token from webhook URL: .../trigger/{token}
|
|
137
|
+
* const preflight = await client.payments.getTriggerPreflight({
|
|
138
|
+
* token: 'abc123def456'
|
|
139
|
+
* });
|
|
140
|
+
*
|
|
141
|
+
* console.log(`Price: ${preflight.x402Pricing}`);
|
|
142
|
+
* console.log(`Pay to: ${preflight.x402WalletAddress}`);
|
|
143
|
+
* ```
|
|
144
|
+
*/
|
|
145
|
+
async getTriggerPreflight(params) {
|
|
146
|
+
// This endpoint is public and doesn't require authentication
|
|
147
|
+
const response = await fetch(`https://api.openserv.ai/webhooks/trigger/${params.token}`);
|
|
148
|
+
if (!response.ok) {
|
|
149
|
+
const errorData = await response.json().catch(() => ({}));
|
|
150
|
+
throw new Error(`Failed to get trigger preflight: ${response.status} ${JSON.stringify(errorData)}`);
|
|
151
|
+
}
|
|
152
|
+
return response.json();
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
exports.PaymentsAPI = PaymentsAPI;
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
import { type TriggerConfig } from "./triggers-api";
|
|
2
|
+
/**
|
|
3
|
+
* Configuration for provisioning an agent and workflow.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```typescript
|
|
7
|
+
* const config: ProvisionConfig = {
|
|
8
|
+
* agent: {
|
|
9
|
+
* name: 'my-agent',
|
|
10
|
+
* description: 'Handles API requests'
|
|
11
|
+
* },
|
|
12
|
+
* workflow: {
|
|
13
|
+
* name: 'api-workflow',
|
|
14
|
+
* trigger: triggers.webhook({ waitForCompletion: true }),
|
|
15
|
+
* task: {
|
|
16
|
+
* description: 'Process incoming requests',
|
|
17
|
+
* body: 'Handle the webhook payload'
|
|
18
|
+
* }
|
|
19
|
+
* }
|
|
20
|
+
* };
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export interface ProvisionConfig {
|
|
24
|
+
/** Agent configuration */
|
|
25
|
+
agent: {
|
|
26
|
+
/** Unique name for the agent */
|
|
27
|
+
name: string;
|
|
28
|
+
/** Description of the agent's capabilities */
|
|
29
|
+
description: string;
|
|
30
|
+
/**
|
|
31
|
+
* URL where the agent is hosted.
|
|
32
|
+
* Optional - when using @openserv-labs/sdk v2.0.0+, the endpoint is automatically
|
|
33
|
+
* set to https://agents-proxy.openserv.ai when run(agent) is called.
|
|
34
|
+
* Only provide this if your agent runs with a different publicly accessible URL.
|
|
35
|
+
*/
|
|
36
|
+
endpointUrl?: string;
|
|
37
|
+
};
|
|
38
|
+
/** Workflow configuration */
|
|
39
|
+
workflow: {
|
|
40
|
+
/** Name for the workflow */
|
|
41
|
+
name: string;
|
|
42
|
+
/** Trigger configuration (use triggers factory) */
|
|
43
|
+
trigger: TriggerConfig;
|
|
44
|
+
/** Optional task configuration */
|
|
45
|
+
task?: {
|
|
46
|
+
/** Task description */
|
|
47
|
+
description?: string;
|
|
48
|
+
/** Detailed task body */
|
|
49
|
+
body?: string;
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Result from provisioning an agent and workflow.
|
|
55
|
+
*/
|
|
56
|
+
export interface ProvisionResult {
|
|
57
|
+
/** The created agent's ID */
|
|
58
|
+
agentId: number;
|
|
59
|
+
/** API key for the agent */
|
|
60
|
+
apiKey: string;
|
|
61
|
+
/** Auth token for securing agent requests (if generated) */
|
|
62
|
+
authToken?: string;
|
|
63
|
+
/** The created workflow's ID */
|
|
64
|
+
workflowId: number;
|
|
65
|
+
/** The created trigger's ID */
|
|
66
|
+
triggerId: string;
|
|
67
|
+
/** Token for the trigger (used in URLs) */
|
|
68
|
+
triggerToken: string;
|
|
69
|
+
/** Paywall URL for x402 triggers */
|
|
70
|
+
paywallUrl?: string;
|
|
71
|
+
/** API endpoint URL for webhook triggers */
|
|
72
|
+
apiEndpoint?: string;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Logger interface for provision operations.
|
|
76
|
+
* Implement this to customize logging behavior.
|
|
77
|
+
*/
|
|
78
|
+
export interface Logger {
|
|
79
|
+
/** Log informational messages */
|
|
80
|
+
info: (...args: unknown[]) => void;
|
|
81
|
+
/** Log warning messages */
|
|
82
|
+
warn: (...args: unknown[]) => void;
|
|
83
|
+
/** Log error messages */
|
|
84
|
+
error: (...args: unknown[]) => void;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Set a custom logger for provision operations.
|
|
88
|
+
*
|
|
89
|
+
* @param customLogger - Logger implementation to use
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* ```typescript
|
|
93
|
+
* setLogger({
|
|
94
|
+
* info: (...args) => myLogger.info(...args),
|
|
95
|
+
* warn: (...args) => myLogger.warn(...args),
|
|
96
|
+
* error: (...args) => myLogger.error(...args)
|
|
97
|
+
* });
|
|
98
|
+
* ```
|
|
99
|
+
*/
|
|
100
|
+
export declare function setLogger(customLogger: Logger): void;
|
|
101
|
+
/**
|
|
102
|
+
* Provision an agent and workflow on the OpenServ platform.
|
|
103
|
+
* This function handles:
|
|
104
|
+
* - Wallet creation/retrieval
|
|
105
|
+
* - Platform authentication (with session persistence)
|
|
106
|
+
* - Agent registration/update
|
|
107
|
+
* - Workflow creation/update
|
|
108
|
+
* - State persistence to .openserv.json
|
|
109
|
+
*
|
|
110
|
+
* @param config - Provisioning configuration
|
|
111
|
+
* @returns Provision result with IDs and URLs
|
|
112
|
+
*
|
|
113
|
+
* @example
|
|
114
|
+
* ```ts
|
|
115
|
+
* import { provision, triggers } from '@openserv-labs/client';
|
|
116
|
+
*
|
|
117
|
+
* const result = await provision({
|
|
118
|
+
* agent: {
|
|
119
|
+
* name: 'my-agent',
|
|
120
|
+
* description: 'My autonomous agent',
|
|
121
|
+
* // endpointUrl is optional - SDK v2.0.0+ auto-updates to agents-proxy when run(agent) is called
|
|
122
|
+
* },
|
|
123
|
+
* workflow: {
|
|
124
|
+
* name: 'default',
|
|
125
|
+
* trigger: triggers.webhook(),
|
|
126
|
+
* task: {
|
|
127
|
+
* description: 'Process incoming requests',
|
|
128
|
+
* },
|
|
129
|
+
* },
|
|
130
|
+
* });
|
|
131
|
+
*
|
|
132
|
+
* console.log('Agent ID:', result.agentId);
|
|
133
|
+
* console.log('API Endpoint:', result.apiEndpoint);
|
|
134
|
+
* ```
|
|
135
|
+
*/
|
|
136
|
+
export declare function provision(config: ProvisionConfig): Promise<ProvisionResult>;
|
|
137
|
+
/**
|
|
138
|
+
* Check if an agent and workflow are already provisioned.
|
|
139
|
+
*
|
|
140
|
+
* This checks the local `.openserv.json` state file.
|
|
141
|
+
*
|
|
142
|
+
* @param agentName - Name of the agent to check
|
|
143
|
+
* @param workflowName - Name of the workflow (defaults to "default")
|
|
144
|
+
* @returns True if both agent and workflow are provisioned
|
|
145
|
+
*
|
|
146
|
+
* @example
|
|
147
|
+
* ```typescript
|
|
148
|
+
* if (isProvisioned('my-agent', 'api-workflow')) {
|
|
149
|
+
* console.log('Already provisioned!');
|
|
150
|
+
* } else {
|
|
151
|
+
* await provision(config);
|
|
152
|
+
* }
|
|
153
|
+
* ```
|
|
154
|
+
*/
|
|
155
|
+
export declare function isProvisioned(agentName: string, workflowName?: string): boolean;
|
|
156
|
+
/**
|
|
157
|
+
* Get provisioned workflow info from the local state file.
|
|
158
|
+
*
|
|
159
|
+
* @param agentName - Name of the agent
|
|
160
|
+
* @param workflowName - Name of the workflow (defaults to "default")
|
|
161
|
+
* @returns Object with agent and workflow details, or null if not provisioned
|
|
162
|
+
*
|
|
163
|
+
* @example
|
|
164
|
+
* ```typescript
|
|
165
|
+
* const info = getProvisionedInfo('my-agent', 'api-workflow');
|
|
166
|
+
* if (info) {
|
|
167
|
+
* console.log('Agent ID:', info.agentId);
|
|
168
|
+
* console.log('Workflow ID:', info.workflowId);
|
|
169
|
+
* }
|
|
170
|
+
* ```
|
|
171
|
+
*/
|
|
172
|
+
export declare function getProvisionedInfo(agentName: string, workflowName?: string): {
|
|
173
|
+
agentId?: number;
|
|
174
|
+
apiKey?: string;
|
|
175
|
+
authToken?: string;
|
|
176
|
+
workflowId?: number;
|
|
177
|
+
triggerId?: string;
|
|
178
|
+
triggerToken?: string;
|
|
179
|
+
} | null;
|
|
180
|
+
/**
|
|
181
|
+
* Clear all provisioned state.
|
|
182
|
+
*
|
|
183
|
+
* This deletes the `.openserv.json` file. Useful for testing or resetting.
|
|
184
|
+
* Note: This does not delete resources from the platform, only the local state file.
|
|
185
|
+
*
|
|
186
|
+
* @example
|
|
187
|
+
* ```typescript
|
|
188
|
+
* clearProvisionedState();
|
|
189
|
+
* // Now provision will create new resources
|
|
190
|
+
* await provision(config);
|
|
191
|
+
* ```
|
|
192
|
+
*/
|
|
193
|
+
export declare function clearProvisionedState(): void;
|
|
194
|
+
//# sourceMappingURL=provision.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provision.d.ts","sourceRoot":"","sources":["../src/provision.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,aAAa,EAAwB,MAAM,gBAAgB,CAAC;AAM1E;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,WAAW,eAAe;IAC9B,0BAA0B;IAC1B,KAAK,EAAE;QACL,gCAAgC;QAChC,IAAI,EAAE,MAAM,CAAC;QACb,8CAA8C;QAC9C,WAAW,EAAE,MAAM,CAAC;QACpB;;;;;WAKG;QACH,WAAW,CAAC,EAAE,MAAM,CAAC;KACtB,CAAC;IACF,6BAA6B;IAC7B,QAAQ,EAAE;QACR,4BAA4B;QAC5B,IAAI,EAAE,MAAM,CAAC;QACb,mDAAmD;QACnD,OAAO,EAAE,aAAa,CAAC;QACvB,kCAAkC;QAClC,IAAI,CAAC,EAAE;YACL,uBAAuB;YACvB,WAAW,CAAC,EAAE,MAAM,CAAC;YACrB,yBAAyB;YACzB,IAAI,CAAC,EAAE,MAAM,CAAC;SACf,CAAC;KACH,CAAC;CACH;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,6BAA6B;IAC7B,OAAO,EAAE,MAAM,CAAC;IAChB,4BAA4B;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,4DAA4D;IAC5D,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,gCAAgC;IAChC,UAAU,EAAE,MAAM,CAAC;IACnB,+BAA+B;IAC/B,SAAS,EAAE,MAAM,CAAC;IAClB,2CAA2C;IAC3C,YAAY,EAAE,MAAM,CAAC;IACrB,oCAAoC;IACpC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,4CAA4C;IAC5C,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AA2BD;;;GAGG;AACH,MAAM,WAAW,MAAM;IACrB,iCAAiC;IACjC,IAAI,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,CAAC;IACnC,2BAA2B;IAC3B,IAAI,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,CAAC;IACnC,yBAAyB;IACzB,KAAK,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,CAAC;CACrC;AAUD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,SAAS,CAAC,YAAY,EAAE,MAAM,GAAG,IAAI,CAEpD;AA2bD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,wBAAsB,SAAS,CAC7B,MAAM,EAAE,eAAe,GACtB,OAAO,CAAC,eAAe,CAAC,CAkC1B;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,aAAa,CAC3B,SAAS,EAAE,MAAM,EACjB,YAAY,CAAC,EAAE,MAAM,GACpB,OAAO,CAMT;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,kBAAkB,CAChC,SAAS,EAAE,MAAM,EACjB,YAAY,CAAC,EAAE,MAAM,GACpB;IACD,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB,GAAG,IAAI,CAmBP;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,qBAAqB,IAAI,IAAI,CAU5C"}
|