@tpmjs/official-base64-decode 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.
package/README.md ADDED
@@ -0,0 +1,88 @@
1
+ # @tpmjs/official-base64-decode
2
+
3
+ Decode base64 encoded data to string with support for multiple output encodings.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @tpmjs/official-base64-decode
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```typescript
14
+ import { base64DecodeTool } from '@tpmjs/official-base64-decode';
15
+ import { generateText } from 'ai';
16
+
17
+ const result = await generateText({
18
+ model: yourModel,
19
+ tools: {
20
+ base64Decode: base64DecodeTool,
21
+ },
22
+ prompt: 'Decode the base64 string "SGVsbG8sIFdvcmxkIQ=="',
23
+ });
24
+ ```
25
+
26
+ ## Parameters
27
+
28
+ - `base64` (string, required): The base64 encoded data to decode
29
+ - `encoding` (string, optional): Character encoding for the output data
30
+ - Options: `'utf8'` (default), `'binary'`, `'hex'`
31
+
32
+ ## Returns
33
+
34
+ ```typescript
35
+ {
36
+ decoded: string; // The decoded string
37
+ byteLength: number; // The byte length of the decoded data
38
+ }
39
+ ```
40
+
41
+ ## Examples
42
+
43
+ ### Decode to UTF-8 text (default)
44
+
45
+ ```typescript
46
+ const result = await base64DecodeTool.execute({
47
+ base64: 'SGVsbG8sIFdvcmxkIQ==',
48
+ });
49
+ // { decoded: 'Hello, World!', byteLength: 13 }
50
+ ```
51
+
52
+ ### Decode to hex string
53
+
54
+ ```typescript
55
+ const result = await base64DecodeTool.execute({
56
+ base64: '3q2+7w==',
57
+ encoding: 'hex',
58
+ });
59
+ // { decoded: 'deadbeef', byteLength: 4 }
60
+ ```
61
+
62
+ ### Decode to binary
63
+
64
+ ```typescript
65
+ const result = await base64DecodeTool.execute({
66
+ base64: 'AAECAw==',
67
+ encoding: 'binary',
68
+ });
69
+ // { decoded: '\x00\x01\x02\x03', byteLength: 4 }
70
+ ```
71
+
72
+ ## Use Cases
73
+
74
+ - Decoding base64-encoded API responses
75
+ - Extracting data from data URIs
76
+ - Decoding authentication tokens
77
+ - Processing base64-encoded file content
78
+ - Converting base64 images back to binary
79
+
80
+ ## Error Handling
81
+
82
+ The tool throws an error if:
83
+ - The base64 string is invalid
84
+ - The encoding parameter is not one of the supported values
85
+
86
+ ## License
87
+
88
+ MIT
@@ -0,0 +1,31 @@
1
+ import * as ai from 'ai';
2
+
3
+ /**
4
+ * Base64 Decode Tool for TPMJS
5
+ * Decodes base64 encoded data to string with support for multiple output encodings
6
+ */
7
+ /**
8
+ * Supported character encodings for base64 decoding output
9
+ */
10
+ type Encoding = 'utf8' | 'binary' | 'hex';
11
+ /**
12
+ * Input interface for base64 decoding
13
+ */
14
+ interface Base64DecodeInput {
15
+ base64: string;
16
+ encoding?: Encoding;
17
+ }
18
+ /**
19
+ * Output interface for base64 decode result
20
+ */
21
+ interface Base64DecodeResult {
22
+ decoded: string;
23
+ byteLength: number;
24
+ }
25
+ /**
26
+ * Base64 Decode Tool
27
+ * Decodes base64 encoded data to string format
28
+ */
29
+ declare const base64DecodeTool: ai.Tool<Base64DecodeInput, Base64DecodeResult>;
30
+
31
+ export { type Base64DecodeResult, base64DecodeTool, base64DecodeTool as default };
package/dist/index.js ADDED
@@ -0,0 +1,48 @@
1
+ import { tool, jsonSchema } from 'ai';
2
+
3
+ // src/index.ts
4
+ var base64DecodeTool = tool({
5
+ description: "Decode base64 encoded data to string. Supports utf8 (default), binary, and hex output encodings. Returns the decoded string and the byte length of the decoded data.",
6
+ inputSchema: jsonSchema({
7
+ type: "object",
8
+ properties: {
9
+ base64: {
10
+ type: "string",
11
+ description: "The base64 encoded data to decode"
12
+ },
13
+ encoding: {
14
+ type: "string",
15
+ enum: ["utf8", "binary", "hex"],
16
+ description: "Character encoding for the output data (default: utf8)"
17
+ }
18
+ },
19
+ required: ["base64"],
20
+ additionalProperties: false
21
+ }),
22
+ execute: async ({ base64, encoding = "utf8" }) => {
23
+ if (typeof base64 !== "string") {
24
+ throw new Error("Base64 data must be a string");
25
+ }
26
+ const validEncodings = ["utf8", "binary", "hex"];
27
+ if (!validEncodings.includes(encoding)) {
28
+ throw new Error(
29
+ `Invalid encoding: ${encoding}. Must be one of: ${validEncodings.join(", ")}`
30
+ );
31
+ }
32
+ try {
33
+ const buffer = Buffer.from(base64, "base64");
34
+ const decoded = buffer.toString(encoding);
35
+ return {
36
+ decoded,
37
+ byteLength: buffer.length
38
+ };
39
+ } catch (error) {
40
+ throw new Error(
41
+ `Failed to decode base64: ${error instanceof Error ? error.message : String(error)}`
42
+ );
43
+ }
44
+ }
45
+ });
46
+ var index_default = base64DecodeTool;
47
+
48
+ export { base64DecodeTool, index_default as default };
package/package.json ADDED
@@ -0,0 +1,76 @@
1
+ {
2
+ "name": "@tpmjs/official-base64-decode",
3
+ "version": "0.1.0",
4
+ "description": "Decode base64 encoded data to string with support for multiple output encodings",
5
+ "type": "module",
6
+ "keywords": [
7
+ "tpmjs",
8
+ "data",
9
+ "base64",
10
+ "decode",
11
+ "encoding"
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/anthropics/tpmjs.git",
33
+ "directory": "packages/tools/official/base64-decode"
34
+ },
35
+ "homepage": "https://tpmjs.com",
36
+ "license": "MIT",
37
+ "tpmjs": {
38
+ "category": "data",
39
+ "frameworks": [
40
+ "vercel-ai"
41
+ ],
42
+ "tools": [
43
+ {
44
+ "name": "base64DecodeTool",
45
+ "description": "Decode base64 encoded data to string with support for multiple output encodings",
46
+ "parameters": [
47
+ {
48
+ "name": "base64",
49
+ "type": "string",
50
+ "description": "The base64 encoded data to decode",
51
+ "required": true
52
+ },
53
+ {
54
+ "name": "encoding",
55
+ "type": "string",
56
+ "description": "Character encoding for output (utf8, binary, hex)",
57
+ "required": false
58
+ }
59
+ ],
60
+ "returns": {
61
+ "type": "Base64DecodeResult",
62
+ "description": "Object with decoded string and byte length"
63
+ }
64
+ }
65
+ ]
66
+ },
67
+ "dependencies": {
68
+ "ai": "6.0.0-beta.124"
69
+ },
70
+ "scripts": {
71
+ "build": "tsup",
72
+ "dev": "tsup --watch",
73
+ "type-check": "tsc --noEmit",
74
+ "clean": "rm -rf dist .turbo"
75
+ }
76
+ }