Chuyển đến nội dung
Skillpedia
Agent40k · #7459

typespec-create-api-plugin

Skill này làm gì

Mã này giúp tạo một “agent” cho Microsoft 365 Copilot có thể tương tác với các dịch vụ khác qua internet (REST API). Nó định nghĩa cách Copilot hiểu và sử dụng các kết nối này.

Khi nào nên dùng

  • ✓Khi bạn muốn Copilot dùng một dịch vụ bên ngoài để lấy hoặc gửi thông tin.
  • ✓Khi tạo một trợ lý tùy chỉnh cần truy cập dữ liệu từ các ứng dụng khác.
  • ✓Để kết nối Copilot với các hệ thống không phải của Microsoft.

Liên kết skill

https://github.com/github/awesome-copilot/blob/main/skills/typespec-create-api-plugin/SKILL.md

Sao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.

Cách dùng

Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.

Tin nhắn có sẵn để dán

Hãy dùng skill này để giúp tôi: https://github.com/github/awesome-copilot/blob/main/skills/typespec-create-api-plugin/SKILL.md Đọc tệp SKILL.md tại liên kết đó và làm theo hướng dẫn cho việc của tôi.
Bạn muốn AI tự tìm những skill như thế này?Cài MCP Skillpedia miễn phí: chỉ một dòng, và AI sẽ tìm trong 15.000+ skill trước mỗi việc.Cài đặt trong 1 phút →

Ví dụ cách nhờ AI

“Tạo một agent cho Copilot có thể lấy thông tin từ một danh mục sản phẩm trực tuyến.”

5 skill mới mỗi tuần. Đọc chỉ 1 phút.

Cách hoạt động

Mã định nghĩa một “agent” với tên và mô tả, đồng thời chỉ định các “actions” (hành động) mà nó có thể thực hiện, như lấy dữ liệu. Nó cũng thiết lập cách Copilot xác thực và cách hiển thị phản hồi.

Nội dung kỹ thuật (SKILL.md gốc)

Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.

Create TypeSpec API Plugin

Create a complete TypeSpec API plugin for Microsoft 365 Copilot that integrates with external REST APIs.

Requirements

Generate TypeSpec files with:

main.tsp - Agent Definition

import "@typespec/http";
import "@typespec/openapi3";
import "@microsoft/typespec-m365-copilot";
import "./actions.tsp";

using TypeSpec.Http;
using TypeSpec.M365.Copilot.Agents;
using TypeSpec.M365.Copilot.Actions;

@agent({
  name: "[Agent Name]",
  description: "[Description]"
})
@instructions("""
  [Instructions for using the API operations]
""")
namespace [AgentName] {
  // Reference operations from actions.tsp
  op operation1 is [APINamespace].operationName;
}

actions.tsp - API Operations

import "@typespec/http";
import "@microsoft/typespec-m365-copilot";

using TypeSpec.Http;
using TypeSpec.M365.Copilot.Actions;

@service
@actions(#{
    nameForHuman: "[API Display Name]",
    descriptionForModel: "[Model description]",
    descriptionForHuman: "[User description]"
})
@server("[API_BASE_URL]", "[API Name]")
@useAuth([AuthType]) // Optional
namespace [APINamespace] {
  
  @route("[/path]")
  @get
  @action
  op operationName(
    @path param1: string,
    @query param2?: string
  ): ResponseModel;

  model ResponseModel {
    // Response structure
  }
}

Authentication Options

Choose based on API requirements:

  1. No Authentication (Public APIs)

    // No @useAuth decorator needed
    
  2. API Key

    @useAuth(ApiKeyAuth<ApiKeyLocation.header, "X-API-Key">)
    
  3. OAuth2

    @useAuth(OAuth2Auth<[{
      type: OAuth2FlowType.authorizationCode;
      authorizationUrl: "https://oauth.example.com/authorize";
      tokenUrl: "https://oauth.example.com/token";
      refreshUrl: "https://oauth.example.com/token";
      scopes: ["read", "write"];
    }]>)
    
  4. Registered Auth Reference

    @useAuth(Auth)
    
    @authReferenceId("registration-id-here")
    model Auth is ApiKeyAuth<ApiKeyLocation.header, "X-API-Key">
    

Function Capabilities

Confirmation Dialog

@capabilities(#{
  confirmation: #{
    type: "AdaptiveCard",
    title: "Confirm Action",
    body: """
    Are you sure you want to perform this action?
      * **Parameter**: {{ function.parameters.paramName }}
    """
  }
})

Adaptive Card Response

@card(#{
  dataPath: "$.items",
  title: "$.title",
  url: "$.link",
  file: "cards/card.json"
})

Reasoning & Response Instructions

@reasoning("""
  Consider user's context when calling this operation.
  Prioritize recent items over older ones.
""")
@responding("""
  Present results in a clear table format with columns: ID, Title, Status.
  Include a summary count at the end.
""")

Best Practices

  1. Operation Names: Use clear, action-oriented names (listProjects, createTicket)
  2. Models: Define TypeScript-like models for requests and responses
  3. HTTP Methods: Use appropriate verbs (@get, @post, @patch, @delete)
  4. Paths: Use RESTful path conventions with @route
  5. Parameters: Use @path, @query, @header, @body appropriately
  6. Descriptions: Provide clear descriptions for model understanding
  7. Confirmations: Add for destructive operations (delete, update critical data)
  8. Cards: Use for rich visual responses with multiple data items

Workflow

Ask the user:

  1. What is the API base URL and purpose?
  2. What operations are needed (CRUD operations)?
  3. What authentication method does the API use?
  4. Should confirmations be required for any operations?
  5. Do responses need Adaptive Cards?

Then generate:

  • Complete main.tsp with agent definition
  • Complete actions.tsp with API operations and models
  • Optional cards/card.json if Adaptive Cards are needed
Câu hỏi thường gặp

TypeSpec là gì?

TypeSpec là ngôn ngữ mô tả API, giúp các công cụ như Copilot dễ hiểu cách tương tác với chúng hơn.

“Adaptive Cards” là gì?

Đây là các thẻ trực quan mà Copilot có thể hiển thị để trình bày thông tin có tổ chức hoặc xin xác nhận.

Tôi có cần biết lập trình để dùng công cụ này không?

Không, mục tiêu là bạn mô tả điều mình cần, và công cụ sẽ tạo mã cho bạn.

Chi tiết

Mô tả gốc của tác giả

Generate a TypeSpec API plugin with REST operations, authentication, and Adaptive Cards for Microsoft 365 Copilot

repo: github/awesome-copilot

Độ phổ biến

Sao GitHub
40k
Vị trí xếp hạng
#7459
Giấy phép
MIT
Cập nhật
15/10/2026

Skill này có hữu ích không?

0

Đăng nhập để bình chọn.

Bình luận

  • …

Thêm skill từ kho mã này

Skill tương tự