@adecore/agents 0.49.6 → 0.49.7

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.
@@ -27,6 +27,7 @@ export declare class ChatLog {
27
27
  get onDisk(): boolean;
28
28
  append(event: ChatEvent, at: number): number;
29
29
  after(since: number): ChatEvent[] | null;
30
+ private indexAfter;
30
31
  compact(seq: number): void;
31
32
  close(): void;
32
33
  private open;
@@ -107,7 +107,21 @@ export class ChatLog {
107
107
  if (since < this.resetSeqValue || since < this.base || since > this.seqValue) {
108
108
  return null;
109
109
  }
110
- return this.lines.filter((line) => line.seq > since).map((line) => line.event);
110
+ return this.lines.slice(this.indexAfter(since)).map((line) => line.event);
111
+ }
112
+ indexAfter(seq) {
113
+ let first = 0;
114
+ let end = this.lines.length;
115
+ while (first < end) {
116
+ const middle = first + Math.floor((end - first) / 2);
117
+ if (this.lines[middle].seq > seq) {
118
+ end = middle;
119
+ }
120
+ else {
121
+ first = middle + 1;
122
+ }
123
+ }
124
+ return first;
111
125
  }
112
126
  /*
113
127
  * Folds the log into a snapshot that holds everything up to `seq`. What came after it (events
@@ -6,24 +6,34 @@ function isUsageProvider(kind) {
6
6
  }
7
7
  /* The accounts of the CLIs whose usage the host reads; a default account nobody named is called after its CLI. */
8
8
  export function machineAccounts(snapshot, nameOf) {
9
- return Object.entries(snapshot.accounts).flatMap(([id, account]) => {
9
+ const entries = Object.entries(snapshot.accounts);
10
+ let states = null;
11
+ const accounts = [];
12
+ for (const [id, account] of entries) {
10
13
  if (!isUsageProvider(account.kind)) {
11
- return [];
14
+ continue;
12
15
  }
13
- const isDefault = id === account.kind;
14
- const state = snapshot.statuses.find((status) => status.id === id)?.state;
15
- return [
16
- {
17
- id,
18
- kind: account.kind,
19
- label: account.label ?? (isDefault ? nameOf(account.kind) : id),
20
- ...(account.color === undefined ? {} : { color: account.color }),
21
- isDefault,
22
- enabled: account.enabled !== false,
23
- signedIn: state === 'ready'
16
+ if (states === null && entries.length >= 32 && snapshot.statuses.length >= 32) {
17
+ states = new Map();
18
+ for (const status of snapshot.statuses) {
19
+ if (!states.has(status.id)) {
20
+ states.set(status.id, status.state);
21
+ }
24
22
  }
25
- ];
26
- });
23
+ }
24
+ const isDefault = id === account.kind;
25
+ const state = states === null ? snapshot.statuses.find((status) => status.id === id)?.state : states.get(id);
26
+ accounts.push({
27
+ id,
28
+ kind: account.kind,
29
+ label: account.label ?? (isDefault ? nameOf(account.kind) : id),
30
+ ...(account.color === undefined ? {} : { color: account.color }),
31
+ isDefault,
32
+ enabled: account.enabled !== false,
33
+ signedIn: state === 'ready'
34
+ });
35
+ }
36
+ return accounts;
27
37
  }
28
38
  function usageAccount({ id, kind, label, color }) {
29
39
  return { id, kind, label, ...(color === undefined ? {} : { color }) };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adecore/agents",
3
- "version": "0.49.6",
3
+ "version": "0.49.7",
4
4
  "description": "Node-compatible agent chat hosts, providers, accounts, usage and durable task coordination.",
5
5
  "type": "module",
6
6
  "exports": {
@@ -93,8 +93,8 @@
93
93
  "test": "bun --conditions=source test"
94
94
  },
95
95
  "dependencies": {
96
- "@adecore/agent-contracts": "0.49.6",
97
- "@adecore/intelligent-ui": "0.49.6",
96
+ "@adecore/agent-contracts": "0.49.7",
97
+ "@adecore/intelligent-ui": "0.49.7",
98
98
  "zod": "^4.6.7"
99
99
  },
100
100
  "devDependencies": {
@@ -141,7 +141,24 @@ export class ChatLog {
141
141
  return null;
142
142
  }
143
143
 
144
- return this.lines.filter((line) => line.seq > since).map((line) => line.event);
144
+ return this.lines.slice(this.indexAfter(since)).map((line) => line.event);
145
+ }
146
+
147
+ private indexAfter(seq: number): number {
148
+ let first = 0;
149
+ let end = this.lines.length;
150
+
151
+ while (first < end) {
152
+ const middle = first + Math.floor((end - first) / 2);
153
+
154
+ if (this.lines[middle]!.seq > seq) {
155
+ end = middle;
156
+ } else {
157
+ first = middle + 1;
158
+ }
159
+ }
160
+
161
+ return first;
145
162
  }
146
163
 
147
164
  /*
@@ -16,26 +16,40 @@ interface MachineAccount extends UsageAccount {
16
16
 
17
17
  /* The accounts of the CLIs whose usage the host reads; a default account nobody named is called after its CLI. */
18
18
  export function machineAccounts(snapshot: ProviderAccounts, nameOf: (kind: UsageProvider) => string): MachineAccount[] {
19
- return Object.entries(snapshot.accounts).flatMap(([id, account]) => {
19
+ const entries = Object.entries(snapshot.accounts);
20
+ let states: Map<string, string> | null = null;
21
+
22
+ const accounts: MachineAccount[] = [];
23
+
24
+ for (const [id, account] of entries) {
20
25
  if (!isUsageProvider(account.kind)) {
21
- return [];
26
+ continue;
22
27
  }
23
28
 
24
- const isDefault = id === account.kind;
25
- const state = snapshot.statuses.find((status) => status.id === id)?.state;
26
-
27
- return [
28
- {
29
- id,
30
- kind: account.kind,
31
- label: account.label ?? (isDefault ? nameOf(account.kind) : id),
32
- ...(account.color === undefined ? {} : { color: account.color }),
33
- isDefault,
34
- enabled: account.enabled !== false,
35
- signedIn: state === 'ready'
29
+ if (states === null && entries.length >= 32 && snapshot.statuses.length >= 32) {
30
+ states = new Map();
31
+
32
+ for (const status of snapshot.statuses) {
33
+ if (!states.has(status.id)) {
34
+ states.set(status.id, status.state);
35
+ }
36
36
  }
37
- ];
38
- });
37
+ }
38
+
39
+ const isDefault = id === account.kind;
40
+ const state = states === null ? snapshot.statuses.find((status) => status.id === id)?.state : states.get(id);
41
+ accounts.push({
42
+ id,
43
+ kind: account.kind,
44
+ label: account.label ?? (isDefault ? nameOf(account.kind) : id),
45
+ ...(account.color === undefined ? {} : { color: account.color }),
46
+ isDefault,
47
+ enabled: account.enabled !== false,
48
+ signedIn: state === 'ready'
49
+ });
50
+ }
51
+
52
+ return accounts;
39
53
  }
40
54
 
41
55
  function usageAccount({ id, kind, label, color }: MachineAccount): UsageAccount {