diff --git a/weave-js/scripts/generate-schemas.sh b/weave-js/scripts/generate-schemas.sh index 545d81e17af..7fb7ddc7ecc 100644 --- a/weave-js/scripts/generate-schemas.sh +++ b/weave-js/scripts/generate-schemas.sh @@ -3,8 +3,8 @@ # Exit on error set -e -SCHEMA_INPUT_PATH="../weave/trace_server/interface/base_object_classes/generated/generated_base_object_class_schemas.json" -SCHEMA_OUTPUT_PATH="./src/components/PagePanelComponents/Home/Browse3/pages/wfReactInterface/generatedBaseObjectClasses.zod.ts" +SCHEMA_INPUT_PATH="../weave/trace_server/interface/builtin_object_classes/generated/generated_builtin_object_class_schemas.json" +SCHEMA_OUTPUT_PATH="./src/components/PagePanelComponents/Home/Browse3/pages/wfReactInterface/generatedBuiltinObjectClasses.zod.ts" echo "Generating schemas..." @@ -13,10 +13,10 @@ yarn quicktype -s schema "$SCHEMA_INPUT_PATH" -o "$SCHEMA_OUTPUT_PATH" --lang ty # Transform the schema to extract the type map sed -i.bak ' - # Find the GeneratedBaseObjectClassesZodSchema definition and capture its contents - /export const GeneratedBaseObjectClassesZodSchema = z.object({/,/});/ { + # Find the GeneratedBuiltinObjectClassesZodSchema definition and capture its contents + /export const GeneratedBuiltinObjectClassesZodSchema = z.object({/,/});/ { # Replace the opening line with typeMap declaration - s/export const GeneratedBaseObjectClassesZodSchema = z.object({/export const baseObjectClassRegistry = ({/ + s/export const GeneratedBuiltinObjectClassesZodSchema = z.object({/export const builtinObjectClassRegistry = ({/ # Store the pattern h # If this is the last line (with closing brace), append the schema definition @@ -27,7 +27,7 @@ sed -i.bak ' s/.*// i\ \ -export const GeneratedBaseObjectClassesZodSchema = z.object(baseObjectClassRegistry) +export const GeneratedBuiltinObjectClassesZodSchema = z.object(builtinObjectClassRegistry) } } ' "$SCHEMA_OUTPUT_PATH" diff --git a/weave-js/src/components/PagePanelComponents/Home/Browse3/feedback/StructuredFeedback/humanAnnotationTypes.ts b/weave-js/src/components/PagePanelComponents/Home/Browse3/feedback/StructuredFeedback/humanAnnotationTypes.ts index 8d3a89e9d24..2b675e244dc 100644 --- a/weave-js/src/components/PagePanelComponents/Home/Browse3/feedback/StructuredFeedback/humanAnnotationTypes.ts +++ b/weave-js/src/components/PagePanelComponents/Home/Browse3/feedback/StructuredFeedback/humanAnnotationTypes.ts @@ -1,4 +1,4 @@ -import {AnnotationSpec} from '../../pages/wfReactInterface/generatedBaseObjectClasses.zod'; +import {AnnotationSpec} from '../../pages/wfReactInterface/generatedBuiltinObjectClasses.zod'; import {Feedback} from '../../pages/wfReactInterface/traceServerClientTypes'; export const HUMAN_ANNOTATION_BASE_TYPE = 'wandb.annotation'; diff --git a/weave-js/src/components/PagePanelComponents/Home/Browse3/feedback/StructuredFeedback/tsHumanFeedback.ts b/weave-js/src/components/PagePanelComponents/Home/Browse3/feedback/StructuredFeedback/tsHumanFeedback.ts index 6460d474b15..09b04378b9d 100644 --- a/weave-js/src/components/PagePanelComponents/Home/Browse3/feedback/StructuredFeedback/tsHumanFeedback.ts +++ b/weave-js/src/components/PagePanelComponents/Home/Browse3/feedback/StructuredFeedback/tsHumanFeedback.ts @@ -1,6 +1,6 @@ import {useEffect, useMemo, useState} from 'react'; -import {useBaseObjectInstances} from '../../pages/wfReactInterface/baseObjectClassQuery'; +import {useBaseObjectInstances} from '../../pages/wfReactInterface/objectClassQuery'; import { TraceObjQueryReq, TraceObjSchema, diff --git a/weave-js/src/components/PagePanelComponents/Home/Browse3/pages/CallPage/CallScoresViewer.tsx b/weave-js/src/components/PagePanelComponents/Home/Browse3/pages/CallPage/CallScoresViewer.tsx index 0b4e9374a26..9ec2f3ff80e 100644 --- a/weave-js/src/components/PagePanelComponents/Home/Browse3/pages/CallPage/CallScoresViewer.tsx +++ b/weave-js/src/components/PagePanelComponents/Home/Browse3/pages/CallPage/CallScoresViewer.tsx @@ -12,12 +12,12 @@ import {CellValue} from '../../../Browse2/CellValue'; import {NotApplicable} from '../../../Browse2/NotApplicable'; import {SmallRef} from '../../../Browse2/SmallRef'; import {StyledDataGrid} from '../../StyledDataGrid'; // Import the StyledDataGrid component +import {WEAVE_REF_SCHEME} from '../wfReactInterface/constants'; +import {useWFHooks} from '../wfReactInterface/context'; import { TraceObjSchemaForBaseObjectClass, useBaseObjectInstances, -} from '../wfReactInterface/baseObjectClassQuery'; -import {WEAVE_REF_SCHEME} from '../wfReactInterface/constants'; -import {useWFHooks} from '../wfReactInterface/context'; +} from '../wfReactInterface/objectClassQuery'; import {useGetTraceServerClientContext} from '../wfReactInterface/traceServerClientContext'; import {Feedback} from '../wfReactInterface/traceServerClientTypes'; import {projectIdFromParts} from '../wfReactInterface/tsDataModelHooks'; diff --git a/weave-js/src/components/PagePanelComponents/Home/Browse3/pages/LeaderboardPage/LeaderboardListingPage.tsx b/weave-js/src/components/PagePanelComponents/Home/Browse3/pages/LeaderboardPage/LeaderboardListingPage.tsx index 52d6795806c..6d495ec9629 100644 --- a/weave-js/src/components/PagePanelComponents/Home/Browse3/pages/LeaderboardPage/LeaderboardListingPage.tsx +++ b/weave-js/src/components/PagePanelComponents/Home/Browse3/pages/LeaderboardPage/LeaderboardListingPage.tsx @@ -12,8 +12,8 @@ import {SimplePageLayout} from '../common/SimplePageLayout'; import {ObjectVersionsTable} from '../ObjectVersionsPage'; import { useBaseObjectInstances, - useCreateBaseObjectInstance, -} from '../wfReactInterface/baseObjectClassQuery'; + useCreateBuiltinObjectInstance, +} from '../wfReactInterface/objectClassQuery'; import {sanitizeObjectId} from '../wfReactInterface/traceServerDirectClient'; import { convertTraceServerObjectVersionToSchema, @@ -162,7 +162,8 @@ const generateLeaderboardId = () => { }; const useCreateLeaderboard = (entity: string, project: string) => { - const createLeaderboardInstance = useCreateBaseObjectInstance('Leaderboard'); + const createLeaderboardInstance = + useCreateBuiltinObjectInstance('Leaderboard'); const createLeaderboard = async () => { const objectId = sanitizeObjectId(generateLeaderboardId()); diff --git a/weave-js/src/components/PagePanelComponents/Home/Browse3/pages/LeaderboardPage/LeaderboardPage.tsx b/weave-js/src/components/PagePanelComponents/Home/Browse3/pages/LeaderboardPage/LeaderboardPage.tsx index 6fac8eaa599..57a3eee4cd1 100644 --- a/weave-js/src/components/PagePanelComponents/Home/Browse3/pages/LeaderboardPage/LeaderboardPage.tsx +++ b/weave-js/src/components/PagePanelComponents/Home/Browse3/pages/LeaderboardPage/LeaderboardPage.tsx @@ -26,8 +26,8 @@ import {LeaderboardObjectVal} from '../../views/Leaderboard/types/leaderboardCon import {SimplePageLayout} from '../common/SimplePageLayout'; import { useBaseObjectInstances, - useCreateBaseObjectInstance, -} from '../wfReactInterface/baseObjectClassQuery'; + useCreateBuiltinObjectInstance, +} from '../wfReactInterface/objectClassQuery'; import {projectIdFromParts} from '../wfReactInterface/tsDataModelHooks'; import {LeaderboardConfigEditor} from './LeaderboardConfigEditor'; @@ -131,7 +131,7 @@ const useUpdateLeaderboard = ( project: string, objectId: string ) => { - const createLeaderboard = useCreateBaseObjectInstance('Leaderboard'); + const createLeaderboard = useCreateBuiltinObjectInstance('Leaderboard'); const updateLeaderboard = async (leaderboardVal: LeaderboardObjectVal) => { return await createLeaderboard({ diff --git a/weave-js/src/components/PagePanelComponents/Home/Browse3/pages/ScorersPage/AnnotationScorerForm.tsx b/weave-js/src/components/PagePanelComponents/Home/Browse3/pages/ScorersPage/AnnotationScorerForm.tsx index a478437facb..77b993e1f0f 100644 --- a/weave-js/src/components/PagePanelComponents/Home/Browse3/pages/ScorersPage/AnnotationScorerForm.tsx +++ b/weave-js/src/components/PagePanelComponents/Home/Browse3/pages/ScorersPage/AnnotationScorerForm.tsx @@ -2,7 +2,7 @@ import {Box} from '@material-ui/core'; import React, {FC, useCallback, useEffect, useState} from 'react'; import {z} from 'zod'; -import {createBaseObjectInstance} from '../wfReactInterface/baseObjectClassQuery'; +import {createBuiltinObjectInstance} from '../wfReactInterface/objectClassQuery'; import {TraceServerClient} from '../wfReactInterface/traceServerClient'; import {sanitizeObjectId} from '../wfReactInterface/traceServerDirectClient'; import {projectIdFromParts} from '../wfReactInterface/tsDataModelHooks'; @@ -86,7 +86,7 @@ export const onAnnotationScorerSave = async ( ) => { const jsonSchemaType = convertTypeToJsonSchemaType(data.Type.type); const typeExtras = convertTypeExtrasToJsonSchema(data); - return createBaseObjectInstance(client, 'AnnotationSpec', { + return createBuiltinObjectInstance(client, 'AnnotationSpec', { obj: { project_id: projectIdFromParts({entity, project}), object_id: sanitizeObjectId(data.Name), diff --git a/weave-js/src/components/PagePanelComponents/Home/Browse3/pages/ScorersPage/LLMJudgeScorerForm.tsx b/weave-js/src/components/PagePanelComponents/Home/Browse3/pages/ScorersPage/LLMJudgeScorerForm.tsx index 64823e9d551..74b9a83860a 100644 --- a/weave-js/src/components/PagePanelComponents/Home/Browse3/pages/ScorersPage/LLMJudgeScorerForm.tsx +++ b/weave-js/src/components/PagePanelComponents/Home/Browse3/pages/ScorersPage/LLMJudgeScorerForm.tsx @@ -10,9 +10,9 @@ import _ from 'lodash'; import React, {FC, useCallback, useState} from 'react'; import {z} from 'zod'; -import {LlmJudgeActionSpecSchema} from '../wfReactInterface/baseObjectClasses.zod'; -import {createBaseObjectInstance} from '../wfReactInterface/baseObjectClassQuery'; -import {ActionSpecSchema} from '../wfReactInterface/generatedBaseObjectClasses.zod'; +import {LlmJudgeActionSpecSchema} from '../wfReactInterface/builtinObjectClasses.zod'; +import {ActionSpecSchema} from '../wfReactInterface/generatedBuiltinObjectClasses.zod'; +import {createBuiltinObjectInstance} from '../wfReactInterface/objectClassQuery'; import {TraceServerClient} from '../wfReactInterface/traceServerClient'; import {projectIdFromParts} from '../wfReactInterface/tsDataModelHooks'; import {AutocompleteWithLabel} from './FormComponents'; @@ -185,7 +185,7 @@ export const onLLMJudgeScorerSave = async ( config: judgeAction, }); - return createBaseObjectInstance(client, 'ActionSpec', { + return createBuiltinObjectInstance(client, 'ActionSpec', { obj: { project_id: projectIdFromParts({entity, project}), object_id: objectId, diff --git a/weave-js/src/components/PagePanelComponents/Home/Browse3/pages/wfReactInterface/baseObjectClasses.zod.ts b/weave-js/src/components/PagePanelComponents/Home/Browse3/pages/wfReactInterface/builtinObjectClasses.zod.ts similarity index 90% rename from weave-js/src/components/PagePanelComponents/Home/Browse3/pages/wfReactInterface/baseObjectClasses.zod.ts rename to weave-js/src/components/PagePanelComponents/Home/Browse3/pages/wfReactInterface/builtinObjectClasses.zod.ts index 627e23604f3..dc714d679cd 100644 --- a/weave-js/src/components/PagePanelComponents/Home/Browse3/pages/wfReactInterface/baseObjectClasses.zod.ts +++ b/weave-js/src/components/PagePanelComponents/Home/Browse3/pages/wfReactInterface/builtinObjectClasses.zod.ts @@ -1,5 +1,5 @@ /** - * This file contains zod schemas for our baseObjectClasses that are not + * This file contains zod schemas for our builtinObjectClasses that are not * correctly / completely generated by the json-schema to zod converter. */ diff --git a/weave-js/src/components/PagePanelComponents/Home/Browse3/pages/wfReactInterface/generatedBaseObjectClasses.zod.ts b/weave-js/src/components/PagePanelComponents/Home/Browse3/pages/wfReactInterface/generatedBuiltinObjectClasses.zod.ts similarity index 92% rename from weave-js/src/components/PagePanelComponents/Home/Browse3/pages/wfReactInterface/generatedBaseObjectClasses.zod.ts rename to weave-js/src/components/PagePanelComponents/Home/Browse3/pages/wfReactInterface/generatedBuiltinObjectClasses.zod.ts index da218f47a85..5a1c4bbf232 100644 --- a/weave-js/src/components/PagePanelComponents/Home/Browse3/pages/wfReactInterface/generatedBaseObjectClasses.zod.ts +++ b/weave-js/src/components/PagePanelComponents/Home/Browse3/pages/wfReactInterface/generatedBuiltinObjectClasses.zod.ts @@ -71,7 +71,7 @@ export const TestOnlyExampleSchema = z.object({ }); export type TestOnlyExample = z.infer; -export const baseObjectClassRegistry = { +export const builtinObjectClassRegistry = { ActionSpec: ActionSpecSchema, AnnotationSpec: AnnotationSpecSchema, Leaderboard: LeaderboardSchema, @@ -79,10 +79,10 @@ export const baseObjectClassRegistry = { TestOnlyNestedBaseObject: TestOnlyNestedBaseObjectSchema, }; -export const GeneratedBaseObjectClassesZodSchema = z.object( - baseObjectClassRegistry +export const GeneratedBuiltinObjectClassesZodSchema = z.object( + builtinObjectClassRegistry ); -export type GeneratedBaseObjectClassesZod = z.infer< - typeof GeneratedBaseObjectClassesZodSchema +export type GeneratedBuiltinObjectClassesZod = z.infer< + typeof GeneratedBuiltinObjectClassesZodSchema >; diff --git a/weave-js/src/components/PagePanelComponents/Home/Browse3/pages/wfReactInterface/baseObjectClassQuery.test.ts b/weave-js/src/components/PagePanelComponents/Home/Browse3/pages/wfReactInterface/objectClassQuery.test.ts similarity index 93% rename from weave-js/src/components/PagePanelComponents/Home/Browse3/pages/wfReactInterface/baseObjectClassQuery.test.ts rename to weave-js/src/components/PagePanelComponents/Home/Browse3/pages/wfReactInterface/objectClassQuery.test.ts index 9918ae7f285..ebc161e322a 100644 --- a/weave-js/src/components/PagePanelComponents/Home/Browse3/pages/wfReactInterface/baseObjectClassQuery.test.ts +++ b/weave-js/src/components/PagePanelComponents/Home/Browse3/pages/wfReactInterface/objectClassQuery.test.ts @@ -1,13 +1,13 @@ import {expectType} from 'tsd'; -import { - useBaseObjectInstances, - useCreateBaseObjectInstance, -} from './baseObjectClassQuery'; import { TestOnlyExample, TestOnlyExampleSchema, -} from './generatedBaseObjectClasses.zod'; +} from './generatedBuiltinObjectClasses.zod'; +import { + useBaseObjectInstances, + useCreateBuiltinObjectInstance, +} from './objectClassQuery'; import { TraceObjCreateReq, TraceObjCreateRes, @@ -74,7 +74,7 @@ describe('Type Tests', () => { it('useCreateCollectionObject return type matches expected structure', () => { type CreateCollectionObjectReturn = ReturnType< - typeof useCreateBaseObjectInstance<'TestOnlyExample'> + typeof useCreateBuiltinObjectInstance<'TestOnlyExample'> >; // Define the expected type structure diff --git a/weave-js/src/components/PagePanelComponents/Home/Browse3/pages/wfReactInterface/baseObjectClassQuery.ts b/weave-js/src/components/PagePanelComponents/Home/Browse3/pages/wfReactInterface/objectClassQuery.ts similarity index 63% rename from weave-js/src/components/PagePanelComponents/Home/Browse3/pages/wfReactInterface/baseObjectClassQuery.ts rename to weave-js/src/components/PagePanelComponents/Home/Browse3/pages/wfReactInterface/objectClassQuery.ts index 6ceb39daa70..3782dce79f9 100644 --- a/weave-js/src/components/PagePanelComponents/Home/Browse3/pages/wfReactInterface/baseObjectClassQuery.ts +++ b/weave-js/src/components/PagePanelComponents/Home/Browse3/pages/wfReactInterface/objectClassQuery.ts @@ -2,7 +2,7 @@ import {useDeepMemo} from '@wandb/weave/hookUtils'; import {useEffect, useRef, useState} from 'react'; import {z} from 'zod'; -import {baseObjectClassRegistry} from './generatedBaseObjectClasses.zod'; +import {builtinObjectClassRegistry} from './generatedBuiltinObjectClasses.zod'; import {TraceServerClient} from './traceServerClient'; import {useGetTraceServerClientContext} from './traceServerClientContext'; import { @@ -13,17 +13,24 @@ import { } from './traceServerClientTypes'; import {Loadable} from './wfDataModelHooksInterface'; -type BaseObjectClassRegistry = typeof baseObjectClassRegistry; -type BaseObjectClassRegistryKeys = keyof BaseObjectClassRegistry; -type BaseObjectClassType = z.infer< - BaseObjectClassRegistry[C] +type BuiltinObjectClassRegistry = typeof builtinObjectClassRegistry; +type BuiltinObjectClassRegistryKeys = keyof BuiltinObjectClassRegistry; +type BaseObjectClassType = z.infer< + BuiltinObjectClassRegistry[C] >; export type TraceObjSchemaForBaseObjectClass< - C extends BaseObjectClassRegistryKeys + C extends BuiltinObjectClassRegistryKeys > = TraceObjSchema, C>; -export const useBaseObjectInstances = ( +// Notice: this is still `base` object class, not `builtin` object class. +// This means we can search by base object class, but not builtin object class today. +// See https://github.com/wandb/weave/pull/3229 for more details. +// base_object_class: this is the name of the first subclass of any subclass of a weave Object class. +// object_class: the string of the actual class. +export const useBaseObjectInstances = < + C extends BuiltinObjectClassRegistryKeys +>( baseObjectClassName: C, req: TraceObjQueryReq ): Loadable>> => { @@ -56,12 +63,12 @@ export const useBaseObjectInstances = ( return {result: objects, loading}; }; -const getBaseObjectInstances = async ( +const getBaseObjectInstances = async ( client: TraceServerClient, baseObjectClassName: C, req: TraceObjQueryReq ): Promise, C>>> => { - const knownObjectClass = baseObjectClassRegistry[baseObjectClassName]; + const knownObjectClass = builtinObjectClassRegistry[baseObjectClassName]; if (!knownObjectClass) { console.warn(`Unknown object class: ${baseObjectClassName}`); return []; @@ -92,41 +99,42 @@ const getBaseObjectInstances = async ( ); }; -export const useCreateBaseObjectInstance = < - C extends BaseObjectClassRegistryKeys, +export const useCreateBuiltinObjectInstance = < + C extends BuiltinObjectClassRegistryKeys, T = BaseObjectClassType >( - baseObjectClassName: C + objectClassName: C ): ((req: TraceObjCreateReq) => Promise) => { const getTsClient = useGetTraceServerClientContext(); const client = getTsClient(); return (req: TraceObjCreateReq) => - createBaseObjectInstance(client, baseObjectClassName, req); + createBuiltinObjectInstance(client, objectClassName, req); }; -export const createBaseObjectInstance = async < - C extends BaseObjectClassRegistryKeys, +export const createBuiltinObjectInstance = async < + C extends BuiltinObjectClassRegistryKeys, T = BaseObjectClassType >( client: TraceServerClient, - baseObjectClassName: C, + builtinObjectClassName: C, req: TraceObjCreateReq ): Promise => { if ( - req.obj.set_base_object_class != null && - req.obj.set_base_object_class !== baseObjectClassName + req.obj.builtin_object_class != null && + req.obj.builtin_object_class !== builtinObjectClassName ) { throw new Error( - `set_base_object_class must match baseObjectClassName: ${baseObjectClassName}` + `object_class must match objectClassName: ${builtinObjectClassName}` ); } - const knownBaseObjectClass = baseObjectClassRegistry[baseObjectClassName]; - if (!knownBaseObjectClass) { - throw new Error(`Unknown object class: ${baseObjectClassName}`); + const knownBuiltinObjectClass = + builtinObjectClassRegistry[builtinObjectClassName]; + if (!knownBuiltinObjectClass) { + throw new Error(`Unknown object class: ${builtinObjectClassName}`); } - const verifiedObject = knownBaseObjectClass.safeParse(req.obj.val); + const verifiedObject = knownBuiltinObjectClass.safeParse(req.obj.val); if (!verifiedObject.success) { throw new Error( @@ -138,7 +146,7 @@ export const createBaseObjectInstance = async < ...req, obj: { ...req.obj, - set_base_object_class: baseObjectClassName, + builtin_object_class: builtinObjectClassName, }, }; diff --git a/weave-js/src/components/PagePanelComponents/Home/Browse3/pages/wfReactInterface/traceServerClientTypes.ts b/weave-js/src/components/PagePanelComponents/Home/Browse3/pages/wfReactInterface/traceServerClientTypes.ts index c396962f0fb..2ad7efb2564 100644 --- a/weave-js/src/components/PagePanelComponents/Home/Browse3/pages/wfReactInterface/traceServerClientTypes.ts +++ b/weave-js/src/components/PagePanelComponents/Home/Browse3/pages/wfReactInterface/traceServerClientTypes.ts @@ -243,7 +243,7 @@ export type TraceObjCreateReq = { project_id: string; object_id: string; val: T; - set_base_object_class?: string; + builtin_object_class?: string; }; }; diff --git a/weave-js/src/components/PagePanelComponents/Home/Browse3/views/Leaderboard/types/leaderboardConfigType.ts b/weave-js/src/components/PagePanelComponents/Home/Browse3/views/Leaderboard/types/leaderboardConfigType.ts index 5207633ebca..4e28bf19d71 100644 --- a/weave-js/src/components/PagePanelComponents/Home/Browse3/views/Leaderboard/types/leaderboardConfigType.ts +++ b/weave-js/src/components/PagePanelComponents/Home/Browse3/views/Leaderboard/types/leaderboardConfigType.ts @@ -1,4 +1,4 @@ -import {Leaderboard} from '../../../pages/wfReactInterface/generatedBaseObjectClasses.zod'; +import {Leaderboard} from '../../../pages/wfReactInterface/generatedBuiltinObjectClasses.zod'; export const ALL_VALUE = '*';