@applica-software-guru/persona-sdk 0.1.113 → 0.1.115
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 +86 -1
- package/dist/bundle.cjs.js +1 -1
- package/dist/bundle.cjs.js.map +1 -1
- package/dist/bundle.es.js +468 -315
- package/dist/bundle.es.js.map +1 -1
- package/dist/index.d.ts +339 -3
- package/package.json +1 -1
- package/src/agents/types.ts +6 -2
- package/src/billing/billing-client.ts +3 -0
- package/src/billing/types.ts +16 -0
- package/src/index.ts +27 -0
- package/src/model-aliases/model-aliases-api.ts +94 -0
- package/src/model-aliases/references.ts +20 -0
- package/src/model-aliases/types.ts +125 -0
- package/src/notifications/notifications-api.ts +42 -0
- package/src/notifications/types.ts +39 -0
- package/src/persona-sdk.ts +14 -0
- package/src/sessions/types.ts +2 -0
- package/src/workflows/channels-api.ts +61 -0
- package/src/workflows/types.ts +45 -0
- package/src/workflows/workflows-api.ts +5 -0
- package/tests/billing-aliases.test.mjs +71 -0
- package/tests/channels-api.test.mjs +55 -0
- package/tests/model-aliases-api.test.mjs +198 -0
- package/tests/notifications-api.test.mjs +88 -0
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
|
+
import test from 'node:test';
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
ApiException,
|
|
6
|
+
ModelAliasesApi,
|
|
7
|
+
PersonaSdk,
|
|
8
|
+
aliasNameFromRef,
|
|
9
|
+
aliasRef,
|
|
10
|
+
isAliasRef,
|
|
11
|
+
} from '../dist/bundle.es.js';
|
|
12
|
+
|
|
13
|
+
const BASE = 'https://core.test';
|
|
14
|
+
|
|
15
|
+
function recordFetch(context, respond = () => ({ status: 200, body: {} })) {
|
|
16
|
+
const originalFetch = globalThis.fetch;
|
|
17
|
+
context.after(() => {
|
|
18
|
+
globalThis.fetch = originalFetch;
|
|
19
|
+
});
|
|
20
|
+
const calls = [];
|
|
21
|
+
globalThis.fetch = async (url, init) => {
|
|
22
|
+
calls.push({
|
|
23
|
+
url: new URL(String(url)),
|
|
24
|
+
method: init.method,
|
|
25
|
+
body: init.body ? JSON.parse(init.body) : undefined,
|
|
26
|
+
headers: init.headers,
|
|
27
|
+
});
|
|
28
|
+
const { status, body } = respond(calls.length);
|
|
29
|
+
return new Response(body === undefined ? null : JSON.stringify(body), {
|
|
30
|
+
status,
|
|
31
|
+
headers: { 'Content-Type': 'application/json' },
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
return calls;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const api = () => new ModelAliasesApi(BASE, 'api-key');
|
|
38
|
+
const summary = (call) => `${call.method} ${call.url.pathname}`;
|
|
39
|
+
|
|
40
|
+
test('list asks for the visible aliases, with paging defaults and optional filters', async (context) => {
|
|
41
|
+
const calls = recordFetch(context, () => ({ status: 200, body: { items: [], total: 0, page: 1, size: 20 } }));
|
|
42
|
+
|
|
43
|
+
await api().list();
|
|
44
|
+
await api().list('p2', 'smart', 3, 10);
|
|
45
|
+
|
|
46
|
+
assert.equal(summary(calls[0]), 'GET /model-aliases');
|
|
47
|
+
assert.deepEqual(Object.fromEntries(calls[0].url.searchParams), { page: '1', size: '20' });
|
|
48
|
+
assert.deepEqual(Object.fromEntries(calls[1].url.searchParams), {
|
|
49
|
+
page: '3',
|
|
50
|
+
size: '10',
|
|
51
|
+
projectId: 'p2',
|
|
52
|
+
keyword: 'smart',
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
test('get, create, update and remove use the REST endpoints', async (context) => {
|
|
57
|
+
const calls = recordFetch(context);
|
|
58
|
+
const input = {
|
|
59
|
+
name: 'smart',
|
|
60
|
+
target: 'openai/gpt-5',
|
|
61
|
+
fallbacks: ['anthropic/claude-sonnet-4'],
|
|
62
|
+
defaults: { reasoningEffort: 'xhigh' },
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
await api().get('al1');
|
|
66
|
+
await api().create(input);
|
|
67
|
+
await api().update('al1', { ...input, target: 'grok/grok-4' });
|
|
68
|
+
await api().remove('al1');
|
|
69
|
+
|
|
70
|
+
assert.deepEqual(calls.map(summary), [
|
|
71
|
+
'GET /model-aliases/al1',
|
|
72
|
+
'POST /model-aliases',
|
|
73
|
+
'PUT /model-aliases/al1',
|
|
74
|
+
'DELETE /model-aliases/al1',
|
|
75
|
+
]);
|
|
76
|
+
assert.deepEqual(calls[1].body, input);
|
|
77
|
+
assert.equal(calls[2].body.target, 'grok/grok-4');
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
test('impact, check and suggestions', async (context) => {
|
|
81
|
+
const calls = recordFetch(context);
|
|
82
|
+
|
|
83
|
+
await api().impact('al1');
|
|
84
|
+
await api().check('al1');
|
|
85
|
+
await api().suggestions('al1');
|
|
86
|
+
await api().suggestions('al1', 'openai/gpt-5', 5);
|
|
87
|
+
|
|
88
|
+
assert.deepEqual(calls.map(summary), [
|
|
89
|
+
'GET /model-aliases/al1/impact',
|
|
90
|
+
'POST /model-aliases/al1/check',
|
|
91
|
+
'GET /model-aliases/al1/suggestions',
|
|
92
|
+
'GET /model-aliases/al1/suggestions',
|
|
93
|
+
]);
|
|
94
|
+
assert.equal(calls[2].url.search, '');
|
|
95
|
+
assert.deepEqual(Object.fromEntries(calls[3].url.searchParams), { model: 'openai/gpt-5', limit: '5' });
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
test('the health check is a POST without a body: the SDK never sends alias fields it does not own', async (context) => {
|
|
99
|
+
const calls = recordFetch(context);
|
|
100
|
+
await api().check('al1');
|
|
101
|
+
assert.equal(calls[0].body, undefined);
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
test('suggestions come back as the server sends them', async (context) => {
|
|
105
|
+
const payload = {
|
|
106
|
+
referenceModel: 'openai/gpt-5',
|
|
107
|
+
reference: null,
|
|
108
|
+
notes: ["openai/gpt-5 is not in litellm's registry"],
|
|
109
|
+
replacements: [
|
|
110
|
+
{
|
|
111
|
+
model: 'anthropic/claude',
|
|
112
|
+
provider: 'anthropic',
|
|
113
|
+
sameProvider: false,
|
|
114
|
+
capabilities: ['function_calling'],
|
|
115
|
+
warnings: [],
|
|
116
|
+
},
|
|
117
|
+
],
|
|
118
|
+
fallbacks: [],
|
|
119
|
+
};
|
|
120
|
+
recordFetch(context, () => ({ status: 200, body: payload }));
|
|
121
|
+
|
|
122
|
+
const result = await api().suggestions('al1');
|
|
123
|
+
|
|
124
|
+
assert.deepEqual(result, payload);
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
test('inUse reads the agents blocking a delete from the 409', async (context) => {
|
|
128
|
+
const impact = {
|
|
129
|
+
aliasId: 'al1',
|
|
130
|
+
aliasName: 'smart',
|
|
131
|
+
total: 2,
|
|
132
|
+
usages: [{ agentId: 'ag1', agentName: 'Support', projectId: 'p1', usedIn: ['model'] }],
|
|
133
|
+
};
|
|
134
|
+
recordFetch(context, () => ({
|
|
135
|
+
status: 409,
|
|
136
|
+
body: { detail: { message: "Model alias 'smart' is used by 2 agent(s)", impact } },
|
|
137
|
+
}));
|
|
138
|
+
|
|
139
|
+
const error = await api()
|
|
140
|
+
.remove('al1')
|
|
141
|
+
.then(
|
|
142
|
+
() => null,
|
|
143
|
+
(e) => e
|
|
144
|
+
);
|
|
145
|
+
|
|
146
|
+
assert.ok(error instanceof ApiException);
|
|
147
|
+
assert.equal(error.statusCode, 409);
|
|
148
|
+
assert.deepEqual(ModelAliasesApi.inUse(error), impact);
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
test('inUse is null for anything that is not the in-use conflict', () => {
|
|
152
|
+
assert.equal(ModelAliasesApi.inUse(new Error('boom')), null);
|
|
153
|
+
assert.equal(ModelAliasesApi.inUse(null), null);
|
|
154
|
+
assert.equal(ModelAliasesApi.inUse(new ApiException(404, '{"detail":"Model alias not found"}')), null);
|
|
155
|
+
assert.equal(ModelAliasesApi.inUse(new ApiException(409, 'not json')), null);
|
|
156
|
+
// a 409 for another reason (a name already used is a 400, but be strict)
|
|
157
|
+
assert.equal(ModelAliasesApi.inUse(new ApiException(409, '{"detail":"conflict"}')), null);
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
test('errors keep the status and the server message', async (context) => {
|
|
161
|
+
recordFetch(context, () => ({ status: 403, body: { detail: 'Only super admins can manage global model aliases' } }));
|
|
162
|
+
|
|
163
|
+
await assert.rejects(api().create({ name: 'g', target: 'openai/gpt-5' }), (error) => {
|
|
164
|
+
assert.ok(error instanceof ApiException);
|
|
165
|
+
assert.equal(error.statusCode, 403);
|
|
166
|
+
assert.match(error.body, /super admins/);
|
|
167
|
+
return true;
|
|
168
|
+
});
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
test('the SDK exposes the API and authenticates with the API key', async (context) => {
|
|
172
|
+
const calls = recordFetch(context);
|
|
173
|
+
const sdk = new PersonaSdk(BASE, 'https://workflows.test');
|
|
174
|
+
|
|
175
|
+
const aliases = sdk.modelAliases('my-key');
|
|
176
|
+
assert.ok(aliases instanceof ModelAliasesApi);
|
|
177
|
+
await aliases.get('al1');
|
|
178
|
+
|
|
179
|
+
assert.equal(calls[0].url.origin, BASE);
|
|
180
|
+
assert.equal(calls[0].headers.get('x-persona-apikey'), 'my-key');
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
test('alias references', () => {
|
|
184
|
+
assert.equal(aliasRef('smart'), 'alias:smart');
|
|
185
|
+
assert.equal(aliasRef(' smart '), 'alias:smart');
|
|
186
|
+
assert.equal(aliasNameFromRef('alias:smart-default'), 'smart-default');
|
|
187
|
+
assert.equal(aliasNameFromRef('alias: smart '), 'smart');
|
|
188
|
+
assert.equal(aliasNameFromRef(aliasRef('x')), 'x');
|
|
189
|
+
|
|
190
|
+
assert.equal(isAliasRef('alias:smart'), true);
|
|
191
|
+
assert.equal(isAliasRef(' ALIAS:smart'), true);
|
|
192
|
+
assert.equal(isAliasRef('openai/gpt-5'), false);
|
|
193
|
+
assert.equal(isAliasRef(''), false);
|
|
194
|
+
assert.equal(isAliasRef(null), false);
|
|
195
|
+
assert.equal(isAliasRef(undefined), false);
|
|
196
|
+
|
|
197
|
+
assert.throws(() => aliasNameFromRef('openai/gpt-5'), /Not a model alias reference/);
|
|
198
|
+
});
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
|
+
import test from 'node:test';
|
|
3
|
+
|
|
4
|
+
import { NotificationsApi, PersonaSdk } from '../dist/bundle.es.js';
|
|
5
|
+
|
|
6
|
+
const BASE = 'https://core.test';
|
|
7
|
+
|
|
8
|
+
function recordFetch(context, respond = () => ({ status: 200, body: {} })) {
|
|
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(body === undefined ? null : JSON.stringify(body), {
|
|
18
|
+
status,
|
|
19
|
+
headers: { 'Content-Type': 'application/json' },
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
return calls;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const api = () => new NotificationsApi(BASE, 'api-key');
|
|
26
|
+
const params = (call) => Object.fromEntries(call.url.searchParams);
|
|
27
|
+
|
|
28
|
+
test('list sends only the filters that are set', async (context) => {
|
|
29
|
+
const calls = recordFetch(context, () => ({ status: 200, body: { items: [], total: 0, page: 1, size: 50 } }));
|
|
30
|
+
|
|
31
|
+
await api().list();
|
|
32
|
+
await api().list({ unreadOnly: true, includeResolved: true, projectId: 'p2', page: 2, size: 5 });
|
|
33
|
+
await api().list({ unreadOnly: false, includeResolved: false, projectId: null });
|
|
34
|
+
|
|
35
|
+
assert.equal(calls[0].method, 'GET');
|
|
36
|
+
assert.equal(calls[0].url.pathname, '/notifications');
|
|
37
|
+
assert.deepEqual(params(calls[0]), { page: '1', size: '20' });
|
|
38
|
+
assert.deepEqual(params(calls[1]), {
|
|
39
|
+
page: '2',
|
|
40
|
+
size: '5',
|
|
41
|
+
unreadOnly: 'true',
|
|
42
|
+
includeResolved: 'true',
|
|
43
|
+
projectId: 'p2',
|
|
44
|
+
});
|
|
45
|
+
assert.deepEqual(params(calls[2]), { page: '1', size: '20' });
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
test('unreadCount returns the badge value', async (context) => {
|
|
49
|
+
const calls = recordFetch(context, () => ({ status: 200, body: { count: 3 } }));
|
|
50
|
+
|
|
51
|
+
assert.equal(await api().unreadCount(), 3);
|
|
52
|
+
assert.equal(await api().unreadCount('p2'), 3);
|
|
53
|
+
|
|
54
|
+
assert.equal(calls[0].url.pathname, '/notifications/unread-count');
|
|
55
|
+
assert.equal(calls[0].url.search, '');
|
|
56
|
+
assert.deepEqual(params(calls[1]), { projectId: 'p2' });
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
test('markRead returns the updated notification', async (context) => {
|
|
60
|
+
const notification = {
|
|
61
|
+
id: 'n1',
|
|
62
|
+
type: 'model_alias',
|
|
63
|
+
code: 'model_alias.missing',
|
|
64
|
+
severity: 'critical',
|
|
65
|
+
readAt: '2026-11-13T09:00:00',
|
|
66
|
+
};
|
|
67
|
+
const calls = recordFetch(context, () => ({ status: 200, body: notification }));
|
|
68
|
+
|
|
69
|
+
const result = await api().markRead('n1');
|
|
70
|
+
|
|
71
|
+
assert.equal(`${calls[0].method} ${calls[0].url.pathname}`, 'POST /notifications/n1/read');
|
|
72
|
+
assert.equal(result.readAt, notification.readAt);
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
test('markAllRead accepts the empty answer of the server', async (context) => {
|
|
76
|
+
const calls = recordFetch(context, () => ({ status: 204, body: undefined }));
|
|
77
|
+
|
|
78
|
+
await api().markAllRead();
|
|
79
|
+
await api().markAllRead('p2');
|
|
80
|
+
|
|
81
|
+
assert.equal(`${calls[0].method} ${calls[0].url.pathname}`, 'POST /notifications/read-all');
|
|
82
|
+
assert.equal(calls[0].url.search, '');
|
|
83
|
+
assert.deepEqual(params(calls[1]), { projectId: 'p2' });
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
test('the SDK exposes the API', () => {
|
|
87
|
+
assert.ok(new PersonaSdk(BASE, 'https://workflows.test').notifications('key') instanceof NotificationsApi);
|
|
88
|
+
});
|