ai-workflows 0.0.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 ADDED
@@ -0,0 +1,14 @@
1
+ # ai-workflows
2
+
3
+ ```javascript
4
+ import { ai, Workflow } from 'ai-workflows'
5
+
6
+ const workflow = Workflow()
7
+
8
+ workflow.on('ticket.created', ticket => {
9
+ const summary = ai.summarize(ticket)
10
+ workflow.send('ticket.summarized', summary)
11
+ })
12
+
13
+ export default workflow
14
+ ```
package/bun.lockb ADDED
Binary file
package/index.ts ADDED
@@ -0,0 +1,59 @@
1
+ import { AI } from 'ai-functions'
2
+ import { AutoRouter } from 'itty-router'
3
+
4
+ export const ai: Record<string, any> = {}
5
+
6
+ export type WorkflowOptions = {
7
+ queue: string
8
+ }
9
+
10
+ // TODO: Add generic type for the event data
11
+ export const Workflow = (options: WorkflowOptions) => {
12
+
13
+
14
+ const { queue = 'workflows' } = options
15
+
16
+ const api = AutoRouter()
17
+
18
+ const events: Record<string, any> = {}
19
+
20
+ const send = (env: any) => async (event: WorkflowEvent) => {
21
+ if (env[queue] && env[queue].send) {
22
+ return await (env[queue] as Queue<WorkflowEvent>).send(event)
23
+ }
24
+ throw new Error('Queue not found')
25
+ }
26
+
27
+ return {
28
+ on: (event: string, handler: WorkflowEventHandler) => {
29
+ events[event] = handler
30
+ api.get('/' + event, async (req, env, ctx) => {
31
+ const data = Object.fromEntries(new URL(req.url).searchParams)
32
+ return send(env)({ event, data })
33
+ })
34
+ api.post('/' + event, async (req, env, ctx) => {
35
+ const data = await req.json()
36
+ return send(env)({ event, data })
37
+ })
38
+ },
39
+ fetch: api.fetch,
40
+ queue: (batch: MessageBatch<WorkflowEvent>, env: any, ctx: ExecutionContext) => {
41
+ batch.messages.map(async (message) => {
42
+
43
+ })
44
+ },
45
+ }
46
+ }
47
+
48
+ export type WorkflowEvent<T = any> = {
49
+ event: string
50
+ data: T
51
+ }
52
+
53
+ export type WorkflowContext = {
54
+ ai: Record<string, any>
55
+ db: Record<string, any>
56
+ api: Record<string, any>
57
+ }
58
+
59
+ export type WorkflowEventHandler = (event: WorkflowEvent, context: WorkflowContext) => Promise<any>
package/package.json ADDED
@@ -0,0 +1,42 @@
1
+ {
2
+ "name": "ai-workflows",
3
+ "version": "0.0.1",
4
+ "description": "Framework for Developing AI-Native Workflows",
5
+ "module": "dist/index.js",
6
+ "scripts": {
7
+ "build": "tsc",
8
+ "format": "prettier --write .",
9
+ "test": "dotenv -- vitest --globals"
10
+ },
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "git+https://github.com/nathanclevenger/ai-workflows.git"
14
+ },
15
+ "keywords": [],
16
+ "author": "Nathan Clevenger",
17
+ "license": "MIT",
18
+ "bugs": {
19
+ "url": "https://github.com/nathanclevenger/ai-workflows/issues"
20
+ },
21
+ "homepage": "https://github.com/nathanclevenger/ai-workflows#readme",
22
+ "devDependencies": {
23
+ "@cloudflare/workers-types": "^4.20241018.0",
24
+ "typescript": "^5.6.3",
25
+ "vitest": "^2.1.3"
26
+ },
27
+ "dependencies": {
28
+ "ai": "^3.4.18",
29
+ "ai-functions": "^0.2.19",
30
+ "autoevals": "^0.0.99",
31
+ "braintrust": "^0.0.166",
32
+ "itty-router": "^5.0.18",
33
+ "openai": "^4.68.1"
34
+ },
35
+ "prettier": {
36
+ "semi": false,
37
+ "singleQuote": true,
38
+ "trailingComma": "es5",
39
+ "tabWidth": 2,
40
+ "printWidth": 120
41
+ }
42
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,48 @@
1
+ {
2
+ "compilerOptions": {
3
+ /* Visit https://aka.ms/tsconfig.json to read more about this file */
4
+
5
+ /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
6
+ "target": "es2021",
7
+ /* Specify a set of bundled library declaration files that describe the target runtime environment. */
8
+ "lib": ["es2021"],
9
+ /* Specify what JSX code is generated. */
10
+ "jsx": "react-jsx",
11
+ "jsxImportSource": "hono/jsx",
12
+
13
+ /* Specify what module code is generated. */
14
+ "module": "es2022",
15
+ /* Specify how TypeScript looks up a file from a given module specifier. */
16
+ "moduleResolution": "Bundler",
17
+ /* Specify type package names to be included without being referenced in a source file. */
18
+ "types": ["@cloudflare/workers-types/2023-07-01"],
19
+ /* Enable importing .json files */
20
+ "resolveJsonModule": true,
21
+
22
+ /* Allow JavaScript files to be a part of your program. Use the `checkJS` option to get errors from these files. */
23
+ "allowJs": true,
24
+ /* Enable error reporting in type-checked JavaScript files. */
25
+ "checkJs": false,
26
+
27
+ /* Disable emitting files from a compilation. */
28
+ "noEmit": false,
29
+
30
+ /* Emit the compiled files to the ./dist folder */
31
+ "outDir": "./dist",
32
+
33
+ /* Ensure that each file can be safely transpiled without relying on other imports. */
34
+ "isolatedModules": true,
35
+ /* Allow 'import x from y' when a module doesn't have a default export. */
36
+ "allowSyntheticDefaultImports": true,
37
+ /* Ensure that casing is correct in imports. */
38
+ "forceConsistentCasingInFileNames": true,
39
+
40
+ /* Enable all strict type-checking options. */
41
+ "strict": true,
42
+
43
+ /* Skip type checking all .d.ts files. */
44
+ "skipLibCheck": true
45
+ },
46
+ "exclude": ["test"],
47
+ "include": ["types.d.ts", "**/*.ts", "**/*.tsx"]
48
+ }