// import { extractErrorMsg, pretty, } from '@ibgib/helper-gib/dist/helpers/utils-helper.mjs'; import { IbGib_V1 } from '@ibgib/ts-gib/dist/V1/types.mjs'; import { ROOT_ADDR } from '@ibgib/ts-gib/dist/V1/constants.mjs'; import { IbGibAddr } from '@ibgib/ts-gib/dist/types.mjs'; import { CommentIbGib_V1 } from '@ibgib/core-gib/dist/common/comment/comment-types.mjs'; import { IbGibSpaceAny } from '@ibgib/core-gib/dist/witness/space/space-base-v1.mjs'; import { MetaspaceService } from '@ibgib/core-gib/dist/witness/space/metaspace/metaspace-types.mjs'; import { WitnessData_V1, WitnessRel8ns_V1 } from '@ibgib/core-gib/dist/witness/witness-types.mjs'; import { SpaceId } from '@ibgib/core-gib/dist/witness/space/space-types.mjs'; // import { GLOBAL_LOG_A_LOT } from '../../constants.mjs'; import { APIFunctionInfo } from '../../api/api-types.mjs'; import type { AgentWitness_V1 } from './agent-one-file.mjs'; import { AgentWitnessAny, } from './agent-one-file.mjs'; import { GEMINI_DEFAULT_MODEL_STR, GeminiModel } from './gemini/gemini-constants.mjs'; import { AGENT_SPECIAL_IBGIB_TYPE_PRIMARYAGENT, DEFAULT_DESCRIPTION_AGENT, DEFAULT_NAME_AGENT, DEFAULT_UUID_AGENT, TextSource } from './agent-constants.mjs'; import { PromptAPIResult_Gemini } from './gemini/gemini-types.mjs'; export const DEFAULT_AGENT_DATA_V1: AgentWitnessData_V1 = { version: '1', uuid: DEFAULT_UUID_AGENT, name: DEFAULT_NAME_AGENT, description: DEFAULT_DESCRIPTION_AGENT, classname: `AgentWitness_V1`, icon: 'happy', // arbitrary persistOptsAndResultIbGibs: false, allowPrimitiveArgs: true, catchAllErrors: true, trace: false, // agent-specific props subSpaceId: '', // purpose: '', superSpaceId: '', availableFunctionNameOrIds: [], model: GEMINI_DEFAULT_MODEL_STR, api: 'gemini', type: AGENT_SPECIAL_IBGIB_TYPE_PRIMARYAGENT, "@currentContextTjpAddr": ROOT_ADDR, } /** * don't init with an empty obj. use undefined or factory_v1.firstGen blows up. */ export const DEFAULT_AGENT_REL8NS_V1: AgentWitnessRel8ns_V1 | undefined = undefined; /** * @interface AgentWitnessData - Data interface for the AgentWitness. * @extends WitnessData_V1 */ export interface AgentWitnessData_V1 extends WitnessData_V1 { /** * this id corresponds to what space the agent has access to as its own "internal" space. * * TODO: implement initialization code to create/get this space when the * agent is created/initialized. * * TODO: implement an APIFunctionInfo for the agent * * it is possible that we will add access to other spaces in the future. */ subSpaceId: SpaceId; /** * The space in which the agent's ibgib itself is saved. This is often * (always?) different than the super space in which the agent itself * resides. */ superSpaceId: SpaceId; /** * nameOrId corresponding to the function info */ availableFunctionNameOrIds: string[]; /** * @see {@link AgentAPI} */ api: AgentAPI; /** * @see {@link AgentModel} */ model: AgentModel; /** * A more fine-grained discriminator. */ type: string; /** * soft link to the current context ibgib. May be out of date, so should use * get latest on the space (often can do this via metaspace with this * agent's {@link superSpaceId}). * * This defaults to ib^gib (ROOT_ADDR), so if this is the value, then this * has not been initialized yet and the agent needs to have their context * set. */ "@currentContextTjpAddr": IbGibAddr; // string } /** * @interface AgentWitnessRel8ns - Rel8ns interface for the AgentWitness. * @extends IbGibRel8ns_V1 */ export interface AgentWitnessRel8ns_V1 extends WitnessRel8ns_V1 { /** * @property chat - Relationships to comment ibgibs representing chat * history for this agent. * * These are expected to be comment ibgibs with special additional metadata * text in the ib that pertains to the agents {@link AgentWitness_V1}. * * @see {@link system} */ chat?: IbGibAddr[]; /** * @property system - Relationships to comment ibgibs representing the * system prompt. * * This is a Gemini-specific construct that I don't know if it exists in * other APIs. But the intent is that these are comment ibgibs to be used in * composing any meta text that is not part of a "chat" between one or more * users and one or more models. * * These are expected to be comment ibgibs with special additional metadata * text in the ib that pertains to the agents {@link AgentWitness_V1}. * * @see {@link system} */ system?: IbGibAddr[]; } /** * @interface AgentWitnessIbGib_V1 - Interface for an agent ibgib. * * @see {@link AgentWitness_V1} */ export interface AgentWitnessIbGib_V1 extends IbGib_V1 { } export interface AddTextInfo { /** * @property text - raw comment text string to add * @optional */ text?: string; /** * @optional @property commentIbGib - existing comment to add */ commentIbGib?: CommentIbGib_V1; // textSrc: 'hardcoded' | 'human' | 'ai' | 'unknown'; textSrc: TextSource; /** * @property isSystem - If true, adds the text to the system prompt instead of chat history. * @default false */ isSystem?: boolean; } /** * @interface AddTextsOpts - Options for adding multiple text comments. */ export interface AddTextsOpts { infos: AddTextInfo[]; } export interface PromptOneOffOpts { text: string; /** * ad hoc system instructions for the one off call. */ systemInstructions: string; /** * ad hoc model overrides for the one off call. If provided, these will be * tried in order before the default model. */ modelOverrides?: string[]; /** * ad hoc model backup overrides for the one off call. If provided, these will be * tried in order before the default backup model. */ modelBackupOverrides?: string[]; } /** * an agent can only have one active context at any time. * * Really this is a timeline, so the key thing of this context ibgib is its * temporal junction point (tjp). */ export interface SetActiveContextOpts { contextIbGib: IbGib_V1; /** * for debug purposes */ loggingInfo?: string; } /** * When composing the prompt to send to the model, this is the information that * we build up. */ export interface PromptInfo { /** * discriminator of what concrete info is contained in this object. */ api: AgentAPI; } /** * @interface {@link PromptAPIResult} - shape of the result when calling into an * api-specific model. In general, the api will either return a string or a * function call request with optional arg(s) * @see {@link AgentWitness_V1.callTextAPI} */ export type PromptAPIResult = | PromptAPIResult_Gemini; /** * info object containing information in an agent ib schema. */ export interface AgentIbInfo { /** * should be {@link AGENT_ATOM} */ atom: string, name: string, uuid: string, type: string, } /** * information encoded in the addlMetadataText part of a comment ibgib that is * part of an agent's chat/system text. * * notes: long name... */ export interface AddlMetadataTextForAgentTextInfo { /** * @see {@link AddTextInfo.textSrc} */ textSrc: TextSource; timestampInTicks: number; /** * if there are additional underscore-delimited metadata texts, they will be here. */ other?: string[]; errorMsg?: string; } export type AgentModel = | GeminiModel; /** * API discriminator of the underlying model. * * @see {@link AgentWitness_V1} * @see {@link AgentWitnessData_V1.api} */ export type AgentAPI = 'gemini'; /** * shape of passed in arg of {@link createNewAgent}. * * ATOW (01/2024) */ export interface CreateNewAgentArg { /** * metaspace singleton */ metaspace: MetaspaceService; /** * optional space in which to save the agent itself (and dependency ibgibs). * This is often (always?) different than * @default superSpace is the metaspace's default local user space */ superSpace?: IbGibSpaceAny; /** * optional name of new agent. Does not have to be unique, but that's always * nice. if not provided, a random one will be created. */ name?: string; api: AgentAPI; model: AgentModel; /** * what functions are available to the agent. if no functions are available * to the agent, then provide an empty array. * @see {@link AgentWitness_V1.getAvailableFunctions} */ availableFunctions: APIFunctionInfo[]; initialSystemText: string; /** * initial text from the user to the agent. */ initialChatText: string; /** * @see {@link AgentWitness_V1.fnGetAPIKey} */ fnGetAPIKey: () => Promise; /** * if true, will tag the agent with the agents tag in the {@link metaspace} * and {@link superSpace}. */ addToAgentsTag?: boolean; /** * will be used as the SpecialIbGibType */ type: string; } /** * shape of return value of {@link createNewAgent}. * * ATOW (01/2025) */ export type CreateNewAgentResult = AgentWitnessAny; /** * factory to create concrete agents that correspond to a given {@link arg}. * * Specifically this is intended to look at the {@link CreateNewAgentArg.api} */ export interface CreateConcreteAgentWitnessFactory { createInitialData(superSpace: IbGibSpaceAny): Promise; createInitialRel8ns(): Promise; createWitness(): Promise; } export type AgentDtoToWitnessFunction = (dto: IbGib_V1) => Promise<{ applies: boolean, agent?: AgentWitnessAny }>;