-
Notifications
You must be signed in to change notification settings - Fork 360
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c2d0288
commit af9eed3
Showing
5 changed files
with
300 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
--- | ||
document type: cmdlet | ||
external help file: PnP.PowerShell.dll-Help.xml | ||
HelpUri: '' | ||
Locale: en-US | ||
Module Name: PnP.PowerShell | ||
ms.date: 12/06/2024 | ||
PlatyPS schema version: 2024-05-01 | ||
title: Get-PnPCopilotAgent | ||
--- | ||
|
||
# Get-PnPCopilotAgent | ||
|
||
## SYNOPSIS | ||
|
||
Returns the Microsoft Copilot Agents (*.agent) in a site collection. | ||
|
||
## SYNTAX | ||
|
||
### __AllParameterSets | ||
|
||
```powershell | ||
Get-PnPCopilotAgent [-ServerRelativeUrl <string>] [-Connection <PnPConnection>] [<CommonParameters>] | ||
``` | ||
|
||
## DESCRIPTION | ||
|
||
This cmdlet iterates through the document libraries in a site and finds the copilot agents in that site. | ||
|
||
## EXAMPLES | ||
|
||
### Example 1 | ||
|
||
```powershell | ||
Get-PnPCopilotAgent | ||
``` | ||
|
||
This will return all the Microsoft Copilot agents in a site. | ||
|
||
|
||
### Example 2 | ||
|
||
```powershell | ||
Get-PnPCopilotAgent -ServerRelativeUrl /sites/demo/siteassets/copilots/approved/main.agent | ||
``` | ||
|
||
This will return the specific Microsoft Copilot agent if it exists. | ||
|
||
|
||
## PARAMETERS | ||
|
||
### -Connection | ||
|
||
Optional connection to be used by the cmdlet. Retrieve the value for this parameter by either specifying -ReturnConnection on Connect-PnPOnline or by executing Get-PnPConnection. | ||
|
||
```yaml | ||
Type: PnP.PowerShell.Commands.Base.PnPConnection | ||
DefaultValue: '' | ||
SupportsWildcards: false | ||
ParameterValue: [] | ||
Aliases: [] | ||
ParameterSets: | ||
- Name: (All) | ||
Position: Named | ||
IsRequired: false | ||
ValueFromPipeline: false | ||
ValueFromPipelineByPropertyName: false | ||
ValueFromRemainingArguments: false | ||
DontShow: false | ||
AcceptedValues: [] | ||
HelpMessage: '' | ||
``` | ||
### -ServerRelativeUrl | ||
The server relative URL to the .agent file. | ||
```yaml | ||
Type: System.String | ||
DefaultValue: '' | ||
SupportsWildcards: false | ||
ParameterValue: [] | ||
Aliases: [] | ||
ParameterSets: | ||
- Name: (All) | ||
Position: Named | ||
IsRequired: false | ||
ValueFromPipeline: false | ||
ValueFromPipelineByPropertyName: false | ||
ValueFromRemainingArguments: false | ||
DontShow: false | ||
AcceptedValues: [] | ||
HelpMessage: '' | ||
``` | ||
### CommonParameters | ||
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, | ||
-InformationAction, -InformationVariable, -OutBuffer, -OutVariable, -PipelineVariable, | ||
-ProgressAction, -Verbose, -WarningAction, and -WarningVariable. For more information, see | ||
[about_CommonParameters](https://go.microsoft.com/fwlink/?LinkID=113216). | ||
## RELATED LINKS | ||
[Microsoft 365 Patterns and Practices](https://aka.ms/m365pnp) |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
using System.Management.Automation; | ||
using System.Text.Json; | ||
using Microsoft.SharePoint.Client; | ||
using PnP.PowerShell.Commands.Model.Copilot; | ||
using System.Linq; | ||
using System; | ||
|
||
namespace PnP.PowerShell.Commands.Copilot | ||
{ | ||
[Cmdlet(VerbsCommon.Get, "PnPCopilotAgent")] | ||
[OutputType("PnP.PowerShell.Commands.Model.Copilot.CopilotAgent")] | ||
public class NewCopilotAgent : PnPWebCmdlet | ||
{ | ||
[Parameter(Mandatory = false)] | ||
public string ServerRelativeUrl; | ||
|
||
protected override void ExecuteCmdlet() | ||
{ | ||
|
||
if (ParameterSpecified(nameof(ServerRelativeUrl))) | ||
{ | ||
try | ||
{ | ||
var agentContents = CurrentWeb.GetFileAsString(ServerRelativeUrl); | ||
var agentObject = JsonSerializer.Deserialize<CopilotAgent>(agentContents); | ||
agentObject.ServerRelativeUrl = ServerRelativeUrl; | ||
WriteObject(agentObject); | ||
} | ||
catch (JsonException) | ||
{ | ||
throw new PSNotSupportedException("Cannot extract agent information from contents."); | ||
} | ||
catch (ServerException) | ||
{ | ||
throw new PSArgumentException($"Agent with url {ServerRelativeUrl} not found."); | ||
} | ||
} | ||
else | ||
{ | ||
|
||
// find all doclibraries | ||
var doclibs = ClientContext.LoadQuery(CurrentWeb.Lists.Where(l => l.BaseTemplate == 101)); | ||
ClientContext.ExecuteQuery(); | ||
var camlQuery = CamlQuery.CreateAllItemsQuery(); | ||
|
||
camlQuery.ViewXml = "<View Scope=\"RecursiveAll\"><Query><Where><Eq><FieldRef Name=\"File_x0020_Type\" /><Value Type=\"Text\">agent</Value></Eq></Where></Query></View>"; | ||
foreach (var doclib in doclibs) | ||
{ | ||
camlQuery.ListItemCollectionPosition = null; | ||
do | ||
{ | ||
camlQuery.ListItemCollectionPosition = GetAgents(doclib, camlQuery); | ||
|
||
} while (camlQuery.ListItemCollectionPosition != null); | ||
} | ||
} | ||
} | ||
|
||
private ListItemCollectionPosition GetAgents(List list, CamlQuery camlQuery) | ||
{ | ||
var items = list.GetItems(camlQuery); | ||
list.Context.Load(items, i => i.IncludeWithDefaultProperties(li => li.FieldValuesAsText), i => i.ListItemCollectionPosition); | ||
ClientContext.ExecuteQueryRetry(); | ||
foreach (var item in items) | ||
{ | ||
var agentContents = CurrentWeb.GetFileAsString(item.FieldValuesAsText["FileRef"]); | ||
var agentObject = JsonSerializer.Deserialize<CopilotAgent>(agentContents); | ||
agentObject.ServerRelativeUrl = item.FieldValuesAsText["FileRef"]; | ||
WriteObject(agentObject); | ||
} | ||
|
||
return items.ListItemCollectionPosition; | ||
} | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
using System.Collections.Generic; | ||
using System.Text.Json.Serialization; | ||
|
||
namespace PnP.PowerShell.Commands.Model.Copilot | ||
{ | ||
public class CopilotAgent | ||
{ | ||
[JsonPropertyName("schemaVersion")] | ||
public string SchemaVersion { get; set; } = "0.2.0"; | ||
|
||
[JsonPropertyName("customCopilotConfig")] | ||
public CopilotAgentCustomCopilotConfig CustomCopilotConfig { get; set; } | ||
|
||
public string ServerRelativeUrl {get;set;} | ||
} | ||
|
||
public class CopilotAgentCustomCopilotConfig | ||
{ | ||
[JsonPropertyName("conversationStarters")] | ||
public CopilotAgentConversationStarters ConversationStarters { get; set; } | ||
|
||
[JsonPropertyName("gptDefinition")] | ||
public CopilotAgentGPTDefinition GPTDefinition { get; set; } | ||
|
||
[JsonPropertyName("icon")] | ||
public string Icon { get; set; } | ||
} | ||
|
||
public class CopilotAgentConversationStarters | ||
{ | ||
[JsonPropertyName("conversationStarterList")] | ||
public List<CopilotAgentTextValue> conversationStarterList { get; set; } | ||
|
||
[JsonPropertyName("welcomeMessage")] | ||
public CopilotAgentTextValue WelcomeMessage { get; set; } | ||
} | ||
|
||
public class CopilotAgentTextValue | ||
{ | ||
[JsonPropertyName("text")] | ||
public string Text { get; set; } | ||
} | ||
|
||
public class CopilotAgentGPTDefinition | ||
{ | ||
[JsonPropertyName("name")] | ||
public string Name { get; set; } | ||
|
||
[JsonPropertyName("description")] | ||
public string Description { get; set; } | ||
|
||
[JsonPropertyName("instructions")] | ||
public string Instructions { get; set; } | ||
|
||
[JsonPropertyName("capabilities")] | ||
public List<CopilotAgentCapabilities> Capabilities { get; set; } | ||
} | ||
|
||
public class CopilotAgentCapabilities | ||
{ | ||
[JsonPropertyName("name")] | ||
public string Name { get; set; } | ||
|
||
[JsonPropertyName("items_by_sharepoint_ids")] | ||
public List<CopilotAgentSourceItem> ItemsBySharePointIds { get; set; } | ||
|
||
[JsonPropertyName("items_by_url")] | ||
public List<CopilotAgentSourceItem> ItemsByUrl { get; set; } | ||
} | ||
|
||
public class CopilotAgentSourceItem | ||
{ | ||
[JsonPropertyName("url")] | ||
public string Url { get; set; } | ||
[JsonPropertyName("name")] | ||
public string Name { get; set; } | ||
[JsonPropertyName("site_id")] | ||
public string SiteId { get; set; } | ||
[JsonPropertyName("web_id")] | ||
public string WebId { get; set; } | ||
[JsonPropertyName("list_id")] | ||
public string ListId { get; set; } | ||
[JsonPropertyName("unique_id")] | ||
public string UniqueId { get; set; } | ||
[JsonPropertyName("type")] | ||
public string Type { get; set; } | ||
} | ||
} |