repo_name string | dataset string | owner string | lang string | func_name string | code string | docstring string | url string | sha string |
|---|---|---|---|---|---|---|---|---|
openai-deno-build | github_2023 | openai | typescript | FileBatches.uploadAndPoll | async uploadAndPoll(
vectorStoreId: string,
{ files, fileIds = [] }: { files: Uploadable[]; fileIds?: string[] },
options?: Core.RequestOptions & {
pollIntervalMs?: number;
maxConcurrency?: number;
},
): Promise<VectorStoreFileBatch> {
if (files == null || files.length == 0) {
th... | /**
* Uploads the given files concurrently and then creates a vector store file batch.
*
* The concurrency limit is configurable using the `maxConcurrency` parameter.
*/ | https://github.com/openai/openai-deno-build/blob/28ffdaa2c107c98db5eec50cf284f4fd37ad8fbe/resources/beta/vector-stores/file-batches.ts#L172-L218 | 28ffdaa2c107c98db5eec50cf284f4fd37ad8fbe |
openai-deno-build | github_2023 | openai | typescript | processFiles | async function processFiles(iterator: IterableIterator<Uploadable>) {
for (let item of iterator) {
const fileObj = await client.files.create({
file: item,
purpose: "assistants",
}, options);
allFileIds.push(fileObj.id);
}
} | // This code is based on this design. The libraries don't accommodate our environment limits. | https://github.com/openai/openai-deno-build/blob/28ffdaa2c107c98db5eec50cf284f4fd37ad8fbe/resources/beta/vector-stores/file-batches.ts#L197-L205 | 28ffdaa2c107c98db5eec50cf284f4fd37ad8fbe |
openai-deno-build | github_2023 | openai | typescript | Files.create | create(
vectorStoreId: string,
body: FileCreateParams,
options?: Core.RequestOptions,
): Core.APIPromise<VectorStoreFile> {
return this._client.post(`/vector_stores/${vectorStoreId}/files`, {
body,
...options,
headers: { "OpenAI-Beta": "assistants=v2", ...options?.headers },
});
... | /**
* Create a vector store file by attaching a
* [File](https://platform.openai.com/docs/api-reference/files) to a
* [vector store](https://platform.openai.com/docs/api-reference/vector-stores/object).
*/ | https://github.com/openai/openai-deno-build/blob/28ffdaa2c107c98db5eec50cf284f4fd37ad8fbe/resources/beta/vector-stores/files.ts#L16-L26 | 28ffdaa2c107c98db5eec50cf284f4fd37ad8fbe |
openai-deno-build | github_2023 | openai | typescript | Files.retrieve | retrieve(
vectorStoreId: string,
fileId: string,
options?: Core.RequestOptions,
): Core.APIPromise<VectorStoreFile> {
return this._client.get(`/vector_stores/${vectorStoreId}/files/${fileId}`, {
...options,
headers: { "OpenAI-Beta": "assistants=v2", ...options?.headers },
});
} | /**
* Retrieves a vector store file.
*/ | https://github.com/openai/openai-deno-build/blob/28ffdaa2c107c98db5eec50cf284f4fd37ad8fbe/resources/beta/vector-stores/files.ts#L31-L40 | 28ffdaa2c107c98db5eec50cf284f4fd37ad8fbe |
openai-deno-build | github_2023 | openai | typescript | Files.del | del(
vectorStoreId: string,
fileId: string,
options?: Core.RequestOptions,
): Core.APIPromise<VectorStoreFileDeleted> {
return this._client.delete(
`/vector_stores/${vectorStoreId}/files/${fileId}`,
{
...options,
headers: { "OpenAI-Beta": "assistants=v2", ...options?.header... | /**
* Delete a vector store file. This will remove the file from the vector store but
* the file itself will not be deleted. To delete the file, use the
* [delete file](https://platform.openai.com/docs/api-reference/files/delete)
* endpoint.
*/ | https://github.com/openai/openai-deno-build/blob/28ffdaa2c107c98db5eec50cf284f4fd37ad8fbe/resources/beta/vector-stores/files.ts#L79-L91 | 28ffdaa2c107c98db5eec50cf284f4fd37ad8fbe |
openai-deno-build | github_2023 | openai | typescript | Files.createAndPoll | async createAndPoll(
vectorStoreId: string,
body: FileCreateParams,
options?: Core.RequestOptions & { pollIntervalMs?: number },
): Promise<VectorStoreFile> {
const file = await this.create(vectorStoreId, body, options);
return await this.poll(vectorStoreId, file.id, options);
} | /**
* Attach a file to the given vector store and wait for it to be processed.
*/ | https://github.com/openai/openai-deno-build/blob/28ffdaa2c107c98db5eec50cf284f4fd37ad8fbe/resources/beta/vector-stores/files.ts#L96-L103 | 28ffdaa2c107c98db5eec50cf284f4fd37ad8fbe |
openai-deno-build | github_2023 | openai | typescript | Files.poll | async poll(
vectorStoreId: string,
fileId: string,
options?: Core.RequestOptions & { pollIntervalMs?: number },
): Promise<VectorStoreFile> {
const headers: { [key: string]: string } = {
...options?.headers,
"X-Stainless-Poll-Helper": "true",
};
if (options?.pollIntervalMs) {
... | /**
* Wait for the vector store file to finish processing.
*
* Note: this will return even if the file failed to process, you need to check
* file.last_error and file.status to handle these cases
*/ | https://github.com/openai/openai-deno-build/blob/28ffdaa2c107c98db5eec50cf284f4fd37ad8fbe/resources/beta/vector-stores/files.ts#L111-L156 | 28ffdaa2c107c98db5eec50cf284f4fd37ad8fbe |
openai-deno-build | github_2023 | openai | typescript | Files.upload | async upload(
vectorStoreId: string,
file: Uploadable,
options?: Core.RequestOptions,
): Promise<VectorStoreFile> {
const fileInfo = await this._client.files.create({
file: file,
purpose: "assistants",
}, options);
return this.create(vectorStoreId, { file_id: fileInfo.id }, options... | /**
* Upload a file to the `files` API and then attach it to the given vector store.
*
* Note the file will be asynchronously processed (you can use the alternative
* polling helper method to wait for processing to complete).
*/ | https://github.com/openai/openai-deno-build/blob/28ffdaa2c107c98db5eec50cf284f4fd37ad8fbe/resources/beta/vector-stores/files.ts#L164-L174 | 28ffdaa2c107c98db5eec50cf284f4fd37ad8fbe |
openai-deno-build | github_2023 | openai | typescript | Files.uploadAndPoll | async uploadAndPoll(
vectorStoreId: string,
file: Uploadable,
options?: Core.RequestOptions & { pollIntervalMs?: number },
): Promise<VectorStoreFile> {
const fileInfo = await this.upload(vectorStoreId, file, options);
return await this.poll(vectorStoreId, fileInfo.id, options);
} | /**
* Add a file to a vector store and poll until processing is complete.
*/ | https://github.com/openai/openai-deno-build/blob/28ffdaa2c107c98db5eec50cf284f4fd37ad8fbe/resources/beta/vector-stores/files.ts#L179-L186 | 28ffdaa2c107c98db5eec50cf284f4fd37ad8fbe |
openai-deno-build | github_2023 | openai | typescript | VectorStores.create | create(
body: VectorStoreCreateParams,
options?: Core.RequestOptions,
): Core.APIPromise<VectorStore> {
return this._client.post("/vector_stores", {
body,
...options,
headers: { "OpenAI-Beta": "assistants=v2", ...options?.headers },
});
} | /**
* Create a vector store.
*/ | https://github.com/openai/openai-deno-build/blob/28ffdaa2c107c98db5eec50cf284f4fd37ad8fbe/resources/beta/vector-stores/vector-stores.ts#L20-L29 | 28ffdaa2c107c98db5eec50cf284f4fd37ad8fbe |
openai-deno-build | github_2023 | openai | typescript | VectorStores.retrieve | retrieve(
vectorStoreId: string,
options?: Core.RequestOptions,
): Core.APIPromise<VectorStore> {
return this._client.get(`/vector_stores/${vectorStoreId}`, {
...options,
headers: { "OpenAI-Beta": "assistants=v2", ...options?.headers },
});
} | /**
* Retrieves a vector store.
*/ | https://github.com/openai/openai-deno-build/blob/28ffdaa2c107c98db5eec50cf284f4fd37ad8fbe/resources/beta/vector-stores/vector-stores.ts#L34-L42 | 28ffdaa2c107c98db5eec50cf284f4fd37ad8fbe |
openai-deno-build | github_2023 | openai | typescript | VectorStores.update | update(
vectorStoreId: string,
body: VectorStoreUpdateParams,
options?: Core.RequestOptions,
): Core.APIPromise<VectorStore> {
return this._client.post(`/vector_stores/${vectorStoreId}`, {
body,
...options,
headers: { "OpenAI-Beta": "assistants=v2", ...options?.headers },
});
} | /**
* Modifies a vector store.
*/ | https://github.com/openai/openai-deno-build/blob/28ffdaa2c107c98db5eec50cf284f4fd37ad8fbe/resources/beta/vector-stores/vector-stores.ts#L47-L57 | 28ffdaa2c107c98db5eec50cf284f4fd37ad8fbe |
openai-deno-build | github_2023 | openai | typescript | VectorStores.del | del(
vectorStoreId: string,
options?: Core.RequestOptions,
): Core.APIPromise<VectorStoreDeleted> {
return this._client.delete(`/vector_stores/${vectorStoreId}`, {
...options,
headers: { "OpenAI-Beta": "assistants=v2", ...options?.headers },
});
} | /**
* Delete a vector store.
*/ | https://github.com/openai/openai-deno-build/blob/28ffdaa2c107c98db5eec50cf284f4fd37ad8fbe/resources/beta/vector-stores/vector-stores.ts#L86-L94 | 28ffdaa2c107c98db5eec50cf284f4fd37ad8fbe |
openai-deno-build | github_2023 | openai | typescript | Jobs.create | create(
body: JobCreateParams,
options?: Core.RequestOptions,
): Core.APIPromise<FineTuningJob> {
return this._client.post("/fine_tuning/jobs", { body, ...options });
} | /**
* Creates a fine-tuning job which begins the process of creating a new model from
* a given dataset.
*
* Response includes details of the enqueued job including job status and the name
* of the fine-tuned models once complete.
*
* [Learn more about fine-tuning](https://platform.openai.com/docs/... | https://github.com/openai/openai-deno-build/blob/28ffdaa2c107c98db5eec50cf284f4fd37ad8fbe/resources/fine-tuning/jobs/jobs.ts#L24-L29 | 28ffdaa2c107c98db5eec50cf284f4fd37ad8fbe |
openai-deno-build | github_2023 | openai | typescript | Jobs.retrieve | retrieve(
fineTuningJobId: string,
options?: Core.RequestOptions,
): Core.APIPromise<FineTuningJob> {
return this._client.get(`/fine_tuning/jobs/${fineTuningJobId}`, options);
} | /**
* Get info about a fine-tuning job.
*
* [Learn more about fine-tuning](https://platform.openai.com/docs/guides/fine-tuning)
*/ | https://github.com/openai/openai-deno-build/blob/28ffdaa2c107c98db5eec50cf284f4fd37ad8fbe/resources/fine-tuning/jobs/jobs.ts#L36-L41 | 28ffdaa2c107c98db5eec50cf284f4fd37ad8fbe |
openai-deno-build | github_2023 | openai | typescript | Jobs.cancel | cancel(
fineTuningJobId: string,
options?: Core.RequestOptions,
): Core.APIPromise<FineTuningJob> {
return this._client.post(
`/fine_tuning/jobs/${fineTuningJobId}/cancel`,
options,
);
} | /**
* Immediately cancel a fine-tune job.
*/ | https://github.com/openai/openai-deno-build/blob/28ffdaa2c107c98db5eec50cf284f4fd37ad8fbe/resources/fine-tuning/jobs/jobs.ts#L69-L77 | 28ffdaa2c107c98db5eec50cf284f4fd37ad8fbe |
openai-deno-build | github_2023 | openai | typescript | Parts.create | create(
uploadId: string,
body: PartCreateParams,
options?: Core.RequestOptions,
): Core.APIPromise<UploadPart> {
return this._client.post(
`/uploads/${uploadId}/parts`,
Core.multipartFormRequestOptions({ body, ...options }),
);
} | /**
* Adds a
* [Part](https://platform.openai.com/docs/api-reference/uploads/part-object) to an
* [Upload](https://platform.openai.com/docs/api-reference/uploads/object) object.
* A Part represents a chunk of bytes from the file you are trying to upload.
*
* Each Part can be at most 64 MB, and you can... | https://github.com/openai/openai-deno-build/blob/28ffdaa2c107c98db5eec50cf284f4fd37ad8fbe/resources/uploads/parts.ts#L21-L30 | 28ffdaa2c107c98db5eec50cf284f4fd37ad8fbe |
openai-deno-build | github_2023 | openai | typescript | Uploads.create | create(
body: UploadCreateParams,
options?: Core.RequestOptions,
): Core.APIPromise<Upload> {
return this._client.post("/uploads", { body, ...options });
} | /**
* Creates an intermediate
* [Upload](https://platform.openai.com/docs/api-reference/uploads/object) object
* that you can add
* [Parts](https://platform.openai.com/docs/api-reference/uploads/part-object) to.
* Currently, an Upload can accept at most 8 GB in total and expires after an hour
* after ... | https://github.com/openai/openai-deno-build/blob/28ffdaa2c107c98db5eec50cf284f4fd37ad8fbe/resources/uploads/uploads.ts#L34-L39 | 28ffdaa2c107c98db5eec50cf284f4fd37ad8fbe |
openai-deno-build | github_2023 | openai | typescript | Uploads.cancel | cancel(
uploadId: string,
options?: Core.RequestOptions,
): Core.APIPromise<Upload> {
return this._client.post(`/uploads/${uploadId}/cancel`, options);
} | /**
* Cancels the Upload. No Parts may be added after an Upload is cancelled.
*/ | https://github.com/openai/openai-deno-build/blob/28ffdaa2c107c98db5eec50cf284f4fd37ad8fbe/resources/uploads/uploads.ts#L44-L49 | 28ffdaa2c107c98db5eec50cf284f4fd37ad8fbe |
openai-deno-build | github_2023 | openai | typescript | Uploads.complete | complete(
uploadId: string,
body: UploadCompleteParams,
options?: Core.RequestOptions,
): Core.APIPromise<Upload> {
return this._client.post(`/uploads/${uploadId}/complete`, {
body,
...options,
});
} | /**
* Completes the
* [Upload](https://platform.openai.com/docs/api-reference/uploads/object).
*
* Within the returned Upload object, there is a nested
* [File](https://platform.openai.com/docs/api-reference/files/object) object that
* is ready to use in the rest of the platform.
*
* You can spe... | https://github.com/openai/openai-deno-build/blob/28ffdaa2c107c98db5eec50cf284f4fd37ad8fbe/resources/uploads/uploads.ts#L66-L75 | 28ffdaa2c107c98db5eec50cf284f4fd37ad8fbe |
explorer-kit | github_2023 | solana-fm | typescript | patchIdlByAppending | const patchIdlByAppending = (patch: Patch, idl?: AnchorIdl | ShankIdl | string) => {
if (idl) {
if (!checkIdlIsString(idl)) {
if (patch.type === PatchType.APPEND) {
const idlToReturn = Object.assign({}, idl);
const keysToAppend = Object.keys(patch.patch);
keysToAppend.forEach((key) ... | // TODO: Remember to check for the slots deployed when patching the IDL. | https://github.com/solana-fm/explorer-kit/blob/0b67fd478284659cdf46d0f9d34715ec45d6dc62/packages/explorerkit-idls/src/idls-patcher/patcher.ts#L40-L63 | 0b67fd478284659cdf46d0f9d34715ec45d6dc62 |
explorer-kit | github_2023 | solana-fm | typescript | SolanaFMParser.constructor | constructor(idl: IdlItem, programHash: string, accountHash?: string) {
this.idlItem = idl;
this.programHash = programHash;
this.accountHash = accountHash;
} | /**
* Creates a new instance of the FMClient class.
* @param idl The IDL that's to be used for initalizing the client.
* @param programHash The program hash.
* @param accountHash The account hash.
*/ | https://github.com/solana-fm/explorer-kit/blob/0b67fd478284659cdf46d0f9d34715ec45d6dc62/packages/explorerkit-translator/src/SolanaFMParser.ts#L45-L49 | 0b67fd478284659cdf46d0f9d34715ec45d6dc62 |
explorer-kit | github_2023 | solana-fm | typescript | SolanaFMParser.createParser | public createParser(parserType: ParserType): Parser {
switch (parserType) {
case ParserType.ACCOUNT:
return createAccountParser(this.idlItem, this.programHash, this.accountHash);
case ParserType.INSTRUCTION:
return createInstructionParser(this.idlItem, this.programHash);
case Par... | /**
* Creates a parser based on the specified parser type.
* @param parserType The parser type.
* @returns A parser instance.
*/ | https://github.com/solana-fm/explorer-kit/blob/0b67fd478284659cdf46d0f9d34715ec45d6dc62/packages/explorerkit-translator/src/SolanaFMParser.ts#L56-L73 | 0b67fd478284659cdf46d0f9d34715ec45d6dc62 |
explorer-kit | github_2023 | solana-fm | typescript | SolanaFMParser.getProgramHash | public getProgramHash(): string {
return this.programHash;
} | /**
* Gets the program hash.
* @returns The program hash.
*/ | https://github.com/solana-fm/explorer-kit/blob/0b67fd478284659cdf46d0f9d34715ec45d6dc62/packages/explorerkit-translator/src/SolanaFMParser.ts#L79-L81 | 0b67fd478284659cdf46d0f9d34715ec45d6dc62 |
explorer-kit | github_2023 | solana-fm | typescript | KinobiTreeGenerator.constructLayout | public constructLayout(
treeGeneratorType: KinobiTreeGeneratorType = KinobiTreeGeneratorType.INSTRUCTIONS,
interfaceDiscriminantMode: boolean = false,
interfacePrefixString?: string
): Map<number | string, FMShankSerializer> {
return this._constructLayout(treeGeneratorType, interfaceDiscriminantMode, ... | /**
* Constructs a map with the discriminant as the key and the serializer as the value for a single shank-generated IDL
* @param treeGeneratorType - The type of tree generator to construct
* @param interfaceDiscriminantMode - Uses 8-bytes discriminant for the map key name if true, otherwise uses the discrimin... | https://github.com/solana-fm/explorer-kit/blob/0b67fd478284659cdf46d0f9d34715ec45d6dc62/packages/explorerkit-translator/src/helpers/KinobiTreeGenerator.ts#L153-L159 | 0b67fd478284659cdf46d0f9d34715ec45d6dc62 |
explorer-kit | github_2023 | solana-fm | typescript | sanitySerializeMetadataAccount | const sanitySerializeMetadataAccount = (
accountDataBuffer: Buffer,
accountSerializer: FMShankSerializer,
idl: ShankIdl
) => {
try {
// Tries to Deserialize the account
const decodedAccountData = accountSerializer.serializer?.deserialize(accountDataBuffer);
if (decodedAccountData && decodedAccountD... | // Source: https://github.com/metaplex-foundation/metaplex-program-library/blob/master/token-metadata/js/src/custom/metadata-deserializer.ts | https://github.com/solana-fm/explorer-kit/blob/0b67fd478284659cdf46d0f9d34715ec45d6dc62/packages/explorerkit-translator/src/parsers/v2/account/metadata.ts#L93-L227 | 0b67fd478284659cdf46d0f9d34715ec45d6dc62 |
explorer-kit | github_2023 | solana-fm | typescript | serializeExtension | const serializeExtension = (
extensionIDL: Idl,
dataBuffer: Uint8Array,
mapTypes?: boolean,
accountKeys?: string[]
): ExtensionTypes | null => {
const extensionSerializerLayout = new KinobiTreeGenerator(extensionIDL).constructLayout();
const extensionIxDiscriminant = Buffer.from(dataBuffer).re... | /**
* Default Token 2022 Extension Serializer
* @param {Idl} extensionIDL - The IDL of the transfer fee extension
* @param {Uint8Array} dataBuffer - The data buffer containing the extension instruction data.
* @param {boolean} [mapTypes=false] - Whether to map the data types to their names.
* @param {str... | https://github.com/solana-fm/explorer-kit/blob/0b67fd478284659cdf46d0f9d34715ec45d6dc62/packages/explorerkit-translator/src/parsers/v2/instruction/token-v2.ts#L369-L416 | 0b67fd478284659cdf46d0f9d34715ec45d6dc62 |
ts-chan | github_2023 | joeycumines | typescript | CircularBuffer.empty | get empty(): boolean {
return this.size === 0;
} | // True if the buffer is empty. | https://github.com/joeycumines/ts-chan/blob/ab43685af09431c1ca391a11c27e44641f3f139e/src/buffer.ts#L18-L20 | ab43685af09431c1ca391a11c27e44641f3f139e |
ts-chan | github_2023 | joeycumines | typescript | CircularBuffer.full | get full(): boolean {
return this.size === this.capacity;
} | // True if the buffer is full. | https://github.com/joeycumines/ts-chan/blob/ab43685af09431c1ca391a11c27e44641f3f139e/src/buffer.ts#L23-L25 | ab43685af09431c1ca391a11c27e44641f3f139e |
ts-chan | github_2023 | joeycumines | typescript | CircularBuffer.length | get length(): number {
return this.size;
} | // The number of elements in the buffer. | https://github.com/joeycumines/ts-chan/blob/ab43685af09431c1ca391a11c27e44641f3f139e/src/buffer.ts#L28-L30 | ab43685af09431c1ca391a11c27e44641f3f139e |
ts-chan | github_2023 | joeycumines | typescript | CircularBuffer.push | push(item: T): void {
if (this.size >= this.capacity) {
throw new Error('ts-chan: buffer full');
}
this.buffer[this.tail] = item;
this.tail = (this.tail + 1) % this.capacity;
this.size++;
} | // Adds an item to the buffer. Throws an error if full. | https://github.com/joeycumines/ts-chan/blob/ab43685af09431c1ca391a11c27e44641f3f139e/src/buffer.ts#L33-L40 | ab43685af09431c1ca391a11c27e44641f3f139e |
ts-chan | github_2023 | joeycumines | typescript | CircularBuffer.shift | shift(): T | undefined {
if (this.empty) {
return undefined;
}
const item = this.buffer[this.head];
this.buffer[this.head] = undefined!;
this.head = (this.head + 1) % this.capacity;
this.size--;
return item;
} | // Removes and returns the oldest item from the buffer, or undefined (empty). | https://github.com/joeycumines/ts-chan/blob/ab43685af09431c1ca391a11c27e44641f3f139e/src/buffer.ts#L43-L52 | ab43685af09431c1ca391a11c27e44641f3f139e |
ts-chan | github_2023 | joeycumines | typescript | CircularBuffer.peek | peek(): T | undefined {
if (this.empty) {
return undefined;
}
return this.buffer[this.head];
} | // Returns the oldest item without removing it, or undefined if empty. | https://github.com/joeycumines/ts-chan/blob/ab43685af09431c1ca391a11c27e44641f3f139e/src/buffer.ts#L55-L60 | ab43685af09431c1ca391a11c27e44641f3f139e |
ts-chan | github_2023 | joeycumines | typescript | CircularBuffer.reset | reset(): void {
this.head = 0;
this.tail = 0;
this.size = 0;
} | // WARNING: Use with caution - prefer the `clear` method if GC is a concern. | https://github.com/joeycumines/ts-chan/blob/ab43685af09431c1ca391a11c27e44641f3f139e/src/buffer.ts#L64-L68 | ab43685af09431c1ca391a11c27e44641f3f139e |
ts-chan | github_2023 | joeycumines | typescript | CircularBuffer.clear | clear() {
while (!this.empty) {
this.shift();
}
this.reset();
} | // Clears the buffer and removes references to all items. | https://github.com/joeycumines/ts-chan/blob/ab43685af09431c1ca391a11c27e44641f3f139e/src/buffer.ts#L71-L76 | ab43685af09431c1ca391a11c27e44641f3f139e |
ts-chan | github_2023 | joeycumines | typescript | Chan.capacity | get capacity(): number {
if (this.#buffer === undefined) {
return 0;
}
return this.#buffer.capacity;
} | /**
* Returns the maximum number of items the channel can buffer.
*/ | https://github.com/joeycumines/ts-chan/blob/ab43685af09431c1ca391a11c27e44641f3f139e/src/chan.ts#L74-L79 | ab43685af09431c1ca391a11c27e44641f3f139e |
ts-chan | github_2023 | joeycumines | typescript | Chan.length | get length(): number {
if (this.#buffer === undefined) {
return 0;
}
return this.#buffer.length;
} | /**
* Returns the number of items in the channel buffer.
*/ | https://github.com/joeycumines/ts-chan/blob/ab43685af09431c1ca391a11c27e44641f3f139e/src/chan.ts#L84-L89 | ab43685af09431c1ca391a11c27e44641f3f139e |
ts-chan | github_2023 | joeycumines | typescript | Chan.concurrency | get concurrency(): number {
return this.#sends.length - this.#recvs.length;
} | /**
* Returns an integer representing the number of blocking operations.
* Positive values indicate senders, while negative values indicate
* receivers.
*/ | https://github.com/joeycumines/ts-chan/blob/ab43685af09431c1ca391a11c27e44641f3f139e/src/chan.ts#L96-L98 | ab43685af09431c1ca391a11c27e44641f3f139e |
ts-chan | github_2023 | joeycumines | typescript | Chan.setUnsafe | setUnsafe(unsafe: boolean): this {
this.unsafe = unsafe;
return this;
} | /**
* Sets the {@link .unsafe} property, and returns this.
*/ | https://github.com/joeycumines/ts-chan/blob/ab43685af09431c1ca391a11c27e44641f3f139e/src/chan.ts#L103-L106 | ab43685af09431c1ca391a11c27e44641f3f139e |
ts-chan | github_2023 | joeycumines | typescript | Chan.trySend | trySend(value: T): boolean {
if (!this.#open) {
throw new SendOnClosedChannelError();
}
if (this.#recvs.length !== 0) {
const recv = this.#recvs.shift()!;
recv(value, true);
return true;
}
this.#fillBuffer();
if (this.#buffer !== undefined && !this.#buffer.full) {
t... | /**
* Performs a synchronous send operation on the channel, returning true if
* it succeeds, or false if there are no waiting receivers, and the channel
* is full.
*
* Will throw {@link SendOnClosedChannelError} if the channel is closed.
*/ | https://github.com/joeycumines/ts-chan/blob/ab43685af09431c1ca391a11c27e44641f3f139e/src/chan.ts#L115-L130 | ab43685af09431c1ca391a11c27e44641f3f139e |
ts-chan | github_2023 | joeycumines | typescript | Chan.send | async send(value: T, abort?: AbortSignal): Promise<void> {
abort?.throwIfAborted();
let yieldGeneration: number | undefined;
let yieldPromise: Promise<number> | undefined;
if (!this.unsafe) {
yieldGeneration = getYieldGeneration();
yieldPromise = yieldToMacrotaskQueue();
}
try {
... | /**
* Sends a value to the channel, returning a promise that resolves when it
* has been received, and rejects on error, or on abort signal.
*/ | https://github.com/joeycumines/ts-chan/blob/ab43685af09431c1ca391a11c27e44641f3f139e/src/chan.ts#L136-L195 | ab43685af09431c1ca391a11c27e44641f3f139e |
ts-chan | github_2023 | joeycumines | typescript | Chan.tryRecv | tryRecv(): IteratorResult<T, T | undefined> | undefined {
this.#fillBuffer();
if (this.#buffer !== undefined && !this.#buffer.empty) {
const result = this.#buffer.shift()!;
this.#fillBuffer();
return {value: result};
}
if (this.#sends.length !== 0) {
const callback = this.#sends.... | /**
* Like {@link trySend}, this performs a synchronous recv operation on the
* channel, returning undefined if no value is available, or an iterator
* result, which models the received value, and whether the channel is open.
*/ | https://github.com/joeycumines/ts-chan/blob/ab43685af09431c1ca391a11c27e44641f3f139e/src/chan.ts#L202-L220 | ab43685af09431c1ca391a11c27e44641f3f139e |
ts-chan | github_2023 | joeycumines | typescript | Chan.recv | async recv(abort?: AbortSignal): Promise<IteratorResult<T, T | undefined>> {
abort?.throwIfAborted();
let yieldGeneration: number | undefined;
let yieldPromise: Promise<number> | undefined;
if (!this.unsafe) {
yieldGeneration = getYieldGeneration();
yieldPromise = yieldToMacrotaskQueue();
... | /**
* Receives a value from the channel, returning a promise that resolves with
* an iterator (the value OR indicator that the channel is closed, possibly
* with a default value), or rejects on error, or on abort signal.
*/ | https://github.com/joeycumines/ts-chan/blob/ab43685af09431c1ca391a11c27e44641f3f139e/src/chan.ts#L227-L294 | ab43685af09431c1ca391a11c27e44641f3f139e |
ts-chan | github_2023 | joeycumines | typescript | Chan.close | close(): void {
if (!this.#open) {
throw new CloseOfClosedChannelError();
}
this.#open = false;
let lastError: unknown;
if (this.#recvs.length !== 0) {
for (let i = 0; i < this.#recvs.length; i++) {
const callback = this.#recvs[i];
this.#recvs[i] = undefined!;
... | /**
* Closes the channel, preventing further sending of values.
*
* See also {@link Sender} and {@link Sender.close}, which this implements.
*
* - Once a channel is closed, no more values can be sent to it.
* - If the channel is buffered and there are still values in the buffer when
* the channel... | https://github.com/joeycumines/ts-chan/blob/ab43685af09431c1ca391a11c27e44641f3f139e/src/chan.ts#L354-L418 | ab43685af09431c1ca391a11c27e44641f3f139e |
ts-chan | github_2023 | joeycumines | typescript | ChanIterator.next | next(): IteratorResult<T> {
switch (this.#outcome) {
case undefined: {
const result = this.#chan.tryRecv();
if (result !== undefined) {
return result;
}
// note: not necessarily a permanent condition
return {done: true, value: undefined};
}
case 'R... | /**
* Next iteration.
*/ | https://github.com/joeycumines/ts-chan/blob/ab43685af09431c1ca391a11c27e44641f3f139e/src/chan.ts#L494-L509 | ab43685af09431c1ca391a11c27e44641f3f139e |
ts-chan | github_2023 | joeycumines | typescript | ChanIterator.return | return(): IteratorResult<T> {
if (this.#outcome === undefined) {
this.#outcome = 'Return';
}
return {done: true, value: undefined};
} | /**
* Ends the iterator, which is an idempotent operation.
*/ | https://github.com/joeycumines/ts-chan/blob/ab43685af09431c1ca391a11c27e44641f3f139e/src/chan.ts#L514-L519 | ab43685af09431c1ca391a11c27e44641f3f139e |
ts-chan | github_2023 | joeycumines | typescript | ChanIterator.throw | throw(e?: unknown): IteratorResult<T> {
if (this.#outcome === undefined) {
this.#outcome = 'Throw';
this.#error = e;
}
return {done: true, value: undefined};
} | /**
* Ends the iterator with an error, which is an idempotent operation.
*/ | https://github.com/joeycumines/ts-chan/blob/ab43685af09431c1ca391a11c27e44641f3f139e/src/chan.ts#L524-L530 | ab43685af09431c1ca391a11c27e44641f3f139e |
ts-chan | github_2023 | joeycumines | typescript | ChanAsyncIterator.next | async next(): Promise<IteratorResult<T>> {
try {
return await this.#chan.recv(this.#abort.signal);
} catch (e) {
if (e === chanAsyncIteratorReturned) {
return {done: true, value: undefined};
}
throw e;
}
} | /**
* Next iteration.
*/ | https://github.com/joeycumines/ts-chan/blob/ab43685af09431c1ca391a11c27e44641f3f139e/src/chan.ts#L563-L572 | ab43685af09431c1ca391a11c27e44641f3f139e |
ts-chan | github_2023 | joeycumines | typescript | ChanAsyncIterator.return | async return(): Promise<IteratorResult<T>> {
this.#abort.abort(chanAsyncIteratorReturned);
return {done: true, value: undefined};
} | /**
* Ends the iterator, which is an idempotent operation.
*/ | https://github.com/joeycumines/ts-chan/blob/ab43685af09431c1ca391a11c27e44641f3f139e/src/chan.ts#L577-L580 | ab43685af09431c1ca391a11c27e44641f3f139e |
ts-chan | github_2023 | joeycumines | typescript | ChanAsyncIterator.throw | async throw(e?: unknown): Promise<IteratorResult<T>> {
this.#abort.abort(e);
return {done: true, value: undefined};
} | /**
* Ends the iterator with an error, which is an idempotent operation.
*/ | https://github.com/joeycumines/ts-chan/blob/ab43685af09431c1ca391a11c27e44641f3f139e/src/chan.ts#L585-L588 | ab43685af09431c1ca391a11c27e44641f3f139e |
ts-chan | github_2023 | joeycumines | typescript | SelectFactory.clear | clear() {
this.#values.clear();
if (this.#select !== undefined) {
for (const c of this.#select.cases) {
const s = c[selectState];
if (s.send instanceof SenderProxy) {
s.send[proxyKey] = undefined;
} else if (s.recv instanceof ReceiverProxy) {
s.recv[proxyKey] = ... | /**
* Clears references to values to send, receives and senders, but not the
* select cases themselves. Use cases include avoiding retaining references
* between iterations of a loop, if such references are not needed, or may
* be problematic.
*
* WARNING: Must not be called concurrently with {@link S... | https://github.com/joeycumines/ts-chan/blob/ab43685af09431c1ca391a11c27e44641f3f139e/src/select-factory.ts#L54-L70 | ab43685af09431c1ca391a11c27e44641f3f139e |
ts-chan | github_2023 | joeycumines | typescript | SelectFactory.with | with<T extends readonly SelectFactoryCase<any>[] | []>(
cases: T
): Select<
{
readonly [K in keyof T]: T[K] extends SelectFactoryCaseSender<infer U>
? SelectCaseSender<U>
: T[K] extends SelectFactoryCaseReceiver<infer U>
? SelectCaseReceiver<U>
: T[K] extends SelectFa... | /**
* With should be to configure and retrieve (or initialize) the underlying
* {@link Select} instance.
*
* Must be called with the same number of cases each time, with each case
* having the same direction.
*/ | https://github.com/joeycumines/ts-chan/blob/ab43685af09431c1ca391a11c27e44641f3f139e/src/select-factory.ts#L79-L141 | ab43685af09431c1ca391a11c27e44641f3f139e |
ts-chan | github_2023 | joeycumines | typescript | Select.promises | static promises<
T extends readonly (SelectCase<any> | PromiseLike<any>)[] | [],
>(
cases: T
): Select<
{
readonly [K in keyof T]: T[K] extends SelectCaseSender<infer U>
? SelectCaseSender<U>
: T[K] extends SelectCaseReceiver<infer U>
? SelectCaseReceiver<U>
: T... | /**
* Promises is a convenience method for creating a select instance with
* promise cases, or a mix of both promises and other cases.
*
* Note that the behavior is identical to passing the same array to the
* constructor. The constructor's typing is more strict, to simplify
* implementations which en... | https://github.com/joeycumines/ts-chan/blob/ab43685af09431c1ca391a11c27e44641f3f139e/src/select.ts#L101-L123 | ab43685af09431c1ca391a11c27e44641f3f139e |
ts-chan | github_2023 | joeycumines | typescript | Select.cases | get cases(): {
readonly [K in keyof T]: T[K];
} {
return this.#cases;
} | /**
* Retrieves the cases associated with this select instance.
*
* Each case corresponds to an input case (including order).
* After selecting a case, via {@link Select.poll} or {@link Select.wait},
* received values may be retrieved by calling {@link Select.recv} with the
* corresponding case.
*
... | https://github.com/joeycumines/ts-chan/blob/ab43685af09431c1ca391a11c27e44641f3f139e/src/select.ts#L173-L177 | ab43685af09431c1ca391a11c27e44641f3f139e |
ts-chan | github_2023 | joeycumines | typescript | Select.length | get length(): number {
return this.#pending.length;
} | /**
* Retrieves the number of the cases that are currently pending.
*
* Will return the length of {@link cases}, less the number of _promise_
* cases that have been resolved and received (or ignored).
*/ | https://github.com/joeycumines/ts-chan/blob/ab43685af09431c1ca391a11c27e44641f3f139e/src/select.ts#L185-L187 | ab43685af09431c1ca391a11c27e44641f3f139e |
ts-chan | github_2023 | joeycumines | typescript | Select.pending | get pending(): Array<
T[number] extends SelectCasePromise<infer U>
? Exclude<SelectCasePromise<U>[typeof selectState]['pval'], undefined>
: never
> {
const pending: any[] = [];
// so they're in case order
for (const c of this.#cases) {
// note: cleared on consume
if (c[selectSt... | /**
* Returns all the original values of all pending promise cases (cases that
* haven't been consumed or ignored), in case order.
*/ | https://github.com/joeycumines/ts-chan/blob/ab43685af09431c1ca391a11c27e44641f3f139e/src/select.ts#L193-L207 | ab43685af09431c1ca391a11c27e44641f3f139e |
ts-chan | github_2023 | joeycumines | typescript | Select.setUnsafe | setUnsafe(unsafe: boolean): this {
this.unsafe = unsafe;
return this;
} | /**
* Sets the {@link .unsafe} property, and returns this.
*/ | https://github.com/joeycumines/ts-chan/blob/ab43685af09431c1ca391a11c27e44641f3f139e/src/select.ts#L212-L215 | ab43685af09431c1ca391a11c27e44641f3f139e |
ts-chan | github_2023 | joeycumines | typescript | Select.poll | poll(): number | undefined {
this.#throwIfInUse();
// sanity check - stop should always have been called
if (this.#semaphore.token !== undefined) {
throw new Error(
'ts-chan: select: poll: unexpected error that should never happen: stop token not cleared'
);
}
// consume the la... | /**
* Poll returns the next case that is ready, or undefined if none are
* ready. It must not be called concurrently with {@link Select.wait} or
* {@link Select.recv}.
*
* This is effectively a non-blocking version of {@link Select.wait}, and
* fills the same role as the `default` select case, in Go's... | https://github.com/joeycumines/ts-chan/blob/ab43685af09431c1ca391a11c27e44641f3f139e/src/select.ts#L226-L303 | ab43685af09431c1ca391a11c27e44641f3f139e |
ts-chan | github_2023 | joeycumines | typescript | Select.wait | async wait(abort?: AbortSignal): Promise<number> {
abort?.throwIfAborted();
let yieldGeneration: number | undefined;
let yieldPromise: Promise<number> | undefined;
if (!this.unsafe) {
yieldGeneration = getYieldGeneration();
yieldPromise = yieldToMacrotaskQueue();
}
try {
// ne... | /**
* Wait returns a promise that will resolve with the index of the next case
* that is ready, or reject with the first error.
*/ | https://github.com/joeycumines/ts-chan/blob/ab43685af09431c1ca391a11c27e44641f3f139e/src/select.ts#L309-L417 | ab43685af09431c1ca391a11c27e44641f3f139e |
ts-chan | github_2023 | joeycumines | typescript | Select.recv | recv<T>(v: SelectCase<T>): IteratorResult<T, T | undefined> {
this.#throwIfInUse();
if (
v?.[selectState]?.cidx === undefined ||
this.#cases[v[selectState].cidx] !== v
) {
throw new Error('ts-chan: select: case not found');
}
let result:
| (IteratorResult<T, T | undefined> ... | /**
* Consume the result of a ready case.
*/ | https://github.com/joeycumines/ts-chan/blob/ab43685af09431c1ca391a11c27e44641f3f139e/src/select.ts#L422-L493 | ab43685af09431c1ca391a11c27e44641f3f139e |
ts-chan | github_2023 | joeycumines | typescript | mapPendingValues | const mapPendingValues = <T extends readonly SelectCase<any>[] | []>(
cases: T,
stop: Exclude<typeof stopForMapPendingValue, undefined>,
selectSemaphore: Exclude<typeof selectSemaphoreForMapPendingValue, undefined>
): T => {
if (
stopForMapPendingValue !== undefined ||
selectSemaphoreForMapPendingValue ... | // Converts any non-cases to the promise variant, returns a new array. | https://github.com/joeycumines/ts-chan/blob/ab43685af09431c1ca391a11c27e44641f3f139e/src/select.ts#L566-L587 | ab43685af09431c1ca391a11c27e44641f3f139e |
ts-chan | github_2023 | joeycumines | typescript | mapPendingValue | const mapPendingValue = <T extends SelectCase<any>>(v: T, i: number): T => {
if (
stopForMapPendingValue === undefined ||
selectSemaphoreForMapPendingValue === undefined
) {
throw new Error(
'ts-chan: select: unexpected error that should never happen: stop vars not set'
);
}
const stop = s... | // Part of the implementation of {@link mapPendingValues}, should never be | https://github.com/joeycumines/ts-chan/blob/ab43685af09431c1ca391a11c27e44641f3f139e/src/select.ts#L591-L794 | ab43685af09431c1ca391a11c27e44641f3f139e |
ts-chan | github_2023 | joeycumines | typescript | shuffleArray | function shuffleArray<T>(array: T[]): T[] {
for (let i = array.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[array[i], array[j]] = [array[j], array[i]];
}
return array;
} | // Helper function: Fisher-Yates Shuffle algorithm | https://github.com/joeycumines/ts-chan/blob/ab43685af09431c1ca391a11c27e44641f3f139e/test/select.test.ts#L467-L473 | ab43685af09431c1ca391a11c27e44641f3f139e |
nuxt-auth-utils | github_2023 | atinux | typescript | createUserValidationError | function createUserValidationError(validateError?: any) {
throw createError({
status: validateError?.statusCode || 400,
message: validateError?.message || 'User Validation Error',
data: validateError,
})
} | // eslint-disable-next-line @typescript-eslint/no-explicit-any | https://github.com/atinux/nuxt-auth-utils/blob/05db8f05352c544c2b00514e6b83239f8d9dde98/src/runtime/server/lib/webauthn/register.ts#L140-L146 | 05db8f05352c544c2b00514e6b83239f8d9dde98 |
serverless-registry | github_2023 | cloudflare | typescript | pushLayer | async function pushLayer(layerDigest: string, readableStream: ReadableStream, totalLayerSize: number) {
const headers = new Headers({
authorization: cred,
});
const layerExistsURL = `${proto}://${imageHost}/v2${imageRepositoryPath}/blobs/${layerDigest}`;
const layerExistsResponse = await fetch(layerExistsUR... | // pushLayer accepts the target digest, the stream to read from, and the total layer size. | https://github.com/cloudflare/serverless-registry/blob/e92b4c9d072c7170550db804941cb28294af010d/push/index.ts#L219-L323 | e92b4c9d072c7170550db804941cb28294af010d |
serverless-registry | github_2023 | cloudflare | typescript | RegistryTokens.createPrivateAndPublicKey | static async createPrivateAndPublicKey(): Promise<[string, string]> {
const key = (await crypto.subtle.generateKey({ name: "ECDSA", namedCurve: "P-256" }, true, [
"sign",
"verify",
])) as CryptoKeyPair;
const exportedPrivateKey = btoa(JSON.stringify(await crypto.subtle.exportKey("jwk", key.priva... | /**
* Very util function that showcases how do we generate private and public keys
*
* @example
* // Sample usage:
* try {
* const [privateKey, publicKey] = await RegistryTokens.createPrivateAndPublicKey();
* const registryTokens = await newRegistryTokens(publicKey);
* const... | https://github.com/cloudflare/serverless-registry/blob/e92b4c9d072c7170550db804941cb28294af010d/src/token.ts#L43-L51 | e92b4c9d072c7170550db804941cb28294af010d |
serverless-registry | github_2023 | cloudflare | typescript | GarbageCollector.markForInsertion | async markForInsertion(namespace: string): Promise<string> {
const uid = crypto.randomUUID();
// mark that there is an on-going insertion
const deletion = await this.registry.put(`${namespace}/insertion/${uid}`, uid);
if (deletion === null) throw new Error("unreachable");
// set last_update so GC is... | // to start inserting data that might conflight with GC. | https://github.com/cloudflare/serverless-registry/blob/e92b4c9d072c7170550db804941cb28294af010d/src/registry/garbage-collector.ts#L92-L103 | e92b4c9d072c7170550db804941cb28294af010d |
serverless-registry | github_2023 | cloudflare | typescript | appendStreamKnownLength | const appendStreamKnownLength = async (stream: ReadableStream, size: number) => {
// This is the normal code-path, hopefully by hinting with headers on the POST call all clients respect this
if (
(state.chunks.length === 0 ||
(state.chunks[state.chunks.length - 1].size === size &&
... | // This function tries to handle the following cases: | https://github.com/cloudflare/serverless-registry/blob/e92b4c9d072c7170550db804941cb28294af010d/src/registry/r2.ts#L517-L620 | e92b4c9d072c7170550db804941cb28294af010d |
amica | github_2023 | semperai | typescript | AmicaLife.loadIdleTextPrompt | public async loadIdleTextPrompt(prompts: string[] | null) {
if (prompts === null) {
idleEvents.forEach((prompt) =>
this.mainEvents.enqueue({ events: prompt }),
);
} else {
if (prompts.length > 0) {
this.mainEvents.clear();
prompts.forEach((prompt: string) =>
b... | // Function for loaded idle text prompt | https://github.com/semperai/amica/blob/c5829dd25a4ad93cc26bc01b4c8520fd3ef51916/src/features/amicaLife/amicaLife.ts#L69-L82 | c5829dd25a4ad93cc26bc01b4c8520fd3ef51916 |
amica | github_2023 | semperai | typescript | AmicaLife.insertFront | public insertFront(event: AmicaLifeEvents) {
const newQueue = new Queue<AmicaLifeEvents>();
newQueue.enqueue(event);
while (!this.mainEvents.isEmpty()) {
newQueue.enqueue(this.mainEvents.dequeue()!);
}
this.mainEvents = newQueue;
} | // Function to insert event to the front of the mainEvents Queue | https://github.com/semperai/amica/blob/c5829dd25a4ad93cc26bc01b4c8520fd3ef51916/src/features/amicaLife/amicaLife.ts#L85-L94 | c5829dd25a4ad93cc26bc01b4c8520fd3ef51916 |
amica | github_2023 | semperai | typescript | AmicaLife.removeEvent | public removeEvent(eventName: string) {
const newQueue = new Queue<AmicaLifeEvents>();
let found = false;
while (!this.mainEvents.isEmpty()) {
const event = this.mainEvents.dequeue();
if (event && event.events !== eventName) {
newQueue.enqueue(event);
} else {
found = true... | // Function to remove a specific event from the mainEvents queue | https://github.com/semperai/amica/blob/c5829dd25a4ad93cc26bc01b4c8520fd3ef51916/src/features/amicaLife/amicaLife.ts#L97-L111 | c5829dd25a4ad93cc26bc01b4c8520fd3ef51916 |
amica | github_2023 | semperai | typescript | AmicaLife.containsEvent | public containsEvent(eventName: string): boolean {
let contains = false;
this.mainEvents.forEach((event) => {
if (event.events === eventName) {
contains = true;
}
});
return contains;
} | // Function to check if a specific event exists in the mainEvents queue | https://github.com/semperai/amica/blob/c5829dd25a4ad93cc26bc01b4c8520fd3ef51916/src/features/amicaLife/amicaLife.ts#L114-L124 | c5829dd25a4ad93cc26bc01b4c8520fd3ef51916 |
amica | github_2023 | semperai | typescript | AmicaLife.receiveMessageFromUser | public receiveMessageFromUser(message: string) {
if (message.toLowerCase().includes('news')) {
console.log("Triggering news function call.");
this.insertFront({events: "News"});
}
// Re-enqueue subconcious event after get the user input (1 Subconcious events per idle cycle)
(!this.containsE... | // Function to check message from user | https://github.com/semperai/amica/blob/c5829dd25a4ad93cc26bc01b4c8520fd3ef51916/src/features/amicaLife/amicaLife.ts#L129-L141 | c5829dd25a4ad93cc26bc01b4c8520fd3ef51916 |
amica | github_2023 | semperai | typescript | AmicaLife.processingIdle | public async processingIdle() {
// Preventing duplicate processingIdle loop
if (this.isProcessingIdleRunning) { return; }
this.isProcessingIdleRunning = true;
console.log("Starting Amica Life");
while (config("amica_life_enabled") === "true") {
// Check if amica is in idle state trigger proc... | // } | https://github.com/semperai/amica/blob/c5829dd25a4ad93cc26bc01b4c8520fd3ef51916/src/features/amicaLife/amicaLife.ts#L152-L171 | c5829dd25a4ad93cc26bc01b4c8520fd3ef51916 |
amica | github_2023 | semperai | typescript | AmicaLife.checkSleep | private async checkSleep() {
if (!this.isSleep) {
const chat = this.chat;
if (!chat) {
console.error("Chat instance is not available");
return;
}
const idleTime = chat.idleTime();
// If character being idle morethan 120 sec or 2 min, play handle sleep event
if (!t... | // Function to check for sleep event if idleTime > time_to_sleep add Sleep event to the front of amica queue | https://github.com/semperai/amica/blob/c5829dd25a4ad93cc26bc01b4c8520fd3ef51916/src/features/amicaLife/amicaLife.ts#L243-L258 | c5829dd25a4ad93cc26bc01b4c8520fd3ef51916 |
amica | github_2023 | semperai | typescript | AmicaLife.checkPause | private async checkPause() {
if (this.isPause) {
console.log("Amica Life Paused");
await new Promise<void>((resolve) => {
const checkPause = setInterval(() => {
if (!this.isPause) {
clearInterval(checkPause);
resolve(console.log("Amica Life Initiated"));
... | // Function to pause the processingEvent loop is pauseFlag is true/false | https://github.com/semperai/amica/blob/c5829dd25a4ad93cc26bc01b4c8520fd3ef51916/src/features/amicaLife/amicaLife.ts#L261-L273 | c5829dd25a4ad93cc26bc01b4c8520fd3ef51916 |
amica | github_2023 | semperai | typescript | AmicaLife.checkResume | private async checkResume(): Promise<boolean> {
if (this.isPause === true && !this.isSleep && this.isSettingOff) {
this.resume();
return true;
}
return false;
} | // Function to resume the processingEvent loop from pause | https://github.com/semperai/amica/blob/c5829dd25a4ad93cc26bc01b4c8520fd3ef51916/src/features/amicaLife/amicaLife.ts#L276-L282 | c5829dd25a4ad93cc26bc01b4c8520fd3ef51916 |
amica | github_2023 | semperai | typescript | AmicaLife.checkSettingOff | public checkSettingOff(off: boolean) {
if (off) {
this.isSettingOff = true;
this.wakeFromSleep();
this.chat?.updateAwake(); // Update awake when user exit the setting page
this.resume();
} else {
this.isSettingOff = false;
this.pause();
}
} | // Function to pause/resume the loop when setting page is open/close | https://github.com/semperai/amica/blob/c5829dd25a4ad93cc26bc01b4c8520fd3ef51916/src/features/amicaLife/amicaLife.ts#L285-L295 | c5829dd25a4ad93cc26bc01b4c8520fd3ef51916 |
amica | github_2023 | semperai | typescript | AmicaLife.updatedIdleTime | public updatedIdleTime() {
const idleTimeSec = Math.min(
parseInt(config("time_before_idle_sec")) * 1.25,
240,
);
// updateConfig("time_before_idle_sec", idleTimeSec.toString());
// removed for staging
//console.log(`Updated time before idle to ${idleTimeSec} seconds`);
} | // Update time before idle increase by 1.25 times | https://github.com/semperai/amica/blob/c5829dd25a4ad93cc26bc01b4c8520fd3ef51916/src/features/amicaLife/amicaLife.ts#L300-L308 | c5829dd25a4ad93cc26bc01b4c8520fd3ef51916 |
amica | github_2023 | semperai | typescript | handleVRMAnimationEvent | async function handleVRMAnimationEvent(viewer: Viewer, amicaLife: AmicaLife) {
let randomAnimation;
do {
randomAnimation = animationList[Math.floor(Math.random() * animationList.length)];
} while (basename(randomAnimation) === previousAnimation);
// Store the current animation as the previous one for the n... | // Handles the VRM animation event. | https://github.com/semperai/amica/blob/c5829dd25a4ad93cc26bc01b4c8520fd3ef51916/src/features/amicaLife/eventHandler.ts#L55-L85 | c5829dd25a4ad93cc26bc01b4c8520fd3ef51916 |
amica | github_2023 | semperai | typescript | handleTextEvent | async function handleTextEvent(chat: Chat, amicaLife: AmicaLife) {
// Randomly select the idle text prompts
const randomIndex = Math.floor(
Math.random() * basedPrompt.idleTextPrompt.length,
);
const randomTextPrompt = basedPrompt.idleTextPrompt[randomIndex];
// removed for staging logs.
//console.log("... | // Handles text-based idle events. | https://github.com/semperai/amica/blob/c5829dd25a4ad93cc26bc01b4c8520fd3ef51916/src/features/amicaLife/eventHandler.ts#L89-L107 | c5829dd25a4ad93cc26bc01b4c8520fd3ef51916 |
amica | github_2023 | semperai | typescript | Chat.receiveMessageFromUser | public async receiveMessageFromUser(message: string, amicaLife: boolean) {
if (message === null || message === "") {
return;
}
console.time("performance_interrupting");
console.debug("interrupting...");
await this.interrupt();
console.timeEnd("performance_interrupting");
await wait(0)... | // this happens either from text or from voice / whisper completion | https://github.com/semperai/amica/blob/c5829dd25a4ad93cc26bc01b4c8520fd3ef51916/src/features/chat/chat.ts#L348-L382 | c5829dd25a4ad93cc26bc01b4c8520fd3ef51916 |
amica | github_2023 | semperai | typescript | getExtra | async function getExtra(messages: Message[]) {
const headers: Record<string, string> = {
"Content-Type": "application/json",
};
const prompt = buildPrompt(messages);
const stop_sequence: string[] = [`${config("name")}:`, ...`${config("koboldai_stop_sequence")}`.split("||")];
const res = await fetch(`${co... | // koboldcpp / stream support | https://github.com/semperai/amica/blob/c5829dd25a4ad93cc26bc01b4c8520fd3ef51916/src/features/chat/koboldAiChat.ts#L14-L78 | c5829dd25a4ad93cc26bc01b4c8520fd3ef51916 |
amica | github_2023 | semperai | typescript | getNormal | async function getNormal(messages: Message[]) {
const headers: Record<string, string> = {
"Content-Type": "application/json",
};
const prompt = buildPrompt(messages);
const stop_sequence: string[] = [`${config("name")}:`, ...`${config("koboldai_stop_sequence")}`.split("||")];
const res = await fetch(`${... | // koboldai / no stream support | https://github.com/semperai/amica/blob/c5829dd25a4ad93cc26bc01b4c8520fd3ef51916/src/features/chat/koboldAiChat.ts#L81-L120 | c5829dd25a4ad93cc26bc01b4c8520fd3ef51916 |
amica | github_2023 | semperai | typescript | userInputToSystem | const userInputToSystem = (input: string) => {
const mapping: { [key: string]: string } = {
...Object.fromEntries(emotions
.filter(e => e[0] === e[0].toUpperCase())
.map(e => [e.toLowerCase(), e]))
};
return mapping[input.toLowerCase()] || input;
}; | // Convert user input to system format e.g. ["suspicious"] -> ["Sus"], ["sleep"] -> ["Sleep"] | https://github.com/semperai/amica/blob/c5829dd25a4ad93cc26bc01b4c8520fd3ef51916/src/features/chat/messages.ts#L33-L41 | c5829dd25a4ad93cc26bc01b4c8520fd3ef51916 |
amica | github_2023 | semperai | typescript | AutoBlink.setEnable | public setEnable(isAuto: boolean) {
this._isAutoBlink = isAuto;
// 目が閉じている場合、目が開くまでの時間を返す
if (!this._isOpen) {
return this._remainingTime;
}
return 0;
} | /**
* 自動瞬きをON/OFFする。
*
* 目を閉じている(blinkが1の)時に感情表現を入れてしまうと不自然になるので、
* 目が開くまでの秒を返し、その時間待ってから感情表現を適用する。
* @param isAuto
* @returns 目が開くまでの秒
*/ | https://github.com/semperai/amica/blob/c5829dd25a4ad93cc26bc01b4c8520fd3ef51916/src/features/emoteController/autoBlink.ts#L28-L37 | c5829dd25a4ad93cc26bc01b4c8520fd3ef51916 |
amica | github_2023 | semperai | typescript | scheduleAudioPlayback | const scheduleAudioPlayback = async (
newAudioData: Float32Array,
nowTime: number | undefined,
viewer: any
) => {
const sampleRate = audioContext.sampleRate;
const newBuffer = audioContext.createBuffer(1, newAudioData.length, sampleRate);
newBuffer.copyToChannel(newAu... | // Audio source node | https://github.com/semperai/amica/blob/c5829dd25a4ad93cc26bc01b4c8520fd3ef51916/src/features/moshi/hooks/useAudioPlayback.ts#L7-L33 | c5829dd25a4ad93cc26bc01b4c8520fd3ef51916 |
amica | github_2023 | semperai | typescript | Model.loadAnimation | public async loadAnimation(
animation: VRMAnimation | THREE.AnimationClip,
): Promise<void> {
const { vrm, mixer } = this;
if (vrm == null || mixer == null) {
throw new Error("You have to load VRM first");
}
const clip =
animation instanceof THREE.AnimationClip
? animation
... | /**
* VRMアニメーションを読み込む
*
* https://github.com/vrm-c/vrm-specification/blob/master/specification/VRMC_vrm_animation-1.0/README.ja.md
*/ | https://github.com/semperai/amica/blob/c5829dd25a4ad93cc26bc01b4c8520fd3ef51916/src/features/vrmViewer/model.ts#L276-L291 | c5829dd25a4ad93cc26bc01b4c8520fd3ef51916 |
amica | github_2023 | semperai | typescript | Model.speak | public async speak(buffer: ArrayBuffer, screenplay: Screenplay) {
this.emoteController?.playEmotion(screenplay.expression);
await new Promise((resolve) => {
this._lipSync?.playFromArrayBuffer(buffer, () => {
resolve(true);
});
});
} | /**
* 音声を再生し、リップシンクを行う
*/ | https://github.com/semperai/amica/blob/c5829dd25a4ad93cc26bc01b4c8520fd3ef51916/src/features/vrmViewer/model.ts#L416-L423 | c5829dd25a4ad93cc26bc01b4c8520fd3ef51916 |
amica | github_2023 | semperai | typescript | Viewer.loadSplat | public loadSplat(url: string) {
if (!this.room) {
this.room = new Room();
}
return this.room.loadSplat(url).then(async () => {
console.log("splat loaded");
if (!this.room?.splat) return;
this.room.splat.position.set(0, 4, 0);
this.room.splat.rotation.set(0, 0, Math.PI);
... | // but fun experiment. maybe some use somewhere for tiny splats ? | https://github.com/semperai/amica/blob/c5829dd25a4ad93cc26bc01b4c8520fd3ef51916/src/features/vrmViewer/viewer.ts#L858-L870 | c5829dd25a4ad93cc26bc01b4c8520fd3ef51916 |
amica | github_2023 | semperai | typescript | Viewer.regenerateBVHForModel | public async regenerateBVHForModel() {
if (!this.modelMeshHelper) return;
this.modelBVHGenerator!.generate(this.modelMeshHelper!.geometry);
if (!this.modelMeshHelper!.geometry.boundsTree) {
this.modelMeshHelper!.geometry.computeBoundsTree();
} else {
this.modelMeshHelper!.geometry.boundsTr... | // TODO investigate if we can get speedup using parallel bvh generation | https://github.com/semperai/amica/blob/c5829dd25a4ad93cc26bc01b4c8520fd3ef51916/src/features/vrmViewer/viewer.ts#L875-L887 | c5829dd25a4ad93cc26bc01b4c8520fd3ef51916 |
amica | github_2023 | semperai | typescript | Viewer.resize | public resize() {
if (!this.renderer) return;
const parentElement = this.renderer.domElement.parentElement;
if (!parentElement) return;
this.renderer.setPixelRatio(window.devicePixelRatio);
this.renderer.setSize(
parentElement.clientWidth,
parentElement.clientHeight,
);
this.c... | /**
* canvasの親要素を参照してサイズを変更する
*/ | https://github.com/semperai/amica/blob/c5829dd25a4ad93cc26bc01b4c8520fd3ef51916/src/features/vrmViewer/viewer.ts#L934-L949 | c5829dd25a4ad93cc26bc01b4c8520fd3ef51916 |
amica | github_2023 | semperai | typescript | Viewer.resetCamera | public resetCamera() {
const headNode = this.model?.vrm?.humanoid.getNormalizedBoneNode("head");
if (headNode) {
const headWPos = headNode.getWorldPosition(new THREE.Vector3());
this.camera?.position.set(
this.camera.position.x,
headWPos.y,
this.camera.position.z,
);
... | /**
* VRMのheadノードを参照してカメラ位置を調整する
*/ | https://github.com/semperai/amica/blob/c5829dd25a4ad93cc26bc01b4c8520fd3ef51916/src/features/vrmViewer/viewer.ts#L977-L990 | c5829dd25a4ad93cc26bc01b4c8520fd3ef51916 |
amica | github_2023 | semperai | typescript | Viewer.createBallAtPoint | public createBallAtPoint(point: THREE.Vector3, itype: number = 0) {
return;
const distance = point.distanceTo(this.camera?.position as THREE.Vector3);
const s = 5;
const h = distance * s - Math.floor(distance * s);
const getAmicaColor = () => {
return this.hslToRgb(h, 1, 0.5);
};
cons... | // itype: 0 = amica, 1 = room | https://github.com/semperai/amica/blob/c5829dd25a4ad93cc26bc01b4c8520fd3ef51916/src/features/vrmViewer/viewer.ts#L1037-L1064 | c5829dd25a4ad93cc26bc01b4c8520fd3ef51916 |
amica | github_2023 | semperai | typescript | Viewer.applyWind | public applyWind(dir: THREE.Vector3, strength: number) {
this.model?.vrm?.springBoneManager?.joints.forEach((e) => {
e.settings.gravityDir = dir;
e.settings.gravityPower = strength;
});
} | // thx @ke456-png :) | https://github.com/semperai/amica/blob/c5829dd25a4ad93cc26bc01b4c8520fd3ef51916/src/features/vrmViewer/viewer.ts#L1205-L1210 | c5829dd25a4ad93cc26bc01b4c8520fd3ef51916 |
amica | github_2023 | semperai | typescript | VRMLookAtSmoother.revertFirstPersonBoneQuat | public revertFirstPersonBoneQuat(): void {
if (this.userTarget) {
const head = this.humanoid.getNormalizedBoneNode("head")!;
head.quaternion.copy(this._tempFirstPersonBoneQuat);
}
} | /** renderしたあとに叩いて頭の回転をもとに戻す */ | https://github.com/semperai/amica/blob/c5829dd25a4ad93cc26bc01b4c8520fd3ef51916/src/lib/VRMLookAtSmootherLoaderPlugin/VRMLookAtSmoother.ts#L168-L173 | c5829dd25a4ad93cc26bc01b4c8520fd3ef51916 |
amica | github_2023 | semperai | typescript | getChatResponseStream | const getChatResponseStream = async (messages: Message[]) => {
console.debug("getChatResponseStream", messages);
const chatbotBackend = config("chatbot_backend");
switch (chatbotBackend) {
case "chatgpt":
return getOpenAiChatResponseStream(messages);
case "llamacpp":
return getL... | // Function to simulate fetching chat response stream based on the selected backend | https://github.com/semperai/amica/blob/c5829dd25a4ad93cc26bc01b4c8520fd3ef51916/src/utils/askLlm.ts#L39-L59 | c5829dd25a4ad93cc26bc01b4c8520fd3ef51916 |
amica | github_2023 | semperai | typescript | OptimizedGLTFLoader.register | public register(callback: ExtensionCallback): this {
// Add to our extensions array
this.extensions.push(callback);
// Register with the underlying loader
this.loader.register(callback as any);
return this;
} | /**
* Register a custom extension or processor
* @param callback Function that receives the GLTFParser
* @returns The loader instance for chaining
*/ | https://github.com/semperai/amica/blob/c5829dd25a4ad93cc26bc01b4c8520fd3ef51916/src/utils/gltfOptimizer.ts#L72-L80 | c5829dd25a4ad93cc26bc01b4c8520fd3ef51916 |
amica | github_2023 | semperai | typescript | createOffscreenCanvas | function createOffscreenCanvas(width: number, height: number): OffscreenCanvas | HTMLCanvasElement {
if (typeof OffscreenCanvas !== 'undefined') {
return new OffscreenCanvas(width, height);
}
const canvas = document.createElement('canvas');
canvas.width = width;
canvas.height = height;
return canvas;
} | // Create an off-screen canvas for image processing | https://github.com/semperai/amica/blob/c5829dd25a4ad93cc26bc01b4c8520fd3ef51916/src/utils/textureDownscaler.ts#L40-L48 | c5829dd25a4ad93cc26bc01b4c8520fd3ef51916 |
amica | github_2023 | semperai | typescript | scaleImage | function scaleImage(image: TexImageSource, newWidth: number, newHeight: number): Promise<ImageBitmap | HTMLCanvasElement> {
const canvas = createOffscreenCanvas(newWidth, newHeight);
const ctx = canvas.getContext('2d') as OffscreenCanvasRenderingContext2D;
if (!ctx) {
throw new Error('Failed to create 2D con... | // Scale down an image to new dimensions | https://github.com/semperai/amica/blob/c5829dd25a4ad93cc26bc01b4c8520fd3ef51916/src/utils/textureDownscaler.ts#L51-L73 | c5829dd25a4ad93cc26bc01b4c8520fd3ef51916 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.