@artinet/sdk 0.6.0-preview.1 → 0.6.0-preview.2
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 +1 -1
- package/dist/browser/client/a2a-client.js +4 -4
- package/dist/browser/config/index.d.ts +1 -1
- package/dist/browser/config/index.js +1 -1
- package/dist/browser/create/agentcard-builder.d.ts +47 -0
- package/dist/browser/create/agentcard-builder.js +65 -0
- package/dist/browser/create/base.d.ts +4 -0
- package/dist/browser/create/base.js +1 -0
- package/dist/browser/create/describe.d.ts +8 -0
- package/dist/browser/create/describe.js +8 -0
- package/dist/browser/create/message-builder.d.ts +78 -0
- package/dist/browser/create/message-builder.js +108 -0
- package/dist/browser/create/part-builder.d.ts +60 -0
- package/dist/browser/create/part-builder.js +81 -0
- package/dist/browser/create/task-builder.d.ts +251 -0
- package/dist/browser/create/task-builder.js +379 -0
- package/dist/browser/transport/rpc/parser.d.ts +1 -1
- package/dist/browser/transport/rpc/parser.js +2 -1
- package/dist/browser/types/a2a/a2a.d.ts +7 -3
- package/dist/browser/types/a2a/index.d.ts +3 -1
- package/dist/browser/types/a2a/index.js +0 -1
- package/dist/browser/utils/common/constants.d.ts +0 -5
- package/dist/browser/utils/common/constants.js +0 -27
- package/dist/browser/utils/common/errors.d.ts +57 -1
- package/dist/browser/utils/common/errors.js +68 -15
- package/dist/client/a2a-client.js +4 -4
- package/dist/config/default.d.ts +1 -1
- package/dist/config/default.js +1 -1
- package/dist/config/index.d.ts +1 -1
- package/dist/config/index.js +1 -1
- package/dist/create/agent-builder.d.ts +77 -0
- package/dist/create/agent-builder.js +20 -0
- package/dist/create/agentcard-builder.d.ts +47 -0
- package/dist/create/agentcard-builder.js +66 -0
- package/dist/create/base.d.ts +4 -0
- package/dist/create/base.js +1 -0
- package/dist/create/create.d.ts +762 -0
- package/dist/create/create.js +556 -0
- package/dist/create/describe.d.ts +8 -0
- package/dist/create/describe.js +8 -0
- package/dist/create/index.d.ts +4 -0
- package/dist/create/index.js +4 -0
- package/dist/create/message-builder.d.ts +78 -0
- package/dist/create/message-builder.js +110 -0
- package/dist/create/part-builder.d.ts +60 -0
- package/dist/create/part-builder.js +84 -0
- package/dist/create/status-builder.d.ts +26 -0
- package/dist/create/status-builder.js +46 -0
- package/dist/create/task-builder.d.ts +251 -0
- package/dist/create/task-builder.js +384 -0
- package/dist/create/transform.d.ts +16 -0
- package/dist/create/transform.js +106 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/server/express/errors.js +4 -8
- package/dist/server/express/middeware.js +17 -38
- package/dist/server/express/server.d.ts +6 -1
- package/dist/server/express/server.js +30 -12
- package/dist/services/a2a/execute.d.ts +5 -0
- package/dist/services/a2a/execute.js +7 -0
- package/dist/services/a2a/factory/context.d.ts +1 -1
- package/dist/services/a2a/factory/context.js +2 -3
- package/dist/services/a2a/factory/handler.js +3 -3
- package/dist/services/a2a/factory/index.d.ts +0 -1
- package/dist/services/a2a/factory/index.js +0 -1
- package/dist/services/a2a/factory/service.d.ts +2 -2
- package/dist/services/a2a/factory/service.js +2 -2
- package/dist/services/a2a/factory/state-machine.d.ts +1 -1
- package/dist/services/a2a/factory/state-machine.js +30 -8
- package/dist/services/a2a/handlers/artifact.d.ts +2 -5
- package/dist/services/a2a/handlers/artifact.js +21 -32
- package/dist/services/a2a/handlers/cancel-task.js +7 -5
- package/dist/services/a2a/handlers/resubscribe-task.d.ts +10 -2
- package/dist/services/a2a/handlers/resubscribe-task.js +21 -18
- package/dist/services/a2a/handlers/send-message.js +6 -10
- package/dist/services/a2a/handlers/stream-message.d.ts +10 -2
- package/dist/services/a2a/handlers/stream-message.js +5 -1
- package/dist/services/a2a/handlers/update.js +11 -6
- package/dist/services/a2a/helpers/content.d.ts +5 -1
- package/dist/services/a2a/helpers/content.js +5 -1
- package/dist/services/a2a/helpers/index.d.ts +2 -2
- package/dist/services/a2a/helpers/index.js +2 -2
- package/dist/services/a2a/index.d.ts +1 -1
- package/dist/services/a2a/index.js +1 -1
- package/dist/services/a2a/managers.js +7 -1
- package/dist/services/a2a/service.d.ts +6 -2
- package/dist/services/a2a/service.js +52 -59
- package/dist/services/a2a/state-machine.d.ts +3 -3
- package/dist/services/a2a/state-machine.js +2 -0
- package/dist/transport/rpc/parser.d.ts +1 -1
- package/dist/transport/rpc/parser.js +2 -1
- package/dist/types/a2a/a2a.d.ts +7 -3
- package/dist/types/a2a/index.d.ts +3 -1
- package/dist/types/a2a/index.js +0 -1
- package/dist/utils/common/constants.d.ts +0 -5
- package/dist/utils/common/constants.js +0 -27
- package/dist/utils/common/errors.d.ts +57 -1
- package/dist/utils/common/errors.js +68 -15
- package/dist/utils/common/parse.d.ts +1 -1
- package/dist/utils/common/schema-validation.d.ts +1 -1
- package/package.json +7 -4
- package/dist/browser/services/a2a/helpers/message-builder.d.ts +0 -17
- package/dist/browser/services/a2a/helpers/message-builder.js +0 -66
- package/dist/browser/types/a2a/builder.d.ts +0 -43
- package/dist/browser/types/a2a/builder.js +0 -5
- package/dist/services/a2a/factory/builder.d.ts +0 -292
- package/dist/services/a2a/factory/builder.js +0 -370
- package/dist/services/a2a/helpers/agentcard-builder.d.ts +0 -11
- package/dist/services/a2a/helpers/agentcard-builder.js +0 -27
- package/dist/services/a2a/helpers/message-builder.d.ts +0 -17
- package/dist/services/a2a/helpers/message-builder.js +0 -66
- package/dist/types/a2a/builder.d.ts +0 -43
- package/dist/types/a2a/builder.js +0 -5
|
@@ -1,370 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright 2025 The Artinet Project
|
|
3
|
-
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* @fileoverview A2A Agent Builder and Execution Engine Factory
|
|
7
|
-
*
|
|
8
|
-
* This module provides a fluent builder API for constructing A2A agents and
|
|
9
|
-
* execution engines. It enables declarative definition of multi-step agent
|
|
10
|
-
* workflows with type-safe step composition and automatic execution orchestration.
|
|
11
|
-
*
|
|
12
|
-
* @module A2ABuilder
|
|
13
|
-
* @version 0.6.0-preview
|
|
14
|
-
* @since 0.5.6
|
|
15
|
-
* @author The Artinet Project
|
|
16
|
-
*/
|
|
17
|
-
import { A2A, } from "../../../types/index.js";
|
|
18
|
-
import { createAgent } from "./service.js";
|
|
19
|
-
import { v4 as uuidv4 } from "uuid";
|
|
20
|
-
import { getContent } from "../helpers/content.js";
|
|
21
|
-
import { SUBMITTED_UPDATE, WORKING_UPDATE } from "../../../utils/index.js";
|
|
22
|
-
/**
|
|
23
|
-
* Fluent builder for constructing A2A agent execution engines.
|
|
24
|
-
*
|
|
25
|
-
* The EngineBuilder provides a type-safe, fluent API for composing multi-step
|
|
26
|
-
* agent workflows. It supports method chaining to build complex agent behaviors
|
|
27
|
-
* from individual processing steps, with automatic type inference and validation.
|
|
28
|
-
*
|
|
29
|
-
* @template TCommand - The command type, defaults to MessageSendParams
|
|
30
|
-
* @template TInboundArgs - The arguments type received from previous steps
|
|
31
|
-
*
|
|
32
|
-
* @example
|
|
33
|
-
* ```typescript
|
|
34
|
-
* const agent = EngineBuilder.create()
|
|
35
|
-
* .text(async ({ command }) => {
|
|
36
|
-
* return `Processing: ${command.message.content}`;
|
|
37
|
-
* })
|
|
38
|
-
* .data(async ({ args }) => {
|
|
39
|
-
* return { processed: true, timestamp: Date.now() };
|
|
40
|
-
* })
|
|
41
|
-
* .text(async ({ args }) => {
|
|
42
|
-
* return `Completed at ${new Date(args[0].timestamp)}`;
|
|
43
|
-
* })
|
|
44
|
-
* .createAgent({ agentCard: myAgentCard });
|
|
45
|
-
* ```
|
|
46
|
-
*
|
|
47
|
-
* @public
|
|
48
|
-
* @since 0.5.6
|
|
49
|
-
*/
|
|
50
|
-
export class EngineBuilder {
|
|
51
|
-
//@typescript-eslint/no-explicit-any
|
|
52
|
-
steps = [];
|
|
53
|
-
/**
|
|
54
|
-
* Protected constructor to enforce factory method usage.
|
|
55
|
-
*
|
|
56
|
-
* @param steps - Initial steps array
|
|
57
|
-
*/
|
|
58
|
-
constructor(
|
|
59
|
-
//@typescript-eslint/no-explicit-any
|
|
60
|
-
steps = []) {
|
|
61
|
-
this.steps = steps;
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* Creates a new EngineBuilder instance.
|
|
65
|
-
*
|
|
66
|
-
* @template TCommand - The command type for the builder
|
|
67
|
-
* @template TInboundArgs - The initial arguments type
|
|
68
|
-
* @returns A new EngineBuilder instance
|
|
69
|
-
*
|
|
70
|
-
* @example
|
|
71
|
-
* ```typescript
|
|
72
|
-
* const builder = EngineBuilder.create<MyCommand, [string, number]>();
|
|
73
|
-
* ```
|
|
74
|
-
*/
|
|
75
|
-
static create() {
|
|
76
|
-
return new EngineBuilder();
|
|
77
|
-
}
|
|
78
|
-
addStep(step) {
|
|
79
|
-
return new EngineBuilder([...this.steps, step]);
|
|
80
|
-
}
|
|
81
|
-
/**
|
|
82
|
-
* Adds a text processing step to the workflow.
|
|
83
|
-
*
|
|
84
|
-
* @template TPart - The text part type
|
|
85
|
-
* @template TForwardArgs - Arguments to forward to next step
|
|
86
|
-
* @template TOutput - The output type of the step
|
|
87
|
-
* @param step - The text step implementation
|
|
88
|
-
* @returns New builder instance with updated type parameters
|
|
89
|
-
*
|
|
90
|
-
* @example
|
|
91
|
-
* ```typescript
|
|
92
|
-
* builder.text(async ({ command, args }) => {
|
|
93
|
-
* return `Hello, ${command.message.content}!`;
|
|
94
|
-
* });
|
|
95
|
-
* ```
|
|
96
|
-
*/
|
|
97
|
-
text(step) {
|
|
98
|
-
return this.addStep({
|
|
99
|
-
step: typeof step === "string" ? () => step : step,
|
|
100
|
-
kind: "text",
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
/**
|
|
104
|
-
* Adds a file processing step to the workflow.
|
|
105
|
-
*
|
|
106
|
-
* @template TPart - The file part type
|
|
107
|
-
* @template TForwardArgs - Arguments to forward to next step
|
|
108
|
-
* @template TOutput - The output type of the step
|
|
109
|
-
* @param step - The file step implementation
|
|
110
|
-
* @returns New builder instance with updated type parameters
|
|
111
|
-
*
|
|
112
|
-
* @example
|
|
113
|
-
* ```typescript
|
|
114
|
-
* builder.file(async ({ command, args }) => {
|
|
115
|
-
* return {
|
|
116
|
-
* name: 'output.txt',
|
|
117
|
-
* mimeType: 'text/plain',
|
|
118
|
-
* bytes: Buffer.from(command.message.content)
|
|
119
|
-
* };
|
|
120
|
-
* });
|
|
121
|
-
* ```
|
|
122
|
-
*/
|
|
123
|
-
file(step) {
|
|
124
|
-
return this.addStep({
|
|
125
|
-
step: step,
|
|
126
|
-
kind: "file",
|
|
127
|
-
});
|
|
128
|
-
}
|
|
129
|
-
/**
|
|
130
|
-
* Adds a data processing step to the workflow.
|
|
131
|
-
*
|
|
132
|
-
* @template TPart - The data part type
|
|
133
|
-
* @template TForwardArgs - Arguments to forward to next step
|
|
134
|
-
* @template TOutput - The output type of the step
|
|
135
|
-
* @param step - The data step implementation
|
|
136
|
-
* @returns New builder instance with updated type parameters
|
|
137
|
-
*
|
|
138
|
-
* @example
|
|
139
|
-
* ```typescript
|
|
140
|
-
* builder.data(async ({ command, args }) => {
|
|
141
|
-
* return {
|
|
142
|
-
* analysis: analyzeText(command.message.content),
|
|
143
|
-
* timestamp: Date.now()
|
|
144
|
-
* };
|
|
145
|
-
* });
|
|
146
|
-
* ```
|
|
147
|
-
*/
|
|
148
|
-
data(step) {
|
|
149
|
-
return this.addStep({
|
|
150
|
-
step: step,
|
|
151
|
-
kind: "data",
|
|
152
|
-
});
|
|
153
|
-
}
|
|
154
|
-
/**
|
|
155
|
-
* Creates a complete A2A agent using the built workflow.
|
|
156
|
-
*
|
|
157
|
-
* @param params - Agent factory parameters (excluding engine)
|
|
158
|
-
* @returns Configured A2A agent instance
|
|
159
|
-
*
|
|
160
|
-
* @example
|
|
161
|
-
* ```typescript
|
|
162
|
-
* const agent = builder.createAgent({
|
|
163
|
-
* agentCard: {
|
|
164
|
-
* id: 'my-agent',
|
|
165
|
-
* name: 'Assistant Agent',
|
|
166
|
-
* capabilities: ['text-processing']
|
|
167
|
-
* }
|
|
168
|
-
* });
|
|
169
|
-
* ```
|
|
170
|
-
*/
|
|
171
|
-
createAgent(params) {
|
|
172
|
-
return createAgent({
|
|
173
|
-
...params,
|
|
174
|
-
engine: this.createAgentEngine(),
|
|
175
|
-
});
|
|
176
|
-
}
|
|
177
|
-
/**
|
|
178
|
-
* Creates an agent execution engine from the built workflow.
|
|
179
|
-
*
|
|
180
|
-
* @returns Agent execution engine function
|
|
181
|
-
*
|
|
182
|
-
* @example
|
|
183
|
-
* ```typescript
|
|
184
|
-
* const engine = builder.createAgentEngine();
|
|
185
|
-
* // Use engine with service execution
|
|
186
|
-
* ```
|
|
187
|
-
*/
|
|
188
|
-
createAgentEngine() {
|
|
189
|
-
return createAgentExecutor(this.build());
|
|
190
|
-
}
|
|
191
|
-
/**
|
|
192
|
-
* Builds the step list for the workflow.
|
|
193
|
-
*
|
|
194
|
-
* @returns Array of workflow steps
|
|
195
|
-
* @throws Error if no steps have been added
|
|
196
|
-
*
|
|
197
|
-
* @example
|
|
198
|
-
* ```typescript
|
|
199
|
-
* const steps = builder.build();
|
|
200
|
-
* ```
|
|
201
|
-
*/
|
|
202
|
-
build() {
|
|
203
|
-
if (this.steps.length === 0) {
|
|
204
|
-
throw new Error("No steps provided");
|
|
205
|
-
}
|
|
206
|
-
return this.steps;
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
/**
|
|
210
|
-
* Convenience factory function for creating an agent builder with default parameters.
|
|
211
|
-
*
|
|
212
|
-
* @returns New EngineBuilder instance with MessageSendParams command type
|
|
213
|
-
*
|
|
214
|
-
* @example
|
|
215
|
-
* ```typescript
|
|
216
|
-
* const agent = AgentBuilder()
|
|
217
|
-
* .text(async ({ command }) => `Hello ${command.message.content}!`)
|
|
218
|
-
* .createAgent({ agentCard: myCard });
|
|
219
|
-
* ```
|
|
220
|
-
*
|
|
221
|
-
* @public
|
|
222
|
-
* @since 0.5.6
|
|
223
|
-
*/
|
|
224
|
-
export const AgentBuilder = () => EngineBuilder.create();
|
|
225
|
-
const partToMessagePart = (kind, part) => {
|
|
226
|
-
switch (kind) {
|
|
227
|
-
case "text": {
|
|
228
|
-
return { kind: "text", text: part };
|
|
229
|
-
}
|
|
230
|
-
case "file": {
|
|
231
|
-
const filePart = part;
|
|
232
|
-
if (filePart.uri) {
|
|
233
|
-
return {
|
|
234
|
-
kind: "file",
|
|
235
|
-
file: {
|
|
236
|
-
uri: filePart.uri,
|
|
237
|
-
name: filePart.name,
|
|
238
|
-
mimeType: filePart.mimeType,
|
|
239
|
-
},
|
|
240
|
-
};
|
|
241
|
-
}
|
|
242
|
-
if (!filePart.bytes) {
|
|
243
|
-
throw new Error("File bytes are required when uri is not provided");
|
|
244
|
-
}
|
|
245
|
-
return {
|
|
246
|
-
kind: "file",
|
|
247
|
-
file: {
|
|
248
|
-
bytes: filePart.bytes,
|
|
249
|
-
name: filePart.name,
|
|
250
|
-
mimeType: filePart.mimeType,
|
|
251
|
-
},
|
|
252
|
-
};
|
|
253
|
-
}
|
|
254
|
-
case "data": {
|
|
255
|
-
return { kind: "data", data: part };
|
|
256
|
-
}
|
|
257
|
-
default:
|
|
258
|
-
throw new Error("Invalid part kind");
|
|
259
|
-
}
|
|
260
|
-
};
|
|
261
|
-
/**
|
|
262
|
-
* Creates an agent execution engine from a list of workflow steps.
|
|
263
|
-
*
|
|
264
|
-
* This function transforms a list of step definitions into an executable
|
|
265
|
-
* agent engine that processes commands through the defined workflow,
|
|
266
|
-
* yielding updates as each step completes.
|
|
267
|
-
*
|
|
268
|
-
* @param stepsList - Array of workflow steps to execute
|
|
269
|
-
* @returns Agent execution engine function
|
|
270
|
-
*
|
|
271
|
-
* @example
|
|
272
|
-
* ```typescript
|
|
273
|
-
* const steps = [
|
|
274
|
-
* { kind: 'text', step: greetingStep },
|
|
275
|
-
* { kind: 'data', step: analysisStep }
|
|
276
|
-
* ];
|
|
277
|
-
* const engine = createAgentExecutor(steps);
|
|
278
|
-
* ```
|
|
279
|
-
*
|
|
280
|
-
* @public
|
|
281
|
-
* @since 0.5.6
|
|
282
|
-
*/
|
|
283
|
-
export function createAgentExecutor(stepsList) {
|
|
284
|
-
return async function* (context) {
|
|
285
|
-
const content = getContent(context.userMessage);
|
|
286
|
-
let _skipStep = false;
|
|
287
|
-
const stepArgs = {
|
|
288
|
-
message: context.messages,
|
|
289
|
-
context: context,
|
|
290
|
-
content: content,
|
|
291
|
-
skip: () => {
|
|
292
|
-
_skipStep = true;
|
|
293
|
-
return;
|
|
294
|
-
},
|
|
295
|
-
};
|
|
296
|
-
const contextId = context.contextId;
|
|
297
|
-
const taskId = context.taskId;
|
|
298
|
-
if (!contextId || !taskId) {
|
|
299
|
-
throw new Error("Context ID and task ID are required");
|
|
300
|
-
}
|
|
301
|
-
const taskStarted = SUBMITTED_UPDATE(taskId, contextId);
|
|
302
|
-
yield taskStarted;
|
|
303
|
-
let finalState = A2A.TaskState.completed;
|
|
304
|
-
const finalMessage = {
|
|
305
|
-
taskId: taskId,
|
|
306
|
-
contextId: contextId,
|
|
307
|
-
messageId: uuidv4(),
|
|
308
|
-
kind: "message",
|
|
309
|
-
role: "agent",
|
|
310
|
-
parts: [],
|
|
311
|
-
};
|
|
312
|
-
for (const step of stepsList) {
|
|
313
|
-
if (await context.isCancelled()) {
|
|
314
|
-
finalState = A2A.TaskState.canceled;
|
|
315
|
-
break;
|
|
316
|
-
}
|
|
317
|
-
const ret = await step.step({ ...stepArgs });
|
|
318
|
-
if (_skipStep) {
|
|
319
|
-
_skipStep = false;
|
|
320
|
-
continue;
|
|
321
|
-
}
|
|
322
|
-
let parts = [];
|
|
323
|
-
if (Array.isArray(ret)) {
|
|
324
|
-
parts = ret.map((part) => partToMessagePart(step.kind, part));
|
|
325
|
-
const taskStatusUpdate = WORKING_UPDATE(taskId, contextId, {
|
|
326
|
-
messageId: uuidv4(),
|
|
327
|
-
kind: "message",
|
|
328
|
-
role: "agent",
|
|
329
|
-
parts: parts,
|
|
330
|
-
});
|
|
331
|
-
yield taskStatusUpdate;
|
|
332
|
-
}
|
|
333
|
-
else if (ret !== null && typeof ret === "object" && "parts" in ret) {
|
|
334
|
-
parts = Array.isArray(ret.parts)
|
|
335
|
-
? ret.parts.map((part) => partToMessagePart(step.kind, part))
|
|
336
|
-
: [partToMessagePart(step.kind, ret.parts)];
|
|
337
|
-
const taskStatusUpdate = WORKING_UPDATE(taskId, contextId, {
|
|
338
|
-
messageId: uuidv4(),
|
|
339
|
-
kind: "message",
|
|
340
|
-
role: "agent",
|
|
341
|
-
parts: parts,
|
|
342
|
-
});
|
|
343
|
-
yield taskStatusUpdate;
|
|
344
|
-
stepArgs.args = ret.args;
|
|
345
|
-
}
|
|
346
|
-
else {
|
|
347
|
-
parts = [partToMessagePart(step.kind, ret)];
|
|
348
|
-
const taskStatusUpdate = WORKING_UPDATE(taskId, contextId, {
|
|
349
|
-
messageId: uuidv4(),
|
|
350
|
-
kind: "message",
|
|
351
|
-
role: "agent",
|
|
352
|
-
parts: parts,
|
|
353
|
-
});
|
|
354
|
-
yield taskStatusUpdate;
|
|
355
|
-
}
|
|
356
|
-
finalMessage.parts.push(...parts);
|
|
357
|
-
}
|
|
358
|
-
const task = {
|
|
359
|
-
kind: "task",
|
|
360
|
-
id: taskId,
|
|
361
|
-
contextId: contextId,
|
|
362
|
-
status: {
|
|
363
|
-
state: finalState,
|
|
364
|
-
timestamp: new Date().toISOString(),
|
|
365
|
-
message: finalMessage,
|
|
366
|
-
},
|
|
367
|
-
};
|
|
368
|
-
yield task;
|
|
369
|
-
};
|
|
370
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright 2025 The Artinet Project
|
|
3
|
-
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
-
*/
|
|
5
|
-
import { A2A } from "../../../types/index.js";
|
|
6
|
-
export declare class AgentCardBuilder {
|
|
7
|
-
agentCard: A2A.AgentCard;
|
|
8
|
-
constructor(agentCard: Partial<A2A.AgentCard> & Required<Pick<A2A.AgentCard, "name">>);
|
|
9
|
-
valueOf(): A2A.AgentCard;
|
|
10
|
-
}
|
|
11
|
-
export declare function createAgentCard(agentCard: A2A.AgentCardParams): A2A.AgentCard;
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright 2025 The Artinet Project
|
|
3
|
-
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
-
*/
|
|
5
|
-
export class AgentCardBuilder {
|
|
6
|
-
agentCard;
|
|
7
|
-
constructor(agentCard) {
|
|
8
|
-
this.agentCard = {
|
|
9
|
-
...agentCard,
|
|
10
|
-
protocolVersion: agentCard.protocolVersion ?? "0.3.0",
|
|
11
|
-
description: agentCard.description ?? "An agent that can use the A2A protocol.",
|
|
12
|
-
url: agentCard.url ?? "https://localhost:3000/a2a",
|
|
13
|
-
version: agentCard.version ?? "0.0.0",
|
|
14
|
-
capabilities: agentCard.capabilities ?? {},
|
|
15
|
-
defaultInputModes: agentCard.defaultInputModes ?? [],
|
|
16
|
-
defaultOutputModes: agentCard.defaultOutputModes ?? [],
|
|
17
|
-
skills: agentCard.skills ?? [],
|
|
18
|
-
preferredTransport: agentCard.preferredTransport ?? "JSONRPC",
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
valueOf() {
|
|
22
|
-
return this.agentCard;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
export function createAgentCard(agentCard) {
|
|
26
|
-
return new AgentCardBuilder(typeof agentCard === "string" ? { name: agentCard } : agentCard).valueOf();
|
|
27
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright 2025 The Artinet Project
|
|
3
|
-
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
-
*/
|
|
5
|
-
import { A2A } from "../../../types/index.js";
|
|
6
|
-
export declare class MessageBuilder {
|
|
7
|
-
message: A2A.Message;
|
|
8
|
-
constructor(message?: Partial<A2A.Message>);
|
|
9
|
-
valueOf(): A2A.Message;
|
|
10
|
-
}
|
|
11
|
-
export declare const MESSAGE: (message?: Partial<A2A.Message>) => A2A.Message;
|
|
12
|
-
export declare class MessageSendConfigurationBuilder {
|
|
13
|
-
configuration: A2A.MessageSendConfiguration;
|
|
14
|
-
constructor(configuration?: Partial<A2A.MessageSendConfiguration> | null);
|
|
15
|
-
valueOf(): A2A.MessageSendConfiguration;
|
|
16
|
-
}
|
|
17
|
-
export declare const createMessageSendParams: (messageSendParams: Partial<A2A.MessageSendParams> | string) => A2A.MessageSendParams;
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright 2025 The Artinet Project
|
|
3
|
-
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
-
*/
|
|
5
|
-
import { v4 as uuidv4 } from "uuid";
|
|
6
|
-
export class MessageBuilder {
|
|
7
|
-
message = {
|
|
8
|
-
role: "user",
|
|
9
|
-
parts: [],
|
|
10
|
-
metadata: undefined,
|
|
11
|
-
extensions: undefined,
|
|
12
|
-
referenceTaskIds: undefined,
|
|
13
|
-
messageId: uuidv4(),
|
|
14
|
-
taskId: undefined,
|
|
15
|
-
contextId: undefined,
|
|
16
|
-
kind: "message",
|
|
17
|
-
};
|
|
18
|
-
constructor(message = {}) {
|
|
19
|
-
this.message.role = message.role ?? this.message.role;
|
|
20
|
-
this.message.parts = message.parts ?? this.message.parts;
|
|
21
|
-
this.message.metadata = message.metadata ?? this.message.metadata;
|
|
22
|
-
this.message.extensions = message.extensions ?? this.message.extensions;
|
|
23
|
-
this.message.referenceTaskIds =
|
|
24
|
-
message.referenceTaskIds ?? this.message.referenceTaskIds;
|
|
25
|
-
this.message.messageId = message.messageId ?? this.message.messageId;
|
|
26
|
-
this.message.taskId = message.taskId ?? this.message.taskId;
|
|
27
|
-
this.message.contextId = message.contextId ?? this.message.contextId;
|
|
28
|
-
}
|
|
29
|
-
valueOf() {
|
|
30
|
-
return this.message;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
export const MESSAGE = (message = {}) => new MessageBuilder(message).message;
|
|
34
|
-
export class MessageSendConfigurationBuilder {
|
|
35
|
-
configuration = {
|
|
36
|
-
acceptedOutputModes: undefined,
|
|
37
|
-
historyLength: undefined,
|
|
38
|
-
pushNotificationConfig: undefined,
|
|
39
|
-
blocking: undefined,
|
|
40
|
-
};
|
|
41
|
-
constructor(configuration = {}) {
|
|
42
|
-
this.configuration.acceptedOutputModes =
|
|
43
|
-
configuration?.acceptedOutputModes ??
|
|
44
|
-
this.configuration.acceptedOutputModes;
|
|
45
|
-
this.configuration.historyLength =
|
|
46
|
-
configuration?.historyLength ?? this.configuration.historyLength;
|
|
47
|
-
this.configuration.pushNotificationConfig =
|
|
48
|
-
configuration?.pushNotificationConfig ??
|
|
49
|
-
this.configuration.pushNotificationConfig;
|
|
50
|
-
this.configuration.blocking =
|
|
51
|
-
configuration?.blocking ?? this.configuration.blocking;
|
|
52
|
-
}
|
|
53
|
-
valueOf() {
|
|
54
|
-
return this.configuration;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
export const createMessageSendParams = (messageSendParams) => {
|
|
58
|
-
const isString = typeof messageSendParams === "string";
|
|
59
|
-
return {
|
|
60
|
-
message: new MessageBuilder(isString
|
|
61
|
-
? { parts: [{ text: messageSendParams, kind: "text" }] }
|
|
62
|
-
: messageSendParams.message).valueOf(),
|
|
63
|
-
configuration: new MessageSendConfigurationBuilder(isString ? undefined : messageSendParams.configuration).valueOf(),
|
|
64
|
-
metadata: isString ? undefined : messageSendParams.metadata,
|
|
65
|
-
};
|
|
66
|
-
};
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright 2025 The Artinet Project
|
|
3
|
-
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
-
*/
|
|
5
|
-
import { MessageSendParams, DataPart, FilePart, TextPart } from "@artinet/types/a2a";
|
|
6
|
-
import { Context } from "./a2a.js";
|
|
7
|
-
/**
|
|
8
|
-
* Restricting to command for now, but could be extended to other types of commands in the future.
|
|
9
|
-
* When we shift to CoreCommand, move this into core.
|
|
10
|
-
*/
|
|
11
|
-
export interface StepArgs {
|
|
12
|
-
message: MessageSendParams;
|
|
13
|
-
context: Context;
|
|
14
|
-
skip: () => Promise<void> | void;
|
|
15
|
-
}
|
|
16
|
-
export type BaseArgs = Record<string, unknown>;
|
|
17
|
-
export type EmptyArgs = Record<string, never>;
|
|
18
|
-
export type StepParams<TInboundArgs extends BaseArgs = EmptyArgs> = StepArgs & Partial<{
|
|
19
|
-
content: string;
|
|
20
|
-
args: TInboundArgs;
|
|
21
|
-
}>;
|
|
22
|
-
export type PartContent = DataPart["data"] | FilePart["file"] | TextPart["text"];
|
|
23
|
-
export type StepOutput<TPart extends PartContent> = {
|
|
24
|
-
parts: Array<TPart> | TPart;
|
|
25
|
-
};
|
|
26
|
-
export type StepOutputWithForwardArgs<TPart extends PartContent, TForwardArgs extends BaseArgs = EmptyArgs> = StepOutput<TPart> & {
|
|
27
|
-
args: TForwardArgs;
|
|
28
|
-
};
|
|
29
|
-
export type OutputType<TPart extends PartContent, TForwardArgs extends BaseArgs = EmptyArgs> = StepOutput<TPart> | StepOutputWithForwardArgs<TPart, TForwardArgs> | Array<TPart> | TPart;
|
|
30
|
-
export type Step<TPart extends PartContent = TextPart["text"], TInboundArgs extends BaseArgs = EmptyArgs, TForwardArgs extends BaseArgs = EmptyArgs, TOutput extends OutputType<TPart, TForwardArgs> = OutputType<TPart, TForwardArgs>> = (params: StepParams<TInboundArgs>) => Promise<TOutput> | TOutput;
|
|
31
|
-
export type StepWithKind<TPart extends PartContent = TextPart["text"], TInboundArgs extends BaseArgs = EmptyArgs, TForwardArgs extends BaseArgs = EmptyArgs, TOutput extends OutputType<TPart, TForwardArgs> = OutputType<TPart, TForwardArgs>, TKind extends "text" | "file" | "data" = "text"> = {
|
|
32
|
-
step: Step<TPart, TInboundArgs, TForwardArgs, TOutput>;
|
|
33
|
-
kind: TKind;
|
|
34
|
-
};
|
|
35
|
-
export type OutArgsOf<O> = O extends StepOutputWithForwardArgs<any, infer A> ? A : EmptyArgs;
|
|
36
|
-
export interface StepBuilder<TInboundArgs extends BaseArgs = EmptyArgs> {
|
|
37
|
-
/**
|
|
38
|
-
* Add a step to the builder.
|
|
39
|
-
* @param step - The step to add.
|
|
40
|
-
* @returns A new builder with the step added.
|
|
41
|
-
*/
|
|
42
|
-
addStep<TPart extends PartContent = TextPart["text"], TForwardArgs extends BaseArgs = EmptyArgs, TOutput extends OutputType<TPart, TForwardArgs> = OutputType<TPart, TForwardArgs>, TKind extends "text" | "file" | "data" = "text">(step: StepWithKind<TPart, TInboundArgs, TForwardArgs, TOutput, TKind>): StepBuilder<OutArgsOf<TOutput>>;
|
|
43
|
-
}
|