@agents24/react 0.2.0 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/model.d.ts CHANGED
@@ -1,6 +1,7 @@
1
- import type { AttachmentResult, HitlAction, RuntimeEvent, ThreadDetail, ThreadSummary } from "@agents24/client";
1
+ import type { AttachmentResult, FailureView, HitlAction, ResponseFeedback, RuntimeEvent, ThreadDetail, ThreadSummary } from "@agents24/client";
2
+ import { type ContextCompression, type ContextWindow } from "@agents24/client/protocol";
2
3
  export type AgentChatMessageRole = "user" | "assistant";
3
- export type AgentChatRunState = "idle" | "streaming" | "reconnecting" | "paused" | "completed" | "failed";
4
+ export type AgentChatRunState = "idle" | "streaming" | "reconnecting" | "paused" | "cancelling" | "completed" | "cancelled" | "failed";
4
5
  export type ChatCitation = {
5
6
  title: string;
6
7
  url: string;
@@ -17,38 +18,106 @@ export type ChatAttachment = {
17
18
  status?: string;
18
19
  [key: string]: unknown;
19
20
  };
21
+ export declare function chatAttachmentIds(attachments?: readonly ChatAttachment[]): string[];
20
22
  export type ChatToolState = "input-streaming" | "input-available" | "output-available" | "output-error" | "cancelled";
21
- export type ChatTextPart = {
23
+ export type ChatPartMetadata = {
22
24
  id: string;
25
+ runId?: string | null;
26
+ sequence?: number | null;
27
+ timestamp?: string | null;
28
+ raw?: Record<string, unknown>;
29
+ };
30
+ export type ChatToolChildRun = {
31
+ runId?: string | null;
32
+ agentId?: string | null;
33
+ agentName?: string | null;
34
+ status?: string | null;
35
+ error?: string | null;
36
+ };
37
+ export type ChatToolChild = {
38
+ id: string;
39
+ runId?: string | null;
40
+ toolCallId?: string | null;
41
+ toolName: string;
42
+ title: string;
43
+ status: string;
44
+ detail?: string | null;
45
+ sequence?: number | null;
46
+ timestamp?: string | null;
47
+ };
48
+ export type ChatToolPresentation = Record<string, unknown> & {
49
+ title?: string | null;
50
+ activity?: string | null;
51
+ detail?: string | null;
52
+ category?: string | null;
53
+ groupKey?: string | null;
54
+ groupLabel?: string | null;
55
+ path?: string | null;
56
+ threadId?: string | null;
57
+ isExploration?: boolean;
58
+ childRun?: ChatToolChildRun | null;
59
+ childTools?: ChatToolChild[];
60
+ activeChildToolId?: string | null;
61
+ };
62
+ export type ChatTextPart = ChatPartMetadata & {
23
63
  type: "text";
24
64
  kind: "text";
25
65
  text: string;
26
- raw?: Record<string, unknown>;
27
66
  };
28
- export type ChatToolPart = {
29
- id: string;
67
+ export type ChatToolPart = ChatPartMetadata & {
30
68
  type: `tool-${string}`;
31
69
  kind: "tool";
32
70
  toolName: string;
71
+ toolKey?: string | null;
72
+ action?: string | null;
73
+ displayName?: string | null;
74
+ summary?: string | null;
33
75
  toolCallId?: string | null;
76
+ sourceKind?: string | null;
34
77
  state: ChatToolState;
35
78
  input?: unknown;
36
79
  output?: unknown;
37
80
  errorText?: string | null;
38
- presentation?: Record<string, unknown> | null;
39
- raw: Record<string, unknown>;
81
+ failure?: FailureView | null;
82
+ presentation: ChatToolPresentation;
40
83
  };
41
- export type ChatReasoningPart = {
42
- id: string;
84
+ export type ChatReasoningPart = ChatPartMetadata & {
43
85
  type: "reasoning";
44
86
  kind: "reasoning";
45
87
  label?: string | null;
46
88
  text?: string | null;
47
89
  status?: string | null;
48
- raw: Record<string, unknown>;
49
90
  };
50
- export type ChatUiBlocksPart = {
51
- id: string;
91
+ export type ChatModelTurnPart = ChatPartMetadata & {
92
+ type: "model-turn";
93
+ kind: "model-turn";
94
+ modelTurnId: string;
95
+ turnKind: "agent" | "model";
96
+ status: "running";
97
+ iteration?: number | null;
98
+ };
99
+ export type ChatContextCompressionPart = ChatPartMetadata & {
100
+ type: "context-compression";
101
+ kind: "context-compression";
102
+ status: "started" | "completed" | "failed";
103
+ compression: ContextCompression;
104
+ };
105
+ export type ChatNodeActivityState = "running" | "completed" | "failed" | "cancelled" | "skipped";
106
+ export type ChatNodeSkipReason = "missing_required_input" | "upstream_input_unavailable" | "empty_optional_source";
107
+ export type ChatNodeActivityPart = ChatPartMetadata & {
108
+ type: "node-activity";
109
+ kind: "node-activity";
110
+ activityId: string;
111
+ /** Opaque trusted-host trace selector; absent from public projections. */
112
+ traceStepId?: string | null;
113
+ label: string;
114
+ nodeKind: string;
115
+ status: ChatNodeActivityState;
116
+ defaultChatVisible: boolean;
117
+ reason?: ChatNodeSkipReason | null;
118
+ failure?: FailureView | null;
119
+ };
120
+ export type ChatUiBlocksPart = ChatPartMetadata & {
52
121
  type: "ui-blocks";
53
122
  kind: "ui-blocks";
54
123
  state: ChatToolState;
@@ -56,12 +125,30 @@ export type ChatUiBlocksPart = {
56
125
  contractVersion?: string | null;
57
126
  bundle?: Record<string, unknown> | null;
58
127
  errorText?: string | null;
59
- raw: Record<string, unknown>;
60
128
  };
61
- export type ChatHitlKind = "tool_review" | "mcp_auth" | "user_approval" | "app_data_permission";
129
+ export type ChatHitlKind = "tool_review" | "mcp_auth" | "user_approval" | "app_data_permission" | "user_input";
62
130
  export type ChatHitlStatus = "pending" | "resolved" | "expired" | "cancelled" | "invalidated";
63
- export type ChatHitlPart = {
131
+ export type ChatHitlQuestion = {
64
132
  id: string;
133
+ header: string;
134
+ question: string;
135
+ options: Array<{
136
+ id: string;
137
+ label: string;
138
+ }>;
139
+ multiSelect: boolean;
140
+ };
141
+ export type ChatHitlAnswer = {
142
+ questionId: string;
143
+ selectedOptionIds: string[];
144
+ customText?: string;
145
+ };
146
+ export type ChatHitlResolution = Record<string, unknown> & {
147
+ answers?: ChatHitlAnswer[];
148
+ outcome?: string;
149
+ status?: string;
150
+ };
151
+ export type ChatHitlPart = ChatPartMetadata & {
65
152
  type: "hitl";
66
153
  kind: "hitl";
67
154
  interruptId: string;
@@ -70,50 +157,41 @@ export type ChatHitlPart = {
70
157
  allowedActions: HitlAction[];
71
158
  status: ChatHitlStatus;
72
159
  presentation: Record<string, unknown>;
73
- resolution?: Record<string, unknown> | null;
74
- raw: Record<string, unknown>;
160
+ questions: ChatHitlQuestion[];
161
+ resolution?: ChatHitlResolution | null;
75
162
  };
76
- export type ChatErrorPart = {
77
- id: string;
163
+ export type ChatErrorPart = ChatPartMetadata & {
78
164
  type: "error";
79
165
  kind: "error";
80
166
  errorText: string;
81
- raw: Record<string, unknown>;
167
+ failure?: FailureView | null;
82
168
  };
83
- export type ChatDataPart = {
84
- id: string;
169
+ export type ChatDataPart = ChatPartMetadata & {
85
170
  type: "data";
86
171
  kind: "data";
87
172
  name: string;
88
173
  data: Record<string, unknown>;
89
- raw: Record<string, unknown>;
90
174
  };
91
- export type ChatSourcePart = {
92
- id: string;
175
+ export type ChatSourcePart = ChatPartMetadata & {
93
176
  type: "source";
94
177
  kind: "source";
95
178
  title: string;
96
179
  url?: string | null;
97
180
  description?: string | null;
98
- raw: Record<string, unknown>;
99
181
  };
100
- export type ChatCitationPart = {
101
- id: string;
182
+ export type ChatCitationPart = ChatPartMetadata & {
102
183
  type: "citation";
103
184
  kind: "citation";
104
185
  sourceId?: string | null;
105
186
  label?: string | null;
106
187
  url?: string | null;
107
- raw: Record<string, unknown>;
108
188
  };
109
- export type ChatAttachmentPart = {
110
- id: string;
189
+ export type ChatAttachmentPart = ChatPartMetadata & {
111
190
  type: "attachment";
112
191
  kind: "attachment";
113
192
  attachment: ChatAttachment;
114
- raw: Record<string, unknown>;
115
193
  };
116
- export type ChatPart = ChatTextPart | ChatToolPart | ChatReasoningPart | ChatUiBlocksPart | ChatHitlPart | ChatErrorPart | ChatDataPart | ChatSourcePart | ChatCitationPart | ChatAttachmentPart;
194
+ export type ChatPart = ChatTextPart | ChatToolPart | ChatReasoningPart | ChatModelTurnPart | ChatContextCompressionPart | ChatNodeActivityPart | ChatUiBlocksPart | ChatHitlPart | ChatErrorPart | ChatDataPart | ChatSourcePart | ChatCitationPart | ChatAttachmentPart;
117
195
  export type ChatMessage = {
118
196
  id: string;
119
197
  role: AgentChatMessageRole;
@@ -124,8 +202,7 @@ export type ChatMessage = {
124
202
  parts: ChatPart[];
125
203
  attachments?: ChatAttachment[];
126
204
  citations?: ChatCitation[];
127
- liked?: boolean;
128
- disliked?: boolean;
205
+ feedback?: ResponseFeedback | null;
129
206
  messageIndex?: number;
130
207
  reasoningSteps?: Array<Record<string, unknown>>;
131
208
  thinkingDurationMs?: number;
@@ -142,11 +219,29 @@ export type StoredChatThread = ThreadSummary & {
142
219
  isHydrated?: boolean;
143
220
  hasOlderTurns?: boolean;
144
221
  nextBeforeTurnIndex?: number | null;
222
+ contextWindow?: ContextWindow | null;
223
+ contextCompression?: ContextCompression | null;
224
+ };
225
+ export type ThreadActivity = {
226
+ status: string | null;
227
+ runId: string | null;
228
+ isSpinning: boolean;
229
+ isPaused: boolean;
230
+ isFailed: boolean;
231
+ isCompleted: boolean;
232
+ isCancelled: boolean;
145
233
  };
146
- export declare function partsFromResponseBlocks(blocks: unknown, fallbackText?: string): ChatPart[];
234
+ export declare function getThreadActivity(thread: Pick<ThreadSummary, "active_run" | "last_run_id" | "last_run_status">): ThreadActivity;
235
+ export declare function partsFromResponseBlocks(blocks: unknown, fallbackText?: string, fallbackPartId?: string): ChatPart[];
147
236
  export declare function assistantProjectionFromEvent(event: RuntimeEvent): {
148
237
  content: string;
149
238
  parts: ChatPart[];
150
239
  };
240
+ export declare function modelTurnPartFromEvent(event: RuntimeEvent): ChatModelTurnPart | null;
241
+ export declare function contextCompressionPartFromEvent(event: RuntimeEvent, existingParts?: readonly ChatPart[]): ChatContextCompressionPart | null;
151
242
  export declare function threadDetailToMessages(detail: ThreadDetail): ChatMessage[];
243
+ export declare function latestThreadContext(detail: ThreadDetail): {
244
+ contextWindow: ContextWindow | null;
245
+ contextCompression: ContextCompression | null;
246
+ };
152
247
  export declare function attachmentResultToChatAttachment(result: AttachmentResult): ChatAttachment;
@@ -0,0 +1,9 @@
1
+ import type { RuntimeEvent } from "@agents24/client";
2
+ export type RuntimeEventFrameScheduler = (callback: () => void) => () => void;
3
+ export type RuntimeEventFrameBuffer = {
4
+ dispose(): void;
5
+ flush(): void;
6
+ push(event: RuntimeEvent): void;
7
+ };
8
+ export declare function runtimeEventFrameScheduler(): RuntimeEventFrameScheduler | undefined;
9
+ export declare function createRuntimeEventFrameBuffer(apply: (events: readonly RuntimeEvent[]) => void, scheduleFrame?: RuntimeEventFrameScheduler): RuntimeEventFrameBuffer;
package/dist/state.d.ts CHANGED
@@ -1,5 +1,17 @@
1
1
  import type { RuntimeEvent, ThreadSummaryEvent } from "@agents24/client";
2
+ import { type ContextCompression, type ContextWindow } from "@agents24/client/protocol";
2
3
  import type { ChatMessage, StoredChatThread } from "./model";
4
+ export type AgentChatOperation = "attach_run" | "cancel_run" | "delete_thread" | "load_more_threads" | "load_older_turns" | "open_thread" | "refresh_threads" | "resume_hitl" | "set_feedback" | "submit";
5
+ export type AgentChatOperationError = {
6
+ kind: "operation";
7
+ operation: AgentChatOperation;
8
+ cause: unknown;
9
+ };
10
+ export type AgentChatBackgroundError = {
11
+ kind: "background";
12
+ source: "thread_events";
13
+ cause: unknown;
14
+ };
3
15
  export type AgentChatState = {
4
16
  threads: StoredChatThread[];
5
17
  activeThreadId: string | null;
@@ -7,10 +19,30 @@ export type AgentChatState = {
7
19
  activeRunId: string | null;
8
20
  cursor: number | null;
9
21
  streamingMessageId: string | null;
10
- runState: "idle" | "streaming" | "reconnecting" | "paused" | "completed" | "failed";
22
+ contextWindow: ContextWindow | null;
23
+ contextCompression: ContextCompression | null;
24
+ contextCompressionRevision: number;
25
+ runState: "idle" | "streaming" | "reconnecting" | "paused" | "cancelling" | "completed" | "cancelled" | "failed";
26
+ /** Fatal chat initialization/session failures only. */
11
27
  error: unknown;
28
+ /** The latest user-visible operation failure. It must not replace the transcript. */
29
+ operationError: AgentChatOperationError | null;
30
+ /** Failure of a non-blocking background synchronization lane. */
31
+ backgroundError: AgentChatBackgroundError | null;
12
32
  };
13
33
  export declare const initialAgentChatState: AgentChatState;
34
+ export type AgentChatThreadSelectionSnapshot = Pick<AgentChatState, "activeRunId" | "activeThreadId" | "cursor" | "messages" | "runState" | "streamingMessageId" | "contextWindow" | "contextCompression" | "contextCompressionRevision">;
35
+ export declare function captureAgentChatThreadSelection(state: AgentChatState): AgentChatThreadSelectionSnapshot;
36
+ export declare function restoreAgentChatThreadSelection(state: AgentChatState, snapshot: AgentChatThreadSelectionSnapshot): AgentChatState;
37
+ export declare function withAgentChatOperationError(state: AgentChatState, operation: AgentChatOperation, cause: unknown): AgentChatState;
38
+ export declare function clearAgentChatOperationError(state: AgentChatState, operation?: AgentChatOperation): AgentChatState;
39
+ export declare function withAgentChatBackgroundError(state: AgentChatState, cause: unknown): AgentChatState;
40
+ export declare function clearAgentChatBackgroundError(state: AgentChatState): AgentChatState;
41
+ /**
42
+ * Reconcile the authoritative first page without dropping a locally-created
43
+ * active thread before it becomes visible in the server's list projection.
44
+ */
45
+ export declare function reconcileRefreshedThreads(current: StoredChatThread[], incoming: StoredChatThread[], activeThreadId: string | null): StoredChatThread[];
14
46
  export type StableChatMessageBase = {
15
47
  id: string;
16
48
  role: "user" | "assistant";
@@ -26,4 +58,5 @@ export type StableAssistantUpsertInput<TMessage extends StableChatMessageBase> =
26
58
  export declare function appendStableStreamingTurn<TMessage extends StableChatMessageBase>(messages: TMessage[], userMessage: TMessage, assistantMessage: TMessage): TMessage[];
27
59
  export declare function upsertStableAssistantMessage<TMessage extends StableChatMessageBase>(messages: TMessage[], input: StableAssistantUpsertInput<TMessage>): TMessage[];
28
60
  export declare function applyRuntimeEvent(state: AgentChatState, event: RuntimeEvent): AgentChatState;
61
+ export declare function applyRuntimeEvents(state: AgentChatState, events: readonly RuntimeEvent[]): AgentChatState;
29
62
  export declare function applyThreadSummaryEvent(threads: StoredChatThread[], event: ThreadSummaryEvent): StoredChatThread[];
@@ -1,6 +1,6 @@
1
- import type { AgentClient, HitlAction } from "@agents24/client";
1
+ import type { AgentClient, FeedbackReason, HitlResponse } from "@agents24/client";
2
2
  import type { ChatAttachment, ChatHitlPart, ChatMessage, StoredChatThread } from "./model";
3
- import { type AgentChatState } from "./state";
3
+ import { type AgentChatOperation, type AgentChatState } from "./state";
4
4
  export type AgentChatSubmitInput = {
5
5
  text: string;
6
6
  attachmentIds?: readonly string[];
@@ -24,6 +24,8 @@ export type AgentChatController = AgentChatState & {
24
24
  isSubmitting: boolean;
25
25
  attachRun(runId: string, cursor?: number): Promise<void>;
26
26
  cancelRun(): Promise<void>;
27
+ clearBackgroundError(): void;
28
+ clearOperationError(operation?: AgentChatOperation): void;
27
29
  deleteThread(threadId: string): Promise<void>;
28
30
  detach(): void;
29
31
  loadOlder(): Promise<void>;
@@ -31,7 +33,12 @@ export type AgentChatController = AgentChatState & {
31
33
  openThread(threadId: string): Promise<void>;
32
34
  refreshThreads(): Promise<void>;
33
35
  regenerate(message: ChatMessage): Promise<void>;
34
- resumeHitl(part: ChatHitlPart, action: HitlAction, comment?: string): Promise<void>;
36
+ resumeHitl(part: ChatHitlPart, response: HitlResponse): Promise<void>;
37
+ setFeedback(message: ChatMessage, input: {
38
+ rating: "like" | "dislike" | null;
39
+ reason?: FeedbackReason | null;
40
+ comment?: string | null;
41
+ }): Promise<void>;
35
42
  startNewThread(): void;
36
43
  submit(input: AgentChatSubmitInput): Promise<void>;
37
44
  };
@@ -12,7 +12,6 @@ export declare function useAgentThreads(options?: {
12
12
  export declare function useAgentThread(threadId: string | null, options?: {
13
13
  limit?: number;
14
14
  beforeTurnIndex?: number;
15
- includeRunEvents?: boolean;
16
15
  }): {
17
16
  error: unknown;
18
17
  isLoading: boolean;
@@ -27,14 +26,21 @@ export declare function useAgentRun(): {
27
26
  isAttached: boolean;
28
27
  };
29
28
  export declare function useAgentAttachments(): {
29
+ createContentAccess: (input: {
30
+ attachmentId: string;
31
+ disposition: "inline" | "attachment";
32
+ signal?: AbortSignalLike;
33
+ }) => Promise<import("@agents24/client").AttachmentContentAccess>;
30
34
  isUploading: boolean;
31
- upload: (input: {
32
- data: BinaryUploadData;
33
- name: string;
34
- mediaType: string;
35
+ uploadBatch: (input: {
36
+ uploads: readonly {
37
+ data: BinaryUploadData;
38
+ name: string;
39
+ mediaType: string;
40
+ }[];
35
41
  threadId?: string;
36
42
  signal?: AbortSignalLike;
37
- }) => Promise<import("./model").ChatAttachment>;
43
+ }) => Promise<import("./model").ChatAttachment[]>;
38
44
  uploads: Record<string, AttachmentResult>;
39
45
  };
40
46
  export declare function useAgentHitl(): {
@@ -45,6 +51,7 @@ export declare function useAgentHitl(): {
45
51
  interruptId: string;
46
52
  action: HitlAction;
47
53
  comment?: string;
54
+ answers?: import("@agents24/client").HitlAnswer[];
48
55
  signal?: AbortSignalLike;
49
56
  }) => Promise<HitlResumeResult>;
50
57
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agents24/react",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
4
4
  "description": "DOM-free React state and hooks for Agents24 client applications.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -40,7 +40,7 @@
40
40
  "prepack": "pnpm run build && pnpm run check:boundaries"
41
41
  },
42
42
  "dependencies": {
43
- "@agents24/client": "0.2.0"
43
+ "@agents24/client": "0.2.2"
44
44
  },
45
45
  "peerDependencies": {
46
46
  "react": ">=19.0.0 <20.0.0"