Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test branch: centralized agent and file language #430

Merged
merged 17 commits into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions bootstrap-languages/centralized-agent-language/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
dist/
node_modules/
target/
.hc
.cargo
*.log
*.dna
build/*
*.js
*.js.map
!*.config.icons.js
!*.config.js
!dna.js
build/dna.js
!*-ui.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<svelte:options tag={null}/>

<script lang="ts">
export let commitExpression
</script>

<div>
</div>

<style lang="scss">
</style>
83 changes: 83 additions & 0 deletions bootstrap-languages/centralized-agent-language/Icon.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<svelte:options tag={null}/>

<script lang="ts">
import type { Expression } from "@perspect3vism/ad4m";
import { Literal, Perspective } from "@perspect3vism/ad4m";
import emailValidator from 'email-validator'
import md5 from 'md5'

export let expression: Expression
let did
let email
let firstName
let lastName

async function update() {
let perspective = new Perspective(expression.data.perspective.links)
did = expression.data.did

try {
firstName = Literal.fromUrl(await perspective.getSingleTarget({source: did, predicate: 'foaf://givenName'})).get()
}catch(e) {
firstName = undefined
}

try {
lastName = Literal.fromUrl(await perspective.getSingleTarget({source: did, predicate: 'foaf://familyName'})).get()
}catch(e) {
lastName = undefined
}

try {
email = Literal.fromUrl(await perspective.getSingleTarget({source: did, predicate: 'foaf://mbox'})).get()
}catch(e) {
email = undefined
}
}

$: if(expression) update()

</script>

<div class="container">

<div class="text">
<h1>{did}</h1>
<h2>{firstName} {lastName}</h2>
<h2>{email}</h2>
</div>

{#if emailValidator.validate(email) }
<img src="http://www.gravatar.com/avatar/{md5(email)}?s=360" alt="gravatar" class="image">
{/if}
</div>


<style>
h1 {
width: 100%;
word-break: break-all;
}
.container {
color: white;
width: 400px;
height: 300px;
text-shadow: black;
}

.text {
position: absolute;
left: 0;
right: 0;
top: 0;
bottom: 0;
z-index: 3;
}
.image {
position: absolute;
left: 0;
right: 0;
top: 0;
bottom: 0;
}
</style>
3 changes: 3 additions & 0 deletions bootstrap-languages/centralized-agent-language/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# centrazlied-agent-language

A ad4m language to store Agent data associated with DID's in a centralized server
61 changes: 61 additions & 0 deletions bootstrap-languages/centralized-agent-language/adapter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import type { Address, Agent, Expression, PublicSharing, LanguageContext, HolochainLanguageDelegate, ExpressionAdapter, AgentService } from "https://esm.sh/@perspect3vism/ad4m@0.5.0";
import axiod from "https://deno.land/x/axiod/mod.ts";

export default class ExpressionAdapterImpl implements ExpressionAdapter {
#agent: AgentService;
putAdapter: PublicSharing

constructor(context: LanguageContext) {
this.#agent = context.agent;
this.putAdapter = new Sharing(context)
}

async get(did: Address): Promise<Expression> {
console.log("Getting expression with did", did);

const data = await axiod.get("https://socket.ad4m.dev/agent", {
params: {
did
}
});

return data.data.expression
};
}

class Sharing implements PublicSharing {
#agent: AgentService;

constructor(context: LanguageContext) {
this.#agent = context.agent;
}

async createPublic(content: Agent): Promise<Address> {

if(!content['did'] || !content['perspective'] || !content['perspective'].links)
throw "Content must be an Agent object"

const agent = content as Agent
if(agent.did != this.#agent.did)
throw "Can't set Agent Expression for foreign DID - only for self"

if(!agent.directMessageLanguage)
agent.directMessageLanguage = undefined

agent.perspective!.links.forEach(link => {
delete link.proof.valid
delete link.proof.invalid
})

const expression = this.#agent.createSignedExpression(agent);

await axiod.post("https://socket.ad4m.dev/agent", {
data: {
did: agent.did,
expression
}
});

return agent.did
}
}
22 changes: 22 additions & 0 deletions bootstrap-languages/centralized-agent-language/esbuild.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import * as esbuild from "https://deno.land/x/esbuild@v0.17.18/mod.js";
// Import the WASM build on platforms where running subprocesses is not
// permitted, such as Deno Deploy, or when running without `--allow-run`.
// import * as esbuild from "https://deno.land/x/esbuild@v0.17.18/wasm.js";

import { denoPlugins } from "https://deno.land/x/esbuild_deno_loader@0.7.0/mod.ts";

const result = await esbuild.build({
plugins: [...denoPlugins()],
entryPoints: ['index.ts'],
outfile: 'build/bundle.js',
bundle: true,
platform: 'node',
target: 'deno1.32.4',
format: 'esm',
globalName: 'centralized.agent.language',
charset: 'ascii',
legalComments: 'inline'
});
console.log(result.outputFiles);

esbuild.stop();
13 changes: 13 additions & 0 deletions bootstrap-languages/centralized-agent-language/expressionUI.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import type { ExpressionUI } from "@perspect3vism/ad4m";
import Icon from './build/Icon.js'
import ConstructorIcon from './build/ConstructorIcon.js'

export class UI implements ExpressionUI {
icon(): string {
return Icon
}

constructorIcon(): string {
return ConstructorIcon
}
}
34 changes: 34 additions & 0 deletions bootstrap-languages/centralized-agent-language/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import type { Address, Language, LanguageContext, HolochainLanguageDelegate, Interaction } from "https://esm.sh/@perspect3vism/ad4m@0.5.0";
import ExpressionAdapter from "./adapter.ts";
import Icon from "./build/Icon.js";
import ConstructorIcon from "./build/ConstructorIcon.js";
import { UI } from "./build/expressionUI.js";

function iconFor(expression: Address): string {
return Icon as unknown as string;
}

function constructorIcon(): string {
return ConstructorIcon as unknown as string;
}

function interactions(expression: Address): Interaction[] {
return [];
}

//!@ad4m-template-variable
export const name = "centralized-agent-expression-store";

export default async function create(context: LanguageContext): Promise<Language> {
const expressionAdapter = new ExpressionAdapter(context);
const expressionUI = new UI();

return {
name,
expressionAdapter,
iconFor,
constructorIcon,
interactions,
expressionUI,
} as Language;
}
45 changes: 45 additions & 0 deletions bootstrap-languages/centralized-agent-language/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"name": "@perspect3vism/centralized-agent-language",
"version": "0.7.1",
"description": "AD4M Language implementation for Holochain profile DNA",
"main": "index.js",
"scripts": {
"test-disabled": "echo \"No agent language integration tests\"",
"rollup-icons": "rollup -c rollup.config.icons.js",
"rollup-expression-ui": "rollup -c rollup.config.expression-ui.js",
"build": "run-script-os",
"build:linux": "pnpm run build:common",
"build:macos": "pnpm run build:common",
"build:windows": "pnpm run build:common",
"build:common": "pnpm run rollup-icons && pnpm run rollup-expression-ui && deno run --allow-all esbuild.ts"
},
"author": "",
"license": "ISC",
"devDependencies": {
"@perspect3vism/ad4m": "*",
"@perspect3vism/rollup-plugin-dna": "^0.0.2",
"@rollup/plugin-commonjs": "^17.0.0",
"@rollup/plugin-json": "^4.1.0",
"@rollup/plugin-node-resolve": "^8.0.0",
"@rollup/plugin-typescript": "^11.1.0",
"@tsconfig/svelte": "^1.0.0",
"@types/node": "^18.0.0",
"rollup": "^2.3.4",
"rollup-plugin-postcss": "^4.0.0",
"rollup-plugin-string": "^3.0.0",
"rollup-plugin-svelte": "^6.0.0",
"rollup-plugin-terser": "^7.0.0",
"run-script-os": "^1.1.6",
"svelte": "^3.0.0",
"svelte-check": "^1.0.0",
"svelte-preprocess": "^4.0.0",
"tslib": "^2.0.0",
"typescript": "^4.2.4",
"xmlhttprequest": "^1.8.0"
},
"dependencies": {
"email-validator": "^2.0.4",
"md5": "^2.3.0",
"postcss": "^8.2.1"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { string } from "rollup-plugin-string";
import typescript from '@rollup/plugin-typescript';

export default {
input: "expressionUI.ts",
external: [],
output: {
sourcemap: true,
format: "esm",
name: "AgentExpressionUI",
file: "build/expressionUI.js",
interop: "esModule",
globals: {},
},
external: [],
plugins: [
string({
include: "build/*.js",
}),
typescript({include: "expressionUI.ts"}),
],
watch: {
clearScreen: false,
},
};
Loading
Loading