kopia lustrzana https://github.com/transitive-bullshit/chatgpt-api
feat: WIP add api-client
rodzic
1a372fd9ff
commit
93a46249f0
|
@ -0,0 +1,2 @@
|
||||||
|
# autogenerated file
|
||||||
|
packages/api-client/src/openapi.d.ts
|
|
@ -5,7 +5,6 @@ export default [
|
||||||
...config,
|
...config,
|
||||||
{
|
{
|
||||||
files: ['**/*.ts', '**/*.tsx'],
|
files: ['**/*.ts', '**/*.tsx'],
|
||||||
ignores: ['**/out/**'],
|
|
||||||
plugins: {
|
plugins: {
|
||||||
drizzle
|
drizzle
|
||||||
},
|
},
|
||||||
|
@ -15,5 +14,8 @@ export default [
|
||||||
'unicorn/no-array-reduce': 'off'
|
'unicorn/no-array-reduce': 'off'
|
||||||
// 'no-restricted-imports': ['error', '@agentic/platform-db']
|
// 'no-restricted-imports': ['error', '@agentic/platform-db']
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
ignores: ['**/out/**']
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
|
@ -4,10 +4,12 @@ export default [
|
||||||
...config,
|
...config,
|
||||||
{
|
{
|
||||||
files: ['**/*.ts', '**/*.tsx'],
|
files: ['**/*.ts', '**/*.tsx'],
|
||||||
ignores: ['**/out/**'],
|
|
||||||
rules: {
|
rules: {
|
||||||
'no-console': 'error',
|
'no-console': 'error',
|
||||||
'unicorn/no-array-reduce': 'off'
|
'unicorn/no-array-reduce': 'off'
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
ignores: ['**/out/**', 'packages/api-client/src/openapi.d.ts']
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
|
@ -0,0 +1,37 @@
|
||||||
|
{
|
||||||
|
"name": "@agentic/platform-api-client",
|
||||||
|
"version": "0.0.1",
|
||||||
|
"description": "Core utilities for the Agentic platform.",
|
||||||
|
"author": "Travis Fischer <travis@transitivebullsh.it>",
|
||||||
|
"license": "UNLICENSED",
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "git+https://github.com/transitive-bullshit/agentic-platform.git",
|
||||||
|
"directory": "packages/api-client"
|
||||||
|
},
|
||||||
|
"type": "module",
|
||||||
|
"source": "./src/index.ts",
|
||||||
|
"types": "./src/index.ts",
|
||||||
|
"sideEffects": false,
|
||||||
|
"exports": {
|
||||||
|
".": "./src/index.ts"
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"generate": "openapi-typescript http://localhost:3000/docs --output ./src/openapi.d.ts",
|
||||||
|
"test": "run-s test:*",
|
||||||
|
"test:lint": "eslint .",
|
||||||
|
"test:typecheck": "tsc --noEmit",
|
||||||
|
"test:unit": "vitest run"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"@agentic/platform-core": "workspace:*",
|
||||||
|
"ky": "catalog:",
|
||||||
|
"type-fest": "catalog:"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"openapi-typescript": "^7.8.0"
|
||||||
|
},
|
||||||
|
"publishConfig": {
|
||||||
|
"access": "public"
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,64 @@
|
||||||
|
import type { Simplify } from 'type-fest'
|
||||||
|
import defaultKy, { type KyInstance } from 'ky'
|
||||||
|
|
||||||
|
import type { operations } from './openapi'
|
||||||
|
import { getEnv } from './utils'
|
||||||
|
|
||||||
|
export class AgenticApiClient {
|
||||||
|
ky: KyInstance
|
||||||
|
|
||||||
|
constructor({
|
||||||
|
apiKey = getEnv('AGENTIC_API_KEY'),
|
||||||
|
ky = defaultKy
|
||||||
|
}: {
|
||||||
|
apiKey?: string
|
||||||
|
ky?: KyInstance
|
||||||
|
}) {
|
||||||
|
this.ky = ky.extend({ headers: { Authorization: `Bearer ${apiKey}` } })
|
||||||
|
}
|
||||||
|
|
||||||
|
async getUser({
|
||||||
|
userId,
|
||||||
|
...searchParams
|
||||||
|
}: OperationParameters<'getUser'>): Promise<OperationResponse<'getUser'>> {
|
||||||
|
return this.ky.get(`/v1/users/${userId}`, { searchParams }).json()
|
||||||
|
}
|
||||||
|
|
||||||
|
async updateUser(
|
||||||
|
user: OperationBody<'updateUser'>,
|
||||||
|
{ userId, ...searchParams }: OperationParameters<'updateUser'>
|
||||||
|
): Promise<OperationResponse<'updateUser'>> {
|
||||||
|
return this.ky
|
||||||
|
.post(`/v1/users/${userId}`, { json: user, searchParams })
|
||||||
|
.json()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
type OperationParameters<
|
||||||
|
T extends keyof operations,
|
||||||
|
Q extends object | undefined = operations[T]['parameters']['query'],
|
||||||
|
P extends object | undefined = operations[T]['parameters']['path']
|
||||||
|
> = Simplify<
|
||||||
|
(Q extends never | undefined ? unknown : Q) &
|
||||||
|
(P extends never | undefined ? unknown : P)
|
||||||
|
>
|
||||||
|
|
||||||
|
type OperationResponse<T extends keyof operations> =
|
||||||
|
operations[T]['responses'][200]['content']['application/json']
|
||||||
|
|
||||||
|
type OperationKeysWithRequestBody = {
|
||||||
|
[K in keyof operations]: operations[K]['requestBody'] extends {
|
||||||
|
content: {
|
||||||
|
'application/json': unknown
|
||||||
|
}
|
||||||
|
}
|
||||||
|
? K
|
||||||
|
: never
|
||||||
|
}[keyof operations]
|
||||||
|
|
||||||
|
type OperationBody<
|
||||||
|
T extends OperationKeysWithRequestBody,
|
||||||
|
B extends
|
||||||
|
| object
|
||||||
|
| undefined = operations[T]['requestBody']['content']['application/json']
|
||||||
|
> = B
|
|
@ -0,0 +1,3 @@
|
||||||
|
export * from './agentic-api-client'
|
||||||
|
export type * from './openapi'
|
||||||
|
export type * from './types'
|
Plik diff jest za duży
Load Diff
|
@ -0,0 +1,7 @@
|
||||||
|
import type { components } from './openapi'
|
||||||
|
|
||||||
|
export type AuthProvider = components['schemas']['AuthProvider']
|
||||||
|
export type AuthProviders = components['schemas']['AuthProviders']
|
||||||
|
export type User = components['schemas']['User']
|
||||||
|
export type Team = components['schemas']['Team']
|
||||||
|
export type TeamMember = components['schemas']['TeamMember']
|
|
@ -0,0 +1,10 @@
|
||||||
|
export function getEnv(name: string): string | undefined {
|
||||||
|
try {
|
||||||
|
return typeof process !== 'undefined'
|
||||||
|
? // eslint-disable-next-line no-process-env
|
||||||
|
process.env?.[name]
|
||||||
|
: undefined
|
||||||
|
} catch {
|
||||||
|
return undefined
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,5 @@
|
||||||
|
{
|
||||||
|
"extends": "@fisch0920/config/tsconfig-node",
|
||||||
|
"include": ["src", "*.config.ts"],
|
||||||
|
"exclude": ["node_modules"]
|
||||||
|
}
|
|
@ -1,5 +1,5 @@
|
||||||
{
|
{
|
||||||
"name": "@agentic/cli",
|
"name": "@agentic/platform-cli",
|
||||||
"version": "0.0.1",
|
"version": "0.0.1",
|
||||||
"description": "CLI for Agentic.",
|
"description": "CLI for Agentic.",
|
||||||
"author": "Travis Fischer <travis@transitivebullsh.it>",
|
"author": "Travis Fischer <travis@transitivebullsh.it>",
|
||||||
|
@ -12,13 +12,15 @@
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"source": "./src/index.ts",
|
"source": "./src/index.ts",
|
||||||
"types": "./src/index.ts",
|
"types": "./src/index.ts",
|
||||||
"sideEffects": false,
|
|
||||||
"exports": {
|
"exports": {
|
||||||
".": "./src/index.ts"
|
".": "./src/index.ts"
|
||||||
},
|
},
|
||||||
"bin": {
|
"bin": {
|
||||||
"agentic": "./bin/run.js"
|
"agentic": "./dist/index.js"
|
||||||
},
|
},
|
||||||
|
"files": [
|
||||||
|
"dist"
|
||||||
|
],
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "run-s test:*",
|
"test": "run-s test:*",
|
||||||
"test:lint": "eslint .",
|
"test:lint": "eslint .",
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "git+https://github.com/transitive-bullshit/agentic-platform.git",
|
"url": "git+https://github.com/transitive-bullshit/agentic-platform.git",
|
||||||
"directory": "packages/cli"
|
"directory": "packages/core"
|
||||||
},
|
},
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"source": "./src/index.ts",
|
"source": "./src/index.ts",
|
||||||
|
|
|
@ -24,6 +24,9 @@ catalogs:
|
||||||
exit-hook:
|
exit-hook:
|
||||||
specifier: ^4.0.0
|
specifier: ^4.0.0
|
||||||
version: 4.0.0
|
version: 4.0.0
|
||||||
|
ky:
|
||||||
|
specifier: ^1.8.1
|
||||||
|
version: 1.8.1
|
||||||
lint-staged:
|
lint-staged:
|
||||||
specifier: ^16.0.0
|
specifier: ^16.0.0
|
||||||
version: 16.0.0
|
version: 16.0.0
|
||||||
|
@ -199,6 +202,22 @@ importers:
|
||||||
specifier: ^7.8.0
|
specifier: ^7.8.0
|
||||||
version: 7.8.0(typescript@5.8.3)
|
version: 7.8.0(typescript@5.8.3)
|
||||||
|
|
||||||
|
packages/api-client:
|
||||||
|
dependencies:
|
||||||
|
'@agentic/platform-core':
|
||||||
|
specifier: workspace:*
|
||||||
|
version: link:../core
|
||||||
|
ky:
|
||||||
|
specifier: 'catalog:'
|
||||||
|
version: 1.8.1
|
||||||
|
type-fest:
|
||||||
|
specifier: 'catalog:'
|
||||||
|
version: 4.41.0
|
||||||
|
devDependencies:
|
||||||
|
openapi-typescript:
|
||||||
|
specifier: ^7.8.0
|
||||||
|
version: 7.8.0(typescript@5.8.3)
|
||||||
|
|
||||||
packages/cli:
|
packages/cli:
|
||||||
dependencies:
|
dependencies:
|
||||||
'@agentic/platform-core':
|
'@agentic/platform-core':
|
||||||
|
@ -220,9 +239,6 @@ importers:
|
||||||
specifier: 'catalog:'
|
specifier: 'catalog:'
|
||||||
version: 3.24.4
|
version: 3.24.4
|
||||||
devDependencies:
|
devDependencies:
|
||||||
'@agentic/platform-api':
|
|
||||||
specifier: workspace:*
|
|
||||||
version: link:../../apps/api
|
|
||||||
'@agentic/platform-db':
|
'@agentic/platform-db':
|
||||||
specifier: workspace:*
|
specifier: workspace:*
|
||||||
version: link:../db
|
version: link:../db
|
||||||
|
@ -2567,6 +2583,10 @@ packages:
|
||||||
keyv@4.5.4:
|
keyv@4.5.4:
|
||||||
resolution: {integrity: sha512-oxVHkHR/EJf2CNXnWxRLW6mg7JyCCUcG0DtEGmL2ctUo1PNTin1PUil+r/+4r5MpVgC/fn1kjsx7mjSujKqIpw==}
|
resolution: {integrity: sha512-oxVHkHR/EJf2CNXnWxRLW6mg7JyCCUcG0DtEGmL2ctUo1PNTin1PUil+r/+4r5MpVgC/fn1kjsx7mjSujKqIpw==}
|
||||||
|
|
||||||
|
ky@1.8.1:
|
||||||
|
resolution: {integrity: sha512-7Bp3TpsE+L+TARSnnDpk3xg8Idi8RwSLdj6CMbNWoOARIrGrbuLGusV0dYwbZOm4bB3jHNxSw8Wk/ByDqJEnDw==}
|
||||||
|
engines: {node: '>=18'}
|
||||||
|
|
||||||
language-subtag-registry@0.3.23:
|
language-subtag-registry@0.3.23:
|
||||||
resolution: {integrity: sha512-0K65Lea881pHotoGEa5gDlMxt3pctLi2RplBb7Ezh4rRdLEOtgi7n4EwK9lamnUCkKBqaeKRVebTq6BAxSkpXQ==}
|
resolution: {integrity: sha512-0K65Lea881pHotoGEa5gDlMxt3pctLi2RplBb7Ezh4rRdLEOtgi7n4EwK9lamnUCkKBqaeKRVebTq6BAxSkpXQ==}
|
||||||
|
|
||||||
|
@ -6020,6 +6040,8 @@ snapshots:
|
||||||
dependencies:
|
dependencies:
|
||||||
json-buffer: 3.0.1
|
json-buffer: 3.0.1
|
||||||
|
|
||||||
|
ky@1.8.1: {}
|
||||||
|
|
||||||
language-subtag-registry@0.3.23: {}
|
language-subtag-registry@0.3.23: {}
|
||||||
|
|
||||||
language-tags@1.0.9:
|
language-tags@1.0.9:
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
- auth
|
- auth
|
||||||
- decide on approach for auth
|
- decide on approach for auth
|
||||||
- built-in, first-party, tight coupling
|
- built-in, first-party, tight coupling
|
||||||
|
- https://www.better-auth.com
|
||||||
- https://github.com/toolbeam/openauth
|
- https://github.com/toolbeam/openauth
|
||||||
- https://github.com/aipotheosis-labs/aci/tree/main/backend/apps
|
- https://github.com/aipotheosis-labs/aci/tree/main/backend/apps
|
||||||
- https://github.com/NangoHQ/nango
|
- https://github.com/NangoHQ/nango
|
||||||
|
|
Ładowanie…
Reference in New Issue