@sedum-dev/core 0.1.0-alpha.5 → 0.1.0-alpha.6

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/index.d.ts CHANGED
@@ -81,6 +81,7 @@ declare const ResultLocatorSchema: z.ZodObject<{
81
81
  abstained: "abstained";
82
82
  }>>;
83
83
  reason: z.ZodOptional<z.ZodString>;
84
+ abstentionReason: z.ZodOptional<z.ZodString>;
84
85
  elapsedMs: z.ZodNumber;
85
86
  failure: z.ZodOptional<z.ZodEnum<{
86
87
  unknown: "unknown";
@@ -92,6 +93,7 @@ declare const ResultLocatorSchema: z.ZodObject<{
92
93
  invalid_json: "invalid_json";
93
94
  invalid_selection: "invalid_selection";
94
95
  truncated_response: "truncated_response";
96
+ stale_page: "stale_page";
95
97
  }>>;
96
98
  httpStatus: z.ZodOptional<z.ZodNumber>;
97
99
  }, z.core.$strict>>;
@@ -182,6 +184,7 @@ declare const ResultStepSchema: z.ZodObject<{
182
184
  abstained: "abstained";
183
185
  }>>;
184
186
  reason: z.ZodOptional<z.ZodString>;
187
+ abstentionReason: z.ZodOptional<z.ZodString>;
185
188
  elapsedMs: z.ZodNumber;
186
189
  failure: z.ZodOptional<z.ZodEnum<{
187
190
  unknown: "unknown";
@@ -193,6 +196,7 @@ declare const ResultStepSchema: z.ZodObject<{
193
196
  invalid_json: "invalid_json";
194
197
  invalid_selection: "invalid_selection";
195
198
  truncated_response: "truncated_response";
199
+ stale_page: "stale_page";
196
200
  }>>;
197
201
  httpStatus: z.ZodOptional<z.ZodNumber>;
198
202
  }, z.core.$strict>>;
@@ -408,6 +412,7 @@ declare const ResultAttemptSchema: z.ZodObject<{
408
412
  abstained: "abstained";
409
413
  }>>;
410
414
  reason: z.ZodOptional<z.ZodString>;
415
+ abstentionReason: z.ZodOptional<z.ZodString>;
411
416
  elapsedMs: z.ZodNumber;
412
417
  failure: z.ZodOptional<z.ZodEnum<{
413
418
  unknown: "unknown";
@@ -419,6 +424,7 @@ declare const ResultAttemptSchema: z.ZodObject<{
419
424
  invalid_json: "invalid_json";
420
425
  invalid_selection: "invalid_selection";
421
426
  truncated_response: "truncated_response";
427
+ stale_page: "stale_page";
422
428
  }>>;
423
429
  httpStatus: z.ZodOptional<z.ZodNumber>;
424
430
  }, z.core.$strict>>;
@@ -684,6 +690,7 @@ declare const ResultTestSchema: z.ZodObject<{
684
690
  abstained: "abstained";
685
691
  }>>;
686
692
  reason: z.ZodOptional<z.ZodString>;
693
+ abstentionReason: z.ZodOptional<z.ZodString>;
687
694
  elapsedMs: z.ZodNumber;
688
695
  failure: z.ZodOptional<z.ZodEnum<{
689
696
  unknown: "unknown";
@@ -695,6 +702,7 @@ declare const ResultTestSchema: z.ZodObject<{
695
702
  invalid_json: "invalid_json";
696
703
  invalid_selection: "invalid_selection";
697
704
  truncated_response: "truncated_response";
705
+ stale_page: "stale_page";
698
706
  }>>;
699
707
  httpStatus: z.ZodOptional<z.ZodNumber>;
700
708
  }, z.core.$strict>>;
@@ -1077,6 +1085,7 @@ declare const RunResultSchema: z.ZodObject<{
1077
1085
  abstained: "abstained";
1078
1086
  }>>;
1079
1087
  reason: z.ZodOptional<z.ZodString>;
1088
+ abstentionReason: z.ZodOptional<z.ZodString>;
1080
1089
  elapsedMs: z.ZodNumber;
1081
1090
  failure: z.ZodOptional<z.ZodEnum<{
1082
1091
  unknown: "unknown";
@@ -1088,6 +1097,7 @@ declare const RunResultSchema: z.ZodObject<{
1088
1097
  invalid_json: "invalid_json";
1089
1098
  invalid_selection: "invalid_selection";
1090
1099
  truncated_response: "truncated_response";
1100
+ stale_page: "stale_page";
1091
1101
  }>>;
1092
1102
  httpStatus: z.ZodOptional<z.ZodNumber>;
1093
1103
  }, z.core.$strict>>;
@@ -2045,8 +2055,9 @@ interface LocatorDiagnostic {
2045
2055
  readonly vision?: {
2046
2056
  readonly outcome?: "selected" | "abstained" | "failed";
2047
2057
  readonly reason?: string;
2058
+ readonly abstentionReason?: string;
2048
2059
  readonly elapsedMs: number;
2049
- readonly failure?: VisionFailure | "unknown";
2060
+ readonly failure?: VisionFailure | "unknown" | "stale_page";
2050
2061
  readonly httpStatus?: number;
2051
2062
  };
2052
2063
  readonly candidateCount: number;
package/dist/index.js CHANGED
@@ -87,6 +87,7 @@ var ResultLocatorSchema = z.strictObject({
87
87
  vision: z.strictObject({
88
88
  outcome: z.enum(["selected", "abstained", "failed"]).optional(),
89
89
  reason: z.string().max(120).optional(),
90
+ abstentionReason: z.string().max(120).optional(),
90
91
  elapsedMs: nonnegative,
91
92
  failure: z.enum([
92
93
  "timeout",
@@ -97,7 +98,8 @@ var ResultLocatorSchema = z.strictObject({
97
98
  "invalid_json",
98
99
  "invalid_selection",
99
100
  "truncated_response",
100
- "unknown"
101
+ "unknown",
102
+ "stale_page"
101
103
  ]).optional(),
102
104
  httpStatus: z.number().int().min(100).max(599).optional()
103
105
  }).optional(),
@@ -2507,6 +2509,9 @@ function sameVisualVersion(a, b) {
2507
2509
  }
2508
2510
  async function captureVisionObservation(page, candidates, version, instruction, projectText = (text) => text) {
2509
2511
  if (!page.captureFrame) return null;
2512
+ const settled = await quietPage(page, 1e3, 4e3);
2513
+ if (!settled.quiet || !sameVisualVersion(settled.version, version))
2514
+ return null;
2510
2515
  const visual = await visualCandidates(page);
2511
2516
  if (!sameVisualVersion(visual.version, version)) return null;
2512
2517
  const boxes = visual.boxes.filter(
@@ -3524,7 +3529,13 @@ async function resolveTarget(page, resolver, options) {
3524
3529
  options.projectText
3525
3530
  );
3526
3531
  ensureActive();
3527
- if (!captured) return unresolved("ambiguous");
3532
+ if (!captured) {
3533
+ if (!sameVersion3(await pageVersion(page), source.version)) {
3534
+ gate = `${gate}:vision_stale_capture`;
3535
+ return unresolved("stale");
3536
+ }
3537
+ return unresolved("ambiguous");
3538
+ }
3528
3539
  let answer;
3529
3540
  const visionStarted = performance.now();
3530
3541
  try {
@@ -3557,11 +3568,16 @@ async function resolveTarget(page, resolver, options) {
3557
3568
  };
3558
3569
  ensureActive();
3559
3570
  if (!sameVersion3(await pageVersion(page), source.version)) {
3571
+ visionDiagnostic = { ...visionDiagnostic, failure: "stale_page" };
3560
3572
  gate = `${gate}:vision_stale`;
3561
3573
  return unresolved("ambiguous");
3562
3574
  }
3563
3575
  if (answer.decision.kind !== "candidate") {
3564
- visionDiagnostic = { ...visionDiagnostic, outcome: "abstained" };
3576
+ visionDiagnostic = {
3577
+ ...visionDiagnostic,
3578
+ outcome: "abstained",
3579
+ abstentionReason: answer.decision.reason
3580
+ };
3565
3581
  gate = `${gate}:vision_abstained`;
3566
3582
  return unresolved("ambiguous");
3567
3583
  }
@@ -3580,6 +3596,7 @@ async function resolveTarget(page, resolver, options) {
3580
3596
  diagnostic: { ...result.diagnostic, vision: visionDiagnostic }
3581
3597
  };
3582
3598
  }
3599
+ visionDiagnostic = { ...visionDiagnostic, failure: "stale_page" };
3583
3600
  return unresolved("ambiguous");
3584
3601
  } catch {
3585
3602
  if (!sameVersion3(await pageVersion(page), source.version)) {
@@ -6984,6 +7001,7 @@ async function executeSentence(page, step, dependencies, data, opaqueEntries, pr
6984
7001
  }
6985
7002
  }
6986
7003
  if (step.op === "remember") {
7004
+ const targetLabel = presentation.display?.startsWith("extract ") ? "extract" : "remember";
6987
7005
  const match = /^(?:remember|capture)\s+(.+?)\s+as\s+\{\{\s*([A-Za-z_][A-Za-z0-9_]*)\s*\}\}\s*\.?$/iu.exec(
6988
7006
  step.text.trim()
6989
7007
  );
@@ -7022,16 +7040,29 @@ async function executeSentence(page, step, dependencies, data, opaqueEntries, pr
7022
7040
  locator,
7023
7041
  error: {
7024
7042
  code: locator.reason,
7025
- message: "The remember target could not be resolved."
7043
+ message: `The ${targetLabel} target could not be resolved.`
7026
7044
  }
7027
7045
  });
7028
- const read = await readTarget(page, locator.target.driverTarget());
7046
+ let read = await readTarget(page, locator.target.driverTarget());
7047
+ if (read.status === "stale") {
7048
+ locator = await reobserve(
7049
+ page,
7050
+ { ...locator, kind: "unresolved", reason: "stale" },
7051
+ locateRead,
7052
+ {
7053
+ staleRetry: true,
7054
+ ...dependencies.signal ? { signal: dependencies.signal } : {}
7055
+ }
7056
+ );
7057
+ if (locator.kind === "resolved")
7058
+ read = await readTarget(page, locator.target.driverTarget());
7059
+ }
7029
7060
  if (read.status !== "ok")
7030
7061
  return record("failed", {
7031
7062
  locator,
7032
7063
  error: {
7033
7064
  code: `remember_${read.status}`,
7034
- message: "The remember target did not contain usable text."
7065
+ message: `The ${targetLabel} target did not contain usable text.`
7035
7066
  }
7036
7067
  });
7037
7068
  remembered = read.text;
@@ -7041,7 +7072,7 @@ async function executeSentence(page, step, dependencies, data, opaqueEntries, pr
7041
7072
  ...locator ? { locator } : {},
7042
7073
  error: {
7043
7074
  code: "remember_invalid_text",
7044
- message: "The remember target did not contain usable text."
7075
+ message: `The ${targetLabel} target did not contain usable text.`
7045
7076
  }
7046
7077
  });
7047
7078
  const echoedSecrets = opaqueMatches(remembered, opaqueEntries);
@@ -652,7 +652,7 @@ var SedumPageScript = (() => {
652
652
  pieces.push(part);
653
653
  }
654
654
  return { text: pieces.join(" "), complete: true };
655
- }, peers = function(element, name) {
655
+ }, peers = function(element, name, operation = "click") {
656
656
  const row = element.closest("tr");
657
657
  const preceding = row?.previousElementSibling;
658
658
  const rank = preceding?.querySelector(".rank");
@@ -680,6 +680,13 @@ var SedumPageScript = (() => {
680
680
  }
681
681
  lastUnique = region;
682
682
  if (region.matches("article,li,[data-product],[role='listitem']")) break;
683
+ const container = region;
684
+ if (operation === "read" && container.classList.length > 0 && Array.from(container.parentElement?.children ?? []).some(
685
+ (sibling) => sibling !== container && sibling.tagName === container.tagName && sibling.classList.length === container.classList.length && Array.from(container.classList).every(
686
+ (name2) => sibling.classList.contains(name2)
687
+ )
688
+ ))
689
+ break;
683
690
  region = composedParent(region);
684
691
  }
685
692
  region = region === document.body ? lastUnique : region;
@@ -764,7 +771,7 @@ var SedumPageScript = (() => {
764
771
  nodeId = `${documentId}-node-${++nodeSequence}`;
765
772
  nodeIds.set(element, nodeId);
766
773
  }
767
- const peerData = peers(element, name);
774
+ const peerData = peers(element, name, operation);
768
775
  const location2 = locationOf(element, heading);
769
776
  const section = sectionOf(element, outline);
770
777
  const hint = operation === "read" ? "" : nameHint(element, rawName);
@@ -972,7 +979,7 @@ var SedumPageScript = (() => {
972
979
  const candidate = snapshot.candidates.find(
973
980
  (item) => item.ref === target.ref
974
981
  );
975
- if (!element || !candidate || element.tagName.toLowerCase() !== target.tag || candidate.name !== target.name || !readable(element) || !visible(element) || label(element) !== owned.get(element)?.rawName || JSON.stringify(peers(element, candidate.name).texts) !== JSON.stringify(candidate.peers))
982
+ if (!element || !candidate || element.tagName.toLowerCase() !== target.tag || candidate.name !== target.name || !readable(element) || !visible(element) || label(element) !== owned.get(element)?.rawName || JSON.stringify(peers(element, candidate.name, "read").texts) !== JSON.stringify(candidate.peers))
976
983
  return { status: "stale" };
977
984
  const text = publicText(element);
978
985
  if (!text) return { status: "empty" };
@@ -798,6 +798,10 @@
798
798
  "type": "string",
799
799
  "maxLength": 120
800
800
  },
801
+ "abstentionReason": {
802
+ "type": "string",
803
+ "maxLength": 120
804
+ },
801
805
  "elapsedMs": {
802
806
  "type": "number",
803
807
  "minimum": 0
@@ -813,7 +817,8 @@
813
817
  "invalid_json",
814
818
  "invalid_selection",
815
819
  "truncated_response",
816
- "unknown"
820
+ "unknown",
821
+ "stale_page"
817
822
  ]
818
823
  },
819
824
  "httpStatus": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sedum-dev/core",
3
- "version": "0.1.0-alpha.5",
3
+ "version": "0.1.0-alpha.6",
4
4
  "repository": "https://github.com/sedum-dev/sedum",
5
5
  "publishConfig": {
6
6
  "access": "public"