-
Notifications
You must be signed in to change notification settings - Fork 12
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
WIP: AD4M integration #3
Draft
lucksus
wants to merge
22
commits into
main
Choose a base branch
from
ad4m
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 21 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
5110902
Persist profile in AD4M's public agent perspective
lucksus 31608a5
Merge branch 'main' into ad4m
lucksus c00a802
Boilerplate ad4m language wired-up to clutter DNA
lucksus 0f60e4c
gitignore
lucksus b5f3e74
Merge branch 'main' into ad4m
lucksus 41ce213
Compiling Mew components for ad4m language icons
lucksus 09fc569
Merge branch 'main' into ad4m
lucksus b0a3f91
Merge branch 'main' into ad4m
lucksus 933bb00
WIP: Clutter AD4M Language integration
lucksus 724378a
route to ad4m profile page for test
weswalla 3e0ae42
Merge branch 'mew-interaction-feature' into ad4m
weswalla b2a8d18
use ad4m mew language when creating mews and viewing mews feed
weswalla dcbd544
initial icon and added script to visually test icon
weswalla df6f49b
WIP: basic mew icon (still needs to interact with ad4m
weswalla d76935c
Merge branch 'mew-interaction-feature' into ad4m
weswalla 51cdc66
mew expression icon complete and works in perspect3ve
weswalla e11b178
use entry header data for ad4m expression author and timestamp
weswalla c1bff41
add agent key and timestamp from mew header to ad4m expression metadata
weswalla e496aae
added interaction for licking mew
weswalla 7284da8
use interaction in icon for licking mew, added unlick mew interaction
weswalla d684453
added basic follow feature (by DID) and show mews of following
weswalla b3a292d
bumped clutter dna to hdk 0.0.123
weswalla File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
*.js | ||
*.js.map | ||
node_modules | ||
build | ||
dist-mew | ||
dist-mew-constructor | ||
!main.js | ||
!rollup.config.icons.dev.js | ||
!rollup.config.icons.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<svelte:options tag={null}/> | ||
|
||
<script lang="ts"> | ||
export let commitExpression | ||
export let mewType | ||
export let discard | ||
|
||
let text = "" | ||
if (!mewType) { | ||
mewType = { | ||
original: null | ||
} | ||
} | ||
function createMewInput(text) { | ||
let createMewInput = { | ||
mewType: mewType, | ||
mew: text | ||
} | ||
return createMewInput | ||
} | ||
|
||
</script> | ||
|
||
<div class="container"> | ||
<input bind:value={text}> | ||
<button on:click={()=>commitExpression(createMewInput(text))}>Publish Mew</button> | ||
<button on:click={discard}>Discard</button> | ||
</div> | ||
|
||
|
||
<style> | ||
.container { | ||
color: burlywood; | ||
width: 400px; | ||
height: 300px; | ||
} | ||
|
||
input { | ||
width: 100%; | ||
height: 200px; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
<svelte:options tag={null}/> | ||
|
||
<script lang="ts"> | ||
import type Expression from "@perspect3vism/ad4m/Expression"; | ||
import type ExpressionClient from "@perspect3vism/ad4m/ExpressionClient"; | ||
import { InteractionCall } from "@perspect3vism/ad4m" | ||
|
||
export let expression: Expression | ||
export let createExpression | ||
export let expressionClient: ExpressionClient | ||
let feedMewWithContext | ||
$: if(expression && expression.data) { | ||
console.log('expression from icon:', expression) | ||
feedMewWithContext = JSON.parse(expression.data) | ||
} | ||
|
||
let text = "" | ||
let isReplying = false | ||
let isMewMewing = false | ||
async function togglelickMew() { | ||
console.log(feedMewWithContext.mewEntryHash) | ||
const interactionCall = new InteractionCall('lick-mew', { entryHash: feedMewWithContext.mewEntryHash }) | ||
const exprAddr = `${expression.language.address}://${feedMewWithContext.mewEntryHash}` | ||
await expressionClient.interact(exprAddr, interactionCall) | ||
// TODO: first check if agent key is in the list of liked mews, then lick or unlick accordingly | ||
} | ||
function replyToMew() { | ||
if (isMewMewing) { | ||
isMewMewing = !isMewMewing | ||
} | ||
isReplying = !isReplying | ||
} | ||
function shareMew() { | ||
const createMewInput = { | ||
mewType: { | ||
reMew: feedMewWithContext.mewEntryHash | ||
}, | ||
mew: null | ||
} | ||
createExpression(createMewInput) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this could also get replaced with |
||
} | ||
function mewMew() { | ||
if (isReplying) { | ||
isReplying = !isReplying | ||
} | ||
isMewMewing = !isMewMewing | ||
} | ||
function createMewInput(text) { | ||
let mewType = isReplying ? { reply: feedMewWithContext.mewEntryHash } : { mewMew: feedMewWithContext.mewEntryHash } | ||
let createMewInput = { | ||
mewType: mewType, | ||
mew: text | ||
} | ||
return createMewInput | ||
} | ||
</script> | ||
|
||
<div class="container"> | ||
{#if expression} | ||
<div class="avatar-box"></div> | ||
<div class="mew-meta"> | ||
{expression.author} {expression.timestamp} | ||
</div> | ||
<div class="mew-content"> | ||
<p>{feedMewWithContext.feedMew.mew.mew.mew}</p> | ||
</div> | ||
<div class="mew-interactions"> | ||
<button on:click={async () => togglelickMew()}>lick ({feedMewWithContext.licks.length})</button> | ||
<button on:click={() => replyToMew()}>reply ({feedMewWithContext.comments.length})</button> | ||
<button on:click={() => shareMew()}>share ({feedMewWithContext.shares.length})</button> | ||
<button on:click={() => mewMew()}>mewmew ({feedMewWithContext.shares.length})</button> | ||
</div> | ||
{#if isReplying} | ||
<input bind:value={text}> | ||
<button on:click={()=>createExpression(createMewInput(text))}>Publish Mew</button> | ||
{:else if isMewMewing} | ||
<input bind:value={text}> | ||
<button on:click={()=>createExpression(createMewInput(text))}>Publish Mew</button> | ||
{/if} | ||
{/if} | ||
</div> | ||
|
||
|
||
<style> | ||
.container { | ||
width: 400px; | ||
height: 300px; | ||
background-color: lightblue; | ||
} | ||
.avatar-box { | ||
width: 50px; | ||
height: 50px; | ||
border-radius: 50px; | ||
background: blue; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import type { Address, Agent, Expression, PublicSharing, LanguageContext, HolochainLanguageDelegate, ExpressionAdapter, AgentService, Interaction } from "@perspect3vism/ad4m"; | ||
import { DNA_NICK } from "./dna"; | ||
import { serializeHash } from "@holochain-open-dev/core-types"; | ||
import { Base64 } from 'js-base64'; | ||
|
||
export default class ExpressionAdapterImpl implements ExpressionAdapter { | ||
#DNA: HolochainLanguageDelegate; | ||
#agent: AgentService; | ||
putAdapter: PublicSharing | ||
|
||
constructor(context: LanguageContext) { | ||
this.#DNA = context.Holochain as HolochainLanguageDelegate; | ||
this.#agent = context.agent; | ||
this.putAdapter = new Sharing(context) | ||
} | ||
|
||
async get(mewAddress: Address): Promise<Expression> { | ||
const fullMewWithContext = await this.#DNA.call( | ||
DNA_NICK, | ||
"mews", | ||
"get_feed_mew_and_context", | ||
mewAddress | ||
); | ||
const author = serializeHash(new Uint8Array(fullMewWithContext.feedMew.header.author.data)) | ||
const timestamp = fullMewWithContext.feedMew.header.timestamp | ||
return { | ||
author: author, | ||
timestamp: timestamp, | ||
data: fullMewWithContext, | ||
proof: { | ||
key: 'none', | ||
signature: 'none' | ||
} | ||
} | ||
}; | ||
|
||
async interactions(expressionAddress: Address): Promise<Interaction[]> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this the right idea @lucksus |
||
return [{ | ||
label: 'lick a mew', | ||
name: 'lick-mew', | ||
parameters: [['entryHash','object']], | ||
execute: async (parameters: object) => { | ||
const mewAddress = parameters['entryHash'] | ||
await this.#DNA.call( | ||
DNA_NICK, | ||
"mews", | ||
"lick_mew", | ||
mewAddress | ||
) | ||
} | ||
}, | ||
{ | ||
label: 'unlick a mew', | ||
name: 'unlick-mew', | ||
parameters: [['entryHash','object']], | ||
execute: async (parameters: object) => { | ||
const mewAddress = parameters['entryHash'] | ||
await this.#DNA.call( | ||
DNA_NICK, | ||
"mews", | ||
"unlick_mew", | ||
mewAddress | ||
) | ||
} | ||
}] | ||
} | ||
} | ||
|
||
class Sharing implements PublicSharing { | ||
#DNA: HolochainLanguageDelegate; | ||
#agent: AgentService; | ||
|
||
constructor(context: LanguageContext) { | ||
this.#DNA = context.Holochain as HolochainLanguageDelegate; | ||
this.#agent = context.agent; | ||
} | ||
|
||
async createPublic(mewObject: object): Promise<Address> { | ||
const address = await this.#DNA.call( | ||
DNA_NICK, | ||
"mews", | ||
"create_mew", | ||
mewObject | ||
); | ||
|
||
return address | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import dna from "../dnas/clutter/workdir/clutter.dna"; | ||
|
||
export const DNA = Buffer.from(dna, "base64"); | ||
export const DNA_NICK = "clutter"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>My Svelte App</title> | ||
<script defer src="build/icon-bundle.js"></script> | ||
</head> | ||
<body></body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import type { Address, Agent, Language, LanguageContext, HolochainLanguageDelegate, Interaction } from "@perspect3vism/ad4m"; | ||
import ExpressionAdapter from "./adapter"; | ||
|
||
import { UI } from "./expressionUI"; | ||
import { DNA, DNA_NICK } from "./dna"; | ||
|
||
|
||
|
||
function interactions(expression: Address): Interaction[] { | ||
return []; | ||
} | ||
|
||
export const name = "clutter"; | ||
|
||
export default async function create(context: LanguageContext): Promise<Language> { | ||
const Holochain = context.Holochain as HolochainLanguageDelegate; | ||
await Holochain.registerDNAs([{ file: DNA, nick: DNA_NICK }]); | ||
|
||
const expressionAdapter = new ExpressionAdapter(context); | ||
const expressionUI = new UI(); | ||
|
||
return { | ||
name, | ||
expressionAdapter, | ||
interactions, | ||
expressionUI, | ||
} as Language; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import App from './Icon.svelte'; | ||
|
||
const expression = { | ||
author: 'unknown', | ||
timestamp: 'unknown', | ||
data: '{"feedMew":{"mew":{"mewType":{"original":null},"mew":{"mew":"creating a mew!"}},"header":{"type":"Create","author":{"type":"Buffer","data":[132,32,36,186,86,176,212,167,6,145,108,225,172,236,229,46,72,224,134,148,218,129,184,207,70,245,63,201,156,56,148,167,21,134,59,226,20,60,70]},"timestamp":1645074844495627,"header_seq":5,"prev_header":{"type":"Buffer","data":[132,41,36,235,154,154,117,54,170,234,91,126,69,140,99,147,170,115,238,38,123,240,254,76,113,233,53,148,148,150,27,128,199,247,194,230,243,127,204]},"entry_type":{"App":{"id":2,"zome_id":1,"visibility":{"Public":null}}},"entry_hash":{"type":"Buffer","data":[132,33,36,116,50,17,86,115,69,106,23,117,208,110,61,50,111,49,35,64,147,83,148,74,241,30,61,230,188,103,37,224,29,196,36,127,138,174,48]}}},"mewEntryHash":"uhCEkdDIRVnNFahd10G49Mm8xI0CTU5RK8R495rxnJeAdxCR_iq4w","comments":[],"shares":[],"licks":[]}', | ||
language: { address: 'QmcWWYnz494S2yucuZb3f1TczqfuAWjvNgRC3wZkB3mPqW' }, | ||
proof: { valid: null, invalid: true } | ||
} | ||
const app = new App({ | ||
target: document.body, | ||
props: { | ||
expression: expression, | ||
}, | ||
}); | ||
|
||
export default app; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how does this look @lucksus ?