@sixb/app 0.2.0 → 0.2.1

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 (87) hide show
  1. package/assets/connector-icons/README.md +1 -0
  2. package/assets/connector-icons/fleetio.ico +0 -0
  3. package/dist/agent/activity-label.d.ts.map +1 -1
  4. package/dist/agent/background/background-card.d.ts +10 -0
  5. package/dist/agent/background/background-card.d.ts.map +1 -0
  6. package/dist/agent/background/background-tool-row.d.ts +9 -0
  7. package/dist/agent/background/background-tool-row.d.ts.map +1 -0
  8. package/dist/agent/background/context.d.ts +23 -0
  9. package/dist/agent/background/context.d.ts.map +1 -0
  10. package/dist/agent/background/interpret.d.ts +116 -0
  11. package/dist/agent/background/interpret.d.ts.map +1 -0
  12. package/dist/agent/bash/bash-tool-view.d.ts.map +1 -1
  13. package/dist/agent/bash/interpret.d.ts +4 -0
  14. package/dist/agent/bash/interpret.d.ts.map +1 -1
  15. package/dist/agent/components/composer-menu.d.ts +3 -1
  16. package/dist/agent/components/composer-menu.d.ts.map +1 -1
  17. package/dist/agent/components/composer-place.d.ts +11 -0
  18. package/dist/agent/components/composer-place.d.ts.map +1 -0
  19. package/dist/agent/components/composer.d.ts +4 -1
  20. package/dist/agent/components/composer.d.ts.map +1 -1
  21. package/dist/agent/components/computer-place.d.ts +3 -1
  22. package/dist/agent/components/computer-place.d.ts.map +1 -1
  23. package/dist/agent/components/transcript.d.ts +6 -0
  24. package/dist/agent/components/transcript.d.ts.map +1 -1
  25. package/dist/agent/components/web-fetch-tool-view.d.ts.map +1 -1
  26. package/dist/agent/delegation/child-parts.d.ts +2 -0
  27. package/dist/agent/delegation/child-parts.d.ts.map +1 -1
  28. package/dist/agent/delegation/use-children.d.ts.map +1 -1
  29. package/dist/agent/hooks/use-agent-conversation.d.ts +15 -1
  30. package/dist/agent/hooks/use-agent-conversation.d.ts.map +1 -1
  31. package/dist/agent/hooks/use-new-thread-place.d.ts +48 -0
  32. package/dist/agent/hooks/use-new-thread-place.d.ts.map +1 -0
  33. package/dist/agent/hooks/use-thread-lists.d.ts +40 -0
  34. package/dist/agent/hooks/use-thread-lists.d.ts.map +1 -1
  35. package/dist/agent/i18n/en.d.ts +60 -0
  36. package/dist/agent/i18n/en.d.ts.map +1 -1
  37. package/dist/agent/i18n/fr.d.ts.map +1 -1
  38. package/dist/agent/i18n/index.d.ts +106 -0
  39. package/dist/agent/i18n/index.d.ts.map +1 -1
  40. package/dist/agent/observed-conversation.d.ts.map +1 -1
  41. package/dist/agent/tool-views/built-in.d.ts.map +1 -1
  42. package/dist/agent/utils/web-fetch.d.ts +33 -1
  43. package/dist/agent/utils/web-fetch.d.ts.map +1 -1
  44. package/dist/agent/utils/web-search.d.ts +14 -2
  45. package/dist/agent/utils/web-search.d.ts.map +1 -1
  46. package/dist/{chunk-zxthr2q5.js → chunk-4j3c3p72.js} +1 -1
  47. package/dist/{chunk-km25essq.js → chunk-7fj9cfkw.js} +1 -1
  48. package/dist/{chunk-j9653e83.js → chunk-j8g956dt.js} +1 -1
  49. package/dist/{chunk-fw2bm6dq.js → chunk-ytadd0b5.js} +3095 -1994
  50. package/dist/{chunk-fw2bm6dq.js.map → chunk-ytadd0b5.js.map} +25 -19
  51. package/dist/index.js +1 -1
  52. package/dist/pages/console/data/shared.d.ts.map +1 -1
  53. package/dist/pages/settings/usage/messages.d.ts +2 -0
  54. package/dist/pages/settings/usage/messages.d.ts.map +1 -1
  55. package/dist/pages/settings/usage/spend-model.d.ts.map +1 -1
  56. package/dist/pages.js +13 -6
  57. package/dist/pages.js.map +6 -6
  58. package/package.json +3 -3
  59. package/src/agent/activity-label.ts +6 -2
  60. package/src/agent/agent.css +18 -0
  61. package/src/agent/background/background-card.tsx +308 -0
  62. package/src/agent/background/background-tool-row.tsx +58 -0
  63. package/src/agent/background/context.ts +26 -0
  64. package/src/agent/background/interpret.ts +356 -0
  65. package/src/agent/bash/bash-tool-view.tsx +9 -4
  66. package/src/agent/bash/interpret.ts +21 -3
  67. package/src/agent/components/composer-menu.tsx +4 -1
  68. package/src/agent/components/composer-place.tsx +144 -0
  69. package/src/agent/components/composer.tsx +13 -0
  70. package/src/agent/components/computer-place.tsx +18 -1
  71. package/src/agent/components/transcript.tsx +33 -1
  72. package/src/agent/components/web-fetch-tool-view.tsx +94 -29
  73. package/src/agent/delegation/child-parts.tsx +1 -1
  74. package/src/agent/hooks/use-agent-conversation.ts +68 -6
  75. package/src/agent/hooks/use-new-thread-place.ts +170 -0
  76. package/src/agent/i18n/en.ts +56 -3
  77. package/src/agent/i18n/fr.ts +58 -3
  78. package/src/agent/observed-conversation.tsx +3 -0
  79. package/src/agent/tool-views/built-in.tsx +26 -11
  80. package/src/agent/utils/web-fetch.ts +89 -10
  81. package/src/agent/utils/web-search.ts +67 -28
  82. package/src/pages/console/data/shared.tsx +1 -0
  83. package/src/pages/settings/usage/messages.ts +2 -0
  84. package/src/pages/settings/usage/spend-model.ts +1 -0
  85. /package/dist/{chunk-zxthr2q5.js.map → chunk-4j3c3p72.js.map} +0 -0
  86. /package/dist/{chunk-km25essq.js.map → chunk-7fj9cfkw.js.map} +0 -0
  87. /package/dist/{chunk-j9653e83.js.map → chunk-j8g956dt.js.map} +0 -0
@@ -51,6 +51,8 @@ export const en = {
51
51
  busy: "An answer is already in progress. Send yours when it finishes.",
52
52
  busyOther: "Someone else's message is being answered. Send yours when it finishes.",
53
53
  sandboxUnavailable: "This conversation's sandbox must be recovered before another answer.",
54
+ computerUnavailable:
55
+ "This computer can't run the agent right now. Try again, or choose Cloud below.",
54
56
  retryFailed: "Couldn't retry this answer. Try again.",
55
57
  stopFailed: "Couldn't stop this answer. Try again.",
56
58
  removed: "You no longer take part in this thread.",
@@ -421,10 +423,18 @@ export const en = {
421
423
  results: (results: number) => count(results, "result"),
422
424
  webPage: "web page",
423
425
  reading: (domain: string) => `Reading ${domain}`,
426
+ /** A page read to answer a question about it. */
427
+ asking: (domain: string) => `Asking ${domain}`,
424
428
  read: (domain: string) => `Read ${domain}`,
425
429
  reviewing: (domain: string) => `Reviewing ${domain}`,
426
430
  readFailed: (domain: string) => `Could not read ${domain}`,
427
431
  pageError: "The page could not be read.",
432
+ redirectedTo: (domain: string) => `Redirected to ${domain}`,
433
+ answerFailed: "No answer came back. Here is how the page begins.",
434
+ /** Under an answer that reached its length limit. */
435
+ answerTruncated: "The answer stopped at its length limit and may be incomplete.",
436
+ /** Beside the size of a page that was too large to read whole. */
437
+ truncated: "truncated",
428
438
  noPageText: "No page text was returned.",
429
439
  openPage: "Open page",
430
440
  newTab: " (opens in a new tab)",
@@ -488,6 +498,8 @@ export const en = {
488
498
  /** Headlines of the agent's shell commands: past tense when done, progressive while running. */
489
499
  bash: {
490
500
  preparing: "Preparing a command",
501
+ /** Beside a command stopped at its timeout, which reads otherwise as a plain failure. */
502
+ timedOut: (duration: string) => `timed out after ${duration}`,
491
503
  steps: {
492
504
  title: (steps: number) => `Ran ${count(steps, "step")}`,
493
505
  running: (steps: number) => `Running ${count(steps, "step")}`,
@@ -783,15 +795,56 @@ export const en = {
783
795
  create: "Create fresh sandbox",
784
796
  ownerOnly: (owner: string) => `Only ${owner} can start this conversation with a fresh sandbox.`,
785
797
  },
798
+ /** A command the agent runs in the background, as its card and its calls read. */
799
+ background: {
800
+ card: (command: string) => `Background command: ${command}`,
801
+ starting: "Starting in the background",
802
+ running: "Running",
803
+ waiting: "the agent waits for it",
804
+ reading: "the agent reads it",
805
+ stopping: "Stopping…",
806
+ exited: (code: number) => (code === 0 ? "Exited · code 0" : `Failed · exit code ${code}`),
807
+ stopped: "Stopped",
808
+ stoppedWithTurn: "Stopped as its turn ended",
809
+ stoppedWithSixb: "Stopped as sixb quit",
810
+ unknown: "Last seen running",
811
+ unreachable: "Last seen running · sixb is closed there",
812
+ stop: "Stop",
813
+ stopHint: "Stop it, and everything it started",
814
+ stopFailed: "Could not stop it: it may have ended. Try again.",
815
+ output: "Output",
816
+ lines: (lines: number) => count(lines, "line"),
817
+ earlierOutput: (path: string) => `Earlier output is in ${path}`,
818
+ rows: {
819
+ start: { title: "Started in the background", running: "Starting in the background" },
820
+ read: { title: "Checked a background command", running: "Checking a background command" },
821
+ wait: {
822
+ title: "Waited for a background command",
823
+ running: "Waiting for a background command",
824
+ },
825
+ stop: { title: "Stopped a background command", running: "Stopping a background command" },
826
+ },
827
+ },
786
828
  /** A conversation that runs on its owner's computer, as its owner sees it. */
787
829
  computer: {
788
- online: "sixb is open there",
789
- offline: "sixb is closed there",
830
+ online: "Connected",
831
+ offline: "Not connected",
790
832
  offlineNotice: (computer: string, folder: string) =>
791
- `${computer} is offline. Your message waits until sixb is open in ${folder} with messages from the web on.`,
833
+ `${computer} is offline. Your message waits until ${folder} is connected there.`,
792
834
  noFolder:
793
835
  "This conversation has no folder yet. Open sixb in its folder and press ctrl+f, or continue in the cloud.",
836
+ /** In a desktop app, about a conversation of this computer's. */
837
+ offlineHere: (folder: string) =>
838
+ `Not running here yet. Your message waits until this computer is connected in ${folder}.`,
839
+ runHere: "Run on this computer",
794
840
  waitingFor: (computer: string) => `Waiting for ${computer}`,
841
+ /** Where a new conversation runs, in a desktop app. */
842
+ placeTitle: "Where this conversation runs",
843
+ placeChip: (place: string) => `Runs in ${place}. Change where it runs`,
844
+ cloud: "Cloud",
845
+ chooseFolder: "Choose a folder…",
846
+ chooseFolderShort: "Choose a folder",
847
+ forgetFolder: (folder: string) => `Stop running messages in ${folder}`,
795
848
  continueInCloud: "Continue in the cloud",
796
849
  moving: "Moving…",
797
850
  moveFailed: "Could not move it to the cloud. Try again.",
@@ -42,6 +42,8 @@ export const fr: Translation<AgentMessages> = {
42
42
  busy: "Une réponse est déjà en cours. Envoyez votre message quand elle sera terminée.",
43
43
  busyOther:
44
44
  "L’agent répond au message de quelqu’un d’autre. Envoyez le vôtre quand il aura fini.",
45
+ computerUnavailable:
46
+ "Cet ordinateur ne peut pas exécuter l’agent pour le moment. Réessayez, ou choisissez Cloud ci-dessous.",
45
47
  sandboxUnavailable:
46
48
  "L’environnement de cette conversation doit être récupéré avant une nouvelle réponse.",
47
49
  retryFailed: "Impossible de relancer cette réponse. Réessayez.",
@@ -401,10 +403,15 @@ export const fr: Translation<AgentMessages> = {
401
403
  results: (results) => count(results, "résultat"),
402
404
  webPage: "page web",
403
405
  reading: (domain) => `Lecture : ${domain}`,
406
+ asking: (domain) => `Question à ${domain}`,
404
407
  read: (domain) => `Page consultée : ${domain}`,
405
408
  reviewing: (domain) => `Analyse : ${domain}`,
406
409
  readFailed: (domain) => `Lecture impossible : ${domain}`,
407
410
  pageError: "La page n’a pas pu être lue.",
411
+ redirectedTo: (domain) => `Redirigé vers ${domain}`,
412
+ answerFailed: "Aucune réponse n’a été obtenue. Voici le début de la page.",
413
+ answerTruncated: "La réponse a atteint sa longueur maximale et peut être incomplète.",
414
+ truncated: "tronqué",
408
415
  noPageText: "Aucun texte n’a été récupéré sur cette page.",
409
416
  openPage: "Ouvrir la page",
410
417
  newTab: " (s’ouvre dans un nouvel onglet)",
@@ -466,6 +473,7 @@ export const fr: Translation<AgentMessages> = {
466
473
  },
467
474
  bash: {
468
475
  preparing: "Préparation d’une commande",
476
+ timedOut: (duration) => `délai de ${duration} dépassé`,
469
477
  steps: {
470
478
  title: (steps) => count(steps, "étape exécutée", "étapes exécutées"),
471
479
  running: (steps) => `Exécution de ${count(steps, "étape")}`,
@@ -835,13 +843,60 @@ export const fr: Translation<AgentMessages> = {
835
843
  ownerOnly: (owner) =>
836
844
  `${owner} est la seule personne à pouvoir faire repartir cette conversation d’un nouvel environnement.`,
837
845
  },
846
+ background: {
847
+ card: (command) => `Commande en arrière-plan : ${command}`,
848
+ starting: "Démarrage en arrière-plan",
849
+ running: "En cours",
850
+ waiting: "l’agent l’attend",
851
+ reading: "l’agent la lit",
852
+ stopping: "Arrêt…",
853
+ exited: (code) => (code === 0 ? "Terminée · code 0" : `Échec · code de sortie ${code}`),
854
+ stopped: "Arrêtée",
855
+ stoppedWithTurn: "Arrêtée à la fin de son tour",
856
+ stoppedWithSixb: "Arrêtée à la fermeture de sixb",
857
+ unknown: "En cours à la dernière lecture",
858
+ unreachable: "En cours à la dernière lecture · sixb y est fermé",
859
+ stop: "Arrêter",
860
+ stopHint: "L’arrêter, avec tout ce qu’elle a lancé",
861
+ stopFailed: "Impossible de l’arrêter : elle est peut-être terminée. Réessayez.",
862
+ output: "Sortie",
863
+ lines: (lines) => count(lines, "ligne"),
864
+ earlierOutput: (path) => `La sortie précédente est dans ${path}`,
865
+ rows: {
866
+ start: {
867
+ title: "Commande lancée en arrière-plan",
868
+ running: "Lancement d’une commande en arrière-plan",
869
+ },
870
+ read: {
871
+ title: "Commande en arrière-plan consultée",
872
+ running: "Consultation d’une commande en arrière-plan",
873
+ },
874
+ wait: {
875
+ title: "Commande en arrière-plan attendue",
876
+ running: "Attente d’une commande en arrière-plan",
877
+ },
878
+ stop: {
879
+ title: "Commande en arrière-plan arrêtée",
880
+ running: "Arrêt d’une commande en arrière-plan",
881
+ },
882
+ },
883
+ },
838
884
  computer: {
839
- online: "sixb y est ouvert",
840
- offline: "sixb y est fermé",
885
+ online: "Connecté",
886
+ offline: "Non connecté",
841
887
  offlineNotice: (computer, folder) =>
842
- `${computer} est hors ligne. Votre message attendra que sixb soit ouvert dans ${folder} avec les messages du web activés.`,
888
+ `${computer} est hors ligne. Votre message attendra que ${folder} y soit connecté.`,
843
889
  noFolder:
844
890
  "Cette conversation n’a pas encore de dossier. Ouvrez sixb dans son dossier et appuyez sur ctrl+f, ou continuez dans le cloud.",
891
+ offlineHere: (folder) =>
892
+ `Pas encore en cours ici. Votre message attendra que cet ordinateur soit connecté dans ${folder}.`,
893
+ runHere: "Exécuter sur cet ordinateur",
894
+ placeTitle: "Où cette conversation s'exécute",
895
+ placeChip: (place) => `S'exécute dans ${place}. Changer l'emplacement`,
896
+ cloud: "Cloud",
897
+ chooseFolder: "Choisir un dossier…",
898
+ chooseFolderShort: "Choisir un dossier",
899
+ forgetFolder: (folder) => `Ne plus exécuter les messages dans ${folder}`,
845
900
  waitingFor: (computer) => `En attente de ${computer}`,
846
901
  continueInCloud: "Continuer dans le cloud",
847
902
  moving: "Déplacement…",
@@ -137,6 +137,9 @@ export function ObservedConversation({
137
137
  messages={conversation}
138
138
  turn={turn}
139
139
  approvalOutcomes={approvalOutcomes}
140
+ background={{
141
+ source: { onComputer: thread.runsOn === "computer", live: null, online: false },
142
+ }}
140
143
  />
141
144
  )
142
145
  if (messagesQuery.isLoading) {
@@ -1,4 +1,7 @@
1
1
  import type { ReactNode } from "react"
2
+ import { BackgroundCommandStep } from "../background/background-card"
3
+ import { BackgroundToolRow } from "../background/background-tool-row"
4
+ import { isBackgroundStart } from "../background/interpret"
2
5
  import { BashToolView } from "../bash/bash-tool-view"
3
6
  import { WebFetchToolView } from "../components/web-fetch-tool-view"
4
7
  import { WebSearchToolView } from "../components/web-search-tool-view"
@@ -18,17 +21,29 @@ const publishArtifact: BuiltInToolView = (tool) => <PublishArtifactToolView tool
18
21
  const BUILT_IN_TOOL_VIEWS: ReadonlyMap<string, BuiltInToolView> = new Map([
19
22
  [
20
23
  "bash",
21
- (tool) => (
22
- <BashToolView
23
- tool={{
24
- state: tool.state,
25
- input: tool.input,
26
- inputText: tool.inputText,
27
- output: tool.output,
28
- errorText: tool.errorText,
29
- }}
30
- />
31
- ),
24
+ (tool) =>
25
+ isBackgroundStart(tool) ? (
26
+ <BackgroundCommandStep tool={tool} />
27
+ ) : (
28
+ <BashToolView
29
+ tool={{
30
+ state: tool.state,
31
+ input: tool.input,
32
+ inputText: tool.inputText,
33
+ output: tool.output,
34
+ errorText: tool.errorText,
35
+ }}
36
+ />
37
+ ),
38
+ ],
39
+ // A failed read or stop keeps the inspector, which says why.
40
+ [
41
+ "bash_output",
42
+ (tool) => (tool.state === "output-error" ? null : <BackgroundToolRow tool={tool} />),
43
+ ],
44
+ [
45
+ "bash_stop",
46
+ (tool) => (tool.state === "output-error" ? null : <BackgroundToolRow tool={tool} />),
32
47
  ],
33
48
  ["read", (tool) => <ReadToolView tool={tool} />],
34
49
  ["view_file", (tool) => <ViewFileToolView tool={tool} />],
@@ -1,18 +1,97 @@
1
- import { coerceWebSearchOutput, type WebSource } from "./web-search"
1
+ import { httpUrl, type WebSource, webSource } from "./web-search"
2
2
 
3
- export function coerceWebFetchOutput(value: unknown): WebSource | null {
4
- if (!isRecord(value) || typeof value.content !== "string") return null
5
- return coerceWebSearchOutput({ results: [{ ...value, text: value.content }] })?.[0] ?? null
3
+ /** A `web_fetch` result, as the chat shows it. */
4
+ export interface WebFetchPage {
5
+ readonly source: WebSource
6
+ /** What the agent asked about the page. */
7
+ readonly question?: string
8
+ readonly answer?: string
9
+ /** The answer stopped at its length limit: its end may be missing. */
10
+ readonly answerTruncated: boolean
11
+ /** The question went unanswered: the preview stands in for the answer. */
12
+ readonly answerFailed: boolean
13
+ /** The start of the page, or all of it when it is short. */
14
+ readonly preview?: string
15
+ /**
16
+ * Another site the address sent the agent to, which it did not follow. Its host stays whole:
17
+ * `example.com` sending to `www.example.com` would otherwise read as a redirect to itself.
18
+ */
19
+ readonly redirect?: { readonly url: string; readonly domain: string }
20
+ // What the server sent: shown only in the opened row.
21
+ readonly status?: number
22
+ readonly contentType?: string
23
+ readonly bytes?: number
24
+ readonly truncated: boolean
25
+ }
26
+
27
+ /**
28
+ * Recognize a `web_fetch` output: Sixb's (`source`, `answer`, `preview`), and the Exa tool's that
29
+ * older threads stored (`title`, `url`, `content`).
30
+ */
31
+ export function coerceWebFetchOutput(value: unknown): WebFetchPage | null {
32
+ if (!isRecord(value)) return null
33
+
34
+ if (typeof value.content === "string") {
35
+ if (typeof value.url !== "string" || typeof value.title !== "string") return null
36
+
37
+ const source = webSource(value.url, value.title, value.content)
38
+ if (!source) return null
39
+
40
+ return {
41
+ source,
42
+ preview: value.content,
43
+ answerTruncated: false,
44
+ answerFailed: false,
45
+ truncated: false,
46
+ }
47
+ }
48
+
49
+ if (!isRecord(value.source) || typeof value.source.url !== "string") return null
50
+
51
+ // The page speaks for itself in the row; its source carries no excerpt of it.
52
+ const source = webSource(value.source.url, text(value.source.title) ?? "", "")
53
+ if (!source) return null
54
+
55
+ const redirect = isRecord(value.redirect) ? httpUrl(text(value.redirect.url) ?? "") : null
56
+
57
+ return {
58
+ source,
59
+ question: text(value.question),
60
+ answer: text(value.answer),
61
+ answerTruncated: value.answerTruncated === true,
62
+ answerFailed: typeof value.answerError === "string",
63
+ preview: text(value.preview),
64
+ redirect: redirect ? { url: redirect.href, domain: redirect.hostname } : undefined,
65
+ status: count(value.status),
66
+ contentType: text(value.contentType),
67
+ bytes: count(value.bytes),
68
+ truncated: value.truncated === true,
69
+ }
70
+ }
71
+
72
+ /** The page a `web_fetch` read, as a source; none when it only pointed elsewhere or failed. */
73
+ export function webFetchSource(value: unknown): WebSource | null {
74
+ const page = coerceWebFetchOutput(value)
75
+ if (!page || page.redirect) return null
76
+ if (page.status !== undefined && (page.status < 200 || page.status >= 300)) return null
77
+ return page.source
6
78
  }
7
79
 
8
80
  export function webFetchUrl(input: unknown): URL | null {
9
81
  if (!isRecord(input) || typeof input.url !== "string") return null
10
- try {
11
- const url = new URL(input.url)
12
- return ["http:", "https:"].includes(url.protocol) && !url.username && !url.password ? url : null
13
- } catch {
14
- return null
15
- }
82
+ return httpUrl(input.url)
83
+ }
84
+
85
+ export function webFetchQuestion(input: unknown): string | undefined {
86
+ return isRecord(input) ? text(input.question) : undefined
87
+ }
88
+
89
+ function text(value: unknown): string | undefined {
90
+ return typeof value === "string" && value.trim() ? value.trim() : undefined
91
+ }
92
+
93
+ function count(value: unknown): number | undefined {
94
+ return typeof value === "number" && Number.isFinite(value) && value >= 0 ? value : undefined
16
95
  }
17
96
 
18
97
  function isRecord(value: unknown): value is Record<string, unknown> {
@@ -1,4 +1,5 @@
1
1
  import type { NormalizedPart } from "../parts"
2
+ import { webFetchSource } from "./web-fetch"
2
3
 
3
4
  export interface WebSource {
4
5
  readonly id: string
@@ -22,61 +23,89 @@ export function formatPublicationDate(value: string, locale: string): string {
22
23
  }).format(new Date(value))
23
24
  }
24
25
 
25
- /** Recognize the bounded Exa web_search output, without depending on the connector package. */
26
+ /**
27
+ * Recognize a `web_search` output: Sixb's hits (`snippet`, `publishedAt`), and the Exa tool's
28
+ * that older threads stored (`text`, `author`, `publishedDate`).
29
+ */
26
30
  export function coerceWebSearchOutput(value: unknown): readonly WebSource[] | null {
27
31
  if (!isRecord(value) || !Array.isArray(value.results)) return null
32
+
28
33
  const sources: WebSource[] = []
29
34
  for (const result of value.results) {
30
- if (
31
- !isRecord(result) ||
32
- typeof result.url !== "string" ||
33
- typeof result.title !== "string" ||
34
- typeof result.text !== "string"
35
- ) {
35
+ if (!isRecord(result) || typeof result.url !== "string" || typeof result.title !== "string") {
36
36
  return null
37
37
  }
38
- const url = httpUrl(result.url)
39
- if (!url) continue
40
- const page = new URL(url)
41
- page.hash = ""
38
+
39
+ const text = typeof result.snippet === "string" ? result.snippet : result.text
40
+ if (typeof text !== "string") return null
41
+
42
+ const source = webSource(result.url, result.title, text)
43
+ if (!source) continue
44
+
42
45
  sources.push({
43
- id: page.href,
44
- url: url.href,
45
- domain: url.hostname.replace(/^www\./, ""),
46
- faviconUrl: new URL("/favicon.ico", url.origin).href,
47
- title: compact(result.title) || url.hostname,
48
- excerpt: excerpt(result.text),
46
+ ...source,
49
47
  author: typeof result.author === "string" ? compact(result.author) : undefined,
50
- publishedDate: publicationDate(result.publishedDate),
48
+ publishedDate: publicationDate(result.publishedAt ?? result.publishedDate),
51
49
  })
52
50
  }
51
+
53
52
  // Invalid links are not evidence that a search returned zero results. Keep the inspector.
54
53
  return value.results.length > 0 && sources.length === 0 ? null : sources
55
54
  }
56
55
 
56
+ /** A page as a source, or null when its link is not a plain web address. */
57
+ export function webSource(url: string, title: string, text: string): WebSource | null {
58
+ const parsed = httpUrl(url)
59
+ if (!parsed) return null
60
+
61
+ const page = new URL(parsed)
62
+ page.hash = ""
63
+ return {
64
+ id: page.href,
65
+ url: parsed.href,
66
+ domain: displayDomain(parsed),
67
+ faviconUrl: new URL("/favicon.ico", parsed.origin).href,
68
+ title: compact(title) || fileName(parsed) || parsed.hostname,
69
+ excerpt: excerpt(text),
70
+ }
71
+ }
72
+
73
+ /** A host as people read it: without the `www.` prefix. */
74
+ export function displayDomain(url: URL): string {
75
+ return url.hostname.replace(/^www\./, "")
76
+ }
77
+
57
78
  export function webSearchQuery(input: unknown): string | undefined {
58
79
  return isRecord(input) && typeof input.query === "string" ? input.query.trim() : undefined
59
80
  }
60
81
 
61
- /** Keep provider order and the first occurrence; separate pages on one domain remain separate. */
82
+ /**
83
+ * Keep provider order and the first occurrence; separate pages on one domain remain separate. A
84
+ * page the agent read counts too, unless it only pointed elsewhere.
85
+ */
62
86
  export function collectWebSources(parts: readonly NormalizedPart[]): readonly WebSource[] {
63
87
  const sources = new Map<string, WebSource>()
88
+ const add = (source: WebSource) => {
89
+ if (!sources.has(source.id)) sources.set(source.id, source)
90
+ }
91
+
64
92
  for (const part of parts) {
65
- if (
66
- part.kind !== "tool" ||
67
- part.tool.toolName !== "web_search" ||
68
- part.tool.state !== "output-available"
69
- ) {
70
- continue
93
+ if (part.kind !== "tool" || part.tool.state !== "output-available") continue
94
+
95
+ if (part.tool.toolName === "web_search") {
96
+ for (const source of coerceWebSearchOutput(part.tool.output) ?? []) add(source)
71
97
  }
72
- for (const source of coerceWebSearchOutput(part.tool.output) ?? []) {
73
- if (!sources.has(source.id)) sources.set(source.id, source)
98
+
99
+ if (part.tool.toolName === "web_fetch") {
100
+ const source = webFetchSource(part.tool.output)
101
+ if (source) add(source)
74
102
  }
75
103
  }
76
104
  return [...sources.values()]
77
105
  }
78
106
 
79
- function httpUrl(value: string): URL | null {
107
+ /** A plain web address: http or https, with no credentials in it. */
108
+ export function httpUrl(value: string): URL | null {
80
109
  try {
81
110
  const url = new URL(value)
82
111
  if (!["http:", "https:"].includes(url.protocol) || url.username || url.password) return null
@@ -86,6 +115,16 @@ function httpUrl(value: string): URL | null {
86
115
  }
87
116
  }
88
117
 
118
+ /** The last segment of a URL's path, decoded: what a PDF or an image without a title is called. */
119
+ function fileName(url: URL): string {
120
+ const segment = url.pathname.slice(url.pathname.lastIndexOf("/") + 1)
121
+ try {
122
+ return compact(decodeURIComponent(segment))
123
+ } catch {
124
+ return compact(segment)
125
+ }
126
+ }
127
+
89
128
  function compact(value: string): string {
90
129
  return value.replace(/\s+/g, " ").trim()
91
130
  }
@@ -9,6 +9,7 @@ const connectorIconFiles: Readonly<Record<string, string>> = {
9
9
  "ace-iot": "ace-iot.ico",
10
10
  companycam: "companycam.png",
11
11
  exa: "exa.png",
12
+ fleetio: "fleetio.ico",
12
13
  github: "github.svg",
13
14
  google: "google.ico",
14
15
  "google-ads": "googleads.svg",
@@ -16,6 +16,7 @@ export const en = {
16
16
  embedding: "Embeddings",
17
17
  decision: "Decisions",
18
18
  reranking: "Reranking",
19
+ "web-search": "Web search",
19
20
  image: "Images",
20
21
  speech: "Speech",
21
22
  transcription: "Transcription",
@@ -288,6 +289,7 @@ export const fr: Translation<AiUsageMessages> = {
288
289
  embedding: "Embeddings",
289
290
  decision: "Décisions",
290
291
  reranking: "Reclassement",
292
+ "web-search": "Recherche web",
291
293
  image: "Images",
292
294
  speech: "Synthèse vocale",
293
295
  transcription: "Transcription",
@@ -88,6 +88,7 @@ const modelKinds: readonly ModelKind[] = [
88
88
  "transcription",
89
89
  "speech",
90
90
  "reranking",
91
+ "web-search",
91
92
  ]
92
93
 
93
94
  export function readFilters(params: URLSearchParams): SpendFilters {