@falai/agent 0.1.0

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 (129) hide show
  1. package/README.md +516 -0
  2. package/dist/constants/index.d.ts +5 -0
  3. package/dist/constants/index.d.ts.map +1 -0
  4. package/dist/constants/index.js +5 -0
  5. package/dist/constants/index.js.map +1 -0
  6. package/dist/core/Agent.d.ts +98 -0
  7. package/dist/core/Agent.d.ts.map +1 -0
  8. package/dist/core/Agent.js +248 -0
  9. package/dist/core/Agent.js.map +1 -0
  10. package/dist/core/DomainRegistry.d.ts +26 -0
  11. package/dist/core/DomainRegistry.d.ts.map +1 -0
  12. package/dist/core/DomainRegistry.js +41 -0
  13. package/dist/core/DomainRegistry.js.map +1 -0
  14. package/dist/core/Events.d.ts +19 -0
  15. package/dist/core/Events.d.ts.map +1 -0
  16. package/dist/core/Events.js +79 -0
  17. package/dist/core/Events.js.map +1 -0
  18. package/dist/core/Observation.d.ts +24 -0
  19. package/dist/core/Observation.d.ts.map +1 -0
  20. package/dist/core/Observation.js +35 -0
  21. package/dist/core/Observation.js.map +1 -0
  22. package/dist/core/PromptBuilder.d.ts +121 -0
  23. package/dist/core/PromptBuilder.d.ts.map +1 -0
  24. package/dist/core/PromptBuilder.js +339 -0
  25. package/dist/core/PromptBuilder.js.map +1 -0
  26. package/dist/core/Route.d.ts +46 -0
  27. package/dist/core/Route.d.ts.map +1 -0
  28. package/dist/core/Route.js +113 -0
  29. package/dist/core/Route.js.map +1 -0
  30. package/dist/core/State.d.ts +50 -0
  31. package/dist/core/State.d.ts.map +1 -0
  32. package/dist/core/State.js +110 -0
  33. package/dist/core/State.js.map +1 -0
  34. package/dist/core/Tool.d.ts +31 -0
  35. package/dist/core/Tool.d.ts.map +1 -0
  36. package/dist/core/Tool.js +33 -0
  37. package/dist/core/Tool.js.map +1 -0
  38. package/dist/core/Transition.d.ts +32 -0
  39. package/dist/core/Transition.d.ts.map +1 -0
  40. package/dist/core/Transition.js +59 -0
  41. package/dist/core/Transition.js.map +1 -0
  42. package/dist/index.d.ts +34 -0
  43. package/dist/index.d.ts.map +1 -0
  44. package/dist/index.js +26 -0
  45. package/dist/index.js.map +1 -0
  46. package/dist/providers/GeminiProvider.d.ts +40 -0
  47. package/dist/providers/GeminiProvider.d.ts.map +1 -0
  48. package/dist/providers/GeminiProvider.js +126 -0
  49. package/dist/providers/GeminiProvider.js.map +1 -0
  50. package/dist/providers/OpenAIProvider.d.ts +42 -0
  51. package/dist/providers/OpenAIProvider.d.ts.map +1 -0
  52. package/dist/providers/OpenAIProvider.js +164 -0
  53. package/dist/providers/OpenAIProvider.js.map +1 -0
  54. package/dist/providers/OpenRouterProvider.d.ts +46 -0
  55. package/dist/providers/OpenRouterProvider.d.ts.map +1 -0
  56. package/dist/providers/OpenRouterProvider.js +171 -0
  57. package/dist/providers/OpenRouterProvider.js.map +1 -0
  58. package/dist/types/agent.d.ts +105 -0
  59. package/dist/types/agent.d.ts.map +1 -0
  60. package/dist/types/agent.js +18 -0
  61. package/dist/types/agent.js.map +1 -0
  62. package/dist/types/ai.d.ts +78 -0
  63. package/dist/types/ai.d.ts.map +1 -0
  64. package/dist/types/ai.js +5 -0
  65. package/dist/types/ai.js.map +1 -0
  66. package/dist/types/history.d.ts +112 -0
  67. package/dist/types/history.d.ts.map +1 -0
  68. package/dist/types/history.js +34 -0
  69. package/dist/types/history.js.map +1 -0
  70. package/dist/types/index.d.ts +14 -0
  71. package/dist/types/index.d.ts.map +1 -0
  72. package/dist/types/index.js +7 -0
  73. package/dist/types/index.js.map +1 -0
  74. package/dist/types/observation.d.ts +25 -0
  75. package/dist/types/observation.d.ts.map +1 -0
  76. package/dist/types/observation.js +5 -0
  77. package/dist/types/observation.js.map +1 -0
  78. package/dist/types/prompt.d.ts +46 -0
  79. package/dist/types/prompt.d.ts.map +1 -0
  80. package/dist/types/prompt.js +16 -0
  81. package/dist/types/prompt.js.map +1 -0
  82. package/dist/types/route.d.ts +59 -0
  83. package/dist/types/route.d.ts.map +1 -0
  84. package/dist/types/route.js +5 -0
  85. package/dist/types/route.js.map +1 -0
  86. package/dist/types/tool.d.ts +46 -0
  87. package/dist/types/tool.d.ts.map +1 -0
  88. package/dist/types/tool.js +5 -0
  89. package/dist/types/tool.js.map +1 -0
  90. package/dist/utils/retry.d.ts +13 -0
  91. package/dist/utils/retry.d.ts.map +1 -0
  92. package/dist/utils/retry.js +70 -0
  93. package/dist/utils/retry.js.map +1 -0
  94. package/docs/API_REFERENCE.md +517 -0
  95. package/docs/CONSTRUCTOR_OPTIONS.md +256 -0
  96. package/docs/CONTRIBUTING.md +481 -0
  97. package/docs/GETTING_STARTED.md +328 -0
  98. package/docs/PROVIDERS.md +472 -0
  99. package/docs/PUBLISHING.md +174 -0
  100. package/docs/README.md +68 -0
  101. package/docs/STRUCTURE.md +32 -0
  102. package/examples/declarative-agent.ts +217 -0
  103. package/examples/healthcare-agent.ts +283 -0
  104. package/examples/openai-agent.ts +167 -0
  105. package/examples/travel-agent.ts +342 -0
  106. package/package.json +73 -0
  107. package/src/constants/index.ts +5 -0
  108. package/src/core/Agent.ts +307 -0
  109. package/src/core/DomainRegistry.ts +50 -0
  110. package/src/core/Events.ts +101 -0
  111. package/src/core/Observation.ts +46 -0
  112. package/src/core/PromptBuilder.ts +511 -0
  113. package/src/core/Route.ts +136 -0
  114. package/src/core/State.ts +153 -0
  115. package/src/core/Tool.ts +54 -0
  116. package/src/core/Transition.ts +66 -0
  117. package/src/index.ts +83 -0
  118. package/src/providers/GeminiProvider.ts +220 -0
  119. package/src/providers/OpenAIProvider.ts +272 -0
  120. package/src/providers/OpenRouterProvider.ts +282 -0
  121. package/src/types/agent.ts +112 -0
  122. package/src/types/ai.ts +85 -0
  123. package/src/types/history.ts +125 -0
  124. package/src/types/index.ts +56 -0
  125. package/src/types/observation.ts +27 -0
  126. package/src/types/prompt.ts +49 -0
  127. package/src/types/route.ts +68 -0
  128. package/src/types/tool.ts +53 -0
  129. package/src/utils/retry.ts +96 -0
@@ -0,0 +1,110 @@
1
+ /**
2
+ * State in the route DSL
3
+ */
4
+ import { END_ROUTE } from "@/constants";
5
+ import { Transition } from "@/core/Transition";
6
+ let stateIdCounter = 0;
7
+ /**
8
+ * Represents a state within a route
9
+ */
10
+ export class State {
11
+ routeId;
12
+ description;
13
+ id;
14
+ transitions = [];
15
+ guidelines = [];
16
+ constructor(routeId, description) {
17
+ this.routeId = routeId;
18
+ this.description = description;
19
+ this.id = `state_${++stateIdCounter}`;
20
+ }
21
+ /**
22
+ * Create a transition from this state to another
23
+ *
24
+ * @param spec - Transition specification (chatState, toolState, or direct state)
25
+ * @param condition - Optional condition for this transition
26
+ * @returns Object with target state that supports chaining
27
+ */
28
+ transitionTo(spec, condition) {
29
+ // Handle END_ROUTE
30
+ if (spec.state &&
31
+ typeof spec.state === "symbol" &&
32
+ spec.state === END_ROUTE) {
33
+ const endTransition = new Transition(this.getRef(), { state: END_ROUTE }, condition);
34
+ this.transitions.push(endTransition);
35
+ // Return a terminal state reference
36
+ return {
37
+ target: this.createTerminalRef(),
38
+ };
39
+ }
40
+ // Handle direct state reference
41
+ if (spec.state && typeof spec.state !== "symbol") {
42
+ const transition = new Transition(this.getRef(), spec, condition);
43
+ this.transitions.push(transition);
44
+ return {
45
+ target: this.createStateRefWithTransition(spec.state),
46
+ };
47
+ }
48
+ // Create new target state for chatState or toolState
49
+ const targetState = new State(this.routeId, spec.chatState);
50
+ const transition = new Transition(this.getRef(), spec, condition);
51
+ transition.setTarget(targetState);
52
+ this.transitions.push(transition);
53
+ return {
54
+ target: this.createStateRefWithTransition(targetState.getRef(), targetState),
55
+ };
56
+ }
57
+ /**
58
+ * Add a guideline specific to this state
59
+ */
60
+ addGuideline(guideline) {
61
+ this.guidelines.push(guideline);
62
+ }
63
+ /**
64
+ * Get guidelines for this state
65
+ */
66
+ getGuidelines() {
67
+ return [...this.guidelines];
68
+ }
69
+ /**
70
+ * Get all transitions from this state
71
+ */
72
+ getTransitions() {
73
+ return [...this.transitions];
74
+ }
75
+ /**
76
+ * Get state reference
77
+ */
78
+ getRef() {
79
+ return {
80
+ id: this.id,
81
+ routeId: this.routeId,
82
+ };
83
+ }
84
+ /**
85
+ * Create a state reference with transitionTo capability for chaining
86
+ */
87
+ createStateRefWithTransition(ref, state) {
88
+ const stateInstance = state || this;
89
+ return {
90
+ ...ref,
91
+ transitionTo: (spec, condition) => stateInstance.transitionTo(spec, condition),
92
+ };
93
+ }
94
+ /**
95
+ * Create a terminal state reference (for END_ROUTE)
96
+ */
97
+ createTerminalRef() {
98
+ const terminalRef = {
99
+ id: "END",
100
+ routeId: this.routeId,
101
+ };
102
+ return {
103
+ ...terminalRef,
104
+ transitionTo: () => {
105
+ throw new Error("Cannot transition from END_ROUTE state");
106
+ },
107
+ };
108
+ }
109
+ }
110
+ //# sourceMappingURL=State.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"State.js","sourceRoot":"","sources":["../../src/core/State.ts"],"names":[],"mappings":"AAAA;;GAEG;AAKH,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAE/C,IAAI,cAAc,GAAG,CAAC,CAAC;AAEvB;;GAEG;AACH,MAAM,OAAO,KAAK;IAME;IACA;IANF,EAAE,CAAS;IACnB,WAAW,GAAiB,EAAE,CAAC;IAC/B,UAAU,GAAgB,EAAE,CAAC;IAErC,YACkB,OAAe,EACf,WAAoB;QADpB,YAAO,GAAP,OAAO,CAAQ;QACf,gBAAW,GAAX,WAAW,CAAS;QAEpC,IAAI,CAAC,EAAE,GAAG,SAAS,EAAE,cAAc,EAAE,CAAC;IACxC,CAAC;IAED;;;;;;OAMG;IACH,YAAY,CAAC,IAAoB,EAAE,SAAkB;QACnD,mBAAmB;QACnB,IACE,IAAI,CAAC,KAAK;YACV,OAAO,IAAI,CAAC,KAAK,KAAK,QAAQ;YAC9B,IAAI,CAAC,KAAK,KAAK,SAAS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X,OAAO,CAAC,GAAG,IAAI,CAAC,UAAU,CAAC,CAAC;IAC9B,CAAC;IAED;;OAEG;IACH,cAAc;QACZ,OAAO,CAAC,GAAG,IAAI,CAAC,WAAW,CAAC,CAAC;IAC/B,CAAC;IAED;;OAEG;IACH,MAAM;QACJ,OAAO;YACL,EAAE,EAAE,IAAI,CAAC,EAAE;YACX,OAAO,EAAE,IAAI,CAAC,OAAO;SACtB,CAAC;IACJ,CAAC;IAED;;OAEG;IACK,4BAA4B,CAClC,GAAa,EACb,KAAa;QAOb,MAAM,aAAa,GAAG,KAAK,IAAI,IAAI,CAAC;QAEpC,OAAO;YACL,GAAG,GAAG;YACN,YAAY,EAAE,CAAC,IAAoB,EAAE,SAAkB,EAAE,EAAE,CACzD,aAAa,CAAC,YAAY,CAAC,IAAI,EAAE,SAAS,CAAC;SAC9C,CAAC;IACJ,CAAC;IAED;;OAEG;IACK,iBAAiB;QAMvB,MAAM,WAAW,GAAa;YAC5B,EAAE,EAAE,KAAK;YACT,OAAO,EAAE,IAAI,CAAC,OAAO;SACtB,CAAC;QAEF,OAAO;YACL,GAAG,WAAW;YACd,YAAY,EAAE,GAAG,EAAE;gBACjB,MAAM,IAAI,KAAK,CAAC,wCAAwC,CAAC,CAAC;YAC5D,CAAC;SACF,CAAC;IACJ,CAAC;CACF"}
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Tool definition and creation utilities
3
+ */
4
+ import type { ToolContext, ToolHandler, ToolRef, ToolResult } from "@/types/tool";
5
+ /**
6
+ * Define a new tool with type-safe context and arguments
7
+ *
8
+ * @param name - Name of the tool
9
+ * @param handler - Handler function that executes the tool
10
+ * @param options - Optional configuration
11
+ * @returns A reference to the defined tool
12
+ *
13
+ * @example
14
+ * ```ts
15
+ * const getTool = defineTool<MyContext, [string, number], string>(
16
+ * 'get_data',
17
+ * async ({ context }, id, count) => {
18
+ * return { data: `Retrieved ${count} items for ${id}` };
19
+ * }
20
+ * );
21
+ * ```
22
+ */
23
+ export declare function defineTool<TContext, TArgs extends unknown[], TResult>(name: string, handler: ToolHandler<TContext, TArgs, TResult>, options?: {
24
+ description?: string;
25
+ parameters?: unknown;
26
+ }): ToolRef<TContext, TArgs, TResult>;
27
+ /**
28
+ * Re-export types for convenience
29
+ */
30
+ export type { ToolContext, ToolHandler, ToolRef, ToolResult };
31
+ //# sourceMappingURL=Tool.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Tool.d.ts","sourceRoot":"","sources":["../../src/core/Tool.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EACV,WAAW,EACX,WAAW,EACX,OAAO,EACP,UAAU,EACX,MAAM,cAAc,CAAC;AAItB;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,UAAU,CAAC,QAAQ,EAAE,KAAK,SAAS,OAAO,EAAE,EAAE,OAAO,EACnE,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,WAAW,CAAC,QAAQ,EAAE,KAAK,EAAE,OAAO,CAAC,EAC9C,OAAO,CAAC,EAAE;IACR,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB,GACA,OAAO,CAAC,QAAQ,EAAE,KAAK,EAAE,OAAO,CAAC,CAUnC;AAED;;GAEG;AACH,YAAY,EAAE,WAAW,EAAE,WAAW,EAAE,OAAO,EAAE,UAAU,EAAE,CAAC"}
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Tool definition and creation utilities
3
+ */
4
+ let toolIdCounter = 0;
5
+ /**
6
+ * Define a new tool with type-safe context and arguments
7
+ *
8
+ * @param name - Name of the tool
9
+ * @param handler - Handler function that executes the tool
10
+ * @param options - Optional configuration
11
+ * @returns A reference to the defined tool
12
+ *
13
+ * @example
14
+ * ```ts
15
+ * const getTool = defineTool<MyContext, [string, number], string>(
16
+ * 'get_data',
17
+ * async ({ context }, id, count) => {
18
+ * return { data: `Retrieved ${count} items for ${id}` };
19
+ * }
20
+ * );
21
+ * ```
22
+ */
23
+ export function defineTool(name, handler, options) {
24
+ const id = `tool_${++toolIdCounter}_${name}`;
25
+ return {
26
+ id,
27
+ name,
28
+ handler,
29
+ description: options?.description,
30
+ parameters: options?.parameters,
31
+ };
32
+ }
33
+ //# sourceMappingURL=Tool.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Tool.js","sourceRoot":"","sources":["../../src/core/Tool.ts"],"names":[],"mappings":"AAAA;;GAEG;AASH,IAAI,aAAa,GAAG,CAAC,CAAC;AAEtB;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,UAAU,CACxB,IAAY,EACZ,OAA8C,EAC9C,OAGC;IAED,MAAM,EAAE,GAAG,QAAQ,EAAE,aAAa,IAAI,IAAI,EAAE,CAAC;IAE7C,OAAO;QACL,EAAE;QACF,IAAI;QACJ,OAAO;QACP,WAAW,EAAE,OAAO,EAAE,WAAW;QACjC,UAAU,EAAE,OAAO,EAAE,UAAU;KAChC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Transition between states in the route DSL
3
+ */
4
+ import type { StateRef, TransitionSpec } from "@/types/route";
5
+ import type { State } from "@/core/State";
6
+ /**
7
+ * Represents a transition from one state to another
8
+ */
9
+ export declare class Transition {
10
+ readonly source: StateRef;
11
+ readonly spec: TransitionSpec;
12
+ readonly condition?: string | undefined;
13
+ private target?;
14
+ constructor(source: StateRef, spec: TransitionSpec, condition?: string | undefined);
15
+ /**
16
+ * Set the target state for this transition
17
+ */
18
+ setTarget(state: State): void;
19
+ /**
20
+ * Get the target state
21
+ */
22
+ getTarget(): State | undefined;
23
+ /**
24
+ * Check if this transition has a condition
25
+ */
26
+ hasCondition(): boolean;
27
+ /**
28
+ * Get transition description for logging/debugging
29
+ */
30
+ describe(): string;
31
+ }
32
+ //# sourceMappingURL=Transition.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Transition.d.ts","sourceRoot":"","sources":["../../src/core/Transition.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC9D,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAE1C;;GAEG;AACH,qBAAa,UAAU;aAIH,MAAM,EAAE,QAAQ;aAChB,IAAI,EAAE,cAAc;aACpB,SAAS,CAAC,EAAE,MAAM;IALpC,OAAO,CAAC,MAAM,CAAC,CAAQ;gBAGL,MAAM,EAAE,QAAQ,EAChB,IAAI,EAAE,cAAc,EACpB,SAAS,CAAC,EAAE,MAAM,YAAA;IAGpC;;OAEG;IACH,SAAS,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI;IAI7B;;OAEG;IACH,SAAS,IAAI,KAAK,GAAG,SAAS;IAI9B;;OAEG;IACH,YAAY,IAAI,OAAO;IAIvB;;OAEG;IACH,QAAQ,IAAI,MAAM;CAsBnB"}
@@ -0,0 +1,59 @@
1
+ /**
2
+ * Transition between states in the route DSL
3
+ */
4
+ /**
5
+ * Represents a transition from one state to another
6
+ */
7
+ export class Transition {
8
+ source;
9
+ spec;
10
+ condition;
11
+ target;
12
+ constructor(source, spec, condition) {
13
+ this.source = source;
14
+ this.spec = spec;
15
+ this.condition = condition;
16
+ }
17
+ /**
18
+ * Set the target state for this transition
19
+ */
20
+ setTarget(state) {
21
+ this.target = state;
22
+ }
23
+ /**
24
+ * Get the target state
25
+ */
26
+ getTarget() {
27
+ return this.target;
28
+ }
29
+ /**
30
+ * Check if this transition has a condition
31
+ */
32
+ hasCondition() {
33
+ return !!this.condition;
34
+ }
35
+ /**
36
+ * Get transition description for logging/debugging
37
+ */
38
+ describe() {
39
+ const parts = [];
40
+ if (this.spec.chatState) {
41
+ parts.push(`chat: "${this.spec.chatState}"`);
42
+ }
43
+ if (this.spec.toolState) {
44
+ parts.push(`tool: ${this.spec.toolState.name}`);
45
+ }
46
+ if (this.spec.state) {
47
+ if (typeof this.spec.state === "symbol") {
48
+ parts.push("state: END_ROUTE");
49
+ }
50
+ else {
51
+ parts.push(`state: ${this.spec.state.id}`);
52
+ }
53
+ }
54
+ const transition = parts.join(", ");
55
+ const conditionPart = this.condition ? ` (when: ${this.condition})` : "";
56
+ return `${this.source.id} -> [${transition}]${conditionPart}`;
57
+ }
58
+ }
59
+ //# sourceMappingURL=Transition.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Transition.js","sourceRoot":"","sources":["../../src/core/Transition.ts"],"names":[],"mappings":"AAAA;;GAEG;AAKH;;GAEG;AACH,MAAM,OAAO,UAAU;IAIH;IACA;IACA;IALV,MAAM,CAAS;IAEvB,YACkB,MAAgB,EAChB,IAAoB,EACpB,SAAkB;QAFlB,WAAM,GAAN,MAAM,CAAU;QAChB,SAAI,GAAJ,IAAI,CAAgB;QACpB,cAAS,GAAT,SAAS,CAAS;IACjC,CAAC;IAEJ;;OAEG;IACH,SAAS,CAAC,KAAY;QACpB,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;IACtB,CAAC;IAED;;OAEG;IACH,SAAS;QACP,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAED;;OAEG;IACH,YAAY;QACV,OAAO,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC;IAC1B,CAAC;IAED;;OAEG;IACH,QAAQ;QACN,MAAM,KAAK,GAAa,EAAE,CAAC;QAE3B,IAAI,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC;YACxB,KAAK,CAAC,IAAI,CAAC,UAAU,IAAI,CAAC,IAAI,CAAC,SAAS,GAAG,CAAC,CAAC;QAC/C,CAAC;QACD,IAAI,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC;YACxB,KAAK,CAAC,IAAI,CAAC,SAAS,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC,CAAC;QAClD,CAAC;QACD,IAAI,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC;YACpB,IAAI,OAAO,IAAI,CAAC,IAAI,CAAC,KAAK,KAAK,QAAQ,EAAE,CAAC;gBACxC,KAAK,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC;YACjC,CAAC;iBAAM,CAAC;gBACN,KAAK,CAAC,IAAI,CAAC,UAAU,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,EAAE,CAAC,CAAC;YAC7C,CAAC;QACH,CAAC;QAED,MAAM,UAAU,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACpC,MAAM,aAAa,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,WAAW,IAAI,CAAC,SAAS,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;QAEzE,OAAO,GAAG,IAAI,CAAC,MAAM,CAAC,EAAE,QAAQ,UAAU,IAAI,aAAa,EAAE,CAAC;IAChE,CAAC;CACF"}
@@ -0,0 +1,34 @@
1
+ /**
2
+ * @falai/agent - Standalone AI Agent framework
3
+ *
4
+ * A strongly-typed, modular agent framework with route DSL and AI provider strategy
5
+ */
6
+ export { Agent } from "./core/Agent";
7
+ export { Route } from "./core/Route";
8
+ export { State } from "./core/State";
9
+ export { Transition } from "./core/Transition";
10
+ export { Observation } from "./core/Observation";
11
+ export { defineTool } from "./core/Tool";
12
+ export { DomainRegistry } from "./core/DomainRegistry";
13
+ export { adaptEvent, createMessageEvent, createToolEvent } from "./core/Events";
14
+ export { PromptBuilder } from "./core/PromptBuilder";
15
+ export type { Customer, AgentInfo } from "./core/PromptBuilder";
16
+ export { BuiltInSection } from "./core/PromptBuilder";
17
+ export { GeminiProvider } from "./providers/GeminiProvider";
18
+ export type { GeminiProviderOptions } from "./providers/GeminiProvider";
19
+ export { OpenAIProvider } from "./providers/OpenAIProvider";
20
+ export type { OpenAIProviderOptions } from "./providers/OpenAIProvider";
21
+ export { OpenRouterProvider } from "./providers/OpenRouterProvider";
22
+ export type { OpenRouterProviderOptions } from "./providers/OpenRouterProvider";
23
+ export { END_ROUTE } from "./constants";
24
+ export type { AgentOptions, Term, Guideline, Capability, GuidelineMatch, } from "@/types/agent";
25
+ export { CompositionMode } from "@/types/agent";
26
+ export type { Event, EmittedEvent, MessageEventData, ToolEventData, StatusEventData, Participant, } from "@/types/history";
27
+ export { EventKind, EventSource } from "@/types/history";
28
+ export type { RouteRef, StateRef, RouteOptions, TransitionSpec, TransitionResult, } from "@/types/route";
29
+ export type { ToolContext, ToolResult, ToolHandler, ToolRef, } from "@/types/tool";
30
+ export type { AiProvider, GenerateMessageInput, GenerateMessageOutput, ReasoningConfig, } from "@/types/ai";
31
+ export type { PromptSection, ContextVariable, ContextVariableValue, } from "@/types/prompt";
32
+ export { SectionStatus } from "@/types/prompt";
33
+ export type { Observation as IObservation, ObservationOptions, } from "@/types/observation";
34
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AACrC,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AACrC,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AACrC,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,UAAU,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChF,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,YAAY,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAChE,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAGtD,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAC5D,YAAY,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AACxE,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAC5D,YAAY,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AACxE,OAAO,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AACpE,YAAY,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAC;AAGhF,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAGxC,YAAY,EACV,YAAY,EACZ,IAAI,EACJ,SAAS,EACT,UAAU,EACV,cAAc,GACf,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAEhD,YAAY,EACV,KAAK,EACL,YAAY,EACZ,gBAAgB,EAChB,aAAa,EACb,eAAe,EACf,WAAW,GACZ,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAEzD,YAAY,EACV,QAAQ,EACR,QAAQ,EACR,YAAY,EACZ,cAAc,EACd,gBAAgB,GACjB,MAAM,eAAe,CAAC;AAEvB,YAAY,EACV,WAAW,EACX,UAAU,EACV,WAAW,EACX,OAAO,GACR,MAAM,cAAc,CAAC;AAEtB,YAAY,EACV,UAAU,EACV,oBAAoB,EACpB,qBAAqB,EACrB,eAAe,GAChB,MAAM,YAAY,CAAC;AAEpB,YAAY,EACV,aAAa,EACb,eAAe,EACf,oBAAoB,GACrB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAE/C,YAAY,EACV,WAAW,IAAI,YAAY,EAC3B,kBAAkB,GACnB,MAAM,qBAAqB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,26 @@
1
+ /**
2
+ * @falai/agent - Standalone AI Agent framework
3
+ *
4
+ * A strongly-typed, modular agent framework with route DSL and AI provider strategy
5
+ */
6
+ // Core
7
+ export { Agent } from "./core/Agent";
8
+ export { Route } from "./core/Route";
9
+ export { State } from "./core/State";
10
+ export { Transition } from "./core/Transition";
11
+ export { Observation } from "./core/Observation";
12
+ export { defineTool } from "./core/Tool";
13
+ export { DomainRegistry } from "./core/DomainRegistry";
14
+ export { adaptEvent, createMessageEvent, createToolEvent } from "./core/Events";
15
+ export { PromptBuilder } from "./core/PromptBuilder";
16
+ export { BuiltInSection } from "./core/PromptBuilder";
17
+ // Providers
18
+ export { GeminiProvider } from "./providers/GeminiProvider";
19
+ export { OpenAIProvider } from "./providers/OpenAIProvider";
20
+ export { OpenRouterProvider } from "./providers/OpenRouterProvider";
21
+ // Constants
22
+ export { END_ROUTE } from "./constants";
23
+ export { CompositionMode } from "@/types/agent";
24
+ export { EventKind, EventSource } from "@/types/history";
25
+ export { SectionStatus } from "@/types/prompt";
26
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO;AACP,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AACrC,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AACrC,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AACrC,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,UAAU,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChF,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAErD,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAEtD,YAAY;AACZ,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAE5D,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAE5D,OAAO,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AAGpE,YAAY;AACZ,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAUxC,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAUhD,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AA6BzD,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC"}
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Google Gemini AI provider implementation with retry and backup models
3
+ */
4
+ import type { GenerateContentConfig } from "@google/genai";
5
+ import type { AiProvider, GenerateMessageInput, GenerateMessageOutput } from "@/types/ai";
6
+ /**
7
+ * Configuration options for Gemini provider
8
+ * Uses types from @google/genai package
9
+ */
10
+ export interface GeminiProviderOptions {
11
+ /** Gemini API key */
12
+ apiKey: string;
13
+ /** Model to use (required) - e.g., "models/gemini-2.5-pro" */
14
+ model: string;
15
+ /** Backup models to try if primary fails (default: []) */
16
+ backupModels?: string[];
17
+ /** Default generation config - uses GenerateContentConfig from @google/genai */
18
+ config?: Partial<GenerateContentConfig>;
19
+ /** Retry configuration */
20
+ retryConfig?: {
21
+ timeout?: number;
22
+ retries?: number;
23
+ };
24
+ }
25
+ /**
26
+ * Gemini provider implementation with backup models and retry logic
27
+ */
28
+ export declare class GeminiProvider implements AiProvider {
29
+ readonly name = "gemini";
30
+ private genAI;
31
+ private primaryModel;
32
+ private backupModels;
33
+ private config?;
34
+ private retryConfig;
35
+ constructor(options: GeminiProviderOptions);
36
+ generateMessage<TContext = unknown>(input: GenerateMessageInput<TContext>): Promise<GenerateMessageOutput>;
37
+ private generateWithBackup;
38
+ private generateWithModel;
39
+ }
40
+ //# sourceMappingURL=GeminiProvider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"GeminiProvider.d.ts","sourceRoot":"","sources":["../../src/providers/GeminiProvider.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAEV,qBAAqB,EAEtB,MAAM,eAAe,CAAC;AAGvB,OAAO,KAAK,EACV,UAAU,EACV,oBAAoB,EACpB,qBAAqB,EACtB,MAAM,YAAY,CAAC;AAQpB;;;GAGG;AACH,MAAM,WAAW,qBAAqB;IACpC,qBAAqB;IACrB,MAAM,EAAE,MAAM,CAAC;IACf,8DAA8D;IAC9D,KAAK,EAAE,MAAM,CAAC;IACd,0DAA0D;IAC1D,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IACxB,gFAAgF;IAChF,MAAM,CAAC,EAAE,OAAO,CAAC,qBAAqB,CAAC,CAAC;IACxC,0BAA0B;IAC1B,WAAW,CAAC,EAAE;QACZ,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,OAAO,CAAC,EAAE,MAAM,CAAC;KAClB,CAAC;CACH;AA8CD;;GAEG;AACH,qBAAa,cAAe,YAAW,UAAU;IAC/C,SAAgB,IAAI,YAAY;IAChC,OAAO,CAAC,KAAK,CAAkB;IAC/B,OAAO,CAAC,YAAY,CAAS;IAC7B,OAAO,CAAC,YAAY,CAAW;IAC/B,OAAO,CAAC,MAAM,CAAC,CAAiC;IAChD,OAAO,CAAC,WAAW,CAAuC;gBAE9C,OAAO,EAAE,qBAAqB;IAqBpC,eAAe,CAAC,QAAQ,GAAG,OAAO,EACtC,KAAK,EAAE,oBAAoB,CAAC,QAAQ,CAAC,GACpC,OAAO,CAAC,qBAAqB,CAAC;YAInB,kBAAkB;YA2DlB,iBAAiB;CAmChC"}
@@ -0,0 +1,126 @@
1
+ /**
2
+ * Google Gemini AI provider implementation with retry and backup models
3
+ */
4
+ import { GoogleGenAI } from "@google/genai";
5
+ import { withTimeoutAndRetry } from "@/utils/retry";
6
+ const DEFAULT_RETRY_CONFIG = {
7
+ timeout: 60000,
8
+ retries: 3,
9
+ };
10
+ /**
11
+ * Determines if an error should trigger backup model usage
12
+ */
13
+ const shouldUseBackupModel = (error) => {
14
+ const err = error;
15
+ if (err?.status === 500 || err?.code === 500) {
16
+ return true;
17
+ }
18
+ const message = err?.message ?? String(error);
19
+ if (message.includes("internal error") ||
20
+ message.includes("Internal error") ||
21
+ message.includes("INTERNAL")) {
22
+ return true;
23
+ }
24
+ if (err?.status === 429 ||
25
+ err?.code === 429 ||
26
+ err?.status === 503 ||
27
+ err?.code === 503) {
28
+ return true;
29
+ }
30
+ if (message.includes("unavailable") || message.includes("not available")) {
31
+ return true;
32
+ }
33
+ return false;
34
+ };
35
+ /**
36
+ * Gemini provider implementation with backup models and retry logic
37
+ */
38
+ export class GeminiProvider {
39
+ name = "gemini";
40
+ genAI;
41
+ primaryModel;
42
+ backupModels;
43
+ config;
44
+ retryConfig;
45
+ constructor(options) {
46
+ const { apiKey, model, backupModels = [], config, retryConfig } = options;
47
+ if (!apiKey) {
48
+ throw new Error("Gemini API key is required");
49
+ }
50
+ if (!model) {
51
+ throw new Error("Model is required. Example: 'models/gemini-2.5-pro'");
52
+ }
53
+ this.genAI = new GoogleGenAI({ apiKey });
54
+ this.primaryModel = model;
55
+ this.backupModels = backupModels;
56
+ this.config = config;
57
+ this.retryConfig = {
58
+ timeout: retryConfig?.timeout || DEFAULT_RETRY_CONFIG.timeout,
59
+ retries: retryConfig?.retries || DEFAULT_RETRY_CONFIG.retries,
60
+ };
61
+ }
62
+ async generateMessage(input) {
63
+ return this.generateWithBackup(input);
64
+ }
65
+ async generateWithBackup(input) {
66
+ // Try primary model first
67
+ try {
68
+ return await this.generateWithModel(this.primaryModel, input);
69
+ }
70
+ catch (primaryError) {
71
+ const primaryErrMsg = String(primaryError);
72
+ console.warn(`[GEMINI] Primary model ${this.primaryModel} failed: ${primaryErrMsg}`);
73
+ if (!shouldUseBackupModel(primaryError)) {
74
+ throw primaryError;
75
+ }
76
+ console.log(`[GEMINI] Trying backup models`);
77
+ let lastBackupError = primaryError;
78
+ for (let i = 0; i < this.backupModels.length; i++) {
79
+ const backupModel = this.backupModels[i];
80
+ console.log(`[GEMINI] Trying backup model ${i + 1}/${this.backupModels.length}: ${backupModel}`);
81
+ try {
82
+ const result = await this.generateWithModel(backupModel, input);
83
+ console.log(`[GEMINI] Backup model ${backupModel} succeeded`);
84
+ return result;
85
+ }
86
+ catch (backupError) {
87
+ const backupErrMsg = String(backupError);
88
+ console.warn(`[GEMINI] Backup model ${backupModel} failed: ${backupErrMsg}`);
89
+ lastBackupError = backupError;
90
+ if (!shouldUseBackupModel(backupError) &&
91
+ i < this.backupModels.length - 1) {
92
+ console.log(`[GEMINI] Backup model error doesn't qualify for further attempts`);
93
+ break;
94
+ }
95
+ }
96
+ }
97
+ const lastBackupErrMsg = String(lastBackupError);
98
+ console.error(`[GEMINI] All models failed. Primary: ${primaryErrMsg}, Last backup: ${lastBackupErrMsg}`);
99
+ throw lastBackupError;
100
+ }
101
+ }
102
+ async generateWithModel(model, input) {
103
+ const operation = async () => {
104
+ const response = await this.genAI.models.generateContent({
105
+ model,
106
+ contents: input.prompt,
107
+ config: this.config,
108
+ });
109
+ const message = response.text;
110
+ if (!message) {
111
+ throw new Error("No response from Gemini");
112
+ }
113
+ return {
114
+ message,
115
+ metadata: {
116
+ model,
117
+ tokensUsed: response.usageMetadata?.totalTokenCount,
118
+ promptTokens: response.usageMetadata?.promptTokenCount,
119
+ completionTokens: response.usageMetadata?.candidatesTokenCount,
120
+ },
121
+ };
122
+ };
123
+ return withTimeoutAndRetry(operation, this.retryConfig.timeout, this.retryConfig.retries, `Gemini ${model}`);
124
+ }
125
+ }
126
+ //# sourceMappingURL=GeminiProvider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"GeminiProvider.js","sourceRoot":"","sources":["../../src/providers/GeminiProvider.ts"],"names":[],"mappings":"AAAA;;GAEG;AAOH,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAO5C,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAEpD,MAAM,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MAAM,CAAC,eAAe,CAAC;gBACtC,KAAK;gBACL,QAAQ,EAAE,KAAK,CAAC,MAAM;gBACtB,MAAM,EAAE,IAAI,CAAC,MAAM;aACpB,CAAC,CAAC;YAEL,MAAM,OAAO,GAAG,QAAQ,CAAC,IAAI,CAAC;YAC9B,IAAI,CAAC,OAAO,EAAE,CAAC;gBACb,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;YAC7C,CAAC;YAED,OAAO;gBACL,OAAO;gBACP,QAAQ,EAAE;oBACR,KAAK;oBACL,UAAU,EAAE,QAAQ,CAAC,aAAa,EAAE,eAAe;oBACnD,YAAY,EAAE,QAAQ,CAAC,aAAa,EAAE,gBAAgB;oBACtD,gBAAgB,EAAE,QAAQ,CAAC,aAAa,EAAE,oBAAoB;iBAC/D;aACF,CAAC;QACJ,CAAC,CAAC;QAEF,OAAO,mBAAmB,CACxB,SAAS,EACT,IAAI,CAAC,WAAW,CAAC,OAAO,EACxB,IAAI,CAAC,WAAW,CAAC,OAAO,EACxB,UAAU,KAAK,EAAE,CAClB,CAAC;IACJ,CAAC;CACF"}
@@ -0,0 +1,42 @@
1
+ /**
2
+ * OpenAI provider implementation with retry and backup models
3
+ */
4
+ import type { ChatCompletionCreateParamsNonStreaming } from "openai/resources/chat/completions";
5
+ import type { AiProvider, GenerateMessageInput, GenerateMessageOutput } from "@/types/ai";
6
+ /**
7
+ * Configuration options for OpenAI provider
8
+ * Uses types from openai package
9
+ */
10
+ export interface OpenAIProviderOptions {
11
+ /** OpenAI API key */
12
+ apiKey: string;
13
+ /** Organization ID (optional) */
14
+ organization?: string;
15
+ /** Model to use (required) - e.g., "gpt-5", "gpt-5-mini" */
16
+ model: string;
17
+ /** Backup models to try if primary fails (default: []) */
18
+ backupModels?: string[];
19
+ /** Default parameters - uses ChatCompletionCreateParamsNonStreaming from openai package */
20
+ config?: Partial<Omit<ChatCompletionCreateParamsNonStreaming, "model" | "messages">>;
21
+ /** Retry configuration */
22
+ retryConfig?: {
23
+ timeout?: number;
24
+ retries?: number;
25
+ };
26
+ }
27
+ /**
28
+ * OpenAI provider implementation with backup models and retry logic
29
+ */
30
+ export declare class OpenAIProvider implements AiProvider {
31
+ readonly name = "openai";
32
+ private client;
33
+ private primaryModel;
34
+ private backupModels;
35
+ private config?;
36
+ private retryConfig;
37
+ constructor(options: OpenAIProviderOptions);
38
+ generateMessage<TContext = unknown>(input: GenerateMessageInput<TContext>): Promise<GenerateMessageOutput>;
39
+ private generateWithBackup;
40
+ private generateWithModel;
41
+ }
42
+ //# sourceMappingURL=OpenAIProvider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"OpenAIProvider.d.ts","sourceRoot":"","sources":["../../src/providers/OpenAIProvider.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,KAAK,EAAE,sCAAsC,EAAE,MAAM,mCAAmC,CAAC;AAEhG,OAAO,KAAK,EACV,UAAU,EACV,oBAAoB,EACpB,qBAAqB,EACtB,MAAM,YAAY,CAAC;AAQpB;;;GAGG;AACH,MAAM,WAAW,qBAAqB;IACpC,qBAAqB;IACrB,MAAM,EAAE,MAAM,CAAC;IACf,iCAAiC;IACjC,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,4DAA4D;IAC5D,KAAK,EAAE,MAAM,CAAC;IACd,0DAA0D;IAC1D,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IACxB,2FAA2F;IAC3F,MAAM,CAAC,EAAE,OAAO,CACd,IAAI,CAAC,sCAAsC,EAAE,OAAO,GAAG,UAAU,CAAC,CACnE,CAAC;IACF,0BAA0B;IAC1B,WAAW,CAAC,EAAE;QACZ,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,OAAO,CAAC,EAAE,MAAM,CAAC;KAClB,CAAC;CACH;AAwED;;GAEG;AACH,qBAAa,cAAe,YAAW,UAAU;IAC/C,SAAgB,IAAI,YAAY;IAChC,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,YAAY,CAAS;IAC7B,OAAO,CAAC,YAAY,CAAW;IAC/B,OAAO,CAAC,MAAM,CAAC,CAEb;IACF,OAAO,CAAC,WAAW,CAAuC;gBAE9C,OAAO,EAAE,qBAAqB;IAiCpC,eAAe,CAAC,QAAQ,GAAG,OAAO,EACtC,KAAK,EAAE,oBAAoB,CAAC,QAAQ,CAAC,GACpC,OAAO,CAAC,qBAAqB,CAAC;YAInB,kBAAkB;YA2DlB,iBAAiB;CA+ChC"}