@codehz/ai 0.4.6 → 0.7.1
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/README.md +221 -75
- package/dist/index.d.mts +670 -523
- package/dist/index.mjs +3677 -2207
- package/dist/index.mjs.map +1 -1
- package/package.json +19 -8
- package/.github/workflows/publish.yml +0 -56
- package/.oxfmtrc.json +0 -12
- package/.oxlintrc.json +0 -34
- package/AGENTS.md +0 -37
- package/src/adapters/chat-completions.ts +0 -624
- package/src/adapters/index.ts +0 -44
- package/src/adapters/messages.ts +0 -635
- package/src/adapters/mock.ts +0 -934
- package/src/adapters/ollama.ts +0 -526
- package/src/adapters/responses.ts +0 -818
- package/src/core/aggregator.ts +0 -428
- package/src/core/client.ts +0 -36
- package/src/core/collect-stream.ts +0 -19
- package/src/core/errors.ts +0 -105
- package/src/core/event-factory.ts +0 -151
- package/src/core/index.ts +0 -18
- package/src/core/merge-auxiliary.ts +0 -22
- package/src/core/normalize.ts +0 -65
- package/src/core/validation.ts +0 -404
- package/src/helpers/adapter-auxiliary.ts +0 -155
- package/src/helpers/adapter-base.ts +0 -218
- package/src/helpers/adapter-security.ts +0 -126
- package/src/helpers/auxiliary-collector.ts +0 -166
- package/src/helpers/incremental-stream-parser.ts +0 -142
- package/src/helpers/index.ts +0 -87
- package/src/helpers/mapping.ts +0 -192
- package/src/helpers/provider-request-options.ts +0 -25
- package/src/helpers/provider-stream.ts +0 -147
- package/src/helpers/reasoning-level.ts +0 -86
- package/src/helpers/request-mapper.ts +0 -94
- package/src/helpers/synthetic-stream.ts +0 -188
- package/src/helpers/usage-mapping.ts +0 -110
- package/src/index.ts +0 -17
- package/src/types/adapter.ts +0 -42
- package/src/types/content.ts +0 -15
- package/src/types/events.ts +0 -138
- package/src/types/index.ts +0 -49
- package/src/types/items.ts +0 -57
- package/src/types/request.ts +0 -52
- package/src/types/response.ts +0 -68
- package/tsdown.config.ts +0 -10
package/package.json
CHANGED
|
@@ -1,18 +1,24 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@codehz/ai",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.1",
|
|
4
|
+
"repository": {
|
|
5
|
+
"type": "git",
|
|
6
|
+
"url": "git+https://github.com/codehz/nano-ai.git"
|
|
7
|
+
},
|
|
8
|
+
"files": [
|
|
9
|
+
"dist"
|
|
10
|
+
],
|
|
4
11
|
"type": "module",
|
|
5
|
-
"
|
|
12
|
+
"sideEffects": false,
|
|
13
|
+
"main": "./dist/index.mjs",
|
|
14
|
+
"module": "./dist/index.mjs",
|
|
15
|
+
"types": "./dist/index.d.mts",
|
|
6
16
|
"exports": {
|
|
7
17
|
".": {
|
|
8
|
-
"
|
|
9
|
-
"
|
|
18
|
+
"types": "./dist/index.d.mts",
|
|
19
|
+
"default": "./dist/index.mjs"
|
|
10
20
|
}
|
|
11
21
|
},
|
|
12
|
-
"repository": {
|
|
13
|
-
"type": "git",
|
|
14
|
-
"url": "git+https://github.com/codehz/nano-ai.git"
|
|
15
|
-
},
|
|
16
22
|
"publishConfig": {
|
|
17
23
|
"access": "public",
|
|
18
24
|
"registry": "https://registry.npmjs.org/"
|
|
@@ -27,6 +33,7 @@
|
|
|
27
33
|
"example:basic": "bun run examples/basic.ts",
|
|
28
34
|
"example:multi-turn": "bun run examples/multi-turn.ts",
|
|
29
35
|
"example:tool-loop": "bun run examples/tool-loop.ts",
|
|
36
|
+
"example:server-tools": "bun run examples/server-tools.ts",
|
|
30
37
|
"prepack": "tsdown"
|
|
31
38
|
},
|
|
32
39
|
"devDependencies": {
|
|
@@ -35,5 +42,9 @@
|
|
|
35
42
|
"oxlint": "^1.73.0",
|
|
36
43
|
"tsdown": "^0.22.3",
|
|
37
44
|
"typescript": "^6"
|
|
45
|
+
},
|
|
46
|
+
"engines": {
|
|
47
|
+
"bun": ">=1.1.0",
|
|
48
|
+
"node": ">=18"
|
|
38
49
|
}
|
|
39
50
|
}
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
name: Publish Package
|
|
2
|
-
|
|
3
|
-
on:
|
|
4
|
-
push:
|
|
5
|
-
tags:
|
|
6
|
-
- "v*"
|
|
7
|
-
|
|
8
|
-
permissions:
|
|
9
|
-
contents: read
|
|
10
|
-
id-token: write # required for npm trusted publishing (OIDC)
|
|
11
|
-
|
|
12
|
-
jobs:
|
|
13
|
-
publish:
|
|
14
|
-
runs-on: ubuntu-latest
|
|
15
|
-
steps:
|
|
16
|
-
- uses: actions/checkout@v6
|
|
17
|
-
|
|
18
|
-
- name: Verify tag matches package.json version
|
|
19
|
-
run: |
|
|
20
|
-
tag="${GITHUB_REF_NAME#v}"
|
|
21
|
-
version="$(node -p "require('./package.json').version")"
|
|
22
|
-
if [ "$tag" != "$version" ]; then
|
|
23
|
-
echo "Tag v${tag} does not match package.json version ${version}"
|
|
24
|
-
exit 1
|
|
25
|
-
fi
|
|
26
|
-
|
|
27
|
-
- uses: oven-sh/setup-bun@v2
|
|
28
|
-
with:
|
|
29
|
-
bun-version: latest
|
|
30
|
-
|
|
31
|
-
- name: Install dependencies
|
|
32
|
-
run: bun install --frozen-lockfile
|
|
33
|
-
|
|
34
|
-
- name: Typecheck
|
|
35
|
-
run: bun run typecheck
|
|
36
|
-
|
|
37
|
-
- name: Lint
|
|
38
|
-
run: bun run lint
|
|
39
|
-
|
|
40
|
-
- name: Test
|
|
41
|
-
run: bun test
|
|
42
|
-
|
|
43
|
-
# Trusted publishing requires npm CLI (OIDC); other package managers cannot publish this way.
|
|
44
|
-
- uses: actions/setup-node@v6
|
|
45
|
-
with:
|
|
46
|
-
node-version: "24"
|
|
47
|
-
registry-url: "https://registry.npmjs.org"
|
|
48
|
-
package-manager-cache: false # never cache package manager state for release builds
|
|
49
|
-
|
|
50
|
-
- name: Ensure npm CLI supports trusted publishing
|
|
51
|
-
run: npm install -g npm@latest
|
|
52
|
-
|
|
53
|
-
- name: Publish to npm
|
|
54
|
-
# No NPM_TOKEN: npm CLI exchanges the GitHub OIDC token automatically.
|
|
55
|
-
# Provenance is generated automatically for trusted publishing from public repos.
|
|
56
|
-
run: npm publish --access public
|
package/.oxfmtrc.json
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"$schema": "./node_modules/oxfmt/configuration_schema.json",
|
|
3
|
-
"semi": true,
|
|
4
|
-
"singleQuote": false,
|
|
5
|
-
"tabWidth": 2,
|
|
6
|
-
"useTabs": false,
|
|
7
|
-
"trailingComma": "all",
|
|
8
|
-
"printWidth": 120,
|
|
9
|
-
"endOfLine": "lf",
|
|
10
|
-
"arrowParens": "always",
|
|
11
|
-
"ignorePatterns": ["node_modules", "dist", "out", "coverage"]
|
|
12
|
-
}
|
package/.oxlintrc.json
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"$schema": "./node_modules/oxlint/configuration_schema.json",
|
|
3
|
-
"plugins": ["typescript", "unicorn", "oxc", "import"],
|
|
4
|
-
"categories": {
|
|
5
|
-
"correctness": "error",
|
|
6
|
-
"suspicious": "warn",
|
|
7
|
-
"perf": "warn"
|
|
8
|
-
},
|
|
9
|
-
"rules": {
|
|
10
|
-
"import/default": "error",
|
|
11
|
-
"import/no-duplicates": "error",
|
|
12
|
-
"import/named": "error",
|
|
13
|
-
"import/namespace": "error",
|
|
14
|
-
"no-await-in-loop": "off",
|
|
15
|
-
"typescript/no-non-null-assertion": "warn",
|
|
16
|
-
"unicorn/no-null": "off",
|
|
17
|
-
"unicorn/no-array-for-each": "off",
|
|
18
|
-
"unicorn/prefer-module": "off",
|
|
19
|
-
"unicorn/prefer-top-level-await": "off"
|
|
20
|
-
},
|
|
21
|
-
"overrides": [
|
|
22
|
-
{
|
|
23
|
-
"files": ["tests/**/*.ts"],
|
|
24
|
-
"rules": {
|
|
25
|
-
"typescript/no-non-null-assertion": "off",
|
|
26
|
-
"unicorn/no-array-reverse": "off"
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
],
|
|
30
|
-
"env": {
|
|
31
|
-
"builtin": true,
|
|
32
|
-
"node": true
|
|
33
|
-
}
|
|
34
|
-
}
|
package/AGENTS.md
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
# Repository Guidelines
|
|
2
|
-
|
|
3
|
-
## Project Structure & Module Organization
|
|
4
|
-
|
|
5
|
-
`src/` contains the library source. Keep canonical request/response logic in `src/core/`, provider integrations in `src/adapters/`, reusable stream utilities in `src/helpers/`, and shared types in `src/types/`. The public entrypoint is `src/index.ts`.
|
|
6
|
-
|
|
7
|
-
`tests/` holds Bun test suites plus shared fixtures such as `tests/fixtures.ts`. `examples/` contains runnable usage samples like `examples/basic.ts` and `examples/tool-loop.ts`. `dist/` is generated output from the packaging build and should not be edited by hand.
|
|
8
|
-
|
|
9
|
-
## Build, Test, and Development Commands
|
|
10
|
-
|
|
11
|
-
- `bun install` installs dependencies.
|
|
12
|
-
- `bun run typecheck` runs strict TypeScript validation without emitting files.
|
|
13
|
-
- `bun run lint` checks the codebase with `oxlint`; use `bun run lint:fix` for safe autofixes.
|
|
14
|
-
- `bun run format` applies `oxfmt`; `bun run format:check` verifies formatting in CI style.
|
|
15
|
-
- `bun test` runs the full Bun test suite.
|
|
16
|
-
- `bun run example:basic`, `bun run example:multi-turn`, and `bun run example:tool-loop` execute sample integrations.
|
|
17
|
-
- `bun run prepack` builds the package with `tsdown` into `dist/`.
|
|
18
|
-
|
|
19
|
-
## Coding Style & Naming Conventions
|
|
20
|
-
|
|
21
|
-
This repository uses TypeScript ESM with 2-space indentation, semicolons, double quotes, trailing commas, and LF line endings. `oxfmt` enforces formatting, and `oxlint` enforces import correctness and general safety rules.
|
|
22
|
-
|
|
23
|
-
Follow existing naming patterns: kebab-case filenames such as `chat-completions.ts`, PascalCase for exported classes and types, and camelCase for functions, variables, and helpers. Add public exports through the existing index files instead of reaching into deep paths from consumers.
|
|
24
|
-
|
|
25
|
-
## Testing Guidelines
|
|
26
|
-
|
|
27
|
-
Tests use `bun:test` and live in `tests/*.test.ts`. Name suites after the unit or scenario under test, for example `responses-adapter.test.ts` or `scenarios.test.ts`. Favor behavior-focused `describe`/`it` blocks and cover event ordering, replay round-trips, warnings, and adapter-specific edge cases. Use `MockAdapter` and shared fixtures when validating streaming behavior.
|
|
28
|
-
|
|
29
|
-
## Commit & Pull Request Guidelines
|
|
30
|
-
|
|
31
|
-
Recent history follows conventional prefixes such as `feat(mock): ...`, `refactor(types): ...`, `docs: ...`, `build: ...`, and `chore: ...`. Keep scopes aligned with the subsystem you changed.
|
|
32
|
-
|
|
33
|
-
Pull requests should summarize behavior changes, list verification commands run locally, and link the relevant issue when applicable. Include example output or event traces when changing stream semantics or adapter behavior.
|
|
34
|
-
|
|
35
|
-
## Configuration & Secrets
|
|
36
|
-
|
|
37
|
-
Use environment variables for provider credentials, such as `OPENAI_API_KEY`. Do not hardcode secrets in source, examples, or tests.
|