gtmmaxing 0.1.1 → 0.1.2
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/README.md +3 -0
- package/dist/gtm.js +210 -38
- package/package.json +11 -10
package/README.md
CHANGED
|
@@ -25,6 +25,9 @@ gtm contacts satyanadella --verify --dry-run
|
|
|
25
25
|
gtm contacts --file leads.csv --verify --out enriched.csv --max-credits 50
|
|
26
26
|
gtm list --titles 'VP Sales' --location 'United States' --max-credits 20
|
|
27
27
|
gtm research acme.com --max-credits 5
|
|
28
|
+
gtm tools describe seo-aeo-audit
|
|
29
|
+
gtm tools run seo-aeo-audit --input '{"url":"example.com"}' --dry-run
|
|
30
|
+
gtm tools run seo-aeo-audit --input '{"url":"example.com"}' --max-credits 35
|
|
28
31
|
gtm results <run_id> --csv > out.csv
|
|
29
32
|
```
|
|
30
33
|
|
package/dist/gtm.js
CHANGED
|
@@ -10426,8 +10426,8 @@ var error43 = () => {
|
|
|
10426
10426
|
case "not_multiple_of":
|
|
10427
10427
|
return `N\xFAmero inv\xE1lido: deve ser m\xFAltiplo de ${issue2.divisor}`;
|
|
10428
10428
|
case "unrecognized_keys": {
|
|
10429
|
-
const
|
|
10430
|
-
return `Chave${
|
|
10429
|
+
const plural3 = issue2.keys.length > 1 ? "s" : "";
|
|
10430
|
+
return `Chave${plural3} inv\xE1lida${plural3}: ${joinValues(issue2.keys, ", ")}`;
|
|
10431
10431
|
}
|
|
10432
10432
|
case "invalid_key":
|
|
10433
10433
|
return `Entrada inv\xE1lida n${translateOriginWithArticle(issue2.origin, "definite")}`;
|
|
@@ -10569,8 +10569,8 @@ var error44 = () => {
|
|
|
10569
10569
|
case "not_multiple_of":
|
|
10570
10570
|
return `N\xFAmero inv\xE1lido: deve ser m\xFAltiplo de ${issue2.divisor}`;
|
|
10571
10571
|
case "unrecognized_keys": {
|
|
10572
|
-
const
|
|
10573
|
-
return `Chave${
|
|
10572
|
+
const plural3 = issue2.keys.length > 1 ? "s" : "";
|
|
10573
|
+
return `Chave${plural3} inv\xE1lida${plural3}: ${joinValues(issue2.keys, ", ")}`;
|
|
10574
10574
|
}
|
|
10575
10575
|
case "invalid_key":
|
|
10576
10576
|
return `Entrada inv\xE1lida n${translateOriginWithArticle(issue2.origin, "definite")}`;
|
|
@@ -18873,6 +18873,7 @@ function date4(params) {
|
|
|
18873
18873
|
|
|
18874
18874
|
// ../contracts/src/tools.ts
|
|
18875
18875
|
var TOOL_CATALOG = {
|
|
18876
|
+
"seo-aeo-audit": { name: "SEO/AEO audit", credits: 35, unit: "completed audit", limit: 1 },
|
|
18876
18877
|
company: { name: "Company enrichment", credits: 1, unit: "company", limit: 1 },
|
|
18877
18878
|
"local-leads": { name: "Local business leads", credits: 1, unit: "search (up to 20 businesses)", limit: 20 },
|
|
18878
18879
|
website: { name: "Website brief", credits: 1, unit: "brief", limit: 1 },
|
|
@@ -18883,6 +18884,7 @@ var TOOL_CATALOG = {
|
|
|
18883
18884
|
"people-search": { name: "People search", credits: 2, unit: "search (up to 20 people)", limit: 20 },
|
|
18884
18885
|
"google-search": { name: "Google search", credits: 1, unit: "search (up to 20 results)", limit: 20 },
|
|
18885
18886
|
"linkedin-profile": { name: "LinkedIn profile", credits: 1, unit: "profile", limit: 1 },
|
|
18887
|
+
"linkedin-activity": { name: "LinkedIn activity", credits: 1, unit: "profile with posts", limit: 1 },
|
|
18886
18888
|
"page-content": { name: "Web page content", credits: 1, unit: "page", limit: 1 }
|
|
18887
18889
|
};
|
|
18888
18890
|
var toolIdSchema = external_exports.enum(Object.keys(TOOL_CATALOG));
|
|
@@ -18905,15 +18907,17 @@ var toolRequestSchema = external_exports.object({
|
|
|
18905
18907
|
company: external_exports.string().trim().max(100).default(""),
|
|
18906
18908
|
location: external_exports.string().trim().max(100).default(""),
|
|
18907
18909
|
titles: external_exports.string().trim().max(200).default(""),
|
|
18910
|
+
/** LinkedIn activity: comma-separated topics to look for in posts. Optional so older saved requests keep their hash. */
|
|
18911
|
+
keywords: external_exports.string().trim().max(300).optional(),
|
|
18908
18912
|
limit: external_exports.number().int().min(1).max(20).default(10)
|
|
18909
18913
|
}).strict().superRefine((v, c) => {
|
|
18910
18914
|
const reject = (message) => c.addIssue({ code: "custom", path: ["query"], message });
|
|
18911
18915
|
if (v.careerBoard && !/^https:\/\/(boards\.greenhouse\.io|jobs\.lever\.co)\/[a-zA-Z0-9_-]+\/?$/.test(v.careerBoard)) reject("Use a public Greenhouse or Lever company board URL.");
|
|
18912
|
-
if (["website", "page-content"].includes(v.tool) && !publicWebsite(websiteUrl(v.query))) reject("Enter a company website, like vercel.com.");
|
|
18916
|
+
if (["website", "page-content", "seo-aeo-audit"].includes(v.tool) && !publicWebsite(websiteUrl(v.query))) reject("Enter a company website, like vercel.com.");
|
|
18913
18917
|
if (["company", "icp"].includes(v.tool) && !publicWebsite(`https://${v.query.replace(/^https?:\/\//, "").replace(/\/$/, "")}`)) reject("Enter a public company domain.");
|
|
18914
18918
|
if (v.tool === "local-leads" && !v.location) reject("Add a city or region.");
|
|
18915
18919
|
if (v.tool === "verify-email" && !external_exports.string().email().safeParse(v.query).success) reject("Enter an email address.");
|
|
18916
|
-
if (["phone-pilot", "linkedin-profile"].includes(v.tool) && !/^https:\/\/(www\.)?linkedin\.com\/in\/[a-zA-Z0-9%_-]+\/?$/.test(v.query)) reject("Enter a LinkedIn profile URL.");
|
|
18920
|
+
if (["phone-pilot", "linkedin-profile", "linkedin-activity"].includes(v.tool) && !/^https:\/\/(www\.)?linkedin\.com\/in\/[a-zA-Z0-9%_-]+\/?$/.test(v.query)) reject("Enter a LinkedIn profile URL.");
|
|
18917
18921
|
});
|
|
18918
18922
|
var toolResultSchema = external_exports.object({
|
|
18919
18923
|
rows: external_exports.array(external_exports.record(external_exports.string(), external_exports.union([external_exports.string().max(1e5), external_exports.number(), external_exports.boolean(), external_exports.null()]))).max(20),
|
|
@@ -18939,22 +18943,38 @@ var optionalText = (max) => external_exports.string().trim().max(max).optional()
|
|
|
18939
18943
|
var limit = (id) => external_exports.number().int().min(1).max(TOOL_CATALOG[id].limit).optional();
|
|
18940
18944
|
var s = external_exports.string();
|
|
18941
18945
|
var n = external_exports.number().nullable();
|
|
18946
|
+
var MAX_BATCH_PEOPLE = 100;
|
|
18947
|
+
var batchPeople = external_exports.array(text(300)).min(1).max(MAX_BATCH_PEOPLE).optional().describe(`Up to ${MAX_BATCH_PEOPLE} LinkedIn profile URLs or handles, instead of profile`);
|
|
18942
18948
|
var toolPrice = (id, free = "Empty results are free.") => ({
|
|
18943
18949
|
credits: TOOL_CATALOG[id].credits,
|
|
18944
18950
|
unit: TOOL_CATALOG[id].unit,
|
|
18945
18951
|
basis: "run",
|
|
18946
18952
|
free
|
|
18947
18953
|
});
|
|
18954
|
+
function canonicalProfileSlug(slug) {
|
|
18955
|
+
return /^AC[ow]AA/.test(slug) ? slug : slug.toLowerCase();
|
|
18956
|
+
}
|
|
18948
18957
|
function linkedinProfileUrl(value) {
|
|
18949
18958
|
const trimmed = value.trim();
|
|
18950
|
-
if (/^[A-Za-z0-9][A-Za-z0-9_%-]{0,99}$/.test(trimmed)) return `https://www.linkedin.com/in/${trimmed
|
|
18959
|
+
if (/^[A-Za-z0-9][A-Za-z0-9_%-]{0,99}$/.test(trimmed)) return `https://www.linkedin.com/in/${canonicalProfileSlug(trimmed)}`;
|
|
18951
18960
|
const match = /^(?:https?:\/\/)?(?:www\.)?linkedin\.com\/in\/([A-Za-z0-9_%-]{1,100})\/?(?:[?#].*)?$/i.exec(trimmed);
|
|
18952
|
-
return match ? `https://www.linkedin.com/in/${match[1]
|
|
18961
|
+
return match ? `https://www.linkedin.com/in/${canonicalProfileSlug(match[1])}` : trimmed;
|
|
18953
18962
|
}
|
|
18954
18963
|
function capability(definition) {
|
|
18955
18964
|
return definition;
|
|
18956
18965
|
}
|
|
18957
18966
|
var CAPABILITIES = {
|
|
18967
|
+
"seo-aeo-audit": capability({
|
|
18968
|
+
title: "SEO/AEO audit",
|
|
18969
|
+
description: "RankAI website audit for search engine and answer engine optimization, with a report URL when complete.",
|
|
18970
|
+
input: external_exports.object({ url: text(300) }).strict(),
|
|
18971
|
+
row: external_exports.object({ url: s, auditId: s, status: s, reportUrl: s }),
|
|
18972
|
+
preview: ["url", "status", "reportUrl"],
|
|
18973
|
+
noun: "audits",
|
|
18974
|
+
price: toolPrice("seo-aeo-audit", "Failed audits and empty results are free."),
|
|
18975
|
+
example: { url: "example.com" },
|
|
18976
|
+
toolRequest: (input2) => ({ tool: "seo-aeo-audit", query: input2.url })
|
|
18977
|
+
}),
|
|
18958
18978
|
"email-finder": capability({
|
|
18959
18979
|
title: "Email finder",
|
|
18960
18980
|
description: "Work email for each LinkedIn profile, checked before it is returned.",
|
|
@@ -19066,14 +19086,28 @@ var CAPABILITIES = {
|
|
|
19066
19086
|
}),
|
|
19067
19087
|
"linkedin-profile": capability({
|
|
19068
19088
|
title: "LinkedIn profile",
|
|
19069
|
-
description: "Public LinkedIn profile: headline, role, company, location and about.",
|
|
19070
|
-
input: external_exports.object({ profile: text(300) }).strict(),
|
|
19089
|
+
description: "Public LinkedIn profile: headline, current role, company, location and about. One profile or up to 100 people.",
|
|
19090
|
+
input: external_exports.object({ profile: text(300).optional(), people: batchPeople }).strict(),
|
|
19071
19091
|
row: external_exports.object({ name: s, headline: s, role: s, company: s, location: s, followers: n, about: s, companyPage: s, url: s }),
|
|
19072
|
-
preview: ["name", "
|
|
19092
|
+
preview: ["name", "role", "company", "location"],
|
|
19073
19093
|
noun: "profiles",
|
|
19074
|
-
price: toolPrice("linkedin-profile"),
|
|
19094
|
+
price: toolPrice("linkedin-profile", "Profiles not found are free."),
|
|
19075
19095
|
example: { profile: "https://www.linkedin.com/in/williamhgates" },
|
|
19076
|
-
toolRequest: (input2) => ({ tool: "linkedin-profile", query: linkedinProfileUrl(input2.profile) })
|
|
19096
|
+
toolRequest: (input2) => ({ tool: "linkedin-profile", query: linkedinProfileUrl(input2.profile ?? "") }),
|
|
19097
|
+
batch: true
|
|
19098
|
+
}),
|
|
19099
|
+
"linkedin-activity": capability({
|
|
19100
|
+
title: "LinkedIn activity",
|
|
19101
|
+
description: "Recent public LinkedIn posts with exact dates: last post, posts in 90 and 365 days, and posts on topics you name. One profile or up to 100 people.",
|
|
19102
|
+
input: external_exports.object({ profile: text(300).optional(), people: batchPeople, topics: external_exports.array(text(40)).max(10).optional().describe("Words to look for in the past year's posts, like automation") }).strict(),
|
|
19103
|
+
row: external_exports.object({ name: s, headline: s, lastPostAt: s, posts90d: external_exports.number(), posts365d: external_exports.number(), topics: s, topicPosts: n, post: s, postAt: s, postKind: s, postUrl: s, url: s }),
|
|
19104
|
+
preview: ["name", "lastPostAt", "posts90d", "topicPosts"],
|
|
19105
|
+
noun: "profiles",
|
|
19106
|
+
price: toolPrice("linkedin-activity", "Profiles with no public posts are free."),
|
|
19107
|
+
example: { profile: "https://www.linkedin.com/in/williamhgates", topics: ["climate"] },
|
|
19108
|
+
// Commas would split a topic, so each is kept whole by dropping them.
|
|
19109
|
+
toolRequest: (input2) => ({ tool: "linkedin-activity", query: linkedinProfileUrl(input2.profile ?? ""), ...input2.topics?.length ? { keywords: input2.topics.map((t) => t.replace(/,/g, " ").trim()).join(", ") } : {} }),
|
|
19110
|
+
batch: true
|
|
19077
19111
|
}),
|
|
19078
19112
|
"page-content": capability({
|
|
19079
19113
|
title: "Web page content",
|
|
@@ -19150,7 +19184,7 @@ var OUTCOME_TOOLS = {
|
|
|
19150
19184
|
},
|
|
19151
19185
|
gtm_research_company: {
|
|
19152
19186
|
title: "Research a company",
|
|
19153
|
-
description: `Company profile and website sales brief for one domain
|
|
19187
|
+
description: `Company profile and website sales brief for one domain. Up to ${price("company") + price("website")} credits; misses free.`,
|
|
19154
19188
|
paid: true,
|
|
19155
19189
|
capabilities: ["company", "website"],
|
|
19156
19190
|
input: researchCompanyInput
|
|
@@ -19164,21 +19198,21 @@ var OUTCOME_TOOLS = {
|
|
|
19164
19198
|
},
|
|
19165
19199
|
gtm_results: {
|
|
19166
19200
|
title: "Get results",
|
|
19167
|
-
description: "Free
|
|
19201
|
+
description: "Free: run rows, job status or CSV link.",
|
|
19168
19202
|
paid: false,
|
|
19169
19203
|
capabilities: [],
|
|
19170
19204
|
input: resultsInput
|
|
19171
19205
|
},
|
|
19172
19206
|
gtm_tools: {
|
|
19173
19207
|
title: "Other tools",
|
|
19174
|
-
description: "Search, describe or run any catalog capability, like
|
|
19208
|
+
description: "Search, describe or run any catalog capability, like LinkedIn activity or SEO/AEO audits. Runs need max_credits.",
|
|
19175
19209
|
paid: true,
|
|
19176
19210
|
capabilities: CAPABILITY_IDS,
|
|
19177
19211
|
input: toolsInput
|
|
19178
19212
|
},
|
|
19179
19213
|
gtm_account: {
|
|
19180
19214
|
title: "Account",
|
|
19181
|
-
description: "Free
|
|
19215
|
+
description: "Free: balance, agent cap, recent spend or batch quote.",
|
|
19182
19216
|
paid: false,
|
|
19183
19217
|
capabilities: [],
|
|
19184
19218
|
input: accountInput
|
|
@@ -19223,7 +19257,7 @@ var agentAnswerSchema = external_exports.object({
|
|
|
19223
19257
|
var byteLength = (value) => new TextEncoder().encode(value).length;
|
|
19224
19258
|
var DEFAULT_NEXT = { tool: "gtm_account", args: {} };
|
|
19225
19259
|
function speakable(value) {
|
|
19226
|
-
const plain = value.replace(/[*`#>|~]/g, "").replace(/\s+/g, " ").trim();
|
|
19260
|
+
const plain = value.replace(/[*`#>|~]/g, "").replace(/\s+/g, " ").replace(/…[.!?]+/g, "\u2026").trim();
|
|
19227
19261
|
const first = plain.match(/^.*?(?:[.!?…](?=\s|$)|$)/)?.[0].trim() ?? plain;
|
|
19228
19262
|
const words = first.split(" ").filter(Boolean);
|
|
19229
19263
|
let sentence = words.length > SUMMARY_MAX_WORDS ? `${words.slice(0, SUMMARY_MAX_WORDS - 1).join(" ")}\u2026` : words.join(" ");
|
|
@@ -19382,8 +19416,12 @@ var clientMetadataDocumentSchema = external_exports.object({
|
|
|
19382
19416
|
client_id: external_exports.string(),
|
|
19383
19417
|
client_name: external_exports.string().trim().min(1).max(100).optional(),
|
|
19384
19418
|
redirect_uris: external_exports.array(external_exports.string()).min(1).max(10),
|
|
19385
|
-
token_endpoint_auth_method: external_exports.
|
|
19386
|
-
|
|
19419
|
+
token_endpoint_auth_method: external_exports.string().optional(),
|
|
19420
|
+
token_endpoint_auth_methods_supported: external_exports.array(external_exports.string()).optional()
|
|
19421
|
+
}).passthrough().refine(
|
|
19422
|
+
(document) => (document.token_endpoint_auth_method ?? "none") === "none" || document.token_endpoint_auth_methods_supported?.includes("none") === true,
|
|
19423
|
+
{ message: "Client must support token_endpoint_auth_method none", path: ["token_endpoint_auth_method"] }
|
|
19424
|
+
);
|
|
19387
19425
|
|
|
19388
19426
|
// ../contracts/src/agent-account.ts
|
|
19389
19427
|
var agentAccessSchema = external_exports.object({
|
|
@@ -19530,7 +19568,7 @@ var SPECS = {
|
|
|
19530
19568
|
research: { ...PAID },
|
|
19531
19569
|
signals: { location: { type: "string" }, company: { type: "string" }, limit: { type: "string" }, ...PAID },
|
|
19532
19570
|
results: { offset: { type: "string" }, csv: { type: "boolean" }, link: { type: "boolean" } },
|
|
19533
|
-
tools: { input: { type: "string" }, ...PAID },
|
|
19571
|
+
tools: { input: { type: "string" }, file: { type: "string" }, column: { type: "string" }, out: { type: "string" }, ...PAID },
|
|
19534
19572
|
account: { count: { type: "string" }, file: { type: "string" }, column: { type: "string" } }
|
|
19535
19573
|
};
|
|
19536
19574
|
var COMMAND_NAMES = Object.keys(SPECS);
|
|
@@ -19642,7 +19680,7 @@ function build2(name, values, positionals) {
|
|
|
19642
19680
|
const [action, ...words] = positionals;
|
|
19643
19681
|
const budget = paid(values, name);
|
|
19644
19682
|
if (action === "search" || action === "describe") {
|
|
19645
|
-
if (values.input !== void 0 || Object.keys(budget).length) throw new UsageError(`gtm tools ${action} is free and takes no --input or budget flags.`, name);
|
|
19683
|
+
if (values.input !== void 0 || values.file !== void 0 || Object.keys(budget).length) throw new UsageError(`gtm tools ${action} is free and takes no --input, --file or budget flags.`, name);
|
|
19646
19684
|
if (action === "search") {
|
|
19647
19685
|
if (!words.length) throw new UsageError("Give words to search for, like gtm tools search google.", name);
|
|
19648
19686
|
return { kind: "tool", tool: "gtm_tools", args: { action, query: words.join(" ") } };
|
|
@@ -19661,6 +19699,11 @@ function build2(name, values, positionals) {
|
|
|
19661
19699
|
}
|
|
19662
19700
|
if (!input2 || typeof input2 !== "object" || Array.isArray(input2)) throw new UsageError("--input needs a JSON object.", name);
|
|
19663
19701
|
}
|
|
19702
|
+
const file2 = str(values, "file");
|
|
19703
|
+
const column = str(values, "column");
|
|
19704
|
+
const out = str(values, "out");
|
|
19705
|
+
if (file2 === void 0 && (column !== void 0 || out !== void 0)) throw new UsageError("--column and --out need --file.", name);
|
|
19706
|
+
if (file2 !== void 0) return { kind: "tool-file", capability: words[0], input: input2 ?? {}, args: budget, file: file2, ...column !== void 0 ? { column } : {}, ...out !== void 0 ? { out } : {} };
|
|
19664
19707
|
return { kind: "tool", tool: "gtm_tools", args: { action, capability: words[0], ...input2 !== void 0 ? { input: input2 } : {}, ...budget } };
|
|
19665
19708
|
}
|
|
19666
19709
|
throw new UsageError("Use gtm tools search <words>, gtm tools describe <capability> or gtm tools run <capability>.", name);
|
|
@@ -19903,11 +19946,12 @@ async function contacts(session, command) {
|
|
|
19903
19946
|
skipped: list.invalid + list.empty
|
|
19904
19947
|
};
|
|
19905
19948
|
const options = { ...args.find ? { find: args.find } : {}, ...args.verify ? { verify: true } : {} };
|
|
19949
|
+
const tool2 = { tool: "gtm_find_contacts", args: (people) => ({ people, ...options }), perPerson: perPersonCredits(options) };
|
|
19906
19950
|
const rerun = (flags) => fileNext(command, options, flags);
|
|
19907
19951
|
const perCall = await session.gateway.peoplePerCall();
|
|
19908
19952
|
const maxCredits = args.max_credits;
|
|
19909
19953
|
if (args.dry_run || maxCredits === void 0) {
|
|
19910
|
-
const quoted = await quote(session, list.profiles, perCall,
|
|
19954
|
+
const quoted = await quote(session, list.profiles, perCall, tool2);
|
|
19911
19955
|
if ("refusal" in quoted) return session.emit(quoted.refusal, fileFields);
|
|
19912
19956
|
const people = plural(list.profiles.length, "person", "people");
|
|
19913
19957
|
const free = quoted.quote === 0;
|
|
@@ -19933,14 +19977,14 @@ async function contacts(session, command) {
|
|
|
19933
19977
|
}), fileFields);
|
|
19934
19978
|
}
|
|
19935
19979
|
}
|
|
19936
|
-
const run = await runBatches(session, list.profiles, perCall, maxCredits ?? null,
|
|
19980
|
+
const run = await runBatches(session, list.profiles, perCall, maxCredits ?? null, tool2, args.idempotency_key);
|
|
19937
19981
|
if (!run.batches.length && run.stop?.refusal?.status !== "error") {
|
|
19938
19982
|
return session.emit(run.refusal ?? shapeAnswer({
|
|
19939
19983
|
status: "refused",
|
|
19940
19984
|
reason: "over_max_credits",
|
|
19941
19985
|
balance: null,
|
|
19942
19986
|
next: rerun({ dry_run: true }),
|
|
19943
|
-
summary: `Nothing was sent: one person can cost up to ${plural(
|
|
19987
|
+
summary: `Nothing was sent: one person can cost up to ${plural(tool2.perPerson, "credit")}, above your --max-credits of ${maxCredits}.`
|
|
19944
19988
|
}), fileFields);
|
|
19945
19989
|
}
|
|
19946
19990
|
if (run.batches.length === 1 && !run.stop) {
|
|
@@ -19965,19 +20009,19 @@ function perPersonCredits(options) {
|
|
|
19965
20009
|
const find = options.find ?? ["email"];
|
|
19966
20010
|
return (find.includes("email") ? CAPABILITIES["email-finder"].price.credits : 0) + (options.verify ? CAPABILITIES["verify-email"].price.credits : 0) + (find.includes("phone") ? CAPABILITIES["phone-pilot"].price.credits : 0);
|
|
19967
20011
|
}
|
|
19968
|
-
async function quote(session, profiles, perCall,
|
|
20012
|
+
async function quote(session, profiles, perCall, tool2) {
|
|
19969
20013
|
let total = 0;
|
|
19970
20014
|
let balance = null;
|
|
19971
20015
|
for (let at = 0; at < profiles.length; at += perCall) {
|
|
19972
|
-
const answer = await session.gateway.call(
|
|
20016
|
+
const answer = await session.gateway.call(tool2.tool, { ...tool2.args(profiles.slice(at, at + perCall)), dry_run: true });
|
|
19973
20017
|
if (answer.status !== "quote") return { refusal: answer };
|
|
19974
20018
|
total += answer.quote ?? 0;
|
|
19975
20019
|
balance = answer.balance;
|
|
19976
20020
|
}
|
|
19977
20021
|
return { quote: total, balance };
|
|
19978
20022
|
}
|
|
19979
|
-
function batchKey(base,
|
|
19980
|
-
const hash2 = createHash("sha256").update(JSON.stringify(
|
|
20023
|
+
function batchKey(base, args) {
|
|
20024
|
+
const hash2 = createHash("sha256").update(JSON.stringify(args)).digest("hex");
|
|
19981
20025
|
if (!base) return `gtm-file-${hash2.slice(0, 32)}`;
|
|
19982
20026
|
const key = `${base}-${hash2.slice(0, 16)}`;
|
|
19983
20027
|
return key.length <= 128 ? key : `gtm-${createHash("sha256").update(key).digest("hex").slice(0, 40)}`;
|
|
@@ -19985,23 +20029,23 @@ function batchKey(base, people, options) {
|
|
|
19985
20029
|
function retryKey(key, runId) {
|
|
19986
20030
|
return `gtm-retry-${createHash("sha256").update(`${key}|${runId}`).digest("hex").slice(0, 40)}`;
|
|
19987
20031
|
}
|
|
19988
|
-
async function runBatches(session, profiles, perCall, budget,
|
|
19989
|
-
const perPerson =
|
|
20032
|
+
async function runBatches(session, profiles, perCall, budget, tool2, baseKey) {
|
|
20033
|
+
const perPerson = tool2.perPerson;
|
|
19990
20034
|
const batches = [];
|
|
19991
20035
|
let remaining = budget ?? 0;
|
|
19992
20036
|
let sent = 0;
|
|
19993
20037
|
let failedCost = 0;
|
|
19994
20038
|
let failedRunCost = 0;
|
|
19995
20039
|
const done = (stop, refusal = null, running = false) => ({ batches, stop, refusal, running, failedCost, failedRunCost });
|
|
20040
|
+
const retried = /* @__PURE__ */ new Set();
|
|
19996
20041
|
while (sent < profiles.length) {
|
|
19997
20042
|
const size = Math.min(perCall, profiles.length - sent, budget === null ? perCall : Math.floor(remaining / perPerson));
|
|
19998
20043
|
if (size <= 0) return done({ reason: "over_max_credits", refusal: null });
|
|
19999
20044
|
const people = profiles.slice(sent, sent + size);
|
|
20000
|
-
let key = batchKey(baseKey, people
|
|
20045
|
+
let key = batchKey(baseKey, tool2.args(people));
|
|
20001
20046
|
for (; ; ) {
|
|
20002
|
-
const first = await session.gateway.call(
|
|
20003
|
-
people,
|
|
20004
|
-
...options,
|
|
20047
|
+
const first = await session.gateway.call(tool2.tool, {
|
|
20048
|
+
...tool2.args(people),
|
|
20005
20049
|
...budget === null ? {} : { max_credits: Math.max(0, remaining) },
|
|
20006
20050
|
idempotency_key: key
|
|
20007
20051
|
});
|
|
@@ -20019,6 +20063,13 @@ async function runBatches(session, profiles, perCall, budget, options, baseKey)
|
|
|
20019
20063
|
key = retryKey(key, answer.run_id);
|
|
20020
20064
|
continue;
|
|
20021
20065
|
}
|
|
20066
|
+
if (answer.reason === "partial_failure" && first.replayed && answer.run_id && !retried.has(key)) {
|
|
20067
|
+
retried.add(key);
|
|
20068
|
+
failedRunCost += runCost;
|
|
20069
|
+
remaining -= runCost;
|
|
20070
|
+
key = retryKey(key, answer.run_id);
|
|
20071
|
+
continue;
|
|
20072
|
+
}
|
|
20022
20073
|
batches.push({ people, answer, replayed: first.replayed === true, runCost, cost: first.replayed ? 0 : runCost });
|
|
20023
20074
|
if (answer.status === "running") return done({ reason: "running", refusal: null }, null, true);
|
|
20024
20075
|
remaining -= runCost;
|
|
@@ -20129,11 +20180,124 @@ async function combined(session, command, run, total, budget, rerun, fileFields)
|
|
|
20129
20180
|
return session.emit(answer, fields, stop && !run.running && !failed2 ? { exit: 3 } : {});
|
|
20130
20181
|
}
|
|
20131
20182
|
|
|
20183
|
+
// src/tools-file.ts
|
|
20184
|
+
import { createHash as createHash2 } from "node:crypto";
|
|
20185
|
+
var plural2 = (n2, one, many = `${one}s`) => `${n2} ${n2 === 1 ? one : many}`;
|
|
20186
|
+
async function toolFile(session, command) {
|
|
20187
|
+
const definition = CAPABILITIES[command.capability];
|
|
20188
|
+
if (!definition?.batch) throw new UsageError(`gtm tools run ${command.capability} does not take --file; it runs one input at a time.`, "tools");
|
|
20189
|
+
if ("people" in command.input || "profile" in command.input) throw new UsageError("Give the people with --file, not in --input.", "tools");
|
|
20190
|
+
const list = profilesFromCsv(await session.readInput(command.file, "tools"), command.column);
|
|
20191
|
+
if (!list.profiles.length) throw new UsageError(`No LinkedIn profiles found in ${command.file}.`, "tools");
|
|
20192
|
+
const fileFields = {
|
|
20193
|
+
file: command.file,
|
|
20194
|
+
column: list.column ?? void 0,
|
|
20195
|
+
file_rows: list.rows,
|
|
20196
|
+
profiles: list.profiles.length,
|
|
20197
|
+
duplicates: list.duplicates,
|
|
20198
|
+
skipped: list.invalid + list.empty
|
|
20199
|
+
};
|
|
20200
|
+
const tool2 = {
|
|
20201
|
+
tool: "gtm_tools",
|
|
20202
|
+
args: (people2) => ({ action: "run", capability: command.capability, input: { ...command.input, people: people2 } }),
|
|
20203
|
+
perPerson: definition.price.credits
|
|
20204
|
+
};
|
|
20205
|
+
const rerun = (flags) => ({
|
|
20206
|
+
tool: "gtm_tools",
|
|
20207
|
+
args: {
|
|
20208
|
+
action: "run",
|
|
20209
|
+
capability: command.capability,
|
|
20210
|
+
file: command.file,
|
|
20211
|
+
...command.column !== void 0 ? { column: command.column } : {},
|
|
20212
|
+
...Object.keys(command.input).length ? { input: command.input } : {},
|
|
20213
|
+
...command.out !== void 0 ? { out: command.out } : {},
|
|
20214
|
+
...flags
|
|
20215
|
+
}
|
|
20216
|
+
});
|
|
20217
|
+
const maxCredits = command.args.max_credits;
|
|
20218
|
+
const perCall = await session.gateway.peoplePerCall();
|
|
20219
|
+
const people = plural2(list.profiles.length, "person", "people");
|
|
20220
|
+
if (command.args.dry_run || maxCredits === void 0) {
|
|
20221
|
+
const quoted = await quote(session, list.profiles, perCall, tool2);
|
|
20222
|
+
if ("refusal" in quoted) return session.emit(quoted.refusal, fileFields);
|
|
20223
|
+
const free = quoted.quote === 0;
|
|
20224
|
+
if (command.args.dry_run || !free) {
|
|
20225
|
+
return session.emit(shapeAnswer({
|
|
20226
|
+
status: command.args.dry_run ? "quote" : "refused",
|
|
20227
|
+
quote: quoted.quote,
|
|
20228
|
+
balance: quoted.balance,
|
|
20229
|
+
...command.args.dry_run ? {} : { reason: "max_credits_required" },
|
|
20230
|
+
next: rerun(free ? {} : { max_credits: quoted.quote }),
|
|
20231
|
+
summary: free ? `${people} cost nothing: this account already has their results; nothing was sent.` : command.args.dry_run ? `${people} would cost at most ${plural2(quoted.quote, "credit")}; nothing was sent.` : `Nothing was sent: this costs at most ${plural2(quoted.quote, "credit")}, so add --max-credits to run it.`
|
|
20232
|
+
}), fileFields);
|
|
20233
|
+
}
|
|
20234
|
+
}
|
|
20235
|
+
const run = await runBatches(session, list.profiles, perCall, maxCredits ?? null, tool2, command.args.idempotency_key);
|
|
20236
|
+
if (!run.batches.length) {
|
|
20237
|
+
return session.emit(run.refusal ?? run.stop?.refusal ?? shapeAnswer({
|
|
20238
|
+
status: "refused",
|
|
20239
|
+
reason: "over_max_credits",
|
|
20240
|
+
balance: null,
|
|
20241
|
+
next: rerun({ dry_run: true }),
|
|
20242
|
+
summary: `Nothing was sent: one person can cost up to ${plural2(tool2.perPerson, "credit")}, above your --max-credits of ${maxCredits}.`
|
|
20243
|
+
}), fileFields);
|
|
20244
|
+
}
|
|
20245
|
+
const sent = run.batches.reduce((sum, batch) => sum + batch.people.length, 0);
|
|
20246
|
+
let cost = run.batches.reduce((sum, batch) => sum + batch.cost, run.failedCost);
|
|
20247
|
+
let runCost = run.batches.reduce((sum, batch) => sum + batch.runCost, run.failedRunCost);
|
|
20248
|
+
const runIds = run.batches.map((batch) => batch.answer.run_id).filter((id) => !!id);
|
|
20249
|
+
const table = run.running ? null : await collectRows(session, run.batches);
|
|
20250
|
+
const errored = table?.rows.filter((row) => row.status === "error" && row.url).map((row) => row.url) ?? [];
|
|
20251
|
+
if (table && errored.length && !run.stop) {
|
|
20252
|
+
const left = maxCredits === void 0 ? null : Math.max(0, maxCredits - runCost);
|
|
20253
|
+
const retry = await runBatches(session, errored, perCall, left, tool2, `gtm-retry-${createHash2("sha256").update(runIds.join(",")).digest("hex").slice(0, 32)}`);
|
|
20254
|
+
const again = retry.batches.length && !retry.running ? await collectRows(session, retry.batches) : null;
|
|
20255
|
+
const byUrl = new Map(again?.rows.map((row) => [row.url, row]) ?? []);
|
|
20256
|
+
table.rows = table.rows.map((row) => row.status === "error" && byUrl.has(row.url) ? { ...row, ...byUrl.get(row.url) } : row);
|
|
20257
|
+
cost += retry.batches.reduce((sum, batch) => sum + batch.cost, retry.failedCost);
|
|
20258
|
+
runCost += retry.batches.reduce((sum, batch) => sum + batch.runCost, retry.failedRunCost);
|
|
20259
|
+
runIds.push(...retry.batches.map((batch) => batch.answer.run_id).filter((id) => !!id));
|
|
20260
|
+
}
|
|
20261
|
+
if (table && command.out) await writeOut(session, command.out, table);
|
|
20262
|
+
const found = table?.rows.filter((row) => row.status === "found").length ?? 0;
|
|
20263
|
+
const stillFailed = table?.rows.filter((row) => row.status === "error").length ?? 0;
|
|
20264
|
+
const unsent = list.profiles.length - sent;
|
|
20265
|
+
const failed2 = run.stop?.refusal?.status === "error" ? run.stop.refusal : null;
|
|
20266
|
+
const noun = definition.noun;
|
|
20267
|
+
const summary = run.running ? `Batch ${run.batches.length} is still running after ${sent} of ${people}; rerun this command to wait and continue.` : failed2 ? `Stopped after ${sent} of ${people}, ${unsent} not sent: ${failed2.summary}` : run.stop ? `Stopped after ${sent} of ${people} (${run.stop.refusal?.summary ?? "budget reached"}); found ${plural2(found, noun.replace(/s$/, ""), noun)} so far.` : `Found ${found} of ${plural2(sent, noun.replace(/s$/, ""), noun)} across ${plural2(run.batches.length, "batch", "batches")}; ${cost ? `${plural2(cost, "credit")} charged` : "nothing was charged"}${sent - found - stillFailed ? `, misses free` : ""}${stillFailed ? `; ${stillFailed} failed twice, so rerun later for them` : ""}.`;
|
|
20268
|
+
const columns = run.batches.find((batch) => batch.answer.columns.length)?.answer.columns ?? [...definition.preview, "status"];
|
|
20269
|
+
const rows = table?.rows ?? run.batches.flatMap((batch) => batch.answer.rows.map((cells) => Object.fromEntries(batch.answer.columns.map((name, i) => [name, cells[i] ?? null]))));
|
|
20270
|
+
const budgetFlag = maxCredits === void 0 ? {} : { max_credits: maxCredits };
|
|
20271
|
+
const next = failed2 || run.running || run.stop ? rerun(budgetFlag) : command.out && table ? ACCOUNT_NEXT : table ? rerun({ ...budgetFlag, out: `${command.file.replace(/\.csv$/i, "")}-${command.capability}.csv` }) : { tool: "gtm_results", args: { run_id: runIds.at(-1) } };
|
|
20272
|
+
const answer = shapeAnswer({
|
|
20273
|
+
status: failed2 ? "error" : run.running ? "running" : found || !table ? "completed" : "not_found",
|
|
20274
|
+
summary,
|
|
20275
|
+
run_id: runIds.length === 1 ? runIds[0] : null,
|
|
20276
|
+
cost,
|
|
20277
|
+
run_cost: runCost,
|
|
20278
|
+
balance: (failed2 ?? run.batches.at(-1)?.answer)?.balance ?? null,
|
|
20279
|
+
total: table?.rows.length ?? sent,
|
|
20280
|
+
label: noun,
|
|
20281
|
+
columns,
|
|
20282
|
+
rows,
|
|
20283
|
+
next,
|
|
20284
|
+
...run.stop && !run.running ? { reason: run.stop.reason } : {},
|
|
20285
|
+
...run.batches.every((batch) => batch.replayed) ? { replayed: true } : {}
|
|
20286
|
+
});
|
|
20287
|
+
return session.emit(answer, {
|
|
20288
|
+
...fileFields,
|
|
20289
|
+
batches: run.batches.length,
|
|
20290
|
+
run_ids: runIds.length > 1 ? runIds : void 0,
|
|
20291
|
+
unsent: unsent || void 0,
|
|
20292
|
+
out: command.out ? table ? command.out : "not written: still running" : void 0
|
|
20293
|
+
}, run.stop && !run.running && !failed2 ? { exit: 3 } : {});
|
|
20294
|
+
}
|
|
20295
|
+
|
|
20132
20296
|
// src/gateway.ts
|
|
20133
20297
|
import { randomUUID } from "node:crypto";
|
|
20134
20298
|
|
|
20135
20299
|
// src/version.ts
|
|
20136
|
-
var VERSION = "0.1.
|
|
20300
|
+
var VERSION = "0.1.2";
|
|
20137
20301
|
|
|
20138
20302
|
// src/gateway.ts
|
|
20139
20303
|
var CliError = class extends Error {
|
|
@@ -20357,7 +20521,7 @@ var TOPICS = {
|
|
|
20357
20521
|
tool("gtm_build_list"),
|
|
20358
20522
|
"",
|
|
20359
20523
|
"Options:",
|
|
20360
|
-
" --titles TITLE
|
|
20524
|
+
" --titles TITLE One job title, no commas; repeat for up to 5",
|
|
20361
20525
|
" --company DOMAIN Decision-makers at one company domain",
|
|
20362
20526
|
" --location PLACE Country or city",
|
|
20363
20527
|
" --business-type TYPE Local businesses, with --location",
|
|
@@ -20405,14 +20569,20 @@ var TOPICS = {
|
|
|
20405
20569
|
"Usage:",
|
|
20406
20570
|
" gtm tools search <words>",
|
|
20407
20571
|
" gtm tools describe <capability>",
|
|
20572
|
+
` gtm tools run seo-aeo-audit --input '{"url":"example.com"}' --max-credits 35`,
|
|
20408
20573
|
" gtm tools run <capability> --input '<json>' --max-credits N",
|
|
20574
|
+
` gtm tools run linkedin-activity --file leads.csv --input '{"topics":["automation"]}' --max-credits N [--out activity.csv]`,
|
|
20409
20575
|
"",
|
|
20410
20576
|
tool("gtm_tools"),
|
|
20411
20577
|
"",
|
|
20412
20578
|
`Capabilities: ${Object.keys(CAPABILITIES).join(", ")}.`,
|
|
20579
|
+
`--file works with ${Object.entries(CAPABILITIES).filter(([, c]) => "batch" in c && c.batch).map(([id]) => id).join(" and ")}: one job per person, run in budgeted batches; reruns replay finished batches free.`,
|
|
20413
20580
|
"",
|
|
20414
20581
|
"Options:",
|
|
20415
20582
|
" --input JSON The capability's input, as gtm tools describe shows",
|
|
20583
|
+
" --file PATH CSV or plain list of LinkedIn profile URLs or handles, any length",
|
|
20584
|
+
" --column NAME Column holding the profiles (found automatically when omitted)",
|
|
20585
|
+
" --out PATH Write every row to this CSV when all batches finish",
|
|
20416
20586
|
...PAID2
|
|
20417
20587
|
]
|
|
20418
20588
|
},
|
|
@@ -20700,7 +20870,7 @@ async function runCli(argv, io) {
|
|
|
20700
20870
|
} catch (error61) {
|
|
20701
20871
|
if (error61 instanceof CliError) return session.emit(errorAnswer(error61));
|
|
20702
20872
|
if (error61 instanceof UsageError) return usage(io, error61);
|
|
20703
|
-
if (error61 instanceof FileInputError) return usage(io, new UsageError(error61.message, command.kind === "quote-file" ? "account" : "contacts"));
|
|
20873
|
+
if (error61 instanceof FileInputError) return usage(io, new UsageError(error61.message, command.kind === "quote-file" ? "account" : command.kind === "tool-file" ? "tools" : "contacts"));
|
|
20704
20874
|
throw error61;
|
|
20705
20875
|
}
|
|
20706
20876
|
}
|
|
@@ -20720,6 +20890,8 @@ async function dispatch(session, command) {
|
|
|
20720
20890
|
return whoami(session);
|
|
20721
20891
|
case "contacts":
|
|
20722
20892
|
return contacts(session, command);
|
|
20893
|
+
case "tool-file":
|
|
20894
|
+
return toolFile(session, command);
|
|
20723
20895
|
case "results":
|
|
20724
20896
|
return results(session, command);
|
|
20725
20897
|
case "quote-file":
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gtmmaxing",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "gtm: the GTMMAXING command line. Find contacts, build lead lists and research companies from a terminal or a coding agent, with credit caps on every paid call.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"gtm",
|
|
@@ -24,20 +24,21 @@
|
|
|
24
24
|
"engines": {
|
|
25
25
|
"node": ">=20"
|
|
26
26
|
},
|
|
27
|
+
"scripts": {
|
|
28
|
+
"build": "node scripts/build.mjs",
|
|
29
|
+
"prepublishOnly": "pnpm build",
|
|
30
|
+
"typecheck": "tsc --noEmit",
|
|
31
|
+
"lint": "eslint src test",
|
|
32
|
+
"test": "vitest run"
|
|
33
|
+
},
|
|
27
34
|
"devDependencies": {
|
|
35
|
+
"@found/contracts": "workspace:*",
|
|
28
36
|
"@types/node": "^24.0.0",
|
|
29
37
|
"@typescript-eslint/eslint-plugin": "^8.46.4",
|
|
30
38
|
"@typescript-eslint/parser": "^8.46.4",
|
|
31
39
|
"esbuild": "0.28.1",
|
|
32
40
|
"eslint": "^9.39.2",
|
|
33
41
|
"typescript": "^5.9.3",
|
|
34
|
-
"vitest": "^4.1.11"
|
|
35
|
-
"@found/contracts": "0.1.0"
|
|
36
|
-
},
|
|
37
|
-
"scripts": {
|
|
38
|
-
"build": "node scripts/build.mjs",
|
|
39
|
-
"typecheck": "tsc --noEmit",
|
|
40
|
-
"lint": "eslint src test",
|
|
41
|
-
"test": "vitest run"
|
|
42
|
+
"vitest": "^4.1.11"
|
|
42
43
|
}
|
|
43
|
-
}
|
|
44
|
+
}
|