Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
B
bit-pm
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
燕伟桐
bit-pm
Commits
3a6ab12b
Unverified
提交
3a6ab12b
authored
6月 17, 2025
作者:
Will Chen
提交者:
GitHub
6月 17, 2025
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Rotate messages in promo banner (show tips) (#420)
上级
17880cb8
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
254 行增加
和
16 行删除
+254
-16
MessagesList.tsx
src/components/chat/MessagesList.tsx
+4
-16
PromoMessage.tsx
src/components/chat/PromoMessage.tsx
+250
-0
没有找到文件。
src/components/chat/MessagesList.tsx
浏览文件 @
3a6ab12b
...
...
@@ -17,6 +17,7 @@ import { chatMessagesAtom } from "@/atoms/chatAtoms";
import
{
useLanguageModelProviders
}
from
"@/hooks/useLanguageModelProviders"
;
import
{
useSettings
}
from
"@/hooks/useSettings"
;
import
{
useUserBudgetInfo
}
from
"@/hooks/useUserBudgetInfo"
;
import
{
PromoMessage
}
from
"./PromoMessage"
;
interface
MessagesListProps
{
messages
:
Message
[];
...
...
@@ -224,22 +225,9 @@ export const MessagesList = forwardRef<HTMLDivElement, MessagesListProps>(
!
settings
?.
enableDyadPro
&&
!
userBudget
&&
messages
.
length
>
0
&&
(
<
div
className=
"max-w-3xl mx-auto mt-4 py-2 px-1 border border-blue-500 rounded-lg bg-blue-50 text-center"
>
<
p
className=
"text-sm text-blue-700"
>
Tired of waiting on AI?
<
a
onClick=
{
()
=>
IpcClient
.
getInstance
().
openExternalUrl
(
"https://dyad.sh/pro#ai"
,
)
}
className=
" text-blue-600 hover:text-blue-800 underline ml-1 cursor-pointer"
>
Get Dyad Pro
</
a
>
{
" "
}
for faster edits with Turbo Edits.
</
p
>
</
div
>
<
PromoMessage
seed=
{
messages
.
length
*
(
appId
??
1
)
*
(
selectedChatId
??
1
)
}
/>
)
}
<
div
ref=
{
messagesEndRef
}
/>
</
div
>
...
...
src/components/chat/PromoMessage.tsx
0 → 100644
浏览文件 @
3a6ab12b
import
{
IpcClient
}
from
"@/ipc/ipc_client"
;
import
React
from
"react"
;
// Types for the message system
export
interface
TextSpan
{
type
:
"text"
;
content
:
string
;
}
export
interface
LinkSpan
{
type
:
"link"
;
content
:
string
;
url
?:
string
;
action
?:
()
=>
void
;
}
export
type
MessageSpan
=
TextSpan
|
LinkSpan
;
export
interface
MessageConfig
{
spans
:
MessageSpan
[];
}
// Generic Message component
export
function
Message
({
spans
}:
MessageConfig
)
{
return
(
<
div
className=
"max-w-3xl mx-auto mt-4 py-2 px-1 border border-blue-500 rounded-lg bg-blue-50 text-center"
>
<
p
className=
"text-sm text-blue-700"
>
{
spans
.
map
((
span
,
index
)
=>
{
if
(
span
.
type
===
"text"
)
{
return
<
span
key=
{
index
}
>
{
span
.
content
}
</
span
>;
}
else
if
(
span
.
type
===
"link"
)
{
return
(
<
a
key=
{
index
}
onClick=
{
()
=>
{
if
(
span
.
action
)
{
span
.
action
();
}
else
if
(
span
.
url
)
{
IpcClient
.
getInstance
().
openExternalUrl
(
span
.
url
);
}
}
}
className=
"text-blue-600 hover:text-blue-800 underline cursor-pointer"
>
{
span
.
content
}
</
a
>
);
}
return
null
;
})
}
</
p
>
</
div
>
);
}
// Predefined message configurations
export
const
TURBO_EDITS_PROMO_MESSAGE
:
MessageConfig
=
{
spans
:
[
{
type
:
"text"
,
content
:
"Tired of waiting on AI?"
},
{
type
:
"link"
,
content
:
" Get Dyad Pro"
,
url
:
"https://dyad.sh/pro#ai"
},
{
type
:
"text"
,
content
:
" for faster edits with Turbo Edits."
},
],
};
export
const
SMART_CONTEXT_PROMO_MESSAGE
:
MessageConfig
=
{
spans
:
[
{
type
:
"text"
,
content
:
"Save up to 5x on AI costs with "
},
{
type
:
"link"
,
content
:
"Dyad Pro's Smart Context"
,
url
:
"https://dyad.sh/pro#ai"
,
},
],
};
// Example of other message types you could easily add
export
const
DIFFERENT_MODEL_TIP
:
MessageConfig
=
{
spans
:
[
{
type
:
"text"
,
content
:
"Getting stuck in a debugging loop? Try a different model."
,
},
],
};
export
const
REDDIT_TIP
:
MessageConfig
=
{
spans
:
[
{
type
:
"text"
,
content
:
"Join 600+ builders in the "
,
},
{
type
:
"link"
,
content
:
"Dyad subreddit"
,
url
:
"https://www.reddit.com/r/dyadbuilders/"
,
},
],
};
export
const
REPORT_A_BUG_TIP
:
MessageConfig
=
{
spans
:
[
{
type
:
"text"
,
content
:
"Found a bug? Click Help > Report a Bug"
,
},
],
};
export
const
UPLOAD_CHAT_TIP
:
MessageConfig
=
{
spans
:
[
{
type
:
"text"
,
content
:
"Want to report a bad AI response? Upload the chat by clicking Help"
,
},
],
};
// https://www.youtube.com/watch?v=a7OoruOkkeg&list=PL1xR2pfIiRlW7mgr9AS95OkFQBtvrSlO5
export
const
BUILD_A_BIBLE_APP_TIP
:
MessageConfig
=
{
spans
:
[
{
type
:
"link"
,
content
:
"Watch"
,
url
:
"https://www.youtube.com/watch?v=a7OoruOkkeg&list=PL1xR2pfIiRlW7mgr9AS95OkFQBtvrSlO5"
,
},
{
type
:
"text"
,
content
:
" the creator of Dyad build a Bible app step-by-step"
,
},
],
};
export
const
DEBUGGING_TIPS_TIP
:
MessageConfig
=
{
spans
:
[
{
type
:
"text"
,
content
:
"Getting stuck? Read our "
,
},
{
type
:
"link"
,
content
:
"debugging tips"
,
url
:
"https://www.dyad.sh/docs/guides/debugging"
,
},
],
};
// Advanced tip: Customize your AI rules https://www.dyad.sh/docs/guides/ai-rules
export
const
AI_RULES_TIP
:
MessageConfig
=
{
spans
:
[
{
type
:
"text"
,
content
:
"Advanced tip: Customize your "
,
},
{
type
:
"link"
,
content
:
"AI rules"
,
url
:
"https://www.dyad.sh/docs/guides/ai-rules"
,
},
],
};
export
const
NEW_CHAT_TIP
:
MessageConfig
=
{
spans
:
[
{
type
:
"text"
,
content
:
"Want to keep the AI focused? Start a new chat."
,
},
],
};
// Want to know what's next? Checkout our roadmap https://www.dyad.sh/docs/roadmap
export
const
ROADMAP_TIP
:
MessageConfig
=
{
spans
:
[
{
type
:
"text"
,
content
:
"Want to know what's next? Check out our "
,
},
{
type
:
"link"
,
content
:
"roadmap"
,
url
:
"https://www.dyad.sh/docs/roadmap"
,
},
],
};
// Like Dyad? Star it on GitHub https://github.com/dyad-sh/dyad/
export
const
GITHUB_TIP
:
MessageConfig
=
{
spans
:
[
{
type
:
"text"
,
content
:
"Like Dyad? Star it on "
,
},
{
type
:
"link"
,
content
:
"GitHub"
,
url
:
"https://github.com/dyad-sh/dyad"
,
},
],
};
// Array of all available messages for rotation
const
ALL_MESSAGES
=
[
TURBO_EDITS_PROMO_MESSAGE
,
SMART_CONTEXT_PROMO_MESSAGE
,
DIFFERENT_MODEL_TIP
,
REDDIT_TIP
,
REPORT_A_BUG_TIP
,
UPLOAD_CHAT_TIP
,
BUILD_A_BIBLE_APP_TIP
,
DEBUGGING_TIPS_TIP
,
AI_RULES_TIP
,
NEW_CHAT_TIP
,
ROADMAP_TIP
,
GITHUB_TIP
,
];
// Main PromoMessage component using the modular system
export
function
PromoMessage
({
seed
}:
{
seed
:
number
})
{
const
hashedSeed
=
hashNumber
(
seed
);
const
randomMessage
=
ALL_MESSAGES
[
hashedSeed
%
ALL_MESSAGES
.
length
];
return
<
Message
{
...
randomMessage
}
/>;
}
/**
* Hashes a 32-bit integer using a variant of the MurmurHash3 algorithm.
* This function is designed to produce a good, random-like distribution
* of hash values, which is crucial for data structures like hash tables.
* @param {number} key - The integer to hash.
* @returns {number} A 32-bit integer hash.
*/
function
hashNumber
(
key
:
number
):
number
{
// Ensure the key is treated as an integer.
let
i
=
key
|
0
;
// MurmurHash3's mixing function (fmix32)
// It uses a series of bitwise multiplications, shifts, and XORs
// to thoroughly mix the bits of the input key.
// XOR with a shifted version of itself to start mixing bits.
i
^=
i
>>>
16
;
// Multiply by a large prime to further scramble bits.
i
=
Math
.
imul
(
i
,
0x85ebca6b
);
// Another XOR shift.
i
^=
i
>>>
13
;
// Another prime multiplication.
i
=
Math
.
imul
(
i
,
0xc2b2ae35
);
// Final XOR shift to get the final mix.
i
^=
i
>>>
16
;
// Return the result as an unsigned 32-bit integer.
return
i
>>>
0
;
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论