Skip to content

Commit 4b26cbd

Browse files
committed
chore: drop cross-fetch, expose source exports
1 parent d02ba4f commit 4b26cbd

18 files changed

Lines changed: 120 additions & 72 deletions

File tree

README.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,59 @@ const message = await complete(model!, {
4545
console.log(message.content);
4646
```
4747

48+
## Requirements
49+
50+
Node `>=18.17.0`. The provider adapters use `globalThis.fetch` directly — no
51+
ponyfill, no polyfill. All supported runtimes (modern browsers, Bun, Deno, and
52+
Node 18.17+) ship a Web-standard fetch with a `ReadableStream` body, which the
53+
adapters need for SSE.
54+
55+
## Consuming from webpack / Next.js
56+
57+
The packages publish ESM with `.js`-suffixed relative imports (e.g.
58+
`from './foo.js'`), which is the correct ESM-with-TS pattern. Webpack does not
59+
auto-rewrite `.js``.ts` when reading TypeScript sources directly (e.g. when
60+
linking the workspace from `apps/`), so add an `extensionAlias` to your
61+
`next.config.mjs`:
62+
63+
```js
64+
// next.config.mjs
65+
export default {
66+
transpilePackages: [
67+
'agentic-kit',
68+
'@agentic-kit/agent',
69+
'@agentic-kit/react',
70+
'@agentic-kit/openai',
71+
'@agentic-kit/anthropic',
72+
'@agentic-kit/ollama',
73+
],
74+
webpack: (config) => {
75+
config.resolve.extensionAlias = {
76+
'.js': ['.ts', '.tsx', '.js'],
77+
'.mjs': ['.mts', '.mjs'],
78+
};
79+
return config;
80+
},
81+
};
82+
```
83+
84+
Once a published artifact is installed (`npm install agentic-kit`), the
85+
compiled `dist/` is what resolves and no `extensionAlias` is required — this
86+
workaround only matters when reading TypeScript source through webpack.
87+
88+
Vite, Bun, and esbuild handle `.js``.ts` natively. Vite users who want to
89+
consume the workspace TypeScript source via the package `"source"` condition
90+
can opt in with:
91+
92+
```js
93+
// vite.config.ts
94+
export default {
95+
resolve: {
96+
conditions: ['source', 'import', 'module', 'browser', 'default'],
97+
},
98+
};
99+
```
100+
48101
## Contributing
49102

50103
See individual package READMEs for docs and local dev instructions.

packages/agent/package.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@
66
"main": "index.js",
77
"module": "esm/index.js",
88
"types": "index.d.ts",
9+
"exports": {
10+
".": {
11+
"source": "./src/index.ts",
12+
"types": "./index.d.ts",
13+
"import": "./esm/index.js",
14+
"require": "./index.js"
15+
}
16+
},
917
"homepage": "https://github.com/constructive-io/agentic-kit",
1018
"license": "SEE LICENSE IN LICENSE",
1119
"publishConfig": {

packages/agentic-kit/jest.setup.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
global.TextEncoder = require('util').TextEncoder;
22
global.TextDecoder = require('util').TextDecoder;
33

4-
jest.mock('cross-fetch', () => jest.fn());
4+
global.fetch = jest.fn();

packages/agentic-kit/package.json

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@
66
"main": "index.js",
77
"module": "esm/index.js",
88
"types": "index.d.ts",
9+
"exports": {
10+
".": {
11+
"source": "./src/index.ts",
12+
"types": "./index.d.ts",
13+
"import": "./esm/index.js",
14+
"require": "./index.js"
15+
}
16+
},
917
"homepage": "https://github.com/constructive-io/agentic-kit",
1018
"license": "SEE LICENSE IN LICENSE",
1119
"publishConfig": {
@@ -33,8 +41,5 @@
3341
"@agentic-kit/ollama": "workspace:*",
3442
"@agentic-kit/openai": "workspace:*"
3543
},
36-
"devDependencies": {
37-
"cross-fetch": "^4.1.0"
38-
},
3944
"keywords": []
4045
}

packages/anthropic/__tests__/anthropic.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import fetch from 'cross-fetch';
21
import { TextEncoder } from 'util';
32

43
import { AnthropicAdapter } from '../src';
54

5+
const fetch = global.fetch as jest.Mock;
6+
67
function createStreamingResponse(frames: string[]) {
78
const encoded = new TextEncoder().encode(frames.join('\n\n'));
89
const reader = {

packages/anthropic/jest.setup.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
global.TextEncoder = require('util').TextEncoder;
22
global.TextDecoder = require('util').TextDecoder;
33

4-
jest.mock('cross-fetch', () => jest.fn());
4+
global.fetch = jest.fn();

packages/anthropic/package.json

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@
66
"main": "index.js",
77
"module": "esm/index.js",
88
"types": "index.d.ts",
9+
"exports": {
10+
".": {
11+
"source": "./src/index.ts",
12+
"types": "./index.d.ts",
13+
"import": "./esm/index.js",
14+
"require": "./index.js"
15+
}
16+
},
917
"homepage": "https://github.com/constructive-io/agentic-kit",
1018
"license": "SEE LICENSE IN LICENSE",
1119
"publishConfig": {
@@ -28,8 +36,5 @@
2836
"test": "jest",
2937
"test:watch": "jest --watch"
3038
},
31-
"keywords": [],
32-
"dependencies": {
33-
"cross-fetch": "^4.1.0"
34-
}
39+
"keywords": []
3540
}

packages/anthropic/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import fetch from 'cross-fetch';
1+
const fetch: typeof globalThis.fetch = globalThis.fetch.bind(globalThis);
22

33
type JsonPrimitive = string | number | boolean | null;
44
type JsonValue = JsonPrimitive | JsonObject | JsonValue[];

packages/ollama/__tests__/ollama.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import fetch from 'cross-fetch';
21
import { PassThrough } from 'stream';
32
import { TextEncoder } from 'util';
43

54
import OllamaClient, { OllamaAdapter } from '../src';
65

6+
const fetch = global.fetch as jest.Mock;
7+
78
function createLineResponse(lines: string[]) {
89
const encoded = new TextEncoder().encode(lines.join('\n'));
910
const reader = {

packages/ollama/jest.setup.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ global.TextEncoder = require('util').TextEncoder;
22
global.TextDecoder = require('util').TextDecoder;
33

44
if (process.env.OLLAMA_LIVE_READY !== '1') {
5-
jest.mock('cross-fetch', () => jest.fn());
5+
global.fetch = jest.fn();
66
}

0 commit comments

Comments
 (0)