agentstack-sdk 0.6.1 → 0.6.2-rc2

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 (199) hide show
  1. package/README.md +36 -29
  2. package/dist/api.cjs +1994 -2
  3. package/dist/api.d.cts +29 -0
  4. package/dist/api.d.ts +25 -1
  5. package/dist/api.js +1801 -2
  6. package/dist/core-DcGxYeok.d.ts +1238 -0
  7. package/dist/core-XN6gWSAb.d.cts +1238 -0
  8. package/dist/core.cjs +1773 -2
  9. package/dist/core.d.cts +7 -0
  10. package/dist/core.d.ts +7 -5
  11. package/dist/core.js +1725 -2
  12. package/dist/extensions.cjs +798 -2
  13. package/dist/extensions.d.cts +244 -0
  14. package/dist/extensions.d.ts +240 -1
  15. package/dist/extensions.js +652 -2
  16. package/dist/index.cjs +3142 -2
  17. package/dist/index.d.cts +10 -0
  18. package/dist/index.d.ts +10 -7
  19. package/dist/index.js +2781 -2
  20. package/dist/index.umd.js +16509 -2
  21. package/dist/schemas-Dy3P_eAt.d.cts +57 -0
  22. package/dist/schemas-Dy3P_eAt.d.ts +57 -0
  23. package/dist/server.cjs +2762 -0
  24. package/dist/server.d.cts +244 -0
  25. package/dist/server.d.ts +244 -0
  26. package/dist/server.js +2716 -0
  27. package/dist/types-B5B3b0V2.d.cts +396 -0
  28. package/dist/types-B5B3b0V2.d.ts +396 -0
  29. package/dist/types-CmEs5_Ag.d.cts +3522 -0
  30. package/dist/types-DJm5-rZZ.d.ts +3522 -0
  31. package/dist/types-DvLt-XuC.d.ts +866 -0
  32. package/dist/types-E26YDM19.d.cts +866 -0
  33. package/dist/types-MfIzGgpV.d.cts +43 -0
  34. package/dist/types-MfIzGgpV.d.ts +43 -0
  35. package/package.json +36 -21
  36. package/src/client/a2a/extensions/auth/oauth/index.ts +6 -6
  37. package/src/client/a2a/extensions/auth/secrets/index.ts +6 -6
  38. package/src/client/a2a/extensions/interactions/approval/index.ts +7 -7
  39. package/src/client/a2a/extensions/services/embedding/index.ts +7 -3
  40. package/src/client/a2a/extensions/services/form/index.ts +3 -3
  41. package/src/client/a2a/extensions/services/llm/index.ts +3 -3
  42. package/src/client/a2a/extensions/services/mcp/index.ts +3 -3
  43. package/src/client/a2a/extensions/services/platform-api/index.ts +2 -2
  44. package/src/client/a2a/extensions/ui/agent-detail/index.ts +4 -4
  45. package/src/client/a2a/extensions/ui/canvas/index.ts +4 -4
  46. package/src/client/a2a/extensions/ui/citation/index.ts +4 -4
  47. package/src/client/a2a/extensions/ui/error/index.ts +4 -4
  48. package/src/client/a2a/extensions/ui/form-request/index.ts +4 -4
  49. package/src/client/a2a/extensions/ui/settings/index.ts +7 -3
  50. package/src/client/a2a/extensions/ui/trajectory/index.ts +4 -4
  51. package/src/client/core/extensions/types.ts +8 -1
  52. package/src/client/core/handle-task-status-update.ts +10 -3
  53. package/src/client/core/index.ts +1 -0
  54. package/src/client/core/utils/extract-text-from-message.ts +15 -0
  55. package/src/examples/hello-world.ts +34 -0
  56. package/src/experimental/server/a2a/extensions/agent-detail/index.ts +35 -0
  57. package/src/experimental/server/a2a/extensions/agent-detail/types.ts +10 -0
  58. package/src/experimental/server/a2a/extensions/index.ts +11 -0
  59. package/src/experimental/server/a2a/extensions/llm/index.ts +70 -0
  60. package/src/experimental/server/a2a/extensions/llm/types.ts +16 -0
  61. package/src/experimental/server/a2a/extensions/platform-self-registration/index.ts +34 -0
  62. package/src/experimental/server/a2a/extensions/platform-self-registration/types.ts +10 -0
  63. package/src/experimental/server/a2a/helpers.ts +95 -0
  64. package/{dist/client/a2a/index.d.ts → src/experimental/server/a2a/index.ts} +1 -1
  65. package/src/experimental/server/a2a/utils.ts +43 -0
  66. package/src/experimental/server/core/config/index.ts +17 -0
  67. package/src/experimental/server/core/config/schemas.ts +15 -0
  68. package/src/experimental/server/core/config/types.ts +10 -0
  69. package/src/experimental/server/core/context/index.ts +18 -0
  70. package/src/experimental/server/core/extensions/types.ts +24 -0
  71. package/{dist/client/a2a/protocol/index.d.ts → src/experimental/server/core/index.ts} +4 -0
  72. package/{dist/client/a2a/protocol/tests.d.ts → src/experimental/server/core/schemas.ts} +2 -1
  73. package/src/experimental/server/core/server/autoregistration.ts +142 -0
  74. package/src/experimental/server/core/server/executor.ts +284 -0
  75. package/src/experimental/server/core/server/helpers.ts +12 -0
  76. package/src/experimental/server/core/server/index.ts +166 -0
  77. package/src/experimental/server/core/server/types.ts +58 -0
  78. package/src/experimental/server/core/types.ts +8 -0
  79. package/src/experimental/server/core/utils.ts +59 -0
  80. package/{dist/client/api/core/errors/index.d.ts → src/server.ts} +3 -2
  81. package/dist/api.cjs.map +0 -1
  82. package/dist/api.js.map +0 -1
  83. package/dist/api.umd.js +0 -2
  84. package/dist/api.umd.js.map +0 -1
  85. package/dist/client/a2a/extensions/auth/oauth/index.d.ts +0 -10
  86. package/dist/client/a2a/extensions/auth/oauth/schemas.d.ts +0 -32
  87. package/dist/client/a2a/extensions/auth/oauth/types.d.ts +0 -13
  88. package/dist/client/a2a/extensions/auth/secrets/index.d.ts +0 -10
  89. package/dist/client/a2a/extensions/auth/secrets/schemas.d.ts +0 -23
  90. package/dist/client/a2a/extensions/auth/secrets/types.d.ts +0 -10
  91. package/dist/client/a2a/extensions/common/form/schemas.d.ts +0 -290
  92. package/dist/client/a2a/extensions/common/form/types.d.ts +0 -24
  93. package/dist/client/a2a/extensions/index.d.ts +0 -21
  94. package/dist/client/a2a/extensions/interactions/approval/index.d.ts +0 -10
  95. package/dist/client/a2a/extensions/interactions/approval/schemas.d.ts +0 -43
  96. package/dist/client/a2a/extensions/interactions/approval/types.d.ts +0 -14
  97. package/dist/client/a2a/extensions/schemas.d.ts +0 -19
  98. package/dist/client/a2a/extensions/services/embedding/index.d.ts +0 -9
  99. package/dist/client/a2a/extensions/services/embedding/schemas.d.ts +0 -29
  100. package/dist/client/a2a/extensions/services/embedding/types.d.ts +0 -10
  101. package/dist/client/a2a/extensions/services/form/index.d.ts +0 -9
  102. package/dist/client/a2a/extensions/services/form/schemas.d.ts +0 -97
  103. package/dist/client/a2a/extensions/services/form/types.d.ts +0 -8
  104. package/dist/client/a2a/extensions/services/llm/index.d.ts +0 -9
  105. package/dist/client/a2a/extensions/services/llm/schemas.d.ts +0 -29
  106. package/dist/client/a2a/extensions/services/llm/types.d.ts +0 -10
  107. package/dist/client/a2a/extensions/services/mcp/index.d.ts +0 -9
  108. package/dist/client/a2a/extensions/services/mcp/schemas.d.ts +0 -35
  109. package/dist/client/a2a/extensions/services/mcp/types.d.ts +0 -14
  110. package/dist/client/a2a/extensions/services/platform-api/index.d.ts +0 -11
  111. package/dist/client/a2a/extensions/services/platform-api/schemas.d.ts +0 -10
  112. package/dist/client/a2a/extensions/services/platform-api/types.d.ts +0 -7
  113. package/dist/client/a2a/extensions/types.d.ts +0 -19
  114. package/dist/client/a2a/extensions/ui/agent-detail/index.d.ts +0 -9
  115. package/dist/client/a2a/extensions/ui/agent-detail/schemas.d.ts +0 -41
  116. package/dist/client/a2a/extensions/ui/agent-detail/types.d.ts +0 -13
  117. package/dist/client/a2a/extensions/ui/canvas/index.d.ts +0 -9
  118. package/dist/client/a2a/extensions/ui/canvas/schemas.d.ts +0 -11
  119. package/dist/client/a2a/extensions/ui/canvas/types.d.ts +0 -7
  120. package/dist/client/a2a/extensions/ui/citation/index.d.ts +0 -9
  121. package/dist/client/a2a/extensions/ui/citation/schemas.d.ts +0 -21
  122. package/dist/client/a2a/extensions/ui/citation/types.d.ts +0 -8
  123. package/dist/client/a2a/extensions/ui/error/index.d.ts +0 -9
  124. package/dist/client/a2a/extensions/ui/error/schemas.d.ts +0 -30
  125. package/dist/client/a2a/extensions/ui/error/types.d.ts +0 -9
  126. package/dist/client/a2a/extensions/ui/form-request/index.d.ts +0 -9
  127. package/dist/client/a2a/extensions/ui/settings/index.d.ts +0 -9
  128. package/dist/client/a2a/extensions/ui/settings/schemas.d.ts +0 -113
  129. package/dist/client/a2a/extensions/ui/settings/types.d.ts +0 -18
  130. package/dist/client/a2a/extensions/ui/trajectory/index.d.ts +0 -9
  131. package/dist/client/a2a/extensions/ui/trajectory/schemas.d.ts +0 -10
  132. package/dist/client/a2a/extensions/ui/trajectory/types.d.ts +0 -7
  133. package/dist/client/a2a/protocol/schemas.d.ts +0 -988
  134. package/dist/client/a2a/protocol/types.d.ts +0 -52
  135. package/dist/client/a2a/protocol/utils.d.ts +0 -6
  136. package/dist/client/api/common/schemas.d.ts +0 -30
  137. package/dist/client/api/common/types.d.ts +0 -18
  138. package/dist/client/api/configuration/api.d.ts +0 -22
  139. package/dist/client/api/configuration/schemas.d.ts +0 -31
  140. package/dist/client/api/configuration/types.d.ts +0 -11
  141. package/dist/client/api/connectors/api.d.ts +0 -78
  142. package/dist/client/api/connectors/schemas.d.ts +0 -114
  143. package/dist/client/api/connectors/types.d.ts +0 -28
  144. package/dist/client/api/contexts/api.d.ts +0 -133
  145. package/dist/client/api/contexts/schemas.d.ts +0 -359
  146. package/dist/client/api/contexts/types.d.ts +0 -34
  147. package/dist/client/api/core/client.d.ts +0 -1273
  148. package/dist/client/api/core/errors/types.d.ts +0 -36
  149. package/dist/client/api/core/errors/utils.d.ts +0 -23
  150. package/dist/client/api/core/index.d.ts +0 -7
  151. package/dist/client/api/core/schemas.d.ts +0 -17
  152. package/dist/client/api/core/types.d.ts +0 -45
  153. package/dist/client/api/core/utils.d.ts +0 -23
  154. package/dist/client/api/files/api.d.ts +0 -32
  155. package/dist/client/api/files/schemas.d.ts +0 -61
  156. package/dist/client/api/files/types.d.ts +0 -19
  157. package/dist/client/api/index.d.ts +0 -7
  158. package/dist/client/api/model-providers/api.d.ts +0 -50
  159. package/dist/client/api/model-providers/schemas.d.ts +0 -80
  160. package/dist/client/api/model-providers/types.d.ts +0 -44
  161. package/dist/client/api/provider-builds/api.d.ts +0 -143
  162. package/dist/client/api/provider-builds/schemas.d.ts +0 -250
  163. package/dist/client/api/provider-builds/types.d.ts +0 -31
  164. package/dist/client/api/providers/api.d.ts +0 -847
  165. package/dist/client/api/providers/schemas.d.ts +0 -1335
  166. package/dist/client/api/providers/types.d.ts +0 -45
  167. package/dist/client/api/schemas.d.ts +0 -15
  168. package/dist/client/api/types.d.ts +0 -15
  169. package/dist/client/api/user-feedback/api.d.ts +0 -9
  170. package/dist/client/api/user-feedback/schemas.d.ts +0 -15
  171. package/dist/client/api/user-feedback/types.d.ts +0 -8
  172. package/dist/client/api/users/api.d.ts +0 -13
  173. package/dist/client/api/users/schemas.d.ts +0 -20
  174. package/dist/client/api/users/types.d.ts +0 -14
  175. package/dist/client/api/variables/api.d.ts +0 -12
  176. package/dist/client/api/variables/schemas.d.ts +0 -13
  177. package/dist/client/api/variables/types.d.ts +0 -10
  178. package/dist/client/core/create-authenticated-fetch.d.ts +0 -5
  179. package/dist/client/core/extensions/extract.d.ts +0 -8
  180. package/dist/client/core/extensions/fulfill.d.ts +0 -8
  181. package/dist/client/core/extensions/resolve-user-metadata.d.ts +0 -6
  182. package/dist/client/core/extensions/types.d.ts +0 -68
  183. package/dist/client/core/fulfillment-resolvers/build-llm-extension-fulfillment-resolver.d.ts +0 -8
  184. package/dist/client/core/handle-agent-card.d.ts +0 -128
  185. package/dist/client/core/handle-task-status-update.d.ts +0 -7
  186. package/dist/client/core/index.d.ts +0 -14
  187. package/dist/client/core/utils/build-message-builder.d.ts +0 -9
  188. package/dist/client/core/utils/get-agent-card-path.d.ts +0 -5
  189. package/dist/core.cjs.map +0 -1
  190. package/dist/core.js.map +0 -1
  191. package/dist/core.umd.js +0 -2
  192. package/dist/core.umd.js.map +0 -1
  193. package/dist/extensions.cjs.map +0 -1
  194. package/dist/extensions.js.map +0 -1
  195. package/dist/extensions.umd.js +0 -2
  196. package/dist/extensions.umd.js.map +0 -1
  197. package/dist/index.cjs.map +0 -1
  198. package/dist/index.js.map +0 -1
  199. package/dist/index.umd.js.map +0 -1
@@ -0,0 +1,70 @@
1
+ /**
2
+ * Copyright 2025 © BeeAI a Series of LF Projects, LLC
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+
6
+ import type { Message } from '@a2a-js/sdk';
7
+
8
+ import { LLM_EXTENSION_URI, llmFulfillmentsSchema } from '../../../../../extensions';
9
+ import type { ExtensionServer, ExtensionSpec } from '../../../core/extensions/types';
10
+ import type { LLMExtensionDeps, LLMExtensionFulfillments, LLMExtensionParams } from './types';
11
+
12
+ export class LLMExtensionSpec implements ExtensionSpec<LLMExtensionParams, LLMExtensionFulfillments> {
13
+ readonly uri = LLM_EXTENSION_URI;
14
+ readonly params: LLMExtensionParams;
15
+ readonly fulfillmentsSchema = llmFulfillmentsSchema;
16
+
17
+ constructor(params: LLMExtensionParams) {
18
+ this.params = params;
19
+ }
20
+
21
+ toAgentCardExtension() {
22
+ return {
23
+ uri: this.uri,
24
+ required: true,
25
+ params: {
26
+ llm_demands: this.params.demands,
27
+ },
28
+ };
29
+ }
30
+
31
+ parseFulfillments(message: Message) {
32
+ const { metadata } = message;
33
+
34
+ if (!metadata) {
35
+ return undefined;
36
+ }
37
+
38
+ const extensionData = metadata[this.uri];
39
+
40
+ if (!extensionData) {
41
+ return undefined;
42
+ }
43
+
44
+ const { success, data } = this.fulfillmentsSchema.safeParse(extensionData);
45
+
46
+ if (!success) {
47
+ return undefined;
48
+ }
49
+
50
+ return data;
51
+ }
52
+ }
53
+
54
+ export class LLMExtensionServer implements ExtensionServer<
55
+ LLMExtensionDeps,
56
+ LLMExtensionParams,
57
+ LLMExtensionFulfillments
58
+ > {
59
+ readonly spec: LLMExtensionSpec;
60
+
61
+ constructor(params: LLMExtensionParams) {
62
+ this.spec = new LLMExtensionSpec(params);
63
+ }
64
+
65
+ resolveDeps(fulfillments: LLMExtensionFulfillments | undefined): LLMExtensionDeps {
66
+ return {
67
+ fulfillments: fulfillments?.llm_fulfillments,
68
+ };
69
+ }
70
+ }
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Copyright 2025 © BeeAI a Series of LF Projects, LLC
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+
6
+ import type { LLMDemand, LLMFulfillment, LLMFulfillments } from '../../../../../extensions';
7
+
8
+ export interface LLMExtensionParams {
9
+ demands: Record<string, LLMDemand>;
10
+ }
11
+
12
+ export type LLMExtensionFulfillments = LLMFulfillments;
13
+
14
+ export interface LLMExtensionDeps {
15
+ fulfillments?: Record<string, LLMFulfillment>;
16
+ }
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Copyright 2025 © BeeAI a Series of LF Projects, LLC
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+
6
+ import type { ExtensionSpec } from '../../../core/extensions/types';
7
+ import type { PlatformSelfRegistrationExtensionFulfillments, PlatformSelfRegistrationExtensionParams } from './types';
8
+
9
+ export const PLATFORM_SELF_REGISTRATION_EXTENSION_URI =
10
+ 'https://a2a-extensions.agentstack.beeai.dev/services/platform-self-registration/v1';
11
+
12
+ export class PlatformSelfRegistrationExtensionSpec implements ExtensionSpec<
13
+ PlatformSelfRegistrationExtensionParams,
14
+ PlatformSelfRegistrationExtensionFulfillments
15
+ > {
16
+ readonly uri = PLATFORM_SELF_REGISTRATION_EXTENSION_URI;
17
+ readonly params: PlatformSelfRegistrationExtensionParams;
18
+
19
+ constructor(params: PlatformSelfRegistrationExtensionParams) {
20
+ this.params = params;
21
+ }
22
+
23
+ toAgentCardExtension() {
24
+ return {
25
+ uri: this.uri,
26
+ required: false,
27
+ params: this.params,
28
+ };
29
+ }
30
+
31
+ parseFulfillments() {
32
+ return undefined;
33
+ }
34
+ }
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Copyright 2025 © BeeAI a Series of LF Projects, LLC
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+
6
+ export interface PlatformSelfRegistrationExtensionParams extends Record<string, unknown> {
7
+ self_registration_id: string;
8
+ }
9
+
10
+ export type PlatformSelfRegistrationExtensionFulfillments = undefined;
@@ -0,0 +1,95 @@
1
+ /**
2
+ * Copyright 2025 © BeeAI a Series of LF Projects, LLC
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+
6
+ import type {
7
+ Artifact,
8
+ DataPart,
9
+ Message,
10
+ Part,
11
+ TaskArtifactUpdateEvent,
12
+ TaskStatus,
13
+ TaskStatusUpdateEvent,
14
+ TextPart,
15
+ } from '@a2a-js/sdk';
16
+ import { randomUUID } from 'crypto';
17
+
18
+ export function createMessage({
19
+ taskId,
20
+ contextId,
21
+ parts,
22
+ metadata,
23
+ }: {
24
+ taskId: string;
25
+ contextId: string;
26
+ parts: Part[];
27
+ metadata?: Record<string, unknown>;
28
+ }): Message {
29
+ return {
30
+ kind: 'message',
31
+ messageId: randomUUID(),
32
+ role: 'agent',
33
+ taskId,
34
+ contextId,
35
+ parts,
36
+ metadata,
37
+ };
38
+ }
39
+
40
+ export function createTextPart(text: string): TextPart {
41
+ return {
42
+ kind: 'text',
43
+ text,
44
+ };
45
+ }
46
+
47
+ export function createDataPart(data: Record<string, unknown>): DataPart {
48
+ return {
49
+ kind: 'data',
50
+ data,
51
+ };
52
+ }
53
+
54
+ export function createStatusUpdateEvent({
55
+ taskId,
56
+ contextId,
57
+ status,
58
+ final,
59
+ }: {
60
+ taskId: string;
61
+ contextId: string;
62
+ status: TaskStatus;
63
+ final: boolean;
64
+ }): TaskStatusUpdateEvent {
65
+ return {
66
+ kind: 'status-update',
67
+ taskId,
68
+ contextId,
69
+ status,
70
+ final,
71
+ };
72
+ }
73
+
74
+ export function createArtifactUpdateEvent({
75
+ taskId,
76
+ contextId,
77
+ artifact,
78
+ lastChunk,
79
+ append,
80
+ }: {
81
+ taskId: string;
82
+ contextId: string;
83
+ artifact: Artifact;
84
+ lastChunk: boolean;
85
+ append: boolean;
86
+ }): TaskArtifactUpdateEvent {
87
+ return {
88
+ kind: 'artifact-update',
89
+ taskId,
90
+ contextId,
91
+ artifact,
92
+ lastChunk,
93
+ append,
94
+ };
95
+ }
@@ -2,5 +2,5 @@
2
2
  * Copyright 2025 © BeeAI a Series of LF Projects, LLC
3
3
  * SPDX-License-Identifier: Apache-2.0
4
4
  */
5
+
5
6
  export * from './extensions';
6
- export * from './protocol';
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Copyright 2025 © BeeAI a Series of LF Projects, LLC
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+
6
+ import type { Artifact, Message, Part, TaskStatus, TaskStatusUpdateEvent, TextPart } from '@a2a-js/sdk';
7
+
8
+ function isObjectLike(value: unknown) {
9
+ return value != null && typeof value === 'object';
10
+ }
11
+
12
+ export function isAsyncIterable<T>(value: unknown): value is AsyncIterable<T> {
13
+ return isObjectLike(value) && Symbol.asyncIterator in value;
14
+ }
15
+
16
+ export function isMessage(value: unknown): value is Message {
17
+ return isObjectLike(value) && 'kind' in value && value.kind === 'message';
18
+ }
19
+
20
+ export function isArtifact(value: unknown): value is Artifact {
21
+ return isObjectLike(value) && 'artifactId' in value;
22
+ }
23
+
24
+ export function isPart(value: unknown): value is Part {
25
+ return (
26
+ isObjectLike(value) &&
27
+ 'kind' in value &&
28
+ typeof value.kind === 'string' &&
29
+ ['text', 'file', 'data'].includes(value.kind)
30
+ );
31
+ }
32
+
33
+ export function isTextPart(part: Part | undefined): part is TextPart {
34
+ return part != null && part.kind === 'text';
35
+ }
36
+
37
+ export function isTaskStatus(value: unknown): value is TaskStatus {
38
+ return isObjectLike(value) && 'state' in value;
39
+ }
40
+
41
+ export function isTaskStatusUpdateEvent(value: unknown): value is TaskStatusUpdateEvent {
42
+ return isObjectLike(value) && 'kind' in value && value.kind === 'status-update';
43
+ }
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Copyright 2025 © BeeAI a Series of LF Projects, LLC
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+
6
+ import { configSchema } from './schemas';
7
+
8
+ export function loadConfig() {
9
+ return configSchema.parse({
10
+ platformUrl: process.env.PLATFORM_URL,
11
+ productionMode: process.env.PRODUCTION_MODE,
12
+ });
13
+ }
14
+
15
+ export function isProductionMode() {
16
+ return loadConfig().productionMode;
17
+ }
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Copyright 2025 © BeeAI a Series of LF Projects, LLC
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+
6
+ import z from 'zod';
7
+
8
+ export const configSchema = z.object({
9
+ platformUrl: z.string().default('http://127.0.0.1:8333'),
10
+ productionMode: z
11
+ .string()
12
+ .optional()
13
+ .transform((value) => value?.toLowerCase() === 'true' || value === '1')
14
+ .default(false),
15
+ });
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Copyright 2025 © BeeAI a Series of LF Projects, LLC
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+
6
+ import type z from 'zod';
7
+
8
+ import type { configSchema } from './schemas';
9
+
10
+ export type Config = z.infer<typeof configSchema>;
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Copyright 2025 © BeeAI a Series of LF Projects, LLC
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+
6
+ import type { Task } from '@a2a-js/sdk';
7
+
8
+ export class RunContext {
9
+ readonly taskId: string;
10
+ readonly contextId: string;
11
+ readonly task?: Task;
12
+
13
+ constructor(taskId: string, contextId: string, task?: Task) {
14
+ this.taskId = taskId;
15
+ this.contextId = contextId;
16
+ this.task = task;
17
+ }
18
+ }
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Copyright 2025 © BeeAI a Series of LF Projects, LLC
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+
6
+ import type { AgentExtension, Message } from '@a2a-js/sdk';
7
+ import type { z } from 'zod';
8
+
9
+ export interface ExtensionSpec<TParams = unknown, TFulfillments = unknown> {
10
+ uri: string;
11
+ params?: TParams;
12
+ fulfillmentsSchema?: z.ZodSchema<TFulfillments>;
13
+ toAgentCardExtension(): AgentExtension;
14
+ parseFulfillments(message: Message): TFulfillments | undefined;
15
+ }
16
+
17
+ export interface ExtensionServer<TDeps = unknown, TParams = unknown, TFulfillments = unknown> {
18
+ spec: ExtensionSpec<TParams, TFulfillments>;
19
+ resolveDeps(fulfillments: TFulfillments | undefined): TDeps;
20
+ }
21
+
22
+ export type ExtensionConfig<TDeps = unknown> = {
23
+ [K in keyof TDeps]: ExtensionServer<TDeps[K], unknown, unknown>;
24
+ };
@@ -2,5 +2,9 @@
2
2
  * Copyright 2025 © BeeAI a Series of LF Projects, LLC
3
3
  * SPDX-License-Identifier: Apache-2.0
4
4
  */
5
+
6
+ export * from './config';
7
+ export * from './context';
5
8
  export * from './schemas';
9
+ export * from './server';
6
10
  export * from './types';
@@ -2,4 +2,5 @@
2
2
  * Copyright 2025 © BeeAI a Series of LF Projects, LLC
3
3
  * SPDX-License-Identifier: Apache-2.0
4
4
  */
5
- export {};
5
+
6
+ export * from './config/schemas';
@@ -0,0 +1,142 @@
1
+ /**
2
+ * Copyright 2025 © BeeAI a Series of LF Projects, LLC
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+
6
+ import { ApiErrorType } from '../../../../api';
7
+ import { isProductionMode } from '../config';
8
+ import { getErrorMessage, setsEqual, withRetry } from '../utils';
9
+ import { createAgentCardUrl, normalizeDockerHost } from './helpers';
10
+ import type { AutoregistrationOptions } from './types';
11
+
12
+ const VARIABLE_RELOAD_INTERVAL_MS = 5000;
13
+
14
+ export function createAutoregisterToAgentstack(options: AutoregistrationOptions): () => void {
15
+ const { selfRegistrationId, agentCard, host, port, api } = options;
16
+
17
+ let providerId: string | null = null;
18
+ let variableReloadInterval: ReturnType<typeof setInterval> | null = null;
19
+ let configuredVariables = new Set<string>();
20
+ let stopped = false;
21
+
22
+ async function loadVariables(firstRun = false): Promise<void> {
23
+ if (!providerId) {
24
+ return;
25
+ }
26
+
27
+ try {
28
+ const result = await api.listProviderVariables({ id: providerId });
29
+
30
+ if (!result.ok) {
31
+ console.warn(`Failed to load variables: ${result.error.message}`);
32
+
33
+ return;
34
+ }
35
+
36
+ const variables = result.data.variables;
37
+ const oldVariables = configuredVariables;
38
+ const newVariables = new Set<string>();
39
+
40
+ for (const variable of configuredVariables) {
41
+ if (!(variable in variables)) {
42
+ delete process.env[variable];
43
+ }
44
+ }
45
+
46
+ for (const [key, value] of Object.entries(variables)) {
47
+ process.env[key] = value;
48
+ newVariables.add(key);
49
+ }
50
+
51
+ const dirty = !setsEqual(oldVariables, newVariables);
52
+ configuredVariables = newVariables;
53
+
54
+ if (dirty && configuredVariables.size > 0) {
55
+ console.log(`Environment variables reloaded: ${[...configuredVariables].join(', ')}`);
56
+ }
57
+
58
+ if (firstRun && configuredVariables.size > 0) {
59
+ console.log('Environment variables loaded.');
60
+ }
61
+ } catch (error) {
62
+ console.error(`Failed to load variables: ${getErrorMessage(error)}`);
63
+ }
64
+ }
65
+
66
+ async function register(): Promise<void> {
67
+ if (isProductionMode()) {
68
+ console.log('Agent is not automatically registered in production mode.');
69
+
70
+ return;
71
+ }
72
+
73
+ const location = createAgentCardUrl(normalizeDockerHost(host), port, selfRegistrationId);
74
+
75
+ console.log('Registering agent to the Agent Stack platform', { location });
76
+
77
+ try {
78
+ await withRetry(
79
+ async () => {
80
+ const existingResult = await api.readProviderByLocation({
81
+ location: encodeURIComponent(location),
82
+ });
83
+
84
+ if (existingResult.ok) {
85
+ const patchResult = await api.patchProvider({
86
+ id: existingResult.data.id,
87
+ agent_card: agentCard,
88
+ });
89
+
90
+ if (!patchResult.ok) {
91
+ throw new Error(`Failed to patch provider: ${patchResult.error.message}`);
92
+ }
93
+
94
+ providerId = patchResult.data.id;
95
+ } else if (existingResult.error.type === ApiErrorType.Http && existingResult.error.response.status === 404) {
96
+ const createResult = await api.createProvider({
97
+ location,
98
+ agent_card: agentCard,
99
+ });
100
+
101
+ if (!createResult.ok) {
102
+ throw new Error(`Failed to create provider: ${createResult.error.message}`);
103
+ }
104
+
105
+ providerId = createResult.data.id;
106
+ } else {
107
+ throw new Error(`Failed to lookup provider: ${existingResult.error.message}`);
108
+ }
109
+ },
110
+ {
111
+ shouldAbort: () => stopped,
112
+ onRetry: (attempt, _error, delayMs) => {
113
+ console.warn(`Registration attempt ${attempt} failed, retrying in ${delayMs}ms...`);
114
+ },
115
+ },
116
+ );
117
+
118
+ console.log('Agent registered successfully');
119
+
120
+ await loadVariables(true);
121
+
122
+ variableReloadInterval = setInterval(() => {
123
+ loadVariables().catch((error) => console.error('Error during variable reload:', error));
124
+ }, VARIABLE_RELOAD_INTERVAL_MS);
125
+ } catch (error) {
126
+ console.error(`Agent cannot be registered to agentstack server: ${getErrorMessage(error)}`);
127
+ }
128
+ }
129
+
130
+ function stop(): void {
131
+ stopped = true;
132
+
133
+ if (variableReloadInterval) {
134
+ clearInterval(variableReloadInterval);
135
+ variableReloadInterval = null;
136
+ }
137
+ }
138
+
139
+ register();
140
+
141
+ return stop;
142
+ }