@hanphone/dsh-a2a 0.2.0 → 0.3.0
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/README.md +101 -106
- package/README.zh.md +50 -74
- package/cordis.patch.yml +4 -7
- package/lib/client.js +217 -73
- package/lib/index.js +1258 -867
- package/lib/types/api.d.ts +40 -23
- package/lib/types/api.d.ts.map +1 -1
- package/lib/types/api.js +58 -23
- package/lib/types/api.js.map +1 -1
- package/lib/types/client/index.d.ts +50 -19
- package/lib/types/client/index.d.ts.map +1 -1
- package/lib/types/commands.d.ts +4 -2
- package/lib/types/commands.d.ts.map +1 -1
- package/lib/types/commands.js +59 -46
- package/lib/types/commands.js.map +1 -1
- package/lib/types/events.d.ts +32 -9
- package/lib/types/events.d.ts.map +1 -1
- package/lib/types/index.d.ts +21 -32
- package/lib/types/index.d.ts.map +1 -1
- package/lib/types/index.js +173 -272
- package/lib/types/index.js.map +1 -1
- package/lib/types/outbound/calls.d.ts.map +1 -1
- package/lib/types/outbound/calls.js +8 -6
- package/lib/types/outbound/calls.js.map +1 -1
- package/lib/types/protocol.d.ts +174 -109
- package/lib/types/protocol.d.ts.map +1 -1
- package/lib/types/protocol.js +58 -34
- package/lib/types/protocol.js.map +1 -1
- package/lib/types/server/a2a-server.d.ts +4 -0
- package/lib/types/server/a2a-server.d.ts.map +1 -1
- package/lib/types/server/a2a-server.js +6 -2
- package/lib/types/server/a2a-server.js.map +1 -1
- package/lib/types/server/card.d.ts +6 -30
- package/lib/types/server/card.d.ts.map +1 -1
- package/lib/types/server/card.js +13 -49
- package/lib/types/server/card.js.map +1 -1
- package/lib/types/server/exec/agent-runtime.d.ts +3 -0
- package/lib/types/server/exec/agent-runtime.d.ts.map +1 -1
- package/lib/types/server/exec/agent-runtime.js +2 -1
- package/lib/types/server/exec/agent-runtime.js.map +1 -1
- package/lib/types/server/routes.d.ts +5 -1
- package/lib/types/server/routes.d.ts.map +1 -1
- package/lib/types/server/routes.js +9 -5
- package/lib/types/server/routes.js.map +1 -1
- package/lib/types/server/store.d.ts +35 -1
- package/lib/types/server/store.d.ts.map +1 -1
- package/lib/types/server/store.js +10 -0
- package/lib/types/server/store.js.map +1 -1
- package/lib/types/servers/inbound-manager.d.ts +131 -0
- package/lib/types/servers/inbound-manager.d.ts.map +1 -0
- package/lib/types/servers/inbound-manager.js +312 -0
- package/lib/types/servers/inbound-manager.js.map +1 -0
- package/lib/types/servers/outbound-manager.d.ts +129 -0
- package/lib/types/servers/outbound-manager.d.ts.map +1 -0
- package/lib/types/servers/outbound-manager.js +238 -0
- package/lib/types/servers/outbound-manager.js.map +1 -0
- package/lib/types/service.d.ts +106 -40
- package/lib/types/service.d.ts.map +1 -1
- package/lib/types/service.js +36 -27
- package/lib/types/service.js.map +1 -1
- package/package.json +2 -2
- package/src/api.ts +67 -53
- package/src/client/index.ts +309 -148
- package/src/commands.ts +59 -43
- package/src/events.ts +14 -7
- package/src/index.ts +199 -310
- package/src/outbound/calls.ts +8 -6
- package/src/protocol.ts +204 -95
- package/src/server/a2a-server.ts +9 -2
- package/src/server/card.ts +13 -62
- package/src/server/exec/agent-runtime.ts +5 -2
- package/src/server/routes.ts +6 -4
- package/src/server/store.ts +45 -4
- package/src/servers/inbound-manager.ts +385 -0
- package/src/servers/outbound-manager.ts +289 -0
- package/src/service.ts +125 -40
- package/lib/tsconfig.client.tsbuildinfo +0 -1
- package/lib/tsconfig.tsbuildinfo +0 -1
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* @module dsh-a2a/server/store
|
|
8
8
|
*/
|
|
9
9
|
import { type Domain, type DomainFacility, type KvTable } from '@deepseek-ai/dsh-storage-domain';
|
|
10
|
-
import { TaskState, type Part } from '../protocol.ts';
|
|
10
|
+
import { TaskState, type AgentSkill, type Part } from '../protocol.ts';
|
|
11
11
|
/** One durable inbound/outbound task record. */
|
|
12
12
|
export interface TaskRecord {
|
|
13
13
|
readonly taskId: string;
|
|
@@ -30,6 +30,8 @@ export interface TaskRecord {
|
|
|
30
30
|
readonly code: string;
|
|
31
31
|
readonly message: string;
|
|
32
32
|
};
|
|
33
|
+
/** The inbound server instance this task arrived through. */
|
|
34
|
+
readonly serverId?: string;
|
|
33
35
|
}
|
|
34
36
|
/** One durable context→session binding (inbound conversation ↔ DSH session). */
|
|
35
37
|
export interface ContextBinding {
|
|
@@ -45,6 +47,31 @@ export interface OutboundAgentRecord {
|
|
|
45
47
|
readonly timeoutMs: number;
|
|
46
48
|
readonly lastCardAt: string | null;
|
|
47
49
|
}
|
|
50
|
+
/** One durable inbound server instance. */
|
|
51
|
+
export interface InboundServerRecord {
|
|
52
|
+
readonly id: string;
|
|
53
|
+
readonly name: string;
|
|
54
|
+
readonly description: string;
|
|
55
|
+
readonly version: string;
|
|
56
|
+
readonly endpointPath: string;
|
|
57
|
+
/** Agent preset id composing inbound sessions; absent = deployment default. */
|
|
58
|
+
readonly preset?: string;
|
|
59
|
+
readonly authTokenEnv?: string;
|
|
60
|
+
/** Advertised skills (creator-entered declarations, default = preset name). */
|
|
61
|
+
readonly skills: readonly AgentSkill[];
|
|
62
|
+
readonly enabled: boolean;
|
|
63
|
+
}
|
|
64
|
+
/** One durable outbound server connection instance. */
|
|
65
|
+
export interface OutboundServerRecord {
|
|
66
|
+
readonly id: string;
|
|
67
|
+
readonly name: string;
|
|
68
|
+
readonly agentCardUrl: string;
|
|
69
|
+
readonly bearerTokenEnv?: string;
|
|
70
|
+
/** Preset composing this DSH's local session when talking to the remote. */
|
|
71
|
+
readonly preset?: string;
|
|
72
|
+
readonly enabled: boolean;
|
|
73
|
+
readonly timeoutMs: number;
|
|
74
|
+
}
|
|
48
75
|
/** The `a2a` storage domain: JSON-encoded records, one table per record kind. */
|
|
49
76
|
export declare const a2aDomainSpec: {
|
|
50
77
|
name: string;
|
|
@@ -54,6 +81,8 @@ export declare const a2aDomainSpec: {
|
|
|
54
81
|
contexts: import("@deepseek-ai/dsh-storage-domain").DomainTableSpec<string, string>;
|
|
55
82
|
agents: import("@deepseek-ai/dsh-storage-domain").DomainTableSpec<string, string>;
|
|
56
83
|
identity: import("@deepseek-ai/dsh-storage-domain").DomainTableSpec<string, string>;
|
|
84
|
+
inbound_servers: import("@deepseek-ai/dsh-storage-domain").DomainTableSpec<string, string>;
|
|
85
|
+
outbound_servers: import("@deepseek-ai/dsh-storage-domain").DomainTableSpec<string, string>;
|
|
57
86
|
};
|
|
58
87
|
};
|
|
59
88
|
export type A2aDomainSpec = typeof a2aDomainSpec;
|
|
@@ -76,6 +105,8 @@ export declare class A2aDomain {
|
|
|
76
105
|
get contexts(): KvTable<string, string>;
|
|
77
106
|
get agents(): KvTable<string, string>;
|
|
78
107
|
get identity(): KvTable<string, string>;
|
|
108
|
+
get inbound_servers(): KvTable<string, string>;
|
|
109
|
+
get outbound_servers(): KvTable<string, string>;
|
|
79
110
|
close(): Promise<void>;
|
|
80
111
|
}
|
|
81
112
|
/** Task-store contract shared by the domain-backed and memory stores. */
|
|
@@ -85,6 +116,7 @@ export interface TaskStore {
|
|
|
85
116
|
skill: string;
|
|
86
117
|
parts: readonly Part[];
|
|
87
118
|
remotePeerId: string | null;
|
|
119
|
+
serverId?: string;
|
|
88
120
|
}): TaskRecord;
|
|
89
121
|
get(taskId: string): TaskRecord | undefined;
|
|
90
122
|
list(): TaskRecord[];
|
|
@@ -111,6 +143,7 @@ export declare class MemoryTaskStore implements TaskStore {
|
|
|
111
143
|
skill: string;
|
|
112
144
|
parts: readonly Part[];
|
|
113
145
|
remotePeerId: string | null;
|
|
146
|
+
serverId?: string;
|
|
114
147
|
}): TaskRecord;
|
|
115
148
|
get(taskId: string): TaskRecord | undefined;
|
|
116
149
|
list(): TaskRecord[];
|
|
@@ -139,6 +172,7 @@ export declare class DomainTaskStore implements TaskStore {
|
|
|
139
172
|
skill: string;
|
|
140
173
|
parts: readonly Part[];
|
|
141
174
|
remotePeerId: string | null;
|
|
175
|
+
serverId?: string;
|
|
142
176
|
}): TaskRecord;
|
|
143
177
|
get(taskId: string): TaskRecord | undefined;
|
|
144
178
|
list(): TaskRecord[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../../../src/server/store.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,EAGL,KAAK,MAAM,EACX,KAAK,cAAc,EACnB,KAAK,OAAO,EACb,MAAM,iCAAiC,CAAA;AACxC,OAAO,EAAE,SAAS,EAAE,KAAK,IAAI,EAAE,MAAM,gBAAgB,CAAA;
|
|
1
|
+
{"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../../../src/server/store.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,EAGL,KAAK,MAAM,EACX,KAAK,cAAc,EACnB,KAAK,OAAO,EACb,MAAM,iCAAiC,CAAA;AACxC,OAAO,EAAE,SAAS,EAAE,KAAK,UAAU,EAAE,KAAK,IAAI,EAAE,MAAM,gBAAgB,CAAA;AAEtE,gDAAgD;AAChD,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;IAC1B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;IACtB,QAAQ,CAAC,KAAK,EAAE,SAAS,CAAA;IACzB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;IAC1B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;IAC1B,QAAQ,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAAA;IACjC,QAAQ,CAAC,YAAY,EAAE,MAAM,GAAG,IAAI,CAAA;IACpC,QAAQ,CAAC,KAAK,EAAE,SAAS,IAAI,EAAE,CAAA;IAC/B,QAAQ,CAAC,SAAS,EAAE,SAAS;QAAE,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,KAAK,EAAE,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C,KAAK,EAAE;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,SAAS,IAAI,EAAE,CAAC;QAAC,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;QAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,UAAU;IAwBvI,GAAG,CAAC,MAAM,EAAE,MAAM,GAAG,UAAU,GAAG,SAAS;IAI3C,IAAI,IAAI,UAAU,EAAE;IAIpB,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,EAAE,OAAO,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,GAAG,UAAU;IAWhG,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE;QAAE,UAAU,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,SAAS,IAAI,EAAE,CAAC;QAAC,SAAS,CAAC,EAAE,OAAO,CAAA;KAAE,GAAG,UAAU;IAWlI,iBAAiB,CAAC,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAMtE,iBAAiB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;IAIjE,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAC7B"}
|
|
@@ -20,6 +20,8 @@ export const a2aDomainSpec = defineDomain({
|
|
|
20
20
|
contexts: domainTable(json),
|
|
21
21
|
agents: domainTable(json),
|
|
22
22
|
identity: domainTable(json),
|
|
23
|
+
inbound_servers: domainTable(json),
|
|
24
|
+
outbound_servers: domainTable(json),
|
|
23
25
|
},
|
|
24
26
|
});
|
|
25
27
|
/**
|
|
@@ -63,6 +65,12 @@ export class A2aDomain {
|
|
|
63
65
|
get identity() {
|
|
64
66
|
return this.handle.table('identity');
|
|
65
67
|
}
|
|
68
|
+
get inbound_servers() {
|
|
69
|
+
return this.handle.table('inbound_servers');
|
|
70
|
+
}
|
|
71
|
+
get outbound_servers() {
|
|
72
|
+
return this.handle.table('outbound_servers');
|
|
73
|
+
}
|
|
66
74
|
async close() {
|
|
67
75
|
await this.handle.close();
|
|
68
76
|
}
|
|
@@ -94,6 +102,7 @@ export class MemoryTaskStore {
|
|
|
94
102
|
artifacts: [],
|
|
95
103
|
executor: 'session',
|
|
96
104
|
summary: null,
|
|
105
|
+
...(input.serverId !== undefined ? { serverId: input.serverId } : {}),
|
|
97
106
|
};
|
|
98
107
|
this.tasks.set(record.taskId, record);
|
|
99
108
|
return record;
|
|
@@ -186,6 +195,7 @@ export class DomainTaskStore {
|
|
|
186
195
|
artifacts: [],
|
|
187
196
|
executor: 'session',
|
|
188
197
|
summary: null,
|
|
198
|
+
...(input.serverId !== undefined ? { serverId: input.serverId } : {}),
|
|
189
199
|
};
|
|
190
200
|
this.records.set(record.taskId, record);
|
|
191
201
|
// Persist eagerly; a failed write must fail the task, not silently lose it.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"store.js","sourceRoot":"","sources":["../../../src/server/store.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AACvB,OAAO,EACL,YAAY,EACZ,WAAW,GAIZ,MAAM,iCAAiC,CAAA;AACxC,OAAO,EAAE,SAAS,
|
|
1
|
+
{"version":3,"file":"store.js","sourceRoot":"","sources":["../../../src/server/store.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AACvB,OAAO,EACL,YAAY,EACZ,WAAW,GAIZ,MAAM,iCAAiC,CAAA;AACxC,OAAO,EAAE,SAAS,EAA8B,MAAM,gBAAgB,CAAA;AAgEtE,8DAA8D;AAC9D,MAAM,IAAI,GAAG,CAAC,CAAC,MA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MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE,YAAY,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,GAAY,EAAE,EAAE;YACvF,MAAM,IAAI,KAAK,CAAC,iCAAiC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,CAAA;QACjE,CAAC,CAAC,CAAA;QACF,OAAO,IAAI,CAAA;IACb,CAAC;IAED,KAAK,CAAC,iBAAiB,CAAC,SAAiB,EAAE,SAAiB;QAC1D,MAAM,OAAO,GAAmB,EAAE,SAAS,EAAE,CAAA;QAC7C,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,SAAS,EAAE,SAAS,CAAC,CAAA;QACvC,MAAM,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,UAAU,CAAC,SAAS,CAAC,EAAE,YAAY,CAAC,OAAO,CAAC,CAAC,CAAA;IAC9E,CAAC;IAED,KAAK,CAAC,iBAAiB,CAAC,SAAiB;QACvC,OAAO,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,SAAS,CAAC,CAAA;IACrC,CAAC;IAED,KAAK,CAAC,KAAK,KAAmB,CAAC;CAChC;AAED,SAAS,SAAS,CAChB,OAAmB,EACnB,KAAgB,EAChB,OAAmD,EACnD,SAAiB;IAEjB,OAAO;QACL,GAAG,OAAO;QACV,KAAK;QACL,SAAS,EAAE,SAAS;QACpB,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,OAAO,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KAC7E,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Inbound server manager: owns every inbound A2A server instance. Each
|
|
3
|
+
* instance binds one agent preset (its session pool is composed from that
|
|
4
|
+
* preset), advertises creator-declared skills, and serves its own endpoint and
|
|
5
|
+
* AgentCard route. Instances are persisted in the `inbound_servers` domain
|
|
6
|
+
* table and assembled on boot; the manager owns route registration and the
|
|
7
|
+
* full lifecycle (add/enable/disable/update/remove) driven from the GUI and
|
|
8
|
+
* facade, and disposes every instance's environment on teardown.
|
|
9
|
+
*
|
|
10
|
+
* Skill declaration: the stored `skills` list is exactly what the creator
|
|
11
|
+
* declared. When a creator leaves it empty at creation time, the default skill
|
|
12
|
+
* derives from the bound preset's display name (else the built-in `chat`
|
|
13
|
+
* skill), per the v1.0 design — the v0.2 tool white-list derivation is gone.
|
|
14
|
+
* @module dsh-a2a/servers/inbound-manager
|
|
15
|
+
*/
|
|
16
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
17
|
+
import { buildCard } from '../server/card.ts';
|
|
18
|
+
import { A2AServer } from '../server/a2a-server.ts';
|
|
19
|
+
import { A2aRoutes } from '../server/routes.ts';
|
|
20
|
+
import { type AgentPresetsLike, type AgentRegistryLike } from '../server/exec/agent-runtime.ts';
|
|
21
|
+
import { type SubagentsLike } from '../server/exec/subagent.ts';
|
|
22
|
+
import { ExecutorSet } from '../server/executor.ts';
|
|
23
|
+
import { LiveInboundRegistry } from '../server/inbound-registry.ts';
|
|
24
|
+
import type { TaskStore, InboundServerRecord } from '../server/store.ts';
|
|
25
|
+
import type { AgentSkill } from '../protocol.ts';
|
|
26
|
+
/** Web-server slice the manager registers instance routes on. */
|
|
27
|
+
export interface WebServerLike {
|
|
28
|
+
register(route: {
|
|
29
|
+
readonly kind: 'exact' | 'prefix';
|
|
30
|
+
readonly path: string;
|
|
31
|
+
handler(...args: unknown[]): unknown;
|
|
32
|
+
}): () => void;
|
|
33
|
+
}
|
|
34
|
+
/** Host service slices one manager needs. */
|
|
35
|
+
export interface InboundManagerHost {
|
|
36
|
+
readonly ctx: Context;
|
|
37
|
+
readonly webServer: WebServerLike;
|
|
38
|
+
readonly tasks: TaskStore;
|
|
39
|
+
readonly logger: {
|
|
40
|
+
info(message: string): void;
|
|
41
|
+
warn(message: string): void;
|
|
42
|
+
error(message: string): void;
|
|
43
|
+
};
|
|
44
|
+
readonly agents?: AgentRegistryLike;
|
|
45
|
+
readonly agentPresets?: AgentPresetsLike;
|
|
46
|
+
readonly subagents?: SubagentsLike;
|
|
47
|
+
readonly sessionCwd: string;
|
|
48
|
+
readonly defaultBaseUrl: string;
|
|
49
|
+
readonly subagentProvider: string;
|
|
50
|
+
/** Resolve the deployment's default model options (may be undefined). */
|
|
51
|
+
readonly resolveDefaultModel?: () => {
|
|
52
|
+
readonly provider?: string;
|
|
53
|
+
readonly model?: string;
|
|
54
|
+
} | undefined;
|
|
55
|
+
/** Allocate a fresh stable instance id. */
|
|
56
|
+
readonly newId: () => string;
|
|
57
|
+
}
|
|
58
|
+
/** One live inbound instance's runtime handle. */
|
|
59
|
+
export interface LiveInboundServer {
|
|
60
|
+
readonly id: string;
|
|
61
|
+
readonly record: InboundServerRecord;
|
|
62
|
+
readonly card: ReturnType<typeof buildCard>;
|
|
63
|
+
readonly server: A2AServer;
|
|
64
|
+
readonly routes: A2aRoutes;
|
|
65
|
+
readonly inbound: LiveInboundRegistry;
|
|
66
|
+
readonly executors: ExecutorSet;
|
|
67
|
+
readonly endpointPath: string;
|
|
68
|
+
readonly cardPath: string;
|
|
69
|
+
dispose(): void;
|
|
70
|
+
}
|
|
71
|
+
/** Creator input for a new (or updated) inbound instance. */
|
|
72
|
+
export interface InboundCreateInput {
|
|
73
|
+
readonly name: string;
|
|
74
|
+
readonly description: string;
|
|
75
|
+
readonly version: string;
|
|
76
|
+
readonly endpointPath?: string;
|
|
77
|
+
readonly preset?: string;
|
|
78
|
+
readonly authTokenEnv?: string;
|
|
79
|
+
/** Declared skills; empty defaults to the preset name (or `chat`). */
|
|
80
|
+
readonly skills?: readonly AgentSkill[];
|
|
81
|
+
readonly enabled?: boolean;
|
|
82
|
+
}
|
|
83
|
+
export interface OpResult {
|
|
84
|
+
readonly ok: boolean;
|
|
85
|
+
readonly message: string;
|
|
86
|
+
}
|
|
87
|
+
/** Default skkill when a creator declares none: the preset display name. */
|
|
88
|
+
export declare function defaultSkillFor(skills: readonly AgentSkill[] | undefined, presetName: string | undefined): readonly AgentSkill[];
|
|
89
|
+
/** Persisted-instance store over the inbound_servers table. */
|
|
90
|
+
export declare class DomainInboundStore {
|
|
91
|
+
private readonly table;
|
|
92
|
+
private static KEY;
|
|
93
|
+
constructor(table: {
|
|
94
|
+
get(key: string): string | undefined;
|
|
95
|
+
put(key: string, value: string): Promise<void>;
|
|
96
|
+
entries?(): IterableIterator<[string, string]>;
|
|
97
|
+
keys?(): IterableIterator<string>;
|
|
98
|
+
});
|
|
99
|
+
list(): InboundServerRecord[];
|
|
100
|
+
get(id: string): InboundServerRecord | undefined;
|
|
101
|
+
save(record: InboundServerRecord): Promise<void>;
|
|
102
|
+
remove(id: string): Promise<void>;
|
|
103
|
+
}
|
|
104
|
+
/** Manages the live set of inbound server instances. */
|
|
105
|
+
export declare class InboundServerManager {
|
|
106
|
+
private readonly host;
|
|
107
|
+
private readonly store;
|
|
108
|
+
private readonly live;
|
|
109
|
+
constructor(host: InboundManagerHost, store: DomainInboundStore);
|
|
110
|
+
/** Assemble every persisted enabled instance (boot). */
|
|
111
|
+
boot(): void;
|
|
112
|
+
list(): readonly LiveInboundServer[];
|
|
113
|
+
get(id: string): LiveInboundServer | undefined;
|
|
114
|
+
/** Resolve the display name of a preset id (undefined when unnamed/absent). */
|
|
115
|
+
private presetDisplayName;
|
|
116
|
+
/** Create, persist, and assemble a new inbound instance. */
|
|
117
|
+
add(input: InboundCreateInput): Promise<OpResult & {
|
|
118
|
+
readonly id?: string;
|
|
119
|
+
}>;
|
|
120
|
+
/** Persist, rebuild, and apply a patch onto a live instance. */
|
|
121
|
+
update(id: string, patch: Partial<Pick<InboundServerRecord, 'name' | 'description' | 'version' | 'endpointPath' | 'preset' | 'authTokenEnv' | 'skills'>>): Promise<OpResult>;
|
|
122
|
+
/** Enable/disable an instance's routes. */
|
|
123
|
+
setEnabled(id: string, enabled: boolean): OpResult;
|
|
124
|
+
/** Remove, dispose, and unpersist an instance. */
|
|
125
|
+
remove(id: string): Promise<OpResult>;
|
|
126
|
+
/** Dispose every instance. */
|
|
127
|
+
disposeAll(): void;
|
|
128
|
+
private newId;
|
|
129
|
+
}
|
|
130
|
+
export type { AgentSkill };
|
|
131
|
+
//# sourceMappingURL=inbound-manager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inbound-manager.d.ts","sourceRoot":"","sources":["../../../src/servers/inbound-manager.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAClD,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAA;AAC7C,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AACnD,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAA;AAC/C,OAAO,EAAsB,KAAK,gBAAgB,EAAE,KAAK,iBAAiB,EAAE,MAAM,iCAAiC,CAAA;AAEnH,OAAO,EAA0B,KAAK,aAAa,EAAE,MAAM,4BAA4B,CAAA;AACvF,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AACnD,OAAO,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAA;AACnE,OAAO,KAAK,EAAE,SAAS,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAA;AACxE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAIhD,iEAAiE;AACjE,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,KAAK,EAAE;QACd,QAAQ,CAAC,IAAI,EAAE,OAAO,GAAG,QAAQ,CAAA;QACjC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;QACrB,OAAO,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,OAAO,CAAA;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O,EAAE,OAAO,GAAG,QAAQ;IAYlD,kDAAkD;IAC5C,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC;IAS3C,8BAA8B;IAC9B,UAAU,IAAI,IAAI;IAKlB,OAAO,CAAC,KAAK;CAId;AAED,YAAY,EAAE,UAAU,EAAE,CAAA"}
|
|
@@ -0,0 +1,312 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Inbound server manager: owns every inbound A2A server instance. Each
|
|
3
|
+
* instance binds one agent preset (its session pool is composed from that
|
|
4
|
+
* preset), advertises creator-declared skills, and serves its own endpoint and
|
|
5
|
+
* AgentCard route. Instances are persisted in the `inbound_servers` domain
|
|
6
|
+
* table and assembled on boot; the manager owns route registration and the
|
|
7
|
+
* full lifecycle (add/enable/disable/update/remove) driven from the GUI and
|
|
8
|
+
* facade, and disposes every instance's environment on teardown.
|
|
9
|
+
*
|
|
10
|
+
* Skill declaration: the stored `skills` list is exactly what the creator
|
|
11
|
+
* declared. When a creator leaves it empty at creation time, the default skill
|
|
12
|
+
* derives from the bound preset's display name (else the built-in `chat`
|
|
13
|
+
* skill), per the v1.0 design — the v0.2 tool white-list derivation is gone.
|
|
14
|
+
* @module dsh-a2a/servers/inbound-manager
|
|
15
|
+
*/
|
|
16
|
+
import { buildCard } from "../server/card.js";
|
|
17
|
+
import { A2AServer } from "../server/a2a-server.js";
|
|
18
|
+
import { A2aRoutes } from "../server/routes.js";
|
|
19
|
+
import { ContextSessionPool } from "../server/exec/agent-runtime.js";
|
|
20
|
+
import { createSessionExecutor } from "../server/exec/session.js";
|
|
21
|
+
import { createSubagentExecutor } from "../server/exec/subagent.js";
|
|
22
|
+
import { ExecutorSet } from "../server/executor.js";
|
|
23
|
+
import { LiveInboundRegistry } from "../server/inbound-registry.js";
|
|
24
|
+
function refuseExecutor(reason) {
|
|
25
|
+
return {
|
|
26
|
+
name: 'refuse',
|
|
27
|
+
async execute() {
|
|
28
|
+
throw new Error(`a2a: ${reason}; refusing inbound task`);
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
/** Default skkill when a creator declares none: the preset display name. */
|
|
33
|
+
export function defaultSkillFor(skills, presetName) {
|
|
34
|
+
if (skills !== undefined && skills.length > 0)
|
|
35
|
+
return skills;
|
|
36
|
+
if (presetName !== undefined && presetName.length > 0) {
|
|
37
|
+
return [{ id: 'chat', name: presetName, description: `Compose inbound sessions from the "${presetName}" agent preset.`, tags: ['preset'] }];
|
|
38
|
+
}
|
|
39
|
+
return [{ id: 'chat', name: 'chat', description: 'Conversational assistance over a DSH agent session.', tags: ['chat'] }];
|
|
40
|
+
}
|
|
41
|
+
/** Assemble one live instance from a persisted record. */
|
|
42
|
+
function assemble(record, host) {
|
|
43
|
+
const skills = record.skills;
|
|
44
|
+
const endpointPath = record.endpointPath;
|
|
45
|
+
const cardPath = `${endpointPath.replace(/\/$/, '')}/agent-card.json`;
|
|
46
|
+
const card = buildCard({
|
|
47
|
+
baseUrl: host.defaultBaseUrl,
|
|
48
|
+
endpointPath,
|
|
49
|
+
name: record.name,
|
|
50
|
+
description: record.description,
|
|
51
|
+
version: record.version,
|
|
52
|
+
skills,
|
|
53
|
+
...(record.authTokenEnv !== undefined && process.env[record.authTokenEnv] !== undefined
|
|
54
|
+
? { authToken: process.env[record.authTokenEnv] }
|
|
55
|
+
: {}),
|
|
56
|
+
});
|
|
57
|
+
// One preset-bound session pool per instance.
|
|
58
|
+
const sessionPool = host.agents
|
|
59
|
+
? new ContextSessionPool(host.agents, {
|
|
60
|
+
cwd: host.sessionCwd,
|
|
61
|
+
...(host.agentPresets !== undefined ? { agentPresets: host.agentPresets } : {}),
|
|
62
|
+
...(record.preset !== undefined ? { presetId: () => record.preset } : {}),
|
|
63
|
+
// `?.()` yields `{ provider?, model? } | undefined`, matching the
|
|
64
|
+
// AgentRuntimeOptions.resolveAgentOptions signature under
|
|
65
|
+
// exactOptionalPropertyTypes.
|
|
66
|
+
resolveAgentOptions: () => host.resolveDefaultModel?.(),
|
|
67
|
+
})
|
|
68
|
+
: undefined;
|
|
69
|
+
const sessionExecutor = sessionPool ? createSessionExecutor(sessionPool) : refuseExecutor('no agent loop mounted');
|
|
70
|
+
const subagentExecutor = sessionPool !== undefined && host.subagents !== undefined
|
|
71
|
+
? createSubagentExecutor({ pool: sessionPool, subagents: host.subagents, provider: host.subagentProvider })
|
|
72
|
+
: undefined;
|
|
73
|
+
const executors = new ExecutorSet({ chat: 'session' }, sessionExecutor, subagentExecutor);
|
|
74
|
+
const inbound = new LiveInboundRegistry();
|
|
75
|
+
const skillIds = new Set(skills.map((s) => s.id));
|
|
76
|
+
const gate = async (input) => {
|
|
77
|
+
if (!skillIds.has(input.skill)) {
|
|
78
|
+
return { ok: false, reason: `unknown skill "${input.skill}"` };
|
|
79
|
+
}
|
|
80
|
+
const decision = {
|
|
81
|
+
contextId: input.contextId,
|
|
82
|
+
skill: input.skill,
|
|
83
|
+
parts: input.parts,
|
|
84
|
+
remotePeerId: input.remotePeerId,
|
|
85
|
+
};
|
|
86
|
+
const decided = await host.ctx.waterfall('a2a/inbound-task', decision, async (d) => d);
|
|
87
|
+
host.logger.info(`[a2a:${record.id}] inbound skill=${decided.skill} rejected=${decided.rejected?.reason ?? 'no'}`);
|
|
88
|
+
if (decided.rejected !== undefined)
|
|
89
|
+
return { ok: false, reason: decided.rejected.reason };
|
|
90
|
+
return { ok: true };
|
|
91
|
+
};
|
|
92
|
+
const server = new A2AServer({
|
|
93
|
+
card,
|
|
94
|
+
store: host.tasks,
|
|
95
|
+
executors,
|
|
96
|
+
...(card.securitySchemes !== undefined ? { authToken: 'configured' } : {}),
|
|
97
|
+
cardPath,
|
|
98
|
+
gate,
|
|
99
|
+
onInbound: (facts) => inbound.note({
|
|
100
|
+
method: facts.method,
|
|
101
|
+
...(facts.source !== undefined ? { source: facts.source } : {}),
|
|
102
|
+
taskIds: facts.taskIds,
|
|
103
|
+
streaming: facts.streaming,
|
|
104
|
+
}),
|
|
105
|
+
onTaskSettled: (taskId) => {
|
|
106
|
+
host.logger.info(`[a2a:${record.id}] task settled ${taskId}`);
|
|
107
|
+
inbound.settle(taskId);
|
|
108
|
+
},
|
|
109
|
+
});
|
|
110
|
+
const routes = new A2aRoutes(host.webServer, server, cardPath);
|
|
111
|
+
return {
|
|
112
|
+
id: record.id,
|
|
113
|
+
record,
|
|
114
|
+
card,
|
|
115
|
+
server,
|
|
116
|
+
routes,
|
|
117
|
+
inbound,
|
|
118
|
+
executors,
|
|
119
|
+
endpointPath,
|
|
120
|
+
cardPath,
|
|
121
|
+
dispose: () => {
|
|
122
|
+
routes.dispose();
|
|
123
|
+
void executors.disposeAll().catch(() => { });
|
|
124
|
+
},
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
/** Persisted-instance store over the inbound_servers table. */
|
|
128
|
+
export class DomainInboundStore {
|
|
129
|
+
table;
|
|
130
|
+
static KEY(id) {
|
|
131
|
+
return `in:${id}`;
|
|
132
|
+
}
|
|
133
|
+
constructor(table) {
|
|
134
|
+
this.table = table;
|
|
135
|
+
}
|
|
136
|
+
list() {
|
|
137
|
+
const out = [];
|
|
138
|
+
const entries = this.table.entries;
|
|
139
|
+
if (entries === undefined)
|
|
140
|
+
return out;
|
|
141
|
+
// Call through the table (method `this` stays bound); the real KvTable's
|
|
142
|
+
// `entries()` reads instance state.
|
|
143
|
+
for (const [key, raw] of entries.call(this.table)) {
|
|
144
|
+
if (!key.startsWith('in:'))
|
|
145
|
+
continue;
|
|
146
|
+
const parsed = safeParse(raw);
|
|
147
|
+
if (parsed !== undefined)
|
|
148
|
+
out.push(parsed);
|
|
149
|
+
}
|
|
150
|
+
return out;
|
|
151
|
+
}
|
|
152
|
+
get(id) {
|
|
153
|
+
const raw = this.table.get(DomainInboundStore.KEY(id));
|
|
154
|
+
return raw === undefined ? undefined : safeParse(raw);
|
|
155
|
+
}
|
|
156
|
+
async save(record) {
|
|
157
|
+
await this.table.put(DomainInboundStore.KEY(record.id), JSON.stringify(record));
|
|
158
|
+
}
|
|
159
|
+
async remove(id) {
|
|
160
|
+
await this.table.put(DomainInboundStore.KEY(id), '');
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
function safeParse(raw) {
|
|
164
|
+
try {
|
|
165
|
+
const parsed = JSON.parse(raw);
|
|
166
|
+
if (typeof parsed.id !== 'string' || typeof parsed.name !== 'string' || !Array.isArray(parsed.skills))
|
|
167
|
+
return undefined;
|
|
168
|
+
return parsed;
|
|
169
|
+
}
|
|
170
|
+
catch {
|
|
171
|
+
return undefined;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
/** Manages the live set of inbound server instances. */
|
|
175
|
+
export class InboundServerManager {
|
|
176
|
+
host;
|
|
177
|
+
store;
|
|
178
|
+
live = new Map();
|
|
179
|
+
constructor(host, store) {
|
|
180
|
+
this.host = host;
|
|
181
|
+
this.store = store;
|
|
182
|
+
}
|
|
183
|
+
/** Assemble every persisted enabled instance (boot). */
|
|
184
|
+
boot() {
|
|
185
|
+
for (const record of this.store.list()) {
|
|
186
|
+
try {
|
|
187
|
+
const live = assemble(record, this.host);
|
|
188
|
+
this.live.set(record.id, live);
|
|
189
|
+
if (record.enabled)
|
|
190
|
+
live.routes.enable();
|
|
191
|
+
}
|
|
192
|
+
catch (err) {
|
|
193
|
+
this.host.logger.error(`[a2a:${record.id}] failed to assemble: ${String(err.message)}`);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
list() {
|
|
198
|
+
return [...this.live.values()];
|
|
199
|
+
}
|
|
200
|
+
get(id) {
|
|
201
|
+
return this.live.get(id);
|
|
202
|
+
}
|
|
203
|
+
/** Resolve the display name of a preset id (undefined when unnamed/absent). */
|
|
204
|
+
async presetDisplayName(preset) {
|
|
205
|
+
if (preset === undefined || this.host.agentPresets === undefined)
|
|
206
|
+
return undefined;
|
|
207
|
+
try {
|
|
208
|
+
const resolved = await this.host.agentPresets.resolve(preset);
|
|
209
|
+
return resolved.name ?? resolved.id;
|
|
210
|
+
}
|
|
211
|
+
catch {
|
|
212
|
+
return undefined;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
/** Create, persist, and assemble a new inbound instance. */
|
|
216
|
+
async add(input) {
|
|
217
|
+
const id = this.newId(input.name);
|
|
218
|
+
if (this.live.has(id))
|
|
219
|
+
return { ok: false, message: `inbound server ${id} already exists` };
|
|
220
|
+
const presetName = await this.presetDisplayName(input.preset);
|
|
221
|
+
const record = {
|
|
222
|
+
id,
|
|
223
|
+
name: input.name,
|
|
224
|
+
description: input.description,
|
|
225
|
+
version: input.version,
|
|
226
|
+
endpointPath: input.endpointPath ?? `/a2a/${id}`,
|
|
227
|
+
...(input.preset !== undefined ? { preset: input.preset } : {}),
|
|
228
|
+
...(input.authTokenEnv !== undefined ? { authTokenEnv: input.authTokenEnv } : {}),
|
|
229
|
+
skills: [...defaultSkillFor(input.skills, presetName)],
|
|
230
|
+
enabled: input.enabled ?? true,
|
|
231
|
+
};
|
|
232
|
+
try {
|
|
233
|
+
const live = assemble(record, this.host);
|
|
234
|
+
await this.store.save(record);
|
|
235
|
+
this.live.set(id, live);
|
|
236
|
+
if (record.enabled)
|
|
237
|
+
live.routes.enable();
|
|
238
|
+
return { ok: true, message: `inbound server "${record.name}" created`, id };
|
|
239
|
+
}
|
|
240
|
+
catch (err) {
|
|
241
|
+
return { ok: false, message: `failed to create inbound server: ${String(err.message)}` };
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
/** Persist, rebuild, and apply a patch onto a live instance. */
|
|
245
|
+
async update(id, patch) {
|
|
246
|
+
const live = this.live.get(id);
|
|
247
|
+
const stored = this.store.get(id);
|
|
248
|
+
if (live === undefined || stored === undefined)
|
|
249
|
+
return { ok: false, message: `inbound server ${id} not found` };
|
|
250
|
+
const next = {
|
|
251
|
+
...stored,
|
|
252
|
+
name: patch.name ?? stored.name,
|
|
253
|
+
description: patch.description ?? stored.description,
|
|
254
|
+
version: patch.version ?? stored.version,
|
|
255
|
+
endpointPath: patch.endpointPath ?? stored.endpointPath,
|
|
256
|
+
...(patch.preset !== undefined ? { preset: patch.preset } : {}),
|
|
257
|
+
...(patch.authTokenEnv !== undefined ? { authTokenEnv: patch.authTokenEnv } : {}),
|
|
258
|
+
skills: patch.skills ?? stored.skills,
|
|
259
|
+
enabled: stored.enabled,
|
|
260
|
+
};
|
|
261
|
+
try {
|
|
262
|
+
await this.store.save(next);
|
|
263
|
+
const replaced = assemble(next, this.host);
|
|
264
|
+
// Preserve the route registration state while swapping runtime halves.
|
|
265
|
+
const wasEnabled = live.routes.active;
|
|
266
|
+
live.dispose();
|
|
267
|
+
this.live.set(id, replaced);
|
|
268
|
+
if (wasEnabled || next.enabled)
|
|
269
|
+
replaced.routes.enable();
|
|
270
|
+
return { ok: true, message: `inbound server ${id} updated` };
|
|
271
|
+
}
|
|
272
|
+
catch (err) {
|
|
273
|
+
return { ok: false, message: `failed to update inbound server: ${String(err.message)}` };
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
/** Enable/disable an instance's routes. */
|
|
277
|
+
setEnabled(id, enabled) {
|
|
278
|
+
const live = this.live.get(id);
|
|
279
|
+
if (live === undefined)
|
|
280
|
+
return { ok: false, message: `inbound server ${id} not found` };
|
|
281
|
+
if (enabled)
|
|
282
|
+
live.routes.enable();
|
|
283
|
+
else
|
|
284
|
+
live.routes.disable();
|
|
285
|
+
const stored = this.store.get(id);
|
|
286
|
+
if (stored !== undefined) {
|
|
287
|
+
void this.store.save({ ...stored, enabled }).catch(() => { });
|
|
288
|
+
}
|
|
289
|
+
return { ok: true, message: `inbound server ${id} ${enabled ? 'enabled' : 'disabled'}` };
|
|
290
|
+
}
|
|
291
|
+
/** Remove, dispose, and unpersist an instance. */
|
|
292
|
+
async remove(id) {
|
|
293
|
+
const live = this.live.get(id);
|
|
294
|
+
if (live === undefined)
|
|
295
|
+
return { ok: false, message: `inbound server ${id} not found` };
|
|
296
|
+
live.dispose();
|
|
297
|
+
this.live.delete(id);
|
|
298
|
+
await this.store.remove(id);
|
|
299
|
+
return { ok: true, message: `inbound server ${id} removed` };
|
|
300
|
+
}
|
|
301
|
+
/** Dispose every instance. */
|
|
302
|
+
disposeAll() {
|
|
303
|
+
for (const live of this.live.values())
|
|
304
|
+
live.dispose();
|
|
305
|
+
this.live.clear();
|
|
306
|
+
}
|
|
307
|
+
newId(seed) {
|
|
308
|
+
const slug = seed.toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/^-+|-+$/g, '') || 'server';
|
|
309
|
+
return `${slug}-${this.host.newId()}`;
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
//# sourceMappingURL=inbound-manager.js.map
|