@applica-software-guru/persona-sdk 0.1.115 → 0.1.116
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/bundle.cjs.js +1 -1
- package/dist/bundle.cjs.js.map +1 -1
- package/dist/bundle.es.js +39 -23
- package/dist/bundle.es.js.map +1 -1
- package/dist/index.d.ts +111 -0
- package/package.json +1 -1
- package/src/decisions/decisions-api.ts +23 -0
- package/src/decisions/types.ts +94 -0
- package/src/index.ts +17 -0
- package/src/persona-sdk.ts +7 -0
- package/tests/decisions-api.test.mjs +57 -0
package/dist/index.d.ts
CHANGED
|
@@ -361,6 +361,22 @@ export declare class ChannelsApi extends HttpApi {
|
|
|
361
361
|
|
|
362
362
|
export declare type ChannelStatus = 'active' | 'incomplete' | 'disconnected';
|
|
363
363
|
|
|
364
|
+
export declare interface ChoiceAnswer {
|
|
365
|
+
type: 'choice';
|
|
366
|
+
/** The winning option key. */
|
|
367
|
+
choice: string;
|
|
368
|
+
probabilities: Record<string, number>;
|
|
369
|
+
/** Normalized entropy (0-1), not the winning probability. */
|
|
370
|
+
confidence: number;
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
/** One of the options: `criteria` maps option keys to their descriptions. */
|
|
374
|
+
export declare interface ChoiceQuestion {
|
|
375
|
+
type: 'choice';
|
|
376
|
+
instructions: string | Record<string, unknown> | unknown[];
|
|
377
|
+
criteria: Record<string, string | null>;
|
|
378
|
+
}
|
|
379
|
+
|
|
364
380
|
export declare interface ChunkResult {
|
|
365
381
|
id?: string;
|
|
366
382
|
text?: string;
|
|
@@ -484,6 +500,63 @@ export declare interface Customer {
|
|
|
484
500
|
stripeCustomerId?: string;
|
|
485
501
|
}
|
|
486
502
|
|
|
503
|
+
export declare type DecisionAnswer = NoulAnswer | ChoiceAnswer | ScoreAnswer | RefusalAnswer;
|
|
504
|
+
|
|
505
|
+
export declare interface DecisionModelInfo {
|
|
506
|
+
id: string;
|
|
507
|
+
provider: string;
|
|
508
|
+
maxInputTokens?: number | null;
|
|
509
|
+
inputCostPerToken?: number | null;
|
|
510
|
+
outputCostPerToken?: number | null;
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
export declare type DecisionQuestion = NoulQuestion | ChoiceQuestion | ScoreQuestion;
|
|
514
|
+
|
|
515
|
+
/**
|
|
516
|
+
* Decisions: typed questions about a state, answered with probabilities by a decision
|
|
517
|
+
* model (TypeSafe Jev, Cloudflare Clef). Mirrors `POST /decisions` of persona-core.
|
|
518
|
+
*/
|
|
519
|
+
export declare type DecisionQuestionType = 'noul' | 'choice' | 'score' | 'box';
|
|
520
|
+
|
|
521
|
+
export declare interface DecisionRequest {
|
|
522
|
+
/** `"<provider>/<model>"` (e.g. `typesafe/jev-latest`) or `alias:<name>`. */
|
|
523
|
+
model: string;
|
|
524
|
+
/** What to decide about: text, an object or a list. */
|
|
525
|
+
state: unknown;
|
|
526
|
+
questions: Record<string, DecisionQuestion>;
|
|
527
|
+
/** Trace: code of the session the decision is stored in. */
|
|
528
|
+
sessionCode?: string;
|
|
529
|
+
/** Trace: parent session (e.g. a workflow execution). */
|
|
530
|
+
parentSessionId?: string;
|
|
531
|
+
userId?: string;
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
export declare interface DecisionResponse {
|
|
535
|
+
sessionId: string;
|
|
536
|
+
sessionCode: string;
|
|
537
|
+
/** The resolved model version that answered (e.g. `jev-1.14.0`). */
|
|
538
|
+
model: string;
|
|
539
|
+
answers: Record<string, DecisionAnswer>;
|
|
540
|
+
usage: DecisionUsage;
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
/**
|
|
544
|
+
* Decisions: typed questions about a state, answered with probabilities by a decision
|
|
545
|
+
* model (TypeSafe Jev, Cloudflare Clef). Stateless, no agent: each call is traced as a
|
|
546
|
+
* session and billed to the project.
|
|
547
|
+
*/
|
|
548
|
+
export declare class DecisionsApi extends HttpApi {
|
|
549
|
+
constructor(baseUrl: string, auth: string | AuthenticationProvider);
|
|
550
|
+
decide(request: DecisionRequest): Promise<DecisionResponse>;
|
|
551
|
+
/** The decision models persona-core knows (`id` is what `decide` takes). */
|
|
552
|
+
listModels(): Promise<DecisionModelInfo[]>;
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
export declare interface DecisionUsage {
|
|
556
|
+
inputTokens: number;
|
|
557
|
+
outputTokens: number;
|
|
558
|
+
}
|
|
559
|
+
|
|
487
560
|
export declare type DocumentExtractorName = 'fitz' | 'document-ai' | 'gemini' | 'markdown';
|
|
488
561
|
|
|
489
562
|
export declare interface DowngradeSubscriptionRequest {
|
|
@@ -1190,6 +1263,22 @@ export declare class NotificationsApi extends HttpApi {
|
|
|
1190
1263
|
|
|
1191
1264
|
export declare type NotificationSeverity = 'info' | 'warning' | 'critical';
|
|
1192
1265
|
|
|
1266
|
+
export declare interface NoulAnswer {
|
|
1267
|
+
type: 'noul';
|
|
1268
|
+
/** Probability of yes (0-1). */
|
|
1269
|
+
noul: number;
|
|
1270
|
+
}
|
|
1271
|
+
|
|
1272
|
+
/** Yes/no question; `criteria` optionally describes the two sides. */
|
|
1273
|
+
export declare interface NoulQuestion {
|
|
1274
|
+
type: 'noul';
|
|
1275
|
+
instructions: string | Record<string, unknown> | unknown[];
|
|
1276
|
+
criteria?: {
|
|
1277
|
+
true?: string;
|
|
1278
|
+
false?: string;
|
|
1279
|
+
} | null;
|
|
1280
|
+
}
|
|
1281
|
+
|
|
1193
1282
|
export declare interface OAuth2CallbackResponse {
|
|
1194
1283
|
id?: string;
|
|
1195
1284
|
successUrl?: string;
|
|
@@ -1281,6 +1370,8 @@ export declare class PersonaSdk {
|
|
|
1281
1370
|
modelAliases(authProvider: AuthenticationProvider): ModelAliasesApi;
|
|
1282
1371
|
notifications(apiKey: string): NotificationsApi;
|
|
1283
1372
|
notifications(authProvider: AuthenticationProvider): NotificationsApi;
|
|
1373
|
+
decisions(apiKey: string): DecisionsApi;
|
|
1374
|
+
decisions(authProvider: AuthenticationProvider): DecisionsApi;
|
|
1284
1375
|
values(apiKey: string): ValuesApi;
|
|
1285
1376
|
values(authProvider: AuthenticationProvider): ValuesApi;
|
|
1286
1377
|
}
|
|
@@ -1400,6 +1491,10 @@ export declare interface Ref {
|
|
|
1400
1491
|
variableName?: string;
|
|
1401
1492
|
}
|
|
1402
1493
|
|
|
1494
|
+
export declare interface RefusalAnswer {
|
|
1495
|
+
type: 'refusal';
|
|
1496
|
+
}
|
|
1497
|
+
|
|
1403
1498
|
export declare interface Revision {
|
|
1404
1499
|
id?: string;
|
|
1405
1500
|
entityId?: string;
|
|
@@ -1426,6 +1521,22 @@ export declare interface RunResult {
|
|
|
1426
1521
|
nextNodes?: string[];
|
|
1427
1522
|
}
|
|
1428
1523
|
|
|
1524
|
+
export declare interface ScoreAnswer {
|
|
1525
|
+
type: 'score';
|
|
1526
|
+
/** Expected zero-based level index (may be fractional). */
|
|
1527
|
+
score: number;
|
|
1528
|
+
probabilities: Record<string, number>;
|
|
1529
|
+
confidence: number;
|
|
1530
|
+
legend?: Record<string, unknown>;
|
|
1531
|
+
}
|
|
1532
|
+
|
|
1533
|
+
/** An ordered rubric: `criteria` lists the levels, lowest first (at least 2). */
|
|
1534
|
+
export declare interface ScoreQuestion {
|
|
1535
|
+
type: 'score';
|
|
1536
|
+
instructions: string | Record<string, unknown> | unknown[];
|
|
1537
|
+
criteria: string[];
|
|
1538
|
+
}
|
|
1539
|
+
|
|
1429
1540
|
export declare interface SearchChunksRequest {
|
|
1430
1541
|
query?: string;
|
|
1431
1542
|
limit?: number;
|
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.116",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"dev": "vite",
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { HttpApi } from '../http-api';
|
|
2
|
+
import { AuthenticationProvider } from '../auth/authentication-provider';
|
|
3
|
+
import { DecisionModelInfo, DecisionRequest, DecisionResponse } from './types';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Decisions: typed questions about a state, answered with probabilities by a decision
|
|
7
|
+
* model (TypeSafe Jev, Cloudflare Clef). Stateless, no agent: each call is traced as a
|
|
8
|
+
* session and billed to the project.
|
|
9
|
+
*/
|
|
10
|
+
export class DecisionsApi extends HttpApi {
|
|
11
|
+
constructor(baseUrl: string, auth: string | AuthenticationProvider) {
|
|
12
|
+
super(baseUrl, auth);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
async decide(request: DecisionRequest): Promise<DecisionResponse> {
|
|
16
|
+
return this.httpPost<DecisionResponse>('/decisions', request);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** The decision models persona-core knows (`id` is what `decide` takes). */
|
|
20
|
+
async listModels(): Promise<DecisionModelInfo[]> {
|
|
21
|
+
return this.httpGet<DecisionModelInfo[]>('/decision-models');
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Decisions: typed questions about a state, answered with probabilities by a decision
|
|
3
|
+
* model (TypeSafe Jev, Cloudflare Clef). Mirrors `POST /decisions` of persona-core.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export type DecisionQuestionType = 'noul' | 'choice' | 'score' | 'box';
|
|
7
|
+
|
|
8
|
+
/** Yes/no question; `criteria` optionally describes the two sides. */
|
|
9
|
+
export interface NoulQuestion {
|
|
10
|
+
type: 'noul';
|
|
11
|
+
instructions: string | Record<string, unknown> | unknown[];
|
|
12
|
+
criteria?: { true?: string; false?: string } | null;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** One of the options: `criteria` maps option keys to their descriptions. */
|
|
16
|
+
export interface ChoiceQuestion {
|
|
17
|
+
type: 'choice';
|
|
18
|
+
instructions: string | Record<string, unknown> | unknown[];
|
|
19
|
+
criteria: Record<string, string | null>;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** An ordered rubric: `criteria` lists the levels, lowest first (at least 2). */
|
|
23
|
+
export interface ScoreQuestion {
|
|
24
|
+
type: 'score';
|
|
25
|
+
instructions: string | Record<string, unknown> | unknown[];
|
|
26
|
+
criteria: string[];
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export type DecisionQuestion = NoulQuestion | ChoiceQuestion | ScoreQuestion;
|
|
30
|
+
|
|
31
|
+
export interface DecisionRequest {
|
|
32
|
+
/** `"<provider>/<model>"` (e.g. `typesafe/jev-latest`) or `alias:<name>`. */
|
|
33
|
+
model: string;
|
|
34
|
+
/** What to decide about: text, an object or a list. */
|
|
35
|
+
state: unknown;
|
|
36
|
+
questions: Record<string, DecisionQuestion>;
|
|
37
|
+
/** Trace: code of the session the decision is stored in. */
|
|
38
|
+
sessionCode?: string;
|
|
39
|
+
/** Trace: parent session (e.g. a workflow execution). */
|
|
40
|
+
parentSessionId?: string;
|
|
41
|
+
userId?: string;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export interface NoulAnswer {
|
|
45
|
+
type: 'noul';
|
|
46
|
+
/** Probability of yes (0-1). */
|
|
47
|
+
noul: number;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export interface ChoiceAnswer {
|
|
51
|
+
type: 'choice';
|
|
52
|
+
/** The winning option key. */
|
|
53
|
+
choice: string;
|
|
54
|
+
probabilities: Record<string, number>;
|
|
55
|
+
/** Normalized entropy (0-1), not the winning probability. */
|
|
56
|
+
confidence: number;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export interface ScoreAnswer {
|
|
60
|
+
type: 'score';
|
|
61
|
+
/** Expected zero-based level index (may be fractional). */
|
|
62
|
+
score: number;
|
|
63
|
+
probabilities: Record<string, number>;
|
|
64
|
+
confidence: number;
|
|
65
|
+
legend?: Record<string, unknown>;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export interface RefusalAnswer {
|
|
69
|
+
type: 'refusal';
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export type DecisionAnswer = NoulAnswer | ChoiceAnswer | ScoreAnswer | RefusalAnswer;
|
|
73
|
+
|
|
74
|
+
export interface DecisionUsage {
|
|
75
|
+
inputTokens: number;
|
|
76
|
+
outputTokens: number;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export interface DecisionResponse {
|
|
80
|
+
sessionId: string;
|
|
81
|
+
sessionCode: string;
|
|
82
|
+
/** The resolved model version that answered (e.g. `jev-1.14.0`). */
|
|
83
|
+
model: string;
|
|
84
|
+
answers: Record<string, DecisionAnswer>;
|
|
85
|
+
usage: DecisionUsage;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export interface DecisionModelInfo {
|
|
89
|
+
id: string;
|
|
90
|
+
provider: string;
|
|
91
|
+
maxInputTokens?: number | null;
|
|
92
|
+
inputCostPerToken?: number | null;
|
|
93
|
+
outputCostPerToken?: number | null;
|
|
94
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -200,6 +200,23 @@ export type {
|
|
|
200
200
|
} from './model-aliases/types';
|
|
201
201
|
export { NotificationsApi } from './notifications/notifications-api';
|
|
202
202
|
export type { Notification, NotificationSeverity, NotificationListParams } from './notifications/types';
|
|
203
|
+
export { DecisionsApi } from './decisions/decisions-api';
|
|
204
|
+
export type {
|
|
205
|
+
DecisionQuestionType,
|
|
206
|
+
DecisionQuestion,
|
|
207
|
+
NoulQuestion,
|
|
208
|
+
ChoiceQuestion,
|
|
209
|
+
ScoreQuestion,
|
|
210
|
+
DecisionRequest,
|
|
211
|
+
DecisionAnswer,
|
|
212
|
+
NoulAnswer,
|
|
213
|
+
ChoiceAnswer,
|
|
214
|
+
ScoreAnswer,
|
|
215
|
+
RefusalAnswer,
|
|
216
|
+
DecisionUsage,
|
|
217
|
+
DecisionResponse,
|
|
218
|
+
DecisionModelInfo,
|
|
219
|
+
} from './decisions/types';
|
|
203
220
|
export type { Revision as RevisionType } from './revisions/types';
|
|
204
221
|
export { BillingClient } from './billing/billing-client';
|
|
205
222
|
export { ValuesApi } from './values/values-api';
|
package/src/persona-sdk.ts
CHANGED
|
@@ -15,6 +15,7 @@ import { BillingClient } from './billing/billing-client';
|
|
|
15
15
|
import { ValuesApi } from './values/values-api';
|
|
16
16
|
import { ModelAliasesApi } from './model-aliases/model-aliases-api';
|
|
17
17
|
import { NotificationsApi } from './notifications/notifications-api';
|
|
18
|
+
import { DecisionsApi } from './decisions/decisions-api';
|
|
18
19
|
|
|
19
20
|
export class PersonaSdk {
|
|
20
21
|
private readonly baseUrl: string;
|
|
@@ -117,6 +118,12 @@ export class PersonaSdk {
|
|
|
117
118
|
return new NotificationsApi(this.baseUrl, auth);
|
|
118
119
|
}
|
|
119
120
|
|
|
121
|
+
decisions(apiKey: string): DecisionsApi;
|
|
122
|
+
decisions(authProvider: AuthenticationProvider): DecisionsApi;
|
|
123
|
+
decisions(auth: string | AuthenticationProvider): DecisionsApi {
|
|
124
|
+
return new DecisionsApi(this.baseUrl, auth);
|
|
125
|
+
}
|
|
126
|
+
|
|
120
127
|
values(apiKey: string): ValuesApi;
|
|
121
128
|
values(authProvider: AuthenticationProvider): ValuesApi;
|
|
122
129
|
values(auth: string | AuthenticationProvider): ValuesApi {
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
|
+
import test from 'node:test';
|
|
3
|
+
|
|
4
|
+
import { DecisionsApi, PersonaSdk } from '../dist/bundle.es.js';
|
|
5
|
+
|
|
6
|
+
const BASE = 'https://core.test';
|
|
7
|
+
|
|
8
|
+
function recordFetch(context, respond) {
|
|
9
|
+
const originalFetch = globalThis.fetch;
|
|
10
|
+
context.after(() => {
|
|
11
|
+
globalThis.fetch = originalFetch;
|
|
12
|
+
});
|
|
13
|
+
const calls = [];
|
|
14
|
+
globalThis.fetch = async (url, init) => {
|
|
15
|
+
calls.push({ url: new URL(String(url)), method: init.method, body: init.body });
|
|
16
|
+
const { status, body } = respond(calls.length);
|
|
17
|
+
return new Response(JSON.stringify(body), {
|
|
18
|
+
status,
|
|
19
|
+
headers: { 'Content-Type': 'application/json' },
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
return calls;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const REPLY = {
|
|
26
|
+
sessionId: 's1',
|
|
27
|
+
sessionCode: 'c1',
|
|
28
|
+
model: 'jev-1.14.0',
|
|
29
|
+
answers: { urgent: { type: 'noul', noul: 0.9 } },
|
|
30
|
+
usage: { inputTokens: 10, outputTokens: 1 },
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
test('decide posts the request and returns the answers', async (context) => {
|
|
34
|
+
const calls = recordFetch(context, () => ({ status: 200, body: REPLY }));
|
|
35
|
+
const request = {
|
|
36
|
+
model: 'typesafe/jev-latest',
|
|
37
|
+
state: { days: 40 },
|
|
38
|
+
questions: {
|
|
39
|
+
urgent: { type: 'noul', instructions: 'Urgent?' },
|
|
40
|
+
refund: { type: 'choice', instructions: 'Approve?', criteria: { approve: 'ok', reject: 'no' } },
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const response = await new DecisionsApi(BASE, 'api-key').decide(request);
|
|
45
|
+
|
|
46
|
+
assert.equal(calls[0].method, 'POST');
|
|
47
|
+
assert.equal(calls[0].url.pathname, '/decisions');
|
|
48
|
+
assert.deepEqual(JSON.parse(calls[0].body), request);
|
|
49
|
+
assert.equal(response.answers.urgent.noul, 0.9);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
test('listModels and the sdk facade', async (context) => {
|
|
53
|
+
const calls = recordFetch(context, () => ({ status: 200, body: [{ id: 'typesafe/jev-latest', provider: 'typesafe' }] }));
|
|
54
|
+
const models = await new PersonaSdk(BASE).decisions('api-key').listModels();
|
|
55
|
+
assert.equal(calls[0].url.pathname, '/decision-models');
|
|
56
|
+
assert.equal(models[0].id, 'typesafe/jev-latest');
|
|
57
|
+
});
|