@dexto/server 1.2.5

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 (174) hide show
  1. package/LICENSE +44 -0
  2. package/dist/a2a/adapters/index.cjs +42 -0
  3. package/dist/a2a/adapters/index.d.ts +10 -0
  4. package/dist/a2a/adapters/index.d.ts.map +1 -0
  5. package/dist/a2a/adapters/index.js +12 -0
  6. package/dist/a2a/adapters/message.cjs +193 -0
  7. package/dist/a2a/adapters/message.d.ts +50 -0
  8. package/dist/a2a/adapters/message.d.ts.map +1 -0
  9. package/dist/a2a/adapters/message.js +167 -0
  10. package/dist/a2a/adapters/state.cjs +57 -0
  11. package/dist/a2a/adapters/state.d.ts +36 -0
  12. package/dist/a2a/adapters/state.d.ts.map +1 -0
  13. package/dist/a2a/adapters/state.js +32 -0
  14. package/dist/a2a/adapters/task-view.cjs +85 -0
  15. package/dist/a2a/adapters/task-view.d.ts +58 -0
  16. package/dist/a2a/adapters/task-view.d.ts.map +1 -0
  17. package/dist/a2a/adapters/task-view.js +60 -0
  18. package/dist/a2a/index.cjs +51 -0
  19. package/dist/a2a/index.d.ts +15 -0
  20. package/dist/a2a/index.d.ts.map +1 -0
  21. package/dist/a2a/index.js +30 -0
  22. package/dist/a2a/jsonrpc/index.cjs +38 -0
  23. package/dist/a2a/jsonrpc/index.d.ts +11 -0
  24. package/dist/a2a/jsonrpc/index.d.ts.map +1 -0
  25. package/dist/a2a/jsonrpc/index.js +10 -0
  26. package/dist/a2a/jsonrpc/methods.cjs +183 -0
  27. package/dist/a2a/jsonrpc/methods.d.ts +110 -0
  28. package/dist/a2a/jsonrpc/methods.d.ts.map +1 -0
  29. package/dist/a2a/jsonrpc/methods.js +159 -0
  30. package/dist/a2a/jsonrpc/server.cjs +199 -0
  31. package/dist/a2a/jsonrpc/server.d.ts +100 -0
  32. package/dist/a2a/jsonrpc/server.d.ts.map +1 -0
  33. package/dist/a2a/jsonrpc/server.js +175 -0
  34. package/dist/a2a/jsonrpc/types.cjs +47 -0
  35. package/dist/a2a/jsonrpc/types.d.ts +91 -0
  36. package/dist/a2a/jsonrpc/types.d.ts.map +1 -0
  37. package/dist/a2a/jsonrpc/types.js +21 -0
  38. package/dist/a2a/types.cjs +16 -0
  39. package/dist/a2a/types.d.ts +250 -0
  40. package/dist/a2a/types.d.ts.map +1 -0
  41. package/dist/a2a/types.js +0 -0
  42. package/dist/approval/approval-coordinator.cjs +87 -0
  43. package/dist/approval/approval-coordinator.d.ts +52 -0
  44. package/dist/approval/approval-coordinator.d.ts.map +1 -0
  45. package/dist/approval/approval-coordinator.js +63 -0
  46. package/dist/approval/manual-approval-handler.cjs +100 -0
  47. package/dist/approval/manual-approval-handler.d.ts +32 -0
  48. package/dist/approval/manual-approval-handler.d.ts.map +1 -0
  49. package/dist/approval/manual-approval-handler.js +76 -0
  50. package/dist/events/a2a-sse-subscriber.cjs +271 -0
  51. package/dist/events/a2a-sse-subscriber.d.ts +94 -0
  52. package/dist/events/a2a-sse-subscriber.d.ts.map +1 -0
  53. package/dist/events/a2a-sse-subscriber.js +247 -0
  54. package/dist/events/types.cjs +16 -0
  55. package/dist/events/types.d.ts +15 -0
  56. package/dist/events/types.d.ts.map +1 -0
  57. package/dist/events/types.js +0 -0
  58. package/dist/events/webhook-subscriber.cjs +301 -0
  59. package/dist/events/webhook-subscriber.d.ts +64 -0
  60. package/dist/events/webhook-subscriber.d.ts.map +1 -0
  61. package/dist/events/webhook-subscriber.js +269 -0
  62. package/dist/events/webhook-types.cjs +16 -0
  63. package/dist/events/webhook-types.d.ts +91 -0
  64. package/dist/events/webhook-types.d.ts.map +1 -0
  65. package/dist/events/webhook-types.js +0 -0
  66. package/dist/hono/__tests__/test-fixtures.cjs +236 -0
  67. package/dist/hono/__tests__/test-fixtures.d.ts +65 -0
  68. package/dist/hono/__tests__/test-fixtures.d.ts.map +1 -0
  69. package/dist/hono/__tests__/test-fixtures.js +197 -0
  70. package/dist/hono/index.cjs +166 -0
  71. package/dist/hono/index.d.ts +2783 -0
  72. package/dist/hono/index.d.ts.map +1 -0
  73. package/dist/hono/index.js +141 -0
  74. package/dist/hono/middleware/auth.cjs +75 -0
  75. package/dist/hono/middleware/auth.d.ts +3 -0
  76. package/dist/hono/middleware/auth.d.ts.map +1 -0
  77. package/dist/hono/middleware/auth.js +51 -0
  78. package/dist/hono/middleware/cors.cjs +57 -0
  79. package/dist/hono/middleware/cors.d.ts +9 -0
  80. package/dist/hono/middleware/cors.d.ts.map +1 -0
  81. package/dist/hono/middleware/cors.js +33 -0
  82. package/dist/hono/middleware/error.cjs +131 -0
  83. package/dist/hono/middleware/error.d.ts +5 -0
  84. package/dist/hono/middleware/error.d.ts.map +1 -0
  85. package/dist/hono/middleware/error.js +105 -0
  86. package/dist/hono/middleware/redaction.cjs +45 -0
  87. package/dist/hono/middleware/redaction.d.ts +4 -0
  88. package/dist/hono/middleware/redaction.d.ts.map +1 -0
  89. package/dist/hono/middleware/redaction.js +20 -0
  90. package/dist/hono/node/index.cjs +139 -0
  91. package/dist/hono/node/index.d.ts +19 -0
  92. package/dist/hono/node/index.d.ts.map +1 -0
  93. package/dist/hono/node/index.js +115 -0
  94. package/dist/hono/routes/a2a-jsonrpc.cjs +119 -0
  95. package/dist/hono/routes/a2a-jsonrpc.d.ts +46 -0
  96. package/dist/hono/routes/a2a-jsonrpc.d.ts.map +1 -0
  97. package/dist/hono/routes/a2a-jsonrpc.js +95 -0
  98. package/dist/hono/routes/a2a-tasks.cjs +315 -0
  99. package/dist/hono/routes/a2a-tasks.d.ts +530 -0
  100. package/dist/hono/routes/a2a-tasks.d.ts.map +1 -0
  101. package/dist/hono/routes/a2a-tasks.js +291 -0
  102. package/dist/hono/routes/a2a.cjs +36 -0
  103. package/dist/hono/routes/a2a.d.ts +4 -0
  104. package/dist/hono/routes/a2a.d.ts.map +1 -0
  105. package/dist/hono/routes/a2a.js +12 -0
  106. package/dist/hono/routes/agents.cjs +735 -0
  107. package/dist/hono/routes/agents.d.ts +650 -0
  108. package/dist/hono/routes/agents.d.ts.map +1 -0
  109. package/dist/hono/routes/agents.js +711 -0
  110. package/dist/hono/routes/approvals.cjs +125 -0
  111. package/dist/hono/routes/approvals.d.ts +89 -0
  112. package/dist/hono/routes/approvals.d.ts.map +1 -0
  113. package/dist/hono/routes/approvals.js +101 -0
  114. package/dist/hono/routes/greeting.cjs +60 -0
  115. package/dist/hono/routes/greeting.d.ts +19 -0
  116. package/dist/hono/routes/greeting.d.ts.map +1 -0
  117. package/dist/hono/routes/greeting.js +36 -0
  118. package/dist/hono/routes/health.cjs +45 -0
  119. package/dist/hono/routes/health.d.ts +17 -0
  120. package/dist/hono/routes/health.d.ts.map +1 -0
  121. package/dist/hono/routes/health.js +21 -0
  122. package/dist/hono/routes/llm.cjs +298 -0
  123. package/dist/hono/routes/llm.d.ts +294 -0
  124. package/dist/hono/routes/llm.d.ts.map +1 -0
  125. package/dist/hono/routes/llm.js +287 -0
  126. package/dist/hono/routes/mcp.cjs +356 -0
  127. package/dist/hono/routes/mcp.d.ts +246 -0
  128. package/dist/hono/routes/mcp.d.ts.map +1 -0
  129. package/dist/hono/routes/mcp.js +332 -0
  130. package/dist/hono/routes/memory.cjs +192 -0
  131. package/dist/hono/routes/memory.d.ts +146 -0
  132. package/dist/hono/routes/memory.d.ts.map +1 -0
  133. package/dist/hono/routes/memory.js +168 -0
  134. package/dist/hono/routes/messages.cjs +320 -0
  135. package/dist/hono/routes/messages.d.ts +163 -0
  136. package/dist/hono/routes/messages.d.ts.map +1 -0
  137. package/dist/hono/routes/messages.js +296 -0
  138. package/dist/hono/routes/prompts.cjs +228 -0
  139. package/dist/hono/routes/prompts.d.ts +150 -0
  140. package/dist/hono/routes/prompts.d.ts.map +1 -0
  141. package/dist/hono/routes/prompts.js +204 -0
  142. package/dist/hono/routes/resources.cjs +110 -0
  143. package/dist/hono/routes/resources.d.ts +76 -0
  144. package/dist/hono/routes/resources.d.ts.map +1 -0
  145. package/dist/hono/routes/resources.js +86 -0
  146. package/dist/hono/routes/search.cjs +109 -0
  147. package/dist/hono/routes/search.d.ts +137 -0
  148. package/dist/hono/routes/search.d.ts.map +1 -0
  149. package/dist/hono/routes/search.js +85 -0
  150. package/dist/hono/routes/sessions.cjs +366 -0
  151. package/dist/hono/routes/sessions.d.ts +229 -0
  152. package/dist/hono/routes/sessions.d.ts.map +1 -0
  153. package/dist/hono/routes/sessions.js +342 -0
  154. package/dist/hono/routes/webhooks.cjs +228 -0
  155. package/dist/hono/routes/webhooks.d.ts +127 -0
  156. package/dist/hono/routes/webhooks.d.ts.map +1 -0
  157. package/dist/hono/routes/webhooks.js +204 -0
  158. package/dist/hono/schemas/responses.cjs +276 -0
  159. package/dist/hono/schemas/responses.d.ts +1418 -0
  160. package/dist/hono/schemas/responses.d.ts.map +1 -0
  161. package/dist/hono/schemas/responses.js +227 -0
  162. package/dist/hono/types.cjs +16 -0
  163. package/dist/hono/types.d.ts +6 -0
  164. package/dist/hono/types.d.ts.map +1 -0
  165. package/dist/hono/types.js +0 -0
  166. package/dist/index.cjs +38 -0
  167. package/dist/index.d.ts +11 -0
  168. package/dist/index.d.ts.map +1 -0
  169. package/dist/index.js +9 -0
  170. package/dist/mcp/mcp-handler.cjs +145 -0
  171. package/dist/mcp/mcp-handler.d.ts +14 -0
  172. package/dist/mcp/mcp-handler.d.ts.map +1 -0
  173. package/dist/mcp/mcp-handler.js +118 -0
  174. package/package.json +59 -0
package/LICENSE ADDED
@@ -0,0 +1,44 @@
1
+ Elastic License 2.0 (ELv2)
2
+
3
+ **Acceptance**
4
+ By using the software, you agree to all of the terms and conditions below.
5
+
6
+ **Copyright License**
7
+ The licensor grants you a non-exclusive, royalty-free, worldwide, non-sublicensable, non-transferable license to use, copy, distribute, make available, and prepare derivative works of the software, in each case subject to the limitations and conditions below
8
+
9
+ **Limitations**
10
+ You may not provide the software to third parties as a hosted or managed service, where the service provides users with access to any substantial set of the features or functionality of the software.
11
+
12
+ You may not move, change, disable, or circumvent the license key functionality in the software, and you may not remove or obscure any functionality in the software that is protected by the license key.
13
+
14
+ You may not alter, remove, or obscure any licensing, copyright, or other notices of the licensor in the software. Any use of the licensor’s trademarks is subject to applicable law.
15
+
16
+ **Patents**
17
+ The licensor grants you a license, under any patent claims the licensor can license, or becomes able to license, to make, have made, use, sell, offer for sale, import and have imported the software, in each case subject to the limitations and conditions in this license. This license does not cover any patent claims that you cause to be infringed by modifications or additions to the software. If you or your company make any written claim that the software infringes or contributes to infringement of any patent, your patent license for the software granted under these terms ends immediately. If your company makes such a claim, your patent license ends immediately for work on behalf of your company.
18
+
19
+ **Notices**
20
+ You must ensure that anyone who gets a copy of any part of the software from you also gets a copy of these terms.
21
+
22
+ If you modify the software, you must include in any modified copies of the software prominent notices stating that you have modified the software.
23
+
24
+ **No Other Rights**
25
+ These terms do not imply any licenses other than those expressly granted in these terms.
26
+
27
+ **Termination**
28
+ If you use the software in violation of these terms, such use is not licensed, and your licenses will automatically terminate. If the licensor provides you with a notice of your violation, and you cease all violation of this license no later than 30 days after you receive that notice, your licenses will be reinstated retroactively. However, if you violate these terms after such reinstatement, any additional violation of these terms will cause your licenses to terminate automatically and permanently.
29
+
30
+ **No Liability**
31
+ As far as the law allows, the software comes as is, without any warranty or condition, and the licensor will not be liable to you for any damages arising out of these terms or the use or nature of the software, under any kind of legal claim.
32
+
33
+ **Definitions**
34
+ The _licensor_ is the entity offering these terms, and the _software_ is the software the licensor makes available under these terms, including any portion of it.
35
+
36
+ _you_ refers to the individual or entity agreeing to these terms.
37
+
38
+ _your company_ is any legal entity, sole proprietorship, or other kind of organization that you work for, plus all organizations that have control over, are under the control of, or are under common control with that organization. _control_ means ownership of substantially all the assets of an entity, or the power to direct its management and policies by vote, contract, or otherwise. Control can be direct or indirect.
39
+
40
+ _your licenses_ are all the licenses granted to you for the software under these terms.
41
+
42
+ _use_ means anything you do with the software requiring one of your licenses.
43
+
44
+ _trademark_ means trademarks, service marks, and similar rights.
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var adapters_exports = {};
20
+ __export(adapters_exports, {
21
+ TaskView: () => import_task_view.TaskView,
22
+ a2aToInternalMessage: () => import_message.a2aToInternalMessage,
23
+ createTaskView: () => import_task_view.createTaskView,
24
+ deriveTaskState: () => import_state.deriveTaskState,
25
+ deriveTaskStateFromA2A: () => import_state.deriveTaskStateFromA2A,
26
+ internalMessagesToA2A: () => import_message.internalMessagesToA2A,
27
+ internalToA2AMessage: () => import_message.internalToA2AMessage
28
+ });
29
+ module.exports = __toCommonJS(adapters_exports);
30
+ var import_task_view = require("./task-view.js");
31
+ var import_message = require("./message.js");
32
+ var import_state = require("./state.js");
33
+ // Annotate the CommonJS export names for ESM import in node:
34
+ 0 && (module.exports = {
35
+ TaskView,
36
+ a2aToInternalMessage,
37
+ createTaskView,
38
+ deriveTaskState,
39
+ deriveTaskStateFromA2A,
40
+ internalMessagesToA2A,
41
+ internalToA2AMessage
42
+ });
@@ -0,0 +1,10 @@
1
+ /**
2
+ * A2A Protocol Adapters
3
+ *
4
+ * Server-layer adapters for converting between A2A protocol format
5
+ * and Dexto's internal representation.
6
+ */
7
+ export { TaskView, createTaskView } from './task-view.js';
8
+ export { a2aToInternalMessage, internalToA2AMessage, internalMessagesToA2A } from './message.js';
9
+ export { deriveTaskState, deriveTaskStateFromA2A } from './state.js';
10
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/a2a/adapters/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAC1D,OAAO,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AACjG,OAAO,EAAE,eAAe,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC"}
@@ -0,0 +1,12 @@
1
+ import { TaskView, createTaskView } from "./task-view.js";
2
+ import { a2aToInternalMessage, internalToA2AMessage, internalMessagesToA2A } from "./message.js";
3
+ import { deriveTaskState, deriveTaskStateFromA2A } from "./state.js";
4
+ export {
5
+ TaskView,
6
+ a2aToInternalMessage,
7
+ createTaskView,
8
+ deriveTaskState,
9
+ deriveTaskStateFromA2A,
10
+ internalMessagesToA2A,
11
+ internalToA2AMessage
12
+ };
@@ -0,0 +1,193 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var message_exports = {};
20
+ __export(message_exports, {
21
+ a2aToInternalMessage: () => a2aToInternalMessage,
22
+ internalMessagesToA2A: () => internalMessagesToA2A,
23
+ internalToA2AMessage: () => internalToA2AMessage
24
+ });
25
+ module.exports = __toCommonJS(message_exports);
26
+ var import_crypto = require("crypto");
27
+ function a2aToInternalMessage(a2aMsg) {
28
+ let text = "";
29
+ let image;
30
+ let file;
31
+ for (const part of a2aMsg.parts) {
32
+ switch (part.kind) {
33
+ case "text":
34
+ text += (text ? " " : "") + part.text;
35
+ break;
36
+ case "file": {
37
+ const fileData = part.file;
38
+ const mimeType = fileData.mimeType || "";
39
+ const isImage = mimeType.startsWith("image/");
40
+ if (isImage && !image) {
41
+ const data = "bytes" in fileData ? fileData.bytes : fileData.uri;
42
+ image = {
43
+ image: data,
44
+ mimeType
45
+ };
46
+ } else if (!file) {
47
+ const data = "bytes" in fileData ? fileData.bytes : fileData.uri;
48
+ const fileObj = {
49
+ data,
50
+ mimeType
51
+ };
52
+ if (fileData.name) {
53
+ fileObj.filename = fileData.name;
54
+ }
55
+ file = fileObj;
56
+ }
57
+ break;
58
+ }
59
+ case "data":
60
+ text += (text ? "\n" : "") + JSON.stringify(part.data, null, 2);
61
+ break;
62
+ }
63
+ }
64
+ return { text, image, file };
65
+ }
66
+ function internalToA2AMessage(msg, taskId, contextId) {
67
+ if (msg.role === "system") {
68
+ return null;
69
+ }
70
+ const role = msg.role === "user" ? "user" : "agent";
71
+ const parts = [];
72
+ if (typeof msg.content === "string") {
73
+ if (msg.content) {
74
+ parts.push({ kind: "text", text: msg.content });
75
+ }
76
+ } else if (msg.content === null) {
77
+ } else if (Array.isArray(msg.content)) {
78
+ for (const part of msg.content) {
79
+ switch (part.type) {
80
+ case "text":
81
+ parts.push({ kind: "text", text: part.text });
82
+ break;
83
+ case "image": {
84
+ const imageData = part.image;
85
+ const mimeType = part.mimeType || "image/png";
86
+ let fileObj;
87
+ if (imageData instanceof URL || typeof imageData === "string" && imageData.startsWith("http")) {
88
+ fileObj = {
89
+ uri: imageData.toString(),
90
+ mimeType
91
+ };
92
+ } else if (Buffer.isBuffer(imageData)) {
93
+ fileObj = {
94
+ bytes: imageData.toString("base64"),
95
+ mimeType
96
+ };
97
+ } else if (imageData instanceof Uint8Array) {
98
+ fileObj = {
99
+ bytes: Buffer.from(imageData).toString("base64"),
100
+ mimeType
101
+ };
102
+ } else if (imageData instanceof ArrayBuffer) {
103
+ fileObj = {
104
+ bytes: Buffer.from(imageData).toString("base64"),
105
+ mimeType
106
+ };
107
+ } else if (typeof imageData === "string") {
108
+ fileObj = {
109
+ bytes: imageData,
110
+ mimeType
111
+ };
112
+ }
113
+ if (fileObj) {
114
+ parts.push({
115
+ kind: "file",
116
+ file: fileObj
117
+ });
118
+ }
119
+ break;
120
+ }
121
+ case "file": {
122
+ const fileData = part.data;
123
+ const mimeType = part.mimeType;
124
+ let fileObj;
125
+ if (fileData instanceof URL || typeof fileData === "string" && fileData.startsWith("http")) {
126
+ fileObj = {
127
+ uri: fileData.toString(),
128
+ mimeType
129
+ };
130
+ } else if (Buffer.isBuffer(fileData)) {
131
+ fileObj = {
132
+ bytes: fileData.toString("base64"),
133
+ mimeType
134
+ };
135
+ } else if (fileData instanceof Uint8Array) {
136
+ fileObj = {
137
+ bytes: Buffer.from(fileData).toString("base64"),
138
+ mimeType
139
+ };
140
+ } else if (fileData instanceof ArrayBuffer) {
141
+ fileObj = {
142
+ bytes: Buffer.from(fileData).toString("base64"),
143
+ mimeType
144
+ };
145
+ } else if (typeof fileData === "string") {
146
+ fileObj = {
147
+ bytes: fileData,
148
+ mimeType
149
+ };
150
+ }
151
+ if (fileObj) {
152
+ if (part.filename) {
153
+ fileObj.name = part.filename;
154
+ }
155
+ parts.push({
156
+ kind: "file",
157
+ file: fileObj
158
+ });
159
+ }
160
+ break;
161
+ }
162
+ }
163
+ }
164
+ }
165
+ if (parts.length === 0) {
166
+ return null;
167
+ }
168
+ const message = {
169
+ role,
170
+ parts,
171
+ messageId: (0, import_crypto.randomUUID)(),
172
+ kind: "message"
173
+ };
174
+ if (taskId) message.taskId = taskId;
175
+ if (contextId) message.contextId = contextId;
176
+ return message;
177
+ }
178
+ function internalMessagesToA2A(messages, taskId, contextId) {
179
+ const a2aMessages = [];
180
+ for (const msg of messages) {
181
+ const a2aMsg = internalToA2AMessage(msg, taskId, contextId);
182
+ if (a2aMsg !== null) {
183
+ a2aMessages.push(a2aMsg);
184
+ }
185
+ }
186
+ return a2aMessages;
187
+ }
188
+ // Annotate the CommonJS export names for ESM import in node:
189
+ 0 && (module.exports = {
190
+ a2aToInternalMessage,
191
+ internalMessagesToA2A,
192
+ internalToA2AMessage
193
+ });
@@ -0,0 +1,50 @@
1
+ /**
2
+ * A2A Message Format Converters
3
+ *
4
+ * Bidirectional conversion between A2A protocol message format
5
+ * and Dexto's internal message format.
6
+ *
7
+ * These converters live at the server boundary, translating between
8
+ * wire format (A2A) and internal format (DextoAgent).
9
+ */
10
+ import type { InternalMessage } from '@dexto/core';
11
+ import type { Message, ConvertedMessage } from '../types.js';
12
+ /**
13
+ * Convert A2A message to internal format for agent.run().
14
+ *
15
+ * Extracts text, image, and file from A2A parts array.
16
+ * agent.run() expects these as separate parameters.
17
+ *
18
+ * @param a2aMsg A2A protocol message
19
+ * @returns Converted message parts for agent.run()
20
+ */
21
+ export declare function a2aToInternalMessage(a2aMsg: Message): ConvertedMessage;
22
+ /**
23
+ * Convert internal message to A2A format.
24
+ *
25
+ * Maps Dexto's internal message structure to A2A protocol format.
26
+ *
27
+ * Role mapping:
28
+ * - 'user' → 'user'
29
+ * - 'assistant' → 'agent'
30
+ * - 'system' → filtered out (not part of A2A conversation)
31
+ * - 'tool' → 'agent' (tool results presented as agent responses)
32
+ *
33
+ * @param msg Internal message from session history
34
+ * @param taskId Optional task ID to associate message with
35
+ * @param contextId Optional context ID to associate message with
36
+ * @returns A2A protocol message or null if message should be filtered
37
+ */
38
+ export declare function internalToA2AMessage(msg: InternalMessage, taskId?: string, contextId?: string): Message | null;
39
+ /**
40
+ * Convert array of internal messages to A2A messages.
41
+ *
42
+ * Filters out system messages and empty messages.
43
+ *
44
+ * @param messages Internal messages from session history
45
+ * @param taskId Optional task ID to associate messages with
46
+ * @param contextId Optional context ID to associate messages with
47
+ * @returns Array of A2A protocol messages
48
+ */
49
+ export declare function internalMessagesToA2A(messages: InternalMessage[], taskId?: string, contextId?: string): Message[];
50
+ //# sourceMappingURL=message.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"message.d.ts","sourceRoot":"","sources":["../../../src/a2a/adapters/message.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,KAAK,EAAE,OAAO,EAAqB,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAGhF;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,OAAO,GAAG,gBAAgB,CA+CtE;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,oBAAoB,CAChC,GAAG,EAAE,eAAe,EACpB,MAAM,CAAC,EAAE,MAAM,EACf,SAAS,CAAC,EAAE,MAAM,GACnB,OAAO,GAAG,IAAI,CAwJhB;AAED;;;;;;;;;GASG;AACH,wBAAgB,qBAAqB,CACjC,QAAQ,EAAE,eAAe,EAAE,EAC3B,MAAM,CAAC,EAAE,MAAM,EACf,SAAS,CAAC,EAAE,MAAM,GACnB,OAAO,EAAE,CAWX"}
@@ -0,0 +1,167 @@
1
+ import { randomUUID } from "crypto";
2
+ function a2aToInternalMessage(a2aMsg) {
3
+ let text = "";
4
+ let image;
5
+ let file;
6
+ for (const part of a2aMsg.parts) {
7
+ switch (part.kind) {
8
+ case "text":
9
+ text += (text ? " " : "") + part.text;
10
+ break;
11
+ case "file": {
12
+ const fileData = part.file;
13
+ const mimeType = fileData.mimeType || "";
14
+ const isImage = mimeType.startsWith("image/");
15
+ if (isImage && !image) {
16
+ const data = "bytes" in fileData ? fileData.bytes : fileData.uri;
17
+ image = {
18
+ image: data,
19
+ mimeType
20
+ };
21
+ } else if (!file) {
22
+ const data = "bytes" in fileData ? fileData.bytes : fileData.uri;
23
+ const fileObj = {
24
+ data,
25
+ mimeType
26
+ };
27
+ if (fileData.name) {
28
+ fileObj.filename = fileData.name;
29
+ }
30
+ file = fileObj;
31
+ }
32
+ break;
33
+ }
34
+ case "data":
35
+ text += (text ? "\n" : "") + JSON.stringify(part.data, null, 2);
36
+ break;
37
+ }
38
+ }
39
+ return { text, image, file };
40
+ }
41
+ function internalToA2AMessage(msg, taskId, contextId) {
42
+ if (msg.role === "system") {
43
+ return null;
44
+ }
45
+ const role = msg.role === "user" ? "user" : "agent";
46
+ const parts = [];
47
+ if (typeof msg.content === "string") {
48
+ if (msg.content) {
49
+ parts.push({ kind: "text", text: msg.content });
50
+ }
51
+ } else if (msg.content === null) {
52
+ } else if (Array.isArray(msg.content)) {
53
+ for (const part of msg.content) {
54
+ switch (part.type) {
55
+ case "text":
56
+ parts.push({ kind: "text", text: part.text });
57
+ break;
58
+ case "image": {
59
+ const imageData = part.image;
60
+ const mimeType = part.mimeType || "image/png";
61
+ let fileObj;
62
+ if (imageData instanceof URL || typeof imageData === "string" && imageData.startsWith("http")) {
63
+ fileObj = {
64
+ uri: imageData.toString(),
65
+ mimeType
66
+ };
67
+ } else if (Buffer.isBuffer(imageData)) {
68
+ fileObj = {
69
+ bytes: imageData.toString("base64"),
70
+ mimeType
71
+ };
72
+ } else if (imageData instanceof Uint8Array) {
73
+ fileObj = {
74
+ bytes: Buffer.from(imageData).toString("base64"),
75
+ mimeType
76
+ };
77
+ } else if (imageData instanceof ArrayBuffer) {
78
+ fileObj = {
79
+ bytes: Buffer.from(imageData).toString("base64"),
80
+ mimeType
81
+ };
82
+ } else if (typeof imageData === "string") {
83
+ fileObj = {
84
+ bytes: imageData,
85
+ mimeType
86
+ };
87
+ }
88
+ if (fileObj) {
89
+ parts.push({
90
+ kind: "file",
91
+ file: fileObj
92
+ });
93
+ }
94
+ break;
95
+ }
96
+ case "file": {
97
+ const fileData = part.data;
98
+ const mimeType = part.mimeType;
99
+ let fileObj;
100
+ if (fileData instanceof URL || typeof fileData === "string" && fileData.startsWith("http")) {
101
+ fileObj = {
102
+ uri: fileData.toString(),
103
+ mimeType
104
+ };
105
+ } else if (Buffer.isBuffer(fileData)) {
106
+ fileObj = {
107
+ bytes: fileData.toString("base64"),
108
+ mimeType
109
+ };
110
+ } else if (fileData instanceof Uint8Array) {
111
+ fileObj = {
112
+ bytes: Buffer.from(fileData).toString("base64"),
113
+ mimeType
114
+ };
115
+ } else if (fileData instanceof ArrayBuffer) {
116
+ fileObj = {
117
+ bytes: Buffer.from(fileData).toString("base64"),
118
+ mimeType
119
+ };
120
+ } else if (typeof fileData === "string") {
121
+ fileObj = {
122
+ bytes: fileData,
123
+ mimeType
124
+ };
125
+ }
126
+ if (fileObj) {
127
+ if (part.filename) {
128
+ fileObj.name = part.filename;
129
+ }
130
+ parts.push({
131
+ kind: "file",
132
+ file: fileObj
133
+ });
134
+ }
135
+ break;
136
+ }
137
+ }
138
+ }
139
+ }
140
+ if (parts.length === 0) {
141
+ return null;
142
+ }
143
+ const message = {
144
+ role,
145
+ parts,
146
+ messageId: randomUUID(),
147
+ kind: "message"
148
+ };
149
+ if (taskId) message.taskId = taskId;
150
+ if (contextId) message.contextId = contextId;
151
+ return message;
152
+ }
153
+ function internalMessagesToA2A(messages, taskId, contextId) {
154
+ const a2aMessages = [];
155
+ for (const msg of messages) {
156
+ const a2aMsg = internalToA2AMessage(msg, taskId, contextId);
157
+ if (a2aMsg !== null) {
158
+ a2aMessages.push(a2aMsg);
159
+ }
160
+ }
161
+ return a2aMessages;
162
+ }
163
+ export {
164
+ a2aToInternalMessage,
165
+ internalMessagesToA2A,
166
+ internalToA2AMessage
167
+ };
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var state_exports = {};
20
+ __export(state_exports, {
21
+ deriveTaskState: () => deriveTaskState,
22
+ deriveTaskStateFromA2A: () => deriveTaskStateFromA2A
23
+ });
24
+ module.exports = __toCommonJS(state_exports);
25
+ function deriveTaskState(messages) {
26
+ if (messages.length === 0) {
27
+ return "submitted";
28
+ }
29
+ const hasUserMessage = messages.some((m) => m.role === "user");
30
+ const hasAssistantMessage = messages.some((m) => m.role === "assistant");
31
+ if (hasUserMessage && hasAssistantMessage) {
32
+ return "completed";
33
+ }
34
+ if (hasUserMessage && !hasAssistantMessage) {
35
+ return "working";
36
+ }
37
+ return "submitted";
38
+ }
39
+ function deriveTaskStateFromA2A(messages) {
40
+ if (messages.length === 0) {
41
+ return "submitted";
42
+ }
43
+ const hasUserMessage = messages.some((m) => m.role === "user");
44
+ const hasAgentMessage = messages.some((m) => m.role === "agent");
45
+ if (hasUserMessage && hasAgentMessage) {
46
+ return "completed";
47
+ }
48
+ if (hasUserMessage && !hasAgentMessage) {
49
+ return "working";
50
+ }
51
+ return "submitted";
52
+ }
53
+ // Annotate the CommonJS export names for ESM import in node:
54
+ 0 && (module.exports = {
55
+ deriveTaskState,
56
+ deriveTaskStateFromA2A
57
+ });
@@ -0,0 +1,36 @@
1
+ /**
2
+ * A2A Task State Derivation
3
+ *
4
+ * Derives A2A task state from Dexto session state.
5
+ * Tasks don't have their own state - state is computed from session history.
6
+ */
7
+ import type { InternalMessage } from '@dexto/core';
8
+ import type { TaskState, Message } from '../types.js';
9
+ /**
10
+ * Derive task state from session message history.
11
+ *
12
+ * Logic per A2A spec:
13
+ * - submitted: Task has been submitted (no messages yet or only user message)
14
+ * - working: Agent is processing the task
15
+ * - completed: Task completed successfully (has complete exchange)
16
+ * - failed: Session encountered an error (would need error tracking)
17
+ * - canceled: Session was explicitly cancelled (would need cancellation tracking)
18
+ *
19
+ * Note: We derive from message patterns, not explicit state tracking.
20
+ * This keeps tasks as pure views over sessions.
21
+ *
22
+ * @param messages Session message history
23
+ * @returns Derived task state
24
+ */
25
+ export declare function deriveTaskState(messages: InternalMessage[]): TaskState;
26
+ /**
27
+ * Derive task state from A2A messages (already converted).
28
+ *
29
+ * This is a convenience function when you already have A2A messages
30
+ * and don't want to go back to internal format.
31
+ *
32
+ * @param messages A2A protocol messages
33
+ * @returns Derived task state
34
+ */
35
+ export declare function deriveTaskStateFromA2A(messages: Message[]): TaskState;
36
+ //# sourceMappingURL=state.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"state.d.ts","sourceRoot":"","sources":["../../../src/a2a/adapters/state.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAEtD;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,eAAe,CAAC,QAAQ,EAAE,eAAe,EAAE,GAAG,SAAS,CAsBtE;AAED;;;;;;;;GAQG;AACH,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,OAAO,EAAE,GAAG,SAAS,CAiBrE"}
@@ -0,0 +1,32 @@
1
+ function deriveTaskState(messages) {
2
+ if (messages.length === 0) {
3
+ return "submitted";
4
+ }
5
+ const hasUserMessage = messages.some((m) => m.role === "user");
6
+ const hasAssistantMessage = messages.some((m) => m.role === "assistant");
7
+ if (hasUserMessage && hasAssistantMessage) {
8
+ return "completed";
9
+ }
10
+ if (hasUserMessage && !hasAssistantMessage) {
11
+ return "working";
12
+ }
13
+ return "submitted";
14
+ }
15
+ function deriveTaskStateFromA2A(messages) {
16
+ if (messages.length === 0) {
17
+ return "submitted";
18
+ }
19
+ const hasUserMessage = messages.some((m) => m.role === "user");
20
+ const hasAgentMessage = messages.some((m) => m.role === "agent");
21
+ if (hasUserMessage && hasAgentMessage) {
22
+ return "completed";
23
+ }
24
+ if (hasUserMessage && !hasAgentMessage) {
25
+ return "working";
26
+ }
27
+ return "submitted";
28
+ }
29
+ export {
30
+ deriveTaskState,
31
+ deriveTaskStateFromA2A
32
+ };