"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.JsonSchema = exports.ToolResultList = exports.FunctionResult = exports.ToolResult = exports.ToolCallList = exports.FunctionCall = exports.ToolCall = exports.FunctionTool = exports.Tool = exports.Token = exports.Alternative = exports.ContentUsage_CompletionTokensDetails = exports.ContentUsage = exports.Message = exports.ReasoningOptions = exports.CompletionOptions = exports.alternative_AlternativeStatusToJSON = exports.alternative_AlternativeStatusFromJSON = exports.Alternative_AlternativeStatus = exports.reasoningOptions_ReasoningModeToJSON = exports.reasoningOptions_ReasoningModeFromJSON = exports.ReasoningOptions_ReasoningMode = exports.protobufPackage = void 0;
/* eslint-disable */
const long_1 = __importDefault(require("long"));
const minimal_1 = __importDefault(require("protobufjs/minimal"));
const wrappers_1 = require("../../../../../google/protobuf/wrappers");
const struct_1 = require("../../../../../google/protobuf/struct");
exports.protobufPackage = 'yandex.cloud.ai.foundation_models.v1';
/** Enum representing the reasoning mode. */
var ReasoningOptions_ReasoningMode;
(function (ReasoningOptions_ReasoningMode) {
    /** REASONING_MODE_UNSPECIFIED - Unspecified reasoning mode. */
    ReasoningOptions_ReasoningMode[ReasoningOptions_ReasoningMode["REASONING_MODE_UNSPECIFIED"] = 0] = "REASONING_MODE_UNSPECIFIED";
    /** DISABLED - Disables reasoning. The model will generate a response without performing any internal reasoning. */
    ReasoningOptions_ReasoningMode[ReasoningOptions_ReasoningMode["DISABLED"] = 1] = "DISABLED";
    /** ENABLED_HIDDEN - Enables reasoning in a hidden manner without exposing the reasoning steps to the user. */
    ReasoningOptions_ReasoningMode[ReasoningOptions_ReasoningMode["ENABLED_HIDDEN"] = 2] = "ENABLED_HIDDEN";
    ReasoningOptions_ReasoningMode[ReasoningOptions_ReasoningMode["UNRECOGNIZED"] = -1] = "UNRECOGNIZED";
})(ReasoningOptions_ReasoningMode = exports.ReasoningOptions_ReasoningMode || (exports.ReasoningOptions_ReasoningMode = {}));
function reasoningOptions_ReasoningModeFromJSON(object) {
    switch (object) {
        case 0:
        case 'REASONING_MODE_UNSPECIFIED':
            return ReasoningOptions_ReasoningMode.REASONING_MODE_UNSPECIFIED;
        case 1:
        case 'DISABLED':
            return ReasoningOptions_ReasoningMode.DISABLED;
        case 2:
        case 'ENABLED_HIDDEN':
            return ReasoningOptions_ReasoningMode.ENABLED_HIDDEN;
        case -1:
        case 'UNRECOGNIZED':
        default:
            return ReasoningOptions_ReasoningMode.UNRECOGNIZED;
    }
}
exports.reasoningOptions_ReasoningModeFromJSON = reasoningOptions_ReasoningModeFromJSON;
function reasoningOptions_ReasoningModeToJSON(object) {
    switch (object) {
        case ReasoningOptions_ReasoningMode.REASONING_MODE_UNSPECIFIED:
            return 'REASONING_MODE_UNSPECIFIED';
        case ReasoningOptions_ReasoningMode.DISABLED:
            return 'DISABLED';
        case ReasoningOptions_ReasoningMode.ENABLED_HIDDEN:
            return 'ENABLED_HIDDEN';
        default:
            return 'UNKNOWN';
    }
}
exports.reasoningOptions_ReasoningModeToJSON = reasoningOptions_ReasoningModeToJSON;
/** Enum representing the generation status of the alternative. */
var Alternative_AlternativeStatus;
(function (Alternative_AlternativeStatus) {
    /** ALTERNATIVE_STATUS_UNSPECIFIED - Unspecified generation status. */
    Alternative_AlternativeStatus[Alternative_AlternativeStatus["ALTERNATIVE_STATUS_UNSPECIFIED"] = 0] = "ALTERNATIVE_STATUS_UNSPECIFIED";
    /** ALTERNATIVE_STATUS_PARTIAL - Partially generated alternative. */
    Alternative_AlternativeStatus[Alternative_AlternativeStatus["ALTERNATIVE_STATUS_PARTIAL"] = 1] = "ALTERNATIVE_STATUS_PARTIAL";
    /** ALTERNATIVE_STATUS_TRUNCATED_FINAL - Incomplete final alternative resulting from reaching the maximum allowed number of tokens. */
    Alternative_AlternativeStatus[Alternative_AlternativeStatus["ALTERNATIVE_STATUS_TRUNCATED_FINAL"] = 2] = "ALTERNATIVE_STATUS_TRUNCATED_FINAL";
    /** ALTERNATIVE_STATUS_FINAL - Final alternative generated without running into any limits. */
    Alternative_AlternativeStatus[Alternative_AlternativeStatus["ALTERNATIVE_STATUS_FINAL"] = 3] = "ALTERNATIVE_STATUS_FINAL";
    /**
     * ALTERNATIVE_STATUS_CONTENT_FILTER - Generation was stopped due to the discovery of potentially sensitive content in the prompt or generated response.
     * To fix, modify the prompt and restart generation.
     */
    Alternative_AlternativeStatus[Alternative_AlternativeStatus["ALTERNATIVE_STATUS_CONTENT_FILTER"] = 4] = "ALTERNATIVE_STATUS_CONTENT_FILTER";
    /** ALTERNATIVE_STATUS_TOOL_CALLS - Tools were invoked during the completion generation. */
    Alternative_AlternativeStatus[Alternative_AlternativeStatus["ALTERNATIVE_STATUS_TOOL_CALLS"] = 5] = "ALTERNATIVE_STATUS_TOOL_CALLS";
    Alternative_AlternativeStatus[Alternative_AlternativeStatus["UNRECOGNIZED"] = -1] = "UNRECOGNIZED";
})(Alternative_AlternativeStatus = exports.Alternative_AlternativeStatus || (exports.Alternative_AlternativeStatus = {}));
function alternative_AlternativeStatusFromJSON(object) {
    switch (object) {
        case 0:
        case 'ALTERNATIVE_STATUS_UNSPECIFIED':
            return Alternative_AlternativeStatus.ALTERNATIVE_STATUS_UNSPECIFIED;
        case 1:
        case 'ALTERNATIVE_STATUS_PARTIAL':
            return Alternative_AlternativeStatus.ALTERNATIVE_STATUS_PARTIAL;
        case 2:
        case 'ALTERNATIVE_STATUS_TRUNCATED_FINAL':
            return Alternative_AlternativeStatus.ALTERNATIVE_STATUS_TRUNCATED_FINAL;
        case 3:
        case 'ALTERNATIVE_STATUS_FINAL':
            return Alternative_AlternativeStatus.ALTERNATIVE_STATUS_FINAL;
        case 4:
        case 'ALTERNATIVE_STATUS_CONTENT_FILTER':
            return Alternative_AlternativeStatus.ALTERNATIVE_STATUS_CONTENT_FILTER;
        case 5:
        case 'ALTERNATIVE_STATUS_TOOL_CALLS':
            return Alternative_AlternativeStatus.ALTERNATIVE_STATUS_TOOL_CALLS;
        case -1:
        case 'UNRECOGNIZED':
        default:
            return Alternative_AlternativeStatus.UNRECOGNIZED;
    }
}
exports.alternative_AlternativeStatusFromJSON = alternative_AlternativeStatusFromJSON;
function alternative_AlternativeStatusToJSON(object) {
    switch (object) {
        case Alternative_AlternativeStatus.ALTERNATIVE_STATUS_UNSPECIFIED:
            return 'ALTERNATIVE_STATUS_UNSPECIFIED';
        case Alternative_AlternativeStatus.ALTERNATIVE_STATUS_PARTIAL:
            return 'ALTERNATIVE_STATUS_PARTIAL';
        case Alternative_AlternativeStatus.ALTERNATIVE_STATUS_TRUNCATED_FINAL:
            return 'ALTERNATIVE_STATUS_TRUNCATED_FINAL';
        case Alternative_AlternativeStatus.ALTERNATIVE_STATUS_FINAL:
            return 'ALTERNATIVE_STATUS_FINAL';
        case Alternative_AlternativeStatus.ALTERNATIVE_STATUS_CONTENT_FILTER:
            return 'ALTERNATIVE_STATUS_CONTENT_FILTER';
        case Alternative_AlternativeStatus.ALTERNATIVE_STATUS_TOOL_CALLS:
            return 'ALTERNATIVE_STATUS_TOOL_CALLS';
        default:
            return 'UNKNOWN';
    }
}
exports.alternative_AlternativeStatusToJSON = alternative_AlternativeStatusToJSON;
const baseCompletionOptions = { stream: false };
exports.CompletionOptions = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.stream === true) {
            writer.uint32(8).bool(message.stream);
        }
        if (message.temperature !== undefined) {
            wrappers_1.DoubleValue.encode({ value: message.temperature }, writer.uint32(18).fork()).ldelim();
        }
        if (message.maxTokens !== undefined) {
            wrappers_1.Int64Value.encode({ value: message.maxTokens }, writer.uint32(26).fork()).ldelim();
        }
        if (message.reasoningOptions !== undefined) {
            exports.ReasoningOptions.encode(message.reasoningOptions, writer.uint32(34).fork()).ldelim();
        }
        return writer;
    },
    decode(input, length) {
        const reader = input instanceof minimal_1.default.Reader ? input : new minimal_1.default.Reader(input);
        let end = length === undefined ? reader.len : reader.pos + length;
        const message = Object.assign({}, baseCompletionOptions);
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.stream = reader.bool();
                    break;
                case 2:
                    message.temperature = wrappers_1.DoubleValue.decode(reader, reader.uint32()).value;
                    break;
                case 3:
                    message.maxTokens = wrappers_1.Int64Value.decode(reader, reader.uint32()).value;
                    break;
                case 4:
                    message.reasoningOptions = exports.ReasoningOptions.decode(reader, reader.uint32());
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        const message = Object.assign({}, baseCompletionOptions);
        message.stream =
            object.stream !== undefined && object.stream !== null ? Boolean(object.stream) : false;
        message.temperature =
            object.temperature !== undefined && object.temperature !== null
                ? Number(object.temperature)
                : undefined;
        message.maxTokens =
            object.maxTokens !== undefined && object.maxTokens !== null
                ? Number(object.maxTokens)
                : undefined;
        message.reasoningOptions =
            object.reasoningOptions !== undefined && object.reasoningOptions !== null
                ? exports.ReasoningOptions.fromJSON(object.reasoningOptions)
                : undefined;
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.stream !== undefined && (obj.stream = message.stream);
        message.temperature !== undefined && (obj.temperature = message.temperature);
        message.maxTokens !== undefined && (obj.maxTokens = message.maxTokens);
        message.reasoningOptions !== undefined &&
            (obj.reasoningOptions = message.reasoningOptions
                ? exports.ReasoningOptions.toJSON(message.reasoningOptions)
                : undefined);
        return obj;
    },
    fromPartial(object) {
        var _a, _b, _c;
        const message = Object.assign({}, baseCompletionOptions);
        message.stream = (_a = object.stream) !== null && _a !== void 0 ? _a : false;
        message.temperature = (_b = object.temperature) !== null && _b !== void 0 ? _b : undefined;
        message.maxTokens = (_c = object.maxTokens) !== null && _c !== void 0 ? _c : undefined;
        message.reasoningOptions =
            object.reasoningOptions !== undefined && object.reasoningOptions !== null
                ? exports.ReasoningOptions.fromPartial(object.reasoningOptions)
                : undefined;
        return message;
    },
};
const baseReasoningOptions = { mode: 0 };
exports.ReasoningOptions = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.mode !== 0) {
            writer.uint32(8).int32(message.mode);
        }
        return writer;
    },
    decode(input, length) {
        const reader = input instanceof minimal_1.default.Reader ? input : new minimal_1.default.Reader(input);
        let end = length === undefined ? reader.len : reader.pos + length;
        const message = Object.assign({}, baseReasoningOptions);
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.mode = reader.int32();
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        const message = Object.assign({}, baseReasoningOptions);
        message.mode =
            object.mode !== undefined && object.mode !== null
                ? reasoningOptions_ReasoningModeFromJSON(object.mode)
                : 0;
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.mode !== undefined &&
            (obj.mode = reasoningOptions_ReasoningModeToJSON(message.mode));
        return obj;
    },
    fromPartial(object) {
        var _a;
        const message = Object.assign({}, baseReasoningOptions);
        message.mode = (_a = object.mode) !== null && _a !== void 0 ? _a : 0;
        return message;
    },
};
const baseMessage = { role: '' };
exports.Message = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.role !== '') {
            writer.uint32(10).string(message.role);
        }
        if (message.text !== undefined) {
            writer.uint32(18).string(message.text);
        }
        if (message.toolCallList !== undefined) {
            exports.ToolCallList.encode(message.toolCallList, writer.uint32(26).fork()).ldelim();
        }
        if (message.toolResultList !== undefined) {
            exports.ToolResultList.encode(message.toolResultList, writer.uint32(34).fork()).ldelim();
        }
        return writer;
    },
    decode(input, length) {
        const reader = input instanceof minimal_1.default.Reader ? input : new minimal_1.default.Reader(input);
        let end = length === undefined ? reader.len : reader.pos + length;
        const message = Object.assign({}, baseMessage);
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.role = reader.string();
                    break;
                case 2:
                    message.text = reader.string();
                    break;
                case 3:
                    message.toolCallList = exports.ToolCallList.decode(reader, reader.uint32());
                    break;
                case 4:
                    message.toolResultList = exports.ToolResultList.decode(reader, reader.uint32());
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        const message = Object.assign({}, baseMessage);
        message.role = object.role !== undefined && object.role !== null ? String(object.role) : '';
        message.text =
            object.text !== undefined && object.text !== null ? String(object.text) : undefined;
        message.toolCallList =
            object.toolCallList !== undefined && object.toolCallList !== null
                ? exports.ToolCallList.fromJSON(object.toolCallList)
                : undefined;
        message.toolResultList =
            object.toolResultList !== undefined && object.toolResultList !== null
                ? exports.ToolResultList.fromJSON(object.toolResultList)
                : undefined;
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.role !== undefined && (obj.role = message.role);
        message.text !== undefined && (obj.text = message.text);
        message.toolCallList !== undefined &&
            (obj.toolCallList = message.toolCallList
                ? exports.ToolCallList.toJSON(message.toolCallList)
                : undefined);
        message.toolResultList !== undefined &&
            (obj.toolResultList = message.toolResultList
                ? exports.ToolResultList.toJSON(message.toolResultList)
                : undefined);
        return obj;
    },
    fromPartial(object) {
        var _a, _b;
        const message = Object.assign({}, baseMessage);
        message.role = (_a = object.role) !== null && _a !== void 0 ? _a : '';
        message.text = (_b = object.text) !== null && _b !== void 0 ? _b : undefined;
        message.toolCallList =
            object.toolCallList !== undefined && object.toolCallList !== null
                ? exports.ToolCallList.fromPartial(object.toolCallList)
                : undefined;
        message.toolResultList =
            object.toolResultList !== undefined && object.toolResultList !== null
                ? exports.ToolResultList.fromPartial(object.toolResultList)
                : undefined;
        return message;
    },
};
const baseContentUsage = { inputTextTokens: 0, completionTokens: 0, totalTokens: 0 };
exports.ContentUsage = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.inputTextTokens !== 0) {
            writer.uint32(8).int64(message.inputTextTokens);
        }
        if (message.completionTokens !== 0) {
            writer.uint32(16).int64(message.completionTokens);
        }
        if (message.totalTokens !== 0) {
            writer.uint32(24).int64(message.totalTokens);
        }
        if (message.completionTokensDetails !== undefined) {
            exports.ContentUsage_CompletionTokensDetails.encode(message.completionTokensDetails, writer.uint32(34).fork()).ldelim();
        }
        return writer;
    },
    decode(input, length) {
        const reader = input instanceof minimal_1.default.Reader ? input : new minimal_1.default.Reader(input);
        let end = length === undefined ? reader.len : reader.pos + length;
        const message = Object.assign({}, baseContentUsage);
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.inputTextTokens = longToNumber(reader.int64());
                    break;
                case 2:
                    message.completionTokens = longToNumber(reader.int64());
                    break;
                case 3:
                    message.totalTokens = longToNumber(reader.int64());
                    break;
                case 4:
                    message.completionTokensDetails = exports.ContentUsage_CompletionTokensDetails.decode(reader, reader.uint32());
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        const message = Object.assign({}, baseContentUsage);
        message.inputTextTokens =
            object.inputTextTokens !== undefined && object.inputTextTokens !== null
                ? Number(object.inputTextTokens)
                : 0;
        message.completionTokens =
            object.completionTokens !== undefined && object.completionTokens !== null
                ? Number(object.completionTokens)
                : 0;
        message.totalTokens =
            object.totalTokens !== undefined && object.totalTokens !== null
                ? Number(object.totalTokens)
                : 0;
        message.completionTokensDetails =
            object.completionTokensDetails !== undefined && object.completionTokensDetails !== null
                ? exports.ContentUsage_CompletionTokensDetails.fromJSON(object.completionTokensDetails)
                : undefined;
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.inputTextTokens !== undefined &&
            (obj.inputTextTokens = Math.round(message.inputTextTokens));
        message.completionTokens !== undefined &&
            (obj.completionTokens = Math.round(message.completionTokens));
        message.totalTokens !== undefined && (obj.totalTokens = Math.round(message.totalTokens));
        message.completionTokensDetails !== undefined &&
            (obj.completionTokensDetails = message.completionTokensDetails
                ? exports.ContentUsage_CompletionTokensDetails.toJSON(message.completionTokensDetails)
                : undefined);
        return obj;
    },
    fromPartial(object) {
        var _a, _b, _c;
        const message = Object.assign({}, baseContentUsage);
        message.inputTextTokens = (_a = object.inputTextTokens) !== null && _a !== void 0 ? _a : 0;
        message.completionTokens = (_b = object.completionTokens) !== null && _b !== void 0 ? _b : 0;
        message.totalTokens = (_c = object.totalTokens) !== null && _c !== void 0 ? _c : 0;
        message.completionTokensDetails =
            object.completionTokensDetails !== undefined && object.completionTokensDetails !== null
                ? exports.ContentUsage_CompletionTokensDetails.fromPartial(object.completionTokensDetails)
                : undefined;
        return message;
    },
};
const baseContentUsage_CompletionTokensDetails = { reasoningTokens: 0 };
exports.ContentUsage_CompletionTokensDetails = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.reasoningTokens !== 0) {
            writer.uint32(8).int64(message.reasoningTokens);
        }
        return writer;
    },
    decode(input, length) {
        const reader = input instanceof minimal_1.default.Reader ? input : new minimal_1.default.Reader(input);
        let end = length === undefined ? reader.len : reader.pos + length;
        const message = Object.assign({}, baseContentUsage_CompletionTokensDetails);
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.reasoningTokens = longToNumber(reader.int64());
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        const message = Object.assign({}, baseContentUsage_CompletionTokensDetails);
        message.reasoningTokens =
            object.reasoningTokens !== undefined && object.reasoningTokens !== null
                ? Number(object.reasoningTokens)
                : 0;
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.reasoningTokens !== undefined &&
            (obj.reasoningTokens = Math.round(message.reasoningTokens));
        return obj;
    },
    fromPartial(object) {
        var _a;
        const message = Object.assign({}, baseContentUsage_CompletionTokensDetails);
        message.reasoningTokens = (_a = object.reasoningTokens) !== null && _a !== void 0 ? _a : 0;
        return message;
    },
};
const baseAlternative = { status: 0 };
exports.Alternative = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.message !== undefined) {
            exports.Message.encode(message.message, writer.uint32(10).fork()).ldelim();
        }
        if (message.status !== 0) {
            writer.uint32(16).int32(message.status);
        }
        return writer;
    },
    decode(input, length) {
        const reader = input instanceof minimal_1.default.Reader ? input : new minimal_1.default.Reader(input);
        let end = length === undefined ? reader.len : reader.pos + length;
        const message = Object.assign({}, baseAlternative);
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.message = exports.Message.decode(reader, reader.uint32());
                    break;
                case 2:
                    message.status = reader.int32();
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        const message = Object.assign({}, baseAlternative);
        message.message =
            object.message !== undefined && object.message !== null
                ? exports.Message.fromJSON(object.message)
                : undefined;
        message.status =
            object.status !== undefined && object.status !== null
                ? alternative_AlternativeStatusFromJSON(object.status)
                : 0;
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.message !== undefined &&
            (obj.message = message.message ? exports.Message.toJSON(message.message) : undefined);
        message.status !== undefined &&
            (obj.status = alternative_AlternativeStatusToJSON(message.status));
        return obj;
    },
    fromPartial(object) {
        var _a;
        const message = Object.assign({}, baseAlternative);
        message.message =
            object.message !== undefined && object.message !== null
                ? exports.Message.fromPartial(object.message)
                : undefined;
        message.status = (_a = object.status) !== null && _a !== void 0 ? _a : 0;
        return message;
    },
};
const baseToken = { id: 0, text: '', special: false };
exports.Token = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.id !== 0) {
            writer.uint32(8).int64(message.id);
        }
        if (message.text !== '') {
            writer.uint32(18).string(message.text);
        }
        if (message.special === true) {
            writer.uint32(24).bool(message.special);
        }
        return writer;
    },
    decode(input, length) {
        const reader = input instanceof minimal_1.default.Reader ? input : new minimal_1.default.Reader(input);
        let end = length === undefined ? reader.len : reader.pos + length;
        const message = Object.assign({}, baseToken);
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.id = longToNumber(reader.int64());
                    break;
                case 2:
                    message.text = reader.string();
                    break;
                case 3:
                    message.special = reader.bool();
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        const message = Object.assign({}, baseToken);
        message.id = object.id !== undefined && object.id !== null ? Number(object.id) : 0;
        message.text = object.text !== undefined && object.text !== null ? String(object.text) : '';
        message.special =
            object.special !== undefined && object.special !== null
                ? Boolean(object.special)
                : false;
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.id !== undefined && (obj.id = Math.round(message.id));
        message.text !== undefined && (obj.text = message.text);
        message.special !== undefined && (obj.special = message.special);
        return obj;
    },
    fromPartial(object) {
        var _a, _b, _c;
        const message = Object.assign({}, baseToken);
        message.id = (_a = object.id) !== null && _a !== void 0 ? _a : 0;
        message.text = (_b = object.text) !== null && _b !== void 0 ? _b : '';
        message.special = (_c = object.special) !== null && _c !== void 0 ? _c : false;
        return message;
    },
};
const baseTool = {};
exports.Tool = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.function !== undefined) {
            exports.FunctionTool.encode(message.function, writer.uint32(10).fork()).ldelim();
        }
        return writer;
    },
    decode(input, length) {
        const reader = input instanceof minimal_1.default.Reader ? input : new minimal_1.default.Reader(input);
        let end = length === undefined ? reader.len : reader.pos + length;
        const message = Object.assign({}, baseTool);
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.function = exports.FunctionTool.decode(reader, reader.uint32());
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        const message = Object.assign({}, baseTool);
        message.function =
            object.function !== undefined && object.function !== null
                ? exports.FunctionTool.fromJSON(object.function)
                : undefined;
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.function !== undefined &&
            (obj.function = message.function ? exports.FunctionTool.toJSON(message.function) : undefined);
        return obj;
    },
    fromPartial(object) {
        const message = Object.assign({}, baseTool);
        message.function =
            object.function !== undefined && object.function !== null
                ? exports.FunctionTool.fromPartial(object.function)
                : undefined;
        return message;
    },
};
const baseFunctionTool = { name: '', description: '' };
exports.FunctionTool = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.name !== '') {
            writer.uint32(10).string(message.name);
        }
        if (message.description !== '') {
            writer.uint32(18).string(message.description);
        }
        if (message.parameters !== undefined) {
            struct_1.Struct.encode(struct_1.Struct.wrap(message.parameters), writer.uint32(26).fork()).ldelim();
        }
        return writer;
    },
    decode(input, length) {
        const reader = input instanceof minimal_1.default.Reader ? input : new minimal_1.default.Reader(input);
        let end = length === undefined ? reader.len : reader.pos + length;
        const message = Object.assign({}, baseFunctionTool);
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.name = reader.string();
                    break;
                case 2:
                    message.description = reader.string();
                    break;
                case 3:
                    message.parameters = struct_1.Struct.unwrap(struct_1.Struct.decode(reader, reader.uint32()));
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        const message = Object.assign({}, baseFunctionTool);
        message.name = object.name !== undefined && object.name !== null ? String(object.name) : '';
        message.description =
            object.description !== undefined && object.description !== null
                ? String(object.description)
                : '';
        message.parameters = typeof object.parameters === 'object' ? object.parameters : undefined;
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.name !== undefined && (obj.name = message.name);
        message.description !== undefined && (obj.description = message.description);
        message.parameters !== undefined && (obj.parameters = message.parameters);
        return obj;
    },
    fromPartial(object) {
        var _a, _b, _c;
        const message = Object.assign({}, baseFunctionTool);
        message.name = (_a = object.name) !== null && _a !== void 0 ? _a : '';
        message.description = (_b = object.description) !== null && _b !== void 0 ? _b : '';
        message.parameters = (_c = object.parameters) !== null && _c !== void 0 ? _c : undefined;
        return message;
    },
};
const baseToolCall = {};
exports.ToolCall = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.functionCall !== undefined) {
            exports.FunctionCall.encode(message.functionCall, writer.uint32(10).fork()).ldelim();
        }
        return writer;
    },
    decode(input, length) {
        const reader = input instanceof minimal_1.default.Reader ? input : new minimal_1.default.Reader(input);
        let end = length === undefined ? reader.len : reader.pos + length;
        const message = Object.assign({}, baseToolCall);
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.functionCall = exports.FunctionCall.decode(reader, reader.uint32());
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        const message = Object.assign({}, baseToolCall);
        message.functionCall =
            object.functionCall !== undefined && object.functionCall !== null
                ? exports.FunctionCall.fromJSON(object.functionCall)
                : undefined;
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.functionCall !== undefined &&
            (obj.functionCall = message.functionCall
                ? exports.FunctionCall.toJSON(message.functionCall)
                : undefined);
        return obj;
    },
    fromPartial(object) {
        const message = Object.assign({}, baseToolCall);
        message.functionCall =
            object.functionCall !== undefined && object.functionCall !== null
                ? exports.FunctionCall.fromPartial(object.functionCall)
                : undefined;
        return message;
    },
};
const baseFunctionCall = { name: '' };
exports.FunctionCall = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.name !== '') {
            writer.uint32(10).string(message.name);
        }
        if (message.arguments !== undefined) {
            struct_1.Struct.encode(struct_1.Struct.wrap(message.arguments), writer.uint32(18).fork()).ldelim();
        }
        return writer;
    },
    decode(input, length) {
        const reader = input instanceof minimal_1.default.Reader ? input : new minimal_1.default.Reader(input);
        let end = length === undefined ? reader.len : reader.pos + length;
        const message = Object.assign({}, baseFunctionCall);
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.name = reader.string();
                    break;
                case 2:
                    message.arguments = struct_1.Struct.unwrap(struct_1.Struct.decode(reader, reader.uint32()));
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        const message = Object.assign({}, baseFunctionCall);
        message.name = object.name !== undefined && object.name !== null ? String(object.name) : '';
        message.arguments = typeof object.arguments === 'object' ? object.arguments : undefined;
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.name !== undefined && (obj.name = message.name);
        message.arguments !== undefined && (obj.arguments = message.arguments);
        return obj;
    },
    fromPartial(object) {
        var _a, _b;
        const message = Object.assign({}, baseFunctionCall);
        message.name = (_a = object.name) !== null && _a !== void 0 ? _a : '';
        message.arguments = (_b = object.arguments) !== null && _b !== void 0 ? _b : undefined;
        return message;
    },
};
const baseToolCallList = {};
exports.ToolCallList = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        for (const v of message.toolCalls) {
            exports.ToolCall.encode(v, writer.uint32(10).fork()).ldelim();
        }
        return writer;
    },
    decode(input, length) {
        const reader = input instanceof minimal_1.default.Reader ? input : new minimal_1.default.Reader(input);
        let end = length === undefined ? reader.len : reader.pos + length;
        const message = Object.assign({}, baseToolCallList);
        message.toolCalls = [];
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.toolCalls.push(exports.ToolCall.decode(reader, reader.uint32()));
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        var _a;
        const message = Object.assign({}, baseToolCallList);
        message.toolCalls = ((_a = object.toolCalls) !== null && _a !== void 0 ? _a : []).map((e) => exports.ToolCall.fromJSON(e));
        return message;
    },
    toJSON(message) {
        const obj = {};
        if (message.toolCalls) {
            obj.toolCalls = message.toolCalls.map((e) => (e ? exports.ToolCall.toJSON(e) : undefined));
        }
        else {
            obj.toolCalls = [];
        }
        return obj;
    },
    fromPartial(object) {
        var _a;
        const message = Object.assign({}, baseToolCallList);
        message.toolCalls = ((_a = object.toolCalls) === null || _a === void 0 ? void 0 : _a.map((e) => exports.ToolCall.fromPartial(e))) || [];
        return message;
    },
};
const baseToolResult = {};
exports.ToolResult = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.functionResult !== undefined) {
            exports.FunctionResult.encode(message.functionResult, writer.uint32(10).fork()).ldelim();
        }
        return writer;
    },
    decode(input, length) {
        const reader = input instanceof minimal_1.default.Reader ? input : new minimal_1.default.Reader(input);
        let end = length === undefined ? reader.len : reader.pos + length;
        const message = Object.assign({}, baseToolResult);
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.functionResult = exports.FunctionResult.decode(reader, reader.uint32());
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        const message = Object.assign({}, baseToolResult);
        message.functionResult =
            object.functionResult !== undefined && object.functionResult !== null
                ? exports.FunctionResult.fromJSON(object.functionResult)
                : undefined;
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.functionResult !== undefined &&
            (obj.functionResult = message.functionResult
                ? exports.FunctionResult.toJSON(message.functionResult)
                : undefined);
        return obj;
    },
    fromPartial(object) {
        const message = Object.assign({}, baseToolResult);
        message.functionResult =
            object.functionResult !== undefined && object.functionResult !== null
                ? exports.FunctionResult.fromPartial(object.functionResult)
                : undefined;
        return message;
    },
};
const baseFunctionResult = { name: '' };
exports.FunctionResult = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.name !== '') {
            writer.uint32(10).string(message.name);
        }
        if (message.content !== undefined) {
            writer.uint32(18).string(message.content);
        }
        return writer;
    },
    decode(input, length) {
        const reader = input instanceof minimal_1.default.Reader ? input : new minimal_1.default.Reader(input);
        let end = length === undefined ? reader.len : reader.pos + length;
        const message = Object.assign({}, baseFunctionResult);
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.name = reader.string();
                    break;
                case 2:
                    message.content = reader.string();
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        const message = Object.assign({}, baseFunctionResult);
        message.name = object.name !== undefined && object.name !== null ? String(object.name) : '';
        message.content =
            object.content !== undefined && object.content !== null
                ? String(object.content)
                : undefined;
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.name !== undefined && (obj.name = message.name);
        message.content !== undefined && (obj.content = message.content);
        return obj;
    },
    fromPartial(object) {
        var _a, _b;
        const message = Object.assign({}, baseFunctionResult);
        message.name = (_a = object.name) !== null && _a !== void 0 ? _a : '';
        message.content = (_b = object.content) !== null && _b !== void 0 ? _b : undefined;
        return message;
    },
};
const baseToolResultList = {};
exports.ToolResultList = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        for (const v of message.toolResults) {
            exports.ToolResult.encode(v, writer.uint32(10).fork()).ldelim();
        }
        return writer;
    },
    decode(input, length) {
        const reader = input instanceof minimal_1.default.Reader ? input : new minimal_1.default.Reader(input);
        let end = length === undefined ? reader.len : reader.pos + length;
        const message = Object.assign({}, baseToolResultList);
        message.toolResults = [];
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.toolResults.push(exports.ToolResult.decode(reader, reader.uint32()));
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        var _a;
        const message = Object.assign({}, baseToolResultList);
        message.toolResults = ((_a = object.toolResults) !== null && _a !== void 0 ? _a : []).map((e) => exports.ToolResult.fromJSON(e));
        return message;
    },
    toJSON(message) {
        const obj = {};
        if (message.toolResults) {
            obj.toolResults = message.toolResults.map((e) => e ? exports.ToolResult.toJSON(e) : undefined);
        }
        else {
            obj.toolResults = [];
        }
        return obj;
    },
    fromPartial(object) {
        var _a;
        const message = Object.assign({}, baseToolResultList);
        message.toolResults = ((_a = object.toolResults) === null || _a === void 0 ? void 0 : _a.map((e) => exports.ToolResult.fromPartial(e))) || [];
        return message;
    },
};
const baseJsonSchema = {};
exports.JsonSchema = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.schema !== undefined) {
            struct_1.Struct.encode(struct_1.Struct.wrap(message.schema), writer.uint32(10).fork()).ldelim();
        }
        return writer;
    },
    decode(input, length) {
        const reader = input instanceof minimal_1.default.Reader ? input : new minimal_1.default.Reader(input);
        let end = length === undefined ? reader.len : reader.pos + length;
        const message = Object.assign({}, baseJsonSchema);
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.schema = struct_1.Struct.unwrap(struct_1.Struct.decode(reader, reader.uint32()));
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        const message = Object.assign({}, baseJsonSchema);
        message.schema = typeof object.schema === 'object' ? object.schema : undefined;
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.schema !== undefined && (obj.schema = message.schema);
        return obj;
    },
    fromPartial(object) {
        var _a;
        const message = Object.assign({}, baseJsonSchema);
        message.schema = (_a = object.schema) !== null && _a !== void 0 ? _a : undefined;
        return message;
    },
};
var globalThis = (() => {
    if (typeof globalThis !== 'undefined')
        return globalThis;
    if (typeof self !== 'undefined')
        return self;
    if (typeof window !== 'undefined')
        return window;
    if (typeof global !== 'undefined')
        return global;
    throw 'Unable to locate global object';
})();
function longToNumber(long) {
    if (long.gt(Number.MAX_SAFE_INTEGER)) {
        throw new globalThis.Error('Value is larger than Number.MAX_SAFE_INTEGER');
    }
    return long.toNumber();
}
if (minimal_1.default.util.Long !== long_1.default) {
    minimal_1.default.util.Long = long_1.default;
    minimal_1.default.configure();
}
