@natalieolivo/title-generator 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +99 -2
- package/dist/index.cjs +115 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +31 -0
- package/dist/index.d.ts +31 -0
- package/dist/index.js +78 -0
- package/dist/index.js.map +1 -0
- package/dist/title-generator.js +143 -0
- package/dist/title-generator.js.map +1 -0
- package/package.json +44 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Natalie
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,100 @@
|
|
|
1
|
-
#
|
|
1
|
+
# title-generator
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
An AI-powered title/headline generator — usable as an importable library or as a standalone CLI. Given a subject (a product, a blog post, an ad, anything that needs a headline), it generates several distinct title variants.
|
|
4
|
+
|
|
5
|
+
This is a personal portfolio package. **It is not published to npm** — clone it and use it locally, or link it into another project with `npm link`.
|
|
6
|
+
|
|
7
|
+
## Status
|
|
8
|
+
|
|
9
|
+
The public API (`generateTitles`, the CLI) is fully implemented. The call to the Anthropic API — `src/providers/anthropic.ts` is an implementation that makes a call with subject, count, and tone inputs. Response is parsed and returns a set of title variants. Everything around it (validation, the CLI, tests) is done and tested against a mocked provider.
|
|
10
|
+
|
|
11
|
+
## Install
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
git clone https://github.com/<you>/title-generator.git
|
|
15
|
+
cd title-generator
|
|
16
|
+
npm install
|
|
17
|
+
npm run build
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
To use it as a CLI from anywhere on your machine:
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
npm link
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
To use it as a library in another local project (also not published, so this is a local link, not an npm registry install):
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
cd ../title-generator && npm link
|
|
30
|
+
cd ../your-other-project && npm link title-generator
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Configuration
|
|
34
|
+
|
|
35
|
+
Set your Anthropic API key before calling `generateTitles` or running the CLI:
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
export ANTHROPIC_API_KEY=sk-ant-...
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
If it's unset, both the library function and the CLI fail fast with a clear error — no silent fallback, no partial request.
|
|
42
|
+
|
|
43
|
+
## Usage as a library
|
|
44
|
+
|
|
45
|
+
```ts
|
|
46
|
+
import { generateTitles } from "title-generator";
|
|
47
|
+
|
|
48
|
+
const titles = await generateTitles({
|
|
49
|
+
subject: "a productivity app for freelancers",
|
|
50
|
+
count: 5, // optional, defaults to 4
|
|
51
|
+
tone: "playful", // optional stylistic hint — see note below
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
console.log(titles);
|
|
55
|
+
// [ "...", "...", "...", "...", "..." ]
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
`subject` can be anything that needs a headline: a product, a blog post, an ad, a landing page. `tone` is an optional stylistic hint ("urgent", "playful", "formal", etc.). When you omit it, the provider defaults to generating a mix of angles across the requested titles — benefit-driven, curiosity-driven, social-proof, and urgency — rather than committing to one tone.
|
|
59
|
+
|
|
60
|
+
Note again: until `src/providers/anthropic.ts` is implemented, calling `generateTitles` will reject with `"TODO: implement generateWithAnthropic"` once past input validation and the API-key check.
|
|
61
|
+
|
|
62
|
+
## Usage as a CLI
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
title-generator "a productivity app for freelancers" --count 5 --tone urgent
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
Each generated title prints on its own line on success. On failure (missing API key, bad input, provider error) it prints a single clear line to stderr and exits with status 1 — no stack trace.
|
|
69
|
+
|
|
70
|
+
```
|
|
71
|
+
title-generator: generateTitles: ANTHROPIC_API_KEY environment variable is not set. Set it before calling generateTitles (e.g. `export ANTHROPIC_API_KEY=sk-ant-...`).
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## Optional pairing with launch-light
|
|
75
|
+
|
|
76
|
+
This repo has **zero package dependency on `launch-light`** — there is no such published package, and title-generator does not import or require anything from it or any other local project. This section is just a documented convention for anyone who happens to use both: `generateTitles` returns a plain array of strings, and it's easy to map that into whatever shape a lightweight launch/experimentation tool expects, e.g.:
|
|
77
|
+
|
|
78
|
+
```ts
|
|
79
|
+
const titles = await generateTitles({ subject: "a productivity app for freelancers" });
|
|
80
|
+
|
|
81
|
+
const variants = titles.map((headline, i) => ({
|
|
82
|
+
id: `variant-${i}`,
|
|
83
|
+
weight: 1 / titles.length,
|
|
84
|
+
payload: { headline },
|
|
85
|
+
}));
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
That's a plain object literal recipe, not an integration — copy it, adapt the shape to whatever your experimentation tool actually expects, and move on.
|
|
89
|
+
|
|
90
|
+
## Development
|
|
91
|
+
|
|
92
|
+
```bash
|
|
93
|
+
npm run dev # tsup --watch
|
|
94
|
+
npm run build # production build (ESM + CJS + .d.ts for the library, ESM for the CLI)
|
|
95
|
+
npm test # vitest run
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
## License
|
|
99
|
+
|
|
100
|
+
MIT — see [LICENSE](./LICENSE).
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/index.ts
|
|
31
|
+
var src_exports = {};
|
|
32
|
+
__export(src_exports, {
|
|
33
|
+
generateTitles: () => generateTitles
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(src_exports);
|
|
36
|
+
|
|
37
|
+
// src/providers/anthropic.ts
|
|
38
|
+
var import_sdk = __toESM(require("@anthropic-ai/sdk"), 1);
|
|
39
|
+
var MODEL = "claude-haiku-4-5-20251001";
|
|
40
|
+
var TITLES_SCHEMA = {
|
|
41
|
+
type: "object",
|
|
42
|
+
properties: {
|
|
43
|
+
variants: { type: "array", items: { type: "string" } }
|
|
44
|
+
},
|
|
45
|
+
required: ["variants"],
|
|
46
|
+
additionalProperties: false
|
|
47
|
+
};
|
|
48
|
+
function isExpectedTitlesPayload(value) {
|
|
49
|
+
return typeof value === "object" && value !== null && Array.isArray(value.variants) && value.variants.every(
|
|
50
|
+
(v) => typeof v === "string"
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
async function generateWithAnthropic({
|
|
54
|
+
subject,
|
|
55
|
+
count,
|
|
56
|
+
tone
|
|
57
|
+
}) {
|
|
58
|
+
const titleCriteriaInstruction = tone ? `Use "${tone}" as a stylistic hint for every title.` : "Mix criteria across the titles: benefit-driven, curiosity-driven, social-proof, and urgency.";
|
|
59
|
+
const client = new import_sdk.default();
|
|
60
|
+
const response = await client.messages.create({
|
|
61
|
+
model: MODEL,
|
|
62
|
+
max_tokens: 1024,
|
|
63
|
+
output_config: {
|
|
64
|
+
format: { type: "json_schema", schema: TITLES_SCHEMA }
|
|
65
|
+
},
|
|
66
|
+
messages: [
|
|
67
|
+
{
|
|
68
|
+
role: "user",
|
|
69
|
+
content: `Write ${count} distinct titles for "${subject}". ${titleCriteriaInstruction}`
|
|
70
|
+
}
|
|
71
|
+
]
|
|
72
|
+
});
|
|
73
|
+
const textBlock = response.content.find((block) => block.type === "text");
|
|
74
|
+
if (!textBlock) {
|
|
75
|
+
throw new Error(
|
|
76
|
+
"generateWithAnthropic: response contained no text content block."
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
const parsed = JSON.parse(textBlock.text);
|
|
80
|
+
if (!isExpectedTitlesPayload(parsed)) {
|
|
81
|
+
throw new Error(
|
|
82
|
+
"generateWithAnthropic: response did not match the expected { variants: string[] } shape."
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
return parsed.variants;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// src/generateTitles.ts
|
|
89
|
+
async function generateTitles({
|
|
90
|
+
subject,
|
|
91
|
+
count = 4,
|
|
92
|
+
tone
|
|
93
|
+
}) {
|
|
94
|
+
if (typeof subject !== "string" || subject.trim().length === 0) {
|
|
95
|
+
throw new Error(
|
|
96
|
+
"generateTitles: `subject` must be a non-empty string."
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
if (!Number.isInteger(count) || count <= 0) {
|
|
100
|
+
throw new Error(
|
|
101
|
+
`generateTitles: \`count\` must be a positive integer, received ${JSON.stringify(count)}.`
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
if (!process.env["ANTHROPIC_API_KEY"]) {
|
|
105
|
+
throw new Error(
|
|
106
|
+
"generateTitles: ANTHROPIC_API_KEY environment variable is not set. Set it before calling generateTitles (e.g. `export ANTHROPIC_API_KEY=sk-ant-...`)."
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
return generateWithAnthropic({ subject, count, tone });
|
|
110
|
+
}
|
|
111
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
112
|
+
0 && (module.exports = {
|
|
113
|
+
generateTitles
|
|
114
|
+
});
|
|
115
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/providers/anthropic.ts","../src/generateTitles.ts"],"sourcesContent":["export { generateTitles } from \"./generateTitles.js\";\nexport type { GenerateTitlesParams } from \"./generateTitles.js\";\nexport type { AnthropicGenerateTitleParams } from \"./providers/anthropic.js\";\n","import Anthropic from \"@anthropic-ai/sdk\";\n\nexport type AnthropicGenerateTitleParams = {\n subject: string;\n count: number;\n tone?: string;\n};\n\nconst MODEL = \"claude-haiku-4-5-20251001\";\n\nconst TITLES_SCHEMA = {\n type: \"object\",\n properties: {\n variants: { type: \"array\", items: { type: \"string\" } },\n },\n required: [\"variants\"],\n additionalProperties: false,\n} as const;\n\nfunction isExpectedTitlesPayload(value: unknown): value is { variants: string[] } {\n return (\n typeof value === \"object\" &&\n value !== null &&\n Array.isArray((value as { variants?: unknown }).variants) &&\n (value as { variants: unknown[] }).variants.every(\n (v) => typeof v === \"string\",\n )\n );\n}\n\n/**\n * generateTitles() in ../generateTitles.ts already validates inputs and checks\n * ANTHROPIC_API_KEY before calling this function.\n */\nexport async function generateWithAnthropic({\n subject,\n count,\n tone,\n}: AnthropicGenerateTitleParams): Promise<string[]> {\n const titleCriteriaInstruction = tone\n ? `Use \"${tone}\" as a stylistic hint for every title.`\n : \"Mix criteria across the titles: benefit-driven, curiosity-driven, social-proof, and urgency.\";\n\n const client = new Anthropic();\n const response = await client.messages.create({\n model: MODEL,\n max_tokens: 1024,\n output_config: {\n format: { type: \"json_schema\", schema: TITLES_SCHEMA },\n },\n messages: [\n {\n role: \"user\",\n content: `Write ${count} distinct titles for \"${subject}\". ${titleCriteriaInstruction}`,\n },\n ],\n });\n\n const textBlock = response.content.find((block): block is Anthropic.TextBlock => block.type === \"text\");\n if (!textBlock) {\n throw new Error(\n \"generateWithAnthropic: response contained no text content block.\",\n );\n }\n\n const parsed: unknown = JSON.parse(textBlock.text);\n if (!isExpectedTitlesPayload(parsed)) {\n throw new Error(\n \"generateWithAnthropic: response did not match the expected { variants: string[] } shape.\",\n );\n }\n\n return parsed.variants;\n}\n","import { generateWithAnthropic } from \"./providers/anthropic.js\";\n\nexport type GenerateTitlesParams = {\n /** The thing to generate titles for — a product, blog post, ad, etc. */\n subject: string;\n /** Number of distinct titles to generate. Defaults to 4. */\n count?: number;\n /**\n * Optional stylistic hint (e.g. \"urgent\", \"playful\"). When omitted, the\n * provider defaults to a mix of benefit/curiosity/social-proof/urgency\n * angles — see providers/anthropic.ts for details.\n */\n tone?: string;\n};\n\n/**\n * Generate title/headline variants for a given subject using the configured\n * AI provider (currently Anthropic's Claude API).\n *\n * Validates input, confirms an API key is configured, then delegates the\n * actual generation to `generateWithAnthropic`.\n *\n * @throws {Error} if `subject` is empty, `count` is not a positive integer,\n * or `ANTHROPIC_API_KEY` is not set.\n */\nexport async function generateTitles({\n subject,\n count = 4,\n tone,\n}: GenerateTitlesParams): Promise<string[]> {\n if (typeof subject !== \"string\" || subject.trim().length === 0) {\n throw new Error(\n \"generateTitles: `subject` must be a non-empty string.\",\n );\n }\n\n if (!Number.isInteger(count) || count <= 0) {\n throw new Error(\n `generateTitles: \\`count\\` must be a positive integer, received ${JSON.stringify(count)}.`,\n );\n }\n\n if (!process.env[\"ANTHROPIC_API_KEY\"]) {\n throw new Error(\n \"generateTitles: ANTHROPIC_API_KEY environment variable is not set. \" +\n \"Set it before calling generateTitles (e.g. `export ANTHROPIC_API_KEY=sk-ant-...`).\",\n );\n }\n\n return generateWithAnthropic({ subject, count, tone });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,iBAAsB;AAQtB,IAAM,QAAQ;AAEd,IAAM,gBAAgB;AAAA,EACpB,MAAM;AAAA,EACN,YAAY;AAAA,IACV,UAAU,EAAE,MAAM,SAAS,OAAO,EAAE,MAAM,SAAS,EAAE;AAAA,EACvD;AAAA,EACA,UAAU,CAAC,UAAU;AAAA,EACrB,sBAAsB;AACxB;AAEA,SAAS,wBAAwB,OAAiD;AAChF,SACE,OAAO,UAAU,YACjB,UAAU,QACV,MAAM,QAAS,MAAiC,QAAQ,KACvD,MAAkC,SAAS;AAAA,IAC1C,CAAC,MAAM,OAAO,MAAM;AAAA,EACtB;AAEJ;AAMA,eAAsB,sBAAsB;AAAA,EAC1C;AAAA,EACA;AAAA,EACA;AACF,GAAoD;AAClD,QAAM,2BAA2B,OAC7B,QAAQ,IAAI,2CACZ;AAEJ,QAAM,SAAS,IAAI,WAAAA,QAAU;AAC7B,QAAM,WAAW,MAAM,OAAO,SAAS,OAAO;AAAA,IAC5C,OAAO;AAAA,IACP,YAAY;AAAA,IACZ,eAAe;AAAA,MACb,QAAQ,EAAE,MAAM,eAAe,QAAQ,cAAc;AAAA,IACvD;AAAA,IACA,UAAU;AAAA,MACR;AAAA,QACE,MAAM;AAAA,QACN,SAAS,SAAS,KAAK,yBAAyB,OAAO,MAAM,wBAAwB;AAAA,MACvF;AAAA,IACF;AAAA,EACF,CAAC;AAED,QAAM,YAAY,SAAS,QAAQ,KAAK,CAAC,UAAwC,MAAM,SAAS,MAAM;AACtG,MAAI,CAAC,WAAW;AACd,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAEA,QAAM,SAAkB,KAAK,MAAM,UAAU,IAAI;AACjD,MAAI,CAAC,wBAAwB,MAAM,GAAG;AACpC,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAEA,SAAO,OAAO;AAChB;;;AChDA,eAAsB,eAAe;AAAA,EACnC;AAAA,EACA,QAAQ;AAAA,EACR;AACF,GAA4C;AAC1C,MAAI,OAAO,YAAY,YAAY,QAAQ,KAAK,EAAE,WAAW,GAAG;AAC9D,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAEA,MAAI,CAAC,OAAO,UAAU,KAAK,KAAK,SAAS,GAAG;AAC1C,UAAM,IAAI;AAAA,MACR,kEAAkE,KAAK,UAAU,KAAK,CAAC;AAAA,IACzF;AAAA,EACF;AAEA,MAAI,CAAC,QAAQ,IAAI,mBAAmB,GAAG;AACrC,UAAM,IAAI;AAAA,MACR;AAAA,IAEF;AAAA,EACF;AAEA,SAAO,sBAAsB,EAAE,SAAS,OAAO,KAAK,CAAC;AACvD;","names":["Anthropic"]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
type GenerateTitlesParams = {
|
|
2
|
+
/** The thing to generate titles for — a product, blog post, ad, etc. */
|
|
3
|
+
subject: string;
|
|
4
|
+
/** Number of distinct titles to generate. Defaults to 4. */
|
|
5
|
+
count?: number;
|
|
6
|
+
/**
|
|
7
|
+
* Optional stylistic hint (e.g. "urgent", "playful"). When omitted, the
|
|
8
|
+
* provider defaults to a mix of benefit/curiosity/social-proof/urgency
|
|
9
|
+
* angles — see providers/anthropic.ts for details.
|
|
10
|
+
*/
|
|
11
|
+
tone?: string;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Generate title/headline variants for a given subject using the configured
|
|
15
|
+
* AI provider (currently Anthropic's Claude API).
|
|
16
|
+
*
|
|
17
|
+
* Validates input, confirms an API key is configured, then delegates the
|
|
18
|
+
* actual generation to `generateWithAnthropic`.
|
|
19
|
+
*
|
|
20
|
+
* @throws {Error} if `subject` is empty, `count` is not a positive integer,
|
|
21
|
+
* or `ANTHROPIC_API_KEY` is not set.
|
|
22
|
+
*/
|
|
23
|
+
declare function generateTitles({ subject, count, tone, }: GenerateTitlesParams): Promise<string[]>;
|
|
24
|
+
|
|
25
|
+
type AnthropicGenerateTitleParams = {
|
|
26
|
+
subject: string;
|
|
27
|
+
count: number;
|
|
28
|
+
tone?: string;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export { type AnthropicGenerateTitleParams, type GenerateTitlesParams, generateTitles };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
type GenerateTitlesParams = {
|
|
2
|
+
/** The thing to generate titles for — a product, blog post, ad, etc. */
|
|
3
|
+
subject: string;
|
|
4
|
+
/** Number of distinct titles to generate. Defaults to 4. */
|
|
5
|
+
count?: number;
|
|
6
|
+
/**
|
|
7
|
+
* Optional stylistic hint (e.g. "urgent", "playful"). When omitted, the
|
|
8
|
+
* provider defaults to a mix of benefit/curiosity/social-proof/urgency
|
|
9
|
+
* angles — see providers/anthropic.ts for details.
|
|
10
|
+
*/
|
|
11
|
+
tone?: string;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Generate title/headline variants for a given subject using the configured
|
|
15
|
+
* AI provider (currently Anthropic's Claude API).
|
|
16
|
+
*
|
|
17
|
+
* Validates input, confirms an API key is configured, then delegates the
|
|
18
|
+
* actual generation to `generateWithAnthropic`.
|
|
19
|
+
*
|
|
20
|
+
* @throws {Error} if `subject` is empty, `count` is not a positive integer,
|
|
21
|
+
* or `ANTHROPIC_API_KEY` is not set.
|
|
22
|
+
*/
|
|
23
|
+
declare function generateTitles({ subject, count, tone, }: GenerateTitlesParams): Promise<string[]>;
|
|
24
|
+
|
|
25
|
+
type AnthropicGenerateTitleParams = {
|
|
26
|
+
subject: string;
|
|
27
|
+
count: number;
|
|
28
|
+
tone?: string;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export { type AnthropicGenerateTitleParams, type GenerateTitlesParams, generateTitles };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
// src/providers/anthropic.ts
|
|
2
|
+
import Anthropic from "@anthropic-ai/sdk";
|
|
3
|
+
var MODEL = "claude-haiku-4-5-20251001";
|
|
4
|
+
var TITLES_SCHEMA = {
|
|
5
|
+
type: "object",
|
|
6
|
+
properties: {
|
|
7
|
+
variants: { type: "array", items: { type: "string" } }
|
|
8
|
+
},
|
|
9
|
+
required: ["variants"],
|
|
10
|
+
additionalProperties: false
|
|
11
|
+
};
|
|
12
|
+
function isExpectedTitlesPayload(value) {
|
|
13
|
+
return typeof value === "object" && value !== null && Array.isArray(value.variants) && value.variants.every(
|
|
14
|
+
(v) => typeof v === "string"
|
|
15
|
+
);
|
|
16
|
+
}
|
|
17
|
+
async function generateWithAnthropic({
|
|
18
|
+
subject,
|
|
19
|
+
count,
|
|
20
|
+
tone
|
|
21
|
+
}) {
|
|
22
|
+
const titleCriteriaInstruction = tone ? `Use "${tone}" as a stylistic hint for every title.` : "Mix criteria across the titles: benefit-driven, curiosity-driven, social-proof, and urgency.";
|
|
23
|
+
const client = new Anthropic();
|
|
24
|
+
const response = await client.messages.create({
|
|
25
|
+
model: MODEL,
|
|
26
|
+
max_tokens: 1024,
|
|
27
|
+
output_config: {
|
|
28
|
+
format: { type: "json_schema", schema: TITLES_SCHEMA }
|
|
29
|
+
},
|
|
30
|
+
messages: [
|
|
31
|
+
{
|
|
32
|
+
role: "user",
|
|
33
|
+
content: `Write ${count} distinct titles for "${subject}". ${titleCriteriaInstruction}`
|
|
34
|
+
}
|
|
35
|
+
]
|
|
36
|
+
});
|
|
37
|
+
const textBlock = response.content.find((block) => block.type === "text");
|
|
38
|
+
if (!textBlock) {
|
|
39
|
+
throw new Error(
|
|
40
|
+
"generateWithAnthropic: response contained no text content block."
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
const parsed = JSON.parse(textBlock.text);
|
|
44
|
+
if (!isExpectedTitlesPayload(parsed)) {
|
|
45
|
+
throw new Error(
|
|
46
|
+
"generateWithAnthropic: response did not match the expected { variants: string[] } shape."
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
return parsed.variants;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// src/generateTitles.ts
|
|
53
|
+
async function generateTitles({
|
|
54
|
+
subject,
|
|
55
|
+
count = 4,
|
|
56
|
+
tone
|
|
57
|
+
}) {
|
|
58
|
+
if (typeof subject !== "string" || subject.trim().length === 0) {
|
|
59
|
+
throw new Error(
|
|
60
|
+
"generateTitles: `subject` must be a non-empty string."
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
if (!Number.isInteger(count) || count <= 0) {
|
|
64
|
+
throw new Error(
|
|
65
|
+
`generateTitles: \`count\` must be a positive integer, received ${JSON.stringify(count)}.`
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
if (!process.env["ANTHROPIC_API_KEY"]) {
|
|
69
|
+
throw new Error(
|
|
70
|
+
"generateTitles: ANTHROPIC_API_KEY environment variable is not set. Set it before calling generateTitles (e.g. `export ANTHROPIC_API_KEY=sk-ant-...`)."
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
return generateWithAnthropic({ subject, count, tone });
|
|
74
|
+
}
|
|
75
|
+
export {
|
|
76
|
+
generateTitles
|
|
77
|
+
};
|
|
78
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/providers/anthropic.ts","../src/generateTitles.ts"],"sourcesContent":["import Anthropic from \"@anthropic-ai/sdk\";\n\nexport type AnthropicGenerateTitleParams = {\n subject: string;\n count: number;\n tone?: string;\n};\n\nconst MODEL = \"claude-haiku-4-5-20251001\";\n\nconst TITLES_SCHEMA = {\n type: \"object\",\n properties: {\n variants: { type: \"array\", items: { type: \"string\" } },\n },\n required: [\"variants\"],\n additionalProperties: false,\n} as const;\n\nfunction isExpectedTitlesPayload(value: unknown): value is { variants: string[] } {\n return (\n typeof value === \"object\" &&\n value !== null &&\n Array.isArray((value as { variants?: unknown }).variants) &&\n (value as { variants: unknown[] }).variants.every(\n (v) => typeof v === \"string\",\n )\n );\n}\n\n/**\n * generateTitles() in ../generateTitles.ts already validates inputs and checks\n * ANTHROPIC_API_KEY before calling this function.\n */\nexport async function generateWithAnthropic({\n subject,\n count,\n tone,\n}: AnthropicGenerateTitleParams): Promise<string[]> {\n const titleCriteriaInstruction = tone\n ? `Use \"${tone}\" as a stylistic hint for every title.`\n : \"Mix criteria across the titles: benefit-driven, curiosity-driven, social-proof, and urgency.\";\n\n const client = new Anthropic();\n const response = await client.messages.create({\n model: MODEL,\n max_tokens: 1024,\n output_config: {\n format: { type: \"json_schema\", schema: TITLES_SCHEMA },\n },\n messages: [\n {\n role: \"user\",\n content: `Write ${count} distinct titles for \"${subject}\". ${titleCriteriaInstruction}`,\n },\n ],\n });\n\n const textBlock = response.content.find((block): block is Anthropic.TextBlock => block.type === \"text\");\n if (!textBlock) {\n throw new Error(\n \"generateWithAnthropic: response contained no text content block.\",\n );\n }\n\n const parsed: unknown = JSON.parse(textBlock.text);\n if (!isExpectedTitlesPayload(parsed)) {\n throw new Error(\n \"generateWithAnthropic: response did not match the expected { variants: string[] } shape.\",\n );\n }\n\n return parsed.variants;\n}\n","import { generateWithAnthropic } from \"./providers/anthropic.js\";\n\nexport type GenerateTitlesParams = {\n /** The thing to generate titles for — a product, blog post, ad, etc. */\n subject: string;\n /** Number of distinct titles to generate. Defaults to 4. */\n count?: number;\n /**\n * Optional stylistic hint (e.g. \"urgent\", \"playful\"). When omitted, the\n * provider defaults to a mix of benefit/curiosity/social-proof/urgency\n * angles — see providers/anthropic.ts for details.\n */\n tone?: string;\n};\n\n/**\n * Generate title/headline variants for a given subject using the configured\n * AI provider (currently Anthropic's Claude API).\n *\n * Validates input, confirms an API key is configured, then delegates the\n * actual generation to `generateWithAnthropic`.\n *\n * @throws {Error} if `subject` is empty, `count` is not a positive integer,\n * or `ANTHROPIC_API_KEY` is not set.\n */\nexport async function generateTitles({\n subject,\n count = 4,\n tone,\n}: GenerateTitlesParams): Promise<string[]> {\n if (typeof subject !== \"string\" || subject.trim().length === 0) {\n throw new Error(\n \"generateTitles: `subject` must be a non-empty string.\",\n );\n }\n\n if (!Number.isInteger(count) || count <= 0) {\n throw new Error(\n `generateTitles: \\`count\\` must be a positive integer, received ${JSON.stringify(count)}.`,\n );\n }\n\n if (!process.env[\"ANTHROPIC_API_KEY\"]) {\n throw new Error(\n \"generateTitles: ANTHROPIC_API_KEY environment variable is not set. \" +\n \"Set it before calling generateTitles (e.g. `export ANTHROPIC_API_KEY=sk-ant-...`).\",\n );\n }\n\n return generateWithAnthropic({ subject, count, tone });\n}\n"],"mappings":";AAAA,OAAO,eAAe;AAQtB,IAAM,QAAQ;AAEd,IAAM,gBAAgB;AAAA,EACpB,MAAM;AAAA,EACN,YAAY;AAAA,IACV,UAAU,EAAE,MAAM,SAAS,OAAO,EAAE,MAAM,SAAS,EAAE;AAAA,EACvD;AAAA,EACA,UAAU,CAAC,UAAU;AAAA,EACrB,sBAAsB;AACxB;AAEA,SAAS,wBAAwB,OAAiD;AAChF,SACE,OAAO,UAAU,YACjB,UAAU,QACV,MAAM,QAAS,MAAiC,QAAQ,KACvD,MAAkC,SAAS;AAAA,IAC1C,CAAC,MAAM,OAAO,MAAM;AAAA,EACtB;AAEJ;AAMA,eAAsB,sBAAsB;AAAA,EAC1C;AAAA,EACA;AAAA,EACA;AACF,GAAoD;AAClD,QAAM,2BAA2B,OAC7B,QAAQ,IAAI,2CACZ;AAEJ,QAAM,SAAS,IAAI,UAAU;AAC7B,QAAM,WAAW,MAAM,OAAO,SAAS,OAAO;AAAA,IAC5C,OAAO;AAAA,IACP,YAAY;AAAA,IACZ,eAAe;AAAA,MACb,QAAQ,EAAE,MAAM,eAAe,QAAQ,cAAc;AAAA,IACvD;AAAA,IACA,UAAU;AAAA,MACR;AAAA,QACE,MAAM;AAAA,QACN,SAAS,SAAS,KAAK,yBAAyB,OAAO,MAAM,wBAAwB;AAAA,MACvF;AAAA,IACF;AAAA,EACF,CAAC;AAED,QAAM,YAAY,SAAS,QAAQ,KAAK,CAAC,UAAwC,MAAM,SAAS,MAAM;AACtG,MAAI,CAAC,WAAW;AACd,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAEA,QAAM,SAAkB,KAAK,MAAM,UAAU,IAAI;AACjD,MAAI,CAAC,wBAAwB,MAAM,GAAG;AACpC,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAEA,SAAO,OAAO;AAChB;;;AChDA,eAAsB,eAAe;AAAA,EACnC;AAAA,EACA,QAAQ;AAAA,EACR;AACF,GAA4C;AAC1C,MAAI,OAAO,YAAY,YAAY,QAAQ,KAAK,EAAE,WAAW,GAAG;AAC9D,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAEA,MAAI,CAAC,OAAO,UAAU,KAAK,KAAK,SAAS,GAAG;AAC1C,UAAM,IAAI;AAAA,MACR,kEAAkE,KAAK,UAAU,KAAK,CAAC;AAAA,IACzF;AAAA,EACF;AAEA,MAAI,CAAC,QAAQ,IAAI,mBAAmB,GAAG;AACrC,UAAM,IAAI;AAAA,MACR;AAAA,IAEF;AAAA,EACF;AAEA,SAAO,sBAAsB,EAAE,SAAS,OAAO,KAAK,CAAC;AACvD;","names":[]}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// src/providers/anthropic.ts
|
|
4
|
+
import Anthropic from "@anthropic-ai/sdk";
|
|
5
|
+
var MODEL = "claude-haiku-4-5-20251001";
|
|
6
|
+
var TITLES_SCHEMA = {
|
|
7
|
+
type: "object",
|
|
8
|
+
properties: {
|
|
9
|
+
variants: { type: "array", items: { type: "string" } }
|
|
10
|
+
},
|
|
11
|
+
required: ["variants"],
|
|
12
|
+
additionalProperties: false
|
|
13
|
+
};
|
|
14
|
+
function isExpectedTitlesPayload(value) {
|
|
15
|
+
return typeof value === "object" && value !== null && Array.isArray(value.variants) && value.variants.every(
|
|
16
|
+
(v) => typeof v === "string"
|
|
17
|
+
);
|
|
18
|
+
}
|
|
19
|
+
async function generateWithAnthropic({
|
|
20
|
+
subject,
|
|
21
|
+
count,
|
|
22
|
+
tone
|
|
23
|
+
}) {
|
|
24
|
+
const titleCriteriaInstruction = tone ? `Use "${tone}" as a stylistic hint for every title.` : "Mix criteria across the titles: benefit-driven, curiosity-driven, social-proof, and urgency.";
|
|
25
|
+
const client = new Anthropic();
|
|
26
|
+
const response = await client.messages.create({
|
|
27
|
+
model: MODEL,
|
|
28
|
+
max_tokens: 1024,
|
|
29
|
+
output_config: {
|
|
30
|
+
format: { type: "json_schema", schema: TITLES_SCHEMA }
|
|
31
|
+
},
|
|
32
|
+
messages: [
|
|
33
|
+
{
|
|
34
|
+
role: "user",
|
|
35
|
+
content: `Write ${count} distinct titles for "${subject}". ${titleCriteriaInstruction}`
|
|
36
|
+
}
|
|
37
|
+
]
|
|
38
|
+
});
|
|
39
|
+
const textBlock = response.content.find((block) => block.type === "text");
|
|
40
|
+
if (!textBlock) {
|
|
41
|
+
throw new Error(
|
|
42
|
+
"generateWithAnthropic: response contained no text content block."
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
const parsed = JSON.parse(textBlock.text);
|
|
46
|
+
if (!isExpectedTitlesPayload(parsed)) {
|
|
47
|
+
throw new Error(
|
|
48
|
+
"generateWithAnthropic: response did not match the expected { variants: string[] } shape."
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
return parsed.variants;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// src/generateTitles.ts
|
|
55
|
+
async function generateTitles({
|
|
56
|
+
subject,
|
|
57
|
+
count = 4,
|
|
58
|
+
tone
|
|
59
|
+
}) {
|
|
60
|
+
if (typeof subject !== "string" || subject.trim().length === 0) {
|
|
61
|
+
throw new Error(
|
|
62
|
+
"generateTitles: `subject` must be a non-empty string."
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
if (!Number.isInteger(count) || count <= 0) {
|
|
66
|
+
throw new Error(
|
|
67
|
+
`generateTitles: \`count\` must be a positive integer, received ${JSON.stringify(count)}.`
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
if (!process.env["ANTHROPIC_API_KEY"]) {
|
|
71
|
+
throw new Error(
|
|
72
|
+
"generateTitles: ANTHROPIC_API_KEY environment variable is not set. Set it before calling generateTitles (e.g. `export ANTHROPIC_API_KEY=sk-ant-...`)."
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
return generateWithAnthropic({ subject, count, tone });
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// src/cli/parseArgs.ts
|
|
79
|
+
function parseArgs(argv) {
|
|
80
|
+
const positionals = [];
|
|
81
|
+
let count;
|
|
82
|
+
let tone;
|
|
83
|
+
for (let i = 0; i < argv.length; i++) {
|
|
84
|
+
const arg = argv[i];
|
|
85
|
+
if (arg === "--count") {
|
|
86
|
+
const value = argv[++i];
|
|
87
|
+
if (value === void 0) {
|
|
88
|
+
throw new Error("--count requires a value");
|
|
89
|
+
}
|
|
90
|
+
const parsed = Number(value);
|
|
91
|
+
if (!Number.isInteger(parsed) || parsed <= 0) {
|
|
92
|
+
throw new Error(
|
|
93
|
+
`--count must be a positive integer, received "${value}"`
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
count = parsed;
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
if (arg === "--tone") {
|
|
100
|
+
const value = argv[++i];
|
|
101
|
+
if (value === void 0) {
|
|
102
|
+
throw new Error("--tone requires a value");
|
|
103
|
+
}
|
|
104
|
+
tone = value;
|
|
105
|
+
continue;
|
|
106
|
+
}
|
|
107
|
+
if (arg !== void 0 && arg.startsWith("--")) {
|
|
108
|
+
throw new Error(`Unknown flag: ${arg}`);
|
|
109
|
+
}
|
|
110
|
+
if (arg !== void 0) {
|
|
111
|
+
positionals.push(arg);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
const subject = positionals.join(" ").trim();
|
|
115
|
+
if (subject.length === 0) {
|
|
116
|
+
throw new Error(
|
|
117
|
+
'Missing required argument: <subject>. Usage: title-generator "<subject>" [--count N] [--tone STRING]'
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
const result = { subject };
|
|
121
|
+
if (count !== void 0) result.count = count;
|
|
122
|
+
if (tone !== void 0) result.tone = tone;
|
|
123
|
+
return result;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// bin/title-generator.ts
|
|
127
|
+
async function main() {
|
|
128
|
+
const args = parseArgs(process.argv.slice(2));
|
|
129
|
+
const titles = await generateTitles({
|
|
130
|
+
subject: args.subject,
|
|
131
|
+
...args.count !== void 0 ? { count: args.count } : {},
|
|
132
|
+
...args.tone !== void 0 ? { tone: args.tone } : {}
|
|
133
|
+
});
|
|
134
|
+
for (const title of titles) {
|
|
135
|
+
console.log(title);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
main().catch((error) => {
|
|
139
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
140
|
+
console.error(`title-generator: ${message}`);
|
|
141
|
+
process.exit(1);
|
|
142
|
+
});
|
|
143
|
+
//# sourceMappingURL=title-generator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/providers/anthropic.ts","../src/generateTitles.ts","../src/cli/parseArgs.ts","../bin/title-generator.ts"],"sourcesContent":["import Anthropic from \"@anthropic-ai/sdk\";\n\nexport type AnthropicGenerateTitleParams = {\n subject: string;\n count: number;\n tone?: string;\n};\n\nconst MODEL = \"claude-haiku-4-5-20251001\";\n\nconst TITLES_SCHEMA = {\n type: \"object\",\n properties: {\n variants: { type: \"array\", items: { type: \"string\" } },\n },\n required: [\"variants\"],\n additionalProperties: false,\n} as const;\n\nfunction isExpectedTitlesPayload(value: unknown): value is { variants: string[] } {\n return (\n typeof value === \"object\" &&\n value !== null &&\n Array.isArray((value as { variants?: unknown }).variants) &&\n (value as { variants: unknown[] }).variants.every(\n (v) => typeof v === \"string\",\n )\n );\n}\n\n/**\n * generateTitles() in ../generateTitles.ts already validates inputs and checks\n * ANTHROPIC_API_KEY before calling this function.\n */\nexport async function generateWithAnthropic({\n subject,\n count,\n tone,\n}: AnthropicGenerateTitleParams): Promise<string[]> {\n const titleCriteriaInstruction = tone\n ? `Use \"${tone}\" as a stylistic hint for every title.`\n : \"Mix criteria across the titles: benefit-driven, curiosity-driven, social-proof, and urgency.\";\n\n const client = new Anthropic();\n const response = await client.messages.create({\n model: MODEL,\n max_tokens: 1024,\n output_config: {\n format: { type: \"json_schema\", schema: TITLES_SCHEMA },\n },\n messages: [\n {\n role: \"user\",\n content: `Write ${count} distinct titles for \"${subject}\". ${titleCriteriaInstruction}`,\n },\n ],\n });\n\n const textBlock = response.content.find((block): block is Anthropic.TextBlock => block.type === \"text\");\n if (!textBlock) {\n throw new Error(\n \"generateWithAnthropic: response contained no text content block.\",\n );\n }\n\n const parsed: unknown = JSON.parse(textBlock.text);\n if (!isExpectedTitlesPayload(parsed)) {\n throw new Error(\n \"generateWithAnthropic: response did not match the expected { variants: string[] } shape.\",\n );\n }\n\n return parsed.variants;\n}\n","import { generateWithAnthropic } from \"./providers/anthropic.js\";\n\nexport type GenerateTitlesParams = {\n /** The thing to generate titles for — a product, blog post, ad, etc. */\n subject: string;\n /** Number of distinct titles to generate. Defaults to 4. */\n count?: number;\n /**\n * Optional stylistic hint (e.g. \"urgent\", \"playful\"). When omitted, the\n * provider defaults to a mix of benefit/curiosity/social-proof/urgency\n * angles — see providers/anthropic.ts for details.\n */\n tone?: string;\n};\n\n/**\n * Generate title/headline variants for a given subject using the configured\n * AI provider (currently Anthropic's Claude API).\n *\n * Validates input, confirms an API key is configured, then delegates the\n * actual generation to `generateWithAnthropic`.\n *\n * @throws {Error} if `subject` is empty, `count` is not a positive integer,\n * or `ANTHROPIC_API_KEY` is not set.\n */\nexport async function generateTitles({\n subject,\n count = 4,\n tone,\n}: GenerateTitlesParams): Promise<string[]> {\n if (typeof subject !== \"string\" || subject.trim().length === 0) {\n throw new Error(\n \"generateTitles: `subject` must be a non-empty string.\",\n );\n }\n\n if (!Number.isInteger(count) || count <= 0) {\n throw new Error(\n `generateTitles: \\`count\\` must be a positive integer, received ${JSON.stringify(count)}.`,\n );\n }\n\n if (!process.env[\"ANTHROPIC_API_KEY\"]) {\n throw new Error(\n \"generateTitles: ANTHROPIC_API_KEY environment variable is not set. \" +\n \"Set it before calling generateTitles (e.g. `export ANTHROPIC_API_KEY=sk-ant-...`).\",\n );\n }\n\n return generateWithAnthropic({ subject, count, tone });\n}\n","export type ParsedArgs = {\n subject: string;\n count?: number;\n tone?: string;\n};\n\n/**\n * Minimal manual argv parser for the title-generator CLI.\n *\n * Usage: title-generator \"<subject>\" [--count N] [--tone STRING]\n *\n * Pure function — no I/O, no process.exit — so it can be unit tested directly.\n * Throws a plain Error with a clear, user-facing message on any parse failure.\n */\nexport function parseArgs(argv: string[]): ParsedArgs {\n const positionals: string[] = [];\n let count: number | undefined;\n let tone: string | undefined;\n\n for (let i = 0; i < argv.length; i++) {\n const arg = argv[i];\n\n if (arg === \"--count\") {\n const value = argv[++i];\n if (value === undefined) {\n throw new Error(\"--count requires a value\");\n }\n const parsed = Number(value);\n if (!Number.isInteger(parsed) || parsed <= 0) {\n throw new Error(\n `--count must be a positive integer, received \"${value}\"`,\n );\n }\n count = parsed;\n continue;\n }\n\n if (arg === \"--tone\") {\n const value = argv[++i];\n if (value === undefined) {\n throw new Error(\"--tone requires a value\");\n }\n tone = value;\n continue;\n }\n\n if (arg !== undefined && arg.startsWith(\"--\")) {\n throw new Error(`Unknown flag: ${arg}`);\n }\n\n if (arg !== undefined) {\n positionals.push(arg);\n }\n }\n\n const subject = positionals.join(\" \").trim();\n if (subject.length === 0) {\n throw new Error(\n 'Missing required argument: <subject>. Usage: title-generator \"<subject>\" [--count N] [--tone STRING]',\n );\n }\n\n const result: ParsedArgs = { subject };\n if (count !== undefined) result.count = count;\n if (tone !== undefined) result.tone = tone;\n return result;\n}\n","import { generateTitles } from \"../src/generateTitles.js\";\nimport { parseArgs } from \"../src/cli/parseArgs.js\";\n\nasync function main(): Promise<void> {\n const args = parseArgs(process.argv.slice(2));\n const titles = await generateTitles({\n subject: args.subject,\n ...(args.count !== undefined ? { count: args.count } : {}),\n ...(args.tone !== undefined ? { tone: args.tone } : {}),\n });\n\n for (const title of titles) {\n console.log(title);\n }\n}\n\nmain().catch((error: unknown) => {\n const message = error instanceof Error ? error.message : String(error);\n console.error(`title-generator: ${message}`);\n process.exit(1);\n});\n"],"mappings":"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","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,46 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@natalieolivo/title-generator",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "AI-powered title/headline generator — importable library and CLI",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"sideEffects": false,
|
|
8
|
+
"publishConfig": {
|
|
9
|
+
"access": "public"
|
|
10
|
+
},
|
|
11
|
+
"main": "./dist/index.cjs",
|
|
12
|
+
"module": "./dist/index.js",
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"bin": {
|
|
15
|
+
"title-generator": "./dist/title-generator.js"
|
|
16
|
+
},
|
|
17
|
+
"exports": {
|
|
18
|
+
".": {
|
|
19
|
+
"types": "./dist/index.d.ts",
|
|
20
|
+
"import": "./dist/index.js",
|
|
21
|
+
"require": "./dist/index.cjs"
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"files": [
|
|
25
|
+
"dist",
|
|
26
|
+
"README.md",
|
|
27
|
+
"LICENSE"
|
|
28
|
+
],
|
|
29
|
+
"scripts": {
|
|
30
|
+
"build": "tsup",
|
|
31
|
+
"dev": "tsup --watch",
|
|
32
|
+
"test": "vitest run"
|
|
33
|
+
},
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"@anthropic-ai/sdk": "^0.131.0"
|
|
36
|
+
},
|
|
37
|
+
"devDependencies": {
|
|
38
|
+
"@types/node": "^22.10.0",
|
|
39
|
+
"tsup": "^8.3.5",
|
|
40
|
+
"typescript": "^5.7.2",
|
|
41
|
+
"vitest": "^2.1.8"
|
|
42
|
+
},
|
|
43
|
+
"engines": {
|
|
44
|
+
"node": ">=18"
|
|
45
|
+
}
|
|
46
|
+
}
|