bkper 4.18.4 → 4.19.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 (39) hide show
  1. package/README.md +7 -3
  2. package/lib/agent/auth-commands.d.ts +28 -0
  3. package/lib/agent/auth-commands.d.ts.map +1 -0
  4. package/lib/agent/auth-commands.js +388 -0
  5. package/lib/agent/auth-commands.js.map +1 -0
  6. package/lib/agent/bkper-ai-provider.d.ts +6 -0
  7. package/lib/agent/bkper-ai-provider.d.ts.map +1 -0
  8. package/lib/agent/bkper-ai-provider.js +140 -0
  9. package/lib/agent/bkper-ai-provider.js.map +1 -0
  10. package/lib/agent/run-agent-mode.d.ts.map +1 -1
  11. package/lib/agent/run-agent-mode.js +46 -5
  12. package/lib/agent/run-agent-mode.js.map +1 -1
  13. package/lib/auth/local-auth-service.d.ts +23 -4
  14. package/lib/auth/local-auth-service.d.ts.map +1 -1
  15. package/lib/auth/local-auth-service.js +97 -27
  16. package/lib/auth/local-auth-service.js.map +1 -1
  17. package/lib/cli.js +2 -0
  18. package/lib/cli.js.map +1 -1
  19. package/lib/commands/events/index.d.ts +3 -0
  20. package/lib/commands/events/index.d.ts.map +1 -0
  21. package/lib/commands/events/index.js +3 -0
  22. package/lib/commands/events/index.js.map +1 -0
  23. package/lib/commands/events/list.d.ts +36 -0
  24. package/lib/commands/events/list.d.ts.map +1 -0
  25. package/lib/commands/events/list.js +160 -0
  26. package/lib/commands/events/list.js.map +1 -0
  27. package/lib/commands/events/register.d.ts +8 -0
  28. package/lib/commands/events/register.d.ts.map +1 -0
  29. package/lib/commands/events/register.js +66 -0
  30. package/lib/commands/events/register.js.map +1 -0
  31. package/lib/commands/events/replay.d.ts +11 -0
  32. package/lib/commands/events/replay.d.ts.map +1 -0
  33. package/lib/commands/events/replay.js +30 -0
  34. package/lib/commands/events/replay.js.map +1 -0
  35. package/lib/docs/cli/app-management.md +6 -1
  36. package/lib/docs/cli/data-management.md +44 -1
  37. package/lib/docs/sdk/bkper-api-types.md +2 -0
  38. package/lib/docs/sdk/bkper-js.md +37 -1
  39. package/package.json +4 -4
@@ -0,0 +1,160 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { getBkperInstance } from '../../bkper-factory.js';
11
+ import { quoteShellArg } from '../../utils/shell-quote.js';
12
+ export const DEFAULT_EVENT_LIST_LIMIT = 50;
13
+ const PREVIEW_MAX_LENGTH = 80;
14
+ /**
15
+ * Lists one page of events from a book.
16
+ *
17
+ * @param bookId - The book ID to query
18
+ * @param options - Filter and pagination options
19
+ * @returns Event page items and optional next cursor
20
+ */
21
+ export function listEvents(bookId_1) {
22
+ return __awaiter(this, arguments, void 0, function* (bookId, options = {}) {
23
+ const bkper = getBkperInstance();
24
+ const book = yield bkper.getBook(bookId);
25
+ const listOptions = toListEventsOptions(options);
26
+ const result = yield book.listEvents(listOptions);
27
+ const page = {
28
+ items: result.getItems(),
29
+ };
30
+ const nextCursor = result.getCursor();
31
+ if (nextCursor) {
32
+ page.cursor = nextCursor;
33
+ }
34
+ return page;
35
+ });
36
+ }
37
+ /**
38
+ * Lists events and returns a ListResult ready for rendering.
39
+ * JSON includes full event payloads with botResponses for LLM debugging.
40
+ */
41
+ export function listEventsFormatted(bookId, options, format) {
42
+ return __awaiter(this, void 0, void 0, function* () {
43
+ const result = yield listEvents(bookId, options);
44
+ if (format === 'json') {
45
+ const jsonResult = {
46
+ kind: 'json',
47
+ items: result.items.map(event => event.json()),
48
+ };
49
+ if (result.cursor) {
50
+ jsonResult.cursor = result.cursor;
51
+ }
52
+ return jsonResult;
53
+ }
54
+ return {
55
+ kind: 'matrix',
56
+ matrix: buildEventsMatrix(result.items),
57
+ footer: buildEventListFooter(bookId, options, result.cursor),
58
+ };
59
+ });
60
+ }
61
+ function toListEventsOptions(options) {
62
+ var _a;
63
+ const listOptions = {
64
+ limit: (_a = options.limit) !== null && _a !== void 0 ? _a : DEFAULT_EVENT_LIST_LIMIT,
65
+ };
66
+ if (options.afterDate !== undefined) {
67
+ listOptions.afterDate = options.afterDate;
68
+ }
69
+ if (options.beforeDate !== undefined) {
70
+ listOptions.beforeDate = options.beforeDate;
71
+ }
72
+ if (options.resourceId !== undefined) {
73
+ listOptions.resourceId = options.resourceId;
74
+ }
75
+ if (options.onError === true) {
76
+ listOptions.onError = true;
77
+ }
78
+ if (options.type !== undefined) {
79
+ listOptions.type = options.type;
80
+ }
81
+ if (options.cursor !== undefined) {
82
+ listOptions.cursor = options.cursor;
83
+ }
84
+ return listOptions;
85
+ }
86
+ function buildEventsMatrix(events) {
87
+ const matrix = [
88
+ ['ID', 'Type', 'Created', 'Resource', 'User', 'Agent', 'Responses', 'Errors', 'Preview'],
89
+ ];
90
+ for (const event of events) {
91
+ const json = event.json();
92
+ const botResponses = json.botResponses || [];
93
+ const errorResponses = botResponses.filter(response => response.type === 'ERROR');
94
+ matrix.push([
95
+ json.id || '',
96
+ json.type || '',
97
+ json.createdOn || json.createdAt || '',
98
+ json.resource || '',
99
+ formatUser(json.user),
100
+ formatAgent(json.agent),
101
+ botResponses.length,
102
+ errorResponses.length,
103
+ formatBotResponsePreview(botResponses),
104
+ ]);
105
+ }
106
+ return matrix;
107
+ }
108
+ function formatUser(user) {
109
+ if (!user) {
110
+ return '';
111
+ }
112
+ return user.email || user.name || user.id || '';
113
+ }
114
+ function formatAgent(agent) {
115
+ if (!agent) {
116
+ return '';
117
+ }
118
+ return agent.name || agent.id || '';
119
+ }
120
+ function formatBotResponsePreview(botResponses) {
121
+ const preferred = botResponses.find(response => response.type === 'ERROR' && response.message) ||
122
+ botResponses.find(response => response.message);
123
+ if (!(preferred === null || preferred === void 0 ? void 0 : preferred.message)) {
124
+ return '';
125
+ }
126
+ return truncate(preferred.message, PREVIEW_MAX_LENGTH);
127
+ }
128
+ function truncate(value, maxLength) {
129
+ if (value.length <= maxLength) {
130
+ return value;
131
+ }
132
+ return `${value.slice(0, maxLength - 1)}…`;
133
+ }
134
+ function buildEventListFooter(bookId, options, cursor) {
135
+ var _a;
136
+ if (!cursor) {
137
+ return undefined;
138
+ }
139
+ const limit = (_a = options.limit) !== null && _a !== void 0 ? _a : DEFAULT_EVENT_LIST_LIMIT;
140
+ const parts = [`bkper event list -b ${quoteShellArg(bookId)}`];
141
+ if (options.afterDate) {
142
+ parts.push(`--after ${quoteShellArg(options.afterDate)}`);
143
+ }
144
+ if (options.beforeDate) {
145
+ parts.push(`--before ${quoteShellArg(options.beforeDate)}`);
146
+ }
147
+ if (options.resourceId) {
148
+ parts.push(`--resource ${quoteShellArg(options.resourceId)}`);
149
+ }
150
+ if (options.onError) {
151
+ parts.push('--error');
152
+ }
153
+ if (options.type) {
154
+ parts.push(`--type ${quoteShellArg(options.type)}`);
155
+ }
156
+ parts.push(`--limit ${limit}`);
157
+ parts.push(`--cursor ${quoteShellArg(cursor)}`);
158
+ return [`Next cursor: ${cursor}`, `Next page: ${parts.join(' ')}`].join('\n');
159
+ }
160
+ //# sourceMappingURL=list.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"list.js","sourceRoot":"","sources":["../../../src/commands/events/list.ts"],"names":[],"mappings":";;;;;;;;;AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAE1D,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAE3D,MAAM,CAAC,MAAM,wBAAwB,GAAG,EAAE,CAAC;AAC3C,MAAM,kBAAkB,GAAG,EAAE,CAAC;AAuB9B;;;;;;GAMG;AACH,M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CAAC;IAC1B,CAAC;IACD,IAAI,OAAO,CAAC,IAAI,EAAE,CAAC;QACf,KAAK,CAAC,IAAI,CAAC,UAAU,aAAa,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACxD,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,WAAW,KAAK,EAAE,CAAC,CAAC;IAC/B,KAAK,CAAC,IAAI,CAAC,YAAY,aAAa,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;IAEhD,OAAO,CAAC,gBAAgB,MAAM,EAAE,EAAE,cAAc,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAClF,CAAC"}
@@ -0,0 +1,8 @@
1
+ import type { Command } from 'commander';
2
+ import { EventType } from 'bkper-js';
3
+ /**
4
+ * Commander parser for EventType values.
5
+ */
6
+ export declare function parseEventType(value: string): EventType;
7
+ export declare function registerEventCommands(program: Command): void;
8
+ //# sourceMappingURL=register.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"register.d.ts","sourceRoot":"","sources":["../../../src/commands/events/register.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AASrC;;GAEG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,CAOvD;AAED,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAuD5D"}
@@ -0,0 +1,66 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { EventType } from 'bkper-js';
11
+ import { withAction } from '../action.js';
12
+ import { parsePositiveInteger } from '../cli-helpers.js';
13
+ import { renderItem, renderListResult } from '../../render/index.js';
14
+ import { validateRequiredOptions, throwIfErrors } from '../../utils/validation.js';
15
+ import { listEventsFormatted, replayEventBotResponse } from './index.js';
16
+ const EVENT_TYPE_VALUES = new Set(Object.values(EventType));
17
+ /**
18
+ * Commander parser for EventType values.
19
+ */
20
+ export function parseEventType(value) {
21
+ if (!EVENT_TYPE_VALUES.has(value)) {
22
+ throw new Error(`Invalid event type '${value}'. Valid types: ${Object.values(EventType).join(', ')}`);
23
+ }
24
+ return value;
25
+ }
26
+ export function registerEventCommands(program) {
27
+ const eventCommand = program.command('event').description('Inspect book events and bot responses');
28
+ eventCommand
29
+ .command('list')
30
+ .description('List events in a book (includes bot responses)')
31
+ .option('-b, --book <bookId>', 'Book ID')
32
+ .option('--after <date>', 'Start date inclusive (RFC3339)')
33
+ .option('--before <date>', 'End date exclusive (RFC3339)')
34
+ .option('--resource <resourceId>', 'Filter by resource ID (Transaction, Account, or Group)')
35
+ .option('--error', 'Only events with at least one error bot response')
36
+ .option('--type <type>', 'Filter by event type', parseEventType)
37
+ .option('--limit <limit>', 'Fetch one page with up to this many events (default 50, max 200)', parsePositiveInteger)
38
+ .option('--cursor <cursor>', 'Cursor for fetching the next page')
39
+ .action(options => withAction('listing events', (format) => __awaiter(this, void 0, void 0, function* () {
40
+ throwIfErrors(validateRequiredOptions(options, [{ name: 'book', flag: '--book' }]));
41
+ const result = yield listEventsFormatted(options.book, {
42
+ afterDate: options.after,
43
+ beforeDate: options.before,
44
+ resourceId: options.resource,
45
+ onError: options.error === true ? true : undefined,
46
+ type: options.type,
47
+ limit: options.limit,
48
+ cursor: options.cursor,
49
+ }, format);
50
+ renderListResult(result, format);
51
+ }))());
52
+ eventCommand
53
+ .command('replay <eventId>')
54
+ .description('Replay one bot response for an event')
55
+ .option('-b, --book <bookId>', 'Book ID')
56
+ .option('--agent-id <agentId>', 'Bot/agent ID to replay')
57
+ .action((eventId, options) => withAction('replaying event bot response', (format) => __awaiter(this, void 0, void 0, function* () {
58
+ throwIfErrors(validateRequiredOptions(options, [
59
+ { name: 'book', flag: '--book' },
60
+ { name: 'agentId', flag: '--agent-id' },
61
+ ]));
62
+ const event = yield replayEventBotResponse(options.book, eventId, options.agentId);
63
+ renderItem(event.json(), format);
64
+ }))());
65
+ }
66
+ //# sourceMappingURL=register.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"register.js","sourceRoot":"","sources":["../../../src/commands/events/register.ts"],"names":[],"mappings":";;;;;;;;;AACA,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AACrC,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AACzD,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACrE,OAAO,EAAE,uBAAuB,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AACnF,OAAO,EAAE,mBAAmB,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AAEzE,MAAM,iBAAiB,GAAG,IAAI,GAAG,CAAS,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC;AAEpE;;GAEG;AACH,MAAM,UAAU,cAAc,CAAC,KAAa;IACxC,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC;QAChC,MAAM,IAAI,KAAK,CACX,uBAAuB,KAAK,mBAAmB,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CACvF,CAAC;IACN,CAAC;IACD,OAAO,KAAkB,CAAC;AAC9B,CAAC;AAED,M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C;QACF,gBAAgB,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACrC,CAAC,CAAA,CAAC,EAAE,CACP,CAAC;IAEN,YAAY;SACP,OAAO,CAAC,kBAAkB,CAAC;SAC3B,WAAW,CAAC,sCAAsC,CAAC;SACnD,MAAM,CAAC,qBAAqB,EAAE,SAAS,CAAC;SACxC,MAAM,CAAC,sBAAsB,EAAE,wBAAwB,CAAC;SACxD,MAAM,CAAC,CAAC,OAAe,EAAE,OAAO,EAAE,EAAE,CACjC,UAAU,CAAC,8BAA8B,EAAE,CAAM,MAAM,EAAC,EAAE;QACtD,aAAa,CACT,uBAAuB,CAAC,OAAO,EAAE;YAC7B,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE;YAChC,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,YAAY,EAAE;SAC1C,CAAC,CACL,CAAC;QACF,MAAM,KAAK,GAAG,MAAM,sBAAsB,CAAC,OAAO,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;QACnF,UAAU,CAAC,KAAK,CAAC,IAAI,EAAE,EAAE,MAAM,CAAC,CAAC;IACrC,CAAC,CAAA,CAAC,EAAE,CACP,CAAC;AACV,CAAC"}
@@ -0,0 +1,11 @@
1
+ import { Event } from 'bkper-js';
2
+ /**
3
+ * Replays one bot response for an event.
4
+ *
5
+ * @param bookId - The book ID containing the event
6
+ * @param eventId - The event ID to replay
7
+ * @param agentId - The bot/agent ID whose response should be replayed
8
+ * @returns The updated event payload after replay
9
+ */
10
+ export declare function replayEventBotResponse(bookId: string, eventId: string, agentId: string): Promise<Event>;
11
+ //# sourceMappingURL=replay.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"replay.d.ts","sourceRoot":"","sources":["../../../src/commands/events/replay.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,KAAK,EAAE,MAAM,UAAU,CAAC;AAG9C;;;;;;;GAOG;AACH,wBAAsB,sBAAsB,CACxC,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,GAChB,OAAO,CAAC,KAAK,CAAC,CAOhB"}
@@ -0,0 +1,30 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { BotResponse, Event } from 'bkper-js';
11
+ import { getBkperInstance } from '../../bkper-factory.js';
12
+ /**
13
+ * Replays one bot response for an event.
14
+ *
15
+ * @param bookId - The book ID containing the event
16
+ * @param eventId - The event ID to replay
17
+ * @param agentId - The bot/agent ID whose response should be replayed
18
+ * @returns The updated event payload after replay
19
+ */
20
+ export function replayEventBotResponse(bookId, eventId, agentId) {
21
+ return __awaiter(this, void 0, void 0, function* () {
22
+ const bkper = getBkperInstance();
23
+ const book = yield bkper.getBook(bookId);
24
+ const event = new Event(book, { id: eventId });
25
+ const botResponse = new BotResponse(event, { agentId });
26
+ yield botResponse.replay();
27
+ return event;
28
+ });
29
+ }
30
+ //# sourceMappingURL=replay.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"replay.js","sourceRoot":"","sources":["../../../src/commands/events/replay.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAC9C,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAE1D;;;;;;;GAOG;AACH,MAAM,UAAgB,sBAAsB,CACxC,MAAc,EACd,OAAe,EACf,OAAe;;QAEf,MAAM,KAAK,GAAG,gBAAgB,EAAE,CAAC;QACjC,MAAM,IAAI,GAAG,MAAM,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;QACzC,MAAM,KAAK,GAAG,IAAI,KAAK,CAAC,IAAI,EAAE,EAAE,EAAE,EAAE,OAAO,EAAE,CAAC,CAAC;QAC/C,MAAM,WAAW,GAAG,IAAI,WAAW,CAAC,KAAK,EAAE,EAAE,OAAO,EAAE,CAAC,CAAC;QACxD,MAAM,WAAW,CAAC,MAAM,EAAE,CAAC;QAC3B,OAAO,KAAK,CAAC;IACjB,CAAC;CAAA"}
@@ -416,7 +416,12 @@ deployment:
416
416
  - `agent` - Start the interactive Bkper Agent
417
417
  - `agent <pi-args...>` - Run Pi CLI with Bkper defaults (system prompt/resources)
418
418
 
419
- Inside the interactive agent, `/login` connects an AI model provider; it is separate from `bkper auth login`, which connects the CLI to your Bkper account.
419
+ Inside the interactive agent:
420
+
421
+ - `/login` connects to Bkper and enables the included Bkper AI models. It uses the same local credentials as `bkper auth login`.
422
+ - `/logout` revokes and clears Bkper authentication.
423
+ - `/connect [provider]` connects an external model provider through a subscription or API key.
424
+ - `/disconnect [provider]` removes credentials stored by `/connect`. Environment variables and model configuration remain unchanged.
420
425
 
421
426
  ### App Lifecycle
422
427
 
@@ -1,6 +1,6 @@
1
1
  # Data Management
2
2
 
3
- Interact with books, files, accounts, transactions, and balances using the `bkper` CLI.
3
+ Interact with books, files, accounts, transactions, events, and balances using the `bkper` CLI.
4
4
 
5
5
  All commands that operate within a book use `-b, --book <bookId>` to specify the book context.
6
6
 
@@ -296,6 +296,49 @@ bkper transaction merge tx_123 tx_456 -b abc123
296
296
  </details>
297
297
 
298
298
 
299
+ ---
300
+
301
+ ## Events
302
+
303
+ Inspect book events and bot responses — useful for debugging automations and recovering from intermittent bot errors.
304
+
305
+ ```bash
306
+ # List recent events (one page, default limit 50)
307
+ bkper event list -b abc123
308
+
309
+ # List only events with error bot responses, as JSON (includes full botResponses)
310
+ bkper event list -b abc123 --error --json
311
+
312
+ # Filter by resource (transaction, account, or group id)
313
+ bkper event list -b abc123 --resource tx_456 --json
314
+
315
+ # Filter by event type and date range
316
+ bkper event list -b abc123 --type TRANSACTION_POSTED --after 2026-01-01T00:00:00Z
317
+
318
+ # Fetch the next page
319
+ bkper event list -b abc123 --limit 50 --cursor cursor_123
320
+
321
+ # Replay one bot response after inspecting an error
322
+ bkper event replay evt_789 -b abc123 --agent-id tax-bot --json
323
+ ```
324
+
325
+ <details>
326
+ <summary>Command reference</summary>
327
+
328
+ - `event list -b <bookId>` - List one page of events in a book (includes bot responses in JSON)
329
+ - `--after <date>` - Start date inclusive (RFC3339)
330
+ - `--before <date>` - End date exclusive (RFC3339)
331
+ - `--resource <resourceId>` - Filter by resource ID (Transaction, Account, or Group). When set, `--error` and `--type` are ignored by the API
332
+ - `--error` - Only events with at least one error bot response. When set, `--type` is ignored by the API
333
+ - `--type <type>` - Filter by event type (e.g. `TRANSACTION_POSTED`, `ACCOUNT_CREATED`)
334
+ - `--limit <number>` - Fetch one page with up to this many events (default `50`, max `200`)
335
+ - `--cursor <cursor>` - Cursor for fetching the next page
336
+ - `event replay <eventId> -b <bookId> --agent-id <agentId>` - Replay one bot response for an event (returns the updated event with bot responses)
337
+
338
+ JSON output includes the full event payload, including nested `botResponses` (`agentId`, `type`, `message`, `createdAt`), for LLM-assisted debugging.
339
+
340
+ </details>
341
+
299
342
  ---
300
343
 
301
344
  ## Balances
@@ -244,6 +244,7 @@ More information at the [Bkper Developer Documentation](https://bkper.com/docs/#
244
244
  **Properties:**
245
245
 
246
246
  - `agentId?`: `string` — The id of agent that created the resource
247
+ - `avatarUrl?`: `string` — The Collaborator public avatar url
247
248
  - `createdAt?`: `string` — The creation timestamp, in milliseconds
248
249
  - `email?`: `string` — The email of the Collaborator
249
250
  - `id?`: `string` — The unique id that identifies the Collaborator in the Book
@@ -534,6 +535,7 @@ More information at the [Bkper Developer Documentation](https://bkper.com/docs/#
534
535
  - `billingAdminEmail?`: `string` — The billing admin email for this user's billing account
535
536
  - `billingEnabled?`: `boolean` — True if billing is enabled for the user
536
537
  - `daysLeftInTrial?`: `number` — How many days left in trial
538
+ - `domain?`: `bkper.Domain`
537
539
  - `email?`: `string` — The user email
538
540
  - `free?`: `boolean` — True if user is in the free plan
539
541
  - `fullName?`: `string` — The user full name
@@ -631,7 +631,7 @@ It contains all `Accounts` where `Transactions` are recorded/posted;
631
631
  - `getTransaction(id: string)` → `Promise<Transaction | undefined>` — Retrieve a transaction by id.
632
632
  - `getVisibility()` / `setVisibility(visibility: Visibility)` → `Visibility` — Gets the visibility of the book.
633
633
  - `json()` → `bkper.Book` — Gets an immutable copy of the JSON payload for this resource.
634
- - `listEvents(afterDate: string | null, beforeDate: string | null, onError: boolean | null, resourceId: string | null, limit: number, cursor?: string)` → `Promise<EventList>` — Lists events in the Book based on the provided parameters.
634
+ - `listEvents(options: ListEventsOptions)` → `Promise<EventList>` — Lists events in the Book based on the provided options.
635
635
  - `listFiles(limit?: number, cursor?: string)` → `Promise<FileList>` — Lists files in the Book, for pagination.
636
636
  - `listTransactions(query?: string, limit?: number, cursor?: string)` → `Promise<TransactionList>` — Lists transactions in the Book based on the provided query, limit, and cursor, for pagination.
637
637
  - `mergeTransactions(transaction1: string | bkper.Transaction | Transaction, transaction2: string | bkper.Transaction | Transaction)` → `Promise<Transaction>` — Merge two `Transactions` into a single new canonical transaction.
@@ -786,6 +786,7 @@ A Collaborator represents a user that has been granted access to a Book with spe
786
786
  **Methods:**
787
787
 
788
788
  - `create(message?: string)` → `Promise<Collaborator>` — Performs create new Collaborator.
789
+ - `getAvatarUrl()` → `string | undefined` — Gets the public avatar url of the Collaborator.
789
790
  - `getEmail()` / `setEmail(email: string)` → `string | undefined (set: string)` — Gets the Collaborator email address.
790
791
  - `getId()` → `string | undefined` — Gets the Collaborator internal id.
791
792
  - `getPermission()` / `setPermission(permission: Permission)` → `Permission | undefined (set: Permission)` — Gets the permission level of the Collaborator.
@@ -902,6 +903,7 @@ A File can be attached to a `Transaction` or used to import data.
902
903
  - `getBook()` → `Book` — Gets the Book this File belongs to.
903
904
  - `getContent()` / `setContent(content: string)` → `Promise<string | undefined> (set: string)` — Gets the file content Base64 encoded.
904
905
  - `getContentType()` / `setContentType(contentType: string)` → `string | undefined (set: string)` — Gets the File content type.
906
+ - `getCreatedAt()` → `Date | undefined` — Gets the date the File was created.
905
907
  - `getId()` → `string | undefined` — Gets the File id.
906
908
  - `getName()` / `setName(name: string)` → `string | undefined (set: string)` — Gets the File name.
907
909
  - `getSize()` → `number | undefined` — Gets the file size in bytes.
@@ -1311,6 +1313,40 @@ Bkper Platform outbound for server-side app routes.
1311
1313
  This function is called when a request fails and needs to be retried.
1312
1314
  It provides the HTTP status code, error message, and the number of retry attempts made so far.
1313
1315
 
1316
+ ### ListEventsOptions
1317
+
1318
+ Options for listing events in a Book.
1319
+
1320
+ **Properties:**
1321
+
1322
+ - `afterDate?`: `string` — The start date (inclusive) for the events search range, in [RFC3339](https://en.wikipedia.org/wiki/ISO_8601#RFC_3339) format.
1323
+ - `beforeDate?`: `string` — The end date (exclusive) for the events search range, in [RFC3339](https://en.wikipedia.org/wiki/ISO_8601#RFC_3339) format.
1324
+ - `cursor?`: `string` — The cursor for pagination.
1325
+ - `limit`: `number` — The maximum number of events to return.
1326
+ - `onError?`: `boolean` — Whether to filter events by error responses.
1327
+ - `resourceId?`: `string` — The ID of the event's resource (Transaction, Account, or Group).
1328
+ - `type?`: `EventType` — The event type to filter by.
1329
+
1330
+ **limit**
1331
+
1332
+ Defaults to `50`, maximum is `200`.
1333
+
1334
+ **onError**
1335
+
1336
+ `true` returns events with at least one error response.
1337
+ `false` returns events with no error responses.
1338
+ `null` or `undefined` includes events regardless of error responses.
1339
+
1340
+ Ignored when `resourceId` is set. When set, `type` is ignored.
1341
+
1342
+ **resourceId**
1343
+
1344
+ When set, `onError` and `type` are ignored.
1345
+
1346
+ **type**
1347
+
1348
+ Ignored when `resourceId` or `onError` is set.
1349
+
1314
1350
  ## Enums
1315
1351
 
1316
1352
  ### AccountType
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bkper",
3
- "version": "4.18.4",
3
+ "version": "4.19.0",
4
4
  "description": "Command line client for Bkper",
5
5
  "bin": {
6
6
  "bkper": "./lib/cli.js"
@@ -43,7 +43,7 @@
43
43
  "test:integration": "TS_NODE_TRANSPILE_ONLY=true BKPER_API_URL=${BKPER_API_URL:-http://localhost:8081/_ah/api/bkper} TS_NODE_PROJECT=tsconfig.test.json mocha --config .mocharc.integration.json",
44
44
  "test:deploy": "TS_NODE_TRANSPILE_ONLY=true BKPER_PLATFORM_URL=http://localhost:8790 BKPER_API_URL=https://api-dev.bkper.app TS_NODE_PROJECT=tsconfig.test.json mocha --config .mocharc.deploy.json",
45
45
  "test:all": "bun run test:unit && bun run test:integration",
46
- "version": "bun ./scripts/sync-plugin-version.ts",
46
+ "version": "bun ./scripts/sync-plugin-version.ts && git add .claude-plugin/plugin.json .claude-plugin/marketplace.json .codex-plugin/plugin.json",
47
47
  "release:patch": "npm version patch -m \"chore(release): v%s\"",
48
48
  "release:minor": "npm version minor -m \"chore(release): v%s\"",
49
49
  "release:major": "npm version major -m \"chore(release): v%s\"",
@@ -52,8 +52,8 @@
52
52
  "upgrade:api": "bun update @bkper/bkper-api-types --latest && bun update bkper-js --latest"
53
53
  },
54
54
  "dependencies": {
55
- "@earendil-works/pi-coding-agent": "0.80.3",
56
- "bkper-js": "^2.37.0",
55
+ "@earendil-works/pi-coding-agent": "0.80.6",
56
+ "bkper-js": "^2.40.1",
57
57
  "commander": "^13.1.0",
58
58
  "dotenv": "^8.2.0",
59
59
  "esbuild": "^0.27.2",