@sixb/core 0.2.1 → 0.2.2

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 (264) hide show
  1. package/dist/actions/index.js +29 -29
  2. package/dist/agents/cancel.d.ts.map +1 -1
  3. package/dist/agents/index.d.ts +5 -3
  4. package/dist/agents/index.d.ts.map +1 -1
  5. package/dist/agents/index.js +38 -32
  6. package/dist/agents/index.js.map +1 -1
  7. package/dist/agents/run-plan.d.ts +15 -1
  8. package/dist/agents/run-plan.d.ts.map +1 -1
  9. package/dist/agents/run-session-http.d.ts.map +1 -1
  10. package/dist/agents/run-session-serve.d.ts.map +1 -1
  11. package/dist/agents/run-session.d.ts +14 -2
  12. package/dist/agents/run-session.d.ts.map +1 -1
  13. package/dist/agents/skills.d.ts +3 -0
  14. package/dist/agents/skills.d.ts.map +1 -1
  15. package/dist/agents/step-limits.d.ts +6 -0
  16. package/dist/agents/step-limits.d.ts.map +1 -1
  17. package/dist/agents/streams/index.js +1 -1
  18. package/dist/agents/streams/internal.js +1 -1
  19. package/dist/agents/streams/protocol.d.ts +8 -2
  20. package/dist/agents/streams/protocol.d.ts.map +1 -1
  21. package/dist/agents/tool-files.d.ts +3 -1
  22. package/dist/agents/tool-files.d.ts.map +1 -1
  23. package/dist/agents/validation.d.ts +1 -1
  24. package/dist/agents/validation.d.ts.map +1 -1
  25. package/dist/agents/web.d.ts +47 -0
  26. package/dist/agents/web.d.ts.map +1 -0
  27. package/dist/artifacts/publish/index.js +16 -16
  28. package/dist/auth/index.js +3 -3
  29. package/dist/authorization/index.js +2 -2
  30. package/dist/authorization/resolve.d.ts +4 -3
  31. package/dist/authorization/resolve.d.ts.map +1 -1
  32. package/dist/authorization/types.d.ts +5 -5
  33. package/dist/authorization/types.d.ts.map +1 -1
  34. package/dist/bootstrap/index.js +34 -34
  35. package/dist/{chunk-neftrg0n.js → chunk-0j3crh1w.js} +2 -2
  36. package/dist/{chunk-tvbmh7tj.js → chunk-2ajw5rz0.js} +14 -10
  37. package/dist/chunk-2ajw5rz0.js.map +18 -0
  38. package/dist/{chunk-23s66j86.js → chunk-31kcqmhf.js} +1 -1
  39. package/dist/{chunk-nghc7eq0.js → chunk-3723kgba.js} +1 -1
  40. package/dist/{chunk-rjeeyssy.js → chunk-3sqqhpr7.js} +4 -4
  41. package/dist/{chunk-m3qe54bb.js → chunk-4bm0caep.js} +1 -1
  42. package/dist/{chunk-h05rg3bx.js → chunk-4s753g3k.js} +3 -3
  43. package/dist/{chunk-8wsjr52f.js → chunk-5wtnmpze.js} +1 -1
  44. package/dist/{chunk-edx8xcsm.js → chunk-7z5rkf0m.js} +29 -6
  45. package/dist/chunk-7z5rkf0m.js.map +13 -0
  46. package/dist/{chunk-2pk5hjj9.js → chunk-80gym75n.js} +1 -1
  47. package/dist/{chunk-qbrmpgvv.js → chunk-9whfmsfk.js} +1 -1
  48. package/dist/{chunk-z3evap21.js → chunk-a5v4gjdx.js} +27 -26
  49. package/dist/{chunk-z3evap21.js.map → chunk-a5v4gjdx.js.map} +3 -3
  50. package/dist/{chunk-w53trr0c.js → chunk-a7aa0nzj.js} +5 -5
  51. package/dist/{chunk-tvefbgvw.js → chunk-az95tsh3.js} +4 -2
  52. package/dist/chunk-az95tsh3.js.map +11 -0
  53. package/dist/{chunk-7hd2ez3q.js → chunk-c4nrycdy.js} +1 -1
  54. package/dist/{chunk-epyfm23v.js → chunk-c706qvyc.js} +3 -3
  55. package/dist/{chunk-t5daew4g.js → chunk-c7cfe31p.js} +6 -6
  56. package/dist/{chunk-qsg8rw04.js → chunk-d04g36fw.js} +1 -1
  57. package/dist/{chunk-ratj7t3t.js → chunk-dsv783c3.js} +305 -32
  58. package/dist/{chunk-ratj7t3t.js.map → chunk-dsv783c3.js.map} +12 -10
  59. package/dist/{chunk-cb21tx14.js → chunk-eqgr6nsa.js} +81 -25
  60. package/dist/{chunk-cb21tx14.js.map → chunk-eqgr6nsa.js.map} +8 -7
  61. package/dist/{chunk-ax10ft8d.js → chunk-f1h34y3r.js} +5 -5
  62. package/dist/{chunk-9rh8ncs5.js → chunk-fwsvshr5.js} +1 -1
  63. package/dist/{chunk-b7a97n8b.js → chunk-ga63a3dz.js} +6 -6
  64. package/dist/{chunk-b7a97n8b.js.map → chunk-ga63a3dz.js.map} +2 -2
  65. package/dist/{chunk-cgznz22f.js → chunk-gkv8r794.js} +2 -2
  66. package/dist/{chunk-t9xyr7y9.js → chunk-j8thxj7w.js} +3 -3
  67. package/dist/{chunk-31khg3g0.js → chunk-kkjfve0t.js} +73 -2
  68. package/dist/{chunk-31khg3g0.js.map → chunk-kkjfve0t.js.map} +3 -3
  69. package/dist/{chunk-8yzhjawq.js → chunk-m2vh8gh0.js} +8 -14
  70. package/dist/{chunk-8yzhjawq.js.map → chunk-m2vh8gh0.js.map} +3 -3
  71. package/dist/{chunk-nqnfz3jg.js → chunk-mbc5hvnj.js} +2 -2
  72. package/dist/{chunk-jk97v21j.js → chunk-n4zzaf6q.js} +3 -2
  73. package/dist/chunk-n4zzaf6q.js.map +10 -0
  74. package/dist/{chunk-y2x2935j.js → chunk-nh26e7c5.js} +2 -2
  75. package/dist/{chunk-jhbk10wf.js → chunk-q9nkpr8k.js} +1 -1
  76. package/dist/{chunk-47e09r7z.js → chunk-qttqe1ah.js} +86 -6
  77. package/dist/{chunk-47e09r7z.js.map → chunk-qttqe1ah.js.map} +5 -4
  78. package/dist/{chunk-3x3bebz7.js → chunk-s7j8ewqv.js} +161 -62
  79. package/dist/{chunk-3x3bebz7.js.map → chunk-s7j8ewqv.js.map} +7 -6
  80. package/dist/{chunk-dz7a4t3a.js → chunk-twfreyxr.js} +5 -10
  81. package/dist/{chunk-dz7a4t3a.js.map → chunk-twfreyxr.js.map} +4 -4
  82. package/dist/{chunk-ks87m383.js → chunk-w1btn96n.js} +49 -24
  83. package/dist/{chunk-ks87m383.js.map → chunk-w1btn96n.js.map} +6 -6
  84. package/dist/{chunk-fg1db9xx.js → chunk-wkq3kvzd.js} +5 -5
  85. package/dist/chunk-wkq3kvzd.js.map +10 -0
  86. package/dist/{chunk-aqyjb86c.js → chunk-wrjx1fqz.js} +6 -6
  87. package/dist/{chunk-agn8d8ys.js → chunk-xtztwpkh.js} +1 -1
  88. package/dist/{chunk-0g5nyx0k.js → chunk-zeykm8my.js} +2 -2
  89. package/dist/connectors/connections/runs.d.ts +7 -0
  90. package/dist/connectors/connections/runs.d.ts.map +1 -1
  91. package/dist/execution/agent.js +29 -29
  92. package/dist/execution/object-reader-security.d.ts.map +1 -1
  93. package/dist/execution/primitive.js +29 -29
  94. package/dist/execution/request.js +30 -30
  95. package/dist/index.d.ts +2 -2
  96. package/dist/index.d.ts.map +1 -1
  97. package/dist/index.js +37 -37
  98. package/dist/materializer/index.js +15 -15
  99. package/dist/models/catalog.d.ts +16 -0
  100. package/dist/models/catalog.d.ts.map +1 -1
  101. package/dist/models/definitions.d.ts +1 -1
  102. package/dist/models/definitions.d.ts.map +1 -1
  103. package/dist/models/execution/index.js +17 -17
  104. package/dist/models/execution/model-call-recorder.d.ts +1 -1
  105. package/dist/models/execution/model-call-recorder.d.ts.map +1 -1
  106. package/dist/models/execution/web-search.d.ts +7 -0
  107. package/dist/models/execution/web-search.d.ts.map +1 -0
  108. package/dist/models/index.d.ts +3 -1
  109. package/dist/models/index.d.ts.map +1 -1
  110. package/dist/models/index.js +5 -3
  111. package/dist/models/index.js.map +1 -1
  112. package/dist/models/language-model.d.ts +12 -0
  113. package/dist/models/language-model.d.ts.map +1 -1
  114. package/dist/models/web-search-model.d.ts +66 -0
  115. package/dist/models/web-search-model.d.ts.map +1 -0
  116. package/dist/objects/index.js +29 -29
  117. package/dist/objects/query/executor.d.ts.map +1 -1
  118. package/dist/objects/query/index.d.ts +1 -0
  119. package/dist/objects/query/index.d.ts.map +1 -1
  120. package/dist/objects/query/index.js +18 -15
  121. package/dist/objects/query/index.js.map +1 -1
  122. package/dist/objects/query/sort-ties.d.ts +11 -0
  123. package/dist/objects/query/sort-ties.d.ts.map +1 -0
  124. package/dist/pipelines/index.js +15 -15
  125. package/dist/projections/internal.js +15 -15
  126. package/dist/runtime/create.d.ts +1 -1
  127. package/dist/runtime/create.d.ts.map +1 -1
  128. package/dist/runtime/internal.js +21 -21
  129. package/dist/runtime/resolve-definitions.d.ts.map +1 -1
  130. package/dist/security/index.d.ts +1 -0
  131. package/dist/security/index.d.ts.map +1 -1
  132. package/dist/security/registry.d.ts +2 -0
  133. package/dist/security/registry.d.ts.map +1 -1
  134. package/dist/security/view-conditions.d.ts.map +1 -1
  135. package/dist/security/visibility-keys.d.ts +19 -0
  136. package/dist/security/visibility-keys.d.ts.map +1 -0
  137. package/dist/shares/internal.js +15 -15
  138. package/dist/storage/agents/in-memory.d.ts +8 -2
  139. package/dist/storage/agents/in-memory.d.ts.map +1 -1
  140. package/dist/storage/agents/index.d.ts +1 -1
  141. package/dist/storage/agents/index.d.ts.map +1 -1
  142. package/dist/storage/agents/provider.d.ts +8 -2
  143. package/dist/storage/agents/provider.d.ts.map +1 -1
  144. package/dist/storage/agents/provider.js +12 -6
  145. package/dist/storage/agents/provider.js.map +1 -1
  146. package/dist/storage/agents/types.d.ts +42 -2
  147. package/dist/storage/agents/types.d.ts.map +1 -1
  148. package/dist/storage/ai-cost/provider.js +4 -4
  149. package/dist/storage/ai-limits/enforcement.js +3 -3
  150. package/dist/storage/ai-limits/provider.js +2 -2
  151. package/dist/storage/connector-connections/provider.js +3 -3
  152. package/dist/storage/connector-connections/provider.js.map +3 -3
  153. package/dist/storage/file-upload-sessions/provider.js +4 -4
  154. package/dist/storage/index.d.ts +2 -2
  155. package/dist/storage/index.d.ts.map +1 -1
  156. package/dist/storage/index.js +14 -14
  157. package/dist/storage/internal.js +2 -2
  158. package/dist/storage/migrations/types.d.ts +6 -0
  159. package/dist/storage/migrations/types.d.ts.map +1 -1
  160. package/dist/storage/objects/in-memory/query.d.ts.map +1 -1
  161. package/dist/storage/objects/index.d.ts +1 -1
  162. package/dist/storage/objects/index.d.ts.map +1 -1
  163. package/dist/storage/objects/query-preparation.d.ts +13 -0
  164. package/dist/storage/objects/query-preparation.d.ts.map +1 -1
  165. package/dist/storage/objects/read-scope.d.ts.map +1 -1
  166. package/dist/storage/objects/types.d.ts +52 -0
  167. package/dist/storage/objects/types.d.ts.map +1 -1
  168. package/dist/storage/share-grants/provider.js +2 -2
  169. package/dist/storage/workflow-runs/provider.js +4 -4
  170. package/dist/syncs/index.js +17 -17
  171. package/dist/testing/agent-storage-contract.d.ts.map +1 -1
  172. package/dist/testing/ai-limit-storage-contract.d.ts.map +1 -1
  173. package/dist/testing/ai-usage-storage-contract.d.ts.map +1 -1
  174. package/dist/testing/connector-connection-storage-contract.d.ts.map +1 -1
  175. package/dist/testing/index.js +399 -45
  176. package/dist/testing/index.js.map +8 -8
  177. package/dist/testing/object-conditional-read-scope-contract.d.ts.map +1 -1
  178. package/dist/testing/object-query-contract.d.ts.map +1 -1
  179. package/dist/webhooks/internal.js +15 -15
  180. package/dist/workflows/index.js +31 -31
  181. package/package.json +1 -1
  182. package/src/agents/README.md +2 -1
  183. package/src/agents/cancel.ts +7 -1
  184. package/src/agents/index.ts +9 -1
  185. package/src/agents/run-plan.ts +31 -0
  186. package/src/agents/run-session-http.ts +15 -12
  187. package/src/agents/run-session-serve.ts +8 -2
  188. package/src/agents/run-session.ts +31 -11
  189. package/src/agents/skills.ts +3 -0
  190. package/src/agents/step-limits.ts +6 -0
  191. package/src/agents/streams/protocol.ts +9 -4
  192. package/src/agents/tool-files.ts +11 -3
  193. package/src/agents/validation.ts +9 -0
  194. package/src/agents/web.ts +218 -0
  195. package/src/authorization/resolve.ts +9 -11
  196. package/src/authorization/types.ts +5 -5
  197. package/src/connectors/connections/runs.ts +42 -5
  198. package/src/execution/object-reader-security.ts +4 -9
  199. package/src/index.ts +2 -0
  200. package/src/models/catalog.ts +52 -3
  201. package/src/models/definitions.ts +2 -0
  202. package/src/models/execution/README.md +22 -2
  203. package/src/models/execution/model-call-recorder.ts +1 -1
  204. package/src/models/execution/web-search.ts +186 -0
  205. package/src/models/index.ts +12 -0
  206. package/src/models/language-model.ts +12 -0
  207. package/src/models/web-search-model.ts +152 -0
  208. package/src/objects/query/executor.ts +7 -3
  209. package/src/objects/query/index.ts +1 -0
  210. package/src/objects/query/sort-ties.ts +16 -0
  211. package/src/runtime/create.ts +3 -2
  212. package/src/runtime/resolve-definitions.ts +4 -0
  213. package/src/security/index.ts +1 -0
  214. package/src/security/registry.ts +2 -0
  215. package/src/security/view-conditions.ts +4 -3
  216. package/src/security/visibility-keys.ts +144 -0
  217. package/src/storage/agents/in-memory.ts +29 -2
  218. package/src/storage/agents/index.ts +2 -0
  219. package/src/storage/agents/provider.ts +57 -1
  220. package/src/storage/agents/types.ts +45 -2
  221. package/src/storage/connector-connections/in-memory.ts +2 -2
  222. package/src/storage/connector-connections/provider/connections.ts +2 -2
  223. package/src/storage/index.ts +4 -0
  224. package/src/storage/migrations/types.ts +6 -0
  225. package/src/storage/objects/in-memory/query.ts +5 -2
  226. package/src/storage/objects/index.ts +2 -0
  227. package/src/storage/objects/query-preparation.ts +59 -1
  228. package/src/storage/objects/read-scope.ts +108 -2
  229. package/src/storage/objects/types.ts +43 -0
  230. package/src/testing/agent-storage-contract.ts +70 -0
  231. package/src/testing/ai-limit-storage-contract.ts +11 -1
  232. package/src/testing/ai-usage-storage-contract.ts +15 -2
  233. package/src/testing/connector-connection-storage-contract.ts +23 -0
  234. package/src/testing/object-conditional-read-scope-contract.ts +267 -5
  235. package/src/testing/object-query-contract.ts +75 -0
  236. package/dist/chunk-edx8xcsm.js.map +0 -13
  237. package/dist/chunk-fg1db9xx.js.map +0 -10
  238. package/dist/chunk-jk97v21j.js.map +0 -10
  239. package/dist/chunk-tvbmh7tj.js.map +0 -18
  240. package/dist/chunk-tvefbgvw.js.map +0 -11
  241. /package/dist/{chunk-neftrg0n.js.map → chunk-0j3crh1w.js.map} +0 -0
  242. /package/dist/{chunk-23s66j86.js.map → chunk-31kcqmhf.js.map} +0 -0
  243. /package/dist/{chunk-nghc7eq0.js.map → chunk-3723kgba.js.map} +0 -0
  244. /package/dist/{chunk-rjeeyssy.js.map → chunk-3sqqhpr7.js.map} +0 -0
  245. /package/dist/{chunk-m3qe54bb.js.map → chunk-4bm0caep.js.map} +0 -0
  246. /package/dist/{chunk-h05rg3bx.js.map → chunk-4s753g3k.js.map} +0 -0
  247. /package/dist/{chunk-8wsjr52f.js.map → chunk-5wtnmpze.js.map} +0 -0
  248. /package/dist/{chunk-2pk5hjj9.js.map → chunk-80gym75n.js.map} +0 -0
  249. /package/dist/{chunk-qbrmpgvv.js.map → chunk-9whfmsfk.js.map} +0 -0
  250. /package/dist/{chunk-w53trr0c.js.map → chunk-a7aa0nzj.js.map} +0 -0
  251. /package/dist/{chunk-7hd2ez3q.js.map → chunk-c4nrycdy.js.map} +0 -0
  252. /package/dist/{chunk-epyfm23v.js.map → chunk-c706qvyc.js.map} +0 -0
  253. /package/dist/{chunk-t5daew4g.js.map → chunk-c7cfe31p.js.map} +0 -0
  254. /package/dist/{chunk-qsg8rw04.js.map → chunk-d04g36fw.js.map} +0 -0
  255. /package/dist/{chunk-ax10ft8d.js.map → chunk-f1h34y3r.js.map} +0 -0
  256. /package/dist/{chunk-9rh8ncs5.js.map → chunk-fwsvshr5.js.map} +0 -0
  257. /package/dist/{chunk-cgznz22f.js.map → chunk-gkv8r794.js.map} +0 -0
  258. /package/dist/{chunk-t9xyr7y9.js.map → chunk-j8thxj7w.js.map} +0 -0
  259. /package/dist/{chunk-nqnfz3jg.js.map → chunk-mbc5hvnj.js.map} +0 -0
  260. /package/dist/{chunk-y2x2935j.js.map → chunk-nh26e7c5.js.map} +0 -0
  261. /package/dist/{chunk-jhbk10wf.js.map → chunk-q9nkpr8k.js.map} +0 -0
  262. /package/dist/{chunk-aqyjb86c.js.map → chunk-wrjx1fqz.js.map} +0 -0
  263. /package/dist/{chunk-agn8d8ys.js.map → chunk-xtztwpkh.js.map} +0 -0
  264. /package/dist/{chunk-0g5nyx0k.js.map → chunk-zeykm8my.js.map} +0 -0
@@ -0,0 +1,186 @@
1
+ import { randomUUID } from "node:crypto"
2
+ import type { WebSearchModelCatalog } from "../catalog"
3
+ import { indexModelBindings } from "../catalog-index"
4
+ import { estimateModelCall, type ModelMoney } from "../pricing"
5
+ import {
6
+ assertWebSearchModel,
7
+ MAX_WEB_SEARCH_RESULTS,
8
+ validateWebSearchHits,
9
+ type WebSearchModel,
10
+ type WebSearchModelRequest,
11
+ WebSearchModelResponseError,
12
+ type WebSearchModelResponseMetadata,
13
+ type WebSearchModelResult,
14
+ } from "../web-search-model"
15
+ import type { AiModelCallRecorder } from "./model-call-recorder"
16
+ import type { ModelExecutionSession } from "./session"
17
+
18
+ /** What a search needs of an execution: its cancellation and its accounting. */
19
+ export type WebSearchExecution = Pick<ModelExecutionSession, "signal" | "accounting">
20
+
21
+ /** Scope the catalog's searches to one execution: each is admitted, bounded and recorded. */
22
+ export function bindWebSearchModels(
23
+ catalog: WebSearchModelCatalog | undefined,
24
+ session: WebSearchExecution
25
+ ): WebSearchModelCatalog | undefined {
26
+ if (!catalog) return undefined
27
+
28
+ const index = indexModelBindings(
29
+ catalog.list().map(({ model }) =>
30
+ Object.freeze({
31
+ providerId: model.providerId,
32
+ modelId: model.modelId,
33
+ definition: model.definition,
34
+ search: (input: WebSearchModelRequest) => executeWebSearch(session, model, input),
35
+ })
36
+ ),
37
+ "webSearch",
38
+ assertWebSearchModel
39
+ )
40
+
41
+ const defaultEntry = index.getByRef(catalog.default)
42
+ if (!defaultEntry) throw new Error("[SixbModels] The default web search model is not listed.")
43
+
44
+ return Object.freeze({ ...index, default: defaultEntry })
45
+ }
46
+
47
+ async function executeWebSearch(
48
+ session: WebSearchExecution,
49
+ binding: WebSearchModel,
50
+ input: WebSearchModelRequest
51
+ ): Promise<WebSearchModelResult> {
52
+ const request = prepareRequest(input)
53
+ const signal = AbortSignal.any([session.signal(input.signal), AbortSignal.timeout(30_000)])
54
+ signal.throwIfAborted()
55
+
56
+ const accounting = await session.accounting()
57
+ accounting.assertHealthy()
58
+ const model = (await binding.resolve?.()) ?? binding
59
+ assertWebSearchModel(model)
60
+ if (model.providerId !== binding.providerId || model.modelId !== binding.modelId) {
61
+ throw new TypeError(
62
+ "[SixbModels] Resolved web search model identity does not match its binding."
63
+ )
64
+ }
65
+ signal.throwIfAborted()
66
+
67
+ const callId = `call_${randomUUID()}`
68
+ await accounting.admitCall({
69
+ callId,
70
+ providerId: model.providerId,
71
+ modelId: model.modelId,
72
+ modelKind: "web-search",
73
+ inputTokens: {
74
+ status: "estimated",
75
+ tokens: Math.ceil(new TextEncoder().encode(request.query).byteLength / 4),
76
+ method: "utf8BytesDividedByFour",
77
+ },
78
+ outputTokenAllowance: 0,
79
+ reservationCost: estimateReservationCost(model, request.maxResults),
80
+ })
81
+
82
+ let result: WebSearchModelResult
83
+ try {
84
+ signal.throwIfAborted()
85
+ result = await model.search({ ...request, signal })
86
+ } catch (error) {
87
+ // A reply Sixb could not read is recorded with what it cost. Without a reply, whether the
88
+ // provider charged is unknown: recording it unpriced would leave a cost limit unable to count
89
+ // until its period ends, so the reservation is kept instead, as for a language call.
90
+ if (error instanceof WebSearchModelResponseError) {
91
+ await recordWebSearch(accounting, model, callId, error.metadata)
92
+ } else {
93
+ await accounting.markCallUnknown(callId)
94
+ }
95
+ throw error
96
+ }
97
+
98
+ // A completed, billable reply must survive cancellation and result validation failures.
99
+ await recordWebSearch(accounting, model, callId, result ?? {})
100
+ signal.throwIfAborted()
101
+
102
+ try {
103
+ return { ...result, results: validateWebSearchHits(result?.results, request.maxResults) }
104
+ } catch (cause) {
105
+ throw new WebSearchModelResponseError(
106
+ "[SixbModels] Invalid web search response.",
107
+ model.providerId,
108
+ model.modelId,
109
+ result ?? {},
110
+ { cause }
111
+ )
112
+ }
113
+ }
114
+
115
+ /** Snapshot the caller's request before the first await. */
116
+ function prepareRequest(input: WebSearchModelRequest): Omit<WebSearchModelRequest, "signal"> {
117
+ const query = input?.query
118
+ if (typeof query !== "string" || !query.trim()) {
119
+ throw new TypeError("[SixbModels] Web search requires a nonempty query.")
120
+ }
121
+
122
+ const maxResults = input.maxResults
123
+ if (typeof maxResults !== "number" || !Number.isSafeInteger(maxResults)) {
124
+ throw new TypeError("[SixbModels] Web search maxResults must be an integer.")
125
+ }
126
+
127
+ const allowedDomains = domains(input.allowedDomains, "allowedDomains")
128
+ const blockedDomains = domains(input.blockedDomains, "blockedDomains")
129
+
130
+ return {
131
+ query: query.trim(),
132
+ maxResults: Math.min(Math.max(maxResults, 1), MAX_WEB_SEARCH_RESULTS),
133
+ ...(allowedDomains === undefined ? {} : { allowedDomains }),
134
+ ...(blockedDomains === undefined ? {} : { blockedDomains }),
135
+ }
136
+ }
137
+
138
+ function domains(value: unknown, field: string): readonly string[] | undefined {
139
+ if (value === undefined) return undefined
140
+
141
+ if (!Array.isArray(value) || value.some((entry) => typeof entry !== "string" || !entry.trim())) {
142
+ throw new TypeError(`[SixbModels] Web search ${field} must contain nonempty strings.`)
143
+ }
144
+
145
+ return Object.freeze([...value])
146
+ }
147
+
148
+ function estimateReservationCost(
149
+ model: WebSearchModel,
150
+ maxResults: number
151
+ ): ModelMoney | undefined {
152
+ try {
153
+ return model.costEstimator?.estimateReservation?.({ maxResults })
154
+ } catch {
155
+ // Optional pricing cannot bypass an enforced budget: admission fails closed without it.
156
+ return undefined
157
+ }
158
+ }
159
+
160
+ async function recordWebSearch(
161
+ accounting: AiModelCallRecorder,
162
+ model: WebSearchModel,
163
+ callId: string,
164
+ metadata: WebSearchModelResponseMetadata
165
+ ): Promise<void> {
166
+ const usage = metadata.usage ?? {}
167
+ const estimate = estimateModelCall(model, {
168
+ usage,
169
+ route: metadata.route,
170
+ responseModelId: metadata.responseModelId,
171
+ })
172
+
173
+ await accounting.onModelCallEnd({
174
+ callId,
175
+ modelKind: "web-search",
176
+ providerId: model.providerId,
177
+ modelId: model.modelId,
178
+ responseId: metadata.providerIds?.responseId ?? callId,
179
+ responseModelId: metadata.responseModelId,
180
+ providerIds: metadata.providerIds,
181
+ usage,
182
+ cost: metadata.reportedCost ? { status: "reported", ...metadata.reportedCost } : estimate,
183
+ ...(metadata.reportedCost ? { estimate } : {}),
184
+ route: metadata.route,
185
+ })
186
+ }
@@ -50,6 +50,8 @@ export type {
50
50
  ModelRef,
51
51
  RerankingModelCatalog,
52
52
  RerankingModelEntry,
53
+ WebSearchModelCatalog,
54
+ WebSearchModelEntry,
53
55
  } from "./catalog"
54
56
  export { createModelCatalog, LANGUAGE_MODEL_TIERS } from "./catalog"
55
57
  export type { DecisionModelCatalog, DecisionModelEntry } from "./decision/catalog"
@@ -202,3 +204,13 @@ export type {
202
204
  } from "./reranking-model"
203
205
  export { RerankingModelResponseError } from "./reranking-model"
204
206
  export type { ModelOutput, ModelTool, ModelToolExecutionContext } from "./tools"
207
+ export type {
208
+ WebSearchCostEstimator,
209
+ WebSearchHit,
210
+ WebSearchModel,
211
+ WebSearchModelDefinition,
212
+ WebSearchModelRequest,
213
+ WebSearchModelResponseMetadata,
214
+ WebSearchModelResult,
215
+ } from "./web-search-model"
216
+ export { WebSearchModelResponseError } from "./web-search-model"
@@ -5,6 +5,7 @@ import type { LanguageModelStreamEvent } from "./events"
5
5
  import type { ModelMessage } from "./messages"
6
6
  import type { ModelCostEstimator } from "./pricing"
7
7
  import type { ModelRateCard } from "./rate-card"
8
+ import type { WebSearchModel } from "./web-search-model"
8
9
 
9
10
  export const MODEL_REASONING_EFFORTS = ["minimal", "low", "medium", "high", "xhigh", "max"] as const
10
11
 
@@ -134,6 +135,17 @@ export interface LanguageModel {
134
135
  * startup.
135
136
  */
136
137
  readonly maxOutputTokens?: number
138
+ /**
139
+ * The web search its provider offers, under the same credentials. Sixb searches with it when
140
+ * `models.webSearch` names none.
141
+ */
142
+ readonly webSearch?: WebSearchModel
143
+ /**
144
+ * The names of the tools its provider runs itself, which every request declares, such as
145
+ * `web_search` from `providerTools`. Sixb checks at startup that none takes a name it gives the
146
+ * Agent's own tools.
147
+ */
148
+ readonly providerToolNames?: readonly string[]
137
149
  /**
138
150
  * Return an executable model pinned to operational metadata, preserving model identity.
139
151
  * `offline` requires a local snapshot without catalog I/O. Workers retain this model
@@ -0,0 +1,152 @@
1
+ import type { ModelDefinition } from "./definitions"
2
+ import { ModelProviderError } from "./errors"
3
+ import type { ModelProviderIds, ModelRoute, ModelUsage } from "./events"
4
+ import type { ModelCostEstimator, ModelMoney, ModelReportedCost } from "./pricing"
5
+
6
+ export interface WebSearchModelDefinition extends ModelDefinition {
7
+ readonly kind: "web-search"
8
+ }
9
+
10
+ export interface WebSearchModelRequest {
11
+ readonly query: string
12
+ /** How many results to return; Sixb clamps it to 1–10. */
13
+ readonly maxResults: number
14
+ /** A hint for the provider; Sixb filters the results again. */
15
+ readonly allowedDomains?: readonly string[]
16
+ readonly blockedDomains?: readonly string[]
17
+ readonly signal?: AbortSignal
18
+ }
19
+
20
+ /** One search result. Sixb cuts the snippet to 300 characters. */
21
+ export interface WebSearchHit {
22
+ readonly url: string
23
+ readonly title: string
24
+ readonly snippet: string
25
+ /** ISO 8601, when the provider knows when the page was published. */
26
+ readonly publishedAt?: string
27
+ }
28
+
29
+ export interface WebSearchModelResponseMetadata {
30
+ readonly usage?: ModelUsage
31
+ readonly providerIds?: ModelProviderIds
32
+ readonly responseModelId?: string
33
+ readonly reportedCost?: ModelReportedCost
34
+ readonly route?: ModelRoute
35
+ }
36
+
37
+ export interface WebSearchModelResult extends WebSearchModelResponseMetadata {
38
+ readonly results: readonly WebSearchHit[]
39
+ }
40
+
41
+ export interface WebSearchCostEstimator extends Pick<ModelCostEstimator, "estimate"> {
42
+ /** Return undefined if the search cannot be priced safely before it runs. */
43
+ estimateReservation?(input: { readonly maxResults: number }): ModelMoney | undefined
44
+ }
45
+
46
+ /** Provider binding. Resolving it may fetch metadata, but must never run a search. */
47
+ export interface WebSearchModel {
48
+ readonly providerId: string
49
+ readonly modelId: string
50
+ readonly definition: WebSearchModelDefinition
51
+ readonly costEstimator?: WebSearchCostEstimator
52
+ resolve?(): Promise<WebSearchModel>
53
+ search(request: WebSearchModelRequest): Promise<WebSearchModelResult>
54
+ }
55
+
56
+ /** A billable reply Sixb could not read; its metadata is still recorded. */
57
+ export class WebSearchModelResponseError extends ModelProviderError {
58
+ constructor(
59
+ message: string,
60
+ providerId: string,
61
+ modelId: string,
62
+ readonly metadata: WebSearchModelResponseMetadata,
63
+ options?: { cause?: unknown }
64
+ ) {
65
+ super(message, providerId, modelId, {
66
+ code: "invalid_web_search_response",
67
+ retryable: false,
68
+ cause: options?.cause,
69
+ })
70
+ }
71
+ }
72
+
73
+ /** The most results one search returns. */
74
+ export const MAX_WEB_SEARCH_RESULTS = 10
75
+
76
+ const SNIPPET_CHARACTERS = 300
77
+
78
+ export function assertWebSearchModel(model: WebSearchModel): void {
79
+ if (
80
+ !model ||
81
+ typeof model !== "object" ||
82
+ typeof model.search !== "function" ||
83
+ !validIdentifier(model.providerId) ||
84
+ !validIdentifier(model.modelId) ||
85
+ model.definition?.kind !== "web-search" ||
86
+ model.definition.providerId !== model.providerId ||
87
+ model.definition.modelId !== model.modelId
88
+ ) {
89
+ throw new TypeError("[Sixb] Expected a WebSearchModel with a valid identity and search method.")
90
+ }
91
+ }
92
+
93
+ /**
94
+ * Check a provider's hits and keep at most `maxResults`: string titles and snippets, snippets cut
95
+ * to 300 characters. A hit without an http(s) URL is dropped, and so is a date that does not parse;
96
+ * the other hits are kept.
97
+ */
98
+ export function validateWebSearchHits(results: unknown, maxResults: number): WebSearchHit[] {
99
+ if (!Array.isArray(results)) {
100
+ throw new TypeError("[SixbModels] Web search must return a list of results.")
101
+ }
102
+
103
+ const hits: WebSearchHit[] = []
104
+ for (const result of results as unknown[]) {
105
+ if (!result || typeof result !== "object") {
106
+ throw new TypeError("[SixbModels] Invalid web search result.")
107
+ }
108
+
109
+ const url: unknown = Reflect.get(result, "url")
110
+ const title: unknown = Reflect.get(result, "title")
111
+ const snippet: unknown = Reflect.get(result, "snippet")
112
+ const publishedAt: unknown = Reflect.get(result, "publishedAt")
113
+ if (
114
+ typeof title !== "string" ||
115
+ typeof snippet !== "string" ||
116
+ (publishedAt !== undefined && typeof publishedAt !== "string")
117
+ ) {
118
+ throw new TypeError("[SixbModels] Web search results need a title and a snippet.")
119
+ }
120
+
121
+ // One odd hit should not cost the caller the others.
122
+ if (!isWebUrl(url)) continue
123
+
124
+ const text = snippet.trim()
125
+ const published = publishedAt === undefined ? Number.NaN : Date.parse(publishedAt)
126
+
127
+ hits.push({
128
+ url,
129
+ title: title.trim(),
130
+ snippet: text.length > SNIPPET_CHARACTERS ? `${text.slice(0, SNIPPET_CHARACTERS)}…` : text,
131
+ ...(Number.isNaN(published) ? {} : { publishedAt: new Date(published).toISOString() }),
132
+ })
133
+ if (hits.length === maxResults) break
134
+ }
135
+
136
+ return hits
137
+ }
138
+
139
+ function isWebUrl(value: unknown): value is string {
140
+ if (typeof value !== "string") return false
141
+
142
+ try {
143
+ const { protocol } = new URL(value)
144
+ return protocol === "http:" || protocol === "https:"
145
+ } catch {
146
+ return false
147
+ }
148
+ }
149
+
150
+ function validIdentifier(value: unknown): value is string {
151
+ return typeof value === "string" && value.length > 0 && value.trim() === value
152
+ }
@@ -40,6 +40,7 @@ import { usePrimaryIdLookups } from "./primary-id"
40
40
  import { rerankObjectCandidates } from "./reranking-executor"
41
41
  import { findQueryReranking } from "./reranking-query"
42
42
  import { compareQueryScalarValues } from "./scalar-values"
43
+ import { sortTieDirection } from "./sort-ties"
43
44
  import { withoutUserExpansions } from "./user-expansions"
44
45
  import {
45
46
  type AdmittedObjectQuery,
@@ -1040,10 +1041,12 @@ function compareExpansionEdges(
1040
1041
  const comparison = compareRowsBySortField(leftRow, rightRow, field)
1041
1042
  if (comparison !== 0) return comparison
1042
1043
  }
1044
+
1043
1045
  // Identity tiebreak keeps the trim deterministic for equal sort keys.
1044
- return targetKey(left.neighborTypeId, left.neighborId).localeCompare(
1046
+ const identity = targetKey(left.neighborTypeId, left.neighborId).localeCompare(
1045
1047
  targetKey(right.neighborTypeId, right.neighborId)
1046
1048
  )
1049
+ return sortTieDirection(fields) === "desc" ? -identity : identity
1047
1050
  }
1048
1051
 
1049
1052
  function compareRowsBySortField(
@@ -1138,6 +1141,7 @@ function sortEntries(
1138
1141
  entries: readonly FallbackEntry[],
1139
1142
  fields: readonly ObjectQuerySortField[]
1140
1143
  ): FallbackEntry[] {
1144
+ const ties = sortTieDirection(fields)
1141
1145
  return [...entries].sort((left, right) => {
1142
1146
  for (const field of fields) {
1143
1147
  const comparison = compareSortField(left, right, field)
@@ -1145,9 +1149,9 @@ function sortEntries(
1145
1149
  }
1146
1150
  // Preserve storage order for true ties, then use identity as a deterministic
1147
1151
  // final fallback so tests and page tokens stay stable.
1148
- return (
1152
+ const tie =
1149
1153
  left.order - right.order || rowIdentityKey(left.row).localeCompare(rowIdentityKey(right.row))
1150
- )
1154
+ return ties === "desc" ? -tie : tie
1151
1155
  })
1152
1156
  }
1153
1157
 
@@ -76,6 +76,7 @@ export type {
76
76
  ObjectQueryProviderOperation,
77
77
  } from "./planner"
78
78
  export { planObjectQuery } from "./planner"
79
+ export { sortTieDirection } from "./sort-ties"
79
80
  export type {
80
81
  ObjectQueryValidationIssue,
81
82
  ObjectQueryValidationOptions,
@@ -0,0 +1,16 @@
1
+ import type { ObjectQuerySortDirection, ObjectQuerySortField } from "./ir"
2
+
3
+ /**
4
+ * The direction objects equal on every sorted property come in: their identity order, reversed
5
+ * when the last property sorted descends.
6
+ *
7
+ * A descending sort then lists the ascending one backwards, apart from null values, which sort last
8
+ * either way. That is what lets PostgreSQL serve both from one ascending index, read backwards for
9
+ * the descending one. Every provider and the fallback reverse their tie order this way.
10
+ */
11
+ export function sortTieDirection(
12
+ fields: readonly ObjectQuerySortField[]
13
+ ): ObjectQuerySortDirection {
14
+ const last = fields.filter((field) => field.kind === "property").at(-1)
15
+ return last?.direction === "desc" ? "desc" : "asc"
16
+ }
@@ -73,7 +73,7 @@ export interface CreateSixbOptions<in out TParams extends ParamsConfig = ParamsC
73
73
  models?: ModelCatalogInput
74
74
  /** Project tools available to Agent runtimes. */
75
75
  tools?: readonly AgentToolDefinition[]
76
- /** How the project's Agent runs: how many steps a turn or a sub-agent may take. */
76
+ /** How the project's Agent runs: how many steps a turn or a sub-agent may take, its web tools. */
77
77
  agent?: AgentOptions
78
78
  datasets?: readonly DatasetDefinition[]
79
79
  /** Connector definitions to register in addition to auto-discovered `connectors/` exports. */
@@ -124,7 +124,7 @@ export async function createSixb<const TParams extends ParamsConfig = ParamsConf
124
124
  const skills = await discoverAgentSkills(projectRoot)
125
125
  const instructions = await discoverProjectInstructions(projectRoot)
126
126
  const ontologyFiles = await discoverOntologyFiles(projectRoot)
127
- const { maxSteps, subagentMaxSteps } = options.agent ?? {}
127
+ const { maxSteps, subagentMaxSteps, web } = options.agent ?? {}
128
128
 
129
129
  // Explicit definitions come first so local setup can override ordering while duplicate ids are
130
130
  // still rejected by the SixbHost constructor. Every family merges — `actions` and `projections`
@@ -165,6 +165,7 @@ export async function createSixb<const TParams extends ParamsConfig = ParamsConf
165
165
  agent: {
166
166
  ...(maxSteps === undefined ? {} : { maxSteps }),
167
167
  ...(subagentMaxSteps === undefined ? {} : { subagentMaxSteps }),
168
+ ...(web === undefined ? {} : { web }),
168
169
  skills,
169
170
  ...(instructions === undefined ? {} : { instructions }),
170
171
  ontologyDocs: { modules: discoveredOntology.modules, ...ontologyFiles },
@@ -6,6 +6,7 @@ import { assertNoAgentDefinitions } from "../agents/retired-config"
6
6
  import { createAgentSkillCatalog } from "../agents/skills"
7
7
  import { assertMaxSteps } from "../agents/step-limits"
8
8
  import { createAgentToolCatalog } from "../agents/tool-catalog"
9
+ import { assertNoProviderWebTools, resolveAgentWebOptions } from "../agents/web"
9
10
  import type { ConnectorDefinition } from "../connectors"
10
11
  import { isDatasetPick } from "../datasets/builders"
11
12
  import { columnsByName } from "../datasets/column-index"
@@ -105,6 +106,8 @@ export function resolveDefinitions(options: DefinitionOptions): ResolvedDefiniti
105
106
  const subagentMaxSteps = options.agent?.subagentMaxSteps
106
107
  assertMaxSteps(maxSteps, "agent.maxSteps")
107
108
  assertMaxSteps(subagentMaxSteps, "agent.subagentMaxSteps")
109
+ const web = resolveAgentWebOptions(options.agent?.web)
110
+ if (web !== false) assertNoProviderWebTools(models)
108
111
  const ontologyDocs = createOntologyDocsCatalog({
109
112
  objectTypes: ontology.listObjectTypes(),
110
113
  ...(options.agent?.ontologyDocs === undefined ? {} : { docs: options.agent.ontologyDocs }),
@@ -226,6 +229,7 @@ export function resolveDefinitions(options: DefinitionOptions): ResolvedDefiniti
226
229
  ontologyDocs,
227
230
  ...(maxSteps === undefined ? {} : { maxSteps }),
228
231
  ...(subagentMaxSteps === undefined ? {} : { subagentMaxSteps }),
232
+ ...(web === undefined ? {} : { web }),
229
233
  }),
230
234
  connectors: createDefinitionCatalog(connectorsById),
231
235
  datasets: createDefinitionCatalog(datasetsById),
@@ -61,3 +61,4 @@ export {
61
61
  isRoleDefinition,
62
62
  validateSecurityDefinitionsAtStartup,
63
63
  } from "./validation"
64
+ export type { ViewCondition } from "./view-conditions"
@@ -18,6 +18,8 @@ export interface SecurityDefinitionCatalog {
18
18
  listRoles(): readonly RoleDefinition[]
19
19
  getRoleById(roleId: string): RoleDefinition | null
20
20
  listResolvedRoles(): readonly ResolvedRole[]
21
+ /** Every role's `can.view(Type).where(...)`, validated, in declaration order. */
22
+ listViewConditions(): readonly ViewCondition[]
21
23
  listMembershipPolicies(): readonly MembershipPolicyDefinition[]
22
24
  getMembershipPolicyById(policyId: string): MembershipPolicyDefinition | null
23
25
  }
@@ -1,4 +1,3 @@
1
- import { bindCurrentUserPredicate } from "../objects/query/current-user"
2
1
  import { ObjectQueryValidationError } from "../objects/query/errors"
3
2
  import type { ObjectQueryPredicate } from "../objects/query/ir"
4
3
  import {
@@ -10,6 +9,7 @@ import { compileConditionalObjectReadScope } from "../storage/objects/read-scope
10
9
  import type { ObjectReadScopeFactory } from "../storage/objects/types"
11
10
  import { SecurityValidationError } from "./errors"
12
11
  import type { GrantDefinition, Selection } from "./types"
12
+ import { viewConditionReadCondition } from "./visibility-keys"
13
13
 
14
14
  /** A role's `can.view(Type).where(...)`, validated against the ontology at startup. */
15
15
  export interface ViewCondition {
@@ -103,7 +103,6 @@ export function assertViewConditionsReadable(input: {
103
103
  readonly getSubTypes: (objectTypeId: string) => readonly string[]
104
104
  }): void {
105
105
  for (const condition of input.conditions) {
106
- const predicate = bindCurrentUserPredicate(condition.predicate, STARTUP_CHECK_USER)
107
106
  const objectTypeIds = [condition.objectTypeId, ...input.getSubTypes(condition.objectTypeId)]
108
107
 
109
108
  try {
@@ -111,7 +110,9 @@ export function assertViewConditionsReadable(input: {
111
110
  projectId: input.projectId,
112
111
  scope: compileConditionalObjectReadScope({
113
112
  kind: "conditional",
114
- conditions: objectTypeIds.map((objectTypeId) => ({ objectTypeId, predicate })),
113
+ conditions: objectTypeIds.map((objectTypeId) =>
114
+ viewConditionReadCondition(objectTypeId, [condition.predicate], STARTUP_CHECK_USER)
115
+ ),
115
116
  }),
116
117
  })
117
118
  } catch (error) {