@vertesia/client 0.81.1 → 1.0.0-dev.20260203.130115Z

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 (266) hide show
  1. package/package.json +7 -7
  2. package/src/InteractionsApi.ts +21 -1
  3. package/src/MCPOAuthApi.ts +67 -0
  4. package/src/ProjectsApi.ts +23 -2
  5. package/src/client.ts +19 -5
  6. package/src/index.ts +2 -2
  7. package/src/store/CollectionsApi.ts +4 -4
  8. package/src/store/DashboardApi.ts +216 -0
  9. package/src/store/DataApi.ts +516 -0
  10. package/src/store/EmailApi.ts +211 -0
  11. package/src/store/FilesApi.ts +13 -0
  12. package/src/store/HiveMemoryApi.ts +231 -0
  13. package/src/store/IndexingAdminApi.ts +336 -0
  14. package/src/store/IndexingApi.ts +62 -0
  15. package/src/store/ObjectsApi.ts +40 -0
  16. package/src/store/PendingAsksApi.ts +98 -0
  17. package/src/store/QueryApi.ts +110 -0
  18. package/src/store/SchedulesApi.ts +114 -0
  19. package/src/store/ToolsApi.ts +19 -0
  20. package/src/store/WorkflowsApi.ts +310 -48
  21. package/src/store/client.ts +18 -0
  22. package/src/store/index.ts +9 -0
  23. package/lib/cjs/AccountApi.js +0 -85
  24. package/lib/cjs/AccountApi.js.map +0 -1
  25. package/lib/cjs/AccountsApi.js +0 -16
  26. package/lib/cjs/AccountsApi.js.map +0 -1
  27. package/lib/cjs/AnalyticsApi.js +0 -41
  28. package/lib/cjs/AnalyticsApi.js.map +0 -1
  29. package/lib/cjs/ApiKeysApi.js +0 -63
  30. package/lib/cjs/ApiKeysApi.js.map +0 -1
  31. package/lib/cjs/AppsApi.js +0 -119
  32. package/lib/cjs/AppsApi.js.map +0 -1
  33. package/lib/cjs/CommandsApi.js +0 -19
  34. package/lib/cjs/CommandsApi.js.map +0 -1
  35. package/lib/cjs/EnvironmentsApi.js +0 -72
  36. package/lib/cjs/EnvironmentsApi.js.map +0 -1
  37. package/lib/cjs/GroupsApi.js +0 -78
  38. package/lib/cjs/GroupsApi.js.map +0 -1
  39. package/lib/cjs/IamApi.js +0 -53
  40. package/lib/cjs/IamApi.js.map +0 -1
  41. package/lib/cjs/InteractionBase.js +0 -44
  42. package/lib/cjs/InteractionBase.js.map +0 -1
  43. package/lib/cjs/InteractionCatalogApi.js +0 -64
  44. package/lib/cjs/InteractionCatalogApi.js.map +0 -1
  45. package/lib/cjs/InteractionOutput.js +0 -300
  46. package/lib/cjs/InteractionOutput.js.map +0 -1
  47. package/lib/cjs/InteractionResult.example.js +0 -57
  48. package/lib/cjs/InteractionResult.example.js.map +0 -1
  49. package/lib/cjs/InteractionsApi.js +0 -243
  50. package/lib/cjs/InteractionsApi.js.map +0 -1
  51. package/lib/cjs/ProjectsApi.js +0 -53
  52. package/lib/cjs/ProjectsApi.js.map +0 -1
  53. package/lib/cjs/PromptsApi.js +0 -133
  54. package/lib/cjs/PromptsApi.js.map +0 -1
  55. package/lib/cjs/RefsApi.js +0 -14
  56. package/lib/cjs/RefsApi.js.map +0 -1
  57. package/lib/cjs/RunsApi.js +0 -113
  58. package/lib/cjs/RunsApi.js.map +0 -1
  59. package/lib/cjs/SkillsApi.js +0 -39
  60. package/lib/cjs/SkillsApi.js.map +0 -1
  61. package/lib/cjs/StreamSource.js +0 -17
  62. package/lib/cjs/StreamSource.js.map +0 -1
  63. package/lib/cjs/TrainingApi.js +0 -54
  64. package/lib/cjs/TrainingApi.js.map +0 -1
  65. package/lib/cjs/UsersApi.js +0 -13
  66. package/lib/cjs/UsersApi.js.map +0 -1
  67. package/lib/cjs/client.js +0 -351
  68. package/lib/cjs/client.js.map +0 -1
  69. package/lib/cjs/execute.js +0 -158
  70. package/lib/cjs/execute.js.map +0 -1
  71. package/lib/cjs/index.js +0 -22
  72. package/lib/cjs/index.js.map +0 -1
  73. package/lib/cjs/nodejs/NodeStreamSource.js +0 -45
  74. package/lib/cjs/nodejs/NodeStreamSource.js.map +0 -1
  75. package/lib/cjs/nodejs/index.js +0 -18
  76. package/lib/cjs/nodejs/index.js.map +0 -1
  77. package/lib/cjs/package.json +0 -3
  78. package/lib/cjs/store/AnalyzeDocApi.js +0 -56
  79. package/lib/cjs/store/AnalyzeDocApi.js.map +0 -1
  80. package/lib/cjs/store/CollectionsApi.js +0 -131
  81. package/lib/cjs/store/CollectionsApi.js.map +0 -1
  82. package/lib/cjs/store/CommandsApi.js +0 -17
  83. package/lib/cjs/store/CommandsApi.js.map +0 -1
  84. package/lib/cjs/store/EmbeddingsApi.js +0 -29
  85. package/lib/cjs/store/EmbeddingsApi.js.map +0 -1
  86. package/lib/cjs/store/FilesApi.js +0 -225
  87. package/lib/cjs/store/FilesApi.js.map +0 -1
  88. package/lib/cjs/store/ObjectsApi.js +0 -283
  89. package/lib/cjs/store/ObjectsApi.js.map +0 -1
  90. package/lib/cjs/store/TypesApi.js +0 -57
  91. package/lib/cjs/store/TypesApi.js.map +0 -1
  92. package/lib/cjs/store/WorkersApi.js +0 -16
  93. package/lib/cjs/store/WorkersApi.js.map +0 -1
  94. package/lib/cjs/store/WorkflowsApi.js +0 -425
  95. package/lib/cjs/store/WorkflowsApi.js.map +0 -1
  96. package/lib/cjs/store/client.js +0 -71
  97. package/lib/cjs/store/client.js.map +0 -1
  98. package/lib/cjs/store/errors.js +0 -11
  99. package/lib/cjs/store/errors.js.map +0 -1
  100. package/lib/cjs/store/index.js +0 -23
  101. package/lib/cjs/store/index.js.map +0 -1
  102. package/lib/cjs/store/version.js +0 -6
  103. package/lib/cjs/store/version.js.map +0 -1
  104. package/lib/esm/AccountApi.js +0 -82
  105. package/lib/esm/AccountApi.js.map +0 -1
  106. package/lib/esm/AccountsApi.js +0 -13
  107. package/lib/esm/AccountsApi.js.map +0 -1
  108. package/lib/esm/AnalyticsApi.js +0 -38
  109. package/lib/esm/AnalyticsApi.js.map +0 -1
  110. package/lib/esm/ApiKeysApi.js +0 -59
  111. package/lib/esm/ApiKeysApi.js.map +0 -1
  112. package/lib/esm/AppsApi.js +0 -116
  113. package/lib/esm/AppsApi.js.map +0 -1
  114. package/lib/esm/CommandsApi.js +0 -16
  115. package/lib/esm/CommandsApi.js.map +0 -1
  116. package/lib/esm/EnvironmentsApi.js +0 -69
  117. package/lib/esm/EnvironmentsApi.js.map +0 -1
  118. package/lib/esm/GroupsApi.js +0 -74
  119. package/lib/esm/GroupsApi.js.map +0 -1
  120. package/lib/esm/IamApi.js +0 -47
  121. package/lib/esm/IamApi.js.map +0 -1
  122. package/lib/esm/InteractionBase.js +0 -40
  123. package/lib/esm/InteractionBase.js.map +0 -1
  124. package/lib/esm/InteractionCatalogApi.js +0 -60
  125. package/lib/esm/InteractionCatalogApi.js.map +0 -1
  126. package/lib/esm/InteractionOutput.js +0 -293
  127. package/lib/esm/InteractionOutput.js.map +0 -1
  128. package/lib/esm/InteractionResult.example.js +0 -55
  129. package/lib/esm/InteractionResult.example.js.map +0 -1
  130. package/lib/esm/InteractionsApi.js +0 -240
  131. package/lib/esm/InteractionsApi.js.map +0 -1
  132. package/lib/esm/ProjectsApi.js +0 -50
  133. package/lib/esm/ProjectsApi.js.map +0 -1
  134. package/lib/esm/PromptsApi.js +0 -130
  135. package/lib/esm/PromptsApi.js.map +0 -1
  136. package/lib/esm/RefsApi.js +0 -10
  137. package/lib/esm/RefsApi.js.map +0 -1
  138. package/lib/esm/RunsApi.js +0 -109
  139. package/lib/esm/RunsApi.js.map +0 -1
  140. package/lib/esm/SkillsApi.js +0 -36
  141. package/lib/esm/SkillsApi.js.map +0 -1
  142. package/lib/esm/StreamSource.js +0 -13
  143. package/lib/esm/StreamSource.js.map +0 -1
  144. package/lib/esm/TrainingApi.js +0 -51
  145. package/lib/esm/TrainingApi.js.map +0 -1
  146. package/lib/esm/UsersApi.js +0 -10
  147. package/lib/esm/UsersApi.js.map +0 -1
  148. package/lib/esm/client.js +0 -342
  149. package/lib/esm/client.js.map +0 -1
  150. package/lib/esm/execute.js +0 -118
  151. package/lib/esm/execute.js.map +0 -1
  152. package/lib/esm/index.js +0 -6
  153. package/lib/esm/index.js.map +0 -1
  154. package/lib/esm/nodejs/NodeStreamSource.js +0 -41
  155. package/lib/esm/nodejs/NodeStreamSource.js.map +0 -1
  156. package/lib/esm/nodejs/index.js +0 -2
  157. package/lib/esm/nodejs/index.js.map +0 -1
  158. package/lib/esm/store/AnalyzeDocApi.js +0 -52
  159. package/lib/esm/store/AnalyzeDocApi.js.map +0 -1
  160. package/lib/esm/store/CollectionsApi.js +0 -127
  161. package/lib/esm/store/CollectionsApi.js.map +0 -1
  162. package/lib/esm/store/CommandsApi.js +0 -13
  163. package/lib/esm/store/CommandsApi.js.map +0 -1
  164. package/lib/esm/store/EmbeddingsApi.js +0 -25
  165. package/lib/esm/store/EmbeddingsApi.js.map +0 -1
  166. package/lib/esm/store/FilesApi.js +0 -219
  167. package/lib/esm/store/FilesApi.js.map +0 -1
  168. package/lib/esm/store/ObjectsApi.js +0 -279
  169. package/lib/esm/store/ObjectsApi.js.map +0 -1
  170. package/lib/esm/store/TypesApi.js +0 -53
  171. package/lib/esm/store/TypesApi.js.map +0 -1
  172. package/lib/esm/store/WorkersApi.js +0 -12
  173. package/lib/esm/store/WorkersApi.js.map +0 -1
  174. package/lib/esm/store/WorkflowsApi.js +0 -419
  175. package/lib/esm/store/WorkflowsApi.js.map +0 -1
  176. package/lib/esm/store/client.js +0 -67
  177. package/lib/esm/store/client.js.map +0 -1
  178. package/lib/esm/store/errors.js +0 -7
  179. package/lib/esm/store/errors.js.map +0 -1
  180. package/lib/esm/store/index.js +0 -7
  181. package/lib/esm/store/index.js.map +0 -1
  182. package/lib/esm/store/version.js +0 -3
  183. package/lib/esm/store/version.js.map +0 -1
  184. package/lib/tsconfig.tsbuildinfo +0 -1
  185. package/lib/types/AccountApi.d.ts +0 -59
  186. package/lib/types/AccountApi.d.ts.map +0 -1
  187. package/lib/types/AccountsApi.d.ts +0 -7
  188. package/lib/types/AccountsApi.d.ts.map +0 -1
  189. package/lib/types/AnalyticsApi.d.ts +0 -11
  190. package/lib/types/AnalyticsApi.d.ts.map +0 -1
  191. package/lib/types/ApiKeysApi.d.ts +0 -42
  192. package/lib/types/ApiKeysApi.d.ts.map +0 -1
  193. package/lib/types/AppsApi.d.ts +0 -65
  194. package/lib/types/AppsApi.d.ts.map +0 -1
  195. package/lib/types/CommandsApi.d.ts +0 -10
  196. package/lib/types/CommandsApi.d.ts.map +0 -1
  197. package/lib/types/EnvironmentsApi.d.ts +0 -40
  198. package/lib/types/EnvironmentsApi.d.ts.map +0 -1
  199. package/lib/types/GroupsApi.d.ts +0 -65
  200. package/lib/types/GroupsApi.d.ts.map +0 -1
  201. package/lib/types/IamApi.d.ts +0 -41
  202. package/lib/types/IamApi.d.ts.map +0 -1
  203. package/lib/types/InteractionBase.d.ts +0 -22
  204. package/lib/types/InteractionBase.d.ts.map +0 -1
  205. package/lib/types/InteractionCatalogApi.d.ts +0 -36
  206. package/lib/types/InteractionCatalogApi.d.ts.map +0 -1
  207. package/lib/types/InteractionOutput.d.ts +0 -174
  208. package/lib/types/InteractionOutput.d.ts.map +0 -1
  209. package/lib/types/InteractionResult.example.d.ts +0 -6
  210. package/lib/types/InteractionResult.example.d.ts.map +0 -1
  211. package/lib/types/InteractionsApi.d.ts +0 -165
  212. package/lib/types/InteractionsApi.d.ts.map +0 -1
  213. package/lib/types/ProjectsApi.d.ts +0 -18
  214. package/lib/types/ProjectsApi.d.ts.map +0 -1
  215. package/lib/types/PromptsApi.d.ts +0 -106
  216. package/lib/types/PromptsApi.d.ts.map +0 -1
  217. package/lib/types/RefsApi.d.ts +0 -6
  218. package/lib/types/RefsApi.d.ts.map +0 -1
  219. package/lib/types/RunsApi.d.ts +0 -79
  220. package/lib/types/RunsApi.d.ts.map +0 -1
  221. package/lib/types/SkillsApi.d.ts +0 -26
  222. package/lib/types/SkillsApi.d.ts.map +0 -1
  223. package/lib/types/StreamSource.d.ts +0 -7
  224. package/lib/types/StreamSource.d.ts.map +0 -1
  225. package/lib/types/TrainingApi.d.ts +0 -27
  226. package/lib/types/TrainingApi.d.ts.map +0 -1
  227. package/lib/types/UsersApi.d.ts +0 -6
  228. package/lib/types/UsersApi.d.ts.map +0 -1
  229. package/lib/types/client.d.ts +0 -125
  230. package/lib/types/client.d.ts.map +0 -1
  231. package/lib/types/execute.d.ts +0 -37
  232. package/lib/types/execute.d.ts.map +0 -1
  233. package/lib/types/index.d.ts +0 -10
  234. package/lib/types/index.d.ts.map +0 -1
  235. package/lib/types/nodejs/NodeStreamSource.d.ts +0 -9
  236. package/lib/types/nodejs/NodeStreamSource.d.ts.map +0 -1
  237. package/lib/types/nodejs/index.d.ts +0 -1
  238. package/lib/types/nodejs/index.d.ts.map +0 -1
  239. package/lib/types/store/AnalyzeDocApi.d.ts +0 -17
  240. package/lib/types/store/AnalyzeDocApi.d.ts.map +0 -1
  241. package/lib/types/store/CollectionsApi.d.ts +0 -82
  242. package/lib/types/store/CollectionsApi.d.ts.map +0 -1
  243. package/lib/types/store/CommandsApi.d.ts +0 -10
  244. package/lib/types/store/CommandsApi.d.ts.map +0 -1
  245. package/lib/types/store/EmbeddingsApi.d.ts +0 -12
  246. package/lib/types/store/EmbeddingsApi.d.ts.map +0 -1
  247. package/lib/types/store/FilesApi.d.ts +0 -103
  248. package/lib/types/store/FilesApi.d.ts.map +0 -1
  249. package/lib/types/store/ObjectsApi.d.ts +0 -117
  250. package/lib/types/store/ObjectsApi.d.ts.map +0 -1
  251. package/lib/types/store/TypesApi.d.ts +0 -23
  252. package/lib/types/store/TypesApi.d.ts.map +0 -1
  253. package/lib/types/store/WorkersApi.d.ts +0 -6
  254. package/lib/types/store/WorkersApi.d.ts.map +0 -1
  255. package/lib/types/store/WorkflowsApi.d.ts +0 -71
  256. package/lib/types/store/WorkflowsApi.d.ts.map +0 -1
  257. package/lib/types/store/client.d.ts +0 -35
  258. package/lib/types/store/client.d.ts.map +0 -1
  259. package/lib/types/store/errors.d.ts +0 -4
  260. package/lib/types/store/errors.d.ts.map +0 -1
  261. package/lib/types/store/index.d.ts +0 -6
  262. package/lib/types/store/index.d.ts.map +0 -1
  263. package/lib/types/store/version.d.ts +0 -2
  264. package/lib/types/store/version.d.ts.map +0 -1
  265. package/lib/vertesia-client.js +0 -2
  266. package/lib/vertesia-client.js.map +0 -1
@@ -0,0 +1,211 @@
1
+ import { ApiTopic, ClientBase } from "@vertesia/api-fetch-client";
2
+ import { EmailRouteData } from "@vertesia/common";
3
+
4
+ /**
5
+ * Request payload for sending an email via the agent.
6
+ * Resend configuration is fetched from project settings.
7
+ * From address is constructed as: {project_namespace}+{agent_name}@{email_domain}
8
+ */
9
+ export interface SendEmailRequest {
10
+ /** Email address to send to */
11
+ to_email: string;
12
+ /** Email subject */
13
+ subject: string;
14
+ /** Email body in markdown format */
15
+ body: string;
16
+ /** Agent/interaction endpoint name (used in from address) */
17
+ agent_name: string;
18
+ /** Display name for the sender (overrides project default) */
19
+ from_name?: string;
20
+ /** Workflow run ID for routing replies */
21
+ run_id: string;
22
+ /** Existing route key (for subsequent emails in same conversation) */
23
+ route_key?: string;
24
+ /** Message ID for In-Reply-To header (email threading) */
25
+ in_reply_to?: string;
26
+ /** Chain of message IDs for References header */
27
+ references?: string[];
28
+ }
29
+
30
+ /**
31
+ * Response from sending an email.
32
+ */
33
+ export interface SendEmailResponse {
34
+ success: boolean;
35
+ /** Resend email ID */
36
+ email_id?: string;
37
+ /** Message-ID header for threading */
38
+ message_id?: string;
39
+ /** Short route key for reply routing */
40
+ route_key?: string;
41
+ /** Error message if failed */
42
+ error?: string;
43
+ }
44
+
45
+ /**
46
+ * Response from creating an email route.
47
+ */
48
+ export interface CreateRouteResponse {
49
+ /** The generated route key (8-char alphanumeric) */
50
+ route_key: string;
51
+ /** Full reply-to address: r+{route_key}@{email_domain} */
52
+ reply_to: string;
53
+ /** The email domain for sending and receiving */
54
+ email_domain: string;
55
+ }
56
+
57
+ /**
58
+ * Request to forward an email to a workflow.
59
+ * Used by external services that handle email reception themselves.
60
+ */
61
+ export interface ForwardEmailRequest {
62
+ /** Email content received by the external service */
63
+ email: {
64
+ /** Sender email address */
65
+ from: string;
66
+ /** Email subject */
67
+ subject?: string;
68
+ /** Plain text body */
69
+ text: string;
70
+ /** HTML body (optional) */
71
+ html?: string;
72
+ /** Message-ID header for threading */
73
+ message_id?: string;
74
+ };
75
+ /** Custom context data from the external service (e.g., auth tokens, user IDs) */
76
+ context?: Record<string, unknown>;
77
+ /** Attachments with download URLs */
78
+ attachments?: Array<{
79
+ filename: string;
80
+ content_type: string;
81
+ size: number;
82
+ download_url: string;
83
+ }>;
84
+ }
85
+
86
+ /**
87
+ * Response from forwarding an email.
88
+ */
89
+ export interface ForwardEmailResponse {
90
+ success: boolean;
91
+ run_id: string;
92
+ workflow_id: string;
93
+ route_key: string;
94
+ }
95
+
96
+ /**
97
+ * Request to create an email route.
98
+ */
99
+ export interface CreateRouteRequest {
100
+ /** Workflow run ID for routing replies */
101
+ run_id: string;
102
+ /** Email address of the user (for context) */
103
+ user_email: string;
104
+ /** Subject of the email thread (optional) */
105
+ thread_subject?: string;
106
+ }
107
+
108
+ /**
109
+ * Email API for sending emails from workflows.
110
+ */
111
+ export class EmailApi extends ApiTopic {
112
+ constructor(parent: ClientBase) {
113
+ super(parent, "/api/v1/email");
114
+ }
115
+
116
+ /**
117
+ * Send an email from an agent/workflow.
118
+ * Creates a route key if not provided, sends via Resend, and returns routing info.
119
+ */
120
+ send(request: SendEmailRequest): Promise<SendEmailResponse> {
121
+ return this.post("/send", { payload: request });
122
+ }
123
+
124
+ /**
125
+ * Resolve a route key to get email context.
126
+ * Used by webhook handler to look up workflow info from reply email.
127
+ * @deprecated Use getRoute() instead
128
+ */
129
+ resolveRoute(routeKey: string): Promise<EmailRouteData> {
130
+ return this.post("/resolve-route", { payload: { route_key: routeKey } });
131
+ }
132
+
133
+ // ============================================================================
134
+ // Routes API - for external service integration
135
+ // ============================================================================
136
+
137
+ /**
138
+ * Create a new email route without sending an email.
139
+ * Useful for external services that want to handle email sending themselves
140
+ * but need reply routing back to Vertesia workflows.
141
+ *
142
+ * @example
143
+ * ```ts
144
+ * const { route_key, reply_to } = await client.store.email.createRoute({
145
+ * run_id: workflowRunId,
146
+ * user_email: "user@example.com",
147
+ * thread_subject: "Contract Review"
148
+ * });
149
+ * // Use reply_to as the Reply-To header when sending your own email
150
+ * // Replies will be routed back to the workflow
151
+ * ```
152
+ */
153
+ createRoute(request: CreateRouteRequest): Promise<CreateRouteResponse> {
154
+ return this.post("/routes", { payload: request });
155
+ }
156
+
157
+ /**
158
+ * Get an email route by key.
159
+ */
160
+ getRoute(routeKey: string): Promise<EmailRouteData & { route_key: string }> {
161
+ return this.get(`/routes/${routeKey}`);
162
+ }
163
+
164
+ /**
165
+ * Update an email route (e.g., to update threading info).
166
+ */
167
+ updateRoute(routeKey: string, updates: Partial<EmailRouteData>): Promise<{ success: boolean; route_key: string }> {
168
+ return this.put(`/routes/${routeKey}`, { payload: updates });
169
+ }
170
+
171
+ /**
172
+ * Forward an email to a workflow via route key.
173
+ *
174
+ * Use this when your service receives an email reply and needs to forward
175
+ * it to the Vertesia workflow. You can add custom context data (like auth
176
+ * tokens or user IDs) that will be merged into `payload.vars.data`.
177
+ *
178
+ * **Important**: Use camelCase keys in context to match the agent start
179
+ * pattern. This ensures tools work identically whether the agent was
180
+ * started directly or received an email reply.
181
+ *
182
+ * @example
183
+ * ```ts
184
+ * // In your email webhook handler:
185
+ * const result = await client.store.email.forwardEmail(routeKey, {
186
+ * email: {
187
+ * from: inboundEmail.from,
188
+ * subject: inboundEmail.subject,
189
+ * text: inboundEmail.text,
190
+ * message_id: inboundEmail.messageId,
191
+ * },
192
+ * context: {
193
+ * // Use camelCase - merged into payload.vars.data
194
+ * apiKey: generateServiceToken(),
195
+ * tenantId: resolvedUser.tenantId,
196
+ * userId: resolvedUser.id,
197
+ * userEmail: resolvedUser.email,
198
+ * },
199
+ * attachments: inboundEmail.attachments?.map(att => ({
200
+ * filename: att.filename,
201
+ * content_type: att.contentType,
202
+ * size: att.size,
203
+ * download_url: att.url,
204
+ * })),
205
+ * });
206
+ * ```
207
+ */
208
+ forwardEmail(routeKey: string, request: ForwardEmailRequest): Promise<ForwardEmailResponse> {
209
+ return this.post(`/routes/${routeKey}/forward`, { payload: request });
210
+ }
211
+ }
@@ -169,6 +169,19 @@ export class FilesApi extends ApiTopic {
169
169
  return res.body;
170
170
  }
171
171
 
172
+ /**
173
+ * Copy a file to a new destination within the same bucket.
174
+ * @param source - Source file path (relative to project bucket)
175
+ * @param dest - Destination file path (relative to project bucket)
176
+ * @returns The destination file URI
177
+ */
178
+ async copyFile(source: string, dest: string): Promise<string> {
179
+ const response = await this.post("/copy", {
180
+ payload: { source, dest },
181
+ }) as { success: boolean; source: string; dest: string };
182
+ return response.dest;
183
+ }
184
+
172
185
  async uploadMemoryPack(source: StreamSource | File): Promise<string> {
173
186
  const fileId = getMemoryFilePath(source.name);
174
187
  const nameWithExt = source.name.endsWith(".tar.gz")
@@ -0,0 +1,231 @@
1
+ import { ApiTopic, ClientBase } from "@vertesia/api-fetch-client";
2
+ import {
3
+ CreateHiveMemoryPayload,
4
+ FormattedMemoryForAgent,
5
+ HiveMemory,
6
+ HiveMemorySearchParams,
7
+ HiveMemorySearchResult,
8
+ UpdateHiveMemoryPayload,
9
+ } from "@vertesia/common";
10
+
11
+ /**
12
+ * Statistics about hive memories in the project
13
+ */
14
+ export interface HiveMemoryStats {
15
+ total_memories: number;
16
+ by_category: Array<{
17
+ category: string;
18
+ count: number;
19
+ avg_confidence: number;
20
+ total_usage: number;
21
+ }>;
22
+ overall: {
23
+ avgConfidence: number;
24
+ avgUsage: number;
25
+ totalContributions: number;
26
+ };
27
+ }
28
+
29
+ /**
30
+ * Result from recall endpoint
31
+ */
32
+ export interface RecallResult {
33
+ memories: FormattedMemoryForAgent[];
34
+ count: number;
35
+ }
36
+
37
+ /**
38
+ * Client API for managing hive memories.
39
+ *
40
+ * Hive memory is a system for storing and retrieving agent learnings,
41
+ * enabling agents to learn from past runs and share knowledge.
42
+ */
43
+ export class HiveMemoryApi extends ApiTopic {
44
+ constructor(parent: ClientBase) {
45
+ super(parent, "/api/v1/hive-memory");
46
+ }
47
+
48
+ /**
49
+ * List memories in the project.
50
+ *
51
+ * @param options - Optional filters and pagination
52
+ */
53
+ list(options?: {
54
+ category?: string;
55
+ scope?: string;
56
+ limit?: number;
57
+ offset?: number;
58
+ }): Promise<HiveMemory[]> {
59
+ const params = new URLSearchParams();
60
+ if (options?.category) params.set('category', options.category);
61
+ if (options?.scope) params.set('scope', options.scope);
62
+ if (options?.limit) params.set('limit', String(options.limit));
63
+ if (options?.offset) params.set('offset', String(options.offset));
64
+
65
+ const queryString = params.toString();
66
+ return this.get(queryString ? `/?${queryString}` : '/');
67
+ }
68
+
69
+ /**
70
+ * Retrieve a memory by ID.
71
+ */
72
+ retrieve(id: string): Promise<HiveMemory> {
73
+ return this.get(`/${id}`);
74
+ }
75
+
76
+ /**
77
+ * Create a new hive memory.
78
+ *
79
+ * @param payload - Memory content including category, summary, and learnings
80
+ */
81
+ create(payload: CreateHiveMemoryPayload): Promise<HiveMemory> {
82
+ return this.post("/", { payload });
83
+ }
84
+
85
+ /**
86
+ * Update an existing memory with new learnings.
87
+ *
88
+ * This merges new learnings with existing ones rather than replacing them.
89
+ *
90
+ * @param id - Memory ID
91
+ * @param payload - Fields to update/merge
92
+ */
93
+ update(id: string, payload: UpdateHiveMemoryPayload): Promise<HiveMemory> {
94
+ return this.put(`/${id}`, { payload });
95
+ }
96
+
97
+ /**
98
+ * Delete a memory.
99
+ *
100
+ * @param id - Memory ID
101
+ */
102
+ delete(id: string): Promise<{ id: string; deleted: boolean }> {
103
+ return this.del(`/${id}`);
104
+ }
105
+
106
+ /**
107
+ * Search memories using semantic and keyword search.
108
+ *
109
+ * @param params - Search parameters including query, filters, and pagination
110
+ */
111
+ search(params: HiveMemorySearchParams): Promise<HiveMemorySearchResult> {
112
+ return this.post("/search", { payload: params });
113
+ }
114
+
115
+ /**
116
+ * Recall memories for an agent.
117
+ *
118
+ * This is the primary method for agents to retrieve relevant learnings.
119
+ * It searches for memories matching the task description and returns
120
+ * them formatted for agent consumption.
121
+ *
122
+ * @param taskDescription - Description of the current task
123
+ * @param options - Optional filters
124
+ *
125
+ * @example
126
+ * ```typescript
127
+ * const result = await client.hiveMemory.recall(
128
+ * "Extract financial data from PDF documents",
129
+ * {
130
+ * tools: ["extract_text", "analyze_document"],
131
+ * maxResults: 5
132
+ * }
133
+ * );
134
+ * ```
135
+ */
136
+ recall(
137
+ taskDescription: string,
138
+ options?: {
139
+ tools?: string[];
140
+ category?: string;
141
+ maxResults?: number;
142
+ }
143
+ ): Promise<RecallResult> {
144
+ return this.post("/recall", {
145
+ payload: {
146
+ task_description: taskDescription,
147
+ tools: options?.tools,
148
+ category: options?.category,
149
+ max_results: options?.maxResults,
150
+ }
151
+ });
152
+ }
153
+
154
+ /**
155
+ * Get a memory formatted for agent consumption.
156
+ *
157
+ * @param id - Memory ID
158
+ */
159
+ getFormatted(id: string): Promise<FormattedMemoryForAgent> {
160
+ return this.get(`/${id}/formatted`);
161
+ }
162
+
163
+ /**
164
+ * Record that a memory was used.
165
+ *
166
+ * This increments the usage count and helps track memory effectiveness.
167
+ *
168
+ * @param id - Memory ID
169
+ */
170
+ recordUsage(id: string): Promise<{ success: boolean }> {
171
+ return this.post(`/${id}/usage`, {});
172
+ }
173
+
174
+ /**
175
+ * Get memories by category.
176
+ *
177
+ * @param category - Task category (e.g., "document-analysis", "data-extraction")
178
+ * @param options - Pagination options
179
+ */
180
+ getByCategory(
181
+ category: string,
182
+ options?: { limit?: number; offset?: number }
183
+ ): Promise<HiveMemory[]> {
184
+ const params = new URLSearchParams();
185
+ if (options?.limit) params.set('limit', String(options.limit));
186
+ if (options?.offset) params.set('offset', String(options.offset));
187
+
188
+ const queryString = params.toString();
189
+ return this.get(`/category/${category}${queryString ? `?${queryString}` : ''}`);
190
+ }
191
+
192
+ /**
193
+ * Get memory statistics for the project.
194
+ */
195
+ getStats(): Promise<HiveMemoryStats> {
196
+ return this.get("/stats");
197
+ }
198
+
199
+ /**
200
+ * Apply confidence decay to unused memories.
201
+ *
202
+ * Admin operation that reduces confidence scores for memories
203
+ * that haven't been used recently.
204
+ *
205
+ * @param options - Decay parameters
206
+ */
207
+ applyDecay(options?: {
208
+ daysThreshold?: number;
209
+ decayRate?: number;
210
+ }): Promise<{ modified_count: number }> {
211
+ return this.post("/admin/decay", {
212
+ payload: {
213
+ days_threshold: options?.daysThreshold,
214
+ decay_rate: options?.decayRate,
215
+ }
216
+ });
217
+ }
218
+
219
+ /**
220
+ * Archive memories with low confidence scores.
221
+ *
222
+ * Admin operation that removes memories below a confidence threshold.
223
+ *
224
+ * @param threshold - Confidence threshold (0-1), default 0.2
225
+ */
226
+ archiveLowConfidence(threshold?: number): Promise<{ archived_count: number }> {
227
+ return this.post("/admin/archive", {
228
+ payload: { threshold }
229
+ });
230
+ }
231
+ }