@fadeaway-ai/sdk
Advanced tools
Comparing version 0.1.2 to 0.1.3
@@ -6,11 +6,17 @@ import { ZodType } from 'zod'; | ||
description: string; | ||
schema: ZodType<Input>; | ||
run: (data: Input) => any; | ||
schema?: ZodType<Input>; | ||
run: (data: Input) => IFunctionResponse<Output> | Promise<IFunctionResponse<Output>>; | ||
} | ||
declare function makeFunction<Input, Output>(arg: { | ||
name: string; | ||
description: string; | ||
schema?: ZodType<Input>; | ||
run: (data: Input) => Output; | ||
}): LLMFunction<Input, Output>; | ||
declare function llmFunction<Input, Output>(arg: LLMFunction<Input, Output>): LLMFunction<Input, Output>; | ||
interface Agent { | ||
prompt: string; | ||
functions: LLMFunction<any, any>[]; | ||
} | ||
interface IFunctionResponse<T = any> { | ||
result: T; | ||
continue?: boolean; | ||
} | ||
declare function FunctionResponse<T>(result: T, options?: { | ||
continue?: boolean; | ||
}): IFunctionResponse<T>; | ||
@@ -20,3 +26,3 @@ type RouteSegmentFunction = (paramsSoFar: { | ||
}) => Promise<any>; | ||
declare class AgentRouter { | ||
declare class FadeawayRouter { | ||
private routes; | ||
@@ -27,3 +33,3 @@ constructor(); | ||
}): void; | ||
matchAndRun(path: string): Promise<any[]>; | ||
matchAndRun(path: string): Promise<Agent[]>; | ||
} | ||
@@ -37,2 +43,2 @@ | ||
export { AgentRouter, LLMFunction, View, makeFunction }; | ||
export { Agent, FadeawayRouter, FunctionResponse, IFunctionResponse, LLMFunction, View, llmFunction }; |
@@ -23,5 +23,6 @@ "use strict"; | ||
__export(src_exports, { | ||
AgentRouter: () => AgentRouter, | ||
FadeawayRouter: () => FadeawayRouter, | ||
FunctionResponse: () => FunctionResponse, | ||
View: () => View, | ||
makeFunction: () => makeFunction | ||
llmFunction: () => llmFunction | ||
}); | ||
@@ -32,7 +33,6 @@ module.exports = __toCommonJS(src_exports); | ||
var import_zod = require("zod"); | ||
function makeFunction(arg) { | ||
function llmFunction(arg) { | ||
return { | ||
name: arg.name, | ||
description: arg.description, | ||
// deno-lint-ignore no-explicit-any | ||
schema: arg.schema || import_zod.z.object({}), | ||
@@ -42,6 +42,12 @@ run: arg.run | ||
} | ||
function FunctionResponse(result, options) { | ||
return { | ||
result, | ||
...options != null ? options : {} | ||
}; | ||
} | ||
// src/Router.ts | ||
var import_path_to_regexp = require("path-to-regexp"); | ||
var AgentRouter = class { | ||
var FadeawayRouter = class { | ||
constructor() { | ||
@@ -60,2 +66,5 @@ this.routes = []; | ||
const allSegments = route.path.split("/").filter(Boolean); | ||
allSegments.push(""); | ||
console.log("match", match); | ||
console.log("allSegments", allSegments); | ||
const paramsSoFar = {}; | ||
@@ -96,6 +105,7 @@ const segmentValues = []; | ||
0 && (module.exports = { | ||
AgentRouter, | ||
FadeawayRouter, | ||
FunctionResponse, | ||
View, | ||
makeFunction | ||
llmFunction | ||
}); | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@fadeaway-ai/sdk", | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"description": "", | ||
@@ -29,4 +29,4 @@ "main": "./dist/index.js", | ||
"yargs": "^17.7.2", | ||
"tsconfig": "0.0.0", | ||
"eslint-config-custom": "0.0.0" | ||
"eslint-config-custom": "0.0.0", | ||
"tsconfig": "0.0.0" | ||
}, | ||
@@ -33,0 +33,0 @@ "dependencies": { |
@@ -7,4 +7,4 @@ #!/usr/bin/env node | ||
import { hideBin } from 'yargs/helpers' | ||
import { generateAgents } from './codegen/genAgents' | ||
import { generateViews } from './codegen/genViews' | ||
import { generateAPI } from './codegen/generateAPI' | ||
import { generateUI } from './codegen/generateUI' | ||
@@ -41,5 +41,5 @@ function main() { | ||
async argv => { | ||
const viewsDirectory = path.resolve(argv.viewsDirectory || ('./views' as string)) | ||
const agentsDirectory = path.resolve(argv.agentsDirectory || ('./agents' as string)) | ||
const outputDirectory = path.resolve(argv.outputDirectory || ('./src/fadeaway' as string)) | ||
const viewsDirectory = path.resolve(argv.viewsDirectory || ('./fadeaway/ui' as string)) | ||
const agentsDirectory = path.resolve(argv.agentsDirectory || ('./fadeaway/api' as string)) | ||
const outputDirectory = path.resolve(argv.outputDirectory || ('./fadeaway/generated' as string)) | ||
@@ -57,8 +57,8 @@ // create all directories if they don't exist | ||
const { views, viewComponents } = await generateViews(viewsDirectory) | ||
const { agentRouter } = await generateAgents(agentsDirectory) | ||
const { ui, uiComponents } = await generateUI(viewsDirectory) | ||
const { fadeawayRouter } = await generateAPI(agentsDirectory) | ||
fs.writeFileSync(path.join(outputDirectory, 'AgentRouter.ts'), agentRouter) | ||
fs.writeFileSync(path.join(outputDirectory, 'Views.ts'), views) | ||
fs.writeFileSync(path.join(outputDirectory, 'ViewComponents.tsx'), viewComponents) | ||
fs.writeFileSync(path.join(outputDirectory, 'FadeawayAPI.ts'), fadeawayRouter) | ||
fs.writeFileSync(path.join(outputDirectory, 'UI.ts'), ui) | ||
fs.writeFileSync(path.join(outputDirectory, 'UIComponents.tsx'), uiComponents) | ||
@@ -65,0 +65,0 @@ console.log('Done!') |
@@ -1,4 +0,4 @@ | ||
export { makeFunction } from './LLMFunction' | ||
export type { LLMFunction } from './LLMFunction' | ||
export { AgentRouter } from './Router' | ||
export { FunctionResponse, llmFunction } from './LLMFunction' | ||
export type { Agent, IFunctionResponse, LLMFunction } from './LLMFunction' | ||
export { FadeawayRouter } from './Router' | ||
export { View } from './View' |
@@ -6,17 +6,12 @@ import { z, ZodType } from 'zod' | ||
description: string | ||
schema: ZodType<Input> | ||
// deno-lint-ignore no-explicit-any | ||
run: (data: Input) => any | ||
schema?: ZodType<Input> | ||
run: (data: Input) => IFunctionResponse<Output> | Promise<IFunctionResponse<Output>> | ||
} | ||
export function makeFunction<Input, Output>(arg: { | ||
name: string | ||
description: string | ||
schema?: ZodType<Input> | ||
run: (data: Input) => Output | ||
}): LLMFunction<Input, Output> { | ||
export function llmFunction<Input, Output>( | ||
arg: LLMFunction<Input, Output> | ||
): LLMFunction<Input, Output> { | ||
return { | ||
name: arg.name, | ||
description: arg.description, | ||
// deno-lint-ignore no-explicit-any | ||
schema: arg.schema || (z.object({}) as any as ZodType<Input>), | ||
@@ -26,1 +21,18 @@ run: arg.run, | ||
} | ||
export interface Agent { | ||
prompt: string | ||
functions: LLMFunction<any, any>[] | ||
} | ||
export interface IFunctionResponse<T = any> { | ||
result: T | ||
continue?: boolean | ||
} | ||
export function FunctionResponse<T>(result: T, options?: { continue?: boolean }): IFunctionResponse<T> { | ||
return { | ||
result, | ||
...(options ?? {}), | ||
} | ||
} |
import { Key, pathToRegexp } from 'path-to-regexp' | ||
import { Agent } from './LLMFunction' | ||
@@ -10,3 +11,3 @@ type RouteSegmentFunction = (paramsSoFar: { [key: string]: string }) => Promise<any> | ||
export class AgentRouter { | ||
export class FadeawayRouter { | ||
private routes: Route[] | ||
@@ -22,3 +23,3 @@ | ||
async matchAndRun(path: string): Promise<any[]> { | ||
async matchAndRun(path: string): Promise<Agent[]> { | ||
for (const route of this.routes) { | ||
@@ -31,2 +32,5 @@ const keys: Key[] = [] | ||
const allSegments = route.path.split('/').filter(Boolean) | ||
allSegments.push('') // handle root | ||
console.log('match', match) | ||
console.log('allSegments', allSegments) | ||
@@ -33,0 +37,0 @@ const paramsSoFar: { [key: string]: string } = {} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
29065290
1416
0
17