@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.
Files changed (113) hide show
  1. package/README.md +1 -1
  2. package/dist/browser/client/a2a-client.js +4 -4
  3. package/dist/browser/config/index.d.ts +1 -1
  4. package/dist/browser/config/index.js +1 -1
  5. package/dist/browser/create/agentcard-builder.d.ts +47 -0
  6. package/dist/browser/create/agentcard-builder.js +65 -0
  7. package/dist/browser/create/base.d.ts +4 -0
  8. package/dist/browser/create/base.js +1 -0
  9. package/dist/browser/create/describe.d.ts +8 -0
  10. package/dist/browser/create/describe.js +8 -0
  11. package/dist/browser/create/message-builder.d.ts +78 -0
  12. package/dist/browser/create/message-builder.js +108 -0
  13. package/dist/browser/create/part-builder.d.ts +60 -0
  14. package/dist/browser/create/part-builder.js +81 -0
  15. package/dist/browser/create/task-builder.d.ts +251 -0
  16. package/dist/browser/create/task-builder.js +379 -0
  17. package/dist/browser/transport/rpc/parser.d.ts +1 -1
  18. package/dist/browser/transport/rpc/parser.js +2 -1
  19. package/dist/browser/types/a2a/a2a.d.ts +7 -3
  20. package/dist/browser/types/a2a/index.d.ts +3 -1
  21. package/dist/browser/types/a2a/index.js +0 -1
  22. package/dist/browser/utils/common/constants.d.ts +0 -5
  23. package/dist/browser/utils/common/constants.js +0 -27
  24. package/dist/browser/utils/common/errors.d.ts +57 -1
  25. package/dist/browser/utils/common/errors.js +68 -15
  26. package/dist/client/a2a-client.js +4 -4
  27. package/dist/config/default.d.ts +1 -1
  28. package/dist/config/default.js +1 -1
  29. package/dist/config/index.d.ts +1 -1
  30. package/dist/config/index.js +1 -1
  31. package/dist/create/agent-builder.d.ts +77 -0
  32. package/dist/create/agent-builder.js +20 -0
  33. package/dist/create/agentcard-builder.d.ts +47 -0
  34. package/dist/create/agentcard-builder.js +66 -0
  35. package/dist/create/base.d.ts +4 -0
  36. package/dist/create/base.js +1 -0
  37. package/dist/create/create.d.ts +762 -0
  38. package/dist/create/create.js +556 -0
  39. package/dist/create/describe.d.ts +8 -0
  40. package/dist/create/describe.js +8 -0
  41. package/dist/create/index.d.ts +4 -0
  42. package/dist/create/index.js +4 -0
  43. package/dist/create/message-builder.d.ts +78 -0
  44. package/dist/create/message-builder.js +110 -0
  45. package/dist/create/part-builder.d.ts +60 -0
  46. package/dist/create/part-builder.js +84 -0
  47. package/dist/create/status-builder.d.ts +26 -0
  48. package/dist/create/status-builder.js +46 -0
  49. package/dist/create/task-builder.d.ts +251 -0
  50. package/dist/create/task-builder.js +384 -0
  51. package/dist/create/transform.d.ts +16 -0
  52. package/dist/create/transform.js +106 -0
  53. package/dist/index.d.ts +2 -0
  54. package/dist/index.js +2 -0
  55. package/dist/server/express/errors.js +4 -8
  56. package/dist/server/express/middeware.js +17 -38
  57. package/dist/server/express/server.d.ts +6 -1
  58. package/dist/server/express/server.js +30 -12
  59. package/dist/services/a2a/execute.d.ts +5 -0
  60. package/dist/services/a2a/execute.js +7 -0
  61. package/dist/services/a2a/factory/context.d.ts +1 -1
  62. package/dist/services/a2a/factory/context.js +2 -3
  63. package/dist/services/a2a/factory/handler.js +3 -3
  64. package/dist/services/a2a/factory/index.d.ts +0 -1
  65. package/dist/services/a2a/factory/index.js +0 -1
  66. package/dist/services/a2a/factory/service.d.ts +2 -2
  67. package/dist/services/a2a/factory/service.js +2 -2
  68. package/dist/services/a2a/factory/state-machine.d.ts +1 -1
  69. package/dist/services/a2a/factory/state-machine.js +30 -8
  70. package/dist/services/a2a/handlers/artifact.d.ts +2 -5
  71. package/dist/services/a2a/handlers/artifact.js +21 -32
  72. package/dist/services/a2a/handlers/cancel-task.js +7 -5
  73. package/dist/services/a2a/handlers/resubscribe-task.d.ts +10 -2
  74. package/dist/services/a2a/handlers/resubscribe-task.js +21 -18
  75. package/dist/services/a2a/handlers/send-message.js +6 -10
  76. package/dist/services/a2a/handlers/stream-message.d.ts +10 -2
  77. package/dist/services/a2a/handlers/stream-message.js +5 -1
  78. package/dist/services/a2a/handlers/update.js +11 -6
  79. package/dist/services/a2a/helpers/content.d.ts +5 -1
  80. package/dist/services/a2a/helpers/content.js +5 -1
  81. package/dist/services/a2a/helpers/index.d.ts +2 -2
  82. package/dist/services/a2a/helpers/index.js +2 -2
  83. package/dist/services/a2a/index.d.ts +1 -1
  84. package/dist/services/a2a/index.js +1 -1
  85. package/dist/services/a2a/managers.js +7 -1
  86. package/dist/services/a2a/service.d.ts +6 -2
  87. package/dist/services/a2a/service.js +52 -59
  88. package/dist/services/a2a/state-machine.d.ts +3 -3
  89. package/dist/services/a2a/state-machine.js +2 -0
  90. package/dist/transport/rpc/parser.d.ts +1 -1
  91. package/dist/transport/rpc/parser.js +2 -1
  92. package/dist/types/a2a/a2a.d.ts +7 -3
  93. package/dist/types/a2a/index.d.ts +3 -1
  94. package/dist/types/a2a/index.js +0 -1
  95. package/dist/utils/common/constants.d.ts +0 -5
  96. package/dist/utils/common/constants.js +0 -27
  97. package/dist/utils/common/errors.d.ts +57 -1
  98. package/dist/utils/common/errors.js +68 -15
  99. package/dist/utils/common/parse.d.ts +1 -1
  100. package/dist/utils/common/schema-validation.d.ts +1 -1
  101. package/package.json +7 -4
  102. package/dist/browser/services/a2a/helpers/message-builder.d.ts +0 -17
  103. package/dist/browser/services/a2a/helpers/message-builder.js +0 -66
  104. package/dist/browser/types/a2a/builder.d.ts +0 -43
  105. package/dist/browser/types/a2a/builder.js +0 -5
  106. package/dist/services/a2a/factory/builder.d.ts +0 -292
  107. package/dist/services/a2a/factory/builder.js +0 -370
  108. package/dist/services/a2a/helpers/agentcard-builder.d.ts +0 -11
  109. package/dist/services/a2a/helpers/agentcard-builder.js +0 -27
  110. package/dist/services/a2a/helpers/message-builder.d.ts +0 -17
  111. package/dist/services/a2a/helpers/message-builder.js +0 -66
  112. package/dist/types/a2a/builder.d.ts +0 -43
  113. package/dist/types/a2a/builder.js +0 -5
@@ -0,0 +1,556 @@
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
+ * **Key Features:**
13
+ * - Fluent API with method chaining (`.text()`, `.data()`, `.file()`, etc.)
14
+ * - Type-safe argument passing between steps via `args` carry pattern
15
+ * - Multiple output types: text, file, data, message, artifact, status, task
16
+ * - Agent-to-agent orchestration via `.sendMessage()`
17
+ * - Static value shortcuts for simple steps
18
+ * - Step skipping via `skip()` function
19
+ *
20
+ * **Basic Usage:**
21
+ * ```typescript
22
+ * import { cr8 } from "@artinet/sdk";
23
+ *
24
+ * const agent = cr8("MyAgent")
25
+ * .text(({ content }) => `You said: ${content}`)
26
+ * .data(({ content }) => ({ length: content?.length }))
27
+ * .agent;
28
+ * ```
29
+ *
30
+ * @module A2ABuilder
31
+ * @version 0.6.0-preview
32
+ * @since 0.5.6
33
+ * @author The Artinet Project
34
+ */
35
+ import { A2A } from "../types/index.js";
36
+ import * as transform from "./transform.js";
37
+ import { createAgent as createAgentImpl, } from "../services/a2a/factory/service.js";
38
+ import { describe } from "./index.js";
39
+ import { extractTextContent } from "../services/a2a/helpers/content.js";
40
+ import { createAgentServer } from "../server/index.js";
41
+ import { logger } from "../config/index.js";
42
+ import { v4 as uuidv4 } from "uuid";
43
+ import { formatJson } from "../utils/index.js";
44
+ const toFunction = (function_or_ret) => {
45
+ return typeof function_or_ret === "function"
46
+ ? function_or_ret
47
+ : () => function_or_ret;
48
+ };
49
+ /**
50
+ * Fluent builder for constructing A2A agent execution engines.
51
+ *
52
+ * AgentFactory provides a type-safe, fluent API for composing multi-step
53
+ * agent workflows. It supports method chaining to build complex agent behaviors
54
+ * from individual processing steps, with automatic type inference for carried
55
+ * arguments between steps.
56
+ *
57
+ * @template I - The arguments type received from previous steps (inferred automatically)
58
+ *
59
+ * @example
60
+ * ```typescript
61
+ * // Basic agent with text steps
62
+ * const agent = cr8("MyAgent")
63
+ * .text(({ content }) => `You said: ${content}`)
64
+ * .agent;
65
+ *
66
+ * // Agent with carried args between steps
67
+ * const agent = cr8("AnalysisAgent")
68
+ * .text(({ content }) => ({
69
+ * reply: `Analyzing: ${content}`,
70
+ * args: { originalContent: content }
71
+ * }))
72
+ * .data(({ args }) => ({
73
+ * wordCount: args?.originalContent?.split(' ').length,
74
+ * timestamp: Date.now()
75
+ * }))
76
+ * .text(({ args }) => `Analysis complete: ${args?.wordCount} words`)
77
+ * .agent;
78
+ *
79
+ * // Agent-to-agent orchestration
80
+ * const orchestrator = cr8("Orchestrator")
81
+ * .text("Starting multi-agent workflow...")
82
+ * .sendMessage({ agent: otherAgent, message: "Process this" })
83
+ * .text(({ args }) => `Got result: ${args?.task?.status.state}`)
84
+ * .agent;
85
+ * ```
86
+ *
87
+ * @public
88
+ * @since 0.5.6
89
+ */
90
+ export class AgentFactory {
91
+ _agentCard;
92
+ _params;
93
+ _steps;
94
+ /**
95
+ * Protected constructor to enforce factory method usage.
96
+ * @param agentCard - The agent card to use
97
+ * @param params - The parameters to use
98
+ * @param steps - Initial steps array
99
+ */
100
+ constructor(_agentCard, _params,
101
+ //@typescript-eslint/no-explicit-any
102
+ _steps = []) {
103
+ this._agentCard = _agentCard;
104
+ this._params = _params;
105
+ this._steps = _steps;
106
+ }
107
+ /**
108
+ * Builds the step list for the workflow.
109
+ *
110
+ * @returns Array of workflow steps
111
+ * @throws Error if no steps have been added
112
+ *
113
+ * @example
114
+ * ```typescript
115
+ * const steps = cr8.steps;
116
+ * ```
117
+ */
118
+ //@typescript-eslint/no-explicit-any
119
+ get steps() {
120
+ return this._steps;
121
+ }
122
+ /**
123
+ * The {@link A2A.AgentCard} to use
124
+ * @returns The {@link A2A.AgentCard}
125
+ */
126
+ get agentCard() {
127
+ return this._agentCard;
128
+ }
129
+ /**
130
+ * The {@link FactoryParams} to use
131
+ * @returns The {@link FactoryParams}
132
+ */
133
+ get params() {
134
+ return this._params;
135
+ }
136
+ /**
137
+ * Creates an agent execution engine from the built workflow.
138
+ *
139
+ * @returns The {@link A2A.Engine}
140
+ *
141
+ * @example
142
+ * ```typescript
143
+ * const engine = builder.engine;
144
+ * // Use engine with service execution
145
+ * ```
146
+ */
147
+ get engine() {
148
+ return createStepEngine(this.steps);
149
+ }
150
+ /**
151
+ * Creates a complete A2A agent using the built workflow.
152
+ *
153
+ * @param params - The {@link ServiceParams} to use
154
+ * @returns The {@link Service}
155
+ *
156
+ * @example
157
+ * ```typescript
158
+ * const agent = cr8({
159
+ * id: 'my-agent',
160
+ * name: 'Assistant Agent',
161
+ * capabilities: ['text-processing']
162
+ * }).agent;
163
+ * ```
164
+ */
165
+ get agent() {
166
+ return createAgentImpl({
167
+ ...this._params,
168
+ agentCard: this._agentCard,
169
+ engine: this.engine,
170
+ });
171
+ }
172
+ get server() {
173
+ return createAgentServer({
174
+ agent: this.agent,
175
+ ...this._params,
176
+ });
177
+ }
178
+ from(engine = this.engine) {
179
+ return createAgentImpl({
180
+ ...this._params,
181
+ agentCard: this._agentCard,
182
+ engine: engine,
183
+ });
184
+ }
185
+ serve(engine = this.engine) {
186
+ return createAgentServer({
187
+ agent: this.from(engine),
188
+ ...this._params,
189
+ });
190
+ }
191
+ addStep(step) {
192
+ return new AgentFactory(this._agentCard, this._params, [
193
+ ...this.steps,
194
+ step,
195
+ ]);
196
+ }
197
+ text(step_or_text) {
198
+ const stepFn = toFunction(step_or_text);
199
+ return this.addStep({
200
+ id: uuidv4(),
201
+ step: stepFn,
202
+ kind: "text",
203
+ handler: transform.Parts("text"),
204
+ });
205
+ }
206
+ file(step_or_file) {
207
+ const stepFn = toFunction(step_or_file);
208
+ return this.addStep({
209
+ id: uuidv4(),
210
+ step: stepFn,
211
+ kind: "file",
212
+ handler: transform.Parts("file"),
213
+ });
214
+ }
215
+ data(step_or_data) {
216
+ const stepFn = toFunction(step_or_data);
217
+ return this.addStep({
218
+ id: uuidv4(),
219
+ step: stepFn,
220
+ kind: "data",
221
+ handler: transform.Parts("data"),
222
+ });
223
+ }
224
+ message(step_or_message) {
225
+ const stepFn = toFunction(step_or_message);
226
+ return this.addStep({
227
+ id: uuidv4(),
228
+ step: stepFn,
229
+ kind: "message",
230
+ handler: transform.Message(),
231
+ });
232
+ }
233
+ artifact(step_or_artifact) {
234
+ const stepFn = toFunction(step_or_artifact);
235
+ return this.addStep({
236
+ id: uuidv4(),
237
+ step: stepFn,
238
+ kind: "artifact-update",
239
+ handler: transform.Artifact(),
240
+ });
241
+ }
242
+ status(step_or_status) {
243
+ const stepFn = toFunction(step_or_status);
244
+ return this.addStep({
245
+ id: uuidv4(),
246
+ step: stepFn,
247
+ kind: "status-update",
248
+ handler: transform.Status(),
249
+ });
250
+ }
251
+ task(step_or_task_or_string) {
252
+ const stepFn = toFunction(step_or_task_or_string);
253
+ return this.addStep({
254
+ id: uuidv4(),
255
+ step: stepFn,
256
+ kind: "task",
257
+ handler: transform.Task(),
258
+ });
259
+ }
260
+ /**
261
+ * Adds an agent-to-agent orchestration step to the workflow.
262
+ *
263
+ * This step sends a message to another agent (local Service or remote A2AClient)
264
+ * and yields the response as a task. Enables multi-agent workflows where one
265
+ * agent delegates work to others.
266
+ *
267
+ * **Note:** This is currently a blocking call. Streaming responses are not
268
+ * yet supported in orchestration steps.
269
+ *
270
+ * @param agent_and_message - Configuration object with target agent and optional message
271
+ * @param agent_and_message.agent - The target agent (Service or A2AClient)
272
+ * @param agent_and_message.message - Message to send (defaults to context.userMessage)
273
+ * @returns New builder instance with task carry args (args.task)
274
+ *
275
+ * @example
276
+ * ```typescript
277
+ * // Delegate to another agent
278
+ * const orchestrator = cr8("Orchestrator")
279
+ * .text("Starting workflow...")
280
+ * .sendMessage({ agent: analysisAgent, message: "Analyze this data" })
281
+ * .text(({ args }) => `Analysis result: ${args?.task?.status.state}`)
282
+ * .agent;
283
+ *
284
+ * // Chain multiple agents
285
+ * const pipeline = cr8("Pipeline")
286
+ * .sendMessage({ agent: preprocessor })
287
+ * .sendMessage({ agent: analyzer })
288
+ * .sendMessage({ agent: postprocessor })
289
+ * .text(({ args }) => `Final result: ${args?.task?.status.message}`)
290
+ * .agent;
291
+ *
292
+ * // Forward user's message to another agent
293
+ * const proxy = cr8("Proxy")
294
+ * .sendMessage({ agent: targetAgent }) // uses context.userMessage
295
+ * .agent;
296
+ * ```
297
+ */
298
+ sendMessage(agent_and_message) {
299
+ const stepFn = async ({ context }) => {
300
+ logger.info("sendMessage: Sending message: ", {
301
+ agent: agent_and_message.agent.constructor.name,
302
+ });
303
+ const response = await agent_and_message.agent
304
+ .sendMessage(describe.messageSendParams(agent_and_message.message ?? context.userMessage))
305
+ .catch((error) => {
306
+ logger.error("sendMessage: Error sending message: ", error);
307
+ return null;
308
+ });
309
+ if (!response) {
310
+ logger.warn("sendMessage: No response from agent");
311
+ }
312
+ const task = response
313
+ ? describe.task({
314
+ ...response,
315
+ state: A2A.TaskState.working,
316
+ taskId: context.taskId,
317
+ contextId: context.contextId,
318
+ })
319
+ : describe.task({
320
+ taskId: context.taskId,
321
+ contextId: context.contextId,
322
+ state: A2A.TaskState.working,
323
+ message: describe.message("No response from agent"),
324
+ });
325
+ return {
326
+ reply: task,
327
+ args: {
328
+ task,
329
+ },
330
+ };
331
+ };
332
+ return this.addStep({
333
+ id: uuidv4(),
334
+ step: stepFn,
335
+ kind: "task",
336
+ handler: transform.Task(),
337
+ });
338
+ }
339
+ /**
340
+ * Creates a new AgentFactory instance.
341
+ *
342
+ * @template Input - The initial arguments type
343
+ * @returns A new AgentFactory instance
344
+ *
345
+ * @example
346
+ * ```typescript
347
+ * const factory = AgentFactory.create(myCard, { params });
348
+ * ```
349
+ */
350
+ static create(agentCard, params) {
351
+ return new AgentFactory(describe.card(agentCard), params);
352
+ }
353
+ /**
354
+ * @deprecated Use engine instead
355
+ */
356
+ createAgentEngine() {
357
+ return createStepEngine(this.steps);
358
+ }
359
+ /**
360
+ * @deprecated Use {@link agent} instead
361
+ */
362
+ createAgent(params) {
363
+ return createAgentImpl({
364
+ ...params,
365
+ engine: this.createAgentEngine(),
366
+ });
367
+ }
368
+ }
369
+ /**
370
+ * Creates a new AgentFactory instance for building agent workflows.
371
+ *
372
+ * This is the primary entry point for the fluent builder API. Accepts an
373
+ * agent card (or name string) and optional factory parameters.
374
+ *
375
+ * @param agentCard - Agent card object or name string
376
+ * @param params - Optional factory parameters (basePath, port, etc.)
377
+ * @returns New AgentFactory instance
378
+ *
379
+ * @example
380
+ * ```typescript
381
+ * // Simple agent with name string
382
+ * const agent = cr8("MyAgent")
383
+ * .text(({ content }) => `Echo: ${content}`)
384
+ * .agent;
385
+ *
386
+ * // Agent with full card and params
387
+ * const agent = cr8(myAgentCard, { basePath: "/api" })
388
+ * .text("Hello!")
389
+ * .data(({ content }) => analyzeContent(content))
390
+ * .agent;
391
+ *
392
+ * // Get the engine directly
393
+ * const engine = cr8("Processor")
394
+ * .text("Processing...")
395
+ * .engine;
396
+ *
397
+ * // Create and start server
398
+ * const server = cr8("ServerAgent", { port: 3000 })
399
+ * .text("Ready to serve!")
400
+ * .server.start();
401
+ * ```
402
+ *
403
+ * @public
404
+ * @since 0.6.0
405
+ */
406
+ export const cr8 = AgentFactory.create.bind(AgentFactory);
407
+ const testAgent = cr8("TestAgent").text("Hello there!").agent;
408
+ export const test = cr8("TestAgent")
409
+ .text("Hello there!")
410
+ .text(({ message }) => {
411
+ const jackfruit = `${message.message.role} there`;
412
+ return {
413
+ reply: ["hello there"],
414
+ args: {
415
+ jackfruit: jackfruit,
416
+ },
417
+ };
418
+ })
419
+ .task(({ context, args }) => {
420
+ console.log(context);
421
+ return args?.jackfruit ?? "no jackfruit";
422
+ })
423
+ .sendMessage({ agent: testAgent, message: "Hello there!" })
424
+ .text(({ args }) => {
425
+ return args?.task?.status.state ?? "no task";
426
+ })
427
+ .message("Hello there!")
428
+ .artifact(({ context }) => {
429
+ return describe.artifact({
430
+ artifactId: context.taskId,
431
+ parts: [{ kind: "text", text: "Hello there!" }],
432
+ });
433
+ })
434
+ .message(({ context }) => {
435
+ return context.taskId;
436
+ })
437
+ .message(({ context }) => {
438
+ return describe.message({
439
+ role: "agent",
440
+ contextId: context.contextId,
441
+ parts: [{ kind: "text", text: "Hello there!" }],
442
+ });
443
+ })
444
+ .text(({ args }) => {
445
+ return [`Hello ${args?.jackfruit}!`];
446
+ })
447
+ .status("working")
448
+ .status(() => {
449
+ return {
450
+ status: {
451
+ state: A2A.TaskState.completed,
452
+ },
453
+ };
454
+ })
455
+ .text(({ context }) => {
456
+ return [`Hello!`, context.taskId];
457
+ })
458
+ .status(({ context }) => {
459
+ return {
460
+ status: {
461
+ contextId: context.contextId,
462
+ state: A2A.TaskState.completed,
463
+ },
464
+ };
465
+ })
466
+ .task(({ context }) => {
467
+ return context.taskId;
468
+ }).steps;
469
+ /**
470
+ * @deprecated Use cr8 instead
471
+ */
472
+ export const AgentBuilder = AgentFactory;
473
+ /**
474
+ * Creates an agent execution engine from a list of workflow steps.
475
+ *
476
+ * This function transforms a list of resolved step definitions into an executable
477
+ * A2A engine that processes contexts through the defined workflow. The engine
478
+ * is an async generator that yields updates as each step completes.
479
+ *
480
+ * **Execution Flow:**
481
+ * 1. Yields "submitted" status update
482
+ * 2. Executes each step in order, yielding transformed results
483
+ * 3. Passes carried args from one step to the next
484
+ * 4. Yields final task on completion
485
+ *
486
+ * @param stepsList - Array of resolved workflow steps (from AgentFactory.steps)
487
+ * @returns A2A.Engine async generator function
488
+ * @throws Error if stepsList is empty
489
+ *
490
+ * @example
491
+ * ```typescript
492
+ * // Typically accessed via AgentFactory
493
+ * const engine = cr8("MyAgent")
494
+ * .text("Hello")
495
+ * .data({ timestamp: Date.now() })
496
+ * .engine;
497
+ *
498
+ * // Or create manually from steps
499
+ * const engine = createStepEngine(factory.steps);
500
+ *
501
+ * // Execute the engine
502
+ * for await (const update of engine(context)) {
503
+ * console.log(update.kind, update);
504
+ * }
505
+ * ```
506
+ *
507
+ * @public
508
+ * @since 0.5.6
509
+ */
510
+ export function createStepEngine(stepsList) {
511
+ if (stepsList.length === 0) {
512
+ throw new Error("No steps provided");
513
+ }
514
+ return async function* (context) {
515
+ logger.info(`engine[context:${context.contextId}]: starting`);
516
+ logger.debug(`engine[context:${context.contextId}]: taskId: ${context.taskId}`);
517
+ const content = extractTextContent(context.userMessage);
518
+ let _skipStep = false;
519
+ const input = {
520
+ message: context.messages,
521
+ context: context,
522
+ content: content,
523
+ skip: () => {
524
+ _skipStep = true;
525
+ return;
526
+ },
527
+ };
528
+ const submitted = describe.update.submitted({
529
+ contextId: context.contextId,
530
+ taskId: context.taskId,
531
+ });
532
+ logger.debug(`engine[context:${context.contextId}]: submitted`);
533
+ yield submitted;
534
+ // let finalState: A2A.TaskState = A2A.TaskState.completed;
535
+ for (const step of stepsList) {
536
+ // if (await context.isCancelled()) {
537
+ // finalState = A2A.TaskState.canceled;
538
+ // break;
539
+ // }
540
+ logger.debug(`engine[context:${context.contextId}]: executing step[${step.id}]: ${step.kind}`);
541
+ const ret = await step.step({ ...input });
542
+ if (_skipStep) {
543
+ _skipStep = false;
544
+ logger.debug(`engine[context:${context.contextId}]: skipping step[${step.id}]`);
545
+ continue;
546
+ }
547
+ logger.debug(`engine[context:${context.contextId}]: transforming step[${step.id}]`);
548
+ const carried = yield* transform.Reply(ret, context, step.handler);
549
+ input.args = carried;
550
+ }
551
+ const task = await context.getTask();
552
+ logger.debug(`engine[context:${context.contextId}]: completed task[${task.id}]: ${formatJson(task)}`);
553
+ // task.status.state = finalState;
554
+ yield task;
555
+ };
556
+ }
@@ -0,0 +1,8 @@
1
+ export { card, type AgentCardParams, isAgentCardParams, } from "./agentcard-builder.js";
2
+ export { message, type MessageParams, isMessageParams, messageSendParams, type MessageSendParamsParams, } from "./message-builder.js";
3
+ export { part } from "./part-builder.js";
4
+ export { artifact, type ArtifactParams, isArtifactParams, type StatusParams, isStatusParams, status, type TaskParams, task, type StatusUpdateParams, type ArtifactUpdateParams, update, } from "./task-builder.js";
5
+ /**
6
+ * Exports from describe are meant to be portable between different modules.
7
+ * As such, they should only be dependant on `./types` or other Factory files that are also portable.
8
+ */
@@ -0,0 +1,8 @@
1
+ export { card, isAgentCardParams, } from "./agentcard-builder.js";
2
+ export { message, isMessageParams, messageSendParams, } from "./message-builder.js";
3
+ export { part } from "./part-builder.js";
4
+ export { artifact, isArtifactParams, isStatusParams, status, task, update, } from "./task-builder.js";
5
+ /**
6
+ * Exports from describe are meant to be portable between different modules.
7
+ * As such, they should only be dependant on `./types` or other Factory files that are also portable.
8
+ */
@@ -0,0 +1,4 @@
1
+ export * as describe from "./describe.js";
2
+ export { AgentCardBuilder, createAgentCard } from "./agentcard-builder.js";
3
+ export { MessageBuilder, MessageSendConfigurationBuilder, createMessageSendParams, } from "./message-builder.js";
4
+ export * from "./status-builder.js";
@@ -0,0 +1,4 @@
1
+ export * as describe from "./describe.js";
2
+ export { AgentCardBuilder, createAgentCard } from "./agentcard-builder.js";
3
+ export { MessageBuilder, MessageSendConfigurationBuilder, createMessageSendParams, } from "./message-builder.js";
4
+ export * from "./status-builder.js";
@@ -0,0 +1,78 @@
1
+ /**
2
+ * Copyright 2025 The Artinet Project
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+ import { A2A } from "../types/index.js";
6
+ import { Kindless } from "./base.js";
7
+ export declare class Message {
8
+ private readonly _message;
9
+ constructor(params?: Partial<Kindless<A2A.Message>>);
10
+ get message(): A2A.Message;
11
+ static create(params?: MessageParams): A2A.Message;
12
+ }
13
+ export type BaseMessageParams = Partial<Kindless<A2A.Message>>;
14
+ export type MessageParams = BaseMessageParams | string;
15
+ export declare const isMessageParams: (params: any) => params is MessageParams;
16
+ /**
17
+ * Convenience factory function for creating a message builder with default parameters.
18
+ *
19
+ * @returns New {@link A2A.Message} with default parameters
20
+ * @defaults {
21
+ * role: "agent",
22
+ * parts: [],
23
+ * messageId: uuidv4(),
24
+ * kind: "message",
25
+ * }
26
+ * @example
27
+ * ```typescript
28
+ * const message = message();
29
+ * ```
30
+ *
31
+ * @public
32
+ * @since 0.6.0
33
+ */
34
+ export declare const message: typeof Message.create;
35
+ /**
36
+ * @deprecated Use {@link message} instead.
37
+ * @since 0.6.0
38
+ */
39
+ export declare const MessageBuilder: typeof Message;
40
+ export declare class MessageSendConfiguration {
41
+ private readonly _configuration;
42
+ constructor(params?: Partial<A2A.MessageSendConfiguration> | null | undefined);
43
+ get configuration(): A2A.MessageSendConfiguration;
44
+ }
45
+ /**
46
+ * @deprecated Use {@link messageSendParams} instead.
47
+ * @since 0.6.0
48
+ */
49
+ export declare const MessageSendConfigurationBuilder: typeof MessageSendConfiguration;
50
+ export type MessageSendParamsParams = Partial<Kindless<A2A.MessageSendParams>> | MessageParams;
51
+ /**
52
+ * Convenience factory function for creating a message send params with default parameters.
53
+ *
54
+ * @returns New {@link A2A.MessageSendParams} with default parameters
55
+ * @defaults {
56
+ * message: {
57
+ * role: "agent",
58
+ * parts: [],
59
+ * messageId: uuidv4(),
60
+ * kind: "message",
61
+ * },
62
+ * configuration: undefined,
63
+ * metadata: undefined,
64
+ * }
65
+ * @example
66
+ * ```typescript
67
+ * const params = messageSendParams("hello there");
68
+ * ```
69
+ *
70
+ * @public
71
+ * @since 0.6.0
72
+ */
73
+ export declare function messageSendParams(params: MessageSendParamsParams): A2A.MessageSendParams;
74
+ /**
75
+ * @deprecated Use {@link messageSendParams} instead.
76
+ * @since 0.6.0
77
+ */
78
+ export declare const createMessageSendParams: typeof messageSendParams;