-
Notifications
You must be signed in to change notification settings - Fork 310
fix(robot): optimized the example and added sessions and UI adjustment. #3484
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,9 +29,9 @@ | |
"@docsearch/react": "npm:@docsearch/css", | ||
"@modelcontextprotocol/sdk": "1.12.1", | ||
"@opentiny/next": "0.1.2", | ||
"@opentiny/tiny-robot": "0.2.0-alpha.8", | ||
"@opentiny/tiny-robot-kit": "0.2.0-alpha.8", | ||
"@opentiny/tiny-robot-svgs": "0.2.0-alpha.8", | ||
"@opentiny/tiny-robot": "0.2.1", | ||
"@opentiny/tiny-robot-kit": "0.2.1", | ||
"@opentiny/tiny-robot-svgs": "0.2.1", | ||
Comment on lines
+32
to
+34
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Verification agent 🧩 Analysis chainGood dependency updates from alpha to stable versions. The consistent update of all tiny-robot packages from alpha versions to stable 🌐 Web query:
💡 Result: I couldn't find a package named If this isn't the package you're referring to, could you please provide more details or verify the package name? That would help me assist you more effectively. Citations: Verify package names and published versions The packages
Once confirmed or corrected, the dependency bump from alpha to stable can be finalized. 🤖 Prompt for AI Agents
|
||
"@opentiny/tiny-schema-renderer": "1.0.0-beta.5", | ||
"@opentiny/tiny-vue-mcp": "0.0.1-beta.1", | ||
"@opentiny/utils": "workspace:~", | ||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,4 +1,4 @@ | ||||||||||||||||||||||||||||||
import { reactive, computed } from 'vue' | ||||||||||||||||||||||||||||||
import { reactive, computed, watch } from 'vue' | ||||||||||||||||||||||||||||||
import { useAutoStore } from './storage' | ||||||||||||||||||||||||||||||
import { useMediaQuery } from './useMediaQuery' | ||||||||||||||||||||||||||||||
import { ZH_CN_LANG, EN_US_LANG, LANG_KEY, LANG_PATH_MAP } from '../const' | ||||||||||||||||||||||||||||||
|
@@ -8,7 +8,8 @@ const enPath = LANG_PATH_MAP[EN_US_LANG] | |||||||||||||||||||||||||||||
const appData = reactive({ | ||||||||||||||||||||||||||||||
lang: useAutoStore('local', LANG_KEY, ZH_CN_LANG), | ||||||||||||||||||||||||||||||
theme: useAutoStore('local', '_theme', 'light'), | ||||||||||||||||||||||||||||||
bpState: useMediaQuery([640, 1024, 1280]).matches // 3点4区间, bp0,bp1,bp2,bp3 | ||||||||||||||||||||||||||||||
bpState: useMediaQuery([640, 1024, 1280]).matches, // 3点4区间, bp0,bp1,bp2,bp3 | ||||||||||||||||||||||||||||||
showTinyRobot: false | ||||||||||||||||||||||||||||||
}) | ||||||||||||||||||||||||||||||
const isZhCn = computed(() => appData.lang === ZH_CN_LANG) | ||||||||||||||||||||||||||||||
const appFn = { | ||||||||||||||||||||||||||||||
|
@@ -27,4 +28,12 @@ const appFn = { | |||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
// 为了和tiny-vue共享同一个响应变量 | ||||||||||||||||||||||||||||||
window.appData = appData | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
watch( | ||||||||||||||||||||||||||||||
() => appData.showTinyRobot, | ||||||||||||||||||||||||||||||
(value) => { | ||||||||||||||||||||||||||||||
document.body.classList.toggle('docs-on-robot-show', value) | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
Comment on lines
+32
to
+37
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Add safety checks for DOM manipulation. The watcher implementation is good for centralizing the robot visibility side effects, but consider adding safety checks for SSR compatibility and document availability. watch(
() => appData.showTinyRobot,
(value) => {
- document.body.classList.toggle('docs-on-robot-show', value)
+ if (typeof document !== 'undefined' && document.body) {
+ document.body.classList.toggle('docs-on-robot-show', value)
+ }
}
) 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents
|
||||||||||||||||||||||||||||||
export { appData, appFn, isZhCn } |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,8 @@ import type { AIModelConfig } from '@opentiny/tiny-robot-kit' | |
import type { ChatCompletionResponse } from '@opentiny/tiny-robot-kit' | ||
import type { StreamHandler } from '@opentiny/tiny-robot-kit' | ||
import { BaseModelProvider } from '@opentiny/tiny-robot-kit' | ||
import { handleSSEStream } from './utils.js' | ||
import { globalConversation, handleSSEStream } from './utils.js' | ||
import type { Ref } from 'vue' | ||
|
||
/** | ||
* 对接AIClient的自定义 Dify 大模型服务 | ||
|
@@ -14,6 +15,8 @@ import { handleSSEStream } from './utils.js' | |
* }); | ||
*/ | ||
export class DifyModelProvider extends BaseModelProvider { | ||
_messages: Ref<ChatCompletionRequest['messages']> = [] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix the The Apply this diff to fix the initialization: - _messages: Ref<ChatCompletionRequest['messages']> = []
+ _messages: Ref<ChatCompletionRequest['messages']> = ref([]) Note: You'll also need to import
🤖 Prompt for AI Agents
|
||
|
||
constructor(config: AIModelConfig) { | ||
super(config) | ||
} | ||
|
@@ -45,11 +48,12 @@ export class DifyModelProvider extends BaseModelProvider { | |
response_mode: 'streaming', | ||
inputs: { | ||
sessionId: window.$sessionId | ||
} | ||
}, | ||
conversation_id: globalConversation.id | ||
}) | ||
}) | ||
|
||
await handleSSEStream(response, handler, signal) | ||
await handleSSEStream(response, handler, this._messages, signal) | ||
} catch (error) { | ||
if (signal && signal.aborted) { | ||
console.warn('Request was aborted:', error) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,13 +4,23 @@ | |
*/ | ||
|
||
import type { ChatMessage, ChatCompletionResponse, StreamHandler } from '@opentiny/tiny-robot-kit' | ||
import type { ChatCompletionRequest } from '@opentiny/tiny-robot-kit' | ||
import type { Ref } from 'vue' | ||
|
||
export const globalConversation = { | ||
id: '' | ||
} | ||
Comment on lines
+10
to
+12
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Consider thread safety for global conversation state. The Consider one of these approaches:
Example for approach 1: export async function handleSSEStream(
response: Response,
handler: StreamHandler,
message: Ref<ChatCompletionRequest['messages']>,
conversationContext: { id: string },
signal?: AbortSignal
): Promise<void> 🤖 Prompt for AI Agents
|
||
/** | ||
* 处理SSE流式响应 | ||
* @param response fetch响应对象 | ||
* @param handler 流处理器 | ||
*/ | ||
export async function handleSSEStream(response: Response, handler: StreamHandler, signal?: AbortSignal): Promise<void> { | ||
export async function handleSSEStream( | ||
response: Response, | ||
handler: StreamHandler, | ||
message: Ref<ChatCompletionRequest['messages']>, | ||
signal?: AbortSignal | ||
): Promise<void> { | ||
// 获取ReadableStream | ||
const reader = response.body?.getReader() | ||
if (!reader) { | ||
|
@@ -64,6 +74,7 @@ export async function handleSSEStream(response: Response, handler: StreamHandler | |
if (!dataMatch) continue | ||
|
||
const data = JSON.parse(dataMatch[1]) | ||
// console.log('SSE data:', data) | ||
if (data?.event === 'workflow_started') { | ||
handler.onData({ | ||
id: data.workflow_run_id, | ||
|
@@ -73,14 +84,18 @@ export async function handleSSEStream(response: Response, handler: StreamHandler | |
index: messageIndex++, | ||
delta: { | ||
role: 'assistant', | ||
content: '**Workflow started** \r\n' | ||
content: ' ' | ||
}, | ||
finish_reason: null | ||
} | ||
], | ||
object: '', | ||
model: '' | ||
}) | ||
message.value.slice(-1)[0].loading = true | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add safety checks for message array access. The code directly accesses the last message in the array without checking if the array is empty, which could cause runtime errors. Apply this diff to add safety checks: - message.value.slice(-1)[0].loading = true
+ const lastMessage = message.value.slice(-1)[0]
+ if (lastMessage) {
+ lastMessage.loading = true
+ } Apply similar fixes to lines 118 and 137 where Also applies to: 118-118, 137-137 🤖 Prompt for AI Agents
|
||
if (!globalConversation.id) { | ||
globalConversation.id = data.conversation_id | ||
} | ||
} | ||
|
||
if (data?.event === 'message' && data?.answer) { | ||
|
@@ -100,6 +115,7 @@ export async function handleSSEStream(response: Response, handler: StreamHandler | |
object: '', | ||
model: '' | ||
}) | ||
message.value.slice(-1)[0].loading = false | ||
} | ||
if (data?.event === 'message_end') { | ||
handler.onData({ | ||
|
@@ -118,6 +134,7 @@ export async function handleSSEStream(response: Response, handler: StreamHandler | |
object: '', | ||
model: '' | ||
}) | ||
message.value.slice(-1)[0].loading = false | ||
} | ||
// handler.onData(data) | ||
} catch (error) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Verification agent
❓ Verification inconclusive
Good security improvement by switching to HTTPS.
The change from HTTP to HTTPS enhances security by encrypting the SSE connection. However, please verify that the endpoint is accessible via HTTPS and consider externalizing this URL to a configuration file for better maintainability.
🏁 Script executed:
Length of output: 698
HTTPS endpoint fails certificate verification
The switch to HTTPS is a great security improvement, but
curl -I https://39.108.160.245/sse
is failing with an SSL error indicating a self-signed certificate. Please address this before merging:🤖 Prompt for AI Agents