6bf8bebf51
CI / Test and Build (push) Failing after 1s
CI / Migrate Dev DB (push) Has been skipped
CI / Migrate DB (push) Has been skipped
CodeQL / Analyze actions (push) Has been cancelled
CodeQL / Analyze javascript-typescript (push) Has been cancelled
CI / Detect Version (push) Has been cancelled
CI / Detect Desktop Changes (push) Has been cancelled
CI / Build AMD64 (blacksmith-2vcpu-ubuntu-2404, ./docker/cron.Dockerfile, ubuntu-latest, ghcr.io/simstudioai/cron) (push) Has been cancelled
CI / Build AMD64 (blacksmith-2vcpu-ubuntu-2404, ./docker/db.Dockerfile, ECR_MIGRATIONS, ubuntu-latest, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build AMD64 (blacksmith-4vcpu-ubuntu-2404, ./docker/pii.Dockerfile, ECR_PII, ubuntu-latest, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build AMD64 (blacksmith-4vcpu-ubuntu-2404, ./docker/realtime.Dockerfile, ECR_REALTIME, ubuntu-latest, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Build AMD64 (blacksmith-8vcpu-ubuntu-2404, ./docker/app.Dockerfile, ECR_APP, linux-x64-8-core, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (blacksmith-4vcpu-ubuntu-2404-arm, ./docker/cron.Dockerfile, ubuntu-24.04-arm, ghcr.io/simstudioai/cron) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (blacksmith-4vcpu-ubuntu-2404-arm, ./docker/db.Dockerfile, ubuntu-24.04-arm, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (blacksmith-4vcpu-ubuntu-2404-arm, ./docker/pii.Dockerfile, ubuntu-24.04-arm, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (blacksmith-4vcpu-ubuntu-2404-arm, ./docker/realtime.Dockerfile, ubuntu-24.04-arm, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (blacksmith-8vcpu-ubuntu-2404-arm, ./docker/app.Dockerfile, linux-arm64-8-core, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Check Docs Changes (push) Has been cancelled
Publish CLI Package / publish-npm (push) Has been cancelled
Publish Python SDK / publish-pypi (push) Has been cancelled
CI / Deploy Trigger.dev (Dev) (push) Has been cancelled
Helm Chart / Lint, test, and validate chart (push) Has been cancelled
Helm Chart / Chart version bumped (push) Has been cancelled
Publish TypeScript SDK / publish-npm (push) Has been cancelled
CI / Build Dev ECR (blacksmith-8vcpu-ubuntu-2404, ./docker/app.Dockerfile, ECR_APP, linux-x64-8-core) (push) Has been cancelled
CI / Promote Images (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/cron) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Build Dev ECR (blacksmith-2vcpu-ubuntu-2404, ./docker/db.Dockerfile, ECR_MIGRATIONS, ubuntu-latest) (push) Has been cancelled
CI / Build Dev ECR (blacksmith-4vcpu-ubuntu-2404, ./docker/pii.Dockerfile, ECR_PII, ubuntu-latest) (push) Has been cancelled
CI / Build Dev ECR (blacksmith-4vcpu-ubuntu-2404, ./docker/realtime.Dockerfile, ECR_REALTIME, ubuntu-latest) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Process Docs (push) Has been cancelled
CI / Create GitHub Release (push) Has been cancelled
CI / Check Desktop Signing Secrets (push) Has been cancelled
CI / Desktop Release (push) Has been cancelled
CI / Create Desktop Prerelease (push) Has been cancelled
CI / Desktop Prerelease Build (push) Has been cancelled
CI / Publish Desktop Prerelease (push) Has been cancelled
CI / Prune Desktop Prereleases (push) Has been cancelled
Helm Chart / Install on kind and run helm test (push) Has been cancelled
158 lines
5.4 KiB
TypeScript
158 lines
5.4 KiB
TypeScript
import { createLogger } from '@sim/logger'
|
|
import type {
|
|
DataverseGetEntityMetadataParams,
|
|
DataverseGetEntityMetadataResponse,
|
|
} from '@/tools/microsoft_dataverse/types'
|
|
import { getDataverseBaseUrl } from '@/tools/microsoft_dataverse/utils'
|
|
import type { ToolConfig } from '@/tools/types'
|
|
|
|
const logger = createLogger('DataverseGetEntityMetadata')
|
|
|
|
const DEFAULT_ATTRIBUTE_SELECT =
|
|
'LogicalName,DisplayName,AttributeType,RequiredLevel,IsPrimaryId,IsPrimaryName'
|
|
|
|
export const dataverseGetEntityMetadataTool: ToolConfig<
|
|
DataverseGetEntityMetadataParams,
|
|
DataverseGetEntityMetadataResponse
|
|
> = {
|
|
id: 'microsoft_dataverse_get_entity_metadata',
|
|
name: 'Get Microsoft Dataverse Table Metadata',
|
|
description:
|
|
'Retrieve table (entity) and column (attribute) definitions for a Microsoft Dataverse table by its singular logical name. Use this to look up the correct entity set name and column logical names before building record data for other operations.',
|
|
version: '1.0.0',
|
|
|
|
oauth: { required: true, provider: 'microsoft-dataverse' },
|
|
errorExtractor: 'nested-error-object',
|
|
|
|
params: {
|
|
accessToken: {
|
|
type: 'string',
|
|
required: true,
|
|
visibility: 'hidden',
|
|
description: 'OAuth access token for Microsoft Dataverse API',
|
|
},
|
|
environmentUrl: {
|
|
type: 'string',
|
|
required: true,
|
|
visibility: 'user-only',
|
|
description: 'Dataverse environment URL (e.g., https://myorg.crm.dynamics.com)',
|
|
},
|
|
entityLogicalName: {
|
|
type: 'string',
|
|
required: true,
|
|
visibility: 'user-or-llm',
|
|
description: 'Singular table logical name to look up (e.g., account, contact)',
|
|
},
|
|
select: {
|
|
type: 'string',
|
|
required: false,
|
|
visibility: 'user-or-llm',
|
|
description:
|
|
'Comma-separated table metadata properties to return (OData $select, e.g., LogicalName,DisplayName,EntitySetName,PrimaryIdAttribute)',
|
|
},
|
|
includeAttributes: {
|
|
type: 'string',
|
|
required: false,
|
|
visibility: 'user-or-llm',
|
|
description: 'Set to "true" to also return the column (attribute) definitions for the table',
|
|
},
|
|
},
|
|
|
|
request: {
|
|
url: (params) => {
|
|
const baseUrl = getDataverseBaseUrl(params.environmentUrl)
|
|
// OData string literals escape embedded single quotes by doubling them - URL-encoding the
|
|
// quote alone isn't sufficient since Dataverse URL-decodes the request before parsing the
|
|
// OData key predicate, so a percent-encoded quote would still land as a literal delimiter.
|
|
const entityLogicalName = params.entityLogicalName.trim().replace(/'/g, "''")
|
|
const queryParts: string[] = []
|
|
if (params.select) queryParts.push(`$select=${encodeURIComponent(params.select)}`)
|
|
if (params.includeAttributes === 'true') {
|
|
queryParts.push(
|
|
`$expand=${encodeURIComponent(`Attributes($select=${DEFAULT_ATTRIBUTE_SELECT})`)}`
|
|
)
|
|
}
|
|
const query = queryParts.length > 0 ? `?${queryParts.join('&')}` : ''
|
|
return `${baseUrl}/api/data/v9.2/EntityDefinitions(LogicalName='${entityLogicalName}')${query}`
|
|
},
|
|
method: 'GET',
|
|
headers: (params) => ({
|
|
Authorization: `Bearer ${params.accessToken}`,
|
|
'OData-MaxVersion': '4.0',
|
|
'OData-Version': '4.0',
|
|
Accept: 'application/json',
|
|
}),
|
|
},
|
|
|
|
transformResponse: async (response: Response) => {
|
|
if (!response.ok) {
|
|
const errorData = await response.json().catch(() => ({}))
|
|
const errorMessage =
|
|
errorData?.error?.message ??
|
|
`Dataverse API error: ${response.status} ${response.statusText}`
|
|
logger.error('Dataverse get entity metadata failed', { errorData, status: response.status })
|
|
throw new Error(errorMessage)
|
|
}
|
|
|
|
const data = await response.json()
|
|
const displayName = data?.DisplayName?.UserLocalizedLabel?.Label ?? null
|
|
|
|
return {
|
|
success: true,
|
|
output: {
|
|
entitySetName: data?.EntitySetName ?? null,
|
|
logicalName: data?.LogicalName ?? null,
|
|
displayName,
|
|
primaryIdAttribute: data?.PrimaryIdAttribute ?? null,
|
|
primaryNameAttribute: data?.PrimaryNameAttribute ?? null,
|
|
attributes: data?.Attributes ?? [],
|
|
metadata: data ?? {},
|
|
success: true,
|
|
},
|
|
}
|
|
},
|
|
|
|
outputs: {
|
|
entitySetName: {
|
|
type: 'string',
|
|
description: 'The entity set name (plural, used in Web API URLs) for this table',
|
|
optional: true,
|
|
},
|
|
logicalName: {
|
|
type: 'string',
|
|
description: 'The singular logical name of the table',
|
|
optional: true,
|
|
},
|
|
displayName: {
|
|
type: 'string',
|
|
description: 'The localized display name of the table',
|
|
optional: true,
|
|
},
|
|
primaryIdAttribute: {
|
|
type: 'string',
|
|
description: 'The logical name of the primary key column',
|
|
optional: true,
|
|
},
|
|
primaryNameAttribute: {
|
|
type: 'string',
|
|
description: 'The logical name of the primary name (title) column',
|
|
optional: true,
|
|
},
|
|
attributes: {
|
|
type: 'array',
|
|
description:
|
|
'Column (attribute) definitions for the table (only populated when includeAttributes is "true")',
|
|
items: {
|
|
type: 'object',
|
|
description:
|
|
'A single column definition (logical name, display name, type, requirement level)',
|
|
},
|
|
},
|
|
metadata: {
|
|
type: 'object',
|
|
description: 'The full raw entity metadata response from Dataverse',
|
|
},
|
|
success: { type: 'boolean', description: 'Whether the metadata was retrieved successfully' },
|
|
},
|
|
}
|