@copilotkit/shared 0.0.0-0.0.0-max-changeset-10101010101010-20260109191632

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 (185) hide show
  1. package/CHANGELOG.md +1800 -0
  2. package/LICENSE +21 -0
  3. package/README.md +141 -0
  4. package/dist/chunk-2OJ5OJ2D.mjs +1 -0
  5. package/dist/chunk-2OJ5OJ2D.mjs.map +1 -0
  6. package/dist/chunk-5YXKLIUO.mjs +38 -0
  7. package/dist/chunk-5YXKLIUO.mjs.map +1 -0
  8. package/dist/chunk-64DYJ27R.mjs +201 -0
  9. package/dist/chunk-64DYJ27R.mjs.map +1 -0
  10. package/dist/chunk-6QGXWNS5.mjs +34 -0
  11. package/dist/chunk-6QGXWNS5.mjs.map +1 -0
  12. package/dist/chunk-6W2UEO2M.mjs +94 -0
  13. package/dist/chunk-6W2UEO2M.mjs.map +1 -0
  14. package/dist/chunk-BOKE4OKY.mjs +41 -0
  15. package/dist/chunk-BOKE4OKY.mjs.map +1 -0
  16. package/dist/chunk-FCCOSO5L.mjs +1 -0
  17. package/dist/chunk-FCCOSO5L.mjs.map +1 -0
  18. package/dist/chunk-GYZIHHE6.mjs +13 -0
  19. package/dist/chunk-GYZIHHE6.mjs.map +1 -0
  20. package/dist/chunk-IAFBVORQ.mjs +1 -0
  21. package/dist/chunk-IAFBVORQ.mjs.map +1 -0
  22. package/dist/chunk-MSUB6DGR.mjs +1 -0
  23. package/dist/chunk-MSUB6DGR.mjs.map +1 -0
  24. package/dist/chunk-N5EP5OD5.mjs +1 -0
  25. package/dist/chunk-N5EP5OD5.mjs.map +1 -0
  26. package/dist/chunk-NAFEBKSO.mjs +1 -0
  27. package/dist/chunk-NAFEBKSO.mjs.map +1 -0
  28. package/dist/chunk-NBLG4PC5.mjs +426 -0
  29. package/dist/chunk-NBLG4PC5.mjs.map +1 -0
  30. package/dist/chunk-P7STFMPO.mjs +1 -0
  31. package/dist/chunk-P7STFMPO.mjs.map +1 -0
  32. package/dist/chunk-PL5WNHFZ.mjs +50 -0
  33. package/dist/chunk-PL5WNHFZ.mjs.map +1 -0
  34. package/dist/chunk-UYARLQNA.mjs +1 -0
  35. package/dist/chunk-UYARLQNA.mjs.map +1 -0
  36. package/dist/chunk-WUPFNPXO.mjs +107 -0
  37. package/dist/chunk-WUPFNPXO.mjs.map +1 -0
  38. package/dist/chunk-XEMZTHQZ.mjs +67 -0
  39. package/dist/chunk-XEMZTHQZ.mjs.map +1 -0
  40. package/dist/chunk-XTHC46M2.mjs +1 -0
  41. package/dist/chunk-XTHC46M2.mjs.map +1 -0
  42. package/dist/constants/index.d.ts +6 -0
  43. package/dist/constants/index.js +40 -0
  44. package/dist/constants/index.js.map +1 -0
  45. package/dist/constants/index.mjs +13 -0
  46. package/dist/constants/index.mjs.map +1 -0
  47. package/dist/index.d.ts +25 -0
  48. package/dist/index.js +1098 -0
  49. package/dist/index.js.map +1 -0
  50. package/dist/index.mjs +124 -0
  51. package/dist/index.mjs.map +1 -0
  52. package/dist/telemetry/events.d.ts +45 -0
  53. package/dist/telemetry/events.js +19 -0
  54. package/dist/telemetry/events.js.map +1 -0
  55. package/dist/telemetry/events.mjs +1 -0
  56. package/dist/telemetry/events.mjs.map +1 -0
  57. package/dist/telemetry/index.d.ts +3 -0
  58. package/dist/telemetry/index.js +188 -0
  59. package/dist/telemetry/index.js.map +1 -0
  60. package/dist/telemetry/index.mjs +12 -0
  61. package/dist/telemetry/index.mjs.map +1 -0
  62. package/dist/telemetry/scarf-client.d.ts +7 -0
  63. package/dist/telemetry/scarf-client.js +59 -0
  64. package/dist/telemetry/scarf-client.js.map +1 -0
  65. package/dist/telemetry/scarf-client.mjs +7 -0
  66. package/dist/telemetry/scarf-client.mjs.map +1 -0
  67. package/dist/telemetry/security-check.d.ts +2 -0
  68. package/dist/telemetry/security-check.js +2 -0
  69. package/dist/telemetry/security-check.js.map +1 -0
  70. package/dist/telemetry/security-check.mjs +1 -0
  71. package/dist/telemetry/security-check.mjs.map +1 -0
  72. package/dist/telemetry/telemetry-client.d.ts +40 -0
  73. package/dist/telemetry/telemetry-client.js +186 -0
  74. package/dist/telemetry/telemetry-client.js.map +1 -0
  75. package/dist/telemetry/telemetry-client.mjs +11 -0
  76. package/dist/telemetry/telemetry-client.mjs.map +1 -0
  77. package/dist/telemetry/utils.d.ts +8 -0
  78. package/dist/telemetry/utils.js +69 -0
  79. package/dist/telemetry/utils.js.map +1 -0
  80. package/dist/telemetry/utils.mjs +9 -0
  81. package/dist/telemetry/utils.mjs.map +1 -0
  82. package/dist/types/action.d.ts +59 -0
  83. package/dist/types/action.js +19 -0
  84. package/dist/types/action.js.map +1 -0
  85. package/dist/types/action.mjs +2 -0
  86. package/dist/types/action.mjs.map +1 -0
  87. package/dist/types/copilot-cloud-config.d.ts +13 -0
  88. package/dist/types/copilot-cloud-config.js +19 -0
  89. package/dist/types/copilot-cloud-config.js.map +1 -0
  90. package/dist/types/copilot-cloud-config.mjs +2 -0
  91. package/dist/types/copilot-cloud-config.mjs.map +1 -0
  92. package/dist/types/error.d.ts +55 -0
  93. package/dist/types/error.js +19 -0
  94. package/dist/types/error.js.map +1 -0
  95. package/dist/types/error.mjs +2 -0
  96. package/dist/types/error.mjs.map +1 -0
  97. package/dist/types/index.d.ts +7 -0
  98. package/dist/types/index.js +19 -0
  99. package/dist/types/index.js.map +1 -0
  100. package/dist/types/index.mjs +8 -0
  101. package/dist/types/index.mjs.map +1 -0
  102. package/dist/types/message.d.ts +26 -0
  103. package/dist/types/message.js +19 -0
  104. package/dist/types/message.js.map +1 -0
  105. package/dist/types/message.mjs +2 -0
  106. package/dist/types/message.mjs.map +1 -0
  107. package/dist/types/openai-assistant.d.ts +53 -0
  108. package/dist/types/openai-assistant.js +19 -0
  109. package/dist/types/openai-assistant.js.map +1 -0
  110. package/dist/types/openai-assistant.mjs +2 -0
  111. package/dist/types/openai-assistant.mjs.map +1 -0
  112. package/dist/types/utility.d.ts +6 -0
  113. package/dist/types/utility.js +19 -0
  114. package/dist/types/utility.js.map +1 -0
  115. package/dist/types/utility.mjs +2 -0
  116. package/dist/types/utility.mjs.map +1 -0
  117. package/dist/utils/conditions.d.ts +26 -0
  118. package/dist/utils/conditions.js +74 -0
  119. package/dist/utils/conditions.js.map +1 -0
  120. package/dist/utils/conditions.mjs +7 -0
  121. package/dist/utils/conditions.mjs.map +1 -0
  122. package/dist/utils/console-styling.d.ts +84 -0
  123. package/dist/utils/console-styling.js +123 -0
  124. package/dist/utils/console-styling.js.map +1 -0
  125. package/dist/utils/console-styling.mjs +17 -0
  126. package/dist/utils/console-styling.mjs.map +1 -0
  127. package/dist/utils/errors.d.ts +280 -0
  128. package/dist/utils/errors.js +443 -0
  129. package/dist/utils/errors.js.map +1 -0
  130. package/dist/utils/errors.mjs +65 -0
  131. package/dist/utils/errors.mjs.map +1 -0
  132. package/dist/utils/index.d.ts +32 -0
  133. package/dist/utils/index.js +927 -0
  134. package/dist/utils/index.js.map +1 -0
  135. package/dist/utils/index.mjs +108 -0
  136. package/dist/utils/index.mjs.map +1 -0
  137. package/dist/utils/json-schema.d.ts +34 -0
  138. package/dist/utils/json-schema.js +228 -0
  139. package/dist/utils/json-schema.js.map +1 -0
  140. package/dist/utils/json-schema.mjs +13 -0
  141. package/dist/utils/json-schema.mjs.map +1 -0
  142. package/dist/utils/random-id.d.ts +6 -0
  143. package/dist/utils/random-id.js +68 -0
  144. package/dist/utils/random-id.js.map +1 -0
  145. package/dist/utils/random-id.mjs +13 -0
  146. package/dist/utils/random-id.mjs.map +1 -0
  147. package/dist/utils/requests.d.ts +10 -0
  148. package/dist/utils/requests.js +91 -0
  149. package/dist/utils/requests.js.map +1 -0
  150. package/dist/utils/requests.mjs +7 -0
  151. package/dist/utils/requests.mjs.map +1 -0
  152. package/dist/utils/types.d.ts +20 -0
  153. package/dist/utils/types.js +19 -0
  154. package/dist/utils/types.js.map +1 -0
  155. package/dist/utils/types.mjs +2 -0
  156. package/dist/utils/types.mjs.map +1 -0
  157. package/jest.config.js +5 -0
  158. package/package.json +68 -0
  159. package/src/constants/index.ts +4 -0
  160. package/src/index.ts +7 -0
  161. package/src/telemetry/events.ts +41 -0
  162. package/src/telemetry/index.ts +1 -0
  163. package/src/telemetry/scarf-client.ts +39 -0
  164. package/src/telemetry/security-check.ts +0 -0
  165. package/src/telemetry/telemetry-client.ts +142 -0
  166. package/src/telemetry/utils.ts +39 -0
  167. package/src/types/action.ts +129 -0
  168. package/src/types/copilot-cloud-config.ts +11 -0
  169. package/src/types/error.ts +70 -0
  170. package/src/types/index.ts +6 -0
  171. package/src/types/message.ts +37 -0
  172. package/src/types/openai-assistant.ts +62 -0
  173. package/src/types/utility.ts +2 -0
  174. package/src/utils/conditions.ts +98 -0
  175. package/src/utils/console-styling.ts +124 -0
  176. package/src/utils/errors.ts +525 -0
  177. package/src/utils/index.ts +49 -0
  178. package/src/utils/json-schema.test.ts +383 -0
  179. package/src/utils/json-schema.ts +258 -0
  180. package/src/utils/random-id.ts +42 -0
  181. package/src/utils/requests.ts +77 -0
  182. package/src/utils/types.ts +22 -0
  183. package/tsconfig.json +9 -0
  184. package/tsup.config.ts +11 -0
  185. package/typedoc.json +4 -0
@@ -0,0 +1,129 @@
1
+ type TypeMap = {
2
+ string: string;
3
+ number: number;
4
+ boolean: boolean;
5
+ object: object;
6
+ "string[]": string[];
7
+ "number[]": number[];
8
+ "boolean[]": boolean[];
9
+ "object[]": object[];
10
+ };
11
+
12
+ type AbstractParameter = {
13
+ name: string;
14
+ type?: keyof TypeMap;
15
+ description?: string;
16
+ required?: boolean;
17
+ };
18
+
19
+ interface StringParameter extends AbstractParameter {
20
+ type: "string";
21
+ enum?: string[];
22
+ }
23
+
24
+ interface ObjectParameter extends AbstractParameter {
25
+ type: "object";
26
+ attributes?: Parameter[];
27
+ }
28
+
29
+ interface ObjectArrayParameter extends AbstractParameter {
30
+ type: "object[]";
31
+ attributes?: Parameter[];
32
+ }
33
+
34
+ type SpecialParameters = StringParameter | ObjectParameter | ObjectArrayParameter;
35
+ interface BaseParameter extends AbstractParameter {
36
+ type?: Exclude<AbstractParameter["type"], SpecialParameters["type"]>;
37
+ }
38
+
39
+ export type Parameter = BaseParameter | SpecialParameters;
40
+
41
+ type OptionalParameterType<P extends AbstractParameter> = P["required"] extends false
42
+ ? undefined
43
+ : never;
44
+
45
+ type StringParameterType<P> = P extends StringParameter
46
+ ? P extends { enum?: Array<infer E> }
47
+ ? E
48
+ : string
49
+ : never;
50
+
51
+ type ObjectParameterType<P> = P extends ObjectParameter
52
+ ? P extends { attributes?: infer Attributes extends Parameter[] }
53
+ ? MappedParameterTypes<Attributes>
54
+ : object
55
+ : never;
56
+
57
+ type ObjectArrayParameterType<P> = P extends ObjectArrayParameter
58
+ ? P extends { attributes?: infer Attributes extends Parameter[] }
59
+ ? MappedParameterTypes<Attributes>[]
60
+ : any[]
61
+ : never;
62
+
63
+ type MappedTypeOrString<T> = T extends keyof TypeMap ? TypeMap[T] : string;
64
+ type BaseParameterType<P extends AbstractParameter> = P extends { type: infer T }
65
+ ? T extends BaseParameter["type"]
66
+ ? MappedTypeOrString<T>
67
+ : never
68
+ : string;
69
+
70
+ export type MappedParameterTypes<T extends Parameter[] | [] = []> = T extends []
71
+ ? Record<string, any>
72
+ : {
73
+ [P in T[number] as P["name"]]:
74
+ | OptionalParameterType<P>
75
+ | StringParameterType<P>
76
+ | ObjectParameterType<P>
77
+ | ObjectArrayParameterType<P>
78
+ | BaseParameterType<P>;
79
+ };
80
+
81
+ export type Action<T extends Parameter[] | [] = []> = {
82
+ name: string;
83
+ description?: string;
84
+ parameters?: T;
85
+ handler?: T extends []
86
+ ? () => any | Promise<any>
87
+ : (args: MappedParameterTypes<T>) => any | Promise<any>;
88
+ additionalConfig?: Record<string, any>;
89
+ };
90
+
91
+ // This is the original "ceiling is being raised" version of MappedParameterTypes.
92
+ //
93
+ // ceiling is being raised. cursor's copilot helped us write "superhuman code"
94
+ // for a critical feature. We can read this code, but VERY few engineers out
95
+ // there could write it from scratch.
96
+ // Took lots of convincing too. "come on, this must be possible, try harder".
97
+ // and obviously- done in parts.
98
+ //
99
+ // - https://twitter.com/ataiiam/status/1765089261374914957
100
+ // (Mar 5, 2024)
101
+ //
102
+ // export type MappedParameterTypes<T extends Parameter[]> = {
103
+ // // Check if the parameter has an 'enum' defined
104
+ // [P in T[number] as P["name"]]: P extends { enum: Array<infer E> }
105
+ // ? E extends string // Ensure the enum values are strings
106
+ // ? P["required"] extends false // Check if the parameter is optional
107
+ // ? E | undefined // If so, include 'undefined' in the type
108
+ // : E // Otherwise, use the enum type directly
109
+ // : never // This case should not occur since 'enum' implies string values
110
+ // : // Handle parameters defined as 'object' with specified attributes
111
+ // P extends { type: "object"; attributes: infer Attributes }
112
+ // ? Attributes extends Parameter[]
113
+ // ? MappedParameterTypes<Attributes> // Recursively map the attributes of the object
114
+ // : never // If 'attributes' is not an array of Parameters, this is invalid
115
+ // : // Handle parameters defined as 'object[]' without specified attributes
116
+ // P extends { type: "object[]"; attributes?: never }
117
+ // ? any[] // Default to 'any[]' for arrays of objects without specific attributes
118
+ // : // Handle parameters defined as 'object[]' with specified attributes
119
+ // P extends { type: "object[]"; attributes: infer Attributes }
120
+ // ? Attributes extends Parameter[]
121
+ // ? MappedParameterTypes<Attributes>[] // Recursively map each object in the array
122
+ // : any[] // Default to 'any[]' if attributes are not properly defined
123
+ // : // Handle all other parameter types
124
+ // P["required"] extends false
125
+ // ? // Include 'undefined' for optional parameters
126
+ // TypeMap[P["type"] extends keyof TypeMap ? P["type"] : "string"] | undefined
127
+ // : // Use the direct mapping from 'TypeMap' for the parameter's type
128
+ // TypeMap[P["type"] extends keyof TypeMap ? P["type"] : "string"];
129
+ // };
@@ -0,0 +1,11 @@
1
+ export interface CopilotCloudConfig {
2
+ guardrails: {
3
+ input: {
4
+ restrictToTopic: {
5
+ enabled: boolean;
6
+ validTopics: string[];
7
+ invalidTopics: string[];
8
+ };
9
+ };
10
+ };
11
+ }
@@ -0,0 +1,70 @@
1
+ export interface CopilotErrorEvent {
2
+ type: "error" | "request" | "response" | "agent_state" | "action" | "message" | "performance";
3
+ timestamp: number;
4
+ context: CopilotRequestContext;
5
+ error?: any; // Present when type is 'error'
6
+ }
7
+
8
+ export interface CopilotRequestContext {
9
+ // Basic identifiers
10
+ threadId?: string;
11
+ runId?: string;
12
+ source: "runtime" | "ui" | "agent" | "network";
13
+
14
+ // Request details
15
+ request?: {
16
+ operation: string;
17
+ method?: string;
18
+ url?: string;
19
+ path?: string;
20
+ headers?: Record<string, string>;
21
+ body?: any;
22
+ startTime: number;
23
+ };
24
+
25
+ // Response details
26
+ response?: {
27
+ status?: number;
28
+ statusText?: string;
29
+ headers?: Record<string, string>;
30
+ body?: any;
31
+ endTime: number;
32
+ latency: number;
33
+ };
34
+
35
+ // Agent context
36
+ agent?: {
37
+ name?: string;
38
+ nodeName?: string;
39
+ state?: any;
40
+ };
41
+
42
+ // Message flow context
43
+ messages?: {
44
+ input?: any[];
45
+ output?: any[];
46
+ messageCount?: number;
47
+ };
48
+
49
+ // Technical context
50
+ technical?: {
51
+ userAgent?: string;
52
+ host?: string;
53
+ environment?: string;
54
+ version?: string;
55
+ stackTrace?: string;
56
+ };
57
+
58
+ // Performance metrics
59
+ performance?: {
60
+ requestDuration?: number;
61
+ streamingDuration?: number;
62
+ actionExecutionTime?: number;
63
+ memoryUsage?: number;
64
+ };
65
+
66
+ // Extensible metadata
67
+ metadata?: Record<string, any>;
68
+ }
69
+
70
+ export type CopilotErrorHandler = (errorEvent: CopilotErrorEvent) => void | Promise<void>;
@@ -0,0 +1,6 @@
1
+ export * from "./openai-assistant";
2
+ export * from "./action";
3
+ export * from "./copilot-cloud-config";
4
+ export * from "./utility";
5
+ export * from "./error";
6
+ export * from "./message";
@@ -0,0 +1,37 @@
1
+ import agui from "@ag-ui/core";
2
+
3
+ export interface ImageData {
4
+ format: string;
5
+ bytes: string;
6
+ }
7
+
8
+ // Pass through types
9
+ export type Role = agui.Role;
10
+ export type SystemMessage = agui.SystemMessage;
11
+ export type DeveloperMessage = agui.DeveloperMessage;
12
+ export type ToolCall = agui.ToolCall;
13
+ export type ActivityMessage = agui.ActivityMessage;
14
+
15
+ // Extended message types
16
+ export type ToolResult = agui.ToolMessage & {
17
+ toolName?: string;
18
+ };
19
+
20
+ export type AIMessage = agui.AssistantMessage & {
21
+ generativeUI?: (props?: any) => any;
22
+ agentName?: string;
23
+ state?: any;
24
+ image?: ImageData;
25
+ };
26
+
27
+ export type UserMessage = agui.UserMessage & {
28
+ image?: ImageData;
29
+ };
30
+
31
+ export type Message =
32
+ | AIMessage
33
+ | ToolResult
34
+ | UserMessage
35
+ | SystemMessage
36
+ | DeveloperMessage
37
+ | ActivityMessage;
@@ -0,0 +1,62 @@
1
+ export interface FunctionDefinition {
2
+ /**
3
+ * The name of the function to be called. Must be a-z, A-Z, 0-9, or contain
4
+ * underscores and dashes, with a maximum length of 64.
5
+ */
6
+ name: string;
7
+ /**
8
+ * The parameters the functions accepts, described as a JSON Schema object. See the
9
+ * [guide](/docs/guides/gpt/function-calling) for examples, and the
10
+ * [JSON Schema reference](https://json-schema.org/understanding-json-schema/) for
11
+ * documentation about the format.
12
+ *
13
+ * To describe a function that accepts no parameters, provide the value
14
+ * `{"type": "object", "properties": {}}`.
15
+ */
16
+ parameters: Record<string, unknown>;
17
+ /**
18
+ * A description of what the function does, used by the model to choose when and
19
+ * how to call the function.
20
+ */
21
+ description?: string;
22
+ }
23
+
24
+ export interface ToolDefinition {
25
+ type: "function";
26
+ function: FunctionDefinition;
27
+ }
28
+
29
+ export interface FunctionCallHandlerArguments {
30
+ messages: any[];
31
+ name: string;
32
+ args: any;
33
+ }
34
+
35
+ export type FunctionCallHandler = (args: FunctionCallHandlerArguments) => Promise<any>;
36
+
37
+ export type CoAgentStateRenderHandlerArguments = {
38
+ name: string;
39
+ nodeName: string;
40
+ state: any;
41
+ };
42
+
43
+ export type CoAgentStateRenderHandler = (args: CoAgentStateRenderHandlerArguments) => Promise<any>;
44
+
45
+ export type AssistantMessage = {
46
+ id: string;
47
+ role: "assistant";
48
+ content: Array<{
49
+ type: "text";
50
+ text: {
51
+ value: string;
52
+ };
53
+ }>;
54
+ };
55
+
56
+ export type JSONValue =
57
+ | null
58
+ | string
59
+ | number
60
+ | boolean
61
+ | { [x: string]: JSONValue }
62
+ | Array<JSONValue>;
@@ -0,0 +1,2 @@
1
+ export type PartialBy<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
2
+ export type RequiredBy<T, K extends keyof T> = T & { [P in K]-?: T[P] };
@@ -0,0 +1,98 @@
1
+ export type ComparisonRule =
2
+ | "EQUALS"
3
+ | "NOT_EQUALS"
4
+ | "GREATER_THAN"
5
+ | "LESS_THAN"
6
+ | "CONTAINS"
7
+ | "NOT_CONTAINS"
8
+ | "MATCHES"
9
+ | "STARTS_WITH"
10
+ | "ENDS_WITH";
11
+ export type LogicalRule = "AND" | "OR" | "NOT";
12
+ export type ExistenceRule = "EXISTS" | "NOT_EXISTS";
13
+
14
+ export type Rule = ComparisonRule | LogicalRule | ExistenceRule;
15
+
16
+ export interface BaseCondition {
17
+ rule: Rule;
18
+ path?: string;
19
+ }
20
+
21
+ export interface ComparisonCondition extends BaseCondition {
22
+ rule: ComparisonRule;
23
+ value: any;
24
+ }
25
+
26
+ export interface LogicalCondition extends BaseCondition {
27
+ rule: LogicalRule;
28
+ conditions: Condition[];
29
+ }
30
+
31
+ export interface ExistenceCondition extends BaseCondition {
32
+ rule: ExistenceRule;
33
+ }
34
+
35
+ export type Condition = ComparisonCondition | LogicalCondition | ExistenceCondition;
36
+
37
+ export function executeConditions({
38
+ conditions,
39
+ value,
40
+ }: {
41
+ conditions?: Condition[];
42
+ value: any;
43
+ }): boolean {
44
+ // If no conditions, consider it a pass
45
+ if (!conditions?.length) return true;
46
+
47
+ // Run all conditions (implicit AND)
48
+ return conditions.every((condition) => executeCondition(condition, value));
49
+ }
50
+
51
+ function executeCondition(condition: Condition, value: any): boolean {
52
+ const targetValue = condition.path ? getValueFromPath(value, condition.path) : value;
53
+
54
+ switch (condition.rule) {
55
+ // Logical
56
+ case "AND":
57
+ return (condition as LogicalCondition).conditions.every((c) => executeCondition(c, value));
58
+ case "OR":
59
+ return (condition as LogicalCondition).conditions.some((c) => executeCondition(c, value));
60
+ case "NOT":
61
+ return !(condition as LogicalCondition).conditions.every((c) => executeCondition(c, value));
62
+
63
+ // Comparison
64
+ case "EQUALS":
65
+ return targetValue === (condition as ComparisonCondition).value;
66
+ case "NOT_EQUALS":
67
+ return targetValue !== (condition as ComparisonCondition).value;
68
+ case "GREATER_THAN":
69
+ return targetValue > (condition as ComparisonCondition).value;
70
+ case "LESS_THAN":
71
+ return targetValue < (condition as ComparisonCondition).value;
72
+ case "CONTAINS":
73
+ return (
74
+ Array.isArray(targetValue) && targetValue.includes((condition as ComparisonCondition).value)
75
+ );
76
+ case "NOT_CONTAINS":
77
+ return (
78
+ Array.isArray(targetValue) &&
79
+ !targetValue.includes((condition as ComparisonCondition).value)
80
+ );
81
+ case "MATCHES":
82
+ return new RegExp((condition as ComparisonCondition).value).test(String(targetValue));
83
+ case "STARTS_WITH":
84
+ return String(targetValue).startsWith((condition as ComparisonCondition).value);
85
+ case "ENDS_WITH":
86
+ return String(targetValue).endsWith((condition as ComparisonCondition).value);
87
+
88
+ // Existence
89
+ case "EXISTS":
90
+ return targetValue !== undefined && targetValue !== null;
91
+ case "NOT_EXISTS":
92
+ return targetValue === undefined || targetValue === null;
93
+ }
94
+ }
95
+
96
+ function getValueFromPath(obj: any, path: string): any {
97
+ return path.split(".").reduce((acc, part) => acc?.[part], obj);
98
+ }
@@ -0,0 +1,124 @@
1
+ /**
2
+ * Console styling utilities for CopilotKit branded messages
3
+ * Provides consistent, readable colors across light and dark console themes
4
+ */
5
+
6
+ /**
7
+ * Color palette optimized for console readability
8
+ */
9
+ export const ConsoleColors = {
10
+ /** Primary brand blue - for titles and links */
11
+ primary: "#007acc",
12
+ /** Success green - for positive messaging */
13
+ success: "#22c55e",
14
+ /** Purple - for feature highlights */
15
+ feature: "#a855f7",
16
+ /** Red - for calls-to-action */
17
+ cta: "#ef4444",
18
+ /** Cyan - for closing statements */
19
+ info: "#06b6d4",
20
+ /** Inherit console default - for body text */
21
+ inherit: "inherit",
22
+ /** Warning style */
23
+ warning: "#f59e0b",
24
+ } as const;
25
+
26
+ /**
27
+ * Console style templates for common patterns
28
+ */
29
+ export const ConsoleStyles = {
30
+ /** Large header style */
31
+ header: `color: ${ConsoleColors.warning}; font-weight: bold; font-size: 16px;`,
32
+ /** Section header style */
33
+ section: `color: ${ConsoleColors.success}; font-weight: bold;`,
34
+ /** Feature highlight style */
35
+ highlight: `color: ${ConsoleColors.feature}; font-weight: bold;`,
36
+ /** Call-to-action style */
37
+ cta: `color: ${ConsoleColors.success}; font-weight: bold;`,
38
+ /** Info style */
39
+ info: `color: ${ConsoleColors.info}; font-weight: bold;`,
40
+ /** Link style */
41
+ link: `color: ${ConsoleColors.primary}; text-decoration: underline;`,
42
+ /** Body text - inherits console theme */
43
+ body: `color: ${ConsoleColors.inherit};`,
44
+ /** Warning style */
45
+ warning: `color: ${ConsoleColors.cta}; font-weight: bold;`,
46
+ } as const;
47
+
48
+ /**
49
+ * Styled console message for CopilotKit Platform promotion
50
+ * Displays a beautiful, branded advertisement in the console
51
+ */
52
+ export function logCopilotKitPlatformMessage() {
53
+ console.log(
54
+ `%cCopilotKit Warning%c
55
+
56
+ useCopilotChatHeadless_c provides full compatibility with CopilotKit's newly released Headless UI feature set. To enable this premium feature, add your public license key, available for free at:
57
+
58
+ %chttps://cloud.copilotkit.ai%c
59
+
60
+ Alternatively, useCopilotChat is available for basic programmatic control, and does not require an API key.
61
+
62
+ To learn more about premium features, read the documentation here:
63
+
64
+ %chttps://docs.copilotkit.ai/premium%c`,
65
+ ConsoleStyles.header,
66
+ ConsoleStyles.body,
67
+ ConsoleStyles.cta,
68
+ ConsoleStyles.body,
69
+ ConsoleStyles.link,
70
+ ConsoleStyles.body,
71
+ );
72
+ }
73
+
74
+ export function publicApiKeyRequired(feature: string) {
75
+ console.log(
76
+ `
77
+ %cCopilotKit Warning%c \n
78
+ In order to use ${feature}, you need to add your CopilotKit API key, available for free at https://cloud.copilotkit.ai.
79
+ `.trim(),
80
+ ConsoleStyles.header,
81
+ ConsoleStyles.body,
82
+ );
83
+ }
84
+
85
+ /**
86
+ * Create a styled console message with custom content
87
+ *
88
+ * @param template - Template string with %c placeholders
89
+ * @param styles - Array of style strings matching the %c placeholders
90
+ *
91
+ * @example
92
+ * ```typescript
93
+ * logStyled(
94
+ * '%cCopilotKit%c Welcome to the platform!',
95
+ * [ConsoleStyles.header, ConsoleStyles.body]
96
+ * );
97
+ * ```
98
+ */
99
+ export function logStyled(template: string, styles: string[]) {
100
+ console.log(template, ...styles);
101
+ }
102
+
103
+ /**
104
+ * Quick styled console methods for common use cases
105
+ */
106
+ export const styledConsole = {
107
+ /** Log a success message */
108
+ success: (message: string) => logStyled(`%c✅ ${message}`, [ConsoleStyles.section]),
109
+
110
+ /** Log an info message */
111
+ info: (message: string) => logStyled(`%cℹ️ ${message}`, [ConsoleStyles.info]),
112
+
113
+ /** Log a feature highlight */
114
+ feature: (message: string) => logStyled(`%c✨ ${message}`, [ConsoleStyles.highlight]),
115
+
116
+ /** Log a call-to-action */
117
+ cta: (message: string) => logStyled(`%c🚀 ${message}`, [ConsoleStyles.cta]),
118
+
119
+ /** Log the CopilotKit platform promotion */
120
+ logCopilotKitPlatformMessage: logCopilotKitPlatformMessage,
121
+
122
+ /** Log a `publicApiKeyRequired` warning */
123
+ publicApiKeyRequired: publicApiKeyRequired,
124
+ } as const;