@sensedealai/cuecue 1.0.5
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/.github/workflows/npm-publish.yml +35 -0
- package/LICENSE +201 -0
- package/README.md +220 -0
- package/package.json +34 -0
- package/src/cli.ts +210 -0
- package/src/client.ts +242 -0
- package/src/index.test.ts +96 -0
- package/src/index.ts +17 -0
- package/src/types.ts +62 -0
- package/tsconfig.json +20 -0
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# This workflow will run tests using node and then publish a package to GitHub Packages when a release is created
|
|
2
|
+
# For more information see: https://docs.github.com/en/actions/publishing-packages/publishing-nodejs-packages
|
|
3
|
+
|
|
4
|
+
name: Node.js Package
|
|
5
|
+
|
|
6
|
+
on:
|
|
7
|
+
release:
|
|
8
|
+
types: [created]
|
|
9
|
+
|
|
10
|
+
jobs:
|
|
11
|
+
build:
|
|
12
|
+
runs-on: ubuntu-latest
|
|
13
|
+
steps:
|
|
14
|
+
- uses: actions/checkout@v4
|
|
15
|
+
- uses: actions/setup-node@v4
|
|
16
|
+
with:
|
|
17
|
+
node-version: 20
|
|
18
|
+
- run: npm ci
|
|
19
|
+
- run: npm test
|
|
20
|
+
|
|
21
|
+
publish-npm:
|
|
22
|
+
needs: build
|
|
23
|
+
runs-on: ubuntu-latest
|
|
24
|
+
steps:
|
|
25
|
+
- uses: actions/checkout@v4
|
|
26
|
+
- uses: actions/setup-node@v4
|
|
27
|
+
with:
|
|
28
|
+
node-version: 20
|
|
29
|
+
registry-url: https://registry.npmjs.org/
|
|
30
|
+
- run: npm ci
|
|
31
|
+
- name: Update package version
|
|
32
|
+
run: npm version ${{ github.event.release.tag_name }} --no-git-tag-version --allow-same-version
|
|
33
|
+
- run: npm publish --access public
|
|
34
|
+
env:
|
|
35
|
+
NODE_AUTH_TOKEN: ${{secrets.npm_token}}
|
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
# CueCue SDK
|
|
2
|
+
|
|
3
|
+
<p align="center">
|
|
4
|
+
<a href="https://www.npmjs.com/package/@sensedealai/cuecue">
|
|
5
|
+
<img src="https://img.shields.io/npm/v/@sensedealai/cuecue.svg" alt="npm version">
|
|
6
|
+
</a>
|
|
7
|
+
<a href="https://opensource.org/licenses/Apache-2.0">
|
|
8
|
+
<img src="https://img.shields.io/badge/License-Apache%202.0-yellow.svg" alt="License: Apache 2.0">
|
|
9
|
+
</a>
|
|
10
|
+
</p>
|
|
11
|
+
|
|
12
|
+
> Conduct deep financial research using CueCue's AI-powered multi-agent system
|
|
13
|
+
|
|
14
|
+
CueCue SDK is a TypeScript library and CLI tool that enables developers and researchers to leverage CueCue's AI-powered multi-agent system for comprehensive financial research and analysis.
|
|
15
|
+
|
|
16
|
+
## Features
|
|
17
|
+
|
|
18
|
+
- 🤖 **AI-Powered Research** - Leverage multi-agent AI system for in-depth research
|
|
19
|
+
- 📡 **Real-time Streaming** - SSE-based streaming for live progress updates
|
|
20
|
+
- 📋 **Task Tracking** - Monitor individual research tasks as they complete
|
|
21
|
+
- 📝 **Report Generation** - Automatically generate comprehensive research reports
|
|
22
|
+
- 🔄 **Conversation Continuity** - Continue existing research conversations
|
|
23
|
+
- 📋 **Templates** - Use predefined research frameworks
|
|
24
|
+
- 🎨 **Style Mimicry** - Mimic writing styles from any URL
|
|
25
|
+
|
|
26
|
+
## Installation
|
|
27
|
+
|
|
28
|
+
``` bash
|
|
29
|
+
npm install @sensedealai/cuecue
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## CLI Usage
|
|
33
|
+
|
|
34
|
+
### Basic Usage
|
|
35
|
+
|
|
36
|
+
``` bash
|
|
37
|
+
# Set your API key (recommended)
|
|
38
|
+
export CUECUE_API_KEY=your_api_key
|
|
39
|
+
|
|
40
|
+
# Run a research query
|
|
41
|
+
cuecue-research "Tesla Q3 2024 revenue analysis"
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### Command Options
|
|
45
|
+
|
|
46
|
+
| Option | Description |
|
|
47
|
+
|--------|-------------|
|
|
48
|
+
| `--api-key KEY` | CueCue API key (defaults to `CUECUE_API_KEY` env var) |
|
|
49
|
+
| `--base-url URL` | CueCue API base URL (defaults to `https://cuecue.cn`) |
|
|
50
|
+
| `--conversation-id ID` | Continue an existing conversation |
|
|
51
|
+
| `--template-id ID` | Use a predefined research framework |
|
|
52
|
+
| `--mimic-url URL` | Mimic writing style from a URL |
|
|
53
|
+
| `--output, -o FILE` | Save report to file (markdown format) |
|
|
54
|
+
| `--verbose, -v` | Enable verbose logging |
|
|
55
|
+
| `--help, -h` | Show help message |
|
|
56
|
+
|
|
57
|
+
### Examples
|
|
58
|
+
|
|
59
|
+
``` bash
|
|
60
|
+
# Specify API key directly
|
|
61
|
+
cuecue-research "Tesla Q3 2024 revenue" --api-key YOUR_KEY
|
|
62
|
+
|
|
63
|
+
# Save report to file
|
|
64
|
+
cuecue-research "BYD financial analysis" --output report.md
|
|
65
|
+
|
|
66
|
+
# Continue existing conversation
|
|
67
|
+
cuecue-research "Further analysis" --conversation-id CONV_ID
|
|
68
|
+
|
|
69
|
+
# Use a template
|
|
70
|
+
cuecue-research "Company analysis" --template-id TEMPLATE_ID
|
|
71
|
+
|
|
72
|
+
# Mimic writing style from a URL
|
|
73
|
+
cuecue-research "Market analysis" --mimic-url https://example.com/article
|
|
74
|
+
|
|
75
|
+
# Enable verbose logging
|
|
76
|
+
cuecue-research "Analysis topic" --verbose
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## Library Usage
|
|
80
|
+
|
|
81
|
+
### Import and Initialize
|
|
82
|
+
|
|
83
|
+
``` typescript
|
|
84
|
+
import { CueCueDeepResearch } from '@sensedealai/cuecue';
|
|
85
|
+
|
|
86
|
+
// Initialize with your API key
|
|
87
|
+
const client = new CueCueDeepResearch('your-api-key');
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### Basic Research
|
|
91
|
+
|
|
92
|
+
``` typescript
|
|
93
|
+
import { CueCueDeepResearch } from '@sensedealai/cuecue';
|
|
94
|
+
|
|
95
|
+
const client = new CueCueDeepResearch('your-api-key');
|
|
96
|
+
|
|
97
|
+
const result = await client.research('Tesla Q3 2024 revenue analysis');
|
|
98
|
+
|
|
99
|
+
console.log(`Conversation ID: ${result.conversationId}`);
|
|
100
|
+
console.log(`Report URL: ${result.reportUrl}`);
|
|
101
|
+
console.log(`Report: ${result.report}`);
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
### Advanced Options
|
|
105
|
+
|
|
106
|
+
``` typescript
|
|
107
|
+
const result = await client.research('Company analysis', {
|
|
108
|
+
// Continue existing conversation
|
|
109
|
+
conversationId: 'existing-conversation-id',
|
|
110
|
+
|
|
111
|
+
// Use a predefined template
|
|
112
|
+
templateId: 'template-id',
|
|
113
|
+
|
|
114
|
+
// Mimic writing style from URL
|
|
115
|
+
mimicUrl: 'https://example.com/article',
|
|
116
|
+
|
|
117
|
+
// Enable verbose logging
|
|
118
|
+
verbose: true,
|
|
119
|
+
});
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
### Using Custom Base URL
|
|
123
|
+
|
|
124
|
+
``` typescript
|
|
125
|
+
const client = new CueCueDeepResearch('your-api-key', 'https://custom-api.example.com');
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
## API Reference
|
|
129
|
+
|
|
130
|
+
### `CueCueDeepResearch`
|
|
131
|
+
|
|
132
|
+
#### Constructor
|
|
133
|
+
|
|
134
|
+
``` typescript
|
|
135
|
+
constructor(apiKey: string, baseUrl?: string)
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
- `apiKey` - Your CueCue API key
|
|
139
|
+
- `baseUrl` - Optional custom base URL (defaults to `https://cuecue.cn`)
|
|
140
|
+
|
|
141
|
+
#### Methods
|
|
142
|
+
|
|
143
|
+
##### `research(query: string, options?: ResearchOptions): Promise<ResearchResult>`
|
|
144
|
+
|
|
145
|
+
Execute a deep research query.
|
|
146
|
+
|
|
147
|
+
- `query` - The research question or topic
|
|
148
|
+
- `options` - Optional research parameters (see `ResearchOptions`)
|
|
149
|
+
- Returns: `Promise<ResearchResult>`
|
|
150
|
+
|
|
151
|
+
### Type Definitions
|
|
152
|
+
|
|
153
|
+
#### `ResearchOptions`
|
|
154
|
+
|
|
155
|
+
``` typescript
|
|
156
|
+
interface ResearchOptions {
|
|
157
|
+
conversationId?: string; // Continue existing conversation
|
|
158
|
+
templateId?: string; // Template ID for predefined framework
|
|
159
|
+
mimicUrl?: string; // URL to mimic writing style
|
|
160
|
+
verbose?: boolean; // Enable verbose logging
|
|
161
|
+
}
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
#### `ResearchResult`
|
|
165
|
+
|
|
166
|
+
``` typescript
|
|
167
|
+
interface ResearchResult {
|
|
168
|
+
conversationId: string; // Unique conversation identifier
|
|
169
|
+
chatId: string; // Chat session identifier
|
|
170
|
+
tasks: string[]; // List of research tasks completed
|
|
171
|
+
report: string; // Generated research report
|
|
172
|
+
reportUrl: string; // URL to view report online
|
|
173
|
+
}
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
#### SSE Events
|
|
177
|
+
|
|
178
|
+
The library also exports types for SSE events:
|
|
179
|
+
|
|
180
|
+
``` typescript
|
|
181
|
+
import type {
|
|
182
|
+
SSEEvent,
|
|
183
|
+
RequestPayload,
|
|
184
|
+
AgentStartEvent,
|
|
185
|
+
AgentEndEvent,
|
|
186
|
+
MessageEvent,
|
|
187
|
+
FinalSessionStateEvent,
|
|
188
|
+
} from '@sensedealai/cuecue';
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
## Getting an API Key
|
|
192
|
+
|
|
193
|
+
1. Log in to CueCue at [https://cuecue.cn](https://cuecue.cn)
|
|
194
|
+
2. Go to Settings → API Keys
|
|
195
|
+
3. Generate a new API key
|
|
196
|
+
|
|
197
|
+
## Building from Source
|
|
198
|
+
|
|
199
|
+
``` bash
|
|
200
|
+
# Install dependencies
|
|
201
|
+
npm install
|
|
202
|
+
|
|
203
|
+
# Build TypeScript
|
|
204
|
+
npm run build
|
|
205
|
+
|
|
206
|
+
# Run CLI
|
|
207
|
+
npm run cli "your research query"
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
## License
|
|
211
|
+
|
|
212
|
+
Apache 2.0 License - see [LICENSE](LICENSE) file for details.
|
|
213
|
+
|
|
214
|
+
## Keywords
|
|
215
|
+
|
|
216
|
+
- research
|
|
217
|
+
- financial-analysis
|
|
218
|
+
- ai-agents
|
|
219
|
+
- report-generation
|
|
220
|
+
- data-analysis
|
package/package.json
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@sensedealai/cuecue",
|
|
3
|
+
"version": "1.0.5",
|
|
4
|
+
"description": "TypeScript SDK for CueCue's AI-powered multi-agent research system",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"bin": {
|
|
8
|
+
"cuecue-research": "dist/cli.js"
|
|
9
|
+
},
|
|
10
|
+
"scripts": {
|
|
11
|
+
"build": "tsc",
|
|
12
|
+
"dev": "tsc --watch",
|
|
13
|
+
"cli": "node dist/cli.js",
|
|
14
|
+
"test": "vitest",
|
|
15
|
+
"lint": "eslint src --ext .ts"
|
|
16
|
+
},
|
|
17
|
+
"keywords": [
|
|
18
|
+
"research",
|
|
19
|
+
"financial-analysis",
|
|
20
|
+
"ai-agents",
|
|
21
|
+
"report-generation",
|
|
22
|
+
"data-analysis"
|
|
23
|
+
],
|
|
24
|
+
"author": "CueCue Team",
|
|
25
|
+
"license": "Apache-2.0",
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"axios": "^1.6.0"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"@types/node": "^20.0.0",
|
|
31
|
+
"typescript": "^5.0.0",
|
|
32
|
+
"vitest": "^1.0.0"
|
|
33
|
+
}
|
|
34
|
+
}
|
package/src/cli.ts
ADDED
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* CueCue Deep Research CLI
|
|
5
|
+
*
|
|
6
|
+
* Command-line interface for conducting deep research using CueCue's
|
|
7
|
+
* AI-powered multi-agent system.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import fs from 'fs';
|
|
11
|
+
import path from 'path';
|
|
12
|
+
import { CueCueDeepResearch } from './client.js';
|
|
13
|
+
|
|
14
|
+
interface CLIArgs {
|
|
15
|
+
query: string;
|
|
16
|
+
apiKey?: string;
|
|
17
|
+
baseUrl: string;
|
|
18
|
+
conversationId?: string;
|
|
19
|
+
templateId?: string;
|
|
20
|
+
mimicUrl?: string;
|
|
21
|
+
output?: string;
|
|
22
|
+
verbose: boolean;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function parseArgs(): CLIArgs {
|
|
26
|
+
const args = process.argv.slice(2);
|
|
27
|
+
|
|
28
|
+
if (args.length === 0 || args.includes('--help') || args.includes('-h')) {
|
|
29
|
+
printHelp();
|
|
30
|
+
process.exit(0);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const result: CLIArgs = {
|
|
34
|
+
query: '',
|
|
35
|
+
baseUrl: process.env.CUECUE_BASE_URL || 'https://cuecue.cn',
|
|
36
|
+
verbose: false,
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
for (let i = 0; i < args.length; i++) {
|
|
40
|
+
const arg = args[i];
|
|
41
|
+
|
|
42
|
+
// Handle --key=value format
|
|
43
|
+
if (arg.includes('=')) {
|
|
44
|
+
const [key, value] = arg.split('=');
|
|
45
|
+
if (key === '--api-key') {
|
|
46
|
+
result.apiKey = value;
|
|
47
|
+
} else if (key === '--base-url') {
|
|
48
|
+
result.baseUrl = value;
|
|
49
|
+
} else if (key === '--conversation-id') {
|
|
50
|
+
result.conversationId = value;
|
|
51
|
+
} else if (key === '--template-id') {
|
|
52
|
+
result.templateId = value;
|
|
53
|
+
} else if (key === '--mimic-url') {
|
|
54
|
+
result.mimicUrl = value;
|
|
55
|
+
} else if (key === '--output' || key === '-o') {
|
|
56
|
+
result.output = value;
|
|
57
|
+
}
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// Handle --key value format
|
|
62
|
+
if (arg === '--api-key') {
|
|
63
|
+
result.apiKey = args[++i];
|
|
64
|
+
} else if (arg === '--base-url') {
|
|
65
|
+
result.baseUrl = args[++i];
|
|
66
|
+
} else if (arg === '--conversation-id') {
|
|
67
|
+
result.conversationId = args[++i];
|
|
68
|
+
} else if (arg === '--template-id') {
|
|
69
|
+
result.templateId = args[++i];
|
|
70
|
+
} else if (arg === '--mimic-url') {
|
|
71
|
+
result.mimicUrl = args[++i];
|
|
72
|
+
} else if (arg === '--output' || arg === '-o') {
|
|
73
|
+
result.output = args[++i];
|
|
74
|
+
} else if (arg === '--verbose' || arg === '-v') {
|
|
75
|
+
result.verbose = true;
|
|
76
|
+
} else if (!arg.startsWith('--') && !arg.startsWith('-')) {
|
|
77
|
+
result.query = arg;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return result;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function printHelp(): void {
|
|
85
|
+
console.log(`
|
|
86
|
+
CueCue Deep Research - AI-powered research assistant
|
|
87
|
+
|
|
88
|
+
Usage:
|
|
89
|
+
cuecue-research <query> [options]
|
|
90
|
+
|
|
91
|
+
Arguments:
|
|
92
|
+
query Research question or topic
|
|
93
|
+
|
|
94
|
+
Options:
|
|
95
|
+
--api-key KEY CueCue API key (defaults to CUECUE_API_KEY env var)
|
|
96
|
+
--base-url URL CueCue API base URL (defaults to CUECUE_BASE_URL or https://cuecue.cn)
|
|
97
|
+
--conversation-id ID Conversation ID to continue an existing conversation
|
|
98
|
+
--template-id ID Template ID to use a predefined research framework
|
|
99
|
+
--mimic-url URL URL to mimic the writing style from
|
|
100
|
+
--output, -o FILE Output file path to save the report (markdown format)
|
|
101
|
+
--verbose, -v Enable verbose logging
|
|
102
|
+
--help, -h Show this help message
|
|
103
|
+
|
|
104
|
+
Examples:
|
|
105
|
+
# Basic research (using environment variable)
|
|
106
|
+
export CUECUE_API_KEY=your_key
|
|
107
|
+
cuecue-research "Tesla Q3 2024 revenue"
|
|
108
|
+
|
|
109
|
+
# Or specify API key directly
|
|
110
|
+
cuecue-research "Tesla Q3 2024 revenue" --api-key YOUR_KEY
|
|
111
|
+
|
|
112
|
+
# Save report to file
|
|
113
|
+
cuecue-research "BYD financial analysis" --output report.md
|
|
114
|
+
|
|
115
|
+
# Continue existing conversation
|
|
116
|
+
cuecue-research "Further analysis" --conversation-id CONV_ID
|
|
117
|
+
|
|
118
|
+
# Use a template
|
|
119
|
+
cuecue-research "Company analysis" --template-id TEMPLATE_ID
|
|
120
|
+
|
|
121
|
+
# Mimic writing style from a URL
|
|
122
|
+
cuecue-research "Market analysis" --mimic-url https://example.com/article
|
|
123
|
+
|
|
124
|
+
For more information, visit: https://cuecue.cn
|
|
125
|
+
`);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
async function main(): Promise<void> {
|
|
129
|
+
const args = parseArgs();
|
|
130
|
+
|
|
131
|
+
// Validate API key
|
|
132
|
+
const apiKey = args.apiKey || process.env.CUECUE_API_KEY;
|
|
133
|
+
if (!apiKey) {
|
|
134
|
+
console.error('❌ Error: API key is required');
|
|
135
|
+
console.error('\nPlease provide an API key using one of these methods:');
|
|
136
|
+
console.error(' 1. Set environment variable: export CUECUE_API_KEY="your_key"');
|
|
137
|
+
console.error(' 2. Use command-line argument: --api-key YOUR_KEY');
|
|
138
|
+
console.error('\nTo obtain an API key:');
|
|
139
|
+
console.error(' 1. Log in to CueCue at https://cuecue.cn');
|
|
140
|
+
console.error(' 2. Go to Settings → API Keys');
|
|
141
|
+
console.error(' 3. Generate a new key');
|
|
142
|
+
process.exit(1);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// Validate query
|
|
146
|
+
if (!args.query) {
|
|
147
|
+
console.error('❌ Error: Research query is required');
|
|
148
|
+
console.error('Usage: cuecue-research <query> [options]');
|
|
149
|
+
console.error('Use --help for more information');
|
|
150
|
+
process.exit(1);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
try {
|
|
154
|
+
const client = new CueCueDeepResearch(apiKey, args.baseUrl);
|
|
155
|
+
|
|
156
|
+
const result = await client.research(args.query, {
|
|
157
|
+
conversationId: args.conversationId,
|
|
158
|
+
templateId: args.templateId,
|
|
159
|
+
mimicUrl: args.mimicUrl,
|
|
160
|
+
verbose: args.verbose,
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
// Print summary
|
|
164
|
+
console.log('\n' + '='.repeat(60));
|
|
165
|
+
console.log('📊 Research Summary');
|
|
166
|
+
console.log('='.repeat(60));
|
|
167
|
+
console.log(`Conversation ID: ${result.conversationId}`);
|
|
168
|
+
console.log(`Tasks completed: ${result.tasks.length}`);
|
|
169
|
+
console.log(`Report URL: ${result.reportUrl}`);
|
|
170
|
+
console.log(`Report length: ${result.report.length} characters`);
|
|
171
|
+
|
|
172
|
+
// Save report to file
|
|
173
|
+
if (args.output) {
|
|
174
|
+
try {
|
|
175
|
+
// Expand ~ to home directory
|
|
176
|
+
let outputPath = args.output;
|
|
177
|
+
if (outputPath.startsWith('~/')) {
|
|
178
|
+
const homeDir = process.env.HOME || process.env.USERPROFILE || '';
|
|
179
|
+
outputPath = path.join(homeDir, outputPath.slice(2));
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
const outputDir = path.dirname(outputPath);
|
|
183
|
+
if (outputDir !== '.' && !fs.existsSync(outputDir)) {
|
|
184
|
+
fs.mkdirSync(outputDir, { recursive: true });
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
if (args.verbose) {
|
|
188
|
+
console.log(`\n[DEBUG] Writing to: ${outputPath}`);
|
|
189
|
+
console.log(`[DEBUG] Content length: ${result.report.length}`);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
// Append report URL to the end of the report
|
|
193
|
+
const reportWithUrl = result.report + `\n\n---\n\n**Report URL:** ${result.reportUrl}\n`;
|
|
194
|
+
|
|
195
|
+
fs.writeFileSync(outputPath, reportWithUrl, 'utf-8');
|
|
196
|
+
console.log(`✅ Report saved to: ${outputPath}`);
|
|
197
|
+
} catch (fileError) {
|
|
198
|
+
console.error(`❌ Failed to save report: ${fileError}`);
|
|
199
|
+
if (args.verbose) {
|
|
200
|
+
console.error(fileError);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
} catch (error) {
|
|
205
|
+
console.error(`❌ Execution failed: ${error}`);
|
|
206
|
+
process.exit(1);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
main();
|
package/src/client.ts
ADDED
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CueCue Deep Research Client
|
|
3
|
+
*
|
|
4
|
+
* A client for interacting with CueCue's deep research API. This client
|
|
5
|
+
* handles authentication, request formatting, and streaming response parsing.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import axios, { AxiosInstance } from 'axios';
|
|
9
|
+
import { randomUUID } from 'crypto';
|
|
10
|
+
import { ResearchOptions, ResearchResult, RequestPayload, SSEEvent } from './types.js';
|
|
11
|
+
|
|
12
|
+
export class CueCueDeepResearch {
|
|
13
|
+
private apiKey: string;
|
|
14
|
+
private baseUrl: string;
|
|
15
|
+
private client: AxiosInstance;
|
|
16
|
+
|
|
17
|
+
constructor(apiKey: string, baseUrl: string = 'https://cuecue.cn') {
|
|
18
|
+
this.apiKey = apiKey;
|
|
19
|
+
this.baseUrl = baseUrl.replace(/\/$/, '');
|
|
20
|
+
this.client = axios.create({
|
|
21
|
+
baseURL: this.baseUrl,
|
|
22
|
+
headers: {
|
|
23
|
+
Authorization: `Bearer ${apiKey}`,
|
|
24
|
+
'Content-Type': 'application/json',
|
|
25
|
+
},
|
|
26
|
+
timeout: 3600000, // 1 hour
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Execute a deep research query
|
|
32
|
+
*
|
|
33
|
+
* @param query - The research question or topic
|
|
34
|
+
* @param options - Optional research parameters
|
|
35
|
+
* @returns Research result containing tasks, report, and URL
|
|
36
|
+
*/
|
|
37
|
+
async research(query: string, options: ResearchOptions = {}): Promise<ResearchResult> {
|
|
38
|
+
const conversationId = options.conversationId || randomUUID();
|
|
39
|
+
const chatId = randomUUID();
|
|
40
|
+
const messageId = `msg_${randomUUID()}`;
|
|
41
|
+
|
|
42
|
+
const reportUrl = `${this.baseUrl}/c/${conversationId}`;
|
|
43
|
+
console.log(`\nStarting Deep Research: ${query}\n`);
|
|
44
|
+
|
|
45
|
+
// Build request payload
|
|
46
|
+
const requestData: RequestPayload = {
|
|
47
|
+
messages: [
|
|
48
|
+
{
|
|
49
|
+
role: 'user',
|
|
50
|
+
content: query,
|
|
51
|
+
id: messageId,
|
|
52
|
+
type: 'text',
|
|
53
|
+
},
|
|
54
|
+
],
|
|
55
|
+
chat_id: chatId,
|
|
56
|
+
conversation_id: conversationId,
|
|
57
|
+
need_confirm: false,
|
|
58
|
+
need_analysis: false,
|
|
59
|
+
need_underlying: false,
|
|
60
|
+
need_recommend: false,
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
if (options.templateId) {
|
|
64
|
+
requestData.template_id = options.templateId;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (options.mimicUrl) {
|
|
68
|
+
requestData.mimic = { url: options.mimicUrl };
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// Initialize result container
|
|
72
|
+
const result: ResearchResult = {
|
|
73
|
+
conversationId,
|
|
74
|
+
chatId,
|
|
75
|
+
tasks: [],
|
|
76
|
+
report: '',
|
|
77
|
+
reportUrl,
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
// State tracking
|
|
81
|
+
const state = {
|
|
82
|
+
isReporter: false,
|
|
83
|
+
};
|
|
84
|
+
const reportContent: string[] = [];
|
|
85
|
+
|
|
86
|
+
try {
|
|
87
|
+
const response = await this.client.post('/api/chat/stream', requestData, {
|
|
88
|
+
responseType: 'stream',
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
await this.parseStream(response.data, result, reportContent, state);
|
|
92
|
+
|
|
93
|
+
// Ensure report is set even if end_of_agent wasn't received
|
|
94
|
+
if (!result.report && reportContent.length > 0) {
|
|
95
|
+
result.report = reportContent.join('');
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
if (options.verbose) {
|
|
99
|
+
console.log(`\n[DEBUG] Collected ${reportContent.length} content chunks`);
|
|
100
|
+
console.log(`[DEBUG] Total report length: ${result.report.length} characters`);
|
|
101
|
+
}
|
|
102
|
+
} catch (error) {
|
|
103
|
+
if (axios.isAxiosError(error)) {
|
|
104
|
+
console.error(`HTTP error: ${error.response?.status} - ${error.response?.data}`);
|
|
105
|
+
} else {
|
|
106
|
+
console.error(`Request failed: ${error}`);
|
|
107
|
+
}
|
|
108
|
+
throw error;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
return result;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Parse SSE stream from the API response
|
|
116
|
+
*/
|
|
117
|
+
private async parseStream(
|
|
118
|
+
stream: NodeJS.ReadableStream,
|
|
119
|
+
result: ResearchResult,
|
|
120
|
+
reportContent: string[],
|
|
121
|
+
state: { isReporter: boolean },
|
|
122
|
+
): Promise<void> {
|
|
123
|
+
return new Promise((resolve, reject) => {
|
|
124
|
+
let buffer = '';
|
|
125
|
+
let currentEvent: SSEEvent = {
|
|
126
|
+
type: 'message',
|
|
127
|
+
data: null,
|
|
128
|
+
id: null,
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
stream.on('data', (chunk: Buffer) => {
|
|
132
|
+
buffer += chunk.toString('utf-8');
|
|
133
|
+
const lines = buffer.split('\n');
|
|
134
|
+
|
|
135
|
+
// Keep the last incomplete line in the buffer
|
|
136
|
+
buffer = lines.pop() || '';
|
|
137
|
+
|
|
138
|
+
for (const line of lines) {
|
|
139
|
+
this.processSSELine(line, currentEvent, result, reportContent, state);
|
|
140
|
+
|
|
141
|
+
// Empty line marks end of event
|
|
142
|
+
if (line === '') {
|
|
143
|
+
currentEvent = {
|
|
144
|
+
type: 'message',
|
|
145
|
+
data: null,
|
|
146
|
+
id: null,
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
stream.on('end', () => {
|
|
153
|
+
// Process any remaining data
|
|
154
|
+
if (buffer) {
|
|
155
|
+
const lines = buffer.split('\n');
|
|
156
|
+
for (const line of lines) {
|
|
157
|
+
this.processSSELine(line, currentEvent, result, reportContent, state);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
resolve();
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
stream.on('error', reject);
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* Process a single SSE line
|
|
169
|
+
*/
|
|
170
|
+
private processSSELine(
|
|
171
|
+
line: string,
|
|
172
|
+
currentEvent: SSEEvent,
|
|
173
|
+
result: ResearchResult,
|
|
174
|
+
reportContent: string[],
|
|
175
|
+
state: { isReporter: boolean },
|
|
176
|
+
): void {
|
|
177
|
+
if (line.startsWith('id: ')) {
|
|
178
|
+
currentEvent.id = line.slice(4);
|
|
179
|
+
} else if (line.startsWith('event: ')) {
|
|
180
|
+
currentEvent.type = line.slice(7);
|
|
181
|
+
} else if (line.startsWith('data: ')) {
|
|
182
|
+
try {
|
|
183
|
+
currentEvent.data = JSON.parse(line.slice(6));
|
|
184
|
+
} catch (e) {
|
|
185
|
+
console.warn(`Failed to parse SSE data: ${e}`);
|
|
186
|
+
}
|
|
187
|
+
} else if (line === '' && currentEvent.data !== null) {
|
|
188
|
+
this.handleSSEEvent(currentEvent, result, reportContent, state);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* Handle a complete SSE event
|
|
194
|
+
*/
|
|
195
|
+
private handleSSEEvent(
|
|
196
|
+
event: SSEEvent,
|
|
197
|
+
result: ResearchResult,
|
|
198
|
+
reportContent: string[],
|
|
199
|
+
state: { isReporter: boolean },
|
|
200
|
+
): void {
|
|
201
|
+
const eventType = event.type;
|
|
202
|
+
const eventData = event.data as Record<string, unknown>;
|
|
203
|
+
|
|
204
|
+
if (!eventData) {
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
const agentName = eventData.agent_name as string;
|
|
209
|
+
|
|
210
|
+
if (eventType === 'start_of_agent') {
|
|
211
|
+
if (agentName === 'coordinator') {
|
|
212
|
+
console.log(`\nResearch begin. You can view progress at: ${result.reportUrl}\n`);
|
|
213
|
+
} else if (agentName === 'supervisor') {
|
|
214
|
+
const taskRequirement = eventData.task_requirement as string;
|
|
215
|
+
if (taskRequirement) {
|
|
216
|
+
result.tasks.push(taskRequirement);
|
|
217
|
+
console.log(`\n📋 Task: ${taskRequirement}`);
|
|
218
|
+
}
|
|
219
|
+
} else if (agentName === 'reporter') {
|
|
220
|
+
state.isReporter = true;
|
|
221
|
+
console.log('\n📝 Generating Report...\n');
|
|
222
|
+
}
|
|
223
|
+
} else if (eventType === 'end_of_agent') {
|
|
224
|
+
if (agentName === 'reporter') {
|
|
225
|
+
state.isReporter = false;
|
|
226
|
+
result.report = reportContent.join('');
|
|
227
|
+
}
|
|
228
|
+
} else if (eventType === 'message' && state.isReporter) {
|
|
229
|
+
// Use state variable instead of checking agent_name in message event
|
|
230
|
+
const delta = eventData.delta as Record<string, unknown>;
|
|
231
|
+
if (delta && delta.content) {
|
|
232
|
+
const content = delta.content as string;
|
|
233
|
+
// Remove citation markers like 【4-4】
|
|
234
|
+
const cleanedContent = content.replace(/【\d+-\d+】/g, '');
|
|
235
|
+
reportContent.push(cleanedContent);
|
|
236
|
+
process.stdout.write(cleanedContent);
|
|
237
|
+
}
|
|
238
|
+
} else if (eventType === 'final_session_state') {
|
|
239
|
+
console.log('\n\n✅ Research complete');
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
import {
|
|
3
|
+
CueCueDeepResearch,
|
|
4
|
+
type ResearchOptions,
|
|
5
|
+
type ResearchResult,
|
|
6
|
+
} from './index.js';
|
|
7
|
+
|
|
8
|
+
describe('CueCueDeepResearch', () => {
|
|
9
|
+
describe('constructor', () => {
|
|
10
|
+
it('should create a client with default base URL', () => {
|
|
11
|
+
const client = new CueCueDeepResearch('test-api-key');
|
|
12
|
+
expect(client).toBeDefined();
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it('should create a client with custom base URL', () => {
|
|
16
|
+
const client = new CueCueDeepResearch('test-api-key', 'https://custom.example.com');
|
|
17
|
+
expect(client).toBeDefined();
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it('should handle base URL with trailing slash', () => {
|
|
21
|
+
const client = new CueCueDeepResearch('test-api-key', 'https://cuecue.cn/');
|
|
22
|
+
expect(client).toBeDefined();
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
describe('ResearchOptions', () => {
|
|
28
|
+
it('should allow optional conversationId', () => {
|
|
29
|
+
const options: ResearchOptions = {};
|
|
30
|
+
expect(options.conversationId).toBeUndefined();
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it('should allow optional templateId', () => {
|
|
34
|
+
const options: ResearchOptions = {
|
|
35
|
+
templateId: 'template-123',
|
|
36
|
+
};
|
|
37
|
+
expect(options.templateId).toBe('template-123');
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it('should allow optional mimicUrl', () => {
|
|
41
|
+
const options: ResearchOptions = {
|
|
42
|
+
mimicUrl: 'https://example.com/article',
|
|
43
|
+
};
|
|
44
|
+
expect(options.mimicUrl).toBe('https://example.com/article');
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it('should allow optional verbose', () => {
|
|
48
|
+
const options: ResearchOptions = {
|
|
49
|
+
verbose: true,
|
|
50
|
+
};
|
|
51
|
+
expect(options.verbose).toBe(true);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it('should allow all options together', () => {
|
|
55
|
+
const options: ResearchOptions = {
|
|
56
|
+
conversationId: 'conv-123',
|
|
57
|
+
templateId: 'template-456',
|
|
58
|
+
mimicUrl: 'https://example.com/article',
|
|
59
|
+
verbose: true,
|
|
60
|
+
};
|
|
61
|
+
expect(options.conversationId).toBe('conv-123');
|
|
62
|
+
expect(options.templateId).toBe('template-456');
|
|
63
|
+
expect(options.mimicUrl).toBe('https://example.com/article');
|
|
64
|
+
expect(options.verbose).toBe(true);
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
describe('ResearchResult', () => {
|
|
69
|
+
it('should have required properties', () => {
|
|
70
|
+
const result: ResearchResult = {
|
|
71
|
+
conversationId: 'conv-123',
|
|
72
|
+
chatId: 'chat-456',
|
|
73
|
+
tasks: ['task1', 'task2'],
|
|
74
|
+
report: 'Test report content',
|
|
75
|
+
reportUrl: 'https://cuecue.cn/c/conv-123',
|
|
76
|
+
};
|
|
77
|
+
expect(result.conversationId).toBe('conv-123');
|
|
78
|
+
expect(result.chatId).toBe('chat-456');
|
|
79
|
+
expect(result.tasks).toHaveLength(2);
|
|
80
|
+
expect(result.report).toBe('Test report content');
|
|
81
|
+
expect(result.reportUrl).toBe('https://cuecue.cn/c/conv-123');
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it('should allow empty tasks array', () => {
|
|
85
|
+
const result: ResearchResult = {
|
|
86
|
+
conversationId: 'conv-123',
|
|
87
|
+
chatId: 'chat-456',
|
|
88
|
+
tasks: [],
|
|
89
|
+
report: '',
|
|
90
|
+
reportUrl: 'https://cuecue.cn/c/conv-123',
|
|
91
|
+
};
|
|
92
|
+
expect(result.tasks).toHaveLength(0);
|
|
93
|
+
expect(result.report).toBe('');
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CueCue Deep Research TypeScript Library
|
|
3
|
+
*
|
|
4
|
+
* Main export for the CueCue Deep Research skill.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
export { CueCueDeepResearch } from './client.js';
|
|
8
|
+
export type {
|
|
9
|
+
ResearchOptions,
|
|
10
|
+
ResearchResult,
|
|
11
|
+
SSEEvent,
|
|
12
|
+
RequestPayload,
|
|
13
|
+
AgentStartEvent,
|
|
14
|
+
AgentEndEvent,
|
|
15
|
+
MessageEvent,
|
|
16
|
+
FinalSessionStateEvent,
|
|
17
|
+
} from './types.js';
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type definitions for CueCue Deep Research
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
export interface ResearchOptions {
|
|
6
|
+
conversationId?: string;
|
|
7
|
+
templateId?: string;
|
|
8
|
+
mimicUrl?: string;
|
|
9
|
+
verbose?: boolean;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface ResearchResult {
|
|
13
|
+
conversationId: string;
|
|
14
|
+
chatId: string;
|
|
15
|
+
tasks: string[];
|
|
16
|
+
report: string;
|
|
17
|
+
reportUrl: string;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface SSEEvent {
|
|
21
|
+
type: string;
|
|
22
|
+
data: Record<string, unknown> | null;
|
|
23
|
+
id: string | null;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface RequestPayload {
|
|
27
|
+
messages: Array<{
|
|
28
|
+
role: string;
|
|
29
|
+
content: string;
|
|
30
|
+
id: string;
|
|
31
|
+
type: string;
|
|
32
|
+
}>;
|
|
33
|
+
chat_id: string;
|
|
34
|
+
conversation_id: string;
|
|
35
|
+
need_confirm: boolean;
|
|
36
|
+
need_analysis: boolean;
|
|
37
|
+
need_underlying: boolean;
|
|
38
|
+
need_recommend: boolean;
|
|
39
|
+
template_id?: string;
|
|
40
|
+
mimic?: {
|
|
41
|
+
url: string;
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export interface AgentStartEvent {
|
|
46
|
+
agent_name: string;
|
|
47
|
+
task_requirement?: string;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export interface AgentEndEvent {
|
|
51
|
+
agent_name: string;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export interface MessageEvent {
|
|
55
|
+
delta: {
|
|
56
|
+
content: string;
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export interface FinalSessionStateEvent {
|
|
61
|
+
[key: string]: unknown;
|
|
62
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2020",
|
|
4
|
+
"module": "ES2020",
|
|
5
|
+
"lib": ["ES2020"],
|
|
6
|
+
"outDir": "./dist",
|
|
7
|
+
"rootDir": "./src",
|
|
8
|
+
"strict": true,
|
|
9
|
+
"esModuleInterop": true,
|
|
10
|
+
"skipLibCheck": true,
|
|
11
|
+
"forceConsistentCasingInFileNames": true,
|
|
12
|
+
"resolveJsonModule": true,
|
|
13
|
+
"declaration": true,
|
|
14
|
+
"declarationMap": true,
|
|
15
|
+
"sourceMap": true,
|
|
16
|
+
"moduleResolution": "node"
|
|
17
|
+
},
|
|
18
|
+
"include": ["src/**/*"],
|
|
19
|
+
"exclude": ["node_modules", "dist"]
|
|
20
|
+
}
|