Skip to content

Commit

Permalink
refactor: prepare packages for publishing (#45)
Browse files Browse the repository at this point in the history
Fixes #29

Introducing Rslib 
Commenting out documentation entry points temporarily (I need to
experiment with this in a follow-up)
Moved vision tools to file, from folder, to simplify structure 
Added missing fields to package.json and fixed typos in some other
places
Tested and tried this setup in Cali, a different project of mine
  • Loading branch information
grabbou committed Dec 9, 2024
1 parent 32b5806 commit 3fea875
Show file tree
Hide file tree
Showing 22 changed files with 174 additions and 53 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -175,4 +175,4 @@ dist
.DS_Store

last-run-id.txt
context-*.json
context-*.json
2 changes: 1 addition & 1 deletion example/src/ecommerce_product_description.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import { agent } from '@dead-simple-ai-agent/framework/agent'
import { teamwork } from '@dead-simple-ai-agent/framework/teamwork'
import { workflow } from '@dead-simple-ai-agent/framework/workflow'
import { visionTool } from '@dead-simple-ai-agent/tools'
import { visionTool } from '@dead-simple-ai-agent/tools/vision'

const techExpert = agent({
role: 'Technical expert',
Expand Down
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,5 @@
"trustedDependencies": [
"core-js"
],
"dependencies": {
"nanoid": "^5.0.9"
}
"version": "0.0.1"
}
3 changes: 3 additions & 0 deletions packages/framework/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@dead-simple-ai-agent/framework
====

39 changes: 33 additions & 6 deletions packages/framework/package.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,47 @@
{
"name": "@dead-simple-ai-agent/framework",
"version": "0.0.1",
"description": "A dead simple AI agent framework",
"author": "Mike Grabowski <[email protected]>",
"contributors": [
"Piotr Karwatka <[email protected]>"
],
"scripts": {
"clean": "rm -rf dist",
"build": "bun run clean && bun run build:lib && bun run build:types",
"build:lib": "rslib build",
"build:types": "tsc --emitDeclarationOnly --declaration --outdir dist/types"
},
"exports": {
"./*": {
"bun": "./src/*.ts"
},
"./models/*": {
"bun": "./src/models/*.ts"
"bun": "./src/*.ts",
"types": "./dist/types/*.d.ts",
"require": "./dist/*.cjs",
"import": "./dist/*.js"
}
},
"type": "module",
"dependencies": {
"dedent": "^1.5.3",
"openai": "^4.76.0",
"zod": "^3.23.8"
}
},
"license": "MIT",
"repository": {
"type": "git",
"url": "git+https://github.com/callstackincubator/ai-agent-framework.git"
},
"keywords": [
"ai",
"ai agents",
"ai tools"
],
"files": [
"dist",
"src",
"README.md"
],
"engines": {
"node": ">=22"
},
"version": "0.0.1"
}
39 changes: 39 additions & 0 deletions packages/framework/rslib.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { defineConfig } from '@rslib/core'

const entry = {
agent: './src/agent.ts',
models: './src/models.ts',
teamwork: './src/teamwork.ts',
telemetry: './src/telemetry.ts',
tool: './src/tool.ts',
workflow: './src/workflow.ts',
}

export default defineConfig({
lib: [
{
source: {
entry,
},
format: 'esm',
bundle: false,
output: {
distPath: {
root: 'dist',
},
},
},
{
source: {
entry,
},
format: 'cjs',
bundle: false,
output: {
distPath: {
root: 'dist',
},
},
},
],
})
2 changes: 1 addition & 1 deletion packages/framework/src/agent.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { openai, Provider } from './models/openai.js'
import { openai, Provider } from './models.js'
import { Tool } from './tool.js'
import { RequiredOptionals } from './types.js'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import OpenAI, { ClientOptions } from 'openai'
import { ChatCompletionCreateParamsNonStreaming } from 'openai/resources/index.mjs'

import { RequiredOptionals } from '../types.js'
import { RequiredOptionals } from './types.js'

type OpenAIOptions = {
model?: string
Expand Down
2 changes: 1 addition & 1 deletion packages/framework/src/supervisor/finalizeWorkflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import s from 'dedent'
import { zodResponseFormat } from 'openai/helpers/zod.mjs'
import { z } from 'zod'

import { Provider } from '../models/openai.js'
import { Provider } from '../models.js'
import { Message } from '../types.js'

export async function finalizeWorkflow(provider: Provider, messages: Message[]): Promise<string> {
Expand Down
2 changes: 1 addition & 1 deletion packages/framework/src/supervisor/nextTask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import s from 'dedent'
import { zodResponseFormat } from 'openai/helpers/zod.mjs'
import { z } from 'zod'

import { Provider } from '../models/openai.js'
import { Provider } from '../models.js'
import { Message } from '../types.js'

export async function nextTask(provider: Provider, history: Message[]): Promise<string | null> {
Expand Down
2 changes: 1 addition & 1 deletion packages/framework/src/supervisor/selectAgent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { zodResponseFormat } from 'openai/helpers/zod.mjs'
import { z } from 'zod'

import { Agent } from '../agent.js'
import { Provider } from '../models/openai.js'
import { Provider } from '../models.js'
import { Message } from '../types.js'

export async function selectAgent(
Expand Down
2 changes: 1 addition & 1 deletion packages/framework/src/tool.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import z, { ZodTypeAny } from 'zod'

import { Provider } from './models/openai.js'
import { Provider } from './models.js'
import { Message } from './types.js'

export type Tool<P extends ZodTypeAny = any> = {
Expand Down
2 changes: 1 addition & 1 deletion packages/framework/src/workflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { randomUUID } from 'node:crypto'
import s from 'dedent'

import { Agent } from './agent.js'
import { openai, Provider } from './models/openai.js'
import { openai, Provider } from './models.js'
import { noop, Telemetry } from './telemetry.js'
import { Message } from './types.js'

Expand Down
3 changes: 2 additions & 1 deletion packages/framework/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"extends": "../../tsconfig.json"
"extends": "../../tsconfig.json",
"include": ["./src"]
}
3 changes: 3 additions & 0 deletions packages/tools/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@dead-simple-ai-agent/tools
====

41 changes: 32 additions & 9 deletions packages/tools/package.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,43 @@
{
"name": "@dead-simple-ai-agent/tools",
"version": "0.0.1",
"description": "A dead simple AI agent tools",
"author": "Piotr Karwatka <[email protected]>",
"scripts": {
"clean": "rm -rf dist",
"build": "bun run clean && bun run build:lib && bun run build:types",
"build:lib": "rslib build",
"build:types": "tsc --emitDeclarationOnly --declaration --outdir dist/types"
},
"exports": {
".": {
"bun": "./src/index.ts"
},
"./tools": {
"bun": "./src/index.ts"
"./*": {
"bun": "./src/*.ts",
"types": "./dist/types/*.d.ts",
"require": "./dist/*.cjs",
"import": "./dist/*.js"
}
},
"type": "module",
"dependencies": {
"dedent": "^1.5.3",
"openai": "^4.76.0",
"@dead-simple-ai-agent/framework": "0.0.1",
"zod": "^3.23.8"
}
},
"license": "MIT",
"repository": {
"type": "git",
"url": "git+https://github.com/callstackincubator/ai-agent-framework.git"
},
"keywords": [
"ai",
"ai agents",
"ai tools"
],
"files": [
"dist",
"src",
"README.md"
],
"engines": {
"node": ">=22"
},
"version": "0.0.1"
}
34 changes: 34 additions & 0 deletions packages/tools/rslib.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { defineConfig } from '@rslib/core'

const entry = {
vision: './src/vision.ts',
}

export default defineConfig({
lib: [
{
source: {
entry,
},
format: 'esm',
bundle: false,
output: {
distPath: {
root: 'dist',
},
},
},
{
source: {
entry,
},
format: 'cjs',
bundle: false,
output: {
distPath: {
root: 'dist',
},
},
},
],
})
1 change: 0 additions & 1 deletion packages/tools/src/index.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
/**
* Example borrowed from CrewAI.
*/
import { Provider } from '@dead-simple-ai-agent/framework/models/openai'
import { Provider } from '@dead-simple-ai-agent/framework/models'
import { tool } from '@dead-simple-ai-agent/framework/tool'
import * as fs from 'fs'
import { z } from 'zod'
Expand Down Expand Up @@ -48,15 +45,11 @@ const runWebHostedImages = async (provider: Provider, imagePathUrl: string): Pro
}

export const visionTool = tool({
description: 'Tool for analyzing and OCR the pitures',
description: 'Tool for analyzing and OCR the pictures',
parameters: z.object({
imagePathUrl: z.string().describe('The image path or URL'),
}),
execute: ({ imagePathUrl }, { provider }) => {
if (!imagePathUrl) {
throw new Error('Image Path or URL is required.')
}

if (imagePathUrl.startsWith('http')) {
return runWebHostedImages(provider, imagePathUrl)
} else {
Expand Down
3 changes: 2 additions & 1 deletion packages/tools/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"extends": "../../tsconfig.json"
"extends": "../../tsconfig.json",
"include": ["./src"]
}
2 changes: 1 addition & 1 deletion website/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@dead-simple-ai-agent/website",
"version": "1.0.0",
"private": true,
"type": "module",
"scripts": {
"dev": "rspress dev",
"build": "rspress build",
Expand Down
26 changes: 13 additions & 13 deletions website/rspress.config.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import * as path from 'node:path'

import { pluginTypeDoc } from '@rspress/plugin-typedoc'
import { defineConfig } from 'rspress/config'
// import { pluginTypeDoc } from '@rspress/plugin-typedoc'

export default defineConfig({
root: path.join(__dirname, 'docs'),
title: 'My Site',
title: 'Dead Simple AI Agent',
icon: '/rspress-icon.png',
logo: {
light: '/rspress-light-logo.png',
Expand All @@ -16,20 +16,20 @@ export default defineConfig({
{
icon: 'github',
mode: 'link',
content: 'https://github.com/web-infra-dev/rspress',
content: 'https://github.com/callstackincubator/ai-agent-framework',
},
],
},
plugins: [
pluginTypeDoc({
entryPoints: [
path.join(__dirname, '../packages/framework/src/agent.ts'),
path.join(__dirname, '../packages/framework/src/teamwork.ts'),
path.join(__dirname, '../packages/framework/src/tool.ts'),
path.join(__dirname, '../packages/framework/src/workflow.ts'),
path.join(__dirname, '../packages/framework/src/models/openai.ts'),
path.join(__dirname, '../packages/framework/src/telemetry.ts'),
],
}),
// pluginTypeDoc({
// entryPoints: [
// path.join(__dirname, '../packages/framework/src/agent.ts'),
// path.join(__dirname, '../packages/framework/src/teamwork.ts'),
// path.join(__dirname, '../packages/framework/src/tool.ts'),
// path.join(__dirname, '../packages/framework/src/workflow.ts'),
// path.join(__dirname, '../packages/framework/src/models/openai.ts'),
// path.join(__dirname, '../packages/framework/src/telemetry.ts'),
// ],
// }),
],
})

0 comments on commit 3fea875

Please sign in to comment.