|
| 1 | +# How to Import UTCP Packages |
| 2 | + |
| 3 | +## ✅ Fixed Export Configuration |
| 4 | + |
| 5 | +Your packages now use the **standard library pattern** - all exports go through the main entry point. |
| 6 | + |
| 7 | +## Correct Import Usage |
| 8 | + |
| 9 | +### ✅ Import from Main Entry Point |
| 10 | + |
| 11 | +```typescript |
| 12 | +// ✅ CORRECT - Import from package root |
| 13 | +import { UtcpClient, ToolDefinition, CallTemplate } from '@utcp/sdk'; |
| 14 | +import { McpCommunicationProtocol } from '@utcp/mcp'; |
| 15 | +import { TextCallTemplate } from '@utcp/text'; |
| 16 | +import { HttpCommunicationProtocol } from '@utcp/http'; |
| 17 | +import { CliCallTemplate } from '@utcp/cli'; |
| 18 | +``` |
| 19 | + |
| 20 | +### ❌ Don't Import from Subpaths |
| 21 | + |
| 22 | +```typescript |
| 23 | +// ❌ WRONG - Don't import from dist or subpaths |
| 24 | +import { ToolDefinition } from '@utcp/sdk'; |
| 25 | +import { ToolDefinition } from '@utcp/sdk/data'; |
| 26 | +``` |
| 27 | + |
| 28 | +## Why This Is Better |
| 29 | + |
| 30 | +### 1. **Standard Library Pattern** |
| 31 | +This is how all major libraries work: |
| 32 | +- `import { z } from 'zod'` (not `'zod/types'`) |
| 33 | +- `import { format } from 'date-fns'` (not `'date-fns/format'`) |
| 34 | +- `import React from 'react'` (not `'react/components'`) |
| 35 | + |
| 36 | +### 2. **Simpler API** |
| 37 | +Users only need to remember one import path per package. |
| 38 | + |
| 39 | +### 3. **Better Tree-Shaking** |
| 40 | +Modern bundlers can tree-shake unused exports from the main entry point automatically. |
| 41 | + |
| 42 | +### 4. **Prevents Breaking Changes** |
| 43 | +Internal file structure can change without breaking user code. |
| 44 | + |
| 45 | +## Package Exports Summary |
| 46 | + |
| 47 | +### @utcp/sdk (Core Package) |
| 48 | +```typescript |
| 49 | +import { |
| 50 | + // Client |
| 51 | + UtcpClient, |
| 52 | + UtcpClientConfig, |
| 53 | + |
| 54 | + // Data Models |
| 55 | + Auth, |
| 56 | + CallTemplate, |
| 57 | + Tool, |
| 58 | + ToolDefinition, |
| 59 | + UtcpManual, |
| 60 | + RegisterManualResult, |
| 61 | + |
| 62 | + // Interfaces |
| 63 | + CommunicationProtocol, |
| 64 | + ConcurrentToolRepository, |
| 65 | + Serializer, |
| 66 | + ToolSearchStrategy, |
| 67 | + VariableSubstitutor, |
| 68 | + |
| 69 | + // Implementations |
| 70 | + InMemConcurrentToolRepository, |
| 71 | + TagSearchStrategy, |
| 72 | + |
| 73 | + // Plugins |
| 74 | + PluginLoader |
| 75 | +} from '@utcp/sdk'; |
| 76 | +``` |
| 77 | + |
| 78 | +### @utcp/mcp |
| 79 | +```typescript |
| 80 | +import { |
| 81 | + McpCommunicationProtocol, |
| 82 | + McpCallTemplate |
| 83 | +} from '@utcp/mcp'; |
| 84 | +``` |
| 85 | + |
| 86 | +### @utcp/text |
| 87 | +```typescript |
| 88 | +import { |
| 89 | + TextCommunicationProtocol, |
| 90 | + TextCallTemplate, |
| 91 | + TextCallTemplateSerializer |
| 92 | +} from '@utcp/text'; |
| 93 | +``` |
| 94 | + |
| 95 | +### @utcp/http |
| 96 | +```typescript |
| 97 | +import { |
| 98 | + HttpCommunicationProtocol, |
| 99 | + HttpCallTemplate, |
| 100 | + OpenApiConverter, |
| 101 | + SseCommunicationProtocol, |
| 102 | + SseCallTemplate, |
| 103 | + StreamableHttpCommunicationProtocol, |
| 104 | + StreamableHttpCallTemplate |
| 105 | +} from '@utcp/http'; |
| 106 | +``` |
| 107 | + |
| 108 | +### @utcp/cli |
| 109 | +```typescript |
| 110 | +import { |
| 111 | + CliCommunicationProtocol, |
| 112 | + CliCallTemplate |
| 113 | +} from '@utcp/cli'; |
| 114 | +``` |
| 115 | + |
| 116 | +## TypeScript IntelliSense |
| 117 | + |
| 118 | +Your IDE will show all available exports when you start typing: |
| 119 | + |
| 120 | +```typescript |
| 121 | +import { /* Ctrl+Space to see all exports */ } from '@utcp/sdk'; |
| 122 | +``` |
| 123 | + |
| 124 | +## Configuration Changes Made |
| 125 | + |
| 126 | +### Before (Problematic) |
| 127 | +```json |
| 128 | +{ |
| 129 | + "exports": { |
| 130 | + ".": { |
| 131 | + "import": "./dist/index.js" |
| 132 | + }, |
| 133 | + "./*": { |
| 134 | + "import": "./dist/*.js" // ❌ This caused @utcp/sdk/dist/ imports |
| 135 | + } |
| 136 | + } |
| 137 | +} |
| 138 | +``` |
| 139 | + |
| 140 | +### After (Fixed) |
| 141 | +```json |
| 142 | +{ |
| 143 | + "exports": { |
| 144 | + ".": { |
| 145 | + "import": "./dist/index.js", |
| 146 | + "types": "./dist/index.d.ts" |
| 147 | + } |
| 148 | + } |
| 149 | +} |
| 150 | +``` |
| 151 | + |
| 152 | +## Re-Publishing |
| 153 | + |
| 154 | +After these changes, you should publish new patch versions: |
| 155 | + |
| 156 | +```bash |
| 157 | +# Update version in each package.json (1.0.1 -> 1.0.2) |
| 158 | +bun run rebuild |
| 159 | +bun run publish:all |
| 160 | +``` |
| 161 | + |
| 162 | +## Migration Guide for Existing Users |
| 163 | + |
| 164 | +If users were importing from subpaths, they need to update: |
| 165 | + |
| 166 | +```typescript |
| 167 | +// Before |
| 168 | +import { ToolDefinition } from '@utcp/sdk'; |
| 169 | + |
| 170 | +// After |
| 171 | +import { ToolDefinition } from '@utcp/sdk'; |
| 172 | +``` |
| 173 | + |
| 174 | +This is a one-line change and follows standard npm package conventions. |
0 commit comments