@ddd-qc/agent-directory 1.165.0
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/package.json +29 -0
- package/src/agent_directory.bridge.ts +44 -0
- package/src/agent_directory.vm.ts +71 -0
- package/src/elements/agent-directory-list.ts +74 -0
- package/src/index.ts +2 -0
- package/tsconfig.json +22 -0
package/package.json
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
{
|
2
|
+
"name": "@ddd-qc/agent-directory",
|
3
|
+
"version": "1.165.0",
|
4
|
+
"main": "./dist/index.js",
|
5
|
+
"module": "./dist/index.js",
|
6
|
+
"typings": "./dist/index.d.ts",
|
7
|
+
"scripts": {
|
8
|
+
"build": "tsc",
|
9
|
+
"build:watch": "tsc --watch --preserveWatchOutput",
|
10
|
+
"analyze": "lit-analyzer src --failFast"
|
11
|
+
},
|
12
|
+
"type": "module",
|
13
|
+
"devDependencies": {
|
14
|
+
"lit-analyzer": "^1.2.1",
|
15
|
+
"watch-cli": "^0.2.3",
|
16
|
+
"tslib": "^2.3.1",
|
17
|
+
"typescript": "4.3.5"
|
18
|
+
},
|
19
|
+
"dependencies": {
|
20
|
+
"@holochain/client": "^0.9.2",
|
21
|
+
"@holochain-open-dev/cell-client": "^0.7.3",
|
22
|
+
"@holochain-open-dev/core-types": "^0.5.0",
|
23
|
+
"@holochain-open-dev/utils": "0.4.0",
|
24
|
+
"@lit-labs/context": "^0.1.2",
|
25
|
+
"@open-wc/scoped-elements": "^2.0.1",
|
26
|
+
"lit": "^2.2.0",
|
27
|
+
"svelte": "^3.42.4"
|
28
|
+
}
|
29
|
+
}
|
@@ -0,0 +1,44 @@
|
|
1
|
+
import {AgentPubKey, CellId} from "@holochain/client";
|
2
|
+
import {AgnosticClient} from '@holochain-open-dev/cell-client';
|
3
|
+
|
4
|
+
|
5
|
+
/**
|
6
|
+
*
|
7
|
+
*/
|
8
|
+
export class AgentDirectoryBridge {
|
9
|
+
/** Ctor */
|
10
|
+
constructor(public agnosticClient: AgnosticClient, public cellId: CellId, defaultTimeout?: number) {
|
11
|
+
this.defaultTimeout = defaultTimeout? defaultTimeout : 10 * 1000;
|
12
|
+
}
|
13
|
+
|
14
|
+
defaultTimeout: number;
|
15
|
+
|
16
|
+
|
17
|
+
/** Zome API */
|
18
|
+
|
19
|
+
async getAllAgents(): Promise<AgentPubKey[]> {
|
20
|
+
return this.callZome('get_registered_agents', null);
|
21
|
+
}
|
22
|
+
|
23
|
+
|
24
|
+
/** Private */
|
25
|
+
|
26
|
+
/** */
|
27
|
+
private callZome(fn_name: string, payload: any): Promise<any> {
|
28
|
+
//console.log("callZome: agent_directory." + fn_name + "() ", payload)
|
29
|
+
//console.info({payload})
|
30
|
+
try {
|
31
|
+
const result = this.agnosticClient.callZome(this.cellId, "agent_directory", fn_name, payload, this.defaultTimeout);
|
32
|
+
//console.log("callZome: agent_directory." + fn_name + "() result")
|
33
|
+
//console.info({result})
|
34
|
+
return result;
|
35
|
+
} catch (e) {
|
36
|
+
console.error("Calling zome agent_directory." + fn_name + "() failed: ")
|
37
|
+
console.error({e})
|
38
|
+
}
|
39
|
+
return Promise.reject("callZome failed")
|
40
|
+
}
|
41
|
+
|
42
|
+
|
43
|
+
|
44
|
+
}
|
@@ -0,0 +1,71 @@
|
|
1
|
+
import {createContext} from "@lit-labs/context";
|
2
|
+
import {LitElement} from "lit";
|
3
|
+
import {writable, Writable, get} from "svelte/store";
|
4
|
+
|
5
|
+
import {CellId} from "@holochain/client";
|
6
|
+
import {AgentPubKeyB64} from '@holochain-open-dev/core-types';
|
7
|
+
import {AgnosticClient} from '@holochain-open-dev/cell-client';
|
8
|
+
import {serializeHash} from "@holochain-open-dev/utils";
|
9
|
+
|
10
|
+
import {AgentDirectoryBridge} from "./agent_directory.bridge";
|
11
|
+
|
12
|
+
/** Global Context */
|
13
|
+
export const agentDirectoryContext = createContext<AgentDirectoryViewModel>('agent_directory/service');
|
14
|
+
|
15
|
+
|
16
|
+
/**
|
17
|
+
*
|
18
|
+
*/
|
19
|
+
export class AgentDirectoryViewModel {
|
20
|
+
/** Ctor */
|
21
|
+
constructor(protected client: AgnosticClient, cellId: CellId) {
|
22
|
+
this._bridge = new AgentDirectoryBridge(client, cellId);
|
23
|
+
this.myAgentPubKey = serializeHash(cellId[1]);
|
24
|
+
// this.bridge.getProperties().then((properties) => {
|
25
|
+
// this.latestBucketIndex = Math.floor(properties.startTime / properties.bucketSizeSec) - 1;
|
26
|
+
// });
|
27
|
+
}
|
28
|
+
|
29
|
+
/** -- Fields -- */
|
30
|
+
|
31
|
+
/** Private */
|
32
|
+
private _bridge : AgentDirectoryBridge
|
33
|
+
//private _dnaProperties?: DnaProperties;
|
34
|
+
private _agentStore: Writable<AgentPubKeyB64[]> = writable([]);
|
35
|
+
|
36
|
+
/** Public */
|
37
|
+
myAgentPubKey: AgentPubKeyB64;
|
38
|
+
|
39
|
+
|
40
|
+
/** -- Methods -- */
|
41
|
+
|
42
|
+
/** */
|
43
|
+
agents(): AgentPubKeyB64[] {
|
44
|
+
return get(this._agentStore);
|
45
|
+
}
|
46
|
+
|
47
|
+
/** */
|
48
|
+
subscribe(parent: LitElement) {
|
49
|
+
this._agentStore.subscribe((value) => {
|
50
|
+
//console.log("localTaskListStore update called");
|
51
|
+
parent.requestUpdate();
|
52
|
+
});
|
53
|
+
}
|
54
|
+
|
55
|
+
|
56
|
+
/** */
|
57
|
+
async pullAllFromDht() {
|
58
|
+
await this.pullAllRegisteredAgents();
|
59
|
+
}
|
60
|
+
|
61
|
+
|
62
|
+
/** */
|
63
|
+
async pullAllRegisteredAgents() {
|
64
|
+
let agents = await this._bridge.getAllAgents();
|
65
|
+
this._agentStore.update(store => {
|
66
|
+
store = agents.map((agentKey) => serializeHash(agentKey));
|
67
|
+
return store;
|
68
|
+
})
|
69
|
+
}
|
70
|
+
|
71
|
+
}
|
@@ -0,0 +1,74 @@
|
|
1
|
+
import {css, html, LitElement} from "lit";
|
2
|
+
import {property, state} from "lit/decorators.js";
|
3
|
+
import { contextProvided } from '@lit-labs/context';
|
4
|
+
import {ScopedElementsMixin} from "@open-wc/scoped-elements";
|
5
|
+
import {agentDirectoryContext, AgentDirectoryViewModel} from "../agent_directory.vm";
|
6
|
+
|
7
|
+
|
8
|
+
/**
|
9
|
+
* @element agent-directory-list
|
10
|
+
*/
|
11
|
+
export class AgentDirectoryList extends ScopedElementsMixin(LitElement) {
|
12
|
+
/** Ctor */
|
13
|
+
constructor() {
|
14
|
+
super();
|
15
|
+
}
|
16
|
+
|
17
|
+
|
18
|
+
/** -- Fields -- */
|
19
|
+
|
20
|
+
@state() initialized = false;
|
21
|
+
|
22
|
+
@contextProvided({ context: agentDirectoryContext })
|
23
|
+
_viewModel!: AgentDirectoryViewModel; // WARN: is actually undefined at startup
|
24
|
+
|
25
|
+
|
26
|
+
/** -- Methods -- */
|
27
|
+
|
28
|
+
/** After first call to render() */
|
29
|
+
async firstUpdated() {
|
30
|
+
this._viewModel.subscribe(this);
|
31
|
+
await this.refresh();
|
32
|
+
this.initialized = true;
|
33
|
+
}
|
34
|
+
|
35
|
+
|
36
|
+
/** After each call to render() */
|
37
|
+
async updated(changedProperties: any) {
|
38
|
+
// n/a
|
39
|
+
}
|
40
|
+
|
41
|
+
|
42
|
+
/** */
|
43
|
+
async refresh(_e?: any) {
|
44
|
+
//console.log("refresh(): Pulling data from DHT")
|
45
|
+
await this._viewModel.pullAllFromDht();
|
46
|
+
}
|
47
|
+
|
48
|
+
|
49
|
+
/** */
|
50
|
+
render() {
|
51
|
+
console.log("agent-directory-list render() START");
|
52
|
+
|
53
|
+
if (!this.initialized) {
|
54
|
+
return html`<span>Loading...</span>`;
|
55
|
+
}
|
56
|
+
|
57
|
+
let agents = this._viewModel.agents();
|
58
|
+
|
59
|
+
/* Agents */
|
60
|
+
const agentLi = Object.entries(agents).map(
|
61
|
+
([_index, agentIdB64]) => {
|
62
|
+
//console.log("" + index + ". " + agentIdB64)
|
63
|
+
return html `<li value="${agentIdB64}">${agentIdB64}</li>`
|
64
|
+
}
|
65
|
+
)
|
66
|
+
|
67
|
+
/** render all */
|
68
|
+
return html`
|
69
|
+
<ul>
|
70
|
+
${agentLi}
|
71
|
+
</ul>
|
72
|
+
`;
|
73
|
+
}
|
74
|
+
}
|
package/src/index.ts
ADDED
package/tsconfig.json
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
{
|
2
|
+
"compilerOptions": {
|
3
|
+
"target": "es2018",
|
4
|
+
"module": "esnext",
|
5
|
+
"moduleResolution": "node",
|
6
|
+
"noEmitOnError": true,
|
7
|
+
"lib": ["es2017", "dom"],
|
8
|
+
"strict": true,
|
9
|
+
"esModuleInterop": false,
|
10
|
+
"allowSyntheticDefaultImports": true,
|
11
|
+
"experimentalDecorators": true,
|
12
|
+
"importHelpers": true,
|
13
|
+
"sourceMap": true,
|
14
|
+
"inlineSources": true,
|
15
|
+
"outDir": "dist",
|
16
|
+
"declarationDir": "dist",
|
17
|
+
"rootDir": "./src",
|
18
|
+
"declaration": true
|
19
|
+
},
|
20
|
+
|
21
|
+
"include": ["src/**/*.ts"]
|
22
|
+
}
|