@sixb/core 0.2.6 → 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 (146) hide show
  1. package/dist/actions/index.js +13 -13
  2. package/dist/agents/index.d.ts +1 -1
  3. package/dist/agents/index.d.ts.map +1 -1
  4. package/dist/agents/index.js +20 -18
  5. package/dist/agents/index.js.map +1 -1
  6. package/dist/agents/model-routing.d.ts +15 -4
  7. package/dist/agents/model-routing.d.ts.map +1 -1
  8. package/dist/agents/request.d.ts.map +1 -1
  9. package/dist/agents/run-token.d.ts +6 -0
  10. package/dist/agents/run-token.d.ts.map +1 -1
  11. package/dist/agents/streams/index.js +1 -1
  12. package/dist/agents/streams/internal.js +2 -2
  13. package/dist/artifacts/live/server.js +6 -6
  14. package/dist/artifacts/publish/index.js +5 -5
  15. package/dist/bootstrap/discovery.d.ts +6 -0
  16. package/dist/bootstrap/discovery.d.ts.map +1 -1
  17. package/dist/bootstrap/index.js +19 -19
  18. package/dist/{chunk-90nqenq8.js → chunk-04r2fdsd.js} +1 -1
  19. package/dist/{chunk-9c9yknwt.js → chunk-06kpaqg4.js} +2 -2
  20. package/dist/{chunk-nxysqbt0.js → chunk-389ybvw9.js} +6 -2
  21. package/dist/chunk-389ybvw9.js.map +10 -0
  22. package/dist/{chunk-xf76csps.js → chunk-44hrfmbk.js} +2 -2
  23. package/dist/{chunk-gaj8djsw.js → chunk-5pz3htbe.js} +7 -2
  24. package/dist/{chunk-gaj8djsw.js.map → chunk-5pz3htbe.js.map} +3 -3
  25. package/dist/{chunk-kft7mp7z.js → chunk-5xkqasvn.js} +1 -1
  26. package/dist/{chunk-fmgf9h5e.js → chunk-6md802cc.js} +1 -1
  27. package/dist/{chunk-ats8y3d9.js → chunk-8qmp9fpa.js} +81 -34
  28. package/dist/{chunk-ats8y3d9.js.map → chunk-8qmp9fpa.js.map} +4 -4
  29. package/dist/{chunk-eg6xqef7.js → chunk-95ps0k5q.js} +3 -3
  30. package/dist/{chunk-eg6xqef7.js.map → chunk-95ps0k5q.js.map} +3 -3
  31. package/dist/{chunk-7r9mqpva.js → chunk-9cyq87qa.js} +12 -11
  32. package/dist/{chunk-7r9mqpva.js.map → chunk-9cyq87qa.js.map} +3 -3
  33. package/dist/{chunk-ykchk644.js → chunk-cpy282b8.js} +1 -1
  34. package/dist/{chunk-bcz9dxtf.js → chunk-fdk0ks9p.js} +1 -1
  35. package/dist/{chunk-t19wjmnc.js → chunk-fycac8e9.js} +47 -13
  36. package/dist/{chunk-t19wjmnc.js.map → chunk-fycac8e9.js.map} +3 -3
  37. package/dist/{chunk-jt012fxq.js → chunk-hvq8xs66.js} +2 -2
  38. package/dist/{chunk-bs1sd0e0.js → chunk-js9e6487.js} +1 -1
  39. package/dist/{chunk-f05994as.js → chunk-k29rdc3h.js} +1 -1
  40. package/dist/{chunk-s8xxef60.js → chunk-m1cwncee.js} +14 -12
  41. package/dist/{chunk-s8xxef60.js.map → chunk-m1cwncee.js.map} +6 -6
  42. package/dist/{chunk-grt2j5vp.js → chunk-mrs7jy17.js} +1 -1
  43. package/dist/{chunk-pqj8vff9.js → chunk-pfdq1ga6.js} +1 -1
  44. package/dist/{chunk-ym1bqd98.js → chunk-phs5fbff.js} +3 -3
  45. package/dist/{chunk-6hfbz4d0.js → chunk-r588h4ev.js} +1 -1
  46. package/dist/{chunk-htdzx40w.js → chunk-t58sktr5.js} +10 -2
  47. package/dist/{chunk-htdzx40w.js.map → chunk-t58sktr5.js.map} +3 -3
  48. package/dist/{chunk-425ydk65.js → chunk-yyj009tv.js} +3 -3
  49. package/dist/deploy/index.d.ts +1 -1
  50. package/dist/deploy/index.d.ts.map +1 -1
  51. package/dist/deploy/internal.js +2 -2
  52. package/dist/deploy/internal.js.map +2 -2
  53. package/dist/deploy/types.d.ts +8 -58
  54. package/dist/deploy/types.d.ts.map +1 -1
  55. package/dist/env/index.d.ts +10 -3
  56. package/dist/env/index.d.ts.map +1 -1
  57. package/dist/env/index.js.map +2 -2
  58. package/dist/execution/agent.js +13 -13
  59. package/dist/execution/primitive.js +13 -13
  60. package/dist/execution/request.js +13 -13
  61. package/dist/index.d.ts +2 -2
  62. package/dist/index.d.ts.map +1 -1
  63. package/dist/index.js +25 -23
  64. package/dist/index.js.map +1 -1
  65. package/dist/materializer/index.js +3 -3
  66. package/dist/models/execution/index.js +3 -3
  67. package/dist/objects/index.js +13 -13
  68. package/dist/objects/query/index.js +3 -3
  69. package/dist/pipelines/index.js +3 -3
  70. package/dist/projections/internal.js +2 -2
  71. package/dist/runtime/create.d.ts.map +1 -1
  72. package/dist/runtime/definitions.d.ts +14 -0
  73. package/dist/runtime/definitions.d.ts.map +1 -1
  74. package/dist/runtime/host.d.ts +3 -1
  75. package/dist/runtime/host.d.ts.map +1 -1
  76. package/dist/runtime/index.d.ts +1 -1
  77. package/dist/runtime/index.d.ts.map +1 -1
  78. package/dist/runtime/internal.js +7 -7
  79. package/dist/runtime/resolve-definitions.d.ts +2 -1
  80. package/dist/runtime/resolve-definitions.d.ts.map +1 -1
  81. package/dist/sandboxes/errors.d.ts +19 -0
  82. package/dist/sandboxes/errors.d.ts.map +1 -1
  83. package/dist/sandboxes/exec.d.ts +2 -0
  84. package/dist/sandboxes/exec.d.ts.map +1 -1
  85. package/dist/sandboxes/index.d.ts +1 -1
  86. package/dist/sandboxes/index.d.ts.map +1 -1
  87. package/dist/sandboxes/index.js +10 -4
  88. package/dist/sandboxes/index.js.map +1 -1
  89. package/dist/sandboxes/sandbox.d.ts +15 -1
  90. package/dist/sandboxes/sandbox.d.ts.map +1 -1
  91. package/dist/shares/internal.js +2 -2
  92. package/dist/storage/agents/provider.d.ts.map +1 -1
  93. package/dist/storage/agents/provider.js +2 -2
  94. package/dist/storage/agents/types.d.ts +14 -1
  95. package/dist/storage/agents/types.d.ts.map +1 -1
  96. package/dist/storage/index.js +3 -3
  97. package/dist/syncs/index.js +4 -4
  98. package/dist/testing/agent-storage-contract.d.ts.map +1 -1
  99. package/dist/testing/artifact-storage-contract.d.ts.map +1 -1
  100. package/dist/testing/index.js +88 -24
  101. package/dist/testing/index.js.map +5 -5
  102. package/dist/testing/sandboxes-contract.d.ts.map +1 -1
  103. package/dist/webhooks/internal.js +2 -2
  104. package/dist/workflows/index.js +17 -17
  105. package/package.json +1 -1
  106. package/src/agents/index.ts +1 -0
  107. package/src/agents/model-routing.ts +104 -38
  108. package/src/agents/request.ts +27 -1
  109. package/src/agents/run-token.ts +7 -0
  110. package/src/bootstrap/discovery.ts +61 -11
  111. package/src/deploy/index.ts +0 -5
  112. package/src/deploy/types.ts +8 -63
  113. package/src/deploy/validation.ts +1 -1
  114. package/src/env/index.ts +10 -4
  115. package/src/index.ts +3 -0
  116. package/src/runtime/create.ts +1 -0
  117. package/src/runtime/definitions.ts +25 -0
  118. package/src/runtime/host.ts +3 -1
  119. package/src/runtime/index.ts +6 -1
  120. package/src/runtime/resolve-definitions.ts +7 -1
  121. package/src/sandboxes/README.md +9 -0
  122. package/src/sandboxes/errors.ts +27 -0
  123. package/src/sandboxes/exec.ts +3 -1
  124. package/src/sandboxes/index.ts +3 -0
  125. package/src/sandboxes/sandbox.ts +15 -1
  126. package/src/storage/agents/provider.ts +8 -0
  127. package/src/storage/agents/types.ts +18 -1
  128. package/src/testing/agent-storage-contract.ts +27 -0
  129. package/src/testing/artifact-storage-contract.ts +10 -0
  130. package/src/testing/sandboxes-contract.ts +50 -0
  131. package/dist/chunk-nxysqbt0.js.map +0 -10
  132. /package/dist/{chunk-90nqenq8.js.map → chunk-04r2fdsd.js.map} +0 -0
  133. /package/dist/{chunk-9c9yknwt.js.map → chunk-06kpaqg4.js.map} +0 -0
  134. /package/dist/{chunk-xf76csps.js.map → chunk-44hrfmbk.js.map} +0 -0
  135. /package/dist/{chunk-kft7mp7z.js.map → chunk-5xkqasvn.js.map} +0 -0
  136. /package/dist/{chunk-fmgf9h5e.js.map → chunk-6md802cc.js.map} +0 -0
  137. /package/dist/{chunk-ykchk644.js.map → chunk-cpy282b8.js.map} +0 -0
  138. /package/dist/{chunk-bcz9dxtf.js.map → chunk-fdk0ks9p.js.map} +0 -0
  139. /package/dist/{chunk-jt012fxq.js.map → chunk-hvq8xs66.js.map} +0 -0
  140. /package/dist/{chunk-bs1sd0e0.js.map → chunk-js9e6487.js.map} +0 -0
  141. /package/dist/{chunk-f05994as.js.map → chunk-k29rdc3h.js.map} +0 -0
  142. /package/dist/{chunk-grt2j5vp.js.map → chunk-mrs7jy17.js.map} +0 -0
  143. /package/dist/{chunk-pqj8vff9.js.map → chunk-pfdq1ga6.js.map} +0 -0
  144. /package/dist/{chunk-ym1bqd98.js.map → chunk-phs5fbff.js.map} +0 -0
  145. /package/dist/{chunk-6hfbz4d0.js.map → chunk-r588h4ev.js.map} +0 -0
  146. /package/dist/{chunk-425ydk65.js.map → chunk-yyj009tv.js.map} +0 -0
@@ -1 +1 @@
1
- {"version":3,"file":"sandboxes-contract.d.ts","sourceRoot":"","sources":["../../src/testing/sandboxes-contract.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,cAAc,EAA0B,MAAM,cAAc,CAAA;AAE1E;;;GAGG;AACH,MAAM,WAAW,6BAA6B;IAC5C,mEAAmE;IACnE,QAAQ,CAAC,eAAe,CAAC,EAAE,OAAO,CAAA;IAClC,wEAAwE;IACxE,QAAQ,CAAC,mBAAmB,CAAC,EAAE,OAAO,CAAA;IACtC,kEAAkE;IAClE,QAAQ,CAAC,SAAS,CAAC,EAAE,OAAO,CAAA;CAC7B;AAED,MAAM,WAAW,6BAA6B;IAC5C,0DAA0D;IAC1D,QAAQ,CAAC,aAAa,EAAE,MAAM,cAAc,GAAG,OAAO,CAAC,cAAc,CAAC,CAAA;IACtE,4FAA4F;IAC5F,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC,OAAO,EAAE,cAAc,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IACrE,QAAQ,CAAC,YAAY,CAAC,EAAE,6BAA6B,CAAA;IACrD;;;OAGG;IACH,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,CAAA;CACjC;AAID;;;GAGG;AACH,wBAAgB,yBAAyB,CACvC,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,6BAA6B,GACrC,IAAI,CAiZN"}
1
+ {"version":3,"file":"sandboxes-contract.d.ts","sourceRoot":"","sources":["../../src/testing/sandboxes-contract.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,cAAc,EAA0B,MAAM,cAAc,CAAA;AAE1E;;;GAGG;AACH,MAAM,WAAW,6BAA6B;IAC5C,mEAAmE;IACnE,QAAQ,CAAC,eAAe,CAAC,EAAE,OAAO,CAAA;IAClC,wEAAwE;IACxE,QAAQ,CAAC,mBAAmB,CAAC,EAAE,OAAO,CAAA;IACtC,kEAAkE;IAClE,QAAQ,CAAC,SAAS,CAAC,EAAE,OAAO,CAAA;CAC7B;AAED,MAAM,WAAW,6BAA6B;IAC5C,0DAA0D;IAC1D,QAAQ,CAAC,aAAa,EAAE,MAAM,cAAc,GAAG,OAAO,CAAC,cAAc,CAAC,CAAA;IACtE,4FAA4F;IAC5F,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC,OAAO,EAAE,cAAc,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IACrE,QAAQ,CAAC,YAAY,CAAC,EAAE,6BAA6B,CAAA;IACrD;;;OAGG;IACH,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,CAAA;CACjC;AAID;;;GAGG;AACH,wBAAgB,yBAAyB,CACvC,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,6BAA6B,GACrC,IAAI,CAmcN"}
@@ -25,7 +25,7 @@ import"../chunk-zrvhsq7f.js";
25
25
  import"../chunk-5grk14e5.js";
26
26
  import"../chunk-az95tsh3.js";
27
27
  import"../chunk-qttqe1ah.js";
28
- import"../chunk-gaj8djsw.js";
28
+ import"../chunk-5pz3htbe.js";
29
29
  import"../chunk-dq3t5sr3.js";
30
30
  import"../chunk-3qtk0070.js";
31
31
  import"../chunk-c4nrycdy.js";
@@ -45,7 +45,7 @@ import"../chunk-cswhawa2.js";
45
45
  import {
46
46
  WEBHOOK_RUN_LEASE_MS2,
47
47
  canRetryWebhookRun2
48
- } from "../chunk-9c9yknwt.js";
48
+ } from "../chunk-06kpaqg4.js";
49
49
  import"../chunk-61zptves.js";
50
50
  import"../chunk-hkbks1xm.js";
51
51
  import"../chunk-3sgvd10b.js";
@@ -8,15 +8,15 @@ import {
8
8
  defineWorkflow2,
9
9
  createWorkflowNodeFailure2,
10
10
  unwrapWorkflowNodeFailure2
11
- } from "../chunk-425ydk65.js";
11
+ } from "../chunk-yyj009tv.js";
12
12
  import"../chunk-dvgc56n2.js";
13
13
  import"../chunk-fzbhybya.js";
14
14
  import"../chunk-z4jqb44a.js";
15
- import"../chunk-7r9mqpva.js";
15
+ import"../chunk-9cyq87qa.js";
16
16
  import"../chunk-de5sfbc3.js";
17
17
  import"../chunk-jka26v8c.js";
18
18
  import"../chunk-wzcjhv54.js";
19
- import"../chunk-f05994as.js";
19
+ import"../chunk-k29rdc3h.js";
20
20
  import {
21
21
  WorkflowDefinitionError2,
22
22
  WorkflowValidationError2,
@@ -46,18 +46,18 @@ import {
46
46
  snapshotWorkflowActionInput2,
47
47
  WorkflowRunDispatcher2,
48
48
  requestWorkflowRun2
49
- } from "../chunk-ats8y3d9.js";
50
- import"../chunk-90nqenq8.js";
49
+ } from "../chunk-8qmp9fpa.js";
50
+ import"../chunk-04r2fdsd.js";
51
51
  import"../chunk-n1hbwc6y.js";
52
52
  import"../chunk-qbd282aa.js";
53
- import"../chunk-pqj8vff9.js";
53
+ import"../chunk-pfdq1ga6.js";
54
54
  import"../chunk-y8fwm3z2.js";
55
- import"../chunk-ym1bqd98.js";
56
- import"../chunk-htdzx40w.js";
57
- import"../chunk-ykchk644.js";
55
+ import"../chunk-phs5fbff.js";
56
+ import"../chunk-t58sktr5.js";
57
+ import"../chunk-cpy282b8.js";
58
58
  import"../chunk-xavet0qs.js";
59
59
  import"../chunk-3723kgba.js";
60
- import"../chunk-grt2j5vp.js";
60
+ import"../chunk-mrs7jy17.js";
61
61
  import"../chunk-5qqmndhm.js";
62
62
  import"../chunk-9tpmfh3n.js";
63
63
  import"../chunk-1vg43g9q.js";
@@ -70,10 +70,10 @@ import"../chunk-0pmpwn3g.js";
70
70
  import"../chunk-ppxf7gw2.js";
71
71
  import"../chunk-w3t94hm6.js";
72
72
  import"../chunk-wx7smkn2.js";
73
- import"../chunk-jt012fxq.js";
74
- import"../chunk-fmgf9h5e.js";
75
- import"../chunk-bs1sd0e0.js";
76
- import"../chunk-9c9yknwt.js";
73
+ import"../chunk-hvq8xs66.js";
74
+ import"../chunk-6md802cc.js";
75
+ import"../chunk-js9e6487.js";
76
+ import"../chunk-06kpaqg4.js";
77
77
  import"../chunk-5sswe5ej.js";
78
78
  import"../chunk-61zptves.js";
79
79
  import"../chunk-22d3qg4x.js";
@@ -92,7 +92,7 @@ import"../chunk-h89wz928.js";
92
92
  import"../chunk-x0v3jd47.js";
93
93
  import"../chunk-g2ph4873.js";
94
94
  import"../chunk-mbsbxarb.js";
95
- import"../chunk-gaj8djsw.js";
95
+ import"../chunk-5pz3htbe.js";
96
96
  import"../chunk-3qtk0070.js";
97
97
  import"../chunk-xtztwpkh.js";
98
98
  import"../chunk-cswhawa2.js";
@@ -115,8 +115,8 @@ import"../chunk-d7v97qxq.js";
115
115
  import"../chunk-xrmbhap8.js";
116
116
  import"../chunk-gfdh9kqa.js";
117
117
  import"../chunk-sgx82nnt.js";
118
- import"../chunk-6hfbz4d0.js";
119
- import"../chunk-kft7mp7z.js";
118
+ import"../chunk-r588h4ev.js";
119
+ import"../chunk-5xkqasvn.js";
120
120
  import"../chunk-mvz89age.js";
121
121
  import"../chunk-6eqsgvxk.js";
122
122
  import"../chunk-vs2s3p8n.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sixb/core",
3
- "version": "0.2.6",
3
+ "version": "0.2.7",
4
4
  "description": "The ontology-first runtime for Sixb — objects, links, telemetry, actions, and provider contracts",
5
5
  "keywords": [
6
6
  "sixb",
@@ -307,6 +307,7 @@ export { decodeWireValue, encodeWireError, encodeWireValue } from "./run-session
307
307
  export type { AgentApiRoute, AgentRunTokenInput } from "./run-token"
308
308
  export {
309
309
  AGENT_API_ROUTES,
310
+ AGENT_RUN_HEADER,
310
311
  agentRunTokenRunId,
311
312
  createAgentRunnerToken,
312
313
  createAgentRunToken,
@@ -28,25 +28,53 @@ const DECISION_TIMEOUT_MS = 2_000
28
28
  /** How long a provider keeps a thread's prompt cache after the last call that read it. */
29
29
  const PROMPT_CACHE_TTL_MS = 5 * 60_000
30
30
 
31
- const TIER_QUESTIONS = {
32
- tier: question.choice({
33
- instructions:
34
- "A user sent this message to a data agent. The agent answers from the project's data with " +
35
- "tools: it searches and reads objects, queries and aggregates datasets, follows links, runs " +
36
- "actions and writes reports. Pick the model tier the answer needs. Judge the work the " +
37
- "answer takes, not the length or tone of the message.",
38
- options: {
39
- light:
40
- "A lookup, a count, a filter or a list: one or two queries with an obvious answer. " +
41
- "Greetings, thanks and short follow-ups.",
42
- standard:
43
- "Usual analysis: several queries, comparisons, trends or aggregations, a short summary, " +
44
- "or a simple action, with a clear path to the answer.",
45
- heavy:
46
- "Open-ended work: a multi-step investigation, explaining why something happened, " +
47
- "weighing trade-offs, building a plan, or writing a long report.",
48
- },
49
- }),
31
+ /** How much of the previous message the decision model reads: enough to tell what work it set. */
32
+ const PREVIOUS_MESSAGE_CHARS = 2_000
33
+
34
+ /** What each tier is for, whatever the project: its models' descriptions say how it uses them. */
35
+ const TIER_WORK: Readonly<Record<LanguageModelTier, string>> = {
36
+ light:
37
+ "A lookup, a count, a filter or a list with an obvious answer. Greetings, thanks, and short " +
38
+ "questions that start no new work.",
39
+ standard:
40
+ "Usual work with a clear path: several queries or reads, a comparison, a short summary, a " +
41
+ "simple action, or a small change to a few files.",
42
+ heavy:
43
+ "Open-ended or long work: a multi-step investigation, explaining why something happened, " +
44
+ "weighing trade-offs, building a plan, writing a long report, or changes across many files " +
45
+ "that must be checked.",
46
+ }
47
+
48
+ /**
49
+ * The tier question for a project: the work each tier is for, and the description of the model a
50
+ * routed turn runs on in that tier, which the project can write to steer the choice.
51
+ */
52
+ function tierQuestions(language: LanguageModelCatalog) {
53
+ return {
54
+ tier: question.choice({
55
+ instructions:
56
+ "A user sent this message to an agent that works in a project with tools: it reads and " +
57
+ "changes the project's data, runs actions, writes documents, and in a workspace runs " +
58
+ "commands and edits files. Pick the model tier the answer needs. Judge the work the " +
59
+ "answer takes, not the length or tone of the message. When the input holds the " +
60
+ "previous message, with the tier it ran on, judge the <message> in its light: a short " +
61
+ "message that carries on that work, such as approving a plan or asking for the next " +
62
+ "step, takes the tier the work needs.",
63
+ options: {
64
+ light: tierOption(language, "light"),
65
+ standard: tierOption(language, "standard"),
66
+ heavy: tierOption(language, "heavy"),
67
+ },
68
+ }),
69
+ }
70
+ }
71
+
72
+ function tierOption(language: LanguageModelCatalog, tier: LanguageModelTier): string {
73
+ const description = language.tiers.includes(tier)
74
+ ? language.getByTier(tier).model.definition.description?.trim()
75
+ : undefined
76
+
77
+ return description ? `${TIER_WORK[tier]} This tier's model: ${description}` : TIER_WORK[tier]
50
78
  }
51
79
 
52
80
  export interface TurnModelChoice {
@@ -58,15 +86,23 @@ export interface TurnModelChoice {
58
86
  readonly tierProbabilities?: LanguageModelTierProbabilities
59
87
  }
60
88
 
89
+ /** A turn whose model Sixb picks. */
90
+ export interface TurnToRoute {
91
+ /** The words of its message. */
92
+ readonly text: string
93
+ /** The thread's previous turn, absent for its first. */
94
+ readonly previous?: {
95
+ readonly run: ConversationAgentRunRecord
96
+ /** The words of the message that started it, which a short follow-up carries on. */
97
+ readonly text?: string
98
+ }
99
+ /** Where the turn runs: the previous turn's cache holds its prompt only if it ran there. */
100
+ readonly place: AgentTurnPlace
101
+ }
102
+
61
103
  export interface TurnModelRouter {
62
- /**
63
- * The model of a turn that names none, given the thread's previous turn and where this one runs.
64
- */
65
- choose(
66
- text: string,
67
- previous: ConversationAgentRunRecord | undefined,
68
- place: AgentTurnPlace
69
- ): Promise<TurnModelChoice>
104
+ /** The model of a turn that names none. */
105
+ choose(turn: TurnToRoute): Promise<TurnModelChoice>
70
106
  }
71
107
 
72
108
  /**
@@ -74,10 +110,12 @@ export interface TurnModelRouter {
74
110
  * Checked at startup: a model that cannot would leave every turn on `standard`, warning each time.
75
111
  */
76
112
  export function assertTurnModelRouting(models: ModelCatalog | undefined): void {
77
- const tiers = models?.language?.tiers ?? []
113
+ const language = models?.language
78
114
  const decision = models?.decision?.default
79
- if (tiers.length === 0 || !decision) return
80
- if (supportsQuestion(decision.model.definition.capabilities, TIER_QUESTIONS.tier)) return
115
+ if (!language || language.tiers.length === 0 || !decision) return
116
+
117
+ const { tier } = tierQuestions(language)
118
+ if (supportsQuestion(decision.model.definition.capabilities, tier)) return
81
119
 
82
120
  throw new RuntimeError(
83
121
  `[Sixb] The default decision model '${decision.provider}/${decision.modelId}' cannot pick the tier of an Agent turn: it needs 'choice' questions with ${LANGUAGE_MODEL_TIERS.length} options. Put a decision model that supports them first in 'models.decision', or configure 'models.language' as a list.`
@@ -92,25 +130,55 @@ export function createTurnModelRouter(
92
130
  const language = models?.language
93
131
  if (!language || language.tiers.length === 0 || !models?.decision) return undefined
94
132
 
133
+ const questions = tierQuestions(language)
134
+
95
135
  return {
96
- async choose(text, previous, place) {
136
+ async choose(turn) {
137
+ const last = turn.previous && previousTurn(language, turn.previous.run, turn.place)
138
+
97
139
  // Files sent alone leave nothing to judge: the turn aims for standard, and the cache rule
98
140
  // keeps a warm thread on its model.
99
- const tierProbabilities = text.trim() ? await askTier(decision, text) : undefined
141
+ const tierProbabilities = turn.text.trim()
142
+ ? await askTier(decision, questions, decisionInput(turn, last))
143
+ : undefined
100
144
  const tier = tierProbabilities ? tierFor(tierProbabilities) : "standard"
101
145
 
102
146
  return {
103
- model: turnModel(language, tier, previous, place),
147
+ model: turnModel(language, tier, last),
104
148
  ...(tierProbabilities ? { tierProbabilities } : {}),
105
149
  }
106
150
  },
107
151
  }
108
152
  }
109
153
 
154
+ /**
155
+ * The message, after the one before it and the tier that one ran on: "Go ahead" after a plan for
156
+ * a large change asks for that change, and judged alone it reads like thanks.
157
+ */
158
+ function decisionInput(turn: TurnToRoute, last: PreviousTurn | undefined): string {
159
+ const before = turn.previous?.text?.trim()
160
+ if (!before) return turn.text
161
+
162
+ const clipped =
163
+ before.length > PREVIOUS_MESSAGE_CHARS ? `${before.slice(0, PREVIOUS_MESSAGE_CHARS)}…` : before
164
+ const tier = last ? ` tier="${last.tier}"` : ""
165
+
166
+ return [
167
+ `<previous_message${tier}>`,
168
+ clipped,
169
+ "</previous_message>",
170
+ "",
171
+ "<message>",
172
+ turn.text,
173
+ "</message>",
174
+ ].join("\n")
175
+ }
176
+
110
177
  /** The decision model's answer, or nothing when it fails or is too slow. */
111
178
  async function askTier(
112
179
  decision: DecisionModelsRuntime,
113
- text: string
180
+ questions: ReturnType<typeof tierQuestions>,
181
+ input: string
114
182
  ): Promise<LanguageModelTierProbabilities | undefined> {
115
183
  const timeout = new AbortController()
116
184
  const timer = setTimeout(() => {
@@ -122,7 +190,7 @@ async function askTier(
122
190
  try {
123
191
  // The race holds the turn to its timeout even when a provider ignores the signal.
124
192
  const { output } = await Promise.race([
125
- decision.evaluate({ input: text, questions: TIER_QUESTIONS, signal: timeout.signal }),
193
+ decision.evaluate({ input, questions, signal: timeout.signal }),
126
194
  rejectOnAbort(timeout.signal),
127
195
  ])
128
196
  const { light, standard, heavy } = output.tier.probabilities
@@ -155,11 +223,9 @@ function tierFor(probabilities: LanguageModelTierProbabilities): LanguageModelTi
155
223
  function turnModel(
156
224
  language: LanguageModelCatalog,
157
225
  tier: LanguageModelTier,
158
- previous: ConversationAgentRunRecord | undefined,
159
- place: AgentTurnPlace
226
+ last: PreviousTurn | undefined
160
227
  ): LanguageModelEntry {
161
228
  const target = language.getByTier(tier)
162
- const last = previous && previousTurn(language, previous, place)
163
229
  if (!last) return target
164
230
 
165
231
  const change = tierRank(target.tier ?? tier) - tierRank(last.tier)
@@ -245,6 +245,8 @@ export async function requestAgentRun(
245
245
  "router" in requested
246
246
  ? await routedConversationRunSpec({
247
247
  ...requested,
248
+ agents,
249
+ projectId,
248
250
  previous: existingThread
249
251
  ? await latestConversationRun(agents, projectId, existingThread.id)
250
252
  : undefined,
@@ -419,6 +421,8 @@ export async function editAgentMessage(
419
421
  "router" in requested
420
422
  ? await routedConversationRunSpec({
421
423
  ...requested,
424
+ agents,
425
+ projectId,
422
426
  previous: await latestRetainedConversationRun(agents, projectId, thread.id, tail),
423
427
  place,
424
428
  settings,
@@ -1866,6 +1870,8 @@ function routedTurn(
1866
1870
  /** The spec of a turn Sixb picks the model for, compared to the thread's previous turn. */
1867
1871
  async function routedConversationRunSpec(
1868
1872
  input: RoutedTurn & {
1873
+ readonly agents: AgentStorage
1874
+ readonly projectId: string
1869
1875
  /** The turn this one continues, absent for a thread's first. */
1870
1876
  readonly previous: ConversationAgentRunRecord | undefined
1871
1877
  /** Where the turn runs: the previous turn's cache holds its prompt only if it ran there. */
@@ -1874,7 +1880,11 @@ async function routedConversationRunSpec(
1874
1880
  readonly language: LanguageModelCatalog | undefined
1875
1881
  }
1876
1882
  ): Promise<ConversationAgentRunSpec> {
1877
- const choice = await input.router.choose(input.text, input.previous, input.place)
1883
+ const previous = input.previous && {
1884
+ run: input.previous,
1885
+ text: await messageWords(input.agents, input.projectId, input.previous.triggerMessageId),
1886
+ }
1887
+ const choice = await input.router.choose({ text: input.text, previous, place: input.place })
1878
1888
 
1879
1889
  return resolveConversationRunSpec({
1880
1890
  models: input.language,
@@ -1884,6 +1894,22 @@ async function routedConversationRunSpec(
1884
1894
  })
1885
1895
  }
1886
1896
 
1897
+ /** What a person wrote in a message, without the context or files sent with it. */
1898
+ async function messageWords(
1899
+ agents: AgentStorage,
1900
+ projectId: string,
1901
+ messageId: string
1902
+ ): Promise<string | undefined> {
1903
+ const message = await agents.messages.getById({ projectId, id: messageId })
1904
+ if (!message) return undefined
1905
+
1906
+ const words = message.parts
1907
+ .flatMap((part) => (part.type === "text" ? [part.text] : []))
1908
+ .join("\n")
1909
+ .trim()
1910
+ return words || undefined
1911
+ }
1912
+
1887
1913
  async function latestConversationRun(
1888
1914
  agents: AgentStorage,
1889
1915
  projectId: string,
@@ -40,6 +40,13 @@ export const AGENT_API_ROUTES: readonly AgentApiRoute[] = SIXB_API_ROUTES.filter
40
40
  effect: route.agentEffect ?? "read",
41
41
  }))
42
42
 
43
+ /**
44
+ * The run a run-token request is from, which the sandbox CLI sends from `SIXB_RUN_ID`: one of the
45
+ * token's run's own children when the child works in its parent's workspace, under its parent's
46
+ * token. The server narrows the token's authority to that child; it never widens it.
47
+ */
48
+ export const AGENT_RUN_HEADER = "x-sixb-run"
49
+
43
50
  export function createAgentRunToken(input: AgentRunTokenInput): string {
44
51
  return signToken(RUN_TOKEN, input)
45
52
  }
@@ -8,7 +8,7 @@
8
8
 
9
9
  import { AsyncLocalStorage } from "node:async_hooks"
10
10
  import { readdir } from "node:fs/promises"
11
- import { join, relative, resolve, sep } from "node:path"
11
+ import { join, posix, relative, resolve, sep } from "node:path"
12
12
  import { pathToFileURL } from "node:url"
13
13
  import { isActionDefinition } from "../actions"
14
14
  import { isConnectorDefinition } from "../connectors"
@@ -19,6 +19,7 @@ import type { ValueType } from "../ontology/types"
19
19
  import { isPipelineDefinition } from "../pipelines"
20
20
  import { isProjectionDefinition } from "../projections/builders"
21
21
  import { isRuleDefinition } from "../rules"
22
+ import type { DefinitionFolderFamily, DefinitionFolderIndex } from "../runtime/definitions"
22
23
  import { RuntimeError } from "../runtime/errors"
23
24
  import { isScheduleDefinition } from "../schedules"
24
25
  import {
@@ -44,6 +45,8 @@ export interface DiscoveredOntologyModule {
44
45
  export interface DiscoveredOntology {
45
46
  readonly sources: readonly OntologySource[]
46
47
  readonly modules: readonly DiscoveredOntologyModule[]
48
+ /** Each object type's folder below `ontology/`; see {@link DefinitionFolderIndex}. */
49
+ readonly folders: ReadonlyMap<string, string>
47
50
  }
48
51
 
49
52
  export async function discoverOntologySources(projectRoot: string): Promise<DiscoveredOntology> {
@@ -53,6 +56,7 @@ export async function discoverOntologySources(projectRoot: string): Promise<Disc
53
56
  const objectTypes: ObjectTypeWithPropertyTokens[] = []
54
57
  const valueTypes: ValueType[] = []
55
58
  const modules: DiscoveredOntologyModule[] = []
59
+ const folders = new DefinitionFolderCollector()
56
60
  const seen = new Set<unknown>()
57
61
 
58
62
  for (const loaded of loadedModules) {
@@ -77,10 +81,9 @@ export async function discoverOntologySources(projectRoot: string): Promise<Disc
77
81
  valueTypes.push(candidate)
78
82
  }
79
83
  }
80
- modules.push({
81
- path: toPosix(relative("ontology", loaded.path)),
82
- objectTypeIds: [...new Set(objectTypeIds)],
83
- })
84
+ const path = toPosix(relative("ontology", loaded.path))
85
+ for (const id of objectTypeIds) folders.add(id, path)
86
+ modules.push({ path, objectTypeIds: [...new Set(objectTypeIds)] })
84
87
  }
85
88
 
86
89
  const discoveredSources: OntologySource[] = [...ontologyDocuments, ...objectTypes]
@@ -93,7 +96,7 @@ export async function discoverOntologySources(projectRoot: string): Promise<Disc
93
96
  })
94
97
  }
95
98
 
96
- return { sources: discoveredSources, modules }
99
+ return { sources: discoveredSources, modules, folders: folders.index }
97
100
  }
98
101
 
99
102
  export type DiscoveryModuleKind =
@@ -217,31 +220,78 @@ export type DiscoveredProjectDefinitions = {
217
220
  readonly [TKey in keyof typeof definitionDiscoveryRegistry]: readonly DefinitionFromFamily<
218
221
  (typeof definitionDiscoveryRegistry)[TKey]
219
222
  >[]
223
+ } & {
224
+ /** The folder each definition was found in; object types come from `discoverOntologySources`. */
225
+ readonly folders: Omit<DefinitionFolderIndex, "objectTypes">
220
226
  }
221
227
 
228
+ /** The families whose folders the app shows; the rest are kept by id alone. */
229
+ const folderFamilies: ReadonlySet<string> = new Set<Exclude<DefinitionFolderFamily, "objectTypes">>(
230
+ ["actions", "connectors", "datasets", "pipelines", "projections", "rules", "syncs", "workflows"]
231
+ )
232
+
222
233
  export async function discoverProjectDefinitions(
223
234
  projectRoot: string
224
235
  ): Promise<DiscoveredProjectDefinitions> {
225
236
  const entries = await Promise.all(
226
237
  Object.entries(definitionDiscoveryRegistry).map(async ([key, family]) => {
227
- const definitions = await discoverDefinitionFamily(projectRoot, family)
228
- return [key, definitions] as const
238
+ const discovered = await discoverDefinitionFamily(projectRoot, family)
239
+ return [key, discovered] as const
229
240
  })
230
241
  )
231
242
 
243
+ const folders = Object.fromEntries(
244
+ entries.filter(([key]) => folderFamilies.has(key)).map(([key, { folders }]) => [key, folders])
245
+ )
232
246
  // Object.fromEntries erases literal keys. Every entry above comes from the exact registry and its
233
247
  // definitions have passed that entry's type guard, so restoring the mapped result type is safe.
234
- return Object.fromEntries(entries) as DiscoveredProjectDefinitions
248
+ return {
249
+ ...Object.fromEntries(entries.map(([key, { definitions }]) => [key, definitions])),
250
+ folders,
251
+ } as DiscoveredProjectDefinitions
235
252
  }
236
253
 
237
254
  async function discoverDefinitionFamily(
238
255
  projectRoot: string,
239
256
  family: DefinitionDiscoveryFamily<unknown>
240
- ): Promise<readonly unknown[]> {
257
+ ): Promise<{ definitions: readonly unknown[]; folders: ReadonlyMap<string, string> }> {
241
258
  const loadedModules = await loadFamilyModules(projectRoot, family.kind, family.directory)
242
259
  const exportedCandidates = new Set(loadedModules.flatMap((loaded) => loaded.exports))
260
+ const definitions = [...exportedCandidates].filter(family.isDefinition)
261
+ const isDefinition = new Set(definitions)
262
+
263
+ const directory = family.directory.join("/")
264
+ const folders = new DefinitionFolderCollector()
265
+ for (const loaded of loadedModules) {
266
+ const path = posix.relative(directory, toPosix(loaded.path))
267
+ for (const candidate of loaded.exports) {
268
+ if (isDefinition.has(candidate) && hasStringId(candidate)) folders.add(candidate.id, path)
269
+ }
270
+ }
271
+
272
+ return { definitions, folders: folders.index }
273
+ }
274
+
275
+ /**
276
+ * Collects each definition's folder from the modules that export it. When several do, the deepest
277
+ * wins: a barrel such as `datasets/index.ts` re-exports what the files below it define.
278
+ */
279
+ class DefinitionFolderCollector {
280
+ readonly index = new Map<string, string>()
281
+ private readonly depths = new Map<string, number>()
282
+
283
+ /** `path` is the module's POSIX path below the family's directory. */
284
+ add(id: string, path: string): void {
285
+ const folder = posix.dirname(path)
286
+ const depth = folder === "." ? 0 : folder.split("/").length
287
+ if ((this.depths.get(id) ?? -1) >= depth) return
288
+ this.depths.set(id, depth)
289
+ if (depth > 0) this.index.set(id, folder)
290
+ }
291
+ }
243
292
 
244
- return [...exportedCandidates].filter(family.isDefinition)
293
+ function hasStringId(value: unknown): value is { readonly id: string } {
294
+ return isRecord(value) && typeof value.id === "string"
245
295
  }
246
296
 
247
297
  /**
@@ -1,11 +1,7 @@
1
1
  export { defineDeploy } from "./define"
2
2
  export type {
3
- DeployAccess,
4
- DeployAccessKey,
5
3
  DeployCheck,
6
4
  DeployCheckContext,
7
- DeployCi,
8
- DeployCiCredential,
9
5
  DeployCommand,
10
6
  DeployConfig,
11
7
  DeployContext,
@@ -29,7 +25,6 @@ export type {
29
25
  DeployScript,
30
26
  DeployServiceName,
31
27
  DeployServicesConfig,
32
- DeploySetupContext,
33
28
  DeploySingletonServiceConfig,
34
29
  DeploySingletonServiceName,
35
30
  DeploySource,
@@ -134,89 +134,34 @@ export interface DeployTarget {
134
134
  ): Promise<void>
135
135
  /** What stands between the target and a working deploy of the release, changing nothing. */
136
136
  check(release: DeployRelease, context: DeployCheckContext): Promise<readonly DeployCheck[]>
137
- /** Prepares the target for the release, fixing what `check` reports as fixable. */
138
- setup?(release: DeployRelease, context: DeploySetupContext): Promise<void>
139
137
  /**
140
138
  * Runs a script against the deployed project, as `sixb run` would there, with the environment the
141
139
  * deployment's services start from and the script's output on this terminal. Resolves with its
142
140
  * exit code; rejects only when the target cannot run it.
143
141
  */
144
142
  run?(script: DeployScript, context: DeployOperationContext): Promise<number>
145
- /** Who may deploy and operate the deployment, for a target reached with keys. */
146
- readonly access?: DeployAccess
147
- /** Credentials for a CI job that deploys, for a target reached with keys. */
148
- readonly ci?: DeployCi
149
143
  }
150
144
 
151
145
  export interface DeployCheck {
152
146
  readonly id: string
153
147
  /** What was checked, such as `"SSH"` or `"api DNS"`. */
154
148
  readonly label: string
155
- /**
156
- * `fixable`: `sixb deploy setup` fixes it. `manual`: only you can, as `remedy` says. Both stop
157
- * a deploy; a `warning` does not.
158
- */
159
- readonly status: "ok" | "fixable" | "manual" | "warning"
149
+ /** `fail` stops a deploy until `remedy` is done; a `warning` does not. */
150
+ readonly status: "ok" | "fail" | "warning"
160
151
  readonly detail: string
161
152
  /** What to do about it, when the status is not `ok`. */
162
153
  readonly remedy?: string
154
+ /** Shell commands that fix it, for someone with administrator rights on the target to run once. */
155
+ readonly commands?: readonly string[]
163
156
  }
164
157
 
165
158
  export interface DeployCheckContext extends DeployOperationContext {
166
159
  /** The project's directory inside its repository: `.` at the root. */
167
160
  readonly projectPath: string
168
- }
169
-
170
- export interface DeploySetupContext extends DeployCheckContext {
171
- /** The account with sudo that prepares a server, for a target that needs one. */
172
- readonly admin?: string
173
- /** A public key file to authorize for deploys, instead of the one the target would pick. */
174
- readonly key?: string
175
- /** Creates the token `steps.env` reads with, for a target that doesn't have one yet. */
176
- readonly createEnvToken?: () => Promise<string>
177
- /** A line of progress for the person running setup. */
178
- write(line: string): void
179
- }
180
-
181
- export interface DeployAccess {
182
- list(context: DeployOperationContext): Promise<readonly DeployAccessKey[]>
183
- /** Authorizes a public key, given as its text (`ssh-ed25519 AAAA… comment`). */
184
- add(key: string, context: DeployOperationContext): Promise<DeployAccessKey>
185
- /** Revokes the keys whose fingerprint or comment matches, and returns them. */
186
- remove(match: string, context: DeployOperationContext): Promise<readonly DeployAccessKey[]>
187
- }
188
-
189
- export interface DeployAccessKey {
190
- readonly type: string
191
- readonly fingerprint: string
192
- readonly comment: string
193
- /** Whether the key is limited to running commands: no forwarding, no terminal. */
194
- readonly restricted: boolean
195
- }
196
-
197
- /**
198
- * Lets a CI job deploy. `sixb deploy ci` stores what `create` returns as the CI system's secrets and
199
- * writes the workflow around it.
200
- */
201
- export interface DeployCi {
202
- /**
203
- * Creates a credential for one CI job, such as `"github:acme/shop"`, and authorizes it on the
204
- * target next to the job's earlier ones. Running it again for the same job rotates the credential.
205
- */
206
- create(job: string, context: DeployOperationContext): Promise<DeployCiCredential>
207
- }
208
-
209
- export interface DeployCiCredential {
210
- /** Describes the credential, such as its key's fingerprint. */
211
- readonly description: string
212
- /** What the CI job needs, by environment variable name. CI stores them as secrets. */
213
- readonly secrets: Readonly<Record<string, string>>
214
- /** Shell lines that install the credential on the CI runner, with `secrets` in the environment. */
215
- readonly install: readonly string[]
216
- /** Revokes the job's earlier credentials once CI holds this one, and returns them. */
217
- retireOthers(): Promise<readonly DeployAccessKey[]>
218
- /** Revokes this credential, when CI could not store it. */
219
- revoke(): Promise<void>
161
+ /** The project prints with Chromium through Playwright, so the target needs its libraries. */
162
+ readonly chromium: boolean
163
+ /** The project's env source reads on the server with a token file, not an identity of its own. */
164
+ readonly envToken: boolean
220
165
  }
221
166
 
222
167
  export interface DeployListenAddress {