@coasys/ad4m 0.11.0 → 0.11.2-dev-multi-user

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.
@@ -101,4 +101,16 @@ export declare class AuthInfoInput {
101
101
  capabilities?: CapabilityInput[];
102
102
  constructor(appName: string, appDesc: string, appDomain: string, appUrl?: string, appIconPath?: string, capabilities?: CapabilityInput[]);
103
103
  }
104
+ export declare class User {
105
+ username: string;
106
+ did: string;
107
+ password: string;
108
+ constructor(username: string, did: string, password: string);
109
+ }
110
+ export declare class UserCreationResult {
111
+ did: string;
112
+ success: boolean;
113
+ error?: string;
114
+ constructor(did: string, success: boolean, error?: string);
115
+ }
104
116
  export {};
@@ -335,3 +335,51 @@ AuthInfoInput = __decorate([
335
335
  __metadata("design:paramtypes", [String, String, String, String, String, Array])
336
336
  ], AuthInfoInput);
337
337
  export { AuthInfoInput };
338
+ let User = class User {
339
+ constructor(username, did, password) {
340
+ this.username = username;
341
+ this.did = did;
342
+ this.password = password;
343
+ }
344
+ };
345
+ __decorate([
346
+ Field(),
347
+ __metadata("design:type", String)
348
+ ], User.prototype, "username", void 0);
349
+ __decorate([
350
+ Field(),
351
+ __metadata("design:type", String)
352
+ ], User.prototype, "did", void 0);
353
+ __decorate([
354
+ Field(),
355
+ __metadata("design:type", String)
356
+ ], User.prototype, "password", void 0);
357
+ User = __decorate([
358
+ ObjectType(),
359
+ __metadata("design:paramtypes", [String, String, String])
360
+ ], User);
361
+ export { User };
362
+ let UserCreationResult = class UserCreationResult {
363
+ constructor(did, success, error) {
364
+ this.did = did;
365
+ this.success = success;
366
+ this.error = error;
367
+ }
368
+ };
369
+ __decorate([
370
+ Field(),
371
+ __metadata("design:type", String)
372
+ ], UserCreationResult.prototype, "did", void 0);
373
+ __decorate([
374
+ Field(),
375
+ __metadata("design:type", Boolean)
376
+ ], UserCreationResult.prototype, "success", void 0);
377
+ __decorate([
378
+ Field({ nullable: true }),
379
+ __metadata("design:type", String)
380
+ ], UserCreationResult.prototype, "error", void 0);
381
+ UserCreationResult = __decorate([
382
+ ObjectType(),
383
+ __metadata("design:paramtypes", [String, Boolean, String])
384
+ ], UserCreationResult);
385
+ export { UserCreationResult };
@@ -1,6 +1,6 @@
1
1
  import { ApolloClient } from "@apollo/client/core";
2
2
  import { PerspectiveInput } from "../perspectives/Perspective";
3
- import { Agent, Apps, AuthInfoInput, EntanglementProof, EntanglementProofInput } from "./Agent";
3
+ import { Agent, Apps, AuthInfoInput, EntanglementProof, EntanglementProofInput, UserCreationResult } from "./Agent";
4
4
  import { AgentStatus } from "./AgentStatus";
5
5
  import { LinkMutations } from "../links/Links";
6
6
  export interface InitializeArgs {
@@ -54,4 +54,6 @@ export declare class AgentClient {
54
54
  revokeToken(requestId: string): Promise<Apps[]>;
55
55
  isLocked(): Promise<boolean>;
56
56
  signMessage(message: string): Promise<string>;
57
+ createUser(email: string, password: string): Promise<UserCreationResult>;
58
+ loginUser(email: string, password: string): Promise<string>;
57
59
  }
@@ -427,5 +427,28 @@ export class AgentClient {
427
427
  }));
428
428
  return agentSignMessage;
429
429
  }
430
+ // Multi-user methods
431
+ async createUser(email, password) {
432
+ const { runtimeCreateUser } = unwrapApolloResult(await __classPrivateFieldGet(this, _AgentClient_apolloClient, "f").mutate({
433
+ mutation: gql `mutation runtimeCreateUser($email: String!, $password: String!) {
434
+ runtimeCreateUser(email: $email, password: $password) {
435
+ did
436
+ success
437
+ error
438
+ }
439
+ }`,
440
+ variables: { email, password },
441
+ }));
442
+ return runtimeCreateUser;
443
+ }
444
+ async loginUser(email, password) {
445
+ const { runtimeLoginUser } = unwrapApolloResult(await __classPrivateFieldGet(this, _AgentClient_apolloClient, "f").mutate({
446
+ mutation: gql `mutation runtimeLoginUser($email: String!, $password: String!) {
447
+ runtimeLoginUser(email: $email, password: $password)
448
+ }`,
449
+ variables: { email, password },
450
+ }));
451
+ return runtimeLoginUser;
452
+ }
430
453
  }
431
454
  _AgentClient_apolloClient = new WeakMap(), _AgentClient_appsChangedCallback = new WeakMap(), _AgentClient_updatedCallbacks = new WeakMap(), _AgentClient_agentStatusChangedCallbacks = new WeakMap();
@@ -148,6 +148,17 @@ export interface LinkSyncAdapter {
148
148
  addCallback(callback: PerspectiveDiffObserver): any;
149
149
  /** Add a sync state callback method */
150
150
  addSyncStateChangeCallback(callback: SyncStateChangeObserver): any;
151
+ /**
152
+ * Set the local agents (DIDs) that own this perspective/neighbourhood.
153
+ * This is used to determine which agents should be registered in the DHT.
154
+ * Optional - if not implemented, all local agents may be registered.
155
+ *
156
+ * This is a temporary hack to support multiple users on one node joining the same neighbourhood.
157
+ * Once we migrate the LanguageController to Rust and run Languages per user, each user will get their
158
+ * own language instance and we won't need to explicitly set local agents. This will provide better
159
+ * isolation and avoid the need to share language state between users.
160
+ */
161
+ setLocalAgents?(agents: DID[]): void;
151
162
  }
152
163
  export type MessageCallback = (message: PerspectiveExpression) => void;
153
164
  export type StatusCallback = (caller: DID) => Perspective;
@@ -185,7 +196,7 @@ export declare class OnlineAgent {
185
196
  did: DID;
186
197
  status: PerspectiveExpression;
187
198
  }
188
- export type TelepresenceSignalCallback = (payload: PerspectiveExpression) => void;
199
+ export type TelepresenceSignalCallback = (payload: PerspectiveExpression, recipientDid?: string) => void;
189
200
  export interface TelepresenceAdapter {
190
201
  setOnlineStatus(status: PerspectiveExpression): Promise<void>;
191
202
  getOnlineAgents(): Promise<OnlineAgent[]>;
@@ -1109,27 +1109,55 @@ WHERE ${whereConditions.join(' AND ')}
1109
1109
  const isEmptyObject = typeof currentValue === 'object' && currentValue !== null && !Array.isArray(currentValue) && Object.keys(currentValue).length === 0;
1110
1110
  if (!currentValue || currentValue === "" || currentValue === 0 || isEmptyObject) {
1111
1111
  let convertedValue = target;
1112
- // Parse literal URLs if property has resolveLanguage
1113
- if (propMeta.resolveLanguage === 'literal' && typeof target === 'string' && target.startsWith('literal://')) {
1114
- try {
1115
- convertedValue = Literal.fromUrl(target).get();
1116
- if (convertedValue.data !== undefined) {
1117
- convertedValue = convertedValue.data;
1112
+ // Only process if target has a value
1113
+ if (target !== undefined && target !== null) {
1114
+ // Check if we need to resolve a non-literal language expression
1115
+ if (propMeta.resolveLanguage != undefined && propMeta.resolveLanguage !== 'literal' && typeof target === 'string') {
1116
+ // For non-literal languages, resolve the expression via perspective.getExpression()
1117
+ // Note: Literals are already parsed by SurrealDB's fn::parse_literal()
1118
+ try {
1119
+ const expression = await perspective.getExpression(target);
1120
+ if (expression) {
1121
+ // Parse the expression data if it's a JSON string
1122
+ try {
1123
+ convertedValue = JSON.parse(expression.data);
1124
+ }
1125
+ catch {
1126
+ // If parsing fails, use the data as-is
1127
+ convertedValue = expression.data;
1128
+ }
1129
+ }
1130
+ }
1131
+ catch (e) {
1132
+ console.warn(`Failed to resolve expression for ${propName}:`, e);
1133
+ convertedValue = target; // Fall back to raw value
1118
1134
  }
1119
1135
  }
1120
- catch (e) {
1121
- console.warn(`Failed to parse literal URL for ${propName}:`, e);
1122
- convertedValue = target; // Fall back to raw value
1123
- }
1124
- }
1125
- else {
1126
- // Type conversion: check the instance property's current type
1127
- const expectedType = typeof instance[propName];
1128
- if (expectedType === 'number' && typeof target === 'string') {
1129
- convertedValue = Number(target);
1136
+ else if (typeof target === 'string' && target.startsWith('literal://')) {
1137
+ // Fallback: If we somehow got a literal URL that wasn't parsed by SurrealDB, parse it now
1138
+ try {
1139
+ const parsed = Literal.fromUrl(target).get();
1140
+ if (parsed.data !== undefined) {
1141
+ convertedValue = parsed.data;
1142
+ }
1143
+ else {
1144
+ convertedValue = parsed;
1145
+ }
1146
+ }
1147
+ catch (e) {
1148
+ // If literal parsing fails, just use the value as-is (don't bail)
1149
+ convertedValue = target;
1150
+ }
1130
1151
  }
1131
- else if (expectedType === 'boolean' && typeof target === 'string') {
1132
- convertedValue = target === 'true' || target === '1';
1152
+ else if (typeof target === 'string') {
1153
+ // Type conversion: check the instance property's current type
1154
+ const expectedType = typeof instance[propName];
1155
+ if (expectedType === 'number') {
1156
+ convertedValue = Number(target);
1157
+ }
1158
+ else if (expectedType === 'boolean') {
1159
+ convertedValue = target === 'true' || target === '1';
1160
+ }
1133
1161
  }
1134
1162
  }
1135
1163
  // Apply transform function if it exists
@@ -26,6 +26,7 @@ uuid
26
26
  name
27
27
  sharedUrl
28
28
  state
29
+ owners
29
30
  neighbourhood {
30
31
  data {
31
32
  linkLanguage
@@ -13,5 +13,6 @@ export declare class PerspectiveHandle {
13
13
  state: PerspectiveState;
14
14
  sharedUrl?: string;
15
15
  neighbourhood?: NeighbourhoodExpression;
16
+ owners?: string[];
16
17
  constructor(uuid?: string, name?: string, state?: PerspectiveState);
17
18
  }
@@ -53,6 +53,10 @@ __decorate([
53
53
  Field(type => NeighbourhoodExpression, { nullable: true }),
54
54
  __metadata("design:type", NeighbourhoodExpression)
55
55
  ], PerspectiveHandle.prototype, "neighbourhood", void 0);
56
+ __decorate([
57
+ Field(type => [String], { nullable: true }),
58
+ __metadata("design:type", Array)
59
+ ], PerspectiveHandle.prototype, "owners", void 0);
56
60
  PerspectiveHandle = __decorate([
57
61
  ObjectType(),
58
62
  __metadata("design:paramtypes", [String, String, String])
@@ -172,6 +172,8 @@ export declare class PerspectiveProxy {
172
172
  neighbourhood: NeighbourhoodExpression | null;
173
173
  /** Current sync state if this perspective is shared */
174
174
  state: PerspectiveState | null;
175
+ /** List of owners of this perspective */
176
+ owners?: string[];
175
177
  /**
176
178
  * Creates a new PerspectiveProxy instance.
177
179
  * Note: Don't create this directly, use ad4m.perspective.add() instead.
@@ -349,6 +349,7 @@ export class PerspectiveProxy {
349
349
  __classPrivateFieldSet(this, _PerspectiveProxy_client, ad4m, "f");
350
350
  this.uuid = __classPrivateFieldGet(this, _PerspectiveProxy_handle, "f").uuid;
351
351
  this.name = __classPrivateFieldGet(this, _PerspectiveProxy_handle, "f").name;
352
+ this.owners = __classPrivateFieldGet(this, _PerspectiveProxy_handle, "f").owners;
352
353
  this.sharedUrl = __classPrivateFieldGet(this, _PerspectiveProxy_handle, "f").sharedUrl;
353
354
  this.neighbourhood = __classPrivateFieldGet(this, _PerspectiveProxy_handle, "f").neighbourhood;
354
355
  this.state = __classPrivateFieldGet(this, _PerspectiveProxy_handle, "f").state;
@@ -1,6 +1,6 @@
1
1
  import { ApolloClient } from "@apollo/client/core";
2
2
  import { Perspective, PerspectiveExpression } from "../perspectives/Perspective";
3
- import { RuntimeInfo, ExceptionInfo, SentMessage, NotificationInput, Notification, TriggeredNotification, ImportResult } from "./RuntimeResolver";
3
+ import { RuntimeInfo, ExceptionInfo, SentMessage, NotificationInput, Notification, TriggeredNotification, ImportResult, UserStatistics } from "./RuntimeResolver";
4
4
  export type MessageCallback = (message: PerspectiveExpression) => null;
5
5
  export type ExceptionCallback = (info: ExceptionInfo) => null;
6
6
  export type NotificationTriggeredCallback = (notification: TriggeredNotification) => null;
@@ -39,6 +39,9 @@ export declare class RuntimeClient {
39
39
  removeNotification(id: string): Promise<boolean>;
40
40
  exportPerspective(uuid: string, filePath: string): Promise<boolean>;
41
41
  importPerspective(filePath: string): Promise<boolean>;
42
+ multiUserEnabled(): Promise<boolean>;
43
+ setMultiUserEnabled(enabled: boolean): Promise<boolean>;
44
+ listUsers(): Promise<UserStatistics[]>;
42
45
  addNotificationTriggeredCallback(cb: NotificationTriggeredCallback): void;
43
46
  subscribeNotificationTriggered(): void;
44
47
  addMessageCallback(cb: MessageCallback): void;
@@ -351,6 +351,36 @@ export class RuntimeClient {
351
351
  }));
352
352
  return runtimeImportPerspective;
353
353
  }
354
+ async multiUserEnabled() {
355
+ const { runtimeMultiUserEnabled } = unwrapApolloResult(await __classPrivateFieldGet(this, _RuntimeClient_apolloClient, "f").query({
356
+ query: gql `query runtimeMultiUserEnabled {
357
+ runtimeMultiUserEnabled
358
+ }`,
359
+ }));
360
+ return runtimeMultiUserEnabled;
361
+ }
362
+ async setMultiUserEnabled(enabled) {
363
+ const { runtimeSetMultiUserEnabled } = unwrapApolloResult(await __classPrivateFieldGet(this, _RuntimeClient_apolloClient, "f").mutate({
364
+ mutation: gql `mutation runtimeSetMultiUserEnabled($enabled: Boolean!) {
365
+ runtimeSetMultiUserEnabled(enabled: $enabled)
366
+ }`,
367
+ variables: { enabled }
368
+ }));
369
+ return runtimeSetMultiUserEnabled;
370
+ }
371
+ async listUsers() {
372
+ const { runtimeListUsers } = unwrapApolloResult(await __classPrivateFieldGet(this, _RuntimeClient_apolloClient, "f").query({
373
+ query: gql `query runtimeListUsers {
374
+ runtimeListUsers {
375
+ email
376
+ did
377
+ lastSeen
378
+ perspectiveCount
379
+ }
380
+ }`
381
+ }));
382
+ return runtimeListUsers;
383
+ }
354
384
  addNotificationTriggeredCallback(cb) {
355
385
  __classPrivateFieldGet(this, _RuntimeClient_notificationTriggeredCallbacks, "f").push(cb);
356
386
  }
@@ -62,6 +62,12 @@ export declare class ImportResult {
62
62
  trustedAgents: ImportStats;
63
63
  knownLinkLanguages: ImportStats;
64
64
  }
65
+ export declare class UserStatistics {
66
+ email: string;
67
+ did: string;
68
+ lastSeen?: string;
69
+ perspectiveCount: number;
70
+ }
65
71
  /**
66
72
  * Resolver classes are used here to define the GraphQL schema
67
73
  * (through the type-graphql annotations)
@@ -103,4 +109,7 @@ export default class RuntimeResolver {
103
109
  runtimeImportDb(filePath: string): boolean;
104
110
  runtimeExportPerspective(perspectiveUuid: string, filePath: string): boolean;
105
111
  runtimeImportPerspective(filePath: string): boolean;
112
+ runtimeMultiUserEnabled(): boolean;
113
+ runtimeSetMultiUserEnabled(enabled: boolean): boolean;
114
+ runtimeListUsers(): UserStatistics[];
106
115
  }
@@ -270,6 +270,28 @@ ImportResult = __decorate([
270
270
  ObjectType()
271
271
  ], ImportResult);
272
272
  export { ImportResult };
273
+ let UserStatistics = class UserStatistics {
274
+ };
275
+ __decorate([
276
+ Field(),
277
+ __metadata("design:type", String)
278
+ ], UserStatistics.prototype, "email", void 0);
279
+ __decorate([
280
+ Field(),
281
+ __metadata("design:type", String)
282
+ ], UserStatistics.prototype, "did", void 0);
283
+ __decorate([
284
+ Field({ nullable: true }),
285
+ __metadata("design:type", String)
286
+ ], UserStatistics.prototype, "lastSeen", void 0);
287
+ __decorate([
288
+ Field(type => Int),
289
+ __metadata("design:type", Number)
290
+ ], UserStatistics.prototype, "perspectiveCount", void 0);
291
+ UserStatistics = __decorate([
292
+ ObjectType()
293
+ ], UserStatistics);
294
+ export { UserStatistics };
273
295
  /**
274
296
  * Resolver classes are used here to define the GraphQL schema
275
297
  * (through the type-graphql annotations)
@@ -419,6 +441,20 @@ let RuntimeResolver = class RuntimeResolver {
419
441
  runtimeImportPerspective(filePath) {
420
442
  return true;
421
443
  }
444
+ runtimeMultiUserEnabled() {
445
+ return false;
446
+ }
447
+ runtimeSetMultiUserEnabled(enabled) {
448
+ return enabled;
449
+ }
450
+ runtimeListUsers() {
451
+ return [{
452
+ email: "test@example.com",
453
+ did: "did:key:test123",
454
+ lastSeen: new Date().toISOString(),
455
+ perspectiveCount: 5
456
+ }];
457
+ }
422
458
  };
423
459
  __decorate([
424
460
  Mutation(returns => Boolean),
@@ -652,6 +688,25 @@ __decorate([
652
688
  __metadata("design:paramtypes", [String]),
653
689
  __metadata("design:returntype", Boolean)
654
690
  ], RuntimeResolver.prototype, "runtimeImportPerspective", null);
691
+ __decorate([
692
+ Query(returns => Boolean),
693
+ __metadata("design:type", Function),
694
+ __metadata("design:paramtypes", []),
695
+ __metadata("design:returntype", Boolean)
696
+ ], RuntimeResolver.prototype, "runtimeMultiUserEnabled", null);
697
+ __decorate([
698
+ Mutation(returns => Boolean),
699
+ __param(0, Arg("enabled")),
700
+ __metadata("design:type", Function),
701
+ __metadata("design:paramtypes", [Boolean]),
702
+ __metadata("design:returntype", Boolean)
703
+ ], RuntimeResolver.prototype, "runtimeSetMultiUserEnabled", null);
704
+ __decorate([
705
+ Query(returns => [UserStatistics]),
706
+ __metadata("design:type", Function),
707
+ __metadata("design:paramtypes", []),
708
+ __metadata("design:returntype", Array)
709
+ ], RuntimeResolver.prototype, "runtimeListUsers", null);
655
710
  RuntimeResolver = __decorate([
656
711
  Resolver()
657
712
  ], RuntimeResolver);
@@ -372,6 +372,7 @@ type Mutation {
372
372
  runtimeRemoveNotification(id: String!): Boolean!
373
373
  runtimeRequestInstallNotification(notification: NotificationInput!): String!
374
374
  runtimeRestartHolochain: Boolean!
375
+ runtimeSetMultiUserEnabled(enabled: Boolean!): Boolean!
375
376
  runtimeSetStatus(status: PerspectiveInput!): Boolean!
376
377
  runtimeUpdateNotification(id: String!, notification: NotificationInput!): Boolean!
377
378
  }
@@ -431,6 +432,7 @@ type PerspectiveExpression {
431
432
  type PerspectiveHandle {
432
433
  name: String!
433
434
  neighbourhood: NeighbourhoodExpression
435
+ owners: [String!]
434
436
  sharedUrl: String
435
437
  state: String!
436
438
  uuid: String!
@@ -479,8 +481,10 @@ type Query {
479
481
  runtimeHcAgentInfos: String!
480
482
  runtimeInfo: RuntimeInfo!
481
483
  runtimeKnownLinkLanguageTemplates: [String!]!
484
+ runtimeListUsers: [UserStatistics!]!
482
485
  runtimeMessageInbox(filter: String): [PerspectiveExpression!]!
483
486
  runtimeMessageOutbox(filter: String): [SentMessage!]!
487
+ runtimeMultiUserEnabled: Boolean!
484
488
  runtimeNotifications: [Notification!]!
485
489
  runtimeVerifyStringSignedByDid(data: String!, did: String!, didSigningKeyId: String!, signedData: String!): Boolean!
486
490
  }
@@ -548,6 +552,13 @@ type TriggeredNotification {
548
552
  triggerMatch: String!
549
553
  }
550
554
 
555
+ type UserStatistics {
556
+ did: String!
557
+ email: String!
558
+ lastSeen: String
559
+ perspectiveCount: Int!
560
+ }
561
+
551
562
  input VoiceActivityParamsInput {
552
563
  endThreshold: Float
553
564
  endWindow: Float
@@ -368,6 +368,7 @@ type Mutation {
368
368
  runtimeRemoveNotification(id: String!): Boolean!
369
369
  runtimeRequestInstallNotification(notification: NotificationInput!): String!
370
370
  runtimeRestartHolochain: Boolean!
371
+ runtimeSetMultiUserEnabled(enabled: Boolean!): Boolean!
371
372
  runtimeSetStatus(status: PerspectiveInput!): Boolean!
372
373
  runtimeUpdateNotification(id: String!, notification: NotificationInput!): Boolean!
373
374
  }
@@ -427,6 +428,7 @@ type PerspectiveExpression {
427
428
  type PerspectiveHandle {
428
429
  name: String!
429
430
  neighbourhood: NeighbourhoodExpression
431
+ owners: [String!]
430
432
  sharedUrl: String
431
433
  state: String!
432
434
  uuid: String!
@@ -475,8 +477,10 @@ type Query {
475
477
  runtimeHcAgentInfos: String!
476
478
  runtimeInfo: RuntimeInfo!
477
479
  runtimeKnownLinkLanguageTemplates: [String!]!
480
+ runtimeListUsers: [UserStatistics!]!
478
481
  runtimeMessageInbox(filter: String): [PerspectiveExpression!]!
479
482
  runtimeMessageOutbox(filter: String): [SentMessage!]!
483
+ runtimeMultiUserEnabled: Boolean!
480
484
  runtimeNotifications: [Notification!]!
481
485
  runtimeVerifyStringSignedByDid(data: String!, did: String!, didSigningKeyId: String!, signedData: String!): Boolean!
482
486
  }
@@ -544,6 +548,13 @@ type TriggeredNotification {
544
548
  triggerMatch: String!
545
549
  }
546
550
 
551
+ type UserStatistics {
552
+ did: String!
553
+ email: String!
554
+ lastSeen: String
555
+ perspectiveCount: Int!
556
+ }
557
+
547
558
  input VoiceActivityParamsInput {
548
559
  endThreshold: Float
549
560
  endWindow: Float
package/package.json CHANGED
@@ -5,7 +5,6 @@
5
5
  "module": "lib/index.js",
6
6
  "types": "lib/src/index.d.ts",
7
7
  "type": "module",
8
- "private": false,
9
8
  "scripts": {
10
9
  "build": "patch-package && tsc && pnpm run buildSchema && pnpm run bundle",
11
10
  "buildSchema": "node --es-module-specifier-resolution=node lib/src/buildSchema.js",
@@ -69,5 +68,5 @@
69
68
  "graphql@15.7.2": "patches/graphql@15.7.2.patch"
70
69
  }
71
70
  },
72
- "version": "0.11.0"
71
+ "version": "0.11.2-dev-multi-user"
73
72
  }
@@ -291,3 +291,39 @@ export class AuthInfoInput {
291
291
  this.appIconPath = appIconPath;
292
292
  }
293
293
  }
294
+
295
+ @ObjectType()
296
+ export class User {
297
+ @Field()
298
+ username: string;
299
+
300
+ @Field()
301
+ did: string;
302
+
303
+ @Field()
304
+ password: string;
305
+
306
+ constructor(username: string, did: string, password: string) {
307
+ this.username = username;
308
+ this.did = did;
309
+ this.password = password;
310
+ }
311
+ }
312
+
313
+ @ObjectType()
314
+ export class UserCreationResult {
315
+ @Field()
316
+ did: string;
317
+
318
+ @Field()
319
+ success: boolean;
320
+
321
+ @Field({ nullable: true })
322
+ error?: string;
323
+
324
+ constructor(did: string, success: boolean, error?: string) {
325
+ this.did = did;
326
+ this.success = success;
327
+ this.error = error;
328
+ }
329
+ }
@@ -8,6 +8,7 @@ import {
8
8
  AuthInfoInput,
9
9
  EntanglementProof,
10
10
  EntanglementProofInput,
11
+ UserCreationResult,
11
12
  } from "./Agent";
12
13
  import { AgentStatus } from "./AgentStatus";
13
14
  import { LinkMutations } from "../links/Links";
@@ -528,4 +529,33 @@ export class AgentClient {
528
529
  );
529
530
  return agentSignMessage;
530
531
  }
532
+
533
+ // Multi-user methods
534
+ async createUser(email: string, password: string): Promise<UserCreationResult> {
535
+ const { runtimeCreateUser } = unwrapApolloResult(
536
+ await this.#apolloClient.mutate({
537
+ mutation: gql`mutation runtimeCreateUser($email: String!, $password: String!) {
538
+ runtimeCreateUser(email: $email, password: $password) {
539
+ did
540
+ success
541
+ error
542
+ }
543
+ }`,
544
+ variables: { email, password },
545
+ })
546
+ );
547
+ return runtimeCreateUser;
548
+ }
549
+
550
+ async loginUser(email: string, password: string): Promise<string> {
551
+ const { runtimeLoginUser } = unwrapApolloResult(
552
+ await this.#apolloClient.mutate({
553
+ mutation: gql`mutation runtimeLoginUser($email: String!, $password: String!) {
554
+ runtimeLoginUser(email: $email, password: $password)
555
+ }`,
556
+ variables: { email, password },
557
+ })
558
+ );
559
+ return runtimeLoginUser;
560
+ }
531
561
  }
@@ -168,10 +168,10 @@ export interface LinkSyncAdapter {
168
168
  /** What revision are we on now -> what changes are included in output of render() */
169
169
  currentRevision(): Promise<string>;
170
170
 
171
- /**
172
- * Check for and get new changes,
171
+ /**
172
+ * Check for and get new changes,
173
173
  * notify others of local changes.
174
- * This function will be called every
174
+ * This function will be called every
175
175
  * few seconds by the ad4m-executor.
176
176
  * */
177
177
  sync(): Promise<PerspectiveDiff>;
@@ -187,6 +187,18 @@ export interface LinkSyncAdapter {
187
187
 
188
188
  /** Add a sync state callback method */
189
189
  addSyncStateChangeCallback(callback: SyncStateChangeObserver);
190
+
191
+ /**
192
+ * Set the local agents (DIDs) that own this perspective/neighbourhood.
193
+ * This is used to determine which agents should be registered in the DHT.
194
+ * Optional - if not implemented, all local agents may be registered.
195
+ *
196
+ * This is a temporary hack to support multiple users on one node joining the same neighbourhood.
197
+ * Once we migrate the LanguageController to Rust and run Languages per user, each user will get their
198
+ * own language instance and we won't need to explicitly set local agents. This will provide better
199
+ * isolation and avoid the need to share language state between users.
200
+ */
201
+ setLocalAgents?(agents: DID[]): void;
190
202
  }
191
203
 
192
204
  export type MessageCallback = (message: PerspectiveExpression) => void;
@@ -255,7 +267,7 @@ export class OnlineAgent {
255
267
  status: PerspectiveExpression
256
268
  }
257
269
 
258
- export type TelepresenceSignalCallback = (payload: PerspectiveExpression) => void;
270
+ export type TelepresenceSignalCallback = (payload: PerspectiveExpression, recipientDid?: string) => void;
259
271
  export interface TelepresenceAdapter {
260
272
  setOnlineStatus(status: PerspectiveExpression): Promise<void>;
261
273
  getOnlineAgents(): Promise<OnlineAgent[]>;