@naylence/agent-sdk 0.3.12 → 0.3.14
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 +30 -0
- package/dist/browser/index.js +1283 -441
- package/dist/browser/index.js.map +1 -1
- package/dist/cjs/naylence/agent/agent-proxy.js.map +1 -1
- package/dist/cjs/naylence/agent/agent.js.map +1 -1
- package/dist/cjs/naylence/agent/background-task-agent.js.map +1 -1
- package/dist/cjs/naylence/agent/base-agent.js.map +1 -1
- package/dist/cjs/public-api.d.ts +7 -0
- package/dist/cjs/public-api.js +26 -0
- package/dist/cjs/public-api.js.map +1 -0
- package/dist/cjs/version.d.ts +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/esm/naylence/agent/agent-proxy.d.ts +148 -0
- package/dist/esm/naylence/agent/agent-proxy.js +130 -0
- package/dist/esm/naylence/agent/agent-proxy.js.map +1 -1
- package/dist/esm/naylence/agent/agent.d.ts +194 -2
- package/dist/esm/naylence/agent/agent.js +123 -0
- package/dist/esm/naylence/agent/agent.js.map +1 -1
- package/dist/esm/naylence/agent/background-task-agent.d.ts +164 -0
- package/dist/esm/naylence/agent/background-task-agent.js +150 -0
- package/dist/esm/naylence/agent/background-task-agent.js.map +1 -1
- package/dist/esm/naylence/agent/base-agent.d.ts +171 -0
- package/dist/esm/naylence/agent/base-agent.js +170 -1
- package/dist/esm/naylence/agent/base-agent.js.map +1 -1
- package/dist/esm/public-api.d.ts +15 -0
- package/dist/esm/public-api.js +16 -0
- package/dist/esm/public-api.js.map +1 -0
- package/dist/esm/version.d.ts +1 -1
- package/dist/esm/version.js +2 -2
- package/dist/types/naylence/agent/agent-proxy.d.ts +148 -0
- package/dist/types/naylence/agent/agent-proxy.d.ts.map +1 -1
- package/dist/types/naylence/agent/agent.d.ts +194 -2
- package/dist/types/naylence/agent/agent.d.ts.map +1 -1
- package/dist/types/naylence/agent/background-task-agent.d.ts +164 -0
- package/dist/types/naylence/agent/background-task-agent.d.ts.map +1 -1
- package/dist/types/naylence/agent/base-agent.d.ts +171 -0
- package/dist/types/naylence/agent/base-agent.d.ts.map +1 -1
- package/dist/types/public-api.d.ts +16 -0
- package/dist/types/public-api.d.ts.map +1 -0
- package/dist/types/version.d.ts +1 -1
- package/package.json +7 -2
|
@@ -1,36 +1,135 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agent proxy module for remote agent communication.
|
|
3
|
+
*
|
|
4
|
+
* An {@link AgentProxy} is a client-side handle for invoking methods on a remote
|
|
5
|
+
* agent. Use it when you need to call an agent that lives in another process,
|
|
6
|
+
* container, or network location.
|
|
7
|
+
*
|
|
8
|
+
* @remarks
|
|
9
|
+
* Create proxies via {@link Agent.remote}, {@link Agent.remoteByAddress}, or
|
|
10
|
+
* {@link Agent.remoteByCapabilities} rather than instantiating AgentProxy directly.
|
|
11
|
+
*
|
|
12
|
+
* @module
|
|
13
|
+
*/
|
|
1
14
|
import { FameAddress } from '@naylence/runtime';
|
|
2
15
|
import type { FameFabric } from '@naylence/runtime';
|
|
3
16
|
import type { FameEnvelope } from '@naylence/core';
|
|
4
17
|
import { type AgentCard, type AuthenticationInfo, type PushNotificationConfig, type Task, type TaskArtifactUpdateEvent, type TaskIdParams, type TaskPushNotificationConfig, type TaskQueryParams, type TaskSendParams, type TaskStatusUpdateEvent } from './a2a-types.js';
|
|
5
18
|
import { Agent, type Payload } from './agent.js';
|
|
19
|
+
/** @internal */
|
|
6
20
|
type RunTaskPayload = Payload;
|
|
21
|
+
/** @internal */
|
|
7
22
|
type AgentTaskResult<TAgent extends Agent> = Awaited<ReturnType<TAgent['runTask']>>;
|
|
23
|
+
/** @internal */
|
|
8
24
|
interface AgentProxyCtorOptions {
|
|
9
25
|
address?: FameAddress | string | null;
|
|
10
26
|
capabilities?: string[] | null;
|
|
11
27
|
intentNl?: string | null;
|
|
12
28
|
fabric: FameFabric;
|
|
13
29
|
}
|
|
30
|
+
/** @internal */
|
|
14
31
|
interface StreamOptions {
|
|
15
32
|
timeoutMs?: number | null;
|
|
16
33
|
maxItems?: number | null;
|
|
17
34
|
}
|
|
35
|
+
/**
|
|
36
|
+
* Client-side proxy for communicating with remote agents.
|
|
37
|
+
*
|
|
38
|
+
* AgentProxy implements the {@link Agent} interface, allowing you to call
|
|
39
|
+
* remote agents as if they were local objects. Method calls are serialized
|
|
40
|
+
* and sent over the Fame fabric.
|
|
41
|
+
*
|
|
42
|
+
* @remarks
|
|
43
|
+
* Do not instantiate AgentProxy directly. Use the factory methods on
|
|
44
|
+
* {@link Agent} to create proxies:
|
|
45
|
+
* - {@link Agent.remote} for flexible options
|
|
46
|
+
* - {@link Agent.remoteByAddress} for direct addressing
|
|
47
|
+
* - {@link Agent.remoteByCapabilities} for capability-based discovery
|
|
48
|
+
*
|
|
49
|
+
* The proxy also supports arbitrary RPC method calls. Any method not defined
|
|
50
|
+
* on the proxy class is forwarded as an RPC call to the remote agent.
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```typescript
|
|
54
|
+
* import { Agent } from '@naylence/agent-sdk';
|
|
55
|
+
*
|
|
56
|
+
* // Create a proxy to a remote agent
|
|
57
|
+
* const proxy = Agent.remoteByAddress('fame://calculator');
|
|
58
|
+
*
|
|
59
|
+
* // Run a task synchronously
|
|
60
|
+
* const result = await proxy.runTask({ a: 1, b: 2 });
|
|
61
|
+
*
|
|
62
|
+
* // Or start a task and poll for completion
|
|
63
|
+
* const task = await proxy.startTask({
|
|
64
|
+
* id: 'task-1',
|
|
65
|
+
* message: { role: 'user', parts: [{ type: 'text', text: 'compute' }] },
|
|
66
|
+
* });
|
|
67
|
+
* ```
|
|
68
|
+
*
|
|
69
|
+
* @typeParam TAgent - The type of the remote agent for result typing.
|
|
70
|
+
*/
|
|
18
71
|
export declare class AgentProxy<TAgent extends Agent = Agent> extends Agent {
|
|
72
|
+
/** @internal */
|
|
19
73
|
private readonly targetAddress;
|
|
74
|
+
/** @internal */
|
|
20
75
|
private readonly targetCapabilities;
|
|
76
|
+
/** @internal */
|
|
21
77
|
private readonly intentNl;
|
|
78
|
+
/** @internal */
|
|
22
79
|
private readonly fabric;
|
|
80
|
+
/**
|
|
81
|
+
* Index signature allowing arbitrary RPC method calls.
|
|
82
|
+
* Methods not defined on AgentProxy are forwarded to the remote agent.
|
|
83
|
+
*/
|
|
23
84
|
[key: string]: any;
|
|
85
|
+
/** @internal */
|
|
24
86
|
constructor(options: AgentProxyCtorOptions);
|
|
87
|
+
/** Returns null as proxies do not have a local name. */
|
|
25
88
|
get name(): string | null;
|
|
89
|
+
/** Returns the proxy's targeting specification. */
|
|
26
90
|
get spec(): Record<string, unknown>;
|
|
91
|
+
/**
|
|
92
|
+
* The target agent's address, if specified.
|
|
93
|
+
* @deprecated Use {@link AgentProxy.address} instead.
|
|
94
|
+
*/
|
|
27
95
|
get addressRef(): FameAddress | null;
|
|
96
|
+
/** The target agent's address, if specified. */
|
|
28
97
|
get address(): FameAddress | null;
|
|
98
|
+
/** The required capabilities for discovery, if specified. */
|
|
29
99
|
get capabilities(): string[] | undefined;
|
|
100
|
+
/** The fabric this proxy uses for communication. */
|
|
30
101
|
get proxyFabric(): FameFabric;
|
|
31
102
|
getAgentCard(): Promise<AgentCard>;
|
|
32
103
|
authenticate(_credentials: AuthenticationInfo): boolean;
|
|
104
|
+
/**
|
|
105
|
+
* Executes a task on the remote agent and waits for completion.
|
|
106
|
+
*
|
|
107
|
+
* Starts the task, subscribes to updates, and returns when the task reaches
|
|
108
|
+
* a terminal state (completed, failed, or canceled).
|
|
109
|
+
*
|
|
110
|
+
* @param payload - The task payload to send.
|
|
111
|
+
* @param id - Optional task identifier. Generated if not provided.
|
|
112
|
+
* @returns The task result extracted from the final status message.
|
|
113
|
+
* @throws Error if the task fails.
|
|
114
|
+
*
|
|
115
|
+
* @example
|
|
116
|
+
* ```typescript
|
|
117
|
+
* const proxy = Agent.remoteByAddress('fame://echo');
|
|
118
|
+
* const result = await proxy.runTask('hello');
|
|
119
|
+
* console.log(result); // 'hello'
|
|
120
|
+
* ```
|
|
121
|
+
*/
|
|
33
122
|
runTask(payload?: RunTaskPayload, id?: string | null): Promise<AgentTaskResult<TAgent>>;
|
|
123
|
+
/**
|
|
124
|
+
* Initiates a task on the remote agent.
|
|
125
|
+
*
|
|
126
|
+
* Returns immediately with the initial task status. Use
|
|
127
|
+
* {@link AgentProxy.subscribeToTaskUpdates} or polling with
|
|
128
|
+
* {@link AgentProxy.getTaskStatus} to track progress.
|
|
129
|
+
*
|
|
130
|
+
* @param params - Task parameters or convenience options.
|
|
131
|
+
* @returns The created task with initial status.
|
|
132
|
+
*/
|
|
34
133
|
startTask(params: TaskSendParams): Promise<Task>;
|
|
35
134
|
startTask(options: {
|
|
36
135
|
id: string;
|
|
@@ -42,17 +141,66 @@ export declare class AgentProxy<TAgent extends Agent = Agent> extends Agent {
|
|
|
42
141
|
historyLength?: number | null;
|
|
43
142
|
metadata?: Record<string, unknown> | null;
|
|
44
143
|
}): Promise<Task>;
|
|
144
|
+
/**
|
|
145
|
+
* Retrieves the current status of a task.
|
|
146
|
+
*
|
|
147
|
+
* @param params - Query parameters including the task ID.
|
|
148
|
+
* @returns The task with current status.
|
|
149
|
+
*/
|
|
45
150
|
getTaskStatus(params: TaskQueryParams): Promise<Task>;
|
|
151
|
+
/**
|
|
152
|
+
* Requests cancellation of a running task.
|
|
153
|
+
*
|
|
154
|
+
* @param params - Parameters including the task ID.
|
|
155
|
+
* @returns The task with updated status.
|
|
156
|
+
*/
|
|
46
157
|
cancelTask(params: TaskIdParams): Promise<Task>;
|
|
158
|
+
/**
|
|
159
|
+
* Subscribes to real-time updates for a task.
|
|
160
|
+
*
|
|
161
|
+
* Returns an async iterable that yields status and artifact events
|
|
162
|
+
* until the task reaches a terminal state or the stream is closed.
|
|
163
|
+
*
|
|
164
|
+
* @param params - Task parameters.
|
|
165
|
+
* @param options - Optional timeout and item limit settings.
|
|
166
|
+
* @returns Async iterable of task events.
|
|
167
|
+
*/
|
|
47
168
|
subscribeToTaskUpdates(params: TaskSendParams, options?: StreamOptions): AsyncIterable<TaskStatusUpdateEvent | TaskArtifactUpdateEvent>;
|
|
169
|
+
/**
|
|
170
|
+
* Cancels a task subscription.
|
|
171
|
+
*
|
|
172
|
+
* @param params - Parameters including the task ID.
|
|
173
|
+
*/
|
|
48
174
|
unsubscribeTask(params: TaskIdParams): Promise<unknown>;
|
|
175
|
+
/**
|
|
176
|
+
* Registers a push notification endpoint for task updates.
|
|
177
|
+
*
|
|
178
|
+
* @param config - Push notification configuration.
|
|
179
|
+
* @returns The registered configuration.
|
|
180
|
+
*/
|
|
49
181
|
registerPushEndpoint(config: TaskPushNotificationConfig): Promise<TaskPushNotificationConfig>;
|
|
182
|
+
/**
|
|
183
|
+
* Retrieves the push notification config for a task.
|
|
184
|
+
*
|
|
185
|
+
* @param params - Parameters including the task ID.
|
|
186
|
+
* @returns The push notification configuration.
|
|
187
|
+
*/
|
|
50
188
|
getPushNotificationConfig(params: TaskIdParams): Promise<TaskPushNotificationConfig>;
|
|
189
|
+
/** @internal */
|
|
51
190
|
private _streamRpc;
|
|
191
|
+
/** @internal */
|
|
52
192
|
private _invokeTarget;
|
|
193
|
+
/**
|
|
194
|
+
* Creates a proxy for a remote agent by address.
|
|
195
|
+
* @internal Use {@link Agent.remoteByAddress} instead.
|
|
196
|
+
*/
|
|
53
197
|
static remoteByAddress<TAgent extends Agent>(address: FameAddress, options: {
|
|
54
198
|
fabric: FameFabric;
|
|
55
199
|
}): AgentProxy<TAgent>;
|
|
200
|
+
/**
|
|
201
|
+
* Creates a proxy for a remote agent by capabilities.
|
|
202
|
+
* @internal Use {@link Agent.remoteByCapabilities} instead.
|
|
203
|
+
*/
|
|
56
204
|
static remoteByCapabilities<TAgent extends Agent>(capabilities: string[], options: {
|
|
57
205
|
fabric: FameFabric;
|
|
58
206
|
}): AgentProxy<TAgent>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent-proxy.d.ts","sourceRoot":"","sources":["../../../../src/naylence/agent/agent-proxy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAA8B,MAAM,mBAAmB,CAAC;AAC5E,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,EACL,KAAK,SAAS,EACd,KAAK,kBAAkB,EAEvB,KAAK,sBAAsB,EAC3B,KAAK,IAAI,EAET,KAAK,uBAAuB,EAE5B,KAAK,YAAY,EAEjB,KAAK,0BAA0B,EAE/B,KAAK,eAAe,EAEpB,KAAK,cAAc,EAInB,KAAK,qBAAqB,EAG3B,MAAM,gBAAgB,CAAC;AAIxB,OAAO,EAAE,KAAK,EAAE,KAAK,OAAO,EAAE,MAAM,YAAY,CAAC;AAEjD,KAAK,cAAc,GAAG,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"agent-proxy.d.ts","sourceRoot":"","sources":["../../../../src/naylence/agent/agent-proxy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,EAAE,WAAW,EAA8B,MAAM,mBAAmB,CAAC;AAC5E,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,EACL,KAAK,SAAS,EACd,KAAK,kBAAkB,EAEvB,KAAK,sBAAsB,EAC3B,KAAK,IAAI,EAET,KAAK,uBAAuB,EAE5B,KAAK,YAAY,EAEjB,KAAK,0BAA0B,EAE/B,KAAK,eAAe,EAEpB,KAAK,cAAc,EAInB,KAAK,qBAAqB,EAG3B,MAAM,gBAAgB,CAAC;AAIxB,OAAO,EAAE,KAAK,EAAE,KAAK,OAAO,EAAE,MAAM,YAAY,CAAC;AAEjD,gBAAgB;AAChB,KAAK,cAAc,GAAG,OAAO,CAAC;AAK9B,gBAAgB;AAChB,KAAK,eAAe,CAAC,MAAM,SAA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e,CAAC,MAAM,EAAE,YAAY,GAAG,OAAO,CAAC,OAAO,CAAC;IAK7D;;;;;OAKG;IACG,oBAAoB,CACxB,MAAM,EAAE,0BAA0B,GACjC,OAAO,CAAC,0BAA0B,CAAC;IAMtC;;;;;OAKG;IACG,yBAAyB,CAAC,MAAM,EAAE,YAAY,GAAG,OAAO,CAAC,0BAA0B,CAAC;IAM1F,gBAAgB;IAChB,OAAO,CAAC,UAAU;IAqFlB,gBAAgB;YACF,aAAa;IA4B3B;;;OAGG;IACH,MAAM,CAAC,eAAe,CAAC,MAAM,SAAS,KAAK,EACzC,OAAO,EAAE,WAAW,EACpB,OAAO,EAAE;QAAE,MAAM,EAAE,UAAU,CAAA;KAAE,GAC9B,UAAU,CAAC,MAAM,CAAC;IAKrB;;;OAGG;IACH,MAAM,CAAC,oBAAoB,CAAC,MAAM,SAAS,KAAK,EAC9C,YAAY,EAAE,MAAM,EAAE,EACtB,OAAO,EAAE;QAAE,MAAM,EAAE,UAAU,CAAA;KAAE,GAC9B,UAAU,CAAC,MAAM,CAAC;CAItB;AACD,YAAY,EAAE,YAAY,EAAE,CAAC"}
|
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agent module providing the abstract {@link Agent} class.
|
|
3
|
+
*
|
|
4
|
+
* An Agent is a self-contained unit of work that can receive tasks, process them,
|
|
5
|
+
* and return results. Agents communicate over the Fame fabric using a standard
|
|
6
|
+
* task-based protocol.
|
|
7
|
+
*
|
|
8
|
+
* @remarks
|
|
9
|
+
* For concrete implementations:
|
|
10
|
+
* - Use {@link BaseAgent} when you need full control over task handling and state.
|
|
11
|
+
* - Use {@link BackgroundTaskAgent} for long-running or async background work.
|
|
12
|
+
*
|
|
13
|
+
* @module
|
|
14
|
+
*/
|
|
1
15
|
import { FameAddress, FameFabric, LogLevel } from '@naylence/runtime';
|
|
2
16
|
import { RpcMixin } from '@naylence/runtime';
|
|
3
17
|
import type { FameService } from '@naylence/core';
|
|
@@ -6,25 +20,57 @@ export { registerAgentProxyFactory } from './agent-proxy-registry.js';
|
|
|
6
20
|
export type { AgentProxyConstructor } from './agent-proxy-registry.js';
|
|
7
21
|
import type { BaseAgent } from './base-agent.js';
|
|
8
22
|
import type { AgentProxy } from './agent-proxy.js';
|
|
23
|
+
/**
|
|
24
|
+
* Payload type for agent task messages.
|
|
25
|
+
*
|
|
26
|
+
* Can be a JSON object, a string, or null.
|
|
27
|
+
*/
|
|
9
28
|
export type Payload = Record<string, unknown> | string | null;
|
|
29
|
+
/**
|
|
30
|
+
* Collection of address-payload pairs for broadcasting tasks to multiple agents.
|
|
31
|
+
*/
|
|
10
32
|
export type Targets = Iterable<readonly [FameAddress | string, Payload]>;
|
|
33
|
+
/** @internal */
|
|
11
34
|
type AgentTaskHandler = (payload: Payload, id: string | null) => unknown | Promise<unknown>;
|
|
35
|
+
/**
|
|
36
|
+
* Constructor signature for BaseAgent implementations.
|
|
37
|
+
* @internal
|
|
38
|
+
*/
|
|
12
39
|
export type BaseAgentConstructor = new (name?: string | null, options?: any) => BaseAgent;
|
|
13
40
|
/** @internal */
|
|
14
41
|
export declare function registerBaseAgentConstructor(ctor: BaseAgentConstructor): void;
|
|
42
|
+
/**
|
|
43
|
+
* Options for creating a remote agent proxy.
|
|
44
|
+
*
|
|
45
|
+
* Provide exactly one of `address` or `capabilities` to identify the target.
|
|
46
|
+
*/
|
|
15
47
|
export interface AgentRemoteOptions {
|
|
48
|
+
/** Direct address of the target agent. */
|
|
16
49
|
address?: FameAddress | string;
|
|
50
|
+
/** Required capabilities for capability-based discovery. */
|
|
17
51
|
capabilities?: string[];
|
|
52
|
+
/** Fabric instance to use. Defaults to the current fabric. */
|
|
18
53
|
fabric?: FameFabric;
|
|
19
54
|
}
|
|
55
|
+
/**
|
|
56
|
+
* Options for running tasks on multiple agents.
|
|
57
|
+
*/
|
|
20
58
|
export interface AgentRunManyOptions {
|
|
59
|
+
/** Fabric instance to use. Defaults to the current fabric. */
|
|
21
60
|
fabric?: FameFabric;
|
|
61
|
+
/**
|
|
62
|
+
* If true (default), errors are collected alongside results.
|
|
63
|
+
* If false, the first error rejects the promise.
|
|
64
|
+
*/
|
|
22
65
|
gatherExceptions?: boolean;
|
|
23
66
|
}
|
|
67
|
+
/**
|
|
68
|
+
* Options for serving an agent at a given address.
|
|
69
|
+
*/
|
|
24
70
|
export interface AgentServeOptions {
|
|
25
71
|
/**
|
|
26
|
-
* Log level for the agent.
|
|
27
|
-
*
|
|
72
|
+
* Log level for the agent.
|
|
73
|
+
* Accepts 'debug', 'info', 'warning', 'error', 'critical', or a LogLevel value.
|
|
28
74
|
*/
|
|
29
75
|
logLevel?: string | number | LogLevel | null;
|
|
30
76
|
/**
|
|
@@ -40,31 +86,177 @@ export interface AgentServeOptions {
|
|
|
40
86
|
*/
|
|
41
87
|
[key: string]: unknown;
|
|
42
88
|
}
|
|
89
|
+
/**
|
|
90
|
+
* Abstract base class for all agents.
|
|
91
|
+
*
|
|
92
|
+
* Agents are addressable services that handle tasks over the Fame fabric.
|
|
93
|
+
* This class defines the core protocol methods every agent must implement.
|
|
94
|
+
*
|
|
95
|
+
* @remarks
|
|
96
|
+
* Do not extend Agent directly. Instead:
|
|
97
|
+
* - Extend {@link BaseAgent} for standard request-response agents.
|
|
98
|
+
* - Extend {@link BackgroundTaskAgent} for long-running background work.
|
|
99
|
+
*
|
|
100
|
+
* Use {@link Agent.remote} or {@link Agent.remoteByAddress} to create proxies
|
|
101
|
+
* for communicating with remote agents.
|
|
102
|
+
*
|
|
103
|
+
* @example
|
|
104
|
+
* ```typescript
|
|
105
|
+
* import { BaseAgent, Payload } from '@naylence/agent-sdk';
|
|
106
|
+
*
|
|
107
|
+
* class EchoAgent extends BaseAgent {
|
|
108
|
+
* async runTask(payload: Payload): Promise<Payload> {
|
|
109
|
+
* return payload;
|
|
110
|
+
* }
|
|
111
|
+
* }
|
|
112
|
+
*
|
|
113
|
+
* const agent = new EchoAgent('echo');
|
|
114
|
+
* await agent.serve('fame://echo');
|
|
115
|
+
* ```
|
|
116
|
+
*/
|
|
43
117
|
export declare abstract class Agent extends RpcMixin implements FameService {
|
|
118
|
+
/**
|
|
119
|
+
* Capabilities advertised by this agent for discovery.
|
|
120
|
+
*/
|
|
44
121
|
get capabilities(): string[] | undefined;
|
|
122
|
+
/** The agent's name, used for logging and identification. */
|
|
45
123
|
abstract get name(): string | null;
|
|
124
|
+
/** Returns metadata about this agent (address, capabilities, etc.). */
|
|
46
125
|
abstract get spec(): Record<string, unknown>;
|
|
126
|
+
/** Returns the agent's card describing its capabilities and metadata. */
|
|
47
127
|
abstract getAgentCard(): Promise<AgentCard>;
|
|
128
|
+
/**
|
|
129
|
+
* Validates authentication credentials.
|
|
130
|
+
* @param credentials - The credentials to validate.
|
|
131
|
+
* @returns True if authentication succeeds.
|
|
132
|
+
*/
|
|
48
133
|
abstract authenticate(credentials: AuthenticationInfo): boolean;
|
|
134
|
+
/**
|
|
135
|
+
* Initiates a new task.
|
|
136
|
+
* @param params - Task parameters including message and optional metadata.
|
|
137
|
+
* @returns The created task with its initial status.
|
|
138
|
+
*/
|
|
49
139
|
abstract startTask(params: TaskSendParams): Promise<Task>;
|
|
140
|
+
/**
|
|
141
|
+
* Executes a task synchronously and returns the result.
|
|
142
|
+
* @param payload - The task payload.
|
|
143
|
+
* @param id - Optional task identifier.
|
|
144
|
+
* @returns The task result.
|
|
145
|
+
*/
|
|
50
146
|
abstract runTask(payload: Payload, id: string | null): Promise<any>;
|
|
147
|
+
/**
|
|
148
|
+
* Retrieves the current status of a task.
|
|
149
|
+
* @param params - Query parameters including the task ID.
|
|
150
|
+
*/
|
|
51
151
|
abstract getTaskStatus(params: TaskQueryParams): Promise<Task>;
|
|
152
|
+
/**
|
|
153
|
+
* Requests cancellation of a running task.
|
|
154
|
+
* @param params - Parameters including the task ID.
|
|
155
|
+
* @returns The task with updated status.
|
|
156
|
+
*/
|
|
52
157
|
abstract cancelTask(params: TaskIdParams): Promise<Task>;
|
|
158
|
+
/**
|
|
159
|
+
* Subscribes to real-time updates for a task.
|
|
160
|
+
* @param params - Task parameters.
|
|
161
|
+
* @returns An async iterable of status and artifact update events.
|
|
162
|
+
*/
|
|
53
163
|
abstract subscribeToTaskUpdates(params: TaskSendParams): AsyncIterable<TaskStatusUpdateEvent | TaskArtifactUpdateEvent>;
|
|
164
|
+
/**
|
|
165
|
+
* Cancels a task subscription.
|
|
166
|
+
* @param params - Parameters including the task ID.
|
|
167
|
+
*/
|
|
54
168
|
abstract unsubscribeTask(params: TaskIdParams): Promise<any>;
|
|
169
|
+
/**
|
|
170
|
+
* Registers a push notification endpoint for task updates.
|
|
171
|
+
* @param config - Push notification configuration.
|
|
172
|
+
*/
|
|
55
173
|
abstract registerPushEndpoint(config: TaskPushNotificationConfig): Promise<TaskPushNotificationConfig>;
|
|
174
|
+
/**
|
|
175
|
+
* Retrieves the push notification config for a task.
|
|
176
|
+
* @param params - Parameters including the task ID.
|
|
177
|
+
*/
|
|
56
178
|
abstract getPushNotificationConfig(params: TaskIdParams): Promise<TaskPushNotificationConfig>;
|
|
179
|
+
/**
|
|
180
|
+
* Creates a proxy for communicating with a remote agent.
|
|
181
|
+
*
|
|
182
|
+
* @remarks
|
|
183
|
+
* Provide exactly one of `address` or `capabilities` in the options.
|
|
184
|
+
*
|
|
185
|
+
* @example
|
|
186
|
+
* ```typescript
|
|
187
|
+
* const proxy = Agent.remote<EchoAgent>({ address: 'fame://echo' });
|
|
188
|
+
* const result = await proxy.runTask('hello');
|
|
189
|
+
* ```
|
|
190
|
+
*
|
|
191
|
+
* @param options - Remote agent options.
|
|
192
|
+
* @returns A proxy for the remote agent.
|
|
193
|
+
* @throws Error if both or neither of address/capabilities are provided.
|
|
194
|
+
*/
|
|
57
195
|
static remote<TAgent extends Agent>(this: typeof Agent, options: AgentRemoteOptions): AgentProxy<TAgent>;
|
|
196
|
+
/**
|
|
197
|
+
* Creates a proxy for a remote agent by its address.
|
|
198
|
+
*
|
|
199
|
+
* @param address - The target agent's address.
|
|
200
|
+
* @param options - Optional fabric configuration.
|
|
201
|
+
* @returns A proxy for the remote agent.
|
|
202
|
+
*/
|
|
58
203
|
static remoteByAddress<TAgent extends Agent>(this: typeof Agent, address: FameAddress | string, options?: {
|
|
59
204
|
fabric?: FameFabric;
|
|
60
205
|
}): AgentProxy<TAgent>;
|
|
206
|
+
/**
|
|
207
|
+
* Creates a proxy for a remote agent by required capabilities.
|
|
208
|
+
*
|
|
209
|
+
* @param capabilities - Required capabilities for discovery.
|
|
210
|
+
* @param options - Optional fabric configuration.
|
|
211
|
+
* @returns A proxy for a matching remote agent.
|
|
212
|
+
*/
|
|
61
213
|
static remoteByCapabilities<TAgent extends Agent>(this: typeof Agent, capabilities: string[], options?: {
|
|
62
214
|
fabric?: FameFabric;
|
|
63
215
|
}): AgentProxy<TAgent>;
|
|
216
|
+
/**
|
|
217
|
+
* Creates an agent from a simple handler function.
|
|
218
|
+
*
|
|
219
|
+
* @remarks
|
|
220
|
+
* Useful for quick prototyping without defining a full agent class.
|
|
221
|
+
*
|
|
222
|
+
* @param handler - Function that processes task payloads.
|
|
223
|
+
* @returns A new agent instance wrapping the handler.
|
|
224
|
+
*/
|
|
64
225
|
static fromHandler(handler: AgentTaskHandler): Promise<Agent>;
|
|
226
|
+
/**
|
|
227
|
+
* Sends the same payload to multiple agents.
|
|
228
|
+
*
|
|
229
|
+
* @param addresses - List of agent addresses.
|
|
230
|
+
* @param payload - Payload to send to all agents.
|
|
231
|
+
* @param options - Execution options.
|
|
232
|
+
* @returns Array of [address, result|error] tuples.
|
|
233
|
+
*/
|
|
65
234
|
static broadcast(this: typeof Agent, addresses: Array<FameAddress | string>, payload?: Payload, options?: AgentRunManyOptions): Promise<Array<[string, any | Error]>>;
|
|
235
|
+
/**
|
|
236
|
+
* Runs tasks on multiple agents with individual payloads.
|
|
237
|
+
*
|
|
238
|
+
* @param targets - Iterable of [address, payload] pairs.
|
|
239
|
+
* @param options - Execution options.
|
|
240
|
+
* @returns Array of [address, result|error] tuples.
|
|
241
|
+
*/
|
|
66
242
|
static runMany<TAgent extends Agent>(this: typeof Agent, targets: Targets, options?: AgentRunManyOptions): Promise<Array<[string, any | Error]>>;
|
|
243
|
+
/**
|
|
244
|
+
* Starts serving this agent at the given address.
|
|
245
|
+
*
|
|
246
|
+
* @remarks
|
|
247
|
+
* In Node.js, the agent listens for SIGINT/SIGTERM to shut down gracefully.
|
|
248
|
+
* The method returns when the agent stops serving.
|
|
249
|
+
*
|
|
250
|
+
* @param address - The address to serve at (e.g., 'fame://my-agent').
|
|
251
|
+
* @param options - Serve options including log level and fabric config.
|
|
252
|
+
*/
|
|
67
253
|
aserve(address: FameAddress | string, options?: AgentServeOptions): Promise<void>;
|
|
254
|
+
/**
|
|
255
|
+
* Alias for {@link Agent.aserve}.
|
|
256
|
+
*
|
|
257
|
+
* @param address - The address to serve at.
|
|
258
|
+
* @param options - Serve options.
|
|
259
|
+
*/
|
|
68
260
|
serve(address: FameAddress | string, options?: AgentServeOptions): Promise<void>;
|
|
69
261
|
}
|
|
70
262
|
//# sourceMappingURL=agent.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../../../../src/naylence/agent/agent.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,UAAU,EAKV,QAAQ,EACT,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,KAAK,EACV,SAAS,EACT,kBAAkB,EAClB,IAAI,EACJ,uBAAuB,EACvB,YAAY,EACZ,0BAA0B,EAC1B,eAAe,EACf,cAAc,EACd,qBAAqB,EACtB,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAE,yBAAyB,EAAE,MAAM,2BAA2B,CAAC;AACtE,YAAY,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAEvE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