@copilotkit/shared 2.0.0-rc.4 → 2.0.0-rc.6
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.
- package/dist/index.cjs +0 -13
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -5
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +3 -5
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +3 -5
- package/dist/index.mjs.map +1 -1
- package/dist/index.umd.js +22 -187
- package/dist/index.umd.js.map +1 -1
- package/dist/package.cjs +1 -1
- package/dist/package.mjs +1 -1
- package/dist/telemetry/telemetry-client.cjs +3 -3
- package/dist/telemetry/telemetry-client.cjs.map +1 -1
- package/dist/telemetry/telemetry-client.mjs +3 -3
- package/dist/telemetry/telemetry-client.mjs.map +1 -1
- package/dist/utils/errors.cjs +4 -42
- package/dist/utils/errors.cjs.map +1 -1
- package/dist/utils/errors.d.cts +16 -34
- package/dist/utils/errors.d.cts.map +1 -1
- package/dist/utils/errors.d.mts +16 -34
- package/dist/utils/errors.d.mts.map +1 -1
- package/dist/utils/errors.mjs +5 -41
- package/dist/utils/errors.mjs.map +1 -1
- package/dist/utils/index.cjs +0 -2
- package/dist/utils/index.cjs.map +1 -1
- package/dist/utils/index.d.cts +2 -4
- package/dist/utils/index.d.cts.map +1 -1
- package/dist/utils/index.d.mts +2 -4
- package/dist/utils/index.d.mts.map +1 -1
- package/dist/utils/index.mjs +2 -4
- package/dist/utils/index.mjs.map +1 -1
- package/dist/utils/random-id.cjs +13 -26
- package/dist/utils/random-id.cjs.map +1 -1
- package/dist/utils/random-id.d.cts +6 -3
- package/dist/utils/random-id.d.cts.map +1 -1
- package/dist/utils/random-id.d.mts +6 -3
- package/dist/utils/random-id.d.mts.map +1 -1
- package/dist/utils/random-id.mjs +14 -25
- package/dist/utils/random-id.mjs.map +1 -1
- package/package.json +3 -6
- package/src/telemetry/telemetry-client.ts +3 -3
- package/src/utils/__tests__/errors.test.ts +44 -0
- package/src/utils/__tests__/random-id.test.ts +37 -0
- package/src/utils/errors.ts +27 -85
- package/src/utils/index.ts +0 -2
- package/src/utils/random-id.ts +17 -37
- package/tsdown.config.ts +1 -10
- package/dist/utils/conditions.cjs +0 -32
- package/dist/utils/conditions.cjs.map +0 -1
- package/dist/utils/conditions.d.cts +0 -31
- package/dist/utils/conditions.d.cts.map +0 -1
- package/dist/utils/conditions.d.mts +0 -31
- package/dist/utils/conditions.d.mts.map +0 -1
- package/dist/utils/conditions.mjs +0 -31
- package/dist/utils/conditions.mjs.map +0 -1
- package/dist/utils/console-styling.cjs +0 -91
- package/dist/utils/console-styling.cjs.map +0 -1
- package/dist/utils/console-styling.d.cts +0 -65
- package/dist/utils/console-styling.d.cts.map +0 -1
- package/dist/utils/console-styling.d.mts +0 -65
- package/dist/utils/console-styling.d.mts.map +0 -1
- package/dist/utils/console-styling.mjs +0 -85
- package/dist/utils/console-styling.mjs.map +0 -1
- package/src/utils/__tests__/conditions.test.ts +0 -161
- package/src/utils/conditions.ts +0 -116
- package/src/utils/console-styling.ts +0 -126
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"console-styling.d.cts","names":[],"sources":["../../src/utils/console-styling.ts"],"mappings":";;AAQA;;;;;;cAAa,aAAA;;;+BAoBA;EAAA;;;;;;;;cAAA,aAAA;mGAuB+B;EAAA,wDAAA;EAAA,0DAsB5B;EAAA;uDAAoC;EAAA,8DAyB3B;EAAA,kCAAC;EAAA;;;;;;iBA/CV,4BAAA,CAAA;AAAA,iBAsBA,oBAAA,CAAqB,OAAA;;;;;;;;;;;;;;;iBAyBrB,SAAA,CAAU,QAAA,UAAkB,MAAA;;;;cAO/B,aAAA;;;;;gDAoBH,4BAAA;wCAAA,oBAAA;AAAA"}
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
//#region src/utils/console-styling.d.ts
|
|
2
|
-
/**
|
|
3
|
-
* Console styling utilities for CopilotKit branded messages
|
|
4
|
-
* Provides consistent, readable colors across light and dark console themes
|
|
5
|
-
*/
|
|
6
|
-
/**
|
|
7
|
-
* Color palette optimized for console readability
|
|
8
|
-
*/
|
|
9
|
-
declare const ConsoleColors: {
|
|
10
|
-
/** Primary brand blue - for titles and links */readonly primary: "#007acc"; /** Success green - for positive messaging */
|
|
11
|
-
readonly success: "#22c55e"; /** Purple - for feature highlights */
|
|
12
|
-
readonly feature: "#a855f7"; /** Red - for calls-to-action */
|
|
13
|
-
readonly cta: "#ef4444"; /** Cyan - for closing statements */
|
|
14
|
-
readonly info: "#06b6d4"; /** Inherit console default - for body text */
|
|
15
|
-
readonly inherit: "inherit"; /** Warning style */
|
|
16
|
-
readonly warning: "#f59e0b";
|
|
17
|
-
};
|
|
18
|
-
/**
|
|
19
|
-
* Console style templates for common patterns
|
|
20
|
-
*/
|
|
21
|
-
declare const ConsoleStyles: {
|
|
22
|
-
/** Large header style */readonly header: "color: #f59e0b; font-weight: bold; font-size: 16px;"; /** Section header style */
|
|
23
|
-
readonly section: "color: #22c55e; font-weight: bold;"; /** Feature highlight style */
|
|
24
|
-
readonly highlight: "color: #a855f7; font-weight: bold;"; /** Call-to-action style */
|
|
25
|
-
readonly cta: "color: #22c55e; font-weight: bold;"; /** Info style */
|
|
26
|
-
readonly info: "color: #06b6d4; font-weight: bold;"; /** Link style */
|
|
27
|
-
readonly link: "color: #007acc; text-decoration: underline;"; /** Body text - inherits console theme */
|
|
28
|
-
readonly body: "color: inherit;"; /** Warning style */
|
|
29
|
-
readonly warning: "color: #ef4444; font-weight: bold;";
|
|
30
|
-
};
|
|
31
|
-
/**
|
|
32
|
-
* Styled console message for CopilotKit Platform promotion
|
|
33
|
-
* Displays a beautiful, branded advertisement in the console
|
|
34
|
-
*/
|
|
35
|
-
declare function logCopilotKitPlatformMessage(): void;
|
|
36
|
-
declare function publicApiKeyRequired(feature: string): void;
|
|
37
|
-
/**
|
|
38
|
-
* Create a styled console message with custom content
|
|
39
|
-
*
|
|
40
|
-
* @param template - Template string with %c placeholders
|
|
41
|
-
* @param styles - Array of style strings matching the %c placeholders
|
|
42
|
-
*
|
|
43
|
-
* @example
|
|
44
|
-
* ```typescript
|
|
45
|
-
* logStyled(
|
|
46
|
-
* '%cCopilotKit%c Welcome to the platform!',
|
|
47
|
-
* [ConsoleStyles.header, ConsoleStyles.body]
|
|
48
|
-
* );
|
|
49
|
-
* ```
|
|
50
|
-
*/
|
|
51
|
-
declare function logStyled(template: string, styles: string[]): void;
|
|
52
|
-
/**
|
|
53
|
-
* Quick styled console methods for common use cases
|
|
54
|
-
*/
|
|
55
|
-
declare const styledConsole: {
|
|
56
|
-
/** Log a success message */readonly success: (message: string) => void; /** Log an info message */
|
|
57
|
-
readonly info: (message: string) => void; /** Log a feature highlight */
|
|
58
|
-
readonly feature: (message: string) => void; /** Log a call-to-action */
|
|
59
|
-
readonly cta: (message: string) => void; /** Log the CopilotKit platform promotion */
|
|
60
|
-
readonly logCopilotKitPlatformMessage: typeof logCopilotKitPlatformMessage; /** Log a `publicApiKeyRequired` warning */
|
|
61
|
-
readonly publicApiKeyRequired: typeof publicApiKeyRequired;
|
|
62
|
-
};
|
|
63
|
-
//#endregion
|
|
64
|
-
export { ConsoleColors, ConsoleStyles, logCopilotKitPlatformMessage, logStyled, publicApiKeyRequired, styledConsole };
|
|
65
|
-
//# sourceMappingURL=console-styling.d.mts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"console-styling.d.mts","names":[],"sources":["../../src/utils/console-styling.ts"],"mappings":";;AAQA;;;;;;cAAa,aAAA;;;+BAoBA;EAAA;;;;;;;;cAAA,aAAA;mGAuB+B;EAAA,wDAAA;EAAA,0DAsB5B;EAAA;uDAAoC;EAAA,8DAyB3B;EAAA,kCAAC;EAAA;;;;;;iBA/CV,4BAAA,CAAA;AAAA,iBAsBA,oBAAA,CAAqB,OAAA;;;;;;;;;;;;;;;iBAyBrB,SAAA,CAAU,QAAA,UAAkB,MAAA;;;;cAO/B,aAAA;;;;;gDAoBH,4BAAA;wCAAA,oBAAA;AAAA"}
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
//#region src/utils/console-styling.ts
|
|
2
|
-
/**
|
|
3
|
-
* Console styling utilities for CopilotKit branded messages
|
|
4
|
-
* Provides consistent, readable colors across light and dark console themes
|
|
5
|
-
*/
|
|
6
|
-
/**
|
|
7
|
-
* Color palette optimized for console readability
|
|
8
|
-
*/
|
|
9
|
-
const ConsoleColors = {
|
|
10
|
-
primary: "#007acc",
|
|
11
|
-
success: "#22c55e",
|
|
12
|
-
feature: "#a855f7",
|
|
13
|
-
cta: "#ef4444",
|
|
14
|
-
info: "#06b6d4",
|
|
15
|
-
inherit: "inherit",
|
|
16
|
-
warning: "#f59e0b"
|
|
17
|
-
};
|
|
18
|
-
/**
|
|
19
|
-
* Console style templates for common patterns
|
|
20
|
-
*/
|
|
21
|
-
const ConsoleStyles = {
|
|
22
|
-
header: `color: ${ConsoleColors.warning}; font-weight: bold; font-size: 16px;`,
|
|
23
|
-
section: `color: ${ConsoleColors.success}; font-weight: bold;`,
|
|
24
|
-
highlight: `color: ${ConsoleColors.feature}; font-weight: bold;`,
|
|
25
|
-
cta: `color: ${ConsoleColors.success}; font-weight: bold;`,
|
|
26
|
-
info: `color: ${ConsoleColors.info}; font-weight: bold;`,
|
|
27
|
-
link: `color: ${ConsoleColors.primary}; text-decoration: underline;`,
|
|
28
|
-
body: `color: ${ConsoleColors.inherit};`,
|
|
29
|
-
warning: `color: ${ConsoleColors.cta}; font-weight: bold;`
|
|
30
|
-
};
|
|
31
|
-
/**
|
|
32
|
-
* Styled console message for CopilotKit Platform promotion
|
|
33
|
-
* Displays a beautiful, branded advertisement in the console
|
|
34
|
-
*/
|
|
35
|
-
function logCopilotKitPlatformMessage() {
|
|
36
|
-
console.log(`%cCopilotKit Warning%c
|
|
37
|
-
|
|
38
|
-
useCopilotChatHeadless_c provides full compatibility with CopilotKit's newly released Headless UI feature set. Headless UI requires a CopilotKit Intelligence license key, available for free at:
|
|
39
|
-
|
|
40
|
-
%chttps://dashboard.operations.copilotkit.ai%c
|
|
41
|
-
|
|
42
|
-
Alternatively, useCopilotChat is available for basic programmatic control, and does not require a license key.
|
|
43
|
-
|
|
44
|
-
To learn more about CopilotKit Intelligence, read the documentation here:
|
|
45
|
-
|
|
46
|
-
%chttps://docs.copilotkit.ai/intelligence/overview%c`, ConsoleStyles.header, ConsoleStyles.body, ConsoleStyles.cta, ConsoleStyles.body, ConsoleStyles.link, ConsoleStyles.body);
|
|
47
|
-
}
|
|
48
|
-
function publicApiKeyRequired(feature) {
|
|
49
|
-
console.log(`
|
|
50
|
-
%cCopilotKit Warning%c \n
|
|
51
|
-
In order to use ${feature}, you need to add your CopilotKit license key, available for free at https://dashboard.operations.copilotkit.ai.
|
|
52
|
-
`.trim(), ConsoleStyles.header, ConsoleStyles.body);
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* Create a styled console message with custom content
|
|
56
|
-
*
|
|
57
|
-
* @param template - Template string with %c placeholders
|
|
58
|
-
* @param styles - Array of style strings matching the %c placeholders
|
|
59
|
-
*
|
|
60
|
-
* @example
|
|
61
|
-
* ```typescript
|
|
62
|
-
* logStyled(
|
|
63
|
-
* '%cCopilotKit%c Welcome to the platform!',
|
|
64
|
-
* [ConsoleStyles.header, ConsoleStyles.body]
|
|
65
|
-
* );
|
|
66
|
-
* ```
|
|
67
|
-
*/
|
|
68
|
-
function logStyled(template, styles) {
|
|
69
|
-
console.log(template, ...styles);
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* Quick styled console methods for common use cases
|
|
73
|
-
*/
|
|
74
|
-
const styledConsole = {
|
|
75
|
-
success: (message) => logStyled(`%c✅ ${message}`, [ConsoleStyles.section]),
|
|
76
|
-
info: (message) => logStyled(`%cℹ️ ${message}`, [ConsoleStyles.info]),
|
|
77
|
-
feature: (message) => logStyled(`%c✨ ${message}`, [ConsoleStyles.highlight]),
|
|
78
|
-
cta: (message) => logStyled(`%c🚀 ${message}`, [ConsoleStyles.cta]),
|
|
79
|
-
logCopilotKitPlatformMessage,
|
|
80
|
-
publicApiKeyRequired
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
//#endregion
|
|
84
|
-
export { ConsoleColors, ConsoleStyles, logCopilotKitPlatformMessage, logStyled, publicApiKeyRequired, styledConsole };
|
|
85
|
-
//# sourceMappingURL=console-styling.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"console-styling.mjs","names":[],"sources":["../../src/utils/console-styling.ts"],"sourcesContent":["/**\n * Console styling utilities for CopilotKit branded messages\n * Provides consistent, readable colors across light and dark console themes\n */\n\n/**\n * Color palette optimized for console readability\n */\nexport const ConsoleColors = {\n /** Primary brand blue - for titles and links */\n primary: \"#007acc\",\n /** Success green - for positive messaging */\n success: \"#22c55e\",\n /** Purple - for feature highlights */\n feature: \"#a855f7\",\n /** Red - for calls-to-action */\n cta: \"#ef4444\",\n /** Cyan - for closing statements */\n info: \"#06b6d4\",\n /** Inherit console default - for body text */\n inherit: \"inherit\",\n /** Warning style */\n warning: \"#f59e0b\",\n} as const;\n\n/**\n * Console style templates for common patterns\n */\nexport const ConsoleStyles = {\n /** Large header style */\n header: `color: ${ConsoleColors.warning}; font-weight: bold; font-size: 16px;`,\n /** Section header style */\n section: `color: ${ConsoleColors.success}; font-weight: bold;`,\n /** Feature highlight style */\n highlight: `color: ${ConsoleColors.feature}; font-weight: bold;`,\n /** Call-to-action style */\n cta: `color: ${ConsoleColors.success}; font-weight: bold;`,\n /** Info style */\n info: `color: ${ConsoleColors.info}; font-weight: bold;`,\n /** Link style */\n link: `color: ${ConsoleColors.primary}; text-decoration: underline;`,\n /** Body text - inherits console theme */\n body: `color: ${ConsoleColors.inherit};`,\n /** Warning style */\n warning: `color: ${ConsoleColors.cta}; font-weight: bold;`,\n} as const;\n\n/**\n * Styled console message for CopilotKit Platform promotion\n * Displays a beautiful, branded advertisement in the console\n */\nexport function logCopilotKitPlatformMessage() {\n console.log(\n `%cCopilotKit Warning%c\n\nuseCopilotChatHeadless_c provides full compatibility with CopilotKit's newly released Headless UI feature set. Headless UI requires a CopilotKit Intelligence license key, available for free at:\n\n%chttps://dashboard.operations.copilotkit.ai%c\n\nAlternatively, useCopilotChat is available for basic programmatic control, and does not require a license key.\n\nTo learn more about CopilotKit Intelligence, read the documentation here:\n\n%chttps://docs.copilotkit.ai/intelligence/overview%c`,\n ConsoleStyles.header,\n ConsoleStyles.body,\n ConsoleStyles.cta,\n ConsoleStyles.body,\n ConsoleStyles.link,\n ConsoleStyles.body,\n );\n}\n\nexport function publicApiKeyRequired(feature: string) {\n console.log(\n `\n%cCopilotKit Warning%c \\n\nIn order to use ${feature}, you need to add your CopilotKit license key, available for free at https://dashboard.operations.copilotkit.ai.\n `.trim(),\n ConsoleStyles.header,\n ConsoleStyles.body,\n );\n}\n\n/**\n * Create a styled console message with custom content\n *\n * @param template - Template string with %c placeholders\n * @param styles - Array of style strings matching the %c placeholders\n *\n * @example\n * ```typescript\n * logStyled(\n * '%cCopilotKit%c Welcome to the platform!',\n * [ConsoleStyles.header, ConsoleStyles.body]\n * );\n * ```\n */\nexport function logStyled(template: string, styles: string[]) {\n console.log(template, ...styles);\n}\n\n/**\n * Quick styled console methods for common use cases\n */\nexport const styledConsole = {\n /** Log a success message */\n success: (message: string) =>\n logStyled(`%c✅ ${message}`, [ConsoleStyles.section]),\n\n /** Log an info message */\n info: (message: string) => logStyled(`%cℹ️ ${message}`, [ConsoleStyles.info]),\n\n /** Log a feature highlight */\n feature: (message: string) =>\n logStyled(`%c✨ ${message}`, [ConsoleStyles.highlight]),\n\n /** Log a call-to-action */\n cta: (message: string) => logStyled(`%c🚀 ${message}`, [ConsoleStyles.cta]),\n\n /** Log the CopilotKit platform promotion */\n logCopilotKitPlatformMessage: logCopilotKitPlatformMessage,\n\n /** Log a `publicApiKeyRequired` warning */\n publicApiKeyRequired: publicApiKeyRequired,\n} as const;\n"],"mappings":";;;;;;;;AAQA,MAAa,gBAAgB;CAE3B,SAAS;CAET,SAAS;CAET,SAAS;CAET,KAAK;CAEL,MAAM;CAEN,SAAS;CAET,SAAS;CACV;;;;AAKD,MAAa,gBAAgB;CAE3B,QAAQ,UAAU,cAAc,QAAQ;CAExC,SAAS,UAAU,cAAc,QAAQ;CAEzC,WAAW,UAAU,cAAc,QAAQ;CAE3C,KAAK,UAAU,cAAc,QAAQ;CAErC,MAAM,UAAU,cAAc,KAAK;CAEnC,MAAM,UAAU,cAAc,QAAQ;CAEtC,MAAM,UAAU,cAAc,QAAQ;CAEtC,SAAS,UAAU,cAAc,IAAI;CACtC;;;;;AAMD,SAAgB,+BAA+B;AAC7C,SAAQ,IACN;;;;;;;;;;uDAWA,cAAc,QACd,cAAc,MACd,cAAc,KACd,cAAc,MACd,cAAc,MACd,cAAc,KACf;;AAGH,SAAgB,qBAAqB,SAAiB;AACpD,SAAQ,IACN;;kBAEc,QAAQ;MACpB,MAAM,EACR,cAAc,QACd,cAAc,KACf;;;;;;;;;;;;;;;;AAiBH,SAAgB,UAAU,UAAkB,QAAkB;AAC5D,SAAQ,IAAI,UAAU,GAAG,OAAO;;;;;AAMlC,MAAa,gBAAgB;CAE3B,UAAU,YACR,UAAU,OAAO,WAAW,CAAC,cAAc,QAAQ,CAAC;CAGtD,OAAO,YAAoB,UAAU,QAAQ,WAAW,CAAC,cAAc,KAAK,CAAC;CAG7E,UAAU,YACR,UAAU,OAAO,WAAW,CAAC,cAAc,UAAU,CAAC;CAGxD,MAAM,YAAoB,UAAU,QAAQ,WAAW,CAAC,cAAc,IAAI,CAAC;CAG7C;CAGR;CACvB"}
|
|
@@ -1,161 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from "vitest";
|
|
2
|
-
import {
|
|
3
|
-
executeConditions,
|
|
4
|
-
Condition,
|
|
5
|
-
ComparisonCondition,
|
|
6
|
-
LogicalCondition,
|
|
7
|
-
ExistenceCondition,
|
|
8
|
-
} from "../conditions";
|
|
9
|
-
|
|
10
|
-
describe("executeConditions", () => {
|
|
11
|
-
it("returns true when conditions is empty or undefined", () => {
|
|
12
|
-
expect(executeConditions({ value: { a: 1 } })).toBe(true);
|
|
13
|
-
expect(executeConditions({ conditions: [], value: { a: 1 } })).toBe(true);
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
it("treats multiple conditions as an implicit AND", () => {
|
|
17
|
-
const conditions: Condition[] = [
|
|
18
|
-
{ rule: "EQUALS", path: "a", value: 1 },
|
|
19
|
-
{ rule: "EQUALS", path: "b", value: 2 },
|
|
20
|
-
];
|
|
21
|
-
expect(executeConditions({ conditions, value: { a: 1, b: 2 } })).toBe(true);
|
|
22
|
-
expect(executeConditions({ conditions, value: { a: 1, b: 3 } })).toBe(false);
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
describe("comparison rules", () => {
|
|
26
|
-
it("EQUALS and NOT_EQUALS", () => {
|
|
27
|
-
const eq: ComparisonCondition = { rule: "EQUALS", path: "a", value: 5 };
|
|
28
|
-
const neq: ComparisonCondition = { rule: "NOT_EQUALS", path: "a", value: 5 };
|
|
29
|
-
expect(executeConditions({ conditions: [eq], value: { a: 5 } })).toBe(true);
|
|
30
|
-
expect(executeConditions({ conditions: [eq], value: { a: 6 } })).toBe(false);
|
|
31
|
-
expect(executeConditions({ conditions: [neq], value: { a: 6 } })).toBe(true);
|
|
32
|
-
expect(executeConditions({ conditions: [neq], value: { a: 5 } })).toBe(false);
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
it("GREATER_THAN and LESS_THAN", () => {
|
|
36
|
-
const gt: ComparisonCondition = { rule: "GREATER_THAN", path: "n", value: 10 };
|
|
37
|
-
const lt: ComparisonCondition = { rule: "LESS_THAN", path: "n", value: 10 };
|
|
38
|
-
expect(executeConditions({ conditions: [gt], value: { n: 11 } })).toBe(true);
|
|
39
|
-
expect(executeConditions({ conditions: [gt], value: { n: 10 } })).toBe(false);
|
|
40
|
-
expect(executeConditions({ conditions: [lt], value: { n: 9 } })).toBe(true);
|
|
41
|
-
expect(executeConditions({ conditions: [lt], value: { n: 10 } })).toBe(false);
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
it("CONTAINS and NOT_CONTAINS only apply to arrays", () => {
|
|
45
|
-
const contains: ComparisonCondition = { rule: "CONTAINS", path: "tags", value: "ts" };
|
|
46
|
-
const notContains: ComparisonCondition = { rule: "NOT_CONTAINS", path: "tags", value: "ts" };
|
|
47
|
-
expect(
|
|
48
|
-
executeConditions({ conditions: [contains], value: { tags: ["js", "ts"] } }),
|
|
49
|
-
).toBe(true);
|
|
50
|
-
expect(
|
|
51
|
-
executeConditions({ conditions: [contains], value: { tags: ["js"] } }),
|
|
52
|
-
).toBe(false);
|
|
53
|
-
expect(
|
|
54
|
-
executeConditions({ conditions: [notContains], value: { tags: ["js"] } }),
|
|
55
|
-
).toBe(true);
|
|
56
|
-
// non-array target always fails both CONTAINS and NOT_CONTAINS
|
|
57
|
-
expect(
|
|
58
|
-
executeConditions({ conditions: [contains], value: { tags: "ts" } }),
|
|
59
|
-
).toBe(false);
|
|
60
|
-
expect(
|
|
61
|
-
executeConditions({ conditions: [notContains], value: { tags: "ts" } }),
|
|
62
|
-
).toBe(false);
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
it("MATCHES uses the value as a regular expression", () => {
|
|
66
|
-
const matches: ComparisonCondition = { rule: "MATCHES", path: "code", value: "^CK-[0-9]+$" };
|
|
67
|
-
expect(executeConditions({ conditions: [matches], value: { code: "CK-123" } })).toBe(true);
|
|
68
|
-
expect(executeConditions({ conditions: [matches], value: { code: "nope" } })).toBe(false);
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
it("STARTS_WITH and ENDS_WITH", () => {
|
|
72
|
-
const sw: ComparisonCondition = { rule: "STARTS_WITH", path: "s", value: "foo" };
|
|
73
|
-
const ew: ComparisonCondition = { rule: "ENDS_WITH", path: "s", value: "bar" };
|
|
74
|
-
expect(executeConditions({ conditions: [sw], value: { s: "foobar" } })).toBe(true);
|
|
75
|
-
expect(executeConditions({ conditions: [sw], value: { s: "barfoo" } })).toBe(false);
|
|
76
|
-
expect(executeConditions({ conditions: [ew], value: { s: "foobar" } })).toBe(true);
|
|
77
|
-
expect(executeConditions({ conditions: [ew], value: { s: "barfoo" } })).toBe(false);
|
|
78
|
-
});
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
describe("existence rules", () => {
|
|
82
|
-
it("EXISTS passes only for defined non-null values", () => {
|
|
83
|
-
const exists: ExistenceCondition = { rule: "EXISTS", path: "a" };
|
|
84
|
-
expect(executeConditions({ conditions: [exists], value: { a: 0 } })).toBe(true);
|
|
85
|
-
expect(executeConditions({ conditions: [exists], value: { a: "" } })).toBe(true);
|
|
86
|
-
expect(executeConditions({ conditions: [exists], value: { a: false } })).toBe(true);
|
|
87
|
-
expect(executeConditions({ conditions: [exists], value: { a: null } })).toBe(false);
|
|
88
|
-
expect(executeConditions({ conditions: [exists], value: {} })).toBe(false);
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
it("NOT_EXISTS is the inverse of EXISTS", () => {
|
|
92
|
-
const notExists: ExistenceCondition = { rule: "NOT_EXISTS", path: "a" };
|
|
93
|
-
expect(executeConditions({ conditions: [notExists], value: { a: 1 } })).toBe(false);
|
|
94
|
-
expect(executeConditions({ conditions: [notExists], value: { a: null } })).toBe(true);
|
|
95
|
-
expect(executeConditions({ conditions: [notExists], value: {} })).toBe(true);
|
|
96
|
-
});
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
describe("logical rules", () => {
|
|
100
|
-
it("AND requires all nested conditions to pass", () => {
|
|
101
|
-
const and: LogicalCondition = {
|
|
102
|
-
rule: "AND",
|
|
103
|
-
conditions: [
|
|
104
|
-
{ rule: "EQUALS", path: "a", value: 1 },
|
|
105
|
-
{ rule: "EQUALS", path: "b", value: 2 },
|
|
106
|
-
],
|
|
107
|
-
};
|
|
108
|
-
expect(executeConditions({ conditions: [and], value: { a: 1, b: 2 } })).toBe(true);
|
|
109
|
-
expect(executeConditions({ conditions: [and], value: { a: 1, b: 3 } })).toBe(false);
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
it("OR passes when any nested condition passes", () => {
|
|
113
|
-
const or: LogicalCondition = {
|
|
114
|
-
rule: "OR",
|
|
115
|
-
conditions: [
|
|
116
|
-
{ rule: "EQUALS", path: "a", value: 1 },
|
|
117
|
-
{ rule: "EQUALS", path: "b", value: 2 },
|
|
118
|
-
],
|
|
119
|
-
};
|
|
120
|
-
expect(executeConditions({ conditions: [or], value: { a: 9, b: 2 } })).toBe(true);
|
|
121
|
-
expect(executeConditions({ conditions: [or], value: { a: 9, b: 9 } })).toBe(false);
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
it("NOT inverts the AND of nested conditions", () => {
|
|
125
|
-
const notAll: LogicalCondition = {
|
|
126
|
-
rule: "NOT",
|
|
127
|
-
conditions: [
|
|
128
|
-
{ rule: "EQUALS", path: "a", value: 1 },
|
|
129
|
-
{ rule: "EQUALS", path: "b", value: 2 },
|
|
130
|
-
],
|
|
131
|
-
};
|
|
132
|
-
// both true → NOT(AND) = false
|
|
133
|
-
expect(executeConditions({ conditions: [notAll], value: { a: 1, b: 2 } })).toBe(false);
|
|
134
|
-
// one false → NOT(AND) = true
|
|
135
|
-
expect(executeConditions({ conditions: [notAll], value: { a: 1, b: 3 } })).toBe(true);
|
|
136
|
-
});
|
|
137
|
-
});
|
|
138
|
-
|
|
139
|
-
describe("path resolution", () => {
|
|
140
|
-
it("resolves nested dot paths", () => {
|
|
141
|
-
const cond: ComparisonCondition = { rule: "EQUALS", path: "user.profile.age", value: 30 };
|
|
142
|
-
expect(
|
|
143
|
-
executeConditions({ conditions: [cond], value: { user: { profile: { age: 30 } } } }),
|
|
144
|
-
).toBe(true);
|
|
145
|
-
expect(
|
|
146
|
-
executeConditions({ conditions: [cond], value: { user: { profile: { age: 31 } } } }),
|
|
147
|
-
).toBe(false);
|
|
148
|
-
});
|
|
149
|
-
|
|
150
|
-
it("returns false for a missing nested path (undefined target)", () => {
|
|
151
|
-
const eq: ComparisonCondition = { rule: "EQUALS", path: "a.b.c", value: 1 };
|
|
152
|
-
expect(executeConditions({ conditions: [eq], value: {} })).toBe(false);
|
|
153
|
-
});
|
|
154
|
-
|
|
155
|
-
it("uses the whole value when no path is given", () => {
|
|
156
|
-
const eq: ComparisonCondition = { rule: "EQUALS", value: 42 };
|
|
157
|
-
expect(executeConditions({ conditions: [eq], value: 42 })).toBe(true);
|
|
158
|
-
expect(executeConditions({ conditions: [eq], value: 43 })).toBe(false);
|
|
159
|
-
});
|
|
160
|
-
});
|
|
161
|
-
});
|
package/src/utils/conditions.ts
DELETED
|
@@ -1,116 +0,0 @@
|
|
|
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 =
|
|
36
|
-
| ComparisonCondition
|
|
37
|
-
| LogicalCondition
|
|
38
|
-
| ExistenceCondition;
|
|
39
|
-
|
|
40
|
-
export function executeConditions({
|
|
41
|
-
conditions,
|
|
42
|
-
value,
|
|
43
|
-
}: {
|
|
44
|
-
conditions?: Condition[];
|
|
45
|
-
value: any;
|
|
46
|
-
}): boolean {
|
|
47
|
-
// If no conditions, consider it a pass
|
|
48
|
-
if (!conditions?.length) return true;
|
|
49
|
-
|
|
50
|
-
// Run all conditions (implicit AND)
|
|
51
|
-
return conditions.every((condition) => executeCondition(condition, value));
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
function executeCondition(condition: Condition, value: any): boolean {
|
|
55
|
-
const targetValue = condition.path
|
|
56
|
-
? getValueFromPath(value, condition.path)
|
|
57
|
-
: value;
|
|
58
|
-
|
|
59
|
-
switch (condition.rule) {
|
|
60
|
-
// Logical
|
|
61
|
-
case "AND":
|
|
62
|
-
return (condition as LogicalCondition).conditions.every((c) =>
|
|
63
|
-
executeCondition(c, value),
|
|
64
|
-
);
|
|
65
|
-
case "OR":
|
|
66
|
-
return (condition as LogicalCondition).conditions.some((c) =>
|
|
67
|
-
executeCondition(c, value),
|
|
68
|
-
);
|
|
69
|
-
case "NOT":
|
|
70
|
-
return !(condition as LogicalCondition).conditions.every((c) =>
|
|
71
|
-
executeCondition(c, value),
|
|
72
|
-
);
|
|
73
|
-
|
|
74
|
-
// Comparison
|
|
75
|
-
case "EQUALS":
|
|
76
|
-
return targetValue === (condition as ComparisonCondition).value;
|
|
77
|
-
case "NOT_EQUALS":
|
|
78
|
-
return targetValue !== (condition as ComparisonCondition).value;
|
|
79
|
-
case "GREATER_THAN":
|
|
80
|
-
return targetValue > (condition as ComparisonCondition).value;
|
|
81
|
-
case "LESS_THAN":
|
|
82
|
-
return targetValue < (condition as ComparisonCondition).value;
|
|
83
|
-
case "CONTAINS":
|
|
84
|
-
return (
|
|
85
|
-
Array.isArray(targetValue) &&
|
|
86
|
-
targetValue.includes((condition as ComparisonCondition).value)
|
|
87
|
-
);
|
|
88
|
-
case "NOT_CONTAINS":
|
|
89
|
-
return (
|
|
90
|
-
Array.isArray(targetValue) &&
|
|
91
|
-
!targetValue.includes((condition as ComparisonCondition).value)
|
|
92
|
-
);
|
|
93
|
-
case "MATCHES":
|
|
94
|
-
return new RegExp((condition as ComparisonCondition).value).test(
|
|
95
|
-
String(targetValue),
|
|
96
|
-
);
|
|
97
|
-
case "STARTS_WITH":
|
|
98
|
-
return String(targetValue).startsWith(
|
|
99
|
-
(condition as ComparisonCondition).value,
|
|
100
|
-
);
|
|
101
|
-
case "ENDS_WITH":
|
|
102
|
-
return String(targetValue).endsWith(
|
|
103
|
-
(condition as ComparisonCondition).value,
|
|
104
|
-
);
|
|
105
|
-
|
|
106
|
-
// Existence
|
|
107
|
-
case "EXISTS":
|
|
108
|
-
return targetValue !== undefined && targetValue !== null;
|
|
109
|
-
case "NOT_EXISTS":
|
|
110
|
-
return targetValue === undefined || targetValue === null;
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
function getValueFromPath(obj: any, path: string): any {
|
|
115
|
-
return path.split(".").reduce((acc, part) => acc?.[part], obj);
|
|
116
|
-
}
|
|
@@ -1,126 +0,0 @@
|
|
|
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. Headless UI requires a CopilotKit Intelligence license key, available for free at:
|
|
57
|
-
|
|
58
|
-
%chttps://dashboard.operations.copilotkit.ai%c
|
|
59
|
-
|
|
60
|
-
Alternatively, useCopilotChat is available for basic programmatic control, and does not require a license key.
|
|
61
|
-
|
|
62
|
-
To learn more about CopilotKit Intelligence, read the documentation here:
|
|
63
|
-
|
|
64
|
-
%chttps://docs.copilotkit.ai/intelligence/overview%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 license key, available for free at https://dashboard.operations.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) =>
|
|
109
|
-
logStyled(`%c✅ ${message}`, [ConsoleStyles.section]),
|
|
110
|
-
|
|
111
|
-
/** Log an info message */
|
|
112
|
-
info: (message: string) => logStyled(`%cℹ️ ${message}`, [ConsoleStyles.info]),
|
|
113
|
-
|
|
114
|
-
/** Log a feature highlight */
|
|
115
|
-
feature: (message: string) =>
|
|
116
|
-
logStyled(`%c✨ ${message}`, [ConsoleStyles.highlight]),
|
|
117
|
-
|
|
118
|
-
/** Log a call-to-action */
|
|
119
|
-
cta: (message: string) => logStyled(`%c🚀 ${message}`, [ConsoleStyles.cta]),
|
|
120
|
-
|
|
121
|
-
/** Log the CopilotKit platform promotion */
|
|
122
|
-
logCopilotKitPlatformMessage: logCopilotKitPlatformMessage,
|
|
123
|
-
|
|
124
|
-
/** Log a `publicApiKeyRequired` warning */
|
|
125
|
-
publicApiKeyRequired: publicApiKeyRequired,
|
|
126
|
-
} as const;
|