typespec-create-api-plugin
它能做什么
这段代码可以帮助你为 Microsoft 365 Copilot 创建一个智能体,让它能够通过互联网与其他服务交互(REST API)。它定义了 Copilot 如何理解并使用这些连接。
适用场景
- ✓当你希望 Copilot 调用外部服务来获取或发送信息时。
- ✓当你创建的自定义助手需要从其他应用中获取数据时。
- ✓当你想把 Copilot 连接到非微软系统时。
技能链接
https://github.com/github/awesome-copilot/blob/main/skills/typespec-create-api-plugin/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“创建一个 Copilot 智能体,让它能够从一个在线产品目录中获取信息。”
每周 5 个新技能,1 分钟读完。
工作原理
代码会定义一个带有名称和描述的智能体,并指定它可以执行的“操作”,比如获取数据。同时还会设置 Copilot 如何进行身份验证,以及如何展示回复内容。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
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:
No Authentication (Public APIs)
// No @useAuth decorator neededAPI Key
@useAuth(ApiKeyAuth<ApiKeyLocation.header, "X-API-Key">)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"]; }]>)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
- Operation Names: Use clear, action-oriented names (listProjects, createTicket)
- Models: Define TypeScript-like models for requests and responses
- HTTP Methods: Use appropriate verbs (@get, @post, @patch, @delete)
- Paths: Use RESTful path conventions with @route
- Parameters: Use @path, @query, @header, @body appropriately
- Descriptions: Provide clear descriptions for model understanding
- Confirmations: Add for destructive operations (delete, update critical data)
- Cards: Use for rich visual responses with multiple data items
Workflow
Ask the user:
- What is the API base URL and purpose?
- What operations are needed (CRUD operations)?
- What authentication method does the API use?
- Should confirmations be required for any operations?
- Do responses need Adaptive Cards?
Then generate:
- Complete
main.tspwith agent definition - Complete
actions.tspwith API operations and models - Optional
cards/card.jsonif Adaptive Cards are needed
常见问题
什么是 TypeSpec?
TypeSpec 是一种用来描述 API 的语言,让 Copilot 等工具更容易理解如何与它们交互。
什么是 “Adaptive Cards”?
这是一种可视化卡片,Copilot 可以用它以有条理的方式展示信息,或者请求你确认某些操作。
使用这个工具需要会编程吗?
不需要。你只需描述你的需求,工具就会为你生成代码。
详情
作者的原始描述
Generate a TypeSpec API plugin with REST operations, authentication, and Adaptive Cards for Microsoft 365 Copilot
repo: github/awesome-copilot
热度
- GitHub 星标
- 40k
- 排名
- #7459
- 许可证
- MIT
- 更新时间
- 2026/10/15
评论
- …
同一仓库的更多技能
acquire-codebase-knowledge
40k帮你的智能体理解并编写现有代码项目的文档。它有助于新成员快速上手,或者快速了解项目架构。
acreadiness-assess
40k让你的智能体评估一个项目对 AI 的准备程度,并生成报告。它有助于了解项目在使用 AI 工具方面的准备情况。
acreadiness-generate-instructions
40k帮你的智能体根据评估结果编写 AI 工具的指令文件。它有助于改善 AI 与代码的交互方式,并弥补已发现的不足。
acreadiness-policy
40k让你的智能体协助制定或应用 AI 项目评估的政策。它有助于规范项目的评估方式,并确保合规。