|
| 1 | +import "@typespec/rest"; |
| 2 | +import "@typespec/versioning"; |
| 3 | +import "@azure-tools/typespec-azure-core"; |
| 4 | +import "@azure-tools/typespec-azure-resource-manager"; |
| 5 | + |
| 6 | +using Http; |
| 7 | +using Rest; |
| 8 | +using Versioning; |
| 9 | +using Azure.Core; |
| 10 | +using Azure.ResourceManager; |
| 11 | +using Azure.ResourceManager.BaseTypes; |
| 12 | +using Azure.ResourceManager.BaseTypes.Agents; |
| 13 | + |
| 14 | +/** Contoso Agent Resource Provider management API. */ |
| 15 | +@armProviderNamespace |
| 16 | +@service(#{ title: "ContosoAgentProviderClient" }) |
| 17 | +@versioned(Versions) |
| 18 | +namespace Microsoft.ContosoAgent; |
| 19 | + |
| 20 | +/** Contoso Agent API versions */ |
| 21 | +enum Versions { |
| 22 | + /** 2024-06-01 version */ |
| 23 | + @armCommonTypesVersion(Azure.ResourceManager.CommonTypes.Versions.v5) |
| 24 | + `2024-06-01`, |
| 25 | +} |
| 26 | + |
| 27 | +// ============================================================================ |
| 28 | +// Agent Definition models |
| 29 | +// ============================================================================ |
| 30 | + |
| 31 | +// AgentDefinitionAppliance: Use for the Appliance deployment model where the service |
| 32 | +// owns and reports agent configuration. All definition fields are read-only. |
| 33 | +// AgentDefinitionPlatform: Use for the Platform deployment model where the client |
| 34 | +// owns and manages agent configuration. Definition fields are writable. |
| 35 | +// Template params control optional definition fields: |
| 36 | +// HasModelDeploymentRef: include a modelDeploymentRef property |
| 37 | +// HasInstructions: include an instructions property |
| 38 | + |
| 39 | +// Appliance definition: read-only fields managed by the service |
| 40 | +model ContosoApplianceDefinition is AgentDefinitionAppliance<true, true>; |
| 41 | + |
| 42 | +// Platform definition: writable fields managed by the client |
| 43 | +model ContosoPlatformDefinition is AgentDefinitionPlatform<true, true>; |
| 44 | + |
| 45 | +// ============================================================================ |
| 46 | +// Agent Properties models |
| 47 | +// ============================================================================ |
| 48 | + |
| 49 | +// AgentPropertiesAppliance: Use when the service owns and manages the agent lifecycle. |
| 50 | +// All properties are read-only. The RP reports state; clients cannot modify it directly. |
| 51 | +// AgentPropertiesPlatform: Use when the client owns and manages the agent configuration. |
| 52 | +// Properties are writable (except baseTypes, which is always ARM-managed and read-only). |
| 53 | + |
| 54 | +// Appliance agent properties: service-managed, read-only |
| 55 | +model ContosoApplianceAgentProperties is AgentPropertiesAppliance<ContosoApplianceDefinition> { |
| 56 | + ...DefaultProvisioningStateProperty; |
| 57 | +} |
| 58 | + |
| 59 | +// Platform agent properties: client-managed, writable |
| 60 | +model ContosoPlatformAgentProperties is AgentPropertiesPlatform<ContosoPlatformDefinition> { |
| 61 | + ...DefaultProvisioningStateProperty; |
| 62 | +} |
| 63 | + |
| 64 | +// ============================================================================ |
| 65 | +// Agent Resource models |
| 66 | +// ============================================================================ |
| 67 | + |
| 68 | +// The Agent template creates an ARM TrackedResource with the @azureBaseType decorator. |
| 69 | +// Each agent resource requires a ResourceNameParameter spread for the key/segment. |
| 70 | + |
| 71 | +// Appliance-deployed agent (service manages configuration) |
| 72 | +#suppress "@azure-tools/typespec-azure-resource-manager/basetypes-experimental" "Experimental BaseTypes" |
| 73 | +model ContosoApplianceAgent is Agent<ContosoApplianceAgentProperties> { |
| 74 | + ...ResourceNameParameter<ContosoApplianceAgent>; |
| 75 | +} |
| 76 | + |
| 77 | +// Platform-deployed agent (client manages configuration) |
| 78 | +#suppress "@azure-tools/typespec-azure-resource-manager/basetypes-experimental" "Experimental BaseTypes" |
| 79 | +model ContosoPlatformAgent is Agent<ContosoPlatformAgentProperties> { |
| 80 | + ...ResourceNameParameter<ContosoPlatformAgent>; |
| 81 | +} |
| 82 | + |
| 83 | +// ============================================================================ |
| 84 | +// Conversation and Response child resources |
| 85 | +// ============================================================================ |
| 86 | + |
| 87 | +// Conversation and Response are required proxy child resources of an Agent. |
| 88 | +// Each must have full CRUD lifecycle operations (create, read, update, delete). |
| 89 | +// ConversationProperties and ResponseProperties provide the base fields; |
| 90 | +// extend them with RP-specific properties as needed. |
| 91 | + |
| 92 | +// RP-specific conversation properties (shared by both agents in this sample) |
| 93 | +model ContosoConversationProperties is ConversationProperties { |
| 94 | + ...DefaultProvisioningStateProperty; |
| 95 | + |
| 96 | + /** System prompt / behavioral instructions for this conversation. */ |
| 97 | + instructions?: string; |
| 98 | +} |
| 99 | + |
| 100 | +// RP-specific response properties (shared by both agents in this sample) |
| 101 | +model ContosoResponseProperties is ResponseProperties { |
| 102 | + ...PreviousResponseProperty; |
| 103 | + ...DefaultProvisioningStateProperty; |
| 104 | +} |
| 105 | + |
| 106 | +@@visibility(ContosoResponseProperties.previousResponseId, Lifecycle.Read); |
| 107 | + |
| 108 | +// Conversation proxy child resource of the Appliance agent |
| 109 | +model ApplianceConversation |
| 110 | + is AgentConversation<ContosoConversationProperties, ContosoApplianceAgent> { |
| 111 | + ...ResourceNameParameter<ApplianceConversation>; |
| 112 | +} |
| 113 | + |
| 114 | +// Response proxy child resource of the Appliance agent |
| 115 | +model ApplianceResponse is AgentResponse<ContosoResponseProperties, ContosoApplianceAgent> { |
| 116 | + ...ResourceNameParameter<ApplianceResponse>; |
| 117 | +} |
| 118 | + |
| 119 | +// Conversation proxy child resource of the Platform agent |
| 120 | +model PlatformConversation |
| 121 | + is AgentConversation<ContosoConversationProperties, ContosoPlatformAgent> { |
| 122 | + ...ResourceNameParameter<PlatformConversation>; |
| 123 | +} |
| 124 | + |
| 125 | +// Response proxy child resource of the Platform agent |
| 126 | +model PlatformResponse is AgentResponse<ContosoResponseProperties, ContosoPlatformAgent> { |
| 127 | + ...ResourceNameParameter<PlatformResponse>; |
| 128 | +} |
| 129 | + |
| 130 | +// ============================================================================ |
| 131 | +// Operations interfaces |
| 132 | +// ============================================================================ |
| 133 | + |
| 134 | +interface Operations extends Azure.ResourceManager.Operations {} |
| 135 | + |
| 136 | +// ARM resource operations use operation templates for standard CRUD patterns. |
| 137 | +// See: https://azure.github.io/typespec-azure/docs/howtos/arm/resource-operations/ |
| 138 | + |
| 139 | +// Appliance agent operations |
| 140 | +@armResourceOperations |
| 141 | +interface ApplianceAgents { |
| 142 | + get is ArmResourceRead<ContosoApplianceAgent>; |
| 143 | + createOrUpdate is ArmResourceCreateOrReplaceAsync<ContosoApplianceAgent>; |
| 144 | + update is ArmTagsPatchSync<ContosoApplianceAgent>; |
| 145 | + delete is ArmResourceDeleteWithoutOkAsync<ContosoApplianceAgent>; |
| 146 | + listBySubscription is ArmListBySubscription<ContosoApplianceAgent>; |
| 147 | + listByResourceGroup is ArmResourceListByParent<ContosoApplianceAgent>; |
| 148 | +} |
| 149 | + |
| 150 | +// Platform agent operations |
| 151 | +@armResourceOperations |
| 152 | +interface PlatformAgents { |
| 153 | + get is ArmResourceRead<ContosoPlatformAgent>; |
| 154 | + createOrUpdate is ArmResourceCreateOrReplaceAsync<ContosoPlatformAgent>; |
| 155 | + update is ArmTagsPatchSync<ContosoPlatformAgent>; |
| 156 | + delete is ArmResourceDeleteWithoutOkAsync<ContosoPlatformAgent>; |
| 157 | + listBySubscription is ArmListBySubscription<ContosoPlatformAgent>; |
| 158 | + listByResourceGroup is ArmResourceListByParent<ContosoPlatformAgent>; |
| 159 | +} |
| 160 | + |
| 161 | +// Conversation and Response proxy child resources require create, read, update, and |
| 162 | +// delete lifecycle operations. Omitting any of these will trigger the |
| 163 | +// arm-agent-base-type-lifecycle-operations linting rule. |
| 164 | +// See: https://azure.github.io/typespec-azure/docs/howtos/arm/resource-operations/ |
| 165 | + |
| 166 | +// Appliance conversation operations (CRUD required) |
| 167 | +@armResourceOperations |
| 168 | +interface ApplianceConversations { |
| 169 | + get is ArmResourceRead<ApplianceConversation>; |
| 170 | + createOrUpdate is ArmResourceCreateOrReplaceAsync<ApplianceConversation>; |
| 171 | + update is ArmCustomPatchSync< |
| 172 | + ApplianceConversation, |
| 173 | + Azure.ResourceManager.Foundations.ResourceUpdateModel< |
| 174 | + ApplianceConversation, |
| 175 | + ContosoConversationProperties |
| 176 | + > |
| 177 | + >; |
| 178 | + delete is ArmResourceDeleteWithoutOkAsync<ApplianceConversation>; |
| 179 | + listByAgent is ArmResourceListByParent<ApplianceConversation>; |
| 180 | +} |
| 181 | + |
| 182 | +// Appliance response operations (CRUD required) |
| 183 | +@armResourceOperations |
| 184 | +interface ApplianceResponses { |
| 185 | + get is ArmResourceRead<ApplianceResponse>; |
| 186 | + createOrUpdate is ArmResourceCreateOrReplaceAsync<ApplianceResponse>; |
| 187 | + update is ArmCustomPatchSync< |
| 188 | + ApplianceResponse, |
| 189 | + Azure.ResourceManager.Foundations.ResourceUpdateModel< |
| 190 | + ApplianceResponse, |
| 191 | + ContosoResponseProperties |
| 192 | + > |
| 193 | + >; |
| 194 | + delete is ArmResourceDeleteWithoutOkAsync<ApplianceResponse>; |
| 195 | + listByAgent is ArmResourceListByParent<ApplianceResponse>; |
| 196 | +} |
| 197 | + |
| 198 | +// Platform conversation operations (CRUD required) |
| 199 | +@armResourceOperations |
| 200 | +interface PlatformConversations { |
| 201 | + get is ArmResourceRead<PlatformConversation>; |
| 202 | + createOrUpdate is ArmResourceCreateOrReplaceAsync<PlatformConversation>; |
| 203 | + update is ArmCustomPatchSync< |
| 204 | + PlatformConversation, |
| 205 | + Azure.ResourceManager.Foundations.ResourceUpdateModel< |
| 206 | + PlatformConversation, |
| 207 | + ContosoConversationProperties |
| 208 | + > |
| 209 | + >; |
| 210 | + delete is ArmResourceDeleteWithoutOkAsync<PlatformConversation>; |
| 211 | + listByAgent is ArmResourceListByParent<PlatformConversation>; |
| 212 | +} |
| 213 | + |
| 214 | +// Platform response operations (CRUD required) |
| 215 | +@armResourceOperations |
| 216 | +interface PlatformResponses { |
| 217 | + get is ArmResourceRead<PlatformResponse>; |
| 218 | + createOrUpdate is ArmResourceCreateOrReplaceAsync<PlatformResponse>; |
| 219 | + update is ArmCustomPatchSync< |
| 220 | + PlatformResponse, |
| 221 | + Azure.ResourceManager.Foundations.ResourceUpdateModel< |
| 222 | + PlatformResponse, |
| 223 | + ContosoResponseProperties |
| 224 | + > |
| 225 | + >; |
| 226 | + delete is ArmResourceDeleteWithoutOkAsync<PlatformResponse>; |
| 227 | + listByAgent is ArmResourceListByParent<PlatformResponse>; |
| 228 | +} |
0 commit comments