feat(skills): add dingtalk-knowledge skill for importing DingTalk docs to KB - #2
Open
parabala wants to merge 2 commits into
Open
feat(skills): add dingtalk-knowledge skill for importing DingTalk docs to KB#2parabala wants to merge 2 commits into
parabala wants to merge 2 commits into
Conversation
…s to KB Add a new skill that allows users to upload DingTalk documents, spreadsheets, and AI tables to Wegent knowledge base. Features: - Parse DingTalk URLs to extract document IDs - Retrieve DingTalk MCP credentials from user preferences - Support for docs, tables (spreadsheets), and AI tables (multidimensional) - Download files from DingTalk using MCP tools - Upload downloaded files to knowledge base as attachments Files added: - backend/init_data/skills/dingtalk-knowledge/SKILL.md - backend/init_data/skills/dingtalk-knowledge/__init__.py - backend/init_data/skills/dingtalk-knowledge/provider.py - backend/init_data/skills/dingtalk-knowledge/upload_dingtalk_to_kb.py
Add backend MCP proxy API to properly handle DingTalk MCP tool calls:
Backend Changes:
- Add /api/internal/mcp/dingtalk/{service_id}/call endpoint
- Add /api/internal/mcp/dingtalk/{service_id}/tools/list endpoint
- Add /api/internal/mcp/dingtalk/{service_id}/config endpoint
- Handles user MCP configuration retrieval and decryption
- Proxies MCP tool calls to DingTalk MCP servers
Skill Changes:
- Update upload_dingtalk_to_kb.py to use backend MCP proxy API
- Remove direct MCP URL usage from user preferences
- Use proper MCP tool flow via backend proxy:
- docs: get_document_info -> get_document_content/download_file
- table: get_all_sheets -> get_range
- ai_table: get_tables -> query_records
Files Added:
- backend/app/api/endpoints/internal/dingtalk_mcp.py
Files Modified:
- backend/app/api/api.py
- backend/app/api/endpoints/internal/__init__.py
- backend/init_data/skills/dingtalk-knowledge/upload_dingtalk_to_kb.py
parabala
pushed a commit
that referenced
this pull request
Jul 16, 2026
* feat(chat): add context status metrics and toolbar indicator * feat(chat): finalize Phase 1 chat status toolbar and reconnect recovery - Replace QuotaUsage with ChatToolbarStatus driven by chat:status_updated - Wire useChatStatusIndicator to derive a fallback snapshot from the latest persisted AI message so toolbar status survives cold reloads before any live socket event arrives - Type UnifiedMessage.result.context_metrics so persisted snapshots flow through the state machine without runtime casts Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * feat(chat_shell): add TruncationPolicy and GuardSource Protocol (T1) Introduce the shared types module for Phase 2 context governance: - TruncationPolicy: frozen dataclass with kind (bytes/tokens) and limit - GuardSource: runtime_checkable Protocol for guard source adapters - DEFAULT_EMERGENCY_RATIO = 0.3 and default_emergency_policy helper Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * feat(chat_shell): add ToolOutputGuardAdapter and compact tool string format (T2) Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * fix(chat_shell): tighten compact footer detection and dedupe encoding (T2 review) * feat(chat_shell): add UnifiedContextGuard with source + compression pipeline (T3) Phase 2 unified context guard. Runs as LangGraph pre_model_hook before every model call (pre-turn and mid-turn alike) and applies: 1. Source-level pass: convert raw tool messages to compact form via the registered GuardSource adapters; mark `compacted=true` so subsequent passes treat them as already-handled. 2. Request-level compression: when live state exceeds the model trigger limit, run MessageCompressor and translate its diff into LangGraph state updates (RemoveMessage for dropped ids, fresh BaseMessage for synthesized summaries; compacted=true marker propagates). 3. Emergency re-truncation: stub for T7; logs a warning when compression alone is insufficient. Skips messages without a stable id since add_messages cannot upsert them without doubling content. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * feat(chat_shell): wire UnifiedContextGuard as pre_model_hook (T4) Phase 2 wiring task: - chat_service constructs UnifiedContextGuard with ToolOutputGuardAdapter as the only source. The guard is chained AFTER guidance_consumer's hook via chain_pre_model_hooks so guidance injection observes already-budgeted state and writes its llm_input_messages on top of the compacted view. - agent.build_messages no longer invokes MessageCompressor — budget enforcement now lives entirely in the pre_model_hook, which fires on pre-turn AND every mid-turn follow-up. Cache-breakpoint application remains in build_messages on the assembled layout. - Drops the now-unused MessageCompressor import from agent.py. - Adds guard/composition.py with chain_pre_model_hooks, supporting mixed sync/async hooks; messages updates concatenate, llm_input_messages from the last hook wins. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * feat(chat_shell): finalize Phase 2 context governance (T7+T8+T9 + review) Completes Phase 2 by adding emergency re-truncation, removing legacy serialization-time truncation, refactoring the metrics tracker to emit-only, and addressing the review findings on the resulting code. T7 — Emergency re-truncation - UnifiedContextGuard stage 3 now re-renders source-owned messages under each source's emergency policy, biggest-first with early stop once usage drops below trigger. - ToolOutputGuardAdapter accepts an emergency_ratio (defaults to DEFAULT_EMERGENCY_RATIO); chat_service passes settings.EMERGENCY_TOOL_OUTPUT_RATIO. - Synthesized messages from stage 2 are excluded from the candidate set so the upsert-by-id contract holds. T8 — Delete legacy _truncate_tool_result_for_storage - graph_builder._serialize_messages_chain no longer chops tool results at serialization time; budget enforcement is owned by the guard. - Removed MAX_TOOL_RESULT_LENGTH from config and its tests. T9 — Tracker → emit-only wrapper - ContextMetricsTracker no longer keeps its own messages duplicate. Single API: capture(messages, phase). Snapshot computation is delegated to an injected metrics_fn so accounting flows from one source. - chat_service captures BUILD_MESSAGES at turn start and FINAL at end with messages + agent_builder._last_messages_chain. - tools/events drops the per-tool tracker calls. Review fixes - #1: extract_raw now parses already-compact strings via the new _split_compact helper, so stage 3 emergency re-render no longer produces nested headers / fabricated total_tokens counts. - #2: UnifiedContextGuard.__call__ is async and emits a metrics snapshot via the injected tracker on every invocation. Phase is PHASE_AFTER_COMPACTION when compaction happened, PHASE_AFTER_TOOL_END otherwise; bucket-throttling in should_emit_status_update suppresses redundant emits. Tests converted to async. - #3: ToolResultTruncationStrategy now skips messages flagged additional_kwargs.compacted=True. Without this, stage 2 compression would corrupt the guard's fixed-format compact strings, leaving a misleading total_tokens count and mixing two truncation notices. - #5: Documented the source-disjointness assumption in _apply_source_pass — registered GuardSources must have non-overlapping applies_to predicates. - #6: calculate_context_metrics accepts pre-built TokenCounter and ModelContextConfig; guard.metrics() reuses its instance state instead of constructing fresh ones on every snapshot. - #8: Kept default_emergency_policy as a documented public reference helper for future GuardSource impls. - #9: _dict_to_base_message forwards d.get('id') so the compressor's synthesized ids survive the round-trip. - #10: New test verifies cache_control markers in additional_kwargs survive guard compaction (Anthropic prompt-cache compatibility). Tests - 14 new tests across guard composition, tracker emit, compact-string roundtrip, id propagation, cache-breakpoint preservation, and compressor skip behavior. Total chat_shell suite: 549 passing. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com> * feat(chat-shell): finalize phase2 context guard * fix(chat-shell): tune tool guard controls and diagnostics * feat(knowledge): add listing pagination and guard fixes * fix(frontend): improve chat toolbar status sections --------- Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add a new skill that allows users to upload DingTalk documents, spreadsheets, and AI tables to Wegent knowledge base.
Features
Usage Example
Users can invoke the skill by saying:
Technical Details
Authentication
The skill retrieves DingTalk MCP configuration from the user table's
preferencesfield, which contains encrypted MCP server URLs for each service type.Workflow
get_document_info+get_document_contentfor docsget_all_sheets+get_rangefor tablesget_tables+query_recordsfor AI tablesFiles Added
backend/init_data/skills/dingtalk-knowledge/SKILL.md- Skill documentationbackend/init_data/skills/dingtalk-knowledge/__init__.py- Package initbackend/init_data/skills/dingtalk-knowledge/provider.py- Tool providerbackend/init_data/skills/dingtalk-knowledge/upload_dingtalk_to_kb.py- Main tool implementationTest Plan