@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.
- package/CHANGELOG.md +1800 -0
- package/LICENSE +21 -0
- package/README.md +141 -0
- package/dist/chunk-2OJ5OJ2D.mjs +1 -0
- package/dist/chunk-2OJ5OJ2D.mjs.map +1 -0
- package/dist/chunk-5YXKLIUO.mjs +38 -0
- package/dist/chunk-5YXKLIUO.mjs.map +1 -0
- package/dist/chunk-64DYJ27R.mjs +201 -0
- package/dist/chunk-64DYJ27R.mjs.map +1 -0
- package/dist/chunk-6QGXWNS5.mjs +34 -0
- package/dist/chunk-6QGXWNS5.mjs.map +1 -0
- package/dist/chunk-6W2UEO2M.mjs +94 -0
- package/dist/chunk-6W2UEO2M.mjs.map +1 -0
- package/dist/chunk-BOKE4OKY.mjs +41 -0
- package/dist/chunk-BOKE4OKY.mjs.map +1 -0
- package/dist/chunk-FCCOSO5L.mjs +1 -0
- package/dist/chunk-FCCOSO5L.mjs.map +1 -0
- package/dist/chunk-GYZIHHE6.mjs +13 -0
- package/dist/chunk-GYZIHHE6.mjs.map +1 -0
- package/dist/chunk-IAFBVORQ.mjs +1 -0
- package/dist/chunk-IAFBVORQ.mjs.map +1 -0
- package/dist/chunk-MSUB6DGR.mjs +1 -0
- package/dist/chunk-MSUB6DGR.mjs.map +1 -0
- package/dist/chunk-N5EP5OD5.mjs +1 -0
- package/dist/chunk-N5EP5OD5.mjs.map +1 -0
- package/dist/chunk-NAFEBKSO.mjs +1 -0
- package/dist/chunk-NAFEBKSO.mjs.map +1 -0
- package/dist/chunk-NBLG4PC5.mjs +426 -0
- package/dist/chunk-NBLG4PC5.mjs.map +1 -0
- package/dist/chunk-P7STFMPO.mjs +1 -0
- package/dist/chunk-P7STFMPO.mjs.map +1 -0
- package/dist/chunk-PL5WNHFZ.mjs +50 -0
- package/dist/chunk-PL5WNHFZ.mjs.map +1 -0
- package/dist/chunk-UYARLQNA.mjs +1 -0
- package/dist/chunk-UYARLQNA.mjs.map +1 -0
- package/dist/chunk-WUPFNPXO.mjs +107 -0
- package/dist/chunk-WUPFNPXO.mjs.map +1 -0
- package/dist/chunk-XEMZTHQZ.mjs +67 -0
- package/dist/chunk-XEMZTHQZ.mjs.map +1 -0
- package/dist/chunk-XTHC46M2.mjs +1 -0
- package/dist/chunk-XTHC46M2.mjs.map +1 -0
- package/dist/constants/index.d.ts +6 -0
- package/dist/constants/index.js +40 -0
- package/dist/constants/index.js.map +1 -0
- package/dist/constants/index.mjs +13 -0
- package/dist/constants/index.mjs.map +1 -0
- package/dist/index.d.ts +25 -0
- package/dist/index.js +1098 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +124 -0
- package/dist/index.mjs.map +1 -0
- package/dist/telemetry/events.d.ts +45 -0
- package/dist/telemetry/events.js +19 -0
- package/dist/telemetry/events.js.map +1 -0
- package/dist/telemetry/events.mjs +1 -0
- package/dist/telemetry/events.mjs.map +1 -0
- package/dist/telemetry/index.d.ts +3 -0
- package/dist/telemetry/index.js +188 -0
- package/dist/telemetry/index.js.map +1 -0
- package/dist/telemetry/index.mjs +12 -0
- package/dist/telemetry/index.mjs.map +1 -0
- package/dist/telemetry/scarf-client.d.ts +7 -0
- package/dist/telemetry/scarf-client.js +59 -0
- package/dist/telemetry/scarf-client.js.map +1 -0
- package/dist/telemetry/scarf-client.mjs +7 -0
- package/dist/telemetry/scarf-client.mjs.map +1 -0
- package/dist/telemetry/security-check.d.ts +2 -0
- package/dist/telemetry/security-check.js +2 -0
- package/dist/telemetry/security-check.js.map +1 -0
- package/dist/telemetry/security-check.mjs +1 -0
- package/dist/telemetry/security-check.mjs.map +1 -0
- package/dist/telemetry/telemetry-client.d.ts +40 -0
- package/dist/telemetry/telemetry-client.js +186 -0
- package/dist/telemetry/telemetry-client.js.map +1 -0
- package/dist/telemetry/telemetry-client.mjs +11 -0
- package/dist/telemetry/telemetry-client.mjs.map +1 -0
- package/dist/telemetry/utils.d.ts +8 -0
- package/dist/telemetry/utils.js +69 -0
- package/dist/telemetry/utils.js.map +1 -0
- package/dist/telemetry/utils.mjs +9 -0
- package/dist/telemetry/utils.mjs.map +1 -0
- package/dist/types/action.d.ts +59 -0
- package/dist/types/action.js +19 -0
- package/dist/types/action.js.map +1 -0
- package/dist/types/action.mjs +2 -0
- package/dist/types/action.mjs.map +1 -0
- package/dist/types/copilot-cloud-config.d.ts +13 -0
- package/dist/types/copilot-cloud-config.js +19 -0
- package/dist/types/copilot-cloud-config.js.map +1 -0
- package/dist/types/copilot-cloud-config.mjs +2 -0
- package/dist/types/copilot-cloud-config.mjs.map +1 -0
- package/dist/types/error.d.ts +55 -0
- package/dist/types/error.js +19 -0
- package/dist/types/error.js.map +1 -0
- package/dist/types/error.mjs +2 -0
- package/dist/types/error.mjs.map +1 -0
- package/dist/types/index.d.ts +7 -0
- package/dist/types/index.js +19 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/index.mjs +8 -0
- package/dist/types/index.mjs.map +1 -0
- package/dist/types/message.d.ts +26 -0
- package/dist/types/message.js +19 -0
- package/dist/types/message.js.map +1 -0
- package/dist/types/message.mjs +2 -0
- package/dist/types/message.mjs.map +1 -0
- package/dist/types/openai-assistant.d.ts +53 -0
- package/dist/types/openai-assistant.js +19 -0
- package/dist/types/openai-assistant.js.map +1 -0
- package/dist/types/openai-assistant.mjs +2 -0
- package/dist/types/openai-assistant.mjs.map +1 -0
- package/dist/types/utility.d.ts +6 -0
- package/dist/types/utility.js +19 -0
- package/dist/types/utility.js.map +1 -0
- package/dist/types/utility.mjs +2 -0
- package/dist/types/utility.mjs.map +1 -0
- package/dist/utils/conditions.d.ts +26 -0
- package/dist/utils/conditions.js +74 -0
- package/dist/utils/conditions.js.map +1 -0
- package/dist/utils/conditions.mjs +7 -0
- package/dist/utils/conditions.mjs.map +1 -0
- package/dist/utils/console-styling.d.ts +84 -0
- package/dist/utils/console-styling.js +123 -0
- package/dist/utils/console-styling.js.map +1 -0
- package/dist/utils/console-styling.mjs +17 -0
- package/dist/utils/console-styling.mjs.map +1 -0
- package/dist/utils/errors.d.ts +280 -0
- package/dist/utils/errors.js +443 -0
- package/dist/utils/errors.js.map +1 -0
- package/dist/utils/errors.mjs +65 -0
- package/dist/utils/errors.mjs.map +1 -0
- package/dist/utils/index.d.ts +32 -0
- package/dist/utils/index.js +927 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/index.mjs +108 -0
- package/dist/utils/index.mjs.map +1 -0
- package/dist/utils/json-schema.d.ts +34 -0
- package/dist/utils/json-schema.js +228 -0
- package/dist/utils/json-schema.js.map +1 -0
- package/dist/utils/json-schema.mjs +13 -0
- package/dist/utils/json-schema.mjs.map +1 -0
- package/dist/utils/random-id.d.ts +6 -0
- package/dist/utils/random-id.js +68 -0
- package/dist/utils/random-id.js.map +1 -0
- package/dist/utils/random-id.mjs +13 -0
- package/dist/utils/random-id.mjs.map +1 -0
- package/dist/utils/requests.d.ts +10 -0
- package/dist/utils/requests.js +91 -0
- package/dist/utils/requests.js.map +1 -0
- package/dist/utils/requests.mjs +7 -0
- package/dist/utils/requests.mjs.map +1 -0
- package/dist/utils/types.d.ts +20 -0
- package/dist/utils/types.js +19 -0
- package/dist/utils/types.js.map +1 -0
- package/dist/utils/types.mjs +2 -0
- package/dist/utils/types.mjs.map +1 -0
- package/jest.config.js +5 -0
- package/package.json +68 -0
- package/src/constants/index.ts +4 -0
- package/src/index.ts +7 -0
- package/src/telemetry/events.ts +41 -0
- package/src/telemetry/index.ts +1 -0
- package/src/telemetry/scarf-client.ts +39 -0
- package/src/telemetry/security-check.ts +0 -0
- package/src/telemetry/telemetry-client.ts +142 -0
- package/src/telemetry/utils.ts +39 -0
- package/src/types/action.ts +129 -0
- package/src/types/copilot-cloud-config.ts +11 -0
- package/src/types/error.ts +70 -0
- package/src/types/index.ts +6 -0
- package/src/types/message.ts +37 -0
- package/src/types/openai-assistant.ts +62 -0
- package/src/types/utility.ts +2 -0
- package/src/utils/conditions.ts +98 -0
- package/src/utils/console-styling.ts +124 -0
- package/src/utils/errors.ts +525 -0
- package/src/utils/index.ts +49 -0
- package/src/utils/json-schema.test.ts +383 -0
- package/src/utils/json-schema.ts +258 -0
- package/src/utils/random-id.ts +42 -0
- package/src/utils/requests.ts +77 -0
- package/src/utils/types.ts +22 -0
- package/tsconfig.json +9 -0
- package/tsup.config.ts +11 -0
- 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,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,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,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;
|