@agent-native/core 0.157.11 → 0.157.12

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.
@@ -1,7 +1,4 @@
1
1
  import { getDbExec } from "@agent-native/core/db";
2
- import { and, eq, gte, isNull, ne, or } from "drizzle-orm";
3
-
4
- import { getDb, schema } from "../db/index.js";
5
2
 
6
3
  export interface FirstPartyAnalyticsPurgeScope {
7
4
  userEmail: string;
@@ -19,34 +16,6 @@ export interface FirstPartyAnalyticsPurgeWindow {
19
16
  startEventDate: string;
20
17
  }
21
18
 
22
- function scopePredicate(
23
- table: {
24
- orgId: any;
25
- ownerEmail: any;
26
- },
27
- scope: FirstPartyAnalyticsPurgeScope,
28
- includeLegacyOwnerRows: boolean,
29
- ) {
30
- if (!includeLegacyOwnerRows) return eq(table.orgId, scope.orgId);
31
- return or(
32
- eq(table.orgId, scope.orgId),
33
- and(isNull(table.orgId), eq(table.ownerEmail, scope.userEmail)),
34
- );
35
- }
36
-
37
- function windowPredicate(
38
- table: {
39
- eventDate: any;
40
- receivedAt?: any;
41
- },
42
- predicate: any,
43
- window: FirstPartyAnalyticsPurgeWindow,
44
- ) {
45
- return table.receivedAt
46
- ? and(predicate, gte(table.receivedAt, window.startReceivedAt))
47
- : and(predicate, gte(table.eventDate, window.startEventDate));
48
- }
49
-
50
19
  type CountTable =
51
20
  | "analytics_events"
52
21
  | "analytics_event_daily_rollups"
@@ -54,6 +23,40 @@ type CountTable =
54
23
 
55
24
  type CountTimeColumn = "received_at" | "event_date";
56
25
 
26
+ const PURGE_BATCH_SIZE = 10_000;
27
+ const PURGE_BATCH_TIMEOUT_MS = 60_000;
28
+ const PURGE_COUNT_TIMEOUT_MS = 60_000;
29
+
30
+ function purgeWhereSql(
31
+ table: CountTable,
32
+ scope: FirstPartyAnalyticsPurgeScope,
33
+ includeLegacyOwnerRows: boolean,
34
+ window: FirstPartyAnalyticsPurgeWindow,
35
+ ): { sql: string; args: unknown[]; timeColumn: CountTimeColumn } {
36
+ const scopeSql = includeLegacyOwnerRows
37
+ ? "(org_id = ? OR (org_id IS NULL AND owner_email = ?))"
38
+ : "org_id = ?";
39
+ const args: unknown[] = includeLegacyOwnerRows
40
+ ? [scope.orgId, scope.userEmail]
41
+ : [scope.orgId];
42
+ const timeColumn =
43
+ table === "analytics_events" ? "received_at" : "event_date";
44
+ args.push(
45
+ timeColumn === "received_at"
46
+ ? window.startReceivedAt
47
+ : window.startEventDate,
48
+ );
49
+ const eventFilter =
50
+ table === "analytics_events"
51
+ ? " AND event_name IS DISTINCT FROM 'http.response'"
52
+ : "";
53
+ return {
54
+ sql: `${scopeSql}${eventFilter} AND ${timeColumn} >= ?`,
55
+ args,
56
+ timeColumn,
57
+ };
58
+ }
59
+
57
60
  async function countScopedRows(
58
61
  table: CountTable,
59
62
  timeColumn: CountTimeColumn,
@@ -84,7 +87,7 @@ async function countScopedRows(
84
87
  ${eventFilter}
85
88
  AND ${timeColumn} >= ?`,
86
89
  args,
87
- timeoutMs: 5_000,
90
+ timeoutMs: PURGE_COUNT_TIMEOUT_MS,
88
91
  maxAttempts: 1,
89
92
  });
90
93
  const rawCount = (rows[0] as { row_count?: unknown } | undefined)?.row_count;
@@ -136,49 +139,34 @@ export async function purgeFirstPartyAnalyticsPostgresRows(
136
139
  includeLegacyOwnerRows,
137
140
  window,
138
141
  );
139
- await (getDb() as any).transaction(async (tx: any) => {
140
- await tx
141
- .delete(schema.analyticsEvents)
142
- .where(
143
- and(
144
- windowPredicate(
145
- schema.analyticsEvents,
146
- scopePredicate(
147
- schema.analyticsEvents,
148
- scope,
149
- includeLegacyOwnerRows,
150
- ),
151
- window,
152
- ),
153
- ne(schema.analyticsEvents.eventName, "http.response"),
154
- ),
155
- );
156
- await tx
157
- .delete(schema.analyticsEventDailyRollups)
158
- .where(
159
- windowPredicate(
160
- schema.analyticsEventDailyRollups,
161
- scopePredicate(
162
- schema.analyticsEventDailyRollups,
163
- scope,
164
- includeLegacyOwnerRows,
165
- ),
166
- window,
167
- ),
168
- );
169
- await tx
170
- .delete(schema.analyticsUserDays)
171
- .where(
172
- windowPredicate(
173
- schema.analyticsUserDays,
174
- scopePredicate(
175
- schema.analyticsUserDays,
176
- scope,
177
- includeLegacyOwnerRows,
178
- ),
179
- window,
180
- ),
181
- );
182
- });
142
+
143
+ for (const table of [
144
+ "analytics_events",
145
+ "analytics_event_daily_rollups",
146
+ "analytics_user_days",
147
+ ] as const) {
148
+ const {
149
+ sql: whereSql,
150
+ args,
151
+ timeColumn,
152
+ } = purgeWhereSql(table, scope, includeLegacyOwnerRows, window);
153
+ while (true) {
154
+ const result = await getDbExec().execute({
155
+ sql: `WITH candidates AS (
156
+ SELECT id
157
+ FROM ${table}
158
+ WHERE ${whereSql}
159
+ ORDER BY ${timeColumn}, id
160
+ LIMIT ?
161
+ )
162
+ DELETE FROM ${table}
163
+ WHERE id IN (SELECT id FROM candidates)`,
164
+ args: [...args, PURGE_BATCH_SIZE],
165
+ timeoutMs: PURGE_BATCH_TIMEOUT_MS,
166
+ maxAttempts: 1,
167
+ });
168
+ if (Number(result.rowsAffected ?? 0) < PURGE_BATCH_SIZE) break;
169
+ }
170
+ }
183
171
  return counts;
184
172
  }
@@ -1051,7 +1051,7 @@ function importedLineStroke(
1051
1051
  innerHtml: string,
1052
1052
  dims: SlideDims,
1053
1053
  ):
1054
- | Pick<
1054
+ | (Pick<
1055
1055
  ShapeElement,
1056
1056
  | "shapeType"
1057
1057
  | "lineColor"
@@ -1060,7 +1060,8 @@ function importedLineStroke(
1060
1060
  | "lineDashType"
1061
1061
  | "lineHeadType"
1062
1062
  | "lineTailType"
1063
- >
1063
+ > &
1064
+ Partial<Pick<ShapeElement, "w" | "h">>)
1064
1065
  | undefined {
1065
1066
  for (const [property, axis] of Object.entries(SINGLE_EDGE_BORDER_AXES)) {
1066
1067
  const border = parseCssBorder(getStyle(style, property));
@@ -1068,6 +1069,10 @@ function importedLineStroke(
1068
1069
  const color = colorToHex(border.color);
1069
1070
  return {
1070
1071
  shapeType: "line",
1072
+ // A single-edge border is a line in the element's local coordinate
1073
+ // system. Keep its perpendicular dimension collapsed after the box
1074
+ // geometry has been parsed, or a thin rule becomes a diagonal line.
1075
+ ...(axis === "x" ? { h: 0 } : { w: 0 }),
1071
1076
  lineColor: color.hex,
1072
1077
  lineTransparency: color.transparency,
1073
1078
  // The same 0.5pt floor the outline paths use, for the same reason:
@@ -62,11 +62,11 @@ export declare const postAwareness: import("h3").EventHandlerWithFetch<import("h
62
62
  error: string;
63
63
  states?: undefined;
64
64
  } | {
65
+ error?: undefined;
65
66
  states: {
66
67
  clientId: number;
67
68
  state: string;
68
69
  }[];
69
- error?: undefined;
70
70
  }>>;
71
71
  /**
72
72
  * GET /_agent-native/collab/:docId/users
@@ -77,9 +77,9 @@ export declare const getActiveUsers: import("h3").EventHandlerWithFetch<import("
77
77
  error: string;
78
78
  users?: undefined;
79
79
  } | {
80
+ error?: undefined;
80
81
  users: {
81
82
  clientId: number;
82
83
  lastSeen: number;
83
84
  }[];
84
- error?: undefined;
85
85
  }>>;
@@ -13,8 +13,8 @@
13
13
  * Body: { json: any, fieldName?: string, type?: "map"|"array", requestSource?: string }
14
14
  */
15
15
  export declare const postCollabJson: import("h3").EventHandlerWithFetch<import("h3").EventHandlerRequest, Promise<{
16
- ok?: undefined;
17
16
  error: string;
17
+ ok?: undefined;
18
18
  } | {
19
19
  error?: undefined;
20
20
  ok: boolean;
@@ -17,11 +17,11 @@ declare const _default: import("../../action.js").ActionDefinition<{
17
17
  id?: undefined;
18
18
  provider?: undefined;
19
19
  } | {
20
- error?: undefined;
21
20
  configured?: undefined;
22
21
  connectPath?: undefined;
23
22
  url: string;
24
23
  id: string;
25
24
  provider: string;
25
+ error?: undefined;
26
26
  }>;
27
27
  export default _default;
@@ -708,12 +708,15 @@ export function createIntegrationsPlugin(options) {
708
708
  // sees the request. Keep the device secret in a dedicated TLS-only
709
709
  // header as a transport fallback; the value is still hashed and looked
710
710
  // up by authenticateRemoteDeviceToken, never persisted raw.
711
- const token = extractBearerToken(getRequestHeader(event, "authorization")) ??
712
- (getRequestHeader(event, "x-agent-native-device-token")?.trim() ||
713
- null);
714
- const device = await authenticateRemoteDeviceToken(token);
715
- if (device)
716
- return device;
711
+ const candidates = [
712
+ getRequestHeader(event, "x-agent-native-device-token")?.trim() || null,
713
+ extractBearerToken(getRequestHeader(event, "authorization")),
714
+ ].filter((token, index, all) => Boolean(token) && all.indexOf(token) === index);
715
+ for (const token of candidates) {
716
+ const device = await authenticateRemoteDeviceToken(token);
717
+ if (device)
718
+ return device;
719
+ }
717
720
  setResponseStatus(event, 401);
718
721
  return null;
719
722
  }
@@ -137,13 +137,13 @@ export declare function screenMemoryMcpToolDefinitions(): ({
137
137
  inputSchema: {
138
138
  type: string;
139
139
  properties: {
140
+ count?: undefined;
140
141
  query?: undefined;
141
142
  minutes?: undefined;
142
143
  limit?: undefined;
143
144
  clientHint?: undefined;
144
145
  timestamp?: undefined;
145
146
  chapterId?: undefined;
146
- count?: undefined;
147
147
  startAt?: undefined;
148
148
  endAt?: undefined;
149
149
  reason?: undefined;
@@ -159,6 +159,7 @@ export declare function screenMemoryMcpToolDefinitions(): ({
159
159
  inputSchema: {
160
160
  type: string;
161
161
  properties: {
162
+ count?: undefined;
162
163
  query: {
163
164
  type: string;
164
165
  description: string;
@@ -174,7 +175,6 @@ export declare function screenMemoryMcpToolDefinitions(): ({
174
175
  clientHint?: undefined;
175
176
  timestamp?: undefined;
176
177
  chapterId?: undefined;
177
- count?: undefined;
178
178
  startAt?: undefined;
179
179
  endAt?: undefined;
180
180
  reason?: undefined;
@@ -190,6 +190,7 @@ export declare function screenMemoryMcpToolDefinitions(): ({
190
190
  inputSchema: {
191
191
  type: string;
192
192
  properties: {
193
+ count?: undefined;
193
194
  minutes: {
194
195
  type: string;
195
196
  description: string;
@@ -199,7 +200,6 @@ export declare function screenMemoryMcpToolDefinitions(): ({
199
200
  clientHint?: undefined;
200
201
  timestamp?: undefined;
201
202
  chapterId?: undefined;
202
- count?: undefined;
203
203
  startAt?: undefined;
204
204
  endAt?: undefined;
205
205
  reason?: undefined;
@@ -216,6 +216,7 @@ export declare function screenMemoryMcpToolDefinitions(): ({
216
216
  type: string;
217
217
  required: string[];
218
218
  properties: {
219
+ count?: undefined;
219
220
  query: {
220
221
  type: string;
221
222
  description: string;
@@ -234,7 +235,6 @@ export declare function screenMemoryMcpToolDefinitions(): ({
234
235
  };
235
236
  timestamp?: undefined;
236
237
  chapterId?: undefined;
237
- count?: undefined;
238
238
  startAt?: undefined;
239
239
  endAt?: undefined;
240
240
  reason?: undefined;
@@ -250,6 +250,7 @@ export declare function screenMemoryMcpToolDefinitions(): ({
250
250
  type: string;
251
251
  required: string[];
252
252
  properties: {
253
+ count?: undefined;
253
254
  query?: undefined;
254
255
  minutes?: undefined;
255
256
  limit?: undefined;
@@ -263,7 +264,6 @@ export declare function screenMemoryMcpToolDefinitions(): ({
263
264
  description: string;
264
265
  };
265
266
  chapterId?: undefined;
266
- count?: undefined;
267
267
  startAt?: undefined;
268
268
  endAt?: undefined;
269
269
  includeMicrophone?: undefined;
@@ -314,13 +314,13 @@ export declare function screenMemoryMcpToolDefinitions(): ({
314
314
  type: string;
315
315
  required: string[];
316
316
  properties: {
317
+ count?: undefined;
317
318
  query?: undefined;
318
319
  minutes?: undefined;
319
320
  limit?: undefined;
320
321
  clientHint?: undefined;
321
322
  timestamp?: undefined;
322
323
  chapterId?: undefined;
323
- count?: undefined;
324
324
  startAt: {
325
325
  type: string;
326
326
  description: string;
@@ -349,13 +349,13 @@ export declare function screenMemoryMcpToolDefinitions(): ({
349
349
  type: string;
350
350
  required: string[];
351
351
  properties: {
352
+ count?: undefined;
352
353
  query?: undefined;
353
354
  minutes?: undefined;
354
355
  limit?: undefined;
355
356
  clientHint?: undefined;
356
357
  timestamp?: undefined;
357
358
  chapterId?: undefined;
358
- count?: undefined;
359
359
  startAt?: undefined;
360
360
  endAt?: undefined;
361
361
  reason?: undefined;
@@ -16,18 +16,18 @@ export declare function createNotificationsHandler(): import("h3").EventHandlerW
16
16
  error?: undefined;
17
17
  ok?: undefined;
18
18
  } | {
19
+ count?: undefined;
19
20
  updated: number;
20
21
  error?: undefined;
21
22
  ok?: undefined;
22
- count?: undefined;
23
23
  } | {
24
+ count?: undefined;
24
25
  updated?: undefined;
25
26
  error: string;
26
27
  ok?: undefined;
27
- count?: undefined;
28
28
  } | {
29
+ count?: undefined;
29
30
  updated?: undefined;
30
31
  error?: undefined;
31
32
  ok: boolean;
32
- count?: undefined;
33
33
  }>>;
@@ -41,16 +41,16 @@ export declare function createObservabilityHandler(): import("h3").EventHandlerW
41
41
  thumbsUpRate: number;
42
42
  avgEvalScore: number;
43
43
  } | {
44
+ error?: undefined;
44
45
  summary: import("./types.js").TraceSummary;
45
46
  spans: import("./types.js").TraceSpan[];
46
47
  id?: undefined;
47
- error?: undefined;
48
48
  ok?: undefined;
49
49
  } | {
50
+ error?: undefined;
50
51
  summary?: undefined;
51
52
  spans?: undefined;
52
53
  id: string;
53
- error?: undefined;
54
54
  ok?: undefined;
55
55
  } | {
56
56
  summary?: undefined;
@@ -59,9 +59,9 @@ export declare function createObservabilityHandler(): import("h3").EventHandlerW
59
59
  error: any;
60
60
  ok?: undefined;
61
61
  } | {
62
+ error?: undefined;
62
63
  summary?: undefined;
63
64
  spans?: undefined;
64
65
  id?: undefined;
65
- error?: undefined;
66
66
  ok: boolean;
67
67
  }>>;
@@ -37,17 +37,17 @@ export declare function createWriteSecretHandler(): import("h3").EventHandlerWit
37
37
  status?: undefined;
38
38
  ok?: undefined;
39
39
  } | {
40
+ error?: undefined;
40
41
  ok: boolean;
41
42
  status: string;
42
- error?: undefined;
43
43
  } | {
44
44
  error: string;
45
45
  removed?: undefined;
46
46
  ok?: undefined;
47
47
  } | {
48
+ error?: undefined;
48
49
  ok: boolean;
49
50
  removed: boolean;
50
- error?: undefined;
51
51
  }>>;
52
52
  /**
53
53
  * POST /_agent-native/secrets/:key/test — validate an optional candidate value
@@ -58,13 +58,13 @@ export declare function createTestSecretHandler(): import("h3").EventHandlerWith
58
58
  note?: undefined;
59
59
  ok?: undefined;
60
60
  } | {
61
+ error?: undefined;
61
62
  ok: boolean;
62
63
  note?: undefined;
63
- error?: undefined;
64
64
  } | {
65
+ error?: undefined;
65
66
  ok: boolean;
66
67
  note: string;
67
- error?: undefined;
68
68
  } | {
69
69
  note?: undefined;
70
70
  ok: boolean;
@@ -95,11 +95,11 @@ export interface AdHocSecretPayload {
95
95
  export declare function createAdHocSecretHandler(): import("h3").EventHandlerWithFetch<import("h3").EventHandlerRequest, Promise<AdHocSecretPayload[] | {
96
96
  error: string;
97
97
  } | {
98
+ error?: undefined;
98
99
  ok: boolean;
99
100
  key: string;
100
- error?: undefined;
101
101
  } | {
102
+ error?: undefined;
102
103
  ok: boolean;
103
104
  removed: boolean;
104
- error?: undefined;
105
105
  }>>;
@@ -27,10 +27,10 @@ export declare function resolveAgentEngineApiKeyWriteTarget(event: H3Event, scop
27
27
  export declare function createAgentEngineApiKeyHandler(): import("h3").EventHandlerWithFetch<import("h3").EventHandlerRequest, Promise<{
28
28
  error: any;
29
29
  } | {
30
+ error?: undefined;
30
31
  ok: boolean;
31
32
  key: string;
32
33
  baseUrlKey?: string;
33
34
  scope: AgentEngineApiKeyScope;
34
- error?: undefined;
35
35
  }>>;
36
36
  export {};
@@ -20,6 +20,6 @@ export declare function createTranscribeVoiceHandler(): import("h3").EventHandle
20
20
  error: string;
21
21
  text?: undefined;
22
22
  } | {
23
- error?: undefined;
24
23
  text: string;
24
+ error?: undefined;
25
25
  }>>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agent-native/core",
3
- "version": "0.157.11",
3
+ "version": "0.157.12",
4
4
  "description": "Framework for agent-native application development — where AI agents and UI share SQL state, actions, and context",
5
5
  "homepage": "https://github.com/BuilderIO/agent-native#readme",
6
6
  "bugs": {