@teable/agent-gateway 1.0.13 → 1.0.15

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.
Files changed (2) hide show
  1. package/dist/cli.js +30 -5
  2. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -569,10 +569,11 @@ var AGENTS = {
569
569
 
570
570
  // src/checkout.ts
571
571
  import { execFile } from "node:child_process";
572
- import { existsSync, mkdirSync as mkdirSync2 } from "node:fs";
572
+ import { existsSync, mkdirSync as mkdirSync2, readdirSync } from "node:fs";
573
573
  import { join as join2 } from "node:path";
574
574
  var APP_DIRECTORY = /^[A-Za-z0-9_-]+$/;
575
575
  var CLONE_TIMEOUT_MS = 5 * 6e4;
576
+ var CHECK_TIMEOUT_MS = 2e4;
576
577
  var RULES_MARK = "[Teable]";
577
578
  var where = (appId) => `${RULES_MARK} You work in a person's Teable sandbox, on the Teable app ${appId}, in this directory.`;
578
579
  var NAME_IT = 'once you know what the app is, name the project after it, in the person\'s language, with `teable-next rename "<name>"`.';
@@ -580,10 +581,18 @@ function newProject(appId) {
580
581
  return [
581
582
  where(appId),
582
583
  "The project has no code yet, so the directory is empty. When you build the app, start it",
583
- `here with \`teable-next init . --project ${appId}\`. If it prints the projectName as null,`,
584
- `nobody has named the project yet: ${NAME_IT}`
584
+ `here with \`teable-next init . --project ${appId}\`, then read the AGENTS.md it writes, all`,
585
+ "of it, before you go on: it says how apps are built here, and it was not there when you",
586
+ "started. As it says, publish once the checks pass, without asking the person whether to.",
587
+ `If \`init\` prints the projectName as null, nobody has named the project yet: ${NAME_IT}`
585
588
  ].join(" ");
586
589
  }
590
+ var UPGRADE = [
591
+ "The app was made from an older scaffold than Teable's newest, so its AGENTS.md may say how",
592
+ "apps were built then: before anything else, run `teable-next upgrade`, which replaces AGENTS.md",
593
+ "and moves the app's packages to the versions apps build with now. Then read AGENTS.md again,",
594
+ "all of it, run the checks and fix what they find, and commit the upgrade with your change."
595
+ ].join(" ");
587
596
  function unnamed(appId) {
588
597
  return [
589
598
  where(appId),
@@ -631,21 +640,37 @@ function clone(appId, dir, env) {
631
640
  );
632
641
  });
633
642
  }
643
+ function behind(cwd, env) {
644
+ return new Promise((resolve) => {
645
+ execFile(
646
+ "teable-next",
647
+ ["upgrade", "--check"],
648
+ { cwd, env, timeout: CHECK_TIMEOUT_MS, maxBuffer: 1 << 20 },
649
+ (error, stdout) => resolve(error === null && fieldOf(stdout, "behind") === true)
650
+ );
651
+ });
652
+ }
653
+ async function upgradedFirst(made, appId, env) {
654
+ if (!await behind(made.cwd, env)) return made;
655
+ return { ...made, rules: `${made.rules ?? where(appId)} ${UPGRADE}` };
656
+ }
634
657
  var cloning = /* @__PURE__ */ new Map();
635
658
  function checkout(home2, appId, env, log2) {
636
659
  if (!APP_DIRECTORY.test(appId)) {
637
660
  return Promise.reject(new Error(`"${appId}" is not an app id`));
638
661
  }
639
662
  const cwd = join2(home2, "apps", appId);
640
- if (existsSync(cwd)) return Promise.resolve({ cwd, rules: null });
641
663
  const running = cloning.get(cwd);
642
664
  if (running) return running;
665
+ if (existsSync(cwd) && readdirSync(cwd).length > 0) {
666
+ return upgradedFirst({ cwd, rules: null }, appId, env);
667
+ }
643
668
  const made = (async () => {
644
669
  mkdirSync2(join2(home2, "apps"), { recursive: true });
645
670
  log2(`cloning ${appId} into ${cwd}`);
646
671
  const cloned = await clone(appId, cwd, env);
647
672
  if (cloned.kind === "cloned" && existsSync(cwd)) {
648
- return { cwd, rules: cloned.named ? null : unnamed(appId) };
673
+ return upgradedFirst({ cwd, rules: cloned.named ? null : unnamed(appId) }, appId, env);
649
674
  }
650
675
  mkdirSync2(cwd, { recursive: true });
651
676
  switch (cloned.kind) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@teable/agent-gateway",
3
- "version": "1.0.13",
3
+ "version": "1.0.15",
4
4
  "description": "The agent gateway in a person's Teable sandbox: starts an ACP agent for each session and relays it to the person's hub",
5
5
  "license": "MIT",
6
6
  "repository": {