@adecore/agent-contracts 0.47.0 → 0.48.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/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/protocol.d.ts +54 -0
- package/dist/protocol.js +2 -1
- package/dist/provider-accounts.d.ts +12 -0
- package/dist/provider-accounts.js +25 -1
- package/package.json +2 -2
- package/src/index.ts +5 -1
- package/src/protocol.ts +2 -0
- package/src/provider-accounts.ts +32 -1
package/dist/index.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ export { SessionIdSchema, type SessionId } from './ids.ts';
|
|
|
5
5
|
export { ModelOptionChoiceSchema, type ModelOptionChoice, ModelOptionDescriptorSchema, type ModelOptionDescriptor, ModelInfoSchema, type ModelInfo, ModelSelectionSchema, type ModelSelection, ModelCatalogProfileSchema, type ModelCatalogProfile, ModelCatalogEntrySchema, type ModelCatalogEntry, ModelCatalogDataSchema, type ModelCatalogData, RuntimeModeSchema, type RuntimeMode, ProviderCapabilitiesSchema, type ProviderCapabilities, ProviderPlatformSchema, type ProviderPlatform, ProviderSignInSchema, type ProviderSignIn, ProviderInstallSchema, type ProviderInstall, ProviderInfoSchema, type ProviderInfo, FRONTIER_PROVIDER_KINDS, API_PROVIDER_KINDS, type ProviderPickerGroup, type ProviderPickerGroups, providerGroupOf, pickerGroupsOf, ProviderListResultSchema, type ProviderListResult, resumeCommandFor } from './model.ts';
|
|
6
6
|
export type { FramePort } from './port.ts';
|
|
7
7
|
export { EmptySchema, AGENT_REQUEST_SCHEMAS, AGENT_EVENT_SCHEMAS, type AgentRequestType, type AgentEventType } from './protocol.ts';
|
|
8
|
-
export { ProviderAccountIdSchema, type ProviderAccountId, ProviderAccountVariableSchema, type ProviderAccountVariable, ProviderAccountSchema, type ProviderAccount, ProviderAccountStateSchema, type ProviderAccountState, ProviderAccountStatusSchema, type ProviderAccountStatus, ProviderAccountMapSchema, type ProviderAccountMap, ProviderAccountsSchema, type ProviderAccounts, ProviderAccountsSavePayloadSchema, type ProviderAccountsSavePayload, ProviderAccountCreatePayloadSchema, type ProviderAccountCreatePayload, ProviderAccountCreateResultSchema, type ProviderAccountCreateResult, ProviderAccountWatchLoginPayloadSchema, type ProviderAccountWatchLoginPayload } from './provider-accounts.ts';
|
|
8
|
+
export { ProviderAccountIdSchema, type ProviderAccountId, ProviderAccountVariableSchema, type ProviderAccountVariable, ProviderAccountSchema, type ProviderAccount, ProviderAccountStateSchema, type ProviderAccountState, ProviderAccountStatusSchema, type ProviderAccountStatus, ProviderAccountMapSchema, type ProviderAccountMap, ProviderAccountsSchema, type ProviderAccounts, ProviderAccountsSavePayloadSchema, type ProviderAccountsSavePayload, ProviderAccountCreatePayloadSchema, type ProviderAccountCreatePayload, ProviderAccountCreateResultSchema, type ProviderAccountCreateResult, ProviderAccountWatchLoginPayloadSchema, type ProviderAccountWatchLoginPayload, ProviderAccountsReorderPayloadSchema, type ProviderAccountsReorderPayload, orderedAccountIds, topAccountOf } from './provider-accounts.ts';
|
|
9
9
|
export { isRecord } from './record.ts';
|
|
10
10
|
export { TaskStatusSchema, type TaskStatus, TaskResultSchema, type TaskResult, TaskSchema, type Task, TaskChangedEventSchema, type TaskChangedEvent } from './task.ts';
|
|
11
11
|
export { clipText, TOOL_OUTPUT_TAIL, appendToolOutput } from './text.ts';
|
package/dist/index.js
CHANGED
|
@@ -5,7 +5,7 @@ export { ErrorSchema, RequestSchema, ReplyOkSchema, ReplyErrorSchema, ReplySchem
|
|
|
5
5
|
export { SessionIdSchema } from './ids.js';
|
|
6
6
|
export { ModelOptionChoiceSchema, ModelOptionDescriptorSchema, ModelInfoSchema, ModelSelectionSchema, ModelCatalogProfileSchema, ModelCatalogEntrySchema, ModelCatalogDataSchema, RuntimeModeSchema, ProviderCapabilitiesSchema, ProviderPlatformSchema, ProviderSignInSchema, ProviderInstallSchema, ProviderInfoSchema, FRONTIER_PROVIDER_KINDS, API_PROVIDER_KINDS, providerGroupOf, pickerGroupsOf, ProviderListResultSchema, resumeCommandFor } from './model.js';
|
|
7
7
|
export { EmptySchema, AGENT_REQUEST_SCHEMAS, AGENT_EVENT_SCHEMAS } from './protocol.js';
|
|
8
|
-
export { ProviderAccountIdSchema, ProviderAccountVariableSchema, ProviderAccountSchema, ProviderAccountStateSchema, ProviderAccountStatusSchema, ProviderAccountMapSchema, ProviderAccountsSchema, ProviderAccountsSavePayloadSchema, ProviderAccountCreatePayloadSchema, ProviderAccountCreateResultSchema, ProviderAccountWatchLoginPayloadSchema } from './provider-accounts.js';
|
|
8
|
+
export { ProviderAccountIdSchema, ProviderAccountVariableSchema, ProviderAccountSchema, ProviderAccountStateSchema, ProviderAccountStatusSchema, ProviderAccountMapSchema, ProviderAccountsSchema, ProviderAccountsSavePayloadSchema, ProviderAccountCreatePayloadSchema, ProviderAccountCreateResultSchema, ProviderAccountWatchLoginPayloadSchema, ProviderAccountsReorderPayloadSchema, orderedAccountIds, topAccountOf } from './provider-accounts.js';
|
|
9
9
|
export { isRecord } from './record.js';
|
|
10
10
|
export { TaskStatusSchema, TaskResultSchema, TaskSchema, TaskChangedEventSchema } from './task.js';
|
|
11
11
|
export { clipText, TOOL_OUTPUT_TAIL, appendToolOutput } from './text.js';
|
package/dist/protocol.d.ts
CHANGED
|
@@ -4549,6 +4549,7 @@ export declare const AGENT_REQUEST_SCHEMAS: {
|
|
|
4549
4549
|
sensitive: z.ZodBoolean;
|
|
4550
4550
|
valueRedacted: z.ZodOptional<z.ZodBoolean>;
|
|
4551
4551
|
}, z.core.$strip>>>;
|
|
4552
|
+
order: z.ZodOptional<z.ZodNumber>;
|
|
4552
4553
|
}, z.core.$strip>>;
|
|
4553
4554
|
statuses: z.ZodArray<z.ZodObject<{
|
|
4554
4555
|
id: z.ZodString;
|
|
@@ -4592,6 +4593,7 @@ export declare const AGENT_REQUEST_SCHEMAS: {
|
|
|
4592
4593
|
sensitive: z.ZodBoolean;
|
|
4593
4594
|
valueRedacted: z.ZodOptional<z.ZodBoolean>;
|
|
4594
4595
|
}, z.core.$strip>>>;
|
|
4596
|
+
order: z.ZodOptional<z.ZodNumber>;
|
|
4595
4597
|
}, z.core.$strip>>;
|
|
4596
4598
|
}, z.core.$strip>;
|
|
4597
4599
|
readonly result: z.ZodObject<{
|
|
@@ -4608,6 +4610,7 @@ export declare const AGENT_REQUEST_SCHEMAS: {
|
|
|
4608
4610
|
sensitive: z.ZodBoolean;
|
|
4609
4611
|
valueRedacted: z.ZodOptional<z.ZodBoolean>;
|
|
4610
4612
|
}, z.core.$strip>>>;
|
|
4613
|
+
order: z.ZodOptional<z.ZodNumber>;
|
|
4611
4614
|
}, z.core.$strip>>;
|
|
4612
4615
|
statuses: z.ZodArray<z.ZodObject<{
|
|
4613
4616
|
id: z.ZodString;
|
|
@@ -4652,6 +4655,7 @@ export declare const AGENT_REQUEST_SCHEMAS: {
|
|
|
4652
4655
|
sensitive: z.ZodBoolean;
|
|
4653
4656
|
valueRedacted: z.ZodOptional<z.ZodBoolean>;
|
|
4654
4657
|
}, z.core.$strip>>>;
|
|
4658
|
+
order: z.ZodOptional<z.ZodNumber>;
|
|
4655
4659
|
}, z.core.$strip>>;
|
|
4656
4660
|
statuses: z.ZodArray<z.ZodObject<{
|
|
4657
4661
|
id: z.ZodString;
|
|
@@ -4700,6 +4704,7 @@ export declare const AGENT_REQUEST_SCHEMAS: {
|
|
|
4700
4704
|
sensitive: z.ZodBoolean;
|
|
4701
4705
|
valueRedacted: z.ZodOptional<z.ZodBoolean>;
|
|
4702
4706
|
}, z.core.$strip>>>;
|
|
4707
|
+
order: z.ZodOptional<z.ZodNumber>;
|
|
4703
4708
|
}, z.core.$strip>>;
|
|
4704
4709
|
statuses: z.ZodArray<z.ZodObject<{
|
|
4705
4710
|
id: z.ZodString;
|
|
@@ -4735,6 +4740,54 @@ export declare const AGENT_REQUEST_SCHEMAS: {
|
|
|
4735
4740
|
}, z.core.$strip>;
|
|
4736
4741
|
readonly result: z.ZodObject<{}, z.core.$strip>;
|
|
4737
4742
|
};
|
|
4743
|
+
readonly 'accounts.reorder': {
|
|
4744
|
+
readonly payload: z.ZodObject<{
|
|
4745
|
+
kind: z.ZodString;
|
|
4746
|
+
ids: z.ZodArray<z.ZodString>;
|
|
4747
|
+
}, z.core.$strip>;
|
|
4748
|
+
readonly result: z.ZodObject<{
|
|
4749
|
+
accounts: z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
4750
|
+
kind: z.ZodString;
|
|
4751
|
+
label: z.ZodOptional<z.ZodString>;
|
|
4752
|
+
color: z.ZodOptional<z.ZodString>;
|
|
4753
|
+
enabled: z.ZodOptional<z.ZodBoolean>;
|
|
4754
|
+
home: z.ZodOptional<z.ZodString>;
|
|
4755
|
+
shadowHome: z.ZodOptional<z.ZodString>;
|
|
4756
|
+
env: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
4757
|
+
name: z.ZodString;
|
|
4758
|
+
value: z.ZodString;
|
|
4759
|
+
sensitive: z.ZodBoolean;
|
|
4760
|
+
valueRedacted: z.ZodOptional<z.ZodBoolean>;
|
|
4761
|
+
}, z.core.$strip>>>;
|
|
4762
|
+
order: z.ZodOptional<z.ZodNumber>;
|
|
4763
|
+
}, z.core.$strip>>;
|
|
4764
|
+
statuses: z.ZodArray<z.ZodObject<{
|
|
4765
|
+
id: z.ZodString;
|
|
4766
|
+
kind: z.ZodString;
|
|
4767
|
+
state: z.ZodEnum<{
|
|
4768
|
+
checking: "checking";
|
|
4769
|
+
disabled: "disabled";
|
|
4770
|
+
failed: "failed";
|
|
4771
|
+
"folder-missing": "folder-missing";
|
|
4772
|
+
"not-found": "not-found";
|
|
4773
|
+
ready: "ready";
|
|
4774
|
+
"signed-out": "signed-out";
|
|
4775
|
+
unavailable: "unavailable";
|
|
4776
|
+
}>;
|
|
4777
|
+
email: z.ZodNullable<z.ZodString>;
|
|
4778
|
+
plan: z.ZodNullable<z.ZodString>;
|
|
4779
|
+
organization: z.ZodNullable<z.ZodString>;
|
|
4780
|
+
home: z.ZodString;
|
|
4781
|
+
transcripts: z.ZodOptional<z.ZodString>;
|
|
4782
|
+
message: z.ZodNullable<z.ZodString>;
|
|
4783
|
+
checkedAt: z.ZodNumber;
|
|
4784
|
+
}, z.core.$strip>>;
|
|
4785
|
+
secretsAvailable: z.ZodOptional<z.ZodBoolean>;
|
|
4786
|
+
loginCommands: z.ZodOptional<z.ZodRecord<z.ZodString & z.core.$partial, z.ZodString>>;
|
|
4787
|
+
chatLogins: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
4788
|
+
silentLogins: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
4789
|
+
}, z.core.$strip>;
|
|
4790
|
+
};
|
|
4738
4791
|
readonly 'usage.summary': {
|
|
4739
4792
|
readonly payload: z.ZodObject<{
|
|
4740
4793
|
from: z.ZodString;
|
|
@@ -6563,6 +6616,7 @@ export declare const AGENT_EVENT_SCHEMAS: {
|
|
|
6563
6616
|
sensitive: z.ZodBoolean;
|
|
6564
6617
|
valueRedacted: z.ZodOptional<z.ZodBoolean>;
|
|
6565
6618
|
}, z.core.$strip>>>;
|
|
6619
|
+
order: z.ZodOptional<z.ZodNumber>;
|
|
6566
6620
|
}, z.core.$strip>>;
|
|
6567
6621
|
statuses: z.ZodArray<z.ZodObject<{
|
|
6568
6622
|
id: z.ZodString;
|
package/dist/protocol.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { ChatAddBookmarkPayloadSchema, ChatAnswerPayloadSchema, ChatApprovePayloadSchema, ChatAttachPayloadSchema, ChatAttachResultSchema, ChatBookmarksEventSchema, ChatBookmarksResultSchema, ChatCancelPayloadSchema, ChatClearPayloadSchema, ChatConfigurePayloadSchema, ChatContinueOnPayloadSchema, ChatContinueOnResultSchema, ChatCreatePayloadSchema, ChatDismissPayloadSchema, ChatEventEnvelopeSchema, ChatForkInfoPayloadSchema, ChatForkInfoResultSchema, ChatForkPayloadSchema, ChatForkResultSchema, ChatGoalPayloadSchema, ChatHistoryPayloadSchema, ChatHistoryResultSchema, ChatInfoSchema, ChatListResultSchema, ChatPreferencesPayloadSchema, ChatQueuePayloadSchema, ChatRemoveBookmarkPayloadSchema, ChatRemoveVisualPayloadSchema, ChatRenameBookmarkPayloadSchema, ChatSendPayloadSchema, ChatSendResultSchema, ChatUiChoicePayloadSchema, ChatUiLinkPayloadSchema, ChatUiLinkReadingSchema, ChatUiQueryPayloadSchema, ChatUiQueryReadingSchema, ChatStatusEventSchema, ChatStopSubagentPayloadSchema, ChatStopTaskPayloadSchema, ChatSubagentChangedEventSchema, ChatSubagentPayloadSchema, ChatSubagentResultSchema, ChatSummarizePayloadSchema, ChatSummarizeResultSchema, ChatTargetPayloadSchema, ChatTurnDiffPayloadSchema, ChatTurnDiffResultSchema, ChatToolOutputPayloadSchema, ChatToolOutputResultSchema, ChatUnqueueResultSchema, ChatVisualsEventSchema, ChatVisualsResultSchema, SkillsListPayloadSchema, SkillsListResultSchema } from './chat.js';
|
|
3
3
|
import { ProviderListResultSchema } from './model.js';
|
|
4
|
-
import { ProviderAccountCreatePayloadSchema, ProviderAccountCreateResultSchema, ProviderAccountWatchLoginPayloadSchema, ProviderAccountsSavePayloadSchema, ProviderAccountsSchema } from './provider-accounts.js';
|
|
4
|
+
import { ProviderAccountCreatePayloadSchema, ProviderAccountCreateResultSchema, ProviderAccountWatchLoginPayloadSchema, ProviderAccountsReorderPayloadSchema, ProviderAccountsSavePayloadSchema, ProviderAccountsSchema } from './provider-accounts.js';
|
|
5
5
|
import { UsageChangedEventSchema, UsageLimitsSnapshotSchema, UsageSummaryPayloadSchema, UsageSummaryResultSchema } from './usage.js';
|
|
6
6
|
export const EmptySchema = z.object({});
|
|
7
7
|
/*
|
|
@@ -51,6 +51,7 @@ export const AGENT_REQUEST_SCHEMAS = {
|
|
|
51
51
|
'accounts.create': { payload: ProviderAccountCreatePayloadSchema, result: ProviderAccountCreateResultSchema },
|
|
52
52
|
// Answers at once; what the CLI says arrives as `accounts.changed`.
|
|
53
53
|
'accounts.watchLogin': { payload: ProviderAccountWatchLoginPayloadSchema, result: EmptySchema },
|
|
54
|
+
'accounts.reorder': { payload: ProviderAccountsReorderPayloadSchema, result: ProviderAccountsSchema },
|
|
54
55
|
'usage.summary': { payload: UsageSummaryPayloadSchema, result: UsageSummaryResultSchema },
|
|
55
56
|
'usage.subscribe': { payload: EmptySchema, result: EmptySchema },
|
|
56
57
|
'usage.unsubscribe': { payload: EmptySchema, result: EmptySchema },
|
|
@@ -21,6 +21,7 @@ export declare const ProviderAccountSchema: z.ZodObject<{
|
|
|
21
21
|
sensitive: z.ZodBoolean;
|
|
22
22
|
valueRedacted: z.ZodOptional<z.ZodBoolean>;
|
|
23
23
|
}, z.core.$strip>>>;
|
|
24
|
+
order: z.ZodOptional<z.ZodNumber>;
|
|
24
25
|
}, z.core.$strip>;
|
|
25
26
|
export type ProviderAccount = z.infer<typeof ProviderAccountSchema>;
|
|
26
27
|
export declare const ProviderAccountStateSchema: z.ZodEnum<{
|
|
@@ -69,6 +70,7 @@ export declare const ProviderAccountMapSchema: z.ZodRecord<z.ZodString, z.ZodObj
|
|
|
69
70
|
sensitive: z.ZodBoolean;
|
|
70
71
|
valueRedacted: z.ZodOptional<z.ZodBoolean>;
|
|
71
72
|
}, z.core.$strip>>>;
|
|
73
|
+
order: z.ZodOptional<z.ZodNumber>;
|
|
72
74
|
}, z.core.$strip>>;
|
|
73
75
|
export type ProviderAccountMap = z.infer<typeof ProviderAccountMapSchema>;
|
|
74
76
|
export declare const ProviderAccountsSchema: z.ZodObject<{
|
|
@@ -85,6 +87,7 @@ export declare const ProviderAccountsSchema: z.ZodObject<{
|
|
|
85
87
|
sensitive: z.ZodBoolean;
|
|
86
88
|
valueRedacted: z.ZodOptional<z.ZodBoolean>;
|
|
87
89
|
}, z.core.$strip>>>;
|
|
90
|
+
order: z.ZodOptional<z.ZodNumber>;
|
|
88
91
|
}, z.core.$strip>>;
|
|
89
92
|
statuses: z.ZodArray<z.ZodObject<{
|
|
90
93
|
id: z.ZodString;
|
|
@@ -127,9 +130,17 @@ export declare const ProviderAccountsSavePayloadSchema: z.ZodObject<{
|
|
|
127
130
|
sensitive: z.ZodBoolean;
|
|
128
131
|
valueRedacted: z.ZodOptional<z.ZodBoolean>;
|
|
129
132
|
}, z.core.$strip>>>;
|
|
133
|
+
order: z.ZodOptional<z.ZodNumber>;
|
|
130
134
|
}, z.core.$strip>>;
|
|
131
135
|
}, z.core.$strip>;
|
|
132
136
|
export type ProviderAccountsSavePayload = z.infer<typeof ProviderAccountsSavePayloadSchema>;
|
|
137
|
+
export declare const ProviderAccountsReorderPayloadSchema: z.ZodObject<{
|
|
138
|
+
kind: z.ZodString;
|
|
139
|
+
ids: z.ZodArray<z.ZodString>;
|
|
140
|
+
}, z.core.$strip>;
|
|
141
|
+
export type ProviderAccountsReorderPayload = z.infer<typeof ProviderAccountsReorderPayloadSchema>;
|
|
142
|
+
export declare function orderedAccountIds(accounts: ProviderAccountMap, kind: string): string[];
|
|
143
|
+
export declare function topAccountOf(accounts: ProviderAccountMap, kind: string): string;
|
|
133
144
|
export declare const ProviderAccountCreatePayloadSchema: z.ZodObject<{
|
|
134
145
|
kind: z.ZodString;
|
|
135
146
|
label: z.ZodString;
|
|
@@ -150,6 +161,7 @@ export declare const ProviderAccountCreateResultSchema: z.ZodObject<{
|
|
|
150
161
|
sensitive: z.ZodBoolean;
|
|
151
162
|
valueRedacted: z.ZodOptional<z.ZodBoolean>;
|
|
152
163
|
}, z.core.$strip>>>;
|
|
164
|
+
order: z.ZodOptional<z.ZodNumber>;
|
|
153
165
|
}, z.core.$strip>>;
|
|
154
166
|
statuses: z.ZodArray<z.ZodObject<{
|
|
155
167
|
id: z.ZodString;
|
|
@@ -31,7 +31,9 @@ export const ProviderAccountSchema = z.object({
|
|
|
31
31
|
// Codex only: a folder of its own for the login, sharing everything else with `home`.
|
|
32
32
|
shadowHome: z.string().min(1).optional(),
|
|
33
33
|
// Set on the CLI's environment after the login variables are taken off, so a key here is one a person chose.
|
|
34
|
-
env: z.array(ProviderAccountVariableSchema).optional()
|
|
34
|
+
env: z.array(ProviderAccountVariableSchema).optional(),
|
|
35
|
+
// Its place among the accounts of its CLI, lowest first; only `accounts.reorder` sets it, and a save without it keeps it.
|
|
36
|
+
order: z.number().int().nonnegative().optional()
|
|
35
37
|
});
|
|
36
38
|
export const ProviderAccountStateSchema = z.enum([
|
|
37
39
|
'checking',
|
|
@@ -79,6 +81,28 @@ export const ProviderAccountsSchema = z.object({
|
|
|
79
81
|
export const ProviderAccountsSavePayloadSchema = z.object({
|
|
80
82
|
accounts: ProviderAccountMapSchema
|
|
81
83
|
});
|
|
84
|
+
/* The accounts of one CLI in a person's order; an account of that CLI left out loses its place and falls in after the ordered ones. */
|
|
85
|
+
export const ProviderAccountsReorderPayloadSchema = z.object({
|
|
86
|
+
kind: AgentKindSchema,
|
|
87
|
+
ids: z.array(ProviderAccountIdSchema)
|
|
88
|
+
});
|
|
89
|
+
/*
|
|
90
|
+
* The ids of the accounts of one CLI in a person's order: the ordered ones first, then the default
|
|
91
|
+
* account, then the rest by id, so a machine where nobody reordered keeps the default on top.
|
|
92
|
+
*/
|
|
93
|
+
export function orderedAccountIds(accounts, kind) {
|
|
94
|
+
const rank = (id, account) => [account.order ?? Number.POSITIVE_INFINITY, id === kind ? 0 : 1, id];
|
|
95
|
+
return (Object.entries(accounts)
|
|
96
|
+
.filter(([, account]) => account.kind === kind)
|
|
97
|
+
.map(([id, account]) => ({ id, rank: rank(id, account) }))
|
|
98
|
+
// Ids compare by code point, the way the iPhone app compares them, so both name the same account first.
|
|
99
|
+
.sort((a, b) => a.rank[0] - b.rank[0] || a.rank[1] - b.rank[1] || (a.rank[2] < b.rank[2] ? -1 : a.rank[2] > b.rank[2] ? 1 : 0))
|
|
100
|
+
.map((entry) => entry.id));
|
|
101
|
+
}
|
|
102
|
+
/* The account a start of this CLI takes when nothing names one: the first in the order that is on, else the CLI's default account. */
|
|
103
|
+
export function topAccountOf(accounts, kind) {
|
|
104
|
+
return orderedAccountIds(accounts, kind).find((id) => accounts[id]?.enabled !== false) ?? kind;
|
|
105
|
+
}
|
|
82
106
|
/* An account in a folder the daemon makes for it under its account data directory; a Codex one is a shadow home over the CLI's own folder. */
|
|
83
107
|
export const ProviderAccountCreatePayloadSchema = z.object({
|
|
84
108
|
kind: AgentKindSchema,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adecore/agent-contracts",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.48.0",
|
|
4
4
|
"description": "Schemas and port contracts for agent chats, provider accounts, models and usage.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -86,7 +86,7 @@
|
|
|
86
86
|
"test": "bun --conditions=source test"
|
|
87
87
|
},
|
|
88
88
|
"dependencies": {
|
|
89
|
-
"@adecore/intelligent-ui": "0.
|
|
89
|
+
"@adecore/intelligent-ui": "0.48.0",
|
|
90
90
|
"zod": "^4.6.7"
|
|
91
91
|
},
|
|
92
92
|
"devDependencies": {
|
package/src/index.ts
CHANGED
|
@@ -350,7 +350,11 @@ export {
|
|
|
350
350
|
ProviderAccountCreateResultSchema,
|
|
351
351
|
type ProviderAccountCreateResult,
|
|
352
352
|
ProviderAccountWatchLoginPayloadSchema,
|
|
353
|
-
type ProviderAccountWatchLoginPayload
|
|
353
|
+
type ProviderAccountWatchLoginPayload,
|
|
354
|
+
ProviderAccountsReorderPayloadSchema,
|
|
355
|
+
type ProviderAccountsReorderPayload,
|
|
356
|
+
orderedAccountIds,
|
|
357
|
+
topAccountOf
|
|
354
358
|
} from './provider-accounts.ts';
|
|
355
359
|
export { isRecord } from './record.ts';
|
|
356
360
|
export {
|
package/src/protocol.ts
CHANGED
|
@@ -60,6 +60,7 @@ import {
|
|
|
60
60
|
ProviderAccountCreatePayloadSchema,
|
|
61
61
|
ProviderAccountCreateResultSchema,
|
|
62
62
|
ProviderAccountWatchLoginPayloadSchema,
|
|
63
|
+
ProviderAccountsReorderPayloadSchema,
|
|
63
64
|
ProviderAccountsSavePayloadSchema,
|
|
64
65
|
ProviderAccountsSchema
|
|
65
66
|
} from './provider-accounts.ts';
|
|
@@ -114,6 +115,7 @@ export const AGENT_REQUEST_SCHEMAS = {
|
|
|
114
115
|
'accounts.create': { payload: ProviderAccountCreatePayloadSchema, result: ProviderAccountCreateResultSchema },
|
|
115
116
|
// Answers at once; what the CLI says arrives as `accounts.changed`.
|
|
116
117
|
'accounts.watchLogin': { payload: ProviderAccountWatchLoginPayloadSchema, result: EmptySchema },
|
|
118
|
+
'accounts.reorder': { payload: ProviderAccountsReorderPayloadSchema, result: ProviderAccountsSchema },
|
|
117
119
|
'usage.summary': { payload: UsageSummaryPayloadSchema, result: UsageSummaryResultSchema },
|
|
118
120
|
'usage.subscribe': { payload: EmptySchema, result: EmptySchema },
|
|
119
121
|
'usage.unsubscribe': { payload: EmptySchema, result: EmptySchema },
|
package/src/provider-accounts.ts
CHANGED
|
@@ -37,7 +37,9 @@ export const ProviderAccountSchema = z.object({
|
|
|
37
37
|
// Codex only: a folder of its own for the login, sharing everything else with `home`.
|
|
38
38
|
shadowHome: z.string().min(1).optional(),
|
|
39
39
|
// Set on the CLI's environment after the login variables are taken off, so a key here is one a person chose.
|
|
40
|
-
env: z.array(ProviderAccountVariableSchema).optional()
|
|
40
|
+
env: z.array(ProviderAccountVariableSchema).optional(),
|
|
41
|
+
// Its place among the accounts of its CLI, lowest first; only `accounts.reorder` sets it, and a save without it keeps it.
|
|
42
|
+
order: z.number().int().nonnegative().optional()
|
|
41
43
|
});
|
|
42
44
|
export type ProviderAccount = z.infer<typeof ProviderAccountSchema>;
|
|
43
45
|
|
|
@@ -97,6 +99,35 @@ export const ProviderAccountsSavePayloadSchema = z.object({
|
|
|
97
99
|
});
|
|
98
100
|
export type ProviderAccountsSavePayload = z.infer<typeof ProviderAccountsSavePayloadSchema>;
|
|
99
101
|
|
|
102
|
+
/* The accounts of one CLI in a person's order; an account of that CLI left out loses its place and falls in after the ordered ones. */
|
|
103
|
+
export const ProviderAccountsReorderPayloadSchema = z.object({
|
|
104
|
+
kind: AgentKindSchema,
|
|
105
|
+
ids: z.array(ProviderAccountIdSchema)
|
|
106
|
+
});
|
|
107
|
+
export type ProviderAccountsReorderPayload = z.infer<typeof ProviderAccountsReorderPayloadSchema>;
|
|
108
|
+
|
|
109
|
+
/*
|
|
110
|
+
* The ids of the accounts of one CLI in a person's order: the ordered ones first, then the default
|
|
111
|
+
* account, then the rest by id, so a machine where nobody reordered keeps the default on top.
|
|
112
|
+
*/
|
|
113
|
+
export function orderedAccountIds(accounts: ProviderAccountMap, kind: string): string[] {
|
|
114
|
+
const rank = (id: string, account: ProviderAccount): [number, number, string] => [account.order ?? Number.POSITIVE_INFINITY, id === kind ? 0 : 1, id];
|
|
115
|
+
|
|
116
|
+
return (
|
|
117
|
+
Object.entries(accounts)
|
|
118
|
+
.filter(([, account]) => account.kind === kind)
|
|
119
|
+
.map(([id, account]) => ({ id, rank: rank(id, account) }))
|
|
120
|
+
// Ids compare by code point, the way the iPhone app compares them, so both name the same account first.
|
|
121
|
+
.sort((a, b) => a.rank[0] - b.rank[0] || a.rank[1] - b.rank[1] || (a.rank[2] < b.rank[2] ? -1 : a.rank[2] > b.rank[2] ? 1 : 0))
|
|
122
|
+
.map((entry) => entry.id)
|
|
123
|
+
);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/* The account a start of this CLI takes when nothing names one: the first in the order that is on, else the CLI's default account. */
|
|
127
|
+
export function topAccountOf(accounts: ProviderAccountMap, kind: string): string {
|
|
128
|
+
return orderedAccountIds(accounts, kind).find((id) => accounts[id]?.enabled !== false) ?? kind;
|
|
129
|
+
}
|
|
130
|
+
|
|
100
131
|
/* An account in a folder the daemon makes for it under its account data directory; a Codex one is a shadow home over the CLI's own folder. */
|
|
101
132
|
export const ProviderAccountCreatePayloadSchema = z.object({
|
|
102
133
|
kind: AgentKindSchema,
|