@tpmjs/official-contract-clause-scan 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,46 @@
1
+ import * as ai from 'ai';
2
+
3
+ /**
4
+ * Contract Clause Scan Tool for TPMJS
5
+ * Scans contract text to identify and categorize key clauses
6
+ */
7
+ /**
8
+ * Types of clauses commonly found in contracts
9
+ */
10
+ type ClauseType = 'termination' | 'liability' | 'intellectual_property' | 'confidentiality' | 'indemnification' | 'payment' | 'jurisdiction' | 'dispute_resolution' | 'force_majeure' | 'assignment' | 'notice' | 'amendment' | 'severability' | 'entire_agreement' | 'warranty' | 'non_compete' | 'auto_renewal' | 'other';
11
+ /**
12
+ * Represents a single identified clause
13
+ */
14
+ interface Clause {
15
+ type: ClauseType;
16
+ text: string;
17
+ location: {
18
+ startIndex: number;
19
+ endIndex: number;
20
+ paragraph?: number;
21
+ };
22
+ confidence: number;
23
+ summary: string;
24
+ }
25
+ /**
26
+ * Input interface for contract clause scanning
27
+ */
28
+ interface ContractClauseScanInput {
29
+ contractText: string;
30
+ }
31
+ /**
32
+ * Output interface for contract clause scan result
33
+ */
34
+ interface ContractClauses {
35
+ clauses: Clause[];
36
+ clauseCount: number;
37
+ clausesByType: Record<ClauseType, number>;
38
+ summary: string;
39
+ }
40
+ /**
41
+ * Contract Clause Scan Tool
42
+ * Scans contract text to identify and categorize key clauses
43
+ */
44
+ declare const contractClauseScanTool: ai.Tool<ContractClauseScanInput, ContractClauses>;
45
+
46
+ export { type Clause, type ContractClauses, contractClauseScanTool, contractClauseScanTool as default };
package/dist/index.js ADDED
@@ -0,0 +1,165 @@
1
+ import { tool, jsonSchema } from 'ai';
2
+
3
+ // src/index.ts
4
+ var CLAUSE_PATTERNS = {
5
+ termination: {
6
+ keywords: ["terminat", "cancel", "end this agreement", "cease"],
7
+ contextKeywords: ["notice", "cause", "convenience"]
8
+ },
9
+ liability: {
10
+ keywords: ["liab", "damages", "loss", "responsible for"],
11
+ contextKeywords: ["limit", "exclude", "consequential", "incidental"]
12
+ },
13
+ intellectual_property: {
14
+ keywords: ["intellectual property", "copyright", "patent", "trademark", "IP rights"],
15
+ contextKeywords: ["ownership", "license", "proprietary"]
16
+ },
17
+ confidentiality: {
18
+ keywords: ["confidential", "proprietary information", "non-disclosure"],
19
+ contextKeywords: ["secret", "disclose", "protect"]
20
+ },
21
+ indemnification: {
22
+ keywords: ["indemnif", "hold harmless", "defend"],
23
+ contextKeywords: ["claims", "losses", "expenses"]
24
+ },
25
+ payment: {
26
+ keywords: ["payment", "fee", "compensation", "invoice", "price"],
27
+ contextKeywords: ["due", "terms", "installment"]
28
+ },
29
+ jurisdiction: {
30
+ keywords: ["jurisdiction", "governing law", "venue"],
31
+ contextKeywords: ["state", "court", "laws of"]
32
+ },
33
+ dispute_resolution: {
34
+ keywords: ["arbitration", "mediation", "dispute resolution"],
35
+ contextKeywords: ["conflict", "disagreement", "binding"]
36
+ },
37
+ force_majeure: {
38
+ keywords: ["force majeure", "act of god", "beyond reasonable control"],
39
+ contextKeywords: ["excused", "delay", "natural disaster"]
40
+ },
41
+ assignment: {
42
+ keywords: ["assign", "transfer", "successor"],
43
+ contextKeywords: ["consent", "bind", "delegate"]
44
+ },
45
+ notice: {
46
+ keywords: ["notice", "notification", "written communication"],
47
+ contextKeywords: ["address", "email", "registered mail"]
48
+ },
49
+ amendment: {
50
+ keywords: ["amend", "modif", "change this agreement"],
51
+ contextKeywords: ["writing", "signed", "mutually"]
52
+ },
53
+ severability: {
54
+ keywords: ["severab", "invalid", "unenforceable"],
55
+ contextKeywords: ["provision", "remainder", "effect"]
56
+ },
57
+ entire_agreement: {
58
+ keywords: ["entire agreement", "integration", "supersede"],
59
+ contextKeywords: ["previous", "prior", "complete"]
60
+ },
61
+ warranty: {
62
+ keywords: ["warrant", "represent", "guarantee"],
63
+ contextKeywords: ["assure", "promise", "covenant"]
64
+ },
65
+ non_compete: {
66
+ keywords: ["non-compete", "non compete", "competitive"],
67
+ contextKeywords: ["restrict", "prohibit", "during term"]
68
+ },
69
+ auto_renewal: {
70
+ keywords: ["auto-renew", "automatic renewal", "renew automatically"],
71
+ contextKeywords: ["unless", "notice", "term"]
72
+ },
73
+ other: {
74
+ keywords: []
75
+ }
76
+ };
77
+ function analyzeContract(contractText) {
78
+ if (!contractText || contractText.trim().length === 0) {
79
+ throw new Error("Contract text cannot be empty");
80
+ }
81
+ const paragraphs = contractText.split(/\n\s*\n/).filter((p) => p.trim().length > 0);
82
+ const clauses = [];
83
+ const clausesByType = {};
84
+ Object.keys(CLAUSE_PATTERNS).forEach((type) => {
85
+ clausesByType[type] = 0;
86
+ });
87
+ paragraphs.forEach((paragraph, paraIndex) => {
88
+ const paraText = paragraph.trim();
89
+ const normalizedPara = paraText.toLowerCase();
90
+ const startIndex = contractText.indexOf(paraText);
91
+ for (const [type, pattern] of Object.entries(CLAUSE_PATTERNS)) {
92
+ if (type === "other") continue;
93
+ const keywordMatches = pattern.keywords.some(
94
+ (keyword) => normalizedPara.includes(keyword.toLowerCase())
95
+ );
96
+ if (keywordMatches) {
97
+ let confidence = 0.6;
98
+ if (pattern.contextKeywords) {
99
+ const contextMatches = pattern.contextKeywords.filter(
100
+ (keyword) => normalizedPara.includes(keyword.toLowerCase())
101
+ ).length;
102
+ confidence += contextMatches / pattern.contextKeywords.length * 0.4;
103
+ } else {
104
+ confidence = 0.8;
105
+ }
106
+ const sentences = paraText.split(/[.!?]+/);
107
+ const summary2 = sentences[0]?.trim() || (paraText.length > 150 ? `${paraText.substring(0, 150)}...` : paraText);
108
+ const clause = {
109
+ type,
110
+ text: paraText,
111
+ location: {
112
+ startIndex,
113
+ endIndex: startIndex + paraText.length,
114
+ paragraph: paraIndex + 1
115
+ },
116
+ confidence: Math.min(confidence, 1),
117
+ summary: summary2
118
+ };
119
+ clauses.push(clause);
120
+ clausesByType[type]++;
121
+ break;
122
+ }
123
+ }
124
+ });
125
+ const topClauseTypes = Object.entries(clausesByType).filter(([_, count]) => count > 0).sort(([, a], [, b]) => b - a).slice(0, 5).map(([type]) => type.replace(/_/g, " "));
126
+ const summary = clauses.length > 0 ? `Found ${clauses.length} clauses across ${paragraphs.length} paragraphs. Primary clause types: ${topClauseTypes.join(", ")}.` : "No standard clauses identified in the provided text.";
127
+ return {
128
+ clauses: clauses.sort((a, b) => b.confidence - a.confidence),
129
+ clauseCount: clauses.length,
130
+ clausesByType,
131
+ summary
132
+ };
133
+ }
134
+ var contractClauseScanTool = tool({
135
+ description: "Scans contract text to identify and categorize key clauses such as termination, liability, intellectual property, confidentiality, indemnification, payment terms, jurisdiction, dispute resolution, and more. Returns identified clauses with their locations in the document and confidence scores.",
136
+ inputSchema: jsonSchema({
137
+ type: "object",
138
+ properties: {
139
+ contractText: {
140
+ type: "string",
141
+ description: "The full contract text to analyze for clause identification"
142
+ }
143
+ },
144
+ required: ["contractText"],
145
+ additionalProperties: false
146
+ }),
147
+ execute: async ({ contractText }) => {
148
+ if (typeof contractText !== "string") {
149
+ throw new Error("Contract text must be a string");
150
+ }
151
+ if (contractText.trim().length === 0) {
152
+ throw new Error("Contract text cannot be empty");
153
+ }
154
+ try {
155
+ return analyzeContract(contractText);
156
+ } catch (error) {
157
+ throw new Error(
158
+ `Failed to scan contract clauses: ${error instanceof Error ? error.message : String(error)}`
159
+ );
160
+ }
161
+ }
162
+ });
163
+ var index_default = contractClauseScanTool;
164
+
165
+ export { contractClauseScanTool, index_default as default };
package/package.json ADDED
@@ -0,0 +1,70 @@
1
+ {
2
+ "name": "@tpmjs/official-contract-clause-scan",
3
+ "version": "0.1.0",
4
+ "description": "Scans contract text to identify and categorize key clauses (termination, liability, IP, etc.)",
5
+ "type": "module",
6
+ "keywords": [
7
+ "tpmjs",
8
+ "legal",
9
+ "contract",
10
+ "clause",
11
+ "analysis"
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/contract-clause-scan"
34
+ },
35
+ "homepage": "https://tpmjs.com",
36
+ "license": "MIT",
37
+ "tpmjs": {
38
+ "category": "legal",
39
+ "frameworks": [
40
+ "vercel-ai"
41
+ ],
42
+ "tools": [
43
+ {
44
+ "name": "contractClauseScanTool",
45
+ "description": "Scans contract text to identify and categorize key clauses (termination, liability, IP, etc.)",
46
+ "parameters": [
47
+ {
48
+ "name": "contractText",
49
+ "type": "string",
50
+ "description": "Contract text to analyze",
51
+ "required": true
52
+ }
53
+ ],
54
+ "returns": {
55
+ "type": "ContractClauses",
56
+ "description": "Identified clauses by category with locations"
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
+ }