@applica-software-guru/persona-sdk 0.1.114 → 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.
@@ -0,0 +1,125 @@
1
+ import type { ReasoningEffort } from '../agents/types';
2
+
3
+ /** Applied only to the fields an agent leaves empty. `temperature` is not here on purpose. */
4
+ export interface ModelAliasDefaults {
5
+ reasoningEffort?: ReasoningEffort | null;
6
+ maxOutputTokens?: number | null;
7
+ contextWindow?: number | null;
8
+ }
9
+
10
+ export type ModelAliasHealthStatus = 'unknown' | 'ok' | 'deprecating' | 'missing' | 'no_credentials';
11
+ export type ModelAliasIssueRole = 'target' | 'fallback';
12
+
13
+ /** A problem found by the health check on one of the alias' models. */
14
+ export interface ModelAliasIssue {
15
+ model: string;
16
+ role: ModelAliasIssueRole;
17
+ status: ModelAliasHealthStatus;
18
+ detail?: string | null;
19
+ /** Provider-announced retirement date (`YYYY-MM-DD`), when known. */
20
+ deprecationDate?: string | null;
21
+ }
22
+
23
+ export interface ModelAliasHealth {
24
+ status: ModelAliasHealthStatus;
25
+ checkedAt?: string | null;
26
+ issues: ModelAliasIssue[];
27
+ }
28
+
29
+ /** Audit entry: one changed field of the alias (the last 50 are kept). */
30
+ export interface ModelAliasChange {
31
+ at: string;
32
+ by?: string | null;
33
+ field: 'target' | 'fallbacks' | 'defaults';
34
+ old?: unknown;
35
+ new?: unknown;
36
+ }
37
+
38
+ /**
39
+ * A named indirection to a concrete `<provider>/<model>`. An agent references it as
40
+ * `alias:<name>` (see {@link aliasRef}); editing the alias moves every agent using it.
41
+ */
42
+ export interface ModelAlias {
43
+ id: string;
44
+ /** Lowercase slug used in `alias:<name>`. Immutable. */
45
+ name: string;
46
+ /** null => global (super admins only); set => per-project. Immutable. */
47
+ projectId?: string | null;
48
+ description?: string | null;
49
+ /** Concrete litellm-style `<provider>/<model>`, never another alias. */
50
+ target: string;
51
+ /** Ordered alternatives, used at runtime when the target cannot serve a call. */
52
+ fallbacks: string[];
53
+ defaults: ModelAliasDefaults;
54
+ /** Result of the last health check. Managed by the server. */
55
+ health: ModelAliasHealth;
56
+ /** Managed by the server. */
57
+ history: ModelAliasChange[];
58
+ createdAt?: string;
59
+ updatedAt?: string;
60
+ updatedBy?: string | null;
61
+ }
62
+
63
+ /**
64
+ * What to send to create or update an alias. The server-managed fields (`health`,
65
+ * `history`, timestamps) are not part of it; `name` is required but immutable, and
66
+ * the scope can only be chosen (via `projectId`) by super admins when creating.
67
+ */
68
+ export interface ModelAliasInput {
69
+ name: string;
70
+ target: string;
71
+ projectId?: string | null;
72
+ description?: string | null;
73
+ fallbacks?: string[];
74
+ defaults?: ModelAliasDefaults;
75
+ }
76
+
77
+ /** An agent that references an alias, and in which model slots. */
78
+ export interface AliasUsage {
79
+ agentId: string;
80
+ agentName?: string | null;
81
+ projectId?: string | null;
82
+ /** `model`, `compaction`, `loopRecovery`, `attachmentsPreprocessor`, `knowledge`. */
83
+ usedIn: string[];
84
+ }
85
+
86
+ /** Agents referencing an alias; also the detail of the 409 returned when deleting one in use. */
87
+ export interface AliasImpact {
88
+ aliasId: string;
89
+ aliasName: string;
90
+ /** May exceed `usages.length` when the list is capped. */
91
+ total: number;
92
+ usages: AliasUsage[];
93
+ }
94
+
95
+ export type ModelCapability = 'function_calling' | 'vision' | 'audio_input' | 'pdf_input' | 'reasoning';
96
+
97
+ /** What litellm's registry knows about a model. */
98
+ export interface ModelProfile {
99
+ model: string;
100
+ contextWindow?: number | null;
101
+ /** USD per million tokens. */
102
+ inputCostPerMillion?: number | null;
103
+ outputCostPerMillion?: number | null;
104
+ capabilities: ModelCapability[];
105
+ }
106
+
107
+ /** A candidate to replace a model, or to add as a fallback. */
108
+ export interface ModelSuggestion extends ModelProfile {
109
+ provider: string;
110
+ sameProvider: boolean;
111
+ /** e.g. a smaller context window, a much higher price. */
112
+ warnings: string[];
113
+ }
114
+
115
+ /** A proposal only: nothing is applied, the alias is edited by hand. */
116
+ export interface AliasSuggestions {
117
+ aliasId?: string | null;
118
+ /** The model the suggestions are measured against (the alias' target by default). */
119
+ referenceModel: string;
120
+ /** null when the registry does not know the reference model (e.g. already retired). */
121
+ reference?: ModelProfile | null;
122
+ notes: string[];
123
+ replacements: ModelSuggestion[];
124
+ fallbacks: ModelSuggestion[];
125
+ }
@@ -0,0 +1,42 @@
1
+ import { HttpApi } from '../http-api';
2
+ import { Paginated } from '../paginated';
3
+ import { AuthenticationProvider } from '../auth/authentication-provider';
4
+ import { Notification, NotificationListParams } from './types';
5
+
6
+ /**
7
+ * In-platform notifications. A project sees its own; platform-wide ones (no project)
8
+ * are for super admins. Agent API keys have no access. Read state is shared by
9
+ * everyone who can see a notification.
10
+ */
11
+ export class NotificationsApi extends HttpApi {
12
+ constructor(baseUrl: string, auth: string | AuthenticationProvider) {
13
+ super(baseUrl, auth);
14
+ }
15
+
16
+ async list(params: NotificationListParams = {}): Promise<Paginated<Notification>> {
17
+ const { page, size } = this.normalizePageParams(params.page, params.size);
18
+ const query: Record<string, unknown> = { page, size };
19
+ if (params.unreadOnly) query.unreadOnly = true;
20
+ if (params.includeResolved) query.includeResolved = true;
21
+ if (params.projectId) query.projectId = params.projectId;
22
+ return this.httpGet<Paginated<Notification>>('/notifications', query);
23
+ }
24
+
25
+ /** Open, unread notifications: the value of the badge. */
26
+ async unreadCount(projectId?: string | null): Promise<number> {
27
+ const result = await this.httpGet<{ count: number }>(
28
+ '/notifications/unread-count',
29
+ projectId ? { projectId } : undefined
30
+ );
31
+ return result.count;
32
+ }
33
+
34
+ async markRead(id: string): Promise<Notification> {
35
+ return this.httpPost<Notification>('/notifications/' + id + '/read');
36
+ }
37
+
38
+ /** Mark as read everything the caller can see. */
39
+ async markAllRead(projectId?: string | null): Promise<void> {
40
+ await this.httpPost<void>('/notifications/read-all', undefined, projectId ? { projectId } : undefined);
41
+ }
42
+ }
@@ -0,0 +1,39 @@
1
+ export type NotificationSeverity = 'info' | 'warning' | 'critical';
2
+
3
+ /**
4
+ * An in-platform notification (badge + banner). `title` and `message` are an English
5
+ * fallback: clients localize from `code` and `data`.
6
+ */
7
+ export interface Notification {
8
+ id: string;
9
+ /** null => platform-wide, visible to super admins only. */
10
+ projectId?: string | null;
11
+ /** Producer area, e.g. `model_alias`. */
12
+ type: string;
13
+ /** Stable machine code, e.g. `model_alias.missing`, `model_alias.runtime_fallback`. */
14
+ code: string;
15
+ severity: NotificationSeverity;
16
+ title: string;
17
+ message: string;
18
+ /** What it is about, for deep links. */
19
+ entityType?: string | null;
20
+ entityId?: string | null;
21
+ dedupeKey?: string | null;
22
+ data: Record<string, unknown>;
23
+ createdAt?: string;
24
+ readAt?: string | null;
25
+ readBy?: string | null;
26
+ /** Set when the problem it describes no longer applies. */
27
+ resolvedAt?: string | null;
28
+ }
29
+
30
+ export interface NotificationListParams {
31
+ /** Only the ones not read yet. */
32
+ unreadOnly?: boolean;
33
+ /** Include the ones whose problem is gone (hidden by default). */
34
+ includeResolved?: boolean;
35
+ /** Super admins: the view of this project (plus platform-wide ones). */
36
+ projectId?: string | null;
37
+ page?: number;
38
+ size?: number;
39
+ }
@@ -13,6 +13,8 @@ import { SessionsApi } from './sessions/sessions-api';
13
13
  import { MissionsApi } from './missions/missions-api';
14
14
  import { BillingClient } from './billing/billing-client';
15
15
  import { ValuesApi } from './values/values-api';
16
+ import { ModelAliasesApi } from './model-aliases/model-aliases-api';
17
+ import { NotificationsApi } from './notifications/notifications-api';
16
18
 
17
19
  export class PersonaSdk {
18
20
  private readonly baseUrl: string;
@@ -103,6 +105,18 @@ export class PersonaSdk {
103
105
  return new BillingClient(this.billingBaseUrl, auth);
104
106
  }
105
107
 
108
+ modelAliases(apiKey: string): ModelAliasesApi;
109
+ modelAliases(authProvider: AuthenticationProvider): ModelAliasesApi;
110
+ modelAliases(auth: string | AuthenticationProvider): ModelAliasesApi {
111
+ return new ModelAliasesApi(this.baseUrl, auth);
112
+ }
113
+
114
+ notifications(apiKey: string): NotificationsApi;
115
+ notifications(authProvider: AuthenticationProvider): NotificationsApi;
116
+ notifications(auth: string | AuthenticationProvider): NotificationsApi {
117
+ return new NotificationsApi(this.baseUrl, auth);
118
+ }
119
+
106
120
  values(apiKey: string): ValuesApi;
107
121
  values(authProvider: AuthenticationProvider): ValuesApi;
108
122
  values(auth: string | AuthenticationProvider): ValuesApi {
@@ -84,6 +84,8 @@ export interface UsageCost {
84
84
  price?: number;
85
85
  credits?: number;
86
86
  unit?: string;
87
+ /** Name of the model alias the usage went through, if any. `service` names the concrete model that served it. */
88
+ alias?: string | null;
87
89
  }
88
90
 
89
91
  export interface CommittedUsage {
@@ -0,0 +1,71 @@
1
+ import assert from 'node:assert/strict';
2
+ import test from 'node:test';
3
+
4
+ import { BillingClient } from '../dist/bundle.es.js';
5
+
6
+ function recordFetch(context, body) {
7
+ const originalFetch = globalThis.fetch;
8
+ context.after(() => {
9
+ globalThis.fetch = originalFetch;
10
+ });
11
+ const calls = [];
12
+ globalThis.fetch = async (url, init) => {
13
+ calls.push({ url: new URL(String(url)), method: init.method });
14
+ return new Response(JSON.stringify(body), { status: 200, headers: { 'Content-Type': 'application/json' } });
15
+ };
16
+ return calls;
17
+ }
18
+
19
+ const client = () => new BillingClient('https://billing.test', 'api-key');
20
+
21
+ test('usage stats carry the breakdown by alias', async (context) => {
22
+ const stats = {
23
+ totals: { creditsUsed: 5100, usageCount: 15 },
24
+ daily: [],
25
+ byModel: [],
26
+ byAlias: [
27
+ { alias: 'smart', credits: 5000, count: 12, totalCost: 0.5, totalPrice: 5 },
28
+ { alias: 'cheap', credits: 100, count: 3 },
29
+ ],
30
+ availableModels: [],
31
+ };
32
+ const calls = recordFetch(context, stats);
33
+
34
+ const result = await client().getUsageStats('p1', '2026-11-01', '2026-11-30');
35
+
36
+ assert.equal(calls[0].url.pathname, '/projects/p1/subscription/usage-stats');
37
+ assert.deepEqual(result.byAlias, stats.byAlias);
38
+ });
39
+
40
+ test('listUsages filters by alias, one parameter per alias', async (context) => {
41
+ const calls = recordFetch(context, { content: [], totalElements: 0, totalPages: 0, page: 0, size: 20 });
42
+
43
+ await client().listUsages('p1', undefined, undefined, undefined, undefined, 0, 20, ['smart', 'my alias']);
44
+
45
+ assert.equal(calls[0].url.pathname, '/projects/p1/subscription/usages');
46
+ assert.deepEqual(calls[0].url.searchParams.getAll('alias'), ['smart', 'my alias']);
47
+ assert.equal(calls[0].url.searchParams.get('page'), '0');
48
+ });
49
+
50
+ test('listUsages without aliases sends no alias parameter', async (context) => {
51
+ const calls = recordFetch(context, { content: [], totalElements: 0, totalPages: 0, page: 0, size: 20 });
52
+
53
+ await client().listUsages('p1', undefined, undefined, ['gpt-5']);
54
+ await client().listUsages('p1', undefined, undefined, undefined, undefined, undefined, undefined, []);
55
+
56
+ for (const call of calls) assert.equal(call.url.searchParams.has('alias'), false);
57
+ assert.deepEqual(calls[0].url.searchParams.getAll('model'), ['gpt-5']);
58
+ });
59
+
60
+ test('usage details keep the alias a line went through', async (context) => {
61
+ const usage = {
62
+ id: 'u1',
63
+ creditsUsed: 200,
64
+ details: [{ service: 'model.openai.gpt-5.prompt_tokens', credits: 200, unit: 'tokens', alias: 'smart' }],
65
+ };
66
+ recordFetch(context, { content: [usage], totalElements: 1, totalPages: 1, page: 0, size: 20 });
67
+
68
+ const page = await client().listUsages('p1', undefined, undefined, undefined, undefined, 0, 20, ['smart']);
69
+
70
+ assert.equal(page.content[0].details[0].alias, 'smart');
71
+ });
@@ -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
+ });