tencil 0.4.0 → 0.5.0
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/cli.mjs +20 -101
- package/dist/cloud-CiwIrP1h.mjs +104 -0
- package/dist/cloud-Ez2olqK0.d.mts +14 -0
- package/dist/index-DzR4m_IL.d.mts +341 -0
- package/dist/index.d.mts +1 -340
- package/dist/index.mjs +1 -1
- package/dist/overlay.global.js +23 -23
- package/dist/react.d.mts +10 -3
- package/dist/react.mjs +20 -5
- package/dist/{server-9m0nvaLs.mjs → server-DZUEgjla.mjs} +15 -2
- package/dist/vite.d.mts +14 -3
- package/dist/vite.mjs +23 -4
- package/package.json +3 -3
package/dist/cli.mjs
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { _ as parsePairingInput, a as detectAgents, c as savedProvider, f as VERSION, g as exchangePairingCredential, h as createLocalPairingCode, i as PROVIDERS, m as DEFAULT_T3_URL, n as probeDaemon, o as providerLabel, p as CredentialStore, r as startDaemon, s as saveProvider, t as DEFAULT_PORT, u as defaultDataDir, v as withoutNpmEnv, y as loadAgentSdk } from "./server-
|
|
2
|
+
import { _ as parsePairingInput, a as detectAgents, c as savedProvider, f as VERSION, g as exchangePairingCredential, h as createLocalPairingCode, i as PROVIDERS, m as DEFAULT_T3_URL, n as probeDaemon, o as providerLabel, p as CredentialStore, r as startDaemon, s as saveProvider, t as DEFAULT_PORT, u as defaultDataDir, v as withoutNpmEnv, y as loadAgentSdk } from "./server-DZUEgjla.mjs";
|
|
3
|
+
import { t as DEFAULT_CLOUD_URL } from "./cloud-CiwIrP1h.mjs";
|
|
3
4
|
import { execFileSync, spawn, spawnSync } from "node:child_process";
|
|
4
|
-
import {
|
|
5
|
+
import { existsSync, mkdirSync, openSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
5
6
|
import { readFile, readdir, writeFile } from "node:fs/promises";
|
|
6
7
|
import { basename, dirname, join, relative, resolve } from "node:path";
|
|
7
8
|
import { parseArgs } from "node:util";
|
|
@@ -668,14 +669,6 @@ function skipString(source, start) {
|
|
|
668
669
|
else if (source[i] === quote) return i;
|
|
669
670
|
return source.length;
|
|
670
671
|
}
|
|
671
|
-
/** Projects set up while Tencil was called Fixhere (up to 0.2.0) import it under the old name. */
|
|
672
|
-
function usesFixhere(source) {
|
|
673
|
-
return /(['"])fixhere\/(?:react|vite)\1/.test(source);
|
|
674
|
-
}
|
|
675
|
-
/** Point a Fixhere integration at Tencil: `fixhere/react` → `tencil/react`, `<Fixhere />` → `<Tencil />`. */
|
|
676
|
-
function renameFromFixhere(source) {
|
|
677
|
-
return source.replace(/(['"])fixhere\/(react|vite)\1/g, "$1tencil/$2$1").replace(/\bFixhere\b/g, "Tencil").replace(/\bimport\s+fixhere\b/g, "import tencil").replace(/\bfixhere\(/g, "tencil(");
|
|
678
|
-
}
|
|
679
672
|
//#endregion
|
|
680
673
|
//#region src/init/detect-framework.ts
|
|
681
674
|
/** Inspect a project folder to decide how Tencil should be wired in. */
|
|
@@ -788,9 +781,6 @@ function installCommand(manager, spec) {
|
|
|
788
781
|
]];
|
|
789
782
|
}
|
|
790
783
|
}
|
|
791
|
-
function uninstallCommand(manager, name) {
|
|
792
|
-
return manager === "npm" ? ["npm", ["uninstall", name]] : [manager, ["remove", name]];
|
|
793
|
-
}
|
|
794
784
|
function variants(bases, extensions) {
|
|
795
785
|
return bases.flatMap((base) => extensions.map((ext) => `${base}.${ext}`));
|
|
796
786
|
}
|
|
@@ -858,15 +848,7 @@ async function planInit(root) {
|
|
|
858
848
|
const edit = async (path, codemod, instruction) => {
|
|
859
849
|
if (!path) return void manual.push(instruction);
|
|
860
850
|
const before = await readFile(path, "utf8");
|
|
861
|
-
if (
|
|
862
|
-
edits.push({
|
|
863
|
-
path,
|
|
864
|
-
before,
|
|
865
|
-
after: renameFromFixhere(before)
|
|
866
|
-
});
|
|
867
|
-
return;
|
|
868
|
-
}
|
|
869
|
-
if (/(?:tencil|fixhere)\.js/.test(before)) {
|
|
851
|
+
if (/tencil\.js/.test(before)) {
|
|
870
852
|
manual.push(`${relative(root, path)} loads tencil.js by hand. Replace that tag with \`<Tencil />\` from \`tencil/react\` so the bridge's port is picked up automatically.`);
|
|
871
853
|
return;
|
|
872
854
|
}
|
|
@@ -928,8 +910,8 @@ async function runInit(options) {
|
|
|
928
910
|
for (const edit of plan.edits) await writeFile(edit.path, edit.after);
|
|
929
911
|
if (!options.skipInstall && plan.framework.kind !== "unknown") {
|
|
930
912
|
if (!await hasDependency(options.root, "tencil") || options.from) install(options, log);
|
|
931
|
-
if (await hasDependency(options.root, "fixhere")) uninstall(options, "fixhere", log);
|
|
932
913
|
}
|
|
914
|
+
if (options.cloud) return logCloudSteps(plan.framework, log);
|
|
933
915
|
let autostart = false;
|
|
934
916
|
if (options.daemon) {
|
|
935
917
|
const result = await ensureDaemon(options.daemon, defaultDataDir());
|
|
@@ -945,6 +927,16 @@ async function runInit(options) {
|
|
|
945
927
|
if (options.daemon && !autostart) log(pc.dim(" Start Tencil at login: npx tencil setup"));
|
|
946
928
|
log("");
|
|
947
929
|
}
|
|
930
|
+
/** What's left to do in Tencil Cloud and the host once the code is in place. */
|
|
931
|
+
function logCloudSteps(framework, log) {
|
|
932
|
+
const env = pc.cyan("TENCIL_CLOUD=<project key>");
|
|
933
|
+
log(` ${pc.green("✓")} The overlay loads from Tencil Cloud on preview builds that set ${env}.`);
|
|
934
|
+
log(` 1. Create a project at ${pc.cyan(DEFAULT_CLOUD_URL)} and copy its key.`);
|
|
935
|
+
log(` 2. Add ${env} to your host's ${pc.bold("Preview")} environment only (Vercel: Settings → Environment Variables).`);
|
|
936
|
+
log(" 3. Redeploy a preview. Production deployments never load the overlay.");
|
|
937
|
+
if (framework.kind === "next-app" || framework.kind === "next-pages") log(pc.dim(" Keep <Tencil /> in a server component: it reads TENCIL_CLOUD when the page renders."));
|
|
938
|
+
log("");
|
|
939
|
+
}
|
|
948
940
|
/** Already a dependency (and no other package asked for with `--from`)? */
|
|
949
941
|
async function hasDependency(root, name) {
|
|
950
942
|
try {
|
|
@@ -954,16 +946,6 @@ async function hasDependency(root, name) {
|
|
|
954
946
|
return false;
|
|
955
947
|
}
|
|
956
948
|
}
|
|
957
|
-
function uninstall(options, name, log) {
|
|
958
|
-
const [command, args] = uninstallCommand(detectPackageManager(options.root), name);
|
|
959
|
-
log(` ${pc.dim(`$ ${command} ${args.join(" ")}`)}`);
|
|
960
|
-
spawnSync(command, args, {
|
|
961
|
-
cwd: options.root,
|
|
962
|
-
stdio: "inherit",
|
|
963
|
-
shell: process.platform === "win32",
|
|
964
|
-
env: withoutNpmEnv()
|
|
965
|
-
});
|
|
966
|
-
}
|
|
967
949
|
function install(options, log) {
|
|
968
950
|
const [command, args] = installCommand(detectPackageManager(options.root), options.from ?? "tencil");
|
|
969
951
|
log(` ${pc.dim(`$ ${command} ${args.join(" ")}`)}`);
|
|
@@ -983,64 +965,6 @@ function describe(framework) {
|
|
|
983
965
|
}
|
|
984
966
|
}
|
|
985
967
|
//#endregion
|
|
986
|
-
//#region src/service/migrate-from-fixhere.ts
|
|
987
|
-
/** What Fixhere (Tencil's name up to 0.2.0) called its login service. */
|
|
988
|
-
function fixhereServiceNames(port = DEFAULT_PORT) {
|
|
989
|
-
const names = [{
|
|
990
|
-
label: "dev.fixhere.daemon",
|
|
991
|
-
unit: "fixhere.service",
|
|
992
|
-
task: "Fixhere"
|
|
993
|
-
}];
|
|
994
|
-
if (port !== 4747) names.push({
|
|
995
|
-
label: `dev.fixhere.daemon.${port}`,
|
|
996
|
-
unit: `fixhere-${port}.service`,
|
|
997
|
-
task: `Fixhere ${port}`
|
|
998
|
-
});
|
|
999
|
-
return names;
|
|
1000
|
-
}
|
|
1001
|
-
/** Files that move to Tencil's data folder: pins, pairing, settings. Not the runtime copy or logs. */
|
|
1002
|
-
function carriesOver(path) {
|
|
1003
|
-
const name = basename(path);
|
|
1004
|
-
return !/^runtime(-\d+)?$/.test(name) && name !== "daemon.log";
|
|
1005
|
-
}
|
|
1006
|
-
/**
|
|
1007
|
-
* Move a Fixhere install over to Tencil, once: copy its data folder, remove its
|
|
1008
|
-
* login service and stop its daemon, which would otherwise hold the port.
|
|
1009
|
-
*/
|
|
1010
|
-
async function migrateFromFixhere(port, dataDir, log) {
|
|
1011
|
-
const steps = [];
|
|
1012
|
-
const oldDir = join(dirname(dataDir), "fixhere");
|
|
1013
|
-
if (existsSync(oldDir) && !existsSync(dataDir)) {
|
|
1014
|
-
cpSync(oldDir, dataDir, {
|
|
1015
|
-
recursive: true,
|
|
1016
|
-
filter: carriesOver
|
|
1017
|
-
});
|
|
1018
|
-
steps.push("pins and pairing");
|
|
1019
|
-
}
|
|
1020
|
-
for (const names of fixhereServiceNames(port)) {
|
|
1021
|
-
if (servicePort(readServiceDefinition(names)) !== port) continue;
|
|
1022
|
-
removeService(names);
|
|
1023
|
-
steps.push("login service");
|
|
1024
|
-
}
|
|
1025
|
-
if (await stopFixhereDaemon(port)) steps.push("daemon");
|
|
1026
|
-
if (steps.length) log(`\n ${pc.green("✓")} Moved Fixhere over to Tencil ${pc.dim(`(${[...new Set(steps)].join(", ")})`)}`);
|
|
1027
|
-
}
|
|
1028
|
-
/** A Fixhere daemon on `port` answers /health as "fixhere"; stop it so Tencil can listen. */
|
|
1029
|
-
async function stopFixhereDaemon(port) {
|
|
1030
|
-
const health = await fetch(`http://127.0.0.1:${port}/health`, { signal: AbortSignal.timeout(1500) }).then((response) => response.json()).catch(() => void 0);
|
|
1031
|
-
if (health?.name !== "fixhere" || !health.pid) return false;
|
|
1032
|
-
try {
|
|
1033
|
-
process.kill(health.pid, "SIGTERM");
|
|
1034
|
-
} catch {
|
|
1035
|
-
return false;
|
|
1036
|
-
}
|
|
1037
|
-
for (let attempt = 0; attempt < 50; attempt++) {
|
|
1038
|
-
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
1039
|
-
if (!await fetch(`http://127.0.0.1:${port}/health`, { signal: AbortSignal.timeout(500) }).catch(() => void 0)) return true;
|
|
1040
|
-
}
|
|
1041
|
-
return true;
|
|
1042
|
-
}
|
|
1043
|
-
//#endregion
|
|
1044
968
|
//#region src/cli/commands/connect.ts
|
|
1045
969
|
async function connect(input, t3Url) {
|
|
1046
970
|
const store = new CredentialStore();
|
|
@@ -1327,18 +1251,12 @@ ${pc.dim("Setup and init options")}
|
|
|
1327
1251
|
--dry-run Show the changes without writing them
|
|
1328
1252
|
--skip-install Don't install the tencil package
|
|
1329
1253
|
--skip-pair Don't pair with T3 Code
|
|
1254
|
+
--cloud init: set up for Tencil Cloud previews (no daemon on this machine)
|
|
1330
1255
|
--from <spec> Package to install instead of "tencil" (e.g. a local path)
|
|
1331
1256
|
|
|
1332
1257
|
-h, --help Show help
|
|
1333
1258
|
-v, --version Show version
|
|
1334
1259
|
`;
|
|
1335
|
-
/** Commands that start or install the daemon. */
|
|
1336
|
-
const SETS_UP = [
|
|
1337
|
-
"setup",
|
|
1338
|
-
"start",
|
|
1339
|
-
"init",
|
|
1340
|
-
"service"
|
|
1341
|
-
];
|
|
1342
1260
|
async function main() {
|
|
1343
1261
|
const { values, positionals } = parseArgs({
|
|
1344
1262
|
allowPositionals: true,
|
|
@@ -1366,6 +1284,7 @@ async function main() {
|
|
|
1366
1284
|
"dry-run": { type: "boolean" },
|
|
1367
1285
|
"skip-install": { type: "boolean" },
|
|
1368
1286
|
"skip-pair": { type: "boolean" },
|
|
1287
|
+
cloud: { type: "boolean" },
|
|
1369
1288
|
from: { type: "string" },
|
|
1370
1289
|
help: {
|
|
1371
1290
|
type: "boolean",
|
|
@@ -1393,7 +1312,6 @@ async function main() {
|
|
|
1393
1312
|
port,
|
|
1394
1313
|
args: forwardedFlags(values)
|
|
1395
1314
|
};
|
|
1396
|
-
if (command === void 0 || SETS_UP.includes(command)) await migrateFromFixhere(port, defaultDataDir(), console.log);
|
|
1397
1315
|
switch (command) {
|
|
1398
1316
|
case void 0: return quickstart(daemonCommand, {
|
|
1399
1317
|
root: resolve(values.root ?? process.cwd()),
|
|
@@ -1430,8 +1348,9 @@ async function main() {
|
|
|
1430
1348
|
skipPair: values["skip-pair"],
|
|
1431
1349
|
from: values.from,
|
|
1432
1350
|
port,
|
|
1433
|
-
daemon: daemonCommand,
|
|
1434
|
-
t3Url
|
|
1351
|
+
daemon: values.cloud ? void 0 : daemonCommand,
|
|
1352
|
+
t3Url,
|
|
1353
|
+
cloud: values.cloud
|
|
1435
1354
|
});
|
|
1436
1355
|
default:
|
|
1437
1356
|
console.error(`Unknown command "${command}"\n${HELP}`);
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
//#region src/integrations/cloud.ts
|
|
2
|
+
/** Where Tencil Cloud serves the overlay and its bridge. */
|
|
3
|
+
const DEFAULT_CLOUD_URL = "https://cloud.tencil.dev";
|
|
4
|
+
const PROJECT_KEY = /^[A-Za-z0-9_-]{8,64}$/;
|
|
5
|
+
const REPO = /^[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+$/;
|
|
6
|
+
const SHA = /^[0-9a-f]{7,64}$/i;
|
|
7
|
+
/**
|
|
8
|
+
* Whether this build loads the overlay from Tencil Cloud. Only when a project key
|
|
9
|
+
* is set, and never for a production deployment: the overlay lets reviewers make
|
|
10
|
+
* an agent change the code, so it belongs on previews only. Repo, branch and
|
|
11
|
+
* commit come from the host (Vercel, Netlify, Cloudflare Pages, GitHub Actions),
|
|
12
|
+
* so the cloud knows which code the page was built from.
|
|
13
|
+
*/
|
|
14
|
+
function resolveCloudBuild(env, options = {}) {
|
|
15
|
+
const projectKey = options.project ?? env.TENCIL_CLOUD;
|
|
16
|
+
if (!projectKey) return { kind: "off" };
|
|
17
|
+
if (!PROJECT_KEY.test(projectKey)) return {
|
|
18
|
+
kind: "refused",
|
|
19
|
+
reason: "TENCIL_CLOUD is not a Tencil Cloud project key."
|
|
20
|
+
};
|
|
21
|
+
const production = productionDeployment(env);
|
|
22
|
+
if (production) return {
|
|
23
|
+
kind: "refused",
|
|
24
|
+
reason: `${production}: the overlay only loads on previews.`
|
|
25
|
+
};
|
|
26
|
+
const repo = options.repo ?? env.TENCIL_CLOUD_REPO ?? hostRepo(env);
|
|
27
|
+
const branch = options.branch ?? env.TENCIL_CLOUD_BRANCH ?? hostBranch(env);
|
|
28
|
+
const sha = options.sha ?? env.TENCIL_CLOUD_SHA ?? hostSha(env);
|
|
29
|
+
const missing = [
|
|
30
|
+
!repo && "repository",
|
|
31
|
+
!branch && "branch",
|
|
32
|
+
!sha && "commit"
|
|
33
|
+
].filter(Boolean);
|
|
34
|
+
if (missing.length) return {
|
|
35
|
+
kind: "refused",
|
|
36
|
+
reason: `No ${missing.join(", ")} found for this build. Set TENCIL_CLOUD_REPO, TENCIL_CLOUD_BRANCH and TENCIL_CLOUD_SHA.`
|
|
37
|
+
};
|
|
38
|
+
if (!REPO.test(repo)) return {
|
|
39
|
+
kind: "refused",
|
|
40
|
+
reason: `"${repo}" is not a GitHub repository (owner/name).`
|
|
41
|
+
};
|
|
42
|
+
if (!SHA.test(sha)) return {
|
|
43
|
+
kind: "refused",
|
|
44
|
+
reason: `"${sha}" is not a commit hash.`
|
|
45
|
+
};
|
|
46
|
+
const url = (options.url ?? env.TENCIL_CLOUD_URL ?? "https://cloud.tencil.dev").replace(/\/+$/, "");
|
|
47
|
+
if (!/^https?:\/\//.test(url)) return {
|
|
48
|
+
kind: "refused",
|
|
49
|
+
reason: `TENCIL_CLOUD_URL "${url}" is not an http(s) URL.`
|
|
50
|
+
};
|
|
51
|
+
return {
|
|
52
|
+
kind: "on",
|
|
53
|
+
url,
|
|
54
|
+
build: {
|
|
55
|
+
projectKey,
|
|
56
|
+
repo,
|
|
57
|
+
branch,
|
|
58
|
+
sha: sha.toLowerCase()
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
/** The host's name for a production deployment, if this is one. */
|
|
63
|
+
function productionDeployment(env) {
|
|
64
|
+
if (env.VERCEL_ENV === "production") return "VERCEL_ENV is production";
|
|
65
|
+
if (env.NETLIFY && env.CONTEXT === "production") return "Netlify CONTEXT is production";
|
|
66
|
+
if (env.TENCIL_CLOUD_ENV === "production") return "TENCIL_CLOUD_ENV is production";
|
|
67
|
+
}
|
|
68
|
+
function hostRepo(env) {
|
|
69
|
+
if (env.VERCEL_GIT_REPO_OWNER && env.VERCEL_GIT_REPO_SLUG) return `${env.VERCEL_GIT_REPO_OWNER}/${env.VERCEL_GIT_REPO_SLUG}`;
|
|
70
|
+
if (env.GITHUB_REPOSITORY) return env.GITHUB_REPOSITORY;
|
|
71
|
+
return (env.REPOSITORY_URL?.match(/github\.com[/:]([^/]+\/[^/]+?)(?:\.git)?$/))?.[1];
|
|
72
|
+
}
|
|
73
|
+
function hostBranch(env) {
|
|
74
|
+
return env.VERCEL_GIT_COMMIT_REF ?? env.CF_PAGES_BRANCH ?? (env.NETLIFY ? env.HEAD : void 0) ?? env.GITHUB_HEAD_REF ?? env.GITHUB_REF_NAME;
|
|
75
|
+
}
|
|
76
|
+
function hostSha(env) {
|
|
77
|
+
return env.VERCEL_GIT_COMMIT_SHA ?? env.CF_PAGES_COMMIT_SHA ?? (env.NETLIFY ? env.COMMIT_REF : void 0) ?? env.GITHUB_SHA;
|
|
78
|
+
}
|
|
79
|
+
/** A JSON string literal that is also safe inside an inline `<script>`. */
|
|
80
|
+
function scriptString(value) {
|
|
81
|
+
return JSON.stringify(value).replace(/</g, "\\u003c");
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Browser code that loads the overlay from Tencil Cloud. The script tag carries
|
|
85
|
+
* the build, which the overlay passes on when it connects.
|
|
86
|
+
*/
|
|
87
|
+
function cloudLoader({ url, build }) {
|
|
88
|
+
return `;(() => {
|
|
89
|
+
if (typeof document === "undefined") return;
|
|
90
|
+
const src = ${scriptString(`${url}/tencil.js`)};
|
|
91
|
+
if (document.querySelector('script[src="' + src + '"]')) return;
|
|
92
|
+
const script = document.createElement("script");
|
|
93
|
+
script.src = src;
|
|
94
|
+
script.async = true;
|
|
95
|
+
script.dataset.bridge = ${scriptString(url)};
|
|
96
|
+
script.dataset.tencilProject = ${scriptString(build.projectKey)};
|
|
97
|
+
script.dataset.tencilRepo = ${scriptString(build.repo)};
|
|
98
|
+
script.dataset.tencilBranch = ${scriptString(build.branch)};
|
|
99
|
+
script.dataset.tencilSha = ${scriptString(build.sha)};
|
|
100
|
+
document.head.appendChild(script);
|
|
101
|
+
})();`;
|
|
102
|
+
}
|
|
103
|
+
//#endregion
|
|
104
|
+
export { cloudLoader as n, resolveCloudBuild as r, DEFAULT_CLOUD_URL as t };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import "./index-DzR4m_IL.mjs";
|
|
2
|
+
//#region src/integrations/cloud.d.ts
|
|
3
|
+
interface TencilCloudOptions {
|
|
4
|
+
/** Project key from the Tencil Cloud dashboard. Defaults to TENCIL_CLOUD. */
|
|
5
|
+
project?: string;
|
|
6
|
+
/** `owner/name` on GitHub. Defaults to the host's git env vars. */
|
|
7
|
+
repo?: string;
|
|
8
|
+
branch?: string;
|
|
9
|
+
sha?: string;
|
|
10
|
+
/** Tencil Cloud itself; only for testing against a local one. Defaults to TENCIL_CLOUD_URL. */
|
|
11
|
+
url?: string;
|
|
12
|
+
}
|
|
13
|
+
//#endregion
|
|
14
|
+
export { TencilCloudOptions as t };
|
|
@@ -0,0 +1,341 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
//#region ../protocol/src/context.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* Everything the overlay knows about the picked element. Captured once when
|
|
5
|
+
* the pin is placed and forwarded to the agent as context.
|
|
6
|
+
*/
|
|
7
|
+
declare const ElementContext: z.ZodObject<{
|
|
8
|
+
tagName: z.ZodString;
|
|
9
|
+
selector: z.ZodString;
|
|
10
|
+
html: z.ZodString;
|
|
11
|
+
text: z.ZodOptional<z.ZodString>;
|
|
12
|
+
components: z.ZodDefault<z.ZodArray<z.ZodObject<{
|
|
13
|
+
name: z.ZodString;
|
|
14
|
+
source: z.ZodOptional<z.ZodObject<{
|
|
15
|
+
file: z.ZodString;
|
|
16
|
+
line: z.ZodOptional<z.ZodNumber>;
|
|
17
|
+
column: z.ZodOptional<z.ZodNumber>;
|
|
18
|
+
}, z.core.$strip>>;
|
|
19
|
+
library: z.ZodOptional<z.ZodString>;
|
|
20
|
+
}, z.core.$strip>>>;
|
|
21
|
+
rect: z.ZodObject<{
|
|
22
|
+
x: z.ZodNumber;
|
|
23
|
+
y: z.ZodNumber;
|
|
24
|
+
width: z.ZodNumber;
|
|
25
|
+
height: z.ZodNumber;
|
|
26
|
+
}, z.core.$strip>;
|
|
27
|
+
viewport: z.ZodObject<{
|
|
28
|
+
width: z.ZodNumber;
|
|
29
|
+
height: z.ZodNumber;
|
|
30
|
+
dpr: z.ZodNumber;
|
|
31
|
+
}, z.core.$strip>;
|
|
32
|
+
selection: z.ZodOptional<z.ZodString>;
|
|
33
|
+
}, z.core.$strip>;
|
|
34
|
+
type ElementContext = z.infer<typeof ElementContext>;
|
|
35
|
+
declare const ImageAttachment: z.ZodObject<{
|
|
36
|
+
name: z.ZodString;
|
|
37
|
+
mimeType: z.ZodEnum<{
|
|
38
|
+
"image/png": "image/png";
|
|
39
|
+
"image/jpeg": "image/jpeg";
|
|
40
|
+
"image/webp": "image/webp";
|
|
41
|
+
}>;
|
|
42
|
+
dataUrl: z.ZodString;
|
|
43
|
+
}, z.core.$strip>;
|
|
44
|
+
type ImageAttachment = z.infer<typeof ImageAttachment>;
|
|
45
|
+
//#endregion
|
|
46
|
+
//#region ../protocol/src/thread.d.ts
|
|
47
|
+
/**
|
|
48
|
+
* Provider-agnostic run state.
|
|
49
|
+
* - `draft`: a comment queued in a batch, not sent to the agent yet
|
|
50
|
+
* - `starting`: thread is being created on the provider
|
|
51
|
+
* - `working`: the agent is producing a turn
|
|
52
|
+
* - `waiting`: the agent needs approval/input inside the provider UI
|
|
53
|
+
* - `idle`: last turn finished, ready for a follow-up
|
|
54
|
+
* - `error`: last turn or the thread itself failed
|
|
55
|
+
*/
|
|
56
|
+
declare const ThreadStatus: z.ZodEnum<{
|
|
57
|
+
error: "error";
|
|
58
|
+
draft: "draft";
|
|
59
|
+
starting: "starting";
|
|
60
|
+
working: "working";
|
|
61
|
+
waiting: "waiting";
|
|
62
|
+
idle: "idle";
|
|
63
|
+
}>;
|
|
64
|
+
type ThreadStatus = z.infer<typeof ThreadStatus>;
|
|
65
|
+
declare const MessageRole: z.ZodEnum<{
|
|
66
|
+
user: "user";
|
|
67
|
+
assistant: "assistant";
|
|
68
|
+
system: "system";
|
|
69
|
+
}>;
|
|
70
|
+
type MessageRole = z.infer<typeof MessageRole>;
|
|
71
|
+
/**
|
|
72
|
+
* A conversation Tencil tracks, backed by one provider thread. Owned and
|
|
73
|
+
* persisted by the bridge. Pinned threads sit on an element of a page;
|
|
74
|
+
* threads opened from the provider's list have no anchor and live in the dock.
|
|
75
|
+
* Several pins may continue the same provider thread.
|
|
76
|
+
*/
|
|
77
|
+
declare const Thread: z.ZodObject<{
|
|
78
|
+
id: z.ZodString;
|
|
79
|
+
title: z.ZodString;
|
|
80
|
+
pageUrl: z.ZodOptional<z.ZodString>;
|
|
81
|
+
anchor: z.ZodOptional<z.ZodObject<{
|
|
82
|
+
selector: z.ZodString;
|
|
83
|
+
offsetX: z.ZodNumber;
|
|
84
|
+
offsetY: z.ZodNumber;
|
|
85
|
+
}, z.core.$strip>>;
|
|
86
|
+
context: z.ZodOptional<z.ZodObject<{
|
|
87
|
+
tagName: z.ZodString;
|
|
88
|
+
selector: z.ZodString;
|
|
89
|
+
html: z.ZodString;
|
|
90
|
+
text: z.ZodOptional<z.ZodString>;
|
|
91
|
+
components: z.ZodDefault<z.ZodArray<z.ZodObject<{
|
|
92
|
+
name: z.ZodString;
|
|
93
|
+
source: z.ZodOptional<z.ZodObject<{
|
|
94
|
+
file: z.ZodString;
|
|
95
|
+
line: z.ZodOptional<z.ZodNumber>;
|
|
96
|
+
column: z.ZodOptional<z.ZodNumber>;
|
|
97
|
+
}, z.core.$strip>>;
|
|
98
|
+
library: z.ZodOptional<z.ZodString>;
|
|
99
|
+
}, z.core.$strip>>>;
|
|
100
|
+
rect: z.ZodObject<{
|
|
101
|
+
x: z.ZodNumber;
|
|
102
|
+
y: z.ZodNumber;
|
|
103
|
+
width: z.ZodNumber;
|
|
104
|
+
height: z.ZodNumber;
|
|
105
|
+
}, z.core.$strip>;
|
|
106
|
+
viewport: z.ZodObject<{
|
|
107
|
+
width: z.ZodNumber;
|
|
108
|
+
height: z.ZodNumber;
|
|
109
|
+
dpr: z.ZodNumber;
|
|
110
|
+
}, z.core.$strip>;
|
|
111
|
+
selection: z.ZodOptional<z.ZodString>;
|
|
112
|
+
}, z.core.$strip>>;
|
|
113
|
+
status: z.ZodEnum<{
|
|
114
|
+
error: "error";
|
|
115
|
+
draft: "draft";
|
|
116
|
+
starting: "starting";
|
|
117
|
+
working: "working";
|
|
118
|
+
waiting: "waiting";
|
|
119
|
+
idle: "idle";
|
|
120
|
+
}>;
|
|
121
|
+
statusDetail: z.ZodOptional<z.ZodString>;
|
|
122
|
+
resolved: z.ZodDefault<z.ZodBoolean>;
|
|
123
|
+
messages: z.ZodArray<z.ZodObject<{
|
|
124
|
+
id: z.ZodString;
|
|
125
|
+
role: z.ZodEnum<{
|
|
126
|
+
user: "user";
|
|
127
|
+
assistant: "assistant";
|
|
128
|
+
system: "system";
|
|
129
|
+
}>;
|
|
130
|
+
text: z.ZodString;
|
|
131
|
+
streaming: z.ZodDefault<z.ZodBoolean>;
|
|
132
|
+
createdAt: z.ZodString;
|
|
133
|
+
}, z.core.$strip>>;
|
|
134
|
+
provider: z.ZodObject<{
|
|
135
|
+
id: z.ZodString;
|
|
136
|
+
threadId: z.ZodOptional<z.ZodString>;
|
|
137
|
+
url: z.ZodOptional<z.ZodString>;
|
|
138
|
+
}, z.core.$strip>;
|
|
139
|
+
createdAt: z.ZodString;
|
|
140
|
+
updatedAt: z.ZodString;
|
|
141
|
+
}, z.core.$strip>;
|
|
142
|
+
type Thread = z.infer<typeof Thread>;
|
|
143
|
+
/** A thread as listed by the provider (e.g. every T3 Code thread in the project). */
|
|
144
|
+
declare const ProviderThreadSummary: z.ZodObject<{
|
|
145
|
+
id: z.ZodString;
|
|
146
|
+
title: z.ZodString;
|
|
147
|
+
status: z.ZodEnum<{
|
|
148
|
+
error: "error";
|
|
149
|
+
working: "working";
|
|
150
|
+
waiting: "waiting";
|
|
151
|
+
idle: "idle";
|
|
152
|
+
}>;
|
|
153
|
+
updatedAt: z.ZodString;
|
|
154
|
+
url: z.ZodOptional<z.ZodString>;
|
|
155
|
+
branch: z.ZodOptional<z.ZodString>;
|
|
156
|
+
pullRequest: z.ZodOptional<z.ZodObject<{
|
|
157
|
+
number: z.ZodNumber;
|
|
158
|
+
url: z.ZodString;
|
|
159
|
+
}, z.core.$strip>>;
|
|
160
|
+
background: z.ZodOptional<z.ZodEnum<{
|
|
161
|
+
working: "working";
|
|
162
|
+
monitoring: "monitoring";
|
|
163
|
+
}>>;
|
|
164
|
+
agent: z.ZodOptional<z.ZodString>;
|
|
165
|
+
}, z.core.$strip>;
|
|
166
|
+
type ProviderThreadSummary = z.infer<typeof ProviderThreadSummary>;
|
|
167
|
+
/** A model a provider can start threads on, e.g. T3 Code's Claude Opus. */
|
|
168
|
+
declare const ProviderModel: z.ZodObject<{
|
|
169
|
+
id: z.ZodString;
|
|
170
|
+
label: z.ZodString;
|
|
171
|
+
group: z.ZodString;
|
|
172
|
+
agent: z.ZodOptional<z.ZodString>;
|
|
173
|
+
}, z.core.$strip>;
|
|
174
|
+
type ProviderModel = z.infer<typeof ProviderModel>;
|
|
175
|
+
/** How the provider presents the project the threads belong to. */
|
|
176
|
+
declare const ProviderProject: z.ZodObject<{
|
|
177
|
+
name: z.ZodString;
|
|
178
|
+
iconUrl: z.ZodOptional<z.ZodString>;
|
|
179
|
+
emoji: z.ZodOptional<z.ZodString>;
|
|
180
|
+
}, z.core.$strip>;
|
|
181
|
+
type ProviderProject = z.infer<typeof ProviderProject>;
|
|
182
|
+
//#endregion
|
|
183
|
+
//#region ../protocol/src/messages.d.ts
|
|
184
|
+
declare const PROTOCOL_VERSION = 1;
|
|
185
|
+
declare const ProviderInfo: z.ZodObject<{
|
|
186
|
+
id: z.ZodString;
|
|
187
|
+
label: z.ZodString;
|
|
188
|
+
state: z.ZodEnum<{
|
|
189
|
+
connecting: "connecting";
|
|
190
|
+
ready: "ready";
|
|
191
|
+
unauthorized: "unauthorized";
|
|
192
|
+
unavailable: "unavailable";
|
|
193
|
+
}>;
|
|
194
|
+
detail: z.ZodOptional<z.ZodString>;
|
|
195
|
+
target: z.ZodOptional<z.ZodString>;
|
|
196
|
+
canPair: z.ZodOptional<z.ZodBoolean>;
|
|
197
|
+
}, z.core.$strip>;
|
|
198
|
+
type ProviderInfo = z.infer<typeof ProviderInfo>;
|
|
199
|
+
/** A provider the project can send pins to. */
|
|
200
|
+
declare const ProviderOption: z.ZodObject<{
|
|
201
|
+
id: z.ZodString;
|
|
202
|
+
label: z.ZodString;
|
|
203
|
+
}, z.core.$strip>;
|
|
204
|
+
type ProviderOption = z.infer<typeof ProviderOption>;
|
|
205
|
+
/** Per-project settings, as the overlay shows them. */
|
|
206
|
+
declare const ProjectSettings: z.ZodObject<{
|
|
207
|
+
provider: z.ZodString;
|
|
208
|
+
providers: z.ZodArray<z.ZodObject<{
|
|
209
|
+
id: z.ZodString;
|
|
210
|
+
label: z.ZodString;
|
|
211
|
+
}, z.core.$strip>>;
|
|
212
|
+
model: z.ZodOptional<z.ZodString>;
|
|
213
|
+
batch: z.ZodBoolean;
|
|
214
|
+
}, z.core.$strip>;
|
|
215
|
+
type ProjectSettings = z.infer<typeof ProjectSettings>;
|
|
216
|
+
type ServerMessage = {
|
|
217
|
+
type: 'ready';
|
|
218
|
+
protocol: typeof PROTOCOL_VERSION;
|
|
219
|
+
version: string;
|
|
220
|
+
project: {
|
|
221
|
+
name: string;
|
|
222
|
+
root: string;
|
|
223
|
+
};
|
|
224
|
+
/** The provider new pins go to. */
|
|
225
|
+
provider: ProviderInfo;
|
|
226
|
+
settings: ProjectSettings;
|
|
227
|
+
threads: Thread[];
|
|
228
|
+
} | {
|
|
229
|
+
type: 'provider.status';
|
|
230
|
+
provider: ProviderInfo;
|
|
231
|
+
} | {
|
|
232
|
+
type: 'settings';
|
|
233
|
+
settings: ProjectSettings;
|
|
234
|
+
} |
|
|
235
|
+
/** The daemon couldn't tell which project this page belongs to; the overlay asks. */
|
|
236
|
+
{
|
|
237
|
+
type: 'project.unknown';
|
|
238
|
+
pageUrl: string;
|
|
239
|
+
choices: Array<{
|
|
240
|
+
root: string;
|
|
241
|
+
title: string;
|
|
242
|
+
}>;
|
|
243
|
+
/** What to do when there are no choices. */
|
|
244
|
+
emptyHint?: string;
|
|
245
|
+
} | {
|
|
246
|
+
type: 'thread.upsert';
|
|
247
|
+
thread: Thread;
|
|
248
|
+
} | {
|
|
249
|
+
type: 'thread.removed';
|
|
250
|
+
threadId: string;
|
|
251
|
+
} | {
|
|
252
|
+
type: 'provider.threads';
|
|
253
|
+
project: ProviderProject;
|
|
254
|
+
threads: ProviderThreadSummary[];
|
|
255
|
+
} | {
|
|
256
|
+
type: 'provider.models';
|
|
257
|
+
provider: string;
|
|
258
|
+
models: ProviderModel[];
|
|
259
|
+
/** What new threads run on when no model is picked. */
|
|
260
|
+
defaultModel?: string;
|
|
261
|
+
} | {
|
|
262
|
+
type: 'error';
|
|
263
|
+
message: string;
|
|
264
|
+
threadId?: string;
|
|
265
|
+
};
|
|
266
|
+
//#endregion
|
|
267
|
+
//#region ../protocol/src/provider.d.ts
|
|
268
|
+
/**
|
|
269
|
+
* A provider is the agent backend a pin is delegated to (T3 Code, Claude Code,
|
|
270
|
+
* …). The bridge owns pins and talks to exactly one provider per process; the
|
|
271
|
+
* provider owns the conversation.
|
|
272
|
+
*
|
|
273
|
+
* Providers only ever see plain text + images: the bridge renders element
|
|
274
|
+
* context into the prompt so every provider gets identical input.
|
|
275
|
+
*/
|
|
276
|
+
interface Provider {
|
|
277
|
+
readonly id: string;
|
|
278
|
+
readonly label: string;
|
|
279
|
+
/** Connect/authenticate. Must not throw; report problems through `info()`. */
|
|
280
|
+
start(): Promise<void>;
|
|
281
|
+
info(): ProviderInfo;
|
|
282
|
+
onInfoChange(listener: (info: ProviderInfo) => void): () => void;
|
|
283
|
+
/** Authorize against the provider (e.g. pair with T3 Code). Optional. */
|
|
284
|
+
pair?(): Promise<void>;
|
|
285
|
+
/** Threads that already exist for this project, newest first. */
|
|
286
|
+
listThreads(): Promise<{
|
|
287
|
+
project: ProviderProject;
|
|
288
|
+
threads: ProviderThreadSummary[];
|
|
289
|
+
}>;
|
|
290
|
+
/** Models new threads can run on, and the one they use by default. Optional. */
|
|
291
|
+
listModels?(): Promise<ProviderModels>;
|
|
292
|
+
/** Deep link into the provider UI for a thread, when it has one. */
|
|
293
|
+
threadUrl(providerThreadId: string): string | undefined;
|
|
294
|
+
createThread(input: CreateThreadInput): Promise<CreatedThread>;
|
|
295
|
+
sendMessage(input: SendMessageInput): Promise<void>;
|
|
296
|
+
interrupt(providerThreadId: string): Promise<void>;
|
|
297
|
+
/**
|
|
298
|
+
* Stream updates for a thread. Called right after `createThread` and again
|
|
299
|
+
* for every persisted thread when the bridge restarts. The provider should
|
|
300
|
+
* replay current state first, then live updates.
|
|
301
|
+
*/
|
|
302
|
+
watch(providerThreadId: string, sink: ThreadSink): () => void;
|
|
303
|
+
dispose(): Promise<void>;
|
|
304
|
+
}
|
|
305
|
+
interface CreateThreadInput {
|
|
306
|
+
title: string;
|
|
307
|
+
text: string;
|
|
308
|
+
attachments: ImageAttachment[];
|
|
309
|
+
/** A `ProviderModel.id` the user picked; the provider's default when absent or unknown. */
|
|
310
|
+
model?: string;
|
|
311
|
+
}
|
|
312
|
+
interface ProviderModels {
|
|
313
|
+
models: ProviderModel[];
|
|
314
|
+
/** `ProviderModel.id` new threads use when none is picked. */
|
|
315
|
+
defaultModel?: string;
|
|
316
|
+
}
|
|
317
|
+
interface CreatedThread {
|
|
318
|
+
providerThreadId: string;
|
|
319
|
+
url?: string;
|
|
320
|
+
}
|
|
321
|
+
interface SendMessageInput {
|
|
322
|
+
providerThreadId: string;
|
|
323
|
+
text: string;
|
|
324
|
+
attachments: ImageAttachment[];
|
|
325
|
+
}
|
|
326
|
+
interface ProviderMessage {
|
|
327
|
+
id: string;
|
|
328
|
+
role: MessageRole;
|
|
329
|
+
text: string;
|
|
330
|
+
streaming: boolean;
|
|
331
|
+
createdAt: string;
|
|
332
|
+
}
|
|
333
|
+
interface ThreadSink {
|
|
334
|
+
/** Upsert by `id`; `text` is cumulative. */
|
|
335
|
+
message(message: ProviderMessage): void;
|
|
336
|
+
status(status: Exclude<ThreadStatus, 'starting' | 'draft'>, detail?: string): void;
|
|
337
|
+
/** Provider no longer has this thread (deleted/archived on its side). */
|
|
338
|
+
gone(): void;
|
|
339
|
+
}
|
|
340
|
+
//#endregion
|
|
341
|
+
export { ElementContext as a, Thread as i, ProviderOption as n, ServerMessage as r, Provider as t };
|