@the-open-engine/zeroshot 6.45.0 → 6.46.0

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.
@@ -7,6 +7,8 @@ import {
7
7
  import type { ClusterMethod, GraphProfile, GraphSpec, ServerCapabilities } from './generated/protocol.js';
8
8
  import { CLUSTER_PROTOCOL_SCHEMA } from './generated/protocol-schema.js';
9
9
  import { ClusterProtocolError, ClusterRequestError } from './errors.js';
10
+ import { isRecord } from './frames.js';
11
+ import type { FrameRecord } from './frames.js';
10
12
 
11
13
  const ajv = new Ajv2020({
12
14
  allErrors: true,
@@ -26,6 +28,41 @@ function validatorFor(definition: string): ValidateFunction {
26
28
  return validator;
27
29
  }
28
30
 
31
+ const RUN_PROJECTION_DEFINITIONS = new Set([
32
+ 'RunForceResult',
33
+ 'RunStatusResult',
34
+ 'RunWatchEventNotification',
35
+ ]);
36
+
37
+ function normalizeRunProjection(value: unknown): unknown {
38
+ if (!isRecord(value)) return value;
39
+ const size = value.size === 'tiny'
40
+ ? 'small'
41
+ : value.size === 'standard'
42
+ ? 'medium'
43
+ : value.size;
44
+ return size === value.size ? value : { ...value, size };
45
+ }
46
+
47
+ /** Normalize deserialize-only aliases before validating an inbound protocol value. */
48
+ function normalizeInboundDefinition(definition: string, value: unknown): unknown {
49
+ if (RUN_PROJECTION_DEFINITIONS.has(definition)) return normalizeRunProjection(value);
50
+ if (definition !== 'RunListResult' || !isRecord(value)) return value;
51
+ const existingRuns = value.runs;
52
+ if (!Array.isArray(existingRuns)) return value;
53
+ const runs = existingRuns.map(normalizeRunProjection);
54
+ return runs.some((run, index) => run !== existingRuns[index]) ? { ...value, runs } : value;
55
+ }
56
+
57
+ export function normalizeInboundSubscriptionFrame(
58
+ kind: string,
59
+ method: string,
60
+ frame: FrameRecord,
61
+ ): FrameRecord {
62
+ if (kind !== 'run/watch' || method !== 'event' || !isRecord(frame.params)) return frame;
63
+ return { ...frame, params: normalizeInboundDefinition('RunWatchEventNotification', frame.params) };
64
+ }
65
+
29
66
  export function assertDefinition(definition: string, value: unknown): void {
30
67
  const validate = validatorFor(definition);
31
68
  if (validate(value)) return;
@@ -38,9 +75,12 @@ export function assertDefinition(definition: string, value: unknown): void {
38
75
  );
39
76
  }
40
77
 
41
- export function assertMethodResult(method: ClusterMethod, value: unknown): void {
78
+ export function assertMethodResult(method: ClusterMethod, value: unknown): unknown {
42
79
  try {
43
- assertDefinition(METHOD_RESULT_DEFINITIONS[method], value);
80
+ const definition = METHOD_RESULT_DEFINITIONS[method];
81
+ const normalized = normalizeInboundDefinition(definition, value);
82
+ assertDefinition(definition, normalized);
83
+ return normalized;
44
84
  } catch (error) {
45
85
  const receivedVersion = method === 'initialize' && value !== null && typeof value === 'object'
46
86
  ? (value as Readonly<Record<string, unknown>>).protocolVersion