@applica-software-guru/persona-sdk 0.1.3 → 0.1.5
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 +97 -7
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -20,29 +20,70 @@ const sdk = new PersonaSdk(
|
|
|
20
20
|
'https://persona.applica.guru/workflows'
|
|
21
21
|
);
|
|
22
22
|
|
|
23
|
-
// Authenticate with API key
|
|
24
|
-
const agents = await sdk.agents('
|
|
23
|
+
// Authenticate with a project API key
|
|
24
|
+
const agents = await sdk.agents('prs_your_project_api_key').list(null, 1, 20);
|
|
25
|
+
console.log(`Total agents: ${agents.total}`);
|
|
25
26
|
```
|
|
26
27
|
|
|
28
|
+
The `PersonaSdk` constructor takes the base URL of persona-core and (optionally)
|
|
29
|
+
the base URL of the workflows service. Each resource is exposed as a factory
|
|
30
|
+
method that requires authentication credentials.
|
|
31
|
+
|
|
27
32
|
## Authentication
|
|
28
33
|
|
|
29
|
-
The SDK supports two authentication methods
|
|
34
|
+
The SDK supports two authentication methods. Pass either a string (API key) or
|
|
35
|
+
an `AuthenticationProvider` instance to any resource factory.
|
|
36
|
+
|
|
37
|
+
### API Key
|
|
38
|
+
|
|
39
|
+
The simplest method — pass the API key string directly. The SDK wraps it in an
|
|
40
|
+
`ApiKeyAuthenticationProvider` and sends it as the `x-persona-apikey` header.
|
|
41
|
+
|
|
42
|
+
Accepts:
|
|
30
43
|
|
|
31
|
-
|
|
44
|
+
- **Master key** — full admin access (server-to-server only)
|
|
45
|
+
- **Project API key** (`prs_...`) — scoped to a single project
|
|
46
|
+
- **Agent API key** (`prs_ag_...`) — scoped to a single agent
|
|
32
47
|
|
|
33
48
|
```typescript
|
|
34
|
-
const projects = await sdk.projects('
|
|
49
|
+
const projects = await sdk.projects('prs_your_project_api_key').getMine();
|
|
35
50
|
```
|
|
36
51
|
|
|
37
|
-
### Bearer Token
|
|
52
|
+
### IAM Bearer Token
|
|
53
|
+
|
|
54
|
+
For applications that authenticate end users via IAM, pass a
|
|
55
|
+
`BearerTokenAuthenticationProvider` with a valid JWT:
|
|
38
56
|
|
|
39
57
|
```typescript
|
|
40
58
|
import { BearerTokenAuthenticationProvider } from '@applica-software-guru/persona-sdk';
|
|
41
59
|
|
|
42
|
-
const auth = new BearerTokenAuthenticationProvider(
|
|
60
|
+
const auth = new BearerTokenAuthenticationProvider(iamJwtToken);
|
|
43
61
|
const projects = await sdk.projects(auth).getMine();
|
|
44
62
|
```
|
|
45
63
|
|
|
64
|
+
The token is sent as the `Authorization: Bearer <token>` header. The server
|
|
65
|
+
validates it via the IAM service and resolves the user's project automatically.
|
|
66
|
+
Use this method when building user-facing apps (e.g. control panels) where the
|
|
67
|
+
user logs in through IAM.
|
|
68
|
+
|
|
69
|
+
### Custom provider
|
|
70
|
+
|
|
71
|
+
Implement your own provider via the `AuthenticationProvider` interface:
|
|
72
|
+
|
|
73
|
+
```typescript
|
|
74
|
+
import { AuthenticationProvider } from '@applica-software-guru/persona-sdk';
|
|
75
|
+
|
|
76
|
+
class MyProvider implements AuthenticationProvider {
|
|
77
|
+
applyHeaders(headers: Headers): void {
|
|
78
|
+
headers.set('x-custom-header', 'value');
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
getCredentials(): string {
|
|
82
|
+
return 'my-credentials';
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
```
|
|
86
|
+
|
|
46
87
|
## Usage Examples
|
|
47
88
|
|
|
48
89
|
### Agents
|
|
@@ -201,6 +242,54 @@ const mission = await missionsApi.create({ name: 'My Mission' });
|
|
|
201
242
|
await missionsApi.execute(mission.id);
|
|
202
243
|
```
|
|
203
244
|
|
|
245
|
+
### Billing
|
|
246
|
+
|
|
247
|
+
The `BillingClient` manages customers, subscriptions, credits and invoices. It uses a separate base URL and can be instantiated directly or via `PersonaSdk`.
|
|
248
|
+
|
|
249
|
+
```typescript
|
|
250
|
+
import { BillingClient } from '@applica-software-guru/persona-sdk';
|
|
251
|
+
|
|
252
|
+
// Standalone usage
|
|
253
|
+
const billing = new BillingClient('https://persona.applica.guru/billing', 'your-api-key');
|
|
254
|
+
|
|
255
|
+
// Or via PersonaSdk
|
|
256
|
+
const billing = sdk.billing('your-api-key');
|
|
257
|
+
|
|
258
|
+
// Customer management
|
|
259
|
+
const customer = await billing.createCustomer({
|
|
260
|
+
owner: 'user-123',
|
|
261
|
+
name: 'Acme Corp',
|
|
262
|
+
email: 'billing@acme.com',
|
|
263
|
+
});
|
|
264
|
+
const existing = await billing.getCustomer('user-123');
|
|
265
|
+
await billing.updateCustomer('user-123', { name: 'Acme Inc.' });
|
|
266
|
+
await billing.deleteCustomer('user-123');
|
|
267
|
+
|
|
268
|
+
// Subscription management
|
|
269
|
+
const subscription = await billing.createSubscription({ owner: 'user-123' });
|
|
270
|
+
const current = await billing.getSubscription('user-123');
|
|
271
|
+
await billing.cancelSubscription('user-123');
|
|
272
|
+
|
|
273
|
+
// Plan changes
|
|
274
|
+
await billing.beginUpgrade('user-123', { toPlanType: 'pro' });
|
|
275
|
+
await billing.downgrade('user-123', { toPlanType: 'starter' });
|
|
276
|
+
await billing.mentorize('user-123', { endDate: '2026-12-31' });
|
|
277
|
+
|
|
278
|
+
// Credits
|
|
279
|
+
await billing.addCredits('user-123', 100);
|
|
280
|
+
await billing.useCredits('user-123', 10, ['chat', 'voice'], 'reference-id');
|
|
281
|
+
const credits = await billing.getCredits('user-123');
|
|
282
|
+
const valid = await billing.isValid('user-123');
|
|
283
|
+
|
|
284
|
+
// Invoices
|
|
285
|
+
const invoices = await billing.listInvoices('user-123', '2026-01-01', '2026-12-31');
|
|
286
|
+
|
|
287
|
+
// Project-level billing
|
|
288
|
+
const projectSub = await billing.getProjectSubscription('project-id');
|
|
289
|
+
await billing.changeProjectSubscriptionPlan('project-id', { toPlanType: 'pro' });
|
|
290
|
+
await billing.addProjectSubscriptionCredits('project-id', { credits: 50 });
|
|
291
|
+
```
|
|
292
|
+
|
|
204
293
|
## Error Handling
|
|
205
294
|
|
|
206
295
|
```typescript
|
|
@@ -235,6 +324,7 @@ try {
|
|
|
235
324
|
| **FeatureTemplatesApi** | `list`, `get`, `create`, `update`, `patch`, `remove`, `getMcpAvailableTools` |
|
|
236
325
|
| **MissionsApi** | `list`, `get`, `create`, `update`, `remove`, `generate`, `execute`, `retry`, `replan`, `sendInstruction`, `stop`, `resume` |
|
|
237
326
|
| **ServicePricesApi** | `list`, `get`, `create`, `update`, `remove` |
|
|
327
|
+
| **BillingClient** | `createCustomer`, `updateCustomer`, `getCustomer`, `saveCustomer`, `deleteCustomer`, `createSubscription`, `getSubscription`, `cancelSubscription`, `beginUpgrade`, `downgrade`, `mentorize`, `addCredits`, `useCredits`, `getCredits`, `isValid`, `listInvoices`, `getProjectSubscription`, `changeProjectSubscriptionPlan`, `addProjectSubscriptionCredits` |
|
|
238
328
|
|
|
239
329
|
## Compatibility
|
|
240
330
|
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@applica-software-guru/persona-sdk",
|
|
3
3
|
"description": "Official TypeScript SDK for the Persona API — manage agents, sessions, projects, knowledge bases, workflows, triggers and more.",
|
|
4
4
|
"private": false,
|
|
5
|
-
"version": "0.1.
|
|
5
|
+
"version": "0.1.5",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"dev": "vite",
|