@jhb.software/payload-alt-text-plugin 0.2.2 → 0.3.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/README.md +93 -22
- package/dist/components/AltTextField.js +6 -6
- package/dist/components/AltTextField.js.map +1 -1
- package/dist/components/BulkGenerateAltTextsButton.js +7 -7
- package/dist/components/BulkGenerateAltTextsButton.js.map +1 -1
- package/dist/components/GenerateAltTextButton.js +12 -12
- package/dist/components/GenerateAltTextButton.js.map +1 -1
- package/dist/components/icons/Lightning.js +4 -4
- package/dist/components/icons/Lightning.js.map +1 -1
- package/dist/components/icons/Spinner.js +11 -11
- package/dist/components/icons/Spinner.js.map +1 -1
- package/dist/endpoints/bulkGenerateAltTexts.js +30 -77
- package/dist/endpoints/bulkGenerateAltTexts.js.map +1 -1
- package/dist/endpoints/generateAltText.d.ts +1 -1
- package/dist/endpoints/generateAltText.js +19 -74
- package/dist/endpoints/generateAltText.js.map +1 -1
- package/dist/exports/client.d.ts +1 -1
- package/dist/exports/client.js +1 -1
- package/dist/exports/client.js.map +1 -1
- package/dist/fields/altTextField.js +7 -7
- package/dist/fields/altTextField.js.map +1 -1
- package/dist/fields/keywordsField.js +7 -7
- package/dist/fields/keywordsField.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/plugin.js +24 -32
- package/dist/plugin.js.map +1 -1
- package/dist/resolvers/openAI.d.ts +24 -0
- package/dist/resolvers/openAI.js +177 -0
- package/dist/resolvers/openAI.js.map +1 -0
- package/dist/resolvers/types.d.ts +68 -0
- package/dist/resolvers/types.js +6 -0
- package/dist/resolvers/types.js.map +1 -0
- package/dist/translations/de.d.ts +1 -1
- package/dist/translations/de.js +3 -3
- package/dist/translations/de.js.map +1 -1
- package/dist/translations/en.d.ts +1 -1
- package/dist/translations/en.js +3 -3
- package/dist/translations/en.js.map +1 -1
- package/dist/types/AltTextPluginConfig.d.ts +28 -26
- package/dist/types/AltTextPluginConfig.js.map +1 -1
- package/dist/utilities/localesFromConfig.d.ts +1 -1
- package/dist/utilities/localesFromConfig.js.map +1 -1
- package/dist/utils/translatedLabel.d.ts +1 -1
- package/dist/utils/translatedLabel.js.map +1 -1
- package/dist/utils/usePluginTranslation.d.ts +1 -1
- package/dist/utils/usePluginTranslation.js +1 -1
- package/dist/utils/usePluginTranslation.js.map +1 -1
- package/package.json +16 -14
- package/dist/utilities/getGenerationCost.d.ts +0 -12
- package/dist/utilities/getGenerationCost.js +0 -30
- package/dist/utilities/getGenerationCost.js.map +0 -1
- package/dist/utilities/zodResponseFormat.d.ts +0 -11
- package/dist/utilities/zodResponseFormat.js +0 -23
- package/dist/utilities/zodResponseFormat.js.map +0 -1
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jhb.software/payload-alt-text-plugin",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "A
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"description": "A Payload CMS plugin that adds AI-powered alt text generation for images.",
|
|
5
5
|
"bugs": "https://github.com/jhb-software/payload-plugins/issues",
|
|
6
6
|
"repository": "https://github.com/jhb-software/payload-plugins",
|
|
7
7
|
"keywords": [
|
|
@@ -17,25 +17,27 @@
|
|
|
17
17
|
"main": "./dist/index.js",
|
|
18
18
|
"types": "./dist/index.d.ts",
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"openai": "^6.
|
|
21
|
-
"p-map": "^7.0.
|
|
22
|
-
"zod": "^4.1.
|
|
20
|
+
"openai": "^6.9.1",
|
|
21
|
+
"p-map": "^7.0.4",
|
|
22
|
+
"zod": "^4.1.13"
|
|
23
23
|
},
|
|
24
24
|
"peerDependencies": {
|
|
25
|
-
"@payloadcms/ui": "^3.
|
|
25
|
+
"@payloadcms/ui": "^3.65.0",
|
|
26
26
|
"next": "15.5.6",
|
|
27
|
-
"payload": "^3.
|
|
27
|
+
"payload": "^3.65.0",
|
|
28
28
|
"react": "19.2.0",
|
|
29
29
|
"react-dom": "19.2.0"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
|
+
"@payloadcms/eslint-config": "^3.28.0",
|
|
32
33
|
"@swc/cli": "^0.7.9",
|
|
33
|
-
"@swc/core": "^1.15.
|
|
34
|
-
"@types/react": "19.2.
|
|
35
|
-
"@types/react-dom": "19.2.
|
|
34
|
+
"@swc/core": "^1.15.3",
|
|
35
|
+
"@types/react": "19.2.7",
|
|
36
|
+
"@types/react-dom": "19.2.3",
|
|
36
37
|
"copyfiles": "2.4.1",
|
|
37
|
-
"
|
|
38
|
-
"
|
|
38
|
+
"eslint": "^9.39.1",
|
|
39
|
+
"prettier": "^3.7.3",
|
|
40
|
+
"rimraf": "6.1.2",
|
|
39
41
|
"typescript": "5.9.3"
|
|
40
42
|
},
|
|
41
43
|
"files": [
|
|
@@ -73,7 +75,7 @@
|
|
|
73
75
|
"clean": "rimraf --glob {dist,*.tsbuildinfo}",
|
|
74
76
|
"dev": "tsc -w",
|
|
75
77
|
"format": "prettier --write src",
|
|
76
|
-
"lint": "eslint
|
|
77
|
-
"lint:fix": "eslint
|
|
78
|
+
"lint": "eslint src",
|
|
79
|
+
"lint:fix": "eslint src --fix"
|
|
78
80
|
}
|
|
79
81
|
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type OpenAI from 'openai';
|
|
2
|
-
import type { AltTextPluginConfig } from '../types/AltTextPluginConfig.js';
|
|
3
|
-
type GenerationCost = {
|
|
4
|
-
model: 'gpt-4.1-nano' | 'gpt-4.1-mini';
|
|
5
|
-
inputCost: number;
|
|
6
|
-
outputCost: number;
|
|
7
|
-
totalCost: number;
|
|
8
|
-
totalTokens: number;
|
|
9
|
-
};
|
|
10
|
-
/** Calculates the cost of a generation. */
|
|
11
|
-
export declare function getGenerationCost(response: OpenAI.Chat.Completions.ChatCompletion, model: AltTextPluginConfig['model']): GenerationCost;
|
|
12
|
-
export {};
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
/** Calculates the cost of a generation. */ export function getGenerationCost(response, model) {
|
|
2
|
-
const modelCosts = {
|
|
3
|
-
// see https://platform.openai.com/docs/models/gpt-4.1-nano
|
|
4
|
-
'gpt-4.1-nano': {
|
|
5
|
-
input: 0.1,
|
|
6
|
-
output: 0.4
|
|
7
|
-
},
|
|
8
|
-
// see https://platform.openai.com/docs/models/gpt-4.1-mini
|
|
9
|
-
'gpt-4.1-mini': {
|
|
10
|
-
input: 0.4,
|
|
11
|
-
output: 1.6
|
|
12
|
-
}
|
|
13
|
-
};
|
|
14
|
-
// Calculate cost based on token usage
|
|
15
|
-
const inputTokens = response.usage?.prompt_tokens || 0;
|
|
16
|
-
const outputTokens = response.usage?.completion_tokens || 0;
|
|
17
|
-
const totalTokens = response.usage?.total_tokens || 0;
|
|
18
|
-
const inputCost = inputTokens / 1_000_000 * modelCosts[model].input;
|
|
19
|
-
const outputCost = outputTokens / 1_000_000 * modelCosts[model].output;
|
|
20
|
-
const totalCost = inputCost + outputCost;
|
|
21
|
-
return {
|
|
22
|
-
model,
|
|
23
|
-
inputCost,
|
|
24
|
-
outputCost,
|
|
25
|
-
totalCost,
|
|
26
|
-
totalTokens
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
//# sourceMappingURL=getGenerationCost.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utilities/getGenerationCost.ts"],"sourcesContent":["import type OpenAI from 'openai'\nimport type { AltTextPluginConfig } from '../types/AltTextPluginConfig.js'\n\ntype GenerationCost = {\n model: 'gpt-4.1-nano' | 'gpt-4.1-mini'\n inputCost: number\n outputCost: number\n totalCost: number\n totalTokens: number\n}\n\n/** Calculates the cost of a generation. */\nexport function getGenerationCost(\n response: OpenAI.Chat.Completions.ChatCompletion,\n model: AltTextPluginConfig['model'],\n): GenerationCost {\n const modelCosts: Record<AltTextPluginConfig['model'], { input: number; output: number }> = {\n // see https://platform.openai.com/docs/models/gpt-4.1-nano\n 'gpt-4.1-nano': {\n input: 0.1,\n output: 0.4,\n },\n // see https://platform.openai.com/docs/models/gpt-4.1-mini\n 'gpt-4.1-mini': {\n input: 0.4,\n output: 1.6,\n },\n }\n\n // Calculate cost based on token usage\n const inputTokens = response.usage?.prompt_tokens || 0\n const outputTokens = response.usage?.completion_tokens || 0\n const totalTokens = response.usage?.total_tokens || 0\n\n const inputCost = (inputTokens / 1_000_000) * modelCosts[model].input\n const outputCost = (outputTokens / 1_000_000) * modelCosts[model].output\n const totalCost = inputCost + outputCost\n\n return {\n model,\n inputCost,\n outputCost,\n totalCost,\n totalTokens,\n }\n}\n"],"names":["getGenerationCost","response","model","modelCosts","input","output","inputTokens","usage","prompt_tokens","outputTokens","completion_tokens","totalTokens","total_tokens","inputCost","outputCost","totalCost"],"mappings":"AAWA,yCAAyC,GACzC,OAAO,SAASA,kBACdC,QAAgD,EAChDC,KAAmC;IAEnC,MAAMC,aAAsF;QAC1F,2DAA2D;QAC3D,gBAAgB;YACdC,OAAO;YACPC,QAAQ;QACV;QACA,2DAA2D;QAC3D,gBAAgB;YACdD,OAAO;YACPC,QAAQ;QACV;IACF;IAEA,sCAAsC;IACtC,MAAMC,cAAcL,SAASM,KAAK,EAAEC,iBAAiB;IACrD,MAAMC,eAAeR,SAASM,KAAK,EAAEG,qBAAqB;IAC1D,MAAMC,cAAcV,SAASM,KAAK,EAAEK,gBAAgB;IAEpD,MAAMC,YAAY,AAACP,cAAc,YAAaH,UAAU,CAACD,MAAM,CAACE,KAAK;IACrE,MAAMU,aAAa,AAACL,eAAe,YAAaN,UAAU,CAACD,MAAM,CAACG,MAAM;IACxE,MAAMU,YAAYF,YAAYC;IAE9B,OAAO;QACLZ;QACAW;QACAC;QACAC;QACAJ;IACF;AACF"}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { AutoParseableResponseFormat } from 'openai/lib/parser.mjs';
|
|
2
|
-
import { ResponseFormatJSONSchema } from 'openai/resources/shared.mjs';
|
|
3
|
-
import { z } from 'zod';
|
|
4
|
-
/**
|
|
5
|
-
* Creates a chat completion `JSONSchema` response format object from
|
|
6
|
-
* the given Zod schema.
|
|
7
|
-
*
|
|
8
|
-
* This is a temporary drop in replacement for the zodResponseFormat from openai/helpers/zod.ts
|
|
9
|
-
* because of issue https://github.com/openai/openai-node/issues/1576
|
|
10
|
-
*/
|
|
11
|
-
export declare function zodResponseFormat<ZodInput extends z.ZodType>(zodObject: ZodInput, name: string, props?: Omit<ResponseFormatJSONSchema.JSONSchema, 'schema' | 'strict' | 'name'>): AutoParseableResponseFormat<z.infer<ZodInput>>;
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { makeParseableResponseFormat } from 'openai/lib/parser.mjs';
|
|
2
|
-
import { z } from 'zod';
|
|
3
|
-
/**
|
|
4
|
-
* Creates a chat completion `JSONSchema` response format object from
|
|
5
|
-
* the given Zod schema.
|
|
6
|
-
*
|
|
7
|
-
* This is a temporary drop in replacement for the zodResponseFormat from openai/helpers/zod.ts
|
|
8
|
-
* because of issue https://github.com/openai/openai-node/issues/1576
|
|
9
|
-
*/ export function zodResponseFormat(zodObject, name, props) {
|
|
10
|
-
return makeParseableResponseFormat({
|
|
11
|
-
type: 'json_schema',
|
|
12
|
-
json_schema: {
|
|
13
|
-
...props,
|
|
14
|
-
name,
|
|
15
|
-
strict: true,
|
|
16
|
-
schema: z.toJSONSchema(zodObject, {
|
|
17
|
-
target: 'draft-7'
|
|
18
|
-
})
|
|
19
|
-
}
|
|
20
|
-
}, (content)=>zodObject.parse(JSON.parse(content)));
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
//# sourceMappingURL=zodResponseFormat.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utilities/zodResponseFormat.ts"],"sourcesContent":["import { AutoParseableResponseFormat, makeParseableResponseFormat } from 'openai/lib/parser.mjs'\nimport { ResponseFormatJSONSchema } from 'openai/resources/shared.mjs'\nimport { z } from 'zod'\n\n/**\n * Creates a chat completion `JSONSchema` response format object from\n * the given Zod schema.\n *\n * This is a temporary drop in replacement for the zodResponseFormat from openai/helpers/zod.ts\n * because of issue https://github.com/openai/openai-node/issues/1576\n */\nexport function zodResponseFormat<ZodInput extends z.ZodType>(\n zodObject: ZodInput,\n name: string,\n props?: Omit<ResponseFormatJSONSchema.JSONSchema, 'schema' | 'strict' | 'name'>,\n): AutoParseableResponseFormat<z.infer<ZodInput>> {\n return makeParseableResponseFormat(\n {\n type: 'json_schema',\n json_schema: {\n ...props,\n name,\n strict: true,\n schema: z.toJSONSchema(zodObject, { target: 'draft-7' }),\n },\n },\n (content) => zodObject.parse(JSON.parse(content)),\n )\n}\n"],"names":["makeParseableResponseFormat","z","zodResponseFormat","zodObject","name","props","type","json_schema","strict","schema","toJSONSchema","target","content","parse","JSON"],"mappings":"AAAA,SAAsCA,2BAA2B,QAAQ,wBAAuB;AAEhG,SAASC,CAAC,QAAQ,MAAK;AAEvB;;;;;;CAMC,GACD,OAAO,SAASC,kBACdC,SAAmB,EACnBC,IAAY,EACZC,KAA+E;IAE/E,OAAOL,4BACL;QACEM,MAAM;QACNC,aAAa;YACX,GAAGF,KAAK;YACRD;YACAI,QAAQ;YACRC,QAAQR,EAAES,YAAY,CAACP,WAAW;gBAAEQ,QAAQ;YAAU;QACxD;IACF,GACA,CAACC,UAAYT,UAAUU,KAAK,CAACC,KAAKD,KAAK,CAACD;AAE5C"}
|