@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,144 @@
1
+ import { bindCurrentUserPredicate } from "../objects/query/current-user"
2
+ import type { ObjectQueryPredicate } from "../objects/query/ir"
3
+ import { isCurrentUser, type UserRef } from "../ontology/user-ref"
4
+ import type { ObjectReadCondition, ObjectVisibilityKeys } from "../storage/objects/types"
5
+
6
+ /**
7
+ * The keys of a view condition, or undefined when it has none.
8
+ *
9
+ * A part that never reads `currentUser()` shows an object to everyone holding the condition while
10
+ * it matches. `eq` and `contains` with `currentUser()` show it to the users the property names, and
11
+ * `in` to those and to everyone when another value matches. Two kinds of conditions keep their
12
+ * predicate: negating a comparison with `currentUser()` shows an object to every user but some,
13
+ * and requiring two of them at once, to the users two properties share.
14
+ */
15
+ export function viewConditionKeys(
16
+ predicate: ObjectQueryPredicate
17
+ ): ObjectVisibilityKeys | undefined {
18
+ const part = keyedPart(predicate)
19
+ if (part === undefined) return undefined
20
+
21
+ return part === EVERYONE ? { kind: "everyone", when: predicate } : part
22
+ }
23
+
24
+ /**
25
+ * What a reader holding these conditions on one concrete type reads it through: their predicates
26
+ * bound to its user, and, for the conditions that have keys, the same condition as keys.
27
+ */
28
+ export function viewConditionReadCondition(
29
+ objectTypeId: string,
30
+ predicates: readonly ObjectQueryPredicate[],
31
+ user: UserRef | undefined
32
+ ): ObjectReadCondition {
33
+ const keys: ObjectVisibilityKeys[] = []
34
+ const remainder: ObjectQueryPredicate[] = []
35
+
36
+ for (const predicate of predicates) {
37
+ const conditionKeys = viewConditionKeys(predicate)
38
+ if (conditionKeys) keys.push(conditionKeys)
39
+ else remainder.push(bindCurrentUserPredicate(predicate, user))
40
+ }
41
+
42
+ const bound = bindCurrentUserPredicate(anyOf(predicates), user)
43
+ if (keys.length === 0) return { objectTypeId, predicate: bound }
44
+
45
+ return {
46
+ objectTypeId,
47
+ predicate: bound,
48
+ visibility: {
49
+ keys,
50
+ ...(user ? { user } : {}),
51
+ ...(remainder.length > 0 ? { remainder: anyOf(remainder) } : {}),
52
+ },
53
+ }
54
+ }
55
+
56
+ /** A part that reads no `currentUser()`: it shows an object to everyone while it matches. */
57
+ const EVERYONE = "everyone"
58
+
59
+ function keyedPart(
60
+ predicate: ObjectQueryPredicate
61
+ ): typeof EVERYONE | ObjectVisibilityKeys | undefined {
62
+ if (!readsCurrentUser(predicate)) return EVERYONE
63
+
64
+ switch (predicate.op) {
65
+ case "and": {
66
+ const parts = predicate.items.map(keyedPart)
67
+ if (parts.includes(undefined)) return undefined
68
+
69
+ const everyone = predicate.items.filter((_, index) => parts[index] === EVERYONE)
70
+ const keyed = parts.filter(isKeys)
71
+
72
+ // Each keyed part names its own users: only the users they share would hold all of them.
73
+ if (keyed.length !== 1) return undefined
74
+
75
+ return everyone.length === 0
76
+ ? keyed[0]
77
+ : { kind: "when", when: allOf(everyone), keys: keyed[0]! }
78
+ }
79
+
80
+ case "or": {
81
+ const parts = predicate.items.map(keyedPart)
82
+ if (parts.includes(undefined)) return undefined
83
+
84
+ const everyone = predicate.items.filter((_, index) => parts[index] === EVERYONE)
85
+ const items = [
86
+ ...(everyone.length > 0 ? [{ kind: "everyone" as const, when: anyOf(everyone) }] : []),
87
+ ...parts.filter(isKeys),
88
+ ]
89
+ return items.length === 1 ? items[0] : { kind: "union", items }
90
+ }
91
+
92
+ case "eq":
93
+ return { kind: "user", propertyId: predicate.propertyId }
94
+
95
+ case "contains":
96
+ return { kind: "users", propertyId: predicate.propertyId }
97
+
98
+ case "in": {
99
+ const values = predicate.values.filter((value) => !isCurrentUser(value))
100
+ const user: ObjectVisibilityKeys = { kind: "user", propertyId: predicate.propertyId }
101
+ if (values.length === 0) return user
102
+
103
+ return {
104
+ kind: "union",
105
+ items: [{ kind: "everyone", when: { ...predicate, values } }, user],
106
+ }
107
+ }
108
+
109
+ default:
110
+ // `not` and `neq` around `currentUser()`.
111
+ return undefined
112
+ }
113
+ }
114
+
115
+ function readsCurrentUser(predicate: ObjectQueryPredicate): boolean {
116
+ switch (predicate.op) {
117
+ case "and":
118
+ case "or":
119
+ return predicate.items.some(readsCurrentUser)
120
+ case "not":
121
+ return readsCurrentUser(predicate.item)
122
+ case "in":
123
+ return predicate.values.some(isCurrentUser)
124
+ case "exists":
125
+ case "constant":
126
+ return false
127
+ default:
128
+ return isCurrentUser(predicate.value)
129
+ }
130
+ }
131
+
132
+ function isKeys(
133
+ part: typeof EVERYONE | ObjectVisibilityKeys | undefined
134
+ ): part is ObjectVisibilityKeys {
135
+ return typeof part === "object"
136
+ }
137
+
138
+ function allOf(predicates: readonly ObjectQueryPredicate[]): ObjectQueryPredicate {
139
+ return predicates.length === 1 ? predicates[0]! : { op: "and", items: predicates }
140
+ }
141
+
142
+ function anyOf(predicates: readonly ObjectQueryPredicate[]): ObjectQueryPredicate {
143
+ return predicates.length === 1 ? predicates[0]! : { op: "or", items: predicates }
144
+ }
@@ -17,6 +17,7 @@ import {
17
17
  agentRunMayHoldCalls,
18
18
  assertAgentApprovalCaller,
19
19
  assertAgentApprovalModeInput,
20
+ assertAgentBackgroundCommandRef,
20
21
  assertAgentComputerSession,
21
22
  assertAgentContextCheckpointAnchors,
22
23
  assertAgentContextCheckpointAuthority,
@@ -52,6 +53,7 @@ import {
52
53
  snapshotAgentThreadSandboxParams,
53
54
  subagentRunMatchesCreateInput,
54
55
  transitionAgentThreadSandbox,
56
+ withStopRequest,
55
57
  } from "./provider"
56
58
  import type {
57
59
  AddAgentThreadParticipantsInput,
@@ -61,6 +63,7 @@ import type {
61
63
  AgentApprovalOutcome,
62
64
  AgentApprovalRecord,
63
65
  AgentApprovalStore,
66
+ AgentBackgroundCommandRef,
64
67
  AgentComputerSessionRecord,
65
68
  AgentComputerSessionStore,
66
69
  AgentContextCheckpointRecord,
@@ -1595,9 +1598,33 @@ function compareApprovals(left: AgentApprovalRecord, right: AgentApprovalRecord)
1595
1598
  class InMemoryAgentComputerSessionStore implements AgentComputerSessionStore {
1596
1599
  private readonly sessions = new Map<string, AgentComputerSessionRecord>()
1597
1600
 
1598
- async hold(input: AgentComputerSessionRecord): Promise<void> {
1601
+ async hold(input: Omit<AgentComputerSessionRecord, "stopRequests">): Promise<void> {
1599
1602
  assertAgentComputerSession(input)
1600
- this.sessions.set(sessionKey(input), clone(input))
1603
+ const { backgroundCommands, ...session } = input
1604
+ const stopRequests = this.sessions.get(sessionKey(input))?.stopRequests
1605
+ this.sessions.set(
1606
+ sessionKey(input),
1607
+ clone({
1608
+ ...session,
1609
+ ...(backgroundCommands?.length ? { backgroundCommands } : {}),
1610
+ ...(stopRequests?.length ? { stopRequests } : {}),
1611
+ })
1612
+ )
1613
+ }
1614
+
1615
+ async requestStop(input: {
1616
+ readonly projectId: string
1617
+ readonly id: string
1618
+ readonly ownerPrincipal: Principal
1619
+ readonly command: AgentBackgroundCommandRef
1620
+ }): Promise<AgentComputerSessionRecord | null> {
1621
+ assertAgentBackgroundCommandRef(input.command)
1622
+ const held = this.sessions.get(sessionKey(input))
1623
+ if (!held) return null
1624
+
1625
+ const next = { ...held, stopRequests: withStopRequest(held.stopRequests ?? [], input.command) }
1626
+ this.sessions.set(sessionKey(input), clone(next))
1627
+ return clone(next)
1601
1628
  }
1602
1629
 
1603
1630
  async release(input: {
@@ -13,6 +13,8 @@ export type {
13
13
  AgentApprovalSettledStatus,
14
14
  AgentApprovalStatus,
15
15
  AgentApprovalStore,
16
+ AgentBackgroundCommandRef,
17
+ AgentComputerBackgroundCommand,
16
18
  AgentComputerSessionRecord,
17
19
  AgentComputerSessionStore,
18
20
  AgentContextCheckpointReason,
@@ -9,12 +9,17 @@ import { isModelReasoning } from "../../models/language-model"
9
9
  import type { ExecutionRecord, ExecutionStorage } from "../executions"
10
10
  import { findAgentRunExecution } from "../executions/run-link"
11
11
  import { AgentStorageError } from "./errors"
12
+ import { AGENT_COMPUTER_BACKGROUND_COMMANDS_MAX } from "./types"
13
+
14
+ export { AGENT_COMPUTER_BACKGROUND_COMMANDS_MAX }
15
+
12
16
  import type {
13
17
  AddAgentThreadParticipantsInput,
14
18
  AgentApprovalCall,
15
19
  AgentApprovalMode,
16
20
  AgentApprovalRecord,
17
21
  AgentApprovalStatus,
22
+ AgentBackgroundCommandRef,
18
23
  AgentComputerSessionRecord,
19
24
  AgentContextCheckpointRecord,
20
25
  AgentMemoryChange,
@@ -490,7 +495,7 @@ export function assertComputerPlace(runsOn: unknown, computer: unknown, prefix =
490
495
 
491
496
  /** Validate a computer session before a store keeps it. */
492
497
  export function assertAgentComputerSession(
493
- session: AgentComputerSessionRecord,
498
+ session: Omit<AgentComputerSessionRecord, "stopRequests">,
494
499
  prefix = "Sixb"
495
500
  ): void {
496
501
  if (typeof session.id !== "string" || session.id.trim() === "" || session.id.length > 200) {
@@ -506,6 +511,57 @@ export function assertAgentComputerSession(
506
511
  )
507
512
  }
508
513
  assertAgentThreadComputer(session.computer, prefix)
514
+
515
+ const commands = session.backgroundCommands ?? []
516
+ if (!Array.isArray(commands) || commands.length > AGENT_COMPUTER_BACKGROUND_COMMANDS_MAX) {
517
+ throw new AgentStorageError(
518
+ "invalid_input",
519
+ `[${prefix}] A computer session reports at most ${AGENT_COMPUTER_BACKGROUND_COMMANDS_MAX} background commands.`
520
+ )
521
+ }
522
+ for (const command of commands) {
523
+ assertAgentBackgroundCommandRef(command, prefix)
524
+ if (
525
+ typeof command.command !== "string" ||
526
+ !["running", "exited", "stopped"].includes(command.status) ||
527
+ (command.exitCode !== undefined && !Number.isInteger(command.exitCode)) ||
528
+ (command.endedAt !== undefined && typeof command.endedAt !== "string")
529
+ ) {
530
+ throw new AgentStorageError(
531
+ "invalid_input",
532
+ `[${prefix}] A background command names its command, its status (running, exited or stopped), and an integer exit code once it ended.`
533
+ )
534
+ }
535
+ }
536
+ }
537
+
538
+ /** Validate which background command a stop names. */
539
+ export function assertAgentBackgroundCommandRef(
540
+ ref: AgentBackgroundCommandRef,
541
+ prefix = "Sixb"
542
+ ): void {
543
+ const fields = [ref?.threadId, ref?.id, ref?.startedAt]
544
+ if (fields.some((field) => typeof field !== "string" || field === "" || field.length > 200)) {
545
+ throw new AgentStorageError(
546
+ "invalid_input",
547
+ `[${prefix}] A background command is named by its thread, its id and its start, each a non-empty string of at most 200 characters.`
548
+ )
549
+ }
550
+ }
551
+
552
+ /** The stop requests a session keeps with `command` added: once, the newest ones. */
553
+ export function withStopRequest(
554
+ requests: readonly AgentBackgroundCommandRef[],
555
+ command: AgentBackgroundCommandRef
556
+ ): AgentBackgroundCommandRef[] {
557
+ const same = (other: AgentBackgroundCommandRef) =>
558
+ other.threadId === command.threadId &&
559
+ other.id === command.id &&
560
+ other.startedAt === command.startedAt
561
+ if (requests.some(same)) return [...requests]
562
+
563
+ const ref = { threadId: command.threadId, id: command.id, startedAt: command.startedAt }
564
+ return [...requests, ref].slice(-AGENT_COMPUTER_BACKGROUND_COMMANDS_MAX)
509
565
  }
510
566
 
511
567
  /** C0 and C1 controls, DEL, and the marks that reorder text where a terminal or page shows it. */
@@ -258,6 +258,36 @@ export interface AgentComputerSessionRecord {
258
258
  readonly ownerPrincipal: Principal
259
259
  readonly computer: AgentThreadComputer
260
260
  readonly expiresAt: Date
261
+ /** Its threads' background commands, as its latest renewal reported them. */
262
+ readonly backgroundCommands?: readonly AgentComputerBackgroundCommand[]
263
+ /** The commands someone asked to stop: each renewal hands back those still running. */
264
+ readonly stopRequests?: readonly AgentBackgroundCommandRef[]
265
+ }
266
+
267
+ /** How many background commands a computer session reports, and keeps stop requests for. */
268
+ export const AGENT_COMPUTER_BACKGROUND_COMMANDS_MAX = 64
269
+
270
+ /**
271
+ * A background command an open `sixb` runs for one of its threads, which outlives the turn that
272
+ * started it: the web shows how it stands between turns.
273
+ */
274
+ export interface AgentComputerBackgroundCommand {
275
+ readonly threadId: string
276
+ /** `bg_<hex>`, as the agent's tools name it. */
277
+ readonly id: string
278
+ readonly command: string
279
+ readonly status: "running" | "exited" | "stopped"
280
+ readonly exitCode?: number
281
+ /** ISO timestamps. */
282
+ readonly startedAt: string
283
+ readonly endedAt?: string
284
+ }
285
+
286
+ /** A background command by its start: its id comes again once `sixb` restarts. */
287
+ export interface AgentBackgroundCommandRef {
288
+ readonly threadId: string
289
+ readonly id: string
290
+ readonly startedAt: string
261
291
  }
262
292
 
263
293
  export interface RemoveAgentThreadParticipantInput {
@@ -1252,8 +1282,21 @@ export const AGENT_MEMORY_HISTORY_DAYS = 90
1252
1282
 
1253
1283
  /** Each open `sixb` on its owner's computers, as a lease it renews. */
1254
1284
  export interface AgentComputerSessionStore {
1255
- /** Open the session, or renew it until `expiresAt`; its computer and folder are kept as given. */
1256
- hold(input: AgentComputerSessionRecord): Promise<void>
1285
+ /**
1286
+ * Open the session, or renew it until `expiresAt`; its computer, folder and background commands
1287
+ * are kept as given, and its stop requests as they are.
1288
+ */
1289
+ hold(input: Omit<AgentComputerSessionRecord, "stopRequests">): Promise<void>
1290
+ /**
1291
+ * Record that someone asked to stop one of its commands, once, keeping the newest
1292
+ * {@link AGENT_COMPUTER_BACKGROUND_COMMANDS_MAX}. Null when the owner holds no such session.
1293
+ */
1294
+ requestStop(input: {
1295
+ readonly projectId: string
1296
+ readonly id: string
1297
+ readonly ownerPrincipal: Principal
1298
+ readonly command: AgentBackgroundCommandRef
1299
+ }): Promise<AgentComputerSessionRecord | null>
1257
1300
  /** End the owner's session; null when it is not open. */
1258
1301
  release(input: {
1259
1302
  readonly projectId: string
@@ -886,7 +886,7 @@ export class InMemoryConnectorConnectionStorage implements ConnectorConnectionSt
886
886
  }
887
887
  const existing = this.findConnectionRecord(input)
888
888
  const sameAccount = existing?.account.id === account.id
889
- if (existing && !sameAccount && !input.replace) {
889
+ if (existing?.status === "connected" && !sameAccount && !input.replace) {
890
890
  throw new ConnectorConnectionStorageError(
891
891
  "connection_conflict",
892
892
  `[Sixb] Connector slot '${input.slot}' is already connected to another account; explicit replacement is required.`
@@ -965,7 +965,7 @@ export class InMemoryConnectorConnectionStorage implements ConnectorConnectionSt
965
965
  ? {}
966
966
  : { revocationPendingAuthorizationId }),
967
967
  created: existing === undefined,
968
- replaced: existing !== undefined && !sameAccount,
968
+ replaced: existing?.status === "connected" && !sameAccount,
969
969
  }
970
970
  }
971
971
 
@@ -182,7 +182,7 @@ export class DurableConnectorConnections extends ConnectorConnectionOperations {
182
182
  }
183
183
  const existing = await persistence.getConnectionBySelector(input)
184
184
  const sameAccount = existing?.account.id === account.id
185
- if (existing && !sameAccount && !input.replace) {
185
+ if (existing?.status === "connected" && !sameAccount && !input.replace) {
186
186
  throw new ConnectorConnectionStorageError(
187
187
  "connection_conflict",
188
188
  `[Sixb] Connector slot '${input.slot}' is already connected to another account; explicit replacement is required.`
@@ -267,7 +267,7 @@ export class DurableConnectorConnections extends ConnectorConnectionOperations {
267
267
  ? {}
268
268
  : { revocationPendingAuthorizationId }),
269
269
  created: existing === null,
270
- replaced: existing !== null && !sameAccount,
270
+ replaced: existing?.status === "connected" && !sameAccount,
271
271
  }
272
272
  }
273
273
  }
@@ -89,6 +89,8 @@ export type {
89
89
  AgentApprovalSettledStatus,
90
90
  AgentApprovalStatus,
91
91
  AgentApprovalStore,
92
+ AgentBackgroundCommandRef,
93
+ AgentComputerBackgroundCommand,
92
94
  AgentComputerSessionRecord,
93
95
  AgentComputerSessionStore,
94
96
  AgentContextCheckpointReason,
@@ -566,10 +568,12 @@ export type {
566
568
  ObjectReadRoot,
567
569
  ObjectReadScopeFactory,
568
570
  ObjectReadStorage,
571
+ ObjectReadVisibility,
569
572
  ObjectRow,
570
573
  ObjectRowLinks,
571
574
  ObjectRowUsers,
572
575
  ObjectStorage,
576
+ ObjectVisibilityKeys,
573
577
  QueryObjectLinksInput,
574
578
  QueryObjectLinksResult,
575
579
  QueryObjectsInput,
@@ -1,4 +1,5 @@
1
1
  import type { OntologyDefinitionCatalog } from "../../ontology/registry"
2
+ import type { SecurityDefinitionCatalog } from "../../security/registry"
2
3
  import type { ObjectQueryPreparationResult } from "../objects/query-preparation"
3
4
  import type { Storage } from "../types"
4
5
 
@@ -128,6 +129,11 @@ export interface MigrationCapableStorage extends Storage {
128
129
  export interface StorageMigrationOptions {
129
130
  readonly projectId: string
130
131
  readonly ontology: OntologyDefinitionCatalog
132
+ /**
133
+ * The roles' view conditions, whose keys member reads filter on. Without them, what was prepared
134
+ * for them is left as it is.
135
+ */
136
+ readonly security?: Pick<SecurityDefinitionCatalog, "listViewConditions">
131
137
  }
132
138
 
133
139
  export interface StorageMigrationResult {
@@ -2,6 +2,7 @@ import type { ObjectQuery, ObjectQuerySortField } from "../../../objects/query"
2
2
  import { linkEndpointObjectTypeIds } from "../../../objects/query/link-endpoints"
3
3
  import { matchesPredicate } from "../../../objects/query/matches-predicate"
4
4
  import { compareQueryScalarValues } from "../../../objects/query/scalar-values"
5
+ import { sortTieDirection } from "../../../objects/query/sort-ties"
5
6
  import { vectorSources } from "../../../objects/vectors/profile"
6
7
  import type { LinkBatchKey } from "../keys"
7
8
  import {
@@ -443,14 +444,16 @@ function sortEntries(
443
444
  entries: readonly QueryEntry[],
444
445
  fields: readonly ObjectQuerySortField[]
445
446
  ): QueryEntry[] {
447
+ const ties = sortTieDirection(fields)
446
448
  return [...entries].sort((left, right) => {
447
449
  for (const field of fields) {
448
450
  const comparison = compareSortField(left, right, field)
449
451
  if (comparison !== 0) return comparison
450
452
  }
451
- return (
453
+
454
+ const tie =
452
455
  left.order - right.order || rowIdentityKey(left.row).localeCompare(rowIdentityKey(right.row))
453
- )
456
+ return ties === "desc" ? -tie : tie
454
457
  })
455
458
  }
456
459
 
@@ -50,10 +50,12 @@ export type {
50
50
  ObjectReadRoot,
51
51
  ObjectReadScopeFactory,
52
52
  ObjectReadStorage,
53
+ ObjectReadVisibility,
53
54
  ObjectRow,
54
55
  ObjectRowLinks,
55
56
  ObjectRowUsers,
56
57
  ObjectStorage,
58
+ ObjectVisibilityKeys,
57
59
  QueryObjectLinksInput,
58
60
  QueryObjectLinksResult,
59
61
  QueryObjectsInput,
@@ -1,3 +1,4 @@
1
+ import { compareStrings } from "../../json"
1
2
  import type { QueryScalarKind } from "../../objects/query/ir"
2
3
  import { linkTargetObjectTypeIds } from "../../objects/query/link-endpoints"
3
4
  import {
@@ -7,7 +8,10 @@ import {
7
8
  } from "../../ontology/query-capabilities"
8
9
  import type { OntologyDefinitionCatalog } from "../../ontology/registry"
9
10
  import type { ObjectQueryIndexDefinition } from "../../ontology/types"
11
+ import type { SecurityDefinitionCatalog } from "../../security/registry"
12
+ import { viewConditionKeys } from "../../security/visibility-keys"
10
13
  import type { Storage } from "../types"
14
+ import type { ObjectVisibilityKeys } from "./types"
11
15
 
12
16
  export interface ObjectQueryPreparationPlan {
13
17
  readonly projectId: string
@@ -26,6 +30,12 @@ export interface ObjectQueryPreparationPlan {
26
30
  readonly linkId: string
27
31
  readonly targetObjectTypeIds: readonly string[] | undefined
28
32
  }[]
33
+ /**
34
+ * The keys of every view condition a role puts on the type or a supertype, each once: a
35
+ * member's reads of the type filter on them. Absent when preparation was not given the view
36
+ * conditions, and a provider then leaves what it prepared for them as it is.
37
+ */
38
+ readonly visibility?: readonly ObjectVisibilityKeys[]
29
39
  }[]
30
40
  }
31
41
 
@@ -54,6 +64,11 @@ export function isQueryPreparationCapableStorage(
54
64
  export async function prepareObjectQueries(input: {
55
65
  projectId: string
56
66
  ontology: OntologyDefinitionCatalog
67
+ /**
68
+ * The roles' view conditions, whose keys member reads filter on. Without them, what was prepared
69
+ * for them is left as it is.
70
+ */
71
+ security?: Pick<SecurityDefinitionCatalog, "listViewConditions">
57
72
  storage: Storage
58
73
  }): Promise<ObjectQueryPreparationResult> {
59
74
  if (!isQueryPreparationCapableStorage(input.storage)) {
@@ -61,6 +76,7 @@ export async function prepareObjectQueries(input: {
61
76
  }
62
77
 
63
78
  const values = input.ontology.getValueTypesById()
79
+ const visibility = viewConditionKeysByType(input.security, input.ontology)
64
80
  const objectTypes = input.ontology.listObjectTypes().map((type) => ({
65
81
  objectTypeId: type.id,
66
82
  properties: type.properties
@@ -82,6 +98,48 @@ export async function prepareObjectQueries(input: {
82
98
  linkId: link.id,
83
99
  targetObjectTypeIds: linkTargetObjectTypeIds(link.targetObjectTypeId, input.ontology),
84
100
  })),
101
+ ...(visibility ? { visibility: visibility.get(type.id) ?? [] } : {}),
85
102
  }))
86
- return input.storage.prepareObjectQueries({ projectId: input.projectId, objectTypes })
103
+ const result = await input.storage.prepareObjectQueries({
104
+ projectId: input.projectId,
105
+ objectTypes,
106
+ })
107
+
108
+ const unindexed = (input.security?.listViewConditions() ?? [])
109
+ .filter((condition) => !viewConditionKeys(condition.predicate))
110
+ .map(
111
+ (condition) =>
112
+ `Role '${condition.roleId}': can.view(${condition.objectTypeId}).where(...) negates currentUser() or needs it twice at once, so members' reads check every object.`
113
+ )
114
+ return unindexed.length > 0 ? { ...result, warnings: [...result.warnings, ...unindexed] } : result
115
+ }
116
+
117
+ /** Each concrete type's distinct condition keys, in a stable order. */
118
+ function viewConditionKeysByType(
119
+ security: Pick<SecurityDefinitionCatalog, "listViewConditions"> | undefined,
120
+ ontology: OntologyDefinitionCatalog
121
+ ): ReadonlyMap<string, readonly ObjectVisibilityKeys[]> | undefined {
122
+ if (!security) return undefined
123
+
124
+ const keysByType = new Map<string, Map<string, ObjectVisibilityKeys>>()
125
+ for (const condition of security.listViewConditions()) {
126
+ const keys = viewConditionKeys(condition.predicate)
127
+ if (!keys) continue
128
+
129
+ for (const objectTypeId of [
130
+ condition.objectTypeId,
131
+ ...ontology.listSubTypes(condition.objectTypeId),
132
+ ]) {
133
+ const typeKeys = keysByType.get(objectTypeId) ?? new Map<string, ObjectVisibilityKeys>()
134
+ typeKeys.set(JSON.stringify(keys), keys)
135
+ keysByType.set(objectTypeId, typeKeys)
136
+ }
137
+ }
138
+
139
+ return new Map(
140
+ [...keysByType].map(([objectTypeId, keys]) => [
141
+ objectTypeId,
142
+ [...keys].sort(([left], [right]) => compareStrings(left, right)).map(([, value]) => value),
143
+ ])
144
+ )
87
145
  }