@adecore/agent-contracts 0.62.1 → 0.63.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/dist/agent.d.ts +1 -4
- package/dist/agent.js +2 -7
- package/dist/chat.d.ts +583 -16
- package/dist/chat.js +24 -1
- package/dist/index.d.ts +5 -4
- package/dist/index.js +5 -4
- package/dist/model.d.ts +8 -0
- package/dist/model.js +13 -1
- package/dist/protocol.d.ts +397 -11
- package/dist/tool-edits.d.ts +10 -0
- package/dist/tool-edits.js +31 -0
- package/dist/visual.d.ts +1 -0
- package/dist/visual.js +3 -1
- package/package.json +3 -3
- package/src/agent.ts +3 -11
- package/src/chat.ts +45 -1
- package/src/index.ts +9 -4
- package/src/model.ts +16 -1
- package/src/tool-edits.ts +53 -0
- package/src/visual.ts +4 -1
package/src/chat.ts
CHANGED
|
@@ -82,7 +82,6 @@ export function attachmentImageMime({ name, mime }: { name: string; mime: string
|
|
|
82
82
|
return dot < 0 ? null : (IMAGE_MIME_BY_EXTENSION.get(name.slice(dot + 1).toLowerCase()) ?? null);
|
|
83
83
|
}
|
|
84
84
|
|
|
85
|
-
// What the composer hands the daemon: the bytes, plus what the file is called and what it is.
|
|
86
85
|
export const ChatAttachmentUploadSchema = z.object({
|
|
87
86
|
name: z.string().min(1).max(255),
|
|
88
87
|
mime: z.string().min(1).max(255),
|
|
@@ -325,6 +324,39 @@ export function holdsConversation(info: Pick<ChatInfo, 'agentSessionId' | 'activ
|
|
|
325
324
|
return info.agentSessionId !== null || info.activeTurnId !== null;
|
|
326
325
|
}
|
|
327
326
|
|
|
327
|
+
/*
|
|
328
|
+
* What a chat is doing, which every "is it busy" question answers from:
|
|
329
|
+
* - `waiting`: a person is asked (`needs-you`).
|
|
330
|
+
* - `working`: a turn is open and nobody is asked.
|
|
331
|
+
* - `delegating`: no turn, but a subagent or workflow of the CLI still works.
|
|
332
|
+
* - `background`: only commands the CLI started in the background run.
|
|
333
|
+
* - `holding`: nothing runs, yet the chat is not at rest: a request is open, a goal is active or messages are queued.
|
|
334
|
+
* - `settled`: none of the above.
|
|
335
|
+
*/
|
|
336
|
+
export type ChatActivity = 'waiting' | 'working' | 'delegating' | 'background' | 'holding' | 'settled';
|
|
337
|
+
|
|
338
|
+
export function chatActivity(
|
|
339
|
+
info: Pick<ChatInfo, 'status' | 'delegating' | 'background' | 'requests' | 'goal' | 'queue'> & Partial<Pick<ChatInfo, 'activeTurnId'>>
|
|
340
|
+
): ChatActivity {
|
|
341
|
+
if (info.status === 'needs-you') {
|
|
342
|
+
return 'waiting';
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
if (info.status === 'running' || (info.activeTurnId ?? null) !== null) {
|
|
346
|
+
return 'working';
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
if (info.delegating === true) {
|
|
350
|
+
return 'delegating';
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
if ((info.background ?? []).length > 0) {
|
|
354
|
+
return 'background';
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
return (info.requests ?? []).length > 0 || info.goal?.status === 'active' || (info.queue ?? []).length > 0 ? 'holding' : 'settled';
|
|
358
|
+
}
|
|
359
|
+
|
|
328
360
|
// Where a skill was found: the person's own folder, the chat's folder, or a plugin.
|
|
329
361
|
export const ChatSkillSourceSchema = z.enum(['user', 'project', 'plugin']);
|
|
330
362
|
export type ChatSkillSource = z.infer<typeof ChatSkillSourceSchema>;
|
|
@@ -555,6 +587,18 @@ export type ChatSubagentUsage = z.infer<typeof ChatSubagentUsageSchema>;
|
|
|
555
587
|
// The `origin` of a subagent row a host opened with a task of its own rather than the CLI with its tool; a legacy spelling that stored threads carry.
|
|
556
588
|
export const HOST_TASK_ORIGIN = 'ruimte';
|
|
557
589
|
|
|
590
|
+
const TASK_ROW_PREFIX = 'task-';
|
|
591
|
+
|
|
592
|
+
/* The id of the subagent row a host writes for a task of its own, which is also the row's `toolUseId`. */
|
|
593
|
+
export function taskRowId(taskId: string): string {
|
|
594
|
+
return `${TASK_ROW_PREFIX}${taskId}`;
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
/* The id of the task a subagent row stands for; null for a row the CLI opened with its own tool. */
|
|
598
|
+
export function taskIdOfRow(row: { id: string; origin?: string }): string | null {
|
|
599
|
+
return row.origin === HOST_TASK_ORIGIN && row.id.startsWith(TASK_ROW_PREFIX) ? row.id.slice(TASK_ROW_PREFIX.length) || null : null;
|
|
600
|
+
}
|
|
601
|
+
|
|
558
602
|
/*
|
|
559
603
|
* One agent the agent delegated to, foreground or background. Its own work stays in the thread as
|
|
560
604
|
* ordinary items that carry `parentToolUseId`, so streaming keeps working; the timeline gathers
|
package/src/index.ts
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
// Public API: exports.test.ts snapshots this list, so a name added or dropped here is an API change.
|
|
2
2
|
export {
|
|
3
|
-
KNOWN_AGENT_KINDS,
|
|
4
|
-
type KnownAgentKind,
|
|
5
3
|
AGENT_KIND_MAX_LENGTH,
|
|
6
4
|
AgentKindSchema,
|
|
7
5
|
type AgentKind,
|
|
8
|
-
isKnownAgentKind,
|
|
9
6
|
AgentStatusSchema,
|
|
10
7
|
type AgentStatus,
|
|
11
8
|
SUGGESTED_TITLE_LIMIT,
|
|
@@ -117,6 +114,8 @@ export {
|
|
|
117
114
|
ChatSubagentUsageSchema,
|
|
118
115
|
type ChatSubagentUsage,
|
|
119
116
|
HOST_TASK_ORIGIN,
|
|
117
|
+
taskRowId,
|
|
118
|
+
taskIdOfRow,
|
|
120
119
|
ChatSubagentItemSchema,
|
|
121
120
|
ChatApprovalDecisionSchema,
|
|
122
121
|
type ChatApprovalDecision,
|
|
@@ -267,7 +266,9 @@ export {
|
|
|
267
266
|
GeneratedImageInputSchema,
|
|
268
267
|
type GeneratedImageInput,
|
|
269
268
|
generatedImageAttachment,
|
|
270
|
-
holdsConversation
|
|
269
|
+
holdsConversation,
|
|
270
|
+
chatActivity,
|
|
271
|
+
type ChatActivity
|
|
271
272
|
} from './chat.ts';
|
|
272
273
|
export {
|
|
273
274
|
ErrorSchema,
|
|
@@ -322,6 +323,8 @@ export {
|
|
|
322
323
|
type ProviderPickerGroups,
|
|
323
324
|
providerGroupOf,
|
|
324
325
|
pickerGroupsOf,
|
|
326
|
+
inPickerOrder,
|
|
327
|
+
separatesGroups,
|
|
325
328
|
ProviderListResultSchema,
|
|
326
329
|
type ProviderListResult,
|
|
327
330
|
resumeCommandFor
|
|
@@ -369,6 +372,7 @@ export {
|
|
|
369
372
|
type TaskChangedEvent
|
|
370
373
|
} from './task.ts';
|
|
371
374
|
export { clipText, TOOL_OUTPUT_TAIL, appendToolOutput } from './text.ts';
|
|
375
|
+
export { type ToolFileEdit, type ToolFileEditPiece, toolFileEdit } from './tool-edits.ts';
|
|
372
376
|
export {
|
|
373
377
|
UsageProviderSchema,
|
|
374
378
|
type UsageProvider,
|
|
@@ -417,6 +421,7 @@ export {
|
|
|
417
421
|
export {
|
|
418
422
|
VISUAL_LIMITS,
|
|
419
423
|
VISUAL_MEASURE_WIDTHS,
|
|
424
|
+
REPLY_COLUMN_WIDTH,
|
|
420
425
|
VisualHeightSchema,
|
|
421
426
|
type VisualHeight,
|
|
422
427
|
VisualLayoutSchema,
|
package/src/model.ts
CHANGED
|
@@ -127,7 +127,10 @@ export const ProviderCapabilitiesSchema = z.object({
|
|
|
127
127
|
slashCommands: z.boolean(),
|
|
128
128
|
// How `/goal` reaches the CLI: through a protocol of its own that pauses, resumes and clears (`native`),
|
|
129
129
|
// or as the slash command alone (`command`); absent where the CLI has no goals.
|
|
130
|
-
goals: z.enum(['native', 'command']).optional()
|
|
130
|
+
goals: z.enum(['native', 'command']).optional(),
|
|
131
|
+
// Whether a chat can be forked and go on in a fork. Absent where it cannot. Where the conversation is copied from
|
|
132
|
+
// (a thread of the CLI's app-server, or a transcript file) is the provider's own business and stays off the wire.
|
|
133
|
+
fork: z.boolean().optional()
|
|
131
134
|
});
|
|
132
135
|
export type ProviderCapabilities = z.infer<typeof ProviderCapabilitiesSchema>;
|
|
133
136
|
|
|
@@ -211,6 +214,18 @@ export function pickerGroupsOf<T extends { kind: AgentKind; name: string }>(prov
|
|
|
211
214
|
return { frontier: inGroup('frontier'), others: inGroup('others'), api: inGroup('api') };
|
|
212
215
|
}
|
|
213
216
|
|
|
217
|
+
/* The providers in the order a picker lists them: the frontier labs, the rest, then the API providers, each by name. */
|
|
218
|
+
export function inPickerOrder<T extends { kind: AgentKind; name: string }>(providers: readonly T[]): T[] {
|
|
219
|
+
const groups = pickerGroupsOf(providers);
|
|
220
|
+
|
|
221
|
+
return [...groups.frontier, ...groups.others, ...groups.api];
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/* Whether a separator goes between two providers next to each other in that order: where one group ends. */
|
|
225
|
+
export function separatesGroups(previous: AgentKind | undefined, kind: AgentKind): boolean {
|
|
226
|
+
return previous !== undefined && providerGroupOf(previous) !== providerGroupOf(kind);
|
|
227
|
+
}
|
|
228
|
+
|
|
214
229
|
export const ProviderListResultSchema = z.object({
|
|
215
230
|
providers: z.array(ProviderInfoSchema)
|
|
216
231
|
});
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { isRecord } from '@adecore/utils/record';
|
|
2
|
+
|
|
3
|
+
/* One replacement a tool call makes in a file; a write has no `before`. */
|
|
4
|
+
export interface ToolFileEditPiece {
|
|
5
|
+
before: string;
|
|
6
|
+
after: string;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/* A file a tool call changes: a write replaces the file whole, an edit replaces pieces of it. */
|
|
10
|
+
export interface ToolFileEdit {
|
|
11
|
+
path: string;
|
|
12
|
+
write: boolean;
|
|
13
|
+
pieces: ToolFileEditPiece[];
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function text(value: unknown): string | null {
|
|
17
|
+
return typeof value === 'string' ? value : null;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function piece(edit: Record<string, unknown>): ToolFileEditPiece {
|
|
21
|
+
return { before: text(edit.old_string) ?? '', after: text(edit.new_string) ?? '' };
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/*
|
|
25
|
+
* The file an `Edit`, `Write` or `MultiEdit` call changes, from its input (the Apple backend uses the
|
|
26
|
+
* same names). Null for any other tool, and for a call that names no `file_path` or, for `MultiEdit`,
|
|
27
|
+
* no `edits` list. The diffs a provider reports with a call (`changes`) are not read here.
|
|
28
|
+
*/
|
|
29
|
+
export function toolFileEdit(name: string, input: unknown): ToolFileEdit | null {
|
|
30
|
+
if (!isRecord(input)) {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const path = text(input.file_path);
|
|
35
|
+
|
|
36
|
+
if (path === null) {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (name === 'Edit') {
|
|
41
|
+
return { path, write: false, pieces: [piece(input)] };
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (name === 'Write') {
|
|
45
|
+
return { path, write: true, pieces: [{ before: '', after: text(input.content) ?? '' }] };
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (name === 'MultiEdit' && Array.isArray(input.edits)) {
|
|
49
|
+
return { path, write: false, pieces: input.edits.filter(isRecord).map(piece) };
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return null;
|
|
53
|
+
}
|
package/src/visual.ts
CHANGED
|
@@ -17,6 +17,9 @@ export const VISUAL_LIMITS = {
|
|
|
17
17
|
heights: 24
|
|
18
18
|
} as const;
|
|
19
19
|
|
|
20
|
+
// The widest a chat's reply column runs by default, in CSS pixels. `@adecore/agents-react` reads it for its reading width, and its stylesheet falls back to the same number (`reading-width.test.ts` holds them together).
|
|
21
|
+
export const REPLY_COLUMN_WIDTH = 768;
|
|
22
|
+
|
|
20
23
|
// The frame widths a host may measure a page at, ascending, from a phone to a wide chat.
|
|
21
24
|
export const VISUAL_MEASURE_WIDTHS: readonly number[] = [320, 400, 480, 560, 640, 720, 800, 900, 1000, 1200];
|
|
22
25
|
|
|
@@ -423,7 +426,7 @@ export const VISUAL_PAGE_RULES =
|
|
|
423
426
|
'relative paths and local files do not. Prefer inline SVG or a canvas when the drawing needs no library. A link to an http(s) page opens in the browser.';
|
|
424
427
|
|
|
425
428
|
export const VISUAL_LAYOUT_GUIDE =
|
|
426
|
-
|
|
429
|
+
`The page appears as a borderless frame on the thread's own background. By default it follows the reply column (up to ${REPLY_COLUMN_WIDTH}px in a chat view). ` +
|
|
427
430
|
'Opt into the wide layout for application mockups or dashboards that need more space: the host uses the available chat pane width with side margins. ' +
|
|
428
431
|
'Both layouts shrink on narrow screens. Lay the page out at a fluid width (percentages, flex, grid) ' +
|
|
429
432
|
'with no horizontal padding on the outermost element. Draw no outer card, border, shadow or banner title: the page is part of the reply. ' +
|