@coasys/ad4m 0.13.1-staging.3 → 0.13.1-staging.4
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/lib/index.cjs +27 -6
- package/lib/index.js +27 -6
- package/lib/src/agent/AgentClient.d.ts +16 -1
- package/lib/src/agent/AgentClient.js +21 -2
- package/lib/src/ai/AITypes.d.ts +6 -2
- package/lib/src/apiClient.js +1 -1
- package/lib/src/generated/api/Apps.d.ts +4 -0
- package/lib/src/generated/api/Events.d.ts +10 -12
- package/lib/src/generated/api/FlowStateChangedEvent.d.ts +3 -2
- package/lib/src/generated/api/Model.d.ts +4 -0
- package/lib/src/generated/api/ModelApi.d.ts +5 -1
- package/lib/src/generated/api/ModelApiInput.d.ts +7 -1
- package/lib/src/generated/api/Notification.d.ts +5 -1
- package/lib/src/generated/api/NotificationInput.d.ts +4 -0
- package/lib/src/generated/api/PerspectiveEvent.d.ts +8 -0
- package/lib/src/generated/api/{PerspectiveLinkWithOwner.d.ts → PerspectiveLinkEvent.d.ts} +4 -2
- package/lib/src/generated/api/{PerspectiveLinkUpdatedWithOwner.d.ts → PerspectiveLinkUpdatedEvent.d.ts} +4 -2
- package/lib/src/generated/api/PerspectiveRemovedEvent.d.ts +7 -0
- package/lib/src/generated/api/RequestCapabilityRequest.d.ts +1 -0
- package/lib/src/generated/api/RpcMethods.d.ts +10 -1
- package/lib/src/generated/api/RuntimeUpdateNotificationParams.d.ts +6 -1
- package/lib/src/generated/api/UsersRevokeAllSessionsParams.d.ts +7 -0
- package/{src/generated/api/PerspectiveRemovedWithOwner.ts → lib/src/generated/api/UsersRevokeAllSessionsParams.js} +1 -2
- package/lib/src/perspectives/WakerSubscriptionManager.js +3 -3
- package/lib/src/runtime/RuntimeClient.d.ts +6 -3
- package/lib/src/runtime/RuntimeClient.js +2 -0
- package/lib/src/runtime/RuntimeTypes.d.ts +5 -1
- package/package.json +2 -2
- package/src/Ad4mClient.test.ts +53 -18
- package/src/agent/AgentClient.ts +26 -2
- package/src/ai/AITypes.ts +6 -2
- package/src/apiClient.test.ts +2 -3
- package/src/apiClient.ts +1 -1
- package/src/generated/api/Apps.ts +6 -1
- package/src/generated/api/Events.ts +10 -12
- package/src/generated/api/FlowStateChangedEvent.ts +3 -2
- package/src/generated/api/Model.ts +4 -0
- package/src/generated/api/ModelApi.ts +5 -1
- package/src/generated/api/ModelApiInput.ts +8 -1
- package/src/generated/api/Notification.ts +5 -1
- package/src/generated/api/NotificationInput.ts +6 -1
- package/src/generated/api/PerspectiveEvent.ts +7 -0
- package/src/generated/api/{PerspectiveLinkUpdatedWithOwner.ts → PerspectiveLinkEvent.ts} +4 -1
- package/src/generated/api/PerspectiveLinkUpdatedEvent.ts +7 -0
- package/src/generated/api/PerspectiveRemovedEvent.ts +6 -0
- package/src/generated/api/RequestCapabilityRequest.ts +1 -1
- package/src/generated/api/RpcMethods.ts +4 -1
- package/src/generated/api/RuntimeUpdateNotificationParams.ts +7 -1
- package/src/generated/api/UsersRevokeAllSessionsParams.ts +8 -0
- package/src/perspectives/WakerSubscriptionManager.test.ts +2 -2
- package/src/perspectives/WakerSubscriptionManager.ts +3 -3
- package/src/perspectives/link-updated-type.test.ts +2 -2
- package/src/perspectives/listener-leaks.test.ts +3 -3
- package/src/runtime/RuntimeClient.ts +6 -3
- package/src/runtime/RuntimeTypes.ts +8 -1
- package/lib/src/generated/api/MessageReceivedEvent.d.ts +0 -7
- package/lib/src/generated/api/PerspectiveRemovedWithOwner.d.ts +0 -5
- package/lib/src/generated/api/PerspectiveWithOwner.d.ts +0 -6
- package/lib/src/generated/api/PerspectiveWithOwner.js +0 -1
- package/src/generated/api/MessageReceivedEvent.ts +0 -7
- package/src/generated/api/PerspectiveLinkWithOwner.ts +0 -4
- package/src/generated/api/PerspectiveWithOwner.ts +0 -4
- /package/lib/src/generated/api/{MessageReceivedEvent.js → PerspectiveEvent.js} +0 -0
- /package/lib/src/generated/api/{PerspectiveLinkUpdatedWithOwner.js → PerspectiveLinkEvent.js} +0 -0
- /package/lib/src/generated/api/{PerspectiveLinkWithOwner.js → PerspectiveLinkUpdatedEvent.js} +0 -0
- /package/lib/src/generated/api/{PerspectiveRemovedWithOwner.js → PerspectiveRemovedEvent.js} +0 -0
package/src/Ad4mClient.test.ts
CHANGED
|
@@ -46,7 +46,8 @@ const MOCK_RESPONSES: Record<string, RpcHandler> = {
|
|
|
46
46
|
'agent.updateProfile': { did: 'did:test:123', perspective: new Perspective(), directMessageLanguage: 'lang://dm' },
|
|
47
47
|
'agent.sign': 'signed-message-data',
|
|
48
48
|
'agent.isLocked': false,
|
|
49
|
-
'agent.requestCapability':
|
|
49
|
+
'agent.requestCapability': (p: Record<string, unknown>) =>
|
|
50
|
+
'agent' in p ? `request-for-${p.agent}` : 'request-id-123',
|
|
50
51
|
'agent.permitCapability': 'permitted-token',
|
|
51
52
|
'agent.generateJwt': 'jwt-token-abc',
|
|
52
53
|
'agent.getApps': [{ requestId: 'app1', auth: {}, token: 'tok', revoked: false }],
|
|
@@ -193,7 +194,7 @@ const MOCK_RESPONSES: Record<string, RpcHandler> = {
|
|
|
193
194
|
'runtime.grantNotification': true,
|
|
194
195
|
'runtime.deleteNotification': true,
|
|
195
196
|
'runtime.setStatus': true,
|
|
196
|
-
'runtime.linkLanguageTemplates': ['
|
|
197
|
+
'runtime.linkLanguageTemplates': [{ address: 'template1', name: 'Template 1', possibleTemplateParams: ['uid', 'name'] }],
|
|
197
198
|
'runtime.addLinkLanguageTemplates': ['lang://template1', 'lang://template2'],
|
|
198
199
|
'runtime.removeLinkLanguageTemplates': ['lang://template1'],
|
|
199
200
|
'runtime.hcAgentInfos': ['hc-agent-info-1', 'hc-agent-info-2'],
|
|
@@ -225,6 +226,8 @@ const MOCK_RESPONSES: Record<string, RpcHandler> = {
|
|
|
225
226
|
'user.create': { success: true, did: 'did:test:new-user' },
|
|
226
227
|
'user.login': 'login-jwt-token',
|
|
227
228
|
'user.verifyEmail': 'verified-token',
|
|
229
|
+
'user.logout': true,
|
|
230
|
+
'user.revokeAllSessions': true,
|
|
228
231
|
'user.requestVerification': { success: true, message: 'Verification email sent', requiresPassword: false, isExistingUser: true },
|
|
229
232
|
'user.list': [{ email: 'user@test.com', credits: 100, freeAccess: false }],
|
|
230
233
|
'user.multiUserEnabled': false,
|
|
@@ -378,12 +381,11 @@ function wireHandle(uuid: string): PerspectiveHandle {
|
|
|
378
381
|
return { uuid, name: 'test-perspective', neighbourhood: null, sharedUrl: null, state: 'SYNCED', owners: null };
|
|
379
382
|
}
|
|
380
383
|
|
|
381
|
-
const
|
|
382
|
-
const
|
|
383
|
-
const linkRemoved = (perspectiveUuid: string, source: string) => event('link-removed', { perspectiveUuid, owner: OWNER, link: wireLink(source) });
|
|
384
|
+
const linkAdded = (perspectiveUuid: string, source: string) => event('link-added', { perspectiveUuid, link: wireLink(source) });
|
|
385
|
+
const linkRemoved = (perspectiveUuid: string, source: string) => event('link-removed', { perspectiveUuid, link: wireLink(source) });
|
|
384
386
|
const linkUpdated = (perspectiveUuid: string, oldSource: string, newSource: string) =>
|
|
385
|
-
event('link-updated', { perspectiveUuid,
|
|
386
|
-
const perspectiveAdded = (uuid: string) => event('perspective-added', { perspectiveUuid: uuid,
|
|
387
|
+
event('link-updated', { perspectiveUuid, oldLink: wireLink(oldSource), newLink: wireLink(newSource) });
|
|
388
|
+
const perspectiveAdded = (uuid: string) => event('perspective-added', { perspectiveUuid: uuid, perspective: wireHandle(uuid) });
|
|
387
389
|
|
|
388
390
|
// ===================== TEST SETUP =====================
|
|
389
391
|
|
|
@@ -501,6 +503,13 @@ describe('AgentClient', () => {
|
|
|
501
503
|
expect(id).toBe('request-id-123');
|
|
502
504
|
});
|
|
503
505
|
|
|
506
|
+
// #1399: the request names the agent the app asks to act as; without one, no `agent`
|
|
507
|
+
// param goes out (the executor's main agent).
|
|
508
|
+
test('requestCapability() passes the requested agent', async () => {
|
|
509
|
+
const id = await ad4m.agent.requestCapability({ appName: 'test', appDesc: 'test', appDomain: 'test', appUrl: 'test', capabilities: [] } as any, 'alice@example.org');
|
|
510
|
+
expect(id).toBe('request-for-alice@example.org');
|
|
511
|
+
});
|
|
512
|
+
|
|
504
513
|
test('permitCapability() returns token', async () => {
|
|
505
514
|
const token = await ad4m.agent.permitCapability('auth-string');
|
|
506
515
|
expect(token).toBe('permitted-token');
|
|
@@ -1135,9 +1144,9 @@ describe('RuntimeClient', () => {
|
|
|
1135
1144
|
expect(result).toEqual(['did:trusted:1']);
|
|
1136
1145
|
});
|
|
1137
1146
|
|
|
1138
|
-
test('knownLinkLanguageTemplates() returns
|
|
1147
|
+
test('knownLinkLanguageTemplates() returns each template with its meta', async () => {
|
|
1139
1148
|
const templates = await ad4m.runtime.knownLinkLanguageTemplates();
|
|
1140
|
-
expect(templates).toEqual(['
|
|
1149
|
+
expect(templates.map(t => [t.address, t.possibleTemplateParams])).toEqual([['template1', ['uid', 'name']]]);
|
|
1141
1150
|
});
|
|
1142
1151
|
|
|
1143
1152
|
test('hcAgentInfos() returns agent infos list', async () => {
|
|
@@ -1183,6 +1192,22 @@ describe('RuntimeClient', () => {
|
|
|
1183
1192
|
expect(notifications).toEqual([]);
|
|
1184
1193
|
});
|
|
1185
1194
|
|
|
1195
|
+
test('updateNotification() without webhookAuth sends none, so the stored one stays', async () => {
|
|
1196
|
+
const result = await ad4m.runtime.updateNotification('notif-1', {
|
|
1197
|
+
description: 'd',
|
|
1198
|
+
appName: 'a',
|
|
1199
|
+
appUrl: 'https://app.test',
|
|
1200
|
+
appIconPath: '',
|
|
1201
|
+
trigger: 'SELECT ?s WHERE { ?s ?p ?o }',
|
|
1202
|
+
perspectiveIds: ['p1'],
|
|
1203
|
+
webhookUrl: 'https://webhook.test',
|
|
1204
|
+
});
|
|
1205
|
+
expect(result).toBe(true);
|
|
1206
|
+
expect(lastRpcCall!.type).toBe('runtime.updateNotification');
|
|
1207
|
+
expect(lastRpcCall!.params.id).toBe('notif-1');
|
|
1208
|
+
expect('webhookAuth' in lastRpcCall!.params).toBe(false);
|
|
1209
|
+
});
|
|
1210
|
+
|
|
1186
1211
|
test('grantNotification() grants a notification', async () => {
|
|
1187
1212
|
const result = await ad4m.runtime.grantNotification('notif-1');
|
|
1188
1213
|
expect(result).toBe(true);
|
|
@@ -1287,6 +1312,21 @@ describe('User and Auth', () => {
|
|
|
1287
1312
|
expect(token).toBe('verified-token');
|
|
1288
1313
|
});
|
|
1289
1314
|
|
|
1315
|
+
test('logout() revokes the session token', async () => {
|
|
1316
|
+
expect(await ad4m.agent.logout()).toBe(true);
|
|
1317
|
+
expect(lastRpcCall).toEqual({ type: 'user.logout', params: {} });
|
|
1318
|
+
});
|
|
1319
|
+
|
|
1320
|
+
test('revokeAllSessions() revokes the caller\'s sessions when no email is given', async () => {
|
|
1321
|
+
expect(await ad4m.agent.revokeAllSessions()).toBe(true);
|
|
1322
|
+
expect(lastRpcCall).toEqual({ type: 'user.revokeAllSessions', params: {} });
|
|
1323
|
+
});
|
|
1324
|
+
|
|
1325
|
+
test('revokeAllSessions(email) names the user', async () => {
|
|
1326
|
+
expect(await ad4m.agent.revokeAllSessions('test@test.com')).toBe(true);
|
|
1327
|
+
expect(lastRpcCall).toEqual({ type: 'user.revokeAllSessions', params: { email: 'test@test.com' } });
|
|
1328
|
+
});
|
|
1329
|
+
|
|
1290
1330
|
test('hostingUserInfo() returns user info', async () => {
|
|
1291
1331
|
const info = await ad4m.agent.hostingUserInfo();
|
|
1292
1332
|
expect(info.email).toBe('test@test.com');
|
|
@@ -1458,7 +1498,7 @@ describe('Ad4mClient', () => {
|
|
|
1458
1498
|
agentUpdated: jest.fn(), agentStatus: jest.fn(), apps: jest.fn(),
|
|
1459
1499
|
hosting: jest.fn(),
|
|
1460
1500
|
added: jest.fn(), updated: jest.fn(), removed: jest.fn(),
|
|
1461
|
-
|
|
1501
|
+
exception: jest.fn(), notification: jest.fn(),
|
|
1462
1502
|
};
|
|
1463
1503
|
freshClient.on('agent-updated', ({ agent }) => handlers.agentUpdated(agent));
|
|
1464
1504
|
freshClient.on('agent-status-changed', ({ agent }) => handlers.agentStatus(agent));
|
|
@@ -1467,7 +1507,6 @@ describe('Ad4mClient', () => {
|
|
|
1467
1507
|
freshClient.on('perspective-added', ({ perspective }) => handlers.added(perspective));
|
|
1468
1508
|
freshClient.on('perspective-updated', ({ perspective }) => handlers.updated(perspective));
|
|
1469
1509
|
freshClient.on('perspective-removed', ({ perspectiveUuid }) => handlers.removed(perspectiveUuid));
|
|
1470
|
-
freshClient.on('message-received', ({ message }) => handlers.message(message));
|
|
1471
1510
|
freshClient.on('exception-occurred', ({ exception }) => handlers.exception(exception));
|
|
1472
1511
|
freshClient.on('notification-triggered', ({ notification }) => handlers.notification(notification));
|
|
1473
1512
|
await freshClient.agent.me(); // wait for the socket to open
|
|
@@ -1476,7 +1515,7 @@ describe('Ad4mClient', () => {
|
|
|
1476
1515
|
const notification = {
|
|
1477
1516
|
notification: {
|
|
1478
1517
|
id: 'n-1', granted: true, description: 'd', appName: 'a', appUrl: 'u', appIconPath: 'i',
|
|
1479
|
-
trigger: 'q', perspectiveIds: ['uuid-a'], webhookUrl: '',
|
|
1518
|
+
trigger: 'q', perspectiveIds: ['uuid-a'], webhookUrl: '', hasWebhookAuth: false, ownerDid: 'did:key:owner',
|
|
1480
1519
|
},
|
|
1481
1520
|
perspectiveId: 'uuid-a', triggerMatch: '[]',
|
|
1482
1521
|
};
|
|
@@ -1489,12 +1528,8 @@ describe('Ad4mClient', () => {
|
|
|
1489
1528
|
}));
|
|
1490
1529
|
ws.emit(event('hosting-user-info-changed', { email: 'a@b.c', remainingCredits: '1', hotWalletAddress: null, freeAccess: false }));
|
|
1491
1530
|
ws.emit(perspectiveAdded('uuid-a'));
|
|
1492
|
-
ws.emit(event('perspective-updated', { perspectiveUuid: 'uuid-a',
|
|
1493
|
-
ws.emit(event('perspective-removed', { perspectiveUuid: 'uuid-a', uuid: 'uuid-a'
|
|
1494
|
-
ws.emit(event('message-received', { message: {
|
|
1495
|
-
author: 'did:test:1', timestamp: '2024-01-01T00:00:00.000Z', data: { links: [] },
|
|
1496
|
-
proof: { key: 'k', signature: 's', valid: true, invalid: false },
|
|
1497
|
-
} }));
|
|
1531
|
+
ws.emit(event('perspective-updated', { perspectiveUuid: 'uuid-a', perspective: wireHandle('uuid-a') }));
|
|
1532
|
+
ws.emit(event('perspective-removed', { perspectiveUuid: 'uuid-a', uuid: 'uuid-a' }));
|
|
1498
1533
|
ws.emit(event('exception-occurred', { exception }));
|
|
1499
1534
|
ws.emit(event('notification-triggered', { perspectiveUuid: 'uuid-a', notification }));
|
|
1500
1535
|
|
package/src/agent/AgentClient.ts
CHANGED
|
@@ -230,8 +230,18 @@ export class AgentClient {
|
|
|
230
230
|
this.#cacheAgent(Agent.fromWire(event.agent));
|
|
231
231
|
};
|
|
232
232
|
|
|
233
|
-
|
|
234
|
-
|
|
233
|
+
/**
|
|
234
|
+
* Asks the executor for a capability token. `agent` names the agent the token will act
|
|
235
|
+
* as: a managed user's email or an agent's DID; absent, the executor's main agent. That
|
|
236
|
+
* agent's owner approves the request (the operator for the main agent, the user for
|
|
237
|
+
* theirs). Returns the request id that {@link generateJwt} redeems with the approver's
|
|
238
|
+
* six-digit code.
|
|
239
|
+
*/
|
|
240
|
+
async requestCapability(authInfo: AuthInfoInput, agent?: string): Promise<string> {
|
|
241
|
+
return this.#apiClient.call(
|
|
242
|
+
'agent.requestCapability',
|
|
243
|
+
agent === undefined ? { authInfo } : { authInfo, agent },
|
|
244
|
+
);
|
|
235
245
|
}
|
|
236
246
|
|
|
237
247
|
async permitCapability(auth: string): Promise<string> {
|
|
@@ -279,6 +289,20 @@ export class AgentClient {
|
|
|
279
289
|
return this.#apiClient.call('user.verifyEmail', { email, code, verificationType });
|
|
280
290
|
}
|
|
281
291
|
|
|
292
|
+
/** Revokes this client's user token. The executor then closes the client's sockets. */
|
|
293
|
+
async logout(): Promise<boolean> {
|
|
294
|
+
return this.#apiClient.call('user.logout', {});
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
/**
|
|
298
|
+
* Revokes every token of a user issued up to now, this client's own included, and closes
|
|
299
|
+
* their sockets. A user leaves out `email` (or names themselves); the operator names the
|
|
300
|
+
* user. Needs AGENT_UPDATE, which a login holds. Tokens from a later login work.
|
|
301
|
+
*/
|
|
302
|
+
async revokeAllSessions(email?: string): Promise<boolean> {
|
|
303
|
+
return this.#apiClient.call('user.revokeAllSessions', email === undefined ? {} : { email });
|
|
304
|
+
}
|
|
305
|
+
|
|
282
306
|
// Hosting methods
|
|
283
307
|
async hostingUserInfo(): Promise<HostingUserInfo> {
|
|
284
308
|
const info = (await this.#apiClient.call('hosting.info', {})).userInfo ?? {
|
package/src/ai/AITypes.ts
CHANGED
|
@@ -2,7 +2,8 @@ import { AIModelLoadingStatus, AITask, AITaskInput } from "./Tasks";
|
|
|
2
2
|
|
|
3
3
|
export class ModelApi {
|
|
4
4
|
baseUrl: string;
|
|
5
|
-
|
|
5
|
+
/** Whether the model has a provider key. The executor never returns the key itself. */
|
|
6
|
+
hasApiKey: boolean;
|
|
6
7
|
model: string;
|
|
7
8
|
apiType: String;
|
|
8
9
|
/** Optional ceiling for the provider's context window (tokens).
|
|
@@ -35,7 +36,10 @@ export class Model {
|
|
|
35
36
|
|
|
36
37
|
export class ModelApiInput {
|
|
37
38
|
baseUrl: string;
|
|
38
|
-
|
|
39
|
+
/** The provider key. Empty or left out on `addModel`: no key. Left out on
|
|
40
|
+
* `updateModel`: the stored key stays, and the update is refused if `baseUrl`
|
|
41
|
+
* changes too. Empty on `updateModel`: the stored key is removed. */
|
|
42
|
+
apiKey?: string;
|
|
39
43
|
model: string;
|
|
40
44
|
apiType: string;
|
|
41
45
|
/** Optional ceiling for the provider's context window (tokens). */
|
package/src/apiClient.test.ts
CHANGED
|
@@ -344,7 +344,7 @@ describe('ApiClient.onReconnect', () => {
|
|
|
344
344
|
})
|
|
345
345
|
|
|
346
346
|
describe('ApiClient when the executor refuses the token', () => {
|
|
347
|
-
const REASON = 'token expired or revoked'
|
|
347
|
+
const REASON = 'Unauthorized access: the token expired or was revoked'
|
|
348
348
|
let authFailed: jest.Mock
|
|
349
349
|
beforeEach(() => {
|
|
350
350
|
TestSocket.autoOpen = false
|
|
@@ -441,7 +441,7 @@ describe('ApiClient when the executor refuses the token', () => {
|
|
|
441
441
|
expect(authFailed).not.toHaveBeenCalled()
|
|
442
442
|
})
|
|
443
443
|
|
|
444
|
-
// A locked wallet is a state of the
|
|
444
|
+
// A locked wallet is a state of the executor: the token may be good. 1013 is not an auth failure.
|
|
445
445
|
it('treats close code 1013 (executor locked) as an ordinary close that carries its reason', async () => {
|
|
446
446
|
const LOCKED = 'Executor is locked: ask the operator to unlock it, then reconnect'
|
|
447
447
|
open()
|
|
@@ -521,7 +521,6 @@ function linkAdded(perspectiveUuid: string, target = 'literal://x') {
|
|
|
521
521
|
return {
|
|
522
522
|
type: 'link-added',
|
|
523
523
|
perspectiveUuid,
|
|
524
|
-
owner: 'did:test:owner',
|
|
525
524
|
link: {
|
|
526
525
|
author: 'did:test:alice',
|
|
527
526
|
timestamp: '2026-01-01T00:00:00Z',
|
package/src/apiClient.ts
CHANGED
|
@@ -168,7 +168,7 @@ export class ApiClient {
|
|
|
168
168
|
? new RpcError(401, event.reason || 'token expired or revoked')
|
|
169
169
|
: closedError(event?.code === CLOSE_TRY_AGAIN_LATER ? event.reason : undefined))
|
|
170
170
|
if (event?.code === CLOSE_AUTH_FAILED && this._ws === ws) {
|
|
171
|
-
this._failAuth(event.reason || 'token expired or revoked')
|
|
171
|
+
this._failAuth(event.reason || 'Unauthorized access: the token expired or was revoked')
|
|
172
172
|
} else {
|
|
173
173
|
this._onClose(ws, event?.code === CLOSE_TRY_AGAIN_LATER ? event.reason : undefined)
|
|
174
174
|
}
|
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
|
|
2
2
|
import type { AuthInfo } from "./AuthInfo";
|
|
3
3
|
|
|
4
|
-
export type Apps = { auth: AuthInfo, requestId: string, revoked: boolean | null,
|
|
4
|
+
export type Apps = { auth: AuthInfo, requestId: string, revoked: boolean | null,
|
|
5
|
+
/**
|
|
6
|
+
* Always empty: the executor does not keep app tokens, and an app receives its token
|
|
7
|
+
* once, from `agent.generateJwt`. The field stays for clients that require it.
|
|
8
|
+
*/
|
|
9
|
+
token: string, };
|
|
@@ -10,14 +10,13 @@ import type { AutoProcessorNeighbourhoodState } from "./AutoProcessorNeighbourho
|
|
|
10
10
|
import type { ExceptionOccurredEvent } from "./ExceptionOccurredEvent";
|
|
11
11
|
import type { FlowStateChangedEvent } from "./FlowStateChangedEvent";
|
|
12
12
|
import type { HostingUserInfo } from "./HostingUserInfo";
|
|
13
|
-
import type { MessageReceivedEvent } from "./MessageReceivedEvent";
|
|
14
13
|
import type { NeighbourhoodSignalFilter } from "./NeighbourhoodSignalFilter";
|
|
15
14
|
import type { NotificationTriggeredEvent } from "./NotificationTriggeredEvent";
|
|
16
|
-
import type {
|
|
17
|
-
import type {
|
|
18
|
-
import type {
|
|
15
|
+
import type { PerspectiveEvent } from "./PerspectiveEvent";
|
|
16
|
+
import type { PerspectiveLinkEvent } from "./PerspectiveLinkEvent";
|
|
17
|
+
import type { PerspectiveLinkUpdatedEvent } from "./PerspectiveLinkUpdatedEvent";
|
|
18
|
+
import type { PerspectiveRemovedEvent } from "./PerspectiveRemovedEvent";
|
|
19
19
|
import type { PerspectiveStateFilter } from "./PerspectiveStateFilter";
|
|
20
|
-
import type { PerspectiveWithOwner } from "./PerspectiveWithOwner";
|
|
21
20
|
import type { QuerySubscriptionUpdateEvent } from "./QuerySubscriptionUpdateEvent";
|
|
22
21
|
import type { SfuCallRenegotiationOffer } from "./SfuCallRenegotiationOffer";
|
|
23
22
|
import type { SfuDataMessage } from "./SfuDataMessage";
|
|
@@ -31,15 +30,14 @@ export interface EventMap {
|
|
|
31
30
|
"agent-updated": AgentUpdatedEvent;
|
|
32
31
|
"apps-changed": Apps;
|
|
33
32
|
"hosting-user-info-changed": HostingUserInfo;
|
|
34
|
-
"perspective-added":
|
|
35
|
-
"perspective-removed":
|
|
36
|
-
"perspective-updated":
|
|
33
|
+
"perspective-added": PerspectiveEvent;
|
|
34
|
+
"perspective-removed": PerspectiveRemovedEvent;
|
|
35
|
+
"perspective-updated": PerspectiveEvent;
|
|
37
36
|
"sync-state-change": PerspectiveStateFilter;
|
|
38
|
-
"link-added":
|
|
39
|
-
"link-removed":
|
|
40
|
-
"link-updated":
|
|
37
|
+
"link-added": PerspectiveLinkEvent;
|
|
38
|
+
"link-removed": PerspectiveLinkEvent;
|
|
39
|
+
"link-updated": PerspectiveLinkUpdatedEvent;
|
|
41
40
|
"signal": NeighbourhoodSignalFilter;
|
|
42
|
-
"message-received": MessageReceivedEvent;
|
|
43
41
|
"notification-triggered": NotificationTriggeredEvent;
|
|
44
42
|
"exception-occurred": ExceptionOccurredEvent;
|
|
45
43
|
"transcription-text": TranscriptionTextFilter;
|
|
@@ -12,8 +12,9 @@
|
|
|
12
12
|
*/
|
|
13
13
|
export type FlowStateChangedEvent = { perspectiveUuid: string,
|
|
14
14
|
/**
|
|
15
|
-
* The agent whose replica derived this
|
|
16
|
-
*
|
|
15
|
+
* The agent whose replica derived this: the event's only recipient when it
|
|
16
|
+
* may read the perspective. Otherwise only the operator gets the main
|
|
17
|
+
* agent's event, and nobody gets another agent's.
|
|
17
18
|
*/
|
|
18
19
|
agentDid: string, instance: string,
|
|
19
20
|
/**
|
|
@@ -3,4 +3,8 @@ import type { LocalModel } from "./LocalModel";
|
|
|
3
3
|
import type { ModelApi } from "./ModelApi";
|
|
4
4
|
import type { ModelType } from "./ModelType";
|
|
5
5
|
|
|
6
|
+
/**
|
|
7
|
+
* A model as RPC results show it. Its provider key never leaves the executor:
|
|
8
|
+
* `api.hasApiKey` says whether one is set.
|
|
9
|
+
*/
|
|
6
10
|
export type Model = { id: string, name: string, api: ModelApi | null, local: LocalModel | null, modelType: ModelType, };
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
|
|
2
2
|
import type { ModelApiType } from "./ModelApiType";
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
/**
|
|
5
|
+
* A remote model's endpoint as RPC results show it: whether a provider key is set,
|
|
6
|
+
* never the key.
|
|
7
|
+
*/
|
|
8
|
+
export type ModelApi = { baseUrl: string, hasApiKey: boolean, model: string, apiType: ModelApiType,
|
|
5
9
|
/**
|
|
6
10
|
* Ceiling for the context window requested from the provider, in tokens.
|
|
7
11
|
*
|
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
|
|
2
2
|
|
|
3
|
-
export type ModelApiInput = { baseUrl: string,
|
|
3
|
+
export type ModelApiInput = { baseUrl: string,
|
|
4
|
+
/**
|
|
5
|
+
* The provider key. An empty key stores no key, and so does `ai.addModel` without
|
|
6
|
+
* one. `ai.updateModel` without one keeps the stored key; it refuses the update if
|
|
7
|
+
* `baseUrl` changes too, because a key goes only to the endpoint it was set for.
|
|
8
|
+
* Never serialised back out.
|
|
9
|
+
*/
|
|
10
|
+
apiKey?: string, model: string, apiType: string,
|
|
4
11
|
/**
|
|
5
12
|
* Optional ceiling for the provider's context window, in tokens.
|
|
6
13
|
* See [`crate::types::ModelApi::max_num_ctx`].
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
/**
|
|
4
|
+
* A notification as RPC results and events show it: whether a webhook credential is
|
|
5
|
+
* set, never the credential.
|
|
6
|
+
*/
|
|
7
|
+
export type Notification = { id: string, granted: boolean, description: string, appName: string, appUrl: string, appIconPath: string, trigger: string, perspectiveIds: Array<string>, webhookUrl: string, hasWebhookAuth: boolean,
|
|
4
8
|
/**
|
|
5
9
|
* The owner's DID: a managed user's, or the main agent's.
|
|
6
10
|
*/
|
|
@@ -1,3 +1,8 @@
|
|
|
1
1
|
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
|
|
2
2
|
|
|
3
|
-
export type NotificationInput = { description: string, appName: string, appUrl: string, appIconPath?: string, trigger: string, perspectiveIds: Array<string>, webhookUrl: string,
|
|
3
|
+
export type NotificationInput = { description: string, appName: string, appUrl: string, appIconPath?: string, trigger: string, perspectiveIds: Array<string>, webhookUrl: string,
|
|
4
|
+
/**
|
|
5
|
+
* Sent as the bearer credential to `webhookUrl`. Results and events say only
|
|
6
|
+
* whether one is set (`hasWebhookAuth`).
|
|
7
|
+
*/
|
|
8
|
+
webhookAuth: string, };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
|
|
2
|
+
import type { PerspectiveHandle } from "./PerspectiveHandle";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* `perspective-added` / `perspective-updated`: one event to all of the perspective's owners.
|
|
6
|
+
*/
|
|
7
|
+
export type PerspectiveEvent = { perspectiveUuid: string, perspective: PerspectiveHandle, };
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
|
|
2
2
|
import type { DecoratedLinkExpression } from "./DecoratedLinkExpression";
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
/**
|
|
5
|
+
* `link-added` / `link-removed`: one event to all of the perspective's owners.
|
|
6
|
+
*/
|
|
7
|
+
export type PerspectiveLinkEvent = { perspectiveUuid: string, link: DecoratedLinkExpression, };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
|
|
2
|
+
import type { DecoratedLinkExpression } from "./DecoratedLinkExpression";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* `link-updated`: one event to all of the perspective's owners.
|
|
6
|
+
*/
|
|
7
|
+
export type PerspectiveLinkUpdatedEvent = { perspectiveUuid: string, newLink: DecoratedLinkExpression, oldLink: DecoratedLinkExpression, };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* `perspective-removed`: one event to all of the perspective's owners.
|
|
5
|
+
*/
|
|
6
|
+
export type PerspectiveRemovedEvent = { perspectiveUuid: string, uuid: string, };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
|
|
2
2
|
import type { AuthInfoInput } from "./AuthInfoInput";
|
|
3
3
|
|
|
4
|
-
export type RequestCapabilityRequest = { authInfo: AuthInfoInput, };
|
|
4
|
+
export type RequestCapabilityRequest = { authInfo: AuthInfoInput, agent?: string, };
|
|
@@ -175,6 +175,7 @@ import type { UsersEmailTestParams } from "./UsersEmailTestParams";
|
|
|
175
175
|
import type { UsersEmailTestResult } from "./UsersEmailTestResult";
|
|
176
176
|
import type { UsersLoginParams } from "./UsersLoginParams";
|
|
177
177
|
import type { UsersRequestVerificationParams } from "./UsersRequestVerificationParams";
|
|
178
|
+
import type { UsersRevokeAllSessionsParams } from "./UsersRevokeAllSessionsParams";
|
|
178
179
|
import type { UsersSetCreditsParams } from "./UsersSetCreditsParams";
|
|
179
180
|
import type { UsersVerifyEmailParams } from "./UsersVerifyEmailParams";
|
|
180
181
|
import type { ValidOutput } from "./ValidOutput";
|
|
@@ -323,7 +324,7 @@ export interface RpcMethods {
|
|
|
323
324
|
"runtime.importData": { params: ImportRequest; result: RuntimeImportResult };
|
|
324
325
|
"runtime.inbox": { params: Record<string, never>; result: Array<PerspectiveExpression> };
|
|
325
326
|
"runtime.info": { params: Record<string, never>; result: RuntimeInfo };
|
|
326
|
-
"runtime.linkLanguageTemplates": { params: Record<string, never>; result: Array<
|
|
327
|
+
"runtime.linkLanguageTemplates": { params: Record<string, never>; result: Array<LanguageMeta> };
|
|
327
328
|
"runtime.networkMetrics": { params: Record<string, never>; result: string };
|
|
328
329
|
"runtime.notifications": { params: Record<string, never>; result: Array<Notification> };
|
|
329
330
|
"runtime.openLink": { params: OpenLinkRequest; result: boolean };
|
|
@@ -371,8 +372,10 @@ export interface RpcMethods {
|
|
|
371
372
|
"user.freeAccess": { params: SetUserFreeAccessRequest; result: boolean };
|
|
372
373
|
"user.list": { params: Record<string, never>; result: Array<UserStatistics> };
|
|
373
374
|
"user.login": { params: UsersLoginParams; result: string };
|
|
375
|
+
"user.logout": { params: Record<string, never>; result: boolean };
|
|
374
376
|
"user.multiUserEnabled": { params: Record<string, never>; result: boolean };
|
|
375
377
|
"user.requestVerification": { params: UsersRequestVerificationParams; result: VerificationRequestResult };
|
|
378
|
+
"user.revokeAllSessions": { params: UsersRevokeAllSessionsParams; result: boolean };
|
|
376
379
|
"user.setMultiUserEnabled": { params: SetMultiUserRequest; result: boolean };
|
|
377
380
|
"user.verifyEmail": { params: UsersVerifyEmailParams; result: string };
|
|
378
381
|
"user.wallet": { params: UsersEmailParams; result: string };
|
|
@@ -1,3 +1,9 @@
|
|
|
1
1
|
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
|
|
2
2
|
|
|
3
|
-
export type RuntimeUpdateNotificationParams = { id: string, description: string, appName: string, appUrl: string, appIconPath?: string, trigger: string, perspectiveIds: Array<string>, webhookUrl: string,
|
|
3
|
+
export type RuntimeUpdateNotificationParams = { id: string, description: string, appName: string, appUrl: string, appIconPath?: string, trigger: string, perspectiveIds: Array<string>, webhookUrl: string,
|
|
4
|
+
/**
|
|
5
|
+
* Without it the update keeps the stored credential, and fails if `webhookUrl`
|
|
6
|
+
* changes too, because a credential goes only to the webhook it was set for. An empty
|
|
7
|
+
* string clears it.
|
|
8
|
+
*/
|
|
9
|
+
webhookAuth?: string, };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
|
|
2
|
+
|
|
3
|
+
export type UsersRevokeAllSessionsParams = {
|
|
4
|
+
/**
|
|
5
|
+
* The user whose sessions to revoke. A user may leave it out or name themselves; the
|
|
6
|
+
* operator must name the user.
|
|
7
|
+
*/
|
|
8
|
+
email?: string, };
|
|
@@ -639,8 +639,8 @@ describe('WakerSubscriptionManager', () => {
|
|
|
639
639
|
|
|
640
640
|
it('names the operator as the fix for a locked executor, on both message shapes', () => {
|
|
641
641
|
// Current executor message (post-#973) and the older internal error must
|
|
642
|
-
// both map to the same hint, and the hint must point at the
|
|
643
|
-
// a remote agent cannot unlock someone else's
|
|
642
|
+
// both map to the same hint, and the hint must point at the executor's operator —
|
|
643
|
+
// a remote agent cannot unlock someone else's executor.
|
|
644
644
|
const current = hintFor('RPC error 403: Executor is locked: the wallet has not been unlocked since the last restart.');
|
|
645
645
|
const legacy = hintFor('RPC error 403: main key not found');
|
|
646
646
|
for (const hint of [current, legacy]) {
|
|
@@ -221,13 +221,13 @@ export function hintFor(msg: string): string {
|
|
|
221
221
|
// "Executor is locked" is the current executor's message; "main key not
|
|
222
222
|
// found" is what older executors (and unrelated key lookups) say for the
|
|
223
223
|
// same locked state. Either way the caller cannot fix it themselves: keys
|
|
224
|
-
// live in memory only, so every restart locks the
|
|
224
|
+
// live in memory only, so every restart locks the executor again and only its
|
|
225
225
|
// operator can unlock it.
|
|
226
226
|
if (/executor is locked/i.test(msg) || /main key not found/i.test(msg)) {
|
|
227
|
-
return " — the executor is locked (its keys live in memory only, so every restart locks it again). Only the
|
|
227
|
+
return " — the executor is locked (its keys live in memory only, so every restart locks it again). Only the executor's operator can unlock it: contact them and ask for unlockAgent, then subscribe again — a pending subscription re-attempts on its own once the executor is unlocked";
|
|
228
228
|
}
|
|
229
229
|
if (/timed out after \d+ms/i.test(msg)) {
|
|
230
|
-
return " — the executor accepted the waker's connection but never answered; check that the waker is pointed at the right executor host and API port (executorUrl in the plugin config) and that the
|
|
230
|
+
return " — the executor accepted the waker's connection but never answered; check that the waker is pointed at the right executor host and API port (executorUrl in the plugin config) and that the executor is unlocked";
|
|
231
231
|
}
|
|
232
232
|
return "";
|
|
233
233
|
}
|
|
@@ -8,7 +8,7 @@ import { PerspectiveClient } from './PerspectiveClient';
|
|
|
8
8
|
import { PerspectiveHandle } from './PerspectiveHandle';
|
|
9
9
|
import { PerspectiveProxy } from './PerspectiveProxy';
|
|
10
10
|
import type { DecoratedLinkExpression } from '../generated/api/DecoratedLinkExpression';
|
|
11
|
-
import type {
|
|
11
|
+
import type { PerspectiveLinkUpdatedEvent } from '../generated/api/PerspectiveLinkUpdatedEvent';
|
|
12
12
|
|
|
13
13
|
/** Captures the socket ApiClient opens, so the test can push an event. */
|
|
14
14
|
class FakeWebSocket {
|
|
@@ -47,7 +47,7 @@ describe('link-updated handler type', () => {
|
|
|
47
47
|
// link-added keeps its `{ link }` payload
|
|
48
48
|
proxy.on('link-added', ({ link }: { link: DecoratedLinkExpression }) => {});
|
|
49
49
|
|
|
50
|
-
const event:
|
|
50
|
+
const event: PerspectiveLinkUpdatedEvent = { perspectiveUuid: 'test-uuid', oldLink: link('old'), newLink: link('new') };
|
|
51
51
|
FakeWebSocket.last.onmessage?.({ data: JSON.stringify({ type: 'link-updated', ...event }) });
|
|
52
52
|
expect(seen).toEqual(['old->new']);
|
|
53
53
|
api.closeAll();
|
|
@@ -52,11 +52,11 @@ const link = (source: string) => ({
|
|
|
52
52
|
});
|
|
53
53
|
const handle = (uuid: string) => ({ uuid, name: 'test', neighbourhood: null, sharedUrl: null, state: PerspectiveState.Synced, owners: null });
|
|
54
54
|
const linkAdded = (perspectiveUuid: string, source: string) =>
|
|
55
|
-
({ type: 'link-added', perspectiveUuid,
|
|
55
|
+
({ type: 'link-added', perspectiveUuid, link: link(source) });
|
|
56
56
|
const linkRemoved = (perspectiveUuid: string, source: string) =>
|
|
57
|
-
({ type: 'link-removed', perspectiveUuid,
|
|
57
|
+
({ type: 'link-removed', perspectiveUuid, link: link(source) });
|
|
58
58
|
const linkUpdated = (perspectiveUuid: string, oldSource: string, newSource: string) =>
|
|
59
|
-
({ type: 'link-updated', perspectiveUuid,
|
|
59
|
+
({ type: 'link-updated', perspectiveUuid, oldLink: link(oldSource), newLink: link(newSource) });
|
|
60
60
|
const syncStateChange = (perspectiveUuid: string, state: PerspectiveState) =>
|
|
61
61
|
({ type: 'sync-state-change', perspectiveUuid, state, perspective: handle(perspectiveUuid) });
|
|
62
62
|
const autoProcessorEvent = (perspectiveUuid: string) => ({
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import {ApiClient, CallOptions } from '../apiClient'
|
|
2
2
|
import { Perspective, PerspectiveExpression } from "../perspectives/Perspective"
|
|
3
|
-
import { RuntimeInfo, SentMessage, NotificationInput, Notification, ImportResult, UserStatistics } from "./RuntimeTypes"
|
|
3
|
+
import { RuntimeInfo, SentMessage, NotificationInput, NotificationUpdate, Notification, ImportResult, UserStatistics } from "./RuntimeTypes"
|
|
4
4
|
import type { HostRate, UnytVersionInfo } from "../generated/api"
|
|
5
|
+
import { LanguageMeta } from "../language/LanguageMeta"
|
|
5
6
|
|
|
6
7
|
export class RuntimeClient {
|
|
7
8
|
#apiClient: ApiClient
|
|
@@ -46,7 +47,9 @@ export class RuntimeClient {
|
|
|
46
47
|
return this.#apiClient.call('runtime.removeLinkLanguageTemplates', { addresses })
|
|
47
48
|
}
|
|
48
49
|
|
|
49
|
-
|
|
50
|
+
/** Every link-language template the executor knows, with its meta (name, description,
|
|
51
|
+
* `possibleTemplateParams`). A template whose meta cannot be read is left out. */
|
|
52
|
+
async knownLinkLanguageTemplates(): Promise<LanguageMeta[]> {
|
|
50
53
|
return this.#apiClient.call('runtime.linkLanguageTemplates', {})
|
|
51
54
|
}
|
|
52
55
|
|
|
@@ -127,7 +130,7 @@ export class RuntimeClient {
|
|
|
127
130
|
return this.#apiClient.call('runtime.notifications', {})
|
|
128
131
|
}
|
|
129
132
|
|
|
130
|
-
async updateNotification(id: string, notification:
|
|
133
|
+
async updateNotification(id: string, notification: NotificationUpdate): Promise<boolean> {
|
|
131
134
|
return this.#apiClient.call('runtime.updateNotification', { ...notification, id })
|
|
132
135
|
}
|
|
133
136
|
|
|
@@ -43,6 +43,11 @@ export class NotificationInput {
|
|
|
43
43
|
webhookAuth: string;
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
+
// What `updateNotification` takes. Without `webhookAuth` the executor keeps the stored
|
|
47
|
+
// credential, and refuses the update if `webhookUrl` changes too: the credential goes only
|
|
48
|
+
// to the webhook it was set for. An empty `webhookAuth` clears it.
|
|
49
|
+
export type NotificationUpdate = Omit<NotificationInput, 'webhookAuth'> & { webhookAuth?: string };
|
|
50
|
+
|
|
46
51
|
export class Notification {
|
|
47
52
|
id: string;
|
|
48
53
|
granted: boolean;
|
|
@@ -53,7 +58,9 @@ export class Notification {
|
|
|
53
58
|
trigger: string;
|
|
54
59
|
perspectiveIds: string[];
|
|
55
60
|
webhookUrl: string;
|
|
56
|
-
|
|
61
|
+
// Whether a webhook credential is set. The executor never returns the credential.
|
|
62
|
+
hasWebhookAuth: boolean;
|
|
63
|
+
ownerDid: string;
|
|
57
64
|
}
|
|
58
65
|
|
|
59
66
|
export class TriggeredNotification {
|