kopia lustrzana https://github.com/transitive-bullshit/chatgpt-api
feat: WIP refactor to monorepo and separate packages
rodzic
3bc0a2c428
commit
a5e8fbeaa2
|
@ -1,8 +1,8 @@
|
|||
#!/usr/bin/env node
|
||||
import 'dotenv/config'
|
||||
|
||||
import { WeatherClient } from '@agentic/stdlib'
|
||||
import { createAISDKTools } from '@agentic/stdlib/ai-sdk'
|
||||
import { createAISDKTools } from '@agentic/ai-sdk'
|
||||
import { WeatherClient } from '@agentic/weather'
|
||||
import { openai } from '@ai-sdk/openai'
|
||||
import { generateText } from 'ai'
|
||||
|
|
@ -1,7 +1,6 @@
|
|||
{
|
||||
"name": "agentic-examples",
|
||||
"name": "agentic-examples-ai-sdk",
|
||||
"private": true,
|
||||
"version": "0.1.0",
|
||||
"description": "Examples of how to use the Agentic AI SDK.",
|
||||
"author": "Travis Fischer <travis@transitivebullsh.it>",
|
||||
"license": "MIT",
|
||||
|
@ -9,33 +8,24 @@
|
|||
"type": "git",
|
||||
"url": "git+https://github.com/transitive-bullshit/agentic.git"
|
||||
},
|
||||
"packageManager": "pnpm@9.2.0",
|
||||
"engines": {
|
||||
"node": ">=18"
|
||||
},
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"preinstall": "npx only-allow pnpm",
|
||||
"build": "tsc",
|
||||
"clean": "del dist",
|
||||
"prebuild": "run-s clean",
|
||||
"pretest": "run-s build",
|
||||
"test": "run-s test:*",
|
||||
"test:format": "prettier --check \"**/*.{js,ts,tsx}\"",
|
||||
"test:lint": "eslint .",
|
||||
"test:typecheck": "tsc --noEmit"
|
||||
},
|
||||
"dependencies": {
|
||||
"@agentic/stdlib": "workspace:*",
|
||||
"@agentic/ai-sdk": "workspace:*",
|
||||
"@agentic/core": "workspace:*",
|
||||
"@agentic/weather": "workspace:*",
|
||||
"@ai-sdk/openai": "^0.0.24",
|
||||
"@dexaai/dexter": "^2.1.0",
|
||||
"@genkit-ai/ai": "^0.5.2",
|
||||
"@genkit-ai/core": "^0.5.2",
|
||||
"@langchain/core": "^0.2.6",
|
||||
"@langchain/openai": "^0.1.2",
|
||||
"@browserbasehq/sdk": "^1.4.2",
|
||||
"ai": "^3.1.30",
|
||||
"dotenv": "^16.4.5",
|
||||
"genkitx-openai": "^0.10.0",
|
||||
"langchain": "^0.2.5",
|
||||
"llamaindex": "^0.3.16",
|
||||
"openai": "^4.49.0",
|
||||
"zod": "^3.23.8"
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
{
|
||||
"extends": "../../tsconfig.json",
|
||||
"include": ["bin"]
|
||||
}
|
|
@ -1,4 +0,0 @@
|
|||
{
|
||||
"extends": "../tsconfig.json",
|
||||
"include": ["ai-sdk", "dexter", "genkit", "langchain", "llamaindex", "openai"]
|
||||
}
|
75
package.json
75
package.json
|
@ -1,7 +1,6 @@
|
|||
{
|
||||
"name": "@agentic/stdlib",
|
||||
"version": "6.6.1",
|
||||
"description": "AI function stdlib that works with any LLM and TypeScript AI SDK.",
|
||||
"name": "agentic",
|
||||
"private": true,
|
||||
"author": "Travis Fischer <travis@transitivebullsh.it>",
|
||||
"license": "MIT",
|
||||
"repository": {
|
||||
|
@ -13,91 +12,51 @@
|
|||
"node": ">=18"
|
||||
},
|
||||
"type": "module",
|
||||
"source": "./src/index.ts",
|
||||
"types": "./dist/index.d.ts",
|
||||
"sideEffects": false,
|
||||
"exports": {
|
||||
".": {
|
||||
"types": "./dist/index.d.ts",
|
||||
"import": "./dist/index.js",
|
||||
"default": "./dist/index.js"
|
||||
}
|
||||
},
|
||||
"files": [
|
||||
"dist"
|
||||
],
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
},
|
||||
"scripts": {
|
||||
"preinstall": "npx only-allow pnpm",
|
||||
"build": "tsup",
|
||||
"dev": "tsup --watch",
|
||||
"clean": "del dist",
|
||||
"build": "run-s build:*",
|
||||
"build:core": "cd packages/core && pnpm build",
|
||||
"build:ai-sdk": "cd packages/ai-sdk && pnpm build",
|
||||
"build:weather": "cd packages/weather && pnpm build",
|
||||
"build:examples": "cd examples/ai-sdk && pnpm build",
|
||||
"clean": "run-s clean:*",
|
||||
"clean:core": "cd packages/core && pnpm clean",
|
||||
"clean:ai-sdk": "cd packages/ai-sdk && pnpm clean",
|
||||
"clean:weather": "cd packages/weather && pnpm clean",
|
||||
"clean:examples": "cd examples/ai-sdk && pnpm clean",
|
||||
"prebuild": "run-s clean",
|
||||
"precommit": "lint-staged",
|
||||
"predev": "run-s clean",
|
||||
"preinstall": "npx only-allow pnpm",
|
||||
"pretest": "run-s build",
|
||||
"prepare": "husky",
|
||||
"precommit": "lint-staged",
|
||||
"test": "run-s test:*",
|
||||
"test:format": "prettier --check \"**/*.{js,ts,tsx}\"",
|
||||
"test:lint": "eslint .",
|
||||
"test:typecheck": "tsc --noEmit",
|
||||
"test:unit": "vitest run"
|
||||
},
|
||||
"dependencies": {
|
||||
"dedent": "^1.5.3",
|
||||
"delay": "^6.0.0",
|
||||
"hash-object": "^5.0.1",
|
||||
"is-relative-url": "^4.0.0",
|
||||
"jsonrepair": "^3.6.1",
|
||||
"ky": "^1.5.0",
|
||||
"normalize-url": "^8.0.1",
|
||||
"p-map": "^7.0.2",
|
||||
"p-throttle": "^6.1.0",
|
||||
"quick-lru": "^7.0.0",
|
||||
"type-fest": "^4.21.0",
|
||||
"zod": "^3.23.3",
|
||||
"zod-to-json-schema": "^3.23.2",
|
||||
"zod-validation-error": "^3.3.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@aws-sdk/client-sso-oidc": "^3.620.1",
|
||||
"@browserbasehq/sdk": "^1.4.2",
|
||||
"@dexaai/dexter": "^2.1.0",
|
||||
"@e2b/code-interpreter": "^0.0.8",
|
||||
"@fisch0920/eslint-config": "^1.4.0",
|
||||
"@genkit-ai/ai": "^0.5.8",
|
||||
"@langchain/core": "^0.2.18",
|
||||
"@nangohq/node": "^0.42.2",
|
||||
"@total-typescript/ts-reset": "^0.5.1",
|
||||
"@types/node": "^22.0.0",
|
||||
"ai": "^3.2.39",
|
||||
"del-cli": "^5.1.0",
|
||||
"dotenv": "^16.4.5",
|
||||
"eslint": "^8.57.0",
|
||||
"husky": "^9.1.4",
|
||||
"lint-staged": "^15.2.7",
|
||||
"llamaindex": "^0.5.11",
|
||||
"mathjs": "^13.0.3",
|
||||
"np": "^10.0.7",
|
||||
"npm-run-all2": "^6.2.2",
|
||||
"octokit": "^4.0.2",
|
||||
"only-allow": "^1.2.1",
|
||||
"openai-fetch": "^2.0.4",
|
||||
"prettier": "^3.3.3",
|
||||
"restore-cursor": "^5.1.0",
|
||||
"tsup": "^8.2.3",
|
||||
"tsx": "^4.16.2",
|
||||
"twitter-api-sdk": "^1.2.1",
|
||||
"typescript": "^5.5.4",
|
||||
"vitest": "2.0.4",
|
||||
"wikibase-sdk": "^10.0.2"
|
||||
"zod": "^3.23.3"
|
||||
},
|
||||
"lint-staged": {
|
||||
"*.{ts,tsx}": [
|
||||
"eslint --fix",
|
||||
"prettier --ignore-unknown --write"
|
||||
"prettier --ignore-unknown --write",
|
||||
"eslint --fix"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
{
|
||||
"name": "@agentic/ai-sdk",
|
||||
"version": "6.6.1",
|
||||
"description": "Agentic adapter for the Vercel AI SDK.",
|
||||
"author": "Travis Fischer <travis@transitivebullsh.it>",
|
||||
"license": "MIT",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/transitive-bullshit/agentic.git"
|
||||
},
|
||||
"type": "module",
|
||||
"source": "./src/index.ts",
|
||||
"types": "./dist/index.d.ts",
|
||||
"sideEffects": false,
|
||||
"exports": {
|
||||
".": {
|
||||
"types": "./dist/index.d.ts",
|
||||
"import": "./dist/index.js",
|
||||
"default": "./dist/index.js"
|
||||
}
|
||||
},
|
||||
"files": [
|
||||
"dist"
|
||||
],
|
||||
"scripts": {
|
||||
"build": "tsup",
|
||||
"dev": "tsup --watch",
|
||||
"clean": "del dist",
|
||||
"test": "run-s test:*",
|
||||
"test:format": "prettier --check \"**/*.{js,ts,tsx}\"",
|
||||
"test:lint": "eslint .",
|
||||
"test:typecheck": "tsc --noEmit",
|
||||
"test:unit": "vitest run"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@agentic/core": "workspace:*",
|
||||
"ai": "^3.1.30"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@agentic/core": "workspace:*"
|
||||
},
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
}
|
||||
}
|
|
@ -1,8 +1,6 @@
|
|||
import { type AIFunctionLike, AIFunctionSet } from '@agentic/core'
|
||||
import { tool } from 'ai'
|
||||
|
||||
import type { AIFunctionLike } from '../types'
|
||||
import { AIFunctionSet } from '../ai-function-set'
|
||||
|
||||
/**
|
||||
* Converts a set of Agentic stdlib AI functions to an object compatible with
|
||||
* the Vercel AI SDK's `tools` parameter.
|
|
@ -0,0 +1 @@
|
|||
export * from './ai-sdk'
|
|
@ -0,0 +1,4 @@
|
|||
{
|
||||
"extends": "../../tsconfig.json",
|
||||
"include": ["src"]
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
export { default } from '../../tsup.config'
|
|
@ -0,0 +1,57 @@
|
|||
{
|
||||
"name": "@agentic/core",
|
||||
"version": "6.6.1",
|
||||
"description": "AI function stdlib that works with any LLM and TypeScript AI SDK.",
|
||||
"author": "Travis Fischer <travis@transitivebullsh.it>",
|
||||
"license": "MIT",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/transitive-bullshit/agentic.git"
|
||||
},
|
||||
"type": "module",
|
||||
"source": "./src/index.ts",
|
||||
"types": "./dist/index.d.ts",
|
||||
"sideEffects": false,
|
||||
"exports": {
|
||||
".": {
|
||||
"types": "./dist/index.d.ts",
|
||||
"import": "./dist/index.js",
|
||||
"default": "./dist/index.js"
|
||||
}
|
||||
},
|
||||
"files": [
|
||||
"dist"
|
||||
],
|
||||
"scripts": {
|
||||
"build": "tsup",
|
||||
"dev": "tsup --watch",
|
||||
"clean": "del dist",
|
||||
"test": "run-s test:*",
|
||||
"test:format": "prettier --check \"**/*.{js,ts,tsx}\"",
|
||||
"test:lint": "eslint .",
|
||||
"test:typecheck": "tsc --noEmit",
|
||||
"test:unit": "vitest run"
|
||||
},
|
||||
"dependencies": {
|
||||
"@sindresorhus/is": "^7.0.0",
|
||||
"dedent": "^1.5.3",
|
||||
"delay": "^6.0.0",
|
||||
"hash-object": "^5.0.1",
|
||||
"is-relative-url": "^4.0.0",
|
||||
"jsonrepair": "^3.6.1",
|
||||
"ky": "^1.5.0",
|
||||
"normalize-url": "^8.0.1",
|
||||
"p-map": "^7.0.2",
|
||||
"p-throttle": "^6.1.0",
|
||||
"quick-lru": "^7.0.0",
|
||||
"type-fest": "^4.21.0",
|
||||
"zod-to-json-schema": "^3.23.2",
|
||||
"zod-validation-error": "^3.3.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"zod": "^3.23.3"
|
||||
},
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
import is from '@sindresorhus/is'
|
||||
|
||||
function assertImpl(value: unknown, message?: string | Error): asserts value {
|
||||
if (value) {
|
||||
return
|
||||
}
|
||||
|
||||
if (is.error(message)) {
|
||||
throw message
|
||||
}
|
||||
|
||||
throw new Error(message ?? 'Assertion failed')
|
||||
}
|
||||
|
||||
/**
|
||||
* Assertion function that defaults to Node.js's `assert` module if it's
|
||||
* available, with a basic backup if not.
|
||||
*/
|
||||
let assert: (value: unknown, message?: string | Error) => asserts value =
|
||||
assertImpl
|
||||
|
||||
try {
|
||||
// Default to the Node.js assert module if it's available
|
||||
const assertImport = await import('node:assert')
|
||||
if (assertImport?.default) {
|
||||
assert = assertImport.default
|
||||
}
|
||||
} catch {}
|
||||
|
||||
export { assert }
|
|
@ -8,7 +8,7 @@ import { zodToJsonSchema } from './zod-to-json-schema'
|
|||
/**
|
||||
* Used to mark schemas so we can support both Zod and custom schemas.
|
||||
*/
|
||||
export const schemaSymbol = Symbol('agentic..schema')
|
||||
export const schemaSymbol = Symbol('agentic.schema')
|
||||
export const validatorSymbol = Symbol('agentic.validator')
|
||||
|
||||
export type Schema<TData = unknown> = {
|
|
@ -0,0 +1,4 @@
|
|||
{
|
||||
"extends": "../../tsconfig.json",
|
||||
"include": ["src"]
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
export { default } from '../../tsup.config'
|
|
@ -0,0 +1,47 @@
|
|||
{
|
||||
"name": "@agentic/weather",
|
||||
"version": "6.6.1",
|
||||
"description": "Agentic Weather SDK.",
|
||||
"author": "Travis Fischer <travis@transitivebullsh.it>",
|
||||
"license": "MIT",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/transitive-bullshit/agentic.git"
|
||||
},
|
||||
"type": "module",
|
||||
"source": "./src/index.ts",
|
||||
"types": "./dist/index.d.ts",
|
||||
"sideEffects": false,
|
||||
"exports": {
|
||||
".": {
|
||||
"types": "./dist/index.d.ts",
|
||||
"import": "./dist/index.js",
|
||||
"default": "./dist/index.js"
|
||||
}
|
||||
},
|
||||
"files": [
|
||||
"dist"
|
||||
],
|
||||
"scripts": {
|
||||
"build": "tsup",
|
||||
"dev": "tsup --watch",
|
||||
"clean": "del dist",
|
||||
"test": "run-s test:*",
|
||||
"test:format": "prettier --check \"**/*.{js,ts,tsx}\"",
|
||||
"test:lint": "eslint .",
|
||||
"test:typecheck": "tsc --noEmit"
|
||||
},
|
||||
"dependencies": {
|
||||
"ky": "^1.5.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@agentic/core": "workspace:*",
|
||||
"zod": "^3.23.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@agentic/core": "workspace:*"
|
||||
},
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
}
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
export * from './weather-client'
|
|
@ -1,9 +1,13 @@
|
|||
import {
|
||||
aiFunction,
|
||||
AIFunctionsProvider,
|
||||
assert,
|
||||
getEnv,
|
||||
sanitizeSearchParams
|
||||
} from '@agentic/core'
|
||||
import defaultKy, { type KyInstance } from 'ky'
|
||||
import { z } from 'zod'
|
||||
|
||||
import { aiFunction, AIFunctionsProvider } from '../fns'
|
||||
import { assert, getEnv, sanitizeSearchParams } from '../utils'
|
||||
|
||||
export namespace weatherapi {
|
||||
export const BASE_URL = 'https://api.weatherapi.com/v1'
|
||||
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
{
|
||||
"extends": "../../tsconfig.json",
|
||||
"include": ["src"]
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
export { default } from '../../tsup.config'
|
6871
pnpm-lock.yaml
6871
pnpm-lock.yaml
Plik diff jest za duży
Load Diff
|
@ -1,2 +1,7 @@
|
|||
packages:
|
||||
- 'examples'
|
||||
- 'packages/core'
|
||||
- 'packages/weather'
|
||||
- 'packages/ai-sdk'
|
||||
- 'examples/ai-sdk'
|
||||
# - 'examples'
|
||||
# - 'packages/*'
|
||||
|
|
|
@ -1,32 +0,0 @@
|
|||
/**
|
||||
* Slightly modified version of [tiny-invariant](https://github.com/alexreardon/tiny-invariant).
|
||||
*
|
||||
* `assert` is used to [assert](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-7.html#assertion-functions) that the `condition` is [truthy](https://github.com/getify/You-Dont-Know-JS/blob/bdbe570600d4e1107d0b131787903ca1c9ec8140/up%20%26%20going/ch2.md#truthy--falsy).
|
||||
*
|
||||
* 💥 `assert` will `throw` an `Error` if the `condition` is [falsey](https://github.com/getify/You-Dont-Know-JS/blob/bdbe570600d4e1107d0b131787903ca1c9ec8140/up%20%26%20going/ch2.md#truthy--falsy)
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* ```ts
|
||||
* const value: Person | null = { name: 'Alex' };
|
||||
* assert(value, 'Expected value to be a person');
|
||||
* // type of `value`` has been narrowed to `Person`
|
||||
* ```
|
||||
*/
|
||||
export function assert(
|
||||
condition: any,
|
||||
/**
|
||||
* Can provide a string, or a function that returns a string for cases where
|
||||
* the message takes a fair amount of effort to compute.
|
||||
*/
|
||||
message?: string | (() => string)
|
||||
): asserts condition {
|
||||
if (condition) {
|
||||
return
|
||||
}
|
||||
|
||||
const providedMessage: string | undefined =
|
||||
typeof message === 'function' ? message() : message
|
||||
|
||||
throw new Error(providedMessage ?? 'Assertion failed')
|
||||
}
|
|
@ -2,19 +2,7 @@ import { defineConfig } from 'tsup'
|
|||
|
||||
export default defineConfig([
|
||||
{
|
||||
entry: [
|
||||
'src/index.ts',
|
||||
'src/sdks/ai-sdk.ts',
|
||||
'src/sdks/dexter.ts',
|
||||
'src/sdks/genkit.ts',
|
||||
'src/sdks/langchain.ts',
|
||||
'src/sdks/llamaindex.ts',
|
||||
'src/services/twitter/index.ts',
|
||||
'src/services/github-client.ts',
|
||||
'src/services/wikidata-client.ts',
|
||||
'src/tools/calculator.ts',
|
||||
'src/tools/e2b.ts'
|
||||
],
|
||||
entry: ['src/index.ts'],
|
||||
outDir: 'dist',
|
||||
target: 'node18',
|
||||
platform: 'node',
|
||||
|
|
|
@ -0,0 +1,54 @@
|
|||
{
|
||||
"$schema": "https://turbo.build/schema.json",
|
||||
"pipeline": {
|
||||
"build": {
|
||||
"dependsOn": ["^build"],
|
||||
"env": [
|
||||
"ANTHROPIC_API_KEY",
|
||||
"AWS_REGION",
|
||||
"AWS_ACCESS_KEY_ID",
|
||||
"AWS_SECRET_ACCESS_KEY",
|
||||
"COHERE_API_KEY",
|
||||
"FIREWORKS_API_KEY",
|
||||
"GOOGLE_API_KEY",
|
||||
"GROQ_API_KEY",
|
||||
"HUGGINGFACE_API_KEY",
|
||||
"MISTRAL_API_KEY",
|
||||
"OPENAI_API_KEY",
|
||||
"OPENAI_API_BASE",
|
||||
"PERPLEXITY_API_KEY",
|
||||
"REPLICATE_API_KEY",
|
||||
"NODE_ENV",
|
||||
"ASSISTANT_ID",
|
||||
"INKEEP_API_KEY",
|
||||
"INKEEP_INTEGRATION_ID",
|
||||
"VERCEL_URL"
|
||||
],
|
||||
"outputs": ["dist/**"]
|
||||
},
|
||||
"lint": {
|
||||
"dependsOn": ["^lint"]
|
||||
},
|
||||
"type-check": {
|
||||
"dependsOn": ["^build", "build"]
|
||||
},
|
||||
"test": {
|
||||
"dependsOn": ["^build", "build"]
|
||||
},
|
||||
"publint": {
|
||||
"dependsOn": ["^build", "build"]
|
||||
},
|
||||
"clean": {
|
||||
"dependsOn": ["^clean"]
|
||||
},
|
||||
"dev": {
|
||||
"cache": false,
|
||||
"persistent": true
|
||||
},
|
||||
"prettier-check": {},
|
||||
"integration-test": {
|
||||
"dependsOn": ["^build", "build"]
|
||||
}
|
||||
},
|
||||
"globalEnv": ["CI", "PORT"]
|
||||
}
|
Ładowanie…
Reference in New Issue