@amalgm/agents 0.2.1 → 0.2.3-main.34175696578
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.
- package/PURPOSE.md +45 -24
- package/README.md +48 -47
- package/dist/agents.d.ts +4 -26
- package/dist/agents.js +4 -87
- package/dist/bin/mcp.js +1 -1
- package/dist/cli/help.d.ts +1 -1
- package/dist/cli/help.js +2 -13
- package/dist/cli/open.d.ts +1 -1
- package/dist/cli/open.js +1 -5
- package/dist/cli/run.js +3 -8
- package/dist/errors.d.ts +1 -1
- package/dist/errors.js +0 -2
- package/dist/http/server.js +1 -7
- package/dist/index.d.ts +0 -2
- package/dist/index.js +0 -2
- package/dist/mcp/agent-tools.js +1 -1
- package/dist/mcp/tools.js +1 -2
- package/dist/rows.d.ts +1 -4
- package/dist/rows.js +0 -39
- package/dist/schema.js +53 -101
- package/dist/types.d.ts +0 -106
- package/docs/ARCHITECTURE.md +21 -33
- package/docs/CLI.md +3 -43
- package/docs/DATA_MODEL.md +7 -46
- package/docs/DEFINITIONS.md +4 -4
- package/docs/ENGINE_INTEGRATION.md +9 -71
- package/docs/MCP.md +3 -19
- package/docs/REST.md +14 -97
- package/docs/SDK.md +12 -61
- package/docs/SECURITY.md +6 -35
- package/docs/SHELL_INTEGRATION.md +29 -0
- package/examples/basic.ts +8 -22
- package/package.json +39 -4
- package/skills/amalgm-agents/SKILL.md +231 -20
- package/skills/amalgm-agents/agents/openai.yaml +2 -2
- package/dist/cli/session-commands.d.ts +0 -4
- package/dist/cli/session-commands.js +0 -54
- package/dist/drivers.d.ts +0 -4
- package/dist/drivers.js +0 -25
- package/dist/event-store.d.ts +0 -13
- package/dist/event-store.js +0 -50
- package/dist/http/session-routes.d.ts +0 -2
- package/dist/http/session-routes.js +0 -67
- package/dist/http/stream.d.ts +0 -3
- package/dist/http/stream.js +0 -30
- package/dist/mcp/session-tools.d.ts +0 -3
- package/dist/mcp/session-tools.js +0 -81
- package/dist/messages.d.ts +0 -3
- package/dist/messages.js +0 -56
- package/dist/runtime.d.ts +0 -29
- package/dist/runtime.js +0 -176
- package/dist/session-store.d.ts +0 -15
- package/dist/session-store.js +0 -83
- package/dist/turn-store.d.ts +0 -31
- package/dist/turn-store.js +0 -164
- package/docs/DRIVERS.md +0 -72
package/PURPOSE.md
CHANGED
|
@@ -2,15 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
## Purpose
|
|
4
4
|
|
|
5
|
-
Amalgm Agents is the small, standalone
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
execution to an injected driver; it does not duplicate their state.
|
|
5
|
+
Amalgm Agents is the small, standalone registry for agent identities,
|
|
6
|
+
installations, and immutable revisions. A user or another agent can create,
|
|
7
|
+
register, install, list, inspect, edit, and delete an available agent, then
|
|
8
|
+
resolve one exact revision for execution by Chat.
|
|
9
|
+
|
|
10
|
+
Shell composes Agents with Chat, harnesses, credentials, Toolbox, files, Live,
|
|
11
|
+
and UI. This package stores references to those products; it does not duplicate
|
|
12
|
+
their state or execute a conversation.
|
|
14
13
|
It also discovers installed agent skills across the canonical project and
|
|
15
14
|
harness roots so every transport presents the same available skill catalog.
|
|
16
15
|
Rich harness configuration is stored inside the same immutable definition and
|
|
@@ -21,25 +20,45 @@ hosts supply explicit ports for resources owned by other products.
|
|
|
21
20
|
## Primitives
|
|
22
21
|
|
|
23
22
|
- An **agent** is a stable identity with a complete current definition.
|
|
24
|
-
-
|
|
25
|
-
|
|
26
|
-
- A **
|
|
23
|
+
- An **installation** is one locally available agent identity and its Agent
|
|
24
|
+
Home descriptor.
|
|
25
|
+
- A **resolved agent** is one exact immutable revision selected for execution.
|
|
27
26
|
- The **Agents service** is the behavior shared by every public surface.
|
|
28
27
|
|
|
29
28
|
## Axioms
|
|
30
29
|
|
|
30
|
+
Consumer assembly derives exact same-branch dependency pins from the declared
|
|
31
|
+
package manifests and registry candidate records. One pending composition per
|
|
32
|
+
branch preserves human edits; complete consumer checks for the exact merge tree govern its
|
|
33
|
+
merge, and publication never implies installed adoption.
|
|
34
|
+
|
|
35
|
+
Managed package delivery starts from a clean, exact main or preview source
|
|
36
|
+
commit. The workflow occurrence supplies only its generated version and source
|
|
37
|
+
record; tests run against those candidate inputs before packing. Every native
|
|
38
|
+
gate and publication use that same tarball and integrity. A candidate tag makes
|
|
39
|
+
bytes available to release assembly; it never promotes an installed runtime.
|
|
40
|
+
Release tooling remains available inside each owner repository so a developer
|
|
41
|
+
or CI job never needs access to another private product repository.
|
|
42
|
+
Registry credentials are available only to the final protected publication job,
|
|
43
|
+
after every native examination proves the exact candidate bytes.
|
|
44
|
+
Native consumers install the archive as a dependency, so SDK development
|
|
45
|
+
dependencies never become an end-user installation requirement.
|
|
46
|
+
The repository token creates only its own dependency proposals and explicitly
|
|
47
|
+
dispatches checks and delivery; every admitted gate proves the actual checkout,
|
|
48
|
+
including the exact two-parent merge commit that becomes managed source.
|
|
49
|
+
|
|
31
50
|
Managed releases bind to one exact published Core version and build from the
|
|
32
51
|
locked dependency graph on the supported Node toolchain.
|
|
33
52
|
|
|
34
53
|
1. A user can create, list, inspect, edit, and delete agents.
|
|
35
|
-
2. A user or another agent can
|
|
36
|
-
|
|
54
|
+
2. A user or another agent can resolve an available agent to one exact
|
|
55
|
+
immutable revision without starting a conversation.
|
|
37
56
|
3. An agent definition can reference its harness, model, instructions, tools,
|
|
38
57
|
skills, files, credentials, and subagents without Agents owning those
|
|
39
58
|
products.
|
|
40
|
-
4.
|
|
41
|
-
|
|
42
|
-
|
|
59
|
+
4. Harness identity is part of an agent revision; provider execution belongs
|
|
60
|
+
to Chat behind a host runtime port.
|
|
61
|
+
5. Agent definitions, installations, and revisions survive restart.
|
|
43
62
|
6. SDK, CLI, REST, MCP, and skill workflows expose the same Agents behavior;
|
|
44
63
|
none is a second implementation.
|
|
45
64
|
7. An unchanged current definition is idempotent; every actual change creates
|
|
@@ -51,10 +70,12 @@ locked dependency graph on the supported Node toolchain.
|
|
|
51
70
|
|
|
52
71
|
## Consequences
|
|
53
72
|
|
|
54
|
-
The package needs no
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
never imports their stores or duplicates their lifecycle
|
|
59
|
-
|
|
60
|
-
|
|
73
|
+
The package needs no conversation, turn, transcript, stream, reconnect,
|
|
74
|
+
interrupt, cloud command inbox, scheduler, trigger relay, or general
|
|
75
|
+
event-routing system. Shell and other hosts resolve Agents revisions while
|
|
76
|
+
preparing a Chat execution. Bundle ports call Apps, Automations, and Toolbox
|
|
77
|
+
public APIs; Agents never imports their stores or duplicates their lifecycle
|
|
78
|
+
behavior.
|
|
79
|
+
|
|
80
|
+
There is no execution subsystem in Agents. Chat is the single owner of every
|
|
81
|
+
conversation and turn.
|
package/README.md
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
# Amalgm Agents
|
|
2
2
|
|
|
3
3
|
`@amalgm/agents` is a local-first TypeScript SDK for persistent agent
|
|
4
|
-
|
|
5
|
-
REST API, and MCP server.
|
|
4
|
+
identities, installations, and immutable revisions. The same registry powers
|
|
5
|
+
its CLI, REST API, and MCP server.
|
|
6
6
|
|
|
7
|
-
It is intentionally not Chat.
|
|
8
|
-
owns the
|
|
9
|
-
|
|
7
|
+
It is intentionally not Chat. Agents resolves the exact installed revision;
|
|
8
|
+
`@amalgm/chat` owns the durable conversation, turns, stream, reconnect, and
|
|
9
|
+
interrupt lifecycle that executes it.
|
|
10
10
|
|
|
11
11
|
## Install
|
|
12
12
|
|
|
@@ -19,25 +19,9 @@ Node 20 or newer is required.
|
|
|
19
19
|
## First agent
|
|
20
20
|
|
|
21
21
|
```ts
|
|
22
|
-
import { Agents
|
|
23
|
-
|
|
24
|
-
const echo = defineDriver({
|
|
25
|
-
id: 'echo',
|
|
26
|
-
async run(request) {
|
|
27
|
-
const text = request.input.parts
|
|
28
|
-
.filter((part) => part.type === 'text')
|
|
29
|
-
.map((part) => part.text)
|
|
30
|
-
.join('');
|
|
31
|
-
return {
|
|
32
|
-
message: {
|
|
33
|
-
role: 'assistant',
|
|
34
|
-
parts: [{ type: 'text', text: `Received: ${text}` }],
|
|
35
|
-
},
|
|
36
|
-
};
|
|
37
|
-
},
|
|
38
|
-
});
|
|
22
|
+
import { Agents } from '@amalgm/agents';
|
|
39
23
|
|
|
40
|
-
const agents = new Agents({ stateDir: './state'
|
|
24
|
+
const agents = new Agents({ stateDir: './state' });
|
|
41
25
|
|
|
42
26
|
agents.createAgent({
|
|
43
27
|
id: 'reviewer',
|
|
@@ -47,28 +31,22 @@ agents.createAgent({
|
|
|
47
31
|
toolbox: { toolIds: ['git'], actionIds: ['git.diff'] },
|
|
48
32
|
});
|
|
49
33
|
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
idempotencyKey: 'review-001',
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
console.log(turn.status);
|
|
57
|
-
console.log(agents.listEvents(session.id));
|
|
58
|
-
await agents.close();
|
|
34
|
+
const revision = agents.getAgentRevision('reviewer');
|
|
35
|
+
console.log(revision.id, revision.definition.driver.id);
|
|
36
|
+
agents.close();
|
|
59
37
|
```
|
|
60
38
|
|
|
61
|
-
An agent definition is normalized into a complete immutable revision.
|
|
62
|
-
|
|
39
|
+
An agent definition is normalized into a complete immutable revision. Chat
|
|
40
|
+
records the resolved revision id in every prepared execution.
|
|
63
41
|
|
|
64
42
|
## Product surfaces
|
|
65
43
|
|
|
66
44
|
| Surface | Entry point | Purpose |
|
|
67
45
|
|---|---|---|
|
|
68
|
-
| SDK | `@amalgm/agents` | Embed the canonical
|
|
69
|
-
| CLI | `amalgm-agents` | Manage
|
|
70
|
-
| REST | `@amalgm/agents/http`, `amalgm-agents-rest` | Local
|
|
71
|
-
| MCP | `@amalgm/agents/mcp`, `amalgm-agents-mcp` | Agent
|
|
46
|
+
| SDK | `@amalgm/agents` | Embed the canonical registry and resolve revisions |
|
|
47
|
+
| CLI | `amalgm-agents` | Manage agent identities and installations |
|
|
48
|
+
| REST | `@amalgm/agents/http`, `amalgm-agents-rest` | Local registry integration |
|
|
49
|
+
| MCP | `@amalgm/agents/mcp`, `amalgm-agents-mcp` | Agent registry tools |
|
|
72
50
|
| Skill | `skills/amalgm-agents` | Minimal workflow over the Agents tools |
|
|
73
51
|
|
|
74
52
|
Installed skills are available from the REST surface without introducing a
|
|
@@ -122,13 +100,9 @@ explicitly; dependencies are never omitted to make a bundle look portable.
|
|
|
122
100
|
```bash
|
|
123
101
|
amalgm-agents agent create ./agent.json
|
|
124
102
|
amalgm-agents agent list
|
|
125
|
-
amalgm-agents session start reviewer
|
|
126
|
-
amalgm-agents session send <session-id> "Review the diff"
|
|
127
|
-
amalgm-agents talk reviewer "Review the diff"
|
|
128
103
|
```
|
|
129
104
|
|
|
130
|
-
The CLI reads the same SQLite
|
|
131
|
-
with `--drivers ./dist/codex-driver.js` or `AMALGM_AGENT_DRIVERS`.
|
|
105
|
+
The CLI reads the same SQLite registry as the SDK.
|
|
132
106
|
|
|
133
107
|
## Documentation
|
|
134
108
|
|
|
@@ -136,13 +110,13 @@ with `--drivers ./dist/codex-driver.js` or `AMALGM_AGENT_DRIVERS`.
|
|
|
136
110
|
- [Architecture and boundaries](./docs/ARCHITECTURE.md)
|
|
137
111
|
- [Agent definitions](./docs/DEFINITIONS.md)
|
|
138
112
|
- [SDK reference](./docs/SDK.md)
|
|
139
|
-
- [Driver contract](./docs/DRIVERS.md)
|
|
140
113
|
- [CLI reference](./docs/CLI.md)
|
|
141
114
|
- [REST API](./docs/REST.md)
|
|
142
115
|
- [MCP server](./docs/MCP.md)
|
|
143
|
-
- [Persistence
|
|
116
|
+
- [Persistence](./docs/DATA_MODEL.md)
|
|
144
117
|
- [Security model](./docs/SECURITY.md)
|
|
145
|
-
- [
|
|
118
|
+
- [Shell integration](./docs/SHELL_INTEGRATION.md)
|
|
119
|
+
- [Historical Engine integration](./docs/ENGINE_INTEGRATION.md)
|
|
146
120
|
|
|
147
121
|
## Development
|
|
148
122
|
|
|
@@ -153,4 +127,31 @@ npm run verify
|
|
|
153
127
|
|
|
154
128
|
`verify` runs strict typechecking for source, tests, and examples; enforces the
|
|
155
129
|
220-line source-file limit; builds JavaScript and declarations; and runs the
|
|
156
|
-
real SQLite,
|
|
130
|
+
real SQLite, TCP, stdio MCP, and CLI tests.
|
|
131
|
+
|
|
132
|
+
## Managed package delivery
|
|
133
|
+
|
|
134
|
+
Managed npm delivery uses `.github/workflows/publish-package.yml` after the
|
|
135
|
+
exact main/preview owner checks pass. The occurrence generates a unique
|
|
136
|
+
prerelease version and records its source SHA; it reruns the owner suite, packs
|
|
137
|
+
once, and installs that tarball on Linux, macOS and Windows before publication.
|
|
138
|
+
The `candidate-main`/`candidate-preview` tags are release-assembly inputs and
|
|
139
|
+
never select installed runtimes. `package.json` declares this owner's gates,
|
|
140
|
+
CLI probes, peer-only exports and lifecycle permissions. The standalone runner
|
|
141
|
+
under `scripts/release/` is intentionally copied across owners to preserve
|
|
142
|
+
private repository access boundaries. The final publish step uses the `NPM_TOKEN`
|
|
143
|
+
secret in the `npm-release` environment. Where npm trusted publishing is
|
|
144
|
+
configured for this repository's `publish-package.yml` and that environment,
|
|
145
|
+
the token can be omitted. Authentication does not replace native certification,
|
|
146
|
+
exact source records or artifact integrity; private source repositories do not
|
|
147
|
+
receive npm's public-source provenance.
|
|
148
|
+
|
|
149
|
+
Managed dependency reconciliation reads this owner’s declared manifests and
|
|
150
|
+
updates exact same-branch registry candidates in one pending composition PR per
|
|
151
|
+
branch. The repository token explicitly dispatches the owner checks. Every declared gate must
|
|
152
|
+
pass for the exact merge tree; an atomic expected-base update prevents merging
|
|
153
|
+
with untested concurrent source. Human additions or amendments are preserved.
|
|
154
|
+
The half-hour CI reconciliation recovers missed dispatch hints. Assembly runs
|
|
155
|
+
no dependency code or lifecycle hooks, and repeated owner checks do not publish
|
|
156
|
+
another candidate for unchanged source. Repository policy must allow GitHub Actions to create pull requests; no
|
|
157
|
+
cross-repository credential or paid auto-merge feature is required.
|
package/dist/agents.d.ts
CHANGED
|
@@ -1,14 +1,8 @@
|
|
|
1
|
-
import type { AgentDefinitionInput,
|
|
1
|
+
import type { AgentDefinitionInput, AgentPatch, AgentRecord, AgentRevision, AgentsOptions, JsonObject } from './types.js';
|
|
2
2
|
export declare class Agents {
|
|
3
3
|
readonly databasePath: string;
|
|
4
|
-
readonly recoveredTurns: number;
|
|
5
4
|
private readonly opened;
|
|
6
5
|
private readonly agentStore;
|
|
7
|
-
private readonly eventStore;
|
|
8
|
-
private readonly sessionStore;
|
|
9
|
-
private readonly turnStore;
|
|
10
|
-
private readonly runtime;
|
|
11
|
-
private readonly listeners;
|
|
12
6
|
private closed;
|
|
13
7
|
constructor(options?: AgentsOptions);
|
|
14
8
|
createAgent(input: AgentDefinitionInput): AgentRecord;
|
|
@@ -16,24 +10,8 @@ export declare class Agents {
|
|
|
16
10
|
deleteAgent(id: string): AgentRecord;
|
|
17
11
|
getAgent(id: string, includeDeleted?: boolean): AgentRecord | null;
|
|
18
12
|
listAgents(includeDeleted?: boolean): AgentRecord[];
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
listSessions(agentId?: string, includeArchived?: boolean): AgentSession[];
|
|
22
|
-
archiveSession(id: string): AgentSession;
|
|
23
|
-
enqueue(id: string, input: SendInput): EnqueuedTurn;
|
|
24
|
-
send(id: string, input: SendInput): Promise<AgentTurn>;
|
|
25
|
-
talk(agentId: string, input: SendInput & {
|
|
26
|
-
sessionId?: string;
|
|
27
|
-
}): EnqueuedTurn & {
|
|
28
|
-
session: AgentSession;
|
|
29
|
-
};
|
|
30
|
-
cancelSession(id: string): AgentTurn;
|
|
31
|
-
listTurns(sessionId: string): AgentTurn[];
|
|
32
|
-
listEvents(sessionId: string, after?: number, limit?: number): SessionEvent[];
|
|
33
|
-
registerDriver(driver: AgentDriver): void;
|
|
34
|
-
driverIds(): string[];
|
|
35
|
-
subscribe(sessionId: string, listener: EventListener): () => void;
|
|
13
|
+
/** Resolve one exact immutable revision for a host such as Chat. */
|
|
14
|
+
getAgentRevision(agentId: string, revisionId?: string): AgentRevision;
|
|
36
15
|
health(): JsonObject;
|
|
37
|
-
close():
|
|
38
|
-
private publish;
|
|
16
|
+
close(): void;
|
|
39
17
|
}
|
package/dist/agents.js
CHANGED
|
@@ -1,36 +1,16 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
2
|
import { AgentStore } from './agent-store.js';
|
|
3
3
|
import { openDatabase } from './database.js';
|
|
4
|
-
import { EventStore } from './event-store.js';
|
|
5
|
-
import { AgentError } from './errors.js';
|
|
6
|
-
import { AgentRuntime } from './runtime.js';
|
|
7
|
-
import { SessionStore } from './session-store.js';
|
|
8
|
-
import { TurnStore } from './turn-store.js';
|
|
9
4
|
export class Agents {
|
|
10
5
|
databasePath;
|
|
11
|
-
recoveredTurns;
|
|
12
6
|
opened;
|
|
13
7
|
agentStore;
|
|
14
|
-
eventStore;
|
|
15
|
-
sessionStore;
|
|
16
|
-
turnStore;
|
|
17
|
-
runtime;
|
|
18
|
-
listeners = new Map();
|
|
19
8
|
closed = false;
|
|
20
9
|
constructor(options = {}) {
|
|
21
10
|
this.opened = openDatabase(options);
|
|
22
11
|
this.databasePath = this.opened.databasePath;
|
|
23
12
|
const now = options.now || (() => new Date().toISOString());
|
|
24
|
-
this.eventStore = new EventStore(this.opened.database, now, (event) => this.publish(event));
|
|
25
13
|
this.agentStore = new AgentStore(this.opened.database, now);
|
|
26
|
-
this.sessionStore = new SessionStore(this.opened.database, this.eventStore, now);
|
|
27
|
-
this.turnStore = new TurnStore(this.opened.database, this.sessionStore, this.eventStore, now);
|
|
28
|
-
this.recoveredTurns = this.turnStore.recoverInterrupted();
|
|
29
|
-
this.runtime = new AgentRuntime(this.agentStore, this.sessionStore, this.turnStore, this.eventStore, {
|
|
30
|
-
maxInputBytes: options.maxInputBytes || 256_000,
|
|
31
|
-
maxEventBytes: options.maxEventBytes || 256_000,
|
|
32
|
-
turnTimeoutMs: options.turnTimeoutMs ?? 600_000,
|
|
33
|
-
}, options.drivers);
|
|
34
14
|
}
|
|
35
15
|
createAgent(input) {
|
|
36
16
|
return this.agentStore.create(input);
|
|
@@ -47,83 +27,20 @@ export class Agents {
|
|
|
47
27
|
listAgents(includeDeleted = false) {
|
|
48
28
|
return this.agentStore.list(includeDeleted);
|
|
49
29
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
return this.sessionStore.create(revision, input.sessionId, input.metadata || {});
|
|
54
|
-
}
|
|
55
|
-
getSession(id) {
|
|
56
|
-
return this.sessionStore.get(id);
|
|
57
|
-
}
|
|
58
|
-
listSessions(agentId, includeArchived = false) {
|
|
59
|
-
return this.sessionStore.list(agentId, includeArchived);
|
|
60
|
-
}
|
|
61
|
-
archiveSession(id) {
|
|
62
|
-
return this.sessionStore.archive(id, Boolean(this.turnStore.active(id)));
|
|
63
|
-
}
|
|
64
|
-
enqueue(id, input) {
|
|
65
|
-
this.sessionStore.require(id);
|
|
66
|
-
return this.runtime.enqueue(id, input);
|
|
67
|
-
}
|
|
68
|
-
send(id, input) {
|
|
69
|
-
this.sessionStore.require(id);
|
|
70
|
-
return this.runtime.send(id, input);
|
|
71
|
-
}
|
|
72
|
-
talk(agentId, input) {
|
|
73
|
-
const session = input.sessionId
|
|
74
|
-
? this.sessionStore.require(input.sessionId)
|
|
75
|
-
: this.startSession({ agentId });
|
|
76
|
-
if (session.agentId !== agentId) {
|
|
77
|
-
throw new AgentError('conflict', `Session ${session.id} belongs to agent ${session.agentId}.`);
|
|
78
|
-
}
|
|
79
|
-
return { session, ...this.enqueue(session.id, input) };
|
|
80
|
-
}
|
|
81
|
-
cancelSession(id) {
|
|
82
|
-
this.sessionStore.require(id);
|
|
83
|
-
return this.runtime.cancel(id);
|
|
84
|
-
}
|
|
85
|
-
listTurns(sessionId) {
|
|
86
|
-
return this.turnStore.list(sessionId);
|
|
87
|
-
}
|
|
88
|
-
listEvents(sessionId, after = 0, limit = 200) {
|
|
89
|
-
this.sessionStore.require(sessionId);
|
|
90
|
-
return this.eventStore.list(sessionId, after, limit);
|
|
91
|
-
}
|
|
92
|
-
registerDriver(driver) {
|
|
93
|
-
this.runtime.register(driver);
|
|
94
|
-
}
|
|
95
|
-
driverIds() {
|
|
96
|
-
return this.runtime.driverIds();
|
|
97
|
-
}
|
|
98
|
-
subscribe(sessionId, listener) {
|
|
99
|
-
this.sessionStore.require(sessionId);
|
|
100
|
-
const listeners = this.listeners.get(sessionId) || new Set();
|
|
101
|
-
listeners.add(listener);
|
|
102
|
-
this.listeners.set(sessionId, listeners);
|
|
103
|
-
return () => {
|
|
104
|
-
listeners.delete(listener);
|
|
105
|
-
if (listeners.size === 0)
|
|
106
|
-
this.listeners.delete(sessionId);
|
|
107
|
-
};
|
|
30
|
+
/** Resolve one exact immutable revision for a host such as Chat. */
|
|
31
|
+
getAgentRevision(agentId, revisionId) {
|
|
32
|
+
return this.agentStore.revision(agentId, revisionId);
|
|
108
33
|
}
|
|
109
34
|
health() {
|
|
110
35
|
return {
|
|
111
36
|
ok: !this.closed,
|
|
112
37
|
database: path.basename(this.databasePath),
|
|
113
|
-
recoveredTurns: this.recoveredTurns,
|
|
114
|
-
drivers: this.driverIds(),
|
|
115
38
|
};
|
|
116
39
|
}
|
|
117
|
-
|
|
40
|
+
close() {
|
|
118
41
|
if (this.closed)
|
|
119
42
|
return;
|
|
120
43
|
this.closed = true;
|
|
121
|
-
await this.runtime.shutdown();
|
|
122
|
-
this.listeners.clear();
|
|
123
44
|
this.opened.close();
|
|
124
45
|
}
|
|
125
|
-
publish(event) {
|
|
126
|
-
for (const listener of this.listeners.get(event.sessionId) || [])
|
|
127
|
-
listener(event);
|
|
128
|
-
}
|
|
129
46
|
}
|
package/dist/bin/mcp.js
CHANGED
|
@@ -6,7 +6,7 @@ import { fatal } from './fatal.js';
|
|
|
6
6
|
async function main() {
|
|
7
7
|
const args = parseArgs(process.argv.slice(2));
|
|
8
8
|
if (args.flags.has('help')) {
|
|
9
|
-
process.stdout.write('Usage: amalgm-agents-mcp [--state-dir <path>]
|
|
9
|
+
process.stdout.write('Usage: amalgm-agents-mcp [--state-dir <path>]\n');
|
|
10
10
|
return;
|
|
11
11
|
}
|
|
12
12
|
const agents = await openAgents(args);
|
package/dist/cli/help.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const HELP = "amalgm-agents \u2014 local agent
|
|
1
|
+
export declare const HELP = "amalgm-agents \u2014 local agent identities and immutable revisions\n\nAgents:\n amalgm-agents agent list [--include-deleted]\n amalgm-agents agent show <id>\n amalgm-agents agent create <definition.json>\n amalgm-agents agent update <id> <patch.json>\n amalgm-agents agent delete <id>\n\nGlobal options:\n --state-dir <path> Agents state directory\n --help Show this help\n";
|
package/dist/cli/help.js
CHANGED
|
@@ -1,24 +1,13 @@
|
|
|
1
|
-
export const HELP = `amalgm-agents — local agent
|
|
1
|
+
export const HELP = `amalgm-agents — local agent identities and immutable revisions
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Agents:
|
|
4
4
|
amalgm-agents agent list [--include-deleted]
|
|
5
5
|
amalgm-agents agent show <id>
|
|
6
6
|
amalgm-agents agent create <definition.json>
|
|
7
7
|
amalgm-agents agent update <id> <patch.json>
|
|
8
8
|
amalgm-agents agent delete <id>
|
|
9
9
|
|
|
10
|
-
Sessions:
|
|
11
|
-
amalgm-agents session list [--agent <id>] [--include-archived]
|
|
12
|
-
amalgm-agents session start <agent-id> [--id <id>] [--revision <id>]
|
|
13
|
-
amalgm-agents session show <id>
|
|
14
|
-
amalgm-agents session events <id> [--after <sequence>]
|
|
15
|
-
amalgm-agents session send <id> <message> [--key <idempotency-key>]
|
|
16
|
-
amalgm-agents session cancel <id>
|
|
17
|
-
amalgm-agents session archive <id>
|
|
18
|
-
amalgm-agents talk <agent-id> <message> [--session <id>] [--background]
|
|
19
|
-
|
|
20
10
|
Global options:
|
|
21
11
|
--state-dir <path> Agents state directory
|
|
22
|
-
--drivers <a.js,b.js> Driver modules (or AMALGM_AGENT_DRIVERS)
|
|
23
12
|
--help Show this help
|
|
24
13
|
`;
|
package/dist/cli/open.d.ts
CHANGED
package/dist/cli/open.js
CHANGED
|
@@ -1,12 +1,8 @@
|
|
|
1
1
|
import { Agents } from '../agents.js';
|
|
2
|
-
import { driverSpecifiers, loadDriverModules } from '../drivers.js';
|
|
3
2
|
import { flag } from './args.js';
|
|
4
|
-
export
|
|
5
|
-
const modules = flag(args, 'drivers');
|
|
3
|
+
export function openAgents(args) {
|
|
6
4
|
const stateDir = flag(args, 'state-dir');
|
|
7
|
-
const drivers = await loadDriverModules(driverSpecifiers(modules));
|
|
8
5
|
return new Agents({
|
|
9
|
-
drivers,
|
|
10
6
|
...(stateDir ? { stateDir } : {}),
|
|
11
7
|
});
|
|
12
8
|
}
|
package/dist/cli/run.js
CHANGED
|
@@ -4,7 +4,6 @@ import { runAgentCommand } from './agent-commands.js';
|
|
|
4
4
|
import { writeJson } from './files.js';
|
|
5
5
|
import { HELP } from './help.js';
|
|
6
6
|
import { openAgents } from './open.js';
|
|
7
|
-
import { runSessionCommand, runTalkCommand } from './session-commands.js';
|
|
8
7
|
export async function runCli(argv = process.argv.slice(2)) {
|
|
9
8
|
const args = parseArgs(argv);
|
|
10
9
|
if (args.flags.has('help') || args.words.length === 0) {
|
|
@@ -13,15 +12,11 @@ export async function runCli(argv = process.argv.slice(2)) {
|
|
|
13
12
|
}
|
|
14
13
|
let agents;
|
|
15
14
|
try {
|
|
16
|
-
agents =
|
|
15
|
+
agents = openAgents(args);
|
|
17
16
|
const command = args.words[0];
|
|
18
17
|
const value = command === 'agent'
|
|
19
18
|
? runAgentCommand(agents, args)
|
|
20
|
-
:
|
|
21
|
-
? await runSessionCommand(agents, args)
|
|
22
|
-
: command === 'talk'
|
|
23
|
-
? await runTalkCommand(agents, args)
|
|
24
|
-
: undefined;
|
|
19
|
+
: undefined;
|
|
25
20
|
if (value === undefined)
|
|
26
21
|
throw new Error(`Unknown command: ${String(command)}`);
|
|
27
22
|
writeJson(value);
|
|
@@ -33,6 +28,6 @@ export async function runCli(argv = process.argv.slice(2)) {
|
|
|
33
28
|
return 1;
|
|
34
29
|
}
|
|
35
30
|
finally {
|
|
36
|
-
|
|
31
|
+
agents?.close();
|
|
37
32
|
}
|
|
38
33
|
}
|
package/dist/errors.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { JsonObject } from './types.js';
|
|
2
|
-
export type AgentErrorCode = 'invalid_input' | 'not_found' | 'conflict' | 'deleted' | '
|
|
2
|
+
export type AgentErrorCode = 'invalid_input' | 'not_found' | 'conflict' | 'deleted' | 'too_large' | 'internal';
|
|
3
3
|
export declare class AgentError extends Error {
|
|
4
4
|
readonly code: AgentErrorCode;
|
|
5
5
|
readonly details: JsonObject;
|
package/dist/errors.js
CHANGED
package/dist/http/server.js
CHANGED
|
@@ -5,9 +5,7 @@ import { routeAgentConfig } from './config-routes.js';
|
|
|
5
5
|
import { routeAgentBundles } from './bundle-routes.js';
|
|
6
6
|
import { routeAgents } from './agent-routes.js';
|
|
7
7
|
import { guardRequest, readJson, sendJson } from './request.js';
|
|
8
|
-
import { routeSessions } from './session-routes.js';
|
|
9
8
|
import { routeSkills } from './skill-routes.js';
|
|
10
|
-
import { streamEvents } from './stream.js';
|
|
11
9
|
export function createRestServer(options = {}) {
|
|
12
10
|
const agents = options.agents || new Agents(options);
|
|
13
11
|
const owned = !options.agents;
|
|
@@ -57,11 +55,7 @@ export function createRestServer(options = {}) {
|
|
|
57
55
|
sendJson(response, 404, { error: { code: 'not_found', message: 'Route not found.' } });
|
|
58
56
|
return;
|
|
59
57
|
}
|
|
60
|
-
if (
|
|
61
|
-
streamEvents(agents, path[1] || '', request, response, Number(url.searchParams.get('after') || 0));
|
|
62
|
-
return;
|
|
63
|
-
}
|
|
64
|
-
if (await routeAgents(context) || await routeSessions(context))
|
|
58
|
+
if (await routeAgents(context))
|
|
65
59
|
return;
|
|
66
60
|
sendJson(response, 404, { error: { code: 'not_found', message: 'Route not found.' } });
|
|
67
61
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
export { Agents } from './agents.js';
|
|
2
2
|
export { AgentError, asAgentError } from './errors.js';
|
|
3
|
-
export { defineDriver, driverSpecifiers, loadDriverModules } from './drivers.js';
|
|
4
3
|
export { definitionHash, normalizeDefinition, patchDefinition } from './definition.js';
|
|
5
|
-
export { messageText, normalizeMessage } from './messages.js';
|
|
6
4
|
export type * from './types.js';
|
|
7
5
|
export { buildCanonicalSkillRoots, classifySkillRoot } from './skills/roots.js';
|
|
8
6
|
export type { SkillRootClassification, SkillRootOptions } from './skills/roots.js';
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
export { Agents } from './agents.js';
|
|
2
2
|
export { AgentError, asAgentError } from './errors.js';
|
|
3
|
-
export { defineDriver, driverSpecifiers, loadDriverModules } from './drivers.js';
|
|
4
3
|
export { definitionHash, normalizeDefinition, patchDefinition } from './definition.js';
|
|
5
|
-
export { messageText, normalizeMessage } from './messages.js';
|
|
6
4
|
export { buildCanonicalSkillRoots, classifySkillRoot } from './skills/roots.js';
|
|
7
5
|
export { parseSkillFrontmatter, scanInstalledSkills } from './skills/scanner.js';
|
|
8
6
|
export { normalizeAgentConfig, stableConfigId } from './config/schema.js';
|
package/dist/mcp/agent-tools.js
CHANGED
|
@@ -41,7 +41,7 @@ export function agentTools(agents) {
|
|
|
41
41
|
},
|
|
42
42
|
{
|
|
43
43
|
name: 'agents_delete',
|
|
44
|
-
description: '
|
|
44
|
+
description: 'Tombstone an agent identity while retaining its immutable revisions.',
|
|
45
45
|
inputSchema: objectSchema({ agent_id: string }, ['agent_id']),
|
|
46
46
|
handler(input) {
|
|
47
47
|
return toolResult({ agent: agents.deleteAgent(stringArg(input, 'agent_id')) });
|
package/dist/mcp/tools.js
CHANGED
package/dist/rows.d.ts
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
import type { AgentRecord, AgentRevision
|
|
1
|
+
import type { AgentRecord, AgentRevision } from './types.js';
|
|
2
2
|
export type Row = Record<string, unknown>;
|
|
3
3
|
export declare function revisionFromRow(row: Row): AgentRevision;
|
|
4
4
|
export declare function agentFromRow(row: Row): AgentRecord;
|
|
5
|
-
export declare function sessionFromRow(row: Row): AgentSession;
|
|
6
|
-
export declare function turnFromRow(row: Row): AgentTurn;
|
|
7
|
-
export declare function eventFromRow(row: Row): SessionEvent;
|
package/dist/rows.js
CHANGED
|
@@ -24,42 +24,3 @@ export function agentFromRow(row) {
|
|
|
24
24
|
deletedAt: nullable(row.deleted_at),
|
|
25
25
|
};
|
|
26
26
|
}
|
|
27
|
-
export function sessionFromRow(row) {
|
|
28
|
-
return {
|
|
29
|
-
id: String(row.id),
|
|
30
|
-
agentId: String(row.agent_id),
|
|
31
|
-
agentRevisionId: String(row.agent_revision_id),
|
|
32
|
-
agentRevision: Number(row.agent_revision_number),
|
|
33
|
-
status: String(row.status),
|
|
34
|
-
driverSessionId: nullable(row.driver_session_id),
|
|
35
|
-
metadata: parseObject(String(row.metadata_json)),
|
|
36
|
-
createdAt: String(row.created_at),
|
|
37
|
-
updatedAt: String(row.updated_at),
|
|
38
|
-
archivedAt: nullable(row.archived_at),
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
export function turnFromRow(row) {
|
|
42
|
-
return {
|
|
43
|
-
id: String(row.id),
|
|
44
|
-
sessionId: String(row.session_id),
|
|
45
|
-
idempotencyKey: String(row.idempotency_key),
|
|
46
|
-
status: String(row.status),
|
|
47
|
-
input: JSON.parse(String(row.input_json)),
|
|
48
|
-
result: row.result_json ? parseObject(String(row.result_json)) : null,
|
|
49
|
-
error: row.error_json ? parseObject(String(row.error_json)) : null,
|
|
50
|
-
createdAt: String(row.created_at),
|
|
51
|
-
startedAt: nullable(row.started_at),
|
|
52
|
-
completedAt: nullable(row.completed_at),
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
export function eventFromRow(row) {
|
|
56
|
-
return {
|
|
57
|
-
id: String(row.id),
|
|
58
|
-
sessionId: String(row.session_id),
|
|
59
|
-
turnId: nullable(row.turn_id),
|
|
60
|
-
sequence: Number(row.sequence),
|
|
61
|
-
type: String(row.type),
|
|
62
|
-
data: parseObject(String(row.data_json)),
|
|
63
|
-
createdAt: String(row.created_at),
|
|
64
|
-
};
|
|
65
|
-
}
|