@ddd-qc/agent-directory 1.165.1 → 1.165.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,17 @@
1
+ import { AgentPubKey, CellId } from "@holochain/client";
2
+ import { AgnosticClient } from '@holochain-open-dev/cell-client';
3
+ /**
4
+ *
5
+ */
6
+ export declare class AgentDirectoryBridge {
7
+ agnosticClient: AgnosticClient;
8
+ cellId: CellId;
9
+ /** Ctor */
10
+ constructor(agnosticClient: AgnosticClient, cellId: CellId, defaultTimeout?: number);
11
+ defaultTimeout: number;
12
+ /** Zome API */
13
+ getAllAgents(): Promise<AgentPubKey[]>;
14
+ /** Private */
15
+ /** */
16
+ private callZome;
17
+ }
@@ -0,0 +1,33 @@
1
+ /**
2
+ *
3
+ */
4
+ export class AgentDirectoryBridge {
5
+ /** Ctor */
6
+ constructor(agnosticClient, cellId, defaultTimeout) {
7
+ this.agnosticClient = agnosticClient;
8
+ this.cellId = cellId;
9
+ this.defaultTimeout = defaultTimeout ? defaultTimeout : 10 * 1000;
10
+ }
11
+ /** Zome API */
12
+ async getAllAgents() {
13
+ return this.callZome('get_registered_agents', null);
14
+ }
15
+ /** Private */
16
+ /** */
17
+ callZome(fn_name, payload) {
18
+ //console.log("callZome: agent_directory." + fn_name + "() ", payload)
19
+ //console.info({payload})
20
+ try {
21
+ const result = this.agnosticClient.callZome(this.cellId, "agent_directory", fn_name, payload, this.defaultTimeout);
22
+ //console.log("callZome: agent_directory." + fn_name + "() result")
23
+ //console.info({result})
24
+ return result;
25
+ }
26
+ catch (e) {
27
+ console.error("Calling zome agent_directory." + fn_name + "() failed: ");
28
+ console.error({ e });
29
+ }
30
+ return Promise.reject("callZome failed");
31
+ }
32
+ }
33
+ //# sourceMappingURL=agent_directory.bridge.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent_directory.bridge.js","sourceRoot":"","sources":["../src/agent_directory.bridge.ts"],"names":[],"mappings":"AAIA;;GAEG;AACH,MAAM,OAAO,oBAAoB;IAC/B,WAAW;IACX,YAAmB,cAA8B,EAAS,MAAc,EAAE,cAAuB;QAA9E,mBAAc,GAAd,cAAc,CAAgB;QAAS,WAAM,GAAN,MAAM,CAAQ;QACtE,IAAI,CAAC,cAAc,GAAG,cAAc,CAAA,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,EAAE,GAAG,IAAI,CAAC;IACnE,CAAC;IAKD,eAAe;IAEf,KAAK,CAAC,YAAY;QAChB,OAAO,IAAI,CAAC,QAAQ,CAAC,uBAAuB,EAAE,IAAI,CAAC,CAAC;IACtD,CAAC;IAGD,cAAc;IAEd,MAAM;IACE,QAAQ,CAAC,OAAe,EAAE,OAAY;QAC5C,sEAAsE;QACtE,yBAAyB;QACzB,IAAI;YACF,MAAM,MAAM,GAAG,IAAI,CAAC,cAAc,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,EAAE,iBAAiB,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,CAAC,cAAc,CAAC,CAAC;YACnH,mEAAmE;YACnE,wBAAwB;YACxB,OAAO,MAAM,CAAC;SACf;QAAC,OAAO,CAAC,EAAE;YACV,OAAO,CAAC,KAAK,CAAC,+BAA+B,GAAG,OAAO,GAAG,aAAa,CAAC,CAAA;YACxE,OAAO,CAAC,KAAK,CAAC,EAAC,CAAC,EAAC,CAAC,CAAA;SACnB;QACD,OAAO,OAAO,CAAC,MAAM,CAAC,iBAAiB,CAAC,CAAA;IAC1C,CAAC;CAIF","sourcesContent":["import {AgentPubKey, CellId} from \"@holochain/client\";\nimport {AgnosticClient} from '@holochain-open-dev/cell-client';\n\n\n/**\n *\n */\nexport class AgentDirectoryBridge {\n /** Ctor */\n constructor(public agnosticClient: AgnosticClient, public cellId: CellId, defaultTimeout?: number) {\n this.defaultTimeout = defaultTimeout? defaultTimeout : 10 * 1000;\n }\n\n defaultTimeout: number;\n\n\n /** Zome API */\n\n async getAllAgents(): Promise<AgentPubKey[]> {\n return this.callZome('get_registered_agents', null);\n }\n\n\n /** Private */\n\n /** */\n private callZome(fn_name: string, payload: any): Promise<any> {\n //console.log(\"callZome: agent_directory.\" + fn_name + \"() \", payload)\n //console.info({payload})\n try {\n const result = this.agnosticClient.callZome(this.cellId, \"agent_directory\", fn_name, payload, this.defaultTimeout);\n //console.log(\"callZome: agent_directory.\" + fn_name + \"() result\")\n //console.info({result})\n return result;\n } catch (e) {\n console.error(\"Calling zome agent_directory.\" + fn_name + \"() failed: \")\n console.error({e})\n }\n return Promise.reject(\"callZome failed\")\n }\n\n\n\n}\n"]}
@@ -0,0 +1,31 @@
1
+ import { LitElement } from "lit";
2
+ import { CellId } from "@holochain/client";
3
+ import { AgentPubKeyB64 } from '@holochain-open-dev/core-types';
4
+ import { AgnosticClient } from '@holochain-open-dev/cell-client';
5
+ /** Global Context */
6
+ export declare const agentDirectoryContext: {
7
+ __context__: AgentDirectoryViewModel;
8
+ };
9
+ /**
10
+ *
11
+ */
12
+ export declare class AgentDirectoryViewModel {
13
+ protected client: AgnosticClient;
14
+ /** Ctor */
15
+ constructor(client: AgnosticClient, cellId: CellId);
16
+ /** -- Fields -- */
17
+ /** Private */
18
+ private _bridge;
19
+ private _agentStore;
20
+ /** Public */
21
+ myAgentPubKey: AgentPubKeyB64;
22
+ /** -- Methods -- */
23
+ /** */
24
+ agents(): AgentPubKeyB64[];
25
+ /** */
26
+ subscribe(parent: LitElement): void;
27
+ /** */
28
+ pullAllFromDht(): Promise<void>;
29
+ /** */
30
+ pullAllRegisteredAgents(): Promise<void>;
31
+ }
@@ -0,0 +1,47 @@
1
+ import { createContext } from "@lit-labs/context";
2
+ import { writable, get } from "svelte/store";
3
+ import { serializeHash } from "@holochain-open-dev/utils";
4
+ import { AgentDirectoryBridge } from "./agent_directory.bridge";
5
+ /** Global Context */
6
+ export const agentDirectoryContext = createContext('agent_directory/service');
7
+ /**
8
+ *
9
+ */
10
+ export class AgentDirectoryViewModel {
11
+ /** Ctor */
12
+ constructor(client, cellId) {
13
+ this.client = client;
14
+ //private _dnaProperties?: DnaProperties;
15
+ this._agentStore = writable([]);
16
+ this._bridge = new AgentDirectoryBridge(client, cellId);
17
+ this.myAgentPubKey = serializeHash(cellId[1]);
18
+ // this.bridge.getProperties().then((properties) => {
19
+ // this.latestBucketIndex = Math.floor(properties.startTime / properties.bucketSizeSec) - 1;
20
+ // });
21
+ }
22
+ /** -- Methods -- */
23
+ /** */
24
+ agents() {
25
+ return get(this._agentStore);
26
+ }
27
+ /** */
28
+ subscribe(parent) {
29
+ this._agentStore.subscribe((value) => {
30
+ //console.log("localTaskListStore update called");
31
+ parent.requestUpdate();
32
+ });
33
+ }
34
+ /** */
35
+ async pullAllFromDht() {
36
+ await this.pullAllRegisteredAgents();
37
+ }
38
+ /** */
39
+ async pullAllRegisteredAgents() {
40
+ let agents = await this._bridge.getAllAgents();
41
+ this._agentStore.update(store => {
42
+ store = agents.map((agentKey) => serializeHash(agentKey));
43
+ return store;
44
+ });
45
+ }
46
+ }
47
+ //# sourceMappingURL=agent_directory.vm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent_directory.vm.js","sourceRoot":"","sources":["../src/agent_directory.vm.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,aAAa,EAAC,MAAM,mBAAmB,CAAC;AAEhD,OAAO,EAAC,QAAQ,EAAY,GAAG,EAAC,MAAM,cAAc,CAAC;AAKrD,OAAO,EAAC,aAAa,EAAC,MAAM,2BAA2B,CAAC;AAExD,OAAO,EAAC,oBAAoB,EAAC,MAAM,0BAA0B,CAAC;AAE9D,qBAAqB;AACrB,MAAM,CAAC,MAAM,qBAAqB,GAAG,aAAa,CAA0B,yBAAyB,CAAC,CAAC;AAGvG;;GAEG;AACH,MAAM,OAAO,uBAAuB;IAClC,WAAW;IACX,YAAsB,MAAsB,EAAE,MAAc;QAAtC,WAAM,GAAN,MAAM,CAAgB;QAY5C,yCAAyC;QACjC,gBAAW,GAA+B,QAAQ,CAAC,EAAE,CAAC,CAAC;QAZ7D,IAAI,CAAC,OAAO,GAAG,IAAI,oBAAoB,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QACxD,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;QAC9C,qDAAqD;QACrD,8FAA8F;QAC9F,MAAM;IACR,CAAC;IAaD,oBAAoB;IAEpB,MAAM;IACN,MAAM;QACJ,OAAO,GAAG,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IAC/B,CAAC;IAED,MAAM;IACN,SAAS,CAAC,MAAkB;QAC1B,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC,KAAK,EAAE,EAAE;YACnC,kDAAkD;YAClD,MAAM,CAAC,aAAa,EAAE,CAAC;QACzB,CAAC,CAAC,CAAC;IACL,CAAC;IAGD,MAAM;IACN,KAAK,CAAC,cAAc;QAClB,MAAM,IAAI,CAAC,uBAAuB,EAAE,CAAC;IACvC,CAAC;IAGD,MAAM;IACN,KAAK,CAAC,uBAAuB;QAC3B,IAAI,MAAM,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,YAAY,EAAE,CAAC;QAC/C,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE;YAC9B,KAAK,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC,CAAC;YAC1D,OAAO,KAAK,CAAC;QACf,CAAC,CAAC,CAAA;IACJ,CAAC;CAEF","sourcesContent":["import {createContext} from \"@lit-labs/context\";\nimport {LitElement} from \"lit\";\nimport {writable, Writable, get} from \"svelte/store\";\n\nimport {CellId} from \"@holochain/client\";\nimport {AgentPubKeyB64} from '@holochain-open-dev/core-types';\nimport {AgnosticClient} from '@holochain-open-dev/cell-client';\nimport {serializeHash} from \"@holochain-open-dev/utils\";\n\nimport {AgentDirectoryBridge} from \"./agent_directory.bridge\";\n\n/** Global Context */\nexport const agentDirectoryContext = createContext<AgentDirectoryViewModel>('agent_directory/service');\n\n\n/**\n *\n */\nexport class AgentDirectoryViewModel {\n /** Ctor */\n constructor(protected client: AgnosticClient, cellId: CellId) {\n this._bridge = new AgentDirectoryBridge(client, cellId);\n this.myAgentPubKey = serializeHash(cellId[1]);\n // this.bridge.getProperties().then((properties) => {\n // this.latestBucketIndex = Math.floor(properties.startTime / properties.bucketSizeSec) - 1;\n // });\n }\n\n /** -- Fields -- */\n\n /** Private */\n private _bridge : AgentDirectoryBridge\n //private _dnaProperties?: DnaProperties;\n private _agentStore: Writable<AgentPubKeyB64[]> = writable([]);\n\n /** Public */\n myAgentPubKey: AgentPubKeyB64;\n\n\n /** -- Methods -- */\n\n /** */\n agents(): AgentPubKeyB64[] {\n return get(this._agentStore);\n }\n\n /** */\n subscribe(parent: LitElement) {\n this._agentStore.subscribe((value) => {\n //console.log(\"localTaskListStore update called\");\n parent.requestUpdate();\n });\n }\n\n\n /** */\n async pullAllFromDht() {\n await this.pullAllRegisteredAgents();\n }\n\n\n /** */\n async pullAllRegisteredAgents() {\n let agents = await this._bridge.getAllAgents();\n this._agentStore.update(store => {\n store = agents.map((agentKey) => serializeHash(agentKey));\n return store;\n })\n }\n\n}\n"]}
@@ -0,0 +1,23 @@
1
+ import { LitElement } from "lit";
2
+ import { AgentDirectoryViewModel } from "../agent_directory.vm";
3
+ declare const AgentDirectoryList_base: typeof LitElement & import("@open-wc/dedupe-mixin").Constructor<import("@open-wc/scoped-elements/types/src/types").ScopedElementsHost>;
4
+ /**
5
+ * @element agent-directory-list
6
+ */
7
+ export declare class AgentDirectoryList extends AgentDirectoryList_base {
8
+ /** Ctor */
9
+ constructor();
10
+ /** -- Fields -- */
11
+ initialized: boolean;
12
+ _viewModel: AgentDirectoryViewModel;
13
+ /** -- Methods -- */
14
+ /** After first call to render() */
15
+ firstUpdated(): Promise<void>;
16
+ /** After each call to render() */
17
+ updated(changedProperties: any): Promise<void>;
18
+ /** */
19
+ refresh(_e?: any): Promise<void>;
20
+ /** */
21
+ render(): import("lit-html").TemplateResult<1>;
22
+ }
23
+ export {};
@@ -0,0 +1,59 @@
1
+ import { __decorate } from "tslib";
2
+ import { html, LitElement } from "lit";
3
+ import { state } from "lit/decorators.js";
4
+ import { contextProvided } from '@lit-labs/context';
5
+ import { ScopedElementsMixin } from "@open-wc/scoped-elements";
6
+ import { agentDirectoryContext } from "../agent_directory.vm";
7
+ /**
8
+ * @element agent-directory-list
9
+ */
10
+ export class AgentDirectoryList extends ScopedElementsMixin(LitElement) {
11
+ /** Ctor */
12
+ constructor() {
13
+ super();
14
+ /** -- Fields -- */
15
+ this.initialized = false;
16
+ }
17
+ /** -- Methods -- */
18
+ /** After first call to render() */
19
+ async firstUpdated() {
20
+ this._viewModel.subscribe(this);
21
+ await this.refresh();
22
+ this.initialized = true;
23
+ }
24
+ /** After each call to render() */
25
+ async updated(changedProperties) {
26
+ // n/a
27
+ }
28
+ /** */
29
+ async refresh(_e) {
30
+ //console.log("refresh(): Pulling data from DHT")
31
+ await this._viewModel.pullAllFromDht();
32
+ }
33
+ /** */
34
+ render() {
35
+ console.log("agent-directory-list render() START");
36
+ if (!this.initialized) {
37
+ return html `<span>Loading...</span>`;
38
+ }
39
+ let agents = this._viewModel.agents();
40
+ /* Agents */
41
+ const agentLi = Object.entries(agents).map(([_index, agentIdB64]) => {
42
+ //console.log("" + index + ". " + agentIdB64)
43
+ return html `<li value="${agentIdB64}">${agentIdB64}</li>`;
44
+ });
45
+ /** render all */
46
+ return html `
47
+ <ul>
48
+ ${agentLi}
49
+ </ul>
50
+ `;
51
+ }
52
+ }
53
+ __decorate([
54
+ state()
55
+ ], AgentDirectoryList.prototype, "initialized", void 0);
56
+ __decorate([
57
+ contextProvided({ context: agentDirectoryContext })
58
+ ], AgentDirectoryList.prototype, "_viewModel", void 0);
59
+ //# sourceMappingURL=agent-directory-list.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent-directory-list.js","sourceRoot":"","sources":["../../src/elements/agent-directory-list.ts"],"names":[],"mappings":";AAAA,OAAO,EAAM,IAAI,EAAE,UAAU,EAAC,MAAM,KAAK,CAAC;AAC1C,OAAO,EAAW,KAAK,EAAC,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAC,mBAAmB,EAAC,MAAM,0BAA0B,CAAC;AAC7D,OAAO,EAAC,qBAAqB,EAA0B,MAAM,uBAAuB,CAAC;AAGrF;;GAEG;AACH,MAAM,OAAO,kBAAmB,SAAQ,mBAAmB,CAAC,UAAU,CAAC;IACrE,WAAW;IACX;QACE,KAAK,EAAE,CAAC;QAIV,mBAAmB;QAEV,gBAAW,GAAG,KAAK,CAAC;IAL7B,CAAC;IAWD,oBAAoB;IAEpB,mCAAmC;IACnC,KAAK,CAAC,YAAY;QAChB,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;QAChC,MAAM,IAAI,CAAC,OAAO,EAAE,CAAC;QACrB,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;IAC1B,CAAC;IAGD,kCAAkC;IAClC,KAAK,CAAC,OAAO,CAAC,iBAAsB;QAClC,MAAM;IACR,CAAC;IAGD,MAAM;IACN,KAAK,CAAC,OAAO,CAAC,EAAQ;QACpB,iDAAiD;QACjD,MAAM,IAAI,CAAC,UAAU,CAAC,cAAc,EAAE,CAAC;IACzC,CAAC;IAGD,MAAM;IACN,MAAM;QACJ,OAAO,CAAC,GAAG,CAAC,qCAAqC,CAAC,CAAC;QAEnD,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE;YACrB,OAAO,IAAI,CAAA,yBAAyB,CAAC;SACtC;QAED,IAAI,MAAM,GAAG,IAAI,CAAC,UAAU,CAAC,MAAM,EAAE,CAAC;QAEtC,YAAY;QACZ,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,GAAG,CACtC,CAAC,CAAC,MAAM,EAAE,UAAU,CAAC,EAAE,EAAE;YACvB,6CAA6C;YAC7C,OAAO,IAAI,CAAC,cAAc,UAAU,KAAK,UAAU,OAAO,CAAA;QAC5D,CAAC,CACJ,CAAA;QAED,iBAAiB;QACjB,OAAO,IAAI,CAAA;;YAEH,OAAO;;KAEd,CAAC;IACJ,CAAC;CACF;AAtDU;IAAR,KAAK,EAAE;uDAAqB;AAG7B;IADC,eAAe,CAAC,EAAE,OAAO,EAAE,qBAAqB,EAAE,CAAC;sDACf","sourcesContent":["import {css, html, LitElement} from \"lit\";\nimport {property, state} from \"lit/decorators.js\";\nimport { contextProvided } from '@lit-labs/context';\nimport {ScopedElementsMixin} from \"@open-wc/scoped-elements\";\nimport {agentDirectoryContext, AgentDirectoryViewModel} from \"../agent_directory.vm\";\n\n\n/**\n * @element agent-directory-list\n */\nexport class AgentDirectoryList extends ScopedElementsMixin(LitElement) {\n /** Ctor */\n constructor() {\n super();\n }\n\n\n /** -- Fields -- */\n\n @state() initialized = false;\n\n @contextProvided({ context: agentDirectoryContext })\n _viewModel!: AgentDirectoryViewModel; // WARN: is actually undefined at startup\n\n\n /** -- Methods -- */\n\n /** After first call to render() */\n async firstUpdated() {\n this._viewModel.subscribe(this);\n await this.refresh();\n this.initialized = true;\n }\n\n\n /** After each call to render() */\n async updated(changedProperties: any) {\n // n/a\n }\n\n\n /** */\n async refresh(_e?: any) {\n //console.log(\"refresh(): Pulling data from DHT\")\n await this._viewModel.pullAllFromDht();\n }\n\n\n /** */\n render() {\n console.log(\"agent-directory-list render() START\");\n\n if (!this.initialized) {\n return html`<span>Loading...</span>`;\n }\n\n let agents = this._viewModel.agents();\n\n /* Agents */\n const agentLi = Object.entries(agents).map(\n ([_index, agentIdB64]) => {\n //console.log(\"\" + index + \". \" + agentIdB64)\n return html `<li value=\"${agentIdB64}\">${agentIdB64}</li>`\n }\n )\n\n /** render all */\n return html` \n <ul>\n ${agentLi}\n </ul>\n `;\n }\n}\n"]}
@@ -0,0 +1,2 @@
1
+ export * from './agent_directory.vm';
2
+ export * from './elements/agent-directory-list';
package/dist/index.js ADDED
@@ -0,0 +1,3 @@
1
+ export * from './agent_directory.vm';
2
+ export * from './elements/agent-directory-list';
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAC;AACrC,cAAc,iCAAiC,CAAC","sourcesContent":["export * from './agent_directory.vm';\nexport * from './elements/agent-directory-list';"]}
package/package.json CHANGED
@@ -1,16 +1,19 @@
1
1
  {
2
2
  "name": "@ddd-qc/agent-directory",
3
- "version": "1.165.1",
3
+ "version": "1.165.2",
4
4
  "license" : "CAL-1.0",
5
+ "keywords": ["holochain", "zome"],
5
6
  "main": "./dist/index.js",
6
7
  "module": "./dist/index.js",
7
8
  "typings": "./dist/index.d.ts",
9
+ "files": [
10
+ "dist"
11
+ ],
8
12
  "scripts": {
9
13
  "build": "tsc",
10
14
  "build:watch": "tsc --watch --preserveWatchOutput",
11
15
  "analyze": "lit-analyzer src --failFast"
12
16
  },
13
- "type": "module",
14
17
  "devDependencies": {
15
18
  "lit-analyzer": "^1.2.1",
16
19
  "watch-cli": "^0.2.3",
@@ -26,5 +29,9 @@
26
29
  "@open-wc/scoped-elements": "^2.0.1",
27
30
  "lit": "^2.2.0",
28
31
  "svelte": "^3.42.4"
32
+ },
33
+ "type": "module",
34
+ "publishConfig": {
35
+ "access": "public"
29
36
  }
30
37
  }
@@ -1,44 +0,0 @@
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
- }
@@ -1,71 +0,0 @@
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
- }
@@ -1,74 +0,0 @@
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 DELETED
@@ -1,2 +0,0 @@
1
- export * from './agent_directory.vm';
2
- export * from './elements/agent-directory-list';
package/tsconfig.json DELETED
@@ -1,22 +0,0 @@
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
- }