Merge remote-tracking branch 'origin/master' into dev/4.11.x

# Conflicts:
#	src/langbot/pkg/pipeline/preproc/preproc.py
#	src/langbot/pkg/pipeline/process/handlers/chat.py
#	src/langbot/pkg/provider/runners/localagent.py
#	src/langbot/pkg/provider/tools/toolmgr.py
#	src/langbot/templates/metadata/pipeline/ai.yaml
#	tests/unit_tests/test_preproc.py
#	web/src/app/home/components/dynamic-form/DynamicFormComponent.tsx
#	web/src/app/home/pipelines/components/pipeline-form/PipelineFormComponent.tsx
This commit is contained in:
Junyan Qin
2026-06-30 21:07:13 +08:00
167 changed files with 16186 additions and 1722 deletions
@@ -0,0 +1,105 @@
import pytest
import langbot_plugin.api.entities.builtin.platform.message as platform_message
from langbot.pkg.platform.sources.aiocqhttp import AiocqhttpAdapter, AiocqhttpMessageConverter
async def _convert_single(component: platform_message.MessageComponent):
chain = platform_message.MessageChain([component])
message, _, _ = await AiocqhttpMessageConverter.yiri2target(chain)
return message[0]
@pytest.mark.asyncio
@pytest.mark.parametrize(
('payload', 'expected'),
[
('data:image/jpeg;base64,raw-image', 'base64://raw-image'),
('raw-image', 'base64://raw-image'),
('base64://raw-image', 'base64://raw-image'),
],
)
async def test_image_base64_payload_is_normalized(payload, expected):
segment = await _convert_single(platform_message.Image(base64=payload))
assert segment.type == 'image'
assert segment.data['file'] == expected
@pytest.mark.asyncio
async def test_voice_data_uri_base64_payload_is_normalized():
segment = await _convert_single(platform_message.Voice(base64='data:audio/wav;base64,raw-voice'))
assert segment.type == 'record'
assert segment.data['file'] == 'base64://raw-voice'
@pytest.mark.asyncio
@pytest.mark.parametrize(
('component', 'expected'),
[
(
platform_message.File(name='report.txt', base64='data:text/plain;base64,raw-file'),
{'file': 'base64://raw-file', 'name': 'report.txt'},
),
(
platform_message.File(name='report.txt', base64='raw-file'),
{'file': 'base64://raw-file', 'name': 'report.txt'},
),
(
platform_message.File(name='a.txt', url='http://example.com/a.txt'),
{'file': 'http://example.com/a.txt', 'name': 'a.txt'},
),
(
platform_message.File(name='a.txt', path='/tmp/a.txt'),
{'file': '/tmp/a.txt', 'name': 'a.txt'},
),
],
)
async def test_file_message_uses_available_file_source(component, expected):
segment = await _convert_single(component)
assert segment.type == 'file'
assert segment.data == expected
@pytest.mark.asyncio
async def test_forward_image_base64_payload_is_normalized():
forward = platform_message.Forward(
node_list=[
platform_message.ForwardMessageNode(
sender_id='10001',
sender_name='Tester',
message_chain=platform_message.MessageChain(
[platform_message.Image(base64='data:image/png;base64,raw-forward-image')]
),
)
]
)
messages = []
class Logger:
async def info(self, _message):
return None
async def error(self, _message):
return None
class Bot:
async def call_action(self, action, **kwargs):
assert action == 'send_forward_msg'
messages.append(kwargs)
platform = AiocqhttpAdapter.model_construct(
bot_account_id='10000',
config={},
logger=Logger(),
bot=Bot(),
)
await platform._send_forward_message(1000, forward)
assert messages[0]['messages'][0]['data']['content'][0] == {
'type': 'image',
'data': {'file': 'base64://raw-forward-image'},
}