@casual-simulation/aux-common 3.2.1 → 3.2.2-alpha.5675659631
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.
- package/bots/BotEvents.d.ts +68 -2
- package/bots/BotEvents.js +15 -0
- package/bots/BotEvents.js.map +1 -1
- package/package.json +3 -3
- package/runtime/AuxLibrary.d.ts +9 -2
- package/runtime/AuxLibrary.js +41 -2
- package/runtime/AuxLibrary.js.map +1 -1
- package/runtime/AuxLibraryDefinitions.def +264 -0
- package/runtime/CasualOSError.d.ts +37 -0
- package/runtime/CasualOSError.js +25 -0
- package/runtime/CasualOSError.js.map +1 -0
|
@@ -8569,6 +8569,11 @@ declare global {
|
|
|
8569
8569
|
*/
|
|
8570
8570
|
const os: Os;
|
|
8571
8571
|
|
|
8572
|
+
/**
|
|
8573
|
+
* Defines a set of functions that relate to AI operations.
|
|
8574
|
+
*/
|
|
8575
|
+
const ai: Ai;
|
|
8576
|
+
|
|
8572
8577
|
/**
|
|
8573
8578
|
* Defines a set of functions that relate to common server operations.
|
|
8574
8579
|
* Typically, these operations are instance-independent.
|
|
@@ -9399,6 +9404,11 @@ interface DebuggerBase {
|
|
|
9399
9404
|
*/
|
|
9400
9405
|
os: Os;
|
|
9401
9406
|
|
|
9407
|
+
/**
|
|
9408
|
+
* Defines a set of functions that relate to AI operations.
|
|
9409
|
+
*/
|
|
9410
|
+
ai: Ai;
|
|
9411
|
+
|
|
9402
9412
|
/**
|
|
9403
9413
|
* Defines a set of functions that relate to common server operations.
|
|
9404
9414
|
* Typically, these operations are instance-independent.
|
|
@@ -9760,6 +9770,260 @@ export interface StopFormAnimationOptions {
|
|
|
9760
9770
|
duration: number;
|
|
9761
9771
|
}
|
|
9762
9772
|
|
|
9773
|
+
/**
|
|
9774
|
+
* Defines an interface that represents a single chat message in a conversation with an AI.
|
|
9775
|
+
*
|
|
9776
|
+
* @dochash types/ai
|
|
9777
|
+
* @docname AIChatMessage
|
|
9778
|
+
*/
|
|
9779
|
+
export interface AIChatMessage {
|
|
9780
|
+
/**
|
|
9781
|
+
* The role of the message.
|
|
9782
|
+
*
|
|
9783
|
+
* - `system` means that the message was generated by the system. Useful for telling the AI how to behave while.
|
|
9784
|
+
* - `user` means that the message was generated by the user.
|
|
9785
|
+
* - `assistant` means that the message was generated by the AI assistant.
|
|
9786
|
+
* - `function` means that the message contains the results of a function call.
|
|
9787
|
+
*/
|
|
9788
|
+
role: 'system' | 'user' | 'assistant' | 'function';
|
|
9789
|
+
|
|
9790
|
+
/**
|
|
9791
|
+
* The contents of the message.
|
|
9792
|
+
*/
|
|
9793
|
+
content: string;
|
|
9794
|
+
|
|
9795
|
+
/**
|
|
9796
|
+
* The name of the author of the message.
|
|
9797
|
+
*
|
|
9798
|
+
* This is required if the role is `function`.
|
|
9799
|
+
*/
|
|
9800
|
+
author?: string;
|
|
9801
|
+
|
|
9802
|
+
/**
|
|
9803
|
+
* The reason why the message was finished.
|
|
9804
|
+
*/
|
|
9805
|
+
finishReason?: string;
|
|
9806
|
+
}
|
|
9807
|
+
|
|
9808
|
+
|
|
9809
|
+
/**
|
|
9810
|
+
* Defines an interface that represents options for {@link ai.chat}.
|
|
9811
|
+
*
|
|
9812
|
+
* @dochash types/ai
|
|
9813
|
+
* @docname AIChatOptions
|
|
9814
|
+
*/
|
|
9815
|
+
export interface AIChatOptions extends RecordActionOptions {
|
|
9816
|
+
/**
|
|
9817
|
+
* The model that should be used.
|
|
9818
|
+
*
|
|
9819
|
+
* If not specified, then a default will be used.
|
|
9820
|
+
*
|
|
9821
|
+
* Currently, the following models are supported:
|
|
9822
|
+
*
|
|
9823
|
+
* - `gpt-4`
|
|
9824
|
+
* - `gpt-3.5-turbo`
|
|
9825
|
+
*/
|
|
9826
|
+
preferredModel?: 'gpt-4' | 'gpt-3.5-turbo';
|
|
9827
|
+
|
|
9828
|
+
/**
|
|
9829
|
+
* The temperature that should be used.
|
|
9830
|
+
*
|
|
9831
|
+
* If not specified, then a default will be used.
|
|
9832
|
+
*/
|
|
9833
|
+
temperature?: number;
|
|
9834
|
+
|
|
9835
|
+
/**
|
|
9836
|
+
* The nucleus sampling probability.
|
|
9837
|
+
*/
|
|
9838
|
+
topP?: number;
|
|
9839
|
+
|
|
9840
|
+
/**
|
|
9841
|
+
* The presence penalty.
|
|
9842
|
+
*
|
|
9843
|
+
* Positive values penalize new tokens based on whether they appear in the text so far, increasing the model's likelihood to talk about new topics.
|
|
9844
|
+
*/
|
|
9845
|
+
presencePenalty?: number;
|
|
9846
|
+
|
|
9847
|
+
/**
|
|
9848
|
+
* The frequency penalty.
|
|
9849
|
+
*
|
|
9850
|
+
* Positive values penalize new tokens based on their existing frequency in the text so far, decreasing the model's likelihood to repeat the same line verbatim.
|
|
9851
|
+
*/
|
|
9852
|
+
frequencyPenalty?: number;
|
|
9853
|
+
|
|
9854
|
+
/**
|
|
9855
|
+
* The list of stop words that should be used.
|
|
9856
|
+
*
|
|
9857
|
+
* If the AI generates a sequence of tokens that match one of the given words, then it will stop generating tokens.
|
|
9858
|
+
*/
|
|
9859
|
+
stopWords?: string[];
|
|
9860
|
+
}
|
|
9861
|
+
|
|
9862
|
+
interface Ai {
|
|
9863
|
+
/**
|
|
9864
|
+
* Sends a chat message to the AI.
|
|
9865
|
+
* Returns a promise that contains the response from the AI.
|
|
9866
|
+
* Throws a {@link CasualOSError} if an error occurs while sending the message.
|
|
9867
|
+
*
|
|
9868
|
+
* This function can be useful for creating chat bots, or for using an Artificial Intelligence (AI) to process a message.
|
|
9869
|
+
*
|
|
9870
|
+
* @param message The message that should be sent to the AI.
|
|
9871
|
+
* @param options The options that should be used.
|
|
9872
|
+
*
|
|
9873
|
+
* @example Send a message to the AI and log the response.
|
|
9874
|
+
* const response = await ai.chat("Hello!");
|
|
9875
|
+
* console.log(response);
|
|
9876
|
+
*
|
|
9877
|
+
* @dochash actions/ai
|
|
9878
|
+
* @doctitle AI Actions
|
|
9879
|
+
* @docsidebar AI
|
|
9880
|
+
* @docdescription AI actions are functions that make it easier to work with the AI.
|
|
9881
|
+
* @docname ai.chat
|
|
9882
|
+
* @docid ai.chat-string
|
|
9883
|
+
*/
|
|
9884
|
+
chat(message: string, options?: AIChatOptions): Promise<string>;
|
|
9885
|
+
|
|
9886
|
+
/**
|
|
9887
|
+
* Sends a chat message to the AI.
|
|
9888
|
+
* Returns a promise that contains the response from the AI.
|
|
9889
|
+
* Throws a {@link CasualOSError} if an error occurs while sending the message.
|
|
9890
|
+
*
|
|
9891
|
+
* This function can be useful for creating chat bots, or for using an Artificial Intelligence (AI) to process a message.
|
|
9892
|
+
*
|
|
9893
|
+
* @param message The message that should be sent to the AI.
|
|
9894
|
+
* @param options The options that should be used.
|
|
9895
|
+
*
|
|
9896
|
+
* @example Send a message to the AI and log the response.
|
|
9897
|
+
* const response = await ai.chat({
|
|
9898
|
+
* role: "user",
|
|
9899
|
+
* content: "Hello!"
|
|
9900
|
+
* });
|
|
9901
|
+
* console.log(`${response.role}: ${response.content}`);
|
|
9902
|
+
*
|
|
9903
|
+
* @dochash actions/ai
|
|
9904
|
+
* @docname ai.chat
|
|
9905
|
+
* @docid ai.chat-message
|
|
9906
|
+
*/
|
|
9907
|
+
chat(
|
|
9908
|
+
message: AIChatMessage,
|
|
9909
|
+
options?: AIChatOptions
|
|
9910
|
+
): Promise<AIChatMessage>;
|
|
9911
|
+
|
|
9912
|
+
/**
|
|
9913
|
+
* Sends a chat message to the AI.
|
|
9914
|
+
* Returns a promise that contains the response from the AI.
|
|
9915
|
+
* Throws a {@link CasualOSError} if an error occurs while sending the message.
|
|
9916
|
+
*
|
|
9917
|
+
* This function can be useful for creating chat bots, or for using an Artificial Intelligence (AI) to process a message.
|
|
9918
|
+
*
|
|
9919
|
+
* @param message The message that should be sent to the AI.
|
|
9920
|
+
* @param options The options that should be used.
|
|
9921
|
+
*
|
|
9922
|
+
* @example Send a message to the AI and log the response.
|
|
9923
|
+
* const response = await ai.chat([
|
|
9924
|
+
* {
|
|
9925
|
+
* role: "system",
|
|
9926
|
+
* content: "You are a helpful assistant."
|
|
9927
|
+
* },
|
|
9928
|
+
* {
|
|
9929
|
+
* role: "user",
|
|
9930
|
+
* content: "Hello!"
|
|
9931
|
+
* }
|
|
9932
|
+
* ]);
|
|
9933
|
+
* console.log(`${response.role}: ${response.content}`);
|
|
9934
|
+
*
|
|
9935
|
+
* @example Build a basic chat bot.
|
|
9936
|
+
* const messages = [
|
|
9937
|
+
* {
|
|
9938
|
+
* role: "system",
|
|
9939
|
+
* content: "You are a helpful assistant."
|
|
9940
|
+
* },
|
|
9941
|
+
* ];
|
|
9942
|
+
*
|
|
9943
|
+
* while(true) {
|
|
9944
|
+
* const userInput = await os.showInput();
|
|
9945
|
+
* if (!userInput) {
|
|
9946
|
+
* break;
|
|
9947
|
+
* }
|
|
9948
|
+
* messages.push({
|
|
9949
|
+
* role: "user",
|
|
9950
|
+
* content: userInput
|
|
9951
|
+
* });
|
|
9952
|
+
*
|
|
9953
|
+
* const response = await ai.chat(messages);
|
|
9954
|
+
* messages.push(response);
|
|
9955
|
+
* os.toast(response.content);
|
|
9956
|
+
* }
|
|
9957
|
+
*
|
|
9958
|
+
* os.toast("Goodbye!");
|
|
9959
|
+
*
|
|
9960
|
+
* @dochash actions/ai
|
|
9961
|
+
* @docname ai.chat
|
|
9962
|
+
* @docid ai.chat-messages
|
|
9963
|
+
*/
|
|
9964
|
+
chat(
|
|
9965
|
+
messages: AIChatMessage[],
|
|
9966
|
+
options?: AIChatOptions
|
|
9967
|
+
): Promise<AIChatMessage>;
|
|
9968
|
+
|
|
9969
|
+
/**
|
|
9970
|
+
* Sends a chat message to the AI.
|
|
9971
|
+
* Returns a promise that contains the response from the AI.
|
|
9972
|
+
* Throws a {@link CasualOSError} if an error occurs while sending the message.
|
|
9973
|
+
*
|
|
9974
|
+
* This function can be useful for creating chat bots, or for using an Artificial Intelligence (AI) to process a message.
|
|
9975
|
+
*
|
|
9976
|
+
* @param message The message that should be sent to the AI.
|
|
9977
|
+
* @param options The options that should be used.
|
|
9978
|
+
*
|
|
9979
|
+
* @example Send a message to the AI and log the response.
|
|
9980
|
+
* const response = await ai.chat([
|
|
9981
|
+
* {
|
|
9982
|
+
* role: "system",
|
|
9983
|
+
* content: "You are a helpful assistant."
|
|
9984
|
+
* },
|
|
9985
|
+
* {
|
|
9986
|
+
* role: "user",
|
|
9987
|
+
* content: "Hello!"
|
|
9988
|
+
* }
|
|
9989
|
+
* ]);
|
|
9990
|
+
* console.log(`${response.role}: ${response.content}`);
|
|
9991
|
+
*
|
|
9992
|
+
* @example Build a basic chat bot.
|
|
9993
|
+
* const messages = [
|
|
9994
|
+
* {
|
|
9995
|
+
* role: "system",
|
|
9996
|
+
* content: "You are a helpful assistant."
|
|
9997
|
+
* },
|
|
9998
|
+
* ];
|
|
9999
|
+
*
|
|
10000
|
+
* while(true) {
|
|
10001
|
+
* const userInput = await os.showInput();
|
|
10002
|
+
* if (!userInput) {
|
|
10003
|
+
* break;
|
|
10004
|
+
* }
|
|
10005
|
+
* messages.push({
|
|
10006
|
+
* role: "user",
|
|
10007
|
+
* content: userInput
|
|
10008
|
+
* });
|
|
10009
|
+
*
|
|
10010
|
+
* const response = await ai.chat(messages);
|
|
10011
|
+
* messages.push(response);
|
|
10012
|
+
* os.toast(response.content);
|
|
10013
|
+
* }
|
|
10014
|
+
*
|
|
10015
|
+
* os.toast("Goodbye!");
|
|
10016
|
+
*
|
|
10017
|
+
* @dochash actions/ai
|
|
10018
|
+
* @docname ai.chat
|
|
10019
|
+
* @docid ai.chat-messages
|
|
10020
|
+
*/
|
|
10021
|
+
chat(
|
|
10022
|
+
messages: string | AIChatMessage | AIChatMessage[],
|
|
10023
|
+
options?: AIChatOptions
|
|
10024
|
+
): Promise<AIChatMessage | string>
|
|
10025
|
+
}
|
|
10026
|
+
|
|
9763
10027
|
interface Os {
|
|
9764
10028
|
/**
|
|
9765
10029
|
* Sleeps for time in ms.
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Defines an interface that represents a generic error.
|
|
3
|
+
*
|
|
4
|
+
* @dochash types/error
|
|
5
|
+
* @docname GenericError
|
|
6
|
+
*/
|
|
7
|
+
export interface GenericError {
|
|
8
|
+
/**
|
|
9
|
+
* The error code.
|
|
10
|
+
*/
|
|
11
|
+
errorCode: string;
|
|
12
|
+
/**
|
|
13
|
+
* The error message.
|
|
14
|
+
*/
|
|
15
|
+
errorMessage: string;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Defines a class that represents a generic CasualOS error.
|
|
19
|
+
*
|
|
20
|
+
* @dochash types/error
|
|
21
|
+
* @doctitle Error Types
|
|
22
|
+
* @docsidebar Error
|
|
23
|
+
* @docdescription Types that contain information about errors that can occur in CasualOS.
|
|
24
|
+
* @docname CasualOSError
|
|
25
|
+
*/
|
|
26
|
+
export declare class CasualOSError extends Error {
|
|
27
|
+
/**
|
|
28
|
+
* The error code that occurred.
|
|
29
|
+
*/
|
|
30
|
+
errorCode: string;
|
|
31
|
+
/**
|
|
32
|
+
* The error message that occurred.
|
|
33
|
+
*/
|
|
34
|
+
errorMessage: string;
|
|
35
|
+
constructor(error: GenericError | string);
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=CasualOSError.d.ts.map
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Defines a class that represents a generic CasualOS error.
|
|
3
|
+
*
|
|
4
|
+
* @dochash types/error
|
|
5
|
+
* @doctitle Error Types
|
|
6
|
+
* @docsidebar Error
|
|
7
|
+
* @docdescription Types that contain information about errors that can occur in CasualOS.
|
|
8
|
+
* @docname CasualOSError
|
|
9
|
+
*/
|
|
10
|
+
export class CasualOSError extends Error {
|
|
11
|
+
constructor(error) {
|
|
12
|
+
super(typeof error === 'string'
|
|
13
|
+
? error
|
|
14
|
+
: `${error.errorCode}: ${error.errorMessage}`);
|
|
15
|
+
if (typeof error === 'string') {
|
|
16
|
+
this.errorCode = 'error';
|
|
17
|
+
this.errorMessage = error;
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
this.errorCode = error.errorCode;
|
|
21
|
+
this.errorMessage = error.errorMessage;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=CasualOSError.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CasualOSError.js","sourceRoot":"","sources":["CasualOSError.ts"],"names":[],"mappings":"AAkBA;;;;;;;;GAQG;AACH,MAAM,OAAO,aAAc,SAAQ,KAAK;IAWpC,YAAY,KAA4B;QACpC,KAAK,CACD,OAAO,KAAK,KAAK,QAAQ;YACrB,CAAC,CAAC,KAAK;YACP,CAAC,CAAC,GAAG,KAAK,CAAC,SAAS,KAAK,KAAK,CAAC,YAAY,EAAE,CACpD,CAAC;QACF,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;YAC3B,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC;YACzB,IAAI,CAAC,YAAY,GAAG,KAAK,CAAC;SAC7B;aAAM;YACH,IAAI,CAAC,SAAS,GAAG,KAAK,CAAC,SAAS,CAAC;YACjC,IAAI,CAAC,YAAY,GAAG,KAAK,CAAC,YAAY,CAAC;SAC1C;IACL,CAAC;CACJ"}
|