@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
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) Atai Barkai
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
# CopilotKit - Shared
|
|
2
|
+
|
|
3
|
+
<img src="https://github.com/user-attachments/assets/0a6b64d9-e193-4940-a3f6-60334ac34084" alt="banner" style="border-radius: 12px; border: 2px solid #d6d4fa;" />
|
|
4
|
+
|
|
5
|
+
<br>
|
|
6
|
+
<div align="center" style="display:flex;justify-content:center;gap:16px;height:20px;margin: 0;">
|
|
7
|
+
<a href="https://www.npmjs.com/package/@copilotkit/react-core" target="_blank">
|
|
8
|
+
<img src="https://img.shields.io/npm/v/%40copilotkit%2Fshared?logo=npm&logoColor=%23FFFFFF&label=Version&color=%236963ff" alt="NPM">
|
|
9
|
+
</a>
|
|
10
|
+
<a href="https://github.com/copilotkit/copilotkit/blob/main/LICENSE" target="_blank">
|
|
11
|
+
<img src="https://img.shields.io/github/license/copilotkit/copilotkit?color=%236963ff&label=License" alt="MIT">
|
|
12
|
+
</a>
|
|
13
|
+
<a href="https://discord.gg/6dffbvGU3D" target="_blank">
|
|
14
|
+
<img src="https://img.shields.io/discord/1122926057641742418?logo=discord&logoColor=%23FFFFFF&label=Discord&color=%236963ff" alt="Discord">
|
|
15
|
+
</a>
|
|
16
|
+
</div>
|
|
17
|
+
<br/>
|
|
18
|
+
<div align="center">
|
|
19
|
+
<a href="https://www.producthunt.com/posts/copilotkit" target="_blank">
|
|
20
|
+
<img src="https://api.producthunt.com/widgets/embed-image/v1/top-post-badge.svg?post_id=428778&theme=light&period=daily">
|
|
21
|
+
</a>
|
|
22
|
+
</div>
|
|
23
|
+
|
|
24
|
+
## ✨ Why CopilotKit?
|
|
25
|
+
|
|
26
|
+
- Minutes to integrate - Get started quickly with our CLI
|
|
27
|
+
- Framework agnostic - Works with React, Next.js, AGUI and more
|
|
28
|
+
- Production-ready UI - Use customizable components or build with headless UI
|
|
29
|
+
- Built-in security - Prompt injection protection
|
|
30
|
+
- Open source - Full transparency and community-driven
|
|
31
|
+
|
|
32
|
+
<img src="https://github.com/user-attachments/assets/6cb425f8-ffcb-49d2-9bbb-87cab5995b78" alt="class-support-ecosystem" style="border-radius: 12px; border: 2px solid #d6d4fa;">
|
|
33
|
+
|
|
34
|
+
## 🧑💻 Real life use cases
|
|
35
|
+
|
|
36
|
+
<span>Deploy deeply-integrated AI assistants & agents that work alongside your users inside your applications.</span>
|
|
37
|
+
|
|
38
|
+
<img src="https://github.com/user-attachments/assets/3b810240-e9f8-43ae-acec-31a58095e223" alt="headless-ui" style="border-radius: 12px; border: 2px solid #d6d4fa;">
|
|
39
|
+
|
|
40
|
+
## 🖥️ Code Samples
|
|
41
|
+
|
|
42
|
+
<span>Drop in these building blocks and tailor them to your needs.</span>
|
|
43
|
+
|
|
44
|
+
<h3>Build with Headless APIs and Pre-Built Components</h3>
|
|
45
|
+
|
|
46
|
+
```ts
|
|
47
|
+
// Headless UI with full control
|
|
48
|
+
const { visibleMessages, appendMessage, setMessages, ... } = useCopilotChat();
|
|
49
|
+
|
|
50
|
+
// Pre-built components with deep customization options (CSS + pass custom sub-components)
|
|
51
|
+
<CopilotPopup
|
|
52
|
+
instructions={"You are assisting the user as best as you can. Answer in the best way possible given the data you have."}
|
|
53
|
+
labels={{ title: "Popup Assistant", initial: "Need any help?" }}
|
|
54
|
+
/>
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
```ts
|
|
58
|
+
// Frontend actions + generative UI, with full streaming support
|
|
59
|
+
useCopilotAction({
|
|
60
|
+
name: "appendToSpreadsheet",
|
|
61
|
+
description: "Append rows to the current spreadsheet",
|
|
62
|
+
parameters: [
|
|
63
|
+
{ name: "rows", type: "object[]", attributes: [{ name: "cells", type: "object[]", attributes: [{ name: "value", type: "string" }] }] }
|
|
64
|
+
],
|
|
65
|
+
render: ({ status, args }) => <Spreadsheet data={canonicalSpreadsheetData(args.rows)} />,
|
|
66
|
+
handler: ({ rows }) => setSpreadsheet({ ...spreadsheet, rows: [...spreadsheet.rows, ...canonicalSpreadsheetData(rows)] }),
|
|
67
|
+
});
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
<h3>Integrate In-App CoAgents with LangGraph</h3>
|
|
71
|
+
|
|
72
|
+
```ts
|
|
73
|
+
// Share state between app and agent
|
|
74
|
+
const { agentState } = useCoAgent({
|
|
75
|
+
name: "basic_agent",
|
|
76
|
+
initialState: { input: "NYC" }
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
// agentic generative UI
|
|
80
|
+
useCoAgentStateRender({
|
|
81
|
+
name: "basic_agent",
|
|
82
|
+
render: ({ state }) => <WeatherDisplay {...state.final_response} />,
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
// Human in the Loop (Approval)
|
|
86
|
+
useCopilotAction({
|
|
87
|
+
name: "email_tool",
|
|
88
|
+
parameters: [
|
|
89
|
+
{
|
|
90
|
+
name: "email_draft",
|
|
91
|
+
type: "string",
|
|
92
|
+
description: "The email content",
|
|
93
|
+
required: true,
|
|
94
|
+
},
|
|
95
|
+
],
|
|
96
|
+
renderAndWaitForResponse: ({ args, status, respond }) => {
|
|
97
|
+
return (
|
|
98
|
+
<EmailConfirmation
|
|
99
|
+
emailContent={args.email_draft || ""}
|
|
100
|
+
isExecuting={status === "executing"}
|
|
101
|
+
onCancel={() => respond?.({ approved: false })}
|
|
102
|
+
onSend={() =>
|
|
103
|
+
respond?.({
|
|
104
|
+
approved: true,
|
|
105
|
+
metadata: { sentAt: new Date().toISOString() },
|
|
106
|
+
})
|
|
107
|
+
}
|
|
108
|
+
/>
|
|
109
|
+
);
|
|
110
|
+
},
|
|
111
|
+
});
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
```ts
|
|
115
|
+
// intermediate agent state streaming (supports both LangGraph.js + LangGraph python)
|
|
116
|
+
const modifiedConfig = copilotKitCustomizeConfig(config, {
|
|
117
|
+
emitIntermediateState: [{
|
|
118
|
+
stateKey: "outline",
|
|
119
|
+
tool: "set_outline",
|
|
120
|
+
toolArgument: "outline"
|
|
121
|
+
}],
|
|
122
|
+
});
|
|
123
|
+
const response = await ChatOpenAI({ model: "gpt-4o" }).invoke(messages, modifiedConfig);
|
|
124
|
+
```
|
|
125
|
+
## 🏆 Featured Examples
|
|
126
|
+
|
|
127
|
+
<p align="center">
|
|
128
|
+
<a href="https://www.copilotkit.ai/examples/form-filling-copilot">
|
|
129
|
+
<img src="https://github.com/user-attachments/assets/874da84a-67ff-47fa-a6b4-cbc3c65eb704" width="300" style="border-radius: 16px;" />
|
|
130
|
+
</a>
|
|
131
|
+
<a href="https://www.copilotkit.ai/examples/state-machine-copilot">
|
|
132
|
+
<img src="https://github.com/user-attachments/assets/0b5e45b3-2704-4678-82dc-2f3e1c58e2dd" width="300" style="border-radius: 16px;" />
|
|
133
|
+
</a>
|
|
134
|
+
<a href="https://www.copilotkit.ai/examples/chat-with-your-data">
|
|
135
|
+
<img src="https://github.com/user-attachments/assets/0fed66be-a4c2-4093-8eab-75c0b27a62f6" width="300" style="border-radius: 16px;" />
|
|
136
|
+
</a>
|
|
137
|
+
</p>
|
|
138
|
+
|
|
139
|
+
# Documentation
|
|
140
|
+
|
|
141
|
+
To get started with CopilotKit, please check out the [documentation](https://docs.copilotkit.ai).
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=chunk-2OJ5OJ2D.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// package.json
|
|
2
|
+
var version = "1.50.2-next.0";
|
|
3
|
+
|
|
4
|
+
// src/telemetry/scarf-client.ts
|
|
5
|
+
var SCARF_BASE_URL = `https://copilotkit.gateway.scarf.sh/${version}`;
|
|
6
|
+
var ScarfClient = class {
|
|
7
|
+
constructor() {
|
|
8
|
+
}
|
|
9
|
+
async logEvent(properties) {
|
|
10
|
+
try {
|
|
11
|
+
const controller = new AbortController();
|
|
12
|
+
const timeoutId = setTimeout(() => controller.abort(), 3e3);
|
|
13
|
+
const queryParams = new URLSearchParams();
|
|
14
|
+
Object.entries(properties).forEach(([key, value]) => {
|
|
15
|
+
if (value !== null && value !== void 0) {
|
|
16
|
+
queryParams.append(key, String(value));
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
const url = `${SCARF_BASE_URL}?${queryParams.toString()}`;
|
|
20
|
+
const response = await fetch(url, {
|
|
21
|
+
method: "GET",
|
|
22
|
+
signal: controller.signal
|
|
23
|
+
});
|
|
24
|
+
clearTimeout(timeoutId);
|
|
25
|
+
if (!response.ok) {
|
|
26
|
+
throw new Error(`HTTP error! status: ${response.status}`);
|
|
27
|
+
}
|
|
28
|
+
} catch {
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
var scarf_client_default = new ScarfClient();
|
|
33
|
+
|
|
34
|
+
export {
|
|
35
|
+
version,
|
|
36
|
+
scarf_client_default
|
|
37
|
+
};
|
|
38
|
+
//# sourceMappingURL=chunk-5YXKLIUO.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../package.json","../src/telemetry/scarf-client.ts"],"sourcesContent":["{\n \"name\": \"@copilotkit/shared\",\n \"private\": false,\n \"homepage\": \"https://github.com/CopilotKit/CopilotKit\",\n \"repository\": {\n \"type\": \"git\",\n \"url\": \"https://github.com/CopilotKit/CopilotKit.git\"\n },\n \"publishConfig\": {\n \"access\": \"public\"\n },\n \"version\": \"1.50.2-next.0\",\n \"sideEffects\": false,\n \"main\": \"./dist/index.js\",\n \"module\": \"./dist/index.mjs\",\n \"exports\": {\n \".\": {\n \"import\": \"./dist/index.mjs\",\n \"require\": \"./dist/index.js\",\n \"types\": \"./dist/index.d.ts\"\n }\n },\n \"types\": \"./dist/index.d.ts\",\n \"license\": \"MIT\",\n \"scripts\": {\n \"build\": \"tsup --clean\",\n \"dev\": \"tsup --watch --no-splitting\",\n \"test\": \"jest --passWithNoTests\",\n \"check-types\": \"tsc --noEmit\",\n \"clean\": \"rm -rf .turbo && rm -rf node_modules && rm -rf dist && rm -rf .next\",\n \"link:global\": \"pnpm link --global\",\n \"unlink:global\": \"pnpm unlink --global\"\n },\n \"devDependencies\": {\n \"@types/jest\": \"^29.5.4\",\n \"@types/uuid\": \"^10.0.0\",\n \"eslint\": \"^8.56.0\",\n \"eslint-config-custom\": \"workspace:*\",\n \"jest\": \"^29.6.4\",\n \"ts-jest\": \"^29.1.1\",\n \"tsconfig\": \"workspace:*\",\n \"tsup\": \"^6.7.0\",\n \"typescript\": \"^5.2.3\",\n \"zod-to-json-schema\": \"^3.23.5\"\n },\n \"dependencies\": {\n \"@segment/analytics-node\": \"^2.1.2\",\n \"chalk\": \"4.1.2\",\n \"graphql\": \"^16.8.1\",\n \"uuid\": \"^10.0.0\",\n \"zod\": \"^3.23.3\"\n },\n \"peerDependencies\": {\n \"@ag-ui/core\": \"^0.0.42\"\n },\n \"keywords\": [\n \"copilotkit\",\n \"copilot\",\n \"react\",\n \"nextjs\",\n \"nodejs\",\n \"ai\",\n \"assistant\",\n \"javascript\",\n \"automation\",\n \"textarea\"\n ]\n}\n","import * as packageJson from \"../../package.json\";\n\nconst SCARF_BASE_URL = `https://copilotkit.gateway.scarf.sh/${packageJson.version}`;\n\nclass ScarfClient {\n constructor() {}\n\n async logEvent(properties: Record<string, any>): Promise<void> {\n try {\n const controller = new AbortController();\n const timeoutId = setTimeout(() => controller.abort(), 3000);\n\n const queryParams = new URLSearchParams();\n\n Object.entries(properties).forEach(([key, value]) => {\n if (value !== null && value !== undefined) {\n queryParams.append(key, String(value));\n }\n });\n\n const url = `${SCARF_BASE_URL}?${queryParams.toString()}`;\n\n const response = await fetch(url, {\n method: \"GET\",\n signal: controller.signal,\n });\n\n clearTimeout(timeoutId);\n\n if (!response.ok) {\n throw new Error(`HTTP error! status: ${response.status}`);\n }\n } catch {\n // Silently fail - telemetry should not break the application\n }\n }\n}\n\nexport default new ScarfClient();\n"],"mappings":";AAWE,cAAW;;;ACTb,IAAM,iBAAiB,uCAAmD;AAE1E,IAAM,cAAN,MAAkB;AAAA,EAChB,cAAc;AAAA,EAAC;AAAA,EAEf,MAAM,SAAS,YAAgD;AAC7D,QAAI;AACF,YAAM,aAAa,IAAI,gBAAgB;AACvC,YAAM,YAAY,WAAW,MAAM,WAAW,MAAM,GAAG,GAAI;AAE3D,YAAM,cAAc,IAAI,gBAAgB;AAExC,aAAO,QAAQ,UAAU,EAAE,QAAQ,CAAC,CAAC,KAAK,KAAK,MAAM;AACnD,YAAI,UAAU,QAAQ,UAAU,QAAW;AACzC,sBAAY,OAAO,KAAK,OAAO,KAAK,CAAC;AAAA,QACvC;AAAA,MACF,CAAC;AAED,YAAM,MAAM,GAAG,kBAAkB,YAAY,SAAS;AAEtD,YAAM,WAAW,MAAM,MAAM,KAAK;AAAA,QAChC,QAAQ;AAAA,QACR,QAAQ,WAAW;AAAA,MACrB,CAAC;AAED,mBAAa,SAAS;AAEtB,UAAI,CAAC,SAAS,IAAI;AAChB,cAAM,IAAI,MAAM,uBAAuB,SAAS,QAAQ;AAAA,MAC1D;AAAA,IACF,QAAE;AAAA,IAEF;AAAA,EACF;AACF;AAEA,IAAO,uBAAQ,IAAI,YAAY;","names":[]}
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
// src/utils/json-schema.ts
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
function actionParametersToJsonSchema(actionParameters) {
|
|
4
|
+
let parameters = {};
|
|
5
|
+
for (let parameter of actionParameters || []) {
|
|
6
|
+
parameters[parameter.name] = convertAttribute(parameter);
|
|
7
|
+
}
|
|
8
|
+
let requiredParameterNames = [];
|
|
9
|
+
for (let arg of actionParameters || []) {
|
|
10
|
+
if (arg.required !== false) {
|
|
11
|
+
requiredParameterNames.push(arg.name);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
return {
|
|
15
|
+
type: "object",
|
|
16
|
+
properties: parameters,
|
|
17
|
+
required: requiredParameterNames
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
function jsonSchemaToActionParameters(jsonSchema) {
|
|
21
|
+
if (jsonSchema.type !== "object" || !jsonSchema.properties) {
|
|
22
|
+
return [];
|
|
23
|
+
}
|
|
24
|
+
const parameters = [];
|
|
25
|
+
const requiredFields = jsonSchema.required || [];
|
|
26
|
+
for (const [name, schema] of Object.entries(jsonSchema.properties)) {
|
|
27
|
+
const parameter = convertJsonSchemaToParameter(name, schema, requiredFields.includes(name));
|
|
28
|
+
parameters.push(parameter);
|
|
29
|
+
}
|
|
30
|
+
return parameters;
|
|
31
|
+
}
|
|
32
|
+
function convertJsonSchemaToParameter(name, schema, isRequired) {
|
|
33
|
+
const baseParameter = {
|
|
34
|
+
name,
|
|
35
|
+
description: schema.description
|
|
36
|
+
};
|
|
37
|
+
if (!isRequired) {
|
|
38
|
+
baseParameter.required = false;
|
|
39
|
+
}
|
|
40
|
+
switch (schema.type) {
|
|
41
|
+
case "string":
|
|
42
|
+
return {
|
|
43
|
+
...baseParameter,
|
|
44
|
+
type: "string",
|
|
45
|
+
...schema.enum && { enum: schema.enum }
|
|
46
|
+
};
|
|
47
|
+
case "number":
|
|
48
|
+
case "boolean":
|
|
49
|
+
return {
|
|
50
|
+
...baseParameter,
|
|
51
|
+
type: schema.type
|
|
52
|
+
};
|
|
53
|
+
case "object":
|
|
54
|
+
if (schema.properties) {
|
|
55
|
+
const attributes = [];
|
|
56
|
+
const requiredFields = schema.required || [];
|
|
57
|
+
for (const [propName, propSchema] of Object.entries(schema.properties)) {
|
|
58
|
+
attributes.push(
|
|
59
|
+
convertJsonSchemaToParameter(propName, propSchema, requiredFields.includes(propName))
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
return {
|
|
63
|
+
...baseParameter,
|
|
64
|
+
type: "object",
|
|
65
|
+
attributes
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
return {
|
|
69
|
+
...baseParameter,
|
|
70
|
+
type: "object"
|
|
71
|
+
};
|
|
72
|
+
case "array":
|
|
73
|
+
if (schema.items.type === "object" && "properties" in schema.items) {
|
|
74
|
+
const attributes = [];
|
|
75
|
+
const requiredFields = schema.items.required || [];
|
|
76
|
+
for (const [propName, propSchema] of Object.entries(schema.items.properties || {})) {
|
|
77
|
+
attributes.push(
|
|
78
|
+
convertJsonSchemaToParameter(propName, propSchema, requiredFields.includes(propName))
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
return {
|
|
82
|
+
...baseParameter,
|
|
83
|
+
type: "object[]",
|
|
84
|
+
attributes
|
|
85
|
+
};
|
|
86
|
+
} else if (schema.items.type === "array") {
|
|
87
|
+
throw new Error("Nested arrays are not supported");
|
|
88
|
+
} else {
|
|
89
|
+
return {
|
|
90
|
+
...baseParameter,
|
|
91
|
+
type: `${schema.items.type}[]`
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
default:
|
|
95
|
+
return {
|
|
96
|
+
...baseParameter,
|
|
97
|
+
type: "string"
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
function convertAttribute(attribute) {
|
|
102
|
+
var _a, _b, _c;
|
|
103
|
+
switch (attribute.type) {
|
|
104
|
+
case "string":
|
|
105
|
+
return {
|
|
106
|
+
type: "string",
|
|
107
|
+
description: attribute.description,
|
|
108
|
+
...attribute.enum && { enum: attribute.enum }
|
|
109
|
+
};
|
|
110
|
+
case "number":
|
|
111
|
+
case "boolean":
|
|
112
|
+
return {
|
|
113
|
+
type: attribute.type,
|
|
114
|
+
description: attribute.description
|
|
115
|
+
};
|
|
116
|
+
case "object":
|
|
117
|
+
case "object[]":
|
|
118
|
+
const properties = (_a = attribute.attributes) == null ? void 0 : _a.reduce(
|
|
119
|
+
(acc, attr) => {
|
|
120
|
+
acc[attr.name] = convertAttribute(attr);
|
|
121
|
+
return acc;
|
|
122
|
+
},
|
|
123
|
+
{}
|
|
124
|
+
);
|
|
125
|
+
const required = (_b = attribute.attributes) == null ? void 0 : _b.filter((attr) => attr.required !== false).map((attr) => attr.name);
|
|
126
|
+
if (attribute.type === "object[]") {
|
|
127
|
+
return {
|
|
128
|
+
type: "array",
|
|
129
|
+
items: {
|
|
130
|
+
type: "object",
|
|
131
|
+
...properties && { properties },
|
|
132
|
+
...required && required.length > 0 && { required }
|
|
133
|
+
},
|
|
134
|
+
description: attribute.description
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
return {
|
|
138
|
+
type: "object",
|
|
139
|
+
description: attribute.description,
|
|
140
|
+
...properties && { properties },
|
|
141
|
+
...required && required.length > 0 && { required }
|
|
142
|
+
};
|
|
143
|
+
default:
|
|
144
|
+
if ((_c = attribute.type) == null ? void 0 : _c.endsWith("[]")) {
|
|
145
|
+
const itemType = attribute.type.slice(0, -2);
|
|
146
|
+
return {
|
|
147
|
+
type: "array",
|
|
148
|
+
items: { type: itemType },
|
|
149
|
+
description: attribute.description
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
return {
|
|
153
|
+
type: "string",
|
|
154
|
+
description: attribute.description
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
function convertJsonSchemaToZodSchema(jsonSchema, required) {
|
|
159
|
+
if (jsonSchema.type === "object") {
|
|
160
|
+
const spec = {};
|
|
161
|
+
if (!jsonSchema.properties || !Object.keys(jsonSchema.properties).length) {
|
|
162
|
+
return !required ? z.object(spec).optional() : z.object(spec);
|
|
163
|
+
}
|
|
164
|
+
for (const [key, value] of Object.entries(jsonSchema.properties)) {
|
|
165
|
+
spec[key] = convertJsonSchemaToZodSchema(
|
|
166
|
+
value,
|
|
167
|
+
jsonSchema.required ? jsonSchema.required.includes(key) : false
|
|
168
|
+
);
|
|
169
|
+
}
|
|
170
|
+
let schema = z.object(spec).describe(jsonSchema.description);
|
|
171
|
+
return required ? schema : schema.optional();
|
|
172
|
+
} else if (jsonSchema.type === "string") {
|
|
173
|
+
let schema = z.string().describe(jsonSchema.description);
|
|
174
|
+
return required ? schema : schema.optional();
|
|
175
|
+
} else if (jsonSchema.type === "number") {
|
|
176
|
+
let schema = z.number().describe(jsonSchema.description);
|
|
177
|
+
return required ? schema : schema.optional();
|
|
178
|
+
} else if (jsonSchema.type === "boolean") {
|
|
179
|
+
let schema = z.boolean().describe(jsonSchema.description);
|
|
180
|
+
return required ? schema : schema.optional();
|
|
181
|
+
} else if (jsonSchema.type === "array") {
|
|
182
|
+
let itemSchema = convertJsonSchemaToZodSchema(jsonSchema.items, true);
|
|
183
|
+
let schema = z.array(itemSchema).describe(jsonSchema.description);
|
|
184
|
+
return required ? schema : schema.optional();
|
|
185
|
+
}
|
|
186
|
+
throw new Error("Invalid JSON schema");
|
|
187
|
+
}
|
|
188
|
+
function getZodParameters(parameters) {
|
|
189
|
+
if (!parameters)
|
|
190
|
+
return z.object({});
|
|
191
|
+
const jsonParams = actionParametersToJsonSchema(parameters);
|
|
192
|
+
return convertJsonSchemaToZodSchema(jsonParams, true);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
export {
|
|
196
|
+
actionParametersToJsonSchema,
|
|
197
|
+
jsonSchemaToActionParameters,
|
|
198
|
+
convertJsonSchemaToZodSchema,
|
|
199
|
+
getZodParameters
|
|
200
|
+
};
|
|
201
|
+
//# sourceMappingURL=chunk-64DYJ27R.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/utils/json-schema.ts"],"sourcesContent":["import { z } from \"zod\";\nimport { Parameter } from \"../types\";\n\nexport type JSONSchemaString = {\n type: \"string\";\n description?: string;\n enum?: string[];\n};\n\nexport type JSONSchemaNumber = {\n type: \"number\";\n description?: string;\n};\n\nexport type JSONSchemaBoolean = {\n type: \"boolean\";\n description?: string;\n};\n\nexport type JSONSchemaObject = {\n type: \"object\";\n properties?: Record<string, JSONSchema>;\n required?: string[];\n description?: string;\n};\n\nexport type JSONSchemaArray = {\n type: \"array\";\n items: JSONSchema;\n description?: string;\n};\n\nexport type JSONSchema =\n | JSONSchemaString\n | JSONSchemaNumber\n | JSONSchemaBoolean\n | JSONSchemaObject\n | JSONSchemaArray;\n\nexport function actionParametersToJsonSchema(actionParameters: Parameter[]): JSONSchema {\n // Create the parameters object based on the argumentAnnotations\n let parameters: { [key: string]: any } = {};\n for (let parameter of actionParameters || []) {\n parameters[parameter.name] = convertAttribute(parameter);\n }\n\n let requiredParameterNames: string[] = [];\n for (let arg of actionParameters || []) {\n if (arg.required !== false) {\n requiredParameterNames.push(arg.name);\n }\n }\n\n // Create the ChatCompletionFunctions object\n return {\n type: \"object\",\n properties: parameters,\n required: requiredParameterNames,\n };\n}\n\n// Convert JSONSchema to Parameter[]\nexport function jsonSchemaToActionParameters(jsonSchema: JSONSchema): Parameter[] {\n if (jsonSchema.type !== \"object\" || !jsonSchema.properties) {\n return [];\n }\n\n const parameters: Parameter[] = [];\n const requiredFields = jsonSchema.required || [];\n\n for (const [name, schema] of Object.entries(jsonSchema.properties)) {\n const parameter = convertJsonSchemaToParameter(name, schema, requiredFields.includes(name));\n parameters.push(parameter);\n }\n\n return parameters;\n}\n\n// Convert JSONSchema property to Parameter\nfunction convertJsonSchemaToParameter(\n name: string,\n schema: JSONSchema,\n isRequired: boolean,\n): Parameter {\n const baseParameter: Parameter = {\n name,\n description: schema.description,\n };\n\n if (!isRequired) {\n baseParameter.required = false;\n }\n\n switch (schema.type) {\n case \"string\":\n return {\n ...baseParameter,\n type: \"string\",\n ...(schema.enum && { enum: schema.enum }),\n };\n case \"number\":\n case \"boolean\":\n return {\n ...baseParameter,\n type: schema.type,\n };\n case \"object\":\n if (schema.properties) {\n const attributes: Parameter[] = [];\n const requiredFields = schema.required || [];\n\n for (const [propName, propSchema] of Object.entries(schema.properties)) {\n attributes.push(\n convertJsonSchemaToParameter(propName, propSchema, requiredFields.includes(propName)),\n );\n }\n\n return {\n ...baseParameter,\n type: \"object\",\n attributes,\n };\n }\n return {\n ...baseParameter,\n type: \"object\",\n };\n case \"array\":\n if (schema.items.type === \"object\" && \"properties\" in schema.items) {\n const attributes: Parameter[] = [];\n const requiredFields = schema.items.required || [];\n\n for (const [propName, propSchema] of Object.entries(schema.items.properties || {})) {\n attributes.push(\n convertJsonSchemaToParameter(propName, propSchema, requiredFields.includes(propName)),\n );\n }\n\n return {\n ...baseParameter,\n type: \"object[]\",\n attributes,\n };\n } else if (schema.items.type === \"array\") {\n throw new Error(\"Nested arrays are not supported\");\n } else {\n return {\n ...baseParameter,\n type: `${schema.items.type}[]`,\n };\n }\n default:\n return {\n ...baseParameter,\n type: \"string\",\n };\n }\n}\n\nfunction convertAttribute(attribute: Parameter): JSONSchema {\n switch (attribute.type) {\n case \"string\":\n return {\n type: \"string\",\n description: attribute.description,\n ...(attribute.enum && { enum: attribute.enum }),\n };\n case \"number\":\n case \"boolean\":\n return {\n type: attribute.type,\n description: attribute.description,\n };\n case \"object\":\n case \"object[]\":\n const properties = attribute.attributes?.reduce(\n (acc, attr) => {\n acc[attr.name] = convertAttribute(attr);\n return acc;\n },\n {} as Record<string, any>,\n );\n const required = attribute.attributes\n ?.filter((attr) => attr.required !== false)\n .map((attr) => attr.name);\n if (attribute.type === \"object[]\") {\n return {\n type: \"array\",\n items: {\n type: \"object\",\n ...(properties && { properties }),\n ...(required && required.length > 0 && { required }),\n },\n description: attribute.description,\n };\n }\n return {\n type: \"object\",\n description: attribute.description,\n ...(properties && { properties }),\n ...(required && required.length > 0 && { required }),\n };\n default:\n // Handle arrays of primitive types and undefined attribute.type\n if (attribute.type?.endsWith(\"[]\")) {\n const itemType = attribute.type.slice(0, -2);\n return {\n type: \"array\",\n items: { type: itemType as any },\n description: attribute.description,\n };\n }\n // Fallback for undefined type or any other unexpected type\n return {\n type: \"string\",\n description: attribute.description,\n };\n }\n}\n\nexport function convertJsonSchemaToZodSchema(jsonSchema: any, required: boolean): z.ZodSchema {\n if (jsonSchema.type === \"object\") {\n const spec: { [key: string]: z.ZodSchema } = {};\n\n if (!jsonSchema.properties || !Object.keys(jsonSchema.properties).length) {\n return !required ? z.object(spec).optional() : z.object(spec);\n }\n\n for (const [key, value] of Object.entries(jsonSchema.properties)) {\n spec[key] = convertJsonSchemaToZodSchema(\n value,\n jsonSchema.required ? jsonSchema.required.includes(key) : false,\n );\n }\n let schema = z.object(spec).describe(jsonSchema.description);\n return required ? schema : schema.optional();\n } else if (jsonSchema.type === \"string\") {\n let schema = z.string().describe(jsonSchema.description);\n return required ? schema : schema.optional();\n } else if (jsonSchema.type === \"number\") {\n let schema = z.number().describe(jsonSchema.description);\n return required ? schema : schema.optional();\n } else if (jsonSchema.type === \"boolean\") {\n let schema = z.boolean().describe(jsonSchema.description);\n return required ? schema : schema.optional();\n } else if (jsonSchema.type === \"array\") {\n let itemSchema = convertJsonSchemaToZodSchema(jsonSchema.items, true);\n let schema = z.array(itemSchema).describe(jsonSchema.description);\n return required ? schema : schema.optional();\n }\n throw new Error(\"Invalid JSON schema\");\n}\n\nexport function getZodParameters<T extends [] | Parameter[] | undefined>(parameters: T): any {\n if (!parameters) return z.object({});\n const jsonParams = actionParametersToJsonSchema(parameters);\n return convertJsonSchemaToZodSchema(jsonParams, true);\n}\n"],"mappings":";AAAA,SAAS,SAAS;AAuCX,SAAS,6BAA6B,kBAA2C;AAEtF,MAAI,aAAqC,CAAC;AAC1C,WAAS,aAAa,oBAAoB,CAAC,GAAG;AAC5C,eAAW,UAAU,IAAI,IAAI,iBAAiB,SAAS;AAAA,EACzD;AAEA,MAAI,yBAAmC,CAAC;AACxC,WAAS,OAAO,oBAAoB,CAAC,GAAG;AACtC,QAAI,IAAI,aAAa,OAAO;AAC1B,6BAAuB,KAAK,IAAI,IAAI;AAAA,IACtC;AAAA,EACF;AAGA,SAAO;AAAA,IACL,MAAM;AAAA,IACN,YAAY;AAAA,IACZ,UAAU;AAAA,EACZ;AACF;AAGO,SAAS,6BAA6B,YAAqC;AAChF,MAAI,WAAW,SAAS,YAAY,CAAC,WAAW,YAAY;AAC1D,WAAO,CAAC;AAAA,EACV;AAEA,QAAM,aAA0B,CAAC;AACjC,QAAM,iBAAiB,WAAW,YAAY,CAAC;AAE/C,aAAW,CAAC,MAAM,MAAM,KAAK,OAA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,SAAS,WAAW;AACxC,QAAI,SAAS,EAAE,QAAQ,EAAE,SAAS,WAAW,WAAW;AACxD,WAAO,WAAW,SAAS,OAAO,SAAS;AAAA,EAC7C,WAAW,WAAW,SAAS,SAAS;AACtC,QAAI,aAAa,6BAA6B,WAAW,OAAO,IAAI;AACpE,QAAI,SAAS,EAAE,MAAM,UAAU,EAAE,SAAS,WAAW,WAAW;AAChE,WAAO,WAAW,SAAS,OAAO,SAAS;AAAA,EAC7C;AACA,QAAM,IAAI,MAAM,qBAAqB;AACvC;AAEO,SAAS,iBAAyD,YAAoB;AAC3F,MAAI,CAAC;AAAY,WAAO,EAAE,OAAO,CAAC,CAAC;AACnC,QAAM,aAAa,6BAA6B,UAAU;AAC1D,SAAO,6BAA6B,YAAY,IAAI;AACtD;","names":[]}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// src/telemetry/utils.ts
|
|
2
|
+
import chalk from "chalk";
|
|
3
|
+
function flattenObject(obj, parentKey = "", res = {}) {
|
|
4
|
+
for (let key in obj) {
|
|
5
|
+
const propName = parentKey ? `${parentKey}.${key}` : key;
|
|
6
|
+
if (typeof obj[key] === "object" && obj[key] !== null) {
|
|
7
|
+
flattenObject(obj[key], propName, res);
|
|
8
|
+
} else {
|
|
9
|
+
res[propName] = obj[key];
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
return res;
|
|
13
|
+
}
|
|
14
|
+
function printSecurityNotice(advisory) {
|
|
15
|
+
const severityColor = {
|
|
16
|
+
low: chalk.blue,
|
|
17
|
+
medium: chalk.yellow,
|
|
18
|
+
high: chalk.red
|
|
19
|
+
}[advisory.severity.toLowerCase()] || chalk.white;
|
|
20
|
+
console.log();
|
|
21
|
+
console.log(`\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501 ${chalk.bold(`CopilotKit`)} \u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501`);
|
|
22
|
+
console.log();
|
|
23
|
+
console.log(`${chalk.bold(`Severity: ${severityColor(advisory.severity.toUpperCase())}`)}`);
|
|
24
|
+
console.log();
|
|
25
|
+
console.log(`${chalk.bold(advisory.message)}`);
|
|
26
|
+
console.log();
|
|
27
|
+
console.log(`\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501`);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export {
|
|
31
|
+
flattenObject,
|
|
32
|
+
printSecurityNotice
|
|
33
|
+
};
|
|
34
|
+
//# sourceMappingURL=chunk-6QGXWNS5.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/telemetry/utils.ts"],"sourcesContent":["import chalk from \"chalk\";\n\nexport function flattenObject(\n obj: Record<string, any>,\n parentKey = \"\",\n res: Record<string, any> = {},\n): Record<string, any> {\n for (let key in obj) {\n const propName = parentKey ? `${parentKey}.${key}` : key;\n if (typeof obj[key] === \"object\" && obj[key] !== null) {\n flattenObject(obj[key], propName, res);\n } else {\n res[propName] = obj[key];\n }\n }\n return res;\n}\n\nexport function printSecurityNotice(advisory: {\n advisory: string | null;\n message: string;\n severity: \"low\" | \"medium\" | \"high\" | \"none\";\n}) {\n const severityColor =\n {\n low: chalk.blue,\n medium: chalk.yellow,\n high: chalk.red,\n }[advisory.severity.toLowerCase()] || chalk.white;\n\n console.log();\n console.log(`━━━━━━━━━━━━━━━━━━ ${chalk.bold(`CopilotKit`)} ━━━━━━━━━━━━━━━━━━`);\n console.log();\n console.log(`${chalk.bold(`Severity: ${severityColor(advisory.severity.toUpperCase())}`)}`);\n console.log();\n console.log(`${chalk.bold(advisory.message)}`);\n console.log();\n console.log(`━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━`);\n}\n"],"mappings":";AAAA,OAAO,WAAW;AAEX,SAAS,cACd,KACA,YAAY,IACZ,MAA2B,CAAC,GACP;AACrB,WAAS,OAAO,KAAK;AACnB,UAAM,WAAW,YAAY,GAAG,aAAa,QAAQ;AACrD,QAAI,OAAO,IAAI,GAAG,MAAM,YAAY,IAAI,GAAG,MAAM,MAAM;AACrD,oBAAc,IAAI,GAAG,GAAG,UAAU,GAAG;AAAA,IACvC,OAAO;AACL,UAAI,QAAQ,IAAI,IAAI,GAAG;AAAA,IACzB;AAAA,EACF;AACA,SAAO;AACT;AAEO,SAAS,oBAAoB,UAIjC;AACD,QAAM,gBACJ;AAAA,IACE,KAAK,MAAM;AAAA,IACX,QAAQ,MAAM;AAAA,IACd,MAAM,MAAM;AAAA,EACd,EAAE,SAAS,SAAS,YAAY,CAAC,KAAK,MAAM;AAE9C,UAAQ,IAAI;AACZ,UAAQ,IAAI,gHAAsB,MAAM,KAAK,YAAY,gHAAsB;AAC/E,UAAQ,IAAI;AACZ,UAAQ,IAAI,GAAG,MAAM,KAAK,aAAa,cAAc,SAAS,SAAS,YAAY,CAAC,GAAG,GAAG;AAC1F,UAAQ,IAAI;AACZ,UAAQ,IAAI,GAAG,MAAM,KAAK,SAAS,OAAO,GAAG;AAC7C,UAAQ,IAAI;AACZ,UAAQ,IAAI,kSAAkD;AAChE;","names":[]}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
// src/utils/console-styling.ts
|
|
2
|
+
var ConsoleColors = {
|
|
3
|
+
/** Primary brand blue - for titles and links */
|
|
4
|
+
primary: "#007acc",
|
|
5
|
+
/** Success green - for positive messaging */
|
|
6
|
+
success: "#22c55e",
|
|
7
|
+
/** Purple - for feature highlights */
|
|
8
|
+
feature: "#a855f7",
|
|
9
|
+
/** Red - for calls-to-action */
|
|
10
|
+
cta: "#ef4444",
|
|
11
|
+
/** Cyan - for closing statements */
|
|
12
|
+
info: "#06b6d4",
|
|
13
|
+
/** Inherit console default - for body text */
|
|
14
|
+
inherit: "inherit",
|
|
15
|
+
/** Warning style */
|
|
16
|
+
warning: "#f59e0b"
|
|
17
|
+
};
|
|
18
|
+
var ConsoleStyles = {
|
|
19
|
+
/** Large header style */
|
|
20
|
+
header: `color: ${ConsoleColors.warning}; font-weight: bold; font-size: 16px;`,
|
|
21
|
+
/** Section header style */
|
|
22
|
+
section: `color: ${ConsoleColors.success}; font-weight: bold;`,
|
|
23
|
+
/** Feature highlight style */
|
|
24
|
+
highlight: `color: ${ConsoleColors.feature}; font-weight: bold;`,
|
|
25
|
+
/** Call-to-action style */
|
|
26
|
+
cta: `color: ${ConsoleColors.success}; font-weight: bold;`,
|
|
27
|
+
/** Info style */
|
|
28
|
+
info: `color: ${ConsoleColors.info}; font-weight: bold;`,
|
|
29
|
+
/** Link style */
|
|
30
|
+
link: `color: ${ConsoleColors.primary}; text-decoration: underline;`,
|
|
31
|
+
/** Body text - inherits console theme */
|
|
32
|
+
body: `color: ${ConsoleColors.inherit};`,
|
|
33
|
+
/** Warning style */
|
|
34
|
+
warning: `color: ${ConsoleColors.cta}; font-weight: bold;`
|
|
35
|
+
};
|
|
36
|
+
function logCopilotKitPlatformMessage() {
|
|
37
|
+
console.log(
|
|
38
|
+
`%cCopilotKit Warning%c
|
|
39
|
+
|
|
40
|
+
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:
|
|
41
|
+
|
|
42
|
+
%chttps://cloud.copilotkit.ai%c
|
|
43
|
+
|
|
44
|
+
Alternatively, useCopilotChat is available for basic programmatic control, and does not require an API key.
|
|
45
|
+
|
|
46
|
+
To learn more about premium features, read the documentation here:
|
|
47
|
+
|
|
48
|
+
%chttps://docs.copilotkit.ai/premium%c`,
|
|
49
|
+
ConsoleStyles.header,
|
|
50
|
+
ConsoleStyles.body,
|
|
51
|
+
ConsoleStyles.cta,
|
|
52
|
+
ConsoleStyles.body,
|
|
53
|
+
ConsoleStyles.link,
|
|
54
|
+
ConsoleStyles.body
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
function publicApiKeyRequired(feature) {
|
|
58
|
+
console.log(
|
|
59
|
+
`
|
|
60
|
+
%cCopilotKit Warning%c
|
|
61
|
+
|
|
62
|
+
In order to use ${feature}, you need to add your CopilotKit API key, available for free at https://cloud.copilotkit.ai.
|
|
63
|
+
`.trim(),
|
|
64
|
+
ConsoleStyles.header,
|
|
65
|
+
ConsoleStyles.body
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
function logStyled(template, styles) {
|
|
69
|
+
console.log(template, ...styles);
|
|
70
|
+
}
|
|
71
|
+
var styledConsole = {
|
|
72
|
+
/** Log a success message */
|
|
73
|
+
success: (message) => logStyled(`%c\u2705 ${message}`, [ConsoleStyles.section]),
|
|
74
|
+
/** Log an info message */
|
|
75
|
+
info: (message) => logStyled(`%c\u2139\uFE0F ${message}`, [ConsoleStyles.info]),
|
|
76
|
+
/** Log a feature highlight */
|
|
77
|
+
feature: (message) => logStyled(`%c\u2728 ${message}`, [ConsoleStyles.highlight]),
|
|
78
|
+
/** Log a call-to-action */
|
|
79
|
+
cta: (message) => logStyled(`%c\u{1F680} ${message}`, [ConsoleStyles.cta]),
|
|
80
|
+
/** Log the CopilotKit platform promotion */
|
|
81
|
+
logCopilotKitPlatformMessage,
|
|
82
|
+
/** Log a `publicApiKeyRequired` warning */
|
|
83
|
+
publicApiKeyRequired
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
export {
|
|
87
|
+
ConsoleColors,
|
|
88
|
+
ConsoleStyles,
|
|
89
|
+
logCopilotKitPlatformMessage,
|
|
90
|
+
publicApiKeyRequired,
|
|
91
|
+
logStyled,
|
|
92
|
+
styledConsole
|
|
93
|
+
};
|
|
94
|
+
//# sourceMappingURL=chunk-6W2UEO2M.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"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. To enable this premium feature, add your public license key, available for free at:\n\n%chttps://cloud.copilotkit.ai%c\n\nAlternatively, useCopilotChat is available for basic programmatic control, and does not require an API key.\n\nTo learn more about premium features, read the documentation here:\n\n%chttps://docs.copilotkit.ai/premium%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 API key, available for free at https://cloud.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) => 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) => 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":";AAQO,IAAM,gBAAgB;AAAA;AAAA,EAE3B,SAAS;AAAA;AAAA,EAET,SAAS;AAAA;AAAA,EAET,SAAS;AAAA;AAAA,EAET,KAAK;AAAA;AAAA,EAEL,MAAM;AAAA;AAAA,EAEN,SAAS;AAAA;AAAA,EAET,SAAS;AACX;AAKO,IAAM,gBAAgB;AAAA;AAAA,EAE3B,QAAQ,UAAU,cAAc;AAAA;AAAA,EAEhC,SAAS,UAAU,cAAc;AAAA;AAAA,EAEjC,WAAW,UAAU,cAAc;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
|
7
|
+
return uuidv4();
|
|
8
|
+
}
|
|
9
|
+
function toSerializable(value) {
|
|
10
|
+
if (typeof value === "function") {
|
|
11
|
+
return value.toString();
|
|
12
|
+
}
|
|
13
|
+
if (Array.isArray(value)) {
|
|
14
|
+
return value.map(toSerializable);
|
|
15
|
+
}
|
|
16
|
+
if (value !== null && typeof value === "object") {
|
|
17
|
+
const result = {};
|
|
18
|
+
for (const key of Object.keys(value)) {
|
|
19
|
+
result[key] = toSerializable(value[key]);
|
|
20
|
+
}
|
|
21
|
+
return result;
|
|
22
|
+
}
|
|
23
|
+
return value;
|
|
24
|
+
}
|
|
25
|
+
function dataToUUID(input, namespace) {
|
|
26
|
+
const BASE_NAMESPACE = "e4b01160-ff74-4c6e-9b27-d53cd930fe8e";
|
|
27
|
+
const boundNamespace = namespace ? uuidv5(namespace, BASE_NAMESPACE) : BASE_NAMESPACE;
|
|
28
|
+
const stringInput = typeof input === "string" ? input : JSON.stringify(toSerializable(input));
|
|
29
|
+
return uuidv5(stringInput, boundNamespace);
|
|
30
|
+
}
|
|
31
|
+
function isValidUUID(uuid) {
|
|
32
|
+
return validate(uuid);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export {
|
|
36
|
+
randomId,
|
|
37
|
+
randomUUID,
|
|
38
|
+
dataToUUID,
|
|
39
|
+
isValidUUID
|
|
40
|
+
};
|
|
41
|
+
//# sourceMappingURL=chunk-BOKE4OKY.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/utils/random-id.ts"],"sourcesContent":["import { v4 as uuidv4, validate, v5 as uuidv5 } from \"uuid\";\n\nexport function randomId() {\n return \"ck-\" + uuidv4();\n}\n\nexport function randomUUID() {\n return uuidv4();\n}\n\n/**\n * Recursively converts an object to a serializable form by converting functions to their string representation.\n */\nfunction toSerializable(value: unknown): unknown {\n if (typeof value === \"function\") {\n return value.toString();\n }\n if (Array.isArray(value)) {\n return value.map(toSerializable);\n }\n if (value !== null && typeof value === \"object\") {\n const result: Record<string, unknown> = {};\n for (const key of Object.keys(value)) {\n result[key] = toSerializable((value as Record<string, unknown>)[key]);\n }\n return result;\n }\n return value;\n}\n\nexport function dataToUUID(input: string | object, namespace?: string): string {\n const BASE_NAMESPACE = \"e4b01160-ff74-4c6e-9b27-d53cd930fe8e\";\n // Since namespace needs to be a uuid, we are creating a uuid for it.\n const boundNamespace = namespace ? uuidv5(namespace, BASE_NAMESPACE) : BASE_NAMESPACE;\n\n const stringInput = typeof input === \"string\" ? input : JSON.stringify(toSerializable(input));\n return uuidv5(stringInput, boundNamespace);\n}\n\nexport function isValidUUID(uuid: string) {\n return validate(uuid);\n}\n"],"mappings":";AAAA,SAAS,MAAM,QAAQ,UAAU,MAAM,cAAc;AAE9C,SAAS,WAAW;AACzB,SAAO,QAAQ,OAAO;AACxB;AAEO,SAAS,aAAa;AAC3B,SAAO,OAAO;AAChB;AAKA,SAAS,eAAe,OAAyB;AAC/C,MAAI,OAAO,UAAU,YAAY;AAC/B,WAAO,MAAM,SAAS;AAAA,EACxB;AACA,MAAI,MAAM,QAAQ,KAAK,GAAG;AACxB,WAAO,MAAM,IAAI,cAAc;AAAA,EACjC;AACA,MAAI,UAAU,QAAQ,OAAO,UAAU,UAAU;AAC/C,UAAM,SAAkC,CAAC;AACzC,eAAW,OAAO,OAAO,KAAK,KAAK,GAAG;AACpC,aAAO,GAAG,IAAI,eAAgB,MAAkC,GAAG,CAAC;AAAA,IACtE;AACA,WAAO;AAAA,EACT;AACA,SAAO;AACT;AAEO,SAAS,WAAW,OAAwB,WAA4B;AAC7E,QAAM,iBAAiB;AAEvB,QAAM,iBAAiB,YAAY,OAAO,WAAW,cAAc,IAAI;AAEvE,QAAM,cAAc,OAAO,UAAU,WAAW,QAAQ,KAAK,UAAU,eAAe,KAAK,CAAC;AAC5F,SAAO,OAAO,aAAa,cAAc;AAC3C;AAEO,SAAS,YAAY,MAAc;AACxC,SAAO,SAAS,IAAI;AACtB;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=chunk-FCCOSO5L.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|