Files
jibo-cli/node_modules/jibo-kb/lib/dts/KnowledgeBase.d.ts

238 lines
9.7 KiB
TypeScript
Raw Normal View History

import Model from './Model';
import KnowledgeDatabase from './KnowledgeDatabase';
import Node from './Node';
import Asset from './Asset';
import DatabaseManager from './DatabaseManager';
import LoopModel from './LoopModel';
import UserNode from './UserNode';
export declare type ErrCallback = (err: Error) => void;
export declare type CreateCallback = (err: Error, created?: boolean) => void;
export declare type ExistsCallback = (err: Error, exists?: boolean) => void;
export declare type NodeConstructor = new (...args: any[]) => Node;
export declare type ModelConstructor = new (kbNames: string | string[], httpUrl: string) => Model;
export declare type ServiceObject = {
host: string;
port: string | number;
};
/**
* @description KnowledgeBase Class.
*
* @deprecated since version 3.0.0
* @class KnowledgeBase
* @memberof jibo.kb
*/
/** The Knowledge Base API.
*
* Can be accessed via `jibo.kb` (or `import {kb} from 'jibo'`).
*
* @namespace jibo.kb
*
* @example
* let model = jibo.kb.createModel('/skillname');
*
*/
declare class KnowledgeBase {
httpUrl: string;
Asset: typeof Asset;
KnowledgeDatabase: typeof KnowledgeDatabase;
Model: typeof Model;
Node: typeof Node;
UserNode: typeof UserNode;
databaseManager: DatabaseManager;
config: any;
onInitCallbacks: ErrCallback[];
/**
* Loop model information.
* @name jibo.kb#loop
* @type {jibo.kb.loop.LoopModel}
*/
loop: LoopModel;
/**
* Media list model information.
* @name jibo.kb#media
* @type {jibo.kb.media.MediaModel}
*/
media: any;
constructor();
/** Initialize the kb API singleton object.
*
* @method jibo.kb#init
* @param {Object} service Service object with host and port of the KB service.
* @param {Function} callback Called when done.
* @internal
*/
init(service: ServiceObject, callback?: ErrCallback): void;
/** Provides a callback when the KB is initialized. This allows utilities to load KB in
* their own initialization without knowledge of what the skill is doing.
*
* @method jibo.kb#onInit
* @param {Function} callback Called when done. If callback is omitted a promise that resolves
* once the KB has been initialized is returned.
* @returns {Promise} A promise that resolves once the KB has been initialized is returned if
* the callback is omitted.
* @internal
*/
onInit(callback: ErrCallback): any;
onInit(): Promise<void>;
/** Optionally attach a loop model as `kb.loop`.
* Call this only after init() has been called.
*
* @method jibo.kb#initLoop
* @internal
*/
initLoop(): void;
/** Optionally attach a media model as `kb.media`.
* Call this only after init() has been called.
*
* @method jibo.kb#initMedia
* @internal
*/
initMedia(): void;
/** Create a KB slice. KB slices must be created before they are
* used the first time. This method creates the KB slice, or does
* nothing if it has already been created. The callback is
* supplied with a boolen indicating if the slice needed to be
* created. If callback is omitted a promise is returned instead.
*
* @method jibo.kb#createSlice
* @param {string} sliceName Name of KB slice to create.
* KB name must start with a `/`, followed by the skill name.
* @param {string} [httpUrl] Base URL of KB service. Defaults to
* URL generated from the service object given to `init()`.
* @param {Function} [callback] Called with `(err, created)`
* arguments. `created` is `false` if the KB slice already
* existed. If callback is omitted a promise that returns
* `created` is returned instead.
* @returns {Promise} A promise that resolves with the value of
* `created` if the callback is omitted.
*/
createSlice(sliceName: string, callback: CreateCallback): any;
createSlice(sliceName: string, httpUrl: string, callback: CreateCallback): any;
createSlice(sliceName: string, httpUrl?: string): Promise<boolean>;
/** Check if a KB slice exists. The callback is supplied with a
* boolen indicating if the slice exists. If callback is omitted a
* promise is returned instead.
*
* @method jibo.kb#existsSlice
* @param {string} sliceName Name of KB slice to check.
* KB name must start with a `/`, followed by the skill name.
* @param {string} [httpUrl] Base URL of KB service. Defaults to
* URL generated from the service object given to `init()`.
* @param {Function} [callback] Called with `(err, exists)`
* arguments. `exists` is `true` if the KB slice exists. If
* callback is omitted a promise that returns `exists` is returned
* instead.
* @returns {Promise} A promise that resolves with the value of
* `exists` if the callback is omitted.
*/
existsSlice(sliceName: string, callback: ExistsCallback): void;
existsSlice(sliceName: string, httpUrl: string, callback: ExistsCallback): void;
existsSlice(sliceName: string, httpUrl?: string): Promise<boolean>;
/** Create a new Model object. Models are the primary interface
* to the knowledge base.
*
* @method jibo.kb#createModel
* @param {string|string[]} kbNames Array of knowledge base slice
* names to include in model, in order of precedence. A single
* KB name can be given as a string instead of an array of strings.
* KB names must start with a `/`, followed by the skill name.
* @param {string} [httpUrl] Base URL of KB.
* service. Defaults to URL generated from the service object
* given to `init()`.
* @param {string} [httpUrl] Base URL of KB service. Defaults to
* URL generated from the service object given to `init()`.
* @returns {jibo.kb.Model} New Model object.
*/
createModel(kbNames: string | string[], httpUrl?: string): Model;
/** Register a Node subclass to be instantiated when a node of a
* given type is loaded or created.
*
* @method jibo.kb#registerNodeClass
* @param {string|string[]} nodeType Node type to use this
* subclass for.
* @param {Function} classConstruction The constructor function
* for the subclass.
* @param {string} [kbName] Name of KB to limit the use
* of this subclass to. Defaults to all KBs.
*/
registerNodeClass(nodeType: string, classConstructor: NodeConstructor, kbName?: string): void;
/** Register a Model subclass to be instantiated for a given KB name
* list.
*
* @method jibo.kb#registerModelClass
* @param {string|string[]} kbNames KB name or name list use this
* subclass for.
* @param {Function} classConstructor The constructor function for
* the subclass.
*/
registerModelClass(kbNames: string | string[], classConstructor: ModelConstructor): void;
/** Use the node type to find a Node subclass in the Node Class
* registry. Default to the plain `Node` object if nothing
* matches.
*
* @method jibo.kb#findNodeClass
* @param {string} nodeType Type of node.
* @param {string} kbName Name of KB slice.
* @returns {Function} Node class constructor.
*/
findNodeClass(nodeType: string, kbName: string): NodeConstructor;
/** Use the given KB slice names to find a Model subclass in the
* Model subclass registry. Defaults to the plain `Model` object
* if nothing matches.
*
* @method jibo.kb#findModelClass
* @param {string|string[]} kbNames Array of knowledge base slice
* names.
* @returns {Function} Model class constructor.
*/
findModelClass(kbNames: string | string[]): ModelConstructor;
/** Unload a given kb slice from the Skills Service Manager memory
* and remove it from disk. Also removes any sub-kbs inside this
* slice. For example, if you remove `/jibo`, that would also
* remove `/jibo/loop`, `/jibo/settings` and all other kb slices
* under `/jibo`. If callback is omitted a promise is returned
* instead.
*
* @method jibo.kb#removeSlice
* @param {string} sliceName Name of kb slice to be removed,
* including all of its sub-slices (if any).
* @param {Function} [callback] Called when done, with `err`
* parameter if there was an error. If callback is omitted a
* promise is returned instead.
* @returns {Promise} A promise if the callback is omitted.
*/
removeSlice(sliceName: string, callback: ErrCallback): any;
removeSlice(sliceName: string): Promise<any>;
/** Unload all kb slices from the Skills Service Manager memory,
* stop the Loop Manager, and delete the ENTIRE KNOWLEDGEBASE!
*
* @method jibo.kb#removeAll
* @param {Function} [callback] Called when done, with `err`
* parameter if there was an error. If callback is omitted a
* promise is returned instead.
* @returns {Promise} A promise if the callback is omitted.
* @internal
*/
removeAll(callback: ErrCallback): any;
removeAll(): Promise<any>;
/** Check http request result for null error object and 2xx result code and
* generate an error object if not (or pass through non null error object).
*
* @method jibo.kb.WebClient#_checkStatusCode
* @param {Error} err Error object returned from request.
* @param {Object} res Http request result object.
* @param {string} [message] Message to add to error object.
* @returns {Error} Error object or null.
* @private
*/
private _checkStatusCode(err, res, message?);
/** Convert a single item to an array for arguments that may be a
* single thing or an array of things.
*
* @method jibo.kb#_toArray
* @private
*/
private _toArray<T>(items);
}
export default KnowledgeBase;