@fadeaway-ai/sdk
Advanced tools
Comparing version 0.1.13 to 0.1.14
@@ -0,118 +1,96 @@ | ||
import * as zod from 'zod'; | ||
import { ZodType } from 'zod'; | ||
import * as zod_to_json_schema_src_parseDef from 'zod-to-json-schema/src/parseDef'; | ||
import { ChatCompletionRequestMessage } from 'openai-edge'; | ||
declare class View { | ||
fadeawayViewId: string; | ||
props?: any; | ||
constructor(fadeawayViewId: string, props?: any); | ||
} | ||
interface FadeawayRedirect { | ||
__typename: 'redirect'; | ||
href: string; | ||
} | ||
interface FadeawayStop { | ||
__typename: 'stop'; | ||
} | ||
interface FadeawayView { | ||
__typename: 'view'; | ||
fadeawayViewId: string; | ||
props: any; | ||
} | ||
interface FadeawayContextMessage { | ||
__typename: 'context'; | ||
name: string; | ||
props: any; | ||
state: any; | ||
} | ||
interface FadeawayInitialContext { | ||
__typename: 'initial-context'; | ||
name: string; | ||
props: any; | ||
} | ||
type IFadeawayMessage = number | string | boolean | FadeawayRedirect | FadeawayStop | FadeawayView | FadeawayContextMessage | FadeawayInitialContext; | ||
declare const FadeawayMessage: { | ||
data: (data: string | number | boolean) => string | number | boolean; | ||
view: (view: View) => FadeawayView; | ||
redirect: (href: string) => FadeawayRedirect; | ||
stop: () => FadeawayStop; | ||
initializeContext: (ctx: FadeawayInitialContextData) => FadeawayInitialContext; | ||
context: (ctx: FadeawayContextData) => FadeawayContextMessage; | ||
}; | ||
interface FadeawayFunctionMeta<Input> { | ||
name: string; | ||
description: string; | ||
schema?: ZodType<Input>; | ||
run: (data: Input) => IFadeawayFunctionResponseMeta | Promise<IFadeawayFunctionResponseMeta>; | ||
} | ||
interface FadeawayFunction<Input> { | ||
name: string; | ||
required?: boolean; | ||
description: string; | ||
schema: ZodType<Input>; | ||
run: (data: Input) => IFadeawayFunctionResponse | Promise<IFadeawayFunctionResponse>; | ||
run: (data: Input) => any | Promise<any>; | ||
} | ||
interface FadeawayFunctionNew<Input> { | ||
declare function makeFunction<Input>(args: Omit<FadeawayFunction<Input>, 'schema'> & { | ||
schema?: ZodType<Input>; | ||
}): FadeawayFunction<Input>; | ||
declare function convertFunction(fn: FadeawayFunction<any>): { | ||
name: string; | ||
description: string; | ||
schema: ZodType<Input>; | ||
run: (data: Input) => any | Promise<any>; | ||
} | ||
type IFadeawayFunctionResponseMeta = IFadeawayMessage | IFadeawayMessage[] | undefined; | ||
type IFadeawayFunctionResponse = IFadeawayMessage[]; | ||
parameters: zod_to_json_schema_src_parseDef.JsonSchema7Type & { | ||
$schema?: string | undefined; | ||
definitions?: { | ||
[key: string]: zod_to_json_schema_src_parseDef.JsonSchema7Type; | ||
} | undefined; | ||
}; | ||
}; | ||
/** | ||
* Data required to initialize a fadeaway context on the server. | ||
*/ | ||
interface FadeawayContextMeta<Props = {}, State = {}> { | ||
name: string; | ||
prompt?: string; | ||
initState?: State; | ||
props?: Props; | ||
functions?: FadeawayFunction<any>[]; | ||
type FadeawayEvent = FadeawayAssistantMessage | FadeawayUserMessage | FadeawaySystemMessage | FadeawayAssistantFunctionCall | FadeawayFunctionResponse | FadeawayRequirementEvent; | ||
interface FadeawayEventBase { | ||
id: string; | ||
createdAt?: Date; | ||
} | ||
/** | ||
* Fadeaway context used in the server. | ||
*/ | ||
interface FadeawayContext<Props = {}, State = {}> { | ||
name: string; | ||
prompt?: string; | ||
initState: State; | ||
props: Props; | ||
functions: FadeawayFunction<any>[]; | ||
interface FadeawayAssistantMessage extends FadeawayEventBase { | ||
role: 'assistant'; | ||
content: string; | ||
} | ||
/** | ||
* Fadeaway context client uses to initialize the full context on the server. | ||
*/ | ||
interface FadeawayInitialContextData<Props = {}> { | ||
interface FadeawayUserMessage extends FadeawayEventBase { | ||
role: 'user'; | ||
content: string; | ||
} | ||
interface FadeawaySystemMessage extends FadeawayEventBase { | ||
role: 'system'; | ||
content: string; | ||
} | ||
interface FadeawayAssistantFunctionCall extends FadeawayEventBase { | ||
role: 'assistant_function_call'; | ||
function_call: string | { | ||
name?: string; | ||
arguments?: string; | ||
}; | ||
} | ||
interface FadeawayFunctionResponse extends FadeawayEventBase { | ||
role: 'function'; | ||
name: string; | ||
props: Props; | ||
content: string; | ||
} | ||
/** | ||
* Fadeaway context exposed to the client. | ||
*/ | ||
interface FadeawayContextData<Props = {}, State = {}> { | ||
interface FadeawayFunctionSchema { | ||
name: string; | ||
props: Props; | ||
state: State; | ||
description: string; | ||
parameters: any; | ||
} | ||
interface FadeawayRequirementEvent extends FadeawayEventBase { | ||
role: 'requirement'; | ||
functionSchema: FadeawayFunctionSchema; | ||
/** | ||
* What the user has currently set the arguments to. | ||
*/ | ||
args?: any; | ||
} | ||
declare function convertFadeawayEvent(event: FadeawayEvent): ChatCompletionRequestMessage | null; | ||
interface FadeawaySession { | ||
interface FadeawaySession<T> { | ||
id: string; | ||
contexts: FadeawayContextData[]; | ||
messages: ChatCompletionRequestMessage[]; | ||
state: T; | ||
events: FadeawayEvent[]; | ||
} | ||
interface FadeawayContextArgs<Props = {}, State = {}> { | ||
props: Props; | ||
session: FadeawaySession; | ||
setState: (state: Partial<State>) => void; | ||
getState: () => State; | ||
} | ||
type FadeawayContextHandler<Props = {}, State = {}> = (args: FadeawayContextArgs<Props, State>) => FadeawayContext<Props, State>; | ||
declare const Fadeaway: { | ||
context: <Props = {}, State = {}>(generator: (args: FadeawayContextArgs<Props, State>) => FadeawayContextMeta<Props, State>) => (args: FadeawayContextArgs<Props, State>) => FadeawayContext<Props, State>; | ||
function: <Input = {}>(args: FadeawayFunctionMeta<Input>) => FadeawayFunction<Input>; | ||
route: <T>(cb: (args: { | ||
session: FadeawaySession<T>; | ||
addFunction: <Input>(args: Omit<FadeawayFunction<Input>, "schema"> & { | ||
schema?: ZodType<Input, zod.ZodTypeDef, Input> | undefined; | ||
}) => void; | ||
addPrompt: (prompt: string) => void; | ||
setState: (newState: Partial<T>) => void; | ||
}) => Promise<void>) => (args: { | ||
session: FadeawaySession<T>; | ||
addFunction: <Input>(args: Omit<FadeawayFunction<Input>, "schema"> & { | ||
schema?: ZodType<Input, zod.ZodTypeDef, Input> | undefined; | ||
}) => void; | ||
addPrompt: (prompt: string) => void; | ||
setState: (newState: Partial<T>) => void; | ||
}) => Promise<void>; | ||
}; | ||
type FadeawayRoute = ReturnType<typeof Fadeaway.route>; | ||
export { Fadeaway, FadeawayContext, FadeawayContextArgs, FadeawayContextData, FadeawayContextHandler, FadeawayContextMessage, FadeawayFunction, FadeawayFunctionMeta, FadeawayFunctionNew, FadeawayInitialContextData, FadeawayMessage, FadeawayRedirect, FadeawaySession, FadeawayStop, FadeawayView, IFadeawayFunctionResponse, IFadeawayFunctionResponseMeta, IFadeawayMessage, View }; | ||
export { Fadeaway, FadeawayAssistantFunctionCall, FadeawayAssistantMessage, FadeawayEvent, FadeawayFunction, FadeawayFunctionResponse, FadeawayFunctionSchema, FadeawayRequirementEvent, FadeawayRoute, FadeawaySession, FadeawaySystemMessage, FadeawayUserMessage, convertFadeawayEvent, convertFunction, makeFunction }; |
@@ -24,4 +24,5 @@ "use strict"; | ||
Fadeaway: () => Fadeaway, | ||
FadeawayMessage: () => FadeawayMessage, | ||
View: () => View | ||
convertFadeawayEvent: () => convertFadeawayEvent, | ||
convertFunction: () => convertFunction, | ||
makeFunction: () => makeFunction | ||
}); | ||
@@ -31,70 +32,74 @@ module.exports = __toCommonJS(src_exports); | ||
// src/Fadeaway.ts | ||
var import_zod = require("zod"); | ||
var Fadeaway = { | ||
context: (generator) => { | ||
return (args) => { | ||
var _a, _b, _c; | ||
const contextMeta = generator(args); | ||
return { | ||
name: contextMeta.name, | ||
prompt: contextMeta.prompt, | ||
props: (_a = contextMeta.props) != null ? _a : {}, | ||
initState: (_b = contextMeta.initState) != null ? _b : {}, | ||
functions: (_c = contextMeta.functions) != null ? _c : [] | ||
// view: contextMeta.view, | ||
}; | ||
route: (cb) => { | ||
return cb; | ||
} | ||
}; | ||
// src/FadeawayEvent.ts | ||
function convertFadeawayEvent(event) { | ||
if (event.role === "user") { | ||
return { | ||
role: "user", | ||
content: event.content | ||
}; | ||
}, | ||
function: (args) => { | ||
} | ||
if (event.role === "assistant") { | ||
return { | ||
name: args.name, | ||
description: args.description, | ||
schema: args.schema || import_zod.z.object({}), | ||
run: async (data) => { | ||
const response = await args.run(data); | ||
if (response === void 0) { | ||
return []; | ||
} else if (Array.isArray(response)) { | ||
return response; | ||
} else { | ||
return [response]; | ||
} | ||
} | ||
role: "assistant", | ||
content: event.content | ||
}; | ||
} | ||
}; | ||
// src/FadeawayMessage.ts | ||
var FadeawayMessage = { | ||
data: (data) => data, | ||
view: (view) => { | ||
return { __typename: "view", fadeawayViewId: view.fadeawayViewId, props: view.props }; | ||
}, | ||
redirect: (href) => { | ||
return { __typename: "redirect", href }; | ||
}, | ||
stop: () => { | ||
return { __typename: "stop" }; | ||
}, | ||
initializeContext: (ctx) => { | ||
return { __typename: "initial-context", ...ctx }; | ||
}, | ||
context: (ctx) => { | ||
return { __typename: "context", ...ctx }; | ||
if (event.role === "system") { | ||
return { | ||
role: "system", | ||
content: event.content | ||
}; | ||
} | ||
}; | ||
if (event.role === "assistant_function_call") { | ||
return { | ||
role: "assistant", | ||
content: null, | ||
function_call: event.function_call | ||
}; | ||
} | ||
if (event.role === "function") { | ||
return { | ||
role: "function", | ||
name: event.name, | ||
content: event.content || "" | ||
}; | ||
} | ||
if (event.role === "requirement") { | ||
return null; | ||
} | ||
throw new Error(`unhandled event: ${JSON.stringify(event)}`); | ||
} | ||
// src/View.ts | ||
var View = class { | ||
constructor(fadeawayViewId, props) { | ||
this.fadeawayViewId = fadeawayViewId; | ||
this.props = props; | ||
} | ||
}; | ||
// src/FadeawayFunction.ts | ||
var import_zod = require("zod"); | ||
var import_zod_to_json_schema = require("zod-to-json-schema"); | ||
function makeFunction(args) { | ||
return { | ||
name: args.name, | ||
required: args.required, | ||
description: args.description, | ||
schema: args.schema || import_zod.z.object({}), | ||
run: args.run | ||
}; | ||
} | ||
function convertFunction(fn) { | ||
return { | ||
name: fn.name, | ||
description: fn.description, | ||
parameters: (0, import_zod_to_json_schema.zodToJsonSchema)(fn.schema) | ||
}; | ||
} | ||
// Annotate the CommonJS export names for ESM import in node: | ||
0 && (module.exports = { | ||
Fadeaway, | ||
FadeawayMessage, | ||
View | ||
convertFadeawayEvent, | ||
convertFunction, | ||
makeFunction | ||
}); | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@fadeaway-ai/sdk", | ||
"version": "0.1.13", | ||
"version": "0.1.14", | ||
"description": "", | ||
@@ -38,4 +38,5 @@ "main": "./dist/index.js", | ||
"path-to-regexp": "^6.2.1", | ||
"zod": "^3.21.4" | ||
"zod": "^3.21.4", | ||
"zod-to-json-schema": "^3.21.4" | ||
} | ||
} |
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
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
13364
4
190
+ Addedzod-to-json-schema@^3.21.4
+ Addedzod-to-json-schema@3.24.1(transitive)