@tpmjs/official-org-chart-format 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,55 @@
1
+ import * as ai from 'ai';
2
+
3
+ /**
4
+ * Org Chart Format Tool for TPMJS
5
+ * Formats organizational hierarchy data into structured org chart representation
6
+ */
7
+ /**
8
+ * Employee input data
9
+ */
10
+ interface EmployeeInput {
11
+ id: string;
12
+ name: string;
13
+ title: string;
14
+ department: string;
15
+ managerId?: string | null;
16
+ email?: string;
17
+ level?: number;
18
+ }
19
+ /**
20
+ * Structured employee node in org chart
21
+ */
22
+ interface OrgChartNode {
23
+ id: string;
24
+ name: string;
25
+ title: string;
26
+ department: string;
27
+ email?: string;
28
+ level: number;
29
+ managerId?: string | null;
30
+ directReports: OrgChartNode[];
31
+ reportCount: number;
32
+ }
33
+ /**
34
+ * Input interface for org chart formatting
35
+ */
36
+ interface OrgChartFormatInput {
37
+ employees: EmployeeInput[];
38
+ }
39
+ /**
40
+ * Org chart output with metadata
41
+ */
42
+ interface OrgChart {
43
+ root: OrgChartNode[];
44
+ totalEmployees: number;
45
+ departments: string[];
46
+ maxDepth: number;
47
+ orphanedEmployees: string[];
48
+ }
49
+ /**
50
+ * Org Chart Format Tool
51
+ * Formats organizational hierarchy data into structured org chart representation
52
+ */
53
+ declare const orgChartFormatTool: ai.Tool<OrgChartFormatInput, OrgChart>;
54
+
55
+ export { type OrgChart, type OrgChartNode, orgChartFormatTool as default, orgChartFormatTool };
package/dist/index.js ADDED
@@ -0,0 +1,134 @@
1
+ import { tool, jsonSchema } from 'ai';
2
+
3
+ // src/index.ts
4
+ var orgChartFormatTool = tool({
5
+ description: "Formats organizational hierarchy data into a structured org chart representation. Processes employee data with manager relationships to create a hierarchical tree structure with reporting relationships, departments, and role titles.",
6
+ inputSchema: jsonSchema({
7
+ type: "object",
8
+ properties: {
9
+ employees: {
10
+ type: "array",
11
+ items: {
12
+ type: "object",
13
+ properties: {
14
+ id: {
15
+ type: "string",
16
+ description: "Unique employee identifier"
17
+ },
18
+ name: {
19
+ type: "string",
20
+ description: "Employee full name"
21
+ },
22
+ title: {
23
+ type: "string",
24
+ description: "Job title"
25
+ },
26
+ department: {
27
+ type: "string",
28
+ description: "Department name"
29
+ },
30
+ managerId: {
31
+ type: ["string", "null"],
32
+ description: "Manager employee ID (null for top-level)"
33
+ },
34
+ email: {
35
+ type: "string",
36
+ description: "Employee email address"
37
+ },
38
+ level: {
39
+ type: "number",
40
+ description: "Organizational level (optional, will be calculated if not provided)"
41
+ }
42
+ },
43
+ required: ["id", "name", "title", "department"]
44
+ },
45
+ minItems: 1,
46
+ description: "Array of employee objects with manager relationships"
47
+ }
48
+ },
49
+ required: ["employees"],
50
+ additionalProperties: false
51
+ }),
52
+ execute: async ({ employees }) => {
53
+ if (!Array.isArray(employees) || employees.length === 0) {
54
+ throw new Error("Employees must be a non-empty array");
55
+ }
56
+ for (const emp of employees) {
57
+ if (!emp.id || typeof emp.id !== "string") {
58
+ throw new Error("Each employee must have a valid id");
59
+ }
60
+ if (!emp.name || typeof emp.name !== "string") {
61
+ throw new Error(`Employee ${emp.id} must have a valid name`);
62
+ }
63
+ if (!emp.title || typeof emp.title !== "string") {
64
+ throw new Error(`Employee ${emp.id} must have a valid title`);
65
+ }
66
+ if (!emp.department || typeof emp.department !== "string") {
67
+ throw new Error(`Employee ${emp.id} must have a valid department`);
68
+ }
69
+ }
70
+ const ids = /* @__PURE__ */ new Set();
71
+ for (const emp of employees) {
72
+ if (ids.has(emp.id)) {
73
+ throw new Error(`Duplicate employee ID found: ${emp.id}`);
74
+ }
75
+ ids.add(emp.id);
76
+ }
77
+ try {
78
+ const employeeMap = /* @__PURE__ */ new Map();
79
+ for (const emp of employees) {
80
+ employeeMap.set(emp.id, emp);
81
+ }
82
+ const rootEmployees = [];
83
+ const orphanedEmployees = [];
84
+ for (const emp of employees) {
85
+ if (!emp.managerId || emp.managerId === null) {
86
+ rootEmployees.push(emp);
87
+ } else if (!employeeMap.has(emp.managerId)) {
88
+ orphanedEmployees.push(emp.id);
89
+ rootEmployees.push(emp);
90
+ }
91
+ }
92
+ if (rootEmployees.length === 0) {
93
+ throw new Error("No root employees found (circular management structure detected)");
94
+ }
95
+ const buildNode = (emp, currentLevel) => {
96
+ const directReportData = employees.filter((e) => e.managerId === emp.id);
97
+ const directReports = directReportData.map((report) => buildNode(report, currentLevel + 1));
98
+ const reportCount = directReports.reduce((sum, dr) => sum + 1 + dr.reportCount, 0);
99
+ return {
100
+ id: emp.id,
101
+ name: emp.name,
102
+ title: emp.title,
103
+ department: emp.department,
104
+ email: emp.email,
105
+ level: emp.level ?? currentLevel,
106
+ managerId: emp.managerId,
107
+ directReports,
108
+ reportCount
109
+ };
110
+ };
111
+ const root = rootEmployees.map((emp) => buildNode(emp, 0));
112
+ const calculateMaxDepth = (node) => {
113
+ if (node.directReports.length === 0) return node.level;
114
+ return Math.max(...node.directReports.map(calculateMaxDepth));
115
+ };
116
+ const maxDepth = Math.max(...root.map(calculateMaxDepth));
117
+ const departments = Array.from(new Set(employees.map((e) => e.department))).sort();
118
+ return {
119
+ root,
120
+ totalEmployees: employees.length,
121
+ departments,
122
+ maxDepth,
123
+ orphanedEmployees
124
+ };
125
+ } catch (error) {
126
+ throw new Error(
127
+ `Failed to format org chart: ${error instanceof Error ? error.message : String(error)}`
128
+ );
129
+ }
130
+ }
131
+ });
132
+ var index_default = orgChartFormatTool;
133
+
134
+ export { index_default as default, orgChartFormatTool };
package/package.json ADDED
@@ -0,0 +1,70 @@
1
+ {
2
+ "name": "@tpmjs/official-org-chart-format",
3
+ "version": "0.1.0",
4
+ "description": "Formats organizational hierarchy data into structured org chart representation",
5
+ "type": "module",
6
+ "keywords": [
7
+ "tpmjs",
8
+ "hr",
9
+ "org-chart",
10
+ "hierarchy",
11
+ "organization"
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/org-chart-format"
34
+ },
35
+ "homepage": "https://tpmjs.com",
36
+ "license": "MIT",
37
+ "tpmjs": {
38
+ "category": "hr",
39
+ "frameworks": [
40
+ "vercel-ai"
41
+ ],
42
+ "tools": [
43
+ {
44
+ "name": "orgChartFormatTool",
45
+ "description": "Formats organizational hierarchy data into structured org chart representation",
46
+ "parameters": [
47
+ {
48
+ "name": "employees",
49
+ "type": "object[]",
50
+ "description": "Employee data with manager relationships",
51
+ "required": true
52
+ }
53
+ ],
54
+ "returns": {
55
+ "type": "OrgChart",
56
+ "description": "Structured organizational chart with hierarchy"
57
+ }
58
+ }
59
+ ]
60
+ },
61
+ "dependencies": {
62
+ "ai": "6.0.0-beta.124"
63
+ },
64
+ "scripts": {
65
+ "build": "tsup",
66
+ "dev": "tsup --watch",
67
+ "type-check": "tsc --noEmit",
68
+ "clean": "rm -rf dist .turbo"
69
+ }
70
+ }