@tangle-network/agent-app 0.60.237 → 0.60.239

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.
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  ReasoningRow,
3
3
  chatToolCallPart
4
- } from "../chunk-BGDQ7245.js";
4
+ } from "../chunk-2UIRJPC6.js";
5
5
  import "../chunk-3HUFJ5LO.js";
6
6
  import "../chunk-BDEBQ4WO.js";
7
7
  import "../chunk-FBVLEGEG.js";
@@ -33,7 +33,7 @@ import "../chunk-VBRUG4N5.js";
33
33
  import "../chunk-B7CL7ENS.js";
34
34
  import "../chunk-PV33JZKV.js";
35
35
  import "../chunk-AMUXRAUO.js";
36
- import "../chunk-E6UTFXKQ.js";
36
+ import "../chunk-PYG2N2JX.js";
37
37
  import "../chunk-ZVEEWGDK.js";
38
38
  import "../chunk-YHRWZZJN.js";
39
39
  import "../chunk-TXD5HXLE.js";
@@ -5,14 +5,17 @@
5
5
  * default implementation — agent-app owns the size/budget/idempotency
6
6
  * mechanism, the product owns where the bytes actually live.
7
7
  *
8
- * One reader, two callers: `resolveChatAttachments` reads only the
8
+ * One reader serves validation, materialization, and dispatch:
9
+ * `resolveChatAttachments` reads only the
9
10
  * authoritative `size` (never trusting the client-reported size), while
10
11
  * `buildDispatchParts` reads the inline `content` (base64 or raw bytes) to
11
- * build a `data:` URI. Both fit behind ONE `ReadAttachmentFn` so a product
12
+ * build a `data:` URI. `prepareDispatchAttachments` copies raw bytes when a
13
+ * product opts in. All share `ReadAttachmentFn` so a product
12
14
  * wires a single vault/object-store adapter, not two. gtm's KV vault (stores
13
15
  * base64 bodies) and `/object-store`'s `ObjectStore` (hands back raw bytes)
14
16
  * both satisfy this shape.
15
17
  */
18
+ import type { ChatAttachmentPart } from '../chat-store/parts';
16
19
  /**
17
20
  * The result of reading one stored attachment. `ok:true` MUST carry the
18
21
  * authoritative decoded byte `size` (the cap is meaningless against a
@@ -46,6 +49,29 @@ export type AttachmentReadResult = {
46
49
  * turn-level exception.
47
50
  */
48
51
  export type ReadAttachmentFn = (scopeId: string, path: string) => Promise<AttachmentReadResult>;
52
+ /** Opt-in copy from the product attachment store to its already-authorized box.
53
+ * Uploads are sequential and their returned byte counts must match the store.
54
+ * The product retains its missing-content sentence and the surrounding trace span. */
55
+ export interface AttachmentMaterialization {
56
+ upload: (absolutePath: string, bytes: Uint8Array) => Promise<{
57
+ size: number;
58
+ }>;
59
+ missingBytesMessage: (path: string) => string;
60
+ }
61
+ /** Prepare carried files before a product constructs its prompt and dispatch input. */
62
+ export interface PrepareDispatchAttachmentsInput {
63
+ attachments: ChatAttachmentPart[];
64
+ historyAttachments?: readonly ChatAttachmentPart[];
65
+ mentionCount?: number;
66
+ scopeId: string;
67
+ readAttachment: ReadAttachmentFn;
68
+ resolveAttachmentPath: (path: string) => string;
69
+ materialize?: AttachmentMaterialization;
70
+ }
71
+ /** Select carried files and optionally copy them before constructing a prompt.
72
+ * Omitted history and materialization preserve the supplied attachment list.
73
+ * `slice(-0)` intentionally retains the apps' current zero-slot behavior. */
74
+ export declare function prepareDispatchAttachments(input: PrepareDispatchAttachmentsInput): Promise<ChatAttachmentPart[]>;
49
75
  /** The ownership identity for one attempted write. The upload and promotion
50
76
  * routes create a unique path for each attempt, and the product adapter stores
51
77
  * this id with it. */
@@ -22,7 +22,7 @@
22
22
  import { type PromptInputPart } from '../sandbox';
23
23
  import { type SandboxExecChannel } from '../sandbox/binary-read';
24
24
  import { type ChatTurnPartInput } from './wire';
25
- import type { ChatAttachmentPart, ChatMentionPart } from '../chat-store/parts';
25
+ import { type ChatAttachmentPart, type ChatMentionPart } from '../chat-store/parts';
26
26
  import type { ReadAttachmentFn } from './attachment-store';
27
27
  export type { PromptInputPart };
28
28
  /** Resolve the outcome of dispatching parts with success status and corresponding value or error message */
@@ -55,6 +55,17 @@ export type ReadSandboxMentionFn = (box: SandboxExecChannel, absolutePath: strin
55
55
  * filename and URL.
56
56
  */
57
57
  export declare function normalizeChatPromptForSandbox(prompt: string | readonly ChatTurnPartInput[]): string | PromptInputPart[];
58
+ /** A persisted message whose attachment pointers accompany its history text. */
59
+ export interface DispatchHistoryMessage {
60
+ role: string;
61
+ content: string;
62
+ parts?: ReadonlyArray<Record<string, unknown>> | null;
63
+ }
64
+ /** Project persisted rows using the same role and attachment policy as dispatch. */
65
+ export declare function projectDispatchHistory(messages: ReadonlyArray<DispatchHistoryMessage>): Array<{
66
+ role: 'user' | 'assistant';
67
+ content: string;
68
+ }>;
58
69
  /** Build input parameters for dispatching chat message parts including text, attachments, mentions, and history */
59
70
  export interface BuildDispatchPartsInput {
60
71
  text: string;
@@ -43,7 +43,7 @@ import {
43
43
  flattenHistory,
44
44
  readSandboxBinaryBytes,
45
45
  statSandboxFileSize
46
- } from "../chunk-K7SKQ7GY.js";
46
+ } from "../chunk-GNWGP3PA.js";
47
47
  import "../chunk-4LBCTFBP.js";
48
48
  import {
49
49
  ModelFailoverExhaustedError,
@@ -83,7 +83,7 @@ import {
83
83
  rowIdOf,
84
84
  storeSupportsDraftPersistence,
85
85
  streamChatRouteAsSandboxEvents
86
- } from "../chunk-MX3RI3MO.js";
86
+ } from "../chunk-QW6PFYJS.js";
87
87
  import "../chunk-TCGZFSN5.js";
88
88
  import "../chunk-FENBDSIW.js";
89
89
  import "../chunk-RN4WPTBH.js";
@@ -98,8 +98,9 @@ import "../chunk-MM6RLOXF.js";
98
98
  import {
99
99
  attachmentInputToPart,
100
100
  attachmentKindForMime,
101
+ historyContentWithAttachments,
101
102
  toChatMessageParts
102
- } from "../chunk-E6UTFXKQ.js";
103
+ } from "../chunk-PYG2N2JX.js";
103
104
  import "../chunk-ZVEEWGDK.js";
104
105
  import {
105
106
  ChatTurnInputError,
@@ -1351,7 +1352,7 @@ function createRouterTurnProducer(options) {
1351
1352
  }
1352
1353
 
1353
1354
  // src/chat-routes/hybrid-producer.ts
1354
- var HYBRID_TURN_GUIDANCE = "Start your reply with text: before your first tool call, write one short sentence telling the member what you are about to do, so they never wait in silence. Use sandbox_run only for work that needs code execution or files on the workspace computer; describe the whole task in it and report what it returns.";
1355
+ var HYBRID_TURN_GUIDANCE = "Start your reply with text: before your first tool call, write one short sentence telling the member what you are about to do, so they never wait in silence. Use sandbox_run only for work that needs code execution or files on the workspace computer. Give the sandbox agent the member's requirements, paths and exact field names, not model-written code; the sandbox agent writes and runs the code. Report what it returns.";
1355
1356
  var DEFAULT_SANDBOX_RUN_TIMEOUT_MS = 4 * 6e4;
1356
1357
  function startHybridBox(body, acquire) {
1357
1358
  const attachments = (body.parts ?? []).map((part) => ({
@@ -1389,6 +1390,7 @@ function createHybridTurnProducer(options) {
1389
1390
  const sandboxRun = createSandboxRunTool({
1390
1391
  box: () => acquire(),
1391
1392
  runTask: box.runTask,
1393
+ memberRequest: router.userMessage,
1392
1394
  timeoutMs,
1393
1395
  signal: stop,
1394
1396
  ...box.warm ? { warm: box.warm } : {},
@@ -2572,6 +2574,36 @@ function createUploadRoute(options) {
2572
2574
  }
2573
2575
 
2574
2576
  // src/chat-routes/attachment-store.ts
2577
+ async function prepareDispatchAttachments(input) {
2578
+ const historyBudget = Math.max(
2579
+ 0,
2580
+ DISPATCH_MAX_MEDIA_PARTS - input.attachments.length - (input.mentionCount ?? 0)
2581
+ );
2582
+ const attachments = input.historyAttachments === void 0 ? input.attachments : [
2583
+ ...input.attachments,
2584
+ ...input.historyAttachments.slice(-historyBudget)
2585
+ ];
2586
+ const materialize = input.materialize;
2587
+ if (!materialize) return attachments;
2588
+ const written = /* @__PURE__ */ new Set();
2589
+ for (const part of attachments) {
2590
+ const target = input.resolveAttachmentPath(part.path);
2591
+ if (written.has(target)) continue;
2592
+ written.add(target);
2593
+ const read = await input.readAttachment(input.scopeId, part.path);
2594
+ if (!read.ok) throw new Error(read.reason);
2595
+ if (!read.bytes) {
2596
+ throw new Error(materialize.missingBytesMessage(part.path));
2597
+ }
2598
+ const result = await materialize.upload(target, read.bytes);
2599
+ if (result.size !== read.size) {
2600
+ throw new Error(
2601
+ `Sandbox attachment size mismatch for ${part.path}: expected ${read.size}, uploaded ${result.size}`
2602
+ );
2603
+ }
2604
+ }
2605
+ return attachments;
2606
+ }
2575
2607
  var ATTACHMENT_STORAGE_FAILURE_MESSAGE = "Attachment storage is temporarily unavailable. Please try again.";
2576
2608
  var ATTACHMENT_ROLLBACK_FAILURE_CODE = "rollback_failed";
2577
2609
  var ATTACHMENT_ROLLBACK_FAILURE_MESSAGE = "Attachment cleanup failed. Please try again.";
@@ -3611,6 +3643,12 @@ function normalizeChatPromptForSandbox(prompt) {
3611
3643
  };
3612
3644
  });
3613
3645
  }
3646
+ function projectDispatchHistory(messages) {
3647
+ return messages.map((message) => ({
3648
+ role: message.role === "assistant" ? "assistant" : "user",
3649
+ content: historyContentWithAttachments(message)
3650
+ }));
3651
+ }
3614
3652
  function readResultToBase64(read) {
3615
3653
  if (typeof read.base64 === "string") return read.base64;
3616
3654
  if (read.bytes) return bytesToBase64(read.bytes);
@@ -3954,7 +3992,9 @@ export {
3954
3992
  parseFileMentions,
3955
3993
  parsePlanFollowUpAttach,
3956
3994
  planFollowUpExecutionId,
3995
+ prepareDispatchAttachments,
3957
3996
  produceChatTurnWithIntelligence,
3997
+ projectDispatchHistory,
3958
3998
  promoteAgentFilePart,
3959
3999
  promptPartsByteSize,
3960
4000
  readCompletedSandboxTurn,