@teaflask/assistant 0.7.1 → 0.9.0

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 (62) hide show
  1. package/README.md +1 -1
  2. package/dist/components/assistant-transcript.js +1 -7
  3. package/dist/components/attachment-chips.js +11 -5
  4. package/dist/components/composer.js +5 -6
  5. package/dist/components/message-list.js +2 -1
  6. package/dist/components/open-minted-url.js +12 -0
  7. package/dist/components/primitives/button.js +3 -0
  8. package/dist/components/tool-call-rows.js +1 -8
  9. package/dist/components/tool-row.js +1 -2
  10. package/dist/components/tool-view-slot.js +0 -1
  11. package/dist/components/tool-views/action-values.js +43 -0
  12. package/dist/components/tool-views/action-view.js +6 -42
  13. package/dist/components/tool-views/graphql-action-view.js +95 -0
  14. package/dist/components/tool-views/view-dom.d.ts +3 -4
  15. package/dist/components/tool-views/view-dom.js +1 -4
  16. package/dist/components/transcript-follow.js +12 -0
  17. package/dist/components/use-child-replay-stream.js +9 -2
  18. package/dist/components/use-transcript.d.ts +3 -2
  19. package/dist/components/user-message.js +26 -1
  20. package/dist/contract/actions-adapter.d.ts +42 -4
  21. package/dist/contract/events.d.ts +1 -0
  22. package/dist/contract/events.js +1 -0
  23. package/dist/contract/threads.d.ts +0 -5
  24. package/dist/contract/threads.js +0 -1
  25. package/dist/core/composer-policy.d.ts +1 -2
  26. package/dist/core/composer-policy.js +0 -2
  27. package/dist/core/connection-epoch.d.ts +1 -5
  28. package/dist/core/connection-epoch.js +23 -11
  29. package/dist/core/conversation-store.js +0 -1
  30. package/dist/core/epoch-sync.js +1 -1
  31. package/dist/core/error-copy.js +9 -1
  32. package/dist/core/long-message.js +22 -0
  33. package/dist/core/message-copy.js +1 -0
  34. package/dist/core/tool-call-display.d.ts +1 -7
  35. package/dist/core/tool-call-presentation.js +0 -3
  36. package/dist/core/tool-outcome.js +0 -1
  37. package/dist/core/tool-view.d.ts +2 -7
  38. package/dist/core/tool-view.js +2 -0
  39. package/dist/core/transcript-rows.d.ts +0 -6
  40. package/dist/core/transcript-rows.js +0 -3
  41. package/dist/core/withdrawn-anchors.d.ts +11 -0
  42. package/dist/core/withdrawn-anchors.js +76 -0
  43. package/dist/generated/models/apiErrorCode.d.ts +12 -0
  44. package/dist/generated/models/apiErrorCode.js +12 -0
  45. package/dist/generated/models/assistantStreamMarkerName.d.ts +1 -0
  46. package/dist/generated/models/assistantStreamMarkerName.js +1 -0
  47. package/dist/generated/models/index.d.ts +1 -0
  48. package/dist/generated/models/index.js +1 -0
  49. package/dist/generated/models/replyWithdrawnMarker.d.ts +4 -0
  50. package/dist/generated/models/replyWithdrawnMarker.js +1 -0
  51. package/dist/generated/models/servingErrorCode.d.ts +5 -4
  52. package/dist/generated/models/servingErrorCode.js +1 -0
  53. package/dist/headless.d.ts +1 -1
  54. package/dist/index.d.ts +2 -2
  55. package/dist/index.js +0 -1
  56. package/dist/styles.css +1 -1
  57. package/dist/transport/actions-adapter.js +83 -6
  58. package/dist/transport/replay-stream-agent.js +4 -0
  59. package/dist/transport/stream-resume.d.ts +4 -2
  60. package/dist/transport/stream-resume.js +4 -4
  61. package/package.json +1 -1
  62. package/dist/core/tool-offload-anchors.js +0 -7
@@ -1,9 +1,34 @@
1
1
  "use client";
2
2
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
3
+ import { useId, useRef, useState } from "react";
4
+ import { longMessagePreviewOf } from "../core/long-message.js";
3
5
  import { conversationalTimeOf } from "../core/time-labels.js";
4
6
  import { AttachmentChips } from "./attachment-chips.js";
5
7
  import { CopyTextButton } from "./copy-text-button.js";
8
+ import { TfButton } from "./primitives/button.js";
9
+ import { useReleaseTranscriptFollow } from "./transcript-follow.js";
6
10
  export function UserMessage({ children, attachments = [], createdAt, }) {
7
11
  const time = createdAt !== undefined ? conversationalTimeOf(createdAt) : null;
8
- return (_jsxs("div", { className: "tf:group/user-message tf:flex tf:flex-col tf:items-end tf:gap-2 tf:ps-20", "data-role": "user", children: [_jsx(AttachmentChips, { attachments: attachments }), children !== "" ? (_jsxs(_Fragment, { children: [_jsx("div", { className: "tf:min-w-0 tf:rounded-xl tf:bg-tf-muted tf:px-4 tf:py-2 tf:text-tf-body tf:break-words tf:whitespace-pre-wrap tf:text-tf-foreground", children: children }), _jsxs("div", { className: "tf:flex tf:h-7 tf:items-center tf:justify-end tf:gap-1", children: [time !== null ? (_jsx("time", { dateTime: createdAt, title: time.full, className: "tf:text-xs tf:text-tf-muted-foreground tf:opacity-0 tf:transition-opacity tf:group-hover/user-message:opacity-100 tf:group-focus-within/user-message:opacity-100 tf:pointer-coarse:opacity-100", children: time.label })) : null, _jsx(CopyTextButton, { text: children, label: "Copy message", className: "tf:opacity-0 tf:transition-opacity tf:group-hover/user-message:opacity-100 tf:group-focus-within/user-message:opacity-100 tf:focus-visible:opacity-100 tf:pointer-coarse:opacity-100" })] })] })) : null] }));
12
+ return (_jsxs("div", { className: "tf:group/user-message tf:flex tf:flex-col tf:items-end tf:gap-2 tf:ps-20", "data-role": "user", children: [_jsx(AttachmentChips, { attachments: attachments }), children !== "" ? (_jsxs(_Fragment, { children: [_jsx("div", { className: "tf:min-w-0 tf:rounded-xl tf:bg-tf-muted tf:px-4 tf:py-2 tf:text-tf-body tf:break-words tf:whitespace-pre-wrap tf:text-tf-foreground", children: _jsx(UserMessageText, { text: children }) }), _jsxs("div", { className: "tf:flex tf:h-7 tf:items-center tf:justify-end tf:gap-1", children: [time !== null ? (_jsx("time", { dateTime: createdAt, title: time.full, className: "tf:text-xs tf:text-tf-muted-foreground tf:opacity-0 tf:transition-opacity tf:group-hover/user-message:opacity-100 tf:group-focus-within/user-message:opacity-100 tf:pointer-coarse:opacity-100", children: time.label })) : null, _jsx(CopyTextButton, { text: children, label: "Copy message", className: "tf:opacity-0 tf:transition-opacity tf:group-hover/user-message:opacity-100 tf:group-focus-within/user-message:opacity-100 tf:focus-visible:opacity-100 tf:pointer-coarse:opacity-100" })] })] })) : null] }));
13
+ }
14
+ function UserMessageText({ text }) {
15
+ const preview = longMessagePreviewOf(text);
16
+ const [expanded, setExpanded] = useState(false);
17
+ const textId = useId();
18
+ const toggleRef = useRef(null);
19
+ const releaseFollow = useReleaseTranscriptFollow();
20
+ if (preview === null) {
21
+ return text;
22
+ }
23
+ return (_jsxs(_Fragment, { children: [_jsx("div", { id: textId, children: expanded ? text : `${preview}…` }), _jsx("div", { className: "tf:sticky tf:bottom-0 tf:bg-tf-muted tf:pt-1", children: _jsx(TfButton, { ref: toggleRef, variant: "bare", "aria-expanded": expanded, "aria-controls": textId, className: "tf:min-h-6 tf:text-tf-label tf:text-tf-muted-foreground tf:hover:text-tf-foreground", onClick: () => {
24
+ if (expanded) {
25
+ requestAnimationFrame(() => {
26
+ toggleRef.current?.scrollIntoView({ block: "nearest" });
27
+ });
28
+ }
29
+ else {
30
+ releaseFollow();
31
+ }
32
+ setExpanded(!expanded);
33
+ }, children: expanded ? "Show less" : "Show more" }) })] }));
9
34
  }
@@ -39,9 +39,41 @@ export interface ActionIntent {
39
39
  query: Record<string, unknown>;
40
40
  /**
41
41
  * The JSON request body; absent when the action sends none. The cookies and
42
- * headers adapters send it with Content-Type application/json.
42
+ * headers adapters send it with Content-Type application/json. For a
43
+ * GraphQL action it is the standard GraphQL request, {query, operationName,
44
+ * variables}.
43
45
  */
44
46
  body?: unknown;
47
+ /**
48
+ * Present when the action is an operation of your app's GraphQL API, so a
49
+ * request adapter can run it through your own GraphQL client; absent for
50
+ * every other action.
51
+ */
52
+ graphql?: ActionIntentGraphQL;
53
+ }
54
+ /**
55
+ * The GraphQL operation an action runs, one your app's own code defines. Run it
56
+ * through your app's GraphQL client. Looking it up by operationName among your
57
+ * app's own operations sends exactly the request your app sends; parsing
58
+ * document lets a client print it again, which a persisted-query allowlist may
59
+ * refuse.
60
+ */
61
+ export interface ActionIntentGraphQL {
62
+ /** The operation's name in your app's code, such as "RenamePost". */
63
+ operationName: string;
64
+ /** Whether the operation is a "query" or a "mutation". */
65
+ operationType: "query" | "mutation";
66
+ /**
67
+ * The operation's GraphQL document as found in your app's code, with every
68
+ * fragment it uses; a client that sends parsed documents, such as Apollo
69
+ * Client, can parse and run it.
70
+ */
71
+ document: string;
72
+ /**
73
+ * The operation's variables, already validated against the action's
74
+ * variables schema; empty when it takes none.
75
+ */
76
+ variables: Record<string, unknown>;
45
77
  }
46
78
  /**
47
79
  * For APIs authenticated by session cookies. The package fetches baseUrl plus
@@ -88,8 +120,10 @@ export interface RequestActionsAdapter {
88
120
  kind: "request";
89
121
  /**
90
122
  * Performs the request and resolves with your API's response body, which
91
- * the agent receives with status 200. Reject (for example by throwing on a
92
- * non-2xx response) to report the action as failed.
123
+ * the agent receives with status 200. For a GraphQL action, resolve the
124
+ * whole GraphQL response, {data, errors}, even when it carries errors.
125
+ * Reject (for example by throwing on a non-2xx response) to report the
126
+ * action as failed.
93
127
  */
94
128
  execute: (intent: ActionIntent) => Promise<unknown>;
95
129
  }
@@ -99,6 +133,10 @@ export interface RequestActionsAdapter {
99
133
  * actions and tells the user to do them. The response's status and body (parsed
100
134
  * as JSON, otherwise text) go back to the agent; a non-2xx status counts as
101
135
  * your API's answer, not a failure, and bodies over about 16,000 characters are
102
- * truncated.
136
+ * truncated. A GraphQL response that carries errors keeps all of them unless
137
+ * the errors alone exceed the limit: its other top-level fields such as
138
+ * extensions are dropped first, and its data is shortened only if it still does
139
+ * not fit. A GraphQL response without errors is truncated whole, like any other
140
+ * body.
103
141
  */
104
142
  export type ActionsAdapter = CookiesActionsAdapter | HeadersActionsAdapter | RequestActionsAdapter;
@@ -1,5 +1,6 @@
1
1
  import type { ApprovalRequestedMarker, ApprovalResolvedMarker, InterruptAnswerConsumedMarker, SubagentResultsDeliveredMarker, ToolExecutionRequestedMarker } from "../generated/models/index.js";
2
2
  export declare const RUN_RESUMED_EVENT_NAME: "run_resumed";
3
+ export declare const REPLY_WITHDRAWN_EVENT_NAME: "reply_withdrawn";
3
4
  export declare const APPROVAL_REQUESTED_EVENT_NAME: "approval_requested";
4
5
  export type ApprovalRequestedPayload = ApprovalRequestedMarker & Required<Pick<ApprovalRequestedMarker, "tool_args" | "tool_input_schema" | "tool_output_schema" | "round" | "gated" | "trust_available">>;
5
6
  export declare const APPROVAL_RESOLVED_EVENT_NAME: "approval_resolved";
@@ -1,5 +1,6 @@
1
1
  import { AssistantStreamMarkerName } from "../generated/models/index.js";
2
2
  export const RUN_RESUMED_EVENT_NAME = AssistantStreamMarkerName.run_resumed;
3
+ export const REPLY_WITHDRAWN_EVENT_NAME = AssistantStreamMarkerName.reply_withdrawn;
3
4
  export const APPROVAL_REQUESTED_EVENT_NAME = AssistantStreamMarkerName.approval_requested;
4
5
  export const APPROVAL_RESOLVED_EVENT_NAME = AssistantStreamMarkerName.approval_resolved;
5
6
  export const INTERRUPT_ANSWER_CONSUMED_EVENT_NAME = AssistantStreamMarkerName.interrupt_answer_consumed;
@@ -1,7 +1,2 @@
1
1
  export type { CreateServingAttachmentUploadResponse as AttachmentUploadIntent, HighlightResult, NavigateResult, PrefillFormResult, ReadPageResult, ResolveServingTurnApprovalRequest as ResolveTurnApprovalRequest, ResolveServingTurnApprovalResponse as ResolveTurnApprovalResponse, ResolveServingTurnToolResultsRequest as ResolveTurnToolResultsRequest, ResolveServingTurnToolResultsResponse as ResolveTurnToolResultsResponse, SendServingAssistantMessageRequest as SendAssistantMessageRequest, SendServingAssistantMessageResponse as SendAssistantMessageResponse, ServingAssistantThreadDetailResponse as AssistantThreadDetailResponse, ServingAssistantThreadResponse as ServingAssistantThread, ServingAssistantTurnResponse as ServingAssistantTurn, ServingAttachmentResponse as ServingAttachment, ServingTurnAttachmentResponse as TurnAttachment, StopServingTurnResponse as StopTurnResponse, ThreadModelPickResponse as ThreadModelPick, AssistantTurnStatus as TurnStatus, } from "../generated/models/index.js";
2
- /**
3
- * The longest message a user can send, in characters; the composer stops input
4
- * at this length and the server rejects longer messages.
5
- */
6
- export declare const ASSISTANT_MESSAGE_MAX_CHARS = 4000;
7
2
  export declare const ASSISTANT_MAX_ATTACHMENTS = 10;
@@ -1,2 +1 @@
1
- export const ASSISTANT_MESSAGE_MAX_CHARS = 4000;
2
1
  export const ASSISTANT_MAX_ATTACHMENTS = 10;
@@ -1,6 +1,5 @@
1
- import { type ServingAttachment } from "../contract/threads.js";
1
+ import type { ServingAttachment } from "../contract/threads.js";
2
2
  import type { AttachmentKind } from "../generated/models/index.js";
3
- export declare const CHARACTER_COUNT_VISIBLE_FROM: number;
4
3
  /** One file staged in the composer for the next message. */
5
4
  export interface AttachmentDraft<A = ServingAttachment> {
6
5
  /**
@@ -1,5 +1,3 @@
1
- import { ASSISTANT_MESSAGE_MAX_CHARS, } from "../contract/threads.js";
2
- export const CHARACTER_COUNT_VISIBLE_FROM = ASSISTANT_MESSAGE_MAX_CHARS - 400;
3
1
  let nextDraftId = 1;
4
2
  export function mintAttachmentDraftId() {
5
3
  return nextDraftId++;
@@ -49,11 +49,6 @@ export interface TranscriptMarkers {
49
49
  * The tool's explanation for each call it declined, keyed by tool call id.
50
50
  */
51
51
  toolRefusalAnchors: ReadonlyMap<string, string>;
52
- /**
53
- * Ids of tool calls whose output was too large and was replaced by a
54
- * shortened stand-in.
55
- */
56
- toolOffloadAnchors: ReadonlySet<string>;
57
52
  /**
58
53
  * Ids of tool calls the user was asked to approve or answer a question for.
59
54
  * Treat a missing set as empty.
@@ -123,6 +118,7 @@ export interface ConnectionEpoch {
123
118
  threadId: string;
124
119
  streamThreadId: string;
125
120
  withExecutionInbox: (mutate: (inbox: ExecutionInbox) => boolean) => void;
121
+ visibleMessages: () => readonly Message[];
126
122
  dispose: () => void;
127
123
  }
128
124
  export declare function beginConnectionEpoch(deps: ConnectionEpochDeps): ConnectionEpoch;
@@ -14,11 +14,11 @@ import { toolCancelRecorder, wellFormedToolCancelAnchorsOf, } from "./tool-cance
14
14
  import { toolErrorRecorder, wellFormedToolErrorAnchorsOf, } from "./tool-error-anchors.js";
15
15
  import { toolDecisionRecorder, wellFormedToolDecisionAnchorsOf, } from "./tool-decision-anchors.js";
16
16
  import { toolDenialRecorder, wellFormedToolDenialAnchorsOf, } from "./tool-denial-anchors.js";
17
- import { toolOffloadRecorder, wellFormedToolOffloadAnchorsOf, } from "./tool-offload-anchors.js";
18
17
  import { toolRefusalRecorder, wellFormedToolRefusalAnchorsOf, } from "./tool-refusal-anchors.js";
19
18
  import { turnFailedMarkerRecorder, wellFormedFailAnchorsOf, } from "./turn-failed-anchors.js";
20
19
  import { turnUsageRecorder, wellFormedTurnUsageAnchorsOf, } from "./turn-usage-anchors.js";
21
20
  import { messagesRecorder, streamErrorRecorder } from "./messages-cell.js";
21
+ import { withdrawnReplyRecorder, withoutWithdrawnReplies, } from "./withdrawn-anchors.js";
22
22
  import { userTurnInjector } from "./user-turn-ledger.js";
23
23
  export function markerAnchorsOf(resume) {
24
24
  return {
@@ -28,7 +28,6 @@ export function markerAnchorsOf(resume) {
28
28
  toolErrorAnchors: wellFormedToolErrorAnchorsOf(resume.toolErrorAnchors),
29
29
  toolCancelAnchors: wellFormedToolCancelAnchorsOf(resume.toolCancelAnchors),
30
30
  toolRefusalAnchors: wellFormedToolRefusalAnchorsOf(resume.toolRefusalAnchors),
31
- toolOffloadAnchors: wellFormedToolOffloadAnchorsOf(resume.toolOffloadAnchors),
32
31
  toolDecisionAnchors: wellFormedToolDecisionAnchorsOf(resume.toolDecisionAnchors),
33
32
  toolDenialAnchors: wellFormedToolDenialAnchorsOf(resume.toolDenialLedger.denied),
34
33
  toolCallDisplayAnchors: wellFormedToolCallDisplayAnchorsOf(resume.toolCallDisplayAnchors),
@@ -83,6 +82,7 @@ export function beginConnectionEpoch(deps) {
83
82
  publishEntries(executionInbox.entries());
84
83
  }
85
84
  },
85
+ visibleMessages: () => _visibleMessagesOf(agent, deps),
86
86
  dispose: () => {
87
87
  for (const subscription of subscriptions) {
88
88
  subscription.unsubscribe();
@@ -92,6 +92,9 @@ export function beginConnectionEpoch(deps) {
92
92
  },
93
93
  };
94
94
  }
95
+ function _visibleMessagesOf(agent, deps) {
96
+ return withoutWithdrawnReplies([...agent.messages], deps.resume.withdrawnReplies);
97
+ }
95
98
  function _runMarkerSubscriptionsOf(agent, deps) {
96
99
  return [
97
100
  agent.subscribe(resumeMarkerRecorder((runId, messageId, markerValue, markerTimestamp) => {
@@ -103,7 +106,7 @@ function _runMarkerSubscriptionsOf(agent, deps) {
103
106
  deps.noteInterruptAnswerConsumed(runId, consumed.interruptId, consumed.round);
104
107
  })),
105
108
  agent.subscribe(turnFailedMarkerRecorder((failedRunId, messageId, position, receipts) => {
106
- if (deps.resume.recordTurnFailedReceipts(failedRunId, messageId, position, receipts)) {
109
+ if (deps.resume.recordTurnFailedReceipts(failedRunId, _visibleAnchorOf(messageId, agent, deps), position, receipts)) {
107
110
  deps.publishMarkerAnchors();
108
111
  }
109
112
  })),
@@ -112,8 +115,22 @@ function _runMarkerSubscriptionsOf(agent, deps) {
112
115
  deps.publishMarkerAnchors();
113
116
  }
114
117
  })),
118
+ agent.subscribe(withdrawnReplyRecorder((marker) => {
119
+ const before = deps.resume.withdrawnReplies;
120
+ deps.resume.recordRepliesWithdrawn(marker);
121
+ if (deps.resume.withdrawnReplies !== before) {
122
+ deps.publishMessages(_visibleMessagesOf(agent, deps));
123
+ }
124
+ })),
115
125
  ];
116
126
  }
127
+ function _visibleAnchorOf(messageId, agent, deps) {
128
+ const visible = _visibleMessagesOf(agent, deps);
129
+ if (visible.some((message) => message.id === messageId)) {
130
+ return messageId;
131
+ }
132
+ return visible.at(-1)?.id ?? messageId;
133
+ }
117
134
  function _toolMarkerSubscriptionsOf(agent, deps) {
118
135
  return [
119
136
  agent.subscribe(toolErrorRecorder((toolCallId, errorText) => {
@@ -151,13 +168,6 @@ function _toolMarkerSubscriptionsOf(agent, deps) {
151
168
  deps.publishMarkerAnchors();
152
169
  }
153
170
  })),
154
- agent.subscribe(toolOffloadRecorder((toolCallId) => {
155
- const before = deps.resume.toolOffloadAnchors;
156
- deps.resume.recordToolOffload(toolCallId);
157
- if (deps.resume.toolOffloadAnchors !== before) {
158
- deps.publishMarkerAnchors();
159
- }
160
- })),
161
171
  agent.subscribe(toolCallDisplayRecorder((toolCallId, display) => {
162
172
  const before = deps.resume.toolCallDisplayAnchors;
163
173
  deps.resume.recordToolCallDisplay(toolCallId, display);
@@ -226,7 +236,9 @@ function _streamStateSubscriptionsOf(agent, deps, inboxes) {
226
236
  deps.onQuietClose(() => agent.isRunning);
227
237
  })),
228
238
  agent.subscribe(executionInboxRecorder(inboxes.executionInbox, inboxes.publishEntries)),
229
- agent.subscribe(messagesRecorder(deps.publishMessages)),
239
+ agent.subscribe(messagesRecorder((messages) => {
240
+ deps.publishMessages(withoutWithdrawnReplies(messages, deps.resume.withdrawnReplies));
241
+ })),
230
242
  agent.subscribe(streamErrorRecorder(deps.onStreamError)),
231
243
  ];
232
244
  }
@@ -132,7 +132,6 @@ export class AssistantConversationStore {
132
132
  toolErrorAnchors: new Map(),
133
133
  toolRefusalAnchors: new Map(),
134
134
  toolCancelAnchors: new Set(),
135
- toolOffloadAnchors: new Set(),
136
135
  toolDecisionAnchors: new Set(),
137
136
  toolDenialAnchors: new Set(),
138
137
  toolCallDisplayAnchors: new Map(),
@@ -38,7 +38,7 @@ export function syncEpoch(store) {
38
38
  store._questionAnswers.clear();
39
39
  publishExecutionEntries(store, []);
40
40
  store._epoch.withExecutionInbox((inbox) => inbox.adoptCoworkerRequests(active.coworkerRequestTurns));
41
- store._messagesCell.set([...store._epoch.agent.messages]);
41
+ store._messagesCell.set(store._epoch.visibleMessages());
42
42
  store._markerAnchorsCell.set(markerAnchorsOf(active.resume));
43
43
  store._connectionCell.set({
44
44
  epochId,
@@ -1,10 +1,14 @@
1
1
  import { ServingApiError } from "../transport/serving-error.js";
2
+ import { MESSAGE_TOO_LONG_SENTENCE } from "./message-copy.js";
2
3
  import { STOP_NOT_DELIVERED_SENTENCE } from "./stop-copy.js";
3
4
  const GENERIC_FAILURE_SENTENCE = "Something went wrong sending that. Please try again.";
4
5
  export function userSentenceFor(error) {
5
6
  if (!(error instanceof ServingApiError)) {
6
7
  return GENERIC_FAILURE_SENTENCE;
7
8
  }
9
+ if (_isAMessageTooLong(error)) {
10
+ return MESSAGE_TOO_LONG_SENTENCE;
11
+ }
8
12
  switch (error.code) {
9
13
  case "ASSISTANT_THREAD_BUSY":
10
14
  return ("The assistant is already answering — possibly in another tab. " +
@@ -20,7 +24,7 @@ export function userSentenceFor(error) {
20
24
  case "NOT_FOUND":
21
25
  return "That conversation isn't available.";
22
26
  case "VALIDATION_ERROR":
23
- return "That message couldn't be sent. Shorten it and try again.";
27
+ return "That message couldn't be sent. Check it and try again.";
24
28
  default:
25
29
  return error.message;
26
30
  }
@@ -37,6 +41,10 @@ export function failureSentenceOf(error) {
37
41
  }
38
42
  return "Something went wrong. Try again.";
39
43
  }
44
+ function _isAMessageTooLong(error) {
45
+ return (error.code === "MESSAGE_TOO_LONG" ||
46
+ (error.status === 413 && error.code === "UNKNOWN"));
47
+ }
40
48
  function _rateLimitedSentence(retryAfterSeconds) {
41
49
  if (retryAfterSeconds !== null && retryAfterSeconds > 0) {
42
50
  return `You're sending messages too quickly. Try again in ${String(retryAfterSeconds)} seconds.`;
@@ -0,0 +1,22 @@
1
+ export const LONG_MESSAGE_COLLAPSE_FROM = 20_000;
2
+ const PREVIEW_CHARS = 600;
3
+ const WORD_BREAK_WINDOW = 120;
4
+ export function longMessagePreviewOf(text) {
5
+ if (text.length <= LONG_MESSAGE_COLLAPSE_FROM) {
6
+ return null;
7
+ }
8
+ return text.slice(0, _previewEndOf(text)).trimEnd();
9
+ }
10
+ function _previewEndOf(text) {
11
+ const windowStart = PREVIEW_CHARS - WORD_BREAK_WINDOW;
12
+ const lastBreak = text.slice(windowStart, PREVIEW_CHARS).search(/\s\S*$/);
13
+ if (lastBreak >= 0) {
14
+ return windowStart + lastBreak;
15
+ }
16
+ return _isLowSurrogate(text.charCodeAt(PREVIEW_CHARS))
17
+ ? PREVIEW_CHARS - 1
18
+ : PREVIEW_CHARS;
19
+ }
20
+ function _isLowSurrogate(code) {
21
+ return code >= 0xdc00 && code <= 0xdfff;
22
+ }
@@ -0,0 +1 @@
1
+ export const MESSAGE_TOO_LONG_SENTENCE = "This message is too long to answer. Please shorten it or split it into smaller messages.";
@@ -63,15 +63,9 @@ export interface ToolCallViewModel {
63
63
  argsText?: string;
64
64
  /**
65
65
  * The raw result text. Undefined until the call finishes, and withheld for
66
- * calls that failed, were not approved, didn't run, were declined or had
67
- * their result replaced by a preview.
66
+ * calls that failed, were not approved, didn't run or were declined.
68
67
  */
69
68
  output?: string;
70
- /**
71
- * True when the result was too large for the agent and was replaced by a
72
- * shortened preview. `output` is then withheld.
73
- */
74
- offloaded?: boolean;
75
69
  /** Why the call failed, set when it failed. */
76
70
  errorText?: string;
77
71
  /**
@@ -67,9 +67,6 @@ function _toolViewCallOf(view, awaitingDecision) {
67
67
  },
68
68
  });
69
69
  }
70
- if (view.offloaded === true) {
71
- call.offloaded = true;
72
- }
73
70
  if (view.errorText !== undefined) {
74
71
  call.errorText = view.errorText;
75
72
  }
@@ -5,7 +5,6 @@ const TOOL_OUTCOME_FIELDS = [
5
5
  "refused",
6
6
  "cancelled",
7
7
  "truncated",
8
- "offloaded",
9
8
  ];
10
9
  const NAMESPACE = "teaflask";
11
10
  const OUTCOME_KEY = "toolOutcome";
@@ -40,8 +40,8 @@ export interface ToolViewCall<TArgs = Record<string, unknown>, TResult = unknown
40
40
  result?: TResult;
41
41
  /**
42
42
  * The raw result text as recorded. Undefined until the call finishes, and
43
- * withheld for calls that failed, were not approved, didn't run, were
44
- * declined or had their result replaced by a preview.
43
+ * withheld for calls that failed, were not approved, didn't run or were
44
+ * declined.
45
45
  */
46
46
  resultText?: string;
47
47
  /**
@@ -50,11 +50,6 @@ export interface ToolViewCall<TArgs = Record<string, unknown>, TResult = unknown
50
50
  * complete.
51
51
  */
52
52
  truncated?: boolean;
53
- /**
54
- * True when the result was too large for the agent and was replaced by a
55
- * shortened preview. The tool's real output is not available to the view.
56
- */
57
- offloaded?: boolean;
58
53
  /**
59
54
  * Why the call failed, set when it failed. Use humanFailureSentenceOf to
60
55
  * get a sentence fit for the user, and actionFailureOf to read an action's
@@ -1,4 +1,5 @@
1
1
  import { actionToolView } from "../components/tool-views/action-view.js";
2
+ import { graphqlActionToolView } from "../components/tool-views/graphql-action-view.js";
2
3
  import { commandToolView } from "../components/tool-views/command-view.js";
3
4
  import { docsSearchToolView } from "../components/tool-views/docs-search-view.js";
4
5
  import { fileEditToolView } from "../components/tool-views/file-edit-view.js";
@@ -10,6 +11,7 @@ export function isReservedToolViewKey(key) {
10
11
  export const PACKAGE_TOOL_VIEWS = Object.freeze({
11
12
  "teaflask.questions": { version: 1, view: questionsToolView },
12
13
  "teaflask.action": { version: 1, view: actionToolView },
14
+ "teaflask.graphql-action": { version: 1, view: graphqlActionToolView },
13
15
  "teaflask.command": { version: 1, view: commandToolView },
14
16
  "teaflask.file-edit": { version: 1, view: fileEditToolView },
15
17
  "teaflask.docs-search": { version: 1, view: docsSearchToolView },
@@ -110,12 +110,6 @@ export interface ToolCallRow {
110
110
  * arrives.
111
111
  */
112
112
  result?: string;
113
- /**
114
- * True when the tool's output was too large and `result` holds a shortened
115
- * stand-in rather than the actual output; show a "result shortened" note
116
- * instead of the content.
117
- */
118
- offloaded: boolean;
119
113
  /** Why the call failed. Present only when state is output-error. */
120
114
  errorText?: string;
121
115
  /**
@@ -21,7 +21,6 @@ export function transcriptRowsOf(messages, anchors, running, metaByMessageId = N
21
21
  errors: anchors.toolErrorAnchors,
22
22
  refusals: anchors.toolRefusalAnchors,
23
23
  cancels: anchors.toolCancelAnchors,
24
- offloads: anchors.toolOffloadAnchors,
25
24
  decisions: anchors.toolDecisionAnchors ?? EMPTY_TOOL_DECISION_ANCHORS,
26
25
  denials: anchors.toolDenialAnchors ?? EMPTY_TOOL_DENIAL_ANCHORS,
27
26
  displays: anchors.toolCallDisplayAnchors,
@@ -112,7 +111,6 @@ function _pushMessageRows(rows, message, results, context) {
112
111
  state,
113
112
  argsText: toolCall.function.arguments,
114
113
  result,
115
- offloaded: context.offloads.has(toolCall.id),
116
114
  errorText: errorTextOf(recordedError, result),
117
115
  ...(state === "refused" ? { refusalText: recordedRefusal } : {}),
118
116
  display: context.displays.get(toolCall.id),
@@ -239,7 +237,6 @@ export function transcriptBlocksOf(messages, anchors, running, metaByMessageId =
239
237
  errors: anchors.toolErrorAnchors,
240
238
  refusals: anchors.toolRefusalAnchors,
241
239
  cancels: anchors.toolCancelAnchors,
242
- offloads: anchors.toolOffloadAnchors,
243
240
  decisions: anchors.toolDecisionAnchors ?? EMPTY_TOOL_DECISION_ANCHORS,
244
241
  denials: anchors.toolDenialAnchors ?? EMPTY_TOOL_DENIAL_ANCHORS,
245
242
  displays: anchors.toolCallDisplayAnchors,
@@ -0,0 +1,11 @@
1
+ import type { AgentSubscriber } from "@ag-ui/client";
2
+ import type { Message } from "@ag-ui/core";
3
+ import type { ReplyWithdrawnMarker } from "../generated/models/index.js";
4
+ export interface WithdrawnReplies {
5
+ messageIds: ReadonlySet<string>;
6
+ toolCallIds: ReadonlySet<string>;
7
+ }
8
+ export declare const EMPTY_WITHDRAWN_REPLIES: WithdrawnReplies;
9
+ export declare function withRepliesWithdrawn(previous: WithdrawnReplies, marker: ReplyWithdrawnMarker): WithdrawnReplies;
10
+ export declare function withdrawnReplyRecorder(onWithdrawn: (marker: ReplyWithdrawnMarker) => void): AgentSubscriber;
11
+ export declare function withoutWithdrawnReplies(messages: readonly Message[], withdrawn: WithdrawnReplies): readonly Message[];
@@ -0,0 +1,76 @@
1
+ import { REPLY_WITHDRAWN_EVENT_NAME } from "../contract/events.js";
2
+ export const EMPTY_WITHDRAWN_REPLIES = {
3
+ messageIds: new Set(),
4
+ toolCallIds: new Set(),
5
+ };
6
+ function _withdrawnRepliesOf(name, value) {
7
+ if (name !== REPLY_WITHDRAWN_EVENT_NAME ||
8
+ typeof value !== "object" ||
9
+ value === null) {
10
+ return null;
11
+ }
12
+ const record = value;
13
+ return {
14
+ messageIds: _idsIn(record.messageIds),
15
+ toolCallIds: _idsIn(record.toolCallIds),
16
+ };
17
+ }
18
+ function _idsIn(field) {
19
+ if (!Array.isArray(field)) {
20
+ return [];
21
+ }
22
+ return field.filter((id) => typeof id === "string" && id !== "");
23
+ }
24
+ export function withRepliesWithdrawn(previous, marker) {
25
+ const messageIds = _withIds(previous.messageIds, marker.messageIds);
26
+ const toolCallIds = _withIds(previous.toolCallIds, marker.toolCallIds);
27
+ if (messageIds === previous.messageIds &&
28
+ toolCallIds === previous.toolCallIds) {
29
+ return previous;
30
+ }
31
+ return { messageIds, toolCallIds };
32
+ }
33
+ function _withIds(previous, ids) {
34
+ if (ids.every((id) => previous.has(id))) {
35
+ return previous;
36
+ }
37
+ return new Set([...previous, ...ids]);
38
+ }
39
+ export function withdrawnReplyRecorder(onWithdrawn) {
40
+ return {
41
+ onCustomEvent({ event }) {
42
+ const marker = _withdrawnRepliesOf(event.name, event.value);
43
+ if (marker !== null) {
44
+ onWithdrawn(marker);
45
+ }
46
+ },
47
+ };
48
+ }
49
+ export function withoutWithdrawnReplies(messages, withdrawn) {
50
+ if (_nothingIsWithdrawn(withdrawn)) {
51
+ return messages;
52
+ }
53
+ return messages.flatMap((message) => _visiblePartOf(message, withdrawn));
54
+ }
55
+ function _nothingIsWithdrawn(withdrawn) {
56
+ return withdrawn.messageIds.size === 0 && withdrawn.toolCallIds.size === 0;
57
+ }
58
+ function _visiblePartOf(message, withdrawn) {
59
+ if (withdrawn.messageIds.has(message.id)) {
60
+ return [];
61
+ }
62
+ if (message.role === "tool") {
63
+ return withdrawn.toolCallIds.has(message.toolCallId) ? [] : [message];
64
+ }
65
+ if (message.role !== "assistant" || message.toolCalls === undefined) {
66
+ return [message];
67
+ }
68
+ const toolCalls = message.toolCalls.filter((toolCall) => !withdrawn.toolCallIds.has(toolCall.id));
69
+ if (toolCalls.length === message.toolCalls.length) {
70
+ return [message];
71
+ }
72
+ if (toolCalls.length === 0 && !message.content) {
73
+ return [];
74
+ }
75
+ return [{ ...message, toolCalls }];
76
+ }
@@ -22,6 +22,7 @@ export declare const ApiErrorCode: {
22
22
  readonly DOC_REVISION_NOT_PUBLISHABLE: "DOC_REVISION_NOT_PUBLISHABLE";
23
23
  readonly DOC_REVISION_NOT_DISCARDABLE: "DOC_REVISION_NOT_DISCARDABLE";
24
24
  readonly DOC_PROPOSAL_STALE: "DOC_PROPOSAL_STALE";
25
+ readonly REVISION_STALE: "REVISION_STALE";
25
26
  readonly DOC_LIMIT_REACHED: "DOC_LIMIT_REACHED";
26
27
  readonly HELP_SITE_CONFIG_INVALID: "HELP_SITE_CONFIG_INVALID";
27
28
  readonly HELP_SITE_NEVER_PUBLISHED: "HELP_SITE_NEVER_PUBLISHED";
@@ -90,6 +91,9 @@ export declare const ApiErrorCode: {
90
91
  readonly ORG_ACTION_PROPOSAL_CHANGED: "ORG_ACTION_PROPOSAL_CHANGED";
91
92
  readonly ORG_ACTION_PROPOSAL_NOT_EDITABLE: "ORG_ACTION_PROPOSAL_NOT_EDITABLE";
92
93
  readonly ORG_ACTION_SCAN_ALREADY_RUNNING: "ORG_ACTION_SCAN_ALREADY_RUNNING";
94
+ readonly ORG_ACTION_SPEC_UPLOADS_NOT_AVAILABLE: "ORG_ACTION_SPEC_UPLOADS_NOT_AVAILABLE";
95
+ readonly ORG_ACTION_SPEC_UPLOAD_INVALID: "ORG_ACTION_SPEC_UPLOAD_INVALID";
96
+ readonly ORG_ACTION_SPEC_UPLOAD_TOO_LARGE: "ORG_ACTION_SPEC_UPLOAD_TOO_LARGE";
93
97
  readonly ORG_SITEMAP_PAGE_INVALID: "ORG_SITEMAP_PAGE_INVALID";
94
98
  readonly ORG_SITEMAP_ROUTE_ALREADY_REGISTERED: "ORG_SITEMAP_ROUTE_ALREADY_REGISTERED";
95
99
  readonly ORG_SITEMAP_PAGE_ALREADY_ARCHIVED: "ORG_SITEMAP_PAGE_ALREADY_ARCHIVED";
@@ -112,6 +116,7 @@ export declare const ApiErrorCode: {
112
116
  readonly WORK_CREDIT_REQUEST_PENDING: "WORK_CREDIT_REQUEST_PENDING";
113
117
  readonly JOIN_REQUEST_ALREADY_MEMBER: "JOIN_REQUEST_ALREADY_MEMBER";
114
118
  readonly JOIN_REQUEST_ALREADY_PENDING: "JOIN_REQUEST_ALREADY_PENDING";
119
+ readonly LAST_OWNER: "LAST_OWNER";
115
120
  readonly ORGANIZATION_DOMAIN_DNS_CLAIMED: "ORGANIZATION_DOMAIN_DNS_CLAIMED";
116
121
  readonly EMAIL_DOMAIN_NOT_CLAIMABLE: "EMAIL_DOMAIN_NOT_CLAIMABLE";
117
122
  readonly EMAIL_DOMAIN_REVOKED: "EMAIL_DOMAIN_REVOKED";
@@ -141,6 +146,13 @@ export declare const ApiErrorCode: {
141
146
  readonly SSO_REQUIRED_FOR_DOMAIN: "SSO_REQUIRED_FOR_DOMAIN";
142
147
  readonly SSO_CONNECTION_NOT_ACTIVE: "SSO_CONNECTION_NOT_ACTIVE";
143
148
  readonly EDGE_ORIGIN_REQUIRED: "EDGE_ORIGIN_REQUIRED";
149
+ readonly MCP_CONNECTIONS_NOT_AVAILABLE: "MCP_CONNECTIONS_NOT_AVAILABLE";
150
+ readonly MCP_AUTHORIZATION_EXPIRED: "MCP_AUTHORIZATION_EXPIRED";
151
+ readonly MCP_CAPABILITY_ABOVE_ROLE: "MCP_CAPABILITY_ABOVE_ROLE";
152
+ readonly MCP_CAPABILITIES_INVALID: "MCP_CAPABILITIES_INVALID";
153
+ readonly MCP_AUTHORIZATION_SERVER_UNAVAILABLE: "MCP_AUTHORIZATION_SERVER_UNAVAILABLE";
154
+ readonly MCP_CONNECTION_CONFLICT: "MCP_CONNECTION_CONFLICT";
155
+ readonly MESSAGE_TOO_LONG: "MESSAGE_TOO_LONG";
144
156
  readonly DEMO_ERROR: "DEMO_ERROR";
145
157
  readonly HTTP_ERROR: "HTTP_ERROR";
146
158
  readonly INTERNAL_ERROR: "INTERNAL_ERROR";
@@ -21,6 +21,7 @@ export const ApiErrorCode = {
21
21
  DOC_REVISION_NOT_PUBLISHABLE: "DOC_REVISION_NOT_PUBLISHABLE",
22
22
  DOC_REVISION_NOT_DISCARDABLE: "DOC_REVISION_NOT_DISCARDABLE",
23
23
  DOC_PROPOSAL_STALE: "DOC_PROPOSAL_STALE",
24
+ REVISION_STALE: "REVISION_STALE",
24
25
  DOC_LIMIT_REACHED: "DOC_LIMIT_REACHED",
25
26
  HELP_SITE_CONFIG_INVALID: "HELP_SITE_CONFIG_INVALID",
26
27
  HELP_SITE_NEVER_PUBLISHED: "HELP_SITE_NEVER_PUBLISHED",
@@ -89,6 +90,9 @@ export const ApiErrorCode = {
89
90
  ORG_ACTION_PROPOSAL_CHANGED: "ORG_ACTION_PROPOSAL_CHANGED",
90
91
  ORG_ACTION_PROPOSAL_NOT_EDITABLE: "ORG_ACTION_PROPOSAL_NOT_EDITABLE",
91
92
  ORG_ACTION_SCAN_ALREADY_RUNNING: "ORG_ACTION_SCAN_ALREADY_RUNNING",
93
+ ORG_ACTION_SPEC_UPLOADS_NOT_AVAILABLE: "ORG_ACTION_SPEC_UPLOADS_NOT_AVAILABLE",
94
+ ORG_ACTION_SPEC_UPLOAD_INVALID: "ORG_ACTION_SPEC_UPLOAD_INVALID",
95
+ ORG_ACTION_SPEC_UPLOAD_TOO_LARGE: "ORG_ACTION_SPEC_UPLOAD_TOO_LARGE",
92
96
  ORG_SITEMAP_PAGE_INVALID: "ORG_SITEMAP_PAGE_INVALID",
93
97
  ORG_SITEMAP_ROUTE_ALREADY_REGISTERED: "ORG_SITEMAP_ROUTE_ALREADY_REGISTERED",
94
98
  ORG_SITEMAP_PAGE_ALREADY_ARCHIVED: "ORG_SITEMAP_PAGE_ALREADY_ARCHIVED",
@@ -111,6 +115,7 @@ export const ApiErrorCode = {
111
115
  WORK_CREDIT_REQUEST_PENDING: "WORK_CREDIT_REQUEST_PENDING",
112
116
  JOIN_REQUEST_ALREADY_MEMBER: "JOIN_REQUEST_ALREADY_MEMBER",
113
117
  JOIN_REQUEST_ALREADY_PENDING: "JOIN_REQUEST_ALREADY_PENDING",
118
+ LAST_OWNER: "LAST_OWNER",
114
119
  ORGANIZATION_DOMAIN_DNS_CLAIMED: "ORGANIZATION_DOMAIN_DNS_CLAIMED",
115
120
  EMAIL_DOMAIN_NOT_CLAIMABLE: "EMAIL_DOMAIN_NOT_CLAIMABLE",
116
121
  EMAIL_DOMAIN_REVOKED: "EMAIL_DOMAIN_REVOKED",
@@ -140,6 +145,13 @@ export const ApiErrorCode = {
140
145
  SSO_REQUIRED_FOR_DOMAIN: "SSO_REQUIRED_FOR_DOMAIN",
141
146
  SSO_CONNECTION_NOT_ACTIVE: "SSO_CONNECTION_NOT_ACTIVE",
142
147
  EDGE_ORIGIN_REQUIRED: "EDGE_ORIGIN_REQUIRED",
148
+ MCP_CONNECTIONS_NOT_AVAILABLE: "MCP_CONNECTIONS_NOT_AVAILABLE",
149
+ MCP_AUTHORIZATION_EXPIRED: "MCP_AUTHORIZATION_EXPIRED",
150
+ MCP_CAPABILITY_ABOVE_ROLE: "MCP_CAPABILITY_ABOVE_ROLE",
151
+ MCP_CAPABILITIES_INVALID: "MCP_CAPABILITIES_INVALID",
152
+ MCP_AUTHORIZATION_SERVER_UNAVAILABLE: "MCP_AUTHORIZATION_SERVER_UNAVAILABLE",
153
+ MCP_CONNECTION_CONFLICT: "MCP_CONNECTION_CONFLICT",
154
+ MESSAGE_TOO_LONG: "MESSAGE_TOO_LONG",
143
155
  DEMO_ERROR: "DEMO_ERROR",
144
156
  HTTP_ERROR: "HTTP_ERROR",
145
157
  INTERNAL_ERROR: "INTERNAL_ERROR",
@@ -16,4 +16,5 @@ export declare const AssistantStreamMarkerName: {
16
16
  readonly turn_failed: "turn_failed";
17
17
  readonly turn_stop_requested: "turn_stop_requested";
18
18
  readonly interrupt_answer_consumed: "interrupt_answer_consumed";
19
+ readonly reply_withdrawn: "reply_withdrawn";
19
20
  };