@get-bb/plugin-sdk 0.6.43 → 0.6.52

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.
@@ -4280,6 +4280,7 @@ function makeThreadResponse(overrides = {}) {
4280
4280
  originKind: null,
4281
4281
  originPluginId: null,
4282
4282
  visibility: "visible",
4283
+ parentNotifications: "auto",
4283
4284
  archivedAt: null,
4284
4285
  pinnedAt: null,
4285
4286
  deletedAt: null,
@@ -4454,6 +4455,7 @@ function makeQueueEntry(overrides = {}) {
4454
4455
  serviceTier: "default",
4455
4456
  groupWithNext: false,
4456
4457
  sendAt: null,
4458
+ state: "waiting",
4457
4459
  waitingOn: {
4458
4460
  kind: "plugin",
4459
4461
  pluginId: "test-plugin",
@@ -4483,6 +4485,362 @@ function makeTurnFailedEvent(overrides = {}) {
4483
4485
  // src/testing/public-sdk-only.ts
4484
4486
  import { readdirSync, readFileSync } from "node:fs";
4485
4487
  import { dirname, isAbsolute, join as join2, relative, resolve, sep } from "node:path";
4488
+
4489
+ // src/testing/module-references.ts
4490
+ var JsxMismatch = class extends Error {
4491
+ };
4492
+ var IDENTIFIER_START = /[\p{ID_Start}$_]/u;
4493
+ var IDENTIFIER_PART = /[\p{ID_Continue}$‌‍]/u;
4494
+ var JSX_NAME_PART = /[\p{ID_Continue}$\-:.]/u;
4495
+ var NUMBER_PART = /[\w.]/u;
4496
+ var WHITESPACE = /\s/u;
4497
+ var MULTI_CHARACTER_PUNCTUATORS = ["...", "?.", "=>", "++", "--"];
4498
+ var KEYWORDS_BEFORE_EXPRESSION = /* @__PURE__ */ new Set([
4499
+ "await",
4500
+ "case",
4501
+ "delete",
4502
+ "do",
4503
+ "else",
4504
+ "in",
4505
+ "instanceof",
4506
+ "new",
4507
+ "of",
4508
+ "return",
4509
+ "throw",
4510
+ "typeof",
4511
+ "void",
4512
+ "yield"
4513
+ ]);
4514
+ var DECLARATION_MODIFIERS = /* @__PURE__ */ new Set(["type", "typeof", "defer", "source"]);
4515
+ function tokenize(source, jsx) {
4516
+ const tokens = [];
4517
+ let pos = source.startsWith("#!") ? source.indexOf("\n") + 1 || source.length : 0;
4518
+ const push = (kind, value, start) => {
4519
+ tokens.push({ kind, value, start, end: pos });
4520
+ };
4521
+ const expressionMayStart = () => {
4522
+ const last = tokens.at(-1);
4523
+ if (last === void 0) return true;
4524
+ if (last.kind === "punct") {
4525
+ return ![")", "]", "++", "--"].includes(last.value);
4526
+ }
4527
+ return last.kind === "name" && KEYWORDS_BEFORE_EXPRESSION.has(last.value);
4528
+ };
4529
+ const skipComment = () => {
4530
+ if (source[pos] !== "/") return false;
4531
+ if (source[pos + 1] === "/") {
4532
+ const newline = source.indexOf("\n", pos);
4533
+ pos = newline === -1 ? source.length : newline;
4534
+ return true;
4535
+ }
4536
+ if (source[pos + 1] === "*") {
4537
+ const close = source.indexOf("*/", pos + 2);
4538
+ pos = close === -1 ? source.length : close + 2;
4539
+ return true;
4540
+ }
4541
+ return false;
4542
+ };
4543
+ const readString = () => {
4544
+ const start = pos;
4545
+ const quote = source[pos];
4546
+ pos++;
4547
+ while (pos < source.length) {
4548
+ const char = source[pos];
4549
+ if (char === "\\") {
4550
+ pos += 2;
4551
+ continue;
4552
+ }
4553
+ if (char === "\n") break;
4554
+ if (char === quote) {
4555
+ pos++;
4556
+ push("string", source.slice(start + 1, pos - 1), start);
4557
+ return;
4558
+ }
4559
+ pos++;
4560
+ }
4561
+ push("literal", source.slice(start, pos), start);
4562
+ };
4563
+ const readTemplate = () => {
4564
+ push("literal", "`", pos);
4565
+ pos++;
4566
+ while (pos < source.length) {
4567
+ const char = source[pos];
4568
+ if (char === "\\") {
4569
+ pos += 2;
4570
+ continue;
4571
+ }
4572
+ if (char === "`") {
4573
+ pos++;
4574
+ break;
4575
+ }
4576
+ if (char === "$" && source[pos + 1] === "{") {
4577
+ pos += 2;
4578
+ scan(true);
4579
+ continue;
4580
+ }
4581
+ pos++;
4582
+ }
4583
+ push("literal", "`", pos);
4584
+ };
4585
+ const readRegex = () => {
4586
+ const start = pos;
4587
+ let inClass = false;
4588
+ pos++;
4589
+ while (pos < source.length) {
4590
+ const char = source[pos];
4591
+ if (char === "\\") {
4592
+ pos += 2;
4593
+ continue;
4594
+ }
4595
+ if (char === "\n") break;
4596
+ pos++;
4597
+ if (inClass) {
4598
+ if (char === "]") inClass = false;
4599
+ } else if (char === "[") {
4600
+ inClass = true;
4601
+ } else if (char === "/") {
4602
+ while (pos < source.length && IDENTIFIER_PART.test(source[pos] ?? "")) {
4603
+ pos++;
4604
+ }
4605
+ break;
4606
+ }
4607
+ }
4608
+ push("literal", source.slice(start, pos), start);
4609
+ };
4610
+ const readWhile = (pattern) => {
4611
+ const start = pos;
4612
+ while (pos < source.length && pattern.test(source[pos] ?? "")) pos++;
4613
+ return source.slice(start, pos);
4614
+ };
4615
+ const skipJsxSpace = () => {
4616
+ while (pos < source.length) {
4617
+ if (WHITESPACE.test(source[pos] ?? "")) {
4618
+ pos++;
4619
+ } else if (!skipComment()) {
4620
+ return;
4621
+ }
4622
+ }
4623
+ };
4624
+ const readJsxName = () => IDENTIFIER_START.test(source[pos] ?? "") ? readWhile(JSX_NAME_PART) : "";
4625
+ const readJsxContainer = () => {
4626
+ push("punct", "{", pos);
4627
+ pos++;
4628
+ if (!scan(true)) throw new JsxMismatch();
4629
+ push("punct", "}", pos - 1);
4630
+ };
4631
+ const readJsxElement = () => {
4632
+ const start = pos;
4633
+ pos++;
4634
+ skipJsxSpace();
4635
+ const name = readJsxName();
4636
+ skipJsxSpace();
4637
+ if (name === "" && source[pos] !== ">") throw new JsxMismatch();
4638
+ if (source[pos] === "," || source.startsWith("extends", pos) && !IDENTIFIER_PART.test(source[pos + "extends".length] ?? "")) {
4639
+ throw new JsxMismatch();
4640
+ }
4641
+ push("literal", "<", start);
4642
+ for (; ; ) {
4643
+ skipJsxSpace();
4644
+ const char = source[pos];
4645
+ if (char === "/" && source[pos + 1] === ">") {
4646
+ pos += 2;
4647
+ return;
4648
+ }
4649
+ if (char === ">") {
4650
+ pos++;
4651
+ break;
4652
+ }
4653
+ if (char === "{") {
4654
+ readJsxContainer();
4655
+ continue;
4656
+ }
4657
+ if (readJsxName() === "") throw new JsxMismatch();
4658
+ skipJsxSpace();
4659
+ if (source[pos] !== "=") continue;
4660
+ pos++;
4661
+ skipJsxSpace();
4662
+ const value = source[pos];
4663
+ if (value === '"' || value === "'") {
4664
+ const close = source.indexOf(value, pos + 1);
4665
+ if (close === -1) throw new JsxMismatch();
4666
+ pos = close + 1;
4667
+ } else if (value === "{") {
4668
+ readJsxContainer();
4669
+ } else if (value === "<") {
4670
+ readJsxElement();
4671
+ } else {
4672
+ throw new JsxMismatch();
4673
+ }
4674
+ }
4675
+ while (pos < source.length) {
4676
+ const char = source[pos];
4677
+ if (char === "{") {
4678
+ readJsxContainer();
4679
+ } else if (char === "<") {
4680
+ const tagStart = pos;
4681
+ pos++;
4682
+ skipJsxSpace();
4683
+ if (source[pos] !== "/") {
4684
+ pos = tagStart;
4685
+ readJsxElement();
4686
+ continue;
4687
+ }
4688
+ pos++;
4689
+ skipJsxSpace();
4690
+ const closing = readJsxName();
4691
+ skipJsxSpace();
4692
+ if (closing !== name || source[pos] !== ">") throw new JsxMismatch();
4693
+ pos++;
4694
+ return;
4695
+ } else {
4696
+ pos++;
4697
+ }
4698
+ }
4699
+ throw new JsxMismatch();
4700
+ };
4701
+ const tryJsx = () => {
4702
+ const savedPos = pos;
4703
+ const savedLength = tokens.length;
4704
+ try {
4705
+ readJsxElement();
4706
+ return true;
4707
+ } catch (error) {
4708
+ if (!(error instanceof JsxMismatch)) throw error;
4709
+ pos = savedPos;
4710
+ tokens.length = savedLength;
4711
+ return false;
4712
+ }
4713
+ };
4714
+ function scan(untilClosingBrace) {
4715
+ let depth = 0;
4716
+ while (pos < source.length) {
4717
+ const char = source[pos] ?? "";
4718
+ const start = pos;
4719
+ if (WHITESPACE.test(char) || skipComment()) {
4720
+ if (pos === start) pos++;
4721
+ } else if (char === '"' || char === "'") {
4722
+ readString();
4723
+ } else if (char === "`") {
4724
+ readTemplate();
4725
+ } else if (char === "/" && expressionMayStart()) {
4726
+ readRegex();
4727
+ } else if (char === "<" && jsx && expressionMayStart() && tryJsx()) {
4728
+ continue;
4729
+ } else if (/\d/u.test(char) || char === "." && /\d/u.test(source[pos + 1] ?? "")) {
4730
+ push("literal", readWhile(NUMBER_PART), start);
4731
+ } else if (IDENTIFIER_START.test(char)) {
4732
+ push("name", readWhile(IDENTIFIER_PART), start);
4733
+ } else {
4734
+ if (char === "{") depth++;
4735
+ if (char === "}") {
4736
+ if (depth === 0 && untilClosingBrace) {
4737
+ pos++;
4738
+ return true;
4739
+ }
4740
+ depth--;
4741
+ }
4742
+ const punct = MULTI_CHARACTER_PUNCTUATORS.find(
4743
+ (candidate) => source.startsWith(candidate, pos) && !(candidate === "?." && /\d/u.test(source[pos + 2] ?? ""))
4744
+ ) ?? char;
4745
+ pos += punct.length;
4746
+ push("punct", punct, start);
4747
+ }
4748
+ }
4749
+ return false;
4750
+ }
4751
+ scan(false);
4752
+ return tokens;
4753
+ }
4754
+ function isPunct(token, value) {
4755
+ return token?.kind === "punct" && token.value === value;
4756
+ }
4757
+ function isName(token, value) {
4758
+ return token?.kind === "name" && (value === void 0 || token.value === value);
4759
+ }
4760
+ function closingIndex(tokens, open, opener, closer) {
4761
+ let depth = 0;
4762
+ for (let index = open; index < tokens.length; index++) {
4763
+ if (isPunct(tokens[index], opener)) depth++;
4764
+ if (isPunct(tokens[index], closer) && --depth === 0) return index;
4765
+ }
4766
+ return -1;
4767
+ }
4768
+ function specifierAfterFrom(tokens, index) {
4769
+ const specifier = tokens[index + 1];
4770
+ return isName(tokens[index], "from") && specifier?.kind === "string" ? specifier.value : void 0;
4771
+ }
4772
+ function importDeclarationSpecifier(tokens, keyword) {
4773
+ let index = keyword + 1;
4774
+ const first = tokens[index];
4775
+ if (first?.kind === "string") return first.value;
4776
+ const afterModifier = tokens[index + 1];
4777
+ if (first?.kind === "name" && DECLARATION_MODIFIERS.has(first.value) && (isPunct(afterModifier, "{") || isPunct(afterModifier, "*") || isName(afterModifier) && afterModifier?.value !== "from")) {
4778
+ index++;
4779
+ }
4780
+ if (isName(tokens[index])) {
4781
+ index++;
4782
+ if (!isPunct(tokens[index], ",")) return specifierAfterFrom(tokens, index);
4783
+ index++;
4784
+ }
4785
+ if (isPunct(tokens[index], "{")) {
4786
+ const close = closingIndex(tokens, index, "{", "}");
4787
+ return close === -1 ? void 0 : specifierAfterFrom(tokens, close + 1);
4788
+ }
4789
+ if (isPunct(tokens[index], "*") && isName(tokens[index + 1], "as")) {
4790
+ return specifierAfterFrom(tokens, index + 3);
4791
+ }
4792
+ return void 0;
4793
+ }
4794
+ function exportDeclarationSpecifier(tokens, keyword) {
4795
+ let index = keyword + 1;
4796
+ if (isName(tokens[index], "type")) index++;
4797
+ if (isPunct(tokens[index], "*")) {
4798
+ return isName(tokens[index + 1], "as") ? specifierAfterFrom(tokens, index + 3) : specifierAfterFrom(tokens, index + 1);
4799
+ }
4800
+ if (isPunct(tokens[index], "{")) {
4801
+ const close = closingIndex(tokens, index, "{", "}");
4802
+ return close === -1 ? void 0 : specifierAfterFrom(tokens, close + 1);
4803
+ }
4804
+ return void 0;
4805
+ }
4806
+ function moduleReferences(source, options) {
4807
+ const tokens = tokenize(source, options.jsx);
4808
+ const references = [];
4809
+ tokens.forEach((token, index) => {
4810
+ if (token.kind !== "name") return;
4811
+ const previous = tokens[index - 1];
4812
+ if ([".", "?.", "#"].some((value) => isPunct(previous, value))) return;
4813
+ const keyword = token.value;
4814
+ if ((keyword === "import" || keyword === "require") && isPunct(tokens[index + 1], "(")) {
4815
+ const close = closingIndex(tokens, index + 1, "(", ")");
4816
+ const after = tokens[close + 1];
4817
+ if (close === -1 || close === index + 2 || isPunct(after, "{") || isPunct(after, ":") && !isPunct(previous, "?")) {
4818
+ return;
4819
+ }
4820
+ const argument = tokens[index + 2];
4821
+ const argumentEnd = tokens[index + 3];
4822
+ if (argument?.kind === "string" && (isPunct(argumentEnd, ")") || isPunct(argumentEnd, ","))) {
4823
+ references.push({ specifier: argument.value, dynamic: false });
4824
+ return;
4825
+ }
4826
+ const open = tokens[index + 1];
4827
+ const closeToken = tokens[close];
4828
+ if (open === void 0 || closeToken === void 0) return;
4829
+ references.push({
4830
+ specifier: source.slice(open.end, closeToken.start).trim(),
4831
+ dynamic: true
4832
+ });
4833
+ return;
4834
+ }
4835
+ const specifier = keyword === "import" ? importDeclarationSpecifier(tokens, index) : keyword === "export" ? exportDeclarationSpecifier(tokens, index) : void 0;
4836
+ if (specifier !== void 0) {
4837
+ references.push({ specifier, dynamic: false });
4838
+ }
4839
+ });
4840
+ return references;
4841
+ }
4842
+
4843
+ // src/testing/public-sdk-only.ts
4486
4844
  var SKIPPED_DIRECTORIES = /* @__PURE__ */ new Set(["node_modules", "dist"]);
4487
4845
  var SOURCE_EXTENSIONS = /\.(?:[cm]?[jt]s|tsx)$/u;
4488
4846
  var TEST_FILE_PATTERN = /\.test\.[cm]?[jt]sx?$/u;
@@ -4498,8 +4856,6 @@ var TEST_IMPORT_ALLOWLIST = [
4498
4856
  /^@get-bb\/plugin-sdk\/(?:testing|testing\/app|testing\/host|provider-bridge\/testing)$/u,
4499
4857
  /^vitest$/u
4500
4858
  ];
4501
- var IMPORT_SPECIFIER_PATTERN = /(?:\bfrom\s*|\bimport\s*\(?\s*|\brequire\s*\(\s*)["']([^"']+)["']/gu;
4502
- var DYNAMIC_SPECIFIER_PATTERN = /\b(?:import|require)\s*\(\s*(?!["'])([^)]+)\)/gu;
4503
4859
  var RELATIVE_SPECIFIER_PATTERN = /^\.\.?\//u;
4504
4860
  function listSourceFiles(directory) {
4505
4861
  const files = [];
@@ -4516,16 +4872,6 @@ function listSourceFiles(directory) {
4516
4872
  }
4517
4873
  return files;
4518
4874
  }
4519
- function importSpecifiers(source) {
4520
- return [...source.matchAll(IMPORT_SPECIFIER_PATTERN)].map(
4521
- (match) => match[1] ?? ""
4522
- );
4523
- }
4524
- function dynamicSpecifiers(source) {
4525
- return [...source.matchAll(DYNAMIC_SPECIFIER_PATTERN)].map(
4526
- (match) => (match[1] ?? "").trim()
4527
- );
4528
- }
4529
4875
  function escapesPackage(packageRoot, file, specifier) {
4530
4876
  const target = relative(packageRoot, resolve(dirname(file), specifier));
4531
4877
  return isAbsolute(target) || target === ".." || target.startsWith(`..${sep}`);
@@ -4553,9 +4899,13 @@ function scanPublicSdkOnly(packageRoot, options = {}) {
4553
4899
  const file = relative(packageRoot, path);
4554
4900
  files.push(file);
4555
4901
  const allowlist = TEST_FILE_PATTERN.test(path) ? testAllowlist : pluginAllowlist;
4556
- const source = readFileSync(path, "utf8");
4557
- for (const specifier of importSpecifiers(source)) {
4558
- if (specifier.startsWith(PRIVATE_PACKAGE_PREFIX)) {
4902
+ const references = moduleReferences(readFileSync(path, "utf8"), {
4903
+ jsx: path.endsWith(".tsx")
4904
+ });
4905
+ for (const { specifier, dynamic } of references) {
4906
+ if (dynamic) {
4907
+ violations.push({ file, specifier, reason: "dynamic-specifier" });
4908
+ } else if (specifier.startsWith(PRIVATE_PACKAGE_PREFIX)) {
4559
4909
  violations.push({ file, specifier, reason: "private-package" });
4560
4910
  } else if (RELATIVE_SPECIFIER_PATTERN.test(specifier) && escapesPackage(packageRoot, path, specifier) && !extra.some((pattern) => pattern.test(specifier))) {
4561
4911
  violations.push({ file, specifier, reason: "outside-package" });
@@ -4563,9 +4913,6 @@ function scanPublicSdkOnly(packageRoot, options = {}) {
4563
4913
  violations.push({ file, specifier, reason: "outside-allowlist" });
4564
4914
  }
4565
4915
  }
4566
- for (const specifier of dynamicSpecifiers(source)) {
4567
- violations.push({ file, specifier, reason: "dynamic-specifier" });
4568
- }
4569
4916
  }
4570
4917
  return {
4571
4918
  files,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@get-bb/plugin-sdk",
3
- "version": "0.6.43",
3
+ "version": "0.6.52",
4
4
  "homepage": "https://github.com/get-bb/bb#readme",
5
5
  "bugs": {
6
6
  "url": "https://github.com/get-bb/bb/issues"