wp-typia 0.22.1 → 0.22.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -211339,6 +211339,27 @@ function ensureInterfaceField(source, interfaceName, fieldName, fieldSource) {
211339
211339
  return `${start}${body}${body.length > 0 && !body.endsWith(lineEnding) ? lineEnding : ""}${formattedFieldSource}${end}`;
211340
211340
  });
211341
211341
  }
211342
+ function normalizeInterfaceFieldBlock(source, interfaceName, fieldName, fieldSource, requiredFragments) {
211343
+ const interfacePattern = new RegExp(`(export\\s+interface\\s+${escapeRegex2(interfaceName)}\\s*\\{\\r?\\n)([\\s\\S]*?)(\\r?\\n\\})`, "u");
211344
+ return source.replace(interfacePattern, (match3, start, body, end) => {
211345
+ const fieldPattern = new RegExp(`(^([ \\t]*)${escapeRegex2(fieldName)}\\??:\\s*\\{[ \\t]*\\r?\\n)([\\s\\S]*?)(^\\2\\};\\r?\\n?)`, "mu");
211346
+ const fieldMatch = fieldPattern.exec(body);
211347
+ if (!fieldMatch) {
211348
+ return match3;
211349
+ }
211350
+ const existingFieldSource = fieldMatch[0];
211351
+ if (requiredFragments.every((fragment) => existingFieldSource.includes(fragment))) {
211352
+ return match3;
211353
+ }
211354
+ const lineEnding = start.endsWith(`\r
211355
+ `) ? `\r
211356
+ ` : `
211357
+ `;
211358
+ const formattedFieldSource = `${fieldSource.replace(/\r?\n$/u, "").split(`
211359
+ `).join(lineEnding)}${lineEnding}`;
211360
+ return `${start}${body.slice(0, fieldMatch.index)}${formattedFieldSource}${body.slice(fieldMatch.index + existingFieldSource.length)}${end}`;
211361
+ });
211362
+ }
211342
211363
  function updateWorkspaceInventorySource(source, {
211343
211364
  blockEntries = [],
211344
211365
  blockStyleEntries = [],
@@ -211370,7 +211391,9 @@ function updateWorkspaceInventorySource(source, {
211370
211391
  nextSource = ensureInterfaceField(nextSource, "WorkspaceBindingSourceConfig", "attribute", "\tattribute?: string;");
211371
211392
  nextSource = ensureInterfaceField(nextSource, "WorkspaceBindingSourceConfig", "block", "\tblock?: string;");
211372
211393
  nextSource = ensureInterfaceField(nextSource, "WorkspaceAbilityConfig", "compatibility", WORKSPACE_COMPATIBILITY_CONFIG_FIELD);
211394
+ nextSource = normalizeInterfaceFieldBlock(nextSource, "WorkspaceAbilityConfig", "compatibility", WORKSPACE_COMPATIBILITY_CONFIG_FIELD, ["optionalFeatureIds: string[];", "requiredFeatureIds: string[];"]);
211373
211395
  nextSource = ensureInterfaceField(nextSource, "WorkspaceAiFeatureConfig", "compatibility", WORKSPACE_COMPATIBILITY_CONFIG_FIELD);
211396
+ nextSource = normalizeInterfaceFieldBlock(nextSource, "WorkspaceAiFeatureConfig", "compatibility", WORKSPACE_COMPATIBILITY_CONFIG_FIELD, ["optionalFeatureIds: string[];", "requiredFeatureIds: string[];"]);
211374
211397
  nextSource = appendEntriesAtMarker(nextSource, EDITOR_PLUGIN_CONFIG_ENTRY_MARKER, editorPluginEntries);
211375
211398
  return nextSource;
211376
211399
  }
@@ -211473,7 +211496,9 @@ export const REST_RESOURCES: WorkspaceRestResourceConfig[] = [
211473
211496
  wordpress?: string;
211474
211497
  };
211475
211498
  mode: 'baseline' | 'optional' | 'required';
211499
+ optionalFeatureIds: string[];
211476
211500
  optionalFeatures: string[];
211501
+ requiredFeatureIds: string[];
211477
211502
  requiredFeatures: string[];
211478
211503
  runtimeGates: string[];
211479
211504
  };
@@ -224640,7 +224665,9 @@ function createScaffoldCompatibilityConfig(policy) {
224640
224665
  return {
224641
224666
  hardMinimums: capabilityPlan.hardMinimums,
224642
224667
  mode: getPolicyMode(capabilityPlan),
224668
+ optionalFeatureIds: capabilityPlan.optionalFeatures.map((feature) => feature.id),
224643
224669
  optionalFeatures: capabilityPlan.optionalFeatures.map((feature) => feature.label),
224670
+ requiredFeatureIds: capabilityPlan.requiredFeatures.map((feature) => feature.id),
224644
224671
  requiredFeatures: capabilityPlan.requiredFeatures.map((feature) => feature.label),
224645
224672
  runtimeGates: [
224646
224673
  ...capabilityPlan.requiredFeatures.flatMap(formatRuntimeGate),
@@ -235415,6 +235442,45 @@ export interface ${pascalCase}AiFeatureResponse {
235415
235442
  result: ${pascalCase}AiFeatureResult;
235416
235443
  telemetry: ${pascalCase}AiFeatureTelemetry;
235417
235444
  }
235445
+
235446
+ export type ${pascalCase}AiFeatureSupportProbeMode = 'request-time';
235447
+
235448
+ export type ${pascalCase}AiFeatureUnavailableErrorCode =
235449
+ 'ai_client_unavailable';
235450
+
235451
+ export type ${pascalCase}AiFeatureUnavailableReasonCode =
235452
+ | 'missing-wordpress-ai-client'
235453
+ | 'request-time-support-probe';
235454
+
235455
+ export interface ${pascalCase}AiFeatureSupportReason {
235456
+ code: ${pascalCase}AiFeatureUnavailableReasonCode;
235457
+ label: string & tags.MinLength< 1 > & tags.MaxLength< 160 >;
235458
+ message: string & tags.MinLength< 1 > & tags.MaxLength< 4000 >;
235459
+ }
235460
+
235461
+ export interface ${pascalCase}AiFeatureSupportMetadata {
235462
+ featureLabel: string & tags.MinLength< 1 > & tags.MaxLength< 160 >;
235463
+ featureSlug: string & tags.MinLength< 1 > & tags.MaxLength< 160 >;
235464
+ compatibility: {
235465
+ hardMinimums: {
235466
+ php?: string;
235467
+ wordpress?: string;
235468
+ };
235469
+ mode: 'baseline' | 'optional' | 'required';
235470
+ optionalFeatureIds: string[];
235471
+ optionalFeatures: string[];
235472
+ requiredFeatureIds: string[];
235473
+ requiredFeatures: string[];
235474
+ runtimeGates: string[];
235475
+ };
235476
+ supportProbe: {
235477
+ endpointMethod: 'POST';
235478
+ endpointPath: string & tags.MinLength< 1 > & tags.MaxLength< 200 >;
235479
+ mode: ${pascalCase}AiFeatureSupportProbeMode;
235480
+ unavailableErrorCode: ${pascalCase}AiFeatureUnavailableErrorCode;
235481
+ };
235482
+ unavailableReasons: ${pascalCase}AiFeatureSupportReason[];
235483
+ }
235418
235484
  `;
235419
235485
  }
235420
235486
  function buildAiFeatureValidatorsSource(aiFeatureSlug) {
@@ -235450,6 +235516,8 @@ export const apiValidators = {
235450
235516
  }
235451
235517
  function buildAiFeatureApiSource(aiFeatureSlug) {
235452
235518
  const pascalCase = toPascalCase(aiFeatureSlug);
235519
+ const compatibility = createScaffoldCompatibilityConfig(resolveScaffoldCompatibilityPolicy(OPTIONAL_WORDPRESS_AI_CLIENT_COMPATIBILITY));
235520
+ const title = toTitleCase(aiFeatureSlug);
235453
235521
  return `import {
235454
235522
  callEndpoint,
235455
235523
  resolveRestRouteUrl,
@@ -235457,6 +235525,7 @@ function buildAiFeatureApiSource(aiFeatureSlug) {
235457
235525
 
235458
235526
  import type {
235459
235527
  ${pascalCase}AiFeatureRequest,
235528
+ ${pascalCase}AiFeatureSupportMetadata,
235460
235529
  } from './api-types';
235461
235530
  import {
235462
235531
  run${pascalCase}AiFeatureEndpoint,
@@ -235483,6 +235552,14 @@ function resolveRestNonce( fallback?: string ): string | undefined {
235483
235552
  : undefined;
235484
235553
  }
235485
235554
 
235555
+ function isPlainObject( value: unknown ): value is Record< string, unknown > {
235556
+ return (
235557
+ !! value &&
235558
+ typeof value === 'object' &&
235559
+ ! Array.isArray( value )
235560
+ );
235561
+ }
235562
+
235486
235563
  export const aiFeatureRunEndpoint = {
235487
235564
  ...run${pascalCase}AiFeatureEndpoint,
235488
235565
  buildRequestOptions: () => {
@@ -235498,6 +235575,63 @@ export const aiFeatureRunEndpoint = {
235498
235575
  },
235499
235576
  };
235500
235577
 
235578
+ export const aiFeatureSupportMetadata = {
235579
+ compatibility: ${JSON.stringify(compatibility, null, "\t")},
235580
+ featureLabel: ${quoteTsString(title)},
235581
+ featureSlug: ${quoteTsString(aiFeatureSlug)},
235582
+ supportProbe: {
235583
+ endpointMethod: 'POST',
235584
+ endpointPath: aiFeatureRunEndpoint.path,
235585
+ mode: 'request-time',
235586
+ unavailableErrorCode: 'ai_client_unavailable',
235587
+ },
235588
+ unavailableReasons: [
235589
+ {
235590
+ code: 'missing-wordpress-ai-client',
235591
+ label: 'WordPress AI Client unavailable',
235592
+ message:
235593
+ 'This AI feature stays disabled until the WordPress AI Client is available on the site.',
235594
+ },
235595
+ {
235596
+ code: 'request-time-support-probe',
235597
+ label: 'Support is checked at request time',
235598
+ message:
235599
+ 'Support is verified when the feature runs, so editor and admin UIs should degrade gracefully when the site rejects the request.',
235600
+ },
235601
+ ],
235602
+ } satisfies ${pascalCase}AiFeatureSupportMetadata;
235603
+
235604
+ export function getAiFeatureSupportHintLines() {
235605
+ return aiFeatureSupportMetadata.unavailableReasons.map(
235606
+ ( reason ) => reason.message
235607
+ );
235608
+ }
235609
+
235610
+ export function isAiFeatureSupportUnavailableError( error: unknown ) {
235611
+ if ( ! isPlainObject( error ) ) {
235612
+ return false;
235613
+ }
235614
+
235615
+ const data = isPlainObject( error.data ) ? error.data : undefined;
235616
+ return (
235617
+ error.code === aiFeatureSupportMetadata.supportProbe.unavailableErrorCode ||
235618
+ data?.status === 501
235619
+ );
235620
+ }
235621
+
235622
+ export function resolveAiFeatureUnavailableMessage( error: unknown ) {
235623
+ if (
235624
+ isPlainObject( error ) &&
235625
+ typeof error.message === 'string' &&
235626
+ error.message.length > 0
235627
+ ) {
235628
+ return error.message;
235629
+ }
235630
+
235631
+ return aiFeatureSupportMetadata.unavailableReasons[ 0 ]?.message ??
235632
+ 'This AI feature is currently unavailable.';
235633
+ }
235634
+
235501
235635
  export function runAiFeature( request: ${pascalCase}AiFeatureRequest ) {
235502
235636
  return callEndpoint( aiFeatureRunEndpoint, request );
235503
235637
  }
@@ -235516,6 +235650,10 @@ import type {
235516
235650
  } from './api-types';
235517
235651
  import {
235518
235652
  aiFeatureRunEndpoint,
235653
+ aiFeatureSupportMetadata,
235654
+ getAiFeatureSupportHintLines,
235655
+ isAiFeatureSupportUnavailableError,
235656
+ resolveAiFeatureUnavailableMessage,
235519
235657
  } from './api';
235520
235658
 
235521
235659
  export type UseRun${pascalCase}AiFeatureMutationOptions =
@@ -235530,6 +235668,13 @@ export function useRun${pascalCase}AiFeatureMutation(
235530
235668
  ) {
235531
235669
  return useEndpointMutation( aiFeatureRunEndpoint, options );
235532
235670
  }
235671
+
235672
+ export {
235673
+ aiFeatureSupportMetadata,
235674
+ getAiFeatureSupportHintLines,
235675
+ isAiFeatureSupportUnavailableError,
235676
+ resolveAiFeatureUnavailableMessage,
235677
+ };
235533
235678
  `;
235534
235679
  }
235535
235680
  function buildAiFeatureSyncScriptSource() {
@@ -235953,18 +236098,40 @@ function buildAiFeaturePhpSource(aiFeatureSlug, namespace, phpPrefix, textDomain
235953
236098
  const normalizeSchemaFunctionName = `${phpPrefix}_${aiFeaturePhpId}_sanitize_ai_feature_schema`;
235954
236099
  const validatePayloadFunctionName = `${phpPrefix}_${aiFeaturePhpId}_validate_ai_feature_payload`;
235955
236100
  const canManageFunctionName = `${phpPrefix}_${aiFeaturePhpId}_can_manage_ai_feature`;
236101
+ const normalizePromptPayloadFunctionName = `${phpPrefix}_${aiFeaturePhpId}_normalize_ai_feature_prompt_payload`;
235956
236102
  const buildPromptFunctionName = `${phpPrefix}_${aiFeaturePhpId}_build_ai_feature_prompt`;
236103
+ const resolvePromptOptionsFunctionName = `${phpPrefix}_${aiFeaturePhpId}_resolve_ai_feature_prompt_options`;
235957
236104
  const normalizeProviderTypeFunctionName = `${phpPrefix}_${aiFeaturePhpId}_normalize_provider_type`;
235958
236105
  const buildTelemetryFunctionName = `${phpPrefix}_${aiFeaturePhpId}_build_ai_feature_telemetry`;
236106
+ const resolveUnavailableMessageFunctionName = `${phpPrefix}_${aiFeaturePhpId}_resolve_ai_feature_unavailable_message`;
235959
236107
  const isSupportedFunctionName = `${phpPrefix}_${aiFeaturePhpId}_is_ai_feature_supported`;
235960
236108
  const adminNoticeFunctionName = `${phpPrefix}_${aiFeaturePhpId}_ai_feature_admin_notice`;
235961
236109
  const handlerFunctionName = `${phpPrefix}_${aiFeaturePhpId}_handle_run_ai_feature`;
235962
236110
  const registerRoutesFunctionName = `${phpPrefix}_${aiFeaturePhpId}_register_ai_feature_routes`;
236111
+ const permissionFilterHook = `${phpPrefix}_${aiFeaturePhpId}_ai_feature_permission`;
236112
+ const promptPayloadFilterHook = `${phpPrefix}_${aiFeaturePhpId}_ai_feature_prompt_payload`;
236113
+ const promptFilterHook = `${phpPrefix}_${aiFeaturePhpId}_ai_feature_prompt`;
236114
+ const promptOptionsFilterHook = `${phpPrefix}_${aiFeaturePhpId}_ai_feature_prompt_options`;
236115
+ const adminNoticeMessageFilterHook = `${phpPrefix}_${aiFeaturePhpId}_ai_feature_admin_notice_message`;
236116
+ const unavailableMessageFilterHook = `${phpPrefix}_${aiFeaturePhpId}_ai_feature_unavailable_message`;
236117
+ const telemetryFilterHook = `${phpPrefix}_${aiFeaturePhpId}_ai_feature_telemetry`;
235963
236118
  return `<?php
235964
236119
  if ( ! defined( 'ABSPATH' ) ) {
235965
236120
  return;
235966
236121
  }
235967
236122
 
236123
+ /*
236124
+ * Customization hooks for the ${aiFeatureTitle} AI feature:
236125
+ *
236126
+ * - ${quotePhpString(permissionFilterHook)} filters the default current_user_can( 'edit_posts' ) capability check.
236127
+ * - ${quotePhpString(promptPayloadFilterHook)} filters the validated request payload array before prompt serialization.
236128
+ * - ${quotePhpString(promptFilterHook)} filters the final prompt string after payload normalization.
236129
+ * - ${quotePhpString(promptOptionsFilterHook)} filters prompt options with \`temperature\` and \`modelPreference\` keys.
236130
+ * - ${quotePhpString(adminNoticeMessageFilterHook)} filters the wp-admin notice shown when AI support is unavailable.
236131
+ * - ${quotePhpString(unavailableMessageFilterHook)} filters REST-facing unavailable messages by reason code.
236132
+ * - ${quotePhpString(telemetryFilterHook)} filters the response telemetry array before schema validation. Return a schema-compatible array.
236133
+ */
236134
+
235968
236135
  if ( ! function_exists( '${loadSchemaFunctionName}' ) ) {
235969
236136
  function ${loadSchemaFunctionName}( $schema_name ) {
235970
236137
  $project_root = dirname( __DIR__, 2 );
@@ -236031,17 +236198,111 @@ if ( ! function_exists( '${validatePayloadFunctionName}' ) ) {
236031
236198
  }
236032
236199
 
236033
236200
  if ( ! function_exists( '${canManageFunctionName}' ) ) {
236034
- function ${canManageFunctionName}() {
236035
- return current_user_can( 'edit_posts' );
236201
+ function ${canManageFunctionName}( WP_REST_Request $request = null ) {
236202
+ $permission = apply_filters(
236203
+ ${quotePhpString(permissionFilterHook)},
236204
+ current_user_can( 'edit_posts' ),
236205
+ $request
236206
+ );
236207
+ if ( is_wp_error( $permission ) ) {
236208
+ return $permission;
236209
+ }
236210
+ return (bool) $permission;
236211
+ }
236212
+ }
236213
+
236214
+ if ( ! function_exists( '${normalizePromptPayloadFunctionName}' ) ) {
236215
+ function ${normalizePromptPayloadFunctionName}( array $payload ) {
236216
+ $normalized_payload = apply_filters(
236217
+ ${quotePhpString(promptPayloadFilterHook)},
236218
+ $payload
236219
+ );
236220
+ return is_array( $normalized_payload ) ? $normalized_payload : $payload;
236036
236221
  }
236037
236222
  }
236038
236223
 
236039
236224
  if ( ! function_exists( '${buildPromptFunctionName}' ) ) {
236040
236225
  function ${buildPromptFunctionName}( array $payload ) {
236041
- return sprintf(
236226
+ $normalized_payload = ${normalizePromptPayloadFunctionName}( $payload );
236227
+ $prompt = sprintf(
236042
236228
  'You are helping with the %1$s AI workflow. Read the JSON request payload and return JSON that matches the provided schema. Request payload: %2$s',
236043
236229
  ${quotePhpString(aiFeatureTitle)},
236044
- wp_json_encode( $payload )
236230
+ wp_json_encode( $normalized_payload )
236231
+ );
236232
+ $filtered_prompt = apply_filters(
236233
+ ${quotePhpString(promptFilterHook)},
236234
+ $prompt,
236235
+ $normalized_payload,
236236
+ $payload
236237
+ );
236238
+ return is_string( $filtered_prompt ) && '' !== $filtered_prompt ? $filtered_prompt : $prompt;
236239
+ }
236240
+ }
236241
+
236242
+ if ( ! function_exists( '${resolvePromptOptionsFunctionName}' ) ) {
236243
+ function ${resolvePromptOptionsFunctionName}( array $payload = array() ) {
236244
+ $options = apply_filters(
236245
+ ${quotePhpString(promptOptionsFilterHook)},
236246
+ array(
236247
+ 'modelPreference' => array(),
236248
+ 'temperature' => 0.2,
236249
+ ),
236250
+ $payload
236251
+ );
236252
+ if ( ! is_array( $options ) ) {
236253
+ $options = array();
236254
+ }
236255
+
236256
+ $temperature = 0.2;
236257
+ if ( array_key_exists( 'temperature', $options ) ) {
236258
+ if ( null === $options['temperature'] ) {
236259
+ $temperature = null;
236260
+ } elseif ( is_numeric( $options['temperature'] ) ) {
236261
+ $temperature = (float) $options['temperature'];
236262
+ }
236263
+ }
236264
+
236265
+ $model_preferences = array();
236266
+ if ( isset( $options['modelPreference'] ) ) {
236267
+ $raw_model_preferences = $options['modelPreference'];
236268
+ if ( is_string( $raw_model_preferences ) && '' !== $raw_model_preferences ) {
236269
+ $model_preferences = array( $raw_model_preferences );
236270
+ } elseif ( is_array( $raw_model_preferences ) ) {
236271
+ $model_preferences = array_values(
236272
+ array_filter(
236273
+ array_map(
236274
+ static function ( $candidate ) {
236275
+ if ( is_string( $candidate ) && '' !== $candidate ) {
236276
+ return $candidate;
236277
+ }
236278
+ if ( ! is_array( $candidate ) ) {
236279
+ return null;
236280
+ }
236281
+
236282
+ $normalized = array_values(
236283
+ array_filter(
236284
+ $candidate,
236285
+ static function ( $value ) {
236286
+ return is_string( $value ) && '' !== $value;
236287
+ }
236288
+ )
236289
+ );
236290
+
236291
+ return count( $normalized ) > 0 ? $normalized : null;
236292
+ },
236293
+ $raw_model_preferences
236294
+ ),
236295
+ static function ( $candidate ) {
236296
+ return null !== $candidate;
236297
+ }
236298
+ )
236299
+ );
236300
+ }
236301
+ }
236302
+
236303
+ return array(
236304
+ 'modelPreference' => $model_preferences,
236305
+ 'temperature' => $temperature,
236045
236306
  );
236046
236307
  }
236047
236308
  }
@@ -236057,7 +236318,7 @@ if ( ! function_exists( '${normalizeProviderTypeFunctionName}' ) ) {
236057
236318
  }
236058
236319
 
236059
236320
  if ( ! function_exists( '${buildTelemetryFunctionName}' ) ) {
236060
- function ${buildTelemetryFunctionName}( $result ) {
236321
+ function ${buildTelemetryFunctionName}( $result, array $payload = array(), array $normalized_result = array() ) {
236061
236322
  if (
236062
236323
  ! is_object( $result ) ||
236063
236324
  ! method_exists( $result, 'getId' ) ||
@@ -236117,47 +236378,95 @@ if ( ! function_exists( '${buildTelemetryFunctionName}' ) ) {
236117
236378
  }
236118
236379
  }
236119
236380
 
236120
- return $telemetry;
236381
+ $filtered_telemetry = apply_filters(
236382
+ ${quotePhpString(telemetryFilterHook)},
236383
+ $telemetry,
236384
+ $result,
236385
+ $payload,
236386
+ $normalized_result
236387
+ );
236388
+ return is_array( $filtered_telemetry ) ? $filtered_telemetry : $telemetry;
236389
+ }
236390
+ }
236391
+
236392
+ if ( ! function_exists( '${resolveUnavailableMessageFunctionName}' ) ) {
236393
+ function ${resolveUnavailableMessageFunctionName}( $message, $reason, array $context = array() ) {
236394
+ $filtered_message = apply_filters(
236395
+ ${quotePhpString(unavailableMessageFilterHook)},
236396
+ $message,
236397
+ $reason,
236398
+ $context
236399
+ );
236400
+ return is_string( $filtered_message ) && '' !== $filtered_message ? $filtered_message : $message;
236121
236401
  }
236122
236402
  }
236123
236403
 
236124
236404
  if ( ! function_exists( '${isSupportedFunctionName}' ) ) {
236125
- function ${isSupportedFunctionName}() {
236405
+ function ${isSupportedFunctionName}( array $payload = array(), $cache_result = true ) {
236126
236406
  static $is_supported = null;
236127
- if ( null !== $is_supported ) {
236407
+ $use_cache = $cache_result && count( $payload ) === 0;
236408
+ if ( $use_cache && null !== $is_supported ) {
236128
236409
  return $is_supported;
236129
236410
  }
236130
236411
 
236131
236412
  if ( ! function_exists( 'wp_ai_client_prompt' ) ) {
236132
- $is_supported = false;
236133
- return $is_supported;
236413
+ if ( $use_cache ) {
236414
+ $is_supported = false;
236415
+ }
236416
+ return false;
236134
236417
  }
236135
236418
 
236136
236419
  $schema = ${loadAiSchemaFunctionName}();
236137
236420
  if ( ! is_array( $schema ) ) {
236138
- $is_supported = false;
236139
- return $is_supported;
236421
+ if ( $use_cache ) {
236422
+ $is_supported = false;
236423
+ }
236424
+ return false;
236140
236425
  }
236141
236426
 
236142
236427
  $prompt = wp_ai_client_prompt( 'AI feature support probe.' );
236143
236428
  if ( ! is_object( $prompt ) || ! method_exists( $prompt, 'as_json_response' ) ) {
236144
- $is_supported = false;
236145
- return $is_supported;
236429
+ if ( $use_cache ) {
236430
+ $is_supported = false;
236431
+ }
236432
+ return false;
236433
+ }
236434
+ $prompt_options = ${resolvePromptOptionsFunctionName}( $payload );
236435
+ if (
236436
+ array_key_exists( 'temperature', $prompt_options ) &&
236437
+ null !== $prompt_options['temperature'] &&
236438
+ method_exists( $prompt, 'using_temperature' )
236439
+ ) {
236440
+ $prompt = $prompt->using_temperature( $prompt_options['temperature'] );
236441
+ }
236442
+ if (
236443
+ ! empty( $prompt_options['modelPreference'] ) &&
236444
+ method_exists( $prompt, 'using_model_preference' )
236445
+ ) {
236446
+ $prompt = $prompt->using_model_preference( ...$prompt_options['modelPreference'] );
236146
236447
  }
236147
236448
 
236148
236449
  $structured_prompt = $prompt->as_json_response( $schema );
236149
236450
  if ( ! is_object( $structured_prompt ) ) {
236150
- $is_supported = false;
236151
- return $is_supported;
236451
+ if ( $use_cache ) {
236452
+ $is_supported = false;
236453
+ }
236454
+ return false;
236152
236455
  }
236153
236456
 
236154
236457
  if ( method_exists( $structured_prompt, 'is_supported_for_text_generation' ) ) {
236155
- $is_supported = (bool) $structured_prompt->is_supported_for_text_generation();
236156
- return $is_supported;
236458
+ $supported = (bool) $structured_prompt->is_supported_for_text_generation();
236459
+ if ( $use_cache ) {
236460
+ $is_supported = $supported;
236461
+ }
236462
+ return $supported;
236157
236463
  }
236158
236464
 
236159
- $is_supported = method_exists( $structured_prompt, 'generate_text_result' );
236160
- return $is_supported;
236465
+ $supported = method_exists( $structured_prompt, 'generate_text_result' );
236466
+ if ( $use_cache ) {
236467
+ $is_supported = $supported;
236468
+ }
236469
+ return $supported;
236161
236470
  }
236162
236471
  }
236163
236472
 
@@ -236172,6 +236481,18 @@ if ( ! function_exists( '${adminNoticeFunctionName}' ) ) {
236172
236481
  __( 'The %s AI feature is optional and remains disabled until the WordPress AI Client is available with structured text generation support for the generated schema.', ${quotePhpString(textDomain)} ),
236173
236482
  ${quotePhpString(aiFeatureTitle)}
236174
236483
  );
236484
+ $filtered_message = apply_filters(
236485
+ ${quotePhpString(adminNoticeMessageFilterHook)},
236486
+ $message,
236487
+ array(
236488
+ 'featureSlug' => ${quotePhpString(aiFeatureSlug)},
236489
+ 'featureTitle' => ${quotePhpString(aiFeatureTitle)},
236490
+ 'namespace' => ${quotePhpString(namespace)},
236491
+ )
236492
+ );
236493
+ if ( is_string( $filtered_message ) && '' !== $filtered_message ) {
236494
+ $message = $filtered_message;
236495
+ }
236175
236496
  printf( '<div class="notice notice-warning"><p>%s</p></div>', esc_html( $message ) );
236176
236497
  }
236177
236498
  }
@@ -236183,10 +236504,16 @@ if ( ! function_exists( '${handlerFunctionName}' ) ) {
236183
236504
  return $payload;
236184
236505
  }
236185
236506
 
236186
- if ( ! ${isSupportedFunctionName}() ) {
236507
+ if ( ! ${isSupportedFunctionName}( $payload, false ) ) {
236187
236508
  return new WP_Error(
236188
236509
  'ai_client_unavailable',
236189
- 'The WordPress AI Client is unavailable or does not support this feature endpoint.',
236510
+ ${resolveUnavailableMessageFunctionName}(
236511
+ 'The WordPress AI Client is unavailable or does not support this feature endpoint.',
236512
+ 'support_probe_failed',
236513
+ array(
236514
+ 'featureSlug' => ${quotePhpString(aiFeatureSlug)},
236515
+ )
236516
+ ),
236190
236517
  array( 'status' => 501 )
236191
236518
  );
236192
236519
  }
@@ -236200,22 +236527,45 @@ if ( ! function_exists( '${handlerFunctionName}' ) ) {
236200
236527
  );
236201
236528
  }
236202
236529
 
236530
+ $prompt_options = ${resolvePromptOptionsFunctionName}( $payload );
236203
236531
  $prompt = wp_ai_client_prompt( ${buildPromptFunctionName}( $payload ) );
236204
236532
  if ( ! is_object( $prompt ) ) {
236205
236533
  return new WP_Error(
236206
236534
  'ai_client_unavailable',
236207
- 'The WordPress AI Client prompt builder is unavailable on this site.',
236535
+ ${resolveUnavailableMessageFunctionName}(
236536
+ 'The WordPress AI Client prompt builder is unavailable on this site.',
236537
+ 'prompt_builder_missing',
236538
+ array(
236539
+ 'featureSlug' => ${quotePhpString(aiFeatureSlug)},
236540
+ )
236541
+ ),
236208
236542
  array( 'status' => 501 )
236209
236543
  );
236210
236544
  }
236211
236545
 
236212
- if ( method_exists( $prompt, 'using_temperature' ) ) {
236213
- $prompt = $prompt->using_temperature( 0.2 );
236546
+ if (
236547
+ array_key_exists( 'temperature', $prompt_options ) &&
236548
+ null !== $prompt_options['temperature'] &&
236549
+ method_exists( $prompt, 'using_temperature' )
236550
+ ) {
236551
+ $prompt = $prompt->using_temperature( $prompt_options['temperature'] );
236552
+ }
236553
+ if (
236554
+ ! empty( $prompt_options['modelPreference'] ) &&
236555
+ method_exists( $prompt, 'using_model_preference' )
236556
+ ) {
236557
+ $prompt = $prompt->using_model_preference( ...$prompt_options['modelPreference'] );
236214
236558
  }
236215
236559
  if ( ! method_exists( $prompt, 'as_json_response' ) ) {
236216
236560
  return new WP_Error(
236217
236561
  'ai_client_unavailable',
236218
- 'The current WordPress AI Client does not expose as_json_response().',
236562
+ ${resolveUnavailableMessageFunctionName}(
236563
+ 'The current WordPress AI Client does not expose as_json_response().',
236564
+ 'as_json_response_missing',
236565
+ array(
236566
+ 'featureSlug' => ${quotePhpString(aiFeatureSlug)},
236567
+ )
236568
+ ),
236219
236569
  array( 'status' => 501 )
236220
236570
  );
236221
236571
  }
@@ -236224,7 +236574,13 @@ if ( ! function_exists( '${handlerFunctionName}' ) ) {
236224
236574
  if ( ! is_object( $structured_prompt ) ) {
236225
236575
  return new WP_Error(
236226
236576
  'ai_client_unavailable',
236227
- 'The current WordPress AI Client could not prepare a structured-output prompt.',
236577
+ ${resolveUnavailableMessageFunctionName}(
236578
+ 'The current WordPress AI Client could not prepare a structured-output prompt.',
236579
+ 'structured_prompt_missing',
236580
+ array(
236581
+ 'featureSlug' => ${quotePhpString(aiFeatureSlug)},
236582
+ )
236583
+ ),
236228
236584
  array( 'status' => 501 )
236229
236585
  );
236230
236586
  }
@@ -236235,14 +236591,26 @@ if ( ! function_exists( '${handlerFunctionName}' ) ) {
236235
236591
  ) {
236236
236592
  return new WP_Error(
236237
236593
  'ai_client_unavailable',
236238
- 'The current WordPress AI Client provider or model does not support this structured-output feature.',
236594
+ ${resolveUnavailableMessageFunctionName}(
236595
+ 'The current WordPress AI Client provider or model does not support this structured-output feature.',
236596
+ 'text_generation_unsupported',
236597
+ array(
236598
+ 'featureSlug' => ${quotePhpString(aiFeatureSlug)},
236599
+ )
236600
+ ),
236239
236601
  array( 'status' => 501 )
236240
236602
  );
236241
236603
  }
236242
236604
  if ( ! method_exists( $structured_prompt, 'generate_text_result' ) ) {
236243
236605
  return new WP_Error(
236244
236606
  'ai_client_unavailable',
236245
- 'The current WordPress AI Client does not expose generate_text_result() after as_json_response().',
236607
+ ${resolveUnavailableMessageFunctionName}(
236608
+ 'The current WordPress AI Client does not expose generate_text_result() after as_json_response().',
236609
+ 'generate_text_result_missing',
236610
+ array(
236611
+ 'featureSlug' => ${quotePhpString(aiFeatureSlug)},
236612
+ )
236613
+ ),
236246
236614
  array( 'status' => 501 )
236247
236615
  );
236248
236616
  }
@@ -236277,7 +236645,7 @@ if ( ! function_exists( '${handlerFunctionName}' ) ) {
236277
236645
  );
236278
236646
  }
236279
236647
 
236280
- $telemetry = ${buildTelemetryFunctionName}( $result );
236648
+ $telemetry = ${buildTelemetryFunctionName}( $result, $payload, $normalized_result );
236281
236649
  if ( is_wp_error( $telemetry ) ) {
236282
236650
  return $telemetry;
236283
236651
  }
@@ -293449,7 +293817,7 @@ import path10 from "path";
293449
293817
  // package.json
293450
293818
  var package_default2 = {
293451
293819
  name: "wp-typia",
293452
- version: "0.22.1",
293820
+ version: "0.22.2",
293453
293821
  description: "Canonical CLI package for wp-typia scaffolding and project workflows",
293454
293822
  packageManager: "bun@1.3.11",
293455
293823
  type: "module",
@@ -293519,7 +293887,7 @@ var package_default2 = {
293519
293887
  "@bunli/tui": "0.6.0",
293520
293888
  "@bunli/utils": "0.6.0",
293521
293889
  "@wp-typia/api-client": "^0.4.5",
293522
- "@wp-typia/project-tools": "0.22.1",
293890
+ "@wp-typia/project-tools": "0.22.2",
293523
293891
  "better-result": "^2.7.0",
293524
293892
  react: "^19.2.5",
293525
293893
  "react-dom": "^19.2.5",
@@ -296071,4 +296439,4 @@ export {
296071
296439
  cli
296072
296440
  };
296073
296441
 
296074
- //# debugId=7FC90D52A694344264756E2164756E21
296442
+ //# debugId=95E6742032974D4764756E2164756E21
@@ -54,7 +54,7 @@ import {
54
54
  } from "./cli-sj5mtyzj.js";
55
55
  import {
56
56
  readWorkspaceInventory
57
- } from "./cli-5md428hf.js";
57
+ } from "./cli-smzkbfna.js";
58
58
  import {
59
59
  getInvalidWorkspaceProjectReason,
60
60
  tryResolveWorkspaceProject