@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
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runtime-owned turn/stream event protocol.
|
|
3
|
+
*
|
|
4
|
+
* Hosts must emit events matching these shapes.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import type { TurnInputItem, TurnState } from './types.js';
|
|
8
|
+
|
|
9
|
+
// ---------------------------------------------------------------------------
|
|
10
|
+
// Tool call shapes
|
|
11
|
+
// ---------------------------------------------------------------------------
|
|
12
|
+
|
|
13
|
+
export interface ToolCallFunction {
|
|
14
|
+
name: string;
|
|
15
|
+
arguments: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export type ToolInfo =
|
|
19
|
+
| { type: 'trueforge-system'; name: string }
|
|
20
|
+
| { type: 'mcp'; serverId: string; serverName: string; name: string }
|
|
21
|
+
| { type: string; name?: string };
|
|
22
|
+
|
|
23
|
+
export interface ToolCall {
|
|
24
|
+
id: string;
|
|
25
|
+
type: 'function';
|
|
26
|
+
function: ToolCallFunction;
|
|
27
|
+
toolInfo?: ToolInfo;
|
|
28
|
+
providerSpecificFields?: Record<string, unknown>;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** Ref used by approval/response-required events. */
|
|
32
|
+
export interface ToolCallRef {
|
|
33
|
+
id: string;
|
|
34
|
+
sourceEventId: string;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export interface ChunkDeltaToolCall {
|
|
38
|
+
index: number;
|
|
39
|
+
id?: string;
|
|
40
|
+
type?: 'function';
|
|
41
|
+
function?: { name?: string; arguments?: string };
|
|
42
|
+
toolInfo?: ToolInfo;
|
|
43
|
+
providerSpecificFields?: Record<string, unknown>;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// ---------------------------------------------------------------------------
|
|
47
|
+
// Content events
|
|
48
|
+
// ---------------------------------------------------------------------------
|
|
49
|
+
|
|
50
|
+
export type ModelMessageContentPart =
|
|
51
|
+
| { type: 'text'; text: string }
|
|
52
|
+
| { type: 'refusal'; refusal: string }
|
|
53
|
+
| { type: 'image_url'; image_url: { url: string } };
|
|
54
|
+
|
|
55
|
+
export interface ModelMessageEvent {
|
|
56
|
+
type: 'model.message';
|
|
57
|
+
id: string;
|
|
58
|
+
threadId: string;
|
|
59
|
+
content?: string | ModelMessageContentPart[] | null;
|
|
60
|
+
name?: string;
|
|
61
|
+
refusal?: string | null;
|
|
62
|
+
reasoningContent?: string;
|
|
63
|
+
toolCalls?: ToolCall[];
|
|
64
|
+
finishReason?: string | null;
|
|
65
|
+
createdAt: string;
|
|
66
|
+
usage?: unknown;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export interface ModelMessageDeltaEvent {
|
|
70
|
+
type: 'model.message.delta';
|
|
71
|
+
id: string;
|
|
72
|
+
threadId: string;
|
|
73
|
+
content?: string | null;
|
|
74
|
+
refusal?: string | null;
|
|
75
|
+
reasoningContent?: string;
|
|
76
|
+
toolCalls?: ChunkDeltaToolCall[];
|
|
77
|
+
finishReason?: string | null;
|
|
78
|
+
createdAt?: string;
|
|
79
|
+
usage?: unknown;
|
|
80
|
+
/** Extended content-block deltas (image streaming). */
|
|
81
|
+
contentBlocks?: {
|
|
82
|
+
index: number;
|
|
83
|
+
delta: { type: 'text'; text?: string } | { type: 'image_url'; image_url?: { url?: string } };
|
|
84
|
+
}[];
|
|
85
|
+
content_blocks?: {
|
|
86
|
+
index: number;
|
|
87
|
+
delta: { type: 'text'; text?: string } | { type: 'image_url'; image_url?: { url?: string } };
|
|
88
|
+
}[];
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export interface ToolResponseEvent {
|
|
92
|
+
type: 'tool.response';
|
|
93
|
+
id: string;
|
|
94
|
+
threadId: string;
|
|
95
|
+
toolCallId: string;
|
|
96
|
+
content: string;
|
|
97
|
+
createdAt: string;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export interface ToolApprovalRequiredEvent {
|
|
101
|
+
type: 'tool.approval_required';
|
|
102
|
+
id: string;
|
|
103
|
+
createdAt: string;
|
|
104
|
+
threadId: string;
|
|
105
|
+
toolCalls: ToolCallRef[];
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export interface ToolResponseRequiredEvent {
|
|
109
|
+
type: 'tool.response_required';
|
|
110
|
+
id: string;
|
|
111
|
+
createdAt: string;
|
|
112
|
+
threadId: string;
|
|
113
|
+
toolCalls: ToolCallRef[];
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export interface AgentInfo {
|
|
117
|
+
type?: string;
|
|
118
|
+
name: string;
|
|
119
|
+
input: string;
|
|
120
|
+
model?: string;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export interface AgentParent {
|
|
124
|
+
threadId: string;
|
|
125
|
+
toolCallId: string;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export interface ThreadCreatedEvent {
|
|
129
|
+
type: 'thread.created';
|
|
130
|
+
id: string;
|
|
131
|
+
threadId: string;
|
|
132
|
+
title: string;
|
|
133
|
+
agentInfo: AgentInfo;
|
|
134
|
+
parent: AgentParent;
|
|
135
|
+
createdAt: string;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export interface ThreadDoneEvent {
|
|
139
|
+
type: 'thread.done';
|
|
140
|
+
id: string;
|
|
141
|
+
threadId: string;
|
|
142
|
+
title?: string;
|
|
143
|
+
createdAt: string;
|
|
144
|
+
state?: unknown;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export interface McpServerAuthInfo {
|
|
148
|
+
id: string;
|
|
149
|
+
name: string;
|
|
150
|
+
authUrl: string;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
export interface McpAuthRequiredEvent {
|
|
154
|
+
type: 'mcp.auth_required';
|
|
155
|
+
id: string;
|
|
156
|
+
createdAt: string;
|
|
157
|
+
threadId?: string | null;
|
|
158
|
+
mcpServers: McpServerAuthInfo[];
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
export interface SandboxCreatedEvent {
|
|
162
|
+
type: 'sandbox.created';
|
|
163
|
+
id: string;
|
|
164
|
+
createdAt: string;
|
|
165
|
+
sandboxId: string;
|
|
166
|
+
threadId: string | null;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
export interface McpInitializeEvent {
|
|
170
|
+
type: 'mcp.initialize';
|
|
171
|
+
id: string;
|
|
172
|
+
createdAt: string;
|
|
173
|
+
threadId: string | null;
|
|
174
|
+
[key: string]: unknown;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
// ---------------------------------------------------------------------------
|
|
178
|
+
// Turn lifecycle events
|
|
179
|
+
// ---------------------------------------------------------------------------
|
|
180
|
+
|
|
181
|
+
export interface TurnCreatedEvent {
|
|
182
|
+
type: 'turn.created';
|
|
183
|
+
id: string;
|
|
184
|
+
turnId: string;
|
|
185
|
+
previousTurnId?: string | null;
|
|
186
|
+
input?: TurnInputItem[];
|
|
187
|
+
state?: { status: 'running' };
|
|
188
|
+
createdAt: string;
|
|
189
|
+
threadId?: string | null;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
export interface TurnDoneEvent {
|
|
193
|
+
type: 'turn.done';
|
|
194
|
+
id: string;
|
|
195
|
+
state: Exclude<TurnState, { status: 'running' }>;
|
|
196
|
+
createdAt: string;
|
|
197
|
+
threadId?: string | null;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
// ---------------------------------------------------------------------------
|
|
201
|
+
// Unions
|
|
202
|
+
// ---------------------------------------------------------------------------
|
|
203
|
+
|
|
204
|
+
/** Events stored in fold buckets (non-delta, non-turn-lifecycle). */
|
|
205
|
+
export type TurnEvent =
|
|
206
|
+
| ModelMessageEvent
|
|
207
|
+
| ToolResponseEvent
|
|
208
|
+
| ThreadCreatedEvent
|
|
209
|
+
| ThreadDoneEvent
|
|
210
|
+
| McpAuthRequiredEvent
|
|
211
|
+
| McpInitializeEvent
|
|
212
|
+
| SandboxCreatedEvent
|
|
213
|
+
| ToolApprovalRequiredEvent
|
|
214
|
+
| ToolResponseRequiredEvent;
|
|
215
|
+
|
|
216
|
+
/** Full streaming event union (includes deltas + turn lifecycle). */
|
|
217
|
+
export type TurnStreamingEvent = TurnEvent | ModelMessageDeltaEvent | TurnCreatedEvent | TurnDoneEvent;
|
|
218
|
+
|
|
219
|
+
export type ActionRequiredEvent = ToolApprovalRequiredEvent | ToolResponseRequiredEvent | McpAuthRequiredEvent;
|
|
220
|
+
|
|
221
|
+
export interface TurnStreamData<TStreamEvent extends TurnStreamingEvent = TurnStreamingEvent> {
|
|
222
|
+
sequenceNumber: number;
|
|
223
|
+
event: TStreamEvent;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/** Session-level event item from `listEvents`. */
|
|
227
|
+
export interface SessionEventItem {
|
|
228
|
+
turnId: string;
|
|
229
|
+
event: TurnCreatedEvent | TurnDoneEvent | TurnEvent;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
export type DeltaEvents = ModelMessageDeltaEvent;
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
export type {
|
|
2
|
+
AgentBuilderCapabilitiesResponse,
|
|
3
|
+
AgentBuilderServer,
|
|
4
|
+
AgentCapabilityConfig,
|
|
5
|
+
AgentChatServer,
|
|
6
|
+
AgentCompactionConfig,
|
|
7
|
+
AgentContextManagementConfig,
|
|
8
|
+
AgentDetail,
|
|
9
|
+
AgentInputTokensCompactionTrigger,
|
|
10
|
+
AgentLibraryEntry,
|
|
11
|
+
AgentMetricChartData,
|
|
12
|
+
AgentMetricChartDataRequest,
|
|
13
|
+
AgentMetricChartDefinition,
|
|
14
|
+
AgentMetricChartType,
|
|
15
|
+
AgentMetricGraph,
|
|
16
|
+
AgentMetricGraphLine,
|
|
17
|
+
AgentMetricMeter,
|
|
18
|
+
AgentMetricPoint,
|
|
19
|
+
AgentMetricRangeRequest,
|
|
20
|
+
AgentMetricsServer,
|
|
21
|
+
AgentRuntimeConfig,
|
|
22
|
+
AgentSandboxConfig,
|
|
23
|
+
AgentSelectorEntry,
|
|
24
|
+
AgentSessionsServer,
|
|
25
|
+
AgentSkill,
|
|
26
|
+
AgentSpec,
|
|
27
|
+
AgentUIServer,
|
|
28
|
+
AgentUIServerPort,
|
|
29
|
+
ApprovalDecision,
|
|
30
|
+
AuthenticateConnectorRequest,
|
|
31
|
+
CatalogServer,
|
|
32
|
+
CodeSnippet,
|
|
33
|
+
CodeSnippetSampleCode,
|
|
34
|
+
ConnectorAuth,
|
|
35
|
+
ConnectorAuthApiKey,
|
|
36
|
+
ConnectorAuthNone,
|
|
37
|
+
ConnectorAuthOAuth,
|
|
38
|
+
ConnectorAuthPublic,
|
|
39
|
+
ConnectorAuthPublicApiKey,
|
|
40
|
+
ConnectorAuthPublicNone,
|
|
41
|
+
ConnectorAuthPublicOAuth,
|
|
42
|
+
ConnectorAuthType,
|
|
43
|
+
ConnectorAuthenticationResult,
|
|
44
|
+
ConnectorBase,
|
|
45
|
+
ConnectorCatalogEntry,
|
|
46
|
+
ConnectorCatalogServer,
|
|
47
|
+
ConnectorConfigBase,
|
|
48
|
+
ConnectorSelectorEntry,
|
|
49
|
+
ConnectorState,
|
|
50
|
+
CreateConnectorRequest,
|
|
51
|
+
CreateModelProviderRequest,
|
|
52
|
+
CreateSandboxProviderRequest,
|
|
53
|
+
CreateSandboxRequest,
|
|
54
|
+
CreateScheduleRequest,
|
|
55
|
+
CreateScheduleRunRequest,
|
|
56
|
+
CreateSessionRequest,
|
|
57
|
+
CreateSkillRequest,
|
|
58
|
+
CreateSkillRequestBase,
|
|
59
|
+
CreateWebSearchProviderRequest,
|
|
60
|
+
CreateWebSearchRequest,
|
|
61
|
+
CreatedBySubject,
|
|
62
|
+
DefinedSkill,
|
|
63
|
+
GithubSkill,
|
|
64
|
+
ImportGithubSkillRequest,
|
|
65
|
+
ListPermissionsRequest,
|
|
66
|
+
ListPermissionsResponse,
|
|
67
|
+
ListResult,
|
|
68
|
+
ListSchedulesParams,
|
|
69
|
+
ListSessionEventsParams,
|
|
70
|
+
ListSessionsOrder,
|
|
71
|
+
ListSessionsParams,
|
|
72
|
+
McpServerMount,
|
|
73
|
+
McpToolSelection,
|
|
74
|
+
Model,
|
|
75
|
+
ModelCatalogServer,
|
|
76
|
+
ModelEntry,
|
|
77
|
+
ModelParams,
|
|
78
|
+
ModelProperties,
|
|
79
|
+
ModelProviderBase,
|
|
80
|
+
ModelProviderCatalogEntry,
|
|
81
|
+
ModelProviderConfigBase,
|
|
82
|
+
ModelSelection,
|
|
83
|
+
ModelSelectorEntry,
|
|
84
|
+
PageParams,
|
|
85
|
+
PermissionResourceType,
|
|
86
|
+
PermissionsServer,
|
|
87
|
+
PreviousTurnIdInput,
|
|
88
|
+
ProviderEntry,
|
|
89
|
+
ProviderType,
|
|
90
|
+
RegistrySkill,
|
|
91
|
+
ResourcePermission,
|
|
92
|
+
SandboxBase,
|
|
93
|
+
SandboxCatalogEntry,
|
|
94
|
+
SandboxCatalogServer,
|
|
95
|
+
SandboxConfig,
|
|
96
|
+
SandboxProviderBase,
|
|
97
|
+
SandboxProviderCatalogEntry,
|
|
98
|
+
SandboxProviderConfig,
|
|
99
|
+
SandboxProviderListEntry,
|
|
100
|
+
SandboxSnapshotSyncStatus,
|
|
101
|
+
SaveAgentRequest,
|
|
102
|
+
SaveAgentResult,
|
|
103
|
+
Schedule,
|
|
104
|
+
ScheduleRun,
|
|
105
|
+
ScheduleRunStatus,
|
|
106
|
+
ScheduleServer,
|
|
107
|
+
ScheduleStatus,
|
|
108
|
+
SearchAgentSelectorParams,
|
|
109
|
+
SearchAgentsParams,
|
|
110
|
+
SelectRegistrySkillRequest,
|
|
111
|
+
Session,
|
|
112
|
+
SessionListEntry,
|
|
113
|
+
SessionListMetrics,
|
|
114
|
+
SkillBase,
|
|
115
|
+
SkillCatalogEntry,
|
|
116
|
+
SkillCatalogServer,
|
|
117
|
+
SkillConfigBase,
|
|
118
|
+
SkillMount,
|
|
119
|
+
SkillSelectorEntry,
|
|
120
|
+
ToolBase,
|
|
121
|
+
Turn,
|
|
122
|
+
TurnDoneMetrics,
|
|
123
|
+
TurnInputItem,
|
|
124
|
+
TurnState,
|
|
125
|
+
TurnStateCancelled,
|
|
126
|
+
TurnStateDone,
|
|
127
|
+
TurnStateError,
|
|
128
|
+
TurnStateRunning,
|
|
129
|
+
UpdateConnectorRequest,
|
|
130
|
+
UpdateModelProviderRequest,
|
|
131
|
+
UpdateSandboxProviderRequest,
|
|
132
|
+
UpdateSandboxRequest,
|
|
133
|
+
UpdateScheduleRequest,
|
|
134
|
+
UpdateSessionRequest,
|
|
135
|
+
UpdateWebSearchProviderRequest,
|
|
136
|
+
UpdateWebSearchRequest,
|
|
137
|
+
UserMessage,
|
|
138
|
+
UserMessageContent,
|
|
139
|
+
UserToolApprovalEvent,
|
|
140
|
+
UserToolResponseEvent,
|
|
141
|
+
WebSearchBase,
|
|
142
|
+
WebSearchCatalogEntry,
|
|
143
|
+
WebSearchCatalogServer,
|
|
144
|
+
WebSearchProviderBase,
|
|
145
|
+
WebSearchProviderCatalogEntry,
|
|
146
|
+
} from './types.js';
|
|
147
|
+
|
|
148
|
+
export type {
|
|
149
|
+
ActionRequiredEvent,
|
|
150
|
+
AgentInfo,
|
|
151
|
+
AgentParent,
|
|
152
|
+
ChunkDeltaToolCall,
|
|
153
|
+
DeltaEvents,
|
|
154
|
+
McpAuthRequiredEvent,
|
|
155
|
+
McpInitializeEvent,
|
|
156
|
+
McpServerAuthInfo,
|
|
157
|
+
ModelMessageContentPart,
|
|
158
|
+
ModelMessageDeltaEvent,
|
|
159
|
+
ModelMessageEvent,
|
|
160
|
+
SandboxCreatedEvent,
|
|
161
|
+
SessionEventItem,
|
|
162
|
+
ThreadCreatedEvent,
|
|
163
|
+
ThreadDoneEvent,
|
|
164
|
+
ToolApprovalRequiredEvent,
|
|
165
|
+
ToolCall,
|
|
166
|
+
ToolCallFunction,
|
|
167
|
+
ToolCallRef,
|
|
168
|
+
ToolInfo,
|
|
169
|
+
ToolResponseEvent,
|
|
170
|
+
ToolResponseRequiredEvent,
|
|
171
|
+
TurnCreatedEvent,
|
|
172
|
+
TurnDoneEvent,
|
|
173
|
+
TurnEvent,
|
|
174
|
+
TurnStreamData,
|
|
175
|
+
TurnStreamingEvent,
|
|
176
|
+
} from './events.js';
|
|
177
|
+
|
|
178
|
+
export { isEventDelta, mergeEventDelta } from './eventUtils.js';
|