@lobu/runtime-device 24.8.0 → 24.10.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/component.json +1 -1
- package/dist/dependencies.bun.lock +36 -34
- package/npm-shrinkwrap.json +228 -207
- package/package.json +1 -1
- package/vendor/cli/dist/bundled-skills/lobu/SKILL.md +17 -3
- package/vendor/cli/dist/commands/_lib/apply/apply-cmd.js +31 -4
- package/vendor/cli/dist/commands/_lib/apply/client.d.ts +37 -22
- package/vendor/cli/dist/commands/_lib/apply/client.js +63 -43
- package/vendor/cli/dist/commands/_lib/apply/deployment.d.ts +8 -12
- package/vendor/cli/dist/commands/_lib/apply/deployment.js +14 -1
- package/vendor/cli/dist/commands/_lib/apply/desired-state.d.ts +8 -4
- package/vendor/cli/dist/commands/_lib/apply/desired-state.js +2 -1
- package/vendor/cli/dist/commands/_lib/apply/diff.d.ts +26 -7
- package/vendor/cli/dist/commands/_lib/apply/diff.js +101 -30
- package/vendor/cli/dist/commands/_lib/apply/map-config.js +29 -2
- package/vendor/cli/dist/commands/_lib/apply/render.js +2 -0
- package/vendor/cli/dist/commands/_lib/apply/shared.d.ts +20 -0
- package/vendor/cli/dist/commands/_lib/apply/shared.js +22 -0
- package/vendor/cli/dist/commands/_lib/init-from-org/bootstrap.js +14 -0
- package/vendor/cli/dist/commands/dev.js +2 -0
- package/vendor/cli/dist/commands/memory/_lib/seed-cmd.js +6 -2
- package/vendor/cli/dist/config/define.d.ts +21 -3
- package/vendor/cli/dist/connectors/README.md +6 -2
- package/vendor/cli/dist/connectors/github.ts +16 -3
- package/vendor/cli/dist/connectors/market_quotes.ts +388 -91
- package/vendor/cli/dist/connectors/postgres.ts +60 -38
- package/vendor/cli/dist/connectors/whatsapp-web-adapter.js +41 -10
- package/vendor/cli/dist/connectors/whatsapp-web-helpers.ts +12 -2
- package/vendor/cli/dist/connectors/whatsapp_web.ts +18 -2
- package/vendor/cli/dist/connectors/x-dm-adapter.js +55 -21
- package/vendor/cli/dist/connectors/x.ts +1 -1
- package/vendor/cli/dist/internal/context.d.ts +5 -0
- package/vendor/cli/dist/internal/context.js +23 -9
- package/vendor/cli/dist/runtime-components.json +4 -4
- package/vendor/cli/package.json +1 -1
- package/vendor/connector-sdk/dist/connector-types.d.ts +29 -2
- package/vendor/connector-sdk/dist/index.d.ts +1 -0
- package/vendor/connector-sdk/dist/index.js +1 -0
- package/vendor/connector-sdk/dist/ip-reachability.d.ts +1 -1
- package/vendor/connector-sdk/dist/ip-reachability.js +1 -1
- package/vendor/connector-sdk/dist/logger.d.ts +1 -1
- package/vendor/connector-sdk/dist/logger.js +1 -1
- package/vendor/connector-sdk/dist/reaction-client-types.d.ts +3 -1
- package/vendor/connector-sdk/dist/retry.d.ts +1 -1
- package/vendor/connector-sdk/dist/retry.js +1 -1
- package/vendor/connector-sdk/dist/source-withheld-error.d.ts +16 -0
- package/vendor/connector-sdk/dist/source-withheld-error.js +19 -0
- package/vendor/connector-sdk/package.json +1 -1
- package/vendor/connector-worker/dist/daemon/automation.js +7 -4
- package/vendor/connector-worker/dist/daemon/index.d.ts +1 -0
- package/vendor/connector-worker/dist/daemon/index.js +1 -0
- package/vendor/connector-worker/dist/daemon/terminal-delivery.d.ts +12 -2
- package/vendor/connector-worker/dist/daemon/terminal-delivery.js +19 -12
- package/vendor/connector-worker/dist/executor/interface.d.ts +10 -0
- package/vendor/connector-worker/dist/executor/interface.js +6 -0
- package/vendor/connector-worker/dist/executor/isolate.d.ts +1 -0
- package/vendor/connector-worker/dist/executor/isolate.js +88 -24
- package/vendor/connector-worker/dist/isolate/prelude.js +5 -0
- package/vendor/connector-worker/package.json +1 -1
- package/vendor/core/dist/classify-error.d.ts +4 -5
- package/vendor/core/dist/classify-error.js +10 -10
- package/vendor/core/dist/contracts/tools/collection-presentation.d.ts +17 -1
- package/vendor/core/dist/contracts/tools/collection-presentation.js +27 -3
- package/vendor/core/dist/contracts/tools/manage-automations.d.ts +67 -3
- package/vendor/core/dist/contracts/tools/manage-automations.js +38 -9
- package/vendor/core/dist/contracts/tools/manage-entity-schema.js +1 -1
- package/vendor/core/dist/contracts/tools/manage-entity.d.ts +8 -0
- package/vendor/core/dist/contracts/tools/manage-entity.js +11 -3
- package/vendor/core/dist/contracts/tools/manage-views.d.ts +249 -7
- package/vendor/core/dist/contracts/tools/manage-views.js +83 -21
- package/vendor/core/dist/contracts/tools/navigation.d.ts +248 -0
- package/vendor/core/dist/contracts/tools/navigation.js +284 -0
- package/vendor/core/dist/contracts/tools/save-memory.d.ts +11 -1
- package/vendor/core/dist/contracts/tools/save-memory.js +25 -3
- package/vendor/core/dist/contracts/tools/search-memory.js +1 -1
- package/vendor/core/dist/contracts/tools/view-attach.d.ts +7 -0
- package/vendor/core/dist/contracts/tools/view-attach.js +15 -0
- package/vendor/core/dist/contracts/tools/view-content-hash.d.ts +4 -1
- package/vendor/core/dist/contracts/tools/view-content-hash.js +4 -2
- package/vendor/core/dist/contracts/tools/view-definition.d.ts +2 -0
- package/vendor/core/dist/contracts/tools/view-definition.js +52 -0
- package/vendor/core/dist/contracts/tools/view-host.d.ts +68 -0
- package/vendor/core/dist/contracts/tools/view-host.js +28 -1
- package/vendor/core/dist/contracts/tools/view-scope.d.ts +31 -0
- package/vendor/core/dist/contracts/tools/view-scope.js +45 -0
- package/vendor/core/dist/credentials.d.ts +12 -0
- package/vendor/core/dist/credentials.js +1 -0
- package/vendor/core/dist/errors.d.ts +17 -24
- package/vendor/core/dist/errors.js +19 -26
- package/vendor/core/dist/types.d.ts +0 -6
- package/vendor/core/dist/worker/auth.d.ts +5 -0
- package/vendor/core/dist/worker/auth.js +15 -4
- package/vendor/core/package.json +11 -1
- package/vendor/postgres/cf/src/connection.js +7 -2
- package/vendor/postgres/cjs/src/connection.js +7 -2
- package/vendor/postgres/src/connection.js +7 -2
- package/vendor/views/dist/api.d.ts +30 -5
- package/vendor/views/dist/api.js +22 -8
- package/vendor/views/dist/bridge.d.ts +17 -0
- package/vendor/views/dist/bridge.js +49 -1
- package/vendor/views/dist/components.d.ts +27 -5
- package/vendor/views/dist/components.js +57 -7
- package/vendor/views/dist/embed.d.ts +98 -0
- package/vendor/views/dist/embed.js +418 -0
- package/vendor/views/dist/index.d.ts +3 -1
- package/vendor/views/dist/index.js +1 -0
- package/vendor/views/dist/native.d.ts +33 -1
- package/vendor/views/dist/native.js +3 -0
- package/vendor/views/package.json +1 -1
- /package/vendor/postgres/{.bun-tag-c81dacd34e959a7a → .bun-tag-652f2580b8090d71} +0 -0
|
@@ -72,9 +72,9 @@ interface PgQueryConfig {
|
|
|
72
72
|
}
|
|
73
73
|
|
|
74
74
|
interface PgCheckpoint {
|
|
75
|
-
/**
|
|
75
|
+
/** Native PostgreSQL text for the last cursor, preserving timestamp microseconds. */
|
|
76
76
|
last_cursor?: string;
|
|
77
|
-
/**
|
|
77
|
+
/** Native PostgreSQL text for the last primary-key value. */
|
|
78
78
|
last_pk?: string;
|
|
79
79
|
}
|
|
80
80
|
|
|
@@ -362,11 +362,6 @@ async function setReadOnly(
|
|
|
362
362
|
await tx.unsafe(`SET LOCAL statement_timeout = ${Math.floor(timeoutMs)}`);
|
|
363
363
|
}
|
|
364
364
|
|
|
365
|
-
function toCheckpointValue(v: unknown): string {
|
|
366
|
-
if (v instanceof Date) return v.toISOString();
|
|
367
|
-
return String(v);
|
|
368
|
-
}
|
|
369
|
-
|
|
370
365
|
function toDate(v: unknown): Date | null {
|
|
371
366
|
if (v instanceof Date) return v;
|
|
372
367
|
if (typeof v === 'number') return new Date(v);
|
|
@@ -386,8 +381,8 @@ export default class PostgresConnector extends ConnectorRuntime {
|
|
|
386
381
|
name: 'PostgreSQL',
|
|
387
382
|
description:
|
|
388
383
|
'Bring your own PostgreSQL database as memory, read a configured feed directly, or run governed connection-level SQL.',
|
|
389
|
-
version: '1.1.
|
|
390
|
-
queryCapabilities: { exactMatch: true, verbatimExactMatch: true, selection: true },
|
|
384
|
+
version: '1.1.1',
|
|
385
|
+
queryCapabilities: { exactMatch: true, verbatimExactMatch: true, exactMatchAny: true, selection: true },
|
|
391
386
|
faviconDomain: 'postgresql.org',
|
|
392
387
|
authSchema: {
|
|
393
388
|
methods: [
|
|
@@ -449,7 +444,7 @@ export default class PostgresConnector extends ConnectorRuntime {
|
|
|
449
444
|
// Everything runs inside ONE read-only transaction — the probe included —
|
|
450
445
|
// so even a crafted query (e.g. a data-modifying CTE that slipped past
|
|
451
446
|
// validation) cannot write while we introspect or read.
|
|
452
|
-
const rows =
|
|
447
|
+
const rows = await sql.begin(async (tx) => {
|
|
453
448
|
await setReadOnly(tx, timeoutMs);
|
|
454
449
|
|
|
455
450
|
// 1. Probe column types so the string-serialized checkpoint can be re-cast.
|
|
@@ -470,10 +465,28 @@ export default class PostgresConnector extends ConnectorRuntime {
|
|
|
470
465
|
};
|
|
471
466
|
const curCast = castFor(cursorCol);
|
|
472
467
|
const pkCast = castFor(pkCol);
|
|
473
|
-
|
|
474
|
-
//
|
|
468
|
+
// Bind as text before the native cast: binding directly as a timestamp
|
|
469
|
+
// makes postgres.js serialize the string through Date, losing precision again.
|
|
470
|
+
const curBound = curCast ? `$1::text${curCast}` : '$1';
|
|
471
|
+
const pkBound = pkCast ? `$2::text${pkCast}` : '$2';
|
|
472
|
+
|
|
473
|
+
// Keep checkpoints separate from driver-decoded payloads: Date loses
|
|
474
|
+
// microseconds, which can make a capped page repeat forever. Native
|
|
475
|
+
// text round-trips through the same type casts used by the predicate.
|
|
476
|
+
// Choose unused aliases so source columns with these names survive.
|
|
477
|
+
const checkpointAlias = (base: string): string => {
|
|
478
|
+
let name = base;
|
|
479
|
+
let suffix = 0;
|
|
480
|
+
while (colByName.has(name)) name = `${base}_${++suffix}`;
|
|
481
|
+
return name;
|
|
482
|
+
};
|
|
483
|
+
const cursorAlias = checkpointAlias('__lobu_checkpoint_cursor');
|
|
484
|
+
const pkAlias = checkpointAlias('__lobu_checkpoint_pk');
|
|
475
485
|
const colCur = `q."${cursorCol}"`;
|
|
476
486
|
const colPk = `q."${pkCol}"`;
|
|
487
|
+
const projection = `q.*, ${colCur}::text AS "${cursorAlias}", ${colPk}::text AS "${pkAlias}"`;
|
|
488
|
+
|
|
489
|
+
// 2. Build the keyset-paginated query.
|
|
477
490
|
const haveCursor =
|
|
478
491
|
checkpoint.last_cursor !== undefined && checkpoint.last_pk !== undefined;
|
|
479
492
|
|
|
@@ -483,18 +496,25 @@ export default class PostgresConnector extends ConnectorRuntime {
|
|
|
483
496
|
// security-allowed: colCur/colPk are assertIdentifier-validated + quoted;
|
|
484
497
|
// the cursor/pk values are bound parameters ($1/$2/$3), not interpolated.
|
|
485
498
|
wrapped =
|
|
486
|
-
`SELECT
|
|
487
|
-
`WHERE (${colCur} > $
|
|
488
|
-
`OR (${colCur} = $
|
|
499
|
+
`SELECT ${projection} FROM (\n${baseSql}\n) q\n` +
|
|
500
|
+
`WHERE (${colCur} > ${curBound} ` +
|
|
501
|
+
`OR (${colCur} = ${curBound} AND ${colPk} > ${pkBound}))\n` +
|
|
489
502
|
`ORDER BY ${colCur}, ${colPk} LIMIT $3`;
|
|
490
503
|
params = [checkpoint.last_cursor, checkpoint.last_pk, limit];
|
|
491
504
|
} else {
|
|
492
|
-
wrapped = `SELECT
|
|
505
|
+
wrapped = `SELECT ${projection} FROM (\n${baseSql}\n) q\nORDER BY ${colCur}, ${colPk} LIMIT $1`;
|
|
493
506
|
params = [limit];
|
|
494
507
|
}
|
|
495
508
|
|
|
496
|
-
|
|
497
|
-
|
|
509
|
+
const page = await tx.unsafe(wrapped, params as never[]);
|
|
510
|
+
return page.map((source) => {
|
|
511
|
+
const { [cursorAlias]: cursor, [pkAlias]: pk, ...row } = source;
|
|
512
|
+
return {
|
|
513
|
+
row,
|
|
514
|
+
checkpoint: { last_cursor: String(cursor), last_pk: String(pk) } satisfies PgCheckpoint,
|
|
515
|
+
};
|
|
516
|
+
});
|
|
517
|
+
});
|
|
498
518
|
|
|
499
519
|
// Namespace origin_ids by the feed INSTANCE, not the feed key: every
|
|
500
520
|
// postgres feed shares feedKey 'query', so two feeds on one connection with
|
|
@@ -508,14 +528,9 @@ export default class PostgresConnector extends ConnectorRuntime {
|
|
|
508
528
|
// so a run cut short keeps every slice it committed.
|
|
509
529
|
for (let start = 0; start < rows.length; start += COMMIT_ROWS) {
|
|
510
530
|
const slice = rows.slice(start, start + COMMIT_ROWS);
|
|
511
|
-
const last = slice[slice.length - 1];
|
|
512
|
-
const sliceCheckpoint: PgCheckpoint = {
|
|
513
|
-
last_cursor: toCheckpointValue(last[cursorCol]),
|
|
514
|
-
last_pk: toCheckpointValue(last[pkCol]),
|
|
515
|
-
};
|
|
516
531
|
await ctx.commit(
|
|
517
|
-
slice.map((row) => this.rowToEvent(originPrefix, row, config, cursorCol, pkCol)),
|
|
518
|
-
|
|
532
|
+
slice.map(({ row }) => this.rowToEvent(originPrefix, row, config, cursorCol, pkCol)),
|
|
533
|
+
slice[slice.length - 1].checkpoint
|
|
519
534
|
);
|
|
520
535
|
}
|
|
521
536
|
|
|
@@ -563,8 +578,10 @@ export default class PostgresConnector extends ConnectorRuntime {
|
|
|
563
578
|
const bind = (value: string) => { params.push(value); return `$${params.length}::text`; };
|
|
564
579
|
let where = '';
|
|
565
580
|
if (ctx.exactMatch) {
|
|
566
|
-
const { columns,
|
|
581
|
+
const { columns, verbatim } = ctx.exactMatch;
|
|
582
|
+
const values = ctx.exactMatch.values ?? [ctx.exactMatch.value];
|
|
567
583
|
if (!columns.length) throw new Error('exactMatch.columns must not be empty');
|
|
584
|
+
if (!values.length) throw new Error('exactMatch.values must not be empty');
|
|
568
585
|
for (const column of columns) assertIdentifier(column, 'exactMatch.column');
|
|
569
586
|
const projection = await tx.unsafe(`SELECT * FROM (\n${baseSql}\n) q LIMIT 0`);
|
|
570
587
|
const projected = projection.columns as Array<{ name: string; type: number; parser?: { array?: boolean } }>;
|
|
@@ -574,11 +591,15 @@ export default class PostgresConnector extends ConnectorRuntime {
|
|
|
574
591
|
if (!candidates.some(isScalar)) {
|
|
575
592
|
throw Object.assign(new Error('Exact-match identity must be a scalar; project a text key in the source query'), { status: 400 });
|
|
576
593
|
}
|
|
594
|
+
// One bound array literal per comparison: a page of keys stays one statement.
|
|
595
|
+
const bindArray = (items: string[]) =>
|
|
596
|
+
bind(`{${items.map((item) => `"${item.replaceAll('\\', '\\\\').replaceAll('"', '\\"')}"`).join(',')}}`);
|
|
577
597
|
const textMatch = (ref: string) => verbatim
|
|
578
|
-
? `${ref} = ${
|
|
579
|
-
: `btrim(${ref}, ${bind('\t\n\v\f\r \u00a0\u1680\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u2028\u2029\u202f\u205f\u3000\ufeff')}) = ${
|
|
580
|
-
const
|
|
581
|
-
|
|
598
|
+
? `${ref} = ANY(${bindArray(values)}::text[])`
|
|
599
|
+
: `btrim(${ref}, ${bind('\t\n\v\f\r \u00a0\u1680\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u2028\u2029\u202f\u205f\u3000\ufeff')}) = ANY(${bindArray(values)}::text[])`;
|
|
600
|
+
const numbers = values.filter((value) => Number.isFinite(Number(value)) && String(Number(value)) === value);
|
|
601
|
+
const numberMatch = (ref: string, cast: string) => numbers.length
|
|
602
|
+
? `${ref} = ANY(${bindArray(numbers)}::${cast}[])` : 'FALSE';
|
|
582
603
|
const cases = candidates.map((column) => {
|
|
583
604
|
const ref = `q.${quoteIdent(column.name)}`;
|
|
584
605
|
const jsonType = [114, 3802].includes(column.type) ? `${column.type === 114 ? 'json' : 'jsonb'}_typeof(${ref})` : undefined;
|
|
@@ -602,20 +623,21 @@ export default class PostgresConnector extends ConnectorRuntime {
|
|
|
602
623
|
} else if ([1082, 1114, 1184].includes(column.type)) {
|
|
603
624
|
// The driver returns Date values; the isolate serializes them as ISO.
|
|
604
625
|
present = `isfinite(${ref})`;
|
|
605
|
-
const
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
626
|
+
const dateMatches = values.flatMap((value) => {
|
|
627
|
+
const date = new Date(value);
|
|
628
|
+
if (!Number.isFinite(date.getTime()) || date.toISOString() !== value) return [];
|
|
629
|
+
if (column.type === 1082) {
|
|
630
|
+
return value.endsWith('T00:00:00.000Z') ? [`${ref} = ${bind(value.slice(0, 10))}::date`] : [];
|
|
631
|
+
}
|
|
611
632
|
// Timestamp without zone is parsed in the worker's local zone.
|
|
612
633
|
const key = column.type === 1114
|
|
613
634
|
? new Date(date.getTime() - date.getTimezoneOffset() * 60_000).toISOString().slice(0, -1)
|
|
614
635
|
: value;
|
|
615
636
|
const bound = `${bind(key)}::${PG_OID[column.type].cast}`;
|
|
616
637
|
// Date drops source microseconds, so retain its full millisecond.
|
|
617
|
-
|
|
618
|
-
}
|
|
638
|
+
return [`(${ref} >= ${bound} AND ${ref} < ${bound} + INTERVAL '1 millisecond')`];
|
|
639
|
+
});
|
|
640
|
+
match = dateMatches.length ? dateMatches.join(' OR ') : 'FALSE';
|
|
619
641
|
} else {
|
|
620
642
|
match = textMatch(`${ref}::text`);
|
|
621
643
|
}
|
|
@@ -33,7 +33,7 @@ export function whatsAppWebAdapterProgram() {
|
|
|
33
33
|
// when this number moves: shipping a fix under the old number leaves every
|
|
34
34
|
// already-open tab running the previous code with nothing to show for it.
|
|
35
35
|
// Keep in lockstep with WHATSAPP_ADAPTER_VERSION in whatsapp-web-helpers.ts.
|
|
36
|
-
const ADAPTER_VERSION =
|
|
36
|
+
const ADAPTER_VERSION = 28;
|
|
37
37
|
const SOURCE_ERROR_ID = "whatsapp-web:source-observation-error";
|
|
38
38
|
// Storage rows one `chat:` read examines; a whole personal history is
|
|
39
39
|
// usually under this, so one read answers.
|
|
@@ -340,6 +340,23 @@ export function whatsAppWebAdapterProgram() {
|
|
|
340
340
|
return false;
|
|
341
341
|
}
|
|
342
342
|
|
|
343
|
+
/** Actual self-mentions, excluding quotes of our messages and other people. */
|
|
344
|
+
async function ownMentionJids(row) {
|
|
345
|
+
const mentions = Array.isArray(row.mentionedJidList) ? row.mentionedJidList : [];
|
|
346
|
+
if (mentions.length === 0) return [];
|
|
347
|
+
const own = await ownJids();
|
|
348
|
+
const mentioned = new Set();
|
|
349
|
+
for (const value of mentions) {
|
|
350
|
+
const candidate = await canonicalJid(value);
|
|
351
|
+
for (const jid of [candidate.jid, candidate.lid]) {
|
|
352
|
+
if (typeof jid === "string" && /^[0-9]{5,32}@(s\.whatsapp\.net|lid)$/.test(jid) && own.has(jid)) {
|
|
353
|
+
mentioned.add(jid);
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
return [...mentioned].slice(0, 2);
|
|
358
|
+
}
|
|
359
|
+
|
|
343
360
|
/**
|
|
344
361
|
* Module names for each write op, most-current first.
|
|
345
362
|
*
|
|
@@ -386,7 +403,7 @@ export function whatsAppWebAdapterProgram() {
|
|
|
386
403
|
const key = row.id ?? model?.id;
|
|
387
404
|
const id = rawId(key);
|
|
388
405
|
const remote = widString(key?.remote ?? row.chatId ?? (key?.fromMe ? row.to : row.from));
|
|
389
|
-
if (!id || !remote || remote
|
|
406
|
+
if (!id || !remote || isBroadcastOnlyJid(remote) || SYSTEM_TYPES.has(row.type)) return null;
|
|
390
407
|
return { id, timestamp: unixSeconds(row), is_group: remote.endsWith("@g.us") };
|
|
391
408
|
}
|
|
392
409
|
|
|
@@ -496,6 +513,21 @@ export function whatsAppWebAdapterProgram() {
|
|
|
496
513
|
return [];
|
|
497
514
|
}
|
|
498
515
|
|
|
516
|
+
/**
|
|
517
|
+
* Chats that are feeds, not conversations: status updates, channels, and the
|
|
518
|
+
* read-only service-announcement chat (`0@c.us`, canonically
|
|
519
|
+
* `0@s.whatsapp.net`). Nobody can reply in them, so they never surface as
|
|
520
|
+
* messages and a send to one is refused instead of hanging.
|
|
521
|
+
*/
|
|
522
|
+
function isBroadcastOnlyJid(jid) {
|
|
523
|
+
return (
|
|
524
|
+
jid === "status@broadcast" ||
|
|
525
|
+
jid.endsWith("@newsletter") ||
|
|
526
|
+
jid === "0@c.us" ||
|
|
527
|
+
jid === "0@s.whatsapp.net"
|
|
528
|
+
);
|
|
529
|
+
}
|
|
530
|
+
|
|
499
531
|
function widString(value) {
|
|
500
532
|
if (typeof value === "string") return value;
|
|
501
533
|
if (!value) return null;
|
|
@@ -670,11 +702,7 @@ export function whatsAppWebAdapterProgram() {
|
|
|
670
702
|
const authorRaw = row.author ?? key?.participant;
|
|
671
703
|
const chatRaw = remoteRaw ?? (fromMe ? toRaw : fromRaw);
|
|
672
704
|
const chat = await canonicalJid(chatRaw);
|
|
673
|
-
if (
|
|
674
|
-
!chat.jid ||
|
|
675
|
-
chat.jid === "status@broadcast" ||
|
|
676
|
-
chat.jid.endsWith("@newsletter")
|
|
677
|
-
) {
|
|
705
|
+
if (!chat.jid || isBroadcastOnlyJid(chat.jid)) {
|
|
678
706
|
return null;
|
|
679
707
|
}
|
|
680
708
|
const senderRaw = fromMe ? fromRaw : (authorRaw ?? fromRaw);
|
|
@@ -723,6 +751,7 @@ export function whatsAppWebAdapterProgram() {
|
|
|
723
751
|
media_filename: row.filename ?? row.fileName ?? row.title ?? null,
|
|
724
752
|
quoted_id: quotedId,
|
|
725
753
|
mentions_me: await mentionsOwnAccount(row),
|
|
754
|
+
own_mention_jids: await ownMentionJids(row),
|
|
726
755
|
is_forwarded: Boolean(row.isForwarded || Number(row.forwardingScore) > 0),
|
|
727
756
|
is_starred: Boolean(row.star ?? row.isStarred),
|
|
728
757
|
is_system_event: SYSTEM_TYPES.has(type),
|
|
@@ -1091,7 +1120,7 @@ export function whatsAppWebAdapterProgram() {
|
|
|
1091
1120
|
const key = keyModule.fromString(row.id);
|
|
1092
1121
|
if (exactId !== null && key.id !== exactId) continue;
|
|
1093
1122
|
const remote = widString(key.remote);
|
|
1094
|
-
if (remote
|
|
1123
|
+
if (isBroadcastOnlyJid(remote)) continue;
|
|
1095
1124
|
const isGroup = remote.endsWith("@g.us");
|
|
1096
1125
|
if ((chatFilter === "group" && !isGroup) || (chatFilter === "individual" && isGroup)) continue;
|
|
1097
1126
|
selected.push(row);
|
|
@@ -1161,8 +1190,7 @@ export function whatsAppWebAdapterProgram() {
|
|
|
1161
1190
|
const jid = (
|
|
1162
1191
|
await canonicalJid(modelData(candidate).id ?? candidate?.id)
|
|
1163
1192
|
).jid;
|
|
1164
|
-
if (!jid || jid
|
|
1165
|
-
continue;
|
|
1193
|
+
if (!jid || isBroadcastOnlyJid(jid)) continue;
|
|
1166
1194
|
const isGroup = jid.endsWith("@g.us");
|
|
1167
1195
|
if (chatFilter === "group" ? isGroup : !isGroup) {
|
|
1168
1196
|
scopedChats.push(candidate);
|
|
@@ -1294,6 +1322,9 @@ export function whatsAppWebAdapterProgram() {
|
|
|
1294
1322
|
async function sendMessage(input, account) {
|
|
1295
1323
|
const collections = requireFirst(["WAWebCollections"]);
|
|
1296
1324
|
const chat = await resolveChat(collections, input);
|
|
1325
|
+
const chatJid = (await canonicalJid(modelData(chat).id ?? chat?.id)).jid;
|
|
1326
|
+
if (chatJid && isBroadcastOnlyJid(chatJid))
|
|
1327
|
+
throw new Error(`WhatsApp chat ${chatJid} does not accept messages`);
|
|
1297
1328
|
const text = String(input?.text ?? "");
|
|
1298
1329
|
if (!text.trim()) throw new Error("text is required");
|
|
1299
1330
|
const module = requireFirst(SEND_MODULES);
|
|
@@ -14,7 +14,7 @@ import {
|
|
|
14
14
|
WHATSAPP_PHONE_SERVER,
|
|
15
15
|
} from "./whatsapp-web-identity.js";
|
|
16
16
|
|
|
17
|
-
export const WHATSAPP_ADAPTER_VERSION =
|
|
17
|
+
export const WHATSAPP_ADAPTER_VERSION = 28;
|
|
18
18
|
export const WHATSAPP_ORIGIN = "https://web.whatsapp.com";
|
|
19
19
|
|
|
20
20
|
export type ChatFilter = "all" | "individual" | "group";
|
|
@@ -39,6 +39,8 @@ export interface WhatsAppMessage {
|
|
|
39
39
|
quoted_id?: string | null;
|
|
40
40
|
/** The message @mentions the account or quotes one of its messages. */
|
|
41
41
|
mentions_me?: boolean;
|
|
42
|
+
/** Verified phone/LID identities of the paired account actually @mentioned. */
|
|
43
|
+
own_mention_jids?: string[];
|
|
42
44
|
edited?: boolean;
|
|
43
45
|
edit_timestamp?: number | null;
|
|
44
46
|
revoked?: boolean;
|
|
@@ -114,10 +116,13 @@ export function normalizeRelayedMessage(
|
|
|
114
116
|
const timestamp = timestampOf(raw);
|
|
115
117
|
if (timestamp <= 0) return null;
|
|
116
118
|
const chatJid = canonicalizeJid(raw.chat_jid);
|
|
119
|
+
// Status updates, channels and the read-only service-announcement chat
|
|
120
|
+
// (`0@c.us`) are feeds nobody can reply in; the page adapter drops them too.
|
|
117
121
|
if (
|
|
118
122
|
!chatJid ||
|
|
119
123
|
chatJid === "status@broadcast" ||
|
|
120
|
-
chatJid.endsWith("@newsletter")
|
|
124
|
+
chatJid.endsWith("@newsletter") ||
|
|
125
|
+
chatJid === `0@${WHATSAPP_PHONE_SERVER}`
|
|
121
126
|
) {
|
|
122
127
|
return null;
|
|
123
128
|
}
|
|
@@ -136,6 +141,11 @@ export function normalizeRelayedMessage(
|
|
|
136
141
|
from_me: fromMe,
|
|
137
142
|
timestamp,
|
|
138
143
|
occurred_at: new Date(timestamp * 1000).toISOString(),
|
|
144
|
+
own_mention_jids: Array.isArray(raw.own_mention_jids)
|
|
145
|
+
? [...new Set(raw.own_mention_jids.map((jid: unknown) =>
|
|
146
|
+
typeof jid === "string" ? normalizeWhatsAppUserJid(jid) : null,
|
|
147
|
+
).filter((jid: string | null): jid is string => jid !== null))].slice(0, 2)
|
|
148
|
+
: [],
|
|
139
149
|
};
|
|
140
150
|
}
|
|
141
151
|
|
|
@@ -338,6 +338,7 @@ function normalizedSearchResults(
|
|
|
338
338
|
is_group: message.is_group,
|
|
339
339
|
quoted_id: message.quoted_id ?? null,
|
|
340
340
|
mentions_me: message.mentions_me === true,
|
|
341
|
+
own_mention_jids: message.own_mention_jids ?? [],
|
|
341
342
|
});
|
|
342
343
|
}
|
|
343
344
|
return rows;
|
|
@@ -363,7 +364,7 @@ export default class WhatsAppWebConnector extends ConnectorRuntime<
|
|
|
363
364
|
name: "WhatsApp",
|
|
364
365
|
description:
|
|
365
366
|
"Personal WhatsApp messages read live from WhatsApp Web in the paired Owletto Chrome without importing message history. Automations react to new-message references and read content on demand. Search, draft, send, edit, react to, and revoke messages.",
|
|
366
|
-
version: "2.3.
|
|
367
|
+
version: "2.3.1",
|
|
367
368
|
faviconDomain: "whatsapp.com",
|
|
368
369
|
authSchema: { methods: [{ type: "browser", mode: "live" }] },
|
|
369
370
|
browser: {
|
|
@@ -462,7 +463,21 @@ export default class WhatsAppWebConnector extends ConnectorRuntime<
|
|
|
462
463
|
type: "string",
|
|
463
464
|
enum: ["whatsapp_fts", "loaded_model_fallback"],
|
|
464
465
|
},
|
|
465
|
-
results: {
|
|
466
|
+
results: {
|
|
467
|
+
type: "array",
|
|
468
|
+
items: {
|
|
469
|
+
type: "object",
|
|
470
|
+
properties: {
|
|
471
|
+
own_mention_jids: {
|
|
472
|
+
type: "array",
|
|
473
|
+
maxItems: 2,
|
|
474
|
+
uniqueItems: true,
|
|
475
|
+
items: { type: "string", pattern: "^[0-9]{5,32}@(s\\.whatsapp\\.net|lid)$" },
|
|
476
|
+
description: "Verified phone/LID JIDs of the paired account actually @mentioned; empty for quotes alone. Original text is preserved.",
|
|
477
|
+
},
|
|
478
|
+
},
|
|
479
|
+
},
|
|
480
|
+
},
|
|
466
481
|
hasMore: { type: "boolean" },
|
|
467
482
|
},
|
|
468
483
|
},
|
|
@@ -710,6 +725,7 @@ export default class WhatsAppWebConnector extends ConnectorRuntime<
|
|
|
710
725
|
{ name: "is_group", type: "boolean" },
|
|
711
726
|
{ name: "quoted_id", type: "string" },
|
|
712
727
|
{ name: "mentions_me", type: "boolean" },
|
|
728
|
+
{ name: "own_mention_jids", type: "array" },
|
|
713
729
|
],
|
|
714
730
|
nextCursor: response.nextCursor,
|
|
715
731
|
hasMore: response.hasMore,
|
|
@@ -621,6 +621,20 @@ export function xDirectMessagesProgram() {
|
|
|
621
621
|
fail("Unable to attach source subscription");
|
|
622
622
|
return { listening: true };
|
|
623
623
|
}
|
|
624
|
+
// X serves at most 50 entries per notifications page (`count=50`); the
|
|
625
|
+
// cap leaves room for a page grown by a replacement instruction.
|
|
626
|
+
const PAGE_ROWS_MAX = 200;
|
|
627
|
+
// A short row-identity hash for the in-page cursor: a page's returned set
|
|
628
|
+
// stays well under the 10,000-character cursor bound.
|
|
629
|
+
async function rowKey(id) {
|
|
630
|
+
const hash = await crypto.subtle.digest(
|
|
631
|
+
"SHA-256",
|
|
632
|
+
new TextEncoder().encode(id),
|
|
633
|
+
);
|
|
634
|
+
return Array.from(new Uint8Array(hash).slice(0, 6), (x) =>
|
|
635
|
+
x.toString(16).padStart(2, "0"),
|
|
636
|
+
).join("");
|
|
637
|
+
}
|
|
624
638
|
// The notification API is read from this same neutral page. In particular,
|
|
625
639
|
// never render /notifications or call its seen/read-state endpoints here.
|
|
626
640
|
async function readNotifications(input) {
|
|
@@ -635,13 +649,32 @@ export function xDirectMessagesProgram() {
|
|
|
635
649
|
fail("Invalid notification cursor");
|
|
636
650
|
cursor = JSON.parse(input.cursor);
|
|
637
651
|
if (
|
|
638
|
-
cursor.v
|
|
652
|
+
![1, 2].includes(cursor.v) ||
|
|
639
653
|
cursor.kind !== "notifications" ||
|
|
640
654
|
cursor.account !== self ||
|
|
641
|
-
!(cursor.source === null || typeof cursor.source === "string")
|
|
642
|
-
!(cursor.after === null || typeof cursor.after === "string")
|
|
655
|
+
!(cursor.source === null || typeof cursor.source === "string")
|
|
643
656
|
)
|
|
644
657
|
fail("Notification cursor belongs to another account or source");
|
|
658
|
+
// v1 boundary cursors persist in sync checkpoints and equal a v2
|
|
659
|
+
// cursor with nothing returned yet. A v1 cursor inside a source page
|
|
660
|
+
// anchored on one row, which X can re-key; that read must restart.
|
|
661
|
+
if (cursor.v === 1) {
|
|
662
|
+
if (cursor.after !== null) {
|
|
663
|
+
account(self);
|
|
664
|
+
if (input.restartExpired)
|
|
665
|
+
return { rows: [], account_id: self, expired: true };
|
|
666
|
+
fail(
|
|
667
|
+
"Notification cursor format changed; restart the read (coverage incomplete)",
|
|
668
|
+
);
|
|
669
|
+
}
|
|
670
|
+
cursor = { ...cursor, returned: [] };
|
|
671
|
+
}
|
|
672
|
+
if (
|
|
673
|
+
!Array.isArray(cursor.returned) ||
|
|
674
|
+
cursor.returned.length > PAGE_ROWS_MAX ||
|
|
675
|
+
!cursor.returned.every((x) => typeof x === "string" && x.length === 12)
|
|
676
|
+
)
|
|
677
|
+
fail("Invalid notification cursor");
|
|
645
678
|
}
|
|
646
679
|
const path =
|
|
647
680
|
"/i/api/2/notifications/all.json?count=50" +
|
|
@@ -760,39 +793,40 @@ export function xDirectMessagesProgram() {
|
|
|
760
793
|
if (input.metadataOnly) delete row.text;
|
|
761
794
|
all.push(row);
|
|
762
795
|
}
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
}
|
|
775
|
-
const rows = all.slice(start, start + limit);
|
|
776
|
-
const moreInPage = start + rows.length < all.length;
|
|
796
|
+
// Resume by excluding rows already returned from this source page, not
|
|
797
|
+
// by anchoring on one row: X regroups its newest page between reads
|
|
798
|
+
// (re-keying, dropping, or reordering grouped reactions). A re-keyed
|
|
799
|
+
// row may come back as a duplicate reference, deduped by origin_id;
|
|
800
|
+
// no row is ever skipped.
|
|
801
|
+
const returned = new Set(cursor?.returned ?? []);
|
|
802
|
+
const keys = [];
|
|
803
|
+
for (const row of all) keys.push(await rowKey(row.id));
|
|
804
|
+
const remaining = all.filter((_, index) => !returned.has(keys[index]));
|
|
805
|
+
const rows = remaining.slice(0, limit);
|
|
806
|
+
const moreInPage = rows.length < remaining.length;
|
|
777
807
|
if (!moreInPage && cursor && next === cursor.source) {
|
|
778
808
|
if (all.length) fail("Notification cursor did not advance");
|
|
779
809
|
next = undefined;
|
|
780
810
|
}
|
|
811
|
+
// Keep only keys still on the page, so the set stays page-bounded.
|
|
812
|
+
const sent = new Set(rows.map((row) => row.id));
|
|
781
813
|
const nextCursor = moreInPage
|
|
782
814
|
? JSON.stringify({
|
|
783
|
-
v:
|
|
815
|
+
v: 2,
|
|
784
816
|
kind: "notifications",
|
|
785
817
|
account: self,
|
|
786
818
|
source: cursor?.source ?? null,
|
|
787
|
-
|
|
819
|
+
returned: keys.filter(
|
|
820
|
+
(key, index) => returned.has(key) || sent.has(all[index].id),
|
|
821
|
+
),
|
|
788
822
|
})
|
|
789
823
|
: next
|
|
790
824
|
? JSON.stringify({
|
|
791
|
-
v:
|
|
825
|
+
v: 2,
|
|
792
826
|
kind: "notifications",
|
|
793
827
|
account: self,
|
|
794
828
|
source: next,
|
|
795
|
-
|
|
829
|
+
returned: [],
|
|
796
830
|
})
|
|
797
831
|
: undefined;
|
|
798
832
|
if (account() !== self)
|
|
@@ -3876,7 +3876,7 @@ export default class XConnector extends ConnectorRuntime {
|
|
|
3876
3876
|
name: "X (Twitter)",
|
|
3877
3877
|
description:
|
|
3878
3878
|
"Fetches tweets, browser-visible like history, bookmarks, and DMs through the X API v2 or the paired Owletto Chrome extension, reads the chronological Following timeline live through the X API, captures notification references and the accounts you follow, reads and answers DMs live in the paired browser, and likes posts or follows accounts there. Links social actors into the person and company graph.",
|
|
3879
|
-
version: "3.17.
|
|
3879
|
+
version: "3.17.2",
|
|
3880
3880
|
faviconDomain: "x.com",
|
|
3881
3881
|
browser: {
|
|
3882
3882
|
origins: ["https://x.com", "https://twitter.com"],
|
|
@@ -35,6 +35,11 @@ export interface ResolvedContext {
|
|
|
35
35
|
url: string;
|
|
36
36
|
source: "default" | "config" | "env";
|
|
37
37
|
}
|
|
38
|
+
/**
|
|
39
|
+
* Only a missing file means "no contexts yet". An unreadable or corrupt file is
|
|
40
|
+
* an error: reading it as empty would report every context as unknown, and the
|
|
41
|
+
* next save would write that empty config over the user's contexts.
|
|
42
|
+
*/
|
|
38
43
|
export declare function loadContextConfig(): Promise<LobuContextConfig>;
|
|
39
44
|
export declare function getCurrentContextName(): Promise<string>;
|
|
40
45
|
export declare function getActiveOrg(contextName?: string): Promise<string | undefined>;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { readFile } from "node:fs/promises";
|
|
2
2
|
import { homedir } from "node:os";
|
|
3
3
|
import { join } from "node:path";
|
|
4
|
+
import { atomicWriteFile } from "@lobu/core";
|
|
4
5
|
export const LOBU_CONFIG_DIR = join(homedir(), ".config", "lobu");
|
|
5
6
|
export const DEFAULT_CONTEXT_NAME = "lobu";
|
|
6
7
|
const DEFAULT_CONTEXT_URL = "https://app.lobu.ai/api/v1";
|
|
@@ -23,21 +24,34 @@ export function validateOrgSlug(slug) {
|
|
|
23
24
|
}
|
|
24
25
|
return slug;
|
|
25
26
|
}
|
|
27
|
+
/**
|
|
28
|
+
* Only a missing file means "no contexts yet". An unreadable or corrupt file is
|
|
29
|
+
* an error: reading it as empty would report every context as unknown, and the
|
|
30
|
+
* next save would write that empty config over the user's contexts.
|
|
31
|
+
*/
|
|
26
32
|
export async function loadContextConfig() {
|
|
33
|
+
let raw;
|
|
34
|
+
try {
|
|
35
|
+
raw = await readFile(CONTEXTS_FILE, "utf-8");
|
|
36
|
+
}
|
|
37
|
+
catch (error) {
|
|
38
|
+
if (error.code === "ENOENT") {
|
|
39
|
+
return normalizeContextConfig({});
|
|
40
|
+
}
|
|
41
|
+
throw error;
|
|
42
|
+
}
|
|
43
|
+
let parsed;
|
|
27
44
|
try {
|
|
28
|
-
|
|
29
|
-
const parsed = JSON.parse(raw);
|
|
30
|
-
return normalizeContextConfig(parsed);
|
|
45
|
+
parsed = JSON.parse(raw);
|
|
31
46
|
}
|
|
32
47
|
catch {
|
|
33
|
-
|
|
48
|
+
throw new Error(`${CONTEXTS_FILE} is not valid JSON. Fix or delete it, then run \`lobu context list\`.`);
|
|
34
49
|
}
|
|
50
|
+
return normalizeContextConfig(parsed);
|
|
35
51
|
}
|
|
52
|
+
/** Atomic, so a concurrent `lobu` process never reads a half-written file. */
|
|
36
53
|
async function saveContextConfig(config) {
|
|
37
|
-
await
|
|
38
|
-
await writeFile(CONTEXTS_FILE, JSON.stringify(config, null, 2), {
|
|
39
|
-
mode: 0o600,
|
|
40
|
-
});
|
|
54
|
+
await atomicWriteFile(CONTEXTS_FILE, JSON.stringify(config, null, 2));
|
|
41
55
|
}
|
|
42
56
|
export async function getCurrentContextName() {
|
|
43
57
|
const envContext = process.env.LOBU_CONTEXT?.trim();
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
"server": "dist/server.bundle.mjs",
|
|
6
6
|
"embeddingsServer": "dist/embeddings-server.mjs"
|
|
7
7
|
},
|
|
8
|
-
"version": "24.
|
|
8
|
+
"version": "24.10.0",
|
|
9
9
|
"verify": "dist/verify.mjs"
|
|
10
10
|
},
|
|
11
11
|
"device": {
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"connector": "node_modules/@lobu/cli/dist/commands/connector.js",
|
|
17
17
|
"worker": "node_modules/@lobu/connector-worker/dist/bin.js"
|
|
18
18
|
},
|
|
19
|
-
"version": "24.
|
|
19
|
+
"version": "24.10.0",
|
|
20
20
|
"verify": "dist/verify.mjs"
|
|
21
21
|
},
|
|
22
22
|
"postgres": {
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"entries": {
|
|
25
25
|
"postgres": "dist/index.mjs"
|
|
26
26
|
},
|
|
27
|
-
"version": "24.
|
|
27
|
+
"version": "24.10.0",
|
|
28
28
|
"verify": "dist/verify.mjs"
|
|
29
29
|
},
|
|
30
30
|
"embeddings": {
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"entries": {
|
|
33
33
|
"embeddings": "dist/embeddings.js"
|
|
34
34
|
},
|
|
35
|
-
"version": "24.
|
|
35
|
+
"version": "24.10.0",
|
|
36
36
|
"verify": "dist/verify.mjs"
|
|
37
37
|
}
|
|
38
38
|
}
|