@lobu/runtime-device 24.9.0 → 24.11.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 +19 -17
- package/npm-shrinkwrap.json +81 -64
- 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/linkedin-inbox-adapter.js +13 -3
- package/vendor/cli/dist/connectors/postgres.ts +39 -24
- package/vendor/cli/dist/connectors/whatsapp-web-adapter.js +54 -22
- package/vendor/cli/dist/connectors/whatsapp-web-helpers.ts +48 -2
- package/vendor/cli/dist/connectors/whatsapp_web.ts +23 -7
- package/vendor/cli/dist/connectors/x-dm-adapter.js +17 -3
- 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/agent-turn/guest.bundle.js +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
|
@@ -62,6 +62,8 @@ const MAX_REDIRECTS = 20;
|
|
|
62
62
|
* reads; an honest connector drains or cancels every body it opens.
|
|
63
63
|
*/
|
|
64
64
|
const MAX_OPEN_FETCHES = 1024;
|
|
65
|
+
/** Rejects a host hook that was still queued when the run ended; never a run's failure. */
|
|
66
|
+
const SKIPPED_HOOK = new Error('the run ended before this hook started');
|
|
65
67
|
/** Thrown when a job demands the isolate lane on a host that cannot run one. */
|
|
66
68
|
export class IsolateRuntimeUnavailableError extends Error {
|
|
67
69
|
constructor(reason) {
|
|
@@ -477,13 +479,44 @@ export class IsolateExecutor {
|
|
|
477
479
|
return ivm;
|
|
478
480
|
}
|
|
479
481
|
async execute(compiledCode, job, hooks) {
|
|
482
|
+
const tail = new RingBuffer(STREAM_TAIL_CAP_BYTES);
|
|
483
|
+
if (this.options.timeoutMs === 0)
|
|
484
|
+
return this.executeInIsolate(compiledCode, job, hooks, tail);
|
|
485
|
+
// The budget belongs to the whole run, including native context setup.
|
|
486
|
+
// Race setup too: merely subtracting its duration would still leave a
|
|
487
|
+
// caller waiting indefinitely before the guest's timer could start.
|
|
488
|
+
const timeoutAbort = new AbortController();
|
|
489
|
+
const signal = hooks?.signal
|
|
490
|
+
? AbortSignal.any([hooks.signal, timeoutAbort.signal])
|
|
491
|
+
: timeoutAbort.signal;
|
|
492
|
+
let timer;
|
|
493
|
+
const timeout = new Promise((_resolve, reject) => {
|
|
494
|
+
timer = setTimeout(() => {
|
|
495
|
+
const outputTail = redactOutput(tail.toString());
|
|
496
|
+
reject(new ConnectorExecutionError(`Execution timed out after ${this.options.timeoutMs}ms${outputTail ? `\n[console]\n${outputTail}` : ''}`, { exitCode: null, exitSignal: null, outputTail, exitReason: 'timeout' }));
|
|
497
|
+
// An in-flight host is terminated immediately. If setup resolves
|
|
498
|
+
// later, executeInIsolate's cancellation latch disposes it before
|
|
499
|
+
// handing it any guest code.
|
|
500
|
+
timeoutAbort.abort();
|
|
501
|
+
}, this.options.timeoutMs);
|
|
502
|
+
});
|
|
503
|
+
try {
|
|
504
|
+
return await Promise.race([
|
|
505
|
+
this.executeInIsolate(compiledCode, job, { ...hooks, signal }, tail),
|
|
506
|
+
timeout,
|
|
507
|
+
]);
|
|
508
|
+
}
|
|
509
|
+
finally {
|
|
510
|
+
clearTimeout(timer);
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
async executeInIsolate(compiledCode, job, hooks, tail) {
|
|
480
514
|
if (job.httpAuth && !hooks?.onHttpFetch) {
|
|
481
515
|
throw new Error('HTTP authentication requires a gateway fetch hook');
|
|
482
516
|
}
|
|
483
517
|
assertIsolateEligible(compiledCode);
|
|
484
518
|
const exemptHosts = [...this.exactAllowedHosts, ...operatorHttpExemptHosts(job)];
|
|
485
519
|
const ivm = await this.requireIsolatedVm();
|
|
486
|
-
const tail = new RingBuffer(STREAM_TAIL_CAP_BYTES);
|
|
487
520
|
let logBytesUsed = 0;
|
|
488
521
|
let logTruncated = false;
|
|
489
522
|
let hookFailure = null;
|
|
@@ -561,7 +594,11 @@ export class IsolateExecutor {
|
|
|
561
594
|
}
|
|
562
595
|
});
|
|
563
596
|
};
|
|
597
|
+
// The first state that ended the run. A run can end after the guest
|
|
598
|
+
// returned, while its hooks drain; that run did not complete.
|
|
599
|
+
let endedWith = null;
|
|
564
600
|
const terminate = (state) => {
|
|
601
|
+
endedWith ??= state;
|
|
565
602
|
runAbort.abort();
|
|
566
603
|
for (const timer of pendingSleeps)
|
|
567
604
|
clearTimeout(timer);
|
|
@@ -592,12 +629,21 @@ export class IsolateExecutor {
|
|
|
592
629
|
hooks?.signal?.addEventListener('abort', onCancel, { once: true });
|
|
593
630
|
const queueHook = (task) => {
|
|
594
631
|
const next = processingChain.then(async () => {
|
|
632
|
+
// A hook queued behind one that outlived the run must not start: the
|
|
633
|
+
// run already has its terminal state, so any side effect now would
|
|
634
|
+
// land for a run reported as failed.
|
|
635
|
+
if (runAbort.signal.aborted)
|
|
636
|
+
throw SKIPPED_HOOK;
|
|
595
637
|
await task();
|
|
596
638
|
});
|
|
597
639
|
// Keep the chain alive after a failure so later calls still see the
|
|
598
640
|
// terminal state instead of re-running against a torn-down host.
|
|
599
641
|
processingChain = next.catch(() => undefined);
|
|
600
642
|
next.catch((error) => {
|
|
643
|
+
// A skipped hook is a consequence of the run's end, not its cause:
|
|
644
|
+
// the original failure keeps its name, status and diagnostics.
|
|
645
|
+
if (error === SKIPPED_HOOK)
|
|
646
|
+
return;
|
|
601
647
|
if (hookFailure === null)
|
|
602
648
|
hookFailure = error;
|
|
603
649
|
terminate({ name: 'HookFailure', message: error instanceof Error ? error.message : String(error) });
|
|
@@ -705,7 +751,7 @@ export class IsolateExecutor {
|
|
|
705
751
|
return { data: chunk.value, done: false };
|
|
706
752
|
};
|
|
707
753
|
const mergedConfig = job.mode === 'authenticate' ? job.config : buildConnectorConfig(job);
|
|
708
|
-
|
|
754
|
+
const createHost = () => IsolateHost.create({
|
|
709
755
|
ivm,
|
|
710
756
|
memoryMb: this.options.memoryMb,
|
|
711
757
|
messageBytes: this.options.messageBytes,
|
|
@@ -1031,12 +1077,13 @@ export class IsolateExecutor {
|
|
|
1031
1077
|
},
|
|
1032
1078
|
},
|
|
1033
1079
|
});
|
|
1034
|
-
const redactedTail = () => redactOutput(tail.toString());
|
|
1035
|
-
const withTail = (prefix) => {
|
|
1036
|
-
const t = redactedTail();
|
|
1037
|
-
return t ? `${prefix}\n[console]\n${t}` : prefix;
|
|
1038
|
-
};
|
|
1039
1080
|
try {
|
|
1081
|
+
host = await createHost();
|
|
1082
|
+
const redactedTail = () => redactOutput(tail.toString());
|
|
1083
|
+
const withTail = (prefix) => {
|
|
1084
|
+
const t = redactedTail();
|
|
1085
|
+
return t ? `${prefix}\n[console]\n${t}` : prefix;
|
|
1086
|
+
};
|
|
1040
1087
|
const source = `var __job_json = ${jsonLiteral(guestJob)};\nvar __config_json = ${jsonLiteral(mergedConfig)};\n${compiledCode}\n${GUEST_RUNNER}`;
|
|
1041
1088
|
let raw;
|
|
1042
1089
|
try {
|
|
@@ -1047,7 +1094,9 @@ export class IsolateExecutor {
|
|
|
1047
1094
|
// reports through exactly the path a mid-run cancel takes.
|
|
1048
1095
|
if (cancelled || hooks?.signal?.aborted)
|
|
1049
1096
|
host.terminate(cancelState);
|
|
1050
|
-
|
|
1097
|
+
// execute owns the single deadline from entry, including setup and
|
|
1098
|
+
// outstanding hooks; a second guest timer would restart the budget.
|
|
1099
|
+
raw = await host.run(source, { timeoutMs: 0 });
|
|
1051
1100
|
}
|
|
1052
1101
|
catch (error) {
|
|
1053
1102
|
if (hookFailure !== null)
|
|
@@ -1055,19 +1104,6 @@ export class IsolateExecutor {
|
|
|
1055
1104
|
if (guestFatal)
|
|
1056
1105
|
throw this.guestError(guestFatal, redactedTail());
|
|
1057
1106
|
if (error instanceof IsolateHostError) {
|
|
1058
|
-
if (error.kind === 'timeout') {
|
|
1059
|
-
// Not "Feed execution": this executor runs feeds, connector
|
|
1060
|
-
// actions AND agent turns, and a chat user whose turn timed out
|
|
1061
|
-
// was being told a feed had failed. The classifier maps both
|
|
1062
|
-
// spellings (classify-error.ts) so a mid-rollout worker still
|
|
1063
|
-
// classifies.
|
|
1064
|
-
throw new ConnectorExecutionError(withTail(`Execution timed out after ${this.options.timeoutMs}ms`), {
|
|
1065
|
-
exitCode: null,
|
|
1066
|
-
exitSignal: null,
|
|
1067
|
-
outputTail: redactedTail(),
|
|
1068
|
-
exitReason: 'timeout',
|
|
1069
|
-
});
|
|
1070
|
-
}
|
|
1071
1107
|
if (error.kind === 'memory') {
|
|
1072
1108
|
throw new ConnectorExecutionError(withTail(`Isolate out of memory (limit ${this.options.memoryMb} MB)`), {
|
|
1073
1109
|
exitCode: null,
|
|
@@ -1087,10 +1123,31 @@ export class IsolateExecutor {
|
|
|
1087
1123
|
throw this.guestError(error instanceof Error ? { name: error.name, message: error.message, stack: error.stack } : { message: String(error) }, redactedTail());
|
|
1088
1124
|
}
|
|
1089
1125
|
// Wait for hooks the guest fired without awaiting (or whose promise the
|
|
1090
|
-
// guest dropped) before reporting the result.
|
|
1091
|
-
|
|
1126
|
+
// guest dropped) before reporting the result. A hook fired just before
|
|
1127
|
+
// the guest returned can join the chain after this wait begins, so wait
|
|
1128
|
+
// until the chain stops growing.
|
|
1129
|
+
let drained;
|
|
1130
|
+
do {
|
|
1131
|
+
drained = processingChain;
|
|
1132
|
+
await drained;
|
|
1133
|
+
} while (drained !== processingChain);
|
|
1092
1134
|
if (hookFailure !== null)
|
|
1093
1135
|
throw hookFailure;
|
|
1136
|
+
// The guest returned, but the run ended (e.g. cancelled) while its hooks
|
|
1137
|
+
// drained, so some never ran or never reached the host: reporting
|
|
1138
|
+
// success would drop their side effects silently.
|
|
1139
|
+
// Assigned inside `terminate`, which TypeScript's narrowing cannot see.
|
|
1140
|
+
const ended = endedWith;
|
|
1141
|
+
if (ended) {
|
|
1142
|
+
if (guestFatal)
|
|
1143
|
+
throw this.guestError(guestFatal, redactedTail());
|
|
1144
|
+
throw new ConnectorExecutionError(withTail(ended.message), {
|
|
1145
|
+
exitCode: null,
|
|
1146
|
+
exitSignal: null,
|
|
1147
|
+
outputTail: redactedTail(),
|
|
1148
|
+
exitReason: 'crash',
|
|
1149
|
+
});
|
|
1150
|
+
}
|
|
1094
1151
|
const outcome = parseGuestJson(raw, 'result');
|
|
1095
1152
|
if (!outcome || typeof outcome !== 'object' || typeof outcome.ok !== 'boolean') {
|
|
1096
1153
|
throw new Error('result: guest returned a malformed outcome envelope');
|
|
@@ -1112,7 +1169,7 @@ export class IsolateExecutor {
|
|
|
1112
1169
|
closeAllSockets();
|
|
1113
1170
|
vault.clear();
|
|
1114
1171
|
void egress.destroy().catch(() => undefined);
|
|
1115
|
-
host
|
|
1172
|
+
host?.dispose();
|
|
1116
1173
|
}
|
|
1117
1174
|
}
|
|
1118
1175
|
/** Build the `ConnectorExecutionError` the daemon reports for a guest-thrown error. */
|
|
@@ -1126,6 +1183,10 @@ export class IsolateExecutor {
|
|
|
1126
1183
|
httpStatus: typeof description.httpStatus === 'number' && description.httpStatus >= 100 && description.httpStatus < 600
|
|
1127
1184
|
? description.httpStatus
|
|
1128
1185
|
: undefined,
|
|
1186
|
+
code: description.code === 'withheld' ? description.code : undefined,
|
|
1187
|
+
pgCode: typeof description.pgCode === 'string' && /^[0-9A-Z]{5}$/.test(description.pgCode) && !description.pgCode.startsWith('E')
|
|
1188
|
+
? description.pgCode
|
|
1189
|
+
: undefined,
|
|
1129
1190
|
});
|
|
1130
1191
|
error.name = description.name ? redactOutput(String(description.name)) : 'ConnectorExecutionError';
|
|
1131
1192
|
if (description.stack)
|
|
@@ -303,6 +303,11 @@ var exports = module.exports;
|
|
|
303
303
|
if (error instanceof Error) {
|
|
304
304
|
var desc = { name: String(error.name || 'Error'), message: String(error.message), stack: typeof error.stack === 'string' ? error.stack : undefined };
|
|
305
305
|
if (typeof error.status === 'number' && error.status >= 100 && error.status < 600) desc.httpStatus = error.status;
|
|
306
|
+
// A deliberately withheld source read (SourceWithheldError, or any error
|
|
307
|
+
// whose own code is 'withheld'). SQLSTATE travels separately so it cannot
|
|
308
|
+
// be mistaken for a connector outcome. Ambiguous E-prefixed errnos stay opaque.
|
|
309
|
+
if (Object.prototype.hasOwnProperty.call(error, 'code') && error.code === 'withheld') desc.code = 'withheld';
|
|
310
|
+
if (Object.prototype.hasOwnProperty.call(error, 'code') && typeof error.code === 'string' && /^[0-9A-Z]{5}$/.test(error.code) && error.code.charAt(0) !== 'E') desc.pgCode = error.code;
|
|
306
311
|
return desc;
|
|
307
312
|
}
|
|
308
313
|
var text;
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
* agent as `agent_error`.
|
|
11
11
|
* - `response-renderer.ts` and `chat-response-bridge.ts` resolve the code to
|
|
12
12
|
* a remediation CTA; with none, the user gets the provider's raw prose.
|
|
13
|
-
* - An unclassified failure also misses the `PROVIDER_*`
|
|
13
|
+
* - An unclassified failure also misses the `PROVIDER_*` error alerting.
|
|
14
14
|
*
|
|
15
15
|
* Adding a failure mode = one pattern here + one entry in `AGENT_ERRORS`.
|
|
16
16
|
*
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
* agent as `agent_error`.
|
|
12
12
|
* - `response-renderer.ts` and `chat-response-bridge.ts` resolve the code to
|
|
13
13
|
* a remediation CTA; with none, the user gets the provider's raw prose.
|
|
14
|
-
* - An unclassified failure also misses the `PROVIDER_*`
|
|
14
|
+
* - An unclassified failure also misses the `PROVIDER_*` error alerting.
|
|
15
15
|
*
|
|
16
16
|
* Adding a failure mode = one pattern here + one entry in `AGENT_ERRORS`.
|
|
17
17
|
*
|
|
@@ -115,7 +115,7 @@ function classifyErrorMessage(message) {
|
|
|
115
115
|
// (code no_credentials) when every credential tier misses. The live red-test
|
|
116
116
|
// (LOBU-BACKEND-W) landed as `unclassified` because the auth-hint regex
|
|
117
117
|
// doesn't cover this shape — and an unclassified event dodges the
|
|
118
|
-
// PROVIDER_*
|
|
118
|
+
// PROVIDER_* alert.
|
|
119
119
|
if (/no\s+(provider\s+)?credentials\s+configured|no_credentials/i.test(message))
|
|
120
120
|
return errors_js_1.AgentErrorCode.PROVIDER_AUTH;
|
|
121
121
|
// The provider accepted the credential but refuses to USE it: Anthropic 403s
|
|
@@ -417,9 +417,17 @@ export declare const AutomationClaimNextWindowContextSchema: import("@sinclair/t
|
|
|
417
417
|
}>>;
|
|
418
418
|
}>;
|
|
419
419
|
export type AutomationClaimNextWindowContext = Static<typeof AutomationClaimNextWindowContextSchema>;
|
|
420
|
-
|
|
420
|
+
/**
|
|
421
|
+
* A claim either leases a window (`claimed`, with context to process and a
|
|
422
|
+
* window_token for completeWindow) or reports that the due window had no new
|
|
423
|
+
* or changed source content and was already booked as a no-op run
|
|
424
|
+
* (`completed`). A completed receipt needs no completeWindow: the schedule
|
|
425
|
+
* has advanced, so refresh activity for the next due window.
|
|
426
|
+
*/
|
|
427
|
+
export declare const AutomationClaimNextWindowResultSchema: import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TObject<{
|
|
421
428
|
action: import("@sinclair/typebox").TLiteral<"claim_next_window">;
|
|
422
429
|
automation_id: import("@sinclair/typebox").TString;
|
|
430
|
+
status: import("@sinclair/typebox").TLiteral<"claimed">;
|
|
423
431
|
run_id: import("@sinclair/typebox").TInteger;
|
|
424
432
|
lease_expires_at: import("@sinclair/typebox").TString;
|
|
425
433
|
context: import("@sinclair/typebox").TObject<{
|
|
@@ -460,7 +468,15 @@ export declare const AutomationClaimNextWindowResultSchema: import("@sinclair/ty
|
|
|
460
468
|
}>>;
|
|
461
469
|
}>>;
|
|
462
470
|
}>;
|
|
463
|
-
}
|
|
471
|
+
}>, import("@sinclair/typebox").TObject<{
|
|
472
|
+
action: import("@sinclair/typebox").TLiteral<"claim_next_window">;
|
|
473
|
+
automation_id: import("@sinclair/typebox").TString;
|
|
474
|
+
status: import("@sinclair/typebox").TLiteral<"completed">;
|
|
475
|
+
run_id: import("@sinclair/typebox").TInteger;
|
|
476
|
+
skipped_unchanged: import("@sinclair/typebox").TLiteral<true>;
|
|
477
|
+
window_start: import("@sinclair/typebox").TString;
|
|
478
|
+
window_end: import("@sinclair/typebox").TString;
|
|
479
|
+
}>]>;
|
|
464
480
|
export type AutomationClaimNextWindowResult = Static<typeof AutomationClaimNextWindowResultSchema>;
|
|
465
481
|
export declare const AutomationTriggerExecutionSchema: import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TObject<{
|
|
466
482
|
lane: import("@sinclair/typebox").TLiteral<"managed_agent">;
|
|
@@ -596,9 +612,10 @@ export declare const ManageAutomationsResultSchema: import("@sinclair/typebox").
|
|
|
596
612
|
window_start: import("@sinclair/typebox").TString;
|
|
597
613
|
window_end: import("@sinclair/typebox").TString;
|
|
598
614
|
content_linked: import("@sinclair/typebox").TInteger;
|
|
599
|
-
}>, import("@sinclair/typebox").TObject<{
|
|
615
|
+
}>, import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TObject<{
|
|
600
616
|
action: import("@sinclair/typebox").TLiteral<"claim_next_window">;
|
|
601
617
|
automation_id: import("@sinclair/typebox").TString;
|
|
618
|
+
status: import("@sinclair/typebox").TLiteral<"claimed">;
|
|
602
619
|
run_id: import("@sinclair/typebox").TInteger;
|
|
603
620
|
lease_expires_at: import("@sinclair/typebox").TString;
|
|
604
621
|
context: import("@sinclair/typebox").TObject<{
|
|
@@ -640,6 +657,14 @@ export declare const ManageAutomationsResultSchema: import("@sinclair/typebox").
|
|
|
640
657
|
}>>;
|
|
641
658
|
}>;
|
|
642
659
|
}>, import("@sinclair/typebox").TObject<{
|
|
660
|
+
action: import("@sinclair/typebox").TLiteral<"claim_next_window">;
|
|
661
|
+
automation_id: import("@sinclair/typebox").TString;
|
|
662
|
+
status: import("@sinclair/typebox").TLiteral<"completed">;
|
|
663
|
+
run_id: import("@sinclair/typebox").TInteger;
|
|
664
|
+
skipped_unchanged: import("@sinclair/typebox").TLiteral<true>;
|
|
665
|
+
window_start: import("@sinclair/typebox").TString;
|
|
666
|
+
window_end: import("@sinclair/typebox").TString;
|
|
667
|
+
}>]>, import("@sinclair/typebox").TObject<{
|
|
643
668
|
action: import("@sinclair/typebox").TLiteral<"trigger">;
|
|
644
669
|
automation_id: import("@sinclair/typebox").TString;
|
|
645
670
|
run_id: import("@sinclair/typebox").TInteger;
|
|
@@ -122,7 +122,7 @@ exports.AutomationScheduleTriggerSchema = typebox_1.Type.Object({
|
|
|
122
122
|
})),
|
|
123
123
|
skip_if_unchanged: typebox_1.Type.Optional(typebox_1.Type.Boolean({
|
|
124
124
|
default: true,
|
|
125
|
-
description: "Book a due window with no new or changed source content as a no-op run instead of dispatching an agent. Applies to native dispatch and to external claimNextWindow, which
|
|
125
|
+
description: "Book a due window with no new or changed source content as a no-op run instead of dispatching an agent. Applies to native dispatch and to external claimNextWindow, which returns a status 'completed' receipt for a skipped window.",
|
|
126
126
|
})),
|
|
127
127
|
}, { additionalProperties: false });
|
|
128
128
|
exports.AutomationTriggerSchema = typebox_1.Type.Union([
|
|
@@ -700,13 +700,32 @@ exports.AutomationClaimNextWindowContextSchema = typebox_1.Type.Object({
|
|
|
700
700
|
skills: typebox_1.Type.Array(typebox_1.Type.Object({ name: typebox_1.Type.String(), content: typebox_1.Type.String() })),
|
|
701
701
|
})),
|
|
702
702
|
});
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
703
|
+
/**
|
|
704
|
+
* A claim either leases a window (`claimed`, with context to process and a
|
|
705
|
+
* window_token for completeWindow) or reports that the due window had no new
|
|
706
|
+
* or changed source content and was already booked as a no-op run
|
|
707
|
+
* (`completed`). A completed receipt needs no completeWindow: the schedule
|
|
708
|
+
* has advanced, so refresh activity for the next due window.
|
|
709
|
+
*/
|
|
710
|
+
exports.AutomationClaimNextWindowResultSchema = typebox_1.Type.Union([
|
|
711
|
+
typebox_1.Type.Object({
|
|
712
|
+
action: typebox_1.Type.Literal("claim_next_window"),
|
|
713
|
+
automation_id: typebox_1.Type.String(),
|
|
714
|
+
status: typebox_1.Type.Literal("claimed"),
|
|
715
|
+
run_id: typebox_1.Type.Integer(),
|
|
716
|
+
lease_expires_at: typebox_1.Type.String(),
|
|
717
|
+
context: exports.AutomationClaimNextWindowContextSchema,
|
|
718
|
+
}),
|
|
719
|
+
typebox_1.Type.Object({
|
|
720
|
+
action: typebox_1.Type.Literal("claim_next_window"),
|
|
721
|
+
automation_id: typebox_1.Type.String(),
|
|
722
|
+
status: typebox_1.Type.Literal("completed"),
|
|
723
|
+
run_id: typebox_1.Type.Integer(),
|
|
724
|
+
skipped_unchanged: typebox_1.Type.Literal(true),
|
|
725
|
+
window_start: typebox_1.Type.String(),
|
|
726
|
+
window_end: typebox_1.Type.String(),
|
|
727
|
+
}),
|
|
728
|
+
]);
|
|
710
729
|
exports.AutomationTriggerExecutionSchema = typebox_1.Type.Union([
|
|
711
730
|
typebox_1.Type.Object({
|
|
712
731
|
lane: typebox_1.Type.Literal("managed_agent"),
|
|
@@ -365,6 +365,13 @@ declare const RelationshipReadFailureSchema: import("@sinclair/typebox").TObject
|
|
|
365
365
|
code: import("@sinclair/typebox").TString;
|
|
366
366
|
}>;
|
|
367
367
|
export type RelationshipReadFailure = Static<typeof RelationshipReadFailureSchema>;
|
|
368
|
+
/** A feed of a source-backed record's live read that returned no rows. */
|
|
369
|
+
export declare const SourceReadFailureSchema: import("@sinclair/typebox").TObject<{
|
|
370
|
+
feed_id: import("@sinclair/typebox").TInteger;
|
|
371
|
+
error: import("@sinclair/typebox").TString;
|
|
372
|
+
code: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TLiteral<"withheld">>;
|
|
373
|
+
}>;
|
|
374
|
+
export type SourceReadFailure = Static<typeof SourceReadFailureSchema>;
|
|
368
375
|
export declare const ManageEntityResultSchema: import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TObject<{
|
|
369
376
|
action: import("@sinclair/typebox").TLiteral<"create">;
|
|
370
377
|
entity: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TObject<{
|
|
@@ -686,6 +693,7 @@ export declare const ManageEntityResultSchema: import("@sinclair/typebox").TUnio
|
|
|
686
693
|
record_failures: import("@sinclair/typebox").TArray<import("@sinclair/typebox").TObject<{
|
|
687
694
|
feed_id: import("@sinclair/typebox").TInteger;
|
|
688
695
|
error: import("@sinclair/typebox").TString;
|
|
696
|
+
code: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TLiteral<"withheld">>;
|
|
689
697
|
}>>;
|
|
690
698
|
next_cursor: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TString, import("@sinclair/typebox").TNull]>>;
|
|
691
699
|
}>, import("@sinclair/typebox").TObject<{
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ManageEntityResultSchema = exports.ManageEntityItemSchema = exports.EntityIdentitySchema = exports.RelationshipCountByTypeSchema = exports.RelationshipRowSchema = exports.ManageEntitySchema = exports.DiscoverDuplicatesAction = exports.ListLinksAction = exports.UpdateLinkAction = exports.UnlinkEntitiesAction = exports.LinkEntitiesAction = exports.DeleteEntityAction = exports.GetEntityAction = exports.ListEntitiesAction = exports.UpdateEntityAction = exports.CreateEntityAction = void 0;
|
|
3
|
+
exports.ManageEntityResultSchema = exports.SourceReadFailureSchema = exports.ManageEntityItemSchema = exports.EntityIdentitySchema = exports.RelationshipCountByTypeSchema = exports.RelationshipRowSchema = exports.ManageEntitySchema = exports.DiscoverDuplicatesAction = exports.ListLinksAction = exports.UpdateLinkAction = exports.UnlinkEntitiesAction = exports.LinkEntitiesAction = exports.DeleteEntityAction = exports.GetEntityAction = exports.ListEntitiesAction = exports.UpdateEntityAction = exports.CreateEntityAction = void 0;
|
|
4
4
|
const typebox_1 = require("@sinclair/typebox");
|
|
5
5
|
const interaction_envelope_1 = require("../interaction-envelope");
|
|
6
6
|
const collection_selection_1 = require("./collection-selection");
|
|
@@ -277,7 +277,7 @@ exports.ListLinksAction = typebox_1.Type.Object({
|
|
|
277
277
|
include_deleted: typebox_1.Type.Optional(IncludeDeleted),
|
|
278
278
|
...(0, pagination_1.paginationFields)(100),
|
|
279
279
|
cursor: typebox_1.Type.Optional(typebox_1.Type.Union([typebox_1.Type.String({ minLength: 1, maxLength: 65536 }), typebox_1.Type.Null()], {
|
|
280
|
-
description: "[list_links, source records] Omit or pass null for the first bounded page, then pass next_cursor until it is null. Stop automatic pagination on record_failures; the cursor retains failed sources for an explicit retry. Pages may be short or empty while next_cursor exists. Merge repeated links across pages by (relationship_type, direction, entity_type, key), keeping the newest occurred_at. Numeric entity_id calls retain limit/offset pagination; source pages bound limit to 100. Authored relationships are permission checked at both endpoints. counts_by_type describes the visible page (counts_scope: page), not a global total. Source pages reject source, confidence_min and include_deleted filters, which cannot be applied to live links. Source reads share a 20 second page deadline. Unavailable endpoints are withheld with key-free relationship_failures; readable links remain available. Updating an edge still requires readable endpoints. Unlink by relationship_id remains available during outages.",
|
|
280
|
+
description: "[list_links, source records] Omit or pass null for the first bounded page, then pass next_cursor until it is null. Stop automatic pagination on record_failures without a code; the cursor retains those failed sources for an explicit retry. A failure with code 'withheld' is a source deliberately keeping the record private (error is its reason): its links are not missing, it is never retried, and pagination continues. Pages may be short or empty while next_cursor exists. Merge repeated links across pages by (relationship_type, direction, entity_type, key), keeping the newest occurred_at. Numeric entity_id calls retain limit/offset pagination; source pages bound limit to 100. Authored relationships are permission checked at both endpoints. counts_by_type describes the visible page (counts_scope: page), not a global total. Source pages reject source, confidence_min and include_deleted filters, which cannot be applied to live links. Source reads share a 20 second page deadline. Unavailable endpoints are withheld with key-free relationship_failures; readable links remain available. Updating an edge still requires readable endpoints. Unlink by relationship_id remains available during outages.",
|
|
281
281
|
})),
|
|
282
282
|
automation_source: typebox_1.Type.Optional(AutomationSource),
|
|
283
283
|
});
|
|
@@ -412,6 +412,14 @@ const RelationshipReadFailureSchema = typebox_1.Type.Object({
|
|
|
412
412
|
relationship_id: typebox_1.Type.Integer(),
|
|
413
413
|
code: typebox_1.Type.String(),
|
|
414
414
|
});
|
|
415
|
+
/** A feed of a source-backed record's live read that returned no rows. */
|
|
416
|
+
exports.SourceReadFailureSchema = typebox_1.Type.Object({
|
|
417
|
+
feed_id: typebox_1.Type.Integer(),
|
|
418
|
+
error: typebox_1.Type.String(),
|
|
419
|
+
code: typebox_1.Type.Optional(typebox_1.Type.Literal("withheld", {
|
|
420
|
+
description: "The source deliberately withholds this record and `error` is its reason. Its items are private, not missing; it is never retained for retry.",
|
|
421
|
+
})),
|
|
422
|
+
});
|
|
415
423
|
exports.ManageEntityResultSchema = typebox_1.Type.Union([
|
|
416
424
|
typebox_1.Type.Object({
|
|
417
425
|
action: typebox_1.Type.Literal("create"),
|
|
@@ -537,7 +545,7 @@ exports.ManageEntityResultSchema = typebox_1.Type.Union([
|
|
|
537
545
|
occurred_at: typebox_1.Type.String(),
|
|
538
546
|
source_url: typebox_1.Type.Union([typebox_1.Type.String(), typebox_1.Type.Null()]),
|
|
539
547
|
})),
|
|
540
|
-
record_failures: typebox_1.Type.Array(
|
|
548
|
+
record_failures: typebox_1.Type.Array(exports.SourceReadFailureSchema),
|
|
541
549
|
next_cursor: typebox_1.Type.Optional(typebox_1.Type.Union([typebox_1.Type.String(), typebox_1.Type.Null()])),
|
|
542
550
|
}),
|
|
543
551
|
typebox_1.Type.Object({
|
|
@@ -11,8 +11,12 @@
|
|
|
11
11
|
*/
|
|
12
12
|
import { type Static } from "@sinclair/typebox";
|
|
13
13
|
import type { FlatActionInput } from "./action-input";
|
|
14
|
+
/** Bounds on `{ name }` entries in `entity_ids`; the handler enforces the count. */
|
|
15
|
+
export declare const MAX_ENTITY_NAMES = 20;
|
|
14
16
|
export declare const SaveContentSchema: import("@sinclair/typebox").TObject<{
|
|
15
|
-
entity_ids: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TArray<import("@sinclair/typebox").
|
|
17
|
+
entity_ids: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TArray<import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TInteger, import("@sinclair/typebox").TObject<{
|
|
18
|
+
name: import("@sinclair/typebox").TString;
|
|
19
|
+
}>]>>>;
|
|
16
20
|
content: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
17
21
|
title: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
18
22
|
author: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
@@ -32,6 +36,12 @@ export declare const SaveContentSchema: import("@sinclair/typebox").TObject<{
|
|
|
32
36
|
}>>;
|
|
33
37
|
}>;
|
|
34
38
|
export type SaveContentArgs = Static<typeof SaveContentSchema>;
|
|
39
|
+
/** A `{ name }` entry from `entity_ids` that did not link, as returned in the save result's `unlinked`. */
|
|
40
|
+
export declare const UnlinkedEntityNameSchema: import("@sinclair/typebox").TObject<{
|
|
41
|
+
name: import("@sinclair/typebox").TString;
|
|
42
|
+
reason: import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TLiteral<"not_found">, import("@sinclair/typebox").TLiteral<"ambiguous">, import("@sinclair/typebox").TLiteral<"not_writable">]>;
|
|
43
|
+
}>;
|
|
44
|
+
export type UnlinkedEntityName = Static<typeof UnlinkedEntityNameSchema>;
|
|
35
45
|
/**
|
|
36
46
|
* `client.knowledge.save` input. The schema leaves every field optional
|
|
37
47
|
* because `saveContent` resolves the requirement per `payload_type`:
|
|
@@ -11,11 +11,23 @@
|
|
|
11
11
|
* connector isolate lane can bundle it (`packages/connector-sdk/AGENTS.md`).
|
|
12
12
|
*/
|
|
13
13
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
-
exports.SaveContentSchema = void 0;
|
|
14
|
+
exports.UnlinkedEntityNameSchema = exports.SaveContentSchema = exports.MAX_ENTITY_NAMES = void 0;
|
|
15
15
|
const typebox_1 = require("@sinclair/typebox");
|
|
16
|
+
/** Bounds on `{ name }` entries in `entity_ids`; the handler enforces the count. */
|
|
17
|
+
exports.MAX_ENTITY_NAMES = 20;
|
|
18
|
+
const MAX_ENTITY_NAME_LENGTH = 256;
|
|
16
19
|
exports.SaveContentSchema = typebox_1.Type.Object({
|
|
17
|
-
entity_ids: typebox_1.Type.Optional(typebox_1.Type.Array(typebox_1.Type.
|
|
18
|
-
|
|
20
|
+
entity_ids: typebox_1.Type.Optional(typebox_1.Type.Array(typebox_1.Type.Union([
|
|
21
|
+
typebox_1.Type.Integer({ minimum: 1 }),
|
|
22
|
+
typebox_1.Type.Object({
|
|
23
|
+
name: typebox_1.Type.String({
|
|
24
|
+
minLength: 1,
|
|
25
|
+
maxLength: MAX_ENTITY_NAME_LENGTH,
|
|
26
|
+
description: "The record's exact full name: a person's full name, owner/repo for a repository.",
|
|
27
|
+
}),
|
|
28
|
+
}, { additionalProperties: false }),
|
|
29
|
+
]), {
|
|
30
|
+
description: `Records this content is about. Each entry is a record id, or { name } with the record's exact full name. A name links only when exactly one record in this workspace has that name; otherwise it is returned in \`unlinked\` and the content is still saved. Reference only records the content is substantially about, at most ${exports.MAX_ENTITY_NAMES} names. Omit for org-scoped content.`,
|
|
19
31
|
})),
|
|
20
32
|
content: typebox_1.Type.Optional(typebox_1.Type.String({
|
|
21
33
|
description: "The text content to save. Required for text/markdown payload types.",
|
|
@@ -69,4 +81,14 @@ exports.SaveContentSchema = typebox_1.Type.Object({
|
|
|
69
81
|
description: "Attribution source when save is triggered by an Automation reaction",
|
|
70
82
|
})),
|
|
71
83
|
});
|
|
84
|
+
/** A `{ name }` entry from `entity_ids` that did not link, as returned in the save result's `unlinked`. */
|
|
85
|
+
exports.UnlinkedEntityNameSchema = typebox_1.Type.Object({
|
|
86
|
+
name: typebox_1.Type.String(),
|
|
87
|
+
reason: typebox_1.Type.Union([
|
|
88
|
+
typebox_1.Type.Literal("not_found"),
|
|
89
|
+
typebox_1.Type.Literal("ambiguous"),
|
|
90
|
+
// Only on a replay of a save stored before members could link records (Nov 2026).
|
|
91
|
+
typebox_1.Type.Literal("not_writable"),
|
|
92
|
+
]),
|
|
93
|
+
});
|
|
72
94
|
//# sourceMappingURL=save-memory.js.map
|
|
@@ -38,7 +38,7 @@ exports.SearchSchema = typebox_1.Type.Object({
|
|
|
38
38
|
description: "Filter by category metadata field",
|
|
39
39
|
})),
|
|
40
40
|
fuzzy: typebox_1.Type.Optional(typebox_1.Type.Boolean({
|
|
41
|
-
description: "Enable fuzzy name matching",
|
|
41
|
+
description: "Enable fuzzy name matching. When false, an entity matches only on its exact name or an exact identifier (case-insensitive); no partial or similar names.",
|
|
42
42
|
default: true,
|
|
43
43
|
})),
|
|
44
44
|
min_similarity: typebox_1.Type.Optional(typebox_1.Type.Number({
|
|
@@ -53,6 +53,18 @@ export declare function normalizeCredential<C extends BaseCredential = BaseCrede
|
|
|
53
53
|
export declare function readCredentialStore<C extends BaseCredential = BaseCredential>(file: string, defaultContextName: string): Promise<CredentialStore<C>>;
|
|
54
54
|
/** Read one context's credential (null when absent/corrupt). */
|
|
55
55
|
export declare function readContextCredential<C extends BaseCredential = BaseCredential>(file: string, contextName: string, defaultContextName: string): Promise<C | null>;
|
|
56
|
+
/**
|
|
57
|
+
* Atomically write `data` to `file` with 0600 perms. Writes to a sibling temp
|
|
58
|
+
* file (same dir, so `rename` is on the same filesystem and therefore atomic on
|
|
59
|
+
* POSIX), chmods the temp BEFORE the rename so the published file never has a
|
|
60
|
+
* window of looser perms, then renames over the target. This makes concurrent
|
|
61
|
+
* writers (CLI `lobu login` + the server's token-refresh write-back) safe: each
|
|
62
|
+
* writer commits its whole-file image in a single atomic `rename`, so a reader
|
|
63
|
+
* always sees one writer's complete file — never a half-written / interleaved
|
|
64
|
+
* one. (Last-writer-wins on the rename; we don't merge, but neither writer can
|
|
65
|
+
* corrupt the store.)
|
|
66
|
+
*/
|
|
67
|
+
export declare function atomicWriteFile(file: string, data: string): Promise<void>;
|
|
56
68
|
/**
|
|
57
69
|
* Write one context's credential into the store, preserving other contexts.
|
|
58
70
|
* The write is atomic (temp-file + `rename`) so a concurrent writer (e.g. the
|
|
@@ -16,6 +16,7 @@ exports.CREDENTIAL_REFRESH_BUFFER_MS = void 0;
|
|
|
16
16
|
exports.normalizeCredential = normalizeCredential;
|
|
17
17
|
exports.readCredentialStore = readCredentialStore;
|
|
18
18
|
exports.readContextCredential = readContextCredential;
|
|
19
|
+
exports.atomicWriteFile = atomicWriteFile;
|
|
19
20
|
exports.writeContextCredential = writeContextCredential;
|
|
20
21
|
exports.deleteContextCredential = deleteContextCredential;
|
|
21
22
|
exports.credentialNeedsRefresh = credentialNeedsRefresh;
|
|
@@ -179,7 +179,7 @@ exports.AGENT_ERRORS = {
|
|
|
179
179
|
// The provider's own finish_reason string is not useful to an end user
|
|
180
180
|
// ("function_call_filter: MALFORMED_FUNCTION_CALL"), so unlike the other
|
|
181
181
|
// PROVIDER_* entries this one carries its own text and does NOT relay the
|
|
182
|
-
// upstream blob. The raw message stays in the logs
|
|
182
|
+
// upstream blob. The raw message stays in the logs.
|
|
183
183
|
[AgentErrorCode.PROVIDER_TOOL_CALL_FAILED]: {
|
|
184
184
|
message: "The model provider rejected its own tool call and ended the turn. This is usually temporary — please try again.",
|
|
185
185
|
cta: "none",
|
|
@@ -241,7 +241,7 @@ exports.PROVIDER_BALANCE_EXHAUSTED = /credit balance is too low|insufficient (?:
|
|
|
241
241
|
* Keep windowed wording ONLY. These classify as quota, but they often clear
|
|
242
242
|
* within the minute, so nothing may treat them as a balance wall.
|
|
243
243
|
*/
|
|
244
|
-
exports.PROVIDER_WINDOWED_QUOTA = /limit exhausted|usage limit|rate[-\s]?limit|quota (?:exceeded|exhausted)|too many requests|\b429\b|resource_exhausted/i;
|
|
244
|
+
exports.PROVIDER_WINDOWED_QUOTA = /limit exhausted|usage limit|(?:you've|you have) hit your weekly limit\b|rate[-\s]?limit|quota (?:exceeded|exhausted)|too many requests|\b429\b|resource_exhausted/i;
|
|
245
245
|
/** Parse an `AgentErrorCode` from an unknown value (payload/DB boundary). */
|
|
246
246
|
function toAgentErrorCode(value) {
|
|
247
247
|
if (typeof value !== "string")
|
|
@@ -236,6 +236,11 @@ export interface WorkerTokenOptions {
|
|
|
236
236
|
nixPackages?: string[];
|
|
237
237
|
}
|
|
238
238
|
export declare function generateWorkerToken(userId: string, conversationId: string, deploymentName: string, options: WorkerTokenOptions): string;
|
|
239
|
+
/** Mint a session bearer and advertise the same lifetime the verifier enforces. */
|
|
240
|
+
export declare function generateWorkerTokenWithExpiry(userId: string, conversationId: string, deploymentName: string, options: WorkerTokenOptions): {
|
|
241
|
+
token: string;
|
|
242
|
+
expiresAt: number;
|
|
243
|
+
};
|
|
239
244
|
/**
|
|
240
245
|
* Mint deployment-lifetime worker and proxy credentials with one revocation
|
|
241
246
|
* identity. Revoking the deployment token must also stop its egress.
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.CHAT_TURN_ACCESS = void 0;
|
|
4
4
|
exports.looksLikeWorkerToken = looksLikeWorkerToken;
|
|
5
5
|
exports.generateWorkerToken = generateWorkerToken;
|
|
6
|
+
exports.generateWorkerTokenWithExpiry = generateWorkerTokenWithExpiry;
|
|
6
7
|
exports.generateWorkerTokenPair = generateWorkerTokenPair;
|
|
7
8
|
exports.mintGatewayMcpToken = mintGatewayMcpToken;
|
|
8
9
|
exports.verifyWorkerToken = verifyWorkerToken;
|
|
@@ -32,7 +33,7 @@ exports.CHAT_TURN_ACCESS = [
|
|
|
32
33
|
"public_visitor",
|
|
33
34
|
"reply_only",
|
|
34
35
|
];
|
|
35
|
-
function generateToken(userId, conversationId, deploymentName, options, tokenKind, jti = (0, node_crypto_1.randomUUID)()) {
|
|
36
|
+
function generateToken(userId, conversationId, deploymentName, options, tokenKind, jti = (0, node_crypto_1.randomUUID)(), timestamp = Date.now()) {
|
|
36
37
|
if (!options.channelId) {
|
|
37
38
|
throw new Error("channelId is required for worker token generation");
|
|
38
39
|
}
|
|
@@ -47,7 +48,7 @@ function generateToken(userId, conversationId, deploymentName, options, tokenKin
|
|
|
47
48
|
connectionId: options.connectionId,
|
|
48
49
|
responseThreadId: options.responseThreadId,
|
|
49
50
|
deploymentName,
|
|
50
|
-
timestamp
|
|
51
|
+
timestamp,
|
|
51
52
|
platform: options.platform,
|
|
52
53
|
source: options.source,
|
|
53
54
|
executionMode: options.executionMode,
|
|
@@ -72,6 +73,14 @@ function generateToken(userId, conversationId, deploymentName, options, tokenKin
|
|
|
72
73
|
function generateWorkerToken(userId, conversationId, deploymentName, options) {
|
|
73
74
|
return generateToken(userId, conversationId, deploymentName, options, "worker");
|
|
74
75
|
}
|
|
76
|
+
/** Mint a session bearer and advertise the same lifetime the verifier enforces. */
|
|
77
|
+
function generateWorkerTokenWithExpiry(userId, conversationId, deploymentName, options) {
|
|
78
|
+
const issuedAt = Date.now();
|
|
79
|
+
return {
|
|
80
|
+
token: generateToken(userId, conversationId, deploymentName, options, "worker", (0, node_crypto_1.randomUUID)(), issuedAt),
|
|
81
|
+
expiresAt: workerTokenExpiresAt(issuedAt),
|
|
82
|
+
};
|
|
83
|
+
}
|
|
75
84
|
/**
|
|
76
85
|
* Mint deployment-lifetime worker and proxy credentials with one revocation
|
|
77
86
|
* identity. Revoking the deployment token must also stop its egress.
|
|
@@ -108,6 +117,9 @@ function parsePositiveIntEnv(name, fallback, allowZero = false) {
|
|
|
108
117
|
return fallback;
|
|
109
118
|
return raw;
|
|
110
119
|
}
|
|
120
|
+
function workerTokenExpiresAt(issuedAt) {
|
|
121
|
+
return (issuedAt + parsePositiveIntEnv("WORKER_TOKEN_TTL_MS", 2 * 60 * 60 * 1000));
|
|
122
|
+
}
|
|
111
123
|
/**
|
|
112
124
|
* Verify and decrypt a worker authentication token
|
|
113
125
|
*/
|
|
@@ -273,10 +285,9 @@ function verifyToken(token, expectedKind) {
|
|
|
273
285
|
// WORKER_TOKEN_CLOCK_SKEW_MS. Tokens timestamped further in the future
|
|
274
286
|
// than the skew are rejected too — otherwise forward drift would grant
|
|
275
287
|
// an unbounded validity window.
|
|
276
|
-
const ttl = parsePositiveIntEnv("WORKER_TOKEN_TTL_MS", 2 * 60 * 60 * 1000);
|
|
277
288
|
const skewMs = parsePositiveIntEnv("WORKER_TOKEN_CLOCK_SKEW_MS", 30 * 1000, true);
|
|
278
289
|
const age = Date.now() - data.timestamp;
|
|
279
|
-
if (
|
|
290
|
+
if (Date.now() > workerTokenExpiresAt(data.timestamp) + skewMs) {
|
|
280
291
|
logger.error("Worker token rejected: expired");
|
|
281
292
|
return null;
|
|
282
293
|
}
|