@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.
Files changed (55) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/LICENSE +201 -0
  3. package/README.md +146 -4
  4. package/dist/chunk-2SQK6TIO.js +104 -0
  5. package/dist/chunk-2SQK6TIO.js.map +1 -0
  6. package/dist/index.d.ts +378 -0
  7. package/dist/index.js +4391 -0
  8. package/dist/index.js.map +1 -0
  9. package/dist/server/index.d.ts +1210 -0
  10. package/dist/server/index.js +9 -0
  11. package/dist/server/index.js.map +1 -0
  12. package/package.json +79 -16
  13. package/src/askUserQuestion.ts +38 -0
  14. package/src/attachmentAdapter.ts +63 -0
  15. package/src/collectPending.ts +167 -0
  16. package/src/constants.ts +2 -0
  17. package/src/convertTurnMessages.ts +1679 -0
  18. package/src/createSubAgent.ts +11 -0
  19. package/src/draft/agentSpec.ts +34 -0
  20. package/src/draft/draftSessionBridge.ts +28 -0
  21. package/src/draft/trueforgeDraftThreadListAdapter.ts +73 -0
  22. package/src/draft/useDraftAgentSpec.ts +289 -0
  23. package/src/extractTurnUserText.ts +23 -0
  24. package/src/foldPeerThreads.ts +553 -0
  25. package/src/hooks.ts +176 -0
  26. package/src/index.ts +227 -0
  27. package/src/lastUserMessageText.ts +19 -0
  28. package/src/listPages.ts +19 -0
  29. package/src/loadSessionSnapshot.ts +34 -0
  30. package/src/mcpAuth.ts +35 -0
  31. package/src/messageCustomMetadata.ts +50 -0
  32. package/src/modelMessageContent.ts +149 -0
  33. package/src/modelMessageImageContent.ts +154 -0
  34. package/src/requiredActionInputs.ts +38 -0
  35. package/src/sandboxDownload.ts +33 -0
  36. package/src/server/eventUtils.ts +125 -0
  37. package/src/server/events.ts +232 -0
  38. package/src/server/index.ts +178 -0
  39. package/src/server/types.ts +1191 -0
  40. package/src/sessionListStartTimestamp.ts +6 -0
  41. package/src/sessionSnapshot.ts +146 -0
  42. package/src/sessionThreadMetadata.ts +36 -0
  43. package/src/sessions.ts +17 -0
  44. package/src/streamTurn.ts +118 -0
  45. package/src/toolApproval.ts +413 -0
  46. package/src/toolResponse.ts +346 -0
  47. package/src/trueforgeExtras.ts +223 -0
  48. package/src/trueforgeOwnedSessionsThreadListAdapter.ts +71 -0
  49. package/src/trueforgeThreadListAdapter.ts +69 -0
  50. package/src/turnEventHelpers.ts +71 -0
  51. package/src/turnStreamUpdate.ts +11 -0
  52. package/src/types.ts +84 -0
  53. package/src/useTrueForgeAgentMessages.ts +1138 -0
  54. package/src/useTrueForgeAgentRuntime.ts +308 -0
  55. package/index.js +0 -6
@@ -0,0 +1,1210 @@
1
+ /**
2
+ * Runtime-owned turn/stream event protocol.
3
+ *
4
+ * Hosts must emit events matching these shapes.
5
+ */
6
+
7
+ interface ToolCallFunction {
8
+ name: string;
9
+ arguments: string;
10
+ }
11
+ type ToolInfo = {
12
+ type: 'trueforge-system';
13
+ name: string;
14
+ } | {
15
+ type: 'mcp';
16
+ serverId: string;
17
+ serverName: string;
18
+ name: string;
19
+ } | {
20
+ type: string;
21
+ name?: string;
22
+ };
23
+ interface ToolCall {
24
+ id: string;
25
+ type: 'function';
26
+ function: ToolCallFunction;
27
+ toolInfo?: ToolInfo;
28
+ providerSpecificFields?: Record<string, unknown>;
29
+ }
30
+ /** Ref used by approval/response-required events. */
31
+ interface ToolCallRef {
32
+ id: string;
33
+ sourceEventId: string;
34
+ }
35
+ interface ChunkDeltaToolCall {
36
+ index: number;
37
+ id?: string;
38
+ type?: 'function';
39
+ function?: {
40
+ name?: string;
41
+ arguments?: string;
42
+ };
43
+ toolInfo?: ToolInfo;
44
+ providerSpecificFields?: Record<string, unknown>;
45
+ }
46
+ type ModelMessageContentPart = {
47
+ type: 'text';
48
+ text: string;
49
+ } | {
50
+ type: 'refusal';
51
+ refusal: string;
52
+ } | {
53
+ type: 'image_url';
54
+ image_url: {
55
+ url: string;
56
+ };
57
+ };
58
+ interface ModelMessageEvent {
59
+ type: 'model.message';
60
+ id: string;
61
+ threadId: string;
62
+ content?: string | ModelMessageContentPart[] | null;
63
+ name?: string;
64
+ refusal?: string | null;
65
+ reasoningContent?: string;
66
+ toolCalls?: ToolCall[];
67
+ finishReason?: string | null;
68
+ createdAt: string;
69
+ usage?: unknown;
70
+ }
71
+ interface ModelMessageDeltaEvent {
72
+ type: 'model.message.delta';
73
+ id: string;
74
+ threadId: string;
75
+ content?: string | null;
76
+ refusal?: string | null;
77
+ reasoningContent?: string;
78
+ toolCalls?: ChunkDeltaToolCall[];
79
+ finishReason?: string | null;
80
+ createdAt?: string;
81
+ usage?: unknown;
82
+ /** Extended content-block deltas (image streaming). */
83
+ contentBlocks?: {
84
+ index: number;
85
+ delta: {
86
+ type: 'text';
87
+ text?: string;
88
+ } | {
89
+ type: 'image_url';
90
+ image_url?: {
91
+ url?: string;
92
+ };
93
+ };
94
+ }[];
95
+ content_blocks?: {
96
+ index: number;
97
+ delta: {
98
+ type: 'text';
99
+ text?: string;
100
+ } | {
101
+ type: 'image_url';
102
+ image_url?: {
103
+ url?: string;
104
+ };
105
+ };
106
+ }[];
107
+ }
108
+ interface ToolResponseEvent {
109
+ type: 'tool.response';
110
+ id: string;
111
+ threadId: string;
112
+ toolCallId: string;
113
+ content: string;
114
+ createdAt: string;
115
+ }
116
+ interface ToolApprovalRequiredEvent {
117
+ type: 'tool.approval_required';
118
+ id: string;
119
+ createdAt: string;
120
+ threadId: string;
121
+ toolCalls: ToolCallRef[];
122
+ }
123
+ interface ToolResponseRequiredEvent {
124
+ type: 'tool.response_required';
125
+ id: string;
126
+ createdAt: string;
127
+ threadId: string;
128
+ toolCalls: ToolCallRef[];
129
+ }
130
+ interface AgentInfo {
131
+ type?: string;
132
+ name: string;
133
+ input: string;
134
+ model?: string;
135
+ }
136
+ interface AgentParent {
137
+ threadId: string;
138
+ toolCallId: string;
139
+ }
140
+ interface ThreadCreatedEvent {
141
+ type: 'thread.created';
142
+ id: string;
143
+ threadId: string;
144
+ title: string;
145
+ agentInfo: AgentInfo;
146
+ parent: AgentParent;
147
+ createdAt: string;
148
+ }
149
+ interface ThreadDoneEvent {
150
+ type: 'thread.done';
151
+ id: string;
152
+ threadId: string;
153
+ title?: string;
154
+ createdAt: string;
155
+ state?: unknown;
156
+ }
157
+ interface McpServerAuthInfo {
158
+ id: string;
159
+ name: string;
160
+ authUrl: string;
161
+ }
162
+ interface McpAuthRequiredEvent {
163
+ type: 'mcp.auth_required';
164
+ id: string;
165
+ createdAt: string;
166
+ threadId?: string | null;
167
+ mcpServers: McpServerAuthInfo[];
168
+ }
169
+ interface SandboxCreatedEvent {
170
+ type: 'sandbox.created';
171
+ id: string;
172
+ createdAt: string;
173
+ sandboxId: string;
174
+ threadId: string | null;
175
+ }
176
+ interface McpInitializeEvent {
177
+ type: 'mcp.initialize';
178
+ id: string;
179
+ createdAt: string;
180
+ threadId: string | null;
181
+ [key: string]: unknown;
182
+ }
183
+ interface TurnCreatedEvent {
184
+ type: 'turn.created';
185
+ id: string;
186
+ turnId: string;
187
+ previousTurnId?: string | null;
188
+ input?: TurnInputItem[];
189
+ state?: {
190
+ status: 'running';
191
+ };
192
+ createdAt: string;
193
+ threadId?: string | null;
194
+ }
195
+ interface TurnDoneEvent {
196
+ type: 'turn.done';
197
+ id: string;
198
+ state: Exclude<TurnState, {
199
+ status: 'running';
200
+ }>;
201
+ createdAt: string;
202
+ threadId?: string | null;
203
+ }
204
+ /** Events stored in fold buckets (non-delta, non-turn-lifecycle). */
205
+ type TurnEvent = ModelMessageEvent | ToolResponseEvent | ThreadCreatedEvent | ThreadDoneEvent | McpAuthRequiredEvent | McpInitializeEvent | SandboxCreatedEvent | ToolApprovalRequiredEvent | ToolResponseRequiredEvent;
206
+ /** Full streaming event union (includes deltas + turn lifecycle). */
207
+ type TurnStreamingEvent = TurnEvent | ModelMessageDeltaEvent | TurnCreatedEvent | TurnDoneEvent;
208
+ type ActionRequiredEvent = ToolApprovalRequiredEvent | ToolResponseRequiredEvent | McpAuthRequiredEvent;
209
+ interface TurnStreamData<TStreamEvent extends TurnStreamingEvent = TurnStreamingEvent> {
210
+ sequenceNumber: number;
211
+ event: TStreamEvent;
212
+ }
213
+ /** Session-level event item from `listEvents`. */
214
+ interface SessionEventItem {
215
+ turnId: string;
216
+ event: TurnCreatedEvent | TurnDoneEvent | TurnEvent;
217
+ }
218
+ type DeltaEvents = ModelMessageDeltaEvent;
219
+
220
+ /**
221
+ * FE-owned AgentUIServer contract.
222
+ *
223
+ * Rule: only methods/fields the runtime or UI invokes.
224
+ * Hosts extend via `T extends Base` for system-specific extras.
225
+ * No dependency on trueforge-gateway-sdk.
226
+ */
227
+
228
+ interface ProviderEntry {
229
+ name: string;
230
+ logo?: string;
231
+ }
232
+ interface ModelProperties {
233
+ reasoningEfforts?: string[];
234
+ contextLength?: number;
235
+ maxOutputTokens?: number;
236
+ }
237
+ /** Model selector row. Host extends for apiModel, modelId, etc. */
238
+ interface ModelSelectorEntry<TProvider extends ProviderEntry = ProviderEntry, TProperties extends ModelProperties = ModelProperties> {
239
+ name: string;
240
+ id: string;
241
+ provider: TProvider;
242
+ properties: TProperties;
243
+ }
244
+ /** Skill selector row. Host extends for fqn, preload, etc. */
245
+ interface SkillSelectorEntry {
246
+ id: string;
247
+ name: string;
248
+ description?: string;
249
+ }
250
+ /** MCP connector selector row. Host extends for type, enableTools, url, etc. */
251
+ interface ConnectorSelectorEntry {
252
+ id: string;
253
+ name: string;
254
+ description?: string;
255
+ /** When true, the connector must be authenticated before use. Omitted when the host does not report auth. */
256
+ requiresAuth?: boolean;
257
+ /** When true, the connector is already authenticated. Omitted when the host does not report auth. */
258
+ authenticated?: boolean;
259
+ }
260
+ /** Who created a resource. Optional on list DTOs when the host does not track creators. */
261
+ interface CreatedBySubject {
262
+ subjectId: string;
263
+ subjectType: string;
264
+ subjectDisplayName: string;
265
+ }
266
+ /** Agent selector row. Host extends for metadata; `agentSpec` enables Edit. */
267
+ interface AgentSelectorEntry {
268
+ name: string;
269
+ /** Stable id when distinct from display `name`. Falls back to `name` when omitted. */
270
+ agentId?: string;
271
+ /** Published-agent description; not part of the executable agent spec. */
272
+ description?: string;
273
+ /** Published agent spec — required for Edit; optional for Try-only hosts. */
274
+ agentSpec?: AgentSpec;
275
+ /** Creator when the host persists one; omit to hide Created-by UI. */
276
+ createdBySubject?: CreatedBySubject;
277
+ }
278
+ interface SearchAgentSelectorParams {
279
+ query?: string;
280
+ limit?: number;
281
+ offset?: number;
282
+ }
283
+ /**
284
+ * Mounts written to AgentSpec.skills[] / AgentSpec.mcpServers[].
285
+ *
286
+ * These are opaque to the runtime — it stores and forwards them but never reads
287
+ * a field, and the backend owns the shape (the gateway identifies a skill by
288
+ * `fqn`, with no `id` or `name` anywhere). So the base constrains only that a
289
+ * mount is an object; hosts intersect their concrete mount type over it, as
290
+ * `TfySkillMount` / `TfyMcpServerMount` do in the gateway adapter.
291
+ *
292
+ * Naming a field here would not just be unread, it would be wrong: a base with
293
+ * required fields rejects the backend's own payloads, and one with only optional
294
+ * fields is a weak type, which TypeScript rejects for a source that shares no
295
+ * property with it — the gateway's registry skill shares none.
296
+ */
297
+ type SkillMount = object;
298
+ type McpServerMount = object;
299
+ interface ModelParams {
300
+ maxTokens?: number;
301
+ reasoningEffort?: string;
302
+ temperature?: number;
303
+ topP?: number;
304
+ topK?: number;
305
+ parallelToolCalls?: boolean;
306
+ }
307
+ interface Model {
308
+ name: string;
309
+ params?: ModelParams;
310
+ }
311
+ interface AgentCapabilityConfig {
312
+ enabled?: boolean;
313
+ }
314
+ interface AgentSandboxConfig extends AgentCapabilityConfig {
315
+ fileDownloads?: boolean;
316
+ }
317
+ interface AgentInputTokensCompactionTrigger {
318
+ type: 'input_tokens';
319
+ value: number;
320
+ }
321
+ interface AgentCompactionConfig extends AgentCapabilityConfig {
322
+ trigger?: AgentInputTokensCompactionTrigger;
323
+ }
324
+ interface AgentContextManagementConfig {
325
+ compaction?: AgentCompactionConfig;
326
+ largeToolResponse?: AgentCapabilityConfig;
327
+ }
328
+ interface AgentRuntimeConfig {
329
+ iterationLimit?: number;
330
+ sandbox?: AgentSandboxConfig;
331
+ contextManagement?: AgentContextManagementConfig;
332
+ generativeUi?: AgentCapabilityConfig;
333
+ dynamicSubAgents?: AgentCapabilityConfig;
334
+ askUserQuestions?: AgentCapabilityConfig;
335
+ webSearch?: AgentCapabilityConfig;
336
+ }
337
+ /**
338
+ * SDK-owned agent definition — fields the FE reads/writes.
339
+ * Host widens `model` / `skills` / `mcpServers` / `config` via type params,
340
+ * and adds extra fields via `TSpec extends AgentSpec<...>`.
341
+ */
342
+ interface AgentSpec<TModel extends Model = Model, TSkill extends SkillMount = SkillMount, TMcp extends McpServerMount = McpServerMount, TConfig extends AgentRuntimeConfig = AgentRuntimeConfig> {
343
+ model: TModel;
344
+ skills?: TSkill[];
345
+ mcpServers?: TMcp[];
346
+ config?: TConfig;
347
+ instructions?: string;
348
+ variables?: Record<string, string>;
349
+ }
350
+ interface Session<TSpec extends AgentSpec = AgentSpec> {
351
+ id: string;
352
+ title?: string | null;
353
+ agentName?: string | null;
354
+ agentSpec?: TSpec;
355
+ /** true → mutable builder + updateSession(spec) allowed. */
356
+ isMutable: boolean;
357
+ createdAt: string;
358
+ updatedAt: string;
359
+ }
360
+ interface CreateSessionRequest<TSpec extends AgentSpec = AgentSpec> {
361
+ agentName?: string;
362
+ agentSpec?: TSpec;
363
+ title?: string;
364
+ }
365
+ interface UpdateSessionRequest<TSpec extends AgentSpec = AgentSpec> {
366
+ sessionId: string;
367
+ agentSpec?: TSpec;
368
+ title?: string;
369
+ }
370
+ interface ListResult<T> {
371
+ data: T[];
372
+ nextPageToken?: string;
373
+ }
374
+ type ListSessionsOrder = 'asc' | 'desc';
375
+ interface PageParams {
376
+ limit?: number;
377
+ order?: ListSessionsOrder;
378
+ pageToken?: string;
379
+ }
380
+ interface ListSessionsParams extends PageParams {
381
+ /** Host-owned agent identity filter. Omit for all sessions (current user). */
382
+ agentId?: string;
383
+ /**
384
+ * When true, only sessions created by the authenticated subject.
385
+ * Omit to include managed-agent visibility where the host supports it.
386
+ */
387
+ createdByMe?: boolean;
388
+ /** Inclusive lower bound on session activity (ISO-8601). */
389
+ startTimestamp?: string;
390
+ /** Inclusive upper bound on session activity (ISO-8601). */
391
+ endTimestamp?: string;
392
+ }
393
+ type PreviousTurnIdInput = string;
394
+ type UserMessageContent = string | ({
395
+ type: 'text';
396
+ text: string;
397
+ } | {
398
+ type: 'file';
399
+ name: string;
400
+ data: string;
401
+ })[];
402
+ interface UserMessage {
403
+ type: 'user.message';
404
+ content: UserMessageContent;
405
+ }
406
+ type ApprovalDecision = {
407
+ status: 'allow';
408
+ } | {
409
+ status: 'deny';
410
+ reason?: string;
411
+ };
412
+ interface UserToolApprovalEvent {
413
+ type: 'user.tool_approval';
414
+ threadId: string;
415
+ toolCallId: string;
416
+ approval: ApprovalDecision;
417
+ }
418
+ interface UserToolResponseEvent {
419
+ type: 'user.tool_response';
420
+ threadId: string;
421
+ toolCallId: string;
422
+ content: string;
423
+ }
424
+ type TurnInputItem = UserMessage | UserToolApprovalEvent | UserToolResponseEvent;
425
+ interface TurnStateRunning {
426
+ status: 'running';
427
+ }
428
+ /**
429
+ * Aggregated token metrics on a finished turn (`turn.done.state.metrics`).
430
+ * Host maps wire snake_case (`total_input_tokens`, …) → camelCase here.
431
+ */
432
+ interface TurnDoneMetrics {
433
+ totalInputTokens: number;
434
+ totalOutputTokens: number;
435
+ totalTokens: number;
436
+ totalCacheReadTokens: number;
437
+ totalCacheWriteTokens: number;
438
+ totalReasoningTokens: number;
439
+ }
440
+ interface TurnStateDone {
441
+ status: 'done';
442
+ output?: unknown;
443
+ requiredActions?: ActionRequiredEvent[];
444
+ completedAt: string;
445
+ /** Present when the host reports per-turn token totals. */
446
+ metrics?: TurnDoneMetrics;
447
+ }
448
+ interface TurnStateCancelled {
449
+ status: 'cancelled';
450
+ reason: string;
451
+ completedAt: string;
452
+ }
453
+ interface TurnStateError {
454
+ status: 'error';
455
+ message: string;
456
+ completedAt: string;
457
+ }
458
+ type TurnState = TurnStateRunning | TurnStateDone | TurnStateCancelled | TurnStateError;
459
+ /** Plain turn DTO — no methods. */
460
+ interface Turn {
461
+ id: string;
462
+ sessionId: string;
463
+ previousTurnId?: string | null;
464
+ input?: TurnInputItem[];
465
+ state: TurnState;
466
+ createdAt: string;
467
+ }
468
+ /**
469
+ * Chat / session port — the runtime calls these.
470
+ *
471
+ * All session ops are flat (sessionId param). No gateway client dependency.
472
+ * `createTrueForgeServer` is one possible implementation (TFY adapter).
473
+ */
474
+ interface AgentChatServer<TSpec extends AgentSpec = AgentSpec, TSession extends Session<TSpec> = Session<TSpec>, TCreate extends CreateSessionRequest<TSpec> = CreateSessionRequest<TSpec>, TList extends ListSessionsParams = ListSessionsParams, TUpdate extends UpdateSessionRequest<TSpec> = UpdateSessionRequest<TSpec>, TTurn extends Turn = Turn> {
475
+ createSession(req: TCreate): Promise<TSession>;
476
+ listSessions(req?: TList): Promise<ListResult<TSession>>;
477
+ getSession(req: {
478
+ sessionId: string;
479
+ }): Promise<TSession>;
480
+ updateSession(req: TUpdate): Promise<TSession>;
481
+ createTurn(req: {
482
+ sessionId: string;
483
+ input?: TurnInputItem[];
484
+ previousTurnId?: PreviousTurnIdInput;
485
+ abortSignal?: AbortSignal;
486
+ headers?: Record<string, string>;
487
+ }): AsyncIterable<TurnStreamData>;
488
+ cancelSession(req: {
489
+ sessionId: string;
490
+ }): Promise<void>;
491
+ deleteSession?(req: {
492
+ sessionId: string;
493
+ }): Promise<void>;
494
+ /**
495
+ * When present, thread-list `rename` persists via this method.
496
+ * Omitted: rename is a no-op (TrueForge Gateway does not persist titles).
497
+ */
498
+ renameSession?(req: {
499
+ sessionId: string;
500
+ title: string;
501
+ }): Promise<void>;
502
+ listTurns(req: {
503
+ sessionId: string;
504
+ limit?: number;
505
+ pageToken?: string;
506
+ order?: ListSessionsOrder;
507
+ }): Promise<ListResult<TTurn>>;
508
+ getTurn(req: {
509
+ sessionId: string;
510
+ turnId: string;
511
+ }): Promise<TTurn>;
512
+ listEvents(req: {
513
+ sessionId: string;
514
+ pageToken?: string;
515
+ lastTurnId?: string;
516
+ limit?: number;
517
+ }): Promise<ListResult<SessionEventItem>>;
518
+ /** Optional per-turn event listing (hydrate in-flight turn content). */
519
+ listTurnEvents?(req: {
520
+ sessionId: string;
521
+ turnId: string;
522
+ limit?: number;
523
+ pageToken?: string;
524
+ order?: ListSessionsOrder;
525
+ }): Promise<ListResult<TurnEvent>>;
526
+ subscribeToTurn?(req: {
527
+ sessionId: string;
528
+ turnId: string;
529
+ afterSequenceNumber?: number;
530
+ abortSignal?: AbortSignal;
531
+ }): AsyncIterable<TurnStreamData>;
532
+ /**
533
+ * Reads a file the agent wrote inside its sandbox. Hosts whose download route is scoped to a
534
+ * turn resolve the sandbox from `turnId` and ignore `sandboxId`; hosts addressing sandboxes
535
+ * directly use `sandboxId` when the runtime was able to recover it (optional after resume when
536
+ * `sandbox.created` is outside the loaded history window).
537
+ */
538
+ downloadSandboxFile?(req: {
539
+ sessionId: string;
540
+ turnId: string;
541
+ /** Present when a `sandbox.created` event was observed in session history or the live stream. */
542
+ sandboxId?: string;
543
+ path: string;
544
+ }): Promise<Blob>;
545
+ }
546
+ /** Request body for `AgentBuilderServer.saveAgent`. */
547
+ interface SaveAgentRequest<TSpec extends AgentSpec = AgentSpec> {
548
+ agentName: string;
549
+ /** Published-agent description; hosts may require it when creating an agent. */
550
+ description?: string;
551
+ agentSpec: TSpec;
552
+ intent: 'create' | 'update';
553
+ /** Current mutable session to update atomically with the named agent. */
554
+ sessionId?: string;
555
+ }
556
+ interface SaveAgentResult {
557
+ /** Immutable id allocated by the host registry. */
558
+ agentId?: string;
559
+ /** Version id allocated by the host registry for this save. */
560
+ versionId?: string;
561
+ /** Timestamp returned when the active mutable session was updated. */
562
+ sessionUpdatedAt?: string;
563
+ }
564
+ /** MCP tool row used by the per-agent connector tool selector. */
565
+ interface McpToolSelection {
566
+ id: string;
567
+ name: string;
568
+ description?: string;
569
+ }
570
+ /**
571
+ * Builder feature flags — atoms gate sandbox / skill / settings surfaces on these.
572
+ */
573
+ interface AgentBuilderCapabilitiesResponse {
574
+ data: {
575
+ sandbox: {
576
+ enabled: boolean;
577
+ };
578
+ skill: {
579
+ enabled: boolean;
580
+ reason?: string;
581
+ };
582
+ settings?: {
583
+ enabled: boolean;
584
+ };
585
+ webSearch?: {
586
+ enabled: boolean;
587
+ };
588
+ };
589
+ }
590
+ /**
591
+ * Builder catalog + persist port — atoms call these.
592
+ * Passed separately from the runtime's chat server.
593
+ */
594
+ interface AgentBuilderServer<TSpec extends AgentSpec = AgentSpec, TModel extends ModelSelectorEntry = ModelSelectorEntry, TSkill extends SkillSelectorEntry = SkillSelectorEntry, TMcp extends ConnectorSelectorEntry = ConnectorSelectorEntry, TAgent extends AgentSelectorEntry = AgentSelectorEntry, TSave = SaveAgentResult, TCapabilities extends AgentBuilderCapabilitiesResponse = AgentBuilderCapabilitiesResponse, TMcpTool extends McpToolSelection = McpToolSelection> {
595
+ getCapabilities(): Promise<TCapabilities>;
596
+ getModels(): Promise<TModel[]>;
597
+ getSkills(): Promise<TSkill[]>;
598
+ getMcp(): Promise<TMcp[]>;
599
+ getMcpConnector?(req: {
600
+ connectorId: string;
601
+ }): Promise<TMcp>;
602
+ getMcpTools?(req: {
603
+ connectorId: string;
604
+ }): Promise<TMcpTool[]>;
605
+ searchAgents(req?: SearchAgentSelectorParams): Promise<TAgent[]>;
606
+ saveAgent(req: SaveAgentRequest<TSpec>): Promise<TSave>;
607
+ deleteAgent?(req: {
608
+ agentName: string;
609
+ }): Promise<void>;
610
+ }
611
+ /**
612
+ * Provider type id. Reserved literal: `"custom"` for user-defined providers;
613
+ * any other string is a builtin (e.g. `"openai"`, `"anthropic"`).
614
+ *
615
+ * Note: `string | "custom"` is useless in TypeScript (`"custom"` ⊆ `string`),
616
+ * so this stays `string` and `"custom"` is a documented convention.
617
+ */
618
+ type ProviderType = string;
619
+ /**
620
+ * Model row — form "Model ID" + "Display name".
621
+ * Host extends for properties, etc.
622
+ */
623
+ interface ModelEntry {
624
+ id: string;
625
+ name: string;
626
+ }
627
+ /**
628
+ * Write config for create/update (custom form + catalog "Save key").
629
+ * Host extends. `baseUrl` present iff `type === "custom"`.
630
+ */
631
+ interface ModelProviderConfigBase<TModel extends ModelEntry = ModelEntry> {
632
+ type: ProviderType;
633
+ name: string;
634
+ /** Present iff `type === "custom"`. */
635
+ baseUrl?: string;
636
+ apiKey: string;
637
+ models: TModel[];
638
+ }
639
+ /**
640
+ * Configured provider card (list/read). No raw `apiKey`.
641
+ * Host extends for apiKeySet, timestamps, etc.
642
+ */
643
+ interface ModelProviderBase<TModel extends ModelEntry = ModelEntry> {
644
+ id: string;
645
+ type: ProviderType;
646
+ name: string;
647
+ /** Present iff `type === "custom"`. */
648
+ baseUrl?: string;
649
+ models: TModel[];
650
+ }
651
+ /**
652
+ * Discovery-only catalog provider (AVAILABLE list).
653
+ * `type` must not be `"custom"` — custom providers use the custom form.
654
+ * Host extends for richer model rows.
655
+ */
656
+ interface ModelProviderCatalogEntry<TModel extends ModelEntry = ModelEntry> {
657
+ type: ProviderType;
658
+ name: string;
659
+ models: TModel[];
660
+ supportedReasoningEfforts?: string[];
661
+ logo?: string;
662
+ }
663
+ /** Create — no `id`; server assigns it. Catalog path = entry + apiKey. */
664
+ type CreateModelProviderRequest<TModel extends ModelEntry = ModelEntry> = ModelProviderConfigBase<TModel>;
665
+ /** Update — `id` required. */
666
+ type UpdateModelProviderRequest<TModel extends ModelEntry = ModelEntry> = ModelProviderConfigBase<TModel> & {
667
+ id: string;
668
+ };
669
+ interface ModelCatalogServer<TModel extends ModelEntry = ModelEntry, TProvider extends ModelProviderBase<TModel> = ModelProviderBase<TModel>, TCatalogProvider extends ModelProviderCatalogEntry<TModel> = ModelProviderCatalogEntry<TModel>, TCreate extends CreateModelProviderRequest<TModel> = CreateModelProviderRequest<TModel>, TUpdate extends UpdateModelProviderRequest<TModel> = UpdateModelProviderRequest<TModel>> {
670
+ getModelProviderCatalog(): Promise<TCatalogProvider[]>;
671
+ listModelProviders(): Promise<TProvider[]>;
672
+ createModelProvider(req: TCreate): Promise<TProvider>;
673
+ /** Full replace update keyed by provider `id`. */
674
+ updateModelProvider(req: TUpdate): Promise<TProvider>;
675
+ deleteModelProvider?(req: {
676
+ id: string;
677
+ }): Promise<void>;
678
+ }
679
+ /** Tool row on a connector detail. Host extends for schemas, etc. */
680
+ interface ToolBase {
681
+ id: string;
682
+ name: string;
683
+ description: string;
684
+ }
685
+ /** Strict auth type id. Hosts widen branches via intersection + re-union. */
686
+ type ConnectorAuthType = 'dcr' | 'header' | 'none';
687
+ interface ConnectorAuthOAuth {
688
+ type: 'dcr';
689
+ authUrl?: string;
690
+ }
691
+ interface ConnectorAuthApiKey {
692
+ type: 'header';
693
+ apiKey?: string;
694
+ headerName?: string;
695
+ }
696
+ interface ConnectorAuthNone {
697
+ type: 'none';
698
+ }
699
+ type ConnectorAuth = ConnectorAuthOAuth | ConnectorAuthApiKey | ConnectorAuthNone;
700
+ interface ConnectorAuthPublicOAuth {
701
+ type: 'dcr';
702
+ authUrl?: string;
703
+ }
704
+ interface ConnectorAuthPublicApiKey {
705
+ type: 'header';
706
+ headerName?: string;
707
+ }
708
+ interface ConnectorAuthPublicNone {
709
+ type: 'none';
710
+ }
711
+ type ConnectorAuthPublic = ConnectorAuthPublicOAuth | ConnectorAuthPublicApiKey | ConnectorAuthPublicNone;
712
+ /**
713
+ * MCP / connector create-edit config. Host extends for extra fields, etc.
714
+ */
715
+ interface ConnectorConfigBase<TAuth extends ConnectorAuth = ConnectorAuth> {
716
+ name: string;
717
+ description: string;
718
+ url: string;
719
+ auth: TAuth;
720
+ }
721
+ /**
722
+ * Connected connector row (settings/connectors). No raw `apiKey` or tools.
723
+ * Tools are fetched separately with `getToolsByConnectorId`.
724
+ * Host extends.
725
+ */
726
+ interface ConnectorBase<TAuth extends ConnectorAuthPublic = ConnectorAuthPublic> {
727
+ id: string;
728
+ name: string;
729
+ description: string;
730
+ url: string;
731
+ auth: TAuth;
732
+ /** When true, UI should not show Disconnect. */
733
+ requiresAuth: boolean;
734
+ authenticated: boolean;
735
+ }
736
+ /** Discovery catalog entry for "+ Add MCP server". Host extends. */
737
+ interface ConnectorCatalogEntry<TAuth extends ConnectorAuthPublic = ConnectorAuthPublic> {
738
+ id: string;
739
+ name: string;
740
+ description?: string;
741
+ url: string;
742
+ auth: TAuth;
743
+ logo?: string;
744
+ }
745
+ /** Create connector — no `id`; server assigns it. Host extends. */
746
+ type CreateConnectorRequest<TAuth extends ConnectorAuth = ConnectorAuth> = ConnectorConfigBase<TAuth>;
747
+ /** Update connector — `id` required. Host extends. */
748
+ type UpdateConnectorRequest<TAuth extends ConnectorAuth = ConnectorAuth> = ConnectorConfigBase<TAuth> & {
749
+ id: string;
750
+ };
751
+ interface AuthenticateConnectorRequest {
752
+ id: string;
753
+ /** OAuth callback page owned by the host application. */
754
+ returnTo?: string;
755
+ }
756
+ interface ConnectorAuthenticationResult<TConnector extends ConnectorBase = ConnectorBase> {
757
+ connector?: TConnector;
758
+ status?: string;
759
+ authorization_endpoint?: string | undefined;
760
+ }
761
+ interface ConnectorCatalogServer<TTool extends ToolBase = ToolBase, TAuthWrite extends ConnectorAuth = ConnectorAuth, TAuthPublic extends ConnectorAuthPublic = ConnectorAuthPublic, TConnector extends ConnectorBase<TAuthPublic> = ConnectorBase<TAuthPublic>, TCatalogEntry extends ConnectorCatalogEntry<TAuthPublic> = ConnectorCatalogEntry<TAuthPublic>, TCreate extends CreateConnectorRequest<TAuthWrite> = CreateConnectorRequest<TAuthWrite>, TUpdate extends UpdateConnectorRequest<TAuthWrite> = UpdateConnectorRequest<TAuthWrite>> {
762
+ getConnectorCatalog(): Promise<TCatalogEntry[]>;
763
+ getConnector(req: {
764
+ id: string;
765
+ }): Promise<TConnector>;
766
+ listConnectors(req?: {
767
+ query?: string;
768
+ }): Promise<TConnector[]>;
769
+ getToolsByConnectorId(req: {
770
+ id: string;
771
+ }): Promise<TTool[]>;
772
+ createConnector(req: TCreate): Promise<TConnector>;
773
+ /** Full replace update keyed by connector `id`. */
774
+ updateConnector(req: TUpdate): Promise<TConnector>;
775
+ /**
776
+ * Start connector auth (e.g. OAuth).
777
+ * May return a connector (already authenticated / with `auth.authUrl`) or a
778
+ * result carrying `authorization_endpoint` for the popup flow.
779
+ */
780
+ authenticateConnector(req: AuthenticateConnectorRequest): Promise<TConnector | ConnectorAuthenticationResult<TConnector>>;
781
+ /** Clear connector auth. */
782
+ disconnectConnector(req: {
783
+ id: string;
784
+ }): Promise<TConnector>;
785
+ deleteConnector?(req: {
786
+ id: string;
787
+ }): Promise<void>;
788
+ }
789
+ /** Skill row shown in settings/skills (list + delete). Host extends for fqn, etc. */
790
+ interface SkillBase {
791
+ id: string;
792
+ name: string;
793
+ description: string;
794
+ }
795
+ interface RegistrySkill extends SkillBase {
796
+ /** `SkillCatalogEntry.id` this skill was created from. */
797
+ catalogId: string;
798
+ }
799
+ type GithubSkill = SkillBase;
800
+ type DefinedSkill = RegistrySkill | GithubSkill;
801
+ /** Git source fields shared by catalog entries and create requests. */
802
+ interface SkillConfigBase {
803
+ name: string;
804
+ description: string;
805
+ repoURL: string;
806
+ path: string;
807
+ ref: string;
808
+ }
809
+ interface SkillCatalogEntry extends SkillConfigBase {
810
+ id: string;
811
+ }
812
+ /** Create-skill base. Hosts may intersect extra fields and re-union. */
813
+ type CreateSkillRequestBase = SkillConfigBase;
814
+ interface SelectRegistrySkillRequest extends CreateSkillRequestBase {
815
+ /** `SkillCatalogEntry.id`, persisted so the created skill links back to it. */
816
+ catalogId: string;
817
+ }
818
+ type ImportGithubSkillRequest = CreateSkillRequestBase;
819
+ type CreateSkillRequest = SelectRegistrySkillRequest | ImportGithubSkillRequest;
820
+ interface SkillCatalogServer<TSkill extends SkillBase = SkillBase, TCatalogEntry extends SkillCatalogEntry = SkillCatalogEntry, TCreate extends CreateSkillRequest = CreateSkillRequest> {
821
+ getSkillCatalog(): Promise<TCatalogEntry[]>;
822
+ listSkills(req?: {
823
+ query?: string;
824
+ }): Promise<TSkill[]>;
825
+ createSkill(req: TCreate): Promise<TSkill>;
826
+ deleteSkill?(req: {
827
+ id: string;
828
+ }): Promise<void>;
829
+ }
830
+ /** Mutable sandbox provider settings shared by catalog rows, create, and update. */
831
+ interface SandboxConfig {
832
+ execTimeoutMs: number;
833
+ autoStopIntervalInMinutes: number;
834
+ autoArchiveIntervalInMinutes: number;
835
+ autoDeleteIntervalInMinutes: number;
836
+ }
837
+ interface SandboxCatalogEntry extends SandboxConfig {
838
+ id: string;
839
+ name: string;
840
+ type: string;
841
+ }
842
+ /**
843
+ * Connected sandbox provider row (settings/sandboxes). No raw `apiKey`.
844
+ * Includes last-saved config so update forms can show previous values.
845
+ */
846
+ interface SandboxBase extends SandboxConfig {
847
+ id: string;
848
+ name: string;
849
+ catalogId: string;
850
+ isConnected: boolean;
851
+ }
852
+ interface SandboxSnapshotSyncStatus {
853
+ status: 'pending' | 'ready' | 'failed';
854
+ statusReason?: string | null;
855
+ }
856
+ interface SandboxProviderListEntry<TSandbox extends SandboxBase = SandboxBase> {
857
+ data: TSandbox;
858
+ snapshotSyncStatus: SandboxSnapshotSyncStatus;
859
+ }
860
+ interface CreateSandboxRequest extends SandboxConfig {
861
+ /** `SandboxCatalogEntry.id` used to create this sandbox provider. */
862
+ catalogId: string;
863
+ name: string;
864
+ type: string;
865
+ apiKey: string;
866
+ }
867
+ interface UpdateSandboxRequest extends SandboxConfig {
868
+ id: string;
869
+ /** Omit to keep the existing key; send a value to rotate. */
870
+ apiKey?: string;
871
+ }
872
+ /** Host-facing aliases (trueforge-ui public names). */
873
+ type SandboxProviderConfig = SandboxConfig;
874
+ type SandboxProviderCatalogEntry = SandboxCatalogEntry;
875
+ type SandboxProviderBase = SandboxBase;
876
+ type CreateSandboxProviderRequest = CreateSandboxRequest;
877
+ type UpdateSandboxProviderRequest = UpdateSandboxRequest;
878
+ interface SandboxCatalogServer<TProvider extends SandboxBase = SandboxBase, TCatalogEntry extends SandboxCatalogEntry = SandboxCatalogEntry, TCreate extends CreateSandboxRequest = CreateSandboxRequest, TUpdate extends UpdateSandboxRequest = UpdateSandboxRequest, TListEntry extends SandboxProviderListEntry<TProvider> = SandboxProviderListEntry<TProvider>> {
879
+ getSandboxProviderCatalog(): Promise<TCatalogEntry[]>;
880
+ listSandboxProviders(req?: {
881
+ query?: string;
882
+ }): Promise<TListEntry[]>;
883
+ createSandboxProvider(req: TCreate): Promise<TProvider>;
884
+ updateSandboxProvider(req: TUpdate): Promise<TProvider>;
885
+ deleteSandboxProvider?(req: {
886
+ id: string;
887
+ }): Promise<void>;
888
+ }
889
+ interface WebSearchCatalogEntry {
890
+ id: string;
891
+ name: string;
892
+ type: string;
893
+ }
894
+ /**
895
+ * Connected web-search provider row (settings/web-search). No raw `apiKey`.
896
+ */
897
+ interface WebSearchBase {
898
+ id: string;
899
+ name: string;
900
+ catalogId: string;
901
+ isConnected: boolean;
902
+ }
903
+ interface CreateWebSearchRequest {
904
+ /** `WebSearchCatalogEntry.id` used to create this web-search provider. */
905
+ catalogId: string;
906
+ name: string;
907
+ type: string;
908
+ apiKey: string;
909
+ }
910
+ interface UpdateWebSearchRequest {
911
+ id: string;
912
+ /** Omit to keep the existing key; send a value to set/rotate. */
913
+ apiKey?: string;
914
+ }
915
+ /** Host-facing aliases (trueforge-ui public names). */
916
+ type WebSearchProviderCatalogEntry = WebSearchCatalogEntry;
917
+ type WebSearchProviderBase = WebSearchBase;
918
+ type CreateWebSearchProviderRequest = CreateWebSearchRequest;
919
+ type UpdateWebSearchProviderRequest = UpdateWebSearchRequest;
920
+ interface WebSearchCatalogServer<TProvider extends WebSearchBase = WebSearchBase, TCatalogEntry extends WebSearchCatalogEntry = WebSearchCatalogEntry, TCreate extends CreateWebSearchRequest = CreateWebSearchRequest, TUpdate extends UpdateWebSearchRequest = UpdateWebSearchRequest> {
921
+ getWebSearchProviderCatalog(): Promise<TCatalogEntry[]>;
922
+ listWebSearchProviders(req?: {
923
+ query?: string;
924
+ }): Promise<TProvider[]>;
925
+ createWebSearchProvider(req: TCreate): Promise<TProvider>;
926
+ updateWebSearchProvider(req: TUpdate): Promise<TProvider>;
927
+ }
928
+ /** Host-facing selector / compose aliases (trueforge-ui public names). */
929
+ type ModelSelection = ModelSelectorEntry;
930
+ type AgentSkill = SkillSelectorEntry;
931
+ type ConnectorState = ConnectorSelectorEntry;
932
+ type AgentLibraryEntry = AgentSelectorEntry;
933
+ type SearchAgentsParams = SearchAgentSelectorParams;
934
+ /**
935
+ * Settings management aggregate — modelCatalog + connectorCatalog + optional
936
+ * skill, sandbox, and web-search catalogs.
937
+ * Hosts may pass the whole object to an app shell, or a focused sub-port to a page.
938
+ */
939
+ interface CatalogServer<TModelCatalog extends ModelCatalogServer = ModelCatalogServer, TConnectorCatalog extends ConnectorCatalogServer = ConnectorCatalogServer, TSkillCatalog extends SkillCatalogServer = SkillCatalogServer, TSandboxCatalog extends SandboxCatalogServer = SandboxCatalogServer, TWebSearchCatalog extends WebSearchCatalogServer = WebSearchCatalogServer> {
940
+ modelCatalog: TModelCatalog;
941
+ connectorCatalog: TConnectorCatalog;
942
+ /** Optional — omit when the host has no skills settings surface. */
943
+ skillCatalog?: TSkillCatalog;
944
+ /** Optional — omit when the host has no sandboxes settings surface. */
945
+ sandboxCatalog?: TSandboxCatalog;
946
+ /** Optional — omit when the host has no web-search settings surface. */
947
+ webSearchCatalog?: TWebSearchCatalog;
948
+ }
949
+ /**
950
+ * Published agent identity + spec for the agent-detail Overview (read-only).
951
+ * Host widens `TSpec` (and may extend this DTO) for mounts / config / extras.
952
+ */
953
+ interface AgentDetail<TSpec extends AgentSpec = AgentSpec> {
954
+ agentId: string;
955
+ /** Display name (e.g. "release-notes-writer"). */
956
+ name: string;
957
+ /** Published-agent description; not part of the executable agent spec. */
958
+ description?: string;
959
+ agentSpec: TSpec;
960
+ }
961
+ /** Stream vs non-stream bodies for one language on the Use In Code tab. */
962
+ interface CodeSnippetSampleCode {
963
+ stream: string;
964
+ nonStream: string;
965
+ }
966
+ /**
967
+ * One language row for Use In Code.
968
+ * Host maps wire `sample_code` / `non_stream` → camelCase here.
969
+ */
970
+ interface CodeSnippet<TSample extends CodeSnippetSampleCode = CodeSnippetSampleCode> {
971
+ /** Sidebar label (e.g. "TypeScript"). */
972
+ labelName: string;
973
+ /** Highlighter / tab id (e.g. "typescript"). */
974
+ language: string;
975
+ icon?: string;
976
+ sampleCode: TSample;
977
+ }
978
+ /**
979
+ * Aggregated session metrics for the sessions list sidebar.
980
+ * Host maps wire snake_case (`total_turns`, `total_cost_in_usd`, …) → camelCase.
981
+ */
982
+ interface SessionListMetrics {
983
+ totalTurns: number;
984
+ totalCostInUsd?: number;
985
+ totalDurationMs: number;
986
+ }
987
+ /**
988
+ * One row in the Agent Sessions list (left pane).
989
+ *
990
+ * Binding: `agentName` → named / immutable agent; `agentSpec` → mutable / draft.
991
+ * Host may send one, both, or neither depending on how the session was created.
992
+ */
993
+ interface SessionListEntry<TSpec extends AgentSpec = AgentSpec> {
994
+ id: string;
995
+ title?: string | null;
996
+ createdAt: string;
997
+ updatedAt: string;
998
+ lastActivityAt: string;
999
+ metrics: SessionListMetrics;
1000
+ /** Present when bound to a published (immutable) agent. */
1001
+ agentName?: string | null;
1002
+ /** Present when bound to a mutable / draft agent spec. */
1003
+ agentSpec?: TSpec;
1004
+ }
1005
+ /** Params for `AgentSessionsServer.listSessionEvents` (session event timeline). */
1006
+ interface ListSessionEventsParams extends Pick<PageParams, 'limit' | 'pageToken'> {
1007
+ sessionId: string;
1008
+ }
1009
+ /**
1010
+ * Optional plug-in for agent-detail UI: Overview, Use In Code, sessions list,
1011
+ * and per-session event timeline. Omit `sessions` on `AgentUIServerPort` when
1012
+ * the host has no agent-detail surface.
1013
+ *
1014
+ * Read-only — create/update/delete stay on `AgentChatServer` / `AgentBuilderServer`.
1015
+ */
1016
+ interface AgentSessionsServer<TSpec extends AgentSpec = AgentSpec, TDetail extends AgentDetail<TSpec> = AgentDetail<TSpec>, TSnippet extends CodeSnippet = CodeSnippet, TListEntry extends SessionListEntry<TSpec> = SessionListEntry<TSpec>, TList extends ListSessionsParams = ListSessionsParams> {
1017
+ /** Fetch published agent details by id for the Overview tab. */
1018
+ getAgent(req: {
1019
+ agentId: string;
1020
+ }): Promise<TDetail>;
1021
+ /** Fetch Use In Code snippets for the agent (one row per language). */
1022
+ getCodeSnippets(req: {
1023
+ agentId: string;
1024
+ }): Promise<TSnippet[]>;
1025
+ /**
1026
+ * List sessions visible to the current user. Pass `agentId` to scope to one
1027
+ * agent; `createdByMe: true` for only sessions they created. Use
1028
+ * `startTimestamp` / `endTimestamp` for date filters.
1029
+ */
1030
+ listSessions(req?: TList): Promise<ListResult<TListEntry>>;
1031
+ /**
1032
+ * Fetch the session event timeline (right pane). Paginate with `pageToken`
1033
+ * until exhausted; rebuild turns from `turn.created` / `turn.done` +
1034
+ * nested `TurnEvent`s. Per-turn token metrics live on `turn.done.state.metrics`.
1035
+ */
1036
+ listSessionEvents(req: ListSessionEventsParams): Promise<ListResult<SessionEventItem>>;
1037
+ }
1038
+ type ScheduleStatus = 'active' | 'paused';
1039
+ type ScheduleRunStatus = 'scheduled' | 'triggered' | 'failed';
1040
+ interface Schedule {
1041
+ id: string;
1042
+ name: string;
1043
+ /** Stable agent id (`AgentSelectorEntry.agentId`). */
1044
+ agentId: string;
1045
+ /** Display name; omit when the host only has `agentId`. */
1046
+ agentName?: string;
1047
+ task: string;
1048
+ cron: string;
1049
+ timezone: string;
1050
+ status: ScheduleStatus;
1051
+ lastRunAt: string | null;
1052
+ /** Creator when the host persists one; omit to hide Created-by UI. */
1053
+ createdBySubject?: CreatedBySubject;
1054
+ }
1055
+ /** Flat schedule-run DTO (ISO-8601 timestamps; host maps from wire Dates). */
1056
+ interface ScheduleRun {
1057
+ id: string;
1058
+ scheduleId: string;
1059
+ name: string;
1060
+ scheduledFor: string;
1061
+ status: ScheduleRunStatus;
1062
+ triggeredAt: string | null;
1063
+ triggeredBy: string;
1064
+ }
1065
+ interface ListSchedulesParams extends Pick<PageParams, 'limit' | 'pageToken'> {
1066
+ agentId?: string;
1067
+ /** Multi-agent filter; combined with `agentId` when both are set. */
1068
+ agentIds?: string[];
1069
+ }
1070
+ interface CreateScheduleRequest {
1071
+ agentId: string;
1072
+ name: string;
1073
+ task: string;
1074
+ cron: string;
1075
+ timezone?: string;
1076
+ status?: ScheduleStatus;
1077
+ }
1078
+ /** `agentId` is not on the base update body; hosts that allow rebinding can extend `TUpdate`. */
1079
+ interface UpdateScheduleRequest {
1080
+ id: string;
1081
+ name: string;
1082
+ task: string;
1083
+ cron: string;
1084
+ timezone?: string;
1085
+ status?: ScheduleStatus;
1086
+ }
1087
+ interface CreateScheduleRunRequest {
1088
+ scheduleId: string;
1089
+ }
1090
+ interface ScheduleServer<TSchedule extends Schedule = Schedule, TCreate extends CreateScheduleRequest = CreateScheduleRequest, TUpdate extends UpdateScheduleRequest = UpdateScheduleRequest, TRun extends ScheduleRun = ScheduleRun> {
1091
+ listSchedules(req?: ListSchedulesParams): Promise<ListResult<TSchedule>>;
1092
+ getSchedule(req: {
1093
+ id: string;
1094
+ }): Promise<TSchedule>;
1095
+ createSchedule(req: TCreate): Promise<TSchedule>;
1096
+ updateSchedule(req: TUpdate): Promise<TSchedule>;
1097
+ deleteSchedule(req: {
1098
+ id: string;
1099
+ }): Promise<void>;
1100
+ listScheduleRuns(req: {
1101
+ scheduleId: string;
1102
+ }): Promise<TRun[]>;
1103
+ createScheduleRun(req: CreateScheduleRunRequest): Promise<TRun>;
1104
+ }
1105
+ type PermissionResourceType = 'agent' | 'schedule' | 'session' | 'tenant';
1106
+ type ResourcePermission = 'USE' | 'MANAGE' | 'DELETE' | 'CREATE';
1107
+ interface ListPermissionsRequest {
1108
+ resourceType: PermissionResourceType;
1109
+ resourceIds: string[];
1110
+ }
1111
+ interface ListPermissionsResponse {
1112
+ data: {
1113
+ type: PermissionResourceType;
1114
+ permissions: Record<string, ResourcePermission[]>;
1115
+ };
1116
+ }
1117
+ interface PermissionsServer<TRequest extends ListPermissionsRequest = ListPermissionsRequest, TResponse extends ListPermissionsResponse = ListPermissionsResponse> {
1118
+ listPermissions(req: TRequest): Promise<TResponse>;
1119
+ }
1120
+ type AgentMetricChartType = 'line';
1121
+ interface AgentMetricChartDefinition {
1122
+ name: string;
1123
+ displayName: string;
1124
+ description: string;
1125
+ chartType: AgentMetricChartType;
1126
+ }
1127
+ interface AgentMetricMeter {
1128
+ name: string;
1129
+ aggregateValue: number;
1130
+ description: string;
1131
+ unit: string;
1132
+ }
1133
+ interface AgentMetricPoint {
1134
+ timestamp: string;
1135
+ value: number;
1136
+ }
1137
+ interface AgentMetricGraphLine<TPoint extends AgentMetricPoint = AgentMetricPoint> {
1138
+ name: string;
1139
+ values: TPoint[];
1140
+ }
1141
+ interface AgentMetricGraph<TLine extends AgentMetricGraphLine = AgentMetricGraphLine> {
1142
+ name: string;
1143
+ displayName: string;
1144
+ description: string;
1145
+ unit: string;
1146
+ chartType: AgentMetricChartType;
1147
+ graphLines: TLine[];
1148
+ }
1149
+ interface AgentMetricChartData<TGraph extends AgentMetricGraph = AgentMetricGraph> {
1150
+ step: string;
1151
+ graphs: TGraph[];
1152
+ }
1153
+ interface AgentMetricRangeRequest {
1154
+ agentId: string;
1155
+ startTimestamp: string;
1156
+ endTimestamp: string;
1157
+ }
1158
+ interface AgentMetricChartDataRequest extends AgentMetricRangeRequest {
1159
+ chartName: string;
1160
+ }
1161
+ interface AgentMetricsServer<TChart extends AgentMetricChartDefinition = AgentMetricChartDefinition, TMeter extends AgentMetricMeter = AgentMetricMeter, TChartData extends AgentMetricChartData = AgentMetricChartData, TRangeRequest extends AgentMetricRangeRequest = AgentMetricRangeRequest, TChartDataRequest extends AgentMetricChartDataRequest = AgentMetricChartDataRequest> {
1162
+ getCharts(): Promise<TChart[]>;
1163
+ getMeters(req: TRangeRequest): Promise<TMeter[]>;
1164
+ getChartData(req: TChartDataRequest): Promise<TChartData>;
1165
+ }
1166
+ /**
1167
+ * Composed host port: chat + builder + optional settings catalog + optional
1168
+ * agent-detail / sessions shell + optional schedules surface + optional metrics.
1169
+ *
1170
+ * `catalog` is optional — if the host passes it, settings UI can call
1171
+ * `useCatalogServer()` / show modelCatalog, connectorCatalog, and skillCatalog;
1172
+ * if omitted, those surfaces stay hidden.
1173
+ *
1174
+ * `sessions` is optional — if the host passes it, agent-detail UI can call
1175
+ * `useAgentSessionsServer()` / Overview + sessions under an agent; if omitted,
1176
+ * that surface stays hidden.
1177
+ *
1178
+ * `schedules` is optional — if the host passes it, schedules UI can call
1179
+ * `useScheduleServer()` / list and manage schedules; if omitted, that surface
1180
+ * stays hidden.
1181
+ *
1182
+ * `metrics` is optional — if the host passes it, agent-detail UI can render
1183
+ * aggregate meter cards and time-series charts.
1184
+ *
1185
+ * trueforge-ui re-exports this as `AgentUIServer`.
1186
+ */
1187
+ type AgentUIServerPort<TChat extends AgentChatServer = AgentChatServer, TBuilder extends AgentBuilderServer = AgentBuilderServer, TCatalog extends CatalogServer = CatalogServer, TSessions extends AgentSessionsServer = AgentSessionsServer, TSchedules extends ScheduleServer = ScheduleServer, TMetrics extends AgentMetricsServer = AgentMetricsServer, TPermissions extends PermissionsServer = PermissionsServer> = TChat & TBuilder & {
1188
+ catalog?: TCatalog;
1189
+ sessions?: TSessions;
1190
+ schedules?: TSchedules;
1191
+ metrics?: TMetrics;
1192
+ permissions?: TPermissions;
1193
+ };
1194
+ /** Host-facing alias used by trueforge-ui. */
1195
+ type AgentUIServer = AgentUIServerPort;
1196
+
1197
+ /**
1198
+ * Local implementations of streaming delta helpers.
1199
+ * Formerly imported from trueforge-gateway-sdk/agents.
1200
+ */
1201
+
1202
+ /** True for `.delta` streaming events. */
1203
+ declare function isEventDelta(event: TurnStreamingEvent): event is DeltaEvents;
1204
+ /**
1205
+ * Merge `delta` into `base` in place (same `id` required).
1206
+ * Currently handles `model.message.delta` → `model.message`.
1207
+ */
1208
+ declare function mergeEventDelta(base: TurnEvent, delta: DeltaEvents): void;
1209
+
1210
+ export { type ActionRequiredEvent, type AgentBuilderCapabilitiesResponse, type AgentBuilderServer, type AgentCapabilityConfig, type AgentChatServer, type AgentCompactionConfig, type AgentContextManagementConfig, type AgentDetail, type AgentInfo, type AgentInputTokensCompactionTrigger, type AgentLibraryEntry, type AgentMetricChartData, type AgentMetricChartDataRequest, type AgentMetricChartDefinition, type AgentMetricChartType, type AgentMetricGraph, type AgentMetricGraphLine, type AgentMetricMeter, type AgentMetricPoint, type AgentMetricRangeRequest, type AgentMetricsServer, type AgentParent, type AgentRuntimeConfig, type AgentSandboxConfig, type AgentSelectorEntry, type AgentSessionsServer, type AgentSkill, type AgentSpec, type AgentUIServer, type AgentUIServerPort, type ApprovalDecision, type AuthenticateConnectorRequest, type CatalogServer, type ChunkDeltaToolCall, type CodeSnippet, type CodeSnippetSampleCode, type ConnectorAuth, type ConnectorAuthApiKey, type ConnectorAuthNone, type ConnectorAuthOAuth, type ConnectorAuthPublic, type ConnectorAuthPublicApiKey, type ConnectorAuthPublicNone, type ConnectorAuthPublicOAuth, type ConnectorAuthType, type ConnectorAuthenticationResult, type ConnectorBase, type ConnectorCatalogEntry, type ConnectorCatalogServer, type ConnectorConfigBase, type ConnectorSelectorEntry, type ConnectorState, type CreateConnectorRequest, type CreateModelProviderRequest, type CreateSandboxProviderRequest, type CreateSandboxRequest, type CreateScheduleRequest, type CreateScheduleRunRequest, type CreateSessionRequest, type CreateSkillRequest, type CreateSkillRequestBase, type CreateWebSearchProviderRequest, type CreateWebSearchRequest, type CreatedBySubject, type DefinedSkill, type DeltaEvents, type GithubSkill, type ImportGithubSkillRequest, type ListPermissionsRequest, type ListPermissionsResponse, type ListResult, type ListSchedulesParams, type ListSessionEventsParams, type ListSessionsOrder, type ListSessionsParams, type McpAuthRequiredEvent, type McpInitializeEvent, type McpServerAuthInfo, type McpServerMount, type McpToolSelection, type Model, type ModelCatalogServer, type ModelEntry, type ModelMessageContentPart, type ModelMessageDeltaEvent, type ModelMessageEvent, type ModelParams, type ModelProperties, type ModelProviderBase, type ModelProviderCatalogEntry, type ModelProviderConfigBase, type ModelSelection, type ModelSelectorEntry, type PageParams, type PermissionResourceType, type PermissionsServer, type PreviousTurnIdInput, type ProviderEntry, type ProviderType, type RegistrySkill, type ResourcePermission, type SandboxBase, type SandboxCatalogEntry, type SandboxCatalogServer, type SandboxConfig, type SandboxCreatedEvent, type SandboxProviderBase, type SandboxProviderCatalogEntry, type SandboxProviderConfig, type SandboxProviderListEntry, type SandboxSnapshotSyncStatus, type SaveAgentRequest, type SaveAgentResult, type Schedule, type ScheduleRun, type ScheduleRunStatus, type ScheduleServer, type ScheduleStatus, type SearchAgentSelectorParams, type SearchAgentsParams, type SelectRegistrySkillRequest, type Session, type SessionEventItem, type SessionListEntry, type SessionListMetrics, type SkillBase, type SkillCatalogEntry, type SkillCatalogServer, type SkillConfigBase, type SkillMount, type SkillSelectorEntry, type ThreadCreatedEvent, type ThreadDoneEvent, type ToolApprovalRequiredEvent, type ToolBase, type ToolCall, type ToolCallFunction, type ToolCallRef, type ToolInfo, type ToolResponseEvent, type ToolResponseRequiredEvent, type Turn, type TurnCreatedEvent, type TurnDoneEvent, type TurnDoneMetrics, type TurnEvent, type TurnInputItem, type TurnState, type TurnStateCancelled, type TurnStateDone, type TurnStateError, type TurnStateRunning, type TurnStreamData, type TurnStreamingEvent, type UpdateConnectorRequest, type UpdateModelProviderRequest, type UpdateSandboxProviderRequest, type UpdateSandboxRequest, type UpdateScheduleRequest, type UpdateSessionRequest, type UpdateWebSearchProviderRequest, type UpdateWebSearchRequest, type UserMessage, type UserMessageContent, type UserToolApprovalEvent, type UserToolResponseEvent, type WebSearchBase, type WebSearchCatalogEntry, type WebSearchCatalogServer, type WebSearchProviderBase, type WebSearchProviderCatalogEntry, isEventDelta, mergeEventDelta };