@lobu/runtime-device 24.9.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 +18 -16
- package/npm-shrinkwrap.json +78 -61
- package/package.json +1 -1
- package/vendor/cli/dist/bundled-skills/lobu/SKILL.md +3 -0
- package/vendor/cli/dist/commands/_lib/apply/apply-cmd.js +4 -4
- package/vendor/cli/dist/commands/_lib/apply/client.d.ts +21 -17
- package/vendor/cli/dist/commands/_lib/apply/client.js +32 -34
- package/vendor/cli/dist/commands/dev.js +2 -0
- package/vendor/cli/dist/connectors/postgres.ts +39 -24
- 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/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 +6 -0
- 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/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 +85 -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 +1 -1
- package/vendor/core/dist/classify-error.js +2 -2
- package/vendor/core/dist/contracts/tools/manage-automations.d.ts +28 -3
- package/vendor/core/dist/contracts/tools/manage-automations.js +27 -8
- 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/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/credentials.d.ts +12 -0
- package/vendor/core/dist/credentials.js +1 -0
- package/vendor/core/dist/errors.js +2 -2
- package/vendor/core/dist/worker/auth.d.ts +5 -0
- package/vendor/core/dist/worker/auth.js +15 -4
- package/vendor/core/package.json +1 -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/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
|
@@ -155,6 +155,8 @@ export interface RemoteAutomation {
|
|
|
155
155
|
outputs?: Record<string, unknown> | null;
|
|
156
156
|
reactions_guidance?: string | null;
|
|
157
157
|
}
|
|
158
|
+
/** Whether apply creates a schema type or updates the existing one. */
|
|
159
|
+
type SchemaWriteVerb = "create" | "update";
|
|
158
160
|
interface UpsertEntityTypeResult {
|
|
159
161
|
created?: boolean;
|
|
160
162
|
updated?: boolean;
|
|
@@ -378,15 +380,19 @@ export declare class ApplyClient {
|
|
|
378
380
|
listEntityTypes(): Promise<RemoteEntityType[]>;
|
|
379
381
|
/**
|
|
380
382
|
* The `manage_entity_schema` admin tool exposes separate `create` / `update`
|
|
381
|
-
* actions
|
|
382
|
-
* `
|
|
383
|
-
*
|
|
384
|
-
* `[
|
|
385
|
-
*
|
|
386
|
-
*
|
|
383
|
+
* actions. The plan already knows which one a row needs, so an `update` row
|
|
384
|
+
* goes straight to `update`: probing with `create` first made every apply of
|
|
385
|
+
* an existing type a failed call on the server. A `create` row that meets a
|
|
386
|
+
* duplicate (`[entity_type_exists]` / `[relationship_type_exists]`, 409) was
|
|
387
|
+
* created concurrently after the plan was read, so it is reconciled as an
|
|
388
|
+
* update. Any other error (e.g. a 422 `[invalid_schema]` validation failure)
|
|
389
|
+
* propagates verbatim — retrying it as an update used to mask the real
|
|
390
|
+
* message behind "Entity type not found" (issue #1177).
|
|
387
391
|
*/
|
|
388
392
|
private upsertSchemaResource;
|
|
389
|
-
upsertEntityType(
|
|
393
|
+
upsertEntityType(
|
|
394
|
+
/** The plan's verb for this row: whether the type exists remotely. */
|
|
395
|
+
verb: SchemaWriteVerb, entity: Omit<DesiredEntityType, "metadata">,
|
|
390
396
|
/**
|
|
391
397
|
* The live type's `metadata_schema` extension keys
|
|
392
398
|
* ({@link RemoteEntityType.schemaExtras}), from the remote snapshot this
|
|
@@ -431,7 +437,9 @@ export declare class ApplyClient {
|
|
|
431
437
|
listRelationshipTypeRules(slug: string): Promise<Array<RelationshipRule & {
|
|
432
438
|
id: number;
|
|
433
439
|
}>>;
|
|
434
|
-
upsertRelationshipType(
|
|
440
|
+
upsertRelationshipType(
|
|
441
|
+
/** The plan's verb for this row: whether the type exists remotely. */
|
|
442
|
+
verb: SchemaWriteVerb, rel: Omit<DesiredRelationshipType, "metadata">): Promise<UpsertEntityTypeResult>;
|
|
435
443
|
/**
|
|
436
444
|
* Delete an entity type (code-managed prune). The server soft-deletes and
|
|
437
445
|
* REFUSES if instances of the type still exist — the data is exempt from
|
|
@@ -566,18 +574,14 @@ export declare class ApplyClient {
|
|
|
566
574
|
updateFeed(feedId: number, payload: UpdateFeedPayload): Promise<RemoteFeed>;
|
|
567
575
|
}
|
|
568
576
|
/**
|
|
569
|
-
* Recognise duplicate-name errors from the admin tools
|
|
570
|
-
*
|
|
571
|
-
*
|
|
572
|
-
* (`manage_entity_schema` create / add_rule → `[entity_type_exists]`,
|
|
573
|
-
* `[relationship_type_exists]`, `[already_exists]`, all httpStatus 409).
|
|
577
|
+
* Recognise duplicate-name errors from the admin tools by status alone. Every
|
|
578
|
+
* duplicate path `apply` upserts through (`manage_entity_schema` create /
|
|
579
|
+
* add_rule) answers 409, and nothing else those calls return does.
|
|
574
580
|
*
|
|
575
581
|
* Anything else is NOT a duplicate. In particular a 422 schema-validation
|
|
576
582
|
* error (`[invalid_schema]`, e.g. ">4 x-table-column fields") must surface
|
|
577
|
-
* verbatim
|
|
578
|
-
*
|
|
579
|
-
* a misleading "Entity type not found" (issue #1177). The 409 fallback stays
|
|
580
|
-
* as a belt-and-braces signal for duplicate paths that predate the codes.
|
|
583
|
+
* verbatim: the old any-4xx fallback retried with `action: update` and buried
|
|
584
|
+
* the real message under a misleading "Entity type not found" (issue #1177).
|
|
581
585
|
*/
|
|
582
586
|
export declare function isDuplicateError(err: ApiError): boolean;
|
|
583
587
|
interface ResolvedClient {
|
|
@@ -380,15 +380,27 @@ export class ApplyClient {
|
|
|
380
380
|
}
|
|
381
381
|
/**
|
|
382
382
|
* The `manage_entity_schema` admin tool exposes separate `create` / `update`
|
|
383
|
-
* actions
|
|
384
|
-
* `
|
|
385
|
-
*
|
|
386
|
-
* `[
|
|
387
|
-
*
|
|
388
|
-
*
|
|
383
|
+
* actions. The plan already knows which one a row needs, so an `update` row
|
|
384
|
+
* goes straight to `update`: probing with `create` first made every apply of
|
|
385
|
+
* an existing type a failed call on the server. A `create` row that meets a
|
|
386
|
+
* duplicate (`[entity_type_exists]` / `[relationship_type_exists]`, 409) was
|
|
387
|
+
* created concurrently after the plan was read, so it is reconciled as an
|
|
388
|
+
* update. Any other error (e.g. a 422 `[invalid_schema]` validation failure)
|
|
389
|
+
* propagates verbatim — retrying it as an update used to mask the real
|
|
390
|
+
* message behind "Entity type not found" (issue #1177).
|
|
389
391
|
*/
|
|
390
|
-
async upsertSchemaResource(schemaType, payload) {
|
|
392
|
+
async upsertSchemaResource(verb, schemaType, payload) {
|
|
391
393
|
const url = `/api/${this.orgSlug}/manage_entity_schema`;
|
|
394
|
+
const update = async () => {
|
|
395
|
+
await this.request("POST", url, {
|
|
396
|
+
schema_type: schemaType,
|
|
397
|
+
action: "update",
|
|
398
|
+
...payload,
|
|
399
|
+
});
|
|
400
|
+
return { updated: true };
|
|
401
|
+
};
|
|
402
|
+
if (verb === "update")
|
|
403
|
+
return update();
|
|
392
404
|
try {
|
|
393
405
|
await this.request("POST", url, {
|
|
394
406
|
schema_type: schemaType,
|
|
@@ -398,18 +410,14 @@ export class ApplyClient {
|
|
|
398
410
|
return { created: true };
|
|
399
411
|
}
|
|
400
412
|
catch (err) {
|
|
401
|
-
if (err instanceof ApiError && isDuplicateError(err))
|
|
402
|
-
|
|
403
|
-
schema_type: schemaType,
|
|
404
|
-
action: "update",
|
|
405
|
-
...payload,
|
|
406
|
-
});
|
|
407
|
-
return { updated: true };
|
|
408
|
-
}
|
|
413
|
+
if (err instanceof ApiError && isDuplicateError(err))
|
|
414
|
+
return update();
|
|
409
415
|
throw err;
|
|
410
416
|
}
|
|
411
417
|
}
|
|
412
418
|
async upsertEntityType(
|
|
419
|
+
/** The plan's verb for this row: whether the type exists remotely. */
|
|
420
|
+
verb,
|
|
413
421
|
// `metadata` is authoring-only — never sent to the server (see
|
|
414
422
|
// DesiredEntityType); extra properties on the passed value are ignored.
|
|
415
423
|
entity,
|
|
@@ -548,7 +556,7 @@ export class ApplyClient {
|
|
|
548
556
|
if (rulesSource !== undefined || clearFacets?.has("rules")) {
|
|
549
557
|
payload.rules_source = rulesSource?.sourceCode ?? null;
|
|
550
558
|
}
|
|
551
|
-
return this.upsertSchemaResource("entity_type", payload);
|
|
559
|
+
return this.upsertSchemaResource(verb, "entity_type", payload);
|
|
552
560
|
}
|
|
553
561
|
async listRelationshipTypes() {
|
|
554
562
|
const { body } = await this.request("POST", `/api/${this.orgSlug}/manage_entity_schema`, {
|
|
@@ -578,10 +586,12 @@ export class ApplyClient {
|
|
|
578
586
|
}));
|
|
579
587
|
}
|
|
580
588
|
async upsertRelationshipType(
|
|
589
|
+
/** The plan's verb for this row: whether the type exists remotely. */
|
|
590
|
+
verb,
|
|
581
591
|
// `metadata` is authoring-only — never sent (see DesiredRelationshipType).
|
|
582
592
|
rel) {
|
|
583
593
|
const { rules, ...payload } = rel;
|
|
584
|
-
const result = await this.upsertSchemaResource("relationship_type", payload);
|
|
594
|
+
const result = await this.upsertSchemaResource(verb, "relationship_type", payload);
|
|
585
595
|
// Reconcile rules to exactly the desired set so config is the source of
|
|
586
596
|
// truth (declarative). Without removing extras, dropping a rule from config
|
|
587
597
|
// would never take effect AND would churn a perpetual "rules changed"
|
|
@@ -1137,28 +1147,16 @@ function mapConnectorDefinitionItem(item) {
|
|
|
1137
1147
|
};
|
|
1138
1148
|
}
|
|
1139
1149
|
/**
|
|
1140
|
-
* Recognise duplicate-name errors from the admin tools
|
|
1141
|
-
*
|
|
1142
|
-
*
|
|
1143
|
-
* (`manage_entity_schema` create / add_rule → `[entity_type_exists]`,
|
|
1144
|
-
* `[relationship_type_exists]`, `[already_exists]`, all httpStatus 409).
|
|
1150
|
+
* Recognise duplicate-name errors from the admin tools by status alone. Every
|
|
1151
|
+
* duplicate path `apply` upserts through (`manage_entity_schema` create /
|
|
1152
|
+
* add_rule) answers 409, and nothing else those calls return does.
|
|
1145
1153
|
*
|
|
1146
1154
|
* Anything else is NOT a duplicate. In particular a 422 schema-validation
|
|
1147
1155
|
* error (`[invalid_schema]`, e.g. ">4 x-table-column fields") must surface
|
|
1148
|
-
* verbatim
|
|
1149
|
-
*
|
|
1150
|
-
* a misleading "Entity type not found" (issue #1177). The 409 fallback stays
|
|
1151
|
-
* as a belt-and-braces signal for duplicate paths that predate the codes.
|
|
1156
|
+
* verbatim: the old any-4xx fallback retried with `action: update` and buried
|
|
1157
|
+
* the real message under a misleading "Entity type not found" (issue #1177).
|
|
1152
1158
|
*/
|
|
1153
1159
|
export function isDuplicateError(err) {
|
|
1154
|
-
if (typeof err.status !== "number")
|
|
1155
|
-
return false;
|
|
1156
|
-
const message = err.message.toLowerCase();
|
|
1157
|
-
if (message.includes("[entity_type_exists]") ||
|
|
1158
|
-
message.includes("[relationship_type_exists]") ||
|
|
1159
|
-
message.includes("[already_exists]")) {
|
|
1160
|
-
return true;
|
|
1161
|
-
}
|
|
1162
1160
|
return err.status === 409;
|
|
1163
1161
|
}
|
|
1164
1162
|
export async function resolveApplyClient(opts) {
|
|
@@ -250,6 +250,8 @@ export async function devCommand(cwd, options = {}) {
|
|
|
250
250
|
envVars.WEB_DIST_DIR ||
|
|
251
251
|
(existsSync(bundledWebDistPath) ? bundledWebDistPath : undefined);
|
|
252
252
|
const childEnv = {
|
|
253
|
+
// Reported by the anonymous install ping; the project .env may override.
|
|
254
|
+
LOBU_DEPLOY_KIND: "cli",
|
|
253
255
|
...mergedEnv,
|
|
254
256
|
...runtime.env,
|
|
255
257
|
LOBU_DEV_PROJECT_PATH: projectPath,
|
|
@@ -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,7 +381,7 @@ 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.
|
|
384
|
+
version: '1.1.1',
|
|
390
385
|
queryCapabilities: { exactMatch: true, verbatimExactMatch: true, exactMatchAny: true, selection: true },
|
|
391
386
|
faviconDomain: 'postgresql.org',
|
|
392
387
|
authSchema: {
|
|
@@ -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
|
|
|
@@ -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,
|
|
@@ -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
|
}
|
package/vendor/cli/package.json
CHANGED
|
@@ -1087,6 +1087,12 @@ export interface FeedReadResult {
|
|
|
1087
1087
|
window?: FeedReadWindowCoverage;
|
|
1088
1088
|
}
|
|
1089
1089
|
export type FeedSyncHandler<C = Record<string, unknown>, F = Record<string, unknown>> = (ctx: SyncContext<C, F>) => Promise<SyncResult>;
|
|
1090
|
+
/**
|
|
1091
|
+
* Reads one page from the source. Throw `SourceWithheldError` (or any error
|
|
1092
|
+
* whose own `code` is `'withheld'`) when the source deliberately withholds the
|
|
1093
|
+
* requested record: callers report it as private with the error's message as
|
|
1094
|
+
* the reason, and never retry it. Any other rejection is a read failure.
|
|
1095
|
+
*/
|
|
1090
1096
|
export type FeedReadHandler<F = Record<string, unknown>> = (ctx: FeedReadContext<F>) => Promise<FeedReadResult>;
|
|
1091
1097
|
/** Executable feed definition held only inside a connector runtime. */
|
|
1092
1098
|
export interface RuntimeFeedDefinition<C = Record<string, unknown>, F = Record<string, unknown>> extends Omit<FeedDefinition, 'operations' | 'webhook'> {
|