@sixb/app 0.2.5 → 0.2.7

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 (136) hide show
  1. package/dist/agent/components/agent-threads.d.ts.map +1 -1
  2. package/dist/agent/components/composer-place.d.ts.map +1 -1
  3. package/dist/agent/components/computer-place.d.ts +24 -6
  4. package/dist/agent/components/computer-place.d.ts.map +1 -1
  5. package/dist/agent/components/conversation-panel.d.ts.map +1 -1
  6. package/dist/agent/components/message-view.d.ts +13 -3
  7. package/dist/agent/components/message-view.d.ts.map +1 -1
  8. package/dist/agent/components/pending-messages.d.ts.map +1 -1
  9. package/dist/agent/components/sandbox-recovery.d.ts +8 -2
  10. package/dist/agent/components/sandbox-recovery.d.ts.map +1 -1
  11. package/dist/agent/components/transcript.d.ts +13 -0
  12. package/dist/agent/components/transcript.d.ts.map +1 -1
  13. package/dist/agent/conversation.d.ts +4 -0
  14. package/dist/agent/conversation.d.ts.map +1 -1
  15. package/dist/agent/delegation/use-children.d.ts +5 -5
  16. package/dist/agent/delegation/use-children.d.ts.map +1 -1
  17. package/dist/agent/format.d.ts +7 -0
  18. package/dist/agent/format.d.ts.map +1 -1
  19. package/dist/agent/hooks/thread-queries.d.ts +1548 -0
  20. package/dist/agent/hooks/thread-queries.d.ts.map +1 -0
  21. package/dist/agent/hooks/use-agent-conversation.d.ts +41 -2
  22. package/dist/agent/hooks/use-agent-conversation.d.ts.map +1 -1
  23. package/dist/agent/hooks/use-thread-lists.d.ts +80 -3
  24. package/dist/agent/hooks/use-thread-lists.d.ts.map +1 -1
  25. package/dist/agent/hooks/use-thread-place.d.ts +49 -0
  26. package/dist/agent/hooks/use-thread-place.d.ts.map +1 -0
  27. package/dist/agent/i18n/en.d.ts +44 -6
  28. package/dist/agent/i18n/en.d.ts.map +1 -1
  29. package/dist/agent/i18n/fr.d.ts.map +1 -1
  30. package/dist/agent/i18n/index.d.ts +76 -12
  31. package/dist/agent/i18n/index.d.ts.map +1 -1
  32. package/dist/agent/live-run.d.ts.map +1 -1
  33. package/dist/agent/model-selection.d.ts +3 -2
  34. package/dist/agent/model-selection.d.ts.map +1 -1
  35. package/dist/agent/moves.d.ts +40 -0
  36. package/dist/agent/moves.d.ts.map +1 -0
  37. package/dist/agent/thread-reader-state.d.ts +30 -0
  38. package/dist/agent/thread-reader-state.d.ts.map +1 -0
  39. package/dist/agent/types.d.ts +4 -0
  40. package/dist/agent/types.d.ts.map +1 -1
  41. package/dist/artifacts/live/session.d.ts.map +1 -1
  42. package/dist/artifacts/queries.d.ts.map +1 -1
  43. package/dist/artifacts/renderers/live-frame.d.ts.map +1 -1
  44. package/dist/{chunk-69qgh20f.js → chunk-1f4h75n3.js} +1 -1
  45. package/dist/{chunk-4fex83k2.js → chunk-7v9622qb.js} +2254 -739
  46. package/dist/{chunk-4fex83k2.js.map → chunk-7v9622qb.js.map} +29 -26
  47. package/dist/{chunk-5sgac68y.js → chunk-dntecmwb.js} +1 -1
  48. package/dist/{chunk-4wm09prf.js → chunk-qmka6aea.js} +1 -1
  49. package/dist/createCustomApp.d.ts +8 -1
  50. package/dist/createCustomApp.d.ts.map +1 -1
  51. package/dist/index.d.ts +3 -2
  52. package/dist/index.d.ts.map +1 -1
  53. package/dist/index.js +4 -2
  54. package/dist/index.js.map +3 -3
  55. package/dist/pages/console/data/accounts.d.ts +94 -0
  56. package/dist/pages/console/data/accounts.d.ts.map +1 -0
  57. package/dist/pages/console/data/connectors.d.ts.map +1 -1
  58. package/dist/pages/console/data/datasets.d.ts.map +1 -1
  59. package/dist/pages/console/data/live-updates.d.ts.map +1 -1
  60. package/dist/pages/console/data/messages.d.ts +46 -0
  61. package/dist/pages/console/data/messages.d.ts.map +1 -1
  62. package/dist/pages/console/data/pipelines.d.ts.map +1 -1
  63. package/dist/pages/console/data/projections.d.ts.map +1 -1
  64. package/dist/pages/console/data/sync-button.d.ts.map +1 -1
  65. package/dist/pages/console/data/syncs.d.ts.map +1 -1
  66. package/dist/pages/console/ontology/actions.d.ts.map +1 -1
  67. package/dist/pages/console/ontology/object-type.d.ts.map +1 -1
  68. package/dist/pages/console/ontology/object-types.d.ts.map +1 -1
  69. package/dist/pages/console/ontology/rules.d.ts.map +1 -1
  70. package/dist/pages/console/ontology/workflow.d.ts.map +1 -1
  71. package/dist/pages/console/ontology/workflows.d.ts.map +1 -1
  72. package/dist/pages/folders.d.ts +106 -0
  73. package/dist/pages/folders.d.ts.map +1 -0
  74. package/dist/pages/settings/usage/breakdown.d.ts.map +1 -1
  75. package/dist/pages/settings/usage/page.d.ts +4 -1
  76. package/dist/pages/settings/usage/page.d.ts.map +1 -1
  77. package/dist/pages/settings/usage/spend-model.d.ts +43 -19
  78. package/dist/pages/settings/usage/spend-model.d.ts.map +1 -1
  79. package/dist/pages.js +23453 -22656
  80. package/dist/pages.js.map +23 -21
  81. package/dist/server.d.ts +1 -1
  82. package/dist/server.d.ts.map +1 -1
  83. package/dist/server.js +40 -3
  84. package/dist/server.js.map +3 -3
  85. package/package.json +3 -3
  86. package/src/agent/agent-chat.tsx +2 -2
  87. package/src/agent/components/agent-threads.tsx +42 -2
  88. package/src/agent/components/composer-place.tsx +2 -7
  89. package/src/agent/components/computer-place.tsx +415 -70
  90. package/src/agent/components/conversation-panel.tsx +31 -26
  91. package/src/agent/components/message-view.tsx +418 -9
  92. package/src/agent/components/pending-messages.tsx +5 -1
  93. package/src/agent/components/sandbox-recovery.tsx +24 -6
  94. package/src/agent/components/transcript.tsx +136 -5
  95. package/src/agent/conversation.ts +16 -1
  96. package/src/agent/format.ts +52 -0
  97. package/src/agent/hooks/thread-queries.ts +75 -0
  98. package/src/agent/hooks/use-agent-conversation.ts +461 -112
  99. package/src/agent/hooks/use-thread-lists.ts +72 -7
  100. package/src/agent/hooks/use-thread-place.ts +239 -0
  101. package/src/agent/i18n/en.ts +69 -16
  102. package/src/agent/i18n/fr.ts +71 -19
  103. package/src/agent/live-run.ts +38 -0
  104. package/src/agent/model-selection.ts +3 -2
  105. package/src/agent/moves.ts +174 -0
  106. package/src/agent/thread-reader-state.ts +75 -0
  107. package/src/agent/types.ts +6 -0
  108. package/src/artifacts/live/session.ts +5 -0
  109. package/src/createCustomApp.ts +57 -3
  110. package/src/index.ts +4 -0
  111. package/src/pages/console/data/accounts.tsx +509 -0
  112. package/src/pages/console/data/connectors.tsx +67 -64
  113. package/src/pages/console/data/datasets.tsx +79 -68
  114. package/src/pages/console/data/live-updates.ts +2 -0
  115. package/src/pages/console/data/messages.ts +73 -0
  116. package/src/pages/console/data/pipelines.tsx +80 -69
  117. package/src/pages/console/data/projections.tsx +111 -82
  118. package/src/pages/console/data/sync-button.tsx +56 -16
  119. package/src/pages/console/data/syncs.tsx +121 -86
  120. package/src/pages/console/ontology/actions.tsx +51 -24
  121. package/src/pages/console/ontology/object-type.tsx +5 -1
  122. package/src/pages/console/ontology/object-types.tsx +41 -32
  123. package/src/pages/console/ontology/rules.tsx +48 -38
  124. package/src/pages/console/ontology/workflow.tsx +9 -3
  125. package/src/pages/console/ontology/workflows.tsx +55 -67
  126. package/src/pages/folders.tsx +335 -0
  127. package/src/pages/section-ui.tsx +1 -1
  128. package/src/pages/settings/usage/breakdown.tsx +5 -2
  129. package/src/pages/settings/usage/filter-menu.tsx +1 -1
  130. package/src/pages/settings/usage/page.tsx +32 -13
  131. package/src/pages/settings/usage/spend-chart.tsx +2 -2
  132. package/src/pages/settings/usage/spend-model.ts +118 -50
  133. package/src/server.ts +1 -0
  134. /package/dist/{chunk-69qgh20f.js.map → chunk-1f4h75n3.js.map} +0 -0
  135. /package/dist/{chunk-5sgac68y.js.map → chunk-dntecmwb.js.map} +0 -0
  136. /package/dist/{chunk-4wm09prf.js.map → chunk-qmka6aea.js.map} +0 -0
@@ -3,6 +3,15 @@ import type {
3
3
  ListAiModelCallGroupsResponse,
4
4
  ListAiModelCallsResponse,
5
5
  } from "@sixb/client"
6
+ import {
7
+ addCalendarPeriods,
8
+ type CalendarPeriod,
9
+ calendarPeriodStart,
10
+ calendarPeriods,
11
+ canonicalTimeZone,
12
+ wallClockAt,
13
+ wallClockInstant,
14
+ } from "@sixb/core/calendar"
6
15
  import { amountFor, nanosToNumber, type Overview } from "./format"
7
16
 
8
17
  /**
@@ -17,44 +26,56 @@ export type Call = ListAiModelCallsResponse["items"][number]
17
26
  export type ModelKind = NonNullable<Overview["kinds"][number]["modelKind"]>
18
27
  type OverviewQuery = GetAiAccountingOverviewData["query"]
19
28
 
20
- const hourMs = 60 * 60 * 1000
21
- const dayMs = 24 * hourMs
22
-
29
+ /**
30
+ * The ranges the page offers: `periods` whole hours or days of the reader's calendar, ending with
31
+ * the current one, drawn in `bucket` bars. The 90 days end today, so their first and last weeks
32
+ * are partial.
33
+ */
23
34
  export const spendRanges = [
24
- { id: "24h", bucket: "hour", ms: dayMs, period: "day" },
25
- { id: "7d", bucket: "day", ms: 7 * dayMs, period: "week" },
26
- { id: "30d", bucket: "day", ms: 30 * dayMs, period: "month" },
27
- { id: "90d", bucket: "week", ms: 91 * dayMs, period: "quarter" },
35
+ { id: "24h", unit: "hour", periods: 24, bucket: "hour", period: "day" },
36
+ { id: "7d", unit: "day", periods: 7, bucket: "day", period: "week" },
37
+ { id: "30d", unit: "day", periods: 30, bucket: "day", period: "month" },
38
+ { id: "90d", unit: "day", periods: 91, bucket: "week", period: "quarter" },
28
39
  ] as const
29
40
 
30
41
  type SpendRangeId = (typeof spendRanges)[number]["id"]
31
- export type Bucket = (typeof spendRanges)[number]["bucket"]
42
+ export type Bucket = CalendarPeriod
32
43
 
33
44
  export interface SpendRange {
34
45
  readonly id: SpendRangeId
35
46
  readonly from: string
36
47
  readonly to: string
48
+ /** What the range is counted in, and what the period it compares with steps back by. */
49
+ readonly unit: (typeof spendRanges)[number]["unit"]
37
50
  readonly bucket: Bucket
38
51
  readonly period: (typeof spendRanges)[number]["period"]
52
+ /** The zone whose days, weeks or hours the bars are, and which the API buckets by. */
53
+ readonly timeZone: string
39
54
  }
40
55
 
41
- /** A range that ends with the current hour or day, so its bars are whole UTC periods. */
42
- export function spendRange(id: string | null, now = Date.now()): SpendRange {
56
+ /** The reader's IANA zone, whose calendar the page follows; UTC when this browser cannot name one. */
57
+ export function viewerTimeZone(): string {
58
+ return canonicalTimeZone(Intl.DateTimeFormat().resolvedOptions().timeZone) ?? "UTC"
59
+ }
60
+
61
+ /** A range that ends with the current hour or day, never later, on the zone's calendar. */
62
+ export function spendRange(id: string | null, timeZone: string, now = Date.now()): SpendRange {
43
63
  const preset = spendRanges.find((range) => range.id === id) ?? spendRanges[1]
44
- const unit = preset.bucket === "hour" ? hourMs : dayMs
45
- const to = Math.floor(now / unit) * unit + unit
64
+ const to = addCalendarPeriods(new Date(now), preset.unit, 1, timeZone)
46
65
  return {
47
66
  id: preset.id,
48
- from: new Date(to - preset.ms).toISOString(),
49
- to: new Date(to).toISOString(),
67
+ from: addCalendarPeriods(to, preset.unit, -preset.periods, timeZone).toISOString(),
68
+ to: to.toISOString(),
69
+ unit: preset.unit,
50
70
  bucket: preset.bucket,
51
71
  period: preset.period,
72
+ timeZone,
52
73
  }
53
74
  }
54
75
 
55
- /** The filters that narrow every number on the page, as the address spells them. */
76
+ /** The filters that narrow every number on the page, read from the address. */
56
77
  export interface SpendFilters {
57
- /** The start of one bar: a day, an hour or a week. */
78
+ /** The start of one bar: a day, an hour or a week. The address spells it with `periodKey`. */
58
79
  readonly day?: string
59
80
  readonly provider?: string
60
81
  readonly model?: string
@@ -91,14 +112,43 @@ const modelKinds: readonly ModelKind[] = [
91
112
  "web-search",
92
113
  ]
93
114
 
94
- export function readFilters(params: URLSearchParams): SpendFilters {
115
+ /**
116
+ * How the address names a bar: its date on the reader's calendar, with its hour when bars are
117
+ * hours. A link to November 14 opens November 14 for a reader in any zone.
118
+ */
119
+ export function periodKey(start: string, range: Pick<SpendRange, "bucket" | "timeZone">): string {
120
+ const wallClock = wallClockAt(new Date(start), range.timeZone)
121
+ return range.bucket === "hour" ? wallClock.slice(0, 16) : wallClock.slice(0, 10)
122
+ }
123
+
124
+ /** The start of the bar a `periodKey` names on the reader's calendar, if it names a date. */
125
+ function periodStart(
126
+ key: string,
127
+ range: Pick<SpendRange, "bucket" | "timeZone">
128
+ ): string | undefined {
129
+ // A date, or a date and an hour; anything after them, such as an older link's zone, is ignored.
130
+ const match = /^(\d{4}-\d{2}-\d{2})(?:T(\d{2}):\d{2})?/.exec(key)
131
+ if (!match) return undefined
132
+
133
+ const wallClock = `${match[1]}T${match[2] ?? "00"}:00:00.000Z`
134
+ if (Number.isNaN(Date.parse(wallClock))) return undefined
135
+
136
+ const at = wallClockInstant(wallClock, range.timeZone)
137
+ return calendarPeriodStart(at, range.bucket, range.timeZone).toISOString()
138
+ }
139
+
140
+ export function readFilters(
141
+ params: URLSearchParams,
142
+ range: Pick<SpendRange, "bucket" | "timeZone">
143
+ ): SpendFilters {
95
144
  const value = (key: FilterKey) => params.get(key)?.trim() || undefined
145
+ const day = value("day") && periodStart(value("day")!, range)
96
146
  const kind = value("kind")
97
147
  const price = value("price")
98
148
  const source = value("source")
99
149
  const person = value("person")
100
150
  return {
101
- ...(value("day") && !Number.isNaN(Date.parse(value("day")!)) ? { day: value("day") } : {}),
151
+ ...(day ? { day } : {}),
102
152
  ...(value("provider") ? { provider: value("provider") } : {}),
103
153
  ...(value("model") ? { model: value("model") } : {}),
104
154
  ...(person && /^(none|user:.+|serviceAccount:.+)$/.test(person) ? { person } : {}),
@@ -125,25 +175,33 @@ export function apiFilters(
125
175
  }
126
176
  }
127
177
 
128
- function bucketMs(bucket: Bucket): number {
129
- return bucket === "hour" ? hourMs : bucket === "day" ? dayMs : 7 * dayMs
130
- }
131
-
132
178
  /** The range every number is read over: the chosen bar when a day is picked, else the range. */
133
179
  export function activeRange(range: SpendRange, filters: SpendFilters) {
134
180
  if (!filters.day) return { from: range.from, to: range.to }
135
- const start = Date.parse(filters.day)
181
+ const start = new Date(filters.day)
182
+ const end = addCalendarPeriods(start, range.bucket, 1, range.timeZone)
183
+
184
+ // A week bar can begin before the range and end after it; the numbers stay inside it.
136
185
  return {
137
- from: new Date(start).toISOString(),
138
- to: new Date(Math.min(start + bucketMs(range.bucket), Date.parse(range.to))).toISOString(),
186
+ from: new Date(Math.max(start.getTime(), Date.parse(range.from))).toISOString(),
187
+ to: new Date(Math.min(end.getTime(), Date.parse(range.to))).toISOString(),
139
188
  }
140
189
  }
141
190
 
142
- /** The period before, as long: the previous bar for a picked day, else the previous range. */
143
- export function priorRange(range: { readonly from: string; readonly to: string }) {
144
- const from = Date.parse(range.from)
145
- const span = Date.parse(range.to) - from
146
- return { from: new Date(from - span).toISOString(), to: new Date(from).toISOString() }
191
+ /**
192
+ * The as many hours or days just before: the previous bar for a picked day, else the previous
193
+ * range, so a range that has not finished its last day compares with one as long.
194
+ */
195
+ export function priorRange(
196
+ active: { readonly from: string; readonly to: string },
197
+ range: Pick<SpendRange, "unit" | "timeZone">
198
+ ) {
199
+ const from = new Date(active.from)
200
+ const count = calendarPeriods(from, new Date(active.to), range.unit, range.timeZone).length
201
+ return {
202
+ from: addCalendarPeriods(from, range.unit, -count, range.timeZone).toISOString(),
203
+ to: active.from,
204
+ }
147
205
  }
148
206
 
149
207
  // ── Numbers ───────────────────────────────────────────────────────────
@@ -241,42 +299,52 @@ export function sharePercent(value: number, locale = "en"): string {
241
299
  }
242
300
 
243
301
  /**
244
- * Where the range's bars start, as the server buckets them: whole UTC hours or days, and weeks
245
- * from Monday. The chart lays out its bars from these before their numbers arrive.
302
+ * Where the range's bars start, as the server buckets them: whole periods of the zone's calendar.
303
+ * The chart lays out its bars from these before their numbers arrive.
246
304
  */
247
- export function rangePeriods(range: Pick<SpendRange, "from" | "to" | "bucket">): string[] {
248
- const first = new Date(range.from)
249
- first.setUTCMinutes(0, 0, 0)
250
- if (range.bucket !== "hour") first.setUTCHours(0)
251
- if (range.bucket === "week") first.setUTCDate(first.getUTCDate() - ((first.getUTCDay() + 6) % 7))
252
- const starts: string[] = []
253
- for (let at = first.getTime(); at < Date.parse(range.to); at += bucketMs(range.bucket)) {
254
- starts.push(new Date(at).toISOString())
255
- }
256
- return starts
305
+ export function rangePeriods(
306
+ range: Pick<SpendRange, "from" | "to" | "bucket" | "timeZone">
307
+ ): string[] {
308
+ return calendarPeriods(
309
+ new Date(range.from),
310
+ new Date(range.to),
311
+ range.bucket,
312
+ range.timeZone
313
+ ).map((period) => period.start.toISOString())
257
314
  }
258
315
 
259
- /** A bar's label: its hour, its day, or the week it starts. Buckets are UTC periods. */
260
- export function bucketLabel(start: string, bucket: Bucket, locale = "en"): string {
316
+ /** A bar's label: its hour, its day, or the week it starts, on the zone's calendar. */
317
+ export function bucketLabel(
318
+ start: string,
319
+ bucket: Bucket,
320
+ locale: string,
321
+ timeZone: string
322
+ ): string {
261
323
  const date = new Date(start)
262
324
  if (bucket === "hour") {
263
- return date.toLocaleTimeString(locale, { hour: "numeric", timeZone: "UTC" })
325
+ return date.toLocaleTimeString(locale, { hour: "numeric", timeZone })
264
326
  }
265
- return date.toLocaleDateString(locale, { month: "short", day: "numeric", timeZone: "UTC" })
327
+ return date.toLocaleDateString(locale, { month: "short", day: "numeric", timeZone })
266
328
  }
267
329
 
268
330
  /** "Oct 23 – 29", "Oct 28 – Nov 3", or one day when the range is one. */
269
- export function rangeLabel(range: { readonly from: string; readonly to: string }, locale = "en") {
331
+ export function rangeLabel(
332
+ range: { readonly from: string; readonly to: string },
333
+ locale: string,
334
+ timeZone: string
335
+ ) {
270
336
  const from = new Date(range.from)
271
337
  const last = new Date(Date.parse(range.to) - 1)
272
338
  const day = (date: Date, month: boolean) =>
273
339
  date.toLocaleDateString(locale, {
274
340
  ...(month ? { month: "short" } : {}),
275
341
  day: "numeric",
276
- timeZone: "UTC",
342
+ timeZone,
277
343
  })
278
- if (from.toISOString().slice(0, 10) === last.toISOString().slice(0, 10)) return day(from, true)
279
- const sameMonth = from.getUTCMonth() === last.getUTCMonth()
344
+ if (day(from, true) === day(last, true)) return day(from, true)
345
+ const month = (date: Date) =>
346
+ date.toLocaleDateString(locale, { month: "short", year: "numeric", timeZone })
347
+ const sameMonth = month(from) === month(last)
280
348
  return `${day(from, true)} – ${day(last, !sameMonth)}`
281
349
  }
282
350
 
package/src/server.ts CHANGED
@@ -13,6 +13,7 @@ export {
13
13
  type CustomAppInstance,
14
14
  type CustomAppServer,
15
15
  type CustomAppStartOptions,
16
+ type CustomAppStopOptions,
16
17
  type CustomAuthExperienceBuildOptions,
17
18
  type CustomAuthExperienceBuildResult,
18
19
  createCustomApp,