Skip to content

Commit

Permalink
refactor(daemon,cli): A handle for every agent
Browse files Browse the repository at this point in the history
  • Loading branch information
kriskowal committed Mar 27, 2024
1 parent 3eff657 commit 2d604a1
Show file tree
Hide file tree
Showing 12 changed files with 308 additions and 159 deletions.
12 changes: 8 additions & 4 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
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 2d604a1

Please sign in to comment.