Skip to content

Commit 0adc770

Browse files
committed
refactor: clean CopilotKit setup for CI/CD
1 parent 7a03deb commit 0adc770

6 files changed

Lines changed: 4021 additions & 238 deletions

File tree

components/CopilotKitWrapper.jsx

Lines changed: 35 additions & 164 deletions
Original file line numberDiff line numberDiff line change
@@ -1,190 +1,61 @@
1-
// CopilotKitWrapper.jsx
1+
"use client";
2+
23
import { CopilotKit } from "@copilotkit/react-core";
3-
import {
4-
CopilotSidebar,
5-
useCopilotChatSuggestions,
6-
} from "@copilotkit/react-ui";
7-
import "@copilotkit/react-ui/styles.css";
4+
import { CopilotSidebar, useCopilotChatSuggestions } from "@copilotkit/react-ui";
5+
6+
// System instructions for the assistant
7+
const SYSTEM_INSTRUCTIONS = `You are the Dspread Documentation Assistant, helping developers with Dspread payment terminals and SDKs.
8+
9+
**KEY GUIDELINES:**
10+
- Use 80% direct documentation quotes, 20% explanation
11+
- Only reference official Dspread GitHub repositories for code examples
12+
- Include links to docs: https://dspreadorg.github.io/docs
13+
14+
**DOCUMENTATION PAGES:**
15+
- Android: /android-terminals/overview, /android-terminals/set-up-integration, /android-terminals/accept-card-payment
16+
- Linux: /linux-terminals/getting-started, /linux-terminals/transaction-flow
17+
- Payment: /payment-gateway-aws, /key-management-aws, /emv-l3-testing
18+
- Management: /tms-larktms, /cloud-speaker
819
9-
// Component with CopilotKit suggestions
10-
function AppWithSuggestions({ children }) {
11-
// Use the official CopilotKit hook for suggestions
20+
**OFFICIAL REPOS:**
21+
- Android SDK: https://github.com/DspreadOrg/android
22+
- Linux Tools: https://github.com/DspreadOrg/qpos-linux-tools
23+
- D30 Linux: https://github.com/DspreadOrg/D30-linux
24+
25+
Only use code from these repos. If no official example exists, state that clearly.`;
26+
27+
// Suggestions component
28+
function ChatSuggestions({ children }) {
1229
useCopilotChatSuggestions({
13-
instructions: `You are a Dspread documentation assistant. Suggest contextual questions that users might want to ask about:
14-
15-
🚀 Getting Started: "How do I set up the development environment for Android terminals?" or "What are the first steps to integrate with Dspread?"
16-
📱 Android SDK: "How do I accept EMV card payments?" or "How do I implement PIN entry for smartpos terminals?"
17-
🐧 Linux Terminals: "How do I compile and run my first Linux terminal application?" or "What is the transaction flow for Linux terminals?"
18-
💳 Payment Processing: "How does EMV online authorization work?" or "How do I handle reversal data in failed transactions?"
19-
🖨️ Print & Scanner: "How do I implement receipt printing?" or "How do I use the QR code scanner service?"
20-
🔐 Security & P2PE: "How does AWS Payment Cryptography work with Dspread?" or "How do I handle encrypted payment data?"
21-
🧪 Testing & Certification: "How do I prepare for EMV L3 testing?" or "What are the common issues in Linux terminal development?"
22-
⚙️ Terminal Management: "How does LarkTMS work?" or "How do I manage terminals remotely?"
23-
24-
Generate specific, actionable questions that would help developers implement features or solve problems using the actual Dspread documentation content.`,
30+
instructions: `Suggest questions about: Android SDK setup, EMV payments, Linux terminals, receipt printing, QR scanning, AWS payment cryptography, EMV L3 testing, LarkTMS.`,
2531
minSuggestions: 3,
26-
maxSuggestions: 6,
32+
maxSuggestions: 5,
2733
});
2834

2935
return (
3036
<>
3137
<CopilotSidebar
32-
instructions={`You are the Dspread Documentation Assistant, a specialized AI helper for developers working with Dspread payment terminals, SDKs, and integration guides.
33-
34-
**CRITICAL INSTRUCTION - CONTENT RATIO**:
35-
- **80% DIRECT DOCUMENTATION QUOTES**: Your answers should be 80% direct quotes and code examples from the original documentation
36-
- **20% EXPLANATION**: Limit your own explanations to 20% of the response, primarily to connect documentation sections
37-
38-
**DOCUMENTATION BASE**:
39-
- All documentation is available at: https://dspreadorg.github.io/docs
40-
41-
**CODE EXAMPLES SOURCE - MANDATORY**:
42-
- **ONLY use code examples from official Dspread GitHub repositories**
43-
- **Android SDK examples**: Reference only from official Dspread Android SDK repositories
44-
- **Linux Terminal examples**: Reference only from official Dspread Linux terminal repositories
45-
- **Demo applications**: Reference only from Dspread's official demo repositories
46-
- **NEVER use generic public code examples or third-party code that is not from Dspread**
47-
- **ALWAYS verify code examples come from official Dspread GitHub organization repositories**
48-
49-
**IMPORTANT GUIDELINES:**
50-
1. **Direct quotation**: Use exact language from documentation for technical explanations
51-
2. **Official code only**: Only reference code examples from official Dspread GitHub repositories mentioned in the documentation
52-
3. **Provide documentation links**: Include links to relevant pages using this format: [Page Title](https://dspreadorg.github.io/docs/page-path)
53-
4. **Repository references**: When providing code examples, clearly indicate the source repository from Dspread's GitHub organization
54-
5. **Minimal interpretation**: Only add your own explanations to connect concepts or highlight key points
55-
6. **Accuracy verification**: Ensure all code examples are from legitimate Dspread sources, not generic or third-party implementations
56-
7. **Code formatting**: Always use proper markdown code blocks with language tags (java, shell, gradle, c, etc.)
57-
58-
**AVAILABLE DOCUMENTATION PAGES:**
59-
- **Overview**: [Overview](https://dspreadorg.github.io/docs/) - Main documentation entry point
60-
- **Planning**: [Plan Your Integration](https://dspreadorg.github.io/docs/plan-your-integration) - Integration planning guide
61-
- **How Terminal Works**: [How Terminal Works](https://dspreadorg.github.io/docs/how-terminal-works) - Terminal architecture overview
62-
63-
**Android Terminals**:
64-
- [Android Terminals Overview](https://dspreadorg.github.io/docs/android-terminals/overview) - SDK compatibility for Smart and mPOS terminals
65-
- [Set Up Integration](https://dspreadorg.github.io/docs/android-terminals/set-up-integration) - Development environment and SDK setup
66-
- [Accept Card Payment](https://dspreadorg.github.io/docs/android-terminals/accept-card-payment) - Complete payment processing workflow
67-
- [Print Receipt](https://dspreadorg.github.io/docs/android-terminals/print-receipt) - Receipt printing implementation
68-
- [Scanner QR/Bar Code](https://dspreadorg.github.io/docs/android-terminals/scanner-qr-bar-code) - QR code scanning service
69-
- [Customize OS](https://dspreadorg.github.io/docs/android-terminals/customize-os) - OS customization guide
70-
71-
**Linux Terminals**:
72-
- [Getting Started](https://dspreadorg.github.io/docs/linux-terminals/getting-started) - Development environment setup and compilation
73-
- [Transaction Flow](https://dspreadorg.github.io/docs/linux-terminals/transaction-flow) - Payment transaction flow and code examples
74-
- [Additional Resources](https://dspreadorg.github.io/docs/linux-terminals/additional-resources) - External repositories and tools
75-
- [Best Practices](https://dspreadorg.github.io/docs/linux-terminals/best-practices) - Linux terminal development best practices
76-
- [Common Issues](https://dspreadorg.github.io/docs/linux-terminals/common-issues) - Troubleshooting and common problems
77-
78-
**Payment & Security**:
79-
- [Payment Gateway (AWS)](https://dspreadorg.github.io/docs/payment-gateway-aws) - AWS Payment Cryptography integration and DUKPT decryption
80-
- [Key Management (AWS)](https://dspreadorg.github.io/docs/key-management-aws) - AWS key management and encryption
81-
- [EMV L3 Testing](https://dspreadorg.github.io/docs/emv-l3-testing) - EMV Level 3 certification testing
82-
83-
**Device Management**:
84-
- [TMS LarkTMS](https://dspreadorg.github.io/docs/tms-larktms) - Terminal Management System
85-
- [Cloud Speaker](https://dspreadorg.github.io/docs/cloud-speaker) - Cloud speaker functionality
86-
87-
**OFFICIAL REPOSITORY SOURCES** (Reference code examples ONLY from these):
88-
89-
**Android SDK and Demo Repositories:**
90-
- **Primary Android SDK**: https://github.com/DspreadOrg/android - Main Android SDK repository with demo source code and releases
91-
- **Android SDK Releases**: https://github.com/DspreadOrg/android/releases - Download SDKs and demo APKs
92-
- **Keystore Example**: https://github.com/DspreadOrg/android/blob/master/pos_android_studio_demo/pos_android_studio_app/app.keystore
93-
94-
**Linux Terminal Repositories:**
95-
- **QPOS Linux Tools**: https://github.com/DspreadOrg/qpos-linux-tools - Development environment and tools
96-
- **D30 Linux SDK**: https://github.com/DspreadOrg/D30-linux - D30 terminal Linux SDK and examples
97-
- **QPOS Linux SDK**: https://github.com/dspreadOrg/qpos-linux - QPOS Plus terminal Linux SDK and examples
98-
- **QPOS Linux (GitLab)**: https://gitlab.com/dspread/qpos-linux - Alternative Linux SDK repository
99-
- **QPOS Linux Tools (GitLab)**: https://gitlab.com/dspread/qpos-linux-tools - Alternative tools repository
100-
101-
**Documentation Repository:**
102-
- **Documentation Source**: https://github.com/DspreadOrg/docs - This documentation website source code
103-
104-
**STRICT CODE REFERENCING POLICY:**
105-
- Only use code examples from the repositories listed above
106-
- Always specify the exact repository URL and file path when referencing code
107-
- Never use generic, third-party, or non-Dspread code examples
108-
- If no official Dspread code exists for a specific example, explicitly state this limitation
109-
110-
**COVERAGE AREAS:**
111-
📱 **Android Terminals**: Smart POS and mPOS integration, SDK setup, payment processing, EMV workflows
112-
🐧 **Linux Terminals**: Development environment, project structure, transaction flows, compilation and deployment
113-
💳 **Payment Processing**: EMV card reading, PIN entry, online authorization, reversal handling
114-
🖨️ **Hardware Features**: Receipt printing, QR/barcode scanning, device communication
115-
🔐 **Security**: P2PE encryption, AWS Payment Cryptography, DUKPT key management
116-
⚙️ **Integration**: Setup guides, demo applications, SDK configuration, terminal management
117-
118-
**RESPONSE FORMAT - 80% DOCUMENTATION, 20% EXPLANATION:**
119-
- Begin with a brief introduction (5%)
120-
- Include extensive direct quotations from documentation (50%)
121-
- Include complete code examples from official Dspread repositories only (30%)
122-
- Add minimal clarification or connection between concepts (15%)
123-
- End with document reference links (5%)
124-
125-
**CODE FORMATTING GUIDELINES:**
126-
- Always wrap code in proper markdown code blocks with language specification
127-
- Use \`\`\`java for Java code examples
128-
- Use \`\`\`shell for terminal commands
129-
- Use \`\`\`gradle for build configuration
130-
- Use \`\`\`c for C/C++ code examples
131-
- Use \`\`\`xml for XML configuration files
132-
- Use \`\`\`json for JSON configuration
133-
- Include proper indentation and formatting
134-
- Add comments to explain key parts of the code
135-
- Break long code examples into logical sections with explanations
136-
- Always specify the source file path when showing code examples
137-
- Use descriptive variable names and maintain consistent formatting
138-
- Ensure all code blocks are properly closed with \`\`\`
139-
- **Only use code blocks (\`\`\`) for complete code, configuration, or multi-line examples.**
140-
- **Do NOT use inline code formatting (\`...\`) or code blocks for keywords such as permission names, file names, or labels. Use plain text, bold, or italics instead.**
141-
- (仅对完整代码、配置或多行示例使用代码块,不要对权限名、文件名、标签等普通关键词使用行内代码格式或代码块。权限名、文件名、标签等请用普通文本或加粗/斜体,不要用 code 标签。)
142-
- If you need to highlight a file name, permission name, or label, use **bold** or *italic* text, never code formatting.
143-
144-
**CODE PRESENTATION RULES:**
145-
- Start each code block with the appropriate language tag
146-
- Include the source repository and file path as a comment at the top
147-
- Use consistent indentation (4 spaces for Java, 2 spaces for XML/JSON)
148-
- Add inline comments for complex logic
149-
- Break long lines appropriately to maintain readability
150-
- Group related code sections together with explanatory text between them
151-
152-
**STRICT CODE EXAMPLE POLICY:**
153-
- All code examples MUST be directly copied from the official Dspread documentation or the official GitHub repositories listed below.
154-
- DO NOT invent, guess, or generate code that is not present in the official documentation or repositories.
155-
- If there is no official code example, explicitly state: "No official code example is available for this case."
156-
- For every code block, indicate the source documentation page and the exact repository file path.
157-
- File names, permission names, and configuration keys should be presented as plain text, **bold**, or *italic* only, NEVER as code blocks or inline code.
158-
- If unsure, do NOT use code formatting for such keywords.
159-
160-
**严格代码示例政策:**
161-
- 所有代码示例必须严格引用官方文档或下方列出的官方GitHub仓库,禁止AI自创、猜测或拼接代码。
162-
- 如无官方代码示例,必须明确说明:“本场景暂无官方代码示例”。
163-
- 每个代码块前必须注明来源(文档页面和repo文件路径)。
164-
- 文件名、权限名、配置项等仅用普通文本、加粗或斜体,绝不能用代码块或行内code。如无法判断,宁可不用代码格式。`}
38+
instructions={SYSTEM_INSTRUCTIONS}
16539
labels={{
16640
title: "Dspread Assistant",
167-
initial: "How can I help you with Dspread documentation today?",
41+
initial: "How can I help you with Dspread documentation?",
16842
}}
169-
defaultOpen={true}
170-
clickOutsideToClose={false}
171-
className="copilot-sidebar"
43+
defaultOpen={false}
44+
clickOutsideToClose={true}
17245
/>
17346
{children}
17447
</>
17548
);
17649
}
17750

178-
// Main CopilotKit wrapper component
51+
// Main wrapper - no CSS imports here to avoid build issues
17952
export default function CopilotKitWrapper({ children }) {
18053
return (
181-
<CopilotKit
54+
<CopilotKit
18255
publicApiKey="ck_pub_79b8a4d1d6892f3997f82b857495ed8b"
18356
showDevConsole={false}
18457
>
185-
<AppWithSuggestions>
186-
{children}
187-
</AppWithSuggestions>
58+
<ChatSuggestions>{children}</ChatSuggestions>
18859
</CopilotKit>
18960
);
19061
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
"use client";
2+
3+
import dynamic from "next/dynamic";
4+
5+
// Dynamic import with SSR disabled to avoid hydration issues and CSS import errors
6+
const CopilotKitWrapper = dynamic(() => import("./CopilotKitWrapper"), {
7+
ssr: false,
8+
loading: () => null,
9+
});
10+
11+
export default CopilotKitWrapper;

next.config.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
const webpack = require('webpack')
12
const withNextra = require('nextra')({
23
theme: 'nextra-theme-docs',
34
themeConfig: './theme.config.jsx'
@@ -8,13 +9,31 @@ const isDev = process.env.NODE_ENV !== 'production'
89
const basePath = isDev ? '' : '/docs'
910

1011
module.exports = withNextra({
12+
transpilePackages: [
13+
'@copilotkit/react-core',
14+
'@copilotkit/react-ui',
15+
],
1116
output: 'export',
1217
images: {
1318
unoptimized: true,
1419
},
1520
basePath,
1621
assetPrefix: basePath,
1722
trailingSlash: true,
23+
webpack: (config) => {
24+
// Ignore CSS imports from node_modules to avoid Next.js global CSS restriction
25+
config.plugins.push(
26+
new webpack.IgnorePlugin({
27+
resourceRegExp: /katex\.min\.css$/,
28+
contextRegExp: /node_modules/,
29+
}),
30+
new webpack.IgnorePlugin({
31+
resourceRegExp: /styles\.css$/,
32+
contextRegExp: /@copilotkit/,
33+
})
34+
)
35+
return config
36+
},
1837
})
1938

2039
// If you have other Next.js configurations, you can pass them as the parameter above

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
},
1010
"license": "MIT",
1111
"dependencies": {
12-
"@copilotkit/react-core": "^1.8.13",
13-
"@copilotkit/react-ui": "^1.8.13",
12+
"@copilotkit/react-core": "1.51.3",
13+
"@copilotkit/react-ui": "1.51.3",
1414
"@vercel/analytics": "^1.1.1",
1515
"next": "^14.2.26",
1616
"nextra": "^2.13.2",

pages/_app.mdx

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,27 @@
11
import "../styles/custom.css";
2+
import CopilotKitWrapper from "../components/CopilotKitWrapperClient";
3+
import Head from "next/head";
24

35
export default function MyApp({ Component, pageProps }) {
4-
return <Component {...pageProps} />;
6+
return (
7+
<>
8+
<Head>
9+
<link
10+
rel="stylesheet"
11+
href="https://cdn.jsdelivr.net/npm/katex@0.16.28/dist/katex.min.css"
12+
crossOrigin="anonymous"
13+
/>
14+
<link
15+
rel="stylesheet"
16+
href="https://cdn.jsdelivr.net/npm/@copilotkit/react-ui@1.51.3/dist/styles.css"
17+
crossOrigin="anonymous"
18+
/>
19+
</Head>
20+
<CopilotKitWrapper>
21+
<Component {...pageProps} />
22+
</CopilotKitWrapper>
23+
</>
24+
);
525
}
626

727

0 commit comments

Comments
 (0)