@promptbook/utils 0.105.0-4 → 0.105.0-6

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.
@@ -39,10 +39,17 @@ export declare abstract class OpenAiCompatibleExecutionTools implements LlmExecu
39
39
  * List all available OpenAI compatible models that can be used
40
40
  */
41
41
  listModels(): Promise<ReadonlyArray<AvailableModel>>;
42
+ /**
43
+ * Calls OpenAI compatible API to use a chat model.
44
+ */
42
45
  /**
43
46
  * Calls OpenAI compatible API to use a chat model.
44
47
  */
45
48
  callChatModel(prompt: Prompt): Promise<ChatPromptResult>;
49
+ /**
50
+ * Calls OpenAI compatible API to use a chat model with streaming.
51
+ */
52
+ callChatModelStream(prompt: Prompt, onProgress: (chunk: ChatPromptResult) => void): Promise<ChatPromptResult>;
46
53
  /**
47
54
  * Internal method that handles parameter retry for chat model calls
48
55
  */
@@ -0,0 +1,6 @@
1
+ export * from './bing/BingSearchEngine';
2
+ export * from './dummy/DummySearchEngine';
3
+ export * from './google/GoogleSearchEngine';
4
+ export * from './SearchEngine';
5
+ export * from './SearchResult';
6
+ export * from './serp/SerpSearchEngine';
@@ -0,0 +1,18 @@
1
+ import type { Promisable } from 'type-fest';
2
+ import type { string_markdown, string_markdown_text, string_title } from '../../types/typeAliases';
3
+ import type { SearchEngine } from '../SearchEngine';
4
+ import type { SearchResult } from '../SearchResult';
5
+ /**
6
+ * A search engine implementation that uses the Google Custom Search JSON API.
7
+ *
8
+ * @private <- TODO: !!!! Export via some package
9
+ */
10
+ export declare class GoogleSearchEngine implements SearchEngine {
11
+ get title(): string_title & string_markdown_text;
12
+ get description(): string_markdown;
13
+ /**
14
+ * @see https://developers.google.com/custom-search/v1/overview
15
+ */
16
+ checkConfiguration(): Promisable<void>;
17
+ search(query: string): Promise<SearchResult[]>;
18
+ }
@@ -0,0 +1,15 @@
1
+ import type { Promisable } from 'type-fest';
2
+ import type { string_markdown, string_markdown_text, string_title } from '../../types/typeAliases';
3
+ import type { SearchEngine } from '../SearchEngine';
4
+ import type { SearchResult } from '../SearchResult';
5
+ /**
6
+ * A search engine implementation that uses the SerpApi to fetch Google search results.
7
+ *
8
+ * @private <- TODO: !!!! Export via some package
9
+ */
10
+ export declare class SerpSearchEngine implements SearchEngine {
11
+ get title(): string_title & string_markdown_text;
12
+ get description(): string_markdown;
13
+ checkConfiguration(): Promisable<void>;
14
+ search(query: string): Promise<SearchResult[]>;
15
+ }
@@ -0,0 +1,21 @@
1
+ import type { SpeechRecognition, SpeechRecognitionEvent, SpeechRecognitionStartOptions, SpeechRecognitionState } from '../types/SpeechRecognition';
2
+ /**
3
+ * Speech recognition using Web Speech API `SpeechRecognition` available in modern browsers
4
+ *
5
+ * @public exported from `@promptbook/browser`
6
+ */
7
+ export declare class BrowserSpeechRecognition implements SpeechRecognition {
8
+ private recognition;
9
+ private callbacks;
10
+ private _state;
11
+ get state(): SpeechRecognitionState;
12
+ constructor();
13
+ $start(options?: SpeechRecognitionStartOptions): void;
14
+ $stop(): void;
15
+ subscribe(callback: (event: SpeechRecognitionEvent) => void): () => void;
16
+ private emit;
17
+ }
18
+ /**
19
+ * TODO: !!!! Search ACRY for `window` and put -> [🔵]
20
+ * Note: [🔵] Code in this file should never be published outside of `@promptbook/browser`
21
+ */
@@ -0,0 +1,32 @@
1
+ import type { SpeechRecognition, SpeechRecognitionEvent, SpeechRecognitionStartOptions, SpeechRecognitionState } from '../types/SpeechRecognition';
2
+ /**
3
+ * Options for OpenAiSpeechRecognition
4
+ */
5
+ export type OpenAiSpeechRecognitionOptions = {
6
+ /**
7
+ * OpenAI API base URL or proxy endpoint
8
+ * @default '/api/openai/v1'
9
+ */
10
+ readonly baseUrl?: string;
11
+ };
12
+ /**
13
+ * Speech recognition using OpenAI Whisper API to transcribe audio into text
14
+ *
15
+ * @private because it requires server-client communication with a proxy endpoint
16
+ *
17
+ * Note: This implementation uses a server-side proxy to avoid exposing the OpenAI API key on the client.
18
+ */
19
+ export declare class OpenAiSpeechRecognition implements SpeechRecognition {
20
+ private readonly options;
21
+ private mediaRecorder;
22
+ private audioChunks;
23
+ private callbacks;
24
+ private _state;
25
+ get state(): SpeechRecognitionState;
26
+ constructor(options?: OpenAiSpeechRecognitionOptions);
27
+ $start(options?: SpeechRecognitionStartOptions): Promise<void>;
28
+ $stop(): void;
29
+ private transcribe;
30
+ subscribe(callback: (event: SpeechRecognitionEvent) => void): () => void;
31
+ private emit;
32
+ }
@@ -0,0 +1,58 @@
1
+ import type { string_language } from './typeAliases';
2
+ /**
3
+ * Interface for speech-to-text recognition
4
+ *
5
+ * @🚉 fully serializable as JSON
6
+ */
7
+ export type SpeechRecognition = {
8
+ /**
9
+ * Start the speech recognition
10
+ */
11
+ $start(options: SpeechRecognitionStartOptions): void;
12
+ /**
13
+ * Stop the speech recognition
14
+ */
15
+ $stop(): void;
16
+ /**
17
+ * Current state of the speech recognition
18
+ */
19
+ readonly state: SpeechRecognitionState;
20
+ /**
21
+ * Subscribe to speech recognition events
22
+ */
23
+ subscribe(callback: (event: SpeechRecognitionEvent) => void): () => void;
24
+ };
25
+ /**
26
+ * Options for starting speech recognition
27
+ */
28
+ export type SpeechRecognitionStartOptions = {
29
+ /**
30
+ * Language for speech recognition
31
+ * @default 'en-US'
32
+ */
33
+ readonly language?: string_language;
34
+ /**
35
+ * Whether to return interim results
36
+ * @default true
37
+ */
38
+ readonly interimResults?: boolean;
39
+ };
40
+ /**
41
+ * Current state of the speech recognition
42
+ */
43
+ export type SpeechRecognitionState = 'IDLE' | 'STARTING' | 'RECORDING' | 'TRANSCRIBING' | 'ERROR';
44
+ /**
45
+ * Event emitted by speech recognition
46
+ */
47
+ export type SpeechRecognitionEvent = {
48
+ readonly type: 'START';
49
+ } | {
50
+ readonly type: 'RESULT';
51
+ readonly text: string;
52
+ readonly isFinal: boolean;
53
+ } | {
54
+ readonly type: 'ERROR';
55
+ readonly message: string;
56
+ } | {
57
+ readonly type: 'STOP';
58
+ };
@@ -668,6 +668,10 @@ export type string_license_token = string_token;
668
668
  export type string_password = string;
669
669
  export type string_ssh_key = string;
670
670
  export type string_pgp_key = string;
671
+ /**
672
+ * Language as a string, e.g. 'en-US', 'cs-CZ', 'en'
673
+ */
674
+ export type string_language = string;
671
675
  /**
672
676
  * Semantic helper for `Date.toISOString()` result
673
677
  *
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Creates human-readable hash
3
+ *
4
+ * @public exported from `@promptbook/utils`
5
+ */
6
+ export declare function linguisticHash(input: string): Promise<string>;
@@ -15,7 +15,7 @@ export declare const BOOK_LANGUAGE_VERSION: string_semantic_version;
15
15
  export declare const PROMPTBOOK_ENGINE_VERSION: string_promptbook_version;
16
16
  /**
17
17
  * Represents the version string of the Promptbook engine.
18
- * It follows semantic versioning (e.g., `0.105.0-3`).
18
+ * It follows semantic versioning (e.g., `0.105.0-5`).
19
19
  *
20
20
  * @generated
21
21
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@promptbook/utils",
3
- "version": "0.105.0-4",
3
+ "version": "0.105.0-6",
4
4
  "description": "Promptbook: Turn your company's scattered knowledge into AI ready books",
5
5
  "private": false,
6
6
  "sideEffects": false,