Skip to content

Commit

Permalink
feat(daemon,cli): One handle for every agent (merge endojs#2184)
Browse files Browse the repository at this point in the history
  • Loading branch information
kriskowal committed Apr 9, 2024
2 parents f95bcee + 5ed0d66 commit 983900d
Show file tree
Hide file tree
Showing 12 changed files with 326 additions and 177 deletions.
38 changes: 21 additions & 17 deletions packages/cli/demo/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,15 @@ through which it obtains all of its authority.
In this example, the doubler requests another counter from the user.

We make a doubler mostly the same way we made the counter.
However, we must give a name to the agent running the doubler, which we will
later use to recognize requests coming from the doubler.
However, we must create a guest profile for the doubler.
The guest has two facets: its handle and its agent powers.
The handle appears in the "to" and "from" fields of messages exchanged with the
guest and provides no other capabilities.
The agent is a permission management broker that the doubler
can use to request other capabilities, like the counter.

```
> endo mkguest doubler-agent
> endo mkguest doubler-handle doubler-agent
> endo make doubler.js --name doubler --powers doubler-agent
```

Expand All @@ -149,7 +153,7 @@ resolve its request for a counter.

```
> endo inbox
0. "doubler-agent" requested "please give me a counter"
0. "doubler-handle" requested "please give me a counter"
> endo resolve 0 counter
```

Expand Down Expand Up @@ -197,14 +201,14 @@ Then, assuming the guise of "alice", we find the message in our inbox
and adopt the "doubler" object into our own store.

```
> endo mkguest alice
> endo mkguest alice alice-agent
> endo send alice 'Please enjoy this @doubler.'
> endo inbox --as alice
> endo inbox --as alice-agent
0. "HOST" sent "Please enjoy this @doubler."
> endo adopt --as alice 0 doubler
> endo list --as alice
> endo adopt --as alice-agent 0 doubler
> endo list --as alice-agent
doubler
> endo dismiss --as alice 0
> endo dismiss --as alice-agent 0
```

# Names in transit are no-one's names
Expand All @@ -223,12 +227,12 @@ Then, alice adopts "counter", giving it their own name, "redoubler".

```
> endo send alice 'Please enjoy this @counter:doubler.'
> endo inbox --as alice
> endo inbox --as alice-agent
1. "HOST" sent "Please enjoy this @counter."
> endo adopt --as alice 1 counter --name redoubler
> endo list --as alice
> endo adopt --as alice-agent 1 counter --name redoubler
> endo list --as alice-agent
redoubler
> endo dismiss --as alice 1
> endo dismiss --as alice-agent 1
```

# Mailboxes are symmetric
Expand All @@ -237,7 +241,7 @@ Guests can also send their host messages.
In this example, "alice" send the doubler back to us, their host.

```
> endo send HOST --as alice 'This is the @doubler you sent me.'
> endo send HOST --as alice-agent 'This is the @doubler you sent me.'
> endo inbox
0. "alice" sent "This is the @doubler you sent me."
> endo adopt 0 doubler doubler-from-alice
Expand Down Expand Up @@ -267,7 +271,7 @@ _Familiar Chat_ is an example application that provides a web app for
interacting with your pet daemon.

```
> endo install cat.js --listen 8920 --powers SELF --name familiar-chat
> endo install cat.js --listen 8920 --powers AGENT --name familiar-chat
```

This command creates a web page named familiar-chat and endows it with the
Expand All @@ -281,8 +285,8 @@ You can then open that page.
So, if you were to simulate a request from your cat:

```
> endo mkguest cat
> endo request 'pet me' --as cat
> endo mkguest cat cat-agent
> endo request HOST 'pet me' --as cat-agent
```

This will appear in your Familiar Chat web page, where you can resolve
Expand Down
12 changes: 10 additions & 2 deletions packages/cli/src/commands/mkguest.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,16 @@ import os from 'os';
import { E } from '@endo/far';
import { withEndoAgent } from '../context.js';

export const mkguest = async ({ name, agentNames, introducedNames }) =>
export const mkguest = async ({
handleName,
agentName,
agentNames,
introducedNames,
}) =>
withEndoAgent(agentNames, { os, process }, async ({ agent }) => {
const newGuest = await E(agent).provideGuest(name, { introducedNames });
const newGuest = await E(agent).provideGuest(handleName, {
introducedNames,
agentName,
});
console.log(newGuest);
});
12 changes: 10 additions & 2 deletions packages/cli/src/commands/mkhost.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,16 @@ import os from 'os';
import { E } from '@endo/far';
import { withEndoAgent } from '../context.js';

export const mkhost = async ({ name, agentNames, introducedNames }) =>
export const mkhost = async ({
handleName,
agentName,
agentNames,
introducedNames,
}) =>
withEndoAgent(agentNames, { os, process }, async ({ agent }) => {
const newHost = await E(agent).provideHost(name, { introducedNames });
const newHost = await E(agent).provideHost(handleName, {
introducedNames,
agentName,
});
console.log(newHost);
});
12 changes: 6 additions & 6 deletions packages/cli/src/endo.js
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ export const main = async rawArgs => {
});

program
.command('mkhost <name>')
.command('mkhost <handle-name> [agent-name]')
.option(...commonOptions.as)
.option(
'--introduce <name>',
Expand All @@ -424,14 +424,14 @@ export const main = async rawArgs => {
{},
)
.description('makes a separate mailbox and storage for you')
.action(async (name, cmd) => {
.action(async (handleName, agentName, cmd) => {
const { as: agentNames, introduce: introducedNames } = cmd.opts();
const { mkhost } = await import('./commands/mkhost.js');
return mkhost({ name, agentNames, introducedNames });
return mkhost({ handleName, agentName, agentNames, introducedNames });
});

program
.command('mkguest <name>')
.command('mkguest <handle-name> [agent-name]')
.option(...commonOptions.as)
.option(
'--introduce <name>',
Expand All @@ -440,10 +440,10 @@ export const main = async rawArgs => {
{},
)
.description('makes a mailbox and storage for a guest (peer or program)')
.action(async (name, cmd) => {
.action(async (handleName, agentName, cmd) => {
const { as: agentNames, introduce: introducedNames } = cmd.opts();
const { mkguest } = await import('./commands/mkguest.js');
return mkguest({ name, agentNames, introducedNames });
return mkguest({ agentName, handleName, agentNames, introducedNames });
});

program
Expand Down
Loading

0 comments on commit 983900d

Please sign in to comment.