chatkit-bun 0.0.2

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.
Files changed (52) hide show
  1. package/README.md +202 -0
  2. package/package.json +40 -0
  3. package/src/actions.ts +39 -0
  4. package/src/agents/accumulate.ts +43 -0
  5. package/src/agents/annotations.ts +157 -0
  6. package/src/agents/context.ts +190 -0
  7. package/src/agents/converter.ts +290 -0
  8. package/src/agents/index.ts +25 -0
  9. package/src/agents/stream.ts +1053 -0
  10. package/src/agents/types.ts +30 -0
  11. package/src/agents/workflows.ts +220 -0
  12. package/src/errors.ts +19 -0
  13. package/src/http.ts +60 -0
  14. package/src/index.ts +11 -0
  15. package/src/serialization.ts +75 -0
  16. package/src/server.ts +874 -0
  17. package/src/sqlite-store.ts +400 -0
  18. package/src/store.ts +98 -0
  19. package/src/types/core.ts +322 -0
  20. package/src/types/server.ts +396 -0
  21. package/src/widgets/components.ts +188 -0
  22. package/src/widgets/diff.ts +151 -0
  23. package/src/widgets/index.ts +6 -0
  24. package/src/widgets/serialization.ts +46 -0
  25. package/src/widgets/stream.ts +104 -0
  26. package/src/widgets/template.ts +180 -0
  27. package/src/widgets/types.ts +52 -0
  28. package/types/actions.d.ts +19 -0
  29. package/types/agents/accumulate.d.ts +4 -0
  30. package/types/agents/annotations.d.ts +21 -0
  31. package/types/agents/context.d.ts +35 -0
  32. package/types/agents/converter.d.ts +60 -0
  33. package/types/agents/index.d.ts +9 -0
  34. package/types/agents/stream.d.ts +4 -0
  35. package/types/agents/types.d.ts +26 -0
  36. package/types/agents/workflows.d.ts +34 -0
  37. package/types/errors.d.ts +11 -0
  38. package/types/http.d.ts +6 -0
  39. package/types/index.d.ts +11 -0
  40. package/types/serialization.d.ts +8 -0
  41. package/types/server.d.ts +73 -0
  42. package/types/sqlite-store.d.ts +43 -0
  43. package/types/store.d.ts +45 -0
  44. package/types/types/core.d.ts +1220 -0
  45. package/types/types/server.d.ts +5841 -0
  46. package/types/widgets/components.d.ts +144 -0
  47. package/types/widgets/diff.d.ts +7 -0
  48. package/types/widgets/index.d.ts +6 -0
  49. package/types/widgets/serialization.d.ts +2 -0
  50. package/types/widgets/stream.d.ts +10 -0
  51. package/types/widgets/template.d.ts +19 -0
  52. package/types/widgets/types.d.ts +24 -0
@@ -0,0 +1,144 @@
1
+ import type { ActionConfig } from "../actions";
2
+ import type { DynamicWidgetComponent, DynamicWidgetRoot, WidgetJson } from "./types";
3
+ type ActionConfigInput = {
4
+ type: ActionConfig["type"];
5
+ payload?: WidgetJson;
6
+ handler?: ActionConfig["handler"];
7
+ loadingBehavior?: ActionConfig["loadingBehavior"];
8
+ streaming?: ActionConfig["streaming"];
9
+ [key: string]: WidgetJson | undefined;
10
+ };
11
+ type WidgetPropValue = WidgetJson | ActionConfigInput | DynamicWidgetComponent | DynamicWidgetComponent[] | undefined;
12
+ type WidgetProps = Record<string, WidgetPropValue>;
13
+ type Children = DynamicWidgetComponent[];
14
+ type SingleChild = DynamicWidgetComponent;
15
+ export type BasicProps = WidgetProps & {
16
+ children?: Children;
17
+ };
18
+ export declare function Basic(props?: BasicProps): DynamicWidgetRoot;
19
+ export type CardProps = WidgetProps & {
20
+ children: Children;
21
+ asForm?: boolean;
22
+ confirm?: WidgetJson;
23
+ cancel?: WidgetJson;
24
+ };
25
+ export declare function Card(props: CardProps): DynamicWidgetRoot;
26
+ export type ListViewProps = WidgetProps & {
27
+ children: DynamicWidgetComponent[];
28
+ };
29
+ export declare function ListView(props: ListViewProps): DynamicWidgetRoot;
30
+ export type ListViewItemProps = WidgetProps & {
31
+ children: Children;
32
+ onClickAction?: ActionConfigInput;
33
+ };
34
+ export declare function ListViewItem(props: ListViewItemProps): DynamicWidgetComponent;
35
+ export type TextProps = WidgetProps & {
36
+ value: string;
37
+ streaming?: boolean;
38
+ };
39
+ export type TextWidget = {
40
+ type: "Text";
41
+ } & TextProps;
42
+ export declare function Text(props: TextProps): TextWidget;
43
+ export type MarkdownProps = WidgetProps & {
44
+ value: string;
45
+ streaming?: boolean;
46
+ };
47
+ export type MarkdownWidget = {
48
+ type: "Markdown";
49
+ } & MarkdownProps;
50
+ export declare function Markdown(props: MarkdownProps): MarkdownWidget;
51
+ export type TitleProps = WidgetProps & {
52
+ value: string;
53
+ };
54
+ export declare function Title(props: TitleProps): DynamicWidgetComponent;
55
+ export type CaptionProps = WidgetProps & {
56
+ value: string;
57
+ };
58
+ export declare function Caption(props: CaptionProps): DynamicWidgetComponent;
59
+ export type BadgeProps = WidgetProps & {
60
+ label: string;
61
+ };
62
+ export declare function Badge(props: BadgeProps): DynamicWidgetComponent;
63
+ export type BoxProps = WidgetProps & {
64
+ children?: Children;
65
+ };
66
+ export declare function Box(props?: BoxProps): DynamicWidgetComponent;
67
+ export type RowProps = WidgetProps & {
68
+ children?: Children;
69
+ };
70
+ export declare function Row(props?: RowProps): DynamicWidgetComponent;
71
+ export type ColProps = WidgetProps & {
72
+ children?: Children;
73
+ };
74
+ export declare function Col(props?: ColProps): DynamicWidgetComponent;
75
+ export type FormProps = WidgetProps & {
76
+ children?: Children;
77
+ onSubmitAction?: ActionConfigInput;
78
+ };
79
+ export declare function Form(props?: FormProps): DynamicWidgetComponent;
80
+ export declare function Divider(props?: WidgetProps): DynamicWidgetComponent;
81
+ export type IconProps = WidgetProps & {
82
+ name: string;
83
+ };
84
+ export declare function Icon(props: IconProps): DynamicWidgetComponent;
85
+ export type ImageProps = WidgetProps & {
86
+ src: string;
87
+ alt?: string;
88
+ };
89
+ export declare function Image(props: ImageProps): DynamicWidgetComponent;
90
+ export type ButtonProps = WidgetProps & {
91
+ label?: string;
92
+ onClickAction?: ActionConfigInput;
93
+ };
94
+ export declare function Button(props?: ButtonProps): DynamicWidgetComponent;
95
+ export declare function Spacer(props?: WidgetProps): DynamicWidgetComponent;
96
+ export type SelectProps = WidgetProps & {
97
+ name: string;
98
+ options: WidgetJson[];
99
+ };
100
+ export declare function Select(props: SelectProps): DynamicWidgetComponent;
101
+ export type DatePickerProps = WidgetProps & {
102
+ name: string;
103
+ };
104
+ export declare function DatePicker(props: DatePickerProps): DynamicWidgetComponent;
105
+ export type CheckboxProps = WidgetProps & {
106
+ name: string;
107
+ label?: string;
108
+ };
109
+ export declare function Checkbox(props: CheckboxProps): DynamicWidgetComponent;
110
+ export type InputProps = WidgetProps & {
111
+ name: string;
112
+ };
113
+ export declare function Input(props: InputProps): DynamicWidgetComponent;
114
+ export type LabelProps = WidgetProps & {
115
+ value: string;
116
+ fieldName: string;
117
+ };
118
+ export declare function Label(props: LabelProps): DynamicWidgetComponent;
119
+ export type RadioGroupProps = WidgetProps & {
120
+ name: string;
121
+ options?: WidgetJson[];
122
+ };
123
+ export declare function RadioGroup(props: RadioGroupProps): DynamicWidgetComponent;
124
+ export type TextareaProps = WidgetProps & {
125
+ name: string;
126
+ };
127
+ export declare function Textarea(props: TextareaProps): DynamicWidgetComponent;
128
+ export type TransitionProps = WidgetProps & {
129
+ children: SingleChild;
130
+ };
131
+ export declare function Transition(props: TransitionProps): DynamicWidgetComponent;
132
+ export type ChartProps = WidgetProps & {
133
+ data: WidgetJson[];
134
+ series: WidgetJson[];
135
+ xAxis: string;
136
+ showYAxis?: boolean;
137
+ showLegend?: boolean;
138
+ showTooltip?: boolean;
139
+ barGap?: string | number;
140
+ barCategoryGap?: string | number;
141
+ flex?: string | number;
142
+ };
143
+ export declare function Chart(props: ChartProps): DynamicWidgetComponent;
144
+ export {};
@@ -0,0 +1,7 @@
1
+ import type { ThreadItemUpdate } from "../types/server";
2
+ import type { WidgetRoot } from "./types";
3
+ type WidgetDiffUpdate = Extract<ThreadItemUpdate, {
4
+ type: "widget.root.updated" | "widget.streaming_text.value_delta";
5
+ }>;
6
+ export declare function diffWidget(before: WidgetRoot, after: WidgetRoot): WidgetDiffUpdate[];
7
+ export {};
@@ -0,0 +1,6 @@
1
+ export * from "./components";
2
+ export * from "./diff";
3
+ export * from "./serialization";
4
+ export * from "./stream";
5
+ export * from "./template";
6
+ export * from "./types";
@@ -0,0 +1,2 @@
1
+ import { type WidgetRoot } from "./types";
2
+ export declare function serializeWidget(widget: WidgetRoot): Record<string, unknown>;
@@ -0,0 +1,10 @@
1
+ import type { StoreItemType } from "../store";
2
+ import type { ThreadMetadata } from "../types/core";
3
+ import type { ThreadStreamEvent } from "../types/server";
4
+ import type { WidgetRoot } from "./types";
5
+ export interface StreamWidgetOptions {
6
+ copyText?: string | null;
7
+ generateId?: (itemType: StoreItemType) => string;
8
+ now?: () => string;
9
+ }
10
+ export declare function streamWidget(thread: ThreadMetadata, widgetOrAsyncIterable: WidgetRoot | AsyncIterable<WidgetRoot>, options?: StreamWidgetOptions): AsyncIterable<ThreadStreamEvent>;
@@ -0,0 +1,19 @@
1
+ import { type BasicRoot, type DynamicWidgetRoot } from "./types";
2
+ export interface WidgetTemplateDefinition {
3
+ version: string;
4
+ name: string;
5
+ template: string;
6
+ dataSchema?: Record<string, unknown>;
7
+ jsonSchema?: Record<string, unknown>;
8
+ }
9
+ export declare class WidgetTemplate {
10
+ readonly version: string;
11
+ readonly name: string;
12
+ readonly template: string;
13
+ readonly dataSchema: Record<string, unknown>;
14
+ readonly jsonSchema?: Record<string, unknown>;
15
+ constructor(definition: WidgetTemplateDefinition);
16
+ static fromFile(path: string): Promise<WidgetTemplate>;
17
+ build(data?: unknown): DynamicWidgetRoot;
18
+ buildBasic(data?: unknown): BasicRoot;
19
+ }
@@ -0,0 +1,24 @@
1
+ import { z } from "zod";
2
+ export type WidgetPrimitive = string | number | boolean | null;
3
+ export type WidgetJson = WidgetPrimitive | WidgetJson[] | {
4
+ [key: string]: WidgetJson | undefined;
5
+ };
6
+ export type DynamicWidgetComponent = {
7
+ type: string;
8
+ key?: string;
9
+ id?: string;
10
+ children?: DynamicWidgetComponent | DynamicWidgetComponent[];
11
+ [key: string]: WidgetJson | DynamicWidgetComponent | DynamicWidgetComponent[] | undefined;
12
+ };
13
+ export type BasicRoot = DynamicWidgetComponent & {
14
+ type: "Basic";
15
+ };
16
+ export type DynamicWidgetRoot = DynamicWidgetComponent & {
17
+ type: "Card" | "ListView" | "Basic";
18
+ };
19
+ export declare const WidgetJsonSchema: z.ZodType<WidgetJson>;
20
+ export declare const DynamicWidgetComponentSchema: z.ZodType<DynamicWidgetComponent>;
21
+ export declare const BasicRootSchema: z.ZodType<BasicRoot>;
22
+ export declare const DynamicWidgetRootSchema: z.ZodType<DynamicWidgetRoot>;
23
+ export type WidgetComponent = DynamicWidgetComponent;
24
+ export type WidgetRoot = DynamicWidgetRoot;