@promptbook/browser 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.
- package/esm/index.es.js +128 -4
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/_packages/browser.index.d.ts +2 -0
- package/esm/typings/src/_packages/types.index.d.ts +12 -0
- package/esm/typings/src/_packages/utils.index.d.ts +2 -0
- package/esm/typings/src/book-2.0/agent-source/AgentBasicInformation.d.ts +6 -1
- package/esm/typings/src/book-components/Chat/Chat/ChatProps.d.ts +3 -6
- package/esm/typings/src/book-components/Chat/types/ChatMessage.d.ts +9 -0
- package/esm/typings/src/execution/LlmExecutionTools.d.ts +3 -1
- package/esm/typings/src/llm-providers/openai/OpenAiCompatibleExecutionTools.d.ts +7 -0
- package/esm/typings/src/search-engines/_index.d.ts +6 -0
- package/esm/typings/src/search-engines/google/GoogleSearchEngine.d.ts +18 -0
- package/esm/typings/src/search-engines/serp/SerpSearchEngine.d.ts +15 -0
- package/esm/typings/src/speech-recognition/BrowserSpeechRecognition.d.ts +21 -0
- package/esm/typings/src/speech-recognition/OpenAiSpeechRecognition.d.ts +32 -0
- package/esm/typings/src/types/SpeechRecognition.d.ts +58 -0
- package/esm/typings/src/types/typeAliases.d.ts +4 -0
- package/esm/typings/src/utils/misc/linguisticHash.d.ts +6 -0
- package/esm/typings/src/utils/misc/linguisticHash.test.d.ts +1 -0
- package/esm/typings/src/version.d.ts +1 -1
- package/package.json +2 -2
- package/umd/index.umd.js +128 -3
- package/umd/index.umd.js.map +1 -1
|
@@ -183,6 +183,7 @@ import type { PostprocessingFunction } from '../scripting/javascript/JavascriptE
|
|
|
183
183
|
import type { ToolFunction } from '../scripting/javascript/JavascriptExecutionToolsOptions';
|
|
184
184
|
import type { SearchEngine } from '../search-engines/SearchEngine';
|
|
185
185
|
import type { SearchResult } from '../search-engines/SearchResult';
|
|
186
|
+
import type { OpenAiSpeechRecognitionOptions } from '../speech-recognition/OpenAiSpeechRecognition';
|
|
186
187
|
import type { PromptbookStorage } from '../storage/_common/PromptbookStorage';
|
|
187
188
|
import type { FileCacheStorageOptions } from '../storage/file-cache-storage/FileCacheStorageOptions';
|
|
188
189
|
import type { IndexedDbStorageOptions } from '../storage/local-storage/utils/IndexedDbStorageOptions';
|
|
@@ -207,6 +208,10 @@ import type { ImagePrompt } from '../types/Prompt';
|
|
|
207
208
|
import type { EmbeddingPrompt } from '../types/Prompt';
|
|
208
209
|
import type { ScriptLanguage } from '../types/ScriptLanguage';
|
|
209
210
|
import type { SectionType } from '../types/SectionType';
|
|
211
|
+
import type { SpeechRecognition } from '../types/SpeechRecognition';
|
|
212
|
+
import type { SpeechRecognitionStartOptions } from '../types/SpeechRecognition';
|
|
213
|
+
import type { SpeechRecognitionState } from '../types/SpeechRecognition';
|
|
214
|
+
import type { SpeechRecognitionEvent } from '../types/SpeechRecognition';
|
|
210
215
|
import type { TaskType } from '../types/TaskType';
|
|
211
216
|
import type { string_char_emoji } from '../types/typeAliasEmoji';
|
|
212
217
|
import type { string_business_category_name } from '../types/typeAliases';
|
|
@@ -316,6 +321,7 @@ import type { string_license_token } from '../types/typeAliases';
|
|
|
316
321
|
import type { string_password } from '../types/typeAliases';
|
|
317
322
|
import type { string_ssh_key } from '../types/typeAliases';
|
|
318
323
|
import type { string_pgp_key } from '../types/typeAliases';
|
|
324
|
+
import type { string_language } from '../types/typeAliases';
|
|
319
325
|
import type { string_date_iso8601 } from '../types/typeAliases';
|
|
320
326
|
import type { number_usd } from '../types/typeAliases';
|
|
321
327
|
import type { number_id } from '../types/typeAliases';
|
|
@@ -557,6 +563,7 @@ export type { PostprocessingFunction };
|
|
|
557
563
|
export type { ToolFunction };
|
|
558
564
|
export type { SearchEngine };
|
|
559
565
|
export type { SearchResult };
|
|
566
|
+
export type { OpenAiSpeechRecognitionOptions };
|
|
560
567
|
export type { PromptbookStorage };
|
|
561
568
|
export type { FileCacheStorageOptions };
|
|
562
569
|
export type { IndexedDbStorageOptions };
|
|
@@ -581,6 +588,10 @@ export type { ImagePrompt };
|
|
|
581
588
|
export type { EmbeddingPrompt };
|
|
582
589
|
export type { ScriptLanguage };
|
|
583
590
|
export type { SectionType };
|
|
591
|
+
export type { SpeechRecognition };
|
|
592
|
+
export type { SpeechRecognitionStartOptions };
|
|
593
|
+
export type { SpeechRecognitionState };
|
|
594
|
+
export type { SpeechRecognitionEvent };
|
|
584
595
|
export type { TaskType };
|
|
585
596
|
export type { string_char_emoji };
|
|
586
597
|
export type { string_business_category_name };
|
|
@@ -690,6 +701,7 @@ export type { string_license_token };
|
|
|
690
701
|
export type { string_password };
|
|
691
702
|
export type { string_ssh_key };
|
|
692
703
|
export type { string_pgp_key };
|
|
704
|
+
export type { string_language };
|
|
693
705
|
export type { string_date_iso8601 };
|
|
694
706
|
export type { number_usd };
|
|
695
707
|
export type { number_id };
|
|
@@ -29,6 +29,7 @@ import { CountUtils } from '../utils/expectation-counters/index';
|
|
|
29
29
|
import { $getCurrentDate } from '../utils/misc/$getCurrentDate';
|
|
30
30
|
import { computeHash } from '../utils/misc/computeHash';
|
|
31
31
|
import { debounce } from '../utils/misc/debounce';
|
|
32
|
+
import { linguisticHash } from '../utils/misc/linguisticHash';
|
|
32
33
|
import { parseNumber } from '../utils/misc/parseNumber';
|
|
33
34
|
import { capitalize } from '../utils/normalization/capitalize';
|
|
34
35
|
import { decapitalize } from '../utils/normalization/decapitalize';
|
|
@@ -118,6 +119,7 @@ export { CountUtils };
|
|
|
118
119
|
export { $getCurrentDate };
|
|
119
120
|
export { computeHash };
|
|
120
121
|
export { debounce };
|
|
122
|
+
export { linguisticHash };
|
|
121
123
|
export { parseNumber };
|
|
122
124
|
export { capitalize };
|
|
123
125
|
export { decapitalize };
|
|
@@ -31,7 +31,7 @@ export type AgentCapability = {
|
|
|
31
31
|
/**
|
|
32
32
|
* The type of the capability
|
|
33
33
|
*/
|
|
34
|
-
type: 'browser' | 'search-engine' | 'knowledge' | 'time';
|
|
34
|
+
type: 'browser' | 'search-engine' | 'knowledge' | 'time' | 'inheritance' | 'import';
|
|
35
35
|
/**
|
|
36
36
|
* The label to display for this capability
|
|
37
37
|
*/
|
|
@@ -40,6 +40,11 @@ export type AgentCapability = {
|
|
|
40
40
|
* The name of the icon to display for this capability
|
|
41
41
|
*/
|
|
42
42
|
iconName: string;
|
|
43
|
+
/**
|
|
44
|
+
* Optional link to another agent
|
|
45
|
+
* This is used for 'inheritance' and 'import' types
|
|
46
|
+
*/
|
|
47
|
+
agentUrl?: string_agent_url;
|
|
43
48
|
};
|
|
44
49
|
export type AgentBasicInformation = {
|
|
45
50
|
/**
|
|
@@ -5,6 +5,7 @@ import type { ChatMessage } from '../types/ChatMessage';
|
|
|
5
5
|
import type { ChatParticipant } from '../types/ChatParticipant';
|
|
6
6
|
import { string_color } from '../../../types/typeAliases';
|
|
7
7
|
import { Color } from '../../../_packages/color.index';
|
|
8
|
+
import { SpeechRecognition } from '../../../types/SpeechRecognition';
|
|
8
9
|
/**
|
|
9
10
|
* @public exported from `@promptbook/components`
|
|
10
11
|
*/
|
|
@@ -47,13 +48,9 @@ export type ChatProps = {
|
|
|
47
48
|
*/
|
|
48
49
|
readonly isVoiceRecognitionButtonShown?: boolean;
|
|
49
50
|
/**
|
|
50
|
-
*
|
|
51
|
+
* Speech recognition provider
|
|
51
52
|
*/
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* The language code to use for voice recognition
|
|
55
|
-
*/
|
|
56
|
-
readonly voiceLanguage?: string;
|
|
53
|
+
readonly speechRecognition?: SpeechRecognition;
|
|
57
54
|
/**
|
|
58
55
|
* Optional placeholder message for the textarea
|
|
59
56
|
*
|
|
@@ -33,6 +33,15 @@ export type ChatMessage = Omit<Message<id>, 'direction' | 'recipients' | 'thread
|
|
|
33
33
|
* Indicates if the message was sent via a voice call
|
|
34
34
|
*/
|
|
35
35
|
isVoiceCall?: boolean;
|
|
36
|
+
/**
|
|
37
|
+
* Optional tool calls made during the execution
|
|
38
|
+
*/
|
|
39
|
+
readonly ongoingToolCalls?: ReadonlyArray<{
|
|
40
|
+
/**
|
|
41
|
+
* Name of the tool
|
|
42
|
+
*/
|
|
43
|
+
readonly name: string;
|
|
44
|
+
}>;
|
|
36
45
|
/**
|
|
37
46
|
* Optional file attachments
|
|
38
47
|
*/
|
|
@@ -56,7 +56,9 @@ export type LlmExecutionTools = {
|
|
|
56
56
|
/**
|
|
57
57
|
* Calls a chat model with streaming
|
|
58
58
|
*/
|
|
59
|
-
callChatModelStream?(prompt: Prompt, onProgress: (chunk: ChatPromptResult
|
|
59
|
+
callChatModelStream?(prompt: Prompt, onProgress: (chunk: ChatPromptResult & {
|
|
60
|
+
isFinished?: boolean;
|
|
61
|
+
}) => void): Promise<ChatPromptResult>;
|
|
60
62
|
/**
|
|
61
63
|
* Calls a voice chat model
|
|
62
64
|
*/
|
|
@@ -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,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 @@
|
|
|
1
|
+
export {};
|
|
@@ -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-
|
|
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/browser",
|
|
3
|
-
"version": "0.105.0-
|
|
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,
|
|
@@ -94,7 +94,7 @@
|
|
|
94
94
|
"module": "./esm/index.es.js",
|
|
95
95
|
"typings": "./esm/typings/src/_packages/browser.index.d.ts",
|
|
96
96
|
"peerDependencies": {
|
|
97
|
-
"@promptbook/core": "0.105.0-
|
|
97
|
+
"@promptbook/core": "0.105.0-6"
|
|
98
98
|
},
|
|
99
99
|
"dependencies": {
|
|
100
100
|
"crypto": "1.0.1",
|
package/umd/index.umd.js
CHANGED
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
* @generated
|
|
24
24
|
* @see https://github.com/webgptorg/promptbook
|
|
25
25
|
*/
|
|
26
|
-
const PROMPTBOOK_ENGINE_VERSION = '0.105.0-
|
|
26
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.105.0-6';
|
|
27
27
|
/**
|
|
28
28
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
29
29
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -1410,6 +1410,104 @@
|
|
|
1410
1410
|
return scrapers;
|
|
1411
1411
|
}
|
|
1412
1412
|
|
|
1413
|
+
/**
|
|
1414
|
+
* Speech recognition using Web Speech API `SpeechRecognition` available in modern browsers
|
|
1415
|
+
*
|
|
1416
|
+
* @public exported from `@promptbook/browser`
|
|
1417
|
+
*/
|
|
1418
|
+
class BrowserSpeechRecognition {
|
|
1419
|
+
get state() {
|
|
1420
|
+
return this._state;
|
|
1421
|
+
}
|
|
1422
|
+
constructor() {
|
|
1423
|
+
this.recognition = null;
|
|
1424
|
+
this.callbacks = [];
|
|
1425
|
+
this._state = 'IDLE';
|
|
1426
|
+
if (typeof window !== 'undefined') {
|
|
1427
|
+
const SpeechRecognitionValue = window.SpeechRecognition ||
|
|
1428
|
+
window /* <- TODO: !!!! Make special windowAny */.webkitSpeechRecognition;
|
|
1429
|
+
if (SpeechRecognitionValue) {
|
|
1430
|
+
this.recognition = new SpeechRecognitionValue();
|
|
1431
|
+
this.recognition.continuous = true;
|
|
1432
|
+
this.recognition.interimResults = true;
|
|
1433
|
+
this.recognition.onstart = () => {
|
|
1434
|
+
this._state = 'RECORDING';
|
|
1435
|
+
this.emit({ type: 'START' });
|
|
1436
|
+
};
|
|
1437
|
+
this.recognition.onresult = (event) => {
|
|
1438
|
+
let finalTranscript = '';
|
|
1439
|
+
let interimTranscript = '';
|
|
1440
|
+
for (let i = event.resultIndex; i < event.results.length; ++i) {
|
|
1441
|
+
if (event.results[i].isFinal) {
|
|
1442
|
+
finalTranscript += event.results[i][0].transcript;
|
|
1443
|
+
}
|
|
1444
|
+
else {
|
|
1445
|
+
interimTranscript += event.results[i][0].transcript;
|
|
1446
|
+
}
|
|
1447
|
+
}
|
|
1448
|
+
const text = (finalTranscript + interimTranscript).trim();
|
|
1449
|
+
if (text) {
|
|
1450
|
+
this.emit({
|
|
1451
|
+
type: 'RESULT',
|
|
1452
|
+
text,
|
|
1453
|
+
isFinal: interimTranscript === '',
|
|
1454
|
+
});
|
|
1455
|
+
}
|
|
1456
|
+
};
|
|
1457
|
+
this.recognition.onerror = (event) => {
|
|
1458
|
+
this._state = 'ERROR';
|
|
1459
|
+
this.emit({ type: 'ERROR', message: event.error || 'Unknown error' });
|
|
1460
|
+
};
|
|
1461
|
+
this.recognition.onend = () => {
|
|
1462
|
+
this._state = 'IDLE';
|
|
1463
|
+
this.emit({ type: 'STOP' });
|
|
1464
|
+
};
|
|
1465
|
+
}
|
|
1466
|
+
}
|
|
1467
|
+
}
|
|
1468
|
+
$start(options = {}) {
|
|
1469
|
+
var _a;
|
|
1470
|
+
if (!this.recognition) {
|
|
1471
|
+
this.emit({ type: 'ERROR', message: 'Speech recognition is not supported in this browser.' });
|
|
1472
|
+
return;
|
|
1473
|
+
}
|
|
1474
|
+
if (this._state !== 'IDLE') {
|
|
1475
|
+
return;
|
|
1476
|
+
}
|
|
1477
|
+
this._state = 'STARTING';
|
|
1478
|
+
this.recognition.lang = options.language || 'en'; // Note: Web Speech API usually accepts ISO-639-1 or BCP-47
|
|
1479
|
+
this.recognition.interimResults = (_a = options.interimResults) !== null && _a !== void 0 ? _a : true;
|
|
1480
|
+
try {
|
|
1481
|
+
this.recognition.start();
|
|
1482
|
+
}
|
|
1483
|
+
catch (error) {
|
|
1484
|
+
this._state = 'ERROR';
|
|
1485
|
+
this.emit({ type: 'ERROR', message: error.message });
|
|
1486
|
+
}
|
|
1487
|
+
}
|
|
1488
|
+
$stop() {
|
|
1489
|
+
if (!this.recognition || this._state === 'IDLE') {
|
|
1490
|
+
return;
|
|
1491
|
+
}
|
|
1492
|
+
this.recognition.stop();
|
|
1493
|
+
}
|
|
1494
|
+
subscribe(callback) {
|
|
1495
|
+
this.callbacks.push(callback);
|
|
1496
|
+
return () => {
|
|
1497
|
+
this.callbacks = this.callbacks.filter((cb) => cb !== callback);
|
|
1498
|
+
};
|
|
1499
|
+
}
|
|
1500
|
+
emit(event) {
|
|
1501
|
+
for (const callback of this.callbacks) {
|
|
1502
|
+
callback(event);
|
|
1503
|
+
}
|
|
1504
|
+
}
|
|
1505
|
+
}
|
|
1506
|
+
/**
|
|
1507
|
+
* TODO: !!!! Search ACRY for `window` and put -> [🔵]
|
|
1508
|
+
* Note: [🔵] Code in this file should never be published outside of `@promptbook/browser`
|
|
1509
|
+
*/
|
|
1510
|
+
|
|
1413
1511
|
/**
|
|
1414
1512
|
* Creates a PromptbookStorage backed by IndexedDB.
|
|
1415
1513
|
* Uses a single object store named 'promptbook'.
|
|
@@ -6681,26 +6779,52 @@
|
|
|
6681
6779
|
});
|
|
6682
6780
|
continue;
|
|
6683
6781
|
}
|
|
6782
|
+
if (commitment.type === 'FROM') {
|
|
6783
|
+
const content = spaceTrim__default["default"](commitment.content).split('\n')[0] || '';
|
|
6784
|
+
if (content === 'Adam' || content === '' /* <- Note: Adam is implicit */) {
|
|
6785
|
+
continue;
|
|
6786
|
+
}
|
|
6787
|
+
let label = content;
|
|
6788
|
+
let iconName = 'SquareArrowOutUpRight'; // Inheritance remote
|
|
6789
|
+
if (content.startsWith('./') || content.startsWith('../') || content.startsWith('/')) {
|
|
6790
|
+
label = content.split('/').pop() || content;
|
|
6791
|
+
iconName = 'SquareArrowUpRight'; // Inheritance local
|
|
6792
|
+
}
|
|
6793
|
+
if (content === 'VOID') {
|
|
6794
|
+
label = 'VOID';
|
|
6795
|
+
iconName = 'ShieldAlert'; // [🧠] Or some other icon for VOID
|
|
6796
|
+
}
|
|
6797
|
+
capabilities.push({
|
|
6798
|
+
type: 'inheritance',
|
|
6799
|
+
label,
|
|
6800
|
+
iconName,
|
|
6801
|
+
agentUrl: content,
|
|
6802
|
+
});
|
|
6803
|
+
continue;
|
|
6804
|
+
}
|
|
6684
6805
|
if (commitment.type === 'IMPORT') {
|
|
6685
6806
|
const content = spaceTrim__default["default"](commitment.content).split('\n')[0] || '';
|
|
6686
6807
|
let label = content;
|
|
6687
|
-
|
|
6808
|
+
let iconName = 'ExternalLink'; // Import remote
|
|
6688
6809
|
try {
|
|
6689
6810
|
if (content.startsWith('http://') || content.startsWith('https://')) {
|
|
6690
6811
|
const url = new URL(content);
|
|
6691
6812
|
label = url.hostname.replace(/^www\./, '') + '.../' + url.pathname.split('/').pop();
|
|
6813
|
+
iconName = 'ExternalLink';
|
|
6692
6814
|
}
|
|
6693
6815
|
else if (content.startsWith('./') || content.startsWith('../') || content.startsWith('/')) {
|
|
6694
6816
|
label = content.split('/').pop() || content;
|
|
6817
|
+
iconName = 'Link'; // Import local
|
|
6695
6818
|
}
|
|
6696
6819
|
}
|
|
6697
6820
|
catch (e) {
|
|
6698
6821
|
// Invalid URL or path, keep default label
|
|
6699
6822
|
}
|
|
6700
6823
|
capabilities.push({
|
|
6701
|
-
type: '
|
|
6824
|
+
type: 'import',
|
|
6702
6825
|
label,
|
|
6703
6826
|
iconName,
|
|
6827
|
+
agentUrl: content,
|
|
6704
6828
|
});
|
|
6705
6829
|
continue;
|
|
6706
6830
|
}
|
|
@@ -6930,6 +7054,7 @@
|
|
|
6930
7054
|
exports.$induceFileDownload = $induceFileDownload;
|
|
6931
7055
|
exports.$provideScrapersForBrowser = $provideScrapersForBrowser;
|
|
6932
7056
|
exports.BOOK_LANGUAGE_VERSION = BOOK_LANGUAGE_VERSION;
|
|
7057
|
+
exports.BrowserSpeechRecognition = BrowserSpeechRecognition;
|
|
6933
7058
|
exports.ObjectUrl = ObjectUrl;
|
|
6934
7059
|
exports.PROMPTBOOK_ENGINE_VERSION = PROMPTBOOK_ENGINE_VERSION;
|
|
6935
7060
|
exports.SimplePromptInterfaceTools = SimplePromptInterfaceTools;
|