@nuanu-ai/agentbrowse 0.2.46 → 0.2.48
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/README.md +69 -10
- package/dist/agentpay-gateway.d.ts +9 -0
- package/dist/agentpay-gateway.d.ts.map +1 -1
- package/dist/agentpay-gateway.js +30 -0
- package/dist/agentpay-stagehand-llm.d.ts.map +1 -1
- package/dist/agentpay-stagehand-llm.js +9 -1
- package/dist/command-api-tracing.d.ts +19 -0
- package/dist/command-api-tracing.d.ts.map +1 -0
- package/dist/command-api-tracing.js +137 -0
- package/dist/commands/act.d.ts.map +1 -1
- package/dist/commands/act.js +822 -670
- package/dist/commands/act.test-harness.d.ts +6 -0
- package/dist/commands/act.test-harness.d.ts.map +1 -1
- package/dist/commands/act.test-harness.js +44 -1
- package/dist/commands/action-acceptance.d.ts.map +1 -1
- package/dist/commands/action-acceptance.js +115 -0
- package/dist/commands/captcha-solve.d.ts.map +1 -1
- package/dist/commands/captcha-solve.js +83 -16
- package/dist/commands/click-action-executor.d.ts +0 -1
- package/dist/commands/click-action-executor.d.ts.map +1 -1
- package/dist/commands/click-action-executor.js +31 -77
- package/dist/commands/close.d.ts +3 -3
- package/dist/commands/close.d.ts.map +1 -1
- package/dist/commands/close.js +178 -0
- package/dist/commands/descriptor-validation.d.ts.map +1 -1
- package/dist/commands/descriptor-validation.js +75 -57
- package/dist/commands/end-session.d.ts +25 -0
- package/dist/commands/end-session.d.ts.map +1 -0
- package/dist/commands/end-session.js +161 -0
- package/dist/commands/extract-stagehand-executor.js +1 -1
- package/dist/commands/extract.d.ts.map +1 -1
- package/dist/commands/extract.js +339 -202
- package/dist/commands/fill-secret.d.ts +3 -3
- package/dist/commands/fill-secret.d.ts.map +1 -1
- package/dist/commands/fill-secret.js +419 -234
- package/dist/commands/get-secrets-catalog.d.ts.map +1 -1
- package/dist/commands/get-secrets-catalog.js +66 -5
- package/dist/commands/interaction-kernel.d.ts +46 -0
- package/dist/commands/interaction-kernel.d.ts.map +1 -0
- package/dist/commands/interaction-kernel.js +215 -0
- package/dist/commands/launch.d.ts +0 -2
- package/dist/commands/launch.d.ts.map +1 -1
- package/dist/commands/launch.js +109 -17
- package/dist/commands/navigate.d.ts.map +1 -1
- package/dist/commands/navigate.js +188 -45
- package/dist/commands/observe-accessibility.d.ts.map +1 -1
- package/dist/commands/observe-accessibility.js +50 -39
- package/dist/commands/observe-dom-label-contract.d.ts.map +1 -1
- package/dist/commands/observe-dom-label-contract.js +5 -0
- package/dist/commands/observe-inventory.d.ts +13 -0
- package/dist/commands/observe-inventory.d.ts.map +1 -1
- package/dist/commands/observe-inventory.js +320 -65
- package/dist/commands/observe-persistence.d.ts.map +1 -1
- package/dist/commands/observe-persistence.js +3 -0
- package/dist/commands/observe-projection.d.ts +1 -0
- package/dist/commands/observe-projection.d.ts.map +1 -1
- package/dist/commands/observe-projection.js +7 -2
- package/dist/commands/observe-protected.d.ts +1 -0
- package/dist/commands/observe-protected.d.ts.map +1 -1
- package/dist/commands/observe-protected.js +9 -4
- package/dist/commands/observe-semantics.d.ts.map +1 -1
- package/dist/commands/observe-semantics.js +5 -2
- package/dist/commands/observe-stagehand.d.ts +1 -0
- package/dist/commands/observe-stagehand.d.ts.map +1 -1
- package/dist/commands/observe-stagehand.js +2 -0
- package/dist/commands/observe.d.ts +2 -0
- package/dist/commands/observe.d.ts.map +1 -1
- package/dist/commands/observe.js +387 -203
- package/dist/commands/observe.test-harness.d.ts +8 -0
- package/dist/commands/observe.test-harness.d.ts.map +1 -1
- package/dist/commands/observe.test-harness.js +48 -1
- package/dist/commands/poll-secret.d.ts +6 -0
- package/dist/commands/poll-secret.d.ts.map +1 -0
- package/dist/commands/poll-secret.js +159 -0
- package/dist/commands/request-secret.d.ts +6 -0
- package/dist/commands/request-secret.d.ts.map +1 -0
- package/dist/commands/request-secret.js +284 -0
- package/dist/commands/screenshot.d.ts.map +1 -1
- package/dist/commands/screenshot.js +172 -7
- package/dist/commands/select-action-executor.d.ts.map +1 -1
- package/dist/commands/semantic-observe.d.ts +4 -0
- package/dist/commands/semantic-observe.d.ts.map +1 -1
- package/dist/commands/semantic-observe.js +388 -17
- package/dist/commands/start-session.d.ts +31 -0
- package/dist/commands/start-session.d.ts.map +1 -0
- package/dist/commands/start-session.js +347 -0
- package/dist/commands/status.d.ts +2 -1
- package/dist/commands/status.d.ts.map +1 -1
- package/dist/commands/status.js +166 -144
- package/dist/control-semantics.d.ts +1 -0
- package/dist/control-semantics.d.ts.map +1 -1
- package/dist/control-semantics.js +51 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +144 -45
- package/dist/otel-exporter.d.ts +58 -0
- package/dist/otel-exporter.d.ts.map +1 -0
- package/dist/otel-exporter.js +263 -0
- package/dist/otel-projector.d.ts +75 -0
- package/dist/otel-projector.d.ts.map +1 -0
- package/dist/otel-projector.js +409 -0
- package/dist/owned-browser.d.ts +1 -1
- package/dist/owned-browser.d.ts.map +1 -1
- package/dist/owned-browser.js +13 -1
- package/dist/owned-process.d.ts +2 -0
- package/dist/owned-process.d.ts.map +1 -1
- package/dist/owned-process.js +7 -3
- package/dist/playwright-runtime.d.ts +1 -1
- package/dist/playwright-runtime.d.ts.map +1 -1
- package/dist/playwright-runtime.js +8 -8
- package/dist/run-observability.d.ts +25 -0
- package/dist/run-observability.d.ts.map +1 -0
- package/dist/run-observability.js +115 -0
- package/dist/run-store.d.ts +274 -0
- package/dist/run-store.d.ts.map +1 -0
- package/dist/run-store.js +631 -0
- package/dist/runtime-metrics.d.ts +27 -0
- package/dist/runtime-metrics.d.ts.map +1 -0
- package/dist/runtime-metrics.js +66 -0
- package/dist/runtime-page-state.d.ts +11 -0
- package/dist/runtime-page-state.d.ts.map +1 -0
- package/dist/runtime-page-state.js +62 -0
- package/dist/runtime-protected-state.d.ts +16 -0
- package/dist/runtime-protected-state.d.ts.map +1 -0
- package/dist/runtime-protected-state.js +157 -0
- package/dist/runtime-state.d.ts +10 -44
- package/dist/runtime-state.d.ts.map +1 -1
- package/dist/runtime-state.js +57 -222
- package/dist/secrets/backend.d.ts +65 -16
- package/dist/secrets/backend.d.ts.map +1 -1
- package/dist/secrets/backend.js +135 -95
- package/dist/secrets/catalog-sync.d.ts.map +1 -1
- package/dist/secrets/catalog-sync.js +4 -1
- package/dist/secrets/form-matcher.d.ts +5 -5
- package/dist/secrets/form-matcher.d.ts.map +1 -1
- package/dist/secrets/form-matcher.js +292 -164
- package/dist/secrets/intent-output.d.ts +6 -10
- package/dist/secrets/intent-output.d.ts.map +1 -1
- package/dist/secrets/intent-output.js +4 -58
- package/dist/secrets/mock-agentpay-cabinet.d.ts +38 -27
- package/dist/secrets/mock-agentpay-cabinet.d.ts.map +1 -1
- package/dist/secrets/mock-agentpay-cabinet.js +177 -111
- package/dist/secrets/protected-artifact-guard.d.ts +2 -2
- package/dist/secrets/protected-artifact-guard.d.ts.map +1 -1
- package/dist/secrets/protected-artifact-guard.js +2 -2
- package/dist/secrets/protected-bindings.d.ts +1 -1
- package/dist/secrets/protected-bindings.d.ts.map +1 -1
- package/dist/secrets/protected-bindings.js +6 -0
- package/dist/secrets/protected-field-semantics.d.ts +9 -0
- package/dist/secrets/protected-field-semantics.d.ts.map +1 -0
- package/dist/secrets/protected-field-semantics.js +154 -0
- package/dist/secrets/protected-field-values.d.ts.map +1 -1
- package/dist/secrets/protected-field-values.js +3 -3
- package/dist/secrets/protected-fill.d.ts +1 -1
- package/dist/secrets/protected-fill.d.ts.map +1 -1
- package/dist/secrets/protected-fill.js +45 -149
- package/dist/secrets/protected-value-adapters.d.ts +2 -1
- package/dist/secrets/protected-value-adapters.d.ts.map +1 -1
- package/dist/secrets/protected-value-adapters.js +80 -1
- package/dist/secrets/request-output.d.ts +11 -0
- package/dist/secrets/request-output.d.ts.map +1 -0
- package/dist/secrets/request-output.js +75 -0
- package/dist/secrets/types.d.ts +15 -9
- package/dist/secrets/types.d.ts.map +1 -1
- package/dist/secrets/types.js +3 -0
- package/dist/session-event-exporter.d.ts +36 -0
- package/dist/session-event-exporter.d.ts.map +1 -0
- package/dist/session-event-exporter.js +428 -0
- package/dist/session.d.ts +16 -7
- package/dist/session.d.ts.map +1 -1
- package/dist/session.js +150 -23
- package/dist/sessions-backend.d.ts +354 -0
- package/dist/sessions-backend.d.ts.map +1 -0
- package/dist/sessions-backend.js +126 -0
- package/dist/solver/browser-launcher.d.ts +1 -1
- package/dist/solver/browser-launcher.d.ts.map +1 -1
- package/dist/solver/browser-launcher.js +39 -13
- package/dist/solver/captcha-solver.d.ts.map +1 -1
- package/dist/solver/captcha-solver.js +8 -1
- package/dist/solver/types.d.ts +1 -0
- package/dist/solver/types.d.ts.map +1 -1
- package/dist/workflow-session-completion.d.ts +33 -0
- package/dist/workflow-session-completion.d.ts.map +1 -0
- package/dist/workflow-session-completion.js +156 -0
- package/package.json +9 -1
- package/dist/commands/create-intent.d.ts +0 -6
- package/dist/commands/create-intent.d.ts.map +0 -1
- package/dist/commands/create-intent.js +0 -75
- package/dist/commands/poll-intent.d.ts +0 -6
- package/dist/commands/poll-intent.d.ts.map +0 -1
- package/dist/commands/poll-intent.js +0 -57
package/dist/runtime-state.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { resolveCachedSecretCatalogForHost } from './secrets/catalog-applicability.js';
|
|
2
|
-
import { logicalProtectedBindingKey } from './secrets/protected-bindings.js';
|
|
3
2
|
import { inferAcceptancePolicyFromFacts, inferAllowedActionsFromFacts, inferAvailabilityFromFacts, inferControlFamilyFromFacts, } from './control-semantics.js';
|
|
4
3
|
export function locatorCandidateKey(candidate) {
|
|
5
4
|
return [
|
|
@@ -35,6 +34,9 @@ function inferAllowedActions(descriptor) {
|
|
|
35
34
|
inputName: descriptor.inputName,
|
|
36
35
|
inputType: descriptor.inputType,
|
|
37
36
|
autocomplete: descriptor.autocomplete,
|
|
37
|
+
ariaAutocomplete: descriptor.ariaAutocomplete,
|
|
38
|
+
surfaceKind: descriptor.surfaceKind,
|
|
39
|
+
controlsSurfaceSelector: descriptor.controlsSurfaceSelector,
|
|
38
40
|
states: descriptor.semantics?.states,
|
|
39
41
|
structure: descriptor.structure,
|
|
40
42
|
legacyMethod,
|
|
@@ -50,6 +52,9 @@ function inferControlFamily(descriptor, allowedActions) {
|
|
|
50
52
|
inputName: descriptor.inputName,
|
|
51
53
|
inputType: descriptor.inputType,
|
|
52
54
|
autocomplete: descriptor.autocomplete,
|
|
55
|
+
ariaAutocomplete: descriptor.ariaAutocomplete,
|
|
56
|
+
surfaceKind: descriptor.surfaceKind,
|
|
57
|
+
controlsSurfaceSelector: descriptor.controlsSurfaceSelector,
|
|
53
58
|
states: descriptor.semantics?.states,
|
|
54
59
|
structure: descriptor.structure,
|
|
55
60
|
legacyMethod: inferLegacyActionMethod(descriptor),
|
|
@@ -65,6 +70,9 @@ function inferAcceptancePolicy(descriptor, allowedActions) {
|
|
|
65
70
|
inputName: descriptor.inputName,
|
|
66
71
|
inputType: descriptor.inputType,
|
|
67
72
|
autocomplete: descriptor.autocomplete,
|
|
73
|
+
ariaAutocomplete: descriptor.ariaAutocomplete,
|
|
74
|
+
surfaceKind: descriptor.surfaceKind,
|
|
75
|
+
controlsSurfaceSelector: descriptor.controlsSurfaceSelector,
|
|
68
76
|
states: descriptor.semantics?.states,
|
|
69
77
|
structure: descriptor.structure,
|
|
70
78
|
legacyMethod: inferLegacyActionMethod(descriptor),
|
|
@@ -106,7 +114,7 @@ function targetIdentity(descriptor, options = {}) {
|
|
|
106
114
|
(descriptor.frameUrl?.trim() ? `url:${descriptor.frameUrl.trim()}` : 'top');
|
|
107
115
|
const pageKey = descriptor.pageSignature ?? descriptor.pageRef;
|
|
108
116
|
const familyKey = descriptor.controlFamily ?? '';
|
|
109
|
-
const surfaceKey = options.ignoreSurfaceRef ? '' : descriptor.surfaceRef ?? '';
|
|
117
|
+
const surfaceKey = options.ignoreSurfaceRef ? '' : (descriptor.surfaceRef ?? '');
|
|
110
118
|
const structureKey = descriptor.structure
|
|
111
119
|
? [
|
|
112
120
|
descriptor.structure.family ?? '',
|
|
@@ -132,7 +140,7 @@ function targetIdentity(descriptor, options = {}) {
|
|
|
132
140
|
}
|
|
133
141
|
return `${pageKey}|${frameKey}|family|${familyKey}|surface|${surfaceKey}|structure|${structureKey}|fallback|${descriptor.kind ?? ''}|${descriptor.label ?? ''}`;
|
|
134
142
|
}
|
|
135
|
-
function createPayloadBudgetMetrics() {
|
|
143
|
+
export function createPayloadBudgetMetrics() {
|
|
136
144
|
return {
|
|
137
145
|
observeRerankCandidatesSeen: 0,
|
|
138
146
|
observeRerankCandidatesSent: 0,
|
|
@@ -142,7 +150,7 @@ function createPayloadBudgetMetrics() {
|
|
|
142
150
|
protectedBindingsSent: 0,
|
|
143
151
|
};
|
|
144
152
|
}
|
|
145
|
-
function createLlmUsageBucket() {
|
|
153
|
+
export function createLlmUsageBucket() {
|
|
146
154
|
return {
|
|
147
155
|
calls: 0,
|
|
148
156
|
inputChars: 0,
|
|
@@ -153,7 +161,7 @@ function createLlmUsageBucket() {
|
|
|
153
161
|
reasoningTokens: 0,
|
|
154
162
|
};
|
|
155
163
|
}
|
|
156
|
-
function ensureMetricsExtensions(metrics) {
|
|
164
|
+
export function ensureMetricsExtensions(metrics) {
|
|
157
165
|
metrics.llmCalls ??= 0;
|
|
158
166
|
metrics.llmPromptTokens ??= 0;
|
|
159
167
|
metrics.llmCompletionTokens ??= 0;
|
|
@@ -239,7 +247,7 @@ export function createRuntimeState(initialPage = {}) {
|
|
|
239
247
|
targets: {},
|
|
240
248
|
secretCatalogByHost: {},
|
|
241
249
|
fillableForms: {},
|
|
242
|
-
|
|
250
|
+
secretRequestSnapshots: {},
|
|
243
251
|
protectedExposureByPage: {},
|
|
244
252
|
counters: {
|
|
245
253
|
nextPage: pageRef === 'p0' ? 1 : 0,
|
|
@@ -277,7 +285,7 @@ export function ensureRuntimeState(session) {
|
|
|
277
285
|
session.runtime.surfaces ??= {};
|
|
278
286
|
session.runtime.secretCatalogByHost ??= {};
|
|
279
287
|
session.runtime.fillableForms ??= {};
|
|
280
|
-
session.runtime.
|
|
288
|
+
session.runtime.secretRequestSnapshots ??= {};
|
|
281
289
|
session.runtime.protectedExposureByPage ??= {};
|
|
282
290
|
session.runtime.counters.nextPage ??= 1;
|
|
283
291
|
session.runtime.counters.nextSurface ??= 1;
|
|
@@ -308,67 +316,6 @@ export function ensureRuntimeState(session) {
|
|
|
308
316
|
ensureMetricsExtensions(session.runtime.metrics);
|
|
309
317
|
return session.runtime;
|
|
310
318
|
}
|
|
311
|
-
export function registerPage(session, page = {}) {
|
|
312
|
-
const runtime = ensureRuntimeState(session);
|
|
313
|
-
const pageRef = page.pageRef ?? `p${runtime.counters.nextPage++}`;
|
|
314
|
-
const now = new Date().toISOString();
|
|
315
|
-
const existing = runtime.pages[pageRef];
|
|
316
|
-
const nextPage = {
|
|
317
|
-
pageRef,
|
|
318
|
-
createdAt: existing?.createdAt ?? now,
|
|
319
|
-
updatedAt: now,
|
|
320
|
-
url: page.url ?? existing?.url,
|
|
321
|
-
title: page.title ?? existing?.title,
|
|
322
|
-
targetId: page.targetId ?? existing?.targetId,
|
|
323
|
-
openerPageRef: page.openerPageRef ?? existing?.openerPageRef,
|
|
324
|
-
scopeEpoch: existing?.scopeEpoch ?? 0,
|
|
325
|
-
};
|
|
326
|
-
runtime.pages[pageRef] = nextPage;
|
|
327
|
-
if (page.makeCurrent !== false) {
|
|
328
|
-
runtime.currentPageRef = pageRef;
|
|
329
|
-
}
|
|
330
|
-
return nextPage;
|
|
331
|
-
}
|
|
332
|
-
export function updatePage(session, pageRef, patch) {
|
|
333
|
-
const runtime = ensureRuntimeState(session);
|
|
334
|
-
const current = runtime.pages[pageRef];
|
|
335
|
-
if (!current) {
|
|
336
|
-
throw new Error(`unknown_page_ref: ${pageRef}`);
|
|
337
|
-
}
|
|
338
|
-
const nextPage = {
|
|
339
|
-
...current,
|
|
340
|
-
...patch,
|
|
341
|
-
scopeEpoch: patch.scopeEpoch ?? current.scopeEpoch ?? 0,
|
|
342
|
-
updatedAt: new Date().toISOString(),
|
|
343
|
-
};
|
|
344
|
-
runtime.pages[pageRef] = nextPage;
|
|
345
|
-
return nextPage;
|
|
346
|
-
}
|
|
347
|
-
export function getPageScopeEpoch(session, pageRef) {
|
|
348
|
-
const runtime = ensureRuntimeState(session);
|
|
349
|
-
return runtime.pages[pageRef]?.scopeEpoch ?? 0;
|
|
350
|
-
}
|
|
351
|
-
export function bumpPageScopeEpoch(session, pageRef) {
|
|
352
|
-
const runtime = ensureRuntimeState(session);
|
|
353
|
-
const current = runtime.pages[pageRef];
|
|
354
|
-
if (!current) {
|
|
355
|
-
throw new Error(`unknown_page_ref: ${pageRef}`);
|
|
356
|
-
}
|
|
357
|
-
const nextEpoch = (current.scopeEpoch ?? 0) + 1;
|
|
358
|
-
runtime.pages[pageRef] = {
|
|
359
|
-
...current,
|
|
360
|
-
scopeEpoch: nextEpoch,
|
|
361
|
-
updatedAt: new Date().toISOString(),
|
|
362
|
-
};
|
|
363
|
-
return nextEpoch;
|
|
364
|
-
}
|
|
365
|
-
export function setCurrentPage(session, pageRef) {
|
|
366
|
-
const runtime = ensureRuntimeState(session);
|
|
367
|
-
if (!runtime.pages[pageRef]) {
|
|
368
|
-
throw new Error(`unknown_page_ref: ${pageRef}`);
|
|
369
|
-
}
|
|
370
|
-
runtime.currentPageRef = pageRef;
|
|
371
|
-
}
|
|
372
319
|
export function createTargetRef(session) {
|
|
373
320
|
const runtime = ensureRuntimeState(session);
|
|
374
321
|
return `t${runtime.counters.nextTarget++}`;
|
|
@@ -444,6 +391,7 @@ export function saveTargets(session, descriptors) {
|
|
|
444
391
|
export function replaceTargetsForPage(session, pageRef, descriptors, options = {}) {
|
|
445
392
|
const runtime = ensureRuntimeState(session);
|
|
446
393
|
const existingEntries = Object.entries(runtime.targets).filter(([, target]) => target.pageRef === pageRef);
|
|
394
|
+
const existingTargets = new Map(existingEntries);
|
|
447
395
|
const preserveExistingOnEmpty = options.preserveExistingOnEmpty !== false;
|
|
448
396
|
const preserveExisting = options.preserveExisting !== false;
|
|
449
397
|
if (descriptors.length === 0 && preserveExistingOnEmpty) {
|
|
@@ -454,13 +402,47 @@ export function replaceTargetsForPage(session, pageRef, descriptors, options = {
|
|
|
454
402
|
refs.push(ref);
|
|
455
403
|
map.set(identity, refs);
|
|
456
404
|
}
|
|
457
|
-
function
|
|
405
|
+
function ownerWorkflowBoundaryChanged(current, next) {
|
|
406
|
+
const currentOwnerRef = current.ownerRef?.trim();
|
|
407
|
+
const nextOwnerRef = next.ownerRef?.trim();
|
|
408
|
+
return Boolean(currentOwnerRef && nextOwnerRef && currentOwnerRef !== nextOwnerRef);
|
|
409
|
+
}
|
|
410
|
+
function workflowContextKey(context) {
|
|
411
|
+
if (!context) {
|
|
412
|
+
return '';
|
|
413
|
+
}
|
|
414
|
+
return ['item', 'group', 'container']
|
|
415
|
+
.map((key) => {
|
|
416
|
+
const node = context[key];
|
|
417
|
+
return node ? `${node.kind ?? ''}:${node.label ?? ''}` : '';
|
|
418
|
+
})
|
|
419
|
+
.join('|');
|
|
420
|
+
}
|
|
421
|
+
function workflowContextBoundaryChanged(current, next) {
|
|
422
|
+
const currentContextKey = workflowContextKey(current.context);
|
|
423
|
+
const nextContextKey = workflowContextKey(next.context);
|
|
424
|
+
return Boolean(currentContextKey.trim().length > 0 &&
|
|
425
|
+
nextContextKey.trim().length > 0 &&
|
|
426
|
+
currentContextKey !== nextContextKey);
|
|
427
|
+
}
|
|
428
|
+
function takeReusableTargetRef(map, identity, consumedRefs, next) {
|
|
458
429
|
const refs = map.get(identity);
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
430
|
+
if (!refs || refs.length === 0) {
|
|
431
|
+
return undefined;
|
|
432
|
+
}
|
|
433
|
+
for (let index = 0; index < refs.length; index += 1) {
|
|
434
|
+
const candidate = refs[index];
|
|
435
|
+
if (!candidate || consumedRefs.has(candidate)) {
|
|
436
|
+
continue;
|
|
437
|
+
}
|
|
438
|
+
const current = existingTargets.get(candidate);
|
|
439
|
+
if (current &&
|
|
440
|
+
(ownerWorkflowBoundaryChanged(current, next) ||
|
|
441
|
+
workflowContextBoundaryChanged(current, next))) {
|
|
442
|
+
continue;
|
|
463
443
|
}
|
|
444
|
+
refs.splice(index, 1);
|
|
445
|
+
return candidate;
|
|
464
446
|
}
|
|
465
447
|
return undefined;
|
|
466
448
|
}
|
|
@@ -480,9 +462,9 @@ export function replaceTargetsForPage(session, pageRef, descriptors, options = {
|
|
|
480
462
|
pageRef,
|
|
481
463
|
}, descriptor.ref ?? '__identity__');
|
|
482
464
|
const identity = targetIdentity(normalizedDescriptor);
|
|
483
|
-
const matchedRef =
|
|
465
|
+
const matchedRef = takeReusableTargetRef(reusableRefs, identity, reusedRefs, normalizedDescriptor) ??
|
|
484
466
|
(normalizedDescriptor.surfaceRef?.trim()
|
|
485
|
-
?
|
|
467
|
+
? takeReusableTargetRef(surfacePromotionRefs, targetIdentity(normalizedDescriptor, { ignoreSurfaceRef: true }), reusedRefs, normalizedDescriptor)
|
|
486
468
|
: undefined);
|
|
487
469
|
const ref = descriptor.ref ?? matchedRef ?? createTargetRef(session);
|
|
488
470
|
const target = normalizeTargetDescriptor(descriptor, ref);
|
|
@@ -517,88 +499,6 @@ export function getSecretCatalog(session, host) {
|
|
|
517
499
|
const runtime = ensureRuntimeState(session);
|
|
518
500
|
return resolveCachedSecretCatalogForHost(host, Object.values(runtime.secretCatalogByHost));
|
|
519
501
|
}
|
|
520
|
-
export function saveFillableForms(session, forms) {
|
|
521
|
-
const runtime = ensureRuntimeState(session);
|
|
522
|
-
for (const form of forms) {
|
|
523
|
-
runtime.fillableForms[form.fillRef] = form;
|
|
524
|
-
syncFillCounter(runtime, form.fillRef);
|
|
525
|
-
}
|
|
526
|
-
return forms.map((form) => runtime.fillableForms[form.fillRef]);
|
|
527
|
-
}
|
|
528
|
-
function fillableFormIdentity(form) {
|
|
529
|
-
const fieldsKey = [...form.fields]
|
|
530
|
-
.map((field) => logicalProtectedBindingKey(field))
|
|
531
|
-
.sort()
|
|
532
|
-
.join('|');
|
|
533
|
-
return [form.pageRef, form.scopeRef ?? '', form.purpose, fieldsKey].join('||');
|
|
534
|
-
}
|
|
535
|
-
export function replaceFillableFormsForPage(session, pageRef, forms, options = {}) {
|
|
536
|
-
const runtime = ensureRuntimeState(session);
|
|
537
|
-
const existingEntries = Object.entries(runtime.fillableForms).filter(([, form]) => form.pageRef === pageRef);
|
|
538
|
-
const preserveExistingOnEmpty = options.preserveExistingOnEmpty !== false;
|
|
539
|
-
if (forms.length === 0 && preserveExistingOnEmpty) {
|
|
540
|
-
return existingEntries.map(([, form]) => form);
|
|
541
|
-
}
|
|
542
|
-
const reusableRefs = new Map();
|
|
543
|
-
for (const [fillRef, form] of existingEntries) {
|
|
544
|
-
const identity = fillableFormIdentity(form);
|
|
545
|
-
const refs = reusableRefs.get(identity) ?? [];
|
|
546
|
-
refs.push(fillRef);
|
|
547
|
-
reusableRefs.set(identity, refs);
|
|
548
|
-
}
|
|
549
|
-
const reusedRefs = new Set();
|
|
550
|
-
const nextForms = [];
|
|
551
|
-
for (const form of forms) {
|
|
552
|
-
const identity = fillableFormIdentity(form);
|
|
553
|
-
const matchedRef = (reusableRefs.get(identity) ?? []).find((ref) => !reusedRefs.has(ref));
|
|
554
|
-
const fillRef = matchedRef ?? createFillRef(session);
|
|
555
|
-
runtime.fillableForms[fillRef] = {
|
|
556
|
-
...form,
|
|
557
|
-
fillRef,
|
|
558
|
-
};
|
|
559
|
-
syncFillCounter(runtime, fillRef);
|
|
560
|
-
reusedRefs.add(fillRef);
|
|
561
|
-
nextForms.push(runtime.fillableForms[fillRef]);
|
|
562
|
-
}
|
|
563
|
-
for (const [fillRef] of existingEntries) {
|
|
564
|
-
if (!reusedRefs.has(fillRef)) {
|
|
565
|
-
delete runtime.fillableForms[fillRef];
|
|
566
|
-
}
|
|
567
|
-
}
|
|
568
|
-
return nextForms;
|
|
569
|
-
}
|
|
570
|
-
export function getFillableForm(session, fillRef) {
|
|
571
|
-
const runtime = ensureRuntimeState(session);
|
|
572
|
-
return runtime.fillableForms[fillRef] ?? null;
|
|
573
|
-
}
|
|
574
|
-
export function saveSecretIntentSnapshot(session, snapshot) {
|
|
575
|
-
const runtime = ensureRuntimeState(session);
|
|
576
|
-
runtime.secretIntentSnapshots[snapshot.intentId] = snapshot;
|
|
577
|
-
return snapshot;
|
|
578
|
-
}
|
|
579
|
-
export function getSecretIntentSnapshot(session, intentId) {
|
|
580
|
-
const runtime = ensureRuntimeState(session);
|
|
581
|
-
return runtime.secretIntentSnapshots[intentId] ?? null;
|
|
582
|
-
}
|
|
583
|
-
export function saveProtectedExposure(session, exposure) {
|
|
584
|
-
const runtime = ensureRuntimeState(session);
|
|
585
|
-
const exposures = runtime.protectedExposureByPage ?? (runtime.protectedExposureByPage = {});
|
|
586
|
-
exposures[exposure.pageRef] = exposure;
|
|
587
|
-
return exposures[exposure.pageRef];
|
|
588
|
-
}
|
|
589
|
-
export function getProtectedExposure(session, pageRef) {
|
|
590
|
-
const runtime = ensureRuntimeState(session);
|
|
591
|
-
return runtime.protectedExposureByPage?.[pageRef] ?? null;
|
|
592
|
-
}
|
|
593
|
-
export function clearProtectedExposure(session, pageRef) {
|
|
594
|
-
const runtime = ensureRuntimeState(session);
|
|
595
|
-
if (!pageRef) {
|
|
596
|
-
runtime.protectedExposureByPage = {};
|
|
597
|
-
return;
|
|
598
|
-
}
|
|
599
|
-
const exposures = runtime.protectedExposureByPage ?? (runtime.protectedExposureByPage = {});
|
|
600
|
-
delete exposures[pageRef];
|
|
601
|
-
}
|
|
602
502
|
export function updateSurface(session, surfaceRef, patch) {
|
|
603
503
|
const runtime = ensureRuntimeState(session);
|
|
604
504
|
const current = runtime.surfaces[surfaceRef];
|
|
@@ -690,68 +590,3 @@ export function clearTargets(session, pageRef) {
|
|
|
690
590
|
}
|
|
691
591
|
}
|
|
692
592
|
}
|
|
693
|
-
export function incrementMetric(session, metric, by = 1) {
|
|
694
|
-
const runtime = ensureRuntimeState(session);
|
|
695
|
-
runtime.metrics[metric] = (runtime.metrics[metric] ?? 0) + by;
|
|
696
|
-
return runtime.metrics[metric] ?? 0;
|
|
697
|
-
}
|
|
698
|
-
export function recordActionResult(session, success, durationMs) {
|
|
699
|
-
const runtime = ensureRuntimeState(session);
|
|
700
|
-
ensureMetricsExtensions(runtime.metrics);
|
|
701
|
-
if (success) {
|
|
702
|
-
runtime.metrics.successfulActions += 1;
|
|
703
|
-
}
|
|
704
|
-
else {
|
|
705
|
-
runtime.metrics.failedActions += 1;
|
|
706
|
-
}
|
|
707
|
-
runtime.metrics.totalActionDurationMs += Math.max(0, durationMs);
|
|
708
|
-
const attempts = runtime.metrics.successfulActions + runtime.metrics.failedActions;
|
|
709
|
-
runtime.metrics.successRate = attempts === 0 ? 0 : runtime.metrics.successfulActions / attempts;
|
|
710
|
-
runtime.metrics.averageActionDurationMs =
|
|
711
|
-
attempts === 0 ? 0 : runtime.metrics.totalActionDurationMs / attempts;
|
|
712
|
-
return runtime.metrics;
|
|
713
|
-
}
|
|
714
|
-
export function recordLlmUsage(session, params) {
|
|
715
|
-
const runtime = ensureRuntimeState(session);
|
|
716
|
-
ensureMetricsExtensions(runtime.metrics);
|
|
717
|
-
const promptTokens = params.promptTokens ?? params.usage?.prompt_tokens ?? 0;
|
|
718
|
-
const completionTokens = params.completionTokens ?? params.usage?.completion_tokens ?? 0;
|
|
719
|
-
const totalTokens = params.totalTokens ??
|
|
720
|
-
params.usage?.total_tokens ??
|
|
721
|
-
(promptTokens > 0 || completionTokens > 0 ? promptTokens + completionTokens : 0);
|
|
722
|
-
const cachedInputTokens = params.cachedInputTokens ?? params.usage?.cached_input_tokens ?? 0;
|
|
723
|
-
const reasoningTokens = params.reasoningTokens ?? params.usage?.reasoning_tokens ?? 0;
|
|
724
|
-
const inputChars = params.inputChars ?? 0;
|
|
725
|
-
runtime.metrics.llmCalls = (runtime.metrics.llmCalls ?? 0) + 1;
|
|
726
|
-
runtime.metrics.llmPromptTokens = (runtime.metrics.llmPromptTokens ?? 0) + promptTokens;
|
|
727
|
-
runtime.metrics.llmCompletionTokens =
|
|
728
|
-
(runtime.metrics.llmCompletionTokens ?? 0) + completionTokens;
|
|
729
|
-
runtime.metrics.llmTotalTokens = (runtime.metrics.llmTotalTokens ?? 0) + totalTokens;
|
|
730
|
-
runtime.metrics.llmCachedInputTokens =
|
|
731
|
-
(runtime.metrics.llmCachedInputTokens ?? 0) + cachedInputTokens;
|
|
732
|
-
runtime.metrics.llmReasoningTokens = (runtime.metrics.llmReasoningTokens ?? 0) + reasoningTokens;
|
|
733
|
-
const purposeKey = params.purpose.trim().length > 0 ? params.purpose.trim() : 'unknown';
|
|
734
|
-
const bucket = runtime.metrics.llmUsageByPurpose?.[purposeKey] ?? createLlmUsageBucket();
|
|
735
|
-
bucket.calls += 1;
|
|
736
|
-
bucket.inputChars += inputChars;
|
|
737
|
-
bucket.promptTokens += promptTokens;
|
|
738
|
-
bucket.completionTokens += completionTokens;
|
|
739
|
-
bucket.totalTokens += totalTokens;
|
|
740
|
-
bucket.cachedInputTokens += cachedInputTokens;
|
|
741
|
-
bucket.reasoningTokens += reasoningTokens;
|
|
742
|
-
runtime.metrics.llmUsageByPurpose[purposeKey] = bucket;
|
|
743
|
-
return runtime.metrics;
|
|
744
|
-
}
|
|
745
|
-
export function recordPayloadBudget(session, patch) {
|
|
746
|
-
const runtime = ensureRuntimeState(session);
|
|
747
|
-
ensureMetricsExtensions(runtime.metrics);
|
|
748
|
-
const payloadBudget = runtime.metrics.payloadBudget ?? createPayloadBudgetMetrics();
|
|
749
|
-
for (const [key, value] of Object.entries(patch)) {
|
|
750
|
-
if (!Number.isFinite(value)) {
|
|
751
|
-
continue;
|
|
752
|
-
}
|
|
753
|
-
payloadBudget[key] += value ?? 0;
|
|
754
|
-
}
|
|
755
|
-
runtime.metrics.payloadBudget = payloadBudget;
|
|
756
|
-
return runtime.metrics;
|
|
757
|
-
}
|
|
@@ -1,21 +1,65 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import { type CreateRemoteSecretRequestInput } from '../sessions-backend.js';
|
|
2
|
+
import { approveMockSecretRequest, denyMockSecretRequest } from './mock-agentpay-cabinet.js';
|
|
3
|
+
import type { SecretCatalogSnapshot, SecretRequestSnapshot, StoredSecretFieldKey, StoredSecretKind } from './types.js';
|
|
4
|
+
export type SecretRequestHintField = {
|
|
5
|
+
key: StoredSecretFieldKey;
|
|
6
|
+
label?: string;
|
|
7
|
+
type?: 'text' | 'secret' | 'date' | 'number';
|
|
8
|
+
required?: boolean;
|
|
9
|
+
};
|
|
10
|
+
export type SecretRequestHint = {
|
|
11
|
+
storedSecretRef?: string;
|
|
12
|
+
credentialKey?: string;
|
|
13
|
+
credentialName?: string;
|
|
14
|
+
kind?: StoredSecretKind;
|
|
15
|
+
host?: string;
|
|
7
16
|
scopeRef?: string;
|
|
17
|
+
fields: SecretRequestHintField[];
|
|
18
|
+
};
|
|
19
|
+
export type SecretBackendSessionState = {
|
|
20
|
+
sessionId: string;
|
|
21
|
+
status: string;
|
|
22
|
+
currentRequestId: string | null;
|
|
23
|
+
lastEventSeq: number;
|
|
24
|
+
browserSessionId: string | null;
|
|
25
|
+
};
|
|
26
|
+
export interface CreateSecretRequestInput {
|
|
27
|
+
sessionId: string;
|
|
28
|
+
clientRequestId: string;
|
|
29
|
+
fillRef: string;
|
|
8
30
|
purpose: string;
|
|
9
|
-
|
|
10
|
-
|
|
31
|
+
merchantName: string;
|
|
32
|
+
page?: {
|
|
33
|
+
ref?: string;
|
|
34
|
+
url?: string;
|
|
35
|
+
title?: string;
|
|
36
|
+
};
|
|
37
|
+
secretHint: SecretRequestHint;
|
|
38
|
+
telemetry?: CreateRemoteSecretRequestInput['telemetry'];
|
|
39
|
+
run?: CreateRemoteSecretRequestInput['run'];
|
|
40
|
+
step?: CreateRemoteSecretRequestInput['step'];
|
|
11
41
|
}
|
|
12
|
-
export interface
|
|
13
|
-
|
|
42
|
+
export interface CreateSecretRequestResult {
|
|
43
|
+
snapshot: SecretRequestSnapshot;
|
|
14
44
|
reused: boolean;
|
|
45
|
+
duplicate: boolean;
|
|
46
|
+
session: SecretBackendSessionState;
|
|
47
|
+
}
|
|
48
|
+
export interface SecretRequestPollResult {
|
|
49
|
+
snapshot: SecretRequestSnapshot;
|
|
50
|
+
session: SecretBackendSessionState;
|
|
15
51
|
}
|
|
16
|
-
export interface
|
|
17
|
-
|
|
18
|
-
|
|
52
|
+
export interface ClaimSecretRequestResult {
|
|
53
|
+
requestId: string;
|
|
54
|
+
issuedAt: string;
|
|
55
|
+
expiresAt?: string;
|
|
56
|
+
secret: {
|
|
57
|
+
values: Partial<Record<StoredSecretFieldKey, string>>;
|
|
58
|
+
source: 'saved_secret' | 'saved_credential' | 'inline_response';
|
|
59
|
+
storedSecretRef?: string;
|
|
60
|
+
credentialId?: string;
|
|
61
|
+
kind?: StoredSecretKind;
|
|
62
|
+
};
|
|
19
63
|
}
|
|
20
64
|
export declare class SecretBackendDisabledError extends Error {
|
|
21
65
|
constructor(message?: string);
|
|
@@ -23,10 +67,15 @@ export declare class SecretBackendDisabledError extends Error {
|
|
|
23
67
|
export interface SecretBackend {
|
|
24
68
|
kind: 'mock' | 'agentpay_api';
|
|
25
69
|
resolveCatalogHost(urlOrHost: string): string;
|
|
26
|
-
syncSecretCatalog(urlOrHost: string): Promise<SecretCatalogSnapshot>;
|
|
27
|
-
|
|
28
|
-
|
|
70
|
+
syncSecretCatalog(sessionId: string, urlOrHost: string): Promise<SecretCatalogSnapshot>;
|
|
71
|
+
createOrReuseSecretRequest(input: CreateSecretRequestInput): Promise<CreateSecretRequestResult>;
|
|
72
|
+
getSecretRequest(sessionId: string, requestId: string): Promise<SecretRequestPollResult | null>;
|
|
73
|
+
claimSecretRequest(sessionId: string, requestId: string, claimId: string): Promise<ClaimSecretRequestResult>;
|
|
29
74
|
}
|
|
30
75
|
export declare function isMockSecretBackendEnabled(): boolean;
|
|
31
76
|
export declare function getSecretBackend(): SecretBackend;
|
|
77
|
+
export declare const __testSecretBackend: {
|
|
78
|
+
approveMockSecretRequest: typeof approveMockSecretRequest;
|
|
79
|
+
denyMockSecretRequest: typeof denyMockSecretRequest;
|
|
80
|
+
};
|
|
32
81
|
//# sourceMappingURL=backend.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"backend.d.ts","sourceRoot":"","sources":["../../src/secrets/backend.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"backend.d.ts","sourceRoot":"","sources":["../../src/secrets/backend.ts"],"names":[],"mappings":"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"}
|