@cellaware/utils 2.0.0 → 3.0.0
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/README.md +6 -0
- package/dist/azure/cosmos.d.ts +9 -0
- package/dist/azure/cosmos.js +9 -0
- package/dist/azure/storage.d.ts +4 -4
- package/dist/azure/storage.js +4 -4
- package/dist/chatwms/api.d.ts +12 -0
- package/dist/chatwms/api.js +14 -0
- package/dist/chatwms/azure/function.d.ts +2 -2
- package/dist/chatwms/azure/function.js +2 -2
- package/dist/chatwms/azure/storage.d.ts +5 -5
- package/dist/chatwms/azure/storage.js +10 -10
- package/dist/chatwms/client.d.ts +2 -2
- package/dist/chatwms/client.js +2 -2
- package/dist/chatwms/github/issue.d.ts +1 -0
- package/dist/chatwms/github/issue.js +4 -0
- package/dist/chatwms/user.d.ts +6 -0
- package/dist/chatwms/user.js +7 -0
- package/dist/github/issue.d.ts +1 -0
- package/dist/github/issue.js +23 -0
- package/dist/llm/chain-store.d.ts +3 -3
- package/dist/util.d.ts +6 -0
- package/dist/util.js +25 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -26,10 +26,16 @@ Azure Cosmos database key.
|
|
|
26
26
|
|
|
27
27
|
Connection string of Azure Storage account.
|
|
28
28
|
|
|
29
|
+
### GITHUB_TOKEN
|
|
30
|
+
|
|
31
|
+
Token used for GitHub authorization.
|
|
32
|
+
|
|
29
33
|
### CHATWMS_URL
|
|
30
34
|
|
|
31
35
|
ChatWMS URL.
|
|
32
36
|
|
|
37
|
+
> NOTE: `CHATWMS_URL` could also refer to `chatwms-mgmt` or other ChatWMS services
|
|
38
|
+
|
|
33
39
|
### CHATWMS_KEY
|
|
34
40
|
|
|
35
41
|
ChatWMS function key.
|
package/dist/azure/cosmos.d.ts
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
export declare const COSMOS_CURRENT_YEAR_CLAUSE = "DateTimePart('yyyy', GetCurrentDateTime())";
|
|
2
|
+
export declare const COSMOS_RECORD_YEAR_CLAUSE = "DateTimePart('yyyy', TimestampToDateTime(c._ts*1000))";
|
|
3
|
+
export declare const COSMOS_CURRENT_MONTH_CLAUSE = "DateTimePart('mm', GetCurrentDateTime())";
|
|
4
|
+
export declare const COSMOS_RECORD_MONTH_CLAUSE = "DateTimePart('mm', TimestampToDateTime(c._ts*1000))";
|
|
5
|
+
export declare const COSMOS_CURRENT_DAY_CLAUSE = "DateTimePart('dd', GetCurrentDateTime())";
|
|
6
|
+
export declare const COSMOS_RECORD_DAY_CLAUSE = "DateTimePart('dd', TimestampToDateTime(c._ts*1000))";
|
|
7
|
+
export declare const COSMOS_CURRENT_DAY_CONDITION_CLAUSE = "DateTimeDiff('dd', TimestampToDateTime(c._ts*1000), GetCurrentDateTime()) = 0";
|
|
8
|
+
export declare const COSMOS_CURRENT_MONTH_CONDITION_CLAUSE = "DateTimeDiff('mm', TimestampToDateTime(c._ts*1000), GetCurrentDateTime()) = 0";
|
|
9
|
+
export declare const COSMOS_CURRENT_YEAR_CONDITION_CLAUSE = "DateTimeDiff('yyyy', TimestampToDateTime(c._ts*1000), GetCurrentDateTime()) = 0";
|
|
1
10
|
export declare function cosmosSelect(databaseId: string, collectionId: string, partitionKey: string, query: string): Promise<any[]>;
|
|
2
11
|
export declare function cosmosInsert(databaseId: string, collectionId: string, partitionKey: string, data: any): Promise<boolean>;
|
|
3
12
|
export declare function cosmosDelete(databaseId: string, collectionId: string, partitionKey: string, query: string): Promise<boolean>;
|
package/dist/azure/cosmos.js
CHANGED
|
@@ -1,4 +1,13 @@
|
|
|
1
1
|
import { CosmosClient } from '@azure/cosmos';
|
|
2
|
+
export const COSMOS_CURRENT_YEAR_CLAUSE = `DateTimePart('yyyy', GetCurrentDateTime())`;
|
|
3
|
+
export const COSMOS_RECORD_YEAR_CLAUSE = `DateTimePart('yyyy', TimestampToDateTime(c._ts*1000))`;
|
|
4
|
+
export const COSMOS_CURRENT_MONTH_CLAUSE = `DateTimePart('mm', GetCurrentDateTime())`;
|
|
5
|
+
export const COSMOS_RECORD_MONTH_CLAUSE = `DateTimePart('mm', TimestampToDateTime(c._ts*1000))`;
|
|
6
|
+
export const COSMOS_CURRENT_DAY_CLAUSE = `DateTimePart('dd', GetCurrentDateTime())`;
|
|
7
|
+
export const COSMOS_RECORD_DAY_CLAUSE = `DateTimePart('dd', TimestampToDateTime(c._ts*1000))`;
|
|
8
|
+
export const COSMOS_CURRENT_DAY_CONDITION_CLAUSE = `DateTimeDiff('dd', TimestampToDateTime(c._ts*1000), GetCurrentDateTime()) = 0`;
|
|
9
|
+
export const COSMOS_CURRENT_MONTH_CONDITION_CLAUSE = `DateTimeDiff('mm', TimestampToDateTime(c._ts*1000), GetCurrentDateTime()) = 0`;
|
|
10
|
+
export const COSMOS_CURRENT_YEAR_CONDITION_CLAUSE = `DateTimeDiff('yyyy', TimestampToDateTime(c._ts*1000), GetCurrentDateTime()) = 0`;
|
|
2
11
|
export async function cosmosSelect(databaseId, collectionId, partitionKey, query) {
|
|
3
12
|
try {
|
|
4
13
|
const cosmosClient = new CosmosClient({
|
package/dist/azure/storage.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare function
|
|
2
|
-
export declare function
|
|
3
|
-
export declare function
|
|
4
|
-
export declare function
|
|
1
|
+
export declare function storageContainerCreate(containerClientId: string): Promise<void>;
|
|
2
|
+
export declare function storageBlobUpload(containerClientId: string, blobId: string, data: any): Promise<void>;
|
|
3
|
+
export declare function storageBlobDelete(containerClientId: string, blobId: string): Promise<void>;
|
|
4
|
+
export declare function storageBlobDownload(containerClientId: string, blobId: string): Promise<any[]>;
|
package/dist/azure/storage.js
CHANGED
|
@@ -11,7 +11,7 @@ function streamToBuffer(stream) {
|
|
|
11
11
|
stream.on("error", reject);
|
|
12
12
|
});
|
|
13
13
|
}
|
|
14
|
-
export async function
|
|
14
|
+
export async function storageContainerCreate(containerClientId) {
|
|
15
15
|
try {
|
|
16
16
|
const blobServiceClient = BlobServiceClient.fromConnectionString(process.env.STORAGE_CONNECTION_STRING ?? '');
|
|
17
17
|
const containerClient = blobServiceClient.getContainerClient(containerClientId);
|
|
@@ -21,7 +21,7 @@ export async function containerCreate(containerClientId) {
|
|
|
21
21
|
console.log(`STORAGE: CONTAINER create error: ${err.message}`);
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
|
-
export async function
|
|
24
|
+
export async function storageBlobUpload(containerClientId, blobId, data) {
|
|
25
25
|
try {
|
|
26
26
|
const blobServiceClient = BlobServiceClient.fromConnectionString(process.env.STORAGE_CONNECTION_STRING ?? '');
|
|
27
27
|
const containerClient = blobServiceClient.getContainerClient(containerClientId);
|
|
@@ -32,7 +32,7 @@ export async function blobUpload(containerClientId, blobId, data) {
|
|
|
32
32
|
console.log(`STORAGE: BLOB upload error: ${err.message}`);
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
|
-
export async function
|
|
35
|
+
export async function storageBlobDelete(containerClientId, blobId) {
|
|
36
36
|
try {
|
|
37
37
|
const blobServiceClient = BlobServiceClient.fromConnectionString(process.env.STORAGE_CONNECTION_STRING ?? '');
|
|
38
38
|
const containerClient = blobServiceClient.getContainerClient(containerClientId);
|
|
@@ -43,7 +43,7 @@ export async function blobDelete(containerClientId, blobId) {
|
|
|
43
43
|
console.log(`STORAGE: BLOB delete error: ${err.message}`);
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
|
-
export async function
|
|
46
|
+
export async function storageBlobDownload(containerClientId, blobId) {
|
|
47
47
|
if (!process.env.STORAGE_CONNECTION_STRING) {
|
|
48
48
|
console.log(`STORAGE: No connection string set`);
|
|
49
49
|
return [];
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ChatWMSUserData } from "./user";
|
|
2
|
+
export interface ChatWMSApiInput {
|
|
3
|
+
userData: ChatWMSUserData;
|
|
4
|
+
data: any;
|
|
5
|
+
}
|
|
6
|
+
export declare function chatwmsInitApiInput(): ChatWMSApiInput;
|
|
7
|
+
export interface ChatWMSApiOutput {
|
|
8
|
+
status: number;
|
|
9
|
+
message: string;
|
|
10
|
+
data: any;
|
|
11
|
+
}
|
|
12
|
+
export declare function chatwmsInitApiOutput(): ChatWMSApiOutput;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { chatwmsInitUserData } from "./user";
|
|
2
|
+
export function chatwmsInitApiInput() {
|
|
3
|
+
return {
|
|
4
|
+
userData: chatwmsInitUserData(),
|
|
5
|
+
data: {}
|
|
6
|
+
};
|
|
7
|
+
}
|
|
8
|
+
export function chatwmsInitApiOutput() {
|
|
9
|
+
return {
|
|
10
|
+
status: 0,
|
|
11
|
+
message: '',
|
|
12
|
+
data: {}
|
|
13
|
+
};
|
|
14
|
+
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare function
|
|
2
|
-
export declare function
|
|
1
|
+
export declare function chatwmsFetch(path: string, method: string, body?: any): Promise<any>;
|
|
2
|
+
export declare function chatwmsQuery(path: string, method: string, query: string): Promise<any>;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { functionFetchJson, functionFetchText } from "../../azure/function.js";
|
|
2
|
-
export function
|
|
2
|
+
export function chatwmsFetch(path, method, body) {
|
|
3
3
|
const url = `${process.env['CHATWMS_URL']}/${path}`;
|
|
4
4
|
return functionFetchJson(url, method, process.env['CHATWMS_KEY'] ?? '', body);
|
|
5
5
|
}
|
|
6
|
-
export function
|
|
6
|
+
export function chatwmsQuery(path, method, query) {
|
|
7
7
|
const url = `${process.env['CHATWMS_URL']}/${path}`;
|
|
8
8
|
return functionFetchText(url, method, process.env['CHATWMS_KEY'] ?? '', query);
|
|
9
9
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export declare function
|
|
2
|
-
export declare function
|
|
3
|
-
export declare function
|
|
4
|
-
export declare function
|
|
5
|
-
export declare function
|
|
1
|
+
export declare function getStorageBlobId(clientId: string, blobName: string): string;
|
|
2
|
+
export declare function chatwmsStorageContainerCreate(): Promise<void>;
|
|
3
|
+
export declare function chatwmsStorageBlobUpload(blobId: string, data: any): Promise<void>;
|
|
4
|
+
export declare function chatwmsStorageBlobDelete(blobId: string): Promise<void>;
|
|
5
|
+
export declare function chatwmsStorageBlobDownload(blobId: string): Promise<any[]>;
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { storageBlobDelete, storageBlobDownload, storageBlobUpload, storageContainerCreate } from "../../azure/storage.js";
|
|
2
2
|
const CONTAINER_CLIENT_ID = 'chatwms';
|
|
3
|
-
export function
|
|
3
|
+
export function getStorageBlobId(clientId, blobName) {
|
|
4
4
|
return clientId.replace('_', '-') + '-' + blobName;
|
|
5
5
|
}
|
|
6
|
-
export async function
|
|
7
|
-
return
|
|
6
|
+
export async function chatwmsStorageContainerCreate() {
|
|
7
|
+
return storageContainerCreate(CONTAINER_CLIENT_ID);
|
|
8
8
|
}
|
|
9
|
-
export async function
|
|
10
|
-
return
|
|
9
|
+
export async function chatwmsStorageBlobUpload(blobId, data) {
|
|
10
|
+
return storageBlobUpload(CONTAINER_CLIENT_ID, blobId, data);
|
|
11
11
|
}
|
|
12
|
-
export async function
|
|
13
|
-
return
|
|
12
|
+
export async function chatwmsStorageBlobDelete(blobId) {
|
|
13
|
+
return storageBlobDelete(CONTAINER_CLIENT_ID, blobId);
|
|
14
14
|
}
|
|
15
|
-
export async function
|
|
16
|
-
return
|
|
15
|
+
export async function chatwmsStorageBlobDownload(blobId) {
|
|
16
|
+
return storageBlobDownload(CONTAINER_CLIENT_ID, blobId);
|
|
17
17
|
}
|
package/dist/chatwms/client.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const
|
|
2
|
-
export declare function
|
|
1
|
+
export declare const CHATWMS_GENERIC_CLIENT_ID = "chatwms";
|
|
2
|
+
export declare function chatwmsGetClientId(customer: string, warehouse: string): string;
|
package/dist/chatwms/client.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function chatwmsGithubCreateIssue(title: string, body: any, labels: string[]): Promise<boolean>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function githubCreateIssue(issueUrl: string, issueTitle: string, issueBody: any, issueLabels: string[]): Promise<boolean>;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export async function githubCreateIssue(issueUrl, issueTitle, issueBody, issueLabels) {
|
|
2
|
+
const token = process.env.GITHUB_TOKEN ?? '';
|
|
3
|
+
if (token.length === 0) {
|
|
4
|
+
throw new Error('GITHUB: `GITHUB_TOKEN` environment variable is not set');
|
|
5
|
+
}
|
|
6
|
+
const headers = {
|
|
7
|
+
'Authorization': `token ${token}`,
|
|
8
|
+
'X-GitHub-Api-Version': '2022-11-28',
|
|
9
|
+
'Accept': 'application/vnd.github+json'
|
|
10
|
+
};
|
|
11
|
+
const body = {
|
|
12
|
+
title: issueTitle,
|
|
13
|
+
body: issueBody,
|
|
14
|
+
labels: issueLabels
|
|
15
|
+
};
|
|
16
|
+
const req = {
|
|
17
|
+
method: 'POST',
|
|
18
|
+
headers,
|
|
19
|
+
body: JSON.stringify(body)
|
|
20
|
+
};
|
|
21
|
+
let res = await fetch(issueUrl, req);
|
|
22
|
+
return res.ok;
|
|
23
|
+
}
|
|
@@ -19,7 +19,7 @@ export declare class SingleActionChain extends BaseChain {
|
|
|
19
19
|
getModelName(): ModelName;
|
|
20
20
|
getPrompt(): string;
|
|
21
21
|
}
|
|
22
|
-
export declare function createSingleActionChain(name: string, modelName:
|
|
22
|
+
export declare function createSingleActionChain(name: string, modelName: ModelName, inputKeys: string[], prompt: string, temperature?: number, verbose?: boolean): SingleActionChain;
|
|
23
23
|
/**
|
|
24
24
|
* A `ChainStore` is a chain registry and calling interface. The `ChainStore`
|
|
25
25
|
* keeps a map of all registered chains.
|
|
@@ -31,11 +31,11 @@ export declare function createSingleActionChain(name: string, modelName: string,
|
|
|
31
31
|
export declare class ChainStore {
|
|
32
32
|
private promptsPath;
|
|
33
33
|
private chains;
|
|
34
|
-
constructor(promptsPath: string, defaultModelName?:
|
|
34
|
+
constructor(promptsPath: string, defaultModelName?: ModelName);
|
|
35
35
|
private initBuiltinChains;
|
|
36
36
|
private static getTokenUsage;
|
|
37
37
|
private getPrompt;
|
|
38
|
-
addChain(name: string, modelName:
|
|
38
|
+
addChain(name: string, modelName: ModelName, temperature?: number, verbose?: boolean): void;
|
|
39
39
|
addExistingChain(chain: SingleActionChain): void;
|
|
40
40
|
callChain(name: string, args: any, tokenUsages: any[]): Promise<import("langchain/dist/schema/index.js").ChainValues>;
|
|
41
41
|
translate(statement: string, language: string, tokenUsages?: any[]): Promise<string>;
|
package/dist/util.d.ts
CHANGED
|
@@ -1,2 +1,8 @@
|
|
|
1
1
|
export declare function sleep(ms: number): Promise<any>;
|
|
2
2
|
export declare function removeMarkdownIndicators(input: string): string;
|
|
3
|
+
export declare function isLeapYear(): boolean;
|
|
4
|
+
export declare function getDaysInMonth(): number;
|
|
5
|
+
export declare function getCurrentDayInMonth(): number;
|
|
6
|
+
export declare function getDaysInYear(): 366 | 365;
|
|
7
|
+
export declare function getCurrentMonth(): number;
|
|
8
|
+
export declare function getCurrentYear(): number;
|
package/dist/util.js
CHANGED
|
@@ -13,3 +13,28 @@ export function removeMarkdownIndicators(input) {
|
|
|
13
13
|
}
|
|
14
14
|
return output;
|
|
15
15
|
}
|
|
16
|
+
export function isLeapYear() {
|
|
17
|
+
let year = new Date().getFullYear();
|
|
18
|
+
return ((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0);
|
|
19
|
+
}
|
|
20
|
+
export function getDaysInMonth() {
|
|
21
|
+
let date = new Date();
|
|
22
|
+
// NOTE: month is 0-based.
|
|
23
|
+
return new Date(date.getFullYear(), date.getMonth() + 1, 0).getDate();
|
|
24
|
+
}
|
|
25
|
+
export function getCurrentDayInMonth() {
|
|
26
|
+
let date = new Date();
|
|
27
|
+
return date.getDate();
|
|
28
|
+
}
|
|
29
|
+
export function getDaysInYear() {
|
|
30
|
+
return isLeapYear() ? 366 : 365;
|
|
31
|
+
}
|
|
32
|
+
export function getCurrentMonth() {
|
|
33
|
+
let date = new Date();
|
|
34
|
+
// NOTE: month is 0-based.
|
|
35
|
+
return date.getMonth() + 1;
|
|
36
|
+
}
|
|
37
|
+
export function getCurrentYear() {
|
|
38
|
+
let date = new Date();
|
|
39
|
+
return date.getFullYear();
|
|
40
|
+
}
|