@truefoundry/trueforge-assistant-ui-runtime 0.0.0 → 0.2.0-rc.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.
- package/CHANGELOG.md +9 -0
- package/LICENSE +201 -0
- package/README.md +146 -4
- package/dist/chunk-2SQK6TIO.js +104 -0
- package/dist/chunk-2SQK6TIO.js.map +1 -0
- package/dist/index.d.ts +378 -0
- package/dist/index.js +4391 -0
- package/dist/index.js.map +1 -0
- package/dist/server/index.d.ts +1210 -0
- package/dist/server/index.js +9 -0
- package/dist/server/index.js.map +1 -0
- package/package.json +79 -16
- package/src/askUserQuestion.ts +38 -0
- package/src/attachmentAdapter.ts +63 -0
- package/src/collectPending.ts +167 -0
- package/src/constants.ts +2 -0
- package/src/convertTurnMessages.ts +1679 -0
- package/src/createSubAgent.ts +11 -0
- package/src/draft/agentSpec.ts +34 -0
- package/src/draft/draftSessionBridge.ts +28 -0
- package/src/draft/trueforgeDraftThreadListAdapter.ts +73 -0
- package/src/draft/useDraftAgentSpec.ts +289 -0
- package/src/extractTurnUserText.ts +23 -0
- package/src/foldPeerThreads.ts +553 -0
- package/src/hooks.ts +176 -0
- package/src/index.ts +227 -0
- package/src/lastUserMessageText.ts +19 -0
- package/src/listPages.ts +19 -0
- package/src/loadSessionSnapshot.ts +34 -0
- package/src/mcpAuth.ts +35 -0
- package/src/messageCustomMetadata.ts +50 -0
- package/src/modelMessageContent.ts +149 -0
- package/src/modelMessageImageContent.ts +154 -0
- package/src/requiredActionInputs.ts +38 -0
- package/src/sandboxDownload.ts +33 -0
- package/src/server/eventUtils.ts +125 -0
- package/src/server/events.ts +232 -0
- package/src/server/index.ts +178 -0
- package/src/server/types.ts +1191 -0
- package/src/sessionListStartTimestamp.ts +6 -0
- package/src/sessionSnapshot.ts +146 -0
- package/src/sessionThreadMetadata.ts +36 -0
- package/src/sessions.ts +17 -0
- package/src/streamTurn.ts +118 -0
- package/src/toolApproval.ts +413 -0
- package/src/toolResponse.ts +346 -0
- package/src/trueforgeExtras.ts +223 -0
- package/src/trueforgeOwnedSessionsThreadListAdapter.ts +71 -0
- package/src/trueforgeThreadListAdapter.ts +69 -0
- package/src/turnEventHelpers.ts +71 -0
- package/src/turnStreamUpdate.ts +11 -0
- package/src/types.ts +84 -0
- package/src/useTrueForgeAgentMessages.ts +1138 -0
- package/src/useTrueForgeAgentRuntime.ts +308 -0
- package/index.js +0 -6
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,378 @@
|
|
|
1
|
+
import * as _assistant_ui_core from '@assistant-ui/core';
|
|
2
|
+
import { AttachmentAdapter, ThreadAssistantMessagePart, ThreadMessage, AppendMessage, ExportedMessageRepositoryItem, RemoteThreadListAdapter, ExternalStoreSharedOptions, SpeechSynthesisAdapter, DictationAdapter, RealtimeVoiceAdapter, FeedbackAdapter } from '@assistant-ui/core';
|
|
3
|
+
import { TurnEvent, ThreadCreatedEvent, UserToolResponseEvent, McpAuthRequiredEvent, UserToolApprovalEvent, Turn, TurnInputItem, AgentChatServer, AgentSpec, Session } from './server/index.js';
|
|
4
|
+
export { AgentBuilderCapabilitiesResponse, AgentBuilderServer, AgentCapabilityConfig, AgentCompactionConfig, AgentContextManagementConfig, AgentDetail, AgentInputTokensCompactionTrigger, AgentLibraryEntry, AgentMetricChartData, AgentMetricChartDataRequest, AgentMetricChartDefinition, AgentMetricChartType, AgentMetricGraph, AgentMetricGraphLine, AgentMetricMeter, AgentMetricPoint, AgentMetricRangeRequest, AgentMetricsServer, AgentRuntimeConfig, AgentSandboxConfig, AgentSelectorEntry, AgentSessionsServer, AgentSkill, AgentUIServer, AgentUIServerPort, ApprovalDecision, AuthenticateConnectorRequest, CatalogServer, CodeSnippet, CodeSnippetSampleCode, ConnectorAuth, ConnectorAuthApiKey, ConnectorAuthNone, ConnectorAuthOAuth, ConnectorAuthPublic, ConnectorAuthPublicApiKey, ConnectorAuthPublicNone, ConnectorAuthPublicOAuth, ConnectorAuthType, ConnectorAuthenticationResult, ConnectorBase, ConnectorCatalogEntry, ConnectorCatalogServer, ConnectorConfigBase, ConnectorSelectorEntry, ConnectorState, CreateConnectorRequest, CreateModelProviderRequest, CreateSandboxProviderRequest, CreateSandboxRequest, CreateScheduleRequest, CreateScheduleRunRequest, CreateSessionRequest, CreateSkillRequest, CreateSkillRequestBase, CreateWebSearchProviderRequest, CreateWebSearchRequest, CreatedBySubject, DefinedSkill, GithubSkill, ImportGithubSkillRequest, ListPermissionsRequest, ListPermissionsResponse, ListResult, ListSchedulesParams, ListSessionEventsParams, ListSessionsOrder, ListSessionsParams, McpServerMount, McpToolSelection, Model, ModelCatalogServer, ModelEntry, ModelMessageEvent, ModelParams, ModelProperties, ModelProviderBase, ModelProviderCatalogEntry, ModelProviderConfigBase, ModelSelection, ModelSelectorEntry, PageParams, PermissionResourceType, PermissionsServer, PreviousTurnIdInput, ProviderEntry, ProviderType, RegistrySkill, ResourcePermission, SandboxBase, SandboxCatalogEntry, SandboxCatalogServer, SandboxConfig, SandboxCreatedEvent, SandboxProviderBase, SandboxProviderCatalogEntry, SandboxProviderConfig, SandboxProviderListEntry, SandboxSnapshotSyncStatus, SaveAgentRequest, SaveAgentResult, Schedule, ScheduleRun, ScheduleRunStatus, ScheduleServer, ScheduleStatus, SearchAgentSelectorParams, SearchAgentsParams, SelectRegistrySkillRequest, SessionEventItem, SessionListEntry, SessionListMetrics, SkillBase, SkillCatalogEntry, SkillCatalogServer, SkillConfigBase, SkillMount, SkillSelectorEntry, ToolApprovalRequiredEvent, ToolBase, ToolCall, ToolResponseRequiredEvent, TurnDoneMetrics, TurnState, TurnStateDone, TurnStreamData, TurnStreamingEvent, UpdateConnectorRequest, UpdateModelProviderRequest, UpdateSandboxProviderRequest, UpdateSandboxRequest, UpdateScheduleRequest, UpdateSessionRequest, UpdateWebSearchProviderRequest, UpdateWebSearchRequest, UserMessage, WebSearchBase, WebSearchCatalogEntry, WebSearchCatalogServer, WebSearchProviderBase, WebSearchProviderCatalogEntry, isEventDelta, mergeEventDelta } from './server/index.js';
|
|
5
|
+
import { AssistantClient } from '@assistant-ui/store';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Reads composer files into `CompleteAttachment` `file` parts for send.
|
|
9
|
+
* Wire via `adapters: { attachments: trueForgeAttachmentAdapter }`.
|
|
10
|
+
*/
|
|
11
|
+
declare const trueForgeAttachmentAdapter: AttachmentAdapter;
|
|
12
|
+
|
|
13
|
+
interface PendingApproval {
|
|
14
|
+
approvalId: string;
|
|
15
|
+
threadId: string;
|
|
16
|
+
toolName: string;
|
|
17
|
+
args: Record<string, unknown>;
|
|
18
|
+
argsText: string;
|
|
19
|
+
}
|
|
20
|
+
interface PendingToolResponse {
|
|
21
|
+
toolCallId: string;
|
|
22
|
+
threadId: string;
|
|
23
|
+
toolName: string;
|
|
24
|
+
args: Record<string, unknown>;
|
|
25
|
+
argsText: string;
|
|
26
|
+
question?: string;
|
|
27
|
+
options?: string[];
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** Gateway root thread id — always the literal `"main"`. */
|
|
31
|
+
declare const ROOT_THREAD_ID = "main";
|
|
32
|
+
|
|
33
|
+
type AssistantContentPart = ThreadAssistantMessagePart;
|
|
34
|
+
|
|
35
|
+
type AgentInfo = ThreadCreatedEvent['agentInfo'];
|
|
36
|
+
interface SubAgentCustomMetadata {
|
|
37
|
+
threadId: string;
|
|
38
|
+
title?: string;
|
|
39
|
+
name?: string;
|
|
40
|
+
model?: string;
|
|
41
|
+
input?: string;
|
|
42
|
+
}
|
|
43
|
+
interface SubAgentArtifact {
|
|
44
|
+
subAgents: {
|
|
45
|
+
threadId: string;
|
|
46
|
+
title?: string;
|
|
47
|
+
agentInfo?: AgentInfo;
|
|
48
|
+
}[];
|
|
49
|
+
}
|
|
50
|
+
interface PendingResponseRef {
|
|
51
|
+
id: string;
|
|
52
|
+
sourceEventId: string;
|
|
53
|
+
question?: string;
|
|
54
|
+
options?: string[];
|
|
55
|
+
}
|
|
56
|
+
interface ApprovalDecisionRef {
|
|
57
|
+
id: string;
|
|
58
|
+
approved: boolean;
|
|
59
|
+
reason?: string;
|
|
60
|
+
}
|
|
61
|
+
interface ThreadBucket {
|
|
62
|
+
events: Map<string, TurnEvent>;
|
|
63
|
+
modelMessageIds: string[];
|
|
64
|
+
toolResults: Map<string, string>;
|
|
65
|
+
pendingApprovals: Map<string, {
|
|
66
|
+
id: string;
|
|
67
|
+
}>;
|
|
68
|
+
approvalDecisions: Map<string, ApprovalDecisionRef>;
|
|
69
|
+
pendingResponses: Map<string, PendingResponseRef>;
|
|
70
|
+
done: boolean;
|
|
71
|
+
title?: string;
|
|
72
|
+
agentInfo?: AgentInfo;
|
|
73
|
+
}
|
|
74
|
+
interface ThreadParentLink {
|
|
75
|
+
parentThreadId: string;
|
|
76
|
+
toolCallId: string;
|
|
77
|
+
}
|
|
78
|
+
declare class PeerThreadFoldState {
|
|
79
|
+
readonly threads: Map<string, ThreadBucket>;
|
|
80
|
+
readonly threadParents: Map<string, ThreadParentLink>;
|
|
81
|
+
getOrCreateBucket(threadId: string): ThreadBucket;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
declare const TOOL_RESPONSE_THREAD_ID_CUSTOM_KEY = "toolResponseThreadId";
|
|
85
|
+
type RespondToToolResponseOptions = Pick<UserToolResponseEvent, 'toolCallId' | 'content'>;
|
|
86
|
+
declare function messageHasPendingResponses(message: ThreadMessage | undefined): boolean;
|
|
87
|
+
declare function collectResponseInputs(message: ThreadMessage, threadId: string): UserToolResponseEvent[];
|
|
88
|
+
|
|
89
|
+
/** Keys written to `ThreadMessage.metadata.custom` by this runtime adapter. */
|
|
90
|
+
interface TrueForgeMessageCustomMetadata {
|
|
91
|
+
subAgent?: SubAgentCustomMetadata;
|
|
92
|
+
pendingMcpAuth?: true;
|
|
93
|
+
mcpServers?: McpAuthRequiredEvent['mcpServers'];
|
|
94
|
+
sandboxId?: string;
|
|
95
|
+
/** Turn that produced this message. Scopes artifact downloads to their own turn. */
|
|
96
|
+
turnId?: string;
|
|
97
|
+
[TOOL_APPROVAL_THREAD_ID_CUSTOM_KEY]?: string;
|
|
98
|
+
[TOOL_RESPONSE_THREAD_ID_CUSTOM_KEY]?: string;
|
|
99
|
+
}
|
|
100
|
+
type SubAgentMessageCustomMetadata = Pick<TrueForgeMessageCustomMetadata, 'subAgent'>;
|
|
101
|
+
type McpAuthMessageCustomMetadata = Pick<TrueForgeMessageCustomMetadata, 'pendingMcpAuth' | 'mcpServers'>;
|
|
102
|
+
type SandboxMessageCustomMetadata = Pick<TrueForgeMessageCustomMetadata, 'sandboxId'>;
|
|
103
|
+
type ToolApprovalMessageCustomMetadata = Pick<TrueForgeMessageCustomMetadata, typeof TOOL_APPROVAL_THREAD_ID_CUSTOM_KEY>;
|
|
104
|
+
type ToolResponseMessageCustomMetadata = Pick<TrueForgeMessageCustomMetadata, typeof TOOL_RESPONSE_THREAD_ID_CUSTOM_KEY>;
|
|
105
|
+
|
|
106
|
+
declare const TOOL_APPROVAL_THREAD_ID_CUSTOM_KEY = "toolApprovalThreadId";
|
|
107
|
+
interface RespondToToolApprovalOptions {
|
|
108
|
+
approvalId: string;
|
|
109
|
+
approved: boolean;
|
|
110
|
+
optionId?: string;
|
|
111
|
+
reason?: string;
|
|
112
|
+
}
|
|
113
|
+
declare function messageHasPendingApprovals(message: ThreadMessage | undefined): boolean;
|
|
114
|
+
declare function collectApprovalInputs(message: ThreadMessage, threadId: string): UserToolApprovalEvent[];
|
|
115
|
+
declare function toTrueForgeApprovalInputs(message: Extract<ThreadMessage, {
|
|
116
|
+
role: 'assistant';
|
|
117
|
+
}>, response: RespondToToolApprovalOptions, defaultThreadId?: string): UserToolApprovalEvent[];
|
|
118
|
+
|
|
119
|
+
interface ConvertTurnsResult {
|
|
120
|
+
messages: ThreadMessage[];
|
|
121
|
+
foldState: PeerThreadFoldState;
|
|
122
|
+
runningTurn?: Turn;
|
|
123
|
+
unstable_resume?: boolean;
|
|
124
|
+
}
|
|
125
|
+
declare function buildTurnAssistantContent(server: AgentChatServer, sessionId: string, turn: Pick<Turn, 'id' | 'state'>, foldState?: PeerThreadFoldState): Promise<AssistantContentPart[]>;
|
|
126
|
+
declare function convertTurnsToThreadMessages(server: AgentChatServer, sessionId: string): Promise<ConvertTurnsResult>;
|
|
127
|
+
declare function getTurnMessageContent(message: AppendMessage): string;
|
|
128
|
+
/**
|
|
129
|
+
* Gateway `user.message` content (string for text-only, or text/file parts).
|
|
130
|
+
* Derived from SDK `TurnInputItem` so it tracks API changes.
|
|
131
|
+
*/
|
|
132
|
+
type UserMessageContent = Extract<TurnInputItem, {
|
|
133
|
+
type: 'user.message';
|
|
134
|
+
}>['content'];
|
|
135
|
+
/**
|
|
136
|
+
* Builds the gateway turn input content from a composer message, forwarding
|
|
137
|
+
* attachments as SDK `FileContent` parts. Mirrors how assistant-ui surfaces
|
|
138
|
+
* attachment content on `message.attachments[].content`.
|
|
139
|
+
*/
|
|
140
|
+
declare function buildUserMessageContent(message: AppendMessage): UserMessageContent;
|
|
141
|
+
/** Strips the `-user` suffix from a projected user message id to recover the turn id. */
|
|
142
|
+
declare function parseTurnIdFromMessageId(messageId: string): string;
|
|
143
|
+
/**
|
|
144
|
+
* Builds resubmit content for a text-only edit: replaces text with `editedText`
|
|
145
|
+
* while preserving original file parts from the turn record.
|
|
146
|
+
*/
|
|
147
|
+
declare function buildEditedUserMessageContent(editedText: string, originalInput: TurnInputItem[] | undefined): UserMessageContent;
|
|
148
|
+
declare function repositoryItemsFromMessages(messages: readonly ThreadMessage[]): ExportedMessageRepositoryItem[];
|
|
149
|
+
|
|
150
|
+
interface DraftSession {
|
|
151
|
+
title?: string | null;
|
|
152
|
+
agentSpec: AgentSpec;
|
|
153
|
+
}
|
|
154
|
+
/** Partial update — host fields flow through when `TSpec` is widened. */
|
|
155
|
+
type AgentSpecUpdate<TSpec extends AgentSpec = AgentSpec> = {
|
|
156
|
+
[K in keyof TSpec]?: K extends 'model' ? Omit<Partial<TSpec['model']>, 'params'> & {
|
|
157
|
+
params?: Partial<NonNullable<TSpec['model']['params']>>;
|
|
158
|
+
} : TSpec[K];
|
|
159
|
+
};
|
|
160
|
+
declare function mergeAgentSpec<TSpec extends AgentSpec>(base: TSpec, update: AgentSpecUpdate<TSpec>): TSpec;
|
|
161
|
+
declare function draftSessionTitle(draft: DraftSession): string;
|
|
162
|
+
|
|
163
|
+
interface DraftSessionBridge {
|
|
164
|
+
syncAgentSpec: (draftSessionId: string, agentSpec: AgentSpec) => Promise<string>;
|
|
165
|
+
getDraftAgentSpec: (draftSessionId: string) => Promise<AgentSpec>;
|
|
166
|
+
}
|
|
167
|
+
declare function createDraftSessionBridge(server: AgentChatServer): DraftSessionBridge;
|
|
168
|
+
|
|
169
|
+
declare function createTrueForgeDraftThreadListAdapter(options: {
|
|
170
|
+
server: AgentChatServer;
|
|
171
|
+
defaultAgentSpec: AgentSpec;
|
|
172
|
+
getAgentSpec?: () => AgentSpec;
|
|
173
|
+
/** When set, filters `listSessions` by this agent id. Omit for all chats. */
|
|
174
|
+
listSessionsAgentId?: string;
|
|
175
|
+
/** Restrict history to sessions created by the authenticated subject. */
|
|
176
|
+
listSessionsCreatedByMe?: boolean;
|
|
177
|
+
}): RemoteThreadListAdapter;
|
|
178
|
+
|
|
179
|
+
interface TrueForgeDraftRuntimeExtras {
|
|
180
|
+
agentSpec: AgentSpec | null;
|
|
181
|
+
draftSessionId: string | undefined;
|
|
182
|
+
isSpecLoading: boolean;
|
|
183
|
+
isSpecSyncing: boolean;
|
|
184
|
+
specError: unknown;
|
|
185
|
+
updateAgentSpec: (update: AgentSpecUpdate) => void;
|
|
186
|
+
flushAgentSpec: () => Promise<void>;
|
|
187
|
+
adoptAgentSpec: (request: {
|
|
188
|
+
agentSpec: AgentSpec;
|
|
189
|
+
updatedAt?: string;
|
|
190
|
+
}) => void;
|
|
191
|
+
}
|
|
192
|
+
interface TrueForgeRuntimeExtras {
|
|
193
|
+
pendingApprovals: PendingApproval[];
|
|
194
|
+
pendingToolResponses: PendingToolResponse[];
|
|
195
|
+
pendingMcpAuth: {
|
|
196
|
+
mcpServers: McpAuthRequiredEvent['mcpServers'];
|
|
197
|
+
} | null;
|
|
198
|
+
resumeUnavailable: boolean;
|
|
199
|
+
sandboxId: string | undefined;
|
|
200
|
+
respondToToolApproval: (response: RespondToToolApprovalOptions) => void;
|
|
201
|
+
respondToToolResponse: (response: RespondToToolResponseOptions) => void;
|
|
202
|
+
resumeMcpAuth: () => Promise<void>;
|
|
203
|
+
downloadSandboxFile: (req: {
|
|
204
|
+
turnId: string;
|
|
205
|
+
path: string;
|
|
206
|
+
}) => Promise<Blob>;
|
|
207
|
+
cancel: () => Promise<void>;
|
|
208
|
+
resetFromTurn: (turnId: string) => Promise<void>;
|
|
209
|
+
reload: () => void;
|
|
210
|
+
hasOlderHistory: boolean;
|
|
211
|
+
isLoadingOlderHistory: boolean;
|
|
212
|
+
loadOlderHistory: () => Promise<void>;
|
|
213
|
+
draft: TrueForgeDraftRuntimeExtras | null;
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* `PartPrimitive.Messages` wraps sub-agent threads in `ReadonlyThreadProvider`,
|
|
217
|
+
* which shadows `thread` (and therefore `thread.extras`) with a readonly client
|
|
218
|
+
* that has no TrueForge extras. Nested AUI clients are `Object.create(parent)`,
|
|
219
|
+
* so walk the prototype chain to reach the root runtime extras.
|
|
220
|
+
*/
|
|
221
|
+
declare function tryGetTrueForgeExtras(client: AssistantClient): TrueForgeRuntimeExtras | undefined;
|
|
222
|
+
declare function getTrueForgeExtras(client: AssistantClient): TrueForgeRuntimeExtras;
|
|
223
|
+
declare function useTrueForgeExtrasApi(): TrueForgeRuntimeExtras;
|
|
224
|
+
declare function useTrueForgeExtrasApi<S>(select: (extras: TrueForgeRuntimeExtras) => S, fallback?: S): S;
|
|
225
|
+
/**
|
|
226
|
+
* Brand + provide/tryGet from assistant-ui; get/use walk ancestor AUI clients so
|
|
227
|
+
* nested readonly sub-agent threads still resolve root TrueForge extras.
|
|
228
|
+
*/
|
|
229
|
+
declare const trueForgeExtras: {
|
|
230
|
+
provide: (value: TrueForgeRuntimeExtras) => TrueForgeRuntimeExtras;
|
|
231
|
+
is: (extras: unknown) => extras is TrueForgeRuntimeExtras;
|
|
232
|
+
tryGet: (extras: unknown) => TrueForgeRuntimeExtras | undefined;
|
|
233
|
+
get: typeof getTrueForgeExtras;
|
|
234
|
+
use: typeof useTrueForgeExtrasApi;
|
|
235
|
+
};
|
|
236
|
+
|
|
237
|
+
/** Pending tool approvals plus a respond action. */
|
|
238
|
+
declare const useTrueForgeApprovals: () => {
|
|
239
|
+
pending: PendingApproval[];
|
|
240
|
+
respond: (response: RespondToToolApprovalOptions) => void;
|
|
241
|
+
};
|
|
242
|
+
/** Pending ask-user tool responses plus a respond action. */
|
|
243
|
+
declare const useTrueForgeToolResponses: () => {
|
|
244
|
+
pending: PendingToolResponse[];
|
|
245
|
+
respond: (response: RespondToToolResponseOptions) => void;
|
|
246
|
+
};
|
|
247
|
+
/** Pending MCP OAuth plus a resume action. */
|
|
248
|
+
declare const useTrueForgeMcpAuth: () => {
|
|
249
|
+
pending: {
|
|
250
|
+
mcpServers: McpAuthRequiredEvent["mcpServers"];
|
|
251
|
+
} | null;
|
|
252
|
+
resume: () => Promise<void>;
|
|
253
|
+
};
|
|
254
|
+
/** Returns a function to respond to a tool approval from any render context. */
|
|
255
|
+
declare const useTrueForgeRespondToToolApproval: () => (response: RespondToToolApprovalOptions) => void;
|
|
256
|
+
/** Returns a function to respond to a pending tool response from any render context. */
|
|
257
|
+
declare const useTrueForgeRespondToToolResponse: () => (response: RespondToToolResponseOptions) => void;
|
|
258
|
+
/** Returns a function to resume after MCP OAuth from any render context. */
|
|
259
|
+
declare const useTrueForgeResumeMcpAuth: () => () => Promise<void>;
|
|
260
|
+
/** Current sandboxId for this session, if a sandbox has been created. */
|
|
261
|
+
declare const useTrueForgeSandboxId: () => string | undefined;
|
|
262
|
+
/** Turn that produced the message being rendered. Only defined inside a message scope. */
|
|
263
|
+
declare const useTrueForgeTurnId: () => string | undefined;
|
|
264
|
+
/**
|
|
265
|
+
* Returns a function to download a file the current turn wrote to its sandbox. Must be called
|
|
266
|
+
* from a message scope, since the artifact belongs to the turn that rendered it.
|
|
267
|
+
* Does not require extras `sandboxId` — turn-scoped hosts resolve the sandbox from `turnId`.
|
|
268
|
+
*/
|
|
269
|
+
declare const useTrueForgeDownloadSandboxFile: () => (path: string) => Promise<Blob>;
|
|
270
|
+
/** Returns a function to cancel the current run from any render context. */
|
|
271
|
+
declare const useTrueForgeCancel: () => () => Promise<void>;
|
|
272
|
+
/** Returns a function to reload (retry) the current session from any render context. */
|
|
273
|
+
declare const useTrueForgeReload: () => () => void;
|
|
274
|
+
/** Older history pagination state plus a load-more action for scroll-up. */
|
|
275
|
+
declare const useTrueForgeHistoryPagination: () => {
|
|
276
|
+
hasOlderHistory: boolean;
|
|
277
|
+
isLoadingOlderHistory: boolean;
|
|
278
|
+
loadOlderHistory: () => Promise<void>;
|
|
279
|
+
};
|
|
280
|
+
/**
|
|
281
|
+
* True while a turn runs that this server cannot stream, so its result will not
|
|
282
|
+
* arrive in this client. Falls back to `false` on runtimes that predate the flag.
|
|
283
|
+
*/
|
|
284
|
+
declare const useTrueForgeResumeUnavailable: () => boolean;
|
|
285
|
+
/** Returns a function to reset (re-submit) a user turn from any render context. */
|
|
286
|
+
declare const useTrueForgeResetFromTurn: () => (turnId: string) => Promise<void>;
|
|
287
|
+
/** Current draft agent spec and sync state (draft mode only). */
|
|
288
|
+
declare const useTrueForgeAgentSpec: () => {
|
|
289
|
+
agentSpec: AgentSpec | null;
|
|
290
|
+
draftSessionId: string | undefined;
|
|
291
|
+
isSpecLoading: boolean;
|
|
292
|
+
isSpecSyncing: boolean;
|
|
293
|
+
specError: unknown;
|
|
294
|
+
updateAgentSpec: (update: AgentSpecUpdate) => void;
|
|
295
|
+
flushAgentSpec: () => Promise<void>;
|
|
296
|
+
adoptAgentSpec: (request: {
|
|
297
|
+
agentSpec: AgentSpec;
|
|
298
|
+
updatedAt?: string;
|
|
299
|
+
}) => void;
|
|
300
|
+
};
|
|
301
|
+
/** Returns a draft spec updater from any render context. */
|
|
302
|
+
declare const useTrueForgeUpdateAgentSpec: () => (update: Parameters<TrueForgeDraftRuntimeExtras["updateAgentSpec"]>[0]) => void | undefined;
|
|
303
|
+
/** Flushes any pending draft-spec synchronization before a coordinated write. */
|
|
304
|
+
declare const useTrueForgeFlushAgentSpec: () => () => Promise<void>;
|
|
305
|
+
/** Adopts a spec already persisted by another server operation without syncing again. */
|
|
306
|
+
declare const useTrueForgeAdoptAgentSpec: () => (request: Parameters<TrueForgeDraftRuntimeExtras["adoptAgentSpec"]>[0]) => void | undefined;
|
|
307
|
+
|
|
308
|
+
type RequiredActionInput = Extract<TurnInputItem, UserToolApprovalEvent | UserToolResponseEvent>;
|
|
309
|
+
declare function messageHasPendingRequiredActions(message: ThreadMessage | undefined): boolean;
|
|
310
|
+
declare function collectRequiredActionInputs(message: ThreadMessage, defaultThreadId?: string): RequiredActionInput[];
|
|
311
|
+
declare function findPausedAssistantMessage(messages: readonly ThreadMessage[]): Extract<ThreadMessage, {
|
|
312
|
+
role: 'assistant';
|
|
313
|
+
}> | undefined;
|
|
314
|
+
|
|
315
|
+
/** `sessionId` is the assistant-ui thread `remoteId` from `RemoteThreadListAdapter.initialize`. */
|
|
316
|
+
declare function getSession(server: AgentChatServer, sessionId: string): Promise<Session>;
|
|
317
|
+
|
|
318
|
+
/**
|
|
319
|
+
* Read-only thread-list adapter backed by `AgentChatServer.listSessions`.
|
|
320
|
+
*/
|
|
321
|
+
declare function createTrueForgeOwnedSessionsThreadListAdapter(options: {
|
|
322
|
+
server: AgentChatServer;
|
|
323
|
+
/** When set, filters `listSessions` by this agent id. Omit for all chats. */
|
|
324
|
+
listSessionsAgentId?: string;
|
|
325
|
+
/** Restrict history to sessions created by the authenticated subject. */
|
|
326
|
+
listSessionsCreatedByMe?: boolean;
|
|
327
|
+
}): RemoteThreadListAdapter;
|
|
328
|
+
|
|
329
|
+
declare function createTrueForgeThreadListAdapter(options: {
|
|
330
|
+
server: AgentChatServer;
|
|
331
|
+
agentName: string;
|
|
332
|
+
/** When set, filters `listSessions` by this agent id. Omit for all chats. */
|
|
333
|
+
listSessionsAgentId?: string;
|
|
334
|
+
/** Restrict history to sessions created by the authenticated subject. */
|
|
335
|
+
listSessionsCreatedByMe?: boolean;
|
|
336
|
+
}): RemoteThreadListAdapter;
|
|
337
|
+
|
|
338
|
+
interface NamedAgentConfig {
|
|
339
|
+
mode: 'named';
|
|
340
|
+
agentName: string;
|
|
341
|
+
}
|
|
342
|
+
interface DraftAgentConfig {
|
|
343
|
+
mode: 'draft';
|
|
344
|
+
defaultAgentSpec: AgentSpec;
|
|
345
|
+
onAgentSpecChange?: ((spec: AgentSpec) => void) | undefined;
|
|
346
|
+
}
|
|
347
|
+
type TrueForgeAgentConfig = NamedAgentConfig | DraftAgentConfig;
|
|
348
|
+
type TrueForgeAgentRuntimeBaseOptions = ExternalStoreSharedOptions & {
|
|
349
|
+
server: AgentChatServer;
|
|
350
|
+
initialSessionId?: string | undefined;
|
|
351
|
+
threadId?: string | undefined;
|
|
352
|
+
onThreadIdChange?: ((threadId: string | undefined) => void) | undefined;
|
|
353
|
+
onError?: ((error: unknown) => void) | undefined;
|
|
354
|
+
/**
|
|
355
|
+
* Optional filter forwarded to `listSessions({ agentId })`.
|
|
356
|
+
* Omit for all chats; hosts that key agents by name pass that name as the id.
|
|
357
|
+
*/
|
|
358
|
+
listSessionsAgentId?: string | undefined;
|
|
359
|
+
/** Restrict thread history to sessions created by the authenticated subject. */
|
|
360
|
+
listSessionsCreatedByMe?: boolean | undefined;
|
|
361
|
+
adapters?: {
|
|
362
|
+
attachments?: AttachmentAdapter | undefined;
|
|
363
|
+
speech?: SpeechSynthesisAdapter | undefined;
|
|
364
|
+
dictation?: DictationAdapter | undefined;
|
|
365
|
+
voice?: RealtimeVoiceAdapter | undefined;
|
|
366
|
+
feedback?: FeedbackAdapter | undefined;
|
|
367
|
+
} | undefined;
|
|
368
|
+
};
|
|
369
|
+
type UseTrueForgeAgentRuntimeOptions = TrueForgeAgentRuntimeBaseOptions & {
|
|
370
|
+
/** Discriminated agent source. Omit when using legacy `agentName`. */
|
|
371
|
+
agent?: TrueForgeAgentConfig | undefined;
|
|
372
|
+
/** Legacy named-agent shorthand. Prefer `agent: { mode: "named", agentName }`. */
|
|
373
|
+
agentName?: string | undefined;
|
|
374
|
+
};
|
|
375
|
+
|
|
376
|
+
declare function useTrueForgeAgentRuntime(options: UseTrueForgeAgentRuntimeOptions): _assistant_ui_core.AssistantRuntime;
|
|
377
|
+
|
|
378
|
+
export { AgentChatServer, AgentSpec, type AgentSpecUpdate, type ConvertTurnsResult, type DraftAgentConfig, type DraftSession, type DraftSessionBridge, type McpAuthMessageCustomMetadata, McpAuthRequiredEvent, type NamedAgentConfig, type PendingApproval, type PendingToolResponse, ROOT_THREAD_ID, type SandboxMessageCustomMetadata, Session, type SubAgentArtifact, type SubAgentCustomMetadata, type SubAgentMessageCustomMetadata, TOOL_RESPONSE_THREAD_ID_CUSTOM_KEY, ThreadCreatedEvent, type ToolApprovalMessageCustomMetadata, type ToolResponseMessageCustomMetadata, type TrueForgeAgentConfig, type TrueForgeDraftRuntimeExtras, type TrueForgeMessageCustomMetadata, type TrueForgeRuntimeExtras, Turn, TurnEvent, TurnInputItem, type UseTrueForgeAgentRuntimeOptions, type UserMessageContent, UserToolApprovalEvent, UserToolResponseEvent, buildEditedUserMessageContent, buildTurnAssistantContent, buildUserMessageContent, collectApprovalInputs, collectRequiredActionInputs, collectResponseInputs, convertTurnsToThreadMessages, createDraftSessionBridge, createTrueForgeDraftThreadListAdapter, createTrueForgeOwnedSessionsThreadListAdapter, createTrueForgeThreadListAdapter, draftSessionTitle, findPausedAssistantMessage, getSession, getTrueForgeExtras, getTurnMessageContent, mergeAgentSpec, messageHasPendingApprovals, messageHasPendingRequiredActions, messageHasPendingResponses, parseTurnIdFromMessageId, repositoryItemsFromMessages, toTrueForgeApprovalInputs, trueForgeAttachmentAdapter, trueForgeExtras, tryGetTrueForgeExtras, useTrueForgeAdoptAgentSpec, useTrueForgeAgentRuntime, useTrueForgeAgentSpec, useTrueForgeApprovals, useTrueForgeCancel, useTrueForgeDownloadSandboxFile, useTrueForgeFlushAgentSpec, useTrueForgeHistoryPagination, useTrueForgeMcpAuth, useTrueForgeReload, useTrueForgeResetFromTurn, useTrueForgeRespondToToolApproval, useTrueForgeRespondToToolResponse, useTrueForgeResumeMcpAuth, useTrueForgeResumeUnavailable, useTrueForgeSandboxId, useTrueForgeToolResponses, useTrueForgeTurnId, useTrueForgeUpdateAgentSpec };
|