@johpaz/hive-agents 1.1.5 → 1.1.11

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 (206) hide show
  1. package/README.md +4 -10
  2. package/dist/hive.js +218257 -148718
  3. package/dist/tool-worker.js +68422 -1622
  4. package/dist/ui/assets/{A2UIPage-Dr3p75oE.js → A2UIPage-v-VggXW3.js} +4 -4
  5. package/dist/ui/assets/{AgentCreateForm-DqYhH_gm.js → AgentCreateForm-Dr1l4Cvg.js} +1 -1
  6. package/dist/ui/assets/AgentDetailPage-Dsh_grrr.js +1 -0
  7. package/dist/ui/assets/{AgentNewPage-BRpFxJIT.js → AgentNewPage-D7557C0J.js} +1 -1
  8. package/dist/ui/assets/AgentsPage-C_Z56LL1.js +10 -0
  9. package/dist/ui/assets/{ApiClientPage-R9UDWfR2.js → ApiClientPage-uuBnrh0y.js} +1 -1
  10. package/dist/ui/assets/ChannelsPage-BI4mAgRU.js +8 -0
  11. package/dist/ui/assets/DashboardPage-BjAxvzYP.js +6 -0
  12. package/dist/ui/assets/LoginPage-D7IZKON0.js +1 -0
  13. package/dist/ui/assets/{LogsPage-DICMU_7m.js → LogsPage-mcqOYvGw.js} +1 -1
  14. package/dist/ui/assets/MeetingPage-qPJ1z5HA.js +1 -0
  15. package/dist/ui/assets/ModelSelector-njfNhkng.js +1 -0
  16. package/dist/ui/assets/{NotFound-D4ZlDVg9.js → NotFound-DY8e1RKh.js} +1 -1
  17. package/dist/ui/assets/{Office3DPage-31AMJ-LN.css → Office3DPage-C3SIzd2H.css} +1 -1
  18. package/dist/ui/assets/Office3DPage-Du42LRwi.js +319 -0
  19. package/dist/ui/assets/ProvidersPage-GDCJs8Zb.js +1 -0
  20. package/dist/ui/assets/{RecoverPage-Blms3NBa.js → RecoverPage-B6qvBBIl.js} +1 -1
  21. package/dist/ui/assets/SettingsPage-Br4PfWuc.js +9 -0
  22. package/dist/ui/assets/{SetupPage-CAjLseE_.js → SetupPage-OaouFLGD.js} +1 -1
  23. package/dist/ui/assets/{Vignette-DrI2yK2m.js → Vignette-GSZ-owcN.js} +17 -17
  24. package/dist/ui/assets/VoicePage-DRQZBl3j.js +307 -0
  25. package/dist/ui/assets/WebChatPage-Cypq-SYi.js +29 -0
  26. package/dist/ui/assets/{agentCapabilities-CDSfJWhw.js → agentCapabilities-Bf71Gir4.js} +1 -1
  27. package/dist/ui/assets/{alert-CjiX20jI.js → alert-Dn604uVs.js} +1 -1
  28. package/dist/ui/assets/{badge-B5AKge1b.js → badge-C6H33ePv.js} +1 -1
  29. package/dist/ui/assets/{card-mTJ4oZbL.js → card-D0qneq1i.js} +1 -1
  30. package/dist/ui/assets/{conversationsStore-DhM07qYi.js → conversationsStore-D6XgjMr1.js} +1 -1
  31. package/dist/ui/assets/{dialog-BP3GTCPn.js → dialog-DO1fQCF7.js} +1 -1
  32. package/dist/ui/assets/dist-js-C2MfmbEW.js +1 -0
  33. package/dist/ui/assets/{dist-js-CkNhvsFc.js → dist-js-Djxbxbst.js} +1 -1
  34. package/dist/ui/assets/google-external-e9lvWjy4.js +1 -0
  35. package/dist/ui/assets/index-BKNFH2al.css +2 -0
  36. package/dist/ui/assets/index-U0e4e5mL.js +156 -0
  37. package/dist/ui/assets/{key-DPkOY-J0.js → key-round-Ca0Ns34v.js} +1 -1
  38. package/dist/ui/assets/{label-D_fvqJyD.js → label-CvAtVE-v.js} +1 -1
  39. package/dist/ui/assets/{scroll-area-CbH8FOo8.js → scroll-area-CYMu7sU0.js} +1 -1
  40. package/dist/ui/assets/select-BjBXxyxL.js +1 -0
  41. package/dist/ui/assets/{slider-DXS4h1LB.js → slider-DR31eN3r.js} +1 -1
  42. package/dist/ui/assets/{switch-ndx8VCpm.js → switch-B5dAwb54.js} +1 -1
  43. package/dist/ui/assets/{tabs-epu-3Tl4.js → tabs-Ct92cLXr.js} +1 -1
  44. package/dist/ui/assets/{earth-BJRGJbVn.js → terminal-CpBDERBE.js} +1 -1
  45. package/dist/ui/assets/{textarea-BgZJFZTX.js → textarea-xtFAVuPf.js} +1 -1
  46. package/dist/ui/assets/{useAudioDevices-zj0fuGwZ.js → useAudioDevices-wZArmV3m.js} +1 -1
  47. package/dist/ui/assets/{useHiveAgentsModelLoad-Cd9p-bjs.js → useHiveAgentsModelLoad-CqJkzTOT.js} +1 -1
  48. package/dist/ui/assets/useOfficeModel-DZvwZRCw.js +1 -0
  49. package/dist/ui/assets/{useProviders-Dj1k5PCk.js → useProviders-CeSzDnx-.js} +1 -1
  50. package/dist/ui/assets/vendor-router-DxU0Uf4R.js +3 -0
  51. package/dist/ui/index.html +5 -5
  52. package/package.json +1 -3
  53. package/packages/cli/src/commands/onboard.ts +3 -2
  54. package/packages/core/src/agent/agent-catalog.ts +98 -1
  55. package/packages/core/src/agent/agent-loop.ts +5 -44
  56. package/packages/core/src/agent/context-compiler.ts +6 -94
  57. package/packages/core/src/agent/conversation-store.ts +23 -1
  58. package/packages/core/src/agent/llm-providers/openai-compat-base.ts +1 -1
  59. package/packages/core/src/agent/minimal-loadout.ts +1 -0
  60. package/packages/core/src/agent/prompt-builder.ts +17 -1
  61. package/packages/core/src/agent/tool-selector.ts +12 -0
  62. package/packages/core/src/artifacts/store.ts +73 -9
  63. package/packages/core/src/canvas/emitter.ts +0 -19
  64. package/packages/core/src/channels/base.ts +26 -0
  65. package/packages/core/src/channels/discord.ts +18 -2
  66. package/packages/core/src/channels/slack.ts +37 -7
  67. package/packages/core/src/channels/telegram.ts +39 -11
  68. package/packages/core/src/channels/whatsapp.ts +16 -1
  69. package/packages/core/src/gateway/channel-notify.ts +42 -0
  70. package/packages/core/src/gateway/google-host.ts +228 -0
  71. package/packages/core/src/gateway/initializer.ts +8 -0
  72. package/packages/core/src/gateway/routes/agents.ts +14 -0
  73. package/packages/core/src/gateway/routes/artifacts.ts +4 -0
  74. package/packages/core/src/gateway/routes/auth.ts +25 -3
  75. package/packages/core/src/gateway/routes/chat.ts +14 -1
  76. package/packages/core/src/gateway/routes/google.ts +252 -0
  77. package/packages/core/src/gateway/routes/meeting.ts +11 -3
  78. package/packages/core/src/gateway/routes/models.ts +27 -11
  79. package/packages/core/src/gateway/routes/multimodal.ts +38 -0
  80. package/packages/core/src/gateway/routes/providers.ts +19 -18
  81. package/packages/core/src/gateway/routes/system.ts +1 -3
  82. package/packages/core/src/gateway/routes/tts-local.ts +20 -374
  83. package/packages/core/src/gateway/routes/voice.ts +29 -35
  84. package/packages/core/src/gateway/server.ts +97 -48
  85. package/packages/core/src/gateway/tts/README.md +7 -86
  86. package/packages/core/src/gateway/tts/build.py +105 -0
  87. package/packages/core/src/gateway/tts/kitten.ts +282 -0
  88. package/packages/core/src/gateway/tts/python.d.ts +4 -0
  89. package/packages/core/src/gateway/tts/src/detect.ts +33 -39
  90. package/packages/core/src/gateway/tts/worker.py +80 -0
  91. package/packages/core/src/gateway/webchat-turn.ts +15 -13
  92. package/packages/core/src/google/client.ts +123 -0
  93. package/packages/core/src/google/config.ts +60 -0
  94. package/packages/core/src/google/google.test.ts +287 -0
  95. package/packages/core/src/google/index.ts +5 -0
  96. package/packages/core/src/google/oauth.ts +144 -0
  97. package/packages/core/src/google/scopes.ts +41 -0
  98. package/packages/core/src/google/token-store.ts +33 -0
  99. package/packages/core/src/multimodal/attachment-ingest.ts +190 -0
  100. package/packages/core/src/multimodal/image-generation.ts +244 -0
  101. package/packages/core/src/multimodal/vision-analyzer.ts +94 -0
  102. package/packages/core/src/multimodal/vision-service.ts +25 -0
  103. package/packages/core/src/storage/collections.ts +8 -8
  104. package/packages/core/src/storage/google-capabilities.ts +91 -0
  105. package/packages/core/src/storage/model-activation.ts +18 -0
  106. package/packages/core/src/storage/model-sync.ts +66 -14
  107. package/packages/core/src/storage/onboarding.ts +10 -2
  108. package/packages/core/src/storage/seed.ts +107 -24
  109. package/packages/core/src/storage/usage.ts +0 -52
  110. package/packages/core/src/tool-runtime/index.ts +2 -0
  111. package/packages/core/src/tools/agents/get-available-models.ts +1 -3
  112. package/packages/core/src/tools/core/index.ts +80 -2
  113. package/packages/core/src/tools/google/calendar.ts +204 -0
  114. package/packages/core/src/tools/google/drive.ts +160 -0
  115. package/packages/core/src/tools/google/gmail.ts +579 -0
  116. package/packages/core/src/tools/google/index.ts +18 -0
  117. package/packages/core/src/tools/google/shared.ts +80 -0
  118. package/packages/core/src/tools/image/image-generate.ts +90 -0
  119. package/packages/core/src/tools/image/index.ts +13 -0
  120. package/packages/core/src/tools/image/office-leer-imagenes.ts +198 -0
  121. package/packages/core/src/tools/index.ts +27 -0
  122. package/packages/core/src/tools/office/index.ts +9 -0
  123. package/packages/core/src/tools/office/office-editar-docx.ts +184 -0
  124. package/packages/core/src/tools/office/office-editar-pptx.ts +126 -0
  125. package/packages/core/src/tools/office/office-editar-xlsx.ts +122 -0
  126. package/packages/core/src/tools/office/office-escribir-docx.ts +3 -2
  127. package/packages/core/src/tools/office/office-escribir-pdf.ts +3 -2
  128. package/packages/core/src/tools/office/office-escribir-pptx.ts +3 -2
  129. package/packages/core/src/tools/office/office-escribir-xlsx.ts +3 -2
  130. package/packages/core/src/tools/office/office-images.ts +137 -0
  131. package/packages/core/src/tools/office/office-leer-docx.ts +16 -3
  132. package/packages/core/src/tools/office/office-leer-pdf.ts +41 -57
  133. package/packages/core/src/tools/office/office-leer-pptx.ts +54 -88
  134. package/packages/core/src/tools/office/office-leer-xlsx.ts +6 -2
  135. package/packages/core/src/tools/office/office-pdf-images.ts +225 -0
  136. package/packages/core/src/tools/office/pdf-text.ts +186 -0
  137. package/packages/core/src/tools/office/pptx-slides.ts +83 -0
  138. package/packages/core/src/tools/office/resolve-input.ts +49 -0
  139. package/packages/core/src/tools/web/browser-screenshot.ts +7 -0
  140. package/packages/core/src/voice/index.ts +123 -155
  141. package/packages/core/src/voice/local-model.ts +8 -0
  142. package/packages/core/src/voice/stt-models.ts +39 -0
  143. package/packages/skills/src/bundled/google/google_calendar/SKILL.md +51 -0
  144. package/packages/skills/src/bundled/google/google_drive/SKILL.md +50 -0
  145. package/packages/skills/src/bundled/google/google_gmail/SKILL.md +61 -0
  146. package/packages/skills/src/bundled-data.generated.ts +45 -0
  147. package/dist/ui/assets/AgentDetailPage-BVtE88U5.js +0 -1
  148. package/dist/ui/assets/AgentsPage-BOIJ55cj.js +0 -10
  149. package/dist/ui/assets/ChannelsPage-C5V2BmjL.js +0 -8
  150. package/dist/ui/assets/DashboardPage-B18gMzNj.js +0 -6
  151. package/dist/ui/assets/LoginPage-nrsYF9AY.js +0 -1
  152. package/dist/ui/assets/MeetingPage-xslJGfIz.js +0 -1
  153. package/dist/ui/assets/ModelSelector-BX4IvuYY.js +0 -1
  154. package/dist/ui/assets/Office3DPage-a6cuzt5X.js +0 -727
  155. package/dist/ui/assets/ProvidersPage-C8-xGoeh.js +0 -1
  156. package/dist/ui/assets/SettingsPage-BBeeq_QS.js +0 -9
  157. package/dist/ui/assets/VoicePage-BeSSYstD.js +0 -307
  158. package/dist/ui/assets/WebChatPage-Bat7uUfd.js +0 -29
  159. package/dist/ui/assets/dist-js-jWCEHSkB.js +0 -1
  160. package/dist/ui/assets/index-BG3nUPKq.js +0 -156
  161. package/dist/ui/assets/index-DmFPF9xQ.css +0 -2
  162. package/dist/ui/assets/lock-open-v0EphssG.js +0 -1
  163. package/dist/ui/assets/select-v_3QBYrD.js +0 -1
  164. package/dist/ui/assets/terminal-BEcTK780.js +0 -1
  165. package/dist/ui/assets/useOfficeModel-BaDn7U-X.js +0 -1
  166. package/dist/ui/assets/vendor-router-DSMCk-Ka.js +0 -3
  167. package/packages/core/src/agent/jev-decisions.ts +0 -242
  168. package/packages/core/src/agent/jev-planner.ts +0 -293
  169. package/packages/core/src/gateway/tts/package.json +0 -25
  170. package/packages/core/src/gateway/tts/src/client.ts +0 -59
  171. package/packages/core/src/gateway/tts/src/index.ts +0 -15
  172. package/packages/core/src/gateway/tts/src/install.ts +0 -137
  173. package/packages/core/src/gateway/tts/src/models.ts +0 -50
  174. package/packages/core/src/gateway/tts/src/server.ts +0 -253
  175. /package/dist/ui/assets/{core-p4c5dns5.js → core-npANj14X.js} +0 -0
  176. /package/dist/ui/assets/{download-BQXrpH0m.js → download-D0aDV8Y_.js} +0 -0
  177. /package/dist/ui/assets/{ellipsis-vertical-D7uFJLGh.js → ellipsis-vertical-BOW_iEOO.js} +0 -0
  178. /package/dist/ui/assets/{external-link-6oTH9pUM.js → external-link-DNJH7epD.js} +0 -0
  179. /package/dist/ui/assets/{eye-CxvxtQT5.js → eye-BVfTWOME.js} +0 -0
  180. /package/dist/ui/assets/{file-text-D5ZJEx3E.js → file-text-ByqNMpXm.js} +0 -0
  181. /package/dist/ui/assets/{gateway-url-BALS_wVh.js → gateway-url-BzQV75Ig.js} +0 -0
  182. /package/dist/ui/assets/{gauge-CEu7PhTW.js → gauge-CB4np0Vz.js} +0 -0
  183. /package/dist/ui/assets/{history-DLK5rTlP.js → history-CbhJX41s.js} +0 -0
  184. /package/dist/ui/assets/{info-8ReWzubE.js → info-BCD3-QX9.js} +0 -0
  185. /package/dist/ui/assets/{lock-3IApZyVy.js → lock-DpBean4K.js} +0 -0
  186. /package/dist/ui/assets/{mail-vwCEHyhQ.js → mail-Biwn8WrV.js} +0 -0
  187. /package/dist/ui/assets/{mic-CpDU_2as.js → mic-Rq4BxU1R.js} +0 -0
  188. /package/dist/ui/assets/{pause-BAMsNQkh.js → pause-87NGXbsz.js} +0 -0
  189. /package/dist/ui/assets/{pencil-CKritjT_.js → pencil-BG8EFaS3.js} +0 -0
  190. /package/dist/ui/assets/{play-Cwpe4tp6.js → play-D3De6YsQ.js} +0 -0
  191. /package/dist/ui/assets/{plus-RD44ce15.js → plus-Bp8-V68t.js} +0 -0
  192. /package/dist/ui/assets/{radio-lFPMHi6-.js → radio-m7rzuDKK.js} +0 -0
  193. /package/dist/ui/assets/{refresh-cw-DtJMHRHO.js → refresh-cw-D6F1zoC6.js} +0 -0
  194. /package/dist/ui/assets/{rotate-ccw-b3E_4PoX.js → rotate-ccw-DUlEC1_D.js} +0 -0
  195. /package/dist/ui/assets/{search-z2oZt00P.js → search-CfNwwpMW.js} +0 -0
  196. /package/dist/ui/assets/{send-CpoY_2F-.js → send-CI868CBV.js} +0 -0
  197. /package/dist/ui/assets/{settings-qV3kVkeG.js → settings-AEM2uWiD.js} +0 -0
  198. /package/dist/ui/assets/{shield-CIarwBvx.js → shield-DvVIcbzd.js} +0 -0
  199. /package/dist/ui/assets/{sparkles-DVvY6jDT.js → sparkles-DRe4GbSH.js} +0 -0
  200. /package/dist/ui/assets/{square-D5zdNkAY.js → square-DTWkjTT3.js} +0 -0
  201. /package/dist/ui/assets/{trash-2-D6oziYAK.js → trash-2-BZsMCfso.js} +0 -0
  202. /package/dist/ui/assets/{utils-DEmd_M8c.js → utils-lc8H6VGT.js} +0 -0
  203. /package/dist/ui/assets/{volume-2-EaA0JRvD.js → volume-2-CBMYsuF3.js} +0 -0
  204. /package/dist/ui/assets/{volume-x-CROXNMGT.js → volume-x-vNFf2e4-.js} +0 -0
  205. /package/dist/ui/assets/{wifi-BUJuOcgP.js → wifi-DNv53AfN.js} +0 -0
  206. /package/dist/ui/assets/{zap-DSoX9NDk.js → zap-Yed86Sh8.js} +0 -0
@@ -0,0 +1,204 @@
1
+ /**
2
+ * Google Calendar: consultar, crear, modificar y borrar eventos; disponibilidad.
3
+ *
4
+ * @category google
5
+ * @spanish calendario, agenda, evento, reunión, cita, disponibilidad
6
+ */
7
+ import { googleJson } from "../../google/client.ts";
8
+ import { CONFIRMED_PARAM, googleTool, needsConfirmation, num, str } from "./shared.ts";
9
+
10
+ const API = "https://www.googleapis.com/calendar/v3";
11
+ const cal = (p: Record<string, unknown>) => encodeURIComponent(str(p.calendar_id) ?? "primary");
12
+
13
+ function slim(e: any) {
14
+ return {
15
+ id: e.id,
16
+ summary: e.summary,
17
+ start: e.start?.dateTime ?? e.start?.date,
18
+ end: e.end?.dateTime ?? e.end?.date,
19
+ location: e.location,
20
+ description: e.description?.slice(0, 500),
21
+ attendees: (e.attendees ?? []).map((a: any) => ({ email: a.email, status: a.responseStatus })),
22
+ meet_link: e.hangoutLink,
23
+ link: e.htmlLink,
24
+ status: e.status,
25
+ };
26
+ }
27
+
28
+ /** Acepta "2026-12-01T10:00:00-05:00" (con zona) o fecha sin hora (evento de día completo). */
29
+ function when(value: string, timeZone?: string) {
30
+ return /^\d{4}-\d{2}-\d{2}$/.test(value)
31
+ ? { date: value }
32
+ : { dateTime: value, ...(timeZone ? { timeZone } : {}) };
33
+ }
34
+
35
+ const ISO = "ISO 8601. Prefer an explicit offset (2026-12-01T10:00:00-05:00); a bare date creates an all-day event.";
36
+
37
+ export const gcalListEventsTool = googleTool({
38
+ name: "gcal_list_events",
39
+ description:
40
+ "List Google Calendar events in a time range (default: the next 7 days). Spanish: ver agenda, qué tengo hoy, próximos eventos, reuniones de la semana",
41
+ parameters: {
42
+ type: "object",
43
+ properties: {
44
+ time_min: { type: "string", description: `Range start. ${ISO} Default: now.` },
45
+ time_max: { type: "string", description: `Range end. ${ISO} Default: +7 days.` },
46
+ query: { type: "string", description: "Free-text filter." },
47
+ calendar_id: { type: "string", description: "Default: primary." },
48
+ max_results: { type: "number", minimum: 1, maximum: 50, description: "Default 20." },
49
+ },
50
+ },
51
+ run: async (p, { userId }) => {
52
+ const now = Date.now();
53
+ const data = await googleJson<any>(userId, "calendar", `${API}/calendars/${cal(p)}/events`, {
54
+ query: {
55
+ timeMin: str(p.time_min) ?? new Date(now).toISOString(),
56
+ timeMax: str(p.time_max) ?? new Date(now + 7 * 864e5).toISOString(),
57
+ q: str(p.query),
58
+ maxResults: num(p.max_results, 20, 1, 50),
59
+ singleEvents: true,
60
+ orderBy: "startTime",
61
+ },
62
+ });
63
+ const events = (data.items ?? []).map(slim);
64
+ return { ok: true, count: events.length, time_zone: data.timeZone, events };
65
+ },
66
+ });
67
+
68
+ export const gcalCreateEventTool = googleTool({
69
+ name: "gcal_create_event",
70
+ description:
71
+ "Create a Google Calendar event. If it has attendees, Google emails them invitations, so the first call returns needs_confirmation; repeat with confirmed=true after the user approves. " +
72
+ "Spanish: agendar reunión, crear evento, programar cita, invitar asistentes",
73
+ parameters: {
74
+ type: "object",
75
+ properties: {
76
+ summary: { type: "string", description: "Event title." },
77
+ start: { type: "string", description: ISO },
78
+ end: { type: "string", description: ISO },
79
+ time_zone: { type: "string", description: "IANA zone, e.g. America/Bogota. Needed only when start/end have no offset." },
80
+ description: { type: "string" },
81
+ location: { type: "string" },
82
+ attendees: { type: "array", items: { type: "string" }, description: "Attendee emails." },
83
+ add_meet: { type: "boolean", description: "Attach a Google Meet link." },
84
+ calendar_id: { type: "string" },
85
+ confirmed: CONFIRMED_PARAM,
86
+ },
87
+ required: ["summary", "start", "end"],
88
+ },
89
+ run: async (p, { userId }) => {
90
+ const summary = str(p.summary), start = str(p.start), end = str(p.end);
91
+ if (!summary || !start || !end) return { ok: false, error: "summary, start y end son obligatorios." };
92
+ const attendees = Array.isArray(p.attendees) ? p.attendees.filter((a): a is string => typeof a === "string" && a.includes("@")) : [];
93
+ if (attendees.length) {
94
+ const pending = needsConfirmation(p, { summary, start, end, attendees, location: str(p.location) });
95
+ if (pending) return pending;
96
+ }
97
+ const tz = str(p.time_zone);
98
+ const body: Record<string, unknown> = {
99
+ summary,
100
+ start: when(start, tz),
101
+ end: when(end, tz),
102
+ description: str(p.description),
103
+ location: str(p.location),
104
+ attendees: attendees.map((email) => ({ email })),
105
+ };
106
+ if (p.add_meet === true) {
107
+ body.conferenceData = { createRequest: { requestId: crypto.randomUUID(), conferenceSolutionKey: { type: "hangoutsMeet" } } };
108
+ }
109
+ const ev = await googleJson<any>(userId, "calendar", `${API}/calendars/${cal(p)}/events`, {
110
+ method: "POST",
111
+ query: { conferenceDataVersion: p.add_meet === true ? 1 : undefined, sendUpdates: attendees.length ? "all" : "none" },
112
+ body,
113
+ });
114
+ return { ok: true, event: slim(ev) };
115
+ },
116
+ });
117
+
118
+ export const gcalUpdateEventTool = googleTool({
119
+ name: "gcal_update_event",
120
+ description:
121
+ "Modify fields of an existing Google Calendar event (only the ones provided). Needs user confirmation (needs_confirmation, then confirmed=true). Spanish: mover reunión, cambiar evento, reprogramar cita",
122
+ parameters: {
123
+ type: "object",
124
+ properties: {
125
+ event_id: { type: "string" },
126
+ summary: { type: "string" },
127
+ start: { type: "string", description: ISO },
128
+ end: { type: "string", description: ISO },
129
+ time_zone: { type: "string" },
130
+ description: { type: "string" },
131
+ location: { type: "string" },
132
+ calendar_id: { type: "string" },
133
+ confirmed: CONFIRMED_PARAM,
134
+ },
135
+ required: ["event_id"],
136
+ },
137
+ run: async (p, { userId }) => {
138
+ const id = str(p.event_id);
139
+ if (!id) return { ok: false, error: "event_id es obligatorio." };
140
+ const tz = str(p.time_zone);
141
+ const patch: Record<string, unknown> = {};
142
+ for (const k of ["summary", "description", "location"] as const) if (str(p[k]) !== undefined) patch[k] = str(p[k]);
143
+ if (str(p.start)) patch.start = when(str(p.start)!, tz);
144
+ if (str(p.end)) patch.end = when(str(p.end)!, tz);
145
+ if (!Object.keys(patch).length) return { ok: false, error: "No hay ningún campo para modificar." };
146
+ const pending = needsConfirmation(p, { event_id: id, changes: patch });
147
+ if (pending) return pending;
148
+ const ev = await googleJson<any>(userId, "calendar", `${API}/calendars/${cal(p)}/events/${encodeURIComponent(id)}`, {
149
+ method: "PATCH", query: { sendUpdates: "all" }, body: patch,
150
+ });
151
+ return { ok: true, event: slim(ev) };
152
+ },
153
+ });
154
+
155
+ export const gcalDeleteEventTool = googleTool({
156
+ name: "gcal_delete_event",
157
+ description:
158
+ "Delete a Google Calendar event (attendees are notified). IRREVERSIBLE: needs_confirmation first, then confirmed=true. Spanish: cancelar reunión, borrar evento",
159
+ parameters: {
160
+ type: "object",
161
+ properties: { event_id: { type: "string" }, calendar_id: { type: "string" }, confirmed: CONFIRMED_PARAM },
162
+ required: ["event_id"],
163
+ },
164
+ run: async (p, { userId }) => {
165
+ const id = str(p.event_id);
166
+ if (!id) return { ok: false, error: "event_id es obligatorio." };
167
+ const pending = needsConfirmation(p, { event_id: id, action: "delete" });
168
+ if (pending) return pending;
169
+ await googleJson(userId, "calendar", `${API}/calendars/${cal(p)}/events/${encodeURIComponent(id)}`, {
170
+ method: "DELETE", query: { sendUpdates: "all" },
171
+ });
172
+ return { ok: true, deleted: id };
173
+ },
174
+ });
175
+
176
+ export const gcalFreebusyTool = googleTool({
177
+ name: "gcal_freebusy",
178
+ description:
179
+ "Check busy intervals for one or more calendars in a time range to find free slots. Spanish: disponibilidad, horarios libres, cuándo estoy libre",
180
+ parameters: {
181
+ type: "object",
182
+ properties: {
183
+ time_min: { type: "string", description: ISO },
184
+ time_max: { type: "string", description: ISO },
185
+ calendar_ids: { type: "array", items: { type: "string" }, description: "Default: [primary]. Other people's emails work if they share their calendar." },
186
+ },
187
+ required: ["time_min", "time_max"],
188
+ },
189
+ run: async (p, { userId }) => {
190
+ const timeMin = str(p.time_min), timeMax = str(p.time_max);
191
+ if (!timeMin || !timeMax) return { ok: false, error: "time_min y time_max son obligatorios." };
192
+ const ids = Array.isArray(p.calendar_ids) && p.calendar_ids.length ? (p.calendar_ids as string[]).slice(0, 10) : ["primary"];
193
+ const data = await googleJson<any>(userId, "calendar", `${API}/freeBusy`, {
194
+ method: "POST",
195
+ body: { timeMin, timeMax, items: ids.map((id) => ({ id })) },
196
+ });
197
+ const calendars = Object.fromEntries(Object.entries<any>(data.calendars ?? {}).map(([id, c]) => [id, { busy: c.busy ?? [], errors: c.errors }]));
198
+ return { ok: true, calendars };
199
+ },
200
+ });
201
+
202
+ export const calendarTools = [
203
+ gcalListEventsTool, gcalCreateEventTool, gcalUpdateEventTool, gcalDeleteEventTool, gcalFreebusyTool,
204
+ ];
@@ -0,0 +1,160 @@
1
+ /**
2
+ * Google Drive: buscar, descargar/exportar y subir archivos.
3
+ *
4
+ * @category google
5
+ * @spanish drive, archivos, documentos de google, hojas de cálculo, subir archivo
6
+ */
7
+ import { googleFetch, googleJson, GoogleApiError } from "../../google/client.ts";
8
+ import { getWorkspace } from "../filesystem/workspace-guard.ts";
9
+ import { createArtifact, readArtifactBytes } from "../../artifacts/store.ts";
10
+ import { googleTool, num, str } from "./shared.ts";
11
+
12
+ const API = "https://www.googleapis.com/drive/v3";
13
+ const UPLOAD = "https://www.googleapis.com/upload/drive/v3/files";
14
+ const MAX_DOWNLOAD = 50 * 1024 * 1024;
15
+ const INLINE_TEXT = 20_000;
16
+
17
+ /** Google Docs/Sheets/Slides no se descargan: se exportan. */
18
+ const EXPORTS: Record<string, { mime: string; ext: string; text: boolean }> = {
19
+ "application/vnd.google-apps.document": { mime: "text/plain", ext: "txt", text: true },
20
+ "application/vnd.google-apps.spreadsheet": { mime: "text/csv", ext: "csv", text: true },
21
+ "application/vnd.google-apps.presentation": { mime: "application/pdf", ext: "pdf", text: false },
22
+ "application/vnd.google-apps.drawing": { mime: "application/pdf", ext: "pdf", text: false },
23
+ };
24
+
25
+ const esc = (s: string) => s.replace(/\\/g, "\\\\").replace(/'/g, "\\'");
26
+
27
+ export const gdriveSearchTool = googleTool({
28
+ name: "gdrive_search",
29
+ description:
30
+ "Search the user's Google Drive by text (name and content) or with a raw Drive query. Returns id, name, type, modified time and link. " +
31
+ "Spanish: buscar en drive, encontrar archivo, documentos de google",
32
+ parameters: {
33
+ type: "object",
34
+ properties: {
35
+ query: { type: "string", description: "Words to find in the file name or content." },
36
+ raw_query: { type: "string", description: "Advanced Drive `q` expression, e.g. \"mimeType='application/pdf' and modifiedTime > '2026-01-01T00:00:00'\". Overrides query." },
37
+ folder_id: { type: "string", description: "Only search inside this folder." },
38
+ max_results: { type: "number", minimum: 1, maximum: 50, description: "Default 15." },
39
+ },
40
+ },
41
+ run: async (p, { userId }) => {
42
+ const clauses = ["trashed = false"];
43
+ const raw = str(p.raw_query), text = str(p.query), folder = str(p.folder_id);
44
+ if (raw) clauses.push(`(${raw})`);
45
+ else if (text) clauses.push(`(name contains '${esc(text)}' or fullText contains '${esc(text)}')`);
46
+ if (folder) clauses.push(`'${esc(folder)}' in parents`);
47
+ const data = await googleJson<any>(userId, "drive", `${API}/files`, {
48
+ query: {
49
+ q: clauses.join(" and "),
50
+ pageSize: num(p.max_results, 15, 1, 50),
51
+ orderBy: "modifiedTime desc",
52
+ fields: "files(id,name,mimeType,modifiedTime,size,webViewLink,owners(emailAddress))",
53
+ },
54
+ });
55
+ return {
56
+ ok: true,
57
+ count: (data.files ?? []).length,
58
+ files: (data.files ?? []).map((f: any) => ({
59
+ id: f.id, name: f.name, type: f.mimeType, modified: f.modifiedTime,
60
+ size: f.size ? Number(f.size) : undefined, link: f.webViewLink, owner: f.owners?.[0]?.emailAddress,
61
+ })),
62
+ };
63
+ },
64
+ });
65
+
66
+ export const gdriveDownloadTool = googleTool({
67
+ name: "gdrive_download",
68
+ description:
69
+ "Download a Drive file (or export a Google Doc as text, a Sheet as CSV, Slides as PDF) into a Hive artifact. Text content up to 20k chars is also returned inline. " +
70
+ "Spanish: descargar de drive, leer documento de google, abrir archivo de drive",
71
+ parameters: {
72
+ type: "object",
73
+ properties: { file_id: { type: "string", description: "Id returned by gdrive_search." } },
74
+ required: ["file_id"],
75
+ },
76
+ run: async (p, { userId, config }) => {
77
+ const id = str(p.file_id);
78
+ if (!id) return { ok: false, error: "file_id es obligatorio." };
79
+ const meta = await googleJson<any>(userId, "drive", `${API}/files/${encodeURIComponent(id)}`, {
80
+ query: { fields: "id,name,mimeType,size" },
81
+ });
82
+ const exp = EXPORTS[meta.mimeType];
83
+ if (!exp && meta.mimeType?.startsWith("application/vnd.google-apps.")) {
84
+ return { ok: false, error: `Los archivos de tipo ${meta.mimeType} no se pueden descargar.` };
85
+ }
86
+ if (meta.size && Number(meta.size) > MAX_DOWNLOAD) {
87
+ return { ok: false, error: `El archivo pesa ${Math.round(Number(meta.size) / 1048576)} MB; el límite es ${MAX_DOWNLOAD / 1048576} MB.` };
88
+ }
89
+ const res = exp
90
+ ? await googleFetch(userId, "drive", `${API}/files/${encodeURIComponent(id)}/export`, { query: { mimeType: exp.mime } })
91
+ : await googleFetch(userId, "drive", `${API}/files/${encodeURIComponent(id)}`, { query: { alt: "media" } });
92
+ if (!res.ok) throw new GoogleApiError(res.status, (await res.text()).slice(0, 300));
93
+ const bytes = new Uint8Array(await res.arrayBuffer());
94
+ const mimeType = exp?.mime ?? meta.mimeType ?? "application/octet-stream";
95
+ const ext = exp?.ext ?? (/\.([A-Za-z0-9]{1,8})$/.exec(meta.name)?.[1]?.toLowerCase());
96
+ const artifact = await createArtifact({
97
+ bytes, mimeType, kind: "gdrive_download", userId, extension: ext,
98
+ visible: { workspace: getWorkspace(config), folder: "descargas", label: meta.name.replace(/\.[^.]+$/, "") },
99
+ runId: config?.configurable?.run_id ?? null, taskId: config?.configurable?.task_id ?? null,
100
+ });
101
+ const isText = exp?.text ?? /^text\//.test(mimeType);
102
+ const text = isText ? Buffer.from(bytes).toString("utf-8") : undefined;
103
+ return {
104
+ ok: true, name: meta.name, mime_type: mimeType, size: bytes.byteLength, artifact_id: artifact.id,
105
+ ...(text !== undefined ? { text: text.slice(0, INLINE_TEXT), truncated: text.length > INLINE_TEXT } : {}),
106
+ };
107
+ },
108
+ });
109
+
110
+ export const gdriveUploadTool = googleTool({
111
+ name: "gdrive_upload",
112
+ description:
113
+ "Upload a file to the user's Google Drive from text `content` or from a Hive artifact (artifact_id). Creates a new file; never overwrites. " +
114
+ "Spanish: subir a drive, guardar en drive, enviar archivo a drive",
115
+ parameters: {
116
+ type: "object",
117
+ properties: {
118
+ name: { type: "string", description: "File name including extension." },
119
+ content: { type: "string", description: "Text content (alternative to artifact_id)." },
120
+ artifact_id: { type: "string", description: "Hive artifact to upload (alternative to content)." },
121
+ mime_type: { type: "string", description: "Default: taken from the artifact, or text/plain." },
122
+ folder_id: { type: "string", description: "Destination folder id. Default: Drive root." },
123
+ },
124
+ required: ["name"],
125
+ },
126
+ run: async (p, { userId }) => {
127
+ const name = str(p.name);
128
+ if (!name) return { ok: false, error: "name es obligatorio." };
129
+ let bytes: Uint8Array, mime = str(p.mime_type);
130
+ const artifactId = str(p.artifact_id);
131
+ if (artifactId) {
132
+ const art = await readArtifactBytes(artifactId);
133
+ if (!art) return { ok: false, error: `No existe el artifact ${artifactId} o ya expiró.` };
134
+ bytes = art.bytes; mime ??= art.mimeType;
135
+ } else if (typeof p.content === "string") {
136
+ bytes = new TextEncoder().encode(p.content); mime ??= "text/plain";
137
+ } else {
138
+ return { ok: false, error: "Indica content o artifact_id." };
139
+ }
140
+ if (bytes.byteLength > MAX_DOWNLOAD) return { ok: false, error: "El archivo supera el límite de 50 MB." };
141
+
142
+ const boundary = `hive_${crypto.randomUUID()}`;
143
+ const metadata = JSON.stringify({ name, ...(str(p.folder_id) ? { parents: [str(p.folder_id)] } : {}) });
144
+ const enc = new TextEncoder();
145
+ const body = Buffer.concat([
146
+ enc.encode(`--${boundary}\r\nContent-Type: application/json; charset=UTF-8\r\n\r\n${metadata}\r\n--${boundary}\r\nContent-Type: ${mime}\r\n\r\n`),
147
+ bytes,
148
+ enc.encode(`\r\n--${boundary}--`),
149
+ ]);
150
+ const file = await googleJson<any>(userId, "drive", UPLOAD, {
151
+ method: "POST",
152
+ query: { uploadType: "multipart", fields: "id,name,webViewLink" },
153
+ headers: { "Content-Type": `multipart/related; boundary=${boundary}` },
154
+ body,
155
+ });
156
+ return { ok: true, id: file.id, name: file.name, link: file.webViewLink };
157
+ },
158
+ });
159
+
160
+ export const driveTools = [gdriveSearchTool, gdriveDownloadTool, gdriveUploadTool];