@tpmjs/audience-persona 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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024-2025 TPMJS
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.
@@ -0,0 +1,88 @@
1
+ import * as ai from 'ai';
2
+
3
+ /**
4
+ * Audience Persona Tool for TPMJS
5
+ * Creates detailed audience persona profiles from demographic and behavioral data
6
+ *
7
+ * This is a proper AI SDK v6 tool that can be used with streamText()
8
+ * Uses jsonSchema() to avoid Zod 4 JSON Schema conversion issues with OpenAI
9
+ */
10
+ interface AudiencePersona {
11
+ name: string;
12
+ demographics: {
13
+ ageRange: string;
14
+ gender?: string;
15
+ location?: string;
16
+ education?: string;
17
+ occupation?: string;
18
+ income?: string;
19
+ };
20
+ psychographics: {
21
+ interests: string[];
22
+ values: string[];
23
+ lifestyle?: string;
24
+ personality?: string;
25
+ };
26
+ goals: string[];
27
+ painPoints: string[];
28
+ behaviors: {
29
+ preferredChannels: string[];
30
+ buyingPatterns?: string;
31
+ contentPreferences: string[];
32
+ deviceUsage?: string[];
33
+ };
34
+ marketingImplications: {
35
+ messagingStrategy: string;
36
+ contentRecommendations: string[];
37
+ channelStrategy: string;
38
+ keyTriggers: string[];
39
+ };
40
+ quote?: string;
41
+ }
42
+ /**
43
+ * Input type for Audience Persona Tool
44
+ */
45
+ type AudiencePersonaInput = {
46
+ data: Record<string, unknown>;
47
+ productContext: string;
48
+ };
49
+ /**
50
+ * Audience Persona Tool
51
+ * Creates detailed audience persona profiles from demographic and behavioral data
52
+ *
53
+ * This is a proper AI SDK v6 tool that can be used with streamText()
54
+ */
55
+ declare const audiencePersonaTool: ai.Tool<AudiencePersonaInput, {
56
+ name: string;
57
+ demographics: {
58
+ ageRange: string;
59
+ gender?: string;
60
+ location?: string;
61
+ education?: string;
62
+ occupation?: string;
63
+ income?: string;
64
+ };
65
+ psychographics: {
66
+ interests: string[];
67
+ values: string[];
68
+ lifestyle?: string;
69
+ personality?: string;
70
+ };
71
+ goals: string[];
72
+ painPoints: string[];
73
+ behaviors: {
74
+ preferredChannels: string[];
75
+ buyingPatterns?: string;
76
+ contentPreferences: string[];
77
+ deviceUsage?: string[];
78
+ };
79
+ marketingImplications: {
80
+ messagingStrategy: string;
81
+ contentRecommendations: string[];
82
+ channelStrategy: string;
83
+ keyTriggers: string[];
84
+ };
85
+ quote: string;
86
+ }>;
87
+
88
+ export { type AudiencePersona, audiencePersonaTool, audiencePersonaTool as default };
package/dist/index.js ADDED
@@ -0,0 +1,215 @@
1
+ import { tool, jsonSchema } from 'ai';
2
+
3
+ // src/index.ts
4
+ function extractDemographics(data) {
5
+ const demographics = {
6
+ ageRange: "Not specified"
7
+ };
8
+ if (data.age) {
9
+ const age = Number(data.age);
10
+ if (!isNaN(age)) {
11
+ if (age < 18) demographics.ageRange = "Under 18";
12
+ else if (age < 25) demographics.ageRange = "18-24";
13
+ else if (age < 35) demographics.ageRange = "25-34";
14
+ else if (age < 45) demographics.ageRange = "35-44";
15
+ else if (age < 55) demographics.ageRange = "45-54";
16
+ else if (age < 65) demographics.ageRange = "55-64";
17
+ else demographics.ageRange = "65+";
18
+ }
19
+ } else if (data.ageRange) {
20
+ demographics.ageRange = String(data.ageRange);
21
+ }
22
+ if (data.gender) demographics.gender = String(data.gender);
23
+ if (data.location) demographics.location = String(data.location);
24
+ if (data.education) demographics.education = String(data.education);
25
+ if (data.occupation) demographics.occupation = String(data.occupation);
26
+ if (data.income) demographics.income = String(data.income);
27
+ return demographics;
28
+ }
29
+ function extractPsychographics(data) {
30
+ const psychographics = {
31
+ interests: [],
32
+ values: []
33
+ };
34
+ if (Array.isArray(data.interests)) {
35
+ psychographics.interests = data.interests.map(String);
36
+ } else if (typeof data.interests === "string") {
37
+ psychographics.interests = data.interests.split(",").map((s) => s.trim());
38
+ }
39
+ if (Array.isArray(data.values)) {
40
+ psychographics.values = data.values.map(String);
41
+ } else if (typeof data.values === "string") {
42
+ psychographics.values = data.values.split(",").map((s) => s.trim());
43
+ }
44
+ if (data.lifestyle) psychographics.lifestyle = String(data.lifestyle);
45
+ if (data.personality) psychographics.personality = String(data.personality);
46
+ return psychographics;
47
+ }
48
+ function extractGoals(data) {
49
+ if (Array.isArray(data.goals)) {
50
+ return data.goals.map(String);
51
+ } else if (typeof data.goals === "string") {
52
+ return data.goals.split(/[,;]/).map((s) => s.trim()).filter(Boolean);
53
+ }
54
+ return [];
55
+ }
56
+ function extractPainPoints(data) {
57
+ if (Array.isArray(data.painPoints)) {
58
+ return data.painPoints.map(String);
59
+ } else if (typeof data.painPoints === "string") {
60
+ return data.painPoints.split(/[,;]/).map((s) => s.trim()).filter(Boolean);
61
+ }
62
+ return [];
63
+ }
64
+ function extractBehaviors(data) {
65
+ const behaviors = {
66
+ preferredChannels: [],
67
+ contentPreferences: []
68
+ };
69
+ if (Array.isArray(data.preferredChannels)) {
70
+ behaviors.preferredChannels = data.preferredChannels.map(String);
71
+ } else if (typeof data.preferredChannels === "string") {
72
+ behaviors.preferredChannels = data.preferredChannels.split(",").map((s) => s.trim());
73
+ }
74
+ if (Array.isArray(data.contentPreferences)) {
75
+ behaviors.contentPreferences = data.contentPreferences.map(String);
76
+ } else if (typeof data.contentPreferences === "string") {
77
+ behaviors.contentPreferences = data.contentPreferences.split(",").map((s) => s.trim());
78
+ }
79
+ if (data.buyingPatterns) {
80
+ behaviors.buyingPatterns = String(data.buyingPatterns);
81
+ }
82
+ if (Array.isArray(data.deviceUsage)) {
83
+ behaviors.deviceUsage = data.deviceUsage.map(String);
84
+ } else if (typeof data.deviceUsage === "string") {
85
+ behaviors.deviceUsage = data.deviceUsage.split(",").map((s) => s.trim());
86
+ }
87
+ return behaviors;
88
+ }
89
+ function generatePersonaName(demographics, _productContext) {
90
+ const occupation = demographics.occupation || "Professional";
91
+ const firstNames = ["Alex", "Beth", "Chris", "Dana", "Emma", "Frank", "Grace", "Henry"];
92
+ const lastNames = ["Anderson", "Baker", "Chen", "Davis", "Evans", "Foster", "Garcia", "Harris"];
93
+ const firstInitial = occupation.charAt(0).toUpperCase();
94
+ const firstName = firstNames.find((n) => n.startsWith(firstInitial)) || firstNames[0];
95
+ const lastName = lastNames[Math.floor(Math.random() * lastNames.length)];
96
+ return `${firstName} ${lastName}`;
97
+ }
98
+ function generateMarketingImplications(demographics, psychographics, goals, painPoints, behaviors, _productContext) {
99
+ let messagingStrategy = "Focus on ";
100
+ if (painPoints.length > 0) {
101
+ messagingStrategy += `addressing ${painPoints[0]?.toLowerCase() ?? "key challenges"}`;
102
+ } else if (goals.length > 0) {
103
+ messagingStrategy += `helping achieve ${goals[0]?.toLowerCase() ?? "objectives"}`;
104
+ } else {
105
+ messagingStrategy += "product benefits and value proposition";
106
+ }
107
+ const contentRecommendations = [];
108
+ if (behaviors.contentPreferences.length > 0) {
109
+ behaviors.contentPreferences.forEach((pref) => {
110
+ contentRecommendations.push(`Create ${pref.toLowerCase()} content`);
111
+ });
112
+ } else {
113
+ contentRecommendations.push("Create educational content about product benefits");
114
+ contentRecommendations.push("Share customer success stories");
115
+ contentRecommendations.push("Provide how-to guides and tutorials");
116
+ }
117
+ const ageNum = Number.parseInt(demographics.ageRange.split("-")[0] || "0");
118
+ if (ageNum < 35) {
119
+ contentRecommendations.push("Use short-form video content (TikTok, Reels)");
120
+ } else if (ageNum >= 35 && ageNum < 55) {
121
+ contentRecommendations.push("Mix video and written content");
122
+ } else {
123
+ contentRecommendations.push("Provide detailed written guides");
124
+ }
125
+ let channelStrategy = "Prioritize ";
126
+ if (behaviors.preferredChannels.length > 0) {
127
+ channelStrategy += behaviors.preferredChannels.slice(0, 2).join(" and ");
128
+ } else {
129
+ channelStrategy += "email and social media";
130
+ }
131
+ const keyTriggers = [];
132
+ if (psychographics.values.length > 0) {
133
+ keyTriggers.push(`Values: ${psychographics.values.slice(0, 2).join(", ")}`);
134
+ }
135
+ if (painPoints.length > 0 && painPoints[0]) {
136
+ keyTriggers.push(`Pain point: ${painPoints[0]}`);
137
+ }
138
+ if (goals.length > 0 && goals[0]) {
139
+ keyTriggers.push(`Goal: ${goals[0]}`);
140
+ }
141
+ if (keyTriggers.length === 0) {
142
+ keyTriggers.push("Product benefits and features");
143
+ keyTriggers.push("Social proof and testimonials");
144
+ }
145
+ return {
146
+ messagingStrategy,
147
+ contentRecommendations,
148
+ channelStrategy,
149
+ keyTriggers
150
+ };
151
+ }
152
+ function generateQuote(goals, painPoints, _productContext) {
153
+ if (painPoints.length > 0 && goals.length > 0 && painPoints[0] && goals[0]) {
154
+ return `"I struggle with ${painPoints[0].toLowerCase()}, and I need a solution that helps me ${goals[0].toLowerCase()}."`;
155
+ } else if (painPoints.length > 0 && painPoints[0]) {
156
+ return `"My biggest challenge is ${painPoints[0].toLowerCase()}."`;
157
+ } else if (goals.length > 0 && goals[0]) {
158
+ return `"I want to ${goals[0].toLowerCase()}."`;
159
+ } else {
160
+ return `"I'm looking for a solution that makes my life easier."`;
161
+ }
162
+ }
163
+ var audiencePersonaTool = tool({
164
+ description: "Creates detailed audience persona profiles from demographic and behavioral data. Generates personas with demographics, psychographics, goals, pain points, behaviors, and actionable marketing implications.",
165
+ inputSchema: jsonSchema({
166
+ type: "object",
167
+ properties: {
168
+ data: {
169
+ type: "object",
170
+ description: "Audience data points (age/ageRange, gender, location, education, occupation, income, interests, values, lifestyle, personality, goals, painPoints, preferredChannels, contentPreferences, buyingPatterns, deviceUsage)",
171
+ additionalProperties: true
172
+ },
173
+ productContext: {
174
+ type: "string",
175
+ description: "Product or service context for persona development"
176
+ }
177
+ },
178
+ required: ["data", "productContext"],
179
+ additionalProperties: false
180
+ }),
181
+ async execute({ data, productContext }) {
182
+ if (!data || typeof data !== "object") {
183
+ throw new Error("Data must be a non-empty object");
184
+ }
185
+ if (!productContext || productContext.trim().length === 0) {
186
+ throw new Error("Product context is required");
187
+ }
188
+ const demographics = extractDemographics(data);
189
+ const psychographics = extractPsychographics(data);
190
+ const goals = extractGoals(data);
191
+ const painPoints = extractPainPoints(data);
192
+ const behaviors = extractBehaviors(data);
193
+ const name = generatePersonaName(demographics);
194
+ const marketingImplications = generateMarketingImplications(
195
+ demographics,
196
+ psychographics,
197
+ goals,
198
+ painPoints,
199
+ behaviors);
200
+ const quote = generateQuote(goals, painPoints);
201
+ return {
202
+ name,
203
+ demographics,
204
+ psychographics,
205
+ goals,
206
+ painPoints,
207
+ behaviors,
208
+ marketingImplications,
209
+ quote
210
+ };
211
+ }
212
+ });
213
+ var index_default = audiencePersonaTool;
214
+
215
+ export { audiencePersonaTool, index_default as default };
package/package.json ADDED
@@ -0,0 +1,85 @@
1
+ {
2
+ "name": "@tpmjs/audience-persona",
3
+ "version": "0.1.0",
4
+ "description": "Create audience persona profiles from demographic and behavioral data",
5
+ "type": "module",
6
+ "keywords": [
7
+ "tpmjs",
8
+ "marketing",
9
+ "persona",
10
+ "audience",
11
+ "ai"
12
+ ],
13
+ "exports": {
14
+ ".": {
15
+ "types": "./dist/index.d.ts",
16
+ "default": "./dist/index.js"
17
+ }
18
+ },
19
+ "files": [
20
+ "dist"
21
+ ],
22
+ "devDependencies": {
23
+ "tsup": "^8.3.5",
24
+ "typescript": "^5.9.3",
25
+ "@tpmjs/tsconfig": "0.0.0"
26
+ },
27
+ "publishConfig": {
28
+ "access": "public"
29
+ },
30
+ "repository": {
31
+ "type": "git",
32
+ "url": "https://github.com/ajaxdavis/tpmjs.git",
33
+ "directory": "packages/tools/official/audience-persona"
34
+ },
35
+ "homepage": "https://tpmjs.com",
36
+ "license": "MIT",
37
+ "tpmjs": {
38
+ "category": "marketing",
39
+ "frameworks": [
40
+ "vercel-ai"
41
+ ],
42
+ "tools": [
43
+ {
44
+ "exportName": "audiencePersonaTool",
45
+ "description": "Creates detailed audience persona profiles from demographic and behavioral data. Generates personas with demographics, psychographics, goals, pain points, behaviors, and actionable marketing implications.",
46
+ "parameters": [
47
+ {
48
+ "name": "data",
49
+ "type": "object",
50
+ "description": "Audience data points (age/ageRange, gender, location, education, occupation, income, interests, values, lifestyle, personality, goals, painPoints, preferredChannels, contentPreferences, buyingPatterns, deviceUsage)",
51
+ "required": true
52
+ },
53
+ {
54
+ "name": "productContext",
55
+ "type": "string",
56
+ "description": "Product or service context for persona development",
57
+ "required": true
58
+ }
59
+ ],
60
+ "returns": {
61
+ "type": "AudiencePersona",
62
+ "description": "Complete persona profile with demographics, psychographics, goals, pain points, behaviors, marketing implications, and representative quote"
63
+ },
64
+ "aiAgent": {
65
+ "useCase": "Use this tool when users need to create detailed audience personas for marketing strategy. Transforms raw audience data into actionable persona profiles with marketing recommendations.",
66
+ "limitations": "Requires structured input data. Generated names are fictional. Marketing implications are strategic suggestions, not guaranteed results.",
67
+ "examples": [
68
+ "Create a persona for our SaaS product targeting small business owners",
69
+ "Build an audience profile from our customer survey data",
70
+ "Generate a marketing persona for 25-34 year old tech professionals"
71
+ ]
72
+ }
73
+ }
74
+ ]
75
+ },
76
+ "dependencies": {
77
+ "ai": "6.0.0-beta.124"
78
+ },
79
+ "scripts": {
80
+ "build": "tsup",
81
+ "dev": "tsup --watch",
82
+ "type-check": "tsc --noEmit",
83
+ "clean": "rm -rf dist .turbo"
84
+ }
85
+ }