@qvac/core 1.0.0-rc.2 → 1.0.0-rc.5

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 (213) hide show
  1. package/CHANGELOG.md +238 -12
  2. package/dist-lib/index.d.ts +3 -1
  3. package/dist-lib/index.js +1 -0
  4. package/dist-lib/lib/api/approval-rules.d.ts +1 -1
  5. package/dist-lib/lib/api/approval-rules.js +5 -1
  6. package/dist-lib/lib/api/chunk-delta.d.ts +7 -2
  7. package/dist-lib/lib/api/chunk-delta.js +89 -7
  8. package/dist-lib/lib/api/chunks.js +14 -8
  9. package/dist-lib/lib/api/config.d.ts +10 -3
  10. package/dist-lib/lib/api/config.js +51 -6
  11. package/dist-lib/lib/api/custom-models.js +3 -5
  12. package/dist-lib/lib/api/devices.js +3 -1
  13. package/dist-lib/lib/api/files.d.ts +1 -1
  14. package/dist-lib/lib/api/files.js +65 -8
  15. package/dist-lib/lib/api/index.d.ts +12 -2
  16. package/dist-lib/lib/api/index.js +6 -1
  17. package/dist-lib/lib/api/instrument.js +12 -4
  18. package/dist-lib/lib/api/members.js +7 -13
  19. package/dist-lib/lib/api/mesh.d.ts +1 -3
  20. package/dist-lib/lib/api/mesh.js +2 -2
  21. package/dist-lib/lib/api/notifications.js +8 -4
  22. package/dist-lib/lib/api/projects.js +5 -1
  23. package/dist-lib/lib/api/rag.js +32 -19
  24. package/dist-lib/lib/api/served.js +2 -1
  25. package/dist-lib/lib/api/workspace.js +0 -1
  26. package/dist-lib/lib/assistant/harness.d.ts +8 -2
  27. package/dist-lib/lib/assistant/harness.js +17 -4
  28. package/dist-lib/lib/assistant/history.d.ts +1 -1
  29. package/dist-lib/lib/assistant/history.js +19 -13
  30. package/dist-lib/lib/assistant/message.d.ts +6 -1
  31. package/dist-lib/lib/assistant/message.js +22 -2
  32. package/dist-lib/lib/assistant/model-round.d.ts +5 -0
  33. package/dist-lib/lib/assistant/model-round.js +47 -19
  34. package/dist-lib/lib/assistant/pdf-budget.d.ts +10 -2
  35. package/dist-lib/lib/assistant/pdf-budget.js +10 -11
  36. package/dist-lib/lib/assistant/pdf-pages.d.ts +25 -0
  37. package/dist-lib/lib/assistant/pdf-pages.js +75 -0
  38. package/dist-lib/lib/assistant/round-host.js +5 -3
  39. package/dist-lib/lib/assistant-client.d.ts +2 -1
  40. package/dist-lib/lib/assistant-client.js +24 -6
  41. package/dist-lib/lib/assistant-tree.d.ts +2 -0
  42. package/dist-lib/lib/assistant-tree.js +8 -5
  43. package/dist-lib/lib/assistant.d.ts +21 -7
  44. package/dist-lib/lib/assistant.js +481 -244
  45. package/dist-lib/lib/client.js +10 -1
  46. package/dist-lib/lib/compaction.d.ts +3 -1
  47. package/dist-lib/lib/compaction.js +18 -4
  48. package/dist-lib/lib/constants.d.ts +3 -0
  49. package/dist-lib/lib/constants.js +3 -0
  50. package/dist-lib/lib/core/agent-copies.js +7 -1
  51. package/dist-lib/lib/core/agent.js +1 -0
  52. package/dist-lib/lib/core/approval-rules.d.ts +5 -1
  53. package/dist-lib/lib/core/approval-rules.js +16 -1
  54. package/dist-lib/lib/core/chat-activity.js +13 -16
  55. package/dist-lib/lib/core/chat-copy.js +1 -1
  56. package/dist-lib/lib/core/chat-fork.js +2 -1
  57. package/dist-lib/lib/core/chat-move.d.ts +4 -0
  58. package/dist-lib/lib/core/chat-move.js +42 -11
  59. package/dist-lib/lib/core/chat.d.ts +0 -1
  60. package/dist-lib/lib/core/chat.js +1 -1
  61. package/dist-lib/lib/core/chunk.d.ts +14 -3
  62. package/dist-lib/lib/core/chunk.js +116 -25
  63. package/dist-lib/lib/core/collections.d.ts +12 -1
  64. package/dist-lib/lib/core/collections.js +12 -1
  65. package/dist-lib/lib/core/config-value.d.ts +7 -0
  66. package/dist-lib/lib/core/config-value.js +15 -0
  67. package/dist-lib/lib/core/contract/activity.d.ts +3 -2
  68. package/dist-lib/lib/core/contract/activity.js +39 -21
  69. package/dist-lib/lib/core/contract/agent-join.js +15 -19
  70. package/dist-lib/lib/core/contract/agents.js +8 -7
  71. package/dist-lib/lib/core/contract/chat.d.ts +3 -0
  72. package/dist-lib/lib/core/contract/chat.js +12 -1
  73. package/dist-lib/lib/core/contract/chunks.js +16 -6
  74. package/dist-lib/lib/core/contract/devices.js +6 -4
  75. package/dist-lib/lib/core/contract/index.js +2 -1
  76. package/dist-lib/lib/core/contract/invites.js +12 -31
  77. package/dist-lib/lib/core/contract/joined-meshes.js +2 -1
  78. package/dist-lib/lib/core/contract/mesh-rules.js +4 -0
  79. package/dist-lib/lib/core/contract/model-requests.js +7 -6
  80. package/dist-lib/lib/core/contract/project-device-keys.js +15 -6
  81. package/dist-lib/lib/core/contract/project-host-keys.js +5 -4
  82. package/dist-lib/lib/core/contract/projects.js +12 -13
  83. package/dist-lib/lib/core/contract/public-seeds.js +5 -5
  84. package/dist-lib/lib/core/contract/roles.js +2 -1
  85. package/dist-lib/lib/core/contract/run-requests.d.ts +1 -1
  86. package/dist-lib/lib/core/contract/run-requests.js +19 -13
  87. package/dist-lib/lib/core/contract/shipped-rows.d.ts +2 -0
  88. package/dist-lib/lib/core/contract/shipped-rows.js +22 -0
  89. package/dist-lib/lib/core/contract/workspace.js +6 -12
  90. package/dist-lib/lib/core/contract/writers.js +20 -6
  91. package/dist-lib/lib/core/deleted-agent-runs.d.ts +7 -0
  92. package/dist-lib/lib/core/deleted-agent-runs.js +46 -0
  93. package/dist-lib/lib/core/devices.d.ts +2 -1
  94. package/dist-lib/lib/core/devices.js +4 -2
  95. package/dist-lib/lib/core/document-attachment.d.ts +6 -3
  96. package/dist-lib/lib/core/document-attachment.js +10 -5
  97. package/dist-lib/lib/core/files/attachments.js +3 -3
  98. package/dist-lib/lib/core/files/index.d.ts +8 -5
  99. package/dist-lib/lib/core/files/index.js +111 -18
  100. package/dist-lib/lib/core/files/processing/index.d.ts +1 -1
  101. package/dist-lib/lib/core/files/processing/index.js +8 -2
  102. package/dist-lib/lib/core/files/processing/source.d.ts +1 -0
  103. package/dist-lib/lib/core/files/processing/source.js +3 -0
  104. package/dist-lib/lib/core/files/processing/state.d.ts +1 -0
  105. package/dist-lib/lib/core/files/processing/state.js +7 -0
  106. package/dist-lib/lib/core/files/rag/build.d.ts +1 -0
  107. package/dist-lib/lib/core/files/rag/build.js +14 -1
  108. package/dist-lib/lib/core/files/rag/index.d.ts +1 -1
  109. package/dist-lib/lib/core/files/rag/index.js +1 -1
  110. package/dist-lib/lib/core/files/rag/produce.js +1 -0
  111. package/dist-lib/lib/core/files/rag/retrieval/full-text.d.ts +2 -0
  112. package/dist-lib/lib/core/files/rag/retrieval/full-text.js +7 -1
  113. package/dist-lib/lib/core/first-event.d.ts +6 -0
  114. package/dist-lib/lib/core/first-event.js +13 -0
  115. package/dist-lib/lib/core/invite.d.ts +2 -2
  116. package/dist-lib/lib/core/invite.js +5 -4
  117. package/dist-lib/lib/core/local/index.d.ts +16 -1
  118. package/dist-lib/lib/core/local/index.js +119 -10
  119. package/dist-lib/lib/core/mesh.d.ts +14 -3
  120. package/dist-lib/lib/core/mesh.js +127 -54
  121. package/dist-lib/lib/core/migrations/chat-chunks.d.ts +4 -0
  122. package/dist-lib/lib/core/migrations/chat-chunks.js +47 -0
  123. package/dist-lib/lib/core/migrations/file-index.d.ts +1 -1
  124. package/dist-lib/lib/core/migrations/file-index.js +6 -2
  125. package/dist-lib/lib/core/migrations/index.d.ts +2 -1
  126. package/dist-lib/lib/core/migrations/index.js +66 -9
  127. package/dist-lib/lib/core/notification.js +96 -23
  128. package/dist-lib/lib/core/pdf/figure.d.ts +22 -0
  129. package/dist-lib/lib/core/pdf/figure.js +64 -0
  130. package/dist-lib/lib/core/pdf/rasterize.d.ts +10 -1
  131. package/dist-lib/lib/core/pdf/rasterize.js +72 -22
  132. package/dist-lib/lib/core/peer-duplex.js +57 -5
  133. package/dist-lib/lib/core/public-mesh.js +8 -2
  134. package/dist-lib/lib/core/run-requests.js +2 -3
  135. package/dist-lib/lib/core/senders.d.ts +7 -6
  136. package/dist-lib/lib/core/senders.js +23 -30
  137. package/dist-lib/lib/core/shared-agents.d.ts +1 -0
  138. package/dist-lib/lib/core/shared-agents.js +47 -19
  139. package/dist-lib/lib/core/skill-secrets.d.ts +3 -2
  140. package/dist-lib/lib/core/skill-secrets.js +4 -1
  141. package/dist-lib/lib/core/sync/background.d.ts +3 -15
  142. package/dist-lib/lib/core/sync/background.js +25 -102
  143. package/dist-lib/lib/core/sync/devices.js +6 -3
  144. package/dist-lib/lib/core/sync/index.js +25 -3
  145. package/dist-lib/lib/core/sync-status.js +3 -3
  146. package/dist-lib/lib/core/vault-managed-skills.d.ts +18 -0
  147. package/dist-lib/lib/core/vault-managed-skills.js +105 -0
  148. package/dist-lib/lib/core.d.ts +66 -10
  149. package/dist-lib/lib/core.js +768 -179
  150. package/dist-lib/lib/credential-pusher.d.ts +11 -7
  151. package/dist-lib/lib/credential-pusher.js +40 -8
  152. package/dist-lib/lib/device-tree.d.ts +18 -0
  153. package/dist-lib/lib/device-tree.js +32 -0
  154. package/dist-lib/lib/doctor/redact.js +1 -1
  155. package/dist-lib/lib/errors.d.ts +12 -0
  156. package/dist-lib/lib/errors.js +12 -0
  157. package/dist-lib/lib/fs-drive-bridge.d.ts +7 -0
  158. package/dist-lib/lib/fs-drive-bridge.js +308 -30
  159. package/dist-lib/lib/integrations/setup-routes.js +7 -5
  160. package/dist-lib/lib/knowledge-search.d.ts +1 -1
  161. package/dist-lib/lib/knowledge-search.js +5 -46
  162. package/dist-lib/lib/kv-cache-retention.d.ts +35 -0
  163. package/dist-lib/lib/kv-cache-retention.js +98 -0
  164. package/dist-lib/lib/latest-frame.d.ts +10 -0
  165. package/dist-lib/lib/latest-frame.js +48 -0
  166. package/dist-lib/lib/mesh-scoped-engine.js +1 -0
  167. package/dist-lib/lib/model-download.d.ts +6 -1
  168. package/dist-lib/lib/model-download.js +32 -17
  169. package/dist-lib/lib/oauth/resolve.js +13 -5
  170. package/dist-lib/lib/reconnecting-watch.js +19 -11
  171. package/dist-lib/lib/run-notices.d.ts +2 -0
  172. package/dist-lib/lib/run-notices.js +5 -0
  173. package/dist-lib/lib/run-replay.d.ts +13 -1
  174. package/dist-lib/lib/run-replay.js +58 -21
  175. package/dist-lib/schema/build.js +66 -57
  176. package/dist-lib/schema/config.d.ts +1 -1
  177. package/dist-lib/schema/config.js +1 -1
  178. package/dist-lib/schema/content.js +2 -1
  179. package/dist-lib/schema/engine.js +70 -6
  180. package/dist-lib/schema/field-order.js +7 -1
  181. package/dist-lib/schema/indexes.d.ts +4 -0
  182. package/dist-lib/schema/indexes.js +18 -0
  183. package/dist-lib/schema/local.js +9 -2
  184. package/dist-lib/schema/qvac.js +116 -6
  185. package/dist-lib/spec/bind.js +15 -0
  186. package/dist-lib/spec/calls.js +5 -0
  187. package/dist-lib/spec/capabilities.d.ts +10 -0
  188. package/dist-lib/spec/config/hyperconf/index.js +1 -1
  189. package/dist-lib/spec/hrpc/hrpc.json +65 -0
  190. package/dist-lib/spec/hrpc/index.js +63 -3
  191. package/dist-lib/spec/hrpc/messages.js +1537 -1395
  192. package/dist-lib/spec/hyperschema/index.js +1537 -1395
  193. package/dist-lib/spec/hyperschema/schema.json +126 -1
  194. package/dist-lib/spec/hyperschema/types.d.ts +33 -1
  195. package/dist-lib/spec/local/hyperdb/messages.js +110 -54
  196. package/dist-lib/spec/local/hyperschema/index.js +56 -28
  197. package/dist-lib/spec/local/hyperschema/schema.json +55 -20
  198. package/dist-lib/spec/local/hyperschema/types.d.ts +8 -1
  199. package/dist-lib/spec/mesh/hyperdb/db.json +255 -51
  200. package/dist-lib/spec/mesh/hyperdb/index.js +1063 -404
  201. package/dist-lib/spec/mesh/hyperdb/messages.js +1673 -1202
  202. package/dist-lib/spec/mesh/hyperdispatch/dispatch.json +62 -56
  203. package/dist-lib/spec/mesh/hyperdispatch/index.js +156 -139
  204. package/dist-lib/spec/mesh/hyperdispatch/messages.js +809 -632
  205. package/dist-lib/spec/mesh/hyperschema/index.js +809 -632
  206. package/dist-lib/spec/mesh/hyperschema/schema.json +293 -174
  207. package/dist-lib/spec/mesh/hyperschema/types.d.ts +31 -1
  208. package/package.json +32 -26
  209. package/worker/assistant-sidecar.mjs +3 -0
  210. package/dist-lib/lib/core/files/processing/settle.d.ts +0 -13
  211. package/dist-lib/lib/core/files/processing/settle.js +0 -86
  212. package/dist-lib/lib/core/migrations/device-indexes.d.ts +0 -2
  213. package/dist-lib/lib/core/migrations/device-indexes.js +0 -7
@@ -1,5 +1,5 @@
1
1
  import crypto from 'hypercore-crypto';
2
- import { liveDeviceForWriter, trackActivity } from './activity.js';
2
+ import { liveDeviceForWriter, liveDevicesOf, trackActivity } from './activity.js';
3
3
  import { nextGrantSequence, removedSinceMint } from './grant-order.js';
4
4
  import { meshKind, sharedKind } from './mesh-kind.js';
5
5
  import { isKickedRow } from '../helpers/index.js';
@@ -25,31 +25,18 @@ async function kickedFromOutside(tx, device, memberId) {
25
25
  const kickerMember = kicker.memberId ?? kicker.claimedMemberId;
26
26
  return !kickerMember || !b4a.equals(kickerMember, memberId);
27
27
  }
28
- async function memberStanding(tx, memberId, grant) {
29
- if (await removedSinceMint(tx, memberId, grant))
30
- return 'removed';
31
- for await (const device of tx.find(DEVICES)) {
32
- if (device.revoked)
33
- continue;
34
- const member = device.memberId ?? device.claimedMemberId;
35
- if (member && b4a.equals(member, memberId)) {
36
- return 'present';
37
- }
38
- }
39
- return null;
40
- }
41
- async function inviteStanding(tx, { device, memberId, grant }) {
42
- const standing = await memberStanding(tx, memberId, grant);
43
- if (standing !== 'present') {
44
- return standing;
28
+ async function inviteRefusal(tx, { device, memberId, grant }) {
29
+ if (await removedSinceMint(tx, memberId, grant)) {
30
+ return 'the member was removed after the mint';
45
31
  }
46
- if (!(await sharedKind(tx))) {
32
+ const present = (await liveDevicesOf(tx, memberId)).length > 0;
33
+ if (!present || !(await sharedKind(tx))) {
47
34
  return null;
48
35
  }
49
- if (!device?.revoked) {
50
- return 'present';
36
+ if (device?.revoked && (await removedBy(tx, device)) !== 'own-member') {
37
+ return null;
51
38
  }
52
- return (await removedBy(tx, device)) === 'own-member' ? 'present' : null;
39
+ return 'the member is still present';
53
40
  }
54
41
  async function belongsToAnotherMember(tx, device, memberId) {
55
42
  if (!device?.memberId || b4a.equals(device.memberId, memberId))
@@ -223,15 +210,9 @@ export function registerInviteRoutes(router) {
223
210
  log?.warn('contract', 'claim-invite dropped: the device belongs to another member', ids);
224
211
  return;
225
212
  }
226
- const standing = spent
227
- ? null
228
- : await inviteStanding(tx, { device: existing, memberId, grant });
229
- if (standing === 'present') {
230
- log?.warn('contract', 'claim-invite dropped: the member is still present', ids);
231
- return;
232
- }
233
- if (standing === 'removed') {
234
- log?.warn('contract', 'claim-invite dropped: the member was removed after the mint', ids);
213
+ const refusal = spent ? null : await inviteRefusal(tx, { device: existing, memberId, grant });
214
+ if (refusal) {
215
+ log?.warn('contract', `claim-invite dropped: ${refusal}`, ids);
235
216
  return;
236
217
  }
237
218
  const admission = await admitDevice(context, payload.device, {
@@ -38,6 +38,7 @@ function merge(mesh, existing, rejoin) {
38
38
  labeledAt: relabels ? mesh.labeledAt : existing.labeledAt,
39
39
  shared: remarks ? mesh.shared : existing.shared,
40
40
  sharedAt: remarks ? mesh.sharedAt : existing.sharedAt,
41
- workspace: existing.workspace || mesh.workspace
41
+ workspace: existing.workspace || mesh.workspace,
42
+ kicked: rejoin ? mesh.kicked : mesh.kicked || existing.kicked
42
43
  };
43
44
  }
@@ -1,5 +1,6 @@
1
1
  import { MESH_RULES } from '../collections.js';
2
2
  import { CoreError } from '../../errors.js';
3
+ import { reindexShippedRows } from './shipped-rows.js';
3
4
  export const MESH_RULES_ROW = 'mesh';
4
5
  export const WORKSPACES_RULES = 1;
5
6
  export const KNOWN_RULES = WORKSPACES_RULES;
@@ -23,6 +24,9 @@ export function registerMeshRulesRoutes(router) {
23
24
  throw new CoreError('MESH_RULES_FROM_A_NEWER_BUILD', [rules, KNOWN_RULES]);
24
25
  }
25
26
  const atGenesis = existing ? existing.atGenesis : host.genesis;
27
+ if (held < WORKSPACES_RULES && !atGenesis) {
28
+ await reindexShippedRows(tx);
29
+ }
26
30
  const row = { id: MESH_RULES_ROW, rules, atGenesis: atGenesis || undefined };
27
31
  await tx.insert(MESH_RULES, row);
28
32
  log?.info('contract', 'mesh rules raised', { rules });
@@ -1,6 +1,7 @@
1
1
  import b4a from 'b4a';
2
2
  import { chunkTypeOrdinal } from '../../../schema/indexes.js';
3
3
  import { liveDeviceForWriter, trackActivity } from './activity.js';
4
+ import { putChunk } from './chat.js';
4
5
  import { projectRules } from './projects.js';
5
6
  import { isProbeRound } from '../../probe-rounds.js';
6
7
  import { derivedId } from '../id.js';
@@ -75,7 +76,7 @@ export async function appendRow(tx, row) {
75
76
  lastActivityAt: Math.max(counter?.lastActivityAt ?? 0, row.createdAt)
76
77
  });
77
78
  const appended = { ...row, seq };
78
- await tx.insert(CHUNKS, appended);
79
+ await putChunk(tx, appended);
79
80
  return appended;
80
81
  }
81
82
  async function resetRound(tx, request, { node, by, at }) {
@@ -169,7 +170,7 @@ export async function closeRounds(tx, { chatId, runId, at }) {
169
170
  for (const chunk of rounds) {
170
171
  const request = asModelRequest(chunk);
171
172
  if (request?.runId === runId && LIVE.has(request.modelRequest.state)) {
172
- await tx.insert(CHUNKS, moved(request, { ...request.modelRequest, state: 'cancelled' }, at));
173
+ await putChunk(tx, moved(request, { ...request.modelRequest, state: 'cancelled' }, at));
173
174
  }
174
175
  }
175
176
  }
@@ -217,7 +218,7 @@ export function registerModelRequestRoutes(router) {
217
218
  await resetRound(tx, request, { node, by: takenBy, at });
218
219
  }
219
220
  const taken = moved(request, { ...request.modelRequest, state: 'taken', takenBy, takenAt: at }, at);
220
- await tx.insert(CHUNKS, taken);
221
+ await putChunk(tx, taken);
221
222
  return taken;
222
223
  }));
223
224
  router.add('@qvac/settle-model-request', trackActivity(async (op, context) => {
@@ -236,7 +237,7 @@ export function registerModelRequestRoutes(router) {
236
237
  return;
237
238
  }
238
239
  const settled = moved(request, { ...request.modelRequest, state: op.state, result: op.result, reason: op.reason }, op.at);
239
- await tx.insert(CHUNKS, settled);
240
+ await putChunk(tx, settled);
240
241
  return settled;
241
242
  }));
242
243
  router.add('@qvac/cancel-model-request', trackActivity(async (op, { tx, node, log }) => {
@@ -252,7 +253,7 @@ export function registerModelRequestRoutes(router) {
252
253
  return;
253
254
  }
254
255
  const cancelled = moved(request, { ...request.modelRequest, state: 'cancelled' }, op.at);
255
- await tx.insert(CHUNKS, cancelled);
256
+ await putChunk(tx, cancelled);
256
257
  return cancelled;
257
258
  }));
258
259
  router.add('@qvac/reopen-model-request', trackActivity(async (op, { tx, node, log }) => {
@@ -273,7 +274,7 @@ export function registerModelRequestRoutes(router) {
273
274
  await resetRound(tx, request, { node, by: owner.id, at: op.at });
274
275
  const { takenBy: _takenBy, takenAt: _takenAt, ...ask } = request.modelRequest;
275
276
  const reopened = moved(request, { ...ask, state: 'open' }, op.at);
276
- await tx.insert(CHUNKS, reopened);
277
+ await putChunk(tx, reopened);
277
278
  return reopened;
278
279
  }));
279
280
  }
@@ -1,5 +1,5 @@
1
1
  import b4a from 'b4a';
2
- import { PROJECT_DEVICE_KEYS } from '../collections.js';
2
+ import { PROJECT_DEVICE_KEYS, PROJECT_DEVICE_KEYS_BY_DEVICE, PROJECT_DEVICE_KEYS_BY_MEMBER } from '../collections.js';
3
3
  export function readProjectDeviceKey(tx, projectId, deviceId) {
4
4
  return tx.get(PROJECT_DEVICE_KEYS, { projectId, deviceId });
5
5
  }
@@ -12,9 +12,6 @@ async function drop(tx, rows, match) {
12
12
  await tx.delete(PROJECT_DEVICE_KEYS, { projectId: row.projectId, deviceId: row.deviceId });
13
13
  }
14
14
  }
15
- function allRows(tx) {
16
- return tx.find(PROJECT_DEVICE_KEYS).toArray();
17
- }
18
15
  export async function dropProjectDeviceKeys(tx, projectId) {
19
16
  await drop(tx, await deviceKeysOf(tx, projectId), () => true);
20
17
  }
@@ -22,8 +19,20 @@ export async function dropListingDeviceKeys(tx, projectId, memberId) {
22
19
  await drop(tx, await deviceKeysOf(tx, projectId), (row) => b4a.equals(row.memberId, memberId));
23
20
  }
24
21
  export async function dropMemberDeviceKeys(tx, memberId) {
25
- await drop(tx, await allRows(tx), (row) => b4a.equals(row.memberId, memberId));
22
+ const rows = await tx
23
+ .find(PROJECT_DEVICE_KEYS_BY_MEMBER, {
24
+ gte: { memberId },
25
+ lte: { memberId }
26
+ })
27
+ .toArray();
28
+ await drop(tx, rows, () => true);
26
29
  }
27
30
  export async function dropDeviceKeysOf(tx, deviceId) {
28
- await drop(tx, await allRows(tx), (row) => b4a.equals(row.deviceId, deviceId));
31
+ const rows = await tx
32
+ .find(PROJECT_DEVICE_KEYS_BY_DEVICE, {
33
+ gte: { deviceId },
34
+ lte: { deviceId }
35
+ })
36
+ .toArray();
37
+ await drop(tx, rows, () => true);
29
38
  }
@@ -1,5 +1,5 @@
1
1
  import b4a from 'b4a';
2
- import { DEVICES, PROJECT_HOST_KEYS } from '../collections.js';
2
+ import { DEVICES, PROJECT_HOST_KEYS, PROJECT_HOST_KEYS_BY_DEVICE } from '../collections.js';
3
3
  import { liveAgentsOn, usesAny } from './public-seeds.js';
4
4
  export function readProjectHostKey(tx, projectId, deviceId) {
5
5
  return tx.get(PROJECT_HOST_KEYS, { projectId, deviceId });
@@ -21,9 +21,10 @@ export async function dropMemberHostKeys(tx, projectId, memberId) {
21
21
  }
22
22
  }
23
23
  }
24
- async function hostKeysSealedTo(tx, deviceId) {
25
- const rows = await tx.find(PROJECT_HOST_KEYS).toArray();
26
- return rows.filter((row) => b4a.equals(row.deviceId, deviceId));
24
+ function hostKeysSealedTo(tx, deviceId) {
25
+ return tx
26
+ .find(PROJECT_HOST_KEYS_BY_DEVICE, { gte: { deviceId }, lte: { deviceId } })
27
+ .toArray();
27
28
  }
28
29
  export async function dropDeviceHostKeys(tx, deviceId) {
29
30
  for (const row of await hostKeysSealedTo(tx, deviceId)) {
@@ -1,4 +1,4 @@
1
- import { liveDeviceForWriter, trackActivity } from './activity.js';
1
+ import { liveDeviceForWriter, liveDevicesOf, trackActivity } from './activity.js';
2
2
  import { meshKind } from './mesh-kind.js';
3
3
  import { WORKSPACES_RULES, rulesVersion } from './mesh-rules.js';
4
4
  import { isWorkspace, readMemberKey, upgradeMembers } from './workspace.js';
@@ -7,7 +7,7 @@ import { dropMemberHostKeys, dropProjectHostKeys, readProjectHostKey } from './p
7
7
  import { dropListingDeviceKeys, dropProjectDeviceKeys, readProjectDeviceKey } from './project-device-keys.js';
8
8
  import b4a from 'b4a';
9
9
  import { SEALED_SEED_BYTES } from '../device-seal.js';
10
- import { AGENT_USERS, AGENTS, CHAT_GROUPS, DEVICES, MESH_FOUNDERS, PROJECT_DEVICE_KEYS, PROJECT_HOST_KEYS, PROJECT_KEYS, PROJECT_MEMBERS, PROJECTS } from '../collections.js';
10
+ import { AGENT_USERS, AGENTS, CHAT_GROUPS, DEVICES, MESH_FOUNDERS, PROJECT_DEVICE_KEYS, PROJECT_HOST_KEYS, PROJECT_KEYS, PROJECT_KEYS_BY_MEMBER, PROJECT_MEMBERS, PROJECTS } from '../collections.js';
11
11
  export const UNGROUPED = '@qvac/ungrouped';
12
12
  export function readProject(tx, id) {
13
13
  return tx.get(PROJECTS, { id });
@@ -22,10 +22,11 @@ async function dropProjectKeys(tx, projectId) {
22
22
  }
23
23
  }
24
24
  export async function dropMemberProjectKeys(tx, memberId) {
25
- for (const row of await tx.find(PROJECT_KEYS).toArray()) {
26
- if (b4a.equals(row.memberId, memberId)) {
27
- await tx.delete(PROJECT_KEYS, { projectId: row.projectId, memberId });
28
- }
25
+ const rows = await tx
26
+ .find(PROJECT_KEYS_BY_MEMBER, { gte: { memberId }, lte: { memberId } })
27
+ .toArray();
28
+ for (const row of rows) {
29
+ await tx.delete(PROJECT_KEYS, { projectId: row.projectId, memberId });
29
30
  }
30
31
  }
31
32
  export function listsMember(project, memberId) {
@@ -53,13 +54,7 @@ export async function outsideProject(tx, memberId) {
53
54
  return !memberId || !(await inProject(tx, memberId));
54
55
  }
55
56
  export async function liveMember(tx, memberId, since = -1) {
56
- for await (const device of tx.find(DEVICES)) {
57
- const theirs = device.memberId && b4a.equals(device.memberId, memberId);
58
- if (!device.revoked && theirs && device.joinedAt > since) {
59
- return true;
60
- }
61
- }
62
- return false;
57
+ return (await liveDevicesOf(tx, memberId)).some((device) => !!device.memberId && b4a.equals(device.memberId, memberId) && device.joinedAt > since);
63
58
  }
64
59
  export async function signerMember({ tx, node }) {
65
60
  return (await liveDeviceForWriter(tx, node.key))?.memberId ?? null;
@@ -312,6 +307,10 @@ async function putProjectMember({ memberId, addedAt }, context) {
312
307
  log?.warn('contract', "put-project-member dropped: only the project's members add one");
313
308
  return;
314
309
  }
310
+ if (b4a.equals(signer, memberId)) {
311
+ log?.warn('contract', 'put-project-member dropped: a member cannot add itself');
312
+ return;
313
+ }
315
314
  }
316
315
  const row = { memberId, addedAt };
317
316
  await tx.insert(PROJECT_MEMBERS, row);
@@ -1,5 +1,4 @@
1
- import b4a from 'b4a';
2
- import { AGENT_USERS, AGENTS_BY_PROVIDER, PUBLIC_SEEDS } from '../collections.js';
1
+ import { AGENT_USERS, AGENTS_BY_PROVIDER, PUBLIC_SEEDS, PUBLIC_SEEDS_BY_DEVICE } from '../collections.js';
3
2
  export function readPublicSeed(tx, memberId, deviceId) {
4
3
  return tx.get(PUBLIC_SEEDS, { memberId, deviceId });
5
4
  }
@@ -17,9 +16,10 @@ export async function dropMemberSeeds(tx, memberId) {
17
16
  await tx.delete(PUBLIC_SEEDS, { memberId, deviceId: row.deviceId });
18
17
  }
19
18
  }
20
- async function seedsSealedTo(tx, deviceId) {
21
- const rows = await tx.find(PUBLIC_SEEDS).toArray();
22
- return rows.filter((row) => b4a.equals(row.deviceId, deviceId));
19
+ function seedsSealedTo(tx, deviceId) {
20
+ return tx
21
+ .find(PUBLIC_SEEDS_BY_DEVICE, { gte: { deviceId }, lte: { deviceId } })
22
+ .toArray();
23
23
  }
24
24
  export async function dropDeviceSeeds(tx, deviceId) {
25
25
  for (const row of await seedsSealedTo(tx, deviceId)) {
@@ -79,7 +79,8 @@ export const ROUTE_ROLES = {
79
79
  '@qvac/put-agent-user': WORKSPACE,
80
80
  '@qvac/agent-join': CONTENT,
81
81
  '@qvac/take-run-request': CONTENT,
82
- '@qvac/put-skill-secret': ['account']
82
+ '@qvac/put-skill-secret': ['account'],
83
+ '@qvac/reindex-chat-chunks': CONTENT
83
84
  };
84
85
  export function inRole(role, route) {
85
86
  return ROUTE_ROLES[route]?.includes(role) ?? false;
@@ -2,7 +2,7 @@ import type HyperDB from 'hyperdb';
2
2
  import type { Router } from '../../../spec/mesh/hyperdispatch/index.js';
3
3
  import type { QvacAppendChunkOperation, QvacChunk } from '../../../spec/mesh/hyperschema/types.d.ts';
4
4
  import type { RouterContext } from './types.ts';
5
- export declare const TERMINAL_RUN_STATES: Set<string>;
5
+ export declare const TERMINAL_RUN_STATES: ReadonlySet<string>;
6
6
  export declare function runHasTerminalStatus(tx: HyperDB, chatId: string, runId: string): Promise<boolean>;
7
7
  export declare function runnerRefusal(op: QvacAppendChunkOperation, { tx, node }: RouterContext): Promise<string | null>;
8
8
  export declare function runTaker(tx: HyperDB, request: QvacChunk, writerKey: Buffer): Promise<Buffer | null>;
@@ -1,21 +1,27 @@
1
1
  import b4a from 'b4a';
2
2
  import { liveDeviceForWriter, trackActivity } from './activity.js';
3
+ import { putChunk } from './chat.js';
3
4
  import { ownerSigner } from './model-requests.js';
4
- import { chunkTypeOrdinal } from '../../../schema/indexes.js';
5
- import { CHUNKS, CHUNKS_BY_TYPE, DEVICES } from '../collections.js';
6
- export const TERMINAL_RUN_STATES = new Set(['completed', 'failed', 'canceled']);
5
+ import { WORKSPACES_RULES, rulesVersion } from './mesh-rules.js';
6
+ import { chunkTypeOrdinal, terminalRunStates } from '../../../schema/indexes.js';
7
+ import { CHUNKS, CHUNKS_BY_TYPE, DEVICES, TERMINAL_RUN_STATUSES } from '../collections.js';
8
+ export const TERMINAL_RUN_STATES = new Set(terminalRunStates);
7
9
  export async function runHasTerminalStatus(tx, chatId, runId) {
8
- const type = chunkTypeOrdinal('run-status');
9
- const statuses = tx.find(CHUNKS_BY_TYPE, {
10
- gte: { chatId, type },
11
- lte: { chatId, type }
12
- });
13
- for await (const chunk of statuses) {
14
- if (chunk.runId === runId && TERMINAL_RUN_STATES.has(chunk.runStatus?.state ?? '')) {
15
- return true;
10
+ if ((await rulesVersion(tx)) < WORKSPACES_RULES) {
11
+ const type = chunkTypeOrdinal('run-status');
12
+ const statuses = tx.find(CHUNKS_BY_TYPE, {
13
+ gte: { chatId, type },
14
+ lte: { chatId, type }
15
+ });
16
+ for await (const chunk of statuses) {
17
+ if (chunk.runId === runId && TERMINAL_RUN_STATES.has(chunk.runStatus?.state ?? '')) {
18
+ return true;
19
+ }
16
20
  }
21
+ return false;
17
22
  }
18
- return false;
23
+ const range = { gte: { chatId, runId }, lte: { chatId, runId } };
24
+ return (await tx.findOne(TERMINAL_RUN_STATUSES, range)) !== null;
19
25
  }
20
26
  export async function runnerRefusal(op, { tx, node }) {
21
27
  if (!op.runnerDeviceId) {
@@ -69,7 +75,7 @@ export function registerRunRequestRoutes(router) {
69
75
  runTakenAt: op.at,
70
76
  updatedAt: Math.max(request.updatedAt ?? 0, op.at)
71
77
  };
72
- await tx.insert(CHUNKS, taken);
78
+ await putChunk(tx, taken);
73
79
  return taken;
74
80
  }));
75
81
  }
@@ -0,0 +1,2 @@
1
+ import type HyperDB from 'hyperdb';
2
+ export declare function reindexShippedRows(tx: HyperDB): Promise<void>;
@@ -0,0 +1,22 @@
1
+ import { chunkTypeOrdinal } from '../../../schema/indexes.js';
2
+ import { CHUNK_COUNTERS, CHUNKS, CHUNKS_BY_TYPE, DEVICES } from '../collections.js';
3
+ export async function reindexShippedRows(tx) {
4
+ const devices = await tx.find(DEVICES).toArray();
5
+ for (const device of devices) {
6
+ await tx.insert(DEVICES, { ...device, version: undefined });
7
+ }
8
+ const statuses = [];
9
+ for await (const chunk of runStatuses(tx)) {
10
+ statuses.push(chunk);
11
+ }
12
+ for (const chunk of statuses) {
13
+ await tx.insert(CHUNKS, { ...chunk, version: undefined });
14
+ }
15
+ }
16
+ async function* runStatuses(db) {
17
+ const type = chunkTypeOrdinal('run-status');
18
+ for await (const { chatId } of db.find(CHUNK_COUNTERS)) {
19
+ const range = { gte: { chatId, type }, lte: { chatId, type } };
20
+ yield* db.find(CHUNKS_BY_TYPE, range);
21
+ }
22
+ }
@@ -1,4 +1,4 @@
1
- import { liveDeviceForWriter, trackActivity } from './activity.js';
1
+ import { liveDeviceForWriter, liveDevices, liveDevicesOf, trackActivity } from './activity.js';
2
2
  import { meshKind } from './mesh-kind.js';
3
3
  import { WORKSPACES_RULES, bornUnderRules, rulesVersion } from './mesh-rules.js';
4
4
  import b4a from 'b4a';
@@ -52,8 +52,8 @@ function ownerOf(device) {
52
52
  }
53
53
  export async function liveMemberIds(tx) {
54
54
  const live = new Set();
55
- for await (const device of tx.find(DEVICES)) {
56
- const owner = device.revoked ? null : ownerOf(device);
55
+ for await (const device of liveDevices(tx)) {
56
+ const owner = ownerOf(device);
57
57
  if (owner) {
58
58
  live.add(b4a.toHex(owner));
59
59
  }
@@ -100,13 +100,7 @@ export async function adminsLastDevice(tx, device) {
100
100
  if (device.revoked || !owner || (await memberRole(tx, owner)) !== 'admin') {
101
101
  return false;
102
102
  }
103
- for await (const other of tx.find(DEVICES)) {
104
- const theirs = ownerOf(other);
105
- if (!other.revoked && theirs && b4a.equals(theirs, owner) && !b4a.equals(other.id, device.id)) {
106
- return false;
107
- }
108
- }
109
- return true;
103
+ return (await liveDevicesOf(tx, owner)).every((other) => b4a.equals(other.id, device.id));
110
104
  }
111
105
  export async function leavesNoAdmin(context, memberId) {
112
106
  if (!(await isWorkspace(context.tx))) {
@@ -251,7 +245,7 @@ async function putMemberKey(op, context) {
251
245
  await tx.insert(MEMBER_KEYS, row);
252
246
  return row;
253
247
  }
254
- async function upgradeToWorkspace({ upgradedAt }, context) {
248
+ async function upgradeToWorkspace(_op, context) {
255
249
  const { tx, log } = context;
256
250
  const kind = await meshKind(tx);
257
251
  const onRules = (await rulesVersion(tx)) >= WORKSPACES_RULES;
@@ -276,7 +270,7 @@ async function upgradeToWorkspace({ upgradedAt }, context) {
276
270
  }
277
271
  }
278
272
  await tx.insert(MESH_KINDS, { id: 'mesh', kind: 'workspace' });
279
- const row = { id: WORKSPACE_ROW, updatedAt: upgradedAt, upgradeMemberIds };
273
+ const row = { id: WORKSPACE_ROW, updatedAt: 0, upgradeMemberIds };
280
274
  await tx.insert(WORKSPACE, row);
281
275
  log?.info('contract', 'shared mesh upgraded to a workspace');
282
276
  return row;
@@ -1,5 +1,5 @@
1
1
  import crypto from 'hypercore-crypto';
2
- import { devicesByWriterKey, liveDeviceForWriter, markWriterRevoked, trackActivity } from './activity.js';
2
+ import { devicesByWriterKey, devicesOfMember, liveDeviceForWriter, markWriterRevoked, trackActivity } from './activity.js';
3
3
  import { recordMemberRemoval } from './grant-order.js';
4
4
  import { verifyMemberWriterClaim, verifyWriterClaim } from '../device-attestation.js';
5
5
  import { meshKind, sharedKind } from './mesh-kind.js';
@@ -14,6 +14,7 @@ import { dropHostRows, hostedDevice, releaseHostedDevice } from './agent-join.js
14
14
  import { actsFor, dropRole, kicksAdminsLastDevice, leavesNoAdmin, uncountMember } from './workspace.js';
15
15
  import { verifyDeviceProof } from '../identity.js';
16
16
  import { sealed } from './seal.js';
17
+ import { WORKSPACES_RULES, rulesVersion } from './mesh-rules.js';
17
18
  import b4a from 'b4a';
18
19
  import { DEVICES, MEMBERS, MESH_INVITE_GRANTS, PROJECT_MEMBERS } from '../collections.js';
19
20
  async function boundToAnother(tx, writerKey, id) {
@@ -186,6 +187,19 @@ async function revokeWriter(payload, context) {
186
187
  }
187
188
  return revoked;
188
189
  }
190
+ async function ownLeave({ writerKey, deviceId, revokedAt }, { tx, node }) {
191
+ if (!b4a.equals(node.key, writerKey) || !deviceId) {
192
+ return false;
193
+ }
194
+ if ((await rulesVersion(tx)) < WORKSPACES_RULES) {
195
+ return false;
196
+ }
197
+ const device = await tx.get(DEVICES, { id: deviceId });
198
+ if (!device?.writerKey || !b4a.equals(device.writerKey, writerKey)) {
199
+ return false;
200
+ }
201
+ return device.joinedAt <= (revokedAt ?? 0);
202
+ }
189
203
  export function registerWriterRoutes(router) {
190
204
  router.add('@qvac/add-writer', trackActivity(async (payload, context) => {
191
205
  if (await meshKind(context.tx)) {
@@ -219,6 +233,10 @@ export function registerWriterRoutes(router) {
219
233
  return payload.device;
220
234
  }));
221
235
  router.add('@qvac/remove-writer', trackActivity(async (payload, context) => {
236
+ if (context.node.optimistic && !(await ownLeave(payload, context))) {
237
+ context.log?.warn('contract', 'remove-writer dropped: its author is not a writer here');
238
+ return;
239
+ }
222
240
  const self = b4a.equals(context.node.key, payload.writerKey);
223
241
  if (!self && !(await hasStanding(context))) {
224
242
  context.log?.warn('contract', 'remove-writer dropped: the author speaks for no member here');
@@ -256,11 +274,7 @@ export function registerWriterRoutes(router) {
256
274
  await context.tx.delete(PROJECT_MEMBERS, { memberId });
257
275
  const removals = [];
258
276
  const devices = [];
259
- for await (const device of context.tx.find(DEVICES)) {
260
- const claims = device.memberId ?? device.claimedMemberId;
261
- if (!claims || !b4a.equals(claims, memberId)) {
262
- continue;
263
- }
277
+ for (const device of await devicesOfMember(context.tx, memberId)) {
264
278
  devices.push(device.id);
265
279
  if (!device.revoked && device.writerKey) {
266
280
  removals.push({ writerKey: device.writerKey, deviceId: device.id, revokedAt });
@@ -0,0 +1,7 @@
1
+ import type { QvacChunk } from '../../spec/mesh/hyperschema/types.d.ts';
2
+ import type { Mesh } from './mesh.ts';
3
+ export interface LandedRuns {
4
+ readonly requests: QvacChunk[];
5
+ readonly deletedAgents: Set<string>;
6
+ }
7
+ export declare function cancelDeletedAgentRuns(mesh: Mesh, deviceId: Buffer, landed: LandedRuns | null): Promise<void>;
@@ -0,0 +1,46 @@
1
+ import { AGENT_DELETED, cancelActiveRuns } from './chat.js';
2
+ import { AGENTS, CHATS, RUN_REQUESTS } from './collections.js';
3
+ import { runHasTerminalStatus } from './contract/run-requests.js';
4
+ export async function cancelDeletedAgentRuns(mesh, deviceId, landed) {
5
+ const deleted = landed ? await deletedOf(mesh, landed) : await allDeleted(mesh);
6
+ if (deleted.size === 0) {
7
+ return;
8
+ }
9
+ const requests = landed && landed.deletedAgents.size === 0
10
+ ? landed.requests
11
+ : await mesh.view.find(RUN_REQUESTS).toArray();
12
+ const chats = new Set();
13
+ for (const { chatId, runId, runRequest } of requests) {
14
+ const asked = runId && deleted.has(runRequest?.agentId ?? '');
15
+ if (asked && !(await runHasTerminalStatus(mesh.view, chatId, runId))) {
16
+ chats.add(chatId);
17
+ }
18
+ }
19
+ for (const chatId of chats) {
20
+ if (mesh.closing || !mesh.writable)
21
+ return;
22
+ const chat = await mesh.view.get(CHATS, { id: chatId });
23
+ if (chat && !chat.deletedAt && deleted.has(chat.agentId)) {
24
+ await cancelActiveRuns(mesh, chatId, {
25
+ deviceId,
26
+ agentId: chat.agentId,
27
+ reason: AGENT_DELETED
28
+ });
29
+ }
30
+ }
31
+ }
32
+ async function deletedOf(mesh, { requests, deletedAgents }) {
33
+ const deleted = new Set(deletedAgents);
34
+ const asked = new Set(requests.map((r) => r.runRequest?.agentId).filter((id) => !!id));
35
+ for (const id of asked) {
36
+ const agent = await mesh.view.get(AGENTS, { id });
37
+ if (agent?.deletedAt) {
38
+ deleted.add(id);
39
+ }
40
+ }
41
+ return deleted;
42
+ }
43
+ async function allDeleted(mesh) {
44
+ const agents = await mesh.view.find(AGENTS).toArray();
45
+ return new Set(agents.filter((agent) => agent.deletedAt).map((agent) => agent.id));
46
+ }
@@ -1,4 +1,4 @@
1
- import type { QvacToolReportEntry } from '../../spec/mesh/hyperschema/types.d.ts';
1
+ import type { QvacCustomModelReportEntry, QvacToolReportEntry } from '../../spec/mesh/hyperschema/types.d.ts';
2
2
  import type { AppBuildMetadata } from './app-build.ts';
3
3
  import type { Mesh } from './mesh.ts';
4
4
  export interface SaveDeviceCapabilitiesInput {
@@ -9,6 +9,7 @@ export interface SaveDeviceCapabilitiesInput {
9
9
  cachedModelNames: string[];
10
10
  readySkillNames?: string[] | null;
11
11
  toolCatalog?: QvacToolReportEntry[] | null;
12
+ customModels?: QvacCustomModelReportEntry[] | null;
12
13
  }
13
14
  export declare function saveDeviceCapabilities(store: Mesh, input: SaveDeviceCapabilitiesInput, isAccount: (mesh: Mesh) => boolean): Promise<void>;
14
15
  export declare function retractInventory(store: Mesh, deviceId: Buffer, isAccount: (mesh: Mesh) => boolean): Promise<void>;
@@ -32,7 +32,8 @@ export async function retractInventory(store, deviceId, isAccount) {
32
32
  row.installedSkillNames,
33
33
  row.installedModelNames,
34
34
  row.cachedModelNames,
35
- row.toolCatalog
35
+ row.toolCatalog,
36
+ row.customModels
36
37
  ].some((list) => list?.length) ||
37
38
  (row.readySkillNames?.length ?? 0) > (trimmed.readySkillNames?.length ?? 0);
38
39
  if (leaked) {
@@ -48,7 +49,8 @@ async function hostedOnly(store, input) {
48
49
  installedModelNames: [],
49
50
  cachedModelNames: [],
50
51
  readySkillNames: readinessForAgents(input.readySkillNames ?? [], hosted),
51
- toolCatalog: []
52
+ toolCatalog: [],
53
+ customModels: []
52
54
  };
53
55
  }
54
56
  export async function advertiseDeviceVersion(store, deviceId, app) {
@@ -25,11 +25,14 @@ export declare function documentUnreadReason({ knowledgeOn, failedFiles, attache
25
25
  export declare function documentUnreadNotice(reason: DocumentUnreadReason, plural: boolean): string;
26
26
  export interface PdfPagesCutState {
27
27
  readonly fileName: string;
28
- readonly lastPage: number;
28
+ readonly cutAt: number;
29
29
  readonly pageCount: number;
30
+ readonly shown: number;
31
+ readonly wholeText: boolean;
30
32
  }
31
- export declare function pdfPagesCutNotice({ fileName, lastPage, pageCount }: PdfPagesCutState): string;
32
- export declare function pdfPagesSkippedNotice(fileName: string): string;
33
+ export declare function pdfPagesCutNotice({ fileName, cutAt, pageCount, shown, wholeText }: PdfPagesCutState): string;
34
+ export declare const PDF_PAGES_SOURCE_LINE = "Page images from the PDFs in this chat are a source too: when an image shows what the excerpts do not, answer from the image.";
35
+ export declare function pdfPagesShownNotice(fileName: string, labels: ReadonlyArray<string>): string;
33
36
  export interface AnnotatedMessage {
34
37
  content: string;
35
38
  documents?: DocumentAttachment[];
@@ -33,11 +33,16 @@ export function documentUnreadNotice(reason, plural) {
33
33
  }[reason];
34
34
  return `[The attached document${plural ? 's' : ''} could not be read for this reply: ${why}.]`;
35
35
  }
36
- export function pdfPagesCutNotice({ fileName, lastPage, pageCount }) {
37
- return `[Only pages 1–${lastPage} of "${fileName}" (${pageCount} pages) were shown to you as images; pages ${lastPage + 1}–${pageCount} were not, and no tool can show them. If asked about a later page you have no excerpt for, tell the user only the first ${lastPage} pages could be read. Do not guess its content.]`;
38
- }
39
- export function pdfPagesSkippedNotice(fileName) {
40
- return `[No page of "${fileName}" was shown to you as an image: the files before it in this message used up the page images, and no tool can show them. If asked about it and you have no excerpt, tell the user it could not be read. Do not guess its content.]`;
36
+ export function pdfPagesCutNotice({ fileName, cutAt, pageCount, shown, wholeText }) {
37
+ const missing = shown
38
+ ? `Some pictures in "${fileName}" (${pageCount} pages), the first on page ${cutAt + 1}, were not shown to you as images`
39
+ : `No picture in "${fileName}" (${pageCount} pages) was shown to you as an image`;
40
+ const text = wholeText ? '; its text is all above' : '';
41
+ return `[${missing}: they did not fit in the context window, and no tool can show them${text}. If asked about a picture you cannot see, say it could not be shown. Do not guess its content.]`;
42
+ }
43
+ export const PDF_PAGES_SOURCE_LINE = 'Page images from the PDFs in this chat are a source too: when an image shows what the excerpts do not, answer from the image.';
44
+ export function pdfPagesShownNotice(fileName, labels) {
45
+ return `[The images from "${fileName}" are, in order: ${labels.join('; ')}.]`;
41
46
  }
42
47
  export function annotateDocumentAttachments(messages) {
43
48
  for (const turn of messages.filter((message) => message.documents?.length)) {