@coasys/ad4m 0.12.0-rc1-dev.1 → 0.12.0-rc1-dev.3

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.
Files changed (124) hide show
  1. package/jest.config.js +8 -1
  2. package/lib/index.cjs +13793 -12854
  3. package/lib/index.js +13782 -12851
  4. package/lib/src/Ad4mClient.test.d.ts +1 -0
  5. package/lib/src/Ad4mClient.test.js +1204 -0
  6. package/lib/src/Literal.test.d.ts +1 -0
  7. package/lib/src/Literal.test.js +41 -0
  8. package/lib/src/model/Ad4mModel.d.ts +528 -101
  9. package/lib/src/model/Ad4mModel.js +1670 -748
  10. package/lib/src/model/Ad4mModel.test.js +140 -156
  11. package/lib/src/model/Subject.d.ts +3 -3
  12. package/lib/src/model/Subject.js +25 -25
  13. package/lib/src/model/decorators.d.ts +259 -247
  14. package/lib/src/model/decorators.js +379 -422
  15. package/lib/src/model/mutation.d.ts +81 -0
  16. package/lib/src/model/mutation.js +317 -0
  17. package/lib/src/model/parentUtils.d.ts +32 -0
  18. package/lib/src/model/parentUtils.js +64 -0
  19. package/lib/src/model/prolog/generatePrologFacts.d.ts +36 -0
  20. package/lib/src/model/prolog/generatePrologFacts.js +139 -0
  21. package/lib/src/model/prolog/index.d.ts +1 -0
  22. package/lib/src/model/prolog/index.js +1 -0
  23. package/lib/src/model/query/ModelQueryBuilder.d.ts +82 -0
  24. package/lib/src/model/query/ModelQueryBuilder.js +115 -0
  25. package/lib/src/model/query/QueryBuilder.d.ts +101 -0
  26. package/lib/src/model/query/QueryBuilder.js +193 -0
  27. package/lib/src/model/query/SurrealQueryBuilder.d.ts +48 -0
  28. package/lib/src/model/query/SurrealQueryBuilder.js +371 -0
  29. package/lib/src/model/query/fetchInstance.d.ts +24 -0
  30. package/lib/src/model/query/fetchInstance.js +144 -0
  31. package/lib/src/model/query/hydration.d.ts +54 -0
  32. package/lib/src/model/query/hydration.js +214 -0
  33. package/lib/src/model/query/operations.d.ts +59 -0
  34. package/lib/src/model/query/operations.js +384 -0
  35. package/lib/src/model/query/snapshot.d.ts +59 -0
  36. package/lib/src/model/query/snapshot.js +106 -0
  37. package/lib/src/model/query/surrealCompiler.d.ts +42 -0
  38. package/lib/src/model/query/surrealCompiler.js +304 -0
  39. package/lib/src/model/schema/fromJSONSchema.d.ts +67 -0
  40. package/lib/src/model/schema/fromJSONSchema.js +264 -0
  41. package/lib/src/model/schema/metadata.d.ts +15 -0
  42. package/lib/src/model/schema/metadata.js +112 -0
  43. package/lib/src/model/subscription.d.ts +47 -0
  44. package/lib/src/model/subscription.js +231 -0
  45. package/lib/src/model/transaction.d.ts +27 -0
  46. package/lib/src/model/transaction.js +32 -0
  47. package/lib/src/model/types.d.ts +195 -0
  48. package/lib/src/model/types.js +8 -0
  49. package/lib/src/model/util.d.ts +6 -6
  50. package/lib/src/model/util.js +22 -22
  51. package/lib/src/neighbourhood/NeighbourhoodClient.js +31 -12
  52. package/lib/src/perspectives/PerspectiveProxy.d.ts +9 -9
  53. package/lib/src/perspectives/PerspectiveProxy.js +63 -51
  54. package/lib/src/shacl/SHACLShape.d.ts +9 -0
  55. package/lib/src/shacl/SHACLShape.js +28 -4
  56. package/lib/src/shims/reflect-metadata.d.ts +0 -0
  57. package/lib/src/shims/type-graphql.d.ts +32 -0
  58. package/lib/src/src/Ad4mClient.d.ts +28 -0
  59. package/lib/src/src/Address.d.ts +1 -0
  60. package/lib/src/src/DID.d.ts +1 -0
  61. package/lib/src/src/Exception.d.ts +7 -0
  62. package/lib/src/src/Literal.d.ts +7 -0
  63. package/lib/src/src/PubSub.d.ts +17 -0
  64. package/lib/src/src/SmartLiteral.d.ts +12 -0
  65. package/lib/src/src/agent/Agent.d.ts +110 -0
  66. package/lib/src/src/agent/AgentClient.d.ts +62 -0
  67. package/lib/src/src/agent/AgentResolver.d.ts +30 -0
  68. package/lib/src/src/agent/AgentStatus.d.ts +8 -0
  69. package/lib/src/src/ai/AIClient.d.ts +32 -0
  70. package/lib/src/src/ai/AIResolver.d.ts +75 -0
  71. package/lib/src/src/ai/Tasks.d.ts +37 -0
  72. package/lib/src/src/buildSchema.d.ts +1 -0
  73. package/lib/src/src/expression/Expression.d.ts +28 -0
  74. package/lib/src/src/expression/ExpressionClient.d.ts +13 -0
  75. package/lib/src/src/expression/ExpressionRef.d.ts +9 -0
  76. package/lib/src/src/expression/ExpressionResolver.d.ts +10 -0
  77. package/lib/src/src/index.d.ts +35 -0
  78. package/lib/src/src/jestSetup.d.ts +1 -0
  79. package/lib/src/src/language/Icon.d.ts +4 -0
  80. package/lib/src/src/language/Language.d.ts +206 -0
  81. package/lib/src/src/language/LanguageClient.d.ts +17 -0
  82. package/lib/src/src/language/LanguageContext.d.ts +37 -0
  83. package/lib/src/src/language/LanguageHandle.d.ts +9 -0
  84. package/lib/src/src/language/LanguageMeta.d.ts +35 -0
  85. package/lib/src/src/language/LanguageRef.d.ts +6 -0
  86. package/lib/src/src/language/LanguageResolver.d.ts +19 -0
  87. package/lib/src/src/links/Links.d.ts +39 -0
  88. package/lib/src/src/links/Links.test.d.ts +1 -0
  89. package/lib/src/src/model/Ad4mModel.d.ts +1438 -0
  90. package/lib/src/src/model/Ad4mModel.test.d.ts +1 -0
  91. package/lib/src/src/model/Subject.d.ts +25 -0
  92. package/lib/src/src/model/decorators.d.ts +545 -0
  93. package/lib/src/src/model/util.d.ts +12 -0
  94. package/lib/src/src/neighbourhood/Neighbourhood.d.ts +10 -0
  95. package/lib/src/src/neighbourhood/NeighbourhoodClient.d.ts +25 -0
  96. package/lib/src/src/neighbourhood/NeighbourhoodProxy.d.ts +19 -0
  97. package/lib/src/src/neighbourhood/NeighbourhoodProxy.test.d.ts +1 -0
  98. package/lib/src/src/neighbourhood/NeighbourhoodResolver.d.ts +24 -0
  99. package/lib/src/src/perspectives/LinkQuery.d.ts +11 -0
  100. package/lib/src/src/perspectives/Perspective.d.ts +38 -0
  101. package/lib/src/src/perspectives/Perspective.test.d.ts +1 -0
  102. package/lib/src/src/perspectives/PerspectiveClient.d.ts +97 -0
  103. package/lib/src/src/perspectives/PerspectiveDiff.d.ts +9 -0
  104. package/lib/src/src/perspectives/PerspectiveHandle.d.ts +18 -0
  105. package/lib/src/src/perspectives/PerspectiveProxy.d.ts +865 -0
  106. package/lib/src/src/perspectives/PerspectiveResolver.d.ts +57 -0
  107. package/lib/src/src/runtime/RuntimeClient.d.ts +56 -0
  108. package/lib/src/src/runtime/RuntimeResolver.d.ts +132 -0
  109. package/lib/src/src/shacl/SHACLFlow.d.ts +171 -0
  110. package/lib/src/src/shacl/SHACLFlow.test.d.ts +1 -0
  111. package/lib/src/src/shacl/SHACLShape.d.ts +117 -0
  112. package/lib/src/src/shacl/SHACLShape.test.d.ts +1 -0
  113. package/lib/src/src/typeDefs.d.ts +1 -0
  114. package/lib/src/src/unwrapApolloResult.d.ts +2 -0
  115. package/lib/src/src/utils.d.ts +25 -0
  116. package/package.json +20 -24
  117. package/src/model/Ad4mModel.test.ts +132 -149
  118. package/src/model/Ad4mModel.ts +1930 -784
  119. package/src/model/Subject.ts +24 -24
  120. package/src/model/decorators.ts +626 -482
  121. package/src/model/util.ts +22 -22
  122. package/src/neighbourhood/NeighbourhoodClient.ts +32 -16
  123. package/src/perspectives/PerspectiveProxy.ts +69 -55
  124. package/src/shacl/SHACLShape.ts +33 -4
@@ -0,0 +1,62 @@
1
+ import { ApolloClient } from "@apollo/client/core";
2
+ import { PerspectiveInput } from "../perspectives/Perspective";
3
+ import { Agent, Apps, AuthInfoInput, EntanglementProof, EntanglementProofInput, UserCreationResult } from "./Agent";
4
+ import { AgentStatus } from "./AgentStatus";
5
+ import { LinkMutations } from "../links/Links";
6
+ import { VerificationRequestResult } from "../runtime/RuntimeResolver";
7
+ export interface InitializeArgs {
8
+ did: string;
9
+ didDocument: string;
10
+ keystore: string;
11
+ passphrase: string;
12
+ }
13
+ export type AgentUpdatedCallback = (agent: Agent) => null;
14
+ export type AgentStatusChangedCallback = (agent: Agent) => null;
15
+ export type AgentAppsUpdatedCallback = () => null;
16
+ /**
17
+ * Provides access to all functions regarding the local agent,
18
+ * such as generating, locking, unlocking, importing the DID keystore,
19
+ * as well as updating the publicly shared Agent expression.
20
+ */
21
+ export declare class AgentClient {
22
+ #private;
23
+ constructor(client: ApolloClient<any>, subscribe?: boolean);
24
+ /**
25
+ * Returns the Agent expression of the local agent as it is shared
26
+ * publicly via the AgentLanguage.
27
+ *
28
+ * I.e. this is the users profile.
29
+ */
30
+ me(): Promise<Agent>;
31
+ status(): Promise<AgentStatus>;
32
+ generate(passphrase: string): Promise<AgentStatus>;
33
+ import(args: InitializeArgs): Promise<AgentStatus>;
34
+ lock(passphrase: string): Promise<AgentStatus>;
35
+ unlock(passphrase: string, holochain?: boolean): Promise<AgentStatus>;
36
+ byDID(did: string): Promise<Agent>;
37
+ updatePublicPerspective(perspective: PerspectiveInput): Promise<Agent>;
38
+ mutatePublicPerspective(mutations: LinkMutations): Promise<Agent>;
39
+ updateDirectMessageLanguage(directMessageLanguage: string): Promise<Agent>;
40
+ addEntanglementProofs(proofs: EntanglementProofInput[]): Promise<EntanglementProof[]>;
41
+ deleteEntanglementProofs(proofs: EntanglementProofInput[]): Promise<EntanglementProof[]>;
42
+ getEntanglementProofs(): Promise<string[]>;
43
+ entanglementProofPreFlight(deviceKey: string, deviceKeyType: string): Promise<EntanglementProof>;
44
+ addUpdatedListener(listener: any): void;
45
+ addAppChangedListener(listener: any): void;
46
+ subscribeAgentUpdated(): void;
47
+ subscribeAppsChanged(): void;
48
+ addAgentStatusChangedListener(listener: any): void;
49
+ subscribeAgentStatusChanged(): void;
50
+ requestCapability(authInfo: AuthInfoInput): Promise<string>;
51
+ permitCapability(auth: string): Promise<string>;
52
+ generateJwt(requestId: string, rand: string): Promise<string>;
53
+ getApps(): Promise<Apps[]>;
54
+ removeApp(requestId: string): Promise<Apps[]>;
55
+ revokeToken(requestId: string): Promise<Apps[]>;
56
+ isLocked(): Promise<boolean>;
57
+ signMessage(message: string): Promise<string>;
58
+ createUser(email: string, password: string, appInfo?: AuthInfoInput): Promise<UserCreationResult>;
59
+ loginUser(email: string, password: string): Promise<string>;
60
+ requestLoginVerification(email: string, appInfo?: AuthInfoInput): Promise<VerificationRequestResult>;
61
+ verifyEmailCode(email: string, code: string, verificationType: string): Promise<string>;
62
+ }
@@ -0,0 +1,30 @@
1
+ import { PerspectiveInput } from "../perspectives/Perspective";
2
+ import { Agent, AgentSignature, AuthInfoInput, EntanglementProof, EntanglementProofInput } from "./Agent";
3
+ import { AgentStatus } from "./AgentStatus";
4
+ export declare const TEST_AGENT_DID = "did:ad4m:test";
5
+ export default class AgentResolver {
6
+ agent(): Agent;
7
+ agentStatus(): AgentStatus;
8
+ agentGenerate(passphrase: string, pubSub: any): AgentStatus;
9
+ agentImport(did: string, didDocument: string, keystore: string, passphrase: string): AgentStatus;
10
+ agentLock(passphrase: string, pubSub: any): AgentStatus;
11
+ agentUnlock(passphrase: string, holochain: boolean, pubSub: any): AgentStatus;
12
+ agentByDID(did: string): Agent;
13
+ agentUpdatePublicPerspective(perspective: PerspectiveInput, pubSub: any): Agent;
14
+ agentUpdateDirectMessageLanguage(directMessageLanguage: string, pubSub: any): Agent;
15
+ agentUpdated(): Agent;
16
+ agentStatusChanged(): AgentStatus;
17
+ agentAddEntanglementProofs(proofs: EntanglementProofInput[]): EntanglementProof[];
18
+ agentDeleteEntanglementProofs(proofs: EntanglementProofInput[]): EntanglementProof[];
19
+ agentGetEntanglementProofs(): EntanglementProof[];
20
+ agentEntanglementProofPreFlight(deviceKey: string, deviceKeyType: string): EntanglementProof;
21
+ agentRequestCapability(authInfo: AuthInfoInput): String;
22
+ agentPermitCapability(auth: string): String;
23
+ agentGenerateJwt(requestId: string, rand: string): String;
24
+ agentIsLocked(): Boolean;
25
+ agentGetApps(): [];
26
+ agentAppsChanged(): null;
27
+ agentRemoveApp(requestId: string, pubSub: any): [];
28
+ agentRevokeToken(requestId: string): any[];
29
+ agentSignMessage(message: string): AgentSignature;
30
+ }
@@ -0,0 +1,8 @@
1
+ export declare class AgentStatus {
2
+ isInitialized: Boolean;
3
+ isUnlocked: Boolean;
4
+ did?: string;
5
+ didDocument?: string;
6
+ error?: string;
7
+ constructor(obj?: object);
8
+ }
@@ -0,0 +1,32 @@
1
+ import { ApolloClient } from "@apollo/client";
2
+ import { AIModelLoadingStatus, AITask } from "./Tasks";
3
+ import { ModelInput, Model, ModelType } from "./AIResolver";
4
+ export declare class AIClient {
5
+ #private;
6
+ constructor(apolloClient: ApolloClient<any>, subscribe?: boolean);
7
+ getModels(): Promise<Model[]>;
8
+ addModel(model: ModelInput): Promise<string>;
9
+ updateModel(modelId: string, model: ModelInput): Promise<boolean>;
10
+ removeModel(modelId: string): Promise<boolean>;
11
+ setDefaultModel(modelType: ModelType, modelId: string): Promise<boolean>;
12
+ getDefaultModel(modelType: ModelType): Promise<Model>;
13
+ tasks(): Promise<AITask[]>;
14
+ addTask(name: string, modelId: string, systemPrompt: string, promptExamples: {
15
+ input: string;
16
+ output: string;
17
+ }[], metaData?: string): Promise<AITask>;
18
+ removeTask(taskId: string): Promise<AITask>;
19
+ updateTask(taskId: string, task: AITask): Promise<AITask>;
20
+ modelLoadingStatus(model: string): Promise<AIModelLoadingStatus>;
21
+ prompt(taskId: string, prompt: string): Promise<string>;
22
+ embed(modelId: string, text: string): Promise<Array<number>>;
23
+ openTranscriptionStream(modelId: string, streamCallback: (text: string) => void, params?: {
24
+ startThreshold?: number;
25
+ startWindow?: number;
26
+ endThreshold?: number;
27
+ endWindow?: number;
28
+ timeBeforeSpeech?: number;
29
+ }): Promise<string>;
30
+ closeTranscriptionStream(streamId: string): Promise<void>;
31
+ feedTranscriptionStream(streamIds: string | string[], audio: Float32Array): Promise<void>;
32
+ }
@@ -0,0 +1,75 @@
1
+ import { AIModelLoadingStatus, AITask, AITaskInput } from "./Tasks";
2
+ export declare class ModelApi {
3
+ baseUrl: string;
4
+ apiKey: string;
5
+ model: string;
6
+ apiType: String;
7
+ }
8
+ export declare class TokenizerSource {
9
+ repo: string;
10
+ revision: string;
11
+ fileName: string;
12
+ }
13
+ export declare class LocalModel {
14
+ fileName: string;
15
+ tokenizerSource?: TokenizerSource;
16
+ huggingfaceRepo?: string;
17
+ revision?: string;
18
+ }
19
+ export type ModelType = "LLM" | "EMBEDDING" | "TRANSCRIPTION";
20
+ export declare class Model {
21
+ id: string;
22
+ name: string;
23
+ api?: ModelApi;
24
+ local?: LocalModel;
25
+ modelType: ModelType;
26
+ }
27
+ export declare class ModelApiInput {
28
+ baseUrl: string;
29
+ apiKey: string;
30
+ model: string;
31
+ apiType: string;
32
+ }
33
+ export declare class TokenizerSourceInput {
34
+ repo: string;
35
+ revision: string;
36
+ fileName: string;
37
+ }
38
+ export declare class LocalModelInput {
39
+ fileName: string;
40
+ tokenizerSource?: TokenizerSourceInput;
41
+ huggingfaceRepo?: string;
42
+ revision?: string;
43
+ }
44
+ export declare class ModelInput {
45
+ name: string;
46
+ api?: ModelApiInput;
47
+ local?: LocalModelInput;
48
+ modelType: ModelType;
49
+ }
50
+ export declare class VoiceActivityParamsInput {
51
+ startThreshold?: number;
52
+ startWindow?: number;
53
+ endThreshold?: number;
54
+ endWindow?: number;
55
+ timeBeforeSpeech?: number;
56
+ }
57
+ export default class AIResolver {
58
+ aiGetModels(): Model[];
59
+ aiAddModel(model: ModelInput): string;
60
+ aiUpdateModel(modelId: string, model: ModelInput): boolean;
61
+ aiRemoveModel(modelId: string): boolean;
62
+ aiSetDefaultModel(modelType: ModelType, modelId: string): boolean;
63
+ aiGetDefaultModel(modelType: ModelType): Model;
64
+ aiTasks(): AITask[];
65
+ aiAddTask(task: AITaskInput): AITask;
66
+ aiRemoveTask(taskId: string): AITask;
67
+ aiUpdateTask(taskId: string, task: AITaskInput): AITask;
68
+ aiModelLoadingStatus(model: string): AIModelLoadingStatus;
69
+ aiPrompt(taskId: string, input: string): string;
70
+ aiEmbed(modelId: string, text: string): string;
71
+ aiOpenTranscriptionStream(modelId: string, params?: VoiceActivityParamsInput): string;
72
+ aiCloseTranscriptionStream(streamId: string): boolean;
73
+ aiFeedTranscriptionStream(streamIds: string[], audio: number[], pubSub: any): boolean;
74
+ aiTranscriptionText(streamId: string): string;
75
+ }
@@ -0,0 +1,37 @@
1
+ export declare class AIPromptExamplesInput {
2
+ input: string;
3
+ output: string;
4
+ constructor(input: string, output: string);
5
+ }
6
+ export declare class AIPromptExamples {
7
+ input: string;
8
+ output: string;
9
+ constructor(input: string, output: string);
10
+ }
11
+ export declare class AITaskInput {
12
+ name: string;
13
+ modelId: string;
14
+ systemPrompt: string;
15
+ promptExamples: AIPromptExamplesInput[];
16
+ metaData: string;
17
+ constructor(name: string, model_id: string, system_prompt: string, prompt_examples: AIPromptExamplesInput[], metaData?: string);
18
+ }
19
+ export declare class AITask {
20
+ name: string;
21
+ modelId: string;
22
+ taskId: string;
23
+ systemPrompt: string;
24
+ promptExamples: AIPromptExamples[];
25
+ metaData?: string;
26
+ createdAt: string;
27
+ updatedAt: string;
28
+ constructor(name: string, model_id: string, task_id: string, system_prompt: string, prompt_examples: AIPromptExamples[], metaData?: string, created_at?: string, updated_at?: string);
29
+ }
30
+ export declare class AIModelLoadingStatus {
31
+ model: string;
32
+ status: string;
33
+ progress: number;
34
+ downloaded: boolean;
35
+ loaded: boolean;
36
+ constructor(model: string, status: string, progress: number, downloaded: boolean, loaded: boolean);
37
+ }
@@ -0,0 +1 @@
1
+ import "reflect-metadata";
@@ -0,0 +1,28 @@
1
+ import { ClassType } from "type-graphql";
2
+ import { Icon } from "../language/Icon";
3
+ import { LanguageRef } from "../language/LanguageRef";
4
+ export declare class ExpressionProof {
5
+ signature: string;
6
+ key: string;
7
+ valid?: boolean;
8
+ invalid?: boolean;
9
+ constructor(sig: string, k: string);
10
+ }
11
+ export declare class ExpressionProofInput {
12
+ signature: string;
13
+ key: string;
14
+ valid?: boolean;
15
+ invalid?: boolean;
16
+ }
17
+ export declare function ExpressionGeneric<DataType>(DataTypeClass: ClassType<DataType>): any;
18
+ export declare function ExpressionGenericInput<DataType>(DataTypeClass: ClassType<DataType>): any;
19
+ declare const Expression_base: any;
20
+ export declare class Expression extends Expression_base {
21
+ }
22
+ declare const ExpressionRendered_base: any;
23
+ export declare class ExpressionRendered extends ExpressionRendered_base {
24
+ language: LanguageRef;
25
+ icon: Icon;
26
+ }
27
+ export declare function isExpression(e: any): boolean;
28
+ export {};
@@ -0,0 +1,13 @@
1
+ import { ApolloClient } from "@apollo/client/core";
2
+ import { InteractionCall, InteractionMeta } from "../language/Language";
3
+ import { ExpressionRendered } from "./Expression";
4
+ export declare class ExpressionClient {
5
+ #private;
6
+ constructor(client: ApolloClient<any>);
7
+ get(url: string, alwaysGet?: boolean): Promise<ExpressionRendered>;
8
+ getMany(urls: string[]): Promise<ExpressionRendered[]>;
9
+ getRaw(url: string): Promise<string>;
10
+ create(content: any, languageAddress: string): Promise<string>;
11
+ interactions(url: string): Promise<InteractionMeta[]>;
12
+ interact(url: string, interactionCall: InteractionCall): Promise<string | null>;
13
+ }
@@ -0,0 +1,9 @@
1
+ import type { Address } from '../Address';
2
+ import { LanguageRef } from '../language/LanguageRef';
3
+ export declare class ExpressionRef {
4
+ language: LanguageRef;
5
+ expression: Address;
6
+ constructor(lang: LanguageRef, expr: Address);
7
+ }
8
+ export declare function exprRef2String(ref: ExpressionRef): string;
9
+ export declare function parseExprUrl(url: string): ExpressionRef;
@@ -0,0 +1,10 @@
1
+ import { ExpressionRendered } from "./Expression";
2
+ import { InteractionCall, InteractionMeta } from "../language/Language";
3
+ export default class ExpressionResolver {
4
+ expression(url: string): ExpressionRendered;
5
+ expressionMany(urls: string[]): (ExpressionRendered | null)[];
6
+ expressionRaw(url: string): string;
7
+ expressionCreate(content: string, languageAddress: string): string;
8
+ expressionInteractions(url: string): InteractionMeta[];
9
+ expressionInteract(url: string, interactionCall: InteractionCall): string | null;
10
+ }
@@ -0,0 +1,35 @@
1
+ export * from "./Ad4mClient";
2
+ export * from "./Address";
3
+ export * from "./agent/Agent";
4
+ export * from "./agent/AgentStatus";
5
+ export * from "./Exception";
6
+ export * from "./expression/Expression";
7
+ export * from "./expression/ExpressionRef";
8
+ export * from "./language/Icon";
9
+ export * from "./language/Language";
10
+ export * from "./language/LanguageRef";
11
+ export * from "./language/LanguageContext";
12
+ export * from "./language/LanguageHandle";
13
+ export * from "./language/LanguageMeta";
14
+ export * from "./links/Links";
15
+ export * from "./Literal";
16
+ export * from "./perspectives/Perspective";
17
+ export * from "./perspectives/PerspectiveHandle";
18
+ export * from "./perspectives/PerspectiveProxy";
19
+ export * from "./perspectives/PerspectiveDiff";
20
+ export * from "./perspectives/LinkQuery";
21
+ export * from "./SmartLiteral";
22
+ export * from "./model/decorators";
23
+ export * from "./model/Subject";
24
+ export * from "./neighbourhood/Neighbourhood";
25
+ export * from "./neighbourhood/NeighbourhoodProxy";
26
+ export * from "./typeDefs";
27
+ export * from "./DID";
28
+ export * from "./utils";
29
+ export * from "./agent/AgentClient";
30
+ export * from "./ai/AIClient";
31
+ export * from "./ai/Tasks";
32
+ export * from "./runtime/RuntimeResolver";
33
+ export * from './model/Ad4mModel';
34
+ export * from './shacl/SHACLShape';
35
+ export { SHACLFlow, FlowState, FlowTransition, LinkPattern, FlowableCondition } from './shacl/SHACLFlow';
@@ -0,0 +1 @@
1
+ import 'reflect-metadata';
@@ -0,0 +1,4 @@
1
+ export declare class Icon {
2
+ code: string;
3
+ constructor(code: string);
4
+ }
@@ -0,0 +1,206 @@
1
+ import type { Address } from '../Address';
2
+ import { DID } from '../DID';
3
+ import type { Expression } from '../expression/Expression';
4
+ import { Perspective, PerspectiveExpression } from '../perspectives/Perspective';
5
+ import { PerspectiveDiff } from '../perspectives/PerspectiveDiff';
6
+ import { PerspectiveState } from '../perspectives/PerspectiveHandle';
7
+ /** Interface of AD4M Languages
8
+ *
9
+ * Any JavaScript module that implements a create() function that returns an object that implements this interface
10
+ * is a valid AD4M language.
11
+ * So the AD4M-internal representation of a language is an object that implements this interface.
12
+ *
13
+ * Since there are a few different kinds of languages, this interface is split into optional sub-interfaces.
14
+ * The only required property is the name of the language.
15
+ *
16
+ * The most usual kind of language is the "Expression Language", which is a language that can be used to create
17
+ * and share Expressions.
18
+ * For that, implement the expressionsAdapter and expressionUI interface.
19
+ *
20
+ * The second most common kind of language is the "Link Language", which is a language that builds the core
21
+ * of AD4M Neighbourhoods.
22
+ * For that, implement the linksAdapter interface.
23
+ */
24
+ export interface Language {
25
+ readonly name: string;
26
+ /** Flagging expressions as immutable to enable
27
+ * expression caching in the ad4m-executor
28
+ */
29
+ isImmutableExpression?(expression: Address): boolean;
30
+ /** ExpressionAdapter implements means of getting an Expression
31
+ * by address and putting an expression
32
+ */
33
+ readonly expressionAdapter?: ExpressionAdapter;
34
+ /** Interface for getting UI/web components for rendering Expressions of this Language */
35
+ readonly expressionUI?: ExpressionUI;
36
+ /** Interface of LinkLanguages for the core implementation of Neighbourhoods */
37
+ readonly linksAdapter?: LinkSyncAdapter;
38
+ /** Additional Interface of LinkLanguages that support telepresence features,
39
+ * that is:
40
+ * - seeing who is online and getting a status
41
+ * - sending/receiveing p2p signals to other online agents without affecting
42
+ * the shared Perspective of the Neighbourhood
43
+ * (see TelepresenceAdapter for more details)
44
+ */
45
+ readonly telepresenceAdapter?: TelepresenceAdapter;
46
+ /** Implementation of a Language that defines and stores Languages*/
47
+ readonly languageAdapter?: LanguageAdapter;
48
+ /** Optional adapter for getting Expressions by author */
49
+ readonly getByAuthorAdapter?: GetByAuthorAdapter;
50
+ /** Optional adapter for getting all Expressions */
51
+ readonly getAllAdapter?: GetAllAdapter;
52
+ /** Optional adapter for direct messaging between agents */
53
+ readonly directMessageAdapter?: DirectMessageAdapter;
54
+ /** Interface for providing UI components for the settings of this Language */
55
+ readonly settingsUI?: SettingsUI;
56
+ /** Optional function to make any cleanup/teardown if your language gets deleting in the ad4m-executor */
57
+ readonly teardown?: () => void;
58
+ /** All available interactions this agent could execute on given expression */
59
+ interactions(expression: Address): Interaction[];
60
+ }
61
+ /** UI factories returning web components */
62
+ export interface ExpressionUI {
63
+ /** Returns JS code of a web component that renders the given expression */
64
+ icon(): string;
65
+ /** Returns JS code of a web component used to create new expressions */
66
+ constructorIcon(): string;
67
+ }
68
+ export interface SettingsUI {
69
+ settingsIcon(): string;
70
+ }
71
+ /** Interface for the most common Expression Languages */
72
+ export interface ExpressionAdapter {
73
+ /** Returns an Expression by address, or null if there is no Expression
74
+ * with that given address
75
+ */
76
+ get(address: Address): Promise<Expression | null>;
77
+ /** Strategy for putting an expression with needs to be different
78
+ * for those two cases:
79
+ * 1. PublicSharing means that this language supports the creation
80
+ * and sharing of Expressions, which is the common use-case
81
+ * 2. ReadOnlyLanguage means that the Language implements a pre-defined
82
+ * set of expressions (which can be infinite or finite).
83
+ * For example the url-iframe Language which directly maps URLs to
84
+ * addresses - meaning every well formed URL is an address in this
85
+ * Language. Or a potential Language implementing the verbs/predicates
86
+ * of a spec like FOAF.
87
+ */
88
+ putAdapter: PublicSharing | ReadOnlyLanguage;
89
+ }
90
+ /** Implement this interface if your Language supports creation of sharing
91
+ * of Expressions.
92
+ * See ExpressionAdapter
93
+ */
94
+ export interface PublicSharing {
95
+ /** Create an Expression and shares it.
96
+ * Return the Expression's address.
97
+ * @param content is the object created by the constructorIcon component
98
+ */
99
+ createPublic(content: object): Promise<Address>;
100
+ }
101
+ /** Implement this interface if your Language is defined over a static
102
+ * set of pre-defined Expressions.
103
+ */
104
+ export interface ReadOnlyLanguage {
105
+ /** This just calculates the address of an object
106
+ * @param content is the object created by the constructorIcon component
107
+ */
108
+ addressOf(content: object): Promise<Address>;
109
+ }
110
+ export interface LanguageAdapter {
111
+ getLanguageSource(address: Address): Promise<string>;
112
+ }
113
+ export interface GetByAuthorAdapter {
114
+ getByAuthor(author: DID, count: number, page: number): Promise<Expression[] | null>;
115
+ }
116
+ export interface GetAllAdapter {
117
+ getAll(filter: any, count: number, page: number): Promise<Expression[] | null>;
118
+ }
119
+ export type PerspectiveDiffObserver = (diff: PerspectiveDiff) => void;
120
+ export type SyncStateChangeObserver = (state: PerspectiveState) => void;
121
+ /** Interface for "Link Languages" that facilitate the synchronization
122
+ * between agents' local Perspectives inside a Neighbourhood.
123
+ * The assumption is that every version of the shared Perspective
124
+ * is labeled with a unique revision string.
125
+ * Changes are committed and retrieved through diffs.
126
+ * Think of a LinkSyncAdapter as a git branch to which agents commit
127
+ * their changes to and pull diffs from their current revision
128
+ * to the latest one.
129
+ */
130
+ export interface LinkSyncAdapter {
131
+ writable(): boolean;
132
+ public(): boolean;
133
+ others(): Promise<DID[]>;
134
+ /** What revision are we on now -> what changes are included in output of render() */
135
+ currentRevision(): Promise<string>;
136
+ /**
137
+ * Check for and get new changes,
138
+ * notify others of local changes.
139
+ * This function will be called every
140
+ * few seconds by the ad4m-executor.
141
+ * */
142
+ sync(): Promise<PerspectiveDiff>;
143
+ /** Returns the full, rendered Perspective at currentRevision */
144
+ render(): Promise<Perspective>;
145
+ /** Publish changes */
146
+ commit(diff: PerspectiveDiff): Promise<string>;
147
+ /** Get push notification when a diff got published */
148
+ addCallback(callback: PerspectiveDiffObserver): any;
149
+ /** Add a sync state callback method */
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;
162
+ }
163
+ export type MessageCallback = (message: PerspectiveExpression) => void;
164
+ export type StatusCallback = (caller: DID) => Perspective;
165
+ export interface DirectMessageAdapter {
166
+ recipient(): DID;
167
+ status(): Promise<PerspectiveExpression | void>;
168
+ sendP2P(message: Perspective): Promise<PerspectiveExpression | void>;
169
+ sendInbox(message: Perspective): Promise<PerspectiveExpression | void>;
170
+ setStatus(status: PerspectiveExpression): any;
171
+ inbox(filter?: string): Promise<PerspectiveExpression[]>;
172
+ addMessageCallback(callback: MessageCallback): any;
173
+ }
174
+ export declare class InteractionParameter {
175
+ name: string;
176
+ type: string;
177
+ }
178
+ export declare class InteractionMeta {
179
+ label: string;
180
+ name: string;
181
+ parameters: InteractionParameter[];
182
+ }
183
+ export interface Interaction {
184
+ readonly label: string;
185
+ readonly name: string;
186
+ readonly parameters: InteractionParameter[];
187
+ execute(parameters: object): Promise<string | null>;
188
+ }
189
+ export declare class InteractionCall {
190
+ name: string;
191
+ parametersStringified: string;
192
+ get parameters(): object;
193
+ constructor(name: string, parameters: object);
194
+ }
195
+ export declare class OnlineAgent {
196
+ did: DID;
197
+ status: PerspectiveExpression;
198
+ }
199
+ export type TelepresenceSignalCallback = (payload: PerspectiveExpression, recipientDid?: string) => void;
200
+ export interface TelepresenceAdapter {
201
+ setOnlineStatus(status: PerspectiveExpression): Promise<void>;
202
+ getOnlineAgents(): Promise<OnlineAgent[]>;
203
+ sendSignal(remoteAgentDid: string, payload: PerspectiveExpression): Promise<object>;
204
+ sendBroadcast(payload: PerspectiveExpression): Promise<object>;
205
+ registerSignalCallback(callback: TelepresenceSignalCallback): Promise<void>;
206
+ }
@@ -0,0 +1,17 @@
1
+ import { ApolloClient } from "@apollo/client/core";
2
+ import { LanguageHandle } from "./LanguageHandle";
3
+ import { LanguageMeta, LanguageMetaInput } from "./LanguageMeta";
4
+ import { LanguageRef } from "./LanguageRef";
5
+ export declare class LanguageClient {
6
+ #private;
7
+ constructor(apolloClient: ApolloClient<any>);
8
+ byAddress(address: string): Promise<LanguageHandle>;
9
+ byFilter(filter: string): Promise<LanguageHandle[]>;
10
+ all(): Promise<LanguageHandle[]>;
11
+ writeSettings(languageAddress: string, settings: string): Promise<Boolean>;
12
+ applyTemplateAndPublish(sourceLanguageHash: string, templateData: string): Promise<LanguageRef>;
13
+ publish(languagePath: string, languageMeta: LanguageMetaInput): Promise<LanguageMeta>;
14
+ meta(address: string): Promise<LanguageMeta>;
15
+ source(address: string): Promise<string>;
16
+ remove(address: string): Promise<Boolean>;
17
+ }
@@ -0,0 +1,37 @@
1
+ /// <reference types="node" />
2
+ import type { AppSignalCb } from '@holochain/client';
3
+ import { Expression } from "../expression/Expression";
4
+ export interface AgentService {
5
+ readonly did: string;
6
+ createSignedExpression(data: any): Expression;
7
+ }
8
+ export interface SignaturesService {
9
+ verify(expr: Expression): boolean;
10
+ }
11
+ export interface LanguageContext {
12
+ agent: AgentService;
13
+ signatures: SignaturesService;
14
+ storageDirectory: string;
15
+ customSettings: object;
16
+ Holochain: HolochainLanguageDelegate | undefined;
17
+ ad4mSignal: Ad4mSignalCB;
18
+ }
19
+ export declare class Dna {
20
+ file: Buffer;
21
+ nick: string;
22
+ zomeCalls: [string, string][];
23
+ }
24
+ export interface HolochainLanguageDelegate {
25
+ /** Installs/registers a given DNA in the ad4m-executor */
26
+ registerDNAs(dnas: Dna[], holochainSignalCallback?: AppSignalCb): Promise<void>;
27
+ /** Makes a single call to a given holochain DNA. Underlying implementation puts these calls into a sync fifo queue */
28
+ call(dnaNick: string, zomeName: string, fnName: string, params: object | string): Promise<any>;
29
+ /** Makes all supplied calls in parallel to the provided holochain dna... Should only be called on read operations to avoid source chain async mutation errors */
30
+ callAsync(calls: {
31
+ dnaNick: string;
32
+ zomeName: string;
33
+ fnName: string;
34
+ params: object | string;
35
+ }[], timeoutMs?: number): Promise<any[]>;
36
+ }
37
+ export type Ad4mSignalCB = (signal: any) => void;
@@ -0,0 +1,9 @@
1
+ import { Icon } from "./Icon";
2
+ export declare class LanguageHandle {
3
+ name: string;
4
+ address: string;
5
+ settings?: string;
6
+ icon?: Icon;
7
+ constructorIcon?: Icon;
8
+ settingsIcon?: Icon;
9
+ }