feat: WIP add api-client

pull/715/head
Travis Fischer 2025-05-20 23:28:31 +07:00
rodzic 1a372fd9ff
commit 93a46249f0
14 zmienionych plików z 1554 dodań i 9 usunięć

2
.prettierignore 100644
Wyświetl plik

@ -0,0 +1,2 @@
# autogenerated file
packages/api-client/src/openapi.d.ts

Wyświetl plik

@ -5,7 +5,6 @@ export default [
...config,
{
files: ['**/*.ts', '**/*.tsx'],
ignores: ['**/out/**'],
plugins: {
drizzle
},
@ -15,5 +14,8 @@ export default [
'unicorn/no-array-reduce': 'off'
// 'no-restricted-imports': ['error', '@agentic/platform-db']
}
},
{
ignores: ['**/out/**']
}
]

Wyświetl plik

@ -4,10 +4,12 @@ export default [
...config,
{
files: ['**/*.ts', '**/*.tsx'],
ignores: ['**/out/**'],
rules: {
'no-console': 'error',
'unicorn/no-array-reduce': 'off'
}
},
{
ignores: ['**/out/**', 'packages/api-client/src/openapi.d.ts']
}
]

Wyświetl plik

@ -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"
}
}

Wyświetl plik

@ -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

Wyświetl plik

@ -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

Wyświetl plik

@ -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']

Wyświetl plik

@ -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
}
}

Wyświetl plik

@ -0,0 +1,5 @@
{
"extends": "@fisch0920/config/tsconfig-node",
"include": ["src", "*.config.ts"],
"exclude": ["node_modules"]
}

Wyświetl plik

@ -1,5 +1,5 @@
{
"name": "@agentic/cli",
"name": "@agentic/platform-cli",
"version": "0.0.1",
"description": "CLI for Agentic.",
"author": "Travis Fischer <travis@transitivebullsh.it>",
@ -12,13 +12,15 @@
"type": "module",
"source": "./src/index.ts",
"types": "./src/index.ts",
"sideEffects": false,
"exports": {
".": "./src/index.ts"
},
"bin": {
"agentic": "./bin/run.js"
"agentic": "./dist/index.js"
},
"files": [
"dist"
],
"scripts": {
"test": "run-s test:*",
"test:lint": "eslint .",

Wyświetl plik

@ -7,7 +7,7 @@
"repository": {
"type": "git",
"url": "git+https://github.com/transitive-bullshit/agentic-platform.git",
"directory": "packages/cli"
"directory": "packages/core"
},
"type": "module",
"source": "./src/index.ts",

Wyświetl plik

@ -24,6 +24,9 @@ catalogs:
exit-hook:
specifier: ^4.0.0
version: 4.0.0
ky:
specifier: ^1.8.1
version: 1.8.1
lint-staged:
specifier: ^16.0.0
version: 16.0.0
@ -199,6 +202,22 @@ importers:
specifier: ^7.8.0
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:
dependencies:
'@agentic/platform-core':
@ -220,9 +239,6 @@ importers:
specifier: 'catalog:'
version: 3.24.4
devDependencies:
'@agentic/platform-api':
specifier: workspace:*
version: link:../../apps/api
'@agentic/platform-db':
specifier: workspace:*
version: link:../db
@ -2567,6 +2583,10 @@ packages:
keyv@4.5.4:
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:
resolution: {integrity: sha512-0K65Lea881pHotoGEa5gDlMxt3pctLi2RplBb7Ezh4rRdLEOtgi7n4EwK9lamnUCkKBqaeKRVebTq6BAxSkpXQ==}
@ -6020,6 +6040,8 @@ snapshots:
dependencies:
json-buffer: 3.0.1
ky@1.8.1: {}
language-subtag-registry@0.3.23: {}
language-tags@1.0.9:

Wyświetl plik

@ -23,6 +23,7 @@
- auth
- decide on approach for auth
- built-in, first-party, tight coupling
- https://www.better-auth.com
- https://github.com/toolbeam/openauth
- https://github.com/aipotheosis-labs/aci/tree/main/backend/apps
- https://github.com/NangoHQ/nango