@workos/oagen 0.29.2 → 0.29.4

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.
@@ -1,5 +1,5 @@
1
- import { $ as AdditiveChangeCategory, At as CompatSnapshot, Bt as ALL_LANGUAGE_IDS, Ct as MethodOverlay, Dt as ViolationSeverity, Et as ViolationCategory, Ft as CompatTypeRef, Ht as getDefaultPolicy, It as CompatVisibility, Lt as LanguageId, Mt as CompatStability, Nt as CompatSymbol, Ot as CompatParameter, Pt as CompatSymbolKind, Rt as ParameterSensitivity, St as LanguageHints, Tt as Violation, Ut as mergePolicy, Vt as CompatPolicyHints, _t as ApiProperty, at as CompatFailLevel, bt as DiffResult, ct as defaultSeverityForCategory, dt as ApiClass, et as BreakingChangeCategory, ft as ApiEnum, gt as ApiParam, ht as ApiMethod, it as CompatConfig, jt as CompatSourceKind, kt as CompatPassingStyle, lt as severityMeetsThreshold, mt as ApiInterface, nt as CompatChangeCategory, ot as CompatProvenance, pt as ApiField, rt as CompatChangeSeverity, st as SoftRiskChangeCategory, t as ApiSpec, tt as CompatApproval, ut as Addition, vt as ApiSurface, wt as OverlayLookup, xt as Extractor, yt as ApiTypeAlias, zt as apiSurfaceToSnapshot } from "../types-CEMBeTr9.mjs";
2
- import { a as specDerivedEnumValues, c as specDerivedMethodPaths, d as ClassifiedChange, f as classifyAddedSymbol, i as filterSurface, l as specDerivedNames, m as summarizeChanges, n as diffSnapshots, o as specDerivedFieldPaths, p as classifySymbolChanges, r as diffSurfaces, s as specDerivedHttpKeys, t as CompatDiffResult, u as ClassificationResult } from "../differ-DxWejtEg.mjs";
1
+ import { $ as AdditiveChangeCategory, At as CompatSnapshot, Bt as ALL_LANGUAGE_IDS, Ct as MethodOverlay, Dt as ViolationSeverity, Et as ViolationCategory, Ft as CompatTypeRef, Ht as getDefaultPolicy, It as CompatVisibility, Lt as LanguageId, Mt as CompatStability, Nt as CompatSymbol, Ot as CompatParameter, Pt as CompatSymbolKind, Rt as ParameterSensitivity, St as LanguageHints, Tt as Violation, Ut as mergePolicy, Vt as CompatPolicyHints, _t as ApiProperty, at as CompatFailLevel, bt as DiffResult, ct as defaultSeverityForCategory, dt as ApiClass, et as BreakingChangeCategory, ft as ApiEnum, gt as ApiParam, ht as ApiMethod, it as CompatConfig, jt as CompatSourceKind, kt as CompatPassingStyle, lt as severityMeetsThreshold, mt as ApiInterface, nt as CompatChangeCategory, ot as CompatProvenance, pt as ApiField, rt as CompatChangeSeverity, st as SoftRiskChangeCategory, t as ApiSpec, tt as CompatApproval, ut as Addition, vt as ApiSurface, wt as OverlayLookup, xt as Extractor, yt as ApiTypeAlias, zt as apiSurfaceToSnapshot } from "../types-yrBidOg3.mjs";
2
+ import { a as specDerivedEnumValues, c as specDerivedMethodPaths, d as ClassifiedChange, f as classifyAddedSymbol, i as filterSurface, l as specDerivedNames, m as summarizeChanges, n as diffSnapshots, o as specDerivedFieldPaths, p as classifySymbolChanges, r as diffSurfaces, s as specDerivedHttpKeys, t as CompatDiffResult, u as ClassificationResult } from "../differ-DHldxZMr.mjs";
3
3
 
4
4
  //#region src/compat/schema.d.ts
5
5
  /** Current schema version for compatibility snapshots. */
@@ -714,6 +714,7 @@ function extractKotlinClassMembers(classBody, source) {
714
714
  const children = classBody.namedChildren;
715
715
  for (let i = 0; i < children.length; i++) {
716
716
  const child = children[i];
717
+ const declIndex = i;
717
718
  let memberName = null;
718
719
  if (child.type === "property_declaration") memberName = child.children.find((c) => c.type === "variable_declaration")?.children.find((c) => c.type === "simple_identifier")?.text ?? null;
719
720
  else if (child.type === "function_declaration") memberName = child.children.find((c) => c.type === "simple_identifier")?.text ?? null;
@@ -728,7 +729,7 @@ function extractKotlinClassMembers(classBody, source) {
728
729
  } else break;
729
730
  }
730
731
  let startIdx = child.startIndex;
731
- for (let k = i - 1; k >= 0; k--) {
732
+ for (let k = declIndex - 1; k >= 0; k--) {
732
733
  const prev = children[k];
733
734
  if (prev.type === "multiline_comment") {
734
735
  if (source.slice(prev.startIndex, prev.endIndex).startsWith("/**")) startIdx = prev.startIndex;
@@ -797,6 +798,13 @@ const kotlinMergeAdapter = {
797
798
  isManagedMember(member) {
798
799
  return KOTLIN_MANAGED_ACCESSOR_DOC.test(member.text);
799
800
  },
801
+ importedNames(imp) {
802
+ const path = imp.text.replace(/^import\s+/, "").trim();
803
+ const alias = path.match(/\s+as\s+([A-Za-z_][A-Za-z0-9_]*)$/);
804
+ if (alias) return [alias[1]];
805
+ const last = path.split(".").pop();
806
+ return last && last !== "*" ? [last] : [];
807
+ },
800
808
  shouldSkipDeepMerge(_symbolName, existingMemberKeys, newMembers) {
801
809
  const newText = newMembers.map((m) => m.text).join("\n");
802
810
  for (const match of newText.matchAll(/this\.(\w+)/g)) {
@@ -1672,6 +1680,116 @@ function declarationLineStart(content, declStartIndex) {
1672
1680
  return prevNewline === -1 ? 0 : prevNewline + 1;
1673
1681
  }
1674
1682
  /**
1683
+ * Widen a member's byte range so deleting it removes whole lines.
1684
+ *
1685
+ * The raw range starts at the declaration (or its docstring), which sits after
1686
+ * the member's indentation — splicing it out verbatim leaves that indentation
1687
+ * glued to the following line. Extends backwards over the indentation and
1688
+ * forwards over the trailing newline, then absorbs the blank line the removal
1689
+ * would otherwise duplicate (or strand in front of the block's closing brace).
1690
+ */
1691
+ function expandPruneRange(source, rawStart, rawEnd) {
1692
+ let start = rawStart;
1693
+ while (start > 0 && (source[start - 1] === " " || source[start - 1] === " ")) start--;
1694
+ let end = rawEnd;
1695
+ while (end < source.length && (source[end] === " " || source[end] === " ")) end++;
1696
+ end = skipLineBreak(source, end);
1697
+ if (precededByBlankLine(source, start)) {
1698
+ if (startsWithLineBreak(source, end)) end = skipLineBreak(source, end);
1699
+ else if (/^[ \t]*\}/.test(source.slice(end, end + 40))) start = backOverLineBreak(source, start);
1700
+ }
1701
+ return {
1702
+ start,
1703
+ end
1704
+ };
1705
+ }
1706
+ function startsWithLineBreak(source, idx) {
1707
+ return source[idx] === "\n" || source[idx] === "\r" && source[idx + 1] === "\n";
1708
+ }
1709
+ function skipLineBreak(source, idx) {
1710
+ let i = idx;
1711
+ if (source[i] === "\r") i++;
1712
+ return source[i] === "\n" ? i + 1 : i;
1713
+ }
1714
+ function backOverLineBreak(source, idx) {
1715
+ let i = idx;
1716
+ if (source[i - 1] === "\n") i--;
1717
+ if (source[i - 1] === "\r") i--;
1718
+ return i;
1719
+ }
1720
+ /** Whether the line ending immediately before `idx` (a line start) is empty. */
1721
+ function precededByBlankLine(source, idx) {
1722
+ if (idx === 0 || source[idx - 1] !== "\n") return false;
1723
+ const priorLineEnd = backOverLineBreak(source, idx);
1724
+ return priorLineEnd > 0 && source[priorLineEnd - 1] === "\n";
1725
+ }
1726
+ function referencesIdentifier(source, name) {
1727
+ return new RegExp(`\\b${name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}\\b`).test(source);
1728
+ }
1729
+ /**
1730
+ * Blank out comments and string text, preserving offsets and line structure.
1731
+ *
1732
+ * An identifier lookup over raw source can't tell a live reference from a name
1733
+ * that merely survives in prose. That distinction decides whether an import
1734
+ * stays: keeping one whose only remaining mention is a KDoc leaves an import of
1735
+ * a class the generator no longer emits, which doesn't compile — the very
1736
+ * failure the prune exists to prevent.
1737
+ *
1738
+ * Interpolated expressions are the exception: `"${Agents.NAME}"` is code that
1739
+ * sits inside a string literal, and masking it would drop an import the file
1740
+ * genuinely uses. String extents are masked around those holes, not over them.
1741
+ *
1742
+ * Grammar node names come from the adapter's `urlFingerprintConfig`, which
1743
+ * already inventories exactly these three categories per language. Comments are
1744
+ * matched structurally instead — every grammar we support names them `*comment`.
1745
+ */
1746
+ function maskNonCode(tree, source, config) {
1747
+ const stringNodeTypes = new Set(config?.stringNodeTypes ?? []);
1748
+ const interpolationNodeTypes = new Set(config?.interpolationNodeTypes ?? []);
1749
+ const spans = [];
1750
+ const collectStringSpans = (node) => {
1751
+ const holes = [];
1752
+ const findHoles = (n) => {
1753
+ if (interpolationNodeTypes.has(n.type)) {
1754
+ holes.push([n.startIndex, n.endIndex]);
1755
+ return;
1756
+ }
1757
+ for (const child of n.children) findHoles(child);
1758
+ };
1759
+ findHoles(node);
1760
+ let cursor = node.startIndex;
1761
+ for (const [holeStart, holeEnd] of holes) {
1762
+ if (holeStart > cursor) spans.push([cursor, holeStart]);
1763
+ cursor = holeEnd;
1764
+ }
1765
+ if (cursor < node.endIndex) spans.push([cursor, node.endIndex]);
1766
+ };
1767
+ const walk = (node) => {
1768
+ if (node.type.includes("comment")) {
1769
+ spans.push([node.startIndex, node.endIndex]);
1770
+ return;
1771
+ }
1772
+ if (stringNodeTypes.has(node.type)) {
1773
+ collectStringSpans(node);
1774
+ return;
1775
+ }
1776
+ for (const child of node.children) walk(child);
1777
+ };
1778
+ walk(tree.rootNode);
1779
+ if (spans.length === 0) return source;
1780
+ let masked = "";
1781
+ let cursor = 0;
1782
+ for (const [spanStart, spanEnd] of spans) {
1783
+ if (spanStart < cursor) continue;
1784
+ masked += source.slice(cursor, spanStart) + source.slice(spanStart, spanEnd).replace(/[^\r\n]/g, " ");
1785
+ cursor = spanEnd;
1786
+ }
1787
+ return masked + source.slice(cursor);
1788
+ }
1789
+ function removeLines(source, lines) {
1790
+ return source.split("\n").filter((line) => !lines.has(line.trim())).join("\n");
1791
+ }
1792
+ /**
1675
1793
  * Resolve a docstring range by searching for the nearest matching text before
1676
1794
  * the declaration start. Falls back to parser-provided offsets when search fails.
1677
1795
  */
@@ -1886,6 +2004,7 @@ async function mergeIntoExisting(existingContent, generatedContent, language, he
1886
2004
  let deepAdded = 0;
1887
2005
  let deepPruned = 0;
1888
2006
  const insertions = [];
2007
+ const prunedTexts = [];
1889
2008
  if (adapter.extractMembers) {
1890
2009
  const parser = await getParser(language);
1891
2010
  const resultTree = safeParse(parser, result);
@@ -1914,10 +2033,9 @@ async function mergeIntoExisting(existingContent, generatedContent, language, he
1914
2033
  if (pruneEdits.length > 0) {
1915
2034
  pruneEdits.sort((a, b) => b.start - a.start);
1916
2035
  for (const edit of pruneEdits) {
1917
- let end = edit.end;
1918
- while (end < result.length && (result[end] === " " || result[end] === " ")) end++;
1919
- if (result[end] === "\n") end++;
1920
- result = result.slice(0, edit.start) + result.slice(end);
2036
+ const { start, end } = expandPruneRange(result, edit.start, edit.end);
2037
+ prunedTexts.push(result.slice(start, end));
2038
+ result = result.slice(0, start) + result.slice(end);
1921
2039
  }
1922
2040
  deepPruned = pruneEdits.length;
1923
2041
  const reTree = safeParse(parser, result);
@@ -1982,6 +2100,21 @@ async function mergeIntoExisting(existingContent, generatedContent, language, he
1982
2100
  result = lines.join("\n");
1983
2101
  }
1984
2102
  }
2103
+ if (prunedTexts.length > 0 && adapter.importedNames) {
2104
+ const prunedText = prunedTexts.join("\n");
2105
+ const codeOnly = maskNonCode(safeParse(await getParser(language), result), result, adapter.urlFingerprintConfig);
2106
+ const orphaned = /* @__PURE__ */ new Set();
2107
+ for (const imp of existingStatements.imports) {
2108
+ const names = adapter.importedNames(imp);
2109
+ if (names.length === 0) continue;
2110
+ if (!names.some((n) => referencesIdentifier(prunedText, n))) continue;
2111
+ const line = imp.text.trim();
2112
+ const withoutImport = removeLines(codeOnly, new Set([line]));
2113
+ if (names.some((n) => referencesIdentifier(withoutImport, n))) continue;
2114
+ orphaned.add(line);
2115
+ }
2116
+ if (orphaned.size > 0) result = removeLines(result, orphaned);
2117
+ }
1985
2118
  let docstringUpdates = 0;
1986
2119
  {
1987
2120
  const parser = await getParser(language);
@@ -4284,4 +4417,4 @@ function summarize(changes) {
4284
4417
  //#endregion
4285
4418
  export { resolveMountTarget as _, registerEmitter as a, integrateGeneratedFiles as c, applyFileHeaders as d, buildEmitterContext as f, deriveMethodName as g, generateFiles as h, getEmitter as i, mapFilesForTargetIntegration as l, generateAllFiles as m, buildDirectionIndex as n, generate as o, collectReferencedNames as p, directionOf as r, MANIFEST_FILENAME as s, diffSpecs as t, treeShakeFiles as u, resolveOperations as v };
4286
4419
 
4287
- //# sourceMappingURL=diff-DqnHHXvr.mjs.map
4420
+ //# sourceMappingURL=diff-B6TjXIwb.mjs.map